cocoa: hot keys handling for windowcontent view #33072

git-svn-id: trunk@57154 -
This commit is contained in:
dmitry 2018-01-27 04:49:42 +00:00
parent 756867c662
commit 96d01f3f8f
2 changed files with 38 additions and 0 deletions

View File

@ -503,6 +503,7 @@ type
ownwin: NSWindow;
popup_parent: HWND; // if not 0, indicates that we should set the popup parent
overlay: NSView;
function performKeyEquivalent(event: NSEvent): Boolean; override;
procedure resolvePopupParent(); message 'resolvePopupParent';
function lclOwnWindow: NSWindow; message 'lclOwnWindow';
procedure lclSetFrame(const r: TRect); override;
@ -1359,6 +1360,16 @@ begin
callback.DidResignKeyNotification;
end;
function TCocoaWindowContent.performKeyEquivalent(event: NSEvent): Boolean;
begin
// this event servers all TextEdit, ComboBoxes and Memos on a form.
// to do short keys for copy, paste, cut, etc...
Result := false;
NSResponderHotKeys(self, event, Result);
if not Result then
Result:=inherited performKeyEquivalent(event);
end;
procedure TCocoaWindowContent.resolvePopupParent();
var
lWindow: NSWindow;

View File

@ -95,6 +95,8 @@ function CFStringToData(AString: CFStringRef; Encoding: CFStringEncoding = DEFAU
function GetCurrentEventTime: double;
function GetMacOSXVersion: Integer;
procedure NSResponderHotKeys(trg: NSResponder; event: NSEvent; var handled: Boolean);
implementation
procedure ColorToRGBFloat(cl: TColorRef; var r,g,b: Single); inline;
@ -699,5 +701,30 @@ begin
Result := lMajor*$10000 + lMinor*$100 + lFix;
end;
procedure NSResponderHotKeys(trg: NSResponder; event: NSEvent; var handled: Boolean);
begin
// todo: system keys could be overriden. thus need to review the current
// keyboard configuration first. See "Key Bindings" at
// https://developer.apple.com/library/content/documentation/Cocoa/Conceptual/EventOverview/TextDefaultsBindings/TextDefaultsBindings.html
handled := false;
if (event.type_ = NSKeyDown) then
begin
if ((event.modifierFlags and NSCommandKeyMask) = 0) then Exit;
if Assigned(event.charactersIgnoringModifiers.UTF8String) then
begin
case event.charactersIgnoringModifiers.UTF8String^ of
'Z': handled := NSApplication(NSApp).sendAction_to_from(objcselector('redo:'), nil, trg);
'a': handled := NSApplication(NSApp).sendAction_to_from(objcselector('selectAll:'), nil, trg);
'c': handled := NSApplication(NSApp).sendAction_to_from(objcselector('copy:'), nil, trg);
'v': handled := NSApplication(NSApp).sendAction_to_from(objcselector('paste:'), nil, trg);
'x': handled := NSApplication(NSApp).sendAction_to_from(objcselector('cut:'), nil, trg);
'z': handled := NSApplication(NSApp).sendAction_to_from(objcselector('undo:'), nil, trg);
end;
end;
end;
end;
end.