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