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

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

corrected regressions caused by previous setfocus fix; make sure owner isn't disabled when specifying SWP_DEACTIVATE

File size: 75.8 KB
Line 
1/* $Id: window.cpp,v 1.130 2003-01-02 17:02:06 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 dprintf(("SetFocus %x", hwnd));
760 teb = GetThreadTEB();
761 if(teb == NULL) {
762 DebugInt3();
763 return 0;
764 }
765
766 //SetFocus is not allowed for minimized or disabled windows (this window
767 //or any parent)
768 hwndTop = hwnd;
769 for (;;)
770 {
771 HWND parent;
772
773 LONG style = GetWindowLongW( hwndTop, GWL_STYLE );
774 if (style & (WS_MINIMIZE | WS_DISABLED)) {
775 dprintf(("SetFocus, %x not allowed on minimized or disabled window (%x)", hwnd, style));
776 return 0;
777 }
778 parent = GetAncestor(hwndTop, GA_PARENT);
779 if (!parent || parent == GetDesktopWindow()) break;
780 hwndTop = parent;
781 }
782
783 window = Win32BaseWindow::GetWindowFromHandle(hwnd);
784 if(!window) {
785 dprintf(("SetFocus, window %x not found", hwnd));
786 //Note: last error not set (NT4, SP6), returns current focus window
787 //SetLastError(ERROR_INVALID_WINDOW_HANDLE);
788 return GetFocus();
789 }
790
791 hwnd_O = window->getOS2WindowHandle();
792 if(teb->o.odin.hwndFocus) {
793 lastFocus = teb->o.odin.hwndFocus;
794 }
795 else lastFocus = OSLibWinQueryFocus (OSLIB_HWND_DESKTOP);
796
797 hwndTopParent = window->GetTopParent();
798 activate = FALSE;
799 lastFocus_W = OS2ToWin32Handle(lastFocus);
800 if(lastFocus_W) {
801 oldfocuswnd = Win32BaseWindow::GetWindowFromHandle(lastFocus_W);
802 if(lastFocus_W != hwnd && hwndTopParent != oldfocuswnd->GetTopParent()) {
803 activate = TRUE;
804 }
805 RELEASE_WNDOBJ(oldfocuswnd);
806 }
807 else activate = TRUE;
808
809 dprintf(("SetFocus %x (%x) -> %x (%x) act %d", lastFocus_W, lastFocus, hwnd, hwnd_O, activate));
810
811 if(HOOK_CallHooksA(WH_CBT, HCBT_SETFOCUS, hwnd, (LPARAM)lastFocus_W)) {
812 dprintf(("hook cancelled SetFocus call!"));
813 RELEASE_WNDOBJ(window);
814 return 0;
815 }
816
817 //PM doesn't allow SetFocus calls during WM_SETFOCUS message processing;
818 //must delay this function call
819 if(teb->o.odin.fWM_SETFOCUS) {
820 dprintf(("USER32: Delay SetFocus call!"));
821 teb->o.odin.hwndFocus = hwnd;
822 //mp1 = win32 window handle
823 //mp2 = top parent if activation required
824 OSLibPostMessageDirect(hwnd_O, WIN32APP_SETFOCUSMSG, hwnd, (activate) ? hwndTopParent : 0);
825 RELEASE_WNDOBJ(window);
826 return lastFocus_W;
827 }
828 teb->o.odin.hwndFocus = 0;
829 if(!IsWindow(hwnd)) return FALSE; //abort if window destroyed
830
831 //NOTE: Don't always activate the window or else the z-order will be changed!!
832 ret = (OSLibWinSetFocus(OSLIB_HWND_DESKTOP, hwnd_O, activate)) ? lastFocus_W : 0;
833 RELEASE_WNDOBJ(window);
834 return ret;
835}
836//******************************************************************************
837//******************************************************************************
838HWND WIN32API GetFocus()
839{
840 TEB *teb;
841 HWND hwnd;
842
843 teb = GetThreadTEB();
844 if(teb == NULL) {
845 DebugInt3();
846 return 0;
847 }
848 //PM doesn't allow SetFocus calls during WM_SETFOCUS message processing;
849 //If focus was changed during WM_SETFOCUS, the focus window handle is
850 //stored in teb->o.odin.hwndFocus (set back to 0 when delayed SetFocus
851 //is activated)
852 if(teb->o.odin.hwndFocus) {
853 dprintf(("USER32: GetFocus %x (DURING WM_SETFOCUS PROCESSING)", teb->o.odin.hwndFocus));
854 return teb->o.odin.hwndFocus;
855 }
856
857 hwnd = OSLibWinQueryFocus(OSLIB_HWND_DESKTOP);
858 hwnd = OS2ToWin32Handle(hwnd);
859 dprintf(("USER32: GetFocus %x\n", hwnd));
860 return hwnd;
861}
862//******************************************************************************
863//******************************************************************************
864BOOL WIN32API GetGUIThreadInfo(DWORD dwThreadId, GUITHREADINFO *lpThreadInfo)
865{
866 dprintf(("!WARNING!: GetGUIThreadInfo not completely implemented!!"));
867
868 if(!lpThreadInfo || lpThreadInfo->cbSize != sizeof(GUITHREADINFO)) {
869 SetLastError(ERROR_INVALID_PARAMETER);
870 return FALSE;
871 }
872 //dwThreadId == 0 -> current thread
873 if(!dwThreadId) dwThreadId = GetCurrentThreadId();
874
875 lpThreadInfo->flags;
876 lpThreadInfo->hwndActive = GetActiveWindow();
877 if(lpThreadInfo->hwndActive) {
878 if(dwThreadId != GetWindowThreadProcessId(lpThreadInfo->hwndActive, NULL))
879 {//this thread doesn't own the active window (TODO: correct??)
880 lpThreadInfo->hwndActive = 0;
881 }
882 }
883 lpThreadInfo->hwndFocus = GetFocus();
884 lpThreadInfo->hwndCapture = GetCapture();
885 lpThreadInfo->flags = 0; //TODO:
886 lpThreadInfo->hwndMenuOwner = 0; //TODO: Handle to the window that owns any active menus
887 lpThreadInfo->hwndMoveSize = 0; //TODO: Handle to the window in a move or size loop.
888 lpThreadInfo->hwndCaret = 0; //TODO: Handle to the window that is displaying the caret
889 lpThreadInfo->rcCaret.left = 0;
890 lpThreadInfo->rcCaret.top = 0;
891 lpThreadInfo->rcCaret.right = 0;
892 lpThreadInfo->rcCaret.bottom = 0;
893
894 SetLastError(ERROR_SUCCESS);
895 return TRUE;
896}
897//******************************************************************************
898//******************************************************************************
899BOOL WIN32API IsZoomed(HWND hwnd)
900{
901 DWORD style;
902
903 style = GetWindowLongA(hwnd, GWL_STYLE);
904 dprintf(("USER32: IsZoomed %x returned %d", hwnd, ((style & WS_MAXIMIZE) != 0)));
905
906 return (style & WS_MAXIMIZE) != 0;
907}
908//******************************************************************************
909//******************************************************************************
910BOOL WIN32API LockWindowUpdate(HWND hwnd)
911{
912 return OSLibWinLockWindowUpdate(Win32ToOS2Handle(hwnd));
913}
914//******************************************************************************
915//******************************************************************************
916BOOL WIN32API GetWindowRect(HWND hwnd, PRECT pRect)
917{
918 Win32BaseWindow *window;
919
920 if(pRect == NULL) {
921 dprintf(("GetWindowRect %x invalid parameter!", hwnd));
922 SetLastError(ERROR_INVALID_PARAMETER);
923 return FALSE;
924 }
925
926 if(hwnd == HWND_DESKTOP) {
927 windowDesktop->addRef();
928 window = windowDesktop;
929 }
930 else window = Win32BaseWindow::GetWindowFromHandle(hwnd);
931
932 if(!window) {
933 dprintf(("GetWindowRect, window %x not found", hwnd));
934 SetLastError(ERROR_INVALID_WINDOW_HANDLE);
935 return FALSE;
936 }
937 *pRect = *window->getWindowRect();
938
939 //convert from parent coordinates to screen (if necessary)
940 if(window->getParent()) {
941 MapWindowPoints(window->getParent()->getWindowHandle(), 0, (PPOINT)pRect, 2);
942 }
943 RELEASE_WNDOBJ(window);
944 dprintf(("GetWindowRect %x (%d,%d) (%d,%d)", hwnd, pRect->left, pRect->top, pRect->right, pRect->bottom));
945 return TRUE;
946}
947//******************************************************************************
948//******************************************************************************
949INT WIN32API GetWindowTextLengthA(HWND hwnd)
950{
951 Win32BaseWindow *window;
952
953 window = Win32BaseWindow::GetWindowFromHandle(hwnd);
954 if(!window) {
955 dprintf(("GetWindowTextLengthA, window %x not found", hwnd));
956 SetLastError(ERROR_INVALID_WINDOW_HANDLE);
957 return 0;
958 }
959 dprintf(("GetWindowTextLengthA %x", hwnd));
960 int ret = window->GetWindowTextLengthA();
961 RELEASE_WNDOBJ(window);
962 return ret;
963}
964//******************************************************************************
965//******************************************************************************
966int WIN32API GetWindowTextA( HWND hwnd, LPSTR lpsz, int cch)
967{
968 Win32BaseWindow *window;
969 int rc;
970
971 window = Win32BaseWindow::GetWindowFromHandle(hwnd);
972 if(!window) {
973 dprintf(("GetWindowTextA, window %x not found", hwnd));
974 SetLastError(ERROR_INVALID_WINDOW_HANDLE);
975 return 0;
976 }
977 rc = window->GetWindowTextA(lpsz, cch);
978 dprintf(("GetWindowTextA %x %s", hwnd, lpsz));
979 RELEASE_WNDOBJ(window);
980 return rc;
981}
982//******************************************************************************
983//******************************************************************************
984int WIN32API GetWindowTextLengthW( HWND hwnd)
985{
986 Win32BaseWindow *window;
987
988 window = Win32BaseWindow::GetWindowFromHandle(hwnd);
989 if(!window) {
990 dprintf(("GetWindowTextLengthW, window %x not found", hwnd));
991 SetLastError(ERROR_INVALID_WINDOW_HANDLE);
992 return 0;
993 }
994 dprintf(("GetWindowTextLengthW %x", hwnd));
995 int ret = window->GetWindowTextLengthW();
996 RELEASE_WNDOBJ(window);
997 return ret;
998}
999//******************************************************************************
1000//******************************************************************************
1001int WIN32API GetWindowTextW(HWND hwnd, LPWSTR lpsz, int cch)
1002{
1003 Win32BaseWindow *window;
1004
1005 window = Win32BaseWindow::GetWindowFromHandle(hwnd);
1006 if(!window) {
1007 dprintf(("GetWindowTextW, window %x not found", hwnd));
1008 SetLastError(ERROR_INVALID_WINDOW_HANDLE);
1009 return 0;
1010 }
1011 int rc = window->GetWindowTextW(lpsz, cch);
1012 RELEASE_WNDOBJ(window);
1013 dprintf(("GetWindowTextW %x %ls", hwnd, lpsz));
1014 return rc;
1015}
1016//******************************************************************************
1017//******************************************************************************
1018BOOL WIN32API SetWindowTextA(HWND hwnd, LPCSTR lpsz)
1019{
1020 Win32BaseWindow *window;
1021
1022 window = Win32BaseWindow::GetWindowFromHandle(hwnd);
1023 if(!window) {
1024 dprintf(("SetWindowTextA, window %x not found", hwnd));
1025 SetLastError(ERROR_INVALID_WINDOW_HANDLE);
1026 return 0;
1027 }
1028 dprintf(("SetWindowTextA %x %s", hwnd, lpsz));
1029 BOOL ret = window->SetWindowTextA((LPSTR)lpsz);
1030 RELEASE_WNDOBJ(window);
1031 return ret;
1032}
1033//******************************************************************************
1034//******************************************************************************
1035BOOL WIN32API SetWindowTextW( HWND hwnd, LPCWSTR lpsz)
1036{
1037 Win32BaseWindow *window;
1038
1039 window = Win32BaseWindow::GetWindowFromHandle(hwnd);
1040 if(!window) {
1041 dprintf(("SetWindowTextA, window %x not found", hwnd));
1042 SetLastError(ERROR_INVALID_WINDOW_HANDLE);
1043 return 0;
1044 }
1045 dprintf(("SetWindowTextW %x %ls", hwnd, lpsz));
1046 BOOL ret = window->SetWindowTextW((LPWSTR)lpsz);
1047 RELEASE_WNDOBJ(window);
1048 return ret;
1049}
1050/*******************************************************************
1051 * InternalGetWindowText (USER32.326)
1052 */
1053int WIN32API InternalGetWindowText(HWND hwnd,
1054 LPWSTR lpString,
1055 INT nMaxCount )
1056{
1057 dprintf(("USER32: InternalGetWindowText(%08xh,%08xh,%08xh) not properly implemented.\n",
1058 hwnd, lpString, nMaxCount));
1059
1060 return GetWindowTextW(hwnd, lpString,nMaxCount);
1061}
1062//******************************************************************************
1063//TODO: Correct?
1064//******************************************************************************
1065BOOL WIN32API SetForegroundWindow(HWND hwnd)
1066{
1067 dprintf((" SetForegroundWindow %x", hwnd));
1068
1069 return SetWindowPos( hwnd, HWND_TOP, 0, 0, 0, 0, SWP_NOMOVE | SWP_NOSIZE);
1070}
1071//******************************************************************************
1072//******************************************************************************
1073BOOL WIN32API GetClientRect( HWND hwnd, PRECT pRect)
1074{
1075 HWND hwndWin32 = hwnd;
1076 Win32BaseWindow *window;
1077
1078 if (!pRect)
1079 {
1080 SetLastError(ERROR_INVALID_PARAMETER);
1081 return FALSE;
1082 }
1083 window = Win32BaseWindow::GetWindowFromHandle(hwnd);
1084 if(!window) {
1085 dprintf(("GetClientRect, window %x not found", hwnd));
1086 SetLastError(ERROR_INVALID_WINDOW_HANDLE);
1087 return FALSE;
1088 }
1089 window->getClientRect(pRect);
1090 dprintf(("GetClientRect of %X returned (%d,%d) (%d,%d)\n", hwndWin32, pRect->left, pRect->top, pRect->right, pRect->bottom));
1091 RELEASE_WNDOBJ(window);
1092 return TRUE;
1093}
1094//******************************************************************************
1095//******************************************************************************
1096BOOL WIN32API AdjustWindowRect(PRECT rect, DWORD style, BOOL menu)
1097{
1098 return AdjustWindowRectEx(rect, style, menu, 0);
1099}
1100//******************************************************************************
1101//Calculate window rectangle based on given client rectangle, style, menu and extended style
1102//******************************************************************************
1103BOOL WIN32API AdjustWindowRectEx( PRECT rect, DWORD style, BOOL menu, DWORD exStyle)
1104{
1105 if(style == 0 && menu == FALSE && exStyle == 0) {
1106 dprintf(("AdjustWindowRectEx %x %x %d (%d,%d)(%d,%d) -> no change required", style, exStyle, menu, rect->left, rect->top, rect->right, rect->bottom));
1107 return TRUE; //nothing needs to be changed (VERIFIED in NT 4)
1108 }
1109 dprintf(("AdjustWindowRectEx %x %x %d (%d,%d)(%d,%d)\n", style, exStyle, menu, rect->left, rect->top, rect->right, rect->bottom));
1110 /* Correct the window style */
1111 if (!(style & (WS_POPUP | WS_CHILD))) /* Overlapped window */
1112 style |= WS_CAPTION;
1113
1114 //SvL: Include WS_POPUP -> otherwise HAS_THINFRAME is true for popup windows
1115 // Also include WS_CHILD -> otherwise HAS_THICKFRAME doesn't work correctly
1116 style &= (WS_DLGFRAME | WS_BORDER | WS_THICKFRAME | WS_CHILD | WS_VSCROLL | WS_HSCROLL | WS_POPUP);
1117 exStyle &= (WS_EX_DLGMODALFRAME | WS_EX_CLIENTEDGE | WS_EX_STATICEDGE | WS_EX_TOOLWINDOW);
1118 if (exStyle & WS_EX_DLGMODALFRAME) style &= ~WS_THICKFRAME;
1119
1120 //Adjust rect outer (Win32BaseWindow::AdjustRectOuter)
1121 if (HAS_THICKFRAME(style,exStyle))
1122 InflateRect( rect, GetSystemMetrics(SM_CXFRAME), GetSystemMetrics(SM_CYFRAME) );
1123 else
1124 if (HAS_DLGFRAME(style,exStyle))
1125 InflateRect(rect, GetSystemMetrics(SM_CXDLGFRAME), GetSystemMetrics(SM_CYDLGFRAME) );
1126 else
1127 if (HAS_THINFRAME(style))
1128 InflateRect( rect, GetSystemMetrics(SM_CXBORDER), GetSystemMetrics(SM_CYBORDER));
1129
1130 if ((style & WS_CAPTION) == WS_CAPTION)
1131 {
1132 if (exStyle & WS_EX_TOOLWINDOW)
1133 rect->top -= GetSystemMetrics(SM_CYSMCAPTION);
1134 else
1135 rect->top -= GetSystemMetrics(SM_CYCAPTION);
1136 }
1137
1138 if (menu)
1139 rect->top -= GetSystemMetrics(SM_CYMENU);
1140
1141 //Adjust rect inner (Win32BaseWindow::AdjustRectInner)
1142 if(!(style & WS_ICONIC)) {
1143 if (exStyle & WS_EX_CLIENTEDGE)
1144 InflateRect (rect, GetSystemMetrics(SM_CXEDGE), GetSystemMetrics(SM_CYEDGE));
1145
1146 if (exStyle & WS_EX_STATICEDGE)
1147 InflateRect (rect, GetSystemMetrics(SM_CXBORDER), GetSystemMetrics(SM_CYBORDER));
1148
1149 //SvL: scrollbars aren't checked *UNLESS* the style includes a border (any border)
1150 // --> VERIFIED IN NT4, SP6 (fixes MFC apps with scrollbars + bar controls)
1151 if(style & (WS_THICKFRAME|WS_BORDER|WS_DLGFRAME)) {
1152 if (style & WS_VSCROLL) rect->right += GetSystemMetrics(SM_CXVSCROLL);
1153 if (style & WS_HSCROLL) rect->bottom += GetSystemMetrics(SM_CYHSCROLL);
1154 }
1155 }
1156
1157 dprintf(("AdjustWindowRectEx returned (%d,%d)(%d,%d)\n", rect->left, rect->top, rect->right, rect->bottom));
1158
1159 return TRUE;
1160}
1161//******************************************************************************
1162/* Coordinate Space and Transformation Functions */
1163//******************************************************************************
1164/*******************************************************************
1165 * WINPOS_GetWinOffset
1166 *
1167 * Calculate the offset between the origin of the two windows. Used
1168 * to implement MapWindowPoints.
1169 */
1170static void WINPOS_GetWinOffset( Win32BaseWindow *wndFrom, Win32BaseWindow *wndTo,
1171 POINT *offset )
1172{
1173 Win32BaseWindow *window;
1174
1175 offset->x = offset->y = 0;
1176
1177 /* Translate source window origin to screen coords */
1178 if(wndFrom != windowDesktop)
1179 {
1180 window = wndFrom;
1181 while(window)
1182 {
1183 offset->x += window->getClientRectPtr()->left + window->getWindowRect()->left;
1184 offset->y += window->getClientRectPtr()->top + window->getWindowRect()->top;
1185 window = window->getParent();
1186 }
1187 }
1188
1189 /* Translate origin to destination window coords */
1190 if(wndTo != windowDesktop)
1191 {
1192 window = wndTo;
1193 while(window)
1194 {
1195 offset->x -= window->getClientRectPtr()->left + window->getWindowRect()->left;
1196 offset->y -= window->getClientRectPtr()->top + window->getWindowRect()->top;
1197 window = window->getParent();
1198 }
1199 }
1200}
1201//******************************************************************************
1202//******************************************************************************
1203int WIN32API MapWindowPoints(HWND hwndFrom, HWND hwndTo, LPPOINT lpPoints,
1204 UINT cPoints)
1205{
1206 Win32BaseWindow *wndfrom, *wndto;
1207 int retval = 0;
1208 POINT offset;
1209
1210 SetLastError(0);
1211 if(lpPoints == NULL || cPoints == 0) {
1212 SetLastError(ERROR_INVALID_PARAMETER);
1213 return 0;
1214 }
1215 if(hwndTo == hwndFrom)
1216 return 0; //nothing to do
1217
1218 if(hwndFrom == HWND_DESKTOP)
1219 {
1220 windowDesktop->addRef();
1221 wndfrom = windowDesktop;
1222 }
1223 else {
1224 wndfrom = Win32BaseWindow::GetWindowFromHandle(hwndFrom);
1225 if(!wndfrom) {
1226 dprintf(("MapWindowPoints, window %x not found", hwndFrom));
1227 SetLastError(ERROR_INVALID_WINDOW_HANDLE);
1228 return 0;
1229 }
1230 }
1231
1232 if(hwndTo == HWND_DESKTOP)
1233 {
1234 windowDesktop->addRef();
1235 wndto = windowDesktop;
1236 }
1237 else {
1238 wndto = Win32BaseWindow::GetWindowFromHandle(hwndTo);
1239 if(!wndto) {
1240 dprintf(("MapWindowPoints, window %x not found", hwndTo));
1241 SetLastError(ERROR_INVALID_WINDOW_HANDLE);
1242 return 0;
1243 }
1244 }
1245
1246 dprintf2(("USER32: MapWindowPoints %x to %x (%d,%d) (%d)", hwndFrom, hwndTo, lpPoints->x, lpPoints->y, cPoints));
1247 WINPOS_GetWinOffset(wndfrom, wndto, &offset);
1248
1249 RELEASE_WNDOBJ(wndto);
1250 RELEASE_WNDOBJ(wndfrom);
1251 for(int i=0;i<cPoints;i++)
1252 {
1253 lpPoints[i].x += offset.x;
1254 lpPoints[i].y += offset.y;
1255 }
1256 retval = ((LONG)offset.y << 16) | offset.x;
1257 return retval;
1258}
1259//******************************************************************************
1260//******************************************************************************
1261BOOL WIN32API ScreenToClient(HWND hwnd, LPPOINT pt)
1262{
1263 PRECT rcl;
1264 BOOL rc;
1265
1266 if(hwnd == HWND_DESKTOP) {
1267 return (TRUE); //nothing to do
1268 }
1269 if (!IsWindow(hwnd)) {
1270 dprintf(("warning: ScreenToClient: window %x not found!", hwnd));
1271 SetLastError(ERROR_INVALID_WINDOW_HANDLE);
1272 return FALSE;
1273 }
1274 SetLastError(0);
1275#ifdef DEBUG
1276 POINT tmp = *pt;
1277#endif
1278 MapWindowPoints(0, hwnd, pt, 1);
1279 dprintf2(("ScreenToClient %x (%d,%d) -> (%d,%d)", hwnd, tmp.x, tmp.y, pt->x, pt->y));
1280 return TRUE;
1281}
1282//******************************************************************************
1283//******************************************************************************
1284HWND WIN32API GetDesktopWindow(void)
1285{
1286 HWND hDesktopWindow = windowDesktop->getWindowHandle();
1287 dprintf2(("USER32: GetDesktopWindow, returned %x\n", hDesktopWindow));
1288 return hDesktopWindow;
1289}
1290//******************************************************************************
1291//******************************************************************************
1292HWND WIN32API FindWindowA(LPCSTR lpszClass, LPCSTR lpszWindow)
1293{
1294 return FindWindowExA( NULL, NULL, lpszClass, lpszWindow );
1295}
1296//******************************************************************************
1297//******************************************************************************
1298HWND WIN32API FindWindowW( LPCWSTR lpClassName, LPCWSTR lpWindowName)
1299{
1300 return FindWindowExW( NULL, NULL, lpClassName, lpWindowName );
1301}
1302//******************************************************************************
1303//******************************************************************************
1304HWND WIN32API FindWindowExA(HWND hwndParent, HWND hwndChildAfter, LPCSTR lpszClass, LPCSTR lpszWindow)
1305{
1306 ATOM atom = 0;
1307
1308 if (lpszClass)
1309 {
1310 /* If the atom doesn't exist, then no class */
1311 /* with this name exists either. */
1312 if (!(atom = GlobalFindAtomA( lpszClass )))
1313 {
1314 SetLastError(ERROR_CANNOT_FIND_WND_CLASS);
1315 return 0;
1316 }
1317 }
1318 return Win32BaseWindow::FindWindowEx(hwndParent, hwndChildAfter, atom, (LPSTR)lpszWindow);
1319}
1320/*****************************************************************************
1321 * Name : HWND WIN32API FindWindowExW
1322 * Purpose : The FindWindowEx function retrieves the handle of a window whose
1323 * class name and window name match the specified strings. The
1324 * function searches child windows, beginning with the one following
1325 * the given child window.
1326 * Parameters: HWND hwndParent handle of parent window
1327 * HWND hwndChildAfter handle of a child window
1328 * LPCTSTR lpszClass address of class name
1329 * LPCTSTR lpszWindow address of window name
1330 * Variables :
1331 * Result : If the function succeeds, the return value is the handle of the
1332 * window that has the specified class and window names.
1333 * If the function fails, the return value is NULL. To get extended
1334 * error information, call GetLastError.
1335 * Remark :
1336 *
1337 *****************************************************************************/
1338
1339HWND WIN32API FindWindowExW(HWND hwndParent,
1340 HWND hwndChildAfter,
1341 LPCWSTR lpszClass,
1342 LPCWSTR lpszWindow)
1343{
1344 ATOM atom = 0;
1345 char *buffer;
1346 HWND hwnd;
1347
1348 if (lpszClass)
1349 {
1350 /* If the atom doesn't exist, then no class */
1351 /* with this name exists either. */
1352 if (!(atom = GlobalFindAtomW( lpszClass )))
1353 {
1354 SetLastError(ERROR_CANNOT_FIND_WND_CLASS);
1355 return 0;
1356 }
1357 }
1358 buffer = HEAP_strdupWtoA( GetProcessHeap(), 0, lpszWindow );
1359 hwnd = Win32BaseWindow::FindWindowEx(hwndParent, hwndChildAfter, atom, buffer);
1360 HeapFree( GetProcessHeap(), 0, buffer );
1361 return hwnd;
1362}
1363//******************************************************************************
1364//******************************************************************************
1365BOOL WIN32API FlashWindow(HWND hwnd, BOOL fFlash)
1366{
1367 dprintf(("FlashWindow %x %d\n", hwnd, fFlash));
1368// return OSLibWinFlashWindow(Win32ToOS2Handle(hwnd), fFlash);
1369 return 1;
1370}
1371//******************************************************************************
1372//******************************************************************************
1373BOOL WIN32API MoveWindow( HWND hwnd, INT x, INT y, INT cx, INT cy,
1374 BOOL repaint )
1375{
1376 int flags = SWP_NOZORDER | SWP_NOACTIVATE;
1377
1378 if (!repaint) flags |= SWP_NOREDRAW;
1379 dprintf(("MoveWindow: %x %d,%d %dx%d %d\n", hwnd, x, y, cx, cy, repaint ));
1380
1381 return SetWindowPos( hwnd, 0, x, y, cx, cy, flags );
1382}
1383//******************************************************************************
1384//******************************************************************************
1385BOOL WIN32API ClientToScreen (HWND hwnd, PPOINT pt)
1386{
1387 PRECT rcl;
1388
1389 if(hwnd == HWND_DESKTOP) {
1390 return(TRUE); //nothing to do
1391 }
1392 if(!IsWindow(hwnd)) {
1393 dprintf(("warning: ClientToScreen window %x not found!", hwnd));
1394 SetLastError(ERROR_INVALID_WINDOW_HANDLE);
1395 return (FALSE);
1396 }
1397#ifdef DEBUG
1398 POINT tmp = *pt;
1399#endif
1400 MapWindowPoints(hwnd, 0, pt, 1);
1401 dprintf2(("ClientToScreen %x (%d,%d) -> (%d,%d)", hwnd, tmp.x, tmp.y, pt->x, pt->y));
1402
1403 return TRUE;
1404}
1405//******************************************************************************
1406//Note: count 0 is a legal parameter (verified in NT4)
1407//******************************************************************************
1408HDWP WIN32API BeginDeferWindowPos(int count)
1409{
1410 HDWP handle;
1411 DWP *pDWP;
1412
1413 if (count < 0)
1414 {
1415 dprintf(("USER32: BeginDeferWindowPos invalid param %d", count));
1416 SetLastError(ERROR_INVALID_PARAMETER);
1417 return 0;
1418 }
1419 dprintf(("USER32: BeginDeferWindowPos %d", count));
1420 if(count == 0)
1421 count = 8; // change to any non-zero value
1422
1423 handle = (HDWP)HeapAlloc(GetProcessHeap(), 0, sizeof(DWP) + (count-1)*sizeof(WINDOWPOS));
1424 if (!handle)
1425 return 0;
1426
1427 pDWP = (DWP *) handle;
1428 pDWP->actualCount = 0;
1429 pDWP->suggestedCount = count;
1430 pDWP->valid = TRUE;
1431 pDWP->wMagic = DWP_MAGIC;
1432 pDWP->hwndParent = 0;
1433 return handle;
1434}
1435/***********************************************************************
1436 * DeferWindowPos (USER32.128)
1437 *
1438 * TODO: SvL: Does this need to be thread safe?
1439 *
1440 */
1441HDWP WIN32API DeferWindowPos( HDWP hdwp, HWND hwnd, HWND hwndAfter,
1442 INT x, INT y, INT cx, INT cy,
1443 UINT flags )
1444{
1445 DWP *pDWP;
1446 int i;
1447 HDWP newhdwp = hdwp,retvalue;
1448
1449 pDWP = (DWP *)hdwp;
1450 if (!pDWP) {
1451 SetLastError(ERROR_INVALID_PARAMETER);
1452 return 0;
1453 }
1454
1455 if (hwnd == GetDesktopWindow())
1456 return 0;
1457
1458 if(!IsWindow(hwnd)) {
1459 dprintf(("DeferWindowPos, window %x not found", hwnd));
1460 SetLastError(ERROR_INVALID_WINDOW_HANDLE);
1461 HeapFree(GetProcessHeap(), 0, (LPVOID)hdwp);
1462 return 0;
1463 }
1464
1465 dprintf(("USER32: DeferWindowPos hdwp %x hwnd %x hwndAfter %x (%d,%d)(%d,%d) %x", hdwp, hwnd, hwndAfter,
1466 x, y, cx, cy, flags));
1467
1468/* Numega Bounds Checker Demo dislikes the following code.
1469 In fact, I've not been able to find any "same parent" requirement in any docu
1470 [AM 980509]
1471 */
1472#if 0
1473 /* All the windows of a DeferWindowPos() must have the same parent */
1474 parent = pWnd->parent->hwndSelf;
1475 if (pDWP->actualCount == 0) pDWP->hwndParent = parent;
1476 else if (parent != pDWP->hwndParent)
1477 {
1478 USER_HEAP_FREE( hdwp );
1479 retvalue = 0;
1480 goto END;
1481 }
1482#endif
1483
1484 for (i = 0; i < pDWP->actualCount; i++)
1485 {
1486 if (pDWP->winPos[i].hwnd == hwnd)
1487 {
1488 /* Merge with the other changes */
1489 if (!(flags & SWP_NOZORDER))
1490 {
1491 pDWP->winPos[i].hwndInsertAfter = hwndAfter;
1492 }
1493 if (!(flags & SWP_NOMOVE))
1494 {
1495 pDWP->winPos[i].x = x;
1496 pDWP->winPos[i].y = y;
1497 }
1498 if (!(flags & SWP_NOSIZE))
1499 {
1500 pDWP->winPos[i].cx = cx;
1501 pDWP->winPos[i].cy = cy;
1502 }
1503 pDWP->winPos[i].flags &= flags | ~(SWP_NOSIZE | SWP_NOMOVE |
1504 SWP_NOZORDER | SWP_NOREDRAW |
1505 SWP_NOACTIVATE | SWP_NOCOPYBITS|
1506 SWP_NOOWNERZORDER);
1507 pDWP->winPos[i].flags |= flags & (SWP_SHOWWINDOW | SWP_HIDEWINDOW |
1508 SWP_FRAMECHANGED);
1509 retvalue = hdwp;
1510 goto END;
1511 }
1512 }
1513 if (pDWP->actualCount >= pDWP->suggestedCount)
1514 {
1515 //DWP structure already contains WINDOWPOS, allocated with (count-1)
1516 //in BeginDeferWindowPos; pDWP->suggestedCount alloc increases it by one
1517 newhdwp = (HDWP)HeapReAlloc(GetProcessHeap(), 0, (LPVOID)hdwp,
1518 sizeof(DWP) + pDWP->suggestedCount*sizeof(WINDOWPOS));
1519 if (!newhdwp)
1520 {
1521 retvalue = 0;
1522 goto END;
1523 }
1524 pDWP = (DWP *) newhdwp;
1525 pDWP->suggestedCount++;
1526 }
1527 pDWP->winPos[pDWP->actualCount].hwnd = hwnd;
1528 pDWP->winPos[pDWP->actualCount].hwndInsertAfter = hwndAfter;
1529 pDWP->winPos[pDWP->actualCount].x = x;
1530 pDWP->winPos[pDWP->actualCount].y = y;
1531 pDWP->winPos[pDWP->actualCount].cx = cx;
1532 pDWP->winPos[pDWP->actualCount].cy = cy;
1533 pDWP->winPos[pDWP->actualCount].flags = flags;
1534 pDWP->actualCount++;
1535 retvalue = newhdwp;
1536END:
1537 return retvalue;
1538}
1539//******************************************************************************
1540//******************************************************************************
1541BOOL WIN32API EndDeferWindowPos( HDWP hdwp)
1542{
1543 DWP *pDWP;
1544 WINDOWPOS *winpos;
1545 BOOL res = TRUE;
1546 int i;
1547
1548 pDWP = (DWP *) hdwp;
1549 if (!pDWP) {
1550 dprintf(("**EndDeferWindowPos invalid parameter\n"));
1551 SetLastError(ERROR_INVALID_PARAMETER);
1552 return FALSE;
1553 }
1554 dprintf(("**EndDeferWindowPos for %d windows", pDWP->actualCount));
1555 for (i = 0, winpos = pDWP->winPos; i < pDWP->actualCount; i++, winpos++)
1556 {
1557 dprintf(("**EndDeferWindowPos %x (%d,%d) (%d,%d) %x", winpos->hwnd, winpos->x, winpos->y, winpos->cx, winpos->cy, winpos->flags));
1558 if (!(res = SetWindowPos(winpos->hwnd, winpos->hwndInsertAfter,
1559 winpos->x, winpos->y, winpos->cx,
1560 winpos->cy, winpos->flags )))
1561 break;
1562 }
1563 dprintf(("**EndDeferWindowPos DONE"));
1564 HeapFree(GetProcessHeap(), 0, (LPVOID)hdwp);
1565 return res;
1566}
1567//******************************************************************************
1568//******************************************************************************
1569HWND WIN32API ChildWindowFromPoint( HWND hwnd, POINT pt)
1570{
1571 dprintf(("USER32: ChildWindowFromPoint\n"));
1572 return ChildWindowFromPointEx(hwnd, pt, 0);
1573}
1574/*****************************************************************************
1575 * Name : HWND WIN32API ChildWindowFromPointEx
1576 * Purpose : pt: client coordinates
1577 * Parameters:
1578 * Variables :
1579 * Result : If the function succeeds, the return value is the window handle.
1580 * If the function fails, the return value is zero
1581 * Remark :
1582 * Status : COMPLETELY IMPLEMENTED AND TESTED
1583 *
1584 * Author : Rene Pronk [Sun, 1999/08/08 23:30]
1585 *****************************************************************************/
1586HWND WIN32API ChildWindowFromPointEx (HWND hwndParent, POINT pt, UINT uFlags)
1587{
1588 RECT rect;
1589 HWND hWnd;
1590
1591 dprintf(("ChildWindowFromPointEx(%08xh,%08xh,%08xh).\n",
1592 hwndParent, pt, uFlags));
1593
1594 if (GetWindowRect (hwndParent, &rect) == 0) {
1595 // oops, invalid handle
1596 SetLastError(ERROR_INVALID_WINDOW_HANDLE);
1597 return NULL;
1598 }
1599
1600 ClientToScreen(hwndParent, &pt);
1601 if (PtInRect (&rect, pt) == 0) {
1602 // point is outside window
1603 return NULL;
1604 }
1605
1606 // get first child
1607 hWnd = GetWindow (hwndParent, GW_CHILD);
1608
1609 while (hWnd != NULL)
1610 {
1611 // do I need to skip this window?
1612 if (((uFlags & CWP_SKIPINVISIBLE) &&
1613 (IsWindowVisible (hWnd) == FALSE)) ||
1614 ((uFlags & CWP_SKIPDISABLED) &&
1615 (IsWindowEnabled (hWnd) == FALSE)) ||
1616 ((uFlags & CWP_SKIPTRANSPARENT) &&
1617 (GetWindowLongA (hWnd, GWL_EXSTYLE) & WS_EX_TRANSPARENT)))
1618 {
1619 hWnd = GetWindow (hWnd, GW_HWNDNEXT);
1620 continue;
1621 }
1622
1623 // is the point in this window's rect?
1624 GetWindowRect (hWnd, &rect);
1625 if (PtInRect (&rect,pt) == FALSE) {
1626 hWnd = GetWindow (hWnd, GW_HWNDNEXT);
1627 continue;
1628 }
1629
1630 dprintf(("ChildWindowFromPointEx returned %x", hWnd));
1631 // found it!
1632 return hWnd;
1633 }
1634 // the point is in the parentwindow but the parentwindow has no child
1635 // at this coordinate
1636 dprintf(("ChildWindowFromPointEx returned parent %x", hwndParent));
1637 return hwndParent;
1638}
1639//******************************************************************************
1640//******************************************************************************
1641BOOL WIN32API CloseWindow(HWND hwnd)
1642{
1643 Win32BaseWindow *window;
1644
1645 window = Win32BaseWindow::GetWindowFromHandle(hwnd);
1646 if(!window) {
1647 dprintf(("CloseWindow, window %x not found", hwnd));
1648 SetLastError(ERROR_INVALID_WINDOW_HANDLE);
1649 return 0;
1650 }
1651 dprintf(("CloseWindow %x\n", hwnd));
1652 BOOL ret = window->CloseWindow();
1653 RELEASE_WNDOBJ(window);
1654 return ret;
1655}
1656//******************************************************************************
1657//******************************************************************************
1658static BOOL IsPointInWindow(HWND hwnd, POINT point)
1659{
1660 RECT rectWindow;
1661 DWORD hittest, dwStyle, dwExStyle;
1662
1663 dwStyle = GetWindowLongA(hwnd, GWL_STYLE);
1664 dwExStyle = GetWindowLongA(hwnd, GWL_EXSTYLE);
1665
1666 GetWindowRect(hwnd, &rectWindow);
1667
1668 /* If point is in window, and window is visible, and it */
1669 /* is enabled (or it's a top-level window), then explore */
1670 /* its children. Otherwise, go to the next window. */
1671
1672 if( (dwStyle & WS_VISIBLE) &&
1673 ((dwExStyle & (WS_EX_LAYERED | WS_EX_TRANSPARENT)) != (WS_EX_LAYERED | WS_EX_TRANSPARENT)) &&
1674 (!(dwStyle & WS_DISABLED) || ((dwStyle & (WS_POPUP | WS_CHILD)) != WS_CHILD)) &&
1675 ((point.x >= rectWindow.left) && (point.x < rectWindow.right) &&
1676 (point.y >= rectWindow.top) && (point.y < rectWindow.bottom))
1677#if 1
1678 )
1679#else
1680 &&
1681 (wndPtr->hrgnWnd ? PtInRegion(wndPtr->hrgnWnd, 1))
1682#endif
1683 {
1684 hittest = SendMessageA(hwnd, WM_NCHITTEST, 0, MAKELONG(point.x, point.y));
1685 if(hittest != HTTRANSPARENT) {
1686 return TRUE;
1687 }
1688 }
1689 return FALSE;
1690}
1691//******************************************************************************
1692//TODO: Does this return handles of hidden or disabled windows?
1693//******************************************************************************
1694HWND WIN32API WindowFromPoint( POINT point)
1695{
1696 HWND hwndOS2, hwnd;
1697 POINT wPoint;
1698
1699 wPoint.x = point.x;
1700 wPoint.y = mapScreenY(point.y);
1701
1702 hwndOS2 = OSLibWinWindowFromPoint(OSLIB_HWND_DESKTOP, (PVOID)&wPoint);
1703 if(hwndOS2)
1704 {
1705 hwnd = OS2ToWin32Handle(hwndOS2);
1706 while(hwnd)
1707 {
1708 if(IsPointInWindow(hwnd, point)) {
1709 dprintf(("WindowFromPoint (%d,%d) %x->%x\n", point.x, point.y, hwndOS2, hwnd));
1710 return hwnd;
1711 }
1712#if 0
1713//TODO: breaks a lot of things
1714 hwnd = GetWindow(hwnd, GW_HWNDNEXT);
1715#else
1716 //try siblings
1717 HWND hwndSibling;
1718 HWND hwndParent = GetParent(hwnd);
1719
1720 if(hwndParent) {
1721 hwndSibling = GetWindow(hwndParent, GW_CHILD);
1722 while(hwndSibling) {
1723 if(hwndSibling != hwnd) {
1724 if(IsPointInWindow(hwndSibling, point)) {
1725 dprintf(("WindowFromPoint (%d,%d) %x->%x\n", point.x, point.y, hwndOS2, hwndSibling));
1726 return hwndSibling;
1727 }
1728 }
1729 hwndSibling = GetWindow(hwndSibling, GW_HWNDNEXT);
1730 }
1731 }
1732 hwnd = hwndParent;
1733#endif
1734 }
1735 }
1736 dprintf(("WindowFromPoint (%d,%d) %x->1\n", point.x, point.y, hwndOS2));
1737 return windowDesktop->getWindowHandle();
1738}
1739//******************************************************************************
1740//******************************************************************************
1741BOOL WIN32API IsWindowUnicode(HWND hwnd)
1742{
1743 Win32BaseWindow *window;
1744
1745 window = Win32BaseWindow::GetWindowFromHandle(hwnd);
1746 if(!window) {
1747 dprintf(("IsWindowUnicode, window %x not found", hwnd));
1748 SetLastError(ERROR_INVALID_WINDOW_HANDLE);
1749 return 0;
1750 }
1751 BOOL ret = window->IsWindowUnicode();
1752 RELEASE_WNDOBJ(window);
1753 return ret;
1754}
1755/***********************************************************************
1756 * SwitchToThisWindow (USER32.539)
1757 */
1758DWORD WINAPI SwitchToThisWindow( HWND hwnd, BOOL restore )
1759{
1760 return ShowWindow( hwnd, restore ? SW_RESTORE : SW_SHOWMINIMIZED );
1761}
1762//******************************************************************************
1763//******************************************************************************
1764BOOL WIN32API EnumThreadWindows(DWORD dwThreadId, WNDENUMPROC lpfn, LPARAM lParam)
1765{
1766 return windowDesktop->EnumThreadWindows(dwThreadId, lpfn, lParam);
1767}
1768//******************************************************************************
1769//******************************************************************************
1770BOOL WIN32API EnumChildWindows(HWND hwnd, WNDENUMPROC lpfn, LPARAM lParam)
1771{
1772 Win32BaseWindow *window;
1773 BOOL ret = TRUE;
1774 ULONG henum;
1775 HWND hwndNext;
1776
1777 if(lpfn == NULL) {
1778 dprintf(("EnumChildWindows invalid parameter %x %x\n", hwnd, lParam));
1779 SetLastError(ERROR_INVALID_PARAMETER);
1780 return FALSE;
1781 }
1782 window = Win32BaseWindow::GetWindowFromHandle(hwnd);
1783 if(!window) {
1784 dprintf(("EnumChildWindows, window %x not found", hwnd));
1785 SetLastError(ERROR_INVALID_WINDOW_HANDLE);
1786 return FALSE;
1787 }
1788 ret = window->EnumChildWindows(lpfn, lParam);
1789 RELEASE_WNDOBJ(window);
1790 return ret;
1791}
1792//******************************************************************************
1793//******************************************************************************
1794BOOL WIN32API EnumWindows(WNDENUMPROC lpfn, LPARAM lParam)
1795{
1796 return windowDesktop->EnumWindows(lpfn, lParam);
1797}
1798//******************************************************************************
1799//******************************************************************************
1800UINT WIN32API ArrangeIconicWindows( HWND parent)
1801{
1802 RECT rectParent;
1803 HWND hwndChild;
1804 INT x, y, xspacing, yspacing;
1805
1806 dprintf(("USER32: ArrangeIconicWindows %x", parent));
1807 dprintf(("USER32: TODO: icon title!!"));
1808
1809 GetClientRect(parent, &rectParent);
1810 x = rectParent.left;
1811 y = rectParent.bottom;
1812 xspacing = GetSystemMetrics(SM_CXICONSPACING);
1813 yspacing = GetSystemMetrics(SM_CYICONSPACING);
1814
1815 hwndChild = GetWindow( parent, GW_CHILD );
1816 while (hwndChild)
1817 {
1818 if( IsIconic( hwndChild ) )
1819 {
1820// WND *wndPtr = WIN_FindWndPtr(hwndChild);
1821
1822// WINPOS_ShowIconTitle( wndPtr, FALSE );
1823
1824 SetWindowPos( hwndChild, 0, x + (xspacing - GetSystemMetrics(SM_CXICON)) / 2,
1825 y - yspacing - GetSystemMetrics(SM_CYICON)/2, 0, 0,
1826 SWP_NOSIZE | SWP_NOZORDER | SWP_NOACTIVATE );
1827// if( IsWindow(hwndChild) )
1828// WINPOS_ShowIconTitle(wndPtr , TRUE );
1829// WIN_ReleaseWndPtr(wndPtr);
1830
1831 if (x <= rectParent.right - xspacing) x += xspacing;
1832 else
1833 {
1834 x = rectParent.left;
1835 y -= yspacing;
1836 }
1837 }
1838 hwndChild = GetWindow( hwndChild, GW_HWNDNEXT );
1839 }
1840 return yspacing;
1841}
1842//******************************************************************************
1843//restores iconized window to previous size/position
1844//******************************************************************************
1845BOOL WIN32API OpenIcon(HWND hwnd)
1846{
1847 dprintf(("USER32: OpenIcon %x", hwnd));
1848
1849 if(!IsIconic(hwnd))
1850 return FALSE;
1851 ShowWindow(hwnd, SW_SHOWNORMAL);
1852 return TRUE;
1853}
1854//******************************************************************************
1855//SDK: Windows can only be shown with ShowOwnedPopups if they were previously
1856// hidden with the same api
1857//TODO: -> needs testing
1858//******************************************************************************
1859BOOL WIN32API ShowOwnedPopups(HWND hwndOwner, BOOL fShow)
1860{
1861 Win32BaseWindow *window, *owner;
1862 HWND hwnd;
1863
1864 owner = Win32BaseWindow::GetWindowFromHandle(hwndOwner);
1865 if(!owner) {
1866 dprintf(("ShowOwnedPopups, window %x not found", hwndOwner));
1867 SetLastError(ERROR_INVALID_WINDOW_HANDLE);
1868 return FALSE;
1869 }
1870 dprintf(("USER32: ShowOwnedPopups %x %d", hwndOwner, fShow));
1871
1872 hwnd = GetWindow(GetDesktopWindow(), GW_CHILD);
1873 while(hwnd) {
1874 window = Win32BaseWindow::GetWindowFromHandle(hwnd);
1875 if(window) {
1876 if(window == owner && (window->getStyle() & WS_POPUP))
1877 {
1878 if(fShow) {
1879 if(window->getFlags() & WIN_NEEDS_SHOW_OWNEDPOPUP)
1880 {
1881 /*
1882 * In Windows, ShowOwnedPopups(TRUE) generates WM_SHOWWINDOW messages with SW_PARENTOPENING,
1883 * regardless of the state of the owner
1884 */
1885 SendMessageA(hwnd, WM_SHOWWINDOW, SW_SHOW, SW_PARENTOPENING);
1886 window->setFlags(window->getFlags() & ~WIN_NEEDS_SHOW_OWNEDPOPUP);
1887 }
1888 }
1889 else
1890 {
1891 if(IsWindowVisible(hwnd))
1892 {
1893 /*
1894 * In Windows, ShowOwnedPopups(FALSE) generates WM_SHOWWINDOW messages with SW_PARENTCLOSING,
1895 * regardless of the state of the owner
1896 */
1897 SendMessageA(hwnd, WM_SHOWWINDOW, SW_HIDE, SW_PARENTCLOSING);
1898 window->setFlags(window->getFlags() | WIN_NEEDS_SHOW_OWNEDPOPUP);
1899 }
1900 }
1901 }
1902 RELEASE_WNDOBJ(window);
1903 }
1904 else dprintf(("WARNING: window %x is not valid", hwnd));
1905
1906 hwnd = GetWindow(hwnd, GW_HWNDNEXT);
1907 }
1908 RELEASE_WNDOBJ(owner);
1909 return TRUE;
1910}
1911//******************************************************************************
1912//******************************************************************************
1913HWND WIN32API GetForegroundWindow()
1914{
1915 HWND hwnd;
1916
1917 hwnd = OS2ToWin32Handle(OSLibWinQueryActiveWindow());
1918 return hwnd;
1919}
1920//******************************************************************************
1921
1922/******************************************************************************
1923 * The return value identifies the most recently active pop-up window.
1924 * The return value is the same as the hWnd parameter, if any of the
1925 * following conditions are met:
1926 *
1927 * - The window identified by hWnd was most recently active.
1928 * - The window identified by hWnd does not own any pop-up windows.
1929 * - The window identified by hWnd is not a top-level window or it is
1930 * owned by another window.
1931 */
1932HWND WIN32API GetLastActivePopup(HWND hWnd)
1933{
1934 Win32BaseWindow *owner;
1935
1936 owner = Win32BaseWindow::GetWindowFromHandle(hWnd);
1937 if(!owner)
1938 {
1939 dprintf(("GetLastActivePopup, window %x not found", hWnd));
1940 SetLastError(ERROR_INVALID_WINDOW_HANDLE);
1941 return hWnd;
1942 }
1943
1944 HWND hwndRetVal = owner->getLastActive();
1945 if (!IsWindow( hwndRetVal ))
1946 hwndRetVal = owner->getWindowHandle();
1947
1948 RELEASE_WNDOBJ(owner);
1949
1950 return hwndRetVal;
1951}
1952//******************************************************************************
1953//******************************************************************************
1954DWORD WIN32API GetWindowThreadProcessId(HWND hwnd, PDWORD lpdwProcessId)
1955{
1956 Win32BaseWindow *window;
1957 DWORD dwThreadId;
1958
1959 window = Win32BaseWindow::GetWindowFromHandle(hwnd);
1960 if(!window) {
1961 dprintf(("GetWindowThreadProcessId, window %x not found", hwnd));
1962 SetLastError(ERROR_INVALID_WINDOW_HANDLE);
1963 return 0;
1964 }
1965 dwThreadId = window->getThreadId();
1966 if(lpdwProcessId) {
1967 *lpdwProcessId = window->getProcessId();
1968 }
1969 RELEASE_WNDOBJ(window);
1970
1971 return dwThreadId;
1972}
1973//******************************************************************************
1974//******************************************************************************
1975DWORD WIN32API GetWindowContextHelpId(HWND hwnd)
1976{
1977 Win32BaseWindow *window;
1978
1979 window = Win32BaseWindow::GetWindowFromHandle(hwnd);
1980 if(!window) {
1981 dprintf(("GetWindowContextHelpId, window %x not found", hwnd));
1982 SetLastError(ERROR_INVALID_WINDOW_HANDLE);
1983 return 0;
1984 }
1985 dprintf(("GetWindowContextHelpId %x", hwnd));
1986 DWORD ret = window->getWindowContextHelpId();
1987 RELEASE_WNDOBJ(window);
1988 return ret;
1989}
1990//******************************************************************************
1991//******************************************************************************
1992BOOL WIN32API SetWindowContextHelpId(HWND hwnd, DWORD dwContextHelpId)
1993{
1994 Win32BaseWindow *window;
1995
1996 window = Win32BaseWindow::GetWindowFromHandle(hwnd);
1997 if(!window) {
1998 dprintf(("SetWindowContextHelpId, window %x not found", hwnd));
1999 SetLastError(ERROR_INVALID_WINDOW_HANDLE);
2000 return 0;
2001 }
2002 dprintf(("SetWindowContextHelpId %x %d", hwnd, dwContextHelpId));
2003 window->setWindowContextHelpId(dwContextHelpId);
2004 RELEASE_WNDOBJ(window);
2005 return(TRUE);
2006}
2007//******************************************************************************
2008//******************************************************************************
2009HANDLE WIN32API GetPropA(HWND hwnd, LPCSTR str )
2010{
2011 Win32BaseWindow *window;
2012
2013 window = Win32BaseWindow::GetWindowFromHandle(hwnd);
2014 if(!window) {
2015 dprintf(("GetPropA, window %x not found", hwnd));
2016 SetLastError(ERROR_INVALID_WINDOW_HANDLE);
2017 return 0;
2018 }
2019 HANDLE ret = window->getProp(str);
2020 RELEASE_WNDOBJ(window);
2021 return ret;
2022}
2023//******************************************************************************
2024//******************************************************************************
2025HANDLE WIN32API GetPropW(HWND hwnd, LPCWSTR str)
2026{
2027 Win32BaseWindow *window;
2028 LPSTR strA;
2029 HANDLE ret;
2030
2031 window = Win32BaseWindow::GetWindowFromHandle(hwnd);
2032 if(!window) {
2033 dprintf(("GetPropW, window %x not found", hwnd));
2034 SetLastError(ERROR_INVALID_WINDOW_HANDLE);
2035 return 0;
2036 }
2037
2038 if(HIWORD(str)) {
2039 strA = HEAP_strdupWtoA( GetProcessHeap(), 0, str );
2040 }
2041 else strA = (LPSTR)str;
2042
2043 ret = window->getProp(strA);
2044
2045 RELEASE_WNDOBJ(window);
2046 if(HIWORD(str)) HeapFree( GetProcessHeap(), 0, strA );
2047 return ret;
2048}
2049//******************************************************************************
2050//******************************************************************************
2051BOOL WIN32API SetPropA(HWND hwnd, LPCSTR str, HANDLE handle )
2052{
2053 Win32BaseWindow *window;
2054
2055 window = Win32BaseWindow::GetWindowFromHandle(hwnd);
2056 if(!window) {
2057 dprintf(("SetPropA, window %x not found", hwnd));
2058 SetLastError(ERROR_INVALID_WINDOW_HANDLE);
2059 return FALSE;
2060 }
2061 BOOL ret = window->setProp(str, handle);
2062 RELEASE_WNDOBJ(window);
2063 return ret;
2064}
2065//******************************************************************************
2066//******************************************************************************
2067BOOL SetPropW(HWND hwnd, LPCWSTR str, HANDLE handle )
2068{
2069 BOOL ret;
2070 LPSTR strA;
2071
2072 if (!HIWORD(str))
2073 return SetPropA( hwnd, (LPCSTR)(UINT)LOWORD(str), handle );
2074 strA = HEAP_strdupWtoA( GetProcessHeap(), 0, str );
2075 ret = SetPropA( hwnd, strA, handle );
2076 HeapFree( GetProcessHeap(), 0, strA );
2077 return ret;
2078}
2079//******************************************************************************
2080//******************************************************************************
2081HANDLE WIN32API RemovePropA(HWND hwnd, LPCSTR str)
2082{
2083 Win32BaseWindow *window;
2084
2085 window = Win32BaseWindow::GetWindowFromHandle(hwnd);
2086 if(!window) {
2087 dprintf(("RemovePropA, window %x not found", hwnd));
2088 SetLastError(ERROR_INVALID_WINDOW_HANDLE);
2089 return 0;
2090 }
2091 HANDLE ret = window->removeProp(str);
2092 RELEASE_WNDOBJ(window);
2093 return ret;
2094}
2095//******************************************************************************
2096//******************************************************************************
2097HANDLE WIN32API RemovePropW(HWND hwnd, LPCWSTR str)
2098{
2099 LPSTR strA;
2100 HANDLE ret;
2101
2102 if (!HIWORD(str))
2103 return RemovePropA( hwnd, (LPCSTR)(UINT)LOWORD(str) );
2104 strA = HEAP_strdupWtoA( GetProcessHeap(), 0, str );
2105 ret = RemovePropA( hwnd, strA );
2106 HeapFree( GetProcessHeap(), 0, strA );
2107 return ret;
2108}
2109//******************************************************************************
2110//******************************************************************************
2111INT WIN32API EnumPropsA(HWND hwnd, PROPENUMPROCA func )
2112{
2113 return EnumPropsExA( hwnd, (PROPENUMPROCEXA)func, 0 );
2114}
2115//******************************************************************************
2116//******************************************************************************
2117INT WIN32API EnumPropsW(HWND hwnd, PROPENUMPROCW func )
2118{
2119 return EnumPropsExW( hwnd, (PROPENUMPROCEXW)func, 0 );
2120}
2121//******************************************************************************
2122//******************************************************************************
2123INT WIN32API EnumPropsExA(HWND hwnd, PROPENUMPROCEXA func, LPARAM lParam)
2124{
2125 Win32BaseWindow *window;
2126
2127 window = Win32BaseWindow::GetWindowFromHandle(hwnd);
2128 if(!window) {
2129 dprintf(("EnumPropsExA, window %x not found", hwnd));
2130 SetLastError(ERROR_INVALID_WINDOW_HANDLE);
2131 return -1;
2132 }
2133 INT ret = window->enumPropsExA(func, lParam);
2134 RELEASE_WNDOBJ(window);
2135 return ret;
2136}
2137//******************************************************************************
2138//******************************************************************************
2139INT WIN32API EnumPropsExW(HWND hwnd, PROPENUMPROCEXW func, LPARAM lParam)
2140{
2141 Win32BaseWindow *window;
2142
2143 window = Win32BaseWindow::GetWindowFromHandle(hwnd);
2144 if(!window) {
2145 dprintf(("EnumPropsExA, window %x not found", hwnd));
2146 SetLastError(ERROR_INVALID_WINDOW_HANDLE);
2147 return -1;
2148 }
2149 INT ret = window->enumPropsExW(func, lParam);
2150 RELEASE_WNDOBJ(window);
2151 return ret;
2152}
2153//******************************************************************************
2154//******************************************************************************
2155
2156
2157/*****************************************************************************
2158 * Name : BOOL WIN32API AnyPopup
2159 * Purpose : The AnyPopup function indicates whether an owned, visible,
2160 * top-level pop-up, or overlapped window exists on the screen. The
2161 * function searches the entire Windows screen, not just the calling
2162 * application's client area.
2163 * Parameters: VOID
2164 * Variables :
2165 * Result : If a pop-up window exists, the return value is TRUE even if the
2166 * pop-up window is completely covered by other windows. Otherwise,
2167 * it is FALSE.
2168 * Remark : AnyPopup is a Windows version 1.x function and is retained for
2169 * compatibility purposes. It is generally not useful.
2170 * Status : UNTESTED STUB
2171 *
2172 * Author : Patrick Haller [Thu, 1998/02/26 11:55]
2173 *****************************************************************************/
2174BOOL WIN32API AnyPopup()
2175{
2176 dprintf(("USER32:AnyPopup() not implemented.\n"));
2177
2178 return (FALSE);
2179}
Note: See TracBrowser for help on using the repository browser.