source: trunk/src/user32/window.cpp@ 21347

Last change on this file since 21347 was 21347, checked in by vladest, 16 years ago
  1. Remove setting up Windows codepage for ODIN PM session. This is incorrect. Fixed umlaut problem
  2. Textinput improves. Attempt to add deadchars support
File size: 78.8 KB
Line 
1/* $Id: window.cpp,v 1.140 2004-03-09 10:06:15 sandervl Exp $ */
2/*
3 * Win32 window apis for OS/2
4 *
5 * Copyright 1999-2001 Sander van Leeuwen (sandervl@xs4all.nl)
6 * Copyright 1999 Daniela Engert (dani@ngrt.de)
7 * Copyright 2000 Christoph Bratschi (cbratschi@datacomm.ch)
8 *
9 * Parts based on Wine Windows code (windows\win.c, windows\property.c, windows\winpos.c)
10 *
11 * Copyright 1993, 1994, 1995 Alexandre Julliard
12 * 1995, 1996, 1999 Alex Korobka
13 *
14 * Project Odin Software License can be found in LICENSE.TXT
15 *
16 *
17 * TODO: Decide what to do about commands for OS/2 windows (non-Win32 apps)
18 * TODO: ShowOwnedPopups needs to be tested
19 * GetLastActivePopup needs to be rewritten
20 *
21 */
22
23#include <odin.h>
24#include <odinwrap.h>
25#include <os2sel.h>
26
27#include <os2win.h>
28#include <misc.h>
29#include <string.h>
30#include <stdio.h>
31#include <win32wbase.h>
32#include <win32wmdiclient.h>
33#include <win32wdesktop.h>
34#include "win32dlg.h"
35#include <oslibwin.h>
36#include <oslibgdi.h>
37#include "user32.h"
38#include "winicon.h"
39#include "pmwindow.h"
40#include "oslibmsg.h"
41#include <win\winpos.h>
42#include <win\win.h>
43#include <heapstring.h>
44#include <winuser32.h>
45#include "hook.h"
46#include <wprocess.h>
47#include <custombuild.h>
48
49#define DBG_LOCALLOG DBG_window
50#include "dbglocal.h"
51
52ODINDEBUGCHANNEL(USER32-WINDOW)
53
54
55//******************************************************************************
56//******************************************************************************
57HWND WIN32API CreateWindowExA(DWORD exStyle,
58 LPCSTR className,
59 LPCSTR windowName,
60 DWORD style,
61 INT x,
62 INT y,
63 INT width,
64 INT height,
65 HWND parent,
66 HMENU menu,
67 HINSTANCE instance,
68 LPVOID data )
69{
70 Win32BaseWindow *window;
71 ATOM classAtom;
72 CREATESTRUCTA cs;
73 char tmpClass[20];
74
75 if(exStyle & WS_EX_MDICHILD)
76 return CreateMDIWindowA(className, windowName, style, x, y, width, height, parent, instance, (LPARAM)data);
77
78 /* Find the class atom */
79 if (!(classAtom = GlobalFindAtomA(className)))
80 {
81 if (!HIWORD(className))
82 dprintf(("CreateWindowEx32A: bad class name %04x\n",LOWORD(className)));
83 else
84 dprintf(("CreateWindowEx32A: bad class name '%s'\n", className));
85
86 SetLastError(ERROR_INVALID_PARAMETER);
87 return 0;
88 }
89
90 // if the pointer to the classname string has the high word cleared,
91 // then it's not a pointer but a number for one of the builtin classes
92 if (!HIWORD(className))
93 {
94 sprintf(tmpClass,"#%d", (int) className);
95 className = tmpClass;
96 }
97
98 /* Create the window */
99 cs.lpCreateParams = data;
100 cs.hInstance = instance;
101 cs.hMenu = menu;
102 cs.hwndParent = parent;
103 cs.x = x;
104 cs.y = y;
105 cs.cx = width;
106 cs.cy = height;
107 cs.style = style;
108 cs.lpszName = windowName;
109 cs.lpszClass = className;
110 cs.dwExStyle = exStyle;
111
112 HOOK_CallOdinHookA(HODIN_PREWINDOWCREATEDA, 0, (DWORD)&cs);
113
114 if(HIWORD(className)) {
115 dprintf(("CreateWindowExA: window %s class %s parent %x (%d,%d) (%d,%d), %x %x menu=%x", windowName, className, parent, x, y, width, height, style, exStyle, menu));
116 }
117 else dprintf(("CreateWindowExA: window %s class %d parent %x (%d,%d) (%d,%d), %x %x menu=%x", windowName, className, parent, x, y, width, height, style, exStyle, menu));
118
119 if(!strcmpi(className, MDICLIENTCLASSNAMEA)) {
120 window = (Win32BaseWindow *) new Win32MDIClientWindow(&cs, classAtom, FALSE);
121 }
122 else
123 if(!strcmpi((char *) className, DIALOG_CLASS_NAMEA))
124 {
125 DLG_TEMPLATE dlgTemplate = {0};
126 dlgTemplate.style = cs.style;
127 dlgTemplate.exStyle = cs.dwExStyle;
128 dlgTemplate.x = cs.x;
129 dlgTemplate.y = cs.y;
130 dlgTemplate.cx = cs.cx;
131 dlgTemplate.cy = cs.cy;
132 dlgTemplate.className = cs.lpszClass;
133 dlgTemplate.caption = cs.lpszName;
134 window = (Win32BaseWindow *) new Win32Dialog(cs.hInstance,
135 (LPCSTR) &dlgTemplate,
136 cs.hwndParent,
137 NULL,
138 (LPARAM) data,
139 FALSE);
140 }
141 else {
142 window = new Win32BaseWindow( &cs, classAtom, FALSE );
143 }
144 if(window == NULL)
145 {
146 dprintf(("Win32BaseWindow creation failed!!"));
147 return 0;
148 }
149 if(GetLastError() != 0)
150 {
151 dprintf(("Win32BaseWindow error found!!"));
152 RELEASE_WNDOBJ(window);
153 delete window;
154 return 0;
155 }
156 HWND hwnd = window->getWindowHandle();
157
158 // set myself as last active popup / window
159 window->setLastActive( hwnd );
160
161 RELEASE_WNDOBJ(window);
162 return hwnd;
163}
164//******************************************************************************
165//******************************************************************************
166HWND WIN32API CreateWindowExW(DWORD exStyle,
167 LPCWSTR className,
168 LPCWSTR windowName,
169 DWORD style,
170 INT x,
171 INT y,
172 INT width,
173 INT height,
174 HWND parent,
175 HMENU menu,
176 HINSTANCE instance,
177 LPVOID data )
178{
179 Win32BaseWindow *window;
180 ATOM classAtom;
181 CREATESTRUCTA cs;
182 WCHAR tmpClassW[20];
183
184 if(exStyle & WS_EX_MDICHILD)
185 return CreateMDIWindowW(className, windowName, style, x, y, width, height, parent, instance, (LPARAM)data);
186
187 /* Find the class atom */
188 if (!(classAtom = GlobalFindAtomW(className)))
189 {
190 if (!HIWORD(className))
191 dprintf(("CreateWindowEx32W: bad class name %04x",LOWORD(className)));
192 else
193 dprintf(("CreateWindowEx32W: bad class name '%ls'", className));
194
195 SetLastError(ERROR_INVALID_PARAMETER);
196 return 0;
197 }
198#ifdef DEBUG
199 if(HIWORD(className)) {
200 dprintf(("CreateWindowExW: class %ls name %ls parent %x (%d,%d) (%d,%d), %x %x menu=%x", className, HIWORD(windowName) ? windowName : NULL, parent, x, y, width, height, style, exStyle, menu));
201 }
202 else dprintf(("CreateWindowExW: class %d name %ls parent %x (%d,%d) (%d,%d), %x %x menu=%x", className, HIWORD(windowName) ? windowName : NULL, parent, x, y, width, height, style, exStyle, menu));
203#endif
204 // if the pointer to the classname string has the high word cleared,
205 // then it's not a pointer but a number for one of the builtin classes
206 if (!HIWORD(className))
207 {
208 wsprintfW(tmpClassW, (LPCWSTR)L"#%d", (int) className);
209 className = tmpClassW;
210 }
211
212 /* Create the window */
213 cs.lpCreateParams = data;
214 cs.hInstance = instance;
215 cs.hMenu = menu;
216 cs.hwndParent = parent;
217 cs.x = x;
218 cs.y = y;
219 cs.cx = width;
220 cs.cy = height;
221 cs.style = style;
222 cs.lpszName = (LPSTR)windowName;
223 cs.lpszClass = (LPSTR)className;
224 cs.dwExStyle = exStyle;
225
226 if(!lstrcmpiW(className, (LPWSTR)MDICLIENTCLASSNAMEW)) {
227 window = (Win32BaseWindow *) new Win32MDIClientWindow(&cs, classAtom, TRUE);
228 }
229 else
230 if(!lstrcmpiW(className, (LPWSTR)DIALOG_CLASS_NAMEW))
231 {
232 DLG_TEMPLATE dlgTemplate = {0};
233 dlgTemplate.style = cs.style;
234 dlgTemplate.exStyle = cs.dwExStyle;
235 dlgTemplate.x = cs.x;
236 dlgTemplate.y = cs.y;
237 dlgTemplate.cx = cs.cx;
238 dlgTemplate.cy = cs.cy;
239 dlgTemplate.className = cs.lpszClass;
240 dlgTemplate.caption = cs.lpszName;
241 window = (Win32BaseWindow *) new Win32Dialog(cs.hInstance,
242 (LPCSTR) &dlgTemplate,
243 cs.hwndParent,
244 NULL,
245 (LPARAM) data,
246 TRUE);
247 }
248 else {
249 window = new Win32BaseWindow( &cs, classAtom, TRUE );
250 }
251 if(window == NULL)
252 {
253 dprintf(("Win32BaseWindow creation failed!!"));
254 return 0;
255 }
256 if(GetLastError() != 0)
257 {
258 dprintf(("Win32BaseWindow error found!!"));
259 RELEASE_WNDOBJ(window);
260 delete window;
261 return 0;
262 }
263 HWND hwnd = window->getWindowHandle();
264
265 // set myself as last active popup / window
266 window->setLastActive( hwnd );
267
268 RELEASE_WNDOBJ(window);
269 return hwnd;
270}
271//******************************************************************************
272//******************************************************************************
273BOOL WIN32API DestroyWindow(HWND hwnd)
274{
275 Win32BaseWindow *window;
276 BOOL ret;
277
278 window = Win32BaseWindow::GetWindowFromHandle(hwnd);
279 if(!window) {
280 dprintf(("DestroyWindow, window %x not found", hwnd));
281 SetLastError(ERROR_INVALID_WINDOW_HANDLE);
282 return 0;
283 }
284 ret = window->DestroyWindow();
285 RELEASE_WNDOBJ(window);
286 return ret;
287}
288//******************************************************************************
289//******************************************************************************
290HWND WIN32API SetActiveWindow(HWND hwnd)
291{
292 Win32BaseWindow *window;
293 HWND hwndActive;
294
295 window = Win32BaseWindow::GetWindowFromHandle(hwnd);
296 if(!window) {
297 dprintf(("SetActiveWindow, window %x not found", hwnd));
298 SetLastError(ERROR_INVALID_WINDOW_HANDLE);
299 return 0;
300 }
301 hwndActive = window->SetActiveWindow();
302
303 // check last active popup window
304 if (hwndActive)
305 {
306 // TODO:
307 // set last active popup window to the ancestor window
308 dprintf(("support for last active popup incorrectly implemented"));
309 }
310
311 RELEASE_WNDOBJ(window);
312 return hwndActive;
313}
314//******************************************************************************
315//Note: does not set last error if no parent (verified in NT4, SP6)
316//******************************************************************************
317HWND WIN32API GetParent(HWND hwnd)
318{
319 Win32BaseWindow *window;
320 HWND hwndParent;
321
322 window = Win32BaseWindow::GetWindowFromHandle(hwnd);
323 if(!window) {
324 dprintf(("GetParent, window %x not found", hwnd));
325 SetLastError(ERROR_INVALID_WINDOW_HANDLE);
326 return 0;
327 }
328 dprintf2(("GetParent %x", hwnd));
329 hwndParent = window->GetParent();
330 RELEASE_WNDOBJ(window);
331 return hwndParent;
332}
333//******************************************************************************
334//******************************************************************************
335HWND WIN32API SetParent(HWND hwndChild, HWND hwndNewParent)
336{
337 Win32BaseWindow *window;
338 HWND hwndOldParent;
339
340 window = Win32BaseWindow::GetWindowFromHandle(hwndChild);
341 if(!window) {
342 dprintf(("SetParent, window %x not found", hwndChild));
343 SetLastError(ERROR_INVALID_WINDOW_HANDLE);
344 return 0;
345 }
346 if(hwndNewParent == HWND_DESKTOP) {
347 hwndNewParent = GetDesktopWindow();
348 }
349 else {
350 if(!IsWindow(hwndNewParent)) {
351 RELEASE_WNDOBJ(window);
352 dprintf(("SetParent, parent %x not found", hwndNewParent));
353 SetLastError(ERROR_INVALID_WINDOW_HANDLE);
354 return 0;
355 }
356 }
357 dprintf(("SetParent %x %x", hwndChild, hwndNewParent));
358 hwndOldParent = window->SetParent(hwndNewParent);
359 RELEASE_WNDOBJ(window);
360 return hwndOldParent;
361}
362//******************************************************************************
363//******************************************************************************
364BOOL WIN32API IsChild(HWND hwndParent, HWND hwnd)
365{
366 Win32BaseWindow *window;
367 BOOL fIsChild;
368
369 window = Win32BaseWindow::GetWindowFromHandle(hwnd);
370 if(!window) {
371 dprintf(("IsChild %x, window %x not found", hwndParent, hwnd));
372 SetLastError(ERROR_INVALID_WINDOW_HANDLE);
373 return 0;
374 }
375 dprintf(("IsChild %x %x", hwndParent, hwnd));
376 fIsChild = window->IsChild(hwndParent);
377 RELEASE_WNDOBJ(window);
378 return fIsChild;
379}
380//******************************************************************************
381//******************************************************************************
382HWND WIN32API GetTopWindow(HWND hwnd)
383{
384 Win32BaseWindow *window;
385 HWND hwndTop;
386
387 if(hwnd == HWND_DESKTOP) {
388 windowDesktop->addRef();
389 window = windowDesktop;
390 }
391 else {
392 window = Win32BaseWindow::GetWindowFromHandle(hwnd);
393 if(!window) {
394 dprintf(("GetTopWindow, window %x not found", hwnd));
395 SetLastError(ERROR_INVALID_WINDOW_HANDLE);
396 return 0;
397 }
398 }
399 hwndTop = window->GetTopWindow();
400 dprintf2(("GetTopWindow %x returned %x", hwnd, hwndTop));
401 RELEASE_WNDOBJ(window);
402 return hwndTop;
403}
404//******************************************************************************
405//******************************************************************************
406BOOL WIN32API IsIconic(HWND hwnd)
407{
408 Win32BaseWindow *window;
409 BOOL fIsIconic;
410
411 window = Win32BaseWindow::GetWindowFromHandle(hwnd);
412 if(!window) {
413 dprintf(("IsIconic, window %x not found", hwnd));
414 SetLastError(ERROR_INVALID_WINDOW_HANDLE);
415 return FALSE;
416 }
417 fIsIconic = window->IsWindowIconic();
418 dprintf(("IsIconic %x returned %d", hwnd, fIsIconic));
419 RELEASE_WNDOBJ(window);
420 return fIsIconic;
421}
422//******************************************************************************
423//******************************************************************************
424HWND WIN32API GetWindow(HWND hwnd, UINT uCmd)
425{
426 Win32BaseWindow *window;
427 HWND hwndRelated;
428
429 window = Win32BaseWindow::GetWindowFromHandle(hwnd);
430 if(!window) {
431 dprintf(("GetWindow, window %x not found", hwnd));
432 SetLastError(ERROR_INVALID_WINDOW_HANDLE);
433 return 0;
434 }
435 hwndRelated = window->GetWindow(uCmd);
436 RELEASE_WNDOBJ(window);
437 return hwndRelated;
438}
439
440/******************************************************************************
441 * GetWindowInfo (USER32.@)
442 *
443 * Note: tests show that Windows doesn't check cbSize of the structure.
444 */
445BOOL WINAPI GetWindowInfo( HWND hwnd, PWINDOWINFO pwi)
446{
447 if (!pwi) return FALSE;
448 if (!IsWindow(hwnd)) return FALSE;
449
450 GetWindowRect(hwnd, &pwi->rcWindow);
451 GetClientRect(hwnd, &pwi->rcClient);
452 /* translate to screen coordinates */
453 MapWindowPoints(hwnd, 0, (LPPOINT)&pwi->rcClient, 2);
454
455 pwi->dwStyle = GetWindowLongW(hwnd, GWL_STYLE);
456 pwi->dwExStyle = GetWindowLongW(hwnd, GWL_EXSTYLE);
457 pwi->dwWindowStatus = ((GetActiveWindow() == hwnd) ? WS_ACTIVECAPTION : 0);
458
459 pwi->cxWindowBorders = pwi->rcClient.left - pwi->rcWindow.left;
460 pwi->cyWindowBorders = pwi->rcWindow.bottom - pwi->rcClient.bottom;
461
462 pwi->atomWindowType = GetClassLongW( hwnd, GCW_ATOM );
463 pwi->wCreatorVersion = 0x0400;
464
465 return TRUE;
466}
467
468//******************************************************************************
469//******************************************************************************
470BOOL WIN32API EnableWindow(HWND hwnd, BOOL fEnable)
471{
472 Win32BaseWindow *window;
473 BOOL fEnabled;
474
475 window = Win32BaseWindow::GetWindowFromHandle(hwnd);
476 if(!window) {
477 dprintf(("EnableWindow, window %x not found", hwnd));
478 SetLastError(ERROR_INVALID_WINDOW_HANDLE);
479 return 0;
480 }
481 dprintf(("EnableWindow %x %d", hwnd, fEnable));
482 fEnabled = window->EnableWindow(fEnable);
483 RELEASE_WNDOBJ(window);
484 return fEnabled;
485}
486//******************************************************************************
487//******************************************************************************
488BOOL WIN32API BringWindowToTop(HWND hwnd)
489{
490 dprintf(("BringWindowToTop %x", hwnd));
491 return SetWindowPos( hwnd, HWND_TOP, 0, 0, 0, 0, SWP_NOMOVE|SWP_NOSIZE );
492}
493/***********************************************************************
494 * SetInternalWindowPos (USER32.483)
495 */
496VOID WIN32API SetInternalWindowPos(HWND hwnd, UINT showCmd, LPRECT lpRect,
497 LPPOINT lpPoint )
498{
499 if( IsWindow(hwnd) )
500 {
501 WINDOWPLACEMENT wndpl;
502 UINT flags;
503
504 GetWindowPlacement(hwnd, &wndpl);
505 wndpl.length = sizeof(wndpl);
506 wndpl.showCmd = showCmd;
507 wndpl.flags = 0;
508
509 if(lpPoint)
510 {
511 wndpl.flags |= WPF_SETMINPOSITION;
512 wndpl.ptMinPosition = *lpPoint;
513 }
514 if(lpRect)
515 {
516 wndpl.rcNormalPosition = *lpRect;
517 }
518 SetWindowPlacement(hwnd, &wndpl);
519 }
520
521}
522/***********************************************************************
523 * GetInternalWindowPos (USER32.245)
524 */
525UINT WIN32API GetInternalWindowPos(HWND hwnd, LPRECT rectWnd, LPPOINT ptIcon )
526{
527 WINDOWPLACEMENT wndpl;
528
529 if(GetWindowPlacement( hwnd, &wndpl ))
530 {
531 if (rectWnd) *rectWnd = wndpl.rcNormalPosition;
532 if (ptIcon) *ptIcon = wndpl.ptMinPosition;
533 return wndpl.showCmd;
534 }
535 return 0;
536}
537//******************************************************************************
538//******************************************************************************
539HWND GetActiveWindow()
540{
541 return Win32BaseWindow::GetActiveWindow();
542}
543//******************************************************************************
544//******************************************************************************
545BOOL WIN32API ShowWindow(HWND hwnd, INT nCmdShow)
546{
547 Win32BaseWindow *window;
548 BOOL ret;
549
550 window = Win32BaseWindow::GetWindowFromHandle(hwnd);
551 if(!window) {
552 dprintf(("ShowWindow, window %x not found", hwnd));
553 SetLastError(ERROR_INVALID_WINDOW_HANDLE);
554 return 0;
555 }
556
557 //PF Start PM restoration routine first if we restore from icon
558 //so all internal PM logic will work - this routine will always
559 //lead to ShowWindow(SW_RESTORE)
560
561 if ((nCmdShow == SW_RESTORE) && (window->getStyle() & WS_MINIMIZE) && fOS2Look )
562 {
563 dprintf(("ShowWindow: Initiating OS/2 PM restore"));
564 ret = OSLibWinRestoreWindow(window->getOS2FrameWindowHandle());
565 }
566 else
567 ret = window->ShowWindow(nCmdShow);
568 RELEASE_WNDOBJ(window);
569 return ret;
570}
571/*****************************************************************************
572 * Name : BOOL WIN32API ShowWindowAsync
573 * Purpose : The ShowWindowAsync function sets the show state of a window
574 * created by a different thread.
575 * Parameters: HWND hwnd handle of window
576 * int nCmdShow show state of window
577 * Variables :
578 * Result : If the window was previously visible, the return value is TRUE.
579 * If the window was previously hidden, the return value is FALSE.
580 * Remark :
581 * Status : UNTESTED STUB
582 *
583 * Author : Patrick Haller [Thu, 1998/02/26 11:55]
584 *****************************************************************************/
585BOOL WIN32API ShowWindowAsync(HWND hwnd, int nCmdShow)
586{
587 dprintf(("USER32:ShowWindowAsync (%08xh,%08x) not correctly implemented.\n",
588 hwnd, nCmdShow));
589
590 return ShowWindow(hwnd, nCmdShow);
591}
592//******************************************************************************
593//******************************************************************************
594BOOL WIN32API SetWindowPos(HWND hwnd, HWND hwndInsertAfter, INT x,
595 INT y, INT cx, INT cy, UINT fuFlags)
596{
597 Win32BaseWindow *window;
598
599 if (!hwnd)
600 {
601 dprintf(("SetWindowPos: Can't move desktop!"));
602 return TRUE;
603 }
604 window = Win32BaseWindow::GetWindowFromHandle(hwnd);
605 if(!window) {
606 dprintf(("SetWindowPos, window %x not found", hwnd));
607 SetLastError(ERROR_INVALID_WINDOW_HANDLE);
608 return FALSE;
609 }
610 dprintf(("SetWindowPos %x %x x=%d y=%d cx=%d cy=%d %x", hwnd, hwndInsertAfter, x, y, cx, cy, fuFlags));
611 BOOL ret = window->SetWindowPos(hwndInsertAfter, x, y, cx, cy, fuFlags);
612 RELEASE_WNDOBJ(window);
613 return ret;
614}
615//******************************************************************************
616//NOTE: length must equal structure size or else api fails (verified in NT4, SP6)
617//******************************************************************************
618BOOL WIN32API SetWindowPlacement(HWND hwnd, const WINDOWPLACEMENT *winpos)
619{
620 Win32BaseWindow *window;
621
622 if(!winpos || winpos->length != sizeof(WINDOWPLACEMENT)) {
623 dprintf(("SetWindowPlacement %x invalid parameter", hwnd));
624 SetLastError(ERROR_INVALID_PARAMETER);
625 return FALSE;
626 }
627 window = Win32BaseWindow::GetWindowFromHandle(hwnd);
628 if(!window) {
629 dprintf(("SetWindowPlacement, window %x not found", hwnd));
630 SetLastError(ERROR_INVALID_WINDOW_HANDLE);
631 return FALSE;
632 }
633 dprintf(("USER32: SetWindowPlacement %x %x", hwnd, winpos));
634 BOOL ret = window->SetWindowPlacement((WINDOWPLACEMENT *)winpos);
635 RELEASE_WNDOBJ(window);
636 return ret;
637}
638//******************************************************************************
639//NOTE: Length does not need to be correct (even though the SDK docs claim otherwise)
640// (Verified in NT4, SP6)
641//******************************************************************************
642BOOL WIN32API GetWindowPlacement(HWND hwnd, LPWINDOWPLACEMENT winpos)
643{
644 Win32BaseWindow *window;
645
646 if(!winpos) {
647 dprintf(("GetWindowPlacement %x invalid parameter", hwnd));
648 SetLastError(ERROR_INVALID_PARAMETER);
649 return FALSE;
650 }
651 window = Win32BaseWindow::GetWindowFromHandle(hwnd);
652 if(!window) {
653 dprintf(("GetWindowPlacement, window %x not found", hwnd));
654 SetLastError(ERROR_INVALID_WINDOW_HANDLE);
655 return FALSE;
656 }
657 dprintf(("USER32: GetWindowPlacement %x %x", hwnd, winpos));
658 BOOL ret = window->GetWindowPlacement(winpos);
659 RELEASE_WNDOBJ(window);
660 return ret;
661}
662//******************************************************************************
663//******************************************************************************
664BOOL WIN32API IsWindow(HWND hwnd)
665{
666 Win32BaseWindow *window;
667
668 window = Win32BaseWindow::GetWindowFromHandle(hwnd);
669 if(!window) {
670 dprintf(("IsWindow, window %x not found", hwnd));
671 SetLastError(ERROR_INVALID_WINDOW_HANDLE);
672 return FALSE;
673 }
674 dprintf2(("IsWindow %x", hwnd));
675 BOOL fIsWindow = window->IsWindow();
676 RELEASE_WNDOBJ(window);
677 return fIsWindow;
678}
679//******************************************************************************
680//******************************************************************************
681BOOL WIN32API IsWindowEnabled(HWND hwnd)
682{
683 DWORD dwStyle;
684
685 if(!IsWindow(hwnd)) {
686 dprintf(("IsWindowEnabled, window %x not found", hwnd));
687 SetLastError(ERROR_INVALID_WINDOW_HANDLE);
688 return 0;
689 }
690 dprintf(("IsWindowEnabled %x", hwnd));
691 dwStyle = GetWindowLongA(hwnd, GWL_STYLE);
692 if(dwStyle & WS_DISABLED) {
693 return FALSE;
694 }
695 return TRUE;
696}
697//******************************************************************************
698//******************************************************************************
699BOOL WIN32API IsWindowVisible(HWND hwnd)
700{
701 BOOL ret;
702 HWND hwndParent;
703 DWORD dwStyle;
704
705 if(hwnd == HWND_DESKTOP) {//TODO: verify in NT!
706 dprintf(("IsWindowVisible DESKTOP returned TRUE"));
707 return TRUE; //desktop is always visible
708 }
709 if(!IsWindow(hwnd)) {
710 dprintf(("IsWindowVisible, window %x not found", hwnd));
711 SetLastError(ERROR_INVALID_WINDOW_HANDLE);
712 return 0;
713 }
714 //check visibility of this window
715 dwStyle = GetWindowLongA(hwnd, GWL_STYLE);
716 if(!(dwStyle & WS_VISIBLE)) {
717 ret = FALSE;
718 goto end;
719 }
720 ret = TRUE;
721
722 if(dwStyle & WS_CHILD)
723 {
724 //check visibility of parents
725 hwndParent = GetParent(hwnd);
726 while(hwndParent) {
727 dwStyle = GetWindowLongA(hwndParent, GWL_STYLE);
728 if(!(dwStyle & WS_VISIBLE)) {
729 dprintf(("IsWindowVisible %x returned FALSE (parent %x invisible)", hwnd, hwndParent));
730 return FALSE;
731 }
732 if(!(dwStyle & WS_CHILD)) {
733 break; //GetParent can also return the owner
734 }
735 hwndParent = GetParent(hwndParent);
736 }
737 }
738end:
739 dprintf(("IsWindowVisible %x returned %d", hwnd, ret));
740 return ret;
741}
742//******************************************************************************
743//******************************************************************************
744HWND WINAPI GetAncestor( HWND hwnd, UINT type )
745{
746 HWND hwndAncestor = 0;
747 Win32BaseWindow *window;
748
749 window = Win32BaseWindow::GetWindowFromHandle(hwnd);
750 if(!window) {
751 dprintf(("GetAncestor, window %x not found", hwnd));
752 SetLastError(ERROR_INVALID_WINDOW_HANDLE);
753 return FALSE;
754 }
755
756 if (type == GA_PARENT)
757 {
758 LONG dwStyle = GetWindowLongW( hwnd, GWL_STYLE );
759 if(dwStyle & WS_CHILD) {
760 hwndAncestor = GetParent(hwnd);
761 }
762 //else no child -> no parent (GetParent returns owner otherwise!)
763 }
764 else
765 if (type == GA_ROOT)
766 {
767 hwndAncestor = window->GetTopParent();
768 }
769 else
770 if (type == GA_ROOTOWNER)
771 {
772 if(hwnd != GetDesktopWindow())
773 {
774 hwndAncestor = hwnd;
775 for(;;)
776 {
777 HWND parent = GetParent( hwndAncestor );
778 if (!parent) break;
779 hwndAncestor = parent;
780 }
781 }
782 }
783 else dprintf(("Unsupported type %d", type));
784
785 RELEASE_WNDOBJ(window);
786 return hwndAncestor;
787}
788//******************************************************************************
789BOOL fIgnoreKeystrokes = FALSE;
790//******************************************************************************
791void SetFocusChanged()
792{
793 //Focus has changed; invalidate SetFocus(0) state
794 fIgnoreKeystrokes = FALSE;
795}
796//******************************************************************************
797//******************************************************************************
798HWND WIN32API SetFocus(HWND hwnd)
799{
800 Win32BaseWindow *window;
801 Win32BaseWindow *oldfocuswnd;
802 HWND lastFocus, lastFocus_W, hwnd_O, hwndTopParent, hwndTop;
803 BOOL activate, ret;
804 TEB *teb;
805
806 dprintf(("SetFocus %x", hwnd));
807 teb = GetThreadTEB();
808 if(teb == NULL) {
809 DebugInt3();
810 return 0;
811 }
812 //Special case; SetFocus(0) tells Windows to ignore keystrokes. Pressing
813 //a key now generates WM_SYSKEYDOWN/(WM_SYSCHAR)/WM_SYSKEYUP instead
814 //of WM_KEYDOWN/(WM_CHAR)/WM_KEYUP
815 //WM_KILLFOCUS is sent to the window that currently has focus
816 if(hwnd == 0) {
817 lastFocus_W = GetFocus();
818 if(lastFocus_W == 0) return 0; //nothing to do
819
820 if(HOOK_CallHooksA(WH_CBT, HCBT_SETFOCUS, 0, (LPARAM)lastFocus_W)) {
821 dprintf(("hook cancelled SetFocus call!"));
822 return 0;
823 }
824 fIgnoreKeystrokes = TRUE;
825 SendMessageA(lastFocus_W, WM_KILLFOCUS, 0, 0);
826
827 return lastFocus_W;
828 }
829
830 //SetFocus is not allowed for minimized or disabled windows (this window
831 //or any parent)
832 hwndTop = hwnd;
833 for (;;)
834 {
835 HWND parent;
836
837 LONG style = GetWindowLongW( hwndTop, GWL_STYLE );
838 if (style & (WS_MINIMIZE | WS_DISABLED)) {
839 dprintf(("SetFocus, %x not allowed on minimized or disabled window (%x)", hwnd, style));
840 return 0;
841 }
842 parent = GetAncestor(hwndTop, GA_PARENT);
843 if (!parent || parent == GetDesktopWindow()) break;
844 hwndTop = parent;
845 }
846
847 window = Win32BaseWindow::GetWindowFromHandle(hwnd);
848 if(!window) {
849 dprintf(("SetFocus, window %x not found", hwnd));
850 //Note: last error not set (NT4, SP6), returns current focus window
851 //SetLastError(ERROR_INVALID_WINDOW_HANDLE);
852 return GetFocus();
853 }
854
855 hwnd_O = window->getOS2WindowHandle();
856 lastFocus = OSLibWinQueryFocus (OSLIB_HWND_DESKTOP);
857
858 hwndTopParent = window->GetTopParent();
859 activate = FALSE;
860 lastFocus_W = OS2ToWin32Handle(lastFocus);
861 if(lastFocus_W) {
862 oldfocuswnd = Win32BaseWindow::GetWindowFromHandle(lastFocus_W);
863 if(lastFocus_W != hwnd && hwndTopParent != oldfocuswnd->GetTopParent()) {
864 activate = TRUE;
865 }
866 RELEASE_WNDOBJ(oldfocuswnd);
867 }
868 else activate = TRUE;
869
870 dprintf(("SetFocus %x (%x) -> %x (%x) act %d", lastFocus_W, lastFocus, hwnd, hwnd_O, activate));
871
872 if(HOOK_CallHooksA(WH_CBT, HCBT_SETFOCUS, hwnd, (LPARAM)lastFocus_W)) {
873 dprintf(("hook cancelled SetFocus call!"));
874 RELEASE_WNDOBJ(window);
875 return 0;
876 }
877
878 if(!IsWindow(hwnd)) return FALSE; //abort if window destroyed
879
880 //NOTE: Don't always activate the window or else the z-order will be changed!!
881 ret = (OSLibWinSetFocus(OSLIB_HWND_DESKTOP, hwnd_O, activate)) ? lastFocus_W : 0;
882 RELEASE_WNDOBJ(window);
883
884 //If keystrokes were ignored and focus is set to the old focus window, then
885 //PM won't send us a WM_SETFOCUS message. (as we don't inform PM for SetFocus(0))
886 if(fIgnoreKeystrokes && lastFocus_W == hwnd) {
887 dprintf(("Manually send WM_SETFOCUS; real focus window hasn't changed"));
888 SendMessageA(lastFocus_W, WM_SETFOCUS, 0, 0);
889 }
890 fIgnoreKeystrokes = FALSE;
891 return ret;
892}
893//******************************************************************************
894//******************************************************************************
895HWND WIN32API GetFocus()
896{
897 TEB *teb;
898 HWND hwnd;
899
900 teb = GetThreadTEB();
901 if(teb == NULL) {
902 DebugInt3();
903 return 0;
904 }
905 //If keystrokes are ignored (SetFocus(0)), then return 0
906 if(fIgnoreKeystrokes) {
907 dprintf(("GetFocus; returning 0 after SetFocus(0) call"));
908 return 0;
909 }
910 hwnd = OSLibWinQueryFocus(OSLIB_HWND_DESKTOP);
911 hwnd = OS2ToWin32Handle(hwnd);
912 dprintf(("USER32: GetFocus %x\n", hwnd));
913 return hwnd;
914}
915//******************************************************************************
916//******************************************************************************
917BOOL WIN32API GetGUIThreadInfo(DWORD dwThreadId, GUITHREADINFO *lpThreadInfo)
918{
919 dprintf(("!WARNING!: GetGUIThreadInfo not completely implemented!!"));
920
921 if(!lpThreadInfo || lpThreadInfo->cbSize != sizeof(GUITHREADINFO)) {
922 SetLastError(ERROR_INVALID_PARAMETER);
923 return FALSE;
924 }
925 //dwThreadId == 0 -> current thread
926 if(!dwThreadId) dwThreadId = GetCurrentThreadId();
927
928 lpThreadInfo->flags;
929 lpThreadInfo->hwndActive = GetActiveWindow();
930 if(lpThreadInfo->hwndActive) {
931 if(dwThreadId != GetWindowThreadProcessId(lpThreadInfo->hwndActive, NULL))
932 {//this thread doesn't own the active window (TODO: correct??)
933 lpThreadInfo->hwndActive = 0;
934 }
935 }
936 lpThreadInfo->hwndFocus = GetFocus();
937 lpThreadInfo->hwndCapture = GetCapture();
938 lpThreadInfo->flags = 0; //TODO:
939 lpThreadInfo->hwndMenuOwner = 0; //TODO: Handle to the window that owns any active menus
940 lpThreadInfo->hwndMoveSize = 0; //TODO: Handle to the window in a move or size loop.
941 lpThreadInfo->hwndCaret = 0; //TODO: Handle to the window that is displaying the caret
942 lpThreadInfo->rcCaret.left = 0;
943 lpThreadInfo->rcCaret.top = 0;
944 lpThreadInfo->rcCaret.right = 0;
945 lpThreadInfo->rcCaret.bottom = 0;
946
947 SetLastError(ERROR_SUCCESS);
948 return TRUE;
949}
950//******************************************************************************
951//******************************************************************************
952BOOL WIN32API IsZoomed(HWND hwnd)
953{
954 DWORD style;
955
956 style = GetWindowLongA(hwnd, GWL_STYLE);
957 dprintf(("USER32: IsZoomed %x returned %d", hwnd, ((style & WS_MAXIMIZE) != 0)));
958
959 return (style & WS_MAXIMIZE) != 0;
960}
961//******************************************************************************
962//******************************************************************************
963BOOL WIN32API LockWindowUpdate(HWND hwnd)
964{
965 return OSLibWinLockWindowUpdate(Win32ToOS2Handle(hwnd));
966}
967//******************************************************************************
968//******************************************************************************
969BOOL WIN32API GetWindowRect(HWND hwnd, PRECT pRect)
970{
971 Win32BaseWindow *window;
972
973 if(pRect == NULL) {
974 dprintf(("GetWindowRect %x invalid parameter!", hwnd));
975 SetLastError(ERROR_INVALID_PARAMETER);
976 return FALSE;
977 }
978
979 if(hwnd == HWND_DESKTOP) {
980 windowDesktop->addRef();
981 window = windowDesktop;
982 }
983 else window = Win32BaseWindow::GetWindowFromHandle(hwnd);
984
985 if(!window) {
986 dprintf(("GetWindowRect, window %x not found", hwnd));
987 SetLastError(ERROR_INVALID_WINDOW_HANDLE);
988 return FALSE;
989 }
990 *pRect = *window->getWindowRect();
991
992 //convert from parent coordinates to screen (if necessary)
993 if(window->getParent()) {
994 MapWindowPoints(window->getParent()->getWindowHandle(), 0, (PPOINT)pRect, 2);
995 }
996 RELEASE_WNDOBJ(window);
997 dprintf(("GetWindowRect %x (%d,%d) (%d,%d)", hwnd, pRect->left, pRect->top, pRect->right, pRect->bottom));
998 return TRUE;
999}
1000//******************************************************************************
1001//******************************************************************************
1002INT WIN32API GetWindowTextLengthA(HWND hwnd)
1003{
1004 Win32BaseWindow *window;
1005
1006 window = Win32BaseWindow::GetWindowFromHandle(hwnd);
1007 if(!window) {
1008 dprintf(("GetWindowTextLengthA, window %x not found", hwnd));
1009 SetLastError(ERROR_INVALID_WINDOW_HANDLE);
1010 return 0;
1011 }
1012 dprintf(("GetWindowTextLengthA %x", hwnd));
1013 int ret = window->GetWindowTextLengthA();
1014 RELEASE_WNDOBJ(window);
1015 return ret;
1016}
1017//******************************************************************************
1018//******************************************************************************
1019int WIN32API GetWindowTextA( HWND hwnd, LPSTR lpsz, int cch)
1020{
1021 Win32BaseWindow *window;
1022 int rc;
1023
1024 window = Win32BaseWindow::GetWindowFromHandle(hwnd);
1025 if(!window) {
1026 dprintf(("GetWindowTextA, window %x not found", hwnd));
1027 SetLastError(ERROR_INVALID_WINDOW_HANDLE);
1028 return 0;
1029 }
1030 rc = window->GetWindowTextA(lpsz, cch);
1031 dprintf(("GetWindowTextA %x %s", hwnd, lpsz));
1032 RELEASE_WNDOBJ(window);
1033 return rc;
1034}
1035//******************************************************************************
1036//******************************************************************************
1037int WIN32API GetWindowTextLengthW( HWND hwnd)
1038{
1039 Win32BaseWindow *window;
1040
1041 window = Win32BaseWindow::GetWindowFromHandle(hwnd);
1042 if(!window) {
1043 dprintf(("GetWindowTextLengthW, window %x not found", hwnd));
1044 SetLastError(ERROR_INVALID_WINDOW_HANDLE);
1045 return 0;
1046 }
1047 dprintf(("GetWindowTextLengthW %x", hwnd));
1048 int ret = window->GetWindowTextLengthW();
1049 RELEASE_WNDOBJ(window);
1050 return ret;
1051}
1052//******************************************************************************
1053//******************************************************************************
1054int WIN32API GetWindowTextW(HWND hwnd, LPWSTR lpsz, int cch)
1055{
1056 Win32BaseWindow *window;
1057
1058 window = Win32BaseWindow::GetWindowFromHandle(hwnd);
1059 if(!window) {
1060 dprintf(("GetWindowTextW, window %x not found", hwnd));
1061 SetLastError(ERROR_INVALID_WINDOW_HANDLE);
1062 return 0;
1063 }
1064 int rc = window->GetWindowTextW(lpsz, cch);
1065 RELEASE_WNDOBJ(window);
1066 dprintf(("GetWindowTextW %x %ls", hwnd, lpsz));
1067 return rc;
1068}
1069//******************************************************************************
1070//******************************************************************************
1071BOOL WIN32API SetWindowTextA(HWND hwnd, LPCSTR lpsz)
1072{
1073 Win32BaseWindow *window;
1074
1075 window = Win32BaseWindow::GetWindowFromHandle(hwnd);
1076 if(!window) {
1077 dprintf(("SetWindowTextA, window %x not found", hwnd));
1078 SetLastError(ERROR_INVALID_WINDOW_HANDLE);
1079 return 0;
1080 }
1081 dprintf(("SetWindowTextA %x %s", hwnd, lpsz));
1082 BOOL ret = window->SetWindowTextA((LPSTR)lpsz);
1083 RELEASE_WNDOBJ(window);
1084 return ret;
1085}
1086//******************************************************************************
1087//******************************************************************************
1088BOOL WIN32API SetWindowTextW( HWND hwnd, LPCWSTR lpsz)
1089{
1090 Win32BaseWindow *window;
1091
1092 window = Win32BaseWindow::GetWindowFromHandle(hwnd);
1093 if(!window) {
1094 dprintf(("SetWindowTextA, window %x not found", hwnd));
1095 SetLastError(ERROR_INVALID_WINDOW_HANDLE);
1096 return 0;
1097 }
1098 dprintf(("SetWindowTextW %x %ls", hwnd, lpsz));
1099 BOOL ret = window->SetWindowTextW((LPWSTR)lpsz);
1100 RELEASE_WNDOBJ(window);
1101 return ret;
1102}
1103/*******************************************************************
1104 * InternalGetWindowText (USER32.326)
1105 */
1106int WIN32API InternalGetWindowText(HWND hwnd,
1107 LPWSTR lpString,
1108 INT nMaxCount )
1109{
1110 dprintf(("USER32: InternalGetWindowText(%08xh,%08xh,%08xh) not properly implemented.\n",
1111 hwnd, lpString, nMaxCount));
1112
1113 return GetWindowTextW(hwnd, lpString,nMaxCount);
1114}
1115//******************************************************************************
1116//TODO: Correct?
1117//******************************************************************************
1118BOOL WIN32API SetForegroundWindow(HWND hwnd)
1119{
1120 dprintf((" SetForegroundWindow %x", hwnd));
1121
1122 return SetWindowPos( hwnd, HWND_TOP, 0, 0, 0, 0, SWP_NOMOVE | SWP_NOSIZE);
1123}
1124//******************************************************************************
1125//******************************************************************************
1126BOOL WIN32API GetClientRect( HWND hwnd, PRECT pRect)
1127{
1128 HWND hwndWin32 = hwnd;
1129 Win32BaseWindow *window;
1130
1131 if (!pRect)
1132 {
1133 SetLastError(ERROR_INVALID_PARAMETER);
1134 return FALSE;
1135 }
1136 window = Win32BaseWindow::GetWindowFromHandle(hwnd);
1137 if(!window) {
1138 dprintf(("GetClientRect, window %x not found", hwnd));
1139 SetLastError(ERROR_INVALID_WINDOW_HANDLE);
1140 return FALSE;
1141 }
1142 window->getClientRect(pRect);
1143 dprintf(("GetClientRect of %X returned (%d,%d) (%d,%d)\n", hwndWin32, pRect->left, pRect->top, pRect->right, pRect->bottom));
1144 RELEASE_WNDOBJ(window);
1145 return TRUE;
1146}
1147//******************************************************************************
1148//******************************************************************************
1149BOOL WIN32API AdjustWindowRect(PRECT rect, DWORD style, BOOL menu)
1150{
1151 return AdjustWindowRectEx(rect, style, menu, 0);
1152}
1153//******************************************************************************
1154//Calculate window rectangle based on given client rectangle, style, menu and extended style
1155//******************************************************************************
1156BOOL WIN32API AdjustWindowRectEx( PRECT rect, DWORD style, BOOL menu, DWORD exStyle)
1157{
1158 if(style == 0 && menu == FALSE && exStyle == 0) {
1159 dprintf(("AdjustWindowRectEx %x %x %d (%d,%d)(%d,%d) -> no change required", style, exStyle, menu, rect->left, rect->top, rect->right, rect->bottom));
1160 return TRUE; //nothing needs to be changed (VERIFIED in NT 4)
1161 }
1162 dprintf(("AdjustWindowRectEx %x %x %d (%d,%d)(%d,%d)\n", style, exStyle, menu, rect->left, rect->top, rect->right, rect->bottom));
1163 /* Correct the window style */
1164 if (!(style & (WS_POPUP | WS_CHILD))) /* Overlapped window */
1165 style |= WS_CAPTION;
1166
1167 //SvL: Include WS_POPUP -> otherwise HAS_THINFRAME is true for popup windows
1168 // Also include WS_CHILD -> otherwise HAS_THICKFRAME doesn't work correctly
1169 style &= (WS_DLGFRAME | WS_BORDER | WS_THICKFRAME | WS_CHILD | WS_VSCROLL | WS_HSCROLL | WS_POPUP);
1170 exStyle &= (WS_EX_DLGMODALFRAME | WS_EX_CLIENTEDGE | WS_EX_STATICEDGE | WS_EX_TOOLWINDOW);
1171 if (exStyle & WS_EX_DLGMODALFRAME) style &= ~WS_THICKFRAME;
1172
1173 //Adjust rect outer (Win32BaseWindow::AdjustRectOuter)
1174 if (HAS_THICKFRAME(style,exStyle))
1175 InflateRect( rect, GetSystemMetrics(SM_CXFRAME), GetSystemMetrics(SM_CYFRAME) );
1176 else
1177 if (HAS_DLGFRAME(style,exStyle))
1178 InflateRect(rect, GetSystemMetrics(SM_CXDLGFRAME), GetSystemMetrics(SM_CYDLGFRAME) );
1179 else
1180 if (HAS_THINFRAME(style))
1181 InflateRect( rect, GetSystemMetrics(SM_CXBORDER), GetSystemMetrics(SM_CYBORDER));
1182
1183 if ((style & WS_CAPTION) == WS_CAPTION)
1184 {
1185 if (exStyle & WS_EX_TOOLWINDOW)
1186 rect->top -= GetSystemMetrics(SM_CYSMCAPTION);
1187 else
1188 rect->top -= GetSystemMetrics(SM_CYCAPTION);
1189 }
1190
1191 if (menu)
1192 rect->top -= GetSystemMetrics(SM_CYMENU);
1193
1194 //Adjust rect inner (Win32BaseWindow::AdjustRectInner)
1195 if(!(style & WS_ICONIC)) {
1196 if (exStyle & WS_EX_CLIENTEDGE)
1197 InflateRect (rect, GetSystemMetrics(SM_CXEDGE), GetSystemMetrics(SM_CYEDGE));
1198
1199 if (exStyle & WS_EX_STATICEDGE)
1200 InflateRect (rect, GetSystemMetrics(SM_CXBORDER), GetSystemMetrics(SM_CYBORDER));
1201
1202 //SvL: scrollbars aren't checked *UNLESS* the style includes a border (any border)
1203 // --> VERIFIED IN NT4, SP6 (fixes MFC apps with scrollbars + bar controls)
1204 if(style & (WS_THICKFRAME|WS_BORDER|WS_DLGFRAME)) {
1205 if (style & WS_VSCROLL) rect->right += GetSystemMetrics(SM_CXVSCROLL);
1206 if (style & WS_HSCROLL) rect->bottom += GetSystemMetrics(SM_CYHSCROLL);
1207 }
1208 }
1209
1210 dprintf(("AdjustWindowRectEx returned (%d,%d)(%d,%d)\n", rect->left, rect->top, rect->right, rect->bottom));
1211
1212 return TRUE;
1213}
1214//******************************************************************************
1215/* Coordinate Space and Transformation Functions */
1216//******************************************************************************
1217/*******************************************************************
1218 * WINPOS_GetWinOffset
1219 *
1220 * Calculate the offset between the origin of the two windows. Used
1221 * to implement MapWindowPoints.
1222 */
1223static void WINPOS_GetWinOffset( Win32BaseWindow *wndFrom, Win32BaseWindow *wndTo,
1224 POINT *offset )
1225{
1226 Win32BaseWindow *window;
1227
1228 offset->x = offset->y = 0;
1229
1230 /* Translate source window origin to screen coords */
1231 if(wndFrom != windowDesktop)
1232 {
1233 window = wndFrom;
1234 while(window)
1235 {
1236 offset->x += window->getClientRectPtr()->left + window->getWindowRect()->left;
1237 offset->y += window->getClientRectPtr()->top + window->getWindowRect()->top;
1238 window = window->getParent();
1239 }
1240 }
1241
1242 /* Translate origin to destination window coords */
1243 if(wndTo != windowDesktop)
1244 {
1245 window = wndTo;
1246 while(window)
1247 {
1248 offset->x -= window->getClientRectPtr()->left + window->getWindowRect()->left;
1249 offset->y -= window->getClientRectPtr()->top + window->getWindowRect()->top;
1250 window = window->getParent();
1251 }
1252 }
1253}
1254//******************************************************************************
1255//******************************************************************************
1256int WIN32API MapWindowPoints(HWND hwndFrom, HWND hwndTo, LPPOINT lpPoints,
1257 UINT cPoints)
1258{
1259 Win32BaseWindow *wndfrom, *wndto;
1260 int retval = 0;
1261 POINT offset;
1262
1263 SetLastError(0);
1264 if(lpPoints == NULL || cPoints == 0) {
1265 dprintf(("MapWindowPoints error: lpPoints %p, cPoints %d", lpPoints, cPoints));
1266 SetLastError(ERROR_INVALID_PARAMETER);
1267 return 0;
1268 }
1269 if(hwndTo == hwndFrom)
1270 return 0; //nothing to do
1271
1272 if(hwndFrom == HWND_DESKTOP)
1273 {
1274 windowDesktop->addRef();
1275 wndfrom = windowDesktop;
1276 }
1277 else {
1278 wndfrom = Win32BaseWindow::GetWindowFromHandle(hwndFrom);
1279 if(!wndfrom) {
1280 dprintf(("MapWindowPoints, window %x not found", hwndFrom));
1281 SetLastError(ERROR_INVALID_WINDOW_HANDLE);
1282 return 0;
1283 }
1284 }
1285
1286 if(hwndTo == HWND_DESKTOP)
1287 {
1288 windowDesktop->addRef();
1289 wndto = windowDesktop;
1290 }
1291 else {
1292 wndto = Win32BaseWindow::GetWindowFromHandle(hwndTo);
1293 if(!wndto) {
1294 dprintf(("MapWindowPoints, window %x not found", hwndTo));
1295 SetLastError(ERROR_INVALID_WINDOW_HANDLE);
1296 return 0;
1297 }
1298 }
1299
1300 dprintf2(("USER32: MapWindowPoints %x to %x (%d,%d) (%d)", hwndFrom, hwndTo, lpPoints->x, lpPoints->y, cPoints));
1301 WINPOS_GetWinOffset(wndfrom, wndto, &offset);
1302
1303 RELEASE_WNDOBJ(wndto);
1304 RELEASE_WNDOBJ(wndfrom);
1305 for(int i=0;i<cPoints;i++)
1306 {
1307 lpPoints[i].x += offset.x;
1308 lpPoints[i].y += offset.y;
1309 }
1310 retval = ((LONG)offset.y << 16) | offset.x;
1311 return retval;
1312}
1313//******************************************************************************
1314//******************************************************************************
1315BOOL WIN32API ScreenToClient(HWND hwnd, LPPOINT pt)
1316{
1317 PRECT rcl;
1318 BOOL rc;
1319
1320 if(hwnd == HWND_DESKTOP) {
1321 return (TRUE); //nothing to do
1322 }
1323 if (!IsWindow(hwnd)) {
1324 dprintf(("warning: ScreenToClient: window %x not found!", hwnd));
1325 SetLastError(ERROR_INVALID_WINDOW_HANDLE);
1326 return FALSE;
1327 }
1328 SetLastError(0);
1329#ifdef DEBUG
1330 POINT tmp = *pt;
1331#endif
1332 MapWindowPoints(0, hwnd, pt, 1);
1333 dprintf2(("ScreenToClient %x (%d,%d) -> (%d,%d)", hwnd, tmp.x, tmp.y, pt->x, pt->y));
1334 return TRUE;
1335}
1336//******************************************************************************
1337//******************************************************************************
1338HWND WIN32API GetDesktopWindow(void)
1339{
1340 HWND hDesktopWindow = windowDesktop->getWindowHandle();
1341 dprintf2(("USER32: GetDesktopWindow, returned %x\n", hDesktopWindow));
1342 return hDesktopWindow;
1343}
1344//******************************************************************************
1345//******************************************************************************
1346HWND WIN32API FindWindowA(LPCSTR lpszClass, LPCSTR lpszWindow)
1347{
1348 return FindWindowExA( NULL, NULL, lpszClass, lpszWindow );
1349}
1350//******************************************************************************
1351//******************************************************************************
1352HWND WIN32API FindWindowW( LPCWSTR lpClassName, LPCWSTR lpWindowName)
1353{
1354 return FindWindowExW( NULL, NULL, lpClassName, lpWindowName );
1355}
1356//******************************************************************************
1357//******************************************************************************
1358HWND WIN32API FindWindowExA(HWND hwndParent, HWND hwndChildAfter, LPCSTR lpszClass, LPCSTR lpszWindow)
1359{
1360 ATOM atom = 0;
1361
1362 if (lpszClass)
1363 {
1364 /* If the atom doesn't exist, then no class */
1365 /* with this name exists either. */
1366 if (!(atom = GlobalFindAtomA( lpszClass )))
1367 {
1368 SetLastError(ERROR_CANNOT_FIND_WND_CLASS);
1369 return 0;
1370 }
1371 }
1372 return Win32BaseWindow::FindWindowEx(hwndParent, hwndChildAfter, atom, (LPSTR)lpszWindow);
1373}
1374/*****************************************************************************
1375 * Name : HWND WIN32API FindWindowExW
1376 * Purpose : The FindWindowEx function retrieves the handle of a window whose
1377 * class name and window name match the specified strings. The
1378 * function searches child windows, beginning with the one following
1379 * the given child window.
1380 * Parameters: HWND hwndParent handle of parent window
1381 * HWND hwndChildAfter handle of a child window
1382 * LPCTSTR lpszClass address of class name
1383 * LPCTSTR lpszWindow address of window name
1384 * Variables :
1385 * Result : If the function succeeds, the return value is the handle of the
1386 * window that has the specified class and window names.
1387 * If the function fails, the return value is NULL. To get extended
1388 * error information, call GetLastError.
1389 * Remark :
1390 *
1391 *****************************************************************************/
1392
1393HWND WIN32API FindWindowExW(HWND hwndParent,
1394 HWND hwndChildAfter,
1395 LPCWSTR lpszClass,
1396 LPCWSTR lpszWindow)
1397{
1398 ATOM atom = 0;
1399 char *buffer;
1400 HWND hwnd;
1401
1402 if (lpszClass)
1403 {
1404 /* If the atom doesn't exist, then no class */
1405 /* with this name exists either. */
1406 if (!(atom = GlobalFindAtomW( lpszClass )))
1407 {
1408 SetLastError(ERROR_CANNOT_FIND_WND_CLASS);
1409 return 0;
1410 }
1411 }
1412 buffer = HEAP_strdupWtoA( GetProcessHeap(), 0, lpszWindow );
1413 hwnd = Win32BaseWindow::FindWindowEx(hwndParent, hwndChildAfter, atom, buffer);
1414 HeapFree( GetProcessHeap(), 0, buffer );
1415 return hwnd;
1416}
1417//******************************************************************************
1418//******************************************************************************
1419BOOL WIN32API FlashWindow(HWND hwnd, BOOL fFlash)
1420{
1421 dprintf(("FlashWindow %x %d\n", hwnd, fFlash));
1422// return OSLibWinFlashWindow(Win32ToOS2Handle(hwnd), fFlash);
1423 return 1;
1424}
1425//******************************************************************************
1426//******************************************************************************
1427BOOL WIN32API FlashWindowEx( PFLASHWINFO pfwi)
1428{
1429 dprintf(("FlashWindow %p %d\n", pfwi));
1430 return 1;
1431}
1432//******************************************************************************
1433//******************************************************************************
1434BOOL WIN32API MoveWindow( HWND hwnd, INT x, INT y, INT cx, INT cy,
1435 BOOL repaint )
1436{
1437 int flags = SWP_NOZORDER | SWP_NOACTIVATE;
1438
1439 if (!repaint) flags |= SWP_NOREDRAW;
1440 dprintf(("MoveWindow: %x %d,%d %dx%d %d\n", hwnd, x, y, cx, cy, repaint ));
1441
1442 return SetWindowPos( hwnd, 0, x, y, cx, cy, flags );
1443}
1444//******************************************************************************
1445//******************************************************************************
1446BOOL WIN32API ClientToScreen (HWND hwnd, PPOINT pt)
1447{
1448 PRECT rcl;
1449
1450 if(hwnd == HWND_DESKTOP) {
1451 return(TRUE); //nothing to do
1452 }
1453 if(!IsWindow(hwnd)) {
1454 dprintf(("warning: ClientToScreen window %x not found!", hwnd));
1455 SetLastError(ERROR_INVALID_WINDOW_HANDLE);
1456 return (FALSE);
1457 }
1458#ifdef DEBUG
1459 POINT tmp = *pt;
1460#endif
1461 MapWindowPoints(hwnd, 0, pt, 1);
1462 dprintf2(("ClientToScreen %x (%d,%d) -> (%d,%d)", hwnd, tmp.x, tmp.y, pt->x, pt->y));
1463
1464 return TRUE;
1465}
1466//******************************************************************************
1467//Note: count 0 is a legal parameter (verified in NT4)
1468//******************************************************************************
1469HDWP WIN32API BeginDeferWindowPos(int count)
1470{
1471 HDWP handle;
1472 DWP *pDWP;
1473
1474 if (count < 0)
1475 {
1476 dprintf(("USER32: BeginDeferWindowPos invalid param %d", count));
1477 SetLastError(ERROR_INVALID_PARAMETER);
1478 return 0;
1479 }
1480 dprintf(("USER32: BeginDeferWindowPos %d", count));
1481 if(count == 0)
1482 count = 8; // change to any non-zero value
1483
1484 handle = (HDWP)HeapAlloc(GetProcessHeap(), 0, sizeof(DWP) + (count-1)*sizeof(WINDOWPOS));
1485 if (!handle)
1486 return 0;
1487
1488 pDWP = (DWP *) handle;
1489 pDWP->actualCount = 0;
1490 pDWP->suggestedCount = count;
1491 pDWP->valid = TRUE;
1492 pDWP->wMagic = DWP_MAGIC;
1493 pDWP->hwndParent = 0;
1494 return handle;
1495}
1496/***********************************************************************
1497 * DeferWindowPos (USER32.128)
1498 *
1499 * TODO: SvL: Does this need to be thread safe?
1500 *
1501 */
1502HDWP WIN32API DeferWindowPos( HDWP hdwp, HWND hwnd, HWND hwndAfter,
1503 INT x, INT y, INT cx, INT cy,
1504 UINT flags )
1505{
1506 DWP *pDWP;
1507 int i;
1508 HDWP newhdwp = hdwp,retvalue;
1509
1510 pDWP = (DWP *)hdwp;
1511 if (!pDWP) {
1512 SetLastError(ERROR_INVALID_PARAMETER);
1513 return 0;
1514 }
1515
1516 if (hwnd == GetDesktopWindow())
1517 return 0;
1518
1519 if(!IsWindow(hwnd)) {
1520 dprintf(("DeferWindowPos, window %x not found", hwnd));
1521 SetLastError(ERROR_INVALID_WINDOW_HANDLE);
1522 HeapFree(GetProcessHeap(), 0, (LPVOID)hdwp);
1523 return 0;
1524 }
1525
1526 dprintf(("USER32: DeferWindowPos hdwp %x hwnd %x hwndAfter %x (%d,%d)(%d,%d) %x", hdwp, hwnd, hwndAfter,
1527 x, y, cx, cy, flags));
1528
1529/* Numega Bounds Checker Demo dislikes the following code.
1530 In fact, I've not been able to find any "same parent" requirement in any docu
1531 [AM 980509]
1532 */
1533#if 0
1534 /* All the windows of a DeferWindowPos() must have the same parent */
1535 parent = pWnd->parent->hwndSelf;
1536 if (pDWP->actualCount == 0) pDWP->hwndParent = parent;
1537 else if (parent != pDWP->hwndParent)
1538 {
1539 USER_HEAP_FREE( hdwp );
1540 retvalue = 0;
1541 goto END;
1542 }
1543#endif
1544
1545 for (i = 0; i < pDWP->actualCount; i++)
1546 {
1547 if (pDWP->winPos[i].hwnd == hwnd)
1548 {
1549 /* Merge with the other changes */
1550 if (!(flags & SWP_NOZORDER))
1551 {
1552 pDWP->winPos[i].hwndInsertAfter = hwndAfter;
1553 }
1554 if (!(flags & SWP_NOMOVE))
1555 {
1556 pDWP->winPos[i].x = x;
1557 pDWP->winPos[i].y = y;
1558 }
1559 if (!(flags & SWP_NOSIZE))
1560 {
1561 pDWP->winPos[i].cx = cx;
1562 pDWP->winPos[i].cy = cy;
1563 }
1564 pDWP->winPos[i].flags &= flags | ~(SWP_NOSIZE | SWP_NOMOVE |
1565 SWP_NOZORDER | SWP_NOREDRAW |
1566 SWP_NOACTIVATE | SWP_NOCOPYBITS|
1567 SWP_NOOWNERZORDER);
1568 pDWP->winPos[i].flags |= flags & (SWP_SHOWWINDOW | SWP_HIDEWINDOW |
1569 SWP_FRAMECHANGED);
1570 retvalue = hdwp;
1571 goto END;
1572 }
1573 }
1574 if (pDWP->actualCount >= pDWP->suggestedCount)
1575 {
1576 //DWP structure already contains WINDOWPOS, allocated with (count-1)
1577 //in BeginDeferWindowPos; pDWP->suggestedCount alloc increases it by one
1578 newhdwp = (HDWP)HeapReAlloc(GetProcessHeap(), 0, (LPVOID)hdwp,
1579 sizeof(DWP) + pDWP->suggestedCount*sizeof(WINDOWPOS));
1580 if (!newhdwp)
1581 {
1582 retvalue = 0;
1583 goto END;
1584 }
1585 pDWP = (DWP *) newhdwp;
1586 pDWP->suggestedCount++;
1587 }
1588 pDWP->winPos[pDWP->actualCount].hwnd = hwnd;
1589 pDWP->winPos[pDWP->actualCount].hwndInsertAfter = hwndAfter;
1590 pDWP->winPos[pDWP->actualCount].x = x;
1591 pDWP->winPos[pDWP->actualCount].y = y;
1592 pDWP->winPos[pDWP->actualCount].cx = cx;
1593 pDWP->winPos[pDWP->actualCount].cy = cy;
1594 pDWP->winPos[pDWP->actualCount].flags = flags;
1595 pDWP->actualCount++;
1596 retvalue = newhdwp;
1597END:
1598 return retvalue;
1599}
1600//******************************************************************************
1601//******************************************************************************
1602BOOL WIN32API EndDeferWindowPos( HDWP hdwp)
1603{
1604 DWP *pDWP;
1605 WINDOWPOS *winpos;
1606 BOOL res = TRUE;
1607 int i;
1608
1609 pDWP = (DWP *) hdwp;
1610 if (!pDWP) {
1611 dprintf(("**EndDeferWindowPos invalid parameter\n"));
1612 SetLastError(ERROR_INVALID_PARAMETER);
1613 return FALSE;
1614 }
1615 dprintf(("**EndDeferWindowPos for %d windows", pDWP->actualCount));
1616 for (i = 0, winpos = pDWP->winPos; i < pDWP->actualCount; i++, winpos++)
1617 {
1618 dprintf(("**EndDeferWindowPos %x (%d,%d) (%d,%d) %x", winpos->hwnd, winpos->x, winpos->y, winpos->cx, winpos->cy, winpos->flags));
1619 if (!(res = SetWindowPos(winpos->hwnd, winpos->hwndInsertAfter,
1620 winpos->x, winpos->y, winpos->cx,
1621 winpos->cy, winpos->flags )))
1622 break;
1623 }
1624 dprintf(("**EndDeferWindowPos DONE"));
1625 HeapFree(GetProcessHeap(), 0, (LPVOID)hdwp);
1626 return res;
1627}
1628//******************************************************************************
1629//******************************************************************************
1630HWND WIN32API ChildWindowFromPoint( HWND hwnd, POINT pt)
1631{
1632 dprintf(("USER32: ChildWindowFromPoint\n"));
1633 return ChildWindowFromPointEx(hwnd, pt, 0);
1634}
1635/*****************************************************************************
1636 * Name : HWND WIN32API ChildWindowFromPointEx
1637 * Purpose : pt: client coordinates
1638 * Parameters:
1639 * Variables :
1640 * Result : If the function succeeds, the return value is the window handle.
1641 * If the function fails, the return value is zero
1642 * Remark :
1643 * Status : COMPLETELY IMPLEMENTED AND TESTED
1644 *
1645 * Author : Rene Pronk [Sun, 1999/08/08 23:30]
1646 *****************************************************************************/
1647HWND WIN32API ChildWindowFromPointEx (HWND hwndParent, POINT pt, UINT uFlags)
1648{
1649 RECT rect;
1650 HWND hWnd;
1651
1652 dprintf(("ChildWindowFromPointEx(%08xh,%08xh,%08xh).\n",
1653 hwndParent, pt, uFlags));
1654
1655 if (GetWindowRect (hwndParent, &rect) == 0) {
1656 // oops, invalid handle
1657 SetLastError(ERROR_INVALID_WINDOW_HANDLE);
1658 return NULL;
1659 }
1660
1661 ClientToScreen(hwndParent, &pt);
1662 if (PtInRect (&rect, pt) == 0) {
1663 // point is outside window
1664 return NULL;
1665 }
1666
1667 // get first child
1668 hWnd = GetWindow (hwndParent, GW_CHILD);
1669
1670 while (hWnd != NULL)
1671 {
1672 // do I need to skip this window?
1673 if (((uFlags & CWP_SKIPINVISIBLE) &&
1674 (IsWindowVisible (hWnd) == FALSE)) ||
1675 ((uFlags & CWP_SKIPDISABLED) &&
1676 (IsWindowEnabled (hWnd) == FALSE)) ||
1677 ((uFlags & CWP_SKIPTRANSPARENT) &&
1678 (GetWindowLongA (hWnd, GWL_EXSTYLE) & WS_EX_TRANSPARENT)))
1679 {
1680 hWnd = GetWindow (hWnd, GW_HWNDNEXT);
1681 continue;
1682 }
1683
1684 // is the point in this window's rect?
1685 GetWindowRect (hWnd, &rect);
1686 if (PtInRect (&rect,pt) == FALSE) {
1687 hWnd = GetWindow (hWnd, GW_HWNDNEXT);
1688 continue;
1689 }
1690
1691 dprintf(("ChildWindowFromPointEx returned %x", hWnd));
1692 // found it!
1693 return hWnd;
1694 }
1695 // the point is in the parentwindow but the parentwindow has no child
1696 // at this coordinate
1697 dprintf(("ChildWindowFromPointEx returned parent %x", hwndParent));
1698 return hwndParent;
1699}
1700//******************************************************************************
1701//******************************************************************************
1702BOOL WIN32API CloseWindow(HWND hwnd)
1703{
1704 Win32BaseWindow *window;
1705
1706 window = Win32BaseWindow::GetWindowFromHandle(hwnd);
1707 if(!window) {
1708 dprintf(("CloseWindow, window %x not found", hwnd));
1709 SetLastError(ERROR_INVALID_WINDOW_HANDLE);
1710 return 0;
1711 }
1712 dprintf(("CloseWindow %x\n", hwnd));
1713 BOOL ret = window->CloseWindow();
1714 RELEASE_WNDOBJ(window);
1715 return ret;
1716}
1717//******************************************************************************
1718//******************************************************************************
1719static BOOL IsPointInWindow(HWND hwnd, POINT point)
1720{
1721 RECT rectWindow;
1722 DWORD hittest, dwStyle, dwExStyle;
1723
1724 dwStyle = GetWindowLongA(hwnd, GWL_STYLE);
1725 dwExStyle = GetWindowLongA(hwnd, GWL_EXSTYLE);
1726
1727 GetWindowRect(hwnd, &rectWindow);
1728
1729 /* If point is in window, and window is visible, and it */
1730 /* is enabled (or it's a top-level window), then explore */
1731 /* its children. Otherwise, go to the next window. */
1732
1733 if( (dwStyle & WS_VISIBLE) &&
1734 ((dwExStyle & (WS_EX_LAYERED | WS_EX_TRANSPARENT)) != (WS_EX_LAYERED | WS_EX_TRANSPARENT)) &&
1735 (!(dwStyle & WS_DISABLED) || ((dwStyle & (WS_POPUP | WS_CHILD)) != WS_CHILD)) &&
1736 ((point.x >= rectWindow.left) && (point.x < rectWindow.right) &&
1737 (point.y >= rectWindow.top) && (point.y < rectWindow.bottom))
1738#if 1
1739 )
1740#else
1741 &&
1742 (wndPtr->hrgnWnd ? PtInRegion(wndPtr->hrgnWnd, 1))
1743#endif
1744 {
1745 DWORD dwThreadId = GetCurrentThreadId();
1746
1747 //Don't send WM_NCHITTEST if this window doesn't belong to the current thread
1748 if(dwThreadId != GetWindowThreadProcessId(hwnd, NULL))
1749 {
1750 return TRUE;
1751 }
1752 hittest = SendMessageA(hwnd, WM_NCHITTEST, 0, MAKELONG(point.x, point.y));
1753 if(hittest != HTTRANSPARENT) {
1754 return TRUE;
1755 }
1756 }
1757 return FALSE;
1758}
1759//******************************************************************************
1760//TODO: Does this return handles of hidden or disabled windows?
1761//******************************************************************************
1762HWND WIN32API WindowFromPoint( POINT point)
1763{
1764 HWND hwndOS2, hwnd;
1765 POINT wPoint;
1766
1767 wPoint.x = point.x;
1768 wPoint.y = mapScreenY(point.y);
1769
1770 hwndOS2 = OSLibWinWindowFromPoint(OSLIB_HWND_DESKTOP, (PVOID)&wPoint);
1771 if(hwndOS2)
1772 {
1773 hwnd = OS2ToWin32Handle(hwndOS2);
1774 while(hwnd)
1775 {
1776 if(IsPointInWindow(hwnd, point)) {
1777 dprintf(("WindowFromPoint (%d,%d) %x->%x\n", point.x, point.y, hwndOS2, hwnd));
1778 return hwnd;
1779 }
1780#if 0
1781//TODO: breaks a lot of things
1782 hwnd = GetWindow(hwnd, GW_HWNDNEXT);
1783#else
1784 //try siblings
1785 HWND hwndSibling;
1786 HWND hwndParent = GetParent(hwnd);
1787
1788 if(hwndParent) {
1789 hwndSibling = GetWindow(hwndParent, GW_CHILD);
1790 while(hwndSibling) {
1791 if(hwndSibling != hwnd) {
1792 if(IsPointInWindow(hwndSibling, point)) {
1793 dprintf(("WindowFromPoint (%d,%d) %x->%x\n", point.x, point.y, hwndOS2, hwndSibling));
1794 return hwndSibling;
1795 }
1796 }
1797 hwndSibling = GetWindow(hwndSibling, GW_HWNDNEXT);
1798 }
1799 }
1800 hwnd = hwndParent;
1801#endif
1802 }
1803 }
1804 dprintf(("WindowFromPoint (%d,%d) %x->1\n", point.x, point.y, hwndOS2));
1805 return windowDesktop->getWindowHandle();
1806}
1807//******************************************************************************
1808//******************************************************************************
1809BOOL WIN32API IsWindowUnicode(HWND hwnd)
1810{
1811 Win32BaseWindow *window;
1812
1813 window = Win32BaseWindow::GetWindowFromHandle(hwnd);
1814 if(!window) {
1815 dprintf(("IsWindowUnicode, window %x not found", hwnd));
1816 SetLastError(ERROR_INVALID_WINDOW_HANDLE);
1817 return 0;
1818 }
1819 BOOL ret = window->IsWindowUnicode();
1820 RELEASE_WNDOBJ(window);
1821 return ret;
1822}
1823/***********************************************************************
1824 * SwitchToThisWindow (USER32.539)
1825 */
1826VOID WINAPI SwitchToThisWindow( HWND hwnd, BOOL restore )
1827{
1828 ShowWindow( hwnd, restore ? SW_RESTORE : SW_SHOWMINIMIZED );
1829}
1830//******************************************************************************
1831//******************************************************************************
1832BOOL WIN32API EnumThreadWindows(DWORD dwThreadId, WNDENUMPROC lpfn, LPARAM lParam)
1833{
1834 return windowDesktop->EnumThreadWindows(dwThreadId, lpfn, lParam);
1835}
1836//******************************************************************************
1837//******************************************************************************
1838BOOL WIN32API EnumChildWindows(HWND hwnd, WNDENUMPROC lpfn, LPARAM lParam)
1839{
1840 Win32BaseWindow *window;
1841 BOOL ret = TRUE;
1842 ULONG henum;
1843 HWND hwndNext;
1844
1845 if(lpfn == NULL) {
1846 dprintf(("EnumChildWindows invalid parameter %x %x\n", hwnd, lParam));
1847 SetLastError(ERROR_INVALID_PARAMETER);
1848 return FALSE;
1849 }
1850 window = Win32BaseWindow::GetWindowFromHandle(hwnd);
1851 if(!window) {
1852 dprintf(("EnumChildWindows, window %x not found", hwnd));
1853 SetLastError(ERROR_INVALID_WINDOW_HANDLE);
1854 return FALSE;
1855 }
1856 ret = window->EnumChildWindows(lpfn, lParam);
1857 RELEASE_WNDOBJ(window);
1858 return ret;
1859}
1860//******************************************************************************
1861//******************************************************************************
1862BOOL WIN32API EnumWindows(WNDENUMPROC lpfn, LPARAM lParam)
1863{
1864 return windowDesktop->EnumWindows(lpfn, lParam);
1865}
1866//******************************************************************************
1867//******************************************************************************
1868UINT WIN32API ArrangeIconicWindows( HWND parent)
1869{
1870 RECT rectParent;
1871 HWND hwndChild;
1872 INT x, y, xspacing, yspacing;
1873
1874 dprintf(("USER32: ArrangeIconicWindows %x", parent));
1875 dprintf(("USER32: TODO: icon title!!"));
1876
1877 GetClientRect(parent, &rectParent);
1878 x = rectParent.left;
1879 y = rectParent.bottom;
1880 xspacing = GetSystemMetrics(SM_CXICONSPACING);
1881 yspacing = GetSystemMetrics(SM_CYICONSPACING);
1882
1883 hwndChild = GetWindow( parent, GW_CHILD );
1884 while (hwndChild)
1885 {
1886 if( IsIconic( hwndChild ) )
1887 {
1888// WND *wndPtr = WIN_FindWndPtr(hwndChild);
1889
1890// WINPOS_ShowIconTitle( wndPtr, FALSE );
1891
1892 SetWindowPos( hwndChild, 0, x + (xspacing - GetSystemMetrics(SM_CXICON)) / 2,
1893 y - yspacing - GetSystemMetrics(SM_CYICON)/2, 0, 0,
1894 SWP_NOSIZE | SWP_NOZORDER | SWP_NOACTIVATE );
1895// if( IsWindow(hwndChild) )
1896// WINPOS_ShowIconTitle(wndPtr , TRUE );
1897// WIN_ReleaseWndPtr(wndPtr);
1898
1899 if (x <= rectParent.right - xspacing) x += xspacing;
1900 else
1901 {
1902 x = rectParent.left;
1903 y -= yspacing;
1904 }
1905 }
1906 hwndChild = GetWindow( hwndChild, GW_HWNDNEXT );
1907 }
1908 return yspacing;
1909}
1910//******************************************************************************
1911//restores iconized window to previous size/position
1912//******************************************************************************
1913BOOL WIN32API OpenIcon(HWND hwnd)
1914{
1915 dprintf(("USER32: OpenIcon %x", hwnd));
1916
1917 if(!IsIconic(hwnd))
1918 return FALSE;
1919 ShowWindow(hwnd, SW_SHOWNORMAL);
1920 return TRUE;
1921}
1922//******************************************************************************
1923//SDK: Windows can only be shown with ShowOwnedPopups if they were previously
1924// hidden with the same api
1925//TODO: -> needs testing
1926//******************************************************************************
1927BOOL WIN32API ShowOwnedPopups(HWND hwndOwner, BOOL fShow)
1928{
1929 Win32BaseWindow *window, *owner;
1930 HWND hwnd;
1931
1932 owner = Win32BaseWindow::GetWindowFromHandle(hwndOwner);
1933 if(!owner) {
1934 dprintf(("ShowOwnedPopups, window %x not found", hwndOwner));
1935 SetLastError(ERROR_INVALID_WINDOW_HANDLE);
1936 return FALSE;
1937 }
1938 dprintf(("USER32: ShowOwnedPopups %x %d", hwndOwner, fShow));
1939
1940 hwnd = GetWindow(GetDesktopWindow(), GW_CHILD);
1941 while(hwnd) {
1942 window = Win32BaseWindow::GetWindowFromHandle(hwnd);
1943 if(window) {
1944 if(window == owner && (window->getStyle() & WS_POPUP))
1945 {
1946 if(fShow) {
1947 if(window->getFlags() & WIN_NEEDS_SHOW_OWNEDPOPUP)
1948 {
1949 /*
1950 * In Windows, ShowOwnedPopups(TRUE) generates WM_SHOWWINDOW messages with SW_PARENTOPENING,
1951 * regardless of the state of the owner
1952 */
1953 SendMessageA(hwnd, WM_SHOWWINDOW, SW_SHOW, SW_PARENTOPENING);
1954 window->setFlags(window->getFlags() & ~WIN_NEEDS_SHOW_OWNEDPOPUP);
1955 }
1956 }
1957 else
1958 {
1959 if(IsWindowVisible(hwnd))
1960 {
1961 /*
1962 * In Windows, ShowOwnedPopups(FALSE) generates WM_SHOWWINDOW messages with SW_PARENTCLOSING,
1963 * regardless of the state of the owner
1964 */
1965 SendMessageA(hwnd, WM_SHOWWINDOW, SW_HIDE, SW_PARENTCLOSING);
1966 window->setFlags(window->getFlags() | WIN_NEEDS_SHOW_OWNEDPOPUP);
1967 }
1968 }
1969 }
1970 RELEASE_WNDOBJ(window);
1971 }
1972 else dprintf(("WARNING: window %x is not valid", hwnd));
1973
1974 hwnd = GetWindow(hwnd, GW_HWNDNEXT);
1975 }
1976 RELEASE_WNDOBJ(owner);
1977 return TRUE;
1978}
1979//******************************************************************************
1980//******************************************************************************
1981HWND WIN32API GetForegroundWindow()
1982{
1983 HWND hwnd;
1984
1985 hwnd = OS2ToWin32Handle(OSLibWinQueryActiveWindow());
1986 return hwnd;
1987}
1988//******************************************************************************
1989
1990/******************************************************************************
1991 * The return value identifies the most recently active pop-up window.
1992 * The return value is the same as the hWnd parameter, if any of the
1993 * following conditions are met:
1994 *
1995 * - The window identified by hWnd was most recently active.
1996 * - The window identified by hWnd does not own any pop-up windows.
1997 * - The window identified by hWnd is not a top-level window or it is
1998 * owned by another window.
1999 */
2000HWND WIN32API GetLastActivePopup(HWND hWnd)
2001{
2002 Win32BaseWindow *owner;
2003
2004 owner = Win32BaseWindow::GetWindowFromHandle(hWnd);
2005 if(!owner)
2006 {
2007 dprintf(("GetLastActivePopup, window %x not found", hWnd));
2008 SetLastError(ERROR_INVALID_WINDOW_HANDLE);
2009 return hWnd;
2010 }
2011
2012 HWND hwndRetVal = owner->getLastActive();
2013 if (!IsWindow( hwndRetVal ))
2014 hwndRetVal = owner->getWindowHandle();
2015
2016 RELEASE_WNDOBJ(owner);
2017
2018 return hwndRetVal;
2019}
2020//******************************************************************************
2021//******************************************************************************
2022DWORD WIN32API GetWindowThreadProcessId(HWND hwnd, PDWORD lpdwProcessId)
2023{
2024 Win32BaseWindow *window;
2025 DWORD dwThreadId;
2026
2027 window = Win32BaseWindow::GetWindowFromHandle(hwnd);
2028 if(!window) {
2029 dprintf(("GetWindowThreadProcessId, window %x not found", hwnd));
2030 SetLastError(ERROR_INVALID_WINDOW_HANDLE);
2031 return 0;
2032 }
2033 dwThreadId = window->getThreadId();
2034 if(lpdwProcessId) {
2035 *lpdwProcessId = window->getProcessId();
2036 }
2037 RELEASE_WNDOBJ(window);
2038
2039 return dwThreadId;
2040}
2041//******************************************************************************
2042//******************************************************************************
2043DWORD WIN32API GetWindowContextHelpId(HWND hwnd)
2044{
2045 Win32BaseWindow *window;
2046
2047 window = Win32BaseWindow::GetWindowFromHandle(hwnd);
2048 if(!window) {
2049 dprintf(("GetWindowContextHelpId, window %x not found", hwnd));
2050 SetLastError(ERROR_INVALID_WINDOW_HANDLE);
2051 return 0;
2052 }
2053 dprintf(("GetWindowContextHelpId %x", hwnd));
2054 DWORD ret = window->getWindowContextHelpId();
2055 RELEASE_WNDOBJ(window);
2056 return ret;
2057}
2058//******************************************************************************
2059//******************************************************************************
2060BOOL WIN32API SetWindowContextHelpId(HWND hwnd, DWORD dwContextHelpId)
2061{
2062 Win32BaseWindow *window;
2063
2064 window = Win32BaseWindow::GetWindowFromHandle(hwnd);
2065 if(!window) {
2066 dprintf(("SetWindowContextHelpId, window %x not found", hwnd));
2067 SetLastError(ERROR_INVALID_WINDOW_HANDLE);
2068 return 0;
2069 }
2070 dprintf(("SetWindowContextHelpId %x %d", hwnd, dwContextHelpId));
2071 window->setWindowContextHelpId(dwContextHelpId);
2072 RELEASE_WNDOBJ(window);
2073 return(TRUE);
2074}
2075//******************************************************************************
2076//******************************************************************************
2077HANDLE WIN32API GetPropA(HWND hwnd, LPCSTR str )
2078{
2079 Win32BaseWindow *window;
2080
2081 window = Win32BaseWindow::GetWindowFromHandle(hwnd);
2082 if(!window) {
2083 dprintf(("GetPropA, window %x not found", hwnd));
2084 SetLastError(ERROR_INVALID_WINDOW_HANDLE);
2085 return 0;
2086 }
2087 HANDLE ret = window->getProp(str);
2088 RELEASE_WNDOBJ(window);
2089 return ret;
2090}
2091//******************************************************************************
2092//******************************************************************************
2093HANDLE WIN32API GetPropW(HWND hwnd, LPCWSTR str)
2094{
2095 Win32BaseWindow *window;
2096 LPSTR strA;
2097 HANDLE ret;
2098
2099 window = Win32BaseWindow::GetWindowFromHandle(hwnd);
2100 if(!window) {
2101 dprintf(("GetPropW, window %x not found", hwnd));
2102 SetLastError(ERROR_INVALID_WINDOW_HANDLE);
2103 return 0;
2104 }
2105
2106 if(HIWORD(str)) {
2107 strA = HEAP_strdupWtoA( GetProcessHeap(), 0, str );
2108 }
2109 else strA = (LPSTR)str;
2110
2111 ret = window->getProp(strA);
2112
2113 RELEASE_WNDOBJ(window);
2114 if(HIWORD(str)) HeapFree( GetProcessHeap(), 0, strA );
2115 return ret;
2116}
2117//******************************************************************************
2118//******************************************************************************
2119BOOL WIN32API SetPropA(HWND hwnd, LPCSTR str, HANDLE handle )
2120{
2121 Win32BaseWindow *window;
2122
2123 window = Win32BaseWindow::GetWindowFromHandle(hwnd);
2124 if(!window) {
2125 dprintf(("SetPropA, window %x not found", hwnd));
2126 SetLastError(ERROR_INVALID_WINDOW_HANDLE);
2127 return FALSE;
2128 }
2129 BOOL ret = window->setProp(str, handle);
2130 RELEASE_WNDOBJ(window);
2131 return ret;
2132}
2133//******************************************************************************
2134//******************************************************************************
2135BOOL SetPropW(HWND hwnd, LPCWSTR str, HANDLE handle )
2136{
2137 BOOL ret;
2138 LPSTR strA;
2139
2140 if (!HIWORD(str))
2141 return SetPropA( hwnd, (LPCSTR)(UINT)LOWORD(str), handle );
2142 strA = HEAP_strdupWtoA( GetProcessHeap(), 0, str );
2143 ret = SetPropA( hwnd, strA, handle );
2144 HeapFree( GetProcessHeap(), 0, strA );
2145 return ret;
2146}
2147//******************************************************************************
2148//******************************************************************************
2149HANDLE WIN32API RemovePropA(HWND hwnd, LPCSTR str)
2150{
2151 Win32BaseWindow *window;
2152
2153 window = Win32BaseWindow::GetWindowFromHandle(hwnd);
2154 if(!window) {
2155 dprintf(("RemovePropA, window %x not found", hwnd));
2156 SetLastError(ERROR_INVALID_WINDOW_HANDLE);
2157 return 0;
2158 }
2159 HANDLE ret = window->removeProp(str);
2160 RELEASE_WNDOBJ(window);
2161 return ret;
2162}
2163//******************************************************************************
2164//******************************************************************************
2165HANDLE WIN32API RemovePropW(HWND hwnd, LPCWSTR str)
2166{
2167 LPSTR strA;
2168 HANDLE ret;
2169
2170 if (!HIWORD(str))
2171 return RemovePropA( hwnd, (LPCSTR)(UINT)LOWORD(str) );
2172 strA = HEAP_strdupWtoA( GetProcessHeap(), 0, str );
2173 ret = RemovePropA( hwnd, strA );
2174 HeapFree( GetProcessHeap(), 0, strA );
2175 return ret;
2176}
2177//******************************************************************************
2178//******************************************************************************
2179INT WIN32API EnumPropsA(HWND hwnd, PROPENUMPROCA func )
2180{
2181 return EnumPropsExA( hwnd, (PROPENUMPROCEXA)func, 0 );
2182}
2183//******************************************************************************
2184//******************************************************************************
2185INT WIN32API EnumPropsW(HWND hwnd, PROPENUMPROCW func )
2186{
2187 return EnumPropsExW( hwnd, (PROPENUMPROCEXW)func, 0 );
2188}
2189//******************************************************************************
2190//******************************************************************************
2191INT WIN32API EnumPropsExA(HWND hwnd, PROPENUMPROCEXA func, LPARAM lParam)
2192{
2193 Win32BaseWindow *window;
2194
2195 window = Win32BaseWindow::GetWindowFromHandle(hwnd);
2196 if(!window) {
2197 dprintf(("EnumPropsExA, window %x not found", hwnd));
2198 SetLastError(ERROR_INVALID_WINDOW_HANDLE);
2199 return -1;
2200 }
2201 INT ret = window->enumPropsExA(func, lParam);
2202 RELEASE_WNDOBJ(window);
2203 return ret;
2204}
2205//******************************************************************************
2206//******************************************************************************
2207INT WIN32API EnumPropsExW(HWND hwnd, PROPENUMPROCEXW func, LPARAM lParam)
2208{
2209 Win32BaseWindow *window;
2210
2211 window = Win32BaseWindow::GetWindowFromHandle(hwnd);
2212 if(!window) {
2213 dprintf(("EnumPropsExA, window %x not found", hwnd));
2214 SetLastError(ERROR_INVALID_WINDOW_HANDLE);
2215 return -1;
2216 }
2217 INT ret = window->enumPropsExW(func, lParam);
2218 RELEASE_WNDOBJ(window);
2219 return ret;
2220}
2221//******************************************************************************
2222//The GetWindowModuleFileName function retrieves the full path and file name of
2223//the module associated with the specified window handle.
2224//******************************************************************************
2225UINT WIN32API GetWindowModuleFileNameA(HWND hwnd, LPTSTR lpszFileName, UINT cchFileNameMax)
2226{
2227 WNDPROC lpfnWindowProc;
2228
2229 if (!IsWindow(hwnd)) {
2230 dprintf(("warning: GetWindowModuleFileName: window %x not found!", hwnd));
2231 SetLastError(ERROR_INVALID_WINDOW_HANDLE);
2232 return 0;
2233 }
2234 lpfnWindowProc = (WNDPROC)GetWindowLongA(hwnd, GWL_WNDPROC);
2235 return GetProcModuleFileNameA((ULONG)lpfnWindowProc, lpszFileName, cchFileNameMax);
2236}
2237//******************************************************************************
2238//******************************************************************************
2239
2240
2241/*****************************************************************************
2242 * Name : BOOL WIN32API AnyPopup
2243 * Purpose : The AnyPopup function indicates whether an owned, visible,
2244 * top-level pop-up, or overlapped window exists on the screen. The
2245 * function searches the entire Windows screen, not just the calling
2246 * application's client area.
2247 * Parameters: VOID
2248 * Variables :
2249 * Result : If a pop-up window exists, the return value is TRUE even if the
2250 * pop-up window is completely covered by other windows. Otherwise,
2251 * it is FALSE.
2252 * Remark : AnyPopup is a Windows version 1.x function and is retained for
2253 * compatibility purposes. It is generally not useful.
2254 * Status : UNTESTED STUB
2255 *
2256 * Author : Patrick Haller [Thu, 1998/02/26 11:55]
2257 *****************************************************************************/
2258BOOL WIN32API AnyPopup()
2259{
2260 dprintf(("USER32:AnyPopup() not implemented.\n"));
2261
2262 return (FALSE);
2263}
Note: See TracBrowser for help on using the repository browser.