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