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