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

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

Moved new user32 here

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