forked from peberlein/WEE
-
Notifications
You must be signed in to change notification settings - Fork 0
/
ui_win.e
1869 lines (1678 loc) · 66.2 KB
/
ui_win.e
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
-- ui_win.e
include window.ew
include wee.exw
include std/text.e
include std/filesys.e
include std/sort.e
include std/machine.e
include std/dll.e
include std/get.e
-- MenuItem constants
constant
File_New = 101,
File_Open = 102,
File_Save = 103,
File_SaveAs = 104,
File_Close = 105,
File_PageSetup = 106,
File_Print = 107,
File_Exit = 108,
File_Recent = 110,
Edit_Undo = 201,
Edit_Cut = 202,
Edit_Copy = 203,
Edit_Paste = 204,
Edit_Clear = 205,
Edit_SelectAll = 206,
Edit_Redo = 207,
Edit_ToggleComment = 208,
Search_Find = 301,
Search_Find_Next = 302,
Search_Find_Prev = 303,
Search_Replace = 304,
View_Subs = 401,
View_Error = 402,
View_Completions = 404,
View_Declaration = 405,
View_GoBack = 406,
View_SubArgs = 407,
Run_Start = 501,
Run_WithArgs = 502,
Run_Arguments = 503,
Run_Interpreter = 507,
Run_Bind = 504,
Run_Shroud = 505,
Run_Translate = 506,
Options_Font = 601,
Options_LineNumbers = 602,
Options_SortedSubs = 603,
Options_Colors = 604,
Options_LineWrap = 605,
Options_ReopenTabs = 606,
Options_CompleteStatements = 607,
Options_CompleteBraces = 608,
Options_Indent = 609,
Options_ErrorIndicators = 610,
Help_About = 701,
Help_ReleaseNotes = 702,
Help_Tutorial = 703,
Help_Context = 704,
Select_Tab = 801,
Select_Next_Tab = 811,
Select_Prev_Tab = 812
constant file_filters = allocate_string(
"Euphoria files (*.ex,*.exw,*.e,*.ew)"&0&"*.EX;*.EXW;*.E;*.EW;ex.err;eu.cfg"&0&
"Text or Document files (*.txt,*.doc)"&0&"*.TXT;*.DOC"&0&
"All files (*.*)"&0&"*.*"&0&0)
atom hMainWnd, hFindDlg, hDlg, class,
hmenu, hfilemenu, heditmenu, hsearchmenu, hviewmenu,
hrunmenu, hoptionsmenu, hhelpmenu, htabmenu,
hstatus, htabs, hcode, hedit, htooltip,
WM_FIND
sequence ui_hedits
ui_hedits = {}
class = 0
WM_FIND = 0
hMainWnd = 0 -- the main window
hFindDlg = 0
hDlg = 0
hedit = 0 -- the richedit control
hstatus = 0 -- the static control showing cursor position
htabs = 0 -- the tab control
hcode = 0 -- the listbox control for code completions
hedit = 0
constant tab_h = 24
x_pos = CW_USEDEFAULT
y_pos = CW_USEDEFAULT
x_size = CW_USEDEFAULT
y_size = CW_USEDEFAULT
constant
ansi_var_font = c_func(GetStockObject, {ANSI_VAR_FONT}),
ansi_fixed_font = c_func(GetStockObject, {ANSI_FIXED_FONT})
atom captionFont, smCaptionFont, menuFont, statusFont, messageFont
-- nifty shortcut, thanks Greg Haberek
function callback(sequence name, atom rid = routine_id(name))
return call_back(rid)
end function
global procedure ui_update_window_title(sequence name)
atom result
result = c_func(SendMessage, {hMainWnd, WM_SETTEXT, 0,
alloc_string(name & " ~ " & window_title)})
free_strings()
end procedure
global procedure ui_update_status(sequence status)
atom txt, junk
txt = allocate_string(status)
junk = c_func(SendMessage, {hstatus, WM_SETTEXT, 0, txt})
free(txt)
end procedure
global procedure ui_refresh_file_menu(sequence recent_files)
atom junk, count
count = c_func(GetMenuItemCount, {hfilemenu}) - 7
if count = 0 and length(recent_files) > 0 then
junk = c_func(AppendMenu, {hfilemenu, MF_BYPOSITION + MF_SEPARATOR, 0, 0})
end if
for i = 1 to length(recent_files) do
if i >= count then
junk = c_func(AppendMenu, {hfilemenu, MF_BYPOSITION + MF_STRING + MF_ENABLED,
File_Recent+i, alloc_string(recent_files[i])})
else
junk = c_func(ModifyMenu, {hfilemenu, i+7, MF_BYPOSITION + MF_STRING + MF_ENABLED,
File_Recent+i, alloc_string(recent_files[i])})
end if
end for
free_strings()
end procedure
global procedure ui_update_tab_name(integer tab, sequence name)
atom junk, tcitem
tcitem = allocate_pack("dddsiip", {TCIF_TEXT, 0, 0, name, 0, 0, 0})
junk = c_func(SendMessage, {htabs, TCM_SETITEMA, tab-1, tcitem})
free(tcitem)
free_strings()
end procedure
-- select the tab and show the hedit
global procedure ui_select_tab(integer tab)
atom junk, rect
integer w, h
-- change tab, and highlight it to make it stand out
junk = c_func(SendMessage, {htabs, TCM_HIGHLIGHTITEM,
c_func(SendMessage, {htabs, TCM_GETCURSEL, 0, 0}), 0})
junk = c_func(SendMessage, {htabs, TCM_SETCURSEL, tab-1, 0})
junk = c_func(SendMessage, {htabs, TCM_HIGHLIGHTITEM, tab-1, 1})
if hedit then
-- hide the previous hedit
c_proc(ShowWindow, {hedit, SW_HIDE})
end if
hedit = ui_hedits[tab]
-- update the richedit control to the window size
rect = allocate(16)
c_proc(GetClientRect, {hMainWnd, rect})
c_proc(MoveWindow, {hedit, 0, tab_h, peek4u(rect+8), peek4u(rect+12)-tab_h, 1})
free(rect)
c_proc(ShowWindow, {hedit, SW_SHOW})
junk = c_func(SetFocus, {hedit})
junk = allocate_pack("zdppddddps", { -- TOOLINFO
TTF_IDISHWND + TTF_SUBCLASS, -- uFlags
hMainWnd, -- hwnd
htabs, -- uId
0,0,0,0, -- rect
0, -- hinst
file_name -- lpszText
})
c_func(SendMessage, {htooltip, TTM_UPDATETIPTEXT, 0, junk})
free(junk)
end procedure
global function ui_new_tab(sequence name)
atom junk, tcitem, tab, hedit
tab = c_func(SendMessage, {htabs, TCM_GETITEMCOUNT, 0, 0})
tcitem = allocate_pack("dddsiip", {TCIF_TEXT, 0, 0, name, 0, 0, 0})
junk = c_func(SendMessage, {htabs, TCM_INSERTITEMA, tab+(tab!=0), tcitem})
free(tcitem)
free_strings()
hedit = CreateWindow({
0,
"Scintilla",
"",
{WS_CHILD, WS_VISIBLE, WS_TABSTOP, WS_CLIPCHILDREN},
0,0,0,0, -- position and size set later by hMainWnd
hMainWnd, NULL, 0, NULL})
-- save the window handle
ui_hedits = append(ui_hedits, hedit)
return c_func(SendMessage, {hedit, SCI_GETDIRECTPOINTER, 0, 0})
end function
global procedure ui_close_tab(integer tab)
atom junk
-- get the edit window handle and destroy it
junk = c_func(DestroyWindow, {hedit})
hedit = 0
-- delete the tab
junk = c_func(SendMessage, {htabs, TCM_DELETEITEM, tab-1, 0})
-- remove the window handle
ui_hedits = ui_hedits[1..tab-1] & ui_hedits[tab+1..$]
end procedure
procedure rightclick_tab()
atom point, x, y
integer tab
point = allocate(12)
c_func(GetCursorPos, {point})
x = peek4s(point)
y = peek4s(point+4)
c_func(ScreenToClient, {hMainWnd, point})
tab = c_func(SendMessage, {htabs, TCM_HITTEST, 0, point})
if tab >= 0 then
select_tab(tab + 1)
c_func(TrackPopupMenu, {htabmenu, TPM_LEFTALIGN, x, y, 0, hMainWnd, 0})
end if
free(point)
end procedure
integer current_filter
current_filter = 1
global function ui_get_open_file_name(integer multiple = 1)
sequence temp
temp = GetOpenFileName({hMainWnd, 0, file_filters, current_filter,
"", 0, 0,
OFN_EXPLORER + OFN_PATHMUSTEXIST + OFN_FILEMUSTEXIST + OFN_HIDEREADONLY
+ (multiple != 0) * OFN_ALLOWMULTISELECT
, 0})
if length(temp) < 2 then return "" end if
current_filter = temp[1]
return temp[2]
end function
global function ui_get_save_file_name(sequence file_name)
sequence temp
temp = GetSaveFileName({hMainWnd, 0, file_filters, current_filter,
file_name, 0, 0, OFN_EXPLORER + OFN_PATHMUSTEXIST + OFN_HIDEREADONLY, 0})
if length(temp) < 2 then return "" end if
current_filter = temp[1]
return temp[2]
end function
-- returns yes=1 no=0
global function ui_message_box_yes_no(sequence title, sequence message)
atom result
result = c_func(MessageBox, {hMainWnd,
alloc_string(message),
alloc_string(title),
or_all({MB_APPLMODAL, MB_ICONINFORMATION, MB_YESNO})})
free_strings()
return result = IDYES
end function
-- returns yes=1 no=0 cancel=-1
global function ui_message_box_yes_no_cancel(sequence title, sequence message)
atom result
result = c_func(MessageBox, {hMainWnd,
alloc_string(message),
alloc_string(title),
or_all({MB_APPLMODAL, MB_ICONINFORMATION, MB_YESNOCANCEL})})
free_strings()
return (result = IDYES) - (result = IDCANCEL)
end function
global function ui_message_box_error(sequence title, sequence message)
atom result
result = c_func(MessageBox, {hMainWnd,
alloc_string(message),
alloc_string(title),
or_all({MB_APPLMODAL, MB_ICONSTOP, MB_OK})})
free_strings()
return result
end function
procedure get_window_size()
atom rect
rect = allocate(16)
c_proc(GetWindowRect, {hMainWnd, rect})
x_pos = peek4s(rect)
y_pos = peek4s(rect+4)
x_size = peek4s(rect+8) - x_pos
y_size = peek4s(rect+12) - y_pos
free(rect)
end procedure
procedure about_box()
atom result
result = c_func(MessageBox, {hMainWnd,
alloc_string(window_title&"\n\nVersion "&version&"\n\nBy "&author),
alloc_string("About "&window_title),
or_all({MB_APPLMODAL, MB_ICONINFORMATION, MB_OK})})
free_strings()
end procedure
constant
DialogListID = 1000,
DialogLabelID = 1001,
DialogEditID = 1002,
DialogOpenID = 1003
sequence subs
function SubsDialogProc(atom hdlg, atom iMsg, atom wParam, atom lParam)
atom junk, hList, pos
sequence text, word, tmp
--? {hdlg, iMsg, wParam, HIWORD(lParam), LOWORD(lParam)}
if iMsg = WM_INITDIALOG then
junk = c_func(SendMessage, {c_func(GetDlgItem, {hdlg, IDOK}),
WM_SETFONT, captionFont, 0})
junk = c_func(SendMessage, {c_func(GetDlgItem, {hdlg, IDCANCEL}),
WM_SETFONT, captionFont, 0})
hList = c_func(GetDlgItem, {hdlg, DialogListID})
junk = c_func(SendMessage, {hList, WM_SETFONT, messageFont, 0})
text = get_edit_text()
pos = get_pos()
word = word_pos(text, pos)
subs = get_subroutines(parse(text, file_name))
if sorted_subs then
subs = sort(subs)
end if
for i = 1 to length(subs) do
junk = c_func(SendMessage, {hList, LB_ADDSTRING, 0, alloc_string(subs[i][1])})
if equal(word[1], subs[i][1]) then
junk = c_func(SendMessage, {hList, LB_SETCURSEL, i-1, 0})
end if
end for
free_strings()
elsif iMsg = WM_COMMAND then
if LOWORD(wParam) = DialogListID and HIWORD(wParam) = LBN_DBLCLK then
wParam = IDOK -- double clicked item in list
end if
if LOWORD(wParam) = IDOK then
hList = c_func(GetDlgItem, {hdlg, DialogListID})
pos = c_func(SendMessage, {hList, LB_GETCURSEL, 0, 0})+1
if pos >= 1 and pos <= length(subs) then
word = subs[pos][1]
pos = subs[pos][2]-1
--printf(1, "%s: pos=%d line=%d\n", {word, pos,
-- c_func(SendMessage, {hedit, SCI_LINEFROMPOSITION, pos, 0})})
junk = c_func(SendMessage, {hedit, SCI_SETSEL, pos, pos+length(word)})
set_top_line(-1) -- set the top visible line to the current line
end if
junk = c_func(EndDialog, {hdlg, 1})
return 1
elsif LOWORD(wParam) = IDCANCEL then
junk = c_func(EndDialog, {hdlg, 0})
return 1
end if
elsif iMsg = WM_CLOSE then --closing dialog
junk = c_func(EndDialog, {hdlg, 0})
end if
return 0
end function
constant SubsDialogCallback = callback("SubsDialogProc")
-- used for struct DLGITEMTEMPLATE
constant
DIALOG_CLASS_BUTTON = #0080,
DIALOG_CLASS_EDIT = #0081,
DIALOG_CLASS_STATIC = #0082,
DIALOG_CLASS_LIST = #0083,
DIALOG_CLASS_SCROLLBAR = #0084,
DIALOG_CLASS_COMBOBOX = #0085
procedure view_subroutines()
atom junk
junk = DialogBoxIndirectParam(c_func(GetModuleHandle, {NULL}), {
--DLGTEMPLATE{style, exstyle, x, y, cx, cy, menu, wndclass, text}
{{WS_POPUP, WS_BORDER, WS_SYSMENU, DS_MODALFRAME, WS_CAPTION}, 0,
50,50, 100,124, 0, 0, "Subroutines"},
--DLGITEMTEMPLATE{style, exstyle, x, y, cx, cy, id, dlgclass, text}
{{WS_CHILD, WS_VISIBLE, WS_VSCROLL, LBS_NOTIFY}, WS_EX_CLIENTEDGE,
4,4, 92,110, DialogListID, DIALOG_CLASS_LIST, "ListBox"},
{{WS_CHILD, WS_VISIBLE, BS_PUSHBUTTON}, 0,
4,108, 44,12, IDCANCEL, DIALOG_CLASS_BUTTON, "Cancel"},
{{WS_CHILD, WS_VISIBLE, BS_DEFPUSHBUTTON}, 0,
52,108, 44,12, IDOK, DIALOG_CLASS_BUTTON, "OK"}
},
hMainWnd,
SubsDialogCallback,
0)
subs = {}
end procedure
sequence err
function ViewErrorProc(atom hdlg, atom iMsg, atom wParam, atom lParam)
atom junk, hList, hLabel, pos, len, item
--? {hdlg, iMsg, wParam, HIWORD(lParam), LOWORD(lParam)}
if iMsg = WM_INITDIALOG then
junk = c_func(SendMessage, {c_func(GetDlgItem, {hdlg, IDOK}),
WM_SETFONT, captionFont, 0})
junk = c_func(SendMessage, {c_func(GetDlgItem, {hdlg, IDCANCEL}),
WM_SETFONT, captionFont, 0})
junk = c_func(SendMessage, {c_func(GetDlgItem, {hdlg, IDRETRY}),
WM_SETFONT, captionFont, 0})
hList = c_func(GetDlgItem, {hdlg, DialogListID})
junk = c_func(SendMessage, {hList, WM_SETFONT, messageFont, 0})
hLabel = c_func(GetDlgItem, {hdlg, DialogLabelID})
junk = c_func(SendMessage, {hLabel, WM_SETFONT, messageFont, 0})
err = get_ex_err()
if length(err) = 0 then
junk = c_func(EndDialog, {hdlg, 0})
return 1
end if
junk = c_func(SendMessage, {hLabel, WM_SETTEXT, 0, alloc_string(err[2])})
for i = 3 to length(err) do
junk = c_func(SendMessage, {hList, LB_ADDSTRING, 0, alloc_string(err[i])})
end for
junk = c_func(SendMessage, {hList, LB_SETCURSEL, 0, 0})
junk = c_func(SetFocus, {hList})
elsif iMsg = WM_COMMAND then
if LOWORD(wParam) = IDOK then
hList = c_func(GetDlgItem, {hdlg, DialogListID})
pos = c_func(SendMessage, {hList, LB_GETCURSEL, 0, 0})
if pos != -1 then
goto_error(err, pos+1)
end if
junk = c_func(EndDialog, {hdlg, 1})
return 1
elsif LOWORD(wParam) = IDRETRY then
open_file(ex_err_name, 1)
junk = c_func(EndDialog, {hdlg, 0})
return 1
elsif LOWORD(wParam) = IDCANCEL then
junk = c_func(EndDialog, {hdlg, 0})
return 1
end if
elsif iMsg = WM_CLOSE then --closing dialog
junk = c_func(EndDialog, {hdlg, 0})
end if
return 0
end function
constant ViewErrorCallback = callback("ViewErrorProc")
global procedure ui_view_error()
integer junk
junk = DialogBoxIndirectParam(c_func(GetModuleHandle, {NULL}), {
--DLGTEMPLATE{style, exstyle, x, y, cx, cy, menu, wndclass, text}
{{WS_POPUP, WS_CAPTION, WS_SYSMENU, DS_MODALFRAME}, 0,
50, 50, 200,150, 0, 0, "View Error"},
--DLGITEMTEMPLATE{style, exstyle, x, y, cx, cy, id, dlgclass, text}
{{WS_CHILD, WS_VISIBLE, WS_VSCROLL}, WS_EX_CLIENTEDGE,
4,24, 192,108, DialogListID, DIALOG_CLASS_LIST, "ListBox"},
{{WS_CHILD, WS_VISIBLE}, 0,
4,4, 192,20, DialogLabelID, DIALOG_CLASS_STATIC, "Static"},
{{WS_CHILD, WS_VISIBLE, BS_PUSHBUTTON}, 0,
54,132, 44,12, IDCANCEL, DIALOG_CLASS_BUTTON, "Cancel"},
{{WS_CHILD, WS_VISIBLE, BS_PUSHBUTTON}, 0,
102,132, 44,12, IDRETRY, DIALOG_CLASS_BUTTON, "Open ex.err"},
{{WS_CHILD, WS_VISIBLE, BS_DEFPUSHBUTTON}, 0,
150,132, 44,12, IDOK, DIALOG_CLASS_BUTTON, "Goto Error"}
},
hMainWnd,
ViewErrorCallback,
0)
end procedure
global procedure ui_show_help(sequence html)
-- TODO
end procedure
global procedure ui_show_uri(sequence uri)
atom result
-- TODO: get default browser from
-- HKEY_LOCAL_MACHINE\SOFTWARE\Classes\http\shell\open\command
-- note: just opening the uri won't work, since shellexecute will
-- strip off any #anchor text, so using iexplore.exe for now
result = c_func(ShellExecute, {
hMainWnd, NULL,
alloc_string("iexplore.exe"),
alloc_string(uri),
NULL,
SW_SHOWNORMAL})
free_strings()
end procedure
procedure process_find(atom struc)
atom flags, junk, result
integer backward
flags = GetFindFlags(struc)
if and_bits(flags, FR_DIALOGTERM) then
find_phrase = GetFindWhat(struc)
replace_phrase = GetReplaceWith(struc)
--puts(1, find_phrase&" "&replace_phrase&"\n")
hFindDlg = 0
return
end if
--printf(1, "flags=%x\n", {flags})
backward = not and_bits(flags, FR_DOWN)
result = 0
if and_bits(flags, FR_MATCHCASE) then
result += SCFIND_MATCHCASE
end if
if and_bits(flags, FR_WHOLEWORD) then
result += SCFIND_WHOLEWORD
end if
junk = c_func(SendMessage, {hedit, SCI_SETSEARCHFLAGS, result, 0})
if and_bits(flags, FR_FINDNEXT) then
if search_find(GetFindWhat(struc), backward) = 0 then
result = c_func(MessageBox, {hFindDlg,
alloc_string("Unable to find a match."),
alloc_string("Find"),
or_all({MB_APPLMODAL, MB_ICONINFORMATION, MB_OK})})
end if
elsif and_bits(flags, FR_REPLACE) then
result = search_replace(GetReplaceWith(struc))
if search_find(GetFindWhat(struc), backward) = 0 and result = 0 then
result = c_func(MessageBox, {hFindDlg,
alloc_string("Unable to find a match."),
alloc_string("Replace"),
or_all({MB_APPLMODAL, MB_ICONINFORMATION, MB_OK})})
end if
elsif and_bits(flags, FR_REPLACEALL) then
result = search_replace_all(GetFindWhat(struc), GetReplaceWith(struc))
if result then
result = c_func(MessageBox, {hFindDlg,
alloc_string(sprintf("%d replacements.", {result})),
alloc_string("Replace All"),
or_all({MB_APPLMODAL, MB_ICONINFORMATION, MB_OK})})
else
result = c_func(MessageBox, {hFindDlg,
alloc_string("Unable to find a match."),
alloc_string("Replace All"),
or_all({MB_APPLMODAL, MB_ICONINFORMATION, MB_OK})})
end if
end if
free_strings()
end procedure
function RunArgsProc(atom hdlg, atom iMsg, atom wParam, atom lParam)
atom junk, hEdit, len, buf
--? {hdlg, iMsg, wParam, HIWORD(lParam), LOWORD(lParam)}
if iMsg = WM_INITDIALOG then
junk = c_func(SendMessage, {c_func(GetDlgItem, {hdlg, IDOK}),
WM_SETFONT, captionFont, 0})
junk = c_func(SendMessage, {c_func(GetDlgItem, {hdlg, IDCANCEL}),
WM_SETFONT, captionFont, 0})
hEdit = c_func(GetDlgItem, {hdlg, DialogEditID})
junk = c_func(SendMessage, {hEdit, WM_SETFONT, messageFont, 0})
junk = c_func(SendMessage, {hEdit, WM_SETTEXT, 0, alloc_string(get_tab_arguments())})
junk = c_func(SetFocus, {hEdit})
junk = c_func(SendMessage, {hEdit, EM_SETSEL, 0, -1})
elsif iMsg = WM_COMMAND then
if LOWORD(wParam) = IDOK then
hEdit = c_func(GetDlgItem, {hdlg, DialogEditID})
len = 1 + c_func(SendMessage, {hEdit, WM_GETTEXTLENGTH, 0, 0})
buf = allocate(len)
junk = c_func(SendMessage, {hEdit, WM_GETTEXT, len, buf})
junk = c_func(EndDialog, {hdlg, buf})
return 1
elsif LOWORD(wParam) = IDCANCEL then
junk = c_func(EndDialog, {hdlg, 0})
return 1
end if
elsif iMsg = WM_CLOSE then --closing dialog
junk = c_func(EndDialog, {hdlg, 0})
end if
return 0
end function
constant RunArgsCallback = callback("RunArgsProc")
global procedure run_arguments()
integer junk
junk = DialogBoxIndirectParam(c_func(GetModuleHandle, {NULL}), {
--DLGTEMPLATE{style, exstyle, x, y, cx, cy, menu, wndclass, text}
{{WS_POPUP, WS_CAPTION, WS_SYSMENU, DS_MODALFRAME}, 0,
50,50, 200,36, 0, 0, "Set Arguments"},
--DLGITEMTEMPLATE{style, exstyle, x, y, cx, cy, id, dlgclass, text}
{{WS_CHILD, WS_VISIBLE, WS_BORDER, ES_AUTOHSCROLL}, 0,
4,4, 192,12, DialogEditID, DIALOG_CLASS_EDIT, "tab arguments"},
{{WS_CHILD, WS_VISIBLE, BS_PUSHBUTTON}, 0,
104,20, 44,12, IDCANCEL, DIALOG_CLASS_BUTTON, "Cancel"},
{{WS_CHILD, WS_VISIBLE, BS_DEFPUSHBUTTON}, 0,
152,20, 44,12, IDOK, DIALOG_CLASS_BUTTON, "OK"}
},
hMainWnd,
RunArgsCallback,
0)
if junk then
set_tab_arguments(peek_string(junk))
free(junk)
end if
end procedure
function RunInterpreterProc(atom hdlg, atom iMsg, atom wParam, atom lParam)
atom junk, hEdit, hLabel, len, buf
sequence interpreters
integer index
--? {hdlg, iMsg, wParam, HIWORD(lParam), LOWORD(lParam)}
if iMsg = WM_INITDIALOG then
junk = c_func(SendMessage, {c_func(GetDlgItem, {hdlg, IDOK}),
WM_SETFONT, captionFont, 0})
junk = c_func(SendMessage, {c_func(GetDlgItem, {hdlg, IDCANCEL}),
WM_SETFONT, captionFont, 0})
junk = c_func(SendMessage, {c_func(GetDlgItem, {hdlg, DialogOpenID}),
WM_SETFONT, captionFont, 0})
hLabel = c_func(GetDlgItem, {hdlg, DialogLabelID})
junk = c_func(SendMessage, {hLabel, WM_SETFONT, messageFont, 0})
hEdit = c_func(GetDlgItem, {hdlg, DialogEditID})
junk = c_func(SendMessage, {hEdit, WM_SETFONT, messageFont, 0})
interpreters = get_interpreters()
for i = 1 to length(interpreters) do
junk = c_func(SendMessage, {hEdit, CB_ADDSTRING, 0, alloc_string(interpreters[i])})
end for
index = find(interpreter, interpreters)
if index then
junk = c_func(SendMessage, {hEdit, CB_SETCURSEL, index-1, 0})
end if
junk = c_func(SetFocus, {hEdit})
junk = c_func(SendMessage, {hEdit, EM_SETSEL, 0, -1})
elsif iMsg = WM_COMMAND then
if LOWORD(wParam) = DialogOpenID then
sequence temp = GetOpenFileName({hMainWnd, 0, alloc_string("Executable Files (*.exe)"&0&"*.EXE"&0&0), 0,
"", 0, 0,
OFN_EXPLORER + OFN_PATHMUSTEXIST + OFN_FILEMUSTEXIST + OFN_HIDEREADONLY
, 0})
if length(temp) then
temp = temp[2] -- just the filename
hEdit = c_func(GetDlgItem, {hdlg, DialogEditID})
junk = c_func(SendMessage, {hEdit, CB_SELECTSTRING, -1, alloc_string(temp)})
if junk = CB_ERR then
-- add a new filename since it wasn't found
junk = c_func(SendMessage, {hEdit, CB_INSERTSTRING, 0, alloc_string(temp)})
junk = c_func(SendMessage, {hEdit, CB_SETCURSEL, 0, 0})
end if
end if
free_strings()
elsif LOWORD(wParam) = IDOK then
hEdit = c_func(GetDlgItem, {hdlg, DialogEditID})
len = 1 + c_func(SendMessage, {hEdit, WM_GETTEXTLENGTH, 0, 0})
buf = allocate(len)
junk = c_func(SendMessage, {hEdit, WM_GETTEXT, len, buf})
junk = c_func(EndDialog, {hdlg, buf})
return 1
elsif LOWORD(wParam) = IDCANCEL then
junk = c_func(EndDialog, {hdlg, 0})
return 1
end if
elsif iMsg = WM_CLOSE then --closing dialog
junk = c_func(EndDialog, {hdlg, 0})
end if
return 0
end function
constant RunInterpreterCallback = callback("RunInterpreterProc")
global procedure run_interpreter()
integer junk
junk = DialogBoxIndirectParam(c_func(GetModuleHandle, {NULL}), {
--DLGTEMPLATE{style, exstyle, x, y, cx, cy, menu, wndclass, text}
{{WS_POPUP, WS_CAPTION, WS_SYSMENU, DS_MODALFRAME}, 0,
50,50, 200,56, 0, 0, "Set Interpreter"},
--DLGITEMTEMPLATE{style, exstyle, x, y, cx, cy, id, dlgclass, text}
{{WS_CHILD, WS_VISIBLE}, 0,
4,4, 192,20, DialogLabelID, DIALOG_CLASS_STATIC,
"Enter an interpreter to use to run programs, or select one from the list.\n"&
"Leave blank to use the default first item in the list."},
{{WS_CHILD, WS_VISIBLE, WS_BORDER, WS_HSCROLL, CBS_AUTOHSCROLL, CBS_DROPDOWN}, 0,
4,24, 176,12, DialogEditID, DIALOG_CLASS_COMBOBOX, "interpreter"},
{{WS_CHILD, WS_VISIBLE, BS_PUSHBUTTON}, 0,
184,24, 12,12, DialogOpenID, DIALOG_CLASS_BUTTON, "..."},
{{WS_CHILD, WS_VISIBLE, BS_PUSHBUTTON}, 0,
104,40, 44,12, IDCANCEL, DIALOG_CLASS_BUTTON, "Cancel"},
{{WS_CHILD, WS_VISIBLE, BS_DEFPUSHBUTTON}, 0,
152,40, 44,12, IDOK, DIALOG_CLASS_BUTTON, "OK"}
},
hMainWnd,
RunInterpreterCallback,
0)
if junk then
interpreter = peek_string(junk)
free(junk)
end if
end procedure
procedure run_start(integer with_args)
atom result
sequence args
-- save, no confirm
if save_if_modified(0) = 0 or length(file_name) = 0 then
return -- cancelled, or no name
end if
run_file_name = file_name
reset_ex_err()
args = quote_spaces(run_file_name)
if with_args then
if length(get_tab_arguments()) = 0 then
run_arguments()
end if
args &= ' ' & get_tab_arguments()
end if
-- if interpreter is set, use it
-- elsif Eu file and eu.cfg points to eudir use it (.exw,.ew->euiw,exw, .ex,.e->eui,ex)
-- else let OS handle it
-- and if that fails use EUDIR or include_paths
result = c_func(ShellExecute, {
hMainWnd, NULL,
alloc_string(get_eu_bin("")),
alloc_string(args),
alloc_string(dirname(run_file_name)),
SW_SHOWNORMAL})
if result < 33 then
-- shellexecute failed
if match(".exw", lower(run_file_name)) or
match(".ew", lower(run_file_name)) then
system(quote_spaces(get_eu_bin("euiw")) & ' ' & args)
else
system(quote_spaces(get_eu_bin("eui")) & ' ' & args)
end if
end if
free_strings()
end procedure
procedure run_convert(sequence name, sequence cmd)
atom result
-- save, no confirm
if save_if_modified(0) = 0 or length(file_name) = 0 then
return -- cancelled, or no name
end if
result = c_func(ShellExecute, {
hMainWnd, NULL,
alloc_string(get_eu_bin(cmd)),
alloc_string(quote_spaces(file_name)),
alloc_string(dirname(file_name)),
SW_SHOWNORMAL})
if result < 33 then
ui_message_box_error(name, cmd & " failed")
end if
end procedure
function get_appdata_path()
atom junk, path
sequence appdata
path = allocate(MAX_PATH)
junk = c_func(SHGetFolderPath, {
NULL,
CSIDL_LOCAL_APPDATA + CSIDL_FLAG_CREATE,
NULL,
0,
path})
appdata = peek_string(path)
free(path)
return appdata
end function
constant wee_conf_filename = get_appdata_path() & "\\wee_conf.txt"
function ColorsDialogProc(atom hdlg, atom iMsg, atom wParam, atom lParam)
atom junk, hEdit, len, buf
integer id
--? {hdlg, iMsg, wParam, HIWORD(lParam), LOWORD(lParam)}
if iMsg = WM_INITDIALOG then
junk = c_func(SendMessage, {c_func(GetDlgItem, {hdlg, IDOK}),
WM_SETFONT, captionFont, 0})
for i = 1000 to 1016 do
junk = c_func(SendMessage, {c_func(GetDlgItem, {hdlg, i}),
WM_SETFONT, captionFont, 0})
end for
for i = 0 to 6 do
if and_bits(bold_flags, power(2, i)) then
junk = BST_CHECKED
else
junk = BST_UNCHECKED
end if
junk = c_func(SendMessage, {c_func(GetDlgItem, {hdlg, 1010+i}),
BM_SETCHECK, junk, 0})
end for
elsif iMsg = WM_COMMAND then
id = LOWORD(wParam)
if id = IDOK then
junk = c_func(EndDialog, {hdlg, 1})
return 1
elsif id = IDCANCEL then
junk = c_func(EndDialog, {hdlg, 0})
return 1
elsif id = 1000 then
normal_color = ChooseColor(hMainWnd, normal_color)
reinit_all_edits()
return 0
elsif id = 1001 then
background_color = ChooseColor(hMainWnd, background_color)
reinit_all_edits()
return 0
elsif id = 1002 then
comment_color = ChooseColor(hMainWnd, comment_color)
reinit_all_edits()
return 0
elsif id = 1003 then
string_color = ChooseColor(hMainWnd, string_color)
reinit_all_edits()
return 0
elsif id = 1004 then
keyword_color = ChooseColor(hMainWnd, keyword_color)
reinit_all_edits()
return 0
elsif id = 1005 then
builtin_color = ChooseColor(hMainWnd, builtin_color)
reinit_all_edits()
return 0
elsif id = 1006 then
number_color = ChooseColor(hMainWnd, number_color)
reinit_all_edits()
return 0
elsif id = 1007 then
bracelight_color = ChooseColor(hMainWnd, bracelight_color)
reinit_all_edits()
return 0
elsif id = 1008 then
linenumber_color = ChooseColor(hMainWnd, linenumber_color)
reinit_all_edits()
return 0
elsif id >= 1010 and id <= 1016 then
junk = power(2, id - 1010)
if and_bits(bold_flags, junk) then
bold_flags = and_bits(bold_flags, not_bits(junk))
junk = BST_UNCHECKED
else
bold_flags = or_bits(bold_flags, junk)
junk = BST_CHECKED
end if
junk = c_func(SendMessage, {
c_func(GetDlgItem, {hdlg, id}), BM_SETCHECK, junk, 0})
reinit_all_edits()
return 0
end if
elsif iMsg = WM_CLOSE then --closing dialog
junk = c_func(EndDialog, {hdlg, 0})
end if
return 0
end function
constant ColorsDialogCallback = callback("ColorsDialogProc")
global procedure choose_colors()
integer junk
junk = DialogBoxIndirectParam(c_func(GetModuleHandle, {NULL}), {
--DLGTEMPLATE{style, exstyle, x, y, cx, cy, menu, wndclass, text}
{{WS_POPUP, WS_CAPTION, WS_SYSMENU, DS_MODALFRAME}, 0,
50,50, 100,166, 0, 0, "Colors"},
--DLGITEMTEMPLATE{style, exstyle, x, y, cx, cy, id, dlgclass, text}
{{WS_CHILD, WS_VISIBLE, BS_PUSHBUTTON}, 0,
4,4, 64,12, 1000, DIALOG_CLASS_BUTTON, "Normal"},
{{WS_CHILD, WS_VISIBLE, BS_PUSHBUTTON}, 0,
4,20, 64,12, 1001, DIALOG_CLASS_BUTTON, "Background"},
{{WS_CHILD, WS_VISIBLE, BS_PUSHBUTTON}, 0,
4,36, 64,12, 1002, DIALOG_CLASS_BUTTON, "Comment"},
{{WS_CHILD, WS_VISIBLE, BS_PUSHBUTTON}, 0,
4,52, 64,12, 1003, DIALOG_CLASS_BUTTON, "String"},
{{WS_CHILD, WS_VISIBLE, BS_PUSHBUTTON}, 0,
4,68, 64,12, 1004, DIALOG_CLASS_BUTTON, "Keyword"},
{{WS_CHILD, WS_VISIBLE, BS_PUSHBUTTON}, 0,
4,84, 64,12, 1005, DIALOG_CLASS_BUTTON, "Built-in"},
{{WS_CHILD, WS_VISIBLE, BS_PUSHBUTTON}, 0,
4,100, 64,12, 1006, DIALOG_CLASS_BUTTON, "Number"},
{{WS_CHILD, WS_VISIBLE, BS_PUSHBUTTON}, 0,
4,116, 64,12, 1007, DIALOG_CLASS_BUTTON, "Brace Highlight"},
{{WS_CHILD, WS_VISIBLE, BS_PUSHBUTTON}, 0,
4,132, 64,12, 1008, DIALOG_CLASS_BUTTON, "Line Number"},
{{WS_CHILD, WS_VISIBLE, BS_CHECKBOX}, 0,
72,4, 32,12, 1010, DIALOG_CLASS_BUTTON, "Bold"},
{{WS_CHILD, WS_VISIBLE, BS_CHECKBOX}, 0,
72,36, 32,12, 1011, DIALOG_CLASS_BUTTON, "Bold"},
{{WS_CHILD, WS_VISIBLE, BS_CHECKBOX}, 0,
72,52, 32,12, 1012, DIALOG_CLASS_BUTTON, "Bold"},
{{WS_CHILD, WS_VISIBLE, BS_CHECKBOX}, 0,
72,68, 32,12, 1013, DIALOG_CLASS_BUTTON, "Bold"},
{{WS_CHILD, WS_VISIBLE, BS_CHECKBOX}, 0,
72,84, 32,12, 1014, DIALOG_CLASS_BUTTON, "Bold"},
{{WS_CHILD, WS_VISIBLE, BS_CHECKBOX}, 0,
72,100, 32,12, 1015, DIALOG_CLASS_BUTTON, "Bold"},
{{WS_CHILD, WS_VISIBLE, BS_CHECKBOX}, 0,
72,116, 32,12, 1016, DIALOG_CLASS_BUTTON, "Bold"},
{{WS_CHILD, WS_VISIBLE, BS_DEFPUSHBUTTON}, 0,
4,150, 44,12, IDOK, DIALOG_CLASS_BUTTON, "Close"}
},
hMainWnd,
ColorsDialogCallback,
0)
end procedure
function icon_from_xpm(sequence xpm)
sequence colors = repeat(0,255), pixels = {}, andbits = {}
integer w = 0, h = 0, clear = 0
atom buf, handle, mask, iconinfo, hbmMask, hbmColor
for i = 2 to length(xpm) do
if length(xpm[i]) >= 6 and xpm[i][3] = 'c' then
if equal(xpm[i][5..$], "None") then
clear = xpm[i][1]
else
colors[xpm[i][1]] = value(xpm[i][5..$])
end if
else
w = length(xpm[i])
h += 1
for j = 1 to length(xpm[i]) do
if remainder(j, 8) = 1 then
andbits &= 0
end if
if xpm[i][j] = clear then
andbits[$] = or_bits(andbits[$], power(2, 7-and_bits(j-1,7)))
pixels &= 0
else
pixels &= #FF000000 + colors[xpm[i][j]][2]
end if
end for
end if
end for
mask = allocate(length(andbits))
poke(mask, andbits)
buf = allocate(length(pixels)*4)
poke4(buf, pixels)
hbmMask = c_func(CreateBitmap, {w, h, 1, 1, mask})
hbmColor = c_func(CreateBitmap, {w, h, 1, 32, buf})
iconinfo = allocate_pack("iddpp", {1,0,0,hbmMask,hbmColor})
handle = c_func(CreateIconIndirect, {iconinfo})
c_func(DeleteObject, {hbmMask})
c_func(DeleteObject, {hbmColor})
free(buf)
free(mask)
free(iconinfo)
return handle