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