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

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

Fixed behaviour of SetFocus(NULL)

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