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

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

Get/SetWindowLongA fixes (last error) + focus hack for realplayer 8

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