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

Last change on this file since 4460 was 4460, checked in by sandervl, 25 years ago

AdjustWindowRectEx fix for scrollbars

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