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