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

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

Lots of changes by several people (see changelog for 4 October

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