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

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

class, dialog control size & drawedge fixes

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