-
Notifications
You must be signed in to change notification settings - Fork 0
/
dlogtool.cpp
executable file
·2134 lines (1863 loc) · 62.5 KB
/
dlogtool.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
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
// dlogtool.c
// OK. What on Earth is this?
// For various reasons (mainly customization and porting ease), we use a custom
// dialog box engine. This is it.
// Dialog boxes are created using the calls in this file. Basically, what happens,
// is that the editor loads in a dialog box resource. The text entries in that resource
// tell the editor what the dialog box should look like. An empty dialog box is created by
// the editor, and the editor draws the buttons on top of that.
// Events for that dialog box are handled using the call cd_event_filter. If you make a new
// dialog box, it must have a line hooking it in in that procedure.
// How to make a new dialog box.
// 1. Make the DLOG resource are usual.
// 2. Make item 1 a button. Move that button off of the window.
// 3. If you want text entry fields, make those items 2 - whatever. (i.e.
// 3 text entries their numbers are items 2-4).
// 4. All of the other items are text. Each is a number, then an underscore,
// then another number. (i.e. "0_1", "3_5").
// The meanings of the numbers are:
// First number = 0: Button. The second number is which button, the button types
// are described in arrays button_type and button_strs below
// First number = 1: Default Button. Like button, but is the default.
// First number = 2: Radio button. Next number should be 0.
// First number = 5: Picture. I don't think this works anymore.
// One exception: If you just want a chunk of text, you can have the text entry contain
// that text. If that text begins with ~, =, or *, formats text differently.
// Of course, you can just ignore all this mess and write regular dialog boxes.
#include "stdafx.h"
/*
#include <windows.h>
#include "stdio.h"
#include "string.h"
*/
#include "global.h"
#include "DibEngine.h"
#define ND 15
#define NI 500
#define NL 100
#define NUM_DLOG_B 53
#define DIALOG_PIXEL_ADJUST 6
// mode selector for cd_press_button()
enum EDLGBtnRes {
eDLGBtnResCompatible, // change graphics of the button - sound and delay - recover graphics
eDLGBtnResChange, // change graphics of the button - sound (no delay)
eDLGBtnResRecover, // recover graphics of the button
};
// Gloabl varialbes
Boolean dialog_not_toast = FALSE;
// external gloabal variables
extern HINSTANCE store_hInstance;
extern HWND mainPtr;
extern HDC main_dc;
extern HFONT font;
extern HFONT bold_font;
extern HACCEL accel;
extern short dlg_units_x;
extern short dlg_units_y;
extern char szWinName[];
extern RECT buttons_from[NUM_BUTTONS];
//extern Boolean block_erase;
extern Boolean mouse_button_held;
/* Adventure globals */
extern HDIB buttons_gworld;
// local variables
short current_key = 0;
short dlg_keys[ND];
short dlg_types[ND];
HWND dlgs[ND];
HWND dlg_parent[ND];
short dlg_highest_item[ND];
Boolean dlg_draw_ready[ND];
short dlog_item_type[NI];
short item_dlg[NI];
short item_number[NI];
// char dlg_item_type[NI];
RECT item_rect[NI];
short item_flag[NI];
short item_active[NI];
char item_key[NI];
short item_label[NI];
short item_label_loc[NI];
char text_long_str[10][256];
char text_short_str[140][40];
char labels[NL][25];
Boolean label_taken[NL];
char custom_dlg_strs[12][256];
short custom_dlg_strs_indent[12];
short store_free_slot,store_dlog_num;
short win_adjust_x = 18,win_adjust_y = 0;//20;
HWND edit_box[80];
HWND store_edit_parent[80];
short store_edit_parent_num[80];
short store_edit_item[80]; // kludgy
WNDPROC old_edit_proc[80];
HDC dlg_force_dc = NULL; // save HDCs when dealing with dlogs
HWND store_parent;
HFONT font_save;
Boolean block_next_dialog_key_event = FALSE;
short available_dlog_buttons[NUM_DLOG_B] = {0,63,64,65,1, 4,5,8,128,9,
10,11,12,13,14, 15,16,17,29, 51,
60,61,62, 66,69,70, 71,72,73,74, // 20
79,80,83,86,87,88, 91,92,93,99,
100,
101,102,104, 129,130,131,132,133,134,135,136,137};
short button_type[150] = {1,1,4,5,1,1,0,0,1,1,
1,1,1,1,1,1,1,1,8,8,
9,9,9,1,1,2,1,6,7,1,
1,12,1,1,2,0,0,0,0,0,
0,0,0,0,0,0,0,0,0,0,
0,1,1,1,2,1,1,1,2,2, // 50
1,1,1,1,1,1,2,3,1,1,
1,1,1,1,2,2,2,2,2,1,
1,1,1,1,2,2,1,1,1,2,
0,1,1,1,15,13,12,12,12,1,
1,1,1,2,1,2,2,2,2,1, // 100
2,2,2,2,2,2,2,2,2,2,
2,2,2,2,2,2,2,2,1,1,
1,1,1,1,1,1,1,1,13,14,
0,0,0,0,0,0,0,0,0,0};
// These are the bits of text that appear on the buttons in the dialog boxes.
// If a button has text 0_51, it shows text 51 ("Take"). If a button has text 1_0, it
// means text 0 ("Done"). The 0_ or the 1_ at the beginning doesn't mean anything to you.
char *button_strs[150] = {"Done ","Ask"," "," ","Keep", "Cancel","+","-","Buy","Leave",
"Get","1","2","3","4","5","6","Cast"," "," ",
" "," "," ","Buy","Sell","Choose","Buy x10"," "," ","Save",
"Race","Train","Items","Spells","Heal Party","1","2","3","4","5",
"6","7","8","9","10","11","12","13","14","15",
/*50*/ "16","Take","Create","Delete","Race/Special","Skill","Name","Graphic","Bash Door","Pick Lock",
/*60*/ "Leave","Steal","Attack","OK","Yes","No","Step In"," ","Record","Climb",
"Flee","Onward","Answer","Drink","Approach","Mage Spells","Priest Spells","Advantages","Main Menu","Land",
"Under","Restore","Restart","Quit","Save First","Just Quit","Rest","Read","Pull","Potions",
/*90*/ "17","Cancel","Pray","Wait","","","Delete","Graphic","Create","Give",
/*100*/ "Destroy","Pay","Free","Next Tip","Touch", "Select Icon","Create/Edit","Clear Special","Edit Abilities","Choose",
"Go Back","Create New","General","One Shots","Affect PCs","If-Thens","Town Specs","Out Specs","Advanced","Weapon Abil",
"General Abil.","NonSpell Use","Spell Usable","Reagents","Missiles","Abilities","Pick Picture","Animated","Enter","Burn",
"Insert","Remove","Accept","Refuse","Open","Close","Sit","Stand","","",
"18","19","20","Invisible!","3DEditor","","","","",""};
short button_left_adj[150] = {2,0,0,0,6,0,0,0,4,5,
3,0,0,0,0,0,0,4,0,0,
0,0,0,4,0,5,0,0,0,6,
6,6,0,0,0,0,0,0,0,0,
0,0,0,0,6,6,6,6,6,6,
6,6,0,2,0,0,0,2,3,3, // 50
6,6,0,7,5,5,0,0,2,6,
4,2,0,5,0,4,10,8,0,6,
6,2,1,6,4,3,6,4,6,4,
6,6,6,6,0,0,0,2,0,4,
2,6,6,3,6,7,3,0,0,0, // 100
0,5,3,3,3,3,3,4,4,4,
6,4,4,2,2,3,6,5,6,6,
0,4,2,2,6,4,6,3,0,0,
0,0,0,0,0,0,0,0,0,0
};
char button_def_key[150] = {
0,0,20,21,'k', 24,0,0,0,0,
'g','1','2','3','4', '5','6',0,0,0,
0,0,0,0,0,' ',0,22,23,0,
0,0,0,0,0,'1','2','3','4','5',
'6','7','8','9','a', 'b','c','d','e','f',
'g',0,0,0,0,0,0,0,0,0,
0,0,0,0,'y','n',0,'?','r',0,
0,0,0,0,0,0,0,0,0, 0,
0,0,0,0,0,0,0,0,0,0,
'g',0,0,0,0,0,0,0,0,0,
0,0,0,0,0,0,0,0,0,0,
0,0,0,0,0,0,0,0,0,0,
0,0,0,0,0,0,0,0,0,0,
0,0,0,0,'o',0,0,0,0,0,
0,0,0,0,0,0,0,0,0,0
};
// specials ... 20 - <- 21 - -> 22 up 23 down 24 esc
// 25-30 ctrl 1-6 31 - return\
// function prototypes
short cd_create_dialog(short dlog_num,HWND parent);
// void process_new_window (HWND hDlg);
// void cd_set_edit_focus(short which_win);
short cd_process_mousetrack( short dlg_num, short item_num, RECT theRect );
// void cd_init_button(short dlog_num,short item_num, short button_num, short status);
// void cd_attach_key(short dlog_num,short item_num,char key);
// void csp(short dlog_num, short item_num, short pict_num);
// void cd_set_pict(short dlog_num, short item_num, short pict_num);
// short cd_get_active(short dlog_num, short item_num);
void cd_set_item_text(short dlog_num, short item_num, const char* str);
void cd_set_item_num(short dlog_num, short item_num, short num);
// void cd_set_flag(short dlog_num,short item_num,short flag);
// void cd_text_frame(short dlog_num,short item_num,short frame);
// void cd_take_label(short dlog_num, short item_num);
// void cd_key_label(short dlog_num, short item_num,short loc);
void cd_draw_item(short dlog_num,short item_num);
void cd_initial_draw(short dlog_num);
void cd_draw(short dlog_num);
void cd_frame_item(short dlog_num, short item_num, short width);
void cd_erase_item(short dlog_num, short item_num);
// void cd_erase_rect(short dlog_num,RECT to_fry);
void cd_press_button(short dlog_num, short item_num, EDLGBtnRes mode );
short cd_get_indices(short dlg_num, short item_num, short* dlg_index, short* item_index);
short cd_get_dlg_index(short dlog_num);
short cd_get_item_id(short dlg_num, short item_num);
RECT get_item_rect(HWND hDlg, short item_num);
void frame_dlog_rect(HWND hDlg, RECT rect, short val);
// void draw_dialog_graphic(HWND hDlg, RECT rect, short which_g, Boolean do_frame,short win_or_gworld);
// RECT calc_rect(short i, short j);
// RECT calc_from_rect(short i, short j);
// RECT get_graphic_rect(HDIB graf);
// void clear_dlog_strs();
// void set_next_dlg_str(short which_str,char *str,short indent);
// short cd_complex_create_custom_dialog(HWND parent, short buttons[3],Boolean record_button);
void cd_kill_dc(short which_slot,HDC hdc);
HDC cd_get_dlog_dc(short which_slot);
INT_PTR CALLBACK dummy_dialog_proc(HWND hDlg, UINT message, WPARAM wParam, LPARAM lParam);
LRESULT CALLBACK fresh_edit_proc(HWND hwnd, UINT message, WPARAM wParam, LPARAM lParam);
void cd_init_dialogs()
{
short i;
for (i = 0; i < ND; i++) {
dlg_keys[i] = -1;
dlg_types[i] = 0;
dlgs[i] = NULL;
dlg_highest_item[i] = 0;
}
for (i = 0; i < NI; i++) {
item_dlg[i] = -1;
}
for (i = 0; i < NL; i++) {
label_taken[i] = FALSE;
}
for (i = 0; i < 80; i++) {
edit_box[i] = NULL;
store_edit_parent[i] = NULL;
store_edit_parent_num[i] = -1;
store_edit_item[i] = -1 ;
}
}
LRESULT CALLBACK fresh_edit_proc(HWND hwnd, UINT message, WPARAM wParam, LPARAM lParam)
{
short i,cur_box = -1,cur_item_num = -1,item_for_focus = -1,first_edit_box = -1;
for (i = 0; i < 80; i++)
if (edit_box[i] == hwnd) {
cur_box = i;
cur_item_num = store_edit_item[i];
}
if (cur_box >= 0) {
switch (message) {
case WM_CHAR:
if ((char) (wParam) == 9) {
return TRUE;
}
break;
case WM_KEYDOWN:
// if (wParam == VK_RETURN)
// SendMessage(store_edit_parent[cur_box],WM_COMMAND,9,0);
// if (wParam == VK_ESCAPE)
// SendMessage(store_edit_parent[cur_box],WM_COMMAND,8,0);
if (wParam == VK_RETURN)
SendMessage(store_edit_parent[cur_box],WM_KEYDOWN,wParam,lParam);
if (wParam == VK_ESCAPE)
SendMessage(store_edit_parent[cur_box],WM_KEYDOWN,wParam,lParam);
if (wParam == VK_TAB) {
//play_sound(1);
for (i = 0; i < 80; i++) {
if ((store_edit_parent[i] == store_edit_parent[cur_box]) &&
(store_edit_item[i] == cur_item_num + 1))
item_for_focus = i;
if ((store_edit_parent[i] == store_edit_parent[cur_box]) &&
(store_edit_item[i] == 2))
first_edit_box = i;
}
//SendMessage(store_edit_parent[cur_box],WM_KEYDOWN,wParam,lParam);
if (item_for_focus >= 0)
SetFocus(edit_box[item_for_focus]);
else if (first_edit_box >= 0)
SetFocus(edit_box[first_edit_box]);
return TRUE;
}
break;
}
return CallWindowProc(old_edit_proc[cur_box],hwnd,message,wParam,lParam);
}
return 0;
}
short cd_create_dialog_parent_num(short dlog_num,short parent)
{
short i;
if ((parent == 0) || (parent == 1))
return cd_create_dialog(dlog_num,mainPtr);
i = cd_get_dlg_index(parent);
if (i < 0)
return -1;
return cd_create_dialog(dlog_num,dlgs[i]);
}
short cd_create_dialog(short dlog_num,HWND parent)
{
short i,free_slot = -1;
HWND dlg;
if (parent != NULL) {
if (IsWindowEnabled(parent) == 0)
return -1;
}
mouse_button_held = FALSE;
store_dlog_num = dlog_num;
//store_parent = parent;
for (i = 0; i < ND; i++) {
if ((dlg_keys[i] >= 0) && (dlg_types[i] == dlog_num))
return -1;
}
for (i = 0; i < ND; i++) {
if (dlg_keys[i] < 0) {
free_slot = i;
i = 500;
}
}
if (free_slot < 0)
return -2;
current_key++;
dlg_keys[free_slot] = current_key;
dlg_types[free_slot] = dlog_num;
dlg_highest_item[free_slot] = 1;
dlg_draw_ready[free_slot] = FALSE;
dlgs[free_slot] = NULL;
// first, create dummy dlog
store_free_slot = free_slot;
dlg = CreateDialog(store_hInstance,MAKEINTRESOURCE(dlog_num),0, dummy_dialog_proc);
if (dlgs[free_slot] == NULL) {
play_sound(3);
return -3;
}
make_cursor_sword();
center_window(dlgs[free_slot]);
dlg_parent[free_slot] = parent;
ShowWindow(dlgs[free_slot],SW_SHOW);
DestroyWindow(dlg); //Necesary? Dunno.
if (dlg_parent[free_slot] != NULL) {
EnableWindow(dlg_parent[free_slot],FALSE);
//if (dlg_parent[free_slot] == mainPtr)
// if (map_dlg_exists == TRUE)
// EnableWindow(map_dlg,FALSE);
}
dialog_not_toast = TRUE;
return 0;
}
INT_PTR CALLBACK dummy_dialog_proc(HWND hDlg, UINT message, WPARAM /*wParam*/, LPARAM /*lParam*/) {
short i,j,k,free_slot = -1,free_item = -1,type,flag;
char item_str[256];
Boolean str_stored = FALSE,focus_set = FALSE;
RECT dlg_rect,store_rect;
short win_height = 0, win_width = 0, num_text_boxes = 0;
short str_offset = 1;
RECT pic_rect = {7,7,43,43};
free_slot = store_free_slot;
switch (message) {
case WM_INITDIALOG:
// now, make a window, matching dialog
GetWindowRect(hDlg,&dlg_rect);
dlgs[store_free_slot] = CreateWindow (szWinName,
"BoA 3D Editor Dialog",
// WS_BORDER | WS_POPUP,// was visible
WS_TILEDWINDOW,
0,
0,
(dlg_rect.right - dlg_rect.left * 8) / dlg_units_x,
(dlg_rect.bottom - dlg_rect.top * 16) / dlg_units_y,
NULL,
NULL,
store_hInstance,
NULL);
// Now, give the window its items
for (i = 0; i < 200; i++)
if (GetDlgItem(hDlg,i) != NULL) {
GetDlgItemText(hDlg,i,item_str,256);
str_offset = 1;
dlg_highest_item[free_slot] = i;
str_stored = FALSE;
if (strlen((char *)item_str) == 0) {
sprintf((char *) item_str, "+");
type = 3;
flag = 0;
str_stored = TRUE;
}
else if (item_str[0] == '+') { // default is framed text
type = 3;
flag = 1;
str_stored = TRUE;
}
else if (item_str[0] == '*') {
type = 3;
flag = 0;
str_stored = TRUE;
}
else if (item_str[0] == '~') {
type = 7;
flag = 0;
str_stored = TRUE;
}
else if (item_str[0] == '!') {
type = 4;
flag = 0;
str_stored = TRUE;
}
else if (item_str[0] == '=') {
type = 9;
flag = 1;
str_stored = TRUE;
}
else if (((item_str[0] >= 65) && (item_str[0] <= 122)) || (item_str[0] == '"')) {
type = 9;
flag = 0;
str_offset = 0;
str_stored = TRUE;
}
else if ((item_str[0] == '^') || (item_str[0] == '&')) {
type = (item_str[0] == '^') ? 10 : 11;
flag = 1;
//if (string_length((char *) item_str) > 55)
// flag = 2;
str_stored = TRUE;
}
else sscanf(item_str,"%hd_%hd",&type,&flag);
free_item = -1;
// find free item
switch (type) {
case 0: case 1: case 2: case 5: case 6:
for (j = 150; j < NI; j++)
if (item_dlg[j] < 0) {
free_item = j;
j = NI + 1;
}
break;
default:
if ((type == 9) ||
((str_stored == TRUE) && (strlen((char *) item_str) > 35))) {
for (j = 0; j < 10; j++)
if (item_dlg[j] < 0) {
free_item = j;
j = NI + 1;
}
}
else {
for (j = 10; j < 140; j++)
if (item_dlg[j] < 0) {
free_item = j;
j = NI + 1;
}
}
break;
}
if (free_item >= 0) {
item_dlg[free_item] = store_dlog_num;
dlog_item_type[free_item] = type;
item_number[free_item] = i;
item_rect[free_item] = get_item_rect(hDlg,i);
OffsetRect(&item_rect[free_item],12,12);
item_rect[free_item].top = item_rect[free_item].top / 2;
item_rect[free_item].left = item_rect[free_item].left / 2;
item_rect[free_item].bottom = item_rect[free_item].bottom / 2;
item_rect[free_item].right = item_rect[free_item].right / 2;
item_rect[free_item].top = (item_rect[free_item].top * 16) / dlg_units_y;
item_rect[free_item].left = (item_rect[free_item].left * 8) / dlg_units_x;
item_rect[free_item].bottom = (item_rect[free_item].bottom * 16) / dlg_units_y;
item_rect[free_item].right = (item_rect[free_item].right * 8) / dlg_units_x;
item_flag[free_item] = flag;
item_active[free_item] = 1;
item_label[free_item] = 0;
item_label_loc[free_item] = -1;
item_key[free_item] = 0;
switch (type) {
case 0: case 1:
if (item_flag[free_item] != 143) {
store_rect = buttons_from[button_type[flag]];
item_rect[free_item].right = item_rect[free_item].left + (store_rect.right - store_rect.left);
item_rect[free_item].bottom = item_rect[free_item].top + (store_rect.bottom - store_rect.top);
item_key[free_item] = button_def_key[flag];
if (type == 1)
item_key[free_item] = 31;
}
break;
case 2:
item_rect[free_item].right = item_rect[free_item].left + 12;
item_rect[free_item].bottom = item_rect[free_item].top + 12;
item_key[free_item] = -1;
break;
case 5: // std dlog pic position
if (item_flag[free_item] < 700)
item_rect[free_item] = pic_rect;
break;
case 3: case 4: case 7: case 8: case 9: case 10: case 11:
sprintf(((free_item < 10) ? text_long_str[free_item] : text_short_str[free_item - 10]),"");
if (str_stored == TRUE) {
if (free_item < 10) {
sprintf(text_long_str[free_item],"%s",
(char *) (item_str + str_offset));
for (k = 0; k < 256; k++) {
if (text_long_str[free_item][k] == '|')
text_long_str[free_item][k] = 13;
if (text_long_str[free_item][k] == '_')
text_long_str[free_item][k] = '"';
if (text_long_str[free_item][k] == 213)
text_long_str[free_item][k] = 39;
if (text_long_str[free_item][k] == -43)
text_long_str[free_item][k] = 39;
}
// give text a little extra room
//if ((store_dlog_num >= 2000) || (store_dlog_num == 986))
// item_rect[free_item].right += 20;
}
else {
sprintf(text_short_str[free_item - 10],"%-34s",
(char *) (item_str + str_offset));
for (k = 0; k < 35; k++) {
if (text_short_str[free_item][k] == '|')
text_short_str[free_item][k] = 13;
if (text_short_str[free_item][k] == '_')
text_short_str[free_item][k] = '"';
if (text_long_str[free_item][k] == 213)
text_long_str[free_item][k] = 39;
if (text_long_str[free_item][k] == -43)
text_long_str[free_item][k] = 39;
}
}
}
item_key[free_item] = -1;
if (type >= 10) { // never got used
break;
//store_rect = dlg_buttons_gworld[1][0]->portRect;
//item_rect[free_item].right = item_rect[free_item].left + store_rect.right;
//item_rect[free_item].bottom = item_rect[free_item].top + store_rect.bottom;
//if (type == 11)
// item_key[free_item] = 31;
}
break;
case 6:
for (short l = 0; l < 80; l++)
if (store_edit_parent[l] == NULL) {
if (item_rect[free_item].bottom - item_rect[free_item].top < 24)
item_rect[free_item].top -= 2;
if (item_rect[free_item].bottom - item_rect[free_item].top <= 22)
edit_box[l] = CreateWindow("edit",NULL,WS_CHILD | WS_BORDER | WS_VISIBLE | ES_AUTOVSCROLL,
item_rect[free_item].left,item_rect[free_item].top,
item_rect[free_item].right - item_rect[free_item].left,
smax(22, (short)(item_rect[free_item].bottom - item_rect[free_item].top)),
dlgs[free_slot],(HMENU) 150,store_hInstance,NULL);
else edit_box[l] = CreateWindow("edit",NULL,WS_CHILD | WS_BORDER | WS_VISIBLE | ES_MULTILINE | ES_AUTOVSCROLL,
item_rect[free_item].left,item_rect[free_item].top,
item_rect[free_item].right - item_rect[free_item].left,
smax(22, (short)(item_rect[free_item].bottom - item_rect[free_item].top)),
dlgs[free_slot],(HMENU) 150,store_hInstance,NULL);
num_text_boxes++;
store_edit_parent[l] = dlgs[free_slot];
store_edit_parent_num[l] = store_dlog_num;
store_edit_item[l] = i;
old_edit_proc[l] = (WNDPROC)GetWindowLong(edit_box[l], GWL_WNDPROC);
SetWindowLong(edit_box[l], GWL_WNDPROC, (LONG)fresh_edit_proc);
if (focus_set == FALSE) {
SetFocus(edit_box[l]);
focus_set = TRUE;
}
l = 80;
}
break;
}
if (free_item > 1) {
win_height = smax(win_height, (short)(item_rect[free_item].bottom + 28 +
((dlg_units_y > 16) ? 3 : 0)));
win_width = smax(win_width, (short)item_rect[free_item].right + 11);
}
}
}
MoveWindow(dlgs[free_slot],0,0,win_width + win_adjust_x,win_height + 3 + win_adjust_y,FALSE);
EndDialog(hDlg, 0);
return TRUE;
}
return TRUE;
}
/*
void cd_set_edit_focus(short which_win)
{
short i;
for (i = 0; i < 80; i++)
if (store_edit_parent_num[i] == which_win) {
if (edit_box[i] != NULL)
SetFocus(edit_box[i]);
return;
}
}
*/
short cd_kill_dialog(short dlog_num,short parent_message)
{
short i,which_dlg = -1;
for (i = 0; i < ND; i++)
if ((dlg_keys[i] >= 0) && (dlg_types[i] == dlog_num))
which_dlg = i;
if (which_dlg < 0)
return -1;
for (i = 0; i < NI; i++)
if (item_dlg[i] == dlog_num) {
if (dlog_item_type[i] == 6) {
for (short j = 0; j < 80; j++)
if ((store_edit_parent_num[j] == dlog_num) && (store_edit_item[j] == item_number[i])) {
DestroyWindow(edit_box[j]);
store_edit_parent[j] = NULL;
edit_box[j] = NULL;
}
}
if (item_label[i] > 0)
label_taken[item_label_loc[i]] = FALSE;
item_dlg[i] = -1;
}
if (dlg_parent[which_dlg] != NULL) {
EnableWindow(dlg_parent[which_dlg],TRUE);
//if (dlg_parent[which_dlg] == mainPtr)
// if (map_dlg_exists == TRUE)
// EnableWindow(map_dlg,TRUE);
SetFocus(dlg_parent[which_dlg]);
SetWindowPos(dlg_parent[which_dlg],HWND_TOP,0,0,100,100,
SWP_NOMOVE | SWP_NOSIZE | SWP_NOREDRAW);
//cd_set_edit_focus(dlg_parent[which_dlg]);
}
if (parent_message > 0)
SendMessage(dlg_parent[which_dlg],WM_COMMAND,parent_message,0);
DestroyWindow(dlgs[which_dlg]);
dlg_keys[which_dlg] = -1;
dialog_not_toast = TRUE;
//?block_erase = TRUE;
return 0;
}
short cd_process_click(HWND window,POINT the_point, WPARAM wparam, /*LPARAM lparam,*/ short *item)
{
short i,which_dlg,dlg_num,item_id;
short dlog_key;
if ((which_dlg = cd_find_dlog(window,&dlg_num,&dlog_key)) < 0)
return -1;
for (i = 0; i < dlg_highest_item[which_dlg] + 1; i++)
if ((item_id = cd_get_item_id(dlg_num,i)) >= 0) {
if ((POINTInRECT(the_point,item_rect[item_id])) && (item_active[item_id] > 0)
&& ((dlog_item_type[item_id] < 3) || (dlog_item_type[item_id] == 8)
|| (dlog_item_type[item_id] == 10)|| (dlog_item_type[item_id] == 11))) {
*item = i;
if (MK_CONTROL & wparam)
*item += 100;
if (dlog_item_type[item_id] != 8)
dlg_num = cd_process_mousetrack( dlg_num, i, item_rect[item_id] );
return dlg_num;
}
}
return -1;
}
short cd_process_mousetrack( short dlg_num, short item_num, RECT theRect )
{
short result = -1;
bool prevInside = false;
bool currInside = true;
cd_press_button(dlg_num, item_num, eDLGBtnResChange); // give click response
// Track mouse while it is down
bool still_down = true;
while ( still_down ) {
POINT currPt;
MSG msg;
GetMessage(&msg, NULL, WM_MOUSEFIRST , WM_MOUSELAST);
currPt.x = (int)(short)LOWORD(msg.lParam);
currPt.y = (int)(short)HIWORD(msg.lParam);
switch (msg.message)
{
// handle movement messages
case WM_MOUSEMOVE:
prevInside = currInside;
currInside = POINTInRECT(currPt, theRect);
if ( !prevInside && currInside )
cd_press_button(dlg_num, item_num, eDLGBtnResChange);
if ( prevInside && !currInside )
cd_press_button(dlg_num, item_num, eDLGBtnResRecover);
break;
// handle accept messages
case WM_LBUTTONUP:
if ( POINTInRECT(currPt, theRect) )
result = dlg_num;
still_down = false;
break;
// ignore these messages
case WM_LBUTTONDOWN:
case WM_RBUTTONDOWN:
case WM_RBUTTONUP:
case WM_MBUTTONDOWN:
case WM_MBUTTONUP:
break;
// just dispatch rest of the messages
default:
DispatchMessage(&msg);
break;
}
}
cd_press_button(dlg_num, item_num, eDLGBtnResRecover);
return result;
}
short cd_process_syskeystroke(HWND window,WPARAM wparam,/* LPARAM lparam,*/ short *item)
{
short i,which_dlg,dlg_num,dlg_key,item_id;
char char_hit;
if ((which_dlg = cd_find_dlog(window,&dlg_num,&dlg_key)) < 0)
return -1;
// specials ... 20 - <- 21 - -> 22 up 23 down 24 esc
// 25-30 ctrl 1-6
switch (wparam) {
case VK_ESCAPE:
char_hit = 24;
break;
case VK_LEFT:
char_hit = 20;
break;
case VK_UP:
char_hit = 22;
break;
case VK_RIGHT:
char_hit = 21;
break;
case VK_DOWN:
char_hit = 23;
break;
case VK_RETURN:
char_hit = 31;
break;
case VK_NUMPAD1: case VK_NUMPAD2: case VK_NUMPAD3: case VK_NUMPAD4: case VK_NUMPAD5:
block_next_dialog_key_event = TRUE;
return -1;
break;
default:
return -1;
}
for (i = 0; i < dlg_highest_item[which_dlg] + 1; i++)
if ((item_id = cd_get_item_id(dlg_num,i)) >= 0) {
if ((item_key[item_id] == char_hit) && (item_active[item_id] > 0)
&& ((dlog_item_type[item_id] < 3) || (dlog_item_type[item_id] == 8))) {
*item = i;
if (dlog_item_type[item_id] != 8)
cd_press_button(dlg_num, i, eDLGBtnResCompatible);
return dlg_num;
}
}
// kludgy. If you get an escape and is isn't processed, make it an enter
if (wparam == VK_ESCAPE) {
char_hit = 31;
for (i = 0; i < dlg_highest_item[which_dlg] + 1; i++)
if ((item_id = cd_get_item_id(dlg_num,i)) >= 0) {
if ((item_key[item_id] == char_hit) && (item_active[item_id] > 0)
&& ((dlog_item_type[item_id] < 3) || (dlog_item_type[item_id] == 8))) {
*item = i;
if (dlog_item_type[item_id] != 8)
cd_press_button( dlg_num, i, eDLGBtnResCompatible);
return dlg_num;
}
}
}
return -1;
}
short cd_process_keystroke(HWND window,WPARAM wparam,/* LPARAM lparam,*/ short *item)
{
short i,which_dlg,dlg_num,dlg_key,item_id;
char char_hit;
if ((which_dlg = cd_find_dlog(window,&dlg_num,&dlg_key)) < 0)
return -1;
// specials ... 20 - <- 21 - -> 22 up 23 down 24 esc
// 25-30 ctrl 1-6
char_hit = (char) wparam;
if (block_next_dialog_key_event == TRUE) {
block_next_dialog_key_event = FALSE;
return -1;
}
for (i = 0; i < dlg_highest_item[which_dlg] + 1; i++)
if ((item_id = cd_get_item_id(dlg_num,i)) >= 0) {
if (((item_key[item_id] == char_hit) && (item_active[item_id] > 0)
&& ((dlog_item_type[item_id] < 3) || (dlog_item_type[item_id] == 8))) ||
((item_key[item_id] == '1') && (char_hit == 13))) {
*item = i;
if (dlog_item_type[item_id] != 8)
cd_press_button( dlg_num,i, eDLGBtnResCompatible );
return dlg_num;
}
}
return -1;
}
/*
void cd_attach_key(short dlog_num,short item_num,char key)
{
short dlg_index,item_index;
if (cd_get_indices(dlog_num,item_num,&dlg_index,&item_index) < 0)
return;
if ((dlog_item_type[item_index] > 2) && (dlog_item_type[item_index] != 8)) {
beep();
return;
}
item_key[item_index] = key;
}
*/
/*
void csp(short dlog_num, short item_num, short pict_num)
{
cd_set_pict( dlog_num, item_num, pict_num);
}
*/
/*
void cd_set_pict(short dlog_num, short item_num, short pict_num)
{
short dlg_index,item_index;
if (cd_get_indices(dlog_num,item_num,&dlg_index,&item_index) < 0)
return;
if (dlog_item_type[item_index] != 5) {
beep();
return;
}
item_flag[item_index] = pict_num;
if (pict_num == -1)
cd_erase_item(dlog_num,item_num);
else cd_draw_item(dlog_num,item_num);
}
*/
void cd_activate_item(short dlog_num, short item_num, short status)
{
short dlg_index,item_index;
if (cd_get_indices(dlog_num,item_num,&dlg_index,&item_index) < 0)
return;
item_active[item_index] = status;
cd_draw_item(dlog_num,item_num);
}
/*
short cd_get_active(short dlog_num, short item_num)
{
short dlg_index,item_index;
if (cd_get_indices(dlog_num,item_num,&dlg_index,&item_index) < 0)
return -1;
return item_active[item_index];
}
*/
void cd_get_item_text(short dlog_num, short item_num, char *str)
{
short dlg_index,item_index;
if (cd_get_indices(dlog_num,item_num,&dlg_index,&item_index) < 0)
return ;
if (dlog_item_type[item_index] == 6) {
sprintf(str,"");
for (short i = 0; i < 80; i++)
if ((store_edit_parent_num[i] == dlog_num) && (store_edit_item[i] == item_num)
&& (edit_box[i] != NULL))
GetWindowText(edit_box[i],str,255);
return;
}
if (item_index >= 150) {
beep();
return;
}
if (item_index < 10)
sprintf(str,"%s",text_long_str[item_index]);
else sprintf(str,"%s",text_short_str[item_index - 10]);
}
void csit(short dlog_num, short item_num, const char* str)
{
cd_set_item_text( dlog_num, item_num, str);
}
/*
void cd_get_text_edit_str(short dlog_num, char *str)
{
if (edit_box != NULL)
GetWindowText(edit_box,str,255);
else str[0] = 0;
}
// NOTE!!! Expects a c string
void cd_set_text_edit_str(short dlog_num,short item_num, char *str)
{
if (edit_box != NULL)
SetWindowText(edit_box,str);
}
*/
void cd_retrieve_text_edit_str(short dlog_num, short item_num, char *str)
{
short i;