source: trunk/src/user32/new/win32dlg.cpp@ 833

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

Dialog update

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