| 1 | /* $Id: win32wnd.cpp,v 1.20 1999-07-24 14:01:45 sandervl Exp $ */
|
|---|
| 2 | /*
|
|---|
| 3 | * Win32 Window Code for OS/2
|
|---|
| 4 | *
|
|---|
| 5 | *
|
|---|
| 6 | * Copyright 1998-1999 Sander van Leeuwen (sandervl@xs4all.nl)
|
|---|
| 7 | *
|
|---|
| 8 | * Parts based on Wine Windows code (windows\win.c)
|
|---|
| 9 | *
|
|---|
| 10 | * Copyright 1993, 1994 Alexandre Julliard
|
|---|
| 11 | *
|
|---|
| 12 | *
|
|---|
| 13 | * Project Odin Software License can be found in LICENSE.TXT
|
|---|
| 14 | *
|
|---|
| 15 | */
|
|---|
| 16 | #include <os2win.h>
|
|---|
| 17 | #include <win.h>
|
|---|
| 18 | #include <stdlib.h>
|
|---|
| 19 | #include <string.h>
|
|---|
| 20 | #include <stdarg.h>
|
|---|
| 21 | #include <assert.h>
|
|---|
| 22 | #include <misc.h>
|
|---|
| 23 | #include <handlemanager.h>
|
|---|
| 24 | #include <win32wnd.h>
|
|---|
| 25 | #include <spy.h>
|
|---|
| 26 | #include "wndmsg.h"
|
|---|
| 27 | #include "hooks.h"
|
|---|
| 28 | #include <oslibwin.h>
|
|---|
| 29 | #include <oslibutil.h>
|
|---|
| 30 | #include <oslibgdi.h>
|
|---|
| 31 | #include <oslibres.h>
|
|---|
| 32 | #include <winres.h>
|
|---|
| 33 |
|
|---|
| 34 | #define HAS_DLGFRAME(style,exStyle) \
|
|---|
| 35 | (((exStyle) & WS_EX_DLGMODALFRAME) || \
|
|---|
| 36 | (((style) & WS_DLGFRAME) && !((style) & WS_BORDER)))
|
|---|
| 37 |
|
|---|
| 38 | #define HAS_THICKFRAME(style) \
|
|---|
| 39 | (((style) & WS_THICKFRAME) && \
|
|---|
| 40 | !(((style) & (WS_DLGFRAME|WS_BORDER)) == WS_DLGFRAME))
|
|---|
| 41 |
|
|---|
| 42 | //******************************************************************************
|
|---|
| 43 | //******************************************************************************
|
|---|
| 44 | Win32Window::Win32Window(DWORD objType) : GenericObject(&windows, objType)
|
|---|
| 45 | {
|
|---|
| 46 | Init();
|
|---|
| 47 | }
|
|---|
| 48 | //******************************************************************************
|
|---|
| 49 | //******************************************************************************
|
|---|
| 50 | Win32Window::Win32Window(CREATESTRUCTA *lpCreateStructA, ATOM classAtom, BOOL isUnicode)
|
|---|
| 51 | : GenericObject(&windows, OBJTYPE_WINDOW), ChildWindow()
|
|---|
| 52 | {
|
|---|
| 53 | Init();
|
|---|
| 54 | this->isUnicode = isUnicode;
|
|---|
| 55 | CreateWindowExA(lpCreateStructA, classAtom);
|
|---|
| 56 | }
|
|---|
| 57 | //******************************************************************************
|
|---|
| 58 | //******************************************************************************
|
|---|
| 59 | void Win32Window::Init()
|
|---|
| 60 | {
|
|---|
| 61 | isUnicode = FALSE;
|
|---|
| 62 |
|
|---|
| 63 | windowName = NULL;
|
|---|
| 64 | wndNameLength = 0;
|
|---|
| 65 |
|
|---|
| 66 | windowText = NULL;;
|
|---|
| 67 | wndTextLength = 0;
|
|---|
| 68 |
|
|---|
| 69 | userWindowLong = NULL;;
|
|---|
| 70 | nrUserWindowLong = 0;
|
|---|
| 71 |
|
|---|
| 72 | magic = WIN32PM_MAGIC;
|
|---|
| 73 | OS2Hwnd = 0;
|
|---|
| 74 | OS2HwndFrame = 0;
|
|---|
| 75 | OS2HwndMenu = 0;
|
|---|
| 76 | Win32Hwnd = 0;
|
|---|
| 77 |
|
|---|
| 78 | if(HMHandleAllocate(&Win32Hwnd, (ULONG)this) != 0)
|
|---|
| 79 | {
|
|---|
| 80 | dprintf(("Win32Window::Init HMHandleAllocate failed!!"));
|
|---|
| 81 | DebugInt3();
|
|---|
| 82 | }
|
|---|
| 83 | Win32Hwnd &= 0xFFFF;
|
|---|
| 84 | Win32Hwnd |= 0x68000000;
|
|---|
| 85 |
|
|---|
| 86 | posx = posy = 0;
|
|---|
| 87 | width = height = 0;
|
|---|
| 88 |
|
|---|
| 89 | dwExStyle = 0;
|
|---|
| 90 | dwStyle = 0;
|
|---|
| 91 | win32wndproc = 0;
|
|---|
| 92 | hInstance = 0;
|
|---|
| 93 | windowId = 0xFFFFFFFF; //default = -1
|
|---|
| 94 | userData = 0;
|
|---|
| 95 |
|
|---|
| 96 | hwndLinkAfter = HWND_BOTTOM;
|
|---|
| 97 | flags = 0;
|
|---|
| 98 | isIcon = FALSE;
|
|---|
| 99 | lastHitTestVal = 0;
|
|---|
| 100 | owner = NULL;
|
|---|
| 101 | windowClass = 0;
|
|---|
| 102 |
|
|---|
| 103 | acceltableResource = NULL;
|
|---|
| 104 | menuResource = NULL;
|
|---|
| 105 | iconResource = NULL;
|
|---|
| 106 | }
|
|---|
| 107 | //******************************************************************************
|
|---|
| 108 | //todo get rid of resources (menu, accel, icon etc)
|
|---|
| 109 | //******************************************************************************
|
|---|
| 110 | Win32Window::~Win32Window()
|
|---|
| 111 | {
|
|---|
| 112 | OSLibWinSetWindowULong(OS2Hwnd, OFFSET_WIN32WNDPTR, 0);
|
|---|
| 113 | OSLibWinSetWindowULong(OS2Hwnd, OFFSET_WIN32PM_MAGIC, 0);
|
|---|
| 114 |
|
|---|
| 115 | if(Win32Hwnd)
|
|---|
| 116 | HMHandleFree(Win32Hwnd & 0xFFFF);
|
|---|
| 117 | if(windowName)
|
|---|
| 118 | free(windowName);
|
|---|
| 119 | if(windowText)
|
|---|
| 120 | free(windowText);
|
|---|
| 121 | if(userWindowLong)
|
|---|
| 122 | free(userWindowLong);
|
|---|
| 123 | }
|
|---|
| 124 | //******************************************************************************
|
|---|
| 125 | //******************************************************************************
|
|---|
| 126 | BOOL Win32Window::isChild()
|
|---|
| 127 | {
|
|---|
| 128 | return (dwStyle & WS_CHILD) != 0;
|
|---|
| 129 | }
|
|---|
| 130 | //******************************************************************************
|
|---|
| 131 | //******************************************************************************
|
|---|
| 132 | BOOL Win32Window::CreateWindowExA(CREATESTRUCTA *cs, ATOM classAtom)
|
|---|
| 133 | {
|
|---|
| 134 | char buffer[256];
|
|---|
| 135 | INT sw = SW_SHOW;
|
|---|
| 136 | POINT maxSize, maxPos, minTrack, maxTrack;
|
|---|
| 137 |
|
|---|
| 138 | SetLastError(0);
|
|---|
| 139 |
|
|---|
| 140 | /* Find the parent window */
|
|---|
| 141 | if (cs->hwndParent)
|
|---|
| 142 | {
|
|---|
| 143 | Win32Window *window = GetWindowFromHandle(cs->hwndParent);
|
|---|
| 144 | if(!window) {
|
|---|
| 145 | dprintf(("Bad parent %04x\n", cs->hwndParent ));
|
|---|
| 146 | SetLastError(ERROR_INVALID_PARAMETER);
|
|---|
| 147 | return FALSE;
|
|---|
| 148 | }
|
|---|
| 149 | /* Make sure parent is valid */
|
|---|
| 150 | if (!window->IsWindow() )
|
|---|
| 151 | {
|
|---|
| 152 | dprintf(("Bad parent %04x\n", cs->hwndParent ));
|
|---|
| 153 | SetLastError(ERROR_INVALID_PARAMETER);
|
|---|
| 154 | return FALSE;
|
|---|
| 155 | }
|
|---|
| 156 | }
|
|---|
| 157 | else
|
|---|
| 158 | if ((cs->style & WS_CHILD) && !(cs->style & WS_POPUP)) {
|
|---|
| 159 | dprintf(("No parent for child window\n" ));
|
|---|
| 160 | SetLastError(ERROR_INVALID_PARAMETER);
|
|---|
| 161 | return FALSE; /* WS_CHILD needs a parent, but WS_POPUP doesn't */
|
|---|
| 162 | }
|
|---|
| 163 |
|
|---|
| 164 | /* Find the window class */
|
|---|
| 165 | windowClass = Win32WndClass::FindClass(cs->hInstance, (LPSTR)classAtom);
|
|---|
| 166 | if (!windowClass)
|
|---|
| 167 | {
|
|---|
| 168 | GlobalGetAtomNameA( classAtom, buffer, sizeof(buffer) );
|
|---|
| 169 | dprintf(("Bad class '%s'\n", buffer ));
|
|---|
| 170 | return 0;
|
|---|
| 171 | }
|
|---|
| 172 |
|
|---|
| 173 | /* Fix the lpszClass field: from existing programs, it seems ok to call a CreateWindowXXX
|
|---|
| 174 | * with an atom as the class name, put some programs expect to have a *REAL* string in
|
|---|
| 175 | * lpszClass when the CREATESTRUCT is sent with WM_CREATE
|
|---|
| 176 | */
|
|---|
| 177 | if (!HIWORD(cs->lpszClass) ) {
|
|---|
| 178 | if (isUnicode) {
|
|---|
| 179 | GlobalGetAtomNameW( classAtom, (LPWSTR)buffer, sizeof(buffer) );
|
|---|
| 180 | }
|
|---|
| 181 | else {
|
|---|
| 182 | GlobalGetAtomNameA( classAtom, buffer, sizeof(buffer) );
|
|---|
| 183 | }
|
|---|
| 184 | cs->lpszClass = buffer;
|
|---|
| 185 | }
|
|---|
| 186 |
|
|---|
| 187 | /* Fix the coordinates */
|
|---|
| 188 | if (cs->x == CW_USEDEFAULT || cs->x == CW_USEDEFAULT16)
|
|---|
| 189 | {
|
|---|
| 190 | // PDB *pdb = PROCESS_Current();
|
|---|
| 191 |
|
|---|
| 192 | /* Never believe Microsoft's documentation... CreateWindowEx doc says
|
|---|
| 193 | * that if an overlapped window is created with WS_VISIBLE style bit
|
|---|
| 194 | * set and the x parameter is set to CW_USEDEFAULT, the system ignores
|
|---|
| 195 | * the y parameter. However, disassembling NT implementation (WIN32K.SYS)
|
|---|
| 196 | * reveals that
|
|---|
| 197 | *
|
|---|
| 198 | * 1) not only if checks for CW_USEDEFAULT but also for CW_USEDEFAULT16
|
|---|
| 199 | * 2) it does not ignore the y parameter as the docs claim; instead, it
|
|---|
| 200 | * uses it as second parameter to ShowWindow() unless y is either
|
|---|
| 201 | * CW_USEDEFAULT or CW_USEDEFAULT16.
|
|---|
| 202 | *
|
|---|
| 203 | * The fact that we didn't do 2) caused bogus windows pop up when wine
|
|---|
| 204 | * was running apps that were using this obscure feature. Example -
|
|---|
| 205 | * calc.exe that comes with Win98 (only Win98, it's different from
|
|---|
| 206 | * the one that comes with Win95 and NT)
|
|---|
| 207 | */
|
|---|
| 208 | if (cs->y != CW_USEDEFAULT && cs->y != CW_USEDEFAULT16) sw = cs->y;
|
|---|
| 209 |
|
|---|
| 210 | /* We have saved cs->y, now we can trash it */
|
|---|
| 211 | #if 0
|
|---|
| 212 | if ( !(cs->style & (WS_CHILD | WS_POPUP))
|
|---|
| 213 | && (pdb->env_db->startup_info->dwFlags & STARTF_USEPOSITION) )
|
|---|
| 214 | {
|
|---|
| 215 | cs->x = pdb->env_db->startup_info->dwX;
|
|---|
| 216 | cs->y = pdb->env_db->startup_info->dwY;
|
|---|
| 217 | }
|
|---|
| 218 | #endif
|
|---|
| 219 | cs->x = 0;
|
|---|
| 220 | cs->y = 0;
|
|---|
| 221 | // }
|
|---|
| 222 | }
|
|---|
| 223 | if (cs->cx == CW_USEDEFAULT || cs->cx == CW_USEDEFAULT16)
|
|---|
| 224 | {
|
|---|
| 225 | #if 0
|
|---|
| 226 | PDB *pdb = PROCESS_Current();
|
|---|
| 227 | if ( !(cs->style & (WS_CHILD | WS_POPUP))
|
|---|
| 228 | && (pdb->env_db->startup_info->dwFlags & STARTF_USESIZE) )
|
|---|
| 229 | {
|
|---|
| 230 | cs->cx = pdb->env_db->startup_info->dwXSize;
|
|---|
| 231 | cs->cy = pdb->env_db->startup_info->dwYSize;
|
|---|
| 232 | }
|
|---|
| 233 | else
|
|---|
| 234 | {
|
|---|
| 235 | #endif
|
|---|
| 236 | cs->cx = 600; /* FIXME */
|
|---|
| 237 | cs->cy = 400;
|
|---|
| 238 | // }
|
|---|
| 239 | }
|
|---|
| 240 |
|
|---|
| 241 | //Allocate window words
|
|---|
| 242 | nrUserWindowLong = windowClass->getExtraWndWords();
|
|---|
| 243 | if(nrUserWindowLong) {
|
|---|
| 244 | userWindowLong = (ULONG *)malloc(nrUserWindowLong);
|
|---|
| 245 | memset(userWindowLong, 0, nrUserWindowLong);
|
|---|
| 246 | }
|
|---|
| 247 |
|
|---|
| 248 | if ((cs->style & WS_CHILD) && cs->hwndParent)
|
|---|
| 249 | {
|
|---|
| 250 | SetParent(cs->hwndParent);
|
|---|
| 251 | }
|
|---|
| 252 | else
|
|---|
| 253 | {
|
|---|
| 254 | if (!cs->hwndParent) {
|
|---|
| 255 | owner = NULL;
|
|---|
| 256 | }
|
|---|
| 257 | else
|
|---|
| 258 | {
|
|---|
| 259 | owner = GetWindowFromHandle(cs->hwndParent);
|
|---|
| 260 | if(owner == NULL)
|
|---|
| 261 | {
|
|---|
| 262 | dprintf(("HMHandleTranslateToOS2 couldn't find owner window %x!!!", cs->hwndParent));
|
|---|
| 263 | return FALSE;
|
|---|
| 264 | }
|
|---|
| 265 | }
|
|---|
| 266 | }
|
|---|
| 267 |
|
|---|
| 268 | setWindowProc(windowClass->getWindowProc());
|
|---|
| 269 | hInstance = cs->hInstance;
|
|---|
| 270 | dwStyle = cs->style & ~WS_VISIBLE;
|
|---|
| 271 | dwExStyle = cs->dwExStyle;
|
|---|
| 272 |
|
|---|
| 273 | hwndLinkAfter = ((cs->style & (WS_CHILD|WS_MAXIMIZE)) == WS_CHILD)
|
|---|
| 274 | ? HWND_BOTTOM : HWND_TOP;
|
|---|
| 275 |
|
|---|
| 276 | #if 0
|
|---|
| 277 | //TODO
|
|---|
| 278 | /* Call the WH_CBT hook */
|
|---|
| 279 |
|
|---|
| 280 | if (HOOK_IsHooked( WH_CBT ))
|
|---|
| 281 | {
|
|---|
| 282 | CBT_CREATEWNDA cbtc;
|
|---|
| 283 | LRESULT ret;
|
|---|
| 284 |
|
|---|
| 285 | cbtc.lpcs = cs;
|
|---|
| 286 | cbtc.hwndInsertAfter = hwndLinkAfter;
|
|---|
| 287 | ret = unicode ? HOOK_CallHooksW(WH_CBT, HCBT_CREATEWND, Win32Hwnd, (LPARAM)&cbtc)
|
|---|
| 288 | : HOOK_CallHooksA(WH_CBT, HCBT_CREATEWND, Win32Hwnd, (LPARAM)&cbtc);
|
|---|
| 289 | if (ret)
|
|---|
| 290 | {
|
|---|
| 291 | TRACE_(win)("CBT-hook returned 0\n");
|
|---|
| 292 | wndPtr->pDriver->pFinalize(wndPtr);
|
|---|
| 293 | retvalue = 0;
|
|---|
| 294 | goto end;
|
|---|
| 295 | }
|
|---|
| 296 | }
|
|---|
| 297 | #endif
|
|---|
| 298 |
|
|---|
| 299 | /* Increment class window counter */
|
|---|
| 300 | windowClass->IncreaseWindowCount();
|
|---|
| 301 |
|
|---|
| 302 | /* Correct the window style */
|
|---|
| 303 | if (!(cs->style & WS_CHILD))
|
|---|
| 304 | {
|
|---|
| 305 | dwStyle |= WS_CLIPSIBLINGS;
|
|---|
| 306 | if (!(cs->style & WS_POPUP))
|
|---|
| 307 | {
|
|---|
| 308 | dwStyle |= WS_CAPTION;
|
|---|
| 309 | flags |= WIN_NEED_SIZE;
|
|---|
| 310 | }
|
|---|
| 311 | }
|
|---|
| 312 | if (cs->dwExStyle & WS_EX_DLGMODALFRAME) dwStyle &= ~WS_THICKFRAME;
|
|---|
| 313 |
|
|---|
| 314 | //TODO?
|
|---|
| 315 | #if 0
|
|---|
| 316 | /* Get class or window DC if needed */
|
|---|
| 317 | if (classPtr->style & CS_OWNDC) dce = DCE_AllocDCE(hwnd,DCE_WINDOW_DC);
|
|---|
| 318 | else if (classPtr->style & CS_CLASSDC) wndPtr->dce = classPtr->dce;
|
|---|
| 319 | else wndPtr->dce = NULL;
|
|---|
| 320 | #endif
|
|---|
| 321 |
|
|---|
| 322 | /* Send the WM_GETMINMAXINFO message and fix the size if needed */
|
|---|
| 323 | if ((cs->style & WS_THICKFRAME) || !(cs->style & (WS_POPUP | WS_CHILD)))
|
|---|
| 324 | {
|
|---|
| 325 | GetMinMaxInfo(&maxSize, &maxPos, &minTrack, &maxTrack);
|
|---|
| 326 | if (maxSize.x < cs->cx) cs->cx = maxSize.x;
|
|---|
| 327 | if (maxSize.y < cs->cy) cs->cy = maxSize.y;
|
|---|
| 328 | if (cs->cx < minTrack.x ) cs->cx = minTrack.x;
|
|---|
| 329 | if (cs->cy < minTrack.y ) cs->cy = minTrack.y;
|
|---|
| 330 | }
|
|---|
| 331 |
|
|---|
| 332 | if(cs->style & WS_CHILD)
|
|---|
| 333 | {
|
|---|
| 334 | if(cs->cx < 0) cs->cx = 0;
|
|---|
| 335 | if(cs->cy < 0) cs->cy = 0;
|
|---|
| 336 | }
|
|---|
| 337 | else
|
|---|
| 338 | {
|
|---|
| 339 | if (cs->cx <= 0) cs->cx = 1;
|
|---|
| 340 | if (cs->cy <= 0) cs->cy = 1;
|
|---|
| 341 | }
|
|---|
| 342 |
|
|---|
| 343 | rectWindow.left = cs->x;
|
|---|
| 344 | rectWindow.top = cs->y;
|
|---|
| 345 | rectWindow.right = cs->x + cs->cx;
|
|---|
| 346 | rectWindow.bottom = cs->y + cs->cy;
|
|---|
| 347 | rectClient = rectWindow;
|
|---|
| 348 |
|
|---|
| 349 | DWORD dwOSWinStyle, dwOSFrameStyle;
|
|---|
| 350 |
|
|---|
| 351 | OSLibWinConvertStyle(cs->style, &dwOSWinStyle, &dwOSFrameStyle);
|
|---|
| 352 |
|
|---|
| 353 | OS2Hwnd = OSLibWinCreateWindow((getParent()) ? getParent()->getOS2WindowHandle() : 0,
|
|---|
| 354 | dwOSWinStyle, dwOSFrameStyle, (char *)cs->lpszName,
|
|---|
| 355 | (owner) ? owner->getOS2WindowHandle() : 0,
|
|---|
| 356 | (hwndLinkAfter == HWND_BOTTOM) ? TRUE : FALSE,
|
|---|
| 357 | &OS2HwndFrame);
|
|---|
| 358 |
|
|---|
| 359 | if(OS2Hwnd == 0) {
|
|---|
| 360 | dprintf(("Window creation failed!!"));
|
|---|
| 361 | return FALSE;
|
|---|
| 362 | }
|
|---|
| 363 | if(OSLibWinSetWindowULong(OS2Hwnd, OFFSET_WIN32WNDPTR, (ULONG)this) == FALSE) {
|
|---|
| 364 | dprintf(("WM_CREATE: WinSetWindowULong %X failed!!", OS2Hwnd));
|
|---|
| 365 | return FALSE;
|
|---|
| 366 | }
|
|---|
| 367 | if(OSLibWinSetWindowULong(OS2Hwnd, OFFSET_WIN32PM_MAGIC, WIN32PM_MAGIC) == FALSE) {
|
|---|
| 368 | dprintf(("WM_CREATE: WinSetWindowULong2 %X failed!!", OS2Hwnd));
|
|---|
| 369 | return FALSE;
|
|---|
| 370 | }
|
|---|
| 371 | #if 0
|
|---|
| 372 | if(OS2Hwnd != OS2HwndFrame) {
|
|---|
| 373 | if(OSLibWinSetWindowULong(OS2HwndFrame, OFFSET_WIN32WNDPTR, (ULONG)this) == FALSE) {
|
|---|
| 374 | dprintf(("WM_CREATE: WinSetWindowULong %X failed!!", OS2HwndFrame));
|
|---|
| 375 | return FALSE;
|
|---|
| 376 | }
|
|---|
| 377 | if(OSLibWinSetWindowULong(OS2HwndFrame, OFFSET_WIN32PM_MAGIC, WIN32PM_MAGIC) == FALSE) {
|
|---|
| 378 | dprintf(("WM_CREATE: WinSetWindowULong2 %X failed!!", OS2HwndFrame));
|
|---|
| 379 | return FALSE;
|
|---|
| 380 | }
|
|---|
| 381 | }
|
|---|
| 382 | #endif
|
|---|
| 383 | /* Set the window menu */
|
|---|
| 384 | if ((dwStyle & (WS_CAPTION | WS_CHILD)) == WS_CAPTION )
|
|---|
| 385 | {
|
|---|
| 386 | if (cs->hMenu) SetMenu(cs->hMenu);
|
|---|
| 387 | else
|
|---|
| 388 | {
|
|---|
| 389 | if (windowClass->getMenuNameA()) {
|
|---|
| 390 | cs->hMenu = LoadMenuA(cs->hInstance, windowClass->getMenuNameA());
|
|---|
| 391 | if (cs->hMenu) SetMenu(cs->hMenu );
|
|---|
| 392 | }
|
|---|
| 393 | }
|
|---|
| 394 | }
|
|---|
| 395 | else windowId = (UINT)cs->hMenu;
|
|---|
| 396 |
|
|---|
| 397 | //Set icon from class
|
|---|
| 398 | if(windowClass->getIcon())
|
|---|
| 399 | SetIcon(windowClass->getIcon());
|
|---|
| 400 |
|
|---|
| 401 | /* Send the WM_CREATE message
|
|---|
| 402 | * Perhaps we shouldn't allow width/height changes as well.
|
|---|
| 403 | * See p327 in "Internals".
|
|---|
| 404 | */
|
|---|
| 405 | maxPos.x = rectWindow.left; maxPos.y = rectWindow.top;
|
|---|
| 406 |
|
|---|
| 407 | if(SendInternalMessage(WM_NCCREATE, 0, (LPARAM)cs) )
|
|---|
| 408 | {
|
|---|
| 409 | SendNCCalcSize(FALSE, &rectWindow, NULL, NULL, 0, &rectClient );
|
|---|
| 410 | OffsetRect(&rectWindow, maxPos.x - rectWindow.left,
|
|---|
| 411 | maxPos.y - rectWindow.top);
|
|---|
| 412 | dprintf(("Sending WM_CREATE"));
|
|---|
| 413 | if( (SendInternalMessage(WM_CREATE, 0, (LPARAM)cs )) != -1 )
|
|---|
| 414 | {
|
|---|
| 415 | SetWindowPos(HWND_TOP, rectClient.left, rectClient.top,
|
|---|
| 416 | rectClient.right-rectClient.left,
|
|---|
| 417 | rectClient.bottom-rectClient.top,
|
|---|
| 418 | SWP_NOACTIVATE);
|
|---|
| 419 |
|
|---|
| 420 | if (cs->style & WS_VISIBLE) ShowWindow( sw );
|
|---|
| 421 |
|
|---|
| 422 | #if 0
|
|---|
| 423 | /* Call WH_SHELL hook */
|
|---|
| 424 |
|
|---|
| 425 | if (!(dwStyle & WS_CHILD) && !owner)
|
|---|
| 426 | HOOK_CallHooks16( WH_SHELL, HSHELL_WINDOWCREATED, hwnd, 0 );
|
|---|
| 427 | #endif
|
|---|
| 428 | SetLastError(0);
|
|---|
| 429 | return TRUE;
|
|---|
| 430 | }
|
|---|
| 431 | }
|
|---|
| 432 | return FALSE;
|
|---|
| 433 | }
|
|---|
| 434 | #if 0
|
|---|
| 435 | /***********************************************************************
|
|---|
| 436 | * WINPOS_MinMaximize
|
|---|
| 437 | *
|
|---|
| 438 | * Fill in lpRect and return additional flags to be used with SetWindowPos().
|
|---|
| 439 | * This function assumes that 'cmd' is different from the current window
|
|---|
| 440 | * state.
|
|---|
| 441 | */
|
|---|
| 442 | UINT Win32Window::MinMaximize(UINT16 cmd, LPRECT16 lpRect )
|
|---|
| 443 | {
|
|---|
| 444 | UINT swpFlags = 0;
|
|---|
| 445 | POINT pt, size;
|
|---|
| 446 | LPINTERNALPOS lpPos;
|
|---|
| 447 |
|
|---|
| 448 | size.x = rectWindow.left; size.y = rectWindow.top;
|
|---|
| 449 | lpPos = WINPOS_InitInternalPos( wndPtr, size, &rectWindow );
|
|---|
| 450 |
|
|---|
| 451 | if (lpPos && !HOOK_CallHooks16(WH_CBT, HCBT_MINMAX, hwndSelf, cmd))
|
|---|
| 452 | {
|
|---|
| 453 | if( dwStyle & WS_MINIMIZE )
|
|---|
| 454 | {
|
|---|
| 455 | if( !SendInternalMessageA(WM_QUERYOPEN, 0, 0L ) )
|
|---|
| 456 | return (SWP_NOSIZE | SWP_NOMOVE);
|
|---|
| 457 | swpFlags |= SWP_NOCOPYBITS;
|
|---|
| 458 | }
|
|---|
| 459 | switch( cmd )
|
|---|
| 460 | {
|
|---|
| 461 | case SW_MINIMIZE:
|
|---|
| 462 | if( dwStyle & WS_MAXIMIZE)
|
|---|
| 463 | {
|
|---|
| 464 | flags |= WIN_RESTORE_MAX;
|
|---|
| 465 | dwStyle &= ~WS_MAXIMIZE;
|
|---|
| 466 | }
|
|---|
| 467 | else
|
|---|
| 468 | flags &= ~WIN_RESTORE_MAX;
|
|---|
| 469 | dwStyle |= WS_MINIMIZE;
|
|---|
| 470 |
|
|---|
| 471 | #if 0
|
|---|
| 472 | if( flags & WIN_NATIVE )
|
|---|
| 473 | if( pDriver->pSetHostAttr( wndPtr, HAK_ICONICSTATE, TRUE ) )
|
|---|
| 474 | swpFlags |= MINMAX_NOSWP;
|
|---|
| 475 | #endif
|
|---|
| 476 |
|
|---|
| 477 | lpPos->ptIconPos = WINPOS_FindIconPos( wndPtr, lpPos->ptIconPos );
|
|---|
| 478 |
|
|---|
| 479 | SetRect(lpRect, lpPos->ptIconPos.x, lpPos->ptIconPos.y,
|
|---|
| 480 | GetSystemMetrics(SM_CXICON), GetSystemMetrics(SM_CYICON) );
|
|---|
| 481 | swpFlags |= SWP_NOCOPYBITS;
|
|---|
| 482 | break;
|
|---|
| 483 |
|
|---|
| 484 | case SW_MAXIMIZE:
|
|---|
| 485 | CONV_POINT16TO32( &lpPos->ptMaxPos, &pt );
|
|---|
| 486 | WINPOS_GetMinMaxInfo( wndPtr, &size, &pt, NULL, NULL );
|
|---|
| 487 | CONV_POINT32TO16( &pt, &lpPos->ptMaxPos );
|
|---|
| 488 |
|
|---|
| 489 | if( dwStyle & WS_MINIMIZE )
|
|---|
| 490 | {
|
|---|
| 491 | if( flags & WIN_NATIVE )
|
|---|
| 492 | if( pDriver->pSetHostAttr( wndPtr, HAK_ICONICSTATE, FALSE ) )
|
|---|
| 493 | swpFlags |= MINMAX_NOSWP;
|
|---|
| 494 |
|
|---|
| 495 | WINPOS_ShowIconTitle( wndPtr, FALSE );
|
|---|
| 496 | dwStyle &= ~WS_MINIMIZE;
|
|---|
| 497 | }
|
|---|
| 498 | dwStyle |= WS_MAXIMIZE;
|
|---|
| 499 |
|
|---|
| 500 | SetRect16( lpRect, lpPos->ptMaxPos.x, lpPos->ptMaxPos.y,
|
|---|
| 501 | size.x, size.y );
|
|---|
| 502 | break;
|
|---|
| 503 |
|
|---|
| 504 | case SW_RESTORE:
|
|---|
| 505 | if( dwStyle & WS_MINIMIZE )
|
|---|
| 506 | {
|
|---|
| 507 | if( flags & WIN_NATIVE )
|
|---|
| 508 | if( pDriver->pSetHostAttr( wndPtr, HAK_ICONICSTATE, FALSE ) )
|
|---|
| 509 | swpFlags |= MINMAX_NOSWP;
|
|---|
| 510 |
|
|---|
| 511 | dwStyle &= ~WS_MINIMIZE;
|
|---|
| 512 | WINPOS_ShowIconTitle( wndPtr, FALSE );
|
|---|
| 513 |
|
|---|
| 514 | if( flags & WIN_RESTORE_MAX)
|
|---|
| 515 | {
|
|---|
| 516 | /* Restore to maximized position */
|
|---|
| 517 | CONV_POINT16TO32( &lpPos->ptMaxPos, &pt );
|
|---|
| 518 | WINPOS_GetMinMaxInfo( wndPtr, &size, &pt, NULL, NULL);
|
|---|
| 519 | CONV_POINT32TO16( &pt, &lpPos->ptMaxPos );
|
|---|
| 520 | dwStyle |= WS_MAXIMIZE;
|
|---|
| 521 | SetRect16( lpRect, lpPos->ptMaxPos.x, lpPos->ptMaxPos.y, size.x, size.y );
|
|---|
| 522 | break;
|
|---|
| 523 | }
|
|---|
| 524 | }
|
|---|
| 525 | else
|
|---|
| 526 | if( !(dwStyle & WS_MAXIMIZE) ) return (UINT16)(-1);
|
|---|
| 527 | else dwStyle &= ~WS_MAXIMIZE;
|
|---|
| 528 |
|
|---|
| 529 | /* Restore to normal position */
|
|---|
| 530 |
|
|---|
| 531 | *lpRect = lpPos->rectNormal;
|
|---|
| 532 | lpRect->right -= lpRect->left;
|
|---|
| 533 | lpRect->bottom -= lpRect->top;
|
|---|
| 534 |
|
|---|
| 535 | break;
|
|---|
| 536 | }
|
|---|
| 537 | } else swpFlags |= SWP_NOSIZE | SWP_NOMOVE;
|
|---|
| 538 | return swpFlags;
|
|---|
| 539 | }
|
|---|
| 540 | #endif
|
|---|
| 541 | /*******************************************************************
|
|---|
| 542 | * GetMinMaxInfo
|
|---|
| 543 | *
|
|---|
| 544 | * Get the minimized and maximized information for a window.
|
|---|
| 545 | */
|
|---|
| 546 | void Win32Window::GetMinMaxInfo(POINT *maxSize, POINT *maxPos,
|
|---|
| 547 | POINT *minTrack, POINT *maxTrack )
|
|---|
| 548 | {
|
|---|
| 549 | MINMAXINFO MinMax;
|
|---|
| 550 | INT xinc, yinc;
|
|---|
| 551 |
|
|---|
| 552 | /* Compute default values */
|
|---|
| 553 |
|
|---|
| 554 | MinMax.ptMaxSize.x = GetSystemMetrics(SM_CXSCREEN);
|
|---|
| 555 | MinMax.ptMaxSize.y = GetSystemMetrics(SM_CYSCREEN);
|
|---|
| 556 | MinMax.ptMinTrackSize.x = GetSystemMetrics(SM_CXMINTRACK);
|
|---|
| 557 | MinMax.ptMinTrackSize.y = GetSystemMetrics(SM_CYMINTRACK);
|
|---|
| 558 | MinMax.ptMaxTrackSize.x = GetSystemMetrics(SM_CXSCREEN);
|
|---|
| 559 | MinMax.ptMaxTrackSize.y = GetSystemMetrics(SM_CYSCREEN);
|
|---|
| 560 |
|
|---|
| 561 | if (flags & WIN_MANAGED) xinc = yinc = 0;
|
|---|
| 562 | else if (HAS_DLGFRAME( dwStyle, dwExStyle ))
|
|---|
| 563 | {
|
|---|
| 564 | xinc = GetSystemMetrics(SM_CXDLGFRAME);
|
|---|
| 565 | yinc = GetSystemMetrics(SM_CYDLGFRAME);
|
|---|
| 566 | }
|
|---|
| 567 | else
|
|---|
| 568 | {
|
|---|
| 569 | xinc = yinc = 0;
|
|---|
| 570 | if (HAS_THICKFRAME(dwStyle))
|
|---|
| 571 | {
|
|---|
| 572 | xinc += GetSystemMetrics(SM_CXFRAME);
|
|---|
| 573 | yinc += GetSystemMetrics(SM_CYFRAME);
|
|---|
| 574 | }
|
|---|
| 575 | if (dwStyle & WS_BORDER)
|
|---|
| 576 | {
|
|---|
| 577 | xinc += GetSystemMetrics(SM_CXBORDER);
|
|---|
| 578 | yinc += GetSystemMetrics(SM_CYBORDER);
|
|---|
| 579 | }
|
|---|
| 580 | }
|
|---|
| 581 | MinMax.ptMaxSize.x += 2 * xinc;
|
|---|
| 582 | MinMax.ptMaxSize.y += 2 * yinc;
|
|---|
| 583 |
|
|---|
| 584 | #if 0
|
|---|
| 585 | lpPos = (LPINTERNALPOS)GetPropA( hwndSelf, atomInternalPos );
|
|---|
| 586 | if( lpPos && !EMPTYPOINT(lpPos->ptMaxPos) )
|
|---|
| 587 | CONV_POINT16TO32( &lpPos->ptMaxPos, &MinMax.ptMaxPosition );
|
|---|
| 588 | else
|
|---|
| 589 | {
|
|---|
| 590 | #endif
|
|---|
| 591 | MinMax.ptMaxPosition.x = -xinc;
|
|---|
| 592 | MinMax.ptMaxPosition.y = -yinc;
|
|---|
| 593 | // }
|
|---|
| 594 |
|
|---|
| 595 | SendInternalMessageA(WM_GETMINMAXINFO, 0, (LPARAM)&MinMax );
|
|---|
| 596 |
|
|---|
| 597 | /* Some sanity checks */
|
|---|
| 598 |
|
|---|
| 599 | dprintf(("GetMinMaxInfo: %ld %ld / %ld %ld / %ld %ld / %ld %ld\n",
|
|---|
| 600 | MinMax.ptMaxSize.x, MinMax.ptMaxSize.y,
|
|---|
| 601 | MinMax.ptMaxPosition.x, MinMax.ptMaxPosition.y,
|
|---|
| 602 | MinMax.ptMaxTrackSize.x, MinMax.ptMaxTrackSize.y,
|
|---|
| 603 | MinMax.ptMinTrackSize.x, MinMax.ptMinTrackSize.y));
|
|---|
| 604 | MinMax.ptMaxTrackSize.x = MAX( MinMax.ptMaxTrackSize.x,
|
|---|
| 605 | MinMax.ptMinTrackSize.x );
|
|---|
| 606 | MinMax.ptMaxTrackSize.y = MAX( MinMax.ptMaxTrackSize.y,
|
|---|
| 607 | MinMax.ptMinTrackSize.y );
|
|---|
| 608 |
|
|---|
| 609 | if (maxSize) *maxSize = MinMax.ptMaxSize;
|
|---|
| 610 | if (maxPos) *maxPos = MinMax.ptMaxPosition;
|
|---|
| 611 | if (minTrack) *minTrack = MinMax.ptMinTrackSize;
|
|---|
| 612 | if (maxTrack) *maxTrack = MinMax.ptMaxTrackSize;
|
|---|
| 613 | }
|
|---|
| 614 | /***********************************************************************
|
|---|
| 615 | * WINPOS_SendNCCalcSize
|
|---|
| 616 | *
|
|---|
| 617 | * Send a WM_NCCALCSIZE message to a window.
|
|---|
| 618 | * All parameters are read-only except newClientRect.
|
|---|
| 619 | * oldWindowRect, oldClientRect and winpos must be non-NULL only
|
|---|
| 620 | * when calcValidRect is TRUE.
|
|---|
| 621 | */
|
|---|
| 622 | LONG Win32Window::SendNCCalcSize(BOOL calcValidRect,
|
|---|
| 623 | RECT *newWindowRect, RECT *oldWindowRect,
|
|---|
| 624 | RECT *oldClientRect, WINDOWPOS *winpos,
|
|---|
| 625 | RECT *newClientRect )
|
|---|
| 626 | {
|
|---|
| 627 | NCCALCSIZE_PARAMS params;
|
|---|
| 628 | WINDOWPOS winposCopy;
|
|---|
| 629 | LONG result;
|
|---|
| 630 |
|
|---|
| 631 | params.rgrc[0] = *newWindowRect;
|
|---|
| 632 | if (calcValidRect)
|
|---|
| 633 | {
|
|---|
| 634 | winposCopy = *winpos;
|
|---|
| 635 | params.rgrc[1] = *oldWindowRect;
|
|---|
| 636 | params.rgrc[2] = *oldClientRect;
|
|---|
| 637 | params.lppos = &winposCopy;
|
|---|
| 638 | }
|
|---|
| 639 | result = SendInternalMessageA(WM_NCCALCSIZE, calcValidRect,
|
|---|
| 640 | (LPARAM)¶ms );
|
|---|
| 641 | *newClientRect = params.rgrc[0];
|
|---|
| 642 | return result;
|
|---|
| 643 | }
|
|---|
| 644 | //******************************************************************************
|
|---|
| 645 | //******************************************************************************
|
|---|
| 646 | ULONG Win32Window::MsgCreate(HWND hwndOS2, ULONG initParam)
|
|---|
| 647 | {
|
|---|
| 648 | OS2Hwnd = hwndOS2;
|
|---|
| 649 | return SendInternalMessageA(WM_CREATE, 0, initParam);
|
|---|
| 650 | }
|
|---|
| 651 | //******************************************************************************
|
|---|
| 652 | //******************************************************************************
|
|---|
| 653 | ULONG Win32Window::MsgQuit()
|
|---|
| 654 | {
|
|---|
| 655 | return SendInternalMessageA(WM_QUIT, 0, 0);
|
|---|
| 656 | }
|
|---|
| 657 | //******************************************************************************
|
|---|
| 658 | //******************************************************************************
|
|---|
| 659 | ULONG Win32Window::MsgClose()
|
|---|
| 660 | {
|
|---|
| 661 | if(SendInternalMessageA(WM_CLOSE, 0, 0) == 0) {
|
|---|
| 662 | return 0; //app handles this message
|
|---|
| 663 | }
|
|---|
| 664 | delete this;
|
|---|
| 665 | return 1;
|
|---|
| 666 | }
|
|---|
| 667 | //******************************************************************************
|
|---|
| 668 | //******************************************************************************
|
|---|
| 669 | ULONG Win32Window::MsgDestroy()
|
|---|
| 670 | {
|
|---|
| 671 | ULONG rc;
|
|---|
| 672 |
|
|---|
| 673 | rc = SendInternalMessageA(WM_DESTROY, 0, 0);
|
|---|
| 674 | delete this;
|
|---|
| 675 | return rc;
|
|---|
| 676 | }
|
|---|
| 677 | //******************************************************************************
|
|---|
| 678 | //******************************************************************************
|
|---|
| 679 | ULONG Win32Window::MsgEnable(BOOL fEnable)
|
|---|
| 680 | {
|
|---|
| 681 | return SendInternalMessageA(WM_ENABLE, fEnable, 0);
|
|---|
| 682 | }
|
|---|
| 683 | //******************************************************************************
|
|---|
| 684 | //TODO: SW_PARENTCLOSING/OPENING flag (lParam)
|
|---|
| 685 | //******************************************************************************
|
|---|
| 686 | ULONG Win32Window::MsgShow(BOOL fShow)
|
|---|
| 687 | {
|
|---|
| 688 | return SendInternalMessageA(WM_SHOWWINDOW, fShow, 0);
|
|---|
| 689 | }
|
|---|
| 690 | //******************************************************************************
|
|---|
| 691 | //******************************************************************************
|
|---|
| 692 | ULONG Win32Window::MsgMove(ULONG x, ULONG y)
|
|---|
| 693 | {
|
|---|
| 694 | dprintf(("MsgMove to (%d,%d)", x, y));
|
|---|
| 695 | return SendInternalMessageA(WM_MOVE, 0, MAKELONG((USHORT)x, (USHORT)y));
|
|---|
| 696 | }
|
|---|
| 697 | //******************************************************************************
|
|---|
| 698 | //******************************************************************************
|
|---|
| 699 | ULONG Win32Window::MsgCommand(ULONG cmd, ULONG Id, HWND hwnd)
|
|---|
| 700 | {
|
|---|
| 701 | switch(cmd) {
|
|---|
| 702 | case CMD_MENU:
|
|---|
| 703 | return SendInternalMessageA(WM_COMMAND, MAKELONG(Id, 0), 0);
|
|---|
| 704 | case CMD_CONTROL:
|
|---|
| 705 | return 0; //todo
|
|---|
| 706 | case CMD_ACCELERATOR:
|
|---|
| 707 | dprintf(("accelerator command"));
|
|---|
| 708 | return 0; //todo
|
|---|
| 709 | }
|
|---|
| 710 | return 0;
|
|---|
| 711 | }
|
|---|
| 712 | //******************************************************************************
|
|---|
| 713 | //******************************************************************************
|
|---|
| 714 | ULONG Win32Window::MsgHitTest(ULONG x, ULONG y)
|
|---|
| 715 | {
|
|---|
| 716 | lastHitTestVal = SendInternalMessageA(WM_NCHITTEST, 0, MAKELONG((USHORT)x, (USHORT)y));
|
|---|
| 717 | return 1; //TODO: May need to change this
|
|---|
| 718 | }
|
|---|
| 719 | //******************************************************************************
|
|---|
| 720 | //TODO: Send WM_NCCALCSIZE message here and correct size if necessary
|
|---|
| 721 | //******************************************************************************
|
|---|
| 722 | ULONG Win32Window::MsgSize(ULONG width, ULONG height, BOOL fMinimize, BOOL fMaximize)
|
|---|
| 723 | {
|
|---|
| 724 | WORD fwSizeType = 0;
|
|---|
| 725 |
|
|---|
| 726 | if(fMinimize) {
|
|---|
| 727 | fwSizeType = SIZE_MINIMIZED;
|
|---|
| 728 | }
|
|---|
| 729 | else
|
|---|
| 730 | if(fMaximize) {
|
|---|
| 731 | fwSizeType = SIZE_MAXIMIZED;
|
|---|
| 732 | }
|
|---|
| 733 | else fwSizeType = SIZE_RESTORED;
|
|---|
| 734 |
|
|---|
| 735 | return SendInternalMessageA(WM_SIZE, fwSizeType, MAKELONG((USHORT)width, (USHORT)height));
|
|---|
| 736 | }
|
|---|
| 737 | //******************************************************************************
|
|---|
| 738 | //******************************************************************************
|
|---|
| 739 | ULONG Win32Window::MsgActivate(BOOL fActivate, HWND hwnd)
|
|---|
| 740 | {
|
|---|
| 741 | return SendInternalMessageA(WM_ACTIVATE, (fActivate) ? WA_ACTIVE : WA_INACTIVE, hwnd);
|
|---|
| 742 | }
|
|---|
| 743 | //******************************************************************************
|
|---|
| 744 | //******************************************************************************
|
|---|
| 745 | ULONG Win32Window::MsgSetFocus(HWND hwnd)
|
|---|
| 746 | {
|
|---|
| 747 | return SendInternalMessageA(WM_SETFOCUS, hwnd, 0);
|
|---|
| 748 | }
|
|---|
| 749 | //******************************************************************************
|
|---|
| 750 | //******************************************************************************
|
|---|
| 751 | ULONG Win32Window::MsgKillFocus(HWND hwnd)
|
|---|
| 752 | {
|
|---|
| 753 | return SendInternalMessageA(WM_KILLFOCUS, hwnd, 0);
|
|---|
| 754 | }
|
|---|
| 755 | //******************************************************************************
|
|---|
| 756 | //******************************************************************************
|
|---|
| 757 | ULONG Win32Window::MsgButton(ULONG msg, ULONG x, ULONG y)
|
|---|
| 758 | {
|
|---|
| 759 | ULONG win32msg;
|
|---|
| 760 | ULONG win32ncmsg;
|
|---|
| 761 |
|
|---|
| 762 | dprintf(("MsgButton to (%d,%d)", x, y));
|
|---|
| 763 | switch(msg) {
|
|---|
| 764 | case BUTTON_LEFTDOWN:
|
|---|
| 765 | win32msg = WM_LBUTTONDOWN;
|
|---|
| 766 | win32ncmsg = WM_NCLBUTTONDOWN;
|
|---|
| 767 | break;
|
|---|
| 768 | case BUTTON_LEFTUP:
|
|---|
| 769 | win32msg = WM_LBUTTONUP;
|
|---|
| 770 | win32ncmsg = WM_NCLBUTTONUP;
|
|---|
| 771 | break;
|
|---|
| 772 | case BUTTON_LEFTDBLCLICK:
|
|---|
| 773 | win32msg = WM_LBUTTONDBLCLK;
|
|---|
| 774 | win32ncmsg = WM_NCLBUTTONDBLCLK;
|
|---|
| 775 | break;
|
|---|
| 776 | case BUTTON_RIGHTUP:
|
|---|
| 777 | win32msg = WM_RBUTTONUP;
|
|---|
| 778 | win32ncmsg = WM_NCRBUTTONUP;
|
|---|
| 779 | break;
|
|---|
| 780 | case BUTTON_RIGHTDOWN:
|
|---|
| 781 | win32msg = WM_RBUTTONDOWN;
|
|---|
| 782 | win32ncmsg = WM_NCRBUTTONDOWN;
|
|---|
| 783 | break;
|
|---|
| 784 | case BUTTON_RIGHTDBLCLICK:
|
|---|
| 785 | win32msg = WM_RBUTTONDBLCLK;
|
|---|
| 786 | win32ncmsg = WM_NCRBUTTONDBLCLK;
|
|---|
| 787 | break;
|
|---|
| 788 | case BUTTON_MIDDLEUP:
|
|---|
| 789 | win32msg = WM_MBUTTONUP;
|
|---|
| 790 | win32ncmsg = WM_NCMBUTTONUP;
|
|---|
| 791 | break;
|
|---|
| 792 | case BUTTON_MIDDLEDOWN:
|
|---|
| 793 | win32msg = WM_MBUTTONDOWN;
|
|---|
| 794 | win32ncmsg = WM_NCMBUTTONDOWN;
|
|---|
| 795 | break;
|
|---|
| 796 | case BUTTON_MIDDLEDBLCLICK:
|
|---|
| 797 | win32msg = WM_MBUTTONDBLCLK;
|
|---|
| 798 | win32ncmsg = WM_NCMBUTTONDBLCLK;
|
|---|
| 799 | break;
|
|---|
| 800 | default:
|
|---|
| 801 | dprintf(("Win32Window::Button: invalid msg!!!!"));
|
|---|
| 802 | return 1;
|
|---|
| 803 | }
|
|---|
| 804 | SendInternalMessageA(win32ncmsg, lastHitTestVal, MAKELONG(x, y)); //TODO:
|
|---|
| 805 | return SendInternalMessageA(win32msg, 0, MAKELONG(x, y));
|
|---|
| 806 | }
|
|---|
| 807 | //******************************************************************************
|
|---|
| 808 | //******************************************************************************
|
|---|
| 809 | ULONG Win32Window::MsgMouseMove(ULONG keystate, ULONG x, ULONG y)
|
|---|
| 810 | {
|
|---|
| 811 | ULONG winstate = 0;
|
|---|
| 812 |
|
|---|
| 813 | if(keystate & WMMOVE_LBUTTON)
|
|---|
| 814 | winstate |= MK_LBUTTON;
|
|---|
| 815 | if(keystate & WMMOVE_RBUTTON)
|
|---|
| 816 | winstate |= MK_RBUTTON;
|
|---|
| 817 | if(keystate & WMMOVE_MBUTTON)
|
|---|
| 818 | winstate |= MK_MBUTTON;
|
|---|
| 819 | if(keystate & WMMOVE_SHIFT)
|
|---|
| 820 | winstate |= MK_SHIFT;
|
|---|
| 821 | if(keystate & WMMOVE_CTRL)
|
|---|
| 822 | winstate |= MK_CONTROL;
|
|---|
| 823 |
|
|---|
| 824 | return SendInternalMessageA(WM_MOUSEMOVE, keystate, MAKELONG(x, y));
|
|---|
| 825 | }
|
|---|
| 826 | //******************************************************************************
|
|---|
| 827 | //******************************************************************************
|
|---|
| 828 | ULONG Win32Window::MsgPaint(ULONG tmp1, ULONG tmp2)
|
|---|
| 829 | {
|
|---|
| 830 | return SendInternalMessageA(WM_PAINT, 0, 0);
|
|---|
| 831 | }
|
|---|
| 832 | //******************************************************************************
|
|---|
| 833 | //******************************************************************************
|
|---|
| 834 | ULONG Win32Window::MsgEraseBackGround(ULONG hps)
|
|---|
| 835 | {
|
|---|
| 836 | if(isIcon) {
|
|---|
| 837 | return SendInternalMessageA(WM_ICONERASEBKGND, hps, 0);
|
|---|
| 838 | }
|
|---|
| 839 | else return SendInternalMessageA(WM_ERASEBKGND, hps, 0);
|
|---|
| 840 | }
|
|---|
| 841 | //******************************************************************************
|
|---|
| 842 | //******************************************************************************
|
|---|
| 843 | ULONG Win32Window::MsgSetText(LPSTR lpsz, LONG cch)
|
|---|
| 844 | {
|
|---|
| 845 | if(isUnicode) {
|
|---|
| 846 | return SendInternalMessageW(WM_SETTEXT, 0, (LPARAM)lpsz);
|
|---|
| 847 | }
|
|---|
| 848 | else return SendInternalMessageA(WM_SETTEXT, 0, (LPARAM)lpsz);
|
|---|
| 849 | }
|
|---|
| 850 | //******************************************************************************
|
|---|
| 851 | //******************************************************************************
|
|---|
| 852 | LRESULT Win32Window::SendMessageA(ULONG Msg, WPARAM wParam, LPARAM lParam)
|
|---|
| 853 | {
|
|---|
| 854 | if(PostSpyMessage(getWindowHandle(), Msg, wParam, lParam) == FALSE)
|
|---|
| 855 | dprintf(("SendMessageA %s for %x %x %x", GetMsgText(Msg), getWindowHandle(), wParam, lParam));
|
|---|
| 856 |
|
|---|
| 857 | if(HkCBT::OS2HkCBTProc(getWindowHandle(), Msg, wParam, lParam) == TRUE) {//hook swallowed msg
|
|---|
| 858 | return(0);
|
|---|
| 859 | }
|
|---|
| 860 | switch(Msg)
|
|---|
| 861 | {
|
|---|
| 862 | case WM_CREATE:
|
|---|
| 863 | {
|
|---|
| 864 | if(win32wndproc(getWindowHandle(), WM_NCCREATE, 0, lParam) == 0) {
|
|---|
| 865 | dprintf(("WM_NCCREATE returned FALSE\n"));
|
|---|
| 866 | return(-1); //don't create window
|
|---|
| 867 | }
|
|---|
| 868 | if(win32wndproc(getWindowHandle(), WM_CREATE, 0, lParam) == -1) {
|
|---|
| 869 | dprintf(("WM_CREATE returned -1\n"));
|
|---|
| 870 | return(-1); //don't create window
|
|---|
| 871 | }
|
|---|
| 872 | NotifyParent(Msg, wParam, lParam);
|
|---|
| 873 |
|
|---|
| 874 | return(0);
|
|---|
| 875 | }
|
|---|
| 876 | case WM_LBUTTONDOWN:
|
|---|
| 877 | case WM_MBUTTONDOWN:
|
|---|
| 878 | case WM_RBUTTONDOWN:
|
|---|
| 879 | NotifyParent(Msg, wParam, lParam);
|
|---|
| 880 | return win32wndproc(getWindowHandle(), Msg, wParam, lParam);
|
|---|
| 881 |
|
|---|
| 882 | case WM_DESTROY:
|
|---|
| 883 | win32wndproc(getWindowHandle(), WM_NCDESTROY, 0, 0);
|
|---|
| 884 | NotifyParent(Msg, wParam, lParam);
|
|---|
| 885 | return win32wndproc(getWindowHandle(), WM_DESTROY, 0, 0);
|
|---|
| 886 | default:
|
|---|
| 887 | return win32wndproc(getWindowHandle(), Msg, wParam, lParam);
|
|---|
| 888 | }
|
|---|
| 889 | }
|
|---|
| 890 | //******************************************************************************
|
|---|
| 891 | //******************************************************************************
|
|---|
| 892 | LRESULT Win32Window::SendMessageW(ULONG Msg, WPARAM wParam, LPARAM lParam)
|
|---|
| 893 | {
|
|---|
| 894 | if(PostSpyMessage(getWindowHandle(), Msg, wParam, lParam) == FALSE)
|
|---|
| 895 | dprintf(("SendMessageA %s for %x %x %x", GetMsgText(Msg), getWindowHandle(), wParam, lParam));
|
|---|
| 896 |
|
|---|
| 897 | if(HkCBT::OS2HkCBTProc(getWindowHandle(), Msg, wParam, lParam) == TRUE) {//hook swallowed msg
|
|---|
| 898 | return(0);
|
|---|
| 899 | }
|
|---|
| 900 | switch(Msg)
|
|---|
| 901 | {
|
|---|
| 902 | case WM_CREATE:
|
|---|
| 903 | {
|
|---|
| 904 | if(win32wndproc(getWindowHandle(), WM_NCCREATE, 0, lParam) == 0) {
|
|---|
| 905 | dprintf(("WM_NCCREATE returned FALSE\n"));
|
|---|
| 906 | return(0); //don't create window
|
|---|
| 907 | }
|
|---|
| 908 | if(win32wndproc(getWindowHandle(), WM_CREATE, 0, lParam) == 0) {
|
|---|
| 909 | dprintf(("WM_CREATE returned FALSE\n"));
|
|---|
| 910 | return(0); //don't create window
|
|---|
| 911 | }
|
|---|
| 912 | NotifyParent(Msg, wParam, lParam);
|
|---|
| 913 |
|
|---|
| 914 | return(1);
|
|---|
| 915 | }
|
|---|
| 916 | case WM_LBUTTONDOWN:
|
|---|
| 917 | case WM_MBUTTONDOWN:
|
|---|
| 918 | case WM_RBUTTONDOWN:
|
|---|
| 919 | NotifyParent(Msg, wParam, lParam);
|
|---|
| 920 | return win32wndproc(getWindowHandle(), Msg, wParam, lParam);
|
|---|
| 921 |
|
|---|
| 922 | case WM_DESTROY:
|
|---|
| 923 | win32wndproc(getWindowHandle(), WM_NCDESTROY, 0, 0);
|
|---|
| 924 | NotifyParent(Msg, wParam, lParam);
|
|---|
| 925 | return win32wndproc(getWindowHandle(), WM_DESTROY, 0, 0);
|
|---|
| 926 |
|
|---|
| 927 | default:
|
|---|
| 928 | return win32wndproc(getWindowHandle(), Msg, wParam, lParam);
|
|---|
| 929 | }
|
|---|
| 930 | }
|
|---|
| 931 | //******************************************************************************
|
|---|
| 932 | //Called as a result of an OS/2 message
|
|---|
| 933 | //******************************************************************************
|
|---|
| 934 | LRESULT Win32Window::SendInternalMessageA(ULONG Msg, WPARAM wParam, LPARAM lParam)
|
|---|
| 935 | {
|
|---|
| 936 | if(PostSpyMessage(getWindowHandle(), Msg, wParam, lParam) == FALSE)
|
|---|
| 937 | dprintf(("SendInternalMessageA %s for %x %x %x", GetMsgText(Msg), getWindowHandle(), wParam, lParam));
|
|---|
| 938 |
|
|---|
| 939 | if(HkCBT::OS2HkCBTProc(getWindowHandle(), Msg, wParam, lParam) == TRUE) {//hook swallowed msg
|
|---|
| 940 | return(0);
|
|---|
| 941 | }
|
|---|
| 942 | switch(Msg)
|
|---|
| 943 | {
|
|---|
| 944 | case WM_CREATE:
|
|---|
| 945 | {
|
|---|
| 946 | if(win32wndproc(getWindowHandle(), WM_NCCREATE, 0, lParam) == 0) {
|
|---|
| 947 | dprintf(("WM_NCCREATE returned FALSE\n"));
|
|---|
| 948 | return(0); //don't create window
|
|---|
| 949 | }
|
|---|
| 950 | if(win32wndproc(getWindowHandle(), WM_CREATE, 0, lParam) == 0) {
|
|---|
| 951 | dprintf(("WM_CREATE returned FALSE\n"));
|
|---|
| 952 | return(0); //don't create window
|
|---|
| 953 | }
|
|---|
| 954 | NotifyParent(Msg, wParam, lParam);
|
|---|
| 955 |
|
|---|
| 956 | return(1);
|
|---|
| 957 | }
|
|---|
| 958 | case WM_LBUTTONDOWN:
|
|---|
| 959 | case WM_MBUTTONDOWN:
|
|---|
| 960 | case WM_RBUTTONDOWN:
|
|---|
| 961 | NotifyParent(Msg, wParam, lParam);
|
|---|
| 962 | return win32wndproc(getWindowHandle(), Msg, wParam, lParam);
|
|---|
| 963 |
|
|---|
| 964 | case WM_DESTROY:
|
|---|
| 965 | win32wndproc(getWindowHandle(), WM_NCDESTROY, 0, 0);
|
|---|
| 966 | NotifyParent(Msg, wParam, lParam);
|
|---|
| 967 | return win32wndproc(getWindowHandle(), WM_DESTROY, 0, 0);
|
|---|
| 968 | default:
|
|---|
| 969 | return win32wndproc(getWindowHandle(), Msg, wParam, lParam);
|
|---|
| 970 | }
|
|---|
| 971 | }
|
|---|
| 972 | //******************************************************************************
|
|---|
| 973 | //Called as a result of an OS/2 message
|
|---|
| 974 | //todo, unicode msgs (WM_SETTEXT etc)
|
|---|
| 975 | //******************************************************************************
|
|---|
| 976 | LRESULT Win32Window::SendInternalMessageW(ULONG Msg, WPARAM wParam, LPARAM lParam)
|
|---|
| 977 | {
|
|---|
| 978 | if(PostSpyMessage(getWindowHandle(), Msg, wParam, lParam) == FALSE)
|
|---|
| 979 | dprintf(("SendInternalMessageW %s for %x %x %x", GetMsgText(Msg), getWindowHandle(), wParam, lParam));
|
|---|
| 980 |
|
|---|
| 981 | if(HkCBT::OS2HkCBTProc(getWindowHandle(), Msg, wParam, lParam) == TRUE) {//hook swallowed msg
|
|---|
| 982 | return(0);
|
|---|
| 983 | }
|
|---|
| 984 | switch(Msg)
|
|---|
| 985 | {
|
|---|
| 986 | case WM_CREATE:
|
|---|
| 987 | {
|
|---|
| 988 | if(win32wndproc(getWindowHandle(), WM_NCCREATE, 0, lParam) == 0) {
|
|---|
| 989 | dprintf(("WM_NCCREATE returned FALSE\n"));
|
|---|
| 990 | return(0); //don't create window
|
|---|
| 991 | }
|
|---|
| 992 | if(win32wndproc(getWindowHandle(), WM_CREATE, 0, lParam) == 0) {
|
|---|
| 993 | dprintf(("WM_CREATE returned FALSE\n"));
|
|---|
| 994 | return(0); //don't create window
|
|---|
| 995 | }
|
|---|
| 996 | NotifyParent(Msg, wParam, lParam);
|
|---|
| 997 |
|
|---|
| 998 | return(1);
|
|---|
| 999 | }
|
|---|
| 1000 | case WM_LBUTTONDOWN:
|
|---|
| 1001 | case WM_MBUTTONDOWN:
|
|---|
| 1002 | case WM_RBUTTONDOWN:
|
|---|
| 1003 | NotifyParent(Msg, wParam, lParam);
|
|---|
| 1004 | return win32wndproc(getWindowHandle(), Msg, wParam, lParam);
|
|---|
| 1005 |
|
|---|
| 1006 | case WM_DESTROY:
|
|---|
| 1007 | win32wndproc(getWindowHandle(), WM_NCDESTROY, 0, 0);
|
|---|
| 1008 | NotifyParent(Msg, wParam, lParam);
|
|---|
| 1009 | return win32wndproc(getWindowHandle(), WM_DESTROY, 0, 0);
|
|---|
| 1010 | default:
|
|---|
| 1011 | return win32wndproc(getWindowHandle(), Msg, wParam, lParam);
|
|---|
| 1012 | }
|
|---|
| 1013 | }
|
|---|
| 1014 | //******************************************************************************
|
|---|
| 1015 | //******************************************************************************
|
|---|
| 1016 | BOOL Win32Window::PostMessageA(ULONG msg, WPARAM wParam, LPARAM lParam)
|
|---|
| 1017 | {
|
|---|
| 1018 | POSTMSG_PACKET *postmsg;
|
|---|
| 1019 |
|
|---|
| 1020 | postmsg = (POSTMSG_PACKET *)malloc(sizeof(POSTMSG_PACKET));
|
|---|
| 1021 | if(postmsg == NULL) {
|
|---|
| 1022 | dprintf(("Win32Window::PostMessageA: malloc returned NULL!!"));
|
|---|
| 1023 | return 0;
|
|---|
| 1024 | }
|
|---|
| 1025 | postmsg->Msg = msg;
|
|---|
| 1026 | postmsg->wParam = wParam;
|
|---|
| 1027 | postmsg->lParam = lParam;
|
|---|
| 1028 | return OSLibPostMessage(OS2Hwnd, WM_WIN32_POSTMESSAGEA, (ULONG)postmsg, 0);
|
|---|
| 1029 | }
|
|---|
| 1030 | //******************************************************************************
|
|---|
| 1031 | //******************************************************************************
|
|---|
| 1032 | BOOL Win32Window::PostMessageW(ULONG msg, WPARAM wParam, LPARAM lParam)
|
|---|
| 1033 | {
|
|---|
| 1034 | POSTMSG_PACKET *postmsg;
|
|---|
| 1035 |
|
|---|
| 1036 | postmsg = (POSTMSG_PACKET *)malloc(sizeof(POSTMSG_PACKET));
|
|---|
| 1037 | if(postmsg == NULL) {
|
|---|
| 1038 | dprintf(("Win32Window::PostMessageW: malloc returned NULL!!"));
|
|---|
| 1039 | return 0;
|
|---|
| 1040 | }
|
|---|
| 1041 | postmsg->Msg = msg;
|
|---|
| 1042 | postmsg->wParam = wParam;
|
|---|
| 1043 | postmsg->lParam = lParam;
|
|---|
| 1044 | return OSLibPostMessage(OS2Hwnd, WM_WIN32_POSTMESSAGEW, (ULONG)postmsg, 0);
|
|---|
| 1045 | }
|
|---|
| 1046 | //******************************************************************************
|
|---|
| 1047 | //TODO: do we need to inform the parent of the parent (etc) of the child window?
|
|---|
| 1048 | //******************************************************************************
|
|---|
| 1049 | void Win32Window::NotifyParent(UINT Msg, WPARAM wParam, LPARAM lParam)
|
|---|
| 1050 | {
|
|---|
| 1051 | Win32Window *window = this;
|
|---|
| 1052 | Win32Window *parentwindow;
|
|---|
| 1053 |
|
|---|
| 1054 | while(window)
|
|---|
| 1055 | {
|
|---|
| 1056 | if(window->getStyle() & WS_CHILD && !(window->getExStyle() & WS_EX_NOPARENTNOTIFY) )
|
|---|
| 1057 | {
|
|---|
| 1058 | /* Notify the parent window only */
|
|---|
| 1059 | parentwindow = window->getParent();
|
|---|
| 1060 | if(parentwindow) {
|
|---|
| 1061 | if(Msg == WM_CREATE || Msg == WM_DESTROY) {
|
|---|
| 1062 | parentwindow->SendInternalMessageA(WM_PARENTNOTIFY, MAKEWPARAM(Msg, window->getWindowId()), (LPARAM)window->getWindowHandle());
|
|---|
| 1063 | }
|
|---|
| 1064 | else parentwindow->SendInternalMessageA(WM_PARENTNOTIFY, MAKEWPARAM(Msg, window->getWindowId()), lParam );
|
|---|
| 1065 | }
|
|---|
| 1066 | }
|
|---|
| 1067 | else break;
|
|---|
| 1068 |
|
|---|
| 1069 | window = parentwindow;
|
|---|
| 1070 | }
|
|---|
| 1071 | }
|
|---|
| 1072 | //******************************************************************************
|
|---|
| 1073 | //******************************************************************************
|
|---|
| 1074 | BOOL Win32Window::SetMenu(HMENU hMenu)
|
|---|
| 1075 | {
|
|---|
| 1076 | PVOID menutemplate;
|
|---|
| 1077 | Win32Resource *winres = (Win32Resource *)hMenu;
|
|---|
| 1078 |
|
|---|
| 1079 | if(HIWORD(winres) == 0) {
|
|---|
| 1080 | dprintf(("Win32Window:: Win32Resource *winres == 0"));
|
|---|
| 1081 | SetLastError(ERROR_INVALID_PARAMETER);
|
|---|
| 1082 | return FALSE;
|
|---|
| 1083 | }
|
|---|
| 1084 | menutemplate = winres->lockOS2Resource();
|
|---|
| 1085 | if(menutemplate == NULL)
|
|---|
| 1086 | {
|
|---|
| 1087 | dprintf(("Win32Window::SetMenu menutemplate == 0"));
|
|---|
| 1088 | return FALSE;
|
|---|
| 1089 | }
|
|---|
| 1090 | OS2HwndMenu = OSLibWinCreateMenu(OS2HwndFrame, menutemplate);
|
|---|
| 1091 | if(OS2HwndMenu == 0) {
|
|---|
| 1092 | dprintf(("Win32Window::SetMenu OS2HwndMenu == 0"));
|
|---|
| 1093 | return FALSE;
|
|---|
| 1094 | }
|
|---|
| 1095 | menuResource = winres;
|
|---|
| 1096 | return TRUE;
|
|---|
| 1097 | }
|
|---|
| 1098 | //******************************************************************************
|
|---|
| 1099 | //******************************************************************************
|
|---|
| 1100 | BOOL Win32Window::SetAccelTable(HACCEL hAccel)
|
|---|
| 1101 | {
|
|---|
| 1102 | Win32Resource *winres = (Win32Resource *)hAccel;
|
|---|
| 1103 | HANDLE accelhandle;
|
|---|
| 1104 |
|
|---|
| 1105 | if(HIWORD(hAccel) == 0) {
|
|---|
| 1106 | dprintf(("SetAccelTable: hAccel %x invalid", hAccel));
|
|---|
| 1107 | SetLastError(ERROR_INVALID_PARAMETER);
|
|---|
| 1108 | return FALSE;
|
|---|
| 1109 | }
|
|---|
| 1110 | acceltableResource = winres;
|
|---|
| 1111 | accelhandle = OSLibWinSetAccelTable(OS2HwndFrame, winres->getOS2Handle(), winres->lockOS2Resource());
|
|---|
| 1112 | winres->setOS2Handle(accelhandle);
|
|---|
| 1113 | return(accelhandle != 0);
|
|---|
| 1114 | }
|
|---|
| 1115 | //******************************************************************************
|
|---|
| 1116 | //******************************************************************************
|
|---|
| 1117 | BOOL Win32Window::SetIcon(HICON hIcon)
|
|---|
| 1118 | {
|
|---|
| 1119 | Win32Resource *winres = (Win32Resource *)hIcon;
|
|---|
| 1120 | HANDLE iconhandle;
|
|---|
| 1121 |
|
|---|
| 1122 | if(HIWORD(hIcon) == 0) {
|
|---|
| 1123 | dprintf(("SetIcon: hIcon %x invalid", hIcon));
|
|---|
| 1124 | SetLastError(ERROR_INVALID_PARAMETER);
|
|---|
| 1125 | return FALSE;
|
|---|
| 1126 | }
|
|---|
| 1127 | dprintf(("Win32Window::SetIcon %x", hIcon));
|
|---|
| 1128 | iconResource = winres;
|
|---|
| 1129 | iconhandle = OSLibWinSetIcon(OS2HwndFrame, winres->getOS2Handle(), winres->lockOS2Resource());
|
|---|
| 1130 | winres->setOS2Handle(iconhandle);
|
|---|
| 1131 | return(iconhandle != 0);
|
|---|
| 1132 | }
|
|---|
| 1133 | //******************************************************************************
|
|---|
| 1134 | //******************************************************************************
|
|---|
| 1135 | BOOL Win32Window::ShowWindow(ULONG nCmdShow)
|
|---|
| 1136 | {
|
|---|
| 1137 | ULONG showstate = 0;
|
|---|
| 1138 |
|
|---|
| 1139 | dprintf(("ShowWindow %x", nCmdShow));
|
|---|
| 1140 | switch(nCmdShow)
|
|---|
| 1141 | {
|
|---|
| 1142 | case SW_SHOW:
|
|---|
| 1143 | case SW_SHOWDEFAULT: //todo
|
|---|
| 1144 | showstate = SWPOS_SHOW | SWPOS_ACTIVATE;
|
|---|
| 1145 | break;
|
|---|
| 1146 | case SW_HIDE:
|
|---|
| 1147 | showstate = SWPOS_HIDE;
|
|---|
| 1148 | break;
|
|---|
| 1149 | case SW_RESTORE:
|
|---|
| 1150 | showstate = SWPOS_RESTORE | SWPOS_SHOW | SWPOS_ACTIVATE;
|
|---|
| 1151 | break;
|
|---|
| 1152 | case SW_MINIMIZE:
|
|---|
| 1153 | showstate = SWPOS_MINIMIZE;
|
|---|
| 1154 | break;
|
|---|
| 1155 | case SW_SHOWMAXIMIZED:
|
|---|
| 1156 | showstate = SWPOS_MAXIMIZE | SWPOS_SHOW | SWPOS_ACTIVATE;
|
|---|
| 1157 | break;
|
|---|
| 1158 | case SW_SHOWMINIMIZED:
|
|---|
| 1159 | showstate = SWPOS_MINIMIZE | SWPOS_SHOW | SWPOS_ACTIVATE;
|
|---|
| 1160 | break;
|
|---|
| 1161 | case SW_SHOWMINNOACTIVE:
|
|---|
| 1162 | showstate = SWPOS_MINIMIZE | SWPOS_SHOW;
|
|---|
| 1163 | break;
|
|---|
| 1164 | case SW_SHOWNA:
|
|---|
| 1165 | showstate = SWPOS_SHOW;
|
|---|
| 1166 | break;
|
|---|
| 1167 | case SW_SHOWNOACTIVATE:
|
|---|
| 1168 | showstate = SWPOS_SHOW;
|
|---|
| 1169 | break;
|
|---|
| 1170 | case SW_SHOWNORMAL:
|
|---|
| 1171 | showstate = SWPOS_RESTORE | SWPOS_ACTIVATE | SWPOS_SHOW;
|
|---|
| 1172 | break;
|
|---|
| 1173 | }
|
|---|
| 1174 | return OSLibWinShowWindow(OS2HwndFrame, showstate);
|
|---|
| 1175 | }
|
|---|
| 1176 | //******************************************************************************
|
|---|
| 1177 | //******************************************************************************
|
|---|
| 1178 | BOOL Win32Window::SetWindowPos(HWND hwndInsertAfter, int x, int y, int cx, int cy, UINT fuFlags)
|
|---|
| 1179 | {
|
|---|
| 1180 | Win32Window *window;
|
|---|
| 1181 | ULONG setstate = 0;
|
|---|
| 1182 |
|
|---|
| 1183 | switch(hwndInsertAfter) {
|
|---|
| 1184 | case HWND_BOTTOM:
|
|---|
| 1185 | hwndInsertAfter = HWNDOS_BOTTOM;
|
|---|
| 1186 | break;
|
|---|
| 1187 | case HWND_TOPMOST: //TODO:
|
|---|
| 1188 | case HWND_NOTOPMOST: //TODO:
|
|---|
| 1189 | case HWND_TOP:
|
|---|
| 1190 | hwndInsertAfter = HWNDOS_TOP;
|
|---|
| 1191 | break;
|
|---|
| 1192 | default:
|
|---|
| 1193 | window = GetWindowFromHandle(hwndInsertAfter);
|
|---|
| 1194 | if(window) {
|
|---|
| 1195 | hwndInsertAfter = window->getOS2WindowHandle();
|
|---|
| 1196 | }
|
|---|
| 1197 | else {
|
|---|
| 1198 | dprintf(("Win32Window::SetWindowPos, unknown hwndInsertAfter %x", hwndInsertAfter));
|
|---|
| 1199 | hwndInsertAfter = 0;
|
|---|
| 1200 | }
|
|---|
| 1201 | break;
|
|---|
| 1202 |
|
|---|
| 1203 | }
|
|---|
| 1204 | setstate = SWPOS_MOVE | SWPOS_SIZE | SWPOS_ACTIVATE | SWPOS_ZORDER;
|
|---|
| 1205 | if(fuFlags & SWP_DRAWFRAME)
|
|---|
| 1206 | setstate |= 0; //TODO
|
|---|
| 1207 | if(fuFlags & SWP_FRAMECHANGED)
|
|---|
| 1208 | setstate |= 0; //TODO
|
|---|
| 1209 | if(fuFlags & SWP_HIDEWINDOW)
|
|---|
| 1210 | setstate &= ~SWPOS_ZORDER;
|
|---|
| 1211 | if(fuFlags & SWP_NOACTIVATE)
|
|---|
| 1212 | setstate &= ~SWPOS_ACTIVATE;
|
|---|
| 1213 | if(fuFlags & SWP_NOCOPYBITS)
|
|---|
| 1214 | setstate |= 0; //TODO
|
|---|
| 1215 | if(fuFlags & SWP_NOMOVE)
|
|---|
| 1216 | setstate &= ~SWPOS_MOVE;
|
|---|
| 1217 | if(fuFlags & SWP_NOSIZE)
|
|---|
| 1218 | setstate &= ~SWPOS_SIZE;
|
|---|
| 1219 | if(fuFlags & SWP_NOREDRAW)
|
|---|
| 1220 | setstate |= SWPOS_NOREDRAW;
|
|---|
| 1221 | if(fuFlags & SWP_NOZORDER)
|
|---|
| 1222 | setstate &= ~SWPOS_ZORDER;
|
|---|
| 1223 | if(fuFlags & SWP_SHOWWINDOW)
|
|---|
| 1224 | setstate |= SWPOS_SHOW;
|
|---|
| 1225 |
|
|---|
| 1226 | return OSLibWinSetWindowPos(OS2HwndFrame, hwndInsertAfter, x, y, cx, cy, setstate);
|
|---|
| 1227 | }
|
|---|
| 1228 | //******************************************************************************
|
|---|
| 1229 | //Also destroys all the child windows (destroy parent, destroy children)
|
|---|
| 1230 | //******************************************************************************
|
|---|
| 1231 | BOOL Win32Window::DestroyWindow()
|
|---|
| 1232 | {
|
|---|
| 1233 | return OSLibWinDestroyWindow(OS2HwndFrame);
|
|---|
| 1234 | }
|
|---|
| 1235 | //******************************************************************************
|
|---|
| 1236 | //******************************************************************************
|
|---|
| 1237 | HWND Win32Window::GetParent()
|
|---|
| 1238 | {
|
|---|
| 1239 | if(getParent()) {
|
|---|
| 1240 | return getParent()->getWindowHandle();
|
|---|
| 1241 | }
|
|---|
| 1242 | else return 0;
|
|---|
| 1243 | }
|
|---|
| 1244 | //******************************************************************************
|
|---|
| 1245 | //******************************************************************************
|
|---|
| 1246 | HWND Win32Window::SetParent(HWND hwndNewParent)
|
|---|
| 1247 | {
|
|---|
| 1248 | HWND oldhwnd;
|
|---|
| 1249 | Win32Window *newparent;
|
|---|
| 1250 |
|
|---|
| 1251 | if(getParent()) {
|
|---|
| 1252 | oldhwnd = getParent()->getWindowHandle();
|
|---|
| 1253 | }
|
|---|
| 1254 | else oldhwnd = 0;
|
|---|
| 1255 |
|
|---|
| 1256 | if(hwndNewParent == 0) {//desktop window = parent
|
|---|
| 1257 | setParent(NULL);
|
|---|
| 1258 | OSLibWinSetParent(getOS2WindowHandle(), OSLIB_HWND_DESKTOP);
|
|---|
| 1259 | return oldhwnd;
|
|---|
| 1260 | }
|
|---|
| 1261 | newparent = GetWindowFromHandle(hwndNewParent);
|
|---|
| 1262 | if(newparent)
|
|---|
| 1263 | {
|
|---|
| 1264 | setParent(newparent);
|
|---|
| 1265 | OSLibWinSetParent(getOS2WindowHandle(), getParent()->getOS2WindowHandle());
|
|---|
| 1266 | return oldhwnd;
|
|---|
| 1267 | }
|
|---|
| 1268 | SetLastError(ERROR_INVALID_PARAMETER);
|
|---|
| 1269 | return 0;
|
|---|
| 1270 | }
|
|---|
| 1271 | //******************************************************************************
|
|---|
| 1272 | //******************************************************************************
|
|---|
| 1273 | BOOL Win32Window::IsChild(HWND hwndParent)
|
|---|
| 1274 | {
|
|---|
| 1275 | if(getParent()) {
|
|---|
| 1276 | return getParent()->getWindowHandle() == hwndParent;
|
|---|
| 1277 | }
|
|---|
| 1278 | else return 0;
|
|---|
| 1279 | }
|
|---|
| 1280 | //******************************************************************************
|
|---|
| 1281 | //******************************************************************************
|
|---|
| 1282 | HWND Win32Window::GetTopWindow()
|
|---|
| 1283 | {
|
|---|
| 1284 | return GetWindow(GW_CHILD);
|
|---|
| 1285 | }
|
|---|
| 1286 | //******************************************************************************
|
|---|
| 1287 | //Don't call WinUpdateWindow as that one also updates the child windows
|
|---|
| 1288 | //Also need to send WM_PAINT directly to the window procedure, which doesn't
|
|---|
| 1289 | //always happen with WinUpdateWindow (could be posted if thread doesn't own window)
|
|---|
| 1290 | //******************************************************************************
|
|---|
| 1291 | BOOL Win32Window::UpdateWindow()
|
|---|
| 1292 | {
|
|---|
| 1293 | RECT rect;
|
|---|
| 1294 |
|
|---|
| 1295 | if(OSLibWinQueryUpdateRect(OS2Hwnd, &rect))
|
|---|
| 1296 | {//update region not empty
|
|---|
| 1297 | SendInternalMessageA((isIcon) ? WM_PAINTICON : WM_PAINT, 0, 0);
|
|---|
| 1298 | }
|
|---|
| 1299 | return TRUE;
|
|---|
| 1300 | }
|
|---|
| 1301 | //******************************************************************************
|
|---|
| 1302 | //******************************************************************************
|
|---|
| 1303 | BOOL Win32Window::IsIconic()
|
|---|
| 1304 | {
|
|---|
| 1305 | return OSLibWinIsIconic(OS2Hwnd);
|
|---|
| 1306 | }
|
|---|
| 1307 | //******************************************************************************
|
|---|
| 1308 | //TODO: not complete nor correct (distinction between top-level, top-most & child windows)
|
|---|
| 1309 | //******************************************************************************
|
|---|
| 1310 | HWND Win32Window::GetWindow(UINT uCmd)
|
|---|
| 1311 | {
|
|---|
| 1312 | Win32Window *win32wnd;
|
|---|
| 1313 | ULONG magic;
|
|---|
| 1314 | ULONG getcmd = 0;
|
|---|
| 1315 | HWND hwndRelated;
|
|---|
| 1316 |
|
|---|
| 1317 | dprintf(("GetWindow %x %d NOT COMPLETE", getWindowHandle(), uCmd));
|
|---|
| 1318 | switch(uCmd)
|
|---|
| 1319 | {
|
|---|
| 1320 | case GW_CHILD:
|
|---|
| 1321 | getcmd = QWOS_TOP;
|
|---|
| 1322 | break;
|
|---|
| 1323 | case GW_HWNDFIRST:
|
|---|
| 1324 | if(getParent()) {
|
|---|
| 1325 | getcmd = QWOS_TOP; //top of child windows
|
|---|
| 1326 | }
|
|---|
| 1327 | else getcmd = QWOS_TOP; //TODO
|
|---|
| 1328 | break;
|
|---|
| 1329 | case GW_HWNDLAST:
|
|---|
| 1330 | if(getParent()) {
|
|---|
| 1331 | getcmd = QWOS_BOTTOM; //bottom of child windows
|
|---|
| 1332 | }
|
|---|
| 1333 | else getcmd = QWOS_BOTTOM; //TODO
|
|---|
| 1334 | break;
|
|---|
| 1335 | case GW_HWNDNEXT:
|
|---|
| 1336 | getcmd = QWOS_NEXT;
|
|---|
| 1337 | break;
|
|---|
| 1338 | case GW_HWNDPREV:
|
|---|
| 1339 | getcmd = QWOS_PREV;
|
|---|
| 1340 | break;
|
|---|
| 1341 | case GW_OWNER:
|
|---|
| 1342 | if(owner) {
|
|---|
| 1343 | return owner->getWindowHandle();
|
|---|
| 1344 | }
|
|---|
| 1345 | else return 0;
|
|---|
| 1346 | }
|
|---|
| 1347 | hwndRelated = OSLibWinQueryWindow(OS2Hwnd, getcmd);
|
|---|
| 1348 | if(hwndRelated)
|
|---|
| 1349 | {
|
|---|
| 1350 | win32wnd = (Win32Window *)OSLibWinGetWindowULong(hwndRelated, OFFSET_WIN32WNDPTR);
|
|---|
| 1351 | magic = OSLibWinGetWindowULong(hwndRelated, OFFSET_WIN32PM_MAGIC);
|
|---|
| 1352 | if(CheckMagicDword(magic) && win32wnd)
|
|---|
| 1353 | {
|
|---|
| 1354 | return win32wnd->getWindowHandle();
|
|---|
| 1355 | }
|
|---|
| 1356 | }
|
|---|
| 1357 | return 0;
|
|---|
| 1358 | }
|
|---|
| 1359 | //******************************************************************************
|
|---|
| 1360 | //******************************************************************************
|
|---|
| 1361 | HWND Win32Window::SetActiveWindow()
|
|---|
| 1362 | {
|
|---|
| 1363 | return OSLibWinSetActiveWindow(OS2Hwnd);
|
|---|
| 1364 | }
|
|---|
| 1365 | //******************************************************************************
|
|---|
| 1366 | //WM_ENABLE is sent to hwnd, but not to it's children (as it should be)
|
|---|
| 1367 | //******************************************************************************
|
|---|
| 1368 | BOOL Win32Window::EnableWindow(BOOL fEnable)
|
|---|
| 1369 | {
|
|---|
| 1370 | return OSLibWinEnableWindow(OS2Hwnd, fEnable);
|
|---|
| 1371 | }
|
|---|
| 1372 | //******************************************************************************
|
|---|
| 1373 | //******************************************************************************
|
|---|
| 1374 | BOOL Win32Window::CloseWindow()
|
|---|
| 1375 | {
|
|---|
| 1376 | return OSLibWinMinimizeWindow(OS2Hwnd);
|
|---|
| 1377 | }
|
|---|
| 1378 | //******************************************************************************
|
|---|
| 1379 | //******************************************************************************
|
|---|
| 1380 | BOOL Win32Window::BringWindowToTop()
|
|---|
| 1381 | {
|
|---|
| 1382 | return SetWindowPos(HWND_TOP, 0, 0, 0, 0, SWP_NOMOVE|SWP_NOSIZE );
|
|---|
| 1383 | }
|
|---|
| 1384 | //******************************************************************************
|
|---|
| 1385 | //******************************************************************************
|
|---|
| 1386 | HWND Win32Window::GetActiveWindow()
|
|---|
| 1387 | {
|
|---|
| 1388 | HWND hwndActive;
|
|---|
| 1389 | Win32Window *win32wnd;
|
|---|
| 1390 | ULONG magic;
|
|---|
| 1391 |
|
|---|
| 1392 | hwndActive = OSLibWinQueryActiveWindow();
|
|---|
| 1393 |
|
|---|
| 1394 | win32wnd = (Win32Window *)OSLibWinGetWindowULong(hwndActive, OFFSET_WIN32WNDPTR);
|
|---|
| 1395 | magic = OSLibWinGetWindowULong(hwndActive, OFFSET_WIN32PM_MAGIC);
|
|---|
| 1396 | if(CheckMagicDword(magic) && win32wnd)
|
|---|
| 1397 | {
|
|---|
| 1398 | return win32wnd->getWindowHandle();
|
|---|
| 1399 | }
|
|---|
| 1400 | return hwndActive;
|
|---|
| 1401 | }
|
|---|
| 1402 | //******************************************************************************
|
|---|
| 1403 | //******************************************************************************
|
|---|
| 1404 | BOOL Win32Window::IsWindow()
|
|---|
| 1405 | {
|
|---|
| 1406 | return TRUE;
|
|---|
| 1407 | }
|
|---|
| 1408 | //******************************************************************************
|
|---|
| 1409 | //******************************************************************************
|
|---|
| 1410 | BOOL Win32Window::IsWindowEnabled()
|
|---|
| 1411 | {
|
|---|
| 1412 | return OSLibWinIsWindowEnabled(OS2Hwnd);
|
|---|
| 1413 | }
|
|---|
| 1414 | //******************************************************************************
|
|---|
| 1415 | //******************************************************************************
|
|---|
| 1416 | BOOL Win32Window::IsWindowVisible()
|
|---|
| 1417 | {
|
|---|
| 1418 | return OSLibWinIsWindowVisible(OS2Hwnd);
|
|---|
| 1419 | }
|
|---|
| 1420 | //******************************************************************************
|
|---|
| 1421 | //******************************************************************************
|
|---|
| 1422 | BOOL Win32Window::GetWindowRect(PRECT pRect)
|
|---|
| 1423 | {
|
|---|
| 1424 | return OSLibWinQueryWindowRect(OS2Hwnd, pRect, RELATIVE_TO_SCREEN);
|
|---|
| 1425 | }
|
|---|
| 1426 | //******************************************************************************
|
|---|
| 1427 | //******************************************************************************
|
|---|
| 1428 | int Win32Window::GetWindowTextLengthA()
|
|---|
| 1429 | {
|
|---|
| 1430 | return OSLibWinQueryWindowTextLength(OS2Hwnd);
|
|---|
| 1431 | }
|
|---|
| 1432 | //******************************************************************************
|
|---|
| 1433 | //******************************************************************************
|
|---|
| 1434 | int Win32Window::GetWindowTextA(LPSTR lpsz, int cch)
|
|---|
| 1435 | {
|
|---|
| 1436 | return OSLibWinQueryWindowText(OS2Hwnd, cch, lpsz);
|
|---|
| 1437 | }
|
|---|
| 1438 | //******************************************************************************
|
|---|
| 1439 | //******************************************************************************
|
|---|
| 1440 | BOOL Win32Window::SetWindowTextA(LPCSTR lpsz)
|
|---|
| 1441 | {
|
|---|
| 1442 | return OSLibWinSetWindowText(OS2Hwnd, (LPSTR)lpsz);
|
|---|
| 1443 | }
|
|---|
| 1444 | //******************************************************************************
|
|---|
| 1445 | //******************************************************************************
|
|---|
| 1446 | LONG Win32Window::SetWindowLongA(int index, ULONG value)
|
|---|
| 1447 | {
|
|---|
| 1448 | LONG oldval;
|
|---|
| 1449 |
|
|---|
| 1450 | switch(index) {
|
|---|
| 1451 | case GWL_EXSTYLE:
|
|---|
| 1452 | oldval = dwExStyle;
|
|---|
| 1453 | dwExStyle = value;
|
|---|
| 1454 | return oldval;
|
|---|
| 1455 | case GWL_STYLE:
|
|---|
| 1456 | oldval = dwStyle;
|
|---|
| 1457 | dwStyle = value;
|
|---|
| 1458 | return oldval;
|
|---|
| 1459 | case GWL_WNDPROC:
|
|---|
| 1460 | oldval = (LONG)getWindowProc();
|
|---|
| 1461 | setWindowProc((WNDPROC)value);
|
|---|
| 1462 | return oldval;
|
|---|
| 1463 | case GWL_HINSTANCE:
|
|---|
| 1464 | oldval = hInstance;
|
|---|
| 1465 | hInstance = value;
|
|---|
| 1466 | return oldval;
|
|---|
| 1467 | case GWL_HWNDPARENT:
|
|---|
| 1468 | return SetParent((HWND)value);
|
|---|
| 1469 |
|
|---|
| 1470 | case GWL_ID:
|
|---|
| 1471 | oldval = getWindowId();
|
|---|
| 1472 | setWindowId(value);
|
|---|
| 1473 | return oldval;
|
|---|
| 1474 | case GWL_USERDATA:
|
|---|
| 1475 | oldval = userData;
|
|---|
| 1476 | userData = value;
|
|---|
| 1477 | return oldval;
|
|---|
| 1478 | default:
|
|---|
| 1479 | if(index >= 0 && index/4 < nrUserWindowLong)
|
|---|
| 1480 | {
|
|---|
| 1481 | oldval = userWindowLong[index/4];
|
|---|
| 1482 | userWindowLong[index/4] = value;
|
|---|
| 1483 | return oldval;
|
|---|
| 1484 | }
|
|---|
| 1485 | SetLastError(ERROR_INVALID_PARAMETER);
|
|---|
| 1486 | return 0;
|
|---|
| 1487 | }
|
|---|
| 1488 | }
|
|---|
| 1489 | //******************************************************************************
|
|---|
| 1490 | //******************************************************************************
|
|---|
| 1491 | ULONG Win32Window::GetWindowLongA(int index)
|
|---|
| 1492 | {
|
|---|
| 1493 | switch(index) {
|
|---|
| 1494 | case GWL_EXSTYLE:
|
|---|
| 1495 | return dwExStyle;
|
|---|
| 1496 | case GWL_STYLE:
|
|---|
| 1497 | return dwStyle;
|
|---|
| 1498 | case GWL_WNDPROC:
|
|---|
| 1499 | return (ULONG)getWindowProc();
|
|---|
| 1500 | case GWL_HINSTANCE:
|
|---|
| 1501 | return hInstance;
|
|---|
| 1502 | case GWL_HWNDPARENT:
|
|---|
| 1503 | if(getParent()) {
|
|---|
| 1504 | return getParent()->getWindowHandle();
|
|---|
| 1505 | }
|
|---|
| 1506 | else return 0;
|
|---|
| 1507 | case GWL_ID:
|
|---|
| 1508 | return getWindowId();
|
|---|
| 1509 | case GWL_USERDATA:
|
|---|
| 1510 | return userData;
|
|---|
| 1511 | default:
|
|---|
| 1512 | if(index >= 0 && index/4 < nrUserWindowLong)
|
|---|
| 1513 | {
|
|---|
| 1514 | return userWindowLong[index/4];
|
|---|
| 1515 | }
|
|---|
| 1516 | SetLastError(ERROR_INVALID_PARAMETER);
|
|---|
| 1517 | return 0;
|
|---|
| 1518 | }
|
|---|
| 1519 | }
|
|---|
| 1520 | //******************************************************************************
|
|---|
| 1521 | //******************************************************************************
|
|---|
| 1522 | WORD Win32Window::SetWindowWord(int index, WORD value)
|
|---|
| 1523 | {
|
|---|
| 1524 | WORD oldval;
|
|---|
| 1525 |
|
|---|
| 1526 | if(index >= 0 && index/4 < nrUserWindowLong)
|
|---|
| 1527 | {
|
|---|
| 1528 | oldval = ((WORD *)userWindowLong)[index/2];
|
|---|
| 1529 | ((WORD *)userWindowLong)[index/2] = value;
|
|---|
| 1530 | return oldval;
|
|---|
| 1531 | }
|
|---|
| 1532 | SetLastError(ERROR_INVALID_PARAMETER);
|
|---|
| 1533 | return 0;
|
|---|
| 1534 | }
|
|---|
| 1535 | //******************************************************************************
|
|---|
| 1536 | //******************************************************************************
|
|---|
| 1537 | WORD Win32Window::GetWindowWord(int index)
|
|---|
| 1538 | {
|
|---|
| 1539 | if(index >= 0 && index/4 < nrUserWindowLong)
|
|---|
| 1540 | {
|
|---|
| 1541 | return ((WORD *)userWindowLong)[index/2];
|
|---|
| 1542 | }
|
|---|
| 1543 | SetLastError(ERROR_INVALID_PARAMETER);
|
|---|
| 1544 | return 0;
|
|---|
| 1545 | }
|
|---|
| 1546 | //******************************************************************************
|
|---|
| 1547 | //******************************************************************************
|
|---|
| 1548 | Win32Window *Win32Window::GetWindowFromHandle(HWND hwnd)
|
|---|
| 1549 | {
|
|---|
| 1550 | Win32Window *window;
|
|---|
| 1551 |
|
|---|
| 1552 | if(HIWORD(hwnd) != 0x6800) {
|
|---|
| 1553 | return NULL;
|
|---|
| 1554 | }
|
|---|
| 1555 |
|
|---|
| 1556 | if(HMHandleTranslateToOS2(LOWORD(hwnd), (PULONG)&window) == NO_ERROR) {
|
|---|
| 1557 | return window;
|
|---|
| 1558 | }
|
|---|
| 1559 | else return NULL;
|
|---|
| 1560 | }
|
|---|
| 1561 | //******************************************************************************
|
|---|
| 1562 | //******************************************************************************
|
|---|
| 1563 | Win32Window *Win32Window::GetWindowFromOS2Handle(HWND hwnd)
|
|---|
| 1564 | {
|
|---|
| 1565 | Win32Window *win32wnd;
|
|---|
| 1566 | DWORD magic;
|
|---|
| 1567 |
|
|---|
| 1568 | win32wnd = (Win32Window *)OSLibWinGetWindowULong(hwnd, OFFSET_WIN32WNDPTR);
|
|---|
| 1569 | magic = OSLibWinGetWindowULong(hwnd, OFFSET_WIN32PM_MAGIC);
|
|---|
| 1570 |
|
|---|
| 1571 | if(win32wnd && CheckMagicDword(magic)) {
|
|---|
| 1572 | return win32wnd;
|
|---|
| 1573 | }
|
|---|
| 1574 | return 0;
|
|---|
| 1575 | }
|
|---|
| 1576 | //******************************************************************************
|
|---|
| 1577 | //******************************************************************************
|
|---|
| 1578 | GenericObject *Win32Window::windows = NULL;
|
|---|