| 1 | /* $Id: win32wbase.cpp,v 1.251 2001-04-15 17:05:29 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(getWindowHandle() == 0x68000044) {
|
|---|
| 1584 | rc = GetClipBox( (HDC)wParam, &rect );
|
|---|
| 1585 | FillRect( (HDC)wParam, &rect, GetSysColorBrush(COLOR_WINDOWTEXT));
|
|---|
| 1586 | return 1;
|
|---|
| 1587 | }
|
|---|
| 1588 |
|
|---|
| 1589 | if (!windowClass || !windowClass->getBackgroundBrush()) return 0;
|
|---|
| 1590 |
|
|---|
| 1591 | rc = GetClipBox( (HDC)wParam, &rect );
|
|---|
| 1592 | if ((rc == SIMPLEREGION) || (rc == COMPLEXREGION))
|
|---|
| 1593 | {
|
|---|
| 1594 | HBRUSH hBrush = windowClass->getBackgroundBrush();
|
|---|
| 1595 |
|
|---|
| 1596 | if (hBrush <= (HBRUSH)(SYSCOLOR_GetLastColor()+1))
|
|---|
| 1597 | hBrush = GetSysColorBrush(hBrush-1);
|
|---|
| 1598 |
|
|---|
| 1599 | FillRect( (HDC)wParam, &rect, hBrush);
|
|---|
| 1600 | }
|
|---|
| 1601 | return 1;
|
|---|
| 1602 | }
|
|---|
| 1603 |
|
|---|
| 1604 | case WM_PRINT:
|
|---|
| 1605 | return DefWndPrint(wParam,lParam);
|
|---|
| 1606 |
|
|---|
| 1607 | case WM_PAINTICON:
|
|---|
| 1608 | case WM_PAINT:
|
|---|
| 1609 | {
|
|---|
| 1610 | PAINTSTRUCT ps;
|
|---|
| 1611 | HDC hdc = BeginPaint(getWindowHandle(), &ps );
|
|---|
| 1612 | if( hdc )
|
|---|
| 1613 | {
|
|---|
| 1614 | if( (getStyle() & WS_MINIMIZE) && (getWindowClass()->getIcon() || hIcon))
|
|---|
| 1615 | {
|
|---|
| 1616 | int x = (rectWindow.right - rectWindow.left - GetSystemMetrics(SM_CXICON))/2;
|
|---|
| 1617 | int y = (rectWindow.bottom - rectWindow.top - GetSystemMetrics(SM_CYICON))/2;
|
|---|
| 1618 | dprintf(("Painting class icon: vis rect=(%i,%i - %i,%i)\n", ps.rcPaint.left, ps.rcPaint.top, ps.rcPaint.right, ps.rcPaint.bottom ));
|
|---|
| 1619 | DrawIcon(hdc, x, y, hIcon ? hIcon:getWindowClass()->getIcon() );
|
|---|
| 1620 | }
|
|---|
| 1621 | EndPaint(getWindowHandle(), &ps );
|
|---|
| 1622 | }
|
|---|
| 1623 | return 0;
|
|---|
| 1624 | }
|
|---|
| 1625 |
|
|---|
| 1626 | case WM_GETDLGCODE:
|
|---|
| 1627 | return 0;
|
|---|
| 1628 |
|
|---|
| 1629 | case WM_NCPAINT:
|
|---|
| 1630 | return HandleNCPaint((HRGN)wParam);
|
|---|
| 1631 |
|
|---|
| 1632 | case WM_NCACTIVATE:
|
|---|
| 1633 | return HandleNCActivate(wParam);
|
|---|
| 1634 |
|
|---|
| 1635 | case WM_NCCREATE:
|
|---|
| 1636 | return(TRUE);
|
|---|
| 1637 |
|
|---|
| 1638 | case WM_NCDESTROY:
|
|---|
| 1639 | return 0;
|
|---|
| 1640 |
|
|---|
| 1641 | case WM_NCCALCSIZE:
|
|---|
| 1642 | return HandleNCCalcSize((BOOL)wParam,(RECT*)lParam);
|
|---|
| 1643 |
|
|---|
| 1644 | case WM_NCLBUTTONDOWN:
|
|---|
| 1645 | return HandleNCLButtonDown(wParam,lParam);
|
|---|
| 1646 |
|
|---|
| 1647 | case WM_LBUTTONDBLCLK:
|
|---|
| 1648 | case WM_NCLBUTTONDBLCLK:
|
|---|
| 1649 | return HandleNCLButtonDblClk(wParam,lParam);
|
|---|
| 1650 |
|
|---|
| 1651 | case WM_NCRBUTTONDOWN:
|
|---|
| 1652 | case WM_NCRBUTTONDBLCLK:
|
|---|
| 1653 | case WM_NCMBUTTONDOWN:
|
|---|
| 1654 | case WM_NCMBUTTONDBLCLK:
|
|---|
| 1655 | if (lastHitTestVal == HTERROR) MessageBeep(MB_ICONEXCLAMATION);
|
|---|
| 1656 | return 0;
|
|---|
| 1657 |
|
|---|
| 1658 | case WM_NCRBUTTONUP:
|
|---|
| 1659 | return HandleNCRButtonUp(wParam,lParam);
|
|---|
| 1660 |
|
|---|
| 1661 | case WM_NCMBUTTONUP:
|
|---|
| 1662 | return 0;
|
|---|
| 1663 |
|
|---|
| 1664 | case WM_NCHITTEST:
|
|---|
| 1665 | {
|
|---|
| 1666 | POINT point;
|
|---|
| 1667 | LRESULT retvalue;
|
|---|
| 1668 |
|
|---|
| 1669 | point.x = (SHORT)LOWORD(lParam);
|
|---|
| 1670 | point.y = (SHORT)HIWORD(lParam);
|
|---|
| 1671 |
|
|---|
| 1672 | retvalue = HandleNCHitTest(point);
|
|---|
| 1673 | #if 0 //CB: let the Corel people fix the bugs first
|
|---|
| 1674 | if(retvalue == HTMENU)
|
|---|
| 1675 | MENU_TrackMouseMenuBar_MouseMove(Win32Hwnd,point,TRUE);
|
|---|
| 1676 | else
|
|---|
| 1677 | MENU_TrackMouseMenuBar_MouseMove(Win32Hwnd,point,FALSE);
|
|---|
| 1678 | #endif
|
|---|
| 1679 | return retvalue;
|
|---|
| 1680 | }
|
|---|
| 1681 |
|
|---|
| 1682 | case WM_SYSCOMMAND:
|
|---|
| 1683 | {
|
|---|
| 1684 | POINT point;
|
|---|
| 1685 |
|
|---|
| 1686 | point.x = LOWORD(lParam);
|
|---|
| 1687 | point.y = HIWORD(lParam);
|
|---|
| 1688 | return HandleSysCommand(wParam,&point);
|
|---|
| 1689 | }
|
|---|
| 1690 |
|
|---|
| 1691 | case WM_SYSKEYDOWN:
|
|---|
| 1692 | if(wParam == VK_F4) /* try to close the window */
|
|---|
| 1693 | {
|
|---|
| 1694 | Win32BaseWindow *window = GetTopParent();
|
|---|
| 1695 | if(window && !(window->getClass()->getStyle() & CS_NOCLOSE))
|
|---|
| 1696 | PostMessageA(window->getWindowHandle(), WM_SYSCOMMAND, SC_CLOSE, 0);
|
|---|
| 1697 | return 0;
|
|---|
| 1698 | }
|
|---|
| 1699 |
|
|---|
| 1700 | Win32BaseWindow *siblingWindow;
|
|---|
| 1701 | HWND sibling;
|
|---|
| 1702 | char nameBuffer [40], mnemonic;
|
|---|
| 1703 | int nameLength;
|
|---|
| 1704 |
|
|---|
| 1705 | GetWindowTextA (nameBuffer, 40);
|
|---|
| 1706 |
|
|---|
| 1707 | // search all sibling to see it this key is their mnemonic
|
|---|
| 1708 | sibling = GetWindow (GW_HWNDFIRST);
|
|---|
| 1709 | while (sibling != 0) {
|
|---|
| 1710 | siblingWindow = GetWindowFromHandle (sibling);
|
|---|
| 1711 | nameLength = siblingWindow->GetWindowTextA (nameBuffer, 40);
|
|---|
| 1712 |
|
|---|
| 1713 | // find the siblings mnemonic
|
|---|
| 1714 | mnemonic = '\0';
|
|---|
| 1715 | for (int i=0 ; i<nameLength ; i++) {
|
|---|
| 1716 | if (IsDBCSLeadByte(nameBuffer[i])) {
|
|---|
| 1717 | // Skip DBCS
|
|---|
| 1718 | continue;
|
|---|
| 1719 | }
|
|---|
| 1720 | if (nameBuffer [i] == '&') {
|
|---|
| 1721 | mnemonic = nameBuffer [i+1];
|
|---|
| 1722 | if ((mnemonic >= 'a') && (mnemonic <= 'z'))
|
|---|
| 1723 | mnemonic -= 32; // make it uppercase
|
|---|
| 1724 | break; // stop searching
|
|---|
| 1725 | }
|
|---|
| 1726 | }
|
|---|
| 1727 |
|
|---|
| 1728 | // key matches siblings mnemonic, send mouseclick
|
|---|
| 1729 | if (mnemonic == (char) wParam) {
|
|---|
| 1730 | siblingWindow->SendInternalMessageA (BM_CLICK, 0, 0);
|
|---|
| 1731 | }
|
|---|
| 1732 |
|
|---|
| 1733 | sibling = siblingWindow->GetNextWindow (GW_HWNDNEXT);
|
|---|
| 1734 | }
|
|---|
| 1735 |
|
|---|
| 1736 | return 0;
|
|---|
| 1737 |
|
|---|
| 1738 | #if 0 //CB: todo: MSDN docu: Windown handles these messages and not WM_SYSCHAR (the code below doesn't work)
|
|---|
| 1739 | case WM_KEYDOWN:
|
|---|
| 1740 | case WM_KEYUP:
|
|---|
| 1741 | case WM_SYSKEYDOWN:
|
|---|
| 1742 | case WM_SYSKEYUP:
|
|---|
| 1743 | #endif
|
|---|
| 1744 |
|
|---|
| 1745 | case WM_SYSCHAR:
|
|---|
| 1746 | {
|
|---|
| 1747 | int iMenuSysKey = 0;
|
|---|
| 1748 | if (wParam == VK_RETURN && (getStyle() & WS_MINIMIZE))
|
|---|
| 1749 | {
|
|---|
| 1750 | PostMessageA(getWindowHandle(), WM_SYSCOMMAND,
|
|---|
| 1751 | (WPARAM)SC_RESTORE, 0L );
|
|---|
| 1752 | break;
|
|---|
| 1753 | }
|
|---|
| 1754 | if((HIWORD(lParam) & KEYDATA_ALT) && wParam)
|
|---|
| 1755 | {
|
|---|
| 1756 | if (wParam == VK_TAB || wParam == VK_ESCAPE || wParam == VK_F4)
|
|---|
| 1757 | break;
|
|---|
| 1758 | if (wParam == VK_SPACE && (getStyle() & WS_CHILD)) {
|
|---|
| 1759 | getParent()->SendMessageA(Msg, wParam, lParam );
|
|---|
| 1760 | }
|
|---|
| 1761 | else SendMessageA(WM_SYSCOMMAND, (WPARAM)SC_KEYMENU, (LPARAM)(DWORD)wParam );
|
|---|
| 1762 | }
|
|---|
| 1763 | #if 0
|
|---|
| 1764 | else /* check for Ctrl-Esc */
|
|---|
| 1765 | if (wParam != VK_ESCAPE) MessageBeep(0);
|
|---|
| 1766 | break;
|
|---|
| 1767 | #endif
|
|---|
| 1768 | }
|
|---|
| 1769 |
|
|---|
| 1770 | case WM_SETHOTKEY:
|
|---|
| 1771 | hotkey = wParam;
|
|---|
| 1772 | return 1; //CB: always successful
|
|---|
| 1773 |
|
|---|
| 1774 | case WM_GETHOTKEY:
|
|---|
| 1775 | return hotkey;
|
|---|
| 1776 |
|
|---|
| 1777 | case WM_CONTEXTMENU:
|
|---|
| 1778 | if ((dwStyle & WS_CHILD) && getParent())
|
|---|
| 1779 | getParent()->SendInternalMessageA(WM_CONTEXTMENU,wParam,lParam);
|
|---|
| 1780 | return 0;
|
|---|
| 1781 |
|
|---|
| 1782 | case WM_SHOWWINDOW:
|
|---|
| 1783 | if (!lParam) return 0; /* sent from ShowWindow */
|
|---|
| 1784 | if (!(dwStyle & WS_POPUP) || !owner) return 0;
|
|---|
| 1785 | if ((dwStyle & WS_VISIBLE) && wParam) return 0;
|
|---|
| 1786 | else if (!(dwStyle & WS_VISIBLE) && !wParam) return 0;
|
|---|
| 1787 | ShowWindow(wParam ? SW_SHOW:SW_HIDE);
|
|---|
| 1788 | return 0;
|
|---|
| 1789 |
|
|---|
| 1790 | case WM_CANCELMODE:
|
|---|
| 1791 | if (getParent() == windowDesktop) EndMenu();
|
|---|
| 1792 | if (GetCapture() == Win32Hwnd) ReleaseCapture();
|
|---|
| 1793 | return 0;
|
|---|
| 1794 |
|
|---|
| 1795 | case WM_DROPOBJECT:
|
|---|
| 1796 | return DRAG_FILE;
|
|---|
| 1797 |
|
|---|
| 1798 | case WM_QUERYDROPOBJECT:
|
|---|
| 1799 | return (dwExStyle & WS_EX_ACCEPTFILES) ? 1:0;
|
|---|
| 1800 |
|
|---|
| 1801 | case WM_QUERYDRAGICON:
|
|---|
| 1802 | {
|
|---|
| 1803 | HICON hDragIcon = windowClass->getCursor();
|
|---|
| 1804 | UINT len;
|
|---|
| 1805 |
|
|---|
| 1806 | if(hDragIcon) return (LRESULT)hDragIcon;
|
|---|
| 1807 | for(len = 1; len < 64; len++)
|
|---|
| 1808 | {
|
|---|
| 1809 | hDragIcon = LoadIconA(hInstance,MAKEINTRESOURCEA(len));
|
|---|
| 1810 | if(hDragIcon)
|
|---|
| 1811 | return (LRESULT)hDragIcon;
|
|---|
| 1812 | }
|
|---|
| 1813 | return (LRESULT)LoadIconA(0,IDI_APPLICATIONA);
|
|---|
| 1814 | }
|
|---|
| 1815 |
|
|---|
| 1816 | case WM_QUERYOPEN:
|
|---|
| 1817 | case WM_QUERYENDSESSION:
|
|---|
| 1818 | return 1;
|
|---|
| 1819 |
|
|---|
| 1820 | case WM_NOTIFYFORMAT:
|
|---|
| 1821 | return IsWindowUnicode() ? NFR_UNICODE:NFR_ANSI;
|
|---|
| 1822 |
|
|---|
| 1823 | case WM_SETICON:
|
|---|
| 1824 | case WM_GETICON:
|
|---|
| 1825 | {
|
|---|
| 1826 | LRESULT result = 0;
|
|---|
| 1827 |
|
|---|
| 1828 | /* Set the appropriate icon members in the window structure. */
|
|---|
| 1829 | if (wParam == ICON_SMALL)
|
|---|
| 1830 | {
|
|---|
| 1831 | result = hIconSm;
|
|---|
| 1832 | if (Msg == WM_SETICON)
|
|---|
| 1833 | hIconSm = (HICON)lParam;
|
|---|
| 1834 | }
|
|---|
| 1835 | else
|
|---|
| 1836 | {
|
|---|
| 1837 | result = hIcon;
|
|---|
| 1838 | if (Msg == WM_SETICON)
|
|---|
| 1839 | {
|
|---|
| 1840 | hIcon = (HICON)lParam;
|
|---|
| 1841 | if ((dwStyle & WS_CAPTION) == WS_CAPTION)
|
|---|
| 1842 | OSLibWinSetIcon(OS2Hwnd,hIcon);
|
|---|
| 1843 | }
|
|---|
| 1844 | }
|
|---|
| 1845 | if ((Msg == WM_SETICON) && ((dwStyle & WS_CAPTION) == WS_CAPTION))
|
|---|
| 1846 | HandleNCPaint((HRGN)1);
|
|---|
| 1847 |
|
|---|
| 1848 | return result;
|
|---|
| 1849 | }
|
|---|
| 1850 |
|
|---|
| 1851 | case WM_HELP:
|
|---|
| 1852 | if (getParent()) getParent()->SendInternalMessageA(Msg,wParam,lParam);
|
|---|
| 1853 | break;
|
|---|
| 1854 |
|
|---|
| 1855 | case WM_NOTIFY:
|
|---|
| 1856 | return 0; //comctl32 controls expect this
|
|---|
| 1857 |
|
|---|
| 1858 | default:
|
|---|
| 1859 | return 0;
|
|---|
| 1860 | }
|
|---|
| 1861 | return 0;
|
|---|
| 1862 | }
|
|---|
| 1863 | //******************************************************************************
|
|---|
| 1864 | //******************************************************************************
|
|---|
| 1865 | LRESULT Win32BaseWindow::DefWindowProcW(UINT Msg, WPARAM wParam, LPARAM lParam)
|
|---|
| 1866 | {
|
|---|
| 1867 | switch(Msg)
|
|---|
| 1868 | {
|
|---|
| 1869 | case WM_GETTEXTLENGTH:
|
|---|
| 1870 | if(windowNameW) {
|
|---|
| 1871 | return lstrlenW(windowNameW);
|
|---|
| 1872 | }
|
|---|
| 1873 | else return 0;
|
|---|
| 1874 |
|
|---|
| 1875 | case WM_GETTEXT:
|
|---|
| 1876 | if (!lParam || !wParam) return 0;
|
|---|
| 1877 | if (!windowNameW) ((LPWSTR)lParam)[0] = 0;
|
|---|
| 1878 | else lstrcpynW((LPWSTR)lParam,windowNameW,wParam);
|
|---|
| 1879 | return min((windowNameW ? lstrlenW(windowNameW) : 0),wParam);
|
|---|
| 1880 |
|
|---|
| 1881 | case WM_SETTEXT:
|
|---|
| 1882 | {
|
|---|
| 1883 | LPWSTR lpsz = (LPWSTR)lParam;
|
|---|
| 1884 |
|
|---|
| 1885 | if(windowNameA) free(windowNameA);
|
|---|
| 1886 | if(windowNameW) free(windowNameW);
|
|---|
| 1887 | if (lParam)
|
|---|
| 1888 | {
|
|---|
| 1889 | // Wide
|
|---|
| 1890 | int wndNameLength = lstrlenW(lpsz);
|
|---|
| 1891 | windowNameW = (LPWSTR)_smalloc((wndNameLength+1)*sizeof(WCHAR));
|
|---|
| 1892 | lstrcpyW(windowNameW,lpsz);
|
|---|
| 1893 | // Ascii
|
|---|
| 1894 | LPSTR tmp = HEAP_strdupWtoA(GetProcessHeap(), 0, lpsz);
|
|---|
| 1895 | if(tmp) {
|
|---|
| 1896 | long tmpLength = strlen( tmp );
|
|---|
| 1897 | windowNameA = (LPSTR)_smalloc(tmpLength+1);
|
|---|
| 1898 | strcpy(windowNameA,tmp);
|
|---|
| 1899 | windowNameA[tmpLength] = 0; // need ?
|
|---|
| 1900 | HEAP_free(tmp);
|
|---|
| 1901 | }
|
|---|
| 1902 | else {
|
|---|
| 1903 | windowNameA = (LPSTR)_smalloc(1);
|
|---|
| 1904 | windowNameA[0] = 0;
|
|---|
| 1905 | }
|
|---|
| 1906 | }
|
|---|
| 1907 | else
|
|---|
| 1908 | {
|
|---|
| 1909 | windowNameA = NULL;
|
|---|
| 1910 | windowNameW = NULL;
|
|---|
| 1911 | }
|
|---|
| 1912 | dprintf(("WM_SETTEXT of %x\n",Win32Hwnd));
|
|---|
| 1913 | if ((dwStyle & WS_CAPTION) == WS_CAPTION)
|
|---|
| 1914 | {
|
|---|
| 1915 | HandleNCPaint((HRGN)1);
|
|---|
| 1916 | if(hTaskList) {
|
|---|
| 1917 | OSLibWinChangeTaskList(hTaskList, OS2Hwnd, getWindowNameA(), (getStyle() & WS_VISIBLE) ? 1 : 0);
|
|---|
| 1918 | }
|
|---|
| 1919 | }
|
|---|
| 1920 |
|
|---|
| 1921 | return TRUE;
|
|---|
| 1922 | }
|
|---|
| 1923 |
|
|---|
| 1924 | default:
|
|---|
| 1925 | return DefWindowProcA(Msg, wParam, lParam);
|
|---|
| 1926 | }
|
|---|
| 1927 | }
|
|---|
| 1928 | //******************************************************************************
|
|---|
| 1929 | //******************************************************************************
|
|---|
| 1930 | LRESULT Win32BaseWindow::SendMessageA(ULONG Msg, WPARAM wParam, LPARAM lParam)
|
|---|
| 1931 | {
|
|---|
| 1932 | //if the destination window is created by this process & thread, call window proc directly
|
|---|
| 1933 | if(dwProcessId == currentProcessId && dwThreadId == GetCurrentThreadId()) {
|
|---|
| 1934 | return SendInternalMessageA(Msg, wParam, lParam);
|
|---|
| 1935 | }
|
|---|
| 1936 | //otherwise use WinSendMsg to send it to the right process/thread
|
|---|
| 1937 | dprintf(("SendMessages (inter-process) %x %x %x %x", getWindowHandle(), Msg, wParam, lParam));
|
|---|
| 1938 | return OSLibSendMessage(getOS2WindowHandle(), Msg, wParam, lParam, FALSE);
|
|---|
| 1939 | }
|
|---|
| 1940 | //******************************************************************************
|
|---|
| 1941 | //******************************************************************************
|
|---|
| 1942 | LRESULT Win32BaseWindow::SendMessageW(ULONG Msg, WPARAM wParam, LPARAM lParam)
|
|---|
| 1943 | {
|
|---|
| 1944 | //if the destination window is created by this process & thread, call window proc directly
|
|---|
| 1945 | if(dwProcessId == currentProcessId && dwThreadId == GetCurrentThreadId()) {
|
|---|
| 1946 | return SendInternalMessageW(Msg, wParam, lParam);
|
|---|
| 1947 | }
|
|---|
| 1948 | //otherwise use WinSendMsg to send it to the right process/thread
|
|---|
| 1949 | return OSLibSendMessage(getOS2WindowHandle(), Msg, wParam, lParam, TRUE);
|
|---|
| 1950 | }
|
|---|
| 1951 | //******************************************************************************
|
|---|
| 1952 | //Called as a result of an OS/2 message or called from a class method
|
|---|
| 1953 | //******************************************************************************
|
|---|
| 1954 | LRESULT Win32BaseWindow::SendInternalMessageA(ULONG Msg, WPARAM wParam, LPARAM lParam)
|
|---|
| 1955 | {
|
|---|
| 1956 | LRESULT rc;
|
|---|
| 1957 | HWND hwnd = getWindowHandle();
|
|---|
| 1958 | BOOL fInternalMsgBackup = fInternalMsg;
|
|---|
| 1959 |
|
|---|
| 1960 | //if the destination window was created by this process & thread, call window proc directly
|
|---|
| 1961 | if(dwProcessId != currentProcessId || dwThreadId != GetCurrentThreadId()) {
|
|---|
| 1962 | dprintf(("SendMessages (inter-process) %x %x %x %x", getWindowHandle(), Msg, wParam, lParam));
|
|---|
| 1963 | return OSLibSendMessage(getOS2WindowHandle(), Msg, wParam, lParam, FALSE);
|
|---|
| 1964 | }
|
|---|
| 1965 |
|
|---|
| 1966 | DebugPrintMessage(getWindowHandle(), Msg, wParam, lParam, FALSE, TRUE);
|
|---|
| 1967 |
|
|---|
| 1968 | CallWindowHookProc(WH_CALLWNDPROC, Msg, wParam, lParam, FALSE);
|
|---|
| 1969 |
|
|---|
| 1970 | fInternalMsg = TRUE;
|
|---|
| 1971 | switch(Msg)
|
|---|
| 1972 | {
|
|---|
| 1973 | case WM_CREATE:
|
|---|
| 1974 | {
|
|---|
| 1975 | if(CallWindowProcA(win32wndproc, getWindowHandle(), WM_CREATE, 0, lParam) == -1) {
|
|---|
| 1976 | dprintf(("WM_CREATE returned -1\n"));
|
|---|
| 1977 | rc = -1; //don't create window
|
|---|
| 1978 | break;
|
|---|
| 1979 | }
|
|---|
| 1980 | rc = 0;
|
|---|
| 1981 | break;
|
|---|
| 1982 | }
|
|---|
| 1983 | case WM_LBUTTONDOWN:
|
|---|
| 1984 | case WM_MBUTTONDOWN:
|
|---|
| 1985 | case WM_RBUTTONDOWN:
|
|---|
| 1986 | {
|
|---|
| 1987 | if (getParent())
|
|---|
| 1988 | {
|
|---|
| 1989 | POINTS pt = MAKEPOINTS(lParam);
|
|---|
| 1990 | POINT point;
|
|---|
| 1991 |
|
|---|
| 1992 | point.x = pt.x;
|
|---|
| 1993 | point.y = pt.y;
|
|---|
| 1994 | MapWindowPoints(getWindowHandle(), getParent()->getWindowHandle(), &point, 1);
|
|---|
| 1995 | NotifyParent(Msg,wParam,MAKELPARAM(point.x,point.y));
|
|---|
| 1996 | }
|
|---|
| 1997 | rc = win32wndproc(getWindowHandle(), Msg, wParam, lParam);
|
|---|
| 1998 | break;
|
|---|
| 1999 | }
|
|---|
| 2000 | case WM_NCHITTEST:
|
|---|
| 2001 | rc = lastHitTestVal = win32wndproc(getWindowHandle(), WM_NCHITTEST, wParam, lParam);
|
|---|
| 2002 | break;
|
|---|
| 2003 |
|
|---|
| 2004 | case WM_DESTROY:
|
|---|
| 2005 | rc = win32wndproc(getWindowHandle(), WM_DESTROY, 0, 0);
|
|---|
| 2006 | break;
|
|---|
| 2007 |
|
|---|
| 2008 | default:
|
|---|
| 2009 | rc = CallWindowProcA(win32wndproc, getWindowHandle(), Msg, wParam, lParam);
|
|---|
| 2010 | break;
|
|---|
| 2011 | }
|
|---|
| 2012 | if(!::IsWindow(hwnd)) {
|
|---|
| 2013 | //window might have been destroyed by now. (this pointer invalid)
|
|---|
| 2014 | //we must return immediately
|
|---|
| 2015 | //(MS Visual C++ install heap corruption)
|
|---|
| 2016 | //TODO: could happen in several places here!!!!
|
|---|
| 2017 | return rc;
|
|---|
| 2018 | }
|
|---|
| 2019 | fInternalMsg = fInternalMsgBackup;
|
|---|
| 2020 | return rc;
|
|---|
| 2021 | }
|
|---|
| 2022 | //******************************************************************************
|
|---|
| 2023 | //Called as a result of an OS/2 message or called from a class method
|
|---|
| 2024 | //******************************************************************************
|
|---|
| 2025 | LRESULT Win32BaseWindow::SendInternalMessageW(ULONG Msg, WPARAM wParam, LPARAM lParam)
|
|---|
| 2026 | {
|
|---|
| 2027 | LRESULT rc;
|
|---|
| 2028 | HWND hwnd = getWindowHandle();
|
|---|
| 2029 | BOOL fInternalMsgBackup = fInternalMsg;
|
|---|
| 2030 |
|
|---|
| 2031 | //if the destination window was created by this process & thread, call window proc directly
|
|---|
| 2032 | if(dwProcessId != currentProcessId || dwThreadId != GetCurrentThreadId()) {
|
|---|
| 2033 | dprintf(("SendMessages (inter-process) %x %x %x %x", getWindowHandle(), Msg, wParam, lParam));
|
|---|
| 2034 | return OSLibSendMessage(getOS2WindowHandle(), Msg, wParam, lParam, FALSE);
|
|---|
| 2035 | }
|
|---|
| 2036 |
|
|---|
| 2037 | DebugPrintMessage(getWindowHandle(), Msg, wParam, lParam, TRUE, TRUE);
|
|---|
| 2038 |
|
|---|
| 2039 | CallWindowHookProc(WH_CALLWNDPROC, Msg, wParam, lParam, TRUE);
|
|---|
| 2040 |
|
|---|
| 2041 | fInternalMsg = TRUE;
|
|---|
| 2042 | switch(Msg)
|
|---|
| 2043 | {
|
|---|
| 2044 | case WM_CREATE:
|
|---|
| 2045 | {
|
|---|
| 2046 | if(CallWindowProcW(win32wndproc, getWindowHandle(), WM_CREATE, 0, lParam) == -1) {
|
|---|
| 2047 | dprintf(("WM_CREATE returned -1\n"));
|
|---|
| 2048 | rc = -1; //don't create window
|
|---|
| 2049 | break;
|
|---|
| 2050 | }
|
|---|
| 2051 | rc = 0;
|
|---|
| 2052 | break;
|
|---|
| 2053 | }
|
|---|
| 2054 | case WM_LBUTTONDOWN:
|
|---|
| 2055 | case WM_MBUTTONDOWN:
|
|---|
| 2056 | case WM_RBUTTONDOWN:
|
|---|
| 2057 | NotifyParent(Msg, wParam, lParam);
|
|---|
| 2058 | rc = win32wndproc(getWindowHandle(), Msg, wParam, lParam);
|
|---|
| 2059 | break;
|
|---|
| 2060 |
|
|---|
| 2061 | case WM_NCHITTEST:
|
|---|
| 2062 | rc = lastHitTestVal = win32wndproc(getWindowHandle(), WM_NCHITTEST, wParam, lParam);
|
|---|
| 2063 | break;
|
|---|
| 2064 |
|
|---|
| 2065 | case WM_DESTROY:
|
|---|
| 2066 | rc = win32wndproc(getWindowHandle(), WM_DESTROY, 0, 0);
|
|---|
| 2067 | break;
|
|---|
| 2068 | default:
|
|---|
| 2069 | rc = CallWindowProcW(win32wndproc, getWindowHandle(), Msg, wParam, lParam);
|
|---|
| 2070 | break;
|
|---|
| 2071 | }
|
|---|
| 2072 | if(!::IsWindow(hwnd)) {
|
|---|
| 2073 | //window might have been destroyed by now. (this pointer invalid)
|
|---|
| 2074 | //we must return immediately
|
|---|
| 2075 | //(MS Visual C++ install heap corruption)
|
|---|
| 2076 | //TODO: could happen in several places here!!!!
|
|---|
| 2077 | return rc;
|
|---|
| 2078 | }
|
|---|
| 2079 | fInternalMsg = fInternalMsgBackup;
|
|---|
| 2080 | return rc;
|
|---|
| 2081 | }
|
|---|
| 2082 | //******************************************************************************
|
|---|
| 2083 | //******************************************************************************
|
|---|
| 2084 | void Win32BaseWindow::CallWindowHookProc(ULONG hooktype, ULONG Msg, WPARAM wParam, LPARAM lParam, BOOL fUnicode)
|
|---|
| 2085 | {
|
|---|
| 2086 | CWPSTRUCT cwp;
|
|---|
| 2087 |
|
|---|
| 2088 | cwp.lParam = lParam;
|
|---|
| 2089 | cwp.wParam = wParam;
|
|---|
| 2090 | cwp.message = Msg;
|
|---|
| 2091 | cwp.hwnd = getWindowHandle();
|
|---|
| 2092 |
|
|---|
| 2093 | switch(hooktype) {
|
|---|
| 2094 | case WH_CALLWNDPROC:
|
|---|
| 2095 | if(fUnicode) {
|
|---|
| 2096 | HOOK_CallHooksW(WH_CALLWNDPROC, HC_ACTION, 1, (LPARAM)&cwp);
|
|---|
| 2097 | }
|
|---|
| 2098 | else HOOK_CallHooksA(WH_CALLWNDPROC, HC_ACTION, 1, (LPARAM)&cwp);
|
|---|
| 2099 | break;
|
|---|
| 2100 | }
|
|---|
| 2101 | }
|
|---|
| 2102 | //******************************************************************************
|
|---|
| 2103 | //TODO: Do this more efficiently
|
|---|
| 2104 | //******************************************************************************
|
|---|
| 2105 | LRESULT Win32BaseWindow::BroadcastMessageA(int type, UINT msg, WPARAM wParam, LPARAM lParam)
|
|---|
| 2106 | {
|
|---|
| 2107 | Win32BaseWindow *window;
|
|---|
| 2108 | HWND hwnd = WNDHANDLE_MAGIC_HIGHWORD;
|
|---|
| 2109 |
|
|---|
| 2110 | dprintf(("BroadCastMessageA %x %x %x", msg, wParam, lParam, GetFS()));
|
|---|
| 2111 |
|
|---|
| 2112 | for(int i=0;i<MAX_WINDOW_HANDLES;i++) {
|
|---|
| 2113 | window = GetWindowFromHandle(hwnd++);
|
|---|
| 2114 | if(window) {
|
|---|
| 2115 | if ((window->getStyle() & WS_POPUP) || ((window->getStyle() & WS_CAPTION) == WS_CAPTION))
|
|---|
| 2116 | {
|
|---|
| 2117 | if(type == BROADCAST_SEND) {
|
|---|
| 2118 | ::SendMessageA(window->getWindowHandle(), msg, wParam, lParam);
|
|---|
| 2119 | }
|
|---|
| 2120 | else PostMessageA(window->getWindowHandle(), msg, wParam, lParam);
|
|---|
| 2121 | }
|
|---|
| 2122 | }
|
|---|
| 2123 | }
|
|---|
| 2124 | return 0;
|
|---|
| 2125 | }
|
|---|
| 2126 | //******************************************************************************
|
|---|
| 2127 | //TODO: Do this more efficiently
|
|---|
| 2128 | //******************************************************************************
|
|---|
| 2129 | LRESULT Win32BaseWindow::BroadcastMessageW(int type, UINT msg, WPARAM wParam, LPARAM lParam)
|
|---|
| 2130 | {
|
|---|
| 2131 | Win32BaseWindow *window;
|
|---|
| 2132 | HWND hwnd = WNDHANDLE_MAGIC_HIGHWORD;
|
|---|
| 2133 |
|
|---|
| 2134 | dprintf(("BroadCastMessageW %x %x %x", msg, wParam, lParam));
|
|---|
| 2135 |
|
|---|
| 2136 | for(int i=0;i<MAX_WINDOW_HANDLES;i++) {
|
|---|
| 2137 | window = GetWindowFromHandle(hwnd++);
|
|---|
| 2138 | if(window) {
|
|---|
| 2139 | if ((window->getStyle() & WS_POPUP) || ((window->getStyle() & WS_CAPTION) == WS_CAPTION))
|
|---|
| 2140 | {
|
|---|
| 2141 | if(type == BROADCAST_SEND) {
|
|---|
| 2142 | ::SendMessageW(window->getWindowHandle(), msg, wParam, lParam);
|
|---|
| 2143 | }
|
|---|
| 2144 | else PostMessageW(window->getWindowHandle(), msg, wParam, lParam);
|
|---|
| 2145 | }
|
|---|
| 2146 | }
|
|---|
| 2147 | }
|
|---|
| 2148 | return 0;
|
|---|
| 2149 | }
|
|---|
| 2150 | //******************************************************************************
|
|---|
| 2151 | //******************************************************************************
|
|---|
| 2152 | void Win32BaseWindow::NotifyParent(UINT Msg, WPARAM wParam, LPARAM lParam)
|
|---|
| 2153 | {
|
|---|
| 2154 | Win32BaseWindow *window = this;
|
|---|
| 2155 | Win32BaseWindow *parentwindow;
|
|---|
| 2156 |
|
|---|
| 2157 | while(window)
|
|---|
| 2158 | {
|
|---|
| 2159 | if(window->getStyle() & WS_CHILD && !(window->getExStyle() & WS_EX_NOPARENTNOTIFY) )
|
|---|
| 2160 | {
|
|---|
| 2161 | /* Notify the parent window only */
|
|---|
| 2162 | parentwindow = window->getParent();
|
|---|
| 2163 | if(parentwindow) {
|
|---|
| 2164 | parentwindow->SendInternalMessageA(WM_PARENTNOTIFY, MAKEWPARAM(Msg, getWindowId()), lParam );
|
|---|
| 2165 | }
|
|---|
| 2166 | }
|
|---|
| 2167 | else break;
|
|---|
| 2168 |
|
|---|
| 2169 | window = parentwindow;
|
|---|
| 2170 | }
|
|---|
| 2171 | }
|
|---|
| 2172 | //******************************************************************************
|
|---|
| 2173 | // Returns the big or small icon for the window, falling back to the
|
|---|
| 2174 | // class as windows does.
|
|---|
| 2175 | //******************************************************************************
|
|---|
| 2176 | HICON Win32BaseWindow::IconForWindow(WPARAM fType)
|
|---|
| 2177 | {
|
|---|
| 2178 | HICON hWndIcon;
|
|---|
| 2179 |
|
|---|
| 2180 | if (fType == ICON_BIG)
|
|---|
| 2181 | {
|
|---|
| 2182 | if (hIcon)
|
|---|
| 2183 | hWndIcon = hIcon;
|
|---|
| 2184 | else
|
|---|
| 2185 | if (windowClass && windowClass->getIcon())
|
|---|
| 2186 | hWndIcon = windowClass->getIcon();
|
|---|
| 2187 | else
|
|---|
| 2188 | if (!(dwStyle & DS_MODALFRAME))
|
|---|
| 2189 | hWndIcon = LoadImageA(0,MAKEINTRESOURCEA(OIC_ODINICON),IMAGE_ICON,0,0,LR_DEFAULTCOLOR);
|
|---|
| 2190 | else hWndIcon = 0;
|
|---|
| 2191 | }
|
|---|
| 2192 | else
|
|---|
| 2193 | {
|
|---|
| 2194 | if (hIconSm)
|
|---|
| 2195 | hWndIcon = hIconSm;
|
|---|
| 2196 | else
|
|---|
| 2197 | if (hIcon)
|
|---|
| 2198 | hWndIcon = hIcon;
|
|---|
| 2199 | else
|
|---|
| 2200 | if (windowClass && windowClass->getIconSm())
|
|---|
| 2201 | hWndIcon = windowClass->getIconSm();
|
|---|
| 2202 | else
|
|---|
| 2203 | if (windowClass && windowClass->getIcon())
|
|---|
| 2204 | hWndIcon = windowClass->getIcon();
|
|---|
| 2205 | else
|
|---|
| 2206 | if (!(dwStyle & DS_MODALFRAME))
|
|---|
| 2207 | hWndIcon = LoadImageA(0,MAKEINTRESOURCEA(OIC_ODINICON),IMAGE_ICON,0,0,LR_DEFAULTCOLOR);
|
|---|
| 2208 | else hWndIcon = 0;
|
|---|
| 2209 | }
|
|---|
| 2210 |
|
|---|
| 2211 | return hWndIcon;
|
|---|
| 2212 | }
|
|---|
| 2213 | //******************************************************************************
|
|---|
| 2214 | //******************************************************************************
|
|---|
| 2215 | BOOL Win32BaseWindow::ShowWindow(ULONG nCmdShow)
|
|---|
| 2216 | {
|
|---|
| 2217 | ULONG swp = 0;
|
|---|
| 2218 | HWND hWinAfter;
|
|---|
| 2219 | BOOL rc,wasVisible,showFlag;
|
|---|
| 2220 | RECT newPos = {0, 0, 0, 0};
|
|---|
| 2221 |
|
|---|
| 2222 | dprintf(("ShowWindow %x %x", getWindowHandle(), nCmdShow));
|
|---|
| 2223 | wasVisible = (getStyle() & WS_VISIBLE) != 0;
|
|---|
| 2224 |
|
|---|
| 2225 | switch(nCmdShow)
|
|---|
| 2226 | {
|
|---|
| 2227 | case SW_HIDE:
|
|---|
| 2228 | if (!wasVisible) goto END;
|
|---|
| 2229 | swp |= SWP_HIDEWINDOW | SWP_NOSIZE | SWP_NOMOVE |
|
|---|
| 2230 | SWP_NOACTIVATE | SWP_NOZORDER;
|
|---|
| 2231 | break;
|
|---|
| 2232 |
|
|---|
| 2233 | case SW_SHOWMINNOACTIVE:
|
|---|
| 2234 | swp |= SWP_NOACTIVATE | SWP_NOZORDER;
|
|---|
| 2235 | /* fall through */
|
|---|
| 2236 | case SW_SHOWMINIMIZED:
|
|---|
| 2237 | swp |= SWP_SHOWWINDOW;
|
|---|
| 2238 | /* fall through */
|
|---|
| 2239 | case SW_MINIMIZE:
|
|---|
| 2240 | if(!(getStyle() & WS_CHILD))
|
|---|
| 2241 | {
|
|---|
| 2242 | if( !(getStyle() & WS_MINIMIZE) )
|
|---|
| 2243 | swp |= MinMaximize(SW_MINIMIZE, &newPos );
|
|---|
| 2244 |
|
|---|
| 2245 | swp |= SWP_NOSIZE | SWP_NOMOVE | SWP_HIDEWINDOW;
|
|---|
| 2246 | }
|
|---|
| 2247 | else {
|
|---|
| 2248 | swp |= SWP_FRAMECHANGED;
|
|---|
| 2249 | if( !(getStyle() & WS_MINIMIZE) ) {
|
|---|
| 2250 | swp |= MinMaximize(SW_MINIMIZE, &newPos );
|
|---|
| 2251 | fMinMaxChange = TRUE; //-> invalidate entire window in WM_CALCINVALIDRECT
|
|---|
| 2252 | }
|
|---|
| 2253 | else swp |= SWP_NOSIZE | SWP_NOMOVE;
|
|---|
| 2254 | }
|
|---|
| 2255 | break;
|
|---|
| 2256 |
|
|---|
| 2257 | case SW_SHOWMAXIMIZED: /* same as SW_MAXIMIZE */
|
|---|
| 2258 | swp |= SWP_SHOWWINDOW | SWP_FRAMECHANGED;
|
|---|
| 2259 | if( !(getStyle() & WS_MAXIMIZE) ) {
|
|---|
| 2260 | swp |= MinMaximize(SW_MAXIMIZE, &newPos );
|
|---|
| 2261 | fMinMaxChange = TRUE; //-> invalidate entire window in WM_CALCINVALIDRECT
|
|---|
| 2262 | }
|
|---|
| 2263 | else swp |= SWP_NOSIZE | SWP_NOMOVE;
|
|---|
| 2264 | break;
|
|---|
| 2265 |
|
|---|
| 2266 | case SW_SHOWNA:
|
|---|
| 2267 | swp |= SWP_NOACTIVATE | SWP_NOZORDER;
|
|---|
| 2268 | /* fall through */
|
|---|
| 2269 | case SW_SHOW:
|
|---|
| 2270 | swp |= SWP_SHOWWINDOW | SWP_NOSIZE | SWP_NOMOVE;
|
|---|
| 2271 |
|
|---|
| 2272 | /*
|
|---|
| 2273 | * ShowWindow has a little peculiar behavior that if the
|
|---|
| 2274 | * window is already the topmost window, it will not
|
|---|
| 2275 | * activate it.
|
|---|
| 2276 | */
|
|---|
| 2277 | if (::GetTopWindow((HWND)0)==getWindowHandle() && (wasVisible || GetActiveWindow() == getWindowHandle()))
|
|---|
| 2278 | swp |= SWP_NOACTIVATE;
|
|---|
| 2279 |
|
|---|
| 2280 | break;
|
|---|
| 2281 |
|
|---|
| 2282 | case SW_SHOWNOACTIVATE:
|
|---|
| 2283 | swp |= SWP_NOZORDER;
|
|---|
| 2284 | if (GetActiveWindow())
|
|---|
| 2285 | swp |= SWP_NOACTIVATE;
|
|---|
| 2286 | /* fall through */
|
|---|
| 2287 | case SW_SHOWNORMAL: /* same as SW_NORMAL: */
|
|---|
| 2288 | case SW_SHOWDEFAULT: /* FIXME: should have its own handler */
|
|---|
| 2289 | case SW_RESTORE:
|
|---|
| 2290 | //TODO: WIN_RESTORE_MAX flag!!!!!!!!!!!!!!
|
|---|
| 2291 | swp |= SWP_SHOWWINDOW | SWP_FRAMECHANGED;
|
|---|
| 2292 |
|
|---|
| 2293 | if( getStyle() & (WS_MINIMIZE | WS_MAXIMIZE) ) {
|
|---|
| 2294 | swp |= MinMaximize(SW_RESTORE, &newPos );
|
|---|
| 2295 | fMinMaxChange = TRUE; //-> invalidate entire window in WM_CALCINVALIDRECT
|
|---|
| 2296 | }
|
|---|
| 2297 | else swp |= SWP_NOSIZE | SWP_NOMOVE;
|
|---|
| 2298 | break;
|
|---|
| 2299 | }
|
|---|
| 2300 |
|
|---|
| 2301 | showFlag = (nCmdShow != SW_HIDE);
|
|---|
| 2302 | if (showFlag != wasVisible)
|
|---|
| 2303 | {
|
|---|
| 2304 | SendInternalMessageA(WM_SHOWWINDOW, showFlag, 0 );
|
|---|
| 2305 | if (!::IsWindow( getWindowHandle() )) goto END;
|
|---|
| 2306 | }
|
|---|
| 2307 |
|
|---|
| 2308 | /* We can't activate a child window */
|
|---|
| 2309 | if((getStyle() & WS_CHILD) && !(getExStyle() & WS_EX_MDICHILD))
|
|---|
| 2310 | swp |= SWP_NOACTIVATE | SWP_NOZORDER;
|
|---|
| 2311 |
|
|---|
| 2312 | SetWindowPos(HWND_TOP, newPos.left, newPos.top, newPos.right, newPos.bottom, LOWORD(swp));
|
|---|
| 2313 |
|
|---|
| 2314 | if(!(swp & SWP_NOACTIVATE)) {
|
|---|
| 2315 | OSLibWinSetActiveWindow(OS2Hwnd);
|
|---|
| 2316 | }
|
|---|
| 2317 |
|
|---|
| 2318 | if (flags & WIN_NEED_SIZE)
|
|---|
| 2319 | {
|
|---|
| 2320 | /* should happen only in CreateWindowEx() */
|
|---|
| 2321 | int wParam = SIZE_RESTORED;
|
|---|
| 2322 |
|
|---|
| 2323 | flags &= ~WIN_NEED_SIZE;
|
|---|
| 2324 | if (dwStyle & WS_MAXIMIZE)
|
|---|
| 2325 | wParam = SIZE_MAXIMIZED;
|
|---|
| 2326 | else
|
|---|
| 2327 | if (dwStyle & WS_MINIMIZE)
|
|---|
| 2328 | wParam = SIZE_MINIMIZED;
|
|---|
| 2329 |
|
|---|
| 2330 | SendInternalMessageA(WM_SIZE, wParam,
|
|---|
| 2331 | MAKELONG(rectClient.right-rectClient.left,
|
|---|
| 2332 | rectClient.bottom-rectClient.top));
|
|---|
| 2333 | SendInternalMessageA(WM_MOVE,0,MAKELONG(rectClient.left,rectClient.top));
|
|---|
| 2334 | }
|
|---|
| 2335 | //testestest
|
|---|
| 2336 | //temporary workaround for file dialogs with template dialog child
|
|---|
| 2337 | //they don't redraw when switching directories
|
|---|
| 2338 | //For some reason the new child's (syslistview32) update rectangle stays
|
|---|
| 2339 | //empty after its parent is made visible with ShowWindow
|
|---|
| 2340 | //TODO: find real cause
|
|---|
| 2341 | if(!wasVisible) {
|
|---|
| 2342 | InvalidateRect(getWindowHandle(), NULL, TRUE);
|
|---|
| 2343 | }
|
|---|
| 2344 | //testestest
|
|---|
| 2345 | END:
|
|---|
| 2346 | fMinMaxChange = FALSE;
|
|---|
| 2347 | return wasVisible;
|
|---|
| 2348 | }
|
|---|
| 2349 | //******************************************************************************
|
|---|
| 2350 | //******************************************************************************
|
|---|
| 2351 | BOOL Win32BaseWindow::SetWindowPos(HWND hwndInsertAfter, int x, int y, int cx, int cy, UINT fuFlags)
|
|---|
| 2352 | {
|
|---|
| 2353 | BOOL rc = FALSE;
|
|---|
| 2354 | Win32BaseWindow *window;
|
|---|
| 2355 | HWND hParent = 0;
|
|---|
| 2356 | RECT oldClientRect = rectClient;
|
|---|
| 2357 |
|
|---|
| 2358 | if (fuFlags &
|
|---|
| 2359 | ~(SWP_NOSIZE | SWP_NOMOVE | SWP_NOZORDER |
|
|---|
| 2360 | SWP_NOREDRAW | SWP_NOACTIVATE | SWP_FRAMECHANGED |
|
|---|
| 2361 | SWP_SHOWWINDOW | SWP_HIDEWINDOW | SWP_NOCOPYBITS |
|
|---|
| 2362 | SWP_NOOWNERZORDER | SWP_NOSENDCHANGING | SWP_DEFERERASE |
|
|---|
| 2363 | SWP_NOCLIENTSIZE | SWP_NOCLIENTMOVE))
|
|---|
| 2364 | {
|
|---|
| 2365 | dprintf(("ERROR: SetWindowPos; UNKNOWN flag"));
|
|---|
| 2366 | return FALSE;
|
|---|
| 2367 | }
|
|---|
| 2368 |
|
|---|
| 2369 | if( fuFlags & (SWP_DEFERERASE | SWP_NOCLIENTSIZE | SWP_NOCLIENTMOVE)) {
|
|---|
| 2370 | dprintf(("WARNING: SetWindowPos; unsupported flag"));
|
|---|
| 2371 | }
|
|---|
| 2372 |
|
|---|
| 2373 | if(IsWindowDestroyed()) {
|
|---|
| 2374 | //changing the position of a window that's being destroyed can cause crashes in PMMERGE
|
|---|
| 2375 | dprintf(("SetWindowPos; window already destroyed"));
|
|---|
| 2376 | return TRUE;
|
|---|
| 2377 | }
|
|---|
| 2378 | #if 0
|
|---|
| 2379 | /* Fix redundant flags */
|
|---|
| 2380 | if(getStyle() & WS_VISIBLE) {
|
|---|
| 2381 | fuFlags &= ~SWP_SHOWWINDOW;
|
|---|
| 2382 | }
|
|---|
| 2383 | else
|
|---|
| 2384 | {
|
|---|
| 2385 | if (!(fuFlags & SWP_SHOWWINDOW))
|
|---|
| 2386 | fuFlags |= SWP_NOREDRAW;
|
|---|
| 2387 | fuFlags &= ~SWP_HIDEWINDOW;
|
|---|
| 2388 | }
|
|---|
| 2389 |
|
|---|
| 2390 | if(cx < 0) cx = 0;
|
|---|
| 2391 | if(cy < 0) cy = 0;
|
|---|
| 2392 |
|
|---|
| 2393 | if((rectWindow.right - rectWindow.left == cx) && (rectWindow.bottom - rectWindow.top == cy)) {
|
|---|
| 2394 | fuFlags |= SWP_NOSIZE; /* Already the right size */
|
|---|
| 2395 | }
|
|---|
| 2396 |
|
|---|
| 2397 | if((rectWindow.left == x) && (rectWindow.top == y)) {
|
|---|
| 2398 | fuFlags |= SWP_NOMOVE; /* Already the right position */
|
|---|
| 2399 | }
|
|---|
| 2400 |
|
|---|
| 2401 | if(getWindowHandle() == GetActiveWindow()) {
|
|---|
| 2402 | fuFlags |= SWP_NOACTIVATE; /* Already active */
|
|---|
| 2403 | }
|
|---|
| 2404 | else
|
|---|
| 2405 | if((getStyle() & (WS_POPUP | WS_CHILD)) != WS_CHILD )
|
|---|
| 2406 | {
|
|---|
| 2407 | if(!(fuFlags & SWP_NOACTIVATE)) /* Bring to the top when activating */
|
|---|
| 2408 | {
|
|---|
| 2409 | fuFlags &= ~SWP_NOZORDER;
|
|---|
| 2410 | hwndInsertAfter = HWND_TOP;
|
|---|
| 2411 | }
|
|---|
| 2412 | }
|
|---|
| 2413 | #endif
|
|---|
| 2414 |
|
|---|
| 2415 | if(!fCreateSetWindowPos)
|
|---|
| 2416 | {//don't change size; modify internal structures only
|
|---|
| 2417 | //TODO: not 100% correct yet (activate)
|
|---|
| 2418 | if(!(fuFlags & SWP_NOZORDER)) {
|
|---|
| 2419 | hwndLinkAfter = hwndInsertAfter;
|
|---|
| 2420 | }
|
|---|
| 2421 | if(!(fuFlags & SWP_NOMOVE)) {
|
|---|
| 2422 | rectWindow.bottom = (rectWindow.bottom - rectWindow.top) + y;
|
|---|
| 2423 | rectWindow.top = y;
|
|---|
| 2424 | rectWindow.right = (rectWindow.right - rectWindow.left) + x;
|
|---|
| 2425 | rectWindow.left = x;
|
|---|
| 2426 | }
|
|---|
| 2427 | if(!(fuFlags & SWP_NOSIZE)) {
|
|---|
| 2428 | rectWindow.bottom = rectWindow.top + cy;
|
|---|
| 2429 | rectWindow.right = rectWindow.left + cx;
|
|---|
| 2430 | }
|
|---|
| 2431 | return TRUE;
|
|---|
| 2432 | }
|
|---|
| 2433 |
|
|---|
| 2434 | WINDOWPOS wpos;
|
|---|
| 2435 | SWP swp, swpOld;
|
|---|
| 2436 | wpos.flags = fuFlags;
|
|---|
| 2437 | wpos.cy = cy;
|
|---|
| 2438 | wpos.cx = cx;
|
|---|
| 2439 | wpos.x = x;
|
|---|
| 2440 | wpos.y = y;
|
|---|
| 2441 | wpos.hwndInsertAfter = hwndInsertAfter;
|
|---|
| 2442 | wpos.hwnd = getWindowHandle();
|
|---|
| 2443 |
|
|---|
| 2444 | if(~fuFlags & (SWP_NOMOVE | SWP_NOSIZE))
|
|---|
| 2445 | {
|
|---|
| 2446 | if (isChild())
|
|---|
| 2447 | {
|
|---|
| 2448 | if(!getParent()) {
|
|---|
| 2449 | dprintf(("WARNING: Win32BaseWindow::SetWindowPos window %x is child but has no parent!!", getWindowHandle()));
|
|---|
| 2450 | }
|
|---|
| 2451 | }
|
|---|
| 2452 | OSLibWinQueryWindowPos(OS2Hwnd, &swpOld);
|
|---|
| 2453 | }
|
|---|
| 2454 |
|
|---|
| 2455 | if(getParent()) {
|
|---|
| 2456 | OSLibMapWINDOWPOStoSWP(&wpos, &swp, &swpOld, getParent()->getWindowHeight(),
|
|---|
| 2457 | getParent()->getClientRectPtr()->left,
|
|---|
| 2458 | getParent()->getClientRectPtr()->top,
|
|---|
| 2459 | OS2Hwnd);
|
|---|
| 2460 | }
|
|---|
| 2461 | else OSLibMapWINDOWPOStoSWP(&wpos, &swp, &swpOld, OSLibQueryScreenHeight(), 0, 0, OS2Hwnd);
|
|---|
| 2462 | if (swp.fl == 0) {
|
|---|
| 2463 | if(fuFlags & SWP_FRAMECHANGED)
|
|---|
| 2464 | {
|
|---|
| 2465 | NotifyFrameChanged(&wpos, &oldClientRect);
|
|---|
| 2466 | }
|
|---|
| 2467 | return TRUE;
|
|---|
| 2468 | }
|
|---|
| 2469 |
|
|---|
| 2470 | // if ((swp.fl & SWPOS_ZORDER) && (swp.hwndInsertBehind > HWNDOS_BOTTOM))
|
|---|
| 2471 | if ((swp.hwndInsertBehind > HWNDOS_BOTTOM))
|
|---|
| 2472 | {
|
|---|
| 2473 | Win32BaseWindow *wndBehind = Win32BaseWindow::GetWindowFromHandle(swp.hwndInsertBehind);
|
|---|
| 2474 | if(wndBehind) {
|
|---|
| 2475 | swp.hwndInsertBehind = wndBehind->getOS2WindowHandle();
|
|---|
| 2476 | }
|
|---|
| 2477 | else {
|
|---|
| 2478 | dprintf(("ERROR: SetWindowPos: hwndInsertBehind %x invalid!",swp.hwndInsertBehind));
|
|---|
| 2479 | swp.hwndInsertBehind = 0;
|
|---|
| 2480 | }
|
|---|
| 2481 | }
|
|---|
| 2482 | swp.hwnd = OS2Hwnd;
|
|---|
| 2483 |
|
|---|
| 2484 | if(fuFlags & SWP_SHOWWINDOW && !IsWindowVisible()) {
|
|---|
| 2485 | setStyle(getStyle() | WS_VISIBLE);
|
|---|
| 2486 | if(hTaskList) {
|
|---|
| 2487 | dprintf(("Adding window %x to tasklist", getWindowHandle()));
|
|---|
| 2488 | OSLibWinChangeTaskList(hTaskList, OS2Hwnd, getWindowNameA(), 1);
|
|---|
| 2489 | }
|
|---|
| 2490 | }
|
|---|
| 2491 | else
|
|---|
| 2492 | if((fuFlags & SWP_HIDEWINDOW) && IsWindowVisible()) {
|
|---|
| 2493 | setStyle(getStyle() & ~WS_VISIBLE);
|
|---|
| 2494 | if(hTaskList && !(getStyle() & WS_MINIMIZE)) {
|
|---|
| 2495 | dprintf(("Removing window %x from tasklist", getWindowHandle()));
|
|---|
| 2496 | OSLibWinChangeTaskList(hTaskList, OS2Hwnd, getWindowNameA(), 0);
|
|---|
| 2497 | }
|
|---|
| 2498 | }
|
|---|
| 2499 | dprintf (("WinSetWindowPos %x %x (%d,%d)(%d,%d) %x", swp.hwnd, swp.hwndInsertBehind, swp.x, swp.y, swp.cx, swp.cy, swp.fl));
|
|---|
| 2500 | rc = OSLibWinSetMultWindowPos(&swp, 1);
|
|---|
| 2501 |
|
|---|
| 2502 | if(rc == FALSE)
|
|---|
| 2503 | {
|
|---|
| 2504 | dprintf(("OSLibWinSetMultWindowPos failed! Error %x",OSLibWinGetLastError()));
|
|---|
| 2505 | return 0;
|
|---|
| 2506 | }
|
|---|
| 2507 |
|
|---|
| 2508 | //Restore window origin of parent window with CS_OWNDC style
|
|---|
| 2509 | //(fixes paint offset problems in Opera windows)
|
|---|
| 2510 | if(getParent() && getParent()->isOwnDC()) {
|
|---|
| 2511 | dprintfOrigin(getParent()->getOwnDC());
|
|---|
| 2512 | selectClientArea(getParent(), getParent()->getOwnDC());
|
|---|
| 2513 | }
|
|---|
| 2514 |
|
|---|
| 2515 | if((fuFlags & SWP_FRAMECHANGED) && (fuFlags & (SWP_NOMOVE | SWP_NOSIZE) == (SWP_NOMOVE | SWP_NOSIZE)))
|
|---|
| 2516 | {
|
|---|
| 2517 | NotifyFrameChanged(&wpos, &oldClientRect);
|
|---|
| 2518 | }
|
|---|
| 2519 | return (rc);
|
|---|
| 2520 | }
|
|---|
| 2521 | //******************************************************************************
|
|---|
| 2522 | //Called by ScrollWindowEx (dc.cpp) to notify child window that it has moved
|
|---|
| 2523 | //******************************************************************************
|
|---|
| 2524 | BOOL Win32BaseWindow::ScrollWindow(int dx, int dy)
|
|---|
| 2525 | {
|
|---|
| 2526 | rectWindow.left += dx;
|
|---|
| 2527 | rectWindow.right += dx;
|
|---|
| 2528 | rectWindow.top += dy;
|
|---|
| 2529 | rectWindow.bottom += dy;
|
|---|
| 2530 | SendInternalMessageA(WM_MOVE, 0, MAKELONG(rectClient.left, rectClient.top));
|
|---|
| 2531 | return TRUE;
|
|---|
| 2532 | }
|
|---|
| 2533 | //******************************************************************************
|
|---|
| 2534 | //******************************************************************************
|
|---|
| 2535 | void Win32BaseWindow::NotifyFrameChanged(WINDOWPOS *wpos, RECT *oldClientRect)
|
|---|
| 2536 | {
|
|---|
| 2537 | HRGN hrgn, hrgnClient;
|
|---|
| 2538 | RECT rect;
|
|---|
| 2539 |
|
|---|
| 2540 | MsgFormatFrame(NULL);
|
|---|
| 2541 |
|
|---|
| 2542 | if(RECT_WIDTH(rectClient) != RECT_WIDTH(*oldClientRect) ||
|
|---|
| 2543 | RECT_HEIGHT(rectClient) != RECT_HEIGHT(*oldClientRect))
|
|---|
| 2544 | {
|
|---|
| 2545 | wpos->flags &= ~(SWP_NOSIZE|SWP_NOCLIENTSIZE);
|
|---|
| 2546 | wpos->cx = RECT_WIDTH(rectWindow);
|
|---|
| 2547 | wpos->cy = RECT_HEIGHT(rectWindow);
|
|---|
| 2548 | }
|
|---|
| 2549 |
|
|---|
| 2550 | if(rectClient.left != oldClientRect->left ||
|
|---|
| 2551 | rectClient.top != oldClientRect->top)
|
|---|
| 2552 | {
|
|---|
| 2553 | wpos->flags &= ~(SWP_NOMOVE|SWP_NOCLIENTMOVE);
|
|---|
| 2554 | wpos->x = rectWindow.left;
|
|---|
| 2555 | wpos->y = rectWindow.top;
|
|---|
| 2556 | }
|
|---|
| 2557 |
|
|---|
| 2558 | WINDOWPOS wpOld = *wpos;
|
|---|
| 2559 | SendInternalMessageA(WM_WINDOWPOSCHANGING, 0, (LPARAM)wpos);
|
|---|
| 2560 |
|
|---|
| 2561 | if ((wpos->hwndInsertAfter != wpOld.hwndInsertAfter) ||
|
|---|
| 2562 | (wpos->x != wpOld.x) || (wpos->y != wpOld.y) || (wpos->cx != wpOld.cx) || (wpos->cy != wpOld.cy) || (wpos->flags != wpOld.flags))
|
|---|
| 2563 | {
|
|---|
| 2564 | dprintf(("WARNING, NotifyFrameChanged: TODO -> adjust flags!!!!"));
|
|---|
| 2565 | SetWindowPos(wpos->hwndInsertAfter, wpos->x, wpos->y, wpos->cx, wpos->cy, wpos->flags | SWP_NOSENDCHANGING);
|
|---|
| 2566 | }
|
|---|
| 2567 | else SendInternalMessageA(WM_WINDOWPOSCHANGED, 0, (LPARAM)wpos);
|
|---|
| 2568 |
|
|---|
| 2569 | //Calculate invalid areas
|
|---|
| 2570 | rect = rectWindow;
|
|---|
| 2571 | OffsetRect(&rect, -rectWindow.left, -rectWindow.top);
|
|---|
| 2572 | hrgn = CreateRectRgnIndirect(&rect);
|
|---|
| 2573 | if (!hrgn) {
|
|---|
| 2574 | dprintf(("ERROR: NotifyFrameChanged, CreateRectRgnIndirect failed!!"));
|
|---|
| 2575 | return;
|
|---|
| 2576 | }
|
|---|
| 2577 | rect = rectClient;
|
|---|
| 2578 | hrgnClient = CreateRectRgnIndirect(&rect);
|
|---|
| 2579 | if (!hrgn) {
|
|---|
| 2580 | dprintf(("ERROR: NotifyFrameChanged, CreateRectRgnIndirect failed!!"));
|
|---|
| 2581 | return;
|
|---|
| 2582 | }
|
|---|
| 2583 | CombineRgn(hrgn, hrgn, hrgnClient, RGN_DIFF);
|
|---|
| 2584 | DeleteObject(hrgnClient);
|
|---|
| 2585 |
|
|---|
| 2586 | if(!EqualRect(oldClientRect, &rectClient)) {
|
|---|
| 2587 | UnionRect(oldClientRect, oldClientRect, &rectClient);
|
|---|
| 2588 | hrgnClient = CreateRectRgnIndirect(oldClientRect);
|
|---|
| 2589 | if (!hrgn) {
|
|---|
| 2590 | dprintf(("ERROR: NotifyFrameChanged, CreateRectRgnIndirect failed!!"));
|
|---|
| 2591 | return;
|
|---|
| 2592 | }
|
|---|
| 2593 | CombineRgn(hrgn, hrgn, hrgnClient, RGN_OR);
|
|---|
| 2594 | DeleteObject(hrgnClient);
|
|---|
| 2595 | }
|
|---|
| 2596 | RedrawWindow(getWindowHandle(), NULL, hrgn, RDW_ALLCHILDREN |
|
|---|
| 2597 | RDW_INVALIDATE | RDW_ERASE | RDW_FRAME);
|
|---|
| 2598 | DeleteObject(hrgn);
|
|---|
| 2599 | }
|
|---|
| 2600 | //******************************************************************************
|
|---|
| 2601 | //TODO: Check how this api really works in NT
|
|---|
| 2602 | //******************************************************************************
|
|---|
| 2603 | BOOL Win32BaseWindow::SetWindowPlacement(WINDOWPLACEMENT *wndpl)
|
|---|
| 2604 | {
|
|---|
| 2605 | dprintf(("SetWindowPlacement %x min (%d,%d)", getWindowHandle(), wndpl->ptMinPosition.x, wndpl->ptMinPosition.y));
|
|---|
| 2606 | dprintf(("SetWindowPlacement %x max (%d,%d)", getWindowHandle(), wndpl->ptMaxPosition.x, wndpl->ptMaxPosition.y));
|
|---|
| 2607 | dprintf(("SetWindowPlacement %x norm (%d,%d)(%d,%d)", getWindowHandle(), wndpl->rcNormalPosition.left, wndpl->rcNormalPosition.top, wndpl->rcNormalPosition.right, wndpl->rcNormalPosition.bottom));
|
|---|
| 2608 | windowpos.ptMinPosition = wndpl->ptMinPosition;
|
|---|
| 2609 | windowpos.ptMaxPosition = wndpl->ptMaxPosition;
|
|---|
| 2610 | windowpos.rcNormalPosition = wndpl->rcNormalPosition;
|
|---|
| 2611 |
|
|---|
| 2612 | if(getStyle() & WS_MINIMIZE )
|
|---|
| 2613 | {
|
|---|
| 2614 | //TODO: Why can't this be (0,0)?
|
|---|
| 2615 | if(wndpl->flags & WPF_SETMINPOSITION && !(!windowpos.ptMinPosition.x && !windowpos.ptMinPosition.y)) {
|
|---|
| 2616 | SetWindowPos(0, windowpos.ptMinPosition.x, windowpos.ptMinPosition.y,
|
|---|
| 2617 | 0, 0, SWP_NOSIZE | SWP_NOZORDER | SWP_NOACTIVATE);
|
|---|
| 2618 | }
|
|---|
| 2619 | }
|
|---|
| 2620 | else
|
|---|
| 2621 | if(getStyle() & WS_MAXIMIZE )
|
|---|
| 2622 | {
|
|---|
| 2623 | //TODO: Why can't this be (0,0)?
|
|---|
| 2624 | if(windowpos.ptMaxPosition.x != 0 || windowpos.ptMaxPosition.y != 0 )
|
|---|
| 2625 | SetWindowPos(0, windowpos.ptMaxPosition.x, windowpos.ptMaxPosition.y,
|
|---|
| 2626 | 0, 0, SWP_NOSIZE | SWP_NOZORDER | SWP_NOACTIVATE);
|
|---|
| 2627 | }
|
|---|
| 2628 | else {
|
|---|
| 2629 | SetWindowPos(0, windowpos.rcNormalPosition.left, windowpos.rcNormalPosition.top,
|
|---|
| 2630 | windowpos.rcNormalPosition.right - windowpos.rcNormalPosition.left,
|
|---|
| 2631 | windowpos.rcNormalPosition.bottom - windowpos.rcNormalPosition.top,
|
|---|
| 2632 | SWP_NOZORDER | SWP_NOACTIVATE );
|
|---|
| 2633 | }
|
|---|
| 2634 | ShowWindow(wndpl->showCmd);
|
|---|
| 2635 | if( ::IsWindow(getWindowHandle()) && getStyle() & WS_MINIMIZE )
|
|---|
| 2636 | {
|
|---|
| 2637 | /* SDK: ...valid only the next time... */
|
|---|
| 2638 | if(wndpl->flags & WPF_RESTORETOMAXIMIZED)
|
|---|
| 2639 | setFlags(getFlags() | WIN_RESTORE_MAX);
|
|---|
| 2640 | }
|
|---|
| 2641 | return TRUE;
|
|---|
| 2642 | }
|
|---|
| 2643 | //******************************************************************************
|
|---|
| 2644 | //******************************************************************************
|
|---|
| 2645 | BOOL Win32BaseWindow::GetWindowPlacement(LPWINDOWPLACEMENT wndpl)
|
|---|
| 2646 | {
|
|---|
| 2647 | wndpl->length = sizeof(*wndpl);
|
|---|
| 2648 | if(getStyle() & WS_MINIMIZE )
|
|---|
| 2649 | wndpl->showCmd = SW_SHOWMINIMIZED;
|
|---|
| 2650 | else wndpl->showCmd = (getStyle() & WS_MAXIMIZE) ? SW_SHOWMAXIMIZED : SW_SHOWNORMAL;
|
|---|
| 2651 |
|
|---|
| 2652 | //TODO: Verify if this is correct -> SDK docs claim this flag must always be set to 0
|
|---|
| 2653 | if(getFlags() & WIN_RESTORE_MAX )
|
|---|
| 2654 | wndpl->flags = WPF_RESTORETOMAXIMIZED;
|
|---|
| 2655 | else wndpl->flags = 0;
|
|---|
| 2656 |
|
|---|
| 2657 | wndpl->ptMinPosition = windowpos.ptMinPosition;
|
|---|
| 2658 | wndpl->ptMaxPosition = windowpos.ptMaxPosition;
|
|---|
| 2659 | //Must be in parent coordinates (or screen if no parent); verified in NT4, SP6
|
|---|
| 2660 | wndpl->rcNormalPosition = rectWindow;
|
|---|
| 2661 |
|
|---|
| 2662 | return TRUE;
|
|---|
| 2663 | }
|
|---|
| 2664 | //******************************************************************************
|
|---|
| 2665 | //Also destroys all the child windows (destroy children first, parent last)
|
|---|
| 2666 | //******************************************************************************
|
|---|
| 2667 | BOOL Win32BaseWindow::DestroyWindow()
|
|---|
| 2668 | {
|
|---|
| 2669 | HWND hwnd = getWindowHandle();
|
|---|
| 2670 |
|
|---|
| 2671 | dprintf(("DestroyWindow %x", hwnd));
|
|---|
| 2672 |
|
|---|
| 2673 | /* Call hooks */
|
|---|
| 2674 | if(HOOK_CallHooksA( WH_CBT, HCBT_DESTROYWND, getWindowHandle(), 0L))
|
|---|
| 2675 | {
|
|---|
| 2676 | return FALSE;
|
|---|
| 2677 | }
|
|---|
| 2678 |
|
|---|
| 2679 | if(!(getStyle() & WS_CHILD) && getOwner() == NULL)
|
|---|
| 2680 | {
|
|---|
| 2681 | HOOK_CallHooksA(WH_SHELL, HSHELL_WINDOWDESTROYED, getWindowHandle(), 0L);
|
|---|
| 2682 | /* FIXME: clean up palette - see "Internals" p.352 */
|
|---|
| 2683 | }
|
|---|
| 2684 |
|
|---|
| 2685 | if((getStyle() & WS_CHILD) && !(getExStyle() & WS_EX_NOPARENTNOTIFY))
|
|---|
| 2686 | {
|
|---|
| 2687 | if(getParent() && getParent()->IsWindowDestroyed() == FALSE)
|
|---|
| 2688 | {
|
|---|
| 2689 | /* Notify the parent window only */
|
|---|
| 2690 | getParent()->SendMessageA(WM_PARENTNOTIFY, MAKEWPARAM(WM_DESTROY, getWindowId()), (LPARAM)getWindowHandle());
|
|---|
| 2691 | if(!::IsWindow(hwnd) )
|
|---|
| 2692 | {
|
|---|
| 2693 | return TRUE;
|
|---|
| 2694 | }
|
|---|
| 2695 | }
|
|---|
| 2696 | //// else DebugInt3();
|
|---|
| 2697 | }
|
|---|
| 2698 | /* Hide the window */
|
|---|
| 2699 | if(IsWindowVisible())
|
|---|
| 2700 | {
|
|---|
| 2701 | SetWindowPos(0, 0, 0, 0, 0, SWP_HIDEWINDOW |
|
|---|
| 2702 | SWP_NOACTIVATE|SWP_NOZORDER|SWP_NOMOVE|SWP_NOSIZE);
|
|---|
| 2703 | if(!::IsWindow(hwnd))
|
|---|
| 2704 | {
|
|---|
| 2705 | return TRUE;
|
|---|
| 2706 | }
|
|---|
| 2707 | }
|
|---|
| 2708 | dprintf(("DestroyWindow %x -> HIDDEN", hwnd));
|
|---|
| 2709 |
|
|---|
| 2710 | fDestroyWindowCalled = TRUE;
|
|---|
| 2711 | return OSLibWinDestroyWindow(OS2Hwnd);
|
|---|
| 2712 | }
|
|---|
| 2713 | //******************************************************************************
|
|---|
| 2714 | //******************************************************************************
|
|---|
| 2715 | Win32BaseWindow *Win32BaseWindow::getParent()
|
|---|
| 2716 | {
|
|---|
| 2717 | Win32BaseWindow *wndparent = (Win32BaseWindow *)ChildWindow::getParentOfChild();
|
|---|
| 2718 | return ((ULONG)wndparent == (ULONG)windowDesktop) ? NULL : wndparent;
|
|---|
| 2719 | }
|
|---|
| 2720 | //******************************************************************************
|
|---|
| 2721 | //Note: does not set last error if no parent (verified in NT4, SP6)
|
|---|
| 2722 | //******************************************************************************
|
|---|
| 2723 | HWND Win32BaseWindow::GetParent()
|
|---|
| 2724 | {
|
|---|
| 2725 | if((!(getStyle() & (WS_POPUP|WS_CHILD)))) {
|
|---|
| 2726 | return 0;
|
|---|
| 2727 | }
|
|---|
| 2728 |
|
|---|
| 2729 | Win32BaseWindow *wndparent = (Win32BaseWindow *)ChildWindow::getParentOfChild();
|
|---|
| 2730 |
|
|---|
| 2731 | if(getStyle() & WS_CHILD) {
|
|---|
| 2732 | if(wndparent) {
|
|---|
| 2733 | return wndparent->getWindowHandle();
|
|---|
| 2734 | }
|
|---|
| 2735 | dprintf(("WARNING: GetParent: WS_CHILD but no parent!!"));
|
|---|
| 2736 | DebugInt3();
|
|---|
| 2737 | return 0;
|
|---|
| 2738 | }
|
|---|
| 2739 | else return (getOwner()) ? getOwner()->getWindowHandle() : 0;
|
|---|
| 2740 | }
|
|---|
| 2741 | //******************************************************************************
|
|---|
| 2742 | //******************************************************************************
|
|---|
| 2743 | HWND Win32BaseWindow::SetParent(HWND hwndNewParent)
|
|---|
| 2744 | {
|
|---|
| 2745 | HWND oldhwnd;
|
|---|
| 2746 | Win32BaseWindow *newparent;
|
|---|
| 2747 | Win32BaseWindow *oldparent = (Win32BaseWindow *)ChildWindow::getParentOfChild();
|
|---|
| 2748 | BOOL fShow = FALSE;
|
|---|
| 2749 |
|
|---|
| 2750 | if(oldparent) {
|
|---|
| 2751 | oldhwnd = oldparent->getWindowHandle();
|
|---|
| 2752 | oldparent->removeChild(this);
|
|---|
| 2753 | }
|
|---|
| 2754 | else oldhwnd = 0;
|
|---|
| 2755 |
|
|---|
| 2756 | /* Windows hides the window first, then shows it again
|
|---|
| 2757 | * including the WM_SHOWWINDOW messages and all */
|
|---|
| 2758 | if(fCreated && (getStyle() & WS_VISIBLE)) {
|
|---|
| 2759 | ShowWindow(SW_HIDE);
|
|---|
| 2760 | fShow = TRUE;
|
|---|
| 2761 | }
|
|---|
| 2762 |
|
|---|
| 2763 | newparent = GetWindowFromHandle(hwndNewParent);
|
|---|
| 2764 | if(newparent && !newparent->isDesktopWindow())
|
|---|
| 2765 | {
|
|---|
| 2766 | setParent(newparent);
|
|---|
| 2767 | getParent()->addChild(this);
|
|---|
| 2768 | OSLibWinSetParent(getOS2WindowHandle(), getParent()->getOS2WindowHandle());
|
|---|
| 2769 | if(!(getStyle() & WS_CHILD))
|
|---|
| 2770 | {
|
|---|
| 2771 | //TODO: Send WM_STYLECHANGED msg?
|
|---|
| 2772 | setStyle(getStyle() | WS_CHILD);
|
|---|
| 2773 | if(getWindowId())
|
|---|
| 2774 | {
|
|---|
| 2775 | DestroyMenu( (HMENU) getWindowId() );
|
|---|
| 2776 | setWindowId(0);
|
|---|
| 2777 | }
|
|---|
| 2778 | }
|
|---|
| 2779 | }
|
|---|
| 2780 | else {
|
|---|
| 2781 | setParent(windowDesktop);
|
|---|
| 2782 | windowDesktop->addChild(this);
|
|---|
| 2783 | OSLibWinSetParent(getOS2WindowHandle(), OSLIB_HWND_DESKTOP);
|
|---|
| 2784 |
|
|---|
| 2785 | //TODO: Send WM_STYLECHANGED msg?
|
|---|
| 2786 | setStyle(getStyle() & ~WS_CHILD);
|
|---|
| 2787 | setWindowId(0);
|
|---|
| 2788 | }
|
|---|
| 2789 | /* SetParent additionally needs to make hwndChild the topmost window
|
|---|
| 2790 | in the x-order and send the expected WM_WINDOWPOSCHANGING and
|
|---|
| 2791 | WM_WINDOWPOSCHANGED notification messages.
|
|---|
| 2792 | */
|
|---|
| 2793 | if(fCreated) {
|
|---|
| 2794 | SetWindowPos(HWND_TOPMOST, 0, 0, 0, 0,
|
|---|
| 2795 | SWP_NOACTIVATE|SWP_NOMOVE|SWP_NOSIZE|(fShow? SWP_SHOWWINDOW : 0));
|
|---|
| 2796 |
|
|---|
| 2797 | /* FIXME: a WM_MOVE is also generated (in the DefWindowProc handler
|
|---|
| 2798 | * for WM_WINDOWPOSCHANGED) in Windows, should probably remove SWP_NOMOVE */
|
|---|
| 2799 | }
|
|---|
| 2800 | return oldhwnd;
|
|---|
| 2801 | }
|
|---|
| 2802 | //******************************************************************************
|
|---|
| 2803 | //******************************************************************************
|
|---|
| 2804 | BOOL Win32BaseWindow::IsChild(HWND hwndParent)
|
|---|
| 2805 | {
|
|---|
| 2806 | if(getParent()) {
|
|---|
| 2807 | if(getParent()->getWindowHandle() == hwndParent)
|
|---|
| 2808 | return TRUE;
|
|---|
| 2809 |
|
|---|
| 2810 | return getParent()->IsChild(hwndParent);
|
|---|
| 2811 | }
|
|---|
| 2812 | else return 0;
|
|---|
| 2813 | }
|
|---|
| 2814 | //******************************************************************************
|
|---|
| 2815 | //******************************************************************************
|
|---|
| 2816 | HWND Win32BaseWindow::GetTopWindow()
|
|---|
| 2817 | {
|
|---|
| 2818 | HWND hwndTop;
|
|---|
| 2819 | Win32BaseWindow *topwindow;
|
|---|
| 2820 |
|
|---|
| 2821 | hwndTop = OSLibWinQueryWindow(getOS2WindowHandle(), QWOS_TOP);
|
|---|
| 2822 | if(!isDesktopWindow()) {
|
|---|
| 2823 | topwindow = GetWindowFromOS2Handle(hwndTop);
|
|---|
| 2824 | if(topwindow) {
|
|---|
| 2825 | return topwindow->getWindowHandle();
|
|---|
| 2826 | }
|
|---|
| 2827 | return 0;
|
|---|
| 2828 | }
|
|---|
| 2829 | while(hwndTop) {
|
|---|
| 2830 | topwindow = GetWindowFromOS2Handle(hwndTop);
|
|---|
| 2831 | if(topwindow) {
|
|---|
| 2832 | return topwindow->getWindowHandle();
|
|---|
| 2833 | }
|
|---|
| 2834 | hwndTop = OSLibWinQueryWindow(hwndTop, QWOS_NEXT);
|
|---|
| 2835 | }
|
|---|
| 2836 |
|
|---|
| 2837 | return 0;
|
|---|
| 2838 | }
|
|---|
| 2839 | //******************************************************************************
|
|---|
| 2840 | // Get the top-level parent for a child window.
|
|---|
| 2841 | //******************************************************************************
|
|---|
| 2842 | Win32BaseWindow *Win32BaseWindow::GetTopParent()
|
|---|
| 2843 | {
|
|---|
| 2844 | Win32BaseWindow *window = this;
|
|---|
| 2845 |
|
|---|
| 2846 | while(window && (window->getStyle() & WS_CHILD))
|
|---|
| 2847 | {
|
|---|
| 2848 | window = window->getParent();
|
|---|
| 2849 | }
|
|---|
| 2850 | return window;
|
|---|
| 2851 | }
|
|---|
| 2852 | //******************************************************************************
|
|---|
| 2853 | //TODO: Should not enumerate children that are created during the enumeration!
|
|---|
| 2854 | //******************************************************************************
|
|---|
| 2855 | BOOL Win32BaseWindow::EnumChildWindows(WNDENUMPROC lpfn, LPARAM lParam)
|
|---|
| 2856 | {
|
|---|
| 2857 | BOOL rc = TRUE;
|
|---|
| 2858 | HWND hwnd;
|
|---|
| 2859 | Win32BaseWindow *prevchild = 0, *child = 0;
|
|---|
| 2860 |
|
|---|
| 2861 | dprintf(("EnumChildWindows of %x parameter %x %x (%x)", getWindowHandle(), lpfn, lParam, getFirstChild()));
|
|---|
| 2862 | for (child = (Win32BaseWindow *)getFirstChild(); child; child = (Win32BaseWindow *)child->getNextChild())
|
|---|
| 2863 | {
|
|---|
| 2864 | dprintf(("EnumChildWindows: enumerating child %x (owner %x; parent %x)", child->getWindowHandle(), (child->getOwner()) ? child->getOwner()->getWindowHandle() : 0, getWindowHandle()));
|
|---|
| 2865 | hwnd = child->getWindowHandle();
|
|---|
| 2866 | if(child->getOwner()) {
|
|---|
| 2867 | continue; //shouldn't have an owner (Wine)
|
|---|
| 2868 | }
|
|---|
| 2869 | if(lpfn(hwnd, lParam) == FALSE)
|
|---|
| 2870 | {
|
|---|
| 2871 | rc = FALSE;
|
|---|
| 2872 | break;
|
|---|
| 2873 | }
|
|---|
| 2874 | //check if the window still exists
|
|---|
| 2875 | if(!::IsWindow(hwnd))
|
|---|
| 2876 | {
|
|---|
| 2877 | child = prevchild;
|
|---|
| 2878 | continue;
|
|---|
| 2879 | }
|
|---|
| 2880 | if(child->getFirstChild() != NULL)
|
|---|
| 2881 | {
|
|---|
| 2882 | dprintf(("EnumChildWindows: Enumerate children of %x", child->getWindowHandle()));
|
|---|
| 2883 | if(child->EnumChildWindows(lpfn, lParam) == FALSE)
|
|---|
| 2884 | {
|
|---|
| 2885 | rc = FALSE;
|
|---|
| 2886 | break;
|
|---|
| 2887 | }
|
|---|
| 2888 | }
|
|---|
| 2889 | prevchild = child;
|
|---|
| 2890 | }
|
|---|
| 2891 | return rc;
|
|---|
| 2892 | }
|
|---|
| 2893 | //******************************************************************************
|
|---|
| 2894 | //Enumerate first-level children only and check thread id
|
|---|
| 2895 | //******************************************************************************
|
|---|
| 2896 | BOOL Win32BaseWindow::EnumThreadWindows(DWORD dwThreadId, WNDENUMPROC lpfn, LPARAM lParam)
|
|---|
| 2897 | {
|
|---|
| 2898 | Win32BaseWindow *child = 0;
|
|---|
| 2899 | ULONG tid, pid;
|
|---|
| 2900 | BOOL rc;
|
|---|
| 2901 | HWND hwnd;
|
|---|
| 2902 |
|
|---|
| 2903 | dprintf(("EnumThreadWindows %x %x %x", dwThreadId, lpfn, lParam));
|
|---|
| 2904 |
|
|---|
| 2905 | for (child = (Win32BaseWindow *)getFirstChild(); child; child = (Win32BaseWindow *)child->getNextChild())
|
|---|
| 2906 | {
|
|---|
| 2907 | OSLibWinQueryWindowProcess(child->getOS2WindowHandle(), &pid, &tid);
|
|---|
| 2908 |
|
|---|
| 2909 | if(dwThreadId == tid) {
|
|---|
| 2910 | dprintf2(("EnumThreadWindows: Found Window %x", child->getWindowHandle()));
|
|---|
| 2911 | if((rc = lpfn(child->getWindowHandle(), lParam)) == FALSE) {
|
|---|
| 2912 | break;
|
|---|
| 2913 | }
|
|---|
| 2914 | }
|
|---|
| 2915 | }
|
|---|
| 2916 | return TRUE;
|
|---|
| 2917 | }
|
|---|
| 2918 | //******************************************************************************
|
|---|
| 2919 | //Enumerate first-level children only
|
|---|
| 2920 | //******************************************************************************
|
|---|
| 2921 | BOOL Win32BaseWindow::EnumWindows(WNDENUMPROC lpfn, LPARAM lParam)
|
|---|
| 2922 | {
|
|---|
| 2923 | Win32BaseWindow *child = 0;
|
|---|
| 2924 | BOOL rc;
|
|---|
| 2925 | HWND hwnd;
|
|---|
| 2926 |
|
|---|
| 2927 | dprintf(("EnumWindows %x %x", lpfn, lParam));
|
|---|
| 2928 |
|
|---|
| 2929 | for (child = (Win32BaseWindow *)getFirstChild(); child; child = (Win32BaseWindow *)child->getNextChild())
|
|---|
| 2930 | {
|
|---|
| 2931 | hwnd = child->getWindowHandle();
|
|---|
| 2932 |
|
|---|
| 2933 | dprintf2(("EnumWindows: Found Window %x", child->getWindowHandle()));
|
|---|
| 2934 | if((rc = lpfn(child->getWindowHandle(), lParam)) == FALSE) {
|
|---|
| 2935 | break;
|
|---|
| 2936 | }
|
|---|
| 2937 | }
|
|---|
| 2938 | return TRUE;
|
|---|
| 2939 | }
|
|---|
| 2940 | //******************************************************************************
|
|---|
| 2941 | //******************************************************************************
|
|---|
| 2942 | Win32BaseWindow *Win32BaseWindow::FindWindowById(int id)
|
|---|
| 2943 | {
|
|---|
| 2944 | for (Win32BaseWindow *child = (Win32BaseWindow *)getFirstChild(); child; child = (Win32BaseWindow *)child->getNextChild())
|
|---|
| 2945 | {
|
|---|
| 2946 | if (child->getWindowId() == id)
|
|---|
| 2947 | {
|
|---|
| 2948 | return child;
|
|---|
| 2949 | }
|
|---|
| 2950 | }
|
|---|
| 2951 | return 0;
|
|---|
| 2952 | }
|
|---|
| 2953 | //******************************************************************************
|
|---|
| 2954 | //TODO:
|
|---|
| 2955 | //We assume (for now) that if hwndParent or hwndChildAfter are real window handles, that
|
|---|
| 2956 | //the current process owns them.
|
|---|
| 2957 | //******************************************************************************
|
|---|
| 2958 | HWND Win32BaseWindow::FindWindowEx(HWND hwndParent, HWND hwndChildAfter, ATOM atom, LPSTR lpszWindow)
|
|---|
| 2959 | {
|
|---|
| 2960 | Win32BaseWindow *parent = GetWindowFromHandle(hwndParent);
|
|---|
| 2961 | Win32BaseWindow *child = GetWindowFromHandle(hwndChildAfter);
|
|---|
| 2962 |
|
|---|
| 2963 | dprintf(("FindWindowEx %x %x %x %s", hwndParent, hwndChildAfter, atom, lpszWindow));
|
|---|
| 2964 | if((hwndParent != 0 && !parent) ||
|
|---|
| 2965 | (hwndChildAfter != 0 && !child) ||
|
|---|
| 2966 | (hwndParent == 0 && hwndChildAfter != 0))
|
|---|
| 2967 | {
|
|---|
| 2968 | dprintf(("Win32BaseWindow::FindWindowEx: parent or child not found %x %x", hwndParent, hwndChildAfter));
|
|---|
| 2969 | SetLastError(ERROR_INVALID_WINDOW_HANDLE);
|
|---|
| 2970 | return 0;
|
|---|
| 2971 | }
|
|---|
| 2972 | SetLastError(0);
|
|---|
| 2973 | if(hwndParent != 0)
|
|---|
| 2974 | {//if the current process owns the window, just do a quick search
|
|---|
| 2975 | child = (Win32BaseWindow *)parent->getFirstChild();
|
|---|
| 2976 | if(hwndChildAfter != 0)
|
|---|
| 2977 | {
|
|---|
| 2978 | while(child)
|
|---|
| 2979 | {
|
|---|
| 2980 | if(child->getWindowHandle() == hwndChildAfter)
|
|---|
| 2981 | {
|
|---|
| 2982 | child = (Win32BaseWindow *)child->getNextChild();
|
|---|
| 2983 | break;
|
|---|
| 2984 | }
|
|---|
| 2985 | child = (Win32BaseWindow *)child->getNextChild();
|
|---|
| 2986 | }
|
|---|
| 2987 | }
|
|---|
| 2988 | while(child)
|
|---|
| 2989 | {
|
|---|
| 2990 | //According to Wine, the class doesn't need to be specified
|
|---|
| 2991 | if((!atom || child->getWindowClass()->getAtom() == atom) &&
|
|---|
| 2992 | (!lpszWindow || child->hasWindowName(lpszWindow)))
|
|---|
| 2993 | {
|
|---|
| 2994 | dprintf(("FindWindowEx: Found window %x", child->getWindowHandle()));
|
|---|
| 2995 | return child->getWindowHandle();
|
|---|
| 2996 | }
|
|---|
| 2997 | child = (Win32BaseWindow *)child->getNextChild();
|
|---|
| 2998 | }
|
|---|
| 2999 | }
|
|---|
| 3000 | else {
|
|---|
| 3001 | Win32BaseWindow *wnd;
|
|---|
| 3002 | HWND henum, hwnd;
|
|---|
| 3003 |
|
|---|
| 3004 | henum = OSLibWinBeginEnumWindows(OSLIB_HWND_DESKTOP);
|
|---|
| 3005 | hwnd = OSLibWinGetNextWindow(henum);
|
|---|
| 3006 |
|
|---|
| 3007 | while(hwnd)
|
|---|
| 3008 | {
|
|---|
| 3009 | wnd = GetWindowFromOS2Handle(hwnd);
|
|---|
| 3010 | if(wnd == NULL) {
|
|---|
| 3011 | hwnd = OSLibWinQueryClientWindow(hwnd);
|
|---|
| 3012 | if(hwnd) wnd = GetWindowFromOS2Handle(hwnd);
|
|---|
| 3013 | }
|
|---|
| 3014 |
|
|---|
| 3015 | if(wnd) {
|
|---|
| 3016 | //According to Wine, the class doesn't need to be specified
|
|---|
| 3017 | if((!atom || wnd->getWindowClass()->getAtom() == atom) &&
|
|---|
| 3018 | (!lpszWindow || wnd->hasWindowName(lpszWindow)))
|
|---|
| 3019 | {
|
|---|
| 3020 | OSLibWinEndEnumWindows(henum);
|
|---|
| 3021 | dprintf(("FindWindowEx: Found window %x", wnd->getWindowHandle()));
|
|---|
| 3022 | return wnd->getWindowHandle();
|
|---|
| 3023 | }
|
|---|
| 3024 | }
|
|---|
| 3025 | hwnd = OSLibWinGetNextWindow(henum);
|
|---|
| 3026 | }
|
|---|
| 3027 | OSLibWinEndEnumWindows(henum);
|
|---|
| 3028 | }
|
|---|
| 3029 | SetLastError(ERROR_CANNOT_FIND_WND_CLASS); //TODO: not always correct
|
|---|
| 3030 | return 0;
|
|---|
| 3031 | }
|
|---|
| 3032 | //******************************************************************************
|
|---|
| 3033 | //******************************************************************************
|
|---|
| 3034 | HWND Win32BaseWindow::GetWindow(UINT uCmd)
|
|---|
| 3035 | {
|
|---|
| 3036 | HWND hwndRelated = 0;
|
|---|
| 3037 | Win32BaseWindow *window;
|
|---|
| 3038 |
|
|---|
| 3039 | #if 1
|
|---|
| 3040 | switch(uCmd)
|
|---|
| 3041 | {
|
|---|
| 3042 | case GW_HWNDFIRST:
|
|---|
| 3043 | if(getParent())
|
|---|
| 3044 | {
|
|---|
| 3045 | window = (Win32BaseWindow *)getParent();
|
|---|
| 3046 | hwndRelated = OSLibWinQueryWindow(window->getOS2WindowHandle(), QWOS_TOP);
|
|---|
| 3047 | window = GetWindowFromOS2Handle(hwndRelated);
|
|---|
| 3048 | if(window) {
|
|---|
| 3049 | hwndRelated = window->getWindowHandle();
|
|---|
| 3050 | }
|
|---|
| 3051 | else hwndRelated = 0;
|
|---|
| 3052 | }
|
|---|
| 3053 | else hwndRelated = 0; //TODO: not correct; should get first child in z-order of desktop
|
|---|
| 3054 | break;
|
|---|
| 3055 |
|
|---|
| 3056 | case GW_HWNDLAST:
|
|---|
| 3057 | hwndRelated = OSLibWinQueryWindow(getOS2WindowHandle(), QWOS_BOTTOM);
|
|---|
| 3058 | window = GetWindowFromOS2Handle(hwndRelated);
|
|---|
| 3059 | if(window) {
|
|---|
| 3060 | hwndRelated = window->getWindowHandle();
|
|---|
| 3061 | }
|
|---|
| 3062 | else hwndRelated = 0;
|
|---|
| 3063 | break;
|
|---|
| 3064 |
|
|---|
| 3065 | case GW_HWNDNEXT:
|
|---|
| 3066 | hwndRelated = OSLibWinQueryWindow(getOS2WindowHandle(), QWOS_NEXT);
|
|---|
| 3067 | window = GetWindowFromOS2Handle(hwndRelated);
|
|---|
| 3068 | if(window) {
|
|---|
| 3069 | hwndRelated = window->getWindowHandle();
|
|---|
| 3070 | }
|
|---|
| 3071 | else hwndRelated = 0;
|
|---|
| 3072 | break;
|
|---|
| 3073 |
|
|---|
| 3074 | case GW_HWNDPREV:
|
|---|
| 3075 | hwndRelated = OSLibWinQueryWindow(getOS2WindowHandle(), QWOS_PREV);
|
|---|
| 3076 | window = GetWindowFromOS2Handle(hwndRelated);
|
|---|
| 3077 | if(window) {
|
|---|
| 3078 | hwndRelated = window->getWindowHandle();
|
|---|
| 3079 | }
|
|---|
| 3080 | else hwndRelated = 0;
|
|---|
| 3081 | break;
|
|---|
| 3082 |
|
|---|
| 3083 | case GW_OWNER:
|
|---|
| 3084 | if(getOwner()) {
|
|---|
| 3085 | hwndRelated = getOwner()->getWindowHandle();
|
|---|
| 3086 | }
|
|---|
| 3087 | break;
|
|---|
| 3088 |
|
|---|
| 3089 | case GW_CHILD:
|
|---|
| 3090 | hwndRelated = OSLibWinQueryWindow(getOS2WindowHandle(), QWOS_TOP);
|
|---|
| 3091 | window = GetWindowFromOS2Handle(hwndRelated);
|
|---|
| 3092 | if(window) {
|
|---|
| 3093 | hwndRelated = window->getWindowHandle();
|
|---|
| 3094 | }
|
|---|
| 3095 | else hwndRelated = 0;
|
|---|
| 3096 | break;
|
|---|
| 3097 | }
|
|---|
| 3098 | #else
|
|---|
| 3099 | switch(uCmd)
|
|---|
| 3100 | {
|
|---|
| 3101 | case GW_HWNDFIRST:
|
|---|
| 3102 | if(getParent()) {
|
|---|
| 3103 | window = (Win32BaseWindow *)getParent()->getFirstChild();
|
|---|
| 3104 | hwndRelated = window->getWindowHandle();
|
|---|
| 3105 | }
|
|---|
| 3106 | break;
|
|---|
| 3107 |
|
|---|
| 3108 | case GW_HWNDLAST:
|
|---|
| 3109 | if(!getParent())
|
|---|
| 3110 | {
|
|---|
| 3111 | goto end;
|
|---|
| 3112 | }
|
|---|
| 3113 |
|
|---|
| 3114 | window = this;
|
|---|
| 3115 | while(window->getNextChild())
|
|---|
| 3116 | {
|
|---|
| 3117 | window = (Win32BaseWindow *)window->getNextChild();
|
|---|
| 3118 | }
|
|---|
| 3119 | hwndRelated = window->getWindowHandle();
|
|---|
| 3120 | break;
|
|---|
| 3121 |
|
|---|
| 3122 | case GW_HWNDNEXT:
|
|---|
| 3123 | window = (Win32BaseWindow *)getNextChild();
|
|---|
| 3124 | if(window) {
|
|---|
| 3125 | hwndRelated = window->getWindowHandle();
|
|---|
| 3126 | }
|
|---|
| 3127 | break;
|
|---|
| 3128 |
|
|---|
| 3129 | case GW_HWNDPREV:
|
|---|
| 3130 | if(!getParent())
|
|---|
| 3131 | {
|
|---|
| 3132 | goto end;
|
|---|
| 3133 | }
|
|---|
| 3134 | window = (Win32BaseWindow *)(getParent()->getFirstChild()); /* First sibling */
|
|---|
| 3135 | if(window == this)
|
|---|
| 3136 | {
|
|---|
| 3137 | hwndRelated = 0; /* First in list */
|
|---|
| 3138 | goto end;
|
|---|
| 3139 | }
|
|---|
| 3140 | while(window->getNextChild())
|
|---|
| 3141 | {
|
|---|
| 3142 | if (window->getNextChild() == this)
|
|---|
| 3143 | {
|
|---|
| 3144 | hwndRelated = window->getWindowHandle();
|
|---|
| 3145 | goto end;
|
|---|
| 3146 | }
|
|---|
| 3147 | window = (Win32BaseWindow *)window->getNextChild();
|
|---|
| 3148 | }
|
|---|
| 3149 | break;
|
|---|
| 3150 |
|
|---|
| 3151 | case GW_OWNER:
|
|---|
| 3152 | if(getOwner()) {
|
|---|
| 3153 | hwndRelated = getOwner()->getWindowHandle();
|
|---|
| 3154 | }
|
|---|
| 3155 | break;
|
|---|
| 3156 |
|
|---|
| 3157 | case GW_CHILD:
|
|---|
| 3158 | if(getFirstChild()) {
|
|---|
| 3159 | hwndRelated = ((Win32BaseWindow *)getFirstChild())->getWindowHandle();
|
|---|
| 3160 | }
|
|---|
| 3161 | break;
|
|---|
| 3162 | }
|
|---|
| 3163 | #endif
|
|---|
| 3164 | end:
|
|---|
| 3165 | dprintf(("GetWindow %x %d returned %x", getWindowHandle(), uCmd, hwndRelated));
|
|---|
| 3166 | return hwndRelated;
|
|---|
| 3167 | }
|
|---|
| 3168 | //******************************************************************************
|
|---|
| 3169 | //******************************************************************************
|
|---|
| 3170 | HWND Win32BaseWindow::SetActiveWindow()
|
|---|
| 3171 | {
|
|---|
| 3172 | HWND hwndActive;
|
|---|
| 3173 |
|
|---|
| 3174 | dprintf(("SetActiveWindow %x", getWindowHandle()));
|
|---|
| 3175 | if (HOOK_IsHooked( WH_CBT ))
|
|---|
| 3176 | {
|
|---|
| 3177 | CBTACTIVATESTRUCT cbta;
|
|---|
| 3178 | LRESULT ret;
|
|---|
| 3179 |
|
|---|
| 3180 | cbta.fMouse = FALSE;
|
|---|
| 3181 | cbta.hWndActive = GetActiveWindow();
|
|---|
| 3182 | ret = HOOK_CallHooksA(WH_CBT, HCBT_ACTIVATE, getWindowHandle(), (LPARAM)&cbta);
|
|---|
| 3183 | if(ret)
|
|---|
| 3184 | {
|
|---|
| 3185 | dprintf(("SetActiveWindow %x, CBT hook cancelled operation", getWindowHandle()));
|
|---|
| 3186 | return cbta.hWndActive;
|
|---|
| 3187 | }
|
|---|
| 3188 | }
|
|---|
| 3189 | SetWindowPos(HWND_TOP, 0,0,0,0, SWP_NOSIZE | SWP_NOMOVE );
|
|---|
| 3190 |
|
|---|
| 3191 | // if(OSLibWinSetActiveWindow(OS2Hwnd) == FALSE) {
|
|---|
| 3192 | // dprintf(("OSLibWinSetActiveWindow %x returned FALSE!", OS2Hwnd));
|
|---|
| 3193 | // }
|
|---|
| 3194 | hwndActive = GetActiveWindow();
|
|---|
| 3195 | return (hwndActive) ? hwndActive : windowDesktop->getWindowHandle(); //pretend the desktop was active
|
|---|
| 3196 | }
|
|---|
| 3197 | //******************************************************************************
|
|---|
| 3198 | //Used to change active status of an mdi window
|
|---|
| 3199 | //******************************************************************************
|
|---|
| 3200 | BOOL Win32BaseWindow::DeactivateChildWindow()
|
|---|
| 3201 | {
|
|---|
| 3202 | /* child windows get a WM_CHILDACTIVATE message */
|
|---|
| 3203 | if((getStyle() & (WS_CHILD | WS_POPUP)) == WS_CHILD )
|
|---|
| 3204 | {
|
|---|
| 3205 | ULONG flags = OSLibWinGetWindowULong(getOS2WindowHandle(), OFFSET_WIN32FLAGS);
|
|---|
| 3206 | OSLibWinSetWindowULong(getOS2WindowHandle(), OFFSET_WIN32FLAGS, (flags & ~WINDOWFLAG_ACTIVE));
|
|---|
| 3207 | return TRUE;
|
|---|
| 3208 | }
|
|---|
| 3209 | DebugInt3(); //should not be called for non-child window
|
|---|
| 3210 | return FALSE;
|
|---|
| 3211 | }
|
|---|
| 3212 | //******************************************************************************
|
|---|
| 3213 | //WM_ENABLE is sent to hwnd, but not to it's children (as it should be)
|
|---|
| 3214 | //******************************************************************************
|
|---|
| 3215 | BOOL Win32BaseWindow::EnableWindow(BOOL fEnable)
|
|---|
| 3216 | {
|
|---|
| 3217 | BOOL rc;
|
|---|
| 3218 |
|
|---|
| 3219 | dprintf(("Win32BaseWindow::EnableWindow %x %d", getWindowHandle(), fEnable));
|
|---|
| 3220 | //return true if previous state was disabled, else false (sdk docs)
|
|---|
| 3221 | rc = (getStyle() & WS_DISABLED) != 0;
|
|---|
| 3222 | if(rc && !fEnable) {
|
|---|
| 3223 | SendMessageA(WM_CANCELMODE, 0, 0);
|
|---|
| 3224 | }
|
|---|
| 3225 | OSLibWinEnableWindow(OS2Hwnd, fEnable);
|
|---|
| 3226 | if(fEnable == FALSE) {
|
|---|
| 3227 | //SvL: No need to clear focus as PM already does this
|
|---|
| 3228 | if(getWindowHandle() == GetCapture()) {
|
|---|
| 3229 | ReleaseCapture(); /* A disabled window can't capture the mouse */
|
|---|
| 3230 | dprintf(("Released capture for window %x that is being disabled", getWindowHandle()));
|
|---|
| 3231 | }
|
|---|
| 3232 | }
|
|---|
| 3233 | return rc;
|
|---|
| 3234 | }
|
|---|
| 3235 | //******************************************************************************
|
|---|
| 3236 | //******************************************************************************
|
|---|
| 3237 | BOOL Win32BaseWindow::CloseWindow()
|
|---|
| 3238 | {
|
|---|
| 3239 | return OSLibWinMinimizeWindow(OS2Hwnd);
|
|---|
| 3240 | }
|
|---|
| 3241 | //******************************************************************************
|
|---|
| 3242 | //TODO: Not be 100% correct; should return active window of current thread
|
|---|
| 3243 | // or NULL when there is none -> WinQueryActiveWindow just returns
|
|---|
| 3244 | // the current active window
|
|---|
| 3245 | //******************************************************************************
|
|---|
| 3246 | HWND Win32BaseWindow::GetActiveWindow()
|
|---|
| 3247 | {
|
|---|
| 3248 | HWND hwndActive;
|
|---|
| 3249 | Win32BaseWindow *win32wnd;
|
|---|
| 3250 | ULONG magic;
|
|---|
| 3251 |
|
|---|
| 3252 | hwndActive = OSLibWinQueryActiveWindow();
|
|---|
| 3253 |
|
|---|
| 3254 | return OS2ToWin32Handle(hwndActive);
|
|---|
| 3255 | }
|
|---|
| 3256 | //******************************************************************************
|
|---|
| 3257 | //******************************************************************************
|
|---|
| 3258 | BOOL Win32BaseWindow::IsWindowEnabled()
|
|---|
| 3259 | {
|
|---|
| 3260 | return OSLibWinIsWindowEnabled(OS2Hwnd);
|
|---|
| 3261 | }
|
|---|
| 3262 | //******************************************************************************
|
|---|
| 3263 | //******************************************************************************
|
|---|
| 3264 | BOOL Win32BaseWindow::IsWindowVisible()
|
|---|
| 3265 | {
|
|---|
| 3266 | //TODO: Do we have to check the state of the parent window? (as Wine does)
|
|---|
| 3267 | #if 1
|
|---|
| 3268 | return (dwStyle & WS_VISIBLE) == WS_VISIBLE;
|
|---|
| 3269 | #else
|
|---|
| 3270 | return OSLibWinIsWindowVisible(OS2Hwnd);
|
|---|
| 3271 | #endif
|
|---|
| 3272 | }
|
|---|
| 3273 | //******************************************************************************
|
|---|
| 3274 | //******************************************************************************
|
|---|
| 3275 | BOOL Win32BaseWindow::hasWindowName(LPSTR wndname, BOOL fUnicode)
|
|---|
| 3276 | {
|
|---|
| 3277 | INT len = GetWindowTextLength(fUnicode);
|
|---|
| 3278 | BOOL res;
|
|---|
| 3279 |
|
|---|
| 3280 | if (wndname == NULL)
|
|---|
| 3281 | return (len == 0);
|
|---|
| 3282 |
|
|---|
| 3283 | len++;
|
|---|
| 3284 | if (fUnicode)
|
|---|
| 3285 | {
|
|---|
| 3286 | WCHAR *text = (WCHAR*)malloc(len*sizeof(WCHAR));
|
|---|
| 3287 |
|
|---|
| 3288 | GetWindowTextW(text,len);
|
|---|
| 3289 | res = (lstrcmpW(text,(LPWSTR)wndname) == 0);
|
|---|
| 3290 | free(text);
|
|---|
| 3291 | }
|
|---|
| 3292 | else
|
|---|
| 3293 | {
|
|---|
| 3294 | CHAR *text = (CHAR*)malloc(len*sizeof(CHAR));
|
|---|
| 3295 |
|
|---|
| 3296 | GetWindowTextA(text,len);
|
|---|
| 3297 | res = (strcmp(text,wndname) == 0);
|
|---|
| 3298 | free(text);
|
|---|
| 3299 | }
|
|---|
| 3300 |
|
|---|
| 3301 | return res;
|
|---|
| 3302 | }
|
|---|
| 3303 | //******************************************************************************
|
|---|
| 3304 | //******************************************************************************
|
|---|
| 3305 | CHAR *Win32BaseWindow::getWindowNamePtrA()
|
|---|
| 3306 | {
|
|---|
| 3307 | INT len = GetWindowTextLength(FALSE);
|
|---|
| 3308 | CHAR *text;
|
|---|
| 3309 |
|
|---|
| 3310 | if (len == 0) return NULL;
|
|---|
| 3311 | len++;
|
|---|
| 3312 | text = (CHAR*)malloc(len*sizeof(CHAR));
|
|---|
| 3313 | GetWindowTextA(text,len);
|
|---|
| 3314 |
|
|---|
| 3315 | return text;
|
|---|
| 3316 | }
|
|---|
| 3317 | //******************************************************************************
|
|---|
| 3318 | //******************************************************************************
|
|---|
| 3319 | WCHAR *Win32BaseWindow::getWindowNamePtrW()
|
|---|
| 3320 | {
|
|---|
| 3321 | INT len = GetWindowTextLength(TRUE);
|
|---|
| 3322 | WCHAR *text;
|
|---|
| 3323 |
|
|---|
| 3324 | if (len == 0) return NULL;
|
|---|
| 3325 | len++;
|
|---|
| 3326 | text = (WCHAR*)malloc(len*sizeof(WCHAR));
|
|---|
| 3327 | GetWindowTextW(text,len);
|
|---|
| 3328 |
|
|---|
| 3329 | return text;
|
|---|
| 3330 | }
|
|---|
| 3331 | //******************************************************************************
|
|---|
| 3332 | //******************************************************************************
|
|---|
| 3333 | VOID Win32BaseWindow::freeWindowNamePtr(PVOID namePtr)
|
|---|
| 3334 | {
|
|---|
| 3335 | if (namePtr) free(namePtr);
|
|---|
| 3336 | }
|
|---|
| 3337 | //******************************************************************************
|
|---|
| 3338 | //When using this API for a window that was created by a different process, NT
|
|---|
| 3339 | //does NOT send WM_GETTEXTLENGTH.
|
|---|
| 3340 | //******************************************************************************
|
|---|
| 3341 | int Win32BaseWindow::GetWindowTextLength(BOOL fUnicode)
|
|---|
| 3342 | {
|
|---|
| 3343 | //if the destination window is created by this process, send message
|
|---|
| 3344 | if(dwProcessId == currentProcessId) {
|
|---|
| 3345 | if(fUnicode) {
|
|---|
| 3346 | return SendInternalMessageW(WM_GETTEXTLENGTH,0,0);
|
|---|
| 3347 | }
|
|---|
| 3348 | else return SendInternalMessageA(WM_GETTEXTLENGTH,0,0);
|
|---|
| 3349 | }
|
|---|
| 3350 | //else get data directory from window structure
|
|---|
| 3351 | //TODO: must lock window structure.... (TODO)
|
|---|
| 3352 | if(fUnicode) {
|
|---|
| 3353 | if(windowNameW) {
|
|---|
| 3354 | return strlenW(windowNameW);
|
|---|
| 3355 | }
|
|---|
| 3356 | else return 0;
|
|---|
| 3357 | }
|
|---|
| 3358 | else {
|
|---|
| 3359 | if(windowNameA) {
|
|---|
| 3360 | return strlen(windowNameA);
|
|---|
| 3361 | }
|
|---|
| 3362 | else return 0;
|
|---|
| 3363 | }
|
|---|
| 3364 | }
|
|---|
| 3365 | //******************************************************************************
|
|---|
| 3366 | //When using this API for a window that was created by a different process, NT
|
|---|
| 3367 | //does NOT send WM_GETTEXT.
|
|---|
| 3368 | //******************************************************************************
|
|---|
| 3369 | int Win32BaseWindow::GetWindowTextA(LPSTR lpsz, int cch)
|
|---|
| 3370 | {
|
|---|
| 3371 | //if the destination window is created by this process, send message
|
|---|
| 3372 | if(dwProcessId == currentProcessId) {
|
|---|
| 3373 | return SendInternalMessageA(WM_GETTEXT,(WPARAM)cch,(LPARAM)lpsz);
|
|---|
| 3374 | }
|
|---|
| 3375 | //else get data directory from window structure
|
|---|
| 3376 | if (!lpsz || !cch) return 0;
|
|---|
| 3377 | if (!windowNameA) lpsz[0] = 0;
|
|---|
| 3378 | else lstrcpynA(lpsz, windowNameA, cch);
|
|---|
| 3379 | return min((windowNameA ? strlen(windowNameA) : 0), cch);
|
|---|
| 3380 | }
|
|---|
| 3381 | //******************************************************************************
|
|---|
| 3382 | //When using this API for a window that was created by a different process, NT
|
|---|
| 3383 | //does NOT send WM_GETTEXT.
|
|---|
| 3384 | //******************************************************************************
|
|---|
| 3385 | int Win32BaseWindow::GetWindowTextW(LPWSTR lpsz, int cch)
|
|---|
| 3386 | {
|
|---|
| 3387 | //if the destination window is created by this process, send message
|
|---|
| 3388 | if(dwProcessId == currentProcessId) {
|
|---|
| 3389 | return SendInternalMessageW(WM_GETTEXT,(WPARAM)cch,(LPARAM)lpsz);
|
|---|
| 3390 | }
|
|---|
| 3391 | //else get data directory from window structure
|
|---|
| 3392 | if (!lpsz || !cch) return 0;
|
|---|
| 3393 | if (!windowNameW) lpsz[0] = 0;
|
|---|
| 3394 | else lstrcpynW(lpsz, windowNameW, cch);
|
|---|
| 3395 | return min((windowNameW ? strlenW(windowNameW) : 0), cch);
|
|---|
| 3396 | }
|
|---|
| 3397 | //******************************************************************************
|
|---|
| 3398 | //TODO: How does this work when the target window belongs to a different process???
|
|---|
| 3399 | //******************************************************************************
|
|---|
| 3400 | BOOL Win32BaseWindow::SetWindowTextA(LPSTR lpsz)
|
|---|
| 3401 | {
|
|---|
| 3402 | return SendInternalMessageA(WM_SETTEXT,0,(LPARAM)lpsz);
|
|---|
| 3403 | }
|
|---|
| 3404 | //******************************************************************************
|
|---|
| 3405 | //******************************************************************************
|
|---|
| 3406 | BOOL Win32BaseWindow::SetWindowTextW(LPWSTR lpsz)
|
|---|
| 3407 | {
|
|---|
| 3408 | return SendInternalMessageW(WM_SETTEXT,0,(LPARAM)lpsz);
|
|---|
| 3409 | }
|
|---|
| 3410 | //******************************************************************************
|
|---|
| 3411 | //******************************************************************************
|
|---|
| 3412 | LONG Win32BaseWindow::SetWindowLongA(int index, ULONG value, BOOL fUnicode)
|
|---|
| 3413 | {
|
|---|
| 3414 | LONG oldval;
|
|---|
| 3415 |
|
|---|
| 3416 | switch(index) {
|
|---|
| 3417 | case GWL_EXSTYLE:
|
|---|
| 3418 | {
|
|---|
| 3419 | STYLESTRUCT ss;
|
|---|
| 3420 |
|
|---|
| 3421 | if(dwExStyle == value) {
|
|---|
| 3422 | oldval = value;
|
|---|
| 3423 | break;
|
|---|
| 3424 | }
|
|---|
| 3425 | ss.styleOld = dwExStyle;
|
|---|
| 3426 | ss.styleNew = value;
|
|---|
| 3427 | dprintf(("SetWindowLong GWL_EXSTYLE %x old %x new style %x", getWindowHandle(), dwExStyle, value));
|
|---|
| 3428 | SendInternalMessageA(WM_STYLECHANGING,GWL_EXSTYLE,(LPARAM)&ss);
|
|---|
| 3429 | setExStyle(ss.styleNew);
|
|---|
| 3430 | SendInternalMessageA(WM_STYLECHANGED,GWL_EXSTYLE,(LPARAM)&ss);
|
|---|
| 3431 | oldval = ss.styleOld;
|
|---|
| 3432 | break;
|
|---|
| 3433 | }
|
|---|
| 3434 | case GWL_STYLE:
|
|---|
| 3435 | {
|
|---|
| 3436 | STYLESTRUCT ss;
|
|---|
| 3437 |
|
|---|
| 3438 | //SvL: TODO: Can you change minimize or maximize status here too?
|
|---|
| 3439 |
|
|---|
| 3440 | if(dwStyle == value) {
|
|---|
| 3441 | oldval = value;
|
|---|
| 3442 | break;
|
|---|
| 3443 | }
|
|---|
| 3444 | value &= ~(WS_CHILD|WS_VISIBLE); /* Some bits can't be changed this way (WINE) */
|
|---|
| 3445 | ss.styleOld = getStyle();
|
|---|
| 3446 | ss.styleNew = value | (ss.styleOld & (WS_CHILD|WS_VISIBLE));
|
|---|
| 3447 | dprintf(("SetWindowLong GWL_STYLE %x old %x new style %x", getWindowHandle(), ss.styleOld, ss.styleNew));
|
|---|
| 3448 | SendInternalMessageA(WM_STYLECHANGING,GWL_STYLE,(LPARAM)&ss);
|
|---|
| 3449 | setStyle(ss.styleNew);
|
|---|
| 3450 | SendInternalMessageA(WM_STYLECHANGED,GWL_STYLE,(LPARAM)&ss);
|
|---|
| 3451 | OSLibSetWindowStyle(getOS2WindowHandle(), getStyle(), getExStyle());
|
|---|
| 3452 | #ifdef DEBUG
|
|---|
| 3453 | PrintWindowStyle(ss.styleNew, 0);
|
|---|
| 3454 | #endif
|
|---|
| 3455 | oldval = ss.styleOld;
|
|---|
| 3456 | break;
|
|---|
| 3457 | }
|
|---|
| 3458 | case GWL_WNDPROC:
|
|---|
| 3459 | {
|
|---|
| 3460 | //Note: Type of SetWindowLong determines new window proc type
|
|---|
| 3461 | // UNLESS the new window proc has already been registered
|
|---|
| 3462 | // (use the old type in that case)
|
|---|
| 3463 | // (VERIFIED in NT 4, SP6)
|
|---|
| 3464 | WINDOWPROCTYPE type = WINPROC_GetProcType((HWINDOWPROC)value);
|
|---|
| 3465 | if(type == WIN_PROC_INVALID) {
|
|---|
| 3466 | type = (fUnicode) ? WIN_PROC_32W : WIN_PROC_32A;
|
|---|
| 3467 | }
|
|---|
| 3468 | oldval = (LONG)WINPROC_GetProc(win32wndproc, (fUnicode) ? WIN_PROC_32W : WIN_PROC_32A);
|
|---|
| 3469 | WINPROC_SetProc((HWINDOWPROC *)&win32wndproc, (WNDPROC)value, type, WIN_PROC_WINDOW);
|
|---|
| 3470 | break;
|
|---|
| 3471 | }
|
|---|
| 3472 | case GWL_HINSTANCE:
|
|---|
| 3473 | oldval = hInstance;
|
|---|
| 3474 | hInstance = value;
|
|---|
| 3475 | break;
|
|---|
| 3476 |
|
|---|
| 3477 | case GWL_HWNDPARENT:
|
|---|
| 3478 | oldval = SetParent((HWND)value);
|
|---|
| 3479 | break;
|
|---|
| 3480 |
|
|---|
| 3481 | case GWL_ID:
|
|---|
| 3482 | oldval = getWindowId();
|
|---|
| 3483 | setWindowId(value);
|
|---|
| 3484 | break;
|
|---|
| 3485 |
|
|---|
| 3486 | case GWL_USERDATA:
|
|---|
| 3487 | oldval = userData;
|
|---|
| 3488 | userData = value;
|
|---|
| 3489 | break;
|
|---|
| 3490 |
|
|---|
| 3491 | default:
|
|---|
| 3492 | if(index >= 0 && index + sizeof(ULONG) <= nrUserWindowBytes)
|
|---|
| 3493 | {
|
|---|
| 3494 | oldval = *(ULONG *)(userWindowBytes + index);
|
|---|
| 3495 | *(ULONG *)(userWindowBytes + index) = value;
|
|---|
| 3496 | break;
|
|---|
| 3497 | }
|
|---|
| 3498 | dprintf(("WARNING: SetWindowLong%c %x %d %x returned %x INVALID index!", (fUnicode) ? 'W' : 'A', getWindowHandle(), index, value));
|
|---|
| 3499 | SetLastError(ERROR_INVALID_INDEX); //verified in NT4, SP6
|
|---|
| 3500 | return 0;
|
|---|
| 3501 | }
|
|---|
| 3502 | //Note: NT4, SP6 does not set the last error to 0
|
|---|
| 3503 | SetLastError(ERROR_SUCCESS);
|
|---|
| 3504 | dprintf2(("SetWindowLong%c %x %d %x returned %x", (fUnicode) ? 'W' : 'A', getWindowHandle(), index, value, oldval));
|
|---|
| 3505 | return oldval;
|
|---|
| 3506 | }
|
|---|
| 3507 | //******************************************************************************
|
|---|
| 3508 | //******************************************************************************
|
|---|
| 3509 | ULONG Win32BaseWindow::GetWindowLongA(int index, BOOL fUnicode)
|
|---|
| 3510 | {
|
|---|
| 3511 | ULONG value;
|
|---|
| 3512 |
|
|---|
| 3513 | switch(index) {
|
|---|
| 3514 | case GWL_EXSTYLE:
|
|---|
| 3515 | value = dwExStyle;
|
|---|
| 3516 | break;
|
|---|
| 3517 | case GWL_STYLE:
|
|---|
| 3518 | value = dwStyle;
|
|---|
| 3519 | break;
|
|---|
| 3520 | case GWL_WNDPROC:
|
|---|
| 3521 | value = (LONG)WINPROC_GetProc(win32wndproc, (fUnicode) ? WIN_PROC_32W : WIN_PROC_32A);
|
|---|
| 3522 | break;
|
|---|
| 3523 | case GWL_HINSTANCE:
|
|---|
| 3524 | value = hInstance;
|
|---|
| 3525 | break;
|
|---|
| 3526 | case GWL_HWNDPARENT:
|
|---|
| 3527 | value = GetParent();
|
|---|
| 3528 | break;
|
|---|
| 3529 | case GWL_ID:
|
|---|
| 3530 | value = getWindowId();
|
|---|
| 3531 | break;
|
|---|
| 3532 | case GWL_USERDATA:
|
|---|
| 3533 | value = userData;
|
|---|
| 3534 | break;
|
|---|
| 3535 | default:
|
|---|
| 3536 | if(index >= 0 && index + sizeof(ULONG) <= nrUserWindowBytes)
|
|---|
| 3537 | {
|
|---|
| 3538 | value = *(ULONG *)(userWindowBytes + index);
|
|---|
| 3539 | break;
|
|---|
| 3540 | }
|
|---|
| 3541 | dprintf(("WARNING: GetWindowLong%c %x %d %x returned %x INVALID index!", (fUnicode) ? 'W' : 'A', getWindowHandle(), index, value));
|
|---|
| 3542 | SetLastError(ERROR_INVALID_INDEX); //verified in NT4, SP6
|
|---|
| 3543 | return 0;
|
|---|
| 3544 | }
|
|---|
| 3545 | dprintf2(("GetWindowLong%c %x %d %x", (fUnicode) ? 'W' : 'A', getWindowHandle(), index, value));
|
|---|
| 3546 | //Note: NT4, SP6 does not set the last error to 0
|
|---|
| 3547 | SetLastError(ERROR_SUCCESS);
|
|---|
| 3548 | return value;
|
|---|
| 3549 | }
|
|---|
| 3550 | //******************************************************************************
|
|---|
| 3551 | //******************************************************************************
|
|---|
| 3552 | WORD Win32BaseWindow::SetWindowWord(int index, WORD value)
|
|---|
| 3553 | {
|
|---|
| 3554 | WORD oldval;
|
|---|
| 3555 |
|
|---|
| 3556 | if(index >= 0 && index + sizeof(WORD) <= nrUserWindowBytes)
|
|---|
| 3557 | {
|
|---|
| 3558 | oldval = *(WORD *)(userWindowBytes + index);
|
|---|
| 3559 | *(WORD *)(userWindowBytes + index) = value;
|
|---|
| 3560 | //Note: NT4, SP6 does not set the last error to 0
|
|---|
| 3561 | dprintf2(("SetWindowWord %x %d %x returned %x", getWindowHandle(), index, value, oldval));
|
|---|
| 3562 | SetLastError(ERROR_SUCCESS);
|
|---|
| 3563 | return oldval;
|
|---|
| 3564 | }
|
|---|
| 3565 | dprintf(("WARNING: SetWindowWord %x %d %x returned %x INVALID index!", getWindowHandle(), index, value));
|
|---|
| 3566 | SetLastError(ERROR_INVALID_INDEX); //verified in NT4, SP6
|
|---|
| 3567 | return 0;
|
|---|
| 3568 | }
|
|---|
| 3569 | //******************************************************************************
|
|---|
| 3570 | //******************************************************************************
|
|---|
| 3571 | WORD Win32BaseWindow::GetWindowWord(int index)
|
|---|
| 3572 | {
|
|---|
| 3573 | if(index >= 0 && index + sizeof(WORD) <= nrUserWindowBytes)
|
|---|
| 3574 | {
|
|---|
| 3575 | //Note: NT4, SP6 does not set the last error to 0
|
|---|
| 3576 | SetLastError(ERROR_SUCCESS);
|
|---|
| 3577 | dprintf2(("GetWindowWord %x %d %x", getWindowHandle(), index, *(WORD *)(userWindowBytes + index)));
|
|---|
| 3578 | return *(WORD *)(userWindowBytes + index);
|
|---|
| 3579 | }
|
|---|
| 3580 | dprintf(("WARNING: GetWindowWord %x %d returned %x INVALID index!", getWindowHandle(), index));
|
|---|
| 3581 | SetLastError(ERROR_INVALID_INDEX); //verified in NT4, SP6
|
|---|
| 3582 | return 0;
|
|---|
| 3583 | }
|
|---|
| 3584 | //******************************************************************************
|
|---|
| 3585 | //******************************************************************************
|
|---|
| 3586 | void Win32BaseWindow::setWindowId(DWORD id)
|
|---|
| 3587 | {
|
|---|
| 3588 | dwIDMenu = id;
|
|---|
| 3589 | }
|
|---|
| 3590 | //******************************************************************************
|
|---|
| 3591 | //******************************************************************************
|
|---|
| 3592 | Win32BaseWindow *Win32BaseWindow::GetWindowFromHandle(HWND hwnd)
|
|---|
| 3593 | {
|
|---|
| 3594 | Win32BaseWindow *window;
|
|---|
| 3595 |
|
|---|
| 3596 | if(HwGetWindowHandleData(hwnd, (DWORD *)&window) == TRUE) {
|
|---|
| 3597 | return window;
|
|---|
| 3598 | }
|
|---|
| 3599 | // dprintf2(("Win32BaseWindow::GetWindowFromHandle: not a win32 window %x", hwnd));
|
|---|
| 3600 | return NULL;
|
|---|
| 3601 | }
|
|---|
| 3602 | //******************************************************************************
|
|---|
| 3603 | //******************************************************************************
|
|---|
| 3604 | Win32BaseWindow *Win32BaseWindow::GetWindowFromOS2Handle(HWND hwnd)
|
|---|
| 3605 | {
|
|---|
| 3606 | Win32BaseWindow *win32wnd;
|
|---|
| 3607 | DWORD magic;
|
|---|
| 3608 |
|
|---|
| 3609 | if(hwnd == OSLIB_HWND_DESKTOP)
|
|---|
| 3610 | {
|
|---|
| 3611 | return windowDesktop;
|
|---|
| 3612 | }
|
|---|
| 3613 |
|
|---|
| 3614 | win32wnd = (Win32BaseWindow *)OSLibWinGetWindowULong(hwnd, OFFSET_WIN32WNDPTR);
|
|---|
| 3615 | magic = OSLibWinGetWindowULong(hwnd, OFFSET_WIN32PM_MAGIC);
|
|---|
| 3616 |
|
|---|
| 3617 | if(win32wnd && CheckMagicDword(magic)) {
|
|---|
| 3618 | return win32wnd;
|
|---|
| 3619 | }
|
|---|
| 3620 | // dprintf2(("Win32BaseWindow::GetWindowFromOS2Handle: not an Odin os2 window %x", hwnd));
|
|---|
| 3621 | return 0;
|
|---|
| 3622 | }
|
|---|
| 3623 | //******************************************************************************
|
|---|
| 3624 | //******************************************************************************
|
|---|
| 3625 | HWND Win32BaseWindow::getNextDlgGroupItem(HWND hwndCtrl, BOOL fPrevious)
|
|---|
| 3626 | {
|
|---|
| 3627 | Win32BaseWindow *child, *nextchild, *lastchild;
|
|---|
| 3628 | HWND retvalue;
|
|---|
| 3629 |
|
|---|
| 3630 | if (hwndCtrl)
|
|---|
| 3631 | {
|
|---|
| 3632 | child = GetWindowFromHandle(hwndCtrl);
|
|---|
| 3633 | if (!child)
|
|---|
| 3634 | {
|
|---|
| 3635 | retvalue = 0;
|
|---|
| 3636 | goto END;
|
|---|
| 3637 | }
|
|---|
| 3638 | /* Make sure hwndCtrl is a top-level child */
|
|---|
| 3639 | while ((child->getStyle() & WS_CHILD) && (child->getParent() != this))
|
|---|
| 3640 | {
|
|---|
| 3641 | child = child->getParent();
|
|---|
| 3642 | if(child == NULL) break;
|
|---|
| 3643 | }
|
|---|
| 3644 |
|
|---|
| 3645 | if (!child || (child->getParent() != this))
|
|---|
| 3646 | {
|
|---|
| 3647 | retvalue = 0;
|
|---|
| 3648 | goto END;
|
|---|
| 3649 | }
|
|---|
| 3650 | }
|
|---|
| 3651 | else
|
|---|
| 3652 | {
|
|---|
| 3653 | /* No ctrl specified -> start from the beginning */
|
|---|
| 3654 | child = (Win32BaseWindow *)getFirstChild();
|
|---|
| 3655 | if (!child)
|
|---|
| 3656 | {
|
|---|
| 3657 | retvalue = 0;
|
|---|
| 3658 | goto END;
|
|---|
| 3659 | }
|
|---|
| 3660 |
|
|---|
| 3661 | if (fPrevious)
|
|---|
| 3662 | {
|
|---|
| 3663 | while (child->getNextChild())
|
|---|
| 3664 | {
|
|---|
| 3665 | child = (Win32BaseWindow *)child->getNextChild();
|
|---|
| 3666 | }
|
|---|
| 3667 | }
|
|---|
| 3668 | }
|
|---|
| 3669 |
|
|---|
| 3670 | lastchild = child;
|
|---|
| 3671 | nextchild = (Win32BaseWindow *)child->getNextChild();
|
|---|
| 3672 | while (TRUE)
|
|---|
| 3673 | {
|
|---|
| 3674 | if (!nextchild || (nextchild->getStyle() & WS_GROUP))
|
|---|
| 3675 | {
|
|---|
| 3676 | /* Wrap-around to the beginning of the group */
|
|---|
| 3677 | Win32BaseWindow *pWndTemp;
|
|---|
| 3678 |
|
|---|
| 3679 | nextchild = (Win32BaseWindow *)getFirstChild();
|
|---|
| 3680 |
|
|---|
| 3681 | for(pWndTemp = nextchild;pWndTemp;pWndTemp = (Win32BaseWindow *)pWndTemp->getNextChild())
|
|---|
| 3682 | {
|
|---|
| 3683 | if (pWndTemp->getStyle() & WS_GROUP)
|
|---|
| 3684 | nextchild = pWndTemp;
|
|---|
| 3685 |
|
|---|
| 3686 | if (pWndTemp == child)
|
|---|
| 3687 | break;
|
|---|
| 3688 | }
|
|---|
| 3689 |
|
|---|
| 3690 | }
|
|---|
| 3691 | if (nextchild == child)
|
|---|
| 3692 | break;
|
|---|
| 3693 |
|
|---|
| 3694 | if ((nextchild->getStyle() & WS_VISIBLE) && !(nextchild->getStyle() & WS_DISABLED))
|
|---|
| 3695 | {
|
|---|
| 3696 | lastchild = nextchild;
|
|---|
| 3697 |
|
|---|
| 3698 | if (!fPrevious)
|
|---|
| 3699 | break;
|
|---|
| 3700 | }
|
|---|
| 3701 |
|
|---|
| 3702 | nextchild = (Win32BaseWindow *)nextchild->getNextChild();
|
|---|
| 3703 | }
|
|---|
| 3704 | retvalue = lastchild->getWindowHandle();
|
|---|
| 3705 | END:
|
|---|
| 3706 | return retvalue;
|
|---|
| 3707 | }
|
|---|
| 3708 | //******************************************************************************
|
|---|
| 3709 | //******************************************************************************
|
|---|
| 3710 | #ifdef DEBUG
|
|---|
| 3711 | void PrintWindowStyle(DWORD dwStyle, DWORD dwExStyle)
|
|---|
| 3712 | {
|
|---|
| 3713 | char style[256] = "";
|
|---|
| 3714 | char exstyle[256] = "";
|
|---|
| 3715 |
|
|---|
| 3716 | /* Window styles */
|
|---|
| 3717 | if(dwStyle & WS_CHILD)
|
|---|
| 3718 | strcat(style, "WS_CHILD ");
|
|---|
| 3719 | if(dwStyle & WS_POPUP)
|
|---|
| 3720 | strcat(style, "WS_POPUP ");
|
|---|
| 3721 | if(dwStyle & WS_VISIBLE)
|
|---|
| 3722 | strcat(style, "WS_VISIBLE ");
|
|---|
| 3723 | if(dwStyle & WS_DISABLED)
|
|---|
| 3724 | strcat(style, "WS_DISABLED ");
|
|---|
| 3725 | if(dwStyle & WS_CLIPSIBLINGS)
|
|---|
| 3726 | strcat(style, "WS_CLIPSIBLINGS ");
|
|---|
| 3727 | if(dwStyle & WS_CLIPCHILDREN)
|
|---|
| 3728 | strcat(style, "WS_CLIPCHILDREN ");
|
|---|
| 3729 | if(dwStyle & WS_MAXIMIZE)
|
|---|
| 3730 | strcat(style, "WS_MAXIMIZE ");
|
|---|
| 3731 | if(dwStyle & WS_MINIMIZE)
|
|---|
| 3732 | strcat(style, "WS_MINIMIZE ");
|
|---|
| 3733 | if(dwStyle & WS_GROUP)
|
|---|
| 3734 | strcat(style, "WS_GROUP ");
|
|---|
| 3735 | if(dwStyle & WS_TABSTOP)
|
|---|
| 3736 | strcat(style, "WS_TABSTOP ");
|
|---|
| 3737 |
|
|---|
| 3738 | if((dwStyle & WS_CAPTION) == WS_CAPTION)
|
|---|
| 3739 | strcat(style, "WS_CAPTION ");
|
|---|
| 3740 | if(dwStyle & WS_DLGFRAME)
|
|---|
| 3741 | strcat(style, "WS_DLGFRAME ");
|
|---|
| 3742 | if(dwStyle & WS_BORDER)
|
|---|
| 3743 | strcat(style, "WS_BORDER ");
|
|---|
| 3744 |
|
|---|
| 3745 | if(dwStyle & WS_VSCROLL)
|
|---|
| 3746 | strcat(style, "WS_VSCROLL ");
|
|---|
| 3747 | if(dwStyle & WS_HSCROLL)
|
|---|
| 3748 | strcat(style, "WS_HSCROLL ");
|
|---|
| 3749 | if(dwStyle & WS_SYSMENU)
|
|---|
| 3750 | strcat(style, "WS_SYSMENU ");
|
|---|
| 3751 | if(dwStyle & WS_THICKFRAME)
|
|---|
| 3752 | strcat(style, "WS_THICKFRAME ");
|
|---|
| 3753 | if(dwStyle & WS_MINIMIZEBOX)
|
|---|
| 3754 | strcat(style, "WS_MINIMIZEBOX ");
|
|---|
| 3755 | if(dwStyle & WS_MAXIMIZEBOX)
|
|---|
| 3756 | strcat(style, "WS_MAXIMIZEBOX ");
|
|---|
| 3757 |
|
|---|
| 3758 | if(dwExStyle & WS_EX_DLGMODALFRAME)
|
|---|
| 3759 | strcat(exstyle, "WS_EX_DLGMODALFRAME ");
|
|---|
| 3760 | if(dwExStyle & WS_EX_ACCEPTFILES)
|
|---|
| 3761 | strcat(exstyle, "WS_EX_ACCEPTFILES ");
|
|---|
| 3762 | if(dwExStyle & WS_EX_NOPARENTNOTIFY)
|
|---|
| 3763 | strcat(exstyle, "WS_EX_NOPARENTNOTIFY ");
|
|---|
| 3764 | if(dwExStyle & WS_EX_TOPMOST)
|
|---|
| 3765 | strcat(exstyle, "WS_EX_TOPMOST ");
|
|---|
| 3766 | if(dwExStyle & WS_EX_TRANSPARENT)
|
|---|
| 3767 | strcat(exstyle, "WS_EX_TRANSPARENT ");
|
|---|
| 3768 |
|
|---|
| 3769 | if(dwExStyle & WS_EX_MDICHILD)
|
|---|
| 3770 | strcat(exstyle, "WS_EX_MDICHILD ");
|
|---|
| 3771 | if(dwExStyle & WS_EX_TOOLWINDOW)
|
|---|
| 3772 | strcat(exstyle, "WS_EX_TOOLWINDOW ");
|
|---|
| 3773 | if(dwExStyle & WS_EX_WINDOWEDGE)
|
|---|
| 3774 | strcat(exstyle, "WS_EX_WINDOWEDGE ");
|
|---|
| 3775 | if(dwExStyle & WS_EX_CLIENTEDGE)
|
|---|
| 3776 | strcat(exstyle, "WS_EX_CLIENTEDGE ");
|
|---|
| 3777 | if(dwExStyle & WS_EX_CONTEXTHELP)
|
|---|
| 3778 | strcat(exstyle, "WS_EX_CONTEXTHELP ");
|
|---|
| 3779 | if(dwExStyle & WS_EX_RIGHT)
|
|---|
| 3780 | strcat(exstyle, "WS_EX_RIGHT ");
|
|---|
| 3781 | if(dwExStyle & WS_EX_LEFT)
|
|---|
| 3782 | strcat(exstyle, "WS_EX_LEFT ");
|
|---|
| 3783 | if(dwExStyle & WS_EX_RTLREADING)
|
|---|
| 3784 | strcat(exstyle, "WS_EX_RTLREADING ");
|
|---|
| 3785 | if(dwExStyle & WS_EX_LTRREADING)
|
|---|
| 3786 | strcat(exstyle, "WS_EX_LTRREADING ");
|
|---|
| 3787 | if(dwExStyle & WS_EX_LEFTSCROLLBAR)
|
|---|
| 3788 | strcat(exstyle, "WS_EX_LEFTSCROLLBAR ");
|
|---|
| 3789 | if(dwExStyle & WS_EX_RIGHTSCROLLBAR)
|
|---|
| 3790 | strcat(exstyle, "WS_EX_RIGHTSCROLLBAR ");
|
|---|
| 3791 | if(dwExStyle & WS_EX_CONTROLPARENT)
|
|---|
| 3792 | strcat(exstyle, "WS_EX_CONTROLPARENT ");
|
|---|
| 3793 | if(dwExStyle & WS_EX_STATICEDGE)
|
|---|
| 3794 | strcat(exstyle, "WS_EX_STATICEDGE ");
|
|---|
| 3795 | if(dwExStyle & WS_EX_APPWINDOW)
|
|---|
| 3796 | strcat(exstyle, "WS_EX_APPWINDOW ");
|
|---|
| 3797 |
|
|---|
| 3798 | dprintf(("Window style: %x %s", dwStyle, style));
|
|---|
| 3799 | dprintf(("Window exStyle: %x %s", dwExStyle, exstyle));
|
|---|
| 3800 | }
|
|---|
| 3801 | #endif
|
|---|
| 3802 | //******************************************************************************
|
|---|
| 3803 | //******************************************************************************
|
|---|
| 3804 | HWND WIN32API Win32ToOS2Handle(HWND hwnd)
|
|---|
| 3805 | {
|
|---|
| 3806 | Win32BaseWindow *window = Win32BaseWindow::GetWindowFromHandle(hwnd);
|
|---|
| 3807 |
|
|---|
| 3808 | if(window) {
|
|---|
| 3809 | return window->getOS2WindowHandle();
|
|---|
| 3810 | }
|
|---|
| 3811 | // dprintf2(("Win32BaseWindow::Win32ToOS2Handle: not a win32 window %x", hwnd));
|
|---|
| 3812 | return hwnd;
|
|---|
| 3813 | }
|
|---|
| 3814 | //******************************************************************************
|
|---|
| 3815 | //******************************************************************************
|
|---|
| 3816 | HWND WIN32API OS2ToWin32Handle(HWND hwnd)
|
|---|
| 3817 | {
|
|---|
| 3818 | Win32BaseWindow *window = Win32BaseWindow::GetWindowFromOS2Handle(hwnd);
|
|---|
| 3819 |
|
|---|
| 3820 | if(window) {
|
|---|
| 3821 | return window->getWindowHandle();
|
|---|
| 3822 | }
|
|---|
| 3823 | // dprintf2(("Win32BaseWindow::OS2ToWin32Handle: not a win32 window %x", hwnd));
|
|---|
| 3824 | return 0;
|
|---|
| 3825 | // else return hwnd; //OS/2 window handle
|
|---|
| 3826 | }
|
|---|
| 3827 | //******************************************************************************
|
|---|
| 3828 | //******************************************************************************
|
|---|
| 3829 |
|
|---|
| 3830 | GenericObject *Win32BaseWindow::windows = NULL;
|
|---|