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