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