1 | /* $Id: win32dlg.cpp,v 1.16 1999-10-17 12:17:44 cbratschi Exp $ */
|
---|
2 | /*
|
---|
3 | * Win32 Dialog Code for OS/2
|
---|
4 | *
|
---|
5 | * Copyright 1999 Sander van Leeuwen (sandervl@xs4all.nl) (Wine port & OS/2 adaption)
|
---|
6 | *
|
---|
7 | * Based on Wine code (990815; windows\dialog.c)
|
---|
8 | *
|
---|
9 | * Copyright 1993, 1994, 1996 Alexandre Julliard
|
---|
10 | *
|
---|
11 | * Project Odin Software License can be found in LICENSE.TXT
|
---|
12 | *
|
---|
13 | */
|
---|
14 | #include <os2win.h>
|
---|
15 | #include <windowsx.h>
|
---|
16 | #include <stdlib.h>
|
---|
17 | #include <string.h>
|
---|
18 | #include <misc.h>
|
---|
19 | #include <win32dlg.h>
|
---|
20 | #include "oslibmsg.h"
|
---|
21 | #include "win32wdesktop.h"
|
---|
22 |
|
---|
23 | #define DEFAULT_DLGFONT "9.WarpSans"
|
---|
24 |
|
---|
25 | //******************************************************************************
|
---|
26 | //******************************************************************************
|
---|
27 | Win32Dialog::Win32Dialog(HINSTANCE hInst, LPCSTR dlgTemplate, HWND owner,
|
---|
28 | DLGPROC dlgProc, LPARAM param, BOOL isUnicode)
|
---|
29 | : Win32BaseWindow(OBJTYPE_DIALOG)
|
---|
30 | {
|
---|
31 | RECT rect;
|
---|
32 | WORD style;
|
---|
33 | ATOM classAtom;
|
---|
34 |
|
---|
35 | this->isUnicode = isUnicode;
|
---|
36 | hUserFont = 0;
|
---|
37 | hMenu = 0;
|
---|
38 | hwndFocus = 0;
|
---|
39 | Win32DlgProc = 0;
|
---|
40 | msgResult = 0;
|
---|
41 | userDlgData = 0;
|
---|
42 | idResult = 0;
|
---|
43 | dialogFlags = 0;
|
---|
44 | memset(&dlgInfo, 0, sizeof(dlgInfo));
|
---|
45 |
|
---|
46 | dprintf(("********* CREATE DIALOG ************"));
|
---|
47 | if(fInitialized == FALSE) {
|
---|
48 | if(DIALOG_Init() == FALSE) {
|
---|
49 | dprintf(("DIALOG_Init FAILED!"));
|
---|
50 | DebugInt3();
|
---|
51 | SetLastError(ERROR_GEN_FAILURE);
|
---|
52 | return;
|
---|
53 | }
|
---|
54 | fInitialized = TRUE;
|
---|
55 | }
|
---|
56 | xUnit = xBaseUnit;
|
---|
57 | yUnit = yBaseUnit;
|
---|
58 |
|
---|
59 | /* Parse dialog template */
|
---|
60 | dlgTemplate = parseTemplate(dlgTemplate, &dlgInfo);
|
---|
61 |
|
---|
62 | /* Load menu */
|
---|
63 | if (dlgInfo.menuName)
|
---|
64 | {
|
---|
65 | hMenu = LoadMenuW( hInst, (LPCWSTR)dlgInfo.menuName );
|
---|
66 | }
|
---|
67 |
|
---|
68 | /* Create custom font if needed */
|
---|
69 | if (dlgInfo.style & DS_SETFONT)
|
---|
70 | {
|
---|
71 | /* The font height must be negative as it is a point size */
|
---|
72 | /* (see CreateFont() documentation in the Windows SDK). */
|
---|
73 | hUserFont = CreateFontW(dlgInfo.pointSize*2, 0, 0, 0,
|
---|
74 | dlgInfo.weight, dlgInfo.italic, FALSE,
|
---|
75 | FALSE, DEFAULT_CHARSET, 0, 0, PROOF_QUALITY,
|
---|
76 | FF_DONTCARE, (LPCWSTR)dlgInfo.faceName );
|
---|
77 | if (hUserFont)
|
---|
78 | {
|
---|
79 | SIZE charSize;
|
---|
80 | getCharSize(hUserFont,&charSize);
|
---|
81 | xBaseUnit = charSize.cx;
|
---|
82 | yBaseUnit = charSize.cy;
|
---|
83 | }
|
---|
84 | }
|
---|
85 |
|
---|
86 | /* Create dialog main window */
|
---|
87 | rect.left = rect.top = 0;
|
---|
88 | rect.right = dlgInfo.cx * xUnit / 4;
|
---|
89 | rect.bottom = dlgInfo.cy * yUnit / 8;
|
---|
90 | if (dlgInfo.style & DS_MODALFRAME)
|
---|
91 | dlgInfo.exStyle |= WS_EX_DLGMODALFRAME;
|
---|
92 |
|
---|
93 | AdjustWindowRectEx( &rect, dlgInfo.style, hMenu ? TRUE : FALSE , dlgInfo.exStyle );
|
---|
94 | rect.right -= rect.left;
|
---|
95 | rect.bottom -= rect.top;
|
---|
96 |
|
---|
97 | if ((INT16)dlgInfo.x == CW_USEDEFAULT16)
|
---|
98 | {
|
---|
99 | rect.left = rect.top = CW_USEDEFAULT;
|
---|
100 | }
|
---|
101 | else
|
---|
102 | {
|
---|
103 | if (dlgInfo.style & DS_CENTER)
|
---|
104 | {
|
---|
105 | rect.left = (GetSystemMetrics(SM_CXSCREEN) - rect.right) / 2;
|
---|
106 | rect.top = (GetSystemMetrics(SM_CYSCREEN) - rect.bottom) / 2;
|
---|
107 | }
|
---|
108 | else
|
---|
109 | {
|
---|
110 | rect.left += dlgInfo.x * xUnit / 4;
|
---|
111 | rect.top += dlgInfo.y * yUnit / 8;
|
---|
112 | }
|
---|
113 | if ( !(dlgInfo.style & WS_CHILD) )
|
---|
114 | {
|
---|
115 | INT dX, dY;
|
---|
116 |
|
---|
117 | if( !(dlgInfo.style & DS_ABSALIGN) )
|
---|
118 | ClientToScreen(owner, (POINT *)&rect );
|
---|
119 |
|
---|
120 | /* try to fit it into the desktop */
|
---|
121 |
|
---|
122 | if( (dX = rect.left + rect.right + GetSystemMetrics(SM_CXDLGFRAME)
|
---|
123 | - GetSystemMetrics(SM_CXSCREEN)) > 0 ) rect.left -= dX;
|
---|
124 | if( (dY = rect.top + rect.bottom + GetSystemMetrics(SM_CYDLGFRAME)
|
---|
125 | - GetSystemMetrics(SM_CYSCREEN)) > 0 ) rect.top -= dY;
|
---|
126 | if( rect.left < 0 ) rect.left = 0;
|
---|
127 | if( rect.top < 0 ) rect.top = 0;
|
---|
128 | }
|
---|
129 | }
|
---|
130 |
|
---|
131 | /* Create the dialog window */
|
---|
132 |
|
---|
133 | /* Find the class atom */
|
---|
134 | if (!HIWORD(dlgInfo.className))
|
---|
135 | {
|
---|
136 | classAtom = (ATOM)LOWORD(dlgInfo.className);
|
---|
137 | }
|
---|
138 | else
|
---|
139 | if(!(classAtom = GlobalFindAtomW((LPWSTR)dlgInfo.className)))
|
---|
140 | {
|
---|
141 | SetLastError(ERROR_INVALID_PARAMETER);
|
---|
142 | return;
|
---|
143 | }
|
---|
144 | CREATESTRUCTA cs;
|
---|
145 | cs.lpCreateParams = NULL;
|
---|
146 | cs.hInstance = hInst;
|
---|
147 | cs.hMenu = hMenu;
|
---|
148 | cs.hwndParent = owner;
|
---|
149 | cs.x = rect.left;
|
---|
150 | cs.y = rect.top;
|
---|
151 | cs.cx = rect.right;
|
---|
152 | cs.cy = rect.bottom;
|
---|
153 | cs.style = dlgInfo.style & ~WS_VISIBLE;
|
---|
154 | if(!isUnicode) {
|
---|
155 | if(dlgInfo.caption) {
|
---|
156 | cs.lpszName = UnicodeToAsciiString((LPWSTR)dlgInfo.caption);
|
---|
157 | }
|
---|
158 | else cs.lpszName = 0;
|
---|
159 | if(HIWORD(cs.lpszClass)) {
|
---|
160 | cs.lpszClass = UnicodeToAsciiString((LPWSTR)dlgInfo.className);
|
---|
161 | }
|
---|
162 | else cs.lpszClass = dlgInfo.className;
|
---|
163 | }
|
---|
164 | else {
|
---|
165 | cs.lpszName = dlgInfo.caption;
|
---|
166 | cs.lpszClass = dlgInfo.className;
|
---|
167 | }
|
---|
168 | cs.dwExStyle = dlgInfo.exStyle;
|
---|
169 |
|
---|
170 | fIsDialog = TRUE;
|
---|
171 | Win32DlgProc = dlgProc;
|
---|
172 |
|
---|
173 | this->tmpParam = param;
|
---|
174 | this->tmpDlgTemplate = (LPSTR)dlgTemplate;
|
---|
175 |
|
---|
176 | if (CreateWindowExA(&cs, classAtom) == FALSE)
|
---|
177 | {
|
---|
178 | if (hUserFont) DeleteObject( hUserFont );
|
---|
179 | if (hMenu) DestroyMenu( hMenu );
|
---|
180 | SetLastError(ERROR_OUTOFMEMORY); //TODO: Wrong error
|
---|
181 | return;
|
---|
182 | }
|
---|
183 | SetLastError(0);
|
---|
184 | return;
|
---|
185 | }
|
---|
186 | //******************************************************************************
|
---|
187 | //******************************************************************************
|
---|
188 | Win32Dialog::~Win32Dialog()
|
---|
189 | {
|
---|
190 | if (hUserFont) DeleteObject( hUserFont );
|
---|
191 | if (hMenu) DestroyMenu( hMenu );
|
---|
192 | }
|
---|
193 | //******************************************************************************
|
---|
194 | //******************************************************************************
|
---|
195 | ULONG Win32Dialog::MsgCreate(HWND hwndFrame, HWND hwndClient)
|
---|
196 | {
|
---|
197 | CREATESTRUCTA *cs = tmpcs; //pointer to CREATESTRUCT used in CreateWindowExA method
|
---|
198 | LPARAM param = tmpParam;
|
---|
199 | LPSTR dlgTemplate = tmpDlgTemplate;
|
---|
200 |
|
---|
201 | Win32BaseWindow::MsgCreate(hwndFrame, hwndClient);
|
---|
202 |
|
---|
203 | if(!isUnicode) {
|
---|
204 | if(cs->lpszName) FreeAsciiString((LPSTR)cs->lpszName);
|
---|
205 | if(HIWORD(cs->lpszClass)) {
|
---|
206 | FreeAsciiString((LPSTR)cs->lpszClass);
|
---|
207 | }
|
---|
208 | }
|
---|
209 |
|
---|
210 | //TODO:
|
---|
211 | // wndPtr->helpContext = helpId;
|
---|
212 |
|
---|
213 | if (hUserFont)
|
---|
214 | SendMessageA(WM_SETFONT, (WPARAM)hUserFont, 0 );
|
---|
215 |
|
---|
216 | /* Create controls */
|
---|
217 | if (createControls(dlgTemplate, hInstance))
|
---|
218 | {
|
---|
219 | dprintf(("********* DIALOG CONTROLS CREATED ************"));
|
---|
220 | /* Send initialisation messages and set focus */
|
---|
221 | hwndFocus = GetNextDlgTabItem( getWindowHandle(), 0, FALSE );
|
---|
222 |
|
---|
223 | if (SendMessageA(WM_INITDIALOG, (WPARAM)hwndFocus, param))
|
---|
224 | SetFocus(hwndFocus);
|
---|
225 |
|
---|
226 | if (dlgInfo.style & WS_VISIBLE && !(getStyle() & WS_VISIBLE))
|
---|
227 | {
|
---|
228 | ShowWindow( SW_SHOWNORMAL ); /* SW_SHOW doesn't always work */
|
---|
229 | ::UpdateWindow( getWindowHandle() );
|
---|
230 | }
|
---|
231 | SetLastError(0);
|
---|
232 | dprintf(("********* DIALOG CREATED ************"));
|
---|
233 | return TRUE;
|
---|
234 | }
|
---|
235 | dprintf(("********* DIALOG CREATION FAILED! ************"));
|
---|
236 | return FALSE;
|
---|
237 | }
|
---|
238 | /***********************************************************************
|
---|
239 | * DIALOG_DoDialogBox
|
---|
240 | */
|
---|
241 | INT Win32Dialog::doDialogBox()
|
---|
242 | {
|
---|
243 | Win32BaseWindow *topOwner;
|
---|
244 | MSG msg;
|
---|
245 | INT retval;
|
---|
246 |
|
---|
247 | /* Owner must be a top-level window */
|
---|
248 | if(getOwner() == NULL) {
|
---|
249 | topOwner = windowDesktop;
|
---|
250 | }
|
---|
251 | else topOwner = getOwner()->getTopParent();
|
---|
252 |
|
---|
253 | if(topOwner == NULL) {
|
---|
254 | dprintf(("Dialog box has no top owner!!!"));
|
---|
255 | return -1;
|
---|
256 | }
|
---|
257 |
|
---|
258 | if (!dialogFlags & DF_END) /* was EndDialog called in WM_INITDIALOG ? */
|
---|
259 | {
|
---|
260 | topOwner->EnableWindow( FALSE );
|
---|
261 | ShowWindow( SW_SHOW );
|
---|
262 |
|
---|
263 | //CB: 100% CPU usage, need a better solution with OSLibWinGetMsg
|
---|
264 | // is WM_ENTERIDLE used and leaving away breaks an application?
|
---|
265 | // this style was useful for Win3.1 but today there are threads
|
---|
266 | // solution: send only few WM_ENTERIDLE messages
|
---|
267 |
|
---|
268 | #if 1
|
---|
269 | while (TRUE)
|
---|
270 | {
|
---|
271 | if (!OSLibWinPeekMsg(&msg,0,0,0,MSG_NOREMOVE))
|
---|
272 | {
|
---|
273 | if(!(getStyle() & DS_NOIDLEMSG))
|
---|
274 | topOwner->SendMessageA(WM_ENTERIDLE,MSGF_DIALOGBOX,getWindowHandle());
|
---|
275 | OSLibWinGetMsg(&msg,0,0,0);
|
---|
276 | } else OSLibWinPeekMsg(&msg,0,0,0,MSG_REMOVE);
|
---|
277 |
|
---|
278 | if(msg.message == WM_QUIT)
|
---|
279 | {
|
---|
280 | dprintf(("Win32Dialog::doDialogBox: received WM_QUIT"));
|
---|
281 | break;
|
---|
282 | }
|
---|
283 | if (!IsDialogMessageA( getWindowHandle(), &msg))
|
---|
284 | {
|
---|
285 | TranslateMessage( &msg );
|
---|
286 | DispatchMessageA( &msg );
|
---|
287 | }
|
---|
288 | if (dialogFlags & DF_END) break;
|
---|
289 | }
|
---|
290 | #else
|
---|
291 | while (TRUE) {
|
---|
292 | // while (OSLibWinPeekMsg(&msg, getWindowHandle(), owner, MSGF_DIALOGBOX,
|
---|
293 | // MSG_REMOVE, !(getStyle() & DS_NOIDLEMSG), NULL ))
|
---|
294 | // if(OSLibWinPeekMsg(&msg, topOwner->getOS2FrameWindowHandle(), 0, 0, MSG_REMOVE))
|
---|
295 | if(OSLibWinPeekMsg(&msg, 0, 0, 0, MSG_REMOVE))
|
---|
296 | {
|
---|
297 | if(msg.message == WM_QUIT) {
|
---|
298 | dprintf(("Win32Dialog::doDialogBox: received WM_QUIT"));
|
---|
299 | break;
|
---|
300 | }
|
---|
301 | if (!IsDialogMessageA( getWindowHandle(), &msg))
|
---|
302 | {
|
---|
303 | TranslateMessage( &msg );
|
---|
304 | DispatchMessageA( &msg );
|
---|
305 | }
|
---|
306 | if (dialogFlags & DF_END) break;
|
---|
307 | }
|
---|
308 | else {
|
---|
309 | if(!(getStyle() & DS_NOIDLEMSG)) {
|
---|
310 | topOwner->SendMessageA(WM_ENTERIDLE, MSGF_DIALOGBOX, getWindowHandle());
|
---|
311 | }
|
---|
312 | }
|
---|
313 | }
|
---|
314 | #endif
|
---|
315 | topOwner->EnableWindow( TRUE );
|
---|
316 | }
|
---|
317 | retval = idResult;
|
---|
318 | DestroyWindow();
|
---|
319 | return retval;
|
---|
320 | }
|
---|
321 | /***********************************************************************
|
---|
322 | * DIALOG_Init
|
---|
323 | *
|
---|
324 | * Initialisation of the dialog manager.
|
---|
325 | */
|
---|
326 | BOOL Win32Dialog::DIALOG_Init(void)
|
---|
327 | {
|
---|
328 | HDC hdc;
|
---|
329 | SIZE size;
|
---|
330 |
|
---|
331 | /* Calculate the dialog base units */
|
---|
332 | if (!(hdc = CreateDCA( "DISPLAY", NULL, NULL, NULL ))) return FALSE;
|
---|
333 | if (!getCharSizeFromDC( hdc, 0, &size )) return FALSE;
|
---|
334 | DeleteDC( hdc );
|
---|
335 | xBaseUnit = size.cx;
|
---|
336 | yBaseUnit = size.cy;
|
---|
337 |
|
---|
338 | return TRUE;
|
---|
339 | }
|
---|
340 | /***********************************************************************
|
---|
341 | * DIALOG_GetCharSizeFromDC
|
---|
342 | *
|
---|
343 | *
|
---|
344 | * Calculates the *true* average size of English characters in the
|
---|
345 | * specified font as oppposed to the one returned by GetTextMetrics.
|
---|
346 | */
|
---|
347 | BOOL Win32Dialog::getCharSizeFromDC( HDC hDC, HFONT hUserFont, SIZE * pSize )
|
---|
348 | {
|
---|
349 | BOOL Success = FALSE;
|
---|
350 | HFONT hUserFontPrev = 0;
|
---|
351 | pSize->cx = xBaseUnit;
|
---|
352 | pSize->cy = yBaseUnit;
|
---|
353 |
|
---|
354 | if ( hDC )
|
---|
355 | {
|
---|
356 | /* select the font */
|
---|
357 | TEXTMETRICA tm;
|
---|
358 | memset(&tm,0,sizeof(tm));
|
---|
359 | if (hUserFont) hUserFontPrev = SelectFont(hDC,hUserFont);
|
---|
360 | if (GetTextMetricsA(hDC,&tm))
|
---|
361 | {
|
---|
362 | pSize->cx = tm.tmAveCharWidth;
|
---|
363 | pSize->cy = tm.tmHeight;
|
---|
364 |
|
---|
365 | /* if variable width font */
|
---|
366 | if (tm.tmPitchAndFamily & TMPF_FIXED_PITCH)
|
---|
367 | {
|
---|
368 | SIZE total;
|
---|
369 | static const char szAvgChars[53] = "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ";
|
---|
370 |
|
---|
371 | /* Calculate a true average as opposed to the one returned
|
---|
372 | * by tmAveCharWidth. This works better when dealing with
|
---|
373 | * proportional spaced fonts and (more important) that's
|
---|
374 | * how Microsoft's dialog creation code calculates the size
|
---|
375 | * of the font
|
---|
376 | */
|
---|
377 | if (GetTextExtentPointA(hDC,szAvgChars,sizeof(szAvgChars),&total))
|
---|
378 | {
|
---|
379 | /* round up */
|
---|
380 | pSize->cx = ((2*total.cx/sizeof(szAvgChars)) + 1)/2;
|
---|
381 | Success = TRUE;
|
---|
382 | }
|
---|
383 | }
|
---|
384 | else
|
---|
385 | {
|
---|
386 | Success = TRUE;
|
---|
387 | }
|
---|
388 | }
|
---|
389 |
|
---|
390 | /* select the original font */
|
---|
391 | if (hUserFontPrev) SelectFont(hDC,hUserFontPrev);
|
---|
392 | }
|
---|
393 | return (Success);
|
---|
394 | }
|
---|
395 | /***********************************************************************
|
---|
396 | * DIALOG_GetCharSize
|
---|
397 | *
|
---|
398 | *
|
---|
399 | * Calculates the *true* average size of English characters in the
|
---|
400 | * specified font as oppposed to the one returned by GetTextMetrics.
|
---|
401 | * A convenient variant of DIALOG_GetCharSizeFromDC.
|
---|
402 | */
|
---|
403 | BOOL Win32Dialog::getCharSize( HFONT hUserFont, SIZE * pSize )
|
---|
404 | {
|
---|
405 | HDC hDC = GetDC(0);
|
---|
406 | BOOL Success = getCharSizeFromDC( hDC, hUserFont, pSize );
|
---|
407 | ReleaseDC(0, hDC);
|
---|
408 | return Success;
|
---|
409 | }
|
---|
410 | /***********************************************************************
|
---|
411 | * DIALOG_ParseTemplate32
|
---|
412 | *
|
---|
413 | * Fill a DLG_TEMPLATE structure from the dialog template, and return
|
---|
414 | * a pointer to the first control.
|
---|
415 | */
|
---|
416 | LPCSTR Win32Dialog::parseTemplate( LPCSTR dlgtemplate, DLG_TEMPLATE * result )
|
---|
417 | {
|
---|
418 | const WORD *p = (const WORD *)dlgtemplate;
|
---|
419 |
|
---|
420 | result->style = GET_DWORD(p); p += 2;
|
---|
421 | if (result->style == 0xffff0001) /* DIALOGEX resource */
|
---|
422 | {
|
---|
423 | result->dialogEx = TRUE;
|
---|
424 | result->helpId = GET_DWORD(p); p += 2;
|
---|
425 | result->exStyle = GET_DWORD(p); p += 2;
|
---|
426 | result->style = GET_DWORD(p); p += 2;
|
---|
427 | }
|
---|
428 | else
|
---|
429 | {
|
---|
430 | result->dialogEx = FALSE;
|
---|
431 | result->helpId = 0;
|
---|
432 | result->exStyle = GET_DWORD(p); p += 2;
|
---|
433 | }
|
---|
434 | result->nbItems = GET_WORD(p); p++;
|
---|
435 | result->x = GET_WORD(p); p++;
|
---|
436 | result->y = GET_WORD(p); p++;
|
---|
437 | result->cx = GET_WORD(p); p++;
|
---|
438 | result->cy = GET_WORD(p); p++;
|
---|
439 |
|
---|
440 | /* Get the menu name */
|
---|
441 |
|
---|
442 | switch(GET_WORD(p))
|
---|
443 | {
|
---|
444 | case 0x0000:
|
---|
445 | result->menuName = NULL;
|
---|
446 | p++;
|
---|
447 | break;
|
---|
448 | case 0xffff:
|
---|
449 | result->menuName = (LPCSTR)(UINT)GET_WORD( p + 1 );
|
---|
450 | p += 2;
|
---|
451 | break;
|
---|
452 | default:
|
---|
453 | result->menuName = (LPCSTR)p;
|
---|
454 | p += lstrlenW( (LPCWSTR)p ) + 1;
|
---|
455 | break;
|
---|
456 | }
|
---|
457 |
|
---|
458 | /* Get the class name */
|
---|
459 | switch(GET_WORD(p))
|
---|
460 | {
|
---|
461 | case 0x0000:
|
---|
462 | result->className = (LPCSTR)DIALOG_CLASS_NAMEW;
|
---|
463 | p++;
|
---|
464 | break;
|
---|
465 | case 0xffff:
|
---|
466 | result->className = (LPCSTR)(UINT)GET_WORD( p + 1 );
|
---|
467 | p += 2;
|
---|
468 | break;
|
---|
469 | default:
|
---|
470 | result->className = (LPCSTR)p;
|
---|
471 | p += lstrlenW( (LPCWSTR)p ) + 1;
|
---|
472 | break;
|
---|
473 | }
|
---|
474 |
|
---|
475 | /* Get the window caption */
|
---|
476 |
|
---|
477 | result->caption = (LPCSTR)p;
|
---|
478 | p += lstrlenW( (LPCWSTR)p ) + 1;
|
---|
479 |
|
---|
480 | /* Get the font name */
|
---|
481 |
|
---|
482 | if (result->style & DS_SETFONT)
|
---|
483 | {
|
---|
484 | result->pointSize = GET_WORD(p);
|
---|
485 | p++;
|
---|
486 | if (result->dialogEx)
|
---|
487 | {
|
---|
488 | result->weight = GET_WORD(p); p++;
|
---|
489 | result->italic = LOBYTE(GET_WORD(p)); p++;
|
---|
490 | }
|
---|
491 | else
|
---|
492 | {
|
---|
493 | result->weight = FW_DONTCARE;
|
---|
494 | result->italic = FALSE;
|
---|
495 | }
|
---|
496 | result->faceName = (LPCSTR)p;
|
---|
497 | p += lstrlenW( (LPCWSTR)p ) + 1;
|
---|
498 | }
|
---|
499 |
|
---|
500 | /* First control is on dword boundary */
|
---|
501 | return (LPCSTR)((((int)p) + 3) & ~3);
|
---|
502 | }
|
---|
503 | /***********************************************************************
|
---|
504 | * DIALOG_GetControl32
|
---|
505 | *
|
---|
506 | * Return the class and text of the control pointed to by ptr,
|
---|
507 | * fill the header structure and return a pointer to the next control.
|
---|
508 | */
|
---|
509 | WORD *Win32Dialog::getControl(const WORD *p, DLG_CONTROL_INFO *info, BOOL dialogEx)
|
---|
510 | {
|
---|
511 | if (dialogEx)
|
---|
512 | {
|
---|
513 | info->helpId = GET_DWORD(p); p += 2;
|
---|
514 | info->exStyle = GET_DWORD(p); p += 2;
|
---|
515 | info->style = GET_DWORD(p); p += 2;
|
---|
516 | }
|
---|
517 | else
|
---|
518 | {
|
---|
519 | info->helpId = 0;
|
---|
520 | info->style = GET_DWORD(p); p += 2;
|
---|
521 | info->exStyle = GET_DWORD(p); p += 2;
|
---|
522 | }
|
---|
523 | info->x = GET_WORD(p); p++;
|
---|
524 | info->y = GET_WORD(p); p++;
|
---|
525 | info->cx = GET_WORD(p); p++;
|
---|
526 | info->cy = GET_WORD(p); p++;
|
---|
527 |
|
---|
528 | if (dialogEx)
|
---|
529 | {
|
---|
530 | /* id is a DWORD for DIALOGEX */
|
---|
531 | info->id = GET_DWORD(p);
|
---|
532 | p += 2;
|
---|
533 | }
|
---|
534 | else
|
---|
535 | {
|
---|
536 | info->id = GET_WORD(p);
|
---|
537 | p++;
|
---|
538 | }
|
---|
539 |
|
---|
540 | if (GET_WORD(p) == 0xffff)
|
---|
541 | {
|
---|
542 | static const WCHAR class_names[6][10] =
|
---|
543 | {
|
---|
544 | { 'B','u','t','t','o','n', }, /* 0x80 */
|
---|
545 | { 'E','d','i','t', }, /* 0x81 */
|
---|
546 | { 'S','t','a','t','i','c', }, /* 0x82 */
|
---|
547 | { 'L','i','s','t','B','o','x', }, /* 0x83 */
|
---|
548 | { 'S','c','r','o','l','l','B','a','r', }, /* 0x84 */
|
---|
549 | { 'C','o','m','b','o','B','o','x', } /* 0x85 */
|
---|
550 | };
|
---|
551 | WORD id = GET_WORD(p+1);
|
---|
552 | if ((id >= 0x80) && (id <= 0x85))
|
---|
553 | info->className = (LPCSTR)class_names[id - 0x80];
|
---|
554 | else
|
---|
555 | {
|
---|
556 | info->className = NULL;
|
---|
557 | dprintf(("Unknown built-in class id %04x\n", id ));
|
---|
558 | }
|
---|
559 | p += 2;
|
---|
560 | }
|
---|
561 | else
|
---|
562 | {
|
---|
563 | info->className = (LPCSTR)p;
|
---|
564 | p += lstrlenW( (LPCWSTR)p ) + 1;
|
---|
565 | }
|
---|
566 |
|
---|
567 | if (GET_WORD(p) == 0xffff) /* Is it an integer id? */
|
---|
568 | {
|
---|
569 | info->windowName = (LPCSTR)(UINT)GET_WORD(p + 1);
|
---|
570 | p += 2;
|
---|
571 | }
|
---|
572 | else
|
---|
573 | {
|
---|
574 | info->windowName = (LPCSTR)p;
|
---|
575 | p += lstrlenW( (LPCWSTR)p ) + 1;
|
---|
576 | }
|
---|
577 |
|
---|
578 | if (GET_WORD(p))
|
---|
579 | {
|
---|
580 | info->data = (LPVOID)(p + 1);
|
---|
581 | p += GET_WORD(p) / sizeof(WORD);
|
---|
582 | }
|
---|
583 | else info->data = NULL;
|
---|
584 | p++;
|
---|
585 |
|
---|
586 | /* Next control is on dword boundary */
|
---|
587 | return (WORD *)((((int)p) + 3) & ~3);
|
---|
588 | }
|
---|
589 |
|
---|
590 |
|
---|
591 | /***********************************************************************
|
---|
592 | * DIALOG_CreateControls
|
---|
593 | *
|
---|
594 | * Create the control windows for a dialog.
|
---|
595 | */
|
---|
596 | BOOL Win32Dialog::createControls(LPCSTR dlgtemplate, HINSTANCE hInst)
|
---|
597 | {
|
---|
598 | DLG_CONTROL_INFO info;
|
---|
599 | HWND hwndCtrl, hwndDefButton = 0;
|
---|
600 | INT items = dlgInfo.nbItems;
|
---|
601 |
|
---|
602 | while (items--)
|
---|
603 | {
|
---|
604 | dlgtemplate = (LPCSTR)getControl( (WORD *)dlgtemplate, &info, dlgInfo.dialogEx );
|
---|
605 |
|
---|
606 | dprintf(("Create CONTROL %d", info.id));
|
---|
607 | hwndCtrl = CreateWindowExW( info.exStyle | WS_EX_NOPARENTNOTIFY,
|
---|
608 | (LPCWSTR)info.className,
|
---|
609 | (LPCWSTR)info.windowName,
|
---|
610 | info.style | WS_CHILD,
|
---|
611 | info.x * xUnit / 4,
|
---|
612 | info.y * yUnit / 8,
|
---|
613 | info.cx * xUnit / 4,
|
---|
614 | info.cy * yUnit / 8,
|
---|
615 | getWindowHandle(), (HMENU)info.id,
|
---|
616 | hInst, info.data );
|
---|
617 |
|
---|
618 | if (!hwndCtrl) return FALSE;
|
---|
619 |
|
---|
620 | /* Send initialisation messages to the control */
|
---|
621 | if (hUserFont) ::SendMessageA( hwndCtrl, WM_SETFONT, (WPARAM)hUserFont, 0 );
|
---|
622 |
|
---|
623 | if (::SendMessageA(hwndCtrl, WM_GETDLGCODE, 0, 0) & DLGC_DEFPUSHBUTTON)
|
---|
624 | {
|
---|
625 | /* If there's already a default push-button, set it back */
|
---|
626 | /* to normal and use this one instead. */
|
---|
627 | if (hwndDefButton)
|
---|
628 | ::SendMessageA( hwndDefButton, BM_SETSTYLE,
|
---|
629 | BS_PUSHBUTTON,FALSE );
|
---|
630 | hwndDefButton = hwndCtrl;
|
---|
631 | idResult = ::GetWindowWord( hwndCtrl, GWW_ID );
|
---|
632 | }
|
---|
633 | dprintf(("Create CONTROL %d DONE", info.id));
|
---|
634 | }
|
---|
635 | return TRUE;
|
---|
636 | }
|
---|
637 | /***********************************************************************
|
---|
638 | * DEFDLG_Proc
|
---|
639 | *
|
---|
640 | * Implementation of DefDlgProc(). Only handle messages that need special
|
---|
641 | * handling for dialogs.
|
---|
642 | */
|
---|
643 | LRESULT Win32Dialog::DefDlg_Proc(UINT msg, WPARAM wParam, LPARAM lParam)
|
---|
644 | {
|
---|
645 | switch(msg)
|
---|
646 | {
|
---|
647 | case WM_ERASEBKGND:
|
---|
648 | {
|
---|
649 | RECT rect;
|
---|
650 | int rc;
|
---|
651 | /* Since WM_ERASEBKGND may receive either a window dc or a */
|
---|
652 | /* client dc, the area to be erased has to be retrieved from */
|
---|
653 | /* the device context. */
|
---|
654 | rc = GetClipBox( (HDC)wParam, &rect );
|
---|
655 | if ((rc == SIMPLEREGION) || (rc == COMPLEXREGION))
|
---|
656 | FillRect( (HDC)wParam, &rect, windowClass->getBackgroundBrush());
|
---|
657 | return 1;
|
---|
658 | }
|
---|
659 | case WM_NCDESTROY:
|
---|
660 | /* Free dialog heap (if created) */
|
---|
661 | #if 0
|
---|
662 | if (dlgInfo->hDialogHeap)
|
---|
663 | {
|
---|
664 | GlobalUnlock16(dlgInfo->hDialogHeap);
|
---|
665 | GlobalFree16(dlgInfo->hDialogHeap);
|
---|
666 | dlgInfo->hDialogHeap = 0;
|
---|
667 | }
|
---|
668 | #endif
|
---|
669 | /* Delete font */
|
---|
670 | if (hUserFont)
|
---|
671 | {
|
---|
672 | DeleteObject( hUserFont );
|
---|
673 | hUserFont = 0;
|
---|
674 | }
|
---|
675 |
|
---|
676 | /* Delete menu */
|
---|
677 | if (hMenu)
|
---|
678 | {
|
---|
679 | DestroyMenu( hMenu );
|
---|
680 | hMenu = 0;
|
---|
681 | }
|
---|
682 |
|
---|
683 | /* Delete window procedure */
|
---|
684 | Win32DlgProc = 0;
|
---|
685 | dialogFlags |= DF_END; /* just in case */
|
---|
686 |
|
---|
687 | /* Window clean-up */
|
---|
688 | return DefWindowProcA(msg, wParam, lParam );
|
---|
689 |
|
---|
690 | case WM_SHOWWINDOW:
|
---|
691 | if (!wParam) saveFocus();
|
---|
692 | return DefWindowProcA(msg, wParam, lParam );
|
---|
693 |
|
---|
694 | case WM_ACTIVATE:
|
---|
695 | if (wParam) {
|
---|
696 | restoreFocus();
|
---|
697 | }
|
---|
698 | else saveFocus();
|
---|
699 | return 0;
|
---|
700 |
|
---|
701 | case WM_SETFOCUS:
|
---|
702 | restoreFocus();
|
---|
703 | return 0;
|
---|
704 |
|
---|
705 | case DM_SETDEFID:
|
---|
706 | if (dialogFlags & DF_END)
|
---|
707 | return 1;
|
---|
708 |
|
---|
709 | setDefButton(wParam ? GetDlgItem( getWindowHandle(), wParam ) : 0 );
|
---|
710 | return 1;
|
---|
711 |
|
---|
712 | case DM_GETDEFID:
|
---|
713 | {
|
---|
714 | HWND hwndDefId;
|
---|
715 | if (dialogFlags & DF_END) return 0;
|
---|
716 | if (idResult)
|
---|
717 | return MAKELONG( idResult, DC_HASDEFID );
|
---|
718 | if ((hwndDefId = findDefButton()))
|
---|
719 | return MAKELONG( GetDlgCtrlID( hwndDefId ), DC_HASDEFID);
|
---|
720 |
|
---|
721 | return 0;
|
---|
722 | }
|
---|
723 |
|
---|
724 | case WM_NEXTDLGCTL:
|
---|
725 | {
|
---|
726 | HWND hwndDest = (HWND)wParam;
|
---|
727 | if (!lParam)
|
---|
728 | hwndDest = GetNextDlgTabItem(getWindowHandle(), GetFocus(), wParam);
|
---|
729 | if (hwndDest) setFocus( hwndDest );
|
---|
730 | setDefButton( hwndDest );
|
---|
731 | return 0;
|
---|
732 | }
|
---|
733 |
|
---|
734 | case WM_ENTERMENULOOP:
|
---|
735 | case WM_LBUTTONDOWN:
|
---|
736 | case WM_NCLBUTTONDOWN:
|
---|
737 | {
|
---|
738 | HWND hwndCurFocus = GetFocus();
|
---|
739 | if (hwndCurFocus)
|
---|
740 | {
|
---|
741 | #if 0
|
---|
742 | WND *wnd = WIN_FindWndPtr( hwndFocus );
|
---|
743 |
|
---|
744 | if( wnd )
|
---|
745 | {
|
---|
746 | /* always make combo box hide its listbox control */
|
---|
747 | if( WIDGETS_IsControl( wnd, BIC32_COMBO ) )
|
---|
748 | SendMessageA( hwndFocus, CB_SHOWDROPDOWN, FALSE, 0 );
|
---|
749 | else
|
---|
750 | if( WIDGETS_IsControl( wnd, BIC32_EDIT ) &&
|
---|
751 | WIDGETS_IsControl( wnd->parent, BIC32_COMBO ))
|
---|
752 | SendMessageA(CB_SHOWDROPDOWN, FALSE, 0 );
|
---|
753 | }
|
---|
754 | #endif
|
---|
755 | }
|
---|
756 | return DefWindowProcA( msg, wParam, lParam );
|
---|
757 | }
|
---|
758 |
|
---|
759 | case WM_GETFONT:
|
---|
760 | return hUserFont;
|
---|
761 |
|
---|
762 | case WM_CLOSE:
|
---|
763 | PostMessageA(WM_COMMAND, IDCANCEL, (LPARAM)GetDlgItem( getWindowHandle(), IDCANCEL ) );
|
---|
764 | return 0;
|
---|
765 |
|
---|
766 | case WM_NOTIFYFORMAT:
|
---|
767 | return DefWindowProcA(msg, wParam, lParam );
|
---|
768 | }
|
---|
769 | return 0;
|
---|
770 | }
|
---|
771 | //******************************************************************************
|
---|
772 | //******************************************************************************
|
---|
773 | LRESULT Win32Dialog::DefDlgProcA(UINT Msg, WPARAM wParam, LPARAM lParam)
|
---|
774 | {
|
---|
775 | BOOL result = FALSE;
|
---|
776 |
|
---|
777 | msgResult = 0;
|
---|
778 |
|
---|
779 | if (Win32DlgProc) { /* Call dialog procedure */
|
---|
780 | result = Win32DlgProc(getWindowHandle(), Msg, wParam, lParam);
|
---|
781 | }
|
---|
782 |
|
---|
783 | if (!result && IsWindow())
|
---|
784 | {
|
---|
785 | /* callback didn't process this message */
|
---|
786 | switch(Msg)
|
---|
787 | {
|
---|
788 | case WM_ERASEBKGND:
|
---|
789 | case WM_SHOWWINDOW:
|
---|
790 | case WM_ACTIVATE:
|
---|
791 | case WM_SETFOCUS:
|
---|
792 | case DM_SETDEFID:
|
---|
793 | case DM_GETDEFID:
|
---|
794 | case WM_NEXTDLGCTL:
|
---|
795 | case WM_GETFONT:
|
---|
796 | case WM_CLOSE:
|
---|
797 | case WM_NCDESTROY:
|
---|
798 | case WM_ENTERMENULOOP:
|
---|
799 | case WM_LBUTTONDOWN:
|
---|
800 | case WM_NCLBUTTONDOWN:
|
---|
801 | return DefDlg_Proc(Msg, (WPARAM)wParam, lParam);
|
---|
802 |
|
---|
803 | case WM_INITDIALOG:
|
---|
804 | case WM_VKEYTOITEM:
|
---|
805 | case WM_COMPAREITEM:
|
---|
806 | case WM_CHARTOITEM:
|
---|
807 | break;
|
---|
808 |
|
---|
809 | default:
|
---|
810 | return DefWindowProcA(Msg, wParam, lParam );
|
---|
811 | }
|
---|
812 | }
|
---|
813 | return DefDlg_Epilog(Msg, result);
|
---|
814 | }
|
---|
815 | //******************************************************************************
|
---|
816 | //******************************************************************************
|
---|
817 | LRESULT Win32Dialog::DefDlgProcW(UINT Msg, WPARAM wParam, LPARAM lParam)
|
---|
818 | {
|
---|
819 | BOOL result = FALSE;
|
---|
820 |
|
---|
821 | msgResult = 0;
|
---|
822 |
|
---|
823 | if (Win32DlgProc) { /* Call dialog procedure */
|
---|
824 | result = Win32DlgProc(getWindowHandle(), Msg, wParam, lParam);
|
---|
825 | }
|
---|
826 |
|
---|
827 | if (!result && IsWindow())
|
---|
828 | {
|
---|
829 | /* callback didn't process this message */
|
---|
830 | switch(Msg)
|
---|
831 | {
|
---|
832 | case WM_ERASEBKGND:
|
---|
833 | case WM_SHOWWINDOW:
|
---|
834 | case WM_ACTIVATE:
|
---|
835 | case WM_SETFOCUS:
|
---|
836 | case DM_SETDEFID:
|
---|
837 | case DM_GETDEFID:
|
---|
838 | case WM_NEXTDLGCTL:
|
---|
839 | case WM_GETFONT:
|
---|
840 | case WM_CLOSE:
|
---|
841 | case WM_NCDESTROY:
|
---|
842 | case WM_ENTERMENULOOP:
|
---|
843 | case WM_LBUTTONDOWN:
|
---|
844 | case WM_NCLBUTTONDOWN:
|
---|
845 | return DefDlg_Proc(Msg, (WPARAM)wParam, lParam);
|
---|
846 |
|
---|
847 | case WM_INITDIALOG:
|
---|
848 | case WM_VKEYTOITEM:
|
---|
849 | case WM_COMPAREITEM:
|
---|
850 | case WM_CHARTOITEM:
|
---|
851 | break;
|
---|
852 |
|
---|
853 | default:
|
---|
854 | return DefWindowProcW(Msg, wParam, lParam );
|
---|
855 | }
|
---|
856 | }
|
---|
857 | return DefDlg_Epilog(Msg, result);
|
---|
858 | }
|
---|
859 | /***********************************************************************
|
---|
860 | * DEFDLG_Epilog
|
---|
861 | */
|
---|
862 | LRESULT Win32Dialog::DefDlg_Epilog(UINT msg, BOOL fResult)
|
---|
863 | {
|
---|
864 | /* see SDK 3.1 */
|
---|
865 | if ((msg >= WM_CTLCOLORMSGBOX && msg <= WM_CTLCOLORSTATIC) ||
|
---|
866 | msg == WM_CTLCOLOR || msg == WM_COMPAREITEM ||
|
---|
867 | msg == WM_VKEYTOITEM || msg == WM_CHARTOITEM ||
|
---|
868 | msg == WM_QUERYDRAGICON || msg == WM_INITDIALOG)
|
---|
869 | return fResult;
|
---|
870 |
|
---|
871 | return msgResult;
|
---|
872 | }
|
---|
873 | /***********************************************************************
|
---|
874 | * DEFDLG_SetFocus
|
---|
875 | *
|
---|
876 | * Set the focus to a control of the dialog, selecting the text if
|
---|
877 | * the control is an edit dialog.
|
---|
878 | */
|
---|
879 | void Win32Dialog::setFocus(HWND hwndCtrl )
|
---|
880 | {
|
---|
881 | HWND hwndPrev = GetFocus();
|
---|
882 |
|
---|
883 | if (IsChild( hwndPrev ))
|
---|
884 | {
|
---|
885 | if (::SendMessageA( hwndPrev, WM_GETDLGCODE, 0, 0 ) & DLGC_HASSETSEL)
|
---|
886 | ::SendMessageA( hwndPrev, EM_SETSEL, TRUE, MAKELONG( -1, 0 ) );
|
---|
887 | }
|
---|
888 | if (::SendMessageA(hwndCtrl, WM_GETDLGCODE, 0, 0 ) & DLGC_HASSETSEL)
|
---|
889 | ::SendMessageA(hwndCtrl, EM_SETSEL, FALSE, MAKELONG( 0, -1 ) );
|
---|
890 | SetFocus( hwndCtrl );
|
---|
891 | }
|
---|
892 |
|
---|
893 |
|
---|
894 | /***********************************************************************
|
---|
895 | * DEFDLG_SaveFocus
|
---|
896 | */
|
---|
897 | BOOL Win32Dialog::saveFocus()
|
---|
898 | {
|
---|
899 | HWND hwndCurrentFocus = GetFocus();
|
---|
900 |
|
---|
901 | if (!hwndCurrentFocus || !IsChild( hwndCurrentFocus )) return FALSE;
|
---|
902 |
|
---|
903 | hwndFocus = hwndCurrentFocus;
|
---|
904 | /* Remove default button */
|
---|
905 | return TRUE;
|
---|
906 | }
|
---|
907 |
|
---|
908 |
|
---|
909 | /***********************************************************************
|
---|
910 | * DEFDLG_RestoreFocus
|
---|
911 | */
|
---|
912 | BOOL Win32Dialog::restoreFocus()
|
---|
913 | {
|
---|
914 | if (!hwndFocus || IsIconic()) return FALSE;
|
---|
915 |
|
---|
916 | if (!::IsWindow( hwndFocus )) return FALSE;
|
---|
917 |
|
---|
918 | /* Don't set the focus back to controls if EndDialog is already called.*/
|
---|
919 | if (!(dialogFlags & DF_END))
|
---|
920 | setFocus(hwndFocus);
|
---|
921 |
|
---|
922 | /* This used to set infoPtr->hwndFocus to NULL for no apparent reason,
|
---|
923 | sometimes losing focus when receiving WM_SETFOCUS messages. */
|
---|
924 | return TRUE;
|
---|
925 | }
|
---|
926 |
|
---|
927 |
|
---|
928 | /***********************************************************************
|
---|
929 | * DEFDLG_FindDefButton
|
---|
930 | *
|
---|
931 | * Find the current default push-button.
|
---|
932 | */
|
---|
933 | HWND Win32Dialog::findDefButton()
|
---|
934 | {
|
---|
935 | HWND hwndChild = GetWindow( GW_CHILD );
|
---|
936 | while (hwndChild)
|
---|
937 | {
|
---|
938 | if (::SendMessageA( hwndChild, WM_GETDLGCODE, 0, 0 ) & DLGC_DEFPUSHBUTTON)
|
---|
939 | break;
|
---|
940 | hwndChild = ::GetWindow( hwndChild, GW_HWNDNEXT );
|
---|
941 | }
|
---|
942 | return hwndChild;
|
---|
943 | }
|
---|
944 |
|
---|
945 |
|
---|
946 | /***********************************************************************
|
---|
947 | * DEFDLG_SetDefButton
|
---|
948 | *
|
---|
949 | * Set the new default button to be hwndNew.
|
---|
950 | */
|
---|
951 | BOOL Win32Dialog::setDefButton(HWND hwndNew )
|
---|
952 | {
|
---|
953 | if (hwndNew &&
|
---|
954 | !(::SendMessageA(hwndNew, WM_GETDLGCODE, 0, 0 ) & DLGC_UNDEFPUSHBUTTON))
|
---|
955 | return FALSE; /* Destination is not a push button */
|
---|
956 |
|
---|
957 | if (idResult) /* There's already a default pushbutton */
|
---|
958 | {
|
---|
959 | HWND hwndOld = GetDlgItem( getWindowHandle(), idResult );
|
---|
960 | if (::SendMessageA( hwndOld, WM_GETDLGCODE, 0, 0) & DLGC_DEFPUSHBUTTON)
|
---|
961 | ::SendMessageA( hwndOld, BM_SETSTYLE, BS_PUSHBUTTON, TRUE );
|
---|
962 | }
|
---|
963 | if (hwndNew)
|
---|
964 | {
|
---|
965 | ::SendMessageA( hwndNew, BM_SETSTYLE, BS_DEFPUSHBUTTON, TRUE );
|
---|
966 | idResult = GetDlgCtrlID( hwndNew );
|
---|
967 | }
|
---|
968 | else idResult = 0;
|
---|
969 | return TRUE;
|
---|
970 | }
|
---|
971 | //******************************************************************************
|
---|
972 | // GetNextDlgTabItem32 (USER32.276)
|
---|
973 | //******************************************************************************
|
---|
974 | HWND Win32Dialog::getNextDlgTabItem(HWND hwndCtrl, BOOL fPrevious)
|
---|
975 | {
|
---|
976 | Win32BaseWindow *child, *nextchild, *lastchild;
|
---|
977 | HWND retvalue;
|
---|
978 |
|
---|
979 | if (hwndCtrl)
|
---|
980 | {
|
---|
981 | child = GetWindowFromHandle(hwndCtrl);
|
---|
982 | if (!child)
|
---|
983 | {
|
---|
984 | retvalue = 0;
|
---|
985 | goto END;
|
---|
986 | }
|
---|
987 | /* Make sure hwndCtrl is a top-level child */
|
---|
988 | while ((child->getStyle() & WS_CHILD) && (child->getParent() != this))
|
---|
989 | {
|
---|
990 | child = child->getParent();
|
---|
991 | if(child == NULL) break;
|
---|
992 | }
|
---|
993 |
|
---|
994 | if (!child || child->getParent() != this)
|
---|
995 | {
|
---|
996 | retvalue = 0;
|
---|
997 | goto END;
|
---|
998 | }
|
---|
999 | }
|
---|
1000 | else
|
---|
1001 | {
|
---|
1002 | /* No ctrl specified -> start from the beginning */
|
---|
1003 | child = (Win32BaseWindow *)getFirstChild();
|
---|
1004 | if (!child)
|
---|
1005 | {
|
---|
1006 | retvalue = 0;
|
---|
1007 | goto END;
|
---|
1008 | }
|
---|
1009 |
|
---|
1010 | if (!fPrevious)
|
---|
1011 | {
|
---|
1012 | while (child->getNextChild())
|
---|
1013 | {
|
---|
1014 | child = (Win32BaseWindow *)child->getNextChild();
|
---|
1015 | }
|
---|
1016 | }
|
---|
1017 | }
|
---|
1018 |
|
---|
1019 | lastchild = child;
|
---|
1020 | nextchild = (Win32BaseWindow *)child->getNextChild();
|
---|
1021 | while (TRUE)
|
---|
1022 | {
|
---|
1023 | if (!nextchild) nextchild = (Win32BaseWindow *)getFirstChild();
|
---|
1024 |
|
---|
1025 | if (child == nextchild) break;
|
---|
1026 |
|
---|
1027 | if ((nextchild->getStyle() & WS_TABSTOP) && (nextchild->getStyle() & WS_VISIBLE) &&
|
---|
1028 | !(nextchild->getStyle() & WS_DISABLED))
|
---|
1029 | {
|
---|
1030 | lastchild = nextchild;
|
---|
1031 | if (!fPrevious) break;
|
---|
1032 | }
|
---|
1033 | nextchild = (Win32BaseWindow *)nextchild->getNextChild();
|
---|
1034 | }
|
---|
1035 | retvalue = lastchild->getWindowHandle();
|
---|
1036 |
|
---|
1037 | END:
|
---|
1038 | return retvalue;
|
---|
1039 | }
|
---|
1040 | //******************************************************************************
|
---|
1041 | //******************************************************************************
|
---|
1042 | HWND Win32Dialog::getNextDlgGroupItem(HWND hwndCtrl, BOOL fPrevious)
|
---|
1043 | {
|
---|
1044 | Win32BaseWindow *child, *nextchild, *lastchild;
|
---|
1045 | HWND retvalue;
|
---|
1046 |
|
---|
1047 | if (hwndCtrl)
|
---|
1048 | {
|
---|
1049 | child = GetWindowFromHandle(hwndCtrl);
|
---|
1050 | if (!child)
|
---|
1051 | {
|
---|
1052 | retvalue = 0;
|
---|
1053 | goto END;
|
---|
1054 | }
|
---|
1055 | /* Make sure hwndCtrl is a top-level child */
|
---|
1056 | while ((child->getStyle() & WS_CHILD) && (child->getParent() != this))
|
---|
1057 | {
|
---|
1058 | child = child->getParent();
|
---|
1059 | if(child == NULL) break;
|
---|
1060 | }
|
---|
1061 |
|
---|
1062 | if (!child || child->getParent() != this)
|
---|
1063 | {
|
---|
1064 | retvalue = 0;
|
---|
1065 | goto END;
|
---|
1066 | }
|
---|
1067 | }
|
---|
1068 | else
|
---|
1069 | {
|
---|
1070 | /* No ctrl specified -> start from the beginning */
|
---|
1071 | child = (Win32BaseWindow *)getFirstChild();
|
---|
1072 | if (!child)
|
---|
1073 | {
|
---|
1074 | retvalue = 0;
|
---|
1075 | goto END;
|
---|
1076 | }
|
---|
1077 |
|
---|
1078 | if (fPrevious)
|
---|
1079 | {
|
---|
1080 | while (child->getNextChild())
|
---|
1081 | {
|
---|
1082 | child = (Win32BaseWindow *)child->getNextChild();
|
---|
1083 | }
|
---|
1084 | }
|
---|
1085 | }
|
---|
1086 |
|
---|
1087 | lastchild = child;
|
---|
1088 | nextchild = (Win32BaseWindow *)child->getNextChild();
|
---|
1089 | while (TRUE)
|
---|
1090 | {
|
---|
1091 | if (!nextchild || nextchild->getStyle() & WS_GROUP)
|
---|
1092 | {
|
---|
1093 | /* Wrap-around to the beginning of the group */
|
---|
1094 | Win32BaseWindow *pWndTemp;
|
---|
1095 |
|
---|
1096 | nextchild = (Win32BaseWindow *)getFirstChild();
|
---|
1097 |
|
---|
1098 | for(pWndTemp = nextchild;pWndTemp;pWndTemp = (Win32BaseWindow *)pWndTemp->getNextChild())
|
---|
1099 | {
|
---|
1100 | if (pWndTemp->getStyle() & WS_GROUP)
|
---|
1101 | nextchild = pWndTemp;
|
---|
1102 |
|
---|
1103 | if (pWndTemp == child)
|
---|
1104 | break;
|
---|
1105 | }
|
---|
1106 |
|
---|
1107 | }
|
---|
1108 | if (nextchild == child)
|
---|
1109 | break;
|
---|
1110 |
|
---|
1111 | if ((nextchild->getStyle() & WS_VISIBLE) && !(nextchild->getStyle() & WS_DISABLED))
|
---|
1112 | {
|
---|
1113 | lastchild = nextchild;
|
---|
1114 |
|
---|
1115 | if (!fPrevious)
|
---|
1116 | break;
|
---|
1117 | }
|
---|
1118 |
|
---|
1119 | nextchild = (Win32BaseWindow *)nextchild->getNextChild();
|
---|
1120 | }
|
---|
1121 | retvalue = lastchild->getWindowHandle();
|
---|
1122 | END:
|
---|
1123 | return retvalue;
|
---|
1124 | }
|
---|
1125 | //******************************************************************************
|
---|
1126 | //******************************************************************************
|
---|
1127 | Win32BaseWindow *Win32Dialog::getDlgItem(int id)
|
---|
1128 | {
|
---|
1129 | for (Win32BaseWindow *child = (Win32BaseWindow *)getFirstChild(); child; child = (Win32BaseWindow *)child->getNextChild())
|
---|
1130 | {
|
---|
1131 | if (child->getWindowId() == id)
|
---|
1132 | {
|
---|
1133 | return child;
|
---|
1134 | }
|
---|
1135 | }
|
---|
1136 | return 0;
|
---|
1137 | }
|
---|
1138 | //******************************************************************************
|
---|
1139 | //******************************************************************************
|
---|
1140 | BOOL Win32Dialog::endDialog(int retval)
|
---|
1141 | {
|
---|
1142 | dialogFlags |= DF_END;
|
---|
1143 | idResult = retval;
|
---|
1144 | return TRUE;
|
---|
1145 | }
|
---|
1146 | //******************************************************************************
|
---|
1147 | //******************************************************************************
|
---|
1148 | LONG Win32Dialog::SetWindowLongA(int index, ULONG value)
|
---|
1149 | {
|
---|
1150 | LONG oldval;
|
---|
1151 |
|
---|
1152 | switch(index)
|
---|
1153 | {
|
---|
1154 | case DWL_DLGPROC:
|
---|
1155 | oldval = (LONG)Win32DlgProc;
|
---|
1156 | Win32DlgProc = (DLGPROC)index;
|
---|
1157 | return oldval;
|
---|
1158 | case DWL_MSGRESULT:
|
---|
1159 | oldval = msgResult;
|
---|
1160 | msgResult = value;
|
---|
1161 | return oldval;
|
---|
1162 | case DWL_USER:
|
---|
1163 | oldval = userDlgData;
|
---|
1164 | userDlgData = value;
|
---|
1165 | return oldval;
|
---|
1166 | default:
|
---|
1167 | return Win32BaseWindow::SetWindowLongA(index, value);
|
---|
1168 | }
|
---|
1169 | }
|
---|
1170 | //******************************************************************************
|
---|
1171 | //******************************************************************************
|
---|
1172 | ULONG Win32Dialog::GetWindowLongA(int index)
|
---|
1173 | {
|
---|
1174 | switch(index)
|
---|
1175 | {
|
---|
1176 | case DWL_DLGPROC:
|
---|
1177 | return (ULONG)Win32DlgProc;
|
---|
1178 | case DWL_MSGRESULT:
|
---|
1179 | return msgResult;
|
---|
1180 | case DWL_USER:
|
---|
1181 | return userDlgData;
|
---|
1182 | default:
|
---|
1183 | return Win32BaseWindow::GetWindowLongA(index);
|
---|
1184 | }
|
---|
1185 | }
|
---|
1186 | //******************************************************************************
|
---|
1187 | //******************************************************************************
|
---|
1188 | BOOL DIALOG_Register()
|
---|
1189 | {
|
---|
1190 | WNDCLASSA wndClass;
|
---|
1191 |
|
---|
1192 | ZeroMemory(&wndClass,sizeof(WNDCLASSA));
|
---|
1193 | wndClass.style = CS_GLOBALCLASS | CS_SAVEBITS;
|
---|
1194 | wndClass.lpfnWndProc = (WNDPROC)DefDlgProcA;
|
---|
1195 | wndClass.cbClsExtra = 0;
|
---|
1196 | wndClass.cbWndExtra = 0;
|
---|
1197 | wndClass.hCursor = (HCURSOR)IDC_ARROWA;
|
---|
1198 | wndClass.hbrBackground = GetSysColorBrush(COLOR_BTNFACE);
|
---|
1199 | wndClass.lpszClassName = DIALOG_CLASS_NAMEA;
|
---|
1200 |
|
---|
1201 | return RegisterClassA(&wndClass);
|
---|
1202 | }
|
---|
1203 | //******************************************************************************
|
---|
1204 | //******************************************************************************
|
---|
1205 | BOOL DIALOG_Unregister()
|
---|
1206 | {
|
---|
1207 | if (GlobalFindAtomA(DIALOG_CLASS_NAMEA))
|
---|
1208 | return UnregisterClassA(DIALOG_CLASS_NAMEA,(HINSTANCE)NULL);
|
---|
1209 | else return FALSE;
|
---|
1210 | }
|
---|
1211 | //******************************************************************************
|
---|
1212 | //******************************************************************************
|
---|
1213 | BOOL Win32Dialog::fInitialized = FALSE;
|
---|
1214 | int Win32Dialog::xBaseUnit = 10;
|
---|
1215 | int Win32Dialog::yBaseUnit = 20;
|
---|