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

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

mdi, setcursor, min/max/restore, dlglist changes

File size: 127.2 KB
Line 
1/* $Id: win32wbase.cpp,v 1.244 2001-02-23 14:52:41 sandervl Exp $ */
2/*
3 * Win32 Window Base Class for OS/2
4 *
5 * Copyright 1998-2000 Sander van Leeuwen (sandervl@xs4all.nl)
6 * Copyright 1999 Daniela Engert (dani@ngrt.de)
7 * Copyright 1999-2000 Christoph Bratschi (cbratschi@datacomm.ch)
8 *
9 * Parts based on Wine Windows code (windows\win.c)
10 * Corel version: corel20000212
11 *
12 * Copyright 1993, 1994, 1996 Alexandre Julliard
13 * 1995 Alex Korobka
14 *
15 * TODO: Not thread/process safe
16 *
17 * NOTE: Client rectangle always relative to frame window
18 * Window rectangle in parent coordinates (relative to parent's client window)
19 * (screen coord. if no parent)
20 *
21 * Project Odin Software License can be found in LICENSE.TXT
22 *
23 */
24#include <os2win.h>
25#include <win.h>
26#include <stdlib.h>
27#include <string.h>
28#include <stdarg.h>
29#include <assert.h>
30#include <misc.h>
31#include <heapstring.h>
32#include <winuser32.h>
33#include "win32wbase.h"
34#include "wndmsg.h"
35#include "oslibwin.h"
36#include "oslibmsg.h"
37#include "oslibutil.h"
38#include "oslibgdi.h"
39#include "oslibres.h"
40#include "oslibdos.h"
41#include "syscolor.h"
42#include "win32wndhandle.h"
43#include "dc.h"
44#include "win32wdesktop.h"
45#include "pmwindow.h"
46#include "controls.h"
47#include <wprocess.h>
48#include <win\hook.h>
49#include <menu.h>
50#define INCL_TIMERWIN32
51#include "timer.h"
52
53#define DBG_LOCALLOG DBG_win32wbase
54#include "dbglocal.h"
55
56/* bits in the dwKeyData */
57#define KEYDATA_ALT 0x2000
58#define KEYDATA_PREVSTATE 0x4000
59
60void PrintWindowStyle(DWORD dwStyle, DWORD dwExStyle);
61
62static fDestroyAll = FALSE;
63//For quick lookup of current process id
64static ULONG currentProcessId = -1;
65
66//******************************************************************************
67//******************************************************************************
68Win32BaseWindow::Win32BaseWindow(DWORD objType) : GenericObject(&windows, objType)
69{
70 Init();
71}
72//******************************************************************************
73//******************************************************************************
74Win32BaseWindow::Win32BaseWindow(HWND hwndOS2, ULONG reserved) : GenericObject(&windows, OBJTYPE_WINDOW), ChildWindow()
75{
76 Init();
77 OS2Hwnd = hwndOS2;
78}
79//******************************************************************************
80//******************************************************************************
81Win32BaseWindow::Win32BaseWindow(CREATESTRUCTA *lpCreateStructA, ATOM classAtom, BOOL isUnicode)
82 : GenericObject(&windows, OBJTYPE_WINDOW), ChildWindow()
83{
84 Init();
85 this->isUnicode = isUnicode;
86 CreateWindowExA(lpCreateStructA, classAtom);
87}
88//******************************************************************************
89//******************************************************************************
90void Win32BaseWindow::Init()
91{
92 isUnicode = FALSE;
93 fFirstShow = TRUE;
94 fIsDialog = FALSE;
95 fIsModalDialogOwner = FALSE;
96 OS2HwndModalDialog = 0;
97 fInternalMsg = FALSE;
98 fNoSizeMsg = FALSE;
99 fIsDestroyed = FALSE;
100 fDestroyWindowCalled = FALSE;
101 fCreated = FALSE;
102 fTaskList = FALSE;
103 fParentDC = FALSE;
104 fComingToTop = FALSE;
105 fCreateSetWindowPos = FALSE;
106 fCreationFinished= FALSE;
107 fMinMaxChange = FALSE;
108
109 windowNameA = NULL;
110 windowNameW = NULL;
111 wndNameLength = 0;
112
113 userWindowBytes = NULL;;
114 nrUserWindowBytes= 0;
115
116 magic = WIN32PM_MAGIC;
117 OS2Hwnd = 0;
118 hSysMenu = 0;
119 Win32Hwnd = 0;
120
121 if(HwAllocateWindowHandle(&Win32Hwnd, (ULONG)this) == FALSE)
122 {
123 dprintf(("Win32BaseWindow::Init HwAllocateWindowHandle failed!!"));
124 DebugInt3();
125 }
126
127 posx = posy = 0;
128 width = height = 0;
129
130 dwExStyle = 0;
131 dwStyle = 0;
132 win32wndproc = 0;
133 hInstance = 0;
134 dwIDMenu = 0; //0xFFFFFFFF; //default -1
135 userData = 0;
136 contextHelpId = 0;
137 hotkey = 0;
138
139
140 hwndLinkAfter = HWND_BOTTOM;
141 flags = 0;
142 lastHitTestVal = HTOS_NORMAL;
143 owner = NULL;
144 windowClass = 0;
145
146 hIcon = 0;
147 hIconSm = 0;
148
149 EraseBkgndFlag = TRUE;
150
151 horzScrollInfo = NULL;
152 vertScrollInfo = NULL;
153
154 propertyList = NULL;
155
156 ownDC = 0;
157 hWindowRegion = 0;
158 hClipRegion = 0;
159
160 hTaskList = 0;
161
162 if(currentProcessId == -1)
163 {
164 currentProcessId = GetCurrentProcessId();
165 }
166 dwThreadId = GetCurrentThreadId();
167 dwProcessId = currentProcessId;
168
169 memset(&windowpos, 0, sizeof(windowpos));
170 //min and max position are initially -1 (verified in NT4, SP6)
171 windowpos.ptMinPosition.x = -1;
172 windowpos.ptMinPosition.y = -1;
173 windowpos.ptMaxPosition.x = -1;
174 windowpos.ptMaxPosition.y = -1;
175}
176//******************************************************************************
177//todo get rid of resources (menu, icon etc)
178//******************************************************************************
179Win32BaseWindow::~Win32BaseWindow()
180{
181 if(hTaskList) {
182 OSLibWinRemoveFromTasklist(hTaskList);
183 }
184
185 OSLibWinSetVisibleRegionNotify(OS2Hwnd, FALSE);
186 OSLibWinSetWindowULong(OS2Hwnd, OFFSET_WIN32WNDPTR, 0);
187 OSLibWinSetWindowULong(OS2Hwnd, OFFSET_WIN32PM_MAGIC, 0);
188
189 if(!fDestroyAll && getParent() && getParent()->getFirstChild() == this && getNextChild() == NULL)
190 {
191 //if we're the last child that's being destroyed and our
192 //parent window was also destroyed, then we delete the parent object
193 if(getParent()->IsWindowDestroyed())
194 {
195 dprintf(("Last Child (%x) destroyed, get rid of our parent window (%x)", getWindowHandle(), getParent()->getWindowHandle()));
196 delete getParent();
197 setParent(NULL); //or else we'll crash in the dtor of the ChildWindow class
198 }
199 }
200 else
201 if(fDestroyAll) {
202 dprintf(("Destroying window %x %s", getWindowHandle(), windowNameA));
203 setParent(NULL); //or else we'll crash in the dtor of the ChildWindow class
204 }
205
206 /* Decrement class window counter */
207 if(windowClass) {
208 windowClass->DecreaseWindowCount();
209 }
210
211 if(isOwnDC())
212 releaseOwnDC(ownDC);
213
214 if(Win32Hwnd)
215 HwFreeWindowHandle(Win32Hwnd);
216
217 if(userWindowBytes)
218 free(userWindowBytes);
219
220 if(windowNameA) {
221 free(windowNameA);
222 windowNameA = NULL;
223 }
224 if(windowNameW) {
225 free(windowNameW);
226 windowNameW = NULL;
227 }
228 if(vertScrollInfo) {
229 free(vertScrollInfo);
230 vertScrollInfo = NULL;
231 }
232 if(horzScrollInfo) {
233 free(horzScrollInfo);
234 horzScrollInfo = NULL;
235 }
236 if(propertyList) {
237 removeWindowProps();
238 }
239}
240//******************************************************************************
241//******************************************************************************
242void Win32BaseWindow::DestroyAll()
243{
244 fDestroyAll = TRUE;
245 GenericObject::DestroyAll(windows);
246}
247//******************************************************************************
248//******************************************************************************
249BOOL Win32BaseWindow::isChild()
250{
251 return ((dwStyle & WS_CHILD) != 0);
252}
253//******************************************************************************
254//******************************************************************************
255BOOL Win32BaseWindow::IsWindowUnicode()
256{
257 dprintf2(("IsWindowUnicode %x %d", getWindowHandle(), WINPROC_GetProcType(getWindowProc()) == WIN_PROC_32W));
258 return (WINPROC_GetProcType(getWindowProc()) == WIN_PROC_32W);
259}
260//******************************************************************************
261//******************************************************************************
262BOOL Win32BaseWindow::CreateWindowExA(CREATESTRUCTA *cs, ATOM classAtom)
263{
264 char buffer[256];
265
266#ifdef DEBUG
267 PrintWindowStyle(cs->style, cs->dwExStyle);
268#endif
269
270 //If window has no owner/parent window, then it will be added to the tasklist
271 //(depending on visibility state)
272 if (!cs->hwndParent) fTaskList = TRUE;
273
274 sw = SW_SHOW;
275 SetLastError(0);
276
277 /* Find the parent window */
278 if (cs->hwndParent)
279 {
280 Win32BaseWindow *window = GetWindowFromHandle(cs->hwndParent);
281 if(!window) {
282 dprintf(("Bad parent %04x\n", cs->hwndParent ));
283 SetLastError(ERROR_INVALID_PARAMETER);
284 return FALSE;
285 }
286 /* Make sure parent is valid */
287 if (!window->IsWindow() )
288 {
289 dprintf(("Bad parent %04x\n", cs->hwndParent ));
290 SetLastError(ERROR_INVALID_PARAMETER);
291 return FALSE;
292 }
293 /* Windows does this for overlapped windows
294 * (I don't know about other styles.) */
295 if (cs->hwndParent == GetDesktopWindow() && (!(cs->style & WS_CHILD) || (cs->style & WS_POPUP)))
296 {
297 cs->hwndParent = 0;
298 }
299 }
300 else
301 if ((cs->style & WS_CHILD) && !(cs->style & WS_POPUP)) {
302 dprintf(("No parent for child window\n" ));
303 SetLastError(ERROR_INVALID_PARAMETER);
304 return FALSE; /* WS_CHILD needs a parent, but WS_POPUP doesn't */
305 }
306
307 /* Find the window class */
308 windowClass = Win32WndClass::FindClass(cs->hInstance, (LPSTR)classAtom);
309 if (!windowClass)
310 {
311 GlobalGetAtomNameA( classAtom, buffer, sizeof(buffer) );
312 dprintf(("Bad class '%s'\n", buffer ));
313 SetLastError(ERROR_INVALID_PARAMETER);
314 return 0;
315 }
316 /* Increment class window counter */
317 windowClass->IncreaseWindowCount();
318
319#ifdef DEBUG
320 if(HIWORD(cs->lpszClass))
321 {
322 char *astring;
323
324 if(isUnicode) astring = UnicodeToAsciiString((LPWSTR)cs->lpszClass);
325 else astring = (char *)cs->lpszClass;
326
327 dprintf(("Window class %s", astring));
328 if(isUnicode) FreeAsciiString(astring);
329 }
330 else dprintf(("Window class %x", cs->lpszClass));
331#endif
332
333 /* Fix the lpszClass field: from existing programs, it seems ok to call a CreateWindowXXX
334 * with an atom as the class name, put some programs expect to have a *REAL* string in
335 * lpszClass when the CREATESTRUCT is sent with WM_CREATE
336 */
337 if (!HIWORD(cs->lpszClass) ) {
338 if (isUnicode) {
339 GlobalGetAtomNameW( classAtom, (LPWSTR)buffer, sizeof(buffer) );
340 }
341 else {
342 GlobalGetAtomNameA( classAtom, buffer, sizeof(buffer) );
343 }
344 cs->lpszClass = buffer;
345 }
346
347 /* Fix the coordinates */
348 fXDefault = FALSE;
349 fCXDefault = FALSE;
350 if ((cs->x == CW_USEDEFAULT) || (cs->x == CW_USEDEFAULT16))
351 {
352 /* Never believe Microsoft's documentation... CreateWindowEx doc says
353 * that if an overlapped window is created with WS_VISIBLE style bit
354 * set and the x parameter is set to CW_USEDEFAULT, the system ignores
355 * the y parameter. However, disassembling NT implementation (WIN32K.SYS)
356 * reveals that
357 *
358 * 1) not only if checks for CW_USEDEFAULT but also for CW_USEDEFAULT16
359 * 2) it does not ignore the y parameter as the docs claim; instead, it
360 * uses it as second parameter to ShowWindow() unless y is either
361 * CW_USEDEFAULT or CW_USEDEFAULT16.
362 *
363 * The fact that we didn't do 2) caused bogus windows pop up when wine
364 * was running apps that were using this obscure feature. Example -
365 * calc.exe that comes with Win98 (only Win98, it's different from
366 * the one that comes with Win95 and NT)
367 */
368 if ((cs->y != CW_USEDEFAULT) && (cs->y != CW_USEDEFAULT16)) sw = cs->y;
369
370 /* We have saved cs->y, now we can trash it */
371 cs->x = 0;
372 cs->y = 0;
373 fXDefault = TRUE;
374 }
375 if ((cs->cx == CW_USEDEFAULT) || (cs->cx == CW_USEDEFAULT16))
376 {
377 cs->cx = 600; /* FIXME */
378 cs->cy = 400;
379 fCXDefault = TRUE;
380 }
381 if (cs->style & (WS_POPUP | WS_CHILD))
382 {
383 fXDefault = FALSE;
384 if (fCXDefault)
385 {
386 fCXDefault = FALSE;
387 cs->cx = cs->cy = 0;
388 }
389 }
390 if (fXDefault && !fCXDefault) fXDefault = FALSE; //CB: only x positioning doesn't work (calc.exe,cdrlabel.exe)
391
392 if (cs->x < 0) cs->x = 0;
393 if (cs->y < 0) cs->y = 0;
394
395 //Allocate window words
396 nrUserWindowBytes = windowClass->getExtraWndBytes();
397 if(nrUserWindowBytes) {
398 userWindowBytes = (char *)_smalloc(nrUserWindowBytes);
399 memset(userWindowBytes, 0, nrUserWindowBytes);
400 }
401
402 if ((cs->style & WS_CHILD) && cs->hwndParent)
403 {
404 SetParent(cs->hwndParent);
405// owner = GetWindowFromHandle(cs->hwndParent);
406 owner = 0;
407/* if(owner == NULL)
408 {
409 dprintf(("HwGetWindowHandleData couldn't find owner window %x!!!", cs->hwndParent));
410 SetLastError(ERROR_INVALID_WINDOW_HANDLE);
411 return FALSE;
412 }*/
413 //SvL: Shell positioning shouldn't be done for child windows! (breaks Notes)
414 fXDefault = fCXDefault = FALSE;
415 }
416 else
417 {
418 SetParent(0);
419 if (!cs->hwndParent || (cs->hwndParent == windowDesktop->getWindowHandle())) {
420 owner = NULL;
421 }
422 else
423 {
424 owner = GetWindowFromHandle(cs->hwndParent)->GetTopParent();
425 if(owner == NULL)
426 {
427 dprintf(("HwGetWindowHandleData couldn't find owner window %x!!!", cs->hwndParent));
428 SetLastError(ERROR_INVALID_WINDOW_HANDLE);
429 return FALSE;
430 }
431 }
432 }
433
434 WINPROC_SetProc((HWINDOWPROC *)&win32wndproc, windowClass->getWindowProc(), WINPROC_GetProcType(windowClass->getWindowProc()), WIN_PROC_WINDOW);
435 hInstance = cs->hInstance;
436 dwStyle = cs->style & ~WS_VISIBLE;
437 dwExStyle = cs->dwExStyle;
438
439 hwndLinkAfter = ((cs->style & (WS_CHILD|WS_MAXIMIZE)) == WS_CHILD) ? HWND_BOTTOM : HWND_TOP;
440
441 /* Correct the window style */
442 if (!(cs->style & WS_CHILD))
443 {
444 dwStyle |= WS_CLIPSIBLINGS;
445 if (!(cs->style & WS_POPUP))
446 {
447 dwStyle |= WS_CAPTION;
448 flags |= WIN_NEED_SIZE;
449 }
450 }
451 if (cs->dwExStyle & WS_EX_DLGMODALFRAME) dwStyle &= ~WS_THICKFRAME;
452
453 //copy pointer of CREATESTRUCT for usage in MsgCreate method
454 tmpcs = cs;
455
456 //Store our window object pointer in thread local memory, so PMWINDOW.CPP can retrieve it
457 TEB *teb = GetThreadTEB();
458 if(teb == NULL) {
459 dprintf(("Window creation failed - teb == NULL")); //this is VERY bad
460 ExitProcess(666);
461 return FALSE;
462 }
463
464 teb->o.odin.newWindow = (ULONG)this;
465
466 DWORD dwOSWinStyle;
467
468 OSLibWinConvertStyle(dwStyle,dwExStyle,&dwOSWinStyle);
469
470 OS2Hwnd = OSLibWinCreateWindow((getParent()) ? getParent()->getOS2WindowHandle() : OSLIB_HWND_DESKTOP,
471 dwOSWinStyle,(char *)windowNameA,
472 (owner) ? owner->getOS2WindowHandle() : ((getParent()) ? getParent()->getOS2WindowHandle() : OSLIB_HWND_DESKTOP),
473 (hwndLinkAfter == HWND_BOTTOM) ? TRUE : FALSE,
474 0, fTaskList,fXDefault | fCXDefault,windowClass->getStyle());
475 if(OS2Hwnd == 0) {
476 dprintf(("Window creation failed!! OS LastError %0x", OSLibWinGetLastError()));
477 SetLastError(ERROR_OUTOFMEMORY); //TODO: Better error
478 return FALSE;
479 }
480 OSLibWinSetVisibleRegionNotify(OS2Hwnd, TRUE);
481 fCreationFinished = TRUE; //creation done with success
482 SetLastError(0);
483 return TRUE;
484}
485//******************************************************************************
486//******************************************************************************
487BOOL Win32BaseWindow::MsgCreate(HWND hwndOS2)
488{
489 CREATESTRUCTA *cs = tmpcs; //pointer to CREATESTRUCT used in CreateWindowExA method
490 POINT maxSize, maxPos, minTrack, maxTrack;
491 HWND hwnd = getWindowHandle();
492
493 OS2Hwnd = hwndOS2;
494
495 fNoSizeMsg = TRUE;
496
497 if(OSLibWinSetWindowULong(OS2Hwnd, OFFSET_WIN32WNDPTR, (ULONG)this) == FALSE) {
498 dprintf(("WM_CREATE: WinSetWindowULong %X failed!!", OS2Hwnd));
499 SetLastError(ERROR_OUTOFMEMORY); //TODO: Better error
500 return FALSE;
501 }
502 if(OSLibWinSetWindowULong(OS2Hwnd, OFFSET_WIN32PM_MAGIC, WIN32PM_MAGIC) == FALSE) {
503 dprintf(("WM_CREATE: WinSetWindowULong2 %X failed!!", OS2Hwnd));
504 SetLastError(ERROR_OUTOFMEMORY); //TODO: Better error
505 return FALSE;
506 }
507 if(OSLibWinSetWindowULong(OS2Hwnd, OFFSET_WIN32FLAGS, 0) == FALSE) {
508 dprintf(("WM_CREATE: WinSetWindowULong2 %X failed!!", OS2Hwnd));
509 SetLastError(ERROR_OUTOFMEMORY); //TODO: Better error
510 return FALSE;
511 }
512
513 if (HOOK_IsHooked( WH_CBT ))
514 {
515 CBT_CREATEWNDA cbtc;
516 LRESULT ret;
517
518 cbtc.lpcs = cs;
519 cbtc.hwndInsertAfter = hwndLinkAfter;
520 ret = (isUnicode) ? HOOK_CallHooksW(WH_CBT, HCBT_CREATEWND, getWindowHandle(), (LPARAM)&cbtc)
521 : HOOK_CallHooksA(WH_CBT, HCBT_CREATEWND, getWindowHandle(), (LPARAM)&cbtc);
522 if(ret)
523 {
524 dprintf(("CBT-hook returned 0!!"));
525 SetLastError(ERROR_CAN_NOT_COMPLETE); //todo: wrong error
526 return FALSE;
527 }
528 //todo: if hook changes parent, we need to do so too!!!!!!!!!!
529 }
530
531 if (cs->style & WS_HSCROLL)
532 {
533 horzScrollInfo = (SCROLLBAR_INFO*)malloc(sizeof(SCROLLBAR_INFO));
534 horzScrollInfo->MinVal = horzScrollInfo->CurVal = horzScrollInfo->Page = 0;
535 horzScrollInfo->MaxVal = 100;
536 horzScrollInfo->flags = ESB_ENABLE_BOTH;
537 }
538
539 if (cs->style & WS_VSCROLL)
540 {
541 vertScrollInfo = (SCROLLBAR_INFO*)malloc(sizeof(SCROLLBAR_INFO));
542 vertScrollInfo->MinVal = vertScrollInfo->CurVal = vertScrollInfo->Page = 0;
543 vertScrollInfo->MaxVal = 100;
544 vertScrollInfo->flags = ESB_ENABLE_BOTH;
545 }
546
547 if(HIWORD(cs->lpszName))
548 {
549 if (!isUnicode)
550 {
551 wndNameLength = strlen(cs->lpszName);
552 windowNameA = (LPSTR)_smalloc(wndNameLength+1);
553 strcpy(windowNameA,cs->lpszName);
554 windowNameW = (LPWSTR)_smalloc((wndNameLength+1)*sizeof(WCHAR));
555 lstrcpyAtoW(windowNameW,windowNameA);
556 windowNameA[wndNameLength] = 0;
557 windowNameW[wndNameLength] = 0;
558 }
559 else
560 {
561 wndNameLength = lstrlenW((LPWSTR)cs->lpszName);
562 windowNameA = (LPSTR)_smalloc(wndNameLength+1);
563 lstrcpyWtoA(windowNameA,(LPWSTR)cs->lpszName);
564 windowNameW = (LPWSTR)_smalloc((wndNameLength+1)*sizeof(WCHAR));
565 lstrcpyW(windowNameW,(LPWSTR)cs->lpszName);
566 windowNameA[wndNameLength] = 0;
567 windowNameW[wndNameLength] = 0;
568 }
569 }
570
571//SvL: This completely messes up MS Word 97 (no button bar, no menu)
572#if 0
573 //adjust CW_USEDEFAULT position
574 if (fXDefault | fCXDefault)
575 {
576 RECT rect;
577
578 //SvL: Returns invalid rectangle (not the expected shell default size)
579 OSLibWinQueryWindowRect(OS2Hwnd,&rect,RELATIVE_TO_SCREEN);
580 if (getParent()) mapWin32Rect(OSLIB_HWND_DESKTOP,getParent()->getOS2WindowHandle(),&rect);
581 if (fXDefault)
582 {
583 cs->x = rect.left;
584 cs->y = rect.top;
585 if (!fCXDefault)
586 {
587 //CB: todo: adjust pos to screen rect
588 }
589 }
590 if (fCXDefault)
591 {
592 cs->cx = rect.right-rect.left;
593 cs->cy = rect.bottom-rect.top;
594 }
595 }
596#endif
597
598 fakeWinBase.hwndThis = OS2Hwnd;
599 fakeWinBase.pWindowClass = windowClass;
600
601 //Set icon from window or class
602 if (hIcon)
603 OSLibWinSetIcon(OS2Hwnd,hIcon);
604 else
605 if (windowClass->getIcon())
606 OSLibWinSetIcon(OS2Hwnd,windowClass->getIcon());
607
608 /* Get class or window DC if needed */
609 if(windowClass->getStyle() & CS_OWNDC) {
610 dprintf(("Class with CS_OWNDC style"));
611 ownDC = GetDCEx(getWindowHandle(), NULL, DCX_USESTYLE);
612 }
613 else
614 if (windowClass->getStyle() & CS_PARENTDC) {
615 fParentDC = TRUE;
616 ownDC = 0;
617 }
618 else
619 if (windowClass->getStyle() & CS_CLASSDC) {
620 dprintf(("WARNING: Class with CS_CLASSDC style!"));
621 ownDC = 0;
622 }
623 /* Set the window menu */
624 if ((dwStyle & (WS_CAPTION | WS_CHILD)) == WS_CAPTION )
625 {
626 if (cs->hMenu) {
627 ::SetMenu(getWindowHandle(), cs->hMenu);
628 }
629 else {
630 if (windowClass->getMenuNameA()) {
631 cs->hMenu = LoadMenuA(windowClass->getInstance(),windowClass->getMenuNameA());
632#if 0 //CB: hack for treeview test cases bug
633if (!cs->hMenu) cs->hMenu = LoadMenuA(windowClass->getInstance(),"MYAPP");
634#endif
635 if (cs->hMenu) ::SetMenu(getWindowHandle(), cs->hMenu );
636 }
637 }
638 }
639 else
640 {
641 setWindowId((DWORD)cs->hMenu);
642 }
643 hSysMenu = (dwStyle & WS_SYSMENU) ? MENU_GetSysMenu(Win32Hwnd,0):0;
644
645 /* Send the WM_GETMINMAXINFO message and fix the size if needed */
646 if ((cs->style & WS_THICKFRAME) || !(cs->style & (WS_POPUP | WS_CHILD)))
647 {
648 GetMinMaxInfo(&maxSize, &maxPos, &minTrack, &maxTrack);
649 if (maxSize.x < cs->cx) cs->cx = maxSize.x;
650 if (maxSize.y < cs->cy) cs->cy = maxSize.y;
651 if (cs->cx < minTrack.x) cs->cx = minTrack.x;
652 if (cs->cy < minTrack.y) cs->cy = minTrack.y;
653 }
654
655 if(cs->style & WS_CHILD)
656 {
657 if(cs->cx < 0) cs->cx = 0;
658 if(cs->cy < 0) cs->cy = 0;
659 }
660 else
661 {
662 if (cs->cx <= 0) cs->cx = 1;
663 if (cs->cy <= 0) cs->cy = 1;
664 }
665
666 //set client & window rectangles from CreateWindowEx CREATESTRUCT
667 rectWindow.left = cs->x;
668 rectWindow.right = cs->x+cs->cx;
669 rectWindow.top = cs->y;
670 rectWindow.bottom = cs->y+cs->cy;
671 rectClient = rectWindow;
672 OffsetRect(&rectClient, -rectClient.left, -rectClient.top);
673
674 /* Send the WM_CREATE message
675 * Perhaps we shouldn't allow width/height changes as well.
676 * See p327 in "Internals".
677 */
678 maxPos.x = rectWindow.left; maxPos.y = rectWindow.top;
679
680 //Note: Solitaire crashes when receiving WM_SIZE messages before WM_CREATE
681 fCreated = TRUE;
682
683 if(fTaskList) {
684 hTaskList = OSLibWinAddToTaskList(OS2Hwnd, windowNameA, (cs->style & WS_VISIBLE) ? 1 : 0);
685 }
686
687 //cs is ascii version of create structure. so use SendInternalMessageA
688 if(SendInternalMessageA(WM_NCCREATE,0,(LPARAM)cs))
689 {
690 RECT tmpRect;
691
692 //CB: recheck flags
693 if (cs->style & (WS_POPUP | WS_CHILD))
694 {
695 fXDefault = FALSE;
696 if (fCXDefault)
697 {
698 fCXDefault = FALSE;
699 cs->cx = cs->cy = 0;
700 rectWindow.right = rectWindow.left;
701 rectWindow.bottom = rectWindow.top;
702 }
703 }
704 tmpRect = rectWindow;
705
706 fCreateSetWindowPos = TRUE;
707
708 //set the window size and update the client
709 SetWindowPos(hwndLinkAfter, tmpRect.left, tmpRect.top, tmpRect.right-tmpRect.left, tmpRect.bottom-tmpRect.top,SWP_NOACTIVATE | SWP_NOREDRAW | SWP_FRAMECHANGED);
710 fNoSizeMsg = FALSE;
711 if (cs->style & WS_VISIBLE) dwStyle |= WS_VISIBLE; //program could change position in WM_CREATE
712 if( (SendInternalMessageA(WM_CREATE, 0, (LPARAM)cs )) != -1 )
713 {
714 if(!(flags & WIN_NEED_SIZE))
715 {
716 SendInternalMessageA(WM_SIZE, SIZE_RESTORED,
717 MAKELONG(rectClient.right-rectClient.left,
718 rectClient.bottom-rectClient.top));
719
720 if(!::IsWindow(hwnd))
721 {
722 dprintf(("Createwindow: WM_SIZE destroyed window"));
723 goto end;
724 }
725 SendInternalMessageA(WM_MOVE,0,MAKELONG(rectClient.left,rectClient.top));
726 if(!::IsWindow(hwnd))
727 {
728 dprintf(("Createwindow: WM_MOVE destroyed window"));
729 goto end;
730 }
731 }
732 if (getStyle() & (WS_MINIMIZE | WS_MAXIMIZE))
733 {
734 RECT newPos;
735 UINT swFlag = (getStyle() & WS_MINIMIZE) ? SW_MINIMIZE : SW_MAXIMIZE;
736 setStyle(getStyle() & ~(WS_MAXIMIZE | WS_MINIMIZE));
737 MinMaximize(swFlag, &newPos);
738 swFlag = ((getStyle() & WS_CHILD) || GetActiveWindow()) ? SWP_NOACTIVATE | SWP_NOZORDER | SWP_FRAMECHANGED
739 : SWP_NOZORDER | SWP_FRAMECHANGED;
740 SetWindowPos(0, newPos.left, newPos.top, newPos.right, newPos.bottom, swFlag);
741 if(!::IsWindow(hwnd))
742 {
743 dprintf(("Createwindow: min/max destroyed window"));
744 goto end;
745 }
746 }
747
748 if( (getStyle() & WS_CHILD) && !(getExStyle() & WS_EX_NOPARENTNOTIFY) )
749 {
750 /* Notify the parent window only */
751 if(getParent() && getParent()->IsWindowDestroyed() == FALSE)
752 {
753 getParent()->SendInternalMessageA(WM_PARENTNOTIFY, MAKEWPARAM(WM_CREATE, getWindowId()), (LPARAM)getWindowHandle());
754 }
755 if(!::IsWindow(hwnd))
756 {
757 dprintf(("Createwindow: WM_PARENTNOTIFY destroyed window"));
758 goto end;
759 }
760 }
761
762 if(cs->style & WS_VISIBLE) {
763 dwStyle &= ~WS_VISIBLE;
764 ShowWindow(sw);
765 }
766
767 /* Call WH_SHELL hook */
768 if (!(getStyle() & WS_CHILD) && !owner)
769 HOOK_CallHooksA(WH_SHELL, HSHELL_WINDOWCREATED, getWindowHandle(), 0);
770
771 SetLastError(0);
772 return TRUE;
773 }
774 }
775 dprintf(("Window creation FAILED (NCCREATE cancelled creation)"));
776 SetLastError(ERROR_OUTOFMEMORY); //TODO: Better error
777end:
778 return FALSE;
779}
780//******************************************************************************
781//******************************************************************************
782ULONG Win32BaseWindow::MsgQuit()
783{
784 return SendInternalMessageA(WM_QUIT, 0, 0);
785}
786//******************************************************************************
787//******************************************************************************
788ULONG Win32BaseWindow::MsgClose()
789{
790 return SendInternalMessageA(WM_CLOSE,0,0);
791}
792//******************************************************************************
793//******************************************************************************
794ULONG Win32BaseWindow::MsgDestroy()
795{
796 ULONG rc;
797 Win32BaseWindow *child;
798 HWND hwnd = getWindowHandle();
799
800 fIsDestroyed = TRUE;
801
802 if(fDestroyWindowCalled == FALSE)
803 {//this window was destroyed because DestroyWindow was called for it's parent
804 //so: send a WM_PARENTNOTIFY now as that hasn't happened yet
805 if((getStyle() & WS_CHILD) && !(getExStyle() & WS_EX_NOPARENTNOTIFY))
806 {
807 if(getParent() && getParent()->IsWindowDestroyed() == FALSE)
808 {
809 /* Notify the parent window only */
810 getParent()->SendMessageA(WM_PARENTNOTIFY, MAKEWPARAM(WM_DESTROY, getWindowId()), (LPARAM)getWindowHandle());
811 }
812//// else DebugInt3();
813 }
814 }
815 SendInternalMessageA(WM_DESTROY, 0, 0);
816 if(::IsWindow(hwnd) == FALSE) {
817 //object already destroyed, so return immediately
818 return 1;
819 }
820 SendInternalMessageA(WM_NCDESTROY, 0, 0);
821
822 TIMER_KillTimerFromWindow(OS2Hwnd);
823
824 if(getFirstChild() == NULL && fCreationFinished) {
825 delete this;
826 }
827 else {
828 //make sure no message can ever arrive for this window again (PM or from other win32 windows)
829 OSLibWinSetWindowULong(OS2Hwnd, OFFSET_WIN32WNDPTR, 0);
830 OSLibWinSetWindowULong(OS2Hwnd, OFFSET_WIN32PM_MAGIC, 0);
831 if(Win32Hwnd) {
832 HwFreeWindowHandle(Win32Hwnd);
833 Win32Hwnd = 0;
834 }
835 }
836 return 1;
837}
838//******************************************************************************
839//******************************************************************************
840ULONG Win32BaseWindow::MsgEnable(BOOL fEnable)
841{
842 if(fEnable) {
843 dwStyle &= ~WS_DISABLED;
844 }
845 else dwStyle |= WS_DISABLED;
846
847 return SendInternalMessageA(WM_ENABLE, fEnable, 0);
848}
849//******************************************************************************
850//TODO: SW_PARENTCLOSING/OPENING flag (lParam)
851//******************************************************************************
852ULONG Win32BaseWindow::MsgShow(BOOL fShow)
853{
854 if(fNoSizeMsg || fDestroyWindowCalled) {
855 return 1;
856 }
857
858 if(fShow) {
859 setStyle(getStyle() | WS_VISIBLE);
860 if(getStyle() & WS_MINIMIZE) {
861 return ShowWindow(SW_RESTORE);
862 }
863 }
864 else setStyle(getStyle() & ~WS_VISIBLE);
865
866 return SendInternalMessageA(WM_SHOWWINDOW, fShow, 0);
867}
868//******************************************************************************
869//******************************************************************************
870ULONG Win32BaseWindow::MsgPosChanging(LPARAM lp)
871{
872 //SvL: Notes crashes when switching views (calls DestroyWindow -> PM sends
873 // a WM_WINDOWPOSCHANGED msg -> crash)
874 if(fNoSizeMsg || fDestroyWindowCalled)
875 return 0;
876
877 return SendInternalMessageA(WM_WINDOWPOSCHANGING, 0, lp);
878}
879//******************************************************************************
880//******************************************************************************
881ULONG Win32BaseWindow::MsgPosChanged(LPARAM lp)
882{
883 //SvL: Notes crashes when switching views (calls DestroyWindow -> PM sends
884 // a WM_WINDOWPOSCHANGED msg -> crash)
885 if(fNoSizeMsg || fDestroyWindowCalled)
886 return 1;
887
888 return SendInternalMessageA(WM_WINDOWPOSCHANGED, 0, lp);
889}
890//******************************************************************************
891//******************************************************************************
892#if 0
893ULONG Win32BaseWindow::MsgMinMax()
894{
895
896}
897#endif
898//******************************************************************************
899//******************************************************************************
900ULONG Win32BaseWindow::MsgScroll(ULONG msg, ULONG scrollCode, ULONG scrollPos)
901{
902 //According to the SDK docs, the scrollbar handle (lParam) is 0 when the standard
903 //window scrollbars send these messages
904 return SendInternalMessageA(msg, MAKELONG(scrollCode, scrollPos), 0);
905}
906//******************************************************************************
907//******************************************************************************
908ULONG Win32BaseWindow::MsgHitTest(MSG *msg)
909{
910 lastHitTestVal = DispatchMsgA(msg);
911
912 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));
913
914 if (lastHitTestVal == HTTRANSPARENT)
915 return HTOS_TRANSPARENT;
916 else
917 return HTOS_NORMAL;
918}
919//******************************************************************************
920//******************************************************************************
921ULONG Win32BaseWindow::MsgActivate(BOOL fActivate, BOOL fMinimized, HWND hwnd, HWND hwndOS2Win)
922{
923 ULONG rc, procidhwnd = -1, threadidhwnd = 0;
924
925 //SvL: Don't send WM_(NC)ACTIVATE messages when the window is being destroyed
926 if(fDestroyWindowCalled) {
927 return 0;
928 }
929
930 //According to SDK docs, if app returns FALSE & window is being deactivated,
931 //default processing is cancelled
932 //TODO: According to Wine we should proceed anyway if window is sysmodal
933 if(SendInternalMessageA(WM_NCACTIVATE, fActivate, 0) == FALSE && !fActivate)
934 {
935 dprintf(("WARNING: WM_NCACTIVATE return code = FALSE -> cancel processing"));
936 return 0;
937 }
938 /* child windows get a WM_CHILDACTIVATE message */
939 if((getStyle() & (WS_CHILD | WS_POPUP)) == WS_CHILD )
940 {
941 if(fActivate) {//WM_CHILDACTIVE is for activation only
942 SendInternalMessageA(WM_CHILDACTIVATE, 0, 0L);
943 }
944 return 0;
945 }
946
947 rc = SendInternalMessageA(WM_ACTIVATE, MAKELONG((fActivate) ? WA_ACTIVE : WA_INACTIVE, fMinimized), hwnd);
948
949 if(hwndOS2Win) {
950 threadidhwnd = O32_GetWindowThreadProcessId(hwndOS2Win, &procidhwnd);
951 }
952//Warning: temporary hack to force focus to newly created window
953//RealPlayer 8 does not pass WM_ACTIVATE to defwindowproc and doesn't call
954//setfocus -> keyboard focus not set
955//TODO: Find real cause!!
956 if(GetFocus() == 0 && fActivate) {
957 if(!(getStyle() & WS_MINIMIZE))
958 SetFocus(getWindowHandle());
959 }
960//Warning: temporary hack to force focus to newly created window
961
962 if(fActivate) {
963 SendInternalMessageA(WM_ACTIVATEAPP, 1, dwThreadId); //activate; specify window thread id
964 }
965 else SendInternalMessageA(WM_ACTIVATEAPP, 0, threadidhwnd); //deactivate; specify thread id of other process
966 return rc;
967}
968//******************************************************************************
969//******************************************************************************
970ULONG Win32BaseWindow::DispatchMsgA(MSG *msg)
971{
972 return SendInternalMessageA(msg->message, msg->wParam, msg->lParam);
973}
974//******************************************************************************
975//******************************************************************************
976ULONG Win32BaseWindow::DispatchMsgW(MSG *msg)
977{
978 return SendInternalMessageW(msg->message, msg->wParam, msg->lParam);
979}
980//******************************************************************************
981//******************************************************************************
982ULONG Win32BaseWindow::MsgSetFocus(HWND hwnd)
983{
984 //SvL: Don't send WM_(NC)ACTIVATE messages when the window is being destroyed
985 if(fDestroyWindowCalled) {
986 return 0;
987 }
988
989 return SendInternalMessageA(WM_SETFOCUS, hwnd, 0);
990}
991//******************************************************************************
992//******************************************************************************
993ULONG Win32BaseWindow::MsgKillFocus(HWND hwnd)
994{
995 //SvL: Don't send WM_(NC)ACTIVATE messages when the window is being destroyed
996 if(fDestroyWindowCalled) {
997 return 0;
998 }
999 return SendInternalMessageA(WM_KILLFOCUS, hwnd, 0);
1000}
1001//******************************************************************************
1002//******************************************************************************
1003ULONG Win32BaseWindow::MsgButton(MSG *msg)
1004{
1005 BOOL fClick = FALSE;
1006
1007// dprintf(("MsgButton at (%d,%d)", msg->pt.x, msg->pt.y));
1008 switch(msg->message) {
1009 case WM_LBUTTONDBLCLK:
1010 case WM_RBUTTONDBLCLK:
1011 case WM_MBUTTONDBLCLK:
1012 if (!(windowClass && windowClass->getClassLongA(GCL_STYLE) & CS_DBLCLKS))
1013 {
1014 msg->message = msg->message - (WM_LBUTTONDBLCLK - WM_LBUTTONDOWN); //dblclick -> down
1015 MsgButton(msg);
1016 msg->message++; //button-up
1017 return MsgButton(msg);
1018 }
1019 break;
1020 case WM_NCLBUTTONDBLCLK:
1021 case WM_NCRBUTTONDBLCLK:
1022 case WM_NCMBUTTONDBLCLK:
1023 //Docs say CS_DBLCLKS style doesn't matter for non-client double clicks
1024 fClick = TRUE;
1025 break;
1026
1027 case WM_LBUTTONDOWN:
1028 case WM_RBUTTONDOWN:
1029 case WM_MBUTTONDOWN:
1030 case WM_NCLBUTTONDOWN:
1031 case WM_NCRBUTTONDOWN:
1032 case WM_NCMBUTTONDOWN:
1033 fClick = TRUE;
1034 break;
1035 }
1036
1037 if(fClick)
1038 {
1039 HWND hwndTop;
1040
1041 /* Activate the window if needed */
1042 hwndTop = (GetTopParent()) ? GetTopParent()->getWindowHandle() : 0;
1043
1044 HWND hwndActive = GetActiveWindow();
1045 if (hwndTop && (getWindowHandle() != hwndActive))
1046 {
1047 LONG ret = SendInternalMessageA(WM_MOUSEACTIVATE, hwndTop,
1048 MAKELONG( lastHitTestVal, msg->message) );
1049
1050#if 0
1051 if ((ret == MA_ACTIVATEANDEAT) || (ret == MA_NOACTIVATEANDEAT))
1052 eatMsg = TRUE;
1053#endif
1054 if(((ret == MA_ACTIVATE) || (ret == MA_ACTIVATEANDEAT))
1055 && (hwndTop != GetForegroundWindow()) )
1056 {
1057 Win32BaseWindow *win32top = Win32BaseWindow::GetWindowFromHandle(hwndTop);
1058
1059 //SvL: Calling OSLibSetActiveWindow(hwndTop); causes focus problems
1060 if (win32top) OSLibWinSetFocus(win32top->getOS2WindowHandle());
1061 }
1062 }
1063 }
1064
1065 SendInternalMessageA(WM_SETCURSOR, getWindowHandle(), MAKELONG(lastHitTestVal, msg->message));
1066
1067 return SendInternalMessageA(msg->message, msg->wParam, msg->lParam);
1068}
1069//******************************************************************************
1070//******************************************************************************
1071ULONG Win32BaseWindow::MsgPaint(ULONG tmp, ULONG select)
1072{
1073 if (select && IsWindowIconic())
1074 return SendInternalMessageA(WM_PAINTICON, 1, 0);
1075 else
1076 return SendInternalMessageA(WM_PAINT, 0, 0);
1077}
1078//******************************************************************************
1079//TODO: Is the clipper region of the window DC equal to the invalidated rectangle?
1080// (or are we simply erasing too much here)
1081//******************************************************************************
1082ULONG Win32BaseWindow::MsgEraseBackGround(HDC hdc)
1083{
1084 ULONG rc;
1085 HDC hdcErase = hdc;
1086
1087 if (hdcErase == 0)
1088 hdcErase = GetDC(getWindowHandle());
1089
1090 if(IsWindowIconic())
1091 rc = SendInternalMessageA(WM_ICONERASEBKGND, hdcErase, 0);
1092 else
1093 rc = SendInternalMessageA(WM_ERASEBKGND, hdcErase, 0);
1094 if (hdc == 0)
1095 ReleaseDC(getWindowHandle(), hdcErase);
1096 return (rc);
1097}
1098//******************************************************************************
1099//******************************************************************************
1100ULONG Win32BaseWindow::MsgMouseMove(MSG *msg)
1101{
1102 //TODO: hiword should be 0 if window enters menu mode (SDK docs)
1103 SendInternalMessageA(WM_SETCURSOR, Win32Hwnd, MAKELONG(lastHitTestVal, msg->message));
1104
1105 //translated message == WM_(NC)MOUSEMOVE
1106 return SendInternalMessageA(msg->message, msg->wParam, msg->lParam);
1107}
1108//******************************************************************************
1109//******************************************************************************
1110ULONG Win32BaseWindow::MsgChar(MSG *msg)
1111{
1112 return DispatchMsgA(msg);
1113}
1114//******************************************************************************
1115//******************************************************************************
1116ULONG Win32BaseWindow::MsgNCPaint()
1117{
1118 RECT rect;
1119
1120 if(GetOS2UpdateRect(this,&rect))
1121 {
1122 HRGN hrgn;
1123 ULONG rc;
1124 RECT client = rectClient;
1125
1126 if ((rect.left >= client.left) && (rect.left < client.right) &&
1127 (rect.right >= client.left) && (rect.right < client.right) &&
1128 (rect.top >= client.top) && (rect.top < client.bottom) &&
1129 (rect.bottom >= client.top) && (rect.bottom < client.bottom))
1130 {
1131 return 0;
1132 }
1133
1134 dprintf(("MsgNCPaint (%d,%d)(%d,%d)", rect.left, rect.top, rect.right, rect.bottom));
1135 hrgn = CreateRectRgnIndirect(&rect);
1136 if (!hrgn) return 0;
1137
1138 rc = SendInternalMessageA(WM_NCPAINT, hrgn, 0);
1139
1140 DeleteObject(hrgn);
1141
1142 return rc;
1143 }
1144 else return 0;
1145}
1146//******************************************************************************
1147//Called when either the frame's size or position has changed (lpWndPos != NULL)
1148//or when the frame layout has changed (i.e. scrollbars added/removed) (lpWndPos == NULL)
1149//******************************************************************************
1150ULONG Win32BaseWindow::MsgFormatFrame(WINDOWPOS *lpWndPos)
1151{
1152 RECT oldWindowRect = rectWindow, client = rectClient, newWindowRect;
1153 WINDOWPOS wndPos;
1154 ULONG rc;
1155
1156 if(lpWndPos)
1157 {
1158 //set new window rectangle
1159 setWindowRect(lpWndPos->x, lpWndPos->y, lpWndPos->x+lpWndPos->cx,
1160 lpWndPos->y+lpWndPos->cy);
1161 newWindowRect = rectWindow;
1162 }
1163 else {
1164 wndPos.hwnd = getWindowHandle();
1165 wndPos.hwndInsertAfter = 0;
1166 newWindowRect= rectWindow;
1167 wndPos.x = newWindowRect.left;
1168 wndPos.y = newWindowRect.top;
1169 wndPos.cx = newWindowRect.right - newWindowRect.left;
1170 wndPos.cy = newWindowRect.bottom - newWindowRect.top;
1171 wndPos.flags = SWP_FRAMECHANGED;
1172 lpWndPos = &wndPos;
1173 }
1174
1175 rc = SendNCCalcSize(TRUE, &newWindowRect, &oldWindowRect, &client, lpWndPos, &rectClient);
1176
1177 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));
1178 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));
1179
1180#if 1
1181//this doesn't always work
1182// if(!fNoSizeMsg && (client.left != rectClient.left || client.top != rectClient.top))
1183 if(!fNoSizeMsg && ((oldWindowRect.right - oldWindowRect.left < rectClient.left
1184 || oldWindowRect.bottom - oldWindowRect.top < rectClient.top) ||
1185 (EqualRect(&oldWindowRect, &rectWindow) && (client.left != rectClient.left || client.top != rectClient.top))))
1186 {
1187 Win32BaseWindow *child = (Win32BaseWindow *)getFirstChild();
1188
1189 //client rectangle has moved -> inform children
1190 dprintf(("MsgFormatFrame -> client rectangle has changed, move children"));
1191 while(child) {
1192 ::SetWindowPos(child->getWindowHandle(),
1193 HWND_TOP, child->getWindowRect()->left,
1194 child->getWindowRect()->top, 0, 0,
1195 SWP_NOACTIVATE|SWP_NOSIZE|SWP_NOZORDER);
1196 child = (Win32BaseWindow *)child->getNextChild();
1197 }
1198 }
1199#endif
1200 return rc;
1201}
1202//******************************************************************************
1203//******************************************************************************
1204ULONG Win32BaseWindow::MsgSetText(LPSTR lpsz, LONG cch)
1205{
1206 return SendInternalMessageA(WM_SETTEXT, 0, (LPARAM)lpsz);
1207}
1208//******************************************************************************
1209//******************************************************************************
1210ULONG Win32BaseWindow::MsgGetTextLength()
1211{
1212 return SendInternalMessageA(WM_GETTEXTLENGTH, 0, 0);
1213}
1214//******************************************************************************
1215//******************************************************************************
1216void Win32BaseWindow::MsgGetText(char *wndtext, ULONG textlength)
1217{
1218 SendInternalMessageA(WM_GETTEXT, textlength, (LPARAM)wndtext);
1219}
1220//******************************************************************************
1221//******************************************************************************
1222LONG Win32BaseWindow::sendHitTest(ULONG lParam)
1223{
1224 lastHitTestVal = SendInternalMessageA(WM_NCHITTEST, 0, lParam);
1225 return lastHitTestVal;
1226}
1227//******************************************************************************
1228//******************************************************************************
1229BOOL Win32BaseWindow::isMDIClient()
1230{
1231 return FALSE;
1232}
1233//******************************************************************************
1234//******************************************************************************
1235BOOL Win32BaseWindow::isMDIChild()
1236{
1237 return FALSE;
1238}
1239//******************************************************************************
1240//TODO: Not complete
1241//******************************************************************************
1242BOOL Win32BaseWindow::isFrameWindow()
1243{
1244 if(getParent() == NULL)
1245 return TRUE;
1246
1247 return FALSE;
1248}
1249//******************************************************************************
1250//******************************************************************************
1251BOOL Win32BaseWindow::isDesktopWindow()
1252{
1253 return FALSE;
1254}
1255//******************************************************************************
1256//******************************************************************************
1257BOOL Win32BaseWindow::IsWindowIconic()
1258{
1259 return ((getStyle() & WS_MINIMIZE) && windowClass->getIcon());
1260}
1261//******************************************************************************
1262//******************************************************************************
1263SCROLLBAR_INFO *Win32BaseWindow::getScrollInfo(int nBar)
1264{
1265 switch(nBar)
1266 {
1267 case SB_HORZ:
1268 if (!horzScrollInfo)
1269 {
1270 horzScrollInfo = (SCROLLBAR_INFO*)malloc(sizeof(SCROLLBAR_INFO));
1271 if (!horzScrollInfo) break;
1272 horzScrollInfo->MinVal = horzScrollInfo->CurVal = horzScrollInfo->Page = 0;
1273 horzScrollInfo->MaxVal = 100;
1274 horzScrollInfo->flags = ESB_ENABLE_BOTH;
1275 }
1276 return horzScrollInfo;
1277
1278 case SB_VERT:
1279 if (!vertScrollInfo)
1280 {
1281 vertScrollInfo = (SCROLLBAR_INFO*)malloc(sizeof(SCROLLBAR_INFO));
1282 if (!vertScrollInfo) break;
1283 vertScrollInfo->MinVal = vertScrollInfo->CurVal = vertScrollInfo->Page = 0;
1284 vertScrollInfo->MaxVal = 100;
1285 vertScrollInfo->flags = ESB_ENABLE_BOTH;
1286 }
1287 return vertScrollInfo;
1288 }
1289
1290 return NULL;
1291}
1292//******************************************************************************
1293//******************************************************************************
1294LRESULT Win32BaseWindow::DefWndControlColor(UINT ctlType, HDC hdc)
1295{
1296 //SvL: Set background color to default button color (not window (white))
1297 if(ctlType == CTLCOLOR_BTN)
1298 {
1299 SetBkColor(hdc, GetSysColor(COLOR_BTNFACE));
1300 SetTextColor(hdc, GetSysColor(COLOR_WINDOWTEXT));
1301 return GetSysColorBrush(COLOR_BTNFACE);
1302 }
1303 //SvL: Set background color to default dialog color if window is dialog
1304 if((ctlType == CTLCOLOR_DLG || ctlType == CTLCOLOR_STATIC) && IsDialog()) {
1305 SetBkColor(hdc, GetSysColor(COLOR_BTNFACE));
1306 SetTextColor(hdc, GetSysColor(COLOR_WINDOWTEXT));
1307 return GetSysColorBrush(COLOR_BTNFACE);
1308 }
1309
1310 if( ctlType == CTLCOLOR_SCROLLBAR)
1311 {
1312 HBRUSH hb = GetSysColorBrush(COLOR_SCROLLBAR);
1313 COLORREF bk = GetSysColor(COLOR_3DHILIGHT);
1314 SetTextColor( hdc, GetSysColor(COLOR_3DFACE));
1315 SetBkColor( hdc, bk);
1316
1317 /* if COLOR_WINDOW happens to be the same as COLOR_3DHILIGHT
1318 * we better use 0x55aa bitmap brush to make scrollbar's background
1319 * look different from the window background.
1320 */
1321 if (bk == GetSysColor(COLOR_WINDOW)) {
1322 return GetPattern55AABrush();
1323 }
1324
1325 UnrealizeObject( hb );
1326 return (LRESULT)hb;
1327 }
1328
1329 SetTextColor( hdc, GetSysColor(COLOR_WINDOWTEXT));
1330
1331 if ((ctlType == CTLCOLOR_EDIT) || (ctlType == CTLCOLOR_LISTBOX))
1332 {
1333 SetBkColor( hdc, GetSysColor(COLOR_WINDOW) );
1334 }
1335 else
1336 {
1337 SetBkColor( hdc, GetSysColor(COLOR_3DFACE) );
1338 return (LRESULT)GetSysColorBrush(COLOR_3DFACE);
1339 }
1340 return (LRESULT)GetSysColorBrush(COLOR_WINDOW);
1341}
1342//******************************************************************************
1343//******************************************************************************
1344LRESULT Win32BaseWindow::DefWndPrint(HDC hdc,ULONG uFlags)
1345{
1346 /*
1347 * Visibility flag.
1348 */
1349 if ( (uFlags & PRF_CHECKVISIBLE) &&
1350 !IsWindowVisible() )
1351 return 0;
1352
1353 /*
1354 * Unimplemented flags.
1355 */
1356 if ( (uFlags & PRF_CHILDREN) ||
1357 (uFlags & PRF_OWNED) ||
1358 (uFlags & PRF_NONCLIENT) )
1359 {
1360 dprintf(("WM_PRINT message with unsupported flags\n"));
1361 }
1362
1363 /*
1364 * Background
1365 */
1366 if ( uFlags & PRF_ERASEBKGND)
1367 SendInternalMessageA(WM_ERASEBKGND, (WPARAM)hdc, 0);
1368
1369 /*
1370 * Client area
1371 */
1372 if ( uFlags & PRF_CLIENT)
1373 SendInternalMessageA(WM_PRINTCLIENT, (WPARAM)hdc, PRF_CLIENT);
1374
1375
1376 return 0;
1377}
1378//******************************************************************************
1379//******************************************************************************
1380LRESULT Win32BaseWindow::DefWindowProcA(UINT Msg, WPARAM wParam, LPARAM lParam)
1381{
1382 switch(Msg)
1383 {
1384 case WM_CLOSE:
1385 dprintf(("DefWindowProcA: WM_CLOSE %x", getWindowHandle()));
1386 DestroyWindow();
1387 return 0;
1388
1389 case WM_GETTEXTLENGTH:
1390 return wndNameLength;
1391
1392 case WM_GETTEXT:
1393 if (!lParam || !wParam) return 0;
1394 if (!windowNameA) ((LPSTR)lParam)[0] = 0;
1395 else lstrcpynA((LPSTR)lParam, windowNameA, wParam);
1396 return min(wndNameLength, wParam);
1397
1398 case WM_SETTEXT:
1399 {
1400 LPCSTR lpsz = (LPCSTR)lParam;
1401
1402 if(windowNameA) free(windowNameA);
1403 if(windowNameW) free(windowNameW);
1404 if (lParam)
1405 {
1406 wndNameLength = strlen(lpsz);
1407 windowNameA = (LPSTR)_smalloc(wndNameLength+1);
1408 strcpy(windowNameA, lpsz);
1409 windowNameW = (LPWSTR)_smalloc((wndNameLength+1)*sizeof(WCHAR));
1410 lstrcpyAtoW(windowNameW, windowNameA);
1411 }
1412 else
1413 {
1414 windowNameA = NULL;
1415 windowNameW = NULL;
1416 wndNameLength = 0;
1417 }
1418 dprintf(("WM_SETTEXT of %x to %s\n", Win32Hwnd, lParam));
1419 if ((dwStyle & WS_CAPTION) == WS_CAPTION)
1420 {
1421 HandleNCPaint((HRGN)1);
1422 if(hTaskList) {
1423 OSLibWinChangeTaskList(hTaskList, OS2Hwnd, getWindowNameA(), (getStyle() & WS_VISIBLE) ? 1 : 0);
1424 }
1425 }
1426
1427 return TRUE;
1428 }
1429
1430 case WM_SETREDRAW:
1431 {
1432 if (wParam)
1433 {
1434 setStyle(getStyle() | WS_VISIBLE);
1435 OSLibWinEnableWindowUpdate(OS2Hwnd,TRUE);
1436 }
1437 else
1438 {
1439 if (getStyle() & WS_VISIBLE)
1440 {
1441 setStyle(getStyle() & ~WS_VISIBLE);
1442 OSLibWinEnableWindowUpdate(OS2Hwnd,FALSE);
1443 }
1444 }
1445 return 0;
1446 }
1447
1448 case WM_CTLCOLORMSGBOX:
1449 case WM_CTLCOLOREDIT:
1450 case WM_CTLCOLORLISTBOX:
1451 case WM_CTLCOLORBTN:
1452 case WM_CTLCOLORDLG:
1453 case WM_CTLCOLORSTATIC:
1454 case WM_CTLCOLORSCROLLBAR:
1455 return DefWndControlColor(Msg - WM_CTLCOLORMSGBOX, (HDC)wParam);
1456
1457 case WM_CTLCOLOR:
1458 return DefWndControlColor(HIWORD(lParam), (HDC)wParam);
1459
1460 case WM_VKEYTOITEM:
1461 case WM_CHARTOITEM:
1462 return -1;
1463
1464 case WM_PARENTNOTIFY:
1465 return 0;
1466
1467 case WM_MOUSEACTIVATE:
1468 {
1469 dprintf(("DefWndProc: WM_MOUSEACTIVATE for %x Msg %s", Win32Hwnd, GetMsgText(HIWORD(lParam))));
1470 if(getStyle() & WS_CHILD && !(getExStyle() & WS_EX_NOPARENTNOTIFY) )
1471 {
1472 if(getParent()) {
1473 LRESULT rc = getParent()->SendInternalMessageA(WM_MOUSEACTIVATE, wParam, lParam );
1474 if(rc) return rc;
1475 }
1476 }
1477 return (LOWORD(lParam) == HTCAPTION) ? MA_NOACTIVATE : MA_ACTIVATE;
1478 }
1479
1480 case WM_ACTIVATE:
1481 /* The default action in Windows is to set the keyboard focus to
1482 * the window, if it's being activated and not minimized */
1483 if (LOWORD(wParam) != WA_INACTIVE) {
1484 if(!(getStyle() & WS_MINIMIZE))
1485 SetFocus(getWindowHandle());
1486 }
1487 return 0;
1488
1489 case WM_SETCURSOR:
1490 {
1491 dprintf(("DefWndProc: WM_SETCURSOR for %x Msg %s", Win32Hwnd, GetMsgText(HIWORD(lParam))));
1492 if((getStyle() & WS_CHILD))
1493 {
1494 if(getParent()) {
1495 LRESULT rc = getParent()->SendInternalMessageA(WM_SETCURSOR, wParam, lParam);
1496 if(rc) return rc;
1497 }
1498 }
1499 if (wParam == getWindowHandle())
1500 {
1501 HCURSOR hCursor;
1502
1503 switch(LOWORD(lParam))
1504 {
1505 case HTCLIENT:
1506 hCursor = windowClass ? windowClass->getCursor():LoadCursorA(0,IDC_ARROWA);
1507 break;
1508
1509 case HTLEFT:
1510 case HTRIGHT:
1511 hCursor = LoadCursorA(0,IDC_SIZEWEA);
1512 break;
1513
1514 case HTTOP:
1515 case HTBOTTOM:
1516 hCursor = LoadCursorA(0,IDC_SIZENSA);
1517 break;
1518
1519 case HTTOPLEFT:
1520 case HTBOTTOMRIGHT:
1521 hCursor = LoadCursorA(0,IDC_SIZENWSEA);
1522 break;
1523
1524 case HTTOPRIGHT:
1525 case HTBOTTOMLEFT:
1526 hCursor = LoadCursorA(0,IDC_SIZENESWA);
1527 break;
1528
1529 default:
1530 hCursor = LoadCursorA(0,IDC_ARROWA);
1531 break;
1532 }
1533
1534 if (hCursor)
1535 {
1536 SetCursor(hCursor);
1537 return 1;
1538 }
1539 else return 0;
1540 }
1541 else return 0;
1542 }
1543
1544 case WM_MOUSEMOVE:
1545 return 0;
1546
1547 case WM_WINDOWPOSCHANGED:
1548 {
1549 PWINDOWPOS wpos = (PWINDOWPOS)lParam;
1550 WPARAM wp = SIZE_RESTORED;
1551
1552 if (!(wpos->flags & SWP_NOMOVE) && !(wpos->flags & SWP_NOCLIENTMOVE))
1553 {
1554 SendInternalMessageA(WM_MOVE, 0, MAKELONG(rectClient.left,rectClient.top));
1555 }
1556 if (!(wpos->flags & SWP_NOSIZE) && !(wpos->flags & SWP_NOCLIENTSIZE))
1557 {
1558 if (dwStyle & WS_MAXIMIZE) wp = SIZE_MAXIMIZED;
1559 else
1560 if (dwStyle & WS_MINIMIZE) wp = SIZE_MINIMIZED;
1561
1562 SendInternalMessageA(WM_SIZE, wp, MAKELONG(rectClient.right - rectClient.left,
1563 rectClient.bottom - rectClient.top));
1564 }
1565 return 0;
1566 }
1567 case WM_WINDOWPOSCHANGING:
1568 return HandleWindowPosChanging((WINDOWPOS *)lParam);
1569
1570 case WM_ERASEBKGND:
1571 case WM_ICONERASEBKGND:
1572 {
1573 RECT rect;
1574 int rc;
1575
1576 if (!windowClass || !windowClass->getBackgroundBrush()) return 0;
1577
1578 rc = GetClipBox( (HDC)wParam, &rect );
1579 if ((rc == SIMPLEREGION) || (rc == COMPLEXREGION))
1580 {
1581 HBRUSH hBrush = windowClass->getBackgroundBrush();
1582
1583 if (hBrush <= (HBRUSH)(SYSCOLOR_GetLastColor()+1))
1584 hBrush = GetSysColorBrush(hBrush-1);
1585
1586 FillRect( (HDC)wParam, &rect, hBrush);
1587 }
1588 return 1;
1589 }
1590
1591 case WM_PRINT:
1592 return DefWndPrint(wParam,lParam);
1593
1594 case WM_PAINTICON:
1595 case WM_PAINT:
1596 {
1597 PAINTSTRUCT ps;
1598 HDC hdc = BeginPaint(getWindowHandle(), &ps );
1599 if( hdc )
1600 {
1601 if( (getStyle() & WS_MINIMIZE) && (getWindowClass()->getIcon() || hIcon))
1602 {
1603 int x = (rectWindow.right - rectWindow.left - GetSystemMetrics(SM_CXICON))/2;
1604 int y = (rectWindow.bottom - rectWindow.top - GetSystemMetrics(SM_CYICON))/2;
1605 dprintf(("Painting class icon: vis rect=(%i,%i - %i,%i)\n", ps.rcPaint.left, ps.rcPaint.top, ps.rcPaint.right, ps.rcPaint.bottom ));
1606 DrawIcon(hdc, x, y, hIcon ? hIcon:getWindowClass()->getIcon() );
1607 }
1608 EndPaint(getWindowHandle(), &ps );
1609 }
1610 return 0;
1611 }
1612
1613 case WM_GETDLGCODE:
1614 return 0;
1615
1616 case WM_NCPAINT:
1617 return HandleNCPaint((HRGN)wParam);
1618
1619 case WM_NCACTIVATE:
1620 return HandleNCActivate(wParam);
1621
1622 case WM_NCCREATE:
1623 return(TRUE);
1624
1625 case WM_NCDESTROY:
1626 return 0;
1627
1628 case WM_NCCALCSIZE:
1629 return HandleNCCalcSize((BOOL)wParam,(RECT*)lParam);
1630
1631 case WM_NCLBUTTONDOWN:
1632 return HandleNCLButtonDown(wParam,lParam);
1633
1634 case WM_LBUTTONDBLCLK:
1635 case WM_NCLBUTTONDBLCLK:
1636 return HandleNCLButtonDblClk(wParam,lParam);
1637
1638 case WM_NCRBUTTONDOWN:
1639 case WM_NCRBUTTONDBLCLK:
1640 case WM_NCMBUTTONDOWN:
1641 case WM_NCMBUTTONDBLCLK:
1642 if (lastHitTestVal == HTERROR) MessageBeep(MB_ICONEXCLAMATION);
1643 return 0;
1644
1645 case WM_NCRBUTTONUP:
1646 return HandleNCRButtonUp(wParam,lParam);
1647
1648 case WM_NCMBUTTONUP:
1649 return 0;
1650
1651 case WM_NCHITTEST:
1652 {
1653 POINT point;
1654 LRESULT retvalue;
1655
1656 point.x = (SHORT)LOWORD(lParam);
1657 point.y = (SHORT)HIWORD(lParam);
1658
1659 retvalue = HandleNCHitTest(point);
1660#if 0 //CB: let the Corel people fix the bugs first
1661 if(retvalue == HTMENU)
1662 MENU_TrackMouseMenuBar_MouseMove(Win32Hwnd,point,TRUE);
1663 else
1664 MENU_TrackMouseMenuBar_MouseMove(Win32Hwnd,point,FALSE);
1665#endif
1666 return retvalue;
1667 }
1668
1669 case WM_SYSCOMMAND:
1670 {
1671 POINT point;
1672
1673 point.x = LOWORD(lParam);
1674 point.y = HIWORD(lParam);
1675 return HandleSysCommand(wParam,&point);
1676 }
1677
1678 case WM_SYSKEYDOWN:
1679 if(wParam == VK_F4) /* try to close the window */
1680 {
1681 Win32BaseWindow *window = GetTopParent();
1682 if(window && !(window->getClass()->getStyle() & CS_NOCLOSE))
1683 PostMessageA(window->getWindowHandle(), WM_SYSCOMMAND, SC_CLOSE, 0);
1684 return 0;
1685 }
1686
1687 Win32BaseWindow *siblingWindow;
1688 HWND sibling;
1689 char nameBuffer [40], mnemonic;
1690 int nameLength;
1691
1692 GetWindowTextA (nameBuffer, 40);
1693
1694 // search all sibling to see it this key is their mnemonic
1695 sibling = GetWindow (GW_HWNDFIRST);
1696 while (sibling != 0) {
1697 siblingWindow = GetWindowFromHandle (sibling);
1698 nameLength = siblingWindow->GetWindowTextA (nameBuffer, 40);
1699
1700 // find the siblings mnemonic
1701 mnemonic = '\0';
1702 for (int i=0 ; i<nameLength ; i++) {
1703 if (nameBuffer [i] == '&') {
1704 mnemonic = nameBuffer [i+1];
1705 if ((mnemonic >= 'a') && (mnemonic <= 'z'))
1706 mnemonic -= 32; // make it uppercase
1707 break; // stop searching
1708 }
1709 }
1710
1711 // key matches siblings mnemonic, send mouseclick
1712 if (mnemonic == (char) wParam) {
1713 siblingWindow->SendInternalMessageA (BM_CLICK, 0, 0);
1714 }
1715
1716 sibling = siblingWindow->GetNextWindow (GW_HWNDNEXT);
1717 }
1718
1719 return 0;
1720
1721#if 0 //CB: todo: MSDN docu: Windown handles these messages and not WM_SYSCHAR (the code below doesn't work)
1722 case WM_KEYDOWN:
1723 case WM_KEYUP:
1724 case WM_SYSKEYDOWN:
1725 case WM_SYSKEYUP:
1726#endif
1727
1728 case WM_SYSCHAR:
1729 {
1730 int iMenuSysKey = 0;
1731 if (wParam == VK_RETURN && (getStyle() & WS_MINIMIZE))
1732 {
1733 PostMessageA(getWindowHandle(), WM_SYSCOMMAND,
1734 (WPARAM)SC_RESTORE, 0L );
1735 break;
1736 }
1737 if((HIWORD(lParam) & KEYDATA_ALT) && wParam)
1738 {
1739 if (wParam == VK_TAB || wParam == VK_ESCAPE || wParam == VK_F4)
1740 break;
1741 if (wParam == VK_SPACE && (getStyle() & WS_CHILD)) {
1742 getParent()->SendMessageA(Msg, wParam, lParam );
1743 }
1744 else SendMessageA(WM_SYSCOMMAND, (WPARAM)SC_KEYMENU, (LPARAM)(DWORD)wParam );
1745 }
1746#if 0
1747 else /* check for Ctrl-Esc */
1748 if (wParam != VK_ESCAPE) MessageBeep(0);
1749 break;
1750#endif
1751 }
1752
1753 case WM_SETHOTKEY:
1754 hotkey = wParam;
1755 return 1; //CB: always successful
1756
1757 case WM_GETHOTKEY:
1758 return hotkey;
1759
1760 case WM_CONTEXTMENU:
1761 if ((dwStyle & WS_CHILD) && getParent())
1762 getParent()->SendInternalMessageA(WM_CONTEXTMENU,wParam,lParam);
1763 return 0;
1764
1765 case WM_SHOWWINDOW:
1766 if (!lParam) return 0; /* sent from ShowWindow */
1767 if (!(dwStyle & WS_POPUP) || !owner) return 0;
1768 if ((dwStyle & WS_VISIBLE) && wParam) return 0;
1769 else if (!(dwStyle & WS_VISIBLE) && !wParam) return 0;
1770 ShowWindow(wParam ? SW_SHOW:SW_HIDE);
1771 return 0;
1772
1773 case WM_CANCELMODE:
1774 if (getParent() == windowDesktop) EndMenu();
1775 if (GetCapture() == Win32Hwnd) ReleaseCapture();
1776 return 0;
1777
1778 case WM_DROPOBJECT:
1779 return DRAG_FILE;
1780
1781 case WM_QUERYDROPOBJECT:
1782 return (dwExStyle & WS_EX_ACCEPTFILES) ? 1:0;
1783
1784 case WM_QUERYDRAGICON:
1785 {
1786 HICON hDragIcon = windowClass->getCursor();
1787 UINT len;
1788
1789 if(hDragIcon) return (LRESULT)hDragIcon;
1790 for(len = 1; len < 64; len++)
1791 {
1792 hDragIcon = LoadIconA(hInstance,MAKEINTRESOURCEA(len));
1793 if(hDragIcon)
1794 return (LRESULT)hDragIcon;
1795 }
1796 return (LRESULT)LoadIconA(0,IDI_APPLICATIONA);
1797 }
1798
1799 case WM_QUERYOPEN:
1800 case WM_QUERYENDSESSION:
1801 return 1;
1802
1803 case WM_NOTIFYFORMAT:
1804 return IsWindowUnicode() ? NFR_UNICODE:NFR_ANSI;
1805
1806 case WM_SETICON:
1807 case WM_GETICON:
1808 {
1809 LRESULT result = 0;
1810
1811 /* Set the appropriate icon members in the window structure. */
1812 if (wParam == ICON_SMALL)
1813 {
1814 result = hIconSm;
1815 if (Msg == WM_SETICON)
1816 hIconSm = (HICON)lParam;
1817 }
1818 else
1819 {
1820 result = hIcon;
1821 if (Msg == WM_SETICON)
1822 {
1823 hIcon = (HICON)lParam;
1824 if ((dwStyle & WS_CAPTION) == WS_CAPTION)
1825 OSLibWinSetIcon(OS2Hwnd,hIcon);
1826 }
1827 }
1828 if ((Msg == WM_SETICON) && ((dwStyle & WS_CAPTION) == WS_CAPTION))
1829 HandleNCPaint((HRGN)1);
1830
1831 return result;
1832 }
1833
1834 case WM_HELP:
1835 if (getParent()) getParent()->SendInternalMessageA(Msg,wParam,lParam);
1836 break;
1837
1838 case WM_NOTIFY:
1839 return 0; //comctl32 controls expect this
1840
1841 default:
1842 return 0;
1843 }
1844 return 0;
1845}
1846//******************************************************************************
1847//******************************************************************************
1848LRESULT Win32BaseWindow::DefWindowProcW(UINT Msg, WPARAM wParam, LPARAM lParam)
1849{
1850 switch(Msg)
1851 {
1852 case WM_GETTEXTLENGTH:
1853 return wndNameLength;
1854
1855 case WM_GETTEXT:
1856 if (!lParam || !wParam) return 0;
1857 if (!windowNameW) ((LPWSTR)lParam)[0] = 0;
1858 else lstrcpynW((LPWSTR)lParam,windowNameW,wParam);
1859 return min(wndNameLength,wParam);
1860
1861 case WM_SETTEXT:
1862 {
1863 LPWSTR lpsz = (LPWSTR)lParam;
1864
1865 if(windowNameA) free(windowNameA);
1866 if(windowNameW) free(windowNameW);
1867 if (lParam)
1868 {
1869 wndNameLength = lstrlenW(lpsz);
1870 windowNameA = (LPSTR)_smalloc(wndNameLength+1);
1871 lstrcpyWtoA(windowNameA,lpsz);
1872 windowNameW = (LPWSTR)_smalloc((wndNameLength+1)*sizeof(WCHAR));
1873 lstrcpyW(windowNameW,lpsz);
1874 }
1875 else
1876 {
1877 windowNameA = NULL;
1878 windowNameW = NULL;
1879 wndNameLength = 0;
1880 }
1881 dprintf(("WM_SETTEXT of %x\n",Win32Hwnd));
1882 if ((dwStyle & WS_CAPTION) == WS_CAPTION)
1883 {
1884 HandleNCPaint((HRGN)1);
1885 if(hTaskList) {
1886 OSLibWinChangeTaskList(hTaskList, OS2Hwnd, getWindowNameA(), (getStyle() & WS_VISIBLE) ? 1 : 0);
1887 }
1888 }
1889
1890 return TRUE;
1891 }
1892
1893 default:
1894 return DefWindowProcA(Msg, wParam, lParam);
1895 }
1896}
1897//******************************************************************************
1898//******************************************************************************
1899LRESULT Win32BaseWindow::SendMessageA(ULONG Msg, WPARAM wParam, LPARAM lParam)
1900{
1901 //if the destination window is created by this process & thread, call window proc directly
1902 if(dwProcessId == currentProcessId && dwThreadId == GetCurrentThreadId()) {
1903 return SendInternalMessageA(Msg, wParam, lParam);
1904 }
1905 //otherwise use WinSendMsg to send it to the right process/thread
1906 dprintf(("SendMessages (inter-process) %x %x %x %x", getWindowHandle(), Msg, wParam, lParam));
1907 return OSLibSendMessage(getOS2WindowHandle(), Msg, wParam, lParam, FALSE);
1908}
1909//******************************************************************************
1910//******************************************************************************
1911LRESULT Win32BaseWindow::SendMessageW(ULONG Msg, WPARAM wParam, LPARAM lParam)
1912{
1913 //if the destination window is created by this process & thread, call window proc directly
1914 if(dwProcessId == currentProcessId && dwThreadId == GetCurrentThreadId()) {
1915 return SendInternalMessageW(Msg, wParam, lParam);
1916 }
1917 //otherwise use WinSendMsg to send it to the right process/thread
1918 return OSLibSendMessage(getOS2WindowHandle(), Msg, wParam, lParam, TRUE);
1919}
1920//******************************************************************************
1921//Called as a result of an OS/2 message or called from a class method
1922//******************************************************************************
1923LRESULT Win32BaseWindow::SendInternalMessageA(ULONG Msg, WPARAM wParam, LPARAM lParam)
1924{
1925 LRESULT rc;
1926 HWND hwnd = getWindowHandle();
1927 BOOL fInternalMsgBackup = fInternalMsg;
1928
1929 //if the destination window was created by this process & thread, call window proc directly
1930 if(dwProcessId != currentProcessId || dwThreadId != GetCurrentThreadId()) {
1931 dprintf(("SendMessages (inter-process) %x %x %x %x", getWindowHandle(), Msg, wParam, lParam));
1932 return OSLibSendMessage(getOS2WindowHandle(), Msg, wParam, lParam, FALSE);
1933 }
1934
1935 DebugPrintMessage(getWindowHandle(), Msg, wParam, lParam, FALSE, TRUE);
1936
1937 CallWindowHookProc(WH_CALLWNDPROC, Msg, wParam, lParam, FALSE);
1938
1939 fInternalMsg = TRUE;
1940 switch(Msg)
1941 {
1942 case WM_CREATE:
1943 {
1944 if(CallWindowProcA(win32wndproc, getWindowHandle(), WM_CREATE, 0, lParam) == -1) {
1945 dprintf(("WM_CREATE returned -1\n"));
1946 rc = -1; //don't create window
1947 break;
1948 }
1949 rc = 0;
1950 break;
1951 }
1952 case WM_LBUTTONDOWN:
1953 case WM_MBUTTONDOWN:
1954 case WM_RBUTTONDOWN:
1955 {
1956 if (getParent())
1957 {
1958 POINTS pt = MAKEPOINTS(lParam);
1959 POINT point;
1960
1961 point.x = pt.x;
1962 point.y = pt.y;
1963 MapWindowPoints(getWindowHandle(), getParent()->getWindowHandle(), &point, 1);
1964 NotifyParent(Msg,wParam,MAKELPARAM(point.x,point.y));
1965 }
1966 rc = win32wndproc(getWindowHandle(), Msg, wParam, lParam);
1967 break;
1968 }
1969
1970 case WM_DESTROY:
1971 rc = win32wndproc(getWindowHandle(), WM_DESTROY, 0, 0);
1972 break;
1973
1974 default:
1975 rc = CallWindowProcA(win32wndproc, getWindowHandle(), Msg, wParam, lParam);
1976 break;
1977 }
1978 if(!::IsWindow(hwnd)) {
1979 //window might have been destroyed by now. (this pointer invalid)
1980 //we must return immediately
1981 //(MS Visual C++ install heap corruption)
1982 //TODO: could happen in several places here!!!!
1983 return rc;
1984 }
1985 fInternalMsg = fInternalMsgBackup;
1986 return rc;
1987}
1988//******************************************************************************
1989//Called as a result of an OS/2 message or called from a class method
1990//******************************************************************************
1991LRESULT Win32BaseWindow::SendInternalMessageW(ULONG Msg, WPARAM wParam, LPARAM lParam)
1992{
1993 LRESULT rc;
1994 HWND hwnd = getWindowHandle();
1995 BOOL fInternalMsgBackup = fInternalMsg;
1996
1997 //if the destination window was created by this process & thread, call window proc directly
1998 if(dwProcessId != currentProcessId || dwThreadId != GetCurrentThreadId()) {
1999 dprintf(("SendMessages (inter-process) %x %x %x %x", getWindowHandle(), Msg, wParam, lParam));
2000 return OSLibSendMessage(getOS2WindowHandle(), Msg, wParam, lParam, FALSE);
2001 }
2002
2003 DebugPrintMessage(getWindowHandle(), Msg, wParam, lParam, TRUE, TRUE);
2004
2005 CallWindowHookProc(WH_CALLWNDPROC, Msg, wParam, lParam, TRUE);
2006
2007 fInternalMsg = TRUE;
2008 switch(Msg)
2009 {
2010 case WM_CREATE:
2011 {
2012 if(CallWindowProcW(win32wndproc, getWindowHandle(), WM_CREATE, 0, lParam) == -1) {
2013 dprintf(("WM_CREATE returned -1\n"));
2014 rc = -1; //don't create window
2015 break;
2016 }
2017 rc = 0;
2018 break;
2019 }
2020 case WM_LBUTTONDOWN:
2021 case WM_MBUTTONDOWN:
2022 case WM_RBUTTONDOWN:
2023 NotifyParent(Msg, wParam, lParam);
2024 rc = win32wndproc(getWindowHandle(), Msg, wParam, lParam);
2025 break;
2026
2027 case WM_DESTROY:
2028 rc = win32wndproc(getWindowHandle(), WM_DESTROY, 0, 0);
2029 break;
2030 default:
2031 rc = CallWindowProcW(win32wndproc, getWindowHandle(), Msg, wParam, lParam);
2032 break;
2033 }
2034 if(!::IsWindow(hwnd)) {
2035 //window might have been destroyed by now. (this pointer invalid)
2036 //we must return immediately
2037 //(MS Visual C++ install heap corruption)
2038 //TODO: could happen in several places here!!!!
2039 return rc;
2040 }
2041 fInternalMsg = fInternalMsgBackup;
2042 return rc;
2043}
2044//******************************************************************************
2045//******************************************************************************
2046void Win32BaseWindow::CallWindowHookProc(ULONG hooktype, ULONG Msg, WPARAM wParam, LPARAM lParam, BOOL fUnicode)
2047{
2048 CWPSTRUCT cwp;
2049
2050 cwp.lParam = lParam;
2051 cwp.wParam = wParam;
2052 cwp.message = Msg;
2053 cwp.hwnd = getWindowHandle();
2054
2055 switch(hooktype) {
2056 case WH_CALLWNDPROC:
2057 if(fUnicode) {
2058 HOOK_CallHooksW(WH_CALLWNDPROC, HC_ACTION, 1, (LPARAM)&cwp);
2059 }
2060 else HOOK_CallHooksA(WH_CALLWNDPROC, HC_ACTION, 1, (LPARAM)&cwp);
2061 break;
2062 }
2063}
2064//******************************************************************************
2065//TODO: Do this more efficiently
2066//******************************************************************************
2067LRESULT Win32BaseWindow::BroadcastMessageA(int type, UINT msg, WPARAM wParam, LPARAM lParam)
2068{
2069 Win32BaseWindow *window;
2070 HWND hwnd = WNDHANDLE_MAGIC_HIGHWORD;
2071
2072 dprintf(("BroadCastMessageA %x %x %x", msg, wParam, lParam, GetFS()));
2073
2074 for(int i=0;i<MAX_WINDOW_HANDLES;i++) {
2075 window = GetWindowFromHandle(hwnd++);
2076 if(window) {
2077 if ((window->getStyle() & WS_POPUP) || ((window->getStyle() & WS_CAPTION) == WS_CAPTION))
2078 {
2079 if(type == BROADCAST_SEND) {
2080 ::SendMessageA(window->getWindowHandle(), msg, wParam, lParam);
2081 }
2082 else PostMessageA(window->getWindowHandle(), msg, wParam, lParam);
2083 }
2084 }
2085 }
2086 return 0;
2087}
2088//******************************************************************************
2089//TODO: Do this more efficiently
2090//******************************************************************************
2091LRESULT Win32BaseWindow::BroadcastMessageW(int type, UINT msg, WPARAM wParam, LPARAM lParam)
2092{
2093 Win32BaseWindow *window;
2094 HWND hwnd = WNDHANDLE_MAGIC_HIGHWORD;
2095
2096 dprintf(("BroadCastMessageW %x %x %x", msg, wParam, lParam));
2097
2098 for(int i=0;i<MAX_WINDOW_HANDLES;i++) {
2099 window = GetWindowFromHandle(hwnd++);
2100 if(window) {
2101 if ((window->getStyle() & WS_POPUP) || ((window->getStyle() & WS_CAPTION) == WS_CAPTION))
2102 {
2103 if(type == BROADCAST_SEND) {
2104 ::SendMessageW(window->getWindowHandle(), msg, wParam, lParam);
2105 }
2106 else PostMessageW(window->getWindowHandle(), msg, wParam, lParam);
2107 }
2108 }
2109 }
2110 return 0;
2111}
2112//******************************************************************************
2113//******************************************************************************
2114void Win32BaseWindow::NotifyParent(UINT Msg, WPARAM wParam, LPARAM lParam)
2115{
2116 Win32BaseWindow *window = this;
2117 Win32BaseWindow *parentwindow;
2118
2119 while(window)
2120 {
2121 if(window->getStyle() & WS_CHILD && !(window->getExStyle() & WS_EX_NOPARENTNOTIFY) )
2122 {
2123 /* Notify the parent window only */
2124 parentwindow = window->getParent();
2125 if(parentwindow) {
2126 parentwindow->SendInternalMessageA(WM_PARENTNOTIFY, MAKEWPARAM(Msg, getWindowId()), lParam );
2127 }
2128 }
2129 else break;
2130
2131 window = parentwindow;
2132 }
2133}
2134//******************************************************************************
2135// Returns the big or small icon for the window, falling back to the
2136// class as windows does.
2137//******************************************************************************
2138HICON Win32BaseWindow::IconForWindow(WPARAM fType)
2139{
2140 HICON hWndIcon;
2141
2142 if (fType == ICON_BIG)
2143 {
2144 if (hIcon)
2145 hWndIcon = hIcon;
2146 else
2147 if (windowClass && windowClass->getIcon())
2148 hWndIcon = windowClass->getIcon();
2149 else
2150 if (!(dwStyle & DS_MODALFRAME))
2151 hWndIcon = LoadImageA(0,MAKEINTRESOURCEA(OIC_ODINICON),IMAGE_ICON,0,0,LR_DEFAULTCOLOR);
2152 else hWndIcon = 0;
2153 }
2154 else
2155 {
2156 if (hIconSm)
2157 hWndIcon = hIconSm;
2158 else
2159 if (hIcon)
2160 hWndIcon = hIcon;
2161 else
2162 if (windowClass && windowClass->getIconSm())
2163 hWndIcon = windowClass->getIconSm();
2164 else
2165 if (windowClass && windowClass->getIcon())
2166 hWndIcon = windowClass->getIcon();
2167 else
2168 if (!(dwStyle & DS_MODALFRAME))
2169 hWndIcon = LoadImageA(0,MAKEINTRESOURCEA(OIC_ODINICON),IMAGE_ICON,0,0,LR_DEFAULTCOLOR);
2170 else hWndIcon = 0;
2171 }
2172
2173 return hWndIcon;
2174}
2175//******************************************************************************
2176//******************************************************************************
2177BOOL Win32BaseWindow::ShowWindow(ULONG nCmdShow)
2178{
2179 ULONG swp = 0;
2180 HWND hWinAfter;
2181 BOOL rc,wasVisible,showFlag;
2182 RECT newPos = {0, 0, 0, 0};
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 if(!(getStyle() & WS_CHILD))
2203 {
2204 if( !(getStyle() & WS_MINIMIZE) )
2205 swp |= MinMaximize(SW_MINIMIZE, &newPos );
2206
2207 swp |= SWP_NOSIZE | SWP_NOMOVE | SWP_HIDEWINDOW;
2208 }
2209 else {
2210 swp |= SWP_FRAMECHANGED;
2211 if( !(getStyle() & WS_MINIMIZE) ) {
2212 swp |= MinMaximize(SW_MINIMIZE, &newPos );
2213 fMinMaxChange = TRUE; //-> invalidate entire window in WM_CALCINVALIDRECT
2214 }
2215 else swp |= SWP_NOSIZE | SWP_NOMOVE;
2216 }
2217 break;
2218
2219 case SW_SHOWMAXIMIZED: /* same as SW_MAXIMIZE */
2220 swp |= SWP_SHOWWINDOW | SWP_FRAMECHANGED;
2221 if( !(getStyle() & WS_MAXIMIZE) ) {
2222 swp |= MinMaximize(SW_MAXIMIZE, &newPos );
2223 fMinMaxChange = TRUE; //-> invalidate entire window in WM_CALCINVALIDRECT
2224 }
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 fMinMaxChange = TRUE; //-> invalidate entire window in WM_CALCINVALIDRECT
2258 }
2259 else swp |= SWP_NOSIZE | SWP_NOMOVE;
2260 break;
2261 }
2262
2263 showFlag = (nCmdShow != SW_HIDE);
2264 if (showFlag != wasVisible)
2265 {
2266 SendInternalMessageA(WM_SHOWWINDOW, showFlag, 0 );
2267 if (!::IsWindow( getWindowHandle() )) goto END;
2268 }
2269
2270 /* We can't activate a child window */
2271 if((getStyle() & WS_CHILD) && !(getExStyle() & WS_EX_MDICHILD))
2272 swp |= SWP_NOACTIVATE | SWP_NOZORDER;
2273
2274 SetWindowPos(HWND_TOP, newPos.left, newPos.top, newPos.right, newPos.bottom, LOWORD(swp));
2275
2276 if(!(swp & SWP_NOACTIVATE)) {
2277 OSLibWinSetActiveWindow(OS2Hwnd);
2278 }
2279
2280 if (flags & WIN_NEED_SIZE)
2281 {
2282 /* should happen only in CreateWindowEx() */
2283 int wParam = SIZE_RESTORED;
2284
2285 flags &= ~WIN_NEED_SIZE;
2286 if (dwStyle & WS_MAXIMIZE)
2287 wParam = SIZE_MAXIMIZED;
2288 else
2289 if (dwStyle & WS_MINIMIZE)
2290 wParam = SIZE_MINIMIZED;
2291
2292 SendInternalMessageA(WM_SIZE, wParam,
2293 MAKELONG(rectClient.right-rectClient.left,
2294 rectClient.bottom-rectClient.top));
2295 SendInternalMessageA(WM_MOVE,0,MAKELONG(rectClient.left,rectClient.top));
2296 }
2297END:
2298 fMinMaxChange = FALSE;
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 //Calculate invalid areas
2522 rect = rectWindow;
2523 OffsetRect(&rect, -rectWindow.left, -rectWindow.top);
2524 hrgn = CreateRectRgnIndirect(&rect);
2525 if (!hrgn) {
2526 dprintf(("ERROR: NotifyFrameChanged, CreateRectRgnIndirect failed!!"));
2527 return;
2528 }
2529 rect = rectClient;
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 hrgnClient = CreateRectRgnIndirect(oldClientRect);
2541 if (!hrgn) {
2542 dprintf(("ERROR: NotifyFrameChanged, CreateRectRgnIndirect failed!!"));
2543 return;
2544 }
2545 CombineRgn(hrgn, hrgn, hrgnClient, RGN_OR);
2546 DeleteObject(hrgnClient);
2547 }
2548 RedrawWindow(getWindowHandle(), NULL, hrgn, RDW_ALLCHILDREN |
2549 RDW_INVALIDATE | RDW_ERASE | RDW_FRAME);
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.