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

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

workaround for window origin changes

File size: 123.6 KB
Line 
1/* $Id: win32wbase.cpp,v 1.236 2001-02-18 14:18:39 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//testestest
2414 if(getParent() && getParent()->isOwnDC()) {
2415 dprintfOrigin(getParent()->getOwnDC());
2416 selectClientArea(getParent(), getParent()->getOwnDC());
2417 }
2418//testestest
2419
2420 if((fuFlags & SWP_FRAMECHANGED) && (fuFlags & (SWP_NOMOVE | SWP_NOSIZE) == (SWP_NOMOVE | SWP_NOSIZE)))
2421 {
2422 NotifyFrameChanged(&wpos, &oldClientRect);
2423 }
2424 return (rc);
2425}
2426//******************************************************************************
2427//******************************************************************************
2428void Win32BaseWindow::NotifyFrameChanged(WINDOWPOS *wpos, RECT *oldClientRect)
2429{
2430 HRGN hrgn, hrgnClient;
2431 RECT rect;
2432
2433 MsgFormatFrame(NULL);
2434
2435 if(RECT_WIDTH(rectClient) != RECT_WIDTH(*oldClientRect) ||
2436 RECT_HEIGHT(rectClient) != RECT_HEIGHT(*oldClientRect))
2437 {
2438 wpos->flags &= ~(SWP_NOSIZE|SWP_NOCLIENTSIZE);
2439 wpos->cx = RECT_WIDTH(rectWindow);
2440 wpos->cy = RECT_HEIGHT(rectWindow);
2441 }
2442
2443 if(rectClient.left != oldClientRect->left ||
2444 rectClient.top != oldClientRect->top)
2445 {
2446 wpos->flags &= ~(SWP_NOMOVE|SWP_NOCLIENTMOVE);
2447 wpos->x = rectWindow.left;
2448 wpos->y = rectWindow.top;
2449 }
2450
2451 WINDOWPOS wpOld = *wpos;
2452 SendInternalMessageA(WM_WINDOWPOSCHANGING, 0, (LPARAM)wpos);
2453
2454 if ((wpos->hwndInsertAfter != wpOld.hwndInsertAfter) ||
2455 (wpos->x != wpOld.x) || (wpos->y != wpOld.y) || (wpos->cx != wpOld.cx) || (wpos->cy != wpOld.cy) || (wpos->flags != wpOld.flags))
2456 {
2457 dprintf(("WARNING, NotifyFrameChanged: TODO -> adjust flags!!!!"));
2458 SetWindowPos(wpos->hwndInsertAfter, wpos->x, wpos->y, wpos->cx, wpos->cy, wpos->flags | SWP_NOSENDCHANGING);
2459 }
2460 else SendInternalMessageA(WM_WINDOWPOSCHANGED, 0, (LPARAM)wpos);
2461
2462 rect = rectWindow;
2463 OffsetRect(&rect, -rectWindow.left, -rectWindow.top);
2464 hrgn = CreateRectRgnIndirect(&rect);
2465 if (!hrgn) {
2466 dprintf(("ERROR: NotifyFrameChanged, CreateRectRgnIndirect failed!!"));
2467 return;
2468 }
2469 rect = rectClient;
2470 OffsetRect(&rect, -rectClient.left, -rectClient.top);
2471 hrgnClient = CreateRectRgnIndirect(&rect);
2472 if (!hrgn) {
2473 dprintf(("ERROR: NotifyFrameChanged, CreateRectRgnIndirect failed!!"));
2474 return;
2475 }
2476 CombineRgn(hrgn, hrgn, hrgnClient, RGN_DIFF);
2477 DeleteObject(hrgnClient);
2478
2479 if(!EqualRect(oldClientRect, &rectClient)) {
2480 UnionRect(oldClientRect, oldClientRect, &rectClient);
2481 OffsetRect(oldClientRect, -rectClient.left, -rectClient.top);
2482 hrgnClient = CreateRectRgnIndirect(oldClientRect);
2483 if (!hrgn) {
2484 dprintf(("ERROR: NotifyFrameChanged, CreateRectRgnIndirect failed!!"));
2485 return;
2486 }
2487 CombineRgn(hrgn, hrgn, hrgnClient, RGN_OR);
2488 DeleteObject(hrgnClient);
2489 }
2490 InvalidateRgn(getWindowHandle(), hrgn, TRUE);
2491 DeleteObject(hrgn);
2492}
2493//******************************************************************************
2494//TODO: Check how this api really works in NT
2495//******************************************************************************
2496BOOL Win32BaseWindow::SetWindowPlacement(WINDOWPLACEMENT *wndpl)
2497{
2498 windowpos.ptMinPosition = wndpl->ptMinPosition;
2499 windowpos.ptMaxPosition = wndpl->ptMaxPosition;
2500 windowpos.rcNormalPosition = wndpl->rcNormalPosition;
2501
2502 if(getStyle() & WS_MINIMIZE )
2503 {
2504 //TODO: Why can't this be (0,0)?
2505 if(wndpl->flags & WPF_SETMINPOSITION && !(!windowpos.ptMinPosition.x && !windowpos.ptMinPosition.y)) {
2506 SetWindowPos(0, windowpos.ptMinPosition.x, windowpos.ptMinPosition.y,
2507 0, 0, SWP_NOSIZE | SWP_NOZORDER | SWP_NOACTIVATE);
2508 }
2509 }
2510 else
2511 if(getStyle() & WS_MAXIMIZE )
2512 {
2513 //TODO: Why can't this be (0,0)?
2514 if(windowpos.ptMaxPosition.x != 0 || windowpos.ptMaxPosition.y != 0 )
2515 SetWindowPos(0, windowpos.ptMaxPosition.x, windowpos.ptMaxPosition.y,
2516 0, 0, SWP_NOSIZE | SWP_NOZORDER | SWP_NOACTIVATE);
2517 }
2518 else {
2519 SetWindowPos(0, windowpos.rcNormalPosition.left, windowpos.rcNormalPosition.top,
2520 windowpos.rcNormalPosition.right - windowpos.rcNormalPosition.left,
2521 windowpos.rcNormalPosition.bottom - windowpos.rcNormalPosition.top,
2522 SWP_NOZORDER | SWP_NOACTIVATE );
2523 }
2524 ShowWindow(wndpl->showCmd);
2525 if( ::IsWindow(getWindowHandle()) && getStyle() & WS_MINIMIZE )
2526 {
2527 /* SDK: ...valid only the next time... */
2528 if(wndpl->flags & WPF_RESTORETOMAXIMIZED)
2529 setFlags(getFlags() | WIN_RESTORE_MAX);
2530 }
2531 return TRUE;
2532}
2533//******************************************************************************
2534//******************************************************************************
2535BOOL Win32BaseWindow::GetWindowPlacement(LPWINDOWPLACEMENT wndpl)
2536{
2537 wndpl->length = sizeof(*wndpl);
2538 if(getStyle() & WS_MINIMIZE )
2539 wndpl->showCmd = SW_SHOWMINIMIZED;
2540 else wndpl->showCmd = (getStyle() & WS_MAXIMIZE) ? SW_SHOWMAXIMIZED : SW_SHOWNORMAL;
2541
2542 //TODO: Verify if this is correct -> SDK docs claim this flag must always be set to 0
2543 if(getFlags() & WIN_RESTORE_MAX )
2544 wndpl->flags = WPF_RESTORETOMAXIMIZED;
2545 else wndpl->flags = 0;
2546
2547 wndpl->ptMinPosition = windowpos.ptMinPosition;
2548 wndpl->ptMaxPosition = windowpos.ptMaxPosition;
2549 //Must be in parent coordinates (or screen if no parent); verified in NT4, SP6
2550 wndpl->rcNormalPosition = rectWindow;
2551
2552 return TRUE;
2553}
2554//******************************************************************************
2555//Also destroys all the child windows (destroy children first, parent last)
2556//******************************************************************************
2557BOOL Win32BaseWindow::DestroyWindow()
2558{
2559 HWND hwnd = getWindowHandle();
2560
2561 dprintf(("DestroyWindow %x", hwnd));
2562
2563 /* Call hooks */
2564 if(HOOK_CallHooksA( WH_CBT, HCBT_DESTROYWND, getWindowHandle(), 0L))
2565 {
2566 return FALSE;
2567 }
2568
2569 if(!(getStyle() & WS_CHILD) && getOwner() == NULL)
2570 {
2571 HOOK_CallHooksA(WH_SHELL, HSHELL_WINDOWDESTROYED, getWindowHandle(), 0L);
2572 /* FIXME: clean up palette - see "Internals" p.352 */
2573 }
2574
2575 if((getStyle() & WS_CHILD) && !(getExStyle() & WS_EX_NOPARENTNOTIFY))
2576 {
2577 if(getParent() && getParent()->IsWindowDestroyed() == FALSE)
2578 {
2579 /* Notify the parent window only */
2580 getParent()->SendMessageA(WM_PARENTNOTIFY, MAKEWPARAM(WM_DESTROY, getWindowId()), (LPARAM)getWindowHandle());
2581 if(!::IsWindow(hwnd) )
2582 {
2583 return TRUE;
2584 }
2585 }
2586//// else DebugInt3();
2587 }
2588 /* Hide the window */
2589 if(IsWindowVisible())
2590 {
2591 SetWindowPos(0, 0, 0, 0, 0, SWP_HIDEWINDOW |
2592 SWP_NOACTIVATE|SWP_NOZORDER|SWP_NOMOVE|SWP_NOSIZE);
2593 if(!::IsWindow(hwnd))
2594 {
2595 return TRUE;
2596 }
2597 }
2598 dprintf(("DestroyWindow %x -> HIDDEN", hwnd));
2599
2600 fDestroyWindowCalled = TRUE;
2601 return OSLibWinDestroyWindow(OS2Hwnd);
2602}
2603//******************************************************************************
2604//******************************************************************************
2605Win32BaseWindow *Win32BaseWindow::getParent()
2606{
2607 Win32BaseWindow *wndparent = (Win32BaseWindow *)ChildWindow::getParentOfChild();
2608 return ((ULONG)wndparent == (ULONG)windowDesktop) ? NULL : wndparent;
2609}
2610//******************************************************************************
2611//Note: does not set last error if no parent (verified in NT4, SP6)
2612//******************************************************************************
2613HWND Win32BaseWindow::GetParent()
2614{
2615 if((!(getStyle() & (WS_POPUP|WS_CHILD)))) {
2616 return 0;
2617 }
2618
2619 Win32BaseWindow *wndparent = (Win32BaseWindow *)ChildWindow::getParentOfChild();
2620
2621 if(getStyle() & WS_CHILD) {
2622 if(wndparent) {
2623 return wndparent->getWindowHandle();
2624 }
2625 dprintf(("WARNING: GetParent: WS_CHILD but no parent!!"));
2626 DebugInt3();
2627 return 0;
2628 }
2629 else return (getOwner()) ? getOwner()->getWindowHandle() : 0;
2630}
2631//******************************************************************************
2632//******************************************************************************
2633HWND Win32BaseWindow::SetParent(HWND hwndNewParent)
2634{
2635 HWND oldhwnd;
2636 Win32BaseWindow *newparent;
2637 Win32BaseWindow *oldparent = (Win32BaseWindow *)ChildWindow::getParentOfChild();
2638 BOOL fShow = FALSE;
2639
2640 if(oldparent) {
2641 oldhwnd = oldparent->getWindowHandle();
2642 oldparent->removeChild(this);
2643 }
2644 else oldhwnd = 0;
2645
2646 /* Windows hides the window first, then shows it again
2647 * including the WM_SHOWWINDOW messages and all */
2648 if(fCreated && (getStyle() & WS_VISIBLE)) {
2649 ShowWindow(SW_HIDE);
2650 fShow = TRUE;
2651 }
2652
2653 newparent = GetWindowFromHandle(hwndNewParent);
2654 if(newparent && !newparent->isDesktopWindow())
2655 {
2656 setParent(newparent);
2657 getParent()->addChild(this);
2658 OSLibWinSetParent(getOS2WindowHandle(), getParent()->getOS2WindowHandle());
2659 if(!(getStyle() & WS_CHILD))
2660 {
2661 //TODO: Send WM_STYLECHANGED msg?
2662 setStyle(getStyle() | WS_CHILD);
2663 if(getWindowId())
2664 {
2665 DestroyMenu( (HMENU) getWindowId() );
2666 setWindowId(0);
2667 }
2668 }
2669 }
2670 else {
2671 setParent(windowDesktop);
2672 windowDesktop->addChild(this);
2673 OSLibWinSetParent(getOS2WindowHandle(), OSLIB_HWND_DESKTOP);
2674
2675 //TODO: Send WM_STYLECHANGED msg?
2676 setStyle(getStyle() & ~WS_CHILD);
2677 setWindowId(0);
2678 }
2679 /* SetParent additionally needs to make hwndChild the topmost window
2680 in the x-order and send the expected WM_WINDOWPOSCHANGING and
2681 WM_WINDOWPOSCHANGED notification messages.
2682 */
2683 if(fCreated) {
2684 SetWindowPos(HWND_TOPMOST, 0, 0, 0, 0,
2685 SWP_NOACTIVATE|SWP_NOMOVE|SWP_NOSIZE|(fShow? SWP_SHOWWINDOW : 0));
2686
2687 /* FIXME: a WM_MOVE is also generated (in the DefWindowProc handler
2688 * for WM_WINDOWPOSCHANGED) in Windows, should probably remove SWP_NOMOVE */
2689 }
2690 return oldhwnd;
2691}
2692//******************************************************************************
2693//******************************************************************************
2694BOOL Win32BaseWindow::IsChild(HWND hwndParent)
2695{
2696 if(getParent()) {
2697 if(getParent()->getWindowHandle() == hwndParent)
2698 return TRUE;
2699
2700 return getParent()->IsChild(hwndParent);
2701 }
2702 else return 0;
2703}
2704//******************************************************************************
2705//******************************************************************************
2706HWND Win32BaseWindow::GetTopWindow()
2707{
2708 HWND hwndTop;
2709 Win32BaseWindow *topwindow;
2710
2711 hwndTop = OSLibWinQueryWindow(getOS2WindowHandle(), QWOS_TOP);
2712 if(!isDesktopWindow()) {
2713 topwindow = GetWindowFromOS2Handle(hwndTop);
2714 if(topwindow) {
2715 return topwindow->getWindowHandle();
2716 }
2717 return 0;
2718 }
2719 while(hwndTop) {
2720 topwindow = GetWindowFromOS2Handle(hwndTop);
2721 if(topwindow) {
2722 return topwindow->getWindowHandle();
2723 }
2724 hwndTop = OSLibWinQueryWindow(hwndTop, QWOS_NEXT);
2725 }
2726
2727 return 0;
2728}
2729//******************************************************************************
2730// Get the top-level parent for a child window.
2731//******************************************************************************
2732Win32BaseWindow *Win32BaseWindow::GetTopParent()
2733{
2734 Win32BaseWindow *window = this;
2735
2736 while(window && (window->getStyle() & WS_CHILD))
2737 {
2738 window = window->getParent();
2739 }
2740 return window;
2741}
2742//******************************************************************************
2743//TODO: Should not enumerate children that are created during the enumeration!
2744//******************************************************************************
2745BOOL Win32BaseWindow::EnumChildWindows(WNDENUMPROC lpfn, LPARAM lParam)
2746{
2747 BOOL rc = TRUE;
2748 HWND hwnd;
2749 Win32BaseWindow *prevchild = 0, *child = 0;
2750
2751 dprintf(("EnumChildWindows of %x parameter %x %x (%x)", getWindowHandle(), lpfn, lParam, getFirstChild()));
2752 for (child = (Win32BaseWindow *)getFirstChild(); child; child = (Win32BaseWindow *)child->getNextChild())
2753 {
2754 dprintf(("EnumChildWindows: enumerating child %x (owner %x; parent %x)", child->getWindowHandle(), (child->getOwner()) ? child->getOwner()->getWindowHandle() : 0, getWindowHandle()));
2755 hwnd = child->getWindowHandle();
2756 if(child->getOwner()) {
2757 continue; //shouldn't have an owner (Wine)
2758 }
2759 if(lpfn(hwnd, lParam) == FALSE)
2760 {
2761 rc = FALSE;
2762 break;
2763 }
2764 //check if the window still exists
2765 if(!::IsWindow(hwnd))
2766 {
2767 child = prevchild;
2768 continue;
2769 }
2770 if(child->getFirstChild() != NULL)
2771 {
2772 dprintf(("EnumChildWindows: Enumerate children of %x", child->getWindowHandle()));
2773 if(child->EnumChildWindows(lpfn, lParam) == FALSE)
2774 {
2775 rc = FALSE;
2776 break;
2777 }
2778 }
2779 prevchild = child;
2780 }
2781 return rc;
2782}
2783//******************************************************************************
2784//Enumerate first-level children only and check thread id
2785//******************************************************************************
2786BOOL Win32BaseWindow::EnumThreadWindows(DWORD dwThreadId, WNDENUMPROC lpfn, LPARAM lParam)
2787{
2788 Win32BaseWindow *child = 0;
2789 ULONG tid, pid;
2790 BOOL rc;
2791 HWND hwnd;
2792
2793 dprintf(("EnumThreadWindows %x %x %x", dwThreadId, lpfn, lParam));
2794
2795 for (child = (Win32BaseWindow *)getFirstChild(); child; child = (Win32BaseWindow *)child->getNextChild())
2796 {
2797 OSLibWinQueryWindowProcess(child->getOS2WindowHandle(), &pid, &tid);
2798
2799 if(dwThreadId == tid) {
2800 dprintf2(("EnumThreadWindows: Found Window %x", child->getWindowHandle()));
2801 if((rc = lpfn(child->getWindowHandle(), lParam)) == FALSE) {
2802 break;
2803 }
2804 }
2805 }
2806 return TRUE;
2807}
2808//******************************************************************************
2809//Enumerate first-level children only
2810//******************************************************************************
2811BOOL Win32BaseWindow::EnumWindows(WNDENUMPROC lpfn, LPARAM lParam)
2812{
2813 Win32BaseWindow *child = 0;
2814 BOOL rc;
2815 HWND hwnd;
2816
2817 dprintf(("EnumWindows %x %x", lpfn, lParam));
2818
2819 for (child = (Win32BaseWindow *)getFirstChild(); child; child = (Win32BaseWindow *)child->getNextChild())
2820 {
2821 hwnd = child->getWindowHandle();
2822
2823 dprintf2(("EnumWindows: Found Window %x", child->getWindowHandle()));
2824 if((rc = lpfn(child->getWindowHandle(), lParam)) == FALSE) {
2825 break;
2826 }
2827 }
2828 return TRUE;
2829}
2830//******************************************************************************
2831//******************************************************************************
2832Win32BaseWindow *Win32BaseWindow::FindWindowById(int id)
2833{
2834 for (Win32BaseWindow *child = (Win32BaseWindow *)getFirstChild(); child; child = (Win32BaseWindow *)child->getNextChild())
2835 {
2836 if (child->getWindowId() == id)
2837 {
2838 return child;
2839 }
2840 }
2841 return 0;
2842}
2843//******************************************************************************
2844//TODO:
2845//We assume (for now) that if hwndParent or hwndChildAfter are real window handles, that
2846//the current process owns them.
2847//******************************************************************************
2848HWND Win32BaseWindow::FindWindowEx(HWND hwndParent, HWND hwndChildAfter, ATOM atom, LPSTR lpszWindow)
2849{
2850 Win32BaseWindow *parent = GetWindowFromHandle(hwndParent);
2851 Win32BaseWindow *child = GetWindowFromHandle(hwndChildAfter);
2852
2853 dprintf(("FindWindowEx %x %x %x %s", hwndParent, hwndChildAfter, atom, lpszWindow));
2854 if((hwndParent != 0 && !parent) ||
2855 (hwndChildAfter != 0 && !child) ||
2856 (hwndParent == 0 && hwndChildAfter != 0))
2857 {
2858 dprintf(("Win32BaseWindow::FindWindowEx: parent or child not found %x %x", hwndParent, hwndChildAfter));
2859 SetLastError(ERROR_INVALID_WINDOW_HANDLE);
2860 return 0;
2861 }
2862 SetLastError(0);
2863 if(hwndParent != 0)
2864 {//if the current process owns the window, just do a quick search
2865 child = (Win32BaseWindow *)parent->getFirstChild();
2866 if(hwndChildAfter != 0)
2867 {
2868 while(child)
2869 {
2870 if(child->getWindowHandle() == hwndChildAfter)
2871 {
2872 child = (Win32BaseWindow *)child->getNextChild();
2873 break;
2874 }
2875 child = (Win32BaseWindow *)child->getNextChild();
2876 }
2877 }
2878 while(child)
2879 {
2880 //According to Wine, the class doesn't need to be specified
2881 if((!atom || child->getWindowClass()->getAtom() == atom) &&
2882 (!lpszWindow || child->hasWindowName(lpszWindow)))
2883 {
2884 dprintf(("FindWindowEx: Found window %x", child->getWindowHandle()));
2885 return child->getWindowHandle();
2886 }
2887 child = (Win32BaseWindow *)child->getNextChild();
2888 }
2889 }
2890 else {
2891 Win32BaseWindow *wnd;
2892 HWND henum, hwnd;
2893
2894 henum = OSLibWinBeginEnumWindows(OSLIB_HWND_DESKTOP);
2895 hwnd = OSLibWinGetNextWindow(henum);
2896
2897 while(hwnd)
2898 {
2899 wnd = GetWindowFromOS2Handle(hwnd);
2900 if(wnd == NULL) {
2901 hwnd = OSLibWinQueryClientWindow(hwnd);
2902 if(hwnd) wnd = GetWindowFromOS2Handle(hwnd);
2903 }
2904
2905 if(wnd) {
2906 //According to Wine, the class doesn't need to be specified
2907 if((!atom || wnd->getWindowClass()->getAtom() == atom) &&
2908 (!lpszWindow || wnd->hasWindowName(lpszWindow)))
2909 {
2910 OSLibWinEndEnumWindows(henum);
2911 dprintf(("FindWindowEx: Found window %x", wnd->getWindowHandle()));
2912 return wnd->getWindowHandle();
2913 }
2914 }
2915 hwnd = OSLibWinGetNextWindow(henum);
2916 }
2917 OSLibWinEndEnumWindows(henum);
2918 }
2919 SetLastError(ERROR_CANNOT_FIND_WND_CLASS); //TODO: not always correct
2920 return 0;
2921}
2922//******************************************************************************
2923//******************************************************************************
2924HWND Win32BaseWindow::GetWindow(UINT uCmd)
2925{
2926 HWND hwndRelated = 0;
2927 Win32BaseWindow *window;
2928
2929#if 1
2930 switch(uCmd)
2931 {
2932 case GW_HWNDFIRST:
2933 if(getParent())
2934 {
2935 window = (Win32BaseWindow *)getParent();
2936 hwndRelated = OSLibWinQueryWindow(window->getOS2WindowHandle(), QWOS_TOP);
2937 window = GetWindowFromOS2Handle(hwndRelated);
2938 if(window) {
2939 hwndRelated = window->getWindowHandle();
2940 }
2941 else hwndRelated = 0;
2942 }
2943 else hwndRelated = 0; //TODO: not correct; should get first child in z-order of desktop
2944 break;
2945
2946 case GW_HWNDLAST:
2947 hwndRelated = OSLibWinQueryWindow(getOS2WindowHandle(), QWOS_BOTTOM);
2948 window = GetWindowFromOS2Handle(hwndRelated);
2949 if(window) {
2950 hwndRelated = window->getWindowHandle();
2951 }
2952 else hwndRelated = 0;
2953 break;
2954
2955 case GW_HWNDNEXT:
2956 hwndRelated = OSLibWinQueryWindow(getOS2WindowHandle(), QWOS_NEXT);
2957 window = GetWindowFromOS2Handle(hwndRelated);
2958 if(window) {
2959 hwndRelated = window->getWindowHandle();
2960 }
2961 else hwndRelated = 0;
2962 break;
2963
2964 case GW_HWNDPREV:
2965 hwndRelated = OSLibWinQueryWindow(getOS2WindowHandle(), QWOS_PREV);
2966 window = GetWindowFromOS2Handle(hwndRelated);
2967 if(window) {
2968 hwndRelated = window->getWindowHandle();
2969 }
2970 else hwndRelated = 0;
2971 break;
2972
2973 case GW_OWNER:
2974 if(getOwner()) {
2975 hwndRelated = getOwner()->getWindowHandle();
2976 }
2977 break;
2978
2979 case GW_CHILD:
2980 hwndRelated = OSLibWinQueryWindow(getOS2WindowHandle(), QWOS_TOP);
2981 window = GetWindowFromOS2Handle(hwndRelated);
2982 if(window) {
2983 hwndRelated = window->getWindowHandle();
2984 }
2985 else hwndRelated = 0;
2986 break;
2987 }
2988#else
2989 switch(uCmd)
2990 {
2991 case GW_HWNDFIRST:
2992 if(getParent()) {
2993 window = (Win32BaseWindow *)getParent()->getFirstChild();
2994 hwndRelated = window->getWindowHandle();
2995 }
2996 break;
2997
2998 case GW_HWNDLAST:
2999 if(!getParent())
3000 {
3001 goto end;
3002 }
3003
3004 window = this;
3005 while(window->getNextChild())
3006 {
3007 window = (Win32BaseWindow *)window->getNextChild();
3008 }
3009 hwndRelated = window->getWindowHandle();
3010 break;
3011
3012 case GW_HWNDNEXT:
3013 window = (Win32BaseWindow *)getNextChild();
3014 if(window) {
3015 hwndRelated = window->getWindowHandle();
3016 }
3017 break;
3018
3019 case GW_HWNDPREV:
3020 if(!getParent())
3021 {
3022 goto end;
3023 }
3024 window = (Win32BaseWindow *)(getParent()->getFirstChild()); /* First sibling */
3025 if(window == this)
3026 {
3027 hwndRelated = 0; /* First in list */
3028 goto end;
3029 }
3030 while(window->getNextChild())
3031 {
3032 if (window->getNextChild() == this)
3033 {
3034 hwndRelated = window->getWindowHandle();
3035 goto end;
3036 }
3037 window = (Win32BaseWindow *)window->getNextChild();
3038 }
3039 break;
3040
3041 case GW_OWNER:
3042 if(getOwner()) {
3043 hwndRelated = getOwner()->getWindowHandle();
3044 }
3045 break;
3046
3047 case GW_CHILD:
3048 if(getFirstChild()) {
3049 hwndRelated = ((Win32BaseWindow *)getFirstChild())->getWindowHandle();
3050 }
3051 break;
3052 }
3053#endif
3054end:
3055 dprintf(("GetWindow %x %d returned %x", getWindowHandle(), uCmd, hwndRelated));
3056 return hwndRelated;
3057}
3058//******************************************************************************
3059//******************************************************************************
3060HWND Win32BaseWindow::SetActiveWindow()
3061{
3062 HWND hwndActive;
3063
3064 dprintf(("SetActiveWindow %x", getWindowHandle()));
3065 if (HOOK_IsHooked( WH_CBT ))
3066 {
3067 CBTACTIVATESTRUCT cbta;
3068 LRESULT ret;
3069
3070 cbta.fMouse = FALSE;
3071 cbta.hWndActive = GetActiveWindow();
3072 ret = HOOK_CallHooksA(WH_CBT, HCBT_ACTIVATE, getWindowHandle(), (LPARAM)&cbta);
3073 if(ret)
3074 {
3075 dprintf(("SetActiveWindow %x, CBT hook cancelled operation", getWindowHandle()));
3076 return cbta.hWndActive;
3077 }
3078 }
3079 SetWindowPos(HWND_TOP, 0,0,0,0, SWP_NOSIZE | SWP_NOMOVE );
3080
3081// if(OSLibWinSetActiveWindow(OS2Hwnd) == FALSE) {
3082// dprintf(("OSLibWinSetActiveWindow %x returned FALSE!", OS2Hwnd));
3083// }
3084 hwndActive = GetActiveWindow();
3085 return (hwndActive) ? hwndActive : windowDesktop->getWindowHandle(); //pretend the desktop was active
3086}
3087//******************************************************************************
3088//WM_ENABLE is sent to hwnd, but not to it's children (as it should be)
3089//******************************************************************************
3090BOOL Win32BaseWindow::EnableWindow(BOOL fEnable)
3091{
3092 BOOL rc;
3093
3094 dprintf(("Win32BaseWindow::EnableWindow %x %d", getWindowHandle(), fEnable));
3095 //return true if previous state was disabled, else false (sdk docs)
3096 rc = (getStyle() & WS_DISABLED) != 0;
3097 if(rc && !fEnable) {
3098 SendMessageA(WM_CANCELMODE, 0, 0);
3099 }
3100 OSLibWinEnableWindow(OS2Hwnd, fEnable);
3101 if(fEnable == FALSE) {
3102 //SvL: No need to clear focus as PM already does this
3103 if(getWindowHandle() == GetCapture()) {
3104 ReleaseCapture(); /* A disabled window can't capture the mouse */
3105 dprintf(("Released capture for window %x that is being disabled", getWindowHandle()));
3106 }
3107 }
3108 return rc;
3109}
3110//******************************************************************************
3111//******************************************************************************
3112BOOL Win32BaseWindow::CloseWindow()
3113{
3114 return OSLibWinMinimizeWindow(OS2Hwnd);
3115}
3116//******************************************************************************
3117//TODO: Not be 100% correct; should return active window of current thread
3118// or NULL when there is none -> WinQueryActiveWindow just returns
3119// the current active window
3120//******************************************************************************
3121HWND Win32BaseWindow::GetActiveWindow()
3122{
3123 HWND hwndActive;
3124 Win32BaseWindow *win32wnd;
3125 ULONG magic;
3126
3127 hwndActive = OSLibWinQueryActiveWindow();
3128
3129 return OS2ToWin32Handle(hwndActive);
3130}
3131//******************************************************************************
3132//******************************************************************************
3133BOOL Win32BaseWindow::IsWindowEnabled()
3134{
3135 return OSLibWinIsWindowEnabled(OS2Hwnd);
3136}
3137//******************************************************************************
3138//******************************************************************************
3139BOOL Win32BaseWindow::IsWindowVisible()
3140{
3141 //TODO: Do we have to check the state of the parent window? (as Wine does)
3142#if 1
3143 return (dwStyle & WS_VISIBLE) == WS_VISIBLE;
3144#else
3145 return OSLibWinIsWindowVisible(OS2Hwnd);
3146#endif
3147}
3148//******************************************************************************
3149//******************************************************************************
3150BOOL Win32BaseWindow::hasWindowName(LPSTR wndname, BOOL fUnicode)
3151{
3152 INT len = GetWindowTextLength();
3153 BOOL res;
3154
3155 if (wndname == NULL)
3156 return (len == 0);
3157
3158 len++;
3159 if (fUnicode)
3160 {
3161 WCHAR *text = (WCHAR*)malloc(len*sizeof(WCHAR));
3162
3163 GetWindowTextW(text,len);
3164 res = (lstrcmpW(text,(LPWSTR)wndname) == 0);
3165 free(text);
3166 } else
3167 {
3168 CHAR *text = (CHAR*)malloc(len*sizeof(CHAR));
3169
3170 GetWindowTextA(text,len);
3171 res = (strcmp(text,wndname) == 0);
3172 free(text);
3173 }
3174
3175 return res;
3176}
3177//******************************************************************************
3178//******************************************************************************
3179CHAR *Win32BaseWindow::getWindowNamePtrA()
3180{
3181 INT len = GetWindowTextLength();
3182 CHAR *text;
3183
3184 if (len == 0) return NULL;
3185 len++;
3186 text = (CHAR*)malloc(len*sizeof(CHAR));
3187 GetWindowTextA(text,len);
3188
3189 return text;
3190}
3191//******************************************************************************
3192//******************************************************************************
3193WCHAR *Win32BaseWindow::getWindowNamePtrW()
3194{
3195 INT len = GetWindowTextLength();
3196 WCHAR *text;
3197
3198 if (len == 0) return NULL;
3199 len++;
3200 text = (WCHAR*)malloc(len*sizeof(WCHAR));
3201 GetWindowTextW(text,len);
3202
3203 return text;
3204}
3205//******************************************************************************
3206//******************************************************************************
3207VOID Win32BaseWindow::freeWindowNamePtr(PVOID namePtr)
3208{
3209 if (namePtr) free(namePtr);
3210}
3211//******************************************************************************
3212//When using this API for a window that was created by a different process, NT
3213//does NOT send WM_GETTEXTLENGTH.
3214//******************************************************************************
3215int Win32BaseWindow::GetWindowTextLength()
3216{
3217 //if the destination window is created by this process, send message
3218 if(dwProcessId == currentProcessId) {
3219 return SendInternalMessageA(WM_GETTEXTLENGTH,0,0);
3220 }
3221 //else get data directory from window structure
3222 return wndNameLength;
3223}
3224//******************************************************************************
3225//When using this API for a window that was created by a different process, NT
3226//does NOT send WM_GETTEXT.
3227//******************************************************************************
3228int Win32BaseWindow::GetWindowTextA(LPSTR lpsz, int cch)
3229{
3230 //if the destination window is created by this process, send message
3231 if(dwProcessId == currentProcessId) {
3232 return SendInternalMessageA(WM_GETTEXT,(WPARAM)cch,(LPARAM)lpsz);
3233 }
3234 //else get data directory from window structure
3235 if (!lpsz || !cch) return 0;
3236 if (!windowNameA) lpsz[0] = 0;
3237 else lstrcpynA(lpsz, windowNameA, cch);
3238 return min(wndNameLength, cch);
3239}
3240//******************************************************************************
3241//When using this API for a window that was created by a different process, NT
3242//does NOT send WM_GETTEXT.
3243//******************************************************************************
3244int Win32BaseWindow::GetWindowTextW(LPWSTR lpsz, int cch)
3245{
3246 //if the destination window is created by this process, send message
3247 if(dwProcessId == currentProcessId) {
3248 return SendInternalMessageW(WM_GETTEXT,(WPARAM)cch,(LPARAM)lpsz);
3249 }
3250 //else get data directory from window structure
3251 if (!lpsz || !cch) return 0;
3252 if (!windowNameW) lpsz[0] = 0;
3253 else lstrcpynW(lpsz, windowNameW, cch);
3254 return min(wndNameLength, cch);
3255}
3256//******************************************************************************
3257//TODO: How does this work when the target window belongs to a different process???
3258//******************************************************************************
3259BOOL Win32BaseWindow::SetWindowTextA(LPSTR lpsz)
3260{
3261 return SendInternalMessageA(WM_SETTEXT,0,(LPARAM)lpsz);
3262}
3263//******************************************************************************
3264//******************************************************************************
3265BOOL Win32BaseWindow::SetWindowTextW(LPWSTR lpsz)
3266{
3267 return SendInternalMessageW(WM_SETTEXT,0,(LPARAM)lpsz);
3268}
3269//******************************************************************************
3270//******************************************************************************
3271LONG Win32BaseWindow::SetWindowLongA(int index, ULONG value, BOOL fUnicode)
3272{
3273 LONG oldval;
3274
3275 switch(index) {
3276 case GWL_EXSTYLE:
3277 {
3278 STYLESTRUCT ss;
3279
3280 if(dwExStyle == value) {
3281 oldval = value;
3282 break;
3283 }
3284 ss.styleOld = dwExStyle;
3285 ss.styleNew = value;
3286 dprintf(("SetWindowLong GWL_EXSTYLE %x old %x new style %x", getWindowHandle(), dwExStyle, value));
3287 SendInternalMessageA(WM_STYLECHANGING,GWL_EXSTYLE,(LPARAM)&ss);
3288 setExStyle(ss.styleNew);
3289 SendInternalMessageA(WM_STYLECHANGED,GWL_EXSTYLE,(LPARAM)&ss);
3290 oldval = ss.styleOld;
3291 break;
3292 }
3293 case GWL_STYLE:
3294 {
3295 STYLESTRUCT ss;
3296
3297 //SvL: TODO: Can you change minimize or maximize status here too?
3298
3299 if(dwStyle == value) {
3300 oldval = value;
3301 break;
3302 }
3303 value &= ~(WS_CHILD|WS_VISIBLE); /* Some bits can't be changed this way (WINE) */
3304 ss.styleOld = getStyle();
3305 ss.styleNew = value | (ss.styleOld & (WS_CHILD|WS_VISIBLE));
3306 dprintf(("SetWindowLong GWL_STYLE %x old %x new style %x", getWindowHandle(), ss.styleOld, ss.styleNew));
3307 SendInternalMessageA(WM_STYLECHANGING,GWL_STYLE,(LPARAM)&ss);
3308 setStyle(ss.styleNew);
3309 SendInternalMessageA(WM_STYLECHANGED,GWL_STYLE,(LPARAM)&ss);
3310//// OSLibSetWindowStyle(getOS2WindowHandle(), getStyle(), getExStyle(),
3311//// windowClass->getStyle() & CS_SAVEBITS);
3312#ifdef DEBUG
3313 PrintWindowStyle(ss.styleNew, 0);
3314#endif
3315 oldval = ss.styleOld;
3316 break;
3317 }
3318 case GWL_WNDPROC:
3319 {
3320 //Note: Type of SetWindowLong determines new window proc type
3321 // UNLESS the new window proc has already been registered
3322 // (use the old type in that case)
3323 // (VERIFIED in NT 4, SP6)
3324 WINDOWPROCTYPE type = WINPROC_GetProcType((HWINDOWPROC)value);
3325 if(type == WIN_PROC_INVALID) {
3326 type = (fUnicode) ? WIN_PROC_32W : WIN_PROC_32A;
3327 }
3328 oldval = (LONG)WINPROC_GetProc(win32wndproc, (fUnicode) ? WIN_PROC_32W : WIN_PROC_32A);
3329 WINPROC_SetProc((HWINDOWPROC *)&win32wndproc, (WNDPROC)value, type, WIN_PROC_WINDOW);
3330 break;
3331 }
3332 case GWL_HINSTANCE:
3333 oldval = hInstance;
3334 hInstance = value;
3335 break;
3336
3337 case GWL_HWNDPARENT:
3338 oldval = SetParent((HWND)value);
3339 break;
3340
3341 case GWL_ID:
3342 oldval = getWindowId();
3343 setWindowId(value);
3344 break;
3345
3346 case GWL_USERDATA:
3347 oldval = userData;
3348 userData = value;
3349 break;
3350
3351 default:
3352 if(index >= 0 && index/4 < nrUserWindowLong)
3353 {
3354 oldval = userWindowLong[index/4];
3355 userWindowLong[index/4] = value;
3356 break;
3357 }
3358 dprintf(("WARNING: SetWindowLong%c %x %d %x returned %x INVALID index!", (fUnicode) ? 'W' : 'A', getWindowHandle(), index, value));
3359 SetLastError(ERROR_INVALID_INDEX); //verified in NT4, SP6
3360 return 0;
3361 }
3362 //Note: NT4, SP6 does not set the last error to 0
3363 SetLastError(ERROR_SUCCESS);
3364 dprintf2(("SetWindowLong%c %x %d %x returned %x", (fUnicode) ? 'W' : 'A', getWindowHandle(), index, value, oldval));
3365 return oldval;
3366}
3367//******************************************************************************
3368//******************************************************************************
3369ULONG Win32BaseWindow::GetWindowLongA(int index, BOOL fUnicode)
3370{
3371 ULONG value;
3372
3373 switch(index) {
3374 case GWL_EXSTYLE:
3375 value = dwExStyle;
3376 break;
3377 case GWL_STYLE:
3378 value = dwStyle;
3379 break;
3380 case GWL_WNDPROC:
3381 value = (LONG)WINPROC_GetProc(win32wndproc, (fUnicode) ? WIN_PROC_32W : WIN_PROC_32A);
3382 break;
3383 case GWL_HINSTANCE:
3384 value = hInstance;
3385 break;
3386 case GWL_HWNDPARENT:
3387 value = GetParent();
3388 break;
3389 case GWL_ID:
3390 value = getWindowId();
3391 break;
3392 case GWL_USERDATA:
3393 value = userData;
3394 break;
3395 default:
3396 if(index >= 0 && index/4 < nrUserWindowLong)
3397 {
3398 value = userWindowLong[index/4];
3399 break;
3400 }
3401 SetLastError(ERROR_INVALID_INDEX); //verified in NT4, SP6
3402 return 0;
3403 }
3404 dprintf2(("GetWindowLongA %x %d %x", getWindowHandle(), index, value));
3405 //Note: NT4, SP6 does not set the last error to 0
3406 SetLastError(ERROR_SUCCESS);
3407 return value;
3408}
3409//******************************************************************************
3410//******************************************************************************
3411WORD Win32BaseWindow::SetWindowWord(int index, WORD value)
3412{
3413 WORD oldval;
3414
3415 if(index >= 0 && index/4 < nrUserWindowLong)
3416 {
3417 oldval = ((WORD *)userWindowLong)[index/2];
3418 ((WORD *)userWindowLong)[index/2] = value;
3419 //Note: NT4, SP6 does not set the last error to 0
3420 SetLastError(ERROR_SUCCESS);
3421 return oldval;
3422 }
3423 SetLastError(ERROR_INVALID_INDEX); //verified in NT4, SP6
3424 return 0;
3425}
3426//******************************************************************************
3427//******************************************************************************
3428WORD Win32BaseWindow::GetWindowWord(int index)
3429{
3430 if(index >= 0 && index/4 < nrUserWindowLong)
3431 {
3432 //Note: NT4, SP6 does not set the last error to 0
3433 SetLastError(ERROR_SUCCESS);
3434 return ((WORD *)userWindowLong)[index/2];
3435 }
3436 SetLastError(ERROR_INVALID_INDEX); //verified in NT4, SP6
3437 return 0;
3438}
3439//******************************************************************************
3440//******************************************************************************
3441void Win32BaseWindow::setWindowId(DWORD id)
3442{
3443 dwIDMenu = id;
3444}
3445//******************************************************************************
3446//******************************************************************************
3447Win32BaseWindow *Win32BaseWindow::GetWindowFromHandle(HWND hwnd)
3448{
3449 Win32BaseWindow *window;
3450
3451 if(HwGetWindowHandleData(hwnd, (DWORD *)&window) == TRUE) {
3452 return window;
3453 }
3454// dprintf2(("Win32BaseWindow::GetWindowFromHandle: not a win32 window %x", hwnd));
3455 return NULL;
3456}
3457//******************************************************************************
3458//******************************************************************************
3459Win32BaseWindow *Win32BaseWindow::GetWindowFromOS2Handle(HWND hwnd)
3460{
3461 Win32BaseWindow *win32wnd;
3462 DWORD magic;
3463
3464 if(hwnd == OSLIB_HWND_DESKTOP)
3465 {
3466 return windowDesktop;
3467 }
3468
3469 win32wnd = (Win32BaseWindow *)OSLibWinGetWindowULong(hwnd, OFFSET_WIN32WNDPTR);
3470 magic = OSLibWinGetWindowULong(hwnd, OFFSET_WIN32PM_MAGIC);
3471
3472 if(win32wnd && CheckMagicDword(magic)) {
3473 return win32wnd;
3474 }
3475// dprintf2(("Win32BaseWindow::GetWindowFromOS2Handle: not an Odin os2 window %x", hwnd));
3476 return 0;
3477}
3478//******************************************************************************
3479//******************************************************************************
3480HWND Win32BaseWindow::getNextDlgGroupItem(HWND hwndCtrl, BOOL fPrevious)
3481{
3482 Win32BaseWindow *child, *nextchild, *lastchild;
3483 HWND retvalue;
3484
3485 if (hwndCtrl)
3486 {
3487 child = GetWindowFromHandle(hwndCtrl);
3488 if (!child)
3489 {
3490 retvalue = 0;
3491 goto END;
3492 }
3493 /* Make sure hwndCtrl is a top-level child */
3494 while ((child->getStyle() & WS_CHILD) && (child->getParent() != this))
3495 {
3496 child = child->getParent();
3497 if(child == NULL) break;
3498 }
3499
3500 if (!child || (child->getParent() != this))
3501 {
3502 retvalue = 0;
3503 goto END;
3504 }
3505 }
3506 else
3507 {
3508 /* No ctrl specified -> start from the beginning */
3509 child = (Win32BaseWindow *)getFirstChild();
3510 if (!child)
3511 {
3512 retvalue = 0;
3513 goto END;
3514 }
3515
3516 if (fPrevious)
3517 {
3518 while (child->getNextChild())
3519 {
3520 child = (Win32BaseWindow *)child->getNextChild();
3521 }
3522 }
3523 }
3524
3525 lastchild = child;
3526 nextchild = (Win32BaseWindow *)child->getNextChild();
3527 while (TRUE)
3528 {
3529 if (!nextchild || (nextchild->getStyle() & WS_GROUP))
3530 {
3531 /* Wrap-around to the beginning of the group */
3532 Win32BaseWindow *pWndTemp;
3533
3534 nextchild = (Win32BaseWindow *)getFirstChild();
3535
3536 for(pWndTemp = nextchild;pWndTemp;pWndTemp = (Win32BaseWindow *)pWndTemp->getNextChild())
3537 {
3538 if (pWndTemp->getStyle() & WS_GROUP)
3539 nextchild = pWndTemp;
3540
3541 if (pWndTemp == child)
3542 break;
3543 }
3544
3545 }
3546 if (nextchild == child)
3547 break;
3548
3549 if ((nextchild->getStyle() & WS_VISIBLE) && !(nextchild->getStyle() & WS_DISABLED))
3550 {
3551 lastchild = nextchild;
3552
3553 if (!fPrevious)
3554 break;
3555 }
3556
3557 nextchild = (Win32BaseWindow *)nextchild->getNextChild();
3558 }
3559 retvalue = lastchild->getWindowHandle();
3560END:
3561 return retvalue;
3562}
3563//******************************************************************************
3564//******************************************************************************
3565#ifdef DEBUG
3566void PrintWindowStyle(DWORD dwStyle, DWORD dwExStyle)
3567{
3568 char style[256] = "";
3569 char exstyle[256] = "";
3570
3571 /* Window styles */
3572 if(dwStyle & WS_CHILD)
3573 strcat(style, "WS_CHILD ");
3574 if(dwStyle & WS_POPUP)
3575 strcat(style, "WS_POPUP ");
3576 if(dwStyle & WS_VISIBLE)
3577 strcat(style, "WS_VISIBLE ");
3578 if(dwStyle & WS_DISABLED)
3579 strcat(style, "WS_DISABLED ");
3580 if(dwStyle & WS_CLIPSIBLINGS)
3581 strcat(style, "WS_CLIPSIBLINGS ");
3582 if(dwStyle & WS_CLIPCHILDREN)
3583 strcat(style, "WS_CLIPCHILDREN ");
3584 if(dwStyle & WS_MAXIMIZE)
3585 strcat(style, "WS_MAXIMIZE ");
3586 if(dwStyle & WS_MINIMIZE)
3587 strcat(style, "WS_MINIMIZE ");
3588 if(dwStyle & WS_GROUP)
3589 strcat(style, "WS_GROUP ");
3590 if(dwStyle & WS_TABSTOP)
3591 strcat(style, "WS_TABSTOP ");
3592
3593 if((dwStyle & WS_CAPTION) == WS_CAPTION)
3594 strcat(style, "WS_CAPTION ");
3595 if(dwStyle & WS_DLGFRAME)
3596 strcat(style, "WS_DLGFRAME ");
3597 if(dwStyle & WS_BORDER)
3598 strcat(style, "WS_BORDER ");
3599
3600 if(dwStyle & WS_VSCROLL)
3601 strcat(style, "WS_VSCROLL ");
3602 if(dwStyle & WS_HSCROLL)
3603 strcat(style, "WS_HSCROLL ");
3604 if(dwStyle & WS_SYSMENU)
3605 strcat(style, "WS_SYSMENU ");
3606 if(dwStyle & WS_THICKFRAME)
3607 strcat(style, "WS_THICKFRAME ");
3608 if(dwStyle & WS_MINIMIZEBOX)
3609 strcat(style, "WS_MINIMIZEBOX ");
3610 if(dwStyle & WS_MAXIMIZEBOX)
3611 strcat(style, "WS_MAXIMIZEBOX ");
3612
3613 if(dwExStyle & WS_EX_DLGMODALFRAME)
3614 strcat(exstyle, "WS_EX_DLGMODALFRAME ");
3615 if(dwExStyle & WS_EX_ACCEPTFILES)
3616 strcat(exstyle, "WS_EX_ACCEPTFILES ");
3617 if(dwExStyle & WS_EX_NOPARENTNOTIFY)
3618 strcat(exstyle, "WS_EX_NOPARENTNOTIFY ");
3619 if(dwExStyle & WS_EX_TOPMOST)
3620 strcat(exstyle, "WS_EX_TOPMOST ");
3621 if(dwExStyle & WS_EX_TRANSPARENT)
3622 strcat(exstyle, "WS_EX_TRANSPARENT ");
3623
3624 if(dwExStyle & WS_EX_MDICHILD)
3625 strcat(exstyle, "WS_EX_MDICHILD ");
3626 if(dwExStyle & WS_EX_TOOLWINDOW)
3627 strcat(exstyle, "WS_EX_TOOLWINDOW ");
3628 if(dwExStyle & WS_EX_WINDOWEDGE)
3629 strcat(exstyle, "WS_EX_WINDOWEDGE ");
3630 if(dwExStyle & WS_EX_CLIENTEDGE)
3631 strcat(exstyle, "WS_EX_CLIENTEDGE ");
3632 if(dwExStyle & WS_EX_CONTEXTHELP)
3633 strcat(exstyle, "WS_EX_CONTEXTHELP ");
3634 if(dwExStyle & WS_EX_RIGHT)
3635 strcat(exstyle, "WS_EX_RIGHT ");
3636 if(dwExStyle & WS_EX_LEFT)
3637 strcat(exstyle, "WS_EX_LEFT ");
3638 if(dwExStyle & WS_EX_RTLREADING)
3639 strcat(exstyle, "WS_EX_RTLREADING ");
3640 if(dwExStyle & WS_EX_LTRREADING)
3641 strcat(exstyle, "WS_EX_LTRREADING ");
3642 if(dwExStyle & WS_EX_LEFTSCROLLBAR)
3643 strcat(exstyle, "WS_EX_LEFTSCROLLBAR ");
3644 if(dwExStyle & WS_EX_RIGHTSCROLLBAR)
3645 strcat(exstyle, "WS_EX_RIGHTSCROLLBAR ");
3646 if(dwExStyle & WS_EX_CONTROLPARENT)
3647 strcat(exstyle, "WS_EX_CONTROLPARENT ");
3648 if(dwExStyle & WS_EX_STATICEDGE)
3649 strcat(exstyle, "WS_EX_STATICEDGE ");
3650 if(dwExStyle & WS_EX_APPWINDOW)
3651 strcat(exstyle, "WS_EX_APPWINDOW ");
3652
3653 dprintf(("Window style: %x %s", dwStyle, style));
3654 dprintf(("Window exStyle: %x %s", dwExStyle, exstyle));
3655}
3656#endif
3657//******************************************************************************
3658//******************************************************************************
3659HWND WIN32API Win32ToOS2Handle(HWND hwnd)
3660{
3661 Win32BaseWindow *window = Win32BaseWindow::GetWindowFromHandle(hwnd);
3662
3663 if(window) {
3664 return window->getOS2WindowHandle();
3665 }
3666// dprintf2(("Win32BaseWindow::Win32ToOS2Handle: not a win32 window %x", hwnd));
3667 return hwnd;
3668}
3669//******************************************************************************
3670//******************************************************************************
3671HWND WIN32API OS2ToWin32Handle(HWND hwnd)
3672{
3673 Win32BaseWindow *window = Win32BaseWindow::GetWindowFromOS2Handle(hwnd);
3674
3675 if(window) {
3676 return window->getWindowHandle();
3677 }
3678// dprintf2(("Win32BaseWindow::OS2ToWin32Handle: not a win32 window %x", hwnd));
3679 return 0;
3680// else return hwnd; //OS/2 window handle
3681}
3682//******************************************************************************
3683//******************************************************************************
3684
3685GenericObject *Win32BaseWindow::windows = NULL;
Note: See TracBrowser for help on using the repository browser.