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

Last change on this file since 5242 was 5242, checked in by sandervl, 25 years ago

window & class user word access fixes

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