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

Last change on this file since 4211 was 4211, checked in by phaller, 25 years ago

FS: corruption suspected in GetWindow

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