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

Last change on this file since 8377 was 8377, checked in by sandervl, 23 years ago

PF: SetParent mustn't change WS_CHILD; experimental getParent change; listbox/combobox fixes for MFC applications

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