Cocoa: Add Form Activation/Deactivation functionality

git-svn-id: trunk@43981 -
This commit is contained in:
freq 2014-02-09 16:08:54 +00:00
parent 867ea44084
commit 66611411f0
4 changed files with 57 additions and 18 deletions

View File

@ -48,6 +48,8 @@ type
function ResetCursorRects: Boolean; function ResetCursorRects: Boolean;
procedure BecomeFirstResponder; procedure BecomeFirstResponder;
procedure ResignFirstResponder; procedure ResignFirstResponder;
procedure DidBecomeKeyNotification;
procedure DidResignKeyNotification;
// non event methods // non event methods
function DeliverMessage(Msg: Cardinal; WParam: WParam; LParam: LParam): LResult; function DeliverMessage(Msg: Cardinal; WParam: WParam; LParam: LParam): LResult;
function GetPropStorage: TStringList; function GetPropStorage: TStringList;
@ -368,6 +370,9 @@ type
{ TCocoaWindowContent } { TCocoaWindowContent }
TCocoaWindowContent = objcclass(TCocoaCustomControl) TCocoaWindowContent = objcclass(TCocoaCustomControl)
protected
procedure didBecomeKeyNotification(sender: NSNotification); message 'didBecomeKeyNotification:';
procedure didResignKeyNotification(sender: NSNotification); message 'didResignKeyNotification:';
public public
isembedded: Boolean; // true - if the content is inside of another control, false - if the content is in its own window; isembedded: Boolean; // true - if the content is inside of another control, false - if the content is in its own window;
ownwin: NSWindow; ownwin: NSWindow;
@ -548,6 +553,18 @@ begin
Result:=true; Result:=true;
end; 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; function TCocoaWindowContent.lclOwnWindow: NSWindow;
begin begin
if not isembedded then if not isembedded then

View File

@ -1002,14 +1002,7 @@ begin
Result := False; Result := False;
end; end;
function TCocoaWidgetSet.WindowFromPoint(Point: TPoint): HWND; function ViewFromPoint(view: NSView;Point: TPoint): HWND;
var
winrect: TRect;
windows: NSArray;
win: integer;
window: NSWindow;
function ViewFromPoint(view:NSView): HWND;
var rect: TRect; var rect: TRect;
p:TPoint; p:TPoint;
begin begin
@ -1029,8 +1022,7 @@ begin
// debugln('No lcl'); // debugln('No lcl');
end; end;
function RecurseSubviews(view: NSView;Point: TPoint):HWND;
function RecurseSubviews(view:NSView):HWND;
var sv:integer; var sv:integer;
begin begin
// first check views subview if there is a embedded view // first check views subview if there is a embedded view
@ -1038,13 +1030,20 @@ begin
sv:=0; sv:=0;
while (Result=0) and (sv<view.subviews.count) do while (Result=0) and (sv<view.subviews.count) do
begin begin
Result:=RecurseSubviews(view.subviews.objectAtIndex(sv)); Result:=RecurseSubviews(view.subviews.objectAtIndex(sv),Point);
inc(sv) inc(sv)
end; end;
if Result=0 then if Result=0 then
Result:=ViewFromPoint(view); Result:=ViewFromPoint(view,Point);
end; end;
function TCocoaWidgetSet.WindowFromPoint(Point: TPoint): HWND;
var
winrect: TRect;
windows: NSArray;
win: integer;
window: NSWindow;
begin begin
Result := 0; Result := 0;
if not assigned(NSApp) then if not assigned(NSApp) then
@ -1054,14 +1053,17 @@ begin
for win := 0 to windows.count - 1 do for win := 0 to windows.count - 1 do
begin begin
window:=windows.objectAtIndex(win); window:=windows.objectAtIndex(win);
if window.isKeyWindow then
begin
winrect := window.lclFrame; winrect := window.lclFrame;
if PtInRect(winrect, Point) then if PtInRect(winrect, Point) then
begin begin
Result:=RecurseSubviews(window.contentView); Result:=RecurseSubviews(window.contentView, Point);
if Result<>0 then if Result<>0 then
exit; exit;
end; end;
end; end;
end;
end; end;

View File

@ -58,6 +58,9 @@ type
procedure boundsDidChange; virtual; procedure boundsDidChange; virtual;
procedure BecomeFirstResponder; virtual; procedure BecomeFirstResponder; virtual;
procedure ResignFirstResponder; virtual; procedure ResignFirstResponder; virtual;
procedure DidBecomeKeyNotification; virtual;
procedure DidResignKeyNotification; virtual;
function DeliverMessage(var Msg): LRESULT; virtual; overload; function DeliverMessage(var Msg): LRESULT; virtual; overload;
function DeliverMessage(Msg: Cardinal; WParam: WParam; LParam: LParam): LResult; virtual; overload; function DeliverMessage(Msg: Cardinal; WParam: WParam; LParam: LParam): LResult; virtual; overload;
procedure Draw(ControlContext: NSGraphicsContext; const bounds, dirty: NSRect); virtual; procedure Draw(ControlContext: NSGraphicsContext; const bounds, dirty: NSRect); virtual;
@ -967,6 +970,18 @@ begin
LCLSendKillFocusMsg(Target); LCLSendKillFocusMsg(Target);
end; 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; function TLCLCommonCallback.DeliverMessage(var Msg): LRESULT;
begin begin
Result := LCLMessageGlue.DeliverMessage(Target, Msg); Result := LCLMessageGlue.DeliverMessage(Target, Msg);

View File

@ -269,11 +269,13 @@ begin
else else
CocoaWidgetSet.SetMainMenu(0); CocoaWidgetSet.SetMainMenu(0);
LCLSendActivateMsg(Target, WA_ACTIVE, false); LCLSendActivateMsg(Target, WA_ACTIVE, false);
LCLSendSetFocusMsg(Target);
end; end;
procedure TLCLWindowCallback.Deactivate; procedure TLCLWindowCallback.Deactivate;
begin begin
LCLSendActivateMsg(Target, WA_INACTIVE, false); LCLSendActivateMsg(Target, WA_INACTIVE, false);
LCLSendKillFocusMsg(Target);
end; end;
procedure TLCLWindowCallback.CloseQuery(var CanClose: Boolean); procedure TLCLWindowCallback.CloseQuery(var CanClose: Boolean);
@ -420,6 +422,9 @@ var
NSView(APArams.WndParent).addSubView(cnt); NSView(APArams.WndParent).addSubView(cnt);
cnt.window.setAcceptsMouseMovedEvents(True); cnt.window.setAcceptsMouseMovedEvents(True);
cnt.callback.IsOpaque:=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;
end; end;