d706be743403e57446dfe4896db3a60f9f419c88
[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 rect.left = rect.top = 0;
851 rect.right = MulDiv(template.cx, xBaseUnit, 4);
852 rect.bottom = MulDiv(template.cy, yBaseUnit, 8);
853
854 if (template.style & DS_CONTROL)
855 template.style &= ~(WS_CAPTION|WS_SYSMENU);
856 template.style |= DS_3DLOOK;
857 if (template.style & DS_MODALFRAME)
858 template.exStyle |= WS_EX_DLGMODALFRAME;
859 if ((template.style & DS_CONTROL) || !(template.style & WS_CHILD))
860 template.exStyle |= WS_EX_CONTROLPARENT;
861 AdjustWindowRectEx( &rect, template.style, (hMenu != 0), template.exStyle );
862 pos.x = rect.left;
863 pos.y = rect.top;
864 size.cx = rect.right - rect.left;
865 size.cy = rect.bottom - rect.top;
866
867 if (template.x == CW_USEDEFAULT16)
868 {
869 pos.x = pos.y = CW_USEDEFAULT;
870 }
871 else
872 {
873 HMONITOR monitor = 0;
874 MONITORINFO mon_info;
875
876 mon_info.cbSize = sizeof(mon_info);
877 if (template.style & DS_CENTER)
878 {
879 monitor = MonitorFromWindow( owner ? owner : GetActiveWindow(), MONITOR_DEFAULTTOPRIMARY );
880 GetMonitorInfoW( monitor, &mon_info );
881 pos.x = (mon_info.rcWork.left + mon_info.rcWork.right - size.cx) / 2;
882 pos.y = (mon_info.rcWork.top + mon_info.rcWork.bottom - size.cy) / 2;
883 }
884 else if (template.style & DS_CENTERMOUSE)
885 {
886 GetCursorPos( &pos );
887 monitor = MonitorFromPoint( pos, MONITOR_DEFAULTTOPRIMARY );
888 GetMonitorInfoW( monitor, &mon_info );
889 }
890 else
891 {
892 pos.x += MulDiv(template.x, xBaseUnit, 4);
893 pos.y += MulDiv(template.y, yBaseUnit, 8);
894 //
895 // REACTOS : Need an owner to be passed!!!
896 //
897 if (!(template.style & (WS_CHILD|DS_ABSALIGN)) && owner ) ClientToScreen( owner, &pos );
898 }
899 if ( !(template.style & WS_CHILD) )
900 {
901 INT dX, dY;
902
903 /* try to fit it into the desktop */
904
905 if (!monitor)
906 {
907 SetRect( &rect, pos.x, pos.y, pos.x + size.cx, pos.y + size.cy );
908 monitor = MonitorFromRect( &rect, MONITOR_DEFAULTTOPRIMARY );
909 GetMonitorInfoW( monitor, &mon_info );
910 }
911 if ((dX = pos.x + size.cx + GetSystemMetrics(SM_CXDLGFRAME) - mon_info.rcWork.right) > 0)
912 pos.x -= dX;
913 if ((dY = pos.y + size.cy + GetSystemMetrics(SM_CYDLGFRAME) - mon_info.rcWork.bottom) > 0)
914 pos.y -= dY;
915 if( pos.x < mon_info.rcWork.left ) pos.x = mon_info.rcWork.left;
916 if( pos.y < mon_info.rcWork.top ) pos.y = mon_info.rcWork.top;
917 }
918 }
919
920 if (modal_owner && owner)
921 {
922 HWND parent = NULL;
923 /*
924 * Owner needs to be top level window. We need to duplicate the logic from server,
925 * because we need to disable it before creating dialog window. Note that we do that
926 * even if dialog has WS_CHILD, but only for modal dialogs, which matched what
927 * Windows does.
928 */
929
930 ////// Wine'ie babies need to fix your code!!!! CORE-11633
931 if ((GetWindowLongW( owner, GWL_STYLE ) & (WS_POPUP|WS_CHILD)) == WS_CHILD)
932 {
933 parent = owner;
934 while ((GetWindowLongW( parent, GWL_STYLE ) & (WS_POPUP|WS_CHILD)) == WS_CHILD)
935 {
936 parent = GetParent( owner );
937 if (!parent || parent == GetDesktopWindow())
938 {
939 parent = NULL;
940 break;
941 }
942 }
943 }
944 else
945 parent = GetAncestor( owner, GA_ROOT );
946
947 if (parent)
948 {
949 owner = parent;
950
951 if (IsWindowEnabled( owner ))
952 {
953 disabled_owner = owner;
954 EnableWindow( disabled_owner, FALSE );
955 }
956 }
957 *modal_owner = owner;
958 }
959
960 if (unicode)
961 {
962 hwnd = CreateWindowExW(template.exStyle, template.className, template.caption,
963 template.style & ~WS_VISIBLE, pos.x, pos.y, size.cx, size.cy,
964 owner, hMenu, hInst, NULL );
965 }
966 else
967 {
968 LPCSTR class = (LPCSTR)template.className;
969 LPCSTR caption = (LPCSTR)template.caption;
970 LPSTR class_tmp = NULL;
971 LPSTR caption_tmp = NULL;
972
973 if (!IS_INTRESOURCE(class))
974 {
975 DWORD len = WideCharToMultiByte( CP_ACP, 0, template.className, -1, NULL, 0, NULL, NULL );
976 class_tmp = HeapAlloc( GetProcessHeap(), 0, len );
977 WideCharToMultiByte( CP_ACP, 0, template.className, -1, class_tmp, len, NULL, NULL );
978 class = class_tmp;
979 }
980 if (!IS_INTRESOURCE(caption))
981 {
982 DWORD len = WideCharToMultiByte( CP_ACP, 0, template.caption, -1, NULL, 0, NULL, NULL );
983 caption_tmp = HeapAlloc( GetProcessHeap(), 0, len );
984 WideCharToMultiByte( CP_ACP, 0, template.caption, -1, caption_tmp, len, NULL, NULL );
985 caption = caption_tmp;
986 }
987 hwnd = CreateWindowExA(template.exStyle, class, caption,
988 template.style & ~WS_VISIBLE, pos.x, pos.y, size.cx, size.cy,
989 owner, hMenu, hInst, NULL );
990 HeapFree( GetProcessHeap(), 0, class_tmp );
991 HeapFree( GetProcessHeap(), 0, caption_tmp );
992 }
993
994 if (!hwnd)
995 {
996 if (hUserFont) DeleteObject( hUserFont );
997 if (hMenu) DestroyMenu( hMenu );
998 if (disabled_owner) EnableWindow( disabled_owner, TRUE );
999 return 0;
1000 }
1001
1002 /* moved this from the top of the method to here as DIALOGINFO structure
1003 will be valid only after WM_CREATE message has been handled in DefDlgProc
1004 All the members of the structure get filled here using temp variables */
1005 dlgInfo = DIALOG_get_info( hwnd, TRUE );
1006 // ReactOS
1007 if (dlgInfo == NULL)
1008 {
1009 if (hUserFont) DeleteObject( hUserFont );
1010 if (hMenu) DestroyMenu( hMenu );
1011 if (disabled_owner) EnableWindow( disabled_owner, TRUE );
1012 return 0;
1013 }
1014 //
1015 dlgInfo->hwndFocus = 0;
1016 dlgInfo->hUserFont = hUserFont;
1017 dlgInfo->hMenu = hMenu;
1018 dlgInfo->xBaseUnit = xBaseUnit;
1019 dlgInfo->yBaseUnit = yBaseUnit;
1020 dlgInfo->flags = flags;
1021
1022 if (template.helpId) SetWindowContextHelpId( hwnd, template.helpId );
1023
1024 if (unicode) SetWindowLongPtrW( hwnd, DWLP_DLGPROC, (ULONG_PTR)dlgProc );
1025 else SetWindowLongPtrA( hwnd, DWLP_DLGPROC, (ULONG_PTR)dlgProc );
1026
1027 if (dlgProc && dlgInfo->hUserFont)
1028 SendMessageW( hwnd, WM_SETFONT, (WPARAM)dlgInfo->hUserFont, 0 );
1029
1030 /* Create controls */
1031
1032 if (DIALOG_CreateControls32( hwnd, dlgTemplate, &template, hInst, unicode ))
1033 {
1034 /* Send initialisation messages and set focus */
1035
1036 if (dlgProc)
1037 {
1038 HWND focus = GetNextDlgTabItem( hwnd, 0, FALSE );
1039 if (!focus) focus = GetNextDlgGroupItem( hwnd, 0, FALSE );
1040 if (SendMessageW( hwnd, WM_INITDIALOG, (WPARAM)focus, param ) && IsWindow( hwnd ) &&
1041 ((~template.style & DS_CONTROL) || (template.style & WS_VISIBLE)))
1042 {
1043 /* By returning TRUE, app has requested a default focus assignment.
1044 * WM_INITDIALOG may have changed the tab order, so find the first
1045 * tabstop control again. */
1046 focus = GetNextDlgTabItem( hwnd, 0, FALSE );
1047 if (!focus) focus = GetNextDlgGroupItem( hwnd, 0, FALSE );
1048 if (focus)
1049 {
1050 if (SendMessageW( focus, WM_GETDLGCODE, 0, 0 ) & DLGC_HASSETSEL)
1051 SendMessageW( focus, EM_SETSEL, 0, MAXLONG );
1052 SetFocus( focus );
1053 }
1054 }
1055 //// ReactOS see 43396, Fixes setting focus on Open and Close dialogs to the FileName edit control in OpenOffice.
1056 //// This now breaks test_SaveRestoreFocus.
1057 //DEFDLG_SaveFocus( hwnd );
1058 ////
1059 }
1060 //// ReactOS Rev 30613 & 30644
1061 if (!(GetWindowLongPtrW( hwnd, GWL_STYLE ) & WS_CHILD))
1062 SendMessageW( hwnd, WM_CHANGEUISTATE, MAKEWPARAM(UIS_INITIALIZE, 0), 0);
1063 ////
1064 if (template.style & WS_VISIBLE && !(GetWindowLongPtrW( hwnd, GWL_STYLE ) & WS_VISIBLE))
1065 {
1066 ShowWindow( hwnd, SW_SHOWNORMAL ); /* SW_SHOW doesn't always work */
1067 UpdateWindow( hwnd );
1068 IntNotifyWinEvent(EVENT_SYSTEM_DIALOGSTART, hwnd, OBJID_WINDOW, CHILDID_SELF, 0);
1069 }
1070 return hwnd;
1071 }
1072 if (disabled_owner) EnableWindow( disabled_owner, TRUE );
1073 IntNotifyWinEvent(EVENT_SYSTEM_DIALOGEND, hwnd, OBJID_WINDOW, CHILDID_SELF, 0);
1074 if( IsWindow(hwnd) )
1075 {
1076 DestroyWindow( hwnd );
1077 //// ReactOS
1078 if (owner)
1079 { ERR("DIALOG_CreateIndirect 1\n");
1080 if ( NtUserGetThreadState(THREADSTATE_FOREGROUNDTHREAD) && // Rule #1.
1081 !NtUserQueryWindow(owner, QUERY_WINDOW_FOREGROUND) )
1082 { ERR("DIALOG_CreateIndirect SFW\n");
1083 SetForegroundWindow(owner);
1084 }
1085 }
1086 ////
1087 }
1088 return 0;
1089 }
1090
1091
1092 /***********************************************************************
1093 * DEFDLG_FindDefButton
1094 *
1095 * Find the current default push-button.
1096 */
1097 static HWND DEFDLG_FindDefButton( HWND hwndDlg )
1098 {
1099 HWND hwndChild, hwndTmp;
1100
1101 hwndChild = GetWindow( hwndDlg, GW_CHILD );
1102 while (hwndChild)
1103 {
1104 if (SendMessageW( hwndChild, WM_GETDLGCODE, 0, 0 ) & DLGC_DEFPUSHBUTTON)
1105 break;
1106
1107 /* Recurse into WS_EX_CONTROLPARENT controls */
1108 if (GetWindowLongPtrW( hwndChild, GWL_EXSTYLE ) & WS_EX_CONTROLPARENT)
1109 {
1110 LONG dsStyle = GetWindowLongPtrW( hwndChild, GWL_STYLE );
1111 if ((dsStyle & WS_VISIBLE) && !(dsStyle & WS_DISABLED) &&
1112 (hwndTmp = DEFDLG_FindDefButton(hwndChild)) != NULL)
1113 return hwndTmp;
1114 }
1115 hwndChild = GetWindow( hwndChild, GW_HWNDNEXT );
1116 }
1117 return hwndChild;
1118 }
1119
1120
1121 /***********************************************************************
1122 * DEFDLG_SetDefId
1123 *
1124 * Set the default button id.
1125 */
1126 static BOOL DEFDLG_SetDefId( HWND hwndDlg, DIALOGINFO *dlgInfo, WPARAM wParam)
1127 {
1128 DWORD dlgcode=0; /* initialize just to avoid a warning */
1129 HWND hwndOld, hwndNew = GetDlgItem(hwndDlg, wParam);
1130 INT old_id = dlgInfo->idResult;
1131
1132 dlgInfo->idResult = wParam;
1133 if (hwndNew &&
1134 !((dlgcode=SendMessageW(hwndNew, WM_GETDLGCODE, 0, 0 ))
1135 & (DLGC_UNDEFPUSHBUTTON | DLGC_BUTTON)))
1136 return FALSE; /* Destination is not a push button */
1137
1138 /* Make sure the old default control is a valid push button ID */
1139 hwndOld = GetDlgItem( hwndDlg, old_id );
1140 if (!hwndOld || !(SendMessageW( hwndOld, WM_GETDLGCODE, 0, 0) & DLGC_DEFPUSHBUTTON))
1141 hwndOld = DEFDLG_FindDefButton( hwndDlg );
1142 if (hwndOld && hwndOld != hwndNew)
1143 SendMessageW( hwndOld, BM_SETSTYLE, BS_PUSHBUTTON, TRUE );
1144
1145 if (hwndNew)
1146 {
1147 if(dlgcode & DLGC_UNDEFPUSHBUTTON)
1148 SendMessageW( hwndNew, BM_SETSTYLE, BS_DEFPUSHBUTTON, TRUE );
1149 }
1150 return TRUE;
1151 }
1152
1153
1154 /***********************************************************************
1155 * DEFDLG_SetDefButton
1156 *
1157 * Set the new default button to be hwndNew.
1158 */
1159 static BOOL DEFDLG_SetDefButton( HWND hwndDlg, DIALOGINFO *dlgInfo, HWND hwndNew )
1160 {
1161 DWORD dlgcode=0; /* initialize just to avoid a warning */
1162 HWND hwndOld = GetDlgItem( hwndDlg, dlgInfo->idResult );
1163
1164 if (hwndNew &&
1165 !((dlgcode=SendMessageW(hwndNew, WM_GETDLGCODE, 0, 0 ))
1166 & (DLGC_UNDEFPUSHBUTTON | DLGC_DEFPUSHBUTTON)))
1167 {
1168 /**
1169 * Need to draw only default push button rectangle.
1170 * Since the next control is not a push button, need to draw the push
1171 * button rectangle for the default control.
1172 */
1173 hwndNew = hwndOld;
1174 dlgcode = SendMessageW(hwndNew, WM_GETDLGCODE, 0, 0 );
1175 }
1176
1177 /* Make sure the old default control is a valid push button ID */
1178 if (!hwndOld || !(SendMessageW( hwndOld, WM_GETDLGCODE, 0, 0) & DLGC_DEFPUSHBUTTON))
1179 hwndOld = DEFDLG_FindDefButton( hwndDlg );
1180 if (hwndOld && hwndOld != hwndNew)
1181 SendMessageW( hwndOld, BM_SETSTYLE, BS_PUSHBUTTON, TRUE );
1182
1183 if (hwndNew)
1184 {
1185 if(dlgcode & DLGC_UNDEFPUSHBUTTON)
1186 SendMessageW( hwndNew, BM_SETSTYLE, BS_DEFPUSHBUTTON, TRUE );
1187 }
1188 return TRUE;
1189 }
1190
1191
1192 /***********************************************************************
1193 * DEFDLG_Proc
1194 *
1195 * Implementation of DefDlgProc(). Only handle messages that need special
1196 * handling for dialogs.
1197 */
1198 static LRESULT DEFDLG_Proc( HWND hwnd, UINT msg, WPARAM wParam,
1199 LPARAM lParam, DIALOGINFO *dlgInfo )
1200 {
1201 switch(msg)
1202 {
1203 case WM_ERASEBKGND:
1204 {
1205 HBRUSH brush = GetControlColor( hwnd, hwnd, (HDC)wParam, WM_CTLCOLORDLG);
1206 if (brush)
1207 {
1208 RECT rect;
1209 HDC hdc = (HDC)wParam;
1210 GetClientRect( hwnd, &rect );
1211 DPtoLP( hdc, (LPPOINT)&rect, 2 );
1212 FillRect( hdc, &rect, brush );
1213 }
1214 return 1;
1215 }
1216 case WM_NCDESTROY:
1217 //// ReactOS
1218 if ((dlgInfo = (DIALOGINFO *)SetWindowLongPtrW( hwnd, DWLP_ROS_DIALOGINFO, 0 )))
1219 {
1220 if (dlgInfo->hUserFont) DeleteObject( dlgInfo->hUserFont );
1221 if (dlgInfo->hMenu) DestroyMenu( dlgInfo->hMenu );
1222 HeapFree( GetProcessHeap(), 0, dlgInfo );
1223 NtUserSetThreadState(0,DF_DIALOGACTIVE);
1224 NtUserxSetDialogPointer( hwnd, 0 );
1225 }
1226 /* Window clean-up */
1227 return DefWindowProcA( hwnd, msg, wParam, lParam );
1228
1229 case WM_SHOWWINDOW:
1230 if (!wParam) DEFDLG_SaveFocus( hwnd );
1231 return DefWindowProcA( hwnd, msg, wParam, lParam );
1232
1233 case WM_ACTIVATE:
1234 { // ReactOS
1235 DWORD dwSetFlag;
1236 HWND hwndparent = DIALOG_FindMsgDestination( hwnd );
1237 // if WA_CLICK/ACTIVE ? set dialog is active.
1238 dwSetFlag = wParam ? DF_DIALOGACTIVE : 0;
1239 if (hwndparent != hwnd) NtUserSetThreadState(dwSetFlag, DF_DIALOGACTIVE);
1240 }
1241 if (wParam) DEFDLG_RestoreFocus( hwnd, TRUE );
1242 else DEFDLG_SaveFocus( hwnd );
1243 return 0;
1244
1245 case WM_SETFOCUS:
1246 DEFDLG_RestoreFocus( hwnd, FALSE );
1247 return 0;
1248
1249 case DM_SETDEFID:
1250 if (dlgInfo && !(dlgInfo->flags & DF_END))
1251 DEFDLG_SetDefId( hwnd, dlgInfo, wParam );
1252 return 1;
1253
1254 case DM_GETDEFID:
1255 if (dlgInfo && !(dlgInfo->flags & DF_END))
1256 {
1257 HWND hwndDefId;
1258 if (dlgInfo->idResult)
1259 return MAKELONG( dlgInfo->idResult, DC_HASDEFID );
1260 if ((hwndDefId = DEFDLG_FindDefButton( hwnd )))
1261 return MAKELONG( GetDlgCtrlID( hwndDefId ), DC_HASDEFID);
1262 }
1263 return 0;
1264
1265 case WM_NEXTDLGCTL:
1266 if (dlgInfo)
1267 {
1268 HWND hwndDest = (HWND)wParam;
1269 if (!lParam)
1270 hwndDest = GetNextDlgTabItem(hwnd, GetFocus(), wParam);
1271 if (hwndDest) DEFDLG_SetFocus( hwndDest );
1272 DEFDLG_SetDefButton( hwnd, dlgInfo, hwndDest );
1273 }
1274 return 0;
1275
1276 case WM_ENTERMENULOOP:
1277 case WM_LBUTTONDOWN:
1278 case WM_NCLBUTTONDOWN:
1279 {
1280 HWND hwndFocus = GetFocus();
1281 if (hwndFocus)
1282 {
1283 /* always make combo box hide its listbox control */
1284 if (!SendMessageW( hwndFocus, CB_SHOWDROPDOWN, FALSE, 0 ))
1285 SendMessageW( GetParent(hwndFocus), CB_SHOWDROPDOWN, FALSE, 0 );
1286 }
1287 }
1288 return DefWindowProcA( hwnd, msg, wParam, lParam );
1289
1290 case WM_GETFONT:
1291 return dlgInfo ? (LRESULT)dlgInfo->hUserFont : 0;
1292
1293 case WM_CLOSE:
1294 PostMessageA( hwnd, WM_COMMAND, MAKEWPARAM(IDCANCEL, BN_CLICKED),
1295 (LPARAM)GetDlgItem( hwnd, IDCANCEL ) );
1296 return 0;
1297 }
1298 return 0;
1299 }
1300
1301 /***********************************************************************
1302 * DEFDLG_Epilog
1303 */
1304 static LRESULT DEFDLG_Epilog(HWND hwnd, UINT msg, WPARAM wParam, LPARAM lParam, BOOL fResult, BOOL fAnsi)
1305 {
1306 if ((msg >= WM_CTLCOLORMSGBOX && msg <= WM_CTLCOLORSTATIC) ||
1307 msg == WM_CTLCOLOR)
1308 {
1309 if (fResult) return fResult;
1310
1311 return fAnsi ? DefWindowProcA(hwnd, msg, wParam, lParam):
1312 DefWindowProcW(hwnd, msg, wParam, lParam);
1313 }
1314 if ( msg == WM_COMPAREITEM ||
1315 msg == WM_VKEYTOITEM || msg == WM_CHARTOITEM ||
1316 msg == WM_QUERYDRAGICON || msg == WM_INITDIALOG)
1317 return fResult;
1318
1319 return GetWindowLongPtrW( hwnd, DWLP_MSGRESULT );
1320 }
1321
1322 /***********************************************************************
1323 * DIALOG_GetNextTabItem
1324 *
1325 * Helper for GetNextDlgTabItem
1326 */
1327 static HWND DIALOG_GetNextTabItem( HWND hwndMain, HWND hwndDlg, HWND hwndCtrl, BOOL fPrevious )
1328 {
1329 LONG dsStyle;
1330 LONG exStyle;
1331 UINT wndSearch = fPrevious ? GW_HWNDPREV : GW_HWNDNEXT;
1332 HWND retWnd = 0;
1333 HWND hChildFirst = 0;
1334
1335 if(!hwndCtrl)
1336 {
1337 hChildFirst = GetWindow(hwndDlg,GW_CHILD);
1338 if(fPrevious) hChildFirst = GetWindow(hChildFirst,GW_HWNDLAST);
1339 }
1340 else if (IsChild( hwndMain, hwndCtrl ))
1341 {
1342 hChildFirst = GetWindow(hwndCtrl,wndSearch);
1343 if(!hChildFirst)
1344 {
1345 if(GetParent(hwndCtrl) != hwndMain)
1346 /* i.e. if we are not at the top level of the recursion */
1347 hChildFirst = GetWindow(GetParent(hwndCtrl),wndSearch);
1348 else
1349 hChildFirst = GetWindow(hwndCtrl, fPrevious ? GW_HWNDLAST : GW_HWNDFIRST);
1350 }
1351 }
1352
1353 while(hChildFirst)
1354 {
1355 dsStyle = GetWindowLongPtrA(hChildFirst,GWL_STYLE);
1356 exStyle = GetWindowLongPtrA(hChildFirst,GWL_EXSTYLE);
1357 if( (exStyle & WS_EX_CONTROLPARENT) && (dsStyle & WS_VISIBLE) && !(dsStyle & WS_DISABLED))
1358 {
1359 HWND retWnd;
1360 retWnd = DIALOG_GetNextTabItem(hwndMain,hChildFirst,NULL,fPrevious );
1361 if (retWnd) return (retWnd);
1362 }
1363 else if( (dsStyle & WS_TABSTOP) && (dsStyle & WS_VISIBLE) && !(dsStyle & WS_DISABLED))
1364 {
1365 return (hChildFirst);
1366 }
1367 hChildFirst = GetWindow(hChildFirst,wndSearch);
1368 }
1369 if(hwndCtrl)
1370 {
1371 HWND hParent = GetParent(hwndCtrl);
1372 while(hParent)
1373 {
1374 if(hParent == hwndMain) break;
1375 retWnd = DIALOG_GetNextTabItem(hwndMain,GetParent(hParent),hParent,fPrevious );
1376 if(retWnd) break;
1377 hParent = GetParent(hParent);
1378 }
1379 if(!retWnd)
1380 retWnd = DIALOG_GetNextTabItem(hwndMain,hwndMain,NULL,fPrevious );
1381 }
1382 return retWnd ? retWnd : hwndCtrl;
1383 }
1384
1385
1386 /**********************************************************************
1387 * DIALOG_DlgDirListW
1388 *
1389 * Helper function for DlgDirList*W
1390 */
1391 static INT DIALOG_DlgDirListW( HWND hDlg, LPWSTR spec, INT idLBox,
1392 INT idStatic, UINT attrib, BOOL combo )
1393 {
1394 HWND hwnd;
1395 LPWSTR orig_spec = spec;
1396 WCHAR any[] = {'*','.','*',0};
1397
1398 #define SENDMSG(msg,wparam,lparam) \
1399 ((attrib & DDL_POSTMSGS) ? PostMessageW( hwnd, msg, wparam, lparam ) \
1400 : SendMessageW( hwnd, msg, wparam, lparam ))
1401
1402 TRACE("%p %s %d %d %04x\n", hDlg, debugstr_w(spec), idLBox, idStatic, attrib );
1403
1404 /* If the path exists and is a directory, chdir to it */
1405 if (!spec || !spec[0] || SetCurrentDirectoryW( spec )) spec = any;
1406 else
1407 {
1408 WCHAR *p, *p2;
1409 p = spec;
1410 if ((p2 = strchrW( p, ':' ))) p = p2 + 1;
1411 if ((p2 = strrchrW( p, '\\' ))) p = p2;
1412 if ((p2 = strrchrW( p, '/' ))) p = p2;
1413 if (p != spec)
1414 {
1415 WCHAR sep = *p;
1416 *p = 0;
1417 if (!SetCurrentDirectoryW( spec ))
1418 {
1419 *p = sep; /* Restore the original spec */
1420 return FALSE;
1421 }
1422 spec = p + 1;
1423 }
1424 }
1425
1426 TRACE( "mask=%s\n", spec );
1427
1428 if (idLBox && ((hwnd = GetDlgItem( hDlg, idLBox )) != 0))
1429 {
1430 if (attrib == DDL_DRIVES) attrib |= DDL_EXCLUSIVE;
1431
1432 SENDMSG( combo ? CB_RESETCONTENT : LB_RESETCONTENT, 0, 0 );
1433 if (attrib & DDL_DIRECTORY)
1434 {
1435 if (!(attrib & DDL_EXCLUSIVE))
1436 {
1437 SENDMSG( combo ? CB_DIR : LB_DIR,
1438 attrib & ~(DDL_DIRECTORY | DDL_DRIVES),
1439 (LPARAM)spec );
1440 }
1441 SENDMSG( combo ? CB_DIR : LB_DIR,
1442 (attrib & (DDL_DIRECTORY | DDL_DRIVES)) | DDL_EXCLUSIVE,
1443 (LPARAM)any );
1444 }
1445 else
1446 {
1447 SENDMSG( combo ? CB_DIR : LB_DIR, attrib, (LPARAM)spec );
1448 }
1449 }
1450
1451 /* Convert path specification to uppercase */
1452 if (spec) CharUpperW(spec);
1453
1454 if (idStatic && ((hwnd = GetDlgItem( hDlg, idStatic )) != 0))
1455 {
1456 WCHAR temp[MAX_PATH];
1457 GetCurrentDirectoryW( sizeof(temp)/sizeof(WCHAR), temp );
1458 CharLowerW( temp );
1459 /* Can't use PostMessage() here, because the string is on the stack */
1460 SetDlgItemTextW( hDlg, idStatic, temp );
1461 }
1462
1463 if (orig_spec && (spec != orig_spec))
1464 {
1465 /* Update the original file spec */
1466 WCHAR *p = spec;
1467 while ((*orig_spec++ = *p++));
1468 }
1469
1470 return TRUE;
1471 #undef SENDMSG
1472 }
1473
1474
1475 /**********************************************************************
1476 * DIALOG_DlgDirListA
1477 *
1478 * Helper function for DlgDirList*A
1479 */
1480 static INT DIALOG_DlgDirListA( HWND hDlg, LPSTR spec, INT idLBox,
1481 INT idStatic, UINT attrib, BOOL combo )
1482 {
1483 if (spec)
1484 {
1485 INT ret, len = MultiByteToWideChar( CP_ACP, 0, spec, -1, NULL, 0 );
1486 LPWSTR specW = HeapAlloc( GetProcessHeap(), 0, len * sizeof(WCHAR) );
1487 if (specW == NULL)
1488 return FALSE;
1489 MultiByteToWideChar( CP_ACP, 0, spec, -1, specW, len );
1490 ret = DIALOG_DlgDirListW( hDlg, specW, idLBox, idStatic, attrib, combo );
1491 WideCharToMultiByte( CP_ACP, 0, specW, -1, spec, 0x7fffffff, NULL, NULL );
1492 HeapFree( GetProcessHeap(), 0, specW );
1493 return ret;
1494 }
1495 return DIALOG_DlgDirListW( hDlg, NULL, idLBox, idStatic, attrib, combo );
1496 }
1497
1498 /**********************************************************************
1499 * DIALOG_DlgDirSelect
1500 *
1501 * Helper function for DlgDirSelect*
1502 */
1503 static BOOL DIALOG_DlgDirSelect( HWND hwnd, LPWSTR str, INT len,
1504 INT id, BOOL unicode, BOOL combo )
1505 {
1506 WCHAR *buffer, *ptr;
1507 INT item, size;
1508 BOOL ret;
1509 HWND listbox = GetDlgItem( hwnd, id );
1510
1511 TRACE("%p %s %d\n", hwnd, unicode ? debugstr_w(str) : debugstr_a((LPSTR)str), id );
1512 if (!listbox) return FALSE;
1513
1514 item = SendMessageW(listbox, combo ? CB_GETCURSEL : LB_GETCURSEL, 0, 0 );
1515 if (item == LB_ERR) return FALSE;
1516
1517 size = SendMessageW(listbox, combo ? CB_GETLBTEXTLEN : LB_GETTEXTLEN, item, 0 );
1518 if (size == LB_ERR) return FALSE;
1519
1520 if (!(buffer = HeapAlloc( GetProcessHeap(), 0, (size+2) * sizeof(WCHAR) ))) return FALSE;
1521
1522 SendMessageW( listbox, combo ? CB_GETLBTEXT : LB_GETTEXT, item, (LPARAM)buffer );
1523
1524 if ((ret = (buffer[0] == '['))) /* drive or directory */
1525 {
1526 if (buffer[1] == '-') /* drive */
1527 {
1528 buffer[3] = ':';
1529 buffer[4] = 0;
1530 ptr = buffer + 2;
1531 }
1532 else
1533 {
1534 buffer[strlenW(buffer)-1] = '\\';
1535 ptr = buffer + 1;
1536 }
1537 }
1538 else
1539 {
1540 /* Filenames without a dot extension must have one tacked at the end */
1541 if (strchrW(buffer, '.') == NULL)
1542 {
1543 buffer[strlenW(buffer)+1] = '\0';
1544 buffer[strlenW(buffer)] = '.';
1545 }
1546 ptr = buffer;
1547 }
1548
1549 if (!unicode)
1550 {
1551 if (len > 0 && !WideCharToMultiByte( CP_ACP, 0, ptr, -1, (LPSTR)str, len, 0, 0 ))
1552 ((LPSTR)str)[len-1] = 0;
1553 }
1554 else lstrcpynW( str, ptr, len );
1555 HeapFree( GetProcessHeap(), 0, buffer );
1556 TRACE("Returning %d %s\n", ret, unicode ? debugstr_w(str) : debugstr_a((LPSTR)str) );
1557 return ret;
1558 }
1559
1560
1561 /* FUNCTIONS *****************************************************************/
1562
1563 /*
1564 * @implemented
1565 */
1566 HWND
1567 WINAPI
1568 CreateDialogIndirectParamAorW(
1569 HINSTANCE hInstance,
1570 LPCDLGTEMPLATE lpTemplate,
1571 HWND hWndParent,
1572 DLGPROC lpDialogFunc,
1573 LPARAM lParamInit,
1574 DWORD Flags)
1575 {
1576 /* FIXME:
1577 * This function might be obsolete since I don't think it is exported by NT
1578 * Also wine has one more parameter identifying weather it should call
1579 * the function with unicode or not
1580 */
1581 return DIALOG_CreateIndirect( hInstance, lpTemplate, hWndParent, lpDialogFunc, lParamInit , Flags == DLG_ISANSI ? FALSE : TRUE, NULL );
1582 }
1583
1584
1585 /*
1586 * @implemented
1587 */
1588 HWND
1589 WINAPI
1590 CreateDialogIndirectParamA(
1591 HINSTANCE hInstance,
1592 LPCDLGTEMPLATE lpTemplate,
1593 HWND hWndParent,
1594 DLGPROC lpDialogFunc,
1595 LPARAM lParamInit)
1596 {
1597 return CreateDialogIndirectParamAorW( hInstance, lpTemplate, hWndParent, lpDialogFunc, lParamInit, DLG_ISANSI);
1598 }
1599
1600
1601 /*
1602 * @implemented
1603 */
1604 HWND
1605 WINAPI
1606 CreateDialogIndirectParamW(
1607 HINSTANCE hInstance,
1608 LPCDLGTEMPLATE lpTemplate,
1609 HWND hWndParent,
1610 DLGPROC lpDialogFunc,
1611 LPARAM lParamInit)
1612 {
1613 return CreateDialogIndirectParamAorW( hInstance, lpTemplate, hWndParent, lpDialogFunc, lParamInit, 0);
1614 }
1615
1616
1617 /*
1618 * @implemented
1619 */
1620 HWND
1621 WINAPI
1622 CreateDialogParamA(
1623 HINSTANCE hInstance,
1624 LPCSTR lpTemplateName,
1625 HWND hWndParent,
1626 DLGPROC lpDialogFunc,
1627 LPARAM dwInitParam)
1628 {
1629 HRSRC hrsrc;
1630 LPCDLGTEMPLATE ptr;
1631
1632 if (!(hrsrc = FindResourceA( hInstance, lpTemplateName, (LPCSTR)RT_DIALOG ))) return 0;
1633 if (!(ptr = (LPCDLGTEMPLATE)LoadResource(hInstance, hrsrc))) return 0;
1634 return CreateDialogIndirectParamA( hInstance, ptr, hWndParent, lpDialogFunc, dwInitParam );
1635 }
1636
1637
1638 /*
1639 * @implemented
1640 */
1641 HWND
1642 WINAPI
1643 CreateDialogParamW(
1644 HINSTANCE hInstance,
1645 LPCWSTR lpTemplateName,
1646 HWND hWndParent,
1647 DLGPROC lpDialogFunc,
1648 LPARAM dwInitParam)
1649 {
1650 HRSRC hrsrc;
1651 LPCDLGTEMPLATE ptr;
1652
1653 if (!(hrsrc = FindResourceW( hInstance, lpTemplateName, (LPCWSTR)RT_DIALOG ))) return 0;
1654 if (!(ptr = (LPCDLGTEMPLATE)LoadResource(hInstance, hrsrc))) return 0;
1655 return CreateDialogIndirectParamW( hInstance, ptr, hWndParent, lpDialogFunc, dwInitParam );
1656 }
1657
1658
1659 /*
1660 * @implemented
1661 */
1662 LRESULT
1663 WINAPI
1664 DefDlgProcA(
1665 HWND hDlg,
1666 UINT Msg,
1667 WPARAM wParam,
1668 LPARAM lParam)
1669 {
1670 DIALOGINFO *dlgInfo;
1671 WNDPROC dlgproc;
1672 BOOL result = FALSE;
1673
1674 /* Perform DIALOGINFO initialization if not done */
1675 if(!(dlgInfo = DIALOG_get_info( hDlg, TRUE ))) return 0; //// REACTOS : Always TRUE! See RealGetWindowClass.
1676
1677 SetWindowLongPtrW( hDlg, DWLP_MSGRESULT, 0 );
1678
1679 if ((dlgproc = (WNDPROC)GetWindowLongPtrW( hDlg, DWLP_DLGPROC )))
1680 {
1681 /* Call dialog procedure */
1682 result = CallWindowProcA( dlgproc, hDlg, Msg, wParam, lParam );
1683 }
1684
1685 if (!result && IsWindow(hDlg))
1686 {
1687 /* callback didn't process this message */
1688
1689 switch(Msg)
1690 {
1691 case WM_ERASEBKGND:
1692 case WM_SHOWWINDOW:
1693 case WM_ACTIVATE:
1694 case WM_SETFOCUS:
1695 case DM_SETDEFID:
1696 case DM_GETDEFID:
1697 case WM_NEXTDLGCTL:
1698 case WM_GETFONT:
1699 case WM_CLOSE:
1700 case WM_NCDESTROY:
1701 case WM_ENTERMENULOOP:
1702 case WM_LBUTTONDOWN:
1703 case WM_NCLBUTTONDOWN:
1704 return DEFDLG_Proc( hDlg, Msg, wParam, lParam, dlgInfo );
1705 case WM_INITDIALOG:
1706 case WM_VKEYTOITEM:
1707 case WM_COMPAREITEM:
1708 case WM_CHARTOITEM:
1709 break;
1710
1711 default:
1712 return DefWindowProcA( hDlg, Msg, wParam, lParam );
1713 }
1714 }
1715 return DEFDLG_Epilog(hDlg, Msg, wParam, lParam, result, TRUE);
1716 }
1717
1718
1719 /*
1720 * @implemented
1721 */
1722 LRESULT
1723 WINAPI
1724 DefDlgProcW(
1725 HWND hDlg,
1726 UINT Msg,
1727 WPARAM wParam,
1728 LPARAM lParam)
1729 {
1730 DIALOGINFO *dlgInfo;
1731 WNDPROC dlgproc;
1732 BOOL result = FALSE;
1733
1734 /* Perform DIALOGINFO initialization if not done */
1735 if(!(dlgInfo = DIALOG_get_info( hDlg, TRUE ))) return 0; //// REACTOS : Always TRUE! See RealGetWindowClass.
1736
1737 SetWindowLongPtrW( hDlg, DWLP_MSGRESULT, 0 );
1738
1739 if ((dlgproc = (WNDPROC)GetWindowLongPtrW( hDlg, DWLP_DLGPROC )))
1740 {
1741 /* Call dialog procedure */
1742 result = CallWindowProcW( dlgproc, hDlg, Msg, wParam, lParam );
1743 }
1744
1745 if (!result && IsWindow(hDlg))
1746 {
1747 /* callback didn't process this message */
1748
1749 switch(Msg)
1750 {
1751 case WM_ERASEBKGND:
1752 case WM_SHOWWINDOW:
1753 case WM_ACTIVATE:
1754 case WM_SETFOCUS:
1755 case DM_SETDEFID:
1756 case DM_GETDEFID:
1757 case WM_NEXTDLGCTL:
1758 case WM_GETFONT:
1759 case WM_CLOSE:
1760 case WM_NCDESTROY:
1761 case WM_ENTERMENULOOP:
1762 case WM_LBUTTONDOWN:
1763 case WM_NCLBUTTONDOWN:
1764 return DEFDLG_Proc( hDlg, Msg, wParam, lParam, dlgInfo );
1765 case WM_INITDIALOG:
1766 case WM_VKEYTOITEM:
1767 case WM_COMPAREITEM:
1768 case WM_CHARTOITEM:
1769 break;
1770
1771 default:
1772 return DefWindowProcW( hDlg, Msg, wParam, lParam );
1773 }
1774 }
1775 return DEFDLG_Epilog(hDlg, Msg, wParam, lParam, result, FALSE);
1776 }
1777
1778
1779 /*
1780 * @implemented
1781 */
1782 INT_PTR
1783 WINAPI
1784 DialogBoxIndirectParamAorW(
1785 HINSTANCE hInstance,
1786 LPCDLGTEMPLATE hDialogTemplate,
1787 HWND hWndParent,
1788 DLGPROC lpDialogFunc,
1789 LPARAM dwInitParam,
1790 DWORD Flags)
1791 {
1792 /* FIXME:
1793 * This function might be obsolete since I don't think it is exported by NT
1794 * Also wine has one more parameter identifying weather it should call
1795 * the function with unicode or not
1796 */
1797 HWND hWnd = DIALOG_CreateIndirect( hInstance, hDialogTemplate, hWndParent, lpDialogFunc, dwInitParam, Flags == DLG_ISANSI ? FALSE : TRUE, &hWndParent );
1798 if (hWnd) return DIALOG_DoDialogBox( hWnd, hWndParent );
1799 return -1;
1800 }
1801
1802
1803 /*
1804 * @implemented
1805 */
1806 INT_PTR
1807 WINAPI
1808 DialogBoxIndirectParamA(
1809 HINSTANCE hInstance,
1810 LPCDLGTEMPLATE hDialogTemplate,
1811 HWND hWndParent,
1812 DLGPROC lpDialogFunc,
1813 LPARAM dwInitParam)
1814 {
1815 return DialogBoxIndirectParamAorW( hInstance, hDialogTemplate, hWndParent, lpDialogFunc, dwInitParam, DLG_ISANSI);
1816 }
1817
1818
1819 /*
1820 * @implemented
1821 */
1822 INT_PTR
1823 WINAPI
1824 DialogBoxIndirectParamW(
1825 HINSTANCE hInstance,
1826 LPCDLGTEMPLATE hDialogTemplate,
1827 HWND hWndParent,
1828 DLGPROC lpDialogFunc,
1829 LPARAM dwInitParam)
1830 {
1831 return DialogBoxIndirectParamAorW( hInstance, hDialogTemplate, hWndParent, lpDialogFunc, dwInitParam, 0);
1832 }
1833
1834
1835 /*
1836 * @implemented
1837 */
1838 INT_PTR
1839 WINAPI
1840 DialogBoxParamA(
1841 HINSTANCE hInstance,
1842 LPCSTR lpTemplateName,
1843 HWND hWndParent,
1844 DLGPROC lpDialogFunc,
1845 LPARAM dwInitParam)
1846 {
1847 HWND hwnd;
1848 HRSRC hrsrc;
1849 LPCDLGTEMPLATE ptr;
1850 //// ReactOS rev 33532
1851 if (!(hrsrc = FindResourceA( hInstance, lpTemplateName, (LPCSTR)RT_DIALOG )) ||
1852 !(ptr = LoadResource(hInstance, hrsrc)))
1853 {
1854 SetLastError(ERROR_RESOURCE_NAME_NOT_FOUND);
1855 return -1;
1856 }
1857 if (hWndParent != NULL && !IsWindow(hWndParent))
1858 {
1859 SetLastError(ERROR_INVALID_WINDOW_HANDLE);
1860 return 0;
1861 }
1862 hwnd = DIALOG_CreateIndirect(hInstance, ptr, hWndParent, lpDialogFunc, dwInitParam, FALSE, &hWndParent );
1863 if (hwnd) return DIALOG_DoDialogBox(hwnd, hWndParent);
1864 return -1;
1865 }
1866
1867
1868 /*
1869 * @implemented
1870 */
1871 INT_PTR
1872 WINAPI
1873 DialogBoxParamW(
1874 HINSTANCE hInstance,
1875 LPCWSTR lpTemplateName,
1876 HWND hWndParent,
1877 DLGPROC lpDialogFunc,
1878 LPARAM dwInitParam)
1879 {
1880 HWND hwnd;
1881 HRSRC hrsrc;
1882 LPCDLGTEMPLATE ptr;
1883 //// ReactOS rev 33532
1884 if (!(hrsrc = FindResourceW( hInstance, lpTemplateName, (LPCWSTR)RT_DIALOG )) ||
1885 !(ptr = LoadResource(hInstance, hrsrc)))
1886 {
1887 SetLastError(ERROR_RESOURCE_NAME_NOT_FOUND);
1888 return -1;
1889 }
1890 if (hWndParent != NULL && !IsWindow(hWndParent))
1891 {
1892 SetLastError(ERROR_INVALID_WINDOW_HANDLE);
1893 return 0;
1894 }
1895 hwnd = DIALOG_CreateIndirect(hInstance, ptr, hWndParent, lpDialogFunc, dwInitParam, TRUE, &hWndParent );
1896 if (hwnd) return DIALOG_DoDialogBox(hwnd, hWndParent);
1897 return -1;
1898 }
1899
1900
1901 /*
1902 * @implemented
1903 */
1904 int
1905 WINAPI
1906 DlgDirListA(
1907 HWND hDlg,
1908 LPSTR lpPathSpec,
1909 int nIDListBox,
1910 int nIDStaticPath,
1911 UINT uFileType)
1912 {
1913 return DIALOG_DlgDirListA( hDlg, lpPathSpec, nIDListBox, nIDStaticPath, uFileType, FALSE );
1914 }
1915
1916
1917 /*
1918 * @implemented
1919 */
1920 int
1921 WINAPI
1922 DlgDirListComboBoxA(
1923 HWND hDlg,
1924 LPSTR lpPathSpec,
1925 int nIDComboBox,
1926 int nIDStaticPath,
1927 UINT uFiletype)
1928 {
1929 return DIALOG_DlgDirListA( hDlg, lpPathSpec, nIDComboBox, nIDStaticPath, uFiletype, TRUE );
1930 }
1931
1932
1933 /*
1934 * @implemented
1935 */
1936 int
1937 WINAPI
1938 DlgDirListComboBoxW(
1939 HWND hDlg,
1940 LPWSTR lpPathSpec,
1941 int nIDComboBox,
1942 int nIDStaticPath,
1943 UINT uFiletype)
1944 {
1945 return DIALOG_DlgDirListW( hDlg, lpPathSpec, nIDComboBox, nIDStaticPath, uFiletype, TRUE );
1946 }
1947
1948
1949 /*
1950 * @implemented
1951 */
1952 int
1953 WINAPI
1954 DlgDirListW(
1955 HWND hDlg,
1956 LPWSTR lpPathSpec,
1957 int nIDListBox,
1958 int nIDStaticPath,
1959 UINT uFileType)
1960 {
1961 return DIALOG_DlgDirListW( hDlg, lpPathSpec, nIDListBox, nIDStaticPath, uFileType, FALSE );
1962 }
1963
1964
1965 /*
1966 * @implemented
1967 */
1968 BOOL
1969 WINAPI
1970 DlgDirSelectComboBoxExA(
1971 HWND hDlg,
1972 LPSTR lpString,
1973 int nCount,
1974 int nIDComboBox)
1975 {
1976 return DIALOG_DlgDirSelect( hDlg, (LPWSTR)lpString, nCount, nIDComboBox, FALSE, TRUE );
1977 }
1978
1979
1980 /*
1981 * @implemented
1982 */
1983 BOOL
1984 WINAPI
1985 DlgDirSelectComboBoxExW(
1986 HWND hDlg,
1987 LPWSTR lpString,
1988 int nCount,
1989 int nIDComboBox)
1990 {
1991 return DIALOG_DlgDirSelect( hDlg, (LPWSTR)lpString, nCount, nIDComboBox, TRUE, TRUE );
1992 }
1993
1994
1995 /*
1996 * @implemented
1997 */
1998 BOOL
1999 WINAPI
2000 DlgDirSelectExA(
2001 HWND hDlg,
2002 LPSTR lpString,
2003 int nCount,
2004 int nIDListBox)
2005 {
2006 return DIALOG_DlgDirSelect( hDlg, (LPWSTR)lpString, nCount, nIDListBox, FALSE, FALSE );
2007 }
2008
2009
2010 /*
2011 * @implemented
2012 */
2013 BOOL
2014 WINAPI
2015 DlgDirSelectExW(
2016 HWND hDlg,
2017 LPWSTR lpString,
2018 int nCount,
2019 int nIDListBox)
2020 {
2021 return DIALOG_DlgDirSelect( hDlg, lpString, nCount, nIDListBox, TRUE, FALSE );
2022 }
2023
2024
2025 /*
2026 * @implemented Modified for ReactOS. Do not Port Sync!!!
2027 */
2028 BOOL
2029 WINAPI
2030 EndDialog(
2031 HWND hwnd,
2032 INT_PTR retval)
2033 {
2034 DIALOGINFO * dlgInfo;
2035 HWND owner;
2036 BOOL wasActive;
2037
2038 TRACE("%p %ld\n", hwnd, retval );
2039
2040 if (!(dlgInfo = GETDLGINFO(hwnd)))
2041 {
2042 ERR("got invalid window handle (%p); buggy app !?\n", hwnd);
2043 return FALSE;
2044 }
2045 wasActive = (hwnd == GetActiveWindow());
2046 dlgInfo->idResult = retval;
2047 dlgInfo->flags |= DF_END;
2048
2049 if ((GetWindowLongW( hwnd, GWL_STYLE ) & (WS_POPUP|WS_CHILD)) == WS_CHILD)
2050 {
2051 owner = GetAncestor( hwnd, GA_PARENT);
2052 }
2053 else
2054 owner = GetWindow( hwnd, GW_OWNER );
2055
2056 if (owner)
2057 EnableWindow( owner, TRUE );
2058
2059 /* Windows sets the focus to the dialog itself in EndDialog */
2060
2061 if (wasActive && IsChild(hwnd, GetFocus()))
2062 SetFocus( hwnd );
2063
2064 /* Don't have to send a ShowWindow(SW_HIDE), just do
2065 SetWindowPos with SWP_HIDEWINDOW as done in Windows */
2066
2067 SetWindowPos(hwnd, NULL, 0, 0, 0, 0, SWP_NOMOVE | SWP_NOSIZE
2068 | SWP_NOZORDER | SWP_NOACTIVATE | SWP_HIDEWINDOW);
2069
2070 if (wasActive && owner)
2071 {
2072 /* If this dialog was given an owner then set the focus to that owner. */
2073 SetActiveWindow(owner);
2074 }
2075 else if (hwnd == GetActiveWindow()) // Check it again!
2076 {
2077 NtUserCallNoParam(NOPARAM_ROUTINE_ZAPACTIVEANDFOUS);
2078 }
2079
2080 /* unblock dialog loop */
2081 PostMessageA(hwnd, WM_NULL, 0, 0);
2082 return TRUE;
2083 }
2084
2085
2086 /*
2087 * @implemented
2088 */
2089 LONG
2090 WINAPI
2091 GetDialogBaseUnits(VOID)
2092 {
2093 static DWORD units;
2094
2095 if (!units)
2096 {
2097 HDC hdc;
2098 SIZE size;
2099
2100 if ((hdc = GetDC(0)))
2101 {
2102 size.cx = GdiGetCharDimensions( hdc, NULL, &size.cy );
2103 if (size.cx) units = MAKELONG( size.cx, size.cy );
2104 ReleaseDC( 0, hdc );
2105 }
2106 }
2107 return units;
2108 }
2109
2110
2111 /*
2112 * @implemented
2113 */
2114 int
2115 WINAPI
2116 GetDlgCtrlID(
2117 HWND hwndCtl)
2118 {
2119 return GetWindowLongPtrW( hwndCtl, GWLP_ID );
2120 }
2121
2122
2123 /*
2124 * @implemented
2125 */
2126 HWND
2127 WINAPI
2128 GetDlgItem(
2129 HWND hDlg,
2130 int nIDDlgItem)
2131 {
2132 int i;
2133 HWND *list;
2134 HWND ret = 0;
2135
2136 if (!hDlg) return 0;
2137
2138 list = WIN_ListChildren(hDlg);
2139 if (!list) return 0;
2140
2141 for (i = 0; list[i]; i++) if (GetWindowLongPtrW(list[i], GWLP_ID) == nIDDlgItem) break;
2142 ret = list[i];
2143 HeapFree(GetProcessHeap(), 0, list);
2144 // if (!ret) SetLastError(ERROR_CONTROL_ID_NOT_FOUND);
2145 return ret;
2146 }
2147
2148
2149 /*
2150 * @implemented
2151 */
2152 UINT
2153 WINAPI
2154 GetDlgItemInt(
2155 HWND hDlg,
2156 int nIDDlgItem,
2157 BOOL *lpTranslated,
2158 BOOL bSigned)
2159 {
2160 char str[30];
2161 char * endptr;
2162 LONG_PTR result = 0;
2163
2164 if (lpTranslated) *lpTranslated = FALSE;
2165 if (!SendDlgItemMessageA(hDlg, nIDDlgItem, WM_GETTEXT, sizeof(str), (LPARAM)str))
2166 return 0;
2167 if (bSigned)
2168 {
2169 result = strtol( str, &endptr, 10 );
2170 if (!endptr || (endptr == str)) /* Conversion was unsuccessful */
2171 return 0;
2172 if (((result == LONG_MIN) || (result == LONG_MAX)))
2173 return 0;
2174 }
2175 else
2176 {
2177 result = strtoul( str, &endptr, 10 );
2178 if (!endptr || (endptr == str)) /* Conversion was unsuccessful */
2179 return 0;
2180 if (result == ULONG_MAX) return 0;
2181 }
2182 if (lpTranslated) *lpTranslated = TRUE;
2183 return (UINT)result;
2184 }
2185
2186
2187 /*
2188 * @implemented
2189 */
2190 UINT
2191 WINAPI
2192 GetDlgItemTextA(
2193 HWND hDlg,
2194 int nIDDlgItem,
2195 LPSTR lpString,
2196 int nMaxCount)
2197 {
2198 HWND hWnd = GetDlgItem(hDlg, nIDDlgItem);
2199 if ( hWnd ) return GetWindowTextA(hWnd, lpString, nMaxCount);
2200 if ( nMaxCount ) lpString[0] = '\0';
2201 return 0;
2202 }
2203
2204
2205 /*
2206 * @implemented
2207 */
2208 UINT
2209 WINAPI
2210 GetDlgItemTextW(
2211 HWND hDlg,
2212 int nIDDlgItem,
2213 LPWSTR lpString,
2214 int nMaxCount)
2215 {
2216 HWND hWnd = GetDlgItem(hDlg, nIDDlgItem);
2217 if ( hWnd ) return GetWindowTextW(hWnd, lpString, nMaxCount);
2218 if ( nMaxCount ) lpString[0] = '\0';
2219 return 0;
2220 }
2221
2222 /*
2223 * @implemented
2224 */
2225 HWND
2226 WINAPI
2227 GetNextDlgGroupItem(
2228 HWND hDlg,
2229 HWND hCtl,
2230 BOOL bPrevious)
2231 {
2232 HWND hwnd, hwndNext, retvalue, hwndLastGroup = 0;
2233 BOOL fLooped=FALSE;
2234 BOOL fSkipping=FALSE;
2235
2236 if (hDlg == hCtl) hCtl = NULL;
2237 if (!hCtl && bPrevious) return 0;
2238
2239 /* if the hwndCtrl is the child of the control in the hwndDlg,
2240 * then the hwndDlg has to be the parent of the hwndCtrl */
2241
2242 if (hCtl)
2243 {
2244 if (!IsChild (hDlg, hCtl)) return 0;
2245 /* Make sure hwndCtrl is a top-level child */
2246
2247 }
2248 else
2249 {
2250 /* No ctrl specified -> start from the beginning */
2251 if (!(hCtl = GetWindow( hDlg, GW_CHILD ))) return 0;
2252 /* MSDN is wrong. fPrevious does not result in the last child */
2253
2254 /* No ctrl specified -> start from the beginning */
2255 if (!(hCtl = GetWindow( hDlg, GW_CHILD ))) return 0;
2256
2257 /* MSDN is wrong. fPrevious does not result in the last child */
2258
2259 /* Maybe that first one is valid. If so then we don't want to skip it*/
2260 if ((GetWindowLongPtrW( hCtl, GWL_STYLE ) & (WS_VISIBLE|WS_DISABLED)) == WS_VISIBLE)
2261 {
2262 return hCtl;
2263 }
2264
2265 }
2266
2267 /* Always go forward around the group and list of controls; for the
2268 * previous control keep track; for the next break when you find one
2269 */
2270 retvalue = hCtl;
2271 hwnd = hCtl;
2272 while (hwndNext = GetWindow (hwnd, GW_HWNDNEXT),
2273 1)
2274 {
2275 while (!hwndNext)
2276 {
2277 /* Climb out until there is a next sibling of the ancestor or we
2278 * reach the top (in which case we loop back to the start)
2279 */
2280 if (hDlg == GetParent (hwnd))
2281 {
2282 /* Wrap around to the beginning of the list, within the same
2283 * group. (Once only)
2284 */
2285 if (fLooped) goto end;
2286 fLooped = TRUE;
2287 hwndNext = GetWindow (hDlg, GW_CHILD);
2288 }
2289 else
2290 {
2291 hwnd = GetParent (hwnd);
2292 hwndNext = GetWindow (hwnd, GW_HWNDNEXT);
2293 }
2294 }
2295 hwnd = hwndNext;
2296
2297 /* Wander down the leading edge of controlparents */
2298 while ( (GetWindowLongPtrW (hwnd, GWL_EXSTYLE) & WS_EX_CONTROLPARENT) &&
2299 ((GetWindowLongPtrW (hwnd, GWL_STYLE) & (WS_VISIBLE | WS_DISABLED)) == WS_VISIBLE) &&
2300 (hwndNext = GetWindow (hwnd, GW_CHILD)))
2301 hwnd = hwndNext;
2302 /* Question. If the control is a control parent but either has no
2303 * children or is not visible/enabled then if it has a WS_GROUP does
2304 * it count? For that matter does it count anyway?
2305 * I believe it doesn't count.
2306 */
2307
2308 if ((GetWindowLongPtrW (hwnd, GWL_STYLE) & WS_GROUP))
2309 {
2310 hwndLastGroup = hwnd;
2311 if (!fSkipping)
2312 {
2313 /* Look for the beginning of the group */
2314 fSkipping = TRUE;
2315 }
2316 }
2317
2318 if (hwnd == hCtl)
2319 {
2320 if (!fSkipping) break;
2321 if (hwndLastGroup == hwnd) break;
2322 hwnd = hwndLastGroup;
2323 fSkipping = FALSE;
2324 fLooped = FALSE;
2325 }
2326
2327 if (!fSkipping &&
2328 (GetWindowLongPtrW (hwnd, GWL_STYLE) & (WS_VISIBLE|WS_DISABLED)) ==
2329 WS_VISIBLE)
2330 {
2331 retvalue = hwnd;
2332 if (!bPrevious) break;
2333 }
2334 }
2335 end:
2336 return retvalue;
2337 }
2338
2339
2340 /*
2341 * @implemented
2342 */
2343 HWND
2344 WINAPI
2345 GetNextDlgTabItem(
2346 HWND hDlg,
2347 HWND hCtl,
2348 BOOL bPrevious)
2349 {
2350 PWND pWindow;
2351
2352 pWindow = ValidateHwnd( hDlg );
2353 if (!pWindow) return NULL;
2354 if (hCtl)
2355 {
2356 pWindow = ValidateHwnd( hCtl );
2357 if (!pWindow) return NULL;
2358 }
2359
2360 /* Undocumented but tested under Win2000 and WinME */
2361 if (hDlg == hCtl) hCtl = NULL;
2362
2363 /* Contrary to MSDN documentation, tested under Win2000 and WinME
2364 * NB GetLastError returns whatever was set before the function was
2365 * called.
2366 */
2367 if (!hCtl && bPrevious) return 0;
2368
2369 return DIALOG_GetNextTabItem(hDlg, hDlg, hCtl, bPrevious);
2370 }
2371
2372
2373 #if 0
2374 BOOL
2375 WINAPI
2376 IsDialogMessage(
2377 HWND hDlg,
2378 LPMSG lpMsg)
2379 {
2380 return IsDialogMessageW(hDlg, lpMsg);
2381 }
2382 #endif
2383
2384 /***********************************************************************
2385 * DIALOG_FixOneChildOnChangeFocus
2386 *
2387 * Callback helper for DIALOG_FixChildrenOnChangeFocus
2388 */
2389
2390 static BOOL CALLBACK DIALOG_FixOneChildOnChangeFocus (HWND hwndChild,
2391 LPARAM lParam)
2392 {
2393 /* If a default pushbutton then no longer default */
2394 if (DLGC_DEFPUSHBUTTON & SendMessageW (hwndChild, WM_GETDLGCODE, 0, 0))
2395 SendMessageW (hwndChild, BM_SETSTYLE, BS_PUSHBUTTON, TRUE);
2396 return TRUE;
2397 }
2398
2399 /***********************************************************************
2400 * DIALOG_FixChildrenOnChangeFocus
2401 *
2402 * Following the change of focus that occurs for example after handling
2403 * a WM_KEYDOWN VK_TAB in IsDialogMessage, some tidying of the dialog's
2404 * children may be required.
2405 */
2406 static void DIALOG_FixChildrenOnChangeFocus (HWND hwndDlg, HWND hwndNext)
2407 {
2408 INT dlgcode_next = SendMessageW (hwndNext, WM_GETDLGCODE, 0, 0);
2409 /* INT dlgcode_dlg = SendMessageW (hwndDlg, WM_GETDLGCODE, 0, 0); */
2410 /* Windows does ask for this. I don't know why yet */
2411
2412 EnumChildWindows (hwndDlg, DIALOG_FixOneChildOnChangeFocus, 0);
2413
2414 /* If the button that is getting the focus WAS flagged as the default
2415 * pushbutton then ask the dialog what it thinks the default is and
2416 * set that in the default style.
2417 */
2418 if (dlgcode_next & DLGC_DEFPUSHBUTTON)
2419 {
2420 DWORD def_id = SendMessageW (hwndDlg, DM_GETDEFID, 0, 0);
2421 if (HIWORD(def_id) == DC_HASDEFID)
2422 {
2423 HWND hwndDef;
2424 def_id = LOWORD(def_id);
2425 hwndDef = GetDlgItem (hwndDlg, def_id);
2426 if (hwndDef)
2427 {
2428 INT dlgcode_def = SendMessageW (hwndDef, WM_GETDLGCODE, 0, 0);
2429 /* I know that if it is a button then it should already be a
2430 * UNDEFPUSHBUTTON, since we have just told the buttons to
2431 * change style. But maybe they ignored our request
2432 */
2433 if ((dlgcode_def & DLGC_BUTTON) &&
2434 (dlgcode_def & DLGC_UNDEFPUSHBUTTON))
2435 {
2436 SendMessageW (hwndDef, BM_SETSTYLE, BS_DEFPUSHBUTTON, TRUE);
2437 }
2438 }
2439 }
2440 }
2441 else if ((dlgcode_next & DLGC_BUTTON) && (dlgcode_next & DLGC_UNDEFPUSHBUTTON))
2442 {
2443 SendMessageW (hwndNext, BM_SETSTYLE, BS_DEFPUSHBUTTON, TRUE);
2444 /* I wonder why it doesn't send a DM_SETDEFID */
2445 }
2446 }
2447
2448 /***********************************************************************
2449 * DIALOG_IdToHwnd
2450 *
2451 * A recursive version of GetDlgItem
2452 *
2453 * RETURNS
2454 * The HWND for a Child ID.
2455 */
2456 static HWND DIALOG_IdToHwnd( HWND hwndDlg, INT id )
2457 {
2458 int i;
2459 HWND *list = WIN_ListChildren( hwndDlg );
2460 HWND ret = 0;
2461
2462 if (!list) return 0;
2463
2464 for (i = 0; list[i]; i++)
2465 {
2466 if (GetWindowLongPtrW( list[i], GWLP_ID ) == id)
2467 {
2468 ret = list[i];
2469 break;
2470 }
2471
2472 /* Recurse into every child */
2473 if ((ret = DIALOG_IdToHwnd( list[i], id ))) break;
2474 }
2475
2476 HeapFree( GetProcessHeap(), 0, list );
2477 return ret;
2478 }
2479
2480
2481 /*
2482 * @implemented
2483 */
2484 BOOL
2485 WINAPI
2486 IsDialogMessageW(
2487 HWND hDlg,
2488 LPMSG lpMsg)
2489 {
2490 INT dlgCode = 0;
2491
2492 if (CallMsgFilterW( lpMsg, MSGF_DIALOGBOX )) return TRUE;
2493
2494 if (hDlg == GetDesktopWindow()) return FALSE;
2495 if ((hDlg != lpMsg->hwnd) && !IsChild( hDlg, lpMsg->hwnd )) return FALSE;
2496
2497 hDlg = DIALOG_FindMsgDestination(hDlg);
2498
2499 switch(lpMsg->message)
2500 {
2501 case WM_KEYDOWN:
2502 dlgCode = SendMessageW( lpMsg->hwnd, WM_GETDLGCODE, lpMsg->wParam, (LPARAM)lpMsg );
2503 if (dlgCode & DLGC_WANTMESSAGE) break;
2504
2505 switch(lpMsg->wParam)
2506 {
2507 case VK_TAB:
2508 if (!(dlgCode & DLGC_WANTTAB))
2509 {
2510 BOOL fIsDialog = TRUE;
2511 WND *pWnd = ValidateHwnd(hDlg);
2512
2513 if (pWnd && TestWindowProcess(pWnd))
2514 {
2515 fIsDialog = (GETDLGINFO(hDlg) != NULL);
2516 }
2517
2518 SendMessageW(hDlg, WM_CHANGEUISTATE, MAKEWPARAM(UIS_CLEAR, UISF_HIDEFOCUS), 0);
2519
2520 /* I am not sure under which circumstances the TAB is handled
2521 * each way. All I do know is that it does not always simply
2522 * send WM_NEXTDLGCTL. (Personally I have never yet seen it
2523 * do so but I presume someone has)
2524 */
2525 if (fIsDialog)
2526 SendMessageW( hDlg, WM_NEXTDLGCTL, (GetKeyState(VK_SHIFT) & 0x8000), 0 );
2527 else
2528 {
2529 /* It would appear that GetNextDlgTabItem can handle being
2530 * passed hwndDlg rather than NULL but that is undocumented
2531 * so let's do it properly
2532 */
2533 HWND hwndFocus = GetFocus();
2534 HWND hwndNext = GetNextDlgTabItem (hDlg,
2535 hwndFocus == hDlg ? NULL : hwndFocus,
2536 GetKeyState (VK_SHIFT) & 0x8000);
2537 if (hwndNext)
2538 {
2539 dlgCode = SendMessageW (hwndNext, WM_GETDLGCODE,
2540 lpMsg->wParam, (LPARAM)lpMsg);
2541 if (dlgCode & DLGC_HASSETSEL)
2542 {
2543 INT maxlen = 1 + SendMessageW (hwndNext, WM_GETTEXTLENGTH, 0, 0);
2544 WCHAR *buffer = HeapAlloc (GetProcessHeap(), 0, maxlen * sizeof(WCHAR));
2545 if (buffer)
2546 {
2547 INT length;
2548 SendMessageW (hwndNext, WM_GETTEXT, maxlen, (LPARAM) buffer);
2549 length = strlenW (buffer);
2550 HeapFree (GetProcessHeap(), 0, buffer);
2551 SendMessageW (hwndNext, EM_SETSEL, 0, length);
2552 }
2553 }
2554 SetFocus (hwndNext);
2555 DIALOG_FixChildrenOnChangeFocus (hDlg, hwndNext);
2556 }
2557 else
2558 return FALSE;
2559 }
2560 return TRUE;
2561 }
2562 break;
2563
2564 case VK_RIGHT:
2565 case VK_DOWN:
2566 case VK_LEFT:
2567 case VK_UP:
2568 if (!(dlgCode & DLGC_WANTARROWS))
2569 {
2570 BOOL fPrevious = (lpMsg->wParam == VK_LEFT || lpMsg->wParam == VK_UP);
2571 HWND hwndNext = GetNextDlgGroupItem (hDlg, GetFocus(), fPrevious );
2572 SendMessageW( hDlg, WM_NEXTDLGCTL, (WPARAM)hwndNext, 1 );
2573 return TRUE;
2574 }
2575 break;
2576
2577 case VK_CANCEL:
2578 case VK_ESCAPE:
2579 SendMessageW( hDlg, WM_COMMAND, IDCANCEL, (LPARAM)GetDlgItem( hDlg, IDCANCEL ) );
2580 return TRUE;
2581
2582 case VK_EXECUTE:
2583 case VK_RETURN:
2584 {
2585 DWORD dw;
2586 if ((GetFocus() == lpMsg->hwnd) &&
2587 (SendMessageW (lpMsg->hwnd, WM_GETDLGCODE, 0, 0) & DLGC_DEFPUSHBUTTON))
2588 {
2589 SendMessageW (hDlg, WM_COMMAND, MAKEWPARAM (GetDlgCtrlID(lpMsg->hwnd),BN_CLICKED), (LPARAM)lpMsg->hwnd);
2590 }
2591 else if (DC_HASDEFID == HIWORD(dw = SendMessageW (hDlg, DM_GETDEFID, 0, 0)))
2592 {
2593 HWND hwndDef = DIALOG_IdToHwnd(hDlg, LOWORD(dw));
2594 if (!hwndDef || IsWindowEnabled(hwndDef))
2595 SendMessageW( hDlg, WM_COMMAND, MAKEWPARAM( LOWORD(dw), BN_CLICKED ), (LPARAM)hwndDef);
2596 }
2597 else
2598 {
2599 SendMessageW( hDlg, WM_COMMAND, IDOK, (LPARAM)GetDlgItem( hDlg, IDOK ) );
2600
2601 }
2602 }
2603 return TRUE;
2604 }
2605 break;
2606
2607 case WM_CHAR:
2608 /* FIXME Under what circumstances does WM_GETDLGCODE get sent?
2609 * It does NOT get sent in the test program I have
2610 */
2611 dlgCode = SendMessageW( lpMsg->hwnd, WM_GETDLGCODE, lpMsg->wParam, (LPARAM)lpMsg );
2612 if (dlgCode & (DLGC_WANTCHARS|DLGC_WANTMESSAGE)) break;
2613 if (lpMsg->wParam == '\t' && (dlgCode & DLGC_WANTTAB)) break;
2614 /* drop through */
2615
2616 case WM_SYSCHAR:
2617 if (DIALOG_IsAccelerator( lpMsg->hwnd, hDlg, lpMsg->wParam ))
2618 {
2619 /* don't translate or dispatch */
2620 return TRUE;
2621 }
2622 break;
2623 //// ReactOS
2624 case WM_SYSKEYDOWN:
2625 /* If the ALT key is being pressed display the keyboard cues */
2626 if ( HIWORD(lpMsg->lParam) & KF_ALTDOWN &&
2627 !(gpsi->dwSRVIFlags & SRVINFO_KBDPREF) && !(gpsi->PUSIFlags & PUSIF_KEYBOARDCUES) )
2628 SendMessageW(hDlg, WM_CHANGEUISTATE, MAKEWPARAM(UIS_CLEAR, UISF_HIDEACCEL | UISF_HIDEFOCUS), 0);
2629 break;
2630
2631 case WM_SYSCOMMAND:
2632 /* If the ALT key is being pressed display the keyboard cues */
2633 if ( lpMsg->wParam == SC_KEYMENU &&
2634 !(gpsi->dwSRVIFlags & SRVINFO_KBDPREF) && !(gpsi->PUSIFlags & PUSIF_KEYBOARDCUES) )
2635 {
2636 SendMessageW(hDlg, WM_CHANGEUISTATE, MAKEWPARAM(UIS_CLEAR, UISF_HIDEACCEL | UISF_HIDEFOCUS), 0);
2637 }
2638 break;
2639 }
2640
2641 TranslateMessage( lpMsg );
2642 DispatchMessageW( lpMsg );
2643 return TRUE;
2644 }
2645
2646
2647 /*
2648 * @implemented
2649 */
2650 UINT
2651 WINAPI
2652 IsDlgButtonChecked(
2653 HWND hDlg,
2654 int nIDButton)
2655 {
2656 return (UINT)SendDlgItemMessageW( hDlg, nIDButton, BM_GETCHECK, 0, 0 );
2657 }
2658
2659
2660 /*
2661 * @implemented
2662 */
2663 BOOL
2664 WINAPI
2665 MapDialogRect(
2666 HWND hDlg,
2667 LPRECT lpRect)
2668 {
2669 DIALOGINFO * dlgInfo;
2670 if (!(dlgInfo = GETDLGINFO(hDlg))) return FALSE;
2671 lpRect->left = MulDiv(lpRect->left, dlgInfo->xBaseUnit, 4);
2672 lpRect->right = MulDiv(lpRect->right, dlgInfo->xBaseUnit, 4);
2673 lpRect->top = MulDiv(lpRect->top, dlgInfo->yBaseUnit, 8);
2674 lpRect->bottom = MulDiv(lpRect->bottom, dlgInfo->yBaseUnit, 8);
2675 return TRUE;
2676 }
2677
2678
2679 /*
2680 * @implemented
2681 */
2682 LRESULT
2683 WINAPI
2684 SendDlgItemMessageA(
2685 HWND hDlg,
2686 int nIDDlgItem,
2687 UINT Msg,
2688 WPARAM wParam,
2689 LPARAM lParam)
2690 {
2691 HWND hwndCtrl;
2692 if ( hDlg == HWND_TOPMOST || hDlg == HWND_BROADCAST ) return 0; // ReactOS
2693 hwndCtrl = GetDlgItem( hDlg, nIDDlgItem );
2694 if (hwndCtrl) return SendMessageA( hwndCtrl, Msg, wParam, lParam );
2695 else return 0;
2696 }
2697
2698
2699 /*
2700 * @implemented
2701 */
2702 LRESULT
2703 WINAPI
2704 SendDlgItemMessageW(
2705 HWND hDlg,
2706 int nIDDlgItem,
2707 UINT Msg,
2708 WPARAM wParam,
2709 LPARAM lParam)
2710 {
2711 HWND hwndCtrl;
2712 if ( hDlg == HWND_TOPMOST || hDlg == HWND_BROADCAST ) return 0; // ReactOS
2713 hwndCtrl = GetDlgItem( hDlg, nIDDlgItem );
2714 if (hwndCtrl) return SendMessageW( hwndCtrl, Msg, wParam, lParam );
2715 else return 0;
2716 }
2717
2718
2719 /*
2720 * @implemented
2721 */
2722 BOOL
2723 WINAPI
2724 SetDlgItemInt(
2725 HWND hDlg,
2726 int nIDDlgItem,
2727 UINT uValue,
2728 BOOL bSigned)
2729 {
2730 char str[20];
2731
2732 if (bSigned) sprintf( str, "%d", (INT)uValue );
2733 else sprintf( str, "%u", uValue );
2734 SendDlgItemMessageA( hDlg, nIDDlgItem, WM_SETTEXT, 0, (LPARAM)str );
2735 return TRUE;
2736 }
2737
2738
2739 /*
2740 * @implemented
2741 */
2742 BOOL
2743 WINAPI
2744 SetDlgItemTextA(
2745 HWND hDlg,
2746 int nIDDlgItem,
2747 LPCSTR lpString)
2748 {
2749 HWND hwndCtrl = GetDlgItem( hDlg, nIDDlgItem ); // ReactOS Themes
2750 if (hwndCtrl) return SetWindowTextA( hwndCtrl, lpString );
2751 return FALSE;
2752 }
2753
2754
2755 /*
2756 * @implemented
2757 */
2758 BOOL
2759 WINAPI
2760 SetDlgItemTextW(
2761 HWND hDlg,
2762 int nIDDlgItem,
2763 LPCWSTR lpString)
2764 {
2765 HWND hwndCtrl = GetDlgItem( hDlg, nIDDlgItem ); // ReactOS Themes
2766 if (hwndCtrl) return SetWindowTextW( hwndCtrl, lpString );
2767 return FALSE;
2768 }
2769
2770
2771 /*
2772 * @implemented
2773 */
2774 BOOL
2775 WINAPI
2776 CheckDlgButton(
2777 HWND hDlg,
2778 int nIDButton,
2779 UINT uCheck)
2780 {
2781 SendDlgItemMessageW( hDlg, nIDButton, BM_SETCHECK, uCheck, 0 );
2782 return TRUE;
2783 }
2784
2785 static BOOL CALLBACK CheckRB(HWND hwnd, LPARAM lParam)
2786 {
2787 LONG lChildID = GetWindowLongPtrW(hwnd, GWLP_ID);
2788 RADIOGROUP *lpRadioGroup = (RADIOGROUP *)lParam;
2789
2790 if((lChildID >= lpRadioGroup->firstID) &&
2791 (lChildID <= lpRadioGroup->lastID))
2792 {
2793 if (lChildID == lpRadioGroup->checkID)
2794 {
2795 SendMessageW(hwnd, BM_SETCHECK, BST_CHECKED, 0);
2796 }
2797 else
2798 {
2799 SendMessageW(hwnd, BM_SETCHECK, BST_UNCHECKED, 0);
2800 }
2801 }
2802
2803 return TRUE;
2804 }
2805
2806 /*
2807 * @implemented
2808 */
2809 BOOL
2810 WINAPI
2811 CheckRadioButton(
2812 HWND hDlg,
2813 int nIDFirstButton,
2814 int nIDLastButton,
2815 int nIDCheckButton)
2816 {
2817 RADIOGROUP radioGroup;
2818
2819 radioGroup.firstID = nIDFirstButton;
2820 radioGroup.lastID = nIDLastButton;
2821 radioGroup.checkID = nIDCheckButton;
2822
2823 return EnumChildWindows(hDlg, CheckRB, (LPARAM)&radioGroup);
2824 }