Release 20001026.
[wine/multimedia.git] / windows / dialog.c
blobdd8545b106c8b6aefd220b7ba6ba924acb65d54e
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>
13 #include "windef.h"
14 #include "wingdi.h"
15 #include "winuser.h"
16 #include "windowsx.h"
17 #include "wine/winuser16.h"
18 #include "wine/winbase16.h"
19 #include "wine/unicode.h"
20 #include "wine/winestring.h"
21 #include "dialog.h"
22 #include "drive.h"
23 #include "heap.h"
24 #include "win.h"
25 #include "ldt.h"
26 #include "user.h"
27 #include "winproc.h"
28 #include "message.h"
29 #include "queue.h"
30 #include "debugtools.h"
32 DEFAULT_DEBUG_CHANNEL(dialog);
35 /* Dialog control information */
36 typedef struct
38 DWORD style;
39 DWORD exStyle;
40 DWORD helpId;
41 INT16 x;
42 INT16 y;
43 INT16 cx;
44 INT16 cy;
45 UINT id;
46 LPCSTR className;
47 LPCSTR windowName;
48 LPVOID data;
49 } DLG_CONTROL_INFO;
51 /* Dialog template */
52 typedef struct
54 DWORD style;
55 DWORD exStyle;
56 DWORD helpId;
57 UINT16 nbItems;
58 INT16 x;
59 INT16 y;
60 INT16 cx;
61 INT16 cy;
62 LPCSTR menuName;
63 LPCSTR className;
64 LPCSTR caption;
65 WORD pointSize;
66 WORD weight;
67 BOOL italic;
68 LPCSTR faceName;
69 BOOL dialogEx;
70 } DLG_TEMPLATE;
72 /* Radio button group */
73 typedef struct
75 UINT firstID;
76 UINT lastID;
77 UINT checkID;
78 } RADIOGROUP;
80 /* Dialog base units */
81 static WORD xBaseUnit = 0, yBaseUnit = 0;
84 /***********************************************************************
85 * DIALOG_EnableOwner
87 * Helper function for modal dialogs to enable again the
88 * owner of the dialog box.
90 void DIALOG_EnableOwner( HWND hOwner, BOOL ownerWasEnabled)
92 /* Owner must be a top-level window */
93 if (hOwner)
94 hOwner = WIN_GetTopParent( hOwner );
95 if (!hOwner) return;
96 if (ownerWasEnabled)
97 EnableWindow( hOwner, TRUE );
101 /***********************************************************************
102 * DIALOG_DisableOwner
104 * Helper function for modal dialogs to disable the
105 * owner of the dialog box. Returns TRUE if owner was enabled.
107 BOOL DIALOG_DisableOwner( HWND hOwner )
109 /* Owner must be a top-level window */
110 if (hOwner)
111 hOwner = WIN_GetTopParent( hOwner );
112 if (!hOwner) return FALSE;
113 if (IsWindowEnabled( hOwner ))
115 EnableWindow( hOwner, FALSE );
116 return TRUE;
118 else
119 return FALSE;
122 /***********************************************************************
123 * DIALOG_GetCharSizeFromDC
126 * Calculates the *true* average size of English characters in the
127 * specified font as oppposed to the one returned by GetTextMetrics.
129 * Latest: the X font driver will now compute a proper average width
130 * so this code can be removed
132 static BOOL DIALOG_GetCharSizeFromDC( HDC hDC, HFONT hFont, SIZE * pSize )
134 BOOL Success = FALSE;
135 HFONT hFontPrev = 0;
136 pSize->cx = xBaseUnit;
137 pSize->cy = yBaseUnit;
138 if ( hDC )
140 /* select the font */
141 TEXTMETRICA tm;
142 memset(&tm,0,sizeof(tm));
143 if (hFont) hFontPrev = SelectFont(hDC,hFont);
144 if (GetTextMetricsA(hDC,&tm))
146 pSize->cx = tm.tmAveCharWidth;
147 pSize->cy = tm.tmHeight;
149 /* if variable width font */
150 if (tm.tmPitchAndFamily & TMPF_FIXED_PITCH)
152 SIZE total;
153 const char* szAvgChars = "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ";
155 /* Calculate a true average as opposed to the one returned
156 * by tmAveCharWidth. This works better when dealing with
157 * proportional spaced fonts and (more important) that's
158 * how Microsoft's dialog creation code calculates the size
159 * of the font
161 if (GetTextExtentPointA(hDC,szAvgChars,sizeof(szAvgChars),&total))
163 /* round up */
164 pSize->cx = ((2*total.cx/sizeof(szAvgChars)) + 1)/2;
165 Success = TRUE;
168 else
170 Success = TRUE;
172 /* Use the text metrics */
173 TRACE("Using tm: %ldx%ld (dlg: %ld x %ld) (%s)\n",
174 tm.tmAveCharWidth, tm.tmHeight, pSize->cx, pSize->cy,
175 tm.tmPitchAndFamily & TMPF_FIXED_PITCH ? "variable" : "fixed");
176 pSize->cx = tm.tmAveCharWidth;
177 pSize->cy = tm.tmHeight;
179 /* select the original font */
180 if (hFontPrev) SelectFont(hDC,hFontPrev);
182 return (Success);
185 /***********************************************************************
186 * DIALOG_GetCharSize
188 * A convenient variant of DIALOG_GetCharSizeFromDC.
190 static BOOL DIALOG_GetCharSize( HFONT hFont, SIZE * pSize )
192 HDC hDC = GetDC(0);
193 BOOL Success = DIALOG_GetCharSizeFromDC( hDC, hFont, pSize );
194 ReleaseDC(0, hDC);
195 return Success;
198 /***********************************************************************
199 * DIALOG_Init
201 * Initialisation of the dialog manager.
203 BOOL DIALOG_Init(void)
205 HDC hdc;
206 SIZE size;
208 /* Calculate the dialog base units */
210 if (!(hdc = CreateDCA( "DISPLAY", NULL, NULL, NULL ))) return FALSE;
211 if (!DIALOG_GetCharSizeFromDC( hdc, 0, &size )) return FALSE;
212 DeleteDC( hdc );
213 xBaseUnit = size.cx;
214 yBaseUnit = size.cy;
216 TRACE("base units = %d,%d\n", xBaseUnit, yBaseUnit );
217 return TRUE;
221 /***********************************************************************
222 * DIALOG_GetControl16
224 * Return the class and text of the control pointed to by ptr,
225 * fill the header structure and return a pointer to the next control.
227 static LPCSTR DIALOG_GetControl16( LPCSTR p, DLG_CONTROL_INFO *info )
229 static char buffer[10];
230 int int_id;
232 info->x = GET_WORD(p); p += sizeof(WORD);
233 info->y = GET_WORD(p); p += sizeof(WORD);
234 info->cx = GET_WORD(p); p += sizeof(WORD);
235 info->cy = GET_WORD(p); p += sizeof(WORD);
236 info->id = GET_WORD(p); p += sizeof(WORD);
237 info->style = GET_DWORD(p); p += sizeof(DWORD);
238 info->exStyle = 0;
240 if (*p & 0x80)
242 switch((BYTE)*p)
244 case 0x80: strcpy( buffer, "BUTTON" ); break;
245 case 0x81: strcpy( buffer, "EDIT" ); break;
246 case 0x82: strcpy( buffer, "STATIC" ); break;
247 case 0x83: strcpy( buffer, "LISTBOX" ); break;
248 case 0x84: strcpy( buffer, "SCROLLBAR" ); break;
249 case 0x85: strcpy( buffer, "COMBOBOX" ); break;
250 default: buffer[0] = '\0'; break;
252 info->className = buffer;
253 p++;
255 else
257 info->className = p;
258 p += strlen(p) + 1;
261 int_id = ((BYTE)*p == 0xff);
262 if (int_id)
264 /* Integer id, not documented (?). Only works for SS_ICON controls */
265 info->windowName = (LPCSTR)(UINT)GET_WORD(p+1);
266 p += 3;
268 else
270 info->windowName = p;
271 p += strlen(p) + 1;
274 if (*p)
276 /* Additional CTLDATA available for this control. */
277 info->data = SEGPTR_ALLOC(*p);
278 memcpy( info->data, p + 1, *p );
280 else info->data = NULL;
282 p += *p + 1;
284 if(int_id)
285 TRACE(" %s %04x %d, %d, %d, %d, %d, %08lx, %08lx\n",
286 info->className, LOWORD(info->windowName),
287 info->id, info->x, info->y, info->cx, info->cy,
288 info->style, (DWORD)SEGPTR_GET(info->data) );
289 else
290 TRACE(" %s '%s' %d, %d, %d, %d, %d, %08lx, %08lx\n",
291 info->className, info->windowName,
292 info->id, info->x, info->y, info->cx, info->cy,
293 info->style, (DWORD)SEGPTR_GET(info->data) );
295 return p;
299 /***********************************************************************
300 * DIALOG_GetControl32
302 * Return the class and text of the control pointed to by ptr,
303 * fill the header structure and return a pointer to the next control.
305 static const WORD *DIALOG_GetControl32( const WORD *p, DLG_CONTROL_INFO *info,
306 BOOL dialogEx )
308 if (dialogEx)
310 info->helpId = GET_DWORD(p); p += 2;
311 info->exStyle = GET_DWORD(p); p += 2;
312 info->style = GET_DWORD(p); p += 2;
314 else
316 info->helpId = 0;
317 info->style = GET_DWORD(p); p += 2;
318 info->exStyle = GET_DWORD(p); p += 2;
320 info->x = GET_WORD(p); p++;
321 info->y = GET_WORD(p); p++;
322 info->cx = GET_WORD(p); p++;
323 info->cy = GET_WORD(p); p++;
325 if (dialogEx)
327 /* id is a DWORD for DIALOGEX */
328 info->id = GET_DWORD(p);
329 p += 2;
331 else
333 info->id = GET_WORD(p);
334 p++;
337 if (GET_WORD(p) == 0xffff)
339 static const WCHAR class_names[6][10] =
341 { 'B','u','t','t','o','n', }, /* 0x80 */
342 { 'E','d','i','t', }, /* 0x81 */
343 { 'S','t','a','t','i','c', }, /* 0x82 */
344 { 'L','i','s','t','B','o','x', }, /* 0x83 */
345 { 'S','c','r','o','l','l','B','a','r', }, /* 0x84 */
346 { 'C','o','m','b','o','B','o','x', } /* 0x85 */
348 WORD id = GET_WORD(p+1);
349 if ((id >= 0x80) && (id <= 0x85))
350 info->className = (LPCSTR)class_names[id - 0x80];
351 else
353 info->className = NULL;
354 ERR("Unknown built-in class id %04x\n", id );
356 p += 2;
358 else
360 info->className = (LPCSTR)p;
361 p += strlenW( (LPCWSTR)p ) + 1;
364 if (GET_WORD(p) == 0xffff) /* Is it an integer id? */
366 info->windowName = (LPCSTR)(UINT)GET_WORD(p + 1);
367 p += 2;
369 else
371 info->windowName = (LPCSTR)p;
372 p += strlenW( (LPCWSTR)p ) + 1;
375 TRACE(" %s %s %d, %d, %d, %d, %d, %08lx, %08lx, %08lx\n",
376 debugstr_w( (LPCWSTR)info->className ),
377 debugres_w( (LPCWSTR)info->windowName ),
378 info->id, info->x, info->y, info->cx, info->cy,
379 info->style, info->exStyle, info->helpId );
381 if (GET_WORD(p))
383 if (TRACE_ON(dialog))
385 WORD i, count = GET_WORD(p) / sizeof(WORD);
386 TRACE(" BEGIN\n");
387 TRACE(" ");
388 for (i = 0; i < count; i++) DPRINTF( "%04x,", GET_WORD(p+i+1) );
389 DPRINTF("\n");
390 TRACE(" END\n" );
392 info->data = (LPVOID)(p + 1);
393 p += GET_WORD(p) / sizeof(WORD);
395 else info->data = NULL;
396 p++;
398 /* Next control is on dword boundary */
399 return (const WORD *)((((int)p) + 3) & ~3);
403 /***********************************************************************
404 * DIALOG_CreateControls
406 * Create the control windows for a dialog.
408 static BOOL DIALOG_CreateControls( WND *pWnd, LPCSTR template,
409 const DLG_TEMPLATE *dlgTemplate,
410 HINSTANCE hInst, BOOL win32 )
412 DIALOGINFO *dlgInfo = (DIALOGINFO *)pWnd->wExtra;
413 DLG_CONTROL_INFO info;
414 HWND hwndCtrl, hwndDefButton = 0;
415 INT items = dlgTemplate->nbItems;
417 TRACE(" BEGIN\n" );
418 while (items--)
420 if (!win32)
422 HINSTANCE16 instance;
423 template = DIALOG_GetControl16( template, &info );
424 if (HIWORD(info.className) && !strcmp( info.className, "EDIT") &&
425 ((pWnd->dwStyle & DS_LOCALEDIT) != DS_LOCALEDIT))
427 if (!dlgInfo->hDialogHeap)
429 dlgInfo->hDialogHeap = GlobalAlloc16(GMEM_FIXED, 0x10000);
430 if (!dlgInfo->hDialogHeap)
432 ERR("Insufficient memory to create heap for edit control\n" );
433 continue;
435 LocalInit16(dlgInfo->hDialogHeap, 0, 0xffff);
437 instance = dlgInfo->hDialogHeap;
439 else instance = (HINSTANCE16)hInst;
441 hwndCtrl = CreateWindowEx16( info.exStyle | WS_EX_NOPARENTNOTIFY,
442 info.className, info.windowName,
443 info.style | WS_CHILD,
444 MulDiv(info.x, dlgInfo->xBaseUnit, 4),
445 MulDiv(info.y, dlgInfo->yBaseUnit, 8),
446 MulDiv(info.cx, dlgInfo->xBaseUnit, 4),
447 MulDiv(info.cy, dlgInfo->yBaseUnit, 8),
448 pWnd->hwndSelf, (HMENU16)info.id,
449 instance, (LPVOID)SEGPTR_GET(info.data) );
451 if (info.data) SEGPTR_FREE(info.data);
453 else
455 template = (LPCSTR)DIALOG_GetControl32( (WORD *)template, &info,
456 dlgTemplate->dialogEx );
457 hwndCtrl = CreateWindowExW( info.exStyle | WS_EX_NOPARENTNOTIFY,
458 (LPCWSTR)info.className,
459 (LPCWSTR)info.windowName,
460 info.style | WS_CHILD,
461 MulDiv(info.x, dlgInfo->xBaseUnit, 4),
462 MulDiv(info.y, dlgInfo->yBaseUnit, 8),
463 MulDiv(info.cx, dlgInfo->xBaseUnit, 4),
464 MulDiv(info.cy, dlgInfo->yBaseUnit, 8),
465 pWnd->hwndSelf, (HMENU)info.id,
466 hInst, info.data );
468 if (!hwndCtrl) return FALSE;
470 /* Send initialisation messages to the control */
471 if (dlgInfo->hUserFont) SendMessageA( hwndCtrl, WM_SETFONT,
472 (WPARAM)dlgInfo->hUserFont, 0 );
473 if (SendMessageA(hwndCtrl, WM_GETDLGCODE, 0, 0) & DLGC_DEFPUSHBUTTON)
475 /* If there's already a default push-button, set it back */
476 /* to normal and use this one instead. */
477 if (hwndDefButton)
478 SendMessageA( hwndDefButton, BM_SETSTYLE,
479 BS_PUSHBUTTON,FALSE );
480 hwndDefButton = hwndCtrl;
481 dlgInfo->idResult = GetWindowWord( hwndCtrl, GWW_ID );
484 TRACE(" END\n" );
485 return TRUE;
489 /***********************************************************************
490 * DIALOG_ParseTemplate16
492 * Fill a DLG_TEMPLATE structure from the dialog template, and return
493 * a pointer to the first control.
495 static LPCSTR DIALOG_ParseTemplate16( LPCSTR p, DLG_TEMPLATE * result )
497 result->style = GET_DWORD(p); p += sizeof(DWORD);
498 result->exStyle = 0;
499 result->nbItems = (unsigned char) *p++;
500 result->x = GET_WORD(p); p += sizeof(WORD);
501 result->y = GET_WORD(p); p += sizeof(WORD);
502 result->cx = GET_WORD(p); p += sizeof(WORD);
503 result->cy = GET_WORD(p); p += sizeof(WORD);
504 TRACE("DIALOG %d, %d, %d, %d\n",
505 result->x, result->y, result->cx, result->cy );
506 TRACE(" STYLE %08lx\n", result->style );
508 /* Get the menu name */
510 switch( (BYTE)*p )
512 case 0:
513 result->menuName = 0;
514 p++;
515 break;
516 case 0xff:
517 result->menuName = (LPCSTR)(UINT)GET_WORD( p + 1 );
518 p += 3;
519 TRACE(" MENU %04x\n", LOWORD(result->menuName) );
520 break;
521 default:
522 result->menuName = p;
523 TRACE(" MENU '%s'\n", p );
524 p += strlen(p) + 1;
525 break;
528 /* Get the class name */
530 if (*p)
532 result->className = p;
533 TRACE(" CLASS '%s'\n", result->className );
535 else result->className = DIALOG_CLASS_ATOM;
536 p += strlen(p) + 1;
538 /* Get the window caption */
540 result->caption = p;
541 p += strlen(p) + 1;
542 TRACE(" CAPTION '%s'\n", result->caption );
544 /* Get the font name */
546 if (result->style & DS_SETFONT)
548 result->pointSize = GET_WORD(p);
549 p += sizeof(WORD);
550 result->faceName = p;
551 p += strlen(p) + 1;
552 TRACE(" FONT %d,'%s'\n",
553 result->pointSize, result->faceName );
555 return p;
559 /***********************************************************************
560 * DIALOG_ParseTemplate32
562 * Fill a DLG_TEMPLATE structure from the dialog template, and return
563 * a pointer to the first control.
565 static LPCSTR DIALOG_ParseTemplate32( LPCSTR template, DLG_TEMPLATE * result )
567 const WORD *p = (const WORD *)template;
569 result->style = GET_DWORD(p); p += 2;
570 if (result->style == 0xffff0001) /* DIALOGEX resource */
572 result->dialogEx = TRUE;
573 result->helpId = GET_DWORD(p); p += 2;
574 result->exStyle = GET_DWORD(p); p += 2;
575 result->style = GET_DWORD(p); p += 2;
577 else
579 result->dialogEx = FALSE;
580 result->helpId = 0;
581 result->exStyle = GET_DWORD(p); p += 2;
583 result->nbItems = GET_WORD(p); p++;
584 result->x = GET_WORD(p); p++;
585 result->y = GET_WORD(p); p++;
586 result->cx = GET_WORD(p); p++;
587 result->cy = GET_WORD(p); p++;
588 TRACE("DIALOG%s %d, %d, %d, %d, %ld\n",
589 result->dialogEx ? "EX" : "", result->x, result->y,
590 result->cx, result->cy, result->helpId );
591 TRACE(" STYLE 0x%08lx\n", result->style );
592 TRACE(" EXSTYLE 0x%08lx\n", result->exStyle );
594 /* Get the menu name */
596 switch(GET_WORD(p))
598 case 0x0000:
599 result->menuName = NULL;
600 p++;
601 break;
602 case 0xffff:
603 result->menuName = (LPCSTR)(UINT)GET_WORD( p + 1 );
604 p += 2;
605 TRACE(" MENU %04x\n", LOWORD(result->menuName) );
606 break;
607 default:
608 result->menuName = (LPCSTR)p;
609 TRACE(" MENU %s\n", debugstr_w( (LPCWSTR)p ));
610 p += strlenW( (LPCWSTR)p ) + 1;
611 break;
614 /* Get the class name */
616 switch(GET_WORD(p))
618 case 0x0000:
619 result->className = DIALOG_CLASS_ATOM;
620 p++;
621 break;
622 case 0xffff:
623 result->className = (LPCSTR)(UINT)GET_WORD( p + 1 );
624 p += 2;
625 TRACE(" CLASS %04x\n", LOWORD(result->className) );
626 break;
627 default:
628 result->className = (LPCSTR)p;
629 TRACE(" CLASS %s\n", debugstr_w( (LPCWSTR)p ));
630 p += strlenW( (LPCWSTR)p ) + 1;
631 break;
634 /* Get the window caption */
636 result->caption = (LPCSTR)p;
637 p += strlenW( (LPCWSTR)p ) + 1;
638 TRACE(" CAPTION %s\n", debugstr_w( (LPCWSTR)result->caption ) );
640 /* Get the font name */
642 if (result->style & DS_SETFONT)
644 result->pointSize = GET_WORD(p);
645 p++;
646 if (result->dialogEx)
648 result->weight = GET_WORD(p); p++;
649 result->italic = LOBYTE(GET_WORD(p)); p++;
651 else
653 result->weight = FW_DONTCARE;
654 result->italic = FALSE;
656 result->faceName = (LPCSTR)p;
657 p += strlenW( (LPCWSTR)p ) + 1;
658 TRACE(" FONT %d, %s, %d, %s\n",
659 result->pointSize, debugstr_w( (LPCWSTR)result->faceName ),
660 result->weight, result->italic ? "TRUE" : "FALSE" );
663 /* First control is on dword boundary */
664 return (LPCSTR)((((int)p) + 3) & ~3);
668 /***********************************************************************
669 * DIALOG_CreateIndirect
670 * Creates a dialog box window
672 * modal = TRUE if we are called from a modal dialog box.
673 * (it's more compatible to do it here, as under Windows the owner
674 * is never disabled if the dialog fails because of an invalid template)
676 static HWND DIALOG_CreateIndirect( HINSTANCE hInst, LPCSTR dlgTemplate,
677 BOOL win32Template, HWND owner,
678 DLGPROC16 dlgProc, LPARAM param,
679 WINDOWPROCTYPE procType, BOOL modal )
681 HMENU16 hMenu = 0;
682 HFONT16 hFont = 0;
683 HWND hwnd;
684 RECT rect;
685 WND * wndPtr;
686 DLG_TEMPLATE template;
687 DIALOGINFO * dlgInfo;
688 WORD xUnit = xBaseUnit;
689 WORD yUnit = yBaseUnit;
690 BOOL ownerEnabled = TRUE;
692 /* Parse dialog template */
694 if (!dlgTemplate) return 0;
695 if (win32Template)
696 dlgTemplate = DIALOG_ParseTemplate32( dlgTemplate, &template );
697 else
698 dlgTemplate = DIALOG_ParseTemplate16( dlgTemplate, &template );
700 /* Load menu */
702 if (template.menuName)
704 if (!win32Template)
706 LPSTR str = SEGPTR_STRDUP( template.menuName );
707 hMenu = LoadMenu16( hInst, SEGPTR_GET(str) );
708 SEGPTR_FREE( str );
710 else hMenu = LoadMenuW( hInst, (LPCWSTR)template.menuName );
713 /* Create custom font if needed */
715 if (template.style & DS_SETFONT)
717 /* The font height must be negative as it is a point size */
718 /* and must be converted to pixels first */
719 /* (see CreateFont() documentation in the Windows SDK). */
720 HDC dc = GetDC(0);
721 int pixels = template.pointSize * GetDeviceCaps(dc , LOGPIXELSY)/72;
722 ReleaseDC(0, dc);
724 if (win32Template)
725 hFont = CreateFontW( -pixels, 0, 0, 0, template.weight,
726 template.italic, FALSE, FALSE,
727 DEFAULT_CHARSET, 0, 0,
728 PROOF_QUALITY, FF_DONTCARE,
729 (LPCWSTR)template.faceName );
730 else
731 hFont = CreateFontA( -pixels, 0, 0, 0, FW_DONTCARE,
732 FALSE, FALSE, FALSE,
733 DEFAULT_CHARSET, 0, 0,
734 PROOF_QUALITY, FF_DONTCARE,
735 template.faceName );
736 if (hFont)
738 SIZE charSize;
739 if (DIALOG_GetCharSize(hFont,&charSize))
741 xUnit = charSize.cx;
742 yUnit = charSize.cy;
745 TRACE("units = %d,%d\n", xUnit, yUnit );
748 /* Create dialog main window */
750 rect.left = rect.top = 0;
751 rect.right = MulDiv(template.cx, xUnit, 4);
752 rect.bottom = MulDiv(template.cy, yUnit, 8);
753 if (template.style & DS_MODALFRAME)
754 template.exStyle |= WS_EX_DLGMODALFRAME;
755 AdjustWindowRectEx( &rect, template.style,
756 hMenu ? TRUE : FALSE , template.exStyle );
757 rect.right -= rect.left;
758 rect.bottom -= rect.top;
760 if ((INT16)template.x == CW_USEDEFAULT16)
762 rect.left = rect.top = win32Template? CW_USEDEFAULT : CW_USEDEFAULT16;
764 else
766 if (template.style & DS_CENTER)
768 rect.left = (GetSystemMetrics(SM_CXSCREEN) - rect.right) / 2;
769 rect.top = (GetSystemMetrics(SM_CYSCREEN) - rect.bottom) / 2;
771 else
773 rect.left += MulDiv(template.x, xUnit, 4);
774 rect.top += MulDiv(template.y, yUnit, 8);
776 if ( !(template.style & WS_CHILD) )
778 INT16 dX, dY;
780 if( !(template.style & DS_ABSALIGN) )
781 ClientToScreen( owner, (POINT *)&rect );
783 /* try to fit it into the desktop */
785 if( (dX = rect.left + rect.right + GetSystemMetrics(SM_CXDLGFRAME)
786 - GetSystemMetrics(SM_CXSCREEN)) > 0 ) rect.left -= dX;
787 if( (dY = rect.top + rect.bottom + GetSystemMetrics(SM_CYDLGFRAME)
788 - GetSystemMetrics(SM_CYSCREEN)) > 0 ) rect.top -= dY;
789 if( rect.left < 0 ) rect.left = 0;
790 if( rect.top < 0 ) rect.top = 0;
794 if (modal)
795 ownerEnabled = DIALOG_DisableOwner( owner );
797 if (!win32Template)
798 hwnd = CreateWindowEx16(template.exStyle, template.className,
799 template.caption, template.style & ~WS_VISIBLE,
800 rect.left, rect.top, rect.right, rect.bottom,
801 owner, hMenu, hInst, NULL );
802 else
803 hwnd = CreateWindowExW(template.exStyle, (LPCWSTR)template.className,
804 (LPCWSTR)template.caption,
805 template.style & ~WS_VISIBLE,
806 rect.left, rect.top, rect.right, rect.bottom,
807 owner, hMenu, hInst, NULL );
809 if (!hwnd)
811 if (hFont) DeleteObject( hFont );
812 if (hMenu) DestroyMenu( hMenu );
813 if (modal)
814 DIALOG_EnableOwner(owner, ownerEnabled);
815 return 0;
817 wndPtr = WIN_FindWndPtr( hwnd );
818 wndPtr->flags |= WIN_ISDIALOG;
819 wndPtr->helpContext = template.helpId;
821 /* Initialise dialog extra data */
823 dlgInfo = (DIALOGINFO *)wndPtr->wExtra;
824 WINPROC_SetProc( &dlgInfo->dlgProc, (WNDPROC16)dlgProc, procType, WIN_PROC_WINDOW );
825 dlgInfo->hUserFont = hFont;
826 dlgInfo->hMenu = hMenu;
827 dlgInfo->xBaseUnit = xUnit;
828 dlgInfo->yBaseUnit = yUnit;
829 dlgInfo->msgResult = 0;
830 dlgInfo->idResult = 0;
831 dlgInfo->flags = ownerEnabled ? DF_OWNERENABLED: 0;
832 dlgInfo->hDialogHeap = 0;
834 if (dlgInfo->hUserFont)
835 SendMessageA( hwnd, WM_SETFONT, (WPARAM)dlgInfo->hUserFont, 0 );
837 /* Create controls */
839 if (DIALOG_CreateControls( wndPtr, dlgTemplate, &template,
840 hInst, win32Template ))
842 HWND hwndPreInitFocus;
844 /* Send initialisation messages and set focus */
846 dlgInfo->hwndFocus = GetNextDlgTabItem( hwnd, 0, FALSE );
848 hwndPreInitFocus = GetFocus();
849 if (SendMessageA( hwnd, WM_INITDIALOG, (WPARAM)dlgInfo->hwndFocus, param ))
851 /* check where the focus is again, some controls status might have changed in
852 WM_INITDIALOG */
853 dlgInfo->hwndFocus = GetNextDlgTabItem( hwnd, 0, FALSE);
854 SetFocus( dlgInfo->hwndFocus );
856 else
858 /* If the dlgproc has returned FALSE (indicating handling of keyboard focus)
859 but the focus has not changed, set the focus where we expect it. */
860 if ( (wndPtr->dwStyle & WS_VISIBLE) && ( GetFocus() == hwndPreInitFocus ) )
862 dlgInfo->hwndFocus = GetNextDlgTabItem( hwnd, 0, FALSE);
863 SetFocus( dlgInfo->hwndFocus );
867 if (template.style & WS_VISIBLE && !(wndPtr->dwStyle & WS_VISIBLE))
869 ShowWindow( hwnd, SW_SHOWNORMAL ); /* SW_SHOW doesn't always work */
871 WIN_ReleaseWndPtr(wndPtr);
872 return hwnd;
874 WIN_ReleaseWndPtr(wndPtr);
875 if( IsWindow(hwnd) ) DestroyWindow( hwnd );
876 if (modal)
877 DIALOG_EnableOwner(owner, ownerEnabled);
878 return 0;
882 /***********************************************************************
883 * CreateDialog16 (USER.89)
885 HWND16 WINAPI CreateDialog16( HINSTANCE16 hInst, SEGPTR dlgTemplate,
886 HWND16 owner, DLGPROC16 dlgProc )
888 return CreateDialogParam16( hInst, dlgTemplate, owner, dlgProc, 0 );
892 /***********************************************************************
893 * CreateDialogParam16 (USER.241)
895 HWND16 WINAPI CreateDialogParam16( HINSTANCE16 hInst, SEGPTR dlgTemplate,
896 HWND16 owner, DLGPROC16 dlgProc,
897 LPARAM param )
899 HWND16 hwnd = 0;
900 HRSRC16 hRsrc;
901 HGLOBAL16 hmem;
902 LPCVOID data;
904 TRACE("%04x,%08lx,%04x,%08lx,%ld\n",
905 hInst, (DWORD)dlgTemplate, owner, (DWORD)dlgProc, param );
907 if (!(hRsrc = FindResource16( hInst, dlgTemplate, RT_DIALOG16 ))) return 0;
908 if (!(hmem = LoadResource16( hInst, hRsrc ))) return 0;
909 if (!(data = LockResource16( hmem ))) hwnd = 0;
910 else hwnd = CreateDialogIndirectParam16( hInst, data, owner,
911 dlgProc, param );
912 FreeResource16( hmem );
913 return hwnd;
916 /***********************************************************************
917 * CreateDialogParamA (USER32.73)
919 HWND WINAPI CreateDialogParamA( HINSTANCE hInst, LPCSTR name,
920 HWND owner, DLGPROC dlgProc,
921 LPARAM param )
923 HANDLE hrsrc = FindResourceA( hInst, name, RT_DIALOGA );
924 if (!hrsrc) return 0;
925 return CreateDialogIndirectParamA( hInst,
926 (LPVOID)LoadResource(hInst, hrsrc),
927 owner, dlgProc, param );
931 /***********************************************************************
932 * CreateDialogParamW (USER32.74)
934 HWND WINAPI CreateDialogParamW( HINSTANCE hInst, LPCWSTR name,
935 HWND owner, DLGPROC dlgProc,
936 LPARAM param )
938 HANDLE hrsrc = FindResourceW( hInst, name, RT_DIALOGW );
939 if (!hrsrc) return 0;
940 return CreateDialogIndirectParamW( hInst,
941 (LPVOID)LoadResource(hInst, hrsrc),
942 owner, dlgProc, param );
946 /***********************************************************************
947 * CreateDialogIndirect16 (USER.219)
949 HWND16 WINAPI CreateDialogIndirect16( HINSTANCE16 hInst, LPCVOID dlgTemplate,
950 HWND16 owner, DLGPROC16 dlgProc )
952 return CreateDialogIndirectParam16( hInst, dlgTemplate, owner, dlgProc, 0);
956 /***********************************************************************
957 * CreateDialogIndirectParam16 (USER.242)
959 HWND16 WINAPI CreateDialogIndirectParam16( HINSTANCE16 hInst,
960 LPCVOID dlgTemplate,
961 HWND16 owner, DLGPROC16 dlgProc,
962 LPARAM param )
964 return DIALOG_CreateIndirect( hInst, dlgTemplate, FALSE, owner,
965 dlgProc, param, WIN_PROC_16, FALSE );
969 /***********************************************************************
970 * CreateDialogIndirectParamA (USER32.69)
972 HWND WINAPI CreateDialogIndirectParamA( HINSTANCE hInst,
973 LPCVOID dlgTemplate,
974 HWND owner, DLGPROC dlgProc,
975 LPARAM param )
977 return DIALOG_CreateIndirect( hInst, dlgTemplate, TRUE, owner,
978 (DLGPROC16)dlgProc, param, WIN_PROC_32A, FALSE );
981 /***********************************************************************
982 * CreateDialogIndirectParamAorW (USER32.71)
984 HWND WINAPI CreateDialogIndirectParamAorW( HINSTANCE hInst,
985 LPCVOID dlgTemplate,
986 HWND owner, DLGPROC dlgProc,
987 LPARAM param )
988 { FIXME("assume WIN_PROC_32W\n");
989 return DIALOG_CreateIndirect( hInst, dlgTemplate, TRUE, owner,
990 (DLGPROC16)dlgProc, param, WIN_PROC_32W, FALSE );
993 /***********************************************************************
994 * CreateDialogIndirectParamW (USER32.72)
996 HWND WINAPI CreateDialogIndirectParamW( HINSTANCE hInst,
997 LPCVOID dlgTemplate,
998 HWND owner, DLGPROC dlgProc,
999 LPARAM param )
1001 return DIALOG_CreateIndirect( hInst, dlgTemplate, TRUE, owner,
1002 (DLGPROC16)dlgProc, param, WIN_PROC_32W, FALSE );
1006 /***********************************************************************
1007 * DIALOG_DoDialogBox
1009 static INT DIALOG_DoDialogBox( HWND hwnd, HWND owner )
1011 WND * wndPtr;
1012 DIALOGINFO * dlgInfo;
1013 MSG msg;
1014 INT retval;
1015 HWND ownerMsg = WIN_GetTopParent( owner );
1017 if (!(wndPtr = WIN_FindWndPtr( hwnd ))) return -1;
1018 dlgInfo = (DIALOGINFO *)wndPtr->wExtra;
1020 if (!(dlgInfo->flags & DF_END)) /* was EndDialog called in WM_INITDIALOG ? */
1022 ShowWindow( hwnd, SW_SHOW );
1023 while (MSG_InternalGetMessage(QMSG_WIN32A, &msg, hwnd, ownerMsg, MSGF_DIALOGBOX,
1024 PM_REMOVE, !(wndPtr->dwStyle & DS_NOIDLEMSG), NULL ))
1026 if (!IsDialogMessageA( hwnd, &msg))
1028 TranslateMessage( &msg );
1029 DispatchMessageA( &msg );
1031 if (dlgInfo->flags & DF_END) break;
1034 DIALOG_EnableOwner( owner, (dlgInfo->flags & DF_OWNERENABLED) );
1035 retval = dlgInfo->idResult;
1036 WIN_ReleaseWndPtr(wndPtr);
1037 DestroyWindow( hwnd );
1038 return retval;
1042 /***********************************************************************
1043 * DialogBox16 (USER.87)
1045 INT16 WINAPI DialogBox16( HINSTANCE16 hInst, SEGPTR dlgTemplate,
1046 HWND16 owner, DLGPROC16 dlgProc )
1048 return DialogBoxParam16( hInst, dlgTemplate, owner, dlgProc, 0 );
1052 /***********************************************************************
1053 * DialogBoxParam16 (USER.239)
1055 INT16 WINAPI DialogBoxParam16( HINSTANCE16 hInst, SEGPTR template,
1056 HWND16 owner, DLGPROC16 dlgProc, LPARAM param )
1058 HWND16 hwnd = 0;
1059 HRSRC16 hRsrc;
1060 HGLOBAL16 hmem;
1061 LPCVOID data;
1062 int ret = -1;
1064 if (!(hRsrc = FindResource16( hInst, template, RT_DIALOG16 ))) return 0;
1065 if (!(hmem = LoadResource16( hInst, hRsrc ))) return 0;
1066 if (!(data = LockResource16( hmem ))) hwnd = 0;
1067 else hwnd = DIALOG_CreateIndirect( hInst, data, FALSE, owner,
1068 dlgProc, param, WIN_PROC_16, TRUE );
1069 if (hwnd)
1070 ret =(INT16)DIALOG_DoDialogBox( hwnd, owner );
1071 if (data) GlobalUnlock16( hmem );
1072 FreeResource16( hmem );
1073 return ret;
1077 /***********************************************************************
1078 * DialogBoxParamA (USER32.139)
1080 INT WINAPI DialogBoxParamA( HINSTANCE hInst, LPCSTR name,
1081 HWND owner, DLGPROC dlgProc, LPARAM param )
1083 HWND hwnd;
1084 HANDLE hrsrc = FindResourceA( hInst, name, RT_DIALOGA );
1085 if (!hrsrc) return 0;
1086 hwnd = DIALOG_CreateIndirect( hInst, (LPVOID)LoadResource(hInst, hrsrc),
1087 TRUE, owner,
1088 (DLGPROC16) dlgProc, param, WIN_PROC_32A, TRUE );
1089 if (hwnd) return DIALOG_DoDialogBox( hwnd, owner );
1090 return -1;
1094 /***********************************************************************
1095 * DialogBoxParamW (USER32.140)
1097 INT WINAPI DialogBoxParamW( HINSTANCE hInst, LPCWSTR name,
1098 HWND owner, DLGPROC dlgProc, LPARAM param )
1100 HWND hwnd;
1101 HANDLE hrsrc = FindResourceW( hInst, name, RT_DIALOGW );
1102 if (!hrsrc) return 0;
1103 hwnd = DIALOG_CreateIndirect( hInst, (LPVOID)LoadResource(hInst, hrsrc),
1104 TRUE, owner,
1105 (DLGPROC16)dlgProc, param, WIN_PROC_32W, TRUE );
1106 if (hwnd) return DIALOG_DoDialogBox( hwnd, owner );
1107 return -1;
1111 /***********************************************************************
1112 * DialogBoxIndirect16 (USER.218)
1114 INT16 WINAPI DialogBoxIndirect16( HINSTANCE16 hInst, HANDLE16 dlgTemplate,
1115 HWND16 owner, DLGPROC16 dlgProc )
1117 return DialogBoxIndirectParam16( hInst, dlgTemplate, owner, dlgProc, 0 );
1121 /***********************************************************************
1122 * DialogBoxIndirectParam16 (USER.240)
1124 INT16 WINAPI DialogBoxIndirectParam16( HINSTANCE16 hInst, HANDLE16 dlgTemplate,
1125 HWND16 owner, DLGPROC16 dlgProc,
1126 LPARAM param )
1128 HWND16 hwnd;
1129 LPCVOID ptr;
1131 if (!(ptr = GlobalLock16( dlgTemplate ))) return -1;
1132 hwnd = DIALOG_CreateIndirect( hInst, ptr, FALSE, owner,
1133 dlgProc, param, WIN_PROC_16, TRUE );
1134 GlobalUnlock16( dlgTemplate );
1135 if (hwnd) return DIALOG_DoDialogBox( hwnd, owner );
1136 return -1;
1140 /***********************************************************************
1141 * DialogBoxIndirectParamA (USER32.136)
1143 INT WINAPI DialogBoxIndirectParamA(HINSTANCE hInstance, LPCVOID template,
1144 HWND owner, DLGPROC dlgProc,
1145 LPARAM param )
1147 HWND hwnd = DIALOG_CreateIndirect( hInstance, template, TRUE, owner,
1148 (DLGPROC16) dlgProc, param, WIN_PROC_32A, TRUE );
1149 if (hwnd) return DIALOG_DoDialogBox( hwnd, owner );
1150 return -1;
1154 /***********************************************************************
1155 * DialogBoxIndirectParamW (USER32.138)
1157 INT WINAPI DialogBoxIndirectParamW(HINSTANCE hInstance, LPCVOID template,
1158 HWND owner, DLGPROC dlgProc,
1159 LPARAM param )
1161 HWND hwnd = DIALOG_CreateIndirect( hInstance, template, TRUE, owner,
1162 (DLGPROC16)dlgProc, param, WIN_PROC_32W, TRUE );
1163 if (hwnd) return DIALOG_DoDialogBox( hwnd, owner );
1164 return -1;
1167 /***********************************************************************
1168 * DialogBoxIndirectParamAorW (USER32.138)
1170 INT WINAPI DialogBoxIndirectParamAorW(HINSTANCE hInstance, LPCVOID template,
1171 HWND owner, DLGPROC dlgProc,
1172 LPARAM param, DWORD x )
1174 HWND hwnd;
1175 FIXME("0x%08x %p 0x%08x %p 0x%08lx 0x%08lx\n",
1176 hInstance, template, owner, dlgProc, param, x);
1177 hwnd = DIALOG_CreateIndirect( hInstance, template, TRUE, owner,
1178 (DLGPROC16)dlgProc, param, WIN_PROC_32W, TRUE );
1179 if (hwnd) return DIALOG_DoDialogBox( hwnd, owner );
1180 return -1;
1183 /***********************************************************************
1184 * EndDialog16 (USER.88)
1186 BOOL16 WINAPI EndDialog16( HWND16 hwnd, INT16 retval )
1188 return EndDialog( hwnd, retval );
1192 /***********************************************************************
1193 * EndDialog (USER32.173)
1195 BOOL WINAPI EndDialog( HWND hwnd, INT retval )
1197 WND * wndPtr = WIN_FindWndPtr( hwnd );
1198 BOOL wasEnabled = TRUE;
1199 DIALOGINFO * dlgInfo;
1201 TRACE("%04x %d\n", hwnd, retval );
1203 if (!wndPtr)
1205 ERR("got invalid window handle (%04x); buggy app !?\n", hwnd);
1206 return FALSE;
1209 if ((dlgInfo = (DIALOGINFO *)wndPtr->wExtra))
1211 dlgInfo->idResult = retval;
1212 dlgInfo->flags |= DF_END;
1213 wasEnabled = (dlgInfo->flags & DF_OWNERENABLED);
1216 if(wndPtr->owner)
1217 DIALOG_EnableOwner( wndPtr->owner->hwndSelf, wasEnabled );
1219 /* Windows sets the focus to the dialog itself in EndDialog */
1221 if (IsChild(hwnd, GetFocus()))
1222 SetFocus(wndPtr->hwndSelf);
1224 /* Don't have to send a ShowWindow(SW_HIDE), just do
1225 SetWindowPos with SWP_HIDEWINDOW as done in Windows */
1227 SetWindowPos(hwnd, (HWND)0, 0, 0, 0, 0, SWP_NOMOVE | SWP_NOSIZE
1228 | SWP_NOZORDER | SWP_NOACTIVATE | SWP_HIDEWINDOW);
1230 WIN_ReleaseWndPtr(wndPtr);
1232 return TRUE;
1236 /***********************************************************************
1237 * DIALOG_IsAccelerator
1239 static BOOL DIALOG_IsAccelerator( HWND hwnd, HWND hwndDlg, WPARAM vKey )
1241 HWND hwndControl = hwnd;
1242 HWND hwndNext;
1243 WND *wndPtr;
1244 BOOL RetVal = FALSE;
1245 INT dlgCode;
1249 wndPtr = WIN_FindWndPtr( hwndControl );
1250 if ( (wndPtr != NULL) &&
1251 ((wndPtr->dwStyle & (WS_VISIBLE | WS_DISABLED)) == WS_VISIBLE) )
1253 dlgCode = SendMessageA( hwndControl, WM_GETDLGCODE, 0, 0 );
1254 if ( (dlgCode & (DLGC_BUTTON | DLGC_STATIC)) &&
1255 (wndPtr->text!=NULL))
1257 /* find the accelerator key */
1258 LPWSTR p = wndPtr->text - 2;
1261 p = strchrW( p + 2, '&' );
1263 while (p != NULL && p[1] == '&');
1265 /* and check if it's the one we're looking for */
1266 /* FIXME: convert vKey to unicode */
1267 if (p != NULL && toupperW( p[1] ) == (WCHAR)toupper( vKey ) )
1269 if ((dlgCode & DLGC_STATIC) ||
1270 (wndPtr->dwStyle & 0x0f) == BS_GROUPBOX )
1272 /* set focus to the control */
1273 SendMessageA( hwndDlg, WM_NEXTDLGCTL,
1274 hwndControl, 1);
1275 /* and bump it on to next */
1276 SendMessageA( hwndDlg, WM_NEXTDLGCTL, 0, 0);
1278 else if (dlgCode & DLGC_BUTTON)
1280 /* send BM_CLICK message to the control */
1281 SendMessageA( hwndControl, BM_CLICK, 0, 0 );
1284 RetVal = TRUE;
1285 WIN_ReleaseWndPtr(wndPtr);
1286 break;
1289 hwndNext = GetWindow( hwndControl, GW_CHILD );
1291 else
1293 hwndNext = 0;
1295 WIN_ReleaseWndPtr(wndPtr);
1296 if (!hwndNext)
1298 hwndNext = GetWindow( hwndControl, GW_HWNDNEXT );
1300 while (!hwndNext && hwndControl)
1302 hwndControl = GetParent( hwndControl );
1303 if (hwndControl == hwndDlg)
1305 if(hwnd==hwndDlg){ /* prevent endless loop */
1306 hwndNext=hwnd;
1307 break;
1309 hwndNext = GetWindow( hwndDlg, GW_CHILD );
1311 else
1313 hwndNext = GetWindow( hwndControl, GW_HWNDNEXT );
1316 hwndControl = hwndNext;
1318 while (hwndControl && (hwndControl != hwnd));
1320 return RetVal;
1323 /***********************************************************************
1324 * DIALOG_FindMsgDestination
1326 * The messages that IsDialogMessage send may not go to the dialog
1327 * calling IsDialogMessage if that dialog is a child, and it has the
1328 * DS_CONTROL style set.
1329 * We propagate up until we hit a that does not have DS_CONTROL, or
1330 * whose parent is not a dialog.
1332 * This is undocumented behaviour.
1334 static HWND DIALOG_FindMsgDestination( HWND hwndDlg )
1336 while (GetWindowLongA(hwndDlg, GWL_STYLE) & DS_CONTROL)
1338 WND *pParent;
1339 HWND hParent = GetParent(hwndDlg);
1340 if (!hParent) break;
1342 pParent = WIN_FindWndPtr(hParent);
1343 if (!pParent) break;
1345 if (!(pParent->flags & WIN_ISDIALOG))
1347 WIN_ReleaseWndPtr(pParent);
1348 break;
1350 WIN_ReleaseWndPtr(pParent);
1352 hwndDlg = hParent;
1355 return hwndDlg;
1358 /***********************************************************************
1359 * DIALOG_IsDialogMessage
1361 static BOOL DIALOG_IsDialogMessage( HWND hwnd, HWND hwndDlg,
1362 UINT message, WPARAM wParam,
1363 LPARAM lParam, BOOL *translate,
1364 BOOL *dispatch, INT dlgCode )
1366 *translate = *dispatch = FALSE;
1368 if (message == WM_PAINT)
1370 /* Apparently, we have to handle this one as well */
1371 *dispatch = TRUE;
1372 return TRUE;
1375 /* Only the key messages get special processing */
1376 if ((message != WM_KEYDOWN) &&
1377 (message != WM_SYSCHAR) &&
1378 (message != WM_CHAR))
1379 return FALSE;
1381 if (dlgCode & DLGC_WANTMESSAGE)
1383 *translate = *dispatch = TRUE;
1384 return TRUE;
1387 hwndDlg = DIALOG_FindMsgDestination(hwndDlg);
1389 switch(message)
1391 case WM_KEYDOWN:
1392 switch(wParam)
1394 case VK_TAB:
1395 if (!(dlgCode & DLGC_WANTTAB))
1397 SendMessageA( hwndDlg, WM_NEXTDLGCTL,
1398 (GetKeyState(VK_SHIFT) & 0x8000), 0 );
1399 return TRUE;
1401 break;
1403 case VK_RIGHT:
1404 case VK_DOWN:
1405 case VK_LEFT:
1406 case VK_UP:
1407 if (!(dlgCode & DLGC_WANTARROWS))
1409 BOOL fPrevious = (wParam == VK_LEFT || wParam == VK_UP);
1410 HWND hwndNext =
1411 GetNextDlgGroupItem (hwndDlg, GetFocus(), fPrevious );
1412 SendMessageA( hwndDlg, WM_NEXTDLGCTL, hwndNext, 1 );
1413 return TRUE;
1415 break;
1417 case VK_ESCAPE:
1418 SendMessageA( hwndDlg, WM_COMMAND, IDCANCEL,
1419 (LPARAM)GetDlgItem( hwndDlg, IDCANCEL ) );
1420 return TRUE;
1422 case VK_RETURN:
1424 DWORD dw = SendMessage16( hwndDlg, DM_GETDEFID, 0, 0 );
1425 if (HIWORD(dw) == DC_HASDEFID)
1427 SendMessageA( hwndDlg, WM_COMMAND,
1428 MAKEWPARAM( LOWORD(dw), BN_CLICKED ),
1429 (LPARAM)GetDlgItem(hwndDlg, LOWORD(dw)));
1431 else
1433 SendMessageA( hwndDlg, WM_COMMAND, IDOK,
1434 (LPARAM)GetDlgItem( hwndDlg, IDOK ) );
1438 return TRUE;
1440 *translate = TRUE;
1441 break; /* case WM_KEYDOWN */
1443 case WM_CHAR:
1444 if (dlgCode & DLGC_WANTCHARS) break;
1445 /* drop through */
1447 case WM_SYSCHAR:
1448 if (DIALOG_IsAccelerator( hwnd, hwndDlg, wParam ))
1450 /* don't translate or dispatch */
1451 return TRUE;
1453 break;
1456 /* If we get here, the message has not been treated specially */
1457 /* and can be sent to its destination window. */
1458 *dispatch = TRUE;
1459 return TRUE;
1463 /***********************************************************************
1464 * IsDialogMessage16 (USER.90)
1466 BOOL16 WINAPI WIN16_IsDialogMessage16( HWND16 hwndDlg, SEGPTR msg16 )
1468 LPMSG16 msg = PTR_SEG_TO_LIN(msg16);
1469 BOOL ret, translate, dispatch;
1470 INT dlgCode = 0;
1472 if ((hwndDlg != msg->hwnd) && !IsChild16( hwndDlg, msg->hwnd ))
1473 return FALSE;
1475 if ((msg->message == WM_KEYDOWN) ||
1476 (msg->message == WM_SYSCHAR) ||
1477 (msg->message == WM_CHAR))
1479 dlgCode = SendMessage16( msg->hwnd, WM_GETDLGCODE, 0, (LPARAM)msg16);
1481 ret = DIALOG_IsDialogMessage( msg->hwnd, hwndDlg, msg->message,
1482 msg->wParam, msg->lParam,
1483 &translate, &dispatch, dlgCode );
1484 if (translate) TranslateMessage16( msg );
1485 if (dispatch) DispatchMessage16( msg );
1486 return ret;
1490 BOOL16 WINAPI IsDialogMessage16( HWND16 hwndDlg, LPMSG16 msg )
1492 LPMSG16 msg16 = SEGPTR_NEW(MSG16);
1493 BOOL ret;
1495 *msg16 = *msg;
1496 ret = WIN16_IsDialogMessage16( hwndDlg, SEGPTR_GET(msg16) );
1497 SEGPTR_FREE(msg16);
1498 return ret;
1501 /***********************************************************************
1502 * IsDialogMessageA (USER32.342)
1504 BOOL WINAPI IsDialogMessageA( HWND hwndDlg, LPMSG msg )
1506 BOOL ret, translate, dispatch;
1507 INT dlgCode = 0;
1509 if ((hwndDlg != msg->hwnd) && !IsChild( hwndDlg, msg->hwnd ))
1510 return FALSE;
1512 if ((msg->message == WM_KEYDOWN) ||
1513 (msg->message == WM_SYSCHAR) ||
1514 (msg->message == WM_CHAR))
1516 dlgCode = SendMessageA( msg->hwnd, WM_GETDLGCODE, 0, (LPARAM)msg);
1518 ret = DIALOG_IsDialogMessage( msg->hwnd, hwndDlg, msg->message,
1519 msg->wParam, msg->lParam,
1520 &translate, &dispatch, dlgCode );
1521 if (translate) TranslateMessage( msg );
1522 if (dispatch) DispatchMessageA( msg );
1523 return ret;
1527 /***********************************************************************
1528 * IsDialogMessageW (USER32.343)
1530 BOOL WINAPI IsDialogMessageW( HWND hwndDlg, LPMSG msg )
1532 BOOL ret, translate, dispatch;
1533 INT dlgCode = 0;
1535 if ((hwndDlg != msg->hwnd) && !IsChild( hwndDlg, msg->hwnd ))
1536 return FALSE;
1538 if ((msg->message == WM_KEYDOWN) ||
1539 (msg->message == WM_SYSCHAR) ||
1540 (msg->message == WM_CHAR))
1542 dlgCode = SendMessageW( msg->hwnd, WM_GETDLGCODE, 0, (LPARAM)msg);
1544 ret = DIALOG_IsDialogMessage( msg->hwnd, hwndDlg, msg->message,
1545 msg->wParam, msg->lParam,
1546 &translate, &dispatch, dlgCode );
1547 if (translate) TranslateMessage( msg );
1548 if (dispatch) DispatchMessageW( msg );
1549 return ret;
1553 /***********************************************************************
1554 * GetDlgCtrlID16 (USER.277)
1556 INT16 WINAPI GetDlgCtrlID16( HWND16 hwnd )
1558 WND *wndPtr = WIN_FindWndPtr(hwnd);
1559 INT16 retvalue;
1561 if (!wndPtr) return 0;
1563 retvalue = wndPtr->wIDmenu;
1564 WIN_ReleaseWndPtr(wndPtr);
1565 return retvalue;
1569 /***********************************************************************
1570 * GetDlgCtrlID (USER32.234)
1572 INT WINAPI GetDlgCtrlID( HWND hwnd )
1574 INT retvalue;
1575 WND *wndPtr = WIN_FindWndPtr(hwnd);
1576 if (!wndPtr) return 0;
1577 retvalue = wndPtr->wIDmenu;
1578 WIN_ReleaseWndPtr(wndPtr);
1579 return retvalue;
1583 /***********************************************************************
1584 * GetDlgItem16 (USER.91)
1586 HWND16 WINAPI GetDlgItem16( HWND16 hwndDlg, INT16 id )
1588 WND *pWnd;
1590 if (!(pWnd = WIN_FindWndPtr( hwndDlg ))) return 0;
1591 for (WIN_UpdateWndPtr(&pWnd,pWnd->child); pWnd; WIN_UpdateWndPtr(&pWnd,pWnd->next))
1592 if (pWnd->wIDmenu == (UINT16)id)
1594 HWND16 retvalue = pWnd->hwndSelf;
1595 WIN_ReleaseWndPtr(pWnd);
1596 return retvalue;
1598 return 0;
1602 /***********************************************************************
1603 * GetDlgItem (USER32.235)
1605 HWND WINAPI GetDlgItem( HWND hwndDlg, INT id )
1607 WND *pWnd;
1609 if (!(pWnd = WIN_FindWndPtr( hwndDlg ))) return 0;
1610 for (WIN_UpdateWndPtr(&pWnd,pWnd->child); pWnd;WIN_UpdateWndPtr(&pWnd,pWnd->next))
1611 if (pWnd->wIDmenu == (UINT16)id)
1613 HWND retvalue = pWnd->hwndSelf;
1614 WIN_ReleaseWndPtr(pWnd);
1615 return retvalue;
1617 return 0;
1621 /*******************************************************************
1622 * SendDlgItemMessage16 (USER.101)
1624 LRESULT WINAPI SendDlgItemMessage16( HWND16 hwnd, INT16 id, UINT16 msg,
1625 WPARAM16 wParam, LPARAM lParam )
1627 HWND16 hwndCtrl = GetDlgItem16( hwnd, id );
1628 if (hwndCtrl) return SendMessage16( hwndCtrl, msg, wParam, lParam );
1629 else return 0;
1633 /*******************************************************************
1634 * SendDlgItemMessageA (USER32.452)
1636 LRESULT WINAPI SendDlgItemMessageA( HWND hwnd, INT id, UINT msg,
1637 WPARAM wParam, LPARAM lParam )
1639 HWND hwndCtrl = GetDlgItem( hwnd, id );
1640 if (hwndCtrl) return SendMessageA( hwndCtrl, msg, wParam, lParam );
1641 else return 0;
1645 /*******************************************************************
1646 * SendDlgItemMessageW (USER32.453)
1648 LRESULT WINAPI SendDlgItemMessageW( HWND hwnd, INT id, UINT msg,
1649 WPARAM wParam, LPARAM lParam )
1651 HWND hwndCtrl = GetDlgItem( hwnd, id );
1652 if (hwndCtrl) return SendMessageW( hwndCtrl, msg, wParam, lParam );
1653 else return 0;
1657 /*******************************************************************
1658 * SetDlgItemText16 (USER.92)
1660 void WINAPI SetDlgItemText16( HWND16 hwnd, INT16 id, SEGPTR lpString )
1662 SendDlgItemMessage16( hwnd, id, WM_SETTEXT, 0, (LPARAM)lpString );
1666 /*******************************************************************
1667 * SetDlgItemTextA (USER32.478)
1669 BOOL WINAPI SetDlgItemTextA( HWND hwnd, INT id, LPCSTR lpString )
1671 return SendDlgItemMessageA( hwnd, id, WM_SETTEXT, 0, (LPARAM)lpString );
1675 /*******************************************************************
1676 * SetDlgItemTextW (USER32.479)
1678 BOOL WINAPI SetDlgItemTextW( HWND hwnd, INT id, LPCWSTR lpString )
1680 return SendDlgItemMessageW( hwnd, id, WM_SETTEXT, 0, (LPARAM)lpString );
1684 /***********************************************************************
1685 * GetDlgItemText16 (USER.93)
1687 INT16 WINAPI GetDlgItemText16( HWND16 hwnd, INT16 id, SEGPTR str, UINT16 len )
1689 return (INT16)SendDlgItemMessage16( hwnd, id, WM_GETTEXT,
1690 len, (LPARAM)str );
1694 /***********************************************************************
1695 * GetDlgItemTextA (USER32.237)
1697 INT WINAPI GetDlgItemTextA( HWND hwnd, INT id, LPSTR str, UINT len )
1699 return (INT)SendDlgItemMessageA( hwnd, id, WM_GETTEXT,
1700 len, (LPARAM)str );
1704 /***********************************************************************
1705 * GetDlgItemTextW (USER32.238)
1707 INT WINAPI GetDlgItemTextW( HWND hwnd, INT id, LPWSTR str, UINT len )
1709 return (INT)SendDlgItemMessageW( hwnd, id, WM_GETTEXT,
1710 len, (LPARAM)str );
1714 /*******************************************************************
1715 * SetDlgItemInt16 (USER.94)
1717 void WINAPI SetDlgItemInt16( HWND16 hwnd, INT16 id, UINT16 value, BOOL16 fSigned )
1719 SetDlgItemInt( hwnd, (UINT)(UINT16)id, value, fSigned );
1723 /*******************************************************************
1724 * SetDlgItemInt (USER32.477)
1726 BOOL WINAPI SetDlgItemInt( HWND hwnd, INT id, UINT value,
1727 BOOL fSigned )
1729 char str[20];
1731 if (fSigned) sprintf( str, "%d", (INT)value );
1732 else sprintf( str, "%u", value );
1733 SendDlgItemMessageA( hwnd, id, WM_SETTEXT, 0, (LPARAM)str );
1734 return TRUE;
1738 /***********************************************************************
1739 * GetDlgItemInt16 (USER.95)
1741 UINT16 WINAPI GetDlgItemInt16( HWND16 hwnd, INT16 id, BOOL16 *translated,
1742 BOOL16 fSigned )
1744 UINT result;
1745 BOOL ok;
1747 if (translated) *translated = FALSE;
1748 result = GetDlgItemInt( hwnd, (UINT)(UINT16)id, &ok, fSigned );
1749 if (!ok) return 0;
1750 if (fSigned)
1752 if (((INT)result < -32767) || ((INT)result > 32767)) return 0;
1754 else
1756 if (result > 65535) return 0;
1758 if (translated) *translated = TRUE;
1759 return (UINT16)result;
1763 /***********************************************************************
1764 * GetDlgItemInt (USER32.236)
1766 UINT WINAPI GetDlgItemInt( HWND hwnd, INT id, BOOL *translated,
1767 BOOL fSigned )
1769 char str[30];
1770 char * endptr;
1771 long result = 0;
1773 if (translated) *translated = FALSE;
1774 if (!SendDlgItemMessageA(hwnd, id, WM_GETTEXT, sizeof(str), (LPARAM)str))
1775 return 0;
1776 if (fSigned)
1778 result = strtol( str, &endptr, 10 );
1779 if (!endptr || (endptr == str)) /* Conversion was unsuccessful */
1780 return 0;
1781 if (((result == LONG_MIN) || (result == LONG_MAX)) && (errno==ERANGE))
1782 return 0;
1784 else
1786 result = strtoul( str, &endptr, 10 );
1787 if (!endptr || (endptr == str)) /* Conversion was unsuccessful */
1788 return 0;
1789 if ((result == ULONG_MAX) && (errno == ERANGE)) return 0;
1791 if (translated) *translated = TRUE;
1792 return (UINT)result;
1796 /***********************************************************************
1797 * CheckDlgButton16 (USER.97)
1799 BOOL16 WINAPI CheckDlgButton16( HWND16 hwnd, INT16 id, UINT16 check )
1801 SendDlgItemMessageA( hwnd, id, BM_SETCHECK, check, 0 );
1802 return TRUE;
1806 /***********************************************************************
1807 * CheckDlgButton (USER32.45)
1809 BOOL WINAPI CheckDlgButton( HWND hwnd, INT id, UINT check )
1811 SendDlgItemMessageA( hwnd, id, BM_SETCHECK, check, 0 );
1812 return TRUE;
1816 /***********************************************************************
1817 * IsDlgButtonChecked16 (USER.98)
1819 UINT16 WINAPI IsDlgButtonChecked16( HWND16 hwnd, UINT16 id )
1821 return (UINT16)SendDlgItemMessageA( hwnd, id, BM_GETCHECK, 0, 0 );
1825 /***********************************************************************
1826 * IsDlgButtonChecked (USER32.344)
1828 UINT WINAPI IsDlgButtonChecked( HWND hwnd, UINT id )
1830 return (UINT)SendDlgItemMessageA( hwnd, id, BM_GETCHECK, 0, 0 );
1834 /***********************************************************************
1835 * CheckRadioButton16 (USER.96)
1837 BOOL16 WINAPI CheckRadioButton16( HWND16 hwndDlg, UINT16 firstID,
1838 UINT16 lastID, UINT16 checkID )
1840 return CheckRadioButton( hwndDlg, firstID, lastID, checkID );
1844 /***********************************************************************
1845 * CheckRB
1847 * Callback function used to check/uncheck radio buttons that fall
1848 * within a specific range of IDs.
1850 static BOOL CALLBACK CheckRB(HWND hwndChild, LPARAM lParam)
1852 LONG lChildID = GetWindowLongA(hwndChild, GWL_ID);
1853 RADIOGROUP *lpRadioGroup = (RADIOGROUP *) lParam;
1855 if ((lChildID >= lpRadioGroup->firstID) &&
1856 (lChildID <= lpRadioGroup->lastID))
1858 if (lChildID == lpRadioGroup->checkID)
1860 SendMessageA(hwndChild, BM_SETCHECK, BST_CHECKED, 0);
1862 else
1864 SendMessageA(hwndChild, BM_SETCHECK, BST_UNCHECKED, 0);
1868 return TRUE;
1872 /***********************************************************************
1873 * CheckRadioButton (USER32.48)
1875 BOOL WINAPI CheckRadioButton( HWND hwndDlg, UINT firstID,
1876 UINT lastID, UINT checkID )
1878 RADIOGROUP radioGroup;
1880 /* perform bounds checking for a radio button group */
1881 radioGroup.firstID = min(min(firstID, lastID), checkID);
1882 radioGroup.lastID = max(max(firstID, lastID), checkID);
1883 radioGroup.checkID = checkID;
1885 return EnumChildWindows(hwndDlg, (WNDENUMPROC)CheckRB,
1886 (LPARAM)&radioGroup);
1890 /***********************************************************************
1891 * GetDialogBaseUnits (USER.243) (USER32.233)
1893 DWORD WINAPI GetDialogBaseUnits(void)
1895 return MAKELONG( xBaseUnit, yBaseUnit );
1899 /***********************************************************************
1900 * MapDialogRect16 (USER.103)
1902 void WINAPI MapDialogRect16( HWND16 hwnd, LPRECT16 rect )
1904 DIALOGINFO * dlgInfo;
1905 WND * wndPtr = WIN_FindWndPtr( hwnd );
1906 if (!wndPtr) return;
1907 dlgInfo = (DIALOGINFO *)wndPtr->wExtra;
1908 rect->left = MulDiv(rect->left, dlgInfo->xBaseUnit, 4);
1909 rect->right = MulDiv(rect->right, dlgInfo->xBaseUnit, 4);
1910 rect->top = MulDiv(rect->top, dlgInfo->yBaseUnit, 8);
1911 rect->bottom = MulDiv(rect->bottom, dlgInfo->yBaseUnit, 8);
1912 WIN_ReleaseWndPtr(wndPtr);
1916 /***********************************************************************
1917 * MapDialogRect (USER32.382)
1919 BOOL WINAPI MapDialogRect( HWND hwnd, LPRECT rect )
1921 DIALOGINFO * dlgInfo;
1922 WND * wndPtr = WIN_FindWndPtr( hwnd );
1923 if (!wndPtr) return FALSE;
1924 dlgInfo = (DIALOGINFO *)wndPtr->wExtra;
1925 rect->left = MulDiv(rect->left, dlgInfo->xBaseUnit, 4);
1926 rect->right = MulDiv(rect->right, dlgInfo->xBaseUnit, 4);
1927 rect->top = MulDiv(rect->top, dlgInfo->yBaseUnit, 8);
1928 rect->bottom = MulDiv(rect->bottom, dlgInfo->yBaseUnit, 8);
1929 WIN_ReleaseWndPtr(wndPtr);
1930 return TRUE;
1934 /***********************************************************************
1935 * GetNextDlgGroupItem16 (USER.227)
1937 HWND16 WINAPI GetNextDlgGroupItem16( HWND16 hwndDlg, HWND16 hwndCtrl,
1938 BOOL16 fPrevious )
1940 return (HWND16)GetNextDlgGroupItem( hwndDlg, hwndCtrl, fPrevious );
1944 /***********************************************************************
1945 * GetNextDlgGroupItem (USER32.275)
1947 HWND WINAPI GetNextDlgGroupItem( HWND hwndDlg, HWND hwndCtrl,
1948 BOOL fPrevious )
1950 WND *pWnd = NULL,
1951 *pWndLast = NULL,
1952 *pWndCtrl = NULL,
1953 *pWndDlg = NULL;
1954 HWND retvalue;
1956 if(hwndCtrl)
1958 /* if the hwndCtrl is the child of the control in the hwndDlg then the hwndDlg has to be the parent of the hwndCtrl */
1959 if(GetParent(hwndCtrl) != hwndDlg && GetParent(GetParent(hwndCtrl)) == hwndDlg)
1960 hwndDlg = GetParent(hwndCtrl);
1963 if (!(pWndDlg = WIN_FindWndPtr( hwndDlg ))) return 0;
1964 if (hwndCtrl)
1966 if (!(pWndCtrl = WIN_FindWndPtr( hwndCtrl )))
1968 retvalue = 0;
1969 goto END;
1971 /* Make sure hwndCtrl is a top-level child */
1972 while ((pWndCtrl->dwStyle & WS_CHILD) && (pWndCtrl->parent != pWndDlg))
1973 WIN_UpdateWndPtr(&pWndCtrl,pWndCtrl->parent);
1974 if (pWndCtrl->parent != pWndDlg)
1976 retvalue = 0;
1977 goto END;
1980 else
1982 /* No ctrl specified -> start from the beginning */
1983 if (!(pWndCtrl = WIN_LockWndPtr(pWndDlg->child)))
1985 retvalue = 0;
1986 goto END;
1988 if (fPrevious)
1989 while (pWndCtrl->next) WIN_UpdateWndPtr(&pWndCtrl,pWndCtrl->next);
1992 pWndLast = WIN_LockWndPtr(pWndCtrl);
1993 pWnd = WIN_LockWndPtr(pWndCtrl->next);
1995 while (1)
1997 if (!pWnd || (pWnd->dwStyle & WS_GROUP))
1999 /* Wrap-around to the beginning of the group */
2000 WND *pWndTemp;
2002 WIN_UpdateWndPtr( &pWnd, pWndDlg->child );
2003 for ( pWndTemp = WIN_LockWndPtr( pWnd );
2004 pWndTemp;
2005 WIN_UpdateWndPtr( &pWndTemp, pWndTemp->next) )
2007 if (pWndTemp->dwStyle & WS_GROUP) WIN_UpdateWndPtr( &pWnd, pWndTemp );
2008 if (pWndTemp == pWndCtrl) break;
2010 WIN_ReleaseWndPtr( pWndTemp );
2012 if (pWnd == pWndCtrl) break;
2013 if ((pWnd->dwStyle & WS_VISIBLE) && !(pWnd->dwStyle & WS_DISABLED))
2015 WIN_UpdateWndPtr(&pWndLast,pWnd);
2016 if (!fPrevious) break;
2018 WIN_UpdateWndPtr(&pWnd,pWnd->next);
2020 retvalue = pWndLast->hwndSelf;
2022 WIN_ReleaseWndPtr(pWndLast);
2023 WIN_ReleaseWndPtr(pWnd);
2024 END:
2025 WIN_ReleaseWndPtr(pWndCtrl);
2026 WIN_ReleaseWndPtr(pWndDlg);
2028 return retvalue;
2032 /***********************************************************************
2033 * GetNextDlgTabItem16 (USER.228)
2035 HWND16 WINAPI GetNextDlgTabItem16( HWND16 hwndDlg, HWND16 hwndCtrl,
2036 BOOL16 fPrevious )
2038 return (HWND16)GetNextDlgTabItem( hwndDlg, hwndCtrl, fPrevious );
2041 /***********************************************************************
2042 * DIALOG_GetNextTabItem
2044 * Helper for GetNextDlgTabItem
2046 static HWND DIALOG_GetNextTabItem( HWND hwndMain, HWND hwndDlg, HWND hwndCtrl, BOOL fPrevious )
2048 LONG dsStyle;
2049 LONG exStyle;
2050 UINT wndSearch = fPrevious ? GW_HWNDPREV : GW_HWNDNEXT;
2051 HWND retWnd = 0;
2052 HWND hChildFirst = 0;
2054 if(!hwndCtrl)
2056 hChildFirst = GetWindow(hwndDlg,GW_CHILD);
2057 if(fPrevious) hChildFirst = GetWindow(hChildFirst,GW_HWNDLAST);
2059 else
2061 HWND hParent = GetParent(hwndCtrl);
2062 BOOL bValid = FALSE;
2063 while( hParent)
2065 if(hParent == hwndMain)
2067 bValid = TRUE;
2068 break;
2070 hParent = GetParent(hParent);
2072 if(bValid)
2074 hChildFirst = GetWindow(hwndCtrl,wndSearch);
2075 if(!hChildFirst)
2077 if(GetParent(hwndCtrl) != hwndMain)
2078 hChildFirst = GetWindow(GetParent(hwndCtrl),wndSearch);
2079 else
2081 if(fPrevious)
2082 hChildFirst = GetWindow(hwndCtrl,GW_HWNDLAST);
2083 else
2084 hChildFirst = GetWindow(hwndCtrl,GW_HWNDFIRST);
2089 while(hChildFirst)
2091 BOOL bCtrl = FALSE;
2092 while(hChildFirst)
2094 dsStyle = GetWindowLongA(hChildFirst,GWL_STYLE);
2095 exStyle = GetWindowLongA(hChildFirst,GWL_EXSTYLE);
2096 if( (dsStyle & DS_CONTROL || exStyle & WS_EX_CONTROLPARENT) && (dsStyle & WS_VISIBLE) && !(dsStyle & WS_DISABLED))
2098 bCtrl=TRUE;
2099 break;
2101 else if( (dsStyle & WS_TABSTOP) && (dsStyle & WS_VISIBLE) && !(dsStyle & WS_DISABLED))
2102 break;
2103 hChildFirst = GetWindow(hChildFirst,wndSearch);
2105 if(hChildFirst)
2107 if(bCtrl)
2108 retWnd = DIALOG_GetNextTabItem(hwndMain,hChildFirst,(HWND)NULL,fPrevious );
2109 else
2110 retWnd = hChildFirst;
2112 if(retWnd) break;
2113 hChildFirst = GetWindow(hChildFirst,wndSearch);
2115 if(!retWnd && hwndCtrl)
2117 HWND hParent = GetParent(hwndCtrl);
2118 while(hParent)
2120 if(hParent == hwndMain) break;
2121 retWnd = DIALOG_GetNextTabItem(hwndMain,GetParent(hParent),hParent,fPrevious );
2122 if(retWnd) break;
2123 hParent = GetParent(hParent);
2125 if(!retWnd)
2126 retWnd = DIALOG_GetNextTabItem(hwndMain,hwndMain,(HWND)NULL,fPrevious );
2128 return retWnd;
2131 /***********************************************************************
2132 * GetNextDlgTabItem (USER32.276)
2134 HWND WINAPI GetNextDlgTabItem( HWND hwndDlg, HWND hwndCtrl,
2135 BOOL fPrevious )
2137 return DIALOG_GetNextTabItem(hwndDlg,hwndDlg,hwndCtrl,fPrevious);
2140 /**********************************************************************
2141 * DIALOG_DlgDirSelect
2143 * Helper function for DlgDirSelect*
2145 static BOOL DIALOG_DlgDirSelect( HWND hwnd, LPSTR str, INT len,
2146 INT id, BOOL win32, BOOL unicode,
2147 BOOL combo )
2149 char *buffer, *ptr;
2150 INT item, size;
2151 BOOL ret;
2152 HWND listbox = GetDlgItem( hwnd, id );
2154 TRACE("%04x '%s' %d\n", hwnd, str, id );
2155 if (!listbox) return FALSE;
2156 if (win32)
2158 item = SendMessageA(listbox, combo ? CB_GETCURSEL
2159 : LB_GETCURSEL, 0, 0 );
2160 if (item == LB_ERR) return FALSE;
2161 size = SendMessageA(listbox, combo ? CB_GETLBTEXTLEN
2162 : LB_GETTEXTLEN, 0, 0 );
2163 if (size == LB_ERR) return FALSE;
2165 else
2167 item = SendMessageA(listbox, combo ? CB_GETCURSEL16
2168 : LB_GETCURSEL16, 0, 0 );
2169 if (item == LB_ERR) return FALSE;
2170 size = SendMessageA(listbox, combo ? CB_GETLBTEXTLEN16
2171 : LB_GETTEXTLEN16, 0, 0 );
2172 if (size == LB_ERR) return FALSE;
2175 if (!(buffer = SEGPTR_ALLOC( size+1 ))) return FALSE;
2177 if (win32)
2178 SendMessageA( listbox, combo ? CB_GETLBTEXT : LB_GETTEXT,
2179 item, (LPARAM)buffer );
2180 else
2181 SendMessage16( listbox, combo ? CB_GETLBTEXT16 : LB_GETTEXT16,
2182 item, (LPARAM)SEGPTR_GET(buffer) );
2184 if ((ret = (buffer[0] == '['))) /* drive or directory */
2186 if (buffer[1] == '-') /* drive */
2188 buffer[3] = ':';
2189 buffer[4] = 0;
2190 ptr = buffer + 2;
2192 else
2194 buffer[strlen(buffer)-1] = '\\';
2195 ptr = buffer + 1;
2198 else ptr = buffer;
2200 if (unicode) lstrcpynAtoW( (LPWSTR)str, ptr, len );
2201 else lstrcpynA( str, ptr, len );
2202 SEGPTR_FREE( buffer );
2203 TRACE("Returning %d '%s'\n", ret, str );
2204 return ret;
2208 /**********************************************************************
2209 * DIALOG_DlgDirList
2211 * Helper function for DlgDirList*
2213 static INT DIALOG_DlgDirList( HWND hDlg, LPSTR spec, INT idLBox,
2214 INT idStatic, UINT attrib, BOOL combo )
2216 int drive;
2217 HWND hwnd;
2218 LPSTR orig_spec = spec;
2220 #define SENDMSG(msg,wparam,lparam) \
2221 ((attrib & DDL_POSTMSGS) ? PostMessageA( hwnd, msg, wparam, lparam ) \
2222 : SendMessageA( hwnd, msg, wparam, lparam ))
2224 TRACE("%04x '%s' %d %d %04x\n",
2225 hDlg, spec ? spec : "NULL", idLBox, idStatic, attrib );
2227 if (spec && spec[0] && (spec[1] == ':'))
2229 drive = toupper( spec[0] ) - 'A';
2230 spec += 2;
2231 if (!DRIVE_SetCurrentDrive( drive )) return FALSE;
2233 else drive = DRIVE_GetCurrentDrive();
2235 /* If the path exists and is a directory, chdir to it */
2236 if (!spec || !spec[0] || DRIVE_Chdir( drive, spec )) spec = "*.*";
2237 else
2239 char *p, *p2;
2240 p = spec;
2241 if ((p2 = strrchr( p, '\\' ))) p = p2;
2242 if ((p2 = strrchr( p, '/' ))) p = p2;
2243 if (p != spec)
2245 char sep = *p;
2246 *p = 0;
2247 if (!DRIVE_Chdir( drive, spec ))
2249 *p = sep; /* Restore the original spec */
2250 return FALSE;
2252 spec = p + 1;
2256 TRACE("path=%c:\\%s mask=%s\n",
2257 'A' + drive, DRIVE_GetDosCwd(drive), spec );
2259 if (idLBox && ((hwnd = GetDlgItem( hDlg, idLBox )) != 0))
2261 SENDMSG( combo ? CB_RESETCONTENT : LB_RESETCONTENT, 0, 0 );
2262 if (attrib & DDL_DIRECTORY)
2264 if (!(attrib & DDL_EXCLUSIVE))
2266 if (SENDMSG( combo ? CB_DIR : LB_DIR,
2267 attrib & ~(DDL_DIRECTORY | DDL_DRIVES),
2268 (LPARAM)spec ) == LB_ERR)
2269 return FALSE;
2271 if (SENDMSG( combo ? CB_DIR : LB_DIR,
2272 (attrib & (DDL_DIRECTORY | DDL_DRIVES)) | DDL_EXCLUSIVE,
2273 (LPARAM)"*.*" ) == LB_ERR)
2274 return FALSE;
2276 else
2278 if (SENDMSG( combo ? CB_DIR : LB_DIR, attrib,
2279 (LPARAM)spec ) == LB_ERR)
2280 return FALSE;
2284 if (idStatic && ((hwnd = GetDlgItem( hDlg, idStatic )) != 0))
2286 char temp[512];
2287 int drive = DRIVE_GetCurrentDrive();
2288 strcpy( temp, "A:\\" );
2289 temp[0] += drive;
2290 lstrcpynA( temp + 3, DRIVE_GetDosCwd(drive), sizeof(temp)-3 );
2291 CharLowerA( temp );
2292 /* Can't use PostMessage() here, because the string is on the stack */
2293 SetDlgItemTextA( hDlg, idStatic, temp );
2296 if (orig_spec && (spec != orig_spec))
2298 /* Update the original file spec */
2299 char *p = spec;
2300 while ((*orig_spec++ = *p++));
2303 return TRUE;
2304 #undef SENDMSG
2308 /**********************************************************************
2309 * DIALOG_DlgDirListW
2311 * Helper function for DlgDirList*W
2313 static INT DIALOG_DlgDirListW( HWND hDlg, LPWSTR spec, INT idLBox,
2314 INT idStatic, UINT attrib, BOOL combo )
2316 if (spec)
2318 LPSTR specA = HEAP_strdupWtoA( GetProcessHeap(), 0, spec );
2319 INT ret = DIALOG_DlgDirList( hDlg, specA, idLBox, idStatic,
2320 attrib, combo );
2321 lstrcpyAtoW( spec, specA );
2322 HeapFree( GetProcessHeap(), 0, specA );
2323 return ret;
2325 return DIALOG_DlgDirList( hDlg, NULL, idLBox, idStatic, attrib, combo );
2329 /**********************************************************************
2330 * DlgDirSelect (USER.99)
2332 BOOL16 WINAPI DlgDirSelect16( HWND16 hwnd, LPSTR str, INT16 id )
2334 return DlgDirSelectEx16( hwnd, str, 128, id );
2338 /**********************************************************************
2339 * DlgDirSelectComboBox (USER.194)
2341 BOOL16 WINAPI DlgDirSelectComboBox16( HWND16 hwnd, LPSTR str, INT16 id )
2343 return DlgDirSelectComboBoxEx16( hwnd, str, 128, id );
2347 /**********************************************************************
2348 * DlgDirSelectEx16 (USER.422)
2350 BOOL16 WINAPI DlgDirSelectEx16( HWND16 hwnd, LPSTR str, INT16 len, INT16 id )
2352 return DIALOG_DlgDirSelect( hwnd, str, len, id, FALSE, FALSE, FALSE );
2356 /**********************************************************************
2357 * DlgDirSelectExA (USER32.149)
2359 BOOL WINAPI DlgDirSelectExA( HWND hwnd, LPSTR str, INT len, INT id )
2361 return DIALOG_DlgDirSelect( hwnd, str, len, id, TRUE, FALSE, FALSE );
2365 /**********************************************************************
2366 * DlgDirSelectExW (USER32.150)
2368 BOOL WINAPI DlgDirSelectExW( HWND hwnd, LPWSTR str, INT len, INT id )
2370 return DIALOG_DlgDirSelect( hwnd, (LPSTR)str, len, id, TRUE, TRUE, FALSE );
2374 /**********************************************************************
2375 * DlgDirSelectComboBoxEx16 (USER.423)
2377 BOOL16 WINAPI DlgDirSelectComboBoxEx16( HWND16 hwnd, LPSTR str, INT16 len,
2378 INT16 id )
2380 return DIALOG_DlgDirSelect( hwnd, str, len, id, FALSE, FALSE, TRUE );
2384 /**********************************************************************
2385 * DlgDirSelectComboBoxExA (USER32.147)
2387 BOOL WINAPI DlgDirSelectComboBoxExA( HWND hwnd, LPSTR str, INT len,
2388 INT id )
2390 return DIALOG_DlgDirSelect( hwnd, str, len, id, TRUE, FALSE, TRUE );
2394 /**********************************************************************
2395 * DlgDirSelectComboBoxExW (USER32.148)
2397 BOOL WINAPI DlgDirSelectComboBoxExW( HWND hwnd, LPWSTR str, INT len,
2398 INT id)
2400 return DIALOG_DlgDirSelect( hwnd, (LPSTR)str, len, id, TRUE, TRUE, TRUE );
2404 /**********************************************************************
2405 * DlgDirList16 (USER.100)
2407 INT16 WINAPI DlgDirList16( HWND16 hDlg, LPSTR spec, INT16 idLBox,
2408 INT16 idStatic, UINT16 attrib )
2410 return DIALOG_DlgDirList( hDlg, spec, idLBox, idStatic, attrib, FALSE );
2414 /**********************************************************************
2415 * DlgDirListA (USER32.143)
2417 INT WINAPI DlgDirListA( HWND hDlg, LPSTR spec, INT idLBox,
2418 INT idStatic, UINT attrib )
2420 return DIALOG_DlgDirList( hDlg, spec, idLBox, idStatic, attrib, FALSE );
2424 /**********************************************************************
2425 * DlgDirListW (USER32.146)
2427 INT WINAPI DlgDirListW( HWND hDlg, LPWSTR spec, INT idLBox,
2428 INT idStatic, UINT attrib )
2430 return DIALOG_DlgDirListW( hDlg, spec, idLBox, idStatic, attrib, FALSE );
2434 /**********************************************************************
2435 * DlgDirListComboBox16 (USER.195)
2437 INT16 WINAPI DlgDirListComboBox16( HWND16 hDlg, LPSTR spec, INT16 idCBox,
2438 INT16 idStatic, UINT16 attrib )
2440 return DIALOG_DlgDirList( hDlg, spec, idCBox, idStatic, attrib, TRUE );
2444 /**********************************************************************
2445 * DlgDirListComboBoxA (USER32.144)
2447 INT WINAPI DlgDirListComboBoxA( HWND hDlg, LPSTR spec, INT idCBox,
2448 INT idStatic, UINT attrib )
2450 return DIALOG_DlgDirList( hDlg, spec, idCBox, idStatic, attrib, TRUE );
2454 /**********************************************************************
2455 * DlgDirListComboBoxW (USER32.145)
2457 INT WINAPI DlgDirListComboBoxW( HWND hDlg, LPWSTR spec, INT idCBox,
2458 INT idStatic, UINT attrib )
2460 return DIALOG_DlgDirListW( hDlg, spec, idCBox, idStatic, attrib, TRUE );