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

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

Lots of changes

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