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