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