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

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

SC_CLOSE translation fix + activation changes

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