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