-
Notifications
You must be signed in to change notification settings - Fork 2
/
OTA.KeyboardBinding.pas
72 lines (60 loc) · 1.91 KB
/
OTA.KeyboardBinding.pas
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
unit OTA.KeyboardBinding;
interface
uses
System.Classes, ToolsAPI;
type
TOTA_KeyboardBinding = class(TNotifierObject, IOTAKeyboardBinding)
private
FKeyProc: TKeyBindingProc;
FMenuItemName: string;
FDisplayName: string;
FShortCuts: TArray<TShortCut>;
procedure DefaultKeyProc(const Context: IOTAKeyContext; KeyCode: TShortcut; var
BindingResult: TKeyBindingResult);
protected
function GetBindingType: TBindingType;
function GetDisplayName: string;
function GetName: string;
procedure BindKeyboard(const BindingServices: IOTAKeyBindingServices);
public
constructor Create(aMenuItemName: string; aDisplayName: string = '';
aShortCuts: TArray<TShortCut> = []; aKeyProc: TKeyBindingProc = nil);
end;
implementation
uses
Winapi.Windows, Vcl.Menus;
procedure TOTA_KeyboardBinding.BindKeyboard(
const BindingServices: IOTAKeyBindingServices);
begin
BindingServices.AddKeyBinding(FShortCuts, FKeyProc, nil, kfImplicitShift or kfImplicitModifier or kfImplicitKeypad, '', FMenuItemName)
end;
procedure TOTA_KeyboardBinding.DefaultKeyProc(const Context: IOTAKeyContext;
KeyCode: TShortcut; var BindingResult: TKeyBindingResult);
begin
BindingResult := TKeyBindingResult.krUnhandled;
end;
constructor TOTA_KeyboardBinding.Create(aMenuItemName: string; aDisplayName:
string = ''; aShortCuts: TArray<TShortCut> = []; aKeyProc: TKeyBindingProc
= nil);
begin
inherited Create;
FMenuItemName := aMenuItemName;
FShortCuts := Copy(aShortCuts, Low(aShortCuts), Length(aShortCuts));
if Assigned(aKeyProc) then
FKeyProc := aKeyProc
else
FKeyProc := DefaultKeyProc;
end;
function TOTA_KeyboardBinding.GetBindingType: TBindingType;
begin
Result := TBindingType.btPartial;
end;
function TOTA_KeyboardBinding.GetDisplayName: string;
begin
Result := FDisplayName;
end;
function TOTA_KeyboardBinding.GetName: string;
begin
Result := FMenuItemName;
end;
end.