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

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

WM_FOCUSCHANGE fixes + misc fixes

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