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

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

implemented simple drag & drop with WM_DROPFILES

File size: 138.1 KB
Line 
1/* $Id: win32wbase.cpp,v 1.325 2002-06-01 17:26:31 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::MsgDropFiles(UINT cFiles, POINT point, LPSTR pszFiles, UINT cbszFiles, BOOL fNonClient)
1271{
1272 DROPFILES *pDropFile;
1273 HGLOBAL hDropFile;
1274 HWND hwnd;
1275
1276 hwnd = (getExStyle() & WS_EX_ACCEPTFILES) ? getWindowHandle() : ::GetParent(getWindowHandle());
1277 cbszFiles++; //extra terminating 0
1278
1279 if(::IsWindowUnicode(hwnd)) {
1280 dprintf(("unicode dropfiles"));
1281 cbszFiles *= 2;
1282 }
1283
1284 hDropFile = GlobalAlloc(0, sizeof(DROPFILES)+cbszFiles);
1285 pDropFile = (DROPFILES *)GlobalLock(hDropFile);
1286 if(pDropFile == NULL) {
1287 DebugInt3();
1288 return 0;
1289 }
1290 pDropFile->pFiles = sizeof(DROPFILES);
1291 pDropFile->fNC = fNonClient;
1292 pDropFile->fWide = ::IsWindowUnicode(hwnd);
1293 pDropFile->pt = point;
1294 if(::IsWindowUnicode(hwnd)) {
1295 LPWSTR lpszFilesW = (LPWSTR)(pDropFile+1);
1296 while(*pszFiles) {
1297 int len = strlen(pszFiles);
1298 MultiByteToWideChar(CP_ACP, 0, pszFiles, -1, lpszFilesW, len);
1299 pszFiles += len + 1;
1300 lpszFilesW += len + 1;
1301 }
1302 *lpszFilesW = 0;
1303 }
1304 else {
1305 //copy strings (excluding terminating 0)
1306 memcpy((pDropFile+1), pszFiles, cbszFiles-1);
1307 }
1308 GlobalUnlock(hDropFile);
1309 ::SendMessageA(hwnd, WM_DROPFILES, hDropFile, 0);
1310 return 0;
1311}
1312//******************************************************************************
1313//******************************************************************************
1314BOOL Win32BaseWindow::AcceptsDropFiles()
1315{
1316 //Is it correct if the window or parent accepts files or must we check the topparent parent?
1317 if(getExStyle() & WS_EX_ACCEPTFILES) {
1318 return TRUE;
1319 }
1320 DWORD dwStyle = GetWindowLongA(::GetParent(getWindowHandle()), GWL_EXSTYLE);
1321 if(!(dwStyle & WS_EX_ACCEPTFILES)) {
1322 return FALSE;
1323 }
1324 return TRUE;
1325}
1326//******************************************************************************
1327//******************************************************************************
1328ULONG Win32BaseWindow::MsgChar(MSG *msg)
1329{
1330 return DispatchMsgA(msg);
1331}
1332//******************************************************************************
1333//TODO: Should use update region, not rectangle
1334//******************************************************************************
1335ULONG Win32BaseWindow::MsgNCPaint(PRECT pUpdateRect)
1336{
1337 HRGN hrgn;
1338 ULONG rc;
1339 RECT client = rectClient;
1340
1341 if ((pUpdateRect->left >= client.left) && (pUpdateRect->left < client.right) &&
1342 (pUpdateRect->right >= client.left) && (pUpdateRect->right < client.right) &&
1343 (pUpdateRect->top >= client.top) && (pUpdateRect->top < client.bottom) &&
1344 (pUpdateRect->bottom >= client.top) && (pUpdateRect->bottom < client.bottom)
1345 && (!(getStyle() & WS_MINIMIZE)))
1346 {
1347 return 0;
1348 }
1349
1350 dprintf(("MsgNCPaint (%d,%d)(%d,%d)", pUpdateRect->left, pUpdateRect->top, pUpdateRect->right, pUpdateRect->bottom));
1351 hrgn = CreateRectRgnIndirect(pUpdateRect);
1352
1353 rc = SendMessageA(getWindowHandle(),WM_NCPAINT, hrgn, 0);
1354 //Send WM_PAINTICON here if minimized, because client window will
1355 //not receive a (valid) WM_PAINT message
1356 if (getStyle() & WS_MINIMIZE)
1357 {
1358 rc = SendMessageA(getWindowHandle(),WM_PAINTICON, 1, 0);
1359 }
1360
1361 DeleteObject(hrgn);
1362
1363 return rc;
1364}
1365//******************************************************************************
1366//Called when either the frame's size or position has changed (lpWndPos != NULL)
1367//or when the frame layout has changed (i.e. scrollbars added/removed) (lpWndPos == NULL)
1368//******************************************************************************
1369ULONG Win32BaseWindow::MsgFormatFrame(WINDOWPOS *lpWndPos)
1370{
1371 RECT oldWindowRect = rectWindow, client = rectClient, newWindowRect;
1372 RECT newClientRect;
1373 WINDOWPOS wndPos;
1374 ULONG rc;
1375
1376 if(lpWndPos)
1377 {
1378 //set new window rectangle
1379 setWindowRect(lpWndPos->x, lpWndPos->y, lpWndPos->x+lpWndPos->cx,
1380 lpWndPos->y+lpWndPos->cy);
1381 newWindowRect = rectWindow;
1382 }
1383 else {
1384 wndPos.hwnd = getWindowHandle();
1385 wndPos.hwndInsertAfter = 0;
1386 newWindowRect= rectWindow;
1387 wndPos.x = newWindowRect.left;
1388 wndPos.y = newWindowRect.top;
1389 wndPos.cx = newWindowRect.right - newWindowRect.left;
1390 wndPos.cy = newWindowRect.bottom - newWindowRect.top;
1391 wndPos.flags = SWP_FRAMECHANGED;
1392 lpWndPos = &wndPos;
1393 }
1394
1395 newClientRect = rectClient;
1396 rc = SendNCCalcSize(TRUE, &newWindowRect, &oldWindowRect, &client, lpWndPos, &newClientRect);
1397 rectClient = newClientRect; //must update rectClient here
1398
1399 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));
1400 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));
1401
1402 if(!CanReceiveSizeMsgs() || !EqualRect(&client, &rectClient)) {
1403 OSLibWinSetClientPos(getOS2WindowHandle(), rectClient.left, rectClient.top, getClientWidth(), getClientHeight(), getWindowHeight());
1404 }
1405
1406#if 1
1407//this doesn't always work
1408// if(CanReceiveSizeMsgs() && (client.left != rectClient.left || client.top != rectClient.top))
1409 if(CanReceiveSizeMsgs() && ((oldWindowRect.right - oldWindowRect.left < rectClient.left
1410 || oldWindowRect.bottom - oldWindowRect.top < rectClient.top) ||
1411 (EqualRect(&oldWindowRect, &rectWindow) && (client.left != rectClient.left || client.top != rectClient.top))))
1412 {
1413 Win32BaseWindow *child = (Win32BaseWindow *)getFirstChild();
1414
1415 //client rectangle has moved -> inform children
1416 dprintf(("MsgFormatFrame -> client rectangle has changed, move children"));
1417 while(child) {
1418 ::SetWindowPos(child->getWindowHandle(),
1419 HWND_TOP, child->getWindowRect()->left,
1420 child->getWindowRect()->top, 0, 0,
1421 SWP_NOACTIVATE|SWP_NOSIZE|SWP_NOZORDER);
1422 child = (Win32BaseWindow *)child->getNextChild();
1423 }
1424 }
1425#endif
1426 if(fOS2Look && ((dwStyle & WS_CAPTION) == WS_CAPTION))
1427 {
1428 RECT rect = {0};
1429 int height = getWindowHeight();
1430 RECTLOS2 rectOS2;
1431
1432 AdjustRectOuter(&rect, FALSE);
1433
1434 rect.left = -rect.left;
1435 rect.top = rect.bottom - rect.top;
1436 rect.right = rectWindow.right - rectWindow.left - rect.right;
1437
1438 rectOS2.xLeft = rect.left;
1439 rectOS2.xRight = rect.right;
1440 rectOS2.yBottom = height - rect.top;
1441 rectOS2.yTop = height - rect.bottom;
1442 OSLibWinPositionFrameControls(getOS2FrameWindowHandle(), &rectOS2, dwStyle, dwExStyle, IconForWindow(ICON_SMALL));
1443 }
1444 return rc;
1445}
1446//******************************************************************************
1447//******************************************************************************
1448ULONG Win32BaseWindow::MsgSetText(LPSTR lpsz, LONG cch)
1449{
1450 return SendMessageA(getWindowHandle(),WM_SETTEXT, 0, (LPARAM)lpsz);
1451}
1452//******************************************************************************
1453//******************************************************************************
1454ULONG Win32BaseWindow::MsgGetTextLength()
1455{
1456 return SendMessageA(getWindowHandle(),WM_GETTEXTLENGTH, 0, 0);
1457}
1458//******************************************************************************
1459//******************************************************************************
1460void Win32BaseWindow::MsgGetText(char *wndtext, ULONG textlength)
1461{
1462 SendMessageA(getWindowHandle(),WM_GETTEXT, textlength, (LPARAM)wndtext);
1463}
1464//******************************************************************************
1465//******************************************************************************
1466BOOL Win32BaseWindow::isMDIClient()
1467{
1468 return FALSE;
1469}
1470//******************************************************************************
1471//******************************************************************************
1472BOOL Win32BaseWindow::isMDIChild()
1473{
1474 return FALSE;
1475}
1476//******************************************************************************
1477//TODO: Not complete
1478//******************************************************************************
1479BOOL Win32BaseWindow::isFrameWindow()
1480{
1481 if(getParent() == NULL)
1482 return TRUE;
1483
1484 return FALSE;
1485}
1486//******************************************************************************
1487//******************************************************************************
1488BOOL Win32BaseWindow::isDesktopWindow()
1489{
1490 return FALSE;
1491}
1492//******************************************************************************
1493//******************************************************************************
1494BOOL Win32BaseWindow::IsWindowIconic()
1495{
1496 return ((getStyle() & WS_MINIMIZE) && windowClass->getIcon());
1497}
1498//******************************************************************************
1499//******************************************************************************
1500SCROLLBAR_INFO *Win32BaseWindow::getScrollInfo(int nBar)
1501{
1502 switch(nBar)
1503 {
1504 case SB_HORZ:
1505 if (!horzScrollInfo)
1506 {
1507 horzScrollInfo = (SCROLLBAR_INFO*)malloc(sizeof(SCROLLBAR_INFO));
1508 if (!horzScrollInfo) break;
1509 horzScrollInfo->MinVal = horzScrollInfo->CurVal = horzScrollInfo->Page = 0;
1510 horzScrollInfo->MaxVal = 100;
1511 horzScrollInfo->flags = ESB_ENABLE_BOTH;
1512 }
1513 return horzScrollInfo;
1514
1515 case SB_VERT:
1516 if (!vertScrollInfo)
1517 {
1518 vertScrollInfo = (SCROLLBAR_INFO*)malloc(sizeof(SCROLLBAR_INFO));
1519 if (!vertScrollInfo) break;
1520 vertScrollInfo->MinVal = vertScrollInfo->CurVal = vertScrollInfo->Page = 0;
1521 vertScrollInfo->MaxVal = 100;
1522 vertScrollInfo->flags = ESB_ENABLE_BOTH;
1523 }
1524 return vertScrollInfo;
1525 }
1526
1527 return NULL;
1528}
1529//******************************************************************************
1530//******************************************************************************
1531LRESULT Win32BaseWindow::DefWndControlColor(UINT ctlType, HDC hdc)
1532{
1533 //SvL: Set background color to default button color (not window (white))
1534 if(ctlType == CTLCOLOR_BTN)
1535 {
1536 SetBkColor(hdc, GetSysColor(COLOR_BTNFACE));
1537 SetTextColor(hdc, GetSysColor(COLOR_WINDOWTEXT));
1538 return GetSysColorBrush(COLOR_BTNFACE);
1539 }
1540 //SvL: Set background color to default dialog color if window is dialog
1541 if((ctlType == CTLCOLOR_DLG || ctlType == CTLCOLOR_STATIC) && IsDialog()) {
1542 SetBkColor(hdc, GetSysColor(COLOR_BTNFACE));
1543 SetTextColor(hdc, GetSysColor(COLOR_WINDOWTEXT));
1544 return GetSysColorBrush(COLOR_BTNFACE);
1545 }
1546 if( ctlType == CTLCOLOR_SCROLLBAR)
1547 {
1548 HBRUSH hb = GetSysColorBrush(COLOR_SCROLLBAR);
1549 COLORREF bk = GetSysColor(COLOR_3DHILIGHT);
1550 SetTextColor( hdc, GetSysColor(COLOR_3DFACE));
1551 SetBkColor( hdc, bk);
1552
1553 /* if COLOR_WINDOW happens to be the same as COLOR_3DHILIGHT
1554 * we better use 0x55aa bitmap brush to make scrollbar's background
1555 * look different from the window background.
1556 */
1557 if (bk == GetSysColor(COLOR_WINDOW)) {
1558 return GetPattern55AABrush();
1559 }
1560
1561 UnrealizeObject( hb );
1562 return (LRESULT)hb;
1563 }
1564
1565 SetTextColor( hdc, GetSysColor(COLOR_WINDOWTEXT));
1566
1567 if ((ctlType == CTLCOLOR_EDIT) || (ctlType == CTLCOLOR_LISTBOX))
1568 {
1569 SetBkColor( hdc, GetSysColor(COLOR_WINDOW) );
1570 }
1571 else
1572 {
1573 SetBkColor( hdc, GetSysColor(COLOR_3DFACE) );
1574 return (LRESULT)GetSysColorBrush(COLOR_3DFACE);
1575 }
1576 return (LRESULT)GetSysColorBrush(COLOR_WINDOW);
1577}
1578//******************************************************************************
1579//******************************************************************************
1580LRESULT Win32BaseWindow::DefWndPrint(HDC hdc,ULONG uFlags)
1581{
1582 /*
1583 * Visibility flag.
1584 */
1585 if ( (uFlags & PRF_CHECKVISIBLE) &&
1586 !IsWindowVisible(getWindowHandle()) )
1587 return 0;
1588
1589 /*
1590 * Unimplemented flags.
1591 */
1592 if ( (uFlags & PRF_CHILDREN) ||
1593 (uFlags & PRF_OWNED) ||
1594 (uFlags & PRF_NONCLIENT) )
1595 {
1596 dprintf(("WM_PRINT message with unsupported flags\n"));
1597 }
1598
1599 /*
1600 * Background
1601 */
1602 if ( uFlags & PRF_ERASEBKGND)
1603 SendMessageA(getWindowHandle(),WM_ERASEBKGND, (WPARAM)hdc, 0);
1604
1605 /*
1606 * Client area
1607 */
1608 if ( uFlags & PRF_CLIENT)
1609 SendMessageA(getWindowHandle(),WM_PRINTCLIENT, (WPARAM)hdc, PRF_CLIENT);
1610
1611
1612 return 0;
1613}
1614//******************************************************************************
1615//******************************************************************************
1616LRESULT Win32BaseWindow::DefWindowProcA(UINT Msg, WPARAM wParam, LPARAM lParam)
1617{
1618 switch(Msg)
1619 {
1620 case WM_CLOSE:
1621 dprintf(("DefWindowProcA: WM_CLOSE %x", getWindowHandle()));
1622 DestroyWindow();
1623 return 0;
1624
1625 case WM_GETTEXTLENGTH:
1626 return windowNameLength;
1627
1628 case WM_GETTEXT:
1629 if (!lParam || !wParam)
1630 return 0;
1631 if (!windowNameA)
1632 ((LPSTR)lParam)[0] = 0;
1633 else
1634 memcpy((LPSTR)lParam, windowNameA, min(windowNameLength+1, wParam) );
1635 return min(windowNameLength, wParam);
1636
1637 case WM_SETTEXT:
1638 {
1639 LPCSTR lpsz = (LPCSTR)lParam;
1640
1641 // reallocate if new buffer is larger
1642 if (!lParam)
1643 {
1644 free(windowNameA);
1645 free(windowNameW);
1646 windowNameLength = 0;
1647 windowNameA = NULL;
1648 windowNameW = NULL;
1649 }
1650 else
1651 {
1652 // determine length of new text
1653 int iTextLength = strlen(lpsz);
1654
1655 if (windowNameLength < iTextLength)
1656 {
1657 if (windowNameA)
1658 {
1659 free(windowNameA);
1660 windowNameA = NULL;
1661 }
1662
1663 if (windowNameW)
1664 {
1665 free(windowNameW);
1666 windowNameW = NULL;
1667 }
1668 }
1669
1670 windowNameLength = iTextLength;
1671 if(!windowNameA)
1672 windowNameA = (LPSTR)_smalloc(windowNameLength+1);
1673 memcpy(windowNameA, lpsz, windowNameLength+1);
1674 if(!windowNameW)
1675 windowNameW = (LPWSTR)_smalloc((windowNameLength+1)*sizeof(WCHAR));
1676 lstrcpynAtoW(windowNameW, windowNameA, windowNameLength+1);
1677 }
1678
1679 dprintf(("WM_SETTEXT of %x to %s\n", Win32Hwnd, lParam));
1680 if ((dwStyle & WS_CAPTION) == WS_CAPTION)
1681 {
1682 HandleNCPaint((HRGN)1);
1683 if(hTaskList) {
1684 OSLibWinChangeTaskList(hTaskList, OS2HwndFrame, getWindowNameA(), (getStyle() & WS_VISIBLE) ? 1 : 0);
1685 }
1686 if(fOS2Look) {
1687 OSLibWinSetTitleBarText(OS2HwndFrame, getWindowNameA());
1688 }
1689 }
1690
1691 return TRUE;
1692 }
1693
1694 case WM_SETREDRAW:
1695 {
1696 if (wParam)
1697 {
1698 setStyle(getStyle() | WS_VISIBLE);
1699 dprintf(("Enable window update for %x", getWindowHandle()));
1700 OSLibWinEnableWindowUpdate(OS2HwndFrame, OS2Hwnd, TRUE);
1701 }
1702 else
1703 {
1704 if (getStyle() & WS_VISIBLE)
1705 {
1706 setStyle(getStyle() & ~WS_VISIBLE);
1707 dprintf(("Disable window update for %x", getWindowHandle()));
1708 OSLibWinEnableWindowUpdate(OS2HwndFrame, OS2Hwnd, FALSE);
1709 }
1710 }
1711 return 0;
1712 }
1713
1714 case WM_CTLCOLORMSGBOX:
1715 case WM_CTLCOLOREDIT:
1716 case WM_CTLCOLORLISTBOX:
1717 case WM_CTLCOLORBTN:
1718 case WM_CTLCOLORDLG:
1719 case WM_CTLCOLORSTATIC:
1720 case WM_CTLCOLORSCROLLBAR:
1721 return DefWndControlColor(Msg - WM_CTLCOLORMSGBOX, (HDC)wParam);
1722
1723 case WM_CTLCOLOR:
1724 return DefWndControlColor(HIWORD(lParam), (HDC)wParam);
1725
1726 case WM_VKEYTOITEM:
1727 case WM_CHARTOITEM:
1728 return -1;
1729
1730 case WM_PARENTNOTIFY:
1731 return 0;
1732
1733 case WM_MOUSEACTIVATE:
1734 {
1735 dprintf(("DefWndProc: WM_MOUSEACTIVATE for %x Msg %s", Win32Hwnd, GetMsgText(HIWORD(lParam))));
1736 if(getStyle() & WS_CHILD && !(getExStyle() & WS_EX_NOPARENTNOTIFY) )
1737 {
1738 if(getParent()) {
1739 LRESULT rc = SendMessageA(getParent()->getWindowHandle(), WM_MOUSEACTIVATE, wParam, lParam );
1740 if(rc) return rc;
1741 }
1742 }
1743 return (LOWORD(lParam) == HTCAPTION) ? MA_NOACTIVATE : MA_ACTIVATE;
1744 }
1745
1746 case WM_ACTIVATE:
1747 /* The default action in Windows is to set the keyboard focus to
1748 * the window, if it's being activated and not minimized */
1749 if (LOWORD(wParam) != WA_INACTIVE) {
1750 if(!(getStyle() & WS_MINIMIZE))
1751 SetFocus(getWindowHandle());
1752 }
1753 return 0;
1754
1755 case WM_SETCURSOR:
1756 {
1757 dprintf(("DefWndProc: WM_SETCURSOR for %x Msg %s", Win32Hwnd, GetMsgText(HIWORD(lParam))));
1758 if((getStyle() & WS_CHILD))
1759 {
1760 if(getParent()) {
1761 LRESULT rc = SendMessageA(getParent()->getWindowHandle(), WM_SETCURSOR, wParam, lParam);
1762 if(rc) return rc;
1763 }
1764 }
1765 if (wParam == getWindowHandle())
1766 {
1767 HCURSOR hCursor;
1768
1769 switch(LOWORD(lParam))
1770 {
1771 case HTCLIENT:
1772 hCursor = windowClass ? windowClass->getCursor():LoadCursorA(0,IDC_ARROWA);
1773 break;
1774
1775 case HTLEFT:
1776 case HTRIGHT:
1777 hCursor = LoadCursorA(0,IDC_SIZEWEA);
1778 break;
1779
1780 case HTTOP:
1781 case HTBOTTOM:
1782 hCursor = LoadCursorA(0,IDC_SIZENSA);
1783 break;
1784
1785 case HTTOPLEFT:
1786 case HTBOTTOMRIGHT:
1787 hCursor = LoadCursorA(0,IDC_SIZENWSEA);
1788 break;
1789
1790 case HTTOPRIGHT:
1791 case HTBOTTOMLEFT:
1792 hCursor = LoadCursorA(0,IDC_SIZENESWA);
1793 break;
1794
1795 default:
1796 hCursor = LoadCursorA(0,IDC_ARROWA);
1797 break;
1798 }
1799
1800 if (hCursor)
1801 {
1802 SetCursor(hCursor);
1803 return 1;
1804 }
1805 else return 0;
1806 }
1807 else return 0;
1808 }
1809
1810 case WM_MOUSEMOVE:
1811 return 0;
1812
1813 case WM_WINDOWPOSCHANGED:
1814 {
1815 PWINDOWPOS wpos = (PWINDOWPOS)lParam;
1816 WPARAM wp = SIZE_RESTORED;
1817
1818 if (!(wpos->flags & SWP_NOMOVE) && !(wpos->flags & SWP_NOCLIENTMOVE))
1819 {
1820 SendMessageA(getWindowHandle(),WM_MOVE, 0, MAKELONG(rectClient.left,rectClient.top));
1821 }
1822 if (!(wpos->flags & SWP_NOSIZE) && !(wpos->flags & SWP_NOCLIENTSIZE))
1823 {
1824 if (dwStyle & WS_MAXIMIZE) wp = SIZE_MAXIMIZED;
1825 else
1826 if (dwStyle & WS_MINIMIZE) wp = SIZE_MINIMIZED;
1827
1828 SendMessageA(getWindowHandle(),WM_SIZE, wp, MAKELONG(rectClient.right - rectClient.left,
1829 rectClient.bottom - rectClient.top));
1830 }
1831 return 0;
1832 }
1833 case WM_WINDOWPOSCHANGING:
1834 return HandleWindowPosChanging((WINDOWPOS *)lParam);
1835
1836 case WM_ERASEBKGND:
1837 case WM_ICONERASEBKGND:
1838 {
1839 RECT rect;
1840 int rc;
1841
1842 if (!windowClass || !windowClass->getBackgroundBrush()) return 0;
1843
1844 rc = GetClipBox( (HDC)wParam, &rect );
1845 if ((rc == SIMPLEREGION) || (rc == COMPLEXREGION))
1846 {
1847 HBRUSH hBrush = windowClass->getBackgroundBrush();
1848
1849 if (hBrush <= (HBRUSH)(SYSCOLOR_GetLastColor()+1))
1850 hBrush = GetSysColorBrush(hBrush-1);
1851
1852 FillRect( (HDC)wParam, &rect, hBrush);
1853 }
1854 return 1;
1855 }
1856
1857 case WM_PRINT:
1858 return DefWndPrint(wParam,lParam);
1859
1860 case WM_SYNCPAINT:
1861 RedrawWindow(getWindowHandle(), NULL, 0, RDW_ERASENOW | RDW_ERASE | RDW_ALLCHILDREN);
1862 return 0;
1863
1864 case WM_PAINTICON:
1865 case WM_PAINT:
1866 {
1867 PAINTSTRUCT ps;
1868 HDC hdc = BeginPaint(getWindowHandle(), &ps );
1869 if( hdc )
1870 {
1871 if( (getStyle() & WS_MINIMIZE) && (getWindowClass()->getIcon() || hIcon))
1872 {
1873 int x = (rectWindow.right - rectWindow.left - GetSystemMetrics(SM_CXICON))/2;
1874 int y = (rectWindow.bottom - rectWindow.top - GetSystemMetrics(SM_CYICON))/2;
1875 dprintf(("Painting class icon: vis rect=(%i,%i - %i,%i)\n", ps.rcPaint.left, ps.rcPaint.top, ps.rcPaint.right, ps.rcPaint.bottom ));
1876 DrawIcon(hdc, x, y, hIcon ? hIcon:getWindowClass()->getIcon() );
1877 }
1878 EndPaint(getWindowHandle(), &ps );
1879 }
1880 return 0;
1881 }
1882
1883 case WM_GETDLGCODE:
1884 return 0;
1885
1886 case WM_NCPAINT:
1887 return HandleNCPaint((HRGN)wParam);
1888
1889 case WM_NCACTIVATE:
1890 return HandleNCActivate(wParam);
1891
1892 case WM_NCCREATE:
1893 return(TRUE);
1894
1895 case WM_NCDESTROY:
1896 return 0;
1897
1898 case WM_NCCALCSIZE:
1899 return HandleNCCalcSize((BOOL)wParam,(RECT*)lParam);
1900
1901 case WM_NCLBUTTONDOWN:
1902 return HandleNCLButtonDown(wParam,lParam);
1903
1904 case WM_LBUTTONDBLCLK:
1905 case WM_NCLBUTTONDBLCLK:
1906 return HandleNCLButtonDblClk(wParam,lParam);
1907
1908 case WM_NCRBUTTONDOWN:
1909 case WM_NCRBUTTONDBLCLK:
1910 case WM_NCMBUTTONDOWN:
1911 case WM_NCMBUTTONDBLCLK:
1912 if (lastHitTestVal == HTERROR) MessageBeep(MB_ICONEXCLAMATION);
1913 return 0;
1914
1915 case WM_NCRBUTTONUP:
1916 return HandleNCRButtonUp(wParam,lParam);
1917
1918 case WM_NCMBUTTONUP:
1919 return 0;
1920
1921 case WM_NCHITTEST:
1922 {
1923 POINT point;
1924 LRESULT retvalue;
1925
1926 point.x = (SHORT)LOWORD(lParam);
1927 point.y = (SHORT)HIWORD(lParam);
1928
1929 retvalue = HandleNCHitTest(point);
1930#if 0 //CB: let the Corel people fix the bugs first
1931 if(retvalue == HTMENU)
1932 MENU_TrackMouseMenuBar_MouseMove(Win32Hwnd,point,TRUE);
1933 else
1934 MENU_TrackMouseMenuBar_MouseMove(Win32Hwnd,point,FALSE);
1935#endif
1936 return retvalue;
1937 }
1938
1939 case WM_SYSCOMMAND:
1940 {
1941 POINT point;
1942
1943 point.x = LOWORD(lParam);
1944 point.y = HIWORD(lParam);
1945 return HandleSysCommand(wParam,&point);
1946 }
1947
1948 case WM_SYSKEYDOWN:
1949 {
1950 if( HIWORD(lParam) & KEYDATA_ALT )
1951 {
1952 /* if( HIWORD(lParam) & ~KEYDATA_PREVSTATE ) */
1953 if( wParam == VK_MENU && !iMenuSysKey )
1954 iMenuSysKey = 1;
1955 else
1956 iMenuSysKey = 0;
1957
1958 iF10Key = 0;
1959
1960 if( wParam == VK_F4 ) /* try to close the window */
1961 {
1962 HWND top = GetTopParent();
1963 if (!(GetClassLongW( top, GCL_STYLE ) & CS_NOCLOSE))
1964 PostMessageW( top, WM_SYSCOMMAND, SC_CLOSE, 0 );
1965 }
1966 }
1967 else if( wParam == VK_F10 )
1968 iF10Key = 1;
1969 else
1970 if( wParam == VK_ESCAPE && (GetKeyState(VK_SHIFT) & 0x8000))
1971 SendMessageW(getWindowHandle(), WM_SYSCOMMAND, SC_KEYMENU, VK_SPACE );
1972
1973 Win32BaseWindow *siblingWindow;
1974 HWND sibling;
1975 char nameBuffer [40], mnemonic;
1976 int nameLength;
1977
1978 GetWindowTextA (nameBuffer, 40);
1979
1980 // search all sibling to see it this key is their mnemonic
1981 sibling = GetWindow (GW_HWNDFIRST);
1982 while (sibling != 0) {
1983 siblingWindow = GetWindowFromHandle (sibling);
1984 nameLength = siblingWindow->GetWindowTextA (nameBuffer, 40);
1985
1986 // find the siblings mnemonic
1987 mnemonic = '\0';
1988 for (int i=0 ; i<nameLength ; i++) {
1989 if (IsDBCSLeadByte(nameBuffer[i])) {
1990 // Skip DBCS
1991 continue;
1992 }
1993 if (nameBuffer [i] == '&') {
1994 mnemonic = nameBuffer [i+1];
1995 if ((mnemonic >= 'a') && (mnemonic <= 'z'))
1996 mnemonic -= 32; // make it uppercase
1997 break; // stop searching
1998 }
1999 }
2000
2001 // key matches siblings mnemonic, send mouseclick
2002 if (mnemonic == (char) wParam) {
2003 ::SendMessageA(siblingWindow->getWindowHandle(), BM_CLICK, 0, 0);
2004 }
2005 sibling = siblingWindow->GetNextWindow (GW_HWNDNEXT);
2006 RELEASE_WNDOBJ(siblingWindow);
2007 }
2008
2009 return 0;
2010 }
2011
2012 case WM_KEYUP:
2013 case WM_SYSKEYUP:
2014 /* Press and release F10 or ALT */
2015 if (((wParam == VK_MENU) && iMenuSysKey) ||
2016 ((wParam == VK_F10) && iF10Key))
2017 ::SendMessageW( GetTopWindow(), WM_SYSCOMMAND, SC_KEYMENU, 0L );
2018 iMenuSysKey = iF10Key = 0;
2019 break;
2020
2021 case WM_SYSCHAR:
2022 {
2023 iMenuSysKey = 0;
2024 if (wParam == VK_RETURN && (getStyle() & WS_MINIMIZE))
2025 {
2026 PostMessageA(getWindowHandle(), WM_SYSCOMMAND,
2027 (WPARAM)SC_RESTORE, 0L );
2028 break;
2029 }
2030 if((HIWORD(lParam) & KEYDATA_ALT) && wParam)
2031 {
2032 if (wParam == VK_TAB || wParam == VK_ESCAPE || wParam == VK_F4)
2033 break;
2034 if (wParam == VK_SPACE && (getStyle() & WS_CHILD)) {
2035 ::SendMessageW(GetParent(), Msg, wParam, lParam );
2036 }
2037 else ::SendMessageA(getWindowHandle(), WM_SYSCOMMAND, (WPARAM)SC_KEYMENU, (LPARAM)(DWORD)wParam );
2038 }
2039#if 0
2040 else /* check for Ctrl-Esc */
2041 if (wParam != VK_ESCAPE) MessageBeep(0);
2042 break;
2043#endif
2044 }
2045
2046 case WM_SETHOTKEY:
2047 hotkey = wParam;
2048 return 1; //CB: always successful
2049
2050 case WM_GETHOTKEY:
2051 return hotkey;
2052
2053 case WM_CONTEXTMENU:
2054 if ((dwStyle & WS_CHILD) && getParent())
2055 SendMessageA(getParent()->getWindowHandle(), WM_CONTEXTMENU,wParam,lParam);
2056 return 0;
2057
2058 case WM_SHOWWINDOW:
2059 if (!lParam) return 0; /* sent from ShowWindow */
2060 if (!(dwStyle & WS_POPUP) || !owner) return 0;
2061 if ((dwStyle & WS_VISIBLE) && wParam) return 0;
2062 else if (!(dwStyle & WS_VISIBLE) && !wParam) return 0;
2063 ShowWindow(wParam ? SW_SHOW:SW_HIDE);
2064 return 0;
2065
2066 case WM_CANCELMODE:
2067 if (getParent() == windowDesktop) EndMenu();
2068 if (GetCapture() == Win32Hwnd) ReleaseCapture();
2069 return 0;
2070
2071 case WM_DROPOBJECT:
2072 return DRAG_FILE;
2073
2074 case WM_QUERYDROPOBJECT:
2075 return (dwExStyle & WS_EX_ACCEPTFILES) ? 1:0;
2076
2077 case WM_QUERYDRAGICON:
2078 {
2079 HICON hDragIcon = windowClass->getCursor();
2080 UINT len;
2081
2082 if(hDragIcon) return (LRESULT)hDragIcon;
2083 for(len = 1; len < 64; len++)
2084 {
2085 hDragIcon = LoadIconA(hInstance,MAKEINTRESOURCEA(len));
2086 if(hDragIcon)
2087 return (LRESULT)hDragIcon;
2088 }
2089 return (LRESULT)LoadIconA(0,IDI_APPLICATIONA);
2090 }
2091
2092 case WM_QUERYOPEN:
2093 case WM_QUERYENDSESSION:
2094 return 1;
2095
2096 case WM_NOTIFYFORMAT:
2097 return IsWindowUnicode() ? NFR_UNICODE:NFR_ANSI;
2098
2099 case WM_SETICON:
2100 case WM_GETICON:
2101 {
2102 LRESULT result = 0;
2103
2104 /* Set the appropriate icon members in the window structure. */
2105 if (wParam == ICON_SMALL)
2106 {
2107 result = hIconSm;
2108 if (Msg == WM_SETICON)
2109 hIconSm = (HICON)lParam;
2110 }
2111 else
2112 {
2113 result = hIcon;
2114 if (Msg == WM_SETICON)
2115 {
2116 hIcon = (HICON)lParam;
2117 if ((dwStyle & WS_CAPTION) == WS_CAPTION)
2118 OSLibWinSetIcon(OS2HwndFrame,hIcon);
2119 }
2120 }
2121 if ((Msg == WM_SETICON) && ((dwStyle & WS_CAPTION) == WS_CAPTION))
2122 HandleNCPaint((HRGN)1);
2123
2124 return result;
2125 }
2126
2127 case WM_HELP:
2128 if (getParent()) SendMessageA(getParent()->getWindowHandle(), Msg,wParam,lParam);
2129 break;
2130
2131 case WM_NOTIFY:
2132 return 0; //comctl32 controls expect this
2133
2134 default:
2135 return 0;
2136 }
2137 return 0;
2138}
2139//******************************************************************************
2140//******************************************************************************
2141LRESULT Win32BaseWindow::DefWindowProcW(UINT Msg, WPARAM wParam, LPARAM lParam)
2142{
2143 switch(Msg)
2144 {
2145 case WM_GETTEXTLENGTH:
2146 return windowNameLength;
2147
2148 case WM_GETTEXT:
2149 if (!lParam || !wParam)
2150 return 0;
2151 if (!windowNameW)
2152 ((LPWSTR)lParam)[0] = 0;
2153 else
2154 memcpy((LPSTR)lParam, windowNameW, min( sizeof(WCHAR) * (windowNameLength+1), wParam) );
2155 return min(windowNameLength, wParam);
2156
2157 case WM_SETTEXT:
2158 {
2159 LPWSTR lpsz = (LPWSTR)lParam;
2160
2161 // reallocate if new buffer is larger
2162 if (!lParam)
2163 {
2164 free(windowNameA);
2165 free(windowNameW);
2166 windowNameLength = 0;
2167 windowNameA = NULL;
2168 windowNameW = NULL;
2169 }
2170 else
2171 {
2172 // determine length of new text
2173 int iTextLength = lstrlenW(lpsz);
2174
2175 if (windowNameLength < iTextLength)
2176 {
2177 if (windowNameA)
2178 {
2179 free(windowNameA);
2180 windowNameA = NULL;
2181 }
2182
2183 if (windowNameW)
2184 {
2185 free(windowNameW);
2186 windowNameW = NULL;
2187 }
2188 }
2189
2190 windowNameLength = iTextLength;
2191 if(!windowNameW)
2192 windowNameW = (LPWSTR)_smalloc((windowNameLength+1)*sizeof(WCHAR));
2193 memcpy(windowNameW, lpsz, (windowNameLength+1) * sizeof(WCHAR));
2194 if(!windowNameA)
2195 windowNameA = (LPSTR)_smalloc(windowNameLength+1);
2196 lstrcpynWtoA(windowNameA, windowNameW, windowNameLength+1);
2197 }
2198
2199 dprintf(("WM_SETTEXT of %x\n",Win32Hwnd));
2200 if ((dwStyle & WS_CAPTION) == WS_CAPTION)
2201 {
2202 HandleNCPaint((HRGN)1);
2203 if(hTaskList) {
2204 OSLibWinChangeTaskList(hTaskList, OS2HwndFrame, getWindowNameA(), (getStyle() & WS_VISIBLE) ? 1 : 0);
2205 }
2206 if(fOS2Look) {
2207 OSLibWinSetTitleBarText(OS2HwndFrame, getWindowNameA());
2208 }
2209 }
2210
2211 return TRUE;
2212 }
2213
2214 default:
2215 return DefWindowProcA(Msg, wParam, lParam);
2216 }
2217}
2218//******************************************************************************
2219//******************************************************************************
2220void Win32BaseWindow::NotifyParent(UINT Msg, WPARAM wParam, LPARAM lParam)
2221{
2222 Win32BaseWindow *window = this;
2223 Win32BaseWindow *parentwindow;
2224
2225 while(window)
2226 {
2227 if(window->getStyle() & WS_CHILD && !(window->getExStyle() & WS_EX_NOPARENTNOTIFY) )
2228 {
2229 /* Notify the parent window only */
2230 parentwindow = window->getParent();
2231 if(parentwindow) {
2232 SendMessageA(parentwindow->getWindowHandle(), WM_PARENTNOTIFY, MAKEWPARAM(Msg, getWindowId()), lParam );
2233 }
2234 }
2235 else break;
2236
2237 window = parentwindow;
2238 }
2239}
2240//******************************************************************************
2241// Returns the big or small icon for the window, falling back to the
2242// class as windows does.
2243//******************************************************************************
2244HICON Win32BaseWindow::IconForWindow(WPARAM fType)
2245{
2246 HICON hWndIcon;
2247
2248 if (fType == ICON_BIG)
2249 {
2250 if (hIcon)
2251 hWndIcon = hIcon;
2252 else
2253 if (windowClass && windowClass->getIcon())
2254 hWndIcon = windowClass->getIcon();
2255 else
2256 if (!(dwStyle & DS_MODALFRAME))
2257 hWndIcon = LoadImageA(0,MAKEINTRESOURCEA(OIC_ODINICON),IMAGE_ICON,0,0,LR_DEFAULTCOLOR);
2258 else hWndIcon = 0;
2259 }
2260 else
2261 {
2262 if (hIconSm)
2263 hWndIcon = hIconSm;
2264 else
2265 if (hIcon)
2266 hWndIcon = hIcon;
2267 else
2268 if (windowClass && windowClass->getIconSm())
2269 hWndIcon = windowClass->getIconSm();
2270 else
2271 if (windowClass && windowClass->getIcon())
2272 hWndIcon = windowClass->getIcon();
2273 else
2274 if (!(dwStyle & DS_MODALFRAME))
2275 hWndIcon = LoadImageA(0,MAKEINTRESOURCEA(OIC_ODINICON),IMAGE_ICON,0,0,LR_DEFAULTCOLOR);
2276 else hWndIcon = 0;
2277 }
2278
2279 return hWndIcon;
2280}
2281//******************************************************************************
2282//******************************************************************************
2283BOOL Win32BaseWindow::ShowWindow(ULONG nCmdShow)
2284{
2285 ULONG swp = 0;
2286 HWND hWinAfter;
2287 BOOL rc,wasVisible,showFlag;
2288 RECT newPos = {0, 0, 0, 0};
2289
2290 dprintf(("ShowWindow %x %x", getWindowHandle(), nCmdShow));
2291 wasVisible = (getStyle() & WS_VISIBLE) != 0;
2292
2293 dwOldStyle = getStyle();
2294
2295 switch(nCmdShow)
2296 {
2297 case SW_HIDE:
2298 if (!wasVisible) goto END;
2299
2300 swp |= SWP_HIDEWINDOW | SWP_NOSIZE | SWP_NOMOVE | SWP_NOACTIVATE | SWP_NOZORDER;
2301 break;
2302
2303 case SW_SHOWMINNOACTIVE:
2304 swp |= SWP_NOACTIVATE | SWP_NOZORDER;
2305 /* fall through */
2306 case SW_SHOWMINIMIZED:
2307 swp |= SWP_SHOWWINDOW;
2308 /* fall through */
2309 case SW_MINIMIZE:
2310 swp |= SWP_FRAMECHANGED;
2311 if( !(getStyle() & WS_MINIMIZE) ) {
2312 swp |= MinMaximize(SW_MINIMIZE, &newPos );
2313 fMinMaxChange = TRUE; //-> invalidate entire window in WM_CALCINVALIDRECT
2314 }
2315 else swp |= SWP_NOSIZE | SWP_NOMOVE;
2316 break;
2317
2318 case SW_SHOWMAXIMIZED: /* same as SW_MAXIMIZE */
2319 swp |= SWP_SHOWWINDOW | SWP_FRAMECHANGED;
2320 if( !(getStyle() & WS_MAXIMIZE) ) {
2321 swp |= MinMaximize(SW_MAXIMIZE, &newPos );
2322 fMinMaxChange = TRUE; //-> invalidate entire window in WM_CALCINVALIDRECT
2323 }
2324 else swp |= SWP_NOSIZE | SWP_NOMOVE;
2325 break;
2326
2327 case SW_SHOWNA:
2328 swp |= SWP_NOACTIVATE | SWP_NOZORDER;
2329 /* fall through */
2330 case SW_SHOW:
2331 swp |= SWP_SHOWWINDOW | SWP_NOSIZE | SWP_NOMOVE;
2332
2333 /*
2334 * ShowWindow has a little peculiar behavior that if the
2335 * window is already the topmost window, it will not
2336 * activate it.
2337 */
2338 if (::GetTopWindow((HWND)0)==getWindowHandle() && (wasVisible || GetActiveWindow() == getWindowHandle()))
2339 swp |= SWP_NOACTIVATE;
2340
2341 break;
2342
2343 case SW_SHOWNOACTIVATE:
2344 swp |= SWP_NOZORDER;
2345 if (GetActiveWindow())
2346 swp |= SWP_NOACTIVATE;
2347 /* fall through */
2348 case SW_SHOWNORMAL: /* same as SW_NORMAL: */
2349 case SW_SHOWDEFAULT: /* FIXME: should have its own handler */
2350 case SW_RESTORE:
2351 dprintf(("ShowWindow:restoring window"));
2352
2353 swp |= SWP_SHOWWINDOW | SWP_FRAMECHANGED;
2354 if( getStyle() & (WS_MINIMIZE | WS_MAXIMIZE) ) {
2355 swp |= MinMaximize(SW_RESTORE, &newPos );
2356 fMinMaxChange = TRUE; //-> invalidate entire window in WM_CALCINVALIDRECT
2357 }
2358 else swp |= SWP_NOSIZE | SWP_NOMOVE;
2359 break;
2360 }
2361
2362 showFlag = (nCmdShow != SW_HIDE);
2363 if (showFlag != wasVisible)
2364 {
2365 SendMessageA(getWindowHandle(),WM_SHOWWINDOW, showFlag, 0 );
2366 if (!::IsWindow( getWindowHandle() )) goto END;
2367 }
2368
2369 /* We can't activate a child window */
2370 if((getStyle() & WS_CHILD) && !(getExStyle() & WS_EX_MDICHILD))
2371 swp |= SWP_NOACTIVATE | SWP_NOZORDER;
2372
2373 dprintf(("ShowWindow : SetWindowPos now"));
2374 if (!(getStyle() & WS_MINIMIZE)) {
2375 SetWindowPos(HWND_TOP, newPos.left, newPos.top, newPos.right, newPos.bottom, LOWORD(swp));
2376 }
2377 else OSLibWinMinimizeWindow(getOS2FrameWindowHandle());
2378
2379 if(!(swp & SWP_NOACTIVATE) && (!(getStyle() & WS_MINIMIZE))) {
2380 OSLibWinSetActiveWindow(OS2HwndFrame);
2381 }
2382
2383 if (flags & WIN_NEED_SIZE)
2384 {
2385 /* should happen only in CreateWindowEx() */
2386 int wParam = SIZE_RESTORED;
2387
2388 flags &= ~WIN_NEED_SIZE;
2389 if (dwStyle & WS_MAXIMIZE)
2390 wParam = SIZE_MAXIMIZED;
2391 else
2392 if (dwStyle & WS_MINIMIZE)
2393 wParam = SIZE_MINIMIZED;
2394
2395 SendMessageA(getWindowHandle(),WM_SIZE, wParam,
2396 MAKELONG(rectClient.right-rectClient.left,
2397 rectClient.bottom-rectClient.top));
2398 SendMessageA(getWindowHandle(),WM_MOVE,0,MAKELONG(rectClient.left,rectClient.top));
2399 }
2400//testestest
2401 //temporary workaround for file dialogs with template dialog child
2402 //they don't redraw when switching directories
2403 //For some reason the new child's (syslistview32) update rectangle stays
2404 //empty after its parent is made visible with ShowWindow
2405 //TODO: find real cause
2406 if(!wasVisible) {
2407 InvalidateRect(getWindowHandle(), NULL, TRUE);
2408 }
2409//testestest
2410END:
2411 fMinMaxChange = FALSE;
2412 return wasVisible;
2413}
2414//******************************************************************************
2415//******************************************************************************
2416BOOL Win32BaseWindow::SetWindowPos(HWND hwndInsertAfter, int x, int y, int cx, int cy, UINT fuFlags)
2417{
2418 BOOL rc = FALSE;
2419 Win32BaseWindow *window;
2420 HWND hParent = 0;
2421 RECT oldClientRect = rectClient;
2422
2423 if (fuFlags &
2424 ~(SWP_NOSIZE | SWP_NOMOVE | SWP_NOZORDER |
2425 SWP_NOREDRAW | SWP_NOACTIVATE | SWP_FRAMECHANGED |
2426 SWP_SHOWWINDOW | SWP_HIDEWINDOW | SWP_NOCOPYBITS |
2427 SWP_NOOWNERZORDER | SWP_NOSENDCHANGING | SWP_DEFERERASE |
2428 SWP_NOCLIENTSIZE | SWP_NOCLIENTMOVE))
2429 {
2430 dprintf(("ERROR: SetWindowPos; UNKNOWN flag"));
2431 return FALSE;
2432 }
2433
2434 if( fuFlags & (SWP_DEFERERASE | SWP_NOCLIENTSIZE | SWP_NOCLIENTMOVE)) {
2435 dprintf(("WARNING: SetWindowPos; unsupported flag"));
2436 }
2437
2438 if(IsWindowDestroyed()) {
2439 //changing the position of a window that's being destroyed can cause crashes in PMMERGE
2440 dprintf(("SetWindowPos; window already destroyed"));
2441 return TRUE;
2442 }
2443
2444#if 0
2445 /* Fix redundant flags */
2446 if(getStyle() & WS_VISIBLE) {
2447 fuFlags &= ~SWP_SHOWWINDOW;
2448 }
2449 else
2450 {
2451 if (!(fuFlags & SWP_SHOWWINDOW))
2452 fuFlags |= SWP_NOREDRAW;
2453 fuFlags &= ~SWP_HIDEWINDOW;
2454 }
2455
2456//// if(cx < 0) cx = 0;
2457//// if(cy < 0) cy = 0;
2458
2459 if((rectWindow.right - rectWindow.left == cx) && (rectWindow.bottom - rectWindow.top == cy)) {
2460 fuFlags |= SWP_NOSIZE; /* Already the right size */
2461 }
2462
2463 if((rectWindow.left == x) && (rectWindow.top == y)) {
2464 fuFlags |= SWP_NOMOVE; /* Already the right position */
2465 }
2466
2467 if(getWindowHandle() == GetActiveWindow()) {
2468 fuFlags |= SWP_NOACTIVATE; /* Already active */
2469 }
2470 else
2471 if((getStyle() & (WS_POPUP | WS_CHILD)) != WS_CHILD )
2472 {
2473 if(!(fuFlags & SWP_NOACTIVATE)) /* Bring to the top when activating */
2474 {
2475 fuFlags &= ~SWP_NOZORDER;
2476 hwndInsertAfter = HWND_TOP;
2477 }
2478 }
2479 /* TODO: Check hwndInsertAfter */
2480
2481#endif
2482
2483 //Note: Solitaire crashes when receiving WM_SIZE messages before WM_CREATE
2484 if(state < STATE_POST_WMNCCREATE)
2485 {//don't change size; modify internal structures only
2486 //TODO: not 100% correct yet (activate)
2487 dprintf2(("state < STATE_POST_WMNCCREATE"));
2488 if(!(fuFlags & SWP_NOZORDER)) {
2489 hwndLinkAfter = hwndInsertAfter;
2490 }
2491 if(!(fuFlags & SWP_NOMOVE)) {
2492 rectWindow.bottom = (rectWindow.bottom - rectWindow.top) + y;
2493 rectWindow.top = y;
2494 rectWindow.right = (rectWindow.right - rectWindow.left) + x;
2495 rectWindow.left = x;
2496 }
2497 if(!(fuFlags & SWP_NOSIZE)) {
2498 rectWindow.bottom = rectWindow.top + cy;
2499 rectWindow.right = rectWindow.left + cx;
2500 }
2501 return TRUE;
2502 }
2503
2504 WINDOWPOS wpos;
2505 SWP swp, swpOld;
2506 wpos.flags = fuFlags;
2507 wpos.cy = cy;
2508 wpos.cx = cx;
2509 wpos.x = x;
2510 wpos.y = y;
2511 wpos.hwndInsertAfter = hwndInsertAfter;
2512 wpos.hwnd = getWindowHandle();
2513
2514 if(~fuFlags & (SWP_NOMOVE | SWP_NOSIZE))
2515 {
2516 if (isChild())
2517 {
2518 if(!getParent()) {
2519 dprintf(("WARNING: Win32BaseWindow::SetWindowPos window %x is child but has no parent!!", getWindowHandle()));
2520 }
2521 }
2522 OSLibWinQueryWindowPos(OS2HwndFrame, &swpOld);
2523 }
2524
2525 if(getParent()) {
2526 OSLibMapWINDOWPOStoSWP(&wpos, &swp, &swpOld, getParent()->getClientHeight(),
2527 OS2HwndFrame);
2528 }
2529 else OSLibMapWINDOWPOStoSWP(&wpos, &swp, &swpOld, OSLibQueryScreenHeight(), OS2HwndFrame);
2530
2531 if (swp.fl == 0) {
2532 dprintf2(("swp.fl == 0"));
2533 if(fuFlags & SWP_FRAMECHANGED)
2534 {
2535 NotifyFrameChanged(&wpos, &oldClientRect);
2536 }
2537 return TRUE;
2538 }
2539
2540// if ((swp.fl & SWPOS_ZORDER) && (swp.hwndInsertBehind > HWNDOS_BOTTOM))
2541 if ((swp.hwndInsertBehind > HWNDOS_BOTTOM))
2542 {
2543 Win32BaseWindow *wndBehind = Win32BaseWindow::GetWindowFromHandle(swp.hwndInsertBehind);
2544 if(wndBehind) {
2545 swp.hwndInsertBehind = wndBehind->getOS2FrameWindowHandle();
2546 RELEASE_WNDOBJ(wndBehind);
2547 }
2548 else {
2549 dprintf(("ERROR: SetWindowPos: hwndInsertBehind %x invalid!",swp.hwndInsertBehind));
2550 swp.hwndInsertBehind = 0;
2551 }
2552 }
2553 swp.hwnd = OS2HwndFrame;
2554
2555 if(fuFlags & SWP_SHOWWINDOW && !IsWindowVisible(getWindowHandle())) {
2556 setStyle(getStyle() | WS_VISIBLE);
2557 if(hTaskList) {
2558 dprintf(("Adding window %x to tasklist", getWindowHandle()));
2559 OSLibWinChangeTaskList(hTaskList, OS2HwndFrame, getWindowNameA(), 1);
2560 }
2561 }
2562 else
2563 if((fuFlags & SWP_HIDEWINDOW) && IsWindowVisible(getWindowHandle())) {
2564 setStyle(getStyle() & ~WS_VISIBLE);
2565 if(hTaskList && !(getStyle() & WS_MINIMIZE)) {
2566 dprintf(("Removing window %x from tasklist", getWindowHandle()));
2567 OSLibWinChangeTaskList(hTaskList, OS2HwndFrame, getWindowNameA(), 0);
2568 }
2569 }
2570 dprintf (("WinSetWindowPos %x %x (%d,%d)(%d,%d) %x", swp.hwnd, swp.hwndInsertBehind, swp.x, swp.y, swp.cx, swp.cy, swp.fl));
2571 rc = OSLibWinSetMultWindowPos(&swp, 1);
2572
2573 if(rc == FALSE)
2574 {
2575 dprintf(("OSLibWinSetMultWindowPos failed! Error %x",OSLibWinGetLastError()));
2576 return 0;
2577 }
2578
2579 if((fuFlags & SWP_FRAMECHANGED) && (fuFlags & (SWP_NOMOVE | SWP_NOSIZE) == (SWP_NOMOVE | SWP_NOSIZE)))
2580 {
2581 NotifyFrameChanged(&wpos, &oldClientRect);
2582 }
2583 if(!(getStyle() & (WS_MAXIMIZE|WS_MINIMIZE))) {
2584 //Restore position always changes when the window position is changed
2585 dprintf(("Save new restore position (%d,%d)(%d,%d)", rectWindow.left, rectWindow.top, rectWindow.right, rectWindow.bottom));
2586 windowpos.rcNormalPosition = rectWindow;
2587 }
2588 return (rc);
2589}
2590//******************************************************************************
2591//Called by ScrollWindowEx (dc.cpp) to notify child window that it has moved
2592//******************************************************************************
2593BOOL Win32BaseWindow::ScrollWindow(int dx, int dy)
2594{
2595 rectWindow.left += dx;
2596 rectWindow.right += dx;
2597 rectWindow.top += dy;
2598 rectWindow.bottom += dy;
2599 SendMessageA(getWindowHandle(),WM_MOVE, 0, MAKELONG(rectClient.left, rectClient.top));
2600 return TRUE;
2601}
2602//******************************************************************************
2603//******************************************************************************
2604void Win32BaseWindow::NotifyFrameChanged(WINDOWPOS *wpos, RECT *oldClientRect)
2605{
2606 HRGN hrgn, hrgnClient;
2607 RECT rect;
2608
2609 MsgFormatFrame(NULL);
2610
2611 if(RECT_WIDTH(rectClient) != RECT_WIDTH(*oldClientRect) ||
2612 RECT_HEIGHT(rectClient) != RECT_HEIGHT(*oldClientRect))
2613 {
2614 wpos->flags &= ~(SWP_NOSIZE|SWP_NOCLIENTSIZE);
2615 wpos->cx = RECT_WIDTH(rectWindow);
2616 wpos->cy = RECT_HEIGHT(rectWindow);
2617 }
2618
2619 if(rectClient.left != oldClientRect->left ||
2620 rectClient.top != oldClientRect->top)
2621 {
2622 wpos->flags &= ~(SWP_NOMOVE|SWP_NOCLIENTMOVE);
2623 wpos->x = rectWindow.left;
2624 wpos->y = rectWindow.top;
2625 }
2626
2627 WINDOWPOS wpOld = *wpos;
2628 if(!(wpos->flags & SWP_NOSENDCHANGING))
2629 SendMessageA(getWindowHandle(),WM_WINDOWPOSCHANGING, 0, (LPARAM)wpos);
2630
2631 if ((wpos->hwndInsertAfter != wpOld.hwndInsertAfter) ||
2632 (wpos->x != wpOld.x) || (wpos->y != wpOld.y) || (wpos->cx != wpOld.cx) || (wpos->cy != wpOld.cy) || (wpos->flags != wpOld.flags))
2633 {
2634 dprintf(("WARNING, NotifyFrameChanged: TODO -> adjust flags!!!!"));
2635 SetWindowPos(wpos->hwndInsertAfter, wpos->x, wpos->y, wpos->cx, wpos->cy, wpos->flags | SWP_NOSENDCHANGING);
2636 }
2637 else SendMessageA(getWindowHandle(),WM_WINDOWPOSCHANGED, 0, (LPARAM)wpos);
2638
2639 //Calculate invalid areas
2640 rect = rectWindow;
2641 OffsetRect(&rect, -rectWindow.left, -rectWindow.top);
2642 hrgn = CreateRectRgnIndirect(&rect);
2643 if (!hrgn) {
2644 dprintf(("ERROR: NotifyFrameChanged, CreateRectRgnIndirect failed!!"));
2645 return;
2646 }
2647 rect = rectClient;
2648 hrgnClient = CreateRectRgnIndirect(&rect);
2649 if (!hrgn) {
2650 dprintf(("ERROR: NotifyFrameChanged, CreateRectRgnIndirect failed!!"));
2651 return;
2652 }
2653 CombineRgn(hrgn, hrgn, hrgnClient, RGN_DIFF);
2654 DeleteObject(hrgnClient);
2655
2656 if(!EqualRect(oldClientRect, &rectClient)) {
2657 UnionRect(oldClientRect, oldClientRect, &rectClient);
2658 hrgnClient = CreateRectRgnIndirect(oldClientRect);
2659 if (!hrgn) {
2660 dprintf(("ERROR: NotifyFrameChanged, CreateRectRgnIndirect failed!!"));
2661 return;
2662 }
2663 CombineRgn(hrgn, hrgn, hrgnClient, RGN_OR);
2664 DeleteObject(hrgnClient);
2665 }
2666 RedrawWindow(getWindowHandle(), NULL, hrgn, RDW_ALLCHILDREN |
2667 RDW_INVALIDATE | RDW_ERASE | RDW_FRAME);
2668 DeleteObject(hrgn);
2669}
2670//******************************************************************************
2671//TODO: Check how this api really works in NT
2672//******************************************************************************
2673BOOL Win32BaseWindow::SetWindowPlacement(WINDOWPLACEMENT *wndpl)
2674{
2675 dprintf(("SetWindowPlacement %x min (%d,%d)", getWindowHandle(), wndpl->ptMinPosition.x, wndpl->ptMinPosition.y));
2676 dprintf(("SetWindowPlacement %x max (%d,%d)", getWindowHandle(), wndpl->ptMaxPosition.x, wndpl->ptMaxPosition.y));
2677 dprintf(("SetWindowPlacement %x norm (%d,%d)(%d,%d)", getWindowHandle(), wndpl->rcNormalPosition.left, wndpl->rcNormalPosition.top, wndpl->rcNormalPosition.right, wndpl->rcNormalPosition.bottom));
2678 windowpos.ptMinPosition = wndpl->ptMinPosition;
2679 windowpos.ptMaxPosition = wndpl->ptMaxPosition;
2680 windowpos.rcNormalPosition = wndpl->rcNormalPosition;
2681
2682 if(getStyle() & WS_MINIMIZE )
2683 {
2684 //TODO: Why can't this be (0,0)?
2685 if(wndpl->flags & WPF_SETMINPOSITION && !(!windowpos.ptMinPosition.x && !windowpos.ptMinPosition.y)) {
2686 SetWindowPos(0, windowpos.ptMinPosition.x, windowpos.ptMinPosition.y,
2687 0, 0, SWP_NOSIZE | SWP_NOZORDER | SWP_NOACTIVATE);
2688 }
2689 }
2690 else
2691 if(getStyle() & WS_MAXIMIZE )
2692 {
2693 //TODO: Why can't this be (0,0)?
2694 if(windowpos.ptMaxPosition.x != 0 || windowpos.ptMaxPosition.y != 0 )
2695 SetWindowPos(0, windowpos.ptMaxPosition.x, windowpos.ptMaxPosition.y,
2696 0, 0, SWP_NOSIZE | SWP_NOZORDER | SWP_NOACTIVATE);
2697 }
2698 else {
2699 SetWindowPos(0, windowpos.rcNormalPosition.left, windowpos.rcNormalPosition.top,
2700 windowpos.rcNormalPosition.right - windowpos.rcNormalPosition.left,
2701 windowpos.rcNormalPosition.bottom - windowpos.rcNormalPosition.top,
2702 SWP_NOZORDER | SWP_NOACTIVATE );
2703 }
2704 ShowWindow(wndpl->showCmd);
2705 if( ::IsWindow(getWindowHandle()) && getStyle() & WS_MINIMIZE )
2706 {
2707 /* SDK: ...valid only the next time... */
2708 if(wndpl->flags & WPF_RESTORETOMAXIMIZED)
2709 setFlags(getFlags() | WIN_RESTORE_MAX);
2710 }
2711 return TRUE;
2712}
2713//******************************************************************************
2714//******************************************************************************
2715BOOL Win32BaseWindow::GetWindowPlacement(LPWINDOWPLACEMENT wndpl)
2716{
2717 wndpl->length = sizeof(*wndpl);
2718 if(getStyle() & WS_MINIMIZE )
2719 wndpl->showCmd = SW_SHOWMINIMIZED;
2720 else wndpl->showCmd = (getStyle() & WS_MAXIMIZE) ? SW_SHOWMAXIMIZED : SW_SHOWNORMAL;
2721
2722 //TODO: Verify if this is correct -> SDK docs claim this flag must always be set to 0
2723 if(getFlags() & WIN_RESTORE_MAX )
2724 wndpl->flags = WPF_RESTORETOMAXIMIZED;
2725 else wndpl->flags = 0;
2726
2727 wndpl->ptMinPosition = windowpos.ptMinPosition;
2728 wndpl->ptMaxPosition = windowpos.ptMaxPosition;
2729 //Must be in parent coordinates (or screen if no parent); verified in NT4, SP6
2730 wndpl->rcNormalPosition = windowpos.rcNormalPosition;
2731
2732 return TRUE;
2733}
2734//******************************************************************************
2735//Also destroys all the child windows (destroy children first, parent last)
2736//******************************************************************************
2737BOOL Win32BaseWindow::DestroyWindow()
2738{
2739 HWND hwnd = getWindowHandle();
2740
2741 dprintf(("DestroyWindow %x", hwnd));
2742
2743 /* Call hooks */
2744 if(HOOK_CallHooksA( WH_CBT, HCBT_DESTROYWND, getWindowHandle(), 0L))
2745 {
2746 return FALSE;
2747 }
2748
2749 if(!(getStyle() & WS_CHILD) && getOwner() == NULL)
2750 {
2751 HOOK_CallHooksA(WH_SHELL, HSHELL_WINDOWDESTROYED, getWindowHandle(), 0L);
2752 /* FIXME: clean up palette - see "Internals" p.352 */
2753 }
2754
2755 if((getStyle() & WS_CHILD) && !(getExStyle() & WS_EX_NOPARENTNOTIFY))
2756 {
2757 if(getParent() && getParent()->IsWindowDestroyed() == FALSE)
2758 {
2759 /* Notify the parent window only */
2760 SendMessageA(getParent()->getWindowHandle(), WM_PARENTNOTIFY, MAKEWPARAM(WM_DESTROY, getWindowId()), (LPARAM)getWindowHandle());
2761 if(!::IsWindow(hwnd) )
2762 {
2763 return TRUE;
2764 }
2765 }
2766//// else DebugInt3();
2767 }
2768 /* Hide the window */
2769 if(IsWindowVisible(getWindowHandle()))
2770 {
2771 SetWindowPos(0, 0, 0, 0, 0, SWP_HIDEWINDOW |
2772 SWP_NOACTIVATE|SWP_NOZORDER|SWP_NOMOVE|SWP_NOSIZE);
2773 if(!::IsWindow(hwnd))
2774 {
2775 return TRUE;
2776 }
2777 }
2778 dprintf(("DestroyWindow %x -> HIDDEN", hwnd));
2779
2780 // check the handle for the last active popup window
2781 Win32BaseWindow* owner = getOwner();
2782 if (NULL != owner)
2783 {
2784 if (owner->getLastActive() == hwnd)
2785 owner->setLastActive( owner->getWindowHandle() );
2786 }
2787
2788 fDestroyWindowCalled = TRUE;
2789 return OSLibWinDestroyWindow(OS2HwndFrame);
2790}
2791//******************************************************************************
2792//******************************************************************************
2793Win32BaseWindow *Win32BaseWindow::getParent()
2794{
2795 Win32BaseWindow *wndparent = (Win32BaseWindow *)ChildWindow::getParentOfChild();
2796 //experiment
2797#if 0
2798 return ((ULONG)wndparent == (ULONG)windowDesktop) ? NULL : wndparent;
2799#else
2800 return wndparent;
2801#endif
2802}
2803//******************************************************************************
2804//Note: does not set last error if no parent (verified in NT4, SP6)
2805//******************************************************************************
2806HWND Win32BaseWindow::GetParent()
2807{
2808 Win32BaseWindow *wndparent = (Win32BaseWindow *)ChildWindow::getParentOfChild();
2809
2810 if(getStyle() & WS_CHILD)
2811 {
2812 if(wndparent) {
2813 return wndparent->getWindowHandle();
2814 }
2815 dprintf(("WARNING: GetParent: WS_CHILD but no parent!!"));
2816 DebugInt3();
2817 return 0;
2818 }
2819 else
2820 if(getStyle() & WS_POPUP)
2821 return (getOwner()) ? getOwner()->getWindowHandle() : 0;
2822 else return 0;
2823}
2824//******************************************************************************
2825//******************************************************************************
2826HWND Win32BaseWindow::SetParent(HWND hwndNewParent)
2827{
2828 HWND oldhwnd;
2829 Win32BaseWindow *newparent;
2830 Win32BaseWindow *oldparent = (Win32BaseWindow *)ChildWindow::getParentOfChild();
2831 BOOL fShow = FALSE;
2832
2833 if(oldparent) {
2834 oldhwnd = oldparent->getWindowHandle();
2835 oldparent->removeChild(this);
2836 }
2837 else oldhwnd = 0;
2838
2839 /* Windows hides the window first, then shows it again
2840 * including the WM_SHOWWINDOW messages and all */
2841 if(IsWindowCreated() && (getStyle() & WS_VISIBLE)) {
2842 ShowWindow(SW_HIDE);
2843 fShow = TRUE;
2844 }
2845 if(oldparent) {
2846 //release parent here (increased refcount during creation)
2847 RELEASE_WNDOBJ(oldparent);
2848 }
2849 newparent = GetWindowFromHandle(hwndNewParent);
2850 if(newparent && !newparent->isDesktopWindow())
2851 {
2852 setParent(newparent);
2853 getParent()->addChild(this);
2854 fParentChange = TRUE;
2855
2856 OSLibWinSetParent(getOS2FrameWindowHandle(), getParent()->getOS2WindowHandle());
2857 if(!(getStyle() & WS_CHILD))
2858 {
2859 if(getWindowId())
2860 {
2861 DestroyMenu( (HMENU) getWindowId() );
2862 setWindowId(0);
2863 }
2864 }
2865 //SvL: Even though the win32 coordinates might not change, the PM
2866 // coordinates can. We must make sure the control stays at the
2867 // same position (y) relative to the (new) parent.
2868 SetWindowPos(HWND_TOPMOST, rectWindow.left, rectWindow.top, 0, 0,
2869 SWP_NOACTIVATE|SWP_NOSIZE);
2870 fParentChange = FALSE;
2871 }
2872 else {
2873 if(newparent) RELEASE_WNDOBJ(newparent);
2874
2875 setParent(windowDesktop);
2876 windowDesktop->addRef();
2877 windowDesktop->addChild(this);
2878 OSLibWinSetParent(getOS2FrameWindowHandle(), OSLIB_HWND_DESKTOP);
2879
2880 setWindowId(0);
2881 }
2882 /* SetParent additionally needs to make hwndChild the topmost window
2883 in the x-order and send the expected WM_WINDOWPOSCHANGING and
2884 WM_WINDOWPOSCHANGED notification messages.
2885 */
2886 if(state >= STATE_PRE_WMNCCREATE) {
2887 SetWindowPos(HWND_TOPMOST, 0, 0, 0, 0,
2888 SWP_NOACTIVATE|SWP_NOMOVE|SWP_NOSIZE|(fShow? SWP_SHOWWINDOW : 0));
2889
2890 /* FIXME: a WM_MOVE is also generated (in the DefWindowProc handler
2891 * for WM_WINDOWPOSCHANGED) in Windows, should probably remove SWP_NOMOVE */
2892 }
2893 return oldhwnd;
2894}
2895//******************************************************************************
2896//******************************************************************************
2897BOOL Win32BaseWindow::IsChild(HWND hwndParent)
2898{
2899 // PH: Optimizer won't unroll calls to getParent() even
2900 // in release build.
2901 Win32BaseWindow *_parent = getParent();
2902
2903 if(_parent)
2904 {
2905 if(_parent->getWindowHandle() == hwndParent)
2906 return TRUE;
2907
2908 return _parent->IsChild(hwndParent);
2909 }
2910 else
2911 return 0;
2912}
2913//******************************************************************************
2914//******************************************************************************
2915HWND Win32BaseWindow::GetTopWindow()
2916{
2917 HWND hwndTop;
2918 Win32BaseWindow *topwindow;
2919
2920 hwndTop = OSLibWinQueryWindow(getOS2WindowHandle(), QWOS_TOP);
2921 if(!isDesktopWindow())
2922 {
2923 topwindow = GetWindowFromOS2FrameHandle(hwndTop);
2924 //Note: GetTopWindow can't return a window that hasn't processed
2925 // WM_NCCREATE yet (verified in NT4, SP6)
2926 if(topwindow) {
2927 if(topwindow->state >= STATE_POST_WMNCCREATE) {
2928 hwndTop = topwindow->getWindowHandle();
2929 }
2930 else hwndTop = topwindow->GetWindow(GW_HWNDNEXT);
2931 RELEASE_WNDOBJ(topwindow);
2932 return hwndTop;
2933 }
2934 if(topwindow) RELEASE_WNDOBJ(topwindow);
2935 return 0;
2936 }
2937 while(hwndTop) {
2938 topwindow = GetWindowFromOS2FrameHandle(hwndTop);
2939 //Note: GetTopWindow can't return a window that hasn't processed
2940 // WM_NCCREATE yet (verified in NT4, SP6)
2941 if(topwindow) {
2942 if(topwindow->state >= STATE_POST_WMNCCREATE) {
2943 hwndTop = topwindow->getWindowHandle();
2944 }
2945 else hwndTop = topwindow->GetWindow(GW_HWNDNEXT);
2946 RELEASE_WNDOBJ(topwindow);
2947 return hwndTop;
2948 }
2949 if(topwindow) RELEASE_WNDOBJ(topwindow);
2950 hwndTop = OSLibWinQueryWindow(hwndTop, QWOS_NEXT);
2951 }
2952
2953 return 0;
2954}
2955//******************************************************************************
2956// Get the top-level parent for a child window.
2957//******************************************************************************
2958HWND Win32BaseWindow::GetTopParent()
2959{
2960 Win32BaseWindow *window = this;
2961 HWND hwndTopParent = 0;
2962
2963 lock();
2964 while(window && (window->getStyle() & WS_CHILD))
2965 {
2966 window = window->getParent();
2967 }
2968 if(window) {
2969 hwndTopParent = window->getWindowHandle();
2970 }
2971 unlock();
2972 return hwndTopParent;
2973}
2974//******************************************************************************
2975//TODO: Should not enumerate children that are created during the enumeration!
2976//TODO: Do this more efficiently
2977//******************************************************************************
2978BOOL Win32BaseWindow::EnumChildWindows(WNDENUMPROC lpfn, LPARAM lParam)
2979{
2980 BOOL rc = TRUE;
2981 HWND hwnd;
2982 Win32BaseWindow *prevchild = 0, *child = 0;
2983
2984 dprintf(("EnumChildWindows of %x parameter %x %x (%x)", getWindowHandle(), lpfn, lParam, getFirstChild()));
2985 lock();
2986 for (child = (Win32BaseWindow *)getFirstChild(); child != NULL; child = (Win32BaseWindow *)child->getNextChild())
2987 {
2988 dprintf(("EnumChildWindows: enumerating child %x (owner %x; parent %x)", child->getWindowHandle(), (child->getOwner()) ? child->getOwner()->getWindowHandle() : 0, getWindowHandle()));
2989 hwnd = child->getWindowHandle();
2990 if(child->IsWindowDestroyed() || child->getOwner()) {
2991 continue; //shouldn't have an owner (Wine)
2992 }
2993 child->addRef();
2994 unlock();
2995 if(lpfn(hwnd, lParam) == FALSE)
2996 {
2997 child->release();
2998 return FALSE;
2999 }
3000 child->release();
3001 lock();
3002 //check if the window still exists
3003 if(!::IsWindow(hwnd))
3004 {
3005 child = prevchild;
3006 if(child == NULL) break;
3007 continue;
3008 }
3009 if(child->getFirstChild() != NULL)
3010 {
3011 dprintf(("EnumChildWindows: Enumerate children of %x", child->getWindowHandle()));
3012 child->addRef();
3013 unlock();
3014 if(child->EnumChildWindows(lpfn, lParam) == FALSE)
3015 {
3016 child->release();
3017 return FALSE;
3018 }
3019 child->release();
3020 lock();
3021 }
3022 prevchild = child;
3023 }
3024 unlock();
3025 return rc;
3026}
3027//******************************************************************************
3028//Enumerate first-level children only and check thread id
3029//******************************************************************************
3030BOOL Win32BaseWindow::EnumThreadWindows(DWORD dwThreadId, WNDENUMPROC lpfn, LPARAM lParam)
3031{
3032 Win32BaseWindow *child = 0;
3033 ULONG tid, pid;
3034 BOOL rc;
3035 HWND hwnd;
3036
3037 dprintf(("EnumThreadWindows %x %x %x", dwThreadId, lpfn, lParam));
3038
3039 for (child = (Win32BaseWindow *)getFirstChild(); child; child = (Win32BaseWindow *)child->getNextChild())
3040 {
3041 OSLibWinQueryWindowProcess(child->getOS2WindowHandle(), &pid, &tid);
3042
3043 if(dwThreadId == tid) {
3044 dprintf2(("EnumThreadWindows: Found Window %x", child->getWindowHandle()));
3045 if((rc = lpfn(child->getWindowHandle(), lParam)) == FALSE) {
3046 break;
3047 }
3048 }
3049 }
3050 return TRUE;
3051}
3052//******************************************************************************
3053//Enumerate first-level children only
3054//******************************************************************************
3055BOOL Win32BaseWindow::EnumWindows(WNDENUMPROC lpfn, LPARAM lParam)
3056{
3057 Win32BaseWindow *window;
3058 BOOL rc;
3059 HWND hwnd = WNDHANDLE_MAGIC_HIGHWORD;
3060 DWORD dwStyle;
3061
3062 dprintf(("EnumWindows %x %x", lpfn, lParam));
3063
3064 for(int i=0;i<MAX_WINDOW_HANDLES;i++)
3065 {
3066 window = Win32BaseWindow::GetWindowFromHandle(hwnd);
3067 if(window) {
3068 if(window->getWindowHandle() != hwnd) {
3069 dprintf(("CORRUPT WINDOW %x %x", window, hwnd));
3070 }
3071 RELEASE_WNDOBJ(window);
3072 dwStyle = ::GetWindowLongA(hwnd, GWL_STYLE);
3073 if ((dwStyle & WS_POPUP) || ((dwStyle & WS_CAPTION) == WS_CAPTION))
3074 {
3075 dprintf2(("EnumWindows: Found Window %x", hwnd));
3076 if((rc = lpfn(hwnd, lParam)) == FALSE) {
3077 break;
3078 }
3079 }
3080 }
3081 hwnd++;
3082 }
3083 return TRUE;
3084}
3085//******************************************************************************
3086//******************************************************************************
3087HWND Win32BaseWindow::FindWindowById(int id)
3088{
3089 HWND hwnd;
3090
3091 lock();
3092 for (Win32BaseWindow *child = (Win32BaseWindow *)getFirstChild(); child; child = (Win32BaseWindow *)child->getNextChild())
3093 {
3094 if (child->getWindowId() == id)
3095 {
3096 hwnd = child->getWindowHandle();
3097 unlock();
3098 return hwnd;
3099 }
3100 }
3101 unlock();
3102 return 0;
3103}
3104//******************************************************************************
3105//TODO:
3106//We assume (for now) that if hwndParent or hwndChildAfter are real window handles, that
3107//the current process owns them.
3108//******************************************************************************
3109HWND Win32BaseWindow::FindWindowEx(HWND hwndParent, HWND hwndChildAfter, ATOM atom, LPSTR lpszWindow)
3110{
3111 Win32BaseWindow *parent = GetWindowFromHandle(hwndParent);
3112 Win32BaseWindow *child = GetWindowFromHandle(hwndChildAfter);
3113 Win32BaseWindow *firstchild = child;
3114
3115 dprintf(("FindWindowEx %x %x %x %s", hwndParent, hwndChildAfter, atom, lpszWindow));
3116 if((hwndParent != 0 && !parent) ||
3117 (hwndChildAfter != 0 && !child) ||
3118 (hwndParent == 0 && hwndChildAfter != 0))
3119 {
3120 if(parent) RELEASE_WNDOBJ(parent);
3121 if(firstchild) RELEASE_WNDOBJ(firstchild);
3122 dprintf(("Win32BaseWindow::FindWindowEx: parent or child not found %x %x", hwndParent, hwndChildAfter));
3123 SetLastError(ERROR_INVALID_WINDOW_HANDLE);
3124 return 0;
3125 }
3126 SetLastError(0);
3127 if(hwndParent != 0)
3128 {//if the current process owns the window, just do a quick search
3129 lock(&critsect);
3130 child = (Win32BaseWindow *)parent->getFirstChild();
3131 if(hwndChildAfter != 0)
3132 {
3133 while(child)
3134 {
3135 if(child->getWindowHandle() == hwndChildAfter)
3136 {
3137 child = (Win32BaseWindow *)child->getNextChild();
3138 break;
3139 }
3140 child = (Win32BaseWindow *)child->getNextChild();
3141 }
3142 }
3143 while(child)
3144 {
3145 //According to Wine, the class doesn't need to be specified
3146 if((!atom || child->getWindowClass()->getAtom() == atom) &&
3147 (!lpszWindow || child->hasWindowName(lpszWindow)))
3148 {
3149 dprintf(("FindWindowEx: Found window %x", child->getWindowHandle()));
3150 HWND hwndChild = child->getWindowHandle();
3151 unlock(&critsect);
3152 if(parent) RELEASE_WNDOBJ(parent);
3153 if(firstchild) RELEASE_WNDOBJ(firstchild);
3154 dprintf(("FindWindowEx: Found window %x", child->getWindowHandle()));
3155 return hwndChild;
3156 }
3157 child = (Win32BaseWindow *)child->getNextChild();
3158 }
3159 unlock(&critsect);
3160 if(parent) RELEASE_WNDOBJ(parent);
3161 if(firstchild) RELEASE_WNDOBJ(firstchild);
3162 }
3163 else {
3164 Win32BaseWindow *wnd;
3165 HWND henum, hwnd;
3166
3167 henum = OSLibWinBeginEnumWindows(OSLIB_HWND_DESKTOP);
3168 hwnd = OSLibWinGetNextWindow(henum);
3169
3170 while(hwnd)
3171 {
3172 wnd = GetWindowFromOS2FrameHandle(hwnd);
3173 if(wnd == NULL) {
3174 hwnd = OSLibWinQueryClientWindow(hwnd);
3175 if(hwnd) wnd = GetWindowFromOS2Handle(hwnd);
3176 }
3177
3178 if(wnd) {
3179 //According to Wine, the class doesn't need to be specified
3180 if((!atom || wnd->getWindowClass()->getAtom() == atom) &&
3181 (!lpszWindow || wnd->hasWindowName(lpszWindow)))
3182 {
3183 OSLibWinEndEnumWindows(henum);
3184 dprintf(("FindWindowEx: Found window %x", wnd->getWindowHandle()));
3185 HWND hwndret = wnd->getWindowHandle();
3186 RELEASE_WNDOBJ(wnd);
3187 return hwndret;
3188 }
3189 RELEASE_WNDOBJ(wnd);
3190 }
3191 hwnd = OSLibWinGetNextWindow(henum);
3192 }
3193 OSLibWinEndEnumWindows(henum);
3194 if(parent) RELEASE_WNDOBJ(parent);
3195 if(firstchild) RELEASE_WNDOBJ(firstchild);
3196 }
3197 SetLastError(ERROR_CANNOT_FIND_WND_CLASS); //TODO: not always correct
3198 return 0;
3199}
3200//******************************************************************************
3201//******************************************************************************
3202HWND Win32BaseWindow::GetWindow(UINT uCmd)
3203{
3204 HWND hwndRelated = 0;
3205 Win32BaseWindow *window;
3206
3207 switch(uCmd)
3208 {
3209 case GW_HWNDFIRST:
3210 window = (Win32BaseWindow *)getParent();
3211 if(window)
3212 {
3213 hwndRelated = OSLibWinQueryWindow(window->getOS2WindowHandle(), QWOS_TOP);
3214 window = GetWindowFromOS2FrameHandle(hwndRelated);
3215 if(window) {
3216 hwndRelated = window->getWindowHandle();
3217 RELEASE_WNDOBJ(window);
3218 }
3219 else hwndRelated = 0;
3220 }
3221 else {
3222 dprintf(("WARNING: GW_HWNDFIRST not correctly implemented for toplevel/most windows!"));
3223 hwndRelated = 0; //TODO: not correct; should get first child in z-order of desktop
3224 }
3225 break;
3226
3227 case GW_HWNDLAST:
3228 window = (Win32BaseWindow *)getParent();
3229 if(window) {
3230 hwndRelated = OSLibWinQueryWindow(window->getOS2WindowHandle(), QWOS_BOTTOM);
3231 dprintf(("os2 handle %x", hwndRelated));
3232 window = GetWindowFromOS2FrameHandle(hwndRelated);
3233 if(window) {
3234 hwndRelated = window->getWindowHandle();
3235 RELEASE_WNDOBJ(window);
3236 }
3237 else hwndRelated = 0;
3238 }
3239 else {
3240 dprintf(("WARNING: GW_HWNDLAST not correctly implemented for toplevel/most windows!"));
3241 hwndRelated = 0; //TODO: not correct; should get first child in z-order of desktop
3242 }
3243 break;
3244
3245 case GW_HWNDNEXT:
3246 if(getParent()) {
3247 hwndRelated = OSLibWinQueryWindow(getOS2FrameWindowHandle(), QWOS_NEXT);
3248 window = GetWindowFromOS2FrameHandle(hwndRelated);
3249 if(window) {
3250 hwndRelated = window->getWindowHandle();
3251 RELEASE_WNDOBJ(window);
3252 }
3253 else hwndRelated = 0;
3254 }
3255 else {
3256 dprintf(("WARNING: GW_HWNDNEXT not correctly implemented for toplevel/most windows!"));
3257 hwndRelated = 0; //TODO: not correct; should get first child in z-order of desktop
3258 }
3259 break;
3260
3261 case GW_HWNDPREV:
3262 if(getParent()) {
3263 hwndRelated = OSLibWinQueryWindow(getOS2FrameWindowHandle(), QWOS_PREV);
3264 window = GetWindowFromOS2FrameHandle(hwndRelated);
3265 if(window) {
3266 hwndRelated = window->getWindowHandle();
3267 RELEASE_WNDOBJ(window);
3268 }
3269 else hwndRelated = 0;
3270 }
3271 else {
3272 dprintf(("WARNING: GW_HWNDPREV not correctly implemented for toplevel/most windows!"));
3273 hwndRelated = 0; //TODO: not correct; should get first child in z-order of desktop
3274 }
3275 break;
3276
3277 case GW_OWNER:
3278 {
3279 Win32BaseWindow *owner = getOwner();
3280 if(owner) {
3281 hwndRelated = owner->getWindowHandle();
3282 }
3283 break;
3284 }
3285
3286 case GW_CHILD:
3287 hwndRelated = OSLibWinQueryWindow(getOS2WindowHandle(), QWOS_TOP);
3288 window = GetWindowFromOS2FrameHandle(hwndRelated);
3289
3290 //Before a window has processed WM_NCCREATE:
3291 //- GetWindow(parent, GW_CHILD) can't return that window handle
3292 //(verified in NT4, SP6)
3293 if(window) {
3294 if(window->state >= STATE_POST_WMNCCREATE) {
3295 hwndRelated = window->getWindowHandle();
3296 RELEASE_WNDOBJ(window);
3297 }
3298 else {
3299 hwndRelated = window->GetWindow(GW_HWNDNEXT);
3300 RELEASE_WNDOBJ(window);
3301 }
3302 }
3303 else hwndRelated = 0;
3304
3305 break;
3306
3307 //for internal use only
3308 case GW_HWNDNEXTCHILD:
3309 lock();
3310 window = (Win32BaseWindow *)getNextChild();
3311 if(window) {
3312 hwndRelated = window->getWindowHandle();
3313 }
3314 else hwndRelated = 0;
3315 unlock();
3316 break;
3317
3318 case GW_HWNDPREVCHILD:
3319 DebugInt3();
3320 break;
3321
3322 case GW_HWNDFIRSTCHILD:
3323 lock();
3324 window = (Win32BaseWindow *)getFirstChild();
3325 if(window) {
3326 hwndRelated = window->getWindowHandle();
3327 }
3328 else hwndRelated = 0;
3329 unlock();
3330 break;
3331
3332 case GW_HWNDLASTCHILD:
3333 lock();
3334 window = (Win32BaseWindow *)getFirstChild();
3335 if(window) {
3336 while (window->getNextChild())
3337 {
3338 window = (Win32BaseWindow *)window->getNextChild();
3339 }
3340 hwndRelated = window->getWindowHandle();
3341 }
3342 else hwndRelated = 0;
3343 unlock();
3344 break;
3345 }
3346end:
3347 dprintf(("GetWindow %x %d returned %x", getWindowHandle(), uCmd, hwndRelated));
3348 return hwndRelated;
3349}
3350//******************************************************************************
3351//******************************************************************************
3352HWND Win32BaseWindow::SetActiveWindow()
3353{
3354 HWND hwndActive;
3355
3356 dprintf(("SetActiveWindow %x", getWindowHandle()));
3357 if(getStyle() & WS_CHILD) {
3358// if(getStyle() & (WS_DISABLED | WS_CHILD)) {
3359 dprintf(("WARNING: Window is a child or disabled"));
3360 return 0;
3361 }
3362
3363 if(GetActiveWindow() == getWindowHandle()) {
3364 dprintf(("Window already active"));
3365 return getWindowHandle();
3366 }
3367 if (HOOK_IsHooked( WH_CBT ))
3368 {
3369 CBTACTIVATESTRUCT cbta;
3370 LRESULT ret;
3371
3372 cbta.fMouse = FALSE;
3373 cbta.hWndActive = GetActiveWindow();
3374 ret = HOOK_CallHooksA(WH_CBT, HCBT_ACTIVATE, getWindowHandle(), (LPARAM)&cbta);
3375 if(ret)
3376 {
3377 dprintf(("SetActiveWindow %x, CBT hook cancelled operation", getWindowHandle()));
3378 return cbta.hWndActive;
3379 }
3380 }
3381 SetWindowPos(HWND_TOP, 0,0,0,0, SWP_NOSIZE | SWP_NOMOVE );
3382
3383// if(OSLibWinSetActiveWindow(OS2Hwnd) == FALSE) {
3384// dprintf(("OSLibWinSetActiveWindow %x returned FALSE!", OS2Hwnd));
3385// }
3386 hwndActive = GetActiveWindow();
3387 return (hwndActive) ? hwndActive : windowDesktop->getWindowHandle(); //pretend the desktop was active
3388}
3389//******************************************************************************
3390//Used to change active status of an mdi window
3391//******************************************************************************
3392BOOL Win32BaseWindow::DeactivateChildWindow()
3393{
3394 /* child windows get a WM_CHILDACTIVATE message */
3395 if((getStyle() & (WS_CHILD | WS_POPUP)) == WS_CHILD )
3396 {
3397 ULONG flags = OSLibWinGetWindowULong(getOS2WindowHandle(), OFFSET_WIN32FLAGS);
3398 OSLibWinSetWindowULong(getOS2WindowHandle(), OFFSET_WIN32FLAGS, (flags & ~WINDOWFLAG_ACTIVE));
3399 return TRUE;
3400 }
3401 DebugInt3(); //should not be called for non-child window
3402 return FALSE;
3403}
3404//******************************************************************************
3405//WM_ENABLE is sent to hwnd, but not to it's children (as it should be)
3406//******************************************************************************
3407BOOL Win32BaseWindow::EnableWindow(BOOL fEnable)
3408{
3409 BOOL rc;
3410
3411 dprintf(("Win32BaseWindow::EnableWindow %x %d", getWindowHandle(), fEnable));
3412 //return true if previous state was disabled, else false (sdk docs)
3413 rc = (getStyle() & WS_DISABLED) != 0;
3414 if(rc && !fEnable) {
3415 SendMessageA(getWindowHandle(), WM_CANCELMODE, 0, 0);
3416 }
3417 OSLibWinEnableWindow(OS2HwndFrame, fEnable);
3418 if(fEnable == FALSE) {
3419 //SvL: No need to clear focus as PM already does this
3420 if(getWindowHandle() == GetCapture()) {
3421 ReleaseCapture(); /* A disabled window can't capture the mouse */
3422 dprintf(("Released capture for window %x that is being disabled", getWindowHandle()));
3423 }
3424 }
3425 return rc;
3426}
3427//******************************************************************************
3428//******************************************************************************
3429BOOL Win32BaseWindow::CloseWindow()
3430{
3431 if (::GetWindowLongW( getWindowHandle() , GWL_STYLE ) & WS_CHILD) return FALSE;
3432 ShowWindow( SW_MINIMIZE );
3433 return TRUE;
3434}
3435//******************************************************************************
3436//TODO: Not be 100% correct; should return active window of current thread
3437// or NULL when there is none -> WinQueryActiveWindow just returns
3438// the current active window
3439//******************************************************************************
3440HWND Win32BaseWindow::GetActiveWindow()
3441{
3442 HWND hwndActive;
3443
3444 hwndActive = OSLibWinQueryActiveWindow();
3445 return OS2ToWin32Handle(hwndActive);
3446}
3447//******************************************************************************
3448//******************************************************************************
3449BOOL Win32BaseWindow::hasWindowName(LPSTR wndname, BOOL fUnicode)
3450{
3451 INT len = GetWindowTextLength(fUnicode);
3452 BOOL res;
3453
3454 if (wndname == NULL)
3455 return (len == 0);
3456
3457 len++;
3458 if (fUnicode)
3459 {
3460 WCHAR *text = (WCHAR*)malloc(len*sizeof(WCHAR));
3461
3462 GetWindowTextW(text,len);
3463 res = (lstrcmpW(text,(LPWSTR)wndname) == 0);
3464 free(text);
3465 }
3466 else
3467 {
3468 CHAR *text = (CHAR*)malloc(len*sizeof(CHAR));
3469
3470 GetWindowTextA(text,len);
3471 res = (strcmp(text,wndname) == 0);
3472 free(text);
3473 }
3474
3475 return res;
3476}
3477//******************************************************************************
3478//******************************************************************************
3479CHAR *Win32BaseWindow::getWindowNamePtrA()
3480{
3481 INT len = GetWindowTextLength(FALSE);
3482 CHAR *text;
3483
3484 if (len == 0) return NULL;
3485 len++;
3486 text = (CHAR*)malloc(len*sizeof(CHAR));
3487 GetWindowTextA(text,len);
3488
3489 return text;
3490}
3491//******************************************************************************
3492//******************************************************************************
3493WCHAR *Win32BaseWindow::getWindowNamePtrW()
3494{
3495 INT len = GetWindowTextLength(TRUE);
3496 WCHAR *text;
3497
3498 if (len == 0) return NULL;
3499 len++;
3500 text = (WCHAR*)malloc(len*sizeof(WCHAR));
3501 GetWindowTextW(text,len);
3502
3503 return text;
3504}
3505//******************************************************************************
3506//******************************************************************************
3507VOID Win32BaseWindow::freeWindowNamePtr(PVOID namePtr)
3508{
3509 if (namePtr) free(namePtr);
3510}
3511//******************************************************************************
3512//When using this API for a window that was created by a different process, NT
3513//does NOT send WM_GETTEXTLENGTH.
3514//******************************************************************************
3515int Win32BaseWindow::GetWindowTextLength(BOOL fUnicode)
3516{
3517 //if the destination window is created by this process, send message
3518 if(dwProcessId == currentProcessId)
3519 {
3520 if(fUnicode) {
3521 return SendMessageW(getWindowHandle(), WM_GETTEXTLENGTH,0,0);
3522 }
3523 else return SendMessageA(getWindowHandle(), WM_GETTEXTLENGTH,0,0);
3524 }
3525 //else get data directory from window structure
3526 //TODO: must lock window structure.... (TODO)
3527 return windowNameLength;
3528}
3529//******************************************************************************
3530//When using this API for a window that was created by a different process, NT
3531//does NOT send WM_GETTEXT.
3532//******************************************************************************
3533int Win32BaseWindow::GetWindowTextA(LPSTR lpsz, int cch)
3534{
3535 //if the destination window is created by this process, send message
3536 if(dwProcessId == currentProcessId) {
3537 return SendMessageA(getWindowHandle(),WM_GETTEXT,(WPARAM)cch,(LPARAM)lpsz);
3538 }
3539
3540 //else get data directory from window structure
3541 if (!lpsz || !cch) return 0;
3542 if (!windowNameA) lpsz[0] = 0;
3543 else memcpy(lpsz, windowNameA, min(windowNameLength + 1, cch) );
3544 return min(windowNameLength, cch);
3545}
3546//******************************************************************************
3547//When using this API for a window that was created by a different process, NT
3548//does NOT send WM_GETTEXT.
3549//******************************************************************************
3550int Win32BaseWindow::GetWindowTextW(LPWSTR lpsz, int cch)
3551{
3552 //if the destination window is created by this process, send message
3553 if(dwProcessId == currentProcessId) {
3554 return ::SendMessageW(getWindowHandle(), WM_GETTEXT,(WPARAM)cch,(LPARAM)lpsz);
3555 }
3556 //else get data directory from window structure
3557 if (!lpsz || !cch)
3558 return 0;
3559 if (!windowNameW)
3560 lpsz[0] = 0;
3561 else
3562 memcpy(lpsz, windowNameW, min( sizeof(WCHAR) * (windowNameLength+1), cch));
3563
3564 return min(windowNameLength, cch);
3565}
3566//******************************************************************************
3567//TODO: How does this work when the target window belongs to a different process???
3568//******************************************************************************
3569BOOL Win32BaseWindow::SetWindowTextA(LPSTR lpsz)
3570{
3571 return SendMessageA(getWindowHandle(),WM_SETTEXT,0,(LPARAM)lpsz);
3572}
3573//******************************************************************************
3574//******************************************************************************
3575BOOL Win32BaseWindow::SetWindowTextW(LPWSTR lpsz)
3576{
3577 return SendMessageW(getWindowHandle(), WM_SETTEXT,0,(LPARAM)lpsz);
3578}
3579//******************************************************************************
3580//******************************************************************************
3581LONG Win32BaseWindow::SetWindowLong(int index, ULONG value, BOOL fUnicode)
3582{
3583 LONG oldval;
3584
3585 switch(index) {
3586 case GWL_EXSTYLE:
3587 {
3588 STYLESTRUCT ss;
3589
3590 if(dwExStyle == value) {
3591 oldval = value;
3592 break;
3593 }
3594 ss.styleOld = dwExStyle;
3595 ss.styleNew = value;
3596 dprintf(("SetWindowLong GWL_EXSTYLE %x old %x new style %x", getWindowHandle(), dwExStyle, value));
3597 SendMessageA(getWindowHandle(),WM_STYLECHANGING,GWL_EXSTYLE,(LPARAM)&ss);
3598 setExStyle(ss.styleNew);
3599 SendMessageA(getWindowHandle(),WM_STYLECHANGED,GWL_EXSTYLE,(LPARAM)&ss);
3600 oldval = ss.styleOld;
3601 break;
3602 }
3603 case GWL_STYLE:
3604 {
3605 STYLESTRUCT ss;
3606
3607 //SvL: TODO: Can you change minimize or maximize status here too?
3608
3609 if(dwStyle == value) {
3610 oldval = value;
3611 break;
3612 }
3613 dprintf(("SetWindowLong GWL_STYLE %x old %x new style %x (%x)", getWindowHandle(), dwStyle, value));
3614#ifdef DEBUG
3615// if((value & WS_CHILD) != (dwStyle & WS_CHILD)) {
3616// DebugInt3(); //is this allowed?
3617// }
3618#endif
3619 value &= ~(WS_CHILD);
3620 ss.styleOld = getStyle();
3621 ss.styleNew = value | (ss.styleOld & WS_CHILD);
3622 SendMessageA(getWindowHandle(),WM_STYLECHANGING,GWL_STYLE,(LPARAM)&ss);
3623 setStyle(ss.styleNew);
3624 SendMessageA(getWindowHandle(),WM_STYLECHANGED,GWL_STYLE,(LPARAM)&ss);
3625 OSLibSetWindowStyle(getOS2FrameWindowHandle(), getOS2WindowHandle(), getStyle(), getExStyle());
3626
3627 //TODO: Might not be correct to use ShowWindow here
3628 if((ss.styleOld & WS_VISIBLE) != (ss.styleNew & WS_VISIBLE)) {
3629 if(ss.styleNew & WS_VISIBLE)
3630 ShowWindow(SW_SHOWNOACTIVATE);
3631 else ShowWindow(SW_HIDE);
3632 }
3633#ifdef DEBUG
3634 PrintWindowStyle(ss.styleNew, 0);
3635#endif
3636 oldval = ss.styleOld;
3637 break;
3638 }
3639 case GWL_WNDPROC:
3640 {
3641 //Note: Type of SetWindowLong determines new window proc type
3642 // UNLESS the new window proc has already been registered
3643 // (use the old type in that case)
3644 // (VERIFIED in NT 4, SP6)
3645 WINDOWPROCTYPE type = WINPROC_GetProcType((HWINDOWPROC)value);
3646 if(type == WIN_PROC_INVALID) {
3647 type = (fUnicode) ? WIN_PROC_32W : WIN_PROC_32A;
3648 }
3649 oldval = (LONG)WINPROC_GetProc(win32wndproc, (fUnicode) ? WIN_PROC_32W : WIN_PROC_32A);
3650 dprintf(("SetWindowLong%c GWL_WNDPROC %x old %x new wndproc %x", (fUnicode) ? 'W' : 'A', getWindowHandle(), oldval, value));
3651 WINPROC_SetProc((HWINDOWPROC *)&win32wndproc, (WNDPROC)value, type, WIN_PROC_WINDOW);
3652 break;
3653 }
3654 case GWL_HINSTANCE:
3655 oldval = hInstance;
3656 hInstance = value;
3657 break;
3658
3659 case GWL_HWNDPARENT:
3660 oldval = SetParent((HWND)value);
3661 break;
3662
3663 case GWL_ID:
3664 dprintf(("GWL_ID old %x, new %x", getWindowId(), value));
3665 oldval = getWindowId();
3666 setWindowId(value);
3667 break;
3668
3669 case GWL_USERDATA:
3670 oldval = userData;
3671 userData = value;
3672 break;
3673
3674 default:
3675 if(index >= 0 && index + sizeof(ULONG) <= nrUserWindowBytes)
3676 {
3677 oldval = *(ULONG *)(userWindowBytes + index);
3678 *(ULONG *)(userWindowBytes + index) = value;
3679 break;
3680 }
3681 dprintf(("WARNING: SetWindowLong%c %x %d %x returned %x INVALID index!", (fUnicode) ? 'W' : 'A', getWindowHandle(), index, value));
3682 SetLastError(ERROR_INVALID_INDEX); //verified in NT4, SP6
3683 return 0;
3684 }
3685 //Note: NT4, SP6 does not set the last error to 0
3686 SetLastError(ERROR_SUCCESS);
3687 dprintf2(("SetWindowLong%c %x %d %x returned %x", (fUnicode) ? 'W' : 'A', getWindowHandle(), index, value, oldval));
3688 return oldval;
3689}
3690//******************************************************************************
3691//******************************************************************************
3692ULONG Win32BaseWindow::GetWindowLong(int index, BOOL fUnicode)
3693{
3694 ULONG value;
3695
3696 switch(index) {
3697 case GWL_EXSTYLE:
3698 value = dwExStyle;
3699 break;
3700 case GWL_STYLE:
3701 value = dwStyle;
3702 break;
3703 case GWL_WNDPROC:
3704 value = (LONG)WINPROC_GetProc(win32wndproc, (fUnicode) ? WIN_PROC_32W : WIN_PROC_32A);
3705 break;
3706 case GWL_HINSTANCE:
3707 value = hInstance;
3708 break;
3709 case GWL_HWNDPARENT:
3710 value = GetParent();
3711 break;
3712 case GWL_ID:
3713 value = getWindowId();
3714 break;
3715 case GWL_USERDATA:
3716 value = userData;
3717 break;
3718 default:
3719 if(index >= 0 && index + sizeof(ULONG) <= nrUserWindowBytes)
3720 {
3721 value = *(ULONG *)(userWindowBytes + index);
3722 break;
3723 }
3724 dprintf(("WARNING: GetWindowLong%c %x %d %x returned %x INVALID index!", (fUnicode) ? 'W' : 'A', getWindowHandle(), index, value));
3725 SetLastError(ERROR_INVALID_INDEX); //verified in NT4, SP6
3726 return 0;
3727 }
3728 dprintf2(("GetWindowLong%c %x %d %x", (fUnicode) ? 'W' : 'A', getWindowHandle(), index, value));
3729 //Note: NT4, SP6 does not set the last error to 0
3730 SetLastError(ERROR_SUCCESS);
3731 return value;
3732}
3733//******************************************************************************
3734//******************************************************************************
3735WORD Win32BaseWindow::SetWindowWord(int index, WORD value)
3736{
3737 WORD oldval;
3738
3739 if(index >= 0 && index + sizeof(WORD) <= nrUserWindowBytes)
3740 {
3741 oldval = *(WORD *)(userWindowBytes + index);
3742 *(WORD *)(userWindowBytes + index) = value;
3743 //Note: NT4, SP6 does not set the last error to 0
3744 dprintf2(("SetWindowWord %x %d %x returned %x", getWindowHandle(), index, value, oldval));
3745 SetLastError(ERROR_SUCCESS);
3746 return oldval;
3747 }
3748 switch(index)
3749 {
3750 case GWW_HINSTANCE:
3751 oldval = hInstance;
3752 hInstance = value;
3753 break;
3754
3755 case GWW_HWNDPARENT:
3756 oldval = SetParent((HWND)(WNDHANDLE_MAGIC_HIGHWORD | value));
3757 break;
3758
3759 case GWW_ID:
3760 oldval = getWindowId();
3761 setWindowId(value);
3762 break;
3763
3764 default:
3765 dprintf(("WARNING: SetWindowWord %x %d %x returned %x INVALID index!", getWindowHandle(), index, value));
3766 SetLastError(ERROR_INVALID_INDEX); //verified in NT4, SP6
3767 return 0;
3768 }
3769 //Note: NT4, SP6 does not set the last error to 0
3770 SetLastError(ERROR_SUCCESS);
3771 dprintf2(("SetWindowWord %x %d %x returned %x", getWindowHandle(), index, value, oldval));
3772 return oldval;
3773}
3774//******************************************************************************
3775//******************************************************************************
3776WORD Win32BaseWindow::GetWindowWord(int index)
3777{
3778 if(index >= 0 && index + sizeof(WORD) <= nrUserWindowBytes)
3779 {
3780 //Note: NT4, SP6 does not set the last error to 0
3781 SetLastError(ERROR_SUCCESS);
3782 dprintf2(("GetWindowWord %x %d %x", getWindowHandle(), index, *(WORD *)(userWindowBytes + index)));
3783 return *(WORD *)(userWindowBytes + index);
3784 }
3785 switch(index)
3786 {
3787 case GWW_ID:
3788 if(HIWORD(getWindowId()))
3789 dprintf(("WARNING: GWW_ID: discards high bits of 0x%08x!\n", getWindowId()));
3790 return (WORD)getWindowId();
3791
3792 case GWW_HWNDPARENT:
3793 dprintf(("WARNING: GWW_HWNDPARENT: discards high bits of 0x%08x!\n", GetParent()));
3794 return (WORD) GetParent();
3795
3796 case GWW_HINSTANCE:
3797 if (HIWORD(hInstance))
3798 dprintf(("WARNING: GWW_HINSTANCE: discards high bits of 0x%08x!\n", hInstance));
3799 return (WORD)hInstance;
3800 }
3801
3802 dprintf(("WARNING: GetWindowWord %x %d returned %x INVALID index!", getWindowHandle(), index));
3803 SetLastError(ERROR_INVALID_INDEX); //verified in NT4, SP6
3804 return 0;
3805}
3806//******************************************************************************
3807//Locates window in linked list and increases reference count (if found)
3808//Window object must be unreferenced after usage
3809//******************************************************************************
3810Win32BaseWindow *Win32BaseWindow::GetWindowFromHandle(HWND hwnd)
3811{
3812 Win32BaseWindow *window;
3813
3814////TODO: temporary workaround for crashes in Opera (pmwinx; releasesemaphore)
3815//// while browsing
3816//// Not thread safe now!
3817//// lock(&critsect);
3818 if(HwGetWindowHandleData(hwnd, (DWORD *)&window) == TRUE) {
3819 if(window) {
3820//// dprintf(("addRef %x; refcount %d", hwnd, window->getRefCount()+1));
3821 window->addRef();
3822 }
3823//// unlock(&critsect);
3824 return window;
3825 }
3826//// unlock(&critsect);
3827// dprintf2(("Win32BaseWindow::GetWindowFromHandle: not a win32 window %x", hwnd));
3828 return NULL;
3829}
3830//******************************************************************************
3831//Locates window in linked list and increases reference count (if found)
3832//Window object must be unreferenced after usage
3833//******************************************************************************
3834Win32BaseWindow *Win32BaseWindow::GetWindowFromOS2Handle(HWND hwndOS2)
3835{
3836 DWORD magic;
3837 HWND hwnd;
3838
3839 if(hwndOS2 == OSLIB_HWND_DESKTOP)
3840 {
3841 windowDesktop->addRef();
3842 return windowDesktop;
3843 }
3844
3845 hwnd = (HWND)OSLibWinGetWindowULong(hwndOS2, OFFSET_WIN32WNDPTR);
3846 magic = OSLibWinGetWindowULong(hwndOS2, OFFSET_WIN32PM_MAGIC);
3847
3848 if(hwnd && CheckMagicDword(magic)) {
3849 return GetWindowFromHandle(hwnd);
3850 }
3851// dprintf2(("Win32BaseWindow::GetWindowFromOS2Handle: not an Odin os2 window %x", hwndOS2));
3852 return 0;
3853}
3854//******************************************************************************
3855//Locates window in linked list and increases reference count (if found)
3856//Window object must be unreferenced after usage
3857//******************************************************************************
3858Win32BaseWindow *Win32BaseWindow::GetWindowFromOS2FrameHandle(HWND hwnd)
3859{
3860 return GetWindowFromOS2Handle(OSLibWinWindowFromID(hwnd,OSLIB_FID_CLIENT));
3861}
3862//******************************************************************************
3863//******************************************************************************
3864HWND WIN32API Win32ToOS2Handle(HWND hwnd)
3865{
3866 HWND hwndOS2;
3867
3868 Win32BaseWindow *window = Win32BaseWindow::GetWindowFromHandle(hwnd);
3869
3870 if(window) {
3871 hwndOS2 = window->getOS2WindowHandle();
3872 RELEASE_WNDOBJ(window);
3873 return hwndOS2;
3874 }
3875// dprintf2(("Win32BaseWindow::Win32ToOS2Handle: not a win32 window %x", hwnd));
3876 return hwnd;
3877}
3878//******************************************************************************
3879//******************************************************************************
3880HWND WIN32API Win32ToOS2FrameHandle(HWND hwnd)
3881{
3882 HWND hwndOS2;
3883
3884 Win32BaseWindow *window = Win32BaseWindow::GetWindowFromHandle(hwnd);
3885
3886 if(window) {
3887 hwndOS2 = window->getOS2FrameWindowHandle();
3888 RELEASE_WNDOBJ(window);
3889 return hwndOS2;
3890 }
3891// dprintf2(("Win32BaseWindow::Win32ToOS2Handle: not a win32 window %x", hwnd));
3892 return hwnd;
3893}
3894//******************************************************************************
3895//******************************************************************************
3896HWND WIN32API OS2ToWin32Handle(HWND hwnd)
3897{
3898 Win32BaseWindow *window = Win32BaseWindow::GetWindowFromOS2Handle(hwnd);
3899 HWND hwndWin32;
3900
3901 if(window) {
3902 hwndWin32 = window->getWindowHandle();
3903 RELEASE_WNDOBJ(window);
3904 return hwndWin32;
3905 }
3906 window = Win32BaseWindow::GetWindowFromOS2FrameHandle(hwnd);
3907 if(window) {
3908 hwndWin32 = window->getWindowHandle();
3909 RELEASE_WNDOBJ(window);
3910 return hwndWin32;
3911 }
3912
3913// dprintf2(("Win32BaseWindow::OS2ToWin32Handle: not a win32 window %x", hwnd));
3914 return 0;
3915// else return hwnd; //OS/2 window handle
3916}
3917#ifdef DEBUG
3918LONG Win32BaseWindow::addRef()
3919{
3920// dprintf2(("addRef %x %d", getWindowHandle(), getRefCount()+1));
3921 return GenericObject::addRef();
3922}
3923//******************************************************************************
3924//******************************************************************************
3925LONG Win32BaseWindow::release(char *function, int line)
3926{
3927// dprintf2(("release %s %d %x %d", function, line, getWindowHandle(), getRefCount()-1));
3928 return GenericObject::release();
3929}
3930#endif
3931//******************************************************************************
3932//******************************************************************************
3933GenericObject *Win32BaseWindow::windows = NULL;
3934CRITICAL_SECTION Win32BaseWindow::critsect = {0};
3935
3936//******************************************************************************
3937//******************************************************************************
3938#ifdef DEBUG
3939void PrintWindowStyle(DWORD dwStyle, DWORD dwExStyle)
3940{
3941 char style[256] = "";
3942 char exstyle[256] = "";
3943
3944 /* Window styles */
3945 if(dwStyle & WS_CHILD)
3946 strcat(style, "WS_CHILD ");
3947 if(dwStyle & WS_POPUP)
3948 strcat(style, "WS_POPUP ");
3949 if(dwStyle & WS_VISIBLE)
3950 strcat(style, "WS_VISIBLE ");
3951 if(dwStyle & WS_DISABLED)
3952 strcat(style, "WS_DISABLED ");
3953 if(dwStyle & WS_CLIPSIBLINGS)
3954 strcat(style, "WS_CLIPSIBLINGS ");
3955 if(dwStyle & WS_CLIPCHILDREN)
3956 strcat(style, "WS_CLIPCHILDREN ");
3957 if(dwStyle & WS_MAXIMIZE)
3958 strcat(style, "WS_MAXIMIZE ");
3959 if(dwStyle & WS_MINIMIZE)
3960 strcat(style, "WS_MINIMIZE ");
3961 if(dwStyle & WS_GROUP)
3962 strcat(style, "WS_GROUP ");
3963 if(dwStyle & WS_TABSTOP)
3964 strcat(style, "WS_TABSTOP ");
3965
3966 if((dwStyle & WS_CAPTION) == WS_CAPTION)
3967 strcat(style, "WS_CAPTION ");
3968 if(dwStyle & WS_DLGFRAME)
3969 strcat(style, "WS_DLGFRAME ");
3970 if(dwStyle & WS_BORDER)
3971 strcat(style, "WS_BORDER ");
3972
3973 if(dwStyle & WS_VSCROLL)
3974 strcat(style, "WS_VSCROLL ");
3975 if(dwStyle & WS_HSCROLL)
3976 strcat(style, "WS_HSCROLL ");
3977 if(dwStyle & WS_SYSMENU)
3978 strcat(style, "WS_SYSMENU ");
3979 if(dwStyle & WS_THICKFRAME)
3980 strcat(style, "WS_THICKFRAME ");
3981 if(dwStyle & WS_MINIMIZEBOX)
3982 strcat(style, "WS_MINIMIZEBOX ");
3983 if(dwStyle & WS_MAXIMIZEBOX)
3984 strcat(style, "WS_MAXIMIZEBOX ");
3985
3986 if(dwExStyle & WS_EX_DLGMODALFRAME)
3987 strcat(exstyle, "WS_EX_DLGMODALFRAME ");
3988 if(dwExStyle & WS_EX_ACCEPTFILES)
3989 strcat(exstyle, "WS_EX_ACCEPTFILES ");
3990 if(dwExStyle & WS_EX_NOPARENTNOTIFY)
3991 strcat(exstyle, "WS_EX_NOPARENTNOTIFY ");
3992 if(dwExStyle & WS_EX_TOPMOST)
3993 strcat(exstyle, "WS_EX_TOPMOST ");
3994 if(dwExStyle & WS_EX_TRANSPARENT)
3995 strcat(exstyle, "WS_EX_TRANSPARENT ");
3996
3997 if(dwExStyle & WS_EX_MDICHILD)
3998 strcat(exstyle, "WS_EX_MDICHILD ");
3999 if(dwExStyle & WS_EX_TOOLWINDOW)
4000 strcat(exstyle, "WS_EX_TOOLWINDOW ");
4001 if(dwExStyle & WS_EX_WINDOWEDGE)
4002 strcat(exstyle, "WS_EX_WINDOWEDGE ");
4003 if(dwExStyle & WS_EX_CLIENTEDGE)
4004 strcat(exstyle, "WS_EX_CLIENTEDGE ");
4005 if(dwExStyle & WS_EX_CONTEXTHELP)
4006 strcat(exstyle, "WS_EX_CONTEXTHELP ");
4007 if(dwExStyle & WS_EX_RIGHT)
4008 strcat(exstyle, "WS_EX_RIGHT ");
4009 if(dwExStyle & WS_EX_LEFT)
4010 strcat(exstyle, "WS_EX_LEFT ");
4011 if(dwExStyle & WS_EX_RTLREADING)
4012 strcat(exstyle, "WS_EX_RTLREADING ");
4013 if(dwExStyle & WS_EX_LTRREADING)
4014 strcat(exstyle, "WS_EX_LTRREADING ");
4015 if(dwExStyle & WS_EX_LEFTSCROLLBAR)
4016 strcat(exstyle, "WS_EX_LEFTSCROLLBAR ");
4017 if(dwExStyle & WS_EX_RIGHTSCROLLBAR)
4018 strcat(exstyle, "WS_EX_RIGHTSCROLLBAR ");
4019 if(dwExStyle & WS_EX_CONTROLPARENT)
4020 strcat(exstyle, "WS_EX_CONTROLPARENT ");
4021 if(dwExStyle & WS_EX_STATICEDGE)
4022 strcat(exstyle, "WS_EX_STATICEDGE ");
4023 if(dwExStyle & WS_EX_APPWINDOW)
4024 strcat(exstyle, "WS_EX_APPWINDOW ");
4025
4026 dprintf(("Window style: %x %s", dwStyle, style));
4027 dprintf(("Window exStyle: %x %s", dwExStyle, exstyle));
4028}
4029#endif
4030//******************************************************************************
4031//******************************************************************************
Note: See TracBrowser for help on using the repository browser.