-
Notifications
You must be signed in to change notification settings - Fork 1.7k
/
Accelerators.cpp
603 lines (546 loc) · 19.1 KB
/
Accelerators.cpp
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
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
/* Copyright 2022 the SumatraPDF project authors (see AUTHORS file).
License: Simplified BSD (see COPYING.BSD) */
#include "utils/BaseUtil.h"
#include "Settings.h"
#include "GlobalPrefs.h"
#include "Translations.h"
#include "Commands.h"
#include "Accelerators.h"
#include "utils/Log.h"
// http://www.kbdedit.com/manual/low_level_vk_list.html
#define VIRT_KEYS(V) \
V(VK_NUMPAD0, "numpad0") \
V(VK_NUMPAD1, "numpad1") \
V(VK_NUMPAD2, "numpad2") \
V(VK_NUMPAD3, "numpad3") \
V(VK_NUMPAD4, "numpad4") \
V(VK_NUMPAD5, "numpad5") \
V(VK_NUMPAD6, "numpad6") \
V(VK_NUMPAD7, "numpad7") \
V(VK_NUMPAD8, "numpad8") \
V(VK_NUMPAD9, "numpad9") \
V(VK_END, "End") \
V(VK_HOME, "Home") \
V(VK_LEFT, "Left") \
V(VK_RIGHT, "Right") \
V(VK_UP, "Up") \
V(VK_DOWN, "Down") \
V(VK_NEXT, "PageDown") \
V(VK_NEXT, "PgDown") \
V(VK_PRIOR, "PageUp") \
V(VK_PRIOR, "PgUp") \
V(VK_BACK, "Back") \
V(VK_BACK, "Backspace") \
V(VK_DELETE, "Del") \
V(VK_DELETE, "Delete") \
V(VK_INSERT, "Ins") \
V(VK_INSERT, "Insert") \
V(VK_ESCAPE, "Esc") \
V(VK_ESCAPE, "Escape") \
V(VK_RETURN, "Return") \
V(VK_SPACE, "Space") \
V(VK_MULTIPLY, "Multiply") \
V(VK_MULTIPLY, "Mult") \
V(VK_ADD, "Add") \
V(VK_SUBTRACT, "Subtract") \
V(VK_SUBTRACT, "Sub") \
V(VK_DIVIDE, "Divide") \
V(VK_DIVIDE, "Div") \
V(VK_HELP, "Help") \
V(VK_SELECT, "Select") \
V(VK_VOLUME_DOWN, "VolumeDown") \
V(VK_VOLUME_UP, "VolumeUp") \
V(VK_F1, "F1") \
V(VK_F2, "F2") \
V(VK_F3, "F3") \
V(VK_F4, "F4") \
V(VK_F5, "F5") \
V(VK_F6, "F6") \
V(VK_F7, "F7") \
V(VK_F8, "F8") \
V(VK_F9, "F9") \
V(VK_F10, "F10") \
V(VK_F11, "F11") \
V(VK_F12, "F12") \
V(VK_F13, "F13") \
V(VK_F14, "F14") \
V(VK_F15, "F15") \
V(VK_F16, "F16") \
V(VK_F17, "F17") \
V(VK_F18, "F18") \
V(VK_F19, "F19") \
V(VK_F20, "F20") \
V(VK_F21, "F21") \
V(VK_F22, "F22") \
V(VK_F23, "F23") \
V(VK_F24, "F24")
ACCEL gBuiltInAccelerators[] = {
{0, 'k', CmdScrollUp},
{0, 'j', CmdScrollDown},
{0, 'h', CmdScrollLeft},
{0, 'l', CmdScrollRight},
{FVIRTKEY, VK_UP, CmdScrollUp},
{FVIRTKEY, VK_DOWN, CmdScrollDown},
{FVIRTKEY, VK_LEFT, CmdScrollLeft},
{FVIRTKEY, VK_RIGHT, CmdScrollRight},
{FSHIFT | FVIRTKEY, VK_UP, CmdScrollUpHalfPage},
{FSHIFT | FVIRTKEY, VK_DOWN, CmdScrollDownHalfPage},
{FSHIFT | FVIRTKEY, VK_LEFT, CmdScrollLeftPage},
{FSHIFT | FVIRTKEY, VK_RIGHT, CmdScrollRightPage},
// TODO: maybe CmdGoToNextPage / CmdGoToPrevPage is better
{FVIRTKEY, VK_NEXT, CmdScrollDownPage},
{FVIRTKEY, VK_PRIOR, CmdScrollUpPage},
{FVIRTKEY, VK_SPACE, CmdScrollDownPage},
{FVIRTKEY, VK_RETURN, CmdScrollDownPage},
{FCONTROL | FVIRTKEY, VK_DOWN, CmdScrollDownPage},
{FSHIFT | FVIRTKEY, VK_SPACE, CmdScrollUpPage},
{FSHIFT | FVIRTKEY, VK_RETURN, CmdScrollUpPage},
{FCONTROL | FVIRTKEY, VK_UP, CmdScrollUpPage},
{0, 'n', CmdGoToNextPage},
//{FCONTROL | FVIRTKEY, VK_NEXT, CmdGoToNextPage},
{0, 'p', CmdGoToPrevPage},
//{FCONTROL | FVIRTKEY, VK_PRIOR, CmdGoToPrevPage},
{FVIRTKEY, VK_HOME, CmdGoToFirstPage},
{FCONTROL | FVIRTKEY, VK_HOME, CmdGoToFirstPage},
{FVIRTKEY, VK_END, CmdGoToLastPage},
{FCONTROL | FVIRTKEY, VK_END, CmdGoToLastPage},
{FVIRTKEY, VK_BACK, CmdNavigateBack},
{FALT | FVIRTKEY, VK_LEFT, CmdNavigateBack},
{FSHIFT | FVIRTKEY, VK_BACK, CmdNavigateForward},
{FALT | FVIRTKEY, VK_RIGHT, CmdNavigateForward},
{FCONTROL | FVIRTKEY, 'O', CmdOpenFile},
{FSHIFT | FCONTROL | FVIRTKEY, VK_RIGHT, CmdOpenNextFileInFolder},
{FSHIFT | FCONTROL | FVIRTKEY, VK_LEFT, CmdOpenPrevFileInFolder},
{FVIRTKEY, VK_F2, CmdRenameFile},
{FCONTROL | FVIRTKEY, 'W', CmdClose},
{FCONTROL | FVIRTKEY, 'N', CmdNewWindow},
{FSHIFT | FCONTROL | FVIRTKEY, 'N', CmdDuplicateInNewWindow},
{FCONTROL | FVIRTKEY, 'S', CmdSaveAs},
//{FSHIFT | FCONTROL | FVIRTKEY, 'S', CmdCreateShortcutToFile},
{FCONTROL | FVIRTKEY, 'A', CmdSelectAll},
{FCONTROL | FVIRTKEY, 'B', CmdFavoriteAdd},
{FCONTROL | FVIRTKEY, 'C', CmdCopySelection},
{FCONTROL | FVIRTKEY, VK_INSERT, CmdCopySelection},
{FCONTROL | FVIRTKEY, 'D', CmdProperties},
{FCONTROL | FVIRTKEY, 'F', CmdFindFirst},
{FCONTROL | FVIRTKEY, 'G', CmdGoToPage},
{0, 'g', CmdGoToPage},
{FCONTROL | FVIRTKEY, 'K', CmdCommandPalette},
{FSHIFT | FCONTROL | FVIRTKEY, 'K', CmdCommandPaletteNoFiles},
{FSHIFT | FCONTROL | FVIRTKEY, 'S', CmdSaveAnnotations},
{FCONTROL | FVIRTKEY, 'P', CmdPrint},
{FCONTROL | FVIRTKEY, 'Q', CmdExit},
{FCONTROL | FVIRTKEY, 'Y', CmdZoomCustom},
{FCONTROL | FVIRTKEY, '0', CmdZoomFitPage},
{FCONTROL | FVIRTKEY, VK_NUMPAD0, CmdZoomFitPage},
{FCONTROL | FVIRTKEY, '1', CmdZoomActualSize},
{FCONTROL | FVIRTKEY, VK_NUMPAD1, CmdZoomActualSize},
{FCONTROL | FVIRTKEY, '2', CmdZoomFitWidth},
{FCONTROL | FVIRTKEY, VK_NUMPAD2, CmdZoomFitWidth},
{FCONTROL | FVIRTKEY, '3', CmdZoomFitContent},
{FCONTROL | FVIRTKEY, VK_NUMPAD3, CmdZoomFitContent},
{FCONTROL | FVIRTKEY, VK_ADD, CmdZoomIn},
{FCONTROL | FVIRTKEY, VK_SUBTRACT, CmdZoomOut},
{FCONTROL | FVIRTKEY, VK_OEM_MINUS, CmdZoomOut},
{FCONTROL | FVIRTKEY, '6', CmdSinglePageView},
{FCONTROL | FVIRTKEY, VK_NUMPAD6, CmdSinglePageView},
{FCONTROL | FVIRTKEY, '7', CmdFacingView},
{FCONTROL | FVIRTKEY, VK_NUMPAD7, CmdFacingView},
{FCONTROL | FVIRTKEY, '8', CmdBookView},
{FCONTROL | FVIRTKEY, VK_NUMPAD8, CmdBookView},
{FSHIFT | FCONTROL | FVIRTKEY, VK_ADD, CmdRotateRight},
{FCONTROL | FVIRTKEY, VK_OEM_PLUS, CmdZoomIn},
{FSHIFT | FCONTROL | FVIRTKEY, VK_OEM_PLUS, CmdRotateRight},
{FVIRTKEY, VK_F3, CmdFindNext},
{FSHIFT | FVIRTKEY, VK_F3, CmdFindPrev},
{FCONTROL | FVIRTKEY, VK_F3, CmdFindNextSel},
{FSHIFT | FCONTROL | FVIRTKEY, VK_F3, CmdFindPrevSel},
{FCONTROL | FVIRTKEY, VK_F4, CmdClose},
{FVIRTKEY, VK_F6, CmdMoveFrameFocus},
{FVIRTKEY, VK_F8, CmdToggleToolbar},
{FVIRTKEY, VK_F9, CmdToggleMenuBar},
{FCONTROL | FVIRTKEY, 'L', CmdTogglePresentationMode},
{FVIRTKEY, VK_F5, CmdTogglePresentationMode},
{FSHIFT | FVIRTKEY, VK_F11, CmdTogglePresentationMode},
{FSHIFT | FCONTROL | FVIRTKEY, 'L', CmdToggleFullscreen},
{FVIRTKEY, VK_F11, CmdToggleFullscreen},
{FVIRTKEY, VK_F12, CmdToggleBookmarks},
{FSHIFT | FVIRTKEY, VK_F12, CmdToggleBookmarks},
{FSHIFT | FCONTROL | FVIRTKEY, VK_SUBTRACT, CmdRotateLeft},
{FSHIFT | FCONTROL | FVIRTKEY, VK_OEM_MINUS, CmdRotateLeft},
{FSHIFT | FCONTROL | FVIRTKEY, 'T', CmdReopenLastClosedFile},
{FCONTROL | FVIRTKEY, VK_NEXT, CmdNextTab},
{FCONTROL | FVIRTKEY, VK_PRIOR, CmdPrevTab},
{FCONTROL | FSHIFT | FVIRTKEY, 'D', CmdCycleTheme},
// need 2 entries for 'a' and 'Shift + a'
// TODO: maybe add CmdCreateAnnotHighlightAndOpenWindow (kind of clumsy)
{0, 'a', CmdCreateAnnotHighlight},
{0, 'A', CmdCreateAnnotHighlight},
{0, 'u', CmdCreateAnnotUnderline},
{0, 'U', CmdCreateAnnotUnderline},
{0, 'i', CmdInvertColors},
{0, 'I', CmdTogglePageInfo},
{FVIRTKEY, VK_DELETE, CmdDeleteAnnotation},
{0, 'q', CmdCloseCurrentDocument},
{0, 'r', CmdReloadDocument},
{0, 'z', CmdToggleZoom},
{0, 'f', CmdToggleFullscreen},
{0, '[', CmdRotateLeft},
{0, ']', CmdRotateRight},
{0, 'm', CmdShowCursorPosition},
{0, 'w', CmdPresentationWhiteBackground},
// // for Logitech's wireless presenters which target PowerPoint's shortcuts
{0, '.', CmdPresentationBlackBackground},
{0, 'c', CmdToggleContinuousView},
};
static void SkipWS(const char*& s) {
while (*s) {
if (!str::IsWs(*s)) {
return;
}
s++;
}
}
static void SkipPlusOrMinus(const char*& s) {
if (*s == '+') {
s++;
return;
}
if (*s == '-') {
s++;
return;
}
}
static bool SkipVirtKey(const char*& s, const char* key) {
if (!str::StartsWithI(s, key)) {
return false;
}
s += str::Len(key);
SkipWS(s);
SkipPlusOrMinus(s);
SkipWS(s);
return true;
}
#define KEY_NAME(id, txt) txt "\0"
SeqStrings gVirtKeyNames = VIRT_KEYS(KEY_NAME) "\0";
#undef KEY_NAME
#define KEY_ID(id, txt) id,
WORD gVirtKeysIds[] = {VIRT_KEYS(KEY_ID)};
#undef KEY_ID
// parses virtual keys like F1, Del, Backspace etc.
// returns 0 if not a known name of virtual key
static WORD ParseVirtKey(const char* s) {
int idx = seqstrings::StrToIdxIS(gVirtKeyNames, s);
if (idx < 0) {
return 0;
}
CrashIf(idx >= dimof(gVirtKeysIds));
WORD keyId = gVirtKeysIds[idx];
return keyId;
}
// Parses a string like Ctrl+Shift+A into ACCEL structure
// We accept variants: "Ctrl+A", "Ctrl-A", "Ctrl + A"
static bool ParseShortcut(const char* shortcut, ACCEL& accel) {
BYTE fVirt = 0;
WORD key = 0;
again:
SkipWS(shortcut);
if (SkipVirtKey(shortcut, "alt")) {
fVirt |= (FALT | FVIRTKEY);
goto again;
}
if (SkipVirtKey(shortcut, "shift")) {
fVirt |= (FSHIFT | FVIRTKEY);
goto again;
}
if (SkipVirtKey(shortcut, "ctrl")) {
fVirt |= (FCONTROL | FVIRTKEY);
goto again;
}
accel.fVirt = fVirt;
accel.key = ParseVirtKey(shortcut);
if (accel.key != 0) {
accel.fVirt |= FVIRTKEY;
return true;
}
// now we expect a character like 'a' or 'P'
char c = *shortcut++;
if (!c) {
return false;
}
if (accel.fVirt != 0) {
// if we have ctrl/alt/shift, convert 'a' - 'z' into 'A' - 'Z'
if (c >= 'a' && c <= 'z') {
c -= ('a' - 'A');
}
}
accel.key = c;
return true;
}
static const char* getVirt(BYTE key, bool isEng) {
// https://docs.microsoft.com/en-us/windows/win32/inputdev/virtual-key-codes
// Note: might need to add if we add more shortcuts
switch (key) {
case VK_END:
return "End";
case VK_HOME:
return "Home";
case VK_LEFT:
if (!isEng) {
return "<-";
}
return "Left";
case VK_RIGHT:
if (!isEng) {
return "->";
}
return "Right";
case VK_UP:
return "Up";
case VK_DOWN:
return "Down";
case VK_NEXT:
return "PageDown";
case VK_PRIOR:
return "PageUp";
case VK_BACK:
return "Backspace";
case VK_DELETE:
return "Del";
case VK_INSERT:
return "Insert";
case VK_ESCAPE:
return "Esc";
case VK_RETURN:
return "Return";
case VK_SPACE:
return "Space";
case VK_MULTIPLY:
return "*";
case VK_ADD:
case VK_OEM_PLUS:
return "+";
case VK_SUBTRACT:
case VK_OEM_MINUS:
return "-";
case VK_DIVIDE:
return "/";
case VK_HELP:
return "Help";
case VK_SELECT:
return "Select";
}
return nullptr;
}
void AppendAccelKeyToMenuString(str::Str& str, const ACCEL& a) {
auto lang = trans::GetCurrentLangCode();
bool isEng = str::IsEmpty(lang) || str::Eq(lang, "en");
bool isGerman = str::Eq(lang, "de");
str.Append("\t"); // marks start of an accelerator in menu item
BYTE virt = a.fVirt;
if (virt & FALT) {
const char* s = "Alt + ";
if (isGerman) {
s = "Größe + ";
}
str.Append(s);
}
if (virt & FCONTROL) {
const char* s = "Ctrl + ";
if (isGerman) {
s = "Strg + ";
}
str.Append(s);
}
if (virt & FSHIFT) {
const char* s = "Shift + ";
if (isGerman) {
s = "Umschalt + ";
}
str.Append(s);
}
bool isVirt = virt & FVIRTKEY;
BYTE key = a.key;
if (isVirt && key >= VK_F1 && key <= VK_F24) {
int n = key - VK_F1 + 1;
str.AppendFmt("F%d", n);
return;
}
if (isVirt && key >= VK_NUMPAD0 && key <= VK_NUMPAD9) {
WCHAR c = (WCHAR)key - VK_NUMPAD0 + '0';
str.AppendChar(c);
return;
}
if (isVirt) {
const char* s = getVirt(key, isEng);
if (s) {
str.Append(s);
return;
}
}
// virtual codes overlap with some ascii chars like '-' is VK_INSERT
// so for non-virtual assume it's a single char
bool isAscii = (key >= 'A' && key <= 'Z') || (key >= 'a' && key <= 'z') || (key >= '0' && key <= '9');
if (isAscii) {
str.AppendChar((char)key);
return;
}
logf("Unknown key: 0x%x, virt: 0x%x\n", key, virt);
ReportIf(true);
}
static bool SameAccelKey(const ACCEL& a1, const ACCEL& a2) {
if (a1.fVirt != a2.fVirt) {
return false;
}
if (a1.key != a2.key) {
return false;
}
return true;
}
// clang-format off
static WORD gNotSafeKeys[] = {
VK_LEFT,
VK_RIGHT,
VK_UP,
VK_DOWN,
VK_SPACE,
VK_RETURN,
VK_INSERT,
VK_DELETE,
VK_BACK,
VK_HOME,
VK_END
};
// clang-format on
// a hackish way to determine if we should allow processing a given
// accelerator in custom controls. This is to disable accelerators
// like 'n' or 'left arrow' in e.g. edit control so that they don't
// block regular processing of key events and mess up edit control
// at the same time, we do want most accelerators to be enabed even
// if edit or tree view control has focus
static bool IsSafeAccel(const ACCEL& a) {
WORD k = a.key;
if (a.fVirt == 0) {
// regular keys like 'n', without any shift / alt modifier
return false;
}
for (WORD notSafe : gNotSafeKeys) {
if (notSafe == k) {
return false;
}
}
return true;
}
ACCEL* gAccels = nullptr;
int gAccelsCount = 0;
static HACCEL gAccelTables[3] = {
nullptr, // for all but edit and tree view
nullptr, // for edit
nullptr, // for tree view
};
/* returns a pointer to HACCEL so that we can update it and message loop will use
the latest version */
static void CreateSumatraAcceleratorTable() {
CrashIf(gAccelTables[0] || gAccelTables[1] || gAccelTables[2]);
int nBuiltIn = (int)dimof(gBuiltInAccelerators);
int nCustomShortcuts = 0;
if (gGlobalPrefs->shortcuts) {
nCustomShortcuts = gGlobalPrefs->shortcuts->isize();
}
// build a combined accelerator table of those defined in settings file
// and built-in shortcuts. Custom shortcuts over-ride built-in
int nMax = nBuiltIn + nCustomShortcuts;
// https://github.com/sumatrapdfreader/sumatrapdf/issues/2981
// sizeof(ACCEL) is 6 so odd number will cause treeViewAccels to
// be mis-aligined. Rounding to 2 should be enoug, do 4 for extra safety
nMax = RoundUp(nMax, 4);
ACCEL* accels = AllocArray<ACCEL>(nMax);
int nAccels = 0;
// perf: only 1 allocation for 2 arrays
ACCEL* toFreeAccels = AllocArray<ACCEL>(nMax * 2);
ACCEL* editAccels = toFreeAccels;
ACCEL* treeViewAccels = toFreeAccels + nMax;
int nEditAccels = 0;
int nTreeViewAccels = 0;
for (Shortcut* shortcut : *gGlobalPrefs->shortcuts) {
char* cmd = shortcut->cmd;
int cmdId = GetCommandIdByName(cmd);
if (cmdId < 0) {
// TODO: make it a notification
logf("CreateSumatraAcceleratorTable: unknown cmd name '%s'\n", cmd);
continue;
}
ACCEL accel = {};
accel.cmd = cmdId;
if (!ParseShortcut(shortcut->key, accel)) {
// TODO: make it a notification
logf("CreateSumatraAcceleratorTable: bad shortcut '%s'\n", shortcut->key);
continue;
}
accels[nAccels++] = accel;
if (IsSafeAccel(accel)) {
editAccels[nEditAccels++] = accel;
treeViewAccels[nTreeViewAccels++] = accel;
}
if (cmdId == CmdToggleBookmarks && !IsSafeAccel(accel)) {
// https://github.com/sumatrapdfreader/sumatrapdf/issues/2832
treeViewAccels[nTreeViewAccels++] = accel;
}
}
// add built-in but only if the shortcut doesn't conflict with custom shortcut
nCustomShortcuts = nAccels;
for (ACCEL accel : gBuiltInAccelerators) {
bool shortcutExists = false;
for (int i = 0; !shortcutExists && i < nAccels; i++) {
ACCEL accelExisting = accels[i];
shortcutExists = SameAccelKey(accels[i], accel);
}
if (shortcutExists) {
continue;
}
accels[nAccels++] = accel;
if (IsSafeAccel(accel)) {
editAccels[nEditAccels++] = accel;
treeViewAccels[nTreeViewAccels++] = accel;
}
}
gAccels = accels;
gAccelsCount = nAccels;
gAccelTables[0] = CreateAcceleratorTableW(gAccels, gAccelsCount);
CrashIf(gAccelTables[0] == nullptr);
gAccelTables[1] = CreateAcceleratorTableW(editAccels, nEditAccels);
CrashIf(gAccelTables[1] == nullptr);
gAccelTables[2] = CreateAcceleratorTableW(treeViewAccels, nTreeViewAccels);
CrashIf(gAccelTables[2] == nullptr);
free(toFreeAccels);
}
void FreeAcceleratorTables() {
DestroyAcceleratorTable(gAccelTables[0]);
DestroyAcceleratorTable(gAccelTables[1]);
DestroyAcceleratorTable(gAccelTables[2]);
gAccelTables[0] = nullptr;
gAccelTables[1] = nullptr;
gAccelTables[2] = nullptr;
free(gAccels);
gAccels = nullptr;
}
void ReCreateSumatraAcceleratorTable() {
FreeAcceleratorTables();
CreateSumatraAcceleratorTable();
}
HACCEL* GetAcceleratorTables() {
if (gAccelTables[0] == nullptr) {
CreateSumatraAcceleratorTable();
}
return gAccelTables;
}
bool GetAccelByCmd(int cmdId, ACCEL& accelOut) {
for (int i = 0; i < gAccelsCount; i++) {
ACCEL& a = gAccels[i];
if (a.cmd == cmdId) {
accelOut = a;
return true;
}
}
return false;
}