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

Last change on this file since 1583 was 1583, checked in by cbratschi, 26 years ago

WM_CONTEXTMENU

File size: 100.7 KB
Line 
1/* $Id: win32wbase.cpp,v 1.75 1999-11-03 22:04:22 cbratschi Exp $ */
2/*
3 * Win32 Window Base Class for OS/2
4 *
5 * Copyright 1998-1999 Sander van Leeuwen (sandervl@xs4all.nl)
6 * Copyright 1999 Daniela Engert (dani@ngrt.de)
7 *
8 * Parts based on Wine Windows code (windows\win.c)
9 *
10 * Copyright 1993, 1994 Alexandre Julliard
11 *
12 * TODO: Not thread/process safe
13 *
14 * Project Odin Software License can be found in LICENSE.TXT
15 *
16 */
17#include <os2win.h>
18#include <win.h>
19#include <stdlib.h>
20#include <string.h>
21#include <stdarg.h>
22#include <assert.h>
23#include <misc.h>
24#include <heapstring.h>
25#include <win32wbase.h>
26#include <winres.h>
27#include "wndmsg.h"
28#include "hooks.h"
29#include "oslibwin.h"
30#include "oslibutil.h"
31#include "oslibgdi.h"
32#include "oslibres.h"
33#include "oslibmenu.h"
34#include "oslibdos.h"
35#include "syscolor.h"
36#include "win32wndhandle.h"
37#include "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//******************************************************************************
1231ULONG Win32BaseWindow::MsgContextMenu(ULONG x,ULONG y)
1232{
1233 return SendInternalMessageA(WM_CONTEXTMENU,Win32Hwnd,MAKELPARAM(x,y));
1234}
1235//******************************************************************************
1236//******************************************************************************
1237BOOL Win32BaseWindow::isMDIClient()
1238{
1239 return FALSE;
1240}
1241//******************************************************************************
1242//******************************************************************************
1243BOOL Win32BaseWindow::isMDIChild()
1244{
1245 return FALSE;
1246}
1247//******************************************************************************
1248//TODO: Not complete
1249//******************************************************************************
1250BOOL Win32BaseWindow::isFrameWindow()
1251{
1252// if(isMDIChild() || IsDialog() || (getParent() == NULL || getParent() == windowDesktop) && ((dwStyle & WS_CAPTION) == WS_CAPTION))
1253 if((dwStyle & WS_CAPTION) == WS_CAPTION || dwStyle & (WS_VSCROLL|WS_HSCROLL))
1254 return TRUE;
1255
1256 return FALSE;
1257}
1258//******************************************************************************
1259//******************************************************************************
1260SCROLLBAR_INFO *Win32BaseWindow::getScrollInfo(int nBar)
1261{
1262 switch(nBar)
1263 {
1264 case SB_HORZ:
1265 return horzScrollInfo;
1266
1267 case SB_VERT:
1268 return vertScrollInfo;
1269 }
1270
1271 return NULL;
1272}
1273//******************************************************************************
1274//******************************************************************************
1275VOID Win32BaseWindow::subclassScrollBars(BOOL subHorz,BOOL subVert)
1276{
1277 SCROLL_SubclassScrollBars(subHorz ? hwndHorzScroll:0,subVert ? hwndVertScroll:0);
1278}
1279/***********************************************************************
1280 * NC_HandleSysCommand
1281 *
1282 * Handle a WM_SYSCOMMAND message. Called from DefWindowProc().
1283 *
1284 * TODO: Not done (see #if 0)
1285 */
1286LONG Win32BaseWindow::HandleSysCommand(WPARAM wParam, POINT *pt32)
1287{
1288 UINT uCommand = wParam & 0xFFF0;
1289
1290 if (getStyle() & WS_CHILD && uCommand != SC_KEYMENU )
1291 ScreenToClient(getParent()->getWindowHandle(), pt32 );
1292
1293 switch (uCommand)
1294 {
1295#if 0
1296 case SC_SIZE:
1297 case SC_MOVE:
1298 NC_DoSizeMove( hwnd, wParam );
1299 break;
1300#endif
1301
1302 case SC_MINIMIZE:
1303 ShowWindow(SW_MINIMIZE);
1304 break;
1305
1306 case SC_MAXIMIZE:
1307 ShowWindow(SW_MAXIMIZE);
1308 break;
1309
1310 case SC_RESTORE:
1311 ShowWindow(SW_RESTORE);
1312 break;
1313
1314 case SC_CLOSE:
1315 return SendMessageA(WM_CLOSE, 0, 0);
1316
1317#if 0
1318 case SC_VSCROLL:
1319 case SC_HSCROLL:
1320 NC_TrackScrollBar( hwnd, wParam, pt32 );
1321 break;
1322
1323 case SC_MOUSEMENU:
1324 MENU_TrackMouseMenuBar( wndPtr, wParam & 0x000F, pt32 );
1325 break;
1326
1327 case SC_KEYMENU:
1328 MENU_TrackKbdMenuBar( wndPtr , wParam , pt.x );
1329 break;
1330
1331 case SC_TASKLIST:
1332 WinExec( "taskman.exe", SW_SHOWNORMAL );
1333 break;
1334
1335 case SC_SCREENSAVE:
1336 if (wParam == SC_ABOUTWINE)
1337 ShellAboutA(hwnd, "Odin", WINE_RELEASE_INFO, 0);
1338 else
1339 if (wParam == SC_PUTMARK)
1340 dprintf(("Mark requested by user\n"));
1341 break;
1342
1343 case SC_HOTKEY:
1344 case SC_ARRANGE:
1345 case SC_NEXTWINDOW:
1346 case SC_PREVWINDOW:
1347 break;
1348#endif
1349 }
1350 return 0;
1351}
1352//******************************************************************************
1353//******************************************************************************
1354LRESULT Win32BaseWindow::DefWndControlColor(UINT ctlType, HDC hdc)
1355{
1356 //SvL: Set background color to default button color (not window (white))
1357 if(ctlType == CTLCOLOR_BTN)
1358 {
1359 SetBkColor(hdc, GetSysColor(COLOR_BTNFACE));
1360 SetTextColor(hdc, GetSysColor(COLOR_WINDOWTEXT));
1361 return GetSysColorBrush(COLOR_BTNFACE);
1362 }
1363 //SvL: Set background color to default dialog color if window is dialog
1364 if((ctlType == CTLCOLOR_DLG || ctlType == CTLCOLOR_STATIC) && IsDialog()) {
1365 SetBkColor(hdc, GetSysColor(COLOR_BTNFACE));
1366 SetTextColor(hdc, GetSysColor(COLOR_WINDOWTEXT));
1367 return GetSysColorBrush(COLOR_BTNFACE);
1368 }
1369
1370 if( ctlType == CTLCOLOR_SCROLLBAR)
1371 {
1372 HBRUSH hb = GetSysColorBrush(COLOR_SCROLLBAR);
1373 COLORREF bk = GetSysColor(COLOR_3DHILIGHT);
1374 SetTextColor( hdc, GetSysColor(COLOR_3DFACE));
1375 SetBkColor( hdc, bk);
1376
1377//TODO?
1378#if 0
1379 /* if COLOR_WINDOW happens to be the same as COLOR_3DHILIGHT
1380 * we better use 0x55aa bitmap brush to make scrollbar's background
1381 * look different from the window background.
1382 */
1383 if (bk == GetSysColor(COLOR_WINDOW)) {
1384 return CACHE_GetPattern55AABrush();
1385 }
1386#endif
1387 UnrealizeObject( hb );
1388 return (LRESULT)hb;
1389 }
1390
1391 SetTextColor( hdc, GetSysColor(COLOR_WINDOWTEXT));
1392
1393 if ((ctlType == CTLCOLOR_EDIT) || (ctlType == CTLCOLOR_LISTBOX))
1394 {
1395 SetBkColor( hdc, GetSysColor(COLOR_WINDOW) );
1396 }
1397 else
1398 {
1399 SetBkColor( hdc, GetSysColor(COLOR_3DFACE) );
1400 return (LRESULT)GetSysColorBrush(COLOR_3DFACE);
1401 }
1402 return (LRESULT)GetSysColorBrush(COLOR_WINDOW);
1403}
1404//******************************************************************************
1405//******************************************************************************
1406LRESULT Win32BaseWindow::DefWindowProcA(UINT Msg, WPARAM wParam, LPARAM lParam)
1407{
1408 switch(Msg)
1409 {
1410 case WM_CLOSE:
1411 DestroyWindow();
1412 return 0;
1413
1414 case WM_GETTEXTLENGTH:
1415 return wndNameLength;
1416
1417 case WM_GETTEXT: //TODO: SS_ICON controls
1418 strncpy((LPSTR)lParam, windowNameA, wParam);
1419 return min(wndNameLength, wParam);
1420
1421 case WM_SETTEXT:
1422 if(!fInternalMsg) {
1423 return SetWindowTextA((LPSTR)lParam);
1424 }
1425 else return 0;
1426
1427 case WM_SETREDRAW:
1428 if(wParam)
1429 SetWindowLongA (GWL_STYLE, GetWindowLongA (GWL_STYLE) | WS_VISIBLE);
1430 else SetWindowLongA (GWL_STYLE, GetWindowLongA (GWL_STYLE) & ~WS_VISIBLE);
1431
1432 return 0; //TODO
1433
1434 case WM_NCCREATE:
1435 return(TRUE);
1436
1437 case WM_NCCALCSIZE:
1438 return NCHandleCalcSize(wParam, (NCCALCSIZE_PARAMS *)lParam);
1439
1440 case WM_CTLCOLORMSGBOX:
1441 case WM_CTLCOLOREDIT:
1442 case WM_CTLCOLORLISTBOX:
1443 case WM_CTLCOLORBTN:
1444 case WM_CTLCOLORDLG:
1445 case WM_CTLCOLORSTATIC:
1446 case WM_CTLCOLORSCROLLBAR:
1447 return DefWndControlColor(Msg - WM_CTLCOLORMSGBOX, (HDC)wParam);
1448
1449 case WM_CTLCOLOR:
1450 return DefWndControlColor(HIWORD(lParam), (HDC)wParam);
1451
1452 case WM_VKEYTOITEM:
1453 case WM_CHARTOITEM:
1454 return -1;
1455
1456 case WM_PARENTNOTIFY:
1457 return 0;
1458
1459 case WM_MOUSEACTIVATE:
1460 {
1461 dprintf(("DefWndProc: WM_MOUSEACTIVATE for %x Msg %s", Win32Hwnd, GetMsgText(HIWORD(lParam))));
1462 if(getStyle() & WS_CHILD && !(getExStyle() & WS_EX_NOPARENTNOTIFY) )
1463 {
1464 if(getParent()) {
1465 LRESULT rc = getParent()->SendMessageA(WM_MOUSEACTIVATE, wParam, lParam );
1466 if(rc) return rc;
1467 }
1468 }
1469 return (LOWORD(lParam) == HTCAPTION) ? MA_NOACTIVATE : MA_ACTIVATE;
1470 }
1471 case WM_SETCURSOR:
1472 {
1473 dprintf(("DefWndProc: WM_SETCURSOR for %x Msg %s", Win32Hwnd, GetMsgText(HIWORD(lParam))));
1474 if(getStyle() & WS_CHILD && !(getExStyle() & WS_EX_NOPARENTNOTIFY) )
1475 {
1476 if(getParent()) {
1477 LRESULT rc = getParent()->SendMessageA(WM_SETCURSOR, wParam, lParam);
1478 if(rc) return rc;
1479 }
1480 }
1481 return 1;
1482 }
1483 case WM_MOUSEMOVE:
1484 return 1; //Let OS/2 change the mouse cursor back to the default
1485
1486 case WM_WINDOWPOSCHANGED:
1487 {
1488
1489/* undocumented SWP flags - from SDK 3.1 */
1490#define SWP_NOCLIENTSIZE 0x0800
1491#define SWP_NOCLIENTMOVE 0x1000
1492
1493 PWINDOWPOS wpos = (PWINDOWPOS)lParam;
1494 WPARAM wp = SIZE_RESTORED;
1495
1496 if (!(wpos->flags & SWP_NOMOVE) && !(wpos->flags & SWP_NOCLIENTMOVE))
1497 SendMessageA(WM_MOVE, 0, MAKELONG(rectClient.left, rectClient.top));
1498
1499 if (!(wpos->flags & SWP_NOSIZE) && !(wpos->flags & SWP_NOCLIENTSIZE))
1500 {
1501 if (dwStyle & WS_MAXIMIZE) wp = SIZE_MAXIMIZED;
1502 else if (dwStyle & WS_MINIMIZE) wp = SIZE_MINIMIZED;
1503
1504 SendMessageA(WM_SIZE, wp, MAKELONG(rectClient.right - rectClient.left,
1505 rectClient.bottom - rectClient.top));
1506 }
1507 return 0;
1508 }
1509 case WM_WINDOWPOSCHANGING:
1510 return HandleWindowPosChanging((WINDOWPOS *)lParam);
1511
1512 case WM_ERASEBKGND:
1513 case WM_ICONERASEBKGND:
1514 {
1515 RECT rect;
1516 int rc;
1517
1518 if (!windowClass || !windowClass->getBackgroundBrush()) return 0;
1519
1520 rc = GetClipBox( (HDC)wParam, &rect );
1521 if ((rc == SIMPLEREGION) || (rc == COMPLEXREGION))
1522 FillRect( (HDC)wParam, &rect, windowClass->getBackgroundBrush());
1523
1524 return 1;
1525 }
1526 case WM_GETDLGCODE:
1527 return 0;
1528
1529 case WM_NCLBUTTONDOWN:
1530 case WM_NCLBUTTONUP:
1531 case WM_NCLBUTTONDBLCLK:
1532 case WM_NCRBUTTONUP:
1533 case WM_NCRBUTTONDOWN:
1534 case WM_NCRBUTTONDBLCLK:
1535 case WM_NCMBUTTONDOWN:
1536 case WM_NCMBUTTONUP:
1537 case WM_NCMBUTTONDBLCLK:
1538 return 0; //TODO: Send WM_SYSCOMMAND if required
1539
1540 case WM_NCHITTEST: //TODO: Calculate position of
1541 return HTCLIENT;
1542
1543 case WM_SYSCOMMAND:
1544 {
1545 POINT point;
1546
1547 point.x = LOWORD(lParam);
1548 point.y = HIWORD(lParam);
1549 return HandleSysCommand(wParam, &point);
1550 }
1551
1552 case WM_SYSKEYDOWN:
1553 if(HIWORD(lParam) & KEYDATA_ALT)
1554 {
1555 if(wParam == VK_F4) /* try to close the window */
1556 {
1557 Win32BaseWindow *window = GetTopParent();
1558 if(window && !(window->getClass()->getStyle() & CS_NOCLOSE) )
1559 window->PostMessageA(WM_SYSCOMMAND, SC_CLOSE, 0);
1560 }
1561 }
1562 return 0;
1563
1564 case WM_QUERYOPEN:
1565 case WM_QUERYENDSESSION:
1566 return 1;
1567
1568 case WM_NOTIFYFORMAT:
1569 if (IsUnicode()) return NFR_UNICODE;
1570 else return NFR_ANSI;
1571
1572 case WM_SETICON:
1573 case WM_GETICON:
1574 {
1575 LRESULT result = 0;
1576 if (!windowClass) return result;
1577 int index = GCL_HICON;
1578
1579 if (wParam == ICON_SMALL)
1580 index = GCL_HICONSM;
1581
1582 result = windowClass->getClassLongA(index);
1583
1584 if (Msg == WM_SETICON)
1585 windowClass->setClassLongA(index, lParam);
1586
1587 return result;
1588 }
1589 case WM_NOTIFY:
1590 return 0; //comctl32 controls expect this
1591
1592 default:
1593 if(Msg > WM_USER) {
1594 return 0;
1595 }
1596 return 1;
1597 }
1598}
1599//******************************************************************************
1600//******************************************************************************
1601LRESULT Win32BaseWindow::DefWindowProcW(UINT Msg, WPARAM wParam, LPARAM lParam)
1602{
1603 switch(Msg)
1604 {
1605 case WM_GETTEXTLENGTH:
1606 return wndNameLength;
1607
1608 case WM_GETTEXT: //TODO: SS_ICON controls
1609 {
1610 LRESULT result;
1611 char *str = (char *) malloc(wParam + 1);
1612 result = DefWindowProcA(Msg, wParam, (LPARAM)str );
1613 lstrcpynAtoW( (LPWSTR)lParam, str, wParam );
1614 free(str);
1615 return result;
1616 }
1617
1618 case WM_SETTEXT:
1619 {
1620 if(!fInternalMsg)
1621 {
1622 LRESULT result;
1623 char *aText = (char *) malloc((lstrlenW((LPWSTR)lParam)+1)*sizeof(WCHAR));
1624 *aText = 0;
1625 lstrcpyWtoA(aText, (LPWSTR) lParam);
1626 result = SetWindowTextA(aText);
1627 free(aText);
1628 return result;
1629 }
1630 else return 0;
1631 }
1632
1633 default:
1634 return DefWindowProcA(Msg, wParam, lParam);
1635 }
1636}
1637//******************************************************************************
1638//******************************************************************************
1639LRESULT Win32BaseWindow::SendMessageA(ULONG Msg, WPARAM wParam, LPARAM lParam)
1640{
1641 LRESULT rc;
1642 BOOL fInternalMsgBackup = fInternalMsg;
1643
1644 //SvL: Some Wine controls send WM_COMMAND messages when they receive the focus -> apps don't like to
1645 // receive those before they get their WM_CREATE message
1646 //NOTE: May need to refuse more messages
1647 if(fCreated == FALSE && Msg == WM_COMMAND) {
1648 dprintf(("SendMessageA BEFORE creation! %s for %x %x %x", GetMsgText(Msg), getWindowHandle(), wParam, lParam));
1649 return 0;
1650 }
1651
1652 DebugPrintMessage(getWindowHandle(), Msg, wParam, lParam, FALSE, FALSE);
1653
1654 if(HkCBT::OS2HkCBTProc(getWindowHandle(), Msg, wParam, lParam) == TRUE) {//hook swallowed msg
1655 return(0);
1656 }
1657 fInternalMsg = FALSE;
1658 switch(Msg)
1659 {
1660 case WM_CREATE:
1661 {
1662 if(CallWindowProcA(win32wndproc, getWindowHandle(), WM_CREATE, 0, lParam) == -1) {
1663 dprintf(("WM_CREATE returned -1\n"));
1664 rc = -1; //don't create window
1665 break;
1666 }
1667 NotifyParent(Msg, wParam, lParam);
1668
1669 rc = 0;
1670 break;
1671 }
1672 case WM_SETTEXT:
1673 rc = CallWindowProcA(win32wndproc, getWindowHandle(), WM_SETTEXT, wParam, lParam);
1674 break;
1675
1676 case WM_LBUTTONDOWN:
1677 case WM_MBUTTONDOWN:
1678 case WM_RBUTTONDOWN:
1679 NotifyParent(Msg, wParam, lParam);
1680 rc = win32wndproc(getWindowHandle(), Msg, wParam, lParam);
1681 break;
1682
1683 case WM_DESTROY:
1684 win32wndproc(getWindowHandle(), WM_NCDESTROY, 0, 0);
1685 rc = win32wndproc(getWindowHandle(), WM_DESTROY, 0, 0);
1686 break;
1687
1688 default:
1689 rc = CallWindowProcA(win32wndproc, getWindowHandle(), Msg, wParam, lParam);
1690 break;
1691 }
1692 fInternalMsg = fInternalMsgBackup;
1693 return rc;
1694}
1695//******************************************************************************
1696//******************************************************************************
1697LRESULT Win32BaseWindow::SendMessageW(ULONG Msg, WPARAM wParam, LPARAM lParam)
1698{
1699 LRESULT rc;
1700 BOOL fInternalMsgBackup = fInternalMsg;
1701
1702 //SvL: Some Wine controls send WM_COMMAND messages when they receive the focus -> apps don't like to
1703 // receive those before they get their WM_CREATE message
1704 //NOTE: May need to refuse more messages
1705 if(fCreated == FALSE && Msg == WM_COMMAND) {
1706 dprintf(("SendMessageA BEFORE creation! %s for %x %x %x", GetMsgText(Msg), getWindowHandle(), wParam, lParam));
1707 return 0;
1708 }
1709
1710 DebugPrintMessage(getWindowHandle(), Msg, wParam, lParam, TRUE, FALSE);
1711
1712 if(HkCBT::OS2HkCBTProc(getWindowHandle(), Msg, wParam, lParam) == TRUE) {//hook swallowed msg
1713 return(0);
1714 }
1715 fInternalMsg = FALSE;
1716 switch(Msg)
1717 {
1718 case WM_CREATE:
1719 {
1720 if(CallWindowProcW(win32wndproc, getWindowHandle(), WM_CREATE, 0, lParam) == -1) {
1721 dprintf(("WM_CREATE returned -1\n"));
1722 rc = -1; //don't create window
1723 break;
1724 }
1725 NotifyParent(Msg, wParam, lParam);
1726
1727 rc = 0;
1728 break;
1729 }
1730 case WM_SETTEXT:
1731 rc = CallWindowProcW(win32wndproc, getWindowHandle(), WM_SETTEXT, wParam, lParam);
1732 break;
1733
1734 case WM_LBUTTONDOWN:
1735 case WM_MBUTTONDOWN:
1736 case WM_RBUTTONDOWN:
1737 NotifyParent(Msg, wParam, lParam);
1738 rc = win32wndproc(getWindowHandle(), Msg, wParam, lParam);
1739 break;
1740
1741 case WM_DESTROY:
1742 win32wndproc(getWindowHandle(), WM_NCDESTROY, 0, 0);
1743 rc = win32wndproc(getWindowHandle(), WM_DESTROY, 0, 0);
1744 break;
1745
1746 default:
1747 rc = CallWindowProcW(win32wndproc, getWindowHandle(), Msg, wParam, lParam);
1748 break;
1749 }
1750 fInternalMsg = fInternalMsgBackup;
1751 return rc;
1752}
1753//******************************************************************************
1754//Called as a result of an OS/2 message
1755//******************************************************************************
1756LRESULT Win32BaseWindow::SendInternalMessageA(ULONG Msg, WPARAM wParam, LPARAM lParam)
1757{
1758 LRESULT rc;
1759 BOOL fInternalMsgBackup = fInternalMsg;
1760
1761 DebugPrintMessage(getWindowHandle(), Msg, wParam, lParam, FALSE, TRUE);
1762
1763 if(HkCBT::OS2HkCBTProc(getWindowHandle(), Msg, wParam, lParam) == TRUE) {//hook swallowed msg
1764 return(0);
1765 }
1766 fInternalMsg = TRUE;
1767 switch(Msg)
1768 {
1769 case WM_CREATE:
1770 {
1771 if(CallWindowProcA(win32wndproc, getWindowHandle(), WM_CREATE, 0, lParam) == -1) {
1772 dprintf(("WM_CREATE returned -1\n"));
1773 rc = -1; //don't create window
1774 break;
1775 }
1776 NotifyParent(Msg, wParam, lParam);
1777 rc = 0;
1778 break;
1779 }
1780 case WM_LBUTTONDOWN:
1781 case WM_MBUTTONDOWN:
1782 case WM_RBUTTONDOWN:
1783 NotifyParent(Msg, wParam, lParam);
1784 rc = win32wndproc(getWindowHandle(), Msg, wParam, lParam);
1785 break;
1786
1787 case WM_DESTROY:
1788 win32wndproc(getWindowHandle(), WM_NCDESTROY, 0, 0);
1789 rc = win32wndproc(getWindowHandle(), WM_DESTROY, 0, 0);
1790 break;
1791 default:
1792 rc = CallWindowProcA(win32wndproc, getWindowHandle(), Msg, wParam, lParam);
1793 break;
1794 }
1795 fInternalMsg = fInternalMsgBackup;
1796 return rc;
1797}
1798//******************************************************************************
1799//Called as a result of an OS/2 message
1800//todo, unicode msgs (WM_SETTEXT etc)
1801//******************************************************************************
1802LRESULT Win32BaseWindow::SendInternalMessageW(ULONG Msg, WPARAM wParam, LPARAM lParam)
1803{
1804 LRESULT rc;
1805 BOOL fInternalMsgBackup = fInternalMsg;
1806
1807 DebugPrintMessage(getWindowHandle(), Msg, wParam, lParam, TRUE, TRUE);
1808
1809 if(HkCBT::OS2HkCBTProc(getWindowHandle(), Msg, wParam, lParam) == TRUE) {//hook swallowed msg
1810 return(0);
1811 }
1812 fInternalMsg = TRUE;
1813 switch(Msg)
1814 {
1815 case WM_CREATE:
1816 {
1817 if(CallWindowProcW(win32wndproc, getWindowHandle(), WM_CREATE, 0, lParam) == -1) {
1818 dprintf(("WM_CREATE returned -1\n"));
1819 rc = -1; //don't create window
1820 break;
1821 }
1822 NotifyParent(Msg, wParam, lParam);
1823 rc = 0;
1824 break;
1825 }
1826 case WM_LBUTTONDOWN:
1827 case WM_MBUTTONDOWN:
1828 case WM_RBUTTONDOWN:
1829 NotifyParent(Msg, wParam, lParam);
1830 rc = win32wndproc(getWindowHandle(), Msg, wParam, lParam);
1831 break;
1832
1833 case WM_DESTROY:
1834 win32wndproc(getWindowHandle(), WM_NCDESTROY, 0, 0);
1835 rc = win32wndproc(getWindowHandle(), WM_DESTROY, 0, 0);
1836 break;
1837 default:
1838 rc = CallWindowProcW(win32wndproc, getWindowHandle(), Msg, wParam, lParam);
1839 break;
1840 }
1841 fInternalMsg = fInternalMsgBackup;
1842 return rc;
1843}
1844//******************************************************************************
1845//******************************************************************************
1846BOOL Win32BaseWindow::PostMessageA(ULONG msg, WPARAM wParam, LPARAM lParam)
1847{
1848 return OSLibPostMessage(OS2Hwnd, WIN32APP_USERMSGBASE+msg, wParam, lParam);
1849}
1850//******************************************************************************
1851//******************************************************************************
1852BOOL Win32BaseWindow::PostMessageW(ULONG msg, WPARAM wParam, LPARAM lParam)
1853{
1854 return OSLibPostMessage(OS2Hwnd, WIN32APP_USERMSGBASE+msg, wParam, lParam);
1855}
1856//******************************************************************************
1857//TODO: do we need to inform the parent of the parent (etc) of the child window?
1858//******************************************************************************
1859void Win32BaseWindow::NotifyParent(UINT Msg, WPARAM wParam, LPARAM lParam)
1860{
1861 Win32BaseWindow *window = this;
1862 Win32BaseWindow *parentwindow;
1863
1864 while(window)
1865 {
1866 if(window->getStyle() & WS_CHILD && !(window->getExStyle() & WS_EX_NOPARENTNOTIFY) )
1867 {
1868 /* Notify the parent window only */
1869 parentwindow = window->getParent();
1870 if(parentwindow) {
1871 if(Msg == WM_CREATE || Msg == WM_DESTROY) {
1872 parentwindow->SendMessageA(WM_PARENTNOTIFY, MAKEWPARAM(Msg, window->getWindowId()), (LPARAM)window->getWindowHandle());
1873 }
1874 else parentwindow->SendMessageA(WM_PARENTNOTIFY, MAKEWPARAM(Msg, window->getWindowId()), lParam );
1875 }
1876 }
1877 else break;
1878
1879 window = parentwindow;
1880 }
1881}
1882//******************************************************************************
1883//******************************************************************************
1884BOOL Win32BaseWindow::SetMenu(HMENU hMenu)
1885{
1886
1887 dprintf(("SetMenu %x", hMenu));
1888 OS2HwndMenu = OSLibWinSetMenu(OS2HwndFrame, hMenu);
1889 if(OS2HwndMenu == 0) {
1890 dprintf(("Win32BaseWindow::SetMenu OS2HwndMenu == 0"));
1891 return FALSE;
1892 }
1893 return TRUE;
1894}
1895//******************************************************************************
1896//******************************************************************************
1897BOOL Win32BaseWindow::SetAccelTable(HACCEL hAccel)
1898{
1899 Win32Resource *winres = (Win32Resource *)hAccel;
1900 HANDLE accelhandle;
1901
1902 if(HIWORD(hAccel) == 0) {
1903 dprintf(("SetAccelTable: hAccel %x invalid", hAccel));
1904 SetLastError(ERROR_INVALID_PARAMETER);
1905 return FALSE;
1906 }
1907 acceltableResource = winres;
1908 accelhandle = OSLibWinSetAccelTable(OS2HwndFrame, winres->getOS2Handle(), winres->lockOS2Resource());
1909 winres->setOS2Handle(accelhandle);
1910 return(accelhandle != 0);
1911}
1912//******************************************************************************
1913//******************************************************************************
1914BOOL Win32BaseWindow::SetIcon(HICON hIcon)
1915{
1916 dprintf(("Win32BaseWindow::SetIcon %x", hIcon));
1917 if(OSLibWinSetIcon(OS2HwndFrame, hIcon) == TRUE) {
1918//TODO: Wine does't send these. Correct?
1919// SendMessageA(WM_SETICON, ICON_BIG, hIcon);
1920 return TRUE;
1921 }
1922 return FALSE;
1923}
1924//******************************************************************************
1925//******************************************************************************
1926BOOL Win32BaseWindow::ShowWindow(ULONG nCmdShow)
1927{
1928 ULONG showstate = 0;
1929 HWND hWinAfter;
1930
1931 dprintf(("ShowWindow %x %x", getWindowHandle(), nCmdShow));
1932#if 1
1933 if (flags & WIN_NEED_SIZE)
1934 {
1935 /* should happen only in CreateWindowEx() */
1936 int wParam = SIZE_RESTORED;
1937
1938 flags &= ~WIN_NEED_SIZE;
1939 if (dwStyle & WS_MAXIMIZE)
1940 wParam = SIZE_MAXIMIZED;
1941 else
1942 if (dwStyle & WS_MINIMIZE)
1943 wParam = SIZE_MINIMIZED;
1944
1945 SendMessageA(WM_SIZE, wParam,
1946 MAKELONG(rectClient.right-rectClient.left,
1947 rectClient.bottom-rectClient.top));
1948 SendMessageA(WM_MOVE, 0, MAKELONG( rectClient.left, rectClient.top ) );
1949 }
1950#else
1951 if(fFirstShow) {
1952 if(isFrameWindow() && IS_OVERLAPPED(getStyle()) && !isChild()) {
1953 SendMessageA(WM_SIZE, SIZE_RESTORED,
1954 MAKELONG(rectClient.right-rectClient.left,
1955 rectClient.bottom-rectClient.top));
1956 SendMessageA(WM_MOVE, 0, MAKELONG( rectClient.left, rectClient.top ) );
1957
1958 }
1959 fFirstShow = FALSE;
1960 }
1961#endif
1962 switch(nCmdShow)
1963 {
1964 case SW_SHOW:
1965 case SW_SHOWDEFAULT: //todo
1966 showstate = SWPOS_SHOW | SWPOS_ACTIVATE;
1967 break;
1968 case SW_HIDE:
1969 showstate = SWPOS_HIDE;
1970 break;
1971 case SW_RESTORE:
1972 showstate = SWPOS_RESTORE | SWPOS_SHOW | SWPOS_ACTIVATE;
1973 break;
1974 case SW_MINIMIZE:
1975 showstate = SWPOS_MINIMIZE;
1976 break;
1977 case SW_SHOWMAXIMIZED:
1978 showstate = SWPOS_MAXIMIZE | SWPOS_SHOW | SWPOS_ACTIVATE;
1979 break;
1980 case SW_SHOWMINIMIZED:
1981 showstate = SWPOS_MINIMIZE | SWPOS_SHOW | SWPOS_ACTIVATE;
1982 break;
1983 case SW_SHOWMINNOACTIVE:
1984 showstate = SWPOS_MINIMIZE | SWPOS_SHOW;
1985 break;
1986 case SW_SHOWNA:
1987 showstate = SWPOS_SHOW;
1988 break;
1989 case SW_SHOWNOACTIVATE:
1990 showstate = SWPOS_SHOW;
1991 break;
1992 case SW_SHOWNORMAL:
1993 showstate = SWPOS_RESTORE | SWPOS_ACTIVATE | SWPOS_SHOW;
1994 break;
1995 }
1996
1997 /* We can't activate a child window (WINE) */
1998 if(getStyle() & WS_CHILD)
1999 showstate &= ~SWPOS_ACTIVATE;
2000
2001 if(showstate & SWPOS_SHOW) {
2002 setStyle(getStyle() | WS_VISIBLE);
2003 }
2004 else setStyle(getStyle() & ~WS_VISIBLE);
2005
2006 BOOL rc = OSLibWinShowWindow(OS2HwndFrame, showstate);
2007 return rc;
2008}
2009//******************************************************************************
2010//******************************************************************************
2011BOOL Win32BaseWindow::SetWindowPos(HWND hwndInsertAfter, int x, int y, int cx, int cy, UINT fuFlags)
2012{
2013 BOOL rc = FALSE;
2014 Win32BaseWindow *window;
2015 HWND hParent = 0;
2016
2017 dprintf (("SetWindowPos %x %x (%d,%d)(%d,%d) %x", Win32Hwnd, hwndInsertAfter, x, y, cx, cy, fuFlags));
2018
2019 if (fuFlags &
2020 ~(SWP_NOSIZE | SWP_NOMOVE | SWP_NOZORDER |
2021 SWP_NOREDRAW | SWP_NOACTIVATE | SWP_FRAMECHANGED |
2022 SWP_SHOWWINDOW | SWP_HIDEWINDOW | SWP_NOCOPYBITS |
2023 SWP_NOOWNERZORDER))
2024 {
2025 return FALSE;
2026 }
2027
2028 WINDOWPOS wpos;
2029 SWP swp, swpOld;
2030
2031 wpos.flags = fuFlags;
2032 wpos.cy = cy;
2033 wpos.cx = cx;
2034 wpos.x = x;
2035 wpos.y = y;
2036 wpos.hwndInsertAfter = hwndInsertAfter;
2037 wpos.hwnd = getWindowHandle();
2038
2039 if(~fuFlags & (SWP_NOMOVE | SWP_NOSIZE))
2040 {
2041 if (isChild())
2042 {
2043 hParent = getParent()->getOS2WindowHandle();
2044 }
2045 OSLibWinQueryWindowPos(OS2HwndFrame, &swpOld);
2046 }
2047
2048 OSLibMapWINDOWPOStoSWP(&wpos, &swp, &swpOld, hParent, OS2HwndFrame);
2049 if (swp.fl == 0)
2050 return TRUE;
2051
2052// if ((swp.fl & SWPOS_ZORDER) && (swp.hwndInsertBehind > HWNDOS_BOTTOM))
2053 if ((swp.hwndInsertBehind > HWNDOS_BOTTOM))
2054 {
2055 Win32BaseWindow *wndBehind = Win32BaseWindow::GetWindowFromHandle(swp.hwndInsertBehind);
2056 if(wndBehind) {
2057 swp.hwndInsertBehind = wndBehind->getOS2WindowHandle();
2058 }
2059 else {
2060 dprintf(("ERROR: SetWindowPos: hwndInsertBehind %x invalid!",swp.hwndInsertBehind));
2061 swp.hwndInsertBehind = 0;
2062 }
2063 }
2064#if 0
2065 if (isFrameWindow())
2066 {
2067 if (!isChild())
2068 {
2069 POINT maxSize, maxPos, minTrack, maxTrack;
2070
2071 GetMinMaxInfo(&maxSize, &maxPos, &minTrack, &maxTrack);
2072
2073 if (swp.cx > maxTrack.x) swp.cx = maxTrack.x;
2074 if (swp.cy > maxTrack.y) swp.cy = maxTrack.y;
2075 if (swp.cx < minTrack.x) swp.cx = minTrack.x;
2076 if (swp.cy < minTrack.y) swp.cy = minTrack.y;
2077 }
2078 swp.hwnd = OS2HwndFrame;
2079 }
2080 else
2081#endif
2082 swp.hwnd = OS2HwndFrame;
2083
2084 dprintf (("WinSetWindowPos %x %x (%d,%d)(%d,%d) %x", swp.hwnd, swp.hwndInsertBehind, swp.x, swp.y, swp.cx, swp.cy, swp.fl));
2085
2086 rc = OSLibWinSetMultWindowPos(&swp, 1);
2087
2088 if (rc == FALSE)
2089 {
2090 dprintf(("OSLibWinSetMultWindowPos failed!"));
2091 }
2092 else
2093 {
2094 if (fuFlags & SWP_FRAMECHANGED_W)
2095 OSLibSendMessage (OS2HwndFrame, 0x42 /*WM_UPDATEFRAME*/, -1, 0);
2096 }
2097
2098 return (rc);
2099}
2100//******************************************************************************
2101//TODO: WPF_RESTOREMAXIMIZED
2102//******************************************************************************
2103BOOL Win32BaseWindow::SetWindowPlacement(WINDOWPLACEMENT *winpos)
2104{
2105 if(isFrameWindow())
2106 {
2107 // Set the minimized position
2108 if (winpos->flags & WPF_SETMINPOSITION)
2109 {
2110 OSLibSetWindowMinPos(OS2HwndFrame, winpos->ptMinPosition.x, winpos->ptMinPosition.y);
2111 }
2112
2113 //TODO: Max position
2114
2115 // Set the new restore position.
2116 OSLibSetWindowRestoreRect(OS2HwndFrame, &winpos->rcNormalPosition);
2117 }
2118
2119 return ShowWindow(winpos->showCmd);
2120}
2121//******************************************************************************
2122//Also destroys all the child windows (destroy parent, destroy children)
2123//******************************************************************************
2124BOOL Win32BaseWindow::DestroyWindow()
2125{
2126 return OSLibWinDestroyWindow(OS2HwndFrame);
2127}
2128//******************************************************************************
2129//******************************************************************************
2130HWND Win32BaseWindow::GetParent()
2131{
2132 if(getParent()) {
2133 return getParent()->getWindowHandle();
2134 }
2135 else return 0;
2136}
2137//******************************************************************************
2138//******************************************************************************
2139HWND Win32BaseWindow::SetParent(HWND hwndNewParent)
2140{
2141 HWND oldhwnd;
2142 Win32BaseWindow *newparent;
2143
2144 if(getParent()) {
2145 oldhwnd = getParent()->getWindowHandle();
2146 getParent()->RemoveChild(this);
2147 }
2148 else oldhwnd = 0;
2149
2150 newparent = GetWindowFromHandle(hwndNewParent);
2151 if(newparent)
2152 {
2153 setParent(newparent);
2154 getParent()->AddChild(this);
2155 OSLibWinSetParent(getOS2WindowHandle(), getParent()->getOS2WindowHandle());
2156 return oldhwnd;
2157 }
2158 SetLastError(ERROR_INVALID_PARAMETER);
2159 return 0;
2160}
2161//******************************************************************************
2162//******************************************************************************
2163BOOL Win32BaseWindow::IsChild(HWND hwndParent)
2164{
2165 if(getParent()) {
2166 return getParent()->getWindowHandle() == hwndParent;
2167 }
2168 else return 0;
2169}
2170//******************************************************************************
2171//******************************************************************************
2172HWND Win32BaseWindow::GetTopWindow()
2173{
2174 return GetWindow(GW_CHILD);
2175}
2176//******************************************************************************
2177// Get the top-level parent for a child window.
2178//******************************************************************************
2179Win32BaseWindow *Win32BaseWindow::GetTopParent()
2180{
2181 Win32BaseWindow *window = this;
2182
2183 while(window && (window->getStyle() & WS_CHILD))
2184 {
2185 window = window->getParent();
2186 }
2187 return window;
2188}
2189//******************************************************************************
2190//Don't call WinUpdateWindow as that one also updates the child windows
2191//Also need to send WM_PAINT directly to the window procedure, which doesn't
2192//always happen with WinUpdateWindow (could be posted if thread doesn't own window)
2193//******************************************************************************
2194BOOL Win32BaseWindow::UpdateWindow()
2195{
2196 RECT rect;
2197
2198 if(OSLibWinQueryUpdateRect(OS2Hwnd, &rect))
2199 {//update region not empty
2200 HDC hdc;
2201
2202 hdc = O32_GetDC(OS2Hwnd);
2203 if (isIcon)
2204 {
2205 SendMessageA(WM_ICONERASEBKGND, (WPARAM)hdc, 0);
2206 SendMessageA(WM_PAINTICON, 0, 0);
2207 } else
2208 {
2209 SendMessageA(WM_ERASEBKGND, (WPARAM)hdc, 0);
2210 SendMessageA(WM_PAINT, 0, 0);
2211 }
2212 O32_ReleaseDC(OS2Hwnd, hdc);
2213 }
2214 return TRUE;
2215}
2216//******************************************************************************
2217//******************************************************************************
2218BOOL Win32BaseWindow::IsIconic()
2219{
2220 return OSLibWinIsIconic(OS2Hwnd);
2221}
2222//******************************************************************************
2223//TODO: Should not enumerate children that are created during the enumeration!
2224//******************************************************************************
2225BOOL Win32BaseWindow::EnumChildWindows(WNDENUMPROC lpfn, LPARAM lParam)
2226{
2227 BOOL rc = TRUE;
2228 HWND hwnd;
2229 Win32BaseWindow *prevchild = 0, *child = 0;
2230
2231 dprintf(("EnumChildWindows of %x parameter %x %x (%x)", getWindowHandle(), lpfn, lParam, getFirstChild()));
2232 for (child = (Win32BaseWindow *)getFirstChild(); child; child = (Win32BaseWindow *)child->getNextChild())
2233 {
2234 dprintf(("EnumChildWindows: enumerating child %x", child->getWindowHandle()));
2235 hwnd = child->getWindowHandle();
2236 if(lpfn(hwnd, lParam) == FALSE)
2237 {
2238 rc = FALSE;
2239 break;
2240 }
2241 //check if the window still exists
2242 if(!::IsWindow(hwnd))
2243 {
2244 child = prevchild;
2245 continue;
2246 }
2247 if(child->getFirstChild() != NULL)
2248 {
2249 dprintf(("EnumChildWindows: Enumerate children of %x", child->getWindowHandle()));
2250 if(child->EnumChildWindows(lpfn, lParam) == FALSE)
2251 {
2252 rc = FALSE;
2253 break;
2254 }
2255 }
2256 prevchild = child;
2257 }
2258 return rc;
2259}
2260//******************************************************************************
2261//******************************************************************************
2262Win32BaseWindow *Win32BaseWindow::FindWindowById(int id)
2263{
2264 for (Win32BaseWindow *child = (Win32BaseWindow *)getFirstChild(); child; child = (Win32BaseWindow *)child->getNextChild())
2265 {
2266 if (child->getWindowId() == id)
2267 {
2268 return child;
2269 }
2270 }
2271 return 0;
2272}
2273//******************************************************************************
2274//TODO:
2275//We assume (for now) that if hwndParent or hwndChildAfter are real window handles, that
2276//the current process owns them.
2277//******************************************************************************
2278HWND Win32BaseWindow::FindWindowEx(HWND hwndParent, HWND hwndChildAfter, LPSTR lpszClass, LPSTR lpszWindow,
2279 BOOL fUnicode)
2280{
2281 Win32BaseWindow *parent = GetWindowFromHandle(hwndParent);
2282 Win32BaseWindow *child = GetWindowFromHandle(hwndChildAfter);
2283
2284 if((hwndParent != OSLIB_HWND_DESKTOP && !parent) ||
2285 (hwndChildAfter != 0 && !child) ||
2286 (hwndParent == OSLIB_HWND_DESKTOP && hwndChildAfter != 0))
2287 {
2288 dprintf(("Win32BaseWindow::FindWindowEx: parent or child not found %x %x", hwndParent, hwndChildAfter));
2289 SetLastError(ERROR_INVALID_WINDOW_HANDLE);
2290 return 0;
2291 }
2292 if(hwndParent != OSLIB_HWND_DESKTOP)
2293 {//if the current process owns the window, just do a quick search
2294 child = (Win32BaseWindow *)parent->getFirstChild();
2295 if(hwndChildAfter != 0)
2296 {
2297 while(child)
2298 {
2299 if(child->getWindowHandle() == hwndChildAfter)
2300 {
2301 child = (Win32BaseWindow *)child->getNextChild();
2302 break;
2303 }
2304 child = (Win32BaseWindow *)child->getNextChild();
2305 }
2306 }
2307 while(child)
2308 {
2309 if(child->getWindowClass()->hasClassName(lpszClass, fUnicode) &&
2310 (!lpszWindow || child->hasWindowName(lpszWindow, fUnicode)))
2311 {
2312 dprintf(("FindWindowEx: Found window %x", child->getWindowHandle()));
2313 return child->getWindowHandle();
2314 }
2315 child = (Win32BaseWindow *)child->getNextChild();
2316 }
2317 }
2318 else {
2319 Win32BaseWindow *wnd;
2320 HWND henum, hwnd;
2321
2322 henum = OSLibWinBeginEnumWindows(OSLIB_HWND_DESKTOP);
2323 hwnd = OSLibWinGetNextWindow(henum);
2324
2325 while(hwnd)
2326 {
2327 wnd = GetWindowFromOS2Handle(hwnd);
2328 if(wnd == NULL) {
2329 hwnd = OSLibWinQueryClientWindow(hwnd);
2330 if(hwnd) wnd = GetWindowFromOS2Handle(hwnd);
2331 if(!hwnd) wnd = GetWindowFromOS2FrameHandle(hwnd);
2332 }
2333
2334 if(wnd) {
2335 if(wnd->getWindowClass()->hasClassName(lpszClass, fUnicode) &&
2336 (!lpszWindow || wnd->hasWindowName(lpszWindow, fUnicode)))
2337 {
2338 OSLibWinEndEnumWindows(henum);
2339 dprintf(("FindWindowEx: Found window %x", wnd->getWindowHandle()));
2340 return wnd->getWindowHandle();
2341 }
2342 }
2343 hwnd = OSLibWinGetNextWindow(henum);
2344 }
2345 OSLibWinEndEnumWindows(henum);
2346 }
2347 SetLastError(ERROR_CANNOT_FIND_WND_CLASS); //TODO: not always correct
2348 return 0;
2349}
2350//******************************************************************************
2351//******************************************************************************
2352HWND Win32BaseWindow::GetWindow(UINT uCmd)
2353{
2354 HWND hwndRelated = 0;
2355 Win32BaseWindow *window;
2356
2357 switch(uCmd)
2358 {
2359 case GW_HWNDFIRST:
2360 if(getParent()) {
2361 window = (Win32BaseWindow *)getParent()->getFirstChild();
2362 hwndRelated = window->getWindowHandle();
2363 }
2364 break;
2365
2366 case GW_HWNDLAST:
2367 if(getParent())
2368 {
2369 goto end;
2370 }
2371
2372 window = this;
2373 while(window)
2374 {
2375 window = (Win32BaseWindow *)window->getNextChild();
2376 }
2377 hwndRelated = window->getWindowHandle();
2378 break;
2379
2380 case GW_HWNDNEXT:
2381 window = (Win32BaseWindow *)getNextChild();
2382 if(window) {
2383 hwndRelated = window->getWindowHandle();
2384 }
2385 break;
2386
2387 case GW_HWNDPREV:
2388 if(!getParent())
2389 {
2390 goto end;
2391 }
2392 window = (Win32BaseWindow *)(getParent()->getFirstChild()); /* First sibling */
2393 if(window == this)
2394 {
2395 hwndRelated = 0; /* First in list */
2396 goto end;
2397 }
2398 while(window->getNextChild())
2399 {
2400 if (window->getNextChild() == this)
2401 {
2402 hwndRelated = window->getWindowHandle();
2403 goto end;
2404 }
2405 window = (Win32BaseWindow *)window->getNextChild();
2406 }
2407 break;
2408
2409 case GW_OWNER:
2410 if(getOwner()) {
2411 hwndRelated = getOwner()->getWindowHandle();
2412 }
2413 break;
2414
2415 case GW_CHILD:
2416 if(getFirstChild()) {
2417 hwndRelated = ((Win32BaseWindow *)getFirstChild())->getWindowHandle();
2418 }
2419 break;
2420 }
2421end:
2422 dprintf(("GetWindow %x %d returned %x", getWindowHandle(), uCmd, hwndRelated));
2423 return hwndRelated;
2424}
2425//******************************************************************************
2426//******************************************************************************
2427HWND Win32BaseWindow::SetActiveWindow()
2428{
2429 return OSLibWinSetActiveWindow(OS2HwndFrame);
2430}
2431//******************************************************************************
2432//WM_ENABLE is sent to hwnd, but not to it's children (as it should be)
2433//******************************************************************************
2434BOOL Win32BaseWindow::EnableWindow(BOOL fEnable)
2435{
2436 return OSLibWinEnableWindow(OS2HwndFrame, fEnable);
2437}
2438//******************************************************************************
2439//******************************************************************************
2440BOOL Win32BaseWindow::CloseWindow()
2441{
2442 return OSLibWinMinimizeWindow(OS2HwndFrame);
2443}
2444//******************************************************************************
2445//******************************************************************************
2446HWND Win32BaseWindow::GetActiveWindow()
2447{
2448 HWND hwndActive;
2449 Win32BaseWindow *win32wnd;
2450 ULONG magic;
2451
2452 hwndActive = OSLibWinQueryActiveWindow();
2453
2454 win32wnd = (Win32BaseWindow *)OSLibWinGetWindowULong(hwndActive, OFFSET_WIN32WNDPTR);
2455 magic = OSLibWinGetWindowULong(hwndActive, OFFSET_WIN32PM_MAGIC);
2456 if(CheckMagicDword(magic) && win32wnd)
2457 {
2458 return win32wnd->getWindowHandle();
2459 }
2460 return hwndActive;
2461}
2462//******************************************************************************
2463//******************************************************************************
2464BOOL Win32BaseWindow::IsWindowEnabled()
2465{
2466 return OSLibWinIsWindowEnabled(OS2HwndFrame);
2467}
2468//******************************************************************************
2469//******************************************************************************
2470BOOL Win32BaseWindow::IsWindowVisible()
2471{
2472#if 1
2473 return (dwStyle & WS_VISIBLE) == WS_VISIBLE;
2474#else
2475 return OSLibWinIsWindowVisible(OS2HwndFrame);
2476#endif
2477}
2478//******************************************************************************
2479//******************************************************************************
2480BOOL Win32BaseWindow::GetWindowRect(PRECT pRect)
2481{
2482 return OSLibWinQueryWindowRect(OS2HwndFrame, pRect, RELATIVE_TO_SCREEN);
2483}
2484//******************************************************************************
2485//******************************************************************************
2486BOOL Win32BaseWindow::hasWindowName(LPSTR wndname, BOOL fUnicode)
2487{
2488 if(fUnicode) {
2489 return (lstrcmpW(windowNameW, (LPWSTR)wndname) == 0);
2490 }
2491 else return (strcmp(windowNameA, wndname) == 0);
2492}
2493//******************************************************************************
2494//******************************************************************************
2495int Win32BaseWindow::GetWindowTextLength()
2496{
2497 return wndNameLength;
2498}
2499//******************************************************************************
2500//******************************************************************************
2501int Win32BaseWindow::GetWindowTextA(LPSTR lpsz, int cch)
2502{
2503 if(windowNameA == NULL) {
2504 *lpsz = 0;
2505 return 0;
2506 }
2507 strncpy(lpsz, windowNameA, cch);
2508 return wndNameLength;
2509}
2510//******************************************************************************
2511//******************************************************************************
2512int Win32BaseWindow::GetWindowTextW(LPWSTR lpsz, int cch)
2513{
2514 if(windowNameW == NULL) {
2515 *lpsz = 0;
2516 return 0;
2517 }
2518 lstrcpynW((LPWSTR)lpsz, windowNameW, cch);
2519 return wndNameLength;
2520}
2521//******************************************************************************
2522//******************************************************************************
2523BOOL Win32BaseWindow::SetWindowTextA(LPSTR lpsz)
2524{
2525 if(lpsz == NULL)
2526 return FALSE;
2527
2528 if(windowNameA) free(windowNameA);
2529 if(windowNameW) free(windowNameW);
2530
2531 windowNameA = (LPSTR)_smalloc(strlen(lpsz)+1);
2532 strcpy(windowNameA, lpsz);
2533 windowNameW = (LPWSTR)_smalloc((strlen(lpsz)+1)*sizeof(WCHAR));
2534 lstrcpyAtoW(windowNameW, windowNameA);
2535 wndNameLength = strlen(windowNameA)+1; //including 0 terminator
2536
2537 if(OS2HwndFrame)
2538 return OSLibWinSetWindowText(OS2HwndFrame, (LPSTR)windowNameA);
2539
2540 return TRUE;
2541}
2542//******************************************************************************
2543//******************************************************************************
2544BOOL Win32BaseWindow::SetWindowTextW(LPWSTR lpsz)
2545{
2546 if(lpsz == NULL)
2547 return FALSE;
2548
2549 if(windowNameA) free(windowNameA);
2550 if(windowNameW) free(windowNameW);
2551
2552 windowNameW = (LPWSTR)_smalloc((lstrlenW((LPWSTR)lpsz)+1)*sizeof(WCHAR));
2553 lstrcpyW(windowNameW, (LPWSTR)lpsz);
2554 windowNameA = (LPSTR)_smalloc(lstrlenW((LPWSTR)lpsz)+1);
2555 lstrcpyWtoA(windowNameA, windowNameW);
2556 wndNameLength = strlen(windowNameA)+1; //including 0 terminator
2557
2558 if(OS2HwndFrame)
2559 return OSLibWinSetWindowText(OS2HwndFrame, (LPSTR)windowNameA);
2560
2561 return TRUE;
2562}
2563//******************************************************************************
2564//******************************************************************************
2565LONG Win32BaseWindow::SetWindowLongA(int index, ULONG value)
2566{
2567 LONG oldval;
2568
2569 switch(index) {
2570 case GWL_EXSTYLE:
2571 {
2572 STYLESTRUCT ss;
2573
2574 if(dwExStyle == value)
2575 return value;
2576
2577 ss.styleOld = dwExStyle;
2578 ss.styleNew = value;
2579 dprintf(("SetWindowLong GWL_EXSTYLE %x old %x new style %x", getWindowHandle(), dwExStyle, value));
2580 SendMessageA(WM_STYLECHANGING,GWL_EXSTYLE,(LPARAM)&ss);
2581 setExStyle(ss.styleNew);
2582 SendMessageA(WM_STYLECHANGED,GWL_EXSTYLE,(LPARAM)&ss);
2583 return ss.styleOld;
2584 }
2585 case GWL_STYLE:
2586 {
2587 STYLESTRUCT ss;
2588
2589 if(dwStyle == value)
2590 return value;
2591
2592 ss.styleOld = dwStyle;
2593 ss.styleNew = value;
2594 dprintf(("SetWindowLong GWL_STYLE %x old %x new style %x", getWindowHandle(), dwStyle, value));
2595 SendMessageA(WM_STYLECHANGING,GWL_STYLE,(LPARAM)&ss);
2596 setStyle(ss.styleNew);
2597 if(!IsWindowDestroyed())
2598 OSLibSetWindowStyle(OS2HwndFrame, ss.styleNew);
2599 SendMessageA(WM_STYLECHANGED,GWL_STYLE,(LPARAM)&ss);
2600 return ss.styleOld;
2601 }
2602 case GWL_WNDPROC:
2603 oldval = (LONG)getWindowProc();
2604 setWindowProc((WNDPROC)value);
2605 return oldval;
2606 case GWL_HINSTANCE:
2607 oldval = hInstance;
2608 hInstance = value;
2609 return oldval;
2610 case GWL_HWNDPARENT:
2611 return SetParent((HWND)value);
2612 case GWL_ID:
2613 oldval = getWindowId();
2614 setWindowId(value);
2615 return oldval;
2616 case GWL_USERDATA:
2617 oldval = userData;
2618 userData = value;
2619 return oldval;
2620 default:
2621 if(index >= 0 && index/4 < nrUserWindowLong)
2622 {
2623 oldval = userWindowLong[index/4];
2624 userWindowLong[index/4] = value;
2625 return oldval;
2626 }
2627 SetLastError(ERROR_INVALID_PARAMETER);
2628 return 0;
2629 }
2630}
2631//******************************************************************************
2632//******************************************************************************
2633ULONG Win32BaseWindow::GetWindowLongA(int index)
2634{
2635 switch(index) {
2636 case GWL_EXSTYLE:
2637 return dwExStyle;
2638 case GWL_STYLE:
2639 return dwStyle;
2640 case GWL_WNDPROC:
2641 return (ULONG)getWindowProc();
2642 case GWL_HINSTANCE:
2643 return hInstance;
2644 case GWL_HWNDPARENT:
2645 if(getParent()) {
2646 return getParent()->getWindowHandle();
2647 }
2648 else return 0;
2649 case GWL_ID:
2650 return getWindowId();
2651 case GWL_USERDATA:
2652 return userData;
2653 default:
2654 if(index >= 0 && index/4 < nrUserWindowLong)
2655 {
2656 return userWindowLong[index/4];
2657 }
2658 SetLastError(ERROR_INVALID_PARAMETER);
2659 return 0;
2660 }
2661}
2662//******************************************************************************
2663//******************************************************************************
2664WORD Win32BaseWindow::SetWindowWord(int index, WORD value)
2665{
2666 WORD oldval;
2667
2668 if(index >= 0 && index/4 < nrUserWindowLong)
2669 {
2670 oldval = ((WORD *)userWindowLong)[index/2];
2671 ((WORD *)userWindowLong)[index/2] = value;
2672 return oldval;
2673 }
2674 SetLastError(ERROR_INVALID_PARAMETER);
2675 return 0;
2676}
2677//******************************************************************************
2678//******************************************************************************
2679WORD Win32BaseWindow::GetWindowWord(int index)
2680{
2681 if(index >= 0 && index/4 < nrUserWindowLong)
2682 {
2683 return ((WORD *)userWindowLong)[index/2];
2684 }
2685 SetLastError(ERROR_INVALID_PARAMETER);
2686 return 0;
2687}
2688//******************************************************************************
2689//******************************************************************************
2690void Win32BaseWindow::setWindowId(DWORD id)
2691{
2692 windowId = id;
2693 OSLibSetWindowID(OS2HwndFrame, id);
2694}
2695//******************************************************************************
2696//******************************************************************************
2697Win32BaseWindow *Win32BaseWindow::GetWindowFromHandle(HWND hwnd)
2698{
2699 Win32BaseWindow *window;
2700
2701 if(hwnd == NULL && windowDesktop)
2702 return windowDesktop;
2703
2704 if(HwGetWindowHandleData(hwnd, (DWORD *)&window) == TRUE) {
2705 return window;
2706 }
2707 else return NULL;
2708}
2709//******************************************************************************
2710//******************************************************************************
2711Win32BaseWindow *Win32BaseWindow::GetWindowFromOS2Handle(HWND hwnd)
2712{
2713 Win32BaseWindow *win32wnd;
2714 DWORD magic;
2715
2716 win32wnd = (Win32BaseWindow *)OSLibWinGetWindowULong(hwnd, OFFSET_WIN32WNDPTR);
2717 magic = OSLibWinGetWindowULong(hwnd, OFFSET_WIN32PM_MAGIC);
2718
2719 if(win32wnd && CheckMagicDword(magic)) {
2720 return win32wnd;
2721 }
2722 return 0;
2723}
2724//******************************************************************************
2725//******************************************************************************
2726Win32BaseWindow *Win32BaseWindow::GetWindowFromOS2FrameHandle(HWND hwnd)
2727{
2728 return GetWindowFromOS2Handle(OSLibWinWindowFromID(hwnd,OSLIB_FID_CLIENT));
2729}
2730//******************************************************************************
2731//******************************************************************************
2732HWND Win32BaseWindow::Win32ToOS2Handle(HWND hwnd)
2733{
2734 Win32BaseWindow *window = GetWindowFromHandle(hwnd);
2735
2736 if(window) {
2737 return window->getOS2WindowHandle();
2738 }
2739 else return hwnd;
2740}
2741//******************************************************************************
2742//******************************************************************************
2743HWND Win32BaseWindow::Win32ToOS2FrameHandle(HWND hwnd)
2744{
2745 Win32BaseWindow *window = GetWindowFromHandle(hwnd);
2746
2747 if(window) {
2748 return window->getOS2FrameWindowHandle();
2749 }
2750 else return hwnd;
2751}
2752//******************************************************************************
2753//******************************************************************************
2754HWND Win32BaseWindow::OS2ToWin32Handle(HWND hwnd)
2755{
2756 Win32BaseWindow *window = GetWindowFromOS2Handle(hwnd);
2757
2758 if(window) {
2759 return window->getWindowHandle();
2760 }
2761 window = GetWindowFromOS2FrameHandle(hwnd);
2762 if(window) {
2763 return window->getWindowHandle();
2764 }
2765 else return 0;
2766// else return hwnd; //OS/2 window handle
2767}
2768//******************************************************************************
2769// GetNextDlgTabItem32 (USER32.276)
2770//******************************************************************************
2771HWND Win32BaseWindow::getNextDlgTabItem(HWND hwndCtrl, BOOL fPrevious)
2772{
2773 Win32BaseWindow *child, *nextchild, *lastchild;
2774 HWND retvalue;
2775
2776 if (hwndCtrl)
2777 {
2778 child = GetWindowFromHandle(hwndCtrl);
2779 if (!child)
2780 {
2781 retvalue = 0;
2782 goto END;
2783 }
2784 /* Make sure hwndCtrl is a top-level child */
2785 while ((child->getStyle() & WS_CHILD) && (child->getParent() != this))
2786 {
2787 child = child->getParent();
2788 if(child == NULL) break;
2789 }
2790
2791 if (!child || child->getParent() != this)
2792 {
2793 retvalue = 0;
2794 goto END;
2795 }
2796 }
2797 else
2798 {
2799 /* No ctrl specified -> start from the beginning */
2800 child = (Win32BaseWindow *)getFirstChild();
2801 if (!child)
2802 {
2803 retvalue = 0;
2804 goto END;
2805 }
2806
2807 if (!fPrevious)
2808 {
2809 while (child->getNextChild())
2810 {
2811 child = (Win32BaseWindow *)child->getNextChild();
2812 }
2813 }
2814 }
2815
2816 lastchild = child;
2817 nextchild = (Win32BaseWindow *)child->getNextChild();
2818 while (TRUE)
2819 {
2820 if (!nextchild) nextchild = (Win32BaseWindow *)getFirstChild();
2821
2822 if (child == nextchild) break;
2823
2824 if ((nextchild->getStyle() & WS_TABSTOP) && (nextchild->getStyle() & WS_VISIBLE) &&
2825 !(nextchild->getStyle() & WS_DISABLED))
2826 {
2827 lastchild = nextchild;
2828 if (!fPrevious) break;
2829 }
2830 nextchild = (Win32BaseWindow *)nextchild->getNextChild();
2831 }
2832 retvalue = lastchild->getWindowHandle();
2833
2834END:
2835 return retvalue;
2836}
2837//******************************************************************************
2838//******************************************************************************
2839HWND Win32BaseWindow::getNextDlgGroupItem(HWND hwndCtrl, BOOL fPrevious)
2840{
2841 Win32BaseWindow *child, *nextchild, *lastchild;
2842 HWND retvalue;
2843
2844 if (hwndCtrl)
2845 {
2846 child = GetWindowFromHandle(hwndCtrl);
2847 if (!child)
2848 {
2849 retvalue = 0;
2850 goto END;
2851 }
2852 /* Make sure hwndCtrl is a top-level child */
2853 while ((child->getStyle() & WS_CHILD) && (child->getParent() != this))
2854 {
2855 child = child->getParent();
2856 if(child == NULL) break;
2857 }
2858
2859 if (!child || child->getParent() != this)
2860 {
2861 retvalue = 0;
2862 goto END;
2863 }
2864 }
2865 else
2866 {
2867 /* No ctrl specified -> start from the beginning */
2868 child = (Win32BaseWindow *)getFirstChild();
2869 if (!child)
2870 {
2871 retvalue = 0;
2872 goto END;
2873 }
2874
2875 if (fPrevious)
2876 {
2877 while (child->getNextChild())
2878 {
2879 child = (Win32BaseWindow *)child->getNextChild();
2880 }
2881 }
2882 }
2883
2884 lastchild = child;
2885 nextchild = (Win32BaseWindow *)child->getNextChild();
2886 while (TRUE)
2887 {
2888 if (!nextchild || nextchild->getStyle() & WS_GROUP)
2889 {
2890 /* Wrap-around to the beginning of the group */
2891 Win32BaseWindow *pWndTemp;
2892
2893 nextchild = (Win32BaseWindow *)getFirstChild();
2894
2895 for(pWndTemp = nextchild;pWndTemp;pWndTemp = (Win32BaseWindow *)pWndTemp->getNextChild())
2896 {
2897 if (pWndTemp->getStyle() & WS_GROUP)
2898 nextchild = pWndTemp;
2899
2900 if (pWndTemp == child)
2901 break;
2902 }
2903
2904 }
2905 if (nextchild == child)
2906 break;
2907
2908 if ((nextchild->getStyle() & WS_VISIBLE) && !(nextchild->getStyle() & WS_DISABLED))
2909 {
2910 lastchild = nextchild;
2911
2912 if (!fPrevious)
2913 break;
2914 }
2915
2916 nextchild = (Win32BaseWindow *)nextchild->getNextChild();
2917 }
2918 retvalue = lastchild->getWindowHandle();
2919END:
2920 return retvalue;
2921}
2922//******************************************************************************
2923//******************************************************************************
2924#ifdef DEBUG
2925void PrintWindowStyle(DWORD dwStyle, DWORD dwExStyle)
2926{
2927 char style[256] = "";
2928 char exstyle[256] = "";
2929
2930 /* Window styles */
2931 if(dwStyle & WS_CHILD)
2932 strcat(style, "WS_CHILD ");
2933 if(dwStyle & WS_POPUP)
2934 strcat(style, "WS_POPUP ");
2935 if(dwStyle & WS_VISIBLE)
2936 strcat(style, "WS_VISIBLE ");
2937 if(dwStyle & WS_DISABLED)
2938 strcat(style, "WS_DISABLED ");
2939 if(dwStyle & WS_CLIPSIBLINGS)
2940 strcat(style, "WS_CLIPSIBLINGS ");
2941 if(dwStyle & WS_CLIPCHILDREN)
2942 strcat(style, "WS_CLIPCHILDREN ");
2943 if(dwStyle & WS_MAXIMIZE)
2944 strcat(style, "WS_MAXIMIZE ");
2945 if(dwStyle & WS_MINIMIZE)
2946 strcat(style, "WS_MINIMIZE ");
2947 if(dwStyle & WS_GROUP)
2948 strcat(style, "WS_GROUP ");
2949 if(dwStyle & WS_TABSTOP)
2950 strcat(style, "WS_TABSTOP ");
2951
2952 if((dwStyle & WS_CAPTION) == WS_CAPTION)
2953 strcat(style, "WS_CAPTION ");
2954 if(dwStyle & WS_DLGFRAME)
2955 strcat(style, "WS_DLGFRAME ");
2956 if(dwStyle & WS_BORDER)
2957 strcat(style, "WS_BORDER ");
2958
2959 if(dwStyle & WS_VSCROLL)
2960 strcat(style, "WS_VSCROLL ");
2961 if(dwStyle & WS_HSCROLL)
2962 strcat(style, "WS_HSCROLL ");
2963 if(dwStyle & WS_SYSMENU)
2964 strcat(style, "WS_SYSMENU ");
2965 if(dwStyle & WS_THICKFRAME)
2966 strcat(style, "WS_THICKFRAME ");
2967 if(dwStyle & WS_MINIMIZEBOX)
2968 strcat(style, "WS_MINIMIZEBOX ");
2969 if(dwStyle & WS_MAXIMIZEBOX)
2970 strcat(style, "WS_MAXIMIZEBOX ");
2971
2972 if(dwExStyle & WS_EX_DLGMODALFRAME)
2973 strcat(exstyle, "WS_EX_DLGMODALFRAME ");
2974 if(dwExStyle & WS_EX_ACCEPTFILES)
2975 strcat(exstyle, "WS_EX_ACCEPTFILES ");
2976 if(dwExStyle & WS_EX_NOPARENTNOTIFY)
2977 strcat(exstyle, "WS_EX_NOPARENTNOTIFY ");
2978 if(dwExStyle & WS_EX_TOPMOST)
2979 strcat(exstyle, "WS_EX_TOPMOST ");
2980 if(dwExStyle & WS_EX_TRANSPARENT)
2981 strcat(exstyle, "WS_EX_TRANSPARENT ");
2982
2983 if(dwExStyle & WS_EX_MDICHILD)
2984 strcat(exstyle, "WS_EX_MDICHILD ");
2985 if(dwExStyle & WS_EX_TOOLWINDOW)
2986 strcat(exstyle, "WS_EX_TOOLWINDOW ");
2987 if(dwExStyle & WS_EX_WINDOWEDGE)
2988 strcat(exstyle, "WS_EX_WINDOWEDGE ");
2989 if(dwExStyle & WS_EX_CLIENTEDGE)
2990 strcat(exstyle, "WS_EX_CLIENTEDGE ");
2991 if(dwExStyle & WS_EX_CONTEXTHELP)
2992 strcat(exstyle, "WS_EX_CONTEXTHELP ");
2993 if(dwExStyle & WS_EX_RIGHT)
2994 strcat(exstyle, "WS_EX_RIGHT ");
2995 if(dwExStyle & WS_EX_LEFT)
2996 strcat(exstyle, "WS_EX_LEFT ");
2997 if(dwExStyle & WS_EX_RTLREADING)
2998 strcat(exstyle, "WS_EX_RTLREADING ");
2999 if(dwExStyle & WS_EX_LTRREADING)
3000 strcat(exstyle, "WS_EX_LTRREADING ");
3001 if(dwExStyle & WS_EX_LEFTSCROLLBAR)
3002 strcat(exstyle, "WS_EX_LEFTSCROLLBAR ");
3003 if(dwExStyle & WS_EX_RIGHTSCROLLBAR)
3004 strcat(exstyle, "WS_EX_RIGHTSCROLLBAR ");
3005 if(dwExStyle & WS_EX_CONTROLPARENT)
3006 strcat(exstyle, "WS_EX_CONTROLPARENT ");
3007 if(dwExStyle & WS_EX_STATICEDGE)
3008 strcat(exstyle, "WS_EX_STATICEDGE ");
3009 if(dwExStyle & WS_EX_APPWINDOW)
3010 strcat(exstyle, "WS_EX_APPWINDOW ");
3011
3012 dprintf(("Window style: %x %s", dwStyle, style));
3013 dprintf(("Window exStyle: %x %s", dwExStyle, exstyle));
3014}
3015#endif
3016//******************************************************************************
3017//******************************************************************************
3018
3019GenericObject *Win32BaseWindow::windows = NULL;
Note: See TracBrowser for help on using the repository browser.