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

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

Get/SetWindowPlacement fixes

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