| 1 | /* $Id: win32wbase.cpp,v 1.4 1999-08-31 14:38:09 sandervl Exp $ */
|
|---|
| 2 | /*
|
|---|
| 3 | * Win32 Window Base Class for OS/2
|
|---|
| 4 | *
|
|---|
| 5 | * Copyright 1998-1999 Sander van Leeuwen (sandervl@xs4all.nl)
|
|---|
| 6 | * Copyright 1999 Daniela Engert (dani@ngrt.de)
|
|---|
| 7 | *
|
|---|
| 8 | * Parts based on Wine Windows code (windows\win.c)
|
|---|
| 9 | *
|
|---|
| 10 | * Copyright 1993, 1994 Alexandre Julliard
|
|---|
| 11 | *
|
|---|
| 12 | * TODO: Not thread/process safe
|
|---|
| 13 | *
|
|---|
| 14 | * Project Odin Software License can be found in LICENSE.TXT
|
|---|
| 15 | *
|
|---|
| 16 | */
|
|---|
| 17 | #include <os2win.h>
|
|---|
| 18 | #include <win.h>
|
|---|
| 19 | #include <stdlib.h>
|
|---|
| 20 | #include <string.h>
|
|---|
| 21 | #include <stdarg.h>
|
|---|
| 22 | #include <assert.h>
|
|---|
| 23 | #include <misc.h>
|
|---|
| 24 | #include <heapstring.h>
|
|---|
| 25 | #include <win32wbase.h>
|
|---|
| 26 | #include <winres.h>
|
|---|
| 27 | #include <spy.h>
|
|---|
| 28 | #include "wndmsg.h"
|
|---|
| 29 | #include "hooks.h"
|
|---|
| 30 | #include "oslibwin.h"
|
|---|
| 31 | #include "oslibutil.h"
|
|---|
| 32 | #include "oslibgdi.h"
|
|---|
| 33 | #include "oslibres.h"
|
|---|
| 34 | #include "oslibmenu.h"
|
|---|
| 35 | #include "oslibdos.h"
|
|---|
| 36 | #include "syscolor.h"
|
|---|
| 37 | #include "win32wndhandle.h"
|
|---|
| 38 | #include "heapshared.h"
|
|---|
| 39 |
|
|---|
| 40 | #define HAS_DLGFRAME(style,exStyle) \
|
|---|
| 41 | (((exStyle) & WS_EX_DLGMODALFRAME) || \
|
|---|
| 42 | (((style) & WS_DLGFRAME) && !((style) & WS_BORDER)))
|
|---|
| 43 |
|
|---|
| 44 | #define HAS_THICKFRAME(style) \
|
|---|
| 45 | (((style) & WS_THICKFRAME) && \
|
|---|
| 46 | !(((style) & (WS_DLGFRAME|WS_BORDER)) == WS_DLGFRAME))
|
|---|
| 47 |
|
|---|
| 48 | #define HAS_BORDER(style, exStyle) \
|
|---|
| 49 | ((style & WS_BORDER) || HAS_THICKFRAME(style) || HAS_DLGFRAME(style,exStyle))
|
|---|
| 50 |
|
|---|
| 51 | #define IS_OVERLAPPED(style) \
|
|---|
| 52 | !(style & (WS_CHILD | WS_POPUP))
|
|---|
| 53 |
|
|---|
| 54 | //******************************************************************************
|
|---|
| 55 | //******************************************************************************
|
|---|
| 56 | Win32BaseWindow::Win32BaseWindow(DWORD objType) : GenericObject(&windows, objType)
|
|---|
| 57 | {
|
|---|
| 58 | Init();
|
|---|
| 59 | }
|
|---|
| 60 | //******************************************************************************
|
|---|
| 61 | //******************************************************************************
|
|---|
| 62 | Win32BaseWindow::Win32BaseWindow(CREATESTRUCTA *lpCreateStructA, ATOM classAtom, BOOL isUnicode)
|
|---|
| 63 | : GenericObject(&windows, OBJTYPE_WINDOW), ChildWindow()
|
|---|
| 64 | {
|
|---|
| 65 | Init();
|
|---|
| 66 | this->isUnicode = isUnicode;
|
|---|
| 67 | CreateWindowExA(lpCreateStructA, classAtom);
|
|---|
| 68 | }
|
|---|
| 69 | //******************************************************************************
|
|---|
| 70 | //******************************************************************************
|
|---|
| 71 | void Win32BaseWindow::Init()
|
|---|
| 72 | {
|
|---|
| 73 | isUnicode = FALSE;
|
|---|
| 74 | fCreated = FALSE;
|
|---|
| 75 | fFirstShow = TRUE;
|
|---|
| 76 |
|
|---|
| 77 | windowNameA = NULL;
|
|---|
| 78 | windowNameW = NULL;
|
|---|
| 79 | wndNameLength = 0;
|
|---|
| 80 |
|
|---|
| 81 | userWindowLong = NULL;;
|
|---|
| 82 | nrUserWindowLong = 0;
|
|---|
| 83 |
|
|---|
| 84 | magic = WIN32PM_MAGIC;
|
|---|
| 85 | OS2Hwnd = 0;
|
|---|
| 86 | OS2HwndFrame = 0;
|
|---|
| 87 | OS2HwndMenu = 0;
|
|---|
| 88 | Win32Hwnd = 0;
|
|---|
| 89 |
|
|---|
| 90 | if(HwAllocateWindowHandle(&Win32Hwnd, (ULONG)this) == FALSE)
|
|---|
| 91 | {
|
|---|
| 92 | dprintf(("Win32BaseWindow::Init HwAllocateWindowHandle failed!!"));
|
|---|
| 93 | DebugInt3();
|
|---|
| 94 | }
|
|---|
| 95 |
|
|---|
| 96 | posx = posy = 0;
|
|---|
| 97 | width = height = 0;
|
|---|
| 98 |
|
|---|
| 99 | dwExStyle = 0;
|
|---|
| 100 | dwStyle = 0;
|
|---|
| 101 | win32wndproc = 0;
|
|---|
| 102 | hInstance = 0;
|
|---|
| 103 | windowId = 0xFFFFFFFF; //default = -1
|
|---|
| 104 | userData = 0;
|
|---|
| 105 |
|
|---|
| 106 | hwndLinkAfter = HWND_BOTTOM;
|
|---|
| 107 | flags = 0;
|
|---|
| 108 | isIcon = FALSE;
|
|---|
| 109 | lastHitTestVal = 0;
|
|---|
| 110 | owner = NULL;
|
|---|
| 111 | windowClass = 0;
|
|---|
| 112 |
|
|---|
| 113 | acceltableResource = NULL;
|
|---|
| 114 | menuResource = NULL;
|
|---|
| 115 | iconResource = NULL;
|
|---|
| 116 | }
|
|---|
| 117 | //******************************************************************************
|
|---|
| 118 | //todo get rid of resources (menu, accel, icon etc)
|
|---|
| 119 | //******************************************************************************
|
|---|
| 120 | Win32BaseWindow::~Win32BaseWindow()
|
|---|
| 121 | {
|
|---|
| 122 | OSLibWinSetWindowULong(OS2Hwnd, OFFSET_WIN32WNDPTR, 0);
|
|---|
| 123 | OSLibWinSetWindowULong(OS2Hwnd, OFFSET_WIN32PM_MAGIC, 0);
|
|---|
| 124 |
|
|---|
| 125 | if(Win32Hwnd)
|
|---|
| 126 | HwFreeWindowHandle(Win32Hwnd);
|
|---|
| 127 |
|
|---|
| 128 | if(userWindowLong)
|
|---|
| 129 | free(userWindowLong);
|
|---|
| 130 | if(windowNameA) {
|
|---|
| 131 | free(windowNameA);
|
|---|
| 132 | windowNameA = NULL;
|
|---|
| 133 | }
|
|---|
| 134 | if(windowNameW) {
|
|---|
| 135 | free(windowNameW);
|
|---|
| 136 | windowNameW = NULL;
|
|---|
| 137 | }
|
|---|
| 138 | }
|
|---|
| 139 | //******************************************************************************
|
|---|
| 140 | //******************************************************************************
|
|---|
| 141 | BOOL Win32BaseWindow::isChild()
|
|---|
| 142 | {
|
|---|
| 143 | return (dwStyle & WS_CHILD) != 0;
|
|---|
| 144 | }
|
|---|
| 145 | //******************************************************************************
|
|---|
| 146 | //******************************************************************************
|
|---|
| 147 | BOOL Win32BaseWindow::CreateWindowExA(CREATESTRUCTA *cs, ATOM classAtom)
|
|---|
| 148 | {
|
|---|
| 149 | char buffer[256];
|
|---|
| 150 | INT sw = SW_SHOW;
|
|---|
| 151 | POINT maxSize, maxPos, minTrack, maxTrack;
|
|---|
| 152 |
|
|---|
| 153 | SetLastError(0);
|
|---|
| 154 |
|
|---|
| 155 | /* Find the parent window */
|
|---|
| 156 | if (cs->hwndParent)
|
|---|
| 157 | {
|
|---|
| 158 | Win32BaseWindow *window = GetWindowFromHandle(cs->hwndParent);
|
|---|
| 159 | if(!window) {
|
|---|
| 160 | dprintf(("Bad parent %04x\n", cs->hwndParent ));
|
|---|
| 161 | SetLastError(ERROR_INVALID_PARAMETER);
|
|---|
| 162 | return FALSE;
|
|---|
| 163 | }
|
|---|
| 164 | /* Make sure parent is valid */
|
|---|
| 165 | if (!window->IsWindow() )
|
|---|
| 166 | {
|
|---|
| 167 | dprintf(("Bad parent %04x\n", cs->hwndParent ));
|
|---|
| 168 | SetLastError(ERROR_INVALID_PARAMETER);
|
|---|
| 169 | return FALSE;
|
|---|
| 170 | }
|
|---|
| 171 | }
|
|---|
| 172 | else
|
|---|
| 173 | if ((cs->style & WS_CHILD) && !(cs->style & WS_POPUP)) {
|
|---|
| 174 | dprintf(("No parent for child window\n" ));
|
|---|
| 175 | SetLastError(ERROR_INVALID_PARAMETER);
|
|---|
| 176 | return FALSE; /* WS_CHILD needs a parent, but WS_POPUP doesn't */
|
|---|
| 177 | }
|
|---|
| 178 |
|
|---|
| 179 | /* Find the window class */
|
|---|
| 180 | windowClass = Win32WndClass::FindClass(cs->hInstance, (LPSTR)classAtom);
|
|---|
| 181 | if (!windowClass)
|
|---|
| 182 | {
|
|---|
| 183 | GlobalGetAtomNameA( classAtom, buffer, sizeof(buffer) );
|
|---|
| 184 | dprintf(("Bad class '%s'\n", buffer ));
|
|---|
| 185 | return 0;
|
|---|
| 186 | }
|
|---|
| 187 |
|
|---|
| 188 | /* Fix the lpszClass field: from existing programs, it seems ok to call a CreateWindowXXX
|
|---|
| 189 | * with an atom as the class name, put some programs expect to have a *REAL* string in
|
|---|
| 190 | * lpszClass when the CREATESTRUCT is sent with WM_CREATE
|
|---|
| 191 | */
|
|---|
| 192 | if (!HIWORD(cs->lpszClass) ) {
|
|---|
| 193 | if (isUnicode) {
|
|---|
| 194 | GlobalGetAtomNameW( classAtom, (LPWSTR)buffer, sizeof(buffer) );
|
|---|
| 195 | }
|
|---|
| 196 | else {
|
|---|
| 197 | GlobalGetAtomNameA( classAtom, buffer, sizeof(buffer) );
|
|---|
| 198 | }
|
|---|
| 199 | cs->lpszClass = buffer;
|
|---|
| 200 | }
|
|---|
| 201 |
|
|---|
| 202 | /* Fix the coordinates */
|
|---|
| 203 | if (cs->x == CW_USEDEFAULT || cs->x == CW_USEDEFAULT16)
|
|---|
| 204 | {
|
|---|
| 205 | // PDB *pdb = PROCESS_Current();
|
|---|
| 206 |
|
|---|
| 207 | /* Never believe Microsoft's documentation... CreateWindowEx doc says
|
|---|
| 208 | * that if an overlapped window is created with WS_VISIBLE style bit
|
|---|
| 209 | * set and the x parameter is set to CW_USEDEFAULT, the system ignores
|
|---|
| 210 | * the y parameter. However, disassembling NT implementation (WIN32K.SYS)
|
|---|
| 211 | * reveals that
|
|---|
| 212 | *
|
|---|
| 213 | * 1) not only if checks for CW_USEDEFAULT but also for CW_USEDEFAULT16
|
|---|
| 214 | * 2) it does not ignore the y parameter as the docs claim; instead, it
|
|---|
| 215 | * uses it as second parameter to ShowWindow() unless y is either
|
|---|
| 216 | * CW_USEDEFAULT or CW_USEDEFAULT16.
|
|---|
| 217 | *
|
|---|
| 218 | * The fact that we didn't do 2) caused bogus windows pop up when wine
|
|---|
| 219 | * was running apps that were using this obscure feature. Example -
|
|---|
| 220 | * calc.exe that comes with Win98 (only Win98, it's different from
|
|---|
| 221 | * the one that comes with Win95 and NT)
|
|---|
| 222 | */
|
|---|
| 223 | if (cs->y != CW_USEDEFAULT && cs->y != CW_USEDEFAULT16) sw = cs->y;
|
|---|
| 224 |
|
|---|
| 225 | /* We have saved cs->y, now we can trash it */
|
|---|
| 226 | #if 0
|
|---|
| 227 | if ( !(cs->style & (WS_CHILD | WS_POPUP))
|
|---|
| 228 | && (pdb->env_db->startup_info->dwFlags & STARTF_USEPOSITION) )
|
|---|
| 229 | {
|
|---|
| 230 | cs->x = pdb->env_db->startup_info->dwX;
|
|---|
| 231 | cs->y = pdb->env_db->startup_info->dwY;
|
|---|
| 232 | }
|
|---|
| 233 | #endif
|
|---|
| 234 | cs->x = 0;
|
|---|
| 235 | cs->y = 0;
|
|---|
| 236 | // }
|
|---|
| 237 | }
|
|---|
| 238 | if (cs->cx == CW_USEDEFAULT || cs->cx == CW_USEDEFAULT16)
|
|---|
| 239 | {
|
|---|
| 240 | #if 0
|
|---|
| 241 | PDB *pdb = PROCESS_Current();
|
|---|
| 242 | if ( !(cs->style & (WS_CHILD | WS_POPUP))
|
|---|
| 243 | && (pdb->env_db->startup_info->dwFlags & STARTF_USESIZE) )
|
|---|
| 244 | {
|
|---|
| 245 | cs->cx = pdb->env_db->startup_info->dwXSize;
|
|---|
| 246 | cs->cy = pdb->env_db->startup_info->dwYSize;
|
|---|
| 247 | }
|
|---|
| 248 | else
|
|---|
| 249 | {
|
|---|
| 250 | #endif
|
|---|
| 251 | cs->cx = 600; /* FIXME */
|
|---|
| 252 | cs->cy = 400;
|
|---|
| 253 | // }
|
|---|
| 254 | }
|
|---|
| 255 |
|
|---|
| 256 | if (cs->x < 0) cs->x = 0;
|
|---|
| 257 | if (cs->y < 0) cs->y = 0;
|
|---|
| 258 |
|
|---|
| 259 | //Allocate window words
|
|---|
| 260 | nrUserWindowLong = windowClass->getExtraWndWords();
|
|---|
| 261 | if(nrUserWindowLong) {
|
|---|
| 262 | userWindowLong = (ULONG *)_smalloc(nrUserWindowLong);
|
|---|
| 263 | memset(userWindowLong, 0, nrUserWindowLong);
|
|---|
| 264 | }
|
|---|
| 265 |
|
|---|
| 266 | if ((cs->style & WS_CHILD) && cs->hwndParent)
|
|---|
| 267 | {
|
|---|
| 268 | SetParent(cs->hwndParent);
|
|---|
| 269 | owner = GetWindowFromHandle(cs->hwndParent);
|
|---|
| 270 | if(owner == NULL)
|
|---|
| 271 | {
|
|---|
| 272 | dprintf(("HwGetWindowHandleData couldn't find owner window %x!!!", cs->hwndParent));
|
|---|
| 273 | return FALSE;
|
|---|
| 274 | }
|
|---|
| 275 | }
|
|---|
| 276 | else
|
|---|
| 277 | {
|
|---|
| 278 | if (!cs->hwndParent) {
|
|---|
| 279 | owner = NULL;
|
|---|
| 280 | }
|
|---|
| 281 | else
|
|---|
| 282 | {
|
|---|
| 283 | owner = GetWindowFromHandle(cs->hwndParent);
|
|---|
| 284 | if(owner == NULL)
|
|---|
| 285 | {
|
|---|
| 286 | dprintf(("HwGetWindowHandleData couldn't find owner window %x!!!", cs->hwndParent));
|
|---|
| 287 | return FALSE;
|
|---|
| 288 | }
|
|---|
| 289 | }
|
|---|
| 290 | }
|
|---|
| 291 |
|
|---|
| 292 | setWindowProc(windowClass->getWindowProc());
|
|---|
| 293 | hInstance = cs->hInstance;
|
|---|
| 294 | dwStyle = cs->style & ~WS_VISIBLE;
|
|---|
| 295 | dwExStyle = cs->dwExStyle;
|
|---|
| 296 |
|
|---|
| 297 | hwndLinkAfter = ((cs->style & (WS_CHILD|WS_MAXIMIZE)) == WS_CHILD)
|
|---|
| 298 | ? HWND_BOTTOM : HWND_TOP;
|
|---|
| 299 |
|
|---|
| 300 | #if 0
|
|---|
| 301 | //TODO
|
|---|
| 302 | /* Call the WH_CBT hook */
|
|---|
| 303 |
|
|---|
| 304 | if (HOOK_IsHooked( WH_CBT ))
|
|---|
| 305 | {
|
|---|
| 306 | CBT_CREATEWNDA cbtc;
|
|---|
| 307 | LRESULT ret;
|
|---|
| 308 |
|
|---|
| 309 | cbtc.lpcs = cs;
|
|---|
| 310 | cbtc.hwndInsertAfter = hwndLinkAfter;
|
|---|
| 311 | ret = unicode ? HOOK_CallHooksW(WH_CBT, HCBT_CREATEWND, Win32Hwnd, (LPARAM)&cbtc)
|
|---|
| 312 | : HOOK_CallHooksA(WH_CBT, HCBT_CREATEWND, Win32Hwnd, (LPARAM)&cbtc);
|
|---|
| 313 | if (ret)
|
|---|
| 314 | {
|
|---|
| 315 | TRACE_(win)("CBT-hook returned 0\n");
|
|---|
| 316 | wndPtr->pDriver->pFinalize(wndPtr);
|
|---|
| 317 | retvalue = 0;
|
|---|
| 318 | goto end;
|
|---|
| 319 | }
|
|---|
| 320 | }
|
|---|
| 321 | #endif
|
|---|
| 322 |
|
|---|
| 323 | /* Increment class window counter */
|
|---|
| 324 | windowClass->IncreaseWindowCount();
|
|---|
| 325 |
|
|---|
| 326 | /* Correct the window style */
|
|---|
| 327 | if (!(cs->style & WS_CHILD))
|
|---|
| 328 | {
|
|---|
| 329 | dwStyle |= WS_CLIPSIBLINGS;
|
|---|
| 330 | if (!(cs->style & WS_POPUP))
|
|---|
| 331 | {
|
|---|
| 332 | dwStyle |= WS_CAPTION;
|
|---|
| 333 | flags |= WIN_NEED_SIZE;
|
|---|
| 334 | }
|
|---|
| 335 | }
|
|---|
| 336 | if (cs->dwExStyle & WS_EX_DLGMODALFRAME) dwStyle &= ~WS_THICKFRAME;
|
|---|
| 337 |
|
|---|
| 338 | //TODO?
|
|---|
| 339 | #if 0
|
|---|
| 340 | /* Get class or window DC if needed */
|
|---|
| 341 | if (classPtr->style & CS_OWNDC) dce = DCE_AllocDCE(hwnd,DCE_WINDOW_DC);
|
|---|
| 342 | else if (classPtr->style & CS_CLASSDC) wndPtr->dce = classPtr->dce;
|
|---|
| 343 | else wndPtr->dce = NULL;
|
|---|
| 344 | #endif
|
|---|
| 345 |
|
|---|
| 346 | /* Send the WM_GETMINMAXINFO message and fix the size if needed */
|
|---|
| 347 | if ((cs->style & WS_THICKFRAME) || !(cs->style & (WS_POPUP | WS_CHILD)))
|
|---|
| 348 | {
|
|---|
| 349 | GetMinMaxInfo(&maxSize, &maxPos, &minTrack, &maxTrack);
|
|---|
| 350 | if (maxSize.x < cs->cx) cs->cx = maxSize.x;
|
|---|
| 351 | if (maxSize.y < cs->cy) cs->cy = maxSize.y;
|
|---|
| 352 | if (cs->cx < minTrack.x ) cs->cx = minTrack.x;
|
|---|
| 353 | if (cs->cy < minTrack.y ) cs->cy = minTrack.y;
|
|---|
| 354 | }
|
|---|
| 355 |
|
|---|
| 356 | if(cs->style & WS_CHILD)
|
|---|
| 357 | {
|
|---|
| 358 | if(cs->cx < 0) cs->cx = 0;
|
|---|
| 359 | if(cs->cy < 0) cs->cy = 0;
|
|---|
| 360 | }
|
|---|
| 361 | else
|
|---|
| 362 | {
|
|---|
| 363 | if (cs->cx <= 0) cs->cx = 1;
|
|---|
| 364 | if (cs->cy <= 0) cs->cy = 1;
|
|---|
| 365 | }
|
|---|
| 366 |
|
|---|
| 367 | rectWindow.left = cs->x;
|
|---|
| 368 | rectWindow.top = cs->y;
|
|---|
| 369 | rectWindow.right = cs->x + cs->cx;
|
|---|
| 370 | rectWindow.bottom = cs->y + cs->cy;
|
|---|
| 371 | rectClient = rectWindow;
|
|---|
| 372 |
|
|---|
| 373 | DWORD dwOSWinStyle, dwOSFrameStyle;
|
|---|
| 374 |
|
|---|
| 375 | OSLibWinConvertStyle(cs->style, cs->dwExStyle, &dwOSWinStyle, &dwOSFrameStyle);
|
|---|
| 376 |
|
|---|
| 377 | //TODO: Test
|
|---|
| 378 | #if 1
|
|---|
| 379 | if(cs->style & WS_CHILD) {
|
|---|
| 380 | dwOSFrameStyle = 0;
|
|---|
| 381 | }
|
|---|
| 382 | #endif
|
|---|
| 383 |
|
|---|
| 384 | if(cs->lpszName)
|
|---|
| 385 | SetWindowText((LPSTR)cs->lpszName);
|
|---|
| 386 |
|
|---|
| 387 | OS2Hwnd = OSLibWinCreateWindow((getParent()) ? getParent()->getOS2WindowHandle() : OSLIB_HWND_DESKTOP,
|
|---|
| 388 | dwOSWinStyle, dwOSFrameStyle, (char *)windowNameA,
|
|---|
| 389 | (owner) ? owner->getOS2WindowHandle() : OSLIB_HWND_DESKTOP,
|
|---|
| 390 | (hwndLinkAfter == HWND_BOTTOM) ? TRUE : FALSE,
|
|---|
| 391 | &OS2HwndFrame);
|
|---|
| 392 |
|
|---|
| 393 | if(OS2Hwnd == 0) {
|
|---|
| 394 | dprintf(("Window creation failed!!"));
|
|---|
| 395 | return FALSE;
|
|---|
| 396 | }
|
|---|
| 397 |
|
|---|
| 398 | if(OSLibWinSetWindowULong(OS2Hwnd, OFFSET_WIN32WNDPTR, (ULONG)this) == FALSE) {
|
|---|
| 399 | dprintf(("WM_CREATE: WinSetWindowULong %X failed!!", OS2Hwnd));
|
|---|
| 400 | return FALSE;
|
|---|
| 401 | }
|
|---|
| 402 | if(OSLibWinSetWindowULong(OS2Hwnd, OFFSET_WIN32PM_MAGIC, WIN32PM_MAGIC) == FALSE) {
|
|---|
| 403 | dprintf(("WM_CREATE: WinSetWindowULong2 %X failed!!", OS2Hwnd));
|
|---|
| 404 | return FALSE;
|
|---|
| 405 | }
|
|---|
| 406 | //SvL: Need to store the shared memory base, or else other apps can map it into their memory space
|
|---|
| 407 | if(OSLibWinSetWindowULong(OS2Hwnd, OFFSET_WIN32PM_SHAREDMEM, HeapGetSharedMemBase()) == FALSE) {
|
|---|
| 408 | dprintf(("WM_CREATE: WinSetWindowULong2 %X failed!!", OS2Hwnd));
|
|---|
| 409 | return FALSE;
|
|---|
| 410 | }
|
|---|
| 411 | #if 0
|
|---|
| 412 | if(OS2Hwnd != OS2HwndFrame) {
|
|---|
| 413 | if(OSLibWinSetWindowULong(OS2HwndFrame, OFFSET_WIN32WNDPTR, (ULONG)this) == FALSE) {
|
|---|
| 414 | dprintf(("WM_CREATE: WinSetWindowULong %X failed!!", OS2HwndFrame));
|
|---|
| 415 | return FALSE;
|
|---|
| 416 | }
|
|---|
| 417 | if(OSLibWinSetWindowULong(OS2HwndFrame, OFFSET_WIN32PM_MAGIC, WIN32PM_MAGIC) == FALSE) {
|
|---|
| 418 | dprintf(("WM_CREATE: WinSetWindowULong2 %X failed!!", OS2HwndFrame));
|
|---|
| 419 | return FALSE;
|
|---|
| 420 | }
|
|---|
| 421 | //SvL: Need to store the shared memory base, or else other apps can map it into their memory space
|
|---|
| 422 | if(OSLibWinSetWindowULong(OS2HwndFrame, OFFSET_WIN32PM_SHAREDMEM, HeapGetSharedMemBase()) == FALSE) {
|
|---|
| 423 | dprintf(("WM_CREATE: WinSetWindowULong2 %X failed!!", OS2HwndFrame));
|
|---|
| 424 | return FALSE;
|
|---|
| 425 | }
|
|---|
| 426 | }
|
|---|
| 427 | #endif
|
|---|
| 428 |
|
|---|
| 429 | /* Set the window menu */
|
|---|
| 430 | if ((dwStyle & (WS_CAPTION | WS_CHILD)) == WS_CAPTION )
|
|---|
| 431 | {
|
|---|
| 432 | if (cs->hMenu) SetMenu(cs->hMenu);
|
|---|
| 433 | else
|
|---|
| 434 | {
|
|---|
| 435 | if (windowClass->getMenuNameA()) {
|
|---|
| 436 | cs->hMenu = LoadMenuA(cs->hInstance, windowClass->getMenuNameA());
|
|---|
| 437 | if (cs->hMenu) SetMenu(cs->hMenu );
|
|---|
| 438 | }
|
|---|
| 439 | }
|
|---|
| 440 | }
|
|---|
| 441 | else windowId = (UINT)cs->hMenu;
|
|---|
| 442 |
|
|---|
| 443 | //Set icon from class
|
|---|
| 444 | if(windowClass->getIcon())
|
|---|
| 445 | SetIcon(windowClass->getIcon());
|
|---|
| 446 |
|
|---|
| 447 | if(getParent()) {
|
|---|
| 448 | SetWindowPos(getParent()->getWindowHandle(), rectClient.left, rectClient.top,
|
|---|
| 449 | rectClient.right-rectClient.left,
|
|---|
| 450 | rectClient.bottom-rectClient.top,
|
|---|
| 451 | SWP_NOACTIVATE | SWP_NOZORDER);
|
|---|
| 452 | }
|
|---|
| 453 | else {
|
|---|
| 454 | SetWindowPos(HWND_TOP, rectClient.left, rectClient.top,
|
|---|
| 455 | rectClient.right-rectClient.left,
|
|---|
| 456 | rectClient.bottom-rectClient.top,
|
|---|
| 457 | SWP_NOACTIVATE);
|
|---|
| 458 | }
|
|---|
| 459 | //Get the client window rectangle
|
|---|
| 460 | GetClientRect(Win32Hwnd, &rectClient);
|
|---|
| 461 |
|
|---|
| 462 | /* Send the WM_CREATE message
|
|---|
| 463 | * Perhaps we shouldn't allow width/height changes as well.
|
|---|
| 464 | * See p327 in "Internals".
|
|---|
| 465 | */
|
|---|
| 466 | maxPos.x = rectWindow.left; maxPos.y = rectWindow.top;
|
|---|
| 467 |
|
|---|
| 468 | fCreated = TRUE; //Allow WM_SIZE messages now
|
|---|
| 469 | if(SendInternalMessage(WM_NCCREATE, 0, (LPARAM)cs) )
|
|---|
| 470 | {
|
|---|
| 471 | //doesn't work right, messes up client rectangle
|
|---|
| 472 | #if 0
|
|---|
| 473 | SendNCCalcSize(FALSE, &rectWindow, NULL, NULL, 0, &rectClient );
|
|---|
| 474 | #endif
|
|---|
| 475 | OffsetRect(&rectWindow, maxPos.x - rectWindow.left, maxPos.y - rectWindow.top);
|
|---|
| 476 | dprintf(("Sending WM_CREATE"));
|
|---|
| 477 | if( (SendInternalMessage(WM_CREATE, 0, (LPARAM)cs )) != -1 )
|
|---|
| 478 | {
|
|---|
| 479 | if(!(flags & WIN_NEED_SIZE)) {
|
|---|
| 480 | SendMessageA(WM_SIZE, SIZE_RESTORED,
|
|---|
| 481 | MAKELONG(rectClient.right-rectClient.left,
|
|---|
| 482 | rectClient.bottom-rectClient.top));
|
|---|
| 483 | SendMessageA(WM_MOVE, 0, MAKELONG( rectClient.left, rectClient.top ) );
|
|---|
| 484 | }
|
|---|
| 485 | if (cs->style & WS_VISIBLE) ShowWindow( sw );
|
|---|
| 486 |
|
|---|
| 487 | #if 0
|
|---|
| 488 | /* Call WH_SHELL hook */
|
|---|
| 489 |
|
|---|
| 490 | if (!(dwStyle & WS_CHILD) && !owner)
|
|---|
| 491 | HOOK_CallHooks16( WH_SHELL, HSHELL_WINDOWCREATED, hwnd, 0 );
|
|---|
| 492 | #endif
|
|---|
| 493 | SetLastError(0);
|
|---|
| 494 | return TRUE;
|
|---|
| 495 | }
|
|---|
| 496 | }
|
|---|
| 497 | fCreated = FALSE;
|
|---|
| 498 | OSLibWinSetWindowULong(OS2Hwnd, OFFSET_WIN32WNDPTR, 0);
|
|---|
| 499 | OSLibWinSetWindowULong(OS2Hwnd, OFFSET_WIN32PM_MAGIC, 0);
|
|---|
| 500 | DestroyWindow();
|
|---|
| 501 | return FALSE;
|
|---|
| 502 | }
|
|---|
| 503 | #if 0
|
|---|
| 504 | /***********************************************************************
|
|---|
| 505 | * WINPOS_MinMaximize
|
|---|
| 506 | *
|
|---|
| 507 | * Fill in lpRect and return additional flags to be used with SetWindowPos().
|
|---|
| 508 | * This function assumes that 'cmd' is different from the current window
|
|---|
| 509 | * state.
|
|---|
| 510 | */
|
|---|
| 511 | UINT Win32BaseWindow::MinMaximize(UINT cmd, LPRECT lpRect )
|
|---|
| 512 | {
|
|---|
| 513 | UINT swpFlags = 0;
|
|---|
| 514 | POINT pt, size;
|
|---|
| 515 | LPINTERNALPOS lpPos;
|
|---|
| 516 |
|
|---|
| 517 | size.x = rectWindow.left; size.y = rectWindow.top;
|
|---|
| 518 | lpPos = WINPOS_InitInternalPos( wndPtr, size, &rectWindow );
|
|---|
| 519 |
|
|---|
| 520 | if (lpPos && !HOOK_CallHooks16(WH_CBT, HCBT_MINMAX, hwndSelf, cmd))
|
|---|
| 521 | {
|
|---|
| 522 | if( dwStyle & WS_MINIMIZE )
|
|---|
| 523 | {
|
|---|
| 524 | if( !SendInternalMessageA(WM_QUERYOPEN, 0, 0L ) )
|
|---|
| 525 | return (SWP_NOSIZE | SWP_NOMOVE);
|
|---|
| 526 | swpFlags |= SWP_NOCOPYBITS;
|
|---|
| 527 | }
|
|---|
| 528 | switch( cmd )
|
|---|
| 529 | {
|
|---|
| 530 | case SW_MINIMIZE:
|
|---|
| 531 | if( dwStyle & WS_MAXIMIZE)
|
|---|
| 532 | {
|
|---|
| 533 | flags |= WIN_RESTORE_MAX;
|
|---|
| 534 | dwStyle &= ~WS_MAXIMIZE;
|
|---|
| 535 | }
|
|---|
| 536 | else
|
|---|
| 537 | flags &= ~WIN_RESTORE_MAX;
|
|---|
| 538 | dwStyle |= WS_MINIMIZE;
|
|---|
| 539 |
|
|---|
| 540 | #if 0
|
|---|
| 541 | if( flags & WIN_NATIVE )
|
|---|
| 542 | if( pDriver->pSetHostAttr( wndPtr, HAK_ICONICSTATE, TRUE ) )
|
|---|
| 543 | swpFlags |= MINMAX_NOSWP;
|
|---|
| 544 | #endif
|
|---|
| 545 |
|
|---|
| 546 | lpPos->ptIconPos = WINPOS_FindIconPos( wndPtr, lpPos->ptIconPos );
|
|---|
| 547 |
|
|---|
| 548 | SetRect(lpRect, lpPos->ptIconPos.x, lpPos->ptIconPos.y,
|
|---|
| 549 | GetSystemMetrics(SM_CXICON), GetSystemMetrics(SM_CYICON) );
|
|---|
| 550 | swpFlags |= SWP_NOCOPYBITS;
|
|---|
| 551 | break;
|
|---|
| 552 |
|
|---|
| 553 | case SW_MAXIMIZE:
|
|---|
| 554 | WINPOS_GetMinMaxInfo( wndPtr, &size, &pt, NULL, NULL );
|
|---|
| 555 |
|
|---|
| 556 | if( dwStyle & WS_MINIMIZE )
|
|---|
| 557 | {
|
|---|
| 558 | if( flags & WIN_NATIVE )
|
|---|
| 559 | if( pDriver->pSetHostAttr( wndPtr, HAK_ICONICSTATE, FALSE ) )
|
|---|
| 560 | swpFlags |= MINMAX_NOSWP;
|
|---|
| 561 |
|
|---|
| 562 | WINPOS_ShowIconTitle( wndPtr, FALSE );
|
|---|
| 563 | dwStyle &= ~WS_MINIMIZE;
|
|---|
| 564 | }
|
|---|
| 565 | dwStyle |= WS_MAXIMIZE;
|
|---|
| 566 |
|
|---|
| 567 | SetRect16( lpRect, lpPos->ptMaxPos.x, lpPos->ptMaxPos.y,
|
|---|
| 568 | size.x, size.y );
|
|---|
| 569 | break;
|
|---|
| 570 |
|
|---|
| 571 | case SW_RESTORE:
|
|---|
| 572 | if( dwStyle & WS_MINIMIZE )
|
|---|
| 573 | {
|
|---|
| 574 | if( flags & WIN_NATIVE )
|
|---|
| 575 | if( pDriver->pSetHostAttr( wndPtr, HAK_ICONICSTATE, FALSE ) )
|
|---|
| 576 | swpFlags |= MINMAX_NOSWP;
|
|---|
| 577 |
|
|---|
| 578 | dwStyle &= ~WS_MINIMIZE;
|
|---|
| 579 | WINPOS_ShowIconTitle( wndPtr, FALSE );
|
|---|
| 580 |
|
|---|
| 581 | if( flags & WIN_RESTORE_MAX)
|
|---|
| 582 | {
|
|---|
| 583 | /* Restore to maximized position */
|
|---|
| 584 | CONV_POINT16TO32( &lpPos->ptMaxPos, &pt );
|
|---|
| 585 | WINPOS_GetMinMaxInfo( wndPtr, &size, &pt, NULL, NULL);
|
|---|
| 586 | CONV_POINT32TO16( &pt, &lpPos->ptMaxPos );
|
|---|
| 587 | dwStyle |= WS_MAXIMIZE;
|
|---|
| 588 | SetRect16( lpRect, lpPos->ptMaxPos.x, lpPos->ptMaxPos.y, size.x, size.y );
|
|---|
| 589 | break;
|
|---|
| 590 | }
|
|---|
| 591 | }
|
|---|
| 592 | else
|
|---|
| 593 | if( !(dwStyle & WS_MAXIMIZE) ) return (UINT16)(-1);
|
|---|
| 594 | else dwStyle &= ~WS_MAXIMIZE;
|
|---|
| 595 |
|
|---|
| 596 | /* Restore to normal position */
|
|---|
| 597 |
|
|---|
| 598 | *lpRect = lpPos->rectNormal;
|
|---|
| 599 | lpRect->right -= lpRect->left;
|
|---|
| 600 | lpRect->bottom -= lpRect->top;
|
|---|
| 601 |
|
|---|
| 602 | break;
|
|---|
| 603 | }
|
|---|
| 604 | } else swpFlags |= SWP_NOSIZE | SWP_NOMOVE;
|
|---|
| 605 | return swpFlags;
|
|---|
| 606 | }
|
|---|
| 607 | #endif
|
|---|
| 608 | /*******************************************************************
|
|---|
| 609 | * GetMinMaxInfo
|
|---|
| 610 | *
|
|---|
| 611 | * Get the minimized and maximized information for a window.
|
|---|
| 612 | */
|
|---|
| 613 | void Win32BaseWindow::GetMinMaxInfo(POINT *maxSize, POINT *maxPos,
|
|---|
| 614 | POINT *minTrack, POINT *maxTrack )
|
|---|
| 615 | {
|
|---|
| 616 | MINMAXINFO MinMax;
|
|---|
| 617 | INT xinc, yinc;
|
|---|
| 618 |
|
|---|
| 619 | /* Compute default values */
|
|---|
| 620 |
|
|---|
| 621 | MinMax.ptMaxSize.x = GetSystemMetrics(SM_CXSCREEN);
|
|---|
| 622 | MinMax.ptMaxSize.y = GetSystemMetrics(SM_CYSCREEN);
|
|---|
| 623 | MinMax.ptMinTrackSize.x = GetSystemMetrics(SM_CXMINTRACK);
|
|---|
| 624 | MinMax.ptMinTrackSize.y = GetSystemMetrics(SM_CYMINTRACK);
|
|---|
| 625 | MinMax.ptMaxTrackSize.x = GetSystemMetrics(SM_CXSCREEN);
|
|---|
| 626 | MinMax.ptMaxTrackSize.y = GetSystemMetrics(SM_CYSCREEN);
|
|---|
| 627 |
|
|---|
| 628 | if (flags & WIN_MANAGED) xinc = yinc = 0;
|
|---|
| 629 | else if (HAS_DLGFRAME( dwStyle, dwExStyle ))
|
|---|
| 630 | {
|
|---|
| 631 | xinc = GetSystemMetrics(SM_CXDLGFRAME);
|
|---|
| 632 | yinc = GetSystemMetrics(SM_CYDLGFRAME);
|
|---|
| 633 | }
|
|---|
| 634 | else
|
|---|
| 635 | {
|
|---|
| 636 | xinc = yinc = 0;
|
|---|
| 637 | if (HAS_THICKFRAME(dwStyle))
|
|---|
| 638 | {
|
|---|
| 639 | xinc += GetSystemMetrics(SM_CXFRAME);
|
|---|
| 640 | yinc += GetSystemMetrics(SM_CYFRAME);
|
|---|
| 641 | }
|
|---|
| 642 | if (dwStyle & WS_BORDER)
|
|---|
| 643 | {
|
|---|
| 644 | xinc += GetSystemMetrics(SM_CXBORDER);
|
|---|
| 645 | yinc += GetSystemMetrics(SM_CYBORDER);
|
|---|
| 646 | }
|
|---|
| 647 | }
|
|---|
| 648 | MinMax.ptMaxSize.x += 2 * xinc;
|
|---|
| 649 | MinMax.ptMaxSize.y += 2 * yinc;
|
|---|
| 650 |
|
|---|
| 651 | #if 0
|
|---|
| 652 | lpPos = (LPINTERNALPOS)GetPropA( hwndSelf, atomInternalPos );
|
|---|
| 653 | if( lpPos && !EMPTYPOINT(lpPos->ptMaxPos) )
|
|---|
| 654 | CONV_POINT16TO32( &lpPos->ptMaxPos, &MinMax.ptMaxPosition );
|
|---|
| 655 | else
|
|---|
| 656 | {
|
|---|
| 657 | #endif
|
|---|
| 658 | MinMax.ptMaxPosition.x = -xinc;
|
|---|
| 659 | MinMax.ptMaxPosition.y = -yinc;
|
|---|
| 660 | // }
|
|---|
| 661 |
|
|---|
| 662 | SendInternalMessageA(WM_GETMINMAXINFO, 0, (LPARAM)&MinMax );
|
|---|
| 663 |
|
|---|
| 664 | /* Some sanity checks */
|
|---|
| 665 |
|
|---|
| 666 | dprintf(("GetMinMaxInfo: %ld %ld / %ld %ld / %ld %ld / %ld %ld\n",
|
|---|
| 667 | MinMax.ptMaxSize.x, MinMax.ptMaxSize.y,
|
|---|
| 668 | MinMax.ptMaxPosition.x, MinMax.ptMaxPosition.y,
|
|---|
| 669 | MinMax.ptMaxTrackSize.x, MinMax.ptMaxTrackSize.y,
|
|---|
| 670 | MinMax.ptMinTrackSize.x, MinMax.ptMinTrackSize.y));
|
|---|
| 671 | MinMax.ptMaxTrackSize.x = MAX( MinMax.ptMaxTrackSize.x,
|
|---|
| 672 | MinMax.ptMinTrackSize.x );
|
|---|
| 673 | MinMax.ptMaxTrackSize.y = MAX( MinMax.ptMaxTrackSize.y,
|
|---|
| 674 | MinMax.ptMinTrackSize.y );
|
|---|
| 675 |
|
|---|
| 676 | if (maxSize) *maxSize = MinMax.ptMaxSize;
|
|---|
| 677 | if (maxPos) *maxPos = MinMax.ptMaxPosition;
|
|---|
| 678 | if (minTrack) *minTrack = MinMax.ptMinTrackSize;
|
|---|
| 679 | if (maxTrack) *maxTrack = MinMax.ptMaxTrackSize;
|
|---|
| 680 | }
|
|---|
| 681 | /***********************************************************************
|
|---|
| 682 | * WINPOS_SendNCCalcSize
|
|---|
| 683 | *
|
|---|
| 684 | * Send a WM_NCCALCSIZE message to a window.
|
|---|
| 685 | * All parameters are read-only except newClientRect.
|
|---|
| 686 | * oldWindowRect, oldClientRect and winpos must be non-NULL only
|
|---|
| 687 | * when calcValidRect is TRUE.
|
|---|
| 688 | */
|
|---|
| 689 | LONG Win32BaseWindow::SendNCCalcSize(BOOL calcValidRect, RECT *newWindowRect, RECT *oldWindowRect,
|
|---|
| 690 | RECT *oldClientRect, WINDOWPOS *winpos,
|
|---|
| 691 | RECT *newClientRect )
|
|---|
| 692 | {
|
|---|
| 693 | NCCALCSIZE_PARAMS params;
|
|---|
| 694 | WINDOWPOS winposCopy;
|
|---|
| 695 | LONG result;
|
|---|
| 696 |
|
|---|
| 697 | params.rgrc[0] = *newWindowRect;
|
|---|
| 698 | if (calcValidRect)
|
|---|
| 699 | {
|
|---|
| 700 | winposCopy = *winpos;
|
|---|
| 701 | params.rgrc[1] = *oldWindowRect;
|
|---|
| 702 | params.rgrc[2] = *oldClientRect;
|
|---|
| 703 | params.lppos = &winposCopy;
|
|---|
| 704 | }
|
|---|
| 705 | result = SendInternalMessageA(WM_NCCALCSIZE, calcValidRect,
|
|---|
| 706 | (LPARAM)¶ms );
|
|---|
| 707 | *newClientRect = params.rgrc[0];
|
|---|
| 708 | return result;
|
|---|
| 709 | }
|
|---|
| 710 | //******************************************************************************
|
|---|
| 711 | //******************************************************************************
|
|---|
| 712 | ULONG Win32BaseWindow::MsgCreate(HWND hwndOS2, ULONG initParam)
|
|---|
| 713 | {
|
|---|
| 714 | OS2Hwnd = hwndOS2;
|
|---|
| 715 | return SendInternalMessageA(WM_CREATE, 0, initParam);
|
|---|
| 716 | }
|
|---|
| 717 | //******************************************************************************
|
|---|
| 718 | //******************************************************************************
|
|---|
| 719 | ULONG Win32BaseWindow::MsgQuit()
|
|---|
| 720 | {
|
|---|
| 721 | return SendInternalMessageA(WM_QUIT, 0, 0);
|
|---|
| 722 | }
|
|---|
| 723 | //******************************************************************************
|
|---|
| 724 | //******************************************************************************
|
|---|
| 725 | ULONG Win32BaseWindow::MsgClose()
|
|---|
| 726 | {
|
|---|
| 727 | if(SendInternalMessageA(WM_CLOSE, 0, 0) == 0) {
|
|---|
| 728 | return 0; //app handles this message
|
|---|
| 729 | }
|
|---|
| 730 | delete this;
|
|---|
| 731 | return 1;
|
|---|
| 732 | }
|
|---|
| 733 | //******************************************************************************
|
|---|
| 734 | //******************************************************************************
|
|---|
| 735 | ULONG Win32BaseWindow::MsgDestroy()
|
|---|
| 736 | {
|
|---|
| 737 | ULONG rc;
|
|---|
| 738 |
|
|---|
| 739 | rc = SendInternalMessageA(WM_DESTROY, 0, 0);
|
|---|
| 740 | delete this;
|
|---|
| 741 | return rc;
|
|---|
| 742 | }
|
|---|
| 743 | //******************************************************************************
|
|---|
| 744 | //******************************************************************************
|
|---|
| 745 | ULONG Win32BaseWindow::MsgEnable(BOOL fEnable)
|
|---|
| 746 | {
|
|---|
| 747 | return SendInternalMessageA(WM_ENABLE, fEnable, 0);
|
|---|
| 748 | }
|
|---|
| 749 | //******************************************************************************
|
|---|
| 750 | //TODO: SW_PARENTCLOSING/OPENING flag (lParam)
|
|---|
| 751 | //******************************************************************************
|
|---|
| 752 | ULONG Win32BaseWindow::MsgShow(BOOL fShow)
|
|---|
| 753 | {
|
|---|
| 754 | return SendInternalMessageA(WM_SHOWWINDOW, fShow, 0);
|
|---|
| 755 | }
|
|---|
| 756 | //******************************************************************************
|
|---|
| 757 | //******************************************************************************
|
|---|
| 758 | ULONG Win32BaseWindow::MsgPosChanging(LPARAM lp)
|
|---|
| 759 | {
|
|---|
| 760 | dprintf(("MsgPosChanging"));
|
|---|
| 761 | #if 1
|
|---|
| 762 | if(fCreated == FALSE) {
|
|---|
| 763 | return 1;
|
|---|
| 764 | }
|
|---|
| 765 | #endif
|
|---|
| 766 | return SendInternalMessageA(WM_WINDOWPOSCHANGING, 0, lp);
|
|---|
| 767 | }
|
|---|
| 768 | //******************************************************************************
|
|---|
| 769 | //******************************************************************************
|
|---|
| 770 | ULONG Win32BaseWindow::MsgPosChanged(LPARAM lp)
|
|---|
| 771 | {
|
|---|
| 772 | dprintf(("MsgPosChanged"));
|
|---|
| 773 | #if 1
|
|---|
| 774 | if(fCreated == FALSE) {
|
|---|
| 775 | return 1;
|
|---|
| 776 | }
|
|---|
| 777 | #endif
|
|---|
| 778 | return SendInternalMessageA(WM_WINDOWPOSCHANGED, 0, lp);
|
|---|
| 779 | }
|
|---|
| 780 | //******************************************************************************
|
|---|
| 781 | //******************************************************************************
|
|---|
| 782 | ULONG Win32BaseWindow::MsgMove(ULONG x, ULONG y)
|
|---|
| 783 | {
|
|---|
| 784 | dprintf(("MsgMove to (%d,%d)", x, y));
|
|---|
| 785 | if(fCreated == FALSE) {
|
|---|
| 786 | return 1;
|
|---|
| 787 | }
|
|---|
| 788 |
|
|---|
| 789 | return SendInternalMessageA(WM_MOVE, 0, MAKELONG((USHORT)x, (USHORT)y));
|
|---|
| 790 | }
|
|---|
| 791 | //******************************************************************************
|
|---|
| 792 | //******************************************************************************
|
|---|
| 793 | ULONG Win32BaseWindow::MsgCommand(ULONG cmd, ULONG Id, HWND hwnd)
|
|---|
| 794 | {
|
|---|
| 795 | switch(cmd) {
|
|---|
| 796 | case CMD_MENU:
|
|---|
| 797 | return SendInternalMessageA(WM_COMMAND, MAKELONG(Id, 0), 0);
|
|---|
| 798 | case CMD_CONTROL:
|
|---|
| 799 | return 0; //todo
|
|---|
| 800 | case CMD_ACCELERATOR:
|
|---|
| 801 | dprintf(("accelerator command"));
|
|---|
| 802 | return 0; //todo
|
|---|
| 803 | }
|
|---|
| 804 | return 0;
|
|---|
| 805 | }
|
|---|
| 806 | //******************************************************************************
|
|---|
| 807 | //******************************************************************************
|
|---|
| 808 | ULONG Win32BaseWindow::MsgHitTest(ULONG x, ULONG y)
|
|---|
| 809 | {
|
|---|
| 810 | lastHitTestVal = SendInternalMessageA(WM_NCHITTEST, 0, MAKELONG((USHORT)x, (USHORT)y));
|
|---|
| 811 | return 1; //TODO: May need to change this
|
|---|
| 812 | }
|
|---|
| 813 | //******************************************************************************
|
|---|
| 814 | //TODO: Send WM_NCCALCSIZE message here and correct size if necessary
|
|---|
| 815 | //******************************************************************************
|
|---|
| 816 | ULONG Win32BaseWindow::MsgSize(ULONG width, ULONG height, BOOL fMinimize, BOOL fMaximize)
|
|---|
| 817 | {
|
|---|
| 818 | WORD fwSizeType = 0;
|
|---|
| 819 |
|
|---|
| 820 | if(fCreated == FALSE) {//Solitaire crashes if it receives a WM_SIZE during CreateWindowEx (normal or our fault?)
|
|---|
| 821 | return 1;
|
|---|
| 822 | }
|
|---|
| 823 |
|
|---|
| 824 | if(fMinimize) {
|
|---|
| 825 | fwSizeType = SIZE_MINIMIZED;
|
|---|
| 826 | }
|
|---|
| 827 | else
|
|---|
| 828 | if(fMaximize) {
|
|---|
| 829 | fwSizeType = SIZE_MAXIMIZED;
|
|---|
| 830 | }
|
|---|
| 831 | else fwSizeType = SIZE_RESTORED;
|
|---|
| 832 |
|
|---|
| 833 | return SendInternalMessageA(WM_SIZE, fwSizeType, MAKELONG((USHORT)width, (USHORT)height));
|
|---|
| 834 | }
|
|---|
| 835 | //******************************************************************************
|
|---|
| 836 | //******************************************************************************
|
|---|
| 837 | ULONG Win32BaseWindow::MsgActivate(BOOL fActivate, HWND hwnd)
|
|---|
| 838 | {
|
|---|
| 839 | if(SendInternalMessageA(WM_NCACTIVATE, fActivate, 0) == FALSE)
|
|---|
| 840 | {
|
|---|
| 841 | if(!fActivate) {
|
|---|
| 842 | return 1;
|
|---|
| 843 | }
|
|---|
| 844 | }
|
|---|
| 845 | return SendInternalMessageA(WM_ACTIVATE, (fActivate) ? WA_ACTIVE : WA_INACTIVE, hwnd);
|
|---|
| 846 | }
|
|---|
| 847 | //******************************************************************************
|
|---|
| 848 | //******************************************************************************
|
|---|
| 849 | ULONG Win32BaseWindow::MsgSysCommand(ULONG win32sc, ULONG x, ULONG y)
|
|---|
| 850 | {
|
|---|
| 851 | return SendInternalMessageA(WM_SYSCOMMAND, win32sc, MAKELONG((USHORT)x, (USHORT)y));
|
|---|
| 852 | }
|
|---|
| 853 | //******************************************************************************
|
|---|
| 854 | //TODO: virtual key & (possibly) scancode translation, extended keyboard bit & Unicode
|
|---|
| 855 | //******************************************************************************
|
|---|
| 856 | ULONG Win32BaseWindow::MsgChar(ULONG cmd, ULONG repeatcnt, ULONG scancode, ULONG vkey, ULONG keyflags)
|
|---|
| 857 | {
|
|---|
| 858 | ULONG lParam = 0;
|
|---|
| 859 |
|
|---|
| 860 | lParam = repeatcnt;
|
|---|
| 861 | lParam |= (scancode << 16);
|
|---|
| 862 | if(keyflags & KEY_ALTDOWN)
|
|---|
| 863 | lParam |= (1<<29);
|
|---|
| 864 | if(keyflags & KEY_PREVDOWN)
|
|---|
| 865 | lParam |= (1<<30);
|
|---|
| 866 | if(keyflags & KEY_UP)
|
|---|
| 867 | lParam |= (1<<31);
|
|---|
| 868 | if(keyflags & KEY_DEADKEY) {
|
|---|
| 869 | dprintf(("WM_DEADCHAR: %x %x %08x", OS2Hwnd, cmd, lParam));
|
|---|
| 870 | return SendInternalMessageA(WM_DEADCHAR, cmd, lParam);
|
|---|
| 871 | }
|
|---|
| 872 | else {
|
|---|
| 873 | dprintf(("WM_CHAR: %x %x %08x", OS2Hwnd, cmd, lParam));
|
|---|
| 874 | return SendInternalMessageA(WM_CHAR, cmd, lParam);
|
|---|
| 875 | }
|
|---|
| 876 | }
|
|---|
| 877 | //******************************************************************************
|
|---|
| 878 | //******************************************************************************
|
|---|
| 879 | ULONG Win32BaseWindow::MsgSetFocus(HWND hwnd)
|
|---|
| 880 | {
|
|---|
| 881 | if(hwnd == 0) {
|
|---|
| 882 | //other app lost focus
|
|---|
| 883 | SendInternalMessageA(WM_ACTIVATEAPP, TRUE, 0); //TODO: Need thread id from hwnd app
|
|---|
| 884 | }
|
|---|
| 885 | return SendInternalMessageA(WM_SETFOCUS, hwnd, 0);
|
|---|
| 886 | }
|
|---|
| 887 | //******************************************************************************
|
|---|
| 888 | //******************************************************************************
|
|---|
| 889 | ULONG Win32BaseWindow::MsgKillFocus(HWND hwnd)
|
|---|
| 890 | {
|
|---|
| 891 | if(hwnd == 0) {
|
|---|
| 892 | //other app lost focus
|
|---|
| 893 | SendInternalMessageA(WM_ACTIVATEAPP, FALSE, 0); //TODO: Need thread id from hwnd app
|
|---|
| 894 | }
|
|---|
| 895 | return SendInternalMessageA(WM_KILLFOCUS, hwnd, 0);
|
|---|
| 896 | }
|
|---|
| 897 | //******************************************************************************
|
|---|
| 898 | //******************************************************************************
|
|---|
| 899 | ULONG Win32BaseWindow::MsgButton(ULONG msg, ULONG ncx, ULONG ncy, ULONG clx, ULONG cly)
|
|---|
| 900 | {
|
|---|
| 901 | ULONG win32msg;
|
|---|
| 902 | ULONG win32ncmsg;
|
|---|
| 903 |
|
|---|
| 904 | dprintf(("MsgButton to (%d,%d)", ncx, ncy));
|
|---|
| 905 | switch(msg) {
|
|---|
| 906 | case BUTTON_LEFTDOWN:
|
|---|
| 907 | win32msg = WM_LBUTTONDOWN;
|
|---|
| 908 | win32ncmsg = WM_NCLBUTTONDOWN;
|
|---|
| 909 | break;
|
|---|
| 910 | case BUTTON_LEFTUP:
|
|---|
| 911 | win32msg = WM_LBUTTONUP;
|
|---|
| 912 | win32ncmsg = WM_NCLBUTTONUP;
|
|---|
| 913 | break;
|
|---|
| 914 | case BUTTON_LEFTDBLCLICK:
|
|---|
| 915 | win32msg = WM_LBUTTONDBLCLK;
|
|---|
| 916 | win32ncmsg = WM_NCLBUTTONDBLCLK;
|
|---|
| 917 | break;
|
|---|
| 918 | case BUTTON_RIGHTUP:
|
|---|
| 919 | win32msg = WM_RBUTTONUP;
|
|---|
| 920 | win32ncmsg = WM_NCRBUTTONUP;
|
|---|
| 921 | break;
|
|---|
| 922 | case BUTTON_RIGHTDOWN:
|
|---|
| 923 | win32msg = WM_RBUTTONDOWN;
|
|---|
| 924 | win32ncmsg = WM_NCRBUTTONDOWN;
|
|---|
| 925 | break;
|
|---|
| 926 | case BUTTON_RIGHTDBLCLICK:
|
|---|
| 927 | win32msg = WM_RBUTTONDBLCLK;
|
|---|
| 928 | win32ncmsg = WM_NCRBUTTONDBLCLK;
|
|---|
| 929 | break;
|
|---|
| 930 | case BUTTON_MIDDLEUP:
|
|---|
| 931 | win32msg = WM_MBUTTONUP;
|
|---|
| 932 | win32ncmsg = WM_NCMBUTTONUP;
|
|---|
| 933 | break;
|
|---|
| 934 | case BUTTON_MIDDLEDOWN:
|
|---|
| 935 | win32msg = WM_MBUTTONDOWN;
|
|---|
| 936 | win32ncmsg = WM_NCMBUTTONDOWN;
|
|---|
| 937 | break;
|
|---|
| 938 | case BUTTON_MIDDLEDBLCLICK:
|
|---|
| 939 | win32msg = WM_MBUTTONDBLCLK;
|
|---|
| 940 | win32ncmsg = WM_NCMBUTTONDBLCLK;
|
|---|
| 941 | break;
|
|---|
| 942 | default:
|
|---|
| 943 | dprintf(("Win32BaseWindow::Button: invalid msg!!!!"));
|
|---|
| 944 | return 1;
|
|---|
| 945 | }
|
|---|
| 946 | if(win32msg == WM_MBUTTONDBLCLK || win32msg == WM_RBUTTONDBLCLK || win32msg == WM_LBUTTONDBLCLK) {
|
|---|
| 947 | if(!(windowClass->getClassLongA(GCL_STYLE) & CS_DBLCLKS)) {
|
|---|
| 948 | return 1;
|
|---|
| 949 | }
|
|---|
| 950 | }
|
|---|
| 951 | SendInternalMessageA(WM_SETCURSOR, Win32Hwnd, MAKELONG(lastHitTestVal, win32ncmsg));
|
|---|
| 952 |
|
|---|
| 953 | //WM_NC*BUTTON* is posted when the cursor is in a non-client area of the window
|
|---|
| 954 | if(lastHitTestVal != HTCLIENT) {
|
|---|
| 955 | SendInternalMessageA(win32ncmsg, lastHitTestVal, MAKELONG(ncx, ncy)); //TODO:
|
|---|
| 956 | }
|
|---|
| 957 | return SendInternalMessageA(win32msg, 0, MAKELONG(clx, cly));
|
|---|
| 958 | }
|
|---|
| 959 | //******************************************************************************
|
|---|
| 960 | //******************************************************************************
|
|---|
| 961 | ULONG Win32BaseWindow::MsgMouseMove(ULONG keystate, ULONG x, ULONG y)
|
|---|
| 962 | {
|
|---|
| 963 | ULONG winstate = 0;
|
|---|
| 964 | ULONG setcursormsg = WM_MOUSEMOVE;
|
|---|
| 965 |
|
|---|
| 966 | if(keystate & WMMOVE_LBUTTON)
|
|---|
| 967 | winstate |= MK_LBUTTON;
|
|---|
| 968 | if(keystate & WMMOVE_RBUTTON)
|
|---|
| 969 | winstate |= MK_RBUTTON;
|
|---|
| 970 | if(keystate & WMMOVE_MBUTTON)
|
|---|
| 971 | winstate |= MK_MBUTTON;
|
|---|
| 972 | if(keystate & WMMOVE_SHIFT)
|
|---|
| 973 | winstate |= MK_SHIFT;
|
|---|
| 974 | if(keystate & WMMOVE_CTRL)
|
|---|
| 975 | winstate |= MK_CONTROL;
|
|---|
| 976 |
|
|---|
| 977 | if(lastHitTestVal != HTCLIENT) {
|
|---|
| 978 | setcursormsg = WM_NCMOUSEMOVE;
|
|---|
| 979 | }
|
|---|
| 980 | //TODO: hiword should be 0 if window enters menu mode (SDK docs)
|
|---|
| 981 | SendInternalMessageA(WM_SETCURSOR, Win32Hwnd, MAKELONG(lastHitTestVal, setcursormsg));
|
|---|
| 982 |
|
|---|
| 983 | //WM_NCMOUSEMOVE is posted when the cursor moves into a non-client area of the window
|
|---|
| 984 | if(lastHitTestVal != HTCLIENT) {
|
|---|
| 985 | SendInternalMessageA(WM_NCMOUSEMOVE, lastHitTestVal, MAKELONG(x, y));
|
|---|
| 986 | }
|
|---|
| 987 | return SendInternalMessageA(WM_MOUSEMOVE, keystate, MAKELONG(x, y));
|
|---|
| 988 | }
|
|---|
| 989 | //******************************************************************************
|
|---|
| 990 | //******************************************************************************
|
|---|
| 991 | ULONG Win32BaseWindow::MsgPaint(ULONG tmp1, ULONG tmp2)
|
|---|
| 992 | {
|
|---|
| 993 | return SendInternalMessageA(WM_PAINT, 0, 0);
|
|---|
| 994 | }
|
|---|
| 995 | //******************************************************************************
|
|---|
| 996 | //TODO: Is the clipper region of the window DC equal to the invalidated rectangle?
|
|---|
| 997 | // (or are we simply erasing too much here)
|
|---|
| 998 | //******************************************************************************
|
|---|
| 999 | ULONG Win32BaseWindow::MsgEraseBackGround(HDC hdc)
|
|---|
| 1000 | {
|
|---|
| 1001 | ULONG rc;
|
|---|
| 1002 | HDC hdcErase = hdc;
|
|---|
| 1003 |
|
|---|
| 1004 | if (hdcErase == 0)
|
|---|
| 1005 | hdcErase = O32_GetDC(OS2Hwnd);
|
|---|
| 1006 |
|
|---|
| 1007 | if(isIcon)
|
|---|
| 1008 | rc = SendInternalMessageA(WM_ICONERASEBKGND, hdcErase, 0);
|
|---|
| 1009 | else
|
|---|
| 1010 | rc = SendInternalMessageA(WM_ERASEBKGND, hdcErase, 0);
|
|---|
| 1011 | if (hdc == 0)
|
|---|
| 1012 | O32_ReleaseDC(OS2Hwnd, hdcErase);
|
|---|
| 1013 | return (rc);
|
|---|
| 1014 | }
|
|---|
| 1015 | //******************************************************************************
|
|---|
| 1016 | //******************************************************************************
|
|---|
| 1017 | ULONG Win32BaseWindow::MsgSetText(LPSTR lpsz, LONG cch)
|
|---|
| 1018 | {
|
|---|
| 1019 | if(isUnicode) {
|
|---|
| 1020 | return SendInternalMessageW(WM_SETTEXT, 0, (LPARAM)lpsz);
|
|---|
| 1021 | }
|
|---|
| 1022 | else return SendInternalMessageA(WM_SETTEXT, 0, (LPARAM)lpsz);
|
|---|
| 1023 | }
|
|---|
| 1024 | //******************************************************************************
|
|---|
| 1025 | //TODO: in- or excluding terminating 0?
|
|---|
| 1026 | //******************************************************************************
|
|---|
| 1027 | ULONG Win32BaseWindow::MsgGetTextLength()
|
|---|
| 1028 | {
|
|---|
| 1029 | return SendInternalMessageA(WM_GETTEXTLENGTH, 0, 0);
|
|---|
| 1030 | }
|
|---|
| 1031 | //******************************************************************************
|
|---|
| 1032 | //******************************************************************************
|
|---|
| 1033 | char *Win32BaseWindow::MsgGetText()
|
|---|
| 1034 | {
|
|---|
| 1035 | if(isUnicode) {
|
|---|
| 1036 | SendInternalMessageW(WM_GETTEXT, wndNameLength, (LPARAM)windowNameW);
|
|---|
| 1037 | }
|
|---|
| 1038 | else {
|
|---|
| 1039 | SendInternalMessageA(WM_GETTEXT, wndNameLength, (LPARAM)windowNameA);
|
|---|
| 1040 | }
|
|---|
| 1041 | return windowNameA;
|
|---|
| 1042 | }
|
|---|
| 1043 | //******************************************************************************
|
|---|
| 1044 | //******************************************************************************
|
|---|
| 1045 | LRESULT Win32BaseWindow::DefWindowProcA(UINT Msg, WPARAM wParam, LPARAM lParam)
|
|---|
| 1046 | {
|
|---|
| 1047 | switch(Msg)
|
|---|
| 1048 | {
|
|---|
| 1049 | case WM_GETTEXTLENGTH:
|
|---|
| 1050 | return wndNameLength;
|
|---|
| 1051 |
|
|---|
| 1052 | case WM_GETTEXT: //TODO: SS_ICON controls
|
|---|
| 1053 | strncpy((LPSTR)lParam, windowNameA, wParam);
|
|---|
| 1054 | return min(wndNameLength, wParam);
|
|---|
| 1055 |
|
|---|
| 1056 | case WM_SETTEXT:
|
|---|
| 1057 | return 0;
|
|---|
| 1058 |
|
|---|
| 1059 | case WM_SETREDRAW:
|
|---|
| 1060 | if(wParam)
|
|---|
| 1061 | SetWindowLongA (GWL_STYLE, GetWindowLongA (GWL_STYLE) | WS_VISIBLE);
|
|---|
| 1062 | else SetWindowLongA (GWL_STYLE, GetWindowLongA (GWL_STYLE) & ~WS_VISIBLE);
|
|---|
| 1063 |
|
|---|
| 1064 | return 0; //TODO
|
|---|
| 1065 |
|
|---|
| 1066 | case WM_NCCREATE:
|
|---|
| 1067 | return(TRUE);
|
|---|
| 1068 |
|
|---|
| 1069 | case WM_CTLCOLORMSGBOX:
|
|---|
| 1070 | case WM_CTLCOLOREDIT:
|
|---|
| 1071 | case WM_CTLCOLORLISTBOX:
|
|---|
| 1072 | case WM_CTLCOLORBTN:
|
|---|
| 1073 | case WM_CTLCOLORDLG:
|
|---|
| 1074 | case WM_CTLCOLORSTATIC:
|
|---|
| 1075 | case WM_CTLCOLORSCROLLBAR:
|
|---|
| 1076 | SetBkColor((HDC)wParam, GetSysColor(COLOR_WINDOW));
|
|---|
| 1077 | SetTextColor((HDC)wParam, GetSysColor(COLOR_WINDOWTEXT));
|
|---|
| 1078 | return GetSysColorBrush(COLOR_BTNFACE);
|
|---|
| 1079 |
|
|---|
| 1080 | case WM_PARENTNOTIFY:
|
|---|
| 1081 | return 0;
|
|---|
| 1082 |
|
|---|
| 1083 | case WM_MOUSEACTIVATE:
|
|---|
| 1084 | {
|
|---|
| 1085 | DWORD dwStyle = GetWindowLongA(GWL_STYLE);
|
|---|
| 1086 | DWORD dwExStyle = GetWindowLongA(GWL_EXSTYLE);
|
|---|
| 1087 | dprintf(("DefWndProc: WM_MOUSEACTIVATE for %x Msg %s", Win32Hwnd, GetMsgText(HIWORD(lParam))));
|
|---|
| 1088 | if(dwStyle & WS_CHILD && !(dwExStyle & WS_EX_NOPARENTNOTIFY) )
|
|---|
| 1089 | {
|
|---|
| 1090 | if(getParent()) {
|
|---|
| 1091 | LRESULT rc = getParent()->SendMessageA(WM_MOUSEACTIVATE, wParam, lParam );
|
|---|
| 1092 | if(rc) return rc;
|
|---|
| 1093 | }
|
|---|
| 1094 | }
|
|---|
| 1095 | return (LOWORD(lParam) == HTCAPTION) ? MA_NOACTIVATE : MA_ACTIVATE;
|
|---|
| 1096 | }
|
|---|
| 1097 | case WM_SETCURSOR:
|
|---|
| 1098 | {
|
|---|
| 1099 | DWORD dwStyle = GetWindowLongA(GWL_STYLE);
|
|---|
| 1100 | DWORD dwExStyle = GetWindowLongA(GWL_EXSTYLE);
|
|---|
| 1101 | dprintf(("DefWndProc: WM_SETCURSOR for %x Msg %s", Win32Hwnd, GetMsgText(HIWORD(lParam))));
|
|---|
| 1102 | if(dwStyle & WS_CHILD && !(dwExStyle & WS_EX_NOPARENTNOTIFY) )
|
|---|
| 1103 | {
|
|---|
| 1104 | if(getParent()) {
|
|---|
| 1105 | LRESULT rc = getParent()->SendMessageA(WM_SETCURSOR, wParam, lParam);
|
|---|
| 1106 | if(rc) return rc;
|
|---|
| 1107 | }
|
|---|
| 1108 | }
|
|---|
| 1109 | return 1;
|
|---|
| 1110 | }
|
|---|
| 1111 | case WM_MOUSEMOVE:
|
|---|
| 1112 | return 0;
|
|---|
| 1113 |
|
|---|
| 1114 | case WM_WINDOWPOSCHANGED:
|
|---|
| 1115 | {
|
|---|
| 1116 |
|
|---|
| 1117 | /* undocumented SWP flags - from SDK 3.1 */
|
|---|
| 1118 | #define SWP_NOCLIENTSIZE 0x0800
|
|---|
| 1119 | #define SWP_NOCLIENTMOVE 0x1000
|
|---|
| 1120 |
|
|---|
| 1121 | PWINDOWPOS wpos = (PWINDOWPOS)lParam;
|
|---|
| 1122 | WPARAM wp = SIZE_RESTORED;
|
|---|
| 1123 |
|
|---|
| 1124 | if (!(wpos->flags & SWP_NOCLIENTMOVE))
|
|---|
| 1125 | SendMessageA(WM_MOVE, 0, MAKELONG(rectClient.left, rectClient.top));
|
|---|
| 1126 |
|
|---|
| 1127 | if (!(wpos->flags & SWP_NOCLIENTSIZE))
|
|---|
| 1128 | {
|
|---|
| 1129 | if (dwStyle & WS_MAXIMIZE) wp = SIZE_MAXIMIZED;
|
|---|
| 1130 | else if (dwStyle & WS_MINIMIZE) wp = SIZE_MINIMIZED;
|
|---|
| 1131 |
|
|---|
| 1132 | SendMessageA(WM_SIZE, wp, MAKELONG(rectClient.right - rectClient.left,
|
|---|
| 1133 | rectClient.bottom - rectClient.top));
|
|---|
| 1134 | }
|
|---|
| 1135 | return 0;
|
|---|
| 1136 | }
|
|---|
| 1137 | case WM_ERASEBKGND:
|
|---|
| 1138 | case WM_ICONERASEBKGND:
|
|---|
| 1139 | {
|
|---|
| 1140 | RECT rect;
|
|---|
| 1141 | int rc;
|
|---|
| 1142 |
|
|---|
| 1143 | if (!windowClass->getBackgroundBrush()) return 0;
|
|---|
| 1144 |
|
|---|
| 1145 | /* Since WM_ERASEBKGND may receive either a window dc or a */
|
|---|
| 1146 | /* client dc, the area to be erased has to be retrieved from */
|
|---|
| 1147 | /* the device context. */
|
|---|
| 1148 | rc = GetClipBox( (HDC)wParam, &rect );
|
|---|
| 1149 | if ((rc == SIMPLEREGION) || (rc == COMPLEXREGION))
|
|---|
| 1150 | FillRect( (HDC)wParam, &rect, windowClass->getBackgroundBrush());
|
|---|
| 1151 |
|
|---|
| 1152 | return 1;
|
|---|
| 1153 | }
|
|---|
| 1154 |
|
|---|
| 1155 | case WM_NCLBUTTONDOWN:
|
|---|
| 1156 | case WM_NCLBUTTONUP:
|
|---|
| 1157 | case WM_NCLBUTTONDBLCLK:
|
|---|
| 1158 | case WM_NCRBUTTONUP:
|
|---|
| 1159 | case WM_NCRBUTTONDOWN:
|
|---|
| 1160 | case WM_NCRBUTTONDBLCLK:
|
|---|
| 1161 | case WM_NCMBUTTONDOWN:
|
|---|
| 1162 | case WM_NCMBUTTONUP:
|
|---|
| 1163 | case WM_NCMBUTTONDBLCLK:
|
|---|
| 1164 | return 0; //TODO: Send WM_SYSCOMMAND if required
|
|---|
| 1165 |
|
|---|
| 1166 | case WM_NCHITTEST: //TODO: Calculate position of
|
|---|
| 1167 | return HTCLIENT;
|
|---|
| 1168 |
|
|---|
| 1169 | default:
|
|---|
| 1170 | return 1;
|
|---|
| 1171 | }
|
|---|
| 1172 | }
|
|---|
| 1173 | //******************************************************************************
|
|---|
| 1174 | //******************************************************************************
|
|---|
| 1175 | LRESULT Win32BaseWindow::DefWindowProcW(UINT Msg, WPARAM wParam, LPARAM lParam)
|
|---|
| 1176 | {
|
|---|
| 1177 | switch(Msg)
|
|---|
| 1178 | {
|
|---|
| 1179 | case WM_GETTEXTLENGTH:
|
|---|
| 1180 | return wndNameLength;
|
|---|
| 1181 |
|
|---|
| 1182 | case WM_GETTEXT: //TODO: SS_ICON controls
|
|---|
| 1183 | lstrcpynW((LPWSTR)lParam, windowNameW, wParam);
|
|---|
| 1184 | return min(wndNameLength, wParam);
|
|---|
| 1185 |
|
|---|
| 1186 | default:
|
|---|
| 1187 | return DefWindowProcA(Msg, wParam, lParam);
|
|---|
| 1188 | }
|
|---|
| 1189 | }
|
|---|
| 1190 | //******************************************************************************
|
|---|
| 1191 | //******************************************************************************
|
|---|
| 1192 | LRESULT Win32BaseWindow::SendMessageA(ULONG Msg, WPARAM wParam, LPARAM lParam)
|
|---|
| 1193 | {
|
|---|
| 1194 | if(PostSpyMessage(getWindowHandle(), Msg, wParam, lParam) == FALSE)
|
|---|
| 1195 | dprintf(("SendMessageA %s for %x %x %x", GetMsgText(Msg), getWindowHandle(), wParam, lParam));
|
|---|
| 1196 |
|
|---|
| 1197 | if(HkCBT::OS2HkCBTProc(getWindowHandle(), Msg, wParam, lParam) == TRUE) {//hook swallowed msg
|
|---|
| 1198 | return(0);
|
|---|
| 1199 | }
|
|---|
| 1200 | switch(Msg)
|
|---|
| 1201 | {
|
|---|
| 1202 | case WM_CREATE:
|
|---|
| 1203 | {
|
|---|
| 1204 | if(win32wndproc(getWindowHandle(), WM_NCCREATE, 0, lParam) == 0) {
|
|---|
| 1205 | dprintf(("WM_NCCREATE returned FALSE\n"));
|
|---|
| 1206 | return(-1); //don't create window
|
|---|
| 1207 | }
|
|---|
| 1208 | if(win32wndproc(getWindowHandle(), WM_CREATE, 0, lParam) == -1) {
|
|---|
| 1209 | dprintf(("WM_CREATE returned -1\n"));
|
|---|
| 1210 | return(-1); //don't create window
|
|---|
| 1211 | }
|
|---|
| 1212 | NotifyParent(Msg, wParam, lParam);
|
|---|
| 1213 |
|
|---|
| 1214 | return(0);
|
|---|
| 1215 | }
|
|---|
| 1216 | case WM_SETTEXT: //TODO: Nothing happens if passed to DefWindowProc
|
|---|
| 1217 | return win32wndproc(getWindowHandle(), WM_SETTEXT, wParam, lParam);
|
|---|
| 1218 |
|
|---|
| 1219 | case WM_LBUTTONDOWN:
|
|---|
| 1220 | case WM_MBUTTONDOWN:
|
|---|
| 1221 | case WM_RBUTTONDOWN:
|
|---|
| 1222 | NotifyParent(Msg, wParam, lParam);
|
|---|
| 1223 | return win32wndproc(getWindowHandle(), Msg, wParam, lParam);
|
|---|
| 1224 |
|
|---|
| 1225 | case WM_DESTROY:
|
|---|
| 1226 | win32wndproc(getWindowHandle(), WM_NCDESTROY, 0, 0);
|
|---|
| 1227 | NotifyParent(Msg, wParam, lParam);
|
|---|
| 1228 | return win32wndproc(getWindowHandle(), WM_DESTROY, 0, 0);
|
|---|
| 1229 | default:
|
|---|
| 1230 | return win32wndproc(getWindowHandle(), Msg, wParam, lParam);
|
|---|
| 1231 | }
|
|---|
| 1232 | }
|
|---|
| 1233 | //******************************************************************************
|
|---|
| 1234 | //******************************************************************************
|
|---|
| 1235 | LRESULT Win32BaseWindow::SendMessageW(ULONG Msg, WPARAM wParam, LPARAM lParam)
|
|---|
| 1236 | {
|
|---|
| 1237 | if(PostSpyMessage(getWindowHandle(), Msg, wParam, lParam) == FALSE)
|
|---|
| 1238 | dprintf(("SendMessageA %s for %x %x %x", GetMsgText(Msg), getWindowHandle(), wParam, lParam));
|
|---|
| 1239 |
|
|---|
| 1240 | if(HkCBT::OS2HkCBTProc(getWindowHandle(), Msg, wParam, lParam) == TRUE) {//hook swallowed msg
|
|---|
| 1241 | return(0);
|
|---|
| 1242 | }
|
|---|
| 1243 | switch(Msg)
|
|---|
| 1244 | {
|
|---|
| 1245 | case WM_CREATE:
|
|---|
| 1246 | {
|
|---|
| 1247 | if(win32wndproc(getWindowHandle(), WM_NCCREATE, 0, lParam) == 0) {
|
|---|
| 1248 | dprintf(("WM_NCCREATE returned FALSE\n"));
|
|---|
| 1249 | return(0); //don't create window
|
|---|
| 1250 | }
|
|---|
| 1251 | if(win32wndproc(getWindowHandle(), WM_CREATE, 0, lParam) == 0) {
|
|---|
| 1252 | dprintf(("WM_CREATE returned FALSE\n"));
|
|---|
| 1253 | return(0); //don't create window
|
|---|
| 1254 | }
|
|---|
| 1255 | NotifyParent(Msg, wParam, lParam);
|
|---|
| 1256 |
|
|---|
| 1257 | return(1);
|
|---|
| 1258 | }
|
|---|
| 1259 | case WM_SETTEXT: //TODO: Nothing happens if passed to DefWindowProc
|
|---|
| 1260 | return win32wndproc(getWindowHandle(), WM_SETTEXT, wParam, lParam);
|
|---|
| 1261 |
|
|---|
| 1262 | case WM_LBUTTONDOWN:
|
|---|
| 1263 | case WM_MBUTTONDOWN:
|
|---|
| 1264 | case WM_RBUTTONDOWN:
|
|---|
| 1265 | NotifyParent(Msg, wParam, lParam);
|
|---|
| 1266 | return win32wndproc(getWindowHandle(), Msg, wParam, lParam);
|
|---|
| 1267 |
|
|---|
| 1268 | case WM_DESTROY:
|
|---|
| 1269 | win32wndproc(getWindowHandle(), WM_NCDESTROY, 0, 0);
|
|---|
| 1270 | NotifyParent(Msg, wParam, lParam);
|
|---|
| 1271 | return win32wndproc(getWindowHandle(), WM_DESTROY, 0, 0);
|
|---|
| 1272 |
|
|---|
| 1273 | default:
|
|---|
| 1274 | return win32wndproc(getWindowHandle(), Msg, wParam, lParam);
|
|---|
| 1275 | }
|
|---|
| 1276 | }
|
|---|
| 1277 | //******************************************************************************
|
|---|
| 1278 | //Called as a result of an OS/2 message
|
|---|
| 1279 | //******************************************************************************
|
|---|
| 1280 | LRESULT Win32BaseWindow::SendInternalMessageA(ULONG Msg, WPARAM wParam, LPARAM lParam)
|
|---|
| 1281 | {
|
|---|
| 1282 | if(PostSpyMessage(getWindowHandle(), Msg, wParam, lParam) == FALSE)
|
|---|
| 1283 | dprintf(("SendInternalMessageA %s for %x %x %x", GetMsgText(Msg), getWindowHandle(), wParam, lParam));
|
|---|
| 1284 |
|
|---|
| 1285 | if(HkCBT::OS2HkCBTProc(getWindowHandle(), Msg, wParam, lParam) == TRUE) {//hook swallowed msg
|
|---|
| 1286 | return(0);
|
|---|
| 1287 | }
|
|---|
| 1288 | switch(Msg)
|
|---|
| 1289 | {
|
|---|
| 1290 | case WM_CREATE:
|
|---|
| 1291 | {
|
|---|
| 1292 | if(win32wndproc(getWindowHandle(), WM_NCCREATE, 0, lParam) == 0) {
|
|---|
| 1293 | dprintf(("WM_NCCREATE returned FALSE\n"));
|
|---|
| 1294 | return(0); //don't create window
|
|---|
| 1295 | }
|
|---|
| 1296 | if(win32wndproc(getWindowHandle(), WM_CREATE, 0, lParam) == 0) {
|
|---|
| 1297 | dprintf(("WM_CREATE returned FALSE\n"));
|
|---|
| 1298 | return(0); //don't create window
|
|---|
| 1299 | }
|
|---|
| 1300 | NotifyParent(Msg, wParam, lParam);
|
|---|
| 1301 |
|
|---|
| 1302 | return(1);
|
|---|
| 1303 | }
|
|---|
| 1304 | case WM_LBUTTONDOWN:
|
|---|
| 1305 | case WM_MBUTTONDOWN:
|
|---|
| 1306 | case WM_RBUTTONDOWN:
|
|---|
| 1307 | NotifyParent(Msg, wParam, lParam);
|
|---|
| 1308 | return win32wndproc(getWindowHandle(), Msg, wParam, lParam);
|
|---|
| 1309 |
|
|---|
| 1310 | case WM_DESTROY:
|
|---|
| 1311 | win32wndproc(getWindowHandle(), WM_NCDESTROY, 0, 0);
|
|---|
| 1312 | NotifyParent(Msg, wParam, lParam);
|
|---|
| 1313 | return win32wndproc(getWindowHandle(), WM_DESTROY, 0, 0);
|
|---|
| 1314 | default:
|
|---|
| 1315 | return win32wndproc(getWindowHandle(), Msg, wParam, lParam);
|
|---|
| 1316 | }
|
|---|
| 1317 | }
|
|---|
| 1318 | //******************************************************************************
|
|---|
| 1319 | //Called as a result of an OS/2 message
|
|---|
| 1320 | //todo, unicode msgs (WM_SETTEXT etc)
|
|---|
| 1321 | //******************************************************************************
|
|---|
| 1322 | LRESULT Win32BaseWindow::SendInternalMessageW(ULONG Msg, WPARAM wParam, LPARAM lParam)
|
|---|
| 1323 | {
|
|---|
| 1324 | if(PostSpyMessage(getWindowHandle(), Msg, wParam, lParam) == FALSE)
|
|---|
| 1325 | dprintf(("SendInternalMessageW %s for %x %x %x", GetMsgText(Msg), getWindowHandle(), wParam, lParam));
|
|---|
| 1326 |
|
|---|
| 1327 | if(HkCBT::OS2HkCBTProc(getWindowHandle(), Msg, wParam, lParam) == TRUE) {//hook swallowed msg
|
|---|
| 1328 | return(0);
|
|---|
| 1329 | }
|
|---|
| 1330 | switch(Msg)
|
|---|
| 1331 | {
|
|---|
| 1332 | case WM_CREATE:
|
|---|
| 1333 | {
|
|---|
| 1334 | if(win32wndproc(getWindowHandle(), WM_NCCREATE, 0, lParam) == 0) {
|
|---|
| 1335 | dprintf(("WM_NCCREATE returned FALSE\n"));
|
|---|
| 1336 | return(0); //don't create window
|
|---|
| 1337 | }
|
|---|
| 1338 | if(win32wndproc(getWindowHandle(), WM_CREATE, 0, lParam) == 0) {
|
|---|
| 1339 | dprintf(("WM_CREATE returned FALSE\n"));
|
|---|
| 1340 | return(0); //don't create window
|
|---|
| 1341 | }
|
|---|
| 1342 | NotifyParent(Msg, wParam, lParam);
|
|---|
| 1343 |
|
|---|
| 1344 | return(1);
|
|---|
| 1345 | }
|
|---|
| 1346 | case WM_LBUTTONDOWN:
|
|---|
| 1347 | case WM_MBUTTONDOWN:
|
|---|
| 1348 | case WM_RBUTTONDOWN:
|
|---|
| 1349 | NotifyParent(Msg, wParam, lParam);
|
|---|
| 1350 | return win32wndproc(getWindowHandle(), Msg, wParam, lParam);
|
|---|
| 1351 |
|
|---|
| 1352 | case WM_DESTROY:
|
|---|
| 1353 | win32wndproc(getWindowHandle(), WM_NCDESTROY, 0, 0);
|
|---|
| 1354 | NotifyParent(Msg, wParam, lParam);
|
|---|
| 1355 | return win32wndproc(getWindowHandle(), WM_DESTROY, 0, 0);
|
|---|
| 1356 | default:
|
|---|
| 1357 | return win32wndproc(getWindowHandle(), Msg, wParam, lParam);
|
|---|
| 1358 | }
|
|---|
| 1359 | }
|
|---|
| 1360 | //******************************************************************************
|
|---|
| 1361 | //******************************************************************************
|
|---|
| 1362 | BOOL Win32BaseWindow::PostMessageA(ULONG msg, WPARAM wParam, LPARAM lParam)
|
|---|
| 1363 | {
|
|---|
| 1364 | return OSLibPostMessage(OS2Hwnd, WIN32APP_USERMSGBASE+msg, wParam, lParam);
|
|---|
| 1365 | }
|
|---|
| 1366 | //******************************************************************************
|
|---|
| 1367 | //******************************************************************************
|
|---|
| 1368 | BOOL Win32BaseWindow::PostMessageW(ULONG msg, WPARAM wParam, LPARAM lParam)
|
|---|
| 1369 | {
|
|---|
| 1370 | return OSLibPostMessage(OS2Hwnd, WIN32APP_USERMSGBASE+msg, wParam, lParam);
|
|---|
| 1371 | }
|
|---|
| 1372 | //******************************************************************************
|
|---|
| 1373 | //TODO: do we need to inform the parent of the parent (etc) of the child window?
|
|---|
| 1374 | //******************************************************************************
|
|---|
| 1375 | void Win32BaseWindow::NotifyParent(UINT Msg, WPARAM wParam, LPARAM lParam)
|
|---|
| 1376 | {
|
|---|
| 1377 | Win32BaseWindow *window = this;
|
|---|
| 1378 | Win32BaseWindow *parentwindow;
|
|---|
| 1379 |
|
|---|
| 1380 | while(window)
|
|---|
| 1381 | {
|
|---|
| 1382 | if(window->getStyle() & WS_CHILD && !(window->getExStyle() & WS_EX_NOPARENTNOTIFY) )
|
|---|
| 1383 | {
|
|---|
| 1384 | /* Notify the parent window only */
|
|---|
| 1385 | parentwindow = window->getParent();
|
|---|
| 1386 | if(parentwindow) {
|
|---|
| 1387 | if(Msg == WM_CREATE || Msg == WM_DESTROY) {
|
|---|
| 1388 | parentwindow->SendInternalMessageA(WM_PARENTNOTIFY, MAKEWPARAM(Msg, window->getWindowId()), (LPARAM)window->getWindowHandle());
|
|---|
| 1389 | }
|
|---|
| 1390 | else parentwindow->SendInternalMessageA(WM_PARENTNOTIFY, MAKEWPARAM(Msg, window->getWindowId()), lParam );
|
|---|
| 1391 | }
|
|---|
| 1392 | }
|
|---|
| 1393 | else break;
|
|---|
| 1394 |
|
|---|
| 1395 | window = parentwindow;
|
|---|
| 1396 | }
|
|---|
| 1397 | }
|
|---|
| 1398 | //******************************************************************************
|
|---|
| 1399 | //******************************************************************************
|
|---|
| 1400 | BOOL Win32BaseWindow::SetMenu(HMENU hMenu)
|
|---|
| 1401 | {
|
|---|
| 1402 | PVOID menutemplate;
|
|---|
| 1403 | Win32Resource *winres = (Win32Resource *)hMenu;
|
|---|
| 1404 |
|
|---|
| 1405 | dprintf(("SetMenu %x", hMenu));
|
|---|
| 1406 | if(HIWORD(winres) == 0) {
|
|---|
| 1407 | dprintf(("Win32BaseWindow:: Win32Resource *winres == 0"));
|
|---|
| 1408 | SetLastError(ERROR_INVALID_PARAMETER);
|
|---|
| 1409 | return FALSE;
|
|---|
| 1410 | }
|
|---|
| 1411 | menutemplate = winres->lockOS2Resource();
|
|---|
| 1412 | if(menutemplate == NULL)
|
|---|
| 1413 | {
|
|---|
| 1414 | dprintf(("Win32BaseWindow::SetMenu menutemplate == 0"));
|
|---|
| 1415 | return FALSE;
|
|---|
| 1416 | }
|
|---|
| 1417 | OS2HwndMenu = OSLibWinCreateMenu(OS2HwndFrame, menutemplate);
|
|---|
| 1418 | if(OS2HwndMenu == 0) {
|
|---|
| 1419 | dprintf(("Win32BaseWindow::SetMenu OS2HwndMenu == 0"));
|
|---|
| 1420 | return FALSE;
|
|---|
| 1421 | }
|
|---|
| 1422 | winres->setOS2Handle(OS2HwndMenu);
|
|---|
| 1423 | menuResource = winres;
|
|---|
| 1424 | return TRUE;
|
|---|
| 1425 | }
|
|---|
| 1426 | //******************************************************************************
|
|---|
| 1427 | //******************************************************************************
|
|---|
| 1428 | BOOL Win32BaseWindow::SetAccelTable(HACCEL hAccel)
|
|---|
| 1429 | {
|
|---|
| 1430 | Win32Resource *winres = (Win32Resource *)hAccel;
|
|---|
| 1431 | HANDLE accelhandle;
|
|---|
| 1432 |
|
|---|
| 1433 | if(HIWORD(hAccel) == 0) {
|
|---|
| 1434 | dprintf(("SetAccelTable: hAccel %x invalid", hAccel));
|
|---|
| 1435 | SetLastError(ERROR_INVALID_PARAMETER);
|
|---|
| 1436 | return FALSE;
|
|---|
| 1437 | }
|
|---|
| 1438 | acceltableResource = winres;
|
|---|
| 1439 | accelhandle = OSLibWinSetAccelTable(OS2HwndFrame, winres->getOS2Handle(), winres->lockOS2Resource());
|
|---|
| 1440 | winres->setOS2Handle(accelhandle);
|
|---|
| 1441 | return(accelhandle != 0);
|
|---|
| 1442 | }
|
|---|
| 1443 | //******************************************************************************
|
|---|
| 1444 | //******************************************************************************
|
|---|
| 1445 | BOOL Win32BaseWindow::SetIcon(HICON hIcon)
|
|---|
| 1446 | {
|
|---|
| 1447 | dprintf(("Win32BaseWindow::SetIcon %x", hIcon));
|
|---|
| 1448 | return OSLibWinSetIcon(OS2HwndFrame, hIcon);
|
|---|
| 1449 | }
|
|---|
| 1450 | //******************************************************************************
|
|---|
| 1451 | //******************************************************************************
|
|---|
| 1452 | BOOL Win32BaseWindow::ShowWindow(ULONG nCmdShow)
|
|---|
| 1453 | {
|
|---|
| 1454 | ULONG showstate = 0;
|
|---|
| 1455 |
|
|---|
| 1456 | dprintf(("ShowWindow %x", nCmdShow));
|
|---|
| 1457 | if(fFirstShow) {
|
|---|
| 1458 | if(isFrameWindow() && IS_OVERLAPPED(getStyle())) {
|
|---|
| 1459 | SendMessageA(WM_SIZE, SIZE_RESTORED,
|
|---|
| 1460 | MAKELONG(rectClient.right-rectClient.left,
|
|---|
| 1461 | rectClient.bottom-rectClient.top));
|
|---|
| 1462 | SendMessageA(WM_MOVE, 0, MAKELONG( rectClient.left, rectClient.top ) );
|
|---|
| 1463 |
|
|---|
| 1464 | }
|
|---|
| 1465 | fFirstShow = FALSE;
|
|---|
| 1466 | }
|
|---|
| 1467 | switch(nCmdShow)
|
|---|
| 1468 | {
|
|---|
| 1469 | case SW_SHOW:
|
|---|
| 1470 | case SW_SHOWDEFAULT: //todo
|
|---|
| 1471 | showstate = SWPOS_SHOW | SWPOS_ACTIVATE;
|
|---|
| 1472 | break;
|
|---|
| 1473 | case SW_HIDE:
|
|---|
| 1474 | showstate = SWPOS_HIDE;
|
|---|
| 1475 | break;
|
|---|
| 1476 | case SW_RESTORE:
|
|---|
| 1477 | showstate = SWPOS_RESTORE | SWPOS_SHOW | SWPOS_ACTIVATE;
|
|---|
| 1478 | break;
|
|---|
| 1479 | case SW_MINIMIZE:
|
|---|
| 1480 | showstate = SWPOS_MINIMIZE;
|
|---|
| 1481 | break;
|
|---|
| 1482 | case SW_SHOWMAXIMIZED:
|
|---|
| 1483 | showstate = SWPOS_MAXIMIZE | SWPOS_SHOW | SWPOS_ACTIVATE;
|
|---|
| 1484 | break;
|
|---|
| 1485 | case SW_SHOWMINIMIZED:
|
|---|
| 1486 | showstate = SWPOS_MINIMIZE | SWPOS_SHOW | SWPOS_ACTIVATE;
|
|---|
| 1487 | break;
|
|---|
| 1488 | case SW_SHOWMINNOACTIVE:
|
|---|
| 1489 | showstate = SWPOS_MINIMIZE | SWPOS_SHOW;
|
|---|
| 1490 | break;
|
|---|
| 1491 | case SW_SHOWNA:
|
|---|
| 1492 | showstate = SWPOS_SHOW;
|
|---|
| 1493 | break;
|
|---|
| 1494 | case SW_SHOWNOACTIVATE:
|
|---|
| 1495 | showstate = SWPOS_SHOW;
|
|---|
| 1496 | break;
|
|---|
| 1497 | case SW_SHOWNORMAL:
|
|---|
| 1498 | showstate = SWPOS_RESTORE | SWPOS_ACTIVATE | SWPOS_SHOW;
|
|---|
| 1499 | break;
|
|---|
| 1500 | }
|
|---|
| 1501 | return OSLibWinShowWindow(OS2HwndFrame, showstate);
|
|---|
| 1502 | }
|
|---|
| 1503 | //******************************************************************************
|
|---|
| 1504 | //******************************************************************************
|
|---|
| 1505 | BOOL Win32BaseWindow::SetWindowPos(HWND hwndInsertAfter, int x, int y, int cx, int cy, UINT fuFlags)
|
|---|
| 1506 | {
|
|---|
| 1507 | BOOL rc = FALSE;
|
|---|
| 1508 | Win32BaseWindow *window;
|
|---|
| 1509 | HWND hParent = 0;
|
|---|
| 1510 |
|
|---|
| 1511 | dprintf (("SetWindowPos %x %x (%d,%d)(%d,%d) %x", Win32Hwnd, hwndInsertAfter, x, y, cx, cy, fuFlags));
|
|---|
| 1512 |
|
|---|
| 1513 | /* Validate the flags passed in ... */
|
|---|
| 1514 | if ( fuFlags &
|
|---|
| 1515 | ~(SWP_NOSIZE | SWP_NOMOVE | SWP_NOZORDER |
|
|---|
| 1516 | SWP_NOREDRAW | SWP_NOACTIVATE | SWP_FRAMECHANGED |
|
|---|
| 1517 | SWP_SHOWWINDOW | SWP_HIDEWINDOW | SWP_NOCOPYBITS |
|
|---|
| 1518 | SWP_NOOWNERZORDER) )
|
|---|
| 1519 | {
|
|---|
| 1520 | return FALSE;
|
|---|
| 1521 | }
|
|---|
| 1522 |
|
|---|
| 1523 | WINDOWPOS wpos;
|
|---|
| 1524 | SWP swp, swpOld;
|
|---|
| 1525 |
|
|---|
| 1526 | //****************************
|
|---|
| 1527 | // Set up with Windows values.
|
|---|
| 1528 | //****************************
|
|---|
| 1529 | wpos.flags = fuFlags;
|
|---|
| 1530 | wpos.cy = cy;
|
|---|
| 1531 | wpos.cx = cx;
|
|---|
| 1532 | wpos.x = x;
|
|---|
| 1533 | wpos.y = y;
|
|---|
| 1534 | wpos.hwndInsertAfter = hwndInsertAfter;
|
|---|
| 1535 | wpos.hwnd = getWindowHandle();
|
|---|
| 1536 |
|
|---|
| 1537 | //**********************************************
|
|---|
| 1538 | // Convert from Windows to PM coords and flags.
|
|---|
| 1539 | //**********************************************
|
|---|
| 1540 | if(~fuFlags & (SWP_NOMOVE | SWP_NOSIZE)) {
|
|---|
| 1541 | if (isChild())
|
|---|
| 1542 | {
|
|---|
| 1543 | hParent = getParent()->getOS2WindowHandle();
|
|---|
| 1544 | OSLibWinQueryWindowPos(OS2Hwnd, &swpOld);
|
|---|
| 1545 | } else
|
|---|
| 1546 | OSLibWinQueryWindowPos(OS2HwndFrame, &swpOld);
|
|---|
| 1547 | }
|
|---|
| 1548 | OSLibMapWINDOWPOStoSWP(&wpos, &swp, &swpOld, hParent, OS2HwndFrame);
|
|---|
| 1549 |
|
|---|
| 1550 | /* MapSWP can clear the SWP_MOVE and SWP_SIZE flags if the window is not
|
|---|
| 1551 | * being moved or sized. If these were the only operations to be done
|
|---|
| 1552 | * and they have been cleared, return now.
|
|---|
| 1553 | */
|
|---|
| 1554 | if (swp.fl == 0)
|
|---|
| 1555 | return TRUE;
|
|---|
| 1556 |
|
|---|
| 1557 | //*********************************************************************
|
|---|
| 1558 | //On Windows, a WM_GETMINMAXINFO is made to the app from within this API.
|
|---|
| 1559 | //We'll send a WM_QUERYTRACKINFO which is translated into a WM_GETMINMAXINFO
|
|---|
| 1560 | //and passed on to the app. Compare the values returned with the SWP cx and
|
|---|
| 1561 | //cy values. They cannot be bigger than the max nor smaller than the min.
|
|---|
| 1562 | //*********************************************************************
|
|---|
| 1563 |
|
|---|
| 1564 | if ((swp.fl & SWPOS_ZORDER) && (swp.hwndInsertBehind > HWNDOS_BOTTOM))
|
|---|
| 1565 | {
|
|---|
| 1566 | Win32BaseWindow *wndBehind = Win32BaseWindow::GetWindowFromHandle(swp.hwndInsertBehind);
|
|---|
| 1567 | swp.hwndInsertBehind = wndBehind->getOS2WindowHandle();
|
|---|
| 1568 | }
|
|---|
| 1569 | if (isFrameWindow())
|
|---|
| 1570 | {
|
|---|
| 1571 | POINT maxSize, maxPos, minTrack, maxTrack;
|
|---|
| 1572 |
|
|---|
| 1573 | GetMinMaxInfo(&maxSize, &maxPos, &minTrack, &maxTrack);
|
|---|
| 1574 |
|
|---|
| 1575 | if (swp.cx > maxTrack.x) swp.cx = maxTrack.x;
|
|---|
| 1576 | if (swp.cy > maxTrack.y) swp.cy = maxTrack.y;
|
|---|
| 1577 | if (swp.cx < minTrack.x) swp.cx = minTrack.x;
|
|---|
| 1578 | if (swp.cy < minTrack.y) swp.cy = minTrack.y;
|
|---|
| 1579 | swp.hwnd = OS2HwndFrame;
|
|---|
| 1580 | } else
|
|---|
| 1581 | swp.hwnd = OS2Hwnd;
|
|---|
| 1582 | dprintf (("WinSetWindowPos %x %x (%d,%d)(%d,%d) %x", swp.hwnd, swp.hwndInsertBehind, swp.x, swp.y, swp.cx, swp.cy, swp.fl));
|
|---|
| 1583 |
|
|---|
| 1584 | //*****************************************************************************
|
|---|
| 1585 | // Squibble the window. (WinSetMultWindowPos is faster than WinSetWindowPos.)
|
|---|
| 1586 | //*****************************************************************************
|
|---|
| 1587 | rc = OSLibWinSetMultWindowPos(&swp, 1);
|
|---|
| 1588 |
|
|---|
| 1589 | if (rc == FALSE)
|
|---|
| 1590 | {
|
|---|
| 1591 | // SET_ERROR_LAST();
|
|---|
| 1592 | }
|
|---|
| 1593 | else
|
|---|
| 1594 | {
|
|---|
| 1595 | /* To implement support for SWP_FRAMECHANGED_W correctly, we would need
|
|---|
| 1596 | ** to send a WM_NCCALCSIZE message. This means DAX would have to support
|
|---|
| 1597 | ** the WM_NCCALCSIZE message. I don't think DAX can support this
|
|---|
| 1598 | ** message because it is tightly bound with the architecture of
|
|---|
| 1599 | ** overlapped windows (the "just one window" architecture). However,
|
|---|
| 1600 | ** we *can* support the SWP_FRAMECHANGED flag by sending the window
|
|---|
| 1601 | ** a WM_UPDATEFRAME, which will provide the behavior of WM_NCCALCSIZE.
|
|---|
| 1602 | */
|
|---|
| 1603 | // if (fuFlags & SWP_FRAMECHANGED_W)
|
|---|
| 1604 | // WinSendMsg(hWindow, WM_UPDATEFRAME, (MPARAM)-1, 0);
|
|---|
| 1605 | }
|
|---|
| 1606 |
|
|---|
| 1607 | return (rc);
|
|---|
| 1608 | }
|
|---|
| 1609 | //******************************************************************************
|
|---|
| 1610 | //Also destroys all the child windows (destroy parent, destroy children)
|
|---|
| 1611 | //******************************************************************************
|
|---|
| 1612 | BOOL Win32BaseWindow::DestroyWindow()
|
|---|
| 1613 | {
|
|---|
| 1614 | return OSLibWinDestroyWindow(OS2HwndFrame);
|
|---|
| 1615 | }
|
|---|
| 1616 | //******************************************************************************
|
|---|
| 1617 | //******************************************************************************
|
|---|
| 1618 | HWND Win32BaseWindow::GetParent()
|
|---|
| 1619 | {
|
|---|
| 1620 | if(getParent()) {
|
|---|
| 1621 | return getParent()->getWindowHandle();
|
|---|
| 1622 | }
|
|---|
| 1623 | else return 0;
|
|---|
| 1624 | }
|
|---|
| 1625 | //******************************************************************************
|
|---|
| 1626 | //******************************************************************************
|
|---|
| 1627 | HWND Win32BaseWindow::SetParent(HWND hwndNewParent)
|
|---|
| 1628 | {
|
|---|
| 1629 | HWND oldhwnd;
|
|---|
| 1630 | Win32BaseWindow *newparent;
|
|---|
| 1631 |
|
|---|
| 1632 | if(getParent()) {
|
|---|
| 1633 | oldhwnd = getParent()->getWindowHandle();
|
|---|
| 1634 | }
|
|---|
| 1635 | else oldhwnd = 0;
|
|---|
| 1636 |
|
|---|
| 1637 | if(hwndNewParent == 0) {//desktop window = parent
|
|---|
| 1638 | setParent(NULL);
|
|---|
| 1639 | OSLibWinSetParent(getOS2WindowHandle(), OSLIB_HWND_DESKTOP);
|
|---|
| 1640 | return oldhwnd;
|
|---|
| 1641 | }
|
|---|
| 1642 | newparent = GetWindowFromHandle(hwndNewParent);
|
|---|
| 1643 | if(newparent)
|
|---|
| 1644 | {
|
|---|
| 1645 | setParent(newparent);
|
|---|
| 1646 | OSLibWinSetParent(getOS2WindowHandle(), getParent()->getOS2WindowHandle());
|
|---|
| 1647 | return oldhwnd;
|
|---|
| 1648 | }
|
|---|
| 1649 | SetLastError(ERROR_INVALID_PARAMETER);
|
|---|
| 1650 | return 0;
|
|---|
| 1651 | }
|
|---|
| 1652 | //******************************************************************************
|
|---|
| 1653 | //******************************************************************************
|
|---|
| 1654 | BOOL Win32BaseWindow::IsChild(HWND hwndParent)
|
|---|
| 1655 | {
|
|---|
| 1656 | if(getParent()) {
|
|---|
| 1657 | return getParent()->getWindowHandle() == hwndParent;
|
|---|
| 1658 | }
|
|---|
| 1659 | else return 0;
|
|---|
| 1660 | }
|
|---|
| 1661 | //******************************************************************************
|
|---|
| 1662 | //******************************************************************************
|
|---|
| 1663 | HWND Win32BaseWindow::GetTopWindow()
|
|---|
| 1664 | {
|
|---|
| 1665 | return GetWindow(GW_CHILD);
|
|---|
| 1666 | }
|
|---|
| 1667 | //******************************************************************************
|
|---|
| 1668 | //Don't call WinUpdateWindow as that one also updates the child windows
|
|---|
| 1669 | //Also need to send WM_PAINT directly to the window procedure, which doesn't
|
|---|
| 1670 | //always happen with WinUpdateWindow (could be posted if thread doesn't own window)
|
|---|
| 1671 | //******************************************************************************
|
|---|
| 1672 | BOOL Win32BaseWindow::UpdateWindow()
|
|---|
| 1673 | {
|
|---|
| 1674 | RECT rect;
|
|---|
| 1675 |
|
|---|
| 1676 | if(OSLibWinQueryUpdateRect(OS2Hwnd, &rect))
|
|---|
| 1677 | {//update region not empty
|
|---|
| 1678 | HDC hdc;
|
|---|
| 1679 |
|
|---|
| 1680 | hdc = O32_GetDC(OS2Hwnd);
|
|---|
| 1681 | if (isIcon)
|
|---|
| 1682 | {
|
|---|
| 1683 | SendInternalMessageA(WM_ICONERASEBKGND, (WPARAM)hdc, 0);
|
|---|
| 1684 | SendInternalMessageA(WM_PAINTICON, 0, 0);
|
|---|
| 1685 | } else
|
|---|
| 1686 | {
|
|---|
| 1687 | SendInternalMessageA(WM_ERASEBKGND, (WPARAM)hdc, 0);
|
|---|
| 1688 | SendInternalMessageA(WM_PAINT, 0, 0);
|
|---|
| 1689 | }
|
|---|
| 1690 | O32_ReleaseDC(OS2Hwnd, hdc);
|
|---|
| 1691 | }
|
|---|
| 1692 | return TRUE;
|
|---|
| 1693 | }
|
|---|
| 1694 | //******************************************************************************
|
|---|
| 1695 | //******************************************************************************
|
|---|
| 1696 | BOOL Win32BaseWindow::IsIconic()
|
|---|
| 1697 | {
|
|---|
| 1698 | return OSLibWinIsIconic(OS2Hwnd);
|
|---|
| 1699 | }
|
|---|
| 1700 | //******************************************************************************
|
|---|
| 1701 | //TODO:
|
|---|
| 1702 | //We assume (for now) that if hwndParent or hwndChildAfter are real window handles, that
|
|---|
| 1703 | //the current process owns them.
|
|---|
| 1704 | //******************************************************************************
|
|---|
| 1705 | HWND Win32BaseWindow::FindWindowEx(HWND hwndParent, HWND hwndChildAfter, LPSTR lpszClass, LPSTR lpszWindow,
|
|---|
| 1706 | BOOL fUnicode)
|
|---|
| 1707 | {
|
|---|
| 1708 | Win32BaseWindow *parent = GetWindowFromHandle(hwndParent);
|
|---|
| 1709 | Win32BaseWindow *child = GetWindowFromHandle(hwndChildAfter);
|
|---|
| 1710 |
|
|---|
| 1711 | if((hwndParent != OSLIB_HWND_DESKTOP && !parent) ||
|
|---|
| 1712 | (hwndChildAfter != 0 && !child) ||
|
|---|
| 1713 | (hwndParent == OSLIB_HWND_DESKTOP && hwndChildAfter != 0))
|
|---|
| 1714 | {
|
|---|
| 1715 | dprintf(("Win32BaseWindow::FindWindowEx: parent or child not found %x %x", hwndParent, hwndChildAfter));
|
|---|
| 1716 | SetLastError(ERROR_INVALID_WINDOW_HANDLE);
|
|---|
| 1717 | return 0;
|
|---|
| 1718 | }
|
|---|
| 1719 | if(hwndParent != OSLIB_HWND_DESKTOP)
|
|---|
| 1720 | {//if the current process owns the window, just do a quick search
|
|---|
| 1721 | child = (Win32BaseWindow *)parent->getFirstChild();
|
|---|
| 1722 | if(hwndChildAfter != 0)
|
|---|
| 1723 | {
|
|---|
| 1724 | while(child)
|
|---|
| 1725 | {
|
|---|
| 1726 | if(child->getWindowHandle() == hwndChildAfter)
|
|---|
| 1727 | {
|
|---|
| 1728 | child = (Win32BaseWindow *)child->getNextChild();
|
|---|
| 1729 | break;
|
|---|
| 1730 | }
|
|---|
| 1731 | child = (Win32BaseWindow *)child->getNextChild();
|
|---|
| 1732 | }
|
|---|
| 1733 | }
|
|---|
| 1734 | while(child)
|
|---|
| 1735 | {
|
|---|
| 1736 | if(child->getWindowClass()->hasClassName(lpszClass, fUnicode) &&
|
|---|
| 1737 | (!lpszWindow || child->hasWindowName(lpszWindow, fUnicode)))
|
|---|
| 1738 | {
|
|---|
| 1739 | dprintf(("FindWindowEx: Found window %x", child->getWindowHandle()));
|
|---|
| 1740 | return child->getWindowHandle();
|
|---|
| 1741 | }
|
|---|
| 1742 | child = (Win32BaseWindow *)child->getNextChild();
|
|---|
| 1743 | }
|
|---|
| 1744 | }
|
|---|
| 1745 | else {
|
|---|
| 1746 | Win32BaseWindow *wnd;
|
|---|
| 1747 | HWND henum, hwnd;
|
|---|
| 1748 |
|
|---|
| 1749 | henum = OSLibWinBeginEnumWindows(OSLIB_HWND_DESKTOP);
|
|---|
| 1750 | hwnd = OSLibWinGetNextWindow(henum);
|
|---|
| 1751 |
|
|---|
| 1752 | while(hwnd)
|
|---|
| 1753 | {
|
|---|
| 1754 | wnd = GetWindowFromOS2Handle(hwnd);
|
|---|
| 1755 | if(wnd == NULL) {
|
|---|
| 1756 | hwnd = OSLibWinQueryClientWindow(hwnd);
|
|---|
| 1757 | if(hwnd) wnd = GetWindowFromOS2Handle(hwnd);
|
|---|
| 1758 | }
|
|---|
| 1759 |
|
|---|
| 1760 | if(wnd) {
|
|---|
| 1761 | LPVOID sharedmembase = (LPVOID)OSLibWinGetWindowULong(hwnd, OFFSET_WIN32PM_SHAREDMEM);
|
|---|
| 1762 |
|
|---|
| 1763 | if(OSLibDosGetSharedMem(sharedmembase, MAX_HEAPSIZE, OSLIB_PAG_READ) != 0) {
|
|---|
| 1764 | dprintf(("OSLibDosGetSharedMem returned error for %x", wnd));
|
|---|
| 1765 | break;
|
|---|
| 1766 | }
|
|---|
| 1767 | if(wnd->getWindowClass()->hasClassName(lpszClass, fUnicode) &&
|
|---|
| 1768 | (!lpszWindow || wnd->hasWindowName(lpszWindow, fUnicode)))
|
|---|
| 1769 | {
|
|---|
| 1770 | OSLibWinEndEnumWindows(henum);
|
|---|
| 1771 | dprintf(("FindWindowEx: Found window %x", wnd->getWindowHandle()));
|
|---|
| 1772 | return wnd->getWindowHandle();
|
|---|
| 1773 | }
|
|---|
| 1774 | }
|
|---|
| 1775 | hwnd = OSLibWinGetNextWindow(henum);
|
|---|
| 1776 | }
|
|---|
| 1777 | OSLibWinEndEnumWindows(henum);
|
|---|
| 1778 | }
|
|---|
| 1779 | SetLastError(ERROR_CANNOT_FIND_WND_CLASS); //TODO: not always correct
|
|---|
| 1780 | return 0;
|
|---|
| 1781 | }
|
|---|
| 1782 | //******************************************************************************
|
|---|
| 1783 | //TODO: not complete nor correct (distinction be tween top-level, top-most & child windows)
|
|---|
| 1784 | //******************************************************************************
|
|---|
| 1785 | HWND Win32BaseWindow::GetWindow(UINT uCmd)
|
|---|
| 1786 | {
|
|---|
| 1787 | Win32BaseWindow *win32wnd;
|
|---|
| 1788 | ULONG magic;
|
|---|
| 1789 | ULONG getcmd = 0;
|
|---|
| 1790 | HWND hwndRelated;
|
|---|
| 1791 |
|
|---|
| 1792 | dprintf(("GetWindow %x %d NOT COMPLETE", getWindowHandle(), uCmd));
|
|---|
| 1793 | switch(uCmd)
|
|---|
| 1794 | {
|
|---|
| 1795 | case GW_CHILD:
|
|---|
| 1796 | getcmd = QWOS_TOP;
|
|---|
| 1797 | break;
|
|---|
| 1798 | case GW_HWNDFIRST:
|
|---|
| 1799 | if(getParent()) {
|
|---|
| 1800 | getcmd = QWOS_TOP; //top of child windows
|
|---|
| 1801 | }
|
|---|
| 1802 | else getcmd = QWOS_TOP; //TODO
|
|---|
| 1803 | break;
|
|---|
| 1804 | case GW_HWNDLAST:
|
|---|
| 1805 | if(getParent()) {
|
|---|
| 1806 | getcmd = QWOS_BOTTOM; //bottom of child windows
|
|---|
| 1807 | }
|
|---|
| 1808 | else getcmd = QWOS_BOTTOM; //TODO
|
|---|
| 1809 | break;
|
|---|
| 1810 | case GW_HWNDNEXT:
|
|---|
| 1811 | getcmd = QWOS_NEXT;
|
|---|
| 1812 | break;
|
|---|
| 1813 | case GW_HWNDPREV:
|
|---|
| 1814 | getcmd = QWOS_PREV;
|
|---|
| 1815 | break;
|
|---|
| 1816 | case GW_OWNER:
|
|---|
| 1817 | if(owner) {
|
|---|
| 1818 | return owner->getWindowHandle();
|
|---|
| 1819 | }
|
|---|
| 1820 | else return 0;
|
|---|
| 1821 | }
|
|---|
| 1822 | hwndRelated = OSLibWinQueryWindow(OS2Hwnd, getcmd);
|
|---|
| 1823 | if(hwndRelated)
|
|---|
| 1824 | {
|
|---|
| 1825 | win32wnd = (Win32BaseWindow *)OSLibWinGetWindowULong(hwndRelated, OFFSET_WIN32WNDPTR);
|
|---|
| 1826 | magic = OSLibWinGetWindowULong(hwndRelated, OFFSET_WIN32PM_MAGIC);
|
|---|
| 1827 | if(CheckMagicDword(magic) && win32wnd)
|
|---|
| 1828 | {
|
|---|
| 1829 | return win32wnd->getWindowHandle();
|
|---|
| 1830 | }
|
|---|
| 1831 | }
|
|---|
| 1832 | return 0;
|
|---|
| 1833 | }
|
|---|
| 1834 | //******************************************************************************
|
|---|
| 1835 | //******************************************************************************
|
|---|
| 1836 | HWND Win32BaseWindow::SetActiveWindow()
|
|---|
| 1837 | {
|
|---|
| 1838 | return OSLibWinSetActiveWindow(OS2Hwnd);
|
|---|
| 1839 | }
|
|---|
| 1840 | //******************************************************************************
|
|---|
| 1841 | //WM_ENABLE is sent to hwnd, but not to it's children (as it should be)
|
|---|
| 1842 | //******************************************************************************
|
|---|
| 1843 | BOOL Win32BaseWindow::EnableWindow(BOOL fEnable)
|
|---|
| 1844 | {
|
|---|
| 1845 | return OSLibWinEnableWindow(OS2Hwnd, fEnable);
|
|---|
| 1846 | }
|
|---|
| 1847 | //******************************************************************************
|
|---|
| 1848 | //******************************************************************************
|
|---|
| 1849 | BOOL Win32BaseWindow::CloseWindow()
|
|---|
| 1850 | {
|
|---|
| 1851 | return OSLibWinMinimizeWindow(OS2Hwnd);
|
|---|
| 1852 | }
|
|---|
| 1853 | //******************************************************************************
|
|---|
| 1854 | //******************************************************************************
|
|---|
| 1855 | HWND Win32BaseWindow::GetActiveWindow()
|
|---|
| 1856 | {
|
|---|
| 1857 | HWND hwndActive;
|
|---|
| 1858 | Win32BaseWindow *win32wnd;
|
|---|
| 1859 | ULONG magic;
|
|---|
| 1860 |
|
|---|
| 1861 | hwndActive = OSLibWinQueryActiveWindow();
|
|---|
| 1862 |
|
|---|
| 1863 | win32wnd = (Win32BaseWindow *)OSLibWinGetWindowULong(hwndActive, OFFSET_WIN32WNDPTR);
|
|---|
| 1864 | magic = OSLibWinGetWindowULong(hwndActive, OFFSET_WIN32PM_MAGIC);
|
|---|
| 1865 | if(CheckMagicDword(magic) && win32wnd)
|
|---|
| 1866 | {
|
|---|
| 1867 | return win32wnd->getWindowHandle();
|
|---|
| 1868 | }
|
|---|
| 1869 | return hwndActive;
|
|---|
| 1870 | }
|
|---|
| 1871 | //******************************************************************************
|
|---|
| 1872 | //******************************************************************************
|
|---|
| 1873 | BOOL Win32BaseWindow::IsWindow()
|
|---|
| 1874 | {
|
|---|
| 1875 | return TRUE;
|
|---|
| 1876 | }
|
|---|
| 1877 | //******************************************************************************
|
|---|
| 1878 | //******************************************************************************
|
|---|
| 1879 | BOOL Win32BaseWindow::IsWindowEnabled()
|
|---|
| 1880 | {
|
|---|
| 1881 | return OSLibWinIsWindowEnabled(OS2Hwnd);
|
|---|
| 1882 | }
|
|---|
| 1883 | //******************************************************************************
|
|---|
| 1884 | //******************************************************************************
|
|---|
| 1885 | BOOL Win32BaseWindow::IsWindowVisible()
|
|---|
| 1886 | {
|
|---|
| 1887 | return OSLibWinIsWindowVisible(OS2Hwnd);
|
|---|
| 1888 | }
|
|---|
| 1889 | //******************************************************************************
|
|---|
| 1890 | //******************************************************************************
|
|---|
| 1891 | BOOL Win32BaseWindow::GetWindowRect(PRECT pRect)
|
|---|
| 1892 | {
|
|---|
| 1893 | return OSLibWinQueryWindowRect(OS2Hwnd, pRect, RELATIVE_TO_SCREEN);
|
|---|
| 1894 | }
|
|---|
| 1895 | //******************************************************************************
|
|---|
| 1896 | //******************************************************************************
|
|---|
| 1897 | BOOL Win32BaseWindow::hasWindowName(LPSTR wndname, BOOL fUnicode)
|
|---|
| 1898 | {
|
|---|
| 1899 | if(fUnicode) {
|
|---|
| 1900 | return (lstrcmpW(windowNameW, (LPWSTR)wndname) == 0);
|
|---|
| 1901 | }
|
|---|
| 1902 | else return (strcmp(windowNameA, wndname) == 0);
|
|---|
| 1903 | }
|
|---|
| 1904 | //******************************************************************************
|
|---|
| 1905 | //******************************************************************************
|
|---|
| 1906 | int Win32BaseWindow::GetWindowTextLengthA()
|
|---|
| 1907 | {
|
|---|
| 1908 | return OSLibWinQueryWindowTextLength(OS2Hwnd);
|
|---|
| 1909 | }
|
|---|
| 1910 | //******************************************************************************
|
|---|
| 1911 | //******************************************************************************
|
|---|
| 1912 | int Win32BaseWindow::GetWindowTextA(LPSTR lpsz, int cch)
|
|---|
| 1913 | {
|
|---|
| 1914 | return OSLibWinQueryWindowText(OS2Hwnd, cch, lpsz);
|
|---|
| 1915 | }
|
|---|
| 1916 | //******************************************************************************
|
|---|
| 1917 | //******************************************************************************
|
|---|
| 1918 | BOOL Win32BaseWindow::SetWindowText(LPSTR lpsz)
|
|---|
| 1919 | {
|
|---|
| 1920 | if(lpsz == NULL)
|
|---|
| 1921 | return FALSE;
|
|---|
| 1922 |
|
|---|
| 1923 | if(isUnicode == FALSE) {
|
|---|
| 1924 | windowNameA = (LPSTR)_smalloc(strlen(lpsz)+1);
|
|---|
| 1925 | strcpy(windowNameA, lpsz);
|
|---|
| 1926 | windowNameW = (LPWSTR)_smalloc((strlen(lpsz)+1)*sizeof(WCHAR));
|
|---|
| 1927 | lstrcpyAtoW(windowNameW, windowNameA);
|
|---|
| 1928 | }
|
|---|
| 1929 | else {
|
|---|
| 1930 | windowNameW = (LPWSTR)_smalloc((lstrlenW((LPWSTR)lpsz)+1)*sizeof(WCHAR));
|
|---|
| 1931 | lstrcpyW(windowNameW, (LPWSTR)lpsz);
|
|---|
| 1932 | windowNameA = (LPSTR)_smalloc(lstrlenW((LPWSTR)lpsz)+1);
|
|---|
| 1933 | lstrcpyWtoA(windowNameA, windowNameW);
|
|---|
| 1934 | }
|
|---|
| 1935 | wndNameLength = strlen(windowNameA)+1; //including 0 terminator
|
|---|
| 1936 |
|
|---|
| 1937 | if(OS2Hwnd)
|
|---|
| 1938 | return OSLibWinSetWindowText(OS2Hwnd, (LPSTR)windowNameA);
|
|---|
| 1939 |
|
|---|
| 1940 | return TRUE;
|
|---|
| 1941 | }
|
|---|
| 1942 | //******************************************************************************
|
|---|
| 1943 | //******************************************************************************
|
|---|
| 1944 | LONG Win32BaseWindow::SetWindowLongA(int index, ULONG value)
|
|---|
| 1945 | {
|
|---|
| 1946 | LONG oldval;
|
|---|
| 1947 |
|
|---|
| 1948 | switch(index) {
|
|---|
| 1949 | case GWL_EXSTYLE:
|
|---|
| 1950 | oldval = dwExStyle;
|
|---|
| 1951 | setExStyle(value);
|
|---|
| 1952 | return oldval;
|
|---|
| 1953 | case GWL_STYLE:
|
|---|
| 1954 | oldval = dwStyle;
|
|---|
| 1955 | setStyle(value);
|
|---|
| 1956 | return oldval;
|
|---|
| 1957 | case GWL_WNDPROC:
|
|---|
| 1958 | oldval = (LONG)getWindowProc();
|
|---|
| 1959 | setWindowProc((WNDPROC)value);
|
|---|
| 1960 | return oldval;
|
|---|
| 1961 | case GWL_HINSTANCE:
|
|---|
| 1962 | oldval = hInstance;
|
|---|
| 1963 | hInstance = value;
|
|---|
| 1964 | return oldval;
|
|---|
| 1965 | case GWL_HWNDPARENT:
|
|---|
| 1966 | return SetParent((HWND)value);
|
|---|
| 1967 |
|
|---|
| 1968 | case GWL_ID:
|
|---|
| 1969 | oldval = getWindowId();
|
|---|
| 1970 | setWindowId(value);
|
|---|
| 1971 | return oldval;
|
|---|
| 1972 | case GWL_USERDATA:
|
|---|
| 1973 | oldval = userData;
|
|---|
| 1974 | userData = value;
|
|---|
| 1975 | return oldval;
|
|---|
| 1976 | default:
|
|---|
| 1977 | if(index >= 0 && index/4 < nrUserWindowLong)
|
|---|
| 1978 | {
|
|---|
| 1979 | oldval = userWindowLong[index/4];
|
|---|
| 1980 | userWindowLong[index/4] = value;
|
|---|
| 1981 | return oldval;
|
|---|
| 1982 | }
|
|---|
| 1983 | SetLastError(ERROR_INVALID_PARAMETER);
|
|---|
| 1984 | return 0;
|
|---|
| 1985 | }
|
|---|
| 1986 | }
|
|---|
| 1987 | //******************************************************************************
|
|---|
| 1988 | //******************************************************************************
|
|---|
| 1989 | ULONG Win32BaseWindow::GetWindowLongA(int index)
|
|---|
| 1990 | {
|
|---|
| 1991 | switch(index) {
|
|---|
| 1992 | case GWL_EXSTYLE:
|
|---|
| 1993 | return dwExStyle;
|
|---|
| 1994 | case GWL_STYLE:
|
|---|
| 1995 | return dwStyle;
|
|---|
| 1996 | case GWL_WNDPROC:
|
|---|
| 1997 | return (ULONG)getWindowProc();
|
|---|
| 1998 | case GWL_HINSTANCE:
|
|---|
| 1999 | return hInstance;
|
|---|
| 2000 | case GWL_HWNDPARENT:
|
|---|
| 2001 | if(getParent()) {
|
|---|
| 2002 | return getParent()->getWindowHandle();
|
|---|
| 2003 | }
|
|---|
| 2004 | else return 0;
|
|---|
| 2005 | case GWL_ID:
|
|---|
| 2006 | return getWindowId();
|
|---|
| 2007 | case GWL_USERDATA:
|
|---|
| 2008 | return userData;
|
|---|
| 2009 | default:
|
|---|
| 2010 | if(index >= 0 && index/4 < nrUserWindowLong)
|
|---|
| 2011 | {
|
|---|
| 2012 | return userWindowLong[index/4];
|
|---|
| 2013 | }
|
|---|
| 2014 | SetLastError(ERROR_INVALID_PARAMETER);
|
|---|
| 2015 | return 0;
|
|---|
| 2016 | }
|
|---|
| 2017 | }
|
|---|
| 2018 | //******************************************************************************
|
|---|
| 2019 | //******************************************************************************
|
|---|
| 2020 | WORD Win32BaseWindow::SetWindowWord(int index, WORD value)
|
|---|
| 2021 | {
|
|---|
| 2022 | WORD oldval;
|
|---|
| 2023 |
|
|---|
| 2024 | if(index >= 0 && index/4 < nrUserWindowLong)
|
|---|
| 2025 | {
|
|---|
| 2026 | oldval = ((WORD *)userWindowLong)[index/2];
|
|---|
| 2027 | ((WORD *)userWindowLong)[index/2] = value;
|
|---|
| 2028 | return oldval;
|
|---|
| 2029 | }
|
|---|
| 2030 | SetLastError(ERROR_INVALID_PARAMETER);
|
|---|
| 2031 | return 0;
|
|---|
| 2032 | }
|
|---|
| 2033 | //******************************************************************************
|
|---|
| 2034 | //******************************************************************************
|
|---|
| 2035 | WORD Win32BaseWindow::GetWindowWord(int index)
|
|---|
| 2036 | {
|
|---|
| 2037 | if(index >= 0 && index/4 < nrUserWindowLong)
|
|---|
| 2038 | {
|
|---|
| 2039 | return ((WORD *)userWindowLong)[index/2];
|
|---|
| 2040 | }
|
|---|
| 2041 | SetLastError(ERROR_INVALID_PARAMETER);
|
|---|
| 2042 | return 0;
|
|---|
| 2043 | }
|
|---|
| 2044 | //******************************************************************************
|
|---|
| 2045 | //******************************************************************************
|
|---|
| 2046 | Win32BaseWindow *Win32BaseWindow::GetWindowFromHandle(HWND hwnd)
|
|---|
| 2047 | {
|
|---|
| 2048 | Win32BaseWindow *window;
|
|---|
| 2049 |
|
|---|
| 2050 | if(HwGetWindowHandleData(hwnd, (DWORD *)&window) == TRUE) {
|
|---|
| 2051 | return window;
|
|---|
| 2052 | }
|
|---|
| 2053 | else return NULL;
|
|---|
| 2054 | }
|
|---|
| 2055 | //******************************************************************************
|
|---|
| 2056 | //******************************************************************************
|
|---|
| 2057 | Win32BaseWindow *Win32BaseWindow::GetWindowFromOS2Handle(HWND hwnd)
|
|---|
| 2058 | {
|
|---|
| 2059 | Win32BaseWindow *win32wnd;
|
|---|
| 2060 | DWORD magic;
|
|---|
| 2061 |
|
|---|
| 2062 | win32wnd = (Win32BaseWindow *)OSLibWinGetWindowULong(hwnd, OFFSET_WIN32WNDPTR);
|
|---|
| 2063 | magic = OSLibWinGetWindowULong(hwnd, OFFSET_WIN32PM_MAGIC);
|
|---|
| 2064 |
|
|---|
| 2065 | if(win32wnd && CheckMagicDword(magic)) {
|
|---|
| 2066 | return win32wnd;
|
|---|
| 2067 | }
|
|---|
| 2068 | return 0;
|
|---|
| 2069 | }
|
|---|
| 2070 | //******************************************************************************
|
|---|
| 2071 | //******************************************************************************
|
|---|
| 2072 | GenericObject *Win32BaseWindow::windows = NULL;
|
|---|