carbon intf: implemented GetWindowSize, GetClientRect, critical sections

git-svn-id: trunk@9531 -
This commit is contained in:
mattias 2006-06-30 18:52:40 +00:00
parent 187e308562
commit 67968958f1
8 changed files with 64 additions and 21 deletions

View File

@ -107,7 +107,7 @@ begin
// create LCL WidgetInfo
Result:=HWnd(Control);
Info := CreateWidgetInfo(Control, AWinControl);
Info := CreateWidgetInfo(Control, AWinControl, cwtControlRef);
TCarbonPrivateHandleClass(WSPrivate).RegisterEvents(Info);
// create the AGL context

View File

@ -42,11 +42,14 @@ var
WIDGETINFO_FOURCC: FourCharCode; // = 'WInf';
type
TCarbonWidgetType = (cwtWindowRef, cwtControlRef);
// Info needed by the API of a HWND (=Widget)
PWidgetInfo = ^TWidgetInfo;
TWidgetInfo = record
LCLObject: TObject; // the object which created this widget
Widget: Pointer; // Reference to the Carbon window or control
WidgetType: TCarbonWidgetType;
WSClass: TWSLCLComponentClass; // The Widgetsetclass for this info
DataOwner: Boolean; // Set if the UserData should be freed when the info is freed
UserData: Pointer;
@ -64,4 +67,4 @@ initialization
LAZARUS_FOURCC := MakeFourCC('Laz ');
WIDGETINFO_FOURCC := MakeFourCC('WInf');
end.
end.

View File

@ -34,7 +34,8 @@ uses
LCLProc, LCLClasses, Controls, LMessages, Forms, Avl_Tree, SysUtils,
CarbonDef;
function CreateWidgetInfo(AWidget: Pointer; AObject: TLCLComponent): PWidgetInfo;
function CreateWidgetInfo(AWidget: Pointer; AObject: TLCLComponent;
TheType: TCarbonWidgetType): PWidgetInfo;
procedure FreeWidgetInfo(AInfo: PWidgetInfo);
function GetWidgetInfo(AWidget: Pointer): PWidgetInfo;
@ -52,13 +53,15 @@ function Dbgs(const ARect: FPCMacOSAll.Rect): string; overload;
implementation
function CreateWidgetInfo(AWidget: Pointer; AObject: TLCLComponent): PWidgetInfo;
function CreateWidgetInfo(AWidget: Pointer; AObject: TLCLComponent;
TheType: TCarbonWidgetType): PWidgetInfo;
begin
New(Result);
FillChar(Result^, SizeOf(Result^), 0);
Result^.LCLObject := AObject;
Result^.Widget := AWidget;
Result^.WSClass := AObject.WidgetSetClass;
Result^.widgetType := TheType;
if IsValidControlHandle(AWidget)
then begin
@ -247,4 +250,4 @@ finalization
if UPPTree <> nil
then FreeAndNil(UPPTree);
end.
end.

View File

@ -190,8 +190,12 @@ end;
procedure TCarbonWidgetSet.DeleteCriticalSection(
var CritSection: TCriticalSection);
var
ACritSec: System.PRTLCriticalSection;
begin
inherited DeleteCriticalSection(CritSection);
ACritSec:=System.PRTLCriticalSection(CritSection);
System.DoneCriticalsection(ACritSec^);
CritSection:=0;
end;
function TCarbonWidgetSet.DeleteDC(hDC: HDC): Boolean;
@ -251,8 +255,11 @@ end;
procedure TCarbonWidgetSet.EnterCriticalSection(
var CritSection: TCriticalSection);
var
ACritSec: System.PRTLCriticalSection;
begin
inherited EnterCriticalSection(CritSection);
ACritSec:=System.PRTLCriticalSection(CritSection);
System.EnterCriticalsection(ACritSec^);
end;
function TCarbonWidgetSet.ExcludeClipRect(dc: hdc; Left, Top, Right,
@ -585,8 +592,19 @@ end;
function TCarbonWidgetSet.GetWindowSize(Handle: hwnd; var Width, Height: integer
): boolean;
var
AWndRect: FPCMacOSAll.Rect;
Info: PWidgetInfo;
begin
Result:=inherited GetWindowSize(Handle, Width, Height);
Info:=GetWidgetInfo(Pointer(Handle));
if Info^.widgetType=cwtWindowRef then begin
Result := GetWindowBounds(WindowRef(Handle),kWindowStructureRgn, AWndRect) = 0;
end else begin
Result := GetControlBounds(ControlRef(Handle), AWndRect) <>nil;
end;
if not Result then Exit;
Width := AWndRect.right-AWndRect.left;
Height := AWndRect.bottom-AWndRect.top;
end;
function TCarbonWidgetSet.GradientFill(DC: HDC; Vertices: PTriVertex;
@ -604,8 +622,11 @@ end;
procedure TCarbonWidgetSet.InitializeCriticalSection(
var CritSection: TCriticalSection);
var
ACritSec: System.PRTLCriticalSection;
begin
inherited InitializeCriticalSection(CritSection);
ACritSec:=System.PRTLCriticalSection(CritSection);
System.InitCriticalSection(ACritSec^);
end;
function TCarbonWidgetSet.IntersectClipRect(dc: hdc; Left, Top, Right,
@ -628,8 +649,11 @@ end;
procedure TCarbonWidgetSet.LeaveCriticalSection(
var CritSection: TCriticalSection);
var
ACritSec: System.PRTLCriticalSection;
begin
inherited LeaveCriticalSection(CritSection);
ACritSec:=System.PRTLCriticalSection(CritSection);
System.LeaveCriticalsection(ACritSec^);
end;
function TCarbonWidgetSet.LineTo(DC: HDC; X, Y: Integer): Boolean;

View File

@ -95,7 +95,7 @@ begin
if Result = 0 then Exit;
// add the info (our data, like which TWinControl belong to this carbon widget)
Info := CreateWidgetInfo(Control, AWinControl);
Info := CreateWidgetInfo(Control, AWinControl, cwtControlRef);
// register events (e.g. mouse, focus, keyboard, size, ...)
TCarbonPrivateHandleClass(WSPrivate).RegisterEvents(Info);

View File

@ -204,13 +204,26 @@ class function TCarbonWSWinControl.GetClientRect(const AWincontrol: TWinControl;
var ARect: TRect): Boolean;
var
AHiRect: HIRect;
AWndRect: FPCMacOSAll.Rect;
begin
Result := HIViewGetBounds(HIViewRef(AWinControl.Handle), AHiRect) = 0;
if not Result then Exit;
ARect.Top := 0;//AHiRect.Origin.y;
ARect.Left := 0;//AHiRect.Origin.x;
ARect.Right := ARect.Left + Trunc(AHiRect.size.width);
ARect.Bottom := ARect.Top + Trunc(AHIRect.size.height);
if (AWinControl is TCustomForm)
and (AWinControl.Parent=nil) then begin
Result := GetWindowBounds(WindowRef(AWinControl.Handle),kWindowContentRgn, AWndRect) = 0;
if not Result then Exit;
ARect.Top := 0;//AHiRect.Origin.y;
ARect.Left := 0;//AHiRect.Origin.x;
ARect.Right := AWndRect.right-AWndRect.left;
ARect.Bottom := AWndRect.bottom-AWndRect.top;
//debugln(['TCarbonWSWinControl.GetClientRect ',dbgs(ARect)]);
end else begin
Result := HIViewGetBounds(HIViewRef(AWinControl.Handle), AHiRect) = 0;
if not Result then Exit;
ARect.Top := 0;//AHiRect.Origin.y;
ARect.Left := 0;//AHiRect.Origin.x;
ARect.Right := ARect.Left + Trunc(AHiRect.size.width);
ARect.Bottom := ARect.Top + Trunc(AHIRect.size.height);
//debugln(['TCarbonWSWinControl.GetClientRect ',dbgs(ARect)]);
end;
end;
{ TCarbonWSCustomControl }
@ -239,7 +252,7 @@ begin
CFRelease(Pointer(CFString));
if Result = 0 then Exit;
Info := CreateWidgetInfo(Control, AWinControl);
Info := CreateWidgetInfo(Control, AWinControl, cwtControlRef);
TCarbonPrivateHandleClass(WSPrivate).RegisterEvents(Info);
end;

View File

@ -158,7 +158,7 @@ begin
SetWindowTitleWithCFString(Window, CFString);
CFRelease(Pointer(CFString));
Info := CreateWidgetInfo(Window, AWinControl);
Info := CreateWidgetInfo(Window, AWinControl, cwtWindowRef);
TCarbonPrivateHandleClass(WSPrivate).RegisterEvents(Info);
MinSize.width:=AWinControl.Constraints.EffectiveMinWidth;

View File

@ -256,7 +256,7 @@ begin
SizeOf(Boolean), @SingleLine);
Info := CreateWidgetInfo(Control, AWinControl);
Info := CreateWidgetInfo(Control, AWinControl, cwtControlRef);
Info^.UserData := IsPassword;
Info^.DataOwner := True;
TCarbonPrivateHandleClass(WSPrivate).RegisterEvents(Info);
@ -476,7 +476,7 @@ begin
CFRelease(Pointer(CFString));
if Result = 0 then Exit;
Info := CreateWidgetInfo(Control, AWinControl);
Info := CreateWidgetInfo(Control, AWinControl, cwtControlRef);
TCarbonPrivateHandleClass(WSPrivate).RegisterEvents(Info);
end;