diff --git a/lcl/interfaces/cocoa/cocoaint.pas b/lcl/interfaces/cocoa/cocoaint.pas index 213520ee91..2fe90c64ae 100644 --- a/lcl/interfaces/cocoa/cocoaint.pas +++ b/lcl/interfaces/cocoa/cocoaint.pas @@ -28,14 +28,14 @@ interface uses // rtl+ftl Types, Classes, SysUtils, Math, GraphMath, - // carbon bindings - MacOSAll, // interfacebase LCLPlatformDef, InterfaceBase, GraphType, + // darwin bindings + MacOSAll, // private CocoaAll, CocoaConfig, CocoaPrivate, CocoaUtils, CocoaGDIObjects, CocoaCursor, cocoa_extra, CocoaMenus, CocoaWindows, CocoaScrollers, - CocoaWSClipboard, CocoaTextEdits, CocoaWSCommon, + CocoaWSClipboard, CocoaTextEdits, // LCL LMessages, LCLProc, LCLIntf, LCLType, Controls, Forms, Themes, Menus, @@ -283,6 +283,27 @@ const var MainPool : NSAutoreleasePool = nil; +function HWNDToTargetObject(AFormHandle: HWND): TObject; +var + cb : ICommonCallback; +begin + Result := nil; + if AFormHandle = 0 then Exit; + cb := NSObject(AFormHandle).lclGetCallback; + if not Assigned(cb) then Exit; + Result := cb.GetTarget; +end; + +function HWNDToForm(AFormHandle: HWND): TCustomForm; +var + obj : TObject; +begin + obj := HWNDToTargetObject(AFormHandle); + if Assigned(obj) and (obj is TCustomForm) + then Result := TCustomForm(obj) + else Result := nil; +end; + procedure InternalInit; begin // MacOSX 10.6 reports a lot of warnings during initialization process diff --git a/lcl/interfaces/cocoa/cocoawinapi.inc b/lcl/interfaces/cocoa/cocoawinapi.inc index b91e2349da..dd0be2b24b 100644 --- a/lcl/interfaces/cocoa/cocoawinapi.inc +++ b/lcl/interfaces/cocoa/cocoawinapi.inc @@ -1443,9 +1443,7 @@ begin Result := Assigned(cbi); if not Result then Exit; - obj := cbi.GetCallbackObject; - Result := (obj is TLCLCommonCallback) - and (HWND(TLCLCommonCallback(obj).HandleFrame)=handle); + Result:= NSObject(handle).isKindOfClass(TCocoaWindowContent); end else Result := False; @@ -2138,7 +2136,7 @@ var view : NSView; dl : NSObject; cb : ICommonCallback; - cbobj : TObject; + lclobj : TObject; begin Result := 0; win := NSApp.keyWindow; @@ -2164,16 +2162,9 @@ begin end else begin - cb := rsp.lclGetCallback; - if Assigned(cb) then - cbobj := cb.GetCallbackObject - else - cbobj := nil; - - if (cbobj is TLCLCommonCallback) then - Result := HWND(TLCLCommonCallback(cbobj).HandleFrame) - else - Result := 0; + lclobj := rsp.lclGetTarget; + if lclobj is TWinControl then + Result := TWinControl(lclobj).Handle; end; end; diff --git a/lcl/interfaces/cocoa/cocoawindows.pas b/lcl/interfaces/cocoa/cocoawindows.pas index 4e73ee5364..5164b19d6f 100644 --- a/lcl/interfaces/cocoa/cocoawindows.pas +++ b/lcl/interfaces/cocoa/cocoawindows.pas @@ -27,7 +27,7 @@ uses Types, Classes, SysUtils, CGGeometry, // Libs - MacOSAll, CocoaAll, CocoaUtils, CocoaCursor, CocoaWScommon, + MacOSAll, CocoaAll, CocoaUtils, CocoaCursor, cocoa_extra, CocoaPrivate, CocoaTextEdits, CocoaScrollers, // LCL //Forms, diff --git a/lcl/interfaces/cocoa/cocoawscommon.pas b/lcl/interfaces/cocoa/cocoawscommon.pas index 9e896750d6..f991c14783 100644 --- a/lcl/interfaces/cocoa/cocoawscommon.pas +++ b/lcl/interfaces/cocoa/cocoawscommon.pas @@ -8,13 +8,10 @@ unit CocoaWSCommon; interface uses - Types, - CocoaAll, cocoa_extra, - Classes, Controls, SysUtils, - // - WSControls, LCLType, LMessages, LCLProc, LCLIntf, Graphics, Forms, - CocoaConfig, CocoaPrivate, CocoaGDIObjects, CocoaCursor, CocoaCaret, CocoaUtils, LCLMessageGlue, - CocoaScrollers; + Types, Classes, Controls, SysUtils, + WSControls, LCLType, LCLMessageGlue, LMessages, LCLProc, LCLIntf, Graphics, Forms, + CocoaAll, CocoaInt, CocoaConfig, CocoaPrivate, CocoaUtils, + CocoaGDIObjects, CocoaCursor, CocoaCaret, CocoaScrollers, cocoa_extra; type { TLCLCommonCallback } @@ -182,9 +179,6 @@ function EmbedInScrollView(AView: NSView; AReleaseView: Boolean = true): TCocoaS function EmbedInManualScrollView(AView: NSView): TCocoaManualScrollView; function EmbedInManualScrollHost(AView: TCocoaManualScrollView): TCocoaManualScrollHost; -function HWNDToTargetObject(AFormHandle: HWND): TObject; -function HWNDToForm(AFormHandle: HWND): TCustomForm; - procedure ScrollViewSetBorderStyle(sv: NSScrollView; astyle: TBorderStyle); procedure UpdateFocusRing(v: NSView; astyle: TBorderStyle); @@ -200,7 +194,7 @@ procedure DebugDumpParents(fromView: NSView); implementation uses - Math, CocoaInt; + Math; var LastMouse: TLastMouseInfo; @@ -2038,27 +2032,6 @@ begin ScrollViewSetBorderStyle( TCocoaManualScrollHost(AWinControl.Handle), ABorderStyle ); end; -function HWNDToTargetObject(AFormHandle: HWND): TObject; -var - cb : ICommonCallback; -begin - Result := nil; - if AFormHandle = 0 then Exit; - cb := NSObject(AFormHandle).lclGetCallback; - if not Assigned(cb) then Exit; - Result := cb.GetTarget; -end; - -function HWNDToForm(AFormHandle: HWND): TCustomForm; -var - obj : TObject; -begin - obj := HWNDToTargetObject(AFormHandle); - if Assigned(obj) and (obj is TCustomForm) - then Result := TCustomForm(obj) - else Result := nil; -end; - function NSObjectDebugStr(obj: NSObject): string; begin Result := IntToStr(PtrUInt(obj));