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