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