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

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

Icon api rewrite + small fixes

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