Release 970509
[wine/multimedia.git] / windows / dialog.c
blobf59cbd9d2629c07765755685a320c6d0838ac3ed
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 <errno.h>
14 #include "windows.h"
15 #include "dialog.h"
16 #include "drive.h"
17 #include "heap.h"
18 #include "win.h"
19 #include "ldt.h"
20 #include "user.h"
21 #include "winproc.h"
22 #include "message.h"
23 #include "sysmetrics.h"
24 #include "stddebug.h"
25 #include "debug.h"
28 /* Dialog control information */
29 typedef struct
31 DWORD style;
32 DWORD exStyle;
33 INT16 x;
34 INT16 y;
35 INT16 cx;
36 INT16 cy;
37 UINT16 id;
38 LPCSTR className;
39 LPCSTR windowName;
40 LPVOID data;
41 } DLG_CONTROL_INFO;
43 /* Dialog template */
44 typedef struct
46 DWORD style;
47 DWORD exStyle;
48 UINT16 nbItems;
49 INT16 x;
50 INT16 y;
51 INT16 cx;
52 INT16 cy;
53 LPCSTR menuName;
54 LPCSTR className;
55 LPCSTR caption;
56 WORD pointSize;
57 LPCSTR faceName;
58 } DLG_TEMPLATE;
60 /* Dialog base units */
61 static WORD xBaseUnit = 0, yBaseUnit = 0;
64 /***********************************************************************
65 * DIALOG_Init
67 * Initialisation of the dialog manager.
69 BOOL32 DIALOG_Init()
71 TEXTMETRIC16 tm;
72 HDC16 hdc;
74 /* Calculate the dialog base units */
76 if (!(hdc = CreateDC16( "DISPLAY", NULL, NULL, NULL ))) return FALSE;
77 GetTextMetrics16( hdc, &tm );
78 DeleteDC32( hdc );
79 xBaseUnit = tm.tmAveCharWidth;
80 yBaseUnit = tm.tmHeight;
82 /* Dialog units are based on a proportional system font */
83 /* so we adjust them a bit for a fixed font. */
84 if (!(tm.tmPitchAndFamily & TMPF_FIXED_PITCH))
85 xBaseUnit = xBaseUnit * 5 / 4;
87 dprintf_dialog( stddeb, "DIALOG_Init: base units = %d,%d\n",
88 xBaseUnit, yBaseUnit );
89 return TRUE;
93 /***********************************************************************
94 * DIALOG_GetControl16
96 * Return the class and text of the control pointed to by ptr,
97 * fill the header structure and return a pointer to the next control.
99 static LPCSTR DIALOG_GetControl16( LPCSTR p, DLG_CONTROL_INFO *info )
101 static char buffer[10];
103 info->x = GET_WORD(p); p += sizeof(WORD);
104 info->y = GET_WORD(p); p += sizeof(WORD);
105 info->cx = GET_WORD(p); p += sizeof(WORD);
106 info->cy = GET_WORD(p); p += sizeof(WORD);
107 info->id = GET_WORD(p); p += sizeof(WORD);
108 info->style = GET_DWORD(p); p += sizeof(DWORD);
109 info->exStyle = 0;
111 if (*p & 0x80)
113 switch((BYTE)*p)
115 case 0x80: strcpy( buffer, "BUTTON" ); break;
116 case 0x81: strcpy( buffer, "EDIT" ); break;
117 case 0x82: strcpy( buffer, "STATIC" ); break;
118 case 0x83: strcpy( buffer, "LISTBOX" ); break;
119 case 0x84: strcpy( buffer, "SCROLLBAR" ); break;
120 case 0x85: strcpy( buffer, "COMBOBOX" ); break;
121 default: buffer[0] = '\0'; break;
123 info->className = buffer;
124 p++;
126 else
128 info->className = p;
129 p += strlen(p) + 1;
131 dprintf_dialog(stddeb, " %s ", info->className );
133 if ((BYTE)*p == 0xff)
135 /* Integer id, not documented (?). Only works for SS_ICON controls */
136 info->windowName = (LPCSTR)(UINT32)GET_WORD(p+1);
137 p += 3;
138 dprintf_dialog( stddeb,"%04x", LOWORD(info->windowName) );
140 else
142 info->windowName = p;
143 p += strlen(p) + 1;
144 dprintf_dialog(stddeb,"'%s'", info->windowName );
147 info->data = (LPVOID)(*p ? p + 1 : NULL); /* FIXME: should be a segptr */
148 p += *p + 1;
150 dprintf_dialog( stddeb," %d, %d, %d, %d, %d, %08lx, %08lx\n",
151 info->id, info->x, info->y, info->cx, info->cy,
152 info->style, (DWORD)info->data);
153 return p;
157 /***********************************************************************
158 * DIALOG_GetControl32
160 * Return the class and text of the control pointed to by ptr,
161 * fill the header structure and return a pointer to the next control.
163 static const WORD *DIALOG_GetControl32( const WORD *p, DLG_CONTROL_INFO *info )
165 static WCHAR buffer[10];
167 info->style = GET_DWORD(p); p += 2;
168 info->exStyle = GET_DWORD(p); p += 2;
169 info->x = GET_WORD(p); p++;
170 info->y = GET_WORD(p); p++;
171 info->cx = GET_WORD(p); p++;
172 info->cy = GET_WORD(p); p++;
173 info->id = GET_WORD(p); p++;
175 if (GET_WORD(p) == 0xffff)
177 switch(GET_WORD(p+1))
179 case 0x80: lstrcpyAtoW( buffer, "Button" ); break;
180 case 0x81: lstrcpyAtoW( buffer, "Edit" ); break;
181 case 0x82: lstrcpyAtoW( buffer, "Static" ); break;
182 case 0x83: lstrcpyAtoW( buffer, "ListBox" ); break;
183 case 0x84: lstrcpyAtoW( buffer, "ScrollBar" ); break;
184 case 0x85: lstrcpyAtoW( buffer, "ComboBox" ); break;
185 default: buffer[0] = '\0'; break;
187 info->className = (LPCSTR)buffer;
188 p += 2;
190 else
192 info->className = (LPCSTR)p;
193 p += lstrlen32W( (LPCWSTR)p ) + 1;
195 dprintf_dialog(stddeb, " %p ", info->className );
197 if (GET_WORD(p) == 0xffff)
199 info->windowName = (LPCSTR)(p + 1);
200 p += 2;
201 dprintf_dialog( stddeb,"%04x", LOWORD(info->windowName) );
203 else
205 info->windowName = (LPCSTR)p;
206 p += lstrlen32W( (LPCWSTR)p ) + 1;
207 dprintf_dialog(stddeb,"'%p'", info->windowName );
210 if (GET_WORD(p))
212 info->data = (LPVOID)(p + 1);
213 p += GET_WORD(p) / sizeof(WORD);
215 else info->data = NULL;
216 p++;
218 dprintf_dialog( stddeb," %d, %d, %d, %d, %d, %08lx, %08lx, %08lx\n",
219 info->id, info->x, info->y, info->cx, info->cy,
220 info->style, info->exStyle, (DWORD)info->data);
221 /* Next control is on dword boundary */
222 return (const WORD *)((((int)p) + 3) & ~3);
226 /***********************************************************************
227 * DIALOG_CreateControls
229 * Create the control windows for a dialog.
231 static BOOL32 DIALOG_CreateControls( WND *pWnd, LPCSTR template, INT32 items,
232 HINSTANCE32 hInst, BOOL32 win32 )
234 DIALOGINFO *dlgInfo = (DIALOGINFO *)pWnd->wExtra;
235 DLG_CONTROL_INFO info;
236 HWND32 hwndCtrl, hwndDefButton = 0;
238 dprintf_dialog(stddeb, " BEGIN\n" );
239 while (items--)
241 if (!win32)
243 HINSTANCE16 instance;
244 template = DIALOG_GetControl16( template, &info );
245 if (HIWORD(info.className) && !strcmp( info.className, "EDIT") &&
246 ((pWnd->dwStyle & DS_LOCALEDIT) != DS_LOCALEDIT))
248 if (!dlgInfo->hDialogHeap)
250 dlgInfo->hDialogHeap = GlobalAlloc16(GMEM_FIXED, 0x10000);
251 if (!dlgInfo->hDialogHeap)
253 fprintf( stderr, "CreateDialogIndirectParam: Insufficient memory to create heap for edit control\n" );
254 continue;
256 LocalInit(dlgInfo->hDialogHeap, 0, 0xffff);
258 instance = dlgInfo->hDialogHeap;
260 else instance = (HINSTANCE16)hInst;
262 hwndCtrl = CreateWindowEx16( info.exStyle | WS_EX_NOPARENTNOTIFY,
263 info.className, info.windowName,
264 info.style | WS_CHILD,
265 info.x * dlgInfo->xBaseUnit / 4,
266 info.y * dlgInfo->yBaseUnit / 8,
267 info.cx * dlgInfo->xBaseUnit / 4,
268 info.cy * dlgInfo->yBaseUnit / 8,
269 pWnd->hwndSelf, (HMENU16)info.id,
270 instance, info.data );
272 else
274 template = (LPCSTR)DIALOG_GetControl32( (WORD *)template, &info );
275 hwndCtrl = CreateWindowEx32W( info.exStyle | WS_EX_NOPARENTNOTIFY,
276 (LPCWSTR)info.className,
277 (LPCWSTR)info.windowName,
278 info.style | WS_CHILD,
279 info.x * dlgInfo->xBaseUnit / 4,
280 info.y * dlgInfo->yBaseUnit / 8,
281 info.cx * dlgInfo->xBaseUnit / 4,
282 info.cy * dlgInfo->yBaseUnit / 8,
283 pWnd->hwndSelf, (HMENU32)info.id,
284 hInst, info.data );
286 if (!hwndCtrl) return FALSE;
288 /* Send initialisation messages to the control */
289 if (dlgInfo->hUserFont) SendMessage32A( hwndCtrl, WM_SETFONT,
290 (WPARAM32)dlgInfo->hUserFont, 0 );
291 if (SendMessage32A(hwndCtrl, WM_GETDLGCODE, 0, 0) & DLGC_DEFPUSHBUTTON)
293 /* If there's already a default push-button, set it back */
294 /* to normal and use this one instead. */
295 if (hwndDefButton)
296 SendMessage32A( hwndDefButton, BM_SETSTYLE32,
297 BS_PUSHBUTTON,FALSE );
298 hwndDefButton = hwndCtrl;
299 dlgInfo->idResult = GetWindowWord32( hwndCtrl, GWW_ID );
302 dprintf_dialog(stddeb, " END\n" );
303 return TRUE;
307 /***********************************************************************
308 * DIALOG_ParseTemplate16
310 * Fill a DLG_TEMPLATE structure from the dialog template, and return
311 * a pointer to the first control.
313 static LPCSTR DIALOG_ParseTemplate16( LPCSTR p, DLG_TEMPLATE * result )
315 result->style = GET_DWORD(p); p += sizeof(DWORD);
316 result->exStyle = 0;
317 result->nbItems = *p++;
318 result->x = GET_WORD(p); p += sizeof(WORD);
319 result->y = GET_WORD(p); p += sizeof(WORD);
320 result->cx = GET_WORD(p); p += sizeof(WORD);
321 result->cy = GET_WORD(p); p += sizeof(WORD);
322 dprintf_dialog( stddeb, "DIALOG %d, %d, %d, %d\n",
323 result->x, result->y, result->cx, result->cy );
324 dprintf_dialog( stddeb, " STYLE %08lx\n", result->style );
326 /* Get the menu name */
328 switch( (BYTE)*p )
330 case 0:
331 result->menuName = 0;
332 p++;
333 break;
334 case 0xff:
335 result->menuName = (LPCSTR)(UINT32)GET_WORD( p + 1 );
336 p += 3;
337 dprintf_dialog(stddeb, " MENU %04x\n", LOWORD(result->menuName) );
338 break;
339 default:
340 result->menuName = p;
341 dprintf_dialog( stddeb, " MENU '%s'\n", p );
342 p += strlen(p) + 1;
343 break;
346 /* Get the class name */
348 if (*p)
350 result->className = p;
351 dprintf_dialog( stddeb, " CLASS '%s'\n", result->className );
353 else result->className = DIALOG_CLASS_ATOM;
354 p += strlen(p) + 1;
356 /* Get the window caption */
358 result->caption = p;
359 p += strlen(p) + 1;
360 dprintf_dialog( stddeb, " CAPTION '%s'\n", result->caption );
362 /* Get the font name */
364 if (result->style & DS_SETFONT)
366 result->pointSize = GET_WORD(p);
367 p += sizeof(WORD);
368 result->faceName = p;
369 p += strlen(p) + 1;
370 dprintf_dialog( stddeb, " FONT %d,'%s'\n",
371 result->pointSize, result->faceName );
373 return p;
377 /***********************************************************************
378 * DIALOG_ParseTemplate32
380 * Fill a DLG_TEMPLATE structure from the dialog template, and return
381 * a pointer to the first control.
383 static LPCSTR DIALOG_ParseTemplate32( LPCSTR template, DLG_TEMPLATE * result )
385 const WORD *p = (const WORD *)template;
387 result->style = GET_DWORD(p); p += 2;
388 result->exStyle = GET_DWORD(p); p += 2;
389 result->nbItems = GET_WORD(p); p++;
390 result->x = GET_WORD(p); p++;
391 result->y = GET_WORD(p); p++;
392 result->cx = GET_WORD(p); p++;
393 result->cy = GET_WORD(p); p++;
394 dprintf_dialog( stddeb, "DIALOG %d, %d, %d, %d\n",
395 result->x, result->y, result->cx, result->cy );
396 dprintf_dialog( stddeb, " STYLE %08lx\n", result->style );
397 dprintf_dialog( stddeb, " EXSTYLE %08lx\n", result->exStyle );
399 /* Get the menu name */
401 switch(GET_WORD(p))
403 case 0x0000:
404 result->menuName = NULL;
405 p++;
406 break;
407 case 0xffff:
408 result->menuName = (LPCSTR)(UINT32)GET_WORD( p + 1 );
409 p += 2;
410 dprintf_dialog(stddeb, " MENU %04x\n", LOWORD(result->menuName) );
411 break;
412 default:
413 result->menuName = (LPCSTR)p;
414 dprintf_dialog( stddeb, " MENU '%p'\n", p );
415 p += lstrlen32W( (LPCWSTR)p ) + 1;
416 break;
419 /* Get the class name */
421 switch(GET_WORD(p))
423 case 0x0000:
424 result->className = DIALOG_CLASS_ATOM;
425 p++;
426 break;
427 case 0xffff:
428 result->className = (LPCSTR)(UINT32)GET_WORD( p + 1 );
429 p += 2;
430 dprintf_dialog(stddeb, " CLASS %04x\n", LOWORD(result->className) );
431 break;
432 default:
433 result->className = (LPCSTR)p;
434 dprintf_dialog( stddeb, " CLASS '%p'\n", p );
435 p += lstrlen32W( (LPCWSTR)p ) + 1;
436 break;
439 /* Get the window caption */
441 result->caption = (LPCSTR)p;
442 p += lstrlen32W( (LPCWSTR)p ) + 1;
443 dprintf_dialog( stddeb, " CAPTION '%p'\n", result->caption );
445 /* Get the font name */
447 if (result->style & DS_SETFONT)
449 result->pointSize = GET_WORD(p);
450 p++;
451 result->faceName = (LPCSTR)p;
452 p += lstrlen32W( (LPCWSTR)p ) + 1;
453 dprintf_dialog( stddeb, " FONT %d,'%p'\n",
454 result->pointSize, result->faceName );
456 /* First control is on dword boundary */
457 return (LPCSTR)((((int)p) + 3) & ~3);
461 /***********************************************************************
462 * DIALOG_CreateIndirect
464 HWND32 DIALOG_CreateIndirect( HINSTANCE32 hInst, LPCSTR dlgTemplate,
465 BOOL32 win32Template, HWND32 owner,
466 DLGPROC16 dlgProc, LPARAM param,
467 WINDOWPROCTYPE procType )
469 HMENU16 hMenu = 0;
470 HFONT16 hFont = 0;
471 HWND32 hwnd;
472 RECT32 rect;
473 WND * wndPtr;
474 DLG_TEMPLATE template;
475 DIALOGINFO * dlgInfo;
476 WORD xUnit = xBaseUnit;
477 WORD yUnit = yBaseUnit;
479 /* Parse dialog template */
481 if (!dlgTemplate) return 0;
482 if (win32Template)
483 dlgTemplate = DIALOG_ParseTemplate32( dlgTemplate, &template );
484 else
485 dlgTemplate = DIALOG_ParseTemplate16( dlgTemplate, &template );
487 /* Load menu */
489 if (template.menuName)
491 LPSTR str = SEGPTR_STRDUP( template.menuName ); /* FIXME: win32 */
492 hMenu = LoadMenu16( hInst, SEGPTR_GET(str) );
493 SEGPTR_FREE( str );
496 /* Create custom font if needed */
498 if (template.style & DS_SETFONT)
500 /* The font height must be negative as it is a point size */
501 /* (see CreateFont() documentation in the Windows SDK). */
502 hFont = CreateFont16( -template.pointSize, 0, 0, 0, FW_DONTCARE,
503 FALSE, FALSE, FALSE, DEFAULT_CHARSET, 0, 0,
504 DEFAULT_QUALITY, FF_DONTCARE,
505 template.faceName ); /* FIXME: win32 */
506 if (hFont)
508 TEXTMETRIC16 tm;
509 HFONT16 oldFont;
511 HDC32 hdc = GetDC32(0);
512 oldFont = SelectObject32( hdc, hFont );
513 GetTextMetrics16( hdc, &tm );
514 SelectObject32( hdc, oldFont );
515 ReleaseDC32( 0, hdc );
516 xUnit = tm.tmAveCharWidth;
517 yUnit = tm.tmHeight;
518 if (!(tm.tmPitchAndFamily & TMPF_FIXED_PITCH))
519 xBaseUnit = xBaseUnit * 5 / 4; /* See DIALOG_Init() */
523 /* Create dialog main window */
525 rect.left = rect.top = 0;
526 rect.right = template.cx * xUnit / 4;
527 rect.bottom = template.cy * yUnit / 8;
528 if (template.style & DS_MODALFRAME)
529 template.exStyle |= WS_EX_DLGMODALFRAME;
530 AdjustWindowRectEx32( &rect, template.style,
531 hMenu ? TRUE : FALSE , template.exStyle );
532 rect.right -= rect.left;
533 rect.bottom -= rect.top;
535 if ((INT16)template.x == CW_USEDEFAULT16)
537 rect.left = rect.top = (procType == WIN_PROC_16) ? CW_USEDEFAULT16
538 : CW_USEDEFAULT32;
540 else
542 rect.left += template.x * xUnit / 4;
543 rect.top += template.y * yUnit / 8;
544 if ( !(template.style & WS_CHILD) )
546 INT16 dX, dY;
548 if( !(template.style & DS_ABSALIGN) )
549 ClientToScreen32( owner, (POINT32 *)&rect );
551 /* try to fit it into the desktop */
553 if( (dX = rect.left + rect.right + SYSMETRICS_CXDLGFRAME
554 - SYSMETRICS_CXSCREEN) > 0 ) rect.left -= dX;
555 if( (dY = rect.top + rect.bottom + SYSMETRICS_CYDLGFRAME
556 - SYSMETRICS_CYSCREEN) > 0 ) rect.top -= dY;
557 if( rect.left < 0 ) rect.left = 0;
558 if( rect.top < 0 ) rect.top = 0;
562 if (procType != WIN_PROC_16)
563 hwnd = CreateWindowEx32W(template.exStyle, (LPCWSTR)template.className,
564 (LPCWSTR)template.caption,
565 template.style & ~WS_VISIBLE,
566 rect.left, rect.top, rect.right, rect.bottom,
567 owner, hMenu, hInst, NULL );
568 else
569 hwnd = CreateWindowEx16(template.exStyle, template.className,
570 template.caption, template.style & ~WS_VISIBLE,
571 rect.left, rect.top, rect.right, rect.bottom,
572 owner, hMenu, hInst, NULL );
573 if (!hwnd)
575 if (hFont) DeleteObject32( hFont );
576 if (hMenu) DestroyMenu32( hMenu );
577 return 0;
579 wndPtr = WIN_FindWndPtr( hwnd );
580 wndPtr->flags |= WIN_ISDIALOG;
582 /* Initialise dialog extra data */
584 dlgInfo = (DIALOGINFO *)wndPtr->wExtra;
585 WINPROC_SetProc( &dlgInfo->dlgProc, dlgProc, procType, WIN_PROC_WINDOW );
586 dlgInfo->hUserFont = hFont;
587 dlgInfo->hMenu = hMenu;
588 dlgInfo->xBaseUnit = xUnit;
589 dlgInfo->yBaseUnit = yUnit;
590 dlgInfo->msgResult = 0;
591 dlgInfo->idResult = 0;
592 dlgInfo->flags = 0;
593 dlgInfo->hDialogHeap = 0;
595 if (dlgInfo->hUserFont)
596 SendMessage32A( hwnd, WM_SETFONT, (WPARAM32)dlgInfo->hUserFont, 0 );
598 /* Create controls */
600 if (DIALOG_CreateControls( wndPtr, dlgTemplate, template.nbItems,
601 hInst, win32Template ))
603 /* Send initialisation messages and set focus */
605 dlgInfo->hwndFocus = GetNextDlgTabItem32( hwnd, 0, FALSE );
606 if (SendMessage32A( hwnd, WM_INITDIALOG,
607 (WPARAM32)dlgInfo->hwndFocus, param ))
608 SetFocus32( dlgInfo->hwndFocus );
609 if (template.style & WS_VISIBLE) ShowWindow32( hwnd, SW_SHOW );
610 return hwnd;
613 if( IsWindow32(hwnd) ) DestroyWindow32( hwnd );
614 return 0;
618 /***********************************************************************
619 * CreateDialog16 (USER.89)
621 HWND16 CreateDialog16( HINSTANCE16 hInst, SEGPTR dlgTemplate,
622 HWND16 owner, DLGPROC16 dlgProc )
624 return CreateDialogParam16( hInst, dlgTemplate, owner, dlgProc, 0 );
628 /***********************************************************************
629 * CreateDialogParam16 (USER.241)
631 HWND16 CreateDialogParam16( HINSTANCE16 hInst, SEGPTR dlgTemplate,
632 HWND16 owner, DLGPROC16 dlgProc, LPARAM param )
634 HWND16 hwnd = 0;
635 HRSRC16 hRsrc;
636 HGLOBAL16 hmem;
637 LPCVOID data;
639 dprintf_dialog(stddeb, "CreateDialogParam16: %04x,%08lx,%04x,%08lx,%ld\n",
640 hInst, (DWORD)dlgTemplate, owner, (DWORD)dlgProc, param );
642 if (!(hRsrc = FindResource16( hInst, dlgTemplate, RT_DIALOG ))) return 0;
643 if (!(hmem = LoadResource16( hInst, hRsrc ))) return 0;
644 if (!(data = LockResource16( hmem ))) hwnd = 0;
645 else hwnd = CreateDialogIndirectParam16( hInst, data, owner,
646 dlgProc, param );
647 FreeResource16( hmem );
648 return hwnd;
652 /***********************************************************************
653 * CreateDialogParam32A (USER32.72)
655 HWND32 CreateDialogParam32A( HINSTANCE32 hInst, LPCSTR name,
656 HWND32 owner, DLGPROC32 dlgProc, LPARAM param )
658 if (HIWORD(name))
660 LPWSTR str = HEAP_strdupAtoW( GetProcessHeap(), 0, name );
661 HWND32 hwnd = CreateDialogParam32W( hInst, str, owner, dlgProc, param);
662 HeapFree( GetProcessHeap(), 0, str );
663 return hwnd;
665 return CreateDialogParam32W( hInst, (LPCWSTR)name, owner, dlgProc, param );
669 /***********************************************************************
670 * CreateDialogParam32W (USER32.73)
672 HWND32 CreateDialogParam32W( HINSTANCE32 hInst, LPCWSTR name,
673 HWND32 owner, DLGPROC32 dlgProc, LPARAM param )
675 HANDLE32 hrsrc = FindResource32W( hInst, name, (LPWSTR)RT_DIALOG );
676 if (!hrsrc) return 0;
677 return CreateDialogIndirectParam32W( hInst,
678 (LPVOID)LoadResource32(hInst, hrsrc),
679 owner, dlgProc, param );
683 /***********************************************************************
684 * CreateDialogIndirect16 (USER.219)
686 HWND16 CreateDialogIndirect16( HINSTANCE16 hInst, LPCVOID dlgTemplate,
687 HWND16 owner, DLGPROC16 dlgProc )
689 return CreateDialogIndirectParam16( hInst, dlgTemplate, owner, dlgProc, 0);
693 /***********************************************************************
694 * CreateDialogIndirectParam16 (USER.242)
696 HWND16 CreateDialogIndirectParam16( HINSTANCE16 hInst, LPCVOID dlgTemplate,
697 HWND16 owner, DLGPROC16 dlgProc,
698 LPARAM param )
700 return DIALOG_CreateIndirect( hInst, dlgTemplate, FALSE, owner,
701 dlgProc, param, WIN_PROC_16 );
705 /***********************************************************************
706 * CreateDialogIndirectParam32A (USER32.69)
708 HWND32 CreateDialogIndirectParam32A( HINSTANCE32 hInst, LPCVOID dlgTemplate,
709 HWND32 owner, DLGPROC32 dlgProc,
710 LPARAM param )
712 return DIALOG_CreateIndirect( hInst, dlgTemplate, TRUE, owner,
713 (DLGPROC16)dlgProc, param, WIN_PROC_32A );
717 /***********************************************************************
718 * CreateDialogIndirectParam32W (USER32.71)
720 HWND32 CreateDialogIndirectParam32W( HINSTANCE32 hInst, LPCVOID dlgTemplate,
721 HWND32 owner, DLGPROC32 dlgProc,
722 LPARAM param )
724 return DIALOG_CreateIndirect( hInst, dlgTemplate, TRUE, owner,
725 (DLGPROC16)dlgProc, param, WIN_PROC_32W );
729 /***********************************************************************
730 * DIALOG_DoDialogBox
732 INT32 DIALOG_DoDialogBox( HWND32 hwnd, HWND32 owner )
734 WND * wndPtr;
735 DIALOGINFO * dlgInfo;
736 MSG16 msg;
737 INT32 retval;
739 /* Owner must be a top-level window */
740 owner = WIN_GetTopParent( owner );
741 if (!(wndPtr = WIN_FindWndPtr( hwnd ))) return -1;
742 dlgInfo = (DIALOGINFO *)wndPtr->wExtra;
743 EnableWindow32( owner, FALSE );
744 ShowWindow32( hwnd, SW_SHOW );
746 while (MSG_InternalGetMessage(&msg, hwnd, owner, MSGF_DIALOGBOX, PM_REMOVE,
747 !(wndPtr->dwStyle & DS_NOIDLEMSG) ))
749 if (!IsDialogMessage16( hwnd, &msg))
751 TranslateMessage16( &msg );
752 DispatchMessage16( &msg );
754 if (dlgInfo->flags & DF_END) break;
756 retval = dlgInfo->idResult;
757 EnableWindow32( owner, TRUE );
758 DestroyWindow32( hwnd );
759 return retval;
763 /***********************************************************************
764 * DialogBox16 (USER.87)
766 INT16 DialogBox16( HINSTANCE16 hInst, SEGPTR dlgTemplate,
767 HWND16 owner, DLGPROC16 dlgProc )
769 return DialogBoxParam16( hInst, dlgTemplate, owner, dlgProc, 0 );
773 /***********************************************************************
774 * DialogBoxParam16 (USER.239)
776 INT16 DialogBoxParam16( HINSTANCE16 hInst, SEGPTR template,
777 HWND16 owner, DLGPROC16 dlgProc, LPARAM param )
779 HWND16 hwnd = CreateDialogParam16( hInst, template, owner, dlgProc, param);
780 if (hwnd) return (INT16)DIALOG_DoDialogBox( hwnd, owner );
781 return -1;
785 /***********************************************************************
786 * DialogBoxParam32A (USER32.138)
788 INT32 DialogBoxParam32A( HINSTANCE32 hInst, LPCSTR name,
789 HWND32 owner, DLGPROC32 dlgProc, LPARAM param )
791 HWND32 hwnd = CreateDialogParam32A( hInst, name, owner, dlgProc, param );
792 if (hwnd) return DIALOG_DoDialogBox( hwnd, owner );
793 return -1;
797 /***********************************************************************
798 * DialogBoxParam32W (USER32.139)
800 INT32 DialogBoxParam32W( HINSTANCE32 hInst, LPCWSTR name,
801 HWND32 owner, DLGPROC32 dlgProc, LPARAM param )
803 HWND32 hwnd = CreateDialogParam32W( hInst, name, owner, dlgProc, param );
804 if (hwnd) return DIALOG_DoDialogBox( hwnd, owner );
805 return -1;
809 /***********************************************************************
810 * DialogBoxIndirect16 (USER.218)
812 INT16 DialogBoxIndirect16( HINSTANCE16 hInst, HANDLE16 dlgTemplate,
813 HWND16 owner, DLGPROC16 dlgProc )
815 return DialogBoxIndirectParam16( hInst, dlgTemplate, owner, dlgProc, 0 );
819 /***********************************************************************
820 * DialogBoxIndirectParam16 (USER.240)
822 INT16 DialogBoxIndirectParam16( HINSTANCE16 hInst, HANDLE16 dlgTemplate,
823 HWND16 owner, DLGPROC16 dlgProc, LPARAM param )
825 HWND16 hwnd;
826 LPCVOID ptr;
828 if (!(ptr = GlobalLock16( dlgTemplate ))) return -1;
829 hwnd = CreateDialogIndirectParam16( hInst, ptr, owner, dlgProc, param );
830 GlobalUnlock16( dlgTemplate );
831 if (hwnd) return (INT16)DIALOG_DoDialogBox( hwnd, owner );
832 return -1;
836 /***********************************************************************
837 * DialogBoxIndirectParam32A (USER32.135)
839 INT32 DialogBoxIndirectParam32A( HINSTANCE32 hInstance, LPCVOID template,
840 HWND32 owner, DLGPROC32 dlgProc, LPARAM param)
842 HWND32 hwnd = CreateDialogIndirectParam32A( hInstance, template,
843 owner, dlgProc, param );
844 if (hwnd) return DIALOG_DoDialogBox( hwnd, owner );
845 return -1;
849 /***********************************************************************
850 * DialogBoxIndirectParam32W (USER32.137)
852 INT32 DialogBoxIndirectParam32W( HINSTANCE32 hInstance, LPCVOID template,
853 HWND32 owner, DLGPROC32 dlgProc, LPARAM param)
855 HWND32 hwnd = CreateDialogIndirectParam32W( hInstance, template,
856 owner, dlgProc, param );
857 if (hwnd) return DIALOG_DoDialogBox( hwnd, owner );
858 return -1;
862 /***********************************************************************
863 * EndDialog16 (USER32.173)
865 BOOL16 EndDialog16( HWND16 hwnd, INT16 retval )
867 return EndDialog32( hwnd, retval );
871 /***********************************************************************
872 * EndDialog32 (USER32.173)
874 BOOL32 EndDialog32( HWND32 hwnd, INT32 retval )
876 WND * wndPtr = WIN_FindWndPtr( hwnd );
877 DIALOGINFO * dlgInfo = (DIALOGINFO *)wndPtr->wExtra;
879 dprintf_dialog(stddeb, "EndDialog: %04x %d\n", hwnd, retval );
881 if( dlgInfo )
883 dlgInfo->idResult = retval;
884 dlgInfo->flags |= DF_END;
886 return TRUE;
890 /***********************************************************************
891 * DIALOG_IsDialogMessage
893 static BOOL32 DIALOG_IsDialogMessage( HWND32 hwnd, HWND32 hwndDlg,
894 UINT32 message, WPARAM32 wParam,
895 LPARAM lParam, BOOL32 *translate,
896 BOOL32 *dispatch )
898 INT32 dlgCode;
900 *translate = *dispatch = FALSE;
902 /* Only the key messages get special processing */
903 if ((message != WM_KEYDOWN) &&
904 (message != WM_SYSCHAR) &&
905 (message != WM_CHAR))
906 return FALSE;
908 dlgCode = SendMessage32A( hwnd, WM_GETDLGCODE, 0, 0 );
909 if (dlgCode & DLGC_WANTMESSAGE)
911 *dispatch = TRUE;
912 return TRUE;
915 switch(message)
917 case WM_KEYDOWN:
918 if (dlgCode & DLGC_WANTALLKEYS) break;
919 switch(wParam)
921 case VK_TAB:
922 if (!(dlgCode & DLGC_WANTTAB))
924 SendMessage32A( hwndDlg, WM_NEXTDLGCTL,
925 (GetKeyState32(VK_SHIFT) & 0x8000), 0 );
926 return TRUE;
928 break;
930 case VK_RIGHT:
931 case VK_DOWN:
932 if (!(dlgCode & DLGC_WANTARROWS))
934 SetFocus32( GetNextDlgGroupItem32( hwndDlg, GetFocus32(),
935 FALSE ) );
936 return TRUE;
938 break;
940 case VK_LEFT:
941 case VK_UP:
942 if (!(dlgCode & DLGC_WANTARROWS))
944 SetFocus32( GetNextDlgGroupItem32( hwndDlg, GetFocus32(),
945 TRUE ) );
946 return TRUE;
948 break;
950 case VK_ESCAPE:
951 SendMessage32A( hwndDlg, WM_COMMAND, IDCANCEL,
952 (LPARAM)GetDlgItem32( hwndDlg, IDCANCEL ) );
953 break;
955 case VK_RETURN:
957 DWORD dw = SendMessage16( hwndDlg, DM_GETDEFID, 0, 0 );
958 if (HIWORD(dw) == DC_HASDEFID)
959 SendMessage32A( hwndDlg, WM_COMMAND,
960 MAKEWPARAM( LOWORD(dw), BN_CLICKED ),
961 (LPARAM)GetDlgItem32(hwndDlg, LOWORD(dw)));
962 else
963 SendMessage32A( hwndDlg, WM_COMMAND, IDOK,
964 (LPARAM)GetDlgItem32( hwndDlg, IDOK ) );
966 break;
968 default:
969 *translate = TRUE;
970 break;
972 break; /* case WM_KEYDOWN */
975 case WM_CHAR:
976 if (dlgCode & (DLGC_WANTALLKEYS | DLGC_WANTCHARS)) break;
977 break;
979 case WM_SYSCHAR:
980 if (dlgCode & DLGC_WANTALLKEYS) break;
981 break;
984 /* If we get here, the message has not been treated specially */
985 /* and can be sent to its destination window. */
986 *dispatch = TRUE;
987 return TRUE;
991 /***********************************************************************
992 * IsDialogMessage16 (USER.90)
994 BOOL16 IsDialogMessage16( HWND16 hwndDlg, LPMSG16 msg )
996 BOOL32 ret, translate, dispatch;
998 if ((hwndDlg != msg->hwnd) && !IsChild16( hwndDlg, msg->hwnd ))
999 return FALSE;
1001 ret = DIALOG_IsDialogMessage( msg->hwnd, hwndDlg, msg->message,
1002 msg->wParam, msg->lParam,
1003 &translate, &dispatch );
1004 if (translate) TranslateMessage16( msg );
1005 if (dispatch) DispatchMessage16( msg );
1006 return ret;
1010 /***********************************************************************
1011 * IsDialogMessage32A (USER32.341)
1013 BOOL32 IsDialogMessage32A( HWND32 hwndDlg, LPMSG32 msg )
1015 BOOL32 ret, translate, dispatch;
1017 if ((hwndDlg != msg->hwnd) && !IsChild32( hwndDlg, msg->hwnd ))
1018 return FALSE;
1020 ret = DIALOG_IsDialogMessage( msg->hwnd, hwndDlg, msg->message,
1021 msg->wParam, msg->lParam,
1022 &translate, &dispatch );
1023 if (translate) TranslateMessage32( msg );
1024 if (dispatch) DispatchMessage32A( msg );
1025 return ret;
1029 /***********************************************************************
1030 * IsDialogMessage32W (USER32.342)
1032 BOOL32 IsDialogMessage32W( HWND32 hwndDlg, LPMSG32 msg )
1034 BOOL32 ret, translate, dispatch;
1036 if ((hwndDlg != msg->hwnd) && !IsChild32( hwndDlg, msg->hwnd ))
1037 return FALSE;
1039 ret = DIALOG_IsDialogMessage( msg->hwnd, hwndDlg, msg->message,
1040 msg->wParam, msg->lParam,
1041 &translate, &dispatch );
1042 if (translate) TranslateMessage32( msg );
1043 if (dispatch) DispatchMessage32W( msg );
1044 return ret;
1048 /****************************************************************
1049 * GetDlgCtrlID16 (USER.277)
1051 INT16 GetDlgCtrlID16( HWND16 hwnd )
1053 WND *wndPtr = WIN_FindWndPtr(hwnd);
1054 if (wndPtr) return wndPtr->wIDmenu;
1055 else return 0;
1059 /****************************************************************
1060 * GetDlgCtrlID32 (USER32.233)
1062 INT32 GetDlgCtrlID32( HWND32 hwnd )
1064 WND *wndPtr = WIN_FindWndPtr(hwnd);
1065 if (wndPtr) return wndPtr->wIDmenu;
1066 else return 0;
1070 /***********************************************************************
1071 * GetDlgItem16 (USER.91)
1073 HWND16 GetDlgItem16( HWND16 hwndDlg, INT16 id )
1075 WND *pWnd;
1077 if (!(pWnd = WIN_FindWndPtr( hwndDlg ))) return 0;
1078 for (pWnd = pWnd->child; pWnd; pWnd = pWnd->next)
1079 if (pWnd->wIDmenu == (UINT16)id) return pWnd->hwndSelf;
1080 return 0;
1084 /***********************************************************************
1085 * GetDlgItem32 (USER32.234)
1087 HWND32 GetDlgItem32( HWND32 hwndDlg, INT32 id )
1089 WND *pWnd;
1091 if (!(pWnd = WIN_FindWndPtr( hwndDlg ))) return 0;
1092 for (pWnd = pWnd->child; pWnd; pWnd = pWnd->next)
1093 if (pWnd->wIDmenu == (UINT16)id) return pWnd->hwndSelf;
1094 return 0;
1098 /*******************************************************************
1099 * SendDlgItemMessage16 (USER.101)
1101 LRESULT SendDlgItemMessage16( HWND16 hwnd, INT16 id, UINT16 msg,
1102 WPARAM16 wParam, LPARAM lParam )
1104 HWND16 hwndCtrl = GetDlgItem16( hwnd, id );
1105 if (hwndCtrl) return SendMessage16( hwndCtrl, msg, wParam, lParam );
1106 else return 0;
1110 /*******************************************************************
1111 * SendDlgItemMessage32A (USER32.451)
1113 LRESULT SendDlgItemMessage32A( HWND32 hwnd, INT32 id, UINT32 msg,
1114 WPARAM32 wParam, LPARAM lParam )
1116 HWND32 hwndCtrl = GetDlgItem32( hwnd, id );
1117 if (hwndCtrl) return SendMessage32A( hwndCtrl, msg, wParam, lParam );
1118 else return 0;
1122 /*******************************************************************
1123 * SendDlgItemMessage32W (USER32.452)
1125 LRESULT SendDlgItemMessage32W( HWND32 hwnd, INT32 id, UINT32 msg,
1126 WPARAM32 wParam, LPARAM lParam )
1128 HWND32 hwndCtrl = GetDlgItem32( hwnd, id );
1129 if (hwndCtrl) return SendMessage32W( hwndCtrl, msg, wParam, lParam );
1130 else return 0;
1134 /*******************************************************************
1135 * SetDlgItemText16 (USER.92)
1137 void SetDlgItemText16( HWND16 hwnd, INT16 id, SEGPTR lpString )
1139 SendDlgItemMessage16( hwnd, id, WM_SETTEXT, 0, (LPARAM)lpString );
1143 /*******************************************************************
1144 * SetDlgItemText32A (USER32.477)
1146 void SetDlgItemText32A( HWND32 hwnd, INT32 id, LPCSTR lpString )
1148 SendDlgItemMessage32A( hwnd, id, WM_SETTEXT, 0, (LPARAM)lpString );
1152 /*******************************************************************
1153 * SetDlgItemText32W (USER32.478)
1155 void SetDlgItemText32W( HWND32 hwnd, INT32 id, LPCWSTR lpString )
1157 SendDlgItemMessage32W( hwnd, id, WM_SETTEXT, 0, (LPARAM)lpString );
1161 /***********************************************************************
1162 * GetDlgItemText16 (USER.93)
1164 INT16 GetDlgItemText16( HWND16 hwnd, INT16 id, SEGPTR str, UINT16 len )
1166 return (INT16)SendDlgItemMessage16( hwnd, id, WM_GETTEXT,
1167 len, (LPARAM)str );
1171 /***********************************************************************
1172 * GetDlgItemText32A (USER32.236)
1174 INT32 GetDlgItemText32A( HWND32 hwnd, INT32 id, LPSTR str, UINT32 len )
1176 return (INT32)SendDlgItemMessage32A( hwnd, id, WM_GETTEXT,
1177 len, (LPARAM)str );
1181 /***********************************************************************
1182 * GetDlgItemText32W (USER32.237)
1184 INT32 GetDlgItemText32W( HWND32 hwnd, INT32 id, LPWSTR str, UINT32 len )
1186 return (INT32)SendDlgItemMessage32W( hwnd, id, WM_GETTEXT,
1187 len, (LPARAM)str );
1191 /*******************************************************************
1192 * SetDlgItemInt16 (USER.94)
1194 void SetDlgItemInt16( HWND16 hwnd, INT16 id, UINT16 value, BOOL16 fSigned )
1196 return SetDlgItemInt32( hwnd, (UINT32)(UINT16)id, value, fSigned );
1200 /*******************************************************************
1201 * SetDlgItemInt32 (USER32.476)
1203 void SetDlgItemInt32( HWND32 hwnd, INT32 id, UINT32 value, BOOL32 fSigned )
1205 char str[20];
1207 if (fSigned) sprintf( str, "%d", (INT32)value );
1208 else sprintf( str, "%u", value );
1209 SendDlgItemMessage32A( hwnd, id, WM_SETTEXT, 0, (LPARAM)str );
1213 /***********************************************************************
1214 * GetDlgItemInt16 (USER.95)
1216 UINT16 GetDlgItemInt16( HWND16 hwnd, INT16 id, BOOL16 *translated,
1217 BOOL16 fSigned )
1219 UINT32 result;
1220 BOOL32 ok;
1222 if (translated) *translated = FALSE;
1223 result = GetDlgItemInt32( hwnd, (UINT32)(UINT16)id, &ok, fSigned );
1224 if (!ok) return 0;
1225 if (fSigned)
1227 if (((INT32)result < -32767) || ((INT32)result > 32767)) return 0;
1229 else
1231 if (result > 65535) return 0;
1233 if (translated) *translated = TRUE;
1234 return (UINT16)result;
1238 /***********************************************************************
1239 * GetDlgItemInt32 (USER32.235)
1241 UINT32 GetDlgItemInt32( HWND32 hwnd, INT32 id, BOOL32 *translated,
1242 BOOL32 fSigned )
1244 char str[30];
1245 char * endptr;
1246 long result = 0;
1248 if (translated) *translated = FALSE;
1249 if (!SendDlgItemMessage32A(hwnd, id, WM_GETTEXT, sizeof(str), (LPARAM)str))
1250 return 0;
1251 if (fSigned)
1253 result = strtol( str, &endptr, 10 );
1254 if (!endptr || (endptr == str)) /* Conversion was unsuccessful */
1255 return 0;
1256 if (((result == LONG_MIN) || (result == LONG_MAX)) && (errno==ERANGE))
1257 return 0;
1259 else
1261 result = strtoul( str, &endptr, 10 );
1262 if (!endptr || (endptr == str)) /* Conversion was unsuccessful */
1263 return 0;
1264 if ((result == ULONG_MAX) && (errno == ERANGE)) return 0;
1266 if (translated) *translated = TRUE;
1267 return (UINT32)result;
1271 /***********************************************************************
1272 * CheckDlgButton16 (USER.97)
1274 BOOL16 CheckDlgButton16( HWND16 hwnd, INT16 id, UINT16 check )
1276 SendDlgItemMessage32A( hwnd, id, BM_SETCHECK32, check, 0 );
1277 return TRUE;
1281 /***********************************************************************
1282 * CheckDlgButton32 (USER32.44)
1284 BOOL32 CheckDlgButton32( HWND32 hwnd, INT32 id, UINT32 check )
1286 SendDlgItemMessage32A( hwnd, id, BM_SETCHECK32, check, 0 );
1287 return TRUE;
1291 /***********************************************************************
1292 * IsDlgButtonChecked16 (USER.98)
1294 UINT16 IsDlgButtonChecked16( HWND16 hwnd, UINT16 id )
1296 return (UINT16)SendDlgItemMessage32A( hwnd, id, BM_GETCHECK32, 0, 0 );
1300 /***********************************************************************
1301 * IsDlgButtonChecked32 (USER32.343)
1303 UINT32 IsDlgButtonChecked32( HWND32 hwnd, UINT32 id )
1305 return (UINT32)SendDlgItemMessage32A( hwnd, id, BM_GETCHECK32, 0, 0 );
1309 /***********************************************************************
1310 * CheckRadioButton16 (USER.96)
1312 BOOL16 CheckRadioButton16( HWND16 hwndDlg, UINT16 firstID, UINT16 lastID,
1313 UINT16 checkID )
1315 return CheckRadioButton32( hwndDlg, firstID, lastID, checkID );
1319 /***********************************************************************
1320 * CheckRadioButton32 (USER32.47)
1322 BOOL32 CheckRadioButton32( HWND32 hwndDlg, UINT32 firstID, UINT32 lastID,
1323 UINT32 checkID )
1325 WND *pWnd = WIN_FindWndPtr( hwndDlg );
1326 if (!pWnd) return FALSE;
1328 for (pWnd = pWnd->child; pWnd; pWnd = pWnd->next)
1329 if ((pWnd->wIDmenu == firstID) || (pWnd->wIDmenu == lastID)) break;
1330 if (!pWnd) return FALSE;
1332 if (pWnd->wIDmenu == lastID)
1333 lastID = firstID; /* Buttons are in reverse order */
1334 while (pWnd)
1336 SendMessage32A( pWnd->hwndSelf, BM_SETCHECK32,
1337 (pWnd->wIDmenu == checkID), 0 );
1338 if (pWnd->wIDmenu == lastID) break;
1339 pWnd = pWnd->next;
1341 return TRUE;
1345 /***********************************************************************
1346 * GetDialogBaseUnits (USER.243) (USER32.232)
1348 DWORD GetDialogBaseUnits(void)
1350 return MAKELONG( xBaseUnit, yBaseUnit );
1354 /***********************************************************************
1355 * MapDialogRect16 (USER.103)
1357 void MapDialogRect16( HWND16 hwnd, LPRECT16 rect )
1359 DIALOGINFO * dlgInfo;
1360 WND * wndPtr = WIN_FindWndPtr( hwnd );
1361 if (!wndPtr) return;
1362 dlgInfo = (DIALOGINFO *)wndPtr->wExtra;
1363 rect->left = (rect->left * dlgInfo->xBaseUnit) / 4;
1364 rect->right = (rect->right * dlgInfo->xBaseUnit) / 4;
1365 rect->top = (rect->top * dlgInfo->yBaseUnit) / 8;
1366 rect->bottom = (rect->bottom * dlgInfo->yBaseUnit) / 8;
1370 /***********************************************************************
1371 * MapDialogRect32 (USER32.381)
1373 void MapDialogRect32( HWND32 hwnd, LPRECT32 rect )
1375 DIALOGINFO * dlgInfo;
1376 WND * wndPtr = WIN_FindWndPtr( hwnd );
1377 if (!wndPtr) return;
1378 dlgInfo = (DIALOGINFO *)wndPtr->wExtra;
1379 rect->left = (rect->left * dlgInfo->xBaseUnit) / 4;
1380 rect->right = (rect->right * dlgInfo->xBaseUnit) / 4;
1381 rect->top = (rect->top * dlgInfo->yBaseUnit) / 8;
1382 rect->bottom = (rect->bottom * dlgInfo->yBaseUnit) / 8;
1386 /***********************************************************************
1387 * GetNextDlgGroupItem16 (USER.227)
1389 HWND16 GetNextDlgGroupItem16(HWND16 hwndDlg, HWND16 hwndCtrl, BOOL16 fPrevious)
1391 return (HWND16)GetNextDlgGroupItem32( hwndDlg, hwndCtrl, fPrevious );
1395 /***********************************************************************
1396 * GetNextDlgGroupItem32 (USER32.274)
1398 HWND32 GetNextDlgGroupItem32(HWND32 hwndDlg, HWND32 hwndCtrl, BOOL32 fPrevious)
1400 WND *pWnd, *pWndLast, *pWndCtrl, *pWndDlg;
1402 if (!(pWndDlg = WIN_FindWndPtr( hwndDlg ))) return 0;
1403 if (hwndCtrl)
1405 if (!(pWndCtrl = WIN_FindWndPtr( hwndCtrl ))) return 0;
1406 /* Make sure hwndCtrl is a top-level child */
1407 while ((pWndCtrl->dwStyle & WS_CHILD) && (pWndCtrl->parent != pWndDlg))
1408 pWndCtrl = pWndCtrl->parent;
1409 if (pWndCtrl->parent != pWndDlg) return 0;
1411 else
1413 /* No ctrl specified -> start from the beginning */
1414 if (!(pWndCtrl = pWndDlg->child)) return 0;
1415 if (fPrevious) while (pWndCtrl->next) pWndCtrl = pWndCtrl->next;
1418 pWndLast = pWndCtrl;
1419 pWnd = pWndCtrl->next;
1420 while (1)
1422 if (!pWnd || (pWnd->dwStyle & WS_GROUP))
1424 /* Wrap-around to the beginning of the group */
1425 WND *pWndStart = pWndDlg->child;
1426 for (pWnd = pWndStart; pWnd; pWnd = pWnd->next)
1428 if (pWnd->dwStyle & WS_GROUP) pWndStart = pWnd;
1429 if (pWnd == pWndCtrl) break;
1431 pWnd = pWndStart;
1433 if (pWnd == pWndCtrl) break;
1434 if ((pWnd->dwStyle & WS_VISIBLE) && !(pWnd->dwStyle & WS_DISABLED))
1436 pWndLast = pWnd;
1437 if (!fPrevious) break;
1439 pWnd = pWnd->next;
1441 return pWndLast->hwndSelf;
1445 /***********************************************************************
1446 * GetNextDlgTabItem16 (USER.228)
1448 HWND16 GetNextDlgTabItem16( HWND16 hwndDlg, HWND16 hwndCtrl, BOOL16 fPrevious )
1450 return (HWND16)GetNextDlgTabItem32( hwndDlg, hwndCtrl, fPrevious );
1454 /***********************************************************************
1455 * GetNextDlgTabItem32 (USER32.275)
1457 HWND32 GetNextDlgTabItem32( HWND32 hwndDlg, HWND32 hwndCtrl, BOOL32 fPrevious )
1459 WND *pWnd, *pWndLast, *pWndCtrl, *pWndDlg;
1461 if (!(pWndDlg = WIN_FindWndPtr( hwndDlg ))) return 0;
1462 if (hwndCtrl)
1464 if (!(pWndCtrl = WIN_FindWndPtr( hwndCtrl ))) return 0;
1465 /* Make sure hwndCtrl is a top-level child */
1466 while ((pWndCtrl->dwStyle & WS_CHILD) && (pWndCtrl->parent != pWndDlg))
1467 pWndCtrl = pWndCtrl->parent;
1468 if (pWndCtrl->parent != pWndDlg) return 0;
1470 else
1472 /* No ctrl specified -> start from the beginning */
1473 if (!(pWndCtrl = pWndDlg->child)) return 0;
1474 if (fPrevious) while (pWndCtrl->next) pWndCtrl = pWndCtrl->next;
1477 pWndLast = pWndCtrl;
1478 pWnd = pWndCtrl->next;
1479 while (1)
1481 if (!pWnd) pWnd = pWndDlg->child;
1482 if (pWnd == pWndCtrl) break;
1483 if ((pWnd->dwStyle & WS_TABSTOP) && (pWnd->dwStyle & WS_VISIBLE) &&
1484 !(pWnd->dwStyle & WS_DISABLED))
1486 pWndLast = pWnd;
1487 if (!fPrevious) break;
1489 pWnd = pWnd->next;
1491 return pWndLast->hwndSelf;
1495 /**********************************************************************
1496 * DIALOG_DlgDirSelect
1498 * Helper function for DlgDirSelect*
1500 static BOOL32 DIALOG_DlgDirSelect( HWND32 hwnd, LPSTR str, INT32 len,
1501 INT32 id, BOOL32 win32, BOOL32 unicode,
1502 BOOL32 combo )
1504 char *buffer, *ptr;
1505 INT32 item, size;
1506 BOOL32 ret;
1507 HWND32 listbox = GetDlgItem32( hwnd, id );
1509 dprintf_dialog( stddeb, "DlgDirSelect: %04x '%s' %d\n", hwnd, str, id );
1510 if (!listbox) return FALSE;
1511 if (win32)
1513 item = SendMessage32A(listbox, combo ? CB_GETCURSEL32
1514 : LB_GETCURSEL32, 0, 0 );
1515 if (item == LB_ERR) return FALSE;
1516 size = SendMessage32A(listbox, combo ? CB_GETLBTEXTLEN32
1517 : LB_GETTEXTLEN32, 0, 0 );
1518 if (size == LB_ERR) return FALSE;
1520 else
1522 item = SendMessage32A(listbox, combo ? CB_GETCURSEL16
1523 : LB_GETCURSEL16, 0, 0 );
1524 if (item == LB_ERR) return FALSE;
1525 size = SendMessage32A(listbox, combo ? CB_GETLBTEXTLEN16
1526 : LB_GETTEXTLEN16, 0, 0 );
1527 if (size == LB_ERR) return FALSE;
1530 if (!(buffer = SEGPTR_ALLOC( size+1 ))) return FALSE;
1532 if (win32)
1533 SendMessage32A( listbox, combo ? CB_GETLBTEXT32 : LB_GETTEXT32,
1534 item, (LPARAM)buffer );
1535 else
1536 SendMessage16( listbox, combo ? CB_GETLBTEXT16 : LB_GETTEXT16,
1537 item, (LPARAM)SEGPTR_GET(buffer) );
1539 if ((ret = (buffer[0] == '['))) /* drive or directory */
1541 if (buffer[1] == '-') /* drive */
1543 buffer[3] = ':';
1544 buffer[4] = 0;
1545 ptr = buffer + 2;
1547 else
1549 buffer[strlen(buffer)-1] = '\\';
1550 ptr = buffer + 1;
1553 else ptr = buffer;
1555 if (unicode) lstrcpynAtoW( (LPWSTR)str, ptr, len );
1556 else lstrcpyn32A( str, ptr, len );
1557 SEGPTR_FREE( buffer );
1558 dprintf_dialog( stddeb, "Returning %d '%s'\n", ret, str );
1559 return ret;
1563 /**********************************************************************
1564 * DIALOG_DlgDirList
1566 * Helper function for DlgDirList*
1568 static INT32 DIALOG_DlgDirList( HWND32 hDlg, LPSTR spec, INT32 idLBox,
1569 INT32 idStatic, UINT32 attrib, BOOL32 combo )
1571 int drive;
1572 HWND32 hwnd;
1573 LPSTR orig_spec = spec;
1575 #define SENDMSG(msg,wparam,lparam) \
1576 ((attrib & DDL_POSTMSGS) ? PostMessage32A( hwnd, msg, wparam, lparam ) \
1577 : SendMessage32A( hwnd, msg, wparam, lparam ))
1579 dprintf_dialog( stddeb, "DlgDirList: %04x '%s' %d %d %04x\n",
1580 hDlg, spec ? spec : "NULL", idLBox, idStatic, attrib );
1582 if (spec && spec[0] && (spec[1] == ':'))
1584 drive = toupper( spec[0] ) - 'A';
1585 spec += 2;
1586 if (!DRIVE_SetCurrentDrive( drive )) return FALSE;
1588 else drive = DRIVE_GetCurrentDrive();
1590 /* If the path exists and is a directory, chdir to it */
1591 if (!spec || !spec[0] || DRIVE_Chdir( drive, spec )) spec = "*.*";
1592 else
1594 char *p, *p2;
1595 p = spec;
1596 if ((p2 = strrchr( p, '\\' ))) p = p2;
1597 if ((p2 = strrchr( p, '/' ))) p = p2;
1598 if (p != spec)
1600 char sep = *p;
1601 *p = 0;
1602 if (!DRIVE_Chdir( drive, spec ))
1604 *p = sep; /* Restore the original spec */
1605 return FALSE;
1607 spec = p + 1;
1611 dprintf_dialog( stddeb, "ListBoxDirectory: path=%c:\\%s mask=%s\n",
1612 'A' + drive, DRIVE_GetDosCwd(drive), spec );
1614 if (idLBox && ((hwnd = GetDlgItem32( hDlg, idLBox )) != 0))
1616 SENDMSG( combo ? CB_RESETCONTENT32 : LB_RESETCONTENT32, 0, 0 );
1617 if (attrib & DDL_DIRECTORY)
1619 if (!(attrib & DDL_EXCLUSIVE))
1621 if (SENDMSG( combo ? CB_DIR32 : LB_DIR32,
1622 attrib & ~(DDL_DIRECTORY | DDL_DRIVES),
1623 (LPARAM)spec ) == LB_ERR)
1624 return FALSE;
1626 if (SENDMSG( combo ? CB_DIR32 : LB_DIR32,
1627 (attrib & (DDL_DIRECTORY | DDL_DRIVES)) | DDL_EXCLUSIVE,
1628 (LPARAM)"*.*" ) == LB_ERR)
1629 return FALSE;
1631 else
1633 if (SENDMSG( combo ? CB_DIR32 : LB_DIR32, attrib,
1634 (LPARAM)spec ) == LB_ERR)
1635 return FALSE;
1639 if (idStatic && ((hwnd = GetDlgItem32( hDlg, idStatic )) != 0))
1641 char temp[512];
1642 int drive = DRIVE_GetCurrentDrive();
1643 strcpy( temp, "A:\\" );
1644 temp[0] += drive;
1645 lstrcpyn32A( temp + 3, DRIVE_GetDosCwd(drive), sizeof(temp)-3 );
1646 CharLower32A( temp );
1647 /* Can't use PostMessage() here, because the string is on the stack */
1648 SetDlgItemText32A( hDlg, idStatic, temp );
1651 if (orig_spec && (spec != orig_spec))
1653 /* Update the original file spec */
1654 char *p = spec;
1655 while ((*orig_spec++ = *p++));
1658 return TRUE;
1659 #undef SENDMSG
1663 /**********************************************************************
1664 * DIALOG_DlgDirListW
1666 * Helper function for DlgDirList*32W
1668 static INT32 DIALOG_DlgDirListW( HWND32 hDlg, LPWSTR spec, INT32 idLBox,
1669 INT32 idStatic, UINT32 attrib, BOOL32 combo )
1671 if (spec)
1673 LPSTR specA = HEAP_strdupWtoA( GetProcessHeap(), 0, spec );
1674 INT32 ret = DIALOG_DlgDirList( hDlg, specA, idLBox, idStatic,
1675 attrib, combo );
1676 lstrcpyAtoW( spec, specA );
1677 HeapFree( GetProcessHeap(), 0, specA );
1678 return ret;
1680 return DIALOG_DlgDirList( hDlg, NULL, idLBox, idStatic, attrib, combo );
1684 /**********************************************************************
1685 * DlgDirSelect (USER.99)
1687 BOOL16 DlgDirSelect( HWND16 hwnd, LPSTR str, INT16 id )
1689 return DlgDirSelectEx16( hwnd, str, 128, id );
1693 /**********************************************************************
1694 * DlgDirSelectComboBox (USER.194)
1696 BOOL16 DlgDirSelectComboBox( HWND16 hwnd, LPSTR str, INT16 id )
1698 return DlgDirSelectComboBoxEx16( hwnd, str, 128, id );
1702 /**********************************************************************
1703 * DlgDirSelectEx16 (USER.422)
1705 BOOL16 DlgDirSelectEx16( HWND16 hwnd, LPSTR str, INT16 len, INT16 id )
1707 return DIALOG_DlgDirSelect( hwnd, str, len, id, FALSE, FALSE, FALSE );
1711 /**********************************************************************
1712 * DlgDirSelectEx32A (USER32.148)
1714 BOOL32 DlgDirSelectEx32A( HWND32 hwnd, LPSTR str, INT32 len, INT32 id )
1716 return DIALOG_DlgDirSelect( hwnd, str, len, id, TRUE, FALSE, FALSE );
1720 /**********************************************************************
1721 * DlgDirSelectEx32W (USER32.149)
1723 BOOL32 DlgDirSelectEx32W( HWND32 hwnd, LPWSTR str, INT32 len, INT32 id )
1725 return DIALOG_DlgDirSelect( hwnd, (LPSTR)str, len, id, TRUE, TRUE, FALSE );
1729 /**********************************************************************
1730 * DlgDirSelectComboBoxEx16 (USER.423)
1732 BOOL16 DlgDirSelectComboBoxEx16( HWND16 hwnd, LPSTR str, INT16 len, INT16 id )
1734 return DIALOG_DlgDirSelect( hwnd, str, len, id, FALSE, FALSE, TRUE );
1738 /**********************************************************************
1739 * DlgDirSelectComboBoxEx32A (USER32.146)
1741 BOOL32 DlgDirSelectComboBoxEx32A( HWND32 hwnd, LPSTR str, INT32 len, INT32 id )
1743 return DIALOG_DlgDirSelect( hwnd, str, len, id, TRUE, FALSE, TRUE );
1747 /**********************************************************************
1748 * DlgDirSelectComboBoxEx32W (USER32.147)
1750 BOOL32 DlgDirSelectComboBoxEx32W( HWND32 hwnd, LPWSTR str, INT32 len, INT32 id)
1752 return DIALOG_DlgDirSelect( hwnd, (LPSTR)str, len, id, TRUE, TRUE, TRUE );
1756 /**********************************************************************
1757 * DlgDirList16 (USER.100)
1759 INT16 DlgDirList16( HWND16 hDlg, LPSTR spec, INT16 idLBox, INT16 idStatic,
1760 UINT16 attrib )
1762 return DIALOG_DlgDirList( hDlg, spec, idLBox, idStatic, attrib, FALSE );
1766 /**********************************************************************
1767 * DlgDirList32A (USER32.142)
1769 INT32 DlgDirList32A( HWND32 hDlg, LPSTR spec, INT32 idLBox, INT32 idStatic,
1770 UINT32 attrib )
1772 return DIALOG_DlgDirList( hDlg, spec, idLBox, idStatic, attrib, FALSE );
1776 /**********************************************************************
1777 * DlgDirList32W (USER32.145)
1779 INT32 DlgDirList32W( HWND32 hDlg, LPWSTR spec, INT32 idLBox, INT32 idStatic,
1780 UINT32 attrib )
1782 return DIALOG_DlgDirListW( hDlg, spec, idLBox, idStatic, attrib, FALSE );
1786 /**********************************************************************
1787 * DlgDirListComboBox16 (USER.195)
1789 INT16 DlgDirListComboBox16( HWND16 hDlg, LPSTR spec, INT16 idCBox,
1790 INT16 idStatic, UINT16 attrib )
1792 return DIALOG_DlgDirList( hDlg, spec, idCBox, idStatic, attrib, TRUE );
1796 /**********************************************************************
1797 * DlgDirListComboBox32A (USER32.143)
1799 INT32 DlgDirListComboBox32A( HWND32 hDlg, LPSTR spec, INT32 idCBox,
1800 INT32 idStatic, UINT32 attrib )
1802 return DIALOG_DlgDirList( hDlg, spec, idCBox, idStatic, attrib, TRUE );
1806 /**********************************************************************
1807 * DlgDirListComboBox32W (USER32.144)
1809 INT32 DlgDirListComboBox32W( HWND32 hDlg, LPWSTR spec, INT32 idCBox,
1810 INT32 idStatic, UINT32 attrib )
1812 return DIALOG_DlgDirListW( hDlg, spec, idCBox, idStatic, attrib, TRUE );