1 | /* $Id: win32wbase.cpp,v 1.27 2000-01-09 17:13:39 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, 1996 Alexandre Julliard
|
---|
11 | * 1995 Alex Korobka
|
---|
12 | *
|
---|
13 | * TODO: Not thread/process safe
|
---|
14 | *
|
---|
15 | * Project Odin Software License can be found in LICENSE.TXT
|
---|
16 | *
|
---|
17 | */
|
---|
18 | #include <os2win.h>
|
---|
19 | #include <win.h>
|
---|
20 | #include <stdlib.h>
|
---|
21 | #include <string.h>
|
---|
22 | #include <stdarg.h>
|
---|
23 | #include <assert.h>
|
---|
24 | #include <misc.h>
|
---|
25 | #include <heapstring.h>
|
---|
26 | #include <win32wbase.h>
|
---|
27 | #include <winres.h>
|
---|
28 | #include "wndmsg.h"
|
---|
29 | #include "oslibwin.h"
|
---|
30 | #include "oslibmsg.h"
|
---|
31 | #include "oslibutil.h"
|
---|
32 | #include "oslibgdi.h"
|
---|
33 | #include "oslibres.h"
|
---|
34 | #include "oslibmenu.h"
|
---|
35 | #include "oslibdos.h"
|
---|
36 | #include "syscolor.h"
|
---|
37 | #include "win32wndhandle.h"
|
---|
38 | #include "dc.h"
|
---|
39 | #include "pmframe.h"
|
---|
40 | #include "win32wdesktop.h"
|
---|
41 | #include "pmwindow.h"
|
---|
42 | #include "controls.h"
|
---|
43 | #include <wprocess.h>
|
---|
44 | #include "winmouse.h"
|
---|
45 | #include <win\hook.h>
|
---|
46 | #include <shellapi.h>
|
---|
47 | #define INCL_TIMERWIN32
|
---|
48 | #include "timer.h"
|
---|
49 |
|
---|
50 | #define SC_ABOUTWINE (SC_SCREENSAVE+1)
|
---|
51 | #define SC_PUTMARK (SC_SCREENSAVE+2)
|
---|
52 |
|
---|
53 | #define HAS_DLGFRAME(style,exStyle) \
|
---|
54 | (((exStyle) & WS_EX_DLGMODALFRAME) || \
|
---|
55 | (((style) & WS_DLGFRAME) && !((style) & WS_THICKFRAME)))
|
---|
56 |
|
---|
57 | #define HAS_THICKFRAME(style,exStyle) \
|
---|
58 | (((style) & WS_THICKFRAME) && \
|
---|
59 | !((exStyle) & WS_EX_DLGMODALFRAME) && \
|
---|
60 | !((style) & WS_CHILD))
|
---|
61 |
|
---|
62 | #define HAS_THINFRAME(style) \
|
---|
63 | (((style) & WS_BORDER) || !((style) & (WS_CHILD | WS_POPUP)))
|
---|
64 |
|
---|
65 | #define HAS_BIGFRAME(style,exStyle) \
|
---|
66 | (((style) & (WS_THICKFRAME | WS_DLGFRAME)) || \
|
---|
67 | ((exStyle) & WS_EX_DLGMODALFRAME))
|
---|
68 |
|
---|
69 | #define HAS_ANYFRAME(style,exStyle) \
|
---|
70 | (((style) & (WS_THICKFRAME | WS_DLGFRAME | WS_BORDER)) || \
|
---|
71 | ((exStyle) & WS_EX_DLGMODALFRAME) || \
|
---|
72 | !((style) & (WS_CHILD | WS_POPUP)))
|
---|
73 |
|
---|
74 | #define HAS_3DFRAME(exStyle) \
|
---|
75 | ((exStyle & WS_EX_CLIENTEDGE) || (exStyle & WS_EX_STATICEDGE) || (exStyle & WS_EX_WINDOWEDGE))
|
---|
76 |
|
---|
77 | #define HAS_BORDER(style, exStyle) \
|
---|
78 | ((style & WS_BORDER) || HAS_THICKFRAME(style) || HAS_DLGFRAME(style,exStyle))
|
---|
79 |
|
---|
80 | #define IS_OVERLAPPED(style) \
|
---|
81 | !(style & (WS_CHILD | WS_POPUP))
|
---|
82 |
|
---|
83 | #define HAS_MENU(w) (!((w)->getStyle() & WS_CHILD) && ((w)->getWindowId() != 0))
|
---|
84 |
|
---|
85 | /* bits in the dwKeyData */
|
---|
86 | #define KEYDATA_ALT 0x2000
|
---|
87 | #define KEYDATA_PREVSTATE 0x4000
|
---|
88 |
|
---|
89 | void PrintWindowStyle(DWORD dwStyle, DWORD dwExStyle);
|
---|
90 |
|
---|
91 | static fDestroyAll = FALSE;
|
---|
92 | //For quick lookup of current process id
|
---|
93 | static ULONG currentProcessId = -1;
|
---|
94 |
|
---|
95 | static HBITMAP hbitmapClose = 0;
|
---|
96 | static HBITMAP hbitmapCloseD = 0;
|
---|
97 | static HBITMAP hbitmapMinimize = 0;
|
---|
98 | static HBITMAP hbitmapMinimizeD = 0;
|
---|
99 | static HBITMAP hbitmapMaximize = 0;
|
---|
100 | static HBITMAP hbitmapMaximizeD = 0;
|
---|
101 | static HBITMAP hbitmapRestore = 0;
|
---|
102 | static HBITMAP hbitmapRestoreD = 0;
|
---|
103 |
|
---|
104 | BYTE lpGrayMask[] = { 0xAA, 0xA0,
|
---|
105 | 0x55, 0x50,
|
---|
106 | 0xAA, 0xA0,
|
---|
107 | 0x55, 0x50,
|
---|
108 | 0xAA, 0xA0,
|
---|
109 | 0x55, 0x50,
|
---|
110 | 0xAA, 0xA0,
|
---|
111 | 0x55, 0x50,
|
---|
112 | 0xAA, 0xA0,
|
---|
113 | 0x55, 0x50};
|
---|
114 |
|
---|
115 | //******************************************************************************
|
---|
116 | //******************************************************************************
|
---|
117 | Win32BaseWindow::Win32BaseWindow(DWORD objType) : GenericObject(&windows, objType)
|
---|
118 | {
|
---|
119 | Init();
|
---|
120 | }
|
---|
121 | //******************************************************************************
|
---|
122 | //******************************************************************************
|
---|
123 | Win32BaseWindow::Win32BaseWindow(HWND os2Handle,VOID* win32WndProc) : GenericObject(&windows,OBJTYPE_WINDOW)
|
---|
124 | {
|
---|
125 | Init();
|
---|
126 | OS2Hwnd = OS2HwndFrame = os2Handle;
|
---|
127 | dwStyle = WS_VISIBLE;
|
---|
128 | setWindowProc((WNDPROC)win32WndProc);
|
---|
129 | fIsSubclassedOS2Wnd = TRUE;
|
---|
130 | fFirstShow = FALSE;
|
---|
131 | fCreated = TRUE;
|
---|
132 |
|
---|
133 | SetLastError(0);
|
---|
134 |
|
---|
135 | //CB: replace by a secure method
|
---|
136 |
|
---|
137 | if(OSLibWinSetWindowULong(OS2Hwnd, OFFSET_WIN32WNDPTR, (ULONG)this) == FALSE) {
|
---|
138 | dprintf(("WM_CREATE: WinSetWindowULong %X failed!!", OS2Hwnd));
|
---|
139 | SetLastError(ERROR_OUTOFMEMORY); //TODO: Better error
|
---|
140 | return;
|
---|
141 | }
|
---|
142 | if(OSLibWinSetWindowULong(OS2Hwnd, OFFSET_WIN32PM_MAGIC, WIN32PM_MAGIC) == FALSE) {
|
---|
143 | dprintf(("WM_CREATE: WinSetWindowULong2 %X failed!!", OS2Hwnd));
|
---|
144 | SetLastError(ERROR_OUTOFMEMORY); //TODO: Better error
|
---|
145 | return;
|
---|
146 | }
|
---|
147 |
|
---|
148 | OSLibWinQueryWindowRect(OS2Hwnd,&rectClient,RELATIVE_TO_WINDOW);
|
---|
149 | OSLibWinQueryWindowRect(OS2Hwnd,&rectWindow,RELATIVE_TO_SCREEN);
|
---|
150 |
|
---|
151 | setOldWndProc(SubclassWithDefHandler(OS2Hwnd));
|
---|
152 | }
|
---|
153 | //******************************************************************************
|
---|
154 | //******************************************************************************
|
---|
155 | Win32BaseWindow::Win32BaseWindow(CREATESTRUCTA *lpCreateStructA, ATOM classAtom, BOOL isUnicode)
|
---|
156 | : GenericObject(&windows, OBJTYPE_WINDOW), ChildWindow()
|
---|
157 | {
|
---|
158 | Init();
|
---|
159 | this->isUnicode = isUnicode;
|
---|
160 | CreateWindowExA(lpCreateStructA, classAtom);
|
---|
161 | }
|
---|
162 | //******************************************************************************
|
---|
163 | //******************************************************************************
|
---|
164 | void Win32BaseWindow::Init()
|
---|
165 | {
|
---|
166 | isUnicode = FALSE;
|
---|
167 | fIsSubclassedOS2Wnd = FALSE;
|
---|
168 | fFirstShow = TRUE;
|
---|
169 | fIsDialog = FALSE;
|
---|
170 | fIsModalDialogOwner = FALSE;
|
---|
171 | OS2HwndModalDialog = 0;
|
---|
172 | fInternalMsg = FALSE;
|
---|
173 | fNoSizeMsg = FALSE;
|
---|
174 | fIsDestroyed = FALSE;
|
---|
175 | fDestroyWindowCalled = FALSE;
|
---|
176 | fCreated = FALSE;
|
---|
177 | fTaskList = FALSE;
|
---|
178 | fParentDC = FALSE;
|
---|
179 |
|
---|
180 | windowNameA = NULL;
|
---|
181 | windowNameW = NULL;
|
---|
182 | wndNameLength = 0;
|
---|
183 |
|
---|
184 | userWindowLong = NULL;;
|
---|
185 | nrUserWindowLong = 0;
|
---|
186 |
|
---|
187 | magic = WIN32PM_MAGIC;
|
---|
188 | OS2Hwnd = 0;
|
---|
189 | OS2HwndFrame = 0;
|
---|
190 | hMenu = 0;
|
---|
191 | hSysMenu = 0;
|
---|
192 | Win32Hwnd = 0;
|
---|
193 |
|
---|
194 | if(HwAllocateWindowHandle(&Win32Hwnd, (ULONG)this) == FALSE)
|
---|
195 | {
|
---|
196 | dprintf(("Win32BaseWindow::Init HwAllocateWindowHandle failed!!"));
|
---|
197 | DebugInt3();
|
---|
198 | }
|
---|
199 |
|
---|
200 | posx = posy = 0;
|
---|
201 | width = height = 0;
|
---|
202 |
|
---|
203 | dwExStyle = 0;
|
---|
204 | dwStyle = 0;
|
---|
205 | win32wndproc = 0;
|
---|
206 | hInstance = 0;
|
---|
207 | windowId = 0xFFFFFFFF; //default = -1
|
---|
208 | userData = 0;
|
---|
209 | contextHelpId = 0;
|
---|
210 |
|
---|
211 | pOldFrameProc = NULL;
|
---|
212 | borderWidth = 0;
|
---|
213 | borderHeight = 0;
|
---|
214 |
|
---|
215 | hwndLinkAfter = HWND_BOTTOM;
|
---|
216 | flags = 0;
|
---|
217 | isIcon = FALSE;
|
---|
218 | lastHitTestVal = HTOS_NORMAL;
|
---|
219 | fIgnoreHitTest = FALSE;
|
---|
220 | owner = NULL;
|
---|
221 | windowClass = 0;
|
---|
222 |
|
---|
223 | iconResource = NULL;
|
---|
224 |
|
---|
225 | EraseBkgndFlag = TRUE;
|
---|
226 | PSEraseFlag = FALSE;
|
---|
227 | SuppressEraseFlag = FALSE;
|
---|
228 |
|
---|
229 | horzScrollInfo = NULL;
|
---|
230 | vertScrollInfo = NULL;
|
---|
231 |
|
---|
232 | ownDC = 0;
|
---|
233 | hWindowRegion = 0;
|
---|
234 |
|
---|
235 | if(currentProcessId == -1)
|
---|
236 | {
|
---|
237 | currentProcessId = GetCurrentProcessId();
|
---|
238 | }
|
---|
239 | dwThreadId = GetCurrentThreadId();
|
---|
240 | dwProcessId = currentProcessId;
|
---|
241 | }
|
---|
242 | //******************************************************************************
|
---|
243 | //todo get rid of resources (menu, icon etc)
|
---|
244 | //******************************************************************************
|
---|
245 | Win32BaseWindow::~Win32BaseWindow()
|
---|
246 | {
|
---|
247 | OSLibWinSetWindowULong(OS2Hwnd, OFFSET_WIN32WNDPTR, 0);
|
---|
248 | OSLibWinSetWindowULong(OS2Hwnd, OFFSET_WIN32PM_MAGIC, 0);
|
---|
249 |
|
---|
250 | if(!fDestroyAll && getParent() && getParent()->getFirstChild() == this && getNextChild() == NULL)
|
---|
251 | {
|
---|
252 | //if we're the last child that's being destroyed and our
|
---|
253 | //parent window was also destroyed, then we delete the parent object
|
---|
254 | if(getParent()->IsWindowDestroyed())
|
---|
255 | {
|
---|
256 | dprintf(("Last Child (%x) destroyed, get rid of our parent window (%x)", getWindowHandle(), getParent()->getWindowHandle()));
|
---|
257 | delete getParent();
|
---|
258 | setParent(NULL); //or else we'll crash in the dtor of the ChildWindow class
|
---|
259 | }
|
---|
260 | }
|
---|
261 | else
|
---|
262 | if(fDestroyAll) {
|
---|
263 | dprintf(("Destroying window %x %s", getWindowHandle(), windowNameA));
|
---|
264 | setParent(NULL); //or else we'll crash in the dtor of the ChildWindow class
|
---|
265 | }
|
---|
266 |
|
---|
267 | if (isOwnDC())
|
---|
268 | releaseOwnDC (ownDC);
|
---|
269 |
|
---|
270 | if(Win32Hwnd)
|
---|
271 | HwFreeWindowHandle(Win32Hwnd);
|
---|
272 |
|
---|
273 | if(userWindowLong)
|
---|
274 | free(userWindowLong);
|
---|
275 | if(windowNameA) {
|
---|
276 | free(windowNameA);
|
---|
277 | windowNameA = NULL;
|
---|
278 | }
|
---|
279 | if(windowNameW) {
|
---|
280 | free(windowNameW);
|
---|
281 | windowNameW = NULL;
|
---|
282 | }
|
---|
283 | if(vertScrollInfo) {
|
---|
284 | free(vertScrollInfo);
|
---|
285 | vertScrollInfo = NULL;
|
---|
286 | }
|
---|
287 | if(horzScrollInfo) {
|
---|
288 | free(horzScrollInfo);
|
---|
289 | horzScrollInfo = NULL;
|
---|
290 | }
|
---|
291 | }
|
---|
292 | //******************************************************************************
|
---|
293 | //******************************************************************************
|
---|
294 | void Win32BaseWindow::DestroyAll()
|
---|
295 | {
|
---|
296 | fDestroyAll = TRUE;
|
---|
297 | GenericObject::DestroyAll(windows);
|
---|
298 | }
|
---|
299 | //******************************************************************************
|
---|
300 | //******************************************************************************
|
---|
301 | BOOL Win32BaseWindow::isChild()
|
---|
302 | {
|
---|
303 | return ((dwStyle & WS_CHILD) != 0);
|
---|
304 | }
|
---|
305 | //******************************************************************************
|
---|
306 | //******************************************************************************
|
---|
307 | BOOL Win32BaseWindow::IsWindowUnicode()
|
---|
308 | {
|
---|
309 | dprintf2(("IsWindowUnicode %x %d", getWindowHandle(), WINPROC_GetProcType(getWindowProc()) == WIN_PROC_32W));
|
---|
310 | return (WINPROC_GetProcType(getWindowProc()) == WIN_PROC_32W);
|
---|
311 | }
|
---|
312 | //******************************************************************************
|
---|
313 | //******************************************************************************
|
---|
314 | BOOL Win32BaseWindow::CreateWindowExA(CREATESTRUCTA *cs, ATOM classAtom)
|
---|
315 | {
|
---|
316 | char buffer[256];
|
---|
317 | POINT maxSize, maxPos, minTrack, maxTrack;
|
---|
318 |
|
---|
319 | #ifdef DEBUG
|
---|
320 | PrintWindowStyle(cs->style, cs->dwExStyle);
|
---|
321 | #endif
|
---|
322 |
|
---|
323 | sw = SW_SHOW;
|
---|
324 | SetLastError(0);
|
---|
325 |
|
---|
326 | /* Find the parent window */
|
---|
327 | if (cs->hwndParent)
|
---|
328 | {
|
---|
329 | Win32BaseWindow *window = GetWindowFromHandle(cs->hwndParent);
|
---|
330 | if(!window) {
|
---|
331 | dprintf(("Bad parent %04x\n", cs->hwndParent ));
|
---|
332 | SetLastError(ERROR_INVALID_PARAMETER);
|
---|
333 | return FALSE;
|
---|
334 | }
|
---|
335 | /* Make sure parent is valid */
|
---|
336 | if (!window->IsWindow() )
|
---|
337 | {
|
---|
338 | dprintf(("Bad parent %04x\n", cs->hwndParent ));
|
---|
339 | SetLastError(ERROR_INVALID_PARAMETER);
|
---|
340 | return FALSE;
|
---|
341 | }
|
---|
342 | }
|
---|
343 | else
|
---|
344 | if ((cs->style & WS_CHILD) && !(cs->style & WS_POPUP)) {
|
---|
345 | dprintf(("No parent for child window\n" ));
|
---|
346 | SetLastError(ERROR_INVALID_PARAMETER);
|
---|
347 | return FALSE; /* WS_CHILD needs a parent, but WS_POPUP doesn't */
|
---|
348 | }
|
---|
349 |
|
---|
350 | /* Find the window class */
|
---|
351 | windowClass = Win32WndClass::FindClass(cs->hInstance, (LPSTR)classAtom);
|
---|
352 | if (!windowClass)
|
---|
353 | {
|
---|
354 | GlobalGetAtomNameA( classAtom, buffer, sizeof(buffer) );
|
---|
355 | dprintf(("Bad class '%s'\n", buffer ));
|
---|
356 | SetLastError(ERROR_INVALID_PARAMETER);
|
---|
357 | return 0;
|
---|
358 | }
|
---|
359 | #ifdef DEBUG
|
---|
360 | if(HIWORD(cs->lpszClass))
|
---|
361 | {
|
---|
362 | char *astring;
|
---|
363 |
|
---|
364 | if(isUnicode) astring = UnicodeToAsciiString((LPWSTR)cs->lpszClass);
|
---|
365 | else astring = (char *)cs->lpszClass;
|
---|
366 |
|
---|
367 | dprintf(("Window class %s", astring));
|
---|
368 | if(isUnicode) FreeAsciiString(astring);
|
---|
369 | }
|
---|
370 | else dprintf(("Window class %x", cs->lpszClass));
|
---|
371 | #endif
|
---|
372 |
|
---|
373 | /* Fix the lpszClass field: from existing programs, it seems ok to call a CreateWindowXXX
|
---|
374 | * with an atom as the class name, put some programs expect to have a *REAL* string in
|
---|
375 | * lpszClass when the CREATESTRUCT is sent with WM_CREATE
|
---|
376 | */
|
---|
377 | if (!HIWORD(cs->lpszClass) ) {
|
---|
378 | if (isUnicode) {
|
---|
379 | GlobalGetAtomNameW( classAtom, (LPWSTR)buffer, sizeof(buffer) );
|
---|
380 | }
|
---|
381 | else {
|
---|
382 | GlobalGetAtomNameA( classAtom, buffer, sizeof(buffer) );
|
---|
383 | }
|
---|
384 | cs->lpszClass = buffer;
|
---|
385 | }
|
---|
386 |
|
---|
387 | /* Fix the coordinates */
|
---|
388 | if ((cs->x == CW_USEDEFAULT) || (cs->x == CW_USEDEFAULT16))
|
---|
389 | {
|
---|
390 | // PDB *pdb = PROCESS_Current();
|
---|
391 |
|
---|
392 | /* Never believe Microsoft's documentation... CreateWindowEx doc says
|
---|
393 | * that if an overlapped window is created with WS_VISIBLE style bit
|
---|
394 | * set and the x parameter is set to CW_USEDEFAULT, the system ignores
|
---|
395 | * the y parameter. However, disassembling NT implementation (WIN32K.SYS)
|
---|
396 | * reveals that
|
---|
397 | *
|
---|
398 | * 1) not only if checks for CW_USEDEFAULT but also for CW_USEDEFAULT16
|
---|
399 | * 2) it does not ignore the y parameter as the docs claim; instead, it
|
---|
400 | * uses it as second parameter to ShowWindow() unless y is either
|
---|
401 | * CW_USEDEFAULT or CW_USEDEFAULT16.
|
---|
402 | *
|
---|
403 | * The fact that we didn't do 2) caused bogus windows pop up when wine
|
---|
404 | * was running apps that were using this obscure feature. Example -
|
---|
405 | * calc.exe that comes with Win98 (only Win98, it's different from
|
---|
406 | * the one that comes with Win95 and NT)
|
---|
407 | */
|
---|
408 | if ((cs->y != CW_USEDEFAULT) && (cs->y != CW_USEDEFAULT16)) sw = cs->y;
|
---|
409 |
|
---|
410 | /* We have saved cs->y, now we can trash it */
|
---|
411 | #if 0
|
---|
412 | if ( !(cs->style & (WS_CHILD | WS_POPUP))
|
---|
413 | && (pdb->env_db->startup_info->dwFlags & STARTF_USEPOSITION) )
|
---|
414 | {
|
---|
415 | cs->x = pdb->env_db->startup_info->dwX;
|
---|
416 | cs->y = pdb->env_db->startup_info->dwY;
|
---|
417 | }
|
---|
418 | #endif
|
---|
419 | cs->x = 0;
|
---|
420 | cs->y = 0;
|
---|
421 | // }
|
---|
422 | }
|
---|
423 | if ((cs->cx == CW_USEDEFAULT) || (cs->cx == CW_USEDEFAULT16))
|
---|
424 | {
|
---|
425 | #if 0
|
---|
426 | PDB *pdb = PROCESS_Current();
|
---|
427 | if ( !(cs->style & (WS_CHILD | WS_POPUP))
|
---|
428 | && (pdb->env_db->startup_info->dwFlags & STARTF_USESIZE) )
|
---|
429 | {
|
---|
430 | cs->cx = pdb->env_db->startup_info->dwXSize;
|
---|
431 | cs->cy = pdb->env_db->startup_info->dwYSize;
|
---|
432 | }
|
---|
433 | else
|
---|
434 | {
|
---|
435 | #endif
|
---|
436 | cs->cx = 600; /* FIXME */
|
---|
437 | cs->cy = 400;
|
---|
438 | // }
|
---|
439 | }
|
---|
440 |
|
---|
441 | if (cs->x < 0) cs->x = 0;
|
---|
442 | if (cs->y < 0) cs->y = 0;
|
---|
443 |
|
---|
444 | //Allocate window words
|
---|
445 | nrUserWindowLong = windowClass->getExtraWndWords();
|
---|
446 | if(nrUserWindowLong) {
|
---|
447 | userWindowLong = (ULONG *)_smalloc(nrUserWindowLong);
|
---|
448 | memset(userWindowLong, 0, nrUserWindowLong);
|
---|
449 | }
|
---|
450 |
|
---|
451 | if ((cs->style & WS_CHILD) && cs->hwndParent)
|
---|
452 | {
|
---|
453 | SetParent(cs->hwndParent);
|
---|
454 | owner = GetWindowFromHandle(cs->hwndParent);
|
---|
455 | if(owner == NULL)
|
---|
456 | {
|
---|
457 | dprintf(("HwGetWindowHandleData couldn't find owner window %x!!!", cs->hwndParent));
|
---|
458 | SetLastError(ERROR_INVALID_WINDOW_HANDLE);
|
---|
459 | return FALSE;
|
---|
460 | }
|
---|
461 | }
|
---|
462 | else
|
---|
463 | {
|
---|
464 | SetParent(0);
|
---|
465 | if (!cs->hwndParent || (cs->hwndParent == windowDesktop->getWindowHandle())) {
|
---|
466 | owner = NULL;
|
---|
467 | }
|
---|
468 | else
|
---|
469 | {
|
---|
470 | owner = GetWindowFromHandle(cs->hwndParent)->GetTopParent();
|
---|
471 | if(owner == NULL)
|
---|
472 | {
|
---|
473 | dprintf(("HwGetWindowHandleData couldn't find owner window %x!!!", cs->hwndParent));
|
---|
474 | SetLastError(ERROR_INVALID_WINDOW_HANDLE);
|
---|
475 | return FALSE;
|
---|
476 | }
|
---|
477 | }
|
---|
478 | }
|
---|
479 |
|
---|
480 | WINPROC_SetProc((HWINDOWPROC *)&win32wndproc, windowClass->getWindowProc(), WINPROC_GetProcType(windowClass->getWindowProc()), WIN_PROC_WINDOW);
|
---|
481 | hInstance = cs->hInstance;
|
---|
482 | dwStyle = cs->style & ~WS_VISIBLE;
|
---|
483 | dwExStyle = cs->dwExStyle;
|
---|
484 |
|
---|
485 | hwndLinkAfter = HWND_TOP;
|
---|
486 | if(CONTROLS_IsControl(this, BUTTON_CONTROL) && ((dwStyle & 0x0f) == BS_GROUPBOX))
|
---|
487 | {
|
---|
488 | hwndLinkAfter = HWND_BOTTOM;
|
---|
489 | dwStyle |= WS_CLIPSIBLINGS;
|
---|
490 | }
|
---|
491 | else
|
---|
492 | if(CONTROLS_IsControl(this, STATIC_CONTROL) && !(dwStyle & WS_GROUP)) {
|
---|
493 | dwStyle |= WS_CLIPSIBLINGS;
|
---|
494 | }
|
---|
495 |
|
---|
496 | /* Increment class window counter */
|
---|
497 | windowClass->IncreaseWindowCount();
|
---|
498 |
|
---|
499 | if (HOOK_IsHooked( WH_CBT ))
|
---|
500 | {
|
---|
501 | CBT_CREATEWNDA cbtc;
|
---|
502 | LRESULT ret;
|
---|
503 |
|
---|
504 | cbtc.lpcs = cs;
|
---|
505 | cbtc.hwndInsertAfter = hwndLinkAfter;
|
---|
506 | ret = HOOK_CallHooksA(WH_CBT, HCBT_CREATEWND, getWindowHandle(), (LPARAM)&cbtc);
|
---|
507 | if(ret)
|
---|
508 | {
|
---|
509 | dprintf(("CBT-hook returned 0!!"));
|
---|
510 | SetLastError(ERROR_CAN_NOT_COMPLETE); //todo: wrong error
|
---|
511 | return FALSE;
|
---|
512 | }
|
---|
513 | }
|
---|
514 |
|
---|
515 | /* Correct the window style */
|
---|
516 | if (!(cs->style & WS_CHILD))
|
---|
517 | {
|
---|
518 | dwStyle |= WS_CLIPSIBLINGS;
|
---|
519 | if (!(cs->style & WS_POPUP))
|
---|
520 | {
|
---|
521 | dwStyle |= WS_CAPTION;
|
---|
522 | flags |= WIN_NEED_SIZE;
|
---|
523 | }
|
---|
524 | }
|
---|
525 | if (cs->dwExStyle & WS_EX_DLGMODALFRAME) dwStyle &= ~WS_THICKFRAME;
|
---|
526 |
|
---|
527 | if (cs->style & WS_HSCROLL)
|
---|
528 | {
|
---|
529 | horzScrollInfo = (SCROLLBAR_INFO*)malloc(sizeof(SCROLLBAR_INFO));
|
---|
530 | horzScrollInfo->MinVal = horzScrollInfo->CurVal = horzScrollInfo->Page = 0;
|
---|
531 | horzScrollInfo->MaxVal = 100;
|
---|
532 | horzScrollInfo->flags = ESB_ENABLE_BOTH;
|
---|
533 | }
|
---|
534 |
|
---|
535 | if (cs->style & WS_VSCROLL)
|
---|
536 | {
|
---|
537 | vertScrollInfo = (SCROLLBAR_INFO*)malloc(sizeof(SCROLLBAR_INFO));
|
---|
538 | vertScrollInfo->MinVal = vertScrollInfo->CurVal = vertScrollInfo->Page = 0;
|
---|
539 | vertScrollInfo->MaxVal = 100;
|
---|
540 | vertScrollInfo->flags = ESB_ENABLE_BOTH;
|
---|
541 | }
|
---|
542 |
|
---|
543 | /* Send the WM_GETMINMAXINFO message and fix the size if needed */
|
---|
544 | if ((cs->style & WS_THICKFRAME) || !(cs->style & (WS_POPUP | WS_CHILD)))
|
---|
545 | {
|
---|
546 | GetMinMaxInfo(&maxSize, &maxPos, &minTrack, &maxTrack);
|
---|
547 | if (maxSize.x < cs->cx) cs->cx = maxSize.x;
|
---|
548 | if (maxSize.y < cs->cy) cs->cy = maxSize.y;
|
---|
549 | if (cs->cx < minTrack.x ) cs->cx = minTrack.x;
|
---|
550 | if (cs->cy < minTrack.y ) cs->cy = minTrack.y;
|
---|
551 | }
|
---|
552 |
|
---|
553 | if(cs->style & WS_CHILD)
|
---|
554 | {
|
---|
555 | if(cs->cx < 0) cs->cx = 0;
|
---|
556 | if(cs->cy < 0) cs->cy = 0;
|
---|
557 | }
|
---|
558 | else
|
---|
559 | {
|
---|
560 | if (cs->cx <= 0) cs->cx = 1;
|
---|
561 | if (cs->cy <= 0) cs->cy = 1;
|
---|
562 | }
|
---|
563 |
|
---|
564 | if(((dwStyle & 0xC0000000) == WS_OVERLAPPED) && ((dwStyle & WS_CAPTION) == WS_CAPTION) && owner == NULL
|
---|
565 | && dwStyle & WS_SYSMENU)
|
---|
566 | {
|
---|
567 | fTaskList = TRUE;
|
---|
568 | }
|
---|
569 |
|
---|
570 | DWORD dwOSWinStyle, dwOSFrameStyle;
|
---|
571 |
|
---|
572 | OSLibWinConvertStyle(dwStyle, &dwExStyle, &dwOSWinStyle, &dwOSFrameStyle, &borderWidth, &borderHeight);
|
---|
573 |
|
---|
574 | if(HIWORD(cs->lpszName))
|
---|
575 | {
|
---|
576 | if (!isUnicode)
|
---|
577 | {
|
---|
578 | wndNameLength = strlen(cs->lpszName);
|
---|
579 | windowNameA = (LPSTR)_smalloc(wndNameLength+1);
|
---|
580 | strcpy(windowNameA,cs->lpszName);
|
---|
581 | windowNameW = (LPWSTR)_smalloc((wndNameLength+1)*sizeof(WCHAR));
|
---|
582 | lstrcpyAtoW(windowNameW,windowNameA);
|
---|
583 | windowNameA[wndNameLength] = 0;
|
---|
584 | windowNameW[wndNameLength] = 0;
|
---|
585 | }
|
---|
586 | else
|
---|
587 | {
|
---|
588 | wndNameLength = lstrlenW((LPWSTR)cs->lpszName);
|
---|
589 | windowNameA = (LPSTR)_smalloc(wndNameLength+1);
|
---|
590 | lstrcpyWtoA(windowNameA,(LPWSTR)cs->lpszName);
|
---|
591 | windowNameW = (LPWSTR)_smalloc((wndNameLength+1)*sizeof(WCHAR));
|
---|
592 | lstrcpyW(windowNameW,(LPWSTR)cs->lpszName);
|
---|
593 | windowNameA[wndNameLength] = 0;
|
---|
594 | windowNameW[wndNameLength] = 0;
|
---|
595 | }
|
---|
596 | }
|
---|
597 |
|
---|
598 | //copy pointer of CREATESTRUCT for usage in MsgCreate method
|
---|
599 | tmpcs = cs;
|
---|
600 |
|
---|
601 | //Store our window object pointer in thread local memory, so PMWINDOW.CPP can retrieve it
|
---|
602 | THDB *thdb = GetThreadTHDB();
|
---|
603 |
|
---|
604 | if(thdb == NULL) {
|
---|
605 | dprintf(("Window creation failed - thdb == NULL")); //this is VERY bad
|
---|
606 | ExitProcess(666);
|
---|
607 | return FALSE;
|
---|
608 | }
|
---|
609 |
|
---|
610 | thdb->newWindow = (ULONG)this;
|
---|
611 |
|
---|
612 | OS2Hwnd = OSLibWinCreateWindow((getParent()) ? getParent()->getOS2WindowHandle() : OSLIB_HWND_DESKTOP,
|
---|
613 | dwOSWinStyle,(char *)windowNameA,
|
---|
614 | (owner) ? owner->getOS2WindowHandle() : OSLIB_HWND_DESKTOP,
|
---|
615 | (hwndLinkAfter == HWND_BOTTOM) ? TRUE : FALSE,
|
---|
616 | &OS2HwndFrame, 0, fTaskList);
|
---|
617 | if(OS2Hwnd == 0) {
|
---|
618 | dprintf(("Window creation failed!!"));
|
---|
619 | SetLastError(ERROR_OUTOFMEMORY); //TODO: Better error
|
---|
620 | return FALSE;
|
---|
621 | }
|
---|
622 |
|
---|
623 | SetLastError(0);
|
---|
624 | return TRUE;
|
---|
625 | }
|
---|
626 | //******************************************************************************
|
---|
627 | //******************************************************************************
|
---|
628 | BOOL Win32BaseWindow::MsgCreate(HWND hwndFrame, HWND hwndClient)
|
---|
629 | {
|
---|
630 | POINT maxPos;
|
---|
631 | CREATESTRUCTA *cs = tmpcs; //pointer to CREATESTRUCT used in CreateWindowExA method
|
---|
632 |
|
---|
633 | OS2Hwnd = hwndClient;
|
---|
634 | OS2HwndFrame = hwndFrame;
|
---|
635 |
|
---|
636 | fNoSizeMsg = TRUE;
|
---|
637 |
|
---|
638 | if(OSLibWinSetWindowULong(OS2Hwnd, OFFSET_WIN32WNDPTR, (ULONG)this) == FALSE) {
|
---|
639 | dprintf(("WM_CREATE: WinSetWindowULong %X failed!!", OS2Hwnd));
|
---|
640 | SetLastError(ERROR_OUTOFMEMORY); //TODO: Better error
|
---|
641 | return FALSE;
|
---|
642 | }
|
---|
643 | if(OSLibWinSetWindowULong(OS2Hwnd, OFFSET_WIN32PM_MAGIC, WIN32PM_MAGIC) == FALSE) {
|
---|
644 | dprintf(("WM_CREATE: WinSetWindowULong2 %X failed!!", OS2Hwnd));
|
---|
645 | SetLastError(ERROR_OUTOFMEMORY); //TODO: Better error
|
---|
646 | return FALSE;
|
---|
647 | }
|
---|
648 |
|
---|
649 | OSLibWinSetOwner(OS2Hwnd, OS2HwndFrame);
|
---|
650 |
|
---|
651 | fakeWinBase.hwndThis = OS2Hwnd;
|
---|
652 | fakeWinBase.pWindowClass = windowClass;
|
---|
653 |
|
---|
654 | //Set icon from class
|
---|
655 | if(windowClass->getIcon())
|
---|
656 | SetIcon(windowClass->getIcon());
|
---|
657 | /* Get class or window DC if needed */
|
---|
658 | if(windowClass->getStyle() & CS_OWNDC) {
|
---|
659 | dprintf(("Class with CS_OWNDC style"));
|
---|
660 | // ownDC = GetWindowDC(getWindowHandle());
|
---|
661 | }
|
---|
662 | else
|
---|
663 | if (windowClass->getStyle() & CS_PARENTDC) {
|
---|
664 | dprintf(("WARNING: Class with CS_PARENTDC style!"));
|
---|
665 | fParentDC = TRUE;
|
---|
666 | ownDC = 0;
|
---|
667 | }
|
---|
668 | else
|
---|
669 | if (windowClass->getStyle() & CS_CLASSDC) {
|
---|
670 | dprintf(("WARNING: Class with CS_CLASSDC style!"));
|
---|
671 | ownDC = 0;
|
---|
672 | }
|
---|
673 | /* Set the window menu */
|
---|
674 | if ((dwStyle & (WS_CAPTION | WS_CHILD)) == WS_CAPTION )
|
---|
675 | {
|
---|
676 | #if 0 //CB: todo
|
---|
677 | if (cs->hMenu) {
|
---|
678 | SetMenu(cs->hMenu);
|
---|
679 | }
|
---|
680 | else {
|
---|
681 | if (windowClass->getMenuNameA()) {
|
---|
682 | cs->hMenu = LoadMenuA(cs->hInstance, windowClass->getMenuNameA());
|
---|
683 | if (cs->hMenu) SetMenu(cs->hMenu );
|
---|
684 | }
|
---|
685 | }
|
---|
686 | #endif
|
---|
687 | }
|
---|
688 | else
|
---|
689 | {
|
---|
690 | setWindowId((DWORD)cs->hMenu);
|
---|
691 | }
|
---|
692 |
|
---|
693 | // Subclass frame
|
---|
694 | pOldFrameProc = FrameSubclassFrameWindow(this);
|
---|
695 | //if (isChild()) FrameSetBorderSize(this,TRUE);
|
---|
696 |
|
---|
697 | //preset rects
|
---|
698 | rectWindow.left = cs->x;
|
---|
699 | rectWindow.right = cs->x+cs->cx;
|
---|
700 | rectWindow.top = cs->y;
|
---|
701 | rectWindow.bottom = cs->y+cs->cy;
|
---|
702 | rectClient = rectWindow; //dummy client rect
|
---|
703 | if (getParent()) mapWin32Rect(getParent()->getOS2WindowHandle(),OSLIB_HWND_DESKTOP,&rectWindow);
|
---|
704 | /* Send the WM_CREATE message
|
---|
705 | * Perhaps we shouldn't allow width/height changes as well.
|
---|
706 | * See p327 in "Internals".
|
---|
707 | */
|
---|
708 | maxPos.x = rectWindow.left; maxPos.y = rectWindow.top;
|
---|
709 |
|
---|
710 | //Note: Solitaire crashes when receiving WM_SIZE messages before WM_CREATE
|
---|
711 | //fNoSizeMsg = FALSE;
|
---|
712 | fCreated = TRUE;
|
---|
713 |
|
---|
714 | if (SendInternalMessageA(WM_NCCREATE,0,(LPARAM)cs))
|
---|
715 | {
|
---|
716 | //update rect
|
---|
717 | rectWindow.left = cs->x;
|
---|
718 | rectWindow.right = cs->x+cs->cx;
|
---|
719 | rectWindow.top = cs->y;
|
---|
720 | rectWindow.bottom = cs->y+cs->cy;
|
---|
721 | if (getParent()) mapWin32Rect(getParent()->getOS2WindowHandle(),OSLIB_HWND_DESKTOP,&rectWindow);
|
---|
722 | OffsetRect(&rectWindow, maxPos.x - rectWindow.left, maxPos.y - rectWindow.top);
|
---|
723 | rectClient = rectWindow;
|
---|
724 | if (getParent()) mapWin32Rect(OSLIB_HWND_DESKTOP,getParent()->getOS2WindowHandle(),&rectClient);
|
---|
725 | //set the window size and update the client
|
---|
726 | SetWindowPos(hwndLinkAfter,rectClient.left,rectClient.top,rectClient.right-rectClient.left,rectClient.bottom-rectClient.top,SWP_NOACTIVATE | SWP_NOREDRAW | SWP_FRAMECHANGED);
|
---|
727 | fNoSizeMsg = FALSE;
|
---|
728 | if (cs->style & WS_VISIBLE) dwStyle |= WS_VISIBLE; //program could change position in WM_CREATE
|
---|
729 | if( (SendInternalMessageA(WM_CREATE, 0, (LPARAM)cs )) != -1 )
|
---|
730 | {
|
---|
731 | if(!(flags & WIN_NEED_SIZE)) {
|
---|
732 | SendInternalMessageA(WM_SIZE, SIZE_RESTORED,
|
---|
733 | MAKELONG(rectClient.right-rectClient.left,
|
---|
734 | rectClient.bottom-rectClient.top));
|
---|
735 | SendInternalMessageA(WM_MOVE, 0, MAKELONG( rectClient.left, rectClient.top ) );
|
---|
736 | }
|
---|
737 |
|
---|
738 | if( (getStyle() & WS_CHILD) && !(getExStyle() & WS_EX_NOPARENTNOTIFY) )
|
---|
739 | {
|
---|
740 | /* Notify the parent window only */
|
---|
741 | SendInternalMessageA(WM_PARENTNOTIFY, MAKEWPARAM(WM_CREATE, getWindowId()), (LPARAM)getWindowHandle());
|
---|
742 | if(!::IsWindow(getWindowHandle()))
|
---|
743 | {
|
---|
744 | dprintf(("Createwindow: WM_PARENTNOTIFY destroyed window"));
|
---|
745 | goto end;
|
---|
746 | }
|
---|
747 | }
|
---|
748 |
|
---|
749 | if (cs->style & WS_VISIBLE) ShowWindow(sw);
|
---|
750 |
|
---|
751 | /* Call WH_SHELL hook */
|
---|
752 | if (!(getStyle() & WS_CHILD) && !owner)
|
---|
753 | HOOK_CallHooksA(WH_SHELL, HSHELL_WINDOWCREATED, getWindowHandle(), 0 );
|
---|
754 |
|
---|
755 | SetLastError(0);
|
---|
756 | return TRUE;
|
---|
757 | }
|
---|
758 | }
|
---|
759 | dprintf(("Window creation FAILED (NCCREATE cancelled creation)"));
|
---|
760 | SetLastError(ERROR_OUTOFMEMORY); //TODO: Better error
|
---|
761 | end:
|
---|
762 | return FALSE;
|
---|
763 | }
|
---|
764 | //******************************************************************************
|
---|
765 | //******************************************************************************
|
---|
766 | ULONG Win32BaseWindow::MsgQuit()
|
---|
767 | {
|
---|
768 | return SendInternalMessageA(WM_QUIT, 0, 0);
|
---|
769 | }
|
---|
770 | //******************************************************************************
|
---|
771 | //******************************************************************************
|
---|
772 | ULONG Win32BaseWindow::MsgClose()
|
---|
773 | {
|
---|
774 | return SendInternalMessageA(WM_CLOSE,0,0);
|
---|
775 | }
|
---|
776 | //******************************************************************************
|
---|
777 | //******************************************************************************
|
---|
778 | ULONG Win32BaseWindow::MsgDestroy()
|
---|
779 | {
|
---|
780 | ULONG rc;
|
---|
781 | Win32BaseWindow *child;
|
---|
782 | HWND hwnd = getWindowHandle();
|
---|
783 |
|
---|
784 | if (isSubclassedOS2Wnd) OSLibWinSubclassWindow(OS2Hwnd,pOldWndProc);
|
---|
785 |
|
---|
786 | fIsDestroyed = TRUE;
|
---|
787 |
|
---|
788 | if(fDestroyWindowCalled == FALSE)
|
---|
789 | {//this window was destroyed because DestroyWindow was called for it's parent
|
---|
790 | //so: send a WM_PARENTNOTIFY now as that hasn't happened yet
|
---|
791 | if((getStyle() & WS_CHILD) && !(getExStyle() & WS_EX_NOPARENTNOTIFY))
|
---|
792 | {
|
---|
793 | if(getParent())
|
---|
794 | {
|
---|
795 | /* Notify the parent window only */
|
---|
796 | getParent()->SendMessageA(WM_PARENTNOTIFY, MAKEWPARAM(WM_DESTROY, getWindowId()), (LPARAM)getWindowHandle());
|
---|
797 | }
|
---|
798 | else DebugInt3();
|
---|
799 | }
|
---|
800 | }
|
---|
801 | SendInternalMessageA(WM_DESTROY, 0, 0);
|
---|
802 | if(::IsWindow(hwnd) == FALSE) {
|
---|
803 | //object already destroyed, so return immediately
|
---|
804 | return 1;
|
---|
805 | }
|
---|
806 | SendInternalMessageA(WM_NCDESTROY, 0, 0);
|
---|
807 |
|
---|
808 | TIMER_KillTimerFromWindow(OS2Hwnd);
|
---|
809 |
|
---|
810 | if(getFirstChild() == NULL) {
|
---|
811 | delete this;
|
---|
812 | }
|
---|
813 | return 1;
|
---|
814 | }
|
---|
815 | //******************************************************************************
|
---|
816 | //******************************************************************************
|
---|
817 | ULONG Win32BaseWindow::MsgEnable(BOOL fEnable)
|
---|
818 | {
|
---|
819 | if(fEnable) {
|
---|
820 | dwStyle &= ~WS_DISABLED;
|
---|
821 | }
|
---|
822 | else dwStyle |= WS_DISABLED;
|
---|
823 |
|
---|
824 | return SendInternalMessageA(WM_ENABLE, fEnable, 0);
|
---|
825 | }
|
---|
826 | //******************************************************************************
|
---|
827 | //TODO: SW_PARENTCLOSING/OPENING flag (lParam)
|
---|
828 | //******************************************************************************
|
---|
829 | ULONG Win32BaseWindow::MsgShow(BOOL fShow)
|
---|
830 | {
|
---|
831 | if(fNoSizeMsg) {
|
---|
832 | return 1;
|
---|
833 | }
|
---|
834 |
|
---|
835 | if(fShow) {
|
---|
836 | setStyle(getStyle() | WS_VISIBLE);
|
---|
837 | }
|
---|
838 | else setStyle(getStyle() & ~WS_VISIBLE);
|
---|
839 |
|
---|
840 | return SendInternalMessageA(WM_SHOWWINDOW, fShow, 0);
|
---|
841 | }
|
---|
842 | //******************************************************************************
|
---|
843 | //******************************************************************************
|
---|
844 | ULONG Win32BaseWindow::MsgPosChanging(LPARAM lp)
|
---|
845 | {
|
---|
846 | //SvL: Notes crashes when switching views (calls DestroyWindow -> PM sends
|
---|
847 | // a WM_WINDOWPOSCHANGED msg -> crash)
|
---|
848 | if(fNoSizeMsg || fDestroyWindowCalled)
|
---|
849 | return 1;
|
---|
850 |
|
---|
851 | return SendInternalMessageA(WM_WINDOWPOSCHANGING, 0, lp);
|
---|
852 | }
|
---|
853 | //******************************************************************************
|
---|
854 | //******************************************************************************
|
---|
855 | ULONG Win32BaseWindow::MsgPosChanged(LPARAM lp)
|
---|
856 | {
|
---|
857 | //SvL: Notes crashes when switching views (calls DestroyWindow -> PM sends
|
---|
858 | // a WM_WINDOWPOSCHANGED msg -> crash)
|
---|
859 | if(fNoSizeMsg || fDestroyWindowCalled)
|
---|
860 | return 1;
|
---|
861 |
|
---|
862 | return SendInternalMessageA(WM_WINDOWPOSCHANGED, 0, lp);
|
---|
863 | }
|
---|
864 | //******************************************************************************
|
---|
865 | //******************************************************************************
|
---|
866 | #if 0
|
---|
867 | ULONG Win32BaseWindow::MsgMinMax()
|
---|
868 | {
|
---|
869 |
|
---|
870 | }
|
---|
871 | #endif
|
---|
872 | //******************************************************************************
|
---|
873 | //******************************************************************************
|
---|
874 | ULONG Win32BaseWindow::MsgScroll(ULONG msg, ULONG scrollCode, ULONG scrollPos)
|
---|
875 | {
|
---|
876 | //According to the SDK docs, the scrollbar handle (lParam) is 0 when the standard
|
---|
877 | //window scrollbars send these messages
|
---|
878 | return SendInternalMessageA(msg, MAKELONG(scrollCode, scrollPos), 0);
|
---|
879 | }
|
---|
880 | //******************************************************************************
|
---|
881 | //******************************************************************************
|
---|
882 | ULONG Win32BaseWindow::MsgHitTest(MSG *msg)
|
---|
883 | {
|
---|
884 | lastHitTestVal = SendInternalMessageA(WM_NCHITTEST,msg->wParam,msg->lParam);
|
---|
885 | dprintf2(("MsgHitTest returned %x", lastHitTestVal));
|
---|
886 |
|
---|
887 | if (lastHitTestVal == HTERROR)
|
---|
888 | return HTOS_ERROR;
|
---|
889 |
|
---|
890 | #if 0 //CB: problems with groupboxes, internal handling is better
|
---|
891 | if (lastHitTestVal == HTTRANSPARENT)
|
---|
892 | return HTOS_TRANSPARENT;
|
---|
893 | #endif
|
---|
894 |
|
---|
895 | return HTOS_NORMAL;
|
---|
896 | }
|
---|
897 | //******************************************************************************
|
---|
898 | //******************************************************************************
|
---|
899 | ULONG Win32BaseWindow::MsgActivate(BOOL fActivate, BOOL fMinimized, HWND hwnd)
|
---|
900 | {
|
---|
901 | ULONG rc, curprocid, procidhwnd = -1, threadidhwnd = 0;
|
---|
902 |
|
---|
903 |
|
---|
904 | //According to SDK docs, if app returns FALSE & window is being deactivated,
|
---|
905 | //default processing is cancelled
|
---|
906 | //TODO: According to Wine we should proceed anyway if window is sysmodal
|
---|
907 | if(SendInternalMessageA(WM_NCACTIVATE, fActivate, 0) == FALSE && !fActivate)
|
---|
908 | {
|
---|
909 | return 0;
|
---|
910 | }
|
---|
911 | rc = SendInternalMessageA(WM_ACTIVATE, MAKELONG((fActivate) ? WA_ACTIVE : WA_INACTIVE, fMinimized), hwnd);
|
---|
912 |
|
---|
913 | curprocid = GetCurrentProcessId();
|
---|
914 | if(hwnd) {
|
---|
915 | threadidhwnd = GetWindowThreadProcessId(hwnd, &procidhwnd);
|
---|
916 | }
|
---|
917 |
|
---|
918 | if(curprocid != procidhwnd && fActivate) {
|
---|
919 | SendInternalMessageA(WM_ACTIVATEAPP, 1, threadidhwnd);
|
---|
920 | }
|
---|
921 | return rc;
|
---|
922 | }
|
---|
923 | //******************************************************************************
|
---|
924 | //TODO: Is this correct and complete?
|
---|
925 | //Add print screen, break & numlock
|
---|
926 | //******************************************************************************
|
---|
927 | void Win32BaseWindow::setExtendedKey(ULONG virtualkey, ULONG *lParam)
|
---|
928 | {
|
---|
929 | switch(virtualkey) {
|
---|
930 | case VK_DOWN:
|
---|
931 | case VK_UP:
|
---|
932 | case VK_PRIOR:
|
---|
933 | case VK_NEXT:
|
---|
934 | case VK_END:
|
---|
935 | case VK_DIVIDE:
|
---|
936 | case VK_DELETE:
|
---|
937 | case VK_EXECUTE: //Numeric enter key?
|
---|
938 | case VK_HOME:
|
---|
939 | case VK_INSERT:
|
---|
940 | case VK_RCONTROL:
|
---|
941 | case VK_RMENU: //is this the right alt???
|
---|
942 | *lParam = *lParam | (1<<24);
|
---|
943 | }
|
---|
944 | }
|
---|
945 | //******************************************************************************
|
---|
946 | //******************************************************************************
|
---|
947 | ULONG Win32BaseWindow::DispatchMsgA(MSG *msg)
|
---|
948 | {
|
---|
949 | return SendInternalMessageA(msg->message, msg->wParam, msg->lParam);
|
---|
950 | }
|
---|
951 | //******************************************************************************
|
---|
952 | //******************************************************************************
|
---|
953 | ULONG Win32BaseWindow::DispatchMsgW(MSG *msg)
|
---|
954 | {
|
---|
955 | return SendInternalMessageW(msg->message, msg->wParam, msg->lParam);
|
---|
956 | }
|
---|
957 | //******************************************************************************
|
---|
958 | //******************************************************************************
|
---|
959 | ULONG Win32BaseWindow::MsgSetFocus(HWND hwnd)
|
---|
960 | {
|
---|
961 | return SendInternalMessageA(WM_SETFOCUS, hwnd, 0);
|
---|
962 | }
|
---|
963 | //******************************************************************************
|
---|
964 | //******************************************************************************
|
---|
965 | ULONG Win32BaseWindow::MsgKillFocus(HWND hwnd)
|
---|
966 | {
|
---|
967 | return SendInternalMessageA(WM_KILLFOCUS, hwnd, 0);
|
---|
968 | }
|
---|
969 | //******************************************************************************
|
---|
970 | //******************************************************************************
|
---|
971 | ULONG Win32BaseWindow::MsgButton(MSG *msg)
|
---|
972 | {
|
---|
973 | BOOL fClick = FALSE;
|
---|
974 |
|
---|
975 | dprintf(("MsgButton at (%d,%d)", msg->pt.x, msg->pt.y));
|
---|
976 | switch(msg->message) {
|
---|
977 | case WM_LBUTTONDBLCLK:
|
---|
978 | case WM_RBUTTONDBLCLK:
|
---|
979 | case WM_MBUTTONDBLCLK:
|
---|
980 | case WM_NCLBUTTONDBLCLK:
|
---|
981 | case WM_NCRBUTTONDBLCLK:
|
---|
982 | case WM_NCMBUTTONDBLCLK:
|
---|
983 | if (!(windowClass && windowClass->getClassLongA(GCL_STYLE) & CS_DBLCLKS) && (msg->message != WM_NCLBUTTONDBLCLK))
|
---|
984 | {
|
---|
985 | msg->message = msg->message - (WM_LBUTTONDBLCLK - WM_LBUTTONDOWN); //dblclick -> down
|
---|
986 | MsgButton(msg);
|
---|
987 | msg->message++; //button-up
|
---|
988 | return MsgButton(msg);
|
---|
989 | }
|
---|
990 | break;
|
---|
991 | case WM_LBUTTONDOWN:
|
---|
992 | case WM_RBUTTONDOWN:
|
---|
993 | case WM_MBUTTONDOWN:
|
---|
994 | case WM_NCLBUTTONDOWN:
|
---|
995 | case WM_NCRBUTTONDOWN:
|
---|
996 | case WM_NCMBUTTONDOWN:
|
---|
997 | fClick = TRUE;
|
---|
998 | break;
|
---|
999 | }
|
---|
1000 |
|
---|
1001 | if(ISMOUSE_CAPTURED())
|
---|
1002 | {
|
---|
1003 | if(DInputMouseHandler(getWindowHandle(), MOUSEMSG_BUTTON, msg->pt.x, msg->pt.y))
|
---|
1004 | return 0;
|
---|
1005 | }
|
---|
1006 |
|
---|
1007 | if(fClick)
|
---|
1008 | {
|
---|
1009 | HWND hwndTop;
|
---|
1010 |
|
---|
1011 | /* Activate the window if needed */
|
---|
1012 | if(isSubclassedOS2Wnd()) {
|
---|
1013 | Win32BaseWindow *parentwnd = GetWindowFromOS2FrameHandle(OSLibWinQueryWindow(OS2Hwnd, QWOS_PARENT));
|
---|
1014 | if(parentwnd) {
|
---|
1015 | hwndTop = (parentwnd->GetTopParent()) ? parentwnd->GetTopParent()->getWindowHandle() : 0;
|
---|
1016 | }
|
---|
1017 | else hwndTop = 0;
|
---|
1018 | }
|
---|
1019 | else hwndTop = (GetTopParent()) ? GetTopParent()->getWindowHandle() : 0;
|
---|
1020 |
|
---|
1021 | HWND hwndActive = GetActiveWindow();
|
---|
1022 | if (hwndTop && (getWindowHandle() != hwndActive))
|
---|
1023 | {
|
---|
1024 | LONG ret = SendInternalMessageA(WM_MOUSEACTIVATE, hwndTop,
|
---|
1025 | MAKELONG( lastHitTestVal, msg->message) );
|
---|
1026 |
|
---|
1027 | #if 0
|
---|
1028 | if ((ret == MA_ACTIVATEANDEAT) || (ret == MA_NOACTIVATEANDEAT))
|
---|
1029 | eatMsg = TRUE;
|
---|
1030 | #endif
|
---|
1031 | if(((ret == MA_ACTIVATE) || (ret == MA_ACTIVATEANDEAT))
|
---|
1032 | && hwndTop != GetForegroundWindow() )
|
---|
1033 | {
|
---|
1034 | ::SetActiveWindow(hwndTop);
|
---|
1035 | }
|
---|
1036 | }
|
---|
1037 | }
|
---|
1038 |
|
---|
1039 | SendInternalMessageA(WM_SETCURSOR, getWindowHandle(), MAKELONG(lastHitTestVal, msg->message));
|
---|
1040 |
|
---|
1041 | return SendInternalMessageA(msg->message, msg->wParam, msg->lParam);
|
---|
1042 | }
|
---|
1043 | //******************************************************************************
|
---|
1044 | //******************************************************************************
|
---|
1045 | ULONG Win32BaseWindow::MsgPaint(ULONG tmp1, BOOL select)
|
---|
1046 | {
|
---|
1047 | if (select && isIcon)
|
---|
1048 | return SendInternalMessageA(WM_PAINTICON, 0, 0);
|
---|
1049 | else
|
---|
1050 | return SendInternalMessageA(WM_PAINT, 0, 0);
|
---|
1051 | }
|
---|
1052 | //******************************************************************************
|
---|
1053 | //TODO: Is the clipper region of the window DC equal to the invalidated rectangle?
|
---|
1054 | // (or are we simply erasing too much here)
|
---|
1055 | //******************************************************************************
|
---|
1056 | ULONG Win32BaseWindow::MsgEraseBackGround(HDC hdc)
|
---|
1057 | {
|
---|
1058 | ULONG rc;
|
---|
1059 | HDC hdcErase = hdc;
|
---|
1060 |
|
---|
1061 | if (hdcErase == 0)
|
---|
1062 | hdcErase = O32_GetDC(OS2Hwnd);
|
---|
1063 |
|
---|
1064 | if(isIcon)
|
---|
1065 | rc = SendInternalMessageA(WM_ICONERASEBKGND, hdcErase, 0);
|
---|
1066 | else
|
---|
1067 | rc = SendInternalMessageA(WM_ERASEBKGND, hdcErase, 0);
|
---|
1068 | if (hdc == 0)
|
---|
1069 | O32_ReleaseDC(OS2Hwnd, hdcErase);
|
---|
1070 | return (rc);
|
---|
1071 | }
|
---|
1072 | //******************************************************************************
|
---|
1073 | //******************************************************************************
|
---|
1074 | ULONG Win32BaseWindow::MsgMouseMove(MSG *msg)
|
---|
1075 | {
|
---|
1076 | if(ISMOUSE_CAPTURED()) {
|
---|
1077 | if(DInputMouseHandler(getWindowHandle(), MOUSEMSG_MOVE, msg->pt.x, msg->pt.y))
|
---|
1078 | return 0;
|
---|
1079 | }
|
---|
1080 |
|
---|
1081 | //TODO: hiword should be 0 if window enters menu mode (SDK docs)
|
---|
1082 | SendInternalMessageA(WM_SETCURSOR, Win32Hwnd, MAKELONG(lastHitTestVal, msg->message));
|
---|
1083 |
|
---|
1084 | //translated message == WM_(NC)MOUSEMOVE
|
---|
1085 | return SendInternalMessageA(msg->message, msg->wParam, msg->lParam);
|
---|
1086 | }
|
---|
1087 | //******************************************************************************
|
---|
1088 | //TODO: Depending on menu type, we should send WM_INITMENU or WM_INITPOPUPMENU
|
---|
1089 | //TODO: PM sends it for each submenu that gets activated; Windows only for the first
|
---|
1090 | // submenu; once the menu bar is active, moving the cursor doesn't generate other
|
---|
1091 | // WM_INITMENU msgs. Not really a problem, but might need to fix this later on.
|
---|
1092 | //******************************************************************************
|
---|
1093 | ULONG Win32BaseWindow::MsgInitMenu(MSG *msg)
|
---|
1094 | {
|
---|
1095 | return SendInternalMessageA(msg->message, msg->wParam, msg->lParam);
|
---|
1096 | }
|
---|
1097 | //******************************************************************************
|
---|
1098 | //******************************************************************************
|
---|
1099 | ULONG Win32BaseWindow::MsgNCPaint()
|
---|
1100 | {
|
---|
1101 | RECT rect;
|
---|
1102 |
|
---|
1103 | if (GetOS2UpdateRect(OS2HwndFrame,&rect))
|
---|
1104 | {
|
---|
1105 | HRGN hrgn;
|
---|
1106 | ULONG rc;
|
---|
1107 | RECT client = rectClient;
|
---|
1108 |
|
---|
1109 | //CB: bug in dc.cpp!!!
|
---|
1110 | if ((rect.left == rect.right) || (rect.bottom == rect.top)) return 0;
|
---|
1111 | mapWin32Rect(getParent() ? getParent()->getOS2WindowHandle():OSLIB_HWND_DESKTOP,OS2HwndFrame,&client);
|
---|
1112 | if ((rect.left >= client.left) && (rect.left < client.right) &&
|
---|
1113 | (rect.right >= client.left) && (rect.right < client.right) &&
|
---|
1114 | (rect.top >= client.top) && (rect.top < client.bottom) &&
|
---|
1115 | (rect.bottom >= client.top) && (rect.bottom < client.bottom))
|
---|
1116 | return 0;
|
---|
1117 | hrgn = CreateRectRgnIndirect(&rect);
|
---|
1118 | if (!hrgn) return 0;
|
---|
1119 | //CB: bug in GetDCEx with region!!!
|
---|
1120 | rc = SendInternalMessageA(WM_NCPAINT,/*hrgn*/0,0);
|
---|
1121 | //dprintf(("CB: %d %d %d %d",rect.left,rect.top,rect.bottom,rect.right));
|
---|
1122 | DeleteObject(hrgn);
|
---|
1123 | //CB: todo: check if intersection with client
|
---|
1124 |
|
---|
1125 | return rc;
|
---|
1126 | } else return 0;
|
---|
1127 | }
|
---|
1128 | //******************************************************************************
|
---|
1129 | //******************************************************************************
|
---|
1130 | ULONG Win32BaseWindow::MsgFormatFrame()
|
---|
1131 | {
|
---|
1132 | RECT window = rectWindow,client = rectClient,rect;
|
---|
1133 | WINDOWPOS wndPos;
|
---|
1134 |
|
---|
1135 | wndPos.hwnd = Win32Hwnd;
|
---|
1136 | wndPos.hwndInsertAfter = 0;
|
---|
1137 | rect = rectWindow;
|
---|
1138 | if (getParent()) mapWin32Rect(OSLIB_HWND_DESKTOP,getParent()->getOS2WindowHandle(),&rect);
|
---|
1139 | wndPos.x = rect.left;
|
---|
1140 | wndPos.y = rect.top;
|
---|
1141 | wndPos.cx = rect.right-rect.left;
|
---|
1142 | wndPos.cy = rect.bottom-rect.top;
|
---|
1143 | wndPos.flags = 0; //dummy
|
---|
1144 |
|
---|
1145 | return SendNCCalcSize(TRUE,&window,&window,&client,&wndPos,&rectClient);
|
---|
1146 | }
|
---|
1147 | //******************************************************************************
|
---|
1148 | //******************************************************************************
|
---|
1149 | ULONG Win32BaseWindow::MsgSetText(LPSTR lpsz, LONG cch)
|
---|
1150 | {
|
---|
1151 | return SendInternalMessageA(WM_SETTEXT, 0, (LPARAM)lpsz);
|
---|
1152 | }
|
---|
1153 | //******************************************************************************
|
---|
1154 | //******************************************************************************
|
---|
1155 | ULONG Win32BaseWindow::MsgGetTextLength()
|
---|
1156 | {
|
---|
1157 | return SendInternalMessageA(WM_GETTEXTLENGTH, 0, 0);
|
---|
1158 | }
|
---|
1159 | //******************************************************************************
|
---|
1160 | //******************************************************************************
|
---|
1161 | char *Win32BaseWindow::MsgGetText()
|
---|
1162 | {
|
---|
1163 | SendInternalMessageA(WM_GETTEXT, wndNameLength, (LPARAM)windowNameA);
|
---|
1164 | return windowNameA;
|
---|
1165 | }
|
---|
1166 | //******************************************************************************
|
---|
1167 | //******************************************************************************
|
---|
1168 | ULONG Win32BaseWindow::MsgContextMenu(ULONG x,ULONG y)
|
---|
1169 | {
|
---|
1170 | return SendInternalMessageA(WM_CONTEXTMENU,Win32Hwnd,MAKELPARAM(x,y));
|
---|
1171 | }
|
---|
1172 | //******************************************************************************
|
---|
1173 | //******************************************************************************
|
---|
1174 | BOOL Win32BaseWindow::isMDIClient()
|
---|
1175 | {
|
---|
1176 | return FALSE;
|
---|
1177 | }
|
---|
1178 | //******************************************************************************
|
---|
1179 | //******************************************************************************
|
---|
1180 | BOOL Win32BaseWindow::isMDIChild()
|
---|
1181 | {
|
---|
1182 | return FALSE;
|
---|
1183 | }
|
---|
1184 | //******************************************************************************
|
---|
1185 | //TODO: Not complete
|
---|
1186 | //******************************************************************************
|
---|
1187 | BOOL Win32BaseWindow::isFrameWindow()
|
---|
1188 | {
|
---|
1189 | // if(isMDIChild() || IsDialog() || (getParent() == NULL || getParent() == windowDesktop) && ((dwStyle & WS_CAPTION) == WS_CAPTION))
|
---|
1190 | if((dwStyle & WS_CAPTION) == WS_CAPTION || dwStyle & (WS_VSCROLL|WS_HSCROLL))
|
---|
1191 | return TRUE;
|
---|
1192 |
|
---|
1193 | return FALSE;
|
---|
1194 | }
|
---|
1195 | //******************************************************************************
|
---|
1196 | //******************************************************************************
|
---|
1197 | SCROLLBAR_INFO *Win32BaseWindow::getScrollInfo(int nBar)
|
---|
1198 | {
|
---|
1199 | switch(nBar)
|
---|
1200 | {
|
---|
1201 | case SB_HORZ:
|
---|
1202 | if (!horzScrollInfo)
|
---|
1203 | {
|
---|
1204 | horzScrollInfo = (SCROLLBAR_INFO*)malloc(sizeof(SCROLLBAR_INFO));
|
---|
1205 | horzScrollInfo->MinVal = horzScrollInfo->CurVal = horzScrollInfo->Page = 0;
|
---|
1206 | horzScrollInfo->MaxVal = 100;
|
---|
1207 | horzScrollInfo->flags = ESB_ENABLE_BOTH;
|
---|
1208 | }
|
---|
1209 | return horzScrollInfo;
|
---|
1210 |
|
---|
1211 | case SB_VERT:
|
---|
1212 | if (!vertScrollInfo)
|
---|
1213 | {
|
---|
1214 | vertScrollInfo = (SCROLLBAR_INFO*)malloc(sizeof(SCROLLBAR_INFO));
|
---|
1215 | vertScrollInfo->MinVal = vertScrollInfo->CurVal = vertScrollInfo->Page = 0;
|
---|
1216 | vertScrollInfo->MaxVal = 100;
|
---|
1217 | vertScrollInfo->flags = ESB_ENABLE_BOTH;
|
---|
1218 | }
|
---|
1219 | return vertScrollInfo;
|
---|
1220 | }
|
---|
1221 |
|
---|
1222 | return NULL;
|
---|
1223 | }
|
---|
1224 | //******************************************************************************
|
---|
1225 | //******************************************************************************
|
---|
1226 | LONG Win32BaseWindow::HandleNCActivate(WPARAM wParam)
|
---|
1227 | {
|
---|
1228 | WORD wStateChange;
|
---|
1229 |
|
---|
1230 | if( wParam ) wStateChange = !(flags & WIN_NCACTIVATED);
|
---|
1231 | else wStateChange = flags & WIN_NCACTIVATED;
|
---|
1232 |
|
---|
1233 | if( wStateChange )
|
---|
1234 | {
|
---|
1235 | if (wParam) flags |= WIN_NCACTIVATED;
|
---|
1236 | else flags &= ~WIN_NCACTIVATED;
|
---|
1237 |
|
---|
1238 | if(!(dwStyle & WS_MINIMIZE))
|
---|
1239 | DoNCPaint((HRGN)1,FALSE);
|
---|
1240 | }
|
---|
1241 |
|
---|
1242 | return TRUE;
|
---|
1243 | }
|
---|
1244 | //******************************************************************************
|
---|
1245 | //******************************************************************************
|
---|
1246 | VOID Win32BaseWindow::TrackMinMaxBox(WORD wParam)
|
---|
1247 | {
|
---|
1248 | MSG msg;
|
---|
1249 | HDC hdc;
|
---|
1250 | BOOL pressed = TRUE;
|
---|
1251 | UINT state;
|
---|
1252 |
|
---|
1253 | if (wParam == HTMINBUTTON)
|
---|
1254 | {
|
---|
1255 | /* If the style is not present, do nothing */
|
---|
1256 | if (!(dwStyle & WS_MINIMIZEBOX))
|
---|
1257 | return;
|
---|
1258 | /* Check if the sysmenu item for minimize is there */
|
---|
1259 | #if 0 //CB: todo
|
---|
1260 | state = GetMenuState(hSysMenu,SC_MINIMIZE,MF_BYCOMMAND);
|
---|
1261 | #endif
|
---|
1262 | } else
|
---|
1263 | {
|
---|
1264 | /* If the style is not present, do nothing */
|
---|
1265 | if (!(dwStyle & WS_MAXIMIZEBOX))
|
---|
1266 | return;
|
---|
1267 | /* Check if the sysmenu item for maximize is there */
|
---|
1268 | #if 0 //CB: todo
|
---|
1269 | state = GetMenuState(hSysMenu, SC_MAXIMIZE, MF_BYCOMMAND);
|
---|
1270 | #endif
|
---|
1271 | }
|
---|
1272 | SetCapture(Win32Hwnd);
|
---|
1273 | hdc = GetWindowDC(Win32Hwnd);
|
---|
1274 | if (wParam == HTMINBUTTON)
|
---|
1275 | DrawMinButton(hdc,TRUE,FALSE);
|
---|
1276 | else
|
---|
1277 | DrawMaxButton(hdc,TRUE,FALSE);
|
---|
1278 | do
|
---|
1279 | {
|
---|
1280 | BOOL oldstate = pressed;
|
---|
1281 |
|
---|
1282 | GetMessageA(&msg,Win32Hwnd,0,0);
|
---|
1283 | pressed = (HandleNCHitTest(msg.pt) == wParam);
|
---|
1284 | if (pressed != oldstate)
|
---|
1285 | {
|
---|
1286 | if (wParam == HTMINBUTTON)
|
---|
1287 | DrawMinButton(hdc,pressed,FALSE);
|
---|
1288 | else
|
---|
1289 | DrawMaxButton(hdc,pressed,FALSE);
|
---|
1290 | }
|
---|
1291 | } while (msg.message != WM_LBUTTONUP);
|
---|
1292 | if (wParam == HTMINBUTTON)
|
---|
1293 | DrawMinButton(hdc,FALSE,FALSE);
|
---|
1294 | else
|
---|
1295 | DrawMaxButton(hdc,FALSE,FALSE);
|
---|
1296 | ReleaseCapture();
|
---|
1297 | ReleaseDC(Win32Hwnd,hdc);
|
---|
1298 | /* If the item minimize or maximize of the sysmenu are not there */
|
---|
1299 | /* or if the style is not present, do nothing */
|
---|
1300 | if ((!pressed) || (state == 0xFFFFFFFF))
|
---|
1301 | return;
|
---|
1302 | if (wParam == HTMINBUTTON)
|
---|
1303 | SendInternalMessageA(WM_SYSCOMMAND,SC_MINIMIZE,*(LPARAM*)&msg.pt);
|
---|
1304 | else
|
---|
1305 | SendInternalMessageA(WM_SYSCOMMAND,IsZoomed(Win32Hwnd) ? SC_RESTORE:SC_MAXIMIZE,*(LPARAM*)&msg.pt);
|
---|
1306 | }
|
---|
1307 | //******************************************************************************
|
---|
1308 | //******************************************************************************
|
---|
1309 | VOID Win32BaseWindow::TrackCloseButton(WORD wParam)
|
---|
1310 | {
|
---|
1311 | MSG msg;
|
---|
1312 | HDC hdc;
|
---|
1313 | BOOL pressed = TRUE;
|
---|
1314 | UINT state;
|
---|
1315 |
|
---|
1316 | #if 0 //CB: todo
|
---|
1317 | if (hSysMenu == 0)
|
---|
1318 | return;
|
---|
1319 | state = GetMenuState(hSysMenu, SC_CLOSE, MF_BYCOMMAND);
|
---|
1320 | #else
|
---|
1321 | state = 0;
|
---|
1322 | #endif
|
---|
1323 | /* If the item close of the sysmenu is disabled or not there do nothing */
|
---|
1324 | if((state & MF_DISABLED) || (state & MF_GRAYED) || (state == 0xFFFFFFFF))
|
---|
1325 | return;
|
---|
1326 | hdc = GetWindowDC(Win32Hwnd);
|
---|
1327 | SetCapture(Win32Hwnd);
|
---|
1328 | DrawCloseButton(hdc,TRUE,FALSE);
|
---|
1329 | do
|
---|
1330 | {
|
---|
1331 | BOOL oldstate = pressed;
|
---|
1332 |
|
---|
1333 | GetMessageA(&msg,Win32Hwnd,0,0);
|
---|
1334 | pressed = (HandleNCHitTest(msg.pt) == wParam);
|
---|
1335 | if (pressed != oldstate)
|
---|
1336 | DrawCloseButton(hdc, pressed, FALSE);
|
---|
1337 | } while (msg.message != WM_LBUTTONUP);
|
---|
1338 | DrawCloseButton(hdc,FALSE,FALSE);
|
---|
1339 | ReleaseCapture();
|
---|
1340 | ReleaseDC(Win32Hwnd,hdc);
|
---|
1341 | if (!pressed) return;
|
---|
1342 | SendInternalMessageA(WM_SYSCOMMAND,SC_CLOSE,*(LPARAM*)&msg.pt);
|
---|
1343 | }
|
---|
1344 | //******************************************************************************
|
---|
1345 | //******************************************************************************
|
---|
1346 | VOID Win32BaseWindow::TrackScrollBar(WPARAM wParam,POINT pt)
|
---|
1347 | {
|
---|
1348 | INT scrollbar;
|
---|
1349 | MSG msg;
|
---|
1350 |
|
---|
1351 | if ((wParam & 0xfff0) == SC_HSCROLL)
|
---|
1352 | {
|
---|
1353 | if ((wParam & 0x0f) != HTHSCROLL) return;
|
---|
1354 | scrollbar = SB_HORZ;
|
---|
1355 | } else /* SC_VSCROLL */
|
---|
1356 | {
|
---|
1357 | if ((wParam & 0x0f) != HTVSCROLL) return;
|
---|
1358 | scrollbar = SB_VERT;
|
---|
1359 | }
|
---|
1360 |
|
---|
1361 | pt.x -= rectWindow.left;
|
---|
1362 | pt.y -= rectWindow.top;
|
---|
1363 | SCROLL_HandleScrollEvent(Win32Hwnd,0,MAKELONG(pt.x,pt.y),scrollbar,WM_LBUTTONDOWN);
|
---|
1364 | if (GetCapture() != Win32Hwnd) return;
|
---|
1365 | do
|
---|
1366 | {
|
---|
1367 | GetMessageA(&msg,Win32Hwnd,0,0);
|
---|
1368 | switch(msg.message)
|
---|
1369 | {
|
---|
1370 | case WM_LBUTTONUP:
|
---|
1371 | case WM_MOUSEMOVE:
|
---|
1372 | pt.x = msg.pt.x-rectWindow.left;
|
---|
1373 | pt.y = msg.pt.y-rectWindow.top;
|
---|
1374 | msg.lParam = MAKELONG(pt.x,pt.y);
|
---|
1375 | case WM_SYSTIMER:
|
---|
1376 | SCROLL_HandleScrollEvent(Win32Hwnd,msg.wParam,msg.lParam,scrollbar,msg.message);
|
---|
1377 | break;
|
---|
1378 |
|
---|
1379 | default:
|
---|
1380 | TranslateMessage(&msg);
|
---|
1381 | DispatchMessageA(&msg);
|
---|
1382 | break;
|
---|
1383 | }
|
---|
1384 | if (!IsWindow())
|
---|
1385 | {
|
---|
1386 | ReleaseCapture();
|
---|
1387 | break;
|
---|
1388 | }
|
---|
1389 | } while (msg.message != WM_LBUTTONUP);
|
---|
1390 | }
|
---|
1391 | //******************************************************************************
|
---|
1392 | //******************************************************************************
|
---|
1393 | LONG Win32BaseWindow::HandleNCLButtonDown(WPARAM wParam,LPARAM lParam)
|
---|
1394 | {
|
---|
1395 | switch(wParam) /* Hit test */
|
---|
1396 | {
|
---|
1397 | case HTCAPTION:
|
---|
1398 | SetActiveWindow();
|
---|
1399 | if (GetActiveWindow() == Win32Hwnd)
|
---|
1400 | SendInternalMessageA(WM_SYSCOMMAND,SC_MOVE+HTCAPTION,lParam);
|
---|
1401 | break;
|
---|
1402 |
|
---|
1403 | case HTSYSMENU:
|
---|
1404 | if(dwStyle & WS_SYSMENU )
|
---|
1405 | {
|
---|
1406 | if( !(dwStyle & WS_MINIMIZE) )
|
---|
1407 | {
|
---|
1408 | HDC hDC = GetWindowDC(Win32Hwnd);
|
---|
1409 | DrawSysButton(hDC,TRUE);
|
---|
1410 | ReleaseDC(Win32Hwnd,hDC);
|
---|
1411 | }
|
---|
1412 | SendInternalMessageA(WM_SYSCOMMAND,SC_MOUSEMENU+HTSYSMENU,lParam);
|
---|
1413 | }
|
---|
1414 | break;
|
---|
1415 |
|
---|
1416 | case HTMENU:
|
---|
1417 | SendInternalMessageA(WM_SYSCOMMAND,SC_MOUSEMENU,lParam);
|
---|
1418 | break;
|
---|
1419 |
|
---|
1420 | case HTHSCROLL:
|
---|
1421 | SendInternalMessageA(WM_SYSCOMMAND,SC_HSCROLL+HTHSCROLL,lParam);
|
---|
1422 | break;
|
---|
1423 |
|
---|
1424 | case HTVSCROLL:
|
---|
1425 | SendInternalMessageA(WM_SYSCOMMAND,SC_VSCROLL+HTVSCROLL,lParam);
|
---|
1426 | break;
|
---|
1427 |
|
---|
1428 | case HTMINBUTTON:
|
---|
1429 | case HTMAXBUTTON:
|
---|
1430 | TrackMinMaxBox(wParam);
|
---|
1431 | break;
|
---|
1432 |
|
---|
1433 | case HTCLOSE:
|
---|
1434 | TrackCloseButton(wParam);
|
---|
1435 | break;
|
---|
1436 |
|
---|
1437 | case HTLEFT:
|
---|
1438 | case HTRIGHT:
|
---|
1439 | case HTTOP:
|
---|
1440 | case HTTOPLEFT:
|
---|
1441 | case HTTOPRIGHT:
|
---|
1442 | case HTBOTTOM:
|
---|
1443 | case HTBOTTOMLEFT:
|
---|
1444 | case HTBOTTOMRIGHT:
|
---|
1445 | /* make sure hittest fits into 0xf and doesn't overlap with HTSYSMENU */
|
---|
1446 | SendInternalMessageA(WM_SYSCOMMAND,SC_SIZE+wParam-2,lParam);
|
---|
1447 | break;
|
---|
1448 | case HTBORDER:
|
---|
1449 | break;
|
---|
1450 | }
|
---|
1451 |
|
---|
1452 | return 0;
|
---|
1453 | }
|
---|
1454 | //******************************************************************************
|
---|
1455 | //******************************************************************************
|
---|
1456 | BOOL Win32BaseWindow::WindowNeedsWMBorder()
|
---|
1457 | {
|
---|
1458 | if (!(dwStyle & WS_CHILD) &&
|
---|
1459 | //Options.managed && //CB: to check
|
---|
1460 | !(dwExStyle & WS_EX_TOOLWINDOW) &&
|
---|
1461 | ( ((dwStyle & WS_CAPTION) == WS_CAPTION) ||
|
---|
1462 | (dwStyle & WS_THICKFRAME)))
|
---|
1463 | return TRUE;
|
---|
1464 | if (dwExStyle & WS_EX_TRAYWINDOW)
|
---|
1465 | return TRUE;
|
---|
1466 | return FALSE;
|
---|
1467 | }
|
---|
1468 | //******************************************************************************
|
---|
1469 | //******************************************************************************
|
---|
1470 | VOID Win32BaseWindow::AdjustRectOuter(LPRECT rect,BOOL menu)
|
---|
1471 | {
|
---|
1472 | if(dwStyle & WS_ICONIC) return;
|
---|
1473 |
|
---|
1474 | /* Decide if the window will be managed (see CreateWindowEx) */
|
---|
1475 | //if (!WindowNeedsWMBorder()) //CB: check Options.managed
|
---|
1476 | {
|
---|
1477 | if (HAS_THICKFRAME(dwStyle,dwExStyle ))
|
---|
1478 | InflateRect( rect, GetSystemMetrics(SM_CXFRAME), GetSystemMetrics(SM_CYFRAME) );
|
---|
1479 | else
|
---|
1480 | if (HAS_DLGFRAME( dwStyle, dwExStyle ))
|
---|
1481 | InflateRect(rect, GetSystemMetrics(SM_CXDLGFRAME), GetSystemMetrics(SM_CYDLGFRAME) );
|
---|
1482 | else
|
---|
1483 | if (HAS_THINFRAME( dwStyle ))
|
---|
1484 | InflateRect( rect, GetSystemMetrics(SM_CXBORDER), GetSystemMetrics(SM_CYBORDER));
|
---|
1485 |
|
---|
1486 | if ((dwStyle & WS_CAPTION) == WS_CAPTION)
|
---|
1487 | {
|
---|
1488 | if (dwExStyle & WS_EX_TOOLWINDOW)
|
---|
1489 | rect->top -= GetSystemMetrics(SM_CYSMCAPTION);
|
---|
1490 | else
|
---|
1491 | rect->top -= GetSystemMetrics(SM_CYCAPTION);
|
---|
1492 | }
|
---|
1493 | }
|
---|
1494 |
|
---|
1495 | if (menu)
|
---|
1496 | rect->top -= GetSystemMetrics(SM_CYMENU);
|
---|
1497 | }
|
---|
1498 | //******************************************************************************
|
---|
1499 | //******************************************************************************
|
---|
1500 | VOID Win32BaseWindow::AdjustRectInner(LPRECT rect)
|
---|
1501 | {
|
---|
1502 | if(dwStyle & WS_ICONIC) return;
|
---|
1503 |
|
---|
1504 | if (dwExStyle & WS_EX_CLIENTEDGE)
|
---|
1505 | InflateRect (rect, GetSystemMetrics(SM_CXEDGE), GetSystemMetrics(SM_CYEDGE));
|
---|
1506 |
|
---|
1507 | if (dwExStyle & WS_EX_STATICEDGE)
|
---|
1508 | InflateRect (rect, GetSystemMetrics(SM_CXBORDER), GetSystemMetrics(SM_CYBORDER));
|
---|
1509 |
|
---|
1510 | if (dwStyle & WS_VSCROLL) rect->right += GetSystemMetrics(SM_CXVSCROLL);
|
---|
1511 | if (dwStyle & WS_HSCROLL) rect->bottom += GetSystemMetrics(SM_CYHSCROLL);
|
---|
1512 | }
|
---|
1513 | //******************************************************************************
|
---|
1514 | //******************************************************************************
|
---|
1515 | LONG Win32BaseWindow::HandleNCCalcSize(BOOL calcValidRects,RECT *winRect)
|
---|
1516 | {
|
---|
1517 | RECT tmpRect = { 0, 0, 0, 0 },*clientRect;
|
---|
1518 | LONG result = WVR_ALIGNTOP | WVR_ALIGNLEFT;
|
---|
1519 | UINT style;
|
---|
1520 |
|
---|
1521 | if (!calcValidRects) return 0;
|
---|
1522 |
|
---|
1523 | style = (UINT) GetClassLongA(Win32Hwnd,GCL_STYLE);
|
---|
1524 |
|
---|
1525 | if (style & CS_VREDRAW) result |= WVR_VREDRAW;
|
---|
1526 | if (style & CS_HREDRAW) result |= WVR_HREDRAW;
|
---|
1527 |
|
---|
1528 | clientRect = &((NCCALCSIZE_PARAMS*)winRect)->rgrc[2];
|
---|
1529 | *clientRect = rectWindow;
|
---|
1530 | if (getParent()) mapWin32Rect(OSLIB_HWND_DESKTOP,getParent()->getOS2WindowHandle(),clientRect);
|
---|
1531 |
|
---|
1532 | if(!(dwStyle & WS_MINIMIZE))
|
---|
1533 | {
|
---|
1534 | AdjustRectOuter(&tmpRect,FALSE); //CB: todo: menu
|
---|
1535 |
|
---|
1536 | clientRect->left -= tmpRect.left;
|
---|
1537 | clientRect->top -= tmpRect.top;
|
---|
1538 | clientRect->right -= tmpRect.right;
|
---|
1539 | clientRect->bottom -= tmpRect.bottom;
|
---|
1540 |
|
---|
1541 | if (HAS_MENU(this))
|
---|
1542 | {
|
---|
1543 | #if 0 //CB: todo
|
---|
1544 | winRect->top +=
|
---|
1545 | MENU_GetMenuBarHeight(Win32Hwnd,
|
---|
1546 | winRect->right - winRect->left,
|
---|
1547 | -tmpRect.left, -tmpRect.top ) + 1;
|
---|
1548 | #endif
|
---|
1549 | }
|
---|
1550 |
|
---|
1551 | SetRect (&tmpRect, 0, 0, 0, 0);
|
---|
1552 | AdjustRectInner(&tmpRect);
|
---|
1553 | clientRect->left -= tmpRect.left;
|
---|
1554 | clientRect->top -= tmpRect.top;
|
---|
1555 | clientRect->right -= tmpRect.right;
|
---|
1556 | clientRect->bottom -= tmpRect.bottom;
|
---|
1557 | }
|
---|
1558 |
|
---|
1559 | return result;
|
---|
1560 | }
|
---|
1561 | //******************************************************************************
|
---|
1562 | //******************************************************************************
|
---|
1563 | LONG Win32BaseWindow::HandleNCHitTest(POINT pt)
|
---|
1564 | {
|
---|
1565 | RECT rect = rectWindow;
|
---|
1566 |
|
---|
1567 | if (!PtInRect(&rect,pt)) return HTNOWHERE;
|
---|
1568 |
|
---|
1569 | if (dwStyle & WS_MINIMIZE) return HTCAPTION;
|
---|
1570 |
|
---|
1571 | if (!(flags & WIN_MANAGED))
|
---|
1572 | {
|
---|
1573 | /* Check borders */
|
---|
1574 | if (HAS_THICKFRAME(dwStyle,dwExStyle))
|
---|
1575 | {
|
---|
1576 | InflateRect(&rect,-GetSystemMetrics(SM_CXFRAME),-GetSystemMetrics(SM_CYFRAME));
|
---|
1577 | if (!PtInRect(&rect,pt))
|
---|
1578 | {
|
---|
1579 | /* Check top sizing border */
|
---|
1580 | if (pt.y < rect.top)
|
---|
1581 | {
|
---|
1582 | if (pt.x < rect.left+GetSystemMetrics(SM_CXSIZE)) return HTTOPLEFT;
|
---|
1583 | if (pt.x >= rect.right-GetSystemMetrics(SM_CXSIZE)) return HTTOPRIGHT;
|
---|
1584 | return HTTOP;
|
---|
1585 | }
|
---|
1586 | /* Check bottom sizing border */
|
---|
1587 | if (pt.y >= rect.bottom)
|
---|
1588 | {
|
---|
1589 | if (pt.x < rect.left+GetSystemMetrics(SM_CXSIZE)) return HTBOTTOMLEFT;
|
---|
1590 | if (pt.x >= rect.right-GetSystemMetrics(SM_CXSIZE)) return HTBOTTOMRIGHT;
|
---|
1591 | return HTBOTTOM;
|
---|
1592 | }
|
---|
1593 | /* Check left sizing border */
|
---|
1594 | if (pt.x < rect.left)
|
---|
1595 | {
|
---|
1596 | if (pt.y < rect.top+GetSystemMetrics(SM_CYSIZE)) return HTTOPLEFT;
|
---|
1597 | if (pt.y >= rect.bottom-GetSystemMetrics(SM_CYSIZE)) return HTBOTTOMLEFT;
|
---|
1598 | return HTLEFT;
|
---|
1599 | }
|
---|
1600 | /* Check right sizing border */
|
---|
1601 | if (pt.x >= rect.right)
|
---|
1602 | {
|
---|
1603 | if (pt.y < rect.top+GetSystemMetrics(SM_CYSIZE)) return HTTOPRIGHT;
|
---|
1604 | if (pt.y >= rect.bottom-GetSystemMetrics(SM_CYSIZE)) return HTBOTTOMRIGHT;
|
---|
1605 | return HTRIGHT;
|
---|
1606 | }
|
---|
1607 | }
|
---|
1608 | } else /* No thick frame */
|
---|
1609 | {
|
---|
1610 | if (HAS_DLGFRAME(dwStyle,dwExStyle))
|
---|
1611 | InflateRect(&rect, -GetSystemMetrics(SM_CXDLGFRAME), -GetSystemMetrics(SM_CYDLGFRAME));
|
---|
1612 | else if (HAS_THINFRAME(dwStyle ))
|
---|
1613 | InflateRect(&rect, -GetSystemMetrics(SM_CXBORDER), -GetSystemMetrics(SM_CYBORDER));
|
---|
1614 | if (!PtInRect( &rect, pt )) return HTBORDER;
|
---|
1615 | }
|
---|
1616 |
|
---|
1617 | /* Check caption */
|
---|
1618 |
|
---|
1619 | if ((dwStyle & WS_CAPTION) == WS_CAPTION)
|
---|
1620 | {
|
---|
1621 | if (dwExStyle & WS_EX_TOOLWINDOW)
|
---|
1622 | rect.top += GetSystemMetrics(SM_CYSMCAPTION)-1;
|
---|
1623 | else
|
---|
1624 | rect.top += GetSystemMetrics(SM_CYCAPTION)-1;
|
---|
1625 | if (!PtInRect(&rect,pt))
|
---|
1626 | {
|
---|
1627 | /* Check system menu */
|
---|
1628 | if(dwStyle & WS_SYSMENU)
|
---|
1629 | {
|
---|
1630 | /* Check if there is an user icon */
|
---|
1631 | HICON hIcon = (HICON) GetClassLongA(Win32Hwnd, GCL_HICONSM);
|
---|
1632 | if(!hIcon) hIcon = (HICON) GetClassLongA(Win32Hwnd, GCL_HICON);
|
---|
1633 |
|
---|
1634 | /* If there is an icon associated with the window OR */
|
---|
1635 | /* If there is no hIcon specified and this is not a modal dialog, */
|
---|
1636 | /* there is a system menu icon. */
|
---|
1637 | if((hIcon != 0) || (!(dwStyle & DS_MODALFRAME)))
|
---|
1638 | rect.left += GetSystemMetrics(SM_CYCAPTION) - 1;
|
---|
1639 | }
|
---|
1640 | if (pt.x < rect.left) return HTSYSMENU;
|
---|
1641 |
|
---|
1642 | /* Check close button */
|
---|
1643 | if (dwStyle & WS_SYSMENU)
|
---|
1644 | rect.right -= GetSystemMetrics(SM_CYCAPTION) - 1;
|
---|
1645 | if (pt.x > rect.right) return HTCLOSE;
|
---|
1646 |
|
---|
1647 | /* Check maximize box */
|
---|
1648 | /* In win95 there is automatically a Maximize button when there is a minimize one*/
|
---|
1649 | if ((dwStyle & WS_MAXIMIZEBOX)|| (dwStyle & WS_MINIMIZEBOX))
|
---|
1650 | rect.right -= GetSystemMetrics(SM_CXSIZE) + 1;
|
---|
1651 | if (pt.x > rect.right) return HTMAXBUTTON;
|
---|
1652 |
|
---|
1653 | /* Check minimize box */
|
---|
1654 | /* In win95 there is automatically a Maximize button when there is a Maximize one*/
|
---|
1655 | if ((dwStyle & WS_MINIMIZEBOX)||(dwStyle & WS_MAXIMIZEBOX))
|
---|
1656 | rect.right -= GetSystemMetrics(SM_CXSIZE) + 1;
|
---|
1657 |
|
---|
1658 | if (pt.x > rect.right) return HTMINBUTTON;
|
---|
1659 | return HTCAPTION;
|
---|
1660 | }
|
---|
1661 | }
|
---|
1662 | }
|
---|
1663 |
|
---|
1664 | /* Check client area */
|
---|
1665 |
|
---|
1666 | ScreenToClient(Win32Hwnd,&pt);
|
---|
1667 | getClientRect(&rect);
|
---|
1668 | if (PtInRect(&rect,pt)) return HTCLIENT;
|
---|
1669 |
|
---|
1670 | /* Check vertical scroll bar */
|
---|
1671 |
|
---|
1672 | if (dwStyle & WS_VSCROLL)
|
---|
1673 | {
|
---|
1674 | rect.right += GetSystemMetrics(SM_CXVSCROLL);
|
---|
1675 | if (PtInRect( &rect, pt )) return HTVSCROLL;
|
---|
1676 | }
|
---|
1677 |
|
---|
1678 | /* Check horizontal scroll bar */
|
---|
1679 |
|
---|
1680 | if (dwStyle & WS_HSCROLL)
|
---|
1681 | {
|
---|
1682 | rect.bottom += GetSystemMetrics(SM_CYHSCROLL);
|
---|
1683 | if (PtInRect( &rect, pt ))
|
---|
1684 | {
|
---|
1685 | /* Check size box */
|
---|
1686 | if ((dwStyle & WS_VSCROLL) &&
|
---|
1687 | (pt.x >= rect.right - GetSystemMetrics(SM_CXVSCROLL)))
|
---|
1688 | return (dwStyle & WS_CHILD) ? HTSIZE:HTBOTTOMRIGHT;
|
---|
1689 | return HTHSCROLL;
|
---|
1690 | }
|
---|
1691 | }
|
---|
1692 |
|
---|
1693 | /* Check menu bar */
|
---|
1694 |
|
---|
1695 | if (HAS_MENU(this))
|
---|
1696 | {
|
---|
1697 | if ((pt.y < 0) && (pt.x >= 0) && (pt.x < rect.right))
|
---|
1698 | return HTMENU;
|
---|
1699 | }
|
---|
1700 |
|
---|
1701 | /* Should never get here */
|
---|
1702 | return HTERROR;
|
---|
1703 | }
|
---|
1704 |
|
---|
1705 | //******************************************************************************
|
---|
1706 | //******************************************************************************
|
---|
1707 | VOID Win32BaseWindow::GetInsideRect(RECT *rect)
|
---|
1708 | {
|
---|
1709 | rect->top = rect->left = 0;
|
---|
1710 | rect->right = rectWindow.right - rectWindow.left;
|
---|
1711 | rect->bottom = rectWindow.bottom - rectWindow.top;
|
---|
1712 |
|
---|
1713 | if ((dwStyle & WS_ICONIC) || (flags & WIN_MANAGED)) return;
|
---|
1714 |
|
---|
1715 | /* Remove frame from rectangle */
|
---|
1716 | if (HAS_THICKFRAME(dwStyle,dwExStyle))
|
---|
1717 | {
|
---|
1718 | InflateRect( rect, -GetSystemMetrics(SM_CXSIZEFRAME), -GetSystemMetrics(SM_CYSIZEFRAME) );
|
---|
1719 | }
|
---|
1720 | else if (HAS_DLGFRAME(dwStyle,dwExStyle ))
|
---|
1721 | {
|
---|
1722 | InflateRect( rect, -GetSystemMetrics(SM_CXFIXEDFRAME), -GetSystemMetrics(SM_CYFIXEDFRAME));
|
---|
1723 | }
|
---|
1724 | else if (HAS_THINFRAME(dwStyle))
|
---|
1725 | {
|
---|
1726 | InflateRect( rect, -GetSystemMetrics(SM_CXBORDER), -GetSystemMetrics(SM_CYBORDER) );
|
---|
1727 | }
|
---|
1728 |
|
---|
1729 | /* We have additional border information if the window
|
---|
1730 | * is a child (but not an MDI child) */
|
---|
1731 | if ( (dwStyle & WS_CHILD) &&
|
---|
1732 | ( (dwExStyle & WS_EX_MDICHILD) == 0 ) )
|
---|
1733 | {
|
---|
1734 | if (dwExStyle & WS_EX_CLIENTEDGE)
|
---|
1735 | InflateRect (rect, -GetSystemMetrics(SM_CXEDGE), -GetSystemMetrics(SM_CYEDGE));
|
---|
1736 |
|
---|
1737 | if (dwExStyle & WS_EX_STATICEDGE)
|
---|
1738 | InflateRect (rect, -GetSystemMetrics(SM_CXBORDER), -GetSystemMetrics(SM_CYBORDER));
|
---|
1739 | }
|
---|
1740 | }
|
---|
1741 | //******************************************************************************
|
---|
1742 | //******************************************************************************
|
---|
1743 | VOID Win32BaseWindow::DrawFrame(HDC hdc,RECT *rect,BOOL dlgFrame,BOOL active)
|
---|
1744 | {
|
---|
1745 | INT width, height;
|
---|
1746 | HBRUSH oldBrush;
|
---|
1747 |
|
---|
1748 | if (dlgFrame)
|
---|
1749 | {
|
---|
1750 | width = GetSystemMetrics(SM_CXDLGFRAME) - GetSystemMetrics(SM_CXEDGE);
|
---|
1751 | height = GetSystemMetrics(SM_CYDLGFRAME) - GetSystemMetrics(SM_CYEDGE);
|
---|
1752 | } else
|
---|
1753 | {
|
---|
1754 | width = GetSystemMetrics(SM_CXFRAME) - GetSystemMetrics(SM_CXEDGE);
|
---|
1755 | height = GetSystemMetrics(SM_CYFRAME) - GetSystemMetrics(SM_CYEDGE);
|
---|
1756 | }
|
---|
1757 |
|
---|
1758 | oldBrush = SelectObject(hdc,GetSysColorBrush(active ? COLOR_ACTIVEBORDER:COLOR_INACTIVEBORDER));
|
---|
1759 |
|
---|
1760 | /* Draw frame */
|
---|
1761 |
|
---|
1762 | PatBlt(hdc,rect->left,rect->top,rect->right-rect->left,height,PATCOPY);
|
---|
1763 | PatBlt(hdc,rect->left,rect->top,width,rect->bottom-rect->top,PATCOPY);
|
---|
1764 | PatBlt(hdc,rect->left,rect->bottom-1,rect->right-rect->left,-height,PATCOPY);
|
---|
1765 | PatBlt(hdc,rect->right-1,rect->top,-width,rect->bottom-rect->top,PATCOPY);
|
---|
1766 | SelectObject(hdc,oldBrush);
|
---|
1767 |
|
---|
1768 | InflateRect(rect,-width,-height);
|
---|
1769 | }
|
---|
1770 | //******************************************************************************
|
---|
1771 | //******************************************************************************
|
---|
1772 | BOOL Win32BaseWindow::DrawSysButton(HDC hdc,BOOL down)
|
---|
1773 | {
|
---|
1774 | if(!(flags & WIN_MANAGED))
|
---|
1775 | {
|
---|
1776 | HICON hIcon;
|
---|
1777 | RECT rect;
|
---|
1778 |
|
---|
1779 | GetInsideRect(&rect);
|
---|
1780 |
|
---|
1781 | hIcon = (HICON) GetClassLongA(Win32Hwnd, GCL_HICONSM);
|
---|
1782 | if(!hIcon) hIcon = (HICON) GetClassLongA(Win32Hwnd, GCL_HICON);
|
---|
1783 |
|
---|
1784 | /* If there is no hIcon specified or this is not a modal dialog, */
|
---|
1785 | /* get the default one. */
|
---|
1786 | if(hIcon == 0)
|
---|
1787 | if (!(dwStyle & DS_MODALFRAME))
|
---|
1788 | hIcon = LoadImageA(0, MAKEINTRESOURCEA(OIC_ODINICON), IMAGE_ICON, 0, 0, LR_DEFAULTCOLOR);
|
---|
1789 |
|
---|
1790 | if (hIcon)
|
---|
1791 | DrawIconEx (hdc, rect.left + 2, rect.top + 2, hIcon,
|
---|
1792 | GetSystemMetrics(SM_CXSMICON),
|
---|
1793 | GetSystemMetrics(SM_CYSMICON),
|
---|
1794 | 0, 0, DI_NORMAL);
|
---|
1795 |
|
---|
1796 | return (hIcon != 0);
|
---|
1797 | }
|
---|
1798 | return FALSE;
|
---|
1799 | }
|
---|
1800 | //******************************************************************************
|
---|
1801 | //******************************************************************************
|
---|
1802 | BOOL Win32BaseWindow::DrawGrayButton(HDC hdc,int x,int y)
|
---|
1803 | {
|
---|
1804 | HBITMAP hMaskBmp;
|
---|
1805 | HDC hdcMask = CreateCompatibleDC (0);
|
---|
1806 | HBRUSH hOldBrush;
|
---|
1807 | hMaskBmp = CreateBitmap (12, 10, 1, 1, lpGrayMask);
|
---|
1808 |
|
---|
1809 | if(hMaskBmp == 0)
|
---|
1810 | return FALSE;
|
---|
1811 |
|
---|
1812 | SelectObject (hdcMask, hMaskBmp);
|
---|
1813 |
|
---|
1814 | /* Draw the grayed bitmap using the mask */
|
---|
1815 | hOldBrush = SelectObject (hdc, RGB(128, 128, 128));
|
---|
1816 | BitBlt (hdc, x, y, 12, 10,
|
---|
1817 | hdcMask, 0, 0, 0xB8074A);
|
---|
1818 |
|
---|
1819 | /* Clean up */
|
---|
1820 | SelectObject (hdc, hOldBrush);
|
---|
1821 | DeleteObject(hMaskBmp);
|
---|
1822 | DeleteDC (hdcMask);
|
---|
1823 |
|
---|
1824 | return TRUE;
|
---|
1825 | }
|
---|
1826 | //******************************************************************************
|
---|
1827 | //******************************************************************************
|
---|
1828 | VOID Win32BaseWindow::DrawCloseButton(HDC hdc,BOOL down,BOOL bGrayed)
|
---|
1829 | {
|
---|
1830 | RECT rect;
|
---|
1831 | HDC hdcMem;
|
---|
1832 |
|
---|
1833 | if( !(flags & WIN_MANAGED) )
|
---|
1834 | {
|
---|
1835 | BITMAP bmp;
|
---|
1836 | HBITMAP hBmp, hOldBmp;
|
---|
1837 |
|
---|
1838 | GetInsideRect(&rect);
|
---|
1839 |
|
---|
1840 | hdcMem = CreateCompatibleDC( hdc );
|
---|
1841 | hBmp = down ? hbitmapCloseD : hbitmapClose;
|
---|
1842 | hOldBmp = SelectObject (hdcMem, hBmp);
|
---|
1843 | GetObjectA (hBmp, sizeof(BITMAP), &bmp);
|
---|
1844 |
|
---|
1845 | BitBlt (hdc, rect.right - (GetSystemMetrics(SM_CYCAPTION) + 1 + bmp.bmWidth) / 2,
|
---|
1846 | rect.top + (GetSystemMetrics(SM_CYCAPTION) - 1 - bmp.bmHeight) / 2,
|
---|
1847 | bmp.bmWidth, bmp.bmHeight, hdcMem, 0, 0, SRCCOPY);
|
---|
1848 |
|
---|
1849 | if(bGrayed)
|
---|
1850 | DrawGrayButton(hdc,rect.right - (GetSystemMetrics(SM_CYCAPTION) + 1 + bmp.bmWidth) / 2 + 2,
|
---|
1851 | rect.top + (GetSystemMetrics(SM_CYCAPTION) - 1 - bmp.bmHeight) / 2 + 2);
|
---|
1852 |
|
---|
1853 | SelectObject (hdcMem, hOldBmp);
|
---|
1854 | DeleteDC (hdcMem);
|
---|
1855 | }
|
---|
1856 | }
|
---|
1857 | //******************************************************************************
|
---|
1858 | //******************************************************************************
|
---|
1859 | VOID Win32BaseWindow::DrawMaxButton(HDC hdc,BOOL down,BOOL bGrayed)
|
---|
1860 | {
|
---|
1861 | RECT rect;
|
---|
1862 | HDC hdcMem;
|
---|
1863 |
|
---|
1864 | if( !(flags & WIN_MANAGED))
|
---|
1865 | {
|
---|
1866 | BITMAP bmp;
|
---|
1867 | HBITMAP hBmp,hOldBmp;
|
---|
1868 |
|
---|
1869 | GetInsideRect(&rect);
|
---|
1870 | hdcMem = CreateCompatibleDC( hdc );
|
---|
1871 | hBmp = IsZoomed(Win32Hwnd) ?
|
---|
1872 | (down ? hbitmapRestoreD : hbitmapRestore ) :
|
---|
1873 | (down ? hbitmapMaximizeD: hbitmapMaximize);
|
---|
1874 | hOldBmp=SelectObject( hdcMem, hBmp );
|
---|
1875 | GetObjectA (hBmp, sizeof(BITMAP), &bmp);
|
---|
1876 |
|
---|
1877 | if (dwStyle & WS_SYSMENU)
|
---|
1878 | rect.right -= GetSystemMetrics(SM_CYCAPTION) + 1;
|
---|
1879 |
|
---|
1880 | BitBlt( hdc, rect.right - (GetSystemMetrics(SM_CXSIZE) + bmp.bmWidth) / 2,
|
---|
1881 | rect.top + (GetSystemMetrics(SM_CYCAPTION) - 1 - bmp.bmHeight) / 2,
|
---|
1882 | bmp.bmWidth, bmp.bmHeight, hdcMem, 0, 0, SRCCOPY );
|
---|
1883 |
|
---|
1884 | if(bGrayed)
|
---|
1885 | DrawGrayButton(hdc, rect.right - (GetSystemMetrics(SM_CXSIZE) + bmp.bmWidth) / 2 + 2,
|
---|
1886 | rect.top + (GetSystemMetrics(SM_CYCAPTION) - 1 - bmp.bmHeight) / 2 + 2);
|
---|
1887 |
|
---|
1888 |
|
---|
1889 | SelectObject (hdcMem, hOldBmp);
|
---|
1890 | DeleteDC( hdcMem );
|
---|
1891 | }
|
---|
1892 | }
|
---|
1893 | //******************************************************************************
|
---|
1894 | //******************************************************************************
|
---|
1895 | VOID Win32BaseWindow::DrawMinButton(HDC hdc,BOOL down,BOOL bGrayed)
|
---|
1896 | {
|
---|
1897 | RECT rect;
|
---|
1898 | HDC hdcMem;
|
---|
1899 |
|
---|
1900 | if( !(flags & WIN_MANAGED))
|
---|
1901 |
|
---|
1902 | {
|
---|
1903 | BITMAP bmp;
|
---|
1904 | HBITMAP hBmp,hOldBmp;
|
---|
1905 |
|
---|
1906 | GetInsideRect(&rect);
|
---|
1907 |
|
---|
1908 | hdcMem = CreateCompatibleDC( hdc );
|
---|
1909 | hBmp = down ? hbitmapMinimizeD : hbitmapMinimize;
|
---|
1910 | hOldBmp= SelectObject( hdcMem, hBmp );
|
---|
1911 | GetObjectA (hBmp, sizeof(BITMAP), &bmp);
|
---|
1912 |
|
---|
1913 | if (dwStyle & WS_SYSMENU)
|
---|
1914 | rect.right -= GetSystemMetrics(SM_CYCAPTION) + 1;
|
---|
1915 |
|
---|
1916 | /* In win 95 there is always a Maximize box when there is a Minimize one */
|
---|
1917 | if ((dwStyle & WS_MAXIMIZEBOX) || (dwStyle & WS_MINIMIZEBOX))
|
---|
1918 | rect.right += -1 - (GetSystemMetrics(SM_CXSIZE) + bmp.bmWidth) / 2;
|
---|
1919 |
|
---|
1920 | BitBlt( hdc, rect.right - (GetSystemMetrics(SM_CXSIZE) + bmp.bmWidth) / 2,
|
---|
1921 | rect.top + (GetSystemMetrics(SM_CYCAPTION) - 1 - bmp.bmHeight) / 2,
|
---|
1922 | bmp.bmWidth, bmp.bmHeight, hdcMem, 0, 0, SRCCOPY );
|
---|
1923 |
|
---|
1924 | if(bGrayed)
|
---|
1925 | DrawGrayButton(hdc, rect.right - (GetSystemMetrics(SM_CXSIZE) + bmp.bmWidth) / 2 + 2,
|
---|
1926 | rect.top + (GetSystemMetrics(SM_CYCAPTION) - 1 - bmp.bmHeight) / 2 + 2);
|
---|
1927 |
|
---|
1928 |
|
---|
1929 | SelectObject (hdcMem, hOldBmp);
|
---|
1930 | DeleteDC( hdcMem );
|
---|
1931 | }
|
---|
1932 | }
|
---|
1933 | //******************************************************************************
|
---|
1934 | //******************************************************************************
|
---|
1935 | VOID Win32BaseWindow::DrawCaption(HDC hdc,RECT *rect,BOOL active)
|
---|
1936 | {
|
---|
1937 | RECT r = *rect;
|
---|
1938 | char buffer[256];
|
---|
1939 | HPEN hPrevPen;
|
---|
1940 | HMENU hSysMenu;
|
---|
1941 |
|
---|
1942 | if (flags & WIN_MANAGED) return;
|
---|
1943 |
|
---|
1944 | hPrevPen = SelectObject( hdc, GetSysColorPen(COLOR_3DFACE) );
|
---|
1945 | MoveToEx( hdc, r.left, r.bottom - 1, NULL );
|
---|
1946 | LineTo( hdc, r.right, r.bottom - 1 );
|
---|
1947 | SelectObject( hdc, hPrevPen );
|
---|
1948 | r.bottom--;
|
---|
1949 |
|
---|
1950 | //CB: todo:
|
---|
1951 | //COLOR_GRADIENTACTIVECAPTION
|
---|
1952 | //COLOR_GRADIENTINACTIVECAPTION
|
---|
1953 | //-> end color
|
---|
1954 |
|
---|
1955 | if (SYSCOLOR_GetUseWinColors())
|
---|
1956 | {
|
---|
1957 | COLORREF startColor = GetSysColor(active ? COLOR_ACTIVECAPTION:COLOR_INACTIVECAPTION),endColor = GetSysColor(active ? COLOR_GRADIENTACTIVECAPTION:COLOR_GRADIENTINACTIVECAPTION);
|
---|
1958 |
|
---|
1959 | if (startColor == endColor)
|
---|
1960 | FillRect(hdc,&r,GetSysColorBrush(startColor));
|
---|
1961 | else
|
---|
1962 | {
|
---|
1963 | INT rDiff = GetRValue(endColor)-GetRValue(startColor);
|
---|
1964 | INT gDiff = GetGValue(endColor)-GetGValue(startColor);
|
---|
1965 | INT bDiff = GetBValue(endColor)-GetBValue(startColor);
|
---|
1966 | INT steps = MAX(MAX(abs(rDiff),abs(gDiff)),abs(bDiff));
|
---|
1967 | INT w = r.right-r.left;
|
---|
1968 | RECT r2;
|
---|
1969 |
|
---|
1970 | if (w < steps) steps = w;
|
---|
1971 | r2.left = r2.right = r.left;
|
---|
1972 | r2.top = r.top;
|
---|
1973 | r2.bottom = r.bottom;
|
---|
1974 | for (INT x = 0;x <= steps;x++)
|
---|
1975 | {
|
---|
1976 | COLORREF color = RGB(GetRValue(startColor)+rDiff*x/steps,GetGValue(startColor)+gDiff*x/steps,GetBValue(startColor)+bDiff*x/steps);
|
---|
1977 | HBRUSH brush = CreateSolidBrush(color);
|
---|
1978 |
|
---|
1979 | r2.left = r2.right;
|
---|
1980 | r2.right = r.left+w*x/steps;
|
---|
1981 | FillRect(hdc,&r2,brush);
|
---|
1982 | DeleteObject(brush);
|
---|
1983 | }
|
---|
1984 | }
|
---|
1985 | } else FillRect(hdc,&r,GetSysColorBrush(active ? COLOR_ACTIVECAPTION:COLOR_INACTIVECAPTION));
|
---|
1986 |
|
---|
1987 | if (!hbitmapClose)
|
---|
1988 | {
|
---|
1989 | if (!(hbitmapClose = LoadBitmapA(0,MAKEINTRESOURCEA(OBM_CLOSE)))) return;
|
---|
1990 | hbitmapCloseD = LoadBitmapA(0,MAKEINTRESOURCEA(OBM_CLOSED));
|
---|
1991 | hbitmapMinimize = LoadBitmapA(0,MAKEINTRESOURCEA(OBM_REDUCE));
|
---|
1992 | hbitmapMinimizeD = LoadBitmapA(0,MAKEINTRESOURCEA(OBM_REDUCED));
|
---|
1993 | hbitmapMaximize = LoadBitmapA(0,MAKEINTRESOURCEA(OBM_ZOOM));
|
---|
1994 | hbitmapMaximizeD = LoadBitmapA(0,MAKEINTRESOURCEA(OBM_ZOOMD));
|
---|
1995 | hbitmapRestore = LoadBitmapA(0,MAKEINTRESOURCEA(OBM_RESTORE));
|
---|
1996 | hbitmapRestoreD = LoadBitmapA(0,MAKEINTRESOURCEA(OBM_RESTORED));
|
---|
1997 | }
|
---|
1998 |
|
---|
1999 | if ((dwStyle & WS_SYSMENU) && !(dwExStyle & WS_EX_TOOLWINDOW))
|
---|
2000 | {
|
---|
2001 | if (DrawSysButton(hdc,FALSE))
|
---|
2002 | r.left += GetSystemMetrics(SM_CYCAPTION) - 1;
|
---|
2003 | }
|
---|
2004 |
|
---|
2005 | if (dwStyle & WS_SYSMENU)
|
---|
2006 | {
|
---|
2007 | UINT state;
|
---|
2008 | #if 0 //CB: todo
|
---|
2009 | /* Go get the sysmenu */
|
---|
2010 | state = GetMenuState(hSysMenu, SC_CLOSE, MF_BYCOMMAND);
|
---|
2011 | #else
|
---|
2012 | state = 0;
|
---|
2013 | #endif
|
---|
2014 | /* Draw a grayed close button if disabled and a normal one if SC_CLOSE is not there */
|
---|
2015 | DrawCloseButton(hdc, FALSE,
|
---|
2016 | ((((state & MF_DISABLED) || (state & MF_GRAYED))) && (state != 0xFFFFFFFF)));
|
---|
2017 | r.right -= GetSystemMetrics(SM_CYCAPTION) - 1;
|
---|
2018 |
|
---|
2019 | if ((dwStyle & WS_MAXIMIZEBOX) || (dwStyle & WS_MINIMIZEBOX))
|
---|
2020 | {
|
---|
2021 | /* In win95 the two buttons are always there */
|
---|
2022 | /* But if the menu item is not in the menu they're disabled*/
|
---|
2023 |
|
---|
2024 | DrawMaxButton(hdc, FALSE, (!(dwStyle & WS_MAXIMIZEBOX)));
|
---|
2025 | r.right -= GetSystemMetrics(SM_CXSIZE) + 1;
|
---|
2026 |
|
---|
2027 | DrawMinButton(hdc, FALSE, (!(dwStyle & WS_MINIMIZEBOX)));
|
---|
2028 | r.right -= GetSystemMetrics(SM_CXSIZE) + 1;
|
---|
2029 | }
|
---|
2030 | }
|
---|
2031 |
|
---|
2032 | if (GetWindowTextA(buffer, sizeof(buffer) ))
|
---|
2033 | {
|
---|
2034 | NONCLIENTMETRICSA nclm;
|
---|
2035 | HFONT hFont, hOldFont;
|
---|
2036 | nclm.cbSize = sizeof(NONCLIENTMETRICSA);
|
---|
2037 | SystemParametersInfoA (SPI_GETNONCLIENTMETRICS, 0, &nclm, 0);
|
---|
2038 | if (dwExStyle & WS_EX_TOOLWINDOW)
|
---|
2039 | hFont = CreateFontIndirectA (&nclm.lfSmCaptionFont);
|
---|
2040 | else
|
---|
2041 | hFont = CreateFontIndirectA (&nclm.lfCaptionFont);
|
---|
2042 | hOldFont = SelectObject (hdc, hFont);
|
---|
2043 | if (active) SetTextColor( hdc, GetSysColor( COLOR_CAPTIONTEXT ) );
|
---|
2044 | else SetTextColor( hdc, GetSysColor( COLOR_INACTIVECAPTIONTEXT ) );
|
---|
2045 | SetBkMode( hdc, TRANSPARENT );
|
---|
2046 | r.left += 2;
|
---|
2047 | DrawTextA( hdc, buffer, -1, &r,
|
---|
2048 | DT_SINGLELINE | DT_VCENTER | DT_NOPREFIX | DT_LEFT );
|
---|
2049 | DeleteObject (SelectObject (hdc, hOldFont));
|
---|
2050 | }
|
---|
2051 | }
|
---|
2052 | //******************************************************************************
|
---|
2053 | //******************************************************************************
|
---|
2054 | VOID Win32BaseWindow::DoNCPaint(HRGN clip,BOOL suppress_menupaint)
|
---|
2055 | {
|
---|
2056 | BOOL active = flags & WIN_NCACTIVATED;
|
---|
2057 | HDC hdc;
|
---|
2058 | RECT rect,rectClip,rfuzz;
|
---|
2059 |
|
---|
2060 | /* MSDN docs are pretty idiotic here, they say app CAN use clipRgn in
|
---|
2061 | the call to GetDCEx implying that it is allowed not to use it either.
|
---|
2062 | However, the suggested GetDCEx( , DCX_WINDOW | DCX_INTERSECTRGN)
|
---|
2063 | will cause clipRgn to be deleted after ReleaseDC().
|
---|
2064 | Now, how is the "system" supposed to tell what happened?
|
---|
2065 | */
|
---|
2066 |
|
---|
2067 | if (!(hdc = GetDCEx( Win32Hwnd, (clip > 1) ? clip : 0, DCX_USESTYLE | DCX_WINDOW |
|
---|
2068 | ((clip > 1) ?(DCX_INTERSECTRGN /*| DCX_KEEPCLIPRGN*/) : 0) ))) return;
|
---|
2069 |
|
---|
2070 | rect.top = rect.left = 0;
|
---|
2071 | rect.right = rectWindow.right - rectWindow.left;
|
---|
2072 | rect.bottom = rectWindow.bottom - rectWindow.top;
|
---|
2073 |
|
---|
2074 | if( clip > 1 )
|
---|
2075 | GetRgnBox( clip, &rectClip );
|
---|
2076 | else
|
---|
2077 | {
|
---|
2078 | clip = 0;
|
---|
2079 | rectClip = rect;
|
---|
2080 | }
|
---|
2081 |
|
---|
2082 | SelectObject( hdc, GetSysColorPen(COLOR_WINDOWFRAME) );
|
---|
2083 |
|
---|
2084 | if(!(flags & WIN_MANAGED))
|
---|
2085 | {
|
---|
2086 | if (HAS_BIGFRAME( dwStyle, dwExStyle))
|
---|
2087 | {
|
---|
2088 | DrawEdge (hdc, &rect, EDGE_RAISED, BF_RECT | BF_ADJUST);
|
---|
2089 | }
|
---|
2090 | if (HAS_THICKFRAME( dwStyle, dwExStyle ))
|
---|
2091 | DrawFrame(hdc, &rect, FALSE, active );
|
---|
2092 | else if (HAS_DLGFRAME( dwStyle, dwExStyle ))
|
---|
2093 | DrawFrame( hdc, &rect, TRUE, active );
|
---|
2094 | else if (HAS_THINFRAME( dwStyle ))
|
---|
2095 | {
|
---|
2096 | SelectObject( hdc, GetStockObject(NULL_BRUSH) );
|
---|
2097 | Rectangle( hdc, 0, 0, rect.right, rect.bottom );
|
---|
2098 | }
|
---|
2099 |
|
---|
2100 | if ((dwStyle & WS_CAPTION) == WS_CAPTION)
|
---|
2101 | {
|
---|
2102 | RECT r = rect;
|
---|
2103 | if (dwExStyle & WS_EX_TOOLWINDOW)
|
---|
2104 | {
|
---|
2105 | r.bottom = rect.top + GetSystemMetrics(SM_CYSMCAPTION);
|
---|
2106 | rect.top += GetSystemMetrics(SM_CYSMCAPTION);
|
---|
2107 | }
|
---|
2108 | else
|
---|
2109 | {
|
---|
2110 | r.bottom = rect.top + GetSystemMetrics(SM_CYCAPTION);
|
---|
2111 | rect.top += GetSystemMetrics(SM_CYCAPTION);
|
---|
2112 | }
|
---|
2113 | if( !clip || IntersectRect( &rfuzz, &r, &rectClip ) )
|
---|
2114 | DrawCaption(hdc, &r, active);
|
---|
2115 | }
|
---|
2116 | }
|
---|
2117 | #if 0 //CB: todo
|
---|
2118 | if (HAS_MENU(wndPtr))
|
---|
2119 | {
|
---|
2120 | RECT r = rect;
|
---|
2121 | r.bottom = rect.top + GetSystemMetrics(SM_CYMENU);
|
---|
2122 |
|
---|
2123 | rect.top += MENU_DrawMenuBar( hdc, &r, hwnd, suppress_menupaint ) + 1;
|
---|
2124 | }
|
---|
2125 | #endif
|
---|
2126 |
|
---|
2127 | if (dwExStyle & WS_EX_CLIENTEDGE)
|
---|
2128 | DrawEdge (hdc, &rect, EDGE_SUNKEN, BF_RECT | BF_ADJUST);
|
---|
2129 |
|
---|
2130 | if (dwExStyle & WS_EX_STATICEDGE)
|
---|
2131 | DrawEdge (hdc, &rect, BDR_SUNKENOUTER, BF_RECT | BF_ADJUST);
|
---|
2132 |
|
---|
2133 | /* Draw the scroll-bars */
|
---|
2134 | if (dwStyle & WS_VSCROLL)
|
---|
2135 | SCROLL_DrawScrollBar(Win32Hwnd,hdc,SB_VERT,TRUE,TRUE);
|
---|
2136 | if (dwStyle & WS_HSCROLL)
|
---|
2137 | SCROLL_DrawScrollBar(Win32Hwnd,hdc,SB_HORZ,TRUE,TRUE);
|
---|
2138 |
|
---|
2139 | /* Draw the "size-box" */
|
---|
2140 | if ((dwStyle & WS_VSCROLL) && (dwStyle & WS_HSCROLL))
|
---|
2141 | {
|
---|
2142 | RECT r = rect;
|
---|
2143 | r.left = r.right - GetSystemMetrics(SM_CXVSCROLL) + 1;
|
---|
2144 | r.top = r.bottom - GetSystemMetrics(SM_CYHSCROLL) + 1;
|
---|
2145 | FillRect( hdc, &r, GetSysColorBrush(COLOR_SCROLLBAR) );
|
---|
2146 | if (!(dwStyle & WS_CHILD))
|
---|
2147 | {
|
---|
2148 | POINT p1,p2;
|
---|
2149 | HPEN penDark = GetSysColorPen(COLOR_3DSHADOW);
|
---|
2150 | HPEN penWhite = GetSysColorPen(COLOR_3DHILIGHT);
|
---|
2151 | HPEN oldPen = SelectObject(hdc,penDark);
|
---|
2152 | INT x;
|
---|
2153 |
|
---|
2154 | p1.x = r.right-1;
|
---|
2155 | p1.y = r.bottom;
|
---|
2156 | p2.x = r.right;
|
---|
2157 | p2.y = r.bottom-1;
|
---|
2158 | for (x = 0;x < 3;x++)
|
---|
2159 | {
|
---|
2160 | SelectObject(hdc,penDark);
|
---|
2161 | MoveToEx(hdc,p1.x,p1.y,NULL);
|
---|
2162 | LineTo(hdc,p2.x,p2.y);
|
---|
2163 | p1.x--;
|
---|
2164 | p2.y--;
|
---|
2165 | MoveToEx(hdc,p1.x,p1.y,NULL);
|
---|
2166 | LineTo(hdc,p2.x,p2.y);
|
---|
2167 | SelectObject(hdc,penWhite);
|
---|
2168 | p1.x--;
|
---|
2169 | p2.y--;
|
---|
2170 | MoveToEx(hdc,p1.x,p1.y,NULL);
|
---|
2171 | LineTo(hdc,p2.x,p2.y);
|
---|
2172 | p1.x -= 2;
|
---|
2173 | p2.y -= 2;
|
---|
2174 | }
|
---|
2175 |
|
---|
2176 | SelectObject(hdc,oldPen);
|
---|
2177 | }
|
---|
2178 | }
|
---|
2179 |
|
---|
2180 | ReleaseDC(Win32Hwnd,hdc);
|
---|
2181 | }
|
---|
2182 | //******************************************************************************
|
---|
2183 | //******************************************************************************
|
---|
2184 | LONG Win32BaseWindow::HandleNCPaint(HRGN clip)
|
---|
2185 | {
|
---|
2186 | //CB: ignore it for now (SetWindowPos in WM_CREATE)
|
---|
2187 | // if (!(dwStyle & WS_VISIBLE)) return 0;
|
---|
2188 |
|
---|
2189 | if (dwStyle & WS_MINIMIZE) return 0;
|
---|
2190 |
|
---|
2191 | DoNCPaint(clip,FALSE);
|
---|
2192 |
|
---|
2193 | return 0;
|
---|
2194 | }
|
---|
2195 | /***********************************************************************
|
---|
2196 | * NC_HandleNCLButtonDblClk
|
---|
2197 | *
|
---|
2198 | * Handle a WM_NCLBUTTONDBLCLK message. Called from DefWindowProc().
|
---|
2199 | */
|
---|
2200 | LONG Win32BaseWindow::HandleNCLButtonDblClk(WPARAM wParam,LPARAM lParam)
|
---|
2201 | {
|
---|
2202 | /*
|
---|
2203 | * if this is an icon, send a restore since we are handling
|
---|
2204 | * a double click
|
---|
2205 | */
|
---|
2206 | if (dwStyle & WS_MINIMIZE)
|
---|
2207 | {
|
---|
2208 | SendInternalMessageA(WM_SYSCOMMAND,SC_RESTORE,lParam);
|
---|
2209 | return 0;
|
---|
2210 | }
|
---|
2211 |
|
---|
2212 | switch(wParam) /* Hit test */
|
---|
2213 | {
|
---|
2214 | case HTCAPTION:
|
---|
2215 | /* stop processing if WS_MAXIMIZEBOX is missing */
|
---|
2216 | if (dwStyle & WS_MAXIMIZEBOX)
|
---|
2217 | SendInternalMessageA(WM_SYSCOMMAND,
|
---|
2218 | (dwStyle & WS_MAXIMIZE) ? SC_RESTORE : SC_MAXIMIZE,
|
---|
2219 | lParam);
|
---|
2220 | break;
|
---|
2221 |
|
---|
2222 | case HTSYSMENU:
|
---|
2223 | if (!(GetClassWord(Win32Hwnd,GCW_STYLE) & CS_NOCLOSE))
|
---|
2224 | SendInternalMessageA(WM_SYSCOMMAND,SC_CLOSE,lParam);
|
---|
2225 | break;
|
---|
2226 |
|
---|
2227 | case HTHSCROLL:
|
---|
2228 | SendInternalMessageA(WM_SYSCOMMAND,SC_HSCROLL+HTHSCROLL,lParam);
|
---|
2229 | break;
|
---|
2230 |
|
---|
2231 | case HTVSCROLL:
|
---|
2232 | SendInternalMessageA(WM_SYSCOMMAND,SC_VSCROLL+HTVSCROLL,lParam);
|
---|
2233 | break;
|
---|
2234 | }
|
---|
2235 |
|
---|
2236 | return 0;
|
---|
2237 | }
|
---|
2238 | /***********************************************************************
|
---|
2239 | * NC_HandleSysCommand
|
---|
2240 | *
|
---|
2241 | * Handle a WM_SYSCOMMAND message. Called from DefWindowProc().
|
---|
2242 | *
|
---|
2243 | * TODO: Not done (see #if 0)
|
---|
2244 | */
|
---|
2245 | LONG Win32BaseWindow::HandleSysCommand(WPARAM wParam,POINT *pt32)
|
---|
2246 | {
|
---|
2247 | UINT uCommand = wParam & 0xFFF0;
|
---|
2248 |
|
---|
2249 | /* //CB: don't need this, perhaps recycle for menus
|
---|
2250 | if ((getStyle() & WS_CHILD) && (uCommand != SC_KEYMENU))
|
---|
2251 | ScreenToClient(getParent()->getWindowHandle(), pt32 );
|
---|
2252 | */
|
---|
2253 | switch (uCommand)
|
---|
2254 | {
|
---|
2255 |
|
---|
2256 | case SC_SIZE:
|
---|
2257 | {
|
---|
2258 | DWORD flags = 0;
|
---|
2259 |
|
---|
2260 | switch ((wParam & 0xF)+2)
|
---|
2261 | {
|
---|
2262 | case HTLEFT:
|
---|
2263 | flags = TFOS_LEFT;
|
---|
2264 | break;
|
---|
2265 |
|
---|
2266 | case HTRIGHT:
|
---|
2267 | flags = TFOS_RIGHT;
|
---|
2268 | break;
|
---|
2269 |
|
---|
2270 | case HTTOP:
|
---|
2271 | flags = TFOS_TOP;
|
---|
2272 | break;
|
---|
2273 |
|
---|
2274 | case HTTOPLEFT:
|
---|
2275 | flags = TFOS_TOP | TFOS_LEFT;
|
---|
2276 | break;
|
---|
2277 |
|
---|
2278 | case HTTOPRIGHT:
|
---|
2279 | flags = TFOS_TOP | TFOS_RIGHT;
|
---|
2280 | break;
|
---|
2281 |
|
---|
2282 | case HTBOTTOM:
|
---|
2283 | flags = TFOS_BOTTOM;
|
---|
2284 | break;
|
---|
2285 |
|
---|
2286 | case HTBOTTOMLEFT:
|
---|
2287 | flags = TFOS_BOTTOM | TFOS_LEFT;
|
---|
2288 | break;
|
---|
2289 |
|
---|
2290 | case HTBOTTOMRIGHT:
|
---|
2291 | flags = TFOS_BOTTOM | TFOS_RIGHT;
|
---|
2292 | break;
|
---|
2293 | }
|
---|
2294 | if (flags) FrameTrackFrame(this,flags);
|
---|
2295 | break;
|
---|
2296 | }
|
---|
2297 |
|
---|
2298 | case SC_MOVE:
|
---|
2299 | FrameTrackFrame(this,TFOS_MOVE);
|
---|
2300 | break;
|
---|
2301 |
|
---|
2302 | case SC_MINIMIZE:
|
---|
2303 | ShowWindow(SW_MINIMIZE);
|
---|
2304 | break;
|
---|
2305 |
|
---|
2306 | case SC_MAXIMIZE:
|
---|
2307 | ShowWindow(SW_MAXIMIZE);
|
---|
2308 | break;
|
---|
2309 |
|
---|
2310 | case SC_RESTORE:
|
---|
2311 | ShowWindow(SW_RESTORE);
|
---|
2312 | break;
|
---|
2313 |
|
---|
2314 | case SC_CLOSE:
|
---|
2315 | return SendInternalMessageA(WM_CLOSE,0,0);
|
---|
2316 |
|
---|
2317 | case SC_VSCROLL:
|
---|
2318 | case SC_HSCROLL:
|
---|
2319 | TrackScrollBar(wParam,*pt32);
|
---|
2320 | break;
|
---|
2321 | #if 0
|
---|
2322 | case SC_MOUSEMENU:
|
---|
2323 | MENU_TrackMouseMenuBar( wndPtr, wParam & 0x000F, pt32 );
|
---|
2324 | break;
|
---|
2325 |
|
---|
2326 | case SC_KEYMENU:
|
---|
2327 | MENU_TrackKbdMenuBar( wndPtr , wParam , pt.x );
|
---|
2328 | break;
|
---|
2329 | #endif
|
---|
2330 | case SC_TASKLIST:
|
---|
2331 | WinExec("taskman.exe",SW_SHOWNORMAL);
|
---|
2332 | break;
|
---|
2333 |
|
---|
2334 | case SC_SCREENSAVE:
|
---|
2335 | if (wParam == SC_ABOUTWINE)
|
---|
2336 | ShellAboutA(Win32Hwnd,"Odin","Odin alpha release compiled with IBM VAC++",0);
|
---|
2337 | else
|
---|
2338 | if (wParam == SC_PUTMARK)
|
---|
2339 | dprintf(("Mark requested by user\n"));
|
---|
2340 | break;
|
---|
2341 |
|
---|
2342 | case SC_HOTKEY:
|
---|
2343 | case SC_ARRANGE:
|
---|
2344 | case SC_NEXTWINDOW:
|
---|
2345 | case SC_PREVWINDOW:
|
---|
2346 | break;
|
---|
2347 | }
|
---|
2348 | return 0;
|
---|
2349 | }
|
---|
2350 | //******************************************************************************
|
---|
2351 | //******************************************************************************
|
---|
2352 | LRESULT Win32BaseWindow::DefWndControlColor(UINT ctlType, HDC hdc)
|
---|
2353 | {
|
---|
2354 | //SvL: Set background color to default button color (not window (white))
|
---|
2355 | if(ctlType == CTLCOLOR_BTN)
|
---|
2356 | {
|
---|
2357 | SetBkColor(hdc, GetSysColor(COLOR_BTNFACE));
|
---|
2358 | SetTextColor(hdc, GetSysColor(COLOR_WINDOWTEXT));
|
---|
2359 | return GetSysColorBrush(COLOR_BTNFACE);
|
---|
2360 | }
|
---|
2361 | //SvL: Set background color to default dialog color if window is dialog
|
---|
2362 | if((ctlType == CTLCOLOR_DLG || ctlType == CTLCOLOR_STATIC) && IsDialog()) {
|
---|
2363 | SetBkColor(hdc, GetSysColor(COLOR_BTNFACE));
|
---|
2364 | SetTextColor(hdc, GetSysColor(COLOR_WINDOWTEXT));
|
---|
2365 | return GetSysColorBrush(COLOR_BTNFACE);
|
---|
2366 | }
|
---|
2367 |
|
---|
2368 | if( ctlType == CTLCOLOR_SCROLLBAR)
|
---|
2369 | {
|
---|
2370 | HBRUSH hb = GetSysColorBrush(COLOR_SCROLLBAR);
|
---|
2371 | COLORREF bk = GetSysColor(COLOR_3DHILIGHT);
|
---|
2372 | SetTextColor( hdc, GetSysColor(COLOR_3DFACE));
|
---|
2373 | SetBkColor( hdc, bk);
|
---|
2374 |
|
---|
2375 | //TODO?
|
---|
2376 | #if 0
|
---|
2377 | /* if COLOR_WINDOW happens to be the same as COLOR_3DHILIGHT
|
---|
2378 | * we better use 0x55aa bitmap brush to make scrollbar's background
|
---|
2379 | * look different from the window background.
|
---|
2380 | */
|
---|
2381 | if (bk == GetSysColor(COLOR_WINDOW)) {
|
---|
2382 | return CACHE_GetPattern55AABrush();
|
---|
2383 | }
|
---|
2384 | #endif
|
---|
2385 | UnrealizeObject( hb );
|
---|
2386 | return (LRESULT)hb;
|
---|
2387 | }
|
---|
2388 |
|
---|
2389 | SetTextColor( hdc, GetSysColor(COLOR_WINDOWTEXT));
|
---|
2390 |
|
---|
2391 | if ((ctlType == CTLCOLOR_EDIT) || (ctlType == CTLCOLOR_LISTBOX))
|
---|
2392 | {
|
---|
2393 | SetBkColor( hdc, GetSysColor(COLOR_WINDOW) );
|
---|
2394 | }
|
---|
2395 | else
|
---|
2396 | {
|
---|
2397 | SetBkColor( hdc, GetSysColor(COLOR_3DFACE) );
|
---|
2398 | return (LRESULT)GetSysColorBrush(COLOR_3DFACE);
|
---|
2399 | }
|
---|
2400 | return (LRESULT)GetSysColorBrush(COLOR_WINDOW);
|
---|
2401 | }
|
---|
2402 | //******************************************************************************
|
---|
2403 | //******************************************************************************
|
---|
2404 | LRESULT Win32BaseWindow::DefWndPrint(HDC hdc,ULONG uFlags)
|
---|
2405 | {
|
---|
2406 | /*
|
---|
2407 | * Visibility flag.
|
---|
2408 | */
|
---|
2409 | if ( (uFlags & PRF_CHECKVISIBLE) &&
|
---|
2410 | !IsWindowVisible() )
|
---|
2411 | return 0;
|
---|
2412 |
|
---|
2413 | /*
|
---|
2414 | * Unimplemented flags.
|
---|
2415 | */
|
---|
2416 | if ( (uFlags & PRF_CHILDREN) ||
|
---|
2417 | (uFlags & PRF_OWNED) ||
|
---|
2418 | (uFlags & PRF_NONCLIENT) )
|
---|
2419 | {
|
---|
2420 | dprintf(("WM_PRINT message with unsupported flags\n"));
|
---|
2421 | }
|
---|
2422 |
|
---|
2423 | /*
|
---|
2424 | * Background
|
---|
2425 | */
|
---|
2426 | if ( uFlags & PRF_ERASEBKGND)
|
---|
2427 | SendInternalMessageA(WM_ERASEBKGND, (WPARAM)hdc, 0);
|
---|
2428 |
|
---|
2429 | /*
|
---|
2430 | * Client area
|
---|
2431 | */
|
---|
2432 | if ( uFlags & PRF_CLIENT)
|
---|
2433 | SendInternalMessageA(WM_PRINTCLIENT, (WPARAM)hdc, PRF_CLIENT);
|
---|
2434 |
|
---|
2435 |
|
---|
2436 | return 0;
|
---|
2437 | }
|
---|
2438 | //******************************************************************************
|
---|
2439 | //******************************************************************************
|
---|
2440 | LRESULT Win32BaseWindow::DefWindowProcA(UINT Msg, WPARAM wParam, LPARAM lParam)
|
---|
2441 | {
|
---|
2442 | switch(Msg)
|
---|
2443 | {
|
---|
2444 | case WM_CLOSE:
|
---|
2445 | dprintf(("DefWindowProcA: WM_CLOSE %x", getWindowHandle()));
|
---|
2446 | DestroyWindow();
|
---|
2447 | return 0;
|
---|
2448 |
|
---|
2449 | case WM_GETTEXTLENGTH:
|
---|
2450 | return wndNameLength;
|
---|
2451 |
|
---|
2452 | case WM_GETTEXT:
|
---|
2453 | if (!lParam || !wParam) return 0;
|
---|
2454 | if (!windowNameA) ((LPSTR)lParam)[0] = 0;
|
---|
2455 | else lstrcpynA((LPSTR)lParam, windowNameA, wParam);
|
---|
2456 | return min(wndNameLength, wParam);
|
---|
2457 |
|
---|
2458 | case WM_SETTEXT:
|
---|
2459 | {
|
---|
2460 | LPCSTR lpsz = (LPCSTR)lParam;
|
---|
2461 |
|
---|
2462 | if(windowNameA) free(windowNameA);
|
---|
2463 | if(windowNameW) free(windowNameW);
|
---|
2464 |
|
---|
2465 | if (lParam)
|
---|
2466 | {
|
---|
2467 | wndNameLength = strlen(lpsz);
|
---|
2468 | windowNameA = (LPSTR)_smalloc(wndNameLength+1);
|
---|
2469 | strcpy(windowNameA, lpsz);
|
---|
2470 | windowNameW = (LPWSTR)_smalloc((wndNameLength+1)*sizeof(WCHAR));
|
---|
2471 | lstrcpyAtoW(windowNameW, windowNameA);
|
---|
2472 | }
|
---|
2473 | else
|
---|
2474 | {
|
---|
2475 | windowNameA = NULL;
|
---|
2476 | windowNameW = NULL;
|
---|
2477 | wndNameLength = 0;
|
---|
2478 | }
|
---|
2479 | dprintf(("WM_SETTEXT of %x to %s\n", Win32Hwnd, lParam));
|
---|
2480 | if (dwStyle & WS_CAPTION)
|
---|
2481 | {
|
---|
2482 | //CB: optimize!
|
---|
2483 | HandleNCPaint(0);
|
---|
2484 | }
|
---|
2485 | /* //CB: endless loop in trackbar.exe -> to fix
|
---|
2486 | if(OS2HwndFrame && (dwStyle & WS_CAPTION) == WS_CAPTION)
|
---|
2487 | return OSLibWinSetWindowText(OS2HwndFrame,(LPSTR)windowNameA);
|
---|
2488 | */
|
---|
2489 | return TRUE;
|
---|
2490 | }
|
---|
2491 |
|
---|
2492 | case WM_SETREDRAW:
|
---|
2493 | {
|
---|
2494 | if (wParam)
|
---|
2495 | {
|
---|
2496 | setStyle(getStyle() | WS_VISIBLE);
|
---|
2497 | OSLibWinEnableWindowUpdate(OS2HwndFrame,TRUE);
|
---|
2498 | } else
|
---|
2499 | {
|
---|
2500 | if (getStyle() & WS_VISIBLE)
|
---|
2501 | {
|
---|
2502 | setStyle(getStyle() & ~WS_VISIBLE);
|
---|
2503 | OSLibWinEnableWindowUpdate(OS2HwndFrame,FALSE);
|
---|
2504 | }
|
---|
2505 | }
|
---|
2506 | return 0;
|
---|
2507 | }
|
---|
2508 |
|
---|
2509 | case WM_NCPAINT:
|
---|
2510 | return HandleNCPaint((HRGN)wParam);
|
---|
2511 |
|
---|
2512 | case WM_NCACTIVATE:
|
---|
2513 | return HandleNCActivate(wParam);
|
---|
2514 |
|
---|
2515 | case WM_NCCREATE:
|
---|
2516 | return(TRUE);
|
---|
2517 |
|
---|
2518 | case WM_NCDESTROY:
|
---|
2519 | return 0;
|
---|
2520 |
|
---|
2521 | case WM_NCCALCSIZE:
|
---|
2522 | return HandleNCCalcSize((BOOL)wParam,(RECT*)lParam);
|
---|
2523 |
|
---|
2524 | case WM_CTLCOLORMSGBOX:
|
---|
2525 | case WM_CTLCOLOREDIT:
|
---|
2526 | case WM_CTLCOLORLISTBOX:
|
---|
2527 | case WM_CTLCOLORBTN:
|
---|
2528 | case WM_CTLCOLORDLG:
|
---|
2529 | case WM_CTLCOLORSTATIC:
|
---|
2530 | case WM_CTLCOLORSCROLLBAR:
|
---|
2531 | return DefWndControlColor(Msg - WM_CTLCOLORMSGBOX, (HDC)wParam);
|
---|
2532 |
|
---|
2533 | case WM_CTLCOLOR:
|
---|
2534 | return DefWndControlColor(HIWORD(lParam), (HDC)wParam);
|
---|
2535 |
|
---|
2536 | case WM_VKEYTOITEM:
|
---|
2537 | case WM_CHARTOITEM:
|
---|
2538 | return -1;
|
---|
2539 |
|
---|
2540 | case WM_PARENTNOTIFY:
|
---|
2541 | return 0;
|
---|
2542 |
|
---|
2543 | case WM_MOUSEACTIVATE:
|
---|
2544 | {
|
---|
2545 | dprintf(("DefWndProc: WM_MOUSEACTIVATE for %x Msg %s", Win32Hwnd, GetMsgText(HIWORD(lParam))));
|
---|
2546 | if(getStyle() & WS_CHILD && !(getExStyle() & WS_EX_NOPARENTNOTIFY) )
|
---|
2547 | {
|
---|
2548 | if(getParent()) {
|
---|
2549 | LRESULT rc = getParent()->SendInternalMessageA(WM_MOUSEACTIVATE, wParam, lParam );
|
---|
2550 | if(rc) return rc;
|
---|
2551 | }
|
---|
2552 | }
|
---|
2553 | return (LOWORD(lParam) == HTCAPTION) ? MA_NOACTIVATE : MA_ACTIVATE;
|
---|
2554 | }
|
---|
2555 |
|
---|
2556 | case WM_ACTIVATE:
|
---|
2557 | return 0;
|
---|
2558 |
|
---|
2559 | case WM_SETCURSOR:
|
---|
2560 | {
|
---|
2561 | dprintf(("DefWndProc: WM_SETCURSOR for %x Msg %s", Win32Hwnd, GetMsgText(HIWORD(lParam))));
|
---|
2562 | if(getStyle() & WS_CHILD && !(getExStyle() & WS_EX_NOPARENTNOTIFY) )
|
---|
2563 | {
|
---|
2564 | if(getParent()) {
|
---|
2565 | LRESULT rc = getParent()->SendInternalMessageA(WM_SETCURSOR, wParam, lParam);
|
---|
2566 | if(rc) return rc;
|
---|
2567 | }
|
---|
2568 | }
|
---|
2569 | if (wParam == Win32Hwnd)
|
---|
2570 | {
|
---|
2571 | HCURSOR hCursor;
|
---|
2572 |
|
---|
2573 | switch(LOWORD(lParam))
|
---|
2574 | {
|
---|
2575 | case HTLEFT:
|
---|
2576 | case HTRIGHT:
|
---|
2577 | hCursor = LoadCursorA(0,IDC_SIZEWEA);
|
---|
2578 | break;
|
---|
2579 |
|
---|
2580 | case HTTOP:
|
---|
2581 | case HTBOTTOM:
|
---|
2582 | hCursor = LoadCursorA(0,IDC_SIZENSA);
|
---|
2583 | break;
|
---|
2584 |
|
---|
2585 | case HTTOPLEFT:
|
---|
2586 | case HTBOTTOMRIGHT:
|
---|
2587 | hCursor = LoadCursorA(0,IDC_SIZENWSEA);
|
---|
2588 | break;
|
---|
2589 |
|
---|
2590 | case HTTOPRIGHT:
|
---|
2591 | case HTBOTTOMLEFT:
|
---|
2592 | hCursor = LoadCursorA(0,IDC_SIZENESWA);
|
---|
2593 | break;
|
---|
2594 |
|
---|
2595 | default:
|
---|
2596 | hCursor = windowClass ? windowClass->getCursor():LoadCursorA(0,IDC_ARROWA);
|
---|
2597 | break;
|
---|
2598 | }
|
---|
2599 |
|
---|
2600 | if (hCursor)
|
---|
2601 | {
|
---|
2602 | SetCursor(hCursor);
|
---|
2603 | return 1;
|
---|
2604 | } else return 0;
|
---|
2605 | } else return 0;
|
---|
2606 | }
|
---|
2607 |
|
---|
2608 | case WM_MOUSEMOVE:
|
---|
2609 | return 0;
|
---|
2610 |
|
---|
2611 | case WM_WINDOWPOSCHANGED:
|
---|
2612 | {
|
---|
2613 |
|
---|
2614 | /* undocumented SWP flags - from SDK 3.1 */
|
---|
2615 | #define SWP_NOCLIENTSIZE 0x0800
|
---|
2616 | #define SWP_NOCLIENTMOVE 0x1000
|
---|
2617 |
|
---|
2618 | PWINDOWPOS wpos = (PWINDOWPOS)lParam;
|
---|
2619 | WPARAM wp = SIZE_RESTORED;
|
---|
2620 |
|
---|
2621 | if (!(wpos->flags & SWP_NOMOVE) && !(wpos->flags & SWP_NOCLIENTMOVE))
|
---|
2622 | SendInternalMessageA(WM_MOVE, 0, MAKELONG(rectClient.left, rectClient.top));
|
---|
2623 |
|
---|
2624 | if (!(wpos->flags & SWP_NOSIZE) && !(wpos->flags & SWP_NOCLIENTSIZE))
|
---|
2625 | {
|
---|
2626 | if (dwStyle & WS_MAXIMIZE) wp = SIZE_MAXIMIZED;
|
---|
2627 | else if (dwStyle & WS_MINIMIZE) wp = SIZE_MINIMIZED;
|
---|
2628 |
|
---|
2629 | SendInternalMessageA(WM_SIZE, wp, MAKELONG(rectClient.right - rectClient.left,
|
---|
2630 | rectClient.bottom - rectClient.top));
|
---|
2631 | }
|
---|
2632 | return 0;
|
---|
2633 | }
|
---|
2634 | case WM_WINDOWPOSCHANGING:
|
---|
2635 | return HandleWindowPosChanging((WINDOWPOS *)lParam);
|
---|
2636 |
|
---|
2637 | case WM_ERASEBKGND:
|
---|
2638 | case WM_ICONERASEBKGND:
|
---|
2639 | {
|
---|
2640 | RECT rect;
|
---|
2641 | int rc;
|
---|
2642 |
|
---|
2643 | if (!windowClass || !windowClass->getBackgroundBrush()) return 0;
|
---|
2644 |
|
---|
2645 | rc = GetClipBox( (HDC)wParam, &rect );
|
---|
2646 | if ((rc == SIMPLEREGION) || (rc == COMPLEXREGION))
|
---|
2647 | {
|
---|
2648 | HBRUSH hBrush = windowClass->getBackgroundBrush();
|
---|
2649 |
|
---|
2650 | if (hBrush <= (HBRUSH)(SYSCOLOR_GetLastColor()+1)) hBrush = GetSysColorBrush(hBrush-1);
|
---|
2651 |
|
---|
2652 | FillRect( (HDC)wParam, &rect, hBrush);
|
---|
2653 | }
|
---|
2654 |
|
---|
2655 | return 1;
|
---|
2656 | }
|
---|
2657 |
|
---|
2658 | case WM_PRINT:
|
---|
2659 | return DefWndPrint(wParam,lParam);
|
---|
2660 |
|
---|
2661 | case WM_PAINTICON:
|
---|
2662 | case WM_PAINT:
|
---|
2663 | {
|
---|
2664 | PAINTSTRUCT ps;
|
---|
2665 | HDC hdc = BeginPaint(getWindowHandle(), &ps );
|
---|
2666 | if( hdc )
|
---|
2667 | {
|
---|
2668 | if( (getStyle() & WS_MINIMIZE) && getWindowClass()->getIcon())
|
---|
2669 | {
|
---|
2670 | int x = (rectWindow.right - rectWindow.left - GetSystemMetrics(SM_CXICON))/2;
|
---|
2671 | int y = (rectWindow.bottom - rectWindow.top - GetSystemMetrics(SM_CYICON))/2;
|
---|
2672 | dprintf(("Painting class icon: vis rect=(%i,%i - %i,%i)\n", ps.rcPaint.left, ps.rcPaint.top, ps.rcPaint.right, ps.rcPaint.bottom ));
|
---|
2673 | DrawIcon(hdc, x, y, getWindowClass()->getIcon() );
|
---|
2674 | }
|
---|
2675 | EndPaint(getWindowHandle(), &ps );
|
---|
2676 | }
|
---|
2677 | return 0;
|
---|
2678 | }
|
---|
2679 |
|
---|
2680 | case WM_GETDLGCODE:
|
---|
2681 | return 0;
|
---|
2682 |
|
---|
2683 | case WM_NCLBUTTONDOWN:
|
---|
2684 | return HandleNCLButtonDown(wParam,lParam);
|
---|
2685 |
|
---|
2686 | case WM_LBUTTONDBLCLK:
|
---|
2687 | case WM_NCLBUTTONDBLCLK:
|
---|
2688 | return HandleNCLButtonDblClk(wParam,lParam);
|
---|
2689 |
|
---|
2690 | case WM_NCRBUTTONDOWN:
|
---|
2691 | case WM_NCRBUTTONDBLCLK:
|
---|
2692 | case WM_NCMBUTTONDOWN:
|
---|
2693 | case WM_NCMBUTTONDBLCLK:
|
---|
2694 | if (lastHitTestVal == HTERROR) MessageBeep(MB_ICONEXCLAMATION);
|
---|
2695 | return 0;
|
---|
2696 |
|
---|
2697 | case WM_NCRBUTTONUP:
|
---|
2698 | case WM_NCMBUTTONUP:
|
---|
2699 | return 0;
|
---|
2700 |
|
---|
2701 | case WM_NCHITTEST:
|
---|
2702 | {
|
---|
2703 | POINT point;
|
---|
2704 |
|
---|
2705 | point.x = (SHORT)LOWORD(lParam);
|
---|
2706 | point.y = (SHORT)HIWORD(lParam);
|
---|
2707 |
|
---|
2708 | return HandleNCHitTest(point);
|
---|
2709 | }
|
---|
2710 |
|
---|
2711 | case WM_SYSCOMMAND:
|
---|
2712 | {
|
---|
2713 | POINT point;
|
---|
2714 |
|
---|
2715 | point.x = LOWORD(lParam);
|
---|
2716 | point.y = HIWORD(lParam);
|
---|
2717 | return HandleSysCommand(wParam,&point);
|
---|
2718 | }
|
---|
2719 |
|
---|
2720 | case WM_SYSKEYDOWN:
|
---|
2721 | if(wParam == VK_F4) /* try to close the window */
|
---|
2722 | {
|
---|
2723 | Win32BaseWindow *window = GetTopParent();
|
---|
2724 | if(window && !(window->getClass()->getStyle() & CS_NOCLOSE))
|
---|
2725 | PostMessageA(getWindowHandle(), WM_SYSCOMMAND, SC_CLOSE, 0);
|
---|
2726 | }
|
---|
2727 |
|
---|
2728 | Win32BaseWindow *siblingWindow;
|
---|
2729 | HWND sibling;
|
---|
2730 | char nameBuffer [40], mnemonic;
|
---|
2731 | int nameLength;
|
---|
2732 |
|
---|
2733 | GetWindowTextA (nameBuffer, 40);
|
---|
2734 |
|
---|
2735 | // search all sibling to see it this key is their mnemonic
|
---|
2736 | sibling = GetWindow (GW_HWNDFIRST);
|
---|
2737 | while (sibling != 0) {
|
---|
2738 | siblingWindow = GetWindowFromHandle (sibling);
|
---|
2739 | nameLength = siblingWindow->GetWindowTextA (nameBuffer, 40);
|
---|
2740 |
|
---|
2741 | // find the siblings mnemonic
|
---|
2742 | mnemonic = '\0';
|
---|
2743 | for (int i=0 ; i<nameLength ; i++) {
|
---|
2744 | if (nameBuffer [i] == '&') {
|
---|
2745 | mnemonic = nameBuffer [i+1];
|
---|
2746 | if ((mnemonic >= 'a') && (mnemonic <= 'z'))
|
---|
2747 | mnemonic -= 32; // make it uppercase
|
---|
2748 | break; // stop searching
|
---|
2749 | }
|
---|
2750 | }
|
---|
2751 |
|
---|
2752 | // key matches siblings mnemonic, send mouseclick
|
---|
2753 | if (mnemonic == (char) wParam) {
|
---|
2754 | siblingWindow->SendInternalMessageA (BM_CLICK, 0, 0);
|
---|
2755 | }
|
---|
2756 |
|
---|
2757 | sibling = siblingWindow->GetNextWindow (GW_HWNDNEXT);
|
---|
2758 | }
|
---|
2759 |
|
---|
2760 | return 0;
|
---|
2761 |
|
---|
2762 | case WM_SHOWWINDOW:
|
---|
2763 | if (!lParam) return 0; /* sent from ShowWindow */
|
---|
2764 | if (!(dwStyle & WS_POPUP) || !owner) return 0;
|
---|
2765 | if ((dwStyle & WS_VISIBLE) && wParam) return 0;
|
---|
2766 | else if (!(dwStyle & WS_VISIBLE) && !wParam) return 0;
|
---|
2767 | ShowWindow(wParam ? SW_SHOWNOACTIVATE : SW_HIDE);
|
---|
2768 | return 0;
|
---|
2769 |
|
---|
2770 | case WM_CANCELMODE:
|
---|
2771 | //if (getParent() == windowDesktop) EndMenu();
|
---|
2772 | if (GetCapture() == Win32Hwnd) ReleaseCapture();
|
---|
2773 | return 0;
|
---|
2774 |
|
---|
2775 | case WM_DROPOBJECT:
|
---|
2776 | return DRAG_FILE;
|
---|
2777 |
|
---|
2778 | case WM_QUERYDROPOBJECT:
|
---|
2779 | if (dwExStyle & WS_EX_ACCEPTFILES) return 1;
|
---|
2780 | return 0;
|
---|
2781 |
|
---|
2782 | case WM_QUERYDRAGICON:
|
---|
2783 | {
|
---|
2784 | HICON hIcon = windowClass->getCursor();
|
---|
2785 | UINT len;
|
---|
2786 |
|
---|
2787 | if(hIcon) return (LRESULT)hIcon;
|
---|
2788 | for(len = 1; len < 64; len++)
|
---|
2789 | {
|
---|
2790 | hIcon = LoadIconA(hInstance,MAKEINTRESOURCEA(len));
|
---|
2791 | if(hIcon)
|
---|
2792 | return (LRESULT)hIcon;
|
---|
2793 | }
|
---|
2794 | return (LRESULT)LoadIconA(0,IDI_APPLICATIONA);
|
---|
2795 | }
|
---|
2796 |
|
---|
2797 | case WM_QUERYOPEN:
|
---|
2798 | case WM_QUERYENDSESSION:
|
---|
2799 | return 1;
|
---|
2800 |
|
---|
2801 | case WM_NOTIFYFORMAT:
|
---|
2802 | if (IsWindowUnicode()) return NFR_UNICODE;
|
---|
2803 | else return NFR_ANSI;
|
---|
2804 |
|
---|
2805 | case WM_SETICON:
|
---|
2806 | case WM_GETICON:
|
---|
2807 | {
|
---|
2808 | LRESULT result = 0;
|
---|
2809 | if (!windowClass) return result;
|
---|
2810 | int index = GCL_HICON;
|
---|
2811 |
|
---|
2812 | if (wParam == ICON_SMALL)
|
---|
2813 | index = GCL_HICONSM;
|
---|
2814 |
|
---|
2815 | result = windowClass->getClassLongA(index);
|
---|
2816 |
|
---|
2817 | if (Msg == WM_SETICON)
|
---|
2818 | windowClass->setClassLongA(index, lParam);
|
---|
2819 |
|
---|
2820 | return result;
|
---|
2821 | }
|
---|
2822 |
|
---|
2823 | case WM_NOTIFY:
|
---|
2824 | return 0; //comctl32 controls expect this
|
---|
2825 |
|
---|
2826 | default:
|
---|
2827 | if(Msg > WM_USER) {
|
---|
2828 | return 0;
|
---|
2829 | }
|
---|
2830 | return 1; //CB: shouldn't this be 0?
|
---|
2831 | }
|
---|
2832 | }
|
---|
2833 | //******************************************************************************
|
---|
2834 | //******************************************************************************
|
---|
2835 | LRESULT Win32BaseWindow::DefWindowProcW(UINT Msg, WPARAM wParam, LPARAM lParam)
|
---|
2836 | {
|
---|
2837 | switch(Msg)
|
---|
2838 | {
|
---|
2839 | case WM_GETTEXTLENGTH:
|
---|
2840 | return wndNameLength;
|
---|
2841 |
|
---|
2842 | case WM_GETTEXT:
|
---|
2843 | if (!lParam || !wParam) return 0;
|
---|
2844 | if (!windowNameW) ((LPWSTR)lParam)[0] = 0;
|
---|
2845 | else lstrcpynW((LPWSTR)lParam,windowNameW,wParam);
|
---|
2846 | return min(wndNameLength,wParam);
|
---|
2847 |
|
---|
2848 | case WM_SETTEXT:
|
---|
2849 | {
|
---|
2850 | LPWSTR lpsz = (LPWSTR)lParam;
|
---|
2851 |
|
---|
2852 | if(windowNameA) free(windowNameA);
|
---|
2853 | if(windowNameW) free(windowNameW);
|
---|
2854 |
|
---|
2855 | if (lParam)
|
---|
2856 | {
|
---|
2857 | wndNameLength = lstrlenW(lpsz);
|
---|
2858 | windowNameA = (LPSTR)_smalloc(wndNameLength+1);
|
---|
2859 | lstrcpyWtoA(windowNameA,lpsz);
|
---|
2860 | windowNameW = (LPWSTR)_smalloc((wndNameLength+1)*sizeof(WCHAR));
|
---|
2861 | lstrcpyW(windowNameW,lpsz);
|
---|
2862 | }
|
---|
2863 | else
|
---|
2864 | {
|
---|
2865 | windowNameA = NULL;
|
---|
2866 | windowNameW = NULL;
|
---|
2867 | wndNameLength = 0;
|
---|
2868 | }
|
---|
2869 |
|
---|
2870 | if(OS2HwndFrame && (dwStyle & WS_CAPTION) == WS_CAPTION)
|
---|
2871 | return OSLibWinSetWindowText(OS2HwndFrame,(LPSTR)windowNameA);
|
---|
2872 |
|
---|
2873 | return TRUE;
|
---|
2874 | }
|
---|
2875 |
|
---|
2876 | default:
|
---|
2877 | return DefWindowProcA(Msg, wParam, lParam);
|
---|
2878 | }
|
---|
2879 | }
|
---|
2880 | //******************************************************************************
|
---|
2881 | //******************************************************************************
|
---|
2882 | LRESULT Win32BaseWindow::SendMessageA(ULONG Msg, WPARAM wParam, LPARAM lParam)
|
---|
2883 | {
|
---|
2884 | //if the destination window is created by this process & thread, call window proc directly
|
---|
2885 | if(dwProcessId == currentProcessId && dwThreadId == GetCurrentThreadId()) {
|
---|
2886 | return SendInternalMessageA(Msg, wParam, lParam);
|
---|
2887 | }
|
---|
2888 | //otherwise use WinSendMsg to send it to the right process/thread
|
---|
2889 | return OSLibSendMessage(getOS2WindowHandle(), Msg, wParam, lParam, FALSE);
|
---|
2890 | }
|
---|
2891 | //******************************************************************************
|
---|
2892 | //******************************************************************************
|
---|
2893 | LRESULT Win32BaseWindow::SendMessageW(ULONG Msg, WPARAM wParam, LPARAM lParam)
|
---|
2894 | {
|
---|
2895 | //if the destination window is created by this process & thread, call window proc directly
|
---|
2896 | if(dwProcessId == currentProcessId && dwThreadId == GetCurrentThreadId()) {
|
---|
2897 | return SendInternalMessageW(Msg, wParam, lParam);
|
---|
2898 | }
|
---|
2899 | //otherwise use WinSendMsg to send it to the right process/thread
|
---|
2900 | return OSLibSendMessage(getOS2WindowHandle(), Msg, wParam, lParam, TRUE);
|
---|
2901 | }
|
---|
2902 | //******************************************************************************
|
---|
2903 | //Called as a result of an OS/2 message or called from a class method
|
---|
2904 | //******************************************************************************
|
---|
2905 | LRESULT Win32BaseWindow::SendInternalMessageA(ULONG Msg, WPARAM wParam, LPARAM lParam)
|
---|
2906 | {
|
---|
2907 | LRESULT rc;
|
---|
2908 | BOOL fInternalMsgBackup = fInternalMsg;
|
---|
2909 |
|
---|
2910 | DebugPrintMessage(getWindowHandle(), Msg, wParam, lParam, FALSE, TRUE);
|
---|
2911 |
|
---|
2912 | CallWindowHookProc(WH_CALLWNDPROC, Msg, wParam, lParam, FALSE);
|
---|
2913 |
|
---|
2914 | fInternalMsg = TRUE;
|
---|
2915 | switch(Msg)
|
---|
2916 | {
|
---|
2917 | case WM_CREATE:
|
---|
2918 | {
|
---|
2919 | if(CallWindowProcA(win32wndproc, getWindowHandle(), WM_CREATE, 0, lParam) == -1) {
|
---|
2920 | dprintf(("WM_CREATE returned -1\n"));
|
---|
2921 | rc = -1; //don't create window
|
---|
2922 | break;
|
---|
2923 | }
|
---|
2924 | rc = 0;
|
---|
2925 | break;
|
---|
2926 | }
|
---|
2927 | case WM_LBUTTONDOWN:
|
---|
2928 | case WM_MBUTTONDOWN:
|
---|
2929 | case WM_RBUTTONDOWN:
|
---|
2930 | {
|
---|
2931 | if (getParent())
|
---|
2932 | {
|
---|
2933 | POINTS pt = MAKEPOINTS(lParam);
|
---|
2934 | POINT point;
|
---|
2935 |
|
---|
2936 | point.x = pt.x;
|
---|
2937 | point.y = pt.y;
|
---|
2938 | mapWin32Point(OS2Hwnd,getParent()->getOS2WindowHandle(),(OSLIBPOINT*)&point);
|
---|
2939 | NotifyParent(Msg,wParam,MAKELPARAM(point.x,point.y));
|
---|
2940 | }
|
---|
2941 | rc = win32wndproc(getWindowHandle(), Msg, wParam, lParam);
|
---|
2942 | break;
|
---|
2943 | }
|
---|
2944 |
|
---|
2945 | case WM_DESTROY:
|
---|
2946 | rc = win32wndproc(getWindowHandle(), WM_DESTROY, 0, 0);
|
---|
2947 | break;
|
---|
2948 |
|
---|
2949 | default:
|
---|
2950 | rc = CallWindowProcA(win32wndproc, getWindowHandle(), Msg, wParam, lParam);
|
---|
2951 | break;
|
---|
2952 | }
|
---|
2953 | fInternalMsg = fInternalMsgBackup;
|
---|
2954 | return rc;
|
---|
2955 | }
|
---|
2956 | //******************************************************************************
|
---|
2957 | //Called as a result of an OS/2 message or called from a class method
|
---|
2958 | //******************************************************************************
|
---|
2959 | LRESULT Win32BaseWindow::SendInternalMessageW(ULONG Msg, WPARAM wParam, LPARAM lParam)
|
---|
2960 | {
|
---|
2961 | LRESULT rc;
|
---|
2962 | BOOL fInternalMsgBackup = fInternalMsg;
|
---|
2963 |
|
---|
2964 | DebugPrintMessage(getWindowHandle(), Msg, wParam, lParam, TRUE, TRUE);
|
---|
2965 |
|
---|
2966 | CallWindowHookProc(WH_CALLWNDPROC, Msg, wParam, lParam, TRUE);
|
---|
2967 |
|
---|
2968 | fInternalMsg = TRUE;
|
---|
2969 | switch(Msg)
|
---|
2970 | {
|
---|
2971 | case WM_CREATE:
|
---|
2972 | {
|
---|
2973 | if(CallWindowProcW(win32wndproc, getWindowHandle(), WM_CREATE, 0, lParam) == -1) {
|
---|
2974 | dprintf(("WM_CREATE returned -1\n"));
|
---|
2975 | rc = -1; //don't create window
|
---|
2976 | break;
|
---|
2977 | }
|
---|
2978 | rc = 0;
|
---|
2979 | break;
|
---|
2980 | }
|
---|
2981 | case WM_LBUTTONDOWN:
|
---|
2982 | case WM_MBUTTONDOWN:
|
---|
2983 | case WM_RBUTTONDOWN:
|
---|
2984 | NotifyParent(Msg, wParam, lParam);
|
---|
2985 | rc = win32wndproc(getWindowHandle(), Msg, wParam, lParam);
|
---|
2986 | break;
|
---|
2987 |
|
---|
2988 | case WM_DESTROY:
|
---|
2989 | rc = win32wndproc(getWindowHandle(), WM_DESTROY, 0, 0);
|
---|
2990 | break;
|
---|
2991 | default:
|
---|
2992 | rc = CallWindowProcW(win32wndproc, getWindowHandle(), Msg, wParam, lParam);
|
---|
2993 | break;
|
---|
2994 | }
|
---|
2995 | fInternalMsg = fInternalMsgBackup;
|
---|
2996 | return rc;
|
---|
2997 | }
|
---|
2998 | //******************************************************************************
|
---|
2999 | //******************************************************************************
|
---|
3000 | void Win32BaseWindow::CallWindowHookProc(ULONG hooktype, ULONG Msg, WPARAM wParam, LPARAM lParam, BOOL fUnicode)
|
---|
3001 | {
|
---|
3002 | CWPSTRUCT cwp;
|
---|
3003 |
|
---|
3004 | cwp.lParam = lParam;
|
---|
3005 | cwp.wParam = wParam;
|
---|
3006 | cwp.message = Msg;
|
---|
3007 | cwp.hwnd = getWindowHandle();
|
---|
3008 |
|
---|
3009 | switch(hooktype) {
|
---|
3010 | case WH_CALLWNDPROC:
|
---|
3011 | if(fUnicode) {
|
---|
3012 | HOOK_CallHooksW(WH_CALLWNDPROC, HC_ACTION, 1, (LPARAM)&cwp);
|
---|
3013 | }
|
---|
3014 | else HOOK_CallHooksA(WH_CALLWNDPROC, HC_ACTION, 1, (LPARAM)&cwp);
|
---|
3015 | break;
|
---|
3016 | }
|
---|
3017 | }
|
---|
3018 | //******************************************************************************
|
---|
3019 | //******************************************************************************
|
---|
3020 | //******************************************************************************
|
---|
3021 | //TODO: Do this more efficiently
|
---|
3022 | //******************************************************************************
|
---|
3023 | LRESULT Win32BaseWindow::BroadcastMessageA(int type, UINT msg, WPARAM wParam, LPARAM lParam)
|
---|
3024 | {
|
---|
3025 | Win32BaseWindow *window;
|
---|
3026 | HWND hwnd = WNDHANDLE_MAGIC_HIGHWORD;
|
---|
3027 |
|
---|
3028 | dprintf(("BroadCastMessageA %x %x %x", msg, wParam, lParam, GetFS()));
|
---|
3029 |
|
---|
3030 | for(int i=0;i<MAX_WINDOW_HANDLES;i++) {
|
---|
3031 | window = GetWindowFromHandle(hwnd++);
|
---|
3032 | if(window) {
|
---|
3033 | if ((window->getStyle() & WS_POPUP) || ((window->getStyle() & WS_CAPTION) == WS_CAPTION))
|
---|
3034 | {
|
---|
3035 |
|
---|
3036 | if(type == BROADCAST_SEND) {
|
---|
3037 | window->SendInternalMessageA(msg, wParam, lParam);
|
---|
3038 | }
|
---|
3039 | else PostMessageA(window->getWindowHandle(), msg, wParam, lParam);
|
---|
3040 | }
|
---|
3041 | }
|
---|
3042 | }
|
---|
3043 | return 0;
|
---|
3044 | }
|
---|
3045 | //******************************************************************************
|
---|
3046 | //TODO: Do this more efficiently
|
---|
3047 | //******************************************************************************
|
---|
3048 | LRESULT Win32BaseWindow::BroadcastMessageW(int type, UINT msg, WPARAM wParam, LPARAM lParam)
|
---|
3049 | {
|
---|
3050 | Win32BaseWindow *window;
|
---|
3051 | HWND hwnd = WNDHANDLE_MAGIC_HIGHWORD;
|
---|
3052 |
|
---|
3053 | dprintf(("BroadCastMessageW %x %x %x", msg, wParam, lParam));
|
---|
3054 |
|
---|
3055 | for(int i=0;i<MAX_WINDOW_HANDLES;i++) {
|
---|
3056 | window = GetWindowFromHandle(hwnd++);
|
---|
3057 | if(window) {
|
---|
3058 | if ((window->getStyle() & WS_POPUP) || ((window->getStyle() & WS_CAPTION) == WS_CAPTION))
|
---|
3059 | {
|
---|
3060 |
|
---|
3061 | if(type == BROADCAST_SEND) {
|
---|
3062 | window->SendInternalMessageW(msg, wParam, lParam);
|
---|
3063 | }
|
---|
3064 | else PostMessageW(window->getWindowHandle(), msg, wParam, lParam);
|
---|
3065 | }
|
---|
3066 | }
|
---|
3067 | }
|
---|
3068 | return 0;
|
---|
3069 | }
|
---|
3070 | //******************************************************************************
|
---|
3071 | //******************************************************************************
|
---|
3072 | void Win32BaseWindow::NotifyParent(UINT Msg, WPARAM wParam, LPARAM lParam)
|
---|
3073 | {
|
---|
3074 | Win32BaseWindow *window = this;
|
---|
3075 | Win32BaseWindow *parentwindow;
|
---|
3076 |
|
---|
3077 | while(window)
|
---|
3078 | {
|
---|
3079 | if(window->getStyle() & WS_CHILD && !(window->getExStyle() & WS_EX_NOPARENTNOTIFY) )
|
---|
3080 | {
|
---|
3081 | /* Notify the parent window only */
|
---|
3082 | parentwindow = window->getParent();
|
---|
3083 | if(parentwindow) {
|
---|
3084 | parentwindow->SendInternalMessageA(WM_PARENTNOTIFY, MAKEWPARAM(Msg, getWindowId()), lParam );
|
---|
3085 | }
|
---|
3086 | }
|
---|
3087 | else break;
|
---|
3088 |
|
---|
3089 | window = parentwindow;
|
---|
3090 | }
|
---|
3091 | }
|
---|
3092 | //******************************************************************************
|
---|
3093 | //******************************************************************************
|
---|
3094 | BOOL Win32BaseWindow::SetIcon(HICON hIcon)
|
---|
3095 | {
|
---|
3096 | dprintf(("Win32BaseWindow::SetIcon %x", hIcon));
|
---|
3097 | if(OSLibWinSetIcon(OS2HwndFrame, hIcon) == TRUE) {
|
---|
3098 | //TODO: Wine does't send these. Correct?
|
---|
3099 | // SendInternalMessageA(WM_SETICON, ICON_BIG, hIcon);
|
---|
3100 | return TRUE;
|
---|
3101 | }
|
---|
3102 | return FALSE;
|
---|
3103 | }
|
---|
3104 | //******************************************************************************
|
---|
3105 | //******************************************************************************
|
---|
3106 | BOOL Win32BaseWindow::ShowWindow(ULONG nCmdShow)
|
---|
3107 | {
|
---|
3108 | ULONG showstate = 0;
|
---|
3109 | HWND hWinAfter;
|
---|
3110 |
|
---|
3111 | dprintf(("ShowWindow %x %x", getWindowHandle(), nCmdShow));
|
---|
3112 | #if 1
|
---|
3113 | if (flags & WIN_NEED_SIZE)
|
---|
3114 | {
|
---|
3115 | /* should happen only in CreateWindowEx() */
|
---|
3116 | int wParam = SIZE_RESTORED;
|
---|
3117 |
|
---|
3118 | flags &= ~WIN_NEED_SIZE;
|
---|
3119 | if (dwStyle & WS_MAXIMIZE)
|
---|
3120 | wParam = SIZE_MAXIMIZED;
|
---|
3121 | else
|
---|
3122 | if (dwStyle & WS_MINIMIZE)
|
---|
3123 | wParam = SIZE_MINIMIZED;
|
---|
3124 |
|
---|
3125 | SendInternalMessageA(WM_SIZE, wParam,
|
---|
3126 | MAKELONG(rectClient.right-rectClient.left,
|
---|
3127 | rectClient.bottom-rectClient.top));
|
---|
3128 | SendInternalMessageA(WM_MOVE, 0, MAKELONG( rectClient.left, rectClient.top ) );
|
---|
3129 | }
|
---|
3130 | #else
|
---|
3131 | if(fFirstShow) {
|
---|
3132 | if(isFrameWindow() && IS_OVERLAPPED(getStyle()) && !isChild()) {
|
---|
3133 | SendInternalMessageA(WM_SIZE, SIZE_RESTORED,
|
---|
3134 | MAKELONG(rectClient.right-rectClient.left,
|
---|
3135 | rectClient.bottom-rectClient.top));
|
---|
3136 | SendInternalMessageA(WM_MOVE, 0, MAKELONG( rectClient.left, rectClient.top ) );
|
---|
3137 |
|
---|
3138 | }
|
---|
3139 | fFirstShow = FALSE;
|
---|
3140 | }
|
---|
3141 | #endif
|
---|
3142 | switch(nCmdShow)
|
---|
3143 | {
|
---|
3144 | case SW_SHOW:
|
---|
3145 | case SW_SHOWDEFAULT: //todo
|
---|
3146 | showstate = SWPOS_SHOW | SWPOS_ACTIVATE;
|
---|
3147 | break;
|
---|
3148 | case SW_HIDE:
|
---|
3149 | showstate = SWPOS_HIDE;
|
---|
3150 | break;
|
---|
3151 | case SW_RESTORE:
|
---|
3152 | showstate = SWPOS_RESTORE | SWPOS_SHOW | SWPOS_ACTIVATE;
|
---|
3153 | break;
|
---|
3154 | case SW_MINIMIZE:
|
---|
3155 | showstate = SWPOS_MINIMIZE;
|
---|
3156 | break;
|
---|
3157 | case SW_SHOWMAXIMIZED:
|
---|
3158 | showstate = SWPOS_MAXIMIZE | SWPOS_SHOW | SWPOS_ACTIVATE;
|
---|
3159 | break;
|
---|
3160 | case SW_SHOWMINIMIZED:
|
---|
3161 | showstate = SWPOS_MINIMIZE | SWPOS_SHOW | SWPOS_ACTIVATE;
|
---|
3162 | break;
|
---|
3163 | case SW_SHOWMINNOACTIVE:
|
---|
3164 | showstate = SWPOS_MINIMIZE | SWPOS_SHOW;
|
---|
3165 | break;
|
---|
3166 | case SW_SHOWNA:
|
---|
3167 | showstate = SWPOS_SHOW;
|
---|
3168 | break;
|
---|
3169 | case SW_SHOWNOACTIVATE:
|
---|
3170 | showstate = SWPOS_SHOW;
|
---|
3171 | break;
|
---|
3172 | case SW_SHOWNORMAL:
|
---|
3173 | showstate = SWPOS_RESTORE | SWPOS_ACTIVATE | SWPOS_SHOW;
|
---|
3174 | break;
|
---|
3175 | }
|
---|
3176 |
|
---|
3177 | /* We can't activate a child window (WINE) */
|
---|
3178 | if(getStyle() & WS_CHILD)
|
---|
3179 | showstate &= ~SWPOS_ACTIVATE;
|
---|
3180 |
|
---|
3181 | if(showstate & SWPOS_SHOW) {
|
---|
3182 | setStyle(getStyle() | WS_VISIBLE);
|
---|
3183 | }
|
---|
3184 | else setStyle(getStyle() & ~WS_VISIBLE);
|
---|
3185 |
|
---|
3186 | BOOL rc = OSLibWinShowWindow(OS2HwndFrame, showstate);
|
---|
3187 |
|
---|
3188 | return rc;
|
---|
3189 | }
|
---|
3190 | //******************************************************************************
|
---|
3191 | //******************************************************************************
|
---|
3192 | BOOL Win32BaseWindow::SetWindowPos(HWND hwndInsertAfter, int x, int y, int cx, int cy, UINT fuFlags)
|
---|
3193 | {
|
---|
3194 | BOOL rc = FALSE;
|
---|
3195 | Win32BaseWindow *window;
|
---|
3196 | HWND hParent = 0;
|
---|
3197 |
|
---|
3198 | dprintf (("SetWindowPos %x %x (%d,%d)(%d,%d) %x", Win32Hwnd, hwndInsertAfter, x, y, cx, cy, fuFlags));
|
---|
3199 |
|
---|
3200 | if (fuFlags &
|
---|
3201 | ~(SWP_NOSIZE | SWP_NOMOVE | SWP_NOZORDER |
|
---|
3202 | SWP_NOREDRAW | SWP_NOACTIVATE | SWP_FRAMECHANGED |
|
---|
3203 | SWP_SHOWWINDOW | SWP_HIDEWINDOW | SWP_NOCOPYBITS |
|
---|
3204 | SWP_NOOWNERZORDER))
|
---|
3205 | {
|
---|
3206 | return FALSE;
|
---|
3207 | }
|
---|
3208 |
|
---|
3209 | WINDOWPOS wpos;
|
---|
3210 | SWP swp, swpOld;
|
---|
3211 |
|
---|
3212 | wpos.flags = fuFlags;
|
---|
3213 | wpos.cy = cy;
|
---|
3214 | wpos.cx = cx;
|
---|
3215 | wpos.x = x;
|
---|
3216 | wpos.y = y;
|
---|
3217 | wpos.hwndInsertAfter = hwndInsertAfter;
|
---|
3218 | wpos.hwnd = getWindowHandle();
|
---|
3219 |
|
---|
3220 | if(~fuFlags & (SWP_NOMOVE | SWP_NOSIZE))
|
---|
3221 | {
|
---|
3222 | if (isChild())
|
---|
3223 | {
|
---|
3224 | Win32BaseWindow *windowParent = getParent();
|
---|
3225 | if(windowParent) {
|
---|
3226 | hParent = getParent()->getOS2WindowHandle();
|
---|
3227 | }
|
---|
3228 | else dprintf(("WARNING: Win32BaseWindow::SetWindowPos window %x is child but has no parent!!", getWindowHandle()));
|
---|
3229 | }
|
---|
3230 | OSLibWinQueryWindowPos(OS2HwndFrame, &swpOld);
|
---|
3231 | }
|
---|
3232 |
|
---|
3233 | OSLibMapWINDOWPOStoSWP(&wpos, &swp, &swpOld, hParent, OS2HwndFrame);
|
---|
3234 | if (swp.fl == 0)
|
---|
3235 | return TRUE;
|
---|
3236 |
|
---|
3237 | // if ((swp.fl & SWPOS_ZORDER) && (swp.hwndInsertBehind > HWNDOS_BOTTOM))
|
---|
3238 | if ((swp.hwndInsertBehind > HWNDOS_BOTTOM))
|
---|
3239 | {
|
---|
3240 | Win32BaseWindow *wndBehind = Win32BaseWindow::GetWindowFromHandle(swp.hwndInsertBehind);
|
---|
3241 | if(wndBehind) {
|
---|
3242 | swp.hwndInsertBehind = wndBehind->getOS2FrameWindowHandle();
|
---|
3243 | }
|
---|
3244 | else {
|
---|
3245 | dprintf(("ERROR: SetWindowPos: hwndInsertBehind %x invalid!",swp.hwndInsertBehind));
|
---|
3246 | swp.hwndInsertBehind = 0;
|
---|
3247 | }
|
---|
3248 | }
|
---|
3249 | //CB: todo
|
---|
3250 | #if 0
|
---|
3251 | if (isFrameWindow())
|
---|
3252 | {
|
---|
3253 | if (!isChild())
|
---|
3254 | {
|
---|
3255 | POINT maxSize, maxPos, minTrack, maxTrack;
|
---|
3256 |
|
---|
3257 | GetMinMaxInfo(&maxSize, &maxPos, &minTrack, &maxTrack);
|
---|
3258 |
|
---|
3259 | if (swp.cx > maxTrack.x) swp.cx = maxTrack.x;
|
---|
3260 | if (swp.cy > maxTrack.y) swp.cy = maxTrack.y;
|
---|
3261 | if (swp.cx < minTrack.x) swp.cx = minTrack.x;
|
---|
3262 | if (swp.cy < minTrack.y) swp.cy = minTrack.y;
|
---|
3263 | }
|
---|
3264 | swp.hwnd = OS2HwndFrame;
|
---|
3265 | }
|
---|
3266 | else
|
---|
3267 | #endif
|
---|
3268 | swp.hwnd = OS2HwndFrame;
|
---|
3269 |
|
---|
3270 | dprintf (("WinSetWindowPos %x %x (%d,%d)(%d,%d) %x", swp.hwnd, swp.hwndInsertBehind, swp.x, swp.y, swp.cx, swp.cy, swp.fl));
|
---|
3271 |
|
---|
3272 | rc = OSLibWinSetMultWindowPos(&swp, 1);
|
---|
3273 |
|
---|
3274 | if (rc == FALSE)
|
---|
3275 | {
|
---|
3276 | dprintf(("OSLibWinSetMultWindowPos failed! Error %x",OSLibWinGetLastError()));
|
---|
3277 | }
|
---|
3278 |
|
---|
3279 | if (fuFlags == SWP_FRAMECHANGED)
|
---|
3280 | {
|
---|
3281 | //CB: optimize: if frame size has changed not necessary!
|
---|
3282 | FrameUpdateFrame(this,0);
|
---|
3283 | }
|
---|
3284 |
|
---|
3285 | return (rc);
|
---|
3286 | }
|
---|
3287 | //******************************************************************************
|
---|
3288 | //TODO: WPF_RESTOREMAXIMIZED
|
---|
3289 | //******************************************************************************
|
---|
3290 | BOOL Win32BaseWindow::SetWindowPlacement(WINDOWPLACEMENT *winpos)
|
---|
3291 | {
|
---|
3292 | if(isFrameWindow())
|
---|
3293 | {
|
---|
3294 | // Set the minimized position
|
---|
3295 | if (winpos->flags & WPF_SETMINPOSITION)
|
---|
3296 | {
|
---|
3297 | OSLibSetWindowMinPos(OS2HwndFrame, winpos->ptMinPosition.x, winpos->ptMinPosition.y);
|
---|
3298 | }
|
---|
3299 |
|
---|
3300 | //TODO: Max position
|
---|
3301 |
|
---|
3302 | // Set the new restore position.
|
---|
3303 | OSLibSetWindowRestoreRect(OS2HwndFrame, &winpos->rcNormalPosition);
|
---|
3304 | }
|
---|
3305 |
|
---|
3306 | return ShowWindow(winpos->showCmd);
|
---|
3307 | }
|
---|
3308 | //******************************************************************************
|
---|
3309 | //Also destroys all the child windows (destroy children first, parent last)
|
---|
3310 | //******************************************************************************
|
---|
3311 | BOOL Win32BaseWindow::DestroyWindow()
|
---|
3312 | {
|
---|
3313 | /* Call hooks */
|
---|
3314 | if(HOOK_CallHooksA( WH_CBT, HCBT_DESTROYWND, getWindowHandle(), 0L))
|
---|
3315 | {
|
---|
3316 | return FALSE;
|
---|
3317 | }
|
---|
3318 |
|
---|
3319 | if(!(getStyle() & WS_CHILD) && getOwner() == NULL)
|
---|
3320 | {
|
---|
3321 | HOOK_CallHooksA(WH_SHELL, HSHELL_WINDOWDESTROYED, getWindowHandle(), 0L);
|
---|
3322 | /* FIXME: clean up palette - see "Internals" p.352 */
|
---|
3323 | }
|
---|
3324 |
|
---|
3325 | if((getStyle() & WS_CHILD) && !(getExStyle() & WS_EX_NOPARENTNOTIFY))
|
---|
3326 | {
|
---|
3327 | if(getParent())
|
---|
3328 | {
|
---|
3329 | /* Notify the parent window only */
|
---|
3330 | getParent()->SendMessageA(WM_PARENTNOTIFY, MAKEWPARAM(WM_DESTROY, getWindowId()), (LPARAM)getWindowHandle());
|
---|
3331 | if( !::IsWindow(getWindowHandle()) )
|
---|
3332 | {
|
---|
3333 | return TRUE;
|
---|
3334 | }
|
---|
3335 | }
|
---|
3336 | else DebugInt3();
|
---|
3337 | }
|
---|
3338 | fDestroyWindowCalled = TRUE;
|
---|
3339 | return OSLibWinDestroyWindow(OS2HwndFrame);
|
---|
3340 | }
|
---|
3341 | //******************************************************************************
|
---|
3342 | //******************************************************************************
|
---|
3343 | Win32BaseWindow *Win32BaseWindow::getParent()
|
---|
3344 | {
|
---|
3345 | Win32BaseWindow *wndparent = (Win32BaseWindow *)ChildWindow::GetParent();
|
---|
3346 | return ((ULONG)wndparent == (ULONG)windowDesktop) ? NULL : wndparent;
|
---|
3347 | }
|
---|
3348 | //******************************************************************************
|
---|
3349 | //******************************************************************************
|
---|
3350 | HWND Win32BaseWindow::GetParent()
|
---|
3351 | {
|
---|
3352 | Win32BaseWindow *wndparent;
|
---|
3353 |
|
---|
3354 | if ((!(getStyle() & (WS_POPUP|WS_CHILD))))
|
---|
3355 | {
|
---|
3356 | return 0;
|
---|
3357 | }
|
---|
3358 | wndparent = ((getStyle() & WS_CHILD) ? getParent() : getOwner());
|
---|
3359 |
|
---|
3360 | return (wndparent) ? wndparent->getWindowHandle() : 0;
|
---|
3361 | }
|
---|
3362 | //******************************************************************************
|
---|
3363 | //******************************************************************************
|
---|
3364 | HWND Win32BaseWindow::SetParent(HWND hwndNewParent)
|
---|
3365 | {
|
---|
3366 | HWND oldhwnd;
|
---|
3367 | Win32BaseWindow *newparent;
|
---|
3368 |
|
---|
3369 | if(getParent()) {
|
---|
3370 | oldhwnd = getParent()->getWindowHandle();
|
---|
3371 | getParent()->RemoveChild(this);
|
---|
3372 | }
|
---|
3373 | else oldhwnd = 0;
|
---|
3374 |
|
---|
3375 | newparent = GetWindowFromHandle(hwndNewParent);
|
---|
3376 | if(newparent)
|
---|
3377 | {
|
---|
3378 | setParent(newparent);
|
---|
3379 | getParent()->AddChild(this);
|
---|
3380 | OSLibWinSetParent(getOS2FrameWindowHandle(), getParent()->getOS2WindowHandle());
|
---|
3381 | return oldhwnd;
|
---|
3382 | }
|
---|
3383 | else {
|
---|
3384 | setParent(windowDesktop);
|
---|
3385 | windowDesktop->AddChild(this);
|
---|
3386 | OSLibWinSetParent(getOS2FrameWindowHandle(), OSLIB_HWND_DESKTOP);
|
---|
3387 | return oldhwnd;
|
---|
3388 | }
|
---|
3389 | }
|
---|
3390 | //******************************************************************************
|
---|
3391 | //******************************************************************************
|
---|
3392 | BOOL Win32BaseWindow::IsChild(HWND hwndParent)
|
---|
3393 | {
|
---|
3394 | if(getParent()) {
|
---|
3395 | return getParent()->getWindowHandle() == hwndParent;
|
---|
3396 | }
|
---|
3397 | else return 0;
|
---|
3398 | }
|
---|
3399 | //******************************************************************************
|
---|
3400 | //******************************************************************************
|
---|
3401 | HWND Win32BaseWindow::GetTopWindow()
|
---|
3402 | {
|
---|
3403 | return GetWindow(GW_CHILD);
|
---|
3404 | }
|
---|
3405 | //******************************************************************************
|
---|
3406 | // Get the top-level parent for a child window.
|
---|
3407 | //******************************************************************************
|
---|
3408 | Win32BaseWindow *Win32BaseWindow::GetTopParent()
|
---|
3409 | {
|
---|
3410 | Win32BaseWindow *window = this;
|
---|
3411 |
|
---|
3412 | while(window && (window->getStyle() & WS_CHILD))
|
---|
3413 | {
|
---|
3414 | window = window->getParent();
|
---|
3415 | }
|
---|
3416 | return window;
|
---|
3417 | }
|
---|
3418 | //******************************************************************************
|
---|
3419 | //Don't call WinUpdateWindow as that one also updates the child windows
|
---|
3420 | //Also need to send WM_PAINT directly to the window procedure, which doesn't
|
---|
3421 | //always happen with WinUpdateWindow (could be posted if thread doesn't own window)
|
---|
3422 | //******************************************************************************
|
---|
3423 | BOOL Win32BaseWindow::UpdateWindow()
|
---|
3424 | {
|
---|
3425 | RECT rect;
|
---|
3426 |
|
---|
3427 | if(OSLibWinQueryUpdateRect(OS2Hwnd, &rect))
|
---|
3428 | {//update region not empty
|
---|
3429 | HDC hdc;
|
---|
3430 |
|
---|
3431 | hdc = O32_GetDC(OS2Hwnd);
|
---|
3432 | if (isIcon)
|
---|
3433 | {
|
---|
3434 | SendInternalMessageA(WM_ICONERASEBKGND, (WPARAM)hdc, 0);
|
---|
3435 | SendInternalMessageA(WM_PAINTICON, 0, 0);
|
---|
3436 | }
|
---|
3437 | else
|
---|
3438 | {
|
---|
3439 | SendInternalMessageA(WM_ERASEBKGND, (WPARAM)hdc, 0);
|
---|
3440 | SendInternalMessageA(WM_PAINT, 0, 0);
|
---|
3441 | }
|
---|
3442 | O32_ReleaseDC(OS2Hwnd, hdc);
|
---|
3443 | }
|
---|
3444 | return TRUE;
|
---|
3445 | }
|
---|
3446 | //******************************************************************************
|
---|
3447 | //******************************************************************************
|
---|
3448 | BOOL Win32BaseWindow::IsIconic()
|
---|
3449 | {
|
---|
3450 | return OSLibWinIsIconic(OS2Hwnd);
|
---|
3451 | }
|
---|
3452 | //******************************************************************************
|
---|
3453 | //TODO: Should not enumerate children that are created during the enumeration!
|
---|
3454 | //******************************************************************************
|
---|
3455 | BOOL Win32BaseWindow::EnumChildWindows(WNDENUMPROC lpfn, LPARAM lParam)
|
---|
3456 | {
|
---|
3457 | BOOL rc = TRUE;
|
---|
3458 | HWND hwnd;
|
---|
3459 | Win32BaseWindow *prevchild = 0, *child = 0;
|
---|
3460 |
|
---|
3461 | dprintf(("EnumChildWindows of %x parameter %x %x (%x)", getWindowHandle(), lpfn, lParam, getFirstChild()));
|
---|
3462 | for (child = (Win32BaseWindow *)getFirstChild(); child; child = (Win32BaseWindow *)child->getNextChild())
|
---|
3463 | {
|
---|
3464 | dprintf(("EnumChildWindows: enumerating child %x", child->getWindowHandle()));
|
---|
3465 | hwnd = child->getWindowHandle();
|
---|
3466 | if(child->getOwner()) {
|
---|
3467 | continue; //shouldn't have an owner (Wine)
|
---|
3468 | }
|
---|
3469 | if(lpfn(hwnd, lParam) == FALSE)
|
---|
3470 | {
|
---|
3471 | rc = FALSE;
|
---|
3472 | break;
|
---|
3473 | }
|
---|
3474 | //check if the window still exists
|
---|
3475 | if(!::IsWindow(hwnd))
|
---|
3476 | {
|
---|
3477 | child = prevchild;
|
---|
3478 | continue;
|
---|
3479 | }
|
---|
3480 | if(child->getFirstChild() != NULL)
|
---|
3481 | {
|
---|
3482 | dprintf(("EnumChildWindows: Enumerate children of %x", child->getWindowHandle()));
|
---|
3483 | if(child->EnumChildWindows(lpfn, lParam) == FALSE)
|
---|
3484 | {
|
---|
3485 | rc = FALSE;
|
---|
3486 | break;
|
---|
3487 | }
|
---|
3488 | }
|
---|
3489 | prevchild = child;
|
---|
3490 | }
|
---|
3491 | return rc;
|
---|
3492 | }
|
---|
3493 | //******************************************************************************
|
---|
3494 | //Enumerate first-level children only and check thread id
|
---|
3495 | //******************************************************************************
|
---|
3496 | BOOL Win32BaseWindow::EnumThreadWindows(DWORD dwThreadId, WNDENUMPROC lpfn, LPARAM lParam)
|
---|
3497 | {
|
---|
3498 | Win32BaseWindow *child = 0;
|
---|
3499 | ULONG tid, pid;
|
---|
3500 | BOOL rc;
|
---|
3501 | HWND hwnd;
|
---|
3502 |
|
---|
3503 | dprintf(("EnumThreadWindows %x %x %x", dwThreadId, lpfn, lParam));
|
---|
3504 |
|
---|
3505 | for (child = (Win32BaseWindow *)getFirstChild(); child; child = (Win32BaseWindow *)child->getNextChild())
|
---|
3506 | {
|
---|
3507 | OSLibWinQueryWindowProcess(child->getOS2WindowHandle(), &pid, &tid);
|
---|
3508 |
|
---|
3509 | if(dwThreadId == tid) {
|
---|
3510 | dprintf2(("EnumThreadWindows: Found Window %x", child->getWindowHandle()));
|
---|
3511 | if((rc = lpfn(child->getWindowHandle(), lParam)) == FALSE) {
|
---|
3512 | break;
|
---|
3513 | }
|
---|
3514 | }
|
---|
3515 | }
|
---|
3516 | return TRUE;
|
---|
3517 | }
|
---|
3518 | //******************************************************************************
|
---|
3519 | //Enumerate first-level children only
|
---|
3520 | //******************************************************************************
|
---|
3521 | BOOL Win32BaseWindow::EnumWindows(WNDENUMPROC lpfn, LPARAM lParam)
|
---|
3522 | {
|
---|
3523 | Win32BaseWindow *child = 0;
|
---|
3524 | BOOL rc;
|
---|
3525 | HWND hwnd;
|
---|
3526 |
|
---|
3527 | dprintf(("EnumWindows %x %x", lpfn, lParam));
|
---|
3528 |
|
---|
3529 | for (child = (Win32BaseWindow *)getFirstChild(); child; child = (Win32BaseWindow *)child->getNextChild())
|
---|
3530 | {
|
---|
3531 | hwnd = child->getWindowHandle();
|
---|
3532 |
|
---|
3533 | dprintf2(("EnumWindows: Found Window %x", child->getWindowHandle()));
|
---|
3534 | if((rc = lpfn(child->getWindowHandle(), lParam)) == FALSE) {
|
---|
3535 | break;
|
---|
3536 | }
|
---|
3537 | }
|
---|
3538 | return TRUE;
|
---|
3539 | }
|
---|
3540 | //******************************************************************************
|
---|
3541 | //******************************************************************************
|
---|
3542 | Win32BaseWindow *Win32BaseWindow::FindWindowById(int id)
|
---|
3543 | {
|
---|
3544 | for (Win32BaseWindow *child = (Win32BaseWindow *)getFirstChild(); child; child = (Win32BaseWindow *)child->getNextChild())
|
---|
3545 | {
|
---|
3546 | if (child->getWindowId() == id)
|
---|
3547 | {
|
---|
3548 | return child;
|
---|
3549 | }
|
---|
3550 | }
|
---|
3551 | return 0;
|
---|
3552 | }
|
---|
3553 | //******************************************************************************
|
---|
3554 | //TODO:
|
---|
3555 | //We assume (for now) that if hwndParent or hwndChildAfter are real window handles, that
|
---|
3556 | //the current process owns them.
|
---|
3557 | //******************************************************************************
|
---|
3558 | HWND Win32BaseWindow::FindWindowEx(HWND hwndParent, HWND hwndChildAfter, LPSTR lpszClass, LPSTR lpszWindow,
|
---|
3559 | BOOL fUnicode)
|
---|
3560 | {
|
---|
3561 | Win32BaseWindow *parent = GetWindowFromHandle(hwndParent);
|
---|
3562 | Win32BaseWindow *child = GetWindowFromHandle(hwndChildAfter);
|
---|
3563 |
|
---|
3564 | if((hwndParent != OSLIB_HWND_DESKTOP && !parent) ||
|
---|
3565 | (hwndChildAfter != 0 && !child) ||
|
---|
3566 | (hwndParent == OSLIB_HWND_DESKTOP && hwndChildAfter != 0))
|
---|
3567 | {
|
---|
3568 | dprintf(("Win32BaseWindow::FindWindowEx: parent or child not found %x %x", hwndParent, hwndChildAfter));
|
---|
3569 | SetLastError(ERROR_INVALID_WINDOW_HANDLE);
|
---|
3570 | return 0;
|
---|
3571 | }
|
---|
3572 | if(hwndParent != OSLIB_HWND_DESKTOP)
|
---|
3573 | {//if the current process owns the window, just do a quick search
|
---|
3574 | child = (Win32BaseWindow *)parent->getFirstChild();
|
---|
3575 | if(hwndChildAfter != 0)
|
---|
3576 | {
|
---|
3577 | while(child)
|
---|
3578 | {
|
---|
3579 | if(child->getWindowHandle() == hwndChildAfter)
|
---|
3580 | {
|
---|
3581 | child = (Win32BaseWindow *)child->getNextChild();
|
---|
3582 | break;
|
---|
3583 | }
|
---|
3584 | child = (Win32BaseWindow *)child->getNextChild();
|
---|
3585 | }
|
---|
3586 | }
|
---|
3587 | while(child)
|
---|
3588 | {
|
---|
3589 | if(child->getWindowClass()->hasClassName(lpszClass, fUnicode) &&
|
---|
3590 | (!lpszWindow || child->hasWindowName(lpszWindow, fUnicode)))
|
---|
3591 | {
|
---|
3592 | dprintf(("FindWindowEx: Found window %x", child->getWindowHandle()));
|
---|
3593 | return child->getWindowHandle();
|
---|
3594 | }
|
---|
3595 | child = (Win32BaseWindow *)child->getNextChild();
|
---|
3596 | }
|
---|
3597 | }
|
---|
3598 | else {
|
---|
3599 | Win32BaseWindow *wnd;
|
---|
3600 | HWND henum, hwnd;
|
---|
3601 |
|
---|
3602 | henum = OSLibWinBeginEnumWindows(OSLIB_HWND_DESKTOP);
|
---|
3603 | hwnd = OSLibWinGetNextWindow(henum);
|
---|
3604 |
|
---|
3605 | while(hwnd)
|
---|
3606 | {
|
---|
3607 | wnd = GetWindowFromOS2Handle(hwnd);
|
---|
3608 | if(wnd == NULL) {
|
---|
3609 | hwnd = OSLibWinQueryClientWindow(hwnd);
|
---|
3610 | if(hwnd) wnd = GetWindowFromOS2Handle(hwnd);
|
---|
3611 | if(!hwnd) wnd = GetWindowFromOS2FrameHandle(hwnd);
|
---|
3612 | }
|
---|
3613 |
|
---|
3614 | if(wnd) {
|
---|
3615 | if(wnd->getWindowClass()->hasClassName(lpszClass, fUnicode) &&
|
---|
3616 | (!lpszWindow || wnd->hasWindowName(lpszWindow, fUnicode)))
|
---|
3617 | {
|
---|
3618 | OSLibWinEndEnumWindows(henum);
|
---|
3619 | dprintf(("FindWindowEx: Found window %x", wnd->getWindowHandle()));
|
---|
3620 | return wnd->getWindowHandle();
|
---|
3621 | }
|
---|
3622 | }
|
---|
3623 | hwnd = OSLibWinGetNextWindow(henum);
|
---|
3624 | }
|
---|
3625 | OSLibWinEndEnumWindows(henum);
|
---|
3626 | }
|
---|
3627 | SetLastError(ERROR_CANNOT_FIND_WND_CLASS); //TODO: not always correct
|
---|
3628 | return 0;
|
---|
3629 | }
|
---|
3630 | //******************************************************************************
|
---|
3631 | //******************************************************************************
|
---|
3632 | HWND Win32BaseWindow::GetWindow(UINT uCmd)
|
---|
3633 | {
|
---|
3634 | HWND hwndRelated = 0;
|
---|
3635 | Win32BaseWindow *window;
|
---|
3636 |
|
---|
3637 | switch(uCmd)
|
---|
3638 | {
|
---|
3639 | case GW_HWNDFIRST:
|
---|
3640 | if(getParent()) {
|
---|
3641 | window = (Win32BaseWindow *)getParent()->getFirstChild();
|
---|
3642 | hwndRelated = window->getWindowHandle();
|
---|
3643 | }
|
---|
3644 | break;
|
---|
3645 |
|
---|
3646 | case GW_HWNDLAST:
|
---|
3647 | if(!getParent())
|
---|
3648 | {
|
---|
3649 | goto end;
|
---|
3650 | }
|
---|
3651 |
|
---|
3652 | window = this;
|
---|
3653 | while(window->getNextChild())
|
---|
3654 | {
|
---|
3655 | window = (Win32BaseWindow *)window->getNextChild();
|
---|
3656 | }
|
---|
3657 | hwndRelated = window->getWindowHandle();
|
---|
3658 | break;
|
---|
3659 |
|
---|
3660 | case GW_HWNDNEXT:
|
---|
3661 | window = (Win32BaseWindow *)getNextChild();
|
---|
3662 | if(window) {
|
---|
3663 | hwndRelated = window->getWindowHandle();
|
---|
3664 | }
|
---|
3665 | break;
|
---|
3666 |
|
---|
3667 | case GW_HWNDPREV:
|
---|
3668 | if(!getParent())
|
---|
3669 | {
|
---|
3670 | goto end;
|
---|
3671 | }
|
---|
3672 | window = (Win32BaseWindow *)(getParent()->getFirstChild()); /* First sibling */
|
---|
3673 | if(window == this)
|
---|
3674 | {
|
---|
3675 | hwndRelated = 0; /* First in list */
|
---|
3676 | goto end;
|
---|
3677 | }
|
---|
3678 | while(window->getNextChild())
|
---|
3679 | {
|
---|
3680 | if (window->getNextChild() == this)
|
---|
3681 | {
|
---|
3682 | hwndRelated = window->getWindowHandle();
|
---|
3683 | goto end;
|
---|
3684 | }
|
---|
3685 | window = (Win32BaseWindow *)window->getNextChild();
|
---|
3686 | }
|
---|
3687 | break;
|
---|
3688 |
|
---|
3689 | case GW_OWNER:
|
---|
3690 | if(getOwner()) {
|
---|
3691 | hwndRelated = getOwner()->getWindowHandle();
|
---|
3692 | }
|
---|
3693 | break;
|
---|
3694 |
|
---|
3695 | case GW_CHILD:
|
---|
3696 | if(getFirstChild()) {
|
---|
3697 | hwndRelated = ((Win32BaseWindow *)getFirstChild())->getWindowHandle();
|
---|
3698 | }
|
---|
3699 | break;
|
---|
3700 | }
|
---|
3701 | end:
|
---|
3702 | dprintf(("GetWindow %x %d returned %x", getWindowHandle(), uCmd, hwndRelated));
|
---|
3703 | return hwndRelated;
|
---|
3704 | }
|
---|
3705 | //******************************************************************************
|
---|
3706 | //******************************************************************************
|
---|
3707 | HWND Win32BaseWindow::SetActiveWindow()
|
---|
3708 | {
|
---|
3709 | HWND hwndActive;
|
---|
3710 | Win32BaseWindow *win32wnd;
|
---|
3711 | ULONG magic;
|
---|
3712 |
|
---|
3713 | hwndActive = OSLibWinSetActiveWindow(OS2HwndFrame);
|
---|
3714 | win32wnd = (Win32BaseWindow *)OSLibWinGetWindowULong(hwndActive, OFFSET_WIN32WNDPTR);
|
---|
3715 | magic = OSLibWinGetWindowULong(hwndActive, OFFSET_WIN32PM_MAGIC);
|
---|
3716 | if(CheckMagicDword(magic) && win32wnd)
|
---|
3717 | {
|
---|
3718 | return win32wnd->getWindowHandle();
|
---|
3719 | }
|
---|
3720 | return 0;
|
---|
3721 | }
|
---|
3722 | //******************************************************************************
|
---|
3723 | //WM_ENABLE is sent to hwnd, but not to it's children (as it should be)
|
---|
3724 | //******************************************************************************
|
---|
3725 | BOOL Win32BaseWindow::EnableWindow(BOOL fEnable)
|
---|
3726 | {
|
---|
3727 | return OSLibWinEnableWindow(OS2HwndFrame, fEnable);
|
---|
3728 | }
|
---|
3729 | //******************************************************************************
|
---|
3730 | //******************************************************************************
|
---|
3731 | BOOL Win32BaseWindow::CloseWindow()
|
---|
3732 | {
|
---|
3733 | return OSLibWinMinimizeWindow(OS2HwndFrame);
|
---|
3734 | }
|
---|
3735 | //******************************************************************************
|
---|
3736 | //******************************************************************************
|
---|
3737 | HWND Win32BaseWindow::GetActiveWindow()
|
---|
3738 | {
|
---|
3739 | HWND hwndActive;
|
---|
3740 | Win32BaseWindow *win32wnd;
|
---|
3741 | ULONG magic;
|
---|
3742 |
|
---|
3743 | hwndActive = OSLibWinQueryActiveWindow();
|
---|
3744 |
|
---|
3745 | return OS2ToWin32Handle(hwndActive);
|
---|
3746 | }
|
---|
3747 | //******************************************************************************
|
---|
3748 | //******************************************************************************
|
---|
3749 | BOOL Win32BaseWindow::IsWindowEnabled()
|
---|
3750 | {
|
---|
3751 | return OSLibWinIsWindowEnabled(OS2HwndFrame);
|
---|
3752 | }
|
---|
3753 | //******************************************************************************
|
---|
3754 | //******************************************************************************
|
---|
3755 | BOOL Win32BaseWindow::IsWindowVisible()
|
---|
3756 | {
|
---|
3757 | #if 1
|
---|
3758 | return (dwStyle & WS_VISIBLE) == WS_VISIBLE;
|
---|
3759 | #else
|
---|
3760 | return OSLibWinIsWindowVisible(OS2HwndFrame);
|
---|
3761 | #endif
|
---|
3762 | }
|
---|
3763 | //******************************************************************************
|
---|
3764 | //******************************************************************************
|
---|
3765 | BOOL Win32BaseWindow::GetWindowRect(PRECT pRect)
|
---|
3766 | {
|
---|
3767 | return OSLibWinQueryWindowRect(OS2HwndFrame, pRect, RELATIVE_TO_SCREEN);
|
---|
3768 | }
|
---|
3769 | //******************************************************************************
|
---|
3770 | //******************************************************************************
|
---|
3771 | BOOL Win32BaseWindow::hasWindowName(LPSTR wndname, BOOL fUnicode)
|
---|
3772 | {
|
---|
3773 | INT len = GetWindowTextLength();
|
---|
3774 | BOOL res;
|
---|
3775 |
|
---|
3776 | if (wndname == NULL)
|
---|
3777 | return (len == 0);
|
---|
3778 |
|
---|
3779 | len++;
|
---|
3780 | if (fUnicode)
|
---|
3781 | {
|
---|
3782 | WCHAR *text = (WCHAR*)malloc(len*sizeof(WCHAR));
|
---|
3783 |
|
---|
3784 | GetWindowTextW(text,len);
|
---|
3785 | res = (lstrcmpW(text,(LPWSTR)wndname) == 0);
|
---|
3786 | free(text);
|
---|
3787 | } else
|
---|
3788 | {
|
---|
3789 | CHAR *text = (CHAR*)malloc(len*sizeof(CHAR));
|
---|
3790 |
|
---|
3791 | GetWindowTextA(text,len);
|
---|
3792 | res = (strcmp(text,wndname) == 0);
|
---|
3793 | free(text);
|
---|
3794 | }
|
---|
3795 |
|
---|
3796 | return res;
|
---|
3797 | }
|
---|
3798 | //******************************************************************************
|
---|
3799 | //******************************************************************************
|
---|
3800 | CHAR *Win32BaseWindow::getWindowNamePtrA()
|
---|
3801 | {
|
---|
3802 | INT len = GetWindowTextLength();
|
---|
3803 | CHAR *text;
|
---|
3804 |
|
---|
3805 | if (len == 0) return NULL;
|
---|
3806 | len++;
|
---|
3807 | text = (CHAR*)malloc(len*sizeof(CHAR));
|
---|
3808 | GetWindowTextA(text,len);
|
---|
3809 |
|
---|
3810 | return text;
|
---|
3811 | }
|
---|
3812 | //******************************************************************************
|
---|
3813 | //******************************************************************************
|
---|
3814 | WCHAR *Win32BaseWindow::getWindowNamePtrW()
|
---|
3815 | {
|
---|
3816 | INT len = GetWindowTextLength();
|
---|
3817 | WCHAR *text;
|
---|
3818 |
|
---|
3819 | if (len == 0) return NULL;
|
---|
3820 | len++;
|
---|
3821 | text = (WCHAR*)malloc(len*sizeof(WCHAR));
|
---|
3822 | GetWindowTextW(text,len);
|
---|
3823 |
|
---|
3824 | return text;
|
---|
3825 | }
|
---|
3826 | //******************************************************************************
|
---|
3827 | //******************************************************************************
|
---|
3828 | VOID Win32BaseWindow::freeWindowNamePtr(PVOID namePtr)
|
---|
3829 | {
|
---|
3830 | if (namePtr) free(namePtr);
|
---|
3831 | }
|
---|
3832 | //******************************************************************************
|
---|
3833 | //******************************************************************************
|
---|
3834 | int Win32BaseWindow::GetWindowTextLength()
|
---|
3835 | {
|
---|
3836 | return SendInternalMessageA(WM_GETTEXTLENGTH,0,0);
|
---|
3837 | }
|
---|
3838 | //******************************************************************************
|
---|
3839 | //******************************************************************************
|
---|
3840 | int Win32BaseWindow::GetWindowTextA(LPSTR lpsz, int cch)
|
---|
3841 | {
|
---|
3842 | return SendInternalMessageA(WM_GETTEXT,(WPARAM)cch,(LPARAM)lpsz);
|
---|
3843 | }
|
---|
3844 | //******************************************************************************
|
---|
3845 | //******************************************************************************
|
---|
3846 | int Win32BaseWindow::GetWindowTextW(LPWSTR lpsz, int cch)
|
---|
3847 | {
|
---|
3848 | return SendInternalMessageW(WM_GETTEXT,(WPARAM)cch,(LPARAM)lpsz);
|
---|
3849 | }
|
---|
3850 | //******************************************************************************
|
---|
3851 | //******************************************************************************
|
---|
3852 | BOOL Win32BaseWindow::SetWindowTextA(LPSTR lpsz)
|
---|
3853 | {
|
---|
3854 | return SendInternalMessageA(WM_SETTEXT,0,(LPARAM)lpsz);
|
---|
3855 | }
|
---|
3856 | //******************************************************************************
|
---|
3857 | //******************************************************************************
|
---|
3858 | BOOL Win32BaseWindow::SetWindowTextW(LPWSTR lpsz)
|
---|
3859 | {
|
---|
3860 | return SendInternalMessageW(WM_SETTEXT,0,(LPARAM)lpsz);
|
---|
3861 | }
|
---|
3862 | //******************************************************************************
|
---|
3863 | //******************************************************************************
|
---|
3864 | VOID Win32BaseWindow::updateWindowStyle(DWORD oldExStyle,DWORD oldStyle)
|
---|
3865 | {
|
---|
3866 | if(IsWindowDestroyed()) return;
|
---|
3867 |
|
---|
3868 | //CB: todo: dwExStyle, creating new frame controls, destroy not used controls, WS_VISIBLE, WS_CHILD, ...
|
---|
3869 | // write test cases
|
---|
3870 | if ((dwStyle & 0xFFFF0000) != (oldStyle & 0xFFFF0000))
|
---|
3871 | {
|
---|
3872 | //dprintf(("updateWindowStyle: %x %x",oldStyle,dwStyle));
|
---|
3873 | OSLibSetWindowStyle(OS2HwndFrame, dwStyle, fTaskList);
|
---|
3874 | }
|
---|
3875 | }
|
---|
3876 | //******************************************************************************
|
---|
3877 | //******************************************************************************
|
---|
3878 | LONG Win32BaseWindow::SetWindowLongA(int index, ULONG value, BOOL fUnicode)
|
---|
3879 | {
|
---|
3880 | LONG oldval;
|
---|
3881 |
|
---|
3882 | dprintf2(("SetWindowLong%c %x %d %x", (fUnicode) ? 'W' : 'A', getWindowHandle(), index, value));
|
---|
3883 | switch(index) {
|
---|
3884 | case GWL_EXSTYLE:
|
---|
3885 | {
|
---|
3886 | STYLESTRUCT ss;
|
---|
3887 |
|
---|
3888 | if(dwExStyle == value)
|
---|
3889 | return value;
|
---|
3890 |
|
---|
3891 | ss.styleOld = dwExStyle;
|
---|
3892 | ss.styleNew = value;
|
---|
3893 | dprintf(("SetWindowLong GWL_EXSTYLE %x old %x new style %x", getWindowHandle(), dwExStyle, value));
|
---|
3894 | SendInternalMessageA(WM_STYLECHANGING,GWL_EXSTYLE,(LPARAM)&ss);
|
---|
3895 | setExStyle(ss.styleNew);
|
---|
3896 | updateWindowStyle(ss.styleOld,getStyle());
|
---|
3897 | SendInternalMessageA(WM_STYLECHANGED,GWL_EXSTYLE,(LPARAM)&ss);
|
---|
3898 | return ss.styleOld;
|
---|
3899 | }
|
---|
3900 | case GWL_STYLE:
|
---|
3901 | {
|
---|
3902 | STYLESTRUCT ss;
|
---|
3903 |
|
---|
3904 | if(dwStyle == value)
|
---|
3905 | return value;
|
---|
3906 |
|
---|
3907 | value &= ~(WS_VISIBLE | WS_CHILD); /* Some bits can't be changed this way (WINE) */
|
---|
3908 | ss.styleOld = getStyle();
|
---|
3909 | ss.styleNew = value | (ss.styleOld & (WS_VISIBLE | WS_CHILD));
|
---|
3910 | dprintf(("SetWindowLong GWL_STYLE %x old %x new style %x", getWindowHandle(), ss.styleOld, ss.styleNew));
|
---|
3911 | SendInternalMessageA(WM_STYLECHANGING,GWL_STYLE,(LPARAM)&ss);
|
---|
3912 | setStyle(ss.styleNew);
|
---|
3913 | updateWindowStyle(dwExStyle,ss.styleOld);
|
---|
3914 | SendInternalMessageA(WM_STYLECHANGED,GWL_STYLE,(LPARAM)&ss);
|
---|
3915 | #ifdef DEBUG
|
---|
3916 | PrintWindowStyle(ss.styleNew, 0);
|
---|
3917 | #endif
|
---|
3918 | return ss.styleOld;
|
---|
3919 | }
|
---|
3920 | case GWL_WNDPROC:
|
---|
3921 | oldval = (LONG)WINPROC_GetProc(win32wndproc, (fUnicode) ? WIN_PROC_32W : WIN_PROC_32A);
|
---|
3922 | //WINPROC_SetProc((HWINDOWPROC *)&win32wndproc, (WNDPROC)value, (fUnicode) ? WIN_PROC_32W : WIN_PROC_32A, WIN_PROC_WINDOW);
|
---|
3923 | WINPROC_SetProc((HWINDOWPROC *)&win32wndproc, (WNDPROC)value, WINPROC_GetProcType(win32wndproc), WIN_PROC_WINDOW);
|
---|
3924 | return oldval;
|
---|
3925 | case GWL_HINSTANCE:
|
---|
3926 | oldval = hInstance;
|
---|
3927 | hInstance = value;
|
---|
3928 | return oldval;
|
---|
3929 | case GWL_HWNDPARENT:
|
---|
3930 | return SetParent((HWND)value);
|
---|
3931 | case GWL_ID:
|
---|
3932 | oldval = getWindowId();
|
---|
3933 | setWindowId(value);
|
---|
3934 | return oldval;
|
---|
3935 | case GWL_USERDATA:
|
---|
3936 | oldval = userData;
|
---|
3937 | userData = value;
|
---|
3938 | return oldval;
|
---|
3939 | default:
|
---|
3940 | if(index >= 0 && index/4 < nrUserWindowLong)
|
---|
3941 | {
|
---|
3942 | oldval = userWindowLong[index/4];
|
---|
3943 | userWindowLong[index/4] = value;
|
---|
3944 | return oldval;
|
---|
3945 | }
|
---|
3946 | SetLastError(ERROR_INVALID_PARAMETER);
|
---|
3947 | return 0;
|
---|
3948 | }
|
---|
3949 | }
|
---|
3950 | //******************************************************************************
|
---|
3951 | //******************************************************************************
|
---|
3952 | ULONG Win32BaseWindow::GetWindowLongA(int index, BOOL fUnicode)
|
---|
3953 | {
|
---|
3954 | ULONG value;
|
---|
3955 |
|
---|
3956 | switch(index) {
|
---|
3957 | case GWL_EXSTYLE:
|
---|
3958 | value = dwExStyle;
|
---|
3959 | break;
|
---|
3960 | case GWL_STYLE:
|
---|
3961 | value = dwStyle;
|
---|
3962 | break;
|
---|
3963 | case GWL_WNDPROC:
|
---|
3964 | value = (LONG)WINPROC_GetProc(win32wndproc, (fUnicode) ? WIN_PROC_32W : WIN_PROC_32A);
|
---|
3965 | break;
|
---|
3966 | case GWL_HINSTANCE:
|
---|
3967 | value = hInstance;
|
---|
3968 | break;
|
---|
3969 | case GWL_HWNDPARENT:
|
---|
3970 | if(getParent()) {
|
---|
3971 | value = getParent()->getWindowHandle();
|
---|
3972 | }
|
---|
3973 | else value = 0;
|
---|
3974 | break;
|
---|
3975 | case GWL_ID:
|
---|
3976 | value = getWindowId();
|
---|
3977 | break;
|
---|
3978 | case GWL_USERDATA:
|
---|
3979 | value = userData;
|
---|
3980 | break;
|
---|
3981 | default:
|
---|
3982 | if(index >= 0 && index/4 < nrUserWindowLong)
|
---|
3983 | {
|
---|
3984 | value = userWindowLong[index/4];
|
---|
3985 | break;
|
---|
3986 | }
|
---|
3987 | SetLastError(ERROR_INVALID_PARAMETER);
|
---|
3988 | return 0;
|
---|
3989 | }
|
---|
3990 | dprintf2(("GetWindowLongA %x %d %x", getWindowHandle(), index, value));
|
---|
3991 | return value;
|
---|
3992 | }
|
---|
3993 | //******************************************************************************
|
---|
3994 | //******************************************************************************
|
---|
3995 | WORD Win32BaseWindow::SetWindowWord(int index, WORD value)
|
---|
3996 | {
|
---|
3997 | WORD oldval;
|
---|
3998 |
|
---|
3999 | if(index >= 0 && index/4 < nrUserWindowLong)
|
---|
4000 | {
|
---|
4001 | oldval = ((WORD *)userWindowLong)[index/2];
|
---|
4002 | ((WORD *)userWindowLong)[index/2] = value;
|
---|
4003 | return oldval;
|
---|
4004 | }
|
---|
4005 | SetLastError(ERROR_INVALID_PARAMETER);
|
---|
4006 | return 0;
|
---|
4007 | }
|
---|
4008 | //******************************************************************************
|
---|
4009 | //******************************************************************************
|
---|
4010 | WORD Win32BaseWindow::GetWindowWord(int index)
|
---|
4011 | {
|
---|
4012 | if(index >= 0 && index/4 < nrUserWindowLong)
|
---|
4013 | {
|
---|
4014 | return ((WORD *)userWindowLong)[index/2];
|
---|
4015 | }
|
---|
4016 | SetLastError(ERROR_INVALID_PARAMETER);
|
---|
4017 | return 0;
|
---|
4018 | }
|
---|
4019 | //******************************************************************************
|
---|
4020 | //******************************************************************************
|
---|
4021 | void Win32BaseWindow::setWindowId(DWORD id)
|
---|
4022 | {
|
---|
4023 | windowId = id;
|
---|
4024 | dprintf(("Set window ID to %x", id));
|
---|
4025 | OSLibSetWindowID(OS2HwndFrame, id);
|
---|
4026 | }
|
---|
4027 | //******************************************************************************
|
---|
4028 | //******************************************************************************
|
---|
4029 | Win32BaseWindow *Win32BaseWindow::GetWindowFromHandle(HWND hwnd)
|
---|
4030 | {
|
---|
4031 | Win32BaseWindow *window;
|
---|
4032 |
|
---|
4033 | if(HwGetWindowHandleData(hwnd, (DWORD *)&window) == TRUE) {
|
---|
4034 | return window;
|
---|
4035 | }
|
---|
4036 | // dprintf2(("Win32BaseWindow::GetWindowFromHandle: not a win32 window %x", hwnd));
|
---|
4037 | return NULL;
|
---|
4038 | }
|
---|
4039 | //******************************************************************************
|
---|
4040 | //******************************************************************************
|
---|
4041 | Win32BaseWindow *Win32BaseWindow::GetWindowFromOS2Handle(HWND hwnd)
|
---|
4042 | {
|
---|
4043 | Win32BaseWindow *win32wnd;
|
---|
4044 | DWORD magic;
|
---|
4045 |
|
---|
4046 | if(hwnd == OSLIB_HWND_DESKTOP)
|
---|
4047 | {
|
---|
4048 | return windowDesktop;
|
---|
4049 | }
|
---|
4050 |
|
---|
4051 | win32wnd = (Win32BaseWindow *)OSLibWinGetWindowULong(hwnd, OFFSET_WIN32WNDPTR);
|
---|
4052 | magic = OSLibWinGetWindowULong(hwnd, OFFSET_WIN32PM_MAGIC);
|
---|
4053 |
|
---|
4054 | if(win32wnd && CheckMagicDword(magic)) {
|
---|
4055 | return win32wnd;
|
---|
4056 | }
|
---|
4057 | // dprintf2(("Win32BaseWindow::GetWindowFromOS2Handle: not an Odin os2 window %x", hwnd));
|
---|
4058 | return 0;
|
---|
4059 | }
|
---|
4060 | //******************************************************************************
|
---|
4061 | //******************************************************************************
|
---|
4062 | Win32BaseWindow *Win32BaseWindow::GetWindowFromOS2FrameHandle(HWND hwnd)
|
---|
4063 | {
|
---|
4064 | return GetWindowFromOS2Handle(OSLibWinWindowFromID(hwnd,OSLIB_FID_CLIENT));
|
---|
4065 | }
|
---|
4066 | //******************************************************************************
|
---|
4067 | //******************************************************************************
|
---|
4068 | HWND Win32BaseWindow::Win32ToOS2Handle(HWND hwnd)
|
---|
4069 | {
|
---|
4070 | Win32BaseWindow *window = GetWindowFromHandle(hwnd);
|
---|
4071 |
|
---|
4072 | if(window) {
|
---|
4073 | return window->getOS2WindowHandle();
|
---|
4074 | }
|
---|
4075 | // dprintf2(("Win32BaseWindow::Win32ToOS2Handle: not a win32 window %x", hwnd));
|
---|
4076 | return hwnd;
|
---|
4077 | }
|
---|
4078 | //******************************************************************************
|
---|
4079 | //******************************************************************************
|
---|
4080 | HWND Win32BaseWindow::Win32ToOS2FrameHandle(HWND hwnd)
|
---|
4081 | {
|
---|
4082 | Win32BaseWindow *window = GetWindowFromHandle(hwnd);
|
---|
4083 |
|
---|
4084 | if(window) {
|
---|
4085 | return window->getOS2FrameWindowHandle();
|
---|
4086 | }
|
---|
4087 | // dprintf2(("Win32BaseWindow::Win32ToOS2FrameHandle: not a win32 window %x", hwnd));
|
---|
4088 | return hwnd;
|
---|
4089 | }
|
---|
4090 | //******************************************************************************
|
---|
4091 | //******************************************************************************
|
---|
4092 | HWND Win32BaseWindow::OS2ToWin32Handle(HWND hwnd)
|
---|
4093 | {
|
---|
4094 | Win32BaseWindow *window = GetWindowFromOS2Handle(hwnd);
|
---|
4095 |
|
---|
4096 | if(window) {
|
---|
4097 | return window->getWindowHandle();
|
---|
4098 | }
|
---|
4099 | window = GetWindowFromOS2FrameHandle(hwnd);
|
---|
4100 | if(window) {
|
---|
4101 | return window->getWindowHandle();
|
---|
4102 | }
|
---|
4103 | // dprintf2(("Win32BaseWindow::OS2ToWin32Handle: not a win32 window %x", hwnd));
|
---|
4104 | return 0;
|
---|
4105 | // else return hwnd; //OS/2 window handle
|
---|
4106 | }
|
---|
4107 | //******************************************************************************
|
---|
4108 | // GetNextDlgTabItem32 (USER32.276)
|
---|
4109 | //******************************************************************************
|
---|
4110 | HWND Win32BaseWindow::getNextDlgTabItem(HWND hwndCtrl, BOOL fPrevious)
|
---|
4111 | {
|
---|
4112 | Win32BaseWindow *child, *nextchild, *lastchild;
|
---|
4113 | HWND retvalue;
|
---|
4114 |
|
---|
4115 | if (hwndCtrl)
|
---|
4116 | {
|
---|
4117 | child = GetWindowFromHandle(hwndCtrl);
|
---|
4118 | if (!child)
|
---|
4119 | {
|
---|
4120 | retvalue = 0;
|
---|
4121 | goto END;
|
---|
4122 | }
|
---|
4123 | /* Make sure hwndCtrl is a top-level child */
|
---|
4124 | while ((child->getStyle() & WS_CHILD) && (child->getParent() != this))
|
---|
4125 | {
|
---|
4126 | child = child->getParent();
|
---|
4127 | if(child == NULL) break;
|
---|
4128 | }
|
---|
4129 |
|
---|
4130 | if (!child || (child->getParent() != this))
|
---|
4131 | {
|
---|
4132 | retvalue = 0;
|
---|
4133 | goto END;
|
---|
4134 | }
|
---|
4135 | }
|
---|
4136 | else
|
---|
4137 | {
|
---|
4138 | /* No ctrl specified -> start from the beginning */
|
---|
4139 | child = (Win32BaseWindow *)getFirstChild();
|
---|
4140 | if (!child)
|
---|
4141 | {
|
---|
4142 | retvalue = 0;
|
---|
4143 | goto END;
|
---|
4144 | }
|
---|
4145 |
|
---|
4146 | if (!fPrevious)
|
---|
4147 | {
|
---|
4148 | while (child->getNextChild())
|
---|
4149 | {
|
---|
4150 | child = (Win32BaseWindow *)child->getNextChild();
|
---|
4151 | }
|
---|
4152 | }
|
---|
4153 | }
|
---|
4154 |
|
---|
4155 | lastchild = child;
|
---|
4156 | nextchild = (Win32BaseWindow *)child->getNextChild();
|
---|
4157 | while (TRUE)
|
---|
4158 | {
|
---|
4159 | if (!nextchild) nextchild = (Win32BaseWindow *)getFirstChild();
|
---|
4160 |
|
---|
4161 | if (child == nextchild) break;
|
---|
4162 |
|
---|
4163 | if ((nextchild->getStyle() & WS_TABSTOP) && (nextchild->getStyle() & WS_VISIBLE) &&
|
---|
4164 | !(nextchild->getStyle() & WS_DISABLED))
|
---|
4165 | {
|
---|
4166 | lastchild = nextchild;
|
---|
4167 | if (!fPrevious) break;
|
---|
4168 | }
|
---|
4169 | nextchild = (Win32BaseWindow *)nextchild->getNextChild();
|
---|
4170 | }
|
---|
4171 | retvalue = lastchild->getWindowHandle();
|
---|
4172 |
|
---|
4173 | END:
|
---|
4174 | return retvalue;
|
---|
4175 | }
|
---|
4176 | //******************************************************************************
|
---|
4177 | //******************************************************************************
|
---|
4178 | HWND Win32BaseWindow::getNextDlgGroupItem(HWND hwndCtrl, BOOL fPrevious)
|
---|
4179 | {
|
---|
4180 | Win32BaseWindow *child, *nextchild, *lastchild;
|
---|
4181 | HWND retvalue;
|
---|
4182 |
|
---|
4183 | if (hwndCtrl)
|
---|
4184 | {
|
---|
4185 | child = GetWindowFromHandle(hwndCtrl);
|
---|
4186 | if (!child)
|
---|
4187 | {
|
---|
4188 | retvalue = 0;
|
---|
4189 | goto END;
|
---|
4190 | }
|
---|
4191 | /* Make sure hwndCtrl is a top-level child */
|
---|
4192 | while ((child->getStyle() & WS_CHILD) && (child->getParent() != this))
|
---|
4193 | {
|
---|
4194 | child = child->getParent();
|
---|
4195 | if(child == NULL) break;
|
---|
4196 | }
|
---|
4197 |
|
---|
4198 | if (!child || (child->getParent() != this))
|
---|
4199 | {
|
---|
4200 | retvalue = 0;
|
---|
4201 | goto END;
|
---|
4202 | }
|
---|
4203 | }
|
---|
4204 | else
|
---|
4205 | {
|
---|
4206 | /* No ctrl specified -> start from the beginning */
|
---|
4207 | child = (Win32BaseWindow *)getFirstChild();
|
---|
4208 | if (!child)
|
---|
4209 | {
|
---|
4210 | retvalue = 0;
|
---|
4211 | goto END;
|
---|
4212 | }
|
---|
4213 |
|
---|
4214 | if (fPrevious)
|
---|
4215 | {
|
---|
4216 | while (child->getNextChild())
|
---|
4217 | {
|
---|
4218 | child = (Win32BaseWindow *)child->getNextChild();
|
---|
4219 | }
|
---|
4220 | }
|
---|
4221 | }
|
---|
4222 |
|
---|
4223 | lastchild = child;
|
---|
4224 | nextchild = (Win32BaseWindow *)child->getNextChild();
|
---|
4225 | while (TRUE)
|
---|
4226 | {
|
---|
4227 | if (!nextchild || (nextchild->getStyle() & WS_GROUP))
|
---|
4228 | {
|
---|
4229 | /* Wrap-around to the beginning of the group */
|
---|
4230 | Win32BaseWindow *pWndTemp;
|
---|
4231 |
|
---|
4232 | nextchild = (Win32BaseWindow *)getFirstChild();
|
---|
4233 |
|
---|
4234 | for(pWndTemp = nextchild;pWndTemp;pWndTemp = (Win32BaseWindow *)pWndTemp->getNextChild())
|
---|
4235 | {
|
---|
4236 | if (pWndTemp->getStyle() & WS_GROUP)
|
---|
4237 | nextchild = pWndTemp;
|
---|
4238 |
|
---|
4239 | if (pWndTemp == child)
|
---|
4240 | break;
|
---|
4241 | }
|
---|
4242 |
|
---|
4243 | }
|
---|
4244 | if (nextchild == child)
|
---|
4245 | break;
|
---|
4246 |
|
---|
4247 | if ((nextchild->getStyle() & WS_VISIBLE) && !(nextchild->getStyle() & WS_DISABLED))
|
---|
4248 | {
|
---|
4249 | lastchild = nextchild;
|
---|
4250 |
|
---|
4251 | if (!fPrevious)
|
---|
4252 | break;
|
---|
4253 | }
|
---|
4254 |
|
---|
4255 | nextchild = (Win32BaseWindow *)nextchild->getNextChild();
|
---|
4256 | }
|
---|
4257 | retvalue = lastchild->getWindowHandle();
|
---|
4258 | END:
|
---|
4259 | return retvalue;
|
---|
4260 | }
|
---|
4261 | //******************************************************************************
|
---|
4262 | //******************************************************************************
|
---|
4263 | #ifdef DEBUG
|
---|
4264 | void PrintWindowStyle(DWORD dwStyle, DWORD dwExStyle)
|
---|
4265 | {
|
---|
4266 | char style[256] = "";
|
---|
4267 | char exstyle[256] = "";
|
---|
4268 |
|
---|
4269 | /* Window styles */
|
---|
4270 | if(dwStyle & WS_CHILD)
|
---|
4271 | strcat(style, "WS_CHILD ");
|
---|
4272 | if(dwStyle & WS_POPUP)
|
---|
4273 | strcat(style, "WS_POPUP ");
|
---|
4274 | if(dwStyle & WS_VISIBLE)
|
---|
4275 | strcat(style, "WS_VISIBLE ");
|
---|
4276 | if(dwStyle & WS_DISABLED)
|
---|
4277 | strcat(style, "WS_DISABLED ");
|
---|
4278 | if(dwStyle & WS_CLIPSIBLINGS)
|
---|
4279 | strcat(style, "WS_CLIPSIBLINGS ");
|
---|
4280 | if(dwStyle & WS_CLIPCHILDREN)
|
---|
4281 | strcat(style, "WS_CLIPCHILDREN ");
|
---|
4282 | if(dwStyle & WS_MAXIMIZE)
|
---|
4283 | strcat(style, "WS_MAXIMIZE ");
|
---|
4284 | if(dwStyle & WS_MINIMIZE)
|
---|
4285 | strcat(style, "WS_MINIMIZE ");
|
---|
4286 | if(dwStyle & WS_GROUP)
|
---|
4287 | strcat(style, "WS_GROUP ");
|
---|
4288 | if(dwStyle & WS_TABSTOP)
|
---|
4289 | strcat(style, "WS_TABSTOP ");
|
---|
4290 |
|
---|
4291 | if((dwStyle & WS_CAPTION) == WS_CAPTION)
|
---|
4292 | strcat(style, "WS_CAPTION ");
|
---|
4293 | if(dwStyle & WS_DLGFRAME)
|
---|
4294 | strcat(style, "WS_DLGFRAME ");
|
---|
4295 | if(dwStyle & WS_BORDER)
|
---|
4296 | strcat(style, "WS_BORDER ");
|
---|
4297 |
|
---|
4298 | if(dwStyle & WS_VSCROLL)
|
---|
4299 | strcat(style, "WS_VSCROLL ");
|
---|
4300 | if(dwStyle & WS_HSCROLL)
|
---|
4301 | strcat(style, "WS_HSCROLL ");
|
---|
4302 | if(dwStyle & WS_SYSMENU)
|
---|
4303 | strcat(style, "WS_SYSMENU ");
|
---|
4304 | if(dwStyle & WS_THICKFRAME)
|
---|
4305 | strcat(style, "WS_THICKFRAME ");
|
---|
4306 | if(dwStyle & WS_MINIMIZEBOX)
|
---|
4307 | strcat(style, "WS_MINIMIZEBOX ");
|
---|
4308 | if(dwStyle & WS_MAXIMIZEBOX)
|
---|
4309 | strcat(style, "WS_MAXIMIZEBOX ");
|
---|
4310 |
|
---|
4311 | if(dwExStyle & WS_EX_DLGMODALFRAME)
|
---|
4312 | strcat(exstyle, "WS_EX_DLGMODALFRAME ");
|
---|
4313 | if(dwExStyle & WS_EX_ACCEPTFILES)
|
---|
4314 | strcat(exstyle, "WS_EX_ACCEPTFILES ");
|
---|
4315 | if(dwExStyle & WS_EX_NOPARENTNOTIFY)
|
---|
4316 | strcat(exstyle, "WS_EX_NOPARENTNOTIFY ");
|
---|
4317 | if(dwExStyle & WS_EX_TOPMOST)
|
---|
4318 | strcat(exstyle, "WS_EX_TOPMOST ");
|
---|
4319 | if(dwExStyle & WS_EX_TRANSPARENT)
|
---|
4320 | strcat(exstyle, "WS_EX_TRANSPARENT ");
|
---|
4321 |
|
---|
4322 | if(dwExStyle & WS_EX_MDICHILD)
|
---|
4323 | strcat(exstyle, "WS_EX_MDICHILD ");
|
---|
4324 | if(dwExStyle & WS_EX_TOOLWINDOW)
|
---|
4325 | strcat(exstyle, "WS_EX_TOOLWINDOW ");
|
---|
4326 | if(dwExStyle & WS_EX_WINDOWEDGE)
|
---|
4327 | strcat(exstyle, "WS_EX_WINDOWEDGE ");
|
---|
4328 | if(dwExStyle & WS_EX_CLIENTEDGE)
|
---|
4329 | strcat(exstyle, "WS_EX_CLIENTEDGE ");
|
---|
4330 | if(dwExStyle & WS_EX_CONTEXTHELP)
|
---|
4331 | strcat(exstyle, "WS_EX_CONTEXTHELP ");
|
---|
4332 | if(dwExStyle & WS_EX_RIGHT)
|
---|
4333 | strcat(exstyle, "WS_EX_RIGHT ");
|
---|
4334 | if(dwExStyle & WS_EX_LEFT)
|
---|
4335 | strcat(exstyle, "WS_EX_LEFT ");
|
---|
4336 | if(dwExStyle & WS_EX_RTLREADING)
|
---|
4337 | strcat(exstyle, "WS_EX_RTLREADING ");
|
---|
4338 | if(dwExStyle & WS_EX_LTRREADING)
|
---|
4339 | strcat(exstyle, "WS_EX_LTRREADING ");
|
---|
4340 | if(dwExStyle & WS_EX_LEFTSCROLLBAR)
|
---|
4341 | strcat(exstyle, "WS_EX_LEFTSCROLLBAR ");
|
---|
4342 | if(dwExStyle & WS_EX_RIGHTSCROLLBAR)
|
---|
4343 | strcat(exstyle, "WS_EX_RIGHTSCROLLBAR ");
|
---|
4344 | if(dwExStyle & WS_EX_CONTROLPARENT)
|
---|
4345 | strcat(exstyle, "WS_EX_CONTROLPARENT ");
|
---|
4346 | if(dwExStyle & WS_EX_STATICEDGE)
|
---|
4347 | strcat(exstyle, "WS_EX_STATICEDGE ");
|
---|
4348 | if(dwExStyle & WS_EX_APPWINDOW)
|
---|
4349 | strcat(exstyle, "WS_EX_APPWINDOW ");
|
---|
4350 |
|
---|
4351 | dprintf(("Window style: %x %s", dwStyle, style));
|
---|
4352 | dprintf(("Window exStyle: %x %s (FS = %x)", dwExStyle, exstyle, GetFS()));
|
---|
4353 | }
|
---|
4354 | #endif
|
---|
4355 | //******************************************************************************
|
---|
4356 | //******************************************************************************
|
---|
4357 |
|
---|
4358 | GenericObject *Win32BaseWindow::windows = NULL;
|
---|