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

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

Dialog update

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