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

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

SetWindowPos fix for SWP_FRAMECHANGED

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