-
Notifications
You must be signed in to change notification settings - Fork 4
/
Copy pathcjsontree.asm
2514 lines (2139 loc) · 88.5 KB
/
cjsontree.asm
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
.686
.MMX
.XMM
.model flat,stdcall
option casemap:none
include \masm32\macros\macros.asm
;DEBUG32 EQU 1
;EXPERIMENTAL_ARRAYNAME_STACK EQU 1 ; Experimental, doesnt seem to work properly, so use if you uncomment, use with caution
IFDEF DEBUG32
echo
echo ------------------------------------------
echo DEBUG32 - Debugging Enabled
echo ------------------------------------------
echo
PRESERVEXMMREGS equ 1
includelib M:\Masm32\lib\Debug32.lib
DBG32LIB equ 1
DEBUGEXE textequ <'M:\Masm32\DbgWin.exe'>
include M:\Masm32\include\debug32.inc
ENDIF
;LIBCJSON EQU 1 ; comment out to use cjson.lib library instead of libcjson.lib
include cjsontree.inc
include statusbar.asm
include ini.asm
include menus.asm
include toolbar.asm
include edit.asm
;include TVFind.asm
include search.asm
include saveexport.asm
include clipboard.asm
IFDEF EXPERIMENTAL_ARRAYNAME_STACK
include stack.asm
ENDIF
.code
start:
Invoke GetModuleHandle,NULL
mov hInstance, eax
invoke LoadAccelerators, hInstance, ACCTABLE
mov hAcc, eax
Invoke GetCommandLine
mov CommandLine, eax
Invoke InitCommonControls
mov icc.dwSize, sizeof INITCOMMONCONTROLSEX
mov icc.dwICC, ICC_COOL_CLASSES or ICC_STANDARD_CLASSES or ICC_WIN95_CLASSES
Invoke InitCommonControlsEx, offset icc
Invoke IniCreateFilename, Addr szIniFilename, NULL
Invoke CmdLineProcess
Invoke WinMain, hInstance, NULL, CommandLine, SW_SHOWDEFAULT
Invoke ExitProcess, eax
;-------------------------------------------------------------------------------------
; WinMain
;-------------------------------------------------------------------------------------
WinMain proc hInst:HINSTANCE,hPrevInst:HINSTANCE,CmdLine:LPSTR,CmdShow:DWORD
LOCAL wc:WNDCLASSEX
LOCAL msg:MSG
mov wc.cbSize, sizeof WNDCLASSEX
mov wc.style, CS_HREDRAW or CS_VREDRAW
mov wc.lpfnWndProc, offset WndProc
mov wc.cbClsExtra, NULL
mov wc.cbWndExtra, DLGWINDOWEXTRA
push hInst
pop wc.hInstance
mov wc.hbrBackground, COLOR_BTNFACE+1 ; COLOR_WINDOW+1
mov wc.lpszMenuName, IDM_MENU
mov wc.lpszClassName, offset ClassName
Invoke LoadIcon, hInstance, ICO_MAIN ; resource icon for main application icon
mov hICO_MAIN, eax ; main application icon
mov wc.hIcon, eax
mov wc.hIconSm, eax
Invoke LoadCursor, NULL, IDC_ARROW
mov wc.hCursor,eax
Invoke RegisterClassEx, addr wc
Invoke CreateDialogParam, hInstance, IDD_DIALOG, NULL, addr WndProc, NULL
mov hWnd, eax
Invoke ShowWindow, hWnd, SW_SHOWNORMAL
Invoke UpdateWindow, hWnd
.WHILE TRUE
invoke GetMessage, addr msg, NULL, 0, 0
.BREAK .if !eax
Invoke TranslateAccelerator, hWnd, hAcc, addr msg
.IF eax == 0
Invoke IsDialogMessage, hWnd, addr msg
.IF eax == 0
Invoke TranslateMessage, addr msg
Invoke DispatchMessage, addr msg
.ENDIF
.ENDIF
.ENDW
mov eax,msg.wParam
ret
WinMain endp
;-------------------------------------------------------------------------------------
; WndProc - Main Window Message Loop
;-------------------------------------------------------------------------------------
WndProc proc USES EBX hWin:HWND,uMsg:UINT,wParam:WPARAM,lParam:LPARAM
LOCAL tvhi:TV_HITTESTINFO
LOCAL hItem:DWORD
LOCAL wNotifyCode:DWORD
mov eax, uMsg
.IF eax == WM_INITDIALOG
push hWin
pop hWnd
; Init Stuff Here
mov hJSONFile, NULL
mov hJSONTreeRoot, NULL
Invoke InitGUI, hWin
Invoke DragAcceptFiles, hWin, TRUE
Invoke SetFocus, hTV
.ELSEIF eax == WM_COMMAND
mov eax, wParam
shr eax, 16
mov wNotifyCode, eax
mov eax,wParam
and eax,0FFFFh
.IF eax == IDM_FILE_EXIT
Invoke SendMessage,hWin,WM_CLOSE,0,0
.ELSEIF eax == IDM_FILE_OPEN || eax == ACC_FILE_OPEN || eax == TB_FILE_OPEN
Invoke szCopy, Addr szNullNull, Addr JsonOpenedFilename
Invoke szCopy, Addr szNullNull, Addr JsonSavedFilename
Invoke szCopy, Addr szNullNull, Addr JsonExportFilename
Invoke JSONFileOpenBrowse, hWin
.IF eax == TRUE
Invoke JSONFileOpen, hWin, Addr JsonOpenedFilename
.IF eax == TRUE
; Start processing JSON file
Invoke JSONDataProcess, hWin, Addr JsonOpenedFilename, NULL
.ENDIF
.ENDIF
.ELSEIF eax == IDM_FILE_CLOSE || eax == ACC_FILE_CLOSE || eax == TB_FILE_CLOSE
;Invoke TreeViewDeleteAll, hTV
Invoke JSONFileClose, hWin
;Invoke MenusReset, hWin
;Invoke ToolbarsReset, hWin
.ELSEIF eax == IDM_FILE_NEW || eax == ACC_FILE_NEW || eax == TB_FILE_NEW
Invoke szCopy, Addr szNullNull, Addr JsonOpenedFilename
Invoke szCopy, Addr szNullNull, Addr JsonSavedFilename
Invoke szCopy, Addr szNullNull, Addr JsonExportFilename
Invoke JSONNew, hWin
;Invoke MenuSaveEnable, hWin, TRUE
;Invoke ToolbarButtonSaveEnable, hWin, TRUE
.ELSEIF eax == IDM_FILE_SAVE || eax == ACC_FILE_SAVE || eax == TB_FILE_SAVE
.IF g_Edit == TRUE && g_Save == TRUE
Invoke JSONFileSave, hWin, FALSE
.ENDIF
.ELSEIF eax == IDM_FILE_SAVEAS || eax == ACC_FILE_SAVEAS || eax == TB_FILE_SAVEAS
.IF g_SaveAs == TRUE
Invoke TreeViewCountItems, hTV
.IF eax != 0
Invoke JSONFileSave, hWin, TRUE
.ENDIF
.ENDIF
.ELSEIF eax == IDM_HELP_ABOUT
Invoke ShellAbout,hWin,addr AppName,addr AboutMsg,NULL
.ELSEIF eax == IDM_EDIT_PASTE_JSON || eax == IDM_CMD_PASTE_JSON
Invoke PasteJSON, hWin
.ELSEIF eax == IDM_EDIT_COPY_TEXT || eax == IDM_CMD_COPY_TEXT
Invoke CopyToClipboard, hWin, FALSE
.ELSEIF eax == IDM_EDIT_COPY_VALUE || eax == IDM_CMD_COPY_VALUE
Invoke CopyToClipboard, hWin, TRUE
.ELSEIF eax == IDM_EDIT_CUT_ITEM || eax == IDM_CMD_CUT_ITEM ;|| eax == ACC_EDIT_CUT_ITEM || eax == TB_EDIT_CUT_ITEM
Invoke JSONCutItem, NULL
.ELSEIF eax == IDM_EDIT_COPY_ITEM || eax == IDM_CMD_COPY_ITEM || eax == ACC_EDIT_COPY_ITEM || eax == TB_EDIT_COPY_ITEM
Invoke JSONCopyItem, NULL, FALSE
.ELSEIF eax == IDM_EDIT_COPY_BRANCH || eax == IDM_CMD_COPY_BRANCH || eax == ACC_EDIT_COPY_BRANCH || eax == TB_EDIT_COPY_BRANCH
;Invoke JSONCopyBranch, NULL, FALSE
.ELSEIF eax == IDM_EDIT_PASTE_ITEM || eax == IDM_CMD_PASTE_ITEM || eax == ACC_EDIT_PASTE_ITEM || eax == TB_EDIT_PASTE_ITEM
Invoke JSONPasteItem, hWin, NULL
.ELSEIF eax == IDM_EDIT_PASTE_BRANCH || eax == IDM_CMD_PASTE_BRANCH || eax == ACC_EDIT_PASTE_BRANCH || eax == TB_EDIT_PASTE_BRANCH
;Invoke JSONPasteBranch, hWin, NULL
.ELSEIF eax == IDM_EDIT_FIND || eax == IDM_CMD_FIND || eax == ACC_EDIT_FIND || eax == TB_EDIT_FIND
Invoke SetFocus, hTxtSearchTextbox
;Invoke SearchTextboxStartSearch, hWin
.ELSEIF eax == IDM_CMD_EXPORT_BRANCH_FILE || eax == ACC_EXPORT_BRANCHFILE
Invoke TreeViewGetSelectedItem, hTV
.IF eax != 0
Invoke ExportJSONBranchToFile, hWin, eax
.ENDIF
.ELSEIF eax == IDM_CMD_EXPORT_ROOT_FILE || eax == ACC_EXPORT_TREEFILE
Invoke ExportJSONBranchToFile, hWin, 0
.ELSEIF eax == IDM_CMD_EXPORT_BRANCH_CLIP || eax == ACC_EXPORT_BRANCHCLIP
Invoke TreeViewGetSelectedItem, hTV
.IF eax != 0
Invoke CopyBranchToClipboard, hWin, eax
.ENDIF
.ELSEIF eax == IDM_CMD_EXPORT_ROOT_CLIP || eax == ACC_EXPORT_TREECLIP
Invoke CopyBranchToClipboard, hWin, 0
.ELSEIF eax == IDM_CMD_COLLAPSE_BRANCH
Invoke TreeViewGetSelectedItem, hTV
Invoke TreeViewBranchCollapse, hTV, eax
.ELSEIF eax == IDM_CMD_EXPAND_BRANCH
Invoke TreeViewGetSelectedItem, hTV
Invoke TreeViewBranchExpand, hTV, eax
.ELSEIF eax == IDM_CMD_COLLAPSE_ALL || eax == ACC_COLLAPSE_ALL
.IF hTVEditControl == NULL
Invoke TreeViewRootCollapse, hTV
Invoke TreeViewSetSelectedItem, hTV, hTVRoot, TRUE
Invoke ToolBarUpdate, hWin, hTVRoot
Invoke MenusUpdate, hWin, hTVRoot
Invoke EditBoxUpdate, hWin, hTVRoot
.ENDIF
.ELSEIF eax == IDM_CMD_EXPAND_ALL || eax == ACC_EXPAND_ALL
.IF hTVEditControl == NULL
Invoke TreeViewRootExpand, hTV
Invoke TreeViewSetSelectedItem, hTV, hTVRoot, TRUE
Invoke ToolBarUpdate, hWin, hTVRoot
Invoke MenusUpdate, hWin, hTVRoot
Invoke EditBoxUpdate, hWin, hTVRoot
.ENDIF
.ELSEIF eax == IDM_CMD_ADD_ITEM || eax == ACC_EDIT_ADD_ITEM
; submenu is processed
Invoke MenuRCAddShow, hWin
.ELSEIF eax == TB_ADD_ITEM
Invoke ToolBarDropdownAddMenuShow, hWin
.ELSEIF eax == IDM_CMD_DEL_ITEM || eax == TB_DEL_ITEM
Invoke JSONDelItem, hWin
.ELSEIF eax == IDM_CMD_EDIT_ITEM
Invoke JSONEditItem, hWin
.ELSEIF eax == IDM_CMD_ADD_ITEM_STRING || eax == TB_ADD_ITEM_STRING || eax == ACC_ADD_ITEM_STRING
Invoke JSONAddItem, hWin, cJSON_String
.ELSEIF eax == IDM_CMD_ADD_ITEM_NUMBER || eax == TB_ADD_ITEM_NUMBER || eax == ACC_ADD_ITEM_NUMBER
Invoke JSONAddItem, hWin, cJSON_Number
.ELSEIF eax == IDM_CMD_ADD_ITEM_TRUE || eax == TB_ADD_ITEM_TRUE || eax == ACC_ADD_ITEM_TRUE
Invoke JSONAddItem, hWin, cJSON_True
.ELSEIF eax == IDM_CMD_ADD_ITEM_FALSE || eax == TB_ADD_ITEM_FALSE || eax == ACC_ADD_ITEM_FALSE
Invoke JSONAddItem, hWin, cJSON_False
.ELSEIF eax == IDM_CMD_ADD_ITEM_ARRAY || eax == TB_ADD_ITEM_ARRAY || eax == ACC_ADD_ITEM_ARRAY
Invoke JSONAddItem, hWin, cJSON_Array
.ELSEIF eax == IDM_CMD_ADD_ITEM_OBJECT || eax == TB_ADD_ITEM_OBJECT || eax == ACC_ADD_ITEM_OBJECT
Invoke JSONAddItem, hWin, cJSON_Object
.ELSEIF eax >= IDM_MRU_1 && eax <= IDM_MRU_9
Invoke GetMenuString, hMainWindowMenu, eax, Addr szMenuString, SIZEOF szMenuString, MF_BYCOMMAND
.IF eax != 0
Invoke szLen, Addr szMenuString
.IF eax != 0
Invoke IniMRUEntryOpenFile, hWin, Addr szMenuString
.ENDIF
.ENDIF
.ELSEIF eax == IDM_OPTIONS_EXPANDALL
Invoke IniToggleExpandAllOnLoad
Invoke MenuOptionsUpdate, hWin
.ELSEIF eax == IDM_OPTIONS_CASESEARCH || eax == ACC_OPTIONS_CASESEARCH
Invoke IniToggleCaseSensitiveSearch
Invoke MenuOptionsUpdate, hWin
Invoke InvalidateRect, hTxtSearchTextbox, NULL, TRUE
.ENDIF
.ELSEIF eax == WM_DROPFILES
mov eax, wParam
mov hDrop, eax
Invoke DragQueryFile, hDrop, 0, Addr JsonOpenedFilename, SIZEOF JsonOpenedFilename
.IF eax != 0
Invoke JSONFileOpen, hWin, Addr JsonOpenedFilename
.IF eax == TRUE
; Start processing JSON file
Invoke JSONDataProcess, hWin, Addr JsonOpenedFilename, NULL
.ENDIF
.ENDIF
mov eax, 0
ret
.ELSEIF eax == WM_WINDOWPOSCHANGED
mov ebx, lParam
mov eax, (WINDOWPOS ptr [ebx]).flags
and eax, SWP_SHOWWINDOW
.IF eax == SWP_SHOWWINDOW && g_fShown == FALSE
mov g_fShown, TRUE
Invoke PostMessage, hWin, WM_APP, 0, 0
.ENDIF
Invoke DefWindowProc,hWin,uMsg,wParam,lParam
xor eax, eax
ret
.ELSEIF eax == WM_APP
.IF CmdLineProcessFileFlag == 1
Invoke CmdLineOpenFile, hWin
.ENDIF
Invoke DefWindowProc,hWin,uMsg,wParam,lParam
ret
.ELSEIF eax == WM_CTLCOLORDLG
mov eax, hWhiteBrush
ret
.ELSEIF eax == WM_SIZE
Invoke SendMessage, hSB, WM_SIZE, 0, 0
mov eax, lParam
and eax, 0FFFFh
mov dwClientWidth, eax
mov eax, lParam
shr eax, 16d
mov dwClientHeight, eax
sub eax, 23d ; take away statusbar height
sub eax, 28d ; take away toolbar height
.IF g_ShowEditBox == 1
sub eax, g_EditBoxHeight ; take away height of editbox if shown
dec eax
.ENDIF
Invoke SetWindowPos, hTV, HWND_TOP, 0, 29, dwClientWidth, eax, SWP_NOZORDER
.IF g_ShowEditBox == 1
; set editbox position
mov eax, dwClientHeight
sub eax, 23d ; take away statusbar height
sub eax, 28d ; take away toolbar height
sub eax, 29d
sub eax, 27d
Invoke SetWindowPos, hEdtText, HWND_TOP, 0, eax, dwClientWidth, g_EditBoxHeight, SWP_NOZORDER
.ENDIF
Invoke SendMessage, hToolBar, TB_AUTOSIZE, 0, 0
Invoke SendMessage, hSB, WM_SIZE, 0, 0
.ELSEIF eax == WM_MOUSEMOVE
.IF g_DragMode == TRUE
mov eax, lParam
and eax, 0ffffh
mov ebx, lParam
shr ebx, 16
sub ebx, 29d ; substract top of treeview (based on pos on dialog, at the momement its always 29)
mov tvhi.pt.x, eax
mov tvhi.pt.y, ebx
Invoke ImageList_DragMove, eax, ebx
Invoke ImageList_DragShowNolock, FALSE
Invoke SendMessage, hTV, TVM_HITTEST, NULL, addr tvhi
.IF eax != NULL
Invoke SendMessage, hTV, TVM_SELECTITEM, TVGN_DROPHILITE, eax
.ENDIF
Invoke UpdateWindow, hTV
Invoke ImageList_DragShowNolock, TRUE
.ENDIF
.ELSEIF eax == WM_LBUTTONUP
.IF g_DragMode == TRUE
Invoke ImageList_DragLeave, hTV
Invoke ImageList_EndDrag
Invoke ImageList_Destroy, hDragImageList
Invoke SendMessage, hTV, TVM_GETNEXTITEM, TVGN_DROPHILITE,0
Invoke SendMessage, hTV, TVM_SELECTITEM, TVGN_CARET, eax
Invoke SendMessage, hTV, TVM_SELECTITEM, TVGN_DROPHILITE,0
Invoke ReleaseCapture
mov g_DragMode, FALSE
; store dragged node somewhere so we can do something with it after drop
; todo add code to handle what we do once we have dropped on target
; popup menu: insert before/after? copy/cut?
; handle child items of dragged node
.ENDIF
.ELSEIF eax==WM_NOTIFY
mov ebx,lParam
mov eax, (NMHDR PTR [ebx]).code
mov ebx, (NMHDR PTR [ebx]).hwndFrom
.IF ebx == hTV
.IF eax == NM_RCLICK
Invoke MenusUpdate, hWin, NULL
Invoke ToolBarUpdate, hWin, NULL
Invoke MenuRCShow, hWin
.ELSEIF eax == NM_CLICK
Invoke GetCursorPos, Addr tvhi.pt
Invoke ScreenToClient, hTV, addr tvhi.pt
Invoke SendMessage, hTV, TVM_HITTEST, 0, Addr tvhi
.IF tvhi.flags == TVHT_ONITEMLABEL
mov eax, tvhi.hItem
mov hFoundItem, eax
;mov hTVSelectedItem, eax
;PrintDec hTVSelectedItem
;mov bSearchTermNew, TRUE
Invoke ToolBarUpdate, hWin, tvhi.hItem
Invoke MenusUpdate, hWin, tvhi.hItem
Invoke EditBoxUpdate, hWin, tvhi.hItem
.ENDIF
;Invoke SearchTextboxShow, hWin, FALSE
;Invoke MenusUpdate, hWin, NULL
;Invoke ToolBarUpdate, hWin, NULL
.ELSEIF eax == NM_DBLCLK
Invoke JSONEditItem, hWin
;----------------------------------------------------------
; WM_NOTIFY:TVN_KEYDOWN
;----------------------------------------------------------
.ELSEIF eax == TVN_KEYDOWN
mov ebx, lParam
movzx eax, (TV_KEYDOWN ptr [ebx]).wVKey
.IF eax == VK_F2
Invoke JSONEditItem, hWin
.ELSEIF eax == VK_F3
;Invoke SetFocus, hTxtSearchTextbox
Invoke SearchTextboxStartSearch, hWin
;Invoke TreeViewGetSelectedItem, hTV
;Invoke TreeViewSetSelectedItem, hTV, eax, TRUE
.ELSEIF eax == VK_F4
Invoke IniToggleCaseSensitiveSearch
Invoke MenuOptionsUpdate, hWin
Invoke InvalidateRect, hTxtSearchTextbox, NULL, TRUE
;Invoke SearchTextboxStartSearch, hWin
.ELSEIF eax == VK_F
Invoke GetAsyncKeyState, VK_CONTROL
.IF eax != 0
;PrintText 'TVN_KEYDOWN:CTRL+F'
Invoke SetFocus, hTxtSearchTextbox
.ENDIF
.ELSEIF eax == VK_V
Invoke GetAsyncKeyState, VK_CONTROL
.IF eax != 0
Invoke PasteJSON, hWin
.ENDIF
.ELSEIF eax == VK_DELETE
Invoke JSONDelItem, hWin
.ELSEIF eax == VK_INSERT ; show add submenu only if on an item with children or on an object or array item
;Invoke GetAsyncKeyState, VK_CONTROL
;.IF eax != 0
Invoke MenuRCAddShow, hWin
;.ENDIF
.ENDIF
;----------------------------------------------------------
; WM_NOTIFY:TVN_SELCHANGED
;----------------------------------------------------------
.ELSEIF eax == TVN_SELCHANGED
mov ebx, lParam
mov eax, (NM_TREEVIEW PTR [ebx]).itemNew.hItem
mov hItem, eax
Invoke ToolBarUpdate, hWin, hItem
Invoke MenusUpdate, hWin, hItem
Invoke EditBoxUpdate, hWin, hItem
;----------------------------------------------------------
; WM_NOTIFY:TVN_BEGINLABELEDIT
;----------------------------------------------------------
.ELSEIF eax == TVN_BEGINLABELEDIT
; Prevent label editing if root and/or an object
mov ebx, lParam
mov eax, (TV_DISPINFO PTR [ebx]).item.hItem
.IF eax == hTVRoot
mov eax, TRUE
ret
.ENDIF
mov eax, (TV_DISPINFO PTR [ebx]).item.lParam
.IF eax != NULL ; eax = hJSON
mov ebx, eax
mov eax, [ebx].cJSON.itemtype
.IF eax == cJSON_Object
mov eax, TRUE
ret
.ENDIF
.ENDIF
; Show Editbox instead?
Invoke EditLabelTextLength, lParam
.IF sdword ptr eax > JSON_ITEM_MAX_TEXTLENGTH
.IF g_ShowEditBox == 1
Invoke SetFocus, hEdtText
mov eax, TRUE
ret
.ENDIF
.ENDIF
; Subclass treeview edit control
mov eax, hTV
mov tve.hTreeview, eax
mov ebx, lParam
mov eax, (TV_DISPINFO PTR [ebx]).item.pszText
mov tve.lpszItemTextOld, eax
.IF eax != NULL
Invoke szCopy, eax, Addr szTVLabelEditOldText
.ENDIF
mov ebx, lParam
mov eax, (TV_DISPINFO PTR [ebx]).item.hItem
mov tve.hItem, eax
Invoke TreeViewGetItemParam, hTV, eax
mov tve.lParam, eax
Invoke SendMessage, hTV, TVM_GETEDITCONTROL, 0, 0
mov hTVEditControl, eax
Invoke SetWindowLong, hTVEditControl, GWL_WNDPROC, Addr TreeViewEditSubclass
mov tve.lpdwOldProc, eax
Invoke SetWindowLong, hTVEditControl, GWL_USERDATA, Addr tve ;eax
Invoke TVEditControlSelectInitial, hTVEditControl, tve.lpszItemTextOld, tve.lParam
mov eax, FALSE
ret
;----------------------------------------------------------
; WM_NOTIFY:TVN_ENDLABELEDIT
;----------------------------------------------------------
.ELSEIF eax == TVN_ENDLABELEDIT
mov ebx, lParam
mov eax, (TV_DISPINFO PTR [ebx]).item.pszText
.IF eax != NULL
Invoke szCopy, eax, Addr szTVLabelEditNewText
Invoke szCmp, Addr szTVLabelEditOldText, Addr szTVLabelEditNewText
.IF eax == 0
mov g_Edit, TRUE
mov ebx, lParam
mov eax, (TV_DISPINFO PTR [ebx]).item.hItem
mov hItem, eax
Invoke JSONUpdateItem, hTV, hItem, Addr szTVLabelEditNewText
Invoke ToolBarUpdate, hWin, hItem
Invoke MenusUpdate, hWin, hItem
.ENDIF
mov hTVEditControl, NULL
mov eax, TRUE
ret
.ELSE
mov hTVEditControl, NULL
mov eax, TRUE
ret
.ENDIF
;----------------------------------------------------------
; WM_NOTIFY:TVN_BEGINDRAG
;----------------------------------------------------------
.ELSEIF eax == TVN_BEGINDRAG
mov ebx, lParam
Invoke SendMessage, hTV, TVM_CREATEDRAGIMAGE, 0, (NM_TREEVIEW ptr [ebx]).itemNew.hItem
mov hDragImageList, eax
Invoke ImageList_BeginDrag, hDragImageList, 0, 0, 0
mov ebx, lParam
Invoke ImageList_DragEnter, hTV, (NM_TREEVIEW ptr [ebx]).ptDrag.x, (NM_TREEVIEW ptr [ebx]).ptDrag.y
Invoke SetCapture, hWin
mov g_DragMode, TRUE
.ENDIF
.ELSE
.IF eax == TBN_DROPDOWN
Invoke ToolBarDropdownAddMenuShow, hWin
.ELSE
Invoke ToolBarTips, lParam
.ENDIF
.ENDIF
.ELSEIF eax == WM_TIMER
mov eax, wParam
.IF eax == TIMER_ARRAY_UPDATE_ID
.IF hTVArrayUpdate != 0
Invoke KillTimer, hWin, TIMER_ARRAY_UPDATE_ID
Invoke JSONUpdateArrayCount, hTVArrayUpdate
mov hTVArrayUpdate, NULL
.ENDIF
.ENDIF
.ELSEIF eax == WM_CLOSE
.IF g_Edit == TRUE
Invoke MessageBox, hWin, Addr szJSONSaveChanges, Addr AppName, MB_ICONQUESTION+MB_YESNO
.IF eax == IDYES
Invoke JSONFileSave, hWin, FALSE
.ENDIF
.ENDIF
Invoke DestroyWindow,hWin
.ELSEIF eax == WM_DESTROY
Invoke PostQuitMessage,NULL
.ELSE
Invoke DefWindowProc,hWin,uMsg,wParam,lParam
ret
.ENDIF
xor eax,eax
ret
WndProc endp
;-------------------------------------------------------------------------------------
; CmdLineProcess - has user passed a file at the command line
;-------------------------------------------------------------------------------------
CmdLineProcess PROC
Invoke getcl_ex, 1, ADDR CmdLineFilename
.IF eax == 1
mov CmdLineProcessFileFlag, 1 ; filename specified, attempt to open it
.ELSE
mov CmdLineProcessFileFlag, 0 ; do nothing, continue as normal
.ENDIF
ret
CmdLineProcess endp
;------------------------------------------------------------------------------
; Opens a file from the command line or shell explorer call
;------------------------------------------------------------------------------
CmdLineOpenFile PROC hWin:DWORD
Invoke InString, 1, Addr CmdLineFilename, Addr szBackslash
.IF eax == 0
Invoke GetCurrentDirectory, MAX_PATH, Addr CmdLineFullPathFilename
Invoke szCatStr, Addr CmdLineFullPathFilename, Addr szBackslash
Invoke szCatStr, Addr CmdLineFullPathFilename, Addr CmdLineFilename
.ELSE
Invoke szCopy, Addr CmdLineFilename, Addr CmdLineFullPathFilename
.ENDIF
Invoke exist, Addr CmdLineFullPathFilename
.IF eax == 0 ; does not exist
Invoke szCopy, Addr szCmdLineFilenameDoesNotExist, Addr szJSONErrorMessage
Invoke szCatStr, Addr szJSONErrorMessage, Addr CmdLineFullPathFilename
Invoke StatusBarSetPanelText, 2, Addr szJSONErrorMessage
ret
.ENDIF
Invoke JSONFileOpen, hWin, Addr CmdLineFullPathFilename
.IF eax == TRUE
Invoke szCopy, Addr CmdLineFullPathFilename, Addr JsonOpenedFilename
; Start processing JSON file
Invoke JSONDataProcess, hWin, Addr CmdLineFullPathFilename, NULL
.ENDIF
ret
CmdLineOpenFile endp
;-------------------------------------------------------------------------------------
; InitGUI - Initialize GUI stuff
;-------------------------------------------------------------------------------------
InitGUI PROC USES EBX hWin:DWORD
LOCAL ncm:NONCLIENTMETRICS
LOCAL lfnt:LOGFONT
Invoke GetMenu, hWin
mov hMainWindowMenu, eax
Invoke CreateSolidBrush, 0FFFFFFh
mov hWhiteBrush, eax
Invoke CreateSolidBrush, 0F7F7F7h ; 240,240,240
mov hMenuGreyBrush, eax
Invoke CreateSolidBrush, 0EDEDF1h ; 241,237,237
mov hStatusbarGreyBrush, eax
mov ncm.cbSize, SIZEOF NONCLIENTMETRICS
Invoke SystemParametersInfo, SPI_GETNONCLIENTMETRICS, SIZEOF NONCLIENTMETRICS, Addr ncm, 0
Invoke CreateFontIndirect, Addr ncm.lfMessageFont
mov hFontNormal, eax
Invoke GetObject, hFontNormal, SIZEOF lfnt, Addr lfnt
mov lfnt.lfWeight, FW_BOLD
Invoke CreateFontIndirect, Addr lfnt
mov hFontBold, eax
Invoke GetObject, hFontNormal, SIZEOF lfnt, Addr lfnt
mov lfnt.lfWeight, FW_NORMAL
lea eax, szFontCourier
lea ebx, lfnt.lfFaceName
Invoke lstrcpyn, ebx, eax, 32d
mov lfnt.lfHeight, -11d
Invoke CreateFontIndirect, Addr lfnt
mov hFontCourier, eax
Invoke GetDlgItem, hWin, IDC_TV
mov hTV, eax
Invoke GetDlgItem, hWin, IDC_SB
mov hSB, eax
Invoke GetDlgItem, hWin, IDC_EdtText
mov hEdtText, eax
Invoke SendMessage, hEdtText, WM_SETFONT, hFontCourier, TRUE
.IF g_ShowEditBox == 1
Invoke EnableWindow, hEdtText, TRUE
Invoke ShowWindow, hEdtText, SW_SHOW
.ELSE
Invoke EnableWindow, hEdtText, FALSE
Invoke ShowWindow, hEdtText, SW_HIDE
.ENDIF
Invoke LoadIcon, hInstance, ICO_MAIN
mov hICO_MAIN, eax
Invoke LoadIcon, hInstance, ICO_JSON_STRING
mov hICO_JSON_STRING, eax
Invoke LoadIcon, hInstance, ICO_JSON_INTEGER
mov hICO_JSON_INTEGER, eax
Invoke LoadIcon, hInstance, ICO_JSON_FLOAT
mov hICO_JSON_FLOAT, eax
Invoke LoadIcon, hInstance, ICO_JSON_CUSTOM
mov hICO_JSON_CUSTOM, eax
Invoke LoadIcon, hInstance, ICO_JSON_TRUE
mov hICO_JSON_TRUE, eax
Invoke LoadIcon, hInstance, ICO_JSON_FALSE
mov hICO_JSON_FALSE, eax
Invoke LoadIcon, hInstance, ICO_JSON_ARRAY
mov hICO_JSON_ARRAY, eax
Invoke LoadIcon, hInstance, ICO_JSON_OBJECT
mov hICO_JSON_OBJECT, eax
Invoke LoadIcon, hInstance, ICO_JSON_NULL
mov hICO_JSON_NULL, eax
Invoke LoadIcon, hInstance, ICO_JSON_INVALID
mov hICO_JSON_INVALID, eax
Invoke LoadIcon, hInstance, ICO_JSON_LOGICAL
mov hICO_JSON_LOGICAL, eax
Invoke ImageList_Create, 16, 16, ILC_COLOR32, 16, 16
mov hIL, eax
Invoke ImageList_AddIcon, hIL, hICO_MAIN
Invoke ImageList_AddIcon, hIL, hICO_JSON_STRING
Invoke ImageList_AddIcon, hIL, hICO_JSON_INTEGER
Invoke ImageList_AddIcon, hIL, hICO_JSON_FLOAT
Invoke ImageList_AddIcon, hIL, hICO_JSON_CUSTOM
Invoke ImageList_AddIcon, hIL, hICO_JSON_TRUE
Invoke ImageList_AddIcon, hIL, hICO_JSON_FALSE
Invoke ImageList_AddIcon, hIL, hICO_JSON_ARRAY
Invoke ImageList_AddIcon, hIL, hICO_JSON_OBJECT
Invoke ImageList_AddIcon, hIL, hICO_JSON_NULL
Invoke ImageList_AddIcon, hIL, hICO_JSON_INVALID
Invoke ImageList_AddIcon, hIL, hICO_JSON_LOGICAL
; Init other controls
Invoke IniGetSettingExpandAllOnLoad
Invoke IniGetSettingCaseSensitiveSearch
Invoke MenusInit, hWin
Invoke ToolbarInit, hWin, 16, 16
Invoke TreeViewInit, hWin
Invoke StatusBarInit, hWin
Invoke SearchTextboxInit, hWin
Invoke IniMRULoadListToMenu, hWin
ret
InitGUI ENDP
;-------------------------------------------------------------------------------------
; ResetGUI - reset GUI back to normal - like when closing a file etc
;-------------------------------------------------------------------------------------
ResetGUI PROC hWin:DWORD
Invoke TreeViewDeleteAll, hTV
Invoke SetWindowTitle, hWin, NULL
Invoke StatusBarSetPanelText, 2, Addr szSpace
mov g_nTVIndex, 0
mov g_Edit, FALSE
.IF g_ShowEditBox == 1
Invoke SetWindowText, hEdtText, Addr szNullNull
.ENDIF
Invoke MenusReset, hWin
Invoke ToolbarsReset, hWin
.IF hJSONTreeRoot != NULL
mov hJSONTreeRoot, NULL
.ENDIF
.IF hJSON_Object_Root != NULL
Invoke cJSON_Delete, hJSON_Object_Root
mov hJSON_Object_Root, NULL
.ENDIF
ret
ResetGUI ENDP
;-------------------------------------------------------------------------------------
; TreeViewInit - Initialize JSON Treeview
;-------------------------------------------------------------------------------------
TreeViewInit PROC hWin:DWORD
Invoke SendMessage, hTV, TVM_SETEXTENDEDSTYLE, TVS_EX_DOUBLEBUFFER, TVS_EX_DOUBLEBUFFER
Invoke TreeViewLinkImageList, hTV, hIL, TVSIL_NORMAL
Invoke TreeViewSubClassProc, hTV, Addr TreeViewSubclass
mov pOldTVProc, eax
Invoke TreeViewSubClassData, hTV, pOldTVProc
ret
TreeViewInit ENDP
;-------------------------------------------------------------------------------------
; Subclass to capture and handle enter key pressed in labels
;-------------------------------------------------------------------------------------
TreeViewSubclass PROC hWin:HWND,uMsg:UINT,wParam:WPARAM,lParam:LPARAM
mov eax, uMsg
.IF eax == WM_GETDLGCODE
mov eax, DLGC_WANTARROWS or DLGC_WANTTAB or DLGC_WANTALLKEYS ; DLGC_WANTARROWS or
ret
.ELSEIF eax == WM_COMMAND
mov eax, lParam
.IF eax == hTVEditControl
mov eax, wParam
shr eax, 16
.IF eax == EN_CHANGE ; Treeview Edit control is subclassed but sents WM_COMMAND to parent
Invoke TreeViewEditValidate, hWin, lParam
Invoke UpdateWindow, hTVEditControl
.ENDIF
.ENDIF
.ELSEIF eax == WM_CHAR
mov eax, wParam
.IF eax == VK_TAB || eax == VK_ADD || eax == VK_SUBTRACT ;|| eax == VK_LEFT || eax == VK_RIGHT ;|| eax == VK_INSERT
xor eax, eax
ret
.ELSE
Invoke GetWindowLong, hWin, GWL_USERDATA
Invoke CallWindowProc, eax, hWin, uMsg, wParam, lParam
ret
.ENDIF
.ELSEIF eax == WM_KEYDOWN
mov eax, wParam
.IF eax == VK_TAB
Invoke SetFocus, hTxtSearchTextbox
xor eax, eax
ret
; .ELSEIF eax == VK_INSERT
; ;PrintText 'WM_KEYDOWN:VK_INSERT'
; Invoke GetWindowLong, hWin, GWL_USERDATA
; Invoke CallWindowProc, eax, hWin, uMsg, wParam, lParam
; ret
;
; .ELSEIF eax == VK_LEFT
; PrintText 'WM_KEYDOWN:VK_LEFT'
; Invoke GetWindowLong, hWin, GWL_USERDATA
; Invoke CallWindowProc, eax, hWin, uMsg, wParam, lParam
; ret
;
; .ELSEIF eax == VK_RIGHT
; PrintText 'WM_KEYDOWN:VK_RIGHT'
; Invoke GetWindowLong, hWin, GWL_USERDATA
; Invoke CallWindowProc, eax, hWin, uMsg, wParam, lParam
; ret
; .ELSEIF eax == VK_F
; Invoke GetAsyncKeyState, VK_CONTROL
; .IF eax != 0
; PrintText 'WM_KEYDOWN:CTRL+F'
; Invoke SetFocus, hTxtSearchTextbox
; xor eax, eax
; ret
; .ELSE
; Invoke GetWindowLong, hWin, GWL_USERDATA
; Invoke CallWindowProc, eax, hWin, uMsg, wParam, lParam
; ret
; .ENDIF
.ELSE
Invoke GetWindowLong, hWin, GWL_USERDATA
Invoke CallWindowProc, eax, hWin, uMsg, wParam, lParam
ret
.ENDIF
.ELSE
invoke GetWindowLong, hWin, GWL_USERDATA
invoke CallWindowProc, eax, hWin, uMsg, wParam, lParam
ret
.ENDIF
Invoke GetWindowLong, hWin, GWL_USERDATA
Invoke CallWindowProc, eax, hWin, uMsg, wParam, lParam
ret
TreeViewSubclass ENDP
;-------------------------------------------------------------------------------------
; Subclass to capture and handle enter key pressed in labels
;-------------------------------------------------------------------------------------
TreeViewEditSubclass PROC hWin:HWND,uMsg:UINT,wParam:WPARAM,lParam:LPARAM
mov eax, uMsg
.IF eax == WM_GETDLGCODE
mov eax, DLGC_WANTALLKEYS
ret
; .ELSEIF eax == WM_CHAR
; PrintText 'TreeViewEditSubclass:WM_CHAR'
; mov eax, wParam
; .IF eax == VK_RETURN
; PrintText 'TreeViewEditSubclass:WM_CHAR:VK_RETURN'
; xor eax, eax
; ret
; .ENDIF
; .ELSEIF eax == WM_KEYDOWN
; PrintText 'TreeViewEditSubclass:WM_KEYDOWN'
; mov eax, wParam
; .IF eax == VK_RETURN
; PrintText 'TreeViewEditSubclass:WM_KEYDOWN:VK_RETURN'
; xor eax, eax
; ret
; .ENDIF
.ELSE
Invoke GetWindowLong, hWin, GWL_USERDATA
mov eax, [eax].TVEDIT.lpdwOldProc
Invoke CallWindowProc, eax, hWin, uMsg, wParam, lParam
ret
.ENDIF
Invoke GetWindowLong, hWin, GWL_USERDATA
mov eax, [eax].TVEDIT.lpdwOldProc
Invoke CallWindowProc, eax, hWin, uMsg, wParam, lParam
ret
TreeViewEditSubclass ENDP
;-------------------------------------------------------------------------------------
; TreeViewEditValidate - validate text in treeview edit control
;-------------------------------------------------------------------------------------
TreeViewEditValidate PROC USES EBX hWin:DWORD, hEdit:DWORD
LOCAL lpTveditStruct:DWORD
LOCAL hTreeview:DWORD
LOCAL hItem:DWORD
LOCAL hJSON:DWORD
LOCAL jsontype:DWORD
LOCAL lpszItemTextOld:DWORD
LOCAL dwLengthItemTextName:DWORD
LOCAL dwLengthItemTextValue:DWORD
LOCAL dwArrayCount:DWORD
;PrintText 'TreeViewEditValidate'
Invoke GetWindowLong, hEdit, GWL_USERDATA
mov lpTveditStruct, eax
mov ebx, eax
mov eax, [ebx].TVEDIT.lParam
mov hJSON, eax
mov eax, [ebx].TVEDIT.hItem
mov hItem, eax
mov eax, [ebx].TVEDIT.hTreeview
mov hTreeview, eax
mov eax, [ebx].TVEDIT.lpszItemTextOld
mov lpszItemTextOld, eax
mov ebx, hJSON
mov eax, [ebx].cJSON.itemtype
mov jsontype, eax
Invoke GetWindowText, hEdit, Addr szItemTextString, SIZEOF szItemTextString
.IF eax != 0
;PrintText 'SeperateNameValue'
Invoke SeperateNameValue, Addr szItemTextString, Addr szItemTextName, Addr szItemTextValue
Invoke lstrlen, Addr szItemTextName
mov dwLengthItemTextName, eax
Invoke lstrlen, Addr szItemTextValue
mov dwLengthItemTextValue, eax
;PrintDec dwLengthItemTextName