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

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

Win32ToOS2Handle & OS2ToWin32Handle exported with stdcall calling convention

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