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