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

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

mdi fix + ShowOwnedPopups implemented

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