From 66611411f03d599d1b18a44be4aed92a4f2e0971 Mon Sep 17 00:00:00 2001 From: freq Date: Sun, 9 Feb 2014 16:08:54 +0000 Subject: [PATCH] Cocoa: Add Form Activation/Deactivation functionality git-svn-id: trunk@43981 - --- lcl/interfaces/cocoa/cocoaprivate.pp | 17 ++++++++++++ lcl/interfaces/cocoa/cocoawinapi.inc | 38 ++++++++++++++------------ lcl/interfaces/cocoa/cocoawscommon.pas | 15 ++++++++++ lcl/interfaces/cocoa/cocoawsforms.pp | 5 ++++ 4 files changed, 57 insertions(+), 18 deletions(-) diff --git a/lcl/interfaces/cocoa/cocoaprivate.pp b/lcl/interfaces/cocoa/cocoaprivate.pp index b1a6a15c42..97d9918864 100644 --- a/lcl/interfaces/cocoa/cocoaprivate.pp +++ b/lcl/interfaces/cocoa/cocoaprivate.pp @@ -48,6 +48,8 @@ type function ResetCursorRects: Boolean; procedure BecomeFirstResponder; procedure ResignFirstResponder; + procedure DidBecomeKeyNotification; + procedure DidResignKeyNotification; // non event methods function DeliverMessage(Msg: Cardinal; WParam: WParam; LParam: LParam): LResult; function GetPropStorage: TStringList; @@ -368,6 +370,9 @@ type { TCocoaWindowContent } TCocoaWindowContent = objcclass(TCocoaCustomControl) + protected + procedure didBecomeKeyNotification(sender: NSNotification); message 'didBecomeKeyNotification:'; + procedure didResignKeyNotification(sender: NSNotification); message 'didResignKeyNotification:'; public isembedded: Boolean; // true - if the content is inside of another control, false - if the content is in its own window; ownwin: NSWindow; @@ -548,6 +553,18 @@ begin Result:=true; end; +procedure TCocoaWindowContent.didBecomeKeyNotification(sender: NSNotification); +begin + if Assigned(callback) then + callback.DidBecomeKeyNotification; +end; + +procedure TCocoaWindowContent.didResignKeyNotification(sender: NSNotification); +begin + if Assigned(callback) then + callback.DidResignKeyNotification; +end; + function TCocoaWindowContent.lclOwnWindow: NSWindow; begin if not isembedded then diff --git a/lcl/interfaces/cocoa/cocoawinapi.inc b/lcl/interfaces/cocoa/cocoawinapi.inc index 9e28e9cfa0..f8076e5109 100644 --- a/lcl/interfaces/cocoa/cocoawinapi.inc +++ b/lcl/interfaces/cocoa/cocoawinapi.inc @@ -1002,14 +1002,7 @@ begin Result := False; end; -function TCocoaWidgetSet.WindowFromPoint(Point: TPoint): HWND; -var - winrect: TRect; - windows: NSArray; - win: integer; - window: NSWindow; - -function ViewFromPoint(view:NSView): HWND; +function ViewFromPoint(view: NSView;Point: TPoint): HWND; var rect: TRect; p:TPoint; begin @@ -1029,8 +1022,7 @@ begin // debugln('No lcl'); end; - -function RecurseSubviews(view:NSView):HWND; +function RecurseSubviews(view: NSView;Point: TPoint):HWND; var sv:integer; begin // first check views subview if there is a embedded view @@ -1038,13 +1030,20 @@ begin sv:=0; while (Result=0) and (sv0 then - exit; + if window.isKeyWindow then + begin + winrect := window.lclFrame; + if PtInRect(winrect, Point) then + begin + Result:=RecurseSubviews(window.contentView, Point); + if Result<>0 then + exit; + end; end; end; end; diff --git a/lcl/interfaces/cocoa/cocoawscommon.pas b/lcl/interfaces/cocoa/cocoawscommon.pas index 2838ff9d99..5c4d683e97 100644 --- a/lcl/interfaces/cocoa/cocoawscommon.pas +++ b/lcl/interfaces/cocoa/cocoawscommon.pas @@ -58,6 +58,9 @@ type procedure boundsDidChange; virtual; procedure BecomeFirstResponder; virtual; procedure ResignFirstResponder; virtual; + procedure DidBecomeKeyNotification; virtual; + procedure DidResignKeyNotification; virtual; + function DeliverMessage(var Msg): LRESULT; virtual; overload; function DeliverMessage(Msg: Cardinal; WParam: WParam; LParam: LParam): LResult; virtual; overload; procedure Draw(ControlContext: NSGraphicsContext; const bounds, dirty: NSRect); virtual; @@ -967,6 +970,18 @@ begin LCLSendKillFocusMsg(Target); end; +procedure TLCLCommonCallback.DidBecomeKeyNotification; +begin + LCLSendActivateMsg(Target, WA_ACTIVE, false); + LCLSendSetFocusMsg(Target); +end; + +procedure TLCLCommonCallback.DidResignKeyNotification; +begin + LCLSendActivateMsg(Target, WA_INACTIVE, false); + LCLSendKillFocusMsg(Target); +end; + function TLCLCommonCallback.DeliverMessage(var Msg): LRESULT; begin Result := LCLMessageGlue.DeliverMessage(Target, Msg); diff --git a/lcl/interfaces/cocoa/cocoawsforms.pp b/lcl/interfaces/cocoa/cocoawsforms.pp index dba23097e5..f4f1fdb770 100644 --- a/lcl/interfaces/cocoa/cocoawsforms.pp +++ b/lcl/interfaces/cocoa/cocoawsforms.pp @@ -269,11 +269,13 @@ begin else CocoaWidgetSet.SetMainMenu(0); LCLSendActivateMsg(Target, WA_ACTIVE, false); + LCLSendSetFocusMsg(Target); end; procedure TLCLWindowCallback.Deactivate; begin LCLSendActivateMsg(Target, WA_INACTIVE, false); + LCLSendKillFocusMsg(Target); end; procedure TLCLWindowCallback.CloseQuery(var CanClose: Boolean); @@ -420,6 +422,9 @@ var NSView(APArams.WndParent).addSubView(cnt); cnt.window.setAcceptsMouseMovedEvents(True); cnt.callback.IsOpaque:=true; + NSNotificationCenter.defaultCenter.addObserver_selector_name_object(cnt, objcselector('didBecomeKeyNotification:'), NSWindowDidBecomeKeyNotification, cnt.window); + NSNotificationCenter.defaultCenter.addObserver_selector_name_object(cnt, objcselector('didResignKeyNotification:'), NSWindowDidResignKeyNotification, cnt.window); + end; end;