| 1 | /* $Id: win32wbase.cpp,v 1.293 2001-10-18 11:02:22 sandervl Exp $ */ | 
|---|
| 2 | /* | 
|---|
| 3 | * Win32 Window Base Class for OS/2 | 
|---|
| 4 | * | 
|---|
| 5 | * Copyright 1998-2001 Sander van Leeuwen (sandervl@xs4all.nl) | 
|---|
| 6 | * Copyright 1999      Daniela Engert (dani@ngrt.de) | 
|---|
| 7 | * Copyright 1999-2000 Christoph Bratschi (cbratschi@datacomm.ch) | 
|---|
| 8 | * | 
|---|
| 9 | * Parts based on Wine Windows code (windows\win.c) | 
|---|
| 10 | *   Corel version: corel20000212 | 
|---|
| 11 | * | 
|---|
| 12 | * Copyright 1993, 1994, 1996 Alexandre Julliard | 
|---|
| 13 | *           1995 Alex Korobka | 
|---|
| 14 | * | 
|---|
| 15 | * TODO: Not thread/process safe | 
|---|
| 16 | * | 
|---|
| 17 | * NOTE: To access a window object, you must call GetWindowFromOS2Handle or | 
|---|
| 18 | *       GetWindowFromHandle. Both these methods increase the reference count | 
|---|
| 19 | *       of the object. When you're done with the object, you MUST call | 
|---|
| 20 | *       the release method! | 
|---|
| 21 | *       This mechanism prevents premature destruction of objects when there | 
|---|
| 22 | *       are still clients using it. | 
|---|
| 23 | * | 
|---|
| 24 | * NOTE: Client rectangle always relative to frame window | 
|---|
| 25 | *       Window rectangle in parent coordinates (relative to parent's client window) | 
|---|
| 26 | *       (screen coord. if no parent) | 
|---|
| 27 | * | 
|---|
| 28 | * NOTE: Status of window: | 
|---|
| 29 | *       Before a window has processed WM_NCCREATE: | 
|---|
| 30 | *       - GetTopWindow can't return that window handle | 
|---|
| 31 | *       - GetWindow(parent, GW_CHILD) can't return that window handle | 
|---|
| 32 | *       - IsChild works | 
|---|
| 33 | *       TODO: Does this affect more functions?? (other GetWindow ops) | 
|---|
| 34 | *       (verified in NT4, SP6) | 
|---|
| 35 | * | 
|---|
| 36 | * Project Odin Software License can be found in LICENSE.TXT | 
|---|
| 37 | * | 
|---|
| 38 | */ | 
|---|
| 39 | #include <os2win.h> | 
|---|
| 40 | #include <win.h> | 
|---|
| 41 | #include <stdlib.h> | 
|---|
| 42 | #include <string.h> | 
|---|
| 43 | #include <stdarg.h> | 
|---|
| 44 | #include <assert.h> | 
|---|
| 45 | #include <misc.h> | 
|---|
| 46 | #include <heapstring.h> | 
|---|
| 47 | #include <winuser32.h> | 
|---|
| 48 | #include "win32wbase.h" | 
|---|
| 49 | #include "wndmsg.h" | 
|---|
| 50 | #include "oslibwin.h" | 
|---|
| 51 | #include "oslibmsg.h" | 
|---|
| 52 | #include "oslibutil.h" | 
|---|
| 53 | #include "oslibgdi.h" | 
|---|
| 54 | #include "oslibres.h" | 
|---|
| 55 | #include "oslibdos.h" | 
|---|
| 56 | #include "syscolor.h" | 
|---|
| 57 | #include "win32wndhandle.h" | 
|---|
| 58 | #include "dc.h" | 
|---|
| 59 | #include "win32wdesktop.h" | 
|---|
| 60 | #include "pmwindow.h" | 
|---|
| 61 | #include "controls.h" | 
|---|
| 62 | #include <wprocess.h> | 
|---|
| 63 | #include <win\hook.h> | 
|---|
| 64 | #include <menu.h> | 
|---|
| 65 | #define INCL_TIMERWIN32 | 
|---|
| 66 | #include "timer.h" | 
|---|
| 67 |  | 
|---|
| 68 | #define DBG_LOCALLOG    DBG_win32wbase | 
|---|
| 69 | #include "dbglocal.h" | 
|---|
| 70 |  | 
|---|
| 71 | /* bits in the dwKeyData */ | 
|---|
| 72 | #define KEYDATA_ALT         0x2000 | 
|---|
| 73 | #define KEYDATA_PREVSTATE   0x4000 | 
|---|
| 74 |  | 
|---|
| 75 | void PrintWindowStyle(DWORD dwStyle, DWORD dwExStyle); | 
|---|
| 76 |  | 
|---|
| 77 | static fDestroyAll = FALSE; | 
|---|
| 78 | //For quick lookup of current process id | 
|---|
| 79 | static ULONG currentProcessId = -1; | 
|---|
| 80 | static int iF10Key = 0; | 
|---|
| 81 | static int iMenuSysKey = 0; | 
|---|
| 82 |  | 
|---|
| 83 |  | 
|---|
| 84 |  | 
|---|
| 85 | /*** | 
|---|
| 86 | * Performance Optimization: | 
|---|
| 87 | * we're directly inlining this micro function from win32wndhandle.cpp. | 
|---|
| 88 | * Changes there must be reflected here. | 
|---|
| 89 | ***/ | 
|---|
| 90 | extern ULONG WindowHandleTable[MAX_WINDOW_HANDLES]; | 
|---|
| 91 |  | 
|---|
| 92 | BOOL INLINE i_HwGetWindowHandleData(HWND hwnd, DWORD *pdwUserData) | 
|---|
| 93 | { | 
|---|
| 94 | if((hwnd & 0xFFFF0000) != WNDHANDLE_MAGIC_HIGHWORD) { | 
|---|
| 95 | return FALSE; //unknown window (PM?) | 
|---|
| 96 | } | 
|---|
| 97 | hwnd &= WNDHANDLE_MAGIC_MASK; | 
|---|
| 98 | if(hwnd < MAX_WINDOW_HANDLES) { | 
|---|
| 99 | *pdwUserData = WindowHandleTable[hwnd]; | 
|---|
| 100 | return TRUE; | 
|---|
| 101 | } | 
|---|
| 102 | *pdwUserData = 0; | 
|---|
| 103 | return FALSE; | 
|---|
| 104 | } | 
|---|
| 105 | #define HwGetWindowHandleData(a,b) i_HwGetWindowHandleData(a,b) | 
|---|
| 106 |  | 
|---|
| 107 |  | 
|---|
| 108 | //****************************************************************************** | 
|---|
| 109 | //****************************************************************************** | 
|---|
| 110 | Win32BaseWindow::Win32BaseWindow() | 
|---|
| 111 | : GenericObject(&windows, &critsect), ChildWindow(&critsect) | 
|---|
| 112 | { | 
|---|
| 113 | Init(); | 
|---|
| 114 | } | 
|---|
| 115 | //****************************************************************************** | 
|---|
| 116 | //****************************************************************************** | 
|---|
| 117 | Win32BaseWindow::Win32BaseWindow(HWND hwndOS2, ULONG reserved) | 
|---|
| 118 | : GenericObject(&windows, &critsect), ChildWindow(&critsect) | 
|---|
| 119 | { | 
|---|
| 120 | Init(); | 
|---|
| 121 | OS2Hwnd = hwndOS2; | 
|---|
| 122 | } | 
|---|
| 123 | //****************************************************************************** | 
|---|
| 124 | //****************************************************************************** | 
|---|
| 125 | Win32BaseWindow::Win32BaseWindow(CREATESTRUCTA *lpCreateStructA, ATOM classAtom, BOOL isUnicode) | 
|---|
| 126 | : GenericObject(&windows, &critsect), ChildWindow(&critsect) | 
|---|
| 127 | { | 
|---|
| 128 | Init(); | 
|---|
| 129 | this->isUnicode = isUnicode; | 
|---|
| 130 | CreateWindowExA(lpCreateStructA, classAtom); | 
|---|
| 131 | } | 
|---|
| 132 | //****************************************************************************** | 
|---|
| 133 | //****************************************************************************** | 
|---|
| 134 | void Win32BaseWindow::Init() | 
|---|
| 135 | { | 
|---|
| 136 | isUnicode        = FALSE; | 
|---|
| 137 | fFirstShow       = TRUE; | 
|---|
| 138 | fIsDialog        = FALSE; | 
|---|
| 139 | fIsModalDialogOwner = FALSE; | 
|---|
| 140 | OS2HwndModalDialog  = 0; | 
|---|
| 141 | fInternalMsg     = FALSE; | 
|---|
| 142 | fParentChange    = FALSE; | 
|---|
| 143 | fDestroyWindowCalled = FALSE; | 
|---|
| 144 | fTaskList        = FALSE; | 
|---|
| 145 | fParentDC        = FALSE; | 
|---|
| 146 | fComingToTop     = FALSE; | 
|---|
| 147 | fMinMaxChange    = FALSE; | 
|---|
| 148 | fVisibleRegionChanged = FALSE; | 
|---|
| 149 | fEraseBkgndFlag  = TRUE; | 
|---|
| 150 |  | 
|---|
| 151 | state            = STATE_INIT; | 
|---|
| 152 | windowNameA      = NULL; | 
|---|
| 153 | windowNameW      = NULL; | 
|---|
| 154 |  | 
|---|
| 155 | userWindowBytes  = NULL;; | 
|---|
| 156 | nrUserWindowBytes= 0; | 
|---|
| 157 |  | 
|---|
| 158 | OS2Hwnd          = 0; | 
|---|
| 159 | OS2HwndFrame     = 0; | 
|---|
| 160 | hSysMenu         = 0; | 
|---|
| 161 | Win32Hwnd        = 0; | 
|---|
| 162 |  | 
|---|
| 163 | if(HwAllocateWindowHandle(&Win32Hwnd, (ULONG)this) == FALSE) | 
|---|
| 164 | { | 
|---|
| 165 | dprintf(("Win32BaseWindow::Init HwAllocateWindowHandle failed!!")); | 
|---|
| 166 | DebugInt3(); | 
|---|
| 167 | } | 
|---|
| 168 |  | 
|---|
| 169 | posx = posy      = 0; | 
|---|
| 170 | width = height   = 0; | 
|---|
| 171 |  | 
|---|
| 172 | dwExStyle        = 0; | 
|---|
| 173 | dwStyle          = 0; | 
|---|
| 174 | dwOldStyle       = 0; | 
|---|
| 175 | win32wndproc     = 0; | 
|---|
| 176 | hInstance        = 0; | 
|---|
| 177 | dwIDMenu         = 0; //0xFFFFFFFF; //default -1 | 
|---|
| 178 | userData         = 0; | 
|---|
| 179 | contextHelpId    = 0; | 
|---|
| 180 | hotkey           = 0; | 
|---|
| 181 |  | 
|---|
| 182 |  | 
|---|
| 183 | hwndLinkAfter    = HWND_BOTTOM; | 
|---|
| 184 | flags            = 0; | 
|---|
| 185 | lastHitTestVal   = HTOS_NORMAL; | 
|---|
| 186 | owner            = NULL; | 
|---|
| 187 | windowClass      = 0; | 
|---|
| 188 |  | 
|---|
| 189 | hIcon            = 0; | 
|---|
| 190 | hIconSm          = 0; | 
|---|
| 191 |  | 
|---|
| 192 | horzScrollInfo   = NULL; | 
|---|
| 193 | vertScrollInfo   = NULL; | 
|---|
| 194 |  | 
|---|
| 195 | propertyList     = NULL; | 
|---|
| 196 |  | 
|---|
| 197 | cbExtra          = 0; | 
|---|
| 198 | pExtra           = NULL; | 
|---|
| 199 |  | 
|---|
| 200 | ownDC              = 0; | 
|---|
| 201 | hWindowRegion      = 0; | 
|---|
| 202 | hClipRegion        = 0; | 
|---|
| 203 |  | 
|---|
| 204 | hTaskList          = 0; | 
|---|
| 205 |  | 
|---|
| 206 | if(currentProcessId == -1) | 
|---|
| 207 | { | 
|---|
| 208 | currentProcessId = GetCurrentProcessId(); | 
|---|
| 209 | } | 
|---|
| 210 | dwThreadId         = GetCurrentThreadId(); | 
|---|
| 211 | dwProcessId        = currentProcessId; | 
|---|
| 212 |  | 
|---|
| 213 | memset(&windowpos, 0, sizeof(windowpos)); | 
|---|
| 214 | //min and max position are initially -1 (verified in NT4, SP6) | 
|---|
| 215 | windowpos.ptMinPosition.x = -1; | 
|---|
| 216 | windowpos.ptMinPosition.y = -1; | 
|---|
| 217 | windowpos.ptMaxPosition.x = -1; | 
|---|
| 218 | windowpos.ptMaxPosition.y = -1; | 
|---|
| 219 |  | 
|---|
| 220 | lpVisRgnNotifyProc  = NULL; | 
|---|
| 221 | dwVisRgnNotifyParam = NULL; | 
|---|
| 222 | } | 
|---|
| 223 | //****************************************************************************** | 
|---|
| 224 | //todo get rid of resources (menu, icon etc) | 
|---|
| 225 | //****************************************************************************** | 
|---|
| 226 | Win32BaseWindow::~Win32BaseWindow() | 
|---|
| 227 | { | 
|---|
| 228 | if(getRefCount() < 0) { | 
|---|
| 229 | DebugInt3(); | 
|---|
| 230 | } | 
|---|
| 231 |  | 
|---|
| 232 | if(hTaskList) { | 
|---|
| 233 | OSLibWinRemoveFromTasklist(hTaskList); | 
|---|
| 234 | } | 
|---|
| 235 |  | 
|---|
| 236 | OSLibWinSetVisibleRegionNotify(OS2Hwnd, FALSE); | 
|---|
| 237 | OSLibWinSetWindowULong(OS2Hwnd, OFFSET_WIN32WNDPTR, 0); | 
|---|
| 238 | OSLibWinSetWindowULong(OS2Hwnd, OFFSET_WIN32PM_MAGIC, 0); | 
|---|
| 239 |  | 
|---|
| 240 | if(fDestroyAll) { | 
|---|
| 241 | dprintf(("Destroying window %x %s", getWindowHandle(), windowNameA)); | 
|---|
| 242 | setParent(NULL);  //or else we'll crash in the dtor of the ChildWindow class | 
|---|
| 243 | } | 
|---|
| 244 | else | 
|---|
| 245 | if(getParent() && getParent()->getFirstChild() == this && getNextChild() == NULL) | 
|---|
| 246 | { | 
|---|
| 247 | //if we're the last child that's being destroyed and our | 
|---|
| 248 | //parent window was also destroyed, then we | 
|---|
| 249 | if(getParent()->IsWindowDestroyed()) | 
|---|
| 250 | { | 
|---|
| 251 | setParent(NULL);  //or else we'll crash in the dtor of the ChildWindow class | 
|---|
| 252 | } | 
|---|
| 253 | } | 
|---|
| 254 | /* Decrement class window counter */ | 
|---|
| 255 | if(windowClass) { | 
|---|
| 256 | RELEASE_CLASSOBJ(windowClass); | 
|---|
| 257 | } | 
|---|
| 258 |  | 
|---|
| 259 | if(isOwnDC()) | 
|---|
| 260 | releaseOwnDC(ownDC); | 
|---|
| 261 |  | 
|---|
| 262 | if(Win32Hwnd) | 
|---|
| 263 | HwFreeWindowHandle(Win32Hwnd); | 
|---|
| 264 |  | 
|---|
| 265 | if(userWindowBytes) | 
|---|
| 266 | free(userWindowBytes); | 
|---|
| 267 |  | 
|---|
| 268 | if(windowNameA) { | 
|---|
| 269 | free(windowNameA); | 
|---|
| 270 | windowNameA = NULL; | 
|---|
| 271 | } | 
|---|
| 272 | if(windowNameW) { | 
|---|
| 273 | free(windowNameW); | 
|---|
| 274 | windowNameW = NULL; | 
|---|
| 275 | } | 
|---|
| 276 | if(vertScrollInfo) { | 
|---|
| 277 | free(vertScrollInfo); | 
|---|
| 278 | vertScrollInfo = NULL; | 
|---|
| 279 | } | 
|---|
| 280 | if(horzScrollInfo) { | 
|---|
| 281 | free(horzScrollInfo); | 
|---|
| 282 | horzScrollInfo = NULL; | 
|---|
| 283 | } | 
|---|
| 284 | if(propertyList) { | 
|---|
| 285 | removeWindowProps(); | 
|---|
| 286 | } | 
|---|
| 287 | Win32BaseWindow *wndparent = (Win32BaseWindow *)ChildWindow::getParentOfChild(); | 
|---|
| 288 | if(wndparent && !fDestroyAll) { | 
|---|
| 289 | RELEASE_WNDOBJ(wndparent); | 
|---|
| 290 | } | 
|---|
| 291 | if(owner && !fDestroyAll) { | 
|---|
| 292 | RELEASE_WNDOBJ(owner); | 
|---|
| 293 | } | 
|---|
| 294 | if(windowClass) { | 
|---|
| 295 | RELEASE_CLASSOBJ(windowClass); | 
|---|
| 296 | } | 
|---|
| 297 | } | 
|---|
| 298 | //****************************************************************************** | 
|---|
| 299 | //****************************************************************************** | 
|---|
| 300 | void Win32BaseWindow::DestroyAll() | 
|---|
| 301 | { | 
|---|
| 302 | fDestroyAll = TRUE; | 
|---|
| 303 | GenericObject::DestroyAll(windows); | 
|---|
| 304 | } | 
|---|
| 305 | //****************************************************************************** | 
|---|
| 306 | //****************************************************************************** | 
|---|
| 307 | BOOL Win32BaseWindow::isChild() | 
|---|
| 308 | { | 
|---|
| 309 | return ((dwStyle & WS_CHILD) != 0); | 
|---|
| 310 | } | 
|---|
| 311 | //****************************************************************************** | 
|---|
| 312 | //****************************************************************************** | 
|---|
| 313 | BOOL Win32BaseWindow::IsWindowUnicode() | 
|---|
| 314 | { | 
|---|
| 315 | dprintf2(("IsWindowUnicode %x %d", getWindowHandle(), WINPROC_GetProcType(getWindowProc()) == WIN_PROC_32W)); | 
|---|
| 316 | return (WINPROC_GetProcType(getWindowProc()) == WIN_PROC_32W); | 
|---|
| 317 | } | 
|---|
| 318 | //****************************************************************************** | 
|---|
| 319 | //****************************************************************************** | 
|---|
| 320 | BOOL Win32BaseWindow::CreateWindowExA(CREATESTRUCTA *cs, ATOM classAtom) | 
|---|
| 321 | { | 
|---|
| 322 | char  buffer[256]; | 
|---|
| 323 |  | 
|---|
| 324 | #ifdef DEBUG | 
|---|
| 325 | PrintWindowStyle(cs->style, cs->dwExStyle); | 
|---|
| 326 | #endif | 
|---|
| 327 |  | 
|---|
| 328 | //If window has no owner/parent window, then it will be added to the tasklist | 
|---|
| 329 | //(depending on visibility state) | 
|---|
| 330 | if (!cs->hwndParent) fTaskList = TRUE; | 
|---|
| 331 |  | 
|---|
| 332 | sw = SW_SHOW; | 
|---|
| 333 | SetLastError(0); | 
|---|
| 334 |  | 
|---|
| 335 | /* Find the parent window */ | 
|---|
| 336 | if (cs->hwndParent) | 
|---|
| 337 | { | 
|---|
| 338 | Win32BaseWindow *window = GetWindowFromHandle(cs->hwndParent); | 
|---|
| 339 | if(!window) { | 
|---|
| 340 | dprintf(("Bad parent %04x\n", cs->hwndParent )); | 
|---|
| 341 | SetLastError(ERROR_INVALID_PARAMETER); | 
|---|
| 342 | return FALSE; | 
|---|
| 343 | } | 
|---|
| 344 | /* Make sure parent is valid */ | 
|---|
| 345 | if (!window->IsWindow() ) | 
|---|
| 346 | { | 
|---|
| 347 | RELEASE_WNDOBJ(window); | 
|---|
| 348 | dprintf(("Bad parent %04x\n", cs->hwndParent )); | 
|---|
| 349 | SetLastError(ERROR_INVALID_PARAMETER); | 
|---|
| 350 | return FALSE; | 
|---|
| 351 | } | 
|---|
| 352 | RELEASE_WNDOBJ(window); | 
|---|
| 353 | /* Windows does this for overlapped windows | 
|---|
| 354 | * (I don't know about other styles.) */ | 
|---|
| 355 | if (cs->hwndParent == GetDesktopWindow() && (!(cs->style & WS_CHILD) || (cs->style & WS_POPUP))) | 
|---|
| 356 | { | 
|---|
| 357 | cs->hwndParent = 0; | 
|---|
| 358 | } | 
|---|
| 359 | } | 
|---|
| 360 | else | 
|---|
| 361 | if ((cs->style & WS_CHILD) && !(cs->style & WS_POPUP)) { | 
|---|
| 362 | dprintf(("No parent for child window" )); | 
|---|
| 363 | SetLastError(ERROR_INVALID_PARAMETER); | 
|---|
| 364 | return FALSE;  /* WS_CHILD needs a parent, but WS_POPUP doesn't */ | 
|---|
| 365 | } | 
|---|
| 366 |  | 
|---|
| 367 | /* Find the window class */ | 
|---|
| 368 | windowClass = Win32WndClass::FindClass(cs->hInstance, (LPSTR)classAtom); | 
|---|
| 369 | if (!windowClass) | 
|---|
| 370 | { | 
|---|
| 371 | GlobalGetAtomNameA( classAtom, buffer, sizeof(buffer) ); | 
|---|
| 372 | dprintf(("Bad class '%s'", buffer )); | 
|---|
| 373 | SetLastError(ERROR_INVALID_PARAMETER); | 
|---|
| 374 | return 0; | 
|---|
| 375 | } | 
|---|
| 376 |  | 
|---|
| 377 | #ifdef DEBUG | 
|---|
| 378 | if(HIWORD(cs->lpszClass)) | 
|---|
| 379 | { | 
|---|
| 380 | if(isUnicode) dprintf(("Window class %ls", cs->lpszClass)); | 
|---|
| 381 | else          dprintf(("Window class %s", cs->lpszClass)); | 
|---|
| 382 | } | 
|---|
| 383 | else dprintf(("Window class %x", cs->lpszClass)); | 
|---|
| 384 | #endif | 
|---|
| 385 |  | 
|---|
| 386 | /* Fix the lpszClass field: from existing programs, it seems ok to call a CreateWindowXXX | 
|---|
| 387 | * with an atom as the class name, put some programs expect to have a *REAL* string in | 
|---|
| 388 | * lpszClass when the CREATESTRUCT is sent with WM_CREATE | 
|---|
| 389 | */ | 
|---|
| 390 | if (!HIWORD(cs->lpszClass) ) { | 
|---|
| 391 | if (isUnicode) { | 
|---|
| 392 | GlobalGetAtomNameW( classAtom, (LPWSTR)buffer, sizeof(buffer) ); | 
|---|
| 393 | } | 
|---|
| 394 | else { | 
|---|
| 395 | GlobalGetAtomNameA( classAtom, buffer, sizeof(buffer) ); | 
|---|
| 396 | } | 
|---|
| 397 | cs->lpszClass = buffer; | 
|---|
| 398 | } | 
|---|
| 399 |  | 
|---|
| 400 | /* Fix the coordinates */ | 
|---|
| 401 | fXDefault = FALSE; | 
|---|
| 402 | fCXDefault = FALSE; | 
|---|
| 403 | if ((cs->x == CW_USEDEFAULT) || (cs->x == CW_USEDEFAULT16)) | 
|---|
| 404 | { | 
|---|
| 405 | /* Never believe Microsoft's documentation... CreateWindowEx doc says | 
|---|
| 406 | * that if an overlapped window is created with WS_VISIBLE style bit | 
|---|
| 407 | * set and the x parameter is set to CW_USEDEFAULT, the system ignores | 
|---|
| 408 | * the y parameter. However, disassembling NT implementation (WIN32K.SYS) | 
|---|
| 409 | * reveals that | 
|---|
| 410 | * | 
|---|
| 411 | * 1) not only if checks for CW_USEDEFAULT but also for CW_USEDEFAULT16 | 
|---|
| 412 | * 2) it does not ignore the y parameter as the docs claim; instead, it | 
|---|
| 413 | *    uses it as second parameter to ShowWindow() unless y is either | 
|---|
| 414 | *    CW_USEDEFAULT or CW_USEDEFAULT16. | 
|---|
| 415 | * | 
|---|
| 416 | * The fact that we didn't do 2) caused bogus windows pop up when wine | 
|---|
| 417 | * was running apps that were using this obscure feature. Example - | 
|---|
| 418 | * calc.exe that comes with Win98 (only Win98, it's different from | 
|---|
| 419 | * the one that comes with Win95 and NT) | 
|---|
| 420 | */ | 
|---|
| 421 | if ((cs->y != CW_USEDEFAULT) && (cs->y != CW_USEDEFAULT16)) sw = cs->y; | 
|---|
| 422 |  | 
|---|
| 423 | /* We have saved cs->y, now we can trash it */ | 
|---|
| 424 | cs->x = 0; | 
|---|
| 425 | cs->y = 0; | 
|---|
| 426 | fXDefault = TRUE; | 
|---|
| 427 | } | 
|---|
| 428 | if ((cs->cx == CW_USEDEFAULT) || (cs->cx == CW_USEDEFAULT16)) | 
|---|
| 429 | { | 
|---|
| 430 | cs->cx = 600; /* FIXME */ | 
|---|
| 431 | cs->cy = 400; | 
|---|
| 432 | fCXDefault = TRUE; | 
|---|
| 433 | } | 
|---|
| 434 | if (cs->style & (WS_POPUP | WS_CHILD)) | 
|---|
| 435 | { | 
|---|
| 436 | fXDefault = FALSE; | 
|---|
| 437 | if (fCXDefault) | 
|---|
| 438 | { | 
|---|
| 439 | fCXDefault = FALSE; | 
|---|
| 440 | cs->cx = cs->cy = 0; | 
|---|
| 441 | } | 
|---|
| 442 | } | 
|---|
| 443 | if (fXDefault && !fCXDefault) fXDefault = FALSE; //CB: only x positioning doesn't work (calc.exe,cdrlabel.exe) | 
|---|
| 444 |  | 
|---|
| 445 | //Allocate window words | 
|---|
| 446 | nrUserWindowBytes = windowClass->getExtraWndBytes(); | 
|---|
| 447 | if(nrUserWindowBytes) { | 
|---|
| 448 | userWindowBytes = (char *)_smalloc(nrUserWindowBytes); | 
|---|
| 449 | memset(userWindowBytes, 0, nrUserWindowBytes); | 
|---|
| 450 | } | 
|---|
| 451 |  | 
|---|
| 452 | if ((cs->style & WS_CHILD) && cs->hwndParent) | 
|---|
| 453 | { | 
|---|
| 454 | SetParent(cs->hwndParent); | 
|---|
| 455 | //        owner = GetWindowFromHandle(cs->hwndParent); | 
|---|
| 456 | owner = 0; | 
|---|
| 457 | /*        if(owner == NULL) | 
|---|
| 458 | { | 
|---|
| 459 | dprintf(("HwGetWindowHandleData couldn't find owner window %x!!!", cs->hwndParent)); | 
|---|
| 460 | SetLastError(ERROR_INVALID_WINDOW_HANDLE); | 
|---|
| 461 | return FALSE; | 
|---|
| 462 | }*/ | 
|---|
| 463 | //SvL: Shell positioning shouldn't be done for child windows! (breaks Notes) | 
|---|
| 464 | fXDefault = fCXDefault = FALSE; | 
|---|
| 465 | } | 
|---|
| 466 | else | 
|---|
| 467 | { | 
|---|
| 468 | SetParent(0); | 
|---|
| 469 | if (!cs->hwndParent || (cs->hwndParent == windowDesktop->getWindowHandle())) { | 
|---|
| 470 | owner = NULL; | 
|---|
| 471 | } | 
|---|
| 472 | else | 
|---|
| 473 | { | 
|---|
| 474 | Win32BaseWindow *wndparent = GetWindowFromHandle(cs->hwndParent); | 
|---|
| 475 | if(wndparent) { | 
|---|
| 476 | owner = GetWindowFromHandle(wndparent->GetTopParent()); | 
|---|
| 477 | RELEASE_WNDOBJ(wndparent); | 
|---|
| 478 | } | 
|---|
| 479 | else owner = NULL; | 
|---|
| 480 |  | 
|---|
| 481 | if(owner == NULL) | 
|---|
| 482 | { | 
|---|
| 483 | dprintf(("HwGetWindowHandleData couldn't find owner window %x!!!", cs->hwndParent)); | 
|---|
| 484 | SetLastError(ERROR_INVALID_WINDOW_HANDLE); | 
|---|
| 485 | return FALSE; | 
|---|
| 486 | } | 
|---|
| 487 | } | 
|---|
| 488 | } | 
|---|
| 489 |  | 
|---|
| 490 | WINPROC_SetProc((HWINDOWPROC *)&win32wndproc, windowClass->getWindowProc(), WINPROC_GetProcType(windowClass->getWindowProc()), WIN_PROC_WINDOW); | 
|---|
| 491 | hInstance  = cs->hInstance; | 
|---|
| 492 | dwStyle    = cs->style & ~WS_VISIBLE; | 
|---|
| 493 | dwOldStyle = dwStyle; | 
|---|
| 494 | dwExStyle  = cs->dwExStyle; | 
|---|
| 495 |  | 
|---|
| 496 | hwndLinkAfter = ((cs->style & (WS_CHILD|WS_MAXIMIZE)) == WS_CHILD) ? HWND_BOTTOM : HWND_TOP; | 
|---|
| 497 |  | 
|---|
| 498 | /* Correct the window style */ | 
|---|
| 499 | if (!(cs->style & WS_CHILD)) | 
|---|
| 500 | { | 
|---|
| 501 | dwStyle |= WS_CLIPSIBLINGS; | 
|---|
| 502 | if (!(cs->style & WS_POPUP)) | 
|---|
| 503 | { | 
|---|
| 504 | dwStyle |= WS_CAPTION; | 
|---|
| 505 | flags |= WIN_NEED_SIZE; | 
|---|
| 506 | } | 
|---|
| 507 | } | 
|---|
| 508 | if (cs->dwExStyle & WS_EX_DLGMODALFRAME) dwStyle &= ~WS_THICKFRAME; | 
|---|
| 509 |  | 
|---|
| 510 | //copy pointer of CREATESTRUCT for usage in MsgCreate method | 
|---|
| 511 | tmpcs = cs; | 
|---|
| 512 |  | 
|---|
| 513 | //Store our window object pointer in thread local memory, so PMWINDOW.CPP can retrieve it | 
|---|
| 514 | TEB *teb = GetThreadTEB(); | 
|---|
| 515 | if(teb == NULL) { | 
|---|
| 516 | dprintf(("Window creation failed - teb == NULL")); //this is VERY bad | 
|---|
| 517 | ExitProcess(666); | 
|---|
| 518 | return FALSE; | 
|---|
| 519 | } | 
|---|
| 520 |  | 
|---|
| 521 | teb->o.odin.newWindow = (ULONG)this; | 
|---|
| 522 |  | 
|---|
| 523 | DWORD dwOSWinStyle, dwOSFrameStyle; | 
|---|
| 524 |  | 
|---|
| 525 | OSLibWinConvertStyle(dwStyle,dwExStyle,&dwOSWinStyle, &dwOSFrameStyle); | 
|---|
| 526 |  | 
|---|
| 527 | OS2Hwnd = OSLibWinCreateWindow((getParent()) ? getParent()->getOS2WindowHandle() : OSLIB_HWND_DESKTOP, | 
|---|
| 528 | dwOSWinStyle, dwOSFrameStyle, (char *)windowNameA, | 
|---|
| 529 | (owner) ? owner->getOS2WindowHandle() : ((getParent()) ? getParent()->getOS2WindowHandle() : OSLIB_HWND_DESKTOP), | 
|---|
| 530 | (hwndLinkAfter == HWND_BOTTOM) ? TRUE : FALSE, | 
|---|
| 531 | 0, fTaskList,fXDefault | fCXDefault,windowClass->getStyle(), &OS2HwndFrame); | 
|---|
| 532 | if(OS2Hwnd == 0) { | 
|---|
| 533 | dprintf(("Window creation failed!! OS LastError %0x", OSLibWinGetLastError())); | 
|---|
| 534 | SetLastError(ERROR_OUTOFMEMORY); //TODO: Better error | 
|---|
| 535 | return FALSE; | 
|---|
| 536 | } | 
|---|
| 537 | OSLibWinSetVisibleRegionNotify(OS2Hwnd, TRUE); | 
|---|
| 538 | state = STATE_CREATED; | 
|---|
| 539 | SetLastError(0); | 
|---|
| 540 | return TRUE; | 
|---|
| 541 | } | 
|---|
| 542 | //****************************************************************************** | 
|---|
| 543 | //****************************************************************************** | 
|---|
| 544 | BOOL Win32BaseWindow::MsgCreate(HWND hwndOS2) | 
|---|
| 545 | { | 
|---|
| 546 | CREATESTRUCTA *cs = tmpcs;  //pointer to CREATESTRUCT used in CreateWindowExA method | 
|---|
| 547 | POINT          maxSize, maxPos, minTrack, maxTrack; | 
|---|
| 548 | HWND           hwnd = getWindowHandle(); | 
|---|
| 549 | LRESULT (* CALLBACK localSend32)(HWND, UINT, WPARAM, LPARAM); | 
|---|
| 550 |  | 
|---|
| 551 | OS2Hwnd      = hwndOS2; | 
|---|
| 552 |  | 
|---|
| 553 | if(OSLibWinSetWindowULong(OS2Hwnd, OFFSET_WIN32WNDPTR, getWindowHandle()) == FALSE) { | 
|---|
| 554 | dprintf(("WM_CREATE: WinSetWindowULong %X failed!!", OS2Hwnd)); | 
|---|
| 555 | SetLastError(ERROR_OUTOFMEMORY); //TODO: Better error | 
|---|
| 556 | return FALSE; | 
|---|
| 557 | } | 
|---|
| 558 | if(OSLibWinSetWindowULong(OS2Hwnd, OFFSET_WIN32PM_MAGIC, WIN32PM_MAGIC) == FALSE) { | 
|---|
| 559 | dprintf(("WM_CREATE: WinSetWindowULong2 %X failed!!", OS2Hwnd)); | 
|---|
| 560 | SetLastError(ERROR_OUTOFMEMORY); //TODO: Better error | 
|---|
| 561 | return FALSE; | 
|---|
| 562 | } | 
|---|
| 563 | if(OSLibWinSetWindowULong(OS2Hwnd, OFFSET_WIN32FLAGS, 0) == FALSE) { | 
|---|
| 564 | dprintf(("WM_CREATE: WinSetWindowULong2 %X failed!!", OS2Hwnd)); | 
|---|
| 565 | SetLastError(ERROR_OUTOFMEMORY); //TODO: Better error | 
|---|
| 566 | return FALSE; | 
|---|
| 567 | } | 
|---|
| 568 |  | 
|---|
| 569 | if (HOOK_IsHooked( WH_CBT )) | 
|---|
| 570 | { | 
|---|
| 571 | CBT_CREATEWNDA cbtc; | 
|---|
| 572 | LRESULT ret; | 
|---|
| 573 |  | 
|---|
| 574 | cbtc.lpcs = cs; | 
|---|
| 575 | cbtc.hwndInsertAfter = hwndLinkAfter; | 
|---|
| 576 | ret = (isUnicode) ? HOOK_CallHooksW(WH_CBT, HCBT_CREATEWND, getWindowHandle(), (LPARAM)&cbtc) | 
|---|
| 577 | : HOOK_CallHooksA(WH_CBT, HCBT_CREATEWND, getWindowHandle(), (LPARAM)&cbtc); | 
|---|
| 578 | if(ret) | 
|---|
| 579 | { | 
|---|
| 580 | dprintf(("CBT-hook returned 0!!")); | 
|---|
| 581 | SetLastError(ERROR_CAN_NOT_COMPLETE); //todo: wrong error | 
|---|
| 582 | return FALSE; | 
|---|
| 583 | } | 
|---|
| 584 | //todo: if hook changes parent, we need to do so too!!!!!!!!!! | 
|---|
| 585 | } | 
|---|
| 586 |  | 
|---|
| 587 | if (cs->style & WS_HSCROLL) | 
|---|
| 588 | { | 
|---|
| 589 | horzScrollInfo = (SCROLLBAR_INFO*)malloc(sizeof(SCROLLBAR_INFO)); | 
|---|
| 590 | horzScrollInfo->MinVal = horzScrollInfo->CurVal = horzScrollInfo->Page = 0; | 
|---|
| 591 | horzScrollInfo->MaxVal = 100; | 
|---|
| 592 | horzScrollInfo->flags  = ESB_ENABLE_BOTH; | 
|---|
| 593 | } | 
|---|
| 594 |  | 
|---|
| 595 | if (cs->style & WS_VSCROLL) | 
|---|
| 596 | { | 
|---|
| 597 | vertScrollInfo = (SCROLLBAR_INFO*)malloc(sizeof(SCROLLBAR_INFO)); | 
|---|
| 598 | vertScrollInfo->MinVal = vertScrollInfo->CurVal = vertScrollInfo->Page = 0; | 
|---|
| 599 | vertScrollInfo->MaxVal = 100; | 
|---|
| 600 | vertScrollInfo->flags  = ESB_ENABLE_BOTH; | 
|---|
| 601 | } | 
|---|
| 602 |  | 
|---|
| 603 | if(HIWORD(cs->lpszName)) | 
|---|
| 604 | { | 
|---|
| 605 | if (!isUnicode) | 
|---|
| 606 | { | 
|---|
| 607 | int wndNameLength = strlen(cs->lpszName); | 
|---|
| 608 | windowNameA = (LPSTR)_smalloc(wndNameLength+1); | 
|---|
| 609 | strcpy(windowNameA,cs->lpszName); | 
|---|
| 610 | windowNameW = (LPWSTR)_smalloc((wndNameLength+1)*sizeof(WCHAR)); | 
|---|
| 611 | lstrcpyAtoW(windowNameW,windowNameA); | 
|---|
| 612 | windowNameA[wndNameLength] = 0; | 
|---|
| 613 | windowNameW[wndNameLength] = 0; | 
|---|
| 614 | } | 
|---|
| 615 | else | 
|---|
| 616 | { | 
|---|
| 617 | // Wide | 
|---|
| 618 | int wndNameLength = lstrlenW((LPWSTR)cs->lpszName); | 
|---|
| 619 | windowNameW = (LPWSTR)_smalloc((wndNameLength+1)*sizeof(WCHAR)); | 
|---|
| 620 | lstrcpyW(windowNameW,(LPWSTR)cs->lpszName); | 
|---|
| 621 | windowNameW[lstrlenW((LPWSTR)cs->lpszName)] = 0; // need ? | 
|---|
| 622 | // Ascii | 
|---|
| 623 | LPSTR tmp = HEAP_strdupWtoA(GetProcessHeap(), 0, (LPWSTR)cs->lpszName); | 
|---|
| 624 | if(tmp) { | 
|---|
| 625 | long tmpLength = strlen( tmp ); | 
|---|
| 626 | windowNameA = (LPSTR)_smalloc(tmpLength+1); | 
|---|
| 627 | strcpy(windowNameA,tmp); | 
|---|
| 628 | windowNameA[tmpLength] = 0; // need ? | 
|---|
| 629 | HEAP_free(tmp); | 
|---|
| 630 | } else { | 
|---|
| 631 | windowNameA = (LPSTR)_smalloc(1); | 
|---|
| 632 | windowNameA[0] = 0; | 
|---|
| 633 | } | 
|---|
| 634 | } | 
|---|
| 635 | if(fOS2Look) { | 
|---|
| 636 | OSLibWinSetTitleBarText(OS2HwndFrame, windowNameA); | 
|---|
| 637 | } | 
|---|
| 638 | } | 
|---|
| 639 |  | 
|---|
| 640 | //SvL: This completely messes up MS Word 97 (no button bar, no menu) | 
|---|
| 641 | #if 0 | 
|---|
| 642 | //adjust CW_USEDEFAULT position | 
|---|
| 643 | if (fXDefault | fCXDefault) | 
|---|
| 644 | { | 
|---|
| 645 | RECT rect; | 
|---|
| 646 |  | 
|---|
| 647 | //SvL: Returns invalid rectangle (not the expected shell default size) | 
|---|
| 648 | OSLibWinQueryWindowRect(OS2Hwnd,&rect,RELATIVE_TO_SCREEN); | 
|---|
| 649 | if (getParent()) mapWin32Rect(OSLIB_HWND_DESKTOP,getParent()->getOS2WindowHandle(),&rect); | 
|---|
| 650 | if (fXDefault) | 
|---|
| 651 | { | 
|---|
| 652 | cs->x = rect.left; | 
|---|
| 653 | cs->y = rect.top; | 
|---|
| 654 | if (!fCXDefault) | 
|---|
| 655 | { | 
|---|
| 656 | //CB: todo: adjust pos to screen rect | 
|---|
| 657 | } | 
|---|
| 658 | } | 
|---|
| 659 | if (fCXDefault) | 
|---|
| 660 | { | 
|---|
| 661 | cs->cx = rect.right-rect.left; | 
|---|
| 662 | cs->cy = rect.bottom-rect.top; | 
|---|
| 663 | } | 
|---|
| 664 | } | 
|---|
| 665 | #endif | 
|---|
| 666 |  | 
|---|
| 667 | fakeWinBase.hwndThis     = OS2Hwnd; | 
|---|
| 668 | fakeWinBase.pWindowClass = windowClass; | 
|---|
| 669 |  | 
|---|
| 670 | //Set icon from window or class | 
|---|
| 671 | if (hIcon) | 
|---|
| 672 | OSLibWinSetIcon(OS2HwndFrame,hIcon); | 
|---|
| 673 | else | 
|---|
| 674 | if (windowClass->getIcon()) | 
|---|
| 675 | OSLibWinSetIcon(OS2HwndFrame,windowClass->getIcon()); | 
|---|
| 676 |  | 
|---|
| 677 | /* Get class or window DC if needed */ | 
|---|
| 678 | if(windowClass->getStyle() & CS_OWNDC) { | 
|---|
| 679 | dprintf(("Class with CS_OWNDC style")); | 
|---|
| 680 | ownDC = GetDCEx(getWindowHandle(), NULL, DCX_USESTYLE); | 
|---|
| 681 | } | 
|---|
| 682 | else | 
|---|
| 683 | if (windowClass->getStyle() & CS_PARENTDC)  { | 
|---|
| 684 | fParentDC = TRUE; | 
|---|
| 685 | ownDC = 0; | 
|---|
| 686 | } | 
|---|
| 687 | else | 
|---|
| 688 | if (windowClass->getStyle() & CS_CLASSDC)  { | 
|---|
| 689 | dprintf(("WARNING: Class with CS_CLASSDC style!")); | 
|---|
| 690 | //not a good solution, but it's a bit difficult to share a single | 
|---|
| 691 | //DC among different windows... DevOpenDC apparently can't be used | 
|---|
| 692 | //for window DCs and WinOpenWindowDC must be associated with a window | 
|---|
| 693 | ownDC = GetDCEx(getWindowHandle(), NULL, DCX_USESTYLE); | 
|---|
| 694 | } | 
|---|
| 695 | /* Set the window menu */ | 
|---|
| 696 | if ((dwStyle & (WS_CAPTION | WS_CHILD)) == WS_CAPTION ) | 
|---|
| 697 | { | 
|---|
| 698 | if (cs->hMenu) { | 
|---|
| 699 | ::SetMenu(getWindowHandle(), cs->hMenu); | 
|---|
| 700 | } | 
|---|
| 701 | else { | 
|---|
| 702 | if (windowClass->getMenuNameA()) { | 
|---|
| 703 | cs->hMenu = LoadMenuA(windowClass->getInstance(),windowClass->getMenuNameA()); | 
|---|
| 704 | #if 0 //CB: hack for treeview test cases bug | 
|---|
| 705 | if (!cs->hMenu) cs->hMenu = LoadMenuA(windowClass->getInstance(),"MYAPP"); | 
|---|
| 706 | #endif | 
|---|
| 707 | if (cs->hMenu) ::SetMenu(getWindowHandle(), cs->hMenu ); | 
|---|
| 708 | } | 
|---|
| 709 | } | 
|---|
| 710 | } | 
|---|
| 711 | else | 
|---|
| 712 | { | 
|---|
| 713 | setWindowId((DWORD)cs->hMenu); | 
|---|
| 714 | } | 
|---|
| 715 | hSysMenu = (dwStyle & WS_SYSMENU) ? MENU_GetSysMenu(Win32Hwnd,0):0; | 
|---|
| 716 |  | 
|---|
| 717 | /* Send the WM_GETMINMAXINFO message and fix the size if needed */ | 
|---|
| 718 | if ((cs->style & WS_THICKFRAME) || !(cs->style & (WS_POPUP | WS_CHILD))) | 
|---|
| 719 | { | 
|---|
| 720 | GetMinMaxInfo(&maxSize, &maxPos, &minTrack, &maxTrack); | 
|---|
| 721 | if (maxSize.x < cs->cx) cs->cx = maxSize.x; | 
|---|
| 722 | if (maxSize.y < cs->cy) cs->cy = maxSize.y; | 
|---|
| 723 | if (cs->cx < minTrack.x) cs->cx = minTrack.x; | 
|---|
| 724 | if (cs->cy < minTrack.y) cs->cy = minTrack.y; | 
|---|
| 725 | } | 
|---|
| 726 |  | 
|---|
| 727 | if(cs->style & WS_CHILD) | 
|---|
| 728 | { | 
|---|
| 729 | if(cs->cx < 0) cs->cx = 0; | 
|---|
| 730 | if(cs->cy < 0) cs->cy = 0; | 
|---|
| 731 | } | 
|---|
| 732 | else | 
|---|
| 733 | { | 
|---|
| 734 | if (cs->cx <= 0) cs->cx = 1; | 
|---|
| 735 | if (cs->cy <= 0) cs->cy = 1; | 
|---|
| 736 | } | 
|---|
| 737 |  | 
|---|
| 738 | //set client & window rectangles from CreateWindowEx CREATESTRUCT | 
|---|
| 739 | rectWindow.left = cs->x; | 
|---|
| 740 | rectWindow.right = cs->x+cs->cx; | 
|---|
| 741 | rectWindow.top = cs->y; | 
|---|
| 742 | rectWindow.bottom = cs->y+cs->cy; | 
|---|
| 743 | rectClient = rectWindow; | 
|---|
| 744 | OffsetRect(&rectClient, -rectClient.left, -rectClient.top); | 
|---|
| 745 |  | 
|---|
| 746 | /* Send the WM_CREATE message | 
|---|
| 747 | * Perhaps we shouldn't allow width/height changes as well. | 
|---|
| 748 | * See p327 in "Internals". | 
|---|
| 749 | */ | 
|---|
| 750 | maxPos.x = rectWindow.left; maxPos.y = rectWindow.top; | 
|---|
| 751 |  | 
|---|
| 752 | if(fTaskList) { | 
|---|
| 753 | hTaskList = OSLibWinAddToTaskList(OS2HwndFrame, windowNameA, (cs->style & WS_VISIBLE) ? 1 : 0); | 
|---|
| 754 | } | 
|---|
| 755 |  | 
|---|
| 756 | localSend32 = (isUnicode) ? ::SendMessageW : ::SendMessageA; | 
|---|
| 757 |  | 
|---|
| 758 | state = STATE_PRE_WMNCCREATE; | 
|---|
| 759 | if(localSend32(getWindowHandle(), WM_NCCREATE,0,(LPARAM)cs)) | 
|---|
| 760 | { | 
|---|
| 761 | RECT tmpRect; | 
|---|
| 762 |  | 
|---|
| 763 | //CB: recheck flags | 
|---|
| 764 | if (cs->style & (WS_POPUP | WS_CHILD)) | 
|---|
| 765 | { | 
|---|
| 766 | fXDefault = FALSE; | 
|---|
| 767 | if (fCXDefault) | 
|---|
| 768 | { | 
|---|
| 769 | fCXDefault = FALSE; | 
|---|
| 770 | cs->cx = cs->cy = 0; | 
|---|
| 771 | rectWindow.right  = rectWindow.left; | 
|---|
| 772 | rectWindow.bottom = rectWindow.top; | 
|---|
| 773 | } | 
|---|
| 774 | } | 
|---|
| 775 | tmpRect = rectWindow; | 
|---|
| 776 | state   = STATE_POST_WMNCCREATE; | 
|---|
| 777 |  | 
|---|
| 778 | //set the window size and update the client | 
|---|
| 779 | SetWindowPos(hwndLinkAfter, tmpRect.left, tmpRect.top, tmpRect.right-tmpRect.left, tmpRect.bottom-tmpRect.top,SWP_NOACTIVATE | SWP_NOREDRAW | SWP_FRAMECHANGED); | 
|---|
| 780 |  | 
|---|
| 781 | state = STATE_PRE_WMCREATE; | 
|---|
| 782 | if (cs->style & WS_VISIBLE) dwStyle |= WS_VISIBLE; //program could change position in WM_CREATE | 
|---|
| 783 | if( (localSend32(getWindowHandle(), WM_CREATE, 0, (LPARAM)cs )) != -1 ) | 
|---|
| 784 | { | 
|---|
| 785 | state = STATE_POST_WMCREATE; | 
|---|
| 786 |  | 
|---|
| 787 | if(!(flags & WIN_NEED_SIZE)) | 
|---|
| 788 | { | 
|---|
| 789 | SendInternalMessageA(WM_SIZE, SIZE_RESTORED, | 
|---|
| 790 | MAKELONG(rectClient.right-rectClient.left, | 
|---|
| 791 | rectClient.bottom-rectClient.top)); | 
|---|
| 792 |  | 
|---|
| 793 | if(!::IsWindow(hwnd)) | 
|---|
| 794 | { | 
|---|
| 795 | dprintf(("Createwindow: WM_SIZE destroyed window")); | 
|---|
| 796 | goto end; | 
|---|
| 797 | } | 
|---|
| 798 | SendInternalMessageA(WM_MOVE,0,MAKELONG(rectClient.left,rectClient.top)); | 
|---|
| 799 | if(!::IsWindow(hwnd)) | 
|---|
| 800 | { | 
|---|
| 801 | dprintf(("Createwindow: WM_MOVE destroyed window")); | 
|---|
| 802 | goto end; | 
|---|
| 803 | } | 
|---|
| 804 | } | 
|---|
| 805 | if (getStyle() & (WS_MINIMIZE | WS_MAXIMIZE)) | 
|---|
| 806 | { | 
|---|
| 807 | RECT newPos; | 
|---|
| 808 | UINT swFlag = (getStyle() & WS_MINIMIZE) ? SW_MINIMIZE : SW_MAXIMIZE; | 
|---|
| 809 | setStyle(getStyle() & ~(WS_MAXIMIZE | WS_MINIMIZE)); | 
|---|
| 810 | MinMaximize(swFlag, &newPos); | 
|---|
| 811 | swFlag = ((getStyle() & WS_CHILD) || GetActiveWindow()) ? SWP_NOACTIVATE | SWP_NOZORDER | SWP_FRAMECHANGED | 
|---|
| 812 | : SWP_NOZORDER | SWP_FRAMECHANGED; | 
|---|
| 813 | SetWindowPos(0, newPos.left, newPos.top,  newPos.right, newPos.bottom, swFlag); | 
|---|
| 814 | if(!::IsWindow(hwnd)) | 
|---|
| 815 | { | 
|---|
| 816 | dprintf(("Createwindow: min/max destroyed window")); | 
|---|
| 817 | goto end; | 
|---|
| 818 | } | 
|---|
| 819 | } | 
|---|
| 820 |  | 
|---|
| 821 | if( (getStyle() & WS_CHILD) && !(getExStyle() & WS_EX_NOPARENTNOTIFY) ) | 
|---|
| 822 | { | 
|---|
| 823 | /* Notify the parent window only */ | 
|---|
| 824 | if(getParent() && getParent()->IsWindowDestroyed() == FALSE) | 
|---|
| 825 | { | 
|---|
| 826 | getParent()->SendInternalMessageA(WM_PARENTNOTIFY, MAKEWPARAM(WM_CREATE, getWindowId()), (LPARAM)getWindowHandle()); | 
|---|
| 827 | } | 
|---|
| 828 | if(!::IsWindow(hwnd)) | 
|---|
| 829 | { | 
|---|
| 830 | dprintf(("Createwindow: WM_PARENTNOTIFY destroyed window")); | 
|---|
| 831 | goto end; | 
|---|
| 832 | } | 
|---|
| 833 | } | 
|---|
| 834 |  | 
|---|
| 835 | if(cs->style & WS_VISIBLE) { | 
|---|
| 836 | dwStyle &= ~WS_VISIBLE; | 
|---|
| 837 | ShowWindow(sw); | 
|---|
| 838 | } | 
|---|
| 839 |  | 
|---|
| 840 | /* Call WH_SHELL hook */ | 
|---|
| 841 | if (!(getStyle() & WS_CHILD) && !owner) | 
|---|
| 842 | HOOK_CallHooksA(WH_SHELL, HSHELL_WINDOWCREATED, getWindowHandle(), 0); | 
|---|
| 843 |  | 
|---|
| 844 | SetLastError(0); | 
|---|
| 845 | return TRUE; | 
|---|
| 846 | } | 
|---|
| 847 | } | 
|---|
| 848 | dprintf(("Window creation FAILED (NCCREATE cancelled creation)")); | 
|---|
| 849 | SetLastError(ERROR_OUTOFMEMORY); //TODO: Better error | 
|---|
| 850 | end: | 
|---|
| 851 | return FALSE; | 
|---|
| 852 | } | 
|---|
| 853 | //****************************************************************************** | 
|---|
| 854 | //****************************************************************************** | 
|---|
| 855 | ULONG Win32BaseWindow::MsgQuit() | 
|---|
| 856 | { | 
|---|
| 857 | return SendInternalMessageA(WM_QUIT, 0, 0); | 
|---|
| 858 | } | 
|---|
| 859 | //****************************************************************************** | 
|---|
| 860 | //****************************************************************************** | 
|---|
| 861 | ULONG Win32BaseWindow::MsgClose() | 
|---|
| 862 | { | 
|---|
| 863 | return SendInternalMessageA(WM_CLOSE,0,0); | 
|---|
| 864 | } | 
|---|
| 865 | //****************************************************************************** | 
|---|
| 866 | //****************************************************************************** | 
|---|
| 867 | ULONG Win32BaseWindow::MsgDestroy() | 
|---|
| 868 | { | 
|---|
| 869 | ULONG rc; | 
|---|
| 870 | Win32BaseWindow *child; | 
|---|
| 871 | HWND hwnd = getWindowHandle(); | 
|---|
| 872 |  | 
|---|
| 873 | state = STATE_DESTROYED; | 
|---|
| 874 |  | 
|---|
| 875 | if(fDestroyWindowCalled == FALSE) | 
|---|
| 876 | {//this window was destroyed because DestroyWindow was called for it's parent | 
|---|
| 877 | //so: send a WM_PARENTNOTIFY now as that hasn't happened yet | 
|---|
| 878 | if((getStyle() & WS_CHILD) && !(getExStyle() & WS_EX_NOPARENTNOTIFY)) | 
|---|
| 879 | { | 
|---|
| 880 | if(getParent() && getParent()->IsWindowDestroyed() == FALSE) | 
|---|
| 881 | { | 
|---|
| 882 | /* Notify the parent window only */ | 
|---|
| 883 | getParent()->SendMessageA(WM_PARENTNOTIFY, MAKEWPARAM(WM_DESTROY, getWindowId()), (LPARAM)getWindowHandle()); | 
|---|
| 884 | } | 
|---|
| 885 | ////            else    DebugInt3(); | 
|---|
| 886 | } | 
|---|
| 887 | } | 
|---|
| 888 | SendInternalMessageA(WM_DESTROY, 0, 0); | 
|---|
| 889 | if(::IsWindow(hwnd) == FALSE) { | 
|---|
| 890 | //object already destroyed, so return immediately | 
|---|
| 891 | return 1; | 
|---|
| 892 | } | 
|---|
| 893 | SendInternalMessageA(WM_NCDESTROY, 0, 0); | 
|---|
| 894 |  | 
|---|
| 895 | TIMER_KillTimerFromWindow(getWindowHandle()); | 
|---|
| 896 |  | 
|---|
| 897 | if(getRefCount() == 0 && getFirstChild() == NULL && state == STATE_CREATED) { | 
|---|
| 898 | delete this; | 
|---|
| 899 | } | 
|---|
| 900 | else { | 
|---|
| 901 | //make sure no message can ever arrive for this window again (PM or from other win32 windows) | 
|---|
| 902 | dprintf(("Mark window %x (%x) as deleted", getWindowHandle(), this)); | 
|---|
| 903 | markDeleted(); | 
|---|
| 904 | OSLibWinSetWindowULong(OS2Hwnd, OFFSET_WIN32WNDPTR, 0); | 
|---|
| 905 | OSLibWinSetWindowULong(OS2Hwnd, OFFSET_WIN32PM_MAGIC, 0); | 
|---|
| 906 | if(Win32Hwnd) { | 
|---|
| 907 | HwFreeWindowHandle(Win32Hwnd); | 
|---|
| 908 | Win32Hwnd = 0; | 
|---|
| 909 | } | 
|---|
| 910 | } | 
|---|
| 911 | return 1; | 
|---|
| 912 | } | 
|---|
| 913 | //****************************************************************************** | 
|---|
| 914 | //****************************************************************************** | 
|---|
| 915 | ULONG Win32BaseWindow::MsgEnable(BOOL fEnable) | 
|---|
| 916 | { | 
|---|
| 917 | if(fEnable) { | 
|---|
| 918 | dwStyle &= ~WS_DISABLED; | 
|---|
| 919 | } | 
|---|
| 920 | else dwStyle |= WS_DISABLED; | 
|---|
| 921 |  | 
|---|
| 922 | return SendInternalMessageA(WM_ENABLE, fEnable, 0); | 
|---|
| 923 | } | 
|---|
| 924 | //****************************************************************************** | 
|---|
| 925 | //TODO: SW_PARENTCLOSING/OPENING flag (lParam) | 
|---|
| 926 | //****************************************************************************** | 
|---|
| 927 | ULONG Win32BaseWindow::MsgShow(BOOL fShow) | 
|---|
| 928 | { | 
|---|
| 929 | if(!CanReceiveSizeMsgs() || fDestroyWindowCalled) { | 
|---|
| 930 | return 1; | 
|---|
| 931 | } | 
|---|
| 932 |  | 
|---|
| 933 | if(fShow) { | 
|---|
| 934 | setStyle(getStyle() | WS_VISIBLE); | 
|---|
| 935 | if(getStyle() & WS_MINIMIZE) { | 
|---|
| 936 | return ShowWindow(SW_RESTORE); | 
|---|
| 937 | } | 
|---|
| 938 | } | 
|---|
| 939 | else setStyle(getStyle() & ~WS_VISIBLE); | 
|---|
| 940 |  | 
|---|
| 941 | //already sent from ShowWindow | 
|---|
| 942 | ////    return SendInternalMessageA(WM_SHOWWINDOW, fShow, 0); | 
|---|
| 943 | return 0; | 
|---|
| 944 | } | 
|---|
| 945 | //****************************************************************************** | 
|---|
| 946 | //****************************************************************************** | 
|---|
| 947 | ULONG Win32BaseWindow::MsgPosChanging(LPARAM lp) | 
|---|
| 948 | { | 
|---|
| 949 | //SvL: Notes crashes when switching views (calls DestroyWindow -> PM sends | 
|---|
| 950 | //     a WM_WINDOWPOSCHANGED msg -> crash) | 
|---|
| 951 | if(!CanReceiveSizeMsgs() || fDestroyWindowCalled) | 
|---|
| 952 | return 0; | 
|---|
| 953 |  | 
|---|
| 954 | return SendInternalMessageA(WM_WINDOWPOSCHANGING, 0, lp); | 
|---|
| 955 | } | 
|---|
| 956 | //****************************************************************************** | 
|---|
| 957 | //****************************************************************************** | 
|---|
| 958 | ULONG Win32BaseWindow::MsgPosChanged(LPARAM lp) | 
|---|
| 959 | { | 
|---|
| 960 | //SvL: Notes crashes when switching views (calls DestroyWindow -> PM sends | 
|---|
| 961 | //     a WM_WINDOWPOSCHANGED msg -> crash) | 
|---|
| 962 | if(!CanReceiveSizeMsgs() || fDestroyWindowCalled) | 
|---|
| 963 | return 1; | 
|---|
| 964 |  | 
|---|
| 965 | return SendInternalMessageA(WM_WINDOWPOSCHANGED, 0, lp); | 
|---|
| 966 | } | 
|---|
| 967 | //****************************************************************************** | 
|---|
| 968 | //****************************************************************************** | 
|---|
| 969 | ULONG Win32BaseWindow::MsgScroll(ULONG msg, ULONG scrollCode, ULONG scrollPos) | 
|---|
| 970 | { | 
|---|
| 971 | //According to the SDK docs, the scrollbar handle (lParam) is 0 when the standard | 
|---|
| 972 | //window scrollbars send these messages | 
|---|
| 973 | return SendInternalMessageA(msg, MAKELONG(scrollCode, scrollPos), 0); | 
|---|
| 974 | } | 
|---|
| 975 | //****************************************************************************** | 
|---|
| 976 | //****************************************************************************** | 
|---|
| 977 | ULONG Win32BaseWindow::MsgActivate(BOOL fActivate, BOOL fMinimized, HWND hwnd, HWND hwndOS2Win) | 
|---|
| 978 | { | 
|---|
| 979 | ULONG rc, procidhwnd = -1, threadidhwnd = 0; | 
|---|
| 980 |  | 
|---|
| 981 | //SvL: Don't send WM_(NC)ACTIVATE messages when the window is being destroyed | 
|---|
| 982 | if(fDestroyWindowCalled) { | 
|---|
| 983 | return 0; | 
|---|
| 984 | } | 
|---|
| 985 |  | 
|---|
| 986 | //According to SDK docs, if app returns FALSE & window is being deactivated, | 
|---|
| 987 | //default processing is cancelled | 
|---|
| 988 | //TODO: According to Wine we should proceed anyway if window is sysmodal | 
|---|
| 989 | if(SendInternalMessageA(WM_NCACTIVATE, fActivate, 0) == FALSE && !fActivate) | 
|---|
| 990 | { | 
|---|
| 991 | dprintf(("WARNING: WM_NCACTIVATE return code = FALSE -> cancel processing")); | 
|---|
| 992 | return 0; | 
|---|
| 993 | } | 
|---|
| 994 | /* child windows get a WM_CHILDACTIVATE message */ | 
|---|
| 995 | if((getStyle() & (WS_CHILD | WS_POPUP)) == WS_CHILD ) | 
|---|
| 996 | { | 
|---|
| 997 | if(fActivate) {//WM_CHILDACTIVE is for activation only | 
|---|
| 998 | SendInternalMessageA(WM_CHILDACTIVATE, 0, 0L); | 
|---|
| 999 | } | 
|---|
| 1000 | return 0; | 
|---|
| 1001 | } | 
|---|
| 1002 |  | 
|---|
| 1003 | rc = SendInternalMessageA(WM_ACTIVATE, MAKELONG((fActivate) ? WA_ACTIVE : WA_INACTIVE, fMinimized), hwnd); | 
|---|
| 1004 |  | 
|---|
| 1005 | if(hwndOS2Win) { | 
|---|
| 1006 | threadidhwnd = O32_GetWindowThreadProcessId(hwndOS2Win, &procidhwnd); | 
|---|
| 1007 | } | 
|---|
| 1008 |  | 
|---|
| 1009 | if(fActivate) { | 
|---|
| 1010 | SendInternalMessageA(WM_ACTIVATEAPP, 1, dwThreadId);    //activate; specify window thread id | 
|---|
| 1011 | } | 
|---|
| 1012 | else SendInternalMessageA(WM_ACTIVATEAPP, 0, threadidhwnd);  //deactivate; specify thread id of other process | 
|---|
| 1013 | return rc; | 
|---|
| 1014 | } | 
|---|
| 1015 | //****************************************************************************** | 
|---|
| 1016 | //****************************************************************************** | 
|---|
| 1017 | ULONG Win32BaseWindow::MsgChildActivate(BOOL fActivate) | 
|---|
| 1018 | { | 
|---|
| 1019 | //SvL: Don't send WM_(NC)ACTIVATE messages when the window is being destroyed | 
|---|
| 1020 | if(fDestroyWindowCalled) { | 
|---|
| 1021 | return 0; | 
|---|
| 1022 | } | 
|---|
| 1023 |  | 
|---|
| 1024 | //According to SDK docs, if app returns FALSE & window is being deactivated, | 
|---|
| 1025 | //default processing is cancelled | 
|---|
| 1026 | //TODO: According to Wine we should proceed anyway if window is sysmodal | 
|---|
| 1027 | if(SendInternalMessageA(WM_NCACTIVATE, fActivate, 0) == FALSE && !fActivate) | 
|---|
| 1028 | { | 
|---|
| 1029 | dprintf(("WARNING: WM_NCACTIVATE return code = FALSE -> cancel processing")); | 
|---|
| 1030 | return 0; | 
|---|
| 1031 | } | 
|---|
| 1032 | /* child windows get a WM_CHILDACTIVATE message */ | 
|---|
| 1033 | if((getStyle() & (WS_CHILD | WS_POPUP)) == WS_CHILD ) | 
|---|
| 1034 | { | 
|---|
| 1035 | if(fActivate) {//WM_CHILDACTIVE is for activation only | 
|---|
| 1036 | SendInternalMessageA(WM_CHILDACTIVATE, 0, 0L); | 
|---|
| 1037 | } | 
|---|
| 1038 | return 0; | 
|---|
| 1039 | } | 
|---|
| 1040 | DebugInt3(); | 
|---|
| 1041 | return 0; | 
|---|
| 1042 | } | 
|---|
| 1043 | //****************************************************************************** | 
|---|
| 1044 | //****************************************************************************** | 
|---|
| 1045 | ULONG Win32BaseWindow::DispatchMsgA(MSG *msg) | 
|---|
| 1046 | { | 
|---|
| 1047 | return SendInternalMessageA(msg->message, msg->wParam, msg->lParam); | 
|---|
| 1048 | } | 
|---|
| 1049 | //****************************************************************************** | 
|---|
| 1050 | //****************************************************************************** | 
|---|
| 1051 | ULONG Win32BaseWindow::DispatchMsgW(MSG *msg) | 
|---|
| 1052 | { | 
|---|
| 1053 | return SendInternalMessageW(msg->message, msg->wParam, msg->lParam); | 
|---|
| 1054 | } | 
|---|
| 1055 | //****************************************************************************** | 
|---|
| 1056 | //****************************************************************************** | 
|---|
| 1057 | ULONG Win32BaseWindow::MsgSetFocus(HWND hwnd) | 
|---|
| 1058 | { | 
|---|
| 1059 | //SvL: Don't send WM_(NC)ACTIVATE messages when the window is being destroyed | 
|---|
| 1060 | if(fDestroyWindowCalled) { | 
|---|
| 1061 | return 0; | 
|---|
| 1062 | } | 
|---|
| 1063 |  | 
|---|
| 1064 | return  SendInternalMessageA(WM_SETFOCUS, hwnd, 0); | 
|---|
| 1065 | } | 
|---|
| 1066 | //****************************************************************************** | 
|---|
| 1067 | //****************************************************************************** | 
|---|
| 1068 | ULONG Win32BaseWindow::MsgKillFocus(HWND hwnd) | 
|---|
| 1069 | { | 
|---|
| 1070 | //SvL: Don't send WM_(NC)ACTIVATE messages when the window is being destroyed | 
|---|
| 1071 | if(fDestroyWindowCalled) { | 
|---|
| 1072 | return 0; | 
|---|
| 1073 | } | 
|---|
| 1074 | return  SendInternalMessageA(WM_KILLFOCUS, hwnd, 0); | 
|---|
| 1075 | } | 
|---|
| 1076 | //****************************************************************************** | 
|---|
| 1077 | //****************************************************************************** | 
|---|
| 1078 | ULONG Win32BaseWindow::MsgButton(MSG *msg) | 
|---|
| 1079 | { | 
|---|
| 1080 | BOOL  fClick = FALSE; | 
|---|
| 1081 |  | 
|---|
| 1082 | //    dprintf(("MsgButton at (%d,%d)", msg->pt.x, msg->pt.y)); | 
|---|
| 1083 | switch(msg->message) { | 
|---|
| 1084 | case WM_LBUTTONDBLCLK: | 
|---|
| 1085 | case WM_RBUTTONDBLCLK: | 
|---|
| 1086 | case WM_MBUTTONDBLCLK: | 
|---|
| 1087 | if (!(windowClass && windowClass->getClassLongA(GCL_STYLE) & CS_DBLCLKS)) | 
|---|
| 1088 | { | 
|---|
| 1089 | msg->message = msg->message - (WM_LBUTTONDBLCLK - WM_LBUTTONDOWN); //dblclick -> down | 
|---|
| 1090 | MsgButton(msg); | 
|---|
| 1091 | msg->message++; //button-up | 
|---|
| 1092 | return MsgButton(msg); | 
|---|
| 1093 | } | 
|---|
| 1094 | break; | 
|---|
| 1095 | case WM_NCLBUTTONDBLCLK: | 
|---|
| 1096 | case WM_NCRBUTTONDBLCLK: | 
|---|
| 1097 | case WM_NCMBUTTONDBLCLK: | 
|---|
| 1098 | //Docs say CS_DBLCLKS style doesn't matter for non-client double clicks | 
|---|
| 1099 | fClick = TRUE; | 
|---|
| 1100 | break; | 
|---|
| 1101 |  | 
|---|
| 1102 | case WM_LBUTTONDOWN: | 
|---|
| 1103 | case WM_RBUTTONDOWN: | 
|---|
| 1104 | case WM_MBUTTONDOWN: | 
|---|
| 1105 | case WM_NCLBUTTONDOWN: | 
|---|
| 1106 | case WM_NCRBUTTONDOWN: | 
|---|
| 1107 | case WM_NCMBUTTONDOWN: | 
|---|
| 1108 | fClick = TRUE; | 
|---|
| 1109 | break; | 
|---|
| 1110 | } | 
|---|
| 1111 |  | 
|---|
| 1112 | if(fClick) | 
|---|
| 1113 | { | 
|---|
| 1114 | HWND hwndTop; | 
|---|
| 1115 |  | 
|---|
| 1116 | /* Activate the window if needed */ | 
|---|
| 1117 | hwndTop = GetTopParent(); | 
|---|
| 1118 |  | 
|---|
| 1119 | HWND hwndActive = GetActiveWindow(); | 
|---|
| 1120 | if (hwndTop && (getWindowHandle() != hwndActive)) | 
|---|
| 1121 | { | 
|---|
| 1122 | LONG ret = SendInternalMessageA(WM_MOUSEACTIVATE, hwndTop, | 
|---|
| 1123 | MAKELONG( lastHitTestVal, msg->message) ); | 
|---|
| 1124 |  | 
|---|
| 1125 | dprintf2(("WM_MOUSEACTIVATE returned %d", ret)); | 
|---|
| 1126 | #if 0 | 
|---|
| 1127 | if ((ret == MA_ACTIVATEANDEAT) || (ret == MA_NOACTIVATEANDEAT)) | 
|---|
| 1128 | eatMsg = TRUE; | 
|---|
| 1129 | #endif | 
|---|
| 1130 | //SvL: 0 is not documented, but experiments in NT4 show that | 
|---|
| 1131 | //     the window will get activated when it returns this. | 
|---|
| 1132 | //     (FreeCell is an example) | 
|---|
| 1133 | if(((ret == MA_ACTIVATE) || (ret == MA_ACTIVATEANDEAT) || (ret == 0)) | 
|---|
| 1134 | && (hwndTop != GetForegroundWindow()) ) | 
|---|
| 1135 | { | 
|---|
| 1136 | Win32BaseWindow *win32top = Win32BaseWindow::GetWindowFromHandle(hwndTop); | 
|---|
| 1137 |  | 
|---|
| 1138 | //SvL: Calling OSLibSetActiveWindow(hwndTop); causes focus problems | 
|---|
| 1139 | if (win32top) { | 
|---|
| 1140 | OSLibWinSetFocus(win32top->getOS2FrameWindowHandle()); | 
|---|
| 1141 | RELEASE_WNDOBJ(win32top); | 
|---|
| 1142 | } | 
|---|
| 1143 | } | 
|---|
| 1144 | } | 
|---|
| 1145 | } | 
|---|
| 1146 |  | 
|---|
| 1147 | SendInternalMessageA(WM_SETCURSOR, getWindowHandle(), MAKELONG(lastHitTestVal, msg->message)); | 
|---|
| 1148 |  | 
|---|
| 1149 | return  SendInternalMessageA(msg->message, msg->wParam, msg->lParam); | 
|---|
| 1150 | } | 
|---|
| 1151 | //****************************************************************************** | 
|---|
| 1152 | //****************************************************************************** | 
|---|
| 1153 | ULONG Win32BaseWindow::MsgPaint(ULONG tmp, ULONG select) | 
|---|
| 1154 | { | 
|---|
| 1155 | if (select && IsWindowIconic()) | 
|---|
| 1156 | return SendInternalMessageA(WM_PAINTICON, 1, 0); | 
|---|
| 1157 | else | 
|---|
| 1158 | return SendInternalMessageA(WM_PAINT, 0, 0); | 
|---|
| 1159 | } | 
|---|
| 1160 | //****************************************************************************** | 
|---|
| 1161 | //TODO: Is the clipper region of the window DC equal to the invalidated rectangle? | 
|---|
| 1162 | //      (or are we simply erasing too much here) | 
|---|
| 1163 | //****************************************************************************** | 
|---|
| 1164 | ULONG Win32BaseWindow::MsgEraseBackGround(HDC hdc) | 
|---|
| 1165 | { | 
|---|
| 1166 | ULONG rc; | 
|---|
| 1167 | HDC   hdcErase = hdc; | 
|---|
| 1168 |  | 
|---|
| 1169 | if (hdcErase == 0) | 
|---|
| 1170 | hdcErase = GetDC(getWindowHandle()); | 
|---|
| 1171 |  | 
|---|
| 1172 | if(IsWindowIconic()) | 
|---|
| 1173 | rc = SendInternalMessageA(WM_ICONERASEBKGND, hdcErase, 0); | 
|---|
| 1174 | else | 
|---|
| 1175 | rc = SendInternalMessageA(WM_ERASEBKGND, hdcErase, 0); | 
|---|
| 1176 | if (hdc == 0) | 
|---|
| 1177 | ReleaseDC(getWindowHandle(), hdcErase); | 
|---|
| 1178 | return (rc); | 
|---|
| 1179 | } | 
|---|
| 1180 | //****************************************************************************** | 
|---|
| 1181 | //****************************************************************************** | 
|---|
| 1182 | ULONG Win32BaseWindow::MsgMouseMove(MSG *msg) | 
|---|
| 1183 | { | 
|---|
| 1184 | //TODO: hiword should be 0 if window enters menu mode (SDK docs) | 
|---|
| 1185 | SendInternalMessageA(WM_SETCURSOR, Win32Hwnd, MAKELONG(lastHitTestVal, msg->message)); | 
|---|
| 1186 |  | 
|---|
| 1187 | //translated message == WM_(NC)MOUSEMOVE | 
|---|
| 1188 | return SendInternalMessageA(msg->message, msg->wParam, msg->lParam); | 
|---|
| 1189 | } | 
|---|
| 1190 | //****************************************************************************** | 
|---|
| 1191 | //****************************************************************************** | 
|---|
| 1192 | ULONG Win32BaseWindow::MsgChar(MSG *msg) | 
|---|
| 1193 | { | 
|---|
| 1194 | return DispatchMsgA(msg); | 
|---|
| 1195 | } | 
|---|
| 1196 | //****************************************************************************** | 
|---|
| 1197 | //TODO: Should use update region, not rectangle | 
|---|
| 1198 | //****************************************************************************** | 
|---|
| 1199 | ULONG Win32BaseWindow::MsgNCPaint(PRECT pUpdateRect) | 
|---|
| 1200 | { | 
|---|
| 1201 | HRGN hrgn; | 
|---|
| 1202 | ULONG rc; | 
|---|
| 1203 | RECT client = rectClient; | 
|---|
| 1204 |  | 
|---|
| 1205 | if ((pUpdateRect->left >= client.left) && (pUpdateRect->left < client.right) && | 
|---|
| 1206 | (pUpdateRect->right >= client.left) && (pUpdateRect->right < client.right) && | 
|---|
| 1207 | (pUpdateRect->top  >= client.top) && (pUpdateRect->top < client.bottom) && | 
|---|
| 1208 | (pUpdateRect->bottom >= client.top) && (pUpdateRect->bottom < client.bottom)) | 
|---|
| 1209 | { | 
|---|
| 1210 | return 0; | 
|---|
| 1211 | } | 
|---|
| 1212 |  | 
|---|
| 1213 | dprintf(("MsgNCPaint (%d,%d)(%d,%d)", pUpdateRect->left, pUpdateRect->top, pUpdateRect->right, pUpdateRect->bottom)); | 
|---|
| 1214 | hrgn = CreateRectRgnIndirect(pUpdateRect); | 
|---|
| 1215 |  | 
|---|
| 1216 | rc = SendInternalMessageA(WM_NCPAINT, hrgn, 0); | 
|---|
| 1217 |  | 
|---|
| 1218 | DeleteObject(hrgn); | 
|---|
| 1219 |  | 
|---|
| 1220 | return rc; | 
|---|
| 1221 | } | 
|---|
| 1222 | //****************************************************************************** | 
|---|
| 1223 | //Called when either the frame's size or position has changed (lpWndPos != NULL) | 
|---|
| 1224 | //or when the frame layout has changed (i.e. scrollbars added/removed) (lpWndPos == NULL) | 
|---|
| 1225 | //****************************************************************************** | 
|---|
| 1226 | ULONG Win32BaseWindow::MsgFormatFrame(WINDOWPOS *lpWndPos) | 
|---|
| 1227 | { | 
|---|
| 1228 | RECT oldWindowRect = rectWindow, client = rectClient, newWindowRect; | 
|---|
| 1229 | RECT newClientRect; | 
|---|
| 1230 | WINDOWPOS wndPos; | 
|---|
| 1231 | ULONG rc; | 
|---|
| 1232 |  | 
|---|
| 1233 | if(lpWndPos) | 
|---|
| 1234 | { | 
|---|
| 1235 | //set new window rectangle | 
|---|
| 1236 | setWindowRect(lpWndPos->x, lpWndPos->y, lpWndPos->x+lpWndPos->cx, | 
|---|
| 1237 | lpWndPos->y+lpWndPos->cy); | 
|---|
| 1238 | newWindowRect = rectWindow; | 
|---|
| 1239 | } | 
|---|
| 1240 | else { | 
|---|
| 1241 | wndPos.hwnd  = getWindowHandle(); | 
|---|
| 1242 | wndPos.hwndInsertAfter = 0; | 
|---|
| 1243 | newWindowRect= rectWindow; | 
|---|
| 1244 | wndPos.x     = newWindowRect.left; | 
|---|
| 1245 | wndPos.y     = newWindowRect.top; | 
|---|
| 1246 | wndPos.cx    = newWindowRect.right - newWindowRect.left; | 
|---|
| 1247 | wndPos.cy    = newWindowRect.bottom - newWindowRect.top; | 
|---|
| 1248 | wndPos.flags = SWP_FRAMECHANGED; | 
|---|
| 1249 | lpWndPos     = &wndPos; | 
|---|
| 1250 | } | 
|---|
| 1251 |  | 
|---|
| 1252 | newClientRect = rectClient; | 
|---|
| 1253 | rc = SendNCCalcSize(TRUE, &newWindowRect,  &oldWindowRect, &client, lpWndPos, &newClientRect); | 
|---|
| 1254 | rectClient = newClientRect; //must update rectClient here | 
|---|
| 1255 |  | 
|---|
| 1256 | dprintf(("MsgFormatFrame: old client rect (%d,%d)(%d,%d), new client (%d,%d)(%d,%d)", client.left, client.top, client.right, client.bottom, rectClient.left, rectClient.top, rectClient.right, rectClient.bottom)); | 
|---|
| 1257 | dprintf(("MsgFormatFrame: old window rect (%d,%d)(%d,%d), new window (%d,%d)(%d,%d)", oldWindowRect.left, oldWindowRect.top, oldWindowRect.right, oldWindowRect.bottom, rectWindow.left, rectWindow.top, rectWindow.right, rectWindow.bottom)); | 
|---|
| 1258 |  | 
|---|
| 1259 | if(!CanReceiveSizeMsgs() || !EqualRect(&client, &rectClient)) { | 
|---|
| 1260 | OSLibWinSetClientPos(getOS2WindowHandle(), rectClient.left, rectClient.top, getClientWidth(), getClientHeight(), getWindowHeight()); | 
|---|
| 1261 | } | 
|---|
| 1262 |  | 
|---|
| 1263 | #if 1 | 
|---|
| 1264 | //this doesn't always work | 
|---|
| 1265 | //  if(CanReceiveSizeMsgs() && (client.left != rectClient.left || client.top != rectClient.top)) | 
|---|
| 1266 | if(CanReceiveSizeMsgs() && ((oldWindowRect.right - oldWindowRect.left < rectClient.left | 
|---|
| 1267 | || oldWindowRect.bottom - oldWindowRect.top < rectClient.top) || | 
|---|
| 1268 | (EqualRect(&oldWindowRect, &rectWindow) && (client.left != rectClient.left || client.top != rectClient.top)))) | 
|---|
| 1269 | { | 
|---|
| 1270 | Win32BaseWindow *child = (Win32BaseWindow *)getFirstChild(); | 
|---|
| 1271 |  | 
|---|
| 1272 | //client rectangle has moved -> inform children | 
|---|
| 1273 | dprintf(("MsgFormatFrame -> client rectangle has changed, move children")); | 
|---|
| 1274 | while(child) { | 
|---|
| 1275 | ::SetWindowPos(child->getWindowHandle(), | 
|---|
| 1276 | HWND_TOP, child->getWindowRect()->left, | 
|---|
| 1277 | child->getWindowRect()->top, 0, 0, | 
|---|
| 1278 | SWP_NOACTIVATE|SWP_NOSIZE|SWP_NOZORDER); | 
|---|
| 1279 | child = (Win32BaseWindow *)child->getNextChild(); | 
|---|
| 1280 | } | 
|---|
| 1281 | } | 
|---|
| 1282 | #endif | 
|---|
| 1283 | if(fOS2Look && ((dwStyle & WS_CAPTION) == WS_CAPTION)) | 
|---|
| 1284 | { | 
|---|
| 1285 | RECT rect = {0}; | 
|---|
| 1286 | int  height  = getWindowHeight(); | 
|---|
| 1287 | RECTLOS2 rectOS2; | 
|---|
| 1288 |  | 
|---|
| 1289 | AdjustRectOuter(&rect, FALSE); | 
|---|
| 1290 |  | 
|---|
| 1291 | rect.left   = -rect.left; | 
|---|
| 1292 | rect.top    = rect.bottom - rect.top; | 
|---|
| 1293 | rect.right  = rectWindow.right - rectWindow.left - rect.right; | 
|---|
| 1294 |  | 
|---|
| 1295 | rectOS2.xLeft   = rect.left; | 
|---|
| 1296 | rectOS2.xRight  = rect.right; | 
|---|
| 1297 | rectOS2.yBottom = height - rect.top; | 
|---|
| 1298 | rectOS2.yTop    = height - rect.bottom; | 
|---|
| 1299 | OSLibWinPositionFrameControls(getOS2FrameWindowHandle(), &rectOS2, dwStyle, dwExStyle, IconForWindow(ICON_SMALL)); | 
|---|
| 1300 | } | 
|---|
| 1301 | return rc; | 
|---|
| 1302 | } | 
|---|
| 1303 | //****************************************************************************** | 
|---|
| 1304 | //****************************************************************************** | 
|---|
| 1305 | ULONG Win32BaseWindow::MsgSetText(LPSTR lpsz, LONG cch) | 
|---|
| 1306 | { | 
|---|
| 1307 | return SendInternalMessageA(WM_SETTEXT, 0, (LPARAM)lpsz); | 
|---|
| 1308 | } | 
|---|
| 1309 | //****************************************************************************** | 
|---|
| 1310 | //****************************************************************************** | 
|---|
| 1311 | ULONG Win32BaseWindow::MsgGetTextLength() | 
|---|
| 1312 | { | 
|---|
| 1313 | return SendInternalMessageA(WM_GETTEXTLENGTH, 0, 0); | 
|---|
| 1314 | } | 
|---|
| 1315 | //****************************************************************************** | 
|---|
| 1316 | //****************************************************************************** | 
|---|
| 1317 | void Win32BaseWindow::MsgGetText(char *wndtext, ULONG textlength) | 
|---|
| 1318 | { | 
|---|
| 1319 | SendInternalMessageA(WM_GETTEXT, textlength, (LPARAM)wndtext); | 
|---|
| 1320 | } | 
|---|
| 1321 | //****************************************************************************** | 
|---|
| 1322 | //****************************************************************************** | 
|---|
| 1323 | BOOL Win32BaseWindow::isMDIClient() | 
|---|
| 1324 | { | 
|---|
| 1325 | return FALSE; | 
|---|
| 1326 | } | 
|---|
| 1327 | //****************************************************************************** | 
|---|
| 1328 | //****************************************************************************** | 
|---|
| 1329 | BOOL Win32BaseWindow::isMDIChild() | 
|---|
| 1330 | { | 
|---|
| 1331 | return FALSE; | 
|---|
| 1332 | } | 
|---|
| 1333 | //****************************************************************************** | 
|---|
| 1334 | //TODO: Not complete | 
|---|
| 1335 | //****************************************************************************** | 
|---|
| 1336 | BOOL Win32BaseWindow::isFrameWindow() | 
|---|
| 1337 | { | 
|---|
| 1338 | if(getParent() == NULL) | 
|---|
| 1339 | return TRUE; | 
|---|
| 1340 |  | 
|---|
| 1341 | return FALSE; | 
|---|
| 1342 | } | 
|---|
| 1343 | //****************************************************************************** | 
|---|
| 1344 | //****************************************************************************** | 
|---|
| 1345 | BOOL Win32BaseWindow::isDesktopWindow() | 
|---|
| 1346 | { | 
|---|
| 1347 | return FALSE; | 
|---|
| 1348 | } | 
|---|
| 1349 | //****************************************************************************** | 
|---|
| 1350 | //****************************************************************************** | 
|---|
| 1351 | BOOL Win32BaseWindow::IsWindowIconic() | 
|---|
| 1352 | { | 
|---|
| 1353 | return ((getStyle() & WS_MINIMIZE) && windowClass->getIcon()); | 
|---|
| 1354 | } | 
|---|
| 1355 | //****************************************************************************** | 
|---|
| 1356 | //****************************************************************************** | 
|---|
| 1357 | SCROLLBAR_INFO *Win32BaseWindow::getScrollInfo(int nBar) | 
|---|
| 1358 | { | 
|---|
| 1359 | switch(nBar) | 
|---|
| 1360 | { | 
|---|
| 1361 | case SB_HORZ: | 
|---|
| 1362 | if (!horzScrollInfo) | 
|---|
| 1363 | { | 
|---|
| 1364 | horzScrollInfo = (SCROLLBAR_INFO*)malloc(sizeof(SCROLLBAR_INFO)); | 
|---|
| 1365 | if (!horzScrollInfo) break; | 
|---|
| 1366 | horzScrollInfo->MinVal = horzScrollInfo->CurVal = horzScrollInfo->Page = 0; | 
|---|
| 1367 | horzScrollInfo->MaxVal = 100; | 
|---|
| 1368 | horzScrollInfo->flags  = ESB_ENABLE_BOTH; | 
|---|
| 1369 | } | 
|---|
| 1370 | return horzScrollInfo; | 
|---|
| 1371 |  | 
|---|
| 1372 | case SB_VERT: | 
|---|
| 1373 | if (!vertScrollInfo) | 
|---|
| 1374 | { | 
|---|
| 1375 | vertScrollInfo = (SCROLLBAR_INFO*)malloc(sizeof(SCROLLBAR_INFO)); | 
|---|
| 1376 | if (!vertScrollInfo) break; | 
|---|
| 1377 | vertScrollInfo->MinVal = vertScrollInfo->CurVal = vertScrollInfo->Page = 0; | 
|---|
| 1378 | vertScrollInfo->MaxVal = 100; | 
|---|
| 1379 | vertScrollInfo->flags  = ESB_ENABLE_BOTH; | 
|---|
| 1380 | } | 
|---|
| 1381 | return vertScrollInfo; | 
|---|
| 1382 | } | 
|---|
| 1383 |  | 
|---|
| 1384 | return NULL; | 
|---|
| 1385 | } | 
|---|
| 1386 | //****************************************************************************** | 
|---|
| 1387 | //****************************************************************************** | 
|---|
| 1388 | LRESULT Win32BaseWindow::DefWndControlColor(UINT ctlType, HDC hdc) | 
|---|
| 1389 | { | 
|---|
| 1390 | //SvL: Set background color to default button color (not window (white)) | 
|---|
| 1391 | if(ctlType == CTLCOLOR_BTN) | 
|---|
| 1392 | { | 
|---|
| 1393 | SetBkColor(hdc, GetSysColor(COLOR_BTNFACE)); | 
|---|
| 1394 | SetTextColor(hdc, GetSysColor(COLOR_WINDOWTEXT)); | 
|---|
| 1395 | return GetSysColorBrush(COLOR_BTNFACE); | 
|---|
| 1396 | } | 
|---|
| 1397 | //SvL: Set background color to default dialog color if window is dialog | 
|---|
| 1398 | if((ctlType == CTLCOLOR_DLG || ctlType == CTLCOLOR_STATIC) && IsDialog()) { | 
|---|
| 1399 | SetBkColor(hdc, GetSysColor(COLOR_BTNFACE)); | 
|---|
| 1400 | SetTextColor(hdc, GetSysColor(COLOR_WINDOWTEXT)); | 
|---|
| 1401 | return GetSysColorBrush(COLOR_BTNFACE); | 
|---|
| 1402 | } | 
|---|
| 1403 | if( ctlType == CTLCOLOR_SCROLLBAR) | 
|---|
| 1404 | { | 
|---|
| 1405 | HBRUSH hb = GetSysColorBrush(COLOR_SCROLLBAR); | 
|---|
| 1406 | COLORREF bk = GetSysColor(COLOR_3DHILIGHT); | 
|---|
| 1407 | SetTextColor( hdc, GetSysColor(COLOR_3DFACE)); | 
|---|
| 1408 | SetBkColor( hdc, bk); | 
|---|
| 1409 |  | 
|---|
| 1410 | /* if COLOR_WINDOW happens to be the same as COLOR_3DHILIGHT | 
|---|
| 1411 | * we better use 0x55aa bitmap brush to make scrollbar's background | 
|---|
| 1412 | * look different from the window background. | 
|---|
| 1413 | */ | 
|---|
| 1414 | if (bk == GetSysColor(COLOR_WINDOW)) { | 
|---|
| 1415 | return GetPattern55AABrush(); | 
|---|
| 1416 | } | 
|---|
| 1417 |  | 
|---|
| 1418 | UnrealizeObject( hb ); | 
|---|
| 1419 | return (LRESULT)hb; | 
|---|
| 1420 | } | 
|---|
| 1421 |  | 
|---|
| 1422 | SetTextColor( hdc, GetSysColor(COLOR_WINDOWTEXT)); | 
|---|
| 1423 |  | 
|---|
| 1424 | if ((ctlType == CTLCOLOR_EDIT) || (ctlType == CTLCOLOR_LISTBOX)) | 
|---|
| 1425 | { | 
|---|
| 1426 | SetBkColor( hdc, GetSysColor(COLOR_WINDOW) ); | 
|---|
| 1427 | } | 
|---|
| 1428 | else | 
|---|
| 1429 | { | 
|---|
| 1430 | SetBkColor( hdc, GetSysColor(COLOR_3DFACE) ); | 
|---|
| 1431 | return (LRESULT)GetSysColorBrush(COLOR_3DFACE); | 
|---|
| 1432 | } | 
|---|
| 1433 | return (LRESULT)GetSysColorBrush(COLOR_WINDOW); | 
|---|
| 1434 | } | 
|---|
| 1435 | //****************************************************************************** | 
|---|
| 1436 | //****************************************************************************** | 
|---|
| 1437 | LRESULT Win32BaseWindow::DefWndPrint(HDC hdc,ULONG uFlags) | 
|---|
| 1438 | { | 
|---|
| 1439 | /* | 
|---|
| 1440 | * Visibility flag. | 
|---|
| 1441 | */ | 
|---|
| 1442 | if ( (uFlags & PRF_CHECKVISIBLE) && | 
|---|
| 1443 | !IsWindowVisible(getWindowHandle()) ) | 
|---|
| 1444 | return 0; | 
|---|
| 1445 |  | 
|---|
| 1446 | /* | 
|---|
| 1447 | * Unimplemented flags. | 
|---|
| 1448 | */ | 
|---|
| 1449 | if ( (uFlags & PRF_CHILDREN) || | 
|---|
| 1450 | (uFlags & PRF_OWNED)    || | 
|---|
| 1451 | (uFlags & PRF_NONCLIENT) ) | 
|---|
| 1452 | { | 
|---|
| 1453 | dprintf(("WM_PRINT message with unsupported flags\n")); | 
|---|
| 1454 | } | 
|---|
| 1455 |  | 
|---|
| 1456 | /* | 
|---|
| 1457 | * Background | 
|---|
| 1458 | */ | 
|---|
| 1459 | if ( uFlags & PRF_ERASEBKGND) | 
|---|
| 1460 | SendInternalMessageA(WM_ERASEBKGND, (WPARAM)hdc, 0); | 
|---|
| 1461 |  | 
|---|
| 1462 | /* | 
|---|
| 1463 | * Client area | 
|---|
| 1464 | */ | 
|---|
| 1465 | if ( uFlags & PRF_CLIENT) | 
|---|
| 1466 | SendInternalMessageA(WM_PRINTCLIENT, (WPARAM)hdc, PRF_CLIENT); | 
|---|
| 1467 |  | 
|---|
| 1468 |  | 
|---|
| 1469 | return 0; | 
|---|
| 1470 | } | 
|---|
| 1471 | //****************************************************************************** | 
|---|
| 1472 | //****************************************************************************** | 
|---|
| 1473 | LRESULT Win32BaseWindow::DefWindowProcA(UINT Msg, WPARAM wParam, LPARAM lParam) | 
|---|
| 1474 | { | 
|---|
| 1475 | switch(Msg) | 
|---|
| 1476 | { | 
|---|
| 1477 | case WM_CLOSE: | 
|---|
| 1478 | dprintf(("DefWindowProcA: WM_CLOSE %x", getWindowHandle())); | 
|---|
| 1479 | DestroyWindow(); | 
|---|
| 1480 | return 0; | 
|---|
| 1481 |  | 
|---|
| 1482 | case WM_GETTEXTLENGTH: | 
|---|
| 1483 | if(windowNameA) { | 
|---|
| 1484 | return strlen(windowNameA); | 
|---|
| 1485 | } | 
|---|
| 1486 | else { | 
|---|
| 1487 | return 0; | 
|---|
| 1488 | } | 
|---|
| 1489 |  | 
|---|
| 1490 | case WM_GETTEXT: | 
|---|
| 1491 | if (!lParam || !wParam) return 0; | 
|---|
| 1492 | if (!windowNameA) ((LPSTR)lParam)[0] = 0; | 
|---|
| 1493 | else lstrcpynA((LPSTR)lParam, windowNameA, wParam); | 
|---|
| 1494 | return min((windowNameA ? strlen(windowNameA) : 0), wParam); | 
|---|
| 1495 |  | 
|---|
| 1496 | case WM_SETTEXT: | 
|---|
| 1497 | { | 
|---|
| 1498 | LPCSTR lpsz = (LPCSTR)lParam; | 
|---|
| 1499 |  | 
|---|
| 1500 | if(windowNameA) free(windowNameA); | 
|---|
| 1501 | if(windowNameW) free(windowNameW); | 
|---|
| 1502 | if (lParam) | 
|---|
| 1503 | { | 
|---|
| 1504 | int wndNameLength = strlen(lpsz); | 
|---|
| 1505 | windowNameA = (LPSTR)_smalloc(wndNameLength+1); | 
|---|
| 1506 | strcpy(windowNameA, lpsz); | 
|---|
| 1507 | windowNameW = (LPWSTR)_smalloc((wndNameLength+1)*sizeof(WCHAR)); | 
|---|
| 1508 | lstrcpyAtoW(windowNameW, windowNameA); | 
|---|
| 1509 | } | 
|---|
| 1510 | else | 
|---|
| 1511 | { | 
|---|
| 1512 | windowNameA = NULL; | 
|---|
| 1513 | windowNameW = NULL; | 
|---|
| 1514 | } | 
|---|
| 1515 | dprintf(("WM_SETTEXT of %x to %s\n", Win32Hwnd, lParam)); | 
|---|
| 1516 | if ((dwStyle & WS_CAPTION) == WS_CAPTION) | 
|---|
| 1517 | { | 
|---|
| 1518 | HandleNCPaint((HRGN)1); | 
|---|
| 1519 | if(hTaskList) { | 
|---|
| 1520 | OSLibWinChangeTaskList(hTaskList, OS2HwndFrame, getWindowNameA(), (getStyle() & WS_VISIBLE) ? 1 : 0); | 
|---|
| 1521 | } | 
|---|
| 1522 | if(fOS2Look) { | 
|---|
| 1523 | OSLibWinSetTitleBarText(OS2HwndFrame, getWindowNameA()); | 
|---|
| 1524 | } | 
|---|
| 1525 | } | 
|---|
| 1526 |  | 
|---|
| 1527 | return TRUE; | 
|---|
| 1528 | } | 
|---|
| 1529 |  | 
|---|
| 1530 | case WM_SETREDRAW: | 
|---|
| 1531 | { | 
|---|
| 1532 | if (wParam) | 
|---|
| 1533 | { | 
|---|
| 1534 | setStyle(getStyle() | WS_VISIBLE); | 
|---|
| 1535 | dprintf(("Enable window update for %x", getWindowHandle())); | 
|---|
| 1536 | OSLibWinEnableWindowUpdate(OS2HwndFrame, OS2Hwnd, TRUE); | 
|---|
| 1537 | } | 
|---|
| 1538 | else | 
|---|
| 1539 | { | 
|---|
| 1540 | if (getStyle() & WS_VISIBLE) | 
|---|
| 1541 | { | 
|---|
| 1542 | setStyle(getStyle() & ~WS_VISIBLE); | 
|---|
| 1543 | dprintf(("Disable window update for %x", getWindowHandle())); | 
|---|
| 1544 | OSLibWinEnableWindowUpdate(OS2HwndFrame, OS2Hwnd, FALSE); | 
|---|
| 1545 | } | 
|---|
| 1546 | } | 
|---|
| 1547 | return 0; | 
|---|
| 1548 | } | 
|---|
| 1549 |  | 
|---|
| 1550 | case WM_CTLCOLORMSGBOX: | 
|---|
| 1551 | case WM_CTLCOLOREDIT: | 
|---|
| 1552 | case WM_CTLCOLORLISTBOX: | 
|---|
| 1553 | case WM_CTLCOLORBTN: | 
|---|
| 1554 | case WM_CTLCOLORDLG: | 
|---|
| 1555 | case WM_CTLCOLORSTATIC: | 
|---|
| 1556 | case WM_CTLCOLORSCROLLBAR: | 
|---|
| 1557 | return DefWndControlColor(Msg - WM_CTLCOLORMSGBOX, (HDC)wParam); | 
|---|
| 1558 |  | 
|---|
| 1559 | case WM_CTLCOLOR: | 
|---|
| 1560 | return DefWndControlColor(HIWORD(lParam), (HDC)wParam); | 
|---|
| 1561 |  | 
|---|
| 1562 | case WM_VKEYTOITEM: | 
|---|
| 1563 | case WM_CHARTOITEM: | 
|---|
| 1564 | return -1; | 
|---|
| 1565 |  | 
|---|
| 1566 | case WM_PARENTNOTIFY: | 
|---|
| 1567 | return 0; | 
|---|
| 1568 |  | 
|---|
| 1569 | case WM_MOUSEACTIVATE: | 
|---|
| 1570 | { | 
|---|
| 1571 | dprintf(("DefWndProc: WM_MOUSEACTIVATE for %x Msg %s", Win32Hwnd, GetMsgText(HIWORD(lParam)))); | 
|---|
| 1572 | if(getStyle() & WS_CHILD && !(getExStyle() & WS_EX_NOPARENTNOTIFY) ) | 
|---|
| 1573 | { | 
|---|
| 1574 | if(getParent()) { | 
|---|
| 1575 | LRESULT rc = getParent()->SendInternalMessageA(WM_MOUSEACTIVATE, wParam, lParam ); | 
|---|
| 1576 | if(rc)  return rc; | 
|---|
| 1577 | } | 
|---|
| 1578 | } | 
|---|
| 1579 | return (LOWORD(lParam) == HTCAPTION) ? MA_NOACTIVATE : MA_ACTIVATE; | 
|---|
| 1580 | } | 
|---|
| 1581 |  | 
|---|
| 1582 | case WM_ACTIVATE: | 
|---|
| 1583 | /* The default action in Windows is to set the keyboard focus to | 
|---|
| 1584 | * the window, if it's being activated and not minimized */ | 
|---|
| 1585 | if (LOWORD(wParam) != WA_INACTIVE) { | 
|---|
| 1586 | if(!(getStyle() & WS_MINIMIZE)) | 
|---|
| 1587 | SetFocus(getWindowHandle()); | 
|---|
| 1588 | } | 
|---|
| 1589 | return 0; | 
|---|
| 1590 |  | 
|---|
| 1591 | case WM_SETCURSOR: | 
|---|
| 1592 | { | 
|---|
| 1593 | dprintf(("DefWndProc: WM_SETCURSOR for %x Msg %s", Win32Hwnd, GetMsgText(HIWORD(lParam)))); | 
|---|
| 1594 | if((getStyle() & WS_CHILD)) | 
|---|
| 1595 | { | 
|---|
| 1596 | if(getParent()) { | 
|---|
| 1597 | LRESULT rc = getParent()->SendInternalMessageA(WM_SETCURSOR, wParam, lParam); | 
|---|
| 1598 | if(rc)  return rc; | 
|---|
| 1599 | } | 
|---|
| 1600 | } | 
|---|
| 1601 | if (wParam == getWindowHandle()) | 
|---|
| 1602 | { | 
|---|
| 1603 | HCURSOR hCursor; | 
|---|
| 1604 |  | 
|---|
| 1605 | switch(LOWORD(lParam)) | 
|---|
| 1606 | { | 
|---|
| 1607 | case HTCLIENT: | 
|---|
| 1608 | hCursor = windowClass ? windowClass->getCursor():LoadCursorA(0,IDC_ARROWA); | 
|---|
| 1609 | break; | 
|---|
| 1610 |  | 
|---|
| 1611 | case HTLEFT: | 
|---|
| 1612 | case HTRIGHT: | 
|---|
| 1613 | hCursor = LoadCursorA(0,IDC_SIZEWEA); | 
|---|
| 1614 | break; | 
|---|
| 1615 |  | 
|---|
| 1616 | case HTTOP: | 
|---|
| 1617 | case HTBOTTOM: | 
|---|
| 1618 | hCursor = LoadCursorA(0,IDC_SIZENSA); | 
|---|
| 1619 | break; | 
|---|
| 1620 |  | 
|---|
| 1621 | case HTTOPLEFT: | 
|---|
| 1622 | case HTBOTTOMRIGHT: | 
|---|
| 1623 | hCursor = LoadCursorA(0,IDC_SIZENWSEA); | 
|---|
| 1624 | break; | 
|---|
| 1625 |  | 
|---|
| 1626 | case HTTOPRIGHT: | 
|---|
| 1627 | case HTBOTTOMLEFT: | 
|---|
| 1628 | hCursor = LoadCursorA(0,IDC_SIZENESWA); | 
|---|
| 1629 | break; | 
|---|
| 1630 |  | 
|---|
| 1631 | default: | 
|---|
| 1632 | hCursor = LoadCursorA(0,IDC_ARROWA); | 
|---|
| 1633 | break; | 
|---|
| 1634 | } | 
|---|
| 1635 |  | 
|---|
| 1636 | if (hCursor) | 
|---|
| 1637 | { | 
|---|
| 1638 | SetCursor(hCursor); | 
|---|
| 1639 | return 1; | 
|---|
| 1640 | } | 
|---|
| 1641 | else return 0; | 
|---|
| 1642 | } | 
|---|
| 1643 | else return 0; | 
|---|
| 1644 | } | 
|---|
| 1645 |  | 
|---|
| 1646 | case WM_MOUSEMOVE: | 
|---|
| 1647 | return 0; | 
|---|
| 1648 |  | 
|---|
| 1649 | case WM_WINDOWPOSCHANGED: | 
|---|
| 1650 | { | 
|---|
| 1651 | PWINDOWPOS wpos = (PWINDOWPOS)lParam; | 
|---|
| 1652 | WPARAM     wp   = SIZE_RESTORED; | 
|---|
| 1653 |  | 
|---|
| 1654 | if (!(wpos->flags & SWP_NOMOVE) && !(wpos->flags & SWP_NOCLIENTMOVE)) | 
|---|
| 1655 | { | 
|---|
| 1656 | SendInternalMessageA(WM_MOVE, 0, MAKELONG(rectClient.left,rectClient.top)); | 
|---|
| 1657 | } | 
|---|
| 1658 | if (!(wpos->flags & SWP_NOSIZE) && !(wpos->flags & SWP_NOCLIENTSIZE)) | 
|---|
| 1659 | { | 
|---|
| 1660 | if (dwStyle & WS_MAXIMIZE) wp = SIZE_MAXIMIZED; | 
|---|
| 1661 | else | 
|---|
| 1662 | if (dwStyle & WS_MINIMIZE) wp = SIZE_MINIMIZED; | 
|---|
| 1663 |  | 
|---|
| 1664 | SendInternalMessageA(WM_SIZE, wp, MAKELONG(rectClient.right  - rectClient.left, | 
|---|
| 1665 | rectClient.bottom - rectClient.top)); | 
|---|
| 1666 | } | 
|---|
| 1667 | return 0; | 
|---|
| 1668 | } | 
|---|
| 1669 | case WM_WINDOWPOSCHANGING: | 
|---|
| 1670 | return HandleWindowPosChanging((WINDOWPOS *)lParam); | 
|---|
| 1671 |  | 
|---|
| 1672 | case WM_ERASEBKGND: | 
|---|
| 1673 | case WM_ICONERASEBKGND: | 
|---|
| 1674 | { | 
|---|
| 1675 | RECT rect; | 
|---|
| 1676 | int rc; | 
|---|
| 1677 |  | 
|---|
| 1678 | if (!windowClass || !windowClass->getBackgroundBrush()) return 0; | 
|---|
| 1679 |  | 
|---|
| 1680 | rc = GetClipBox( (HDC)wParam, &rect ); | 
|---|
| 1681 | if ((rc == SIMPLEREGION) || (rc == COMPLEXREGION)) | 
|---|
| 1682 | { | 
|---|
| 1683 | HBRUSH hBrush = windowClass->getBackgroundBrush(); | 
|---|
| 1684 |  | 
|---|
| 1685 | if (hBrush <= (HBRUSH)(SYSCOLOR_GetLastColor()+1)) | 
|---|
| 1686 | hBrush = GetSysColorBrush(hBrush-1); | 
|---|
| 1687 |  | 
|---|
| 1688 | FillRect( (HDC)wParam, &rect, hBrush); | 
|---|
| 1689 | } | 
|---|
| 1690 | return 1; | 
|---|
| 1691 | } | 
|---|
| 1692 |  | 
|---|
| 1693 | case WM_PRINT: | 
|---|
| 1694 | return DefWndPrint(wParam,lParam); | 
|---|
| 1695 |  | 
|---|
| 1696 | case WM_PAINTICON: | 
|---|
| 1697 | case WM_PAINT: | 
|---|
| 1698 | { | 
|---|
| 1699 | PAINTSTRUCT ps; | 
|---|
| 1700 | HDC hdc = BeginPaint(getWindowHandle(), &ps ); | 
|---|
| 1701 | if( hdc ) | 
|---|
| 1702 | { | 
|---|
| 1703 | if( (getStyle() & WS_MINIMIZE) && (getWindowClass()->getIcon() || hIcon)) | 
|---|
| 1704 | { | 
|---|
| 1705 | int x = (rectWindow.right - rectWindow.left - GetSystemMetrics(SM_CXICON))/2; | 
|---|
| 1706 | int y = (rectWindow.bottom - rectWindow.top - GetSystemMetrics(SM_CYICON))/2; | 
|---|
| 1707 | dprintf(("Painting class icon: vis rect=(%i,%i - %i,%i)\n", ps.rcPaint.left, ps.rcPaint.top, ps.rcPaint.right, ps.rcPaint.bottom )); | 
|---|
| 1708 | DrawIcon(hdc, x, y, hIcon ? hIcon:getWindowClass()->getIcon() ); | 
|---|
| 1709 | } | 
|---|
| 1710 | EndPaint(getWindowHandle(), &ps ); | 
|---|
| 1711 | } | 
|---|
| 1712 | return 0; | 
|---|
| 1713 | } | 
|---|
| 1714 |  | 
|---|
| 1715 | case WM_GETDLGCODE: | 
|---|
| 1716 | return 0; | 
|---|
| 1717 |  | 
|---|
| 1718 | case WM_NCPAINT: | 
|---|
| 1719 | return HandleNCPaint((HRGN)wParam); | 
|---|
| 1720 |  | 
|---|
| 1721 | case WM_NCACTIVATE: | 
|---|
| 1722 | return HandleNCActivate(wParam); | 
|---|
| 1723 |  | 
|---|
| 1724 | case WM_NCCREATE: | 
|---|
| 1725 | return(TRUE); | 
|---|
| 1726 |  | 
|---|
| 1727 | case WM_NCDESTROY: | 
|---|
| 1728 | return 0; | 
|---|
| 1729 |  | 
|---|
| 1730 | case WM_NCCALCSIZE: | 
|---|
| 1731 | return HandleNCCalcSize((BOOL)wParam,(RECT*)lParam); | 
|---|
| 1732 |  | 
|---|
| 1733 | case WM_NCLBUTTONDOWN: | 
|---|
| 1734 | return HandleNCLButtonDown(wParam,lParam); | 
|---|
| 1735 |  | 
|---|
| 1736 | case WM_LBUTTONDBLCLK: | 
|---|
| 1737 | case WM_NCLBUTTONDBLCLK: | 
|---|
| 1738 | return HandleNCLButtonDblClk(wParam,lParam); | 
|---|
| 1739 |  | 
|---|
| 1740 | case WM_NCRBUTTONDOWN: | 
|---|
| 1741 | case WM_NCRBUTTONDBLCLK: | 
|---|
| 1742 | case WM_NCMBUTTONDOWN: | 
|---|
| 1743 | case WM_NCMBUTTONDBLCLK: | 
|---|
| 1744 | if (lastHitTestVal == HTERROR) MessageBeep(MB_ICONEXCLAMATION); | 
|---|
| 1745 | return 0; | 
|---|
| 1746 |  | 
|---|
| 1747 | case WM_NCRBUTTONUP: | 
|---|
| 1748 | return HandleNCRButtonUp(wParam,lParam); | 
|---|
| 1749 |  | 
|---|
| 1750 | case WM_NCMBUTTONUP: | 
|---|
| 1751 | return 0; | 
|---|
| 1752 |  | 
|---|
| 1753 | case WM_NCHITTEST: | 
|---|
| 1754 | { | 
|---|
| 1755 | POINT point; | 
|---|
| 1756 | LRESULT retvalue; | 
|---|
| 1757 |  | 
|---|
| 1758 | point.x = (SHORT)LOWORD(lParam); | 
|---|
| 1759 | point.y = (SHORT)HIWORD(lParam); | 
|---|
| 1760 |  | 
|---|
| 1761 | retvalue = HandleNCHitTest(point); | 
|---|
| 1762 | #if 0 //CB: let the Corel people fix the bugs first | 
|---|
| 1763 | if(retvalue == HTMENU) | 
|---|
| 1764 | MENU_TrackMouseMenuBar_MouseMove(Win32Hwnd,point,TRUE); | 
|---|
| 1765 | else | 
|---|
| 1766 | MENU_TrackMouseMenuBar_MouseMove(Win32Hwnd,point,FALSE); | 
|---|
| 1767 | #endif | 
|---|
| 1768 | return retvalue; | 
|---|
| 1769 | } | 
|---|
| 1770 |  | 
|---|
| 1771 | case WM_SYSCOMMAND: | 
|---|
| 1772 | { | 
|---|
| 1773 | POINT point; | 
|---|
| 1774 |  | 
|---|
| 1775 | point.x = LOWORD(lParam); | 
|---|
| 1776 | point.y = HIWORD(lParam); | 
|---|
| 1777 | return HandleSysCommand(wParam,&point); | 
|---|
| 1778 | } | 
|---|
| 1779 |  | 
|---|
| 1780 | case WM_SYSKEYDOWN: | 
|---|
| 1781 | { | 
|---|
| 1782 | if( HIWORD(lParam) & KEYDATA_ALT ) | 
|---|
| 1783 | { | 
|---|
| 1784 | /* if( HIWORD(lParam) & ~KEYDATA_PREVSTATE ) */ | 
|---|
| 1785 | if( wParam == VK_MENU && !iMenuSysKey ) | 
|---|
| 1786 | iMenuSysKey = 1; | 
|---|
| 1787 | else | 
|---|
| 1788 | iMenuSysKey = 0; | 
|---|
| 1789 |  | 
|---|
| 1790 | iF10Key = 0; | 
|---|
| 1791 |  | 
|---|
| 1792 | if( wParam == VK_F4 )       /* try to close the window */ | 
|---|
| 1793 | { | 
|---|
| 1794 | HWND top = GetTopWindow(); | 
|---|
| 1795 | if (!(GetClassLongW( top, GCL_STYLE ) & CS_NOCLOSE)) | 
|---|
| 1796 | PostMessageW( top, WM_SYSCOMMAND, SC_CLOSE, 0 ); | 
|---|
| 1797 | } | 
|---|
| 1798 | } | 
|---|
| 1799 | else if( wParam == VK_F10 ) | 
|---|
| 1800 | iF10Key = 1; | 
|---|
| 1801 | else | 
|---|
| 1802 | if( wParam == VK_ESCAPE && (GetKeyState(VK_SHIFT) & 0x8000)) | 
|---|
| 1803 | SendMessageW(WM_SYSCOMMAND, SC_KEYMENU, VK_SPACE ); | 
|---|
| 1804 |  | 
|---|
| 1805 | Win32BaseWindow *siblingWindow; | 
|---|
| 1806 | HWND sibling; | 
|---|
| 1807 | char nameBuffer [40], mnemonic; | 
|---|
| 1808 | int nameLength; | 
|---|
| 1809 |  | 
|---|
| 1810 | GetWindowTextA (nameBuffer, 40); | 
|---|
| 1811 |  | 
|---|
| 1812 | // search all sibling to see it this key is their mnemonic | 
|---|
| 1813 | sibling = GetWindow (GW_HWNDFIRST); | 
|---|
| 1814 | while (sibling != 0) { | 
|---|
| 1815 | siblingWindow = GetWindowFromHandle (sibling); | 
|---|
| 1816 | nameLength = siblingWindow->GetWindowTextA (nameBuffer, 40); | 
|---|
| 1817 |  | 
|---|
| 1818 | // find the siblings mnemonic | 
|---|
| 1819 | mnemonic = '\0'; | 
|---|
| 1820 | for (int i=0 ; i<nameLength ; i++) { | 
|---|
| 1821 | if (IsDBCSLeadByte(nameBuffer[i])) { | 
|---|
| 1822 | // Skip DBCS | 
|---|
| 1823 | continue; | 
|---|
| 1824 | } | 
|---|
| 1825 | if (nameBuffer [i] == '&') { | 
|---|
| 1826 | mnemonic = nameBuffer [i+1]; | 
|---|
| 1827 | if ((mnemonic >= 'a') && (mnemonic <= 'z')) | 
|---|
| 1828 | mnemonic -= 32; // make it uppercase | 
|---|
| 1829 | break;  // stop searching | 
|---|
| 1830 | } | 
|---|
| 1831 | } | 
|---|
| 1832 |  | 
|---|
| 1833 | // key matches siblings mnemonic, send mouseclick | 
|---|
| 1834 | if (mnemonic == (char) wParam) { | 
|---|
| 1835 | siblingWindow->SendInternalMessageA (BM_CLICK, 0, 0); | 
|---|
| 1836 | } | 
|---|
| 1837 | sibling = siblingWindow->GetNextWindow (GW_HWNDNEXT); | 
|---|
| 1838 | RELEASE_WNDOBJ(siblingWindow); | 
|---|
| 1839 | } | 
|---|
| 1840 |  | 
|---|
| 1841 | return 0; | 
|---|
| 1842 | } | 
|---|
| 1843 |  | 
|---|
| 1844 | case WM_KEYUP: | 
|---|
| 1845 | case WM_SYSKEYUP: | 
|---|
| 1846 | /* Press and release F10 or ALT */ | 
|---|
| 1847 | if (((wParam == VK_MENU) && iMenuSysKey) || | 
|---|
| 1848 | ((wParam == VK_F10) && iF10Key)) | 
|---|
| 1849 | ::SendMessageW( GetTopWindow(), WM_SYSCOMMAND, SC_KEYMENU, 0L ); | 
|---|
| 1850 | iMenuSysKey = iF10Key = 0; | 
|---|
| 1851 | break; | 
|---|
| 1852 |  | 
|---|
| 1853 | case WM_SYSCHAR: | 
|---|
| 1854 | { | 
|---|
| 1855 | iMenuSysKey = 0; | 
|---|
| 1856 | if (wParam == VK_RETURN && (getStyle() & WS_MINIMIZE)) | 
|---|
| 1857 | { | 
|---|
| 1858 | PostMessageA(getWindowHandle(), WM_SYSCOMMAND, | 
|---|
| 1859 | (WPARAM)SC_RESTORE, 0L ); | 
|---|
| 1860 | break; | 
|---|
| 1861 | } | 
|---|
| 1862 | if((HIWORD(lParam) & KEYDATA_ALT) && wParam) | 
|---|
| 1863 | { | 
|---|
| 1864 | if (wParam == VK_TAB || wParam == VK_ESCAPE || wParam == VK_F4) | 
|---|
| 1865 | break; | 
|---|
| 1866 | if (wParam == VK_SPACE && (getStyle() & WS_CHILD)) { | 
|---|
| 1867 | ::SendMessageW(GetParent(), Msg, wParam, lParam ); | 
|---|
| 1868 | } | 
|---|
| 1869 | else    SendMessageA(WM_SYSCOMMAND, (WPARAM)SC_KEYMENU, (LPARAM)(DWORD)wParam ); | 
|---|
| 1870 | } | 
|---|
| 1871 | #if 0 | 
|---|
| 1872 | else /* check for Ctrl-Esc */ | 
|---|
| 1873 | if (wParam != VK_ESCAPE) MessageBeep(0); | 
|---|
| 1874 | break; | 
|---|
| 1875 | #endif | 
|---|
| 1876 | } | 
|---|
| 1877 |  | 
|---|
| 1878 | case WM_SETHOTKEY: | 
|---|
| 1879 | hotkey = wParam; | 
|---|
| 1880 | return 1; //CB: always successful | 
|---|
| 1881 |  | 
|---|
| 1882 | case WM_GETHOTKEY: | 
|---|
| 1883 | return hotkey; | 
|---|
| 1884 |  | 
|---|
| 1885 | case WM_CONTEXTMENU: | 
|---|
| 1886 | if ((dwStyle & WS_CHILD) && getParent()) | 
|---|
| 1887 | getParent()->SendInternalMessageA(WM_CONTEXTMENU,wParam,lParam); | 
|---|
| 1888 | return 0; | 
|---|
| 1889 |  | 
|---|
| 1890 | case WM_SHOWWINDOW: | 
|---|
| 1891 | if (!lParam) return 0; /* sent from ShowWindow */ | 
|---|
| 1892 | if (!(dwStyle & WS_POPUP) || !owner) return 0; | 
|---|
| 1893 | if ((dwStyle & WS_VISIBLE) && wParam) return 0; | 
|---|
| 1894 | else if (!(dwStyle & WS_VISIBLE) && !wParam) return 0; | 
|---|
| 1895 | ShowWindow(wParam ? SW_SHOW:SW_HIDE); | 
|---|
| 1896 | return 0; | 
|---|
| 1897 |  | 
|---|
| 1898 | case WM_CANCELMODE: | 
|---|
| 1899 | if (getParent() == windowDesktop) EndMenu(); | 
|---|
| 1900 | if (GetCapture() == Win32Hwnd) ReleaseCapture(); | 
|---|
| 1901 | return 0; | 
|---|
| 1902 |  | 
|---|
| 1903 | case WM_DROPOBJECT: | 
|---|
| 1904 | return DRAG_FILE; | 
|---|
| 1905 |  | 
|---|
| 1906 | case WM_QUERYDROPOBJECT: | 
|---|
| 1907 | return (dwExStyle & WS_EX_ACCEPTFILES) ? 1:0; | 
|---|
| 1908 |  | 
|---|
| 1909 | case WM_QUERYDRAGICON: | 
|---|
| 1910 | { | 
|---|
| 1911 | HICON hDragIcon = windowClass->getCursor(); | 
|---|
| 1912 | UINT len; | 
|---|
| 1913 |  | 
|---|
| 1914 | if(hDragIcon) return (LRESULT)hDragIcon; | 
|---|
| 1915 | for(len = 1; len < 64; len++) | 
|---|
| 1916 | { | 
|---|
| 1917 | hDragIcon = LoadIconA(hInstance,MAKEINTRESOURCEA(len)); | 
|---|
| 1918 | if(hDragIcon) | 
|---|
| 1919 | return (LRESULT)hDragIcon; | 
|---|
| 1920 | } | 
|---|
| 1921 | return (LRESULT)LoadIconA(0,IDI_APPLICATIONA); | 
|---|
| 1922 | } | 
|---|
| 1923 |  | 
|---|
| 1924 | case WM_QUERYOPEN: | 
|---|
| 1925 | case WM_QUERYENDSESSION: | 
|---|
| 1926 | return 1; | 
|---|
| 1927 |  | 
|---|
| 1928 | case WM_NOTIFYFORMAT: | 
|---|
| 1929 | return IsWindowUnicode() ? NFR_UNICODE:NFR_ANSI; | 
|---|
| 1930 |  | 
|---|
| 1931 | case WM_SETICON: | 
|---|
| 1932 | case WM_GETICON: | 
|---|
| 1933 | { | 
|---|
| 1934 | LRESULT result = 0; | 
|---|
| 1935 |  | 
|---|
| 1936 | /* Set the appropriate icon members in the window structure. */ | 
|---|
| 1937 | if (wParam == ICON_SMALL) | 
|---|
| 1938 | { | 
|---|
| 1939 | result = hIconSm; | 
|---|
| 1940 | if (Msg == WM_SETICON) | 
|---|
| 1941 | hIconSm = (HICON)lParam; | 
|---|
| 1942 | } | 
|---|
| 1943 | else | 
|---|
| 1944 | { | 
|---|
| 1945 | result = hIcon; | 
|---|
| 1946 | if (Msg == WM_SETICON) | 
|---|
| 1947 | { | 
|---|
| 1948 | hIcon = (HICON)lParam; | 
|---|
| 1949 | if ((dwStyle & WS_CAPTION) == WS_CAPTION) | 
|---|
| 1950 | OSLibWinSetIcon(OS2HwndFrame,hIcon); | 
|---|
| 1951 | } | 
|---|
| 1952 | } | 
|---|
| 1953 | if ((Msg == WM_SETICON) && ((dwStyle & WS_CAPTION) == WS_CAPTION)) | 
|---|
| 1954 | HandleNCPaint((HRGN)1); | 
|---|
| 1955 |  | 
|---|
| 1956 | return result; | 
|---|
| 1957 | } | 
|---|
| 1958 |  | 
|---|
| 1959 | case WM_HELP: | 
|---|
| 1960 | if (getParent()) getParent()->SendInternalMessageA(Msg,wParam,lParam); | 
|---|
| 1961 | break; | 
|---|
| 1962 |  | 
|---|
| 1963 | case WM_NOTIFY: | 
|---|
| 1964 | return 0; //comctl32 controls expect this | 
|---|
| 1965 |  | 
|---|
| 1966 | default: | 
|---|
| 1967 | return 0; | 
|---|
| 1968 | } | 
|---|
| 1969 | return 0; | 
|---|
| 1970 | } | 
|---|
| 1971 | //****************************************************************************** | 
|---|
| 1972 | //****************************************************************************** | 
|---|
| 1973 | LRESULT Win32BaseWindow::DefWindowProcW(UINT Msg, WPARAM wParam, LPARAM lParam) | 
|---|
| 1974 | { | 
|---|
| 1975 | switch(Msg) | 
|---|
| 1976 | { | 
|---|
| 1977 | case WM_GETTEXTLENGTH: | 
|---|
| 1978 | if(windowNameW) { | 
|---|
| 1979 | return lstrlenW(windowNameW); | 
|---|
| 1980 | } | 
|---|
| 1981 | else return 0; | 
|---|
| 1982 |  | 
|---|
| 1983 | case WM_GETTEXT: | 
|---|
| 1984 | if (!lParam || !wParam) return 0; | 
|---|
| 1985 | if (!windowNameW) ((LPWSTR)lParam)[0] = 0; | 
|---|
| 1986 | else lstrcpynW((LPWSTR)lParam,windowNameW,wParam); | 
|---|
| 1987 | return min((windowNameW ? lstrlenW(windowNameW) : 0),wParam); | 
|---|
| 1988 |  | 
|---|
| 1989 | case WM_SETTEXT: | 
|---|
| 1990 | { | 
|---|
| 1991 | LPWSTR lpsz = (LPWSTR)lParam; | 
|---|
| 1992 |  | 
|---|
| 1993 | if(windowNameA) free(windowNameA); | 
|---|
| 1994 | if(windowNameW) free(windowNameW); | 
|---|
| 1995 | if (lParam) | 
|---|
| 1996 | { | 
|---|
| 1997 | // Wide | 
|---|
| 1998 | int wndNameLength = lstrlenW(lpsz); | 
|---|
| 1999 | windowNameW = (LPWSTR)_smalloc((wndNameLength+1)*sizeof(WCHAR)); | 
|---|
| 2000 | lstrcpyW(windowNameW,lpsz); | 
|---|
| 2001 | // Ascii | 
|---|
| 2002 | LPSTR tmp = HEAP_strdupWtoA(GetProcessHeap(), 0, lpsz); | 
|---|
| 2003 | if(tmp) { | 
|---|
| 2004 | long tmpLength = strlen( tmp ); | 
|---|
| 2005 | windowNameA = (LPSTR)_smalloc(tmpLength+1); | 
|---|
| 2006 | strcpy(windowNameA,tmp); | 
|---|
| 2007 | windowNameA[tmpLength] = 0; // need ? | 
|---|
| 2008 | HEAP_free(tmp); | 
|---|
| 2009 | } | 
|---|
| 2010 | else { | 
|---|
| 2011 | windowNameA = (LPSTR)_smalloc(1); | 
|---|
| 2012 | windowNameA[0] = 0; | 
|---|
| 2013 | } | 
|---|
| 2014 | } | 
|---|
| 2015 | else | 
|---|
| 2016 | { | 
|---|
| 2017 | windowNameA = NULL; | 
|---|
| 2018 | windowNameW = NULL; | 
|---|
| 2019 | } | 
|---|
| 2020 | dprintf(("WM_SETTEXT of %x\n",Win32Hwnd)); | 
|---|
| 2021 | if ((dwStyle & WS_CAPTION) == WS_CAPTION) | 
|---|
| 2022 | { | 
|---|
| 2023 | HandleNCPaint((HRGN)1); | 
|---|
| 2024 | if(hTaskList) { | 
|---|
| 2025 | OSLibWinChangeTaskList(hTaskList, OS2HwndFrame, getWindowNameA(), (getStyle() & WS_VISIBLE) ? 1 : 0); | 
|---|
| 2026 | } | 
|---|
| 2027 | if(fOS2Look) { | 
|---|
| 2028 | OSLibWinSetTitleBarText(OS2HwndFrame, getWindowNameA()); | 
|---|
| 2029 | } | 
|---|
| 2030 | } | 
|---|
| 2031 |  | 
|---|
| 2032 | return TRUE; | 
|---|
| 2033 | } | 
|---|
| 2034 |  | 
|---|
| 2035 | default: | 
|---|
| 2036 | return DefWindowProcA(Msg, wParam, lParam); | 
|---|
| 2037 | } | 
|---|
| 2038 | } | 
|---|
| 2039 | //****************************************************************************** | 
|---|
| 2040 | //****************************************************************************** | 
|---|
| 2041 | LRESULT Win32BaseWindow::SendMessageA(ULONG Msg, WPARAM wParam, LPARAM lParam) | 
|---|
| 2042 | { | 
|---|
| 2043 | //if the destination window is created by this process & thread, call window proc directly | 
|---|
| 2044 | if(dwProcessId == currentProcessId && dwThreadId == GetCurrentThreadId()) { | 
|---|
| 2045 | return SendInternalMessageA(Msg, wParam, lParam); | 
|---|
| 2046 | } | 
|---|
| 2047 | //otherwise use WinSendMsg to send it to the right process/thread | 
|---|
| 2048 | dprintf(("SendMessages (inter-process) %x %x %x %x", getWindowHandle(), Msg, wParam, lParam)); | 
|---|
| 2049 | return OSLibSendMessage(getOS2WindowHandle(), Msg, wParam, lParam, FALSE); | 
|---|
| 2050 | } | 
|---|
| 2051 | //****************************************************************************** | 
|---|
| 2052 | //****************************************************************************** | 
|---|
| 2053 | LRESULT Win32BaseWindow::SendMessageW(ULONG Msg, WPARAM wParam, LPARAM lParam) | 
|---|
| 2054 | { | 
|---|
| 2055 | //if the destination window is created by this process & thread, call window proc directly | 
|---|
| 2056 | if(dwProcessId == currentProcessId && dwThreadId == GetCurrentThreadId()) { | 
|---|
| 2057 | return SendInternalMessageW(Msg, wParam, lParam); | 
|---|
| 2058 | } | 
|---|
| 2059 | //otherwise use WinSendMsg to send it to the right process/thread | 
|---|
| 2060 | return OSLibSendMessage(getOS2WindowHandle(), Msg, wParam, lParam, TRUE); | 
|---|
| 2061 | } | 
|---|
| 2062 | //****************************************************************************** | 
|---|
| 2063 | //Called as a result of an OS/2 message or called from a class method | 
|---|
| 2064 | //****************************************************************************** | 
|---|
| 2065 | LRESULT Win32BaseWindow::SendInternalMessageA(ULONG Msg, WPARAM wParam, LPARAM lParam) | 
|---|
| 2066 | { | 
|---|
| 2067 | LRESULT rc; | 
|---|
| 2068 | HWND    hwnd = getWindowHandle(); | 
|---|
| 2069 | BOOL    fInternalMsgBackup = fInternalMsg; | 
|---|
| 2070 |  | 
|---|
| 2071 | //if the destination window was created by this process & thread, call window proc directly | 
|---|
| 2072 | if(dwProcessId != currentProcessId || dwThreadId != GetCurrentThreadId()) { | 
|---|
| 2073 | dprintf(("SendMessages (inter-process) %x %x %x %x", getWindowHandle(), Msg, wParam, lParam)); | 
|---|
| 2074 | return OSLibSendMessage(getOS2WindowHandle(), Msg, wParam, lParam, FALSE); | 
|---|
| 2075 | } | 
|---|
| 2076 |  | 
|---|
| 2077 | DebugPrintMessage(getWindowHandle(), Msg, wParam, lParam, FALSE, TRUE); | 
|---|
| 2078 |  | 
|---|
| 2079 | CallWindowHookProc(WH_CALLWNDPROC, Msg, wParam, lParam, FALSE); | 
|---|
| 2080 |  | 
|---|
| 2081 | fInternalMsg = TRUE; | 
|---|
| 2082 | switch(Msg) | 
|---|
| 2083 | { | 
|---|
| 2084 | case WM_CREATE: | 
|---|
| 2085 | { | 
|---|
| 2086 | if(CallWindowProcA(win32wndproc, getWindowHandle(), WM_CREATE, 0, lParam) == -1) { | 
|---|
| 2087 | dprintf(("WM_CREATE returned -1\n")); | 
|---|
| 2088 | rc = -1; //don't create window | 
|---|
| 2089 | break; | 
|---|
| 2090 | } | 
|---|
| 2091 | rc = 0; | 
|---|
| 2092 | break; | 
|---|
| 2093 | } | 
|---|
| 2094 | case WM_LBUTTONDOWN: | 
|---|
| 2095 | case WM_MBUTTONDOWN: | 
|---|
| 2096 | case WM_RBUTTONDOWN: | 
|---|
| 2097 | { | 
|---|
| 2098 | if (getParent()) | 
|---|
| 2099 | { | 
|---|
| 2100 | POINTS pt = MAKEPOINTS(lParam); | 
|---|
| 2101 | POINT point; | 
|---|
| 2102 |  | 
|---|
| 2103 | point.x = pt.x; | 
|---|
| 2104 | point.y = pt.y; | 
|---|
| 2105 | MapWindowPoints(getWindowHandle(), getParent()->getWindowHandle(), &point, 1); | 
|---|
| 2106 | NotifyParent(Msg,wParam,MAKELPARAM(point.x,point.y)); | 
|---|
| 2107 | } | 
|---|
| 2108 | rc = win32wndproc(getWindowHandle(), Msg, wParam, lParam); | 
|---|
| 2109 | break; | 
|---|
| 2110 | } | 
|---|
| 2111 | case WM_NCHITTEST: | 
|---|
| 2112 | rc = lastHitTestVal = win32wndproc(getWindowHandle(), WM_NCHITTEST, wParam, lParam); | 
|---|
| 2113 | break; | 
|---|
| 2114 |  | 
|---|
| 2115 | case WM_DESTROY: | 
|---|
| 2116 | rc = win32wndproc(getWindowHandle(), WM_DESTROY, 0, 0); | 
|---|
| 2117 | break; | 
|---|
| 2118 |  | 
|---|
| 2119 | default: | 
|---|
| 2120 | rc = CallWindowProcA(win32wndproc, getWindowHandle(), Msg, wParam, lParam); | 
|---|
| 2121 | break; | 
|---|
| 2122 | } | 
|---|
| 2123 | if(!::IsWindow(hwnd)) { | 
|---|
| 2124 | //window might have been destroyed by now. (this pointer invalid) | 
|---|
| 2125 | //we must return immediately | 
|---|
| 2126 | //(MS Visual C++ install heap corruption) | 
|---|
| 2127 | //TODO: could happen in several places here!!!! | 
|---|
| 2128 | return rc; | 
|---|
| 2129 | } | 
|---|
| 2130 | fInternalMsg = fInternalMsgBackup; | 
|---|
| 2131 | dprintf2(("SendMessageA %x %x %x %x returned %d", getWindowHandle(), Msg, wParam, lParam, rc)); | 
|---|
| 2132 | return rc; | 
|---|
| 2133 | } | 
|---|
| 2134 | //****************************************************************************** | 
|---|
| 2135 | //Called as a result of an OS/2 message or called from a class method | 
|---|
| 2136 | //****************************************************************************** | 
|---|
| 2137 | LRESULT Win32BaseWindow::SendInternalMessageW(ULONG Msg, WPARAM wParam, LPARAM lParam) | 
|---|
| 2138 | { | 
|---|
| 2139 | LRESULT rc; | 
|---|
| 2140 | HWND    hwnd = getWindowHandle(); | 
|---|
| 2141 | BOOL    fInternalMsgBackup = fInternalMsg; | 
|---|
| 2142 |  | 
|---|
| 2143 | //if the destination window was created by this process & thread, call window proc directly | 
|---|
| 2144 | if(dwProcessId != currentProcessId || dwThreadId != GetCurrentThreadId()) { | 
|---|
| 2145 | dprintf(("SendMessages (inter-process) %x %x %x %x", getWindowHandle(), Msg, wParam, lParam)); | 
|---|
| 2146 | return OSLibSendMessage(getOS2WindowHandle(), Msg, wParam, lParam, FALSE); | 
|---|
| 2147 | } | 
|---|
| 2148 |  | 
|---|
| 2149 | DebugPrintMessage(getWindowHandle(), Msg, wParam, lParam, TRUE, TRUE); | 
|---|
| 2150 |  | 
|---|
| 2151 | CallWindowHookProc(WH_CALLWNDPROC, Msg, wParam, lParam, TRUE); | 
|---|
| 2152 |  | 
|---|
| 2153 | fInternalMsg = TRUE; | 
|---|
| 2154 | switch(Msg) | 
|---|
| 2155 | { | 
|---|
| 2156 | case WM_CREATE: | 
|---|
| 2157 | { | 
|---|
| 2158 | if(CallWindowProcW(win32wndproc, getWindowHandle(), WM_CREATE, 0, lParam) == -1) { | 
|---|
| 2159 | dprintf(("WM_CREATE returned -1\n")); | 
|---|
| 2160 | rc = -1; //don't create window | 
|---|
| 2161 | break; | 
|---|
| 2162 | } | 
|---|
| 2163 | rc = 0; | 
|---|
| 2164 | break; | 
|---|
| 2165 | } | 
|---|
| 2166 | case WM_LBUTTONDOWN: | 
|---|
| 2167 | case WM_MBUTTONDOWN: | 
|---|
| 2168 | case WM_RBUTTONDOWN: | 
|---|
| 2169 | NotifyParent(Msg, wParam, lParam); | 
|---|
| 2170 | rc = win32wndproc(getWindowHandle(), Msg, wParam, lParam); | 
|---|
| 2171 | break; | 
|---|
| 2172 |  | 
|---|
| 2173 | case WM_NCHITTEST: | 
|---|
| 2174 | rc = lastHitTestVal = win32wndproc(getWindowHandle(), WM_NCHITTEST, wParam, lParam); | 
|---|
| 2175 | break; | 
|---|
| 2176 |  | 
|---|
| 2177 | case WM_DESTROY: | 
|---|
| 2178 | rc = win32wndproc(getWindowHandle(), WM_DESTROY, 0, 0); | 
|---|
| 2179 | break; | 
|---|
| 2180 | default: | 
|---|
| 2181 | rc = CallWindowProcW(win32wndproc, getWindowHandle(), Msg, wParam, lParam); | 
|---|
| 2182 | break; | 
|---|
| 2183 | } | 
|---|
| 2184 | if(!::IsWindow(hwnd)) { | 
|---|
| 2185 | //window might have been destroyed by now. (this pointer invalid) | 
|---|
| 2186 | //we must return immediately | 
|---|
| 2187 | //(MS Visual C++ install heap corruption) | 
|---|
| 2188 | //TODO: could happen in several places here!!!! | 
|---|
| 2189 | return rc; | 
|---|
| 2190 | } | 
|---|
| 2191 | fInternalMsg = fInternalMsgBackup; | 
|---|
| 2192 | dprintf2(("SendMessageW %x %x %x %x returned %d", getWindowHandle(), Msg, wParam, lParam, rc)); | 
|---|
| 2193 | return rc; | 
|---|
| 2194 | } | 
|---|
| 2195 | //****************************************************************************** | 
|---|
| 2196 | //****************************************************************************** | 
|---|
| 2197 | void Win32BaseWindow::CallWindowHookProc(ULONG hooktype, ULONG Msg, WPARAM wParam, LPARAM lParam, BOOL fUnicode) | 
|---|
| 2198 | { | 
|---|
| 2199 | CWPSTRUCT cwp; | 
|---|
| 2200 |  | 
|---|
| 2201 | cwp.lParam  = lParam; | 
|---|
| 2202 | cwp.wParam  = wParam; | 
|---|
| 2203 | cwp.message = Msg; | 
|---|
| 2204 | cwp.hwnd    = getWindowHandle(); | 
|---|
| 2205 |  | 
|---|
| 2206 | switch(hooktype) { | 
|---|
| 2207 | case WH_CALLWNDPROC: | 
|---|
| 2208 | if(fUnicode) { | 
|---|
| 2209 | HOOK_CallHooksW(WH_CALLWNDPROC, HC_ACTION, 1, (LPARAM)&cwp); | 
|---|
| 2210 | } | 
|---|
| 2211 | else HOOK_CallHooksA(WH_CALLWNDPROC, HC_ACTION, 1, (LPARAM)&cwp); | 
|---|
| 2212 | break; | 
|---|
| 2213 | } | 
|---|
| 2214 | } | 
|---|
| 2215 | //****************************************************************************** | 
|---|
| 2216 | //TODO: Do this more efficiently | 
|---|
| 2217 | //****************************************************************************** | 
|---|
| 2218 | LRESULT Win32BaseWindow::BroadcastMessageA(int type, UINT msg, WPARAM wParam, LPARAM lParam) | 
|---|
| 2219 | { | 
|---|
| 2220 | Win32BaseWindow *window; | 
|---|
| 2221 | HWND hwnd = WNDHANDLE_MAGIC_HIGHWORD; | 
|---|
| 2222 |  | 
|---|
| 2223 | dprintf(("BroadCastMessageA %x %x %x %s", msg, wParam, lParam, (type == BROADCAST_SEND) ? "Send" : "Post")); | 
|---|
| 2224 |  | 
|---|
| 2225 | for(int i=0;i<MAX_WINDOW_HANDLES;i++) { | 
|---|
| 2226 | window = GetWindowFromHandle(hwnd++); | 
|---|
| 2227 | if(window) { | 
|---|
| 2228 | if ((window->getStyle() & WS_POPUP) || ((window->getStyle() & WS_CAPTION) == WS_CAPTION)) | 
|---|
| 2229 | { | 
|---|
| 2230 | if(type == BROADCAST_SEND) { | 
|---|
| 2231 | ::SendMessageA(window->getWindowHandle(), msg, wParam, lParam); | 
|---|
| 2232 | } | 
|---|
| 2233 | else    PostMessageA(window->getWindowHandle(), msg, wParam, lParam); | 
|---|
| 2234 | } | 
|---|
| 2235 | RELEASE_WNDOBJ(window); | 
|---|
| 2236 | } | 
|---|
| 2237 | } | 
|---|
| 2238 | return 0; | 
|---|
| 2239 | } | 
|---|
| 2240 | //****************************************************************************** | 
|---|
| 2241 | //TODO: Do this more efficiently | 
|---|
| 2242 | //****************************************************************************** | 
|---|
| 2243 | LRESULT Win32BaseWindow::BroadcastMessageW(int type, UINT msg, WPARAM wParam, LPARAM lParam) | 
|---|
| 2244 | { | 
|---|
| 2245 | Win32BaseWindow *window; | 
|---|
| 2246 | HWND hwnd = WNDHANDLE_MAGIC_HIGHWORD; | 
|---|
| 2247 |  | 
|---|
| 2248 | dprintf(("BroadCastMessageW %x %x %x %s", msg, wParam, lParam, (type == BROADCAST_SEND) ? "Send" : "Post")); | 
|---|
| 2249 |  | 
|---|
| 2250 | for(int i=0;i<MAX_WINDOW_HANDLES;i++) { | 
|---|
| 2251 | window = GetWindowFromHandle(hwnd++); | 
|---|
| 2252 | if(window) { | 
|---|
| 2253 | if ((window->getStyle() & WS_POPUP) || ((window->getStyle() & WS_CAPTION) == WS_CAPTION)) | 
|---|
| 2254 | { | 
|---|
| 2255 | if(type == BROADCAST_SEND) { | 
|---|
| 2256 | ::SendMessageW(window->getWindowHandle(), msg, wParam, lParam); | 
|---|
| 2257 | } | 
|---|
| 2258 | else    PostMessageW(window->getWindowHandle(), msg, wParam, lParam); | 
|---|
| 2259 | } | 
|---|
| 2260 | RELEASE_WNDOBJ(window); | 
|---|
| 2261 | } | 
|---|
| 2262 | } | 
|---|
| 2263 | return 0; | 
|---|
| 2264 | } | 
|---|
| 2265 | //****************************************************************************** | 
|---|
| 2266 | //****************************************************************************** | 
|---|
| 2267 | void Win32BaseWindow::NotifyParent(UINT Msg, WPARAM wParam, LPARAM lParam) | 
|---|
| 2268 | { | 
|---|
| 2269 | Win32BaseWindow *window = this; | 
|---|
| 2270 | Win32BaseWindow *parentwindow; | 
|---|
| 2271 |  | 
|---|
| 2272 | while(window) | 
|---|
| 2273 | { | 
|---|
| 2274 | if(window->getStyle() & WS_CHILD && !(window->getExStyle() & WS_EX_NOPARENTNOTIFY) ) | 
|---|
| 2275 | { | 
|---|
| 2276 | /* Notify the parent window only */ | 
|---|
| 2277 | parentwindow = window->getParent(); | 
|---|
| 2278 | if(parentwindow) { | 
|---|
| 2279 | parentwindow->SendInternalMessageA(WM_PARENTNOTIFY, MAKEWPARAM(Msg, getWindowId()), lParam ); | 
|---|
| 2280 | } | 
|---|
| 2281 | } | 
|---|
| 2282 | else    break; | 
|---|
| 2283 |  | 
|---|
| 2284 | window = parentwindow; | 
|---|
| 2285 | } | 
|---|
| 2286 | } | 
|---|
| 2287 | //****************************************************************************** | 
|---|
| 2288 | // Returns the big or small icon for the window, falling back to the | 
|---|
| 2289 | // class as windows does. | 
|---|
| 2290 | //****************************************************************************** | 
|---|
| 2291 | HICON Win32BaseWindow::IconForWindow(WPARAM fType) | 
|---|
| 2292 | { | 
|---|
| 2293 | HICON hWndIcon; | 
|---|
| 2294 |  | 
|---|
| 2295 | if (fType == ICON_BIG) | 
|---|
| 2296 | { | 
|---|
| 2297 | if (hIcon) | 
|---|
| 2298 | hWndIcon = hIcon; | 
|---|
| 2299 | else | 
|---|
| 2300 | if (windowClass && windowClass->getIcon()) | 
|---|
| 2301 | hWndIcon = windowClass->getIcon(); | 
|---|
| 2302 | else | 
|---|
| 2303 | if (!(dwStyle & DS_MODALFRAME)) | 
|---|
| 2304 | hWndIcon = LoadImageA(0,MAKEINTRESOURCEA(OIC_ODINICON),IMAGE_ICON,0,0,LR_DEFAULTCOLOR); | 
|---|
| 2305 | else hWndIcon = 0; | 
|---|
| 2306 | } | 
|---|
| 2307 | else | 
|---|
| 2308 | { | 
|---|
| 2309 | if (hIconSm) | 
|---|
| 2310 | hWndIcon = hIconSm; | 
|---|
| 2311 | else | 
|---|
| 2312 | if (hIcon) | 
|---|
| 2313 | hWndIcon = hIcon; | 
|---|
| 2314 | else | 
|---|
| 2315 | if (windowClass && windowClass->getIconSm()) | 
|---|
| 2316 | hWndIcon = windowClass->getIconSm(); | 
|---|
| 2317 | else | 
|---|
| 2318 | if (windowClass && windowClass->getIcon()) | 
|---|
| 2319 | hWndIcon = windowClass->getIcon(); | 
|---|
| 2320 | else | 
|---|
| 2321 | if (!(dwStyle & DS_MODALFRAME)) | 
|---|
| 2322 | hWndIcon = LoadImageA(0,MAKEINTRESOURCEA(OIC_ODINICON),IMAGE_ICON,0,0,LR_DEFAULTCOLOR); | 
|---|
| 2323 | else hWndIcon = 0; | 
|---|
| 2324 | } | 
|---|
| 2325 |  | 
|---|
| 2326 | return hWndIcon; | 
|---|
| 2327 | } | 
|---|
| 2328 | //****************************************************************************** | 
|---|
| 2329 | //****************************************************************************** | 
|---|
| 2330 | BOOL Win32BaseWindow::ShowWindow(ULONG nCmdShow) | 
|---|
| 2331 | { | 
|---|
| 2332 | ULONG swp = 0; | 
|---|
| 2333 | HWND  hWinAfter; | 
|---|
| 2334 | BOOL  rc,wasVisible,showFlag; | 
|---|
| 2335 | RECT  newPos = {0, 0, 0, 0}; | 
|---|
| 2336 |  | 
|---|
| 2337 | dprintf(("ShowWindow %x %x", getWindowHandle(), nCmdShow)); | 
|---|
| 2338 | wasVisible = (getStyle() & WS_VISIBLE) != 0; | 
|---|
| 2339 |  | 
|---|
| 2340 | dwOldStyle = getStyle(); | 
|---|
| 2341 |  | 
|---|
| 2342 | switch(nCmdShow) | 
|---|
| 2343 | { | 
|---|
| 2344 | case SW_HIDE: | 
|---|
| 2345 | if (!wasVisible) goto END; | 
|---|
| 2346 |  | 
|---|
| 2347 | swp |= SWP_HIDEWINDOW | SWP_NOSIZE | SWP_NOMOVE | SWP_NOACTIVATE | SWP_NOZORDER; | 
|---|
| 2348 | break; | 
|---|
| 2349 |  | 
|---|
| 2350 | case SW_SHOWMINNOACTIVE: | 
|---|
| 2351 | swp |= SWP_NOACTIVATE | SWP_NOZORDER; | 
|---|
| 2352 | /* fall through */ | 
|---|
| 2353 | case SW_SHOWMINIMIZED: | 
|---|
| 2354 | swp |= SWP_SHOWWINDOW; | 
|---|
| 2355 | /* fall through */ | 
|---|
| 2356 | case SW_MINIMIZE: | 
|---|
| 2357 | swp |= SWP_FRAMECHANGED; | 
|---|
| 2358 | if( !(getStyle() & WS_MINIMIZE) ) { | 
|---|
| 2359 | swp |= MinMaximize(SW_MINIMIZE, &newPos ); | 
|---|
| 2360 | fMinMaxChange = TRUE; //-> invalidate entire window in WM_CALCINVALIDRECT | 
|---|
| 2361 | } | 
|---|
| 2362 | else swp |= SWP_NOSIZE | SWP_NOMOVE; | 
|---|
| 2363 | break; | 
|---|
| 2364 |  | 
|---|
| 2365 | case SW_SHOWMAXIMIZED: /* same as SW_MAXIMIZE */ | 
|---|
| 2366 | swp |= SWP_SHOWWINDOW | SWP_FRAMECHANGED; | 
|---|
| 2367 | if( !(getStyle() & WS_MAXIMIZE) ) { | 
|---|
| 2368 | swp |= MinMaximize(SW_MAXIMIZE, &newPos ); | 
|---|
| 2369 | fMinMaxChange = TRUE; //-> invalidate entire window in WM_CALCINVALIDRECT | 
|---|
| 2370 | } | 
|---|
| 2371 | else swp |= SWP_NOSIZE | SWP_NOMOVE; | 
|---|
| 2372 | break; | 
|---|
| 2373 |  | 
|---|
| 2374 | case SW_SHOWNA: | 
|---|
| 2375 | swp |= SWP_NOACTIVATE | SWP_NOZORDER; | 
|---|
| 2376 | /* fall through */ | 
|---|
| 2377 | case SW_SHOW: | 
|---|
| 2378 | swp |= SWP_SHOWWINDOW | SWP_NOSIZE | SWP_NOMOVE; | 
|---|
| 2379 |  | 
|---|
| 2380 | /* | 
|---|
| 2381 | * ShowWindow has a little peculiar behavior that if the | 
|---|
| 2382 | * window is already the topmost window, it will not | 
|---|
| 2383 | * activate it. | 
|---|
| 2384 | */ | 
|---|
| 2385 | if (::GetTopWindow((HWND)0)==getWindowHandle() && (wasVisible || GetActiveWindow() == getWindowHandle())) | 
|---|
| 2386 | swp |= SWP_NOACTIVATE; | 
|---|
| 2387 |  | 
|---|
| 2388 | break; | 
|---|
| 2389 |  | 
|---|
| 2390 | case SW_SHOWNOACTIVATE: | 
|---|
| 2391 | swp |= SWP_NOZORDER; | 
|---|
| 2392 | if (GetActiveWindow()) | 
|---|
| 2393 | swp |= SWP_NOACTIVATE; | 
|---|
| 2394 | /* fall through */ | 
|---|
| 2395 | case SW_SHOWNORMAL:  /* same as SW_NORMAL: */ | 
|---|
| 2396 | case SW_SHOWDEFAULT: /* FIXME: should have its own handler */ | 
|---|
| 2397 | case SW_RESTORE: | 
|---|
| 2398 | swp |= SWP_SHOWWINDOW | SWP_FRAMECHANGED; | 
|---|
| 2399 |  | 
|---|
| 2400 | if( getStyle() & (WS_MINIMIZE | WS_MAXIMIZE) ) { | 
|---|
| 2401 | swp |= MinMaximize(SW_RESTORE, &newPos ); | 
|---|
| 2402 | fMinMaxChange = TRUE; //-> invalidate entire window in WM_CALCINVALIDRECT | 
|---|
| 2403 | } | 
|---|
| 2404 | else swp |= SWP_NOSIZE | SWP_NOMOVE; | 
|---|
| 2405 | break; | 
|---|
| 2406 | } | 
|---|
| 2407 |  | 
|---|
| 2408 | showFlag = (nCmdShow != SW_HIDE); | 
|---|
| 2409 | if (showFlag != wasVisible) | 
|---|
| 2410 | { | 
|---|
| 2411 | SendInternalMessageA(WM_SHOWWINDOW, showFlag, 0 ); | 
|---|
| 2412 | if (!::IsWindow( getWindowHandle() )) goto END; | 
|---|
| 2413 | } | 
|---|
| 2414 |  | 
|---|
| 2415 | /* We can't activate a child window */ | 
|---|
| 2416 | if((getStyle() & WS_CHILD) && !(getExStyle() & WS_EX_MDICHILD)) | 
|---|
| 2417 | swp |= SWP_NOACTIVATE | SWP_NOZORDER; | 
|---|
| 2418 |  | 
|---|
| 2419 | SetWindowPos(HWND_TOP, newPos.left, newPos.top, newPos.right, newPos.bottom, LOWORD(swp)); | 
|---|
| 2420 |  | 
|---|
| 2421 | if(!(swp & SWP_NOACTIVATE)) { | 
|---|
| 2422 | OSLibWinSetActiveWindow(OS2HwndFrame); | 
|---|
| 2423 | } | 
|---|
| 2424 |  | 
|---|
| 2425 | if (flags & WIN_NEED_SIZE) | 
|---|
| 2426 | { | 
|---|
| 2427 | /* should happen only in CreateWindowEx() */ | 
|---|
| 2428 | int wParam = SIZE_RESTORED; | 
|---|
| 2429 |  | 
|---|
| 2430 | flags &= ~WIN_NEED_SIZE; | 
|---|
| 2431 | if (dwStyle & WS_MAXIMIZE) | 
|---|
| 2432 | wParam = SIZE_MAXIMIZED; | 
|---|
| 2433 | else | 
|---|
| 2434 | if (dwStyle & WS_MINIMIZE) | 
|---|
| 2435 | wParam = SIZE_MINIMIZED; | 
|---|
| 2436 |  | 
|---|
| 2437 | SendInternalMessageA(WM_SIZE, wParam, | 
|---|
| 2438 | MAKELONG(rectClient.right-rectClient.left, | 
|---|
| 2439 | rectClient.bottom-rectClient.top)); | 
|---|
| 2440 | SendInternalMessageA(WM_MOVE,0,MAKELONG(rectClient.left,rectClient.top)); | 
|---|
| 2441 | } | 
|---|
| 2442 | //testestest | 
|---|
| 2443 | //temporary workaround for file dialogs with template dialog child | 
|---|
| 2444 | //they don't redraw when switching directories | 
|---|
| 2445 | //For some reason the new child's (syslistview32) update rectangle stays | 
|---|
| 2446 | //empty after its parent is made visible with ShowWindow | 
|---|
| 2447 | //TODO: find real cause | 
|---|
| 2448 | if(!wasVisible) { | 
|---|
| 2449 | InvalidateRect(getWindowHandle(), NULL, TRUE); | 
|---|
| 2450 | } | 
|---|
| 2451 | //testestest | 
|---|
| 2452 | END: | 
|---|
| 2453 | fMinMaxChange = FALSE; | 
|---|
| 2454 | return wasVisible; | 
|---|
| 2455 | } | 
|---|
| 2456 | //****************************************************************************** | 
|---|
| 2457 | //****************************************************************************** | 
|---|
| 2458 | BOOL Win32BaseWindow::SetWindowPos(HWND hwndInsertAfter, int x, int y, int cx, int cy, UINT fuFlags) | 
|---|
| 2459 | { | 
|---|
| 2460 | BOOL rc = FALSE; | 
|---|
| 2461 | Win32BaseWindow *window; | 
|---|
| 2462 | HWND hParent = 0; | 
|---|
| 2463 | RECT oldClientRect = rectClient; | 
|---|
| 2464 |  | 
|---|
| 2465 | if (fuFlags & | 
|---|
| 2466 | ~(SWP_NOSIZE     | SWP_NOMOVE     | SWP_NOZORDER     | | 
|---|
| 2467 | SWP_NOREDRAW   | SWP_NOACTIVATE | SWP_FRAMECHANGED | | 
|---|
| 2468 | SWP_SHOWWINDOW | SWP_HIDEWINDOW | SWP_NOCOPYBITS   | | 
|---|
| 2469 | SWP_NOOWNERZORDER | SWP_NOSENDCHANGING | SWP_DEFERERASE | | 
|---|
| 2470 | SWP_NOCLIENTSIZE | SWP_NOCLIENTMOVE)) | 
|---|
| 2471 | { | 
|---|
| 2472 | dprintf(("ERROR: SetWindowPos; UNKNOWN flag")); | 
|---|
| 2473 | return FALSE; | 
|---|
| 2474 | } | 
|---|
| 2475 |  | 
|---|
| 2476 | if( fuFlags & (SWP_DEFERERASE | SWP_NOCLIENTSIZE | SWP_NOCLIENTMOVE)) { | 
|---|
| 2477 | dprintf(("WARNING: SetWindowPos; unsupported flag")); | 
|---|
| 2478 | } | 
|---|
| 2479 |  | 
|---|
| 2480 | if(IsWindowDestroyed()) { | 
|---|
| 2481 | //changing the position of a window that's being destroyed can cause crashes in PMMERGE | 
|---|
| 2482 | dprintf(("SetWindowPos; window already destroyed")); | 
|---|
| 2483 | return TRUE; | 
|---|
| 2484 | } | 
|---|
| 2485 | #if 0 | 
|---|
| 2486 | /* Fix redundant flags */ | 
|---|
| 2487 | if(getStyle() & WS_VISIBLE) { | 
|---|
| 2488 | fuFlags &= ~SWP_SHOWWINDOW; | 
|---|
| 2489 | } | 
|---|
| 2490 | else | 
|---|
| 2491 | { | 
|---|
| 2492 | if (!(fuFlags & SWP_SHOWWINDOW)) | 
|---|
| 2493 | fuFlags |= SWP_NOREDRAW; | 
|---|
| 2494 | fuFlags &= ~SWP_HIDEWINDOW; | 
|---|
| 2495 | } | 
|---|
| 2496 |  | 
|---|
| 2497 | if(cx < 0) cx = 0; | 
|---|
| 2498 | if(cy < 0) cy = 0; | 
|---|
| 2499 |  | 
|---|
| 2500 | if((rectWindow.right - rectWindow.left == cx) && (rectWindow.bottom - rectWindow.top == cy)) { | 
|---|
| 2501 | fuFlags |= SWP_NOSIZE;    /* Already the right size */ | 
|---|
| 2502 | } | 
|---|
| 2503 |  | 
|---|
| 2504 | if((rectWindow.left == x) && (rectWindow.top == y)) { | 
|---|
| 2505 | fuFlags |= SWP_NOMOVE;    /* Already the right position */ | 
|---|
| 2506 | } | 
|---|
| 2507 |  | 
|---|
| 2508 | if(getWindowHandle() == GetActiveWindow()) { | 
|---|
| 2509 | fuFlags |= SWP_NOACTIVATE;   /* Already active */ | 
|---|
| 2510 | } | 
|---|
| 2511 | else | 
|---|
| 2512 | if((getStyle() & (WS_POPUP | WS_CHILD)) != WS_CHILD ) | 
|---|
| 2513 | { | 
|---|
| 2514 | if(!(fuFlags & SWP_NOACTIVATE)) /* Bring to the top when activating */ | 
|---|
| 2515 | { | 
|---|
| 2516 | fuFlags &= ~SWP_NOZORDER; | 
|---|
| 2517 | hwndInsertAfter = HWND_TOP; | 
|---|
| 2518 | } | 
|---|
| 2519 | } | 
|---|
| 2520 | #endif | 
|---|
| 2521 |  | 
|---|
| 2522 | //Note: Solitaire crashes when receiving WM_SIZE messages before WM_CREATE | 
|---|
| 2523 | if(state < STATE_POST_WMNCCREATE) | 
|---|
| 2524 | {//don't change size; modify internal structures only | 
|---|
| 2525 | //TODO: not 100% correct yet (activate) | 
|---|
| 2526 | dprintf2(("state < STATE_POST_WMNCCREATE")); | 
|---|
| 2527 | if(!(fuFlags & SWP_NOZORDER)) { | 
|---|
| 2528 | hwndLinkAfter = hwndInsertAfter; | 
|---|
| 2529 | } | 
|---|
| 2530 | if(!(fuFlags & SWP_NOMOVE)) { | 
|---|
| 2531 | rectWindow.bottom = (rectWindow.bottom - rectWindow.top) + y; | 
|---|
| 2532 | rectWindow.top    = y; | 
|---|
| 2533 | rectWindow.right  = (rectWindow.right - rectWindow.left) + x; | 
|---|
| 2534 | rectWindow.left   = x; | 
|---|
| 2535 | } | 
|---|
| 2536 | if(!(fuFlags & SWP_NOSIZE)) { | 
|---|
| 2537 | rectWindow.bottom = rectWindow.top + cy; | 
|---|
| 2538 | rectWindow.right  = rectWindow.left + cx; | 
|---|
| 2539 | } | 
|---|
| 2540 | return TRUE; | 
|---|
| 2541 | } | 
|---|
| 2542 |  | 
|---|
| 2543 | WINDOWPOS wpos; | 
|---|
| 2544 | SWP swp, swpOld; | 
|---|
| 2545 | wpos.flags            = fuFlags; | 
|---|
| 2546 | wpos.cy               = cy; | 
|---|
| 2547 | wpos.cx               = cx; | 
|---|
| 2548 | wpos.x                = x; | 
|---|
| 2549 | wpos.y                = y; | 
|---|
| 2550 | wpos.hwndInsertAfter  = hwndInsertAfter; | 
|---|
| 2551 | wpos.hwnd             = getWindowHandle(); | 
|---|
| 2552 |  | 
|---|
| 2553 | if(~fuFlags & (SWP_NOMOVE | SWP_NOSIZE)) | 
|---|
| 2554 | { | 
|---|
| 2555 | if (isChild()) | 
|---|
| 2556 | { | 
|---|
| 2557 | if(!getParent()) { | 
|---|
| 2558 | dprintf(("WARNING: Win32BaseWindow::SetWindowPos window %x is child but has no parent!!", getWindowHandle())); | 
|---|
| 2559 | } | 
|---|
| 2560 | } | 
|---|
| 2561 | OSLibWinQueryWindowPos(OS2HwndFrame, &swpOld); | 
|---|
| 2562 | } | 
|---|
| 2563 |  | 
|---|
| 2564 | if(getParent()) { | 
|---|
| 2565 | OSLibMapWINDOWPOStoSWP(&wpos, &swp, &swpOld, getParent()->getClientHeight(), | 
|---|
| 2566 | OS2HwndFrame); | 
|---|
| 2567 | } | 
|---|
| 2568 | else  OSLibMapWINDOWPOStoSWP(&wpos, &swp, &swpOld, OSLibQueryScreenHeight(), OS2HwndFrame); | 
|---|
| 2569 |  | 
|---|
| 2570 | if (swp.fl == 0) { | 
|---|
| 2571 | dprintf2(("swp.fl == 0")); | 
|---|
| 2572 | if(fuFlags & SWP_FRAMECHANGED) | 
|---|
| 2573 | { | 
|---|
| 2574 | NotifyFrameChanged(&wpos, &oldClientRect); | 
|---|
| 2575 | } | 
|---|
| 2576 | return TRUE; | 
|---|
| 2577 | } | 
|---|
| 2578 |  | 
|---|
| 2579 | //   if ((swp.fl & SWPOS_ZORDER) && (swp.hwndInsertBehind > HWNDOS_BOTTOM)) | 
|---|
| 2580 | if ((swp.hwndInsertBehind > HWNDOS_BOTTOM)) | 
|---|
| 2581 | { | 
|---|
| 2582 | Win32BaseWindow *wndBehind = Win32BaseWindow::GetWindowFromHandle(swp.hwndInsertBehind); | 
|---|
| 2583 | if(wndBehind) { | 
|---|
| 2584 | swp.hwndInsertBehind   = wndBehind->getOS2FrameWindowHandle(); | 
|---|
| 2585 | RELEASE_WNDOBJ(wndBehind); | 
|---|
| 2586 | } | 
|---|
| 2587 | else { | 
|---|
| 2588 | dprintf(("ERROR: SetWindowPos: hwndInsertBehind %x invalid!",swp.hwndInsertBehind)); | 
|---|
| 2589 | swp.hwndInsertBehind = 0; | 
|---|
| 2590 | } | 
|---|
| 2591 | } | 
|---|
| 2592 | swp.hwnd = OS2HwndFrame; | 
|---|
| 2593 |  | 
|---|
| 2594 | if(fuFlags & SWP_SHOWWINDOW && !IsWindowVisible(getWindowHandle())) { | 
|---|
| 2595 | setStyle(getStyle() | WS_VISIBLE); | 
|---|
| 2596 | if(hTaskList) { | 
|---|
| 2597 | dprintf(("Adding window %x to tasklist", getWindowHandle())); | 
|---|
| 2598 | OSLibWinChangeTaskList(hTaskList, OS2HwndFrame, getWindowNameA(), 1); | 
|---|
| 2599 | } | 
|---|
| 2600 | } | 
|---|
| 2601 | else | 
|---|
| 2602 | if((fuFlags & SWP_HIDEWINDOW) && IsWindowVisible(getWindowHandle())) { | 
|---|
| 2603 | setStyle(getStyle() & ~WS_VISIBLE); | 
|---|
| 2604 | if(hTaskList && !(getStyle() & WS_MINIMIZE)) { | 
|---|
| 2605 | dprintf(("Removing window %x from tasklist", getWindowHandle())); | 
|---|
| 2606 | OSLibWinChangeTaskList(hTaskList, OS2HwndFrame, getWindowNameA(), 0); | 
|---|
| 2607 | } | 
|---|
| 2608 | } | 
|---|
| 2609 | dprintf (("WinSetWindowPos %x %x (%d,%d)(%d,%d) %x", swp.hwnd, swp.hwndInsertBehind, swp.x, swp.y, swp.cx, swp.cy, swp.fl)); | 
|---|
| 2610 | rc = OSLibWinSetMultWindowPos(&swp, 1); | 
|---|
| 2611 |  | 
|---|
| 2612 | if(rc == FALSE) | 
|---|
| 2613 | { | 
|---|
| 2614 | dprintf(("OSLibWinSetMultWindowPos failed! Error %x",OSLibWinGetLastError())); | 
|---|
| 2615 | return 0; | 
|---|
| 2616 | } | 
|---|
| 2617 |  | 
|---|
| 2618 | if((fuFlags & SWP_FRAMECHANGED) && (fuFlags & (SWP_NOMOVE | SWP_NOSIZE) == (SWP_NOMOVE | SWP_NOSIZE))) | 
|---|
| 2619 | { | 
|---|
| 2620 | NotifyFrameChanged(&wpos, &oldClientRect); | 
|---|
| 2621 | } | 
|---|
| 2622 | return (rc); | 
|---|
| 2623 | } | 
|---|
| 2624 | //****************************************************************************** | 
|---|
| 2625 | //Called by ScrollWindowEx (dc.cpp) to notify child window that it has moved | 
|---|
| 2626 | //****************************************************************************** | 
|---|
| 2627 | BOOL Win32BaseWindow::ScrollWindow(int dx, int dy) | 
|---|
| 2628 | { | 
|---|
| 2629 | rectWindow.left   += dx; | 
|---|
| 2630 | rectWindow.right  += dx; | 
|---|
| 2631 | rectWindow.top    += dy; | 
|---|
| 2632 | rectWindow.bottom += dy; | 
|---|
| 2633 | SendInternalMessageA(WM_MOVE, 0, MAKELONG(rectClient.left, rectClient.top)); | 
|---|
| 2634 | return TRUE; | 
|---|
| 2635 | } | 
|---|
| 2636 | //****************************************************************************** | 
|---|
| 2637 | //****************************************************************************** | 
|---|
| 2638 | void Win32BaseWindow::NotifyFrameChanged(WINDOWPOS *wpos, RECT *oldClientRect) | 
|---|
| 2639 | { | 
|---|
| 2640 | HRGN hrgn, hrgnClient; | 
|---|
| 2641 | RECT rect; | 
|---|
| 2642 |  | 
|---|
| 2643 | MsgFormatFrame(NULL); | 
|---|
| 2644 |  | 
|---|
| 2645 | if(RECT_WIDTH(rectClient) != RECT_WIDTH(*oldClientRect) || | 
|---|
| 2646 | RECT_HEIGHT(rectClient) != RECT_HEIGHT(*oldClientRect)) | 
|---|
| 2647 | { | 
|---|
| 2648 | wpos->flags &= ~(SWP_NOSIZE|SWP_NOCLIENTSIZE); | 
|---|
| 2649 | wpos->cx     = RECT_WIDTH(rectWindow); | 
|---|
| 2650 | wpos->cy     = RECT_HEIGHT(rectWindow); | 
|---|
| 2651 | } | 
|---|
| 2652 |  | 
|---|
| 2653 | if(rectClient.left != oldClientRect->left || | 
|---|
| 2654 | rectClient.top != oldClientRect->top) | 
|---|
| 2655 | { | 
|---|
| 2656 | wpos->flags &= ~(SWP_NOMOVE|SWP_NOCLIENTMOVE); | 
|---|
| 2657 | wpos->x      = rectWindow.left; | 
|---|
| 2658 | wpos->y      = rectWindow.top; | 
|---|
| 2659 | } | 
|---|
| 2660 |  | 
|---|
| 2661 | WINDOWPOS wpOld = *wpos; | 
|---|
| 2662 | SendInternalMessageA(WM_WINDOWPOSCHANGING, 0, (LPARAM)wpos); | 
|---|
| 2663 |  | 
|---|
| 2664 | if ((wpos->hwndInsertAfter != wpOld.hwndInsertAfter) || | 
|---|
| 2665 | (wpos->x != wpOld.x) || (wpos->y != wpOld.y) || (wpos->cx != wpOld.cx) || (wpos->cy != wpOld.cy) || (wpos->flags != wpOld.flags)) | 
|---|
| 2666 | { | 
|---|
| 2667 | dprintf(("WARNING, NotifyFrameChanged: TODO -> adjust flags!!!!")); | 
|---|
| 2668 | SetWindowPos(wpos->hwndInsertAfter, wpos->x, wpos->y, wpos->cx, wpos->cy, wpos->flags | SWP_NOSENDCHANGING); | 
|---|
| 2669 | } | 
|---|
| 2670 | else SendInternalMessageA(WM_WINDOWPOSCHANGED, 0, (LPARAM)wpos); | 
|---|
| 2671 |  | 
|---|
| 2672 | //Calculate invalid areas | 
|---|
| 2673 | rect = rectWindow; | 
|---|
| 2674 | OffsetRect(&rect, -rectWindow.left, -rectWindow.top); | 
|---|
| 2675 | hrgn = CreateRectRgnIndirect(&rect); | 
|---|
| 2676 | if (!hrgn) { | 
|---|
| 2677 | dprintf(("ERROR: NotifyFrameChanged, CreateRectRgnIndirect failed!!")); | 
|---|
| 2678 | return; | 
|---|
| 2679 | } | 
|---|
| 2680 | rect = rectClient; | 
|---|
| 2681 | hrgnClient = CreateRectRgnIndirect(&rect); | 
|---|
| 2682 | if (!hrgn) { | 
|---|
| 2683 | dprintf(("ERROR: NotifyFrameChanged, CreateRectRgnIndirect failed!!")); | 
|---|
| 2684 | return; | 
|---|
| 2685 | } | 
|---|
| 2686 | CombineRgn(hrgn, hrgn, hrgnClient, RGN_DIFF); | 
|---|
| 2687 | DeleteObject(hrgnClient); | 
|---|
| 2688 |  | 
|---|
| 2689 | if(!EqualRect(oldClientRect, &rectClient)) { | 
|---|
| 2690 | UnionRect(oldClientRect, oldClientRect, &rectClient); | 
|---|
| 2691 | hrgnClient = CreateRectRgnIndirect(oldClientRect); | 
|---|
| 2692 | if (!hrgn) { | 
|---|
| 2693 | dprintf(("ERROR: NotifyFrameChanged, CreateRectRgnIndirect failed!!")); | 
|---|
| 2694 | return; | 
|---|
| 2695 | } | 
|---|
| 2696 | CombineRgn(hrgn, hrgn, hrgnClient, RGN_OR); | 
|---|
| 2697 | DeleteObject(hrgnClient); | 
|---|
| 2698 | } | 
|---|
| 2699 | RedrawWindow(getWindowHandle(), NULL, hrgn, RDW_ALLCHILDREN | | 
|---|
| 2700 | RDW_INVALIDATE | RDW_ERASE | RDW_FRAME); | 
|---|
| 2701 | DeleteObject(hrgn); | 
|---|
| 2702 | } | 
|---|
| 2703 | //****************************************************************************** | 
|---|
| 2704 | //TODO: Check how this api really works in NT | 
|---|
| 2705 | //****************************************************************************** | 
|---|
| 2706 | BOOL Win32BaseWindow::SetWindowPlacement(WINDOWPLACEMENT *wndpl) | 
|---|
| 2707 | { | 
|---|
| 2708 | dprintf(("SetWindowPlacement %x min  (%d,%d)", getWindowHandle(), wndpl->ptMinPosition.x, wndpl->ptMinPosition.y)); | 
|---|
| 2709 | dprintf(("SetWindowPlacement %x max  (%d,%d)", getWindowHandle(), wndpl->ptMaxPosition.x, wndpl->ptMaxPosition.y)); | 
|---|
| 2710 | dprintf(("SetWindowPlacement %x norm (%d,%d)(%d,%d)", getWindowHandle(), wndpl->rcNormalPosition.left, wndpl->rcNormalPosition.top, wndpl->rcNormalPosition.right, wndpl->rcNormalPosition.bottom)); | 
|---|
| 2711 | windowpos.ptMinPosition    = wndpl->ptMinPosition; | 
|---|
| 2712 | windowpos.ptMaxPosition    = wndpl->ptMaxPosition; | 
|---|
| 2713 | windowpos.rcNormalPosition = wndpl->rcNormalPosition; | 
|---|
| 2714 |  | 
|---|
| 2715 | if(getStyle() & WS_MINIMIZE ) | 
|---|
| 2716 | { | 
|---|
| 2717 | //TODO: Why can't this be (0,0)? | 
|---|
| 2718 | if(wndpl->flags & WPF_SETMINPOSITION && !(!windowpos.ptMinPosition.x && !windowpos.ptMinPosition.y)) { | 
|---|
| 2719 | SetWindowPos(0, windowpos.ptMinPosition.x, windowpos.ptMinPosition.y, | 
|---|
| 2720 | 0, 0, SWP_NOSIZE | SWP_NOZORDER | SWP_NOACTIVATE); | 
|---|
| 2721 | } | 
|---|
| 2722 | } | 
|---|
| 2723 | else | 
|---|
| 2724 | if(getStyle() & WS_MAXIMIZE ) | 
|---|
| 2725 | { | 
|---|
| 2726 | //TODO: Why can't this be (0,0)? | 
|---|
| 2727 | if(windowpos.ptMaxPosition.x != 0 || windowpos.ptMaxPosition.y != 0 ) | 
|---|
| 2728 | SetWindowPos(0, windowpos.ptMaxPosition.x, windowpos.ptMaxPosition.y, | 
|---|
| 2729 | 0, 0, SWP_NOSIZE | SWP_NOZORDER | SWP_NOACTIVATE); | 
|---|
| 2730 | } | 
|---|
| 2731 | else { | 
|---|
| 2732 | SetWindowPos(0, windowpos.rcNormalPosition.left, windowpos.rcNormalPosition.top, | 
|---|
| 2733 | windowpos.rcNormalPosition.right - windowpos.rcNormalPosition.left, | 
|---|
| 2734 | windowpos.rcNormalPosition.bottom - windowpos.rcNormalPosition.top, | 
|---|
| 2735 | SWP_NOZORDER | SWP_NOACTIVATE ); | 
|---|
| 2736 | } | 
|---|
| 2737 | ShowWindow(wndpl->showCmd); | 
|---|
| 2738 | if( ::IsWindow(getWindowHandle()) && getStyle() & WS_MINIMIZE ) | 
|---|
| 2739 | { | 
|---|
| 2740 | /* SDK: ...valid only the next time... */ | 
|---|
| 2741 | if(wndpl->flags & WPF_RESTORETOMAXIMIZED) | 
|---|
| 2742 | setFlags(getFlags() | WIN_RESTORE_MAX); | 
|---|
| 2743 | } | 
|---|
| 2744 | return TRUE; | 
|---|
| 2745 | } | 
|---|
| 2746 | //****************************************************************************** | 
|---|
| 2747 | //****************************************************************************** | 
|---|
| 2748 | BOOL Win32BaseWindow::GetWindowPlacement(LPWINDOWPLACEMENT wndpl) | 
|---|
| 2749 | { | 
|---|
| 2750 | wndpl->length = sizeof(*wndpl); | 
|---|
| 2751 | if(getStyle() & WS_MINIMIZE ) | 
|---|
| 2752 | wndpl->showCmd = SW_SHOWMINIMIZED; | 
|---|
| 2753 | else wndpl->showCmd = (getStyle() & WS_MAXIMIZE) ? SW_SHOWMAXIMIZED : SW_SHOWNORMAL; | 
|---|
| 2754 |  | 
|---|
| 2755 | //TODO: Verify if this is correct -> SDK docs claim this flag must always be set to 0 | 
|---|
| 2756 | if(getFlags() & WIN_RESTORE_MAX ) | 
|---|
| 2757 | wndpl->flags = WPF_RESTORETOMAXIMIZED; | 
|---|
| 2758 | else wndpl->flags = 0; | 
|---|
| 2759 |  | 
|---|
| 2760 | wndpl->ptMinPosition    = windowpos.ptMinPosition; | 
|---|
| 2761 | wndpl->ptMaxPosition    = windowpos.ptMaxPosition; | 
|---|
| 2762 | //Must be in parent coordinates (or screen if no parent); verified in NT4, SP6 | 
|---|
| 2763 | wndpl->rcNormalPosition = rectWindow; | 
|---|
| 2764 |  | 
|---|
| 2765 | return TRUE; | 
|---|
| 2766 | } | 
|---|
| 2767 | //****************************************************************************** | 
|---|
| 2768 | //Also destroys all the child windows (destroy children first, parent last) | 
|---|
| 2769 | //****************************************************************************** | 
|---|
| 2770 | BOOL Win32BaseWindow::DestroyWindow() | 
|---|
| 2771 | { | 
|---|
| 2772 | HWND hwnd = getWindowHandle(); | 
|---|
| 2773 |  | 
|---|
| 2774 | dprintf(("DestroyWindow %x", hwnd)); | 
|---|
| 2775 |  | 
|---|
| 2776 | /* Call hooks */ | 
|---|
| 2777 | if(HOOK_CallHooksA( WH_CBT, HCBT_DESTROYWND, getWindowHandle(), 0L)) | 
|---|
| 2778 | { | 
|---|
| 2779 | return FALSE; | 
|---|
| 2780 | } | 
|---|
| 2781 |  | 
|---|
| 2782 | if(!(getStyle() & WS_CHILD) && getOwner() == NULL) | 
|---|
| 2783 | { | 
|---|
| 2784 | HOOK_CallHooksA(WH_SHELL, HSHELL_WINDOWDESTROYED, getWindowHandle(), 0L); | 
|---|
| 2785 | /* FIXME: clean up palette - see "Internals" p.352 */ | 
|---|
| 2786 | } | 
|---|
| 2787 |  | 
|---|
| 2788 | if((getStyle() & WS_CHILD) && !(getExStyle() & WS_EX_NOPARENTNOTIFY)) | 
|---|
| 2789 | { | 
|---|
| 2790 | if(getParent() && getParent()->IsWindowDestroyed() == FALSE) | 
|---|
| 2791 | { | 
|---|
| 2792 | /* Notify the parent window only */ | 
|---|
| 2793 | getParent()->SendMessageA(WM_PARENTNOTIFY, MAKEWPARAM(WM_DESTROY, getWindowId()), (LPARAM)getWindowHandle()); | 
|---|
| 2794 | if(!::IsWindow(hwnd) ) | 
|---|
| 2795 | { | 
|---|
| 2796 | return TRUE; | 
|---|
| 2797 | } | 
|---|
| 2798 | } | 
|---|
| 2799 | ////        else DebugInt3(); | 
|---|
| 2800 | } | 
|---|
| 2801 | /* Hide the window */ | 
|---|
| 2802 | if(IsWindowVisible(getWindowHandle())) | 
|---|
| 2803 | { | 
|---|
| 2804 | SetWindowPos(0, 0, 0, 0, 0, SWP_HIDEWINDOW | | 
|---|
| 2805 | SWP_NOACTIVATE|SWP_NOZORDER|SWP_NOMOVE|SWP_NOSIZE); | 
|---|
| 2806 | if(!::IsWindow(hwnd)) | 
|---|
| 2807 | { | 
|---|
| 2808 | return TRUE; | 
|---|
| 2809 | } | 
|---|
| 2810 | } | 
|---|
| 2811 | dprintf(("DestroyWindow %x -> HIDDEN", hwnd)); | 
|---|
| 2812 |  | 
|---|
| 2813 | // check the handle for the last active popup window | 
|---|
| 2814 | Win32BaseWindow* owner = getOwner(); | 
|---|
| 2815 | if (NULL != owner) | 
|---|
| 2816 | { | 
|---|
| 2817 | if (owner->getLastActive() == hwnd) | 
|---|
| 2818 | owner->setLastActive( owner->getWindowHandle() ); | 
|---|
| 2819 | } | 
|---|
| 2820 |  | 
|---|
| 2821 | fDestroyWindowCalled = TRUE; | 
|---|
| 2822 | return OSLibWinDestroyWindow(OS2HwndFrame); | 
|---|
| 2823 | } | 
|---|
| 2824 | //****************************************************************************** | 
|---|
| 2825 | //****************************************************************************** | 
|---|
| 2826 | Win32BaseWindow *Win32BaseWindow::getParent() | 
|---|
| 2827 | { | 
|---|
| 2828 | Win32BaseWindow *wndparent = (Win32BaseWindow *)ChildWindow::getParentOfChild(); | 
|---|
| 2829 | return ((ULONG)wndparent == (ULONG)windowDesktop) ? NULL : wndparent; | 
|---|
| 2830 | } | 
|---|
| 2831 | //****************************************************************************** | 
|---|
| 2832 | //Note: does not set last error if no parent (verified in NT4, SP6) | 
|---|
| 2833 | //****************************************************************************** | 
|---|
| 2834 | HWND Win32BaseWindow::GetParent() | 
|---|
| 2835 | { | 
|---|
| 2836 | if((!(getStyle() & (WS_POPUP|WS_CHILD)))) { | 
|---|
| 2837 | return 0; | 
|---|
| 2838 | } | 
|---|
| 2839 |  | 
|---|
| 2840 | Win32BaseWindow *wndparent = (Win32BaseWindow *)ChildWindow::getParentOfChild(); | 
|---|
| 2841 |  | 
|---|
| 2842 | if(getStyle() & WS_CHILD) { | 
|---|
| 2843 | if(wndparent) { | 
|---|
| 2844 | return wndparent->getWindowHandle(); | 
|---|
| 2845 | } | 
|---|
| 2846 | dprintf(("WARNING: GetParent: WS_CHILD but no parent!!")); | 
|---|
| 2847 | DebugInt3(); | 
|---|
| 2848 | return 0; | 
|---|
| 2849 | } | 
|---|
| 2850 | else  return (getOwner()) ? getOwner()->getWindowHandle() : 0; | 
|---|
| 2851 | } | 
|---|
| 2852 | //****************************************************************************** | 
|---|
| 2853 | //****************************************************************************** | 
|---|
| 2854 | HWND Win32BaseWindow::SetParent(HWND hwndNewParent) | 
|---|
| 2855 | { | 
|---|
| 2856 | HWND oldhwnd; | 
|---|
| 2857 | Win32BaseWindow *newparent; | 
|---|
| 2858 | Win32BaseWindow *oldparent = (Win32BaseWindow *)ChildWindow::getParentOfChild(); | 
|---|
| 2859 | BOOL fShow = FALSE; | 
|---|
| 2860 |  | 
|---|
| 2861 | if(oldparent) { | 
|---|
| 2862 | oldhwnd = oldparent->getWindowHandle(); | 
|---|
| 2863 | oldparent->removeChild(this); | 
|---|
| 2864 | } | 
|---|
| 2865 | else oldhwnd = 0; | 
|---|
| 2866 |  | 
|---|
| 2867 | /* Windows hides the window first, then shows it again | 
|---|
| 2868 | * including the WM_SHOWWINDOW messages and all */ | 
|---|
| 2869 | if(IsWindowCreated() && (getStyle() & WS_VISIBLE)) { | 
|---|
| 2870 | ShowWindow(SW_HIDE); | 
|---|
| 2871 | fShow = TRUE; | 
|---|
| 2872 | } | 
|---|
| 2873 | if(oldparent) { | 
|---|
| 2874 | //release parent here (increased refcount during creation) | 
|---|
| 2875 | RELEASE_WNDOBJ(oldparent); | 
|---|
| 2876 | } | 
|---|
| 2877 | newparent = GetWindowFromHandle(hwndNewParent); | 
|---|
| 2878 | if(newparent && !newparent->isDesktopWindow()) | 
|---|
| 2879 | { | 
|---|
| 2880 | setParent(newparent); | 
|---|
| 2881 | getParent()->addChild(this); | 
|---|
| 2882 | fParentChange = TRUE; | 
|---|
| 2883 |  | 
|---|
| 2884 | OSLibWinSetParent(getOS2FrameWindowHandle(), getParent()->getOS2WindowHandle()); | 
|---|
| 2885 | if(!(getStyle() & WS_CHILD)) | 
|---|
| 2886 | { | 
|---|
| 2887 | //TODO: Send WM_STYLECHANGED msg? | 
|---|
| 2888 | setStyle(getStyle() | WS_CHILD); | 
|---|
| 2889 | if(getWindowId()) | 
|---|
| 2890 | { | 
|---|
| 2891 | DestroyMenu( (HMENU) getWindowId() ); | 
|---|
| 2892 | setWindowId(0); | 
|---|
| 2893 | } | 
|---|
| 2894 | } | 
|---|
| 2895 | //SvL: Even though the win32 coordinates might not change, the PM | 
|---|
| 2896 | //     coordinates can. We must make sure the control stays at the | 
|---|
| 2897 | //     same position (y) relative to the (new) parent. | 
|---|
| 2898 | SetWindowPos(HWND_TOPMOST, rectWindow.left, rectWindow.top, 0, 0, | 
|---|
| 2899 | SWP_NOACTIVATE|SWP_NOSIZE); | 
|---|
| 2900 | fParentChange = FALSE; | 
|---|
| 2901 | } | 
|---|
| 2902 | else { | 
|---|
| 2903 | if(newparent) RELEASE_WNDOBJ(newparent); | 
|---|
| 2904 |  | 
|---|
| 2905 | setParent(windowDesktop); | 
|---|
| 2906 | windowDesktop->addRef(); | 
|---|
| 2907 | windowDesktop->addChild(this); | 
|---|
| 2908 | OSLibWinSetParent(getOS2FrameWindowHandle(), OSLIB_HWND_DESKTOP); | 
|---|
| 2909 |  | 
|---|
| 2910 | //TODO: Send WM_STYLECHANGED msg? | 
|---|
| 2911 | setStyle(getStyle() & ~WS_CHILD); | 
|---|
| 2912 | setWindowId(0); | 
|---|
| 2913 | } | 
|---|
| 2914 | /* SetParent additionally needs to make hwndChild the topmost window | 
|---|
| 2915 | in the x-order and send the expected WM_WINDOWPOSCHANGING and | 
|---|
| 2916 | WM_WINDOWPOSCHANGED notification messages. | 
|---|
| 2917 | */ | 
|---|
| 2918 | if(state >= STATE_PRE_WMNCCREATE) { | 
|---|
| 2919 | SetWindowPos(HWND_TOPMOST, 0, 0, 0, 0, | 
|---|
| 2920 | SWP_NOACTIVATE|SWP_NOMOVE|SWP_NOSIZE|(fShow? SWP_SHOWWINDOW : 0)); | 
|---|
| 2921 |  | 
|---|
| 2922 | /* FIXME: a WM_MOVE is also generated (in the DefWindowProc handler | 
|---|
| 2923 | * for WM_WINDOWPOSCHANGED) in Windows, should probably remove SWP_NOMOVE */ | 
|---|
| 2924 | } | 
|---|
| 2925 | return oldhwnd; | 
|---|
| 2926 | } | 
|---|
| 2927 | //****************************************************************************** | 
|---|
| 2928 | //****************************************************************************** | 
|---|
| 2929 | BOOL Win32BaseWindow::IsChild(HWND hwndParent) | 
|---|
| 2930 | { | 
|---|
| 2931 | // PH: Optimizer won't unroll calls to getParent() even | 
|---|
| 2932 | // in release build. | 
|---|
| 2933 | Win32BaseWindow *_parent = getParent(); | 
|---|
| 2934 |  | 
|---|
| 2935 | if(_parent) | 
|---|
| 2936 | { | 
|---|
| 2937 | if(_parent->getWindowHandle() == hwndParent) | 
|---|
| 2938 | return TRUE; | 
|---|
| 2939 |  | 
|---|
| 2940 | return _parent->IsChild(hwndParent); | 
|---|
| 2941 | } | 
|---|
| 2942 | else | 
|---|
| 2943 | return 0; | 
|---|
| 2944 | } | 
|---|
| 2945 | //****************************************************************************** | 
|---|
| 2946 | //****************************************************************************** | 
|---|
| 2947 | HWND Win32BaseWindow::GetTopWindow() | 
|---|
| 2948 | { | 
|---|
| 2949 | HWND             hwndTop; | 
|---|
| 2950 | Win32BaseWindow *topwindow; | 
|---|
| 2951 |  | 
|---|
| 2952 | hwndTop = OSLibWinQueryWindow(getOS2WindowHandle(), QWOS_TOP); | 
|---|
| 2953 | if(!isDesktopWindow()) | 
|---|
| 2954 | { | 
|---|
| 2955 | topwindow = GetWindowFromOS2FrameHandle(hwndTop); | 
|---|
| 2956 | //Note: GetTopWindow can't return a window that hasn't processed | 
|---|
| 2957 | //      WM_NCCREATE yet (verified in NT4, SP6) | 
|---|
| 2958 | if(topwindow) { | 
|---|
| 2959 | if(topwindow->state >= STATE_POST_WMNCCREATE) { | 
|---|
| 2960 | hwndTop = topwindow->getWindowHandle(); | 
|---|
| 2961 | } | 
|---|
| 2962 | else hwndTop = topwindow->GetWindow(GW_HWNDNEXT); | 
|---|
| 2963 | RELEASE_WNDOBJ(topwindow); | 
|---|
| 2964 | return hwndTop; | 
|---|
| 2965 | } | 
|---|
| 2966 | if(topwindow) RELEASE_WNDOBJ(topwindow); | 
|---|
| 2967 | return 0; | 
|---|
| 2968 | } | 
|---|
| 2969 | while(hwndTop) { | 
|---|
| 2970 | topwindow = GetWindowFromOS2FrameHandle(hwndTop); | 
|---|
| 2971 | //Note: GetTopWindow can't return a window that hasn't processed | 
|---|
| 2972 | //      WM_NCCREATE yet (verified in NT4, SP6) | 
|---|
| 2973 | if(topwindow) { | 
|---|
| 2974 | if(topwindow->state >= STATE_POST_WMNCCREATE) { | 
|---|
| 2975 | hwndTop = topwindow->getWindowHandle(); | 
|---|
| 2976 | } | 
|---|
| 2977 | else hwndTop = topwindow->GetWindow(GW_HWNDNEXT); | 
|---|
| 2978 | RELEASE_WNDOBJ(topwindow); | 
|---|
| 2979 | return hwndTop; | 
|---|
| 2980 | } | 
|---|
| 2981 | if(topwindow) RELEASE_WNDOBJ(topwindow); | 
|---|
| 2982 | hwndTop = OSLibWinQueryWindow(hwndTop, QWOS_NEXT); | 
|---|
| 2983 | } | 
|---|
| 2984 |  | 
|---|
| 2985 | return 0; | 
|---|
| 2986 | } | 
|---|
| 2987 | //****************************************************************************** | 
|---|
| 2988 | // Get the top-level parent for a child window. | 
|---|
| 2989 | //****************************************************************************** | 
|---|
| 2990 | HWND Win32BaseWindow::GetTopParent() | 
|---|
| 2991 | { | 
|---|
| 2992 | Win32BaseWindow *window = this; | 
|---|
| 2993 | HWND             hwndTopParent = 0; | 
|---|
| 2994 |  | 
|---|
| 2995 | lock(); | 
|---|
| 2996 | while(window && (window->getStyle() & WS_CHILD)) | 
|---|
| 2997 | { | 
|---|
| 2998 | window = window->getParent(); | 
|---|
| 2999 | } | 
|---|
| 3000 | if(window) { | 
|---|
| 3001 | hwndTopParent = window->getWindowHandle(); | 
|---|
| 3002 | } | 
|---|
| 3003 | unlock(); | 
|---|
| 3004 | return hwndTopParent; | 
|---|
| 3005 | } | 
|---|
| 3006 | //****************************************************************************** | 
|---|
| 3007 | //TODO: Should not enumerate children that are created during the enumeration! | 
|---|
| 3008 | //****************************************************************************** | 
|---|
| 3009 | BOOL Win32BaseWindow::EnumChildWindows(WNDENUMPROC lpfn, LPARAM lParam) | 
|---|
| 3010 | { | 
|---|
| 3011 | BOOL rc = TRUE; | 
|---|
| 3012 | HWND hwnd; | 
|---|
| 3013 | Win32BaseWindow *prevchild = 0, *child = 0; | 
|---|
| 3014 |  | 
|---|
| 3015 | dprintf(("EnumChildWindows of %x parameter %x %x (%x)", getWindowHandle(), lpfn, lParam, getFirstChild())); | 
|---|
| 3016 | lock(); | 
|---|
| 3017 | for (child = (Win32BaseWindow *)getFirstChild(); child; child = (Win32BaseWindow *)child->getNextChild()) | 
|---|
| 3018 | { | 
|---|
| 3019 | dprintf(("EnumChildWindows: enumerating child %x (owner %x; parent %x)", child->getWindowHandle(), (child->getOwner()) ? child->getOwner()->getWindowHandle() : 0, getWindowHandle())); | 
|---|
| 3020 | hwnd = child->getWindowHandle(); | 
|---|
| 3021 | if(child->IsWindowDestroyed() || child->getOwner()) { | 
|---|
| 3022 | continue; //shouldn't have an owner (Wine) | 
|---|
| 3023 | } | 
|---|
| 3024 | child->addRef(); | 
|---|
| 3025 | unlock(); | 
|---|
| 3026 | if(lpfn(hwnd, lParam) == FALSE) | 
|---|
| 3027 | { | 
|---|
| 3028 | child->release(); | 
|---|
| 3029 | return FALSE; | 
|---|
| 3030 | } | 
|---|
| 3031 | child->release(); | 
|---|
| 3032 | lock(); | 
|---|
| 3033 | //check if the window still exists | 
|---|
| 3034 | if(!::IsWindow(hwnd)) | 
|---|
| 3035 | { | 
|---|
| 3036 | child = prevchild; | 
|---|
| 3037 | continue; | 
|---|
| 3038 | } | 
|---|
| 3039 | if(child->getFirstChild() != NULL) | 
|---|
| 3040 | { | 
|---|
| 3041 | dprintf(("EnumChildWindows: Enumerate children of %x", child->getWindowHandle())); | 
|---|
| 3042 | child->addRef(); | 
|---|
| 3043 | unlock(); | 
|---|
| 3044 | if(child->EnumChildWindows(lpfn, lParam) == FALSE) | 
|---|
| 3045 | { | 
|---|
| 3046 | child->release(); | 
|---|
| 3047 | return FALSE; | 
|---|
| 3048 | } | 
|---|
| 3049 | child->release(); | 
|---|
| 3050 | lock(); | 
|---|
| 3051 | } | 
|---|
| 3052 | prevchild = child; | 
|---|
| 3053 | } | 
|---|
| 3054 | unlock(); | 
|---|
| 3055 | return rc; | 
|---|
| 3056 | } | 
|---|
| 3057 | //****************************************************************************** | 
|---|
| 3058 | //Enumerate first-level children only and check thread id | 
|---|
| 3059 | //****************************************************************************** | 
|---|
| 3060 | BOOL Win32BaseWindow::EnumThreadWindows(DWORD dwThreadId, WNDENUMPROC lpfn, LPARAM lParam) | 
|---|
| 3061 | { | 
|---|
| 3062 | Win32BaseWindow *child = 0; | 
|---|
| 3063 | ULONG  tid, pid; | 
|---|
| 3064 | BOOL   rc; | 
|---|
| 3065 | HWND   hwnd; | 
|---|
| 3066 |  | 
|---|
| 3067 | dprintf(("EnumThreadWindows %x %x %x", dwThreadId, lpfn, lParam)); | 
|---|
| 3068 |  | 
|---|
| 3069 | for (child = (Win32BaseWindow *)getFirstChild(); child; child = (Win32BaseWindow *)child->getNextChild()) | 
|---|
| 3070 | { | 
|---|
| 3071 | OSLibWinQueryWindowProcess(child->getOS2WindowHandle(), &pid, &tid); | 
|---|
| 3072 |  | 
|---|
| 3073 | if(dwThreadId == tid) { | 
|---|
| 3074 | dprintf2(("EnumThreadWindows: Found Window %x", child->getWindowHandle())); | 
|---|
| 3075 | if((rc = lpfn(child->getWindowHandle(), lParam)) == FALSE) { | 
|---|
| 3076 | break; | 
|---|
| 3077 | } | 
|---|
| 3078 | } | 
|---|
| 3079 | } | 
|---|
| 3080 | return TRUE; | 
|---|
| 3081 | } | 
|---|
| 3082 | //****************************************************************************** | 
|---|
| 3083 | //Enumerate first-level children only | 
|---|
| 3084 | //****************************************************************************** | 
|---|
| 3085 | BOOL Win32BaseWindow::EnumWindows(WNDENUMPROC lpfn, LPARAM lParam) | 
|---|
| 3086 | { | 
|---|
| 3087 | Win32BaseWindow *child = 0; | 
|---|
| 3088 | BOOL   rc; | 
|---|
| 3089 | HWND   hwnd; | 
|---|
| 3090 |  | 
|---|
| 3091 | dprintf(("EnumWindows %x %x", lpfn, lParam)); | 
|---|
| 3092 |  | 
|---|
| 3093 | for (child = (Win32BaseWindow *)getFirstChild(); child; child = (Win32BaseWindow *)child->getNextChild()) | 
|---|
| 3094 | { | 
|---|
| 3095 | hwnd = child->getWindowHandle(); | 
|---|
| 3096 |  | 
|---|
| 3097 | dprintf2(("EnumWindows: Found Window %x", child->getWindowHandle())); | 
|---|
| 3098 | if((rc = lpfn(child->getWindowHandle(), lParam)) == FALSE) { | 
|---|
| 3099 | break; | 
|---|
| 3100 | } | 
|---|
| 3101 | } | 
|---|
| 3102 | return TRUE; | 
|---|
| 3103 | } | 
|---|
| 3104 | //****************************************************************************** | 
|---|
| 3105 | //****************************************************************************** | 
|---|
| 3106 | HWND Win32BaseWindow::FindWindowById(int id) | 
|---|
| 3107 | { | 
|---|
| 3108 | HWND hwnd; | 
|---|
| 3109 |  | 
|---|
| 3110 | lock(); | 
|---|
| 3111 | for (Win32BaseWindow *child = (Win32BaseWindow *)getFirstChild(); child; child = (Win32BaseWindow *)child->getNextChild()) | 
|---|
| 3112 | { | 
|---|
| 3113 | if (child->getWindowId() == id) | 
|---|
| 3114 | { | 
|---|
| 3115 | hwnd = child->getWindowHandle(); | 
|---|
| 3116 | unlock(); | 
|---|
| 3117 | return hwnd; | 
|---|
| 3118 | } | 
|---|
| 3119 | } | 
|---|
| 3120 | unlock(); | 
|---|
| 3121 | return 0; | 
|---|
| 3122 | } | 
|---|
| 3123 | //****************************************************************************** | 
|---|
| 3124 | //TODO: | 
|---|
| 3125 | //We assume (for now) that if hwndParent or hwndChildAfter are real window handles, that | 
|---|
| 3126 | //the current process owns them. | 
|---|
| 3127 | //****************************************************************************** | 
|---|
| 3128 | HWND Win32BaseWindow::FindWindowEx(HWND hwndParent, HWND hwndChildAfter, ATOM atom, LPSTR lpszWindow) | 
|---|
| 3129 | { | 
|---|
| 3130 | Win32BaseWindow *parent = GetWindowFromHandle(hwndParent); | 
|---|
| 3131 | Win32BaseWindow *child  = GetWindowFromHandle(hwndChildAfter); | 
|---|
| 3132 | Win32BaseWindow *firstchild = child; | 
|---|
| 3133 |  | 
|---|
| 3134 | dprintf(("FindWindowEx %x %x %x %s", hwndParent, hwndChildAfter, atom, lpszWindow)); | 
|---|
| 3135 | if((hwndParent != 0 && !parent) || | 
|---|
| 3136 | (hwndChildAfter != 0 && !child) || | 
|---|
| 3137 | (hwndParent == 0 && hwndChildAfter != 0)) | 
|---|
| 3138 | { | 
|---|
| 3139 | if(parent)      RELEASE_WNDOBJ(parent); | 
|---|
| 3140 | if(firstchild)  RELEASE_WNDOBJ(firstchild); | 
|---|
| 3141 | dprintf(("Win32BaseWindow::FindWindowEx: parent or child not found %x %x", hwndParent, hwndChildAfter)); | 
|---|
| 3142 | SetLastError(ERROR_INVALID_WINDOW_HANDLE); | 
|---|
| 3143 | return 0; | 
|---|
| 3144 | } | 
|---|
| 3145 | SetLastError(0); | 
|---|
| 3146 | if(hwndParent != 0) | 
|---|
| 3147 | {//if the current process owns the window, just do a quick search | 
|---|
| 3148 | lock(&critsect); | 
|---|
| 3149 | child = (Win32BaseWindow *)parent->getFirstChild(); | 
|---|
| 3150 | if(hwndChildAfter != 0) | 
|---|
| 3151 | { | 
|---|
| 3152 | while(child) | 
|---|
| 3153 | { | 
|---|
| 3154 | if(child->getWindowHandle() == hwndChildAfter) | 
|---|
| 3155 | { | 
|---|
| 3156 | child = (Win32BaseWindow *)child->getNextChild(); | 
|---|
| 3157 | break; | 
|---|
| 3158 | } | 
|---|
| 3159 | child = (Win32BaseWindow *)child->getNextChild(); | 
|---|
| 3160 | } | 
|---|
| 3161 | } | 
|---|
| 3162 | while(child) | 
|---|
| 3163 | { | 
|---|
| 3164 | //According to Wine, the class doesn't need to be specified | 
|---|
| 3165 | if((!atom || child->getWindowClass()->getAtom() == atom) && | 
|---|
| 3166 | (!lpszWindow || child->hasWindowName(lpszWindow))) | 
|---|
| 3167 | { | 
|---|
| 3168 | dprintf(("FindWindowEx: Found window %x", child->getWindowHandle())); | 
|---|
| 3169 | HWND hwndChild = child->getWindowHandle(); | 
|---|
| 3170 | unlock(&critsect); | 
|---|
| 3171 | if(parent)      RELEASE_WNDOBJ(parent); | 
|---|
| 3172 | if(firstchild)  RELEASE_WNDOBJ(firstchild); | 
|---|
| 3173 | dprintf(("FindWindowEx: Found window %x", child->getWindowHandle())); | 
|---|
| 3174 | return hwndChild; | 
|---|
| 3175 | } | 
|---|
| 3176 | child = (Win32BaseWindow *)child->getNextChild(); | 
|---|
| 3177 | } | 
|---|
| 3178 | unlock(&critsect); | 
|---|
| 3179 | if(parent)      RELEASE_WNDOBJ(parent); | 
|---|
| 3180 | if(firstchild)  RELEASE_WNDOBJ(firstchild); | 
|---|
| 3181 | } | 
|---|
| 3182 | else { | 
|---|
| 3183 | Win32BaseWindow *wnd; | 
|---|
| 3184 | HWND henum, hwnd; | 
|---|
| 3185 |  | 
|---|
| 3186 | henum = OSLibWinBeginEnumWindows(OSLIB_HWND_DESKTOP); | 
|---|
| 3187 | hwnd = OSLibWinGetNextWindow(henum); | 
|---|
| 3188 |  | 
|---|
| 3189 | while(hwnd) | 
|---|
| 3190 | { | 
|---|
| 3191 | wnd = GetWindowFromOS2FrameHandle(hwnd); | 
|---|
| 3192 | if(wnd == NULL) { | 
|---|
| 3193 | hwnd = OSLibWinQueryClientWindow(hwnd); | 
|---|
| 3194 | if(hwnd)  wnd = GetWindowFromOS2Handle(hwnd); | 
|---|
| 3195 | } | 
|---|
| 3196 |  | 
|---|
| 3197 | if(wnd) { | 
|---|
| 3198 | //According to Wine, the class doesn't need to be specified | 
|---|
| 3199 | if((!atom || wnd->getWindowClass()->getAtom() == atom) && | 
|---|
| 3200 | (!lpszWindow || wnd->hasWindowName(lpszWindow))) | 
|---|
| 3201 | { | 
|---|
| 3202 | OSLibWinEndEnumWindows(henum); | 
|---|
| 3203 | dprintf(("FindWindowEx: Found window %x", wnd->getWindowHandle())); | 
|---|
| 3204 | HWND hwndret = wnd->getWindowHandle(); | 
|---|
| 3205 | RELEASE_WNDOBJ(wnd); | 
|---|
| 3206 | return hwndret; | 
|---|
| 3207 | } | 
|---|
| 3208 | RELEASE_WNDOBJ(wnd); | 
|---|
| 3209 | } | 
|---|
| 3210 | hwnd = OSLibWinGetNextWindow(henum); | 
|---|
| 3211 | } | 
|---|
| 3212 | OSLibWinEndEnumWindows(henum); | 
|---|
| 3213 | if(parent)      RELEASE_WNDOBJ(parent); | 
|---|
| 3214 | if(firstchild)  RELEASE_WNDOBJ(firstchild); | 
|---|
| 3215 | } | 
|---|
| 3216 | SetLastError(ERROR_CANNOT_FIND_WND_CLASS); //TODO: not always correct | 
|---|
| 3217 | return 0; | 
|---|
| 3218 | } | 
|---|
| 3219 | //****************************************************************************** | 
|---|
| 3220 | //****************************************************************************** | 
|---|
| 3221 | HWND Win32BaseWindow::GetWindow(UINT uCmd) | 
|---|
| 3222 | { | 
|---|
| 3223 | HWND hwndRelated = 0; | 
|---|
| 3224 | Win32BaseWindow *window; | 
|---|
| 3225 |  | 
|---|
| 3226 | switch(uCmd) | 
|---|
| 3227 | { | 
|---|
| 3228 | case GW_HWNDFIRST: | 
|---|
| 3229 | window = (Win32BaseWindow *)getParent(); | 
|---|
| 3230 | if(window) | 
|---|
| 3231 | { | 
|---|
| 3232 | hwndRelated = OSLibWinQueryWindow(window->getOS2WindowHandle(), QWOS_TOP); | 
|---|
| 3233 | window = GetWindowFromOS2FrameHandle(hwndRelated); | 
|---|
| 3234 | if(window) { | 
|---|
| 3235 | hwndRelated = window->getWindowHandle(); | 
|---|
| 3236 | RELEASE_WNDOBJ(window); | 
|---|
| 3237 | } | 
|---|
| 3238 | else hwndRelated = 0; | 
|---|
| 3239 | } | 
|---|
| 3240 | else { | 
|---|
| 3241 | dprintf(("WARNING: GW_HWNDFIRST not correctly implemented for toplevel/most windows!")); | 
|---|
| 3242 | hwndRelated = 0; //TODO: not correct; should get first child in z-order of desktop | 
|---|
| 3243 | } | 
|---|
| 3244 | break; | 
|---|
| 3245 |  | 
|---|
| 3246 | case GW_HWNDLAST: | 
|---|
| 3247 | window = (Win32BaseWindow *)getParent(); | 
|---|
| 3248 | if(window) { | 
|---|
| 3249 | hwndRelated = OSLibWinQueryWindow(window->getOS2WindowHandle(), QWOS_BOTTOM); | 
|---|
| 3250 | dprintf(("os2 handle %x", hwndRelated)); | 
|---|
| 3251 | window = GetWindowFromOS2FrameHandle(hwndRelated); | 
|---|
| 3252 | if(window) { | 
|---|
| 3253 | hwndRelated = window->getWindowHandle(); | 
|---|
| 3254 | RELEASE_WNDOBJ(window); | 
|---|
| 3255 | } | 
|---|
| 3256 | else hwndRelated = 0; | 
|---|
| 3257 | } | 
|---|
| 3258 | else { | 
|---|
| 3259 | dprintf(("WARNING: GW_HWNDLAST not correctly implemented for toplevel/most windows!")); | 
|---|
| 3260 | hwndRelated = 0; //TODO: not correct; should get first child in z-order of desktop | 
|---|
| 3261 | } | 
|---|
| 3262 | break; | 
|---|
| 3263 |  | 
|---|
| 3264 | case GW_HWNDNEXT: | 
|---|
| 3265 | if(getParent()) { | 
|---|
| 3266 | hwndRelated = OSLibWinQueryWindow(getOS2FrameWindowHandle(), QWOS_NEXT); | 
|---|
| 3267 | window = GetWindowFromOS2FrameHandle(hwndRelated); | 
|---|
| 3268 | if(window) { | 
|---|
| 3269 | hwndRelated = window->getWindowHandle(); | 
|---|
| 3270 | RELEASE_WNDOBJ(window); | 
|---|
| 3271 | } | 
|---|
| 3272 | else hwndRelated = 0; | 
|---|
| 3273 | } | 
|---|
| 3274 | else { | 
|---|
| 3275 | dprintf(("WARNING: GW_HWNDNEXT not correctly implemented for toplevel/most windows!")); | 
|---|
| 3276 | hwndRelated = 0; //TODO: not correct; should get first child in z-order of desktop | 
|---|
| 3277 | } | 
|---|
| 3278 | break; | 
|---|
| 3279 |  | 
|---|
| 3280 | case GW_HWNDPREV: | 
|---|
| 3281 | if(getParent()) { | 
|---|
| 3282 | hwndRelated = OSLibWinQueryWindow(getOS2FrameWindowHandle(), QWOS_PREV); | 
|---|
| 3283 | window = GetWindowFromOS2FrameHandle(hwndRelated); | 
|---|
| 3284 | if(window) { | 
|---|
| 3285 | hwndRelated = window->getWindowHandle(); | 
|---|
| 3286 | RELEASE_WNDOBJ(window); | 
|---|
| 3287 | } | 
|---|
| 3288 | else hwndRelated = 0; | 
|---|
| 3289 | } | 
|---|
| 3290 | else { | 
|---|
| 3291 | dprintf(("WARNING: GW_HWNDPREV not correctly implemented for toplevel/most windows!")); | 
|---|
| 3292 | hwndRelated = 0; //TODO: not correct; should get first child in z-order of desktop | 
|---|
| 3293 | } | 
|---|
| 3294 | break; | 
|---|
| 3295 |  | 
|---|
| 3296 | case GW_OWNER: | 
|---|
| 3297 | { | 
|---|
| 3298 | Win32BaseWindow *owner = getOwner(); | 
|---|
| 3299 | if(owner) { | 
|---|
| 3300 | hwndRelated = owner->getWindowHandle(); | 
|---|
| 3301 | } | 
|---|
| 3302 | break; | 
|---|
| 3303 | } | 
|---|
| 3304 |  | 
|---|
| 3305 | case GW_CHILD: | 
|---|
| 3306 | hwndRelated = OSLibWinQueryWindow(getOS2WindowHandle(), QWOS_TOP); | 
|---|
| 3307 | window = GetWindowFromOS2FrameHandle(hwndRelated); | 
|---|
| 3308 |  | 
|---|
| 3309 | //Before a window has processed WM_NCCREATE: | 
|---|
| 3310 | //- GetWindow(parent, GW_CHILD) can't return that window handle | 
|---|
| 3311 | //(verified in NT4, SP6) | 
|---|
| 3312 | if(window) { | 
|---|
| 3313 | if(window->state >= STATE_POST_WMNCCREATE) { | 
|---|
| 3314 | hwndRelated = window->getWindowHandle(); | 
|---|
| 3315 | RELEASE_WNDOBJ(window); | 
|---|
| 3316 | } | 
|---|
| 3317 | else { | 
|---|
| 3318 | hwndRelated = window->GetWindow(GW_HWNDNEXT); | 
|---|
| 3319 | RELEASE_WNDOBJ(window); | 
|---|
| 3320 | } | 
|---|
| 3321 | } | 
|---|
| 3322 | else hwndRelated = 0; | 
|---|
| 3323 |  | 
|---|
| 3324 | break; | 
|---|
| 3325 |  | 
|---|
| 3326 | //for internal use only | 
|---|
| 3327 | case GW_HWNDNEXTCHILD: | 
|---|
| 3328 | lock(); | 
|---|
| 3329 | window = (Win32BaseWindow *)getNextChild(); | 
|---|
| 3330 | if(window) { | 
|---|
| 3331 | hwndRelated = window->getWindowHandle(); | 
|---|
| 3332 | } | 
|---|
| 3333 | else hwndRelated = 0; | 
|---|
| 3334 | unlock(); | 
|---|
| 3335 | break; | 
|---|
| 3336 |  | 
|---|
| 3337 | case GW_HWNDPREVCHILD: | 
|---|
| 3338 | DebugInt3(); | 
|---|
| 3339 | break; | 
|---|
| 3340 |  | 
|---|
| 3341 | case GW_HWNDFIRSTCHILD: | 
|---|
| 3342 | lock(); | 
|---|
| 3343 | window = (Win32BaseWindow *)getFirstChild(); | 
|---|
| 3344 | if(window) { | 
|---|
| 3345 | hwndRelated = window->getWindowHandle(); | 
|---|
| 3346 | } | 
|---|
| 3347 | else hwndRelated = 0; | 
|---|
| 3348 | unlock(); | 
|---|
| 3349 | break; | 
|---|
| 3350 |  | 
|---|
| 3351 | case GW_HWNDLASTCHILD: | 
|---|
| 3352 | lock(); | 
|---|
| 3353 | window = (Win32BaseWindow *)getFirstChild(); | 
|---|
| 3354 | if(window) { | 
|---|
| 3355 | while (window->getNextChild()) | 
|---|
| 3356 | { | 
|---|
| 3357 | window = (Win32BaseWindow *)window->getNextChild(); | 
|---|
| 3358 | } | 
|---|
| 3359 | hwndRelated = window->getWindowHandle(); | 
|---|
| 3360 | } | 
|---|
| 3361 | else hwndRelated = 0; | 
|---|
| 3362 | unlock(); | 
|---|
| 3363 | break; | 
|---|
| 3364 | } | 
|---|
| 3365 | end: | 
|---|
| 3366 | dprintf(("GetWindow %x %d returned %x", getWindowHandle(), uCmd, hwndRelated)); | 
|---|
| 3367 | return hwndRelated; | 
|---|
| 3368 | } | 
|---|
| 3369 | //****************************************************************************** | 
|---|
| 3370 | //****************************************************************************** | 
|---|
| 3371 | HWND Win32BaseWindow::SetActiveWindow() | 
|---|
| 3372 | { | 
|---|
| 3373 | HWND hwndActive; | 
|---|
| 3374 |  | 
|---|
| 3375 | dprintf(("SetActiveWindow %x", getWindowHandle())); | 
|---|
| 3376 | if(getStyle() & WS_CHILD) { | 
|---|
| 3377 | //    if(getStyle() & (WS_DISABLED | WS_CHILD)) { | 
|---|
| 3378 | dprintf(("WARNING: Window is a child or disabled")); | 
|---|
| 3379 | return 0; | 
|---|
| 3380 | } | 
|---|
| 3381 |  | 
|---|
| 3382 | if(GetActiveWindow() == getWindowHandle()) { | 
|---|
| 3383 | dprintf(("Window already active")); | 
|---|
| 3384 | return getWindowHandle(); | 
|---|
| 3385 | } | 
|---|
| 3386 | if (HOOK_IsHooked( WH_CBT )) | 
|---|
| 3387 | { | 
|---|
| 3388 | CBTACTIVATESTRUCT cbta; | 
|---|
| 3389 | LRESULT ret; | 
|---|
| 3390 |  | 
|---|
| 3391 | cbta.fMouse = FALSE; | 
|---|
| 3392 | cbta.hWndActive = GetActiveWindow(); | 
|---|
| 3393 | ret = HOOK_CallHooksA(WH_CBT, HCBT_ACTIVATE, getWindowHandle(), (LPARAM)&cbta); | 
|---|
| 3394 | if(ret) | 
|---|
| 3395 | { | 
|---|
| 3396 | dprintf(("SetActiveWindow %x, CBT hook cancelled operation", getWindowHandle())); | 
|---|
| 3397 | return cbta.hWndActive; | 
|---|
| 3398 | } | 
|---|
| 3399 | } | 
|---|
| 3400 | SetWindowPos(HWND_TOP, 0,0,0,0, SWP_NOSIZE | SWP_NOMOVE ); | 
|---|
| 3401 |  | 
|---|
| 3402 | //    if(OSLibWinSetActiveWindow(OS2Hwnd) == FALSE) { | 
|---|
| 3403 | //        dprintf(("OSLibWinSetActiveWindow %x returned FALSE!", OS2Hwnd)); | 
|---|
| 3404 | //    } | 
|---|
| 3405 | hwndActive = GetActiveWindow(); | 
|---|
| 3406 | return (hwndActive) ? hwndActive : windowDesktop->getWindowHandle(); //pretend the desktop was active | 
|---|
| 3407 | } | 
|---|
| 3408 | //****************************************************************************** | 
|---|
| 3409 | //Used to change active status of an mdi window | 
|---|
| 3410 | //****************************************************************************** | 
|---|
| 3411 | BOOL Win32BaseWindow::DeactivateChildWindow() | 
|---|
| 3412 | { | 
|---|
| 3413 | /* child windows get a WM_CHILDACTIVATE message */ | 
|---|
| 3414 | if((getStyle() & (WS_CHILD | WS_POPUP)) == WS_CHILD ) | 
|---|
| 3415 | { | 
|---|
| 3416 | ULONG flags = OSLibWinGetWindowULong(getOS2WindowHandle(), OFFSET_WIN32FLAGS); | 
|---|
| 3417 | OSLibWinSetWindowULong(getOS2WindowHandle(), OFFSET_WIN32FLAGS, (flags & ~WINDOWFLAG_ACTIVE)); | 
|---|
| 3418 | return TRUE; | 
|---|
| 3419 | } | 
|---|
| 3420 | DebugInt3();    //should not be called for non-child window | 
|---|
| 3421 | return FALSE; | 
|---|
| 3422 | } | 
|---|
| 3423 | //****************************************************************************** | 
|---|
| 3424 | //WM_ENABLE is sent to hwnd, but not to it's children (as it should be) | 
|---|
| 3425 | //****************************************************************************** | 
|---|
| 3426 | BOOL Win32BaseWindow::EnableWindow(BOOL fEnable) | 
|---|
| 3427 | { | 
|---|
| 3428 | BOOL rc; | 
|---|
| 3429 |  | 
|---|
| 3430 | dprintf(("Win32BaseWindow::EnableWindow %x %d", getWindowHandle(), fEnable)); | 
|---|
| 3431 | //return true if previous state was disabled, else false (sdk docs) | 
|---|
| 3432 | rc = (getStyle() & WS_DISABLED) != 0; | 
|---|
| 3433 | if(rc && !fEnable) { | 
|---|
| 3434 | SendMessageA(WM_CANCELMODE, 0, 0); | 
|---|
| 3435 | } | 
|---|
| 3436 | OSLibWinEnableWindow(OS2HwndFrame, fEnable); | 
|---|
| 3437 | if(fEnable == FALSE) { | 
|---|
| 3438 | //SvL: No need to clear focus as PM already does this | 
|---|
| 3439 | if(getWindowHandle() == GetCapture()) { | 
|---|
| 3440 | ReleaseCapture();  /* A disabled window can't capture the mouse */ | 
|---|
| 3441 | dprintf(("Released capture for window %x that is being disabled", getWindowHandle())); | 
|---|
| 3442 | } | 
|---|
| 3443 | } | 
|---|
| 3444 | return rc; | 
|---|
| 3445 | } | 
|---|
| 3446 | //****************************************************************************** | 
|---|
| 3447 | //****************************************************************************** | 
|---|
| 3448 | BOOL Win32BaseWindow::CloseWindow() | 
|---|
| 3449 | { | 
|---|
| 3450 | return OSLibWinMinimizeWindow(OS2Hwnd); | 
|---|
| 3451 | } | 
|---|
| 3452 | //****************************************************************************** | 
|---|
| 3453 | //TODO: Not be 100% correct; should return active window of current thread | 
|---|
| 3454 | //      or NULL when there is none -> WinQueryActiveWindow just returns | 
|---|
| 3455 | //      the current active window | 
|---|
| 3456 | //****************************************************************************** | 
|---|
| 3457 | HWND Win32BaseWindow::GetActiveWindow() | 
|---|
| 3458 | { | 
|---|
| 3459 | HWND          hwndActive; | 
|---|
| 3460 |  | 
|---|
| 3461 | hwndActive = OSLibWinQueryActiveWindow(); | 
|---|
| 3462 |  | 
|---|
| 3463 | return OS2ToWin32Handle(hwndActive); | 
|---|
| 3464 | } | 
|---|
| 3465 | //****************************************************************************** | 
|---|
| 3466 | //****************************************************************************** | 
|---|
| 3467 | BOOL Win32BaseWindow::hasWindowName(LPSTR wndname, BOOL fUnicode) | 
|---|
| 3468 | { | 
|---|
| 3469 | INT len = GetWindowTextLength(fUnicode); | 
|---|
| 3470 | BOOL res; | 
|---|
| 3471 |  | 
|---|
| 3472 | if (wndname == NULL) | 
|---|
| 3473 | return (len == 0); | 
|---|
| 3474 |  | 
|---|
| 3475 | len++; | 
|---|
| 3476 | if (fUnicode) | 
|---|
| 3477 | { | 
|---|
| 3478 | WCHAR *text = (WCHAR*)malloc(len*sizeof(WCHAR)); | 
|---|
| 3479 |  | 
|---|
| 3480 | GetWindowTextW(text,len); | 
|---|
| 3481 | res = (lstrcmpW(text,(LPWSTR)wndname) == 0); | 
|---|
| 3482 | free(text); | 
|---|
| 3483 | } | 
|---|
| 3484 | else | 
|---|
| 3485 | { | 
|---|
| 3486 | CHAR *text = (CHAR*)malloc(len*sizeof(CHAR)); | 
|---|
| 3487 |  | 
|---|
| 3488 | GetWindowTextA(text,len); | 
|---|
| 3489 | res = (strcmp(text,wndname) == 0); | 
|---|
| 3490 | free(text); | 
|---|
| 3491 | } | 
|---|
| 3492 |  | 
|---|
| 3493 | return res; | 
|---|
| 3494 | } | 
|---|
| 3495 | //****************************************************************************** | 
|---|
| 3496 | //****************************************************************************** | 
|---|
| 3497 | CHAR *Win32BaseWindow::getWindowNamePtrA() | 
|---|
| 3498 | { | 
|---|
| 3499 | INT len = GetWindowTextLength(FALSE); | 
|---|
| 3500 | CHAR *text; | 
|---|
| 3501 |  | 
|---|
| 3502 | if (len == 0) return NULL; | 
|---|
| 3503 | len++; | 
|---|
| 3504 | text = (CHAR*)malloc(len*sizeof(CHAR)); | 
|---|
| 3505 | GetWindowTextA(text,len); | 
|---|
| 3506 |  | 
|---|
| 3507 | return text; | 
|---|
| 3508 | } | 
|---|
| 3509 | //****************************************************************************** | 
|---|
| 3510 | //****************************************************************************** | 
|---|
| 3511 | WCHAR *Win32BaseWindow::getWindowNamePtrW() | 
|---|
| 3512 | { | 
|---|
| 3513 | INT len = GetWindowTextLength(TRUE); | 
|---|
| 3514 | WCHAR *text; | 
|---|
| 3515 |  | 
|---|
| 3516 | if (len == 0) return NULL; | 
|---|
| 3517 | len++; | 
|---|
| 3518 | text = (WCHAR*)malloc(len*sizeof(WCHAR)); | 
|---|
| 3519 | GetWindowTextW(text,len); | 
|---|
| 3520 |  | 
|---|
| 3521 | return text; | 
|---|
| 3522 | } | 
|---|
| 3523 | //****************************************************************************** | 
|---|
| 3524 | //****************************************************************************** | 
|---|
| 3525 | VOID Win32BaseWindow::freeWindowNamePtr(PVOID namePtr) | 
|---|
| 3526 | { | 
|---|
| 3527 | if (namePtr) free(namePtr); | 
|---|
| 3528 | } | 
|---|
| 3529 | //****************************************************************************** | 
|---|
| 3530 | //When using this API for a window that was created by a different process, NT | 
|---|
| 3531 | //does NOT send WM_GETTEXTLENGTH. | 
|---|
| 3532 | //****************************************************************************** | 
|---|
| 3533 | int Win32BaseWindow::GetWindowTextLength(BOOL fUnicode) | 
|---|
| 3534 | { | 
|---|
| 3535 | //if the destination window is created by this process, send message | 
|---|
| 3536 | if(dwProcessId == currentProcessId) { | 
|---|
| 3537 | if(fUnicode) { | 
|---|
| 3538 | return SendInternalMessageW(WM_GETTEXTLENGTH,0,0); | 
|---|
| 3539 | } | 
|---|
| 3540 | else return SendInternalMessageA(WM_GETTEXTLENGTH,0,0); | 
|---|
| 3541 | } | 
|---|
| 3542 | //else get data directory from window structure | 
|---|
| 3543 | //TODO: must lock window structure.... (TODO) | 
|---|
| 3544 | if(fUnicode) { | 
|---|
| 3545 | if(windowNameW) { | 
|---|
| 3546 | return strlenW(windowNameW); | 
|---|
| 3547 | } | 
|---|
| 3548 | else return 0; | 
|---|
| 3549 | } | 
|---|
| 3550 | else { | 
|---|
| 3551 | if(windowNameA) { | 
|---|
| 3552 | return strlen(windowNameA); | 
|---|
| 3553 | } | 
|---|
| 3554 | else return 0; | 
|---|
| 3555 | } | 
|---|
| 3556 | } | 
|---|
| 3557 | //****************************************************************************** | 
|---|
| 3558 | //When using this API for a window that was created by a different process, NT | 
|---|
| 3559 | //does NOT send WM_GETTEXT. | 
|---|
| 3560 | //****************************************************************************** | 
|---|
| 3561 | int Win32BaseWindow::GetWindowTextA(LPSTR lpsz, int cch) | 
|---|
| 3562 | { | 
|---|
| 3563 | //if the destination window is created by this process, send message | 
|---|
| 3564 | if(dwProcessId == currentProcessId) { | 
|---|
| 3565 | return SendInternalMessageA(WM_GETTEXT,(WPARAM)cch,(LPARAM)lpsz); | 
|---|
| 3566 | } | 
|---|
| 3567 | //else get data directory from window structure | 
|---|
| 3568 | if (!lpsz || !cch) return 0; | 
|---|
| 3569 | if (!windowNameA) lpsz[0] = 0; | 
|---|
| 3570 | else lstrcpynA(lpsz, windowNameA, cch); | 
|---|
| 3571 | return min((windowNameA ? strlen(windowNameA) : 0), cch); | 
|---|
| 3572 | } | 
|---|
| 3573 | //****************************************************************************** | 
|---|
| 3574 | //When using this API for a window that was created by a different process, NT | 
|---|
| 3575 | //does NOT send WM_GETTEXT. | 
|---|
| 3576 | //****************************************************************************** | 
|---|
| 3577 | int Win32BaseWindow::GetWindowTextW(LPWSTR lpsz, int cch) | 
|---|
| 3578 | { | 
|---|
| 3579 | //if the destination window is created by this process, send message | 
|---|
| 3580 | if(dwProcessId == currentProcessId) { | 
|---|
| 3581 | return SendInternalMessageW(WM_GETTEXT,(WPARAM)cch,(LPARAM)lpsz); | 
|---|
| 3582 | } | 
|---|
| 3583 | //else get data directory from window structure | 
|---|
| 3584 | if (!lpsz || !cch) return 0; | 
|---|
| 3585 | if (!windowNameW) lpsz[0] = 0; | 
|---|
| 3586 | else lstrcpynW(lpsz, windowNameW, cch); | 
|---|
| 3587 | return min((windowNameW ? strlenW(windowNameW) : 0), cch); | 
|---|
| 3588 | } | 
|---|
| 3589 | //****************************************************************************** | 
|---|
| 3590 | //TODO: How does this work when the target window belongs to a different process??? | 
|---|
| 3591 | //****************************************************************************** | 
|---|
| 3592 | BOOL Win32BaseWindow::SetWindowTextA(LPSTR lpsz) | 
|---|
| 3593 | { | 
|---|
| 3594 | return SendInternalMessageA(WM_SETTEXT,0,(LPARAM)lpsz); | 
|---|
| 3595 | } | 
|---|
| 3596 | //****************************************************************************** | 
|---|
| 3597 | //****************************************************************************** | 
|---|
| 3598 | BOOL Win32BaseWindow::SetWindowTextW(LPWSTR lpsz) | 
|---|
| 3599 | { | 
|---|
| 3600 | return SendInternalMessageW(WM_SETTEXT,0,(LPARAM)lpsz); | 
|---|
| 3601 | } | 
|---|
| 3602 | //****************************************************************************** | 
|---|
| 3603 | //****************************************************************************** | 
|---|
| 3604 | LONG Win32BaseWindow::SetWindowLongA(int index, ULONG value, BOOL fUnicode) | 
|---|
| 3605 | { | 
|---|
| 3606 | LONG oldval; | 
|---|
| 3607 |  | 
|---|
| 3608 | switch(index) { | 
|---|
| 3609 | case GWL_EXSTYLE: | 
|---|
| 3610 | { | 
|---|
| 3611 | STYLESTRUCT ss; | 
|---|
| 3612 |  | 
|---|
| 3613 | if(dwExStyle == value) { | 
|---|
| 3614 | oldval = value; | 
|---|
| 3615 | break; | 
|---|
| 3616 | } | 
|---|
| 3617 | ss.styleOld = dwExStyle; | 
|---|
| 3618 | ss.styleNew = value; | 
|---|
| 3619 | dprintf(("SetWindowLong GWL_EXSTYLE %x old %x new style %x", getWindowHandle(), dwExStyle, value)); | 
|---|
| 3620 | SendInternalMessageA(WM_STYLECHANGING,GWL_EXSTYLE,(LPARAM)&ss); | 
|---|
| 3621 | setExStyle(ss.styleNew); | 
|---|
| 3622 | SendInternalMessageA(WM_STYLECHANGED,GWL_EXSTYLE,(LPARAM)&ss); | 
|---|
| 3623 | oldval = ss.styleOld; | 
|---|
| 3624 | break; | 
|---|
| 3625 | } | 
|---|
| 3626 | case GWL_STYLE: | 
|---|
| 3627 | { | 
|---|
| 3628 | STYLESTRUCT ss; | 
|---|
| 3629 |  | 
|---|
| 3630 | //SvL: TODO: Can you change minimize or maximize status here too? | 
|---|
| 3631 |  | 
|---|
| 3632 | if(dwStyle == value) { | 
|---|
| 3633 | oldval = value; | 
|---|
| 3634 | break; | 
|---|
| 3635 | } | 
|---|
| 3636 | dprintf(("SetWindowLong GWL_STYLE %x old %x new style %x (%x)", getWindowHandle(), dwStyle, value)); | 
|---|
| 3637 | #ifdef DEBUG | 
|---|
| 3638 | //                if((value & WS_CHILD) != (dwStyle & WS_CHILD)) { | 
|---|
| 3639 | //                    DebugInt3(); //is this allowed? | 
|---|
| 3640 | //                } | 
|---|
| 3641 | #endif | 
|---|
| 3642 | value &= ~(WS_CHILD); | 
|---|
| 3643 | ss.styleOld = getStyle(); | 
|---|
| 3644 | ss.styleNew = value | (ss.styleOld & WS_CHILD); | 
|---|
| 3645 | SendInternalMessageA(WM_STYLECHANGING,GWL_STYLE,(LPARAM)&ss); | 
|---|
| 3646 | setStyle(ss.styleNew); | 
|---|
| 3647 | SendInternalMessageA(WM_STYLECHANGED,GWL_STYLE,(LPARAM)&ss); | 
|---|
| 3648 | OSLibSetWindowStyle(getOS2FrameWindowHandle(), getOS2WindowHandle(), getStyle(), getExStyle()); | 
|---|
| 3649 |  | 
|---|
| 3650 | //TODO: Might not be correct to use ShowWindow here | 
|---|
| 3651 | if((ss.styleOld & WS_VISIBLE) != (ss.styleNew & WS_VISIBLE)) { | 
|---|
| 3652 | if(ss.styleNew & WS_VISIBLE) | 
|---|
| 3653 | ShowWindow(SW_SHOWNOACTIVATE); | 
|---|
| 3654 | else ShowWindow(SW_HIDE); | 
|---|
| 3655 | } | 
|---|
| 3656 | #ifdef DEBUG | 
|---|
| 3657 | PrintWindowStyle(ss.styleNew, 0); | 
|---|
| 3658 | #endif | 
|---|
| 3659 | oldval = ss.styleOld; | 
|---|
| 3660 | break; | 
|---|
| 3661 | } | 
|---|
| 3662 | case GWL_WNDPROC: | 
|---|
| 3663 | { | 
|---|
| 3664 | //Note: Type of SetWindowLong determines new window proc type | 
|---|
| 3665 | //      UNLESS the new window proc has already been registered | 
|---|
| 3666 | //      (use the old type in that case) | 
|---|
| 3667 | //      (VERIFIED in NT 4, SP6) | 
|---|
| 3668 | WINDOWPROCTYPE type = WINPROC_GetProcType((HWINDOWPROC)value); | 
|---|
| 3669 | if(type == WIN_PROC_INVALID) { | 
|---|
| 3670 | type = (fUnicode) ? WIN_PROC_32W : WIN_PROC_32A; | 
|---|
| 3671 | } | 
|---|
| 3672 | oldval = (LONG)WINPROC_GetProc(win32wndproc, (fUnicode) ? WIN_PROC_32W : WIN_PROC_32A); | 
|---|
| 3673 | dprintf(("SetWindowLong GWL_WNDPROC %x old %x new wndproc %x", getWindowHandle(), oldval, value)); | 
|---|
| 3674 | WINPROC_SetProc((HWINDOWPROC *)&win32wndproc, (WNDPROC)value, type, WIN_PROC_WINDOW); | 
|---|
| 3675 | break; | 
|---|
| 3676 | } | 
|---|
| 3677 | case GWL_HINSTANCE: | 
|---|
| 3678 | oldval = hInstance; | 
|---|
| 3679 | hInstance = value; | 
|---|
| 3680 | break; | 
|---|
| 3681 |  | 
|---|
| 3682 | case GWL_HWNDPARENT: | 
|---|
| 3683 | oldval = SetParent((HWND)value); | 
|---|
| 3684 | break; | 
|---|
| 3685 |  | 
|---|
| 3686 | case GWL_ID: | 
|---|
| 3687 | oldval = getWindowId(); | 
|---|
| 3688 | setWindowId(value); | 
|---|
| 3689 | break; | 
|---|
| 3690 |  | 
|---|
| 3691 | case GWL_USERDATA: | 
|---|
| 3692 | oldval = userData; | 
|---|
| 3693 | userData = value; | 
|---|
| 3694 | break; | 
|---|
| 3695 |  | 
|---|
| 3696 | default: | 
|---|
| 3697 | if(index >= 0 && index + sizeof(ULONG) <= nrUserWindowBytes) | 
|---|
| 3698 | { | 
|---|
| 3699 | oldval = *(ULONG *)(userWindowBytes + index); | 
|---|
| 3700 | *(ULONG *)(userWindowBytes + index) = value; | 
|---|
| 3701 | break; | 
|---|
| 3702 | } | 
|---|
| 3703 | dprintf(("WARNING: SetWindowLong%c %x %d %x returned %x INVALID index!", (fUnicode) ? 'W' : 'A', getWindowHandle(), index, value)); | 
|---|
| 3704 | SetLastError(ERROR_INVALID_INDEX);  //verified in NT4, SP6 | 
|---|
| 3705 | return 0; | 
|---|
| 3706 | } | 
|---|
| 3707 | //Note: NT4, SP6 does not set the last error to 0 | 
|---|
| 3708 | SetLastError(ERROR_SUCCESS); | 
|---|
| 3709 | dprintf2(("SetWindowLong%c %x %d %x returned %x", (fUnicode) ? 'W' : 'A', getWindowHandle(), index, value, oldval)); | 
|---|
| 3710 | return oldval; | 
|---|
| 3711 | } | 
|---|
| 3712 | //****************************************************************************** | 
|---|
| 3713 | //****************************************************************************** | 
|---|
| 3714 | ULONG Win32BaseWindow::GetWindowLongA(int index, BOOL fUnicode) | 
|---|
| 3715 | { | 
|---|
| 3716 | ULONG value; | 
|---|
| 3717 |  | 
|---|
| 3718 | switch(index) { | 
|---|
| 3719 | case GWL_EXSTYLE: | 
|---|
| 3720 | value = dwExStyle; | 
|---|
| 3721 | break; | 
|---|
| 3722 | case GWL_STYLE: | 
|---|
| 3723 | value = dwStyle; | 
|---|
| 3724 | break; | 
|---|
| 3725 | case GWL_WNDPROC: | 
|---|
| 3726 | value = (LONG)WINPROC_GetProc(win32wndproc, (fUnicode) ? WIN_PROC_32W : WIN_PROC_32A); | 
|---|
| 3727 | break; | 
|---|
| 3728 | case GWL_HINSTANCE: | 
|---|
| 3729 | value = hInstance; | 
|---|
| 3730 | break; | 
|---|
| 3731 | case GWL_HWNDPARENT: | 
|---|
| 3732 | value = GetParent(); | 
|---|
| 3733 | break; | 
|---|
| 3734 | case GWL_ID: | 
|---|
| 3735 | value = getWindowId(); | 
|---|
| 3736 | break; | 
|---|
| 3737 | case GWL_USERDATA: | 
|---|
| 3738 | value = userData; | 
|---|
| 3739 | break; | 
|---|
| 3740 | default: | 
|---|
| 3741 | if(index >= 0 && index + sizeof(ULONG) <= nrUserWindowBytes) | 
|---|
| 3742 | { | 
|---|
| 3743 | value = *(ULONG *)(userWindowBytes + index); | 
|---|
| 3744 | break; | 
|---|
| 3745 | } | 
|---|
| 3746 | dprintf(("WARNING: GetWindowLong%c %x %d %x returned %x INVALID index!", (fUnicode) ? 'W' : 'A', getWindowHandle(), index, value)); | 
|---|
| 3747 | SetLastError(ERROR_INVALID_INDEX);  //verified in NT4, SP6 | 
|---|
| 3748 | return 0; | 
|---|
| 3749 | } | 
|---|
| 3750 | dprintf2(("GetWindowLong%c %x %d %x", (fUnicode) ? 'W' : 'A', getWindowHandle(), index, value)); | 
|---|
| 3751 | //Note: NT4, SP6 does not set the last error to 0 | 
|---|
| 3752 | SetLastError(ERROR_SUCCESS); | 
|---|
| 3753 | return value; | 
|---|
| 3754 | } | 
|---|
| 3755 | //****************************************************************************** | 
|---|
| 3756 | //****************************************************************************** | 
|---|
| 3757 | WORD Win32BaseWindow::SetWindowWord(int index, WORD value) | 
|---|
| 3758 | { | 
|---|
| 3759 | WORD oldval; | 
|---|
| 3760 |  | 
|---|
| 3761 | if(index >= 0 && index + sizeof(WORD) <= nrUserWindowBytes) | 
|---|
| 3762 | { | 
|---|
| 3763 | oldval = *(WORD *)(userWindowBytes + index); | 
|---|
| 3764 | *(WORD *)(userWindowBytes + index) = value; | 
|---|
| 3765 | //Note: NT4, SP6 does not set the last error to 0 | 
|---|
| 3766 | dprintf2(("SetWindowWord %x %d %x returned %x", getWindowHandle(), index, value, oldval)); | 
|---|
| 3767 | SetLastError(ERROR_SUCCESS); | 
|---|
| 3768 | return oldval; | 
|---|
| 3769 | } | 
|---|
| 3770 | switch(index) | 
|---|
| 3771 | { | 
|---|
| 3772 | case GWW_HINSTANCE: | 
|---|
| 3773 | oldval = hInstance; | 
|---|
| 3774 | hInstance = value; | 
|---|
| 3775 | break; | 
|---|
| 3776 |  | 
|---|
| 3777 | case GWW_HWNDPARENT: | 
|---|
| 3778 | oldval = SetParent((HWND)(WNDHANDLE_MAGIC_HIGHWORD | value)); | 
|---|
| 3779 | break; | 
|---|
| 3780 |  | 
|---|
| 3781 | case GWW_ID: | 
|---|
| 3782 | oldval = getWindowId(); | 
|---|
| 3783 | setWindowId(value); | 
|---|
| 3784 | break; | 
|---|
| 3785 |  | 
|---|
| 3786 | default: | 
|---|
| 3787 | dprintf(("WARNING: SetWindowWord %x %d %x returned %x INVALID index!", getWindowHandle(), index, value)); | 
|---|
| 3788 | SetLastError(ERROR_INVALID_INDEX);  //verified in NT4, SP6 | 
|---|
| 3789 | return 0; | 
|---|
| 3790 | } | 
|---|
| 3791 | //Note: NT4, SP6 does not set the last error to 0 | 
|---|
| 3792 | SetLastError(ERROR_SUCCESS); | 
|---|
| 3793 | dprintf2(("SetWindowWord %x %d %x returned %x", getWindowHandle(), index, value, oldval)); | 
|---|
| 3794 | return oldval; | 
|---|
| 3795 | } | 
|---|
| 3796 | //****************************************************************************** | 
|---|
| 3797 | //****************************************************************************** | 
|---|
| 3798 | WORD Win32BaseWindow::GetWindowWord(int index) | 
|---|
| 3799 | { | 
|---|
| 3800 | if(index >= 0 && index + sizeof(WORD) <= nrUserWindowBytes) | 
|---|
| 3801 | { | 
|---|
| 3802 | //Note: NT4, SP6 does not set the last error to 0 | 
|---|
| 3803 | SetLastError(ERROR_SUCCESS); | 
|---|
| 3804 | dprintf2(("GetWindowWord %x %d %x", getWindowHandle(), index, *(WORD *)(userWindowBytes + index))); | 
|---|
| 3805 | return *(WORD *)(userWindowBytes + index); | 
|---|
| 3806 | } | 
|---|
| 3807 | switch(index) | 
|---|
| 3808 | { | 
|---|
| 3809 | case GWW_ID: | 
|---|
| 3810 | if(HIWORD(getWindowId())) | 
|---|
| 3811 | dprintf(("WARNING: GWW_ID: discards high bits of 0x%08x!\n", getWindowId())); | 
|---|
| 3812 | return (WORD)getWindowId(); | 
|---|
| 3813 |  | 
|---|
| 3814 | case GWW_HWNDPARENT: | 
|---|
| 3815 | dprintf(("WARNING: GWW_HWNDPARENT: discards high bits of 0x%08x!\n", GetParent())); | 
|---|
| 3816 | return (WORD) GetParent(); | 
|---|
| 3817 |  | 
|---|
| 3818 | case GWW_HINSTANCE: | 
|---|
| 3819 | if (HIWORD(hInstance)) | 
|---|
| 3820 | dprintf(("WARNING: GWW_HINSTANCE: discards high bits of 0x%08x!\n", hInstance)); | 
|---|
| 3821 | return (WORD)hInstance; | 
|---|
| 3822 | } | 
|---|
| 3823 |  | 
|---|
| 3824 | dprintf(("WARNING: GetWindowWord %x %d returned %x INVALID index!", getWindowHandle(), index)); | 
|---|
| 3825 | SetLastError(ERROR_INVALID_INDEX);  //verified in NT4, SP6 | 
|---|
| 3826 | return 0; | 
|---|
| 3827 | } | 
|---|
| 3828 | //****************************************************************************** | 
|---|
| 3829 | //****************************************************************************** | 
|---|
| 3830 | void Win32BaseWindow::setWindowId(DWORD id) | 
|---|
| 3831 | { | 
|---|
| 3832 | dwIDMenu = id; | 
|---|
| 3833 | } | 
|---|
| 3834 | //****************************************************************************** | 
|---|
| 3835 | //Locates window in linked list and increases reference count (if found) | 
|---|
| 3836 | //Window object must be unreferenced after usage | 
|---|
| 3837 | //****************************************************************************** | 
|---|
| 3838 | Win32BaseWindow *Win32BaseWindow::GetWindowFromHandle(HWND hwnd) | 
|---|
| 3839 | { | 
|---|
| 3840 | Win32BaseWindow *window; | 
|---|
| 3841 |  | 
|---|
| 3842 | ////TODO: temporary workaround for crashes in Opera (pmwinx; releasesemaphore) | 
|---|
| 3843 | ////      while browsing | 
|---|
| 3844 | ////      Not thread safe now! | 
|---|
| 3845 | ////    lock(&critsect); | 
|---|
| 3846 | if(HwGetWindowHandleData(hwnd, (DWORD *)&window) == TRUE) { | 
|---|
| 3847 | if(window) { | 
|---|
| 3848 | ////             dprintf(("addRef %x; refcount %d", hwnd, window->getRefCount()+1)); | 
|---|
| 3849 | window->addRef(); | 
|---|
| 3850 | } | 
|---|
| 3851 | ////         unlock(&critsect); | 
|---|
| 3852 | return window; | 
|---|
| 3853 | } | 
|---|
| 3854 | ////    unlock(&critsect); | 
|---|
| 3855 | //    dprintf2(("Win32BaseWindow::GetWindowFromHandle: not a win32 window %x", hwnd)); | 
|---|
| 3856 | return NULL; | 
|---|
| 3857 | } | 
|---|
| 3858 | //****************************************************************************** | 
|---|
| 3859 | //Locates window in linked list and increases reference count (if found) | 
|---|
| 3860 | //Window object must be unreferenced after usage | 
|---|
| 3861 | //****************************************************************************** | 
|---|
| 3862 | Win32BaseWindow *Win32BaseWindow::GetWindowFromOS2Handle(HWND hwndOS2) | 
|---|
| 3863 | { | 
|---|
| 3864 | DWORD            magic; | 
|---|
| 3865 | HWND             hwnd; | 
|---|
| 3866 |  | 
|---|
| 3867 | if(hwndOS2 == OSLIB_HWND_DESKTOP) | 
|---|
| 3868 | { | 
|---|
| 3869 | windowDesktop->addRef(); | 
|---|
| 3870 | return windowDesktop; | 
|---|
| 3871 | } | 
|---|
| 3872 |  | 
|---|
| 3873 | hwnd  = (HWND)OSLibWinGetWindowULong(hwndOS2, OFFSET_WIN32WNDPTR); | 
|---|
| 3874 | magic = OSLibWinGetWindowULong(hwndOS2, OFFSET_WIN32PM_MAGIC); | 
|---|
| 3875 |  | 
|---|
| 3876 | if(hwnd && CheckMagicDword(magic)) { | 
|---|
| 3877 | return GetWindowFromHandle(hwnd); | 
|---|
| 3878 | } | 
|---|
| 3879 | //  dprintf2(("Win32BaseWindow::GetWindowFromOS2Handle: not an Odin os2 window %x", hwndOS2)); | 
|---|
| 3880 | return 0; | 
|---|
| 3881 | } | 
|---|
| 3882 | //****************************************************************************** | 
|---|
| 3883 | //Locates window in linked list and increases reference count (if found) | 
|---|
| 3884 | //Window object must be unreferenced after usage | 
|---|
| 3885 | //****************************************************************************** | 
|---|
| 3886 | Win32BaseWindow *Win32BaseWindow::GetWindowFromOS2FrameHandle(HWND hwnd) | 
|---|
| 3887 | { | 
|---|
| 3888 | return GetWindowFromOS2Handle(OSLibWinWindowFromID(hwnd,OSLIB_FID_CLIENT)); | 
|---|
| 3889 | } | 
|---|
| 3890 | //****************************************************************************** | 
|---|
| 3891 | //****************************************************************************** | 
|---|
| 3892 | HWND WIN32API Win32ToOS2Handle(HWND hwnd) | 
|---|
| 3893 | { | 
|---|
| 3894 | HWND hwndOS2; | 
|---|
| 3895 |  | 
|---|
| 3896 | Win32BaseWindow *window = Win32BaseWindow::GetWindowFromHandle(hwnd); | 
|---|
| 3897 |  | 
|---|
| 3898 | if(window) { | 
|---|
| 3899 | hwndOS2 = window->getOS2WindowHandle(); | 
|---|
| 3900 | RELEASE_WNDOBJ(window); | 
|---|
| 3901 | return hwndOS2; | 
|---|
| 3902 | } | 
|---|
| 3903 | //    dprintf2(("Win32BaseWindow::Win32ToOS2Handle: not a win32 window %x", hwnd)); | 
|---|
| 3904 | return hwnd; | 
|---|
| 3905 | } | 
|---|
| 3906 | //****************************************************************************** | 
|---|
| 3907 | //****************************************************************************** | 
|---|
| 3908 | HWND WIN32API Win32ToOS2FrameHandle(HWND hwnd) | 
|---|
| 3909 | { | 
|---|
| 3910 | HWND hwndOS2; | 
|---|
| 3911 |  | 
|---|
| 3912 | Win32BaseWindow *window = Win32BaseWindow::GetWindowFromHandle(hwnd); | 
|---|
| 3913 |  | 
|---|
| 3914 | if(window) { | 
|---|
| 3915 | hwndOS2 = window->getOS2FrameWindowHandle(); | 
|---|
| 3916 | RELEASE_WNDOBJ(window); | 
|---|
| 3917 | return hwndOS2; | 
|---|
| 3918 | } | 
|---|
| 3919 | //    dprintf2(("Win32BaseWindow::Win32ToOS2Handle: not a win32 window %x", hwnd)); | 
|---|
| 3920 | return hwnd; | 
|---|
| 3921 | } | 
|---|
| 3922 | //****************************************************************************** | 
|---|
| 3923 | //****************************************************************************** | 
|---|
| 3924 | HWND WIN32API OS2ToWin32Handle(HWND hwnd) | 
|---|
| 3925 | { | 
|---|
| 3926 | Win32BaseWindow *window = Win32BaseWindow::GetWindowFromOS2Handle(hwnd); | 
|---|
| 3927 | HWND hwndWin32; | 
|---|
| 3928 |  | 
|---|
| 3929 | if(window) { | 
|---|
| 3930 | hwndWin32 = window->getWindowHandle(); | 
|---|
| 3931 | RELEASE_WNDOBJ(window); | 
|---|
| 3932 | return hwndWin32; | 
|---|
| 3933 | } | 
|---|
| 3934 | window = Win32BaseWindow::GetWindowFromOS2FrameHandle(hwnd); | 
|---|
| 3935 | if(window) { | 
|---|
| 3936 | hwndWin32 = window->getWindowHandle(); | 
|---|
| 3937 | RELEASE_WNDOBJ(window); | 
|---|
| 3938 | return hwndWin32; | 
|---|
| 3939 | } | 
|---|
| 3940 |  | 
|---|
| 3941 | //    dprintf2(("Win32BaseWindow::OS2ToWin32Handle: not a win32 window %x", hwnd)); | 
|---|
| 3942 | return 0; | 
|---|
| 3943 | //    else    return hwnd;    //OS/2 window handle | 
|---|
| 3944 | } | 
|---|
| 3945 | #ifdef DEBUG | 
|---|
| 3946 | LONG  Win32BaseWindow::addRef() | 
|---|
| 3947 | { | 
|---|
| 3948 | dprintf2(("addRef %x %d", getWindowHandle(), getRefCount()+1)); | 
|---|
| 3949 | return GenericObject::addRef(); | 
|---|
| 3950 | } | 
|---|
| 3951 | //****************************************************************************** | 
|---|
| 3952 | //****************************************************************************** | 
|---|
| 3953 | LONG  Win32BaseWindow::release(char *function, int line) | 
|---|
| 3954 | { | 
|---|
| 3955 | dprintf2(("release %s %d %x %d", function, line, getWindowHandle(), getRefCount()-1)); | 
|---|
| 3956 | return GenericObject::release(); | 
|---|
| 3957 | } | 
|---|
| 3958 | #endif | 
|---|
| 3959 | //****************************************************************************** | 
|---|
| 3960 | //****************************************************************************** | 
|---|
| 3961 | GenericObject   *Win32BaseWindow::windows  = NULL; | 
|---|
| 3962 | CRITICAL_SECTION Win32BaseWindow::critsect = {0}; | 
|---|
| 3963 |  | 
|---|
| 3964 | //****************************************************************************** | 
|---|
| 3965 | //****************************************************************************** | 
|---|
| 3966 | #ifdef DEBUG | 
|---|
| 3967 | void PrintWindowStyle(DWORD dwStyle, DWORD dwExStyle) | 
|---|
| 3968 | { | 
|---|
| 3969 | char style[256] = ""; | 
|---|
| 3970 | char exstyle[256] = ""; | 
|---|
| 3971 |  | 
|---|
| 3972 | /* Window styles */ | 
|---|
| 3973 | if(dwStyle & WS_CHILD) | 
|---|
| 3974 | strcat(style, "WS_CHILD "); | 
|---|
| 3975 | if(dwStyle & WS_POPUP) | 
|---|
| 3976 | strcat(style, "WS_POPUP "); | 
|---|
| 3977 | if(dwStyle & WS_VISIBLE) | 
|---|
| 3978 | strcat(style, "WS_VISIBLE "); | 
|---|
| 3979 | if(dwStyle & WS_DISABLED) | 
|---|
| 3980 | strcat(style, "WS_DISABLED "); | 
|---|
| 3981 | if(dwStyle & WS_CLIPSIBLINGS) | 
|---|
| 3982 | strcat(style, "WS_CLIPSIBLINGS "); | 
|---|
| 3983 | if(dwStyle & WS_CLIPCHILDREN) | 
|---|
| 3984 | strcat(style, "WS_CLIPCHILDREN "); | 
|---|
| 3985 | if(dwStyle & WS_MAXIMIZE) | 
|---|
| 3986 | strcat(style, "WS_MAXIMIZE "); | 
|---|
| 3987 | if(dwStyle & WS_MINIMIZE) | 
|---|
| 3988 | strcat(style, "WS_MINIMIZE "); | 
|---|
| 3989 | if(dwStyle & WS_GROUP) | 
|---|
| 3990 | strcat(style, "WS_GROUP "); | 
|---|
| 3991 | if(dwStyle & WS_TABSTOP) | 
|---|
| 3992 | strcat(style, "WS_TABSTOP "); | 
|---|
| 3993 |  | 
|---|
| 3994 | if((dwStyle & WS_CAPTION) == WS_CAPTION) | 
|---|
| 3995 | strcat(style, "WS_CAPTION "); | 
|---|
| 3996 | if(dwStyle & WS_DLGFRAME) | 
|---|
| 3997 | strcat(style, "WS_DLGFRAME "); | 
|---|
| 3998 | if(dwStyle & WS_BORDER) | 
|---|
| 3999 | strcat(style, "WS_BORDER "); | 
|---|
| 4000 |  | 
|---|
| 4001 | if(dwStyle & WS_VSCROLL) | 
|---|
| 4002 | strcat(style, "WS_VSCROLL "); | 
|---|
| 4003 | if(dwStyle & WS_HSCROLL) | 
|---|
| 4004 | strcat(style, "WS_HSCROLL "); | 
|---|
| 4005 | if(dwStyle & WS_SYSMENU) | 
|---|
| 4006 | strcat(style, "WS_SYSMENU "); | 
|---|
| 4007 | if(dwStyle & WS_THICKFRAME) | 
|---|
| 4008 | strcat(style, "WS_THICKFRAME "); | 
|---|
| 4009 | if(dwStyle & WS_MINIMIZEBOX) | 
|---|
| 4010 | strcat(style, "WS_MINIMIZEBOX "); | 
|---|
| 4011 | if(dwStyle & WS_MAXIMIZEBOX) | 
|---|
| 4012 | strcat(style, "WS_MAXIMIZEBOX "); | 
|---|
| 4013 |  | 
|---|
| 4014 | if(dwExStyle & WS_EX_DLGMODALFRAME) | 
|---|
| 4015 | strcat(exstyle, "WS_EX_DLGMODALFRAME "); | 
|---|
| 4016 | if(dwExStyle & WS_EX_ACCEPTFILES) | 
|---|
| 4017 | strcat(exstyle, "WS_EX_ACCEPTFILES "); | 
|---|
| 4018 | if(dwExStyle & WS_EX_NOPARENTNOTIFY) | 
|---|
| 4019 | strcat(exstyle, "WS_EX_NOPARENTNOTIFY "); | 
|---|
| 4020 | if(dwExStyle & WS_EX_TOPMOST) | 
|---|
| 4021 | strcat(exstyle, "WS_EX_TOPMOST "); | 
|---|
| 4022 | if(dwExStyle & WS_EX_TRANSPARENT) | 
|---|
| 4023 | strcat(exstyle, "WS_EX_TRANSPARENT "); | 
|---|
| 4024 |  | 
|---|
| 4025 | if(dwExStyle & WS_EX_MDICHILD) | 
|---|
| 4026 | strcat(exstyle, "WS_EX_MDICHILD "); | 
|---|
| 4027 | if(dwExStyle & WS_EX_TOOLWINDOW) | 
|---|
| 4028 | strcat(exstyle, "WS_EX_TOOLWINDOW "); | 
|---|
| 4029 | if(dwExStyle & WS_EX_WINDOWEDGE) | 
|---|
| 4030 | strcat(exstyle, "WS_EX_WINDOWEDGE "); | 
|---|
| 4031 | if(dwExStyle & WS_EX_CLIENTEDGE) | 
|---|
| 4032 | strcat(exstyle, "WS_EX_CLIENTEDGE "); | 
|---|
| 4033 | if(dwExStyle & WS_EX_CONTEXTHELP) | 
|---|
| 4034 | strcat(exstyle, "WS_EX_CONTEXTHELP "); | 
|---|
| 4035 | if(dwExStyle & WS_EX_RIGHT) | 
|---|
| 4036 | strcat(exstyle, "WS_EX_RIGHT "); | 
|---|
| 4037 | if(dwExStyle & WS_EX_LEFT) | 
|---|
| 4038 | strcat(exstyle, "WS_EX_LEFT "); | 
|---|
| 4039 | if(dwExStyle & WS_EX_RTLREADING) | 
|---|
| 4040 | strcat(exstyle, "WS_EX_RTLREADING "); | 
|---|
| 4041 | if(dwExStyle & WS_EX_LTRREADING) | 
|---|
| 4042 | strcat(exstyle, "WS_EX_LTRREADING "); | 
|---|
| 4043 | if(dwExStyle & WS_EX_LEFTSCROLLBAR) | 
|---|
| 4044 | strcat(exstyle, "WS_EX_LEFTSCROLLBAR "); | 
|---|
| 4045 | if(dwExStyle & WS_EX_RIGHTSCROLLBAR) | 
|---|
| 4046 | strcat(exstyle, "WS_EX_RIGHTSCROLLBAR "); | 
|---|
| 4047 | if(dwExStyle & WS_EX_CONTROLPARENT) | 
|---|
| 4048 | strcat(exstyle, "WS_EX_CONTROLPARENT "); | 
|---|
| 4049 | if(dwExStyle & WS_EX_STATICEDGE) | 
|---|
| 4050 | strcat(exstyle, "WS_EX_STATICEDGE "); | 
|---|
| 4051 | if(dwExStyle & WS_EX_APPWINDOW) | 
|---|
| 4052 | strcat(exstyle, "WS_EX_APPWINDOW "); | 
|---|
| 4053 |  | 
|---|
| 4054 | dprintf(("Window style:   %x %s", dwStyle, style)); | 
|---|
| 4055 | dprintf(("Window exStyle: %x %s", dwExStyle, exstyle)); | 
|---|
| 4056 | } | 
|---|
| 4057 | #endif | 
|---|
| 4058 | //****************************************************************************** | 
|---|
| 4059 | //****************************************************************************** | 
|---|