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

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

put back original GetWindow

File size: 61.0 KB
Line 
1/* $Id: window.cpp,v 1.77 2000-09-08 18:08:58 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//******************************************************************************
910BOOL WIN32API AdjustWindowRectEx( PRECT rect, DWORD style, BOOL menu, DWORD exStyle)
911{
912 dprintf(("AdjustWindowRectEx %x %x %d (%d,%d)(%d,%d)\n", style, exStyle, menu, rect->left, rect->top, rect->right, rect->bottom));
913
914 if(style == 0 && menu == FALSE && exStyle == 0) {
915 return TRUE; //nothing needs to be changed (VERIFIED in NT 4)
916 }
917 /* Correct the window style */
918 if (!(style & (WS_POPUP | WS_CHILD))) /* Overlapped window */
919 style |= WS_CAPTION;
920
921 //SvL: Include WS_POPUP -> otherwise HAS_THINFRAME is true for popup windows
922 // Also include WS_CHILD -> otherwise HAS_THICKFRAME doesn't work correctly
923 style &= (WS_DLGFRAME | WS_BORDER | WS_THICKFRAME | WS_CHILD | WS_VSCROLL | WS_HSCROLL | WS_POPUP);
924 exStyle &= (WS_EX_DLGMODALFRAME | WS_EX_CLIENTEDGE | WS_EX_STATICEDGE | WS_EX_TOOLWINDOW);
925 if (exStyle & WS_EX_DLGMODALFRAME) style &= ~WS_THICKFRAME;
926
927 //Adjust rect outer (Win32BaseWindow::AdjustRectOuter)
928 if (HAS_THICKFRAME(style,exStyle))
929 InflateRect( rect, GetSystemMetrics(SM_CXFRAME), GetSystemMetrics(SM_CYFRAME) );
930 else
931 if (HAS_DLGFRAME(style,exStyle))
932 InflateRect(rect, GetSystemMetrics(SM_CXDLGFRAME), GetSystemMetrics(SM_CYDLGFRAME) );
933 else
934 if (HAS_THINFRAME(style))
935 InflateRect( rect, GetSystemMetrics(SM_CXBORDER), GetSystemMetrics(SM_CYBORDER));
936
937 if ((style & WS_CAPTION) == WS_CAPTION)
938 {
939 if (exStyle & WS_EX_TOOLWINDOW)
940 rect->top -= GetSystemMetrics(SM_CYSMCAPTION);
941 else
942 rect->top -= GetSystemMetrics(SM_CYCAPTION);
943 }
944
945 if (menu)
946 rect->top -= GetSystemMetrics(SM_CYMENU);
947
948 //Adjust rect inner (Win32BaseWindow::AdjustRectInner)
949 if (exStyle & WS_EX_CLIENTEDGE)
950 InflateRect (rect, GetSystemMetrics(SM_CXEDGE), GetSystemMetrics(SM_CYEDGE));
951
952 if (exStyle & WS_EX_STATICEDGE)
953 InflateRect (rect, GetSystemMetrics(SM_CXBORDER), GetSystemMetrics(SM_CYBORDER));
954
955 if (style & WS_VSCROLL) rect->right += GetSystemMetrics(SM_CXVSCROLL);
956 if (style & WS_HSCROLL) rect->bottom += GetSystemMetrics(SM_CYHSCROLL);
957
958 dprintf(("AdjustWindowRectEx returned (%d,%d)(%d,%d)\n", rect->left, rect->top, rect->right, rect->bottom));
959
960 return TRUE;
961}
962//******************************************************************************
963/* Coordinate Space and Transformation Functions */
964//******************************************************************************
965/*******************************************************************
966 * WINPOS_GetWinOffset
967 *
968 * Calculate the offset between the origin of the two windows. Used
969 * to implement MapWindowPoints.
970 */
971static void WINPOS_GetWinOffset( Win32BaseWindow *wndFrom, Win32BaseWindow *wndTo,
972 POINT *offset )
973{
974 Win32BaseWindow *window;
975
976 offset->x = offset->y = 0;
977
978 /* Translate source window origin to screen coords */
979 if(wndFrom != windowDesktop)
980 {
981 window = wndFrom;
982 while(window)
983 {
984 offset->x += window->getClientRectPtr()->left + window->getWindowRect()->left;
985 offset->y += window->getClientRectPtr()->top + window->getWindowRect()->top;
986 window = window->getParent();
987 }
988 }
989
990 /* Translate origin to destination window coords */
991 if(wndTo != windowDesktop)
992 {
993 window = wndTo;
994 while(window)
995 {
996 offset->x -= window->getClientRectPtr()->left + window->getWindowRect()->left;
997 offset->y -= window->getClientRectPtr()->top + window->getWindowRect()->top;
998 window = window->getParent();
999 }
1000 }
1001}
1002//******************************************************************************
1003//******************************************************************************
1004int WIN32API MapWindowPoints(HWND hwndFrom, HWND hwndTo, LPPOINT lpPoints,
1005 UINT cPoints)
1006{
1007 Win32BaseWindow *wndfrom, *wndto;
1008 int retval = 0;
1009 POINT offset;
1010
1011 SetLastError(0);
1012 if(lpPoints == NULL || cPoints == 0) {
1013 SetLastError(ERROR_INVALID_PARAMETER);
1014 return 0;
1015 }
1016 if(hwndFrom)
1017 {
1018 wndfrom = Win32BaseWindow::GetWindowFromHandle(hwndFrom);
1019 if(!wndfrom) {
1020 dprintf(("MapWindowPoints, window %x not found", hwndFrom));
1021 SetLastError(ERROR_INVALID_WINDOW_HANDLE);
1022 return 0;
1023 }
1024 }
1025 else wndfrom = windowDesktop;
1026
1027 if(hwndTo)
1028 {
1029 wndto = Win32BaseWindow::GetWindowFromHandle(hwndTo);
1030 if(!wndto) {
1031 dprintf(("MapWindowPoints, window %x not found", hwndTo));
1032 SetLastError(ERROR_INVALID_WINDOW_HANDLE);
1033 return 0;
1034 }
1035 }
1036 else wndto = windowDesktop;
1037
1038 if(wndto == wndfrom)
1039 return 0; //nothing to do
1040
1041 dprintf2(("USER32: MapWindowPoints %x to %x (%d,%d) (%d)", hwndFrom, hwndTo, lpPoints->x, lpPoints->y, cPoints));
1042 WINPOS_GetWinOffset(wndfrom, wndto, &offset);
1043
1044 for(int i=0;i<cPoints;i++)
1045 {
1046 lpPoints[i].x += offset.x;
1047 lpPoints[i].y += offset.y;
1048 }
1049 retval = ((LONG)offset.y << 16) | offset.x;
1050 return retval;
1051}
1052//******************************************************************************
1053//******************************************************************************
1054BOOL WIN32API ScreenToClient(HWND hwnd, LPPOINT pt)
1055{
1056 Win32BaseWindow *wnd;
1057 PRECT rcl;
1058 BOOL rc;
1059
1060 if(!hwnd) {
1061 return (TRUE);
1062 }
1063 wnd = Win32BaseWindow::GetWindowFromHandle (hwnd);
1064 if (!wnd) {
1065 dprintf(("warning: ScreenToClient: window %x not found!", hwnd));
1066 SetLastError(ERROR_INVALID_WINDOW_HANDLE);
1067 return FALSE;
1068 }
1069 SetLastError(0);
1070#ifdef DEBUG
1071 POINT tmp = *pt;
1072#endif
1073 MapWindowPoints(0, hwnd, pt, 1);
1074 dprintf2(("ScreenToClient %x (%d,%d) -> (%d,%d)", hwnd, tmp.x, tmp.y, pt->x, pt->y));
1075 return TRUE;
1076}
1077//******************************************************************************
1078//******************************************************************************
1079HWND WIN32API GetDesktopWindow(void)
1080{
1081 HWND DesktopWindow = windowDesktop->getWindowHandle();
1082 dprintf2(("USER32: GetDesktopWindow, returned %x\n", DesktopWindow));
1083 return DesktopWindow;
1084}
1085//******************************************************************************
1086//******************************************************************************
1087HWND WIN32API FindWindowA(LPCSTR lpszClass, LPCSTR lpszWindow)
1088{
1089 return FindWindowExA( NULL, NULL, lpszClass, lpszWindow );
1090}
1091//******************************************************************************
1092//******************************************************************************
1093HWND WIN32API FindWindowW( LPCWSTR lpClassName, LPCWSTR lpWindowName)
1094{
1095 return FindWindowExW( NULL, NULL, lpClassName, lpWindowName );
1096}
1097//******************************************************************************
1098//******************************************************************************
1099HWND WIN32API FindWindowExA(HWND hwndParent, HWND hwndChildAfter, LPCSTR lpszClass, LPCSTR lpszWindow)
1100{
1101 ATOM atom = 0;
1102
1103 if (lpszClass)
1104 {
1105 /* If the atom doesn't exist, then no class */
1106 /* with this name exists either. */
1107 if (!(atom = GlobalFindAtomA( lpszClass )))
1108 {
1109 SetLastError(ERROR_CANNOT_FIND_WND_CLASS);
1110 return 0;
1111 }
1112 }
1113 return Win32BaseWindow::FindWindowEx(hwndParent, hwndChildAfter, atom, (LPSTR)lpszWindow);
1114}
1115/*****************************************************************************
1116 * Name : HWND WIN32API FindWindowExW
1117 * Purpose : The FindWindowEx function retrieves the handle of a window whose
1118 * class name and window name match the specified strings. The
1119 * function searches child windows, beginning with the one following
1120 * the given child window.
1121 * Parameters: HWND hwndParent handle of parent window
1122 * HWND hwndChildAfter handle of a child window
1123 * LPCTSTR lpszClass address of class name
1124 * LPCTSTR lpszWindow address of window name
1125 * Variables :
1126 * Result : If the function succeeds, the return value is the handle of the
1127 * window that has the specified class and window names.
1128 * If the function fails, the return value is NULL. To get extended
1129 * error information, call GetLastError.
1130 * Remark :
1131 *
1132 *****************************************************************************/
1133
1134HWND WIN32API FindWindowExW(HWND hwndParent,
1135 HWND hwndChildAfter,
1136 LPCWSTR lpszClass,
1137 LPCWSTR lpszWindow)
1138{
1139 ATOM atom = 0;
1140 char *buffer;
1141 HWND hwnd;
1142
1143 if (lpszClass)
1144 {
1145 /* If the atom doesn't exist, then no class */
1146 /* with this name exists either. */
1147 if (!(atom = GlobalFindAtomW( lpszClass )))
1148 {
1149 SetLastError(ERROR_CANNOT_FIND_WND_CLASS);
1150 return 0;
1151 }
1152 }
1153 buffer = HEAP_strdupWtoA( GetProcessHeap(), 0, lpszWindow );
1154 hwnd = Win32BaseWindow::FindWindowEx(hwndParent, hwndChildAfter, atom, buffer);
1155 HeapFree( GetProcessHeap(), 0, buffer );
1156 return hwnd;
1157}
1158//******************************************************************************
1159//******************************************************************************
1160BOOL WIN32API FlashWindow(HWND hwnd, BOOL fFlash)
1161{
1162 dprintf(("FlashWindow %x %d\n", hwnd, fFlash));
1163// return OSLibWinFlashWindow(Win32BaseWindow::Win32ToOS2Handle(hwnd), fFlash);
1164 return 1;
1165}
1166//******************************************************************************
1167//******************************************************************************
1168BOOL WIN32API MoveWindow( HWND hwnd, INT x, INT y, INT cx, INT cy,
1169 BOOL repaint )
1170{
1171 int flags = SWP_NOZORDER | SWP_NOACTIVATE;
1172
1173 if (!repaint) flags |= SWP_NOREDRAW;
1174 dprintf(("MoveWindow: %x %d,%d %dx%d %d\n", hwnd, x, y, cx, cy, repaint ));
1175
1176 return SetWindowPos( hwnd, 0, x, y, cx, cy, flags );
1177}
1178//******************************************************************************
1179//******************************************************************************
1180BOOL WIN32API ClientToScreen (HWND hwnd, PPOINT pt)
1181{
1182 Win32BaseWindow *wnd;
1183 PRECT rcl;
1184
1185 if (!hwnd) {
1186 SetLastError(ERROR_INVALID_PARAMETER);
1187 return (FALSE);
1188 }
1189 wnd = Win32BaseWindow::GetWindowFromHandle (hwnd);
1190 if (!wnd) {
1191 dprintf(("warning: ClientToScreen window %x not found!", hwnd));
1192 SetLastError(ERROR_INVALID_WINDOW_HANDLE);
1193 return (FALSE);
1194 }
1195#ifdef DEBUG
1196 POINT tmp = *pt;
1197#endif
1198 MapWindowPoints(hwnd, 0, pt, 1);
1199 dprintf2(("ClientToScreen %x (%d,%d) -> (%d,%d)", hwnd, tmp.x, tmp.y, pt->x, pt->y));
1200
1201 return TRUE;
1202}
1203//******************************************************************************
1204//Note: count 0 is a legal parameter (verified in NT4)
1205//******************************************************************************
1206HDWP WIN32API BeginDeferWindowPos(int count)
1207{
1208 HDWP handle;
1209 DWP *pDWP;
1210
1211 if (count < 0)
1212 {
1213 dprintf(("USER32: BeginDeferWindowPos invalid param %d", count));
1214 SetLastError(ERROR_INVALID_PARAMETER);
1215 return 0;
1216 }
1217 dprintf(("USER32: BeginDeferWindowPos %d", count));
1218 if(count == 0)
1219 count = 8; // change to any non-zero value
1220
1221 handle = (HDWP)HeapAlloc(GetProcessHeap(), 0, sizeof(DWP) + (count-1)*sizeof(WINDOWPOS));
1222 if (!handle)
1223 return 0;
1224
1225 pDWP = (DWP *) handle;
1226 pDWP->actualCount = 0;
1227 pDWP->suggestedCount = count;
1228 pDWP->valid = TRUE;
1229 pDWP->wMagic = DWP_MAGIC;
1230 pDWP->hwndParent = 0;
1231 return handle;
1232}
1233/***********************************************************************
1234 * DeferWindowPos (USER32.128)
1235 *
1236 * TODO: SvL: Does this need to be thread safe?
1237 *
1238 */
1239HDWP WIN32API DeferWindowPos( HDWP hdwp, HWND hwnd, HWND hwndAfter,
1240 INT x, INT y, INT cx, INT cy,
1241 UINT flags )
1242{
1243 DWP *pDWP;
1244 int i;
1245 HDWP newhdwp = hdwp,retvalue;
1246 Win32BaseWindow *window;
1247
1248 pDWP = (DWP *)hdwp;
1249 if (!pDWP) {
1250 SetLastError(ERROR_INVALID_PARAMETER);
1251 return 0;
1252 }
1253
1254 if (hwnd == GetDesktopWindow())
1255 return 0;
1256
1257 window = Win32BaseWindow::GetWindowFromHandle(hwnd);
1258 if(!window) {
1259 dprintf(("DeferWindowPos, window %x not found", hwnd));
1260 SetLastError(ERROR_INVALID_WINDOW_HANDLE);
1261 HeapFree(GetProcessHeap(), 0, (LPVOID)hdwp);
1262 return 0;
1263 }
1264
1265 dprintf(("USER32: DeferWindowPos hdwp %x hwnd %x hwndAfter %x (%d,%d)(%d,%d) %x", hdwp, hwnd, hwndAfter,
1266 x, y, cx, cy, flags));
1267
1268/* Numega Bounds Checker Demo dislikes the following code.
1269 In fact, I've not been able to find any "same parent" requirement in any docu
1270 [AM 980509]
1271 */
1272#if 0
1273 /* All the windows of a DeferWindowPos() must have the same parent */
1274 parent = pWnd->parent->hwndSelf;
1275 if (pDWP->actualCount == 0) pDWP->hwndParent = parent;
1276 else if (parent != pDWP->hwndParent)
1277 {
1278 USER_HEAP_FREE( hdwp );
1279 retvalue = 0;
1280 goto END;
1281 }
1282#endif
1283
1284 for (i = 0; i < pDWP->actualCount; i++)
1285 {
1286 if (pDWP->winPos[i].hwnd == hwnd)
1287 {
1288 /* Merge with the other changes */
1289 if (!(flags & SWP_NOZORDER))
1290 {
1291 pDWP->winPos[i].hwndInsertAfter = hwndAfter;
1292 }
1293 if (!(flags & SWP_NOMOVE))
1294 {
1295 pDWP->winPos[i].x = x;
1296 pDWP->winPos[i].y = y;
1297 }
1298 if (!(flags & SWP_NOSIZE))
1299 {
1300 pDWP->winPos[i].cx = cx;
1301 pDWP->winPos[i].cy = cy;
1302 }
1303 pDWP->winPos[i].flags &= flags | ~(SWP_NOSIZE | SWP_NOMOVE |
1304 SWP_NOZORDER | SWP_NOREDRAW |
1305 SWP_NOACTIVATE | SWP_NOCOPYBITS|
1306 SWP_NOOWNERZORDER);
1307 pDWP->winPos[i].flags |= flags & (SWP_SHOWWINDOW | SWP_HIDEWINDOW |
1308 SWP_FRAMECHANGED);
1309 retvalue = hdwp;
1310 goto END;
1311 }
1312 }
1313 if (pDWP->actualCount >= pDWP->suggestedCount)
1314 {
1315 //DWP structure already contains WINDOWPOS, allocated with (count-1)
1316 //in BeginDeferWindowPos; pDWP->suggestedCount alloc increases it by one
1317 newhdwp = (HDWP)HeapReAlloc(GetProcessHeap(), 0, (LPVOID)hdwp,
1318 sizeof(DWP) + pDWP->suggestedCount*sizeof(WINDOWPOS));
1319 if (!newhdwp)
1320 {
1321 retvalue = 0;
1322 goto END;
1323 }
1324 pDWP = (DWP *) newhdwp;
1325 pDWP->suggestedCount++;
1326 }
1327 pDWP->winPos[pDWP->actualCount].hwnd = hwnd;
1328 pDWP->winPos[pDWP->actualCount].hwndInsertAfter = hwndAfter;
1329 pDWP->winPos[pDWP->actualCount].x = x;
1330 pDWP->winPos[pDWP->actualCount].y = y;
1331 pDWP->winPos[pDWP->actualCount].cx = cx;
1332 pDWP->winPos[pDWP->actualCount].cy = cy;
1333 pDWP->winPos[pDWP->actualCount].flags = flags;
1334 pDWP->actualCount++;
1335 retvalue = newhdwp;
1336END:
1337 return retvalue;
1338}
1339//******************************************************************************
1340//******************************************************************************
1341BOOL WIN32API EndDeferWindowPos( HDWP hdwp)
1342{
1343 DWP *pDWP;
1344 WINDOWPOS *winpos;
1345 BOOL res = TRUE;
1346 int i;
1347
1348 pDWP = (DWP *) hdwp;
1349 if (!pDWP) {
1350 dprintf(("**EndDeferWindowPos invalid parameter\n"));
1351 SetLastError(ERROR_INVALID_PARAMETER);
1352 return FALSE;
1353 }
1354 dprintf(("**EndDeferWindowPos for %d windows", pDWP->actualCount));
1355 for (i = 0, winpos = pDWP->winPos; i < pDWP->actualCount; i++, winpos++)
1356 {
1357 dprintf(("**EndDeferWindowPos %x (%d,%d) (%d,%d) %x", winpos->hwnd, winpos->x, winpos->y, winpos->x, winpos->cy, winpos->flags));
1358 if (!(res = SetWindowPos(winpos->hwnd, winpos->hwndInsertAfter,
1359 winpos->x, winpos->y, winpos->cx,
1360 winpos->cy, winpos->flags )))
1361 break;
1362 }
1363 dprintf(("**EndDeferWindowPos DONE"));
1364 HeapFree(GetProcessHeap(), 0, (LPVOID)hdwp);
1365 return res;
1366}
1367//******************************************************************************
1368//******************************************************************************
1369HWND WIN32API ChildWindowFromPoint( HWND hwnd, POINT pt)
1370{
1371 dprintf(("USER32: ChildWindowFromPoint\n"));
1372 return ChildWindowFromPointEx(hwnd, pt, 0);
1373}
1374/*****************************************************************************
1375 * Name : HWND WIN32API ChildWindowFromPointEx
1376 * Purpose : pt: client coordinates
1377 * Parameters:
1378 * Variables :
1379 * Result : If the function succeeds, the return value is the window handle.
1380 * If the function fails, the return value is zero
1381 * Remark :
1382 * Status : COMPLETELY IMPLEMENTED AND TESTED
1383 *
1384 * Author : Rene Pronk [Sun, 1999/08/08 23:30]
1385 *****************************************************************************/
1386HWND WIN32API ChildWindowFromPointEx (HWND hwndParent, POINT pt, UINT uFlags)
1387{
1388 RECT rect;
1389 HWND hWnd;
1390
1391 dprintf(("ChildWindowFromPointEx(%08xh,%08xh,%08xh).\n",
1392 hwndParent, pt, uFlags));
1393
1394 if (GetWindowRect (hwndParent, &rect) == 0) {
1395 // oops, invalid handle
1396 SetLastError(ERROR_INVALID_WINDOW_HANDLE);
1397 return NULL;
1398 }
1399
1400 ClientToScreen(hwndParent, &pt);
1401 if (PtInRect (&rect, pt) == 0) {
1402 // point is outside window
1403 return NULL;
1404 }
1405
1406
1407 // get first child
1408 hWnd = GetWindow (hwndParent, GW_CHILD);
1409
1410 while (hWnd != NULL) {
1411
1412 // do I need to skip this window?
1413 if (((uFlags & CWP_SKIPINVISIBLE) &&
1414 (IsWindowVisible (hWnd) == FALSE)) ||
1415 ((uFlags & CWP_SKIPDISABLED) &&
1416 (IsWindowEnabled (hWnd) == FALSE)) ||
1417 ((uFlags & CWP_SKIPTRANSPARENT) &&
1418 (GetWindowLongA (hWnd, GWL_EXSTYLE) & WS_EX_TRANSPARENT)))
1419
1420 {
1421 hWnd = GetWindow (hWnd, GW_HWNDNEXT);
1422 continue;
1423 }
1424
1425 // is the point in this window's rect?
1426 GetWindowRect (hWnd, &rect);
1427 if (PtInRect (&rect,pt) == FALSE) {
1428 hWnd = GetWindow (hWnd, GW_HWNDNEXT);
1429 continue;
1430 }
1431
1432 dprintf(("ChildWindowFromPointEx returned %x", hWnd));
1433 // found it!
1434 return hWnd;
1435 }
1436
1437 // the point is in the parentwindow but the parentwindow has no child
1438 // at this coordinate
1439 dprintf(("ChildWindowFromPointEx returned parent %x", hwndParent));
1440 return hwndParent;
1441}
1442//******************************************************************************
1443//******************************************************************************
1444BOOL WIN32API CloseWindow(HWND hwnd)
1445{
1446 Win32BaseWindow *window;
1447
1448 window = Win32BaseWindow::GetWindowFromHandle(hwnd);
1449 if(!window) {
1450 dprintf(("CloseWindow, window %x not found", hwnd));
1451 SetLastError(ERROR_INVALID_WINDOW_HANDLE);
1452 return 0;
1453 }
1454 dprintf(("CloseWindow %x\n", hwnd));
1455 return window->CloseWindow();
1456}
1457//******************************************************************************
1458//TODO: Does this return handles of hidden or disabled windows?
1459//******************************************************************************
1460HWND WIN32API WindowFromPoint( POINT point)
1461{
1462 HWND hwndOS2, hwnd;
1463 POINT wPoint;
1464
1465 wPoint.x = point.x;
1466 wPoint.y = mapScreenY(point.y);
1467
1468 hwndOS2 = OSLibWinWindowFromPoint(OSLIB_HWND_DESKTOP, (PVOID)&wPoint);
1469 if(hwndOS2)
1470 {
1471 hwnd = Win32BaseWindow::OS2ToWin32Handle(hwndOS2);
1472 if(hwnd) {
1473 dprintf(("WindowFromPoint (%d,%d) %x->%x\n", point.x, point.y, hwndOS2, hwnd));
1474 return hwnd;
1475 }
1476 }
1477 dprintf(("WindowFromPoint (%d,%d) %x->1\n", point.x, point.y, hwndOS2));
1478 return windowDesktop->getWindowHandle();
1479}
1480//******************************************************************************
1481//******************************************************************************
1482BOOL WIN32API IsWindowUnicode(HWND hwnd)
1483{
1484 Win32BaseWindow *window;
1485
1486 window = Win32BaseWindow::GetWindowFromHandle(hwnd);
1487 if(!window) {
1488 dprintf(("IsWindowUnicode, window %x not found", hwnd));
1489 SetLastError(ERROR_INVALID_WINDOW_HANDLE);
1490 return 0;
1491 }
1492 return window->IsWindowUnicode();
1493}
1494/***********************************************************************
1495 * SwitchToThisWindow (USER32.539)
1496 */
1497DWORD WINAPI SwitchToThisWindow( HWND hwnd, BOOL restore )
1498{
1499 return ShowWindow( hwnd, restore ? SW_RESTORE : SW_SHOWMINIMIZED );
1500}
1501//******************************************************************************
1502//******************************************************************************
1503BOOL WIN32API EnumThreadWindows(DWORD dwThreadId, WNDENUMPROC lpfn, LPARAM lParam)
1504{
1505 return windowDesktop->EnumThreadWindows(dwThreadId, lpfn, lParam);
1506}
1507//******************************************************************************
1508//******************************************************************************
1509BOOL WIN32API EnumChildWindows(HWND hwnd, WNDENUMPROC lpfn, LPARAM lParam)
1510{
1511 Win32BaseWindow *window;
1512 BOOL rc = TRUE;
1513 ULONG henum;
1514 HWND hwndNext;
1515
1516 if(lpfn == NULL) {
1517 dprintf(("EnumChildWindows invalid parameter %x %x\n", hwnd, lParam));
1518 SetLastError(ERROR_INVALID_PARAMETER);
1519 return FALSE;
1520 }
1521 window = Win32BaseWindow::GetWindowFromHandle(hwnd);
1522 if(!window) {
1523 dprintf(("EnumChildWindows, window %x not found", hwnd));
1524 SetLastError(ERROR_INVALID_WINDOW_HANDLE);
1525 return FALSE;
1526 }
1527 return window->EnumChildWindows(lpfn, lParam);
1528}
1529//******************************************************************************
1530//******************************************************************************
1531BOOL WIN32API EnumWindows(WNDENUMPROC lpfn, LPARAM lParam)
1532{
1533 return windowDesktop->EnumWindows(lpfn, lParam);
1534}
1535//******************************************************************************
1536//******************************************************************************
1537UINT WIN32API ArrangeIconicWindows( HWND hwnd)
1538{
1539 dprintf(("USER32: ArrangeIconicWindows %x", hwnd));
1540 return O32_ArrangeIconicWindows(Win32BaseWindow::Win32ToOS2Handle(hwnd));
1541}
1542//******************************************************************************
1543//restores iconized window to previous size/position
1544//******************************************************************************
1545BOOL WIN32API OpenIcon(HWND hwnd)
1546{
1547 dprintf(("USER32: OpenIcon"));
1548
1549 if(!IsIconic(hwnd))
1550 return FALSE;
1551 ShowWindow(hwnd, SW_SHOWNORMAL);
1552 return TRUE;
1553}
1554//******************************************************************************
1555//******************************************************************************
1556BOOL WIN32API ShowOwnedPopups( HWND hwnd, BOOL arg2)
1557{
1558 dprintf(("USER32: ShowOwnedPopups (OPEN32: todo) %x", hwnd));
1559 return O32_ShowOwnedPopups(Win32BaseWindow::Win32ToOS2Handle(hwnd), arg2);
1560}
1561//******************************************************************************
1562//******************************************************************************
1563HWND WIN32API GetForegroundWindow(void)
1564{
1565 HWND hwnd;
1566
1567 hwnd = Win32BaseWindow::OS2ToWin32Handle(OSLibWinQueryActiveWindow());
1568 dprintf(("USER32: GetForegroundWindow returned %x", hwnd));
1569 return hwnd;
1570}
1571//******************************************************************************
1572//******************************************************************************
1573HWND WIN32API GetLastActivePopup( HWND hWnd)
1574{
1575 HWND hwnd;
1576
1577 hWnd = Win32BaseWindow::Win32ToOS2Handle(hWnd);
1578
1579 hwnd = Win32BaseWindow::OS2ToWin32Handle(O32_GetLastActivePopup(hWnd));
1580
1581 dprintf(("GetLastActivePopup %x returned %x", hWnd, hwnd));
1582 return hwnd;
1583}
1584//******************************************************************************
1585//******************************************************************************
1586DWORD WIN32API GetWindowThreadProcessId(HWND hWnd, PDWORD lpdwProcessId)
1587{
1588 dprintf2(("USER32: GetWindowThreadProcessId"));
1589 hWnd = Win32BaseWindow::Win32ToOS2Handle(hWnd);
1590
1591 return O32_GetWindowThreadProcessId(hWnd,lpdwProcessId);
1592}
1593//******************************************************************************
1594//******************************************************************************
1595DWORD WIN32API GetWindowContextHelpId(HWND hwnd)
1596{
1597 Win32BaseWindow *window;
1598
1599 window = Win32BaseWindow::GetWindowFromHandle(hwnd);
1600 if(!window) {
1601 dprintf(("GetWindowContextHelpId, window %x not found", hwnd));
1602 SetLastError(ERROR_INVALID_WINDOW_HANDLE);
1603 return 0;
1604 }
1605 dprintf(("GetWindowContextHelpId %x", hwnd));
1606 return window->getWindowContextHelpId();
1607}
1608//******************************************************************************
1609//******************************************************************************
1610BOOL WIN32API SetWindowContextHelpId(HWND hwnd, DWORD dwContextHelpId)
1611{
1612 Win32BaseWindow *window;
1613
1614 window = Win32BaseWindow::GetWindowFromHandle(hwnd);
1615 if(!window) {
1616 dprintf(("SetWindowContextHelpId, window %x not found", hwnd));
1617 SetLastError(ERROR_INVALID_WINDOW_HANDLE);
1618 return 0;
1619 }
1620 dprintf(("SetWindowContextHelpId %x %d", hwnd, dwContextHelpId));
1621 window->setWindowContextHelpId(dwContextHelpId);
1622 return(TRUE);
1623}
1624//******************************************************************************
1625//******************************************************************************
1626HANDLE WINAPI GetPropA( HWND hwnd, LPCSTR str )
1627{
1628 Win32BaseWindow *window;
1629
1630 window = Win32BaseWindow::GetWindowFromHandle(hwnd);
1631 if(!window) {
1632 dprintf(("GetPropA, window %x not found", hwnd));
1633 SetLastError(ERROR_INVALID_WINDOW_HANDLE);
1634 return 0;
1635 }
1636 return window->getProp(str);
1637}
1638//******************************************************************************
1639//******************************************************************************
1640HANDLE WINAPI GetPropW( HWND hwnd, LPCWSTR str )
1641{
1642 LPSTR strA;
1643 HANDLE ret;
1644
1645 if (!HIWORD(str)) return GetPropA( hwnd, (LPCSTR)(UINT)LOWORD(str) );
1646 strA = HEAP_strdupWtoA( GetProcessHeap(), 0, str );
1647 ret = GetPropA( hwnd, strA );
1648 HeapFree( GetProcessHeap(), 0, strA );
1649 return ret;
1650}
1651//******************************************************************************
1652//******************************************************************************
1653BOOL WINAPI SetPropA( HWND hwnd, LPCSTR str, HANDLE handle )
1654{
1655 Win32BaseWindow *window;
1656
1657 window = Win32BaseWindow::GetWindowFromHandle(hwnd);
1658 if(!window) {
1659 dprintf(("SetPropA, window %x not found", hwnd));
1660 SetLastError(ERROR_INVALID_WINDOW_HANDLE);
1661 return FALSE;
1662 }
1663 return window->setProp(str, handle);
1664}
1665//******************************************************************************
1666//******************************************************************************
1667BOOL WINAPI SetPropW( HWND hwnd, LPCWSTR str, HANDLE handle )
1668{
1669 BOOL ret;
1670 LPSTR strA;
1671
1672 if (!HIWORD(str))
1673 return SetPropA( hwnd, (LPCSTR)(UINT)LOWORD(str), handle );
1674 strA = HEAP_strdupWtoA( GetProcessHeap(), 0, str );
1675 ret = SetPropA( hwnd, strA, handle );
1676 HeapFree( GetProcessHeap(), 0, strA );
1677 return ret;
1678}
1679//******************************************************************************
1680//******************************************************************************
1681HANDLE WINAPI RemovePropA( HWND hwnd, LPCSTR str )
1682{
1683 Win32BaseWindow *window;
1684
1685 window = Win32BaseWindow::GetWindowFromHandle(hwnd);
1686 if(!window) {
1687 dprintf(("RemovePropA, window %x not found", hwnd));
1688 SetLastError(ERROR_INVALID_WINDOW_HANDLE);
1689 return 0;
1690 }
1691 return window->removeProp(str);
1692}
1693//******************************************************************************
1694//******************************************************************************
1695HANDLE WINAPI RemovePropW( HWND hwnd, LPCWSTR str )
1696{
1697 LPSTR strA;
1698 HANDLE ret;
1699
1700 if (!HIWORD(str))
1701 return RemovePropA( hwnd, (LPCSTR)(UINT)LOWORD(str) );
1702 strA = HEAP_strdupWtoA( GetProcessHeap(), 0, str );
1703 ret = RemovePropA( hwnd, strA );
1704 HeapFree( GetProcessHeap(), 0, strA );
1705 return ret;
1706}
1707//******************************************************************************
1708//******************************************************************************
1709INT WINAPI EnumPropsA( HWND hwnd, PROPENUMPROCA func )
1710{
1711 return EnumPropsExA( hwnd, (PROPENUMPROCEXA)func, 0 );
1712}
1713//******************************************************************************
1714//******************************************************************************
1715INT WINAPI EnumPropsW( HWND hwnd, PROPENUMPROCW func )
1716{
1717 return EnumPropsExW( hwnd, (PROPENUMPROCEXW)func, 0 );
1718}
1719//******************************************************************************
1720//******************************************************************************
1721INT WINAPI EnumPropsExA(HWND hwnd, PROPENUMPROCEXA func, LPARAM lParam)
1722{
1723 Win32BaseWindow *window;
1724
1725 window = Win32BaseWindow::GetWindowFromHandle(hwnd);
1726 if(!window) {
1727 dprintf(("EnumPropsExA, window %x not found", hwnd));
1728 SetLastError(ERROR_INVALID_WINDOW_HANDLE);
1729 return -1;
1730 }
1731 return window->enumPropsExA(func, lParam);
1732}
1733//******************************************************************************
1734//******************************************************************************
1735INT WINAPI EnumPropsExW(HWND hwnd, PROPENUMPROCEXW func, LPARAM lParam)
1736{
1737 Win32BaseWindow *window;
1738
1739 window = Win32BaseWindow::GetWindowFromHandle(hwnd);
1740 if(!window) {
1741 dprintf(("EnumPropsExA, window %x not found", hwnd));
1742 SetLastError(ERROR_INVALID_WINDOW_HANDLE);
1743 return -1;
1744 }
1745 return window->enumPropsExW(func, lParam);
1746}
1747//******************************************************************************
1748//******************************************************************************
Note: See TracBrowser for help on using the repository browser.