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

Last change on this file since 4686 was 4686, checked in by sandervl, 25 years ago

Dialog message fixes

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