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

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

Rene Pronk's WM_(SYS)KEYUP/DOWN changes + SvL's dialog changes

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