[User32]
[reactos.git] / reactos / win32ss / user / user32 / windows / dialog.c
1 /*
2 * ReactOS kernel
3 * Copyright (C) 1998, 1999, 2000, 2001 ReactOS Team
4 *
5 * This program is free software; you can redistribute it and/or modify
6 * it under the terms of the GNU General Public License as published by
7 * the Free Software Foundation; either version 2 of the License, or
8 * (at your option) any later version.
9 *
10 * This program is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 * GNU General Public License for more details.
14 *
15 * You should have received a copy of the GNU General Public License
16 * along with this program; if not, write to the Free Software
17 * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
18 */
19 /*
20 * PROJECT: ReactOS user32.dll
21 * FILE: win32ss/user/user32/windows/dialog.c
22 * PURPOSE: Input
23 * PROGRAMMER: Casper S. Hornstrup (chorns@users.sourceforge.net)
24 * Thomas Weidenmueller (w3seek@users.sourceforge.net)
25 * Steven Edwards (Steven_Ed4153@yahoo.com)
26 * UPDATE HISTORY:
27 * 07-26-2003 Code ported from wine
28 * 09-05-2001 CSH Created
29 */
30
31 /* INCLUDES ******************************************************************/
32
33 #include <user32.h>
34
35 #include <wine/debug.h>
36 WINE_DEFAULT_DEBUG_CHANNEL(user32);
37
38 /* MACROS/DEFINITIONS ********************************************************/
39
40 #define DF_END 0x0001
41 #define DF_DIALOGACTIVE 0x4000 // ReactOS
42 #define DWLP_ROS_DIALOGINFO (DWLP_USER+sizeof(ULONG_PTR))
43 #define GETDLGINFO(hwnd) DIALOG_get_info(hwnd, FALSE)
44 #define SETDLGINFO(hwnd, info) SetWindowLongPtrW((hwnd), DWLP_ROS_DIALOGINFO, (LONG_PTR)(info))
45 #define GET_WORD(ptr) (*(WORD *)(ptr))
46 #define GET_DWORD(ptr) (*(DWORD *)(ptr))
47 #define DLG_ISANSI 2
48
49 /* INTERNAL STRUCTS **********************************************************/
50
51 /* Dialog info structure */
52 typedef struct
53 {
54 HWND hwndFocus; /* Current control with focus */
55 HFONT hUserFont; /* Dialog font */
56 HMENU hMenu; /* Dialog menu */
57 UINT xBaseUnit; /* Dialog units (depends on the font) */
58 UINT yBaseUnit;
59 INT idResult; /* EndDialog() result / default pushbutton ID */
60 UINT flags; /* EndDialog() called for this dialog */
61 } DIALOGINFO;
62
63 /* Dialog control information */
64 typedef struct
65 {
66 DWORD style;
67 DWORD exStyle;
68 DWORD helpId;
69 short x;
70 short y;
71 short cx;
72 short cy;
73 UINT id;
74 LPCWSTR className;
75 LPCWSTR windowName;
76 BOOL windowNameFree; // ReactOS
77 LPCVOID data;
78 } DLG_CONTROL_INFO;
79
80 /* Dialog template */
81 typedef struct
82 {
83 DWORD style;
84 DWORD exStyle;
85 DWORD helpId;
86 WORD nbItems;
87 short x;
88 short y;
89 short cx;
90 short cy;
91 LPCWSTR menuName;
92 LPCWSTR className;
93 LPCWSTR caption;
94 WORD pointSize;
95 WORD weight;
96 BOOL italic;
97 LPCWSTR faceName;
98 BOOL dialogEx;
99 } DLG_TEMPLATE;
100
101 /* CheckRadioButton structure */
102 typedef struct
103 {
104 UINT firstID;
105 UINT lastID;
106 UINT checkID;
107 } RADIOGROUP;
108
109
110 /*********************************************************************
111 * dialog class descriptor
112 */
113 const struct builtin_class_descr DIALOG_builtin_class =
114 {
115 WC_DIALOG, /* name */
116 CS_SAVEBITS | CS_DBLCLKS, /* style */
117 DefDlgProcA, /* procA */
118 DefDlgProcW, /* procW */
119 DLGWINDOWEXTRA, /* extra */
120 (LPCWSTR) IDC_ARROW, /* cursor */
121 0 /* brush */
122 };
123
124
125 /* INTERNAL FUNCTIONS ********************************************************/
126
127 /***********************************************************************
128 * DIALOG_get_info
129 *
130 * Get the DIALOGINFO structure of a window, allocating it if needed
131 * and 'create' is TRUE.
132 *
133 * ReactOS
134 */
135 DIALOGINFO *DIALOG_get_info( HWND hWnd, BOOL create )
136 {
137 PWND pWindow;
138 DIALOGINFO* dlgInfo;
139
140 pWindow = ValidateHwnd( hWnd );
141 if (!pWindow)
142 {
143 return NULL;
144 }
145
146 dlgInfo = (DIALOGINFO *)GetWindowLongPtrW( hWnd, DWLP_ROS_DIALOGINFO );
147
148 if (!dlgInfo && create)
149 {
150 if (pWindow && pWindow->cbwndExtra >= DLGWINDOWEXTRA)
151 {
152 if (!(dlgInfo = HeapAlloc( GetProcessHeap(), HEAP_ZERO_MEMORY, sizeof(*dlgInfo) )))
153 return NULL;
154
155 dlgInfo->idResult = IDOK;
156 SETDLGINFO( hWnd, dlgInfo );
157 }
158 else
159 {
160 return NULL;
161 }
162 }
163
164 if (dlgInfo)
165 {
166 if (!(pWindow->state & WNDS_DIALOGWINDOW))
167 {
168 NtUserxSetDialogPointer( hWnd, dlgInfo );
169 }
170 }
171 return dlgInfo;
172 }
173
174 /***********************************************************************
175 * DIALOG_GetControl32
176 *
177 * Return the class and text of the control pointed to by ptr,
178 * fill the header structure and return a pointer to the next control.
179 */
180 static const WORD *DIALOG_GetControl32( const WORD *p, DLG_CONTROL_INFO *info,
181 BOOL dialogEx )
182 {
183 if (dialogEx)
184 {
185 info->helpId = GET_DWORD(p); p += 2;
186 info->exStyle = GET_DWORD(p); p += 2;
187 info->style = GET_DWORD(p); p += 2;
188 }
189 else
190 {
191 info->helpId = 0;
192 info->style = GET_DWORD(p); p += 2;
193 info->exStyle = GET_DWORD(p); p += 2;
194 }
195 info->x = GET_WORD(p); p++;
196 info->y = GET_WORD(p); p++;
197 info->cx = GET_WORD(p); p++;
198 info->cy = GET_WORD(p); p++;
199
200 if (dialogEx)
201 {
202 /* id is a DWORD for DIALOGEX */
203 info->id = GET_DWORD(p);
204 p += 2;
205 }
206 else
207 {
208 info->id = GET_WORD(p);
209 p++;
210 }
211
212 if (GET_WORD(p) == 0xffff)
213 {
214 static const WCHAR class_names[6][10] =
215 {
216 { 'B','u','t','t','o','n', }, /* 0x80 */
217 { 'E','d','i','t', }, /* 0x81 */
218 { 'S','t','a','t','i','c', }, /* 0x82 */
219 { 'L','i','s','t','B','o','x', }, /* 0x83 */
220 { 'S','c','r','o','l','l','B','a','r', }, /* 0x84 */
221 { 'C','o','m','b','o','B','o','x', } /* 0x85 */
222 };
223 WORD id = GET_WORD(p+1);
224 /* Windows treats dialog control class ids 0-5 same way as 0x80-0x85 */
225 if ((id >= 0x80) && (id <= 0x85)) id -= 0x80;
226 if (id <= 5)
227 {
228 info->className = class_names[id];
229 }
230 else
231 {
232 info->className = NULL;
233 /* FIXME: load other classes here? */
234 ERR("Unknown built-in class id %04x\n", id );
235 }
236 p += 2;
237 }
238 else
239 {
240 info->className = (LPCWSTR)p;
241 p += strlenW( info->className ) + 1;
242 }
243
244 if (GET_WORD(p) == 0xffff) /* Is it an integer id? */
245 {
246 //// ReactOS Rev 6478
247 info->windowName = HeapAlloc( GetProcessHeap(), 0, sizeof(L"#65535") );
248 if (info->windowName != NULL)
249 {
250 wsprintf((LPWSTR)info->windowName, L"#%u", GET_WORD(p + 1));
251 info->windowNameFree = TRUE;
252 }
253 else
254 {
255 info->windowNameFree = FALSE;
256 }
257 p += 2;
258 }
259 else
260 {
261 info->windowName = (LPCWSTR)p;
262 info->windowNameFree = FALSE;
263 p += strlenW( info->windowName ) + 1;
264 }
265
266 TRACE(" %s %s %ld, %d, %d, %d, %d, %08x, %08x, %08x\n",
267 debugstr_w( info->className ), debugstr_w( info->windowName ),
268 info->id, info->x, info->y, info->cx, info->cy,
269 info->style, info->exStyle, info->helpId );
270
271 if (GET_WORD(p))
272 {
273 info->data = p;
274 p += GET_WORD(p) / sizeof(WORD);
275 }
276 else info->data = NULL;
277 p++;
278
279 /* Next control is on dword boundary */
280 return (const WORD *)(((UINT_PTR)p + 3) & ~3);
281 }
282
283
284 /***********************************************************************
285 * DIALOG_CreateControls32
286 *
287 * Create the control windows for a dialog.
288 */
289 static BOOL DIALOG_CreateControls32( HWND hwnd, LPCSTR template, const DLG_TEMPLATE *dlgTemplate,
290 HINSTANCE hInst, BOOL unicode )
291 {
292 DIALOGINFO * dlgInfo;
293 DLG_CONTROL_INFO info;
294 HWND hwndCtrl, hwndDefButton = 0;
295 INT items = dlgTemplate->nbItems;
296
297 if (!(dlgInfo = GETDLGINFO(hwnd))) return FALSE;
298
299 TRACE(" BEGIN\n" );
300 while (items--)
301 {
302 template = (LPCSTR)DIALOG_GetControl32( (const WORD *)template, &info,
303 dlgTemplate->dialogEx );
304 info.style &= ~WS_POPUP;
305 info.style |= WS_CHILD;
306
307 if (info.style & WS_BORDER)
308 {
309 info.style &= ~WS_BORDER;
310 info.exStyle |= WS_EX_CLIENTEDGE;
311 }
312
313 if (unicode)
314 {
315 hwndCtrl = CreateWindowExW( info.exStyle | WS_EX_NOPARENTNOTIFY,
316 info.className, info.windowName,
317 info.style | WS_CHILD,
318 MulDiv(info.x, dlgInfo->xBaseUnit, 4),
319 MulDiv(info.y, dlgInfo->yBaseUnit, 8),
320 MulDiv(info.cx, dlgInfo->xBaseUnit, 4),
321 MulDiv(info.cy, dlgInfo->yBaseUnit, 8),
322 hwnd, (HMENU)(ULONG_PTR)info.id,
323 hInst, (LPVOID)info.data );
324 }
325 else
326 {
327 LPSTR class = (LPSTR)info.className;
328 LPSTR caption = (LPSTR)info.windowName;
329
330 if (!IS_INTRESOURCE(class))
331 {
332 DWORD len = WideCharToMultiByte( CP_ACP, 0, info.className, -1, NULL, 0, NULL, NULL );
333 class = HeapAlloc( GetProcessHeap(), 0, len );
334 if (class != NULL)
335 WideCharToMultiByte( CP_ACP, 0, info.className, -1, class, len, NULL, NULL );
336 }
337 if (!IS_INTRESOURCE(caption))
338 {
339 DWORD len = WideCharToMultiByte( CP_ACP, 0, info.windowName, -1, NULL, 0, NULL, NULL );
340 caption = HeapAlloc( GetProcessHeap(), 0, len );
341 if (caption != NULL)
342 WideCharToMultiByte( CP_ACP, 0, info.windowName, -1, caption, len, NULL, NULL );
343 }
344
345 if (class != NULL && caption != NULL)
346 {
347 hwndCtrl = CreateWindowExA( info.exStyle | WS_EX_NOPARENTNOTIFY,
348 class, caption, info.style | WS_CHILD,
349 MulDiv(info.x, dlgInfo->xBaseUnit, 4),
350 MulDiv(info.y, dlgInfo->yBaseUnit, 8),
351 MulDiv(info.cx, dlgInfo->xBaseUnit, 4),
352 MulDiv(info.cy, dlgInfo->yBaseUnit, 8),
353 hwnd, (HMENU)(ULONG_PTR)info.id,
354 hInst, (LPVOID)info.data );
355 }
356 else
357 hwndCtrl = NULL;
358 if (!IS_INTRESOURCE(class)) HeapFree( GetProcessHeap(), 0, class );
359 if (!IS_INTRESOURCE(caption)) HeapFree( GetProcessHeap(), 0, caption );
360 }
361
362 if (info.windowNameFree)
363 {
364 HeapFree( GetProcessHeap(), 0, (LPVOID)info.windowName );
365 }
366
367 if (!hwndCtrl)
368 {
369 WARN("control %s %s creation failed\n", debugstr_w(info.className),
370 debugstr_w(info.windowName));
371 if (dlgTemplate->style & DS_NOFAILCREATE) continue;
372 return FALSE;
373 }
374
375 /* Send initialisation messages to the control */
376 if (dlgInfo->hUserFont) SendMessageW( hwndCtrl, WM_SETFONT,
377 (WPARAM)dlgInfo->hUserFont, 0 );
378 if (SendMessageW(hwndCtrl, WM_GETDLGCODE, 0, 0) & DLGC_DEFPUSHBUTTON)
379 {
380 /* If there's already a default push-button, set it back */
381 /* to normal and use this one instead. */
382 if (hwndDefButton)
383 SendMessageW( hwndDefButton, BM_SETSTYLE, BS_PUSHBUTTON, FALSE );
384 hwndDefButton = hwndCtrl;
385 dlgInfo->idResult = GetWindowLongPtrA( hwndCtrl, GWLP_ID );
386 }
387 }
388 TRACE(" END\n" );
389 return TRUE;
390 }
391
392
393 /***********************************************************************
394 * DIALOG_IsAccelerator
395 */
396 static BOOL DIALOG_IsAccelerator( HWND hwnd, HWND hwndDlg, WPARAM wParam )
397 {
398 HWND hwndControl = hwnd;
399 HWND hwndNext;
400 INT dlgCode;
401 WCHAR buffer[128];
402
403 do
404 {
405 DWORD style = GetWindowLongPtrW( hwndControl, GWL_STYLE );
406 if ((style & (WS_VISIBLE | WS_DISABLED)) == WS_VISIBLE)
407 {
408 dlgCode = SendMessageW( hwndControl, WM_GETDLGCODE, 0, 0 );
409 if ( (dlgCode & (DLGC_BUTTON | DLGC_STATIC)) &&
410 GetWindowTextW( hwndControl, buffer, sizeof(buffer)/sizeof(WCHAR) ))
411 {
412 /* find the accelerator key */
413 LPWSTR p = buffer - 2;
414
415 do
416 {
417 p = strchrW( p + 2, '&' );
418 }
419 while (p != NULL && p[1] == '&');
420
421 /* and check if it's the one we're looking for */
422 if (p != NULL && toupperW( p[1] ) == toupperW( wParam ) )
423 {
424 if ((dlgCode & DLGC_STATIC) || (style & 0x0f) == BS_GROUPBOX )
425 {
426 /* set focus to the control */
427 SendMessageW( hwndDlg, WM_NEXTDLGCTL, (WPARAM)hwndControl, 1);
428 /* and bump it on to next */
429 SendMessageW( hwndDlg, WM_NEXTDLGCTL, 0, 0);
430 }
431 else if (dlgCode & DLGC_BUTTON)
432 {
433 /* send BM_CLICK message to the control */
434 SendMessageW( hwndControl, BM_CLICK, 0, 0 );
435 }
436 return TRUE;
437 }
438 }
439 hwndNext = GetWindow( hwndControl, GW_CHILD );
440 }
441 else hwndNext = 0;
442
443 if (!hwndNext) hwndNext = GetWindow( hwndControl, GW_HWNDNEXT );
444
445 while (!hwndNext && hwndControl)
446 {
447 hwndControl = GetParent( hwndControl );
448 if (hwndControl == hwndDlg)
449 {
450 if(hwnd==hwndDlg) /* prevent endless loop */
451 {
452 hwndNext=hwnd;
453 break;
454 }
455 hwndNext = GetWindow( hwndDlg, GW_CHILD );
456 }
457 else
458 hwndNext = GetWindow( hwndControl, GW_HWNDNEXT );
459 }
460 hwndControl = hwndNext;
461 }
462 while (hwndControl && (hwndControl != hwnd));
463
464 return FALSE;
465 }
466
467 /***********************************************************************
468 * DIALOG_FindMsgDestination
469 *
470 * The messages that IsDialogMessage sends may not go to the dialog
471 * calling IsDialogMessage if that dialog is a child, and it has the
472 * DS_CONTROL style set.
473 * We propagate up until we hit one that does not have DS_CONTROL, or
474 * whose parent is not a dialog.
475 *
476 * This is undocumented behaviour.
477 */
478 static HWND DIALOG_FindMsgDestination( HWND hwndDlg )
479 {
480 while (GetWindowLongA(hwndDlg, GWL_STYLE) & DS_CONTROL)
481 {
482 PWND pWnd;
483 HWND hParent = GetParent(hwndDlg);
484 if (!hParent) break;
485 // ReactOS
486 if (!IsWindow(hParent)) break;
487
488 pWnd = ValidateHwnd(hParent);
489 // FIXME: Use pWnd->fnid == FNID_DESKTOP
490 if (!pWnd || !TestWindowProcess(pWnd) || hParent == GetDesktopWindow()) break;
491
492 if (!(pWnd->state & WNDS_DIALOGWINDOW))
493 {
494 break;
495 }
496
497 hwndDlg = hParent;
498 }
499
500 return hwndDlg;
501 }
502
503 /***********************************************************************
504 * DIALOG_DoDialogBox
505 */
506 INT DIALOG_DoDialogBox( HWND hwnd, HWND owner )
507 {
508 DIALOGINFO * dlgInfo;
509 MSG msg;
510 INT retval;
511 BOOL bFirstEmpty;
512 PWND pWnd;
513
514 pWnd = ValidateHwnd(hwnd);
515 if (!pWnd) return -1;
516
517 if (!(dlgInfo = GETDLGINFO(hwnd))) return -1;
518
519 bFirstEmpty = TRUE;
520 if (!(dlgInfo->flags & DF_END)) /* was EndDialog called in WM_INITDIALOG ? */
521 {
522 for (;;)
523 {
524 if (!PeekMessageW( &msg, 0, 0, 0, PM_REMOVE ))
525 {
526 if (bFirstEmpty)
527 {
528 /* ShowWindow the first time the queue goes empty */
529 ShowWindow( hwnd, SW_SHOWNORMAL );
530 bFirstEmpty = FALSE;
531 }
532 if (!(GetWindowLongPtrW( hwnd, GWL_STYLE ) & DS_NOIDLEMSG))
533 {
534 /* No message present -> send ENTERIDLE and wait */
535 SendMessageW( owner, WM_ENTERIDLE, MSGF_DIALOGBOX, (LPARAM)hwnd );
536 }
537 GetMessageW( &msg, 0, 0, 0 );
538 }
539
540 if (msg.message == WM_QUIT)
541 {
542 PostQuitMessage( msg.wParam );
543 if (!IsWindow( hwnd )) return 0;
544 break;
545 }
546
547 /*
548 * If the user is pressing Ctrl+C, send a WM_COPY message.
549 * Guido Pola, CORE-4829, Is there another way to check if the Dialog is a MessageBox?
550 */
551 if (msg.message == WM_KEYDOWN &&
552 pWnd->state & WNDS_MSGBOX && // Yes!
553 GetForegroundWindow() == hwnd)
554 {
555 if (msg.wParam == L'C' && GetKeyState(VK_CONTROL) < 0)
556 SendMessageW(hwnd, WM_COPY, 0, 0);
557 }
558
559 if (!IsWindow( hwnd )) return 0;
560 if (!(dlgInfo->flags & DF_END) && !IsDialogMessageW( hwnd, &msg))
561 {
562 TranslateMessage( &msg );
563 DispatchMessageW( &msg );
564 }
565 if (!IsWindow( hwnd )) return 0;
566 if (dlgInfo->flags & DF_END) break;
567
568 if (bFirstEmpty && msg.message == WM_TIMER)
569 {
570 ShowWindow( hwnd, SW_SHOWNORMAL );
571 bFirstEmpty = FALSE;
572 }
573 }
574 }
575 retval = dlgInfo->idResult;
576 DestroyWindow( hwnd );
577 return retval;
578 }
579
580 /***********************************************************************
581 * DIALOG_ParseTemplate32
582 *
583 * Fill a DLG_TEMPLATE structure from the dialog template, and return
584 * a pointer to the first control.
585 */
586 static LPCSTR DIALOG_ParseTemplate32( LPCSTR template, DLG_TEMPLATE * result )
587 {
588 const WORD *p = (const WORD *)template;
589 WORD signature;
590 WORD dlgver;
591
592 dlgver = GET_WORD(p); p++;
593 signature = GET_WORD(p); p++;
594
595 if (dlgver == 1 && signature == 0xffff) /* DIALOGEX resource */
596 {
597 result->dialogEx = TRUE;
598 result->helpId = GET_DWORD(p); p += 2;
599 result->exStyle = GET_DWORD(p); p += 2;
600 result->style = GET_DWORD(p); p += 2;
601 }
602 else
603 {
604 result->style = GET_DWORD(p - 2);
605 result->dialogEx = FALSE;
606 result->helpId = 0;
607 result->exStyle = GET_DWORD(p); p += 2;
608 }
609 result->nbItems = GET_WORD(p); p++;
610 result->x = GET_WORD(p); p++;
611 result->y = GET_WORD(p); p++;
612 result->cx = GET_WORD(p); p++;
613 result->cy = GET_WORD(p); p++;
614 TRACE("DIALOG%s %d, %d, %d, %d, %d\n",
615 result->dialogEx ? "EX" : "", result->x, result->y,
616 result->cx, result->cy, result->helpId );
617 TRACE(" STYLE 0x%08x\n", result->style );
618 TRACE(" EXSTYLE 0x%08x\n", result->exStyle );
619
620 /* Get the menu name */
621
622 switch(GET_WORD(p))
623 {
624 case 0x0000:
625 result->menuName = NULL;
626 p++;
627 break;
628 case 0xffff:
629 result->menuName = (LPCWSTR)(UINT_PTR)GET_WORD( p + 1 );
630 p += 2;
631 TRACE(" MENU %04x\n", LOWORD(result->menuName) );
632 break;
633 default:
634 result->menuName = (LPCWSTR)p;
635 TRACE(" MENU %s\n", debugstr_w(result->menuName) );
636 p += strlenW( result->menuName ) + 1;
637 break;
638 }
639
640 /* Get the class name */
641
642 switch(GET_WORD(p))
643 {
644 case 0x0000:
645 result->className = WC_DIALOG;
646 p++;
647 break;
648 case 0xffff:
649 result->className = (LPCWSTR)(UINT_PTR)GET_WORD( p + 1 );
650 p += 2;
651 TRACE(" CLASS %04x\n", LOWORD(result->className) );
652 break;
653 default:
654 result->className = (LPCWSTR)p;
655 TRACE(" CLASS %s\n", debugstr_w( result->className ));
656 p += strlenW( result->className ) + 1;
657 break;
658 }
659
660 /* Get the window caption */
661
662 result->caption = (LPCWSTR)p;
663 p += strlenW( result->caption ) + 1;
664 TRACE(" CAPTION %s\n", debugstr_w( result->caption ) );
665
666 /* Get the font name */
667
668 result->pointSize = 0;
669 result->faceName = NULL;
670 result->weight = FW_DONTCARE;
671 result->italic = FALSE;
672
673 if (result->style & DS_SETFONT)
674 {
675 result->pointSize = GET_WORD(p);
676 p++;
677
678 /* If pointSize is 0x7fff, it means that we need to use the font
679 * in NONCLIENTMETRICSW.lfMessageFont, and NOT read the weight,
680 * italic, and facename from the dialog template.
681 */
682 if (result->pointSize == 0x7fff)
683 {
684 /* We could call SystemParametersInfo here, but then we'd have
685 * to convert from pixel size to point size (which can be
686 * imprecise).
687 */
688 TRACE(" FONT: Using message box font\n");
689 }
690 else
691 {
692 if (result->dialogEx)
693 {
694 result->weight = GET_WORD(p); p++;
695 result->italic = LOBYTE(GET_WORD(p)); p++;
696 }
697 result->faceName = (LPCWSTR)p;
698 p += strlenW( result->faceName ) + 1;
699
700 TRACE(" FONT %d, %s, %d, %s\n",
701 result->pointSize, debugstr_w( result->faceName ),
702 result->weight, result->italic ? "TRUE" : "FALSE" );
703 }
704 }
705
706 /* First control is on dword boundary */
707 return (LPCSTR)((((UINT_PTR)p) + 3) & ~3);
708 }
709
710 /***********************************************************************
711 * DEFDLG_SetFocus
712 *
713 * Set the focus to a control of the dialog, selecting the text if
714 * the control is an edit dialog that has DLGC_HASSETSEL.
715 */
716 static void DEFDLG_SetFocus( HWND hwndCtrl )
717 {
718 if (SendMessageW( hwndCtrl, WM_GETDLGCODE, 0, 0 ) & DLGC_HASSETSEL)
719 SendMessageW( hwndCtrl, EM_SETSEL, 0, -1 );
720 SetFocus( hwndCtrl );
721 }
722
723
724 /***********************************************************************
725 * DEFDLG_SaveFocus
726 */
727 static void DEFDLG_SaveFocus( HWND hwnd )
728 {
729 DIALOGINFO *infoPtr;
730 HWND hwndFocus = GetFocus();
731
732 if (!hwndFocus || !IsChild( hwnd, hwndFocus )) return;
733 if (!(infoPtr = GETDLGINFO(hwnd))) return;
734 infoPtr->hwndFocus = hwndFocus;
735 /* Remove default button */
736 }
737
738
739 /***********************************************************************
740 * DEFDLG_RestoreFocus
741 */
742 static void DEFDLG_RestoreFocus( HWND hwnd, BOOL justActivate )
743 {
744 DIALOGINFO *infoPtr;
745
746 if (IsIconic( hwnd )) return;
747 if (!(infoPtr = GETDLGINFO(hwnd))) return;
748 /* Don't set the focus back to controls if EndDialog is already called.*/
749 if (infoPtr->flags & DF_END) return;
750 if (!IsWindow(infoPtr->hwndFocus) || infoPtr->hwndFocus == hwnd) {
751 if (justActivate) return;
752 /* If no saved focus control exists, set focus to the first visible,
753 non-disabled, WS_TABSTOP control in the dialog */
754 infoPtr->hwndFocus = GetNextDlgTabItem( hwnd, 0, FALSE );
755 /* If there are no WS_TABSTOP controls, set focus to the first visible,
756 non-disabled control in the dialog */
757 if (!infoPtr->hwndFocus) infoPtr->hwndFocus = GetNextDlgGroupItem( hwnd, 0, FALSE );
758 if (!IsWindow( infoPtr->hwndFocus )) return;
759 }
760 if (justActivate)
761 SetFocus( infoPtr->hwndFocus );
762 else
763 DEFDLG_SetFocus( infoPtr->hwndFocus );
764
765 infoPtr->hwndFocus = NULL;
766 }
767
768 /***********************************************************************
769 * DIALOG_CreateIndirect
770 * Creates a dialog box window
771 *
772 * modal = TRUE if we are called from a modal dialog box.
773 * (it's more compatible to do it here, as under Windows the owner
774 * is never disabled if the dialog fails because of an invalid template)
775 */
776 static HWND DIALOG_CreateIndirect( HINSTANCE hInst, LPCVOID dlgTemplate,
777 HWND owner, DLGPROC dlgProc, LPARAM param,
778 BOOL unicode, HWND *modal_owner )
779 {
780 HWND hwnd;
781 RECT rect;
782 POINT pos;
783 SIZE size;
784 DLG_TEMPLATE template;
785 DIALOGINFO * dlgInfo = NULL;
786 DWORD units = GetDialogBaseUnits();
787 HWND disabled_owner = NULL;
788 HMENU hMenu = 0;
789 HFONT hUserFont = 0;
790 UINT flags = 0;
791 UINT xBaseUnit = LOWORD(units);
792 UINT yBaseUnit = HIWORD(units);
793
794 /* Parse dialog template */
795
796 if (!dlgTemplate) return 0;
797 dlgTemplate = DIALOG_ParseTemplate32( dlgTemplate, &template );
798
799 /* Load menu */
800
801 if (template.menuName) hMenu = LoadMenuW( hInst, template.menuName );
802
803 /* Create custom font if needed */
804
805 if (template.style & DS_SETFONT)
806 {
807 HDC dc = GetDC(0);
808
809 if (template.pointSize == 0x7fff)
810 {
811 /* We get the message font from the non-client metrics */
812 NONCLIENTMETRICSW ncMetrics;
813
814 ncMetrics.cbSize = sizeof(NONCLIENTMETRICSW);
815 if (SystemParametersInfoW(SPI_GETNONCLIENTMETRICS,
816 sizeof(NONCLIENTMETRICSW), &ncMetrics, 0))
817 {
818 hUserFont = CreateFontIndirectW( &ncMetrics.lfMessageFont );
819 }
820 }
821 else
822 {
823 /* We convert the size to pixels and then make it -ve. This works
824 * for both +ve and -ve template.pointSize */
825 int pixels = MulDiv(template.pointSize, GetDeviceCaps(dc , LOGPIXELSY), 72);
826 hUserFont = CreateFontW( -pixels, 0, 0, 0, template.weight,
827 template.italic, FALSE, FALSE, DEFAULT_CHARSET, 0, 0,
828 PROOF_QUALITY, FF_DONTCARE,
829 template.faceName );
830 }
831
832 if (hUserFont)
833 {
834 SIZE charSize;
835 HFONT hOldFont = SelectObject( dc, hUserFont );
836 charSize.cx = GdiGetCharDimensions( dc, NULL, &charSize.cy );
837 if (charSize.cx)
838 {
839 xBaseUnit = charSize.cx;
840 yBaseUnit = charSize.cy;
841 }
842 SelectObject( dc, hOldFont );
843 }
844 ReleaseDC(0, dc);
845 TRACE("units = %d,%d\n", xBaseUnit, yBaseUnit );
846 }
847
848 /* Create dialog main window */
849
850 SetRect(&rect, 0, 0, MulDiv(template.cx, xBaseUnit, 4), MulDiv(template.cy, yBaseUnit, 8));
851 if (template.style & DS_CONTROL)
852 template.style &= ~(WS_CAPTION|WS_SYSMENU);
853 template.style |= DS_3DLOOK;
854 if (template.style & DS_MODALFRAME)
855 template.exStyle |= WS_EX_DLGMODALFRAME;
856 if ((template.style & DS_CONTROL) || !(template.style & WS_CHILD))
857 template.exStyle |= WS_EX_CONTROLPARENT;
858 AdjustWindowRectEx( &rect, template.style, (hMenu != 0), template.exStyle );
859 pos.x = rect.left;
860 pos.y = rect.top;
861 size.cx = rect.right - rect.left;
862 size.cy = rect.bottom - rect.top;
863
864 if (template.x == CW_USEDEFAULT16)
865 {
866 pos.x = pos.y = CW_USEDEFAULT;
867 }
868 else
869 {
870 HMONITOR monitor = 0;
871 MONITORINFO mon_info;
872
873 mon_info.cbSize = sizeof(mon_info);
874 if (template.style & DS_CENTER)
875 {
876 monitor = MonitorFromWindow( owner ? owner : GetActiveWindow(), MONITOR_DEFAULTTOPRIMARY );
877 GetMonitorInfoW( monitor, &mon_info );
878 pos.x = (mon_info.rcWork.left + mon_info.rcWork.right - size.cx) / 2;
879 pos.y = (mon_info.rcWork.top + mon_info.rcWork.bottom - size.cy) / 2;
880 }
881 else if (template.style & DS_CENTERMOUSE)
882 {
883 GetCursorPos( &pos );
884 monitor = MonitorFromPoint( pos, MONITOR_DEFAULTTOPRIMARY );
885 GetMonitorInfoW( monitor, &mon_info );
886 }
887 else
888 {
889 pos.x += MulDiv(template.x, xBaseUnit, 4);
890 pos.y += MulDiv(template.y, yBaseUnit, 8);
891 //
892 // REACTOS : Need an owner to be passed!!!
893 //
894 if (!(template.style & (WS_CHILD|DS_ABSALIGN)) && owner ) ClientToScreen( owner, &pos );
895 }
896 if ( !(template.style & WS_CHILD) )
897 {
898 INT dX, dY;
899
900 /* try to fit it into the desktop */
901
902 if (!monitor)
903 {
904 SetRect( &rect, pos.x, pos.y, pos.x + size.cx, pos.y + size.cy );
905 monitor = MonitorFromRect( &rect, MONITOR_DEFAULTTOPRIMARY );
906 GetMonitorInfoW( monitor, &mon_info );
907 }
908 if ((dX = pos.x + size.cx + GetSystemMetrics(SM_CXDLGFRAME) - mon_info.rcWork.right) > 0)
909 pos.x -= dX;
910 if ((dY = pos.y + size.cy + GetSystemMetrics(SM_CYDLGFRAME) - mon_info.rcWork.bottom) > 0)
911 pos.y -= dY;
912 if( pos.x < mon_info.rcWork.left ) pos.x = mon_info.rcWork.left;
913 if( pos.y < mon_info.rcWork.top ) pos.y = mon_info.rcWork.top;
914 }
915 }
916
917 if (modal_owner && owner)
918 {
919 HWND parent = NULL;
920 /*
921 * Owner needs to be top level window. We need to duplicate the logic from server,
922 * because we need to disable it before creating dialog window. Note that we do that
923 * even if dialog has WS_CHILD, but only for modal dialogs, which matched what
924 * Windows does.
925 */
926 while ((GetWindowLongW( owner, GWL_STYLE ) & (WS_POPUP|WS_CHILD)) == WS_CHILD)
927 {
928 parent = GetParent( owner );
929 if (!parent || parent == GetDesktopWindow()) break;
930 owner = parent;
931 }
932 ////// Wine'ie babies need to fix your code!!!! CORE-11633
933 if (parent)
934 {
935 owner = parent;
936
937 if (IsWindowEnabled( owner ))
938 {
939 disabled_owner = owner;
940 EnableWindow( disabled_owner, FALSE );
941 }
942 }
943 *modal_owner = owner;
944 }
945
946 if (unicode)
947 {
948 hwnd = CreateWindowExW(template.exStyle, template.className, template.caption,
949 template.style & ~WS_VISIBLE, pos.x, pos.y, size.cx, size.cy,
950 owner, hMenu, hInst, NULL );
951 }
952 else
953 {
954 LPCSTR class = (LPCSTR)template.className;
955 LPCSTR caption = (LPCSTR)template.caption;
956 LPSTR class_tmp = NULL;
957 LPSTR caption_tmp = NULL;
958
959 if (!IS_INTRESOURCE(class))
960 {
961 DWORD len = WideCharToMultiByte( CP_ACP, 0, template.className, -1, NULL, 0, NULL, NULL );
962 class_tmp = HeapAlloc( GetProcessHeap(), 0, len );
963 WideCharToMultiByte( CP_ACP, 0, template.className, -1, class_tmp, len, NULL, NULL );
964 class = class_tmp;
965 }
966 if (!IS_INTRESOURCE(caption))
967 {
968 DWORD len = WideCharToMultiByte( CP_ACP, 0, template.caption, -1, NULL, 0, NULL, NULL );
969 caption_tmp = HeapAlloc( GetProcessHeap(), 0, len );
970 WideCharToMultiByte( CP_ACP, 0, template.caption, -1, caption_tmp, len, NULL, NULL );
971 caption = caption_tmp;
972 }
973 hwnd = CreateWindowExA(template.exStyle, class, caption,
974 template.style & ~WS_VISIBLE, pos.x, pos.y, size.cx, size.cy,
975 owner, hMenu, hInst, NULL );
976 HeapFree( GetProcessHeap(), 0, class_tmp );
977 HeapFree( GetProcessHeap(), 0, caption_tmp );
978 }
979
980 if (!hwnd)
981 {
982 if (hUserFont) DeleteObject( hUserFont );
983 if (hMenu) DestroyMenu( hMenu );
984 if (disabled_owner) EnableWindow( disabled_owner, TRUE );
985 return 0;
986 }
987
988 /* moved this from the top of the method to here as DIALOGINFO structure
989 will be valid only after WM_CREATE message has been handled in DefDlgProc
990 All the members of the structure get filled here using temp variables */
991 dlgInfo = DIALOG_get_info( hwnd, TRUE );
992 // ReactOS
993 if (dlgInfo == NULL)
994 {
995 if (hUserFont) DeleteObject( hUserFont );
996 if (hMenu) DestroyMenu( hMenu );
997 if (disabled_owner) EnableWindow( disabled_owner, TRUE );
998 return 0;
999 }
1000 //
1001 dlgInfo->hwndFocus = 0;
1002 dlgInfo->hUserFont = hUserFont;
1003 dlgInfo->hMenu = hMenu;
1004 dlgInfo->xBaseUnit = xBaseUnit;
1005 dlgInfo->yBaseUnit = yBaseUnit;
1006 dlgInfo->flags = flags;
1007
1008 if (template.helpId) SetWindowContextHelpId( hwnd, template.helpId );
1009
1010 if (unicode) SetWindowLongPtrW( hwnd, DWLP_DLGPROC, (ULONG_PTR)dlgProc );
1011 else SetWindowLongPtrA( hwnd, DWLP_DLGPROC, (ULONG_PTR)dlgProc );
1012
1013 if (dlgProc && dlgInfo->hUserFont)
1014 SendMessageW( hwnd, WM_SETFONT, (WPARAM)dlgInfo->hUserFont, 0 );
1015
1016 /* Create controls */
1017
1018 if (DIALOG_CreateControls32( hwnd, dlgTemplate, &template, hInst, unicode ))
1019 {
1020 /* Send initialisation messages and set focus */
1021
1022 if (dlgProc)
1023 {
1024 HWND focus = GetNextDlgTabItem( hwnd, 0, FALSE );
1025 if (!focus) focus = GetNextDlgGroupItem( hwnd, 0, FALSE );
1026 if (SendMessageW( hwnd, WM_INITDIALOG, (WPARAM)focus, param ) && IsWindow( hwnd ) &&
1027 ((~template.style & DS_CONTROL) || (template.style & WS_VISIBLE)))
1028 {
1029 /* By returning TRUE, app has requested a default focus assignment.
1030 * WM_INITDIALOG may have changed the tab order, so find the first
1031 * tabstop control again. */
1032 focus = GetNextDlgTabItem( hwnd, 0, FALSE );
1033 if (!focus) focus = GetNextDlgGroupItem( hwnd, 0, FALSE );
1034 if (focus)
1035 {
1036 if (SendMessageW( focus, WM_GETDLGCODE, 0, 0 ) & DLGC_HASSETSEL)
1037 SendMessageW( focus, EM_SETSEL, 0, MAXLONG );
1038 SetFocus( focus );
1039 }
1040 }
1041 //// ReactOS see 43396, Fixes setting focus on Open and Close dialogs to the FileName edit control in OpenOffice.
1042 //// This now breaks test_SaveRestoreFocus.
1043 //DEFDLG_SaveFocus( hwnd );
1044 ////
1045 }
1046 //// ReactOS Rev 30613 & 30644
1047 if (!(GetWindowLongPtrW( hwnd, GWL_STYLE ) & WS_CHILD))
1048 SendMessageW( hwnd, WM_CHANGEUISTATE, MAKEWPARAM(UIS_INITIALIZE, 0), 0);
1049 ////
1050 if (template.style & WS_VISIBLE && !(GetWindowLongPtrW( hwnd, GWL_STYLE ) & WS_VISIBLE))
1051 {
1052 ShowWindow( hwnd, SW_SHOWNORMAL ); /* SW_SHOW doesn't always work */
1053 UpdateWindow( hwnd );
1054 IntNotifyWinEvent(EVENT_SYSTEM_DIALOGSTART, hwnd, OBJID_WINDOW, CHILDID_SELF, 0);
1055 }
1056 return hwnd;
1057 }
1058 if (disabled_owner) EnableWindow( disabled_owner, TRUE );
1059 IntNotifyWinEvent(EVENT_SYSTEM_DIALOGEND, hwnd, OBJID_WINDOW, CHILDID_SELF, 0);
1060 if( IsWindow(hwnd) )
1061 {
1062 DestroyWindow( hwnd );
1063 //// ReactOS
1064 if (owner)
1065 { ERR("DIALOG_CreateIndirect 1\n");
1066 if ( NtUserGetThreadState(THREADSTATE_FOREGROUNDTHREAD) && // Rule #1.
1067 !NtUserQueryWindow(owner, QUERY_WINDOW_FOREGROUND) )
1068 { ERR("DIALOG_CreateIndirect SFW\n");
1069 SetForegroundWindow(owner);
1070 }
1071 }
1072 ////
1073 }
1074 return 0;
1075 }
1076
1077
1078 /***********************************************************************
1079 * DEFDLG_FindDefButton
1080 *
1081 * Find the current default push-button.
1082 */
1083 static HWND DEFDLG_FindDefButton( HWND hwndDlg )
1084 {
1085 HWND hwndChild, hwndTmp;
1086
1087 hwndChild = GetWindow( hwndDlg, GW_CHILD );
1088 while (hwndChild)
1089 {
1090 if (SendMessageW( hwndChild, WM_GETDLGCODE, 0, 0 ) & DLGC_DEFPUSHBUTTON)
1091 break;
1092
1093 /* Recurse into WS_EX_CONTROLPARENT controls */
1094 if (GetWindowLongPtrW( hwndChild, GWL_EXSTYLE ) & WS_EX_CONTROLPARENT)
1095 {
1096 LONG dsStyle = GetWindowLongPtrW( hwndChild, GWL_STYLE );
1097 if ((dsStyle & WS_VISIBLE) && !(dsStyle & WS_DISABLED) &&
1098 (hwndTmp = DEFDLG_FindDefButton(hwndChild)) != NULL)
1099 return hwndTmp;
1100 }
1101 hwndChild = GetWindow( hwndChild, GW_HWNDNEXT );
1102 }
1103 return hwndChild;
1104 }
1105
1106
1107 /***********************************************************************
1108 * DEFDLG_SetDefId
1109 *
1110 * Set the default button id.
1111 */
1112 static BOOL DEFDLG_SetDefId( HWND hwndDlg, DIALOGINFO *dlgInfo, WPARAM wParam)
1113 {
1114 DWORD dlgcode=0; /* initialize just to avoid a warning */
1115 HWND hwndOld, hwndNew = GetDlgItem(hwndDlg, wParam);
1116 INT old_id = dlgInfo->idResult;
1117
1118 dlgInfo->idResult = wParam;
1119 if (hwndNew &&
1120 !((dlgcode=SendMessageW(hwndNew, WM_GETDLGCODE, 0, 0 ))
1121 & (DLGC_UNDEFPUSHBUTTON | DLGC_BUTTON)))
1122 return FALSE; /* Destination is not a push button */
1123
1124 /* Make sure the old default control is a valid push button ID */
1125 hwndOld = GetDlgItem( hwndDlg, old_id );
1126 if (!hwndOld || !(SendMessageW( hwndOld, WM_GETDLGCODE, 0, 0) & DLGC_DEFPUSHBUTTON))
1127 hwndOld = DEFDLG_FindDefButton( hwndDlg );
1128 if (hwndOld && hwndOld != hwndNew)
1129 SendMessageW( hwndOld, BM_SETSTYLE, BS_PUSHBUTTON, TRUE );
1130
1131 if (hwndNew)
1132 {
1133 if(dlgcode & DLGC_UNDEFPUSHBUTTON)
1134 SendMessageW( hwndNew, BM_SETSTYLE, BS_DEFPUSHBUTTON, TRUE );
1135 }
1136 return TRUE;
1137 }
1138
1139
1140 /***********************************************************************
1141 * DEFDLG_SetDefButton
1142 *
1143 * Set the new default button to be hwndNew.
1144 */
1145 static BOOL DEFDLG_SetDefButton( HWND hwndDlg, DIALOGINFO *dlgInfo, HWND hwndNew )
1146 {
1147 DWORD dlgcode=0; /* initialize just to avoid a warning */
1148 HWND hwndOld = GetDlgItem( hwndDlg, dlgInfo->idResult );
1149
1150 if (hwndNew &&
1151 !((dlgcode=SendMessageW(hwndNew, WM_GETDLGCODE, 0, 0 ))
1152 & (DLGC_UNDEFPUSHBUTTON | DLGC_DEFPUSHBUTTON)))
1153 {
1154 /**
1155 * Need to draw only default push button rectangle.
1156 * Since the next control is not a push button, need to draw the push
1157 * button rectangle for the default control.
1158 */
1159 hwndNew = hwndOld;
1160 dlgcode = SendMessageW(hwndNew, WM_GETDLGCODE, 0, 0 );
1161 }
1162
1163 /* Make sure the old default control is a valid push button ID */
1164 if (!hwndOld || !(SendMessageW( hwndOld, WM_GETDLGCODE, 0, 0) & DLGC_DEFPUSHBUTTON))
1165 hwndOld = DEFDLG_FindDefButton( hwndDlg );
1166 if (hwndOld && hwndOld != hwndNew)
1167 SendMessageW( hwndOld, BM_SETSTYLE, BS_PUSHBUTTON, TRUE );
1168
1169 if (hwndNew)
1170 {
1171 if(dlgcode & DLGC_UNDEFPUSHBUTTON)
1172 SendMessageW( hwndNew, BM_SETSTYLE, BS_DEFPUSHBUTTON, TRUE );
1173 }
1174 return TRUE;
1175 }
1176
1177
1178 /***********************************************************************
1179 * DEFDLG_Proc
1180 *
1181 * Implementation of DefDlgProc(). Only handle messages that need special
1182 * handling for dialogs.
1183 */
1184 static LRESULT DEFDLG_Proc( HWND hwnd, UINT msg, WPARAM wParam,
1185 LPARAM lParam, DIALOGINFO *dlgInfo )
1186 {
1187 switch(msg)
1188 {
1189 case WM_ERASEBKGND:
1190 {
1191 HBRUSH brush = GetControlColor( hwnd, hwnd, (HDC)wParam, WM_CTLCOLORDLG);
1192 if (brush)
1193 {
1194 RECT rect;
1195 HDC hdc = (HDC)wParam;
1196 GetClientRect( hwnd, &rect );
1197 DPtoLP( hdc, (LPPOINT)&rect, 2 );
1198 FillRect( hdc, &rect, brush );
1199 }
1200 return 1;
1201 }
1202 case WM_NCDESTROY:
1203 //// ReactOS
1204 if ((dlgInfo = (DIALOGINFO *)SetWindowLongPtrW( hwnd, DWLP_ROS_DIALOGINFO, 0 )))
1205 {
1206 if (dlgInfo->hUserFont) DeleteObject( dlgInfo->hUserFont );
1207 if (dlgInfo->hMenu) DestroyMenu( dlgInfo->hMenu );
1208 HeapFree( GetProcessHeap(), 0, dlgInfo );
1209 NtUserSetThreadState(0,DF_DIALOGACTIVE);
1210 NtUserxSetDialogPointer( hwnd, 0 );
1211 }
1212 /* Window clean-up */
1213 return DefWindowProcA( hwnd, msg, wParam, lParam );
1214
1215 case WM_SHOWWINDOW:
1216 if (!wParam) DEFDLG_SaveFocus( hwnd );
1217 return DefWindowProcA( hwnd, msg, wParam, lParam );
1218
1219 case WM_ACTIVATE:
1220 { // ReactOS
1221 DWORD dwSetFlag;
1222 HWND hwndparent = DIALOG_FindMsgDestination( hwnd );
1223 // if WA_CLICK/ACTIVE ? set dialog is active.
1224 dwSetFlag = wParam ? DF_DIALOGACTIVE : 0;
1225 if (hwndparent != hwnd) NtUserSetThreadState(dwSetFlag, DF_DIALOGACTIVE);
1226 }
1227 if (wParam) DEFDLG_RestoreFocus( hwnd, TRUE );
1228 else DEFDLG_SaveFocus( hwnd );
1229 return 0;
1230
1231 case WM_SETFOCUS:
1232 DEFDLG_RestoreFocus( hwnd, FALSE );
1233 return 0;
1234
1235 case DM_SETDEFID:
1236 if (dlgInfo && !(dlgInfo->flags & DF_END))
1237 DEFDLG_SetDefId( hwnd, dlgInfo, wParam );
1238 return 1;
1239
1240 case DM_GETDEFID:
1241 if (dlgInfo && !(dlgInfo->flags & DF_END))
1242 {
1243 HWND hwndDefId;
1244 if (dlgInfo->idResult)
1245 return MAKELONG( dlgInfo->idResult, DC_HASDEFID );
1246 if ((hwndDefId = DEFDLG_FindDefButton( hwnd )))
1247 return MAKELONG( GetDlgCtrlID( hwndDefId ), DC_HASDEFID);
1248 }
1249 return 0;
1250
1251 case WM_NEXTDLGCTL:
1252 if (dlgInfo)
1253 {
1254 HWND hwndDest = (HWND)wParam;
1255 if (!lParam)
1256 hwndDest = GetNextDlgTabItem(hwnd, GetFocus(), wParam);
1257 if (hwndDest) DEFDLG_SetFocus( hwndDest );
1258 DEFDLG_SetDefButton( hwnd, dlgInfo, hwndDest );
1259 }
1260 return 0;
1261
1262 case WM_ENTERMENULOOP:
1263 case WM_LBUTTONDOWN:
1264 case WM_NCLBUTTONDOWN:
1265 {
1266 HWND hwndFocus = GetFocus();
1267 if (hwndFocus)
1268 {
1269 /* always make combo box hide its listbox control */
1270 if (!SendMessageW( hwndFocus, CB_SHOWDROPDOWN, FALSE, 0 ))
1271 SendMessageW( GetParent(hwndFocus), CB_SHOWDROPDOWN, FALSE, 0 );
1272 }
1273 }
1274 return DefWindowProcA( hwnd, msg, wParam, lParam );
1275
1276 case WM_GETFONT:
1277 return dlgInfo ? (LRESULT)dlgInfo->hUserFont : 0;
1278
1279 case WM_CLOSE:
1280 PostMessageA( hwnd, WM_COMMAND, MAKEWPARAM(IDCANCEL, BN_CLICKED),
1281 (LPARAM)GetDlgItem( hwnd, IDCANCEL ) );
1282 return 0;
1283 }
1284 return 0;
1285 }
1286
1287 /***********************************************************************
1288 * DEFDLG_Epilog
1289 */
1290 static LRESULT DEFDLG_Epilog(HWND hwnd, UINT msg, WPARAM wParam, LPARAM lParam, BOOL fResult, BOOL fAnsi)
1291 {
1292 if ((msg >= WM_CTLCOLORMSGBOX && msg <= WM_CTLCOLORSTATIC) ||
1293 msg == WM_CTLCOLOR)
1294 {
1295 if (fResult) return fResult;
1296
1297 return fAnsi ? DefWindowProcA(hwnd, msg, wParam, lParam):
1298 DefWindowProcW(hwnd, msg, wParam, lParam);
1299 }
1300 if ( msg == WM_COMPAREITEM ||
1301 msg == WM_VKEYTOITEM || msg == WM_CHARTOITEM ||
1302 msg == WM_QUERYDRAGICON || msg == WM_INITDIALOG)
1303 return fResult;
1304
1305 return GetWindowLongPtrW( hwnd, DWLP_MSGRESULT );
1306 }
1307
1308 /***********************************************************************
1309 * DIALOG_GetNextTabItem
1310 *
1311 * Helper for GetNextDlgTabItem
1312 */
1313 static HWND DIALOG_GetNextTabItem( HWND hwndMain, HWND hwndDlg, HWND hwndCtrl, BOOL fPrevious )
1314 {
1315 LONG dsStyle;
1316 LONG exStyle;
1317 UINT wndSearch = fPrevious ? GW_HWNDPREV : GW_HWNDNEXT;
1318 HWND retWnd = 0;
1319 HWND hChildFirst = 0;
1320
1321 if(!hwndCtrl)
1322 {
1323 hChildFirst = GetWindow(hwndDlg,GW_CHILD);
1324 if(fPrevious) hChildFirst = GetWindow(hChildFirst,GW_HWNDLAST);
1325 }
1326 else if (IsChild( hwndMain, hwndCtrl ))
1327 {
1328 hChildFirst = GetWindow(hwndCtrl,wndSearch);
1329 if(!hChildFirst)
1330 {
1331 if(GetParent(hwndCtrl) != hwndMain)
1332 /* i.e. if we are not at the top level of the recursion */
1333 hChildFirst = GetWindow(GetParent(hwndCtrl),wndSearch);
1334 else
1335 hChildFirst = GetWindow(hwndCtrl, fPrevious ? GW_HWNDLAST : GW_HWNDFIRST);
1336 }
1337 }
1338
1339 while(hChildFirst)
1340 {
1341 dsStyle = GetWindowLongPtrA(hChildFirst,GWL_STYLE);
1342 exStyle = GetWindowLongPtrA(hChildFirst,GWL_EXSTYLE);
1343 if( (exStyle & WS_EX_CONTROLPARENT) && (dsStyle & WS_VISIBLE) && !(dsStyle & WS_DISABLED))
1344 {
1345 HWND retWnd;
1346 retWnd = DIALOG_GetNextTabItem(hwndMain,hChildFirst,NULL,fPrevious );
1347 if (retWnd) return (retWnd);
1348 }
1349 else if( (dsStyle & WS_TABSTOP) && (dsStyle & WS_VISIBLE) && !(dsStyle & WS_DISABLED))
1350 {
1351 return (hChildFirst);
1352 }
1353 hChildFirst = GetWindow(hChildFirst,wndSearch);
1354 }
1355 if(hwndCtrl)
1356 {
1357 HWND hParent = GetParent(hwndCtrl);
1358 while(hParent)
1359 {
1360 if(hParent == hwndMain) break;
1361 retWnd = DIALOG_GetNextTabItem(hwndMain,GetParent(hParent),hParent,fPrevious );
1362 if(retWnd) break;
1363 hParent = GetParent(hParent);
1364 }
1365 if(!retWnd)
1366 retWnd = DIALOG_GetNextTabItem(hwndMain,hwndMain,NULL,fPrevious );
1367 }
1368 return retWnd ? retWnd : hwndCtrl;
1369 }
1370
1371
1372 /**********************************************************************
1373 * DIALOG_DlgDirListW
1374 *
1375 * Helper function for DlgDirList*W
1376 */
1377 static INT DIALOG_DlgDirListW( HWND hDlg, LPWSTR spec, INT idLBox,
1378 INT idStatic, UINT attrib, BOOL combo )
1379 {
1380 HWND hwnd;
1381 LPWSTR orig_spec = spec;
1382 WCHAR any[] = {'*','.','*',0};
1383
1384 #define SENDMSG(msg,wparam,lparam) \
1385 ((attrib & DDL_POSTMSGS) ? PostMessageW( hwnd, msg, wparam, lparam ) \
1386 : SendMessageW( hwnd, msg, wparam, lparam ))
1387
1388 TRACE("%p %s %d %d %04x\n", hDlg, debugstr_w(spec), idLBox, idStatic, attrib );
1389
1390 /* If the path exists and is a directory, chdir to it */
1391 if (!spec || !spec[0] || SetCurrentDirectoryW( spec )) spec = any;
1392 else
1393 {
1394 WCHAR *p, *p2;
1395 p = spec;
1396 if ((p2 = strchrW( p, ':' ))) p = p2 + 1;
1397 if ((p2 = strrchrW( p, '\\' ))) p = p2;
1398 if ((p2 = strrchrW( p, '/' ))) p = p2;
1399 if (p != spec)
1400 {
1401 WCHAR sep = *p;
1402 *p = 0;
1403 if (!SetCurrentDirectoryW( spec ))
1404 {
1405 *p = sep; /* Restore the original spec */
1406 return FALSE;
1407 }
1408 spec = p + 1;
1409 }
1410 }
1411
1412 TRACE( "mask=%s\n", spec );
1413
1414 if (idLBox && ((hwnd = GetDlgItem( hDlg, idLBox )) != 0))
1415 {
1416 if (attrib == DDL_DRIVES) attrib |= DDL_EXCLUSIVE;
1417
1418 SENDMSG( combo ? CB_RESETCONTENT : LB_RESETCONTENT, 0, 0 );
1419 if (attrib & DDL_DIRECTORY)
1420 {
1421 if (!(attrib & DDL_EXCLUSIVE))
1422 {
1423 SENDMSG( combo ? CB_DIR : LB_DIR,
1424 attrib & ~(DDL_DIRECTORY | DDL_DRIVES),
1425 (LPARAM)spec );
1426 }
1427 SENDMSG( combo ? CB_DIR : LB_DIR,
1428 (attrib & (DDL_DIRECTORY | DDL_DRIVES)) | DDL_EXCLUSIVE,
1429 (LPARAM)any );
1430 }
1431 else
1432 {
1433 SENDMSG( combo ? CB_DIR : LB_DIR, attrib, (LPARAM)spec );
1434 }
1435 }
1436
1437 /* Convert path specification to uppercase */
1438 if (spec) CharUpperW(spec);
1439
1440 if (idStatic && ((hwnd = GetDlgItem( hDlg, idStatic )) != 0))
1441 {
1442 WCHAR temp[MAX_PATH];
1443 GetCurrentDirectoryW( sizeof(temp)/sizeof(WCHAR), temp );
1444 CharLowerW( temp );
1445 /* Can't use PostMessage() here, because the string is on the stack */
1446 SetDlgItemTextW( hDlg, idStatic, temp );
1447 }
1448
1449 if (orig_spec && (spec != orig_spec))
1450 {
1451 /* Update the original file spec */
1452 WCHAR *p = spec;
1453 while ((*orig_spec++ = *p++));
1454 }
1455
1456 return TRUE;
1457 #undef SENDMSG
1458 }
1459
1460
1461 /**********************************************************************
1462 * DIALOG_DlgDirListA
1463 *
1464 * Helper function for DlgDirList*A
1465 */
1466 static INT DIALOG_DlgDirListA( HWND hDlg, LPSTR spec, INT idLBox,
1467 INT idStatic, UINT attrib, BOOL combo )
1468 {
1469 if (spec)
1470 {
1471 INT ret, len = MultiByteToWideChar( CP_ACP, 0, spec, -1, NULL, 0 );
1472 LPWSTR specW = HeapAlloc( GetProcessHeap(), 0, len * sizeof(WCHAR) );
1473 if (specW == NULL)
1474 return FALSE;
1475 MultiByteToWideChar( CP_ACP, 0, spec, -1, specW, len );
1476 ret = DIALOG_DlgDirListW( hDlg, specW, idLBox, idStatic, attrib, combo );
1477 WideCharToMultiByte( CP_ACP, 0, specW, -1, spec, 0x7fffffff, NULL, NULL );
1478 HeapFree( GetProcessHeap(), 0, specW );
1479 return ret;
1480 }
1481 return DIALOG_DlgDirListW( hDlg, NULL, idLBox, idStatic, attrib, combo );
1482 }
1483
1484 /**********************************************************************
1485 * DIALOG_DlgDirSelect
1486 *
1487 * Helper function for DlgDirSelect*
1488 */
1489 static BOOL DIALOG_DlgDirSelect( HWND hwnd, LPWSTR str, INT len,
1490 INT id, BOOL unicode, BOOL combo )
1491 {
1492 WCHAR *buffer, *ptr;
1493 INT item, size;
1494 BOOL ret;
1495 HWND listbox = GetDlgItem( hwnd, id );
1496
1497 TRACE("%p %s %d\n", hwnd, unicode ? debugstr_w(str) : debugstr_a((LPSTR)str), id );
1498 if (!listbox) return FALSE;
1499
1500 item = SendMessageW(listbox, combo ? CB_GETCURSEL : LB_GETCURSEL, 0, 0 );
1501 if (item == LB_ERR) return FALSE;
1502
1503 size = SendMessageW(listbox, combo ? CB_GETLBTEXTLEN : LB_GETTEXTLEN, item, 0 );
1504 if (size == LB_ERR) return FALSE;
1505
1506 if (!(buffer = HeapAlloc( GetProcessHeap(), 0, (size+2) * sizeof(WCHAR) ))) return FALSE;
1507
1508 SendMessageW( listbox, combo ? CB_GETLBTEXT : LB_GETTEXT, item, (LPARAM)buffer );
1509
1510 if ((ret = (buffer[0] == '['))) /* drive or directory */
1511 {
1512 if (buffer[1] == '-') /* drive */
1513 {
1514 buffer[3] = ':';
1515 buffer[4] = 0;
1516 ptr = buffer + 2;
1517 }
1518 else
1519 {
1520 buffer[strlenW(buffer)-1] = '\\';
1521 ptr = buffer + 1;
1522 }
1523 }
1524 else
1525 {
1526 /* Filenames without a dot extension must have one tacked at the end */
1527 if (strchrW(buffer, '.') == NULL)
1528 {
1529 buffer[strlenW(buffer)+1] = '\0';
1530 buffer[strlenW(buffer)] = '.';
1531 }
1532 ptr = buffer;
1533 }
1534
1535 if (!unicode)
1536 {
1537 if (len > 0 && !WideCharToMultiByte( CP_ACP, 0, ptr, -1, (LPSTR)str, len, 0, 0 ))
1538 ((LPSTR)str)[len-1] = 0;
1539 }
1540 else lstrcpynW( str, ptr, len );
1541 HeapFree( GetProcessHeap(), 0, buffer );
1542 TRACE("Returning %d %s\n", ret, unicode ? debugstr_w(str) : debugstr_a((LPSTR)str) );
1543 return ret;
1544 }
1545
1546
1547 /* FUNCTIONS *****************************************************************/
1548
1549 /*
1550 * @implemented
1551 */
1552 HWND
1553 WINAPI
1554 CreateDialogIndirectParamAorW(
1555 HINSTANCE hInstance,
1556 LPCDLGTEMPLATE lpTemplate,
1557 HWND hWndParent,
1558 DLGPROC lpDialogFunc,
1559 LPARAM lParamInit,
1560 DWORD Flags)
1561 {
1562 /* FIXME:
1563 * This function might be obsolete since I don't think it is exported by NT
1564 * Also wine has one more parameter identifying weather it should call
1565 * the function with unicode or not
1566 */
1567 return DIALOG_CreateIndirect( hInstance, lpTemplate, hWndParent, lpDialogFunc, lParamInit , Flags == DLG_ISANSI ? FALSE : TRUE, NULL );
1568 }
1569
1570
1571 /*
1572 * @implemented
1573 */
1574 HWND
1575 WINAPI
1576 CreateDialogIndirectParamA(
1577 HINSTANCE hInstance,
1578 LPCDLGTEMPLATE lpTemplate,
1579 HWND hWndParent,
1580 DLGPROC lpDialogFunc,
1581 LPARAM lParamInit)
1582 {
1583 return CreateDialogIndirectParamAorW( hInstance, lpTemplate, hWndParent, lpDialogFunc, lParamInit, DLG_ISANSI);
1584 }
1585
1586
1587 /*
1588 * @implemented
1589 */
1590 HWND
1591 WINAPI
1592 CreateDialogIndirectParamW(
1593 HINSTANCE hInstance,
1594 LPCDLGTEMPLATE lpTemplate,
1595 HWND hWndParent,
1596 DLGPROC lpDialogFunc,
1597 LPARAM lParamInit)
1598 {
1599 return CreateDialogIndirectParamAorW( hInstance, lpTemplate, hWndParent, lpDialogFunc, lParamInit, 0);
1600 }
1601
1602
1603 /*
1604 * @implemented
1605 */
1606 HWND
1607 WINAPI
1608 CreateDialogParamA(
1609 HINSTANCE hInstance,
1610 LPCSTR lpTemplateName,
1611 HWND hWndParent,
1612 DLGPROC lpDialogFunc,
1613 LPARAM dwInitParam)
1614 {
1615 HRSRC hrsrc;
1616 LPCDLGTEMPLATE ptr;
1617
1618 if (!(hrsrc = FindResourceA( hInstance, lpTemplateName, (LPCSTR)RT_DIALOG ))) return 0;
1619 if (!(ptr = (LPCDLGTEMPLATE)LoadResource(hInstance, hrsrc))) return 0;
1620 return CreateDialogIndirectParamA( hInstance, ptr, hWndParent, lpDialogFunc, dwInitParam );
1621 }
1622
1623
1624 /*
1625 * @implemented
1626 */
1627 HWND
1628 WINAPI
1629 CreateDialogParamW(
1630 HINSTANCE hInstance,
1631 LPCWSTR lpTemplateName,
1632 HWND hWndParent,
1633 DLGPROC lpDialogFunc,
1634 LPARAM dwInitParam)
1635 {
1636 HRSRC hrsrc;
1637 LPCDLGTEMPLATE ptr;
1638
1639 if (!(hrsrc = FindResourceW( hInstance, lpTemplateName, (LPCWSTR)RT_DIALOG ))) return 0;
1640 if (!(ptr = (LPCDLGTEMPLATE)LoadResource(hInstance, hrsrc))) return 0;
1641 return CreateDialogIndirectParamW( hInstance, ptr, hWndParent, lpDialogFunc, dwInitParam );
1642 }
1643
1644
1645 /*
1646 * @implemented
1647 */
1648 LRESULT
1649 WINAPI
1650 DefDlgProcA(
1651 HWND hDlg,
1652 UINT Msg,
1653 WPARAM wParam,
1654 LPARAM lParam)
1655 {
1656 DIALOGINFO *dlgInfo;
1657 WNDPROC dlgproc;
1658 BOOL result = FALSE;
1659
1660 /* Perform DIALOGINFO initialization if not done */
1661 if(!(dlgInfo = DIALOG_get_info( hDlg, TRUE ))) return 0; //// REACTOS : Always TRUE! See RealGetWindowClass.
1662
1663 SetWindowLongPtrW( hDlg, DWLP_MSGRESULT, 0 );
1664
1665 if ((dlgproc = (WNDPROC)GetWindowLongPtrW( hDlg, DWLP_DLGPROC )))
1666 {
1667 /* Call dialog procedure */
1668 result = CallWindowProcA( dlgproc, hDlg, Msg, wParam, lParam );
1669 }
1670
1671 if (!result && IsWindow(hDlg))
1672 {
1673 /* callback didn't process this message */
1674
1675 switch(Msg)
1676 {
1677 case WM_ERASEBKGND:
1678 case WM_SHOWWINDOW:
1679 case WM_ACTIVATE:
1680 case WM_SETFOCUS:
1681 case DM_SETDEFID:
1682 case DM_GETDEFID:
1683 case WM_NEXTDLGCTL:
1684 case WM_GETFONT:
1685 case WM_CLOSE:
1686 case WM_NCDESTROY:
1687 case WM_ENTERMENULOOP:
1688 case WM_LBUTTONDOWN:
1689 case WM_NCLBUTTONDOWN:
1690 return DEFDLG_Proc( hDlg, Msg, wParam, lParam, dlgInfo );
1691 case WM_INITDIALOG:
1692 case WM_VKEYTOITEM:
1693 case WM_COMPAREITEM:
1694 case WM_CHARTOITEM:
1695 break;
1696
1697 default:
1698 return DefWindowProcA( hDlg, Msg, wParam, lParam );
1699 }
1700 }
1701 return DEFDLG_Epilog(hDlg, Msg, wParam, lParam, result, TRUE);
1702 }
1703
1704
1705 /*
1706 * @implemented
1707 */
1708 LRESULT
1709 WINAPI
1710 DefDlgProcW(
1711 HWND hDlg,
1712 UINT Msg,
1713 WPARAM wParam,
1714 LPARAM lParam)
1715 {
1716 DIALOGINFO *dlgInfo;
1717 WNDPROC dlgproc;
1718 BOOL result = FALSE;
1719
1720 /* Perform DIALOGINFO initialization if not done */
1721 if(!(dlgInfo = DIALOG_get_info( hDlg, TRUE ))) return 0; //// REACTOS : Always TRUE! See RealGetWindowClass.
1722
1723 SetWindowLongPtrW( hDlg, DWLP_MSGRESULT, 0 );
1724
1725 if ((dlgproc = (WNDPROC)GetWindowLongPtrW( hDlg, DWLP_DLGPROC )))
1726 {
1727 /* Call dialog procedure */
1728 result = CallWindowProcW( dlgproc, hDlg, Msg, wParam, lParam );
1729 }
1730
1731 if (!result && IsWindow(hDlg))
1732 {
1733 /* callback didn't process this message */
1734
1735 switch(Msg)
1736 {
1737 case WM_ERASEBKGND:
1738 case WM_SHOWWINDOW:
1739 case WM_ACTIVATE:
1740 case WM_SETFOCUS:
1741 case DM_SETDEFID:
1742 case DM_GETDEFID:
1743 case WM_NEXTDLGCTL:
1744 case WM_GETFONT:
1745 case WM_CLOSE:
1746 case WM_NCDESTROY:
1747 case WM_ENTERMENULOOP:
1748 case WM_LBUTTONDOWN:
1749 case WM_NCLBUTTONDOWN:
1750 return DEFDLG_Proc( hDlg, Msg, wParam, lParam, dlgInfo );
1751 case WM_INITDIALOG:
1752 case WM_VKEYTOITEM:
1753 case WM_COMPAREITEM:
1754 case WM_CHARTOITEM:
1755 break;
1756
1757 default:
1758 return DefWindowProcW( hDlg, Msg, wParam, lParam );
1759 }
1760 }
1761 return DEFDLG_Epilog(hDlg, Msg, wParam, lParam, result, FALSE);
1762 }
1763
1764
1765 /*
1766 * @implemented
1767 */
1768 INT_PTR
1769 WINAPI
1770 DialogBoxIndirectParamAorW(
1771 HINSTANCE hInstance,
1772 LPCDLGTEMPLATE hDialogTemplate,
1773 HWND hWndParent,
1774 DLGPROC lpDialogFunc,
1775 LPARAM dwInitParam,
1776 DWORD Flags)
1777 {
1778 /* FIXME:
1779 * This function might be obsolete since I don't think it is exported by NT
1780 * Also wine has one more parameter identifying weather it should call
1781 * the function with unicode or not
1782 */
1783 HWND hWnd = DIALOG_CreateIndirect( hInstance, hDialogTemplate, hWndParent, lpDialogFunc, dwInitParam, Flags == DLG_ISANSI ? FALSE : TRUE, &hWndParent );
1784 if (hWnd) return DIALOG_DoDialogBox( hWnd, hWndParent );
1785 return -1;
1786 }
1787
1788
1789 /*
1790 * @implemented
1791 */
1792 INT_PTR
1793 WINAPI
1794 DialogBoxIndirectParamA(
1795 HINSTANCE hInstance,
1796 LPCDLGTEMPLATE hDialogTemplate,
1797 HWND hWndParent,
1798 DLGPROC lpDialogFunc,
1799 LPARAM dwInitParam)
1800 {
1801 return DialogBoxIndirectParamAorW( hInstance, hDialogTemplate, hWndParent, lpDialogFunc, dwInitParam, DLG_ISANSI);
1802 }
1803
1804
1805 /*
1806 * @implemented
1807 */
1808 INT_PTR
1809 WINAPI
1810 DialogBoxIndirectParamW(
1811 HINSTANCE hInstance,
1812 LPCDLGTEMPLATE hDialogTemplate,
1813 HWND hWndParent,
1814 DLGPROC lpDialogFunc,
1815 LPARAM dwInitParam)
1816 {
1817 return DialogBoxIndirectParamAorW( hInstance, hDialogTemplate, hWndParent, lpDialogFunc, dwInitParam, 0);
1818 }
1819
1820
1821 /*
1822 * @implemented
1823 */
1824 INT_PTR
1825 WINAPI
1826 DialogBoxParamA(
1827 HINSTANCE hInstance,
1828 LPCSTR lpTemplateName,
1829 HWND hWndParent,
1830 DLGPROC lpDialogFunc,
1831 LPARAM dwInitParam)
1832 {
1833 HWND hwnd;
1834 HRSRC hrsrc;
1835 LPCDLGTEMPLATE ptr;
1836 //// ReactOS rev 33532
1837 if (!(hrsrc = FindResourceA( hInstance, lpTemplateName, (LPCSTR)RT_DIALOG )) ||
1838 !(ptr = LoadResource(hInstance, hrsrc)))
1839 {
1840 SetLastError(ERROR_RESOURCE_NAME_NOT_FOUND);
1841 return -1;
1842 }
1843 if (hWndParent != NULL && !IsWindow(hWndParent))
1844 {
1845 SetLastError(ERROR_INVALID_WINDOW_HANDLE);
1846 return 0;
1847 }
1848 hwnd = DIALOG_CreateIndirect(hInstance, ptr, hWndParent, lpDialogFunc, dwInitParam, FALSE, &hWndParent );
1849 if (hwnd) return DIALOG_DoDialogBox(hwnd, hWndParent);
1850 return -1;
1851 }
1852
1853
1854 /*
1855 * @implemented
1856 */
1857 INT_PTR
1858 WINAPI
1859 DialogBoxParamW(
1860 HINSTANCE hInstance,
1861 LPCWSTR lpTemplateName,
1862 HWND hWndParent,
1863 DLGPROC lpDialogFunc,
1864 LPARAM dwInitParam)
1865 {
1866 HWND hwnd;
1867 HRSRC hrsrc;
1868 LPCDLGTEMPLATE ptr;
1869 //// ReactOS rev 33532
1870 if (!(hrsrc = FindResourceW( hInstance, lpTemplateName, (LPCWSTR)RT_DIALOG )) ||
1871 !(ptr = LoadResource(hInstance, hrsrc)))
1872 {
1873 SetLastError(ERROR_RESOURCE_NAME_NOT_FOUND);
1874 return -1;
1875 }
1876 if (hWndParent != NULL && !IsWindow(hWndParent))
1877 {
1878 SetLastError(ERROR_INVALID_WINDOW_HANDLE);
1879 return 0;
1880 }
1881 hwnd = DIALOG_CreateIndirect(hInstance, ptr, hWndParent, lpDialogFunc, dwInitParam, TRUE, &hWndParent );
1882 if (hwnd) return DIALOG_DoDialogBox(hwnd, hWndParent);
1883 return -1;
1884 }
1885
1886
1887 /*
1888 * @implemented
1889 */
1890 int
1891 WINAPI
1892 DlgDirListA(
1893 HWND hDlg,
1894 LPSTR lpPathSpec,
1895 int nIDListBox,
1896 int nIDStaticPath,
1897 UINT uFileType)
1898 {
1899 return DIALOG_DlgDirListA( hDlg, lpPathSpec, nIDListBox, nIDStaticPath, uFileType, FALSE );
1900 }
1901
1902
1903 /*
1904 * @implemented
1905 */
1906 int
1907 WINAPI
1908 DlgDirListComboBoxA(
1909 HWND hDlg,
1910 LPSTR lpPathSpec,
1911 int nIDComboBox,
1912 int nIDStaticPath,
1913 UINT uFiletype)
1914 {
1915 return DIALOG_DlgDirListA( hDlg, lpPathSpec, nIDComboBox, nIDStaticPath, uFiletype, TRUE );
1916 }
1917
1918
1919 /*
1920 * @implemented
1921 */
1922 int
1923 WINAPI
1924 DlgDirListComboBoxW(
1925 HWND hDlg,
1926 LPWSTR lpPathSpec,
1927 int nIDComboBox,
1928 int nIDStaticPath,
1929 UINT uFiletype)
1930 {
1931 return DIALOG_DlgDirListW( hDlg, lpPathSpec, nIDComboBox, nIDStaticPath, uFiletype, TRUE );
1932 }
1933
1934
1935 /*
1936 * @implemented
1937 */
1938 int
1939 WINAPI
1940 DlgDirListW(
1941 HWND hDlg,
1942 LPWSTR lpPathSpec,
1943 int nIDListBox,
1944 int nIDStaticPath,
1945 UINT uFileType)
1946 {
1947 return DIALOG_DlgDirListW( hDlg, lpPathSpec, nIDListBox, nIDStaticPath, uFileType, FALSE );
1948 }
1949
1950
1951 /*
1952 * @implemented
1953 */
1954 BOOL
1955 WINAPI
1956 DlgDirSelectComboBoxExA(
1957 HWND hDlg,
1958 LPSTR lpString,
1959 int nCount,
1960 int nIDComboBox)
1961 {
1962 return DIALOG_DlgDirSelect( hDlg, (LPWSTR)lpString, nCount, nIDComboBox, FALSE, TRUE );
1963 }
1964
1965
1966 /*
1967 * @implemented
1968 */
1969 BOOL
1970 WINAPI
1971 DlgDirSelectComboBoxExW(
1972 HWND hDlg,
1973 LPWSTR lpString,
1974 int nCount,
1975 int nIDComboBox)
1976 {
1977 return DIALOG_DlgDirSelect( hDlg, (LPWSTR)lpString, nCount, nIDComboBox, TRUE, TRUE );
1978 }
1979
1980
1981 /*
1982 * @implemented
1983 */
1984 BOOL
1985 WINAPI
1986 DlgDirSelectExA(
1987 HWND hDlg,
1988 LPSTR lpString,
1989 int nCount,
1990 int nIDListBox)
1991 {
1992 return DIALOG_DlgDirSelect( hDlg, (LPWSTR)lpString, nCount, nIDListBox, FALSE, FALSE );
1993 }
1994
1995
1996 /*
1997 * @implemented
1998 */
1999 BOOL
2000 WINAPI
2001 DlgDirSelectExW(
2002 HWND hDlg,
2003 LPWSTR lpString,
2004 int nCount,
2005 int nIDListBox)
2006 {
2007 return DIALOG_DlgDirSelect( hDlg, lpString, nCount, nIDListBox, TRUE, FALSE );
2008 }
2009
2010
2011 /*
2012 * @implemented Modified for ReactOS. Do not Port Sync!!!
2013 */
2014 BOOL
2015 WINAPI
2016 EndDialog(
2017 HWND hwnd,
2018 INT_PTR retval)
2019 {
2020 DIALOGINFO * dlgInfo;
2021 HWND owner;
2022 BOOL wasActive;
2023
2024 TRACE("%p %ld\n", hwnd, retval );
2025
2026 if (!(dlgInfo = GETDLGINFO(hwnd)))
2027 {
2028 ERR("got invalid window handle (%p); buggy app !?\n", hwnd);
2029 return FALSE;
2030 }
2031 wasActive = (hwnd == GetActiveWindow());
2032 dlgInfo->idResult = retval;
2033 dlgInfo->flags |= DF_END;
2034
2035 if ((GetWindowLongW( hwnd, GWL_STYLE ) & (WS_POPUP|WS_CHILD)) == WS_CHILD)
2036 {
2037 owner = GetAncestor( hwnd, GA_PARENT);
2038 }
2039 else
2040 owner = GetWindow( hwnd, GW_OWNER );
2041
2042 if (owner)
2043 EnableWindow( owner, TRUE );
2044
2045 /* Windows sets the focus to the dialog itself in EndDialog */
2046
2047 if (wasActive && IsChild(hwnd, GetFocus()))
2048 SetFocus( hwnd );
2049
2050 /* Don't have to send a ShowWindow(SW_HIDE), just do
2051 SetWindowPos with SWP_HIDEWINDOW as done in Windows */
2052
2053 SetWindowPos(hwnd, NULL, 0, 0, 0, 0, SWP_NOMOVE | SWP_NOSIZE
2054 | SWP_NOZORDER | SWP_NOACTIVATE | SWP_HIDEWINDOW);
2055
2056 if (wasActive && owner)
2057 {
2058 /* If this dialog was given an owner then set the focus to that owner. */
2059 SetActiveWindow(owner);
2060 }
2061 else if (hwnd == GetActiveWindow()) // Check it again!
2062 {
2063 NtUserCallNoParam(NOPARAM_ROUTINE_ZAPACTIVEANDFOUS);
2064 }
2065
2066 /* unblock dialog loop */
2067 PostMessageA(hwnd, WM_NULL, 0, 0);
2068 return TRUE;
2069 }
2070
2071
2072 /*
2073 * @implemented
2074 */
2075 LONG
2076 WINAPI
2077 GetDialogBaseUnits(VOID)
2078 {
2079 static DWORD units;
2080
2081 if (!units)
2082 {
2083 HDC hdc;
2084 SIZE size;
2085
2086 if ((hdc = GetDC(0)))
2087 {
2088 size.cx = GdiGetCharDimensions( hdc, NULL, &size.cy );
2089 if (size.cx) units = MAKELONG( size.cx, size.cy );
2090 ReleaseDC( 0, hdc );
2091 }
2092 }
2093 return units;
2094 }
2095
2096
2097 /*
2098 * @implemented
2099 */
2100 int
2101 WINAPI
2102 GetDlgCtrlID(
2103 HWND hwndCtl)
2104 {
2105 return GetWindowLongPtrW( hwndCtl, GWLP_ID );
2106 }
2107
2108
2109 /*
2110 * @implemented
2111 */
2112 HWND
2113 WINAPI
2114 GetDlgItem(
2115 HWND hDlg,
2116 int nIDDlgItem)
2117 {
2118 int i;
2119 HWND *list;
2120 HWND ret = 0;
2121
2122 if (!hDlg) return 0;
2123
2124 list = WIN_ListChildren(hDlg);
2125 if (!list) return 0;
2126
2127 for (i = 0; list[i]; i++) if (GetWindowLongPtrW(list[i], GWLP_ID) == nIDDlgItem) break;
2128 ret = list[i];
2129 HeapFree(GetProcessHeap(), 0, list);
2130 // if (!ret) SetLastError(ERROR_CONTROL_ID_NOT_FOUND);
2131 return ret;
2132 }
2133
2134
2135 /*
2136 * @implemented
2137 */
2138 UINT
2139 WINAPI
2140 GetDlgItemInt(
2141 HWND hDlg,
2142 int nIDDlgItem,
2143 BOOL *lpTranslated,
2144 BOOL bSigned)
2145 {
2146 char str[30];
2147 char * endptr;
2148 LONG_PTR result = 0;
2149
2150 if (lpTranslated) *lpTranslated = FALSE;
2151 if (!SendDlgItemMessageA(hDlg, nIDDlgItem, WM_GETTEXT, sizeof(str), (LPARAM)str))
2152 return 0;
2153 if (bSigned)
2154 {
2155 result = strtol( str, &endptr, 10 );
2156 if (!endptr || (endptr == str)) /* Conversion was unsuccessful */
2157 return 0;
2158 if (((result == LONG_MIN) || (result == LONG_MAX)))
2159 return 0;
2160 }
2161 else
2162 {
2163 result = strtoul( str, &endptr, 10 );
2164 if (!endptr || (endptr == str)) /* Conversion was unsuccessful */
2165 return 0;
2166 if (result == ULONG_MAX) return 0;
2167 }
2168 if (lpTranslated) *lpTranslated = TRUE;
2169 return (UINT)result;
2170 }
2171
2172
2173 /*
2174 * @implemented
2175 */
2176 UINT
2177 WINAPI
2178 GetDlgItemTextA(
2179 HWND hDlg,
2180 int nIDDlgItem,
2181 LPSTR lpString,
2182 int nMaxCount)
2183 {
2184 HWND hWnd = GetDlgItem(hDlg, nIDDlgItem);
2185 if ( hWnd ) return GetWindowTextA(hWnd, lpString, nMaxCount);
2186 if ( nMaxCount ) lpString[0] = '\0';
2187 return 0;
2188 }
2189
2190
2191 /*
2192 * @implemented
2193 */
2194 UINT
2195 WINAPI
2196 GetDlgItemTextW(
2197 HWND hDlg,
2198 int nIDDlgItem,
2199 LPWSTR lpString,
2200 int nMaxCount)
2201 {
2202 HWND hWnd = GetDlgItem(hDlg, nIDDlgItem);
2203 if ( hWnd ) return GetWindowTextW(hWnd, lpString, nMaxCount);
2204 if ( nMaxCount ) lpString[0] = '\0';
2205 return 0;
2206 }
2207
2208 /*
2209 * @implemented
2210 */
2211 HWND
2212 WINAPI
2213 GetNextDlgGroupItem(
2214 HWND hDlg,
2215 HWND hCtl,
2216 BOOL bPrevious)
2217 {
2218 HWND hwnd, hwndNext, retvalue, hwndLastGroup = 0;
2219 BOOL fLooped=FALSE;
2220 BOOL fSkipping=FALSE;
2221
2222 if (hDlg == hCtl) hCtl = NULL;
2223 if (!hCtl && bPrevious) return 0;
2224
2225 /* if the hwndCtrl is the child of the control in the hwndDlg,
2226 * then the hwndDlg has to be the parent of the hwndCtrl */
2227
2228 if (hCtl)
2229 {
2230 if (!IsChild (hDlg, hCtl)) return 0;
2231 /* Make sure hwndCtrl is a top-level child */
2232
2233 }
2234 else
2235 {
2236 /* No ctrl specified -> start from the beginning */
2237 if (!(hCtl = GetWindow( hDlg, GW_CHILD ))) return 0;
2238 /* MSDN is wrong. fPrevious does not result in the last child */
2239
2240 /* No ctrl specified -> start from the beginning */
2241 if (!(hCtl = GetWindow( hDlg, GW_CHILD ))) return 0;
2242
2243 /* MSDN is wrong. fPrevious does not result in the last child */
2244
2245 /* Maybe that first one is valid. If so then we don't want to skip it*/
2246 if ((GetWindowLongPtrW( hCtl, GWL_STYLE ) & (WS_VISIBLE|WS_DISABLED)) == WS_VISIBLE)
2247 {
2248 return hCtl;
2249 }
2250
2251 }
2252
2253 /* Always go forward around the group and list of controls; for the
2254 * previous control keep track; for the next break when you find one
2255 */
2256 retvalue = hCtl;
2257 hwnd = hCtl;
2258 while (hwndNext = GetWindow (hwnd, GW_HWNDNEXT),
2259 1)
2260 {
2261 while (!hwndNext)
2262 {
2263 /* Climb out until there is a next sibling of the ancestor or we
2264 * reach the top (in which case we loop back to the start)
2265 */
2266 if (hDlg == GetParent (hwnd))
2267 {
2268 /* Wrap around to the beginning of the list, within the same
2269 * group. (Once only)
2270 */
2271 if (fLooped) goto end;
2272 fLooped = TRUE;
2273 hwndNext = GetWindow (hDlg, GW_CHILD);
2274 }
2275 else
2276 {
2277 hwnd = GetParent (hwnd);
2278 hwndNext = GetWindow (hwnd, GW_HWNDNEXT);
2279 }
2280 }
2281 hwnd = hwndNext;
2282
2283 /* Wander down the leading edge of controlparents */
2284 while ( (GetWindowLongPtrW (hwnd, GWL_EXSTYLE) & WS_EX_CONTROLPARENT) &&
2285 ((GetWindowLongPtrW (hwnd, GWL_STYLE) & (WS_VISIBLE | WS_DISABLED)) == WS_VISIBLE) &&
2286 (hwndNext = GetWindow (hwnd, GW_CHILD)))
2287 hwnd = hwndNext;
2288 /* Question. If the control is a control parent but either has no
2289 * children or is not visible/enabled then if it has a WS_GROUP does
2290 * it count? For that matter does it count anyway?
2291 * I believe it doesn't count.
2292 */
2293
2294 if ((GetWindowLongPtrW (hwnd, GWL_STYLE) & WS_GROUP))
2295 {
2296 hwndLastGroup = hwnd;
2297 if (!fSkipping)
2298 {
2299 /* Look for the beginning of the group */
2300 fSkipping = TRUE;
2301 }
2302 }
2303
2304 if (hwnd == hCtl)
2305 {
2306 if (!fSkipping) break;
2307 if (hwndLastGroup == hwnd) break;
2308 hwnd = hwndLastGroup;
2309 fSkipping = FALSE;
2310 fLooped = FALSE;
2311 }
2312
2313 if (!fSkipping &&
2314 (GetWindowLongPtrW (hwnd, GWL_STYLE) & (WS_VISIBLE|WS_DISABLED)) ==
2315 WS_VISIBLE)
2316 {
2317 retvalue = hwnd;
2318 if (!bPrevious) break;
2319 }
2320 }
2321 end:
2322 return retvalue;
2323 }
2324
2325
2326 /*
2327 * @implemented
2328 */
2329 HWND
2330 WINAPI
2331 GetNextDlgTabItem(
2332 HWND hDlg,
2333 HWND hCtl,
2334 BOOL bPrevious)
2335 {
2336 PWND pWindow;
2337
2338 pWindow = ValidateHwnd( hDlg );
2339 if (!pWindow) return NULL;
2340 if (hCtl)
2341 {
2342 pWindow = ValidateHwnd( hCtl );
2343 if (!pWindow) return NULL;
2344 }
2345
2346 /* Undocumented but tested under Win2000 and WinME */
2347 if (hDlg == hCtl) hCtl = NULL;
2348
2349 /* Contrary to MSDN documentation, tested under Win2000 and WinME
2350 * NB GetLastError returns whatever was set before the function was
2351 * called.
2352 */
2353 if (!hCtl && bPrevious) return 0;
2354
2355 return DIALOG_GetNextTabItem(hDlg, hDlg, hCtl, bPrevious);
2356 }
2357
2358
2359 #if 0
2360 BOOL
2361 WINAPI
2362 IsDialogMessage(
2363 HWND hDlg,
2364 LPMSG lpMsg)
2365 {
2366 return IsDialogMessageW(hDlg, lpMsg);
2367 }
2368 #endif
2369
2370 /***********************************************************************
2371 * DIALOG_FixOneChildOnChangeFocus
2372 *
2373 * Callback helper for DIALOG_FixChildrenOnChangeFocus
2374 */
2375
2376 static BOOL CALLBACK DIALOG_FixOneChildOnChangeFocus (HWND hwndChild,
2377 LPARAM lParam)
2378 {
2379 /* If a default pushbutton then no longer default */
2380 if (DLGC_DEFPUSHBUTTON & SendMessageW (hwndChild, WM_GETDLGCODE, 0, 0))
2381 SendMessageW (hwndChild, BM_SETSTYLE, BS_PUSHBUTTON, TRUE);
2382 return TRUE;
2383 }
2384
2385 /***********************************************************************
2386 * DIALOG_FixChildrenOnChangeFocus
2387 *
2388 * Following the change of focus that occurs for example after handling
2389 * a WM_KEYDOWN VK_TAB in IsDialogMessage, some tidying of the dialog's
2390 * children may be required.
2391 */
2392 static void DIALOG_FixChildrenOnChangeFocus (HWND hwndDlg, HWND hwndNext)
2393 {
2394 INT dlgcode_next = SendMessageW (hwndNext, WM_GETDLGCODE, 0, 0);
2395 /* INT dlgcode_dlg = SendMessageW (hwndDlg, WM_GETDLGCODE, 0, 0); */
2396 /* Windows does ask for this. I don't know why yet */
2397
2398 EnumChildWindows (hwndDlg, DIALOG_FixOneChildOnChangeFocus, 0);
2399
2400 /* If the button that is getting the focus WAS flagged as the default
2401 * pushbutton then ask the dialog what it thinks the default is and
2402 * set that in the default style.
2403 */
2404 if (dlgcode_next & DLGC_DEFPUSHBUTTON)
2405 {
2406 DWORD def_id = SendMessageW (hwndDlg, DM_GETDEFID, 0, 0);
2407 if (HIWORD(def_id) == DC_HASDEFID)
2408 {
2409 HWND hwndDef;
2410 def_id = LOWORD(def_id);
2411 hwndDef = GetDlgItem (hwndDlg, def_id);
2412 if (hwndDef)
2413 {
2414 INT dlgcode_def = SendMessageW (hwndDef, WM_GETDLGCODE, 0, 0);
2415 /* I know that if it is a button then it should already be a
2416 * UNDEFPUSHBUTTON, since we have just told the buttons to
2417 * change style. But maybe they ignored our request
2418 */
2419 if ((dlgcode_def & DLGC_BUTTON) &&
2420 (dlgcode_def & DLGC_UNDEFPUSHBUTTON))
2421 {
2422 SendMessageW (hwndDef, BM_SETSTYLE, BS_DEFPUSHBUTTON, TRUE);
2423 }
2424 }
2425 }
2426 }
2427 else if ((dlgcode_next & DLGC_BUTTON) && (dlgcode_next & DLGC_UNDEFPUSHBUTTON))
2428 {
2429 SendMessageW (hwndNext, BM_SETSTYLE, BS_DEFPUSHBUTTON, TRUE);
2430 /* I wonder why it doesn't send a DM_SETDEFID */
2431 }
2432 }
2433
2434 /***********************************************************************
2435 * DIALOG_IdToHwnd
2436 *
2437 * A recursive version of GetDlgItem
2438 *
2439 * RETURNS
2440 * The HWND for a Child ID.
2441 */
2442 static HWND DIALOG_IdToHwnd( HWND hwndDlg, INT id )
2443 {
2444 int i;
2445 HWND *list = WIN_ListChildren( hwndDlg );
2446 HWND ret = 0;
2447
2448 if (!list) return 0;
2449
2450 for (i = 0; list[i]; i++)
2451 {
2452 if (GetWindowLongPtrW( list[i], GWLP_ID ) == id)
2453 {
2454 ret = list[i];
2455 break;
2456 }
2457
2458 /* Recurse into every child */
2459 if ((ret = DIALOG_IdToHwnd( list[i], id ))) break;
2460 }
2461
2462 HeapFree( GetProcessHeap(), 0, list );
2463 return ret;
2464 }
2465
2466
2467 /*
2468 * @implemented
2469 */
2470 BOOL
2471 WINAPI
2472 IsDialogMessageW(
2473 HWND hDlg,
2474 LPMSG lpMsg)
2475 {
2476 INT dlgCode = 0;
2477
2478 if (!IsWindow( hDlg ))
2479 return FALSE;
2480
2481 if (CallMsgFilterW( lpMsg, MSGF_DIALOGBOX )) return TRUE;
2482
2483 if (hDlg == GetDesktopWindow()) return FALSE;
2484 if ((hDlg != lpMsg->hwnd) && !IsChild( hDlg, lpMsg->hwnd )) return FALSE;
2485
2486 hDlg = DIALOG_FindMsgDestination(hDlg);
2487
2488 switch(lpMsg->message)
2489 {
2490 case WM_KEYDOWN:
2491 dlgCode = SendMessageW( lpMsg->hwnd, WM_GETDLGCODE, lpMsg->wParam, (LPARAM)lpMsg );
2492 if (dlgCode & DLGC_WANTMESSAGE) break;
2493
2494 switch(lpMsg->wParam)
2495 {
2496 case VK_TAB:
2497 if (!(dlgCode & DLGC_WANTTAB))
2498 {
2499 BOOL fIsDialog = TRUE;
2500 WND *pWnd = ValidateHwnd(hDlg);
2501
2502 if (pWnd && TestWindowProcess(pWnd))
2503 {
2504 fIsDialog = (GETDLGINFO(hDlg) != NULL);
2505 }
2506
2507 SendMessageW(hDlg, WM_CHANGEUISTATE, MAKEWPARAM(UIS_CLEAR, UISF_HIDEFOCUS), 0);
2508
2509 /* I am not sure under which circumstances the TAB is handled
2510 * each way. All I do know is that it does not always simply
2511 * send WM_NEXTDLGCTL. (Personally I have never yet seen it
2512 * do so but I presume someone has)
2513 */
2514 if (fIsDialog)
2515 SendMessageW( hDlg, WM_NEXTDLGCTL, (GetKeyState(VK_SHIFT) & 0x8000), 0 );
2516 else
2517 {
2518 /* It would appear that GetNextDlgTabItem can handle being
2519 * passed hwndDlg rather than NULL but that is undocumented
2520 * so let's do it properly
2521 */
2522 HWND hwndFocus = GetFocus();
2523 HWND hwndNext = GetNextDlgTabItem (hDlg,
2524 hwndFocus == hDlg ? NULL : hwndFocus,
2525 GetKeyState (VK_SHIFT) & 0x8000);
2526 if (hwndNext)
2527 {
2528 dlgCode = SendMessageW (hwndNext, WM_GETDLGCODE,
2529 lpMsg->wParam, (LPARAM)lpMsg);
2530 if (dlgCode & DLGC_HASSETSEL)
2531 {
2532 INT maxlen = 1 + SendMessageW (hwndNext, WM_GETTEXTLENGTH, 0, 0);
2533 WCHAR *buffer = HeapAlloc (GetProcessHeap(), 0, maxlen * sizeof(WCHAR));
2534 if (buffer)
2535 {
2536 INT length;
2537 SendMessageW (hwndNext, WM_GETTEXT, maxlen, (LPARAM) buffer);
2538 length = strlenW (buffer);
2539 HeapFree (GetProcessHeap(), 0, buffer);
2540 SendMessageW (hwndNext, EM_SETSEL, 0, length);
2541 }
2542 }
2543 SetFocus (hwndNext);
2544 DIALOG_FixChildrenOnChangeFocus (hDlg, hwndNext);
2545 }
2546 else
2547 return FALSE;
2548 }
2549 return TRUE;
2550 }
2551 break;
2552
2553 case VK_RIGHT:
2554 case VK_DOWN:
2555 case VK_LEFT:
2556 case VK_UP:
2557 if (!(dlgCode & DLGC_WANTARROWS))
2558 {
2559 BOOL fPrevious = (lpMsg->wParam == VK_LEFT || lpMsg->wParam == VK_UP);
2560 HWND hwndNext = GetNextDlgGroupItem (hDlg, GetFocus(), fPrevious );
2561 SendMessageW( hDlg, WM_NEXTDLGCTL, (WPARAM)hwndNext, 1 );
2562 return TRUE;
2563 }
2564 break;
2565
2566 case VK_CANCEL:
2567 case VK_ESCAPE:
2568 SendMessageW( hDlg, WM_COMMAND, IDCANCEL, (LPARAM)GetDlgItem( hDlg, IDCANCEL ) );
2569 return TRUE;
2570
2571 case VK_EXECUTE:
2572 case VK_RETURN:
2573 {
2574 DWORD dw;
2575 if ((GetFocus() == lpMsg->hwnd) &&
2576 (SendMessageW (lpMsg->hwnd, WM_GETDLGCODE, 0, 0) & DLGC_DEFPUSHBUTTON))
2577 {
2578 SendMessageW (hDlg, WM_COMMAND, MAKEWPARAM (GetDlgCtrlID(lpMsg->hwnd),BN_CLICKED), (LPARAM)lpMsg->hwnd);
2579 }
2580 else if (DC_HASDEFID == HIWORD(dw = SendMessageW (hDlg, DM_GETDEFID, 0, 0)))
2581 {
2582 HWND hwndDef = DIALOG_IdToHwnd(hDlg, LOWORD(dw));
2583 if (!hwndDef || IsWindowEnabled(hwndDef))
2584 SendMessageW( hDlg, WM_COMMAND, MAKEWPARAM( LOWORD(dw), BN_CLICKED ), (LPARAM)hwndDef);
2585 }
2586 else
2587 {
2588 SendMessageW( hDlg, WM_COMMAND, IDOK, (LPARAM)GetDlgItem( hDlg, IDOK ) );
2589
2590 }
2591 }
2592 return TRUE;
2593 }
2594 break;
2595
2596 case WM_CHAR:
2597 /* FIXME Under what circumstances does WM_GETDLGCODE get sent?
2598 * It does NOT get sent in the test program I have
2599 */
2600 dlgCode = SendMessageW( lpMsg->hwnd, WM_GETDLGCODE, lpMsg->wParam, (LPARAM)lpMsg );
2601 if (dlgCode & (DLGC_WANTCHARS|DLGC_WANTMESSAGE)) break;
2602 if (lpMsg->wParam == '\t' && (dlgCode & DLGC_WANTTAB)) break;
2603 /* drop through */
2604
2605 case WM_SYSCHAR:
2606 if (DIALOG_IsAccelerator( lpMsg->hwnd, hDlg, lpMsg->wParam ))
2607 {
2608 /* don't translate or dispatch */
2609 return TRUE;
2610 }
2611 break;
2612 //// ReactOS
2613 case WM_SYSKEYDOWN:
2614 /* If the ALT key is being pressed display the keyboard cues */
2615 if ( HIWORD(lpMsg->lParam) & KF_ALTDOWN &&
2616 !(gpsi->dwSRVIFlags & SRVINFO_KBDPREF) && !(gpsi->PUSIFlags & PUSIF_KEYBOARDCUES) )
2617 SendMessageW(hDlg, WM_CHANGEUISTATE, MAKEWPARAM(UIS_CLEAR, UISF_HIDEACCEL | UISF_HIDEFOCUS), 0);
2618 break;
2619
2620 case WM_SYSCOMMAND:
2621 /* If the ALT key is being pressed display the keyboard cues */
2622 if ( lpMsg->wParam == SC_KEYMENU &&
2623 !(gpsi->dwSRVIFlags & SRVINFO_KBDPREF) && !(gpsi->PUSIFlags & PUSIF_KEYBOARDCUES) )
2624 {
2625 SendMessageW(hDlg, WM_CHANGEUISTATE, MAKEWPARAM(UIS_CLEAR, UISF_HIDEACCEL | UISF_HIDEFOCUS), 0);
2626 }
2627 break;
2628 }
2629
2630 TranslateMessage( lpMsg );
2631 DispatchMessageW( lpMsg );
2632 return TRUE;
2633 }
2634
2635
2636 /*
2637 * @implemented
2638 */
2639 UINT
2640 WINAPI
2641 IsDlgButtonChecked(
2642 HWND hDlg,
2643 int nIDButton)
2644 {
2645 return (UINT)SendDlgItemMessageW( hDlg, nIDButton, BM_GETCHECK, 0, 0 );
2646 }
2647
2648
2649 /*
2650 * @implemented
2651 */
2652 BOOL
2653 WINAPI
2654 MapDialogRect(
2655 HWND hDlg,
2656 LPRECT lpRect)
2657 {
2658 DIALOGINFO * dlgInfo;
2659 if (!(dlgInfo = GETDLGINFO(hDlg))) return FALSE;
2660 lpRect->left = MulDiv(lpRect->left, dlgInfo->xBaseUnit, 4);
2661 lpRect->right = MulDiv(lpRect->right, dlgInfo->xBaseUnit, 4);
2662 lpRect->top = MulDiv(lpRect->top, dlgInfo->yBaseUnit, 8);
2663 lpRect->bottom = MulDiv(lpRect->bottom, dlgInfo->yBaseUnit, 8);
2664 return TRUE;
2665 }
2666
2667
2668 /*
2669 * @implemented
2670 */
2671 LRESULT
2672 WINAPI
2673 SendDlgItemMessageA(
2674 HWND hDlg,
2675 int nIDDlgItem,
2676 UINT Msg,
2677 WPARAM wParam,
2678 LPARAM lParam)
2679 {
2680 HWND hwndCtrl;
2681 if ( hDlg == HWND_TOPMOST || hDlg == HWND_BROADCAST ) return 0; // ReactOS
2682 hwndCtrl = GetDlgItem( hDlg, nIDDlgItem );
2683 if (hwndCtrl) return SendMessageA( hwndCtrl, Msg, wParam, lParam );
2684 else return 0;
2685 }
2686
2687
2688 /*
2689 * @implemented
2690 */
2691 LRESULT
2692 WINAPI
2693 SendDlgItemMessageW(
2694 HWND hDlg,
2695 int nIDDlgItem,
2696 UINT Msg,
2697 WPARAM wParam,
2698 LPARAM lParam)
2699 {
2700 HWND hwndCtrl;
2701 if ( hDlg == HWND_TOPMOST || hDlg == HWND_BROADCAST ) return 0; // ReactOS
2702 hwndCtrl = GetDlgItem( hDlg, nIDDlgItem );
2703 if (hwndCtrl) return SendMessageW( hwndCtrl, Msg, wParam, lParam );
2704 else return 0;
2705 }
2706
2707
2708 /*
2709 * @implemented
2710 */
2711 BOOL
2712 WINAPI
2713 SetDlgItemInt(
2714 HWND hDlg,
2715 int nIDDlgItem,
2716 UINT uValue,
2717 BOOL bSigned)
2718 {
2719 char str[20];
2720
2721 if (bSigned) sprintf( str, "%d", (INT)uValue );
2722 else sprintf( str, "%u", uValue );
2723 SendDlgItemMessageA( hDlg, nIDDlgItem, WM_SETTEXT, 0, (LPARAM)str );
2724 return TRUE;
2725 }
2726
2727
2728 /*
2729 * @implemented
2730 */
2731 BOOL
2732 WINAPI
2733 SetDlgItemTextA(
2734 HWND hDlg,
2735 int nIDDlgItem,
2736 LPCSTR lpString)
2737 {
2738 HWND hwndCtrl = GetDlgItem( hDlg, nIDDlgItem ); // ReactOS Themes
2739 if (hwndCtrl) return SetWindowTextA( hwndCtrl, lpString );
2740 return FALSE;
2741 }
2742
2743
2744 /*
2745 * @implemented
2746 */
2747 BOOL
2748 WINAPI
2749 SetDlgItemTextW(
2750 HWND hDlg,
2751 int nIDDlgItem,
2752 LPCWSTR lpString)
2753 {
2754 HWND hwndCtrl = GetDlgItem( hDlg, nIDDlgItem ); // ReactOS Themes
2755 if (hwndCtrl) return SetWindowTextW( hwndCtrl, lpString );
2756 return FALSE;
2757 }
2758
2759
2760 /*
2761 * @implemented
2762 */
2763 BOOL
2764 WINAPI
2765 CheckDlgButton(
2766 HWND hDlg,
2767 int nIDButton,
2768 UINT uCheck)
2769 {
2770 SendDlgItemMessageW( hDlg, nIDButton, BM_SETCHECK, uCheck, 0 );
2771 return TRUE;
2772 }
2773
2774 static BOOL CALLBACK CheckRB(HWND hwnd, LPARAM lParam)
2775 {
2776 LONG lChildID = GetWindowLongPtrW(hwnd, GWLP_ID);
2777 RADIOGROUP *lpRadioGroup = (RADIOGROUP *)lParam;
2778
2779 if((lChildID >= lpRadioGroup->firstID) &&
2780 (lChildID <= lpRadioGroup->lastID))
2781 {
2782 if (lChildID == lpRadioGroup->checkID)
2783 {
2784 SendMessageW(hwnd, BM_SETCHECK, BST_CHECKED, 0);
2785 }
2786 else
2787 {
2788 SendMessageW(hwnd, BM_SETCHECK, BST_UNCHECKED, 0);
2789 }
2790 }
2791
2792 return TRUE;
2793 }
2794
2795 /*
2796 * @implemented
2797 */
2798 BOOL
2799 WINAPI
2800 CheckRadioButton(
2801 HWND hDlg,
2802 int nIDFirstButton,
2803 int nIDLastButton,
2804 int nIDCheckButton)
2805 {
2806 RADIOGROUP radioGroup;
2807
2808 radioGroup.firstID = nIDFirstButton;
2809 radioGroup.lastID = nIDLastButton;
2810 radioGroup.checkID = nIDCheckButton;
2811
2812 return EnumChildWindows(hDlg, CheckRB, (LPARAM)&radioGroup);
2813 }