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