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

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

reference count (window + class objects) rewrite

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