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

Last change on this file since 1525 was 1525, checked in by cbratschi, 26 years ago

button, static, scroll and dialog fixes

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