Documentation fixes.
[wine/testsucceed.git] / windows / dialog.c
blob449b016239d126fbe75931da835f6e9a91ba4092
1 /*
2 * Dialog functions
4 * Copyright 1993, 1994, 1996 Alexandre Julliard
5 */
7 #include <ctype.h>
8 #include <errno.h>
9 #include <limits.h>
10 #include <stdlib.h>
11 #include <stdio.h>
12 #include <string.h>
14 #include "windef.h"
15 #include "winnls.h"
16 #include "winbase.h"
17 #include "wingdi.h"
18 #include "winuser.h"
19 #include "windowsx.h"
20 #include "wine/winuser16.h"
21 #include "wine/winbase16.h"
22 #include "wine/unicode.h"
23 #include "wine/port.h"
24 #include "controls.h"
25 #include "heap.h"
26 #include "win.h"
27 #include "user.h"
28 #include "message.h"
29 #include "debugtools.h"
31 DEFAULT_DEBUG_CHANNEL(dialog);
34 /* Dialog control information */
35 typedef struct
37 DWORD style;
38 DWORD exStyle;
39 DWORD helpId;
40 INT16 x;
41 INT16 y;
42 INT16 cx;
43 INT16 cy;
44 UINT id;
45 LPCSTR className;
46 LPCSTR windowName;
47 LPVOID data;
48 } DLG_CONTROL_INFO;
50 /* Dialog template */
51 typedef struct
53 DWORD style;
54 DWORD exStyle;
55 DWORD helpId;
56 UINT16 nbItems;
57 INT16 x;
58 INT16 y;
59 INT16 cx;
60 INT16 cy;
61 LPCSTR menuName;
62 LPCSTR className;
63 LPCSTR caption;
64 WORD pointSize;
65 WORD weight;
66 BOOL italic;
67 LPCSTR faceName;
68 BOOL dialogEx;
69 } DLG_TEMPLATE;
71 /* Radio button group */
72 typedef struct
74 UINT firstID;
75 UINT lastID;
76 UINT checkID;
77 } RADIOGROUP;
79 /* Dialog base units */
80 static WORD xBaseUnit = 0, yBaseUnit = 0;
83 /*********************************************************************
84 * dialog class descriptor
86 const struct builtin_class_descr DIALOG_builtin_class =
88 DIALOG_CLASS_ATOM, /* name */
89 CS_GLOBALCLASS | CS_SAVEBITS, /* style */
90 DefDlgProcA, /* procA */
91 DefDlgProcW, /* procW */
92 DLGWINDOWEXTRA, /* extra */
93 IDC_ARROWA, /* cursor */
94 0 /* brush */
98 /***********************************************************************
99 * DIALOG_EnableOwner
101 * Helper function for modal dialogs to enable again the
102 * owner of the dialog box.
104 void DIALOG_EnableOwner( HWND hOwner, BOOL ownerWasEnabled)
106 /* Owner must be a top-level window */
107 if (hOwner)
108 hOwner = WIN_GetTopParent( hOwner );
109 if (!hOwner) return;
110 if (ownerWasEnabled)
111 EnableWindow( hOwner, TRUE );
115 /***********************************************************************
116 * DIALOG_DisableOwner
118 * Helper function for modal dialogs to disable the
119 * owner of the dialog box. Returns TRUE if owner was enabled.
121 BOOL DIALOG_DisableOwner( HWND hOwner )
123 /* Owner must be a top-level window */
124 if (hOwner)
125 hOwner = WIN_GetTopParent( hOwner );
126 if (!hOwner) return FALSE;
127 if (IsWindowEnabled( hOwner ))
129 EnableWindow( hOwner, FALSE );
130 return TRUE;
132 else
133 return FALSE;
136 /***********************************************************************
137 * DIALOG_GetCharSizeFromDC
140 * Calculates the *true* average size of English characters in the
141 * specified font as oppposed to the one returned by GetTextMetrics.
143 * Latest: the X font driver will now compute a proper average width
144 * so this code can be removed
146 static BOOL DIALOG_GetCharSizeFromDC( HDC hDC, HFONT hFont, SIZE * pSize )
148 BOOL Success = FALSE;
149 HFONT hFontPrev = 0;
150 pSize->cx = xBaseUnit;
151 pSize->cy = yBaseUnit;
152 if ( hDC )
154 /* select the font */
155 TEXTMETRICA tm;
156 memset(&tm,0,sizeof(tm));
157 if (hFont) hFontPrev = SelectFont(hDC,hFont);
158 if (GetTextMetricsA(hDC,&tm))
160 pSize->cx = tm.tmAveCharWidth;
161 pSize->cy = tm.tmHeight;
163 /* if variable width font */
164 if (tm.tmPitchAndFamily & TMPF_FIXED_PITCH)
166 SIZE total;
167 const char* szAvgChars = "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ";
169 /* Calculate a true average as opposed to the one returned
170 * by tmAveCharWidth. This works better when dealing with
171 * proportional spaced fonts and (more important) that's
172 * how Microsoft's dialog creation code calculates the size
173 * of the font
175 if (GetTextExtentPointA(hDC,szAvgChars,sizeof(szAvgChars),&total))
177 /* round up */
178 pSize->cx = ((2*total.cx/sizeof(szAvgChars)) + 1)/2;
179 Success = TRUE;
182 else
184 Success = TRUE;
186 /* Use the text metrics */
187 TRACE("Using tm: %ldx%ld (dlg: %ld x %ld) (%s)\n",
188 tm.tmAveCharWidth, tm.tmHeight, pSize->cx, pSize->cy,
189 tm.tmPitchAndFamily & TMPF_FIXED_PITCH ? "variable" : "fixed");
190 pSize->cx = tm.tmAveCharWidth;
191 pSize->cy = tm.tmHeight;
193 /* select the original font */
194 if (hFontPrev) SelectFont(hDC,hFontPrev);
196 return (Success);
199 /***********************************************************************
200 * DIALOG_GetCharSize
202 * A convenient variant of DIALOG_GetCharSizeFromDC.
204 static BOOL DIALOG_GetCharSize( HFONT hFont, SIZE * pSize )
206 HDC hDC = GetDC(0);
207 BOOL Success = DIALOG_GetCharSizeFromDC( hDC, hFont, pSize );
208 ReleaseDC(0, hDC);
209 return Success;
212 /***********************************************************************
213 * DIALOG_Init
215 * Initialisation of the dialog manager.
217 BOOL DIALOG_Init(void)
219 HDC hdc;
220 SIZE size;
222 /* Calculate the dialog base units */
224 if (!(hdc = CreateDCA( "DISPLAY", NULL, NULL, NULL )))
226 ERR("Could not create Display DC\n");
227 return FALSE;
230 if (!DIALOG_GetCharSizeFromDC( hdc, 0, &size ))
232 DeleteDC( hdc );
233 ERR("Could not initialize base dialog units\n");
234 return FALSE;
237 DeleteDC( hdc );
238 xBaseUnit = size.cx;
239 yBaseUnit = size.cy;
241 TRACE("base units = %d,%d\n", xBaseUnit, yBaseUnit );
242 return TRUE;
246 /***********************************************************************
247 * DIALOG_GetControl16
249 * Return the class and text of the control pointed to by ptr,
250 * fill the header structure and return a pointer to the next control.
252 static LPCSTR DIALOG_GetControl16( LPCSTR p, DLG_CONTROL_INFO *info )
254 static char buffer[10];
255 int int_id;
257 info->x = GET_WORD(p); p += sizeof(WORD);
258 info->y = GET_WORD(p); p += sizeof(WORD);
259 info->cx = GET_WORD(p); p += sizeof(WORD);
260 info->cy = GET_WORD(p); p += sizeof(WORD);
261 info->id = GET_WORD(p); p += sizeof(WORD);
262 info->style = GET_DWORD(p); p += sizeof(DWORD);
263 info->exStyle = 0;
265 if (*p & 0x80)
267 switch((BYTE)*p)
269 case 0x80: strcpy( buffer, "BUTTON" ); break;
270 case 0x81: strcpy( buffer, "EDIT" ); break;
271 case 0x82: strcpy( buffer, "STATIC" ); break;
272 case 0x83: strcpy( buffer, "LISTBOX" ); break;
273 case 0x84: strcpy( buffer, "SCROLLBAR" ); break;
274 case 0x85: strcpy( buffer, "COMBOBOX" ); break;
275 default: buffer[0] = '\0'; break;
277 info->className = buffer;
278 p++;
280 else
282 info->className = p;
283 p += strlen(p) + 1;
286 int_id = ((BYTE)*p == 0xff);
287 if (int_id)
289 /* Integer id, not documented (?). Only works for SS_ICON controls */
290 info->windowName = (LPCSTR)(UINT)GET_WORD(p+1);
291 p += 3;
293 else
295 info->windowName = p;
296 p += strlen(p) + 1;
299 if (*p)
301 /* Additional CTLDATA available for this control. */
302 info->data = SEGPTR_ALLOC(*p);
303 memcpy( info->data, p + 1, *p );
305 else info->data = NULL;
307 p += *p + 1;
309 if(int_id)
310 TRACE(" %s %04x %d, %d, %d, %d, %d, %08lx, %08lx\n",
311 info->className, LOWORD(info->windowName),
312 info->id, info->x, info->y, info->cx, info->cy,
313 info->style, (DWORD)SEGPTR_GET(info->data) );
314 else
315 TRACE(" %s '%s' %d, %d, %d, %d, %d, %08lx, %08lx\n",
316 info->className, info->windowName,
317 info->id, info->x, info->y, info->cx, info->cy,
318 info->style, (DWORD)SEGPTR_GET(info->data) );
320 return p;
324 /***********************************************************************
325 * DIALOG_GetControl32
327 * Return the class and text of the control pointed to by ptr,
328 * fill the header structure and return a pointer to the next control.
330 static const WORD *DIALOG_GetControl32( const WORD *p, DLG_CONTROL_INFO *info,
331 BOOL dialogEx )
333 if (dialogEx)
335 info->helpId = GET_DWORD(p); p += 2;
336 info->exStyle = GET_DWORD(p); p += 2;
337 info->style = GET_DWORD(p); p += 2;
339 else
341 info->helpId = 0;
342 info->style = GET_DWORD(p); p += 2;
343 info->exStyle = GET_DWORD(p); p += 2;
345 info->x = GET_WORD(p); p++;
346 info->y = GET_WORD(p); p++;
347 info->cx = GET_WORD(p); p++;
348 info->cy = GET_WORD(p); p++;
350 if (dialogEx)
352 /* id is a DWORD for DIALOGEX */
353 info->id = GET_DWORD(p);
354 p += 2;
356 else
358 info->id = GET_WORD(p);
359 p++;
362 if (GET_WORD(p) == 0xffff)
364 static const WCHAR class_names[6][10] =
366 { 'B','u','t','t','o','n', }, /* 0x80 */
367 { 'E','d','i','t', }, /* 0x81 */
368 { 'S','t','a','t','i','c', }, /* 0x82 */
369 { 'L','i','s','t','B','o','x', }, /* 0x83 */
370 { 'S','c','r','o','l','l','B','a','r', }, /* 0x84 */
371 { 'C','o','m','b','o','B','o','x', } /* 0x85 */
373 WORD id = GET_WORD(p+1);
374 if ((id >= 0x80) && (id <= 0x85))
375 info->className = (LPCSTR)class_names[id - 0x80];
376 else
378 info->className = NULL;
379 ERR("Unknown built-in class id %04x\n", id );
381 p += 2;
383 else
385 info->className = (LPCSTR)p;
386 p += strlenW( (LPCWSTR)p ) + 1;
389 if (GET_WORD(p) == 0xffff) /* Is it an integer id? */
391 info->windowName = (LPCSTR)(UINT)GET_WORD(p + 1);
392 p += 2;
394 else
396 info->windowName = (LPCSTR)p;
397 p += strlenW( (LPCWSTR)p ) + 1;
400 TRACE(" %s %s %d, %d, %d, %d, %d, %08lx, %08lx, %08lx\n",
401 debugstr_w( (LPCWSTR)info->className ),
402 debugres_w( (LPCWSTR)info->windowName ),
403 info->id, info->x, info->y, info->cx, info->cy,
404 info->style, info->exStyle, info->helpId );
406 if (GET_WORD(p))
408 if (TRACE_ON(dialog))
410 WORD i, count = GET_WORD(p) / sizeof(WORD);
411 TRACE(" BEGIN\n");
412 TRACE(" ");
413 for (i = 0; i < count; i++) DPRINTF( "%04x,", GET_WORD(p+i+1) );
414 DPRINTF("\n");
415 TRACE(" END\n" );
417 info->data = (LPVOID)(p + 1);
418 p += GET_WORD(p) / sizeof(WORD);
420 else info->data = NULL;
421 p++;
423 /* Next control is on dword boundary */
424 return (const WORD *)((((int)p) + 3) & ~3);
428 /***********************************************************************
429 * DIALOG_CreateControls
431 * Create the control windows for a dialog.
433 static BOOL DIALOG_CreateControls( WND *pWnd, LPCSTR template,
434 const DLG_TEMPLATE *dlgTemplate,
435 HINSTANCE hInst, BOOL win32 )
437 DIALOGINFO *dlgInfo = (DIALOGINFO *)pWnd->wExtra;
438 DLG_CONTROL_INFO info;
439 HWND hwndCtrl, hwndDefButton = 0;
440 INT items = dlgTemplate->nbItems;
442 TRACE(" BEGIN\n" );
443 while (items--)
445 if (!win32)
447 HINSTANCE16 instance;
448 template = DIALOG_GetControl16( template, &info );
449 if (HIWORD(info.className) && !strcmp( info.className, "EDIT") &&
450 ((pWnd->dwStyle & DS_LOCALEDIT) != DS_LOCALEDIT))
452 if (!dlgInfo->hDialogHeap)
454 dlgInfo->hDialogHeap = GlobalAlloc16(GMEM_FIXED, 0x10000);
455 if (!dlgInfo->hDialogHeap)
457 ERR("Insufficient memory to create heap for edit control\n" );
458 continue;
460 LocalInit16(dlgInfo->hDialogHeap, 0, 0xffff);
462 instance = dlgInfo->hDialogHeap;
464 else instance = (HINSTANCE16)hInst;
466 hwndCtrl = CreateWindowEx16( info.exStyle | WS_EX_NOPARENTNOTIFY,
467 info.className, info.windowName,
468 info.style | WS_CHILD,
469 MulDiv(info.x, dlgInfo->xBaseUnit, 4),
470 MulDiv(info.y, dlgInfo->yBaseUnit, 8),
471 MulDiv(info.cx, dlgInfo->xBaseUnit, 4),
472 MulDiv(info.cy, dlgInfo->yBaseUnit, 8),
473 pWnd->hwndSelf, (HMENU16)info.id,
474 instance, (LPVOID)SEGPTR_GET(info.data) );
476 if (info.data) SEGPTR_FREE(info.data);
478 else
480 template = (LPCSTR)DIALOG_GetControl32( (WORD *)template, &info,
481 dlgTemplate->dialogEx );
482 /* Is this it? */
483 if (info.style & WS_BORDER)
485 info.style &= ~WS_BORDER;
486 info.exStyle |= WS_EX_CLIENTEDGE;
488 hwndCtrl = CreateWindowExW( info.exStyle | WS_EX_NOPARENTNOTIFY,
489 (LPCWSTR)info.className,
490 (LPCWSTR)info.windowName,
491 info.style | WS_CHILD,
492 MulDiv(info.x, dlgInfo->xBaseUnit, 4),
493 MulDiv(info.y, dlgInfo->yBaseUnit, 8),
494 MulDiv(info.cx, dlgInfo->xBaseUnit, 4),
495 MulDiv(info.cy, dlgInfo->yBaseUnit, 8),
496 pWnd->hwndSelf, (HMENU)info.id,
497 hInst, info.data );
499 if (!hwndCtrl) return FALSE;
501 /* Send initialisation messages to the control */
502 if (dlgInfo->hUserFont) SendMessageA( hwndCtrl, WM_SETFONT,
503 (WPARAM)dlgInfo->hUserFont, 0 );
504 if (SendMessageA(hwndCtrl, WM_GETDLGCODE, 0, 0) & DLGC_DEFPUSHBUTTON)
506 /* If there's already a default push-button, set it back */
507 /* to normal and use this one instead. */
508 if (hwndDefButton)
509 SendMessageA( hwndDefButton, BM_SETSTYLE,
510 BS_PUSHBUTTON,FALSE );
511 hwndDefButton = hwndCtrl;
512 dlgInfo->idResult = GetWindowWord( hwndCtrl, GWW_ID );
515 TRACE(" END\n" );
516 return TRUE;
520 /***********************************************************************
521 * DIALOG_ParseTemplate16
523 * Fill a DLG_TEMPLATE structure from the dialog template, and return
524 * a pointer to the first control.
526 static LPCSTR DIALOG_ParseTemplate16( LPCSTR p, DLG_TEMPLATE * result )
528 result->style = GET_DWORD(p); p += sizeof(DWORD);
529 result->exStyle = 0;
530 result->nbItems = (unsigned char) *p++;
531 result->x = GET_WORD(p); p += sizeof(WORD);
532 result->y = GET_WORD(p); p += sizeof(WORD);
533 result->cx = GET_WORD(p); p += sizeof(WORD);
534 result->cy = GET_WORD(p); p += sizeof(WORD);
535 TRACE("DIALOG %d, %d, %d, %d\n",
536 result->x, result->y, result->cx, result->cy );
537 TRACE(" STYLE %08lx\n", result->style );
539 /* Get the menu name */
541 switch( (BYTE)*p )
543 case 0:
544 result->menuName = 0;
545 p++;
546 break;
547 case 0xff:
548 result->menuName = (LPCSTR)(UINT)GET_WORD( p + 1 );
549 p += 3;
550 TRACE(" MENU %04x\n", LOWORD(result->menuName) );
551 break;
552 default:
553 result->menuName = p;
554 TRACE(" MENU '%s'\n", p );
555 p += strlen(p) + 1;
556 break;
559 /* Get the class name */
561 if (*p)
563 result->className = p;
564 TRACE(" CLASS '%s'\n", result->className );
566 else result->className = DIALOG_CLASS_ATOM;
567 p += strlen(p) + 1;
569 /* Get the window caption */
571 result->caption = p;
572 p += strlen(p) + 1;
573 TRACE(" CAPTION '%s'\n", result->caption );
575 /* Get the font name */
577 if (result->style & DS_SETFONT)
579 result->pointSize = GET_WORD(p);
580 p += sizeof(WORD);
581 result->faceName = p;
582 p += strlen(p) + 1;
583 TRACE(" FONT %d,'%s'\n",
584 result->pointSize, result->faceName );
586 return p;
590 /***********************************************************************
591 * DIALOG_ParseTemplate32
593 * Fill a DLG_TEMPLATE structure from the dialog template, and return
594 * a pointer to the first control.
596 static LPCSTR DIALOG_ParseTemplate32( LPCSTR template, DLG_TEMPLATE * result )
598 const WORD *p = (const WORD *)template;
600 result->style = GET_DWORD(p); p += 2;
601 if (result->style == 0xffff0001) /* DIALOGEX resource */
603 result->dialogEx = TRUE;
604 result->helpId = GET_DWORD(p); p += 2;
605 result->exStyle = GET_DWORD(p); p += 2;
606 result->style = GET_DWORD(p); p += 2;
608 else
610 result->dialogEx = FALSE;
611 result->helpId = 0;
612 result->exStyle = GET_DWORD(p); p += 2;
614 result->nbItems = GET_WORD(p); p++;
615 result->x = GET_WORD(p); p++;
616 result->y = GET_WORD(p); p++;
617 result->cx = GET_WORD(p); p++;
618 result->cy = GET_WORD(p); p++;
619 TRACE("DIALOG%s %d, %d, %d, %d, %ld\n",
620 result->dialogEx ? "EX" : "", result->x, result->y,
621 result->cx, result->cy, result->helpId );
622 TRACE(" STYLE 0x%08lx\n", result->style );
623 TRACE(" EXSTYLE 0x%08lx\n", result->exStyle );
625 /* Get the menu name */
627 switch(GET_WORD(p))
629 case 0x0000:
630 result->menuName = NULL;
631 p++;
632 break;
633 case 0xffff:
634 result->menuName = (LPCSTR)(UINT)GET_WORD( p + 1 );
635 p += 2;
636 TRACE(" MENU %04x\n", LOWORD(result->menuName) );
637 break;
638 default:
639 result->menuName = (LPCSTR)p;
640 TRACE(" MENU %s\n", debugstr_w( (LPCWSTR)p ));
641 p += strlenW( (LPCWSTR)p ) + 1;
642 break;
645 /* Get the class name */
647 switch(GET_WORD(p))
649 case 0x0000:
650 result->className = DIALOG_CLASS_ATOM;
651 p++;
652 break;
653 case 0xffff:
654 result->className = (LPCSTR)(UINT)GET_WORD( p + 1 );
655 p += 2;
656 TRACE(" CLASS %04x\n", LOWORD(result->className) );
657 break;
658 default:
659 result->className = (LPCSTR)p;
660 TRACE(" CLASS %s\n", debugstr_w( (LPCWSTR)p ));
661 p += strlenW( (LPCWSTR)p ) + 1;
662 break;
665 /* Get the window caption */
667 result->caption = (LPCSTR)p;
668 p += strlenW( (LPCWSTR)p ) + 1;
669 TRACE(" CAPTION %s\n", debugstr_w( (LPCWSTR)result->caption ) );
671 /* Get the font name */
673 if (result->style & DS_SETFONT)
675 result->pointSize = GET_WORD(p);
676 p++;
677 if (result->dialogEx)
679 result->weight = GET_WORD(p); p++;
680 result->italic = LOBYTE(GET_WORD(p)); p++;
682 else
684 result->weight = FW_DONTCARE;
685 result->italic = FALSE;
687 result->faceName = (LPCSTR)p;
688 p += strlenW( (LPCWSTR)p ) + 1;
689 TRACE(" FONT %d, %s, %d, %s\n",
690 result->pointSize, debugstr_w( (LPCWSTR)result->faceName ),
691 result->weight, result->italic ? "TRUE" : "FALSE" );
694 /* First control is on dword boundary */
695 return (LPCSTR)((((int)p) + 3) & ~3);
699 /***********************************************************************
700 * DIALOG_CreateIndirect
701 * Creates a dialog box window
703 * modal = TRUE if we are called from a modal dialog box.
704 * (it's more compatible to do it here, as under Windows the owner
705 * is never disabled if the dialog fails because of an invalid template)
707 static HWND DIALOG_CreateIndirect( HINSTANCE hInst, LPCSTR dlgTemplate,
708 BOOL win32Template, HWND owner,
709 DLGPROC16 dlgProc, LPARAM param,
710 WINDOWPROCTYPE procType, BOOL modal )
712 HMENU16 hMenu = 0;
713 HFONT16 hFont = 0;
714 HWND hwnd;
715 RECT rect;
716 WND * wndPtr;
717 DLG_TEMPLATE template;
718 DIALOGINFO * dlgInfo;
719 WORD xUnit = xBaseUnit;
720 WORD yUnit = yBaseUnit;
721 BOOL ownerEnabled = TRUE;
723 /* Parse dialog template */
725 if (!dlgTemplate) return 0;
726 if (win32Template)
727 dlgTemplate = DIALOG_ParseTemplate32( dlgTemplate, &template );
728 else
729 dlgTemplate = DIALOG_ParseTemplate16( dlgTemplate, &template );
731 /* Load menu */
733 if (template.menuName)
735 if (!win32Template) hMenu = LoadMenu16( hInst, template.menuName );
736 else hMenu = LoadMenuW( hInst, (LPCWSTR)template.menuName );
739 /* Create custom font if needed */
741 if (template.style & DS_SETFONT)
743 /* The font height must be negative as it is a point size */
744 /* and must be converted to pixels first */
745 /* (see CreateFont() documentation in the Windows SDK). */
746 HDC dc;
747 int pixels;
748 if (((short)template.pointSize) < 0)
749 pixels = -((short)template.pointSize);
750 else
752 dc = GetDC(0);
753 pixels = template.pointSize * GetDeviceCaps(dc , LOGPIXELSY)/72;
754 ReleaseDC(0, dc);
756 if (win32Template)
757 hFont = CreateFontW( -pixels, 0, 0, 0, template.weight,
758 template.italic, FALSE, FALSE,
759 DEFAULT_CHARSET, 0, 0,
760 PROOF_QUALITY, FF_DONTCARE,
761 (LPCWSTR)template.faceName );
762 else
763 hFont = CreateFontA( -pixels, 0, 0, 0, FW_DONTCARE,
764 FALSE, FALSE, FALSE,
765 DEFAULT_CHARSET, 0, 0,
766 PROOF_QUALITY, FF_DONTCARE,
767 template.faceName );
768 if (hFont)
770 SIZE charSize;
771 if (DIALOG_GetCharSize(hFont,&charSize))
773 xUnit = charSize.cx;
774 yUnit = charSize.cy;
777 TRACE("units = %d,%d\n", xUnit, yUnit );
780 /* Create dialog main window */
782 rect.left = rect.top = 0;
783 rect.right = MulDiv(template.cx, xUnit, 4);
784 rect.bottom = MulDiv(template.cy, yUnit, 8);
785 if (template.style & DS_MODALFRAME)
786 template.exStyle |= WS_EX_DLGMODALFRAME;
787 AdjustWindowRectEx( &rect, template.style,
788 hMenu ? TRUE : FALSE , template.exStyle );
789 rect.right -= rect.left;
790 rect.bottom -= rect.top;
792 if ((INT16)template.x == CW_USEDEFAULT16)
794 rect.left = rect.top = win32Template? CW_USEDEFAULT : CW_USEDEFAULT16;
796 else
798 if (template.style & DS_CENTER)
800 rect.left = (GetSystemMetrics(SM_CXSCREEN) - rect.right) / 2;
801 rect.top = (GetSystemMetrics(SM_CYSCREEN) - rect.bottom) / 2;
803 else
805 rect.left += MulDiv(template.x, xUnit, 4);
806 rect.top += MulDiv(template.y, yUnit, 8);
808 if ( !(template.style & WS_CHILD) )
810 INT16 dX, dY;
812 if( !(template.style & DS_ABSALIGN) )
813 ClientToScreen( owner, (POINT *)&rect );
815 /* try to fit it into the desktop */
817 if( (dX = rect.left + rect.right + GetSystemMetrics(SM_CXDLGFRAME)
818 - GetSystemMetrics(SM_CXSCREEN)) > 0 ) rect.left -= dX;
819 if( (dY = rect.top + rect.bottom + GetSystemMetrics(SM_CYDLGFRAME)
820 - GetSystemMetrics(SM_CYSCREEN)) > 0 ) rect.top -= dY;
821 if( rect.left < 0 ) rect.left = 0;
822 if( rect.top < 0 ) rect.top = 0;
826 if (modal)
827 ownerEnabled = DIALOG_DisableOwner( owner );
829 if (!win32Template)
830 hwnd = CreateWindowEx16(template.exStyle, template.className,
831 template.caption, template.style & ~WS_VISIBLE,
832 rect.left, rect.top, rect.right, rect.bottom,
833 owner, hMenu, hInst, NULL );
834 else
835 hwnd = CreateWindowExW(template.exStyle, (LPCWSTR)template.className,
836 (LPCWSTR)template.caption,
837 template.style & ~WS_VISIBLE,
838 rect.left, rect.top, rect.right, rect.bottom,
839 owner, hMenu, hInst, NULL );
841 if (!hwnd)
843 if (hFont) DeleteObject( hFont );
844 if (hMenu) DestroyMenu( hMenu );
845 if (modal)
846 DIALOG_EnableOwner(owner, ownerEnabled);
847 return 0;
849 wndPtr = WIN_FindWndPtr( hwnd );
850 wndPtr->flags |= WIN_ISDIALOG;
851 wndPtr->helpContext = template.helpId;
853 /* Initialise dialog extra data */
855 dlgInfo = (DIALOGINFO *)wndPtr->wExtra;
856 WINPROC_SetProc( &dlgInfo->dlgProc, (WNDPROC16)dlgProc, procType, WIN_PROC_WINDOW );
857 dlgInfo->hUserFont = hFont;
858 dlgInfo->hMenu = hMenu;
859 dlgInfo->xBaseUnit = xUnit;
860 dlgInfo->yBaseUnit = yUnit;
861 dlgInfo->msgResult = 0;
862 dlgInfo->idResult = 0;
863 dlgInfo->flags = ownerEnabled ? DF_OWNERENABLED: 0;
864 dlgInfo->hDialogHeap = 0;
866 if (dlgInfo->hUserFont)
867 SendMessageA( hwnd, WM_SETFONT, (WPARAM)dlgInfo->hUserFont, 0 );
869 /* Create controls */
871 if (DIALOG_CreateControls( wndPtr, dlgTemplate, &template,
872 hInst, win32Template ))
874 HWND hwndPreInitFocus;
876 /* Send initialisation messages and set focus */
878 dlgInfo->hwndFocus = GetNextDlgTabItem( hwnd, 0, FALSE );
880 hwndPreInitFocus = GetFocus();
881 if (SendMessageA( hwnd, WM_INITDIALOG, (WPARAM)dlgInfo->hwndFocus, param ))
883 /* check where the focus is again,
884 * some controls status might have changed in WM_INITDIALOG */
885 dlgInfo->hwndFocus = GetNextDlgTabItem( hwnd, 0, FALSE);
886 SetFocus( dlgInfo->hwndFocus );
888 else
890 /* If the dlgproc has returned FALSE (indicating handling of keyboard focus)
891 but the focus has not changed, set the focus where we expect it. */
892 if ( (wndPtr->dwStyle & WS_VISIBLE) && ( GetFocus() == hwndPreInitFocus ) )
894 dlgInfo->hwndFocus = GetNextDlgTabItem( hwnd, 0, FALSE);
895 SetFocus( dlgInfo->hwndFocus );
899 if (template.style & WS_VISIBLE && !(wndPtr->dwStyle & WS_VISIBLE))
901 ShowWindow( hwnd, SW_SHOWNORMAL ); /* SW_SHOW doesn't always work */
903 WIN_ReleaseWndPtr(wndPtr);
904 return hwnd;
906 WIN_ReleaseWndPtr(wndPtr);
907 if( IsWindow(hwnd) ) DestroyWindow( hwnd );
908 if (modal)
909 DIALOG_EnableOwner(owner, ownerEnabled);
910 return 0;
914 /***********************************************************************
915 * CreateDialog (USER.89)
917 HWND16 WINAPI CreateDialog16( HINSTANCE16 hInst, LPCSTR dlgTemplate,
918 HWND16 owner, DLGPROC16 dlgProc )
920 return CreateDialogParam16( hInst, dlgTemplate, owner, dlgProc, 0 );
924 /***********************************************************************
925 * CreateDialogParam (USER.241)
927 HWND16 WINAPI CreateDialogParam16( HINSTANCE16 hInst, LPCSTR dlgTemplate,
928 HWND16 owner, DLGPROC16 dlgProc,
929 LPARAM param )
931 HWND16 hwnd = 0;
932 HRSRC16 hRsrc;
933 HGLOBAL16 hmem;
934 LPCVOID data;
936 TRACE("%04x,%s,%04x,%08lx,%ld\n",
937 hInst, debugres_a(dlgTemplate), owner, (DWORD)dlgProc, param );
939 if (!(hRsrc = FindResource16( hInst, dlgTemplate, RT_DIALOGA ))) return 0;
940 if (!(hmem = LoadResource16( hInst, hRsrc ))) return 0;
941 if (!(data = LockResource16( hmem ))) hwnd = 0;
942 else hwnd = CreateDialogIndirectParam16( hInst, data, owner,
943 dlgProc, param );
944 FreeResource16( hmem );
945 return hwnd;
948 /***********************************************************************
949 * CreateDialogParamA (USER32.@)
951 HWND WINAPI CreateDialogParamA( HINSTANCE hInst, LPCSTR name,
952 HWND owner, DLGPROC dlgProc,
953 LPARAM param )
955 HANDLE hrsrc = FindResourceA( hInst, name, RT_DIALOGA );
956 if (!hrsrc) return 0;
957 return CreateDialogIndirectParamA( hInst,
958 (LPVOID)LoadResource(hInst, hrsrc),
959 owner, dlgProc, param );
963 /***********************************************************************
964 * CreateDialogParamW (USER32.@)
966 HWND WINAPI CreateDialogParamW( HINSTANCE hInst, LPCWSTR name,
967 HWND owner, DLGPROC dlgProc,
968 LPARAM param )
970 HANDLE hrsrc = FindResourceW( hInst, name, RT_DIALOGW );
971 if (!hrsrc) return 0;
972 return CreateDialogIndirectParamW( hInst,
973 (LPVOID)LoadResource(hInst, hrsrc),
974 owner, dlgProc, param );
978 /***********************************************************************
979 * CreateDialogIndirect (USER.219)
981 HWND16 WINAPI CreateDialogIndirect16( HINSTANCE16 hInst, LPCVOID dlgTemplate,
982 HWND16 owner, DLGPROC16 dlgProc )
984 return CreateDialogIndirectParam16( hInst, dlgTemplate, owner, dlgProc, 0);
988 /***********************************************************************
989 * CreateDialogIndirectParam (USER.242)
990 * CreateDialogIndirectParam16 (USER32.@)
992 HWND16 WINAPI CreateDialogIndirectParam16( HINSTANCE16 hInst,
993 LPCVOID dlgTemplate,
994 HWND16 owner, DLGPROC16 dlgProc,
995 LPARAM param )
997 return DIALOG_CreateIndirect( hInst, dlgTemplate, FALSE, owner,
998 dlgProc, param, WIN_PROC_16, FALSE );
1002 /***********************************************************************
1003 * CreateDialogIndirectParamA (USER32.@)
1005 HWND WINAPI CreateDialogIndirectParamA( HINSTANCE hInst,
1006 LPCVOID dlgTemplate,
1007 HWND owner, DLGPROC dlgProc,
1008 LPARAM param )
1010 return DIALOG_CreateIndirect( hInst, dlgTemplate, TRUE, owner,
1011 (DLGPROC16)dlgProc, param, WIN_PROC_32A, FALSE );
1014 /***********************************************************************
1015 * CreateDialogIndirectParamAorW (USER32.@)
1017 HWND WINAPI CreateDialogIndirectParamAorW( HINSTANCE hInst,
1018 LPCVOID dlgTemplate,
1019 HWND owner, DLGPROC dlgProc,
1020 LPARAM param )
1021 { FIXME("assume WIN_PROC_32W\n");
1022 return DIALOG_CreateIndirect( hInst, dlgTemplate, TRUE, owner,
1023 (DLGPROC16)dlgProc, param, WIN_PROC_32W, FALSE );
1026 /***********************************************************************
1027 * CreateDialogIndirectParamW (USER32.@)
1029 HWND WINAPI CreateDialogIndirectParamW( HINSTANCE hInst,
1030 LPCVOID dlgTemplate,
1031 HWND owner, DLGPROC dlgProc,
1032 LPARAM param )
1034 return DIALOG_CreateIndirect( hInst, dlgTemplate, TRUE, owner,
1035 (DLGPROC16)dlgProc, param, WIN_PROC_32W, FALSE );
1039 /***********************************************************************
1040 * DIALOG_DoDialogBox
1042 static INT DIALOG_DoDialogBox( HWND hwnd, HWND owner )
1044 WND * wndPtr;
1045 DIALOGINFO * dlgInfo;
1046 MSG msg;
1047 INT retval;
1048 HWND ownerMsg = WIN_GetTopParent( owner );
1050 if (!(wndPtr = WIN_FindWndPtr( hwnd ))) return -1;
1051 dlgInfo = (DIALOGINFO *)wndPtr->wExtra;
1053 if (!(dlgInfo->flags & DF_END)) /* was EndDialog called in WM_INITDIALOG ? */
1055 ShowWindow( hwnd, SW_SHOW );
1056 while (MSG_InternalGetMessage(&msg, hwnd, ownerMsg, 0, 0, MSGF_DIALOGBOX,
1057 PM_REMOVE, !(wndPtr->dwStyle & DS_NOIDLEMSG), NULL ))
1059 if (!(dlgInfo->flags & DF_END) && (!IsDialogMessageA( hwnd, &msg)))
1061 TranslateMessage( &msg );
1062 DispatchMessageA( &msg );
1064 if (dlgInfo->flags & DF_END) break;
1067 DIALOG_EnableOwner( owner, (dlgInfo->flags & DF_OWNERENABLED) );
1068 retval = dlgInfo->idResult;
1069 WIN_ReleaseWndPtr(wndPtr);
1070 DestroyWindow( hwnd );
1071 return retval;
1075 /***********************************************************************
1076 * DialogBox (USER.87)
1078 INT16 WINAPI DialogBox16( HINSTANCE16 hInst, LPCSTR dlgTemplate,
1079 HWND16 owner, DLGPROC16 dlgProc )
1081 return DialogBoxParam16( hInst, dlgTemplate, owner, dlgProc, 0 );
1085 /***********************************************************************
1086 * DialogBoxParam (USER.239)
1088 INT16 WINAPI DialogBoxParam16( HINSTANCE16 hInst, LPCSTR template,
1089 HWND16 owner, DLGPROC16 dlgProc, LPARAM param )
1091 HWND16 hwnd = 0;
1092 HRSRC16 hRsrc;
1093 HGLOBAL16 hmem;
1094 LPCVOID data;
1095 int ret = -1;
1097 if (!(hRsrc = FindResource16( hInst, template, RT_DIALOGA ))) return 0;
1098 if (!(hmem = LoadResource16( hInst, hRsrc ))) return 0;
1099 if (!(data = LockResource16( hmem ))) hwnd = 0;
1100 else hwnd = DIALOG_CreateIndirect( hInst, data, FALSE, owner,
1101 dlgProc, param, WIN_PROC_16, TRUE );
1102 if (hwnd)
1103 ret =(INT16)DIALOG_DoDialogBox( hwnd, owner );
1104 if (data) GlobalUnlock16( hmem );
1105 FreeResource16( hmem );
1106 return ret;
1110 /***********************************************************************
1111 * DialogBoxParamA (USER32.@)
1113 INT WINAPI DialogBoxParamA( HINSTANCE hInst, LPCSTR name,
1114 HWND owner, DLGPROC dlgProc, LPARAM param )
1116 HWND hwnd;
1117 HANDLE hrsrc = FindResourceA( hInst, name, RT_DIALOGA );
1118 if (!hrsrc) return 0;
1119 hwnd = DIALOG_CreateIndirect( hInst, (LPVOID)LoadResource(hInst, hrsrc),
1120 TRUE, owner,
1121 (DLGPROC16) dlgProc, param, WIN_PROC_32A, TRUE );
1122 if (hwnd) return DIALOG_DoDialogBox( hwnd, owner );
1123 return -1;
1127 /***********************************************************************
1128 * DialogBoxParamW (USER32.@)
1130 INT WINAPI DialogBoxParamW( HINSTANCE hInst, LPCWSTR name,
1131 HWND owner, DLGPROC dlgProc, LPARAM param )
1133 HWND hwnd;
1134 HANDLE hrsrc = FindResourceW( hInst, name, RT_DIALOGW );
1135 if (!hrsrc) return 0;
1136 hwnd = DIALOG_CreateIndirect( hInst, (LPVOID)LoadResource(hInst, hrsrc),
1137 TRUE, owner,
1138 (DLGPROC16)dlgProc, param, WIN_PROC_32W, TRUE );
1139 if (hwnd) return DIALOG_DoDialogBox( hwnd, owner );
1140 return -1;
1144 /***********************************************************************
1145 * DialogBoxIndirect (USER.218)
1147 INT16 WINAPI DialogBoxIndirect16( HINSTANCE16 hInst, HANDLE16 dlgTemplate,
1148 HWND16 owner, DLGPROC16 dlgProc )
1150 return DialogBoxIndirectParam16( hInst, dlgTemplate, owner, dlgProc, 0 );
1154 /***********************************************************************
1155 * DialogBoxIndirectParam (USER.240)
1156 * DialogBoxIndirectParam16 (USER32.@)
1158 INT16 WINAPI DialogBoxIndirectParam16( HINSTANCE16 hInst, HANDLE16 dlgTemplate,
1159 HWND16 owner, DLGPROC16 dlgProc,
1160 LPARAM param )
1162 HWND16 hwnd;
1163 LPCVOID ptr;
1165 if (!(ptr = GlobalLock16( dlgTemplate ))) return -1;
1166 hwnd = DIALOG_CreateIndirect( hInst, ptr, FALSE, owner,
1167 dlgProc, param, WIN_PROC_16, TRUE );
1168 GlobalUnlock16( dlgTemplate );
1169 if (hwnd) return DIALOG_DoDialogBox( hwnd, owner );
1170 return -1;
1174 /***********************************************************************
1175 * DialogBoxIndirectParamA (USER32.@)
1177 INT WINAPI DialogBoxIndirectParamA(HINSTANCE hInstance, LPCVOID template,
1178 HWND owner, DLGPROC dlgProc,
1179 LPARAM param )
1181 HWND hwnd = DIALOG_CreateIndirect( hInstance, template, TRUE, owner,
1182 (DLGPROC16) dlgProc, param, WIN_PROC_32A, TRUE );
1183 if (hwnd) return DIALOG_DoDialogBox( hwnd, owner );
1184 return -1;
1188 /***********************************************************************
1189 * DialogBoxIndirectParamW (USER32.@)
1191 INT WINAPI DialogBoxIndirectParamW(HINSTANCE hInstance, LPCVOID template,
1192 HWND owner, DLGPROC dlgProc,
1193 LPARAM param )
1195 HWND hwnd = DIALOG_CreateIndirect( hInstance, template, TRUE, owner,
1196 (DLGPROC16)dlgProc, param, WIN_PROC_32W, TRUE );
1197 if (hwnd) return DIALOG_DoDialogBox( hwnd, owner );
1198 return -1;
1201 /***********************************************************************
1202 * DialogBoxIndirectParamAorW (USER32.@)
1204 INT WINAPI DialogBoxIndirectParamAorW(HINSTANCE hInstance, LPCVOID template,
1205 HWND owner, DLGPROC dlgProc,
1206 LPARAM param, DWORD x )
1208 HWND hwnd;
1209 FIXME("0x%08x %p 0x%08x %p 0x%08lx 0x%08lx\n",
1210 hInstance, template, owner, dlgProc, param, x);
1211 hwnd = DIALOG_CreateIndirect( hInstance, template, TRUE, owner,
1212 (DLGPROC16)dlgProc, param, WIN_PROC_32W, TRUE );
1213 if (hwnd) return DIALOG_DoDialogBox( hwnd, owner );
1214 return -1;
1217 /***********************************************************************
1218 * EndDialog (USER.88)
1220 BOOL16 WINAPI EndDialog16( HWND16 hwnd, INT16 retval )
1222 return EndDialog( hwnd, retval );
1226 /***********************************************************************
1227 * EndDialog (USER32.@)
1229 BOOL WINAPI EndDialog( HWND hwnd, INT retval )
1231 WND * wndPtr = WIN_FindWndPtr( hwnd );
1232 BOOL wasEnabled = TRUE;
1233 DIALOGINFO * dlgInfo;
1235 TRACE("%04x %d\n", hwnd, retval );
1237 if (!wndPtr)
1239 ERR("got invalid window handle (%04x); buggy app !?\n", hwnd);
1240 return FALSE;
1243 if ((dlgInfo = (DIALOGINFO *)wndPtr->wExtra))
1245 dlgInfo->idResult = retval;
1246 dlgInfo->flags |= DF_END;
1247 wasEnabled = (dlgInfo->flags & DF_OWNERENABLED);
1250 if(wndPtr->owner)
1251 DIALOG_EnableOwner( wndPtr->owner->hwndSelf, wasEnabled );
1253 /* Windows sets the focus to the dialog itself in EndDialog */
1255 if (IsChild(hwnd, GetFocus()))
1256 SetFocus(wndPtr->hwndSelf);
1258 /* Don't have to send a ShowWindow(SW_HIDE), just do
1259 SetWindowPos with SWP_HIDEWINDOW as done in Windows */
1261 SetWindowPos(hwnd, (HWND)0, 0, 0, 0, 0, SWP_NOMOVE | SWP_NOSIZE
1262 | SWP_NOZORDER | SWP_NOACTIVATE | SWP_HIDEWINDOW);
1264 WIN_ReleaseWndPtr(wndPtr);
1265 /* unblock dialog loop */
1266 PostMessageA(hwnd, WM_NULL, 0, 0);
1267 return TRUE;
1271 /***********************************************************************
1272 * DIALOG_IsAccelerator
1274 static BOOL DIALOG_IsAccelerator( HWND hwnd, HWND hwndDlg, WPARAM vKey )
1276 HWND hwndControl = hwnd;
1277 HWND hwndNext;
1278 WND *wndPtr;
1279 BOOL RetVal = FALSE;
1280 INT dlgCode;
1284 wndPtr = WIN_FindWndPtr( hwndControl );
1285 if ( (wndPtr != NULL) &&
1286 ((wndPtr->dwStyle & (WS_VISIBLE | WS_DISABLED)) == WS_VISIBLE) )
1288 dlgCode = SendMessageA( hwndControl, WM_GETDLGCODE, 0, 0 );
1289 if ( (dlgCode & (DLGC_BUTTON | DLGC_STATIC)) &&
1290 (wndPtr->text!=NULL))
1292 /* find the accelerator key */
1293 LPWSTR p = wndPtr->text - 2;
1294 char a_char = vKey;
1295 WCHAR w_char = 0;
1299 p = strchrW( p + 2, '&' );
1301 while (p != NULL && p[1] == '&');
1303 /* and check if it's the one we're looking for */
1304 MultiByteToWideChar(CP_ACP, 0, &a_char, 1, &w_char, 1);
1305 if (p != NULL && toupperW( p[1] ) == toupperW( w_char ) )
1307 if ((dlgCode & DLGC_STATIC) ||
1308 (wndPtr->dwStyle & 0x0f) == BS_GROUPBOX )
1310 /* set focus to the control */
1311 SendMessageA( hwndDlg, WM_NEXTDLGCTL,
1312 hwndControl, 1);
1313 /* and bump it on to next */
1314 SendMessageA( hwndDlg, WM_NEXTDLGCTL, 0, 0);
1316 else if (dlgCode & DLGC_BUTTON)
1318 /* send BM_CLICK message to the control */
1319 SendMessageA( hwndControl, BM_CLICK, 0, 0 );
1322 RetVal = TRUE;
1323 WIN_ReleaseWndPtr(wndPtr);
1324 break;
1327 hwndNext = GetWindow( hwndControl, GW_CHILD );
1329 else
1331 hwndNext = 0;
1333 WIN_ReleaseWndPtr(wndPtr);
1334 if (!hwndNext)
1336 hwndNext = GetWindow( hwndControl, GW_HWNDNEXT );
1338 while (!hwndNext && hwndControl)
1340 hwndControl = GetParent( hwndControl );
1341 if (hwndControl == hwndDlg)
1343 if(hwnd==hwndDlg){ /* prevent endless loop */
1344 hwndNext=hwnd;
1345 break;
1347 hwndNext = GetWindow( hwndDlg, GW_CHILD );
1349 else
1351 hwndNext = GetWindow( hwndControl, GW_HWNDNEXT );
1354 hwndControl = hwndNext;
1356 while (hwndControl && (hwndControl != hwnd));
1358 return RetVal;
1361 /***********************************************************************
1362 * DIALOG_FindMsgDestination
1364 * The messages that IsDialogMessage sends may not go to the dialog
1365 * calling IsDialogMessage if that dialog is a child, and it has the
1366 * DS_CONTROL style set.
1367 * We propagate up until we hit one that does not have DS_CONTROL, or
1368 * whose parent is not a dialog.
1370 * This is undocumented behaviour.
1372 static HWND DIALOG_FindMsgDestination( HWND hwndDlg )
1374 while (GetWindowLongA(hwndDlg, GWL_STYLE) & DS_CONTROL)
1376 WND *pParent;
1377 HWND hParent = GetParent(hwndDlg);
1378 if (!hParent) break;
1380 pParent = WIN_FindWndPtr(hParent);
1381 if (!pParent) break;
1383 if (!(pParent->flags & WIN_ISDIALOG))
1385 WIN_ReleaseWndPtr(pParent);
1386 break;
1388 WIN_ReleaseWndPtr(pParent);
1390 hwndDlg = hParent;
1393 return hwndDlg;
1396 /***********************************************************************
1397 * DIALOG_IsDialogMessage
1399 static BOOL DIALOG_IsDialogMessage( HWND hwnd, HWND hwndDlg,
1400 UINT message, WPARAM wParam,
1401 LPARAM lParam, BOOL *translate,
1402 BOOL *dispatch, INT dlgCode )
1404 *translate = *dispatch = FALSE;
1406 if (message == WM_PAINT)
1408 /* Apparently, we have to handle this one as well */
1409 *dispatch = TRUE;
1410 return TRUE;
1413 /* Only the key messages get special processing */
1414 if ((message != WM_KEYDOWN) &&
1415 (message != WM_SYSKEYDOWN) &&
1416 (message != WM_SYSCHAR) &&
1417 (message != WM_CHAR))
1418 return FALSE;
1420 if (dlgCode & DLGC_WANTMESSAGE)
1422 *translate = *dispatch = TRUE;
1423 return TRUE;
1426 hwndDlg = DIALOG_FindMsgDestination(hwndDlg);
1428 switch(message)
1430 case WM_KEYDOWN:
1431 switch(wParam)
1433 case VK_TAB:
1434 if (!(dlgCode & DLGC_WANTTAB))
1436 SendMessageA( hwndDlg, WM_NEXTDLGCTL,
1437 (GetKeyState(VK_SHIFT) & 0x8000), 0 );
1438 return TRUE;
1440 break;
1442 case VK_RIGHT:
1443 case VK_DOWN:
1444 case VK_LEFT:
1445 case VK_UP:
1446 if (!(dlgCode & DLGC_WANTARROWS))
1448 BOOL fPrevious = (wParam == VK_LEFT || wParam == VK_UP);
1449 HWND hwndNext =
1450 GetNextDlgGroupItem (hwndDlg, GetFocus(), fPrevious );
1451 SendMessageA( hwndDlg, WM_NEXTDLGCTL, hwndNext, 1 );
1452 return TRUE;
1454 break;
1456 case VK_ESCAPE:
1457 SendMessageA( hwndDlg, WM_COMMAND, IDCANCEL,
1458 (LPARAM)GetDlgItem( hwndDlg, IDCANCEL ) );
1459 return TRUE;
1461 case VK_RETURN:
1463 DWORD dw = SendMessage16( hwndDlg, DM_GETDEFID, 0, 0 );
1464 if (HIWORD(dw) == DC_HASDEFID)
1466 SendMessageA( hwndDlg, WM_COMMAND,
1467 MAKEWPARAM( LOWORD(dw), BN_CLICKED ),
1468 (LPARAM)GetDlgItem(hwndDlg, LOWORD(dw)));
1470 else
1472 SendMessageA( hwndDlg, WM_COMMAND, IDOK,
1473 (LPARAM)GetDlgItem( hwndDlg, IDOK ) );
1477 return TRUE;
1479 *translate = TRUE;
1480 break; /* case WM_KEYDOWN */
1482 case WM_CHAR:
1483 if (dlgCode & DLGC_WANTCHARS) break;
1484 /* drop through */
1486 case WM_SYSCHAR:
1487 if (DIALOG_IsAccelerator( hwnd, hwndDlg, wParam ))
1489 /* don't translate or dispatch */
1490 return TRUE;
1492 break;
1494 case WM_SYSKEYDOWN:
1495 *translate = TRUE;
1496 break;
1499 /* If we get here, the message has not been treated specially */
1500 /* and can be sent to its destination window. */
1501 *dispatch = TRUE;
1502 return TRUE;
1506 /***********************************************************************
1507 * IsDialogMessage (USER.90)
1509 BOOL16 WINAPI IsDialogMessage16( HWND16 hwndDlg, SEGPTR msg16 )
1511 LPMSG16 msg = MapSL(msg16);
1512 BOOL ret, translate, dispatch;
1513 INT dlgCode = 0;
1515 if ((hwndDlg != msg->hwnd) && !IsChild16( hwndDlg, msg->hwnd ))
1516 return FALSE;
1518 if ((msg->message == WM_KEYDOWN) ||
1519 (msg->message == WM_CHAR))
1521 dlgCode = SendMessage16( msg->hwnd, WM_GETDLGCODE, 0, (LPARAM)msg16);
1523 ret = DIALOG_IsDialogMessage( msg->hwnd, hwndDlg, msg->message,
1524 msg->wParam, msg->lParam,
1525 &translate, &dispatch, dlgCode );
1526 if (translate) TranslateMessage16( msg );
1527 if (dispatch) DispatchMessage16( msg );
1528 return ret;
1532 /***********************************************************************
1533 * IsDialogMessage (USER32.@)
1534 * IsDialogMessageA (USER32.@)
1536 BOOL WINAPI IsDialogMessageA( HWND hwndDlg, LPMSG msg )
1538 BOOL ret, translate, dispatch;
1539 INT dlgCode = 0;
1541 if ((hwndDlg != msg->hwnd) && !IsChild( hwndDlg, msg->hwnd ))
1542 return FALSE;
1544 if ((msg->message == WM_KEYDOWN) ||
1545 (msg->message == WM_CHAR))
1547 dlgCode = SendMessageA( msg->hwnd, WM_GETDLGCODE, 0, (LPARAM)msg);
1549 ret = DIALOG_IsDialogMessage( msg->hwnd, hwndDlg, msg->message,
1550 msg->wParam, msg->lParam,
1551 &translate, &dispatch, dlgCode );
1552 if (translate) TranslateMessage( msg );
1553 if (dispatch) DispatchMessageA( msg );
1554 return ret;
1558 /***********************************************************************
1559 * IsDialogMessageW (USER32.@)
1561 BOOL WINAPI IsDialogMessageW( HWND hwndDlg, LPMSG msg )
1563 BOOL ret, translate, dispatch;
1564 INT dlgCode = 0;
1566 if ((hwndDlg != msg->hwnd) && !IsChild( hwndDlg, msg->hwnd ))
1567 return FALSE;
1569 if ((msg->message == WM_KEYDOWN) ||
1570 (msg->message == WM_CHAR))
1572 dlgCode = SendMessageW( msg->hwnd, WM_GETDLGCODE, 0, (LPARAM)msg);
1574 ret = DIALOG_IsDialogMessage( msg->hwnd, hwndDlg, msg->message,
1575 msg->wParam, msg->lParam,
1576 &translate, &dispatch, dlgCode );
1577 if (translate) TranslateMessage( msg );
1578 if (dispatch) DispatchMessageW( msg );
1579 return ret;
1583 /***********************************************************************
1584 * GetDlgCtrlID (USER.277)
1586 INT16 WINAPI GetDlgCtrlID16( HWND16 hwnd )
1588 WND *wndPtr = WIN_FindWndPtr(hwnd);
1589 INT16 retvalue;
1591 if (!wndPtr) return 0;
1593 retvalue = wndPtr->wIDmenu;
1594 WIN_ReleaseWndPtr(wndPtr);
1595 return retvalue;
1599 /***********************************************************************
1600 * GetDlgCtrlID (USER32.@)
1602 INT WINAPI GetDlgCtrlID( HWND hwnd )
1604 INT retvalue;
1605 WND *wndPtr = WIN_FindWndPtr(hwnd);
1606 if (!wndPtr) return 0;
1607 retvalue = wndPtr->wIDmenu;
1608 WIN_ReleaseWndPtr(wndPtr);
1609 return retvalue;
1613 /***********************************************************************
1614 * GetDlgItem (USER.91)
1616 HWND16 WINAPI GetDlgItem16( HWND16 hwndDlg, INT16 id )
1618 WND *pWnd;
1620 if (!(pWnd = WIN_FindWndPtr( hwndDlg ))) return 0;
1621 for (WIN_UpdateWndPtr(&pWnd,pWnd->child); pWnd; WIN_UpdateWndPtr(&pWnd,pWnd->next))
1622 if (pWnd->wIDmenu == (UINT16)id)
1624 HWND16 retvalue = pWnd->hwndSelf;
1625 WIN_ReleaseWndPtr(pWnd);
1626 return retvalue;
1628 return 0;
1632 /***********************************************************************
1633 * GetDlgItem (USER32.@)
1635 HWND WINAPI GetDlgItem( HWND hwndDlg, INT id )
1637 WND *pWnd;
1639 if (!(pWnd = WIN_FindWndPtr( hwndDlg ))) return 0;
1640 for (WIN_UpdateWndPtr(&pWnd,pWnd->child); pWnd;WIN_UpdateWndPtr(&pWnd,pWnd->next))
1641 if (pWnd->wIDmenu == (UINT16)id)
1643 HWND retvalue = pWnd->hwndSelf;
1644 WIN_ReleaseWndPtr(pWnd);
1645 return retvalue;
1647 return 0;
1651 /*******************************************************************
1652 * SendDlgItemMessage (USER.101)
1654 LRESULT WINAPI SendDlgItemMessage16( HWND16 hwnd, INT16 id, UINT16 msg,
1655 WPARAM16 wParam, LPARAM lParam )
1657 HWND16 hwndCtrl = GetDlgItem16( hwnd, id );
1658 if (hwndCtrl) return SendMessage16( hwndCtrl, msg, wParam, lParam );
1659 else return 0;
1663 /*******************************************************************
1664 * SendDlgItemMessageA (USER32.@)
1666 LRESULT WINAPI SendDlgItemMessageA( HWND hwnd, INT id, UINT msg,
1667 WPARAM wParam, LPARAM lParam )
1669 HWND hwndCtrl = GetDlgItem( hwnd, id );
1670 if (hwndCtrl) return SendMessageA( hwndCtrl, msg, wParam, lParam );
1671 else return 0;
1675 /*******************************************************************
1676 * SendDlgItemMessageW (USER32.@)
1678 LRESULT WINAPI SendDlgItemMessageW( HWND hwnd, INT id, UINT msg,
1679 WPARAM wParam, LPARAM lParam )
1681 HWND hwndCtrl = GetDlgItem( hwnd, id );
1682 if (hwndCtrl) return SendMessageW( hwndCtrl, msg, wParam, lParam );
1683 else return 0;
1687 /*******************************************************************
1688 * SetDlgItemText (USER.92)
1690 void WINAPI SetDlgItemText16( HWND16 hwnd, INT16 id, SEGPTR lpString )
1692 SendDlgItemMessage16( hwnd, id, WM_SETTEXT, 0, (LPARAM)lpString );
1696 /*******************************************************************
1697 * SetDlgItemTextA (USER32.@)
1699 BOOL WINAPI SetDlgItemTextA( HWND hwnd, INT id, LPCSTR lpString )
1701 return SendDlgItemMessageA( hwnd, id, WM_SETTEXT, 0, (LPARAM)lpString );
1705 /*******************************************************************
1706 * SetDlgItemTextW (USER32.@)
1708 BOOL WINAPI SetDlgItemTextW( HWND hwnd, INT id, LPCWSTR lpString )
1710 return SendDlgItemMessageW( hwnd, id, WM_SETTEXT, 0, (LPARAM)lpString );
1714 /***********************************************************************
1715 * GetDlgItemText (USER.93)
1717 INT16 WINAPI GetDlgItemText16( HWND16 hwnd, INT16 id, SEGPTR str, UINT16 len )
1719 return (INT16)SendDlgItemMessage16( hwnd, id, WM_GETTEXT,
1720 len, (LPARAM)str );
1724 /***********************************************************************
1725 * GetDlgItemTextA (USER32.@)
1727 INT WINAPI GetDlgItemTextA( HWND hwnd, INT id, LPSTR str, UINT len )
1729 return (INT)SendDlgItemMessageA( hwnd, id, WM_GETTEXT,
1730 len, (LPARAM)str );
1734 /***********************************************************************
1735 * GetDlgItemTextW (USER32.@)
1737 INT WINAPI GetDlgItemTextW( HWND hwnd, INT id, LPWSTR str, UINT len )
1739 return (INT)SendDlgItemMessageW( hwnd, id, WM_GETTEXT,
1740 len, (LPARAM)str );
1744 /*******************************************************************
1745 * SetDlgItemInt (USER.94)
1747 void WINAPI SetDlgItemInt16( HWND16 hwnd, INT16 id, UINT16 value, BOOL16 fSigned )
1749 SetDlgItemInt( hwnd, (UINT)(UINT16)id, value, fSigned );
1753 /*******************************************************************
1754 * SetDlgItemInt (USER32.@)
1756 BOOL WINAPI SetDlgItemInt( HWND hwnd, INT id, UINT value,
1757 BOOL fSigned )
1759 char str[20];
1761 if (fSigned) sprintf( str, "%d", (INT)value );
1762 else sprintf( str, "%u", value );
1763 SendDlgItemMessageA( hwnd, id, WM_SETTEXT, 0, (LPARAM)str );
1764 return TRUE;
1768 /***********************************************************************
1769 * GetDlgItemInt (USER.95)
1771 UINT16 WINAPI GetDlgItemInt16( HWND16 hwnd, INT16 id, BOOL16 *translated,
1772 BOOL16 fSigned )
1774 UINT result;
1775 BOOL ok;
1777 if (translated) *translated = FALSE;
1778 result = GetDlgItemInt( hwnd, (UINT)(UINT16)id, &ok, fSigned );
1779 if (!ok) return 0;
1780 if (fSigned)
1782 if (((INT)result < -32767) || ((INT)result > 32767)) return 0;
1784 else
1786 if (result > 65535) return 0;
1788 if (translated) *translated = TRUE;
1789 return (UINT16)result;
1793 /***********************************************************************
1794 * GetDlgItemInt (USER32.@)
1796 UINT WINAPI GetDlgItemInt( HWND hwnd, INT id, BOOL *translated,
1797 BOOL fSigned )
1799 char str[30];
1800 char * endptr;
1801 long result = 0;
1803 if (translated) *translated = FALSE;
1804 if (!SendDlgItemMessageA(hwnd, id, WM_GETTEXT, sizeof(str), (LPARAM)str))
1805 return 0;
1806 if (fSigned)
1808 result = strtol( str, &endptr, 10 );
1809 if (!endptr || (endptr == str)) /* Conversion was unsuccessful */
1810 return 0;
1811 if (((result == LONG_MIN) || (result == LONG_MAX)) && (errno==ERANGE))
1812 return 0;
1814 else
1816 result = strtoul( str, &endptr, 10 );
1817 if (!endptr || (endptr == str)) /* Conversion was unsuccessful */
1818 return 0;
1819 if ((result == ULONG_MAX) && (errno == ERANGE)) return 0;
1821 if (translated) *translated = TRUE;
1822 return (UINT)result;
1826 /***********************************************************************
1827 * CheckDlgButton (USER.97)
1829 BOOL16 WINAPI CheckDlgButton16( HWND16 hwnd, INT16 id, UINT16 check )
1831 SendDlgItemMessageA( hwnd, id, BM_SETCHECK, check, 0 );
1832 return TRUE;
1836 /***********************************************************************
1837 * CheckDlgButton (USER32.@)
1839 BOOL WINAPI CheckDlgButton( HWND hwnd, INT id, UINT check )
1841 SendDlgItemMessageA( hwnd, id, BM_SETCHECK, check, 0 );
1842 return TRUE;
1846 /***********************************************************************
1847 * IsDlgButtonChecked (USER.98)
1849 UINT16 WINAPI IsDlgButtonChecked16( HWND16 hwnd, UINT16 id )
1851 return (UINT16)SendDlgItemMessageA( hwnd, id, BM_GETCHECK, 0, 0 );
1855 /***********************************************************************
1856 * IsDlgButtonChecked (USER32.@)
1858 UINT WINAPI IsDlgButtonChecked( HWND hwnd, UINT id )
1860 return (UINT)SendDlgItemMessageA( hwnd, id, BM_GETCHECK, 0, 0 );
1864 /***********************************************************************
1865 * CheckRadioButton (USER.96)
1867 BOOL16 WINAPI CheckRadioButton16( HWND16 hwndDlg, UINT16 firstID,
1868 UINT16 lastID, UINT16 checkID )
1870 return CheckRadioButton( hwndDlg, firstID, lastID, checkID );
1874 /***********************************************************************
1875 * CheckRB
1877 * Callback function used to check/uncheck radio buttons that fall
1878 * within a specific range of IDs.
1880 static BOOL CALLBACK CheckRB(HWND hwndChild, LPARAM lParam)
1882 LONG lChildID = GetWindowLongA(hwndChild, GWL_ID);
1883 RADIOGROUP *lpRadioGroup = (RADIOGROUP *) lParam;
1885 if ((lChildID >= lpRadioGroup->firstID) &&
1886 (lChildID <= lpRadioGroup->lastID))
1888 if (lChildID == lpRadioGroup->checkID)
1890 SendMessageA(hwndChild, BM_SETCHECK, BST_CHECKED, 0);
1892 else
1894 SendMessageA(hwndChild, BM_SETCHECK, BST_UNCHECKED, 0);
1898 return TRUE;
1902 /***********************************************************************
1903 * CheckRadioButton (USER32.@)
1905 BOOL WINAPI CheckRadioButton( HWND hwndDlg, UINT firstID,
1906 UINT lastID, UINT checkID )
1908 RADIOGROUP radioGroup;
1910 /* perform bounds checking for a radio button group */
1911 radioGroup.firstID = min(min(firstID, lastID), checkID);
1912 radioGroup.lastID = max(max(firstID, lastID), checkID);
1913 radioGroup.checkID = checkID;
1915 return EnumChildWindows(hwndDlg, (WNDENUMPROC)CheckRB,
1916 (LPARAM)&radioGroup);
1920 /***********************************************************************
1921 * GetDialogBaseUnits (USER.243)
1922 * GetDialogBaseUnits (USER32.@)
1924 DWORD WINAPI GetDialogBaseUnits(void)
1926 return MAKELONG( xBaseUnit, yBaseUnit );
1930 /***********************************************************************
1931 * MapDialogRect (USER.103)
1933 void WINAPI MapDialogRect16( HWND16 hwnd, LPRECT16 rect )
1935 DIALOGINFO * dlgInfo;
1936 WND * wndPtr = WIN_FindWndPtr( hwnd );
1937 if (!wndPtr) return;
1938 dlgInfo = (DIALOGINFO *)wndPtr->wExtra;
1939 rect->left = MulDiv(rect->left, dlgInfo->xBaseUnit, 4);
1940 rect->right = MulDiv(rect->right, dlgInfo->xBaseUnit, 4);
1941 rect->top = MulDiv(rect->top, dlgInfo->yBaseUnit, 8);
1942 rect->bottom = MulDiv(rect->bottom, dlgInfo->yBaseUnit, 8);
1943 WIN_ReleaseWndPtr(wndPtr);
1947 /***********************************************************************
1948 * MapDialogRect (USER32.@)
1950 BOOL WINAPI MapDialogRect( HWND hwnd, LPRECT rect )
1952 DIALOGINFO * dlgInfo;
1953 WND * wndPtr = WIN_FindWndPtr( hwnd );
1954 if (!wndPtr) return FALSE;
1955 dlgInfo = (DIALOGINFO *)wndPtr->wExtra;
1956 rect->left = MulDiv(rect->left, dlgInfo->xBaseUnit, 4);
1957 rect->right = MulDiv(rect->right, dlgInfo->xBaseUnit, 4);
1958 rect->top = MulDiv(rect->top, dlgInfo->yBaseUnit, 8);
1959 rect->bottom = MulDiv(rect->bottom, dlgInfo->yBaseUnit, 8);
1960 WIN_ReleaseWndPtr(wndPtr);
1961 return TRUE;
1965 /***********************************************************************
1966 * GetNextDlgGroupItem (USER.227)
1968 HWND16 WINAPI GetNextDlgGroupItem16( HWND16 hwndDlg, HWND16 hwndCtrl,
1969 BOOL16 fPrevious )
1971 return (HWND16)GetNextDlgGroupItem( hwndDlg, hwndCtrl, fPrevious );
1975 /***********************************************************************
1976 * GetNextDlgGroupItem (USER32.@)
1978 HWND WINAPI GetNextDlgGroupItem( HWND hwndDlg, HWND hwndCtrl,
1979 BOOL fPrevious )
1981 WND *pWnd = NULL,
1982 *pWndLast = NULL,
1983 *pWndCtrl = NULL,
1984 *pWndDlg = NULL;
1985 HWND retvalue;
1987 if(hwndCtrl)
1989 /* if the hwndCtrl is the child of the control in the hwndDlg,
1990 * then the hwndDlg has to be the parent of the hwndCtrl */
1991 if(GetParent(hwndCtrl) != hwndDlg && GetParent(GetParent(hwndCtrl)) == hwndDlg)
1992 hwndDlg = GetParent(hwndCtrl);
1995 if (!(pWndDlg = WIN_FindWndPtr( hwndDlg ))) return 0;
1996 if (hwndCtrl)
1998 if (!(pWndCtrl = WIN_FindWndPtr( hwndCtrl )))
2000 retvalue = 0;
2001 goto END;
2003 /* Make sure hwndCtrl is a top-level child */
2004 while (pWndCtrl->parent && (pWndCtrl->parent != pWndDlg))
2005 WIN_UpdateWndPtr(&pWndCtrl,pWndCtrl->parent);
2006 if (pWndCtrl->parent != pWndDlg)
2008 retvalue = 0;
2009 goto END;
2012 else
2014 /* No ctrl specified -> start from the beginning */
2015 if (!(pWndCtrl = WIN_LockWndPtr(pWndDlg->child)))
2017 retvalue = 0;
2018 goto END;
2020 if (fPrevious)
2021 while (pWndCtrl->next) WIN_UpdateWndPtr(&pWndCtrl,pWndCtrl->next);
2024 pWndLast = WIN_LockWndPtr(pWndCtrl);
2025 pWnd = WIN_LockWndPtr(pWndCtrl->next);
2027 while (1)
2029 if (!pWnd || (pWnd->dwStyle & WS_GROUP))
2031 /* Wrap-around to the beginning of the group */
2032 WND *pWndTemp;
2034 WIN_UpdateWndPtr( &pWnd, pWndDlg->child );
2035 for ( pWndTemp = WIN_LockWndPtr( pWnd );
2036 pWndTemp;
2037 WIN_UpdateWndPtr( &pWndTemp, pWndTemp->next) )
2039 if (pWndTemp->dwStyle & WS_GROUP) WIN_UpdateWndPtr( &pWnd, pWndTemp );
2040 if (pWndTemp == pWndCtrl) break;
2042 WIN_ReleaseWndPtr( pWndTemp );
2044 if (pWnd == pWndCtrl) break;
2045 if ((pWnd->dwStyle & WS_VISIBLE) && !(pWnd->dwStyle & WS_DISABLED))
2047 WIN_UpdateWndPtr(&pWndLast,pWnd);
2048 if (!fPrevious) break;
2050 WIN_UpdateWndPtr(&pWnd,pWnd->next);
2052 retvalue = pWndLast->hwndSelf;
2054 WIN_ReleaseWndPtr(pWndLast);
2055 WIN_ReleaseWndPtr(pWnd);
2056 END:
2057 WIN_ReleaseWndPtr(pWndCtrl);
2058 WIN_ReleaseWndPtr(pWndDlg);
2060 return retvalue;
2064 /***********************************************************************
2065 * GetNextDlgTabItem (USER.228)
2067 HWND16 WINAPI GetNextDlgTabItem16( HWND16 hwndDlg, HWND16 hwndCtrl,
2068 BOOL16 fPrevious )
2070 return (HWND16)GetNextDlgTabItem( hwndDlg, hwndCtrl, fPrevious );
2073 /***********************************************************************
2074 * DIALOG_GetNextTabItem
2076 * Helper for GetNextDlgTabItem
2078 static HWND DIALOG_GetNextTabItem( HWND hwndMain, HWND hwndDlg, HWND hwndCtrl, BOOL fPrevious )
2080 LONG dsStyle;
2081 LONG exStyle;
2082 UINT wndSearch = fPrevious ? GW_HWNDPREV : GW_HWNDNEXT;
2083 HWND retWnd = 0;
2084 HWND hChildFirst = 0;
2086 if(!hwndCtrl)
2088 hChildFirst = GetWindow(hwndDlg,GW_CHILD);
2089 if(fPrevious) hChildFirst = GetWindow(hChildFirst,GW_HWNDLAST);
2091 else
2093 HWND hParent = GetParent(hwndCtrl);
2094 BOOL bValid = FALSE;
2095 while( hParent)
2097 if(hParent == hwndMain)
2099 bValid = TRUE;
2100 break;
2102 hParent = GetParent(hParent);
2104 if(bValid)
2106 hChildFirst = GetWindow(hwndCtrl,wndSearch);
2107 if(!hChildFirst)
2109 if(GetParent(hwndCtrl) != hwndMain)
2110 hChildFirst = GetWindow(GetParent(hwndCtrl),wndSearch);
2111 else
2113 if(fPrevious)
2114 hChildFirst = GetWindow(hwndCtrl,GW_HWNDLAST);
2115 else
2116 hChildFirst = GetWindow(hwndCtrl,GW_HWNDFIRST);
2121 while(hChildFirst)
2123 BOOL bCtrl = FALSE;
2124 while(hChildFirst)
2126 dsStyle = GetWindowLongA(hChildFirst,GWL_STYLE);
2127 exStyle = GetWindowLongA(hChildFirst,GWL_EXSTYLE);
2128 if( (dsStyle & DS_CONTROL || exStyle & WS_EX_CONTROLPARENT) && (dsStyle & WS_VISIBLE) && !(dsStyle & WS_DISABLED))
2130 bCtrl=TRUE;
2131 break;
2133 else if( (dsStyle & WS_TABSTOP) && (dsStyle & WS_VISIBLE) && !(dsStyle & WS_DISABLED))
2134 break;
2135 hChildFirst = GetWindow(hChildFirst,wndSearch);
2137 if(hChildFirst)
2139 if(bCtrl)
2140 retWnd = DIALOG_GetNextTabItem(hwndMain,hChildFirst,(HWND)NULL,fPrevious );
2141 else
2142 retWnd = hChildFirst;
2144 if(retWnd) break;
2145 hChildFirst = GetWindow(hChildFirst,wndSearch);
2147 if(!retWnd && hwndCtrl)
2149 HWND hParent = GetParent(hwndCtrl);
2150 while(hParent)
2152 if(hParent == hwndMain) break;
2153 retWnd = DIALOG_GetNextTabItem(hwndMain,GetParent(hParent),hParent,fPrevious );
2154 if(retWnd) break;
2155 hParent = GetParent(hParent);
2157 if(!retWnd)
2158 retWnd = DIALOG_GetNextTabItem(hwndMain,hwndMain,(HWND)NULL,fPrevious );
2160 return retWnd;
2163 /***********************************************************************
2164 * GetNextDlgTabItem (USER32.@)
2166 HWND WINAPI GetNextDlgTabItem( HWND hwndDlg, HWND hwndCtrl,
2167 BOOL fPrevious )
2169 return DIALOG_GetNextTabItem(hwndDlg,hwndDlg,hwndCtrl,fPrevious);
2172 /**********************************************************************
2173 * DIALOG_DlgDirSelect
2175 * Helper function for DlgDirSelect*
2177 static BOOL DIALOG_DlgDirSelect( HWND hwnd, LPSTR str, INT len,
2178 INT id, BOOL win32, BOOL unicode,
2179 BOOL combo )
2181 char *buffer, *ptr;
2182 INT item, size;
2183 BOOL ret;
2184 HWND listbox = GetDlgItem( hwnd, id );
2186 TRACE("%04x '%s' %d\n", hwnd, str, id );
2187 if (!listbox) return FALSE;
2188 if (win32)
2190 item = SendMessageA(listbox, combo ? CB_GETCURSEL
2191 : LB_GETCURSEL, 0, 0 );
2192 if (item == LB_ERR) return FALSE;
2193 size = SendMessageA(listbox, combo ? CB_GETLBTEXTLEN
2194 : LB_GETTEXTLEN, 0, 0 );
2195 if (size == LB_ERR) return FALSE;
2197 else
2199 item = SendMessageA(listbox, combo ? CB_GETCURSEL16
2200 : LB_GETCURSEL16, 0, 0 );
2201 if (item == LB_ERR) return FALSE;
2202 size = SendMessageA(listbox, combo ? CB_GETLBTEXTLEN16
2203 : LB_GETTEXTLEN16, 0, 0 );
2204 if (size == LB_ERR) return FALSE;
2207 if (!(buffer = SEGPTR_ALLOC( size+1 ))) return FALSE;
2209 if (win32)
2210 SendMessageA( listbox, combo ? CB_GETLBTEXT : LB_GETTEXT,
2211 item, (LPARAM)buffer );
2212 else
2213 SendMessage16( listbox, combo ? CB_GETLBTEXT16 : LB_GETTEXT16,
2214 item, (LPARAM)SEGPTR_GET(buffer) );
2216 if ((ret = (buffer[0] == '['))) /* drive or directory */
2218 if (buffer[1] == '-') /* drive */
2220 buffer[3] = ':';
2221 buffer[4] = 0;
2222 ptr = buffer + 2;
2224 else
2226 buffer[strlen(buffer)-1] = '\\';
2227 ptr = buffer + 1;
2230 else ptr = buffer;
2232 if (unicode)
2234 if (len > 0 && !MultiByteToWideChar( CP_ACP, 0, ptr, -1, (LPWSTR)str, len ))
2235 ((LPWSTR)str)[len-1] = 0;
2237 else lstrcpynA( str, ptr, len );
2238 SEGPTR_FREE( buffer );
2239 TRACE("Returning %d '%s'\n", ret, str );
2240 return ret;
2244 /**********************************************************************
2245 * DIALOG_DlgDirList
2247 * Helper function for DlgDirList*
2249 static INT DIALOG_DlgDirList( HWND hDlg, LPSTR spec, INT idLBox,
2250 INT idStatic, UINT attrib, BOOL combo )
2252 HWND hwnd;
2253 LPSTR orig_spec = spec;
2255 #define SENDMSG(msg,wparam,lparam) \
2256 ((attrib & DDL_POSTMSGS) ? PostMessageA( hwnd, msg, wparam, lparam ) \
2257 : SendMessageA( hwnd, msg, wparam, lparam ))
2259 TRACE("%04x '%s' %d %d %04x\n",
2260 hDlg, spec ? spec : "NULL", idLBox, idStatic, attrib );
2262 /* If the path exists and is a directory, chdir to it */
2263 if (!spec || !spec[0] || SetCurrentDirectoryA( spec )) spec = "*.*";
2264 else
2266 char *p, *p2;
2267 p = spec;
2268 if ((p2 = strrchr( p, '\\' ))) p = p2;
2269 if ((p2 = strrchr( p, '/' ))) p = p2;
2270 if (p != spec)
2272 char sep = *p;
2273 *p = 0;
2274 if (!SetCurrentDirectoryA( spec ))
2276 *p = sep; /* Restore the original spec */
2277 return FALSE;
2279 spec = p + 1;
2283 TRACE( "mask=%s\n", spec );
2285 if (idLBox && ((hwnd = GetDlgItem( hDlg, idLBox )) != 0))
2287 SENDMSG( combo ? CB_RESETCONTENT : LB_RESETCONTENT, 0, 0 );
2288 if (attrib & DDL_DIRECTORY)
2290 if (!(attrib & DDL_EXCLUSIVE))
2292 if (SENDMSG( combo ? CB_DIR : LB_DIR,
2293 attrib & ~(DDL_DIRECTORY | DDL_DRIVES),
2294 (LPARAM)spec ) == LB_ERR)
2295 return FALSE;
2297 if (SENDMSG( combo ? CB_DIR : LB_DIR,
2298 (attrib & (DDL_DIRECTORY | DDL_DRIVES)) | DDL_EXCLUSIVE,
2299 (LPARAM)"*.*" ) == LB_ERR)
2300 return FALSE;
2302 else
2304 if (SENDMSG( combo ? CB_DIR : LB_DIR, attrib,
2305 (LPARAM)spec ) == LB_ERR)
2306 return FALSE;
2310 if (idStatic && ((hwnd = GetDlgItem( hDlg, idStatic )) != 0))
2312 char temp[MAX_PATH];
2313 GetCurrentDirectoryA( sizeof(temp), temp );
2314 CharLowerA( temp );
2315 /* Can't use PostMessage() here, because the string is on the stack */
2316 SetDlgItemTextA( hDlg, idStatic, temp );
2319 if (orig_spec && (spec != orig_spec))
2321 /* Update the original file spec */
2322 char *p = spec;
2323 while ((*orig_spec++ = *p++));
2326 return TRUE;
2327 #undef SENDMSG
2331 /**********************************************************************
2332 * DIALOG_DlgDirListW
2334 * Helper function for DlgDirList*W
2336 static INT DIALOG_DlgDirListW( HWND hDlg, LPWSTR spec, INT idLBox,
2337 INT idStatic, UINT attrib, BOOL combo )
2339 if (spec)
2341 LPSTR specA = HEAP_strdupWtoA( GetProcessHeap(), 0, spec );
2342 INT ret = DIALOG_DlgDirList( hDlg, specA, idLBox, idStatic,
2343 attrib, combo );
2344 MultiByteToWideChar( CP_ACP, 0, specA, -1, spec, 0x7fffffff );
2345 HeapFree( GetProcessHeap(), 0, specA );
2346 return ret;
2348 return DIALOG_DlgDirList( hDlg, NULL, idLBox, idStatic, attrib, combo );
2352 /**********************************************************************
2353 * DlgDirSelect (USER.99)
2355 BOOL16 WINAPI DlgDirSelect16( HWND16 hwnd, LPSTR str, INT16 id )
2357 return DlgDirSelectEx16( hwnd, str, 128, id );
2361 /**********************************************************************
2362 * DlgDirSelectComboBox (USER.194)
2364 BOOL16 WINAPI DlgDirSelectComboBox16( HWND16 hwnd, LPSTR str, INT16 id )
2366 return DlgDirSelectComboBoxEx16( hwnd, str, 128, id );
2370 /**********************************************************************
2371 * DlgDirSelectEx (USER.422)
2373 BOOL16 WINAPI DlgDirSelectEx16( HWND16 hwnd, LPSTR str, INT16 len, INT16 id )
2375 return DIALOG_DlgDirSelect( hwnd, str, len, id, FALSE, FALSE, FALSE );
2379 /**********************************************************************
2380 * DlgDirSelectExA (USER32.@)
2382 BOOL WINAPI DlgDirSelectExA( HWND hwnd, LPSTR str, INT len, INT id )
2384 return DIALOG_DlgDirSelect( hwnd, str, len, id, TRUE, FALSE, FALSE );
2388 /**********************************************************************
2389 * DlgDirSelectExW (USER32.@)
2391 BOOL WINAPI DlgDirSelectExW( HWND hwnd, LPWSTR str, INT len, INT id )
2393 return DIALOG_DlgDirSelect( hwnd, (LPSTR)str, len, id, TRUE, TRUE, FALSE );
2397 /**********************************************************************
2398 * DlgDirSelectComboBoxEx (USER.423)
2400 BOOL16 WINAPI DlgDirSelectComboBoxEx16( HWND16 hwnd, LPSTR str, INT16 len,
2401 INT16 id )
2403 return DIALOG_DlgDirSelect( hwnd, str, len, id, FALSE, FALSE, TRUE );
2407 /**********************************************************************
2408 * DlgDirSelectComboBoxExA (USER32.@)
2410 BOOL WINAPI DlgDirSelectComboBoxExA( HWND hwnd, LPSTR str, INT len,
2411 INT id )
2413 return DIALOG_DlgDirSelect( hwnd, str, len, id, TRUE, FALSE, TRUE );
2417 /**********************************************************************
2418 * DlgDirSelectComboBoxExW (USER32.@)
2420 BOOL WINAPI DlgDirSelectComboBoxExW( HWND hwnd, LPWSTR str, INT len,
2421 INT id)
2423 return DIALOG_DlgDirSelect( hwnd, (LPSTR)str, len, id, TRUE, TRUE, TRUE );
2427 /**********************************************************************
2428 * DlgDirList (USER.100)
2430 INT16 WINAPI DlgDirList16( HWND16 hDlg, LPSTR spec, INT16 idLBox,
2431 INT16 idStatic, UINT16 attrib )
2433 /* according to Win16 docs, DDL_DRIVES should make DDL_EXCLUSIVE
2434 * be set automatically (this is different in Win32, and
2435 * DIALOG_DlgDirList sends Win32 messages to the control,
2436 * so do it here) */
2437 if (attrib & DDL_DRIVES) attrib |= DDL_EXCLUSIVE;
2438 return DIALOG_DlgDirList( hDlg, spec, idLBox, idStatic, attrib, FALSE );
2442 /**********************************************************************
2443 * DlgDirListA (USER32.@)
2445 INT WINAPI DlgDirListA( HWND hDlg, LPSTR spec, INT idLBox,
2446 INT idStatic, UINT attrib )
2448 return DIALOG_DlgDirList( hDlg, spec, idLBox, idStatic, attrib, FALSE );
2452 /**********************************************************************
2453 * DlgDirListW (USER32.@)
2455 INT WINAPI DlgDirListW( HWND hDlg, LPWSTR spec, INT idLBox,
2456 INT idStatic, UINT attrib )
2458 return DIALOG_DlgDirListW( hDlg, spec, idLBox, idStatic, attrib, FALSE );
2462 /**********************************************************************
2463 * DlgDirListComboBox (USER.195)
2465 INT16 WINAPI DlgDirListComboBox16( HWND16 hDlg, LPSTR spec, INT16 idCBox,
2466 INT16 idStatic, UINT16 attrib )
2468 return DIALOG_DlgDirList( hDlg, spec, idCBox, idStatic, attrib, TRUE );
2472 /**********************************************************************
2473 * DlgDirListComboBoxA (USER32.@)
2475 INT WINAPI DlgDirListComboBoxA( HWND hDlg, LPSTR spec, INT idCBox,
2476 INT idStatic, UINT attrib )
2478 return DIALOG_DlgDirList( hDlg, spec, idCBox, idStatic, attrib, TRUE );
2482 /**********************************************************************
2483 * DlgDirListComboBoxW (USER32.@)
2485 INT WINAPI DlgDirListComboBoxW( HWND hDlg, LPWSTR spec, INT idCBox,
2486 INT idStatic, UINT attrib )
2488 return DIALOG_DlgDirListW( hDlg, spec, idCBox, idStatic, attrib, TRUE );