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

Last change on this file since 9094 was 8978, checked in by sandervl, 23 years ago

Partly implemented GetGUIThreadInfo

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