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

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

activate, tab and ischild bugfixes

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