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

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

mouse message translation + dc reset after resize fixes

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