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

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

fixes for minimizing frame windows + WM_BUTTONxMOTIONSTART/END handling

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