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

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

MDI activation fixes

File size: 125.6 KB
Line 
1/* $Id: win32wbase.cpp,v 1.239 2001-02-20 17:22:05 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 a WM_CHILDACTIVATE message */
928 if((getStyle() & (WS_CHILD | WS_POPUP)) == WS_CHILD )
929 {
930 if(fActivate) {//WM_CHILDACTIVE is for activation only
931 SendInternalMessageA(WM_CHILDACTIVATE, 0, 0L);
932 }
933 return 0;
934 }
935
936 rc = SendInternalMessageA(WM_ACTIVATE, MAKELONG((fActivate) ? WA_ACTIVE : WA_INACTIVE, fMinimized), hwnd);
937
938 if(hwndOS2Win) {
939 threadidhwnd = O32_GetWindowThreadProcessId(hwndOS2Win, &procidhwnd);
940 }
941//Warning: temporary hack to force focus to newly created window
942//RealPlayer 8 does not pass WM_ACTIVATE to defwindowproc and doesn't call
943//setfocus -> keyboard focus not set
944//TODO: Find real cause!!
945 if(GetFocus() == 0 && fActivate) {
946 if(!(getStyle() & WS_MINIMIZE))
947 SetFocus(getWindowHandle());
948 }
949//Warning: temporary hack to force focus to newly created window
950
951 if(fActivate) {
952 SendInternalMessageA(WM_ACTIVATEAPP, 1, dwThreadId); //activate; specify window thread id
953 }
954 else SendInternalMessageA(WM_ACTIVATEAPP, 0, threadidhwnd); //deactivate; specify thread id of other process
955 return rc;
956}
957//******************************************************************************
958//******************************************************************************
959ULONG Win32BaseWindow::DispatchMsgA(MSG *msg)
960{
961 return SendInternalMessageA(msg->message, msg->wParam, msg->lParam);
962}
963//******************************************************************************
964//******************************************************************************
965ULONG Win32BaseWindow::DispatchMsgW(MSG *msg)
966{
967 return SendInternalMessageW(msg->message, msg->wParam, msg->lParam);
968}
969//******************************************************************************
970//******************************************************************************
971ULONG Win32BaseWindow::MsgSetFocus(HWND hwnd)
972{
973 //SvL: Don't send WM_(NC)ACTIVATE messages when the window is being destroyed
974 if(fDestroyWindowCalled) {
975 return 0;
976 }
977
978 return SendInternalMessageA(WM_SETFOCUS, hwnd, 0);
979}
980//******************************************************************************
981//******************************************************************************
982ULONG Win32BaseWindow::MsgKillFocus(HWND hwnd)
983{
984 //SvL: Don't send WM_(NC)ACTIVATE messages when the window is being destroyed
985 if(fDestroyWindowCalled) {
986 return 0;
987 }
988 return SendInternalMessageA(WM_KILLFOCUS, hwnd, 0);
989}
990//******************************************************************************
991//******************************************************************************
992ULONG Win32BaseWindow::MsgButton(MSG *msg)
993{
994 BOOL fClick = FALSE;
995
996// dprintf(("MsgButton at (%d,%d)", msg->pt.x, msg->pt.y));
997 switch(msg->message) {
998 case WM_LBUTTONDBLCLK:
999 case WM_RBUTTONDBLCLK:
1000 case WM_MBUTTONDBLCLK:
1001 if (!(windowClass && windowClass->getClassLongA(GCL_STYLE) & CS_DBLCLKS))
1002 {
1003 msg->message = msg->message - (WM_LBUTTONDBLCLK - WM_LBUTTONDOWN); //dblclick -> down
1004 MsgButton(msg);
1005 msg->message++; //button-up
1006 return MsgButton(msg);
1007 }
1008 break;
1009 case WM_NCLBUTTONDBLCLK:
1010 case WM_NCRBUTTONDBLCLK:
1011 case WM_NCMBUTTONDBLCLK:
1012 //Docs say CS_DBLCLKS style doesn't matter for non-client double clicks
1013 fClick = TRUE;
1014 break;
1015
1016 case WM_LBUTTONDOWN:
1017 case WM_RBUTTONDOWN:
1018 case WM_MBUTTONDOWN:
1019 case WM_NCLBUTTONDOWN:
1020 case WM_NCRBUTTONDOWN:
1021 case WM_NCMBUTTONDOWN:
1022 fClick = TRUE;
1023 break;
1024 }
1025
1026 if(fClick)
1027 {
1028 HWND hwndTop;
1029
1030 /* Activate the window if needed */
1031 hwndTop = (GetTopParent()) ? GetTopParent()->getWindowHandle() : 0;
1032
1033 HWND hwndActive = GetActiveWindow();
1034 if (hwndTop && (getWindowHandle() != hwndActive))
1035 {
1036 LONG ret = SendInternalMessageA(WM_MOUSEACTIVATE, hwndTop,
1037 MAKELONG( lastHitTestVal, msg->message) );
1038
1039#if 0
1040 if ((ret == MA_ACTIVATEANDEAT) || (ret == MA_NOACTIVATEANDEAT))
1041 eatMsg = TRUE;
1042#endif
1043 if(((ret == MA_ACTIVATE) || (ret == MA_ACTIVATEANDEAT))
1044 && (hwndTop != GetForegroundWindow()) )
1045 {
1046 Win32BaseWindow *win32top = Win32BaseWindow::GetWindowFromHandle(hwndTop);
1047
1048 //SvL: Calling OSLibSetActiveWindow(hwndTop); causes focus problems
1049 if (win32top) OSLibWinSetFocus(win32top->getOS2WindowHandle());
1050 }
1051 }
1052 }
1053
1054 SendInternalMessageA(WM_SETCURSOR, getWindowHandle(), MAKELONG(lastHitTestVal, msg->message));
1055
1056 return SendInternalMessageA(msg->message, msg->wParam, msg->lParam);
1057}
1058//******************************************************************************
1059//******************************************************************************
1060ULONG Win32BaseWindow::MsgPaint(ULONG tmp1, BOOL select)
1061{
1062 if (select && IsWindowIconic())
1063 return SendInternalMessageA(WM_PAINTICON, 1, 0);
1064 else
1065 return SendInternalMessageA(WM_PAINT, 0, 0);
1066}
1067//******************************************************************************
1068//TODO: Is the clipper region of the window DC equal to the invalidated rectangle?
1069// (or are we simply erasing too much here)
1070//******************************************************************************
1071ULONG Win32BaseWindow::MsgEraseBackGround(HDC hdc)
1072{
1073 ULONG rc;
1074 HDC hdcErase = hdc;
1075
1076 if (hdcErase == 0)
1077 hdcErase = GetDC(getWindowHandle());
1078
1079 if(IsWindowIconic())
1080 rc = SendInternalMessageA(WM_ICONERASEBKGND, hdcErase, 0);
1081 else
1082 rc = SendInternalMessageA(WM_ERASEBKGND, hdcErase, 0);
1083 if (hdc == 0)
1084 ReleaseDC(getWindowHandle(), hdcErase);
1085 return (rc);
1086}
1087//******************************************************************************
1088//******************************************************************************
1089ULONG Win32BaseWindow::MsgMouseMove(MSG *msg)
1090{
1091 //TODO: hiword should be 0 if window enters menu mode (SDK docs)
1092 SendInternalMessageA(WM_SETCURSOR, Win32Hwnd, MAKELONG(lastHitTestVal, msg->message));
1093
1094 //translated message == WM_(NC)MOUSEMOVE
1095 return SendInternalMessageA(msg->message, msg->wParam, msg->lParam);
1096}
1097//******************************************************************************
1098//******************************************************************************
1099ULONG Win32BaseWindow::MsgChar(MSG *msg)
1100{
1101 return DispatchMsgA(msg);
1102}
1103//******************************************************************************
1104//******************************************************************************
1105ULONG Win32BaseWindow::MsgNCPaint()
1106{
1107 RECT rect;
1108
1109 if(GetOS2UpdateRect(this,&rect))
1110 {
1111 HRGN hrgn;
1112 ULONG rc;
1113 RECT client = rectClient;
1114
1115 if ((rect.left >= client.left) && (rect.left < client.right) &&
1116 (rect.right >= client.left) && (rect.right < client.right) &&
1117 (rect.top >= client.top) && (rect.top < client.bottom) &&
1118 (rect.bottom >= client.top) && (rect.bottom < client.bottom))
1119 {
1120 return 0;
1121 }
1122
1123 dprintf(("MsgNCPaint (%d,%d)(%d,%d)", rect.left, rect.top, rect.right, rect.bottom));
1124 hrgn = CreateRectRgnIndirect(&rect);
1125 if (!hrgn) return 0;
1126
1127 rc = SendInternalMessageA(WM_NCPAINT, hrgn, 0);
1128
1129 DeleteObject(hrgn);
1130
1131 return rc;
1132 }
1133 else return 0;
1134}
1135//******************************************************************************
1136//Called when either the frame's size or position has changed (lpWndPos != NULL)
1137//or when the frame layout has changed (i.e. scrollbars added/removed) (lpWndPos == NULL)
1138//******************************************************************************
1139ULONG Win32BaseWindow::MsgFormatFrame(WINDOWPOS *lpWndPos)
1140{
1141 RECT oldWindowRect = rectWindow, client = rectClient, newWindowRect;
1142 WINDOWPOS wndPos;
1143 ULONG rc;
1144
1145 if(lpWndPos)
1146 {
1147 //set new window rectangle
1148 setWindowRect(lpWndPos->x, lpWndPos->y, lpWndPos->x+lpWndPos->cx,
1149 lpWndPos->y+lpWndPos->cy);
1150 newWindowRect = rectWindow;
1151 }
1152 else {
1153 wndPos.hwnd = getWindowHandle();
1154 wndPos.hwndInsertAfter = 0;
1155 newWindowRect= rectWindow;
1156 wndPos.x = newWindowRect.left;
1157 wndPos.y = newWindowRect.top;
1158 wndPos.cx = newWindowRect.right - newWindowRect.left;
1159 wndPos.cy = newWindowRect.bottom - newWindowRect.top;
1160 wndPos.flags = SWP_FRAMECHANGED;
1161 lpWndPos = &wndPos;
1162 }
1163
1164 rc = SendNCCalcSize(TRUE, &newWindowRect, &oldWindowRect, &client, lpWndPos, &rectClient);
1165
1166 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));
1167 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));
1168
1169#if 1
1170//this doesn't always work
1171// if(!fNoSizeMsg && (client.left != rectClient.left || client.top != rectClient.top))
1172 if(!fNoSizeMsg && ((oldWindowRect.right - oldWindowRect.left < rectClient.left
1173 || oldWindowRect.bottom - oldWindowRect.top < rectClient.top) ||
1174 (EqualRect(&oldWindowRect, &rectWindow) && (client.left != rectClient.left || client.top != rectClient.top))))
1175 {
1176 Win32BaseWindow *child = (Win32BaseWindow *)getFirstChild();
1177
1178 //client rectangle has moved -> inform children
1179 dprintf(("MsgFormatFrame -> client rectangle has changed, move children"));
1180 while(child) {
1181 ::SetWindowPos(child->getWindowHandle(),
1182 HWND_TOP, child->getWindowRect()->left,
1183 child->getWindowRect()->top, 0, 0,
1184 SWP_NOACTIVATE|SWP_NOSIZE|SWP_NOZORDER);
1185 child = (Win32BaseWindow *)child->getNextChild();
1186 }
1187 }
1188#endif
1189 return rc;
1190}
1191//******************************************************************************
1192//******************************************************************************
1193ULONG Win32BaseWindow::MsgSetText(LPSTR lpsz, LONG cch)
1194{
1195 return SendInternalMessageA(WM_SETTEXT, 0, (LPARAM)lpsz);
1196}
1197//******************************************************************************
1198//******************************************************************************
1199ULONG Win32BaseWindow::MsgGetTextLength()
1200{
1201 return SendInternalMessageA(WM_GETTEXTLENGTH, 0, 0);
1202}
1203//******************************************************************************
1204//******************************************************************************
1205void Win32BaseWindow::MsgGetText(char *wndtext, ULONG textlength)
1206{
1207 SendInternalMessageA(WM_GETTEXT, textlength, (LPARAM)wndtext);
1208}
1209//******************************************************************************
1210//******************************************************************************
1211LONG Win32BaseWindow::sendHitTest(ULONG lParam)
1212{
1213 lastHitTestVal = SendInternalMessageA(WM_NCHITTEST, 0, lParam);
1214 return lastHitTestVal;
1215}
1216//******************************************************************************
1217//******************************************************************************
1218BOOL Win32BaseWindow::isMDIClient()
1219{
1220 return FALSE;
1221}
1222//******************************************************************************
1223//******************************************************************************
1224BOOL Win32BaseWindow::isMDIChild()
1225{
1226 return FALSE;
1227}
1228//******************************************************************************
1229//TODO: Not complete
1230//******************************************************************************
1231BOOL Win32BaseWindow::isFrameWindow()
1232{
1233 if(getParent() == NULL)
1234 return TRUE;
1235
1236 return FALSE;
1237}
1238//******************************************************************************
1239//******************************************************************************
1240BOOL Win32BaseWindow::isDesktopWindow()
1241{
1242 return FALSE;
1243}
1244//******************************************************************************
1245//******************************************************************************
1246BOOL Win32BaseWindow::IsWindowIconic()
1247{
1248 return ((getStyle() & WS_MINIMIZE) && windowClass->getIcon());
1249}
1250//******************************************************************************
1251//******************************************************************************
1252SCROLLBAR_INFO *Win32BaseWindow::getScrollInfo(int nBar)
1253{
1254 switch(nBar)
1255 {
1256 case SB_HORZ:
1257 if (!horzScrollInfo)
1258 {
1259 horzScrollInfo = (SCROLLBAR_INFO*)malloc(sizeof(SCROLLBAR_INFO));
1260 if (!horzScrollInfo) break;
1261 horzScrollInfo->MinVal = horzScrollInfo->CurVal = horzScrollInfo->Page = 0;
1262 horzScrollInfo->MaxVal = 100;
1263 horzScrollInfo->flags = ESB_ENABLE_BOTH;
1264 }
1265 return horzScrollInfo;
1266
1267 case SB_VERT:
1268 if (!vertScrollInfo)
1269 {
1270 vertScrollInfo = (SCROLLBAR_INFO*)malloc(sizeof(SCROLLBAR_INFO));
1271 if (!vertScrollInfo) break;
1272 vertScrollInfo->MinVal = vertScrollInfo->CurVal = vertScrollInfo->Page = 0;
1273 vertScrollInfo->MaxVal = 100;
1274 vertScrollInfo->flags = ESB_ENABLE_BOTH;
1275 }
1276 return vertScrollInfo;
1277 }
1278
1279 return NULL;
1280}
1281//******************************************************************************
1282//******************************************************************************
1283LRESULT Win32BaseWindow::DefWndControlColor(UINT ctlType, HDC hdc)
1284{
1285 //SvL: Set background color to default button color (not window (white))
1286 if(ctlType == CTLCOLOR_BTN)
1287 {
1288 SetBkColor(hdc, GetSysColor(COLOR_BTNFACE));
1289 SetTextColor(hdc, GetSysColor(COLOR_WINDOWTEXT));
1290 return GetSysColorBrush(COLOR_BTNFACE);
1291 }
1292 //SvL: Set background color to default dialog color if window is dialog
1293 if((ctlType == CTLCOLOR_DLG || ctlType == CTLCOLOR_STATIC) && IsDialog()) {
1294 SetBkColor(hdc, GetSysColor(COLOR_BTNFACE));
1295 SetTextColor(hdc, GetSysColor(COLOR_WINDOWTEXT));
1296 return GetSysColorBrush(COLOR_BTNFACE);
1297 }
1298
1299 if( ctlType == CTLCOLOR_SCROLLBAR)
1300 {
1301 HBRUSH hb = GetSysColorBrush(COLOR_SCROLLBAR);
1302 COLORREF bk = GetSysColor(COLOR_3DHILIGHT);
1303 SetTextColor( hdc, GetSysColor(COLOR_3DFACE));
1304 SetBkColor( hdc, bk);
1305
1306 /* if COLOR_WINDOW happens to be the same as COLOR_3DHILIGHT
1307 * we better use 0x55aa bitmap brush to make scrollbar's background
1308 * look different from the window background.
1309 */
1310 if (bk == GetSysColor(COLOR_WINDOW)) {
1311 return GetPattern55AABrush();
1312 }
1313
1314 UnrealizeObject( hb );
1315 return (LRESULT)hb;
1316 }
1317
1318 SetTextColor( hdc, GetSysColor(COLOR_WINDOWTEXT));
1319
1320 if ((ctlType == CTLCOLOR_EDIT) || (ctlType == CTLCOLOR_LISTBOX))
1321 {
1322 SetBkColor( hdc, GetSysColor(COLOR_WINDOW) );
1323 }
1324 else
1325 {
1326 SetBkColor( hdc, GetSysColor(COLOR_3DFACE) );
1327 return (LRESULT)GetSysColorBrush(COLOR_3DFACE);
1328 }
1329 return (LRESULT)GetSysColorBrush(COLOR_WINDOW);
1330}
1331//******************************************************************************
1332//******************************************************************************
1333LRESULT Win32BaseWindow::DefWndPrint(HDC hdc,ULONG uFlags)
1334{
1335 /*
1336 * Visibility flag.
1337 */
1338 if ( (uFlags & PRF_CHECKVISIBLE) &&
1339 !IsWindowVisible() )
1340 return 0;
1341
1342 /*
1343 * Unimplemented flags.
1344 */
1345 if ( (uFlags & PRF_CHILDREN) ||
1346 (uFlags & PRF_OWNED) ||
1347 (uFlags & PRF_NONCLIENT) )
1348 {
1349 dprintf(("WM_PRINT message with unsupported flags\n"));
1350 }
1351
1352 /*
1353 * Background
1354 */
1355 if ( uFlags & PRF_ERASEBKGND)
1356 SendInternalMessageA(WM_ERASEBKGND, (WPARAM)hdc, 0);
1357
1358 /*
1359 * Client area
1360 */
1361 if ( uFlags & PRF_CLIENT)
1362 SendInternalMessageA(WM_PRINTCLIENT, (WPARAM)hdc, PRF_CLIENT);
1363
1364
1365 return 0;
1366}
1367//******************************************************************************
1368//******************************************************************************
1369LRESULT Win32BaseWindow::DefWindowProcA(UINT Msg, WPARAM wParam, LPARAM lParam)
1370{
1371 switch(Msg)
1372 {
1373 case WM_CLOSE:
1374 dprintf(("DefWindowProcA: WM_CLOSE %x", getWindowHandle()));
1375 DestroyWindow();
1376 return 0;
1377
1378 case WM_GETTEXTLENGTH:
1379 return wndNameLength;
1380
1381 case WM_GETTEXT:
1382 if (!lParam || !wParam) return 0;
1383 if (!windowNameA) ((LPSTR)lParam)[0] = 0;
1384 else lstrcpynA((LPSTR)lParam, windowNameA, wParam);
1385 return min(wndNameLength, wParam);
1386
1387 case WM_SETTEXT:
1388 {
1389 LPCSTR lpsz = (LPCSTR)lParam;
1390
1391 if(windowNameA) free(windowNameA);
1392 if(windowNameW) free(windowNameW);
1393 if (lParam)
1394 {
1395 wndNameLength = strlen(lpsz);
1396 windowNameA = (LPSTR)_smalloc(wndNameLength+1);
1397 strcpy(windowNameA, lpsz);
1398 windowNameW = (LPWSTR)_smalloc((wndNameLength+1)*sizeof(WCHAR));
1399 lstrcpyAtoW(windowNameW, windowNameA);
1400 }
1401 else
1402 {
1403 windowNameA = NULL;
1404 windowNameW = NULL;
1405 wndNameLength = 0;
1406 }
1407 dprintf(("WM_SETTEXT of %x to %s\n", Win32Hwnd, lParam));
1408 if ((dwStyle & WS_CAPTION) == WS_CAPTION)
1409 {
1410 HandleNCPaint((HRGN)1);
1411 if(hTaskList) {
1412 OSLibWinChangeTaskList(hTaskList, OS2Hwnd, getWindowNameA(), (getStyle() & WS_VISIBLE) ? 1 : 0);
1413 }
1414 }
1415
1416 return TRUE;
1417 }
1418
1419 case WM_SETREDRAW:
1420 {
1421 if (wParam)
1422 {
1423 setStyle(getStyle() | WS_VISIBLE);
1424 OSLibWinEnableWindowUpdate(OS2Hwnd,TRUE);
1425 }
1426 else
1427 {
1428 if (getStyle() & WS_VISIBLE)
1429 {
1430 setStyle(getStyle() & ~WS_VISIBLE);
1431 OSLibWinEnableWindowUpdate(OS2Hwnd,FALSE);
1432 }
1433 }
1434 return 0;
1435 }
1436
1437 case WM_CTLCOLORMSGBOX:
1438 case WM_CTLCOLOREDIT:
1439 case WM_CTLCOLORLISTBOX:
1440 case WM_CTLCOLORBTN:
1441 case WM_CTLCOLORDLG:
1442 case WM_CTLCOLORSTATIC:
1443 case WM_CTLCOLORSCROLLBAR:
1444 return DefWndControlColor(Msg - WM_CTLCOLORMSGBOX, (HDC)wParam);
1445
1446 case WM_CTLCOLOR:
1447 return DefWndControlColor(HIWORD(lParam), (HDC)wParam);
1448
1449 case WM_VKEYTOITEM:
1450 case WM_CHARTOITEM:
1451 return -1;
1452
1453 case WM_PARENTNOTIFY:
1454 return 0;
1455
1456 case WM_MOUSEACTIVATE:
1457 {
1458 dprintf(("DefWndProc: WM_MOUSEACTIVATE for %x Msg %s", Win32Hwnd, GetMsgText(HIWORD(lParam))));
1459 if(getStyle() & WS_CHILD && !(getExStyle() & WS_EX_NOPARENTNOTIFY) )
1460 {
1461 if(getParent()) {
1462 LRESULT rc = getParent()->SendInternalMessageA(WM_MOUSEACTIVATE, wParam, lParam );
1463 if(rc) return rc;
1464 }
1465 }
1466 return (LOWORD(lParam) == HTCAPTION) ? MA_NOACTIVATE : MA_ACTIVATE;
1467 }
1468
1469 case WM_ACTIVATE:
1470 /* The default action in Windows is to set the keyboard focus to
1471 * the window, if it's being activated and not minimized */
1472 if (LOWORD(wParam) != WA_INACTIVE) {
1473 if(!(getStyle() & WS_MINIMIZE))
1474 SetFocus(getWindowHandle());
1475 }
1476 return 0;
1477
1478 case WM_SETCURSOR:
1479 {
1480 dprintf(("DefWndProc: WM_SETCURSOR for %x Msg %s", Win32Hwnd, GetMsgText(HIWORD(lParam))));
1481 if((getStyle() & WS_CHILD) && !(getExStyle() & WS_EX_NOPARENTNOTIFY))
1482 {
1483 if(getParent()) {
1484 LRESULT rc = getParent()->SendInternalMessageA(WM_SETCURSOR, wParam, lParam);
1485 if(rc) return rc;
1486 }
1487 }
1488 if (wParam == Win32Hwnd)
1489 {
1490 HCURSOR hCursor;
1491
1492 switch(LOWORD(lParam))
1493 {
1494 case HTCLIENT:
1495 hCursor = windowClass ? windowClass->getCursor():LoadCursorA(0,IDC_ARROWA);
1496 break;
1497
1498 case HTLEFT:
1499 case HTRIGHT:
1500 hCursor = LoadCursorA(0,IDC_SIZEWEA);
1501 break;
1502
1503 case HTTOP:
1504 case HTBOTTOM:
1505 hCursor = LoadCursorA(0,IDC_SIZENSA);
1506 break;
1507
1508 case HTTOPLEFT:
1509 case HTBOTTOMRIGHT:
1510 hCursor = LoadCursorA(0,IDC_SIZENWSEA);
1511 break;
1512
1513 case HTTOPRIGHT:
1514 case HTBOTTOMLEFT:
1515 hCursor = LoadCursorA(0,IDC_SIZENESWA);
1516 break;
1517
1518 default:
1519 hCursor = LoadCursorA(0,IDC_ARROWA);
1520 break;
1521 }
1522
1523 if (hCursor)
1524 {
1525 SetCursor(hCursor);
1526 return 1;
1527 }
1528 else return 0;
1529 }
1530 else return 0;
1531 }
1532
1533 case WM_MOUSEMOVE:
1534 return 0;
1535
1536 case WM_WINDOWPOSCHANGED:
1537 {
1538 PWINDOWPOS wpos = (PWINDOWPOS)lParam;
1539 WPARAM wp = SIZE_RESTORED;
1540
1541 if (!(wpos->flags & SWP_NOMOVE) && !(wpos->flags & SWP_NOCLIENTMOVE))
1542 {
1543 SendInternalMessageA(WM_MOVE, 0, MAKELONG(rectClient.left,rectClient.top));
1544 }
1545 if (!(wpos->flags & SWP_NOSIZE) && !(wpos->flags & SWP_NOCLIENTSIZE))
1546 {
1547 if (dwStyle & WS_MAXIMIZE) wp = SIZE_MAXIMIZED;
1548 else
1549 if (dwStyle & WS_MINIMIZE) wp = SIZE_MINIMIZED;
1550
1551 SendInternalMessageA(WM_SIZE, wp, MAKELONG(rectClient.right - rectClient.left,
1552 rectClient.bottom - rectClient.top));
1553 }
1554 return 0;
1555 }
1556 case WM_WINDOWPOSCHANGING:
1557 return HandleWindowPosChanging((WINDOWPOS *)lParam);
1558
1559 case WM_ERASEBKGND:
1560 case WM_ICONERASEBKGND:
1561 {
1562 RECT rect;
1563 int rc;
1564
1565 if (!windowClass || !windowClass->getBackgroundBrush()) return 0;
1566
1567 rc = GetClipBox( (HDC)wParam, &rect );
1568 if ((rc == SIMPLEREGION) || (rc == COMPLEXREGION))
1569 {
1570 HBRUSH hBrush = windowClass->getBackgroundBrush();
1571
1572 if (hBrush <= (HBRUSH)(SYSCOLOR_GetLastColor()+1))
1573 hBrush = GetSysColorBrush(hBrush-1);
1574
1575 FillRect( (HDC)wParam, &rect, hBrush);
1576 }
1577 return 1;
1578 }
1579
1580 case WM_PRINT:
1581 return DefWndPrint(wParam,lParam);
1582
1583 case WM_PAINTICON:
1584 case WM_PAINT:
1585 {
1586 PAINTSTRUCT ps;
1587 HDC hdc = BeginPaint(getWindowHandle(), &ps );
1588 if( hdc )
1589 {
1590 if( (getStyle() & WS_MINIMIZE) && (getWindowClass()->getIcon() && hIcon))
1591 {
1592 int x = (rectWindow.right - rectWindow.left - GetSystemMetrics(SM_CXICON))/2;
1593 int y = (rectWindow.bottom - rectWindow.top - GetSystemMetrics(SM_CYICON))/2;
1594 dprintf(("Painting class icon: vis rect=(%i,%i - %i,%i)\n", ps.rcPaint.left, ps.rcPaint.top, ps.rcPaint.right, ps.rcPaint.bottom ));
1595 DrawIcon(hdc, x, y, hIcon ? hIcon:getWindowClass()->getIcon() );
1596 }
1597 EndPaint(getWindowHandle(), &ps );
1598 }
1599 return 0;
1600 }
1601
1602 case WM_GETDLGCODE:
1603 return 0;
1604
1605 case WM_NCPAINT:
1606 return HandleNCPaint((HRGN)wParam);
1607
1608 case WM_NCACTIVATE:
1609 return HandleNCActivate(wParam);
1610
1611 case WM_NCCREATE:
1612 return(TRUE);
1613
1614 case WM_NCDESTROY:
1615 return 0;
1616
1617 case WM_NCCALCSIZE:
1618 return HandleNCCalcSize((BOOL)wParam,(RECT*)lParam);
1619
1620 case WM_NCLBUTTONDOWN:
1621 return HandleNCLButtonDown(wParam,lParam);
1622
1623 case WM_LBUTTONDBLCLK:
1624 case WM_NCLBUTTONDBLCLK:
1625 return HandleNCLButtonDblClk(wParam,lParam);
1626
1627 case WM_NCRBUTTONDOWN:
1628 case WM_NCRBUTTONDBLCLK:
1629 case WM_NCMBUTTONDOWN:
1630 case WM_NCMBUTTONDBLCLK:
1631 if (lastHitTestVal == HTERROR) MessageBeep(MB_ICONEXCLAMATION);
1632 return 0;
1633
1634 case WM_NCRBUTTONUP:
1635 return HandleNCRButtonUp(wParam,lParam);
1636
1637 case WM_NCMBUTTONUP:
1638 return 0;
1639
1640 case WM_NCHITTEST:
1641 {
1642 POINT point;
1643 LRESULT retvalue;
1644
1645 point.x = (SHORT)LOWORD(lParam);
1646 point.y = (SHORT)HIWORD(lParam);
1647
1648 retvalue = HandleNCHitTest(point);
1649#if 0 //CB: let the Corel people fix the bugs first
1650 if(retvalue == HTMENU)
1651 MENU_TrackMouseMenuBar_MouseMove(Win32Hwnd,point,TRUE);
1652 else
1653 MENU_TrackMouseMenuBar_MouseMove(Win32Hwnd,point,FALSE);
1654#endif
1655 return retvalue;
1656 }
1657
1658 case WM_SYSCOMMAND:
1659 {
1660 POINT point;
1661
1662 point.x = LOWORD(lParam);
1663 point.y = HIWORD(lParam);
1664 return HandleSysCommand(wParam,&point);
1665 }
1666
1667 case WM_SYSKEYDOWN:
1668 if(wParam == VK_F4) /* try to close the window */
1669 {
1670 Win32BaseWindow *window = GetTopParent();
1671 if(window && !(window->getClass()->getStyle() & CS_NOCLOSE))
1672 PostMessageA(window->getWindowHandle(), WM_SYSCOMMAND, SC_CLOSE, 0);
1673 return 0;
1674 }
1675
1676 Win32BaseWindow *siblingWindow;
1677 HWND sibling;
1678 char nameBuffer [40], mnemonic;
1679 int nameLength;
1680
1681 GetWindowTextA (nameBuffer, 40);
1682
1683 // search all sibling to see it this key is their mnemonic
1684 sibling = GetWindow (GW_HWNDFIRST);
1685 while (sibling != 0) {
1686 siblingWindow = GetWindowFromHandle (sibling);
1687 nameLength = siblingWindow->GetWindowTextA (nameBuffer, 40);
1688
1689 // find the siblings mnemonic
1690 mnemonic = '\0';
1691 for (int i=0 ; i<nameLength ; i++) {
1692 if (nameBuffer [i] == '&') {
1693 mnemonic = nameBuffer [i+1];
1694 if ((mnemonic >= 'a') && (mnemonic <= 'z'))
1695 mnemonic -= 32; // make it uppercase
1696 break; // stop searching
1697 }
1698 }
1699
1700 // key matches siblings mnemonic, send mouseclick
1701 if (mnemonic == (char) wParam) {
1702 siblingWindow->SendInternalMessageA (BM_CLICK, 0, 0);
1703 }
1704
1705 sibling = siblingWindow->GetNextWindow (GW_HWNDNEXT);
1706 }
1707
1708 return 0;
1709
1710#if 0 //CB: todo: MSDN docu: Windown handles these messages and not WM_SYSCHAR (the code below doesn't work)
1711 case WM_KEYDOWN:
1712 case WM_KEYUP:
1713 case WM_SYSKEYDOWN:
1714 case WM_SYSKEYUP:
1715#endif
1716
1717 case WM_SYSCHAR:
1718 {
1719 int iMenuSysKey = 0;
1720 if (wParam == VK_RETURN && (getStyle() & WS_MINIMIZE))
1721 {
1722 PostMessageA(getWindowHandle(), WM_SYSCOMMAND,
1723 (WPARAM)SC_RESTORE, 0L );
1724 break;
1725 }
1726 if((HIWORD(lParam) & KEYDATA_ALT) && wParam)
1727 {
1728 if (wParam == VK_TAB || wParam == VK_ESCAPE || wParam == VK_F4)
1729 break;
1730 if (wParam == VK_SPACE && (getStyle() & WS_CHILD)) {
1731 getParent()->SendMessageA(Msg, wParam, lParam );
1732 }
1733 else SendMessageA(WM_SYSCOMMAND, (WPARAM)SC_KEYMENU, (LPARAM)(DWORD)wParam );
1734 }
1735#if 0
1736 else /* check for Ctrl-Esc */
1737 if (wParam != VK_ESCAPE) MessageBeep(0);
1738 break;
1739#endif
1740 }
1741
1742 case WM_SETHOTKEY:
1743 hotkey = wParam;
1744 return 1; //CB: always successful
1745
1746 case WM_GETHOTKEY:
1747 return hotkey;
1748
1749 case WM_CONTEXTMENU:
1750 if ((dwStyle & WS_CHILD) && getParent())
1751 getParent()->SendInternalMessageA(WM_CONTEXTMENU,wParam,lParam);
1752 return 0;
1753
1754 case WM_SHOWWINDOW:
1755 if (!lParam) return 0; /* sent from ShowWindow */
1756 if (!(dwStyle & WS_POPUP) || !owner) return 0;
1757 if ((dwStyle & WS_VISIBLE) && wParam) return 0;
1758 else if (!(dwStyle & WS_VISIBLE) && !wParam) return 0;
1759 ShowWindow(wParam ? SW_SHOW:SW_HIDE);
1760 return 0;
1761
1762 case WM_CANCELMODE:
1763 if (getParent() == windowDesktop) EndMenu();
1764 if (GetCapture() == Win32Hwnd) ReleaseCapture();
1765 return 0;
1766
1767 case WM_DROPOBJECT:
1768 return DRAG_FILE;
1769
1770 case WM_QUERYDROPOBJECT:
1771 return (dwExStyle & WS_EX_ACCEPTFILES) ? 1:0;
1772
1773 case WM_QUERYDRAGICON:
1774 {
1775 HICON hDragIcon = windowClass->getCursor();
1776 UINT len;
1777
1778 if(hDragIcon) return (LRESULT)hDragIcon;
1779 for(len = 1; len < 64; len++)
1780 {
1781 hDragIcon = LoadIconA(hInstance,MAKEINTRESOURCEA(len));
1782 if(hDragIcon)
1783 return (LRESULT)hDragIcon;
1784 }
1785 return (LRESULT)LoadIconA(0,IDI_APPLICATIONA);
1786 }
1787
1788 case WM_QUERYOPEN:
1789 case WM_QUERYENDSESSION:
1790 return 1;
1791
1792 case WM_NOTIFYFORMAT:
1793 return IsWindowUnicode() ? NFR_UNICODE:NFR_ANSI;
1794
1795 case WM_SETICON:
1796 case WM_GETICON:
1797 {
1798 LRESULT result = 0;
1799
1800 /* Set the appropriate icon members in the window structure. */
1801 if (wParam == ICON_SMALL)
1802 {
1803 result = hIconSm;
1804 if (Msg == WM_SETICON)
1805 hIconSm = (HICON)lParam;
1806 }
1807 else
1808 {
1809 result = hIcon;
1810 if (Msg == WM_SETICON)
1811 {
1812 hIcon = (HICON)lParam;
1813 if ((dwStyle & WS_CAPTION) == WS_CAPTION)
1814 OSLibWinSetIcon(OS2Hwnd,hIcon);
1815 }
1816 }
1817 if ((Msg == WM_SETICON) && ((dwStyle & WS_CAPTION) == WS_CAPTION))
1818 HandleNCPaint((HRGN)1);
1819
1820 return result;
1821 }
1822
1823 case WM_HELP:
1824 if (getParent()) getParent()->SendInternalMessageA(Msg,wParam,lParam);
1825 break;
1826
1827 case WM_NOTIFY:
1828 return 0; //comctl32 controls expect this
1829
1830 default:
1831 return 0;
1832 }
1833 return 0;
1834}
1835//******************************************************************************
1836//******************************************************************************
1837LRESULT Win32BaseWindow::DefWindowProcW(UINT Msg, WPARAM wParam, LPARAM lParam)
1838{
1839 switch(Msg)
1840 {
1841 case WM_GETTEXTLENGTH:
1842 return wndNameLength;
1843
1844 case WM_GETTEXT:
1845 if (!lParam || !wParam) return 0;
1846 if (!windowNameW) ((LPWSTR)lParam)[0] = 0;
1847 else lstrcpynW((LPWSTR)lParam,windowNameW,wParam);
1848 return min(wndNameLength,wParam);
1849
1850 case WM_SETTEXT:
1851 {
1852 LPWSTR lpsz = (LPWSTR)lParam;
1853
1854 if(windowNameA) free(windowNameA);
1855 if(windowNameW) free(windowNameW);
1856 if (lParam)
1857 {
1858 wndNameLength = lstrlenW(lpsz);
1859 windowNameA = (LPSTR)_smalloc(wndNameLength+1);
1860 lstrcpyWtoA(windowNameA,lpsz);
1861 windowNameW = (LPWSTR)_smalloc((wndNameLength+1)*sizeof(WCHAR));
1862 lstrcpyW(windowNameW,lpsz);
1863 }
1864 else
1865 {
1866 windowNameA = NULL;
1867 windowNameW = NULL;
1868 wndNameLength = 0;
1869 }
1870 dprintf(("WM_SETTEXT of %x\n",Win32Hwnd));
1871 if ((dwStyle & WS_CAPTION) == WS_CAPTION)
1872 {
1873 HandleNCPaint((HRGN)1);
1874 if(hTaskList) {
1875 OSLibWinChangeTaskList(hTaskList, OS2Hwnd, getWindowNameA(), (getStyle() & WS_VISIBLE) ? 1 : 0);
1876 }
1877 }
1878
1879 return TRUE;
1880 }
1881
1882 default:
1883 return DefWindowProcA(Msg, wParam, lParam);
1884 }
1885}
1886//******************************************************************************
1887//******************************************************************************
1888LRESULT Win32BaseWindow::SendMessageA(ULONG Msg, WPARAM wParam, LPARAM lParam)
1889{
1890 //if the destination window is created by this process & thread, call window proc directly
1891 if(dwProcessId == currentProcessId && dwThreadId == GetCurrentThreadId()) {
1892 return SendInternalMessageA(Msg, wParam, lParam);
1893 }
1894 //otherwise use WinSendMsg to send it to the right process/thread
1895 dprintf(("SendMessages (inter-process) %x %x %x %x", getWindowHandle(), Msg, wParam, lParam));
1896 return OSLibSendMessage(getOS2WindowHandle(), Msg, wParam, lParam, FALSE);
1897}
1898//******************************************************************************
1899//******************************************************************************
1900LRESULT Win32BaseWindow::SendMessageW(ULONG Msg, WPARAM wParam, LPARAM lParam)
1901{
1902 //if the destination window is created by this process & thread, call window proc directly
1903 if(dwProcessId == currentProcessId && dwThreadId == GetCurrentThreadId()) {
1904 return SendInternalMessageW(Msg, wParam, lParam);
1905 }
1906 //otherwise use WinSendMsg to send it to the right process/thread
1907 return OSLibSendMessage(getOS2WindowHandle(), Msg, wParam, lParam, TRUE);
1908}
1909//******************************************************************************
1910//Called as a result of an OS/2 message or called from a class method
1911//******************************************************************************
1912LRESULT Win32BaseWindow::SendInternalMessageA(ULONG Msg, WPARAM wParam, LPARAM lParam)
1913{
1914 LRESULT rc;
1915 HWND hwnd = getWindowHandle();
1916 BOOL fInternalMsgBackup = fInternalMsg;
1917
1918 //if the destination window was created by this process & thread, call window proc directly
1919 if(dwProcessId != currentProcessId || dwThreadId != GetCurrentThreadId()) {
1920 dprintf(("SendMessages (inter-process) %x %x %x %x", getWindowHandle(), Msg, wParam, lParam));
1921 return OSLibSendMessage(getOS2WindowHandle(), Msg, wParam, lParam, FALSE);
1922 }
1923
1924 DebugPrintMessage(getWindowHandle(), Msg, wParam, lParam, FALSE, TRUE);
1925
1926 CallWindowHookProc(WH_CALLWNDPROC, Msg, wParam, lParam, FALSE);
1927
1928 fInternalMsg = TRUE;
1929 switch(Msg)
1930 {
1931 case WM_CREATE:
1932 {
1933 if(CallWindowProcA(win32wndproc, getWindowHandle(), WM_CREATE, 0, lParam) == -1) {
1934 dprintf(("WM_CREATE returned -1\n"));
1935 rc = -1; //don't create window
1936 break;
1937 }
1938 rc = 0;
1939 break;
1940 }
1941 case WM_LBUTTONDOWN:
1942 case WM_MBUTTONDOWN:
1943 case WM_RBUTTONDOWN:
1944 {
1945 if (getParent())
1946 {
1947 POINTS pt = MAKEPOINTS(lParam);
1948 POINT point;
1949
1950 point.x = pt.x;
1951 point.y = pt.y;
1952 MapWindowPoints(getWindowHandle(), getParent()->getWindowHandle(), &point, 1);
1953 NotifyParent(Msg,wParam,MAKELPARAM(point.x,point.y));
1954 }
1955 rc = win32wndproc(getWindowHandle(), Msg, wParam, lParam);
1956 break;
1957 }
1958
1959 case WM_DESTROY:
1960 rc = win32wndproc(getWindowHandle(), WM_DESTROY, 0, 0);
1961 break;
1962
1963 default:
1964 rc = CallWindowProcA(win32wndproc, getWindowHandle(), Msg, wParam, lParam);
1965 break;
1966 }
1967 if(!::IsWindow(hwnd)) {
1968 //window might have been destroyed by now. (this pointer invalid)
1969 //we must return immediately
1970 //(MS Visual C++ install heap corruption)
1971 //TODO: could happen in several places here!!!!
1972 return rc;
1973 }
1974 fInternalMsg = fInternalMsgBackup;
1975 return rc;
1976}
1977//******************************************************************************
1978//Called as a result of an OS/2 message or called from a class method
1979//******************************************************************************
1980LRESULT Win32BaseWindow::SendInternalMessageW(ULONG Msg, WPARAM wParam, LPARAM lParam)
1981{
1982 LRESULT rc;
1983 HWND hwnd = getWindowHandle();
1984 BOOL fInternalMsgBackup = fInternalMsg;
1985
1986 //if the destination window was created by this process & thread, call window proc directly
1987 if(dwProcessId != currentProcessId || dwThreadId != GetCurrentThreadId()) {
1988 dprintf(("SendMessages (inter-process) %x %x %x %x", getWindowHandle(), Msg, wParam, lParam));
1989 return OSLibSendMessage(getOS2WindowHandle(), Msg, wParam, lParam, FALSE);
1990 }
1991
1992 DebugPrintMessage(getWindowHandle(), Msg, wParam, lParam, TRUE, TRUE);
1993
1994 CallWindowHookProc(WH_CALLWNDPROC, Msg, wParam, lParam, TRUE);
1995
1996 fInternalMsg = TRUE;
1997 switch(Msg)
1998 {
1999 case WM_CREATE:
2000 {
2001 if(CallWindowProcW(win32wndproc, getWindowHandle(), WM_CREATE, 0, lParam) == -1) {
2002 dprintf(("WM_CREATE returned -1\n"));
2003 rc = -1; //don't create window
2004 break;
2005 }
2006 rc = 0;
2007 break;
2008 }
2009 case WM_LBUTTONDOWN:
2010 case WM_MBUTTONDOWN:
2011 case WM_RBUTTONDOWN:
2012 NotifyParent(Msg, wParam, lParam);
2013 rc = win32wndproc(getWindowHandle(), Msg, wParam, lParam);
2014 break;
2015
2016 case WM_DESTROY:
2017 rc = win32wndproc(getWindowHandle(), WM_DESTROY, 0, 0);
2018 break;
2019 default:
2020 rc = CallWindowProcW(win32wndproc, getWindowHandle(), Msg, wParam, lParam);
2021 break;
2022 }
2023 if(!::IsWindow(hwnd)) {
2024 //window might have been destroyed by now. (this pointer invalid)
2025 //we must return immediately
2026 //(MS Visual C++ install heap corruption)
2027 //TODO: could happen in several places here!!!!
2028 return rc;
2029 }
2030 fInternalMsg = fInternalMsgBackup;
2031 return rc;
2032}
2033//******************************************************************************
2034//******************************************************************************
2035void Win32BaseWindow::CallWindowHookProc(ULONG hooktype, ULONG Msg, WPARAM wParam, LPARAM lParam, BOOL fUnicode)
2036{
2037 CWPSTRUCT cwp;
2038
2039 cwp.lParam = lParam;
2040 cwp.wParam = wParam;
2041 cwp.message = Msg;
2042 cwp.hwnd = getWindowHandle();
2043
2044 switch(hooktype) {
2045 case WH_CALLWNDPROC:
2046 if(fUnicode) {
2047 HOOK_CallHooksW(WH_CALLWNDPROC, HC_ACTION, 1, (LPARAM)&cwp);
2048 }
2049 else HOOK_CallHooksA(WH_CALLWNDPROC, HC_ACTION, 1, (LPARAM)&cwp);
2050 break;
2051 }
2052}
2053//******************************************************************************
2054//TODO: Do this more efficiently
2055//******************************************************************************
2056LRESULT Win32BaseWindow::BroadcastMessageA(int type, UINT msg, WPARAM wParam, LPARAM lParam)
2057{
2058 Win32BaseWindow *window;
2059 HWND hwnd = WNDHANDLE_MAGIC_HIGHWORD;
2060
2061 dprintf(("BroadCastMessageA %x %x %x", msg, wParam, lParam, GetFS()));
2062
2063 for(int i=0;i<MAX_WINDOW_HANDLES;i++) {
2064 window = GetWindowFromHandle(hwnd++);
2065 if(window) {
2066 if ((window->getStyle() & WS_POPUP) || ((window->getStyle() & WS_CAPTION) == WS_CAPTION))
2067 {
2068 if(type == BROADCAST_SEND) {
2069 ::SendMessageA(window->getWindowHandle(), msg, wParam, lParam);
2070 }
2071 else PostMessageA(window->getWindowHandle(), msg, wParam, lParam);
2072 }
2073 }
2074 }
2075 return 0;
2076}
2077//******************************************************************************
2078//TODO: Do this more efficiently
2079//******************************************************************************
2080LRESULT Win32BaseWindow::BroadcastMessageW(int type, UINT msg, WPARAM wParam, LPARAM lParam)
2081{
2082 Win32BaseWindow *window;
2083 HWND hwnd = WNDHANDLE_MAGIC_HIGHWORD;
2084
2085 dprintf(("BroadCastMessageW %x %x %x", msg, wParam, lParam));
2086
2087 for(int i=0;i<MAX_WINDOW_HANDLES;i++) {
2088 window = GetWindowFromHandle(hwnd++);
2089 if(window) {
2090 if ((window->getStyle() & WS_POPUP) || ((window->getStyle() & WS_CAPTION) == WS_CAPTION))
2091 {
2092 if(type == BROADCAST_SEND) {
2093 ::SendMessageW(window->getWindowHandle(), msg, wParam, lParam);
2094 }
2095 else PostMessageW(window->getWindowHandle(), msg, wParam, lParam);
2096 }
2097 }
2098 }
2099 return 0;
2100}
2101//******************************************************************************
2102//******************************************************************************
2103void Win32BaseWindow::NotifyParent(UINT Msg, WPARAM wParam, LPARAM lParam)
2104{
2105 Win32BaseWindow *window = this;
2106 Win32BaseWindow *parentwindow;
2107
2108 while(window)
2109 {
2110 if(window->getStyle() & WS_CHILD && !(window->getExStyle() & WS_EX_NOPARENTNOTIFY) )
2111 {
2112 /* Notify the parent window only */
2113 parentwindow = window->getParent();
2114 if(parentwindow) {
2115 parentwindow->SendInternalMessageA(WM_PARENTNOTIFY, MAKEWPARAM(Msg, getWindowId()), lParam );
2116 }
2117 }
2118 else break;
2119
2120 window = parentwindow;
2121 }
2122}
2123//******************************************************************************
2124// Returns the big or small icon for the window, falling back to the
2125// class as windows does.
2126//******************************************************************************
2127HICON Win32BaseWindow::IconForWindow(WPARAM fType)
2128{
2129 HICON hWndIcon;
2130
2131 if (fType == ICON_BIG)
2132 {
2133 if (hIcon)
2134 hWndIcon = hIcon;
2135 else
2136 if (windowClass && windowClass->getIcon())
2137 hWndIcon = windowClass->getIcon();
2138 else
2139 if (!(dwStyle & DS_MODALFRAME))
2140 hWndIcon = LoadImageA(0,MAKEINTRESOURCEA(OIC_ODINICON),IMAGE_ICON,0,0,LR_DEFAULTCOLOR);
2141 else hWndIcon = 0;
2142 }
2143 else
2144 {
2145 if (hIconSm)
2146 hWndIcon = hIconSm;
2147 else
2148 if (hIcon)
2149 hWndIcon = hIcon;
2150 else
2151 if (windowClass && windowClass->getIconSm())
2152 hWndIcon = windowClass->getIconSm();
2153 else
2154 if (windowClass && windowClass->getIcon())
2155 hWndIcon = windowClass->getIcon();
2156 else
2157 if (!(dwStyle & DS_MODALFRAME))
2158 hWndIcon = LoadImageA(0,MAKEINTRESOURCEA(OIC_ODINICON),IMAGE_ICON,0,0,LR_DEFAULTCOLOR);
2159 else hWndIcon = 0;
2160 }
2161
2162 return hWndIcon;
2163}
2164//******************************************************************************
2165//******************************************************************************
2166BOOL Win32BaseWindow::ShowWindow(ULONG nCmdShow)
2167{
2168 ULONG swp = 0;
2169 HWND hWinAfter;
2170 BOOL rc,wasVisible,showFlag;
2171 RECT newPos = {0, 0, 0, 0};
2172
2173 dprintf(("ShowWindow %x %x", getWindowHandle(), nCmdShow));
2174 wasVisible = (getStyle() & WS_VISIBLE) != 0;
2175
2176 switch(nCmdShow)
2177 {
2178 case SW_HIDE:
2179 if (!wasVisible) goto END;
2180 swp |= SWP_HIDEWINDOW | SWP_NOSIZE | SWP_NOMOVE |
2181 SWP_NOACTIVATE | SWP_NOZORDER;
2182 break;
2183
2184 case SW_SHOWMINNOACTIVE:
2185 swp |= SWP_NOACTIVATE | SWP_NOZORDER;
2186 /* fall through */
2187 case SW_SHOWMINIMIZED:
2188 swp |= SWP_SHOWWINDOW;
2189 /* fall through */
2190 case SW_MINIMIZE:
2191 swp |= SWP_FRAMECHANGED;
2192 if( !(getStyle() & WS_MINIMIZE) )
2193 swp |= MinMaximize(SW_MINIMIZE, &newPos );
2194 else swp |= SWP_NOSIZE | SWP_NOMOVE;
2195 break;
2196
2197 case SW_SHOWMAXIMIZED: /* same as SW_MAXIMIZE */
2198 swp |= SWP_SHOWWINDOW | SWP_FRAMECHANGED;
2199 if( !(getStyle() & WS_MAXIMIZE) )
2200 swp |= MinMaximize(SW_MAXIMIZE, &newPos );
2201 else swp |= SWP_NOSIZE | SWP_NOMOVE;
2202 break;
2203
2204 case SW_SHOWNA:
2205 swp |= SWP_NOACTIVATE | SWP_NOZORDER;
2206 /* fall through */
2207 case SW_SHOW:
2208 swp |= SWP_SHOWWINDOW | SWP_NOSIZE | SWP_NOMOVE;
2209
2210 /*
2211 * ShowWindow has a little peculiar behavior that if the
2212 * window is already the topmost window, it will not
2213 * activate it.
2214 */
2215 if (::GetTopWindow((HWND)0)==getWindowHandle() && (wasVisible || GetActiveWindow() == getWindowHandle()))
2216 swp |= SWP_NOACTIVATE;
2217
2218 break;
2219
2220 case SW_SHOWNOACTIVATE:
2221 swp |= SWP_NOZORDER;
2222 if (GetActiveWindow())
2223 swp |= SWP_NOACTIVATE;
2224 /* fall through */
2225 case SW_SHOWNORMAL: /* same as SW_NORMAL: */
2226 case SW_SHOWDEFAULT: /* FIXME: should have its own handler */
2227 case SW_RESTORE:
2228 //TODO: WIN_RESTORE_MAX flag!!!!!!!!!!!!!!
2229 swp |= SWP_SHOWWINDOW | SWP_FRAMECHANGED;
2230
2231 if( getStyle() & (WS_MINIMIZE | WS_MAXIMIZE) )
2232 swp |= MinMaximize(SW_RESTORE, &newPos );
2233 else swp |= SWP_NOSIZE | SWP_NOMOVE;
2234 break;
2235 }
2236
2237 showFlag = (nCmdShow != SW_HIDE);
2238 if (showFlag != wasVisible)
2239 {
2240 SendInternalMessageA(WM_SHOWWINDOW, showFlag, 0 );
2241 if (!::IsWindow( getWindowHandle() )) goto END;
2242 }
2243
2244 /* We can't activate a child window */
2245 if((getStyle() & WS_CHILD) && !(getExStyle() & WS_EX_MDICHILD))
2246 swp |= SWP_NOACTIVATE | SWP_NOZORDER;
2247
2248 SetWindowPos(HWND_TOP, newPos.left, newPos.top, newPos.right, newPos.bottom, LOWORD(swp));
2249
2250 if(!(swp & SWP_NOACTIVATE)) {
2251 OSLibWinSetActiveWindow(OS2Hwnd);
2252 }
2253
2254 if (flags & WIN_NEED_SIZE)
2255 {
2256 /* should happen only in CreateWindowEx() */
2257 int wParam = SIZE_RESTORED;
2258
2259 flags &= ~WIN_NEED_SIZE;
2260 if (dwStyle & WS_MAXIMIZE)
2261 wParam = SIZE_MAXIMIZED;
2262 else
2263 if (dwStyle & WS_MINIMIZE)
2264 wParam = SIZE_MINIMIZED;
2265
2266 SendInternalMessageA(WM_SIZE, wParam,
2267 MAKELONG(rectClient.right-rectClient.left,
2268 rectClient.bottom-rectClient.top));
2269 SendInternalMessageA(WM_MOVE,0,MAKELONG(rectClient.left,rectClient.top));
2270 }
2271END:
2272 return wasVisible;
2273}
2274//******************************************************************************
2275//******************************************************************************
2276BOOL Win32BaseWindow::SetWindowPos(HWND hwndInsertAfter, int x, int y, int cx, int cy, UINT fuFlags)
2277{
2278 BOOL rc = FALSE;
2279 Win32BaseWindow *window;
2280 HWND hParent = 0;
2281 RECT oldClientRect = rectClient;
2282
2283 if (fuFlags &
2284 ~(SWP_NOSIZE | SWP_NOMOVE | SWP_NOZORDER |
2285 SWP_NOREDRAW | SWP_NOACTIVATE | SWP_FRAMECHANGED |
2286 SWP_SHOWWINDOW | SWP_HIDEWINDOW | SWP_NOCOPYBITS |
2287 SWP_NOOWNERZORDER | SWP_NOSENDCHANGING | SWP_DEFERERASE |
2288 SWP_NOCLIENTSIZE | SWP_NOCLIENTMOVE))
2289 {
2290 dprintf(("ERROR: SetWindowPos; UNKNOWN flag"));
2291 return FALSE;
2292 }
2293
2294 if( fuFlags & (SWP_DEFERERASE | SWP_NOCLIENTSIZE | SWP_NOCLIENTMOVE)) {
2295 dprintf(("WARNING: SetWindowPos; unsupported flag"));
2296 }
2297
2298 if(IsWindowDestroyed()) {
2299 //changing the position of a window that's being destroyed can cause crashes in PMMERGE
2300 dprintf(("SetWindowPos; window already destroyed"));
2301 return TRUE;
2302 }
2303#if 0
2304 /* Fix redundant flags */
2305 if(getStyle() & WS_VISIBLE) {
2306 fuFlags &= ~SWP_SHOWWINDOW;
2307 }
2308 else
2309 {
2310 if (!(fuFlags & SWP_SHOWWINDOW))
2311 fuFlags |= SWP_NOREDRAW;
2312 fuFlags &= ~SWP_HIDEWINDOW;
2313 }
2314
2315 if(cx < 0) cx = 0;
2316 if(cy < 0) cy = 0;
2317
2318 if((rectWindow.right - rectWindow.left == cx) && (rectWindow.bottom - rectWindow.top == cy)) {
2319 fuFlags |= SWP_NOSIZE; /* Already the right size */
2320 }
2321
2322 if((rectWindow.left == x) && (rectWindow.top == y)) {
2323 fuFlags |= SWP_NOMOVE; /* Already the right position */
2324 }
2325
2326 if(getWindowHandle() == GetActiveWindow()) {
2327 fuFlags |= SWP_NOACTIVATE; /* Already active */
2328 }
2329 else
2330 if((getStyle() & (WS_POPUP | WS_CHILD)) != WS_CHILD )
2331 {
2332 if(!(fuFlags & SWP_NOACTIVATE)) /* Bring to the top when activating */
2333 {
2334 fuFlags &= ~SWP_NOZORDER;
2335 hwndInsertAfter = HWND_TOP;
2336 }
2337 }
2338#endif
2339
2340 if(!fCreateSetWindowPos)
2341 {//don't change size; modify internal structures only
2342 //TODO: not 100% correct yet (activate)
2343 if(!(fuFlags & SWP_NOZORDER)) {
2344 hwndLinkAfter = hwndInsertAfter;
2345 }
2346 if(!(fuFlags & SWP_NOMOVE)) {
2347 rectWindow.bottom = (rectWindow.bottom - rectWindow.top) + y;
2348 rectWindow.top = y;
2349 rectWindow.right = (rectWindow.right - rectWindow.left) + x;
2350 rectWindow.left = x;
2351 }
2352 if(!(fuFlags & SWP_NOSIZE)) {
2353 rectWindow.bottom = rectWindow.top + cy;
2354 rectWindow.right = rectWindow.left + cx;
2355 }
2356 return TRUE;
2357 }
2358
2359 WINDOWPOS wpos;
2360 SWP swp, swpOld;
2361 wpos.flags = fuFlags;
2362 wpos.cy = cy;
2363 wpos.cx = cx;
2364 wpos.x = x;
2365 wpos.y = y;
2366 wpos.hwndInsertAfter = hwndInsertAfter;
2367 wpos.hwnd = getWindowHandle();
2368
2369 if(~fuFlags & (SWP_NOMOVE | SWP_NOSIZE))
2370 {
2371 if (isChild())
2372 {
2373 if(!getParent()) {
2374 dprintf(("WARNING: Win32BaseWindow::SetWindowPos window %x is child but has no parent!!", getWindowHandle()));
2375 }
2376 }
2377 OSLibWinQueryWindowPos(OS2Hwnd, &swpOld);
2378 }
2379
2380 if(getParent()) {
2381 OSLibMapWINDOWPOStoSWP(&wpos, &swp, &swpOld, getParent()->getWindowHeight(),
2382 getParent()->getClientRectPtr()->left,
2383 getParent()->getClientRectPtr()->top,
2384 OS2Hwnd);
2385 }
2386 else OSLibMapWINDOWPOStoSWP(&wpos, &swp, &swpOld, OSLibQueryScreenHeight(), 0, 0, OS2Hwnd);
2387 if (swp.fl == 0) {
2388 if(fuFlags & SWP_FRAMECHANGED)
2389 {
2390 NotifyFrameChanged(&wpos, &oldClientRect);
2391 }
2392 return TRUE;
2393 }
2394
2395// if ((swp.fl & SWPOS_ZORDER) && (swp.hwndInsertBehind > HWNDOS_BOTTOM))
2396 if ((swp.hwndInsertBehind > HWNDOS_BOTTOM))
2397 {
2398 Win32BaseWindow *wndBehind = Win32BaseWindow::GetWindowFromHandle(swp.hwndInsertBehind);
2399 if(wndBehind) {
2400 swp.hwndInsertBehind = wndBehind->getOS2WindowHandle();
2401 }
2402 else {
2403 dprintf(("ERROR: SetWindowPos: hwndInsertBehind %x invalid!",swp.hwndInsertBehind));
2404 swp.hwndInsertBehind = 0;
2405 }
2406 }
2407 swp.hwnd = OS2Hwnd;
2408
2409 if(fuFlags & SWP_SHOWWINDOW && !IsWindowVisible()) {
2410 setStyle(getStyle() | WS_VISIBLE);
2411 if(hTaskList) {
2412 dprintf(("Adding window %x to tasklist", getWindowHandle()));
2413 OSLibWinChangeTaskList(hTaskList, OS2Hwnd, getWindowNameA(), (getStyle() & WS_VISIBLE) ? 1 : 0);
2414 }
2415 }
2416 else
2417 if(fuFlags & SWP_HIDEWINDOW && IsWindowVisible()) {
2418 setStyle(getStyle() & ~WS_VISIBLE);
2419 if(hTaskList) {
2420 dprintf(("Removing window %x from tasklist", getWindowHandle()));
2421 OSLibWinChangeTaskList(hTaskList, OS2Hwnd, getWindowNameA(), (getStyle() & WS_VISIBLE) ? 1 : 0);
2422 }
2423 }
2424 dprintf (("WinSetWindowPos %x %x (%d,%d)(%d,%d) %x", swp.hwnd, swp.hwndInsertBehind, swp.x, swp.y, swp.cx, swp.cy, swp.fl));
2425 rc = OSLibWinSetMultWindowPos(&swp, 1);
2426
2427 if(rc == FALSE)
2428 {
2429 dprintf(("OSLibWinSetMultWindowPos failed! Error %x",OSLibWinGetLastError()));
2430 return 0;
2431 }
2432
2433 //Restore window origin of parent window with CS_OWNDC style
2434 //(fixes paint offset problems in Opera windows)
2435 if(getParent() && getParent()->isOwnDC()) {
2436 dprintfOrigin(getParent()->getOwnDC());
2437 selectClientArea(getParent(), getParent()->getOwnDC());
2438 }
2439
2440 if((fuFlags & SWP_FRAMECHANGED) && (fuFlags & (SWP_NOMOVE | SWP_NOSIZE) == (SWP_NOMOVE | SWP_NOSIZE)))
2441 {
2442 NotifyFrameChanged(&wpos, &oldClientRect);
2443 }
2444 return (rc);
2445}
2446//******************************************************************************
2447//Called by ScrollWindowEx (dc.cpp) to notify child window that it has moved
2448//******************************************************************************
2449BOOL Win32BaseWindow::ScrollWindow(int dx, int dy)
2450{
2451 rectWindow.left += dx;
2452 rectWindow.right += dx;
2453 rectWindow.top += dy;
2454 rectWindow.bottom += dy;
2455 SendInternalMessageA(WM_MOVE, 0, MAKELONG(rectClient.left, rectClient.top));
2456 return TRUE;
2457}
2458//******************************************************************************
2459//******************************************************************************
2460void Win32BaseWindow::NotifyFrameChanged(WINDOWPOS *wpos, RECT *oldClientRect)
2461{
2462 HRGN hrgn, hrgnClient;
2463 RECT rect;
2464
2465 MsgFormatFrame(NULL);
2466
2467 if(RECT_WIDTH(rectClient) != RECT_WIDTH(*oldClientRect) ||
2468 RECT_HEIGHT(rectClient) != RECT_HEIGHT(*oldClientRect))
2469 {
2470 wpos->flags &= ~(SWP_NOSIZE|SWP_NOCLIENTSIZE);
2471 wpos->cx = RECT_WIDTH(rectWindow);
2472 wpos->cy = RECT_HEIGHT(rectWindow);
2473 }
2474
2475 if(rectClient.left != oldClientRect->left ||
2476 rectClient.top != oldClientRect->top)
2477 {
2478 wpos->flags &= ~(SWP_NOMOVE|SWP_NOCLIENTMOVE);
2479 wpos->x = rectWindow.left;
2480 wpos->y = rectWindow.top;
2481 }
2482
2483 WINDOWPOS wpOld = *wpos;
2484 SendInternalMessageA(WM_WINDOWPOSCHANGING, 0, (LPARAM)wpos);
2485
2486 if ((wpos->hwndInsertAfter != wpOld.hwndInsertAfter) ||
2487 (wpos->x != wpOld.x) || (wpos->y != wpOld.y) || (wpos->cx != wpOld.cx) || (wpos->cy != wpOld.cy) || (wpos->flags != wpOld.flags))
2488 {
2489 dprintf(("WARNING, NotifyFrameChanged: TODO -> adjust flags!!!!"));
2490 SetWindowPos(wpos->hwndInsertAfter, wpos->x, wpos->y, wpos->cx, wpos->cy, wpos->flags | SWP_NOSENDCHANGING);
2491 }
2492 else SendInternalMessageA(WM_WINDOWPOSCHANGED, 0, (LPARAM)wpos);
2493
2494 rect = rectWindow;
2495 OffsetRect(&rect, -rectWindow.left, -rectWindow.top);
2496 hrgn = CreateRectRgnIndirect(&rect);
2497 if (!hrgn) {
2498 dprintf(("ERROR: NotifyFrameChanged, CreateRectRgnIndirect failed!!"));
2499 return;
2500 }
2501 rect = rectClient;
2502 OffsetRect(&rect, -rectClient.left, -rectClient.top);
2503 hrgnClient = CreateRectRgnIndirect(&rect);
2504 if (!hrgn) {
2505 dprintf(("ERROR: NotifyFrameChanged, CreateRectRgnIndirect failed!!"));
2506 return;
2507 }
2508 CombineRgn(hrgn, hrgn, hrgnClient, RGN_DIFF);
2509 DeleteObject(hrgnClient);
2510
2511 if(!EqualRect(oldClientRect, &rectClient)) {
2512 UnionRect(oldClientRect, oldClientRect, &rectClient);
2513 OffsetRect(oldClientRect, -rectClient.left, -rectClient.top);
2514 hrgnClient = CreateRectRgnIndirect(oldClientRect);
2515 if (!hrgn) {
2516 dprintf(("ERROR: NotifyFrameChanged, CreateRectRgnIndirect failed!!"));
2517 return;
2518 }
2519 CombineRgn(hrgn, hrgn, hrgnClient, RGN_OR);
2520 DeleteObject(hrgnClient);
2521 }
2522 InvalidateRgn(getWindowHandle(), hrgn, TRUE);
2523 DeleteObject(hrgn);
2524}
2525//******************************************************************************
2526//TODO: Check how this api really works in NT
2527//******************************************************************************
2528BOOL Win32BaseWindow::SetWindowPlacement(WINDOWPLACEMENT *wndpl)
2529{
2530 windowpos.ptMinPosition = wndpl->ptMinPosition;
2531 windowpos.ptMaxPosition = wndpl->ptMaxPosition;
2532 windowpos.rcNormalPosition = wndpl->rcNormalPosition;
2533
2534 if(getStyle() & WS_MINIMIZE )
2535 {
2536 //TODO: Why can't this be (0,0)?
2537 if(wndpl->flags & WPF_SETMINPOSITION && !(!windowpos.ptMinPosition.x && !windowpos.ptMinPosition.y)) {
2538 SetWindowPos(0, windowpos.ptMinPosition.x, windowpos.ptMinPosition.y,
2539 0, 0, SWP_NOSIZE | SWP_NOZORDER | SWP_NOACTIVATE);
2540 }
2541 }
2542 else
2543 if(getStyle() & WS_MAXIMIZE )
2544 {
2545 //TODO: Why can't this be (0,0)?
2546 if(windowpos.ptMaxPosition.x != 0 || windowpos.ptMaxPosition.y != 0 )
2547 SetWindowPos(0, windowpos.ptMaxPosition.x, windowpos.ptMaxPosition.y,
2548 0, 0, SWP_NOSIZE | SWP_NOZORDER | SWP_NOACTIVATE);
2549 }
2550 else {
2551 SetWindowPos(0, windowpos.rcNormalPosition.left, windowpos.rcNormalPosition.top,
2552 windowpos.rcNormalPosition.right - windowpos.rcNormalPosition.left,
2553 windowpos.rcNormalPosition.bottom - windowpos.rcNormalPosition.top,
2554 SWP_NOZORDER | SWP_NOACTIVATE );
2555 }
2556 ShowWindow(wndpl->showCmd);
2557 if( ::IsWindow(getWindowHandle()) && getStyle() & WS_MINIMIZE )
2558 {
2559 /* SDK: ...valid only the next time... */
2560 if(wndpl->flags & WPF_RESTORETOMAXIMIZED)
2561 setFlags(getFlags() | WIN_RESTORE_MAX);
2562 }
2563 return TRUE;
2564}
2565//******************************************************************************
2566//******************************************************************************
2567BOOL Win32BaseWindow::GetWindowPlacement(LPWINDOWPLACEMENT wndpl)
2568{
2569 wndpl->length = sizeof(*wndpl);
2570 if(getStyle() & WS_MINIMIZE )
2571 wndpl->showCmd = SW_SHOWMINIMIZED;
2572 else wndpl->showCmd = (getStyle() & WS_MAXIMIZE) ? SW_SHOWMAXIMIZED : SW_SHOWNORMAL;
2573
2574 //TODO: Verify if this is correct -> SDK docs claim this flag must always be set to 0
2575 if(getFlags() & WIN_RESTORE_MAX )
2576 wndpl->flags = WPF_RESTORETOMAXIMIZED;
2577 else wndpl->flags = 0;
2578
2579 wndpl->ptMinPosition = windowpos.ptMinPosition;
2580 wndpl->ptMaxPosition = windowpos.ptMaxPosition;
2581 //Must be in parent coordinates (or screen if no parent); verified in NT4, SP6
2582 wndpl->rcNormalPosition = rectWindow;
2583
2584 return TRUE;
2585}
2586//******************************************************************************
2587//Also destroys all the child windows (destroy children first, parent last)
2588//******************************************************************************
2589BOOL Win32BaseWindow::DestroyWindow()
2590{
2591 HWND hwnd = getWindowHandle();
2592
2593 dprintf(("DestroyWindow %x", hwnd));
2594
2595 /* Call hooks */
2596 if(HOOK_CallHooksA( WH_CBT, HCBT_DESTROYWND, getWindowHandle(), 0L))
2597 {
2598 return FALSE;
2599 }
2600
2601 if(!(getStyle() & WS_CHILD) && getOwner() == NULL)
2602 {
2603 HOOK_CallHooksA(WH_SHELL, HSHELL_WINDOWDESTROYED, getWindowHandle(), 0L);
2604 /* FIXME: clean up palette - see "Internals" p.352 */
2605 }
2606
2607 if((getStyle() & WS_CHILD) && !(getExStyle() & WS_EX_NOPARENTNOTIFY))
2608 {
2609 if(getParent() && getParent()->IsWindowDestroyed() == FALSE)
2610 {
2611 /* Notify the parent window only */
2612 getParent()->SendMessageA(WM_PARENTNOTIFY, MAKEWPARAM(WM_DESTROY, getWindowId()), (LPARAM)getWindowHandle());
2613 if(!::IsWindow(hwnd) )
2614 {
2615 return TRUE;
2616 }
2617 }
2618//// else DebugInt3();
2619 }
2620 /* Hide the window */
2621 if(IsWindowVisible())
2622 {
2623 SetWindowPos(0, 0, 0, 0, 0, SWP_HIDEWINDOW |
2624 SWP_NOACTIVATE|SWP_NOZORDER|SWP_NOMOVE|SWP_NOSIZE);
2625 if(!::IsWindow(hwnd))
2626 {
2627 return TRUE;
2628 }
2629 }
2630 dprintf(("DestroyWindow %x -> HIDDEN", hwnd));
2631
2632 fDestroyWindowCalled = TRUE;
2633 return OSLibWinDestroyWindow(OS2Hwnd);
2634}
2635//******************************************************************************
2636//******************************************************************************
2637Win32BaseWindow *Win32BaseWindow::getParent()
2638{
2639 Win32BaseWindow *wndparent = (Win32BaseWindow *)ChildWindow::getParentOfChild();
2640 return ((ULONG)wndparent == (ULONG)windowDesktop) ? NULL : wndparent;
2641}
2642//******************************************************************************
2643//Note: does not set last error if no parent (verified in NT4, SP6)
2644//******************************************************************************
2645HWND Win32BaseWindow::GetParent()
2646{
2647 if((!(getStyle() & (WS_POPUP|WS_CHILD)))) {
2648 return 0;
2649 }
2650
2651 Win32BaseWindow *wndparent = (Win32BaseWindow *)ChildWindow::getParentOfChild();
2652
2653 if(getStyle() & WS_CHILD) {
2654 if(wndparent) {
2655 return wndparent->getWindowHandle();
2656 }
2657 dprintf(("WARNING: GetParent: WS_CHILD but no parent!!"));
2658 DebugInt3();
2659 return 0;
2660 }
2661 else return (getOwner()) ? getOwner()->getWindowHandle() : 0;
2662}
2663//******************************************************************************
2664//******************************************************************************
2665HWND Win32BaseWindow::SetParent(HWND hwndNewParent)
2666{
2667 HWND oldhwnd;
2668 Win32BaseWindow *newparent;
2669 Win32BaseWindow *oldparent = (Win32BaseWindow *)ChildWindow::getParentOfChild();
2670 BOOL fShow = FALSE;
2671
2672 if(oldparent) {
2673 oldhwnd = oldparent->getWindowHandle();
2674 oldparent->removeChild(this);
2675 }
2676 else oldhwnd = 0;
2677
2678 /* Windows hides the window first, then shows it again
2679 * including the WM_SHOWWINDOW messages and all */
2680 if(fCreated && (getStyle() & WS_VISIBLE)) {
2681 ShowWindow(SW_HIDE);
2682 fShow = TRUE;
2683 }
2684
2685 newparent = GetWindowFromHandle(hwndNewParent);
2686 if(newparent && !newparent->isDesktopWindow())
2687 {
2688 setParent(newparent);
2689 getParent()->addChild(this);
2690 OSLibWinSetParent(getOS2WindowHandle(), getParent()->getOS2WindowHandle());
2691 if(!(getStyle() & WS_CHILD))
2692 {
2693 //TODO: Send WM_STYLECHANGED msg?
2694 setStyle(getStyle() | WS_CHILD);
2695 if(getWindowId())
2696 {
2697 DestroyMenu( (HMENU) getWindowId() );
2698 setWindowId(0);
2699 }
2700 }
2701 }
2702 else {
2703 setParent(windowDesktop);
2704 windowDesktop->addChild(this);
2705 OSLibWinSetParent(getOS2WindowHandle(), OSLIB_HWND_DESKTOP);
2706
2707 //TODO: Send WM_STYLECHANGED msg?
2708 setStyle(getStyle() & ~WS_CHILD);
2709 setWindowId(0);
2710 }
2711 /* SetParent additionally needs to make hwndChild the topmost window
2712 in the x-order and send the expected WM_WINDOWPOSCHANGING and
2713 WM_WINDOWPOSCHANGED notification messages.
2714 */
2715 if(fCreated) {
2716 SetWindowPos(HWND_TOPMOST, 0, 0, 0, 0,
2717 SWP_NOACTIVATE|SWP_NOMOVE|SWP_NOSIZE|(fShow? SWP_SHOWWINDOW : 0));
2718
2719 /* FIXME: a WM_MOVE is also generated (in the DefWindowProc handler
2720 * for WM_WINDOWPOSCHANGED) in Windows, should probably remove SWP_NOMOVE */
2721 }
2722 return oldhwnd;
2723}
2724//******************************************************************************
2725//******************************************************************************
2726BOOL Win32BaseWindow::IsChild(HWND hwndParent)
2727{
2728 if(getParent()) {
2729 if(getParent()->getWindowHandle() == hwndParent)
2730 return TRUE;
2731
2732 return getParent()->IsChild(hwndParent);
2733 }
2734 else return 0;
2735}
2736//******************************************************************************
2737//******************************************************************************
2738HWND Win32BaseWindow::GetTopWindow()
2739{
2740 HWND hwndTop;
2741 Win32BaseWindow *topwindow;
2742
2743 hwndTop = OSLibWinQueryWindow(getOS2WindowHandle(), QWOS_TOP);
2744 if(!isDesktopWindow()) {
2745 topwindow = GetWindowFromOS2Handle(hwndTop);
2746 if(topwindow) {
2747 return topwindow->getWindowHandle();
2748 }
2749 return 0;
2750 }
2751 while(hwndTop) {
2752 topwindow = GetWindowFromOS2Handle(hwndTop);
2753 if(topwindow) {
2754 return topwindow->getWindowHandle();
2755 }
2756 hwndTop = OSLibWinQueryWindow(hwndTop, QWOS_NEXT);
2757 }
2758
2759 return 0;
2760}
2761//******************************************************************************
2762// Get the top-level parent for a child window.
2763//******************************************************************************
2764Win32BaseWindow *Win32BaseWindow::GetTopParent()
2765{
2766 Win32BaseWindow *window = this;
2767
2768 while(window && (window->getStyle() & WS_CHILD))
2769 {
2770 window = window->getParent();
2771 }
2772 return window;
2773}
2774//******************************************************************************
2775//TODO: Should not enumerate children that are created during the enumeration!
2776//******************************************************************************
2777BOOL Win32BaseWindow::EnumChildWindows(WNDENUMPROC lpfn, LPARAM lParam)
2778{
2779 BOOL rc = TRUE;
2780 HWND hwnd;
2781 Win32BaseWindow *prevchild = 0, *child = 0;
2782
2783 dprintf(("EnumChildWindows of %x parameter %x %x (%x)", getWindowHandle(), lpfn, lParam, getFirstChild()));
2784 for (child = (Win32BaseWindow *)getFirstChild(); child; child = (Win32BaseWindow *)child->getNextChild())
2785 {
2786 dprintf(("EnumChildWindows: enumerating child %x (owner %x; parent %x)", child->getWindowHandle(), (child->getOwner()) ? child->getOwner()->getWindowHandle() : 0, getWindowHandle()));
2787 hwnd = child->getWindowHandle();
2788 if(child->getOwner()) {
2789 continue; //shouldn't have an owner (Wine)
2790 }
2791 if(lpfn(hwnd, lParam) == FALSE)
2792 {
2793 rc = FALSE;
2794 break;
2795 }
2796 //check if the window still exists
2797 if(!::IsWindow(hwnd))
2798 {
2799 child = prevchild;
2800 continue;
2801 }
2802 if(child->getFirstChild() != NULL)
2803 {
2804 dprintf(("EnumChildWindows: Enumerate children of %x", child->getWindowHandle()));
2805 if(child->EnumChildWindows(lpfn, lParam) == FALSE)
2806 {
2807 rc = FALSE;
2808 break;
2809 }
2810 }
2811 prevchild = child;
2812 }
2813 return rc;
2814}
2815//******************************************************************************
2816//Enumerate first-level children only and check thread id
2817//******************************************************************************
2818BOOL Win32BaseWindow::EnumThreadWindows(DWORD dwThreadId, WNDENUMPROC lpfn, LPARAM lParam)
2819{
2820 Win32BaseWindow *child = 0;
2821 ULONG tid, pid;
2822 BOOL rc;
2823 HWND hwnd;
2824
2825 dprintf(("EnumThreadWindows %x %x %x", dwThreadId, lpfn, lParam));
2826
2827 for (child = (Win32BaseWindow *)getFirstChild(); child; child = (Win32BaseWindow *)child->getNextChild())
2828 {
2829 OSLibWinQueryWindowProcess(child->getOS2WindowHandle(), &pid, &tid);
2830
2831 if(dwThreadId == tid) {
2832 dprintf2(("EnumThreadWindows: Found Window %x", child->getWindowHandle()));
2833 if((rc = lpfn(child->getWindowHandle(), lParam)) == FALSE) {
2834 break;
2835 }
2836 }
2837 }
2838 return TRUE;
2839}
2840//******************************************************************************
2841//Enumerate first-level children only
2842//******************************************************************************
2843BOOL Win32BaseWindow::EnumWindows(WNDENUMPROC lpfn, LPARAM lParam)
2844{
2845 Win32BaseWindow *child = 0;
2846 BOOL rc;
2847 HWND hwnd;
2848
2849 dprintf(("EnumWindows %x %x", lpfn, lParam));
2850
2851 for (child = (Win32BaseWindow *)getFirstChild(); child; child = (Win32BaseWindow *)child->getNextChild())
2852 {
2853 hwnd = child->getWindowHandle();
2854
2855 dprintf2(("EnumWindows: Found Window %x", child->getWindowHandle()));
2856 if((rc = lpfn(child->getWindowHandle(), lParam)) == FALSE) {
2857 break;
2858 }
2859 }
2860 return TRUE;
2861}
2862//******************************************************************************
2863//******************************************************************************
2864Win32BaseWindow *Win32BaseWindow::FindWindowById(int id)
2865{
2866 for (Win32BaseWindow *child = (Win32BaseWindow *)getFirstChild(); child; child = (Win32BaseWindow *)child->getNextChild())
2867 {
2868 if (child->getWindowId() == id)
2869 {
2870 return child;
2871 }
2872 }
2873 return 0;
2874}
2875//******************************************************************************
2876//TODO:
2877//We assume (for now) that if hwndParent or hwndChildAfter are real window handles, that
2878//the current process owns them.
2879//******************************************************************************
2880HWND Win32BaseWindow::FindWindowEx(HWND hwndParent, HWND hwndChildAfter, ATOM atom, LPSTR lpszWindow)
2881{
2882 Win32BaseWindow *parent = GetWindowFromHandle(hwndParent);
2883 Win32BaseWindow *child = GetWindowFromHandle(hwndChildAfter);
2884
2885 dprintf(("FindWindowEx %x %x %x %s", hwndParent, hwndChildAfter, atom, lpszWindow));
2886 if((hwndParent != 0 && !parent) ||
2887 (hwndChildAfter != 0 && !child) ||
2888 (hwndParent == 0 && hwndChildAfter != 0))
2889 {
2890 dprintf(("Win32BaseWindow::FindWindowEx: parent or child not found %x %x", hwndParent, hwndChildAfter));
2891 SetLastError(ERROR_INVALID_WINDOW_HANDLE);
2892 return 0;
2893 }
2894 SetLastError(0);
2895 if(hwndParent != 0)
2896 {//if the current process owns the window, just do a quick search
2897 child = (Win32BaseWindow *)parent->getFirstChild();
2898 if(hwndChildAfter != 0)
2899 {
2900 while(child)
2901 {
2902 if(child->getWindowHandle() == hwndChildAfter)
2903 {
2904 child = (Win32BaseWindow *)child->getNextChild();
2905 break;
2906 }
2907 child = (Win32BaseWindow *)child->getNextChild();
2908 }
2909 }
2910 while(child)
2911 {
2912 //According to Wine, the class doesn't need to be specified
2913 if((!atom || child->getWindowClass()->getAtom() == atom) &&
2914 (!lpszWindow || child->hasWindowName(lpszWindow)))
2915 {
2916 dprintf(("FindWindowEx: Found window %x", child->getWindowHandle()));
2917 return child->getWindowHandle();
2918 }
2919 child = (Win32BaseWindow *)child->getNextChild();
2920 }
2921 }
2922 else {
2923 Win32BaseWindow *wnd;
2924 HWND henum, hwnd;
2925
2926 henum = OSLibWinBeginEnumWindows(OSLIB_HWND_DESKTOP);
2927 hwnd = OSLibWinGetNextWindow(henum);
2928
2929 while(hwnd)
2930 {
2931 wnd = GetWindowFromOS2Handle(hwnd);
2932 if(wnd == NULL) {
2933 hwnd = OSLibWinQueryClientWindow(hwnd);
2934 if(hwnd) wnd = GetWindowFromOS2Handle(hwnd);
2935 }
2936
2937 if(wnd) {
2938 //According to Wine, the class doesn't need to be specified
2939 if((!atom || wnd->getWindowClass()->getAtom() == atom) &&
2940 (!lpszWindow || wnd->hasWindowName(lpszWindow)))
2941 {
2942 OSLibWinEndEnumWindows(henum);
2943 dprintf(("FindWindowEx: Found window %x", wnd->getWindowHandle()));
2944 return wnd->getWindowHandle();
2945 }
2946 }
2947 hwnd = OSLibWinGetNextWindow(henum);
2948 }
2949 OSLibWinEndEnumWindows(henum);
2950 }
2951 SetLastError(ERROR_CANNOT_FIND_WND_CLASS); //TODO: not always correct
2952 return 0;
2953}
2954//******************************************************************************
2955//******************************************************************************
2956HWND Win32BaseWindow::GetWindow(UINT uCmd)
2957{
2958 HWND hwndRelated = 0;
2959 Win32BaseWindow *window;
2960
2961#if 1
2962 switch(uCmd)
2963 {
2964 case GW_HWNDFIRST:
2965 if(getParent())
2966 {
2967 window = (Win32BaseWindow *)getParent();
2968 hwndRelated = OSLibWinQueryWindow(window->getOS2WindowHandle(), QWOS_TOP);
2969 window = GetWindowFromOS2Handle(hwndRelated);
2970 if(window) {
2971 hwndRelated = window->getWindowHandle();
2972 }
2973 else hwndRelated = 0;
2974 }
2975 else hwndRelated = 0; //TODO: not correct; should get first child in z-order of desktop
2976 break;
2977
2978 case GW_HWNDLAST:
2979 hwndRelated = OSLibWinQueryWindow(getOS2WindowHandle(), QWOS_BOTTOM);
2980 window = GetWindowFromOS2Handle(hwndRelated);
2981 if(window) {
2982 hwndRelated = window->getWindowHandle();
2983 }
2984 else hwndRelated = 0;
2985 break;
2986
2987 case GW_HWNDNEXT:
2988 hwndRelated = OSLibWinQueryWindow(getOS2WindowHandle(), QWOS_NEXT);
2989 window = GetWindowFromOS2Handle(hwndRelated);
2990 if(window) {
2991 hwndRelated = window->getWindowHandle();
2992 }
2993 else hwndRelated = 0;
2994 break;
2995
2996 case GW_HWNDPREV:
2997 hwndRelated = OSLibWinQueryWindow(getOS2WindowHandle(), QWOS_PREV);
2998 window = GetWindowFromOS2Handle(hwndRelated);
2999 if(window) {
3000 hwndRelated = window->getWindowHandle();
3001 }
3002 else hwndRelated = 0;
3003 break;
3004
3005 case GW_OWNER:
3006 if(getOwner()) {
3007 hwndRelated = getOwner()->getWindowHandle();
3008 }
3009 break;
3010
3011 case GW_CHILD:
3012 hwndRelated = OSLibWinQueryWindow(getOS2WindowHandle(), QWOS_TOP);
3013 window = GetWindowFromOS2Handle(hwndRelated);
3014 if(window) {
3015 hwndRelated = window->getWindowHandle();
3016 }
3017 else hwndRelated = 0;
3018 break;
3019 }
3020#else
3021 switch(uCmd)
3022 {
3023 case GW_HWNDFIRST:
3024 if(getParent()) {
3025 window = (Win32BaseWindow *)getParent()->getFirstChild();
3026 hwndRelated = window->getWindowHandle();
3027 }
3028 break;
3029
3030 case GW_HWNDLAST:
3031 if(!getParent())
3032 {
3033 goto end;
3034 }
3035
3036 window = this;
3037 while(window->getNextChild())
3038 {
3039 window = (Win32BaseWindow *)window->getNextChild();
3040 }
3041 hwndRelated = window->getWindowHandle();
3042 break;
3043
3044 case GW_HWNDNEXT:
3045 window = (Win32BaseWindow *)getNextChild();
3046 if(window) {
3047 hwndRelated = window->getWindowHandle();
3048 }
3049 break;
3050
3051 case GW_HWNDPREV:
3052 if(!getParent())
3053 {
3054 goto end;
3055 }
3056 window = (Win32BaseWindow *)(getParent()->getFirstChild()); /* First sibling */
3057 if(window == this)
3058 {
3059 hwndRelated = 0; /* First in list */
3060 goto end;
3061 }
3062 while(window->getNextChild())
3063 {
3064 if (window->getNextChild() == this)
3065 {
3066 hwndRelated = window->getWindowHandle();
3067 goto end;
3068 }
3069 window = (Win32BaseWindow *)window->getNextChild();
3070 }
3071 break;
3072
3073 case GW_OWNER:
3074 if(getOwner()) {
3075 hwndRelated = getOwner()->getWindowHandle();
3076 }
3077 break;
3078
3079 case GW_CHILD:
3080 if(getFirstChild()) {
3081 hwndRelated = ((Win32BaseWindow *)getFirstChild())->getWindowHandle();
3082 }
3083 break;
3084 }
3085#endif
3086end:
3087 dprintf(("GetWindow %x %d returned %x", getWindowHandle(), uCmd, hwndRelated));
3088 return hwndRelated;
3089}
3090//******************************************************************************
3091//******************************************************************************
3092HWND Win32BaseWindow::SetActiveWindow()
3093{
3094 HWND hwndActive;
3095
3096 dprintf(("SetActiveWindow %x", getWindowHandle()));
3097 if (HOOK_IsHooked( WH_CBT ))
3098 {
3099 CBTACTIVATESTRUCT cbta;
3100 LRESULT ret;
3101
3102 cbta.fMouse = FALSE;
3103 cbta.hWndActive = GetActiveWindow();
3104 ret = HOOK_CallHooksA(WH_CBT, HCBT_ACTIVATE, getWindowHandle(), (LPARAM)&cbta);
3105 if(ret)
3106 {
3107 dprintf(("SetActiveWindow %x, CBT hook cancelled operation", getWindowHandle()));
3108 return cbta.hWndActive;
3109 }
3110 }
3111 SetWindowPos(HWND_TOP, 0,0,0,0, SWP_NOSIZE | SWP_NOMOVE );
3112
3113// if(OSLibWinSetActiveWindow(OS2Hwnd) == FALSE) {
3114// dprintf(("OSLibWinSetActiveWindow %x returned FALSE!", OS2Hwnd));
3115// }
3116 hwndActive = GetActiveWindow();
3117 return (hwndActive) ? hwndActive : windowDesktop->getWindowHandle(); //pretend the desktop was active
3118}
3119//******************************************************************************
3120//Used to change active status of an mdi window
3121//******************************************************************************
3122BOOL Win32BaseWindow::DeactivateChildWindow()
3123{
3124 /* child windows get a WM_CHILDACTIVATE message */
3125 if((getStyle() & (WS_CHILD | WS_POPUP)) == WS_CHILD )
3126 {
3127 ULONG flags = OSLibWinGetWindowULong(getOS2WindowHandle(), OFFSET_WIN32FLAGS);
3128 OSLibWinSetWindowULong(getOS2WindowHandle(), OFFSET_WIN32FLAGS, (flags & ~WINDOWFLAG_ACTIVE));
3129 return TRUE;
3130 }
3131 DebugInt3(); //should not be called for non-child window
3132 return FALSE;
3133}
3134//******************************************************************************
3135//WM_ENABLE is sent to hwnd, but not to it's children (as it should be)
3136//******************************************************************************
3137BOOL Win32BaseWindow::EnableWindow(BOOL fEnable)
3138{
3139 BOOL rc;
3140
3141 dprintf(("Win32BaseWindow::EnableWindow %x %d", getWindowHandle(), fEnable));
3142 //return true if previous state was disabled, else false (sdk docs)
3143 rc = (getStyle() & WS_DISABLED) != 0;
3144 if(rc && !fEnable) {
3145 SendMessageA(WM_CANCELMODE, 0, 0);
3146 }
3147 OSLibWinEnableWindow(OS2Hwnd, fEnable);
3148 if(fEnable == FALSE) {
3149 //SvL: No need to clear focus as PM already does this
3150 if(getWindowHandle() == GetCapture()) {
3151 ReleaseCapture(); /* A disabled window can't capture the mouse */
3152 dprintf(("Released capture for window %x that is being disabled", getWindowHandle()));
3153 }
3154 }
3155 return rc;
3156}
3157//******************************************************************************
3158//******************************************************************************
3159BOOL Win32BaseWindow::CloseWindow()
3160{
3161 return OSLibWinMinimizeWindow(OS2Hwnd);
3162}
3163//******************************************************************************
3164//TODO: Not be 100% correct; should return active window of current thread
3165// or NULL when there is none -> WinQueryActiveWindow just returns
3166// the current active window
3167//******************************************************************************
3168HWND Win32BaseWindow::GetActiveWindow()
3169{
3170 HWND hwndActive;
3171 Win32BaseWindow *win32wnd;
3172 ULONG magic;
3173
3174 hwndActive = OSLibWinQueryActiveWindow();
3175
3176 return OS2ToWin32Handle(hwndActive);
3177}
3178//******************************************************************************
3179//******************************************************************************
3180BOOL Win32BaseWindow::IsWindowEnabled()
3181{
3182 return OSLibWinIsWindowEnabled(OS2Hwnd);
3183}
3184//******************************************************************************
3185//******************************************************************************
3186BOOL Win32BaseWindow::IsWindowVisible()
3187{
3188 //TODO: Do we have to check the state of the parent window? (as Wine does)
3189#if 1
3190 return (dwStyle & WS_VISIBLE) == WS_VISIBLE;
3191#else
3192 return OSLibWinIsWindowVisible(OS2Hwnd);
3193#endif
3194}
3195//******************************************************************************
3196//******************************************************************************
3197BOOL Win32BaseWindow::hasWindowName(LPSTR wndname, BOOL fUnicode)
3198{
3199 INT len = GetWindowTextLength();
3200 BOOL res;
3201
3202 if (wndname == NULL)
3203 return (len == 0);
3204
3205 len++;
3206 if (fUnicode)
3207 {
3208 WCHAR *text = (WCHAR*)malloc(len*sizeof(WCHAR));
3209
3210 GetWindowTextW(text,len);
3211 res = (lstrcmpW(text,(LPWSTR)wndname) == 0);
3212 free(text);
3213 } else
3214 {
3215 CHAR *text = (CHAR*)malloc(len*sizeof(CHAR));
3216
3217 GetWindowTextA(text,len);
3218 res = (strcmp(text,wndname) == 0);
3219 free(text);
3220 }
3221
3222 return res;
3223}
3224//******************************************************************************
3225//******************************************************************************
3226CHAR *Win32BaseWindow::getWindowNamePtrA()
3227{
3228 INT len = GetWindowTextLength();
3229 CHAR *text;
3230
3231 if (len == 0) return NULL;
3232 len++;
3233 text = (CHAR*)malloc(len*sizeof(CHAR));
3234 GetWindowTextA(text,len);
3235
3236 return text;
3237}
3238//******************************************************************************
3239//******************************************************************************
3240WCHAR *Win32BaseWindow::getWindowNamePtrW()
3241{
3242 INT len = GetWindowTextLength();
3243 WCHAR *text;
3244
3245 if (len == 0) return NULL;
3246 len++;
3247 text = (WCHAR*)malloc(len*sizeof(WCHAR));
3248 GetWindowTextW(text,len);
3249
3250 return text;
3251}
3252//******************************************************************************
3253//******************************************************************************
3254VOID Win32BaseWindow::freeWindowNamePtr(PVOID namePtr)
3255{
3256 if (namePtr) free(namePtr);
3257}
3258//******************************************************************************
3259//When using this API for a window that was created by a different process, NT
3260//does NOT send WM_GETTEXTLENGTH.
3261//******************************************************************************
3262int Win32BaseWindow::GetWindowTextLength()
3263{
3264 //if the destination window is created by this process, send message
3265 if(dwProcessId == currentProcessId) {
3266 return SendInternalMessageA(WM_GETTEXTLENGTH,0,0);
3267 }
3268 //else get data directory from window structure
3269 return wndNameLength;
3270}
3271//******************************************************************************
3272//When using this API for a window that was created by a different process, NT
3273//does NOT send WM_GETTEXT.
3274//******************************************************************************
3275int Win32BaseWindow::GetWindowTextA(LPSTR lpsz, int cch)
3276{
3277 //if the destination window is created by this process, send message
3278 if(dwProcessId == currentProcessId) {
3279 return SendInternalMessageA(WM_GETTEXT,(WPARAM)cch,(LPARAM)lpsz);
3280 }
3281 //else get data directory from window structure
3282 if (!lpsz || !cch) return 0;
3283 if (!windowNameA) lpsz[0] = 0;
3284 else lstrcpynA(lpsz, windowNameA, cch);
3285 return min(wndNameLength, cch);
3286}
3287//******************************************************************************
3288//When using this API for a window that was created by a different process, NT
3289//does NOT send WM_GETTEXT.
3290//******************************************************************************
3291int Win32BaseWindow::GetWindowTextW(LPWSTR lpsz, int cch)
3292{
3293 //if the destination window is created by this process, send message
3294 if(dwProcessId == currentProcessId) {
3295 return SendInternalMessageW(WM_GETTEXT,(WPARAM)cch,(LPARAM)lpsz);
3296 }
3297 //else get data directory from window structure
3298 if (!lpsz || !cch) return 0;
3299 if (!windowNameW) lpsz[0] = 0;
3300 else lstrcpynW(lpsz, windowNameW, cch);
3301 return min(wndNameLength, cch);
3302}
3303//******************************************************************************
3304//TODO: How does this work when the target window belongs to a different process???
3305//******************************************************************************
3306BOOL Win32BaseWindow::SetWindowTextA(LPSTR lpsz)
3307{
3308 return SendInternalMessageA(WM_SETTEXT,0,(LPARAM)lpsz);
3309}
3310//******************************************************************************
3311//******************************************************************************
3312BOOL Win32BaseWindow::SetWindowTextW(LPWSTR lpsz)
3313{
3314 return SendInternalMessageW(WM_SETTEXT,0,(LPARAM)lpsz);
3315}
3316//******************************************************************************
3317//******************************************************************************
3318LONG Win32BaseWindow::SetWindowLongA(int index, ULONG value, BOOL fUnicode)
3319{
3320 LONG oldval;
3321
3322 switch(index) {
3323 case GWL_EXSTYLE:
3324 {
3325 STYLESTRUCT ss;
3326
3327 if(dwExStyle == value) {
3328 oldval = value;
3329 break;
3330 }
3331 ss.styleOld = dwExStyle;
3332 ss.styleNew = value;
3333 dprintf(("SetWindowLong GWL_EXSTYLE %x old %x new style %x", getWindowHandle(), dwExStyle, value));
3334 SendInternalMessageA(WM_STYLECHANGING,GWL_EXSTYLE,(LPARAM)&ss);
3335 setExStyle(ss.styleNew);
3336 SendInternalMessageA(WM_STYLECHANGED,GWL_EXSTYLE,(LPARAM)&ss);
3337 oldval = ss.styleOld;
3338 break;
3339 }
3340 case GWL_STYLE:
3341 {
3342 STYLESTRUCT ss;
3343
3344 //SvL: TODO: Can you change minimize or maximize status here too?
3345
3346 if(dwStyle == value) {
3347 oldval = value;
3348 break;
3349 }
3350 value &= ~(WS_CHILD|WS_VISIBLE); /* Some bits can't be changed this way (WINE) */
3351 ss.styleOld = getStyle();
3352 ss.styleNew = value | (ss.styleOld & (WS_CHILD|WS_VISIBLE));
3353 dprintf(("SetWindowLong GWL_STYLE %x old %x new style %x", getWindowHandle(), ss.styleOld, ss.styleNew));
3354 SendInternalMessageA(WM_STYLECHANGING,GWL_STYLE,(LPARAM)&ss);
3355 setStyle(ss.styleNew);
3356 SendInternalMessageA(WM_STYLECHANGED,GWL_STYLE,(LPARAM)&ss);
3357//// OSLibSetWindowStyle(getOS2WindowHandle(), getStyle(), getExStyle(),
3358//// windowClass->getStyle() & CS_SAVEBITS);
3359#ifdef DEBUG
3360 PrintWindowStyle(ss.styleNew, 0);
3361#endif
3362 oldval = ss.styleOld;
3363 break;
3364 }
3365 case GWL_WNDPROC:
3366 {
3367 //Note: Type of SetWindowLong determines new window proc type
3368 // UNLESS the new window proc has already been registered
3369 // (use the old type in that case)
3370 // (VERIFIED in NT 4, SP6)
3371 WINDOWPROCTYPE type = WINPROC_GetProcType((HWINDOWPROC)value);
3372 if(type == WIN_PROC_INVALID) {
3373 type = (fUnicode) ? WIN_PROC_32W : WIN_PROC_32A;
3374 }
3375 oldval = (LONG)WINPROC_GetProc(win32wndproc, (fUnicode) ? WIN_PROC_32W : WIN_PROC_32A);
3376 WINPROC_SetProc((HWINDOWPROC *)&win32wndproc, (WNDPROC)value, type, WIN_PROC_WINDOW);
3377 break;
3378 }
3379 case GWL_HINSTANCE:
3380 oldval = hInstance;
3381 hInstance = value;
3382 break;
3383
3384 case GWL_HWNDPARENT:
3385 oldval = SetParent((HWND)value);
3386 break;
3387
3388 case GWL_ID:
3389 oldval = getWindowId();
3390 setWindowId(value);
3391 break;
3392
3393 case GWL_USERDATA:
3394 oldval = userData;
3395 userData = value;
3396 break;
3397
3398 default:
3399 if(index >= 0 && index/4 < nrUserWindowLong)
3400 {
3401 oldval = userWindowLong[index/4];
3402 userWindowLong[index/4] = value;
3403 break;
3404 }
3405 dprintf(("WARNING: SetWindowLong%c %x %d %x returned %x INVALID index!", (fUnicode) ? 'W' : 'A', getWindowHandle(), index, value));
3406 SetLastError(ERROR_INVALID_INDEX); //verified in NT4, SP6
3407 return 0;
3408 }
3409 //Note: NT4, SP6 does not set the last error to 0
3410 SetLastError(ERROR_SUCCESS);
3411 dprintf2(("SetWindowLong%c %x %d %x returned %x", (fUnicode) ? 'W' : 'A', getWindowHandle(), index, value, oldval));
3412 return oldval;
3413}
3414//******************************************************************************
3415//******************************************************************************
3416ULONG Win32BaseWindow::GetWindowLongA(int index, BOOL fUnicode)
3417{
3418 ULONG value;
3419
3420 switch(index) {
3421 case GWL_EXSTYLE:
3422 value = dwExStyle;
3423 break;
3424 case GWL_STYLE:
3425 value = dwStyle;
3426 break;
3427 case GWL_WNDPROC:
3428 value = (LONG)WINPROC_GetProc(win32wndproc, (fUnicode) ? WIN_PROC_32W : WIN_PROC_32A);
3429 break;
3430 case GWL_HINSTANCE:
3431 value = hInstance;
3432 break;
3433 case GWL_HWNDPARENT:
3434 value = GetParent();
3435 break;
3436 case GWL_ID:
3437 value = getWindowId();
3438 break;
3439 case GWL_USERDATA:
3440 value = userData;
3441 break;
3442 default:
3443 if(index >= 0 && index/4 < nrUserWindowLong)
3444 {
3445 value = userWindowLong[index/4];
3446 break;
3447 }
3448 SetLastError(ERROR_INVALID_INDEX); //verified in NT4, SP6
3449 return 0;
3450 }
3451 dprintf2(("GetWindowLongA %x %d %x", getWindowHandle(), index, value));
3452 //Note: NT4, SP6 does not set the last error to 0
3453 SetLastError(ERROR_SUCCESS);
3454 return value;
3455}
3456//******************************************************************************
3457//******************************************************************************
3458WORD Win32BaseWindow::SetWindowWord(int index, WORD value)
3459{
3460 WORD oldval;
3461
3462 if(index >= 0 && index/4 < nrUserWindowLong)
3463 {
3464 oldval = ((WORD *)userWindowLong)[index/2];
3465 ((WORD *)userWindowLong)[index/2] = value;
3466 //Note: NT4, SP6 does not set the last error to 0
3467 SetLastError(ERROR_SUCCESS);
3468 return oldval;
3469 }
3470 SetLastError(ERROR_INVALID_INDEX); //verified in NT4, SP6
3471 return 0;
3472}
3473//******************************************************************************
3474//******************************************************************************
3475WORD Win32BaseWindow::GetWindowWord(int index)
3476{
3477 if(index >= 0 && index/4 < nrUserWindowLong)
3478 {
3479 //Note: NT4, SP6 does not set the last error to 0
3480 SetLastError(ERROR_SUCCESS);
3481 return ((WORD *)userWindowLong)[index/2];
3482 }
3483 SetLastError(ERROR_INVALID_INDEX); //verified in NT4, SP6
3484 return 0;
3485}
3486//******************************************************************************
3487//******************************************************************************
3488void Win32BaseWindow::setWindowId(DWORD id)
3489{
3490 dwIDMenu = id;
3491}
3492//******************************************************************************
3493//******************************************************************************
3494Win32BaseWindow *Win32BaseWindow::GetWindowFromHandle(HWND hwnd)
3495{
3496 Win32BaseWindow *window;
3497
3498 if(HwGetWindowHandleData(hwnd, (DWORD *)&window) == TRUE) {
3499 return window;
3500 }
3501// dprintf2(("Win32BaseWindow::GetWindowFromHandle: not a win32 window %x", hwnd));
3502 return NULL;
3503}
3504//******************************************************************************
3505//******************************************************************************
3506Win32BaseWindow *Win32BaseWindow::GetWindowFromOS2Handle(HWND hwnd)
3507{
3508 Win32BaseWindow *win32wnd;
3509 DWORD magic;
3510
3511 if(hwnd == OSLIB_HWND_DESKTOP)
3512 {
3513 return windowDesktop;
3514 }
3515
3516 win32wnd = (Win32BaseWindow *)OSLibWinGetWindowULong(hwnd, OFFSET_WIN32WNDPTR);
3517 magic = OSLibWinGetWindowULong(hwnd, OFFSET_WIN32PM_MAGIC);
3518
3519 if(win32wnd && CheckMagicDword(magic)) {
3520 return win32wnd;
3521 }
3522// dprintf2(("Win32BaseWindow::GetWindowFromOS2Handle: not an Odin os2 window %x", hwnd));
3523 return 0;
3524}
3525//******************************************************************************
3526//******************************************************************************
3527HWND Win32BaseWindow::getNextDlgGroupItem(HWND hwndCtrl, BOOL fPrevious)
3528{
3529 Win32BaseWindow *child, *nextchild, *lastchild;
3530 HWND retvalue;
3531
3532 if (hwndCtrl)
3533 {
3534 child = GetWindowFromHandle(hwndCtrl);
3535 if (!child)
3536 {
3537 retvalue = 0;
3538 goto END;
3539 }
3540 /* Make sure hwndCtrl is a top-level child */
3541 while ((child->getStyle() & WS_CHILD) && (child->getParent() != this))
3542 {
3543 child = child->getParent();
3544 if(child == NULL) break;
3545 }
3546
3547 if (!child || (child->getParent() != this))
3548 {
3549 retvalue = 0;
3550 goto END;
3551 }
3552 }
3553 else
3554 {
3555 /* No ctrl specified -> start from the beginning */
3556 child = (Win32BaseWindow *)getFirstChild();
3557 if (!child)
3558 {
3559 retvalue = 0;
3560 goto END;
3561 }
3562
3563 if (fPrevious)
3564 {
3565 while (child->getNextChild())
3566 {
3567 child = (Win32BaseWindow *)child->getNextChild();
3568 }
3569 }
3570 }
3571
3572 lastchild = child;
3573 nextchild = (Win32BaseWindow *)child->getNextChild();
3574 while (TRUE)
3575 {
3576 if (!nextchild || (nextchild->getStyle() & WS_GROUP))
3577 {
3578 /* Wrap-around to the beginning of the group */
3579 Win32BaseWindow *pWndTemp;
3580
3581 nextchild = (Win32BaseWindow *)getFirstChild();
3582
3583 for(pWndTemp = nextchild;pWndTemp;pWndTemp = (Win32BaseWindow *)pWndTemp->getNextChild())
3584 {
3585 if (pWndTemp->getStyle() & WS_GROUP)
3586 nextchild = pWndTemp;
3587
3588 if (pWndTemp == child)
3589 break;
3590 }
3591
3592 }
3593 if (nextchild == child)
3594 break;
3595
3596 if ((nextchild->getStyle() & WS_VISIBLE) && !(nextchild->getStyle() & WS_DISABLED))
3597 {
3598 lastchild = nextchild;
3599
3600 if (!fPrevious)
3601 break;
3602 }
3603
3604 nextchild = (Win32BaseWindow *)nextchild->getNextChild();
3605 }
3606 retvalue = lastchild->getWindowHandle();
3607END:
3608 return retvalue;
3609}
3610//******************************************************************************
3611//******************************************************************************
3612#ifdef DEBUG
3613void PrintWindowStyle(DWORD dwStyle, DWORD dwExStyle)
3614{
3615 char style[256] = "";
3616 char exstyle[256] = "";
3617
3618 /* Window styles */
3619 if(dwStyle & WS_CHILD)
3620 strcat(style, "WS_CHILD ");
3621 if(dwStyle & WS_POPUP)
3622 strcat(style, "WS_POPUP ");
3623 if(dwStyle & WS_VISIBLE)
3624 strcat(style, "WS_VISIBLE ");
3625 if(dwStyle & WS_DISABLED)
3626 strcat(style, "WS_DISABLED ");
3627 if(dwStyle & WS_CLIPSIBLINGS)
3628 strcat(style, "WS_CLIPSIBLINGS ");
3629 if(dwStyle & WS_CLIPCHILDREN)
3630 strcat(style, "WS_CLIPCHILDREN ");
3631 if(dwStyle & WS_MAXIMIZE)
3632 strcat(style, "WS_MAXIMIZE ");
3633 if(dwStyle & WS_MINIMIZE)
3634 strcat(style, "WS_MINIMIZE ");
3635 if(dwStyle & WS_GROUP)
3636 strcat(style, "WS_GROUP ");
3637 if(dwStyle & WS_TABSTOP)
3638 strcat(style, "WS_TABSTOP ");
3639
3640 if((dwStyle & WS_CAPTION) == WS_CAPTION)
3641 strcat(style, "WS_CAPTION ");
3642 if(dwStyle & WS_DLGFRAME)
3643 strcat(style, "WS_DLGFRAME ");
3644 if(dwStyle & WS_BORDER)
3645 strcat(style, "WS_BORDER ");
3646
3647 if(dwStyle & WS_VSCROLL)
3648 strcat(style, "WS_VSCROLL ");
3649 if(dwStyle & WS_HSCROLL)
3650 strcat(style, "WS_HSCROLL ");
3651 if(dwStyle & WS_SYSMENU)
3652 strcat(style, "WS_SYSMENU ");
3653 if(dwStyle & WS_THICKFRAME)
3654 strcat(style, "WS_THICKFRAME ");
3655 if(dwStyle & WS_MINIMIZEBOX)
3656 strcat(style, "WS_MINIMIZEBOX ");
3657 if(dwStyle & WS_MAXIMIZEBOX)
3658 strcat(style, "WS_MAXIMIZEBOX ");
3659
3660 if(dwExStyle & WS_EX_DLGMODALFRAME)
3661 strcat(exstyle, "WS_EX_DLGMODALFRAME ");
3662 if(dwExStyle & WS_EX_ACCEPTFILES)
3663 strcat(exstyle, "WS_EX_ACCEPTFILES ");
3664 if(dwExStyle & WS_EX_NOPARENTNOTIFY)
3665 strcat(exstyle, "WS_EX_NOPARENTNOTIFY ");
3666 if(dwExStyle & WS_EX_TOPMOST)
3667 strcat(exstyle, "WS_EX_TOPMOST ");
3668 if(dwExStyle & WS_EX_TRANSPARENT)
3669 strcat(exstyle, "WS_EX_TRANSPARENT ");
3670
3671 if(dwExStyle & WS_EX_MDICHILD)
3672 strcat(exstyle, "WS_EX_MDICHILD ");
3673 if(dwExStyle & WS_EX_TOOLWINDOW)
3674 strcat(exstyle, "WS_EX_TOOLWINDOW ");
3675 if(dwExStyle & WS_EX_WINDOWEDGE)
3676 strcat(exstyle, "WS_EX_WINDOWEDGE ");
3677 if(dwExStyle & WS_EX_CLIENTEDGE)
3678 strcat(exstyle, "WS_EX_CLIENTEDGE ");
3679 if(dwExStyle & WS_EX_CONTEXTHELP)
3680 strcat(exstyle, "WS_EX_CONTEXTHELP ");
3681 if(dwExStyle & WS_EX_RIGHT)
3682 strcat(exstyle, "WS_EX_RIGHT ");
3683 if(dwExStyle & WS_EX_LEFT)
3684 strcat(exstyle, "WS_EX_LEFT ");
3685 if(dwExStyle & WS_EX_RTLREADING)
3686 strcat(exstyle, "WS_EX_RTLREADING ");
3687 if(dwExStyle & WS_EX_LTRREADING)
3688 strcat(exstyle, "WS_EX_LTRREADING ");
3689 if(dwExStyle & WS_EX_LEFTSCROLLBAR)
3690 strcat(exstyle, "WS_EX_LEFTSCROLLBAR ");
3691 if(dwExStyle & WS_EX_RIGHTSCROLLBAR)
3692 strcat(exstyle, "WS_EX_RIGHTSCROLLBAR ");
3693 if(dwExStyle & WS_EX_CONTROLPARENT)
3694 strcat(exstyle, "WS_EX_CONTROLPARENT ");
3695 if(dwExStyle & WS_EX_STATICEDGE)
3696 strcat(exstyle, "WS_EX_STATICEDGE ");
3697 if(dwExStyle & WS_EX_APPWINDOW)
3698 strcat(exstyle, "WS_EX_APPWINDOW ");
3699
3700 dprintf(("Window style: %x %s", dwStyle, style));
3701 dprintf(("Window exStyle: %x %s", dwExStyle, exstyle));
3702}
3703#endif
3704//******************************************************************************
3705//******************************************************************************
3706HWND WIN32API Win32ToOS2Handle(HWND hwnd)
3707{
3708 Win32BaseWindow *window = Win32BaseWindow::GetWindowFromHandle(hwnd);
3709
3710 if(window) {
3711 return window->getOS2WindowHandle();
3712 }
3713// dprintf2(("Win32BaseWindow::Win32ToOS2Handle: not a win32 window %x", hwnd));
3714 return hwnd;
3715}
3716//******************************************************************************
3717//******************************************************************************
3718HWND WIN32API OS2ToWin32Handle(HWND hwnd)
3719{
3720 Win32BaseWindow *window = Win32BaseWindow::GetWindowFromOS2Handle(hwnd);
3721
3722 if(window) {
3723 return window->getWindowHandle();
3724 }
3725// dprintf2(("Win32BaseWindow::OS2ToWin32Handle: not a win32 window %x", hwnd));
3726 return 0;
3727// else return hwnd; //OS/2 window handle
3728}
3729//******************************************************************************
3730//******************************************************************************
3731
3732GenericObject *Win32BaseWindow::windows = NULL;
Note: See TracBrowser for help on using the repository browser.