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