1 | /* $Id: win32wbase.cpp,v 1.61 1999-10-23 16:45:23 cbratschi 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 "wndmsg.h"
|
---|
28 | #include "hooks.h"
|
---|
29 | #include "oslibwin.h"
|
---|
30 | #include "oslibutil.h"
|
---|
31 | #include "oslibgdi.h"
|
---|
32 | #include "oslibres.h"
|
---|
33 | #include "oslibmenu.h"
|
---|
34 | #include "oslibdos.h"
|
---|
35 | #include "syscolor.h"
|
---|
36 | #include "win32wndhandle.h"
|
---|
37 | #include "heapshared.h"
|
---|
38 | #include "dc.h"
|
---|
39 | #include "pmframe.h"
|
---|
40 | #include "win32wdesktop.h"
|
---|
41 | #include "pmwindow.h"
|
---|
42 | #include <wprocess.h>
|
---|
43 |
|
---|
44 | #define HAS_DLGFRAME(style,exStyle) \
|
---|
45 | (((exStyle) & WS_EX_DLGMODALFRAME) || \
|
---|
46 | (((style) & WS_DLGFRAME) && !((style) & WS_THICKFRAME)))
|
---|
47 |
|
---|
48 | #define HAS_THICKFRAME(style,exStyle) \
|
---|
49 | (((style) & WS_THICKFRAME) && \
|
---|
50 | !((exStyle) & WS_EX_DLGMODALFRAME))
|
---|
51 |
|
---|
52 | #define HAS_THINFRAME(style) \
|
---|
53 | (((style) & WS_BORDER) || !((style) & (WS_CHILD | WS_POPUP)))
|
---|
54 |
|
---|
55 | #define HAS_BIGFRAME(style,exStyle) \
|
---|
56 | (((style) & (WS_THICKFRAME | WS_DLGFRAME)) || \
|
---|
57 | ((exStyle) & WS_EX_DLGMODALFRAME))
|
---|
58 |
|
---|
59 | #define HAS_ANYFRAME(style,exStyle) \
|
---|
60 | (((style) & (WS_THICKFRAME | WS_DLGFRAME | WS_BORDER)) || \
|
---|
61 | ((exStyle) & WS_EX_DLGMODALFRAME) || \
|
---|
62 | !((style) & (WS_CHILD | WS_POPUP)))
|
---|
63 |
|
---|
64 | #define HAS_3DFRAME(exStyle) \
|
---|
65 | ((exStyle & WS_EX_CLIENTEDGE) || (exStyle & WS_EX_STATICEDGE) || (exStyle & WS_EX_WINDOWEDGE))
|
---|
66 |
|
---|
67 | #define HAS_BORDER(style, exStyle) \
|
---|
68 | ((style & WS_BORDER) || HAS_THICKFRAME(style) || HAS_DLGFRAME(style,exStyle))
|
---|
69 |
|
---|
70 | #define IS_OVERLAPPED(style) \
|
---|
71 | !(style & (WS_CHILD | WS_POPUP))
|
---|
72 |
|
---|
73 | /* bits in the dwKeyData */
|
---|
74 | #define KEYDATA_ALT 0x2000
|
---|
75 | #define KEYDATA_PREVSTATE 0x4000
|
---|
76 |
|
---|
77 | void PrintWindowStyle(DWORD dwStyle, DWORD dwExStyle);
|
---|
78 |
|
---|
79 | //******************************************************************************
|
---|
80 | //******************************************************************************
|
---|
81 | Win32BaseWindow::Win32BaseWindow(DWORD objType) : GenericObject(&windows, objType)
|
---|
82 | {
|
---|
83 | Init();
|
---|
84 | }
|
---|
85 | //******************************************************************************
|
---|
86 | //******************************************************************************
|
---|
87 | Win32BaseWindow::Win32BaseWindow(HWND os2Handle,VOID* win32WndProc) : GenericObject(&windows,OBJTYPE_WINDOW)
|
---|
88 | {
|
---|
89 | Init();
|
---|
90 | OS2Hwnd = OS2HwndFrame = os2Handle;
|
---|
91 | dwStyle = WS_VISIBLE;
|
---|
92 | setWindowProc((WNDPROC)win32WndProc);
|
---|
93 | fIsSubclassedOS2Wnd = TRUE;
|
---|
94 | fFirstShow = FALSE;
|
---|
95 |
|
---|
96 | //CB: replace by a secure method
|
---|
97 |
|
---|
98 | if(OSLibWinSetWindowULong(OS2Hwnd, OFFSET_WIN32WNDPTR, (ULONG)this) == FALSE) {
|
---|
99 | dprintf(("WM_CREATE: WinSetWindowULong %X failed!!", OS2Hwnd));
|
---|
100 | SetLastError(ERROR_OUTOFMEMORY); //TODO: Better error
|
---|
101 | return;
|
---|
102 | }
|
---|
103 | if(OSLibWinSetWindowULong(OS2Hwnd, OFFSET_WIN32PM_MAGIC, WIN32PM_MAGIC) == FALSE) {
|
---|
104 | dprintf(("WM_CREATE: WinSetWindowULong2 %X failed!!", OS2Hwnd));
|
---|
105 | SetLastError(ERROR_OUTOFMEMORY); //TODO: Better error
|
---|
106 | return;
|
---|
107 | }
|
---|
108 |
|
---|
109 | OSLibWinQueryWindowRect(OS2Hwnd,&rectWindow);
|
---|
110 | rectClient = rectWindow;
|
---|
111 | rectClient.bottom -= rectClient.top;
|
---|
112 | rectClient.top = 0;
|
---|
113 | rectClient.right -= rectClient.left;
|
---|
114 | rectClient.left = 0;
|
---|
115 |
|
---|
116 | setOldWndProc(SubclassWithDefHandler(OS2Hwnd));
|
---|
117 | }
|
---|
118 | //******************************************************************************
|
---|
119 | //******************************************************************************
|
---|
120 | Win32BaseWindow::Win32BaseWindow(CREATESTRUCTA *lpCreateStructA, ATOM classAtom, BOOL isUnicode)
|
---|
121 | : GenericObject(&windows, OBJTYPE_WINDOW), ChildWindow()
|
---|
122 | {
|
---|
123 | Init();
|
---|
124 | this->isUnicode = isUnicode;
|
---|
125 | CreateWindowExA(lpCreateStructA, classAtom);
|
---|
126 | }
|
---|
127 | //******************************************************************************
|
---|
128 | //******************************************************************************
|
---|
129 | void Win32BaseWindow::Init()
|
---|
130 | {
|
---|
131 | isUnicode = FALSE;
|
---|
132 | fIsSubclassedOS2Wnd = FALSE;
|
---|
133 | fFirstShow = TRUE;
|
---|
134 | fIsDialog = FALSE;
|
---|
135 | fInternalMsg = FALSE;
|
---|
136 | fNoSizeMsg = FALSE;
|
---|
137 | fIsDestroyed = FALSE;
|
---|
138 | fCreated = FALSE;
|
---|
139 |
|
---|
140 | windowNameA = NULL;
|
---|
141 | windowNameW = NULL;
|
---|
142 | wndNameLength = 0;
|
---|
143 |
|
---|
144 | userWindowLong = NULL;;
|
---|
145 | nrUserWindowLong = 0;
|
---|
146 |
|
---|
147 | magic = WIN32PM_MAGIC;
|
---|
148 | OS2Hwnd = 0;
|
---|
149 | OS2HwndFrame = 0;
|
---|
150 | OS2HwndMenu = 0;
|
---|
151 | Win32Hwnd = 0;
|
---|
152 |
|
---|
153 | if(HwAllocateWindowHandle(&Win32Hwnd, (ULONG)this) == FALSE)
|
---|
154 | {
|
---|
155 | dprintf(("Win32BaseWindow::Init HwAllocateWindowHandle failed!!"));
|
---|
156 | DebugInt3();
|
---|
157 | }
|
---|
158 |
|
---|
159 | posx = posy = 0;
|
---|
160 | width = height = 0;
|
---|
161 |
|
---|
162 | dwExStyle = 0;
|
---|
163 | dwStyle = 0;
|
---|
164 | win32wndproc = 0;
|
---|
165 | hInstance = 0;
|
---|
166 | windowId = 0xFFFFFFFF; //default = -1
|
---|
167 | userData = 0;
|
---|
168 |
|
---|
169 | pOldFrameProc = NULL;
|
---|
170 | borderWidth = 0;
|
---|
171 | borderHeight = 0;
|
---|
172 |
|
---|
173 | hwndLinkAfter = HWND_BOTTOM;
|
---|
174 | flags = 0;
|
---|
175 | isIcon = FALSE;
|
---|
176 | lastHitTestVal = 0;
|
---|
177 | owner = NULL;
|
---|
178 | windowClass = 0;
|
---|
179 |
|
---|
180 | acceltableResource = NULL;
|
---|
181 | iconResource = NULL;
|
---|
182 |
|
---|
183 | EraseBkgndFlag = TRUE;
|
---|
184 | PSEraseFlag = FALSE;
|
---|
185 | SupressEraseFlag = FALSE;
|
---|
186 |
|
---|
187 | horzScrollInfo = NULL;
|
---|
188 | vertScrollInfo = NULL;
|
---|
189 | hwndHorzScroll = 0;
|
---|
190 | hwndVertScroll = 0;
|
---|
191 |
|
---|
192 | ownDC = 0;
|
---|
193 | }
|
---|
194 | //******************************************************************************
|
---|
195 | //todo get rid of resources (menu, accel, icon etc)
|
---|
196 | //******************************************************************************
|
---|
197 | Win32BaseWindow::~Win32BaseWindow()
|
---|
198 | {
|
---|
199 | OSLibWinSetWindowULong(OS2Hwnd, OFFSET_WIN32WNDPTR, 0);
|
---|
200 | OSLibWinSetWindowULong(OS2Hwnd, OFFSET_WIN32PM_MAGIC, 0);
|
---|
201 |
|
---|
202 | if(getParent() && getParent()->getFirstChild() == this && getNextChild() == NULL)
|
---|
203 | {
|
---|
204 | //if we're the last child that's being destroyed and our
|
---|
205 | //parent window was also destroyed, then we delete the parent object
|
---|
206 | if(getParent()->IsWindowDestroyed())
|
---|
207 | {
|
---|
208 | dprintf(("Last Child (%x) destroyed, get rid of our parent window (%x)", getWindowHandle(), getParent()->getWindowHandle()));
|
---|
209 | delete getParent();
|
---|
210 | setParent(NULL); //or else we'll crash in the dtor of the ChildWindow class
|
---|
211 | }
|
---|
212 | }
|
---|
213 | if (isOwnDC())
|
---|
214 | releaseOwnDC (ownDC);
|
---|
215 |
|
---|
216 | if(Win32Hwnd)
|
---|
217 | HwFreeWindowHandle(Win32Hwnd);
|
---|
218 |
|
---|
219 | if(userWindowLong)
|
---|
220 | free(userWindowLong);
|
---|
221 | if(windowNameA) {
|
---|
222 | free(windowNameA);
|
---|
223 | windowNameA = NULL;
|
---|
224 | }
|
---|
225 | if(windowNameW) {
|
---|
226 | free(windowNameW);
|
---|
227 | windowNameW = NULL;
|
---|
228 | }
|
---|
229 | if(vertScrollInfo) {
|
---|
230 | free(vertScrollInfo);
|
---|
231 | vertScrollInfo = NULL;
|
---|
232 | }
|
---|
233 | if(horzScrollInfo) {
|
---|
234 | free(horzScrollInfo);
|
---|
235 | horzScrollInfo = NULL;
|
---|
236 | }
|
---|
237 | }
|
---|
238 | //******************************************************************************
|
---|
239 | //******************************************************************************
|
---|
240 | BOOL Win32BaseWindow::isChild()
|
---|
241 | {
|
---|
242 | return ((dwStyle & WS_CHILD) != 0);
|
---|
243 | }
|
---|
244 | //******************************************************************************
|
---|
245 | //******************************************************************************
|
---|
246 | BOOL Win32BaseWindow::CreateWindowExA(CREATESTRUCTA *cs, ATOM classAtom)
|
---|
247 | {
|
---|
248 | char buffer[256];
|
---|
249 | POINT maxSize, maxPos, minTrack, maxTrack;
|
---|
250 |
|
---|
251 | #ifdef DEBUG
|
---|
252 | PrintWindowStyle(cs->style, cs->dwExStyle);
|
---|
253 | #endif
|
---|
254 |
|
---|
255 | sw = SW_SHOW;
|
---|
256 | SetLastError(0);
|
---|
257 |
|
---|
258 | /* Find the parent window */
|
---|
259 | if (cs->hwndParent)
|
---|
260 | {
|
---|
261 | Win32BaseWindow *window = GetWindowFromHandle(cs->hwndParent);
|
---|
262 | if(!window) {
|
---|
263 | dprintf(("Bad parent %04x\n", cs->hwndParent ));
|
---|
264 | SetLastError(ERROR_INVALID_PARAMETER);
|
---|
265 | return FALSE;
|
---|
266 | }
|
---|
267 | /* Make sure parent is valid */
|
---|
268 | if (!window->IsWindow() )
|
---|
269 | {
|
---|
270 | dprintf(("Bad parent %04x\n", cs->hwndParent ));
|
---|
271 | SetLastError(ERROR_INVALID_PARAMETER);
|
---|
272 | return FALSE;
|
---|
273 | }
|
---|
274 | }
|
---|
275 | else
|
---|
276 | if ((cs->style & WS_CHILD) && !(cs->style & WS_POPUP)) {
|
---|
277 | dprintf(("No parent for child window\n" ));
|
---|
278 | SetLastError(ERROR_INVALID_PARAMETER);
|
---|
279 | return FALSE; /* WS_CHILD needs a parent, but WS_POPUP doesn't */
|
---|
280 | }
|
---|
281 |
|
---|
282 | /* Find the window class */
|
---|
283 | windowClass = Win32WndClass::FindClass(cs->hInstance, (LPSTR)classAtom);
|
---|
284 | if (!windowClass)
|
---|
285 | {
|
---|
286 | GlobalGetAtomNameA( classAtom, buffer, sizeof(buffer) );
|
---|
287 | dprintf(("Bad class '%s'\n", buffer ));
|
---|
288 | SetLastError(ERROR_INVALID_PARAMETER);
|
---|
289 | return 0;
|
---|
290 | }
|
---|
291 | #ifdef DEBUG
|
---|
292 | if(HIWORD(cs->lpszClass))
|
---|
293 | {
|
---|
294 | char *astring;
|
---|
295 |
|
---|
296 | if(isUnicode) astring = UnicodeToAsciiString((LPWSTR)cs->lpszClass);
|
---|
297 | else astring = (char *)cs->lpszClass;
|
---|
298 |
|
---|
299 | dprintf(("Window class %s", astring));
|
---|
300 | if(isUnicode) FreeAsciiString(astring);
|
---|
301 | }
|
---|
302 | else dprintf(("Window class %x", cs->lpszClass));
|
---|
303 | #endif
|
---|
304 |
|
---|
305 | /* Fix the lpszClass field: from existing programs, it seems ok to call a CreateWindowXXX
|
---|
306 | * with an atom as the class name, put some programs expect to have a *REAL* string in
|
---|
307 | * lpszClass when the CREATESTRUCT is sent with WM_CREATE
|
---|
308 | */
|
---|
309 | if (!HIWORD(cs->lpszClass) ) {
|
---|
310 | if (isUnicode) {
|
---|
311 | GlobalGetAtomNameW( classAtom, (LPWSTR)buffer, sizeof(buffer) );
|
---|
312 | }
|
---|
313 | else {
|
---|
314 | GlobalGetAtomNameA( classAtom, buffer, sizeof(buffer) );
|
---|
315 | }
|
---|
316 | cs->lpszClass = buffer;
|
---|
317 | }
|
---|
318 |
|
---|
319 | /* Fix the coordinates */
|
---|
320 | if (cs->x == CW_USEDEFAULT || cs->x == CW_USEDEFAULT16)
|
---|
321 | {
|
---|
322 | // PDB *pdb = PROCESS_Current();
|
---|
323 |
|
---|
324 | /* Never believe Microsoft's documentation... CreateWindowEx doc says
|
---|
325 | * that if an overlapped window is created with WS_VISIBLE style bit
|
---|
326 | * set and the x parameter is set to CW_USEDEFAULT, the system ignores
|
---|
327 | * the y parameter. However, disassembling NT implementation (WIN32K.SYS)
|
---|
328 | * reveals that
|
---|
329 | *
|
---|
330 | * 1) not only if checks for CW_USEDEFAULT but also for CW_USEDEFAULT16
|
---|
331 | * 2) it does not ignore the y parameter as the docs claim; instead, it
|
---|
332 | * uses it as second parameter to ShowWindow() unless y is either
|
---|
333 | * CW_USEDEFAULT or CW_USEDEFAULT16.
|
---|
334 | *
|
---|
335 | * The fact that we didn't do 2) caused bogus windows pop up when wine
|
---|
336 | * was running apps that were using this obscure feature. Example -
|
---|
337 | * calc.exe that comes with Win98 (only Win98, it's different from
|
---|
338 | * the one that comes with Win95 and NT)
|
---|
339 | */
|
---|
340 | if (cs->y != CW_USEDEFAULT && cs->y != CW_USEDEFAULT16) sw = cs->y;
|
---|
341 |
|
---|
342 | /* We have saved cs->y, now we can trash it */
|
---|
343 | #if 0
|
---|
344 | if ( !(cs->style & (WS_CHILD | WS_POPUP))
|
---|
345 | && (pdb->env_db->startup_info->dwFlags & STARTF_USEPOSITION) )
|
---|
346 | {
|
---|
347 | cs->x = pdb->env_db->startup_info->dwX;
|
---|
348 | cs->y = pdb->env_db->startup_info->dwY;
|
---|
349 | }
|
---|
350 | #endif
|
---|
351 | cs->x = 0;
|
---|
352 | cs->y = 0;
|
---|
353 | // }
|
---|
354 | }
|
---|
355 | if (cs->cx == CW_USEDEFAULT || cs->cx == CW_USEDEFAULT16)
|
---|
356 | {
|
---|
357 | #if 0
|
---|
358 | PDB *pdb = PROCESS_Current();
|
---|
359 | if ( !(cs->style & (WS_CHILD | WS_POPUP))
|
---|
360 | && (pdb->env_db->startup_info->dwFlags & STARTF_USESIZE) )
|
---|
361 | {
|
---|
362 | cs->cx = pdb->env_db->startup_info->dwXSize;
|
---|
363 | cs->cy = pdb->env_db->startup_info->dwYSize;
|
---|
364 | }
|
---|
365 | else
|
---|
366 | {
|
---|
367 | #endif
|
---|
368 | cs->cx = 600; /* FIXME */
|
---|
369 | cs->cy = 400;
|
---|
370 | // }
|
---|
371 | }
|
---|
372 |
|
---|
373 | if (cs->x < 0) cs->x = 0;
|
---|
374 | if (cs->y < 0) cs->y = 0;
|
---|
375 |
|
---|
376 | //Allocate window words
|
---|
377 | nrUserWindowLong = windowClass->getExtraWndWords();
|
---|
378 | if(nrUserWindowLong) {
|
---|
379 | userWindowLong = (ULONG *)_smalloc(nrUserWindowLong);
|
---|
380 | memset(userWindowLong, 0, nrUserWindowLong);
|
---|
381 | }
|
---|
382 |
|
---|
383 | if ((cs->style & WS_CHILD) && cs->hwndParent)
|
---|
384 | {
|
---|
385 | SetParent(cs->hwndParent);
|
---|
386 | owner = GetWindowFromHandle(cs->hwndParent);
|
---|
387 | if(owner == NULL)
|
---|
388 | {
|
---|
389 | dprintf(("HwGetWindowHandleData couldn't find owner window %x!!!", cs->hwndParent));
|
---|
390 | SetLastError(ERROR_INVALID_WINDOW_HANDLE);
|
---|
391 | return FALSE;
|
---|
392 | }
|
---|
393 | }
|
---|
394 | else
|
---|
395 | {
|
---|
396 | SetParent(windowDesktop->getWindowHandle());
|
---|
397 | if (!cs->hwndParent || cs->hwndParent == windowDesktop->getWindowHandle()) {
|
---|
398 | owner = NULL;
|
---|
399 | }
|
---|
400 | else
|
---|
401 | {
|
---|
402 | owner = GetWindowFromHandle(cs->hwndParent)->GetTopParent();
|
---|
403 | if(owner == NULL)
|
---|
404 | {
|
---|
405 | dprintf(("HwGetWindowHandleData couldn't find owner window %x!!!", cs->hwndParent));
|
---|
406 | SetLastError(ERROR_INVALID_WINDOW_HANDLE);
|
---|
407 | return FALSE;
|
---|
408 | }
|
---|
409 | }
|
---|
410 | }
|
---|
411 |
|
---|
412 | setWindowProc(windowClass->getWindowProc());
|
---|
413 | hInstance = cs->hInstance;
|
---|
414 | dwStyle = cs->style & ~WS_VISIBLE;
|
---|
415 | dwExStyle = cs->dwExStyle;
|
---|
416 |
|
---|
417 | #if 1
|
---|
418 | //SvL: Messes up Z-order of dialog controls
|
---|
419 | hwndLinkAfter = HWND_TOP;
|
---|
420 | #else
|
---|
421 | hwndLinkAfter = ((cs->style & (WS_CHILD|WS_MAXIMIZE)) == WS_CHILD)
|
---|
422 | ? HWND_BOTTOM : HWND_TOP;
|
---|
423 | #endif
|
---|
424 |
|
---|
425 | #if 0
|
---|
426 | //TODO
|
---|
427 | /* Call the WH_CBT hook */
|
---|
428 |
|
---|
429 | if (HOOK_IsHooked( WH_CBT ))
|
---|
430 | {
|
---|
431 | CBT_CREATEWNDA cbtc;
|
---|
432 | LRESULT ret;
|
---|
433 |
|
---|
434 | cbtc.lpcs = cs;
|
---|
435 | cbtc.hwndInsertAfter = hwndLinkAfter;
|
---|
436 | ret = unicode ? HOOK_CallHooksW(WH_CBT, HCBT_CREATEWND, Win32Hwnd, (LPARAM)&cbtc)
|
---|
437 | : HOOK_CallHooksA(WH_CBT, HCBT_CREATEWND, Win32Hwnd, (LPARAM)&cbtc);
|
---|
438 | if (ret)
|
---|
439 | {
|
---|
440 | TRACE_(win)("CBT-hook returned 0\n");
|
---|
441 | wndPtr->pDriver->pFinalize(wndPtr);
|
---|
442 | retvalue = 0;
|
---|
443 | goto end;
|
---|
444 | }
|
---|
445 | }
|
---|
446 | #endif
|
---|
447 |
|
---|
448 | /* Increment class window counter */
|
---|
449 | windowClass->IncreaseWindowCount();
|
---|
450 |
|
---|
451 | /* Correct the window style */
|
---|
452 | if (!(cs->style & WS_CHILD))
|
---|
453 | {
|
---|
454 | dwStyle |= WS_CLIPSIBLINGS;
|
---|
455 | if (!(cs->style & WS_POPUP))
|
---|
456 | {
|
---|
457 | dwStyle |= WS_CAPTION;
|
---|
458 | flags |= WIN_NEED_SIZE;
|
---|
459 | }
|
---|
460 | }
|
---|
461 | if (cs->dwExStyle & WS_EX_DLGMODALFRAME) dwStyle &= ~WS_THICKFRAME;
|
---|
462 |
|
---|
463 | //TODO?
|
---|
464 | #if 0
|
---|
465 | /* Get class or window DC if needed */
|
---|
466 | if (classPtr->style & CS_OWNDC) dce = DCE_AllocDCE(hwnd,DCE_WINDOW_DC);
|
---|
467 | else if (classPtr->style & CS_CLASSDC) wndPtr->dce = classPtr->dce;
|
---|
468 | else wndPtr->dce = NULL;
|
---|
469 | #endif
|
---|
470 |
|
---|
471 | if (cs->style & WS_HSCROLL)
|
---|
472 | {
|
---|
473 | horzScrollInfo = (SCROLLBAR_INFO*)malloc(sizeof(SCROLLBAR_INFO));
|
---|
474 | horzScrollInfo->MinVal = horzScrollInfo->CurVal = horzScrollInfo->Page = 0;
|
---|
475 | horzScrollInfo->MaxVal = 100;
|
---|
476 | horzScrollInfo->flags = ESB_ENABLE_BOTH;
|
---|
477 | }
|
---|
478 |
|
---|
479 | if (cs->style & WS_VSCROLL)
|
---|
480 | {
|
---|
481 | vertScrollInfo = (SCROLLBAR_INFO*)malloc(sizeof(SCROLLBAR_INFO));
|
---|
482 | vertScrollInfo->MinVal = vertScrollInfo->CurVal = vertScrollInfo->Page = 0;
|
---|
483 | vertScrollInfo->MaxVal = 100;
|
---|
484 | vertScrollInfo->flags = ESB_ENABLE_BOTH;
|
---|
485 | }
|
---|
486 |
|
---|
487 | /* Send the WM_GETMINMAXINFO message and fix the size if needed */
|
---|
488 | if ((cs->style & WS_THICKFRAME) || !(cs->style & (WS_POPUP | WS_CHILD)))
|
---|
489 | {
|
---|
490 | GetMinMaxInfo(&maxSize, &maxPos, &minTrack, &maxTrack);
|
---|
491 | if (maxSize.x < cs->cx) cs->cx = maxSize.x;
|
---|
492 | if (maxSize.y < cs->cy) cs->cy = maxSize.y;
|
---|
493 | if (cs->cx < minTrack.x ) cs->cx = minTrack.x;
|
---|
494 | if (cs->cy < minTrack.y ) cs->cy = minTrack.y;
|
---|
495 | }
|
---|
496 |
|
---|
497 | if(cs->style & WS_CHILD)
|
---|
498 | {
|
---|
499 | if(cs->cx < 0) cs->cx = 0;
|
---|
500 | if(cs->cy < 0) cs->cy = 0;
|
---|
501 | }
|
---|
502 | else
|
---|
503 | {
|
---|
504 | if (cs->cx <= 0) cs->cx = 1;
|
---|
505 | if (cs->cy <= 0) cs->cy = 1;
|
---|
506 | }
|
---|
507 |
|
---|
508 | DWORD dwOSWinStyle, dwOSFrameStyle;
|
---|
509 |
|
---|
510 | OSLibWinConvertStyle(cs->style, &cs->dwExStyle, &dwOSWinStyle, &dwOSFrameStyle, &borderWidth, &borderHeight);
|
---|
511 | dwExStyle = cs->dwExStyle;
|
---|
512 |
|
---|
513 | rectWindow.left = cs->x;
|
---|
514 | rectWindow.top = cs->y;
|
---|
515 | rectWindow.right = cs->x + cs->cx;
|
---|
516 | rectWindow.bottom = cs->y + cs->cy;
|
---|
517 | rectClient = rectWindow;
|
---|
518 |
|
---|
519 | if(HIWORD(cs->lpszName))
|
---|
520 | {
|
---|
521 | if(isUnicode)
|
---|
522 | SetWindowTextW((LPWSTR)cs->lpszName);
|
---|
523 | else SetWindowTextA((LPSTR)cs->lpszName);
|
---|
524 | }
|
---|
525 |
|
---|
526 | //copy pointer of CREATESTRUCT for usage in MsgCreate method
|
---|
527 | tmpcs = cs;
|
---|
528 |
|
---|
529 | //Store our window object pointer in thread local memory, so PMWINDOW.CPP can retrieve it
|
---|
530 | THDB *thdb = GetThreadTHDB();
|
---|
531 |
|
---|
532 | if(thdb == NULL) {
|
---|
533 | dprintf(("Window creation failed - thdb == NULL")); //this is VERY bad
|
---|
534 | ExitProcess(666);
|
---|
535 | return FALSE;
|
---|
536 | }
|
---|
537 |
|
---|
538 | thdb->newWindow = (ULONG)this;
|
---|
539 |
|
---|
540 | OS2Hwnd = OSLibWinCreateWindow((getParent()) ? getParent()->getOS2WindowHandle() : OSLIB_HWND_DESKTOP,
|
---|
541 | dwOSWinStyle, dwOSFrameStyle, (char *)windowNameA,
|
---|
542 | (owner) ? owner->getOS2WindowHandle() : OSLIB_HWND_DESKTOP,
|
---|
543 | (hwndLinkAfter == HWND_BOTTOM) ? TRUE : FALSE,
|
---|
544 | &OS2HwndFrame, 0);
|
---|
545 |
|
---|
546 | if(OS2Hwnd == 0) {
|
---|
547 | dprintf(("Window creation failed!!"));
|
---|
548 | SetLastError(ERROR_OUTOFMEMORY); //TODO: Better error
|
---|
549 | return FALSE;
|
---|
550 | }
|
---|
551 | SetLastError(0);
|
---|
552 | return TRUE;
|
---|
553 | }
|
---|
554 | //******************************************************************************
|
---|
555 | //******************************************************************************
|
---|
556 | BOOL Win32BaseWindow::MsgCreate(HWND hwndFrame, HWND hwndClient)
|
---|
557 | {
|
---|
558 | POINT maxPos;
|
---|
559 | CREATESTRUCTA *cs = tmpcs; //pointer to CREATESTRUCT used in CreateWindowExA method
|
---|
560 | RECT rectWndTmp, rectClientTmp;
|
---|
561 |
|
---|
562 | OS2Hwnd = hwndClient;
|
---|
563 | OS2HwndFrame = hwndFrame;
|
---|
564 |
|
---|
565 | //make backup copy of rectangles (some calls below result in WM_WINDOWPOSCHANGED with weird values since we haven't
|
---|
566 | //set our window size just yet)
|
---|
567 | rectWndTmp = rectWindow;
|
---|
568 | rectClientTmp = rectClient;
|
---|
569 |
|
---|
570 | fNoSizeMsg = TRUE;
|
---|
571 |
|
---|
572 | if(OSLibWinSetWindowULong(OS2Hwnd, OFFSET_WIN32WNDPTR, (ULONG)this) == FALSE) {
|
---|
573 | dprintf(("WM_CREATE: WinSetWindowULong %X failed!!", OS2Hwnd));
|
---|
574 | SetLastError(ERROR_OUTOFMEMORY); //TODO: Better error
|
---|
575 | return FALSE;
|
---|
576 | }
|
---|
577 | if(OSLibWinSetWindowULong(OS2Hwnd, OFFSET_WIN32PM_MAGIC, WIN32PM_MAGIC) == FALSE) {
|
---|
578 | dprintf(("WM_CREATE: WinSetWindowULong2 %X failed!!", OS2Hwnd));
|
---|
579 | SetLastError(ERROR_OUTOFMEMORY); //TODO: Better error
|
---|
580 | return FALSE;
|
---|
581 | }
|
---|
582 | //SvL: Need to store the shared memory base, or else other apps can map it into their memory space
|
---|
583 | if(OSLibWinSetWindowULong(OS2Hwnd, OFFSET_WIN32PM_SHAREDMEM, HeapGetSharedMemBase()) == FALSE) {
|
---|
584 | dprintf(("WM_CREATE: WinSetWindowULong2 %X failed!!", OS2Hwnd));
|
---|
585 | SetLastError(ERROR_OUTOFMEMORY); //TODO: Better error
|
---|
586 | return FALSE;
|
---|
587 | }
|
---|
588 | #if 0
|
---|
589 | if(OS2Hwnd != OS2HwndFrame) {
|
---|
590 | if(OSLibWinSetWindowULong(OS2HwndFrame, OFFSET_WIN32WNDPTR, (ULONG)this) == FALSE) {
|
---|
591 | dprintf(("WM_CREATE: WinSetWindowULong %X failed!!", OS2HwndFrame));
|
---|
592 | SetLastError(ERROR_OUTOFMEMORY); //TODO: Better error
|
---|
593 | return FALSE;
|
---|
594 | }
|
---|
595 | if(OSLibWinSetWindowULong(OS2HwndFrame, OFFSET_WIN32PM_MAGIC, WIN32PM_MAGIC) == FALSE) {
|
---|
596 | dprintf(("WM_CREATE: WinSetWindowULong2 %X failed!!", OS2HwndFrame));
|
---|
597 | SetLastError(ERROR_OUTOFMEMORY); //TODO: Better error
|
---|
598 | return FALSE;
|
---|
599 | }
|
---|
600 | //SvL: Need to store the shared memory base, or else other apps can map it into their memory space
|
---|
601 | if(OSLibWinSetWindowULong(OS2HwndFrame, OFFSET_WIN32PM_SHAREDMEM, HeapGetSharedMemBase()) == FALSE) {
|
---|
602 | dprintf(("WM_CREATE: WinSetWindowULong2 %X failed!!", OS2HwndFrame));
|
---|
603 | SetLastError(ERROR_OUTOFMEMORY); //TODO: Better error
|
---|
604 | return FALSE;
|
---|
605 | }
|
---|
606 | }
|
---|
607 | #endif
|
---|
608 |
|
---|
609 | OSLibWinSetOwner(OS2Hwnd, OS2HwndFrame);
|
---|
610 |
|
---|
611 | if (dwStyle & WS_HSCROLL)
|
---|
612 | {
|
---|
613 | hwndHorzScroll = OSLibWinQueryScrollBarHandle(OS2HwndFrame, OSLIB_HSCROLL);
|
---|
614 | // OSLibWinShowScrollBar(OS2HwndFrame, hwndHorzScroll, OSLIB_HSCROLL, FALSE, TRUE);
|
---|
615 | }
|
---|
616 |
|
---|
617 | if (dwStyle & WS_VSCROLL) {
|
---|
618 | hwndVertScroll = OSLibWinQueryScrollBarHandle(OS2HwndFrame, OSLIB_VSCROLL);
|
---|
619 | // OSLibWinShowScrollBar(OS2HwndFrame, hwndVertScroll, OSLIB_VSCROLL, FALSE, TRUE);
|
---|
620 | }
|
---|
621 |
|
---|
622 | //CB: switch off -> OS/2 scrollbars
|
---|
623 | subclassScrollBars(dwStyle & WS_HSCROLL,dwStyle & WS_VSCROLL);
|
---|
624 |
|
---|
625 | fakeWinBase.hwndThis = OS2Hwnd;
|
---|
626 | fakeWinBase.pWindowClass = windowClass;
|
---|
627 |
|
---|
628 | //Set icon from class
|
---|
629 | if(windowClass->getIcon())
|
---|
630 | SetIcon(windowClass->getIcon());
|
---|
631 |
|
---|
632 | /* Set the window menu */
|
---|
633 | if ((dwStyle & (WS_CAPTION | WS_CHILD)) == WS_CAPTION )
|
---|
634 | {
|
---|
635 | if (cs->hMenu) SetMenu(cs->hMenu);
|
---|
636 | else
|
---|
637 | {
|
---|
638 | if (windowClass->getMenuNameA()) {
|
---|
639 | cs->hMenu = LoadMenuA(cs->hInstance, windowClass->getMenuNameA());
|
---|
640 | if (cs->hMenu) SetMenu(cs->hMenu );
|
---|
641 | }
|
---|
642 | }
|
---|
643 | }
|
---|
644 | else
|
---|
645 | {
|
---|
646 | dprintf(("Set window ID to %x", cs->hMenu));
|
---|
647 | setWindowId((DWORD)cs->hMenu);
|
---|
648 | }
|
---|
649 |
|
---|
650 | // Subclass frame
|
---|
651 | pOldFrameProc = FrameSubclassFrameWindow(this);
|
---|
652 | if (isChild()) FrameSetBorderSize(this,TRUE);
|
---|
653 |
|
---|
654 | //restore rectangles (some calls below result in WM_WINDOWPOSCHANGED with weird values since we haven't
|
---|
655 | //set our window size just yet)
|
---|
656 | rectWindow = rectWndTmp;
|
---|
657 | rectClient = rectClientTmp;
|
---|
658 |
|
---|
659 | /* Send the WM_CREATE message
|
---|
660 | * Perhaps we shouldn't allow width/height changes as well.
|
---|
661 | * See p327 in "Internals".
|
---|
662 | */
|
---|
663 | maxPos.x = rectWindow.left; maxPos.y = rectWindow.top;
|
---|
664 |
|
---|
665 | if(getParent()) {
|
---|
666 | SetWindowPos(getParent()->getWindowHandle(), rectClient.left, rectClient.top,
|
---|
667 | rectClient.right-rectClient.left,
|
---|
668 | rectClient.bottom-rectClient.top,
|
---|
669 | SWP_NOACTIVATE | SWP_NOZORDER | SWP_NOREDRAW);
|
---|
670 | }
|
---|
671 | else {
|
---|
672 | SetWindowPos(HWND_TOP, rectClient.left, rectClient.top,
|
---|
673 | rectClient.right-rectClient.left,
|
---|
674 | rectClient.bottom-rectClient.top,
|
---|
675 | SWP_NOACTIVATE | SWP_NOREDRAW);
|
---|
676 | }
|
---|
677 | //Note: Solitaire crashes when receiving WM_SIZE messages before WM_CREATE
|
---|
678 | fNoSizeMsg = FALSE;
|
---|
679 |
|
---|
680 | if(SendMessageA(WM_NCCREATE, 0, (LPARAM)cs) )
|
---|
681 | {
|
---|
682 | fCreated = TRUE;
|
---|
683 |
|
---|
684 | SendNCCalcSize(FALSE, &rectWindow, NULL, NULL, 0, &rectClient );
|
---|
685 |
|
---|
686 | // OffsetRect(&rectWindow, maxPos.x - rectWindow.left, maxPos.y - rectWindow.top);
|
---|
687 | if( (SendMessageA(WM_CREATE, 0, (LPARAM)cs )) != -1 )
|
---|
688 | {
|
---|
689 | if(!(flags & WIN_NEED_SIZE)) {
|
---|
690 | SendMessageA(WM_SIZE, SIZE_RESTORED,
|
---|
691 | MAKELONG(rectClient.right-rectClient.left,
|
---|
692 | rectClient.bottom-rectClient.top));
|
---|
693 | SendMessageA(WM_MOVE, 0, MAKELONG( rectClient.left, rectClient.top ) );
|
---|
694 | }
|
---|
695 |
|
---|
696 | if (cs->style & WS_VISIBLE) ShowWindow( sw );
|
---|
697 |
|
---|
698 | #if 0
|
---|
699 | /* Call WH_SHELL hook */
|
---|
700 |
|
---|
701 | if (!(dwStyle & WS_CHILD) && !owner)
|
---|
702 | HOOK_CallHooks16( WH_SHELL, HSHELL_WINDOWCREATED, hwnd, 0 );
|
---|
703 | #endif
|
---|
704 | SetLastError(0);
|
---|
705 | return TRUE;
|
---|
706 | }
|
---|
707 | }
|
---|
708 | dprintf(("Window creation FAILED (NCCREATE cancelled creation)"));
|
---|
709 | SetLastError(ERROR_OUTOFMEMORY); //TODO: Better error
|
---|
710 | return FALSE;
|
---|
711 | }
|
---|
712 | //******************************************************************************
|
---|
713 | //******************************************************************************
|
---|
714 | ULONG Win32BaseWindow::MsgQuit()
|
---|
715 | {
|
---|
716 | return SendInternalMessageA(WM_QUIT, 0, 0);
|
---|
717 | }
|
---|
718 | //******************************************************************************
|
---|
719 | //******************************************************************************
|
---|
720 | ULONG Win32BaseWindow::MsgClose()
|
---|
721 | {
|
---|
722 | if(SendInternalMessageA(WM_CLOSE, 0, 0) == 0) {
|
---|
723 | return 0; //app handles this message
|
---|
724 | }
|
---|
725 | return 1;
|
---|
726 | }
|
---|
727 | //******************************************************************************
|
---|
728 | //******************************************************************************
|
---|
729 | ULONG Win32BaseWindow::MsgDestroy()
|
---|
730 | {
|
---|
731 | ULONG rc;
|
---|
732 | Win32BaseWindow *child;
|
---|
733 |
|
---|
734 | if (isSubclassedOS2Wnd) OSLibWinSubclassWindow(OS2Hwnd,pOldWndProc);
|
---|
735 |
|
---|
736 | fIsDestroyed = TRUE;
|
---|
737 | //According to the SDK, WM_PARENTNOTIFY messages are sent to the parent (this window)
|
---|
738 | //before any window destruction has begun
|
---|
739 | child = (Win32BaseWindow *)getFirstChild();
|
---|
740 | while(child) {
|
---|
741 | child->NotifyParent(WM_DESTROY, 0, 0);
|
---|
742 |
|
---|
743 | child = (Win32BaseWindow *)child->getNextChild();
|
---|
744 | }
|
---|
745 | SendInternalMessageA(WM_DESTROY, 0, 0);
|
---|
746 |
|
---|
747 | if (hwndHorzScroll && OSLibWinQueryWindow(hwndHorzScroll,QWOS_PARENT) == OSLIB_HWND_OBJECT) OSLibWinDestroyWindow(hwndHorzScroll);
|
---|
748 | if (hwndVertScroll && OSLibWinQueryWindow(hwndVertScroll,QWOS_PARENT) == OSLIB_HWND_OBJECT) OSLibWinDestroyWindow(hwndVertScroll);
|
---|
749 |
|
---|
750 | if(getFirstChild() == NULL) {
|
---|
751 | delete this;
|
---|
752 | }
|
---|
753 | return 1;
|
---|
754 | }
|
---|
755 | //******************************************************************************
|
---|
756 | //******************************************************************************
|
---|
757 | ULONG Win32BaseWindow::MsgEnable(BOOL fEnable)
|
---|
758 | {
|
---|
759 | if(fEnable) {
|
---|
760 | dwStyle &= ~WS_DISABLED;
|
---|
761 | }
|
---|
762 | else dwStyle |= WS_DISABLED;
|
---|
763 |
|
---|
764 | return SendInternalMessageA(WM_ENABLE, fEnable, 0);
|
---|
765 | }
|
---|
766 | //******************************************************************************
|
---|
767 | //TODO: SW_PARENTCLOSING/OPENING flag (lParam)
|
---|
768 | //******************************************************************************
|
---|
769 | ULONG Win32BaseWindow::MsgShow(BOOL fShow)
|
---|
770 | {
|
---|
771 | if(fNoSizeMsg) {
|
---|
772 | return 1;
|
---|
773 | }
|
---|
774 |
|
---|
775 | if(fShow) {
|
---|
776 | setStyle(getStyle() | WS_VISIBLE);
|
---|
777 | }
|
---|
778 | else setStyle(getStyle() & ~WS_VISIBLE);
|
---|
779 |
|
---|
780 | return SendInternalMessageA(WM_SHOWWINDOW, fShow, 0);
|
---|
781 | }
|
---|
782 | //******************************************************************************
|
---|
783 | //******************************************************************************
|
---|
784 | ULONG Win32BaseWindow::MsgPosChanging(LPARAM lp)
|
---|
785 | {
|
---|
786 | if(fNoSizeMsg)
|
---|
787 | return 1;
|
---|
788 |
|
---|
789 | return SendInternalMessageA(WM_WINDOWPOSCHANGING, 0, lp);
|
---|
790 | }
|
---|
791 | //******************************************************************************
|
---|
792 | //******************************************************************************
|
---|
793 | ULONG Win32BaseWindow::MsgPosChanged(LPARAM lp)
|
---|
794 | {
|
---|
795 | if(fNoSizeMsg)
|
---|
796 | return 1;
|
---|
797 |
|
---|
798 | return SendInternalMessageA(WM_WINDOWPOSCHANGED, 0, lp);
|
---|
799 | }
|
---|
800 | //******************************************************************************
|
---|
801 | //******************************************************************************
|
---|
802 | ULONG Win32BaseWindow::MsgMove(ULONG x, ULONG y)
|
---|
803 | {
|
---|
804 | dprintf(("MsgMove to (%d,%d)", x, y));
|
---|
805 | if(fNoSizeMsg)
|
---|
806 | return 1;
|
---|
807 |
|
---|
808 | return SendInternalMessageA(WM_MOVE, 0, MAKELONG((USHORT)x, (USHORT)y));
|
---|
809 | }
|
---|
810 | //******************************************************************************
|
---|
811 | //******************************************************************************
|
---|
812 | ULONG Win32BaseWindow::MsgTimer(ULONG TimerID)
|
---|
813 | {
|
---|
814 | // TODO: call TIMERPROC if not NULL
|
---|
815 | return SendInternalMessageA(WM_TIMER, TimerID, 0);
|
---|
816 | }
|
---|
817 | //******************************************************************************
|
---|
818 | //******************************************************************************
|
---|
819 | ULONG Win32BaseWindow::MsgSysTimer(ULONG TimerID)
|
---|
820 | {
|
---|
821 | // TODO: call TIMERPROC if not NULL
|
---|
822 | return SendInternalMessageA(WM_SYSTIMER, TimerID, 0);
|
---|
823 | }
|
---|
824 | //******************************************************************************
|
---|
825 | //******************************************************************************
|
---|
826 | ULONG Win32BaseWindow::MsgScroll(ULONG msg, ULONG scrollCode, ULONG scrollPos)
|
---|
827 | {
|
---|
828 | //According to the SDK docs, the scrollbar handle (lParam) is 0 when the standard
|
---|
829 | //window scrollbars send these messages
|
---|
830 | return SendInternalMessageA(msg, MAKELONG(scrollCode, scrollPos), 0);
|
---|
831 | }
|
---|
832 | //******************************************************************************
|
---|
833 | //******************************************************************************
|
---|
834 | ULONG Win32BaseWindow::MsgCommand(ULONG cmd, ULONG Id, HWND hwnd)
|
---|
835 | {
|
---|
836 | switch(cmd) {
|
---|
837 | case CMD_MENU:
|
---|
838 | return SendInternalMessageA(WM_COMMAND, MAKELONG(Id, 0), 0);
|
---|
839 | case CMD_CONTROL:
|
---|
840 | return 0; //todo
|
---|
841 | case CMD_ACCELERATOR:
|
---|
842 | // this fit not really windows behavior.
|
---|
843 | // maybe TranslateAccelerator() is better
|
---|
844 | dprintf(("accelerator command"));
|
---|
845 | return SendInternalMessageA(WM_COMMAND, MAKELONG(Id, 0), 0);
|
---|
846 | }
|
---|
847 | return 0;
|
---|
848 | }
|
---|
849 | //******************************************************************************
|
---|
850 | //******************************************************************************
|
---|
851 | ULONG Win32BaseWindow::MsgHitTest(ULONG x, ULONG y)
|
---|
852 | {
|
---|
853 | lastHitTestVal = SendInternalMessageA(WM_NCHITTEST, 0, MAKELONG((USHORT)x, (USHORT)y));
|
---|
854 | return 1; //TODO: May need to change this
|
---|
855 | }
|
---|
856 | //******************************************************************************
|
---|
857 | //TODO: Send WM_NCCALCSIZE message here and correct size if necessary
|
---|
858 | //******************************************************************************
|
---|
859 | ULONG Win32BaseWindow::MsgSize(ULONG width, ULONG height, BOOL fMinimize, BOOL fMaximize)
|
---|
860 | {
|
---|
861 | WORD fwSizeType = 0;
|
---|
862 |
|
---|
863 | dwStyle &= ~(WS_MINIMIZE|WS_MAXIMIZE);
|
---|
864 | if(fMinimize) {
|
---|
865 | fwSizeType = SIZE_MINIMIZED;
|
---|
866 | dwStyle |= WS_MINIMIZE;
|
---|
867 | }
|
---|
868 | else
|
---|
869 | if(fMaximize) {
|
---|
870 | fwSizeType = SIZE_MAXIMIZED;
|
---|
871 | dwStyle |= WS_MAXIMIZE;
|
---|
872 | }
|
---|
873 | else fwSizeType = SIZE_RESTORED;
|
---|
874 |
|
---|
875 | return SendInternalMessageA(WM_SIZE, fwSizeType, MAKELONG((USHORT)width, (USHORT)height));
|
---|
876 | }
|
---|
877 | //******************************************************************************
|
---|
878 | //******************************************************************************
|
---|
879 | ULONG Win32BaseWindow::MsgActivate(BOOL fActivate, BOOL fMinimized, HWND hwnd)
|
---|
880 | {
|
---|
881 | ULONG rc, curprocid, procidhwnd = -1, threadidhwnd = 0;
|
---|
882 |
|
---|
883 | //According to SDK docs, if app returns FALSE & window is being deactivated,
|
---|
884 | //default processing is cancelled
|
---|
885 | //TODO: According to Wine we should proceed anyway if window is sysmodal
|
---|
886 | if(SendInternalMessageA(WM_NCACTIVATE, fActivate, 0) == FALSE && !fActivate)
|
---|
887 | {
|
---|
888 | return 0;
|
---|
889 | }
|
---|
890 | rc = SendInternalMessageA(WM_ACTIVATE, MAKELONG((fActivate) ? WA_ACTIVE : WA_INACTIVE, fMinimized), hwnd);
|
---|
891 |
|
---|
892 | curprocid = GetCurrentProcessId();
|
---|
893 | if(hwnd) {
|
---|
894 | threadidhwnd = GetWindowThreadProcessId(hwnd, &procidhwnd);
|
---|
895 | }
|
---|
896 |
|
---|
897 | if(curprocid != procidhwnd && fActivate) {
|
---|
898 | SendInternalMessageA(WM_ACTIVATEAPP, 1, threadidhwnd);
|
---|
899 | }
|
---|
900 | return rc;
|
---|
901 | }
|
---|
902 | //******************************************************************************
|
---|
903 | //******************************************************************************
|
---|
904 | ULONG Win32BaseWindow::MsgSysCommand(ULONG win32sc, ULONG x, ULONG y)
|
---|
905 | {
|
---|
906 | return SendInternalMessageA(WM_SYSCOMMAND, win32sc, MAKELONG((USHORT)x, (USHORT)y));
|
---|
907 | }
|
---|
908 | //******************************************************************************
|
---|
909 | //TODO: Is this correct and complete?
|
---|
910 | //Add print screen, break & numlock
|
---|
911 | //******************************************************************************
|
---|
912 | void Win32BaseWindow::setExtendedKey(ULONG virtualkey, ULONG *lParam)
|
---|
913 | {
|
---|
914 | switch(virtualkey) {
|
---|
915 | case VK_DOWN:
|
---|
916 | case VK_UP:
|
---|
917 | case VK_PRIOR:
|
---|
918 | case VK_NEXT:
|
---|
919 | case VK_END:
|
---|
920 | case VK_DIVIDE:
|
---|
921 | case VK_DELETE:
|
---|
922 | case VK_EXECUTE: //Numeric enter key?
|
---|
923 | case VK_HOME:
|
---|
924 | case VK_INSERT:
|
---|
925 | case VK_RCONTROL:
|
---|
926 | case VK_RMENU: //is this the right alt???
|
---|
927 | *lParam = *lParam | (1<<24);
|
---|
928 | }
|
---|
929 | }
|
---|
930 | //******************************************************************************
|
---|
931 | //TODO: virtual key & (possibly) scancode translation, extended keyboard bit & Unicode
|
---|
932 | //******************************************************************************
|
---|
933 | ULONG Win32BaseWindow::MsgChar(ULONG cmd, ULONG repeatcnt, ULONG scancode, ULONG vkey, ULONG keyflags)
|
---|
934 | {
|
---|
935 | ULONG lParam = 0;
|
---|
936 |
|
---|
937 | lParam = repeatcnt;
|
---|
938 | lParam |= (scancode << 16);
|
---|
939 | setExtendedKey(vkey, &lParam);
|
---|
940 |
|
---|
941 | if(keyflags & KEY_ALTDOWN)
|
---|
942 | lParam |= (1<<29);
|
---|
943 | if(keyflags & KEY_PREVDOWN)
|
---|
944 | lParam |= (1<<30);
|
---|
945 | if(keyflags & KEY_UP)
|
---|
946 | lParam |= (1<<31);
|
---|
947 | if(keyflags & KEY_DEADKEY) {
|
---|
948 | dprintf(("WM_DEADCHAR: %x %x %08x", OS2Hwnd, cmd, lParam));
|
---|
949 | return SendInternalMessageA(WM_DEADCHAR, cmd, lParam);
|
---|
950 | }
|
---|
951 | else {
|
---|
952 | dprintf(("WM_CHAR: %x %x %08x", OS2Hwnd, cmd, lParam));
|
---|
953 | return SendInternalMessageA(WM_CHAR, cmd, lParam);
|
---|
954 | }
|
---|
955 | }
|
---|
956 | //******************************************************************************
|
---|
957 | //******************************************************************************
|
---|
958 | ULONG Win32BaseWindow::MsgKeyUp (ULONG repeatCount, ULONG scancode, ULONG virtualKey)
|
---|
959 | {
|
---|
960 | ULONG lParam=0;
|
---|
961 |
|
---|
962 | lParam = repeatCount & 0x0FFFF; // bit 0-15, repeatcount
|
---|
963 | lParam |= (scancode & 0x0FF) << 16; // bit 16-23, scancode
|
---|
964 | // bit 24, 1=extended key
|
---|
965 | // bit 25-28, reserved
|
---|
966 | lParam |= 0 << 29; // bit 29, key is released, always 0 for WM_KEYUP ?? <- conflict according to the MS docs
|
---|
967 | lParam |= 1 << 30; // bit 30, previous state, always 1 for a WM_KEYUP message
|
---|
968 | lParam |= 1 << 31; // bit 31, transition state, always 1 for WM_KEYUP
|
---|
969 |
|
---|
970 | dprintf(("WM_KEYUP: vkey:(%x) param:(%x)", virtualKey, lParam));
|
---|
971 |
|
---|
972 | setExtendedKey(virtualKey, &lParam);
|
---|
973 | return SendInternalMessageA (WM_KEYUP, virtualKey, lParam);
|
---|
974 | }
|
---|
975 | //******************************************************************************
|
---|
976 | //******************************************************************************
|
---|
977 | ULONG Win32BaseWindow::MsgKeyDown (ULONG repeatCount, ULONG scancode, ULONG virtualKey, BOOL keyWasPressed)
|
---|
978 | {
|
---|
979 | ULONG lParam=0;
|
---|
980 |
|
---|
981 | lParam = repeatCount & 0x0FFFF; // bit 0-15, repeatcount
|
---|
982 | lParam |= (scancode & 0x0FF) << 16; // bit 16-23, scancode
|
---|
983 | // bit 24, 1=extended key
|
---|
984 | // bit 25-28, reserved
|
---|
985 | // bit 29, key is pressed, always 0 for WM_KEYDOWN ?? <- conflict according to the MS docs
|
---|
986 | if (keyWasPressed)
|
---|
987 | lParam |= 1 << 30; // bit 30, previous state, 1 means key was pressed
|
---|
988 | // bit 31, transition state, always 0 for WM_KEYDOWN
|
---|
989 |
|
---|
990 | setExtendedKey(virtualKey, &lParam);
|
---|
991 |
|
---|
992 | dprintf(("WM_KEYDOWN: vkey:(%x) param:(%x)", virtualKey, lParam));
|
---|
993 |
|
---|
994 | return SendInternalMessageA (WM_KEYDOWN, virtualKey, lParam);
|
---|
995 | }
|
---|
996 | //******************************************************************************
|
---|
997 | //******************************************************************************
|
---|
998 | ULONG Win32BaseWindow::MsgSysKeyUp (ULONG repeatCount, ULONG scancode, ULONG virtualKey)
|
---|
999 | {
|
---|
1000 | ULONG lParam=0;
|
---|
1001 |
|
---|
1002 | lParam = repeatCount & 0x0FFFF; // bit 0-15,repeatcount
|
---|
1003 | lParam |= (scancode & 0x0FF) << 16; // bit 16-23, scancode
|
---|
1004 | // bit 24, 1=extended key
|
---|
1005 | // bit 25-28, reserved
|
---|
1006 | lParam |= 0 << 29; // bit 29, key is released, always 1 for WM_SYSKEYUP ?? <- conflict according to the MS docs
|
---|
1007 | lParam |= 1 << 30; // bit 30, previous state, always 1 for a WM_KEYUP message
|
---|
1008 | lParam |= 1 << 31; // bit 31, transition state, always 1 for WM_KEYUP
|
---|
1009 |
|
---|
1010 | setExtendedKey(virtualKey, &lParam);
|
---|
1011 | dprintf(("WM_SYSKEYUP: vkey:(%x) param:(%x)", virtualKey, lParam));
|
---|
1012 |
|
---|
1013 | return SendInternalMessageA (WM_SYSKEYUP, virtualKey, lParam);
|
---|
1014 | }
|
---|
1015 | //******************************************************************************
|
---|
1016 | //******************************************************************************
|
---|
1017 | ULONG Win32BaseWindow::MsgSysKeyDown (ULONG repeatCount, ULONG scancode, ULONG virtualKey, BOOL keyWasPressed)
|
---|
1018 | {
|
---|
1019 | ULONG lParam=0;
|
---|
1020 |
|
---|
1021 | lParam = repeatCount & 0x0FFFF; // bit 0-15, repeatcount
|
---|
1022 | lParam |= (scancode & 0x0FF) << 16; // bit 16-23, scancode
|
---|
1023 | // bit 24, 1=extended key
|
---|
1024 | // bit 25-28, reserved
|
---|
1025 | // bit 29, key is released, always 1 for WM_SYSKEYUP ?? <- conflict according to the MS docs
|
---|
1026 | if (keyWasPressed)
|
---|
1027 | lParam |= 1 << 30; // bit 30, previous state, 1 means key was pressed
|
---|
1028 | // bit 31, transition state, always 0 for WM_KEYDOWN
|
---|
1029 |
|
---|
1030 | setExtendedKey(virtualKey, &lParam);
|
---|
1031 | dprintf(("WM_SYSKEYDOWN: vkey:(%x) param:(%x)", virtualKey, lParam));
|
---|
1032 |
|
---|
1033 | return SendInternalMessageA (WM_SYSKEYDOWN, virtualKey, lParam);
|
---|
1034 | }
|
---|
1035 | //******************************************************************************
|
---|
1036 | //******************************************************************************
|
---|
1037 | ULONG Win32BaseWindow::MsgSetFocus(HWND hwnd)
|
---|
1038 | {
|
---|
1039 | return SendInternalMessageA(WM_SETFOCUS, hwnd, 0);
|
---|
1040 | }
|
---|
1041 | //******************************************************************************
|
---|
1042 | //******************************************************************************
|
---|
1043 | ULONG Win32BaseWindow::MsgKillFocus(HWND hwnd)
|
---|
1044 | {
|
---|
1045 | return SendInternalMessageA(WM_KILLFOCUS, hwnd, 0);
|
---|
1046 | }
|
---|
1047 | //******************************************************************************
|
---|
1048 | //******************************************************************************
|
---|
1049 | //******************************************************************************
|
---|
1050 | ULONG Win32BaseWindow::MsgButton(ULONG msg, ULONG ncx, ULONG ncy, ULONG clx, ULONG cly)
|
---|
1051 | {
|
---|
1052 | ULONG win32msg;
|
---|
1053 | ULONG win32ncmsg;
|
---|
1054 |
|
---|
1055 | dprintf(("MsgButton to (%d,%d)", ncx, ncy));
|
---|
1056 | switch(msg) {
|
---|
1057 | case BUTTON_LEFTDOWN:
|
---|
1058 | win32msg = WM_LBUTTONDOWN;
|
---|
1059 | win32ncmsg = WM_NCLBUTTONDOWN;
|
---|
1060 | break;
|
---|
1061 | case BUTTON_LEFTUP:
|
---|
1062 | win32msg = WM_LBUTTONUP;
|
---|
1063 | win32ncmsg = WM_NCLBUTTONUP;
|
---|
1064 | break;
|
---|
1065 | case BUTTON_LEFTDBLCLICK:
|
---|
1066 | if (windowClass && windowClass->getClassLongA(GCL_STYLE) & CS_DBLCLKS)
|
---|
1067 | {
|
---|
1068 | win32msg = WM_LBUTTONDBLCLK;
|
---|
1069 | win32ncmsg = WM_NCLBUTTONDBLCLK;
|
---|
1070 | } else
|
---|
1071 | {
|
---|
1072 | MsgButton(BUTTON_LEFTDOWN,ncx,ncy,clx,cly);
|
---|
1073 | return MsgButton(BUTTON_LEFTUP,ncx,ncy,clx,cly);
|
---|
1074 | }
|
---|
1075 | break;
|
---|
1076 | case BUTTON_RIGHTUP:
|
---|
1077 | win32msg = WM_RBUTTONUP;
|
---|
1078 | win32ncmsg = WM_NCRBUTTONUP;
|
---|
1079 | break;
|
---|
1080 | case BUTTON_RIGHTDOWN:
|
---|
1081 | win32msg = WM_RBUTTONDOWN;
|
---|
1082 | win32ncmsg = WM_NCRBUTTONDOWN;
|
---|
1083 | break;
|
---|
1084 | case BUTTON_RIGHTDBLCLICK:
|
---|
1085 | if (windowClass && windowClass->getClassLongA(GCL_STYLE) & CS_DBLCLKS)
|
---|
1086 | {
|
---|
1087 | win32msg = WM_RBUTTONDBLCLK;
|
---|
1088 | win32ncmsg = WM_NCRBUTTONDBLCLK;
|
---|
1089 | } else
|
---|
1090 | {
|
---|
1091 | MsgButton(BUTTON_RIGHTDOWN,ncx,ncy,clx,cly);
|
---|
1092 | return MsgButton(BUTTON_RIGHTUP,ncx,ncy,clx,cly);
|
---|
1093 | }
|
---|
1094 | break;
|
---|
1095 | case BUTTON_MIDDLEUP:
|
---|
1096 | win32msg = WM_MBUTTONUP;
|
---|
1097 | win32ncmsg = WM_NCMBUTTONUP;
|
---|
1098 | break;
|
---|
1099 | case BUTTON_MIDDLEDOWN:
|
---|
1100 | win32msg = WM_MBUTTONDOWN;
|
---|
1101 | win32ncmsg = WM_NCMBUTTONDOWN;
|
---|
1102 | break;
|
---|
1103 | case BUTTON_MIDDLEDBLCLICK:
|
---|
1104 | if (windowClass && windowClass->getClassLongA(GCL_STYLE) & CS_DBLCLKS)
|
---|
1105 | {
|
---|
1106 | win32msg = WM_MBUTTONDBLCLK;
|
---|
1107 | win32ncmsg = WM_NCMBUTTONDBLCLK;
|
---|
1108 | } else
|
---|
1109 | {
|
---|
1110 | MsgButton(BUTTON_MIDDLEDOWN,ncx,ncy,clx,cly);
|
---|
1111 | return MsgButton(BUTTON_MIDDLEUP,ncx,ncy,clx,cly);
|
---|
1112 | }
|
---|
1113 | break;
|
---|
1114 | default:
|
---|
1115 | dprintf(("Win32BaseWindow::Button: invalid msg!!!!"));
|
---|
1116 | return 1;
|
---|
1117 | }
|
---|
1118 |
|
---|
1119 | SendInternalMessageA(WM_SETCURSOR, Win32Hwnd, MAKELONG(lastHitTestVal, win32ncmsg));
|
---|
1120 |
|
---|
1121 | //WM_NC*BUTTON* is posted when the cursor is in a non-client area of the window
|
---|
1122 | if(lastHitTestVal != HTCLIENT) {
|
---|
1123 | return SendInternalMessageA(win32ncmsg, lastHitTestVal, MAKELONG(ncx, ncy)); //TODO:
|
---|
1124 | }
|
---|
1125 | return SendInternalMessageA(win32msg, 0, MAKELONG(clx, cly));
|
---|
1126 | }
|
---|
1127 | //******************************************************************************
|
---|
1128 | //******************************************************************************
|
---|
1129 | ULONG Win32BaseWindow::MsgMouseMove(ULONG keystate, ULONG x, ULONG y)
|
---|
1130 | {
|
---|
1131 | ULONG winstate = 0;
|
---|
1132 | ULONG setcursormsg = WM_MOUSEMOVE;
|
---|
1133 |
|
---|
1134 | if(keystate & WMMOVE_LBUTTON)
|
---|
1135 | winstate |= MK_LBUTTON;
|
---|
1136 | if(keystate & WMMOVE_RBUTTON)
|
---|
1137 | winstate |= MK_RBUTTON;
|
---|
1138 | if(keystate & WMMOVE_MBUTTON)
|
---|
1139 | winstate |= MK_MBUTTON;
|
---|
1140 | if(keystate & WMMOVE_SHIFT)
|
---|
1141 | winstate |= MK_SHIFT;
|
---|
1142 | if(keystate & WMMOVE_CTRL)
|
---|
1143 | winstate |= MK_CONTROL;
|
---|
1144 |
|
---|
1145 | if(lastHitTestVal != HTCLIENT) {
|
---|
1146 | setcursormsg = WM_NCMOUSEMOVE;
|
---|
1147 | }
|
---|
1148 | //TODO: hiword should be 0 if window enters menu mode (SDK docs)
|
---|
1149 | SendInternalMessageA(WM_SETCURSOR, Win32Hwnd, MAKELONG(lastHitTestVal, setcursormsg));
|
---|
1150 |
|
---|
1151 | //WM_NCMOUSEMOVE is posted when the cursor moves into a non-client area of the window
|
---|
1152 | if(lastHitTestVal != HTCLIENT) {
|
---|
1153 | SendInternalMessageA(WM_NCMOUSEMOVE, lastHitTestVal, MAKELONG(x, y));
|
---|
1154 | }
|
---|
1155 | return SendInternalMessageA(WM_MOUSEMOVE, keystate, MAKELONG(x, y));
|
---|
1156 | }
|
---|
1157 | //******************************************************************************
|
---|
1158 | //******************************************************************************
|
---|
1159 | ULONG Win32BaseWindow::MsgPaint(ULONG tmp1, BOOL select)
|
---|
1160 | {
|
---|
1161 | if (select && isIcon)
|
---|
1162 | return SendInternalMessageA(WM_PAINTICON, 0, 0);
|
---|
1163 | else
|
---|
1164 | return SendInternalMessageA(WM_PAINT, 0, 0);
|
---|
1165 | }
|
---|
1166 | //******************************************************************************
|
---|
1167 | //TODO: Is the clipper region of the window DC equal to the invalidated rectangle?
|
---|
1168 | // (or are we simply erasing too much here)
|
---|
1169 | //******************************************************************************
|
---|
1170 | ULONG Win32BaseWindow::MsgEraseBackGround(HDC hdc)
|
---|
1171 | {
|
---|
1172 | ULONG rc;
|
---|
1173 | HDC hdcErase = hdc;
|
---|
1174 |
|
---|
1175 | if (hdcErase == 0)
|
---|
1176 | hdcErase = O32_GetDC(OS2Hwnd);
|
---|
1177 |
|
---|
1178 | if(isIcon)
|
---|
1179 | rc = SendInternalMessageA(WM_ICONERASEBKGND, hdcErase, 0);
|
---|
1180 | else
|
---|
1181 | rc = SendInternalMessageA(WM_ERASEBKGND, hdcErase, 0);
|
---|
1182 | if (hdc == 0)
|
---|
1183 | O32_ReleaseDC(OS2Hwnd, hdcErase);
|
---|
1184 | return (rc);
|
---|
1185 | }
|
---|
1186 | //******************************************************************************
|
---|
1187 | //******************************************************************************
|
---|
1188 | ULONG Win32BaseWindow::MsgSetText(LPSTR lpsz, LONG cch)
|
---|
1189 | {
|
---|
1190 | if(isUnicode) {
|
---|
1191 | return SendInternalMessageW(WM_SETTEXT, 0, (LPARAM)lpsz);
|
---|
1192 | }
|
---|
1193 | else return SendInternalMessageA(WM_SETTEXT, 0, (LPARAM)lpsz);
|
---|
1194 | }
|
---|
1195 | //******************************************************************************
|
---|
1196 | //TODO: in- or excluding terminating 0?
|
---|
1197 | //******************************************************************************
|
---|
1198 | ULONG Win32BaseWindow::MsgGetTextLength()
|
---|
1199 | {
|
---|
1200 | return SendInternalMessageA(WM_GETTEXTLENGTH, 0, 0);
|
---|
1201 | }
|
---|
1202 | //******************************************************************************
|
---|
1203 | //******************************************************************************
|
---|
1204 | char *Win32BaseWindow::MsgGetText()
|
---|
1205 | {
|
---|
1206 | if(isUnicode) {
|
---|
1207 | SendInternalMessageW(WM_GETTEXT, wndNameLength, (LPARAM)windowNameW);
|
---|
1208 | }
|
---|
1209 | else {
|
---|
1210 | SendInternalMessageA(WM_GETTEXT, wndNameLength, (LPARAM)windowNameA);
|
---|
1211 | }
|
---|
1212 | return windowNameA;
|
---|
1213 | }
|
---|
1214 | //******************************************************************************
|
---|
1215 | //******************************************************************************
|
---|
1216 | BOOL Win32BaseWindow::isMDIClient()
|
---|
1217 | {
|
---|
1218 | return FALSE;
|
---|
1219 | }
|
---|
1220 | //******************************************************************************
|
---|
1221 | //******************************************************************************
|
---|
1222 | BOOL Win32BaseWindow::isMDIChild()
|
---|
1223 | {
|
---|
1224 | return FALSE;
|
---|
1225 | }
|
---|
1226 | //******************************************************************************
|
---|
1227 | //TODO: Not complete
|
---|
1228 | //******************************************************************************
|
---|
1229 | BOOL Win32BaseWindow::isFrameWindow()
|
---|
1230 | {
|
---|
1231 | // if(isMDIChild() || IsDialog() || (getParent() == NULL || getParent() == windowDesktop) && ((dwStyle & WS_CAPTION) == WS_CAPTION))
|
---|
1232 | if((dwStyle & WS_CAPTION) == WS_CAPTION || dwStyle & (WS_VSCROLL|WS_HSCROLL))
|
---|
1233 | return TRUE;
|
---|
1234 |
|
---|
1235 | return FALSE;
|
---|
1236 | }
|
---|
1237 | //******************************************************************************
|
---|
1238 | //TODO: Not complete (flags)
|
---|
1239 | //******************************************************************************
|
---|
1240 | SCROLLBAR_INFO *Win32BaseWindow::getScrollInfo(int nBar)
|
---|
1241 | {
|
---|
1242 | switch(nBar) {
|
---|
1243 | case SB_HORZ:
|
---|
1244 | if(horzScrollInfo) {
|
---|
1245 | //CB:horzScrollInfo->CurVal = OSLibWinGetScrollPos(OS2HwndFrame, hwndHorzScroll);
|
---|
1246 | return horzScrollInfo;
|
---|
1247 | }
|
---|
1248 | break;
|
---|
1249 | case SB_VERT:
|
---|
1250 | if(vertScrollInfo) {
|
---|
1251 | //CB:vertScrollInfo->CurVal = OSLibWinGetScrollPos(OS2HwndFrame, hwndVertScroll);
|
---|
1252 | return vertScrollInfo;
|
---|
1253 | }
|
---|
1254 | break;
|
---|
1255 | }
|
---|
1256 | return NULL;
|
---|
1257 | }
|
---|
1258 | /***********************************************************************/
|
---|
1259 | /***********************************************************************/
|
---|
1260 | VOID Win32BaseWindow::subclassScrollBars(BOOL subHorz,BOOL subVert)
|
---|
1261 | {
|
---|
1262 | SCROLL_SubclassScrollBars(subHorz ? hwndHorzScroll:0,subVert ? hwndVertScroll:0);
|
---|
1263 | }
|
---|
1264 | /***********************************************************************
|
---|
1265 | * NC_HandleSysCommand
|
---|
1266 | *
|
---|
1267 | * Handle a WM_SYSCOMMAND message. Called from DefWindowProc().
|
---|
1268 | *
|
---|
1269 | * TODO: Not done (see #if 0)
|
---|
1270 | */
|
---|
1271 | LONG Win32BaseWindow::HandleSysCommand(WPARAM wParam, POINT *pt32)
|
---|
1272 | {
|
---|
1273 | UINT uCommand = wParam & 0xFFF0;
|
---|
1274 |
|
---|
1275 | if (getStyle() & WS_CHILD && uCommand != SC_KEYMENU )
|
---|
1276 | ScreenToClient(getParent()->getWindowHandle(), pt32 );
|
---|
1277 |
|
---|
1278 | switch (uCommand)
|
---|
1279 | {
|
---|
1280 | #if 0
|
---|
1281 | case SC_SIZE:
|
---|
1282 | case SC_MOVE:
|
---|
1283 | NC_DoSizeMove( hwnd, wParam );
|
---|
1284 | break;
|
---|
1285 | #endif
|
---|
1286 |
|
---|
1287 | case SC_MINIMIZE:
|
---|
1288 | ShowWindow(SW_MINIMIZE);
|
---|
1289 | break;
|
---|
1290 |
|
---|
1291 | case SC_MAXIMIZE:
|
---|
1292 | ShowWindow(SW_MAXIMIZE);
|
---|
1293 | break;
|
---|
1294 |
|
---|
1295 | case SC_RESTORE:
|
---|
1296 | ShowWindow(SW_RESTORE);
|
---|
1297 | break;
|
---|
1298 |
|
---|
1299 | case SC_CLOSE:
|
---|
1300 | return SendMessageA(WM_CLOSE, 0, 0);
|
---|
1301 |
|
---|
1302 | #if 0
|
---|
1303 | case SC_VSCROLL:
|
---|
1304 | case SC_HSCROLL:
|
---|
1305 | NC_TrackScrollBar( hwnd, wParam, pt32 );
|
---|
1306 | break;
|
---|
1307 |
|
---|
1308 | case SC_MOUSEMENU:
|
---|
1309 | MENU_TrackMouseMenuBar( wndPtr, wParam & 0x000F, pt32 );
|
---|
1310 | break;
|
---|
1311 |
|
---|
1312 | case SC_KEYMENU:
|
---|
1313 | MENU_TrackKbdMenuBar( wndPtr , wParam , pt.x );
|
---|
1314 | break;
|
---|
1315 |
|
---|
1316 | case SC_TASKLIST:
|
---|
1317 | WinExec( "taskman.exe", SW_SHOWNORMAL );
|
---|
1318 | break;
|
---|
1319 |
|
---|
1320 | case SC_SCREENSAVE:
|
---|
1321 | if (wParam == SC_ABOUTWINE)
|
---|
1322 | ShellAboutA(hwnd, "Odin", WINE_RELEASE_INFO, 0);
|
---|
1323 | else
|
---|
1324 | if (wParam == SC_PUTMARK)
|
---|
1325 | dprintf(("Mark requested by user\n"));
|
---|
1326 | break;
|
---|
1327 |
|
---|
1328 | case SC_HOTKEY:
|
---|
1329 | case SC_ARRANGE:
|
---|
1330 | case SC_NEXTWINDOW:
|
---|
1331 | case SC_PREVWINDOW:
|
---|
1332 | break;
|
---|
1333 | #endif
|
---|
1334 | }
|
---|
1335 | return 0;
|
---|
1336 | }
|
---|
1337 | //******************************************************************************
|
---|
1338 | //******************************************************************************
|
---|
1339 | LRESULT Win32BaseWindow::DefWndControlColor(UINT ctlType, HDC hdc)
|
---|
1340 | {
|
---|
1341 | //SvL: Set background color to default button color (not window (white))
|
---|
1342 | if(ctlType == CTLCOLOR_BTN)
|
---|
1343 | {
|
---|
1344 | SetBkColor(hdc, GetSysColor(COLOR_BTNFACE));
|
---|
1345 | SetTextColor(hdc, GetSysColor(COLOR_WINDOWTEXT));
|
---|
1346 | return GetSysColorBrush(COLOR_BTNFACE);
|
---|
1347 | }
|
---|
1348 | //SvL: Set background color to default dialog color if window is dialog
|
---|
1349 | if((ctlType == CTLCOLOR_DLG || ctlType == CTLCOLOR_STATIC) && IsDialog()) {
|
---|
1350 | SetBkColor(hdc, GetSysColor(COLOR_BTNFACE));
|
---|
1351 | SetTextColor(hdc, GetSysColor(COLOR_WINDOWTEXT));
|
---|
1352 | return GetSysColorBrush(COLOR_BTNFACE);
|
---|
1353 | }
|
---|
1354 |
|
---|
1355 | if( ctlType == CTLCOLOR_SCROLLBAR)
|
---|
1356 | {
|
---|
1357 | HBRUSH hb = GetSysColorBrush(COLOR_SCROLLBAR);
|
---|
1358 | COLORREF bk = GetSysColor(COLOR_3DHILIGHT);
|
---|
1359 | SetTextColor( hdc, GetSysColor(COLOR_3DFACE));
|
---|
1360 | SetBkColor( hdc, bk);
|
---|
1361 |
|
---|
1362 | //TODO?
|
---|
1363 | #if 0
|
---|
1364 | /* if COLOR_WINDOW happens to be the same as COLOR_3DHILIGHT
|
---|
1365 | * we better use 0x55aa bitmap brush to make scrollbar's background
|
---|
1366 | * look different from the window background.
|
---|
1367 | */
|
---|
1368 | if (bk == GetSysColor(COLOR_WINDOW)) {
|
---|
1369 | return CACHE_GetPattern55AABrush();
|
---|
1370 | }
|
---|
1371 | #endif
|
---|
1372 | UnrealizeObject( hb );
|
---|
1373 | return (LRESULT)hb;
|
---|
1374 | }
|
---|
1375 |
|
---|
1376 | SetTextColor( hdc, GetSysColor(COLOR_WINDOWTEXT));
|
---|
1377 |
|
---|
1378 | if ((ctlType == CTLCOLOR_EDIT) || (ctlType == CTLCOLOR_LISTBOX))
|
---|
1379 | {
|
---|
1380 | SetBkColor( hdc, GetSysColor(COLOR_WINDOW) );
|
---|
1381 | }
|
---|
1382 | else
|
---|
1383 | {
|
---|
1384 | SetBkColor( hdc, GetSysColor(COLOR_3DFACE) );
|
---|
1385 | return (LRESULT)GetSysColorBrush(COLOR_3DFACE);
|
---|
1386 | }
|
---|
1387 | return (LRESULT)GetSysColorBrush(COLOR_WINDOW);
|
---|
1388 | }
|
---|
1389 | //******************************************************************************
|
---|
1390 | //******************************************************************************
|
---|
1391 | LRESULT Win32BaseWindow::DefWindowProcA(UINT Msg, WPARAM wParam, LPARAM lParam)
|
---|
1392 | {
|
---|
1393 | switch(Msg)
|
---|
1394 | {
|
---|
1395 | case WM_CLOSE:
|
---|
1396 | DestroyWindow();
|
---|
1397 | return 0;
|
---|
1398 |
|
---|
1399 | case WM_GETTEXTLENGTH:
|
---|
1400 | return wndNameLength;
|
---|
1401 |
|
---|
1402 | case WM_GETTEXT: //TODO: SS_ICON controls
|
---|
1403 | strncpy((LPSTR)lParam, windowNameA, wParam);
|
---|
1404 | return min(wndNameLength, wParam);
|
---|
1405 |
|
---|
1406 | case WM_SETTEXT:
|
---|
1407 | if(!fInternalMsg) {
|
---|
1408 | return SetWindowTextA((LPSTR)lParam);
|
---|
1409 | }
|
---|
1410 | else return 0;
|
---|
1411 |
|
---|
1412 | case WM_SETREDRAW:
|
---|
1413 | if(wParam)
|
---|
1414 | SetWindowLongA (GWL_STYLE, GetWindowLongA (GWL_STYLE) | WS_VISIBLE);
|
---|
1415 | else SetWindowLongA (GWL_STYLE, GetWindowLongA (GWL_STYLE) & ~WS_VISIBLE);
|
---|
1416 |
|
---|
1417 | return 0; //TODO
|
---|
1418 |
|
---|
1419 | case WM_NCCREATE:
|
---|
1420 | return(TRUE);
|
---|
1421 |
|
---|
1422 | case WM_NCCALCSIZE:
|
---|
1423 | return NCHandleCalcSize(wParam, (NCCALCSIZE_PARAMS *)lParam);
|
---|
1424 |
|
---|
1425 | case WM_CTLCOLORMSGBOX:
|
---|
1426 | case WM_CTLCOLOREDIT:
|
---|
1427 | case WM_CTLCOLORLISTBOX:
|
---|
1428 | case WM_CTLCOLORBTN:
|
---|
1429 | case WM_CTLCOLORDLG:
|
---|
1430 | case WM_CTLCOLORSTATIC:
|
---|
1431 | case WM_CTLCOLORSCROLLBAR:
|
---|
1432 | return DefWndControlColor(Msg - WM_CTLCOLORMSGBOX, (HDC)wParam);
|
---|
1433 |
|
---|
1434 | case WM_CTLCOLOR:
|
---|
1435 | return DefWndControlColor(HIWORD(lParam), (HDC)wParam);
|
---|
1436 |
|
---|
1437 | case WM_VKEYTOITEM:
|
---|
1438 | case WM_CHARTOITEM:
|
---|
1439 | return -1;
|
---|
1440 |
|
---|
1441 | case WM_PARENTNOTIFY:
|
---|
1442 | return 0;
|
---|
1443 |
|
---|
1444 | case WM_MOUSEACTIVATE:
|
---|
1445 | {
|
---|
1446 | DWORD dwStyle = GetWindowLongA(GWL_STYLE);
|
---|
1447 | DWORD dwExStyle = GetWindowLongA(GWL_EXSTYLE);
|
---|
1448 | dprintf(("DefWndProc: WM_MOUSEACTIVATE for %x Msg %s", Win32Hwnd, GetMsgText(HIWORD(lParam))));
|
---|
1449 | if(dwStyle & WS_CHILD && !(dwExStyle & WS_EX_NOPARENTNOTIFY) )
|
---|
1450 | {
|
---|
1451 | if(getParent()) {
|
---|
1452 | LRESULT rc = getParent()->SendMessageA(WM_MOUSEACTIVATE, wParam, lParam );
|
---|
1453 | if(rc) return rc;
|
---|
1454 | }
|
---|
1455 | }
|
---|
1456 | return (LOWORD(lParam) == HTCAPTION) ? MA_NOACTIVATE : MA_ACTIVATE;
|
---|
1457 | }
|
---|
1458 | case WM_SETCURSOR:
|
---|
1459 | {
|
---|
1460 | DWORD dwStyle = GetWindowLongA(GWL_STYLE);
|
---|
1461 | DWORD dwExStyle = GetWindowLongA(GWL_EXSTYLE);
|
---|
1462 | dprintf(("DefWndProc: WM_SETCURSOR for %x Msg %s", Win32Hwnd, GetMsgText(HIWORD(lParam))));
|
---|
1463 | if(dwStyle & WS_CHILD && !(dwExStyle & WS_EX_NOPARENTNOTIFY) )
|
---|
1464 | {
|
---|
1465 | if(getParent()) {
|
---|
1466 | LRESULT rc = getParent()->SendMessageA(WM_SETCURSOR, wParam, lParam);
|
---|
1467 | if(rc) return rc;
|
---|
1468 | }
|
---|
1469 | }
|
---|
1470 | return 1;
|
---|
1471 | }
|
---|
1472 | case WM_MOUSEMOVE:
|
---|
1473 | return 1; //Let OS/2 change the mouse cursor back to the default
|
---|
1474 |
|
---|
1475 | case WM_WINDOWPOSCHANGED:
|
---|
1476 | {
|
---|
1477 |
|
---|
1478 | /* undocumented SWP flags - from SDK 3.1 */
|
---|
1479 | #define SWP_NOCLIENTSIZE 0x0800
|
---|
1480 | #define SWP_NOCLIENTMOVE 0x1000
|
---|
1481 |
|
---|
1482 | PWINDOWPOS wpos = (PWINDOWPOS)lParam;
|
---|
1483 | WPARAM wp = SIZE_RESTORED;
|
---|
1484 |
|
---|
1485 | if (!(wpos->flags & SWP_NOMOVE) && !(wpos->flags & SWP_NOCLIENTMOVE))
|
---|
1486 | SendMessageA(WM_MOVE, 0, MAKELONG(rectClient.left, rectClient.top));
|
---|
1487 |
|
---|
1488 | if (!(wpos->flags & SWP_NOSIZE) && !(wpos->flags & SWP_NOCLIENTSIZE))
|
---|
1489 | {
|
---|
1490 | if (dwStyle & WS_MAXIMIZE) wp = SIZE_MAXIMIZED;
|
---|
1491 | else if (dwStyle & WS_MINIMIZE) wp = SIZE_MINIMIZED;
|
---|
1492 |
|
---|
1493 | SendMessageA(WM_SIZE, wp, MAKELONG(rectClient.right - rectClient.left,
|
---|
1494 | rectClient.bottom - rectClient.top));
|
---|
1495 | }
|
---|
1496 | return 0;
|
---|
1497 | }
|
---|
1498 | case WM_WINDOWPOSCHANGING:
|
---|
1499 | return HandleWindowPosChanging((WINDOWPOS *)lParam);
|
---|
1500 |
|
---|
1501 | case WM_ERASEBKGND:
|
---|
1502 | case WM_ICONERASEBKGND:
|
---|
1503 | {
|
---|
1504 | RECT rect;
|
---|
1505 | int rc;
|
---|
1506 |
|
---|
1507 | if (!windowClass || !windowClass->getBackgroundBrush()) return 0;
|
---|
1508 |
|
---|
1509 | rc = GetClipBox( (HDC)wParam, &rect );
|
---|
1510 | if ((rc == SIMPLEREGION) || (rc == COMPLEXREGION))
|
---|
1511 | FillRect( (HDC)wParam, &rect, windowClass->getBackgroundBrush());
|
---|
1512 |
|
---|
1513 | return 1;
|
---|
1514 | }
|
---|
1515 | case WM_GETDLGCODE:
|
---|
1516 | return 0;
|
---|
1517 |
|
---|
1518 | case WM_NCLBUTTONDOWN:
|
---|
1519 | case WM_NCLBUTTONUP:
|
---|
1520 | case WM_NCLBUTTONDBLCLK:
|
---|
1521 | case WM_NCRBUTTONUP:
|
---|
1522 | case WM_NCRBUTTONDOWN:
|
---|
1523 | case WM_NCRBUTTONDBLCLK:
|
---|
1524 | case WM_NCMBUTTONDOWN:
|
---|
1525 | case WM_NCMBUTTONUP:
|
---|
1526 | case WM_NCMBUTTONDBLCLK:
|
---|
1527 | return 0; //TODO: Send WM_SYSCOMMAND if required
|
---|
1528 |
|
---|
1529 | case WM_NCHITTEST: //TODO: Calculate position of
|
---|
1530 | return HTCLIENT;
|
---|
1531 |
|
---|
1532 | case WM_SYSCOMMAND:
|
---|
1533 | {
|
---|
1534 | POINT point;
|
---|
1535 |
|
---|
1536 | point.x = LOWORD(lParam);
|
---|
1537 | point.y = HIWORD(lParam);
|
---|
1538 | return HandleSysCommand(wParam, &point);
|
---|
1539 | }
|
---|
1540 |
|
---|
1541 | case WM_SYSKEYDOWN:
|
---|
1542 | if(HIWORD(lParam) & KEYDATA_ALT)
|
---|
1543 | {
|
---|
1544 | if(wParam == VK_F4) /* try to close the window */
|
---|
1545 | {
|
---|
1546 | Win32BaseWindow *window = GetTopParent();
|
---|
1547 | if(window && !(window->getClass()->getStyle() & CS_NOCLOSE) )
|
---|
1548 | window->PostMessageA(WM_SYSCOMMAND, SC_CLOSE, 0);
|
---|
1549 | }
|
---|
1550 | }
|
---|
1551 | return 0;
|
---|
1552 |
|
---|
1553 | case WM_QUERYOPEN:
|
---|
1554 | case WM_QUERYENDSESSION:
|
---|
1555 | return 1;
|
---|
1556 |
|
---|
1557 | case WM_NOTIFYFORMAT:
|
---|
1558 | if (IsUnicode()) return NFR_UNICODE;
|
---|
1559 | else return NFR_ANSI;
|
---|
1560 |
|
---|
1561 | case WM_SETICON:
|
---|
1562 | case WM_GETICON:
|
---|
1563 | {
|
---|
1564 | LRESULT result = 0;
|
---|
1565 | if (!windowClass) return result;
|
---|
1566 | int index = GCL_HICON;
|
---|
1567 |
|
---|
1568 | if (wParam == ICON_SMALL)
|
---|
1569 | index = GCL_HICONSM;
|
---|
1570 |
|
---|
1571 | result = windowClass->getClassLongA(index);
|
---|
1572 |
|
---|
1573 | if (Msg == WM_SETICON)
|
---|
1574 | windowClass->setClassLongA(index, lParam);
|
---|
1575 |
|
---|
1576 | return result;
|
---|
1577 | }
|
---|
1578 | case WM_NOTIFY:
|
---|
1579 | return 0; //comctl32 controls expect this
|
---|
1580 |
|
---|
1581 | default:
|
---|
1582 | if(Msg > WM_USER) {
|
---|
1583 | return 0;
|
---|
1584 | }
|
---|
1585 | return 1;
|
---|
1586 | }
|
---|
1587 | }
|
---|
1588 | //******************************************************************************
|
---|
1589 | //******************************************************************************
|
---|
1590 | LRESULT Win32BaseWindow::DefWindowProcW(UINT Msg, WPARAM wParam, LPARAM lParam)
|
---|
1591 | {
|
---|
1592 | switch(Msg)
|
---|
1593 | {
|
---|
1594 | case WM_GETTEXTLENGTH:
|
---|
1595 | return wndNameLength;
|
---|
1596 |
|
---|
1597 | case WM_GETTEXT: //TODO: SS_ICON controls
|
---|
1598 | lstrcpynW((LPWSTR)lParam, windowNameW, wParam);
|
---|
1599 | return min(wndNameLength, wParam);
|
---|
1600 |
|
---|
1601 | case WM_SETTEXT:
|
---|
1602 | if(!fInternalMsg) {
|
---|
1603 | return SetWindowTextW((LPWSTR)lParam);
|
---|
1604 | }
|
---|
1605 | else return 0;
|
---|
1606 |
|
---|
1607 | default:
|
---|
1608 | return DefWindowProcA(Msg, wParam, lParam);
|
---|
1609 | }
|
---|
1610 | }
|
---|
1611 | //******************************************************************************
|
---|
1612 | //******************************************************************************
|
---|
1613 | LRESULT Win32BaseWindow::SendMessageA(ULONG Msg, WPARAM wParam, LPARAM lParam)
|
---|
1614 | {
|
---|
1615 | LRESULT rc;
|
---|
1616 | BOOL fInternalMsgBackup = fInternalMsg;
|
---|
1617 |
|
---|
1618 | //SvL: Some Wine controls send WM_COMMAND messages when they receive the focus -> apps don't like to
|
---|
1619 | // receive those before they get their WM_CREATE message
|
---|
1620 | //NOTE: May need to refuse more messages
|
---|
1621 | if(fCreated == FALSE && Msg == WM_COMMAND) {
|
---|
1622 | dprintf(("SendMessageA BEFORE creation! %s for %x %x %x", GetMsgText(Msg), getWindowHandle(), wParam, lParam));
|
---|
1623 | return 0;
|
---|
1624 | }
|
---|
1625 |
|
---|
1626 | DebugPrintMessage(getWindowHandle(), Msg, wParam, lParam, FALSE, FALSE);
|
---|
1627 |
|
---|
1628 | if(HkCBT::OS2HkCBTProc(getWindowHandle(), Msg, wParam, lParam) == TRUE) {//hook swallowed msg
|
---|
1629 | return(0);
|
---|
1630 | }
|
---|
1631 | fInternalMsg = FALSE;
|
---|
1632 | switch(Msg)
|
---|
1633 | {
|
---|
1634 | case WM_CREATE:
|
---|
1635 | {
|
---|
1636 | if(win32wndproc(getWindowHandle(), WM_CREATE, 0, lParam) == -1) {
|
---|
1637 | dprintf(("WM_CREATE returned -1\n"));
|
---|
1638 | rc = -1; //don't create window
|
---|
1639 | break;
|
---|
1640 | }
|
---|
1641 | NotifyParent(Msg, wParam, lParam);
|
---|
1642 |
|
---|
1643 | rc = 0;
|
---|
1644 | break;
|
---|
1645 | }
|
---|
1646 | case WM_SETTEXT:
|
---|
1647 | rc = win32wndproc(getWindowHandle(), WM_SETTEXT, wParam, lParam);
|
---|
1648 | break;
|
---|
1649 |
|
---|
1650 | case WM_LBUTTONDOWN:
|
---|
1651 | case WM_MBUTTONDOWN:
|
---|
1652 | case WM_RBUTTONDOWN:
|
---|
1653 | NotifyParent(Msg, wParam, lParam);
|
---|
1654 | rc = win32wndproc(getWindowHandle(), Msg, wParam, lParam);
|
---|
1655 | break;
|
---|
1656 |
|
---|
1657 | case WM_DESTROY:
|
---|
1658 | win32wndproc(getWindowHandle(), WM_NCDESTROY, 0, 0);
|
---|
1659 | rc = win32wndproc(getWindowHandle(), WM_DESTROY, 0, 0);
|
---|
1660 | break;
|
---|
1661 |
|
---|
1662 | default:
|
---|
1663 | rc = win32wndproc(getWindowHandle(), Msg, wParam, lParam);
|
---|
1664 | break;
|
---|
1665 | }
|
---|
1666 | fInternalMsg = fInternalMsgBackup;
|
---|
1667 | return rc;
|
---|
1668 | }
|
---|
1669 | //******************************************************************************
|
---|
1670 | //******************************************************************************
|
---|
1671 | LRESULT Win32BaseWindow::SendMessageW(ULONG Msg, WPARAM wParam, LPARAM lParam)
|
---|
1672 | {
|
---|
1673 | LRESULT rc;
|
---|
1674 | BOOL fInternalMsgBackup = fInternalMsg;
|
---|
1675 |
|
---|
1676 | //SvL: Some Wine controls send WM_COMMAND messages when they receive the focus -> apps don't like to
|
---|
1677 | // receive those before they get their WM_CREATE message
|
---|
1678 | //NOTE: May need to refuse more messages
|
---|
1679 | if(fCreated == FALSE && Msg == WM_COMMAND) {
|
---|
1680 | dprintf(("SendMessageA BEFORE creation! %s for %x %x %x", GetMsgText(Msg), getWindowHandle(), wParam, lParam));
|
---|
1681 | return 0;
|
---|
1682 | }
|
---|
1683 |
|
---|
1684 | DebugPrintMessage(getWindowHandle(), Msg, wParam, lParam, TRUE, FALSE);
|
---|
1685 |
|
---|
1686 | if(HkCBT::OS2HkCBTProc(getWindowHandle(), Msg, wParam, lParam) == TRUE) {//hook swallowed msg
|
---|
1687 | return(0);
|
---|
1688 | }
|
---|
1689 | fInternalMsg = FALSE;
|
---|
1690 | switch(Msg)
|
---|
1691 | {
|
---|
1692 | case WM_CREATE:
|
---|
1693 | {
|
---|
1694 | if(win32wndproc(getWindowHandle(), WM_CREATE, 0, lParam) == -1) {
|
---|
1695 | dprintf(("WM_CREATE returned -1\n"));
|
---|
1696 | rc = -1; //don't create window
|
---|
1697 | break;
|
---|
1698 | }
|
---|
1699 | NotifyParent(Msg, wParam, lParam);
|
---|
1700 |
|
---|
1701 | rc = 0;
|
---|
1702 | break;
|
---|
1703 | }
|
---|
1704 | case WM_SETTEXT:
|
---|
1705 | rc = win32wndproc(getWindowHandle(), WM_SETTEXT, wParam, lParam);
|
---|
1706 | break;
|
---|
1707 |
|
---|
1708 | case WM_LBUTTONDOWN:
|
---|
1709 | case WM_MBUTTONDOWN:
|
---|
1710 | case WM_RBUTTONDOWN:
|
---|
1711 | NotifyParent(Msg, wParam, lParam);
|
---|
1712 | rc = win32wndproc(getWindowHandle(), Msg, wParam, lParam);
|
---|
1713 | break;
|
---|
1714 |
|
---|
1715 | case WM_DESTROY:
|
---|
1716 | win32wndproc(getWindowHandle(), WM_NCDESTROY, 0, 0);
|
---|
1717 | rc = win32wndproc(getWindowHandle(), WM_DESTROY, 0, 0);
|
---|
1718 | break;
|
---|
1719 |
|
---|
1720 | default:
|
---|
1721 | rc = win32wndproc(getWindowHandle(), Msg, wParam, lParam);
|
---|
1722 | break;
|
---|
1723 | }
|
---|
1724 | fInternalMsg = fInternalMsgBackup;
|
---|
1725 | return rc;
|
---|
1726 | }
|
---|
1727 | //******************************************************************************
|
---|
1728 | //Called as a result of an OS/2 message
|
---|
1729 | //******************************************************************************
|
---|
1730 | LRESULT Win32BaseWindow::SendInternalMessageA(ULONG Msg, WPARAM wParam, LPARAM lParam)
|
---|
1731 | {
|
---|
1732 | LRESULT rc;
|
---|
1733 | BOOL fInternalMsgBackup = fInternalMsg;
|
---|
1734 |
|
---|
1735 | DebugPrintMessage(getWindowHandle(), Msg, wParam, lParam, FALSE, TRUE);
|
---|
1736 |
|
---|
1737 | if(HkCBT::OS2HkCBTProc(getWindowHandle(), Msg, wParam, lParam) == TRUE) {//hook swallowed msg
|
---|
1738 | return(0);
|
---|
1739 | }
|
---|
1740 | fInternalMsg = TRUE;
|
---|
1741 | switch(Msg)
|
---|
1742 | {
|
---|
1743 | case WM_CREATE:
|
---|
1744 | {
|
---|
1745 | if(win32wndproc(getWindowHandle(), WM_CREATE, 0, lParam) == -1) {
|
---|
1746 | dprintf(("WM_CREATE returned -1\n"));
|
---|
1747 | rc = -1; //don't create window
|
---|
1748 | break;
|
---|
1749 | }
|
---|
1750 | NotifyParent(Msg, wParam, lParam);
|
---|
1751 | rc = 0;
|
---|
1752 | break;
|
---|
1753 | }
|
---|
1754 | case WM_LBUTTONDOWN:
|
---|
1755 | case WM_MBUTTONDOWN:
|
---|
1756 | case WM_RBUTTONDOWN:
|
---|
1757 | NotifyParent(Msg, wParam, lParam);
|
---|
1758 | rc = win32wndproc(getWindowHandle(), Msg, wParam, lParam);
|
---|
1759 | break;
|
---|
1760 |
|
---|
1761 | case WM_DESTROY:
|
---|
1762 | win32wndproc(getWindowHandle(), WM_NCDESTROY, 0, 0);
|
---|
1763 | rc = win32wndproc(getWindowHandle(), WM_DESTROY, 0, 0);
|
---|
1764 | break;
|
---|
1765 | default:
|
---|
1766 | rc = win32wndproc(getWindowHandle(), Msg, wParam, lParam);
|
---|
1767 | break;
|
---|
1768 | }
|
---|
1769 | fInternalMsg = fInternalMsgBackup;
|
---|
1770 | return rc;
|
---|
1771 | }
|
---|
1772 | //******************************************************************************
|
---|
1773 | //Called as a result of an OS/2 message
|
---|
1774 | //todo, unicode msgs (WM_SETTEXT etc)
|
---|
1775 | //******************************************************************************
|
---|
1776 | LRESULT Win32BaseWindow::SendInternalMessageW(ULONG Msg, WPARAM wParam, LPARAM lParam)
|
---|
1777 | {
|
---|
1778 | LRESULT rc;
|
---|
1779 | BOOL fInternalMsgBackup = fInternalMsg;
|
---|
1780 |
|
---|
1781 | DebugPrintMessage(getWindowHandle(), Msg, wParam, lParam, TRUE, TRUE);
|
---|
1782 |
|
---|
1783 | if(HkCBT::OS2HkCBTProc(getWindowHandle(), Msg, wParam, lParam) == TRUE) {//hook swallowed msg
|
---|
1784 | return(0);
|
---|
1785 | }
|
---|
1786 | fInternalMsg = TRUE;
|
---|
1787 | switch(Msg)
|
---|
1788 | {
|
---|
1789 | case WM_CREATE:
|
---|
1790 | {
|
---|
1791 | if(win32wndproc(getWindowHandle(), WM_CREATE, 0, lParam) == -1) {
|
---|
1792 | dprintf(("WM_CREATE returned -1\n"));
|
---|
1793 | rc = -1; //don't create window
|
---|
1794 | break;
|
---|
1795 | }
|
---|
1796 | NotifyParent(Msg, wParam, lParam);
|
---|
1797 | rc = 0;
|
---|
1798 | break;
|
---|
1799 | }
|
---|
1800 | case WM_LBUTTONDOWN:
|
---|
1801 | case WM_MBUTTONDOWN:
|
---|
1802 | case WM_RBUTTONDOWN:
|
---|
1803 | NotifyParent(Msg, wParam, lParam);
|
---|
1804 | rc = win32wndproc(getWindowHandle(), Msg, wParam, lParam);
|
---|
1805 | break;
|
---|
1806 |
|
---|
1807 | case WM_DESTROY:
|
---|
1808 | win32wndproc(getWindowHandle(), WM_NCDESTROY, 0, 0);
|
---|
1809 | rc = win32wndproc(getWindowHandle(), WM_DESTROY, 0, 0);
|
---|
1810 | break;
|
---|
1811 | default:
|
---|
1812 | rc = win32wndproc(getWindowHandle(), Msg, wParam, lParam);
|
---|
1813 | break;
|
---|
1814 | }
|
---|
1815 | fInternalMsg = fInternalMsgBackup;
|
---|
1816 | return rc;
|
---|
1817 | }
|
---|
1818 | //******************************************************************************
|
---|
1819 | //******************************************************************************
|
---|
1820 | BOOL Win32BaseWindow::PostMessageA(ULONG msg, WPARAM wParam, LPARAM lParam)
|
---|
1821 | {
|
---|
1822 | return OSLibPostMessage(OS2Hwnd, WIN32APP_USERMSGBASE+msg, wParam, lParam);
|
---|
1823 | }
|
---|
1824 | //******************************************************************************
|
---|
1825 | //******************************************************************************
|
---|
1826 | BOOL Win32BaseWindow::PostMessageW(ULONG msg, WPARAM wParam, LPARAM lParam)
|
---|
1827 | {
|
---|
1828 | return OSLibPostMessage(OS2Hwnd, WIN32APP_USERMSGBASE+msg, wParam, lParam);
|
---|
1829 | }
|
---|
1830 | //******************************************************************************
|
---|
1831 | //TODO: do we need to inform the parent of the parent (etc) of the child window?
|
---|
1832 | //******************************************************************************
|
---|
1833 | void Win32BaseWindow::NotifyParent(UINT Msg, WPARAM wParam, LPARAM lParam)
|
---|
1834 | {
|
---|
1835 | Win32BaseWindow *window = this;
|
---|
1836 | Win32BaseWindow *parentwindow;
|
---|
1837 |
|
---|
1838 | while(window)
|
---|
1839 | {
|
---|
1840 | if(window->getStyle() & WS_CHILD && !(window->getExStyle() & WS_EX_NOPARENTNOTIFY) )
|
---|
1841 | {
|
---|
1842 | /* Notify the parent window only */
|
---|
1843 | parentwindow = window->getParent();
|
---|
1844 | if(parentwindow) {
|
---|
1845 | if(Msg == WM_CREATE || Msg == WM_DESTROY) {
|
---|
1846 | parentwindow->SendMessageA(WM_PARENTNOTIFY, MAKEWPARAM(Msg, window->getWindowId()), (LPARAM)window->getWindowHandle());
|
---|
1847 | }
|
---|
1848 | else parentwindow->SendMessageA(WM_PARENTNOTIFY, MAKEWPARAM(Msg, window->getWindowId()), lParam );
|
---|
1849 | }
|
---|
1850 | }
|
---|
1851 | else break;
|
---|
1852 |
|
---|
1853 | window = parentwindow;
|
---|
1854 | }
|
---|
1855 | }
|
---|
1856 | //******************************************************************************
|
---|
1857 | //******************************************************************************
|
---|
1858 | Win32BaseWindow *Win32BaseWindow::getTopParent()
|
---|
1859 | {
|
---|
1860 | Win32BaseWindow *tmpWnd = this;
|
---|
1861 |
|
---|
1862 | while( tmpWnd && (tmpWnd->getStyle() & WS_CHILD))
|
---|
1863 | {
|
---|
1864 | tmpWnd = tmpWnd->getParent();
|
---|
1865 | }
|
---|
1866 | return tmpWnd;
|
---|
1867 | }
|
---|
1868 | //******************************************************************************
|
---|
1869 | //******************************************************************************
|
---|
1870 | BOOL Win32BaseWindow::SetMenu(HMENU hMenu)
|
---|
1871 | {
|
---|
1872 |
|
---|
1873 | dprintf(("SetMenu %x", hMenu));
|
---|
1874 | OS2HwndMenu = OSLibWinSetMenu(OS2HwndFrame, hMenu);
|
---|
1875 | if(OS2HwndMenu == 0) {
|
---|
1876 | dprintf(("Win32BaseWindow::SetMenu OS2HwndMenu == 0"));
|
---|
1877 | return FALSE;
|
---|
1878 | }
|
---|
1879 | return TRUE;
|
---|
1880 | }
|
---|
1881 | //******************************************************************************
|
---|
1882 | //******************************************************************************
|
---|
1883 | BOOL Win32BaseWindow::SetAccelTable(HACCEL hAccel)
|
---|
1884 | {
|
---|
1885 | Win32Resource *winres = (Win32Resource *)hAccel;
|
---|
1886 | HANDLE accelhandle;
|
---|
1887 |
|
---|
1888 | if(HIWORD(hAccel) == 0) {
|
---|
1889 | dprintf(("SetAccelTable: hAccel %x invalid", hAccel));
|
---|
1890 | SetLastError(ERROR_INVALID_PARAMETER);
|
---|
1891 | return FALSE;
|
---|
1892 | }
|
---|
1893 | acceltableResource = winres;
|
---|
1894 | accelhandle = OSLibWinSetAccelTable(OS2HwndFrame, winres->getOS2Handle(), winres->lockOS2Resource());
|
---|
1895 | winres->setOS2Handle(accelhandle);
|
---|
1896 | return(accelhandle != 0);
|
---|
1897 | }
|
---|
1898 | //******************************************************************************
|
---|
1899 | //******************************************************************************
|
---|
1900 | BOOL Win32BaseWindow::SetIcon(HICON hIcon)
|
---|
1901 | {
|
---|
1902 | dprintf(("Win32BaseWindow::SetIcon %x", hIcon));
|
---|
1903 | if(OSLibWinSetIcon(OS2HwndFrame, hIcon) == TRUE) {
|
---|
1904 | SendMessageA(WM_SETICON, hIcon, 0);
|
---|
1905 | return TRUE;
|
---|
1906 | }
|
---|
1907 | return FALSE;
|
---|
1908 | }
|
---|
1909 | //******************************************************************************
|
---|
1910 | //******************************************************************************
|
---|
1911 | BOOL Win32BaseWindow::ShowWindow(ULONG nCmdShow)
|
---|
1912 | {
|
---|
1913 | ULONG showstate = 0;
|
---|
1914 |
|
---|
1915 | dprintf(("ShowWindow %x %x", getWindowHandle(), nCmdShow));
|
---|
1916 | #if 1
|
---|
1917 | if (flags & WIN_NEED_SIZE)
|
---|
1918 | {
|
---|
1919 | /* should happen only in CreateWindowEx() */
|
---|
1920 | int wParam = SIZE_RESTORED;
|
---|
1921 |
|
---|
1922 | flags &= ~WIN_NEED_SIZE;
|
---|
1923 | if (dwStyle & WS_MAXIMIZE)
|
---|
1924 | wParam = SIZE_MAXIMIZED;
|
---|
1925 | else
|
---|
1926 | if (dwStyle & WS_MINIMIZE)
|
---|
1927 | wParam = SIZE_MINIMIZED;
|
---|
1928 |
|
---|
1929 | SendMessageA(WM_SIZE, wParam,
|
---|
1930 | MAKELONG(rectClient.right-rectClient.left,
|
---|
1931 | rectClient.bottom-rectClient.top));
|
---|
1932 | SendMessageA(WM_MOVE, 0, MAKELONG( rectClient.left, rectClient.top ) );
|
---|
1933 | }
|
---|
1934 | #else
|
---|
1935 | if(fFirstShow) {
|
---|
1936 | if(isFrameWindow() && IS_OVERLAPPED(getStyle()) && !isChild()) {
|
---|
1937 | SendMessageA(WM_SIZE, SIZE_RESTORED,
|
---|
1938 | MAKELONG(rectClient.right-rectClient.left,
|
---|
1939 | rectClient.bottom-rectClient.top));
|
---|
1940 | SendMessageA(WM_MOVE, 0, MAKELONG( rectClient.left, rectClient.top ) );
|
---|
1941 |
|
---|
1942 | }
|
---|
1943 | fFirstShow = FALSE;
|
---|
1944 | }
|
---|
1945 | #endif
|
---|
1946 | switch(nCmdShow)
|
---|
1947 | {
|
---|
1948 | case SW_SHOW:
|
---|
1949 | case SW_SHOWDEFAULT: //todo
|
---|
1950 | showstate = SWPOS_SHOW | SWPOS_ACTIVATE;
|
---|
1951 | break;
|
---|
1952 | case SW_HIDE:
|
---|
1953 | showstate = SWPOS_HIDE;
|
---|
1954 | break;
|
---|
1955 | case SW_RESTORE:
|
---|
1956 | showstate = SWPOS_RESTORE | SWPOS_SHOW | SWPOS_ACTIVATE;
|
---|
1957 | break;
|
---|
1958 | case SW_MINIMIZE:
|
---|
1959 | showstate = SWPOS_MINIMIZE;
|
---|
1960 | break;
|
---|
1961 | case SW_SHOWMAXIMIZED:
|
---|
1962 | showstate = SWPOS_MAXIMIZE | SWPOS_SHOW | SWPOS_ACTIVATE;
|
---|
1963 | break;
|
---|
1964 | case SW_SHOWMINIMIZED:
|
---|
1965 | showstate = SWPOS_MINIMIZE | SWPOS_SHOW | SWPOS_ACTIVATE;
|
---|
1966 | break;
|
---|
1967 | case SW_SHOWMINNOACTIVE:
|
---|
1968 | showstate = SWPOS_MINIMIZE | SWPOS_SHOW;
|
---|
1969 | break;
|
---|
1970 | case SW_SHOWNA:
|
---|
1971 | showstate = SWPOS_SHOW;
|
---|
1972 | break;
|
---|
1973 | case SW_SHOWNOACTIVATE:
|
---|
1974 | showstate = SWPOS_SHOW;
|
---|
1975 | break;
|
---|
1976 | case SW_SHOWNORMAL:
|
---|
1977 | showstate = SWPOS_RESTORE | SWPOS_ACTIVATE | SWPOS_SHOW;
|
---|
1978 | break;
|
---|
1979 | }
|
---|
1980 |
|
---|
1981 | if(showstate & SWPOS_SHOW) {
|
---|
1982 | setStyle(getStyle() | WS_VISIBLE);
|
---|
1983 | }
|
---|
1984 | else setStyle(getStyle() & ~WS_VISIBLE);
|
---|
1985 |
|
---|
1986 | BOOL rc = OSLibWinShowWindow(OS2HwndFrame, showstate);
|
---|
1987 | return rc;
|
---|
1988 | }
|
---|
1989 | //******************************************************************************
|
---|
1990 | //******************************************************************************
|
---|
1991 | BOOL Win32BaseWindow::SetWindowPos(HWND hwndInsertAfter, int x, int y, int cx, int cy, UINT fuFlags)
|
---|
1992 | {
|
---|
1993 | BOOL rc = FALSE;
|
---|
1994 | Win32BaseWindow *window;
|
---|
1995 | HWND hParent = 0;
|
---|
1996 |
|
---|
1997 | dprintf (("SetWindowPos %x %x (%d,%d)(%d,%d) %x", Win32Hwnd, hwndInsertAfter, x, y, cx, cy, fuFlags));
|
---|
1998 |
|
---|
1999 | if (fuFlags &
|
---|
2000 | ~(SWP_NOSIZE | SWP_NOMOVE | SWP_NOZORDER |
|
---|
2001 | SWP_NOREDRAW | SWP_NOACTIVATE | SWP_FRAMECHANGED |
|
---|
2002 | SWP_SHOWWINDOW | SWP_HIDEWINDOW | SWP_NOCOPYBITS |
|
---|
2003 | SWP_NOOWNERZORDER))
|
---|
2004 | {
|
---|
2005 | return FALSE;
|
---|
2006 | }
|
---|
2007 |
|
---|
2008 | WINDOWPOS wpos;
|
---|
2009 | SWP swp, swpOld;
|
---|
2010 |
|
---|
2011 | wpos.flags = fuFlags;
|
---|
2012 | wpos.cy = cy;
|
---|
2013 | wpos.cx = cx;
|
---|
2014 | wpos.x = x;
|
---|
2015 | wpos.y = y;
|
---|
2016 | wpos.hwndInsertAfter = hwndInsertAfter;
|
---|
2017 | wpos.hwnd = getWindowHandle();
|
---|
2018 |
|
---|
2019 | if(~fuFlags & (SWP_NOMOVE | SWP_NOSIZE))
|
---|
2020 | {
|
---|
2021 | if (isChild())
|
---|
2022 | {
|
---|
2023 | hParent = getParent()->getOS2WindowHandle();
|
---|
2024 | }
|
---|
2025 | OSLibWinQueryWindowPos(OS2HwndFrame, &swpOld);
|
---|
2026 | }
|
---|
2027 |
|
---|
2028 | OSLibMapWINDOWPOStoSWP(&wpos, &swp, &swpOld, hParent, OS2HwndFrame);
|
---|
2029 | if (swp.fl == 0)
|
---|
2030 | return TRUE;
|
---|
2031 |
|
---|
2032 | // if ((swp.fl & SWPOS_ZORDER) && (swp.hwndInsertBehind > HWNDOS_BOTTOM))
|
---|
2033 | if ((swp.hwndInsertBehind > HWNDOS_BOTTOM))
|
---|
2034 | {
|
---|
2035 | Win32BaseWindow *wndBehind = Win32BaseWindow::GetWindowFromHandle(swp.hwndInsertBehind);
|
---|
2036 | if(wndBehind) {
|
---|
2037 | swp.hwndInsertBehind = wndBehind->getOS2WindowHandle();
|
---|
2038 | }
|
---|
2039 | else {
|
---|
2040 | dprintf(("ERROR: SetWindowPos: hwndInsertBehind %x invalid!",swp.hwndInsertBehind));
|
---|
2041 | swp.hwndInsertBehind = 0;
|
---|
2042 | }
|
---|
2043 | }
|
---|
2044 | #if 0
|
---|
2045 | if (isFrameWindow())
|
---|
2046 | {
|
---|
2047 | if (!isChild())
|
---|
2048 | {
|
---|
2049 | POINT maxSize, maxPos, minTrack, maxTrack;
|
---|
2050 |
|
---|
2051 | GetMinMaxInfo(&maxSize, &maxPos, &minTrack, &maxTrack);
|
---|
2052 |
|
---|
2053 | if (swp.cx > maxTrack.x) swp.cx = maxTrack.x;
|
---|
2054 | if (swp.cy > maxTrack.y) swp.cy = maxTrack.y;
|
---|
2055 | if (swp.cx < minTrack.x) swp.cx = minTrack.x;
|
---|
2056 | if (swp.cy < minTrack.y) swp.cy = minTrack.y;
|
---|
2057 | }
|
---|
2058 | swp.hwnd = OS2HwndFrame;
|
---|
2059 | }
|
---|
2060 | else
|
---|
2061 | #endif
|
---|
2062 | swp.hwnd = OS2HwndFrame;
|
---|
2063 |
|
---|
2064 | dprintf (("WinSetWindowPos %x %x (%d,%d)(%d,%d) %x", swp.hwnd, swp.hwndInsertBehind, swp.x, swp.y, swp.cx, swp.cy, swp.fl));
|
---|
2065 |
|
---|
2066 | rc = OSLibWinSetMultWindowPos(&swp, 1);
|
---|
2067 |
|
---|
2068 | if (rc == FALSE)
|
---|
2069 | {
|
---|
2070 | dprintf(("OSLibWinSetMultWindowPos failed!"));
|
---|
2071 | }
|
---|
2072 | else
|
---|
2073 | {
|
---|
2074 | if (fuFlags & SWP_FRAMECHANGED_W)
|
---|
2075 | OSLibSendMessage (OS2HwndFrame, 0x42 /*WM_UPDATEFRAME*/, -1, 0);
|
---|
2076 | }
|
---|
2077 |
|
---|
2078 | return (rc);
|
---|
2079 | }
|
---|
2080 | //******************************************************************************
|
---|
2081 | //TODO: WPF_RESTOREMAXIMIZED
|
---|
2082 | //******************************************************************************
|
---|
2083 | BOOL Win32BaseWindow::SetWindowPlacement(WINDOWPLACEMENT *winpos)
|
---|
2084 | {
|
---|
2085 | if(isFrameWindow())
|
---|
2086 | {
|
---|
2087 | // Set the minimized position
|
---|
2088 | if (winpos->flags & WPF_SETMINPOSITION)
|
---|
2089 | {
|
---|
2090 | OSLibSetWindowMinPos(OS2HwndFrame, winpos->ptMinPosition.x, winpos->ptMinPosition.y);
|
---|
2091 | }
|
---|
2092 |
|
---|
2093 | //TODO: Max position
|
---|
2094 |
|
---|
2095 | // Set the new restore position.
|
---|
2096 | OSLibSetWindowRestoreRect(OS2HwndFrame, &winpos->rcNormalPosition);
|
---|
2097 | }
|
---|
2098 |
|
---|
2099 | return ShowWindow(winpos->showCmd);
|
---|
2100 | }
|
---|
2101 | //******************************************************************************
|
---|
2102 | //Also destroys all the child windows (destroy parent, destroy children)
|
---|
2103 | //******************************************************************************
|
---|
2104 | BOOL Win32BaseWindow::DestroyWindow()
|
---|
2105 | {
|
---|
2106 | return OSLibWinDestroyWindow(OS2HwndFrame);
|
---|
2107 | }
|
---|
2108 | //******************************************************************************
|
---|
2109 | //******************************************************************************
|
---|
2110 | HWND Win32BaseWindow::GetParent()
|
---|
2111 | {
|
---|
2112 | if(getParent()) {
|
---|
2113 | return getParent()->getWindowHandle();
|
---|
2114 | }
|
---|
2115 | else return 0;
|
---|
2116 | }
|
---|
2117 | //******************************************************************************
|
---|
2118 | //******************************************************************************
|
---|
2119 | HWND Win32BaseWindow::SetParent(HWND hwndNewParent)
|
---|
2120 | {
|
---|
2121 | HWND oldhwnd;
|
---|
2122 | Win32BaseWindow *newparent;
|
---|
2123 |
|
---|
2124 | if(getParent()) {
|
---|
2125 | oldhwnd = getParent()->getWindowHandle();
|
---|
2126 | getParent()->RemoveChild(this);
|
---|
2127 | }
|
---|
2128 | else oldhwnd = 0;
|
---|
2129 |
|
---|
2130 | newparent = GetWindowFromHandle(hwndNewParent);
|
---|
2131 | if(newparent)
|
---|
2132 | {
|
---|
2133 | setParent(newparent);
|
---|
2134 | getParent()->AddChild(this);
|
---|
2135 | OSLibWinSetParent(getOS2WindowHandle(), getParent()->getOS2WindowHandle());
|
---|
2136 | return oldhwnd;
|
---|
2137 | }
|
---|
2138 | SetLastError(ERROR_INVALID_PARAMETER);
|
---|
2139 | return 0;
|
---|
2140 | }
|
---|
2141 | //******************************************************************************
|
---|
2142 | //******************************************************************************
|
---|
2143 | BOOL Win32BaseWindow::IsChild(HWND hwndParent)
|
---|
2144 | {
|
---|
2145 | if(getParent()) {
|
---|
2146 | return getParent()->getWindowHandle() == hwndParent;
|
---|
2147 | }
|
---|
2148 | else return 0;
|
---|
2149 | }
|
---|
2150 | //******************************************************************************
|
---|
2151 | //******************************************************************************
|
---|
2152 | HWND Win32BaseWindow::GetTopWindow()
|
---|
2153 | {
|
---|
2154 | return GetWindow(GW_CHILD);
|
---|
2155 | }
|
---|
2156 | //******************************************************************************
|
---|
2157 | // Get the top-level parent for a child window.
|
---|
2158 | //******************************************************************************
|
---|
2159 | Win32BaseWindow *Win32BaseWindow::GetTopParent()
|
---|
2160 | {
|
---|
2161 | Win32BaseWindow *window = this;
|
---|
2162 |
|
---|
2163 | while(window && (window->getStyle() & WS_CHILD))
|
---|
2164 | {
|
---|
2165 | window = window->getParent();
|
---|
2166 | }
|
---|
2167 | return window;
|
---|
2168 | }
|
---|
2169 | //******************************************************************************
|
---|
2170 | //Don't call WinUpdateWindow as that one also updates the child windows
|
---|
2171 | //Also need to send WM_PAINT directly to the window procedure, which doesn't
|
---|
2172 | //always happen with WinUpdateWindow (could be posted if thread doesn't own window)
|
---|
2173 | //******************************************************************************
|
---|
2174 | BOOL Win32BaseWindow::UpdateWindow()
|
---|
2175 | {
|
---|
2176 | RECT rect;
|
---|
2177 |
|
---|
2178 | if(OSLibWinQueryUpdateRect(OS2Hwnd, &rect))
|
---|
2179 | {//update region not empty
|
---|
2180 | HDC hdc;
|
---|
2181 |
|
---|
2182 | hdc = O32_GetDC(OS2Hwnd);
|
---|
2183 | if (isIcon)
|
---|
2184 | {
|
---|
2185 | SendMessageA(WM_ICONERASEBKGND, (WPARAM)hdc, 0);
|
---|
2186 | SendMessageA(WM_PAINTICON, 0, 0);
|
---|
2187 | } else
|
---|
2188 | {
|
---|
2189 | SendMessageA(WM_ERASEBKGND, (WPARAM)hdc, 0);
|
---|
2190 | SendMessageA(WM_PAINT, 0, 0);
|
---|
2191 | }
|
---|
2192 | O32_ReleaseDC(OS2Hwnd, hdc);
|
---|
2193 | }
|
---|
2194 | return TRUE;
|
---|
2195 | }
|
---|
2196 | //******************************************************************************
|
---|
2197 | //******************************************************************************
|
---|
2198 | BOOL Win32BaseWindow::IsIconic()
|
---|
2199 | {
|
---|
2200 | return OSLibWinIsIconic(OS2Hwnd);
|
---|
2201 | }
|
---|
2202 | //******************************************************************************
|
---|
2203 | //TODO: Should not enumerate children that are created during the enumeration!
|
---|
2204 | //******************************************************************************
|
---|
2205 | BOOL Win32BaseWindow::EnumChildWindows(WNDENUMPROC lpfn, LPARAM lParam)
|
---|
2206 | {
|
---|
2207 | BOOL rc = TRUE;
|
---|
2208 | HWND hwnd;
|
---|
2209 | Win32BaseWindow *prevchild = 0, *child = 0;
|
---|
2210 |
|
---|
2211 | dprintf(("EnumChildWindows of %x parameter %x %x (%x)", getWindowHandle(), lpfn, lParam, getFirstChild()));
|
---|
2212 | for (child = (Win32BaseWindow *)getFirstChild(); child; child = (Win32BaseWindow *)child->getNextChild())
|
---|
2213 | {
|
---|
2214 | dprintf(("EnumChildWindows: enumerating child %x", child->getWindowHandle()));
|
---|
2215 | hwnd = child->getWindowHandle();
|
---|
2216 | if(lpfn(hwnd, lParam) == FALSE)
|
---|
2217 | {
|
---|
2218 | rc = FALSE;
|
---|
2219 | break;
|
---|
2220 | }
|
---|
2221 | //check if the window still exists
|
---|
2222 | if(!::IsWindow(hwnd))
|
---|
2223 | {
|
---|
2224 | child = prevchild;
|
---|
2225 | continue;
|
---|
2226 | }
|
---|
2227 | if(child->getFirstChild() != NULL)
|
---|
2228 | {
|
---|
2229 | dprintf(("EnumChildWindows: Enumerate children of %x", child->getWindowHandle()));
|
---|
2230 | if(child->EnumChildWindows(lpfn, lParam) == FALSE)
|
---|
2231 | {
|
---|
2232 | rc = FALSE;
|
---|
2233 | break;
|
---|
2234 | }
|
---|
2235 | }
|
---|
2236 | prevchild = child;
|
---|
2237 | }
|
---|
2238 | return rc;
|
---|
2239 | }
|
---|
2240 | //******************************************************************************
|
---|
2241 | //******************************************************************************
|
---|
2242 | Win32BaseWindow *Win32BaseWindow::FindWindowById(int id)
|
---|
2243 | {
|
---|
2244 | for (Win32BaseWindow *child = (Win32BaseWindow *)getFirstChild(); child; child = (Win32BaseWindow *)child->getNextChild())
|
---|
2245 | {
|
---|
2246 | if (child->getWindowId() == id)
|
---|
2247 | {
|
---|
2248 | return child;
|
---|
2249 | }
|
---|
2250 | }
|
---|
2251 | return 0;
|
---|
2252 | }
|
---|
2253 | //******************************************************************************
|
---|
2254 | //TODO:
|
---|
2255 | //We assume (for now) that if hwndParent or hwndChildAfter are real window handles, that
|
---|
2256 | //the current process owns them.
|
---|
2257 | //******************************************************************************
|
---|
2258 | HWND Win32BaseWindow::FindWindowEx(HWND hwndParent, HWND hwndChildAfter, LPSTR lpszClass, LPSTR lpszWindow,
|
---|
2259 | BOOL fUnicode)
|
---|
2260 | {
|
---|
2261 | Win32BaseWindow *parent = GetWindowFromHandle(hwndParent);
|
---|
2262 | Win32BaseWindow *child = GetWindowFromHandle(hwndChildAfter);
|
---|
2263 |
|
---|
2264 | if((hwndParent != OSLIB_HWND_DESKTOP && !parent) ||
|
---|
2265 | (hwndChildAfter != 0 && !child) ||
|
---|
2266 | (hwndParent == OSLIB_HWND_DESKTOP && hwndChildAfter != 0))
|
---|
2267 | {
|
---|
2268 | dprintf(("Win32BaseWindow::FindWindowEx: parent or child not found %x %x", hwndParent, hwndChildAfter));
|
---|
2269 | SetLastError(ERROR_INVALID_WINDOW_HANDLE);
|
---|
2270 | return 0;
|
---|
2271 | }
|
---|
2272 | if(hwndParent != OSLIB_HWND_DESKTOP)
|
---|
2273 | {//if the current process owns the window, just do a quick search
|
---|
2274 | child = (Win32BaseWindow *)parent->getFirstChild();
|
---|
2275 | if(hwndChildAfter != 0)
|
---|
2276 | {
|
---|
2277 | while(child)
|
---|
2278 | {
|
---|
2279 | if(child->getWindowHandle() == hwndChildAfter)
|
---|
2280 | {
|
---|
2281 | child = (Win32BaseWindow *)child->getNextChild();
|
---|
2282 | break;
|
---|
2283 | }
|
---|
2284 | child = (Win32BaseWindow *)child->getNextChild();
|
---|
2285 | }
|
---|
2286 | }
|
---|
2287 | while(child)
|
---|
2288 | {
|
---|
2289 | if(child->getWindowClass()->hasClassName(lpszClass, fUnicode) &&
|
---|
2290 | (!lpszWindow || child->hasWindowName(lpszWindow, fUnicode)))
|
---|
2291 | {
|
---|
2292 | dprintf(("FindWindowEx: Found window %x", child->getWindowHandle()));
|
---|
2293 | return child->getWindowHandle();
|
---|
2294 | }
|
---|
2295 | child = (Win32BaseWindow *)child->getNextChild();
|
---|
2296 | }
|
---|
2297 | }
|
---|
2298 | else {
|
---|
2299 | Win32BaseWindow *wnd;
|
---|
2300 | HWND henum, hwnd;
|
---|
2301 |
|
---|
2302 | henum = OSLibWinBeginEnumWindows(OSLIB_HWND_DESKTOP);
|
---|
2303 | hwnd = OSLibWinGetNextWindow(henum);
|
---|
2304 |
|
---|
2305 | while(hwnd)
|
---|
2306 | {
|
---|
2307 | wnd = GetWindowFromOS2Handle(hwnd);
|
---|
2308 | if(wnd == NULL) {
|
---|
2309 | hwnd = OSLibWinQueryClientWindow(hwnd);
|
---|
2310 | if(hwnd) wnd = GetWindowFromOS2Handle(hwnd);
|
---|
2311 | if(!hwnd) wnd = GetWindowFromOS2FrameHandle(hwnd);
|
---|
2312 | }
|
---|
2313 |
|
---|
2314 | if(wnd) {
|
---|
2315 | LPVOID sharedmembase = (LPVOID)OSLibWinGetWindowULong(hwnd, OFFSET_WIN32PM_SHAREDMEM);
|
---|
2316 |
|
---|
2317 | if(OSLibDosGetSharedMem(sharedmembase, MAX_HEAPSIZE, OSLIB_PAG_READ) != 0) {
|
---|
2318 | dprintf(("OSLibDosGetSharedMem returned error for %x", wnd));
|
---|
2319 | break;
|
---|
2320 | }
|
---|
2321 | if(wnd->getWindowClass()->hasClassName(lpszClass, fUnicode) &&
|
---|
2322 | (!lpszWindow || wnd->hasWindowName(lpszWindow, fUnicode)))
|
---|
2323 | {
|
---|
2324 | OSLibWinEndEnumWindows(henum);
|
---|
2325 | dprintf(("FindWindowEx: Found window %x", wnd->getWindowHandle()));
|
---|
2326 | return wnd->getWindowHandle();
|
---|
2327 | }
|
---|
2328 | }
|
---|
2329 | hwnd = OSLibWinGetNextWindow(henum);
|
---|
2330 | }
|
---|
2331 | OSLibWinEndEnumWindows(henum);
|
---|
2332 | }
|
---|
2333 | SetLastError(ERROR_CANNOT_FIND_WND_CLASS); //TODO: not always correct
|
---|
2334 | return 0;
|
---|
2335 | }
|
---|
2336 | //******************************************************************************
|
---|
2337 | //******************************************************************************
|
---|
2338 | HWND Win32BaseWindow::GetWindow(UINT uCmd)
|
---|
2339 | {
|
---|
2340 | HWND hwndRelated = 0;
|
---|
2341 | Win32BaseWindow *window;
|
---|
2342 |
|
---|
2343 | switch(uCmd)
|
---|
2344 | {
|
---|
2345 | case GW_HWNDFIRST:
|
---|
2346 | if(getParent()) {
|
---|
2347 | window = (Win32BaseWindow *)getParent()->getFirstChild();
|
---|
2348 | hwndRelated = window->getWindowHandle();
|
---|
2349 | }
|
---|
2350 | break;
|
---|
2351 |
|
---|
2352 | case GW_HWNDLAST:
|
---|
2353 | if(getParent())
|
---|
2354 | {
|
---|
2355 | goto end;
|
---|
2356 | }
|
---|
2357 |
|
---|
2358 | window = this;
|
---|
2359 | while(window)
|
---|
2360 | {
|
---|
2361 | window = (Win32BaseWindow *)window->getNextChild();
|
---|
2362 | }
|
---|
2363 | hwndRelated = window->getWindowHandle();
|
---|
2364 | break;
|
---|
2365 |
|
---|
2366 | case GW_HWNDNEXT:
|
---|
2367 | window = (Win32BaseWindow *)getNextChild();
|
---|
2368 | if(window) {
|
---|
2369 | hwndRelated = window->getWindowHandle();
|
---|
2370 | }
|
---|
2371 | break;
|
---|
2372 |
|
---|
2373 | case GW_HWNDPREV:
|
---|
2374 | if(!getParent())
|
---|
2375 | {
|
---|
2376 | goto end;
|
---|
2377 | }
|
---|
2378 | window = (Win32BaseWindow *)(getParent()->getFirstChild()); /* First sibling */
|
---|
2379 | if(window == this)
|
---|
2380 | {
|
---|
2381 | hwndRelated = 0; /* First in list */
|
---|
2382 | goto end;
|
---|
2383 | }
|
---|
2384 | while(window->getNextChild())
|
---|
2385 | {
|
---|
2386 | if (window->getNextChild() == this)
|
---|
2387 | {
|
---|
2388 | hwndRelated = window->getWindowHandle();
|
---|
2389 | goto end;
|
---|
2390 | }
|
---|
2391 | window = (Win32BaseWindow *)window->getNextChild();
|
---|
2392 | }
|
---|
2393 | break;
|
---|
2394 |
|
---|
2395 | case GW_OWNER:
|
---|
2396 | if(getOwner()) {
|
---|
2397 | hwndRelated = getOwner()->getWindowHandle();
|
---|
2398 | }
|
---|
2399 | break;
|
---|
2400 |
|
---|
2401 | case GW_CHILD:
|
---|
2402 | if(getFirstChild()) {
|
---|
2403 | hwndRelated = ((Win32BaseWindow *)getFirstChild())->getWindowHandle();
|
---|
2404 | }
|
---|
2405 | break;
|
---|
2406 | }
|
---|
2407 | end:
|
---|
2408 | dprintf(("GetWindow %x %d returned %x", getWindowHandle(), uCmd, hwndRelated));
|
---|
2409 | return hwndRelated;
|
---|
2410 | }
|
---|
2411 | //******************************************************************************
|
---|
2412 | //******************************************************************************
|
---|
2413 | HWND Win32BaseWindow::SetActiveWindow()
|
---|
2414 | {
|
---|
2415 | return OSLibWinSetActiveWindow(OS2Hwnd);
|
---|
2416 | }
|
---|
2417 | //******************************************************************************
|
---|
2418 | //WM_ENABLE is sent to hwnd, but not to it's children (as it should be)
|
---|
2419 | //******************************************************************************
|
---|
2420 | BOOL Win32BaseWindow::EnableWindow(BOOL fEnable)
|
---|
2421 | {
|
---|
2422 | return OSLibWinEnableWindow(OS2Hwnd, fEnable);
|
---|
2423 | }
|
---|
2424 | //******************************************************************************
|
---|
2425 | //******************************************************************************
|
---|
2426 | BOOL Win32BaseWindow::CloseWindow()
|
---|
2427 | {
|
---|
2428 | return OSLibWinMinimizeWindow(OS2Hwnd);
|
---|
2429 | }
|
---|
2430 | //******************************************************************************
|
---|
2431 | //******************************************************************************
|
---|
2432 | HWND Win32BaseWindow::GetActiveWindow()
|
---|
2433 | {
|
---|
2434 | HWND hwndActive;
|
---|
2435 | Win32BaseWindow *win32wnd;
|
---|
2436 | ULONG magic;
|
---|
2437 |
|
---|
2438 | hwndActive = OSLibWinQueryActiveWindow();
|
---|
2439 |
|
---|
2440 | win32wnd = (Win32BaseWindow *)OSLibWinGetWindowULong(hwndActive, OFFSET_WIN32WNDPTR);
|
---|
2441 | magic = OSLibWinGetWindowULong(hwndActive, OFFSET_WIN32PM_MAGIC);
|
---|
2442 | if(CheckMagicDword(magic) && win32wnd)
|
---|
2443 | {
|
---|
2444 | return win32wnd->getWindowHandle();
|
---|
2445 | }
|
---|
2446 | return hwndActive;
|
---|
2447 | }
|
---|
2448 | //******************************************************************************
|
---|
2449 | //******************************************************************************
|
---|
2450 | BOOL Win32BaseWindow::IsWindowEnabled()
|
---|
2451 | {
|
---|
2452 | return OSLibWinIsWindowEnabled(OS2Hwnd);
|
---|
2453 | }
|
---|
2454 | //******************************************************************************
|
---|
2455 | //******************************************************************************
|
---|
2456 | BOOL Win32BaseWindow::IsWindowVisible()
|
---|
2457 | {
|
---|
2458 | #if 1
|
---|
2459 | return (dwStyle & WS_VISIBLE) == WS_VISIBLE;
|
---|
2460 | #else
|
---|
2461 | return OSLibWinIsWindowVisible(OS2Hwnd);
|
---|
2462 | #endif
|
---|
2463 | }
|
---|
2464 | //******************************************************************************
|
---|
2465 | //******************************************************************************
|
---|
2466 | BOOL Win32BaseWindow::GetWindowRect(PRECT pRect)
|
---|
2467 | {
|
---|
2468 | return OSLibWinQueryWindowRect(OS2HwndFrame, pRect, RELATIVE_TO_SCREEN);
|
---|
2469 | }
|
---|
2470 | //******************************************************************************
|
---|
2471 | //******************************************************************************
|
---|
2472 | BOOL Win32BaseWindow::hasWindowName(LPSTR wndname, BOOL fUnicode)
|
---|
2473 | {
|
---|
2474 | if(fUnicode) {
|
---|
2475 | return (lstrcmpW(windowNameW, (LPWSTR)wndname) == 0);
|
---|
2476 | }
|
---|
2477 | else return (strcmp(windowNameA, wndname) == 0);
|
---|
2478 | }
|
---|
2479 | //******************************************************************************
|
---|
2480 | //******************************************************************************
|
---|
2481 | int Win32BaseWindow::GetWindowTextLength()
|
---|
2482 | {
|
---|
2483 | return wndNameLength;
|
---|
2484 | }
|
---|
2485 | //******************************************************************************
|
---|
2486 | //******************************************************************************
|
---|
2487 | int Win32BaseWindow::GetWindowTextA(LPSTR lpsz, int cch)
|
---|
2488 | {
|
---|
2489 | if(windowNameA == NULL) {
|
---|
2490 | *lpsz = 0;
|
---|
2491 | return 0;
|
---|
2492 | }
|
---|
2493 | strncpy(lpsz, windowNameA, cch);
|
---|
2494 | return wndNameLength;
|
---|
2495 | }
|
---|
2496 | //******************************************************************************
|
---|
2497 | //******************************************************************************
|
---|
2498 | int Win32BaseWindow::GetWindowTextW(LPWSTR lpsz, int cch)
|
---|
2499 | {
|
---|
2500 | if(windowNameW == NULL) {
|
---|
2501 | *lpsz = 0;
|
---|
2502 | return 0;
|
---|
2503 | }
|
---|
2504 | lstrcpynW((LPWSTR)lpsz, windowNameW, cch);
|
---|
2505 | return wndNameLength;
|
---|
2506 | }
|
---|
2507 | //******************************************************************************
|
---|
2508 | //******************************************************************************
|
---|
2509 | BOOL Win32BaseWindow::SetWindowTextA(LPSTR lpsz)
|
---|
2510 | {
|
---|
2511 | if(lpsz == NULL)
|
---|
2512 | return FALSE;
|
---|
2513 |
|
---|
2514 | if(windowNameA) free(windowNameA);
|
---|
2515 | if(windowNameW) free(windowNameW);
|
---|
2516 |
|
---|
2517 | windowNameA = (LPSTR)_smalloc(strlen(lpsz)+1);
|
---|
2518 | strcpy(windowNameA, lpsz);
|
---|
2519 | windowNameW = (LPWSTR)_smalloc((strlen(lpsz)+1)*sizeof(WCHAR));
|
---|
2520 | lstrcpyAtoW(windowNameW, windowNameA);
|
---|
2521 | wndNameLength = strlen(windowNameA)+1; //including 0 terminator
|
---|
2522 |
|
---|
2523 | if(OS2HwndFrame)
|
---|
2524 | return OSLibWinSetWindowText(OS2HwndFrame, (LPSTR)windowNameA);
|
---|
2525 |
|
---|
2526 | return TRUE;
|
---|
2527 | }
|
---|
2528 | //******************************************************************************
|
---|
2529 | //******************************************************************************
|
---|
2530 | BOOL Win32BaseWindow::SetWindowTextW(LPWSTR lpsz)
|
---|
2531 | {
|
---|
2532 | if(lpsz == NULL)
|
---|
2533 | return FALSE;
|
---|
2534 |
|
---|
2535 | if(windowNameA) free(windowNameA);
|
---|
2536 | if(windowNameW) free(windowNameW);
|
---|
2537 |
|
---|
2538 | windowNameW = (LPWSTR)_smalloc((lstrlenW((LPWSTR)lpsz)+1)*sizeof(WCHAR));
|
---|
2539 | lstrcpyW(windowNameW, (LPWSTR)lpsz);
|
---|
2540 | windowNameA = (LPSTR)_smalloc(lstrlenW((LPWSTR)lpsz)+1);
|
---|
2541 | lstrcpyWtoA(windowNameA, windowNameW);
|
---|
2542 | wndNameLength = strlen(windowNameA)+1; //including 0 terminator
|
---|
2543 |
|
---|
2544 | if(OS2HwndFrame)
|
---|
2545 | return OSLibWinSetWindowText(OS2HwndFrame, (LPSTR)windowNameA);
|
---|
2546 |
|
---|
2547 | return TRUE;
|
---|
2548 | }
|
---|
2549 | //******************************************************************************
|
---|
2550 | //******************************************************************************
|
---|
2551 | LONG Win32BaseWindow::SetWindowLongA(int index, ULONG value)
|
---|
2552 | {
|
---|
2553 | LONG oldval;
|
---|
2554 |
|
---|
2555 | switch(index) {
|
---|
2556 | case GWL_EXSTYLE:
|
---|
2557 | {
|
---|
2558 | STYLESTRUCT ss;
|
---|
2559 |
|
---|
2560 | if(dwExStyle == value)
|
---|
2561 | return value;
|
---|
2562 |
|
---|
2563 | ss.styleOld = dwExStyle;
|
---|
2564 | ss.styleNew = value;
|
---|
2565 | dprintf(("SetWindowLong GWL_EXSTYLE %x old %x new style %x", getWindowHandle(), dwExStyle, value));
|
---|
2566 | SendMessageA(WM_STYLECHANGING,GWL_EXSTYLE,(LPARAM)&ss);
|
---|
2567 | setExStyle(ss.styleNew);
|
---|
2568 | SendMessageA(WM_STYLECHANGED,GWL_EXSTYLE,(LPARAM)&ss);
|
---|
2569 | return ss.styleOld;
|
---|
2570 | }
|
---|
2571 | case GWL_STYLE:
|
---|
2572 | {
|
---|
2573 | STYLESTRUCT ss;
|
---|
2574 |
|
---|
2575 | if(dwStyle == value)
|
---|
2576 | return value;
|
---|
2577 |
|
---|
2578 | ss.styleOld = dwStyle;
|
---|
2579 | ss.styleNew = value;
|
---|
2580 | dprintf(("SetWindowLong GWL_STYLE %x old %x new style %x", getWindowHandle(), dwStyle, value));
|
---|
2581 | SendMessageA(WM_STYLECHANGING,GWL_STYLE,(LPARAM)&ss);
|
---|
2582 | setStyle(ss.styleNew);
|
---|
2583 | if(!IsWindowDestroyed())
|
---|
2584 | OSLibSetWindowStyle(OS2HwndFrame, dwStyle);
|
---|
2585 | SendMessageA(WM_STYLECHANGED,GWL_STYLE,(LPARAM)&ss);
|
---|
2586 | return ss.styleOld;
|
---|
2587 | }
|
---|
2588 | case GWL_WNDPROC:
|
---|
2589 | oldval = (LONG)getWindowProc();
|
---|
2590 | setWindowProc((WNDPROC)value);
|
---|
2591 | return oldval;
|
---|
2592 | case GWL_HINSTANCE:
|
---|
2593 | oldval = hInstance;
|
---|
2594 | hInstance = value;
|
---|
2595 | return oldval;
|
---|
2596 | case GWL_HWNDPARENT:
|
---|
2597 | return SetParent((HWND)value);
|
---|
2598 | case GWL_ID:
|
---|
2599 | oldval = getWindowId();
|
---|
2600 | setWindowId(value);
|
---|
2601 | return oldval;
|
---|
2602 | case GWL_USERDATA:
|
---|
2603 | oldval = userData;
|
---|
2604 | userData = value;
|
---|
2605 | return oldval;
|
---|
2606 | default:
|
---|
2607 | if(index >= 0 && index/4 < nrUserWindowLong)
|
---|
2608 | {
|
---|
2609 | oldval = userWindowLong[index/4];
|
---|
2610 | userWindowLong[index/4] = value;
|
---|
2611 | return oldval;
|
---|
2612 | }
|
---|
2613 | SetLastError(ERROR_INVALID_PARAMETER);
|
---|
2614 | return 0;
|
---|
2615 | }
|
---|
2616 | }
|
---|
2617 | //******************************************************************************
|
---|
2618 | //******************************************************************************
|
---|
2619 | ULONG Win32BaseWindow::GetWindowLongA(int index)
|
---|
2620 | {
|
---|
2621 | switch(index) {
|
---|
2622 | case GWL_EXSTYLE:
|
---|
2623 | return dwExStyle;
|
---|
2624 | case GWL_STYLE:
|
---|
2625 | return dwStyle;
|
---|
2626 | case GWL_WNDPROC:
|
---|
2627 | return (ULONG)getWindowProc();
|
---|
2628 | case GWL_HINSTANCE:
|
---|
2629 | return hInstance;
|
---|
2630 | case GWL_HWNDPARENT:
|
---|
2631 | if(getParent()) {
|
---|
2632 | return getParent()->getWindowHandle();
|
---|
2633 | }
|
---|
2634 | else return 0;
|
---|
2635 | case GWL_ID:
|
---|
2636 | return getWindowId();
|
---|
2637 | case GWL_USERDATA:
|
---|
2638 | return userData;
|
---|
2639 | default:
|
---|
2640 | if(index >= 0 && index/4 < nrUserWindowLong)
|
---|
2641 | {
|
---|
2642 | return userWindowLong[index/4];
|
---|
2643 | }
|
---|
2644 | SetLastError(ERROR_INVALID_PARAMETER);
|
---|
2645 | return 0;
|
---|
2646 | }
|
---|
2647 | }
|
---|
2648 | //******************************************************************************
|
---|
2649 | //******************************************************************************
|
---|
2650 | WORD Win32BaseWindow::SetWindowWord(int index, WORD value)
|
---|
2651 | {
|
---|
2652 | WORD oldval;
|
---|
2653 |
|
---|
2654 | if(index >= 0 && index/4 < nrUserWindowLong)
|
---|
2655 | {
|
---|
2656 | oldval = ((WORD *)userWindowLong)[index/2];
|
---|
2657 | ((WORD *)userWindowLong)[index/2] = value;
|
---|
2658 | return oldval;
|
---|
2659 | }
|
---|
2660 | SetLastError(ERROR_INVALID_PARAMETER);
|
---|
2661 | return 0;
|
---|
2662 | }
|
---|
2663 | //******************************************************************************
|
---|
2664 | //******************************************************************************
|
---|
2665 | WORD Win32BaseWindow::GetWindowWord(int index)
|
---|
2666 | {
|
---|
2667 | if(index >= 0 && index/4 < nrUserWindowLong)
|
---|
2668 | {
|
---|
2669 | return ((WORD *)userWindowLong)[index/2];
|
---|
2670 | }
|
---|
2671 | SetLastError(ERROR_INVALID_PARAMETER);
|
---|
2672 | return 0;
|
---|
2673 | }
|
---|
2674 | //******************************************************************************
|
---|
2675 | //******************************************************************************
|
---|
2676 | void Win32BaseWindow::setWindowId(DWORD id)
|
---|
2677 | {
|
---|
2678 | windowId = id;
|
---|
2679 | OSLibSetWindowID(OS2HwndFrame, id);
|
---|
2680 | }
|
---|
2681 | //******************************************************************************
|
---|
2682 | //******************************************************************************
|
---|
2683 | Win32BaseWindow *Win32BaseWindow::GetWindowFromHandle(HWND hwnd)
|
---|
2684 | {
|
---|
2685 | Win32BaseWindow *window;
|
---|
2686 |
|
---|
2687 | if(hwnd == NULL && windowDesktop)
|
---|
2688 | return windowDesktop;
|
---|
2689 |
|
---|
2690 | if(HwGetWindowHandleData(hwnd, (DWORD *)&window) == TRUE) {
|
---|
2691 | return window;
|
---|
2692 | }
|
---|
2693 | else return NULL;
|
---|
2694 | }
|
---|
2695 | //******************************************************************************
|
---|
2696 | //******************************************************************************
|
---|
2697 | Win32BaseWindow *Win32BaseWindow::GetWindowFromOS2Handle(HWND hwnd)
|
---|
2698 | {
|
---|
2699 | Win32BaseWindow *win32wnd;
|
---|
2700 | DWORD magic;
|
---|
2701 |
|
---|
2702 | win32wnd = (Win32BaseWindow *)OSLibWinGetWindowULong(hwnd, OFFSET_WIN32WNDPTR);
|
---|
2703 | magic = OSLibWinGetWindowULong(hwnd, OFFSET_WIN32PM_MAGIC);
|
---|
2704 |
|
---|
2705 | if(win32wnd && CheckMagicDword(magic)) {
|
---|
2706 | return win32wnd;
|
---|
2707 | }
|
---|
2708 | return 0;
|
---|
2709 | }
|
---|
2710 | //******************************************************************************
|
---|
2711 | //******************************************************************************
|
---|
2712 | Win32BaseWindow *Win32BaseWindow::GetWindowFromOS2FrameHandle(HWND hwnd)
|
---|
2713 | {
|
---|
2714 | return GetWindowFromOS2Handle(OSLibWinWindowFromID(hwnd,OSLIB_FID_CLIENT));
|
---|
2715 | }
|
---|
2716 | //******************************************************************************
|
---|
2717 | //******************************************************************************
|
---|
2718 | HWND Win32BaseWindow::Win32ToOS2Handle(HWND hwnd)
|
---|
2719 | {
|
---|
2720 | Win32BaseWindow *window = GetWindowFromHandle(hwnd);
|
---|
2721 |
|
---|
2722 | if(window) {
|
---|
2723 | return window->getOS2WindowHandle();
|
---|
2724 | }
|
---|
2725 | else return hwnd;
|
---|
2726 | }
|
---|
2727 | //******************************************************************************
|
---|
2728 | //******************************************************************************
|
---|
2729 | HWND Win32BaseWindow::Win32ToOS2FrameHandle(HWND hwnd)
|
---|
2730 | {
|
---|
2731 | Win32BaseWindow *window = GetWindowFromHandle(hwnd);
|
---|
2732 |
|
---|
2733 | if(window) {
|
---|
2734 | return window->getOS2FrameWindowHandle();
|
---|
2735 | }
|
---|
2736 | else return hwnd;
|
---|
2737 | }
|
---|
2738 | //******************************************************************************
|
---|
2739 | //******************************************************************************
|
---|
2740 | HWND Win32BaseWindow::OS2ToWin32Handle(HWND hwnd)
|
---|
2741 | {
|
---|
2742 | Win32BaseWindow *window = GetWindowFromOS2Handle(hwnd);
|
---|
2743 |
|
---|
2744 | if(window) {
|
---|
2745 | return window->getWindowHandle();
|
---|
2746 | }
|
---|
2747 | window = GetWindowFromOS2FrameHandle(hwnd);
|
---|
2748 | if(window) {
|
---|
2749 | return window->getWindowHandle();
|
---|
2750 | }
|
---|
2751 | else return 0;
|
---|
2752 | // else return hwnd; //OS/2 window handle
|
---|
2753 | }
|
---|
2754 | //******************************************************************************
|
---|
2755 | //******************************************************************************
|
---|
2756 | #ifdef DEBUG
|
---|
2757 | void PrintWindowStyle(DWORD dwStyle, DWORD dwExStyle)
|
---|
2758 | {
|
---|
2759 | char style[256] = "";
|
---|
2760 | char exstyle[256] = "";
|
---|
2761 |
|
---|
2762 | /* Window styles */
|
---|
2763 | if(dwStyle & WS_CHILD)
|
---|
2764 | strcat(style, "WS_CHILD ");
|
---|
2765 | if(dwStyle & WS_POPUP)
|
---|
2766 | strcat(style, "WS_POPUP ");
|
---|
2767 | if(dwStyle & WS_VISIBLE)
|
---|
2768 | strcat(style, "WS_VISIBLE ");
|
---|
2769 | if(dwStyle & WS_DISABLED)
|
---|
2770 | strcat(style, "WS_DISABLED ");
|
---|
2771 | if(dwStyle & WS_CLIPSIBLINGS)
|
---|
2772 | strcat(style, "WS_CLIPSIBLINGS ");
|
---|
2773 | if(dwStyle & WS_CLIPCHILDREN)
|
---|
2774 | strcat(style, "WS_CLIPCHILDREN ");
|
---|
2775 | if(dwStyle & WS_MAXIMIZE)
|
---|
2776 | strcat(style, "WS_MAXIMIZE ");
|
---|
2777 | if(dwStyle & WS_MINIMIZE)
|
---|
2778 | strcat(style, "WS_MINIMIZE ");
|
---|
2779 | if(dwStyle & WS_GROUP)
|
---|
2780 | strcat(style, "WS_GROUP ");
|
---|
2781 | if(dwStyle & WS_TABSTOP)
|
---|
2782 | strcat(style, "WS_TABSTOP ");
|
---|
2783 |
|
---|
2784 | if((dwStyle & WS_CAPTION) == WS_CAPTION)
|
---|
2785 | strcat(style, "WS_CAPTION ");
|
---|
2786 | if(dwStyle & WS_DLGFRAME)
|
---|
2787 | strcat(style, "WS_DLGFRAME ");
|
---|
2788 | if(dwStyle & WS_BORDER)
|
---|
2789 | strcat(style, "WS_BORDER ");
|
---|
2790 |
|
---|
2791 | if(dwStyle & WS_VSCROLL)
|
---|
2792 | strcat(style, "WS_VSCROLL ");
|
---|
2793 | if(dwStyle & WS_HSCROLL)
|
---|
2794 | strcat(style, "WS_HSCROLL ");
|
---|
2795 | if(dwStyle & WS_SYSMENU)
|
---|
2796 | strcat(style, "WS_SYSMENU ");
|
---|
2797 | if(dwStyle & WS_THICKFRAME)
|
---|
2798 | strcat(style, "WS_THICKFRAME ");
|
---|
2799 | if(dwStyle & WS_MINIMIZEBOX)
|
---|
2800 | strcat(style, "WS_MINIMIZEBOX ");
|
---|
2801 | if(dwStyle & WS_MAXIMIZEBOX)
|
---|
2802 | strcat(style, "WS_MAXIMIZEBOX ");
|
---|
2803 |
|
---|
2804 | if(dwExStyle & WS_EX_DLGMODALFRAME)
|
---|
2805 | strcat(exstyle, "WS_EX_DLGMODALFRAME ");
|
---|
2806 | if(dwExStyle & WS_EX_ACCEPTFILES)
|
---|
2807 | strcat(exstyle, "WS_EX_ACCEPTFILES ");
|
---|
2808 | if(dwExStyle & WS_EX_NOPARENTNOTIFY)
|
---|
2809 | strcat(exstyle, "WS_EX_NOPARENTNOTIFY ");
|
---|
2810 | if(dwExStyle & WS_EX_TOPMOST)
|
---|
2811 | strcat(exstyle, "WS_EX_TOPMOST ");
|
---|
2812 | if(dwExStyle & WS_EX_TRANSPARENT)
|
---|
2813 | strcat(exstyle, "WS_EX_TRANSPARENT ");
|
---|
2814 |
|
---|
2815 | if(dwExStyle & WS_EX_MDICHILD)
|
---|
2816 | strcat(exstyle, "WS_EX_MDICHILD ");
|
---|
2817 | if(dwExStyle & WS_EX_TOOLWINDOW)
|
---|
2818 | strcat(exstyle, "WS_EX_TOOLWINDOW ");
|
---|
2819 | if(dwExStyle & WS_EX_WINDOWEDGE)
|
---|
2820 | strcat(exstyle, "WS_EX_WINDOWEDGE ");
|
---|
2821 | if(dwExStyle & WS_EX_CLIENTEDGE)
|
---|
2822 | strcat(exstyle, "WS_EX_CLIENTEDGE ");
|
---|
2823 | if(dwExStyle & WS_EX_CONTEXTHELP)
|
---|
2824 | strcat(exstyle, "WS_EX_CONTEXTHELP ");
|
---|
2825 | if(dwExStyle & WS_EX_RIGHT)
|
---|
2826 | strcat(exstyle, "WS_EX_RIGHT ");
|
---|
2827 | if(dwExStyle & WS_EX_LEFT)
|
---|
2828 | strcat(exstyle, "WS_EX_LEFT ");
|
---|
2829 | if(dwExStyle & WS_EX_RTLREADING)
|
---|
2830 | strcat(exstyle, "WS_EX_RTLREADING ");
|
---|
2831 | if(dwExStyle & WS_EX_LTRREADING)
|
---|
2832 | strcat(exstyle, "WS_EX_LTRREADING ");
|
---|
2833 | if(dwExStyle & WS_EX_LEFTSCROLLBAR)
|
---|
2834 | strcat(exstyle, "WS_EX_LEFTSCROLLBAR ");
|
---|
2835 | if(dwExStyle & WS_EX_RIGHTSCROLLBAR)
|
---|
2836 | strcat(exstyle, "WS_EX_RIGHTSCROLLBAR ");
|
---|
2837 | if(dwExStyle & WS_EX_CONTROLPARENT)
|
---|
2838 | strcat(exstyle, "WS_EX_CONTROLPARENT ");
|
---|
2839 | if(dwExStyle & WS_EX_STATICEDGE)
|
---|
2840 | strcat(exstyle, "WS_EX_STATICEDGE ");
|
---|
2841 | if(dwExStyle & WS_EX_APPWINDOW)
|
---|
2842 | strcat(exstyle, "WS_EX_APPWINDOW ");
|
---|
2843 |
|
---|
2844 | dprintf(("Window style: %x %s", dwStyle, style));
|
---|
2845 | dprintf(("Window exStyle: %x %s", dwExStyle, exstyle));
|
---|
2846 | }
|
---|
2847 | #endif
|
---|
2848 | //******************************************************************************
|
---|
2849 | //******************************************************************************
|
---|
2850 |
|
---|
2851 | GenericObject *Win32BaseWindow::windows = NULL;
|
---|