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

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

DC changes + commented out shell position update

File size: 33.2 KB
Line 
1/* $Id: win32dlg.cpp,v 1.43 2000-02-06 22:00:23 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 if ((rc == SIMPLEREGION) || (rc == COMPLEXREGION))
704 {
705 HBRUSH hBrush = windowClass->getBackgroundBrush();
706
707 if (hBrush <= (HBRUSH)(SYSCOLOR_GetLastColor()+1))
708 hBrush = GetSysColorBrush(hBrush-1);
709
710 FillRect( (HDC)wParam, &rect, hBrush);
711 }
712
713 return 1;
714 }
715
716 case WM_NCDESTROY:
717 /* Free dialog heap (if created) */
718#if 0
719 if (dlgInfo->hDialogHeap)
720 {
721 GlobalUnlock16(dlgInfo->hDialogHeap);
722 GlobalFree16(dlgInfo->hDialogHeap);
723 dlgInfo->hDialogHeap = 0;
724 }
725#endif
726 /* Delete font */
727 if (hUserFont)
728 {
729 DeleteObject( hUserFont );
730 hUserFont = 0;
731 }
732
733 /* Delete menu */
734 if (hMenu)
735 {
736 DestroyMenu( hMenu );
737 hMenu = 0;
738 }
739
740 /* Delete window procedure */
741 Win32DlgProc = 0;
742 dialogFlags |= DF_END; /* just in case */
743
744 /* Window clean-up */
745 return DefWindowProcA(msg, wParam, lParam );
746
747 case WM_SHOWWINDOW:
748 if (!wParam) saveFocus();
749 return DefWindowProcA(msg, wParam, lParam );
750
751 case WM_ACTIVATE:
752 if (wParam) {
753 restoreFocus();
754 }
755 else saveFocus();
756 return 0;
757
758 case WM_SETFOCUS:
759 restoreFocus();
760 return 0;
761
762 case DM_SETDEFID:
763 if (dialogFlags & DF_END)
764 return 1;
765
766 setDefButton(wParam ? GetDlgItem( getWindowHandle(), wParam ) : 0 );
767 return 1;
768
769 case DM_GETDEFID:
770 {
771 HWND hwndDefId;
772 if (dialogFlags & DF_END) return 0;
773 if (idResult)
774 return MAKELONG( idResult, DC_HASDEFID );
775 if ((hwndDefId = findDefButton()) != 0)
776 return MAKELONG( GetDlgCtrlID( hwndDefId ), DC_HASDEFID);
777
778 return 0;
779 }
780
781 case WM_NEXTDLGCTL:
782 {
783 HWND hwndDest = (HWND)wParam;
784 if (!lParam)
785 hwndDest = GetNextDlgTabItem(getWindowHandle(), GetFocus(), wParam);
786 if (hwndDest) setFocus( hwndDest );
787 setDefButton( hwndDest );
788 return 0;
789 }
790
791 case WM_ENTERMENULOOP:
792 case WM_LBUTTONDOWN:
793 case WM_NCLBUTTONDOWN:
794 {
795 HWND hwndCurFocus = GetFocus();
796 if (hwndCurFocus)
797 {
798 Win32BaseWindow *wndFocus = Win32BaseWindow::GetWindowFromHandle(hwndFocus);
799
800 if(wndFocus)
801 {
802 /* always make combo box hide its listbox control */
803 if( CONTROLS_IsControl( wndFocus, COMBOBOX_CONTROL ) )
804 wndFocus->SendMessageA(CB_SHOWDROPDOWN, FALSE, 0 );
805 else
806 if( CONTROLS_IsControl( wndFocus, EDIT_CONTROL ) &&
807 CONTROLS_IsControl( wndFocus->getParent(), COMBOBOX_CONTROL ))
808 wndFocus->SendMessageA(CB_SHOWDROPDOWN, FALSE, 0 );
809 }
810 }
811 return DefWindowProcA( msg, wParam, lParam );
812 }
813
814 case WM_GETFONT:
815 return hUserFont;
816
817 case WM_CLOSE:
818 PostMessageA(getWindowHandle(), WM_COMMAND, IDCANCEL, (LPARAM)GetDlgItem( getWindowHandle(), IDCANCEL ) );
819 return 0;
820
821 case WM_NOTIFYFORMAT:
822 return DefWindowProcA(msg, wParam, lParam );
823 }
824 return 0;
825}
826//******************************************************************************
827//******************************************************************************
828LRESULT Win32Dialog::DefDlgProcA(UINT Msg, WPARAM wParam, LPARAM lParam)
829{
830 BOOL result = FALSE;
831
832 msgResult = 0;
833
834 if (Win32DlgProc) { /* Call dialog procedure */
835 result = Win32DlgProc(getWindowHandle(), Msg, wParam, lParam);
836 }
837
838 if (!result && IsWindow())
839 {
840 /* callback didn't process this message */
841 switch(Msg)
842 {
843 case WM_ERASEBKGND:
844 case WM_SHOWWINDOW:
845 case WM_ACTIVATE:
846 case WM_SETFOCUS:
847 case DM_SETDEFID:
848 case DM_GETDEFID:
849 case WM_NEXTDLGCTL:
850 case WM_GETFONT:
851 case WM_CLOSE:
852 case WM_NCDESTROY:
853 case WM_ENTERMENULOOP:
854 case WM_LBUTTONDOWN:
855 case WM_NCLBUTTONDOWN:
856 return DefDlg_Proc(Msg, (WPARAM)wParam, lParam);
857
858 case WM_INITDIALOG:
859 case WM_VKEYTOITEM:
860 case WM_COMPAREITEM:
861 case WM_CHARTOITEM:
862 break;
863
864 default:
865 return DefWindowProcA(Msg, wParam, lParam );
866 }
867 }
868 return DefDlg_Epilog(Msg, result);
869}
870//******************************************************************************
871//******************************************************************************
872LRESULT Win32Dialog::DefDlgProcW(UINT Msg, WPARAM wParam, LPARAM lParam)
873{
874 BOOL result = FALSE;
875
876 msgResult = 0;
877
878 if (Win32DlgProc) { /* Call dialog procedure */
879 result = Win32DlgProc(getWindowHandle(), Msg, wParam, lParam);
880 }
881
882 if (!result && IsWindow())
883 {
884 /* callback didn't process this message */
885 switch(Msg)
886 {
887 case WM_ERASEBKGND:
888 case WM_SHOWWINDOW:
889 case WM_ACTIVATE:
890 case WM_SETFOCUS:
891 case DM_SETDEFID:
892 case DM_GETDEFID:
893 case WM_NEXTDLGCTL:
894 case WM_GETFONT:
895 case WM_CLOSE:
896 case WM_NCDESTROY:
897 case WM_ENTERMENULOOP:
898 case WM_LBUTTONDOWN:
899 case WM_NCLBUTTONDOWN:
900 return DefDlg_Proc(Msg, (WPARAM)wParam, lParam);
901
902 case WM_INITDIALOG:
903 case WM_VKEYTOITEM:
904 case WM_COMPAREITEM:
905 case WM_CHARTOITEM:
906 break;
907
908 default:
909 return DefWindowProcW(Msg, wParam, lParam );
910 }
911 }
912 return DefDlg_Epilog(Msg, result);
913}
914/***********************************************************************
915 * DEFDLG_Epilog
916 */
917LRESULT Win32Dialog::DefDlg_Epilog(UINT msg, BOOL fResult)
918{
919 /* see SDK 3.1 */
920 if ((msg >= WM_CTLCOLORMSGBOX && msg <= WM_CTLCOLORSTATIC) ||
921 msg == WM_CTLCOLOR || msg == WM_COMPAREITEM ||
922 msg == WM_VKEYTOITEM || msg == WM_CHARTOITEM ||
923 msg == WM_QUERYDRAGICON || msg == WM_INITDIALOG)
924 return fResult;
925
926 return msgResult;
927}
928/***********************************************************************
929 * DEFDLG_SetFocus
930 *
931 * Set the focus to a control of the dialog, selecting the text if
932 * the control is an edit dialog.
933 */
934void Win32Dialog::setFocus(HWND hwndCtrl )
935{
936 HWND hwndPrev = GetFocus();
937
938 if (IsChild( hwndPrev ))
939 {
940 if (::SendMessageA( hwndPrev, WM_GETDLGCODE, 0, 0 ) & DLGC_HASSETSEL)
941 ::SendMessageA( hwndPrev, EM_SETSEL, TRUE, MAKELONG( -1, 0 ) );
942 }
943 if (::SendMessageA(hwndCtrl, WM_GETDLGCODE, 0, 0 ) & DLGC_HASSETSEL)
944 ::SendMessageA(hwndCtrl, EM_SETSEL, FALSE, MAKELONG( 0, -1 ) );
945 SetFocus( hwndCtrl );
946}
947
948
949/***********************************************************************
950 * DEFDLG_SaveFocus
951 */
952BOOL Win32Dialog::saveFocus()
953{
954 HWND hwndCurrentFocus = GetFocus();
955
956 if (!hwndCurrentFocus || !IsChild( hwndCurrentFocus )) return FALSE;
957
958 hwndFocus = hwndCurrentFocus;
959 /* Remove default button */
960 return TRUE;
961}
962
963
964/***********************************************************************
965 * DEFDLG_RestoreFocus
966 */
967BOOL Win32Dialog::restoreFocus()
968{
969 if (!hwndFocus || IsIconic()) return FALSE;
970
971 if (!::IsWindow( hwndFocus )) return FALSE;
972
973 /* Don't set the focus back to controls if EndDialog is already called.*/
974 if (!(dialogFlags & DF_END))
975 setFocus(hwndFocus);
976
977 /* This used to set infoPtr->hwndFocus to NULL for no apparent reason,
978 sometimes losing focus when receiving WM_SETFOCUS messages. */
979 return TRUE;
980}
981
982
983/***********************************************************************
984 * DEFDLG_FindDefButton
985 *
986 * Find the current default push-button.
987 */
988HWND Win32Dialog::findDefButton()
989{
990 HWND hwndChild = GetWindow( GW_CHILD );
991 while (hwndChild)
992 {
993 if (::SendMessageA( hwndChild, WM_GETDLGCODE, 0, 0 ) & DLGC_DEFPUSHBUTTON)
994 break;
995 hwndChild = ::GetWindow( hwndChild, GW_HWNDNEXT );
996 }
997 return hwndChild;
998}
999
1000
1001/***********************************************************************
1002 * DEFDLG_SetDefButton
1003 *
1004 * Set the new default button to be hwndNew.
1005 */
1006BOOL Win32Dialog::setDefButton(HWND hwndNew )
1007{
1008 if (hwndNew &&
1009 !(::SendMessageA(hwndNew, WM_GETDLGCODE, 0, 0 ) & DLGC_UNDEFPUSHBUTTON))
1010 return FALSE; /* Destination is not a push button */
1011
1012 if (idResult) /* There's already a default pushbutton */
1013 {
1014 HWND hwndOld = GetDlgItem( getWindowHandle(), idResult );
1015 if (::SendMessageA( hwndOld, WM_GETDLGCODE, 0, 0) & DLGC_DEFPUSHBUTTON)
1016 ::SendMessageA( hwndOld, BM_SETSTYLE, BS_PUSHBUTTON, TRUE );
1017 }
1018 if (hwndNew)
1019 {
1020 ::SendMessageA( hwndNew, BM_SETSTYLE, BS_DEFPUSHBUTTON, TRUE );
1021 idResult = GetDlgCtrlID( hwndNew );
1022 }
1023 else idResult = 0;
1024 return TRUE;
1025}
1026//******************************************************************************
1027//******************************************************************************
1028BOOL Win32Dialog::endDialog(int retval)
1029{
1030 dialogFlags |= DF_END;
1031 idResult = retval;
1032 return TRUE;
1033}
1034//******************************************************************************
1035//******************************************************************************
1036LONG Win32Dialog::SetWindowLongA(int index, ULONG value, BOOL fUnicode)
1037{
1038 LONG oldval;
1039
1040 dprintf2(("Win32Dialog::SetWindowLongA %x %d %x", getWindowHandle(), index, value));
1041 switch(index)
1042 {
1043 case DWL_DLGPROC:
1044 oldval = (LONG)WINPROC_GetProc(Win32DlgProc, (fUnicode) ? WIN_PROC_32W : WIN_PROC_32A);
1045 WINPROC_SetProc((HWINDOWPROC *)&Win32DlgProc, (WNDPROC)value, (fUnicode) ? WIN_PROC_32W : WIN_PROC_32A, WIN_PROC_WINDOW);
1046 return oldval;
1047 case DWL_MSGRESULT:
1048 oldval = msgResult;
1049 msgResult = value;
1050 return oldval;
1051 case DWL_USER:
1052 oldval = userDlgData;
1053 userDlgData = value;
1054 return oldval;
1055 default:
1056 return Win32BaseWindow::SetWindowLongA(index, value);
1057 }
1058}
1059//******************************************************************************
1060//******************************************************************************
1061ULONG Win32Dialog::GetWindowLongA(int index, BOOL fUnicode)
1062{
1063 dprintf2(("Win32Dialog::GetWindowLongA %x %d", getWindowHandle(), index));
1064 switch(index)
1065 {
1066 case DWL_DLGPROC:
1067 return (ULONG)WINPROC_GetProc(Win32DlgProc, (fUnicode) ? WIN_PROC_32W : WIN_PROC_32A);
1068 case DWL_MSGRESULT:
1069 return msgResult;
1070 case DWL_USER:
1071 return userDlgData;
1072 default:
1073 return Win32BaseWindow::GetWindowLongA(index);
1074 }
1075}
1076//******************************************************************************
1077//******************************************************************************
1078BOOL DIALOG_Register()
1079{
1080 WNDCLASSA wndClass;
1081
1082 ZeroMemory(&wndClass,sizeof(WNDCLASSA));
1083 wndClass.style = CS_GLOBALCLASS | CS_SAVEBITS;
1084 wndClass.lpfnWndProc = (WNDPROC)DefDlgProcA;
1085 wndClass.cbClsExtra = 0;
1086 wndClass.cbWndExtra = 0;
1087 wndClass.hCursor = LoadCursorA(0,IDC_ARROWA);
1088 wndClass.hbrBackground = GetSysColorBrush(COLOR_BTNFACE);
1089 wndClass.lpszClassName = DIALOG_CLASS_NAMEA;
1090
1091 return RegisterClassA(&wndClass);
1092}
1093//******************************************************************************
1094//******************************************************************************
1095BOOL DIALOG_Unregister()
1096{
1097 if (GlobalFindAtomA(DIALOG_CLASS_NAMEA))
1098 return UnregisterClassA(DIALOG_CLASS_NAMEA,(HINSTANCE)NULL);
1099 else return FALSE;
1100}
1101//******************************************************************************
1102//******************************************************************************
1103BOOL Win32Dialog::fInitialized = FALSE;
1104int Win32Dialog::xBaseUnit = 10;
1105int Win32Dialog::yBaseUnit = 20;
Note: See TracBrowser for help on using the repository browser.