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

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

small updates for frame tracking

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