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

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

Major rewrite: frame/client -> frame

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