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

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

SetLastError to 0 for dialog creation

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