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