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