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

Last change on this file since 6751 was 6751, checked in by sandervl, 24 years ago

GetLastActivePopup update + DIALOG_IsAccelerator fix

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