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