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

Last change on this file since 4837 was 4825, checked in by sandervl, 25 years ago

hook, mdi & focus fixes

File size: 120.9 KB
Line 
1/* $Id: win32wbase.cpp,v 1.225 2000-12-17 15:04:11 sandervl Exp $ */
2/*
3 * Win32 Window Base Class for OS/2
4 *
5 * Copyright 1998-2000 Sander van Leeuwen (sandervl@xs4all.nl)
6 * Copyright 1999 Daniela Engert (dani@ngrt.de)
7 * Copyright 1999-2000 Christoph Bratschi (cbratschi@datacomm.ch)
8 *
9 * Parts based on Wine Windows code (windows\win.c)
10 * Corel version: corel20000212
11 *
12 * Copyright 1993, 1994, 1996 Alexandre Julliard
13 * 1995 Alex Korobka
14 *
15 * TODO: Not thread/process safe
16 *
17 * NOTE: Client rectangle always relative to frame window
18 * Window rectangle in parent coordinates (relative to parent's client window)
19 * (screen coord. if no parent)
20 *
21 * Project Odin Software License can be found in LICENSE.TXT
22 *
23 */
24#include <os2win.h>
25#include <win.h>
26#include <stdlib.h>
27#include <string.h>
28#include <stdarg.h>
29#include <assert.h>
30#include <misc.h>
31#include <heapstring.h>
32#include <win32wbase.h>
33#include "wndmsg.h"
34#include "oslibwin.h"
35#include "oslibmsg.h"
36#include "oslibutil.h"
37#include "oslibgdi.h"
38#include "oslibres.h"
39#include "oslibdos.h"
40#include "syscolor.h"
41#include "win32wndhandle.h"
42#include "dc.h"
43#include "win32wdesktop.h"
44#include "pmwindow.h"
45#include "controls.h"
46#include <wprocess.h>
47#include <win\hook.h>
48#include <menu.h>
49#define INCL_TIMERWIN32
50#include "timer.h"
51
52#define DBG_LOCALLOG DBG_win32wbase
53#include "dbglocal.h"
54
55/* bits in the dwKeyData */
56#define KEYDATA_ALT 0x2000
57#define KEYDATA_PREVSTATE 0x4000
58
59void PrintWindowStyle(DWORD dwStyle, DWORD dwExStyle);
60
61static fDestroyAll = FALSE;
62//For quick lookup of current process id
63static ULONG currentProcessId = -1;
64
65//******************************************************************************
66//******************************************************************************
67Win32BaseWindow::Win32BaseWindow(DWORD objType) : GenericObject(&windows, objType)
68{
69 Init();
70}
71//******************************************************************************
72//******************************************************************************
73Win32BaseWindow::Win32BaseWindow(CREATESTRUCTA *lpCreateStructA, ATOM classAtom, BOOL isUnicode)
74 : GenericObject(&windows, OBJTYPE_WINDOW), ChildWindow()
75{
76 Init();
77 this->isUnicode = isUnicode;
78 CreateWindowExA(lpCreateStructA, classAtom);
79}
80//******************************************************************************
81//******************************************************************************
82void Win32BaseWindow::Init()
83{
84 isUnicode = FALSE;
85 fFirstShow = TRUE;
86 fIsDialog = FALSE;
87 fIsModalDialogOwner = FALSE;
88 OS2HwndModalDialog = 0;
89 fInternalMsg = FALSE;
90 fNoSizeMsg = FALSE;
91 fIsDestroyed = FALSE;
92 fDestroyWindowCalled = FALSE;
93 fCreated = FALSE;
94 fTaskList = FALSE;
95 fParentDC = FALSE;
96 fComingToTop = FALSE;
97 fCreateSetWindowPos = FALSE;
98
99 windowNameA = NULL;
100 windowNameW = NULL;
101 wndNameLength = 0;
102
103 userWindowLong = NULL;;
104 nrUserWindowLong = 0;
105
106 magic = WIN32PM_MAGIC;
107 OS2Hwnd = 0;
108 hSysMenu = 0;
109 Win32Hwnd = 0;
110
111 if(HwAllocateWindowHandle(&Win32Hwnd, (ULONG)this) == FALSE)
112 {
113 dprintf(("Win32BaseWindow::Init HwAllocateWindowHandle failed!!"));
114 DebugInt3();
115 }
116
117 posx = posy = 0;
118 width = height = 0;
119
120 dwExStyle = 0;
121 dwStyle = 0;
122 win32wndproc = 0;
123 hInstance = 0;
124 dwIDMenu = 0; //0xFFFFFFFF; //default -1
125 userData = 0;
126 contextHelpId = 0;
127 hotkey = 0;
128
129
130 hwndLinkAfter = HWND_BOTTOM;
131 flags = 0;
132 lastHitTestVal = HTOS_NORMAL;
133 owner = NULL;
134 windowClass = 0;
135
136 hIcon = 0;
137 hIconSm = 0;
138
139 EraseBkgndFlag = TRUE;
140
141 horzScrollInfo = NULL;
142 vertScrollInfo = NULL;
143
144 propertyList = NULL;
145
146 ownDC = 0;
147 hWindowRegion = 0;
148 hClipRegion = 0;
149
150 hTaskList = 0;
151
152 if(currentProcessId == -1)
153 {
154 currentProcessId = GetCurrentProcessId();
155 }
156 dwThreadId = GetCurrentThreadId();
157 dwProcessId = currentProcessId;
158
159 memset(&windowpos, 0, sizeof(windowpos));
160 //min and max position are initially -1 (verified in NT4, SP6)
161 windowpos.ptMinPosition.x = -1;
162 windowpos.ptMinPosition.y = -1;
163 windowpos.ptMaxPosition.x = -1;
164 windowpos.ptMaxPosition.y = -1;
165}
166//******************************************************************************
167//todo get rid of resources (menu, icon etc)
168//******************************************************************************
169Win32BaseWindow::~Win32BaseWindow()
170{
171 if(hTaskList) {
172 OSLibWinRemoveFromTasklist(hTaskList);
173 }
174
175 OSLibWinSetVisibleRegionNotify(OS2Hwnd, FALSE);
176 OSLibWinSetWindowULong(OS2Hwnd, OFFSET_WIN32WNDPTR, 0);
177 OSLibWinSetWindowULong(OS2Hwnd, OFFSET_WIN32PM_MAGIC, 0);
178
179 if(!fDestroyAll && getParent() && getParent()->getFirstChild() == this && getNextChild() == NULL)
180 {
181 //if we're the last child that's being destroyed and our
182 //parent window was also destroyed, then we delete the parent object
183 if(getParent()->IsWindowDestroyed())
184 {
185 dprintf(("Last Child (%x) destroyed, get rid of our parent window (%x)", getWindowHandle(), getParent()->getWindowHandle()));
186 delete getParent();
187 setParent(NULL); //or else we'll crash in the dtor of the ChildWindow class
188 }
189 }
190 else
191 if(fDestroyAll) {
192 dprintf(("Destroying window %x %s", getWindowHandle(), windowNameA));
193 setParent(NULL); //or else we'll crash in the dtor of the ChildWindow class
194 }
195
196 /* Decrement class window counter */
197 if(windowClass) {
198 windowClass->DecreaseWindowCount();
199 }
200
201 if(isOwnDC())
202 releaseOwnDC(ownDC);
203
204 if(Win32Hwnd)
205 HwFreeWindowHandle(Win32Hwnd);
206
207 if(userWindowLong)
208 free(userWindowLong);
209
210 if(windowNameA) {
211 free(windowNameA);
212 windowNameA = NULL;
213 }
214 if(windowNameW) {
215 free(windowNameW);
216 windowNameW = NULL;
217 }
218 if(vertScrollInfo) {
219 free(vertScrollInfo);
220 vertScrollInfo = NULL;
221 }
222 if(horzScrollInfo) {
223 free(horzScrollInfo);
224 horzScrollInfo = NULL;
225 }
226 if(propertyList) {
227 removeWindowProps();
228 }
229}
230//******************************************************************************
231//******************************************************************************
232void Win32BaseWindow::DestroyAll()
233{
234 fDestroyAll = TRUE;
235 GenericObject::DestroyAll(windows);
236}
237//******************************************************************************
238//******************************************************************************
239BOOL Win32BaseWindow::isChild()
240{
241 return ((dwStyle & WS_CHILD) != 0);
242}
243//******************************************************************************
244//******************************************************************************
245BOOL Win32BaseWindow::IsWindowUnicode()
246{
247 dprintf2(("IsWindowUnicode %x %d", getWindowHandle(), WINPROC_GetProcType(getWindowProc()) == WIN_PROC_32W));
248 return (WINPROC_GetProcType(getWindowProc()) == WIN_PROC_32W);
249}
250//******************************************************************************
251//******************************************************************************
252BOOL Win32BaseWindow::CreateWindowExA(CREATESTRUCTA *cs, ATOM classAtom)
253{
254 char buffer[256];
255
256#ifdef DEBUG
257 PrintWindowStyle(cs->style, cs->dwExStyle);
258#endif
259
260 //If window has no owner/parent window, then it will be added to the tasklist
261 //(depending on visibility state)
262 if (!cs->hwndParent) fTaskList = TRUE;
263
264 sw = SW_SHOW;
265 SetLastError(0);
266
267 /* Find the parent window */
268 if (cs->hwndParent)
269 {
270 Win32BaseWindow *window = GetWindowFromHandle(cs->hwndParent);
271 if(!window) {
272 dprintf(("Bad parent %04x\n", cs->hwndParent ));
273 SetLastError(ERROR_INVALID_PARAMETER);
274 return FALSE;
275 }
276 /* Make sure parent is valid */
277 if (!window->IsWindow() )
278 {
279 dprintf(("Bad parent %04x\n", cs->hwndParent ));
280 SetLastError(ERROR_INVALID_PARAMETER);
281 return FALSE;
282 }
283 /* Windows does this for overlapped windows
284 * (I don't know about other styles.) */
285 if (cs->hwndParent == GetDesktopWindow() && (!(cs->style & WS_CHILD) || (cs->style & WS_POPUP)))
286 {
287 cs->hwndParent = 0;
288 }
289 }
290 else
291 if ((cs->style & WS_CHILD) && !(cs->style & WS_POPUP)) {
292 dprintf(("No parent for child window\n" ));
293 SetLastError(ERROR_INVALID_PARAMETER);
294 return FALSE; /* WS_CHILD needs a parent, but WS_POPUP doesn't */
295 }
296
297 /* Find the window class */
298 windowClass = Win32WndClass::FindClass(cs->hInstance, (LPSTR)classAtom);
299 if (!windowClass)
300 {
301 GlobalGetAtomNameA( classAtom, buffer, sizeof(buffer) );
302 dprintf(("Bad class '%s'\n", buffer ));
303 SetLastError(ERROR_INVALID_PARAMETER);
304 return 0;
305 }
306 /* Increment class window counter */
307 windowClass->IncreaseWindowCount();
308
309#ifdef DEBUG
310 if(HIWORD(cs->lpszClass))
311 {
312 char *astring;
313
314 if(isUnicode) astring = UnicodeToAsciiString((LPWSTR)cs->lpszClass);
315 else astring = (char *)cs->lpszClass;
316
317 dprintf(("Window class %s", astring));
318 if(isUnicode) FreeAsciiString(astring);
319 }
320 else dprintf(("Window class %x", cs->lpszClass));
321#endif
322
323 /* Fix the lpszClass field: from existing programs, it seems ok to call a CreateWindowXXX
324 * with an atom as the class name, put some programs expect to have a *REAL* string in
325 * lpszClass when the CREATESTRUCT is sent with WM_CREATE
326 */
327 if (!HIWORD(cs->lpszClass) ) {
328 if (isUnicode) {
329 GlobalGetAtomNameW( classAtom, (LPWSTR)buffer, sizeof(buffer) );
330 }
331 else {
332 GlobalGetAtomNameA( classAtom, buffer, sizeof(buffer) );
333 }
334 cs->lpszClass = buffer;
335 }
336
337 /* Fix the coordinates */
338 fXDefault = FALSE;
339 fCXDefault = FALSE;
340 if ((cs->x == CW_USEDEFAULT) || (cs->x == CW_USEDEFAULT16))
341 {
342 /* Never believe Microsoft's documentation... CreateWindowEx doc says
343 * that if an overlapped window is created with WS_VISIBLE style bit
344 * set and the x parameter is set to CW_USEDEFAULT, the system ignores
345 * the y parameter. However, disassembling NT implementation (WIN32K.SYS)
346 * reveals that
347 *
348 * 1) not only if checks for CW_USEDEFAULT but also for CW_USEDEFAULT16
349 * 2) it does not ignore the y parameter as the docs claim; instead, it
350 * uses it as second parameter to ShowWindow() unless y is either
351 * CW_USEDEFAULT or CW_USEDEFAULT16.
352 *
353 * The fact that we didn't do 2) caused bogus windows pop up when wine
354 * was running apps that were using this obscure feature. Example -
355 * calc.exe that comes with Win98 (only Win98, it's different from
356 * the one that comes with Win95 and NT)
357 */
358 if ((cs->y != CW_USEDEFAULT) && (cs->y != CW_USEDEFAULT16)) sw = cs->y;
359
360 /* We have saved cs->y, now we can trash it */
361 cs->x = 0;
362 cs->y = 0;
363 fXDefault = TRUE;
364 }
365 if ((cs->cx == CW_USEDEFAULT) || (cs->cx == CW_USEDEFAULT16))
366 {
367 cs->cx = 600; /* FIXME */
368 cs->cy = 400;
369 fCXDefault = TRUE;
370 }
371 if (cs->style & (WS_POPUP | WS_CHILD))
372 {
373 fXDefault = FALSE;
374 if (fCXDefault)
375 {
376 fCXDefault = FALSE;
377 cs->cx = cs->cy = 0;
378 }
379 }
380 if (fXDefault && !fCXDefault) fXDefault = FALSE; //CB: only x positioning doesn't work (calc.exe,cdrlabel.exe)
381
382 if (cs->x < 0) cs->x = 0;
383 if (cs->y < 0) cs->y = 0;
384
385 //Allocate window words
386 nrUserWindowLong = windowClass->getExtraWndWords();
387 if(nrUserWindowLong) {
388 userWindowLong = (ULONG *)_smalloc(nrUserWindowLong);
389 memset(userWindowLong, 0, nrUserWindowLong);
390 }
391
392 if ((cs->style & WS_CHILD) && cs->hwndParent)
393 {
394 SetParent(cs->hwndParent);
395// owner = GetWindowFromHandle(cs->hwndParent);
396 owner = 0;
397/* if(owner == NULL)
398 {
399 dprintf(("HwGetWindowHandleData couldn't find owner window %x!!!", cs->hwndParent));
400 SetLastError(ERROR_INVALID_WINDOW_HANDLE);
401 return FALSE;
402 }*/
403 //SvL: Shell positioning shouldn't be done for child windows! (breaks Notes)
404 fXDefault = fCXDefault = FALSE;
405 }
406 else
407 {
408 SetParent(0);
409 if (!cs->hwndParent || (cs->hwndParent == windowDesktop->getWindowHandle())) {
410 owner = NULL;
411 }
412 else
413 {
414 owner = GetWindowFromHandle(cs->hwndParent)->GetTopParent();
415 if(owner == NULL)
416 {
417 dprintf(("HwGetWindowHandleData couldn't find owner window %x!!!", cs->hwndParent));
418 SetLastError(ERROR_INVALID_WINDOW_HANDLE);
419 return FALSE;
420 }
421 }
422 }
423
424 WINPROC_SetProc((HWINDOWPROC *)&win32wndproc, windowClass->getWindowProc(), WINPROC_GetProcType(windowClass->getWindowProc()), WIN_PROC_WINDOW);
425 hInstance = cs->hInstance;
426 dwStyle = cs->style & ~WS_VISIBLE;
427 dwExStyle = cs->dwExStyle;
428
429 hwndLinkAfter = ((cs->style & (WS_CHILD|WS_MAXIMIZE)) == WS_CHILD) ? HWND_BOTTOM : HWND_TOP;
430
431 /* Correct the window style */
432 if (!(cs->style & WS_CHILD))
433 {
434 dwStyle |= WS_CLIPSIBLINGS;
435 if (!(cs->style & WS_POPUP))
436 {
437 dwStyle |= WS_CAPTION;
438 flags |= WIN_NEED_SIZE;
439 }
440 }
441 if (cs->dwExStyle & WS_EX_DLGMODALFRAME) dwStyle &= ~WS_THICKFRAME;
442
443 //copy pointer of CREATESTRUCT for usage in MsgCreate method
444 tmpcs = cs;
445
446 //Store our window object pointer in thread local memory, so PMWINDOW.CPP can retrieve it
447 TEB *teb = GetThreadTEB();
448 if(teb == NULL) {
449 dprintf(("Window creation failed - teb == NULL")); //this is VERY bad
450 ExitProcess(666);
451 return FALSE;
452 }
453
454 teb->o.odin.newWindow = (ULONG)this;
455
456 DWORD dwOSWinStyle;
457
458 OSLibWinConvertStyle(dwStyle,dwExStyle,&dwOSWinStyle);
459
460 OS2Hwnd = OSLibWinCreateWindow((getParent()) ? getParent()->getOS2WindowHandle() : OSLIB_HWND_DESKTOP,
461 dwOSWinStyle,(char *)windowNameA,
462 (owner) ? owner->getOS2WindowHandle() : ((getParent()) ? getParent()->getOS2WindowHandle() : OSLIB_HWND_DESKTOP),
463 (hwndLinkAfter == HWND_BOTTOM) ? TRUE : FALSE,
464 0, fTaskList,fXDefault | fCXDefault,windowClass->getStyle());
465 if(OS2Hwnd == 0) {
466 dprintf(("Window creation failed!! OS LastError %0x", OSLibWinGetLastError()));
467 SetLastError(ERROR_OUTOFMEMORY); //TODO: Better error
468 return FALSE;
469 }
470 OSLibWinSetVisibleRegionNotify(OS2Hwnd, TRUE);
471 SetLastError(0);
472 return TRUE;
473}
474//******************************************************************************
475//******************************************************************************
476BOOL Win32BaseWindow::MsgCreate(HWND hwndOS2)
477{
478 CREATESTRUCTA *cs = tmpcs; //pointer to CREATESTRUCT used in CreateWindowExA method
479 POINT maxSize, maxPos, minTrack, maxTrack;
480
481 OS2Hwnd = hwndOS2;
482
483 fNoSizeMsg = TRUE;
484
485 if(OSLibWinSetWindowULong(OS2Hwnd, OFFSET_WIN32WNDPTR, (ULONG)this) == FALSE) {
486 dprintf(("WM_CREATE: WinSetWindowULong %X failed!!", OS2Hwnd));
487 SetLastError(ERROR_OUTOFMEMORY); //TODO: Better error
488 return FALSE;
489 }
490 if(OSLibWinSetWindowULong(OS2Hwnd, OFFSET_WIN32PM_MAGIC, WIN32PM_MAGIC) == FALSE) {
491 dprintf(("WM_CREATE: WinSetWindowULong2 %X failed!!", OS2Hwnd));
492 SetLastError(ERROR_OUTOFMEMORY); //TODO: Better error
493 return FALSE;
494 }
495
496 if (HOOK_IsHooked( WH_CBT ))
497 {
498 CBT_CREATEWNDA cbtc;
499 LRESULT ret;
500
501 cbtc.lpcs = cs;
502 cbtc.hwndInsertAfter = hwndLinkAfter;
503 ret = (isUnicode) ? HOOK_CallHooksW(WH_CBT, HCBT_CREATEWND, getWindowHandle(), (LPARAM)&cbtc)
504 : HOOK_CallHooksA(WH_CBT, HCBT_CREATEWND, getWindowHandle(), (LPARAM)&cbtc);
505 if(ret)
506 {
507 dprintf(("CBT-hook returned 0!!"));
508 SetLastError(ERROR_CAN_NOT_COMPLETE); //todo: wrong error
509 return FALSE;
510 }
511 //todo: if hook changes parent, we need to do so too!!!!!!!!!!
512 }
513
514 if (cs->style & WS_HSCROLL)
515 {
516 horzScrollInfo = (SCROLLBAR_INFO*)malloc(sizeof(SCROLLBAR_INFO));
517 horzScrollInfo->MinVal = horzScrollInfo->CurVal = horzScrollInfo->Page = 0;
518 horzScrollInfo->MaxVal = 100;
519 horzScrollInfo->flags = ESB_ENABLE_BOTH;
520 }
521
522 if (cs->style & WS_VSCROLL)
523 {
524 vertScrollInfo = (SCROLLBAR_INFO*)malloc(sizeof(SCROLLBAR_INFO));
525 vertScrollInfo->MinVal = vertScrollInfo->CurVal = vertScrollInfo->Page = 0;
526 vertScrollInfo->MaxVal = 100;
527 vertScrollInfo->flags = ESB_ENABLE_BOTH;
528 }
529
530 if(HIWORD(cs->lpszName))
531 {
532 if (!isUnicode)
533 {
534 wndNameLength = strlen(cs->lpszName);
535 windowNameA = (LPSTR)_smalloc(wndNameLength+1);
536 strcpy(windowNameA,cs->lpszName);
537 windowNameW = (LPWSTR)_smalloc((wndNameLength+1)*sizeof(WCHAR));
538 lstrcpyAtoW(windowNameW,windowNameA);
539 windowNameA[wndNameLength] = 0;
540 windowNameW[wndNameLength] = 0;
541 }
542 else
543 {
544 wndNameLength = lstrlenW((LPWSTR)cs->lpszName);
545 windowNameA = (LPSTR)_smalloc(wndNameLength+1);
546 lstrcpyWtoA(windowNameA,(LPWSTR)cs->lpszName);
547 windowNameW = (LPWSTR)_smalloc((wndNameLength+1)*sizeof(WCHAR));
548 lstrcpyW(windowNameW,(LPWSTR)cs->lpszName);
549 windowNameA[wndNameLength] = 0;
550 windowNameW[wndNameLength] = 0;
551 }
552 }
553
554
555//SvL: This completely messes up MS Word 97 (no button bar, no menu)
556#if 0
557 //adjust CW_USEDEFAULT position
558 if (fXDefault | fCXDefault)
559 {
560 RECT rect;
561
562 //SvL: Returns invalid rectangle (not the expected shell default size)
563 OSLibWinQueryWindowRect(OS2Hwnd,&rect,RELATIVE_TO_SCREEN);
564 if (getParent()) mapWin32Rect(OSLIB_HWND_DESKTOP,getParent()->getOS2WindowHandle(),&rect);
565 if (fXDefault)
566 {
567 cs->x = rect.left;
568 cs->y = rect.top;
569 if (!fCXDefault)
570 {
571 //CB: todo: adjust pos to screen rect
572 }
573 }
574 if (fCXDefault)
575 {
576 cs->cx = rect.right-rect.left;
577 cs->cy = rect.bottom-rect.top;
578 }
579 }
580#endif
581
582 fakeWinBase.hwndThis = OS2Hwnd;
583 fakeWinBase.pWindowClass = windowClass;
584
585 //Set icon from window or class
586 if (hIcon)
587 OSLibWinSetIcon(OS2Hwnd,hIcon);
588 else
589 if (windowClass->getIcon())
590 OSLibWinSetIcon(OS2Hwnd,windowClass->getIcon());
591
592 /* Get class or window DC if needed */
593 if(windowClass->getStyle() & CS_OWNDC) {
594 dprintf(("Class with CS_OWNDC style"));
595 ownDC = GetDCEx(getWindowHandle(), NULL, DCX_USESTYLE);
596 }
597 else
598 if (windowClass->getStyle() & CS_PARENTDC) {
599 fParentDC = TRUE;
600 ownDC = 0;
601 }
602 else
603 if (windowClass->getStyle() & CS_CLASSDC) {
604 dprintf(("WARNING: Class with CS_CLASSDC style!"));
605 ownDC = 0;
606 }
607 /* Set the window menu */
608 if ((dwStyle & (WS_CAPTION | WS_CHILD)) == WS_CAPTION )
609 {
610 if (cs->hMenu) {
611 ::SetMenu(getWindowHandle(), cs->hMenu);
612 }
613 else {
614 if (windowClass->getMenuNameA()) {
615 cs->hMenu = LoadMenuA(windowClass->getInstance(),windowClass->getMenuNameA());
616#if 0 //CB: hack for treeview test cases bug
617if (!cs->hMenu) cs->hMenu = LoadMenuA(windowClass->getInstance(),"MYAPP");
618#endif
619 if (cs->hMenu) ::SetMenu(getWindowHandle(), cs->hMenu );
620 }
621 }
622 }
623 else
624 {
625 setWindowId((DWORD)cs->hMenu);
626 }
627 hSysMenu = (dwStyle & WS_SYSMENU) ? MENU_GetSysMenu(Win32Hwnd,0):0;
628
629 /* Send the WM_GETMINMAXINFO message and fix the size if needed */
630 if ((cs->style & WS_THICKFRAME) || !(cs->style & (WS_POPUP | WS_CHILD)))
631 {
632 GetMinMaxInfo(&maxSize, &maxPos, &minTrack, &maxTrack);
633 if (maxSize.x < cs->cx) cs->cx = maxSize.x;
634 if (maxSize.y < cs->cy) cs->cy = maxSize.y;
635 if (cs->cx < minTrack.x) cs->cx = minTrack.x;
636 if (cs->cy < minTrack.y) cs->cy = minTrack.y;
637 }
638
639 if(cs->style & WS_CHILD)
640 {
641 if(cs->cx < 0) cs->cx = 0;
642 if(cs->cy < 0) cs->cy = 0;
643 }
644 else
645 {
646 if (cs->cx <= 0) cs->cx = 1;
647 if (cs->cy <= 0) cs->cy = 1;
648 }
649
650 //set client & window rectangles from CreateWindowEx CREATESTRUCT
651 rectWindow.left = cs->x;
652 rectWindow.right = cs->x+cs->cx;
653 rectWindow.top = cs->y;
654 rectWindow.bottom = cs->y+cs->cy;
655 rectClient = rectWindow;
656 OffsetRect(&rectClient, -rectClient.left, -rectClient.top);
657
658 /* Send the WM_CREATE message
659 * Perhaps we shouldn't allow width/height changes as well.
660 * See p327 in "Internals".
661 */
662 maxPos.x = rectWindow.left; maxPos.y = rectWindow.top;
663
664 //Note: Solitaire crashes when receiving WM_SIZE messages before WM_CREATE
665 fCreated = TRUE;
666
667 if(fTaskList) {
668 hTaskList = OSLibWinAddToTaskList(OS2Hwnd, windowNameA, (cs->style & WS_VISIBLE) ? 1 : 0);
669 }
670
671 //cs is ascii version of create structure. so use SendInternalMessageA
672 if(SendInternalMessageA(WM_NCCREATE,0,(LPARAM)cs))
673 {
674 RECT tmpRect;
675
676 //CB: recheck flags
677 if (cs->style & (WS_POPUP | WS_CHILD))
678 {
679 fXDefault = FALSE;
680 if (fCXDefault)
681 {
682 fCXDefault = FALSE;
683 cs->cx = cs->cy = 0;
684 rectWindow.right = rectWindow.left;
685 rectWindow.bottom = rectWindow.top;
686 }
687 }
688 tmpRect = rectWindow;
689
690 fCreateSetWindowPos = TRUE;
691
692 //set the window size and update the client
693 SetWindowPos(hwndLinkAfter, tmpRect.left, tmpRect.top, tmpRect.right-tmpRect.left, tmpRect.bottom-tmpRect.top,SWP_NOACTIVATE | SWP_NOREDRAW | SWP_FRAMECHANGED);
694 fNoSizeMsg = FALSE;
695 if (cs->style & WS_VISIBLE) dwStyle |= WS_VISIBLE; //program could change position in WM_CREATE
696 if( (SendInternalMessageA(WM_CREATE, 0, (LPARAM)cs )) != -1 )
697 {
698 if(!(flags & WIN_NEED_SIZE))
699 {
700 SendInternalMessageA(WM_SIZE, SIZE_RESTORED,
701 MAKELONG(rectClient.right-rectClient.left,
702 rectClient.bottom-rectClient.top));
703
704 SendInternalMessageA(WM_MOVE,0,MAKELONG(rectClient.left,rectClient.top));
705 }
706 if( (getStyle() & WS_CHILD) && !(getExStyle() & WS_EX_NOPARENTNOTIFY) )
707 {
708 /* Notify the parent window only */
709 if(getParent() && getParent()->IsWindowDestroyed() == FALSE)
710 {
711 getParent()->SendInternalMessageA(WM_PARENTNOTIFY, MAKEWPARAM(WM_CREATE, getWindowId()), (LPARAM)getWindowHandle());
712 }
713 if(!::IsWindow(getWindowHandle()))
714 {
715 dprintf(("Createwindow: WM_PARENTNOTIFY destroyed window"));
716 goto end;
717 }
718 }
719
720 if(cs->style & WS_VISIBLE) {
721 dwStyle &= ~WS_VISIBLE;
722 ShowWindow(sw);
723 }
724
725 /* Call WH_SHELL hook */
726 if (!(getStyle() & WS_CHILD) && !owner)
727 HOOK_CallHooksA(WH_SHELL, HSHELL_WINDOWCREATED, getWindowHandle(), 0);
728
729 SetLastError(0);
730 return TRUE;
731 }
732 }
733 dprintf(("Window creation FAILED (NCCREATE cancelled creation)"));
734 SetLastError(ERROR_OUTOFMEMORY); //TODO: Better error
735end:
736 return FALSE;
737}
738//******************************************************************************
739//******************************************************************************
740ULONG Win32BaseWindow::MsgQuit()
741{
742 return SendInternalMessageA(WM_QUIT, 0, 0);
743}
744//******************************************************************************
745//******************************************************************************
746ULONG Win32BaseWindow::MsgClose()
747{
748 return SendInternalMessageA(WM_CLOSE,0,0);
749}
750//******************************************************************************
751//******************************************************************************
752ULONG Win32BaseWindow::MsgDestroy()
753{
754 ULONG rc;
755 Win32BaseWindow *child;
756 HWND hwnd = getWindowHandle();
757
758 fIsDestroyed = TRUE;
759
760 if(fDestroyWindowCalled == FALSE)
761 {//this window was destroyed because DestroyWindow was called for it's parent
762 //so: send a WM_PARENTNOTIFY now as that hasn't happened yet
763 if((getStyle() & WS_CHILD) && !(getExStyle() & WS_EX_NOPARENTNOTIFY))
764 {
765 if(getParent() && getParent()->IsWindowDestroyed() == FALSE)
766 {
767 /* Notify the parent window only */
768 getParent()->SendMessageA(WM_PARENTNOTIFY, MAKEWPARAM(WM_DESTROY, getWindowId()), (LPARAM)getWindowHandle());
769 }
770//// else DebugInt3();
771 }
772 }
773 SendInternalMessageA(WM_DESTROY, 0, 0);
774 if(::IsWindow(hwnd) == FALSE) {
775 //object already destroyed, so return immediately
776 return 1;
777 }
778 SendInternalMessageA(WM_NCDESTROY, 0, 0);
779
780 TIMER_KillTimerFromWindow(OS2Hwnd);
781
782 if(getFirstChild() == NULL) {
783 delete this;
784 }
785 else {
786 //make sure no message can ever arrive for this window again (PM or from other win32 windows)
787 OSLibWinSetWindowULong(OS2Hwnd, OFFSET_WIN32WNDPTR, 0);
788 OSLibWinSetWindowULong(OS2Hwnd, OFFSET_WIN32PM_MAGIC, 0);
789 if(Win32Hwnd) {
790 HwFreeWindowHandle(Win32Hwnd);
791 Win32Hwnd = 0;
792 }
793 }
794 return 1;
795}
796//******************************************************************************
797//******************************************************************************
798ULONG Win32BaseWindow::MsgEnable(BOOL fEnable)
799{
800 if(fEnable) {
801 dwStyle &= ~WS_DISABLED;
802 }
803 else dwStyle |= WS_DISABLED;
804
805 return SendInternalMessageA(WM_ENABLE, fEnable, 0);
806}
807//******************************************************************************
808//TODO: SW_PARENTCLOSING/OPENING flag (lParam)
809//******************************************************************************
810ULONG Win32BaseWindow::MsgShow(BOOL fShow)
811{
812 if(fNoSizeMsg || fDestroyWindowCalled) {
813 return 1;
814 }
815
816 if(fShow) {
817 setStyle(getStyle() | WS_VISIBLE);
818 }
819 else setStyle(getStyle() & ~WS_VISIBLE);
820
821 return SendInternalMessageA(WM_SHOWWINDOW, fShow, 0);
822}
823//******************************************************************************
824//******************************************************************************
825ULONG Win32BaseWindow::MsgPosChanging(LPARAM lp)
826{
827 //SvL: Notes crashes when switching views (calls DestroyWindow -> PM sends
828 // a WM_WINDOWPOSCHANGED msg -> crash)
829 if(fNoSizeMsg || fDestroyWindowCalled)
830 return 0;
831
832 return SendInternalMessageA(WM_WINDOWPOSCHANGING, 0, lp);
833}
834//******************************************************************************
835//******************************************************************************
836ULONG Win32BaseWindow::MsgPosChanged(LPARAM lp)
837{
838 //SvL: Notes crashes when switching views (calls DestroyWindow -> PM sends
839 // a WM_WINDOWPOSCHANGED msg -> crash)
840 if(fNoSizeMsg || fDestroyWindowCalled)
841 return 1;
842
843 return SendInternalMessageA(WM_WINDOWPOSCHANGED, 0, lp);
844}
845//******************************************************************************
846//******************************************************************************
847#if 0
848ULONG Win32BaseWindow::MsgMinMax()
849{
850
851}
852#endif
853//******************************************************************************
854//******************************************************************************
855ULONG Win32BaseWindow::MsgScroll(ULONG msg, ULONG scrollCode, ULONG scrollPos)
856{
857 //According to the SDK docs, the scrollbar handle (lParam) is 0 when the standard
858 //window scrollbars send these messages
859 return SendInternalMessageA(msg, MAKELONG(scrollCode, scrollPos), 0);
860}
861//******************************************************************************
862//******************************************************************************
863ULONG Win32BaseWindow::MsgHitTest(MSG *msg)
864{
865 lastHitTestVal = DispatchMsgA(msg);
866
867 dprintf2(("MsgHitTest %x (%d,%d) (%d,%d) (%d,%d) returned %x", getWindowHandle(), LOWORD(msg->lParam), HIWORD(msg->lParam), rectWindow.left, rectWindow.top, rectWindow.right, rectWindow.bottom, lastHitTestVal));
868
869 if (lastHitTestVal == HTTRANSPARENT)
870 return HTOS_TRANSPARENT;
871 else
872 return HTOS_NORMAL;
873}
874//******************************************************************************
875//******************************************************************************
876ULONG Win32BaseWindow::MsgActivate(BOOL fActivate, BOOL fMinimized, HWND hwnd, HWND hwndOS2Win)
877{
878 ULONG rc, procidhwnd = -1, threadidhwnd = 0;
879
880 //SvL: Don't send WM_(NC)ACTIVATE messages when the window is being destroyed
881 if(fDestroyWindowCalled) {
882 return 0;
883 }
884
885 //According to SDK docs, if app returns FALSE & window is being deactivated,
886 //default processing is cancelled
887 //TODO: According to Wine we should proceed anyway if window is sysmodal
888 if(SendInternalMessageA(WM_NCACTIVATE, fActivate, 0) == FALSE && !fActivate)
889 {
890 dprintf(("WARNING: WM_NCACTIVATE return code = FALSE -> cancel processing"));
891 return 0;
892 }
893 /* child windows get WM_CHILDACTIVATE message */
894 if((getStyle() & (WS_CHILD | WS_POPUP)) == WS_CHILD )
895 {
896 SendInternalMessageA(WM_CHILDACTIVATE, 0, 0L);
897 return 0;
898 }
899
900 rc = SendInternalMessageA(WM_ACTIVATE, MAKELONG((fActivate) ? WA_ACTIVE : WA_INACTIVE, fMinimized), hwnd);
901
902 if(hwndOS2Win) {
903 threadidhwnd = O32_GetWindowThreadProcessId(hwndOS2Win, &procidhwnd);
904 }
905
906 if(fActivate) {
907 SendInternalMessageA(WM_ACTIVATEAPP, 1, dwThreadId); //activate; specify window thread id
908 }
909 else SendInternalMessageA(WM_ACTIVATEAPP, 0, threadidhwnd); //deactivate; specify thread id of other process
910 return rc;
911}
912//******************************************************************************
913//******************************************************************************
914ULONG Win32BaseWindow::DispatchMsgA(MSG *msg)
915{
916 return SendInternalMessageA(msg->message, msg->wParam, msg->lParam);
917}
918//******************************************************************************
919//******************************************************************************
920ULONG Win32BaseWindow::DispatchMsgW(MSG *msg)
921{
922 return SendInternalMessageW(msg->message, msg->wParam, msg->lParam);
923}
924//******************************************************************************
925//******************************************************************************
926ULONG Win32BaseWindow::MsgSetFocus(HWND hwnd)
927{
928 //SvL: Don't send WM_(NC)ACTIVATE messages when the window is being destroyed
929 if(fDestroyWindowCalled) {
930 return 0;
931 }
932
933 return SendInternalMessageA(WM_SETFOCUS, hwnd, 0);
934}
935//******************************************************************************
936//******************************************************************************
937ULONG Win32BaseWindow::MsgKillFocus(HWND hwnd)
938{
939 //SvL: Don't send WM_(NC)ACTIVATE messages when the window is being destroyed
940 if(fDestroyWindowCalled) {
941 return 0;
942 }
943 return SendInternalMessageA(WM_KILLFOCUS, hwnd, 0);
944}
945//******************************************************************************
946//******************************************************************************
947ULONG Win32BaseWindow::MsgButton(MSG *msg)
948{
949 BOOL fClick = FALSE;
950
951// dprintf(("MsgButton at (%d,%d)", msg->pt.x, msg->pt.y));
952 switch(msg->message) {
953 case WM_LBUTTONDBLCLK:
954 case WM_RBUTTONDBLCLK:
955 case WM_MBUTTONDBLCLK:
956 if (!(windowClass && windowClass->getClassLongA(GCL_STYLE) & CS_DBLCLKS))
957 {
958 msg->message = msg->message - (WM_LBUTTONDBLCLK - WM_LBUTTONDOWN); //dblclick -> down
959 MsgButton(msg);
960 msg->message++; //button-up
961 return MsgButton(msg);
962 }
963 break;
964 case WM_NCLBUTTONDBLCLK:
965 case WM_NCRBUTTONDBLCLK:
966 case WM_NCMBUTTONDBLCLK:
967 //Docs say CS_DBLCLKS style doesn't matter for non-client double clicks
968 fClick = TRUE;
969 break;
970
971 case WM_LBUTTONDOWN:
972 case WM_RBUTTONDOWN:
973 case WM_MBUTTONDOWN:
974 case WM_NCLBUTTONDOWN:
975 case WM_NCRBUTTONDOWN:
976 case WM_NCMBUTTONDOWN:
977 fClick = TRUE;
978 break;
979 }
980
981 if(fClick)
982 {
983 HWND hwndTop;
984
985 /* Activate the window if needed */
986 hwndTop = (GetTopParent()) ? GetTopParent()->getWindowHandle() : 0;
987
988 HWND hwndActive = GetActiveWindow();
989 if (hwndTop && (getWindowHandle() != hwndActive))
990 {
991 LONG ret = SendInternalMessageA(WM_MOUSEACTIVATE, hwndTop,
992 MAKELONG( lastHitTestVal, msg->message) );
993
994#if 0
995 if ((ret == MA_ACTIVATEANDEAT) || (ret == MA_NOACTIVATEANDEAT))
996 eatMsg = TRUE;
997#endif
998 if(((ret == MA_ACTIVATE) || (ret == MA_ACTIVATEANDEAT))
999 && (hwndTop != GetForegroundWindow()) )
1000 {
1001 Win32BaseWindow *win32top = Win32BaseWindow::GetWindowFromHandle(hwndTop);
1002
1003 //SvL: Calling OSLibSetActiveWindow(hwndTop); causes focus problems
1004 if (win32top) OSLibWinSetFocus(win32top->getOS2WindowHandle());
1005 }
1006 }
1007 }
1008
1009 SendInternalMessageA(WM_SETCURSOR, getWindowHandle(), MAKELONG(lastHitTestVal, msg->message));
1010
1011 return SendInternalMessageA(msg->message, msg->wParam, msg->lParam);
1012}
1013//******************************************************************************
1014//******************************************************************************
1015ULONG Win32BaseWindow::MsgPaint(ULONG tmp1, BOOL select)
1016{
1017 if (select && IsWindowIconic())
1018 return SendInternalMessageA(WM_PAINTICON, 1, 0);
1019 else
1020 return SendInternalMessageA(WM_PAINT, 0, 0);
1021}
1022//******************************************************************************
1023//TODO: Is the clipper region of the window DC equal to the invalidated rectangle?
1024// (or are we simply erasing too much here)
1025//******************************************************************************
1026ULONG Win32BaseWindow::MsgEraseBackGround(HDC hdc)
1027{
1028 ULONG rc;
1029 HDC hdcErase = hdc;
1030
1031 if (hdcErase == 0)
1032 hdcErase = GetDC(getWindowHandle());
1033
1034 if(IsWindowIconic())
1035 rc = SendInternalMessageA(WM_ICONERASEBKGND, hdcErase, 0);
1036 else
1037 rc = SendInternalMessageA(WM_ERASEBKGND, hdcErase, 0);
1038 if (hdc == 0)
1039 ReleaseDC(getWindowHandle(), hdcErase);
1040 return (rc);
1041}
1042//******************************************************************************
1043//******************************************************************************
1044ULONG Win32BaseWindow::MsgMouseMove(MSG *msg)
1045{
1046 //TODO: hiword should be 0 if window enters menu mode (SDK docs)
1047 SendInternalMessageA(WM_SETCURSOR, Win32Hwnd, MAKELONG(lastHitTestVal, msg->message));
1048
1049 //translated message == WM_(NC)MOUSEMOVE
1050 return SendInternalMessageA(msg->message, msg->wParam, msg->lParam);
1051}
1052//******************************************************************************
1053//******************************************************************************
1054ULONG Win32BaseWindow::MsgChar(MSG *msg)
1055{
1056 return DispatchMsgA(msg);
1057}
1058//******************************************************************************
1059//******************************************************************************
1060ULONG Win32BaseWindow::MsgNCPaint()
1061{
1062 RECT rect;
1063
1064 if(GetOS2UpdateRect(this,&rect))
1065 {
1066 HRGN hrgn;
1067 ULONG rc;
1068 RECT client = rectClient;
1069
1070 if ((rect.left >= client.left) && (rect.left < client.right) &&
1071 (rect.right >= client.left) && (rect.right < client.right) &&
1072 (rect.top >= client.top) && (rect.top < client.bottom) &&
1073 (rect.bottom >= client.top) && (rect.bottom < client.bottom))
1074 {
1075 return 0;
1076 }
1077
1078 dprintf(("MsgNCPaint (%d,%d)(%d,%d)", rect.left, rect.top, rect.right, rect.bottom));
1079 hrgn = CreateRectRgnIndirect(&rect);
1080 if (!hrgn) return 0;
1081
1082 rc = SendInternalMessageA(WM_NCPAINT, hrgn, 0);
1083
1084 DeleteObject(hrgn);
1085
1086 return rc;
1087 }
1088 else return 0;
1089}
1090//******************************************************************************
1091//Called when either the frame's size or position has changed (lpWndPos != NULL)
1092//or when the frame layout has changed (i.e. scrollbars added/removed) (lpWndPos == NULL)
1093//******************************************************************************
1094ULONG Win32BaseWindow::MsgFormatFrame(WINDOWPOS *lpWndPos)
1095{
1096 RECT oldWindowRect = rectWindow, client = rectClient, newWindowRect;
1097 WINDOWPOS wndPos;
1098 ULONG rc;
1099
1100 if(lpWndPos)
1101 {
1102 //set new window rectangle
1103 setWindowRect(lpWndPos->x, lpWndPos->y, lpWndPos->x+lpWndPos->cx,
1104 lpWndPos->y+lpWndPos->cy);
1105 newWindowRect = rectWindow;
1106 }
1107 else {
1108 wndPos.hwnd = getWindowHandle();
1109 wndPos.hwndInsertAfter = 0;
1110 newWindowRect= rectWindow;
1111 wndPos.x = newWindowRect.left;
1112 wndPos.y = newWindowRect.top;
1113 wndPos.cx = newWindowRect.right - newWindowRect.left;
1114 wndPos.cy = newWindowRect.bottom - newWindowRect.top;
1115 wndPos.flags = SWP_FRAMECHANGED;
1116 lpWndPos = &wndPos;
1117 }
1118
1119 rc = SendNCCalcSize(TRUE, &newWindowRect, &oldWindowRect, &client, lpWndPos, &rectClient);
1120
1121 dprintf(("MsgFormatFrame: old client rect (%d,%d)(%d,%d), new client (%d,%d)(%d,%d)", client.left, client.top, client.right, client.bottom, rectClient.left, rectClient.top, rectClient.right, rectClient.bottom));
1122 dprintf(("MsgFormatFrame: old window rect (%d,%d)(%d,%d), new window (%d,%d)(%d,%d)", oldWindowRect.left, oldWindowRect.top, oldWindowRect.right, oldWindowRect.bottom, rectWindow.left, rectWindow.top, rectWindow.right, rectWindow.bottom));
1123
1124#if 1
1125//this doesn't always work
1126// if(!fNoSizeMsg && (client.left != rectClient.left || client.top != rectClient.top))
1127 if(!fNoSizeMsg && ((oldWindowRect.right - oldWindowRect.left < rectClient.left
1128 || oldWindowRect.bottom - oldWindowRect.top < rectClient.top) ||
1129 (EqualRect(&oldWindowRect, &rectWindow) && (client.left != rectClient.left || client.top != rectClient.top))))
1130 {
1131 Win32BaseWindow *child = (Win32BaseWindow *)getFirstChild();
1132
1133 //client rectangle has moved -> inform children
1134 dprintf(("MsgFormatFrame -> client rectangle has changed, move children"));
1135 while(child) {
1136 ::SetWindowPos(child->getWindowHandle(),
1137 HWND_TOP, child->getWindowRect()->left,
1138 child->getWindowRect()->top, 0, 0,
1139 SWP_NOACTIVATE|SWP_NOSIZE|SWP_NOZORDER);
1140 child = (Win32BaseWindow *)child->getNextChild();
1141 }
1142 }
1143#endif
1144 return rc;
1145}
1146//******************************************************************************
1147//******************************************************************************
1148ULONG Win32BaseWindow::MsgSetText(LPSTR lpsz, LONG cch)
1149{
1150 return SendInternalMessageA(WM_SETTEXT, 0, (LPARAM)lpsz);
1151}
1152//******************************************************************************
1153//******************************************************************************
1154ULONG Win32BaseWindow::MsgGetTextLength()
1155{
1156 return SendInternalMessageA(WM_GETTEXTLENGTH, 0, 0);
1157}
1158//******************************************************************************
1159//******************************************************************************
1160void Win32BaseWindow::MsgGetText(char *wndtext, ULONG textlength)
1161{
1162 SendInternalMessageA(WM_GETTEXT, textlength, (LPARAM)wndtext);
1163}
1164//******************************************************************************
1165//******************************************************************************
1166LONG Win32BaseWindow::sendHitTest(ULONG lParam)
1167{
1168 lastHitTestVal = SendInternalMessageA(WM_NCHITTEST, 0, lParam);
1169 return lastHitTestVal;
1170}
1171//******************************************************************************
1172//******************************************************************************
1173BOOL Win32BaseWindow::isMDIClient()
1174{
1175 return FALSE;
1176}
1177//******************************************************************************
1178//******************************************************************************
1179BOOL Win32BaseWindow::isMDIChild()
1180{
1181 return FALSE;
1182}
1183//******************************************************************************
1184//TODO: Not complete
1185//******************************************************************************
1186BOOL Win32BaseWindow::isFrameWindow()
1187{
1188 if(getParent() == NULL)
1189 return TRUE;
1190
1191 return FALSE;
1192}
1193//******************************************************************************
1194//******************************************************************************
1195BOOL Win32BaseWindow::isDesktopWindow()
1196{
1197 return FALSE;
1198}
1199//******************************************************************************
1200//******************************************************************************
1201BOOL Win32BaseWindow::IsWindowIconic()
1202{
1203 return ((getStyle() & WS_MINIMIZE) && windowClass->getIcon());
1204}
1205//******************************************************************************
1206//******************************************************************************
1207SCROLLBAR_INFO *Win32BaseWindow::getScrollInfo(int nBar)
1208{
1209 switch(nBar)
1210 {
1211 case SB_HORZ:
1212 if (!horzScrollInfo)
1213 {
1214 horzScrollInfo = (SCROLLBAR_INFO*)malloc(sizeof(SCROLLBAR_INFO));
1215 if (!horzScrollInfo) break;
1216 horzScrollInfo->MinVal = horzScrollInfo->CurVal = horzScrollInfo->Page = 0;
1217 horzScrollInfo->MaxVal = 100;
1218 horzScrollInfo->flags = ESB_ENABLE_BOTH;
1219 }
1220 return horzScrollInfo;
1221
1222 case SB_VERT:
1223 if (!vertScrollInfo)
1224 {
1225 vertScrollInfo = (SCROLLBAR_INFO*)malloc(sizeof(SCROLLBAR_INFO));
1226 if (!vertScrollInfo) break;
1227 vertScrollInfo->MinVal = vertScrollInfo->CurVal = vertScrollInfo->Page = 0;
1228 vertScrollInfo->MaxVal = 100;
1229 vertScrollInfo->flags = ESB_ENABLE_BOTH;
1230 }
1231 return vertScrollInfo;
1232 }
1233
1234 return NULL;
1235}
1236//******************************************************************************
1237//******************************************************************************
1238LRESULT Win32BaseWindow::DefWndControlColor(UINT ctlType, HDC hdc)
1239{
1240 //SvL: Set background color to default button color (not window (white))
1241 if(ctlType == CTLCOLOR_BTN)
1242 {
1243 SetBkColor(hdc, GetSysColor(COLOR_BTNFACE));
1244 SetTextColor(hdc, GetSysColor(COLOR_WINDOWTEXT));
1245 return GetSysColorBrush(COLOR_BTNFACE);
1246 }
1247 //SvL: Set background color to default dialog color if window is dialog
1248 if((ctlType == CTLCOLOR_DLG || ctlType == CTLCOLOR_STATIC) && IsDialog()) {
1249 SetBkColor(hdc, GetSysColor(COLOR_BTNFACE));
1250 SetTextColor(hdc, GetSysColor(COLOR_WINDOWTEXT));
1251 return GetSysColorBrush(COLOR_BTNFACE);
1252 }
1253
1254 if( ctlType == CTLCOLOR_SCROLLBAR)
1255 {
1256 HBRUSH hb = GetSysColorBrush(COLOR_SCROLLBAR);
1257 COLORREF bk = GetSysColor(COLOR_3DHILIGHT);
1258 SetTextColor( hdc, GetSysColor(COLOR_3DFACE));
1259 SetBkColor( hdc, bk);
1260
1261 /* if COLOR_WINDOW happens to be the same as COLOR_3DHILIGHT
1262 * we better use 0x55aa bitmap brush to make scrollbar's background
1263 * look different from the window background.
1264 */
1265 if (bk == GetSysColor(COLOR_WINDOW)) {
1266 return GetPattern55AABrush();
1267 }
1268
1269 UnrealizeObject( hb );
1270 return (LRESULT)hb;
1271 }
1272
1273 SetTextColor( hdc, GetSysColor(COLOR_WINDOWTEXT));
1274
1275 if ((ctlType == CTLCOLOR_EDIT) || (ctlType == CTLCOLOR_LISTBOX))
1276 {
1277 SetBkColor( hdc, GetSysColor(COLOR_WINDOW) );
1278 }
1279 else
1280 {
1281 SetBkColor( hdc, GetSysColor(COLOR_3DFACE) );
1282 return (LRESULT)GetSysColorBrush(COLOR_3DFACE);
1283 }
1284 return (LRESULT)GetSysColorBrush(COLOR_WINDOW);
1285}
1286//******************************************************************************
1287//******************************************************************************
1288LRESULT Win32BaseWindow::DefWndPrint(HDC hdc,ULONG uFlags)
1289{
1290 /*
1291 * Visibility flag.
1292 */
1293 if ( (uFlags & PRF_CHECKVISIBLE) &&
1294 !IsWindowVisible() )
1295 return 0;
1296
1297 /*
1298 * Unimplemented flags.
1299 */
1300 if ( (uFlags & PRF_CHILDREN) ||
1301 (uFlags & PRF_OWNED) ||
1302 (uFlags & PRF_NONCLIENT) )
1303 {
1304 dprintf(("WM_PRINT message with unsupported flags\n"));
1305 }
1306
1307 /*
1308 * Background
1309 */
1310 if ( uFlags & PRF_ERASEBKGND)
1311 SendInternalMessageA(WM_ERASEBKGND, (WPARAM)hdc, 0);
1312
1313 /*
1314 * Client area
1315 */
1316 if ( uFlags & PRF_CLIENT)
1317 SendInternalMessageA(WM_PRINTCLIENT, (WPARAM)hdc, PRF_CLIENT);
1318
1319
1320 return 0;
1321}
1322//******************************************************************************
1323//******************************************************************************
1324LRESULT Win32BaseWindow::DefWindowProcA(UINT Msg, WPARAM wParam, LPARAM lParam)
1325{
1326 switch(Msg)
1327 {
1328 case WM_CLOSE:
1329 dprintf(("DefWindowProcA: WM_CLOSE %x", getWindowHandle()));
1330 DestroyWindow();
1331 return 0;
1332
1333 case WM_GETTEXTLENGTH:
1334 return wndNameLength;
1335
1336 case WM_GETTEXT:
1337 if (!lParam || !wParam) return 0;
1338 if (!windowNameA) ((LPSTR)lParam)[0] = 0;
1339 else lstrcpynA((LPSTR)lParam, windowNameA, wParam);
1340 return min(wndNameLength, wParam);
1341
1342 case WM_SETTEXT:
1343 {
1344 LPCSTR lpsz = (LPCSTR)lParam;
1345
1346 if(windowNameA) free(windowNameA);
1347 if(windowNameW) free(windowNameW);
1348 if (lParam)
1349 {
1350 wndNameLength = strlen(lpsz);
1351 windowNameA = (LPSTR)_smalloc(wndNameLength+1);
1352 strcpy(windowNameA, lpsz);
1353 windowNameW = (LPWSTR)_smalloc((wndNameLength+1)*sizeof(WCHAR));
1354 lstrcpyAtoW(windowNameW, windowNameA);
1355 }
1356 else
1357 {
1358 windowNameA = NULL;
1359 windowNameW = NULL;
1360 wndNameLength = 0;
1361 }
1362 dprintf(("WM_SETTEXT of %x to %s\n", Win32Hwnd, lParam));
1363 if ((dwStyle & WS_CAPTION) == WS_CAPTION)
1364 {
1365 HandleNCPaint((HRGN)1);
1366 if(hTaskList) {
1367 OSLibWinChangeTaskList(hTaskList, OS2Hwnd, getWindowNameA(), (getStyle() & WS_VISIBLE) ? 1 : 0);
1368 }
1369 }
1370
1371 return TRUE;
1372 }
1373
1374 case WM_SETREDRAW:
1375 {
1376 if (wParam)
1377 {
1378 setStyle(getStyle() | WS_VISIBLE);
1379 OSLibWinEnableWindowUpdate(OS2Hwnd,TRUE);
1380 }
1381 else
1382 {
1383 if (getStyle() & WS_VISIBLE)
1384 {
1385 setStyle(getStyle() & ~WS_VISIBLE);
1386 OSLibWinEnableWindowUpdate(OS2Hwnd,FALSE);
1387 }
1388 }
1389 return 0;
1390 }
1391
1392 case WM_CTLCOLORMSGBOX:
1393 case WM_CTLCOLOREDIT:
1394 case WM_CTLCOLORLISTBOX:
1395 case WM_CTLCOLORBTN:
1396 case WM_CTLCOLORDLG:
1397 case WM_CTLCOLORSTATIC:
1398 case WM_CTLCOLORSCROLLBAR:
1399 return DefWndControlColor(Msg - WM_CTLCOLORMSGBOX, (HDC)wParam);
1400
1401 case WM_CTLCOLOR:
1402 return DefWndControlColor(HIWORD(lParam), (HDC)wParam);
1403
1404 case WM_VKEYTOITEM:
1405 case WM_CHARTOITEM:
1406 return -1;
1407
1408 case WM_PARENTNOTIFY:
1409 return 0;
1410
1411 case WM_MOUSEACTIVATE:
1412 {
1413 dprintf(("DefWndProc: WM_MOUSEACTIVATE for %x Msg %s", Win32Hwnd, GetMsgText(HIWORD(lParam))));
1414 if(getStyle() & WS_CHILD && !(getExStyle() & WS_EX_NOPARENTNOTIFY) )
1415 {
1416 if(getParent()) {
1417 LRESULT rc = getParent()->SendInternalMessageA(WM_MOUSEACTIVATE, wParam, lParam );
1418 if(rc) return rc;
1419 }
1420 }
1421 return (LOWORD(lParam) == HTCAPTION) ? MA_NOACTIVATE : MA_ACTIVATE;
1422 }
1423
1424 case WM_ACTIVATE:
1425 /* The default action in Windows is to set the keyboard focus to
1426 * the window, if it's being activated and not minimized */
1427 if (LOWORD(wParam) != WA_INACTIVE) {
1428 if(!(getStyle() & WS_MINIMIZE))
1429 SetFocus(getWindowHandle());
1430 }
1431 return 0;
1432
1433 case WM_SETCURSOR:
1434 {
1435 dprintf(("DefWndProc: WM_SETCURSOR for %x Msg %s", Win32Hwnd, GetMsgText(HIWORD(lParam))));
1436 if((getStyle() & WS_CHILD) && !(getExStyle() & WS_EX_NOPARENTNOTIFY))
1437 {
1438 if(getParent()) {
1439 LRESULT rc = getParent()->SendInternalMessageA(WM_SETCURSOR, wParam, lParam);
1440 if(rc) return rc;
1441 }
1442 }
1443 if (wParam == Win32Hwnd)
1444 {
1445 HCURSOR hCursor;
1446
1447 switch(LOWORD(lParam))
1448 {
1449 case HTCLIENT:
1450 hCursor = windowClass ? windowClass->getCursor():LoadCursorA(0,IDC_ARROWA);
1451 break;
1452
1453 case HTLEFT:
1454 case HTRIGHT:
1455 hCursor = LoadCursorA(0,IDC_SIZEWEA);
1456 break;
1457
1458 case HTTOP:
1459 case HTBOTTOM:
1460 hCursor = LoadCursorA(0,IDC_SIZENSA);
1461 break;
1462
1463 case HTTOPLEFT:
1464 case HTBOTTOMRIGHT:
1465 hCursor = LoadCursorA(0,IDC_SIZENWSEA);
1466 break;
1467
1468 case HTTOPRIGHT:
1469 case HTBOTTOMLEFT:
1470 hCursor = LoadCursorA(0,IDC_SIZENESWA);
1471 break;
1472
1473 default:
1474 hCursor = LoadCursorA(0,IDC_ARROWA);
1475 break;
1476 }
1477
1478 if (hCursor)
1479 {
1480 SetCursor(hCursor);
1481 return 1;
1482 }
1483 else return 0;
1484 }
1485 else return 0;
1486 }
1487
1488 case WM_MOUSEMOVE:
1489 return 0;
1490
1491 case WM_WINDOWPOSCHANGED:
1492 {
1493 PWINDOWPOS wpos = (PWINDOWPOS)lParam;
1494 WPARAM wp = SIZE_RESTORED;
1495
1496 if (!(wpos->flags & SWP_NOMOVE) && !(wpos->flags & SWP_NOCLIENTMOVE))
1497 {
1498 SendInternalMessageA(WM_MOVE, 0, MAKELONG(rectClient.left,rectClient.top));
1499 }
1500 if (!(wpos->flags & SWP_NOSIZE) && !(wpos->flags & SWP_NOCLIENTSIZE))
1501 {
1502 if (dwStyle & WS_MAXIMIZE) wp = SIZE_MAXIMIZED;
1503 else
1504 if (dwStyle & WS_MINIMIZE) wp = SIZE_MINIMIZED;
1505
1506 SendInternalMessageA(WM_SIZE, wp, MAKELONG(rectClient.right - rectClient.left,
1507 rectClient.bottom - rectClient.top));
1508 }
1509 return 0;
1510 }
1511 case WM_WINDOWPOSCHANGING:
1512 return HandleWindowPosChanging((WINDOWPOS *)lParam);
1513
1514 case WM_ERASEBKGND:
1515 case WM_ICONERASEBKGND:
1516 {
1517 RECT rect;
1518 int rc;
1519
1520 if (!windowClass || !windowClass->getBackgroundBrush()) return 0;
1521
1522 rc = GetClipBox( (HDC)wParam, &rect );
1523 if ((rc == SIMPLEREGION) || (rc == COMPLEXREGION))
1524 {
1525 HBRUSH hBrush = windowClass->getBackgroundBrush();
1526
1527 if (hBrush <= (HBRUSH)(SYSCOLOR_GetLastColor()+1))
1528 hBrush = GetSysColorBrush(hBrush-1);
1529
1530 FillRect( (HDC)wParam, &rect, hBrush);
1531 }
1532 return 1;
1533 }
1534
1535 case WM_PRINT:
1536 return DefWndPrint(wParam,lParam);
1537
1538 case WM_PAINTICON:
1539 case WM_PAINT:
1540 {
1541 PAINTSTRUCT ps;
1542 HDC hdc = BeginPaint(getWindowHandle(), &ps );
1543 if( hdc )
1544 {
1545 if( (getStyle() & WS_MINIMIZE) && (getWindowClass()->getIcon() && hIcon))
1546 {
1547 int x = (rectWindow.right - rectWindow.left - GetSystemMetrics(SM_CXICON))/2;
1548 int y = (rectWindow.bottom - rectWindow.top - GetSystemMetrics(SM_CYICON))/2;
1549 dprintf(("Painting class icon: vis rect=(%i,%i - %i,%i)\n", ps.rcPaint.left, ps.rcPaint.top, ps.rcPaint.right, ps.rcPaint.bottom ));
1550 DrawIcon(hdc, x, y, hIcon ? hIcon:getWindowClass()->getIcon() );
1551 }
1552 EndPaint(getWindowHandle(), &ps );
1553 }
1554 return 0;
1555 }
1556
1557 case WM_GETDLGCODE:
1558 return 0;
1559
1560 case WM_NCPAINT:
1561 return HandleNCPaint((HRGN)wParam);
1562
1563 case WM_NCACTIVATE:
1564 return HandleNCActivate(wParam);
1565
1566 case WM_NCCREATE:
1567 return(TRUE);
1568
1569 case WM_NCDESTROY:
1570 return 0;
1571
1572 case WM_NCCALCSIZE:
1573 return HandleNCCalcSize((BOOL)wParam,(RECT*)lParam);
1574
1575 case WM_NCLBUTTONDOWN:
1576 return HandleNCLButtonDown(wParam,lParam);
1577
1578 case WM_LBUTTONDBLCLK:
1579 case WM_NCLBUTTONDBLCLK:
1580 return HandleNCLButtonDblClk(wParam,lParam);
1581
1582 case WM_NCRBUTTONDOWN:
1583 case WM_NCRBUTTONDBLCLK:
1584 case WM_NCMBUTTONDOWN:
1585 case WM_NCMBUTTONDBLCLK:
1586 if (lastHitTestVal == HTERROR) MessageBeep(MB_ICONEXCLAMATION);
1587 return 0;
1588
1589 case WM_NCRBUTTONUP:
1590 return HandleNCRButtonUp(wParam,lParam);
1591
1592 case WM_NCMBUTTONUP:
1593 return 0;
1594
1595 case WM_NCHITTEST:
1596 {
1597 POINT point;
1598 LRESULT retvalue;
1599
1600 point.x = (SHORT)LOWORD(lParam);
1601 point.y = (SHORT)HIWORD(lParam);
1602
1603 retvalue = HandleNCHitTest(point);
1604#if 0 //CB: let the Corel people fix the bugs first
1605 if(retvalue == HTMENU)
1606 MENU_TrackMouseMenuBar_MouseMove(Win32Hwnd,point,TRUE);
1607 else
1608 MENU_TrackMouseMenuBar_MouseMove(Win32Hwnd,point,FALSE);
1609#endif
1610 return retvalue;
1611 }
1612
1613 case WM_SYSCOMMAND:
1614 {
1615 POINT point;
1616
1617 point.x = LOWORD(lParam);
1618 point.y = HIWORD(lParam);
1619 return HandleSysCommand(wParam,&point);
1620 }
1621
1622 case WM_SYSKEYDOWN:
1623 if(wParam == VK_F4) /* try to close the window */
1624 {
1625 Win32BaseWindow *window = GetTopParent();
1626 if(window && !(window->getClass()->getStyle() & CS_NOCLOSE))
1627 PostMessageA(window->getWindowHandle(), WM_SYSCOMMAND, SC_CLOSE, 0);
1628 return 0;
1629 }
1630
1631 Win32BaseWindow *siblingWindow;
1632 HWND sibling;
1633 char nameBuffer [40], mnemonic;
1634 int nameLength;
1635
1636 GetWindowTextA (nameBuffer, 40);
1637
1638 // search all sibling to see it this key is their mnemonic
1639 sibling = GetWindow (GW_HWNDFIRST);
1640 while (sibling != 0) {
1641 siblingWindow = GetWindowFromHandle (sibling);
1642 nameLength = siblingWindow->GetWindowTextA (nameBuffer, 40);
1643
1644 // find the siblings mnemonic
1645 mnemonic = '\0';
1646 for (int i=0 ; i<nameLength ; i++) {
1647 if (nameBuffer [i] == '&') {
1648 mnemonic = nameBuffer [i+1];
1649 if ((mnemonic >= 'a') && (mnemonic <= 'z'))
1650 mnemonic -= 32; // make it uppercase
1651 break; // stop searching
1652 }
1653 }
1654
1655 // key matches siblings mnemonic, send mouseclick
1656 if (mnemonic == (char) wParam) {
1657 siblingWindow->SendInternalMessageA (BM_CLICK, 0, 0);
1658 }
1659
1660 sibling = siblingWindow->GetNextWindow (GW_HWNDNEXT);
1661 }
1662
1663 return 0;
1664
1665#if 0 //CB: todo: MSDN docu: Windown handles these messages and not WM_SYSCHAR (the code below doesn't work)
1666 case WM_KEYDOWN:
1667 case WM_KEYUP:
1668 case WM_SYSKEYDOWN:
1669 case WM_SYSKEYUP:
1670#endif
1671
1672 case WM_SYSCHAR:
1673 {
1674 int iMenuSysKey = 0;
1675 if (wParam == VK_RETURN && (getStyle() & WS_MINIMIZE))
1676 {
1677 PostMessageA(getWindowHandle(), WM_SYSCOMMAND,
1678 (WPARAM)SC_RESTORE, 0L );
1679 break;
1680 }
1681 if((HIWORD(lParam) & KEYDATA_ALT) && wParam)
1682 {
1683 if (wParam == VK_TAB || wParam == VK_ESCAPE || wParam == VK_F4)
1684 break;
1685 if (wParam == VK_SPACE && (getStyle() & WS_CHILD)) {
1686 getParent()->SendMessageA(Msg, wParam, lParam );
1687 }
1688 else SendMessageA(WM_SYSCOMMAND, (WPARAM)SC_KEYMENU, (LPARAM)(DWORD)wParam );
1689 }
1690#if 0
1691 else /* check for Ctrl-Esc */
1692 if (wParam != VK_ESCAPE) MessageBeep(0);
1693 break;
1694#endif
1695 }
1696
1697 case WM_SETHOTKEY:
1698 hotkey = wParam;
1699 return 1; //CB: always successful
1700
1701 case WM_GETHOTKEY:
1702 return hotkey;
1703
1704 case WM_CONTEXTMENU:
1705 if ((dwStyle & WS_CHILD) && getParent())
1706 getParent()->SendInternalMessageA(WM_CONTEXTMENU,wParam,lParam);
1707 return 0;
1708
1709 case WM_SHOWWINDOW:
1710 if (!lParam) return 0; /* sent from ShowWindow */
1711 if (!(dwStyle & WS_POPUP) || !owner) return 0;
1712 if ((dwStyle & WS_VISIBLE) && wParam) return 0;
1713 else if (!(dwStyle & WS_VISIBLE) && !wParam) return 0;
1714 ShowWindow(wParam ? SW_SHOW:SW_HIDE);
1715 return 0;
1716
1717 case WM_CANCELMODE:
1718 if (getParent() == windowDesktop) EndMenu();
1719 if (GetCapture() == Win32Hwnd) ReleaseCapture();
1720 return 0;
1721
1722 case WM_DROPOBJECT:
1723 return DRAG_FILE;
1724
1725 case WM_QUERYDROPOBJECT:
1726 return (dwExStyle & WS_EX_ACCEPTFILES) ? 1:0;
1727
1728 case WM_QUERYDRAGICON:
1729 {
1730 HICON hDragIcon = windowClass->getCursor();
1731 UINT len;
1732
1733 if(hDragIcon) return (LRESULT)hDragIcon;
1734 for(len = 1; len < 64; len++)
1735 {
1736 hDragIcon = LoadIconA(hInstance,MAKEINTRESOURCEA(len));
1737 if(hDragIcon)
1738 return (LRESULT)hDragIcon;
1739 }
1740 return (LRESULT)LoadIconA(0,IDI_APPLICATIONA);
1741 }
1742
1743 case WM_QUERYOPEN:
1744 case WM_QUERYENDSESSION:
1745 return 1;
1746
1747 case WM_NOTIFYFORMAT:
1748 return IsWindowUnicode() ? NFR_UNICODE:NFR_ANSI;
1749
1750 case WM_SETICON:
1751 case WM_GETICON:
1752 {
1753 LRESULT result = 0;
1754
1755 /* Set the appropriate icon members in the window structure. */
1756 if (wParam == ICON_SMALL)
1757 {
1758 result = hIconSm;
1759 if (Msg == WM_SETICON)
1760 hIconSm = (HICON)lParam;
1761 }
1762 else
1763 {
1764 result = hIcon;
1765 if (Msg == WM_SETICON)
1766 {
1767 hIcon = (HICON)lParam;
1768 if ((dwStyle & WS_CAPTION) == WS_CAPTION)
1769 OSLibWinSetIcon(OS2Hwnd,hIcon);
1770 }
1771 }
1772 if ((Msg == WM_SETICON) && ((dwStyle & WS_CAPTION) == WS_CAPTION))
1773 HandleNCPaint((HRGN)1);
1774
1775 return result;
1776 }
1777
1778 case WM_HELP:
1779 if (getParent()) getParent()->SendInternalMessageA(Msg,wParam,lParam);
1780 break;
1781
1782 case WM_NOTIFY:
1783 return 0; //comctl32 controls expect this
1784
1785 default:
1786 return 0;
1787 }
1788 return 0;
1789}
1790//******************************************************************************
1791//******************************************************************************
1792LRESULT Win32BaseWindow::DefWindowProcW(UINT Msg, WPARAM wParam, LPARAM lParam)
1793{
1794 switch(Msg)
1795 {
1796 case WM_GETTEXTLENGTH:
1797 return wndNameLength;
1798
1799 case WM_GETTEXT:
1800 if (!lParam || !wParam) return 0;
1801 if (!windowNameW) ((LPWSTR)lParam)[0] = 0;
1802 else lstrcpynW((LPWSTR)lParam,windowNameW,wParam);
1803 return min(wndNameLength,wParam);
1804
1805 case WM_SETTEXT:
1806 {
1807 LPWSTR lpsz = (LPWSTR)lParam;
1808
1809 if(windowNameA) free(windowNameA);
1810 if(windowNameW) free(windowNameW);
1811 if (lParam)
1812 {
1813 wndNameLength = lstrlenW(lpsz);
1814 windowNameA = (LPSTR)_smalloc(wndNameLength+1);
1815 lstrcpyWtoA(windowNameA,lpsz);
1816 windowNameW = (LPWSTR)_smalloc((wndNameLength+1)*sizeof(WCHAR));
1817 lstrcpyW(windowNameW,lpsz);
1818 }
1819 else
1820 {
1821 windowNameA = NULL;
1822 windowNameW = NULL;
1823 wndNameLength = 0;
1824 }
1825 dprintf(("WM_SETTEXT of %x\n",Win32Hwnd));
1826 if ((dwStyle & WS_CAPTION) == WS_CAPTION)
1827 {
1828 HandleNCPaint((HRGN)1);
1829 if(hTaskList) {
1830 OSLibWinChangeTaskList(hTaskList, OS2Hwnd, getWindowNameA(), (getStyle() & WS_VISIBLE) ? 1 : 0);
1831 }
1832 }
1833
1834 return TRUE;
1835 }
1836
1837 default:
1838 return DefWindowProcA(Msg, wParam, lParam);
1839 }
1840}
1841//******************************************************************************
1842//******************************************************************************
1843LRESULT Win32BaseWindow::SendMessageA(ULONG Msg, WPARAM wParam, LPARAM lParam)
1844{
1845 //if the destination window is created by this process & thread, call window proc directly
1846 if(dwProcessId == currentProcessId && dwThreadId == GetCurrentThreadId()) {
1847 return SendInternalMessageA(Msg, wParam, lParam);
1848 }
1849 //otherwise use WinSendMsg to send it to the right process/thread
1850 dprintf(("SendMessages (inter-process) %x %x %x %x", getWindowHandle(), Msg, wParam, lParam));
1851 return OSLibSendMessage(getOS2WindowHandle(), Msg, wParam, lParam, FALSE);
1852}
1853//******************************************************************************
1854//******************************************************************************
1855LRESULT Win32BaseWindow::SendMessageW(ULONG Msg, WPARAM wParam, LPARAM lParam)
1856{
1857 //if the destination window is created by this process & thread, call window proc directly
1858 if(dwProcessId == currentProcessId && dwThreadId == GetCurrentThreadId()) {
1859 return SendInternalMessageW(Msg, wParam, lParam);
1860 }
1861 //otherwise use WinSendMsg to send it to the right process/thread
1862 return OSLibSendMessage(getOS2WindowHandle(), Msg, wParam, lParam, TRUE);
1863}
1864//******************************************************************************
1865//Called as a result of an OS/2 message or called from a class method
1866//******************************************************************************
1867LRESULT Win32BaseWindow::SendInternalMessageA(ULONG Msg, WPARAM wParam, LPARAM lParam)
1868{
1869 LRESULT rc;
1870 BOOL fInternalMsgBackup = fInternalMsg;
1871
1872 //if the destination window was created by this process & thread, call window proc directly
1873 if(dwProcessId != currentProcessId || dwThreadId != GetCurrentThreadId()) {
1874 dprintf(("SendMessages (inter-process) %x %x %x %x", getWindowHandle(), Msg, wParam, lParam));
1875 return OSLibSendMessage(getOS2WindowHandle(), Msg, wParam, lParam, FALSE);
1876 }
1877
1878 DebugPrintMessage(getWindowHandle(), Msg, wParam, lParam, FALSE, TRUE);
1879
1880 CallWindowHookProc(WH_CALLWNDPROC, Msg, wParam, lParam, FALSE);
1881
1882 fInternalMsg = TRUE;
1883 switch(Msg)
1884 {
1885 case WM_CREATE:
1886 {
1887 if(CallWindowProcA(win32wndproc, getWindowHandle(), WM_CREATE, 0, lParam) == -1) {
1888 dprintf(("WM_CREATE returned -1\n"));
1889 rc = -1; //don't create window
1890 break;
1891 }
1892 rc = 0;
1893 break;
1894 }
1895 case WM_LBUTTONDOWN:
1896 case WM_MBUTTONDOWN:
1897 case WM_RBUTTONDOWN:
1898 {
1899 if (getParent())
1900 {
1901 POINTS pt = MAKEPOINTS(lParam);
1902 POINT point;
1903
1904 point.x = pt.x;
1905 point.y = pt.y;
1906 MapWindowPoints(getWindowHandle(), getParent()->getWindowHandle(), &point, 1);
1907 NotifyParent(Msg,wParam,MAKELPARAM(point.x,point.y));
1908 }
1909 rc = win32wndproc(getWindowHandle(), Msg, wParam, lParam);
1910 break;
1911 }
1912
1913 case WM_DESTROY:
1914 rc = win32wndproc(getWindowHandle(), WM_DESTROY, 0, 0);
1915 break;
1916
1917 default:
1918 rc = CallWindowProcA(win32wndproc, getWindowHandle(), Msg, wParam, lParam);
1919 break;
1920 }
1921 fInternalMsg = fInternalMsgBackup;
1922 return rc;
1923}
1924//******************************************************************************
1925//Called as a result of an OS/2 message or called from a class method
1926//******************************************************************************
1927LRESULT Win32BaseWindow::SendInternalMessageW(ULONG Msg, WPARAM wParam, LPARAM lParam)
1928{
1929 LRESULT rc;
1930 BOOL fInternalMsgBackup = fInternalMsg;
1931
1932 //if the destination window was created by this process & thread, call window proc directly
1933 if(dwProcessId != currentProcessId || dwThreadId != GetCurrentThreadId()) {
1934 dprintf(("SendMessages (inter-process) %x %x %x %x", getWindowHandle(), Msg, wParam, lParam));
1935 return OSLibSendMessage(getOS2WindowHandle(), Msg, wParam, lParam, FALSE);
1936 }
1937
1938 DebugPrintMessage(getWindowHandle(), Msg, wParam, lParam, TRUE, TRUE);
1939
1940 CallWindowHookProc(WH_CALLWNDPROC, Msg, wParam, lParam, TRUE);
1941
1942 fInternalMsg = TRUE;
1943 switch(Msg)
1944 {
1945 case WM_CREATE:
1946 {
1947 if(CallWindowProcW(win32wndproc, getWindowHandle(), WM_CREATE, 0, lParam) == -1) {
1948 dprintf(("WM_CREATE returned -1\n"));
1949 rc = -1; //don't create window
1950 break;
1951 }
1952 rc = 0;
1953 break;
1954 }
1955 case WM_LBUTTONDOWN:
1956 case WM_MBUTTONDOWN:
1957 case WM_RBUTTONDOWN:
1958 NotifyParent(Msg, wParam, lParam);
1959 rc = win32wndproc(getWindowHandle(), Msg, wParam, lParam);
1960 break;
1961
1962 case WM_DESTROY:
1963 rc = win32wndproc(getWindowHandle(), WM_DESTROY, 0, 0);
1964 break;
1965 default:
1966 rc = CallWindowProcW(win32wndproc, getWindowHandle(), Msg, wParam, lParam);
1967 break;
1968 }
1969 fInternalMsg = fInternalMsgBackup;
1970 return rc;
1971}
1972//******************************************************************************
1973//******************************************************************************
1974void Win32BaseWindow::CallWindowHookProc(ULONG hooktype, ULONG Msg, WPARAM wParam, LPARAM lParam, BOOL fUnicode)
1975{
1976 CWPSTRUCT cwp;
1977
1978 cwp.lParam = lParam;
1979 cwp.wParam = wParam;
1980 cwp.message = Msg;
1981 cwp.hwnd = getWindowHandle();
1982
1983 switch(hooktype) {
1984 case WH_CALLWNDPROC:
1985 if(fUnicode) {
1986 HOOK_CallHooksW(WH_CALLWNDPROC, HC_ACTION, 1, (LPARAM)&cwp);
1987 }
1988 else HOOK_CallHooksA(WH_CALLWNDPROC, HC_ACTION, 1, (LPARAM)&cwp);
1989 break;
1990 }
1991}
1992//******************************************************************************
1993//TODO: Do this more efficiently
1994//******************************************************************************
1995LRESULT Win32BaseWindow::BroadcastMessageA(int type, UINT msg, WPARAM wParam, LPARAM lParam)
1996{
1997 Win32BaseWindow *window;
1998 HWND hwnd = WNDHANDLE_MAGIC_HIGHWORD;
1999
2000 dprintf(("BroadCastMessageA %x %x %x", msg, wParam, lParam, GetFS()));
2001
2002 for(int i=0;i<MAX_WINDOW_HANDLES;i++) {
2003 window = GetWindowFromHandle(hwnd++);
2004 if(window) {
2005 if ((window->getStyle() & WS_POPUP) || ((window->getStyle() & WS_CAPTION) == WS_CAPTION))
2006 {
2007 if(type == BROADCAST_SEND) {
2008 ::SendMessageA(window->getWindowHandle(), msg, wParam, lParam);
2009 }
2010 else PostMessageA(window->getWindowHandle(), msg, wParam, lParam);
2011 }
2012 }
2013 }
2014 return 0;
2015}
2016//******************************************************************************
2017//TODO: Do this more efficiently
2018//******************************************************************************
2019LRESULT Win32BaseWindow::BroadcastMessageW(int type, UINT msg, WPARAM wParam, LPARAM lParam)
2020{
2021 Win32BaseWindow *window;
2022 HWND hwnd = WNDHANDLE_MAGIC_HIGHWORD;
2023
2024 dprintf(("BroadCastMessageW %x %x %x", msg, wParam, lParam));
2025
2026 for(int i=0;i<MAX_WINDOW_HANDLES;i++) {
2027 window = GetWindowFromHandle(hwnd++);
2028 if(window) {
2029 if ((window->getStyle() & WS_POPUP) || ((window->getStyle() & WS_CAPTION) == WS_CAPTION))
2030 {
2031 if(type == BROADCAST_SEND) {
2032 ::SendMessageW(window->getWindowHandle(), msg, wParam, lParam);
2033 }
2034 else PostMessageW(window->getWindowHandle(), msg, wParam, lParam);
2035 }
2036 }
2037 }
2038 return 0;
2039}
2040//******************************************************************************
2041//******************************************************************************
2042void Win32BaseWindow::NotifyParent(UINT Msg, WPARAM wParam, LPARAM lParam)
2043{
2044 Win32BaseWindow *window = this;
2045 Win32BaseWindow *parentwindow;
2046
2047 while(window)
2048 {
2049 if(window->getStyle() & WS_CHILD && !(window->getExStyle() & WS_EX_NOPARENTNOTIFY) )
2050 {
2051 /* Notify the parent window only */
2052 parentwindow = window->getParent();
2053 if(parentwindow) {
2054 parentwindow->SendInternalMessageA(WM_PARENTNOTIFY, MAKEWPARAM(Msg, getWindowId()), lParam );
2055 }
2056 }
2057 else break;
2058
2059 window = parentwindow;
2060 }
2061}
2062//******************************************************************************
2063// Returns the big or small icon for the window, falling back to the
2064// class as windows does.
2065//******************************************************************************
2066HICON Win32BaseWindow::IconForWindow(WPARAM fType)
2067{
2068 HICON hWndIcon;
2069
2070 if (fType == ICON_BIG)
2071 {
2072 if (hIcon)
2073 hWndIcon = hIcon;
2074 else
2075 if (windowClass && windowClass->getIcon())
2076 hWndIcon = windowClass->getIcon();
2077 else
2078 if (!(dwStyle & DS_MODALFRAME))
2079 hWndIcon = LoadImageA(0,MAKEINTRESOURCEA(OIC_ODINICON),IMAGE_ICON,0,0,LR_DEFAULTCOLOR);
2080 else hWndIcon = 0;
2081 }
2082 else
2083 {
2084 if (hIconSm)
2085 hWndIcon = hIconSm;
2086 else
2087 if (hIcon)
2088 hWndIcon = hIcon;
2089 else
2090 if (windowClass && windowClass->getIconSm())
2091 hWndIcon = windowClass->getIconSm();
2092 else
2093 if (windowClass && windowClass->getIcon())
2094 hWndIcon = windowClass->getIcon();
2095 else
2096 if (!(dwStyle & DS_MODALFRAME))
2097 hWndIcon = LoadImageA(0,MAKEINTRESOURCEA(OIC_ODINICON),IMAGE_ICON,0,0,LR_DEFAULTCOLOR);
2098 else hWndIcon = 0;
2099 }
2100
2101 return hWndIcon;
2102}
2103//******************************************************************************
2104//******************************************************************************
2105BOOL Win32BaseWindow::ShowWindow(ULONG nCmdShow)
2106{
2107 ULONG swp = 0;
2108 HWND hWinAfter;
2109 BOOL rc,wasVisible,showFlag;
2110 RECT newPos = {0, 0, 0, 0};
2111
2112 dprintf(("ShowWindow %x %x", getWindowHandle(), nCmdShow));
2113 wasVisible = (getStyle() & WS_VISIBLE) != 0;
2114
2115 switch(nCmdShow)
2116 {
2117 case SW_HIDE:
2118 if (!wasVisible) goto END;
2119 swp |= SWP_HIDEWINDOW | SWP_NOSIZE | SWP_NOMOVE |
2120 SWP_NOACTIVATE | SWP_NOZORDER;
2121 break;
2122
2123 case SW_SHOWMINNOACTIVE:
2124 swp |= SWP_NOACTIVATE | SWP_NOZORDER;
2125 /* fall through */
2126 case SW_SHOWMINIMIZED:
2127 swp |= SWP_SHOWWINDOW;
2128 /* fall through */
2129 case SW_MINIMIZE:
2130 swp |= SWP_FRAMECHANGED;
2131 if( !(getStyle() & WS_MINIMIZE) )
2132 swp |= MinMaximize(SW_MINIMIZE, &newPos );
2133 else swp |= SWP_NOSIZE | SWP_NOMOVE;
2134 break;
2135
2136 case SW_SHOWMAXIMIZED: /* same as SW_MAXIMIZE */
2137 swp |= SWP_SHOWWINDOW | SWP_FRAMECHANGED;
2138 if( !(getStyle() & WS_MAXIMIZE) )
2139 swp |= MinMaximize(SW_MAXIMIZE, &newPos );
2140 else swp |= SWP_NOSIZE | SWP_NOMOVE;
2141 break;
2142
2143 case SW_SHOWNA:
2144 swp |= SWP_NOACTIVATE | SWP_NOZORDER;
2145 /* fall through */
2146 case SW_SHOW:
2147 swp |= SWP_SHOWWINDOW | SWP_NOSIZE | SWP_NOMOVE;
2148
2149 /*
2150 * ShowWindow has a little peculiar behavior that if the
2151 * window is already the topmost window, it will not
2152 * activate it.
2153 */
2154 if (::GetTopWindow((HWND)0)==getWindowHandle() && (wasVisible || GetActiveWindow() == getWindowHandle()))
2155 swp |= SWP_NOACTIVATE;
2156
2157 break;
2158
2159 case SW_SHOWNOACTIVATE:
2160 swp |= SWP_NOZORDER;
2161 if (GetActiveWindow())
2162 swp |= SWP_NOACTIVATE;
2163 /* fall through */
2164 case SW_SHOWNORMAL: /* same as SW_NORMAL: */
2165 case SW_SHOWDEFAULT: /* FIXME: should have its own handler */
2166 case SW_RESTORE:
2167 //TODO: WIN_RESTORE_MAX flag!!!!!!!!!!!!!!
2168 swp |= SWP_SHOWWINDOW | SWP_FRAMECHANGED;
2169
2170 if( getStyle() & (WS_MINIMIZE | WS_MAXIMIZE) )
2171 swp |= MinMaximize(SW_RESTORE, &newPos );
2172 else swp |= SWP_NOSIZE | SWP_NOMOVE;
2173 break;
2174 }
2175
2176 showFlag = (nCmdShow != SW_HIDE);
2177 if (showFlag != wasVisible)
2178 {
2179 SendInternalMessageA(WM_SHOWWINDOW, showFlag, 0 );
2180 if (!::IsWindow( getWindowHandle() )) goto END;
2181 }
2182
2183 /* We can't activate a child window */
2184 if((getStyle() & WS_CHILD) && !(getExStyle() & WS_EX_MDICHILD))
2185 swp |= SWP_NOACTIVATE | SWP_NOZORDER;
2186
2187 SetWindowPos(HWND_TOP, newPos.left, newPos.top, newPos.right, newPos.bottom, LOWORD(swp));
2188
2189 if(!(swp & SWP_NOACTIVATE)) {
2190 OSLibWinSetActiveWindow(OS2Hwnd);
2191 }
2192
2193 if (flags & WIN_NEED_SIZE)
2194 {
2195 /* should happen only in CreateWindowEx() */
2196 int wParam = SIZE_RESTORED;
2197
2198 flags &= ~WIN_NEED_SIZE;
2199 if (dwStyle & WS_MAXIMIZE)
2200 wParam = SIZE_MAXIMIZED;
2201 else
2202 if (dwStyle & WS_MINIMIZE)
2203 wParam = SIZE_MINIMIZED;
2204
2205 SendInternalMessageA(WM_SIZE, wParam,
2206 MAKELONG(rectClient.right-rectClient.left,
2207 rectClient.bottom-rectClient.top));
2208 SendInternalMessageA(WM_MOVE,0,MAKELONG(rectClient.left,rectClient.top));
2209 }
2210END:
2211 return wasVisible;
2212}
2213//******************************************************************************
2214//******************************************************************************
2215BOOL Win32BaseWindow::SetWindowPos(HWND hwndInsertAfter, int x, int y, int cx, int cy, UINT fuFlags)
2216{
2217 BOOL rc = FALSE;
2218 Win32BaseWindow *window;
2219 HWND hParent = 0;
2220 RECT oldClientRect = rectClient;
2221
2222 if (fuFlags &
2223 ~(SWP_NOSIZE | SWP_NOMOVE | SWP_NOZORDER |
2224 SWP_NOREDRAW | SWP_NOACTIVATE | SWP_FRAMECHANGED |
2225 SWP_SHOWWINDOW | SWP_HIDEWINDOW | SWP_NOCOPYBITS |
2226 SWP_NOOWNERZORDER))
2227 {
2228 return FALSE;
2229 }
2230
2231 if(IsWindowDestroyed()) {
2232 //changing the position of a window that's being destroyed can cause crashes in PMMERGE
2233 dprintf(("SetWindowPos; window already destroyed"));
2234 return TRUE;
2235 }
2236#if 0
2237 /* Fix redundant flags */
2238 if(getStyle() & WS_VISIBLE) {
2239 fuFlags &= ~SWP_SHOWWINDOW;
2240 }
2241 else
2242 {
2243 if (!(fuFlags & SWP_SHOWWINDOW))
2244 fuFlags |= SWP_NOREDRAW;
2245 fuFlags &= ~SWP_HIDEWINDOW;
2246 }
2247
2248 if(cx < 0) cx = 0;
2249 if(cy < 0) cy = 0;
2250
2251 if((rectWindow.right - rectWindow.left == cx) && (rectWindow.bottom - rectWindow.top == cy)) {
2252 fuFlags |= SWP_NOSIZE; /* Already the right size */
2253 }
2254
2255 if((rectWindow.left == x) && (rectWindow.top == y)) {
2256 fuFlags |= SWP_NOMOVE; /* Already the right position */
2257 }
2258
2259 if(getWindowHandle() == GetActiveWindow()) {
2260 fuFlags |= SWP_NOACTIVATE; /* Already active */
2261 }
2262 else
2263 if((getStyle() & (WS_POPUP | WS_CHILD)) != WS_CHILD )
2264 {
2265 if(!(fuFlags & SWP_NOACTIVATE)) /* Bring to the top when activating */
2266 {
2267 fuFlags &= ~SWP_NOZORDER;
2268 hwndInsertAfter = HWND_TOP;
2269 }
2270 }
2271#endif
2272
2273 if(!fCreateSetWindowPos)
2274 {//don't change size; modify internal structures only
2275 //TODO: not 100% correct yet (activate)
2276 if(!(fuFlags & SWP_NOZORDER)) {
2277 hwndLinkAfter = hwndInsertAfter;
2278 }
2279 if(!(fuFlags & SWP_NOMOVE)) {
2280 rectWindow.bottom = (rectWindow.bottom - rectWindow.top) + y;
2281 rectWindow.top = y;
2282 rectWindow.right = (rectWindow.right - rectWindow.left) + x;
2283 rectWindow.left = x;
2284 }
2285 if(!(fuFlags & SWP_NOSIZE)) {
2286 rectWindow.bottom = rectWindow.top + cy;
2287 rectWindow.right = rectWindow.left + cx;
2288 }
2289 return TRUE;
2290 }
2291
2292 WINDOWPOS wpos;
2293 SWP swp, swpOld;
2294 wpos.flags = fuFlags;
2295 wpos.cy = cy;
2296 wpos.cx = cx;
2297 wpos.x = x;
2298 wpos.y = y;
2299 wpos.hwndInsertAfter = hwndInsertAfter;
2300 wpos.hwnd = getWindowHandle();
2301
2302 if(~fuFlags & (SWP_NOMOVE | SWP_NOSIZE))
2303 {
2304 if (isChild())
2305 {
2306 if(!getParent()) {
2307 dprintf(("WARNING: Win32BaseWindow::SetWindowPos window %x is child but has no parent!!", getWindowHandle()));
2308 }
2309 }
2310 OSLibWinQueryWindowPos(OS2Hwnd, &swpOld);
2311 }
2312
2313 if(getParent()) {
2314 OSLibMapWINDOWPOStoSWP(&wpos, &swp, &swpOld, getParent()->getWindowHeight(),
2315 getParent()->getClientRectPtr()->left,
2316 getParent()->getClientRectPtr()->top,
2317 OS2Hwnd);
2318 }
2319 else OSLibMapWINDOWPOStoSWP(&wpos, &swp, &swpOld, OSLibQueryScreenHeight(), 0, 0, OS2Hwnd);
2320 if (swp.fl == 0) {
2321 if(fuFlags & SWP_FRAMECHANGED)
2322 {
2323 NotifyFrameChanged(&wpos, &oldClientRect);
2324 }
2325 return TRUE;
2326 }
2327
2328// if ((swp.fl & SWPOS_ZORDER) && (swp.hwndInsertBehind > HWNDOS_BOTTOM))
2329 if ((swp.hwndInsertBehind > HWNDOS_BOTTOM))
2330 {
2331 Win32BaseWindow *wndBehind = Win32BaseWindow::GetWindowFromHandle(swp.hwndInsertBehind);
2332 if(wndBehind) {
2333 swp.hwndInsertBehind = wndBehind->getOS2WindowHandle();
2334 }
2335 else {
2336 dprintf(("ERROR: SetWindowPos: hwndInsertBehind %x invalid!",swp.hwndInsertBehind));
2337 swp.hwndInsertBehind = 0;
2338 }
2339 }
2340 swp.hwnd = OS2Hwnd;
2341
2342 if(fuFlags & SWP_SHOWWINDOW && !IsWindowVisible()) {
2343 setStyle(getStyle() | WS_VISIBLE);
2344 if(hTaskList) {
2345 dprintf(("Adding window %x to tasklist", getWindowHandle()));
2346 OSLibWinChangeTaskList(hTaskList, OS2Hwnd, getWindowNameA(), (getStyle() & WS_VISIBLE) ? 1 : 0);
2347 }
2348 }
2349 else
2350 if(fuFlags & SWP_HIDEWINDOW && IsWindowVisible()) {
2351 setStyle(getStyle() & ~WS_VISIBLE);
2352 if(hTaskList) {
2353 dprintf(("Removing window %x from tasklist", getWindowHandle()));
2354 OSLibWinChangeTaskList(hTaskList, OS2Hwnd, getWindowNameA(), (getStyle() & WS_VISIBLE) ? 1 : 0);
2355 }
2356 }
2357 dprintf (("WinSetWindowPos %x %x (%d,%d)(%d,%d) %x", swp.hwnd, swp.hwndInsertBehind, swp.x, swp.y, swp.cx, swp.cy, swp.fl));
2358 rc = OSLibWinSetMultWindowPos(&swp, 1);
2359
2360 if(rc == FALSE)
2361 {
2362 dprintf(("OSLibWinSetMultWindowPos failed! Error %x",OSLibWinGetLastError()));
2363 return 0;
2364 }
2365
2366 if((fuFlags & SWP_FRAMECHANGED) && (fuFlags & (SWP_NOMOVE | SWP_NOSIZE) == (SWP_NOMOVE | SWP_NOSIZE)))
2367 {
2368 NotifyFrameChanged(&wpos, &oldClientRect);
2369 }
2370 return (rc);
2371}
2372//******************************************************************************
2373//******************************************************************************
2374void Win32BaseWindow::NotifyFrameChanged(WINDOWPOS *wpos, RECT *oldClientRect)
2375{
2376 MsgFormatFrame(NULL);
2377 if(RECT_WIDTH(rectClient) != RECT_WIDTH(*oldClientRect) ||
2378 RECT_HEIGHT(rectClient) != RECT_HEIGHT(*oldClientRect))
2379 {
2380 wpos->flags &= ~SWP_NOSIZE;
2381 }
2382
2383 WINDOWPOS wpOld = *wpos;
2384 SendInternalMessageA(WM_WINDOWPOSCHANGING, 0, (LPARAM)wpos);
2385
2386 UnionRect(oldClientRect, oldClientRect, &rectClient);
2387 OffsetRect(oldClientRect, -rectClient.left, -rectClient.top);
2388 InvalidateRect(getWindowHandle(), oldClientRect, TRUE);
2389
2390 if ((wpos->hwndInsertAfter != wpOld.hwndInsertAfter) ||
2391 (wpos->x != wpOld.x) || (wpos->y != wpOld.y) || (wpos->cx != wpOld.cx) || (wpos->cy != wpOld.cy) || (wpos->flags != wpOld.flags))
2392 {
2393 dprintf(("WARNING, NotifyFrameChanged: TODO -> adjust flags!!!!"));
2394 SetWindowPos(wpos->hwndInsertAfter, wpos->x, wpos->y, wpos->cx, wpos->cy, wpos->flags | SWP_NOSENDCHANGING);
2395 }
2396 else SendInternalMessageA(WM_WINDOWPOSCHANGED, 0, (LPARAM)wpos);
2397}
2398//******************************************************************************
2399//TODO: Check how this api really works in NT
2400//******************************************************************************
2401BOOL Win32BaseWindow::SetWindowPlacement(WINDOWPLACEMENT *wndpl)
2402{
2403 windowpos.ptMinPosition = wndpl->ptMinPosition;
2404 windowpos.ptMaxPosition = wndpl->ptMaxPosition;
2405 windowpos.rcNormalPosition = wndpl->rcNormalPosition;
2406
2407 if(getStyle() & WS_MINIMIZE )
2408 {
2409 //TODO: Why can't this be (0,0)?
2410 if(wndpl->flags & WPF_SETMINPOSITION && !(!windowpos.ptMinPosition.x && !windowpos.ptMinPosition.y)) {
2411 SetWindowPos(0, windowpos.ptMinPosition.x, windowpos.ptMinPosition.y,
2412 0, 0, SWP_NOSIZE | SWP_NOZORDER | SWP_NOACTIVATE);
2413 }
2414 }
2415 else
2416 if(getStyle() & WS_MAXIMIZE )
2417 {
2418 //TODO: Why can't this be (0,0)?
2419 if(windowpos.ptMaxPosition.x != 0 || windowpos.ptMaxPosition.y != 0 )
2420 SetWindowPos(0, windowpos.ptMaxPosition.x, windowpos.ptMaxPosition.y,
2421 0, 0, SWP_NOSIZE | SWP_NOZORDER | SWP_NOACTIVATE);
2422 }
2423 else {
2424 SetWindowPos(0, windowpos.rcNormalPosition.left, windowpos.rcNormalPosition.top,
2425 windowpos.rcNormalPosition.right - windowpos.rcNormalPosition.left,
2426 windowpos.rcNormalPosition.bottom - windowpos.rcNormalPosition.top,
2427 SWP_NOZORDER | SWP_NOACTIVATE );
2428 }
2429 ShowWindow(wndpl->showCmd);
2430 if( ::IsWindow(getWindowHandle()) && getStyle() & WS_MINIMIZE )
2431 {
2432 /* SDK: ...valid only the next time... */
2433 if(wndpl->flags & WPF_RESTORETOMAXIMIZED)
2434 setFlags(getFlags() | WIN_RESTORE_MAX);
2435 }
2436 return TRUE;
2437}
2438//******************************************************************************
2439//******************************************************************************
2440BOOL Win32BaseWindow::GetWindowPlacement(LPWINDOWPLACEMENT wndpl)
2441{
2442 wndpl->length = sizeof(*wndpl);
2443 if(getStyle() & WS_MINIMIZE )
2444 wndpl->showCmd = SW_SHOWMINIMIZED;
2445 else wndpl->showCmd = (getStyle() & WS_MAXIMIZE) ? SW_SHOWMAXIMIZED : SW_SHOWNORMAL;
2446
2447 //TODO: Verify if this is correct -> SDK docs claim this flag must always be set to 0
2448 if(getFlags() & WIN_RESTORE_MAX )
2449 wndpl->flags = WPF_RESTORETOMAXIMIZED;
2450 else wndpl->flags = 0;
2451
2452 wndpl->ptMinPosition = windowpos.ptMinPosition;
2453 wndpl->ptMaxPosition = windowpos.ptMaxPosition;
2454 //Must be in parent coordinates (or screen if no parent); verified in NT4, SP6
2455 wndpl->rcNormalPosition = rectWindow;
2456
2457 return TRUE;
2458}
2459//******************************************************************************
2460//Also destroys all the child windows (destroy children first, parent last)
2461//******************************************************************************
2462BOOL Win32BaseWindow::DestroyWindow()
2463{
2464 HWND hwnd = getWindowHandle();
2465
2466 dprintf(("DestroyWindow %x", hwnd));
2467
2468 /* Call hooks */
2469 if(HOOK_CallHooksA( WH_CBT, HCBT_DESTROYWND, getWindowHandle(), 0L))
2470 {
2471 return FALSE;
2472 }
2473
2474 if(!(getStyle() & WS_CHILD) && getOwner() == NULL)
2475 {
2476 HOOK_CallHooksA(WH_SHELL, HSHELL_WINDOWDESTROYED, getWindowHandle(), 0L);
2477 /* FIXME: clean up palette - see "Internals" p.352 */
2478 }
2479
2480 if((getStyle() & WS_CHILD) && !(getExStyle() & WS_EX_NOPARENTNOTIFY))
2481 {
2482 if(getParent() && getParent()->IsWindowDestroyed() == FALSE)
2483 {
2484 /* Notify the parent window only */
2485 getParent()->SendMessageA(WM_PARENTNOTIFY, MAKEWPARAM(WM_DESTROY, getWindowId()), (LPARAM)getWindowHandle());
2486 if(!::IsWindow(hwnd) )
2487 {
2488 return TRUE;
2489 }
2490 }
2491//// else DebugInt3();
2492 }
2493 /* Hide the window */
2494 if(IsWindowVisible())
2495 {
2496 SetWindowPos(0, 0, 0, 0, 0, SWP_HIDEWINDOW |
2497 SWP_NOACTIVATE|SWP_NOZORDER|SWP_NOMOVE|SWP_NOSIZE);
2498 if(!::IsWindow(hwnd))
2499 {
2500 return TRUE;
2501 }
2502 }
2503 dprintf(("DestroyWindow %x -> HIDDEN", hwnd));
2504
2505 fDestroyWindowCalled = TRUE;
2506 return OSLibWinDestroyWindow(OS2Hwnd);
2507}
2508//******************************************************************************
2509//******************************************************************************
2510Win32BaseWindow *Win32BaseWindow::getParent()
2511{
2512 Win32BaseWindow *wndparent = (Win32BaseWindow *)ChildWindow::getParentOfChild();
2513 return ((ULONG)wndparent == (ULONG)windowDesktop) ? NULL : wndparent;
2514}
2515//******************************************************************************
2516//******************************************************************************
2517HWND Win32BaseWindow::GetParent()
2518{
2519 if((!(getStyle() & (WS_POPUP|WS_CHILD)))) {
2520 return 0;
2521 }
2522
2523 Win32BaseWindow *wndparent = (Win32BaseWindow *)ChildWindow::getParentOfChild();
2524
2525 if(getStyle() & WS_CHILD) {
2526 if(wndparent) {
2527 return wndparent->getWindowHandle();
2528 }
2529 dprintf(("WARNING: GetParent: WS_CHILD but no parent!!"));
2530 DebugInt3();
2531 return 0;
2532 }
2533 else return (getOwner()) ? getOwner()->getWindowHandle() : 0;
2534}
2535//******************************************************************************
2536//******************************************************************************
2537HWND Win32BaseWindow::SetParent(HWND hwndNewParent)
2538{
2539 HWND oldhwnd;
2540 Win32BaseWindow *newparent;
2541 Win32BaseWindow *oldparent = (Win32BaseWindow *)ChildWindow::getParentOfChild();
2542 BOOL fShow = FALSE;
2543
2544 if(oldparent) {
2545 oldhwnd = oldparent->getWindowHandle();
2546 oldparent->removeChild(this);
2547 }
2548 else oldhwnd = 0;
2549
2550 /* Windows hides the window first, then shows it again
2551 * including the WM_SHOWWINDOW messages and all */
2552 if(fCreated && (getStyle() & WS_VISIBLE)) {
2553 ShowWindow(SW_HIDE);
2554 fShow = TRUE;
2555 }
2556
2557 newparent = GetWindowFromHandle(hwndNewParent);
2558 if(newparent && !newparent->isDesktopWindow())
2559 {
2560 setParent(newparent);
2561 getParent()->addChild(this);
2562 OSLibWinSetParent(getOS2WindowHandle(), getParent()->getOS2WindowHandle());
2563 if(!(getStyle() & WS_CHILD))
2564 {
2565 //TODO: Send WM_STYLECHANGED msg?
2566 setStyle(getStyle() | WS_CHILD);
2567 if(getWindowId())
2568 {
2569 DestroyMenu( (HMENU) getWindowId() );
2570 setWindowId(0);
2571 }
2572 }
2573 }
2574 else {
2575 setParent(windowDesktop);
2576 windowDesktop->addChild(this);
2577 OSLibWinSetParent(getOS2WindowHandle(), OSLIB_HWND_DESKTOP);
2578
2579 //TODO: Send WM_STYLECHANGED msg?
2580 setStyle(getStyle() & ~WS_CHILD);
2581 setWindowId(0);
2582 }
2583 /* SetParent additionally needs to make hwndChild the topmost window
2584 in the x-order and send the expected WM_WINDOWPOSCHANGING and
2585 WM_WINDOWPOSCHANGED notification messages.
2586 */
2587 if(fCreated) {
2588 SetWindowPos(HWND_TOPMOST, 0, 0, 0, 0,
2589 SWP_NOMOVE|SWP_NOSIZE|(fShow? SWP_SHOWWINDOW : 0));
2590
2591 /* FIXME: a WM_MOVE is also generated (in the DefWindowProc handler
2592 * for WM_WINDOWPOSCHANGED) in Windows, should probably remove SWP_NOMOVE */
2593 }
2594 return oldhwnd;
2595}
2596//******************************************************************************
2597//******************************************************************************
2598BOOL Win32BaseWindow::IsChild(HWND hwndParent)
2599{
2600 if(getParent()) {
2601 return getParent()->getWindowHandle() == hwndParent;
2602 }
2603 else return 0;
2604}
2605//******************************************************************************
2606//******************************************************************************
2607HWND Win32BaseWindow::GetTopWindow()
2608{
2609 HWND hwndTop;
2610 Win32BaseWindow *topwindow;
2611
2612 hwndTop = OSLibWinQueryWindow(getOS2WindowHandle(), QWOS_TOP);
2613 if(!isDesktopWindow()) {
2614 topwindow = GetWindowFromOS2Handle(hwndTop);
2615 if(topwindow) {
2616 return topwindow->getWindowHandle();
2617 }
2618 return 0;
2619 }
2620 while(hwndTop) {
2621 topwindow = GetWindowFromOS2Handle(hwndTop);
2622 if(topwindow) {
2623 return topwindow->getWindowHandle();
2624 }
2625 hwndTop = OSLibWinQueryWindow(hwndTop, QWOS_NEXT);
2626 }
2627
2628 return 0;
2629}
2630//******************************************************************************
2631// Get the top-level parent for a child window.
2632//******************************************************************************
2633Win32BaseWindow *Win32BaseWindow::GetTopParent()
2634{
2635 Win32BaseWindow *window = this;
2636
2637 while(window && (window->getStyle() & WS_CHILD))
2638 {
2639 window = window->getParent();
2640 }
2641 return window;
2642}
2643//******************************************************************************
2644//TODO: Should not enumerate children that are created during the enumeration!
2645//******************************************************************************
2646BOOL Win32BaseWindow::EnumChildWindows(WNDENUMPROC lpfn, LPARAM lParam)
2647{
2648 BOOL rc = TRUE;
2649 HWND hwnd;
2650 Win32BaseWindow *prevchild = 0, *child = 0;
2651
2652 dprintf(("EnumChildWindows of %x parameter %x %x (%x)", getWindowHandle(), lpfn, lParam, getFirstChild()));
2653 for (child = (Win32BaseWindow *)getFirstChild(); child; child = (Win32BaseWindow *)child->getNextChild())
2654 {
2655 dprintf(("EnumChildWindows: enumerating child %x (owner %x; parent %x)", child->getWindowHandle(), (child->getOwner()) ? child->getOwner()->getWindowHandle() : 0, getWindowHandle()));
2656 hwnd = child->getWindowHandle();
2657 if(child->getOwner()) {
2658 continue; //shouldn't have an owner (Wine)
2659 }
2660 if(lpfn(hwnd, lParam) == FALSE)
2661 {
2662 rc = FALSE;
2663 break;
2664 }
2665 //check if the window still exists
2666 if(!::IsWindow(hwnd))
2667 {
2668 child = prevchild;
2669 continue;
2670 }
2671 if(child->getFirstChild() != NULL)
2672 {
2673 dprintf(("EnumChildWindows: Enumerate children of %x", child->getWindowHandle()));
2674 if(child->EnumChildWindows(lpfn, lParam) == FALSE)
2675 {
2676 rc = FALSE;
2677 break;
2678 }
2679 }
2680 prevchild = child;
2681 }
2682 return rc;
2683}
2684//******************************************************************************
2685//Enumerate first-level children only and check thread id
2686//******************************************************************************
2687BOOL Win32BaseWindow::EnumThreadWindows(DWORD dwThreadId, WNDENUMPROC lpfn, LPARAM lParam)
2688{
2689 Win32BaseWindow *child = 0;
2690 ULONG tid, pid;
2691 BOOL rc;
2692 HWND hwnd;
2693
2694 dprintf(("EnumThreadWindows %x %x %x", dwThreadId, lpfn, lParam));
2695
2696 for (child = (Win32BaseWindow *)getFirstChild(); child; child = (Win32BaseWindow *)child->getNextChild())
2697 {
2698 OSLibWinQueryWindowProcess(child->getOS2WindowHandle(), &pid, &tid);
2699
2700 if(dwThreadId == tid) {
2701 dprintf2(("EnumThreadWindows: Found Window %x", child->getWindowHandle()));
2702 if((rc = lpfn(child->getWindowHandle(), lParam)) == FALSE) {
2703 break;
2704 }
2705 }
2706 }
2707 return TRUE;
2708}
2709//******************************************************************************
2710//Enumerate first-level children only
2711//******************************************************************************
2712BOOL Win32BaseWindow::EnumWindows(WNDENUMPROC lpfn, LPARAM lParam)
2713{
2714 Win32BaseWindow *child = 0;
2715 BOOL rc;
2716 HWND hwnd;
2717
2718 dprintf(("EnumWindows %x %x", lpfn, lParam));
2719
2720 for (child = (Win32BaseWindow *)getFirstChild(); child; child = (Win32BaseWindow *)child->getNextChild())
2721 {
2722 hwnd = child->getWindowHandle();
2723
2724 dprintf2(("EnumWindows: Found Window %x", child->getWindowHandle()));
2725 if((rc = lpfn(child->getWindowHandle(), lParam)) == FALSE) {
2726 break;
2727 }
2728 }
2729 return TRUE;
2730}
2731//******************************************************************************
2732//******************************************************************************
2733Win32BaseWindow *Win32BaseWindow::FindWindowById(int id)
2734{
2735 for (Win32BaseWindow *child = (Win32BaseWindow *)getFirstChild(); child; child = (Win32BaseWindow *)child->getNextChild())
2736 {
2737 if (child->getWindowId() == id)
2738 {
2739 return child;
2740 }
2741 }
2742 return 0;
2743}
2744//******************************************************************************
2745//TODO:
2746//We assume (for now) that if hwndParent or hwndChildAfter are real window handles, that
2747//the current process owns them.
2748//******************************************************************************
2749HWND Win32BaseWindow::FindWindowEx(HWND hwndParent, HWND hwndChildAfter, ATOM atom, LPSTR lpszWindow)
2750{
2751 Win32BaseWindow *parent = GetWindowFromHandle(hwndParent);
2752 Win32BaseWindow *child = GetWindowFromHandle(hwndChildAfter);
2753
2754 dprintf(("FindWindowEx %x %x %x %s", hwndParent, hwndChildAfter, atom, lpszWindow));
2755 if((hwndParent != 0 && !parent) ||
2756 (hwndChildAfter != 0 && !child) ||
2757 (hwndParent == 0 && hwndChildAfter != 0))
2758 {
2759 dprintf(("Win32BaseWindow::FindWindowEx: parent or child not found %x %x", hwndParent, hwndChildAfter));
2760 SetLastError(ERROR_INVALID_WINDOW_HANDLE);
2761 return 0;
2762 }
2763 SetLastError(0);
2764 if(hwndParent != 0)
2765 {//if the current process owns the window, just do a quick search
2766 child = (Win32BaseWindow *)parent->getFirstChild();
2767 if(hwndChildAfter != 0)
2768 {
2769 while(child)
2770 {
2771 if(child->getWindowHandle() == hwndChildAfter)
2772 {
2773 child = (Win32BaseWindow *)child->getNextChild();
2774 break;
2775 }
2776 child = (Win32BaseWindow *)child->getNextChild();
2777 }
2778 }
2779 while(child)
2780 {
2781 //According to Wine, the class doesn't need to be specified
2782 if((!atom || child->getWindowClass()->getAtom() == atom) &&
2783 (!lpszWindow || child->hasWindowName(lpszWindow)))
2784 {
2785 dprintf(("FindWindowEx: Found window %x", child->getWindowHandle()));
2786 return child->getWindowHandle();
2787 }
2788 child = (Win32BaseWindow *)child->getNextChild();
2789 }
2790 }
2791 else {
2792 Win32BaseWindow *wnd;
2793 HWND henum, hwnd;
2794
2795 henum = OSLibWinBeginEnumWindows(OSLIB_HWND_DESKTOP);
2796 hwnd = OSLibWinGetNextWindow(henum);
2797
2798 while(hwnd)
2799 {
2800 wnd = GetWindowFromOS2Handle(hwnd);
2801 if(wnd == NULL) {
2802 hwnd = OSLibWinQueryClientWindow(hwnd);
2803 if(hwnd) wnd = GetWindowFromOS2Handle(hwnd);
2804 }
2805
2806 if(wnd) {
2807 //According to Wine, the class doesn't need to be specified
2808 if((!atom || wnd->getWindowClass()->getAtom() == atom) &&
2809 (!lpszWindow || wnd->hasWindowName(lpszWindow)))
2810 {
2811 OSLibWinEndEnumWindows(henum);
2812 dprintf(("FindWindowEx: Found window %x", wnd->getWindowHandle()));
2813 return wnd->getWindowHandle();
2814 }
2815 }
2816 hwnd = OSLibWinGetNextWindow(henum);
2817 }
2818 OSLibWinEndEnumWindows(henum);
2819 }
2820 SetLastError(ERROR_CANNOT_FIND_WND_CLASS); //TODO: not always correct
2821 return 0;
2822}
2823//******************************************************************************
2824//******************************************************************************
2825HWND Win32BaseWindow::GetWindow(UINT uCmd)
2826{
2827 HWND hwndRelated = 0;
2828 Win32BaseWindow *window;
2829
2830#if 1
2831 switch(uCmd)
2832 {
2833 case GW_HWNDFIRST:
2834 if(getParent())
2835 {
2836 window = (Win32BaseWindow *)getParent();
2837 hwndRelated = OSLibWinQueryWindow(window->getOS2WindowHandle(), QWOS_TOP);
2838 window = GetWindowFromOS2Handle(hwndRelated);
2839 if(window) {
2840 hwndRelated = window->getWindowHandle();
2841 }
2842 else hwndRelated = 0;
2843 }
2844 else hwndRelated = 0; //TODO: not correct; should get first child in z-order of desktop
2845 break;
2846
2847 case GW_HWNDLAST:
2848 hwndRelated = OSLibWinQueryWindow(getOS2WindowHandle(), QWOS_BOTTOM);
2849 window = GetWindowFromOS2Handle(hwndRelated);
2850 if(window) {
2851 hwndRelated = window->getWindowHandle();
2852 }
2853 else hwndRelated = 0;
2854 break;
2855
2856 case GW_HWNDNEXT:
2857 hwndRelated = OSLibWinQueryWindow(getOS2WindowHandle(), QWOS_NEXT);
2858 window = GetWindowFromOS2Handle(hwndRelated);
2859 if(window) {
2860 hwndRelated = window->getWindowHandle();
2861 }
2862 else hwndRelated = 0;
2863 break;
2864
2865 case GW_HWNDPREV:
2866 hwndRelated = OSLibWinQueryWindow(getOS2WindowHandle(), QWOS_PREV);
2867 window = GetWindowFromOS2Handle(hwndRelated);
2868 if(window) {
2869 hwndRelated = window->getWindowHandle();
2870 }
2871 else hwndRelated = 0;
2872 break;
2873
2874 case GW_OWNER:
2875 if(getOwner()) {
2876 hwndRelated = getOwner()->getWindowHandle();
2877 }
2878 break;
2879
2880 case GW_CHILD:
2881 hwndRelated = OSLibWinQueryWindow(getOS2WindowHandle(), QWOS_TOP);
2882 window = GetWindowFromOS2Handle(hwndRelated);
2883 if(window) {
2884 hwndRelated = window->getWindowHandle();
2885 }
2886 else hwndRelated = 0;
2887 break;
2888 }
2889#else
2890 switch(uCmd)
2891 {
2892 case GW_HWNDFIRST:
2893 if(getParent()) {
2894 window = (Win32BaseWindow *)getParent()->getFirstChild();
2895 hwndRelated = window->getWindowHandle();
2896 }
2897 break;
2898
2899 case GW_HWNDLAST:
2900 if(!getParent())
2901 {
2902 goto end;
2903 }
2904
2905 window = this;
2906 while(window->getNextChild())
2907 {
2908 window = (Win32BaseWindow *)window->getNextChild();
2909 }
2910 hwndRelated = window->getWindowHandle();
2911 break;
2912
2913 case GW_HWNDNEXT:
2914 window = (Win32BaseWindow *)getNextChild();
2915 if(window) {
2916 hwndRelated = window->getWindowHandle();
2917 }
2918 break;
2919
2920 case GW_HWNDPREV:
2921 if(!getParent())
2922 {
2923 goto end;
2924 }
2925 window = (Win32BaseWindow *)(getParent()->getFirstChild()); /* First sibling */
2926 if(window == this)
2927 {
2928 hwndRelated = 0; /* First in list */
2929 goto end;
2930 }
2931 while(window->getNextChild())
2932 {
2933 if (window->getNextChild() == this)
2934 {
2935 hwndRelated = window->getWindowHandle();
2936 goto end;
2937 }
2938 window = (Win32BaseWindow *)window->getNextChild();
2939 }
2940 break;
2941
2942 case GW_OWNER:
2943 if(getOwner()) {
2944 hwndRelated = getOwner()->getWindowHandle();
2945 }
2946 break;
2947
2948 case GW_CHILD:
2949 if(getFirstChild()) {
2950 hwndRelated = ((Win32BaseWindow *)getFirstChild())->getWindowHandle();
2951 }
2952 break;
2953 }
2954#endif
2955end:
2956 dprintf(("GetWindow %x %d returned %x", getWindowHandle(), uCmd, hwndRelated));
2957 return hwndRelated;
2958}
2959//******************************************************************************
2960//******************************************************************************
2961HWND Win32BaseWindow::SetActiveWindow()
2962{
2963 HWND hwndActive;
2964
2965 dprintf(("SetActiveWindow %x", getWindowHandle()));
2966 if (HOOK_IsHooked( WH_CBT ))
2967 {
2968 CBTACTIVATESTRUCT cbta;
2969 LRESULT ret;
2970
2971 cbta.fMouse = FALSE;
2972 cbta.hWndActive = GetActiveWindow();
2973 ret = HOOK_CallHooksA(WH_CBT, HCBT_ACTIVATE, getWindowHandle(), (LPARAM)&cbta);
2974 if(ret)
2975 {
2976 dprintf(("SetActiveWindow %x, CBT hook cancelled operation", getWindowHandle()));
2977 return cbta.hWndActive;
2978 }
2979 }
2980
2981 if(OSLibWinSetActiveWindow(OS2Hwnd) == FALSE) {
2982 dprintf(("OSLibWinSetActiveWindow %x returned FALSE!", OS2Hwnd));
2983 }
2984 hwndActive = GetActiveWindow();
2985 return (hwndActive) ? hwndActive : windowDesktop->getWindowHandle(); //pretend the desktop was active
2986}
2987//******************************************************************************
2988//WM_ENABLE is sent to hwnd, but not to it's children (as it should be)
2989//******************************************************************************
2990BOOL Win32BaseWindow::EnableWindow(BOOL fEnable)
2991{
2992 BOOL rc;
2993
2994 dprintf(("Win32BaseWindow::EnableWindow %x %d", getWindowHandle(), fEnable));
2995 //return true if previous state was disabled, else false (sdk docs)
2996 rc = (getStyle() & WS_DISABLED) != 0;
2997 if(rc && !fEnable) {
2998 SendMessageA(WM_CANCELMODE, 0, 0);
2999 }
3000 OSLibWinEnableWindow(OS2Hwnd, fEnable);
3001 if(fEnable == FALSE) {
3002 //SvL: No need to clear focus as PM already does this
3003 if(getWindowHandle() == GetCapture()) {
3004 ReleaseCapture(); /* A disabled window can't capture the mouse */
3005 dprintf(("Released capture for window %x that is being disabled", getWindowHandle()));
3006 }
3007 }
3008 return rc;
3009}
3010//******************************************************************************
3011//******************************************************************************
3012BOOL Win32BaseWindow::CloseWindow()
3013{
3014 return OSLibWinMinimizeWindow(OS2Hwnd);
3015}
3016//******************************************************************************
3017//TODO: Not be 100% correct; should return active window of current thread
3018// or NULL when there is none -> WinQueryActiveWindow just returns
3019// the current active window
3020//******************************************************************************
3021HWND Win32BaseWindow::GetActiveWindow()
3022{
3023 HWND hwndActive;
3024 Win32BaseWindow *win32wnd;
3025 ULONG magic;
3026
3027 hwndActive = OSLibWinQueryActiveWindow();
3028
3029 return OS2ToWin32Handle(hwndActive);
3030}
3031//******************************************************************************
3032//******************************************************************************
3033BOOL Win32BaseWindow::IsWindowEnabled()
3034{
3035 return OSLibWinIsWindowEnabled(OS2Hwnd);
3036}
3037//******************************************************************************
3038//******************************************************************************
3039BOOL Win32BaseWindow::IsWindowVisible()
3040{
3041 //TODO: Do we have to check the state of the parent window? (as Wine does)
3042#if 1
3043 return (dwStyle & WS_VISIBLE) == WS_VISIBLE;
3044#else
3045 return OSLibWinIsWindowVisible(OS2Hwnd);
3046#endif
3047}
3048//******************************************************************************
3049//******************************************************************************
3050BOOL Win32BaseWindow::hasWindowName(LPSTR wndname, BOOL fUnicode)
3051{
3052 INT len = GetWindowTextLength();
3053 BOOL res;
3054
3055 if (wndname == NULL)
3056 return (len == 0);
3057
3058 len++;
3059 if (fUnicode)
3060 {
3061 WCHAR *text = (WCHAR*)malloc(len*sizeof(WCHAR));
3062
3063 GetWindowTextW(text,len);
3064 res = (lstrcmpW(text,(LPWSTR)wndname) == 0);
3065 free(text);
3066 } else
3067 {
3068 CHAR *text = (CHAR*)malloc(len*sizeof(CHAR));
3069
3070 GetWindowTextA(text,len);
3071 res = (strcmp(text,wndname) == 0);
3072 free(text);
3073 }
3074
3075 return res;
3076}
3077//******************************************************************************
3078//******************************************************************************
3079CHAR *Win32BaseWindow::getWindowNamePtrA()
3080{
3081 INT len = GetWindowTextLength();
3082 CHAR *text;
3083
3084 if (len == 0) return NULL;
3085 len++;
3086 text = (CHAR*)malloc(len*sizeof(CHAR));
3087 GetWindowTextA(text,len);
3088
3089 return text;
3090}
3091//******************************************************************************
3092//******************************************************************************
3093WCHAR *Win32BaseWindow::getWindowNamePtrW()
3094{
3095 INT len = GetWindowTextLength();
3096 WCHAR *text;
3097
3098 if (len == 0) return NULL;
3099 len++;
3100 text = (WCHAR*)malloc(len*sizeof(WCHAR));
3101 GetWindowTextW(text,len);
3102
3103 return text;
3104}
3105//******************************************************************************
3106//******************************************************************************
3107VOID Win32BaseWindow::freeWindowNamePtr(PVOID namePtr)
3108{
3109 if (namePtr) free(namePtr);
3110}
3111//******************************************************************************
3112//When using this API for a window that was created by a different process, NT
3113//does NOT send WM_GETTEXTLENGTH.
3114//******************************************************************************
3115int Win32BaseWindow::GetWindowTextLength()
3116{
3117 //if the destination window is created by this process, send message
3118 if(dwProcessId == currentProcessId) {
3119 return SendInternalMessageA(WM_GETTEXTLENGTH,0,0);
3120 }
3121 //else get data directory from window structure
3122 return wndNameLength;
3123}
3124//******************************************************************************
3125//When using this API for a window that was created by a different process, NT
3126//does NOT send WM_GETTEXT.
3127//******************************************************************************
3128int Win32BaseWindow::GetWindowTextA(LPSTR lpsz, int cch)
3129{
3130 //if the destination window is created by this process, send message
3131 if(dwProcessId == currentProcessId) {
3132 return SendInternalMessageA(WM_GETTEXT,(WPARAM)cch,(LPARAM)lpsz);
3133 }
3134 //else get data directory from window structure
3135 if (!lpsz || !cch) return 0;
3136 if (!windowNameA) lpsz[0] = 0;
3137 else lstrcpynA(lpsz, windowNameA, cch);
3138 return min(wndNameLength, cch);
3139}
3140//******************************************************************************
3141//When using this API for a window that was created by a different process, NT
3142//does NOT send WM_GETTEXT.
3143//******************************************************************************
3144int Win32BaseWindow::GetWindowTextW(LPWSTR lpsz, int cch)
3145{
3146 //if the destination window is created by this process, send message
3147 if(dwProcessId == currentProcessId) {
3148 return SendInternalMessageW(WM_GETTEXT,(WPARAM)cch,(LPARAM)lpsz);
3149 }
3150 //else get data directory from window structure
3151 if (!lpsz || !cch) return 0;
3152 if (!windowNameW) lpsz[0] = 0;
3153 else lstrcpynW(lpsz, windowNameW, cch);
3154 return min(wndNameLength, cch);
3155}
3156//******************************************************************************
3157//TODO: How does this work when the target window belongs to a different process???
3158//******************************************************************************
3159BOOL Win32BaseWindow::SetWindowTextA(LPSTR lpsz)
3160{
3161 return SendInternalMessageA(WM_SETTEXT,0,(LPARAM)lpsz);
3162}
3163//******************************************************************************
3164//******************************************************************************
3165BOOL Win32BaseWindow::SetWindowTextW(LPWSTR lpsz)
3166{
3167 return SendInternalMessageW(WM_SETTEXT,0,(LPARAM)lpsz);
3168}
3169//******************************************************************************
3170//******************************************************************************
3171LONG Win32BaseWindow::SetWindowLongA(int index, ULONG value, BOOL fUnicode)
3172{
3173 LONG oldval;
3174
3175 switch(index) {
3176 case GWL_EXSTYLE:
3177 {
3178 STYLESTRUCT ss;
3179
3180 if(dwExStyle == value) {
3181 oldval = value;
3182 break;
3183 }
3184 ss.styleOld = dwExStyle;
3185 ss.styleNew = value;
3186 dprintf(("SetWindowLong GWL_EXSTYLE %x old %x new style %x", getWindowHandle(), dwExStyle, value));
3187 SendInternalMessageA(WM_STYLECHANGING,GWL_EXSTYLE,(LPARAM)&ss);
3188 setExStyle(ss.styleNew);
3189 SendInternalMessageA(WM_STYLECHANGED,GWL_EXSTYLE,(LPARAM)&ss);
3190 oldval = ss.styleOld;
3191 break;
3192 }
3193 case GWL_STYLE:
3194 {
3195 STYLESTRUCT ss;
3196
3197 //SvL: TODO: Can you change minimize or maximize status here too?
3198
3199 if(dwStyle == value) {
3200 oldval = value;
3201 break;
3202 }
3203 value &= ~(WS_CHILD|WS_VISIBLE); /* Some bits can't be changed this way (WINE) */
3204 ss.styleOld = getStyle();
3205 ss.styleNew = value | (ss.styleOld & (WS_CHILD|WS_VISIBLE));
3206 dprintf(("SetWindowLong GWL_STYLE %x old %x new style %x", getWindowHandle(), ss.styleOld, ss.styleNew));
3207 SendInternalMessageA(WM_STYLECHANGING,GWL_STYLE,(LPARAM)&ss);
3208 setStyle(ss.styleNew);
3209 SendInternalMessageA(WM_STYLECHANGED,GWL_STYLE,(LPARAM)&ss);
3210//// OSLibSetWindowStyle(getOS2WindowHandle(), getStyle(), getExStyle(),
3211//// windowClass->getStyle() & CS_SAVEBITS);
3212#ifdef DEBUG
3213 PrintWindowStyle(ss.styleNew, 0);
3214#endif
3215 oldval = ss.styleOld;
3216 break;
3217 }
3218 case GWL_WNDPROC:
3219 {
3220 //Note: Type of SetWindowLong determines new window proc type
3221 // UNLESS the new window proc has already been registered
3222 // (use the old type in that case)
3223 // (VERIFIED in NT 4, SP6)
3224 WINDOWPROCTYPE type = WINPROC_GetProcType((HWINDOWPROC)value);
3225 if(type == WIN_PROC_INVALID) {
3226 type = (fUnicode) ? WIN_PROC_32W : WIN_PROC_32A;
3227 }
3228 oldval = (LONG)WINPROC_GetProc(win32wndproc, (fUnicode) ? WIN_PROC_32W : WIN_PROC_32A);
3229 WINPROC_SetProc((HWINDOWPROC *)&win32wndproc, (WNDPROC)value, type, WIN_PROC_WINDOW);
3230 break;
3231 }
3232 case GWL_HINSTANCE:
3233 oldval = hInstance;
3234 hInstance = value;
3235 break;
3236
3237 case GWL_HWNDPARENT:
3238 oldval = SetParent((HWND)value);
3239 break;
3240
3241 case GWL_ID:
3242 oldval = getWindowId();
3243 setWindowId(value);
3244 break;
3245
3246 case GWL_USERDATA:
3247 oldval = userData;
3248 userData = value;
3249 break;
3250
3251 default:
3252 if(index >= 0 && index/4 < nrUserWindowLong)
3253 {
3254 oldval = userWindowLong[index/4];
3255 userWindowLong[index/4] = value;
3256 break;
3257 }
3258 dprintf(("WARNING: SetWindowLong%c %x %d %x returned %x INVALID index!", (fUnicode) ? 'W' : 'A', getWindowHandle(), index, value));
3259 SetLastError(ERROR_INVALID_PARAMETER);
3260 return 0;
3261 }
3262 SetLastError(ERROR_SUCCESS);
3263 dprintf2(("SetWindowLong%c %x %d %x returned %x", (fUnicode) ? 'W' : 'A', getWindowHandle(), index, value, oldval));
3264 return oldval;
3265}
3266//******************************************************************************
3267//******************************************************************************
3268ULONG Win32BaseWindow::GetWindowLongA(int index, BOOL fUnicode)
3269{
3270 ULONG value;
3271
3272 switch(index) {
3273 case GWL_EXSTYLE:
3274 value = dwExStyle;
3275 break;
3276 case GWL_STYLE:
3277 value = dwStyle;
3278 break;
3279 case GWL_WNDPROC:
3280 value = (LONG)WINPROC_GetProc(win32wndproc, (fUnicode) ? WIN_PROC_32W : WIN_PROC_32A);
3281 break;
3282 case GWL_HINSTANCE:
3283 value = hInstance;
3284 break;
3285 case GWL_HWNDPARENT:
3286 value = GetParent();
3287 break;
3288 case GWL_ID:
3289 value = getWindowId();
3290 break;
3291 case GWL_USERDATA:
3292 value = userData;
3293 break;
3294 default:
3295 if(index >= 0 && index/4 < nrUserWindowLong)
3296 {
3297 value = userWindowLong[index/4];
3298 break;
3299 }
3300 SetLastError(ERROR_INVALID_PARAMETER);
3301 return 0;
3302 }
3303 dprintf2(("GetWindowLongA %x %d %x", getWindowHandle(), index, value));
3304 return value;
3305}
3306//******************************************************************************
3307//******************************************************************************
3308WORD Win32BaseWindow::SetWindowWord(int index, WORD value)
3309{
3310 WORD oldval;
3311
3312 if(index >= 0 && index/4 < nrUserWindowLong)
3313 {
3314 oldval = ((WORD *)userWindowLong)[index/2];
3315 ((WORD *)userWindowLong)[index/2] = value;
3316 return oldval;
3317 }
3318 SetLastError(ERROR_INVALID_PARAMETER);
3319 return 0;
3320}
3321//******************************************************************************
3322//******************************************************************************
3323WORD Win32BaseWindow::GetWindowWord(int index)
3324{
3325 if(index >= 0 && index/4 < nrUserWindowLong)
3326 {
3327 return ((WORD *)userWindowLong)[index/2];
3328 }
3329 SetLastError(ERROR_INVALID_PARAMETER);
3330 return 0;
3331}
3332//******************************************************************************
3333//******************************************************************************
3334void Win32BaseWindow::setWindowId(DWORD id)
3335{
3336 dwIDMenu = id;
3337}
3338//******************************************************************************
3339//******************************************************************************
3340Win32BaseWindow *Win32BaseWindow::GetWindowFromHandle(HWND hwnd)
3341{
3342 Win32BaseWindow *window;
3343
3344 if(HwGetWindowHandleData(hwnd, (DWORD *)&window) == TRUE) {
3345 return window;
3346 }
3347// dprintf2(("Win32BaseWindow::GetWindowFromHandle: not a win32 window %x", hwnd));
3348 return NULL;
3349}
3350//******************************************************************************
3351//******************************************************************************
3352Win32BaseWindow *Win32BaseWindow::GetWindowFromOS2Handle(HWND hwnd)
3353{
3354 Win32BaseWindow *win32wnd;
3355 DWORD magic;
3356
3357 if(hwnd == OSLIB_HWND_DESKTOP)
3358 {
3359 return windowDesktop;
3360 }
3361
3362 win32wnd = (Win32BaseWindow *)OSLibWinGetWindowULong(hwnd, OFFSET_WIN32WNDPTR);
3363 magic = OSLibWinGetWindowULong(hwnd, OFFSET_WIN32PM_MAGIC);
3364
3365 if(win32wnd && CheckMagicDword(magic)) {
3366 return win32wnd;
3367 }
3368// dprintf2(("Win32BaseWindow::GetWindowFromOS2Handle: not an Odin os2 window %x", hwnd));
3369 return 0;
3370}
3371//******************************************************************************
3372//******************************************************************************
3373HWND Win32BaseWindow::Win32ToOS2Handle(HWND hwnd)
3374{
3375 Win32BaseWindow *window = GetWindowFromHandle(hwnd);
3376
3377 if(window) {
3378 return window->getOS2WindowHandle();
3379 }
3380// dprintf2(("Win32BaseWindow::Win32ToOS2Handle: not a win32 window %x", hwnd));
3381 return hwnd;
3382}
3383//******************************************************************************
3384//******************************************************************************
3385HWND Win32BaseWindow::OS2ToWin32Handle(HWND hwnd)
3386{
3387 Win32BaseWindow *window = GetWindowFromOS2Handle(hwnd);
3388
3389 if(window) {
3390 return window->getWindowHandle();
3391 }
3392// dprintf2(("Win32BaseWindow::OS2ToWin32Handle: not a win32 window %x", hwnd));
3393 return 0;
3394// else return hwnd; //OS/2 window handle
3395}
3396//******************************************************************************
3397//******************************************************************************
3398HWND Win32BaseWindow::getNextDlgTabItem(HWND hwndCtrl, BOOL fPrevious)
3399{
3400 Win32BaseWindow *child, *nextchild, *lastchild;
3401 HWND retvalue;
3402
3403 if (hwndCtrl)
3404 {
3405 child = GetWindowFromHandle(hwndCtrl);
3406 if (!child)
3407 {
3408 retvalue = 0;
3409 goto END;
3410 }
3411 /* Make sure hwndCtrl is a top-level child */
3412 while ((child->getStyle() & WS_CHILD) && (child->getParent() != this))
3413 {
3414 child = child->getParent();
3415 if(child == NULL) break;
3416 }
3417
3418 if (!child || (child->getParent() != this))
3419 {
3420 retvalue = 0;
3421 goto END;
3422 }
3423 }
3424 else
3425 {
3426 /* No ctrl specified -> start from the beginning */
3427 child = (Win32BaseWindow *)getFirstChild();
3428 if (!child)
3429 {
3430 retvalue = 0;
3431 goto END;
3432 }
3433
3434 if (!fPrevious)
3435 {
3436 while (child->getNextChild())
3437 {
3438 child = (Win32BaseWindow *)child->getNextChild();
3439 }
3440 }
3441 }
3442
3443 lastchild = child;
3444 nextchild = (Win32BaseWindow *)child->getNextChild();
3445 while (TRUE)
3446 {
3447 if (!nextchild) nextchild = (Win32BaseWindow *)getFirstChild();
3448
3449 if (child == nextchild) break;
3450
3451 if ((nextchild->getStyle() & WS_TABSTOP) && (nextchild->getStyle() & WS_VISIBLE) &&
3452 !(nextchild->getStyle() & WS_DISABLED))
3453 {
3454 lastchild = nextchild;
3455 if (!fPrevious) break;
3456 }
3457 nextchild = (Win32BaseWindow *)nextchild->getNextChild();
3458 }
3459 retvalue = lastchild->getWindowHandle();
3460
3461END:
3462 return retvalue;
3463}
3464//******************************************************************************
3465//******************************************************************************
3466HWND Win32BaseWindow::getNextDlgGroupItem(HWND hwndCtrl, BOOL fPrevious)
3467{
3468 Win32BaseWindow *child, *nextchild, *lastchild;
3469 HWND retvalue;
3470
3471 if (hwndCtrl)
3472 {
3473 child = GetWindowFromHandle(hwndCtrl);
3474 if (!child)
3475 {
3476 retvalue = 0;
3477 goto END;
3478 }
3479 /* Make sure hwndCtrl is a top-level child */
3480 while ((child->getStyle() & WS_CHILD) && (child->getParent() != this))
3481 {
3482 child = child->getParent();
3483 if(child == NULL) break;
3484 }
3485
3486 if (!child || (child->getParent() != this))
3487 {
3488 retvalue = 0;
3489 goto END;
3490 }
3491 }
3492 else
3493 {
3494 /* No ctrl specified -> start from the beginning */
3495 child = (Win32BaseWindow *)getFirstChild();
3496 if (!child)
3497 {
3498 retvalue = 0;
3499 goto END;
3500 }
3501
3502 if (fPrevious)
3503 {
3504 while (child->getNextChild())
3505 {
3506 child = (Win32BaseWindow *)child->getNextChild();
3507 }
3508 }
3509 }
3510
3511 lastchild = child;
3512 nextchild = (Win32BaseWindow *)child->getNextChild();
3513 while (TRUE)
3514 {
3515 if (!nextchild || (nextchild->getStyle() & WS_GROUP))
3516 {
3517 /* Wrap-around to the beginning of the group */
3518 Win32BaseWindow *pWndTemp;
3519
3520 nextchild = (Win32BaseWindow *)getFirstChild();
3521
3522 for(pWndTemp = nextchild;pWndTemp;pWndTemp = (Win32BaseWindow *)pWndTemp->getNextChild())
3523 {
3524 if (pWndTemp->getStyle() & WS_GROUP)
3525 nextchild = pWndTemp;
3526
3527 if (pWndTemp == child)
3528 break;
3529 }
3530
3531 }
3532 if (nextchild == child)
3533 break;
3534
3535 if ((nextchild->getStyle() & WS_VISIBLE) && !(nextchild->getStyle() & WS_DISABLED))
3536 {
3537 lastchild = nextchild;
3538
3539 if (!fPrevious)
3540 break;
3541 }
3542
3543 nextchild = (Win32BaseWindow *)nextchild->getNextChild();
3544 }
3545 retvalue = lastchild->getWindowHandle();
3546END:
3547 return retvalue;
3548}
3549//******************************************************************************
3550//******************************************************************************
3551#ifdef DEBUG
3552void PrintWindowStyle(DWORD dwStyle, DWORD dwExStyle)
3553{
3554 char style[256] = "";
3555 char exstyle[256] = "";
3556
3557 /* Window styles */
3558 if(dwStyle & WS_CHILD)
3559 strcat(style, "WS_CHILD ");
3560 if(dwStyle & WS_POPUP)
3561 strcat(style, "WS_POPUP ");
3562 if(dwStyle & WS_VISIBLE)
3563 strcat(style, "WS_VISIBLE ");
3564 if(dwStyle & WS_DISABLED)
3565 strcat(style, "WS_DISABLED ");
3566 if(dwStyle & WS_CLIPSIBLINGS)
3567 strcat(style, "WS_CLIPSIBLINGS ");
3568 if(dwStyle & WS_CLIPCHILDREN)
3569 strcat(style, "WS_CLIPCHILDREN ");
3570 if(dwStyle & WS_MAXIMIZE)
3571 strcat(style, "WS_MAXIMIZE ");
3572 if(dwStyle & WS_MINIMIZE)
3573 strcat(style, "WS_MINIMIZE ");
3574 if(dwStyle & WS_GROUP)
3575 strcat(style, "WS_GROUP ");
3576 if(dwStyle & WS_TABSTOP)
3577 strcat(style, "WS_TABSTOP ");
3578
3579 if((dwStyle & WS_CAPTION) == WS_CAPTION)
3580 strcat(style, "WS_CAPTION ");
3581 if(dwStyle & WS_DLGFRAME)
3582 strcat(style, "WS_DLGFRAME ");
3583 if(dwStyle & WS_BORDER)
3584 strcat(style, "WS_BORDER ");
3585
3586 if(dwStyle & WS_VSCROLL)
3587 strcat(style, "WS_VSCROLL ");
3588 if(dwStyle & WS_HSCROLL)
3589 strcat(style, "WS_HSCROLL ");
3590 if(dwStyle & WS_SYSMENU)
3591 strcat(style, "WS_SYSMENU ");
3592 if(dwStyle & WS_THICKFRAME)
3593 strcat(style, "WS_THICKFRAME ");
3594 if(dwStyle & WS_MINIMIZEBOX)
3595 strcat(style, "WS_MINIMIZEBOX ");
3596 if(dwStyle & WS_MAXIMIZEBOX)
3597 strcat(style, "WS_MAXIMIZEBOX ");
3598
3599 if(dwExStyle & WS_EX_DLGMODALFRAME)
3600 strcat(exstyle, "WS_EX_DLGMODALFRAME ");
3601 if(dwExStyle & WS_EX_ACCEPTFILES)
3602 strcat(exstyle, "WS_EX_ACCEPTFILES ");
3603 if(dwExStyle & WS_EX_NOPARENTNOTIFY)
3604 strcat(exstyle, "WS_EX_NOPARENTNOTIFY ");
3605 if(dwExStyle & WS_EX_TOPMOST)
3606 strcat(exstyle, "WS_EX_TOPMOST ");
3607 if(dwExStyle & WS_EX_TRANSPARENT)
3608 strcat(exstyle, "WS_EX_TRANSPARENT ");
3609
3610 if(dwExStyle & WS_EX_MDICHILD)
3611 strcat(exstyle, "WS_EX_MDICHILD ");
3612 if(dwExStyle & WS_EX_TOOLWINDOW)
3613 strcat(exstyle, "WS_EX_TOOLWINDOW ");
3614 if(dwExStyle & WS_EX_WINDOWEDGE)
3615 strcat(exstyle, "WS_EX_WINDOWEDGE ");
3616 if(dwExStyle & WS_EX_CLIENTEDGE)
3617 strcat(exstyle, "WS_EX_CLIENTEDGE ");
3618 if(dwExStyle & WS_EX_CONTEXTHELP)
3619 strcat(exstyle, "WS_EX_CONTEXTHELP ");
3620 if(dwExStyle & WS_EX_RIGHT)
3621 strcat(exstyle, "WS_EX_RIGHT ");
3622 if(dwExStyle & WS_EX_LEFT)
3623 strcat(exstyle, "WS_EX_LEFT ");
3624 if(dwExStyle & WS_EX_RTLREADING)
3625 strcat(exstyle, "WS_EX_RTLREADING ");
3626 if(dwExStyle & WS_EX_LTRREADING)
3627 strcat(exstyle, "WS_EX_LTRREADING ");
3628 if(dwExStyle & WS_EX_LEFTSCROLLBAR)
3629 strcat(exstyle, "WS_EX_LEFTSCROLLBAR ");
3630 if(dwExStyle & WS_EX_RIGHTSCROLLBAR)
3631 strcat(exstyle, "WS_EX_RIGHTSCROLLBAR ");
3632 if(dwExStyle & WS_EX_CONTROLPARENT)
3633 strcat(exstyle, "WS_EX_CONTROLPARENT ");
3634 if(dwExStyle & WS_EX_STATICEDGE)
3635 strcat(exstyle, "WS_EX_STATICEDGE ");
3636 if(dwExStyle & WS_EX_APPWINDOW)
3637 strcat(exstyle, "WS_EX_APPWINDOW ");
3638
3639 dprintf(("Window style: %x %s", dwStyle, style));
3640 dprintf(("Window exStyle: %x %s", dwExStyle, exstyle));
3641}
3642#endif
3643//******************************************************************************
3644//******************************************************************************
3645
3646GenericObject *Win32BaseWindow::windows = NULL;
Note: See TracBrowser for help on using the repository browser.