blob: 8dc29c4be2ed054b669d9228cfda925e68c7c4c3 [file] [log] [blame]
Alexandre Julliard0e607781993-11-03 19:23:37 +00001/*
2 * Dialog functions
3 *
Alexandre Julliardaca05781994-10-17 18:12:41 +00004 * Copyright 1993, 1994 Alexandre Julliard
Alexandre Julliard234bc241994-12-10 13:02:28 +00005 *
Alexandre Julliardaca05781994-10-17 18:12:41 +00006static char Copyright[] = "Copyright Alexandre Julliard, 1993, 1994";
Alexandre Julliard234bc241994-12-10 13:02:28 +00007*/
Alexandre Julliard0e607781993-11-03 19:23:37 +00008
Alexandre Julliard8d24ae61994-04-05 21:42:43 +00009#include <stdlib.h>
10#include <stdio.h>
11#include <string.h>
Alexandre Julliard0e607781993-11-03 19:23:37 +000012#include "windows.h"
13#include "dialog.h"
14#include "win.h"
Alexandre Julliarde2abbb11995-03-19 17:39:39 +000015#include "ldt.h"
Alexandre Julliard2787be81995-05-22 18:23:01 +000016#include "stackframe.h"
Alexandre Julliarddba420a1994-02-02 06:48:31 +000017#include "user.h"
Alexandre Julliard3f2abfa1994-08-16 15:43:11 +000018#include "message.h"
Alexandre Julliardaca05781994-10-17 18:12:41 +000019#include "stddebug.h"
Alexandre Julliard3a405ba1994-10-30 16:25:19 +000020/* #define DEBUG_DIALOG */
Alexandre Julliardaca05781994-10-17 18:12:41 +000021#include "debug.h"
Alexandre Julliard0e607781993-11-03 19:23:37 +000022
Alexandre Julliard0e607781993-11-03 19:23:37 +000023 /* Dialog base units */
24static WORD xBaseUnit = 0, yBaseUnit = 0;
25
26
27/***********************************************************************
28 * DIALOG_Init
29 *
30 * Initialisation of the dialog manager.
31 */
32BOOL DIALOG_Init()
33{
34 TEXTMETRIC tm;
35 HDC hdc;
36
37 /* Calculate the dialog base units */
38
Alexandre Julliard7cbe6571995-01-09 18:21:16 +000039 if (!(hdc = GetDC( 0 ))) return FALSE;
Alexandre Julliard0e607781993-11-03 19:23:37 +000040 GetTextMetrics( hdc, &tm );
41 ReleaseDC( 0, hdc );
42 xBaseUnit = tm.tmAveCharWidth;
43 yBaseUnit = tm.tmHeight;
Alexandre Julliard7cbe6571995-01-09 18:21:16 +000044
45 /* Dialog units are based on a proportional system font */
46 /* so we adjust them a bit for a fixed font. */
47 if (tm.tmPitchAndFamily & TMPF_FIXED_PITCH) xBaseUnit = xBaseUnit * 5 / 4;
48
49 dprintf_dialog( stddeb, "DIALOG_Init: base units = %d,%d\n",
50 xBaseUnit, yBaseUnit );
Alexandre Julliard0e607781993-11-03 19:23:37 +000051 return TRUE;
52}
53
54
55/***********************************************************************
Alexandre Julliardaca05781994-10-17 18:12:41 +000056 * DIALOG_GetFirstTabItem
57 *
58 * Return the first item of the dialog that has the WS_TABSTOP style.
59 */
60HWND DIALOG_GetFirstTabItem( HWND hwndDlg )
61{
62 HWND hwnd;
63 WND *wndPtr = WIN_FindWndPtr( hwndDlg );
64 hwnd = wndPtr->hwndChild;
65 while(hwnd)
66 {
67 wndPtr = WIN_FindWndPtr( hwnd );
68 if (wndPtr->dwStyle & WS_TABSTOP) break;
69 hwnd = wndPtr->hwndNext;
70 }
71 return hwnd;
72}
73
74
75/***********************************************************************
Alexandre Julliard0e607781993-11-03 19:23:37 +000076 * DIALOG_GetControl
77 *
78 * Return the class and text of the control pointed to by ptr,
79 * and return a pointer to the next control.
80 */
Alexandre Julliardff8331e1995-09-18 11:19:54 +000081static SEGPTR DIALOG_GetControl( SEGPTR ptr, SEGPTR *class, SEGPTR *text )
Alexandre Julliard0e607781993-11-03 19:23:37 +000082{
Alexandre Julliardff8331e1995-09-18 11:19:54 +000083 unsigned char *base = (unsigned char *)PTR_SEG_TO_LIN( ptr );
84 unsigned char *p = base;
85
Alexandre Julliard0e607781993-11-03 19:23:37 +000086 p += 14; /* size of control header */
Alexandre Julliard7e50df31994-08-06 11:22:41 +000087
Alexandre Julliard0e607781993-11-03 19:23:37 +000088 if (*p & 0x80)
89 {
Alexandre Julliardff8331e1995-09-18 11:19:54 +000090 *class = MAKEINTRESOURCE( *p );
91 p++;
Alexandre Julliard0e607781993-11-03 19:23:37 +000092 }
93 else
94 {
Alexandre Julliardff8331e1995-09-18 11:19:54 +000095 *class = ptr + (WORD)(p - base);
Alexandre Julliard0e607781993-11-03 19:23:37 +000096 p += strlen(p) + 1;
97 }
Alexandre Julliardff8331e1995-09-18 11:19:54 +000098
Alexandre Julliard940d58c1994-09-16 09:24:37 +000099 if (*p == 0xff)
100 {
101 /* Integer id, not documented (?). Only works for SS_ICON controls */
Alexandre Julliardff8331e1995-09-18 11:19:54 +0000102 *text = MAKEINTRESOURCE( p[1] + 256 * p[2] );
Alexandre Julliard7e50df31994-08-06 11:22:41 +0000103 p += 4;
Alexandre Julliard940d58c1994-09-16 09:24:37 +0000104 }
105 else
106 {
Alexandre Julliardff8331e1995-09-18 11:19:54 +0000107 *text = ptr + (WORD)(p - base);
Alexandre Julliard7e50df31994-08-06 11:22:41 +0000108 p += strlen(p) + 2;
109 }
Alexandre Julliardff8331e1995-09-18 11:19:54 +0000110 return ptr + (WORD)(p - base);
Alexandre Julliard0e607781993-11-03 19:23:37 +0000111}
112
113
114/***********************************************************************
115 * DIALOG_ParseTemplate
116 *
Alexandre Julliarde399fc31993-11-24 17:08:56 +0000117 * Fill a DLGTEMPLATE structure from the dialog template, and return
118 * a pointer to the first control.
Alexandre Julliard0e607781993-11-03 19:23:37 +0000119 */
Alexandre Julliardff8331e1995-09-18 11:19:54 +0000120static SEGPTR DIALOG_ParseTemplate( SEGPTR template, DLGTEMPLATE * result )
Alexandre Julliard0e607781993-11-03 19:23:37 +0000121{
Alexandre Julliardff8331e1995-09-18 11:19:54 +0000122 unsigned char *base = (unsigned char *)PTR_SEG_TO_LIN(template);
123 unsigned char * p = base;
Alexandre Julliard0e607781993-11-03 19:23:37 +0000124
Alexandre Julliardff8331e1995-09-18 11:19:54 +0000125 result->header = *(DLGTEMPLATEHEADER *)p;
Alexandre Julliard0e607781993-11-03 19:23:37 +0000126 p += 13;
Alexandre Julliarde399fc31993-11-24 17:08:56 +0000127
Alexandre Julliardff8331e1995-09-18 11:19:54 +0000128 /* Get the menu name */
Alexandre Julliard0e607781993-11-03 19:23:37 +0000129
Alexandre Julliardff8331e1995-09-18 11:19:54 +0000130 if (*p == 0xff)
Alexandre Julliard0e607781993-11-03 19:23:37 +0000131 {
Alexandre Julliardff8331e1995-09-18 11:19:54 +0000132 result->menuName = MAKEINTRESOURCE( p[1] + 256 * p[2] );
133 p += 3;
134 }
135 else if (*p)
136 {
137 result->menuName = template + (WORD)(p - base);
138 p += strlen(p) + 1;
139 }
140 else
141 {
142 result->menuName = 0;
143 p++;
Alexandre Julliard0e607781993-11-03 19:23:37 +0000144 }
Alexandre Julliard0e607781993-11-03 19:23:37 +0000145
Alexandre Julliardff8331e1995-09-18 11:19:54 +0000146 /* Get the class name */
147
148 if (*p) result->className = template + (WORD)(p - base);
149 else result->className = DIALOG_CLASS_ATOM;
150 p += strlen(p) + 1;
151
152 /* Get the window caption */
153
154 result->caption = template + (WORD)(p - base);
155 p += strlen(p) + 1;
156
157 /* Get the font name */
158
159 if (result->header.style & DS_SETFONT)
160 {
161 result->pointSize = *(WORD *)p;
162 p += sizeof(WORD);
163 result->faceName = template + (WORD)(p - base);
164 p += strlen(p) + 1;
165 }
166
167 return template + (WORD)(p - base);
Alexandre Julliard0e607781993-11-03 19:23:37 +0000168}
169
170
171/***********************************************************************
172 * DIALOG_DisplayTemplate
173 */
Alexandre Julliard0e607781993-11-03 19:23:37 +0000174static void DIALOG_DisplayTemplate( DLGTEMPLATE * result )
175{
Alexandre Julliardff8331e1995-09-18 11:19:54 +0000176 dprintf_dialog(stddeb, "DIALOG %d, %d, %d, %d\n", result->header.x, result->header.y,
177 result->header.cx, result->header.cy );
178 dprintf_dialog(stddeb, " STYLE %08lx\n", result->header.style );
179 dprintf_dialog( stddeb, " CAPTION '%s'\n",
180 (char *)PTR_SEG_TO_LIN(result->caption) );
181
182 if (HIWORD(result->className))
183 dprintf_dialog( stddeb, " CLASS '%s'\n",
184 (char *)PTR_SEG_TO_LIN(result->className) );
185 else
186 dprintf_dialog( stddeb, " CLASS #%d\n", LOWORD(result->className) );
187
188 if (HIWORD(result->menuName))
189 dprintf_dialog( stddeb, " MENU '%s'\n",
190 (char *)PTR_SEG_TO_LIN(result->menuName) );
191 else if (LOWORD(result->menuName))
192 dprintf_dialog(stddeb, " MENU %04x\n", LOWORD(result->menuName) );
193
194 if (result->header.style & DS_SETFONT)
195 dprintf_dialog( stddeb, " FONT %d,'%s'\n", result->pointSize,
196 (char *)PTR_SEG_TO_LIN(result->faceName) );
Alexandre Julliard0e607781993-11-03 19:23:37 +0000197}
Alexandre Julliard0e607781993-11-03 19:23:37 +0000198
199
200/***********************************************************************
201 * CreateDialog (USER.89)
202 */
Alexandre Julliarde2abbb11995-03-19 17:39:39 +0000203HWND CreateDialog( HINSTANCE hInst, SEGPTR dlgTemplate,
Alexandre Julliardaca05781994-10-17 18:12:41 +0000204 HWND owner, WNDPROC dlgProc )
Alexandre Julliard0e607781993-11-03 19:23:37 +0000205{
206 return CreateDialogParam( hInst, dlgTemplate, owner, dlgProc, 0 );
207}
208
209
210/***********************************************************************
211 * CreateDialogParam (USER.241)
212 */
Alexandre Julliarde2abbb11995-03-19 17:39:39 +0000213HWND CreateDialogParam( HINSTANCE hInst, SEGPTR dlgTemplate,
Alexandre Julliardaca05781994-10-17 18:12:41 +0000214 HWND owner, WNDPROC dlgProc, LPARAM param )
Alexandre Julliard0e607781993-11-03 19:23:37 +0000215{
216 HWND hwnd = 0;
Alexandre Julliard594997c1995-04-30 10:05:20 +0000217 HRSRC hRsrc;
218 HGLOBAL hmem;
Alexandre Julliardff8331e1995-09-18 11:19:54 +0000219 SEGPTR data;
Alexandre Julliard0e607781993-11-03 19:23:37 +0000220
Alexandre Julliardaf0bae51995-10-03 17:06:08 +0000221 dprintf_dialog(stddeb, "CreateDialogParam: "NPFMT",%08lx,"NPFMT",%08lx,%ld\n",
Alexandre Julliard2787be81995-05-22 18:23:01 +0000222 hInst, dlgTemplate, owner, (DWORD)dlgProc, param );
Alexandre Julliard5f721f81994-01-04 20:14:34 +0000223
Alexandre Julliard594997c1995-04-30 10:05:20 +0000224 if (!(hRsrc = FindResource( hInst, dlgTemplate, RT_DIALOG ))) return 0;
225 if (!(hmem = LoadResource( hInst, hRsrc ))) return 0;
Alexandre Julliardff8331e1995-09-18 11:19:54 +0000226 if (!(data = WIN16_LockResource( hmem ))) hwnd = 0;
Alexandre Julliard0e607781993-11-03 19:23:37 +0000227 else hwnd = CreateDialogIndirectParam(hInst, data, owner, dlgProc, param);
228 FreeResource( hmem );
Alexandre Julliard0e607781993-11-03 19:23:37 +0000229 return hwnd;
230}
231
232
233/***********************************************************************
234 * CreateDialogIndirect (USER.219)
235 */
Alexandre Julliardff8331e1995-09-18 11:19:54 +0000236HWND CreateDialogIndirect( HINSTANCE hInst, SEGPTR dlgTemplate,
Alexandre Julliardaca05781994-10-17 18:12:41 +0000237 HWND owner, WNDPROC dlgProc )
Alexandre Julliard0e607781993-11-03 19:23:37 +0000238{
239 return CreateDialogIndirectParam( hInst, dlgTemplate, owner, dlgProc, 0 );
240}
241
242
243/***********************************************************************
244 * CreateDialogIndirectParam (USER.242)
245 */
Alexandre Julliardff8331e1995-09-18 11:19:54 +0000246HWND CreateDialogIndirectParam( HINSTANCE hInst, SEGPTR dlgTemplate,
Alexandre Julliardaca05781994-10-17 18:12:41 +0000247 HWND owner, WNDPROC dlgProc, LPARAM param )
Alexandre Julliard0e607781993-11-03 19:23:37 +0000248{
Alexandre Julliardff8331e1995-09-18 11:19:54 +0000249 HMENU hMenu = 0;
Alexandre Julliard0e607781993-11-03 19:23:37 +0000250 HFONT hFont = 0;
Alexandre Julliardaca05781994-10-17 18:12:41 +0000251 HWND hwnd, hwndCtrl;
Alexandre Julliardcdd09231994-01-12 11:12:51 +0000252 RECT rect;
Alexandre Julliard0e607781993-11-03 19:23:37 +0000253 WND * wndPtr;
Alexandre Julliarde399fc31993-11-24 17:08:56 +0000254 int i;
Alexandre Julliard0e607781993-11-03 19:23:37 +0000255 DLGTEMPLATE template;
Alexandre Julliardff8331e1995-09-18 11:19:54 +0000256 SEGPTR headerPtr;
Alexandre Julliard0e607781993-11-03 19:23:37 +0000257 DIALOGINFO * dlgInfo;
Alexandre Julliardcdd09231994-01-12 11:12:51 +0000258 DWORD exStyle = 0;
Alexandre Julliard0e607781993-11-03 19:23:37 +0000259 WORD xUnit = xBaseUnit;
260 WORD yUnit = yBaseUnit;
Alexandre Julliard0e607781993-11-03 19:23:37 +0000261
Alexandre Julliarde399fc31993-11-24 17:08:56 +0000262 /* Parse dialog template */
263
264 if (!dlgTemplate) return 0;
Alexandre Julliardff8331e1995-09-18 11:19:54 +0000265 headerPtr = DIALOG_ParseTemplate( dlgTemplate, &template );
266 if (debugging_dialog) DIALOG_DisplayTemplate( &template );
Alexandre Julliard0e607781993-11-03 19:23:37 +0000267
268 /* Load menu */
269
Alexandre Julliardff8331e1995-09-18 11:19:54 +0000270 if (template.menuName) hMenu = LoadMenu( hInst, template.menuName );
Alexandre Julliard0e607781993-11-03 19:23:37 +0000271
272 /* Create custom font if needed */
273
Alexandre Julliardff8331e1995-09-18 11:19:54 +0000274 if (template.header.style & DS_SETFONT)
Alexandre Julliard0e607781993-11-03 19:23:37 +0000275 {
Alexandre Julliard3ed37e01994-11-07 18:20:42 +0000276 /* The font height must be negative as it is a point size */
277 /* (see CreateFont() documentation in the Windows SDK). */
278 hFont = CreateFont( -template.pointSize, 0, 0, 0, FW_DONTCARE,
Alexandre Julliard0e607781993-11-03 19:23:37 +0000279 FALSE, FALSE, FALSE, DEFAULT_CHARSET, 0, 0,
Alexandre Julliardff8331e1995-09-18 11:19:54 +0000280 DEFAULT_QUALITY, FF_DONTCARE,
281 (LPSTR)PTR_SEG_TO_LIN(template.faceName) );
Alexandre Julliard0e607781993-11-03 19:23:37 +0000282 if (hFont)
283 {
284 TEXTMETRIC tm;
285 HFONT oldFont;
286 HDC hdc;
287
Alexandre Julliardcdd09231994-01-12 11:12:51 +0000288 hdc = GetDC(0);
Alexandre Julliard0e607781993-11-03 19:23:37 +0000289 oldFont = SelectObject( hdc, hFont );
290 GetTextMetrics( hdc, &tm );
291 SelectObject( hdc, oldFont );
292 ReleaseDC( 0, hdc );
293 xUnit = tm.tmAveCharWidth;
294 yUnit = tm.tmHeight;
Alexandre Julliard7cbe6571995-01-09 18:21:16 +0000295 if (tm.tmPitchAndFamily & TMPF_FIXED_PITCH)
296 xBaseUnit = xBaseUnit * 5 / 4; /* See DIALOG_Init() */
Alexandre Julliard0e607781993-11-03 19:23:37 +0000297 }
298 }
Alexandre Julliarde399fc31993-11-24 17:08:56 +0000299
Alexandre Julliard0e607781993-11-03 19:23:37 +0000300 /* Create dialog main window */
301
Alexandre Julliardcdd09231994-01-12 11:12:51 +0000302 rect.left = rect.top = 0;
Alexandre Julliardff8331e1995-09-18 11:19:54 +0000303 rect.right = template.header.cx * xUnit / 4;
304 rect.bottom = template.header.cy * yUnit / 8;
305 if (template.header.style & DS_MODALFRAME) exStyle |= WS_EX_DLGMODALFRAME;
Alexandre Julliardaf0bae51995-10-03 17:06:08 +0000306 AdjustWindowRectEx( &rect, template.header.style,
307 hMenu ? TRUE : FALSE , exStyle );
Alexandre Julliardff8331e1995-09-18 11:19:54 +0000308 rect.right -= rect.left;
309 rect.bottom -= rect.top;
Alexandre Julliardcdd09231994-01-12 11:12:51 +0000310
Alexandre Julliardff8331e1995-09-18 11:19:54 +0000311 if ((INT)template.header.x == CW_USEDEFAULT)
312 rect.left = rect.top = CW_USEDEFAULT;
313 else
314 {
315 rect.left += template.header.x * xUnit / 4;
316 rect.top += template.header.y * yUnit / 8;
317 if (!(template.header.style & DS_ABSALIGN))
318 ClientToScreen( owner, (POINT *)&rect );
319 }
320
321 hwnd = CreateWindowEx( exStyle, template.className, template.caption,
322 template.header.style & ~WS_VISIBLE,
323 rect.left, rect.top, rect.right, rect.bottom,
Alexandre Julliarde2abbb11995-03-19 17:39:39 +0000324 owner, hMenu, hInst, (SEGPTR)0 );
Alexandre Julliard0e607781993-11-03 19:23:37 +0000325 if (!hwnd)
326 {
327 if (hFont) DeleteObject( hFont );
328 if (hMenu) DestroyMenu( hMenu );
Alexandre Julliard0e607781993-11-03 19:23:37 +0000329 return 0;
330 }
331
332 /* Create control windows */
333
Alexandre Julliardaca05781994-10-17 18:12:41 +0000334 dprintf_dialog(stddeb, " BEGIN\n" );
Alexandre Julliarde399fc31993-11-24 17:08:56 +0000335
Alexandre Julliard3f2abfa1994-08-16 15:43:11 +0000336 wndPtr = WIN_FindWndPtr( hwnd );
337 dlgInfo = (DIALOGINFO *)wndPtr->wExtra;
Alexandre Julliardaca05781994-10-17 18:12:41 +0000338 dlgInfo->msgResult = 0; /* This is used to store the default button id */
Alexandre Julliard3f2abfa1994-08-16 15:43:11 +0000339 dlgInfo->hDialogHeap = 0;
340
Alexandre Julliardff8331e1995-09-18 11:19:54 +0000341 for (i = 0; i < template.header.nbItems; i++)
Alexandre Julliard0e607781993-11-03 19:23:37 +0000342 {
Alexandre Julliardff8331e1995-09-18 11:19:54 +0000343 DLGCONTROLHEADER *header;
344 SEGPTR className, winName;
Alexandre Julliardaca05781994-10-17 18:12:41 +0000345 HWND hwndDefButton = 0;
Alexandre Julliardff8331e1995-09-18 11:19:54 +0000346 char buffer[10];
Alexandre Julliarde399fc31993-11-24 17:08:56 +0000347
Alexandre Julliardff8331e1995-09-18 11:19:54 +0000348 header = (DLGCONTROLHEADER *)PTR_SEG_TO_LIN( headerPtr );
349 headerPtr = DIALOG_GetControl( headerPtr, &className, &winName );
350
351 if (!HIWORD(className))
352 {
353 switch(LOWORD(className))
354 {
355 case 0x80: strcpy( buffer, "BUTTON" ); break;
356 case 0x81: strcpy( buffer, "EDIT" ); break;
357 case 0x82: strcpy( buffer, "STATIC" ); break;
358 case 0x83: strcpy( buffer, "LISTBOX" ); break;
359 case 0x84: strcpy( buffer, "SCROLLBAR" ); break;
360 case 0x85: strcpy( buffer, "COMBOBOX" ); break;
361 default: buffer[0] = '\0'; break;
362 }
363 className = MAKE_SEGPTR(buffer);
364 }
365
366 if (HIWORD(className))
367 dprintf_dialog(stddeb, " %s ", (char*)PTR_SEG_TO_LIN(className));
368 else dprintf_dialog(stddeb, " %04x ", LOWORD(className) );
369 if (HIWORD(winName))
370 dprintf_dialog(stddeb,"'%s'", (char *)PTR_SEG_TO_LIN(winName) );
371 else dprintf_dialog(stddeb,"%04x", LOWORD(winName) );
372
Alexandre Julliard3a405ba1994-10-30 16:25:19 +0000373 dprintf_dialog(stddeb," %d, %d, %d, %d, %d, %08lx\n",
Alexandre Julliardff8331e1995-09-18 11:19:54 +0000374 header->id, header->x, header->y,
375 header->cx, header->cy, header->style );
Alexandre Julliard3f2abfa1994-08-16 15:43:11 +0000376
Alexandre Julliardff8331e1995-09-18 11:19:54 +0000377 if (HIWORD(className) &&
378 !strcmp( (char *)PTR_SEG_TO_LIN(className), "EDIT") &&
379 ((header->style & DS_LOCALEDIT) != DS_LOCALEDIT))
380 {
381 if (!dlgInfo->hDialogHeap)
382 {
Alexandre Julliard3f2abfa1994-08-16 15:43:11 +0000383 dlgInfo->hDialogHeap = GlobalAlloc(GMEM_FIXED, 0x10000);
Alexandre Julliardff8331e1995-09-18 11:19:54 +0000384 if (!dlgInfo->hDialogHeap)
385 {
Alexandre Julliard3a405ba1994-10-30 16:25:19 +0000386 fprintf(stderr,"CreateDialogIndirectParam: Insufficient memory to create heap for edit control\n");
Alexandre Julliard3f2abfa1994-08-16 15:43:11 +0000387 continue;
388 }
Alexandre Julliarde2abbb11995-03-19 17:39:39 +0000389 LocalInit(dlgInfo->hDialogHeap, 0, 0xffff);
Alexandre Julliarde399fc31993-11-24 17:08:56 +0000390 }
Alexandre Julliardff8331e1995-09-18 11:19:54 +0000391 hwndCtrl = CreateWindowEx(WS_EX_NOPARENTNOTIFY, className, winName,
392 header->style | WS_CHILD,
393 header->x * xUnit / 4,
394 header->y * yUnit / 8,
395 header->cx * xUnit / 4,
396 header->cy * yUnit / 8,
Alexandre Julliardaf0bae51995-10-03 17:06:08 +0000397 hwnd, (HMENU)header->id,
398 dlgInfo->hDialogHeap, (SEGPTR)0 );
Alexandre Julliard3f2abfa1994-08-16 15:43:11 +0000399 }
Alexandre Julliardaca05781994-10-17 18:12:41 +0000400 else
401 {
Alexandre Julliardff8331e1995-09-18 11:19:54 +0000402 hwndCtrl = CreateWindowEx(WS_EX_NOPARENTNOTIFY, className, winName,
403 header->style | WS_CHILD,
404 header->x * xUnit / 4,
405 header->y * yUnit / 8,
406 header->cx * xUnit / 4,
407 header->cy * yUnit / 8,
Alexandre Julliardaf0bae51995-10-03 17:06:08 +0000408 hwnd, (HMENU)header->id,
409 hInst, (SEGPTR)0 );
Alexandre Julliard3f2abfa1994-08-16 15:43:11 +0000410 }
Alexandre Julliardff8331e1995-09-18 11:19:54 +0000411
Alexandre Julliardecc37121994-11-22 16:31:29 +0000412 /* Make the control last one in Z-order, so that controls remain
413 in the order in which they were created */
414 SetWindowPos( hwndCtrl, HWND_BOTTOM, 0, 0, 0, 0,
415 SWP_NOSIZE | SWP_NOMOVE | SWP_NOACTIVATE );
416
Alexandre Julliardaca05781994-10-17 18:12:41 +0000417 /* Send initialisation messages to the control */
Alexandre Julliardaf0bae51995-10-03 17:06:08 +0000418 if (hFont) SendMessage( hwndCtrl, WM_SETFONT, (WPARAM)hFont, 0 );
Alexandre Julliardaca05781994-10-17 18:12:41 +0000419 if (SendMessage( hwndCtrl, WM_GETDLGCODE, 0, 0 ) & DLGC_DEFPUSHBUTTON)
420 {
421 /* If there's already a default push-button, set it back */
422 /* to normal and use this one instead. */
423 if (hwndDefButton)
424 SendMessage( hwndDefButton, BM_SETSTYLE, BS_PUSHBUTTON, FALSE);
425 hwndDefButton = hwndCtrl;
Alexandre Julliardff8331e1995-09-18 11:19:54 +0000426 dlgInfo->msgResult = GetWindowWord( hwndCtrl, GWW_ID );
Alexandre Julliardaca05781994-10-17 18:12:41 +0000427 }
Alexandre Julliarde399fc31993-11-24 17:08:56 +0000428 }
429
Alexandre Julliardaca05781994-10-17 18:12:41 +0000430 dprintf_dialog(stddeb, " END\n" );
Alexandre Julliard0e607781993-11-03 19:23:37 +0000431
432 /* Initialise dialog extra data */
433
Alexandre Julliard0e607781993-11-03 19:23:37 +0000434 dlgInfo->dlgProc = dlgProc;
435 dlgInfo->hUserFont = hFont;
436 dlgInfo->hMenu = hMenu;
437 dlgInfo->xBaseUnit = xUnit;
438 dlgInfo->yBaseUnit = yUnit;
Alexandre Julliardaca05781994-10-17 18:12:41 +0000439 dlgInfo->hwndFocus = DIALOG_GetFirstTabItem( hwnd );
Alexandre Julliard0e607781993-11-03 19:23:37 +0000440
441 /* Send initialisation messages and set focus */
442
Alexandre Julliard58199531994-04-21 01:20:00 +0000443 if (dlgInfo->hUserFont)
Alexandre Julliardaf0bae51995-10-03 17:06:08 +0000444 SendMessage( hwnd, WM_SETFONT, (WPARAM)dlgInfo->hUserFont, 0 );
445 if (SendMessage( hwnd, WM_INITDIALOG, (WPARAM)dlgInfo->hwndFocus, param ))
Alexandre Julliard58199531994-04-21 01:20:00 +0000446 SetFocus( dlgInfo->hwndFocus );
Alexandre Julliardff8331e1995-09-18 11:19:54 +0000447 if (template.header.style & WS_VISIBLE) ShowWindow(hwnd, SW_SHOW);
Alexandre Julliard0e607781993-11-03 19:23:37 +0000448 return hwnd;
449}
450
451
452/***********************************************************************
Alexandre Julliarde399fc31993-11-24 17:08:56 +0000453 * DIALOG_DoDialogBox
Alexandre Julliard0e607781993-11-03 19:23:37 +0000454 */
Alexandre Julliard3f2abfa1994-08-16 15:43:11 +0000455static int DIALOG_DoDialogBox( HWND hwnd, HWND owner )
Alexandre Julliard0e607781993-11-03 19:23:37 +0000456{
Alexandre Julliard0e607781993-11-03 19:23:37 +0000457 WND * wndPtr;
458 DIALOGINFO * dlgInfo;
Alexandre Julliard58199531994-04-21 01:20:00 +0000459 HANDLE msgHandle;
460 MSG* lpmsg;
Alexandre Julliard0e607781993-11-03 19:23:37 +0000461 int retval;
462
Alexandre Julliardaca05781994-10-17 18:12:41 +0000463 /* Owner must be a top-level window */
Alexandre Julliarde2991ea1995-07-29 13:09:43 +0000464 owner = WIN_GetTopParent( owner );
Alexandre Julliarde399fc31993-11-24 17:08:56 +0000465 if (!(wndPtr = WIN_FindWndPtr( hwnd ))) return -1;
Alexandre Julliarde2abbb11995-03-19 17:39:39 +0000466 if (!(msgHandle = USER_HEAP_ALLOC( sizeof(MSG) ))) return -1;
467 lpmsg = (MSG *) USER_HEAP_LIN_ADDR( msgHandle );
Alexandre Julliard0e607781993-11-03 19:23:37 +0000468 dlgInfo = (DIALOGINFO *)wndPtr->wExtra;
Alexandre Julliardaca05781994-10-17 18:12:41 +0000469 EnableWindow( owner, FALSE );
Alexandre Julliarde399fc31993-11-24 17:08:56 +0000470 ShowWindow( hwnd, SW_SHOW );
471
Alexandre Julliarde2abbb11995-03-19 17:39:39 +0000472 while (MSG_InternalGetMessage( USER_HEAP_SEG_ADDR(msgHandle), hwnd, owner,
Alexandre Julliardaca05781994-10-17 18:12:41 +0000473 MSGF_DIALOGBOX, PM_REMOVE,
474 !(wndPtr->dwStyle & DS_NOIDLEMSG) ))
Alexandre Julliard0e607781993-11-03 19:23:37 +0000475 {
Alexandre Julliard58199531994-04-21 01:20:00 +0000476 if (!IsDialogMessage( hwnd, lpmsg))
Alexandre Julliard0e607781993-11-03 19:23:37 +0000477 {
Alexandre Julliard58199531994-04-21 01:20:00 +0000478 TranslateMessage( lpmsg );
479 DispatchMessage( lpmsg );
Alexandre Julliard0e607781993-11-03 19:23:37 +0000480 }
481 if (dlgInfo->fEnd) break;
482 }
483 retval = dlgInfo->msgResult;
484 DestroyWindow( hwnd );
Alexandre Julliard58199531994-04-21 01:20:00 +0000485 USER_HEAP_FREE( msgHandle );
Alexandre Julliardaca05781994-10-17 18:12:41 +0000486 EnableWindow( owner, TRUE );
Alexandre Julliard0e607781993-11-03 19:23:37 +0000487 return retval;
488}
489
490
491/***********************************************************************
Alexandre Julliarde399fc31993-11-24 17:08:56 +0000492 * DialogBox (USER.87)
493 */
Alexandre Julliarde2abbb11995-03-19 17:39:39 +0000494int DialogBox( HINSTANCE hInst, SEGPTR dlgTemplate,
Alexandre Julliardaca05781994-10-17 18:12:41 +0000495 HWND owner, WNDPROC dlgProc )
Alexandre Julliarde399fc31993-11-24 17:08:56 +0000496{
497 return DialogBoxParam( hInst, dlgTemplate, owner, dlgProc, 0 );
498}
499
500
501/***********************************************************************
502 * DialogBoxParam (USER.239)
503 */
Alexandre Julliarde2abbb11995-03-19 17:39:39 +0000504int DialogBoxParam( HINSTANCE hInst, SEGPTR dlgTemplate,
Alexandre Julliardaca05781994-10-17 18:12:41 +0000505 HWND owner, WNDPROC dlgProc, LPARAM param )
Alexandre Julliarde399fc31993-11-24 17:08:56 +0000506{
507 HWND hwnd;
508
Alexandre Julliardaf0bae51995-10-03 17:06:08 +0000509 dprintf_dialog(stddeb, "DialogBoxParam: "NPFMT",%08lx,"NPFMT",%08lx,%ld\n",
Alexandre Julliard2787be81995-05-22 18:23:01 +0000510 hInst, dlgTemplate, owner, (DWORD)dlgProc, param );
Alexandre Julliarde399fc31993-11-24 17:08:56 +0000511 hwnd = CreateDialogParam( hInst, dlgTemplate, owner, dlgProc, param );
Alexandre Julliard3f2abfa1994-08-16 15:43:11 +0000512 if (hwnd) return DIALOG_DoDialogBox( hwnd, owner );
Alexandre Julliarde399fc31993-11-24 17:08:56 +0000513 return -1;
514}
515
516
517/***********************************************************************
518 * DialogBoxIndirect (USER.218)
519 */
520int DialogBoxIndirect( HINSTANCE hInst, HANDLE dlgTemplate,
Alexandre Julliardaca05781994-10-17 18:12:41 +0000521 HWND owner, WNDPROC dlgProc )
Alexandre Julliarde399fc31993-11-24 17:08:56 +0000522{
523 return DialogBoxIndirectParam( hInst, dlgTemplate, owner, dlgProc, 0 );
524}
525
526
527/***********************************************************************
528 * DialogBoxIndirectParam (USER.240)
529 */
530int DialogBoxIndirectParam( HINSTANCE hInst, HANDLE dlgTemplate,
Alexandre Julliardaca05781994-10-17 18:12:41 +0000531 HWND owner, WNDPROC dlgProc, LPARAM param )
Alexandre Julliarde399fc31993-11-24 17:08:56 +0000532{
533 HWND hwnd;
Alexandre Julliardff8331e1995-09-18 11:19:54 +0000534 SEGPTR ptr;
Alexandre Julliarde399fc31993-11-24 17:08:56 +0000535
Alexandre Julliardaf0bae51995-10-03 17:06:08 +0000536 if (!(ptr = (SEGPTR)WIN16_GlobalLock( dlgTemplate ))) return -1;
Alexandre Julliarde399fc31993-11-24 17:08:56 +0000537 hwnd = CreateDialogIndirectParam( hInst, ptr, owner, dlgProc, param );
538 GlobalUnlock( dlgTemplate );
Alexandre Julliard3f2abfa1994-08-16 15:43:11 +0000539 if (hwnd) return DIALOG_DoDialogBox( hwnd, owner );
Alexandre Julliarde399fc31993-11-24 17:08:56 +0000540 return -1;
541}
542
Alexandre Julliard7cbe6571995-01-09 18:21:16 +0000543
Alexandre Julliard3ed37e01994-11-07 18:20:42 +0000544/***********************************************************************
Alexandre Julliard0e607781993-11-03 19:23:37 +0000545 * EndDialog (USER.88)
546 */
547void EndDialog( HWND hwnd, short retval )
548{
549 WND * wndPtr = WIN_FindWndPtr( hwnd );
550 DIALOGINFO * dlgInfo = (DIALOGINFO *)wndPtr->wExtra;
551 dlgInfo->msgResult = retval;
552 dlgInfo->fEnd = TRUE;
Alexandre Julliardaf0bae51995-10-03 17:06:08 +0000553 dprintf_dialog(stddeb, "EndDialog: "NPFMT" %d\n", hwnd, retval );
Alexandre Julliard0e607781993-11-03 19:23:37 +0000554}
555
556
557/***********************************************************************
558 * IsDialogMessage (USER.90)
559 */
560BOOL IsDialogMessage( HWND hwndDlg, LPMSG msg )
561{
562 WND * wndPtr;
Alexandre Julliardaca05781994-10-17 18:12:41 +0000563 int dlgCode;
564
Alexandre Julliard0e607781993-11-03 19:23:37 +0000565 if (!(wndPtr = WIN_FindWndPtr( hwndDlg ))) return FALSE;
566 if ((hwndDlg != msg->hwnd) && !IsChild( hwndDlg, msg->hwnd )) return FALSE;
567
Alexandre Julliardaca05781994-10-17 18:12:41 +0000568 /* Only the key messages get special processing */
Alexandre Julliard7cbe6571995-01-09 18:21:16 +0000569 if ((msg->message != WM_KEYDOWN) &&
570 (msg->message != WM_SYSCHAR) &&
571 (msg->message != WM_CHAR))
572 return FALSE;
573
574 dlgCode = SendMessage( msg->hwnd, WM_GETDLGCODE, 0, 0 );
575 if (dlgCode & DLGC_WANTMESSAGE)
Alexandre Julliard0e607781993-11-03 19:23:37 +0000576 {
Alexandre Julliard7cbe6571995-01-09 18:21:16 +0000577 DispatchMessage( msg );
578 return TRUE;
Alexandre Julliard0e607781993-11-03 19:23:37 +0000579 }
Alexandre Julliardaca05781994-10-17 18:12:41 +0000580
581 switch(msg->message)
Alexandre Julliard0e607781993-11-03 19:23:37 +0000582 {
Alexandre Julliardaca05781994-10-17 18:12:41 +0000583 case WM_KEYDOWN:
584 if (dlgCode & DLGC_WANTALLKEYS) break;
585 switch(msg->wParam)
586 {
587 case VK_TAB:
588 if (!(dlgCode & DLGC_WANTTAB))
589 {
590 SendMessage( hwndDlg, WM_NEXTDLGCTL,
Alexandre Julliardecc37121994-11-22 16:31:29 +0000591 (GetKeyState(VK_SHIFT) & 0x80), 0 );
Alexandre Julliardaca05781994-10-17 18:12:41 +0000592 return TRUE;
593 }
594 break;
595
596 case VK_RIGHT:
597 case VK_DOWN:
598 if (!(dlgCode & DLGC_WANTARROWS))
599 {
Alexandre Julliardecc37121994-11-22 16:31:29 +0000600 SetFocus(GetNextDlgGroupItem(hwndDlg,GetFocus(),FALSE));
Alexandre Julliardaca05781994-10-17 18:12:41 +0000601 return TRUE;
602 }
603 break;
604
605 case VK_LEFT:
606 case VK_UP:
607 if (!(dlgCode & DLGC_WANTARROWS))
608 {
Alexandre Julliardecc37121994-11-22 16:31:29 +0000609 SetFocus(GetNextDlgGroupItem(hwndDlg,GetFocus(),TRUE));
Alexandre Julliardaca05781994-10-17 18:12:41 +0000610 return TRUE;
611 }
612 break;
613
614 case VK_ESCAPE:
Alexandre Julliardaf0bae51995-10-03 17:06:08 +0000615#ifdef WINELIB32
616 SendMessage( hwndDlg, WM_COMMAND,
617 MAKEWPARAM( IDCANCEL, 0 ),
618 (LPARAM)GetDlgItem(hwndDlg,IDCANCEL) );
619#else
Alexandre Julliardaca05781994-10-17 18:12:41 +0000620 SendMessage( hwndDlg, WM_COMMAND, IDCANCEL,
621 MAKELPARAM( GetDlgItem(hwndDlg,IDCANCEL), 0 ));
Alexandre Julliardaf0bae51995-10-03 17:06:08 +0000622#endif
Alexandre Julliardaca05781994-10-17 18:12:41 +0000623 break;
624
625 case VK_RETURN:
626 {
627 DWORD dw = SendMessage( hwndDlg, DM_GETDEFID, 0, 0 );
628 if (HIWORD(dw) == DC_HASDEFID)
Alexandre Julliardaf0bae51995-10-03 17:06:08 +0000629#ifdef WINELIB32
630 SendMessage( hwndDlg, WM_COMMAND,
631 MAKEWPARAM( LOWORD(dw), BN_CLICKED ),
632 (LPARAM)GetDlgItem( hwndDlg, LOWORD(dw) ) );
633 else
634 SendMessage( hwndDlg, WM_COMMAND,
635 MAKEWPARAM( IDOK, 0 ),
636 (LPARAM)GetDlgItem(hwndDlg,IDOK) );
637#else
Alexandre Julliardaca05781994-10-17 18:12:41 +0000638 SendMessage( hwndDlg, WM_COMMAND, LOWORD(dw),
639 MAKELPARAM( GetDlgItem( hwndDlg, LOWORD(dw) ),
640 BN_CLICKED ));
641 else
642 SendMessage( hwndDlg, WM_COMMAND, IDOK,
643 MAKELPARAM( GetDlgItem(hwndDlg,IDOK), 0 ));
Alexandre Julliardaf0bae51995-10-03 17:06:08 +0000644#endif
Alexandre Julliardaca05781994-10-17 18:12:41 +0000645 }
646 break;
647 }
648 break; /* case WM_KEYDOWN */
649
650
651 case WM_CHAR:
652 if (dlgCode & (DLGC_WANTALLKEYS | DLGC_WANTCHARS)) break;
653 break;
654
655 case WM_SYSCHAR:
656 if (dlgCode & DLGC_WANTALLKEYS) break;
657 break;
Alexandre Julliard0e607781993-11-03 19:23:37 +0000658 }
Alexandre Julliardaca05781994-10-17 18:12:41 +0000659
660 /* If we get here, the message has not been treated specially */
661 /* and can be sent to its destination window. */
662 DispatchMessage( msg );
Alexandre Julliard0e607781993-11-03 19:23:37 +0000663 return TRUE;
664}
665
666
667/****************************************************************
668 * GetDlgCtrlID (USER.277)
669 */
670int GetDlgCtrlID( HWND hwnd )
671{
672 WND *wndPtr = WIN_FindWndPtr(hwnd);
673 if (wndPtr) return wndPtr->wIDmenu;
674 else return 0;
675}
676
677
678/***********************************************************************
679 * GetDlgItem (USER.91)
680 */
681HWND GetDlgItem( HWND hwndDlg, WORD id )
682{
683 HWND curChild;
684 WND * childPtr;
685 WND * wndPtr;
686
687 if (!(wndPtr = WIN_FindWndPtr( hwndDlg ))) return 0;
688 curChild = wndPtr->hwndChild;
689 while(curChild)
690 {
691 childPtr = WIN_FindWndPtr( curChild );
692 if (childPtr->wIDmenu == id) return curChild;
693 curChild = childPtr->hwndNext;
694 }
695 return 0;
696}
697
698
699/*******************************************************************
700 * SendDlgItemMessage (USER.101)
701 */
Alexandre Julliardaf0bae51995-10-03 17:06:08 +0000702LRESULT SendDlgItemMessage(HWND hwnd, INT id, UINT msg, WPARAM wParam, LPARAM lParam)
Alexandre Julliard0e607781993-11-03 19:23:37 +0000703{
704 HWND hwndCtrl = GetDlgItem( hwnd, id );
705 if (hwndCtrl) return SendMessage( hwndCtrl, msg, wParam, lParam );
706 else return 0;
707}
708
709
710/*******************************************************************
711 * SetDlgItemText (USER.92)
712 */
Alexandre Julliarde2abbb11995-03-19 17:39:39 +0000713void SetDlgItemText( HWND hwnd, WORD id, SEGPTR lpString )
Alexandre Julliard0e607781993-11-03 19:23:37 +0000714{
715 SendDlgItemMessage( hwnd, id, WM_SETTEXT, 0, (DWORD)lpString );
716}
717
718
719/***********************************************************************
720 * GetDlgItemText (USER.93)
721 */
Alexandre Julliarde2abbb11995-03-19 17:39:39 +0000722int GetDlgItemText( HWND hwnd, WORD id, SEGPTR str, WORD max )
Alexandre Julliard0e607781993-11-03 19:23:37 +0000723{
724 return (int)SendDlgItemMessage( hwnd, id, WM_GETTEXT, max, (DWORD)str );
725}
726
727
728/*******************************************************************
729 * SetDlgItemInt (USER.94)
730 */
731void SetDlgItemInt( HWND hwnd, WORD id, WORD value, BOOL fSigned )
732{
Alexandre Julliard2787be81995-05-22 18:23:01 +0000733 char str[20];
Alexandre Julliard0e607781993-11-03 19:23:37 +0000734
Alexandre Julliard2787be81995-05-22 18:23:01 +0000735 if (fSigned) sprintf( str, "%d", (int)value );
Alexandre Julliard0e607781993-11-03 19:23:37 +0000736 else sprintf( str, "%u", value );
Alexandre Julliard2787be81995-05-22 18:23:01 +0000737 SendDlgItemMessage( hwnd, id, WM_SETTEXT, 0, MAKE_SEGPTR(str) );
Alexandre Julliard0e607781993-11-03 19:23:37 +0000738}
739
740
741/***********************************************************************
742 * GetDlgItemInt (USER.95)
743 */
744WORD GetDlgItemInt( HWND hwnd, WORD id, BOOL * translated, BOOL fSigned )
745{
Alexandre Julliard2787be81995-05-22 18:23:01 +0000746 char str[30];
Alexandre Julliard3ed37e01994-11-07 18:20:42 +0000747 long result = 0;
Alexandre Julliard0e607781993-11-03 19:23:37 +0000748
749 if (translated) *translated = FALSE;
Alexandre Julliard2787be81995-05-22 18:23:01 +0000750 if (SendDlgItemMessage( hwnd, id, WM_GETTEXT, 30, MAKE_SEGPTR(str) ))
Alexandre Julliard0e607781993-11-03 19:23:37 +0000751 {
752 char * endptr;
753 result = strtol( str, &endptr, 10 );
754 if (endptr && (endptr != str)) /* Conversion was successful */
755 {
756 if (fSigned)
757 {
758 if ((result < -32767) || (result > 32767)) result = 0;
759 else if (translated) *translated = TRUE;
760 }
761 else
762 {
763 if ((result < 0) || (result > 65535)) result = 0;
764 else if (translated) *translated = TRUE;
765 }
766 }
767 }
Alexandre Julliard0e607781993-11-03 19:23:37 +0000768 return (WORD)result;
769}
770
771
772/***********************************************************************
773 * CheckDlgButton (USER.97)
774 */
775void CheckDlgButton( HWND hwnd, WORD id, WORD check )
776{
777 SendDlgItemMessage( hwnd, id, BM_SETCHECK, check, 0 );
778}
779
780
781/***********************************************************************
782 * IsDlgButtonChecked (USER.98)
783 */
784WORD IsDlgButtonChecked( HWND hwnd, WORD id )
785{
786 return (WORD)SendDlgItemMessage( hwnd, id, BM_GETCHECK, 0, 0 );
787}
788
789
790/***********************************************************************
791 * CheckRadioButton (USER.96)
792 */
793void CheckRadioButton( HWND hwndDlg, WORD firstID, WORD lastID, WORD checkID )
794{
Alexandre Julliardecc37121994-11-22 16:31:29 +0000795 HWND button = GetWindow( hwndDlg, GW_CHILD );
796 WND *wndPtr;
797
798 while (button)
Alexandre Julliard0e607781993-11-03 19:23:37 +0000799 {
Alexandre Julliardecc37121994-11-22 16:31:29 +0000800 if (!(wndPtr = WIN_FindWndPtr( button ))) return;
801 if ((wndPtr->wIDmenu == firstID) || (wndPtr->wIDmenu == lastID)) break;
802 button = wndPtr->hwndNext;
803 }
804 if (!button) return;
805
806 if (wndPtr->wIDmenu == lastID)
807 lastID = firstID; /* Buttons are in reverse order */
808 while (button)
809 {
810 if (!(wndPtr = WIN_FindWndPtr( button ))) return;
Alexandre Julliard0e607781993-11-03 19:23:37 +0000811 SendMessage( button, BM_SETCHECK, (wndPtr->wIDmenu == checkID), 0 );
Alexandre Julliardecc37121994-11-22 16:31:29 +0000812 if (wndPtr->wIDmenu == lastID) break;
Alexandre Julliard0e607781993-11-03 19:23:37 +0000813 button = wndPtr->hwndNext;
814 }
815}
816
817
818/***********************************************************************
819 * GetDialogBaseUnits (USER.243)
820 */
821DWORD GetDialogBaseUnits()
822{
823 return MAKELONG( xBaseUnit, yBaseUnit );
824}
825
826
827/***********************************************************************
828 * MapDialogRect (USER.103)
829 */
830void MapDialogRect( HWND hwnd, LPRECT rect )
831{
832 DIALOGINFO * dlgInfo;
833 WND * wndPtr = WIN_FindWndPtr( hwnd );
834 if (!wndPtr) return;
835 dlgInfo = (DIALOGINFO *)wndPtr->wExtra;
836 rect->left = (rect->left * dlgInfo->xBaseUnit) / 4;
837 rect->right = (rect->right * dlgInfo->xBaseUnit) / 4;
838 rect->top = (rect->top * dlgInfo->yBaseUnit) / 8;
839 rect->bottom = (rect->bottom * dlgInfo->yBaseUnit) / 8;
840}
841
842
843/***********************************************************************
844 * GetNextDlgGroupItem (USER.227)
845 */
846HWND GetNextDlgGroupItem( HWND hwndDlg, HWND hwndCtrl, BOOL fPrevious )
847{
Alexandre Julliardaca05781994-10-17 18:12:41 +0000848 HWND hwnd, hwndStart;
Alexandre Julliard0e607781993-11-03 19:23:37 +0000849 WND * dlgPtr, * ctrlPtr, * wndPtr;
850
851 if (!(dlgPtr = WIN_FindWndPtr( hwndDlg ))) return 0;
852 if (!(ctrlPtr = WIN_FindWndPtr( hwndCtrl ))) return 0;
853 if (ctrlPtr->hwndParent != hwndDlg) return 0;
854
Alexandre Julliardaca05781994-10-17 18:12:41 +0000855 if (!fPrevious && ctrlPtr->hwndNext) /*Check if next control is in group*/
Alexandre Julliard0e607781993-11-03 19:23:37 +0000856 {
Alexandre Julliardaca05781994-10-17 18:12:41 +0000857 wndPtr = WIN_FindWndPtr( ctrlPtr->hwndNext );
858 if (!(wndPtr->dwStyle & WS_GROUP)) return ctrlPtr->hwndNext;
859 }
860
Alexandre Julliardaca05781994-10-17 18:12:41 +0000861 /* Now we will have to find the start of the group */
862
Alexandre Julliardecc37121994-11-22 16:31:29 +0000863 hwndStart = hwnd = dlgPtr->hwndChild;
Alexandre Julliardaca05781994-10-17 18:12:41 +0000864 while (hwnd)
865 {
Alexandre Julliard0e607781993-11-03 19:23:37 +0000866 wndPtr = WIN_FindWndPtr( hwnd );
Alexandre Julliardaca05781994-10-17 18:12:41 +0000867 if (wndPtr->dwStyle & WS_GROUP) hwndStart = hwnd; /*Start of a group*/
Alexandre Julliard808cb041995-08-17 17:11:36 +0000868 if (hwnd == hwndCtrl) break;
Alexandre Julliard0e607781993-11-03 19:23:37 +0000869 hwnd = wndPtr->hwndNext;
870 }
Alexandre Julliard808cb041995-08-17 17:11:36 +0000871
872 if (!hwnd) fprintf(stderr, "GetNextDlgGroupItem: hwnd not in dialog!\n");
873
874 /* only case left for forward search: wraparound */
875 if (!fPrevious) return hwndStart;
876
877 hwnd = hwndStart;
878 wndPtr = WIN_FindWndPtr( hwnd );
879 hwnd = wndPtr->hwndNext;
880 while (hwnd && (hwnd != hwndCtrl))
881 {
882 wndPtr = WIN_FindWndPtr( hwnd );
883 if (wndPtr->dwStyle & WS_GROUP) break;
884 hwndStart = hwnd;
885 hwnd = wndPtr->hwndNext;
886 }
887 return hwndStart;
Alexandre Julliard0e607781993-11-03 19:23:37 +0000888}
889
890
891/***********************************************************************
892 * GetNextDlgTabItem (USER.228)
893 */
894HWND GetNextDlgTabItem( HWND hwndDlg, HWND hwndCtrl, BOOL fPrevious )
895{
896 HWND hwnd, hwndLast;
897 WND * dlgPtr, * ctrlPtr, * wndPtr;
898
899 if (!(dlgPtr = WIN_FindWndPtr( hwndDlg ))) return 0;
900 if (!(ctrlPtr = WIN_FindWndPtr( hwndCtrl ))) return 0;
901 if (ctrlPtr->hwndParent != hwndDlg) return 0;
902
903 hwndLast = hwndCtrl;
904 hwnd = ctrlPtr->hwndNext;
905 while (1)
906 {
907 if (!hwnd) hwnd = dlgPtr->hwndChild;
908 if (hwnd == hwndCtrl) break;
909 wndPtr = WIN_FindWndPtr( hwnd );
Alexandre Julliard2787be81995-05-22 18:23:01 +0000910 if ((wndPtr->dwStyle & WS_TABSTOP) && (wndPtr->dwStyle & WS_VISIBLE))
Alexandre Julliard0e607781993-11-03 19:23:37 +0000911 {
912 hwndLast = hwnd;
913 if (!fPrevious) break;
914 }
915 hwnd = wndPtr->hwndNext;
916 }
917 return hwndLast;
918}