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

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

set/getwindowword additions

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