-
Notifications
You must be signed in to change notification settings - Fork 72
/
class_WM_Dlg.ahk
2318 lines (1944 loc) · 57.5 KB
/
class_WM_Dlg.ahk
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
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
/*
License: NO LICENSE
I (Noah Graydon) retain all rights and do not permit distribution, reproduction, or derivative works. I soley grant GitHub the required rights according to their terms of service; namely, GitHub users may view and fork this code.
*/
class WM_Dlg
{
__New()
{
global WM_Dlg
; Spacing is deliberate to indicate that these dialogs are needed by the other one.
this.HKDlg := new HKDlg("AddHKForSequence", "ModifyHKForSequence", "ValidateHK") ; Note: Pay close attention to the ShowHKDlg_ methods.
this.PrecisionDlg := new PrecisionDlg("AddPrecisionItem", "ModifyPrecisionItem", "ValidatePrecisionItem", "ValidateHK") ; Also uses WindowSetDlg.
this.SequenceDlg := new SequenceDlg("AddSequence", "ModifySequence") ; Also uses WindowSetDlg.
;~ this.LeapGesturesDlg := new LeapGestureDlg()
this.ImportDlg := new ImportDlg()
this.IntroDlg := new CIntroDlg()
WM_Dlg.1 := &this
}
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
/*
Author: Verdlin
Function: ShowHKDlg_ForSequence
Purpose:
Parameters
hOwner
bFromEdit
*/
ShowHKDlg_ForSequence(hOwner, bFromEdit, sHKBeingEdited="", sGestureBeingEdited="", sAppendToTitle="Add a Sequence Hotkey")
{
global g_bHasLeap
this.HKDlg.m_sAddFunc := "AddHKForSequence"
this.HKDlg.m_sEditFunc := "ModifyHKForSequence"
this.HKDlg.m_bMustHaveHotkey := !g_bHasLeap
this.HKDlg.ShowDlg(hOwner, bFromEdit, sHKBeingEdited, sGestureBeingEdited, sAppendToTitle)
return
}
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
/*
Author: Verdlin
Function: ShowHKDlg_ForGenericLV
Purpose:
Parameters
hOwner
*/
ShowHKDlg_ForGenericLV(hOwner, sHKBeingEdited="", sGestureBeingEdited="", sAppendToTitle="")
{
global g_bHasLeap
; No add function because, with the current design, you cannot add to the GenericLV (except for PrecisionDlg the override).
this.HKDlg.m_sAddFunc := ""
this.HKDlg.m_sEditFunc := "GenericLV_ModifyHK"
this.HKDlg.m_bMustHaveHotkey := !g_bHasLeap
this.HKDlg.ShowDlg(hOwner, true, sHKBeingEdited, sGestureBeingEdited, sAppendToTitle)
return
}
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
/*
Author: Verdlin
Function: ShowHKDlg_ForInteractive
Purpose:
Parameters
hOwner
*/
ShowHKDlg_ForInteractive(hOwner, sHKBeingEdited="", sGestureBeingEdited="", sAppendToTitle="")
{
; No add function because, with the current design, you cannot add to GenericLV (except for PrecisionDlg the override).
this.HKDlg.m_sAddFunc := ""
this.HKDlg.m_sEditFunc := "GenericLV_ModifyInteractive"
this.HKDlg.m_bMustHaveHotkey := false
this.HKDlg.ShowDlg(hOwner, true, sHKBeingEdited, sGestureBeingEdited, sAppendToTitle)
return
}
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
}
class PrecisionDlg
{
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
/*
Author: Verdlin
Function: __New
Purpose:
Parameters
sAddFunc:
sEditFunc:
sValidateFunc:
*/
__New(sAddFunc, sEditFunc, sValidateFunc, sHKDlgValidateFunc)
{
global
this.m_sAddFunc := sAddFunc
this.m_sEditFunc := sEditFunc
this.m_sValidateFunc := sValidateFunc
this.m_iOldX := iX
this.m_iOldY := iY
this.m_iOldW := iW
this.m_iOldH := iH
GUI PrecisionDlg_: New, hwndg_hPrecisionDlg -MaximizeBox -MinimizeBox
;------------------------------------------------------------------------
GUI, Add, GroupBox, x5 y0 w165 r8, Placement
GUI, Add, Text, x15 y25 w10 h13, %A_Space%x
GUI, Add, Text, x15 y53 w8 hp, %A_Space%y
GUI, Add, Text, x15 y81 w29 hp, %A_Space%width
GUI, Add, Text, x15 y109 w33 hp, %A_Space%height
GUI, Add, Edit, x92 y21 w40 h21 Limit5 Number vg_vEditX, %iX%
GUI, Add, Edit, x92 y49 wp hp Limit5 Number vg_vEditY, %iY%
GUI, Add, Edit, x92 y77 wp hp Limit5 Number vg_vEditW, %iW%
GUI, Add, Edit, x92 y105 wp hp Limit5 Number vg_vEditH, %iH%
GUI, Add, Button, x12 y146 w154 h23 gPrecisionDlg_WindowSet, &Set with Window
;------------------------------------------------------------------------
;------------------------------------------------------------------------
GUI, Add, GroupBox, x175 y0 w340 r14, Hotkey
this.HKDlg := new HKDlg(this.m_sAddFunc, this.m_sEditFunc, sHKDlgValidateFunc, "PrecisionDlg_", 175, 20)
;------------------------------------------------------------------------
GUI, Add, Button, x356 y260 w%g_iMSDNStdBtnW% h%g_iMSDNStdBtnH% gPrecisionDlg_OK vg_vHKDlg_OKBtn, OK ; g_vHKDlg_OKBtn is currentl;y enable/disabled in Validate_Error_Msg, ValidateHK, and HKDlg_GestureDDLProc
GUI, Add, Button, % "xp+" g_iMSDNStdBtnW+g_iMSDNStdBtnSpacing " yp wp hp gPrecisionDlg_Cancel", Cancel
this.WindowSetDlg := new WindowSetDlg("PrecisionDlg_")
return this
; HKDlg overries.
PrecisionDlg_WinProc:
{
g_vDlgs.PrecisionDlg.HKDlg.WinProc()
return
}
PrecisionDlg_RecordHK:
{
g_vDlgs.PrecisionDlg.HKDlg.RecordHK()
return
}
PrecisionDlg_LaunchGesturesDlg:
{
g_vDlgs.PrecisionDlg.HKDlg.LaunchGesturesDlg(g_hPrecisionDlg)
return
}
PrecisionDlg_GestureDDLProc:
{
g_vDlgs.PrecisionDlg.HKDlg.GestureDDLProc()
return
}
; End HKDlg overrides.
PrecisionDlg_WindowSet:
{
g_vDlgs.PrecisionDlg.WindowSetDlg.ShowDlg(g_hPrecisionDlg, "PrecisionDlg_")
return
}
PrecisionDlg_OK:
{
g_vDlgs.PrecisionDlg.GUIOK()
return
}
PrecisionDlg_GUIEscape:
{
g_vDlgs.PrecisionDlg.GUIEscape()
return
}
PrecisionDlg_Cancel:
PrecisionDlg_GUIClose:
{
g_vDlgs.PrecisionDlg.GUIClose()
return
}
}
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
/*
Author: Verdlin
Function: __Get
Purpose:
Parameters
*/
__Get(aName)
{
global
GUI, PrecisionDlg_:Default
if (aName = "m_hDlg")
return g_hPrecisionDlg
if (aName = "m_bHasLeap")
return g_bHasLeap
if (aName = "m_iX")
return GUIControlGet("", "g_vEditX")
if (aName = "m_iY")
return GUIControlGet("", "g_vEditY")
if (aName = "m_iWidth")
return GUIControlGet("", "g_vEditW")
if (aName = "m_iHeight")
return GUIControlGet("", "g_vEditH")
return
}
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
/*
Author: Verdlin
Function: Add
Purpose: To locaize dynamical function calls for Add (note: I tried to override __Call, but I was to dull to get that working properly.)
Parameters
*/
Add(sPlacement, sHK, sGestureID)
{
sFunc := this.m_sAddFunc ; Note; I also tried using Func() instead, for some reason, only the first parameter ever gets passed into the function.
return %sFunc%(sPlacement, sHK, sGestureID)
}
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
/*
Author: Verdlin
Function: Edit
Purpose:
Parameters
*/
Edit(sPlacement, sHK, sGestureID)
{
sFunc := this.m_sEditFunc
return %sFunc%(sPlacement, sHK, sGestureID)
}
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
/*
Author: Verdlin
Function: Validate
Purpose:
Parameters
*/
Validate(sHK, ByRef rsError)
{
sFunc := this.m_sValidateFunc
return %sFunc%(sHK, this.m_bUseEditFunc, rsError)
}
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
/*
Author: Verdlin
Function: GUIOK
Purpose:
Parameters
*/
GUIOK()
{
GUI PrecisionDlg_:Default
sHK := this.HKDlg.TranslateHKForSave()
if (!this.Validate(sHK, sError))
{
Msgbox(sError)
return ; Validation failed
}
; Not using associative array because that sorts members alphabetically.
sParse := "x|y|width|height"
sPlacement :=
Loop, Parse, sParse, |
sPlacement .= " " A_LoopField ": " this["m_i" A_LoopField] " "
sGestureID := this.HKDlg.m_sGesture
if (this.m_bUseEditFunc)
bSuccess := this.Edit(sPlacement, sHK, sGestureID)
else bSuccess := this.Add(sPlacement, sHK, sGestureID)
if (bSuccess)
this.GUIClose()
return
}
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
/*
Author: Verdlin
Function: GUIEscape
Purpose: Basically a wrapper to HKDlg.GUIEscape
Parameters
*/
GUIEscape()
{
if (this.HKDlg.GUIEscape())
this.GUIClose()
return
}
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
/*
Author: Verdlin
Function: GUIClose
Purpose:
Parameters
*/
GUIClose()
{
GUI, PrecisionDlg_: Hide
WinSet, Enable, , % "ahk_id" this.m_hOwner
WinActivate, % "ahk_id" this.m_hOwner
this.m_bIsActive := false
SuspendThreads("Off")
return
}
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
/*
Author: Verdlin
Function: ShowDlg
Purpose:
Parameters
hOwner:
sHKBeingEdited:
sGestureBeingEdited:
iX:
iY:
iW:
iH:
sAppendToTitle:
*/
ShowDlg(hOwner=0, sHKBeingEdited="", sGestureBeingEdited="", iX="", iY="", iW="", iH="", sAppendToTitle="Add a Placement")
{
GUI, PrecisionDlg_:Default
GUI, +Owner%hOwner%
WinSet, Disable,, ahk_id %hOwner%
this.m_hOwner := this.HKDlg.m_hOwner := hOwner
this.m_sHKBeingEdited := this.HKDlg.m_sHKBeingEdited := sHKBeingEdited
this.m_sGestureBeingEdited := this.HKDlg.m_sGestureBeingEdited := sGestureBeingEdited
this.m_bUseEditFunc := this.HKDlg.m_bUseEditFunc := !(sHKBeingEdited == A_Blank && sGestureBeingEdited == A_Blank)
; By settings the HKDlg vars, OnShowDlg will update controls that HKDlg are responsible for.
this.HKDlg.OnShowDlg()
; iX, iY, iW, iH.
this.m_iOldX := iX
this.m_iOldY := iY
this.m_iOldW := iW
this.m_iOldH := iH
GUI, PrecisionDlg_:Default
GUIControl,, g_vEditX, % this.m_iOldX
GUIControl,, g_vEditY, % this.m_iOldY
GUIControl,, g_vEditW, % this.m_iOldW
GUIControl,, g_vEditH, % this.m_iOldH
GUI, Show, x-32768 AutoSize, % "Precise Window Placement - " sAppendToTitle
CenterWndOnParent(this.m_hDlg, this.m_hOwner)
GUIControl, Focus, g_vEditX
this.m_bIsActive := true
return
}
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
}
class HKDlg
{
__New(sAddFunc, sEditFunc, sValidateFunc, sGUI="HKDlg_", iXOffset=0, iYOffset=0)
{
global
; The first three parameters here may be overriden externally.
this.m_bMustHaveHotkey := true
this.m_sAddFunc := sAddFunc
this.m_sEditFunc := sEditFunc
this.m_sValidateFunc := sValidateFunc
this.m_sGUI := sGUI
if (sGUI = "HKDlg_")
{
GUI %sGUI%: New, hwndg_hHKDlg, Record a Hotkey
GUI, Add, Button, x182 y244 w%g_iMSDNStdBtnW% h%g_iMSDNStdBtnH% vg_vHKDlg_OKBtn gHKDlg_OK, OK
GUI, Add, Button, % "xp+" g_iMSDNStdBtnW+g_iMSDNStdBtnSpacing " yp wp hp vg_vHKDlg_GUICancelBtn g" this.m_sGUI "GUIClose", Cancel
}
else GUI %sGUI%:Default
; Offset first controls by offsets passed in, and be sure that every following GUI, Add call uses coordinates relative to the last control that was added.
GUI, Add, Hotkey, % "x" 5+iXOffset " y" 8+iYOffset " w155 h20 hwndg_hHKDlg_Hotkey vg_vHKDlg_Hotkey g" this.m_sGUI "RecordHK"
GUI, Add, Checkbox, % "xp+175 yp+3 vg_vHKDlg_WinCheck g" this.m_sGUI "WinProc", Win
local iX := iXOffset+5
local iY := 0
local iYInc := 21
sModifiersAsPipes := this.m_sModifiersAsPipes
Loop, Parse, sModifiersAsPipes, |
{
iY := iYOffset+56
GUI, Add, Radio, % "x" iX " y" iY " w70 h21 Group vbMod" A_LoopField "Left g" this.m_sGUI "RecordHK", Left %A_LoopField%
GUI, Add, Radio, % "xp yp+" iYInc " wp hp vbMod" A_LoopField "Right g" this.m_sGUI "RecordHK ", Right %A_LoopField%
GUI, Add, Radio, % "xp yp+" iYInc "wp hp vbMod" A_LoopField "Either g" this.m_sGUI "RecordHK +Checked", Either %A_LoopField%
iX += 83
}
iX := iXOffset+5
iY := iYOffset+34
if (this.m_bHasLeap)
{
GUI, Add, Text, % "x" iX " yp+" iY-iYOffset " w50 h25", Gesture:
GUI, Add, DropDownList, % "xp+45 yp-3 w257 g" this.m_sGUI "GestureDDLProc vg_vHKDlg_Gesture", % "|" g_vLeap.m_vGesturesIni.GetSections("|", "C")
GUI, Add, Button, % "xp+258 yp-1 w25 hp+2 hwndg_hHKDlg_GCCBtn g" this.m_sGUI "LaunchGesturesDlg"
ILButton(g_hHKDlg_GCCBtn, "AutoLeap\Add.ico", 16, 16, 4)
iY := iYOffset+161
}
else iY := iYOffset+131
GUI, Add, Text, % "x" iX " y" iY " w" 330 " r5 vHotkeyWarnTxt Hidden", % g_sDefaultHotkeyWarnTxt
return this
HKDlg_GUIEscape:
{
g_vDlgs.HKDlg.GUIEscape()
return
}
HKDlg_GUIClose:
{
g_vDlgs.HKDlg.GUIClose()
return
}
HKDlg_WinProc:
{
g_vDlgs.HKDlg.WinProc()
return
}
HKDlg_RecordHK:
{
g_vDlgs.HKDlg.RecordHK()
return
}
HKDlg_LaunchGesturesDlg:
{
g_vDlgs.HKDlg.LaunchGesturesDlg(g_hHKDlg)
return
}
HKDlg_GestureDDLProc:
{
g_vDlgs.HKDlg.GestureDDLProc()
return
}
HKDlg_OK:
{
g_vDlgs.HKDlg.GUIOK()
return
}
}
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
/*
Author: Verdlin
Function: __Get
Purpose:
Parameters
*/
__Get(aName)
{
global
GUI, % this.m_sGUI ":Default"
if (aName = "m_hDlg")
return g_hHKDlg
if (aName = "m_sModifiersAsPipes")
return g_sModParse
if (aName = "m_sAbbrModParse")
return g_sAbbrModParse
if (aName = "m_bHasLeap")
return g_bHasLeap
if (aName = "m_sHotkey")
{
if (GUIControlGet("", "g_vHKDlg_WinCheck"))
local sWin := "#"
return sWin GUIControlGet("", "g_vHKDlg_Hotkey")
}
if (aName = "m_sGesture")
return GUIControlGet("", "g_vHKDlg_Gesture")
if (aName = "m_bWin")
return GUIControlGet("", "g_vHKDlg_WinCheck")
if (aName = "m_hFocused")
{
local sFocused, hFocused
GUIControlGet, sFocused, Focus
ControlGet, hFocused, hwnd,, %sFocused%
return hFocused
}
if (aName = "m_sFocused")
return GUIControlGet("Focus")
return
}
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
/*
Author: Verdlin
Function: Add
Purpose: To locaize dynamical function calls for Add (note: I tried to override __Call, but I was too dull to get that working properly.)
Parameters
sHK
sGestureID
*/
Add(sHK, sGestureID)
{
if (this.m_bUseEditFunc)
{
Msgbox("Internal Error: Hotkey Dialog is using the Add function when it should be using the Edit function")
return
}
sFunc := this.m_sAddFunc ; Note; I also tried using Func() instead, for some reason, only the first parameter ever gets passed into the function.
return %sFunc%(sHK, sGestureID)
}
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
/*
Author: Verdlin
Function: Edit
Purpose:
Parameters
sHK
sGestureID
*/
Edit(sHK, sGestureID)
{
if (!this.m_bUseEditFunc)
{
Msgbox("Internal Error: Hotkey Dialog is using the Edit function when it should be using the Add function")
return
}
sFunc := this.m_sEditFunc
return %sFunc%(sHK, sGestureID, this.m_bMustHaveHotkey)
}
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
/*
Author: Verdlin
Function: Validate
Purpose:
Parameters
sHK
*/
Validate(sHK, ByRef rsError)
{
sFunc := this.m_sValidateFunc
return %sFunc%(sHK, this.m_bUseEditFunc, rsError)
}
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
/*
Author: Verdlin
Function: WinProc
Purpose:
Parameters
*/
WinProc()
{
if (this.m_bWin)
{
GUIControl, Show, bModWinLeft
GUIControl, Show, bModWinRight
GUIControl, Show, bModWinEither
}
else
{
GUIControl, Hide, bModWinLeft
GUIControl, Hide, bModWinRight
GUIControl, Hide, bModWinEither
}
; Outputs an error or warning on HotkeyWarnTxt.
if (this.ValidateHK())
this.GestureDDLProc()
return
}
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
/*
Author: Verdlin
Function: RecordHK
Purpose:
Parameters
*/
RecordHK()
{
global g_VKsIni
this.ShowHideRadios()
if (this.HKHasTriggerKey(this.m_sHotkey))
{
; Outputs an error or warning on HotkeyWarnTxt
if (this.ValidateHK())
this.GestureDDLProc()
}
return
}
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
/*
Author: Verdlin
Function: LaunchGesturesDlg()
Purpose:
Parameters
*/
LaunchGesturesDlg(hOwner)
{
ShowControlCenterDlg(hOwner, this.m_sGesture, this.m_sGUI, "g_vHKDlg_Gesture")
return
}
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
/*
Author: Verdlin
Function: GestureDDLProc
Purpose:
Parameters
*/
GestureDDLProc()
{
sGestureID := this.m_sGesture
/*
g_vLeap.m_vGesturesIni := Gestures.ini
[Snap to Corner Left]
Activate=true
Hotkey=Win + Ctrl + Alt + L
GestureName=Left
[....]
*/
; Validate that this gesture is not mapped to any other action
bIsValid := core_ValidateGesture(sGestureID, this.m_bUseEditFunc, sError)
GUI, % this.m_sGUI ":Default"
if (bIsValid)
{ ; The gesture may be valid, but the hotkey may not!
if (this.ValidateHK())
{
sWarnTxt := GUIControlGet("", "HotkeyWarnTxt")
; Don't override validation if the hotkey is invalid.
if (sWarnTxt == A_Blank || sWarnTxt == this.m_sDefaultHotkeyWarnTxt)
GUIControl, Enable, g_vHKDlg_OKBtn
}
}
else
{
GUIControl,, HotkeyWarnTxt, % sError
GUIControl, Show, HotkeyWarnTxt
GUIControl, Disable, g_vHKDlg_OKBtn ; Instead of intruding with a MsgBox prompt, disable the OK button.
}
return
}
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
/*
Author: Verdlin
Function: GUIOK
Purpose:
Parameters
*/
GUIOK()
{
GUI, % this.m_sGUI ":Default"
sGestureID := this.m_sGesture
sHK := this.TranslateHKForSave()
if (sHK != "FALSE" && sHK != A_Blank) ; if there was an error, such as a blank hotkey, TranslateHKForSave returns "FALSE".
bCanClose := this.ValidateHK()
if (sGestureID != A_Blank)
bCanClose := core_ValidateGesture(sGestureID, this.m_bUseEditFunc, sError)
if (bCanClose)
{
if (this.m_bUseEditFunc)
bSuccess := this.Edit(sHK, sGestureID)
else bSuccess := this.Add(sHK, sGestureID)
if (bSuccess)
this.GUIClose()
}
else if (sError)
Msgbox(sError)
return
}
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
/*
Author: Verdlin
Function: GUIEscape
Purpose: To help avoid escaping while recording hotkeys, but still allow escaping in every other situation
Parameters
*/
GUIEscape()
{
if (InStr(this.m_sFocused, "msctls_hotkey32"))
{
sHK := this.m_sHotkey
StringReplace, sHK, sHK, Escape
GUIControl,, g_vHKDlg_Hotkey, % sHK "Escape"
return false
}
this.GUIClose()
return true
}
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
/*
Author: Verdlin
Function: GUIClose
Purpose:
Parameters
*/
GUIClose()
{
GUI HKDlg_:Hide
WinSetTitle, % "ahk_id" this.m_hDlg, Record a Hotkey
; Clear controls
GUIControl,, g_vHKDlg_Hotkey
GUIControl,, g_vHKDlg_Gesture, |
GUIControl,, g_vHKDlg_WinCheck, 0
this.CheckRadioBtns("Junk") ; This unchecks the radios.
this.ShowHideRadios("Junk") ; This hides the radios.
WinSet, Enable,, % "ahk_id" this.m_hOwner
WinActivate, % "ahk_id" this.m_hOwner
this.m_bIsActive := false
SuspendThreads("Off")
return true
}
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
ValidateHK()
{
sHK := this.TranslateHKForSave(true)
if (sHK == A_Blank)
{
GUIControl,, HotkeyWarnTxt
return true
}
SetFormat, Integer, d
bFuncRet := this.Validate(sHK, sError)
GUI, % this.m_sGUI ":Default"
if (bFuncRet) ; Hotkey passed application validation.
{
sHKInAHKFormat := this.m_sHotkey
Loop 4 ; Up to 3 Modifier keys, and 1 trigger key.
{
sThisKey := SubStr(sHKInAHKFormat, A_Index, 1)
if (sThisKey != "" && sThisKey != "^" && sThisKey != "!" && sThisKey != "+" && sThisKey != "#")
{
sTriggerKey := SubStr(sHKInAHKFormat, A_Index)
break
}
}
this.EscapeSpecialKeys(sTriggerKey)
iVK := g_VKsIni[sTriggerKey][sTriggerKey] ; TODO: Simple ini with just section and key, no val
; Ini is not perfect, but neither is GetKeyVK. Use ini first. If key is blank, use GetKeyVK.
iVKTest := GetKeyVK(sTriggerKey)
SetFormat, Integer, hex
iVKTest += 0
if (!iVK)
iVK := iVKTest
; I've tried using hex numbers, but AHK keeps removing the 000 parts in 0x0001
; I tested to see if this was OK; it's not. The 000s MUST be there for this to work
iModifiers := 0
if (InStr(sHKInAHKFormat, "^"))
iModifiers = 1
if (InStr(sHKInAHKFormat, "!"))
iModifiers += 2
if (InStr(sHKInAHKFormat, "+"))
iModifiers += 4
if (InStr(sHKInAHKFormat, "#"))
iModifiers += 8
if (iModifiers > 9)
iModifiers := (iModifiers == 10 ? 0x000a : iModifiers == 11 ? 0x000b : iModifiers == 12 ? 0x000c : iModifiers == 13 ? 0x000d : iModifiers == 14 ? 0x000e : iModifiers == 15 ? 0x000f : "")
if (DllCall("RegisterHotKey", "Ptr", "", "Int", iVK, "UInt", iModifiers, "UInt", iVK))
{
DllCall("UnregisterHotKey", "Ptr", "", "Int", iVK)
GUIControl,, HotkeyWarnTxt,
GUIControl, Hide, HotkeyWarnTxt
}
else
{
GUIControl,, HotkeyWarnTxt, % this.m_sDefaultHotkeyWarnTxt
GUIControl, Show, HotkeyWarnTxt
}
SetFormat, Integer, d
GUIControl, Enable, g_vHKDlg_OKBtn
}
else
{
GUIControl,, HotkeyWarnTxt, %sError%
GUIControl, Show, HotkeyWarnTxt
GUIControl, Disable, g_vHKDlg_OKBtn ; Instead of intruding with a MsgBox prompt, disable the OK button.
}
return bFuncRet
}
TranslateHKForDisplay()
{
sKey := this.m_sHotkey
StringReplace, sKey, sKey, `^, % this.GetLeftRightEither("bModCtrl") "Ctrl" A_Space
StringReplace, sKey, sKey, `!, % this.GetLeftRightEither("bModAlt") "Alt" A_Space
StringReplace, sKey, sKey, `+, % this.GetLeftRightEither("bModShift") "Shift" A_Space
StringReplace, sKey, sKey, `#, % this.GetLeftRightEither("bModWin") "Win" A_Space
StringReplace, sKey, sKey, sc135, NumpadDiv
StringReplace, sKey, sKey, `r,, All
Trim(sKey, A_Space)
Trim(sKey, "+")
Loop, Parse, sKey, %A_Space%
iCnt++
Loop, Parse, sKey, %A_Space%
{
if (A_Index == iCnt)
s .= A_LoopField
else s .= A_LoopField " + "
}
return s
}
TranslateHKForDlg(sHK, ByRef rbWin=0, ByRef rsLRCtrl="", ByRef rsLRAlt="", ByRef rsLRShift="", ByRef rsLRWin="")
{
rbWin := rsLRCtrl := rsLRAlt := rsLRShift := rsLRWin :=
sModifiersAsPipes := this.m_sModifiersAsPipes
Loop, Parse, sModifiersAsPipes, |
{
sMod := A_LoopField
Loop, Parse, sHK, +
{
sHKMod := Trim(A_LoopField)
if (Trim(sHKMod = "L" sMod))
rsLR%sMod% := "L"
else if (Trim(sHKMod = "R" sMod))
rsLR%sMod% := "R"
}
}
if (InStr(sHK, "Win"))
{
StringReplace, sHK, sHK, LWin%A_Space%,, All
StringReplace, sHK, sHK, RWin%A_Space%,, All
StringReplace, sHK, sHK, Win%A_Space%,, All
rbWin := true
}
return TranslateHKForHotkeyCmd(sHK) ; In Window Master.ahk
}
TranslateHKForSave(bValidateOnly=false)
{
sHK := this.TranslateHKForDisplay()
if (sHK == A_Blank && this.m_bMustHaveHotkey && !bValidateOnly)
{
Msgbox("You must record a complete hotkey to be used!")
return "FALSE"
}
; If the dialog is dismissed without ever recording a hotkey, then the hotkey is blank.
if (sHK == A_Blank && this.m_bMustHaveHotkey)
sHK := this.m_sHKBeingEdited
return sHK
}
GetLeftRightEither(sRadioCtrl)
{
return GUIControlGet("", sRadioCtrl "Left") ? "L" : GUIControlGet("", sRadioCtrl "Right") ? "R" : GUIControlGet("", sRadioCtrl "Either") ? "" : ""
}
CheckRadioBtns(sHK)
{
GUI, % this.m_sGUI ":Default"
this.TranslateHKForDlg(sHK, bWin, sLRCtrl, sLRAlt, sLRShift, sLRWin)
sVars := "sLRCtrl|sLRAlt|sLRShift|sLRWin"
Loop, Parse, sVars, |
{
sMod := SubStr(A_LoopFIeld, 4)
if (%A_LoopField% = "L")
GUIControl,, bMod%sMod%Left, 1
else if (%A_LoopField% = "R")
GUIControl,, bMod%sMod%Right, 1
else ; either
GUIControl,, bMod%sMod%Either, 1
}
return
}
HKHasTriggerKey(sKey)
{
return sKey != "^" && sKey != "!" && sKey != "+" && sKey != "+^" && sKey != "^!" && sKey != "+!" && sKey != "+^!"
}
HKHasModifier(sHK)
{
return (this.GetModifiersFromHK(sHK) != A_Blank)
}
GetModifiersFromHK(sHK)
{
if (InStr(sHK, "^"))
sMods .= "^|"
if (InStr(sHK, "!"))
sMods .= "!|"
if (InStr(sHK, "+"))
sMods .= "+|"
if (InStr(sHK, "#"))
sMods .= "#|"
return SubStr(sMods, 1, StrLen(sMods)-1)
}