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;
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

View File

@ -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 (sv<view.subviews.count) do
begin
Result:=RecurseSubviews(view.subviews.objectAtIndex(sv));
Result:=RecurseSubviews(view.subviews.objectAtIndex(sv),Point);
inc(sv)
end;
if Result=0 then
Result:=ViewFromPoint(view);
Result:=ViewFromPoint(view,Point);
end;
function TCocoaWidgetSet.WindowFromPoint(Point: TPoint): HWND;
var
winrect: TRect;
windows: NSArray;
win: integer;
window: NSWindow;
begin
Result := 0;
if not assigned(NSApp) then
@ -1054,12 +1053,15 @@ begin
for win := 0 to windows.count - 1 do
begin
window:=windows.objectAtIndex(win);
winrect := window.lclFrame;
if PtInRect(winrect, Point) then
begin
Result:=RecurseSubviews(window.contentView);
if Result<>0 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;

View File

@ -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);

View File

@ -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;