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