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