Added registry support to the server.
[wine.git] / windows / dialog.c
blobfdf3c28ffc418dd36b085e336dd1ff2b543b0ffd
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 <string.h>
12 #include "winuser.h"
13 #include "windowsx.h"
14 #include "wine/winuser16.h"
15 #include "wine/winbase16.h"
16 #include "dialog.h"
17 #include "drive.h"
18 #include "heap.h"
19 #include "win.h"
20 #include "ldt.h"
21 #include "user.h"
22 #include "winproc.h"
23 #include "message.h"
24 #include "debugtools.h"
26 DEFAULT_DEBUG_CHANNEL(dialog)
29 /* Dialog control information */
30 typedef struct
32 DWORD style;
33 DWORD exStyle;
34 DWORD helpId;
35 INT16 x;
36 INT16 y;
37 INT16 cx;
38 INT16 cy;
39 UINT id;
40 LPCSTR className;
41 LPCSTR windowName;
42 LPVOID data;
43 } DLG_CONTROL_INFO;
45 /* Dialog template */
46 typedef struct
48 DWORD style;
49 DWORD exStyle;
50 DWORD helpId;
51 UINT16 nbItems;
52 INT16 x;
53 INT16 y;
54 INT16 cx;
55 INT16 cy;
56 LPCSTR menuName;
57 LPCSTR className;
58 LPCSTR caption;
59 WORD pointSize;
60 WORD weight;
61 BOOL italic;
62 LPCSTR faceName;
63 BOOL dialogEx;
64 } DLG_TEMPLATE;
66 /* Radio button group */
67 typedef struct
69 UINT firstID;
70 UINT lastID;
71 UINT checkID;
72 } RADIOGROUP;
74 /* Dialog base units */
75 static WORD xBaseUnit = 0, yBaseUnit = 0;
77 /***********************************************************************
78 * DIALOG_GetCharSizeFromDC
81 * Calculates the *true* average size of English characters in the
82 * specified font as oppposed to the one returned by GetTextMetrics.
84 * Latest: the X font driver will now compute a proper average width
85 * so this code can be removed
87 static BOOL DIALOG_GetCharSizeFromDC( HDC hDC, HFONT hFont, SIZE * pSize )
89 BOOL Success = FALSE;
90 HFONT hFontPrev = 0;
91 pSize->cx = xBaseUnit;
92 pSize->cy = yBaseUnit;
93 if ( hDC )
95 /* select the font */
96 TEXTMETRICA tm;
97 memset(&tm,0,sizeof(tm));
98 if (hFont) hFontPrev = SelectFont(hDC,hFont);
99 if (GetTextMetricsA(hDC,&tm))
101 pSize->cx = tm.tmAveCharWidth;
102 pSize->cy = tm.tmHeight;
104 /* if variable width font */
105 if (tm.tmPitchAndFamily & TMPF_FIXED_PITCH)
107 SIZE total;
108 const char* szAvgChars = "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ";
110 /* Calculate a true average as opposed to the one returned
111 * by tmAveCharWidth. This works better when dealing with
112 * proportional spaced fonts and (more important) that's
113 * how Microsoft's dialog creation code calculates the size
114 * of the font
116 if (GetTextExtentPointA(hDC,szAvgChars,sizeof(szAvgChars),&total))
118 /* round up */
119 pSize->cx = ((2*total.cx/sizeof(szAvgChars)) + 1)/2;
120 Success = TRUE;
123 else
125 Success = TRUE;
127 /* Use the text metrics */
128 TRACE("Using tm: %ldx%ld (dlg: %dx%d) (%s)\n", tm.tmAveCharWidth, tm.tmHeight, pSize->cx, pSize->cy,
129 tm.tmPitchAndFamily & TMPF_FIXED_PITCH ? "variable" : "fixed");
130 pSize->cx = tm.tmAveCharWidth;
131 pSize->cy = tm.tmHeight;
133 /* select the original font */
134 if (hFontPrev) SelectFont(hDC,hFontPrev);
136 return (Success);
139 /***********************************************************************
140 * DIALOG_GetCharSize
142 * A convenient variant of DIALOG_GetCharSizeFromDC.
144 static BOOL DIALOG_GetCharSize( HFONT hFont, SIZE * pSize )
146 HDC hDC = GetDC(0);
147 BOOL Success = DIALOG_GetCharSizeFromDC( hDC, hFont, pSize );
148 ReleaseDC(0, hDC);
149 return Success;
152 /***********************************************************************
153 * DIALOG_Init
155 * Initialisation of the dialog manager.
157 BOOL DIALOG_Init(void)
159 HDC16 hdc;
160 SIZE size;
162 /* Calculate the dialog base units */
164 if (!(hdc = CreateDC16( "DISPLAY", NULL, NULL, NULL ))) return FALSE;
165 if (!DIALOG_GetCharSizeFromDC( hdc, 0, &size )) return FALSE;
166 DeleteDC( hdc );
167 xBaseUnit = size.cx;
168 yBaseUnit = size.cy;
170 TRACE("base units = %d,%d\n", xBaseUnit, yBaseUnit );
171 return TRUE;
175 /***********************************************************************
176 * DIALOG_GetControl16
178 * Return the class and text of the control pointed to by ptr,
179 * fill the header structure and return a pointer to the next control.
181 static LPCSTR DIALOG_GetControl16( LPCSTR p, DLG_CONTROL_INFO *info )
183 static char buffer[10];
184 int int_id;
186 info->x = GET_WORD(p); p += sizeof(WORD);
187 info->y = GET_WORD(p); p += sizeof(WORD);
188 info->cx = GET_WORD(p); p += sizeof(WORD);
189 info->cy = GET_WORD(p); p += sizeof(WORD);
190 info->id = GET_WORD(p); p += sizeof(WORD);
191 info->style = GET_DWORD(p); p += sizeof(DWORD);
192 info->exStyle = 0;
194 if (*p & 0x80)
196 switch((BYTE)*p)
198 case 0x80: strcpy( buffer, "BUTTON" ); break;
199 case 0x81: strcpy( buffer, "EDIT" ); break;
200 case 0x82: strcpy( buffer, "STATIC" ); break;
201 case 0x83: strcpy( buffer, "LISTBOX" ); break;
202 case 0x84: strcpy( buffer, "SCROLLBAR" ); break;
203 case 0x85: strcpy( buffer, "COMBOBOX" ); break;
204 default: buffer[0] = '\0'; break;
206 info->className = buffer;
207 p++;
209 else
211 info->className = p;
212 p += strlen(p) + 1;
215 int_id = ((BYTE)*p == 0xff);
216 if (int_id)
218 /* Integer id, not documented (?). Only works for SS_ICON controls */
219 info->windowName = (LPCSTR)(UINT)GET_WORD(p+1);
220 p += 3;
222 else
224 info->windowName = p;
225 p += strlen(p) + 1;
228 info->data = (LPVOID)(*p ? p + 1 : NULL); /* FIXME: should be a segptr */
229 p += *p + 1;
231 if(int_id)
232 TRACE(" %s %04x %d, %d, %d, %d, %d, %08lx, %08lx\n",
233 info->className, LOWORD(info->windowName),
234 info->id, info->x, info->y, info->cx, info->cy,
235 info->style, (DWORD)info->data);
236 else
237 TRACE(" %s '%s' %d, %d, %d, %d, %d, %08lx, %08lx\n",
238 info->className, info->windowName,
239 info->id, info->x, info->y, info->cx, info->cy,
240 info->style, (DWORD)info->data);
242 return p;
246 /***********************************************************************
247 * DIALOG_GetControl32
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 const WORD *DIALOG_GetControl32( const WORD *p, DLG_CONTROL_INFO *info,
253 BOOL dialogEx )
255 if (dialogEx)
257 info->helpId = GET_DWORD(p); p += 2;
258 info->exStyle = GET_DWORD(p); p += 2;
259 info->style = GET_DWORD(p); p += 2;
261 else
263 info->helpId = 0;
264 info->style = GET_DWORD(p); p += 2;
265 info->exStyle = GET_DWORD(p); p += 2;
267 info->x = GET_WORD(p); p++;
268 info->y = GET_WORD(p); p++;
269 info->cx = GET_WORD(p); p++;
270 info->cy = GET_WORD(p); p++;
272 if (dialogEx)
274 /* id is a DWORD for DIALOGEX */
275 info->id = GET_DWORD(p);
276 p += 2;
278 else
280 info->id = GET_WORD(p);
281 p++;
284 if (GET_WORD(p) == 0xffff)
286 static const WCHAR class_names[6][10] =
288 { 'B','u','t','t','o','n', }, /* 0x80 */
289 { 'E','d','i','t', }, /* 0x81 */
290 { 'S','t','a','t','i','c', }, /* 0x82 */
291 { 'L','i','s','t','B','o','x', }, /* 0x83 */
292 { 'S','c','r','o','l','l','B','a','r', }, /* 0x84 */
293 { 'C','o','m','b','o','B','o','x', } /* 0x85 */
295 WORD id = GET_WORD(p+1);
296 if ((id >= 0x80) && (id <= 0x85))
297 info->className = (LPCSTR)class_names[id - 0x80];
298 else
300 info->className = NULL;
301 ERR("Unknown built-in class id %04x\n", id );
303 p += 2;
305 else
307 info->className = (LPCSTR)p;
308 p += lstrlenW( (LPCWSTR)p ) + 1;
311 if (GET_WORD(p) == 0xffff) /* Is it an integer id? */
313 info->windowName = (LPCSTR)(UINT)GET_WORD(p + 1);
314 p += 2;
316 else
318 info->windowName = (LPCSTR)p;
319 p += lstrlenW( (LPCWSTR)p ) + 1;
322 TRACE(" %s %s %d, %d, %d, %d, %d, %08lx, %08lx, %08lx\n",
323 debugstr_w( (LPCWSTR)info->className ),
324 debugres_w( (LPCWSTR)info->windowName ),
325 info->id, info->x, info->y, info->cx, info->cy,
326 info->style, info->exStyle, info->helpId );
328 if (GET_WORD(p))
330 if (TRACE_ON(dialog))
332 WORD i, count = GET_WORD(p) / sizeof(WORD);
333 TRACE(" BEGIN\n");
334 TRACE(" ");
335 for (i = 0; i < count; i++) DPRINTF( "%04x,", GET_WORD(p+i+1) );
336 DPRINTF("\n");
337 TRACE(" END\n" );
339 info->data = (LPVOID)(p + 1);
340 p += GET_WORD(p) / sizeof(WORD);
342 else info->data = NULL;
343 p++;
345 /* Next control is on dword boundary */
346 return (const WORD *)((((int)p) + 3) & ~3);
350 /***********************************************************************
351 * DIALOG_CreateControls
353 * Create the control windows for a dialog.
355 static BOOL DIALOG_CreateControls( WND *pWnd, LPCSTR template,
356 const DLG_TEMPLATE *dlgTemplate,
357 HINSTANCE hInst, BOOL win32 )
359 DIALOGINFO *dlgInfo = (DIALOGINFO *)pWnd->wExtra;
360 DLG_CONTROL_INFO info;
361 HWND hwndCtrl, hwndDefButton = 0;
362 INT items = dlgTemplate->nbItems;
364 TRACE(" BEGIN\n" );
365 while (items--)
367 if (!win32)
369 HINSTANCE16 instance;
370 template = DIALOG_GetControl16( template, &info );
371 if (HIWORD(info.className) && !strcmp( info.className, "EDIT") &&
372 ((pWnd->dwStyle & DS_LOCALEDIT) != DS_LOCALEDIT))
374 if (!dlgInfo->hDialogHeap)
376 dlgInfo->hDialogHeap = GlobalAlloc16(GMEM_FIXED, 0x10000);
377 if (!dlgInfo->hDialogHeap)
379 ERR("Insufficient memory to create heap for edit control\n" );
380 continue;
382 LocalInit16(dlgInfo->hDialogHeap, 0, 0xffff);
384 instance = dlgInfo->hDialogHeap;
386 else instance = (HINSTANCE16)hInst;
388 hwndCtrl = CreateWindowEx16( info.exStyle | WS_EX_NOPARENTNOTIFY,
389 info.className, info.windowName,
390 info.style | WS_CHILD,
391 MulDiv(info.x, dlgInfo->xBaseUnit, 4),
392 MulDiv(info.y, dlgInfo->yBaseUnit, 8),
393 MulDiv(info.cx, dlgInfo->xBaseUnit, 4),
394 MulDiv(info.cy, dlgInfo->yBaseUnit, 8),
395 pWnd->hwndSelf, (HMENU16)info.id,
396 instance, info.data );
398 else
400 template = (LPCSTR)DIALOG_GetControl32( (WORD *)template, &info,
401 dlgTemplate->dialogEx );
402 hwndCtrl = CreateWindowExW( info.exStyle | WS_EX_NOPARENTNOTIFY,
403 (LPCWSTR)info.className,
404 (LPCWSTR)info.windowName,
405 info.style | WS_CHILD,
406 MulDiv(info.x, dlgInfo->xBaseUnit, 4),
407 MulDiv(info.y, dlgInfo->yBaseUnit, 8),
408 MulDiv(info.cx, dlgInfo->xBaseUnit, 4),
409 MulDiv(info.cy, dlgInfo->yBaseUnit, 8),
410 pWnd->hwndSelf, (HMENU)info.id,
411 hInst, info.data );
413 if (!hwndCtrl) return FALSE;
415 /* Send initialisation messages to the control */
416 if (dlgInfo->hUserFont) SendMessageA( hwndCtrl, WM_SETFONT,
417 (WPARAM)dlgInfo->hUserFont, 0 );
418 if (SendMessageA(hwndCtrl, WM_GETDLGCODE, 0, 0) & DLGC_DEFPUSHBUTTON)
420 /* If there's already a default push-button, set it back */
421 /* to normal and use this one instead. */
422 if (hwndDefButton)
423 SendMessageA( hwndDefButton, BM_SETSTYLE,
424 BS_PUSHBUTTON,FALSE );
425 hwndDefButton = hwndCtrl;
426 dlgInfo->idResult = GetWindowWord( hwndCtrl, GWW_ID );
429 TRACE(" END\n" );
430 return TRUE;
434 /***********************************************************************
435 * DIALOG_ParseTemplate16
437 * Fill a DLG_TEMPLATE structure from the dialog template, and return
438 * a pointer to the first control.
440 static LPCSTR DIALOG_ParseTemplate16( LPCSTR p, DLG_TEMPLATE * result )
442 result->style = GET_DWORD(p); p += sizeof(DWORD);
443 result->exStyle = 0;
444 result->nbItems = (unsigned char) *p++;
445 result->x = GET_WORD(p); p += sizeof(WORD);
446 result->y = GET_WORD(p); p += sizeof(WORD);
447 result->cx = GET_WORD(p); p += sizeof(WORD);
448 result->cy = GET_WORD(p); p += sizeof(WORD);
449 TRACE("DIALOG %d, %d, %d, %d\n",
450 result->x, result->y, result->cx, result->cy );
451 TRACE(" STYLE %08lx\n", result->style );
453 /* Get the menu name */
455 switch( (BYTE)*p )
457 case 0:
458 result->menuName = 0;
459 p++;
460 break;
461 case 0xff:
462 result->menuName = (LPCSTR)(UINT)GET_WORD( p + 1 );
463 p += 3;
464 TRACE(" MENU %04x\n", LOWORD(result->menuName) );
465 break;
466 default:
467 result->menuName = p;
468 TRACE(" MENU '%s'\n", p );
469 p += strlen(p) + 1;
470 break;
473 /* Get the class name */
475 if (*p)
477 result->className = p;
478 TRACE(" CLASS '%s'\n", result->className );
480 else result->className = DIALOG_CLASS_ATOM;
481 p += strlen(p) + 1;
483 /* Get the window caption */
485 result->caption = p;
486 p += strlen(p) + 1;
487 TRACE(" CAPTION '%s'\n", result->caption );
489 /* Get the font name */
491 if (result->style & DS_SETFONT)
493 result->pointSize = GET_WORD(p);
494 p += sizeof(WORD);
495 result->faceName = p;
496 p += strlen(p) + 1;
497 TRACE(" FONT %d,'%s'\n",
498 result->pointSize, result->faceName );
500 return p;
504 /***********************************************************************
505 * DIALOG_ParseTemplate32
507 * Fill a DLG_TEMPLATE structure from the dialog template, and return
508 * a pointer to the first control.
510 static LPCSTR DIALOG_ParseTemplate32( LPCSTR template, DLG_TEMPLATE * result )
512 const WORD *p = (const WORD *)template;
514 result->style = GET_DWORD(p); p += 2;
515 if (result->style == 0xffff0001) /* DIALOGEX resource */
517 result->dialogEx = TRUE;
518 result->helpId = GET_DWORD(p); p += 2;
519 result->exStyle = GET_DWORD(p); p += 2;
520 result->style = GET_DWORD(p); p += 2;
522 else
524 result->dialogEx = FALSE;
525 result->helpId = 0;
526 result->exStyle = GET_DWORD(p); p += 2;
528 result->nbItems = GET_WORD(p); p++;
529 result->x = GET_WORD(p); p++;
530 result->y = GET_WORD(p); p++;
531 result->cx = GET_WORD(p); p++;
532 result->cy = GET_WORD(p); p++;
533 TRACE("DIALOG%s %d, %d, %d, %d, %ld\n",
534 result->dialogEx ? "EX" : "", result->x, result->y,
535 result->cx, result->cy, result->helpId );
536 TRACE(" STYLE 0x%08lx\n", result->style );
537 TRACE(" EXSTYLE 0x%08lx\n", result->exStyle );
539 /* Get the menu name */
541 switch(GET_WORD(p))
543 case 0x0000:
544 result->menuName = NULL;
545 p++;
546 break;
547 case 0xffff:
548 result->menuName = (LPCSTR)(UINT)GET_WORD( p + 1 );
549 p += 2;
550 TRACE(" MENU %04x\n", LOWORD(result->menuName) );
551 break;
552 default:
553 result->menuName = (LPCSTR)p;
554 TRACE(" MENU %s\n", debugstr_w( (LPCWSTR)p ));
555 p += lstrlenW( (LPCWSTR)p ) + 1;
556 break;
559 /* Get the class name */
561 switch(GET_WORD(p))
563 case 0x0000:
564 result->className = DIALOG_CLASS_ATOM;
565 p++;
566 break;
567 case 0xffff:
568 result->className = (LPCSTR)(UINT)GET_WORD( p + 1 );
569 p += 2;
570 TRACE(" CLASS %04x\n", LOWORD(result->className) );
571 break;
572 default:
573 result->className = (LPCSTR)p;
574 TRACE(" CLASS %s\n", debugstr_w( (LPCWSTR)p ));
575 p += lstrlenW( (LPCWSTR)p ) + 1;
576 break;
579 /* Get the window caption */
581 result->caption = (LPCSTR)p;
582 p += lstrlenW( (LPCWSTR)p ) + 1;
583 TRACE(" CAPTION %s\n", debugstr_w( (LPCWSTR)result->caption ) );
585 /* Get the font name */
587 if (result->style & DS_SETFONT)
589 result->pointSize = GET_WORD(p);
590 p++;
591 if (result->dialogEx)
593 result->weight = GET_WORD(p); p++;
594 result->italic = LOBYTE(GET_WORD(p)); p++;
596 else
598 result->weight = FW_DONTCARE;
599 result->italic = FALSE;
601 result->faceName = (LPCSTR)p;
602 p += lstrlenW( (LPCWSTR)p ) + 1;
603 TRACE(" FONT %d, %s, %d, %s\n",
604 result->pointSize, debugstr_w( (LPCWSTR)result->faceName ),
605 result->weight, result->italic ? "TRUE" : "FALSE" );
608 /* First control is on dword boundary */
609 return (LPCSTR)((((int)p) + 3) & ~3);
613 /***********************************************************************
614 * DIALOG_CreateIndirect
616 HWND DIALOG_CreateIndirect( HINSTANCE hInst, LPCSTR dlgTemplate,
617 BOOL win32Template, HWND owner,
618 DLGPROC16 dlgProc, LPARAM param,
619 WINDOWPROCTYPE procType )
621 HMENU16 hMenu = 0;
622 HFONT16 hFont = 0;
623 HWND hwnd;
624 RECT rect;
625 WND * wndPtr;
626 DLG_TEMPLATE template;
627 DIALOGINFO * dlgInfo;
628 WORD xUnit = xBaseUnit;
629 WORD yUnit = yBaseUnit;
631 /* Parse dialog template */
633 if (!dlgTemplate) return 0;
634 if (win32Template)
635 dlgTemplate = DIALOG_ParseTemplate32( dlgTemplate, &template );
636 else
637 dlgTemplate = DIALOG_ParseTemplate16( dlgTemplate, &template );
639 /* Load menu */
641 if (template.menuName)
643 if (!win32Template)
645 LPSTR str = SEGPTR_STRDUP( template.menuName );
646 hMenu = LoadMenu16( hInst, SEGPTR_GET(str) );
647 SEGPTR_FREE( str );
649 else hMenu = LoadMenuW( hInst, (LPCWSTR)template.menuName );
652 /* Create custom font if needed */
654 if (template.style & DS_SETFONT)
656 /* The font height must be negative as it is a point size */
657 /* and must be converted to pixels first */
658 /* (see CreateFont() documentation in the Windows SDK). */
659 HDC dc = GetDC(0);
660 int pixels = template.pointSize * GetDeviceCaps(dc , LOGPIXELSY)/72;
661 ReleaseDC(0, dc);
663 if (win32Template)
664 hFont = CreateFontW( -pixels, 0, 0, 0, template.weight,
665 template.italic, FALSE, FALSE,
666 DEFAULT_CHARSET, 0, 0,
667 PROOF_QUALITY, FF_DONTCARE,
668 (LPCWSTR)template.faceName );
669 else
670 hFont = CreateFont16( -pixels, 0, 0, 0, FW_DONTCARE,
671 FALSE, FALSE, FALSE,
672 DEFAULT_CHARSET, 0, 0,
673 PROOF_QUALITY, FF_DONTCARE,
674 template.faceName );
675 if (hFont)
677 SIZE charSize;
678 DIALOG_GetCharSize(hFont,&charSize);
679 xUnit = charSize.cx;
680 yUnit = charSize.cy;
682 TRACE("units = %d,%d\n", xUnit, yUnit );
685 /* Create dialog main window */
687 rect.left = rect.top = 0;
688 rect.right = MulDiv(template.cx, xUnit, 4);
689 rect.bottom = MulDiv(template.cy, yUnit, 8);
690 if (template.style & DS_MODALFRAME)
691 template.exStyle |= WS_EX_DLGMODALFRAME;
692 AdjustWindowRectEx( &rect, template.style,
693 hMenu ? TRUE : FALSE , template.exStyle );
694 rect.right -= rect.left;
695 rect.bottom -= rect.top;
697 if ((INT16)template.x == CW_USEDEFAULT16)
699 rect.left = rect.top = win32Template? CW_USEDEFAULT : CW_USEDEFAULT16;
701 else
703 if (template.style & DS_CENTER)
705 rect.left = (GetSystemMetrics(SM_CXSCREEN) - rect.right) / 2;
706 rect.top = (GetSystemMetrics(SM_CYSCREEN) - rect.bottom) / 2;
708 else
710 rect.left += MulDiv(template.x, xUnit, 4);
711 rect.top += MulDiv(template.y, yUnit, 8);
713 if ( !(template.style & WS_CHILD) )
715 INT16 dX, dY;
717 if( !(template.style & DS_ABSALIGN) )
718 ClientToScreen( owner, (POINT *)&rect );
720 /* try to fit it into the desktop */
722 if( (dX = rect.left + rect.right + GetSystemMetrics(SM_CXDLGFRAME)
723 - GetSystemMetrics(SM_CXSCREEN)) > 0 ) rect.left -= dX;
724 if( (dY = rect.top + rect.bottom + GetSystemMetrics(SM_CYDLGFRAME)
725 - GetSystemMetrics(SM_CYSCREEN)) > 0 ) rect.top -= dY;
726 if( rect.left < 0 ) rect.left = 0;
727 if( rect.top < 0 ) rect.top = 0;
731 if (!win32Template)
732 hwnd = CreateWindowEx16(template.exStyle, template.className,
733 template.caption, template.style & ~WS_VISIBLE,
734 rect.left, rect.top, rect.right, rect.bottom,
735 owner, hMenu, hInst, NULL );
736 else
737 hwnd = CreateWindowExW(template.exStyle, (LPCWSTR)template.className,
738 (LPCWSTR)template.caption,
739 template.style & ~WS_VISIBLE,
740 rect.left, rect.top, rect.right, rect.bottom,
741 owner, hMenu, hInst, NULL );
743 if (!hwnd)
745 if (hFont) DeleteObject( hFont );
746 if (hMenu) DestroyMenu( hMenu );
747 return 0;
749 wndPtr = WIN_FindWndPtr( hwnd );
750 wndPtr->flags |= WIN_ISDIALOG;
751 wndPtr->helpContext = template.helpId;
753 /* Initialise dialog extra data */
755 dlgInfo = (DIALOGINFO *)wndPtr->wExtra;
756 WINPROC_SetProc( &dlgInfo->dlgProc, (WNDPROC16)dlgProc, procType, WIN_PROC_WINDOW );
757 dlgInfo->hUserFont = hFont;
758 dlgInfo->hMenu = hMenu;
759 dlgInfo->xBaseUnit = xUnit;
760 dlgInfo->yBaseUnit = yUnit;
761 dlgInfo->msgResult = 0;
762 dlgInfo->idResult = 0;
763 dlgInfo->flags = 0;
764 dlgInfo->hDialogHeap = 0;
766 if (dlgInfo->hUserFont)
767 SendMessageA( hwnd, WM_SETFONT, (WPARAM)dlgInfo->hUserFont, 0 );
769 /* Create controls */
771 if (DIALOG_CreateControls( wndPtr, dlgTemplate, &template,
772 hInst, win32Template ))
774 HWND hwndPreInitFocus;
776 /* Send initialisation messages and set focus */
778 dlgInfo->hwndFocus = GetNextDlgTabItem( hwnd, 0, FALSE );
780 hwndPreInitFocus = GetFocus();
781 if (SendMessageA( hwnd, WM_INITDIALOG, (WPARAM)dlgInfo->hwndFocus, param ))
782 SetFocus( dlgInfo->hwndFocus );
783 else
785 /* If the dlgproc has returned FALSE (indicating handling of keyboard focus)
786 but the focus has not changed, set the focus where we expect it. */
787 if ( GetFocus() == hwndPreInitFocus )
788 SetFocus( dlgInfo->hwndFocus );
791 if (template.style & WS_VISIBLE && !(wndPtr->dwStyle & WS_VISIBLE))
793 ShowWindow( hwnd, SW_SHOWNORMAL ); /* SW_SHOW doesn't always work */
794 UpdateWindow( hwnd );
796 WIN_ReleaseWndPtr(wndPtr);
797 return hwnd;
799 WIN_ReleaseWndPtr(wndPtr);
800 if( IsWindow(hwnd) ) DestroyWindow( hwnd );
801 return 0;
805 /***********************************************************************
806 * CreateDialog16 (USER.89)
808 HWND16 WINAPI CreateDialog16( HINSTANCE16 hInst, SEGPTR dlgTemplate,
809 HWND16 owner, DLGPROC16 dlgProc )
811 return CreateDialogParam16( hInst, dlgTemplate, owner, dlgProc, 0 );
815 /***********************************************************************
816 * CreateDialogParam16 (USER.241)
818 HWND16 WINAPI CreateDialogParam16( HINSTANCE16 hInst, SEGPTR dlgTemplate,
819 HWND16 owner, DLGPROC16 dlgProc,
820 LPARAM param )
822 HWND16 hwnd = 0;
823 HRSRC16 hRsrc;
824 HGLOBAL16 hmem;
825 LPCVOID data;
827 TRACE("%04x,%08lx,%04x,%08lx,%ld\n",
828 hInst, (DWORD)dlgTemplate, owner, (DWORD)dlgProc, param );
830 if (!(hRsrc = FindResource16( hInst, dlgTemplate, RT_DIALOG16 ))) return 0;
831 if (!(hmem = LoadResource16( hInst, hRsrc ))) return 0;
832 if (!(data = LockResource16( hmem ))) hwnd = 0;
833 else hwnd = CreateDialogIndirectParam16( hInst, data, owner,
834 dlgProc, param );
835 FreeResource16( hmem );
836 return hwnd;
839 /***********************************************************************
840 * CreateDialogParam32A (USER32.73)
842 HWND WINAPI CreateDialogParamA( HINSTANCE hInst, LPCSTR name,
843 HWND owner, DLGPROC dlgProc,
844 LPARAM param )
846 HANDLE hrsrc = FindResourceA( hInst, name, RT_DIALOGA );
847 if (!hrsrc) return 0;
848 return CreateDialogIndirectParamA( hInst,
849 (LPVOID)LoadResource(hInst, hrsrc),
850 owner, dlgProc, param );
854 /***********************************************************************
855 * CreateDialogParam32W (USER32.74)
857 HWND WINAPI CreateDialogParamW( HINSTANCE hInst, LPCWSTR name,
858 HWND owner, DLGPROC dlgProc,
859 LPARAM param )
861 HANDLE hrsrc = FindResourceW( hInst, name, RT_DIALOGW );
862 if (!hrsrc) return 0;
863 return CreateDialogIndirectParamW( hInst,
864 (LPVOID)LoadResource(hInst, hrsrc),
865 owner, dlgProc, param );
869 /***********************************************************************
870 * CreateDialogIndirect16 (USER.219)
872 HWND16 WINAPI CreateDialogIndirect16( HINSTANCE16 hInst, LPCVOID dlgTemplate,
873 HWND16 owner, DLGPROC16 dlgProc )
875 return CreateDialogIndirectParam16( hInst, dlgTemplate, owner, dlgProc, 0);
879 /***********************************************************************
880 * CreateDialogIndirectParam16 (USER.242)
882 HWND16 WINAPI CreateDialogIndirectParam16( HINSTANCE16 hInst,
883 LPCVOID dlgTemplate,
884 HWND16 owner, DLGPROC16 dlgProc,
885 LPARAM param )
887 return DIALOG_CreateIndirect( hInst, dlgTemplate, FALSE, owner,
888 dlgProc, param, WIN_PROC_16 );
892 /***********************************************************************
893 * CreateDialogIndirectParam32A (USER32.69)
895 HWND WINAPI CreateDialogIndirectParamA( HINSTANCE hInst,
896 LPCVOID dlgTemplate,
897 HWND owner, DLGPROC dlgProc,
898 LPARAM param )
900 return DIALOG_CreateIndirect( hInst, dlgTemplate, TRUE, owner,
901 (DLGPROC16)dlgProc, param, WIN_PROC_32A );
904 /***********************************************************************
905 * CreateDialogIndirectParam32AorW (USER32.71)
907 HWND WINAPI CreateDialogIndirectParamAorW( HINSTANCE hInst,
908 LPCVOID dlgTemplate,
909 HWND owner, DLGPROC dlgProc,
910 LPARAM param )
911 { FIXME("assume WIN_PROC_32W\n");
912 return DIALOG_CreateIndirect( hInst, dlgTemplate, TRUE, owner,
913 (DLGPROC16)dlgProc, param, WIN_PROC_32W );
916 /***********************************************************************
917 * CreateDialogIndirectParam32W (USER32.72)
919 HWND WINAPI CreateDialogIndirectParamW( HINSTANCE hInst,
920 LPCVOID dlgTemplate,
921 HWND owner, DLGPROC dlgProc,
922 LPARAM param )
924 return DIALOG_CreateIndirect( hInst, dlgTemplate, TRUE, owner,
925 (DLGPROC16)dlgProc, param, WIN_PROC_32W );
929 /***********************************************************************
930 * DIALOG_DoDialogBox
932 INT DIALOG_DoDialogBox( HWND hwnd, HWND owner )
934 WND * wndPtr;
935 DIALOGINFO * dlgInfo;
936 MSG msg;
937 INT retval;
939 /* Owner must be a top-level window */
940 owner = WIN_GetTopParent( owner );
941 if (!(wndPtr = WIN_FindWndPtr( hwnd ))) return -1;
942 dlgInfo = (DIALOGINFO *)wndPtr->wExtra;
944 if (!dlgInfo->flags & DF_END) /* was EndDialog called in WM_INITDIALOG ? */
946 EnableWindow( owner, FALSE );
947 ShowWindow( hwnd, SW_SHOW );
948 while (MSG_InternalGetMessage(&msg, hwnd, owner, MSGF_DIALOGBOX,
949 PM_REMOVE, !(wndPtr->dwStyle & DS_NOIDLEMSG), NULL ))
951 if (!IsDialogMessageA( hwnd, &msg))
953 TranslateMessage( &msg );
954 DispatchMessageA( &msg );
956 if (dlgInfo->flags & DF_END) break;
958 EnableWindow( owner, TRUE );
960 retval = dlgInfo->idResult;
961 WIN_ReleaseWndPtr(wndPtr);
962 DestroyWindow( hwnd );
963 return retval;
967 /***********************************************************************
968 * DialogBox16 (USER.87)
970 INT16 WINAPI DialogBox16( HINSTANCE16 hInst, SEGPTR dlgTemplate,
971 HWND16 owner, DLGPROC16 dlgProc )
973 return DialogBoxParam16( hInst, dlgTemplate, owner, dlgProc, 0 );
977 /***********************************************************************
978 * DialogBoxParam16 (USER.239)
980 INT16 WINAPI DialogBoxParam16( HINSTANCE16 hInst, SEGPTR template,
981 HWND16 owner, DLGPROC16 dlgProc, LPARAM param )
983 HWND16 hwnd = CreateDialogParam16( hInst, template, owner, dlgProc, param);
984 if (hwnd) return (INT16)DIALOG_DoDialogBox( hwnd, owner );
985 return -1;
989 /***********************************************************************
990 * DialogBoxParam32A (USER32.139)
992 INT WINAPI DialogBoxParamA( HINSTANCE hInst, LPCSTR name,
993 HWND owner, DLGPROC dlgProc, LPARAM param )
995 HWND hwnd = CreateDialogParamA( hInst, name, owner, dlgProc, param );
996 if (hwnd) return DIALOG_DoDialogBox( hwnd, owner );
997 return -1;
1001 /***********************************************************************
1002 * DialogBoxParam32W (USER32.140)
1004 INT WINAPI DialogBoxParamW( HINSTANCE hInst, LPCWSTR name,
1005 HWND owner, DLGPROC dlgProc, LPARAM param )
1007 HWND hwnd = CreateDialogParamW( hInst, name, owner, dlgProc, param );
1008 if (hwnd) return DIALOG_DoDialogBox( hwnd, owner );
1009 return -1;
1013 /***********************************************************************
1014 * DialogBoxIndirect16 (USER.218)
1016 INT16 WINAPI DialogBoxIndirect16( HINSTANCE16 hInst, HANDLE16 dlgTemplate,
1017 HWND16 owner, DLGPROC16 dlgProc )
1019 return DialogBoxIndirectParam16( hInst, dlgTemplate, owner, dlgProc, 0 );
1023 /***********************************************************************
1024 * DialogBoxIndirectParam16 (USER.240)
1026 INT16 WINAPI DialogBoxIndirectParam16( HINSTANCE16 hInst, HANDLE16 dlgTemplate,
1027 HWND16 owner, DLGPROC16 dlgProc,
1028 LPARAM param )
1030 HWND16 hwnd;
1031 LPCVOID ptr;
1033 if (!(ptr = GlobalLock16( dlgTemplate ))) return -1;
1034 hwnd = CreateDialogIndirectParam16( hInst, ptr, owner, dlgProc, param );
1035 GlobalUnlock16( dlgTemplate );
1036 if (hwnd) return (INT16)DIALOG_DoDialogBox( hwnd, owner );
1037 return -1;
1041 /***********************************************************************
1042 * DialogBoxIndirectParam32A (USER32.136)
1044 INT WINAPI DialogBoxIndirectParamA(HINSTANCE hInstance, LPCVOID template,
1045 HWND owner, DLGPROC dlgProc,
1046 LPARAM param )
1048 HWND hwnd = CreateDialogIndirectParamA( hInstance, template,
1049 owner, dlgProc, param );
1050 if (hwnd) return DIALOG_DoDialogBox( hwnd, owner );
1051 return -1;
1055 /***********************************************************************
1056 * DialogBoxIndirectParam32W (USER32.138)
1058 INT WINAPI DialogBoxIndirectParamW(HINSTANCE hInstance, LPCVOID template,
1059 HWND owner, DLGPROC dlgProc,
1060 LPARAM param )
1062 HWND hwnd = CreateDialogIndirectParamW( hInstance, template,
1063 owner, dlgProc, param );
1064 if (hwnd) return DIALOG_DoDialogBox( hwnd, owner );
1065 return -1;
1069 /***********************************************************************
1070 * EndDialog16 (USER.88)
1072 BOOL16 WINAPI EndDialog16( HWND16 hwnd, INT16 retval )
1074 return EndDialog( hwnd, retval );
1078 /***********************************************************************
1079 * EndDialog32 (USER32.173)
1081 BOOL WINAPI EndDialog( HWND hwnd, INT retval )
1083 WND * wndPtr = WIN_FindWndPtr( hwnd );
1084 DIALOGINFO * dlgInfo = (DIALOGINFO *)wndPtr->wExtra;
1085 HWND hOwner = 0;
1087 TRACE("%04x %d\n", hwnd, retval );
1089 if( dlgInfo )
1091 dlgInfo->idResult = retval;
1092 dlgInfo->flags |= DF_END;
1095 if(wndPtr->owner)
1096 hOwner = WIN_GetTopParent( wndPtr->owner->hwndSelf );
1098 /* Enable the owner first */
1099 if (hOwner && !IsWindowEnabled(hOwner))
1100 EnableWindow( hOwner, TRUE );
1102 /* Windows sets the focus to the dialog itself in EndDialog */
1104 if (IsChild(hwnd, GetFocus()))
1105 SetFocus(wndPtr->hwndSelf);
1107 /* Don't have to send a ShowWindow(SW_HIDE), just do
1108 SetWindowPos with SWP_HIDEWINDOW as done in Windows */
1110 SetWindowPos(hwnd, (HWND)0, 0, 0, 0, 0, SWP_NOMOVE | SWP_NOSIZE
1111 | SWP_NOZORDER | SWP_NOACTIVATE | SWP_HIDEWINDOW);
1113 WIN_ReleaseWndPtr(wndPtr);
1115 return TRUE;
1119 /***********************************************************************
1120 * DIALOG_IsAccelerator
1122 static BOOL DIALOG_IsAccelerator( HWND hwnd, HWND hwndDlg, WPARAM vKey )
1124 HWND hwndControl = hwnd;
1125 HWND hwndNext;
1126 WND *wndPtr;
1127 BOOL RetVal = FALSE;
1128 INT dlgCode;
1130 if (vKey == VK_SPACE)
1132 dlgCode = SendMessageA( hwndControl, WM_GETDLGCODE, 0, 0 );
1133 if (dlgCode & DLGC_BUTTON)
1135 SendMessageA( hwndControl, WM_LBUTTONDOWN, 0, 0);
1136 SendMessageA( hwndControl, WM_LBUTTONUP, 0, 0);
1137 RetVal = TRUE;
1140 else
1144 wndPtr = WIN_FindWndPtr( hwndControl );
1145 if ( (wndPtr != NULL) &&
1146 ((wndPtr->dwStyle & (WS_VISIBLE | WS_DISABLED)) == WS_VISIBLE) )
1148 dlgCode = SendMessageA( hwndControl, WM_GETDLGCODE, 0, 0 );
1149 if ( (dlgCode & (DLGC_BUTTON | DLGC_STATIC)) &&
1150 (wndPtr->text!=NULL))
1152 /* find the accelerator key */
1153 LPSTR p = wndPtr->text - 2;
1156 p = strchr( p + 2, '&' );
1158 while (p != NULL && p[1] == '&');
1160 /* and check if it's the one we're looking for */
1161 if (p != NULL && toupper( p[1] ) == toupper( vKey ) )
1163 if ((dlgCode & DLGC_STATIC) ||
1164 (wndPtr->dwStyle & 0x0f) == BS_GROUPBOX )
1166 /* set focus to the control */
1167 SendMessageA( hwndDlg, WM_NEXTDLGCTL,
1168 hwndControl, 1);
1169 /* and bump it on to next */
1170 SendMessageA( hwndDlg, WM_NEXTDLGCTL, 0, 0);
1172 else if (dlgCode &
1173 (DLGC_DEFPUSHBUTTON | DLGC_UNDEFPUSHBUTTON))
1175 /* send command message as from the control */
1176 SendMessageA( hwndDlg, WM_COMMAND,
1177 MAKEWPARAM( LOWORD(wndPtr->wIDmenu),
1178 BN_CLICKED ),
1179 (LPARAM)hwndControl );
1181 else
1183 /* click the control */
1184 SendMessageA( hwndControl, WM_LBUTTONDOWN, 0, 0);
1185 SendMessageA( hwndControl, WM_LBUTTONUP, 0, 0);
1187 RetVal = TRUE;
1188 WIN_ReleaseWndPtr(wndPtr);
1189 break;
1192 hwndNext = GetWindow( hwndControl, GW_CHILD );
1194 else
1196 hwndNext = 0;
1198 WIN_ReleaseWndPtr(wndPtr);
1199 if (!hwndNext)
1201 hwndNext = GetWindow( hwndControl, GW_HWNDNEXT );
1203 while (!hwndNext && hwndControl)
1205 hwndControl = GetParent( hwndControl );
1206 if (hwndControl == hwndDlg)
1208 if(hwnd==hwndDlg){ /* prevent endless loop */
1209 hwndNext=hwnd;
1210 break;
1212 hwndNext = GetWindow( hwndDlg, GW_CHILD );
1214 else
1216 hwndNext = GetWindow( hwndControl, GW_HWNDNEXT );
1219 hwndControl = hwndNext;
1221 while (hwndControl && (hwndControl != hwnd));
1223 return RetVal;
1227 /***********************************************************************
1228 * DIALOG_IsDialogMessage
1230 static BOOL DIALOG_IsDialogMessage( HWND hwnd, HWND hwndDlg,
1231 UINT message, WPARAM wParam,
1232 LPARAM lParam, BOOL *translate,
1233 BOOL *dispatch, INT dlgCode )
1235 *translate = *dispatch = FALSE;
1237 if (message == WM_PAINT)
1239 /* Apparently, we have to handle this one as well */
1240 *dispatch = TRUE;
1241 return TRUE;
1244 /* Only the key messages get special processing */
1245 if ((message != WM_KEYDOWN) &&
1246 (message != WM_SYSCHAR) &&
1247 (message != WM_CHAR))
1248 return FALSE;
1250 if (dlgCode & DLGC_WANTMESSAGE)
1252 *translate = *dispatch = TRUE;
1253 return TRUE;
1256 switch(message)
1258 case WM_KEYDOWN:
1259 switch(wParam)
1261 case VK_TAB:
1262 if (!(dlgCode & DLGC_WANTTAB))
1264 SendMessageA( hwndDlg, WM_NEXTDLGCTL,
1265 (GetKeyState(VK_SHIFT) & 0x8000), 0 );
1266 return TRUE;
1268 break;
1270 case VK_RIGHT:
1271 case VK_DOWN:
1272 case VK_LEFT:
1273 case VK_UP:
1274 if (!(dlgCode & DLGC_WANTARROWS))
1276 BOOL fPrevious = (wParam == VK_LEFT || wParam == VK_UP);
1277 HWND hwndNext =
1278 GetNextDlgGroupItem (hwndDlg, GetFocus(), fPrevious );
1279 SendMessageA( hwndDlg, WM_NEXTDLGCTL, hwndNext, 1 );
1280 return TRUE;
1282 break;
1284 case VK_ESCAPE:
1285 SendMessageA( hwndDlg, WM_COMMAND, IDCANCEL,
1286 (LPARAM)GetDlgItem( hwndDlg, IDCANCEL ) );
1287 return TRUE;
1289 case VK_RETURN:
1291 DWORD dw = SendMessage16( hwndDlg, DM_GETDEFID, 0, 0 );
1292 if (HIWORD(dw) == DC_HASDEFID)
1294 SendMessageA( hwndDlg, WM_COMMAND,
1295 MAKEWPARAM( LOWORD(dw), BN_CLICKED ),
1296 (LPARAM)GetDlgItem(hwndDlg, LOWORD(dw)));
1298 else
1300 SendMessageA( hwndDlg, WM_COMMAND, IDOK,
1301 (LPARAM)GetDlgItem( hwndDlg, IDOK ) );
1305 return TRUE;
1307 *translate = TRUE;
1308 break; /* case WM_KEYDOWN */
1310 case WM_CHAR:
1311 if (dlgCode & DLGC_WANTCHARS) break;
1312 /* drop through */
1314 case WM_SYSCHAR:
1315 if (DIALOG_IsAccelerator( hwnd, hwndDlg, wParam ))
1317 /* don't translate or dispatch */
1318 return TRUE;
1320 break;
1323 /* If we get here, the message has not been treated specially */
1324 /* and can be sent to its destination window. */
1325 *dispatch = TRUE;
1326 return TRUE;
1330 /***********************************************************************
1331 * IsDialogMessage16 (USER.90)
1333 BOOL16 WINAPI WIN16_IsDialogMessage16( HWND16 hwndDlg, SEGPTR msg16 )
1335 LPMSG16 msg = PTR_SEG_TO_LIN(msg16);
1336 BOOL ret, translate, dispatch;
1337 INT dlgCode = 0;
1339 if ((hwndDlg != msg->hwnd) && !IsChild16( hwndDlg, msg->hwnd ))
1340 return FALSE;
1342 if ((msg->message == WM_KEYDOWN) ||
1343 (msg->message == WM_SYSCHAR) ||
1344 (msg->message == WM_CHAR))
1346 dlgCode = SendMessage16( msg->hwnd, WM_GETDLGCODE, 0, (LPARAM)msg16);
1348 ret = DIALOG_IsDialogMessage( msg->hwnd, hwndDlg, msg->message,
1349 msg->wParam, msg->lParam,
1350 &translate, &dispatch, dlgCode );
1351 if (translate) TranslateMessage16( msg );
1352 if (dispatch) DispatchMessage16( msg );
1353 return ret;
1357 BOOL16 WINAPI IsDialogMessage16( HWND16 hwndDlg, LPMSG16 msg )
1359 LPMSG16 msg16 = SEGPTR_NEW(MSG16);
1360 BOOL ret;
1362 *msg16 = *msg;
1363 ret = WIN16_IsDialogMessage16( hwndDlg, SEGPTR_GET(msg16) );
1364 SEGPTR_FREE(msg16);
1365 return ret;
1368 /***********************************************************************
1369 * IsDialogMessage32A (USER32.342)
1371 BOOL WINAPI IsDialogMessageA( HWND hwndDlg, LPMSG msg )
1373 BOOL ret, translate, dispatch;
1374 INT dlgCode = 0;
1376 if ((hwndDlg != msg->hwnd) && !IsChild( hwndDlg, msg->hwnd ))
1377 return FALSE;
1379 if ((msg->message == WM_KEYDOWN) ||
1380 (msg->message == WM_SYSCHAR) ||
1381 (msg->message == WM_CHAR))
1383 dlgCode = SendMessageA( msg->hwnd, WM_GETDLGCODE, 0, (LPARAM)msg);
1385 ret = DIALOG_IsDialogMessage( msg->hwnd, hwndDlg, msg->message,
1386 msg->wParam, msg->lParam,
1387 &translate, &dispatch, dlgCode );
1388 if (translate) TranslateMessage( msg );
1389 if (dispatch) DispatchMessageA( msg );
1390 return ret;
1394 /***********************************************************************
1395 * IsDialogMessage32W (USER32.343)
1397 BOOL WINAPI IsDialogMessageW( HWND hwndDlg, LPMSG msg )
1399 BOOL ret, translate, dispatch;
1400 INT dlgCode = 0;
1402 if ((hwndDlg != msg->hwnd) && !IsChild( hwndDlg, msg->hwnd ))
1403 return FALSE;
1405 if ((msg->message == WM_KEYDOWN) ||
1406 (msg->message == WM_SYSCHAR) ||
1407 (msg->message == WM_CHAR))
1409 dlgCode = SendMessageW( msg->hwnd, WM_GETDLGCODE, 0, (LPARAM)msg);
1411 ret = DIALOG_IsDialogMessage( msg->hwnd, hwndDlg, msg->message,
1412 msg->wParam, msg->lParam,
1413 &translate, &dispatch, dlgCode );
1414 if (translate) TranslateMessage( msg );
1415 if (dispatch) DispatchMessageW( msg );
1416 return ret;
1420 /****************************************************************
1421 * GetDlgCtrlID16 (USER.277)
1423 INT16 WINAPI GetDlgCtrlID16( HWND16 hwnd )
1425 WND *wndPtr = WIN_FindWndPtr(hwnd);
1426 INT16 retvalue;
1428 if (!wndPtr) return 0;
1430 retvalue = wndPtr->wIDmenu;
1431 WIN_ReleaseWndPtr(wndPtr);
1432 return retvalue;
1436 /****************************************************************
1437 * GetDlgCtrlID32 (USER32.234)
1439 INT WINAPI GetDlgCtrlID( HWND hwnd )
1441 INT retvalue;
1442 WND *wndPtr = WIN_FindWndPtr(hwnd);
1443 if (!wndPtr) return 0;
1444 retvalue = wndPtr->wIDmenu;
1445 WIN_ReleaseWndPtr(wndPtr);
1446 return retvalue;
1450 /***********************************************************************
1451 * GetDlgItem16 (USER.91)
1453 HWND16 WINAPI GetDlgItem16( HWND16 hwndDlg, INT16 id )
1455 WND *pWnd;
1457 if (!(pWnd = WIN_FindWndPtr( hwndDlg ))) return 0;
1458 for (WIN_UpdateWndPtr(&pWnd,pWnd->child); pWnd; WIN_UpdateWndPtr(&pWnd,pWnd->next))
1459 if (pWnd->wIDmenu == (UINT16)id)
1461 HWND16 retvalue = pWnd->hwndSelf;
1462 WIN_ReleaseWndPtr(pWnd);
1463 return retvalue;
1465 return 0;
1469 /***********************************************************************
1470 * GetDlgItem32 (USER32.235)
1472 HWND WINAPI GetDlgItem( HWND hwndDlg, INT id )
1474 WND *pWnd;
1476 if (!(pWnd = WIN_FindWndPtr( hwndDlg ))) return 0;
1477 for (WIN_UpdateWndPtr(&pWnd,pWnd->child); pWnd;WIN_UpdateWndPtr(&pWnd,pWnd->next))
1478 if (pWnd->wIDmenu == (UINT16)id)
1480 HWND retvalue = pWnd->hwndSelf;
1481 WIN_ReleaseWndPtr(pWnd);
1482 return retvalue;
1484 return 0;
1488 /*******************************************************************
1489 * SendDlgItemMessage16 (USER.101)
1491 LRESULT WINAPI SendDlgItemMessage16( HWND16 hwnd, INT16 id, UINT16 msg,
1492 WPARAM16 wParam, LPARAM lParam )
1494 HWND16 hwndCtrl = GetDlgItem16( hwnd, id );
1495 if (hwndCtrl) return SendMessage16( hwndCtrl, msg, wParam, lParam );
1496 else return 0;
1500 /*******************************************************************
1501 * SendDlgItemMessage32A (USER32.452)
1503 LRESULT WINAPI SendDlgItemMessageA( HWND hwnd, INT id, UINT msg,
1504 WPARAM wParam, LPARAM lParam )
1506 HWND hwndCtrl = GetDlgItem( hwnd, id );
1507 if (hwndCtrl) return SendMessageA( hwndCtrl, msg, wParam, lParam );
1508 else return 0;
1512 /*******************************************************************
1513 * SendDlgItemMessage32W (USER32.453)
1515 LRESULT WINAPI SendDlgItemMessageW( HWND hwnd, INT id, UINT msg,
1516 WPARAM wParam, LPARAM lParam )
1518 HWND hwndCtrl = GetDlgItem( hwnd, id );
1519 if (hwndCtrl) return SendMessageW( hwndCtrl, msg, wParam, lParam );
1520 else return 0;
1524 /*******************************************************************
1525 * SetDlgItemText16 (USER.92)
1527 void WINAPI SetDlgItemText16( HWND16 hwnd, INT16 id, SEGPTR lpString )
1529 SendDlgItemMessage16( hwnd, id, WM_SETTEXT, 0, (LPARAM)lpString );
1533 /*******************************************************************
1534 * SetDlgItemText32A (USER32.478)
1536 BOOL WINAPI SetDlgItemTextA( HWND hwnd, INT id, LPCSTR lpString )
1538 return SendDlgItemMessageA( hwnd, id, WM_SETTEXT, 0, (LPARAM)lpString );
1542 /*******************************************************************
1543 * SetDlgItemText32W (USER32.479)
1545 BOOL WINAPI SetDlgItemTextW( HWND hwnd, INT id, LPCWSTR lpString )
1547 return SendDlgItemMessageW( hwnd, id, WM_SETTEXT, 0, (LPARAM)lpString );
1551 /***********************************************************************
1552 * GetDlgItemText16 (USER.93)
1554 INT16 WINAPI GetDlgItemText16( HWND16 hwnd, INT16 id, SEGPTR str, UINT16 len )
1556 return (INT16)SendDlgItemMessage16( hwnd, id, WM_GETTEXT,
1557 len, (LPARAM)str );
1561 /***********************************************************************
1562 * GetDlgItemText32A (USER32.237)
1564 INT WINAPI GetDlgItemTextA( HWND hwnd, INT id, LPSTR str, UINT len )
1566 return (INT)SendDlgItemMessageA( hwnd, id, WM_GETTEXT,
1567 len, (LPARAM)str );
1571 /***********************************************************************
1572 * GetDlgItemText32W (USER32.238)
1574 INT WINAPI GetDlgItemTextW( HWND hwnd, INT id, LPWSTR str, UINT len )
1576 return (INT)SendDlgItemMessageW( hwnd, id, WM_GETTEXT,
1577 len, (LPARAM)str );
1581 /*******************************************************************
1582 * SetDlgItemInt16 (USER.94)
1584 void WINAPI SetDlgItemInt16( HWND16 hwnd, INT16 id, UINT16 value, BOOL16 fSigned )
1586 SetDlgItemInt( hwnd, (UINT)(UINT16)id, value, fSigned );
1590 /*******************************************************************
1591 * SetDlgItemInt32 (USER32.477)
1593 BOOL WINAPI SetDlgItemInt( HWND hwnd, INT id, UINT value,
1594 BOOL fSigned )
1596 char str[20];
1598 if (fSigned) sprintf( str, "%d", (INT)value );
1599 else sprintf( str, "%u", value );
1600 SendDlgItemMessageA( hwnd, id, WM_SETTEXT, 0, (LPARAM)str );
1601 return TRUE;
1605 /***********************************************************************
1606 * GetDlgItemInt16 (USER.95)
1608 UINT16 WINAPI GetDlgItemInt16( HWND16 hwnd, INT16 id, BOOL16 *translated,
1609 BOOL16 fSigned )
1611 UINT result;
1612 BOOL ok;
1614 if (translated) *translated = FALSE;
1615 result = GetDlgItemInt( hwnd, (UINT)(UINT16)id, &ok, fSigned );
1616 if (!ok) return 0;
1617 if (fSigned)
1619 if (((INT)result < -32767) || ((INT)result > 32767)) return 0;
1621 else
1623 if (result > 65535) return 0;
1625 if (translated) *translated = TRUE;
1626 return (UINT16)result;
1630 /***********************************************************************
1631 * GetDlgItemInt32 (USER32.236)
1633 UINT WINAPI GetDlgItemInt( HWND hwnd, INT id, BOOL *translated,
1634 BOOL fSigned )
1636 char str[30];
1637 char * endptr;
1638 long result = 0;
1640 if (translated) *translated = FALSE;
1641 if (!SendDlgItemMessageA(hwnd, id, WM_GETTEXT, sizeof(str), (LPARAM)str))
1642 return 0;
1643 if (fSigned)
1645 result = strtol( str, &endptr, 10 );
1646 if (!endptr || (endptr == str)) /* Conversion was unsuccessful */
1647 return 0;
1648 if (((result == LONG_MIN) || (result == LONG_MAX)) && (errno==ERANGE))
1649 return 0;
1651 else
1653 result = strtoul( str, &endptr, 10 );
1654 if (!endptr || (endptr == str)) /* Conversion was unsuccessful */
1655 return 0;
1656 if ((result == ULONG_MAX) && (errno == ERANGE)) return 0;
1658 if (translated) *translated = TRUE;
1659 return (UINT)result;
1663 /***********************************************************************
1664 * CheckDlgButton16 (USER.97)
1666 BOOL16 WINAPI CheckDlgButton16( HWND16 hwnd, INT16 id, UINT16 check )
1668 SendDlgItemMessageA( hwnd, id, BM_SETCHECK, check, 0 );
1669 return TRUE;
1673 /***********************************************************************
1674 * CheckDlgButton32 (USER32.45)
1676 BOOL WINAPI CheckDlgButton( HWND hwnd, INT id, UINT check )
1678 SendDlgItemMessageA( hwnd, id, BM_SETCHECK, check, 0 );
1679 return TRUE;
1683 /***********************************************************************
1684 * IsDlgButtonChecked16 (USER.98)
1686 UINT16 WINAPI IsDlgButtonChecked16( HWND16 hwnd, UINT16 id )
1688 return (UINT16)SendDlgItemMessageA( hwnd, id, BM_GETCHECK, 0, 0 );
1692 /***********************************************************************
1693 * IsDlgButtonChecked32 (USER32.344)
1695 UINT WINAPI IsDlgButtonChecked( HWND hwnd, UINT id )
1697 return (UINT)SendDlgItemMessageA( hwnd, id, BM_GETCHECK, 0, 0 );
1701 /***********************************************************************
1702 * CheckRadioButton16 (USER.96)
1704 BOOL16 WINAPI CheckRadioButton16( HWND16 hwndDlg, UINT16 firstID,
1705 UINT16 lastID, UINT16 checkID )
1707 return CheckRadioButton( hwndDlg, firstID, lastID, checkID );
1711 /***********************************************************************
1712 * CheckRB
1714 * Callback function used to check/uncheck radio buttons that fall
1715 * within a specific range of IDs.
1717 static BOOL CALLBACK CheckRB(HWND hwndChild, LPARAM lParam)
1719 LONG lChildID = GetWindowLongA(hwndChild, GWL_ID);
1720 RADIOGROUP *lpRadioGroup = (RADIOGROUP *) lParam;
1722 if ((lChildID >= lpRadioGroup->firstID) &&
1723 (lChildID <= lpRadioGroup->lastID))
1725 if (lChildID == lpRadioGroup->checkID)
1727 SendMessageA(hwndChild, BM_SETCHECK, BST_CHECKED, 0);
1729 else
1731 SendMessageA(hwndChild, BM_SETCHECK, BST_UNCHECKED, 0);
1735 return TRUE;
1739 /***********************************************************************
1740 * CheckRadioButton32 (USER32.48)
1742 BOOL WINAPI CheckRadioButton( HWND hwndDlg, UINT firstID,
1743 UINT lastID, UINT checkID )
1745 RADIOGROUP radioGroup;
1747 /* perform bounds checking for a radio button group */
1748 radioGroup.firstID = min(min(firstID, lastID), checkID);
1749 radioGroup.lastID = max(max(firstID, lastID), checkID);
1750 radioGroup.checkID = checkID;
1752 return EnumChildWindows(hwndDlg, (WNDENUMPROC)CheckRB,
1753 (LPARAM)&radioGroup);
1757 /***********************************************************************
1758 * GetDialogBaseUnits (USER.243) (USER32.233)
1760 DWORD WINAPI GetDialogBaseUnits(void)
1762 return MAKELONG( xBaseUnit, yBaseUnit );
1766 /***********************************************************************
1767 * MapDialogRect16 (USER.103)
1769 void WINAPI MapDialogRect16( HWND16 hwnd, LPRECT16 rect )
1771 DIALOGINFO * dlgInfo;
1772 WND * wndPtr = WIN_FindWndPtr( hwnd );
1773 if (!wndPtr) return;
1774 dlgInfo = (DIALOGINFO *)wndPtr->wExtra;
1775 rect->left = MulDiv(rect->left, dlgInfo->xBaseUnit, 4);
1776 rect->right = MulDiv(rect->right, dlgInfo->xBaseUnit, 4);
1777 rect->top = MulDiv(rect->top, dlgInfo->yBaseUnit, 8);
1778 rect->bottom = MulDiv(rect->bottom, dlgInfo->yBaseUnit, 8);
1779 WIN_ReleaseWndPtr(wndPtr);
1783 /***********************************************************************
1784 * MapDialogRect32 (USER32.382)
1786 BOOL WINAPI MapDialogRect( HWND hwnd, LPRECT rect )
1788 DIALOGINFO * dlgInfo;
1789 WND * wndPtr = WIN_FindWndPtr( hwnd );
1790 if (!wndPtr) return FALSE;
1791 dlgInfo = (DIALOGINFO *)wndPtr->wExtra;
1792 rect->left = MulDiv(rect->left, dlgInfo->xBaseUnit, 4);
1793 rect->right = MulDiv(rect->right, dlgInfo->xBaseUnit, 4);
1794 rect->top = MulDiv(rect->top, dlgInfo->yBaseUnit, 8);
1795 rect->bottom = MulDiv(rect->bottom, dlgInfo->yBaseUnit, 8);
1796 WIN_ReleaseWndPtr(wndPtr);
1797 return TRUE;
1801 /***********************************************************************
1802 * GetNextDlgGroupItem16 (USER.227)
1804 HWND16 WINAPI GetNextDlgGroupItem16( HWND16 hwndDlg, HWND16 hwndCtrl,
1805 BOOL16 fPrevious )
1807 return (HWND16)GetNextDlgGroupItem( hwndDlg, hwndCtrl, fPrevious );
1811 /***********************************************************************
1812 * GetNextDlgGroupItem32 (USER32.275)
1814 HWND WINAPI GetNextDlgGroupItem( HWND hwndDlg, HWND hwndCtrl,
1815 BOOL fPrevious )
1817 WND *pWnd = NULL,
1818 *pWndLast = NULL,
1819 *pWndCtrl = NULL,
1820 *pWndDlg = NULL;
1821 HWND retvalue;
1823 if (!(pWndDlg = WIN_FindWndPtr( hwndDlg ))) return 0;
1824 if (hwndCtrl)
1826 if (!(pWndCtrl = WIN_FindWndPtr( hwndCtrl )))
1828 retvalue = 0;
1829 goto END;
1831 /* Make sure hwndCtrl is a top-level child */
1832 while ((pWndCtrl->dwStyle & WS_CHILD) && (pWndCtrl->parent != pWndDlg))
1833 WIN_UpdateWndPtr(&pWndCtrl,pWndCtrl->parent);
1834 if (pWndCtrl->parent != pWndDlg)
1836 retvalue = 0;
1837 goto END;
1840 else
1842 /* No ctrl specified -> start from the beginning */
1843 if (!(pWndCtrl = WIN_LockWndPtr(pWndDlg->child)))
1845 retvalue = 0;
1846 goto END;
1848 if (fPrevious)
1849 while (pWndCtrl->next) WIN_UpdateWndPtr(&pWndCtrl,pWndCtrl->next);
1852 pWndLast = WIN_LockWndPtr(pWndCtrl);
1853 pWnd = WIN_LockWndPtr(pWndCtrl->next);
1855 while (1)
1857 if (!pWnd || (pWnd->dwStyle & WS_GROUP))
1859 /* Wrap-around to the beginning of the group */
1860 WND *pWndTemp;
1862 WIN_UpdateWndPtr( &pWnd, pWndDlg->child );
1863 for ( pWndTemp = WIN_LockWndPtr( pWnd );
1864 pWndTemp;
1865 WIN_UpdateWndPtr( &pWndTemp, pWndTemp->next) )
1867 if (pWndTemp->dwStyle & WS_GROUP) WIN_UpdateWndPtr( &pWnd, pWndTemp );
1868 if (pWndTemp == pWndCtrl) break;
1870 WIN_ReleaseWndPtr( pWndTemp );
1872 if (pWnd == pWndCtrl) break;
1873 if ((pWnd->dwStyle & WS_VISIBLE) && !(pWnd->dwStyle & WS_DISABLED))
1875 WIN_UpdateWndPtr(&pWndLast,pWnd);
1876 if (!fPrevious) break;
1878 WIN_UpdateWndPtr(&pWnd,pWnd->next);
1880 retvalue = pWndLast->hwndSelf;
1882 WIN_ReleaseWndPtr(pWndLast);
1883 WIN_ReleaseWndPtr(pWnd);
1884 END:
1885 WIN_ReleaseWndPtr(pWndCtrl);
1886 WIN_ReleaseWndPtr(pWndDlg);
1888 return retvalue;
1892 /***********************************************************************
1893 * GetNextDlgTabItem16 (USER.228)
1895 HWND16 WINAPI GetNextDlgTabItem16( HWND16 hwndDlg, HWND16 hwndCtrl,
1896 BOOL16 fPrevious )
1898 return (HWND16)GetNextDlgTabItem( hwndDlg, hwndCtrl, fPrevious );
1901 /***********************************************************************
1902 * DIALOG_GetNextTabItem
1904 * Helper for GetNextDlgTabItem
1906 static HWND DIALOG_GetNextTabItem( HWND hwndMain, HWND hwndDlg, HWND hwndCtrl, BOOL fPrevious )
1908 LONG dsStyle;
1909 LONG exStyle;
1910 UINT wndSearch = fPrevious ? GW_HWNDPREV : GW_HWNDNEXT;
1911 HWND retWnd = 0;
1912 HWND hChildFirst = 0;
1914 if(!hwndCtrl)
1916 hChildFirst = GetWindow(hwndDlg,GW_CHILD);
1917 if(fPrevious) hChildFirst = GetWindow(hChildFirst,GW_HWNDLAST);
1919 else
1921 HWND hParent = GetParent(hwndCtrl);
1922 BOOL bValid = FALSE;
1923 while( hParent)
1925 if(hParent == hwndMain)
1927 bValid = TRUE;
1928 break;
1930 hParent = GetParent(hParent);
1932 if(bValid)
1934 hChildFirst = GetWindow(hwndCtrl,wndSearch);
1935 if(!hChildFirst)
1937 if(GetParent(hwndCtrl) != hwndMain)
1938 hChildFirst = GetWindow(GetParent(hwndCtrl),wndSearch);
1939 else
1941 if(fPrevious)
1942 hChildFirst = GetWindow(hwndCtrl,GW_HWNDLAST);
1943 else
1944 hChildFirst = GetWindow(hwndCtrl,GW_HWNDFIRST);
1949 while(hChildFirst)
1951 BOOL bCtrl = FALSE;
1952 while(hChildFirst)
1954 dsStyle = GetWindowLongA(hChildFirst,GWL_STYLE);
1955 exStyle = GetWindowLongA(hChildFirst,GWL_EXSTYLE);
1956 if(dsStyle & DS_CONTROL || exStyle & WS_EX_CONTROLPARENT)
1958 bCtrl=TRUE;
1959 break;
1961 else if( (dsStyle & WS_TABSTOP) && (dsStyle & WS_VISIBLE) && !(dsStyle & WS_DISABLED))
1962 break;
1963 hChildFirst = GetWindow(hChildFirst,wndSearch);
1965 if(hChildFirst)
1967 if(bCtrl)
1968 retWnd = DIALOG_GetNextTabItem(hwndMain,hChildFirst,(HWND)NULL,fPrevious );
1969 else
1970 retWnd = hChildFirst;
1972 if(retWnd) break;
1973 hChildFirst = GetWindow(hChildFirst,wndSearch);
1975 if(!retWnd && hwndCtrl)
1977 HWND hParent = GetParent(hwndCtrl);
1978 while(hParent)
1980 if(hParent == hwndMain) break;
1981 retWnd = DIALOG_GetNextTabItem(hwndMain,GetParent(hParent),hParent,fPrevious );
1982 if(retWnd) break;
1983 hParent = GetParent(hParent);
1985 if(!retWnd)
1986 retWnd = DIALOG_GetNextTabItem(hwndMain,hwndMain,(HWND)NULL,fPrevious );
1988 return retWnd;
1991 /***********************************************************************
1992 * GetNextDlgTabItem32 (USER32.276)
1994 HWND WINAPI GetNextDlgTabItem( HWND hwndDlg, HWND hwndCtrl,
1995 BOOL fPrevious )
1997 return DIALOG_GetNextTabItem(hwndDlg,hwndDlg,hwndCtrl,fPrevious);
2000 /**********************************************************************
2001 * DIALOG_DlgDirSelect
2003 * Helper function for DlgDirSelect*
2005 static BOOL DIALOG_DlgDirSelect( HWND hwnd, LPSTR str, INT len,
2006 INT id, BOOL win32, BOOL unicode,
2007 BOOL combo )
2009 char *buffer, *ptr;
2010 INT item, size;
2011 BOOL ret;
2012 HWND listbox = GetDlgItem( hwnd, id );
2014 TRACE("%04x '%s' %d\n", hwnd, str, id );
2015 if (!listbox) return FALSE;
2016 if (win32)
2018 item = SendMessageA(listbox, combo ? CB_GETCURSEL
2019 : LB_GETCURSEL, 0, 0 );
2020 if (item == LB_ERR) return FALSE;
2021 size = SendMessageA(listbox, combo ? CB_GETLBTEXTLEN
2022 : LB_GETTEXTLEN, 0, 0 );
2023 if (size == LB_ERR) return FALSE;
2025 else
2027 item = SendMessageA(listbox, combo ? CB_GETCURSEL16
2028 : LB_GETCURSEL16, 0, 0 );
2029 if (item == LB_ERR) return FALSE;
2030 size = SendMessageA(listbox, combo ? CB_GETLBTEXTLEN16
2031 : LB_GETTEXTLEN16, 0, 0 );
2032 if (size == LB_ERR) return FALSE;
2035 if (!(buffer = SEGPTR_ALLOC( size+1 ))) return FALSE;
2037 if (win32)
2038 SendMessageA( listbox, combo ? CB_GETLBTEXT : LB_GETTEXT,
2039 item, (LPARAM)buffer );
2040 else
2041 SendMessage16( listbox, combo ? CB_GETLBTEXT16 : LB_GETTEXT16,
2042 item, (LPARAM)SEGPTR_GET(buffer) );
2044 if ((ret = (buffer[0] == '['))) /* drive or directory */
2046 if (buffer[1] == '-') /* drive */
2048 buffer[3] = ':';
2049 buffer[4] = 0;
2050 ptr = buffer + 2;
2052 else
2054 buffer[strlen(buffer)-1] = '\\';
2055 ptr = buffer + 1;
2058 else ptr = buffer;
2060 if (unicode) lstrcpynAtoW( (LPWSTR)str, ptr, len );
2061 else lstrcpynA( str, ptr, len );
2062 SEGPTR_FREE( buffer );
2063 TRACE("Returning %d '%s'\n", ret, str );
2064 return ret;
2068 /**********************************************************************
2069 * DIALOG_DlgDirList
2071 * Helper function for DlgDirList*
2073 static INT DIALOG_DlgDirList( HWND hDlg, LPSTR spec, INT idLBox,
2074 INT idStatic, UINT attrib, BOOL combo )
2076 int drive;
2077 HWND hwnd;
2078 LPSTR orig_spec = spec;
2080 #define SENDMSG(msg,wparam,lparam) \
2081 ((attrib & DDL_POSTMSGS) ? PostMessageA( hwnd, msg, wparam, lparam ) \
2082 : SendMessageA( hwnd, msg, wparam, lparam ))
2084 TRACE("%04x '%s' %d %d %04x\n",
2085 hDlg, spec ? spec : "NULL", idLBox, idStatic, attrib );
2087 if (spec && spec[0] && (spec[1] == ':'))
2089 drive = toupper( spec[0] ) - 'A';
2090 spec += 2;
2091 if (!DRIVE_SetCurrentDrive( drive )) return FALSE;
2093 else drive = DRIVE_GetCurrentDrive();
2095 /* If the path exists and is a directory, chdir to it */
2096 if (!spec || !spec[0] || DRIVE_Chdir( drive, spec )) spec = "*.*";
2097 else
2099 char *p, *p2;
2100 p = spec;
2101 if ((p2 = strrchr( p, '\\' ))) p = p2;
2102 if ((p2 = strrchr( p, '/' ))) p = p2;
2103 if (p != spec)
2105 char sep = *p;
2106 *p = 0;
2107 if (!DRIVE_Chdir( drive, spec ))
2109 *p = sep; /* Restore the original spec */
2110 return FALSE;
2112 spec = p + 1;
2116 TRACE("path=%c:\\%s mask=%s\n",
2117 'A' + drive, DRIVE_GetDosCwd(drive), spec );
2119 if (idLBox && ((hwnd = GetDlgItem( hDlg, idLBox )) != 0))
2121 SENDMSG( combo ? CB_RESETCONTENT : LB_RESETCONTENT, 0, 0 );
2122 if (attrib & DDL_DIRECTORY)
2124 if (!(attrib & DDL_EXCLUSIVE))
2126 if (SENDMSG( combo ? CB_DIR : LB_DIR,
2127 attrib & ~(DDL_DIRECTORY | DDL_DRIVES),
2128 (LPARAM)spec ) == LB_ERR)
2129 return FALSE;
2131 if (SENDMSG( combo ? CB_DIR : LB_DIR,
2132 (attrib & (DDL_DIRECTORY | DDL_DRIVES)) | DDL_EXCLUSIVE,
2133 (LPARAM)"*.*" ) == LB_ERR)
2134 return FALSE;
2136 else
2138 if (SENDMSG( combo ? CB_DIR : LB_DIR, attrib,
2139 (LPARAM)spec ) == LB_ERR)
2140 return FALSE;
2144 if (idStatic && ((hwnd = GetDlgItem( hDlg, idStatic )) != 0))
2146 char temp[512];
2147 int drive = DRIVE_GetCurrentDrive();
2148 strcpy( temp, "A:\\" );
2149 temp[0] += drive;
2150 lstrcpynA( temp + 3, DRIVE_GetDosCwd(drive), sizeof(temp)-3 );
2151 CharLowerA( temp );
2152 /* Can't use PostMessage() here, because the string is on the stack */
2153 SetDlgItemTextA( hDlg, idStatic, temp );
2156 if (orig_spec && (spec != orig_spec))
2158 /* Update the original file spec */
2159 char *p = spec;
2160 while ((*orig_spec++ = *p++));
2163 return TRUE;
2164 #undef SENDMSG
2168 /**********************************************************************
2169 * DIALOG_DlgDirListW
2171 * Helper function for DlgDirList*32W
2173 static INT DIALOG_DlgDirListW( HWND hDlg, LPWSTR spec, INT idLBox,
2174 INT idStatic, UINT attrib, BOOL combo )
2176 if (spec)
2178 LPSTR specA = HEAP_strdupWtoA( GetProcessHeap(), 0, spec );
2179 INT ret = DIALOG_DlgDirList( hDlg, specA, idLBox, idStatic,
2180 attrib, combo );
2181 lstrcpyAtoW( spec, specA );
2182 HeapFree( GetProcessHeap(), 0, specA );
2183 return ret;
2185 return DIALOG_DlgDirList( hDlg, NULL, idLBox, idStatic, attrib, combo );
2189 /**********************************************************************
2190 * DlgDirSelect (USER.99)
2192 BOOL16 WINAPI DlgDirSelect16( HWND16 hwnd, LPSTR str, INT16 id )
2194 return DlgDirSelectEx16( hwnd, str, 128, id );
2198 /**********************************************************************
2199 * DlgDirSelectComboBox (USER.194)
2201 BOOL16 WINAPI DlgDirSelectComboBox16( HWND16 hwnd, LPSTR str, INT16 id )
2203 return DlgDirSelectComboBoxEx16( hwnd, str, 128, id );
2207 /**********************************************************************
2208 * DlgDirSelectEx16 (USER.422)
2210 BOOL16 WINAPI DlgDirSelectEx16( HWND16 hwnd, LPSTR str, INT16 len, INT16 id )
2212 return DIALOG_DlgDirSelect( hwnd, str, len, id, FALSE, FALSE, FALSE );
2216 /**********************************************************************
2217 * DlgDirSelectEx32A (USER32.149)
2219 BOOL WINAPI DlgDirSelectExA( HWND hwnd, LPSTR str, INT len, INT id )
2221 return DIALOG_DlgDirSelect( hwnd, str, len, id, TRUE, FALSE, FALSE );
2225 /**********************************************************************
2226 * DlgDirSelectEx32W (USER32.150)
2228 BOOL WINAPI DlgDirSelectExW( HWND hwnd, LPWSTR str, INT len, INT id )
2230 return DIALOG_DlgDirSelect( hwnd, (LPSTR)str, len, id, TRUE, TRUE, FALSE );
2234 /**********************************************************************
2235 * DlgDirSelectComboBoxEx16 (USER.423)
2237 BOOL16 WINAPI DlgDirSelectComboBoxEx16( HWND16 hwnd, LPSTR str, INT16 len,
2238 INT16 id )
2240 return DIALOG_DlgDirSelect( hwnd, str, len, id, FALSE, FALSE, TRUE );
2244 /**********************************************************************
2245 * DlgDirSelectComboBoxEx32A (USER32.147)
2247 BOOL WINAPI DlgDirSelectComboBoxExA( HWND hwnd, LPSTR str, INT len,
2248 INT id )
2250 return DIALOG_DlgDirSelect( hwnd, str, len, id, TRUE, FALSE, TRUE );
2254 /**********************************************************************
2255 * DlgDirSelectComboBoxEx32W (USER32.148)
2257 BOOL WINAPI DlgDirSelectComboBoxExW( HWND hwnd, LPWSTR str, INT len,
2258 INT id)
2260 return DIALOG_DlgDirSelect( hwnd, (LPSTR)str, len, id, TRUE, TRUE, TRUE );
2264 /**********************************************************************
2265 * DlgDirList16 (USER.100)
2267 INT16 WINAPI DlgDirList16( HWND16 hDlg, LPSTR spec, INT16 idLBox,
2268 INT16 idStatic, UINT16 attrib )
2270 return DIALOG_DlgDirList( hDlg, spec, idLBox, idStatic, attrib, FALSE );
2274 /**********************************************************************
2275 * DlgDirList32A (USER32.143)
2277 INT WINAPI DlgDirListA( HWND hDlg, LPSTR spec, INT idLBox,
2278 INT idStatic, UINT attrib )
2280 return DIALOG_DlgDirList( hDlg, spec, idLBox, idStatic, attrib, FALSE );
2284 /**********************************************************************
2285 * DlgDirList32W (USER32.146)
2287 INT WINAPI DlgDirListW( HWND hDlg, LPWSTR spec, INT idLBox,
2288 INT idStatic, UINT attrib )
2290 return DIALOG_DlgDirListW( hDlg, spec, idLBox, idStatic, attrib, FALSE );
2294 /**********************************************************************
2295 * DlgDirListComboBox16 (USER.195)
2297 INT16 WINAPI DlgDirListComboBox16( HWND16 hDlg, LPSTR spec, INT16 idCBox,
2298 INT16 idStatic, UINT16 attrib )
2300 return DIALOG_DlgDirList( hDlg, spec, idCBox, idStatic, attrib, TRUE );
2304 /**********************************************************************
2305 * DlgDirListComboBox32A (USER32.144)
2307 INT WINAPI DlgDirListComboBoxA( HWND hDlg, LPSTR spec, INT idCBox,
2308 INT idStatic, UINT attrib )
2310 return DIALOG_DlgDirList( hDlg, spec, idCBox, idStatic, attrib, TRUE );
2314 /**********************************************************************
2315 * DlgDirListComboBox32W (USER32.145)
2317 INT WINAPI DlgDirListComboBoxW( HWND hDlg, LPWSTR spec, INT idCBox,
2318 INT idStatic, UINT attrib )
2320 return DIALOG_DlgDirListW( hDlg, spec, idCBox, idStatic, attrib, TRUE );