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

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

Commented out winzip button change in BeginPaint (fixes repaint problems) + implemented IsZoomed)

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