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

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

ScrollWindow, maximized window + system menu fixes

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