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

Last change on this file since 6773 was 6773, checked in by sandervl, 24 years ago

WM_MOUSEACTIVATE & WM_NEXTMENU fixes

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