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

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

ported the Wine MDI control + some menu fixes

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