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

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

SetWindowPos fixes for SWP_FRAMECHANGED

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