diff options
author | sekelsenmat <sekelsenmat@ae50a9b5-8222-0410-bf8d-8a13f76226bf> | 2007-05-31 14:54:39 +0000 |
---|---|---|
committer | sekelsenmat <sekelsenmat@ae50a9b5-8222-0410-bf8d-8a13f76226bf> | 2007-05-31 14:54:39 +0000 |
commit | 5c84b5c66c967254400370c991170a61533a8014 (patch) | |
tree | 02b3da868e266eadfe275e2cc6b7fbb591e4a56f | |
parent | 59ae98e700b4774a123e62435b54c1141380fcaa (diff) | |
download | fpGUI-5c84b5c66c967254400370c991170a61533a8014.tar.xz |
Moved the handle internal field to platform specific area. Added GetHandle function. Improved carbon interface
-rw-r--r-- | gfx/carbon/gfx_carbon.pas | 67 | ||||
-rw-r--r-- | gfx/gdi/gfx_gdi.pas | 7 | ||||
-rw-r--r-- | gfx/gfxbase.pas | 4 | ||||
-rw-r--r-- | gfx/template/gfx_xxx.pas | 1 | ||||
-rw-r--r-- | gfx/x11/gfx_x11.pas | 7 |
5 files changed, 80 insertions, 6 deletions
diff --git a/gfx/carbon/gfx_carbon.pas b/gfx/carbon/gfx_carbon.pas index c1236e4c..8ca3a083 100644 --- a/gfx/carbon/gfx_carbon.pas +++ b/gfx/carbon/gfx_carbon.pas @@ -16,7 +16,7 @@ unit gfx_carbon; {$ifdef fpc} - {$mode objfpc}{$H+} + {$mode delphi}{$H+} {$endif} interface @@ -129,10 +129,14 @@ type { TCarbonWindow } TCarbonWindow = class(TFCustomWindow) + private + FHandle: WindowRef; + contentView: HIViewRef; protected function GetTitle: String; override; procedure SetTitle(const ATitle: String); override; procedure DoSetCursor; override; + function GetHandle: PtrUInt; override; public constructor Create(AParent: TFCustomWindow; AWindowOptions: TFWindowOptions); override; destructor Destroy; override; @@ -373,7 +377,7 @@ end; procedure TCarbonApplication.Run; begin - + RunApplicationEventLoop(); end; procedure TCarbonApplication.Quit; @@ -383,6 +387,23 @@ end; { TCarbonWindow } +function WindowCommandHandler(nextHandler: EventHandlerCallRef; theEvent: EventRef; userDataPtr: UnivPtr): OSStatus; +var + status: OSStatus; + ignoreResult: OSStatus; + aCommand: HICommand; + theAssociatedControl: ControlRef; +begin + status := eventNotHandledErr; + + ignoreResult := GetEventParameter(theEvent, kEventParamDirectObject, typeHICommand, NIL, sizeof(aCommand), NIL, @aCommand); + +// if aCommand.commandID = UInt32(FourCharCode(kButtonHello)) then status := ButtonHelloPressed() +// else if aCommand.commandID = UInt32(FourCharCode(kButtonMessage)) then status := ButtonMessagePressed(); + + Result := status; +end; + function TCarbonWindow.GetTitle: String; begin @@ -398,9 +419,47 @@ begin end; -constructor TCarbonWindow.Create(AParent: TFCustomWindow; AWindowOptions: TFWindowOptions); +function TCarbonWindow.GetHandle: PtrUInt; begin + Result := PtrUInt(FHandle); +end; + +constructor TCarbonWindow.Create(AParent: TFCustomWindow; AWindowOptions: TFWindowOptions); +var + status, ignoreResult: OSStatus; + cmdEvent: EventTypeSpec; + eventHandler: EventHandlerUPP; + CarbonRect: FPCMacOSAll.Rect; +begin + CarbonRect.left := 50; + CarbonRect.Top := 50; + CarbonRect.right := 300; + CarbonRect.bottom := 300; + + status := CreateNewWindow(kDocumentWindowClass, + (kWindowStandardDocumentAttributes or kWindowStandardHandlerAttribute + or kWindowCompositingAttribute), + CarbonRect, FHandle); + + if (status <> noErr) or (FHandle = nil) then + begin +// DoShowMessage('Error', 'CreateNewWindow failed'); + end; + + ignoreResult := SetWindowTitleWithCFString(FHandle, CFSTRP('Carbon FPC Hello World')); + ignoreResult := HIViewFindByID(HIViewGetRoot(FHandle), kHIViewWindowContentID, contentView); + + { Add events } + + cmdEvent.eventClass := kEventClassCommand; + cmdEvent.eventKind := kEventCommandProcess; + eventHandler := NewEventHandlerUPP(@WindowCommandHandler); + ignoreResult := InstallEventHandler(GetWindowEventTarget(FHandle), + eventHandler, 1, @cmdEvent, nil, nil); + + { Creates a canvas } + FCanvas := TCarbonCanvas.Create; end; destructor TCarbonWindow.Destroy; @@ -440,7 +499,7 @@ end; procedure TCarbonWindow.Show; begin - + ShowWindow(FHandle); end; procedure TCarbonWindow.Invalidate(const ARect: TRect); diff --git a/gfx/gdi/gfx_gdi.pas b/gfx/gdi/gfx_gdi.pas index a8196916..83955cdb 100644 --- a/gfx/gdi/gfx_gdi.pas +++ b/gfx/gdi/gfx_gdi.pas @@ -174,6 +174,7 @@ type TGDIWindow = class(TFCustomWindow) protected + FHandle: PtrUInt; WindowClass: TWndClass; WindowClassW: TWndClassW; FWindowStyle, FWindowStyleEx: LongWord; @@ -181,6 +182,7 @@ type function GetTitle: String; override; procedure SetTitle(const ATitle: String); override; procedure DoSetCursor; override; + function GetHandle: PtrUInt; override; procedure UpdateWindowButtons; function DoMouseEnterLeaveCheck(uMsg, wParam, lParam: Cardinal): Boolean; public @@ -1739,6 +1741,11 @@ begin end; end; +function TGDIWindow.GetHandle: PtrUInt; +begin + Result := FHandle; +end; + procedure TGDIWindow.UpdateWindowButtons; var diff --git a/gfx/gfxbase.pas b/gfx/gfxbase.pas index 74c6f637..1c23d351 100644 --- a/gfx/gfxbase.pas +++ b/gfx/gfxbase.pas @@ -493,7 +493,6 @@ type procedure SetCursor(ACursor: TFCursor); procedure SetWindowOptions(const AValue: TFWindowOptions); virtual; protected - FHandle: Cardinal; FParent: TFCustomWindow; FCanvas: TFCustomCanvas; FLeft: Integer; @@ -508,6 +507,7 @@ type function GetTitle: String; virtual; procedure SetTitle(const ATitle: String); virtual; procedure DoSetCursor; virtual; abstract; + function GetHandle: PtrUInt; virtual; abstract; public constructor Create(AParent: TFCustomWindow; AWindowOptions: TFWindowOptions); virtual; destructor Destroy; override; @@ -526,7 +526,7 @@ type property WindowOptions: TFWindowOptions read FWindowOptions write SetWindowOptions; property Canvas: TFCustomCanvas read FCanvas; - property Handle: Cardinal read FHandle; + property Handle: PtrUInt read GetHandle; property ChildWindows: TList read FChildWindows; // Window state property Left: Integer read FLeft write SetLeft; diff --git a/gfx/template/gfx_xxx.pas b/gfx/template/gfx_xxx.pas index 9005f30f..51aab56d 100644 --- a/gfx/template/gfx_xxx.pas +++ b/gfx/template/gfx_xxx.pas @@ -126,6 +126,7 @@ type function GetTitle: String; override; procedure SetTitle(const ATitle: String); override; procedure DoSetCursor; override; + function GetHandle: PtrUInt; override; public constructor Create(AParent: TFCustomWindow; AWindowOptions: TFWindowOptions); override; destructor Destroy; override; diff --git a/gfx/x11/gfx_x11.pas b/gfx/x11/gfx_x11.pas index a6f46d40..282fbdb1 100644 --- a/gfx/x11/gfx_x11.pas +++ b/gfx/x11/gfx_x11.pas @@ -224,6 +224,7 @@ type TX11Window = class(TFCustomWindow) private + FHandle: PtrUInt; FComposeStatus: TXComposeStatus; FComposeBuffer: String[32]; FCurCursorHandle: X.TCursor; @@ -240,6 +241,7 @@ type function KeySymToKeycode(KeySym: TKeySym): Word; procedure SetTitle(const ATitle: String); override; procedure DoSetCursor; override; + function GetHandle: PtrUInt; override; procedure UpdateMotifWMHints; public constructor Create(AParent: TFCustomWindow; AWindowOptions: TFWindowOptions); override; @@ -1734,6 +1736,11 @@ begin XDefineCursor(GFApplication.Handle, Handle, FCurCursorHandle); end; +function TX11Window.GetHandle: PtrUInt; +begin + Result := FHandle; +end; + function TX11Window.ConvertShiftState(AState: Cardinal): TShiftState; begin Result := []; |