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

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

Window creation rewrite + bugfixes. NOT WORKING CORRECTLY YET..

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