source: trunk/src/user32/win32dlg.cpp@ 2663

Last change on this file since 2663 was 2663, checked in by sandervl, 26 years ago

WM_ERASEBKGND changes

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