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

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

Set/GetParent changes/fixes

File size: 60.1 KB
Line 
1/* $Id: window.cpp,v 1.69 2000-06-07 21:45:52 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
402 window = Win32BaseWindow::GetWindowFromHandle(hwnd);
403 if(!window) {
404 dprintf(("GetTopWindow, window %x not found", hwnd));
405 SetLastError(ERROR_INVALID_WINDOW_HANDLE);
406 return 0;
407 }
408 return window->GetTopWindow();
409}
410//******************************************************************************
411//******************************************************************************
412BOOL WIN32API IsIconic( HWND hwnd)
413{
414 Win32BaseWindow *window;
415 BOOL rc;
416
417 window = Win32BaseWindow::GetWindowFromHandle(hwnd);
418 if(!window) {
419 dprintf(("IsIconic, window %x not found", hwnd));
420 SetLastError(ERROR_INVALID_WINDOW_HANDLE);
421 return FALSE;
422 }
423 rc = window->IsWindowIconic();
424 dprintf(("IsIconic %x returned %d", hwnd, rc));
425 return rc;
426}
427//******************************************************************************
428//******************************************************************************
429HWND WIN32API GetWindow(HWND hwnd, UINT uCmd)
430{
431 Win32BaseWindow *window;
432 HWND rc;
433
434 window = Win32BaseWindow::GetWindowFromHandle(hwnd);
435 if(!window) {
436 dprintf(("GetWindow, window %x not found", hwnd));
437 SetLastError(ERROR_INVALID_WINDOW_HANDLE);
438 return 0;
439 }
440 rc = window->GetWindow(uCmd);
441 return rc;
442}
443//******************************************************************************
444//******************************************************************************
445BOOL WIN32API EnableWindow( HWND hwnd, BOOL fEnable)
446{
447 Win32BaseWindow *window;
448
449 window = Win32BaseWindow::GetWindowFromHandle(hwnd);
450 if(!window) {
451 dprintf(("EnableWindow, window %x not found", hwnd));
452 SetLastError(ERROR_INVALID_WINDOW_HANDLE);
453 return 0;
454 }
455 dprintf(("EnableWindow %x %d", hwnd, fEnable));
456 return window->EnableWindow(fEnable);
457}
458//******************************************************************************
459//******************************************************************************
460BOOL WIN32API BringWindowToTop(HWND hwnd)
461{
462 return SetWindowPos( hwnd, HWND_TOP, 0, 0, 0, 0, SWP_NOMOVE|SWP_NOSIZE );
463}
464/***********************************************************************
465 * SetInternalWindowPos (USER32.483)
466 */
467void WIN32API SetInternalWindowPos(HWND hwnd,
468 UINT showCmd,
469 LPRECT lpRect,
470 LPPOINT lpPoint )
471{
472 dprintf(("USER32: SetInternalWindowPos(%08xh,%08xh,%08xh,%08xh)",
473 hwnd, showCmd, lpRect, lpPoint));
474
475 if( IsWindow(hwnd) )
476 {
477 WINDOWPLACEMENT wndpl;
478 UINT flags;
479
480 GetWindowPlacement(hwnd, &wndpl);
481 wndpl.length = sizeof(wndpl);
482 wndpl.showCmd = showCmd;
483 wndpl.flags = 0;
484
485 if(lpPoint)
486 {
487 wndpl.flags |= WPF_SETMINPOSITION;
488 wndpl.ptMinPosition = *lpPoint;
489 }
490 if(lpRect)
491 {
492 wndpl.rcNormalPosition = *lpRect;
493 }
494 SetWindowPlacement( hwnd, &wndpl);
495 }
496
497}
498/***********************************************************************
499 * GetInternalWindowPos (USER32.245)
500 */
501UINT WIN32API GetInternalWindowPos(HWND hwnd,
502 LPRECT rectWnd,
503 LPPOINT ptIcon )
504{
505 WINDOWPLACEMENT wndpl;
506
507 dprintf(("USER32: GetInternalWindowPos(%08xh,%08xh,%08xh)\n",
508 hwnd,
509 rectWnd,
510 ptIcon));
511
512 if(GetWindowPlacement( hwnd, &wndpl ))
513 {
514 if (rectWnd) *rectWnd = wndpl.rcNormalPosition;
515 if (ptIcon) *ptIcon = wndpl.ptMinPosition;
516 return wndpl.showCmd;
517 }
518 return 0;
519}
520//******************************************************************************
521//******************************************************************************
522HWND WIN32API GetActiveWindow()
523{
524 return Win32BaseWindow::GetActiveWindow();
525}
526//******************************************************************************
527//******************************************************************************
528BOOL WIN32API ShowWindow(HWND hwnd, int nCmdShow)
529{
530 Win32BaseWindow *window;
531
532 window = Win32BaseWindow::GetWindowFromHandle(hwnd);
533 if(!window) {
534 dprintf(("ShowWindow, window %x not found", hwnd));
535 SetLastError(ERROR_INVALID_WINDOW_HANDLE);
536 return 0;
537 }
538 return window->ShowWindow(nCmdShow);
539}
540/*****************************************************************************
541 * Name : BOOL WIN32API ShowWindowAsync
542 * Purpose : The ShowWindowAsync function sets the show state of a window
543 * created by a different thread.
544 * Parameters: HWND hwnd handle of window
545 * int nCmdShow show state of window
546 * Variables :
547 * Result : If the window was previously visible, the return value is TRUE.
548 * If the window was previously hidden, the return value is FALSE.
549 * Remark :
550 * Status : UNTESTED STUB
551 *
552 * Author : Patrick Haller [Thu, 1998/02/26 11:55]
553 *****************************************************************************/
554BOOL WIN32API ShowWindowAsync (HWND hwnd,
555 int nCmdShow)
556{
557 dprintf(("USER32:ShowWindowAsync (%08xh,%08x) not correctly implemented.\n",
558 hwnd,
559 nCmdShow));
560
561 return ShowWindow(hwnd, nCmdShow);
562}
563//******************************************************************************
564//******************************************************************************
565BOOL WIN32API SetWindowPos(HWND hwnd, HWND hwndInsertAfter, int x, int y, int cx, int cy, UINT fuFlags)
566{
567 Win32BaseWindow *window;
568
569 if (!hwnd)
570 {
571 dprintf(("SetWindowPos: Can't move desktop!"));
572 return TRUE;
573 }
574 window = Win32BaseWindow::GetWindowFromHandle(hwnd);
575 if(!window) {
576 dprintf(("SetWindowPos, window %x not found", hwnd));
577 SetLastError(ERROR_INVALID_WINDOW_HANDLE);
578 return FALSE;
579 }
580 dprintf(("SetWindowPos %x %x x=%d y=%d cx=%d cy=%d %x", hwnd, hwndInsertAfter, x, y, cx, cy, fuFlags));
581 return window->SetWindowPos(hwndInsertAfter, x, y, cx, cy, fuFlags);
582}
583//******************************************************************************
584//******************************************************************************
585BOOL WIN32API SetWindowPlacement(HWND hwnd, const WINDOWPLACEMENT *winpos)
586{
587 Win32BaseWindow *window;
588
589 window = Win32BaseWindow::GetWindowFromHandle(hwnd);
590 if(!window) {
591 dprintf(("SetWindowPlacement, window %x not found", hwnd));
592 SetLastError(ERROR_INVALID_WINDOW_HANDLE);
593 return FALSE;
594 }
595 if(!winpos) {
596 dprintf(("SetWindowPlacement %x invalid parameter", hwnd));
597 SetLastError(ERROR_INVALID_PARAMETER);
598 return FALSE;
599 }
600 dprintf(("USER32: SetWindowPlacement %x %x", hwnd, winpos));
601 return window->SetWindowPlacement((WINDOWPLACEMENT *)winpos);
602}
603//******************************************************************************
604//******************************************************************************
605BOOL WIN32API GetWindowPlacement(HWND hwnd, LPWINDOWPLACEMENT winpos)
606{
607 Win32BaseWindow *window;
608
609 window = Win32BaseWindow::GetWindowFromHandle(hwnd);
610 if(!window) {
611 dprintf(("GetWindowPlacement, window %x not found", hwnd));
612 SetLastError(ERROR_INVALID_WINDOW_HANDLE);
613 return FALSE;
614 }
615 if(!winpos) {
616 dprintf(("GetWindowPlacement %x invalid parameter", hwnd));
617 SetLastError(ERROR_INVALID_PARAMETER);
618 return FALSE;
619 }
620 dprintf(("USER32: GetWindowPlacement %x %x", hwnd, winpos));
621 return window->GetWindowPlacement(winpos);
622}
623//******************************************************************************
624//******************************************************************************
625BOOL WIN32API IsWindow( HWND hwnd)
626{
627 Win32BaseWindow *window;
628
629 window = Win32BaseWindow::GetWindowFromHandle(hwnd);
630 if(!window) {
631 dprintf(("IsWindow, window %x not found", hwnd));
632 SetLastError(ERROR_INVALID_WINDOW_HANDLE);
633 return FALSE;
634 }
635 dprintf(("IsWindow %x", hwnd));
636 return window->IsWindow();
637}
638//******************************************************************************
639//******************************************************************************
640BOOL WIN32API IsWindowEnabled( HWND hwnd)
641{
642 Win32BaseWindow *window;
643
644 window = Win32BaseWindow::GetWindowFromHandle(hwnd);
645 if(!window) {
646 dprintf(("IsWindowEnabled, window %x not found", hwnd));
647 SetLastError(ERROR_INVALID_WINDOW_HANDLE);
648 return 0;
649 }
650 dprintf(("IsWindowEnabled %x", hwnd));
651 return window->IsWindowEnabled();
652}
653//******************************************************************************
654//******************************************************************************
655BOOL WIN32API IsWindowVisible( HWND hwnd)
656{
657 Win32BaseWindow *window;
658 BOOL rc;
659
660 if (hwnd)
661 window = Win32BaseWindow::GetWindowFromHandle(hwnd);
662 else
663 window = windowDesktop;
664 if(!window) {
665 dprintf(("IsWindowVisible, window %x not found", hwnd));
666 SetLastError(ERROR_INVALID_WINDOW_HANDLE);
667 return 0;
668 }
669 rc = window->IsWindowVisible();
670 dprintf(("IsWindowVisible %x returned %d", hwnd, rc));
671 return rc;
672}
673//******************************************************************************
674//******************************************************************************
675HWND WIN32API SetFocus (HWND hwnd)
676{
677 HWND lastFocus, lastFocus_W, hwnd_O;
678 BOOL activate;
679
680 hwnd_O = Win32BaseWindow::Win32ToOS2Handle (hwnd);
681 lastFocus = OSLibWinQueryFocus (OSLIB_HWND_DESKTOP);
682 activate = ((hwnd_O == lastFocus) || OSLibWinIsChild (lastFocus, hwnd_O));
683 lastFocus_W = Win32BaseWindow::OS2ToWin32Handle (lastFocus);
684
685 dprintf(("SetFocus %x (%x) -> %x (%x)\n", lastFocus_W, lastFocus, hwnd, hwnd_O));
686
687 return (OSLibWinSetFocus (OSLIB_HWND_DESKTOP, hwnd_O, activate)) ? lastFocus_W : 0;
688}
689//******************************************************************************
690//******************************************************************************
691HWND WIN32API GetFocus(void)
692{
693 HWND hwnd;
694
695 hwnd = OSLibWinQueryFocus(OSLIB_HWND_DESKTOP);
696 hwnd = Win32BaseWindow::OS2ToWin32Handle(hwnd);
697 dprintf(("USER32: GetFocus %x\n", hwnd));
698 return hwnd;
699}
700//******************************************************************************
701//******************************************************************************
702BOOL WIN32API IsZoomed(HWND hwnd)
703{
704 dprintf(("USER32: IsZoomed\n"));
705 return O32_IsZoomed(Win32BaseWindow::Win32ToOS2Handle(hwnd));
706}
707//******************************************************************************
708//******************************************************************************
709BOOL WIN32API LockWindowUpdate(HWND hwnd)
710{
711 dprintf(("USER32: LockWindowUpdate\n"));
712 return O32_LockWindowUpdate(Win32BaseWindow::Win32ToOS2Handle(hwnd));
713}
714//******************************************************************************
715//******************************************************************************
716BOOL WIN32API GetWindowRect( HWND hwnd, PRECT pRect)
717{
718 Win32BaseWindow *window;
719
720 if (hwnd)
721 window = Win32BaseWindow::GetWindowFromHandle(hwnd);
722 else
723 window = windowDesktop;
724
725 if(!window) {
726 dprintf(("GetWindowRect, window %x not found", hwnd));
727 SetLastError(ERROR_INVALID_WINDOW_HANDLE);
728 return FALSE;
729 }
730 if(pRect == NULL) {
731 SetLastError(ERROR_INVALID_PARAMETER);
732 return FALSE;
733 }
734 *pRect = *window->getWindowRect();
735
736 //convert from parent coordinates to screen (if necessary)
737 if(window->getParent()) {
738 MapWindowPoints(window->getParent()->getWindowHandle(), 0, (PPOINT)pRect, 2);
739 }
740
741 dprintf(("GetWindowRect %x (%d,%d) (%d,%d)", hwnd, pRect->left, pRect->top, pRect->right, pRect->bottom));
742 return TRUE;
743}
744//******************************************************************************
745//******************************************************************************
746int WIN32API GetWindowTextLengthA( HWND hwnd)
747{
748 Win32BaseWindow *window;
749
750 window = Win32BaseWindow::GetWindowFromHandle(hwnd);
751 if(!window) {
752 dprintf(("GetWindowTextLength, window %x not found", hwnd));
753 SetLastError(ERROR_INVALID_WINDOW_HANDLE);
754 return 0;
755 }
756 dprintf(("GetWindowTextLength %x", hwnd));
757 return window->GetWindowTextLength();
758}
759//******************************************************************************
760//******************************************************************************
761int WIN32API GetWindowTextA( HWND hwnd, LPSTR lpsz, int cch)
762{
763 Win32BaseWindow *window;
764 int rc;
765
766 window = Win32BaseWindow::GetWindowFromHandle(hwnd);
767 if(!window) {
768 dprintf(("GetWindowTextA, window %x not found", hwnd));
769 SetLastError(ERROR_INVALID_WINDOW_HANDLE);
770 return 0;
771 }
772 rc = window->GetWindowTextA(lpsz, cch);
773 dprintf(("GetWindowTextA %x %s", hwnd, lpsz));
774 return rc;
775}
776//******************************************************************************
777//******************************************************************************
778int WIN32API GetWindowTextLengthW( HWND hwnd)
779{
780 dprintf(("USER32: GetWindowTextLengthW\n"));
781 return GetWindowTextLengthA(hwnd);
782}
783//******************************************************************************
784//******************************************************************************
785int WIN32API GetWindowTextW(HWND hwnd, LPWSTR lpsz, int cch)
786{
787 Win32BaseWindow *window;
788
789 window = Win32BaseWindow::GetWindowFromHandle(hwnd);
790 if(!window) {
791 dprintf(("GetWindowTextW, window %x not found", hwnd));
792 SetLastError(ERROR_INVALID_WINDOW_HANDLE);
793 return 0;
794 }
795 dprintf(("GetWindowTextW %x", hwnd));
796 return window->GetWindowTextW(lpsz, cch);
797}
798//******************************************************************************
799//******************************************************************************
800BOOL WIN32API SetWindowTextA(HWND hwnd, LPCSTR lpsz)
801{
802 Win32BaseWindow *window;
803
804 window = Win32BaseWindow::GetWindowFromHandle(hwnd);
805 if(!window) {
806 dprintf(("SetWindowTextA, window %x not found", hwnd));
807 SetLastError(ERROR_INVALID_WINDOW_HANDLE);
808 return 0;
809 }
810 dprintf(("SetWindowTextA %x %s", hwnd, lpsz));
811 return window->SetWindowTextA((LPSTR)lpsz);
812}
813//******************************************************************************
814//******************************************************************************
815BOOL WIN32API SetWindowTextW( HWND hwnd, LPCWSTR lpsz)
816{
817 Win32BaseWindow *window;
818
819 window = Win32BaseWindow::GetWindowFromHandle(hwnd);
820 if(!window) {
821 dprintf(("SetWindowTextA, window %x not found", hwnd));
822 SetLastError(ERROR_INVALID_WINDOW_HANDLE);
823 return 0;
824 }
825 dprintf(("SetWindowTextW %x", hwnd));
826 return window->SetWindowTextW((LPWSTR)lpsz);
827}
828/*******************************************************************
829 * InternalGetWindowText (USER32.326)
830 */
831int WIN32API InternalGetWindowText(HWND hwnd,
832 LPWSTR lpString,
833 INT nMaxCount )
834{
835 dprintf(("USER32: InternalGetWindowText(%08xh,%08xh,%08xh) not properly implemented.\n",
836 hwnd,
837 lpString,
838 nMaxCount));
839
840 return GetWindowTextW(hwnd,lpString,nMaxCount);
841}
842//******************************************************************************
843//TODO: Correct?
844//******************************************************************************
845BOOL WIN32API SetForegroundWindow(HWND hwnd)
846{
847 dprintf((" SetForegroundWindow %x", hwnd));
848
849 return SetWindowPos( hwnd, HWND_TOP, 0, 0, 0, 0, SWP_NOMOVE | SWP_NOSIZE);
850}
851//******************************************************************************
852//******************************************************************************
853BOOL WIN32API GetClientRect( HWND hwnd, PRECT pRect)
854{
855 HWND hwndWin32 = hwnd;
856 Win32BaseWindow *window;
857
858 if (!pRect)
859 {
860 SetLastError(ERROR_INVALID_PARAMETER);
861 return FALSE;
862 }
863 window = Win32BaseWindow::GetWindowFromHandle(hwnd);
864 if(!window) {
865 dprintf(("GetClientRect, window %x not found", hwnd));
866 SetLastError(ERROR_INVALID_WINDOW_HANDLE);
867 return FALSE;
868 }
869 window->getClientRect(pRect);
870 dprintf(("GetClientRect of %X returned (%d,%d) (%d,%d)\n", hwndWin32, pRect->left, pRect->top, pRect->right, pRect->bottom));
871 return TRUE;
872}
873//******************************************************************************
874//******************************************************************************
875BOOL WIN32API AdjustWindowRect(PRECT rect, DWORD style, BOOL menu)
876{
877 return AdjustWindowRectEx(rect, style, menu, 0);
878}
879//******************************************************************************
880//******************************************************************************
881BOOL WIN32API AdjustWindowRectEx( PRECT rect, DWORD style, BOOL menu, DWORD exStyle)
882{
883 dprintf(("AdjustWindowRectEx %x %x %d (%d,%d)(%d,%d)\n", style, exStyle, menu, rect->left, rect->top, rect->right, rect->bottom));
884
885 if(style == 0 && menu == FALSE && exStyle == 0) {
886 return TRUE; //nothing needs to be changed (VERIFIED in NT 4)
887 }
888 /* Correct the window style */
889 if (!(style & (WS_POPUP | WS_CHILD))) /* Overlapped window */
890 style |= WS_CAPTION;
891
892 //SvL: Include WS_POPUP -> otherwise HAS_THINFRAME is true for popup windows
893 // Also include WS_CHILD -> otherwise HAS_THICKFRAME doesn't work correctly
894 style &= (WS_DLGFRAME | WS_BORDER | WS_THICKFRAME | WS_CHILD | WS_VSCROLL | WS_HSCROLL | WS_POPUP);
895 exStyle &= (WS_EX_DLGMODALFRAME | WS_EX_CLIENTEDGE | WS_EX_STATICEDGE | WS_EX_TOOLWINDOW);
896 if (exStyle & WS_EX_DLGMODALFRAME) style &= ~WS_THICKFRAME;
897
898 //Adjust rect outer (Win32BaseWindow::AdjustRectOuter)
899 if (HAS_THICKFRAME(style,exStyle))
900 InflateRect( rect, GetSystemMetrics(SM_CXFRAME), GetSystemMetrics(SM_CYFRAME) );
901 else
902 if (HAS_DLGFRAME(style,exStyle))
903 InflateRect(rect, GetSystemMetrics(SM_CXDLGFRAME), GetSystemMetrics(SM_CYDLGFRAME) );
904 else
905 if (HAS_THINFRAME(style))
906 InflateRect( rect, GetSystemMetrics(SM_CXBORDER), GetSystemMetrics(SM_CYBORDER));
907
908 if ((style & WS_CAPTION) == WS_CAPTION)
909 {
910 if (exStyle & WS_EX_TOOLWINDOW)
911 rect->top -= GetSystemMetrics(SM_CYSMCAPTION);
912 else
913 rect->top -= GetSystemMetrics(SM_CYCAPTION);
914 }
915
916 if (menu)
917 rect->top -= GetSystemMetrics(SM_CYMENU);
918
919 //Adjust rect inner (Win32BaseWindow::AdjustRectInner)
920 if (exStyle & WS_EX_CLIENTEDGE)
921 InflateRect (rect, GetSystemMetrics(SM_CXEDGE), GetSystemMetrics(SM_CYEDGE));
922
923 if (exStyle & WS_EX_STATICEDGE)
924 InflateRect (rect, GetSystemMetrics(SM_CXBORDER), GetSystemMetrics(SM_CYBORDER));
925
926 if (style & WS_VSCROLL) rect->right += GetSystemMetrics(SM_CXVSCROLL);
927 if (style & WS_HSCROLL) rect->bottom += GetSystemMetrics(SM_CYHSCROLL);
928
929 dprintf(("AdjustWindowRectEx returned (%d,%d)(%d,%d)\n", rect->left, rect->top, rect->right, rect->bottom));
930
931 return TRUE;
932}
933//******************************************************************************
934/* Coordinate Space and Transformation Functions */
935//******************************************************************************
936/*******************************************************************
937 * WINPOS_GetWinOffset
938 *
939 * Calculate the offset between the origin of the two windows. Used
940 * to implement MapWindowPoints.
941 */
942static void WINPOS_GetWinOffset( Win32BaseWindow *wndFrom, Win32BaseWindow *wndTo,
943 POINT *offset )
944{
945 Win32BaseWindow *window;
946
947 offset->x = offset->y = 0;
948
949 /* Translate source window origin to screen coords */
950 if(wndFrom != windowDesktop)
951 {
952 window = wndFrom;
953 while(window)
954 {
955 offset->x += window->getClientRectPtr()->left + window->getWindowRect()->left;
956 offset->y += window->getClientRectPtr()->top + window->getWindowRect()->top;
957 window = window->getParent();
958 }
959 }
960
961 /* Translate origin to destination window coords */
962 if(wndTo != windowDesktop)
963 {
964 window = wndTo;
965 while(window)
966 {
967 offset->x -= window->getClientRectPtr()->left + window->getWindowRect()->left;
968 offset->y -= window->getClientRectPtr()->top + window->getWindowRect()->top;
969 window = window->getParent();
970 }
971 }
972}
973//******************************************************************************
974//******************************************************************************
975int WIN32API MapWindowPoints(HWND hwndFrom, HWND hwndTo, LPPOINT lpPoints,
976 UINT cPoints)
977{
978 Win32BaseWindow *wndfrom, *wndto;
979 int retval = 0;
980 POINT offset;
981
982 SetLastError(0);
983 if(lpPoints == NULL || cPoints == 0) {
984 SetLastError(ERROR_INVALID_PARAMETER);
985 return 0;
986 }
987 if(hwndFrom)
988 {
989 wndfrom = Win32BaseWindow::GetWindowFromHandle(hwndFrom);
990 if(!wndfrom) {
991 dprintf(("MapWindowPoints, window %x not found", hwndFrom));
992 SetLastError(ERROR_INVALID_WINDOW_HANDLE);
993 return 0;
994 }
995 }
996 else wndfrom = windowDesktop;
997
998 if(hwndTo)
999 {
1000 wndto = Win32BaseWindow::GetWindowFromHandle(hwndTo);
1001 if(!wndto) {
1002 dprintf(("MapWindowPoints, window %x not found", hwndTo));
1003 SetLastError(ERROR_INVALID_WINDOW_HANDLE);
1004 return 0;
1005 }
1006 }
1007 else wndto = windowDesktop;
1008
1009 if(wndto == wndfrom)
1010 return 0; //nothing to do
1011
1012 dprintf2(("USER32: MapWindowPoints %x to %x (%d,%d) (%d)", hwndFrom, hwndTo, lpPoints->x, lpPoints->y, cPoints));
1013 WINPOS_GetWinOffset(wndfrom, wndto, &offset);
1014
1015 for(int i=0;i<cPoints;i++)
1016 {
1017 lpPoints[i].x += offset.x;
1018 lpPoints[i].y += offset.y;
1019 }
1020 retval = ((LONG)offset.y << 16) | offset.x;
1021 return retval;
1022}
1023//******************************************************************************
1024//******************************************************************************
1025BOOL WIN32API ScreenToClient(HWND hwnd, LPPOINT pt)
1026{
1027 Win32BaseWindow *wnd;
1028 PRECT rcl;
1029 BOOL rc;
1030
1031 if(!hwnd) {
1032 return (TRUE);
1033 }
1034 wnd = Win32BaseWindow::GetWindowFromHandle (hwnd);
1035 if (!wnd) {
1036 dprintf(("warning: ScreenToClient: window %x not found!", hwnd));
1037 SetLastError(ERROR_INVALID_WINDOW_HANDLE);
1038 return FALSE;
1039 }
1040 SetLastError(0);
1041#ifdef DEBUG
1042 POINT tmp = *pt;
1043#endif
1044 MapWindowPoints(0, hwnd, pt, 1);
1045 dprintf2(("ScreenToClient %x (%d,%d) -> (%d,%d)", hwnd, tmp.x, tmp.y, pt->x, pt->y));
1046 return TRUE;
1047}
1048//******************************************************************************
1049//******************************************************************************
1050HWND WIN32API GetDesktopWindow(void)
1051{
1052 HWND DesktopWindow = windowDesktop->getWindowHandle();
1053 dprintf2(("USER32: GetDesktopWindow, returned %x\n", DesktopWindow));
1054 return DesktopWindow;
1055}
1056//******************************************************************************
1057//******************************************************************************
1058HWND WIN32API FindWindowA(LPCSTR lpszClass, LPCSTR lpszWindow)
1059{
1060 return FindWindowExA( NULL, NULL, lpszClass, lpszWindow );
1061}
1062//******************************************************************************
1063//******************************************************************************
1064HWND WIN32API FindWindowW( LPCWSTR lpClassName, LPCWSTR lpWindowName)
1065{
1066 return FindWindowExW( NULL, NULL, lpClassName, lpWindowName );
1067}
1068//******************************************************************************
1069//******************************************************************************
1070HWND WIN32API FindWindowExA(HWND hwndParent, HWND hwndChildAfter, LPCSTR lpszClass, LPCSTR lpszWindow)
1071{
1072 ATOM atom = 0;
1073
1074 if (lpszClass)
1075 {
1076 /* If the atom doesn't exist, then no class */
1077 /* with this name exists either. */
1078 if (!(atom = GlobalFindAtomA( lpszClass )))
1079 {
1080 SetLastError(ERROR_CANNOT_FIND_WND_CLASS);
1081 return 0;
1082 }
1083 }
1084 return Win32BaseWindow::FindWindowEx(hwndParent, hwndChildAfter, atom, (LPSTR)lpszWindow);
1085}
1086/*****************************************************************************
1087 * Name : HWND WIN32API FindWindowExW
1088 * Purpose : The FindWindowEx function retrieves the handle of a window whose
1089 * class name and window name match the specified strings. The
1090 * function searches child windows, beginning with the one following
1091 * the given child window.
1092 * Parameters: HWND hwndParent handle of parent window
1093 * HWND hwndChildAfter handle of a child window
1094 * LPCTSTR lpszClass address of class name
1095 * LPCTSTR lpszWindow address of window name
1096 * Variables :
1097 * Result : If the function succeeds, the return value is the handle of the
1098 * window that has the specified class and window names.
1099 * If the function fails, the return value is NULL. To get extended
1100 * error information, call GetLastError.
1101 * Remark :
1102 *
1103 *****************************************************************************/
1104
1105HWND WIN32API FindWindowExW(HWND hwndParent,
1106 HWND hwndChildAfter,
1107 LPCWSTR lpszClass,
1108 LPCWSTR lpszWindow)
1109{
1110 ATOM atom = 0;
1111 char *buffer;
1112 HWND hwnd;
1113
1114 if (lpszClass)
1115 {
1116 /* If the atom doesn't exist, then no class */
1117 /* with this name exists either. */
1118 if (!(atom = GlobalFindAtomW( lpszClass )))
1119 {
1120 SetLastError(ERROR_CANNOT_FIND_WND_CLASS);
1121 return 0;
1122 }
1123 }
1124 buffer = HEAP_strdupWtoA( GetProcessHeap(), 0, lpszWindow );
1125 hwnd = Win32BaseWindow::FindWindowEx(hwndParent, hwndChildAfter, atom, buffer);
1126 HeapFree( GetProcessHeap(), 0, buffer );
1127 return hwnd;
1128}
1129//******************************************************************************
1130//******************************************************************************
1131BOOL WIN32API FlashWindow(HWND hwnd, BOOL fFlash)
1132{
1133 dprintf(("FlashWindow %x %d\n", hwnd, fFlash));
1134// return OSLibWinFlashWindow(Win32BaseWindow::Win32ToOS2Handle(hwnd), fFlash);
1135 return 1;
1136}
1137//******************************************************************************
1138//******************************************************************************
1139BOOL WIN32API MoveWindow( HWND hwnd, INT x, INT y, INT cx, INT cy,
1140 BOOL repaint )
1141{
1142 int flags = SWP_NOZORDER | SWP_NOACTIVATE;
1143
1144 if (!repaint) flags |= SWP_NOREDRAW;
1145 dprintf(("MoveWindow: %x %d,%d %dx%d %d\n", hwnd, x, y, cx, cy, repaint ));
1146
1147 return SetWindowPos( hwnd, 0, x, y, cx, cy, flags );
1148}
1149//******************************************************************************
1150//******************************************************************************
1151BOOL WIN32API ClientToScreen (HWND hwnd, PPOINT pt)
1152{
1153 Win32BaseWindow *wnd;
1154 PRECT rcl;
1155
1156 if (!hwnd) {
1157 SetLastError(ERROR_INVALID_PARAMETER);
1158 return (FALSE);
1159 }
1160 wnd = Win32BaseWindow::GetWindowFromHandle (hwnd);
1161 if (!wnd) {
1162 dprintf(("warning: ClientToScreen window %x not found!", hwnd));
1163 SetLastError(ERROR_INVALID_WINDOW_HANDLE);
1164 return (FALSE);
1165 }
1166#ifdef DEBUG
1167 POINT tmp = *pt;
1168#endif
1169 MapWindowPoints(hwnd, 0, pt, 1);
1170 dprintf2(("ClientToScreen %x (%d,%d) -> (%d,%d)", hwnd, tmp.x, tmp.y, pt->x, pt->y));
1171
1172 return TRUE;
1173}
1174//******************************************************************************
1175//******************************************************************************
1176HDWP WIN32API BeginDeferWindowPos(int count)
1177{
1178 HDWP handle;
1179 DWP *pDWP;
1180
1181 if (count <= 0)
1182 {
1183 dprintf(("USER32: BeginDeferWindowPos invalid param %d", count));
1184 SetLastError(ERROR_INVALID_PARAMETER);
1185 return 0;
1186 }
1187 dprintf(("USER32: BeginDeferWindowPos %d", count));
1188 handle = (HDWP)HeapAlloc(GetProcessHeap(), 0, sizeof(DWP) + (count-1)*sizeof(WINDOWPOS) );
1189 if (!handle)
1190 return 0;
1191
1192 pDWP = (DWP *) handle;
1193 pDWP->actualCount = 0;
1194 pDWP->suggestedCount = count;
1195 pDWP->valid = TRUE;
1196 pDWP->wMagic = DWP_MAGIC;
1197 pDWP->hwndParent = 0;
1198 return handle;
1199}
1200/***********************************************************************
1201 * DeferWindowPos (USER32.128)
1202 */
1203HDWP WIN32API DeferWindowPos( HDWP hdwp, HWND hwnd, HWND hwndAfter,
1204 INT x, INT y, INT cx, INT cy,
1205 UINT flags )
1206{
1207 DWP *pDWP;
1208 int i;
1209 HDWP newhdwp = hdwp,retvalue;
1210 Win32BaseWindow *window;
1211
1212 pDWP = (DWP *)hdwp;
1213 if (!pDWP) {
1214 SetLastError(ERROR_INVALID_PARAMETER);
1215 return 0;
1216 }
1217
1218 if (hwnd == GetDesktopWindow())
1219 return 0;
1220
1221 window = Win32BaseWindow::GetWindowFromHandle(hwnd);
1222 if(!window) {
1223 dprintf(("DeferWindowPos, window %x not found", hwnd));
1224 SetLastError(ERROR_INVALID_WINDOW_HANDLE);
1225 HeapFree(GetProcessHeap(), 0, (LPVOID)hdwp);
1226 return 0;
1227 }
1228
1229 dprintf(("USER32: DeferWindowPos hdwp %x hwnd %x hwndAfter %x (%d,%d)(%d,%d) %x", hdwp, hwnd, hwndAfter,
1230 x, y, cx, cy, flags));
1231
1232/* Numega Bounds Checker Demo dislikes the following code.
1233 In fact, I've not been able to find any "same parent" requirement in any docu
1234 [AM 980509]
1235 */
1236#if 0
1237 /* All the windows of a DeferWindowPos() must have the same parent */
1238 parent = pWnd->parent->hwndSelf;
1239 if (pDWP->actualCount == 0) pDWP->hwndParent = parent;
1240 else if (parent != pDWP->hwndParent)
1241 {
1242 USER_HEAP_FREE( hdwp );
1243 retvalue = 0;
1244 goto END;
1245 }
1246#endif
1247
1248 for (i = 0; i < pDWP->actualCount; i++)
1249 {
1250 if (pDWP->winPos[i].hwnd == hwnd)
1251 {
1252 /* Merge with the other changes */
1253 if (!(flags & SWP_NOZORDER))
1254 {
1255 pDWP->winPos[i].hwndInsertAfter = hwndAfter;
1256 }
1257 if (!(flags & SWP_NOMOVE))
1258 {
1259 pDWP->winPos[i].x = x;
1260 pDWP->winPos[i].y = y;
1261 }
1262 if (!(flags & SWP_NOSIZE))
1263 {
1264 pDWP->winPos[i].cx = cx;
1265 pDWP->winPos[i].cy = cy;
1266 }
1267 pDWP->winPos[i].flags &= flags | ~(SWP_NOSIZE | SWP_NOMOVE |
1268 SWP_NOZORDER | SWP_NOREDRAW |
1269 SWP_NOACTIVATE | SWP_NOCOPYBITS|
1270 SWP_NOOWNERZORDER);
1271 pDWP->winPos[i].flags |= flags & (SWP_SHOWWINDOW | SWP_HIDEWINDOW |
1272 SWP_FRAMECHANGED);
1273 retvalue = hdwp;
1274 goto END;
1275 }
1276 }
1277 if (pDWP->actualCount >= pDWP->suggestedCount)
1278 {
1279 newhdwp = (HDWP)HeapReAlloc(GetProcessHeap(), 0, (LPVOID)hdwp,
1280 sizeof(DWP) + pDWP->suggestedCount*sizeof(WINDOWPOS));
1281 if (!newhdwp)
1282 {
1283 retvalue = 0;
1284 goto END;
1285 }
1286 pDWP = (DWP *) newhdwp;
1287 pDWP->suggestedCount++;
1288 }
1289 pDWP->winPos[pDWP->actualCount].hwnd = hwnd;
1290 pDWP->winPos[pDWP->actualCount].hwndInsertAfter = hwndAfter;
1291 pDWP->winPos[pDWP->actualCount].x = x;
1292 pDWP->winPos[pDWP->actualCount].y = y;
1293 pDWP->winPos[pDWP->actualCount].cx = cx;
1294 pDWP->winPos[pDWP->actualCount].cy = cy;
1295 pDWP->winPos[pDWP->actualCount].flags = flags;
1296 pDWP->actualCount++;
1297 retvalue = newhdwp;
1298END:
1299 return retvalue;
1300}
1301//******************************************************************************
1302//******************************************************************************
1303BOOL WIN32API EndDeferWindowPos( HDWP hdwp)
1304{
1305 DWP *pDWP;
1306 WINDOWPOS *winpos;
1307 BOOL res = TRUE;
1308 int i;
1309
1310 pDWP = (DWP *) hdwp;
1311 if (!pDWP) {
1312 dprintf(("**EndDeferWindowPos invalid parameter\n"));
1313 SetLastError(ERROR_INVALID_PARAMETER);
1314 return FALSE;
1315 }
1316 dprintf(("**EndDeferWindowPos for %d windows", pDWP->actualCount));
1317 for (i = 0, winpos = pDWP->winPos; i < pDWP->actualCount; i++, winpos++)
1318 {
1319 dprintf(("**EndDeferWindowPos %x (%d,%d) (%d,%d) %x", winpos->hwnd, winpos->x, winpos->y, winpos->x, winpos->cy, winpos->flags));
1320 if (!(res = SetWindowPos(winpos->hwnd, winpos->hwndInsertAfter,
1321 winpos->x, winpos->y, winpos->cx,
1322 winpos->cy, winpos->flags )))
1323 break;
1324 }
1325 dprintf(("**EndDeferWindowPos DONE"));
1326 HeapFree(GetProcessHeap(), 0, (LPVOID)hdwp);
1327 return res;
1328}
1329//******************************************************************************
1330//******************************************************************************
1331HWND WIN32API ChildWindowFromPoint( HWND hwnd, POINT pt)
1332{
1333 dprintf(("USER32: ChildWindowFromPoint\n"));
1334 return ChildWindowFromPointEx(hwnd, pt, 0);
1335}
1336/*****************************************************************************
1337 * Name : HWND WIN32API ChildWindowFromPointEx
1338 * Purpose : pt: client coordinates
1339 * Parameters:
1340 * Variables :
1341 * Result : If the function succeeds, the return value is the window handle.
1342 * If the function fails, the return value is zero
1343 * Remark :
1344 * Status : FULLY IMPLEMENTED AND TESTED
1345 *
1346 * Author : Rene Pronk [Sun, 1999/08/08 23:30]
1347 *****************************************************************************/
1348HWND WIN32API ChildWindowFromPointEx (HWND hwndParent, POINT pt, UINT uFlags)
1349{
1350 RECT rect;
1351 HWND hWnd;
1352
1353 dprintf(("ChildWindowFromPointEx(%08xh,%08xh,%08xh).\n",
1354 hwndParent, pt, uFlags));
1355
1356 if (GetWindowRect (hwndParent, &rect) == 0) {
1357 // oops, invalid handle
1358 SetLastError(ERROR_INVALID_WINDOW_HANDLE);
1359 return NULL;
1360 }
1361
1362 ClientToScreen(hwndParent, &pt);
1363 if (PtInRect (&rect, pt) == 0) {
1364 // point is outside window
1365 return NULL;
1366 }
1367
1368
1369 // get first child
1370 hWnd = GetWindow (hwndParent, GW_CHILD);
1371
1372 while (hWnd != NULL) {
1373
1374 // do I need to skip this window?
1375 if (((uFlags & CWP_SKIPINVISIBLE) &&
1376 (IsWindowVisible (hWnd) == FALSE)) ||
1377 ((uFlags & CWP_SKIPDISABLED) &&
1378 (IsWindowEnabled (hWnd) == FALSE)) ||
1379 ((uFlags & CWP_SKIPTRANSPARENT) &&
1380 (GetWindowLongA (hWnd, GWL_EXSTYLE) & WS_EX_TRANSPARENT)))
1381
1382 {
1383 hWnd = GetWindow (hWnd, GW_HWNDNEXT);
1384 continue;
1385 }
1386
1387 // is the point in this window's rect?
1388 GetWindowRect (hWnd, &rect);
1389 if (PtInRect (&rect,pt) == FALSE) {
1390 hWnd = GetWindow (hWnd, GW_HWNDNEXT);
1391 continue;
1392 }
1393
1394 dprintf(("ChildWindowFromPointEx returned %x", hWnd));
1395 // found it!
1396 return hWnd;
1397 }
1398
1399 // the point is in the parentwindow but the parentwindow has no child
1400 // at this coordinate
1401 dprintf(("ChildWindowFromPointEx returned parent %x", hwndParent));
1402 return hwndParent;
1403}
1404//******************************************************************************
1405//******************************************************************************
1406BOOL WIN32API CloseWindow(HWND hwnd)
1407{
1408 Win32BaseWindow *window;
1409
1410 window = Win32BaseWindow::GetWindowFromHandle(hwnd);
1411 if(!window) {
1412 dprintf(("CloseWindow, window %x not found", hwnd));
1413 SetLastError(ERROR_INVALID_WINDOW_HANDLE);
1414 return 0;
1415 }
1416 dprintf(("CloseWindow %x\n", hwnd));
1417 return window->CloseWindow();
1418}
1419//******************************************************************************
1420//TODO: Does this return handles of hidden or disabled windows?
1421//******************************************************************************
1422HWND WIN32API WindowFromPoint( POINT point)
1423{
1424 HWND hwndOS2, hwnd;
1425 POINT wPoint;
1426
1427 wPoint.x = point.x;
1428 wPoint.y = mapScreenY(point.y);
1429
1430 hwndOS2 = OSLibWinWindowFromPoint(OSLIB_HWND_DESKTOP, (PVOID)&wPoint);
1431 if(hwndOS2)
1432 {
1433 hwnd = Win32BaseWindow::OS2ToWin32Handle(hwndOS2);
1434 if(hwnd) {
1435 dprintf(("WindowFromPoint (%d,%d) %x->%x\n", point.x, point.y, hwndOS2, hwnd));
1436 return hwnd;
1437 }
1438 }
1439 dprintf(("WindowFromPoint (%d,%d) %x->1\n", point.x, point.y, hwndOS2));
1440 return windowDesktop->getWindowHandle();
1441}
1442//******************************************************************************
1443//******************************************************************************
1444BOOL WIN32API IsWindowUnicode(HWND hwnd)
1445{
1446 Win32BaseWindow *window;
1447
1448 window = Win32BaseWindow::GetWindowFromHandle(hwnd);
1449 if(!window) {
1450 dprintf(("IsWindowUnicode, window %x not found", hwnd));
1451 SetLastError(ERROR_INVALID_WINDOW_HANDLE);
1452 return 0;
1453 }
1454 return window->IsWindowUnicode();
1455}
1456/***********************************************************************
1457 * SwitchToThisWindow (USER32.539)
1458 */
1459DWORD WINAPI SwitchToThisWindow( HWND hwnd, BOOL restore )
1460{
1461 return ShowWindow( hwnd, restore ? SW_RESTORE : SW_SHOWMINIMIZED );
1462}
1463//******************************************************************************
1464//******************************************************************************
1465BOOL WIN32API EnumThreadWindows(DWORD dwThreadId, WNDENUMPROC lpfn, LPARAM lParam)
1466{
1467 return windowDesktop->EnumThreadWindows(dwThreadId, lpfn, lParam);
1468}
1469//******************************************************************************
1470//******************************************************************************
1471BOOL WIN32API EnumChildWindows(HWND hwnd, WNDENUMPROC lpfn, LPARAM lParam)
1472{
1473 Win32BaseWindow *window;
1474 BOOL rc = TRUE;
1475 ULONG henum;
1476 HWND hwndNext;
1477
1478 if(lpfn == NULL) {
1479 dprintf(("EnumChildWindows invalid parameter %x %x\n", hwnd, lParam));
1480 SetLastError(ERROR_INVALID_PARAMETER);
1481 return FALSE;
1482 }
1483 window = Win32BaseWindow::GetWindowFromHandle(hwnd);
1484 if(!window) {
1485 dprintf(("EnumChildWindows, window %x not found", hwnd));
1486 SetLastError(ERROR_INVALID_WINDOW_HANDLE);
1487 return FALSE;
1488 }
1489 return window->EnumChildWindows(lpfn, lParam);
1490}
1491//******************************************************************************
1492//******************************************************************************
1493BOOL WIN32API EnumWindows(WNDENUMPROC lpfn, LPARAM lParam)
1494{
1495 return windowDesktop->EnumWindows(lpfn, lParam);
1496}
1497//******************************************************************************
1498//******************************************************************************
1499UINT WIN32API ArrangeIconicWindows( HWND hwnd)
1500{
1501 dprintf(("USER32: ArrangeIconicWindows %x", hwnd));
1502 return O32_ArrangeIconicWindows(Win32BaseWindow::Win32ToOS2Handle(hwnd));
1503}
1504//******************************************************************************
1505//restores iconized window to previous size/position
1506//******************************************************************************
1507BOOL WIN32API OpenIcon(HWND hwnd)
1508{
1509 dprintf(("USER32: OpenIcon"));
1510
1511 if(!IsIconic(hwnd))
1512 return FALSE;
1513 ShowWindow(hwnd, SW_SHOWNORMAL);
1514 return TRUE;
1515}
1516//******************************************************************************
1517//******************************************************************************
1518BOOL WIN32API ShowOwnedPopups( HWND hwnd, BOOL arg2)
1519{
1520 dprintf(("USER32: ShowOwnedPopups (OPEN32: todo) %x", hwnd));
1521 return O32_ShowOwnedPopups(Win32BaseWindow::Win32ToOS2Handle(hwnd), arg2);
1522}
1523//******************************************************************************
1524//******************************************************************************
1525HWND WIN32API GetForegroundWindow(void)
1526{
1527 HWND hwnd;
1528
1529 hwnd = Win32BaseWindow::OS2ToWin32Handle(OSLibWinQueryActiveWindow());
1530 dprintf(("USER32: GetForegroundWindow returned %x", hwnd));
1531 return hwnd;
1532}
1533//******************************************************************************
1534//******************************************************************************
1535HWND WIN32API GetLastActivePopup( HWND hWnd)
1536{
1537 HWND hwnd;
1538
1539 hWnd = Win32BaseWindow::Win32ToOS2Handle(hWnd);
1540
1541 hwnd = Win32BaseWindow::OS2ToWin32Handle(O32_GetLastActivePopup(hWnd));
1542
1543 dprintf(("GetLastActivePopup %x returned %x", hWnd, hwnd));
1544 return hwnd;
1545}
1546//******************************************************************************
1547//******************************************************************************
1548DWORD WIN32API GetWindowThreadProcessId(HWND hWnd, PDWORD lpdwProcessId)
1549{
1550 dprintf2(("USER32: GetWindowThreadProcessId"));
1551 hWnd = Win32BaseWindow::Win32ToOS2Handle(hWnd);
1552
1553 return O32_GetWindowThreadProcessId(hWnd,lpdwProcessId);
1554}
1555//******************************************************************************
1556//******************************************************************************
1557DWORD WIN32API GetWindowContextHelpId(HWND hwnd)
1558{
1559 Win32BaseWindow *window;
1560
1561 window = Win32BaseWindow::GetWindowFromHandle(hwnd);
1562 if(!window) {
1563 dprintf(("GetWindowContextHelpId, window %x not found", hwnd));
1564 SetLastError(ERROR_INVALID_WINDOW_HANDLE);
1565 return 0;
1566 }
1567 dprintf(("GetWindowContextHelpId %x", hwnd));
1568 return window->getWindowContextHelpId();
1569}
1570//******************************************************************************
1571//******************************************************************************
1572BOOL WIN32API SetWindowContextHelpId(HWND hwnd, DWORD dwContextHelpId)
1573{
1574 Win32BaseWindow *window;
1575
1576 window = Win32BaseWindow::GetWindowFromHandle(hwnd);
1577 if(!window) {
1578 dprintf(("SetWindowContextHelpId, window %x not found", hwnd));
1579 SetLastError(ERROR_INVALID_WINDOW_HANDLE);
1580 return 0;
1581 }
1582 dprintf(("SetWindowContextHelpId %x %d", hwnd, dwContextHelpId));
1583 window->setWindowContextHelpId(dwContextHelpId);
1584 return(TRUE);
1585}
1586//******************************************************************************
1587//******************************************************************************
1588HANDLE WINAPI GetPropA( HWND hwnd, LPCSTR str )
1589{
1590 Win32BaseWindow *window;
1591
1592 window = Win32BaseWindow::GetWindowFromHandle(hwnd);
1593 if(!window) {
1594 dprintf(("GetPropA, window %x not found", hwnd));
1595 SetLastError(ERROR_INVALID_WINDOW_HANDLE);
1596 return 0;
1597 }
1598 return window->getProp(str);
1599}
1600//******************************************************************************
1601//******************************************************************************
1602HANDLE WINAPI GetPropW( HWND hwnd, LPCWSTR str )
1603{
1604 LPSTR strA;
1605 HANDLE ret;
1606
1607 if (!HIWORD(str)) return GetPropA( hwnd, (LPCSTR)(UINT)LOWORD(str) );
1608 strA = HEAP_strdupWtoA( GetProcessHeap(), 0, str );
1609 ret = GetPropA( hwnd, strA );
1610 HeapFree( GetProcessHeap(), 0, strA );
1611 return ret;
1612}
1613//******************************************************************************
1614//******************************************************************************
1615BOOL WINAPI SetPropA( HWND hwnd, LPCSTR str, HANDLE handle )
1616{
1617 Win32BaseWindow *window;
1618
1619 window = Win32BaseWindow::GetWindowFromHandle(hwnd);
1620 if(!window) {
1621 dprintf(("SetPropA, window %x not found", hwnd));
1622 SetLastError(ERROR_INVALID_WINDOW_HANDLE);
1623 return FALSE;
1624 }
1625 return window->setProp(str, handle);
1626}
1627//******************************************************************************
1628//******************************************************************************
1629BOOL WINAPI SetPropW( HWND hwnd, LPCWSTR str, HANDLE handle )
1630{
1631 BOOL ret;
1632 LPSTR strA;
1633
1634 if (!HIWORD(str))
1635 return SetPropA( hwnd, (LPCSTR)(UINT)LOWORD(str), handle );
1636 strA = HEAP_strdupWtoA( GetProcessHeap(), 0, str );
1637 ret = SetPropA( hwnd, strA, handle );
1638 HeapFree( GetProcessHeap(), 0, strA );
1639 return ret;
1640}
1641//******************************************************************************
1642//******************************************************************************
1643HANDLE WINAPI RemovePropA( HWND hwnd, LPCSTR str )
1644{
1645 Win32BaseWindow *window;
1646
1647 window = Win32BaseWindow::GetWindowFromHandle(hwnd);
1648 if(!window) {
1649 dprintf(("RemovePropA, window %x not found", hwnd));
1650 SetLastError(ERROR_INVALID_WINDOW_HANDLE);
1651 return 0;
1652 }
1653 return window->removeProp(str);
1654}
1655//******************************************************************************
1656//******************************************************************************
1657HANDLE WINAPI RemovePropW( HWND hwnd, LPCWSTR str )
1658{
1659 LPSTR strA;
1660 HANDLE ret;
1661
1662 if (!HIWORD(str))
1663 return RemovePropA( hwnd, (LPCSTR)(UINT)LOWORD(str) );
1664 strA = HEAP_strdupWtoA( GetProcessHeap(), 0, str );
1665 ret = RemovePropA( hwnd, strA );
1666 HeapFree( GetProcessHeap(), 0, strA );
1667 return ret;
1668}
1669//******************************************************************************
1670//******************************************************************************
1671INT WINAPI EnumPropsA( HWND hwnd, PROPENUMPROCA func )
1672{
1673 return EnumPropsExA( hwnd, (PROPENUMPROCEXA)func, 0 );
1674}
1675//******************************************************************************
1676//******************************************************************************
1677INT WINAPI EnumPropsW( HWND hwnd, PROPENUMPROCW func )
1678{
1679 return EnumPropsExW( hwnd, (PROPENUMPROCEXW)func, 0 );
1680}
1681//******************************************************************************
1682//******************************************************************************
1683INT WINAPI EnumPropsExA(HWND hwnd, PROPENUMPROCEXA func, LPARAM lParam)
1684{
1685 Win32BaseWindow *window;
1686
1687 window = Win32BaseWindow::GetWindowFromHandle(hwnd);
1688 if(!window) {
1689 dprintf(("EnumPropsExA, window %x not found", hwnd));
1690 SetLastError(ERROR_INVALID_WINDOW_HANDLE);
1691 return -1;
1692 }
1693 return window->enumPropsExA(func, lParam);
1694}
1695//******************************************************************************
1696//******************************************************************************
1697INT WINAPI EnumPropsExW(HWND hwnd, PROPENUMPROCEXW func, LPARAM lParam)
1698{
1699 Win32BaseWindow *window;
1700
1701 window = Win32BaseWindow::GetWindowFromHandle(hwnd);
1702 if(!window) {
1703 dprintf(("EnumPropsExA, window %x not found", hwnd));
1704 SetLastError(ERROR_INVALID_WINDOW_HANDLE);
1705 return -1;
1706 }
1707 return window->enumPropsExW(func, lParam);
1708}
1709//******************************************************************************
1710//******************************************************************************
Note: See TracBrowser for help on using the repository browser.