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