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

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

extra exports for gdi32; moved 4 apis back into gdi32

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