mirror of
https://gitlab.com/freepascal.org/lazarus/lazarus.git
synced 2025-08-24 20:19:23 +02:00
cocoa: using a single method to get unmodified character in a key event. based on the patch by Zoë Peterson. #35538
git-svn-id: trunk@61212 -
This commit is contained in:
parent
1740585023
commit
e714d64672
@ -220,9 +220,21 @@ type
|
|||||||
function performDragOperation(sender: NSDraggingInfoProtocol): LCLObjCBoolean; override;
|
function performDragOperation(sender: NSDraggingInfoProtocol): LCLObjCBoolean; override;
|
||||||
end;
|
end;
|
||||||
|
|
||||||
|
function NSEventRawKeyChar(ev: NSEvent): System.WideChar;
|
||||||
|
|
||||||
implementation
|
implementation
|
||||||
|
|
||||||
|
function NSEventRawKeyChar(ev: NSEvent): System.WideChar;
|
||||||
|
var
|
||||||
|
m : NSString;
|
||||||
|
begin
|
||||||
|
m := ev.charactersIgnoringModifiers;
|
||||||
|
if m.length <> 1 then
|
||||||
|
Result := #0
|
||||||
|
else
|
||||||
|
Result := System.WideChar(m.characterAtIndex(0));
|
||||||
|
end;
|
||||||
|
|
||||||
|
|
||||||
{ TCocoaDesignOverlay }
|
{ TCocoaDesignOverlay }
|
||||||
|
|
||||||
@ -287,6 +299,7 @@ end;
|
|||||||
procedure NSResponderHotKeys(asender: NSResponder; event: NSEvent; var handled: LCLObjCBoolean; atarget: NSResponder);
|
procedure NSResponderHotKeys(asender: NSResponder; event: NSEvent; var handled: LCLObjCBoolean; atarget: NSResponder);
|
||||||
var
|
var
|
||||||
undoManager: NSUndoManager;
|
undoManager: NSUndoManager;
|
||||||
|
ch : System.WideChar;
|
||||||
begin
|
begin
|
||||||
// todo: system keys could be overriden. thus need to review the current
|
// todo: system keys could be overriden. thus need to review the current
|
||||||
// keyboard configuration first. See "Key Bindings" at
|
// keyboard configuration first. See "Key Bindings" at
|
||||||
@ -297,30 +310,28 @@ begin
|
|||||||
begin
|
begin
|
||||||
if ((event.modifierFlags and NSCommandKeyMask) = 0) then Exit;
|
if ((event.modifierFlags and NSCommandKeyMask) = 0) then Exit;
|
||||||
|
|
||||||
if Assigned(event.charactersIgnoringModifiers.UTF8String) then
|
ch := NSEventRawKeyChar(event);
|
||||||
begin
|
case ch of
|
||||||
case event.charactersIgnoringModifiers.UTF8String^ of
|
'a': handled := NSApplication(NSApp).sendAction_to_from(objcselector('selectAll:'), atarget, asender);
|
||||||
'a': handled := NSApplication(NSApp).sendAction_to_from(objcselector('selectAll:'), atarget, asender);
|
'c': handled := NSApplication(NSApp).sendAction_to_from(objcselector('copy:'), atarget, asender);
|
||||||
'c': handled := NSApplication(NSApp).sendAction_to_from(objcselector('copy:'), atarget, asender);
|
'v': handled := NSApplication(NSApp).sendAction_to_from(objcselector('paste:'), atarget, asender);
|
||||||
'v': handled := NSApplication(NSApp).sendAction_to_from(objcselector('paste:'), atarget, asender);
|
'x': handled := NSApplication(NSApp).sendAction_to_from(objcselector('cut:'), atarget, asender);
|
||||||
'x': handled := NSApplication(NSApp).sendAction_to_from(objcselector('cut:'), atarget, asender);
|
'z':
|
||||||
'z':
|
begin
|
||||||
|
undoManager := atarget.undoManager;
|
||||||
|
if Assigned(undoManager) and undoManager.canUndo then
|
||||||
begin
|
begin
|
||||||
undoManager := atarget.undoManager;
|
handled := true;
|
||||||
if Assigned(undoManager) and undoManager.canUndo then
|
undoManager.undo;
|
||||||
begin
|
|
||||||
handled := true;
|
|
||||||
undoManager.undo;
|
|
||||||
end;
|
|
||||||
end;
|
end;
|
||||||
'Z':
|
end;
|
||||||
|
'Z':
|
||||||
|
begin
|
||||||
|
undoManager := atarget.undoManager;
|
||||||
|
if Assigned(undoManager) and undoManager.canRedo then
|
||||||
begin
|
begin
|
||||||
undoManager := atarget.undoManager;
|
handled := true;
|
||||||
if Assigned(undoManager) and undoManager.canRedo then
|
undoManager.redo;
|
||||||
begin
|
|
||||||
handled := true;
|
|
||||||
undoManager.redo;
|
|
||||||
end;
|
|
||||||
end;
|
end;
|
||||||
end;
|
end;
|
||||||
end;
|
end;
|
||||||
@ -331,21 +342,22 @@ function TCocoaWindowContent.performKeyEquivalent(event: NSEvent): LCLObjCBoolea
|
|||||||
var
|
var
|
||||||
resp : NSResponder;
|
resp : NSResponder;
|
||||||
wn : NSWindow;
|
wn : NSWindow;
|
||||||
|
ch : System.WideChar;
|
||||||
begin
|
begin
|
||||||
Result := false;
|
Result := false;
|
||||||
|
|
||||||
// If the form has a default or cancel button, capture Return and Escape to
|
// If the form has a default or cancel button, capture Return and Escape to
|
||||||
// prevent further processing. Actually clicking the buttons is handled in
|
// prevent further processing. Actually clicking the buttons is handled in
|
||||||
// the LCL in response to the keyUp
|
// the LCL in response to the keyUp
|
||||||
if Assigned(wincallback) and (event.modifierFlags_ = 0) and
|
if Assigned(wincallback) and (event.modifierFlags_ = 0) then
|
||||||
(event.charactersIgnoringModifiers.length = 1) and
|
|
||||||
(((event.charactersIgnoringModifiers.characterAtIndex(0) = NSCarriageReturnCharacter) and
|
|
||||||
wincallback.HasDefaultControl) or
|
|
||||||
((event.charactersIgnoringModifiers.characterAtIndex(0) = 27{Escape}) and
|
|
||||||
wincallback.HasCancelControl)) then
|
|
||||||
begin
|
begin
|
||||||
Result := true;
|
ch := NSEventRawKeyChar(event);
|
||||||
Exit;
|
if (((ch = System.WideChar(NSCarriageReturnCharacter)) and wincallback.HasDefaultControl)
|
||||||
|
or ((ch = #27{Escape}) and wincallback.HasCancelControl)) then
|
||||||
|
begin
|
||||||
|
Result := true;
|
||||||
|
Exit;
|
||||||
|
end;
|
||||||
end;
|
end;
|
||||||
|
|
||||||
// Support Cut/Copy/Paste if the firstResponder is an NSTextView.
|
// Support Cut/Copy/Paste if the firstResponder is an NSTextView.
|
||||||
|
Loading…
Reference in New Issue
Block a user