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