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