forked from otya128/winevdm
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathdialog.c
1098 lines (999 loc) · 32.2 KB
/
dialog.c
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
/*
* 16-bit dialog functions
*
* Copyright 1993, 1994, 1996, 2003 Alexandre Julliard
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
* License as published by the Free Software Foundation; either
* version 2.1 of the License, or (at your option) any later version.
*
* This library is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
* License along with this library; if not, write to the Free Software
* Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA
*/
#include "config.h"
#include "wine/port.h"
#include <stdarg.h>
#include "windef.h"
#include "winbase.h"
#include "wownt32.h"
#include "wine/winuser16.h"
#include "user_private.h"
#include "wine/debug.h"
#include <Uxtheme.h>
#include "../krnl386/kernel16_private.h"
WINE_DEFAULT_DEBUG_CHANNEL(dialog);
BOOL is_reactos();
#include <pshpack1.h>
typedef struct
{
BYTE pop_eax; /* 58 */
BYTE push_imm; /* 68 */
LPVOID this_;
BYTE push_eax; /* 50 */
BYTE jmp_rel; /* E9 */
UINT_PTR DlgProc;
BOOL used;
HWND hDlg;
LPVOID param;
} DLGPROCTHUNK;
#include <poppack.h>
void free_proc_thunk(DLGPROCTHUNK *thunk);
BYTE get_aflags(HMODULE16 hModule);
/* Dialog control information */
typedef struct
{
DWORD style;
INT16 x;
INT16 y;
INT16 cx;
INT16 cy;
UINT id;
LPCSTR className;
LPCSTR windowName;
LPCVOID data;
} DLG_CONTROL_INFO;
/* Dialog template */
typedef struct
{
DWORD style;
UINT16 nbItems;
INT16 x;
INT16 y;
INT16 cx;
INT16 cy;
LPCSTR menuName;
LPCSTR className;
LPCSTR caption;
INT16 pointSize;
INT16 weight;
LPCSTR faceName;
} DLG_TEMPLATE;
#include "pshpack2.h"
typedef struct
{
WORD dlgVer;
WORD signature;
DWORD helpID;
DWORD exStyle;
DWORD style;
WORD cdit;
short x;
short y;
short cx;
short cy;
} DLGTEMPLATEEX;
typedef struct
{
DWORD helpid;
DWORD exStyle;
DWORD style;
short x;
short y;
short cx;
short cy;
DWORD id;
} DLGITEMTEMPLATEEX;
#include "poppack.h"
#define IS_ANY_DBCS_CHARSET( CharSet ) \
( ((CharSet) == SHIFTJIS_CHARSET) ? TRUE : \
((CharSet) == HANGEUL_CHARSET) ? TRUE : \
((CharSet) == CHINESEBIG5_CHARSET) ? TRUE : \
((CharSet) == GB2312_CHARSET) ? TRUE : FALSE )
#define DIALOG_CLASS_ATOM MAKEINTATOM(32770)
/***********************************************************************
* DIALOG_GetControl16
*
* Return the class and text of the control pointed to by ptr,
* fill the header structure and return a pointer to the next control.
*/
static LPCSTR DIALOG_GetControl16( LPCSTR p, DLG_CONTROL_INFO *info )
{
static char buffer[10];
int int_id;
info->x = GET_WORD(p); p += sizeof(WORD);
info->y = GET_WORD(p); p += sizeof(WORD);
info->cx = GET_WORD(p); p += sizeof(WORD);
info->cy = GET_WORD(p); p += sizeof(WORD);
info->id = GET_WORD(p); p += sizeof(WORD);
info->style = GET_DWORD(p); p += sizeof(DWORD);
if (*p & 0x80)
{
switch((BYTE)*p)
{
case 0x80: strcpy( buffer, "BUTTON" );
// this is undocumented but makes BS_USERBUTTON work
// BS_ICON and BS_BITMAP work without it
if (((info->style & 0xf) == BS_USERBUTTON) && !(info->style & 0xc0))
info->style |= 0x10;
break;
case 0x81: strcpy( buffer, "EDIT" ); break;
case 0x82: strcpy( buffer, "STATIC" ); break;
case 0x83: strcpy( buffer, "LISTBOX" ); break;
case 0x84: strcpy( buffer, "SCROLLBAR" ); break;
case 0x85: strcpy( buffer, "COMBOBOX" ); break;
default: buffer[0] = '\0'; break;
}
info->className = buffer;
p++;
}
else
{
info->className = p;
p += strlen(p) + 1;
}
int_id = ((BYTE)*p == 0xff);
if (int_id)
{
/* Integer id, not documented (?). Only works for SS_ICON controls */
info->windowName = MAKEINTRESOURCEA(GET_WORD(p+1));
p += 3;
}
else
{
info->windowName = p;
p += strlen(p) + 1;
}
if (*p) info->data = p + 1;
else info->data = NULL;
p += *p + 1;
TRACE(" %s %s %d, %d, %d, %d, %d, %08x, %p\n",
debugstr_a(info->className), debugstr_a(info->windowName),
info->id, info->x, info->y, info->cx, info->cy,
info->style, info->data );
return p;
}
/***********************************************************************
* DIALOG_ParseTemplate16
*
* Fill a DLG_TEMPLATE structure from the dialog template, and return
* a pointer to the first control.
*/
static LPCSTR DIALOG_ParseTemplate16( LPCSTR p, DLG_TEMPLATE * result )
{
result->style = GET_DWORD(p); p += sizeof(DWORD);
result->nbItems = (unsigned char) *p++;
result->x = GET_WORD(p); p += sizeof(WORD);
result->y = GET_WORD(p); p += sizeof(WORD);
result->cx = GET_WORD(p); p += sizeof(WORD);
result->cy = GET_WORD(p); p += sizeof(WORD);
TRACE("DIALOG %d, %d, %d, %d\n", result->x, result->y, result->cx, result->cy );
TRACE(" STYLE %08x\n", result->style );
/* Get the menu name */
switch( (BYTE)*p )
{
case 0:
result->menuName = 0;
p++;
break;
case 0xff:
result->menuName = MAKEINTRESOURCEA(GET_WORD( p + 1 ));
p += 3;
TRACE(" MENU %04x\n", LOWORD(result->menuName) );
break;
default:
result->menuName = p;
TRACE(" MENU '%s'\n", p );
p += strlen(p) + 1;
break;
}
/* Get the class name */
if (*p)
{
result->className = p;
TRACE(" CLASS '%s'\n", result->className );
}
else result->className = (LPCSTR)DIALOG_CLASS_ATOM;
p += strlen(p) + 1;
/* Get the window caption */
result->caption = p;
p += strlen(p) + 1;
TRACE(" CAPTION '%s'\n", result->caption );
/* Get the font name */
result->pointSize = 0;
result->faceName = NULL;
result->weight = 0;
if (result->style & DS_SETFONT)
{
CHARSETINFO info;
if (!TranslateCharsetInfo((DWORD *)(GetACP()), &info, TCI_SRCCODEPAGE))
info.ciCharset = ANSI_CHARSET;
result->pointSize = GET_WORD(p);
p += sizeof(WORD);
result->faceName = p;
p += strlen(p) + 1;
result->weight = IS_ANY_DBCS_CHARSET(info.ciCharset) ? FW_NORMAL : FW_BOLD;
TRACE(" FONT %d,'%s'\n", result->pointSize, result->faceName );
}
else if (IsOldWindowsTask(GetCurrentTask()) && !(get_aflags(GetExePtr(GetCurrentTask())) & NE_AFLAGS_WIN2_PROTMODE))
{
result->style |= DS_SETFONT;
result->pointSize = 10;
result->faceName = "FIXEDSYS";
result->weight = FW_NORMAL;
}
return p;
}
LRESULT get_message_callback(HWND16 hwnd, UINT16 msg, WPARAM16 wp, LPARAM lp,
LRESULT *result, void *arg);
LRESULT CALLBACK DlgProcCall16(HWND hDlg, UINT Msg, WPARAM wParam, LPARAM lParam)
{
HWND16 hWnd16 = HWND_16(hDlg);
WNDPROC16 wndproc16 = GetWndProc16(hWnd16);
switch (Msg)
{
case WM_INITDIALOG:
{
CREATESTRUCTA* cs = (CREATESTRUCTA*)lParam;
LPARAM *params = cs->lpCreateParams;
HMENU hMenu;
if (cs->hMenu)
{
BOOL ret = SetMenu(hDlg, HMENU_32(cs->hMenu));
}
ATOM classatom = GetClassLongA(hDlg, GCW_ATOM);//WNDPROC16
HWND16 hWnd16 = HWND_16(hDlg);
if (classatom)
{
if (params[1])
{
SetDlgProc16(hWnd16, params[1]);
}
else
{
SetDlgProc16(hWnd16, WNDCLASS16Info[classatom].wndproc);
}
}
cs->lpCreateParams = params[0];
free(cs);
}
break;
}
if (wndproc16)
{
MSG msg;
msg.hwnd = hDlg;
msg.message = Msg;
msg.wParam = wParam;
msg.lParam = lParam;
MSG16 msg16;
LRESULT unused;
WINPROC_CallProc32ATo16(get_message_callback, msg.hwnd, msg.message, msg.wParam, msg.lParam,
&unused, &msg16);
switch (msg.message)
{
default:
case WM_PAINT:
case WM_COMMAND:
return DispatchMessage16(&msg16),1;
}
}
return 0;//DefWindowProcA(hDlg, Msg, wParam, lParam);
}
LRESULT call_window_proc16(HWND16 hwnd, UINT16 msg, WPARAM16 wParam, LPARAM lParam,
LRESULT *result, void *arg);
LRESULT call_dialog_proc16(HWND16 hwnd, UINT16 msg, WPARAM16 wParam, LPARAM lParam,
LRESULT *result, void *arg)
{
SetWindowLong16(hwnd, DWL_MSGRESULT, 0xdeadbeef);
call_window_proc16(hwnd, msg, wParam, lParam, result, arg);
*result &= 0xffff;
LRESULT r = *result;/* result: 16-bit */
if (GetWindowLong16(hwnd, DWL_MSGRESULT) == 0xdeadbeef)
{
return r;
}
else
{
*result = GetWindowLong16(hwnd, DWL_MSGRESULT);
}
return r;
}
INT_PTR CALLBACK DlgProc(HWND hDlg, UINT Msg, WPARAM wParam, LPARAM lParam);
INT_PTR CALLBACK DlgProc_Thunk(DLGPROCTHUNK *thunk_data, HWND hDlg, UINT Msg, WPARAM wParam, LPARAM lParam)
{
if (!thunk_data->hDlg)
{
thunk_data->hDlg = hDlg;
dialog_data* cs = (dialog_data*)thunk_data->param;
if (cs->hMenu16)
{
BOOL ret = SetMenu(hDlg, HMENU_32(cs->hMenu16));
}
HWND16 hWnd16 = HWND_16(hDlg);
SetDlgProc16(hWnd16, cs->dlgProc);
SetWindowLongPtrA(hDlg, DWLP_DLGPROC, DlgProc);
HeapFree(GetProcessHeap(), 0, cs);
free_proc_thunk(thunk_data);
}
return DlgProc(hDlg, Msg, wParam, lParam);
}
INT_PTR CALLBACK DlgProc(HWND hDlg, UINT Msg, WPARAM wParam, LPARAM lParam)
{
HWND16 hWnd16 = HWND_16(hDlg);
WNDPROC16 wndproc16 = GetDlgProc16(hWnd16);
LRESULT ret = 0;
if (wndproc16)
{
MSG msg;
msg.hwnd = hDlg;
msg.message = Msg;
msg.wParam = wParam;
msg.lParam = lParam;
MSG16 msg16;
switch (msg.message)
{
default:
{
INT_PTR result = WINPROC_CallProc32ATo16(call_dialog_proc16, msg.hwnd, msg.message, msg.wParam, msg.lParam,
&ret, wndproc16);
if (GetWindowLong16(HWND_16(msg.hwnd), DWL_MSGRESULT) != 0xdeadbeef)
SetWindowLongA(hDlg, DWL_MSGRESULT, ret);
else
return ret;
return result;
}
}
}
return ret;
}
/* internal API for COMMDLG hooks */
LRESULT WINAPI DIALOG_CallDialogProc(HWND hwnd, UINT msg, WPARAM wParam, LPARAM lParam, WNDPROC16 proc)
{
LRESULT ret;
BOOL16 result = WINPROC_CallProc32ATo16(call_dialog_proc16, hwnd, msg, wParam, lParam,
&ret, proc);
if (GetWindowLong16(HWND_16(hwnd), DWL_MSGRESULT) != 0xdeadbeef)
SetWindowLongA(hwnd, DWL_MSGRESULT, ret);
return result;
}
void paddingDWORD(DWORD **d)
{
*d = (BYTE*)(((DWORD)*d + 3) & ~((DWORD)3));
}
void copy_widestr(LPCSTR name, LPWSTR *templatew, DLGTEMPLATEEX **template32)
{
int len = 0;
int slen;
if (slen = strlen(name))
{
if (slen > 256)
{
UINT_PTR off = (char *)*templatew - (char *)*template32;
*template32 = HeapReAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY, *template32, HeapSize(GetProcessHeap(), 0, *template32) + slen * 2);
*templatew = (char *)*template32 + off;
}
len = MultiByteToWideChar(CP_ACP, NULL, name, -1, *templatew, strlen(name) * 4)
* 2;
}
if (len)
{
*templatew = (WORD*)((BYTE*)*templatew + len);
}
else
{
**templatew = 0;
(*templatew)++;
}
}
/***********************************************************************
* DIALOG_CreateControls16
*
* Create the control windows for a dialog.
*/
static BOOL DIALOG_CreateControls16Ex(HWND hwnd, LPCSTR template,
const DLG_TEMPLATE *dlgTemplate, HINSTANCE16 hInst, DLGITEMTEMPLATEEX *dlgItemTemplate32, SEGPTR base16, SIZE_T base32, DLGTEMPLATEEX **template32)
{
DLG_CONTROL_INFO info;
HWND hwndCtrl, hwndDefButton = 0;
INT items = dlgTemplate->nbItems;
dlgItemTemplate32 = (BYTE*) (((DWORD)dlgItemTemplate32 + 3) & ~((DWORD)3));
WORD *dlgItemTemplatew;
TRACE(" BEGIN\n");
while (items--)
{
paddingDWORD(&dlgItemTemplate32);
template = DIALOG_GetControl16(template, &info);
dlgItemTemplate32->helpid = 0;
dlgItemTemplate32->style = info.style | WS_CHILD;
dlgItemTemplate32->exStyle = 0;// WS_EX_NOPARENTNOTIFY;
dlgItemTemplate32->x = info.x;
dlgItemTemplate32->y = info.y;
dlgItemTemplate32->cx = info.cx;
dlgItemTemplate32->cy = info.cy;
dlgItemTemplate32->id = info.id;
dlgItemTemplatew = (WORD*)(dlgItemTemplate32 + 1);
info.className = win32classname(hInst, info.className);
copy_widestr(info.className, &dlgItemTemplatew, template32);
if (!HIWORD(info.windowName))
{
char buffer[512];
if (((dlgItemTemplate32->style & 0xF) == SS_ICON || (dlgItemTemplate32->style & 0xF) == SS_BITMAP) && stricmp(info.className, "STATIC") == 0)
{
sprintf(buffer, "#%d", (int)info.windowName);
copy_widestr(buffer, &dlgItemTemplatew, template32);
}
else
{
if (LoadString16(hInst, LOWORD(info.windowName), buffer, sizeof(buffer)))
info.windowName = buffer;
else
info.windowName = "dialog error: invalid window name";
copy_widestr(info.windowName, &dlgItemTemplatew, template32);
}
}
else
{
copy_widestr(info.windowName, &dlgItemTemplatew, template32);
}
if (info.data)
{
*dlgItemTemplatew++ = sizeof(info.data);
/* reference to 16-bit dialog template */
*((LPCVOID*)dlgItemTemplatew) = MAKESEGPTR(SELECTOROF(base16), OFFSETOF(base16) + (WORD)((SIZE_T)info.data - base32));
dlgItemTemplatew += 2;
}
else
{
*dlgItemTemplatew++ = 0;
}
dlgItemTemplate32 = dlgItemTemplatew;
}
TRACE(" END\n");
return TRUE;
}
static BOOL DIALOG_DumpControls32(HWND hwnd, LPCSTR template,
const DLG_TEMPLATE *dlgTemplate, HINSTANCE16 hInst, DLGITEMTEMPLATEEX *dlgItemTemplate32)
{
DLG_CONTROL_INFO info;
HWND hwndCtrl, hwndDefButton = 0;
INT items = dlgTemplate->nbItems;
dlgItemTemplate32 = (BYTE*)(((DWORD)dlgItemTemplate32 + 3) & ~((DWORD)3));
WORD *dlgItemTemplatew;
TRACE(" BEGIN\n");
while (items--)
{
char buf[256];
template = DIALOG_GetControl16(template, &info);
GetDlgItemTextA(hwnd, info.id, buf, 256);
char pszError[512];
//最後のエラー番号取得
DWORD dwError = GetLastError();
//文字列変換
FormatMessageA(FORMAT_MESSAGE_FROM_SYSTEM, NULL, dwError, NULL, pszError, sizeof(pszError), NULL);
DPRINTF("id 0x%x=%s, err=%s\n", info.id, buf, pszError);
}
TRACE(" END\n");
return TRUE;
}
#include <stdio.h>
/* internal API for COMMDLG hooks */
DLGTEMPLATEEX *WINAPI dialog_template16_to_template32(HINSTANCE16 hInst, SEGPTR dlgTemplate16, DWORD *size, dialog_data *paramd)
{
HINSTANCE hInst32 = HINSTANCE_32(hInst);
DLGTEMPLATEEX *template32;
DLG_TEMPLATE template;
DWORD units = GetDialogBaseUnits();
HMENU16 hMenu = 0;
HFONT hUserFont = 0;
UINT xBaseUnit = LOWORD(units);
UINT yBaseUnit = HIWORD(units);
LPCVOID dlgTemplate = MapSL(dlgTemplate16);
LPCVOID base32 = dlgTemplate;
/* Parse dialog template */
dlgTemplate = DIALOG_ParseTemplate16(dlgTemplate, &template);
/* Load menu */
if (template.menuName) hMenu = LoadMenu16(hInst, template.menuName);
//FIXME:memory
template32 = HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY, 1024 + template.nbItems * 512);
template32->dlgVer = 1;
template32->signature = 0xffff;
template32->style = template.style;
template32->exStyle = 0;
template32->helpID = 0;
template32->cdit = template.nbItems;
template32->x = template.x;
template32->y = template.y;
template32->cx = template.cx;
template32->cy = template.cy;
WORD *templatew = (WORD*)(template32 + 1);
//Menu
*templatew++ = 0;
int len;
if (template.className == DIALOG_CLASS_ATOM)
{
*templatew++ = 0;
}
else
{
//WNDclass
template.className = win32classname(hInst, template.className);
len = MultiByteToWideChar(CP_ACP, NULL, template.className, -1, (LPWSTR)templatew, (1 + strlen(template.className)) * 4)
* 2;
if (len)
{
templatew = (WORD*)((BYTE*)templatew + len);
}
else
{
*templatew++ = 0;
}
}
//dialog title
len = MultiByteToWideChar(CP_ACP, NULL, template.caption, -1, (LPWSTR)templatew, (1 + strlen(template.caption)) * 4)
* 2;
if (len)
{
templatew = (WORD*)((BYTE*)templatew + len);
}
else
{
*templatew++ = 0;
}
if (template.style & DS_SETFONT)
{
*templatew++ = template.pointSize;
*templatew++ = template.weight;
*templatew++ = (DEFAULT_CHARSET << 8) | FALSE;
len = MultiByteToWideChar(CP_ACP, NULL, template.faceName, -1, (LPWSTR)templatew, (1 + strlen(template.faceName)) * 4)
* 2;
if (len)
{
templatew = (WORD*)((BYTE*)templatew + len);
}
else
{
*templatew++ = 0;
}
/* We convert the size to pixels and then make it -ve. This works
* for both +ve and -ve template.pointSize */
HDC dc;
int pixels;
dc = GetDC(0);
pixels = MulDiv(template.pointSize, GetDeviceCaps(dc , LOGPIXELSY), 72);
hUserFont = CreateFontA( -pixels, 0, 0, 0, FW_DONTCARE,
FALSE, FALSE, FALSE, DEFAULT_CHARSET, 0, 0,
PROOF_QUALITY, FF_DONTCARE, template.faceName );
if (hUserFont)
{
SIZE charSize;
HFONT hOldFont = SelectObject( dc, hUserFont );
charSize.cx = GdiGetCharDimensions( dc, NULL, &charSize.cy );
if (charSize.cx)
{
xBaseUnit = charSize.cx;
yBaseUnit = charSize.cy;
}
SelectObject( dc, hOldFont );
}
ReleaseDC(0, dc);
DeleteObject( hUserFont );
TRACE("units = %d,%d\n", xBaseUnit, yBaseUnit );
}
DIALOG_CreateControls16Ex(NULL, dlgTemplate, &template, hInst, templatew, dlgTemplate16, (SIZE_T)base32, &template32);
WNDCLASSEXA wc2 = { 0 };
GetClassInfoExA(hInst32, template.className, &wc2);
if (!wc2.lpszClassName)
GetClassInfoExA(GetModuleHandleW(NULL), template.className, &wc2);
if (!paramd)
{
if (hMenu || wc2.lpszMenuName)
{
FIXME("dialog menu is not supported.\n");
}
}
else
{
paramd->hMenu16 = hMenu;
if (!hMenu)
paramd->hMenu16 = LoadMenu16(hInst, wc2.lpszMenuName);
}
/* Add menu height */
/* Precision...? */
if (hMenu)
{
template32->cy += MulDiv(GetSystemMetrics(SM_CYMENU), 8, yBaseUnit);
}
return template32;
}
static DLGPROCTHUNK *thunk_array;
static int MAX_THUNK;
static void init_proc_thunk()
{
if (thunk_array)
return;
MAX_THUNK = 4096 / sizeof(DLGPROCTHUNK);
thunk_array = VirtualAlloc(NULL, MAX_THUNK * sizeof(DLGPROCTHUNK), MEM_COMMIT, PAGE_EXECUTE_READWRITE);
}
dialog_data *get_dialog_data(HWND hWnd)
{
DLGPROC dlgproc = GetWindowLongPtrA(hWnd, DWLP_DLGPROC);
if (thunk_array <= dlgproc && thunk_array + MAX_THUNK > dlgproc)
{
return (dialog_data*)(((DLGPROCTHUNK *)dlgproc)->param);
}
return 0;
}
DLGPROCTHUNK *init_thunk_data(LPVOID param, int i, LPVOID func)
{
thunk_array[i].pop_eax = 0x58;
thunk_array[i].push_imm = 0x68;
thunk_array[i].this_ = thunk_array + i;
thunk_array[i].push_eax = 0x50;
thunk_array[i].jmp_rel = 0xE9;
thunk_array[i].DlgProc = (UINT_PTR)DlgProc_Thunk - (UINT_PTR)(&thunk_array[i].DlgProc + 1);
thunk_array[i].used = TRUE;
thunk_array[i].hDlg = 0;
thunk_array[i].param = param;
return thunk_array + i;
}
DLGPROC allocate_proc_thunk(LPVOID param, LPVOID func)
{
init_proc_thunk();
for (int i = 0; i < MAX_THUNK; i++)
{
if (!thunk_array[i].used)
{
return (DLGPROC)init_thunk_data(param, i, func);
}
}
for (int i = 0; i < MAX_THUNK; i++)
{
if (thunk_array[i].hDlg && !IsWindow(thunk_array[i].hDlg))
{
return (DLGPROC)init_thunk_data(param, i, func);
}
}
ERR("could not allocate dialog thunk!\n");
return DlgProc;
}
void free_proc_thunk(DLGPROCTHUNK *thunk)
{
thunk->used = FALSE;
}
/***********************************************************************
* DIALOG_CreateIndirect16
*
* Creates a dialog box window
*
* modal = TRUE if we are called from a modal dialog box.
* (it's more compatible to do it here, as under Windows the owner
* is never disabled if the dialog fails because of an invalid template)
*/
static HWND DIALOG_CreateIndirect16(HINSTANCE16 hInst, SEGPTR dlgTemplate16,
HWND owner, DLGPROC16 dlgProc, LPARAM param,
BOOL modal)
{
HWND result;
dialog_data *paramd = (dialog_data*)HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY, sizeof(dialog_data));
HINSTANCE hInst32 = HINSTANCE_32(hInst);
DWORD size;
DLGTEMPLATEEX *template32 = dialog_template16_to_template32(hInst32, dlgTemplate16, &size, paramd);
DWORD count;
DLGPROC proc = allocate_proc_thunk(paramd, DlgProc_Thunk);
paramd->dlgProc = dlgProc;
ReleaseThunkLock(&count);
if (modal)
{
SetEvent(kernel_get_thread_data()->idle_event);
result = (HWND)DialogBoxIndirectParamA(
UlongToHandle(HandleToUlong(hInst32) | (is_reactos() ? 0xfefe0000 : 0)),
template32,
owner,
proc, param);
}
else
{
result = CreateDialogIndirectParamA(
UlongToHandle(HandleToUlong(hInst32) | (is_reactos() ? 0xfefe0000 : 0)),
template32,
owner,
proc, param);
}
HeapFree(GetProcessHeap(), 0, template32);
RestoreThunkLock(count);
return result;
}
/***********************************************************************
* DialogBox (USER.87)
*/
INT16 WINAPI DialogBox16( HINSTANCE16 hInst, LPCSTR dlgTemplate,
HWND16 owner, DLGPROC16 dlgProc )
{
return DialogBoxParam16( hInst, dlgTemplate, owner, dlgProc, 0 );
}
/**************************************************************************
* EndDialog (USER.88)
*/
BOOL16 WINAPI EndDialog16( HWND16 hwnd, INT16 retval )
{
DWORD count;
BOOL result;
ReleaseThunkLock(&count);
result = EndDialog( WIN_Handle32(hwnd), retval );
RestoreThunkLock(count);
return (BOOL16)result;
}
/***********************************************************************
* CreateDialog (USER.89)
*/
HWND16 WINAPI CreateDialog16( HINSTANCE16 hInst, LPCSTR dlgTemplate,
HWND16 owner, DLGPROC16 dlgProc )
{
return CreateDialogParam16( hInst, dlgTemplate, owner, dlgProc, 0 );
}
/**************************************************************************
* GetDlgItem (USER.91)
*/
HWND16 WINAPI GetDlgItem16( HWND16 hwndDlg, INT16 id )
{
return HWND_16( GetDlgItem( WIN_Handle32(hwndDlg), (UINT16) id ));
}
/**************************************************************************
* SetDlgItemText (USER.92)
*/
void WINAPI SetDlgItemText16( HWND16 hwnd, INT16 id, SEGPTR lpString )
{
const char *txt = MapSL(lpString);
SetDlgItemTextA(HWND_32(hwnd), (UINT16)id, txt);
SendDlgItemMessage16( hwnd, id, WM_SETTEXT, 0, lpString );
}
/**************************************************************************
* GetDlgItemText (USER.93)
*/
INT16 WINAPI GetDlgItemText16( HWND16 hwnd, INT16 id, SEGPTR str, UINT16 len )
{
return GetDlgItemTextA(HWND_32(hwnd), (UINT16)id, MapSL(str), len);
return SendDlgItemMessage16( hwnd, id, WM_GETTEXT, len, str );
}
/**************************************************************************
* SetDlgItemInt (USER.94)
*/
void WINAPI SetDlgItemInt16( HWND16 hwnd, INT16 id, UINT16 value, BOOL16 fSigned )
{
SetDlgItemInt( WIN_Handle32(hwnd), (UINT)(UINT16)id,
(UINT)(fSigned ? (INT16) value : value), fSigned );
}
/**************************************************************************
* GetDlgItemInt (USER.95)
*/
UINT16 WINAPI GetDlgItemInt16( HWND16 hwnd, INT16 id, BOOL16 *translated, BOOL16 fSigned )
{
UINT result;
BOOL ok;
if (translated) *translated = FALSE;
result = GetDlgItemInt( WIN_Handle32(hwnd), (UINT)(UINT16)id, &ok, fSigned );
if (!ok) return 0;
if (fSigned)
{
if (((INT)result < -32767) || ((INT)result > 32767)) return 0;
}
else
{
if (result > 65535) return 0;
}
if (translated) *translated = TRUE;
return (UINT16)result;
}
/**************************************************************************
* CheckRadioButton (USER.96)
*/
BOOL16 WINAPI CheckRadioButton16( HWND16 hwndDlg, UINT16 firstID,
UINT16 lastID, UINT16 checkID )
{
return CheckRadioButton( WIN_Handle32(hwndDlg), firstID, lastID, checkID );
}
/**************************************************************************
* CheckDlgButton (USER.97)
*/
BOOL16 WINAPI CheckDlgButton16( HWND16 hwnd, INT16 id, UINT16 check )
{
SendDlgItemMessage16( hwnd, id, BM_SETCHECK16, check, 0 );
return TRUE;
}
/**************************************************************************
* IsDlgButtonChecked (USER.98)
*/
UINT16 WINAPI IsDlgButtonChecked16( HWND16 hwnd, UINT16 id )
{
return (UINT16)SendDlgItemMessage16( hwnd, id, BM_GETCHECK16, 0, 0 );
}
/**************************************************************************
* DlgDirSelect (USER.99)
*/
BOOL16 WINAPI DlgDirSelect16( HWND16 hwnd, LPSTR str, INT16 id )
{
return DlgDirSelectEx16( hwnd, str, 128, id );
}
/**************************************************************************
* DlgDirList (USER.100)
*/
INT16 WINAPI DlgDirList16( HWND16 hDlg, LPSTR spec, INT16 idLBox,
INT16 idStatic, UINT16 attrib )
{
/* according to Win16 docs, DDL_DRIVES should make DDL_EXCLUSIVE
* be set automatically (this is different in Win32, and
* DIALOG_DlgDirList sends Win32 messages to the control,
* so do it here) */
if (attrib == DDL_DRIVES) attrib |= DDL_EXCLUSIVE;
return DlgDirListA( WIN_Handle32(hDlg), spec, idLBox, idStatic, attrib );
}
/**************************************************************************
* SendDlgItemMessage (USER.101)
*/
LRESULT WINAPI SendDlgItemMessage16( HWND16 hwnd, INT16 id, UINT16 msg,
WPARAM16 wParam, LPARAM lParam )
{
HWND16 hwndCtrl = GetDlgItem16( hwnd, id );
if (hwndCtrl) return SendMessage16( hwndCtrl, msg, wParam, lParam );
else return 0;
}
/**************************************************************************
* MapDialogRect (USER.103)
*/
void WINAPI MapDialogRect16( HWND16 hwnd, LPRECT16 rect )
{
RECT rect32 = { rect->left, rect->top, rect->right, rect->bottom };
MapDialogRect( WIN_Handle32(hwnd), &rect32 );
rect->left = rect32.left;
rect->right = rect32.right;
rect->top = rect32.top;
rect->bottom = rect32.bottom;
}
/**************************************************************************
* DlgDirSelectComboBox (USER.194)
*/
BOOL16 WINAPI DlgDirSelectComboBox16( HWND16 hwnd, LPSTR str, INT16 id )
{
return DlgDirSelectComboBoxEx16( hwnd, str, 128, id );
}
/**************************************************************************
* DlgDirListComboBox (USER.195)
*/
INT16 WINAPI DlgDirListComboBox16( HWND16 hDlg, LPSTR spec, INT16 idCBox,
INT16 idStatic, UINT16 attrib )
{
return DlgDirListComboBoxA( WIN_Handle32(hDlg), spec, idCBox, idStatic, attrib );
}
/***********************************************************************
* DialogBoxIndirect (USER.218)
*/
INT16 WINAPI DialogBoxIndirect16( HINSTANCE16 hInst, HANDLE16 dlgTemplate,
HWND16 owner, DLGPROC16 dlgProc )
{
return DialogBoxIndirectParam16( hInst, dlgTemplate, owner, dlgProc, 0 );
}
/***********************************************************************
* CreateDialogIndirect (USER.219)
*/
HWND16 WINAPI CreateDialogIndirect16( HINSTANCE16 hInst, SEGPTR dlgTemplate,
HWND16 owner, DLGPROC16 dlgProc )
{
return CreateDialogIndirectParam16( hInst, dlgTemplate, owner, dlgProc, 0);
}
/**************************************************************************
* GetNextDlgGroupItem (USER.227)
*/
HWND16 WINAPI GetNextDlgGroupItem16( HWND16 hwndDlg, HWND16 hwndCtrl,
BOOL16 fPrevious )
{
return HWND_16( GetNextDlgGroupItem( WIN_Handle32(hwndDlg), WIN_Handle32(hwndCtrl), fPrevious ));
}
/**************************************************************************
* GetNextDlgTabItem (USER.228)
*/
HWND16 WINAPI GetNextDlgTabItem16( HWND16 hwndDlg, HWND16 hwndCtrl,
BOOL16 fPrevious )
{
return HWND_16( GetNextDlgTabItem( WIN_Handle32(hwndDlg), WIN_Handle32(hwndCtrl), fPrevious ));
}
/***********************************************************************