source: trunk/src/user32/win32wbase.cpp@ 1576

Last change on this file since 1576 was 1576, checked in by sandervl, 26 years ago

mouse activate + CreateIconIndirect fix

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