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