blob: 2d206bd536c1a50e181058e09c0e9bb9b25b3397 [file] [log] [blame]
Alexandre Julliard0e607781993-11-03 19:23:37 +00001/*
2 * Dialog functions
3 *
Alexandre Julliard1e9ac791996-06-06 18:38:27 +00004 * Copyright 1993, 1994, 1996 Alexandre Julliard
Alexandre Julliard59730ae1996-03-24 16:20:51 +00005 */
Alexandre Julliard0e607781993-11-03 19:23:37 +00006
Alexandre Julliardda0cfb31996-12-01 17:17:47 +00007#include <ctype.h>
Patrik Stridvall1e1cf481998-10-17 12:56:00 +00008#include <errno.h>
Alexandre Julliard01d63461997-01-20 19:43:45 +00009#include <limits.h>
Alexandre Julliard8d24ae61994-04-05 21:42:43 +000010#include <stdlib.h>
Jeremy Whited3e22d92000-02-10 19:03:02 +000011#include <stdio.h>
Alexandre Julliard8d24ae61994-04-05 21:42:43 +000012#include <string.h>
Jeremy Whited3e22d92000-02-10 19:03:02 +000013#include "windef.h"
14#include "wingdi.h"
Marcus Meissner61afa331999-02-22 10:16:00 +000015#include "winuser.h"
Slava Monich3a170a11999-06-06 09:03:08 +000016#include "windowsx.h"
Marcus Meissner61afa331999-02-22 10:16:00 +000017#include "wine/winuser16.h"
18#include "wine/winbase16.h"
Dmitry Timoshkov04da8b82000-07-10 12:09:31 +000019#include "wine/unicode.h"
Alexandre Julliard0e607781993-11-03 19:23:37 +000020#include "dialog.h"
Alexandre Julliardda0cfb31996-12-01 17:17:47 +000021#include "drive.h"
Alexandre Julliarde2bfa4c1996-05-16 18:21:06 +000022#include "heap.h"
Alexandre Julliard0e607781993-11-03 19:23:37 +000023#include "win.h"
Alexandre Julliarde2abbb11995-03-19 17:39:39 +000024#include "ldt.h"
Alexandre Julliarddba420a1994-02-02 06:48:31 +000025#include "user.h"
Alexandre Julliard1e9ac791996-06-06 18:38:27 +000026#include "winproc.h"
Alexandre Julliard3f2abfa1994-08-16 15:43:11 +000027#include "message.h"
Patrik Stridvall6cc47d42000-03-08 18:26:56 +000028#include "queue.h"
Alexandre Julliard359f497e1999-07-04 16:02:24 +000029#include "debugtools.h"
Alexandre Julliard0e607781993-11-03 19:23:37 +000030
Jeremy Whited3e22d92000-02-10 19:03:02 +000031DEFAULT_DEBUG_CHANNEL(dialog);
Patrik Stridvallb4b9fae1999-04-19 14:56:29 +000032
Alexandre Julliard1e9ac791996-06-06 18:38:27 +000033
34 /* Dialog control information */
35typedef struct
36{
37 DWORD style;
38 DWORD exStyle;
Alexandre Julliardc7c217b1998-04-13 12:21:30 +000039 DWORD helpId;
Alexandre Julliard1e9ac791996-06-06 18:38:27 +000040 INT16 x;
41 INT16 y;
42 INT16 cx;
43 INT16 cy;
Alexandre Julliarda3960291999-02-26 11:11:13 +000044 UINT id;
Alexandre Julliard1e9ac791996-06-06 18:38:27 +000045 LPCSTR className;
46 LPCSTR windowName;
47 LPVOID data;
48} DLG_CONTROL_INFO;
49
50 /* Dialog template */
51typedef struct
52{
53 DWORD style;
54 DWORD exStyle;
Alexandre Julliardc7c217b1998-04-13 12:21:30 +000055 DWORD helpId;
Alexandre Julliard1e9ac791996-06-06 18:38:27 +000056 UINT16 nbItems;
57 INT16 x;
58 INT16 y;
59 INT16 cx;
60 INT16 cy;
61 LPCSTR menuName;
62 LPCSTR className;
63 LPCSTR caption;
64 WORD pointSize;
Alexandre Julliardc7c217b1998-04-13 12:21:30 +000065 WORD weight;
Alexandre Julliarda3960291999-02-26 11:11:13 +000066 BOOL italic;
Alexandre Julliard1e9ac791996-06-06 18:38:27 +000067 LPCSTR faceName;
Alexandre Julliarda3960291999-02-26 11:11:13 +000068 BOOL dialogEx;
Alexandre Julliard1e9ac791996-06-06 18:38:27 +000069} DLG_TEMPLATE;
70
Luc Tourangeau8e238d01999-05-29 14:19:42 +000071 /* Radio button group */
72typedef struct
73{
74 UINT firstID;
75 UINT lastID;
76 UINT checkID;
77} RADIOGROUP;
78
Alexandre Julliard0e607781993-11-03 19:23:37 +000079 /* Dialog base units */
Alexandre Julliard1e9ac791996-06-06 18:38:27 +000080static WORD xBaseUnit = 0, yBaseUnit = 0;
Alexandre Julliard0e607781993-11-03 19:23:37 +000081
Alexandre Julliard0e607781993-11-03 19:23:37 +000082/***********************************************************************
Slava Monich3a170a11999-06-06 09:03:08 +000083 * DIALOG_GetCharSizeFromDC
84 *
85 *
86 * Calculates the *true* average size of English characters in the
87 * specified font as oppposed to the one returned by GetTextMetrics.
Richard Cohen0ded0fe1999-09-05 12:25:33 +000088 *
89 * Latest: the X font driver will now compute a proper average width
90 * so this code can be removed
Slava Monich3a170a11999-06-06 09:03:08 +000091 */
92static BOOL DIALOG_GetCharSizeFromDC( HDC hDC, HFONT hFont, SIZE * pSize )
93{
94 BOOL Success = FALSE;
95 HFONT hFontPrev = 0;
96 pSize->cx = xBaseUnit;
97 pSize->cy = yBaseUnit;
98 if ( hDC )
99 {
100 /* select the font */
101 TEXTMETRICA tm;
102 memset(&tm,0,sizeof(tm));
103 if (hFont) hFontPrev = SelectFont(hDC,hFont);
104 if (GetTextMetricsA(hDC,&tm))
105 {
106 pSize->cx = tm.tmAveCharWidth;
107 pSize->cy = tm.tmHeight;
108
109 /* if variable width font */
110 if (tm.tmPitchAndFamily & TMPF_FIXED_PITCH)
111 {
112 SIZE total;
Richard Cohen0ded0fe1999-09-05 12:25:33 +0000113 const char* szAvgChars = "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ";
Slava Monich3a170a11999-06-06 09:03:08 +0000114
115 /* Calculate a true average as opposed to the one returned
116 * by tmAveCharWidth. This works better when dealing with
117 * proportional spaced fonts and (more important) that's
118 * how Microsoft's dialog creation code calculates the size
119 * of the font
120 */
121 if (GetTextExtentPointA(hDC,szAvgChars,sizeof(szAvgChars),&total))
122 {
123 /* round up */
124 pSize->cx = ((2*total.cx/sizeof(szAvgChars)) + 1)/2;
125 Success = TRUE;
126 }
127 }
128 else
129 {
130 Success = TRUE;
131 }
Richard Cohen0ded0fe1999-09-05 12:25:33 +0000132 /* Use the text metrics */
133 TRACE("Using tm: %ldx%ld (dlg: %dx%d) (%s)\n", tm.tmAveCharWidth, tm.tmHeight, pSize->cx, pSize->cy,
134 tm.tmPitchAndFamily & TMPF_FIXED_PITCH ? "variable" : "fixed");
135 pSize->cx = tm.tmAveCharWidth;
136 pSize->cy = tm.tmHeight;
Slava Monich3a170a11999-06-06 09:03:08 +0000137 }
Slava Monich3a170a11999-06-06 09:03:08 +0000138 /* select the original font */
139 if (hFontPrev) SelectFont(hDC,hFontPrev);
140 }
141 return (Success);
142}
143
Slava Monich3a170a11999-06-06 09:03:08 +0000144/***********************************************************************
145 * DIALOG_GetCharSize
146 *
Slava Monich3a170a11999-06-06 09:03:08 +0000147 * A convenient variant of DIALOG_GetCharSizeFromDC.
148 */
149static BOOL DIALOG_GetCharSize( HFONT hFont, SIZE * pSize )
150{
151 HDC hDC = GetDC(0);
152 BOOL Success = DIALOG_GetCharSizeFromDC( hDC, hFont, pSize );
153 ReleaseDC(0, hDC);
154 return Success;
155}
156
Slava Monich3a170a11999-06-06 09:03:08 +0000157/***********************************************************************
Alexandre Julliard0e607781993-11-03 19:23:37 +0000158 * DIALOG_Init
159 *
160 * Initialisation of the dialog manager.
161 */
Alexandre Julliarda3960291999-02-26 11:11:13 +0000162BOOL DIALOG_Init(void)
Alexandre Julliard0e607781993-11-03 19:23:37 +0000163{
Alexandre Julliard530ee841996-10-23 16:59:13 +0000164 HDC16 hdc;
Slava Monich3a170a11999-06-06 09:03:08 +0000165 SIZE size;
166
Alexandre Julliard0e607781993-11-03 19:23:37 +0000167 /* Calculate the dialog base units */
168
Alexandre Julliardb1bac321996-12-15 19:45:59 +0000169 if (!(hdc = CreateDC16( "DISPLAY", NULL, NULL, NULL ))) return FALSE;
Slava Monich3a170a11999-06-06 09:03:08 +0000170 if (!DIALOG_GetCharSizeFromDC( hdc, 0, &size )) return FALSE;
Alexandre Julliarda3960291999-02-26 11:11:13 +0000171 DeleteDC( hdc );
Slava Monich3a170a11999-06-06 09:03:08 +0000172 xBaseUnit = size.cx;
173 yBaseUnit = size.cy;
Alexandre Julliard7cbe6571995-01-09 18:21:16 +0000174
Alexandre Julliard359f497e1999-07-04 16:02:24 +0000175 TRACE("base units = %d,%d\n", xBaseUnit, yBaseUnit );
Alexandre Julliard0e607781993-11-03 19:23:37 +0000176 return TRUE;
177}
178
179
180/***********************************************************************
Alexandre Julliard1e9ac791996-06-06 18:38:27 +0000181 * DIALOG_GetControl16
Alexandre Julliard0e607781993-11-03 19:23:37 +0000182 *
183 * Return the class and text of the control pointed to by ptr,
Alexandre Julliard329f0681996-04-14 13:21:20 +0000184 * fill the header structure and return a pointer to the next control.
Alexandre Julliard0e607781993-11-03 19:23:37 +0000185 */
Alexandre Julliard1e9ac791996-06-06 18:38:27 +0000186static LPCSTR DIALOG_GetControl16( LPCSTR p, DLG_CONTROL_INFO *info )
Alexandre Julliard0e607781993-11-03 19:23:37 +0000187{
Alexandre Julliard1e9ac791996-06-06 18:38:27 +0000188 static char buffer[10];
Alexandre Julliard03468f71998-02-15 19:40:49 +0000189 int int_id;
Alexandre Julliardff8331e1995-09-18 11:19:54 +0000190
Alexandre Julliard1e9ac791996-06-06 18:38:27 +0000191 info->x = GET_WORD(p); p += sizeof(WORD);
192 info->y = GET_WORD(p); p += sizeof(WORD);
193 info->cx = GET_WORD(p); p += sizeof(WORD);
194 info->cy = GET_WORD(p); p += sizeof(WORD);
195 info->id = GET_WORD(p); p += sizeof(WORD);
196 info->style = GET_DWORD(p); p += sizeof(DWORD);
197 info->exStyle = 0;
Alexandre Julliard7e50df31994-08-06 11:22:41 +0000198
Alexandre Julliard0e607781993-11-03 19:23:37 +0000199 if (*p & 0x80)
200 {
Alexandre Julliard1e9ac791996-06-06 18:38:27 +0000201 switch((BYTE)*p)
202 {
203 case 0x80: strcpy( buffer, "BUTTON" ); break;
204 case 0x81: strcpy( buffer, "EDIT" ); break;
205 case 0x82: strcpy( buffer, "STATIC" ); break;
206 case 0x83: strcpy( buffer, "LISTBOX" ); break;
207 case 0x84: strcpy( buffer, "SCROLLBAR" ); break;
208 case 0x85: strcpy( buffer, "COMBOBOX" ); break;
209 default: buffer[0] = '\0'; break;
210 }
211 info->className = buffer;
Alexandre Julliardff8331e1995-09-18 11:19:54 +0000212 p++;
Alexandre Julliard0e607781993-11-03 19:23:37 +0000213 }
214 else
215 {
Alexandre Julliard1e9ac791996-06-06 18:38:27 +0000216 info->className = p;
Alexandre Julliard0e607781993-11-03 19:23:37 +0000217 p += strlen(p) + 1;
218 }
Alexandre Julliardff8331e1995-09-18 11:19:54 +0000219
Alexandre Julliard03468f71998-02-15 19:40:49 +0000220 int_id = ((BYTE)*p == 0xff);
221 if (int_id)
Alexandre Julliard940d58c1994-09-16 09:24:37 +0000222 {
223 /* Integer id, not documented (?). Only works for SS_ICON controls */
Alexandre Julliarda3960291999-02-26 11:11:13 +0000224 info->windowName = (LPCSTR)(UINT)GET_WORD(p+1);
Alexandre Julliard1e9ac791996-06-06 18:38:27 +0000225 p += 3;
Alexandre Julliard940d58c1994-09-16 09:24:37 +0000226 }
227 else
228 {
Alexandre Julliard1e9ac791996-06-06 18:38:27 +0000229 info->windowName = p;
230 p += strlen(p) + 1;
Alexandre Julliard7e50df31994-08-06 11:22:41 +0000231 }
Alexandre Julliard1e9ac791996-06-06 18:38:27 +0000232
Bernd Herd5b60bf02000-05-11 00:05:22 +0000233 if (*p)
234 {
235 /* Additional CTLDATA available for this control. */
236 info->data = SEGPTR_ALLOC(*p);
237 memcpy( info->data, p + 1, *p );
238 }
239 else info->data = NULL;
240
Alexandre Julliard1e9ac791996-06-06 18:38:27 +0000241 p += *p + 1;
242
Alexandre Julliard03468f71998-02-15 19:40:49 +0000243 if(int_id)
Alexandre Julliard359f497e1999-07-04 16:02:24 +0000244 TRACE(" %s %04x %d, %d, %d, %d, %d, %08lx, %08lx\n",
Alexandre Julliard03468f71998-02-15 19:40:49 +0000245 info->className, LOWORD(info->windowName),
246 info->id, info->x, info->y, info->cx, info->cy,
Bernd Herd5b60bf02000-05-11 00:05:22 +0000247 info->style, (DWORD)SEGPTR_GET(info->data) );
Alexandre Julliard03468f71998-02-15 19:40:49 +0000248 else
Alexandre Julliard359f497e1999-07-04 16:02:24 +0000249 TRACE(" %s '%s' %d, %d, %d, %d, %d, %08lx, %08lx\n",
Alexandre Julliard03468f71998-02-15 19:40:49 +0000250 info->className, info->windowName,
251 info->id, info->x, info->y, info->cx, info->cy,
Bernd Herd5b60bf02000-05-11 00:05:22 +0000252 info->style, (DWORD)SEGPTR_GET(info->data) );
Alexandre Julliard03468f71998-02-15 19:40:49 +0000253
Alexandre Julliard1e9ac791996-06-06 18:38:27 +0000254 return p;
Alexandre Julliard0e607781993-11-03 19:23:37 +0000255}
256
257
258/***********************************************************************
Alexandre Julliard1e9ac791996-06-06 18:38:27 +0000259 * DIALOG_GetControl32
Alexandre Julliard0e607781993-11-03 19:23:37 +0000260 *
Alexandre Julliard1e9ac791996-06-06 18:38:27 +0000261 * Return the class and text of the control pointed to by ptr,
262 * fill the header structure and return a pointer to the next control.
Alexandre Julliard0e607781993-11-03 19:23:37 +0000263 */
Alexandre Julliardc7c217b1998-04-13 12:21:30 +0000264static const WORD *DIALOG_GetControl32( const WORD *p, DLG_CONTROL_INFO *info,
Alexandre Julliarda3960291999-02-26 11:11:13 +0000265 BOOL dialogEx )
Alexandre Julliard0e607781993-11-03 19:23:37 +0000266{
Alexandre Julliardc7c217b1998-04-13 12:21:30 +0000267 if (dialogEx)
268 {
269 info->helpId = GET_DWORD(p); p += 2;
270 info->exStyle = GET_DWORD(p); p += 2;
271 info->style = GET_DWORD(p); p += 2;
272 }
273 else
274 {
275 info->helpId = 0;
276 info->style = GET_DWORD(p); p += 2;
277 info->exStyle = GET_DWORD(p); p += 2;
278 }
Alexandre Julliard1e9ac791996-06-06 18:38:27 +0000279 info->x = GET_WORD(p); p++;
280 info->y = GET_WORD(p); p++;
281 info->cx = GET_WORD(p); p++;
282 info->cy = GET_WORD(p); p++;
Alexandre Julliardc7c217b1998-04-13 12:21:30 +0000283
284 if (dialogEx)
285 {
286 /* id is a DWORD for DIALOGEX */
287 info->id = GET_DWORD(p);
288 p += 2;
289 }
290 else
291 {
292 info->id = GET_WORD(p);
293 p++;
294 }
Alexandre Julliard0e607781993-11-03 19:23:37 +0000295
Alexandre Julliard1e9ac791996-06-06 18:38:27 +0000296 if (GET_WORD(p) == 0xffff)
Alexandre Julliard0e607781993-11-03 19:23:37 +0000297 {
Alexandre Julliardc7c217b1998-04-13 12:21:30 +0000298 static const WCHAR class_names[6][10] =
Alexandre Julliard1e9ac791996-06-06 18:38:27 +0000299 {
Alexandre Julliardc7c217b1998-04-13 12:21:30 +0000300 { 'B','u','t','t','o','n', }, /* 0x80 */
301 { 'E','d','i','t', }, /* 0x81 */
302 { 'S','t','a','t','i','c', }, /* 0x82 */
303 { 'L','i','s','t','B','o','x', }, /* 0x83 */
304 { 'S','c','r','o','l','l','B','a','r', }, /* 0x84 */
305 { 'C','o','m','b','o','B','o','x', } /* 0x85 */
306 };
307 WORD id = GET_WORD(p+1);
308 if ((id >= 0x80) && (id <= 0x85))
309 info->className = (LPCSTR)class_names[id - 0x80];
310 else
311 {
312 info->className = NULL;
Alexandre Julliard359f497e1999-07-04 16:02:24 +0000313 ERR("Unknown built-in class id %04x\n", id );
Alexandre Julliard1e9ac791996-06-06 18:38:27 +0000314 }
Alexandre Julliard1e9ac791996-06-06 18:38:27 +0000315 p += 2;
Alexandre Julliardff8331e1995-09-18 11:19:54 +0000316 }
317 else
318 {
Alexandre Julliard1e9ac791996-06-06 18:38:27 +0000319 info->className = (LPCSTR)p;
Alexandre Julliarda3960291999-02-26 11:11:13 +0000320 p += lstrlenW( (LPCWSTR)p ) + 1;
Alexandre Julliard1e9ac791996-06-06 18:38:27 +0000321 }
Alexandre Julliard1e9ac791996-06-06 18:38:27 +0000322
Alexandre Julliardc7c217b1998-04-13 12:21:30 +0000323 if (GET_WORD(p) == 0xffff) /* Is it an integer id? */
Alexandre Julliard1e9ac791996-06-06 18:38:27 +0000324 {
Alexandre Julliarda3960291999-02-26 11:11:13 +0000325 info->windowName = (LPCSTR)(UINT)GET_WORD(p + 1);
Alexandre Julliard1e9ac791996-06-06 18:38:27 +0000326 p += 2;
Alexandre Julliard1e9ac791996-06-06 18:38:27 +0000327 }
328 else
329 {
330 info->windowName = (LPCSTR)p;
Alexandre Julliarda3960291999-02-26 11:11:13 +0000331 p += lstrlenW( (LPCWSTR)p ) + 1;
Alexandre Julliard1e9ac791996-06-06 18:38:27 +0000332 }
333
Alexandre Julliard359f497e1999-07-04 16:02:24 +0000334 TRACE(" %s %s %d, %d, %d, %d, %d, %08lx, %08lx, %08lx\n",
Alexandre Julliardc7c217b1998-04-13 12:21:30 +0000335 debugstr_w( (LPCWSTR)info->className ),
336 debugres_w( (LPCWSTR)info->windowName ),
337 info->id, info->x, info->y, info->cx, info->cy,
338 info->style, info->exStyle, info->helpId );
339
Alexandre Julliard1e9ac791996-06-06 18:38:27 +0000340 if (GET_WORD(p))
341 {
Alexandre Julliardc7c217b1998-04-13 12:21:30 +0000342 if (TRACE_ON(dialog))
343 {
344 WORD i, count = GET_WORD(p) / sizeof(WORD);
Alexandre Julliard359f497e1999-07-04 16:02:24 +0000345 TRACE(" BEGIN\n");
346 TRACE(" ");
347 for (i = 0; i < count; i++) DPRINTF( "%04x,", GET_WORD(p+i+1) );
348 DPRINTF("\n");
349 TRACE(" END\n" );
Alexandre Julliardc7c217b1998-04-13 12:21:30 +0000350 }
Alexandre Julliard1e9ac791996-06-06 18:38:27 +0000351 info->data = (LPVOID)(p + 1);
352 p += GET_WORD(p) / sizeof(WORD);
353 }
354 else info->data = NULL;
355 p++;
356
Alexandre Julliard1e9ac791996-06-06 18:38:27 +0000357 /* Next control is on dword boundary */
358 return (const WORD *)((((int)p) + 3) & ~3);
359}
360
361
362/***********************************************************************
363 * DIALOG_CreateControls
364 *
365 * Create the control windows for a dialog.
366 */
Alexandre Julliarda3960291999-02-26 11:11:13 +0000367static BOOL DIALOG_CreateControls( WND *pWnd, LPCSTR template,
Alexandre Julliardc7c217b1998-04-13 12:21:30 +0000368 const DLG_TEMPLATE *dlgTemplate,
Alexandre Julliarda3960291999-02-26 11:11:13 +0000369 HINSTANCE hInst, BOOL win32 )
Alexandre Julliard1e9ac791996-06-06 18:38:27 +0000370{
371 DIALOGINFO *dlgInfo = (DIALOGINFO *)pWnd->wExtra;
372 DLG_CONTROL_INFO info;
Alexandre Julliarda3960291999-02-26 11:11:13 +0000373 HWND hwndCtrl, hwndDefButton = 0;
374 INT items = dlgTemplate->nbItems;
Alexandre Julliard1e9ac791996-06-06 18:38:27 +0000375
Alexandre Julliard359f497e1999-07-04 16:02:24 +0000376 TRACE(" BEGIN\n" );
Alexandre Julliard1e9ac791996-06-06 18:38:27 +0000377 while (items--)
378 {
379 if (!win32)
380 {
381 HINSTANCE16 instance;
382 template = DIALOG_GetControl16( template, &info );
383 if (HIWORD(info.className) && !strcmp( info.className, "EDIT") &&
Alexandre Julliard139a4b11996-11-02 14:24:07 +0000384 ((pWnd->dwStyle & DS_LOCALEDIT) != DS_LOCALEDIT))
Alexandre Julliard1e9ac791996-06-06 18:38:27 +0000385 {
386 if (!dlgInfo->hDialogHeap)
387 {
388 dlgInfo->hDialogHeap = GlobalAlloc16(GMEM_FIXED, 0x10000);
389 if (!dlgInfo->hDialogHeap)
390 {
Alexandre Julliard359f497e1999-07-04 16:02:24 +0000391 ERR("Insufficient memory to create heap for edit control\n" );
Alexandre Julliard1e9ac791996-06-06 18:38:27 +0000392 continue;
393 }
Alexandre Julliarda3960291999-02-26 11:11:13 +0000394 LocalInit16(dlgInfo->hDialogHeap, 0, 0xffff);
Alexandre Julliard1e9ac791996-06-06 18:38:27 +0000395 }
396 instance = dlgInfo->hDialogHeap;
397 }
398 else instance = (HINSTANCE16)hInst;
399
400 hwndCtrl = CreateWindowEx16( info.exStyle | WS_EX_NOPARENTNOTIFY,
401 info.className, info.windowName,
402 info.style | WS_CHILD,
Francis Beaudeteb13dd41999-09-03 15:14:27 +0000403 MulDiv(info.x, dlgInfo->xBaseUnit, 4),
404 MulDiv(info.y, dlgInfo->yBaseUnit, 8),
405 MulDiv(info.cx, dlgInfo->xBaseUnit, 4),
406 MulDiv(info.cy, dlgInfo->yBaseUnit, 8),
Alexandre Julliardbf9130a1996-10-13 17:45:47 +0000407 pWnd->hwndSelf, (HMENU16)info.id,
Bernd Herd5b60bf02000-05-11 00:05:22 +0000408 instance, (LPVOID)SEGPTR_GET(info.data) );
409
410 if (info.data) SEGPTR_FREE(info.data);
Alexandre Julliard1e9ac791996-06-06 18:38:27 +0000411 }
412 else
413 {
Alexandre Julliardc7c217b1998-04-13 12:21:30 +0000414 template = (LPCSTR)DIALOG_GetControl32( (WORD *)template, &info,
415 dlgTemplate->dialogEx );
Alexandre Julliarda3960291999-02-26 11:11:13 +0000416 hwndCtrl = CreateWindowExW( info.exStyle | WS_EX_NOPARENTNOTIFY,
Alexandre Julliard1e9ac791996-06-06 18:38:27 +0000417 (LPCWSTR)info.className,
418 (LPCWSTR)info.windowName,
419 info.style | WS_CHILD,
Francis Beaudeteb13dd41999-09-03 15:14:27 +0000420 MulDiv(info.x, dlgInfo->xBaseUnit, 4),
421 MulDiv(info.y, dlgInfo->yBaseUnit, 8),
422 MulDiv(info.cx, dlgInfo->xBaseUnit, 4),
423 MulDiv(info.cy, dlgInfo->yBaseUnit, 8),
Alexandre Julliarda3960291999-02-26 11:11:13 +0000424 pWnd->hwndSelf, (HMENU)info.id,
Alexandre Julliard1e9ac791996-06-06 18:38:27 +0000425 hInst, info.data );
426 }
427 if (!hwndCtrl) return FALSE;
428
Alexandre Julliard1e9ac791996-06-06 18:38:27 +0000429 /* Send initialisation messages to the control */
Alexandre Julliarda3960291999-02-26 11:11:13 +0000430 if (dlgInfo->hUserFont) SendMessageA( hwndCtrl, WM_SETFONT,
431 (WPARAM)dlgInfo->hUserFont, 0 );
432 if (SendMessageA(hwndCtrl, WM_GETDLGCODE, 0, 0) & DLGC_DEFPUSHBUTTON)
Alexandre Julliard1e9ac791996-06-06 18:38:27 +0000433 {
434 /* If there's already a default push-button, set it back */
435 /* to normal and use this one instead. */
436 if (hwndDefButton)
Alexandre Julliarda3960291999-02-26 11:11:13 +0000437 SendMessageA( hwndDefButton, BM_SETSTYLE,
Alexandre Julliard1e9ac791996-06-06 18:38:27 +0000438 BS_PUSHBUTTON,FALSE );
439 hwndDefButton = hwndCtrl;
Alexandre Julliarda3960291999-02-26 11:11:13 +0000440 dlgInfo->idResult = GetWindowWord( hwndCtrl, GWW_ID );
Alexandre Julliard1e9ac791996-06-06 18:38:27 +0000441 }
442 }
Alexandre Julliard359f497e1999-07-04 16:02:24 +0000443 TRACE(" END\n" );
Alexandre Julliard1e9ac791996-06-06 18:38:27 +0000444 return TRUE;
445}
446
447
448/***********************************************************************
449 * DIALOG_ParseTemplate16
450 *
451 * Fill a DLG_TEMPLATE structure from the dialog template, and return
452 * a pointer to the first control.
453 */
454static LPCSTR DIALOG_ParseTemplate16( LPCSTR p, DLG_TEMPLATE * result )
455{
456 result->style = GET_DWORD(p); p += sizeof(DWORD);
457 result->exStyle = 0;
Pavel Roskin4b5f8761999-06-12 08:11:32 +0000458 result->nbItems = (unsigned char) *p++;
Alexandre Julliard1e9ac791996-06-06 18:38:27 +0000459 result->x = GET_WORD(p); p += sizeof(WORD);
460 result->y = GET_WORD(p); p += sizeof(WORD);
461 result->cx = GET_WORD(p); p += sizeof(WORD);
462 result->cy = GET_WORD(p); p += sizeof(WORD);
Alexandre Julliard359f497e1999-07-04 16:02:24 +0000463 TRACE("DIALOG %d, %d, %d, %d\n",
Alexandre Julliard1e9ac791996-06-06 18:38:27 +0000464 result->x, result->y, result->cx, result->cy );
Alexandre Julliard359f497e1999-07-04 16:02:24 +0000465 TRACE(" STYLE %08lx\n", result->style );
Alexandre Julliard1e9ac791996-06-06 18:38:27 +0000466
467 /* Get the menu name */
468
469 switch( (BYTE)*p )
470 {
471 case 0:
Alexandre Julliardff8331e1995-09-18 11:19:54 +0000472 result->menuName = 0;
473 p++;
Alexandre Julliard1e9ac791996-06-06 18:38:27 +0000474 break;
475 case 0xff:
Alexandre Julliarda3960291999-02-26 11:11:13 +0000476 result->menuName = (LPCSTR)(UINT)GET_WORD( p + 1 );
Alexandre Julliard1e9ac791996-06-06 18:38:27 +0000477 p += 3;
Alexandre Julliard359f497e1999-07-04 16:02:24 +0000478 TRACE(" MENU %04x\n", LOWORD(result->menuName) );
Alexandre Julliard1e9ac791996-06-06 18:38:27 +0000479 break;
480 default:
481 result->menuName = p;
Alexandre Julliard359f497e1999-07-04 16:02:24 +0000482 TRACE(" MENU '%s'\n", p );
Alexandre Julliard1e9ac791996-06-06 18:38:27 +0000483 p += strlen(p) + 1;
484 break;
Alexandre Julliard0e607781993-11-03 19:23:37 +0000485 }
Alexandre Julliard0e607781993-11-03 19:23:37 +0000486
Alexandre Julliardff8331e1995-09-18 11:19:54 +0000487 /* Get the class name */
488
Alexandre Julliard1e9ac791996-06-06 18:38:27 +0000489 if (*p)
490 {
491 result->className = p;
Alexandre Julliard359f497e1999-07-04 16:02:24 +0000492 TRACE(" CLASS '%s'\n", result->className );
Alexandre Julliard1e9ac791996-06-06 18:38:27 +0000493 }
Alexandre Julliardff8331e1995-09-18 11:19:54 +0000494 else result->className = DIALOG_CLASS_ATOM;
495 p += strlen(p) + 1;
496
497 /* Get the window caption */
498
Alexandre Julliard1e9ac791996-06-06 18:38:27 +0000499 result->caption = p;
Alexandre Julliardff8331e1995-09-18 11:19:54 +0000500 p += strlen(p) + 1;
Alexandre Julliard359f497e1999-07-04 16:02:24 +0000501 TRACE(" CAPTION '%s'\n", result->caption );
Alexandre Julliardff8331e1995-09-18 11:19:54 +0000502
503 /* Get the font name */
504
Alexandre Julliard329f0681996-04-14 13:21:20 +0000505 if (result->style & DS_SETFONT)
Alexandre Julliardff8331e1995-09-18 11:19:54 +0000506 {
Alexandre Julliard329f0681996-04-14 13:21:20 +0000507 result->pointSize = GET_WORD(p);
Alexandre Julliardff8331e1995-09-18 11:19:54 +0000508 p += sizeof(WORD);
Alexandre Julliard1e9ac791996-06-06 18:38:27 +0000509 result->faceName = p;
Alexandre Julliardff8331e1995-09-18 11:19:54 +0000510 p += strlen(p) + 1;
Alexandre Julliard359f497e1999-07-04 16:02:24 +0000511 TRACE(" FONT %d,'%s'\n",
Alexandre Julliard1e9ac791996-06-06 18:38:27 +0000512 result->pointSize, result->faceName );
513 }
514 return p;
515}
516
517
518/***********************************************************************
519 * DIALOG_ParseTemplate32
520 *
521 * Fill a DLG_TEMPLATE structure from the dialog template, and return
522 * a pointer to the first control.
523 */
524static LPCSTR DIALOG_ParseTemplate32( LPCSTR template, DLG_TEMPLATE * result )
525{
526 const WORD *p = (const WORD *)template;
527
Alexandre Julliardc7c217b1998-04-13 12:21:30 +0000528 result->style = GET_DWORD(p); p += 2;
529 if (result->style == 0xffff0001) /* DIALOGEX resource */
530 {
531 result->dialogEx = TRUE;
532 result->helpId = GET_DWORD(p); p += 2;
533 result->exStyle = GET_DWORD(p); p += 2;
534 result->style = GET_DWORD(p); p += 2;
535 }
536 else
537 {
538 result->dialogEx = FALSE;
539 result->helpId = 0;
540 result->exStyle = GET_DWORD(p); p += 2;
541 }
Alexandre Julliard1e9ac791996-06-06 18:38:27 +0000542 result->nbItems = GET_WORD(p); p++;
543 result->x = GET_WORD(p); p++;
544 result->y = GET_WORD(p); p++;
545 result->cx = GET_WORD(p); p++;
546 result->cy = GET_WORD(p); p++;
Alexandre Julliard359f497e1999-07-04 16:02:24 +0000547 TRACE("DIALOG%s %d, %d, %d, %d, %ld\n",
Alexandre Julliardc7c217b1998-04-13 12:21:30 +0000548 result->dialogEx ? "EX" : "", result->x, result->y,
549 result->cx, result->cy, result->helpId );
Alexandre Julliard359f497e1999-07-04 16:02:24 +0000550 TRACE(" STYLE 0x%08lx\n", result->style );
551 TRACE(" EXSTYLE 0x%08lx\n", result->exStyle );
Alexandre Julliard1e9ac791996-06-06 18:38:27 +0000552
553 /* Get the menu name */
554
555 switch(GET_WORD(p))
556 {
557 case 0x0000:
558 result->menuName = NULL;
559 p++;
560 break;
561 case 0xffff:
Alexandre Julliarda3960291999-02-26 11:11:13 +0000562 result->menuName = (LPCSTR)(UINT)GET_WORD( p + 1 );
Alexandre Julliard1e9ac791996-06-06 18:38:27 +0000563 p += 2;
Alexandre Julliard359f497e1999-07-04 16:02:24 +0000564 TRACE(" MENU %04x\n", LOWORD(result->menuName) );
Alexandre Julliard1e9ac791996-06-06 18:38:27 +0000565 break;
566 default:
567 result->menuName = (LPCSTR)p;
Alexandre Julliard359f497e1999-07-04 16:02:24 +0000568 TRACE(" MENU %s\n", debugstr_w( (LPCWSTR)p ));
Alexandre Julliarda3960291999-02-26 11:11:13 +0000569 p += lstrlenW( (LPCWSTR)p ) + 1;
Alexandre Julliard1e9ac791996-06-06 18:38:27 +0000570 break;
Alexandre Julliardff8331e1995-09-18 11:19:54 +0000571 }
572
Alexandre Julliard1e9ac791996-06-06 18:38:27 +0000573 /* Get the class name */
Alexandre Julliard0e607781993-11-03 19:23:37 +0000574
Alexandre Julliard1e9ac791996-06-06 18:38:27 +0000575 switch(GET_WORD(p))
576 {
577 case 0x0000:
578 result->className = DIALOG_CLASS_ATOM;
579 p++;
580 break;
581 case 0xffff:
Alexandre Julliarda3960291999-02-26 11:11:13 +0000582 result->className = (LPCSTR)(UINT)GET_WORD( p + 1 );
Alexandre Julliard1e9ac791996-06-06 18:38:27 +0000583 p += 2;
Alexandre Julliard359f497e1999-07-04 16:02:24 +0000584 TRACE(" CLASS %04x\n", LOWORD(result->className) );
Alexandre Julliard1e9ac791996-06-06 18:38:27 +0000585 break;
586 default:
587 result->className = (LPCSTR)p;
Alexandre Julliard359f497e1999-07-04 16:02:24 +0000588 TRACE(" CLASS %s\n", debugstr_w( (LPCWSTR)p ));
Alexandre Julliarda3960291999-02-26 11:11:13 +0000589 p += lstrlenW( (LPCWSTR)p ) + 1;
Alexandre Julliard1e9ac791996-06-06 18:38:27 +0000590 break;
591 }
Alexandre Julliard0e607781993-11-03 19:23:37 +0000592
Alexandre Julliard1e9ac791996-06-06 18:38:27 +0000593 /* Get the window caption */
Alexandre Julliardff8331e1995-09-18 11:19:54 +0000594
Alexandre Julliard1e9ac791996-06-06 18:38:27 +0000595 result->caption = (LPCSTR)p;
Alexandre Julliarda3960291999-02-26 11:11:13 +0000596 p += lstrlenW( (LPCWSTR)p ) + 1;
Alexandre Julliard359f497e1999-07-04 16:02:24 +0000597 TRACE(" CAPTION %s\n", debugstr_w( (LPCWSTR)result->caption ) );
Alexandre Julliardff8331e1995-09-18 11:19:54 +0000598
Alexandre Julliard1e9ac791996-06-06 18:38:27 +0000599 /* Get the font name */
Alexandre Julliardff8331e1995-09-18 11:19:54 +0000600
Alexandre Julliard329f0681996-04-14 13:21:20 +0000601 if (result->style & DS_SETFONT)
Alexandre Julliard1e9ac791996-06-06 18:38:27 +0000602 {
603 result->pointSize = GET_WORD(p);
604 p++;
Alexandre Julliardc7c217b1998-04-13 12:21:30 +0000605 if (result->dialogEx)
606 {
607 result->weight = GET_WORD(p); p++;
608 result->italic = LOBYTE(GET_WORD(p)); p++;
609 }
610 else
611 {
612 result->weight = FW_DONTCARE;
613 result->italic = FALSE;
614 }
Alexandre Julliard1e9ac791996-06-06 18:38:27 +0000615 result->faceName = (LPCSTR)p;
Alexandre Julliarda3960291999-02-26 11:11:13 +0000616 p += lstrlenW( (LPCWSTR)p ) + 1;
Alexandre Julliard359f497e1999-07-04 16:02:24 +0000617 TRACE(" FONT %d, %s, %d, %s\n",
Alexandre Julliardc7c217b1998-04-13 12:21:30 +0000618 result->pointSize, debugstr_w( (LPCWSTR)result->faceName ),
619 result->weight, result->italic ? "TRUE" : "FALSE" );
Alexandre Julliard1e9ac791996-06-06 18:38:27 +0000620 }
Alexandre Julliardc7c217b1998-04-13 12:21:30 +0000621
Alexandre Julliard1e9ac791996-06-06 18:38:27 +0000622 /* First control is on dword boundary */
623 return (LPCSTR)((((int)p) + 3) & ~3);
Alexandre Julliard0e607781993-11-03 19:23:37 +0000624}
Alexandre Julliard0e607781993-11-03 19:23:37 +0000625
626
627/***********************************************************************
Alexandre Julliard1e9ac791996-06-06 18:38:27 +0000628 * DIALOG_CreateIndirect
Alexandre Julliard0e607781993-11-03 19:23:37 +0000629 */
Alexandre Julliarda3960291999-02-26 11:11:13 +0000630HWND DIALOG_CreateIndirect( HINSTANCE hInst, LPCSTR dlgTemplate,
631 BOOL win32Template, HWND owner,
Alexandre Julliard9ea19e51997-01-01 17:29:55 +0000632 DLGPROC16 dlgProc, LPARAM param,
633 WINDOWPROCTYPE procType )
Alexandre Julliard0e607781993-11-03 19:23:37 +0000634{
Alexandre Julliardbf9130a1996-10-13 17:45:47 +0000635 HMENU16 hMenu = 0;
636 HFONT16 hFont = 0;
Alexandre Julliarda3960291999-02-26 11:11:13 +0000637 HWND hwnd;
638 RECT rect;
Alexandre Julliard0e607781993-11-03 19:23:37 +0000639 WND * wndPtr;
Alexandre Julliard1e9ac791996-06-06 18:38:27 +0000640 DLG_TEMPLATE template;
Alexandre Julliard0e607781993-11-03 19:23:37 +0000641 DIALOGINFO * dlgInfo;
642 WORD xUnit = xBaseUnit;
643 WORD yUnit = yBaseUnit;
Alexandre Julliard0e607781993-11-03 19:23:37 +0000644
Alexandre Julliarde399fc31993-11-24 17:08:56 +0000645 /* Parse dialog template */
646
647 if (!dlgTemplate) return 0;
Alexandre Julliard9ea19e51997-01-01 17:29:55 +0000648 if (win32Template)
Alexandre Julliard3051b641996-07-05 17:14:13 +0000649 dlgTemplate = DIALOG_ParseTemplate32( dlgTemplate, &template );
650 else
651 dlgTemplate = DIALOG_ParseTemplate16( dlgTemplate, &template );
Alexandre Julliard0e607781993-11-03 19:23:37 +0000652
653 /* Load menu */
654
Alexandre Julliard491502b1997-11-01 19:08:16 +0000655 if (template.menuName)
656 {
657 if (!win32Template)
Alexandre Julliard77b99181997-09-14 17:17:23 +0000658 {
659 LPSTR str = SEGPTR_STRDUP( template.menuName );
660 hMenu = LoadMenu16( hInst, SEGPTR_GET(str) );
661 SEGPTR_FREE( str );
Alexandre Julliard491502b1997-11-01 19:08:16 +0000662 }
Alexandre Julliarda3960291999-02-26 11:11:13 +0000663 else hMenu = LoadMenuW( hInst, (LPCWSTR)template.menuName );
Alexandre Julliard1e9ac791996-06-06 18:38:27 +0000664 }
Alexandre Julliard0e607781993-11-03 19:23:37 +0000665
666 /* Create custom font if needed */
667
Alexandre Julliard329f0681996-04-14 13:21:20 +0000668 if (template.style & DS_SETFONT)
Alexandre Julliard0e607781993-11-03 19:23:37 +0000669 {
Richard Cohen0ded0fe1999-09-05 12:25:33 +0000670 /* The font height must be negative as it is a point size */
671 /* and must be converted to pixels first */
Alexandre Julliard3ed37e01994-11-07 18:20:42 +0000672 /* (see CreateFont() documentation in the Windows SDK). */
Richard Cohen0ded0fe1999-09-05 12:25:33 +0000673 HDC dc = GetDC(0);
674 int pixels = template.pointSize * GetDeviceCaps(dc , LOGPIXELSY)/72;
675 ReleaseDC(0, dc);
Alexandre Julliardf90efa91998-06-14 15:24:15 +0000676
Alexandre Julliard3db94ef1997-09-28 17:43:24 +0000677 if (win32Template)
Richard Cohen0ded0fe1999-09-05 12:25:33 +0000678 hFont = CreateFontW( -pixels, 0, 0, 0, template.weight,
679 template.italic, FALSE, FALSE,
680 DEFAULT_CHARSET, 0, 0,
681 PROOF_QUALITY, FF_DONTCARE,
682 (LPCWSTR)template.faceName );
Alexandre Julliard3db94ef1997-09-28 17:43:24 +0000683 else
Richard Cohen0ded0fe1999-09-05 12:25:33 +0000684 hFont = CreateFont16( -pixels, 0, 0, 0, FW_DONTCARE,
685 FALSE, FALSE, FALSE,
686 DEFAULT_CHARSET, 0, 0,
Alexandre Julliardf90efa91998-06-14 15:24:15 +0000687 PROOF_QUALITY, FF_DONTCARE,
688 template.faceName );
Slava Monich3a170a11999-06-06 09:03:08 +0000689 if (hFont)
690 {
691 SIZE charSize;
Slava Moniche6dd5d12000-07-08 18:27:24 +0000692 if (DIALOG_GetCharSize(hFont,&charSize))
693 {
694 xUnit = charSize.cx;
695 yUnit = charSize.cy;
696 }
Slava Monich3a170a11999-06-06 09:03:08 +0000697 }
Richard Cohen0ded0fe1999-09-05 12:25:33 +0000698 TRACE("units = %d,%d\n", xUnit, yUnit );
Alexandre Julliard0e607781993-11-03 19:23:37 +0000699 }
Alexandre Julliarde399fc31993-11-24 17:08:56 +0000700
Alexandre Julliard1e9ac791996-06-06 18:38:27 +0000701 /* Create dialog main window */
Alexandre Julliard0e607781993-11-03 19:23:37 +0000702
Alexandre Julliardcdd09231994-01-12 11:12:51 +0000703 rect.left = rect.top = 0;
Francis Beaudeteb13dd41999-09-03 15:14:27 +0000704 rect.right = MulDiv(template.cx, xUnit, 4);
705 rect.bottom = MulDiv(template.cy, yUnit, 8);
Alexandre Julliard1e9ac791996-06-06 18:38:27 +0000706 if (template.style & DS_MODALFRAME)
707 template.exStyle |= WS_EX_DLGMODALFRAME;
Alexandre Julliarda3960291999-02-26 11:11:13 +0000708 AdjustWindowRectEx( &rect, template.style,
Alexandre Julliard1e9ac791996-06-06 18:38:27 +0000709 hMenu ? TRUE : FALSE , template.exStyle );
Alexandre Julliardff8331e1995-09-18 11:19:54 +0000710 rect.right -= rect.left;
711 rect.bottom -= rect.top;
Alexandre Julliardcdd09231994-01-12 11:12:51 +0000712
Alexandre Julliard1285c2f1996-05-06 16:06:24 +0000713 if ((INT16)template.x == CW_USEDEFAULT16)
Alexandre Julliardca22b331996-07-12 19:02:39 +0000714 {
Ulrich Weigandf03c9361999-07-10 13:08:50 +0000715 rect.left = rect.top = win32Template? CW_USEDEFAULT : CW_USEDEFAULT16;
Alexandre Julliardca22b331996-07-12 19:02:39 +0000716 }
Alexandre Julliardff8331e1995-09-18 11:19:54 +0000717 else
718 {
Dave Picklesfcc9d131998-10-10 15:52:46 +0000719 if (template.style & DS_CENTER)
720 {
Marcus Meissnerddca3151999-05-22 11:33:23 +0000721 rect.left = (GetSystemMetrics(SM_CXSCREEN) - rect.right) / 2;
722 rect.top = (GetSystemMetrics(SM_CYSCREEN) - rect.bottom) / 2;
Dave Picklesfcc9d131998-10-10 15:52:46 +0000723 }
724 else
725 {
Francis Beaudeteb13dd41999-09-03 15:14:27 +0000726 rect.left += MulDiv(template.x, xUnit, 4);
727 rect.top += MulDiv(template.y, yUnit, 8);
Dave Picklesfcc9d131998-10-10 15:52:46 +0000728 }
Alexandre Julliardda0cfb31996-12-01 17:17:47 +0000729 if ( !(template.style & WS_CHILD) )
730 {
731 INT16 dX, dY;
732
733 if( !(template.style & DS_ABSALIGN) )
Alexandre Julliarda3960291999-02-26 11:11:13 +0000734 ClientToScreen( owner, (POINT *)&rect );
Alexandre Julliardda0cfb31996-12-01 17:17:47 +0000735
736 /* try to fit it into the desktop */
737
Marcus Meissnerddca3151999-05-22 11:33:23 +0000738 if( (dX = rect.left + rect.right + GetSystemMetrics(SM_CXDLGFRAME)
739 - GetSystemMetrics(SM_CXSCREEN)) > 0 ) rect.left -= dX;
740 if( (dY = rect.top + rect.bottom + GetSystemMetrics(SM_CYDLGFRAME)
741 - GetSystemMetrics(SM_CYSCREEN)) > 0 ) rect.top -= dY;
Alexandre Julliardda0cfb31996-12-01 17:17:47 +0000742 if( rect.left < 0 ) rect.left = 0;
743 if( rect.top < 0 ) rect.top = 0;
744 }
Alexandre Julliardff8331e1995-09-18 11:19:54 +0000745 }
746
Ulrich Weigandf03c9361999-07-10 13:08:50 +0000747 if (!win32Template)
Alexandre Julliard3db94ef1997-09-28 17:43:24 +0000748 hwnd = CreateWindowEx16(template.exStyle, template.className,
749 template.caption, template.style & ~WS_VISIBLE,
750 rect.left, rect.top, rect.right, rect.bottom,
751 owner, hMenu, hInst, NULL );
752 else
Alexandre Julliarda3960291999-02-26 11:11:13 +0000753 hwnd = CreateWindowExW(template.exStyle, (LPCWSTR)template.className,
Alexandre Julliard1e9ac791996-06-06 18:38:27 +0000754 (LPCWSTR)template.caption,
755 template.style & ~WS_VISIBLE,
756 rect.left, rect.top, rect.right, rect.bottom,
757 owner, hMenu, hInst, NULL );
Alexandre Julliard3db94ef1997-09-28 17:43:24 +0000758
Alexandre Julliard0e607781993-11-03 19:23:37 +0000759 if (!hwnd)
760 {
Alexandre Julliarda3960291999-02-26 11:11:13 +0000761 if (hFont) DeleteObject( hFont );
762 if (hMenu) DestroyMenu( hMenu );
Alexandre Julliard0e607781993-11-03 19:23:37 +0000763 return 0;
764 }
Alexandre Julliard902da691995-11-05 14:39:02 +0000765 wndPtr = WIN_FindWndPtr( hwnd );
Alexandre Julliard3051b641996-07-05 17:14:13 +0000766 wndPtr->flags |= WIN_ISDIALOG;
Alexandre Julliardc7c217b1998-04-13 12:21:30 +0000767 wndPtr->helpContext = template.helpId;
Alexandre Julliard902da691995-11-05 14:39:02 +0000768
Alexandre Julliard0e607781993-11-03 19:23:37 +0000769 /* Initialise dialog extra data */
770
Alexandre Julliard1e9ac791996-06-06 18:38:27 +0000771 dlgInfo = (DIALOGINFO *)wndPtr->wExtra;
Marcus Meissner03479f81999-01-28 10:06:38 +0000772 WINPROC_SetProc( &dlgInfo->dlgProc, (WNDPROC16)dlgProc, procType, WIN_PROC_WINDOW );
Alexandre Julliard0e607781993-11-03 19:23:37 +0000773 dlgInfo->hUserFont = hFont;
774 dlgInfo->hMenu = hMenu;
775 dlgInfo->xBaseUnit = xUnit;
776 dlgInfo->yBaseUnit = yUnit;
Alexandre Julliarddf2673b1997-03-29 17:20:20 +0000777 dlgInfo->msgResult = 0;
Alexandre Julliard7e6ae4b1996-12-08 19:25:27 +0000778 dlgInfo->idResult = 0;
Alexandre Julliarddf2673b1997-03-29 17:20:20 +0000779 dlgInfo->flags = 0;
Alexandre Julliard1e9ac791996-06-06 18:38:27 +0000780 dlgInfo->hDialogHeap = 0;
781
Alexandre Julliardda0cfb31996-12-01 17:17:47 +0000782 if (dlgInfo->hUserFont)
Alexandre Julliarda3960291999-02-26 11:11:13 +0000783 SendMessageA( hwnd, WM_SETFONT, (WPARAM)dlgInfo->hUserFont, 0 );
Alexandre Julliardda0cfb31996-12-01 17:17:47 +0000784
Alexandre Julliard1e9ac791996-06-06 18:38:27 +0000785 /* Create controls */
786
Alexandre Julliardc7c217b1998-04-13 12:21:30 +0000787 if (DIALOG_CreateControls( wndPtr, dlgTemplate, &template,
788 hInst, win32Template ))
Alexandre Julliard1e9ac791996-06-06 18:38:27 +0000789 {
Adrian Thurston00442ba1999-10-23 16:48:05 +0000790 HWND hwndPreInitFocus;
791
792 /* Send initialisation messages and set focus */
Alexandre Julliarddf2673b1997-03-29 17:20:20 +0000793
Alexandre Julliarda3960291999-02-26 11:11:13 +0000794 dlgInfo->hwndFocus = GetNextDlgTabItem( hwnd, 0, FALSE );
Alexandre Julliard77b99181997-09-14 17:17:23 +0000795
Adrian Thurston00442ba1999-10-23 16:48:05 +0000796 hwndPreInitFocus = GetFocus();
Alexandre Julliarda3960291999-02-26 11:11:13 +0000797 if (SendMessageA( hwnd, WM_INITDIALOG, (WPARAM)dlgInfo->hwndFocus, param ))
Sheri Steevesa4b73d42000-06-15 01:00:42 +0000798 {
799 /* check where the focus is again, some controls status might have changed in
800 WM_INITDIALOG */
801 dlgInfo->hwndFocus = GetNextDlgTabItem( hwnd, 0, FALSE);
Alexandre Julliarda3960291999-02-26 11:11:13 +0000802 SetFocus( dlgInfo->hwndFocus );
Sheri Steevesa4b73d42000-06-15 01:00:42 +0000803 }
804 else
805 {
806 /* If the dlgproc has returned FALSE (indicating handling of keyboard focus)
807 but the focus has not changed, set the focus where we expect it. */
Gerard Patel2b37da62000-04-23 19:57:50 +0000808 if ( (wndPtr->dwStyle & WS_VISIBLE) && ( GetFocus() == hwndPreInitFocus ) )
Sheri Steevesa4b73d42000-06-15 01:00:42 +0000809 {
810 dlgInfo->hwndFocus = GetNextDlgTabItem( hwnd, 0, FALSE);
Gerard Patel2b37da62000-04-23 19:57:50 +0000811 SetFocus( dlgInfo->hwndFocus );
Sheri Steevesa4b73d42000-06-15 01:00:42 +0000812 }
813 }
Alexandre Julliard77b99181997-09-14 17:17:23 +0000814
815 if (template.style & WS_VISIBLE && !(wndPtr->dwStyle & WS_VISIBLE))
816 {
Alexandre Julliarda3960291999-02-26 11:11:13 +0000817 ShowWindow( hwnd, SW_SHOWNORMAL ); /* SW_SHOW doesn't always work */
818 UpdateWindow( hwnd );
Alexandre Julliard77b99181997-09-14 17:17:23 +0000819 }
Francois Boisvert6b1b41c1999-03-14 17:25:32 +0000820 WIN_ReleaseWndPtr(wndPtr);
Alexandre Julliard77b99181997-09-14 17:17:23 +0000821 return hwnd;
Alexandre Julliard1e9ac791996-06-06 18:38:27 +0000822 }
Francois Boisvert6b1b41c1999-03-14 17:25:32 +0000823 WIN_ReleaseWndPtr(wndPtr);
Alexandre Julliarda3960291999-02-26 11:11:13 +0000824 if( IsWindow(hwnd) ) DestroyWindow( hwnd );
Alexandre Julliarddf2673b1997-03-29 17:20:20 +0000825 return 0;
Alexandre Julliard0e607781993-11-03 19:23:37 +0000826}
827
828
829/***********************************************************************
Alexandre Julliard1e9ac791996-06-06 18:38:27 +0000830 * CreateDialog16 (USER.89)
831 */
Alexandre Julliard670cdc41997-08-24 16:00:30 +0000832HWND16 WINAPI CreateDialog16( HINSTANCE16 hInst, SEGPTR dlgTemplate,
833 HWND16 owner, DLGPROC16 dlgProc )
Alexandre Julliard1e9ac791996-06-06 18:38:27 +0000834{
835 return CreateDialogParam16( hInst, dlgTemplate, owner, dlgProc, 0 );
836}
837
838
839/***********************************************************************
840 * CreateDialogParam16 (USER.241)
841 */
Alexandre Julliard670cdc41997-08-24 16:00:30 +0000842HWND16 WINAPI CreateDialogParam16( HINSTANCE16 hInst, SEGPTR dlgTemplate,
843 HWND16 owner, DLGPROC16 dlgProc,
844 LPARAM param )
Alexandre Julliard1e9ac791996-06-06 18:38:27 +0000845{
846 HWND16 hwnd = 0;
Alexandre Julliard8cc3a5e1996-08-11 15:49:51 +0000847 HRSRC16 hRsrc;
Alexandre Julliard1e9ac791996-06-06 18:38:27 +0000848 HGLOBAL16 hmem;
849 LPCVOID data;
850
Alexandre Julliard359f497e1999-07-04 16:02:24 +0000851 TRACE("%04x,%08lx,%04x,%08lx,%ld\n",
Alexandre Julliard1e9ac791996-06-06 18:38:27 +0000852 hInst, (DWORD)dlgTemplate, owner, (DWORD)dlgProc, param );
853
Alexandre Julliardc7c217b1998-04-13 12:21:30 +0000854 if (!(hRsrc = FindResource16( hInst, dlgTemplate, RT_DIALOG16 ))) return 0;
Alexandre Julliard18f92e71996-07-17 20:02:21 +0000855 if (!(hmem = LoadResource16( hInst, hRsrc ))) return 0;
856 if (!(data = LockResource16( hmem ))) hwnd = 0;
Alexandre Julliard1e9ac791996-06-06 18:38:27 +0000857 else hwnd = CreateDialogIndirectParam16( hInst, data, owner,
858 dlgProc, param );
Alexandre Julliard18f92e71996-07-17 20:02:21 +0000859 FreeResource16( hmem );
Alexandre Julliard1e9ac791996-06-06 18:38:27 +0000860 return hwnd;
861}
862
Alexandre Julliard1e9ac791996-06-06 18:38:27 +0000863/***********************************************************************
Patrik Stridvall2d6457c2000-03-28 20:22:59 +0000864 * CreateDialogParamA (USER32.73)
Alexandre Julliard1e9ac791996-06-06 18:38:27 +0000865 */
Alexandre Julliarda3960291999-02-26 11:11:13 +0000866HWND WINAPI CreateDialogParamA( HINSTANCE hInst, LPCSTR name,
867 HWND owner, DLGPROC dlgProc,
Alexandre Julliard670cdc41997-08-24 16:00:30 +0000868 LPARAM param )
Alexandre Julliard1e9ac791996-06-06 18:38:27 +0000869{
Ove Kaaven483c5481999-07-18 15:29:09 +0000870 HANDLE hrsrc = FindResourceA( hInst, name, RT_DIALOGA );
871 if (!hrsrc) return 0;
872 return CreateDialogIndirectParamA( hInst,
873 (LPVOID)LoadResource(hInst, hrsrc),
874 owner, dlgProc, param );
Alexandre Julliard1e9ac791996-06-06 18:38:27 +0000875}
876
877
878/***********************************************************************
Patrik Stridvall2d6457c2000-03-28 20:22:59 +0000879 * CreateDialogParamW (USER32.74)
Alexandre Julliard1e9ac791996-06-06 18:38:27 +0000880 */
Alexandre Julliarda3960291999-02-26 11:11:13 +0000881HWND WINAPI CreateDialogParamW( HINSTANCE hInst, LPCWSTR name,
882 HWND owner, DLGPROC dlgProc,
Alexandre Julliard670cdc41997-08-24 16:00:30 +0000883 LPARAM param )
Alexandre Julliard1e9ac791996-06-06 18:38:27 +0000884{
Alexandre Julliarda3960291999-02-26 11:11:13 +0000885 HANDLE hrsrc = FindResourceW( hInst, name, RT_DIALOGW );
Alexandre Julliard1e9ac791996-06-06 18:38:27 +0000886 if (!hrsrc) return 0;
Alexandre Julliarda3960291999-02-26 11:11:13 +0000887 return CreateDialogIndirectParamW( hInst,
888 (LPVOID)LoadResource(hInst, hrsrc),
Alexandre Julliard1e9ac791996-06-06 18:38:27 +0000889 owner, dlgProc, param );
890}
891
892
893/***********************************************************************
894 * CreateDialogIndirect16 (USER.219)
895 */
Alexandre Julliard670cdc41997-08-24 16:00:30 +0000896HWND16 WINAPI CreateDialogIndirect16( HINSTANCE16 hInst, LPCVOID dlgTemplate,
897 HWND16 owner, DLGPROC16 dlgProc )
Alexandre Julliard1e9ac791996-06-06 18:38:27 +0000898{
899 return CreateDialogIndirectParam16( hInst, dlgTemplate, owner, dlgProc, 0);
900}
901
902
903/***********************************************************************
904 * CreateDialogIndirectParam16 (USER.242)
905 */
Alexandre Julliard670cdc41997-08-24 16:00:30 +0000906HWND16 WINAPI CreateDialogIndirectParam16( HINSTANCE16 hInst,
907 LPCVOID dlgTemplate,
908 HWND16 owner, DLGPROC16 dlgProc,
909 LPARAM param )
Alexandre Julliard1e9ac791996-06-06 18:38:27 +0000910{
Alexandre Julliard9ea19e51997-01-01 17:29:55 +0000911 return DIALOG_CreateIndirect( hInst, dlgTemplate, FALSE, owner,
Alexandre Julliard3051b641996-07-05 17:14:13 +0000912 dlgProc, param, WIN_PROC_16 );
Alexandre Julliard1e9ac791996-06-06 18:38:27 +0000913}
914
915
916/***********************************************************************
Patrik Stridvall2d6457c2000-03-28 20:22:59 +0000917 * CreateDialogIndirectParamA (USER32.69)
Alexandre Julliard1e9ac791996-06-06 18:38:27 +0000918 */
Alexandre Julliarda3960291999-02-26 11:11:13 +0000919HWND WINAPI CreateDialogIndirectParamA( HINSTANCE hInst,
Alexandre Julliard670cdc41997-08-24 16:00:30 +0000920 LPCVOID dlgTemplate,
Alexandre Julliarda3960291999-02-26 11:11:13 +0000921 HWND owner, DLGPROC dlgProc,
Alexandre Julliard670cdc41997-08-24 16:00:30 +0000922 LPARAM param )
Alexandre Julliard1e9ac791996-06-06 18:38:27 +0000923{
Alexandre Julliard9ea19e51997-01-01 17:29:55 +0000924 return DIALOG_CreateIndirect( hInst, dlgTemplate, TRUE, owner,
Alexandre Julliard3051b641996-07-05 17:14:13 +0000925 (DLGPROC16)dlgProc, param, WIN_PROC_32A );
Alexandre Julliard1e9ac791996-06-06 18:38:27 +0000926}
927
Juergen Schmied84b358d1998-10-11 15:38:35 +0000928/***********************************************************************
Patrik Stridvall2d6457c2000-03-28 20:22:59 +0000929 * CreateDialogIndirectParamAorW (USER32.71)
Juergen Schmied84b358d1998-10-11 15:38:35 +0000930 */
Alexandre Julliarda3960291999-02-26 11:11:13 +0000931HWND WINAPI CreateDialogIndirectParamAorW( HINSTANCE hInst,
Juergen Schmied84b358d1998-10-11 15:38:35 +0000932 LPCVOID dlgTemplate,
Alexandre Julliarda3960291999-02-26 11:11:13 +0000933 HWND owner, DLGPROC dlgProc,
Juergen Schmied84b358d1998-10-11 15:38:35 +0000934 LPARAM param )
Alexandre Julliard359f497e1999-07-04 16:02:24 +0000935{ FIXME("assume WIN_PROC_32W\n");
Juergen Schmied84b358d1998-10-11 15:38:35 +0000936 return DIALOG_CreateIndirect( hInst, dlgTemplate, TRUE, owner,
937 (DLGPROC16)dlgProc, param, WIN_PROC_32W );
938}
Alexandre Julliard1e9ac791996-06-06 18:38:27 +0000939
940/***********************************************************************
Patrik Stridvall2d6457c2000-03-28 20:22:59 +0000941 * CreateDialogIndirectParamW (USER32.72)
Alexandre Julliard1e9ac791996-06-06 18:38:27 +0000942 */
Alexandre Julliarda3960291999-02-26 11:11:13 +0000943HWND WINAPI CreateDialogIndirectParamW( HINSTANCE hInst,
Alexandre Julliard670cdc41997-08-24 16:00:30 +0000944 LPCVOID dlgTemplate,
Alexandre Julliarda3960291999-02-26 11:11:13 +0000945 HWND owner, DLGPROC dlgProc,
Alexandre Julliard670cdc41997-08-24 16:00:30 +0000946 LPARAM param )
Alexandre Julliard1e9ac791996-06-06 18:38:27 +0000947{
Alexandre Julliard9ea19e51997-01-01 17:29:55 +0000948 return DIALOG_CreateIndirect( hInst, dlgTemplate, TRUE, owner,
Alexandre Julliard3051b641996-07-05 17:14:13 +0000949 (DLGPROC16)dlgProc, param, WIN_PROC_32W );
Alexandre Julliard1e9ac791996-06-06 18:38:27 +0000950}
951
952
953/***********************************************************************
Alexandre Julliarde399fc31993-11-24 17:08:56 +0000954 * DIALOG_DoDialogBox
Alexandre Julliard0e607781993-11-03 19:23:37 +0000955 */
Alexandre Julliarda3960291999-02-26 11:11:13 +0000956INT DIALOG_DoDialogBox( HWND hwnd, HWND owner )
Alexandre Julliard0e607781993-11-03 19:23:37 +0000957{
Alexandre Julliard0e607781993-11-03 19:23:37 +0000958 WND * wndPtr;
959 DIALOGINFO * dlgInfo;
Alexandre Julliarda3960291999-02-26 11:11:13 +0000960 MSG msg;
961 INT retval;
Alexandre Julliard0e607781993-11-03 19:23:37 +0000962
Alexandre Julliardaca05781994-10-17 18:12:41 +0000963 /* Owner must be a top-level window */
Alexandre Julliarde2991ea1995-07-29 13:09:43 +0000964 owner = WIN_GetTopParent( owner );
Alexandre Julliarde399fc31993-11-24 17:08:56 +0000965 if (!(wndPtr = WIN_FindWndPtr( hwnd ))) return -1;
Alexandre Julliard0e607781993-11-03 19:23:37 +0000966 dlgInfo = (DIALOGINFO *)wndPtr->wExtra;
Alexandre Julliarde399fc31993-11-24 17:08:56 +0000967
Gerard Patel902f9c61999-02-14 11:22:03 +0000968 if (!dlgInfo->flags & DF_END) /* was EndDialog called in WM_INITDIALOG ? */
Alexandre Julliard0e607781993-11-03 19:23:37 +0000969 {
Alexandre Julliarda3960291999-02-26 11:11:13 +0000970 EnableWindow( owner, FALSE );
971 ShowWindow( hwnd, SW_SHOW );
Ulrich Weigand2faf2cf1999-12-10 03:47:13 +0000972 while (MSG_InternalGetMessage(QMSG_WIN32A, &msg, hwnd, owner, MSGF_DIALOGBOX,
Francis Beaudet7ed1af31999-08-15 16:58:03 +0000973 PM_REMOVE, !(wndPtr->dwStyle & DS_NOIDLEMSG), NULL ))
Gerard Patel902f9c61999-02-14 11:22:03 +0000974 {
Alexandre Julliarda3960291999-02-26 11:11:13 +0000975 if (!IsDialogMessageA( hwnd, &msg))
Gerard Patel902f9c61999-02-14 11:22:03 +0000976 {
Alexandre Julliarda3960291999-02-26 11:11:13 +0000977 TranslateMessage( &msg );
978 DispatchMessageA( &msg );
Gerard Patel902f9c61999-02-14 11:22:03 +0000979 }
980 if (dlgInfo->flags & DF_END) break;
981 }
Alexandre Julliarda3960291999-02-26 11:11:13 +0000982 EnableWindow( owner, TRUE );
Alexandre Julliard0e607781993-11-03 19:23:37 +0000983 }
Gerard Patel902f9c61999-02-14 11:22:03 +0000984 retval = dlgInfo->idResult;
Francois Boisvert6b1b41c1999-03-14 17:25:32 +0000985 WIN_ReleaseWndPtr(wndPtr);
Alexandre Julliarda3960291999-02-26 11:11:13 +0000986 DestroyWindow( hwnd );
Alexandre Julliard0e607781993-11-03 19:23:37 +0000987 return retval;
988}
989
990
991/***********************************************************************
Alexandre Julliard1e9ac791996-06-06 18:38:27 +0000992 * DialogBox16 (USER.87)
Alexandre Julliarde399fc31993-11-24 17:08:56 +0000993 */
Alexandre Julliard670cdc41997-08-24 16:00:30 +0000994INT16 WINAPI DialogBox16( HINSTANCE16 hInst, SEGPTR dlgTemplate,
995 HWND16 owner, DLGPROC16 dlgProc )
Alexandre Julliarde399fc31993-11-24 17:08:56 +0000996{
Alexandre Julliard1e9ac791996-06-06 18:38:27 +0000997 return DialogBoxParam16( hInst, dlgTemplate, owner, dlgProc, 0 );
Alexandre Julliarde399fc31993-11-24 17:08:56 +0000998}
999
1000
1001/***********************************************************************
Alexandre Julliard1e9ac791996-06-06 18:38:27 +00001002 * DialogBoxParam16 (USER.239)
Alexandre Julliarde399fc31993-11-24 17:08:56 +00001003 */
Alexandre Julliard670cdc41997-08-24 16:00:30 +00001004INT16 WINAPI DialogBoxParam16( HINSTANCE16 hInst, SEGPTR template,
1005 HWND16 owner, DLGPROC16 dlgProc, LPARAM param )
Alexandre Julliarde399fc31993-11-24 17:08:56 +00001006{
Alexandre Julliard1e9ac791996-06-06 18:38:27 +00001007 HWND16 hwnd = CreateDialogParam16( hInst, template, owner, dlgProc, param);
1008 if (hwnd) return (INT16)DIALOG_DoDialogBox( hwnd, owner );
1009 return -1;
1010}
1011
1012
1013/***********************************************************************
Patrik Stridvall2d6457c2000-03-28 20:22:59 +00001014 * DialogBoxParamA (USER32.139)
Alexandre Julliard1e9ac791996-06-06 18:38:27 +00001015 */
Alexandre Julliarda3960291999-02-26 11:11:13 +00001016INT WINAPI DialogBoxParamA( HINSTANCE hInst, LPCSTR name,
1017 HWND owner, DLGPROC dlgProc, LPARAM param )
Alexandre Julliard1e9ac791996-06-06 18:38:27 +00001018{
Alexandre Julliarda3960291999-02-26 11:11:13 +00001019 HWND hwnd = CreateDialogParamA( hInst, name, owner, dlgProc, param );
Alexandre Julliard3f2abfa1994-08-16 15:43:11 +00001020 if (hwnd) return DIALOG_DoDialogBox( hwnd, owner );
Alexandre Julliarde399fc31993-11-24 17:08:56 +00001021 return -1;
1022}
1023
1024
1025/***********************************************************************
Patrik Stridvall2d6457c2000-03-28 20:22:59 +00001026 * DialogBoxParamW (USER32.140)
Alexandre Julliarde399fc31993-11-24 17:08:56 +00001027 */
Alexandre Julliarda3960291999-02-26 11:11:13 +00001028INT WINAPI DialogBoxParamW( HINSTANCE hInst, LPCWSTR name,
1029 HWND owner, DLGPROC dlgProc, LPARAM param )
Alexandre Julliarde399fc31993-11-24 17:08:56 +00001030{
Alexandre Julliarda3960291999-02-26 11:11:13 +00001031 HWND hwnd = CreateDialogParamW( hInst, name, owner, dlgProc, param );
Alexandre Julliard1e9ac791996-06-06 18:38:27 +00001032 if (hwnd) return DIALOG_DoDialogBox( hwnd, owner );
1033 return -1;
Alexandre Julliarde399fc31993-11-24 17:08:56 +00001034}
1035
1036
1037/***********************************************************************
Alexandre Julliard1e9ac791996-06-06 18:38:27 +00001038 * DialogBoxIndirect16 (USER.218)
Alexandre Julliarde399fc31993-11-24 17:08:56 +00001039 */
Alexandre Julliard670cdc41997-08-24 16:00:30 +00001040INT16 WINAPI DialogBoxIndirect16( HINSTANCE16 hInst, HANDLE16 dlgTemplate,
1041 HWND16 owner, DLGPROC16 dlgProc )
Alexandre Julliarde399fc31993-11-24 17:08:56 +00001042{
Alexandre Julliard1e9ac791996-06-06 18:38:27 +00001043 return DialogBoxIndirectParam16( hInst, dlgTemplate, owner, dlgProc, 0 );
1044}
Alexandre Julliarde399fc31993-11-24 17:08:56 +00001045
Alexandre Julliard1e9ac791996-06-06 18:38:27 +00001046
1047/***********************************************************************
1048 * DialogBoxIndirectParam16 (USER.240)
1049 */
Alexandre Julliard670cdc41997-08-24 16:00:30 +00001050INT16 WINAPI DialogBoxIndirectParam16( HINSTANCE16 hInst, HANDLE16 dlgTemplate,
1051 HWND16 owner, DLGPROC16 dlgProc,
1052 LPARAM param )
Alexandre Julliard1e9ac791996-06-06 18:38:27 +00001053{
1054 HWND16 hwnd;
1055 LPCVOID ptr;
1056
1057 if (!(ptr = GlobalLock16( dlgTemplate ))) return -1;
1058 hwnd = CreateDialogIndirectParam16( hInst, ptr, owner, dlgProc, param );
Alexandre Julliard1285c2f1996-05-06 16:06:24 +00001059 GlobalUnlock16( dlgTemplate );
Alexandre Julliard1e9ac791996-06-06 18:38:27 +00001060 if (hwnd) return (INT16)DIALOG_DoDialogBox( hwnd, owner );
1061 return -1;
1062}
1063
1064
1065/***********************************************************************
Patrik Stridvall2d6457c2000-03-28 20:22:59 +00001066 * DialogBoxIndirectParamA (USER32.136)
Alexandre Julliard1e9ac791996-06-06 18:38:27 +00001067 */
Alexandre Julliarda3960291999-02-26 11:11:13 +00001068INT WINAPI DialogBoxIndirectParamA(HINSTANCE hInstance, LPCVOID template,
1069 HWND owner, DLGPROC dlgProc,
Alexandre Julliard670cdc41997-08-24 16:00:30 +00001070 LPARAM param )
Alexandre Julliard1e9ac791996-06-06 18:38:27 +00001071{
Alexandre Julliarda3960291999-02-26 11:11:13 +00001072 HWND hwnd = CreateDialogIndirectParamA( hInstance, template,
Alexandre Julliard1e9ac791996-06-06 18:38:27 +00001073 owner, dlgProc, param );
Alexandre Julliard3f2abfa1994-08-16 15:43:11 +00001074 if (hwnd) return DIALOG_DoDialogBox( hwnd, owner );
Alexandre Julliarde399fc31993-11-24 17:08:56 +00001075 return -1;
1076}
1077
Alexandre Julliard7cbe6571995-01-09 18:21:16 +00001078
Alexandre Julliard3ed37e01994-11-07 18:20:42 +00001079/***********************************************************************
Patrik Stridvall2d6457c2000-03-28 20:22:59 +00001080 * DialogBoxIndirectParamW (USER32.138)
Alexandre Julliard0e607781993-11-03 19:23:37 +00001081 */
Alexandre Julliarda3960291999-02-26 11:11:13 +00001082INT WINAPI DialogBoxIndirectParamW(HINSTANCE hInstance, LPCVOID template,
1083 HWND owner, DLGPROC dlgProc,
Alexandre Julliard670cdc41997-08-24 16:00:30 +00001084 LPARAM param )
Alexandre Julliard1e9ac791996-06-06 18:38:27 +00001085{
Alexandre Julliarda3960291999-02-26 11:11:13 +00001086 HWND hwnd = CreateDialogIndirectParamW( hInstance, template,
Alexandre Julliard1e9ac791996-06-06 18:38:27 +00001087 owner, dlgProc, param );
1088 if (hwnd) return DIALOG_DoDialogBox( hwnd, owner );
1089 return -1;
1090}
1091
Juergen Schmieda4d7ca02000-01-04 00:29:44 +00001092/***********************************************************************
1093 * DialogBoxIndirectParamAorW (USER32.138)
1094 */
1095INT WINAPI DialogBoxIndirectParamAorW(HINSTANCE hInstance, LPCVOID template,
1096 HWND owner, DLGPROC dlgProc,
1097 LPARAM param, DWORD x )
1098{
1099 HWND hwnd;
1100 FIXME("0x%08x %p 0x%08x %p 0x%08lx 0x%08lx\n",
1101 hInstance, template, owner, dlgProc, param, x);
1102 hwnd = CreateDialogIndirectParamW( hInstance, template,
1103 owner, dlgProc, param );
1104 if (hwnd) return DIALOG_DoDialogBox( hwnd, owner );
1105 return -1;
1106}
Alexandre Julliard1e9ac791996-06-06 18:38:27 +00001107
1108/***********************************************************************
Andreas Mohr01f84261999-03-19 16:49:30 +00001109 * EndDialog16 (USER.88)
Alexandre Julliard1e9ac791996-06-06 18:38:27 +00001110 */
Alexandre Julliard670cdc41997-08-24 16:00:30 +00001111BOOL16 WINAPI EndDialog16( HWND16 hwnd, INT16 retval )
Alexandre Julliardf0cbfa01997-02-15 14:29:56 +00001112{
Alexandre Julliarda3960291999-02-26 11:11:13 +00001113 return EndDialog( hwnd, retval );
Alexandre Julliardf0cbfa01997-02-15 14:29:56 +00001114}
1115
1116
1117/***********************************************************************
Patrik Stridvall2d6457c2000-03-28 20:22:59 +00001118 * EndDialog (USER32.173)
Alexandre Julliardf0cbfa01997-02-15 14:29:56 +00001119 */
Alexandre Julliarda3960291999-02-26 11:11:13 +00001120BOOL WINAPI EndDialog( HWND hwnd, INT retval )
Alexandre Julliard0e607781993-11-03 19:23:37 +00001121{
1122 WND * wndPtr = WIN_FindWndPtr( hwnd );
Andreas Mohrbeae14d2000-02-12 13:21:23 +00001123 DIALOGINFO * dlgInfo;
Abey George3336f481999-10-13 15:45:23 +00001124 HWND hOwner = 0;
Alexandre Julliarddf2673b1997-03-29 17:20:20 +00001125
Alexandre Julliard359f497e1999-07-04 16:02:24 +00001126 TRACE("%04x %d\n", hwnd, retval );
Alexandre Julliarddf2673b1997-03-29 17:20:20 +00001127
Andreas Mohrbeae14d2000-02-12 13:21:23 +00001128 if (!wndPtr)
1129 {
1130 ERR("got invalid window handle (%04x); buggy app !?\n", hwnd);
Andreas Mohr1c20b392000-02-20 19:17:35 +00001131 return FALSE;
Andreas Mohrbeae14d2000-02-12 13:21:23 +00001132 }
1133
1134 if ((dlgInfo = (DIALOGINFO *)wndPtr->wExtra))
Alexandre Julliarddf2673b1997-03-29 17:20:20 +00001135 {
1136 dlgInfo->idResult = retval;
1137 dlgInfo->flags |= DF_END;
1138 }
Andreas Mohr01f84261999-03-19 16:49:30 +00001139
Abey George3336f481999-10-13 15:45:23 +00001140 if(wndPtr->owner)
1141 hOwner = WIN_GetTopParent( wndPtr->owner->hwndSelf );
1142
1143 /* Enable the owner first */
1144 if (hOwner && !IsWindowEnabled(hOwner))
1145 EnableWindow( hOwner, TRUE );
1146
1147 /* Windows sets the focus to the dialog itself in EndDialog */
Abey George15c58c41999-08-07 14:10:04 +00001148
1149 if (IsChild(hwnd, GetFocus()))
1150 SetFocus(wndPtr->hwndSelf);
1151
Abey George3336f481999-10-13 15:45:23 +00001152 /* Don't have to send a ShowWindow(SW_HIDE), just do
1153 SetWindowPos with SWP_HIDEWINDOW as done in Windows */
Andreas Mohr01f84261999-03-19 16:49:30 +00001154
Abey George3336f481999-10-13 15:45:23 +00001155 SetWindowPos(hwnd, (HWND)0, 0, 0, 0, 0, SWP_NOMOVE | SWP_NOSIZE
1156 | SWP_NOZORDER | SWP_NOACTIVATE | SWP_HIDEWINDOW);
Stephane Lussier18613bb1999-07-24 10:18:02 +00001157
Francois Boisvert6b1b41c1999-03-14 17:25:32 +00001158 WIN_ReleaseWndPtr(wndPtr);
Abey George3336f481999-10-13 15:45:23 +00001159
Alexandre Julliard0c126c71996-02-18 18:44:41 +00001160 return TRUE;
Alexandre Julliard0e607781993-11-03 19:23:37 +00001161}
1162
1163
1164/***********************************************************************
Norman Stevensa83d0651998-10-12 07:25:35 +00001165 * DIALOG_IsAccelerator
1166 */
Alexandre Julliarda3960291999-02-26 11:11:13 +00001167static BOOL DIALOG_IsAccelerator( HWND hwnd, HWND hwndDlg, WPARAM vKey )
Norman Stevensa83d0651998-10-12 07:25:35 +00001168{
Alexandre Julliarda3960291999-02-26 11:11:13 +00001169 HWND hwndControl = hwnd;
1170 HWND hwndNext;
Norman Stevensa83d0651998-10-12 07:25:35 +00001171 WND *wndPtr;
Alexandre Julliarda3960291999-02-26 11:11:13 +00001172 BOOL RetVal = FALSE;
1173 INT dlgCode;
Norman Stevensa83d0651998-10-12 07:25:35 +00001174
Norman Stevensa83d0651998-10-12 07:25:35 +00001175 do
1176 {
1177 wndPtr = WIN_FindWndPtr( hwndControl );
Francis Beaudetf91e6d01999-03-25 13:22:42 +00001178 if ( (wndPtr != NULL) &&
1179 ((wndPtr->dwStyle & (WS_VISIBLE | WS_DISABLED)) == WS_VISIBLE) )
Norman Stevensa83d0651998-10-12 07:25:35 +00001180 {
Alexandre Julliarda3960291999-02-26 11:11:13 +00001181 dlgCode = SendMessageA( hwndControl, WM_GETDLGCODE, 0, 0 );
Francis Beaudetf91e6d01999-03-25 13:22:42 +00001182 if ( (dlgCode & (DLGC_BUTTON | DLGC_STATIC)) &&
1183 (wndPtr->text!=NULL))
Norman Stevensa83d0651998-10-12 07:25:35 +00001184 {
1185 /* find the accelerator key */
Dmitry Timoshkov04da8b82000-07-10 12:09:31 +00001186 LPWSTR p = wndPtr->text - 2;
Norman Stevensa83d0651998-10-12 07:25:35 +00001187 do
1188 {
Dmitry Timoshkov04da8b82000-07-10 12:09:31 +00001189 p = strchrW( p + 2, '&' );
Norman Stevensa83d0651998-10-12 07:25:35 +00001190 }
1191 while (p != NULL && p[1] == '&');
1192
1193 /* and check if it's the one we're looking for */
Dmitry Timoshkov04da8b82000-07-10 12:09:31 +00001194 /* FIXME: convert vKey to unicode */
1195 if (p != NULL && toupperW( p[1] ) == (WCHAR)toupper( vKey ) )
Norman Stevensa83d0651998-10-12 07:25:35 +00001196 {
1197 if ((dlgCode & DLGC_STATIC) ||
1198 (wndPtr->dwStyle & 0x0f) == BS_GROUPBOX )
1199 {
1200 /* set focus to the control */
Alexandre Julliarda3960291999-02-26 11:11:13 +00001201 SendMessageA( hwndDlg, WM_NEXTDLGCTL,
Norman Stevensa83d0651998-10-12 07:25:35 +00001202 hwndControl, 1);
1203 /* and bump it on to next */
Alexandre Julliarda3960291999-02-26 11:11:13 +00001204 SendMessageA( hwndDlg, WM_NEXTDLGCTL, 0, 0);
Norman Stevensa83d0651998-10-12 07:25:35 +00001205 }
Dmitry Timoshkovb7bb42d1999-12-25 22:52:44 +00001206 else if (dlgCode & DLGC_BUTTON)
1207 {
Dmitry Timoshkov6fb62f52000-01-29 22:09:40 +00001208 /* send BM_CLICK message to the control */
1209 SendMessageA( hwndControl, BM_CLICK, 0, 0 );
Dmitry Timoshkovb7bb42d1999-12-25 22:52:44 +00001210 }
Dmitry Timoshkovf92a7771999-12-05 23:51:15 +00001211
Norman Stevensa83d0651998-10-12 07:25:35 +00001212 RetVal = TRUE;
Abey George15c58c41999-08-07 14:10:04 +00001213 WIN_ReleaseWndPtr(wndPtr);
Norman Stevensa83d0651998-10-12 07:25:35 +00001214 break;
1215 }
1216 }
Norman Stevens460881c1999-02-28 09:59:32 +00001217 hwndNext = GetWindow( hwndControl, GW_CHILD );
Norman Stevensa83d0651998-10-12 07:25:35 +00001218 }
Norman Stevens460881c1999-02-28 09:59:32 +00001219 else
1220 {
1221 hwndNext = 0;
1222 }
Francois Boisvert6b1b41c1999-03-14 17:25:32 +00001223 WIN_ReleaseWndPtr(wndPtr);
NF Stevense1f67b91998-11-08 16:44:41 +00001224 if (!hwndNext)
1225 {
Alexandre Julliarda3960291999-02-26 11:11:13 +00001226 hwndNext = GetWindow( hwndControl, GW_HWNDNEXT );
NF Stevense1f67b91998-11-08 16:44:41 +00001227 }
Marcus Meissner6f7797b1999-09-03 16:39:36 +00001228 while (!hwndNext && hwndControl)
NF Stevense1f67b91998-11-08 16:44:41 +00001229 {
Alexandre Julliarda3960291999-02-26 11:11:13 +00001230 hwndControl = GetParent( hwndControl );
NF Stevense1f67b91998-11-08 16:44:41 +00001231 if (hwndControl == hwndDlg)
1232 {
Abey George15c58c41999-08-07 14:10:04 +00001233 if(hwnd==hwndDlg){ /* prevent endless loop */
1234 hwndNext=hwnd;
1235 break;
1236 }
Alexandre Julliarda3960291999-02-26 11:11:13 +00001237 hwndNext = GetWindow( hwndDlg, GW_CHILD );
NF Stevense1f67b91998-11-08 16:44:41 +00001238 }
1239 else
1240 {
Alexandre Julliarda3960291999-02-26 11:11:13 +00001241 hwndNext = GetWindow( hwndControl, GW_HWNDNEXT );
NF Stevense1f67b91998-11-08 16:44:41 +00001242 }
1243 }
1244 hwndControl = hwndNext;
Norman Stevensa83d0651998-10-12 07:25:35 +00001245 }
Marcus Meissner6f7797b1999-09-03 16:39:36 +00001246 while (hwndControl && (hwndControl != hwnd));
Dmitry Timoshkovf92a7771999-12-05 23:51:15 +00001247
Norman Stevensa83d0651998-10-12 07:25:35 +00001248 return RetVal;
1249}
1250
Andrew Lewycky0ceb2552000-03-19 14:20:52 +00001251/***********************************************************************
1252 * DIALOG_FindMsgDestination
1253 *
1254 * The messages that IsDialogMessage send may not go to the dialog
1255 * calling IsDialogMessage if that dialog is a child, and it has the
1256 * DS_CONTROL style set.
1257 * We propagate up until we hit a that does not have DS_CONTROL, or
1258 * whose parent is not a dialog.
1259 *
1260 * This is undocumented behaviour.
1261 */
1262static HWND DIALOG_FindMsgDestination( HWND hwndDlg )
1263{
1264 while (GetWindowLongA(hwndDlg, GWL_STYLE) & DS_CONTROL)
1265 {
1266 WND *pParent;
1267 HWND hParent = GetParent(hwndDlg);
1268 if (!hParent) break;
1269
1270 pParent = WIN_FindWndPtr(hParent);
1271 if (!pParent) break;
1272
1273 if (!(pParent->flags & WIN_ISDIALOG))
1274 {
1275 WIN_ReleaseWndPtr(pParent);
1276 break;
1277 }
1278 WIN_ReleaseWndPtr(pParent);
1279
1280 hwndDlg = hParent;
1281 }
1282
1283 return hwndDlg;
1284}
Norman Stevensa83d0651998-10-12 07:25:35 +00001285
1286/***********************************************************************
Alexandre Julliardf0cbfa01997-02-15 14:29:56 +00001287 * DIALOG_IsDialogMessage
Alexandre Julliard0e607781993-11-03 19:23:37 +00001288 */
Alexandre Julliarda3960291999-02-26 11:11:13 +00001289static BOOL DIALOG_IsDialogMessage( HWND hwnd, HWND hwndDlg,
1290 UINT message, WPARAM wParam,
1291 LPARAM lParam, BOOL *translate,
1292 BOOL *dispatch, INT dlgCode )
Alexandre Julliard0e607781993-11-03 19:23:37 +00001293{
Alexandre Julliardf0cbfa01997-02-15 14:29:56 +00001294 *translate = *dispatch = FALSE;
Alexandre Julliard0e607781993-11-03 19:23:37 +00001295
Alexandre Julliard641ee761997-08-04 16:34:36 +00001296 if (message == WM_PAINT)
1297 {
1298 /* Apparently, we have to handle this one as well */
1299 *dispatch = TRUE;
1300 return TRUE;
1301 }
1302
Alexandre Julliardaca05781994-10-17 18:12:41 +00001303 /* Only the key messages get special processing */
Alexandre Julliardf0cbfa01997-02-15 14:29:56 +00001304 if ((message != WM_KEYDOWN) &&
1305 (message != WM_SYSCHAR) &&
1306 (message != WM_CHAR))
Alexandre Julliard7cbe6571995-01-09 18:21:16 +00001307 return FALSE;
1308
Alexandre Julliard7cbe6571995-01-09 18:21:16 +00001309 if (dlgCode & DLGC_WANTMESSAGE)
Alexandre Julliard0e607781993-11-03 19:23:37 +00001310 {
Alexandre Julliard23946ad1997-06-16 17:43:53 +00001311 *translate = *dispatch = TRUE;
Alexandre Julliard7cbe6571995-01-09 18:21:16 +00001312 return TRUE;
Alexandre Julliard0e607781993-11-03 19:23:37 +00001313 }
Alexandre Julliardaca05781994-10-17 18:12:41 +00001314
Andrew Lewycky0ceb2552000-03-19 14:20:52 +00001315 hwndDlg = DIALOG_FindMsgDestination(hwndDlg);
1316
Alexandre Julliardf0cbfa01997-02-15 14:29:56 +00001317 switch(message)
Alexandre Julliard0e607781993-11-03 19:23:37 +00001318 {
Alexandre Julliardaca05781994-10-17 18:12:41 +00001319 case WM_KEYDOWN:
Alexandre Julliardf0cbfa01997-02-15 14:29:56 +00001320 switch(wParam)
Alexandre Julliardaca05781994-10-17 18:12:41 +00001321 {
1322 case VK_TAB:
1323 if (!(dlgCode & DLGC_WANTTAB))
1324 {
Alexandre Julliarda3960291999-02-26 11:11:13 +00001325 SendMessageA( hwndDlg, WM_NEXTDLGCTL,
1326 (GetKeyState(VK_SHIFT) & 0x8000), 0 );
Alexandre Julliardaca05781994-10-17 18:12:41 +00001327 return TRUE;
1328 }
1329 break;
1330
1331 case VK_RIGHT:
1332 case VK_DOWN:
Alexandre Julliardaca05781994-10-17 18:12:41 +00001333 case VK_LEFT:
1334 case VK_UP:
1335 if (!(dlgCode & DLGC_WANTARROWS))
1336 {
Alexandre Julliarda3960291999-02-26 11:11:13 +00001337 BOOL fPrevious = (wParam == VK_LEFT || wParam == VK_UP);
1338 HWND hwndNext =
1339 GetNextDlgGroupItem (hwndDlg, GetFocus(), fPrevious );
1340 SendMessageA( hwndDlg, WM_NEXTDLGCTL, hwndNext, 1 );
Alexandre Julliardaca05781994-10-17 18:12:41 +00001341 return TRUE;
1342 }
1343 break;
1344
1345 case VK_ESCAPE:
Alexandre Julliarda3960291999-02-26 11:11:13 +00001346 SendMessageA( hwndDlg, WM_COMMAND, IDCANCEL,
1347 (LPARAM)GetDlgItem( hwndDlg, IDCANCEL ) );
Norman Stevensa83d0651998-10-12 07:25:35 +00001348 return TRUE;
Alexandre Julliardaca05781994-10-17 18:12:41 +00001349
1350 case VK_RETURN:
1351 {
Alexandre Julliard2d93d001996-05-21 15:01:41 +00001352 DWORD dw = SendMessage16( hwndDlg, DM_GETDEFID, 0, 0 );
Alexandre Julliardaca05781994-10-17 18:12:41 +00001353 if (HIWORD(dw) == DC_HASDEFID)
Norman Stevensa83d0651998-10-12 07:25:35 +00001354 {
Alexandre Julliarda3960291999-02-26 11:11:13 +00001355 SendMessageA( hwndDlg, WM_COMMAND,
Alexandre Julliard2d93d001996-05-21 15:01:41 +00001356 MAKEWPARAM( LOWORD(dw), BN_CLICKED ),
Alexandre Julliarda3960291999-02-26 11:11:13 +00001357 (LPARAM)GetDlgItem(hwndDlg, LOWORD(dw)));
Norman Stevensa83d0651998-10-12 07:25:35 +00001358 }
Alexandre Julliardaf0bae51995-10-03 17:06:08 +00001359 else
Norman Stevensa83d0651998-10-12 07:25:35 +00001360 {
Alexandre Julliarda3960291999-02-26 11:11:13 +00001361 SendMessageA( hwndDlg, WM_COMMAND, IDOK,
1362 (LPARAM)GetDlgItem( hwndDlg, IDOK ) );
Norman Stevensa83d0651998-10-12 07:25:35 +00001363
1364 }
Alexandre Julliardaca05781994-10-17 18:12:41 +00001365 }
Norman Stevensa83d0651998-10-12 07:25:35 +00001366 return TRUE;
Alexandre Julliardaca05781994-10-17 18:12:41 +00001367 }
Norman Stevensa83d0651998-10-12 07:25:35 +00001368 *translate = TRUE;
1369 break; /* case WM_KEYDOWN */
Alexandre Julliardaca05781994-10-17 18:12:41 +00001370
Alexandre Julliardaca05781994-10-17 18:12:41 +00001371 case WM_CHAR:
Norman Stevensa83d0651998-10-12 07:25:35 +00001372 if (dlgCode & DLGC_WANTCHARS) break;
1373 /* drop through */
Alexandre Julliardaca05781994-10-17 18:12:41 +00001374
1375 case WM_SYSCHAR:
Norman Stevensa83d0651998-10-12 07:25:35 +00001376 if (DIALOG_IsAccelerator( hwnd, hwndDlg, wParam ))
1377 {
1378 /* don't translate or dispatch */
1379 return TRUE;
1380 }
Alexandre Julliardaca05781994-10-17 18:12:41 +00001381 break;
Alexandre Julliard0e607781993-11-03 19:23:37 +00001382 }
Alexandre Julliardaca05781994-10-17 18:12:41 +00001383
Alexandre Julliardf0cbfa01997-02-15 14:29:56 +00001384 /* If we get here, the message has not been treated specially */
1385 /* and can be sent to its destination window. */
1386 *dispatch = TRUE;
Alexandre Julliard0e607781993-11-03 19:23:37 +00001387 return TRUE;
1388}
1389
1390
Alexandre Julliardf0cbfa01997-02-15 14:29:56 +00001391/***********************************************************************
1392 * IsDialogMessage16 (USER.90)
1393 */
Ove Kaaven748acbb1998-11-01 15:27:12 +00001394BOOL16 WINAPI WIN16_IsDialogMessage16( HWND16 hwndDlg, SEGPTR msg16 )
Alexandre Julliardf0cbfa01997-02-15 14:29:56 +00001395{
Ove Kaaven748acbb1998-11-01 15:27:12 +00001396 LPMSG16 msg = PTR_SEG_TO_LIN(msg16);
Alexandre Julliarda3960291999-02-26 11:11:13 +00001397 BOOL ret, translate, dispatch;
David Grantedb77971999-11-07 21:02:17 +00001398 INT dlgCode = 0;
Alexandre Julliardf0cbfa01997-02-15 14:29:56 +00001399
1400 if ((hwndDlg != msg->hwnd) && !IsChild16( hwndDlg, msg->hwnd ))
1401 return FALSE;
1402
David Grantedb77971999-11-07 21:02:17 +00001403 if ((msg->message == WM_KEYDOWN) ||
1404 (msg->message == WM_SYSCHAR) ||
1405 (msg->message == WM_CHAR))
1406 {
1407 dlgCode = SendMessage16( msg->hwnd, WM_GETDLGCODE, 0, (LPARAM)msg16);
1408 }
Alexandre Julliardf0cbfa01997-02-15 14:29:56 +00001409 ret = DIALOG_IsDialogMessage( msg->hwnd, hwndDlg, msg->message,
1410 msg->wParam, msg->lParam,
Norman Stevensa83d0651998-10-12 07:25:35 +00001411 &translate, &dispatch, dlgCode );
Alexandre Julliardf0cbfa01997-02-15 14:29:56 +00001412 if (translate) TranslateMessage16( msg );
1413 if (dispatch) DispatchMessage16( msg );
1414 return ret;
1415}
1416
1417
Ove Kaaven748acbb1998-11-01 15:27:12 +00001418BOOL16 WINAPI IsDialogMessage16( HWND16 hwndDlg, LPMSG16 msg )
1419{
1420 LPMSG16 msg16 = SEGPTR_NEW(MSG16);
Alexandre Julliarda3960291999-02-26 11:11:13 +00001421 BOOL ret;
Ove Kaaven748acbb1998-11-01 15:27:12 +00001422
1423 *msg16 = *msg;
1424 ret = WIN16_IsDialogMessage16( hwndDlg, SEGPTR_GET(msg16) );
1425 SEGPTR_FREE(msg16);
1426 return ret;
1427}
1428
Alexandre Julliardf0cbfa01997-02-15 14:29:56 +00001429/***********************************************************************
Patrik Stridvall2d6457c2000-03-28 20:22:59 +00001430 * IsDialogMessageA (USER32.342)
Alexandre Julliardf0cbfa01997-02-15 14:29:56 +00001431 */
Alexandre Julliarda3960291999-02-26 11:11:13 +00001432BOOL WINAPI IsDialogMessageA( HWND hwndDlg, LPMSG msg )
Alexandre Julliardf0cbfa01997-02-15 14:29:56 +00001433{
Alexandre Julliarda3960291999-02-26 11:11:13 +00001434 BOOL ret, translate, dispatch;
David Grantedb77971999-11-07 21:02:17 +00001435 INT dlgCode = 0;
Alexandre Julliardf0cbfa01997-02-15 14:29:56 +00001436
Alexandre Julliarda3960291999-02-26 11:11:13 +00001437 if ((hwndDlg != msg->hwnd) && !IsChild( hwndDlg, msg->hwnd ))
Alexandre Julliardf0cbfa01997-02-15 14:29:56 +00001438 return FALSE;
1439
David Grantedb77971999-11-07 21:02:17 +00001440 if ((msg->message == WM_KEYDOWN) ||
1441 (msg->message == WM_SYSCHAR) ||
1442 (msg->message == WM_CHAR))
1443 {
1444 dlgCode = SendMessageA( msg->hwnd, WM_GETDLGCODE, 0, (LPARAM)msg);
1445 }
Alexandre Julliardf0cbfa01997-02-15 14:29:56 +00001446 ret = DIALOG_IsDialogMessage( msg->hwnd, hwndDlg, msg->message,
1447 msg->wParam, msg->lParam,
Norman Stevensa83d0651998-10-12 07:25:35 +00001448 &translate, &dispatch, dlgCode );
Alexandre Julliarda3960291999-02-26 11:11:13 +00001449 if (translate) TranslateMessage( msg );
1450 if (dispatch) DispatchMessageA( msg );
Alexandre Julliardf0cbfa01997-02-15 14:29:56 +00001451 return ret;
1452}
1453
1454
1455/***********************************************************************
Patrik Stridvall2d6457c2000-03-28 20:22:59 +00001456 * IsDialogMessageW (USER32.343)
Alexandre Julliardf0cbfa01997-02-15 14:29:56 +00001457 */
Alexandre Julliarda3960291999-02-26 11:11:13 +00001458BOOL WINAPI IsDialogMessageW( HWND hwndDlg, LPMSG msg )
Alexandre Julliardf0cbfa01997-02-15 14:29:56 +00001459{
Alexandre Julliarda3960291999-02-26 11:11:13 +00001460 BOOL ret, translate, dispatch;
David Grantedb77971999-11-07 21:02:17 +00001461 INT dlgCode = 0;
Alexandre Julliardf0cbfa01997-02-15 14:29:56 +00001462
Alexandre Julliarda3960291999-02-26 11:11:13 +00001463 if ((hwndDlg != msg->hwnd) && !IsChild( hwndDlg, msg->hwnd ))
Alexandre Julliardf0cbfa01997-02-15 14:29:56 +00001464 return FALSE;
1465
David Grantedb77971999-11-07 21:02:17 +00001466 if ((msg->message == WM_KEYDOWN) ||
1467 (msg->message == WM_SYSCHAR) ||
1468 (msg->message == WM_CHAR))
1469 {
1470 dlgCode = SendMessageW( msg->hwnd, WM_GETDLGCODE, 0, (LPARAM)msg);
1471 }
Alexandre Julliardf0cbfa01997-02-15 14:29:56 +00001472 ret = DIALOG_IsDialogMessage( msg->hwnd, hwndDlg, msg->message,
1473 msg->wParam, msg->lParam,
Norman Stevensa83d0651998-10-12 07:25:35 +00001474 &translate, &dispatch, dlgCode );
Alexandre Julliarda3960291999-02-26 11:11:13 +00001475 if (translate) TranslateMessage( msg );
1476 if (dispatch) DispatchMessageW( msg );
Alexandre Julliardf0cbfa01997-02-15 14:29:56 +00001477 return ret;
1478}
1479
1480
Patrik Stridvall54fe8382000-04-06 20:21:16 +00001481/***********************************************************************
Alexandre Julliard01d63461997-01-20 19:43:45 +00001482 * GetDlgCtrlID16 (USER.277)
Alexandre Julliard0e607781993-11-03 19:23:37 +00001483 */
Alexandre Julliard670cdc41997-08-24 16:00:30 +00001484INT16 WINAPI GetDlgCtrlID16( HWND16 hwnd )
Alexandre Julliard01d63461997-01-20 19:43:45 +00001485{
1486 WND *wndPtr = WIN_FindWndPtr(hwnd);
Francois Boisvert6b1b41c1999-03-14 17:25:32 +00001487 INT16 retvalue;
1488
1489 if (!wndPtr) return 0;
1490
1491 retvalue = wndPtr->wIDmenu;
1492 WIN_ReleaseWndPtr(wndPtr);
1493 return retvalue;
Alexandre Julliard01d63461997-01-20 19:43:45 +00001494}
1495
1496
Patrik Stridvall54fe8382000-04-06 20:21:16 +00001497/***********************************************************************
Patrik Stridvall2d6457c2000-03-28 20:22:59 +00001498 * GetDlgCtrlID (USER32.234)
Alexandre Julliard01d63461997-01-20 19:43:45 +00001499 */
Alexandre Julliarda3960291999-02-26 11:11:13 +00001500INT WINAPI GetDlgCtrlID( HWND hwnd )
Alexandre Julliard0e607781993-11-03 19:23:37 +00001501{
Francois Boisvert6b1b41c1999-03-14 17:25:32 +00001502 INT retvalue;
Alexandre Julliard0e607781993-11-03 19:23:37 +00001503 WND *wndPtr = WIN_FindWndPtr(hwnd);
Francois Boisvert6b1b41c1999-03-14 17:25:32 +00001504 if (!wndPtr) return 0;
1505 retvalue = wndPtr->wIDmenu;
1506 WIN_ReleaseWndPtr(wndPtr);
1507 return retvalue;
Alexandre Julliard0e607781993-11-03 19:23:37 +00001508}
1509
1510
1511/***********************************************************************
Alexandre Julliard01d63461997-01-20 19:43:45 +00001512 * GetDlgItem16 (USER.91)
Alexandre Julliard0e607781993-11-03 19:23:37 +00001513 */
Alexandre Julliard670cdc41997-08-24 16:00:30 +00001514HWND16 WINAPI GetDlgItem16( HWND16 hwndDlg, INT16 id )
Alexandre Julliard0e607781993-11-03 19:23:37 +00001515{
Alexandre Julliard59730ae1996-03-24 16:20:51 +00001516 WND *pWnd;
Alexandre Julliard0e607781993-11-03 19:23:37 +00001517
Alexandre Julliard59730ae1996-03-24 16:20:51 +00001518 if (!(pWnd = WIN_FindWndPtr( hwndDlg ))) return 0;
Francois Boisvert6b1b41c1999-03-14 17:25:32 +00001519 for (WIN_UpdateWndPtr(&pWnd,pWnd->child); pWnd; WIN_UpdateWndPtr(&pWnd,pWnd->next))
1520 if (pWnd->wIDmenu == (UINT16)id)
1521 {
1522 HWND16 retvalue = pWnd->hwndSelf;
1523 WIN_ReleaseWndPtr(pWnd);
1524 return retvalue;
1525 }
Alexandre Julliard01d63461997-01-20 19:43:45 +00001526 return 0;
1527}
1528
1529
1530/***********************************************************************
Patrik Stridvall2d6457c2000-03-28 20:22:59 +00001531 * GetDlgItem (USER32.235)
Alexandre Julliard01d63461997-01-20 19:43:45 +00001532 */
Alexandre Julliarda3960291999-02-26 11:11:13 +00001533HWND WINAPI GetDlgItem( HWND hwndDlg, INT id )
Alexandre Julliard01d63461997-01-20 19:43:45 +00001534{
1535 WND *pWnd;
1536
1537 if (!(pWnd = WIN_FindWndPtr( hwndDlg ))) return 0;
Francois Boisvert6b1b41c1999-03-14 17:25:32 +00001538 for (WIN_UpdateWndPtr(&pWnd,pWnd->child); pWnd;WIN_UpdateWndPtr(&pWnd,pWnd->next))
1539 if (pWnd->wIDmenu == (UINT16)id)
1540 {
1541 HWND retvalue = pWnd->hwndSelf;
1542 WIN_ReleaseWndPtr(pWnd);
1543 return retvalue;
1544 }
Alexandre Julliard0e607781993-11-03 19:23:37 +00001545 return 0;
1546}
1547
1548
1549/*******************************************************************
Alexandre Julliard2d93d001996-05-21 15:01:41 +00001550 * SendDlgItemMessage16 (USER.101)
Alexandre Julliard0e607781993-11-03 19:23:37 +00001551 */
Alexandre Julliard670cdc41997-08-24 16:00:30 +00001552LRESULT WINAPI SendDlgItemMessage16( HWND16 hwnd, INT16 id, UINT16 msg,
1553 WPARAM16 wParam, LPARAM lParam )
Alexandre Julliard0e607781993-11-03 19:23:37 +00001554{
Alexandre Julliard01d63461997-01-20 19:43:45 +00001555 HWND16 hwndCtrl = GetDlgItem16( hwnd, id );
Alexandre Julliard2d93d001996-05-21 15:01:41 +00001556 if (hwndCtrl) return SendMessage16( hwndCtrl, msg, wParam, lParam );
Alexandre Julliard0e607781993-11-03 19:23:37 +00001557 else return 0;
1558}
1559
1560
1561/*******************************************************************
Patrik Stridvall2d6457c2000-03-28 20:22:59 +00001562 * SendDlgItemMessageA (USER32.452)
Alexandre Julliard0e607781993-11-03 19:23:37 +00001563 */
Alexandre Julliarda3960291999-02-26 11:11:13 +00001564LRESULT WINAPI SendDlgItemMessageA( HWND hwnd, INT id, UINT msg,
1565 WPARAM wParam, LPARAM lParam )
Alexandre Julliard0e607781993-11-03 19:23:37 +00001566{
Alexandre Julliarda3960291999-02-26 11:11:13 +00001567 HWND hwndCtrl = GetDlgItem( hwnd, id );
1568 if (hwndCtrl) return SendMessageA( hwndCtrl, msg, wParam, lParam );
Alexandre Julliard2d93d001996-05-21 15:01:41 +00001569 else return 0;
Alexandre Julliard0e607781993-11-03 19:23:37 +00001570}
1571
1572
1573/*******************************************************************
Patrik Stridvall2d6457c2000-03-28 20:22:59 +00001574 * SendDlgItemMessageW (USER32.453)
Alexandre Julliard0e607781993-11-03 19:23:37 +00001575 */
Alexandre Julliarda3960291999-02-26 11:11:13 +00001576LRESULT WINAPI SendDlgItemMessageW( HWND hwnd, INT id, UINT msg,
1577 WPARAM wParam, LPARAM lParam )
Alexandre Julliard2d93d001996-05-21 15:01:41 +00001578{
Alexandre Julliarda3960291999-02-26 11:11:13 +00001579 HWND hwndCtrl = GetDlgItem( hwnd, id );
1580 if (hwndCtrl) return SendMessageW( hwndCtrl, msg, wParam, lParam );
Alexandre Julliard2d93d001996-05-21 15:01:41 +00001581 else return 0;
1582}
1583
1584
1585/*******************************************************************
1586 * SetDlgItemText16 (USER.92)
1587 */
Alexandre Julliard670cdc41997-08-24 16:00:30 +00001588void WINAPI SetDlgItemText16( HWND16 hwnd, INT16 id, SEGPTR lpString )
Alexandre Julliard2d93d001996-05-21 15:01:41 +00001589{
1590 SendDlgItemMessage16( hwnd, id, WM_SETTEXT, 0, (LPARAM)lpString );
1591}
1592
1593
1594/*******************************************************************
Patrik Stridvall2d6457c2000-03-28 20:22:59 +00001595 * SetDlgItemTextA (USER32.478)
Alexandre Julliard2d93d001996-05-21 15:01:41 +00001596 */
Alexandre Julliarda3960291999-02-26 11:11:13 +00001597BOOL WINAPI SetDlgItemTextA( HWND hwnd, INT id, LPCSTR lpString )
Alexandre Julliard2d93d001996-05-21 15:01:41 +00001598{
Alexandre Julliarda3960291999-02-26 11:11:13 +00001599 return SendDlgItemMessageA( hwnd, id, WM_SETTEXT, 0, (LPARAM)lpString );
Alexandre Julliard2d93d001996-05-21 15:01:41 +00001600}
1601
1602
1603/*******************************************************************
Patrik Stridvall2d6457c2000-03-28 20:22:59 +00001604 * SetDlgItemTextW (USER32.479)
Alexandre Julliard2d93d001996-05-21 15:01:41 +00001605 */
Alexandre Julliarda3960291999-02-26 11:11:13 +00001606BOOL WINAPI SetDlgItemTextW( HWND hwnd, INT id, LPCWSTR lpString )
Alexandre Julliard2d93d001996-05-21 15:01:41 +00001607{
Alexandre Julliarda3960291999-02-26 11:11:13 +00001608 return SendDlgItemMessageW( hwnd, id, WM_SETTEXT, 0, (LPARAM)lpString );
Alexandre Julliard2d93d001996-05-21 15:01:41 +00001609}
1610
1611
1612/***********************************************************************
1613 * GetDlgItemText16 (USER.93)
1614 */
Alexandre Julliard670cdc41997-08-24 16:00:30 +00001615INT16 WINAPI GetDlgItemText16( HWND16 hwnd, INT16 id, SEGPTR str, UINT16 len )
Alexandre Julliard2d93d001996-05-21 15:01:41 +00001616{
1617 return (INT16)SendDlgItemMessage16( hwnd, id, WM_GETTEXT,
1618 len, (LPARAM)str );
1619}
1620
1621
1622/***********************************************************************
Patrik Stridvall2d6457c2000-03-28 20:22:59 +00001623 * GetDlgItemTextA (USER32.237)
Alexandre Julliard2d93d001996-05-21 15:01:41 +00001624 */
Alexandre Julliarda3960291999-02-26 11:11:13 +00001625INT WINAPI GetDlgItemTextA( HWND hwnd, INT id, LPSTR str, UINT len )
Alexandre Julliard2d93d001996-05-21 15:01:41 +00001626{
Alexandre Julliarda3960291999-02-26 11:11:13 +00001627 return (INT)SendDlgItemMessageA( hwnd, id, WM_GETTEXT,
Alexandre Julliard2d93d001996-05-21 15:01:41 +00001628 len, (LPARAM)str );
1629}
1630
1631
1632/***********************************************************************
Patrik Stridvall2d6457c2000-03-28 20:22:59 +00001633 * GetDlgItemTextW (USER32.238)
Alexandre Julliard2d93d001996-05-21 15:01:41 +00001634 */
Alexandre Julliarda3960291999-02-26 11:11:13 +00001635INT WINAPI GetDlgItemTextW( HWND hwnd, INT id, LPWSTR str, UINT len )
Alexandre Julliard2d93d001996-05-21 15:01:41 +00001636{
Alexandre Julliarda3960291999-02-26 11:11:13 +00001637 return (INT)SendDlgItemMessageW( hwnd, id, WM_GETTEXT,
Alexandre Julliard2d93d001996-05-21 15:01:41 +00001638 len, (LPARAM)str );
1639}
1640
1641
1642/*******************************************************************
1643 * SetDlgItemInt16 (USER.94)
1644 */
Alexandre Julliard670cdc41997-08-24 16:00:30 +00001645void WINAPI SetDlgItemInt16( HWND16 hwnd, INT16 id, UINT16 value, BOOL16 fSigned )
Alexandre Julliard0e607781993-11-03 19:23:37 +00001646{
Alexandre Julliarda3960291999-02-26 11:11:13 +00001647 SetDlgItemInt( hwnd, (UINT)(UINT16)id, value, fSigned );
Alexandre Julliard0e607781993-11-03 19:23:37 +00001648}
1649
1650
Alexandre Julliard2d93d001996-05-21 15:01:41 +00001651/*******************************************************************
Patrik Stridvall2d6457c2000-03-28 20:22:59 +00001652 * SetDlgItemInt (USER32.477)
Alexandre Julliard2d93d001996-05-21 15:01:41 +00001653 */
Alexandre Julliarda3960291999-02-26 11:11:13 +00001654BOOL WINAPI SetDlgItemInt( HWND hwnd, INT id, UINT value,
1655 BOOL fSigned )
Alexandre Julliard2d93d001996-05-21 15:01:41 +00001656{
1657 char str[20];
1658
Alexandre Julliarda3960291999-02-26 11:11:13 +00001659 if (fSigned) sprintf( str, "%d", (INT)value );
Alexandre Julliard2d93d001996-05-21 15:01:41 +00001660 else sprintf( str, "%u", value );
Alexandre Julliarda3960291999-02-26 11:11:13 +00001661 SendDlgItemMessageA( hwnd, id, WM_SETTEXT, 0, (LPARAM)str );
Eric Pouechb9544f11999-02-14 14:09:42 +00001662 return TRUE;
Alexandre Julliard2d93d001996-05-21 15:01:41 +00001663}
1664
1665
Alexandre Julliard0e607781993-11-03 19:23:37 +00001666/***********************************************************************
Alexandre Julliard01d63461997-01-20 19:43:45 +00001667 * GetDlgItemInt16 (USER.95)
Alexandre Julliard0e607781993-11-03 19:23:37 +00001668 */
Alexandre Julliard670cdc41997-08-24 16:00:30 +00001669UINT16 WINAPI GetDlgItemInt16( HWND16 hwnd, INT16 id, BOOL16 *translated,
1670 BOOL16 fSigned )
Alexandre Julliard0e607781993-11-03 19:23:37 +00001671{
Alexandre Julliarda3960291999-02-26 11:11:13 +00001672 UINT result;
1673 BOOL ok;
Alexandre Julliard01d63461997-01-20 19:43:45 +00001674
Alexandre Julliard0e607781993-11-03 19:23:37 +00001675 if (translated) *translated = FALSE;
Alexandre Julliarda3960291999-02-26 11:11:13 +00001676 result = GetDlgItemInt( hwnd, (UINT)(UINT16)id, &ok, fSigned );
Alexandre Julliard01d63461997-01-20 19:43:45 +00001677 if (!ok) return 0;
1678 if (fSigned)
Alexandre Julliard0e607781993-11-03 19:23:37 +00001679 {
Alexandre Julliarda3960291999-02-26 11:11:13 +00001680 if (((INT)result < -32767) || ((INT)result > 32767)) return 0;
Alexandre Julliard0e607781993-11-03 19:23:37 +00001681 }
Alexandre Julliard01d63461997-01-20 19:43:45 +00001682 else
1683 {
1684 if (result > 65535) return 0;
1685 }
1686 if (translated) *translated = TRUE;
1687 return (UINT16)result;
Alexandre Julliard0e607781993-11-03 19:23:37 +00001688}
1689
1690
1691/***********************************************************************
Patrik Stridvall2d6457c2000-03-28 20:22:59 +00001692 * GetDlgItemInt (USER32.236)
Alexandre Julliard0e607781993-11-03 19:23:37 +00001693 */
Alexandre Julliarda3960291999-02-26 11:11:13 +00001694UINT WINAPI GetDlgItemInt( HWND hwnd, INT id, BOOL *translated,
1695 BOOL fSigned )
Alexandre Julliard01d63461997-01-20 19:43:45 +00001696{
1697 char str[30];
1698 char * endptr;
1699 long result = 0;
1700
1701 if (translated) *translated = FALSE;
Alexandre Julliarda3960291999-02-26 11:11:13 +00001702 if (!SendDlgItemMessageA(hwnd, id, WM_GETTEXT, sizeof(str), (LPARAM)str))
Alexandre Julliard01d63461997-01-20 19:43:45 +00001703 return 0;
1704 if (fSigned)
1705 {
1706 result = strtol( str, &endptr, 10 );
1707 if (!endptr || (endptr == str)) /* Conversion was unsuccessful */
1708 return 0;
1709 if (((result == LONG_MIN) || (result == LONG_MAX)) && (errno==ERANGE))
1710 return 0;
1711 }
1712 else
1713 {
1714 result = strtoul( str, &endptr, 10 );
1715 if (!endptr || (endptr == str)) /* Conversion was unsuccessful */
1716 return 0;
1717 if ((result == ULONG_MAX) && (errno == ERANGE)) return 0;
1718 }
1719 if (translated) *translated = TRUE;
Alexandre Julliarda3960291999-02-26 11:11:13 +00001720 return (UINT)result;
Alexandre Julliard01d63461997-01-20 19:43:45 +00001721}
1722
1723
1724/***********************************************************************
1725 * CheckDlgButton16 (USER.97)
1726 */
Alexandre Julliard670cdc41997-08-24 16:00:30 +00001727BOOL16 WINAPI CheckDlgButton16( HWND16 hwnd, INT16 id, UINT16 check )
Alexandre Julliard0e607781993-11-03 19:23:37 +00001728{
Alexandre Julliarda3960291999-02-26 11:11:13 +00001729 SendDlgItemMessageA( hwnd, id, BM_SETCHECK, check, 0 );
Alexandre Julliard7e56f681996-01-31 19:02:28 +00001730 return TRUE;
Alexandre Julliard0e607781993-11-03 19:23:37 +00001731}
1732
1733
1734/***********************************************************************
Patrik Stridvall2d6457c2000-03-28 20:22:59 +00001735 * CheckDlgButton (USER32.45)
Alexandre Julliard0e607781993-11-03 19:23:37 +00001736 */
Alexandre Julliarda3960291999-02-26 11:11:13 +00001737BOOL WINAPI CheckDlgButton( HWND hwnd, INT id, UINT check )
Alexandre Julliard0e607781993-11-03 19:23:37 +00001738{
Alexandre Julliarda3960291999-02-26 11:11:13 +00001739 SendDlgItemMessageA( hwnd, id, BM_SETCHECK, check, 0 );
Alexandre Julliard01d63461997-01-20 19:43:45 +00001740 return TRUE;
Alexandre Julliard0e607781993-11-03 19:23:37 +00001741}
1742
1743
1744/***********************************************************************
Alexandre Julliard01d63461997-01-20 19:43:45 +00001745 * IsDlgButtonChecked16 (USER.98)
Alexandre Julliard0e607781993-11-03 19:23:37 +00001746 */
Alexandre Julliard670cdc41997-08-24 16:00:30 +00001747UINT16 WINAPI IsDlgButtonChecked16( HWND16 hwnd, UINT16 id )
Alexandre Julliard01d63461997-01-20 19:43:45 +00001748{
Alexandre Julliarda3960291999-02-26 11:11:13 +00001749 return (UINT16)SendDlgItemMessageA( hwnd, id, BM_GETCHECK, 0, 0 );
Alexandre Julliard01d63461997-01-20 19:43:45 +00001750}
1751
1752
1753/***********************************************************************
Patrik Stridvall2d6457c2000-03-28 20:22:59 +00001754 * IsDlgButtonChecked (USER32.344)
Alexandre Julliard01d63461997-01-20 19:43:45 +00001755 */
Alexandre Julliarda3960291999-02-26 11:11:13 +00001756UINT WINAPI IsDlgButtonChecked( HWND hwnd, UINT id )
Alexandre Julliard01d63461997-01-20 19:43:45 +00001757{
Alexandre Julliarda3960291999-02-26 11:11:13 +00001758 return (UINT)SendDlgItemMessageA( hwnd, id, BM_GETCHECK, 0, 0 );
Alexandre Julliard01d63461997-01-20 19:43:45 +00001759}
1760
1761
1762/***********************************************************************
1763 * CheckRadioButton16 (USER.96)
1764 */
Alexandre Julliard670cdc41997-08-24 16:00:30 +00001765BOOL16 WINAPI CheckRadioButton16( HWND16 hwndDlg, UINT16 firstID,
1766 UINT16 lastID, UINT16 checkID )
Alexandre Julliard01d63461997-01-20 19:43:45 +00001767{
Alexandre Julliarda3960291999-02-26 11:11:13 +00001768 return CheckRadioButton( hwndDlg, firstID, lastID, checkID );
Alexandre Julliard01d63461997-01-20 19:43:45 +00001769}
1770
1771
1772/***********************************************************************
Luc Tourangeau8e238d01999-05-29 14:19:42 +00001773 * CheckRB
1774 *
1775 * Callback function used to check/uncheck radio buttons that fall
1776 * within a specific range of IDs.
1777 */
1778static BOOL CALLBACK CheckRB(HWND hwndChild, LPARAM lParam)
1779{
1780 LONG lChildID = GetWindowLongA(hwndChild, GWL_ID);
1781 RADIOGROUP *lpRadioGroup = (RADIOGROUP *) lParam;
1782
1783 if ((lChildID >= lpRadioGroup->firstID) &&
1784 (lChildID <= lpRadioGroup->lastID))
1785 {
1786 if (lChildID == lpRadioGroup->checkID)
1787 {
1788 SendMessageA(hwndChild, BM_SETCHECK, BST_CHECKED, 0);
1789 }
1790 else
1791 {
1792 SendMessageA(hwndChild, BM_SETCHECK, BST_UNCHECKED, 0);
1793 }
1794 }
1795
1796 return TRUE;
1797}
1798
1799
1800/***********************************************************************
Patrik Stridvall2d6457c2000-03-28 20:22:59 +00001801 * CheckRadioButton (USER32.48)
Alexandre Julliard01d63461997-01-20 19:43:45 +00001802 */
Alexandre Julliarda3960291999-02-26 11:11:13 +00001803BOOL WINAPI CheckRadioButton( HWND hwndDlg, UINT firstID,
Luc Tourangeau8e238d01999-05-29 14:19:42 +00001804 UINT lastID, UINT checkID )
Alexandre Julliard0e607781993-11-03 19:23:37 +00001805{
Luc Tourangeau8e238d01999-05-29 14:19:42 +00001806 RADIOGROUP radioGroup;
Francois Boisvert3a3cd9f1999-03-28 12:42:52 +00001807
Luc Tourangeau8e238d01999-05-29 14:19:42 +00001808 /* perform bounds checking for a radio button group */
1809 radioGroup.firstID = min(min(firstID, lastID), checkID);
1810 radioGroup.lastID = max(max(firstID, lastID), checkID);
1811 radioGroup.checkID = checkID;
1812
1813 return EnumChildWindows(hwndDlg, (WNDENUMPROC)CheckRB,
1814 (LPARAM)&radioGroup);
Alexandre Julliard0e607781993-11-03 19:23:37 +00001815}
1816
1817
1818/***********************************************************************
Alexandre Julliardc7c217b1998-04-13 12:21:30 +00001819 * GetDialogBaseUnits (USER.243) (USER32.233)
Alexandre Julliard0e607781993-11-03 19:23:37 +00001820 */
Alexandre Julliard670cdc41997-08-24 16:00:30 +00001821DWORD WINAPI GetDialogBaseUnits(void)
Alexandre Julliard0e607781993-11-03 19:23:37 +00001822{
1823 return MAKELONG( xBaseUnit, yBaseUnit );
1824}
1825
1826
1827/***********************************************************************
Alexandre Julliarde2bfa4c1996-05-16 18:21:06 +00001828 * MapDialogRect16 (USER.103)
Alexandre Julliard0e607781993-11-03 19:23:37 +00001829 */
Alexandre Julliard670cdc41997-08-24 16:00:30 +00001830void WINAPI MapDialogRect16( HWND16 hwnd, LPRECT16 rect )
Alexandre Julliarde2bfa4c1996-05-16 18:21:06 +00001831{
1832 DIALOGINFO * dlgInfo;
1833 WND * wndPtr = WIN_FindWndPtr( hwnd );
1834 if (!wndPtr) return;
1835 dlgInfo = (DIALOGINFO *)wndPtr->wExtra;
Francis Beaudeteb13dd41999-09-03 15:14:27 +00001836 rect->left = MulDiv(rect->left, dlgInfo->xBaseUnit, 4);
1837 rect->right = MulDiv(rect->right, dlgInfo->xBaseUnit, 4);
1838 rect->top = MulDiv(rect->top, dlgInfo->yBaseUnit, 8);
1839 rect->bottom = MulDiv(rect->bottom, dlgInfo->yBaseUnit, 8);
Francois Boisvert6b1b41c1999-03-14 17:25:32 +00001840 WIN_ReleaseWndPtr(wndPtr);
Alexandre Julliarde2bfa4c1996-05-16 18:21:06 +00001841}
1842
1843
1844/***********************************************************************
Patrik Stridvall2d6457c2000-03-28 20:22:59 +00001845 * MapDialogRect (USER32.382)
Alexandre Julliarde2bfa4c1996-05-16 18:21:06 +00001846 */
Alexandre Julliarda3960291999-02-26 11:11:13 +00001847BOOL WINAPI MapDialogRect( HWND hwnd, LPRECT rect )
Alexandre Julliard0e607781993-11-03 19:23:37 +00001848{
1849 DIALOGINFO * dlgInfo;
1850 WND * wndPtr = WIN_FindWndPtr( hwnd );
Eric Pouechb9544f11999-02-14 14:09:42 +00001851 if (!wndPtr) return FALSE;
Alexandre Julliard0e607781993-11-03 19:23:37 +00001852 dlgInfo = (DIALOGINFO *)wndPtr->wExtra;
Francis Beaudeteb13dd41999-09-03 15:14:27 +00001853 rect->left = MulDiv(rect->left, dlgInfo->xBaseUnit, 4);
1854 rect->right = MulDiv(rect->right, dlgInfo->xBaseUnit, 4);
1855 rect->top = MulDiv(rect->top, dlgInfo->yBaseUnit, 8);
1856 rect->bottom = MulDiv(rect->bottom, dlgInfo->yBaseUnit, 8);
Francois Boisvert6b1b41c1999-03-14 17:25:32 +00001857 WIN_ReleaseWndPtr(wndPtr);
Eric Pouechb9544f11999-02-14 14:09:42 +00001858 return TRUE;
Alexandre Julliard0e607781993-11-03 19:23:37 +00001859}
1860
1861
1862/***********************************************************************
Alexandre Julliardbf9130a1996-10-13 17:45:47 +00001863 * GetNextDlgGroupItem16 (USER.227)
Alexandre Julliard0e607781993-11-03 19:23:37 +00001864 */
Alexandre Julliard670cdc41997-08-24 16:00:30 +00001865HWND16 WINAPI GetNextDlgGroupItem16( HWND16 hwndDlg, HWND16 hwndCtrl,
1866 BOOL16 fPrevious )
Alexandre Julliard0e607781993-11-03 19:23:37 +00001867{
Alexandre Julliarda3960291999-02-26 11:11:13 +00001868 return (HWND16)GetNextDlgGroupItem( hwndDlg, hwndCtrl, fPrevious );
Alexandre Julliard0e607781993-11-03 19:23:37 +00001869}
1870
1871
1872/***********************************************************************
Patrik Stridvall2d6457c2000-03-28 20:22:59 +00001873 * GetNextDlgGroupItem (USER32.275)
Alexandre Julliard0e607781993-11-03 19:23:37 +00001874 */
Alexandre Julliarda3960291999-02-26 11:11:13 +00001875HWND WINAPI GetNextDlgGroupItem( HWND hwndDlg, HWND hwndCtrl,
1876 BOOL fPrevious )
Alexandre Julliard0e607781993-11-03 19:23:37 +00001877{
Francois Boisvert6b1b41c1999-03-14 17:25:32 +00001878 WND *pWnd = NULL,
1879 *pWndLast = NULL,
1880 *pWndCtrl = NULL,
1881 *pWndDlg = NULL;
1882 HWND retvalue;
Alexandre Julliard0e607781993-11-03 19:23:37 +00001883
Alexandre Julliarde6b82e71999-12-12 20:17:59 +00001884 if(hwndCtrl)
1885 {
1886 /* if the hwndCtrl is the child of the control in the hwndDlg then the hwndDlg has to be the parent of the hwndCtrl */
1887 if(GetParent(hwndCtrl) != hwndDlg && GetParent(GetParent(hwndCtrl)) == hwndDlg)
1888 hwndDlg = GetParent(hwndCtrl);
1889 }
1890
Alexandre Julliard59730ae1996-03-24 16:20:51 +00001891 if (!(pWndDlg = WIN_FindWndPtr( hwndDlg ))) return 0;
Alexandre Julliardbf9130a1996-10-13 17:45:47 +00001892 if (hwndCtrl)
1893 {
Francois Boisvert6b1b41c1999-03-14 17:25:32 +00001894 if (!(pWndCtrl = WIN_FindWndPtr( hwndCtrl )))
1895 {
1896 retvalue = 0;
1897 goto END;
1898 }
Alexandre Julliardbf9130a1996-10-13 17:45:47 +00001899 /* Make sure hwndCtrl is a top-level child */
1900 while ((pWndCtrl->dwStyle & WS_CHILD) && (pWndCtrl->parent != pWndDlg))
Francois Boisvert6b1b41c1999-03-14 17:25:32 +00001901 WIN_UpdateWndPtr(&pWndCtrl,pWndCtrl->parent);
1902 if (pWndCtrl->parent != pWndDlg)
1903 {
1904 retvalue = 0;
1905 goto END;
1906 }
Alexandre Julliardbf9130a1996-10-13 17:45:47 +00001907 }
1908 else
1909 {
1910 /* No ctrl specified -> start from the beginning */
Francois Boisvert6b1b41c1999-03-14 17:25:32 +00001911 if (!(pWndCtrl = WIN_LockWndPtr(pWndDlg->child)))
1912 {
1913 retvalue = 0;
1914 goto END;
1915 }
1916 if (fPrevious)
1917 while (pWndCtrl->next) WIN_UpdateWndPtr(&pWndCtrl,pWndCtrl->next);
Alexandre Julliardbf9130a1996-10-13 17:45:47 +00001918 }
1919
Francois Boisvert6b1b41c1999-03-14 17:25:32 +00001920 pWndLast = WIN_LockWndPtr(pWndCtrl);
1921 pWnd = WIN_LockWndPtr(pWndCtrl->next);
1922
Alexandre Julliardbf9130a1996-10-13 17:45:47 +00001923 while (1)
1924 {
1925 if (!pWnd || (pWnd->dwStyle & WS_GROUP))
1926 {
1927 /* Wrap-around to the beginning of the group */
Ulrich Weigand9c3b18f1999-05-17 14:54:09 +00001928 WND *pWndTemp;
1929
1930 WIN_UpdateWndPtr( &pWnd, pWndDlg->child );
1931 for ( pWndTemp = WIN_LockWndPtr( pWnd );
1932 pWndTemp;
1933 WIN_UpdateWndPtr( &pWndTemp, pWndTemp->next) )
Alexandre Julliardbf9130a1996-10-13 17:45:47 +00001934 {
Ulrich Weigand9c3b18f1999-05-17 14:54:09 +00001935 if (pWndTemp->dwStyle & WS_GROUP) WIN_UpdateWndPtr( &pWnd, pWndTemp );
1936 if (pWndTemp == pWndCtrl) break;
Alexandre Julliardbf9130a1996-10-13 17:45:47 +00001937 }
Ulrich Weigand9c3b18f1999-05-17 14:54:09 +00001938 WIN_ReleaseWndPtr( pWndTemp );
Alexandre Julliardbf9130a1996-10-13 17:45:47 +00001939 }
1940 if (pWnd == pWndCtrl) break;
1941 if ((pWnd->dwStyle & WS_VISIBLE) && !(pWnd->dwStyle & WS_DISABLED))
1942 {
Francois Boisvert6b1b41c1999-03-14 17:25:32 +00001943 WIN_UpdateWndPtr(&pWndLast,pWnd);
Alexandre Julliardbf9130a1996-10-13 17:45:47 +00001944 if (!fPrevious) break;
1945 }
Francois Boisvert6b1b41c1999-03-14 17:25:32 +00001946 WIN_UpdateWndPtr(&pWnd,pWnd->next);
Alexandre Julliardbf9130a1996-10-13 17:45:47 +00001947 }
Francois Boisvert6b1b41c1999-03-14 17:25:32 +00001948 retvalue = pWndLast->hwndSelf;
1949
1950 WIN_ReleaseWndPtr(pWndLast);
1951 WIN_ReleaseWndPtr(pWnd);
1952END:
1953 WIN_ReleaseWndPtr(pWndCtrl);
1954 WIN_ReleaseWndPtr(pWndDlg);
1955
1956 return retvalue;
Alexandre Julliardbf9130a1996-10-13 17:45:47 +00001957}
1958
1959
1960/***********************************************************************
1961 * GetNextDlgTabItem16 (USER.228)
1962 */
Alexandre Julliard670cdc41997-08-24 16:00:30 +00001963HWND16 WINAPI GetNextDlgTabItem16( HWND16 hwndDlg, HWND16 hwndCtrl,
1964 BOOL16 fPrevious )
Alexandre Julliardbf9130a1996-10-13 17:45:47 +00001965{
Alexandre Julliarda3960291999-02-26 11:11:13 +00001966 return (HWND16)GetNextDlgTabItem( hwndDlg, hwndCtrl, fPrevious );
Alexandre Julliardbf9130a1996-10-13 17:45:47 +00001967}
1968
Ulrich Czekalla1720c981999-10-31 21:35:35 +00001969/***********************************************************************
1970 * DIALOG_GetNextTabItem
1971 *
1972 * Helper for GetNextDlgTabItem
1973 */
1974static HWND DIALOG_GetNextTabItem( HWND hwndMain, HWND hwndDlg, HWND hwndCtrl, BOOL fPrevious )
1975{
1976 LONG dsStyle;
1977 LONG exStyle;
1978 UINT wndSearch = fPrevious ? GW_HWNDPREV : GW_HWNDNEXT;
1979 HWND retWnd = 0;
1980 HWND hChildFirst = 0;
1981
1982 if(!hwndCtrl)
1983 {
1984 hChildFirst = GetWindow(hwndDlg,GW_CHILD);
1985 if(fPrevious) hChildFirst = GetWindow(hChildFirst,GW_HWNDLAST);
1986 }
1987 else
1988 {
1989 HWND hParent = GetParent(hwndCtrl);
1990 BOOL bValid = FALSE;
1991 while( hParent)
1992 {
1993 if(hParent == hwndMain)
1994 {
1995 bValid = TRUE;
1996 break;
1997 }
1998 hParent = GetParent(hParent);
1999 }
2000 if(bValid)
2001 {
2002 hChildFirst = GetWindow(hwndCtrl,wndSearch);
2003 if(!hChildFirst)
2004 {
2005 if(GetParent(hwndCtrl) != hwndMain)
2006 hChildFirst = GetWindow(GetParent(hwndCtrl),wndSearch);
2007 else
2008 {
2009 if(fPrevious)
2010 hChildFirst = GetWindow(hwndCtrl,GW_HWNDLAST);
2011 else
2012 hChildFirst = GetWindow(hwndCtrl,GW_HWNDFIRST);
2013 }
2014 }
2015 }
2016 }
2017 while(hChildFirst)
2018 {
2019 BOOL bCtrl = FALSE;
2020 while(hChildFirst)
2021 {
2022 dsStyle = GetWindowLongA(hChildFirst,GWL_STYLE);
2023 exStyle = GetWindowLongA(hChildFirst,GWL_EXSTYLE);
Alexandre Julliarde6b82e71999-12-12 20:17:59 +00002024 if( (dsStyle & DS_CONTROL || exStyle & WS_EX_CONTROLPARENT) && (dsStyle & WS_VISIBLE) && !(dsStyle & WS_DISABLED))
Ulrich Czekalla1720c981999-10-31 21:35:35 +00002025 {
2026 bCtrl=TRUE;
2027 break;
2028 }
2029 else if( (dsStyle & WS_TABSTOP) && (dsStyle & WS_VISIBLE) && !(dsStyle & WS_DISABLED))
2030 break;
2031 hChildFirst = GetWindow(hChildFirst,wndSearch);
2032 }
2033 if(hChildFirst)
2034 {
2035 if(bCtrl)
2036 retWnd = DIALOG_GetNextTabItem(hwndMain,hChildFirst,(HWND)NULL,fPrevious );
2037 else
2038 retWnd = hChildFirst;
2039 }
2040 if(retWnd) break;
2041 hChildFirst = GetWindow(hChildFirst,wndSearch);
2042 }
2043 if(!retWnd && hwndCtrl)
2044 {
2045 HWND hParent = GetParent(hwndCtrl);
2046 while(hParent)
2047 {
2048 if(hParent == hwndMain) break;
2049 retWnd = DIALOG_GetNextTabItem(hwndMain,GetParent(hParent),hParent,fPrevious );
2050 if(retWnd) break;
2051 hParent = GetParent(hParent);
2052 }
2053 if(!retWnd)
2054 retWnd = DIALOG_GetNextTabItem(hwndMain,hwndMain,(HWND)NULL,fPrevious );
2055 }
2056 return retWnd;
2057}
Alexandre Julliardbf9130a1996-10-13 17:45:47 +00002058
2059/***********************************************************************
Patrik Stridvall2d6457c2000-03-28 20:22:59 +00002060 * GetNextDlgTabItem (USER32.276)
Alexandre Julliardbf9130a1996-10-13 17:45:47 +00002061 */
Alexandre Julliarda3960291999-02-26 11:11:13 +00002062HWND WINAPI GetNextDlgTabItem( HWND hwndDlg, HWND hwndCtrl,
2063 BOOL fPrevious )
Alexandre Julliardbf9130a1996-10-13 17:45:47 +00002064{
Ulrich Czekalla1720c981999-10-31 21:35:35 +00002065 return DIALOG_GetNextTabItem(hwndDlg,hwndDlg,hwndCtrl,fPrevious);
Alexandre Julliard0e607781993-11-03 19:23:37 +00002066}
Alexandre Julliard75d86e11996-11-17 18:59:11 +00002067
Alexandre Julliard75d86e11996-11-17 18:59:11 +00002068/**********************************************************************
2069 * DIALOG_DlgDirSelect
2070 *
2071 * Helper function for DlgDirSelect*
2072 */
Alexandre Julliarda3960291999-02-26 11:11:13 +00002073static BOOL DIALOG_DlgDirSelect( HWND hwnd, LPSTR str, INT len,
2074 INT id, BOOL win32, BOOL unicode,
2075 BOOL combo )
Alexandre Julliard75d86e11996-11-17 18:59:11 +00002076{
2077 char *buffer, *ptr;
Alexandre Julliarda3960291999-02-26 11:11:13 +00002078 INT item, size;
2079 BOOL ret;
2080 HWND listbox = GetDlgItem( hwnd, id );
Alexandre Julliard75d86e11996-11-17 18:59:11 +00002081
Alexandre Julliard359f497e1999-07-04 16:02:24 +00002082 TRACE("%04x '%s' %d\n", hwnd, str, id );
Alexandre Julliard75d86e11996-11-17 18:59:11 +00002083 if (!listbox) return FALSE;
2084 if (win32)
2085 {
Alexandre Julliarda3960291999-02-26 11:11:13 +00002086 item = SendMessageA(listbox, combo ? CB_GETCURSEL
2087 : LB_GETCURSEL, 0, 0 );
Alexandre Julliard75d86e11996-11-17 18:59:11 +00002088 if (item == LB_ERR) return FALSE;
Alexandre Julliarda3960291999-02-26 11:11:13 +00002089 size = SendMessageA(listbox, combo ? CB_GETLBTEXTLEN
2090 : LB_GETTEXTLEN, 0, 0 );
Alexandre Julliard75d86e11996-11-17 18:59:11 +00002091 if (size == LB_ERR) return FALSE;
2092 }
2093 else
2094 {
Alexandre Julliarda3960291999-02-26 11:11:13 +00002095 item = SendMessageA(listbox, combo ? CB_GETCURSEL16
Alexandre Julliard75d86e11996-11-17 18:59:11 +00002096 : LB_GETCURSEL16, 0, 0 );
2097 if (item == LB_ERR) return FALSE;
Alexandre Julliarda3960291999-02-26 11:11:13 +00002098 size = SendMessageA(listbox, combo ? CB_GETLBTEXTLEN16
Alexandre Julliard75d86e11996-11-17 18:59:11 +00002099 : LB_GETTEXTLEN16, 0, 0 );
2100 if (size == LB_ERR) return FALSE;
2101 }
2102
2103 if (!(buffer = SEGPTR_ALLOC( size+1 ))) return FALSE;
2104
2105 if (win32)
Alexandre Julliarda3960291999-02-26 11:11:13 +00002106 SendMessageA( listbox, combo ? CB_GETLBTEXT : LB_GETTEXT,
Alexandre Julliard75d86e11996-11-17 18:59:11 +00002107 item, (LPARAM)buffer );
2108 else
2109 SendMessage16( listbox, combo ? CB_GETLBTEXT16 : LB_GETTEXT16,
2110 item, (LPARAM)SEGPTR_GET(buffer) );
2111
2112 if ((ret = (buffer[0] == '['))) /* drive or directory */
2113 {
2114 if (buffer[1] == '-') /* drive */
2115 {
2116 buffer[3] = ':';
2117 buffer[4] = 0;
2118 ptr = buffer + 2;
2119 }
2120 else
2121 {
2122 buffer[strlen(buffer)-1] = '\\';
2123 ptr = buffer + 1;
2124 }
2125 }
2126 else ptr = buffer;
2127
2128 if (unicode) lstrcpynAtoW( (LPWSTR)str, ptr, len );
Alexandre Julliarda3960291999-02-26 11:11:13 +00002129 else lstrcpynA( str, ptr, len );
Alexandre Julliard75d86e11996-11-17 18:59:11 +00002130 SEGPTR_FREE( buffer );
Alexandre Julliard359f497e1999-07-04 16:02:24 +00002131 TRACE("Returning %d '%s'\n", ret, str );
Alexandre Julliard75d86e11996-11-17 18:59:11 +00002132 return ret;
2133}
2134
2135
2136/**********************************************************************
Alexandre Julliardda0cfb31996-12-01 17:17:47 +00002137 * DIALOG_DlgDirList
2138 *
2139 * Helper function for DlgDirList*
2140 */
Alexandre Julliarda3960291999-02-26 11:11:13 +00002141static INT DIALOG_DlgDirList( HWND hDlg, LPSTR spec, INT idLBox,
2142 INT idStatic, UINT attrib, BOOL combo )
Alexandre Julliardda0cfb31996-12-01 17:17:47 +00002143{
2144 int drive;
Alexandre Julliarda3960291999-02-26 11:11:13 +00002145 HWND hwnd;
Alexandre Julliard84c70f51997-05-09 08:40:27 +00002146 LPSTR orig_spec = spec;
Alexandre Julliardda0cfb31996-12-01 17:17:47 +00002147
2148#define SENDMSG(msg,wparam,lparam) \
Alexandre Julliarda3960291999-02-26 11:11:13 +00002149 ((attrib & DDL_POSTMSGS) ? PostMessageA( hwnd, msg, wparam, lparam ) \
2150 : SendMessageA( hwnd, msg, wparam, lparam ))
Alexandre Julliardda0cfb31996-12-01 17:17:47 +00002151
Alexandre Julliard359f497e1999-07-04 16:02:24 +00002152 TRACE("%04x '%s' %d %d %04x\n",
Alexandre Julliardda0cfb31996-12-01 17:17:47 +00002153 hDlg, spec ? spec : "NULL", idLBox, idStatic, attrib );
2154
2155 if (spec && spec[0] && (spec[1] == ':'))
2156 {
2157 drive = toupper( spec[0] ) - 'A';
2158 spec += 2;
2159 if (!DRIVE_SetCurrentDrive( drive )) return FALSE;
2160 }
2161 else drive = DRIVE_GetCurrentDrive();
2162
Alexandre Julliard84c70f51997-05-09 08:40:27 +00002163 /* If the path exists and is a directory, chdir to it */
2164 if (!spec || !spec[0] || DRIVE_Chdir( drive, spec )) spec = "*.*";
2165 else
2166 {
2167 char *p, *p2;
2168 p = spec;
2169 if ((p2 = strrchr( p, '\\' ))) p = p2;
2170 if ((p2 = strrchr( p, '/' ))) p = p2;
2171 if (p != spec)
2172 {
2173 char sep = *p;
2174 *p = 0;
2175 if (!DRIVE_Chdir( drive, spec ))
2176 {
2177 *p = sep; /* Restore the original spec */
2178 return FALSE;
2179 }
2180 spec = p + 1;
2181 }
2182 }
2183
Alexandre Julliard359f497e1999-07-04 16:02:24 +00002184 TRACE("path=%c:\\%s mask=%s\n",
Alexandre Julliard84c70f51997-05-09 08:40:27 +00002185 'A' + drive, DRIVE_GetDosCwd(drive), spec );
2186
Alexandre Julliarda3960291999-02-26 11:11:13 +00002187 if (idLBox && ((hwnd = GetDlgItem( hDlg, idLBox )) != 0))
Alexandre Julliardda0cfb31996-12-01 17:17:47 +00002188 {
Alexandre Julliarda3960291999-02-26 11:11:13 +00002189 SENDMSG( combo ? CB_RESETCONTENT : LB_RESETCONTENT, 0, 0 );
Alexandre Julliard84c70f51997-05-09 08:40:27 +00002190 if (attrib & DDL_DIRECTORY)
Alexandre Julliardda0cfb31996-12-01 17:17:47 +00002191 {
Alexandre Julliard84c70f51997-05-09 08:40:27 +00002192 if (!(attrib & DDL_EXCLUSIVE))
2193 {
Alexandre Julliarda3960291999-02-26 11:11:13 +00002194 if (SENDMSG( combo ? CB_DIR : LB_DIR,
Alexandre Julliard84c70f51997-05-09 08:40:27 +00002195 attrib & ~(DDL_DIRECTORY | DDL_DRIVES),
2196 (LPARAM)spec ) == LB_ERR)
2197 return FALSE;
2198 }
Alexandre Julliarda3960291999-02-26 11:11:13 +00002199 if (SENDMSG( combo ? CB_DIR : LB_DIR,
Alexandre Julliardda0cfb31996-12-01 17:17:47 +00002200 (attrib & (DDL_DIRECTORY | DDL_DRIVES)) | DDL_EXCLUSIVE,
2201 (LPARAM)"*.*" ) == LB_ERR)
2202 return FALSE;
2203 }
2204 else
2205 {
Alexandre Julliarda3960291999-02-26 11:11:13 +00002206 if (SENDMSG( combo ? CB_DIR : LB_DIR, attrib,
Alexandre Julliardda0cfb31996-12-01 17:17:47 +00002207 (LPARAM)spec ) == LB_ERR)
2208 return FALSE;
2209 }
2210 }
2211
Alexandre Julliarda3960291999-02-26 11:11:13 +00002212 if (idStatic && ((hwnd = GetDlgItem( hDlg, idStatic )) != 0))
Alexandre Julliardda0cfb31996-12-01 17:17:47 +00002213 {
2214 char temp[512];
2215 int drive = DRIVE_GetCurrentDrive();
2216 strcpy( temp, "A:\\" );
2217 temp[0] += drive;
Alexandre Julliarda3960291999-02-26 11:11:13 +00002218 lstrcpynA( temp + 3, DRIVE_GetDosCwd(drive), sizeof(temp)-3 );
2219 CharLowerA( temp );
Alexandre Julliardda0cfb31996-12-01 17:17:47 +00002220 /* Can't use PostMessage() here, because the string is on the stack */
Alexandre Julliarda3960291999-02-26 11:11:13 +00002221 SetDlgItemTextA( hDlg, idStatic, temp );
Alexandre Julliardda0cfb31996-12-01 17:17:47 +00002222 }
Alexandre Julliard84c70f51997-05-09 08:40:27 +00002223
2224 if (orig_spec && (spec != orig_spec))
2225 {
2226 /* Update the original file spec */
2227 char *p = spec;
2228 while ((*orig_spec++ = *p++));
2229 }
2230
Alexandre Julliardda0cfb31996-12-01 17:17:47 +00002231 return TRUE;
2232#undef SENDMSG
2233}
2234
2235
2236/**********************************************************************
Alexandre Julliard84c70f51997-05-09 08:40:27 +00002237 * DIALOG_DlgDirListW
2238 *
Patrik Stridvall2d6457c2000-03-28 20:22:59 +00002239 * Helper function for DlgDirList*W
Alexandre Julliard84c70f51997-05-09 08:40:27 +00002240 */
Alexandre Julliarda3960291999-02-26 11:11:13 +00002241static INT DIALOG_DlgDirListW( HWND hDlg, LPWSTR spec, INT idLBox,
2242 INT idStatic, UINT attrib, BOOL combo )
Alexandre Julliard84c70f51997-05-09 08:40:27 +00002243{
2244 if (spec)
2245 {
2246 LPSTR specA = HEAP_strdupWtoA( GetProcessHeap(), 0, spec );
Alexandre Julliarda3960291999-02-26 11:11:13 +00002247 INT ret = DIALOG_DlgDirList( hDlg, specA, idLBox, idStatic,
Alexandre Julliard84c70f51997-05-09 08:40:27 +00002248 attrib, combo );
2249 lstrcpyAtoW( spec, specA );
2250 HeapFree( GetProcessHeap(), 0, specA );
2251 return ret;
2252 }
2253 return DIALOG_DlgDirList( hDlg, NULL, idLBox, idStatic, attrib, combo );
2254}
2255
2256
2257/**********************************************************************
Alexandre Julliard75d86e11996-11-17 18:59:11 +00002258 * DlgDirSelect (USER.99)
2259 */
Alexandre Julliarda3960291999-02-26 11:11:13 +00002260BOOL16 WINAPI DlgDirSelect16( HWND16 hwnd, LPSTR str, INT16 id )
Alexandre Julliard75d86e11996-11-17 18:59:11 +00002261{
2262 return DlgDirSelectEx16( hwnd, str, 128, id );
2263}
2264
2265
2266/**********************************************************************
2267 * DlgDirSelectComboBox (USER.194)
2268 */
Alexandre Julliarda3960291999-02-26 11:11:13 +00002269BOOL16 WINAPI DlgDirSelectComboBox16( HWND16 hwnd, LPSTR str, INT16 id )
Alexandre Julliard75d86e11996-11-17 18:59:11 +00002270{
2271 return DlgDirSelectComboBoxEx16( hwnd, str, 128, id );
2272}
2273
2274
2275/**********************************************************************
2276 * DlgDirSelectEx16 (USER.422)
2277 */
Alexandre Julliard670cdc41997-08-24 16:00:30 +00002278BOOL16 WINAPI DlgDirSelectEx16( HWND16 hwnd, LPSTR str, INT16 len, INT16 id )
Alexandre Julliard75d86e11996-11-17 18:59:11 +00002279{
2280 return DIALOG_DlgDirSelect( hwnd, str, len, id, FALSE, FALSE, FALSE );
2281}
2282
2283
2284/**********************************************************************
Patrik Stridvall2d6457c2000-03-28 20:22:59 +00002285 * DlgDirSelectExA (USER32.149)
Alexandre Julliard75d86e11996-11-17 18:59:11 +00002286 */
Alexandre Julliarda3960291999-02-26 11:11:13 +00002287BOOL WINAPI DlgDirSelectExA( HWND hwnd, LPSTR str, INT len, INT id )
Alexandre Julliard75d86e11996-11-17 18:59:11 +00002288{
2289 return DIALOG_DlgDirSelect( hwnd, str, len, id, TRUE, FALSE, FALSE );
2290}
2291
2292
2293/**********************************************************************
Patrik Stridvall2d6457c2000-03-28 20:22:59 +00002294 * DlgDirSelectExW (USER32.150)
Alexandre Julliard75d86e11996-11-17 18:59:11 +00002295 */
Alexandre Julliarda3960291999-02-26 11:11:13 +00002296BOOL WINAPI DlgDirSelectExW( HWND hwnd, LPWSTR str, INT len, INT id )
Alexandre Julliard75d86e11996-11-17 18:59:11 +00002297{
2298 return DIALOG_DlgDirSelect( hwnd, (LPSTR)str, len, id, TRUE, TRUE, FALSE );
2299}
2300
2301
2302/**********************************************************************
2303 * DlgDirSelectComboBoxEx16 (USER.423)
2304 */
Alexandre Julliard670cdc41997-08-24 16:00:30 +00002305BOOL16 WINAPI DlgDirSelectComboBoxEx16( HWND16 hwnd, LPSTR str, INT16 len,
2306 INT16 id )
Alexandre Julliard75d86e11996-11-17 18:59:11 +00002307{
2308 return DIALOG_DlgDirSelect( hwnd, str, len, id, FALSE, FALSE, TRUE );
2309}
2310
2311
2312/**********************************************************************
Patrik Stridvall2d6457c2000-03-28 20:22:59 +00002313 * DlgDirSelectComboBoxExA (USER32.147)
Alexandre Julliard75d86e11996-11-17 18:59:11 +00002314 */
Alexandre Julliarda3960291999-02-26 11:11:13 +00002315BOOL WINAPI DlgDirSelectComboBoxExA( HWND hwnd, LPSTR str, INT len,
2316 INT id )
Alexandre Julliard75d86e11996-11-17 18:59:11 +00002317{
2318 return DIALOG_DlgDirSelect( hwnd, str, len, id, TRUE, FALSE, TRUE );
2319}
2320
2321
2322/**********************************************************************
Patrik Stridvall2d6457c2000-03-28 20:22:59 +00002323 * DlgDirSelectComboBoxExW (USER32.148)
Alexandre Julliard75d86e11996-11-17 18:59:11 +00002324 */
Alexandre Julliarda3960291999-02-26 11:11:13 +00002325BOOL WINAPI DlgDirSelectComboBoxExW( HWND hwnd, LPWSTR str, INT len,
2326 INT id)
Alexandre Julliard75d86e11996-11-17 18:59:11 +00002327{
2328 return DIALOG_DlgDirSelect( hwnd, (LPSTR)str, len, id, TRUE, TRUE, TRUE );
2329}
Alexandre Julliardda0cfb31996-12-01 17:17:47 +00002330
2331
2332/**********************************************************************
2333 * DlgDirList16 (USER.100)
2334 */
Alexandre Julliard670cdc41997-08-24 16:00:30 +00002335INT16 WINAPI DlgDirList16( HWND16 hDlg, LPSTR spec, INT16 idLBox,
2336 INT16 idStatic, UINT16 attrib )
Alexandre Julliardda0cfb31996-12-01 17:17:47 +00002337{
2338 return DIALOG_DlgDirList( hDlg, spec, idLBox, idStatic, attrib, FALSE );
2339}
2340
2341
2342/**********************************************************************
Patrik Stridvall2d6457c2000-03-28 20:22:59 +00002343 * DlgDirListA (USER32.143)
Alexandre Julliardda0cfb31996-12-01 17:17:47 +00002344 */
Alexandre Julliarda3960291999-02-26 11:11:13 +00002345INT WINAPI DlgDirListA( HWND hDlg, LPSTR spec, INT idLBox,
2346 INT idStatic, UINT attrib )
Alexandre Julliardda0cfb31996-12-01 17:17:47 +00002347{
2348 return DIALOG_DlgDirList( hDlg, spec, idLBox, idStatic, attrib, FALSE );
2349}
2350
2351
2352/**********************************************************************
Patrik Stridvall2d6457c2000-03-28 20:22:59 +00002353 * DlgDirListW (USER32.146)
Alexandre Julliardda0cfb31996-12-01 17:17:47 +00002354 */
Alexandre Julliarda3960291999-02-26 11:11:13 +00002355INT WINAPI DlgDirListW( HWND hDlg, LPWSTR spec, INT idLBox,
2356 INT idStatic, UINT attrib )
Alexandre Julliardda0cfb31996-12-01 17:17:47 +00002357{
Alexandre Julliard84c70f51997-05-09 08:40:27 +00002358 return DIALOG_DlgDirListW( hDlg, spec, idLBox, idStatic, attrib, FALSE );
Alexandre Julliardda0cfb31996-12-01 17:17:47 +00002359}
2360
2361
2362/**********************************************************************
2363 * DlgDirListComboBox16 (USER.195)
2364 */
Alexandre Julliard670cdc41997-08-24 16:00:30 +00002365INT16 WINAPI DlgDirListComboBox16( HWND16 hDlg, LPSTR spec, INT16 idCBox,
2366 INT16 idStatic, UINT16 attrib )
Alexandre Julliardda0cfb31996-12-01 17:17:47 +00002367{
2368 return DIALOG_DlgDirList( hDlg, spec, idCBox, idStatic, attrib, TRUE );
2369}
2370
2371
2372/**********************************************************************
Patrik Stridvall2d6457c2000-03-28 20:22:59 +00002373 * DlgDirListComboBoxA (USER32.144)
Alexandre Julliardda0cfb31996-12-01 17:17:47 +00002374 */
Alexandre Julliarda3960291999-02-26 11:11:13 +00002375INT WINAPI DlgDirListComboBoxA( HWND hDlg, LPSTR spec, INT idCBox,
2376 INT idStatic, UINT attrib )
Alexandre Julliardda0cfb31996-12-01 17:17:47 +00002377{
2378 return DIALOG_DlgDirList( hDlg, spec, idCBox, idStatic, attrib, TRUE );
2379}
2380
2381
2382/**********************************************************************
Patrik Stridvall2d6457c2000-03-28 20:22:59 +00002383 * DlgDirListComboBoxW (USER32.145)
Alexandre Julliardda0cfb31996-12-01 17:17:47 +00002384 */
Alexandre Julliarda3960291999-02-26 11:11:13 +00002385INT WINAPI DlgDirListComboBoxW( HWND hDlg, LPWSTR spec, INT idCBox,
2386 INT idStatic, UINT attrib )
Alexandre Julliardda0cfb31996-12-01 17:17:47 +00002387{
Alexandre Julliard84c70f51997-05-09 08:40:27 +00002388 return DIALOG_DlgDirListW( hDlg, spec, idCBox, idStatic, attrib, TRUE );
Alexandre Julliardda0cfb31996-12-01 17:17:47 +00002389}