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