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

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

bug fixes

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