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