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

Last change on this file since 1297 was 1297, checked in by sandervl, 26 years ago

Lots of window fixes & changes

File size: 44.4 KB
Line 
1/* $Id: window.cpp,v 1.15 1999-10-14 18:27:59 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 *
8 * Parts based on Wine Windows code (windows\win.c)
9 *
10 * Copyright 1993, 1994 Alexandre Julliard
11 *
12 * Project Odin Software License can be found in LICENSE.TXT
13 *
14 *
15 * TODO: Decide what to do about commands for OS/2 windows (non-Win32 apps)
16 *
17 */
18
19#include <os2win.h>
20#include <misc.h>
21#include <string.h>
22#include <stdio.h>
23#include <win32wbase.h>
24#include <win32wmdiclient.h>
25#include <win32wdesktop.h>
26#include "win32dlg.h"
27#include <oslibwin.h>
28#include <oslibgdi.h>
29#include "user32.h"
30#include "winicon.h"
31
32//******************************************************************************
33//******************************************************************************
34HWND WIN32API CreateWindowExA(DWORD exStyle, LPCSTR className,
35 LPCSTR windowName, DWORD style, INT x,
36 INT y, INT width, INT height,
37 HWND parent, HMENU menu,
38 HINSTANCE instance, LPVOID data )
39{
40 Win32BaseWindow *window;
41 ATOM classAtom;
42 CREATESTRUCTA cs;
43 char tmpClass[20];
44
45 if(exStyle & WS_EX_MDICHILD)
46 return CreateMDIWindowA(className, windowName, style, x, y, width, height, parent, instance, (LPARAM)data);
47
48 /* Find the class atom */
49 if (!(classAtom = GlobalFindAtomA(className)))
50 {
51 if (!HIWORD(className))
52 {
53 sprintf(tmpClass,"#%d", (int) className);
54 classAtom = GlobalFindAtomA(tmpClass);
55 className = tmpClass;
56 }
57 if (!classAtom)
58 {
59 if (!HIWORD(className)) {
60 dprintf(("CreateWindowEx32W: bad class name %04x\n", LOWORD(className)));
61 }
62 else dprintf(("CreateWindowEx32W: bad class name '%s'\n", className ));
63
64 SetLastError(ERROR_INVALID_PARAMETER);
65 return 0;
66 }
67 }
68
69 /* Create the window */
70 cs.lpCreateParams = data;
71 cs.hInstance = instance;
72 cs.hMenu = menu;
73 cs.hwndParent = parent;
74 cs.x = x;
75 cs.y = y;
76 cs.cx = width;
77 cs.cy = height;
78 cs.style = style;
79 cs.lpszName = windowName;
80 cs.lpszClass = className;
81 cs.dwExStyle = exStyle;
82 if(HIWORD(className)) {
83 dprintf(("CreateWindowExA: class %s parent %x (%d,%d) (%d,%d), %x %x", className, parent, x, y, width, height, style, exStyle));
84 }
85 else dprintf(("CreateWindowExA: class %d parent %x (%d,%d) (%d,%d), %x %x", className, parent, x, y, width, height, style, exStyle));
86
87 if(!strcmpi(className, MDICLIENTCLASSNAMEA)) {
88 window = (Win32BaseWindow *) new Win32MDIClientWindow(&cs, classAtom, FALSE);
89 }
90 else
91 if(!strcmpi((char *) className, DIALOG_CLASS_NAMEA))
92 {
93 DLG_TEMPLATE dlgTemplate = {0};
94 dlgTemplate.style = cs.style;
95 dlgTemplate.exStyle = cs.dwExStyle;
96 dlgTemplate.x = cs.x;
97 dlgTemplate.y = cs.y;
98 dlgTemplate.cx = cs.cx;
99 dlgTemplate.cy = cs.cy;
100 dlgTemplate.className = cs.lpszClass;
101 dlgTemplate.caption = cs.lpszName;
102 window = (Win32BaseWindow *) new Win32Dialog(cs.hInstance,
103 (LPCSTR) &dlgTemplate,
104 cs.hwndParent,
105 NULL,
106 (LPARAM) data,
107 FALSE);
108 }
109 else {
110 window = new Win32BaseWindow( &cs, classAtom, FALSE );
111 }
112 if(window == NULL)
113 {
114 dprintf(("Win32BaseWindow creation failed!!"));
115 return 0;
116 }
117 if(GetLastError() != 0)
118 {
119 dprintf(("Win32BaseWindow error found!!"));
120 delete window;
121 return 0;
122 }
123 return window->getWindowHandle();
124}
125//******************************************************************************
126//******************************************************************************
127HWND WIN32API CreateWindowExW(DWORD exStyle, LPCWSTR className,
128 LPCWSTR windowName, DWORD style, INT x,
129 INT y, INT width, INT height,
130 HWND parent, HMENU menu,
131 HINSTANCE instance, LPVOID data )
132{
133 Win32BaseWindow *window;
134 ATOM classAtom;
135 CREATESTRUCTA cs;
136 char tmpClassA[20];
137 WCHAR tmpClassW[20];
138
139 if(exStyle & WS_EX_MDICHILD)
140 return CreateMDIWindowW(className, windowName, style, x, y, width, height, parent, instance, (LPARAM)data);
141
142 /* Find the class atom */
143 if (!(classAtom = GlobalFindAtomW(className)))
144 {
145 if (!HIWORD(className))
146 {
147 sprintf(tmpClassA,"#%d", (int) className);
148 AsciiToUnicode(tmpClassA, tmpClassW);
149 classAtom = GlobalFindAtomW(tmpClassW);
150 className = (LPCWSTR)tmpClassW;
151 }
152 if (!classAtom)
153 {
154 if (!HIWORD(className)) {
155 dprintf(("CreateWindowEx32W: bad class name %04x\n", LOWORD(className)));
156 }
157 else dprintf(("CreateWindowEx32W: bad class name "));
158
159 SetLastError(ERROR_INVALID_PARAMETER);
160 return 0;
161 }
162 }
163
164 /* Create the window */
165 cs.lpCreateParams = data;
166 cs.hInstance = instance;
167 cs.hMenu = menu;
168 cs.hwndParent = parent;
169 cs.x = x;
170 cs.y = y;
171 cs.cx = width;
172 cs.cy = height;
173 cs.style = style;
174 cs.lpszName = (LPSTR)windowName;
175 cs.lpszClass = (LPSTR)className;
176 cs.dwExStyle = exStyle;
177
178 if(!lstrcmpiW(className, (LPWSTR)MDICLIENTCLASSNAMEW)) {
179 window = (Win32BaseWindow *) new Win32MDIClientWindow(&cs, classAtom, TRUE);
180 }
181 else
182 if(!lstrcmpiW(className, (LPWSTR)DIALOG_CLASS_NAMEW))
183 {
184 DLG_TEMPLATE dlgTemplate = {0};
185 dlgTemplate.style = cs.style;
186 dlgTemplate.exStyle = cs.dwExStyle;
187 dlgTemplate.x = cs.x;
188 dlgTemplate.y = cs.y;
189 dlgTemplate.cx = cs.cx;
190 dlgTemplate.cy = cs.cy;
191 dlgTemplate.className = cs.lpszClass;
192 dlgTemplate.caption = cs.lpszName;
193 window = (Win32BaseWindow *) new Win32Dialog(cs.hInstance,
194 (LPCSTR) &dlgTemplate,
195 cs.hwndParent,
196 NULL,
197 (LPARAM) data,
198 TRUE);
199 }
200 else {
201 window = new Win32BaseWindow( &cs, classAtom, TRUE );
202 }
203 if(window == NULL)
204 {
205 dprintf(("Win32BaseWindow creation failed!!"));
206 return 0;
207 }
208 if(GetLastError() != 0)
209 {
210 dprintf(("Win32BaseWindow error found!!"));
211 delete window;
212 return 0;
213 }
214 return window->getWindowHandle();
215}
216//******************************************************************************
217//******************************************************************************
218HWND WIN32API CreateMDIWindowA(LPCSTR lpszClassName, LPCSTR lpszWindowName,
219 DWORD dwStyle, int x, int y, int nWidth,
220 int nHeight, HWND hwndParent,
221 HINSTANCE hInstance, LPARAM lParam )
222{
223 HWND hwnd;
224 MDICREATESTRUCTA cs;
225 Win32BaseWindow *window;
226
227 window = Win32BaseWindow::GetWindowFromHandle(hwndParent);
228 if(!window) {
229 dprintf(("CreateMDIWindowA, window %x not found", hwndParent));
230 return 0;
231 }
232
233 dprintf(("USER32: CreateMDIWindowA\n"));
234 cs.szClass = lpszClassName;
235 cs.szTitle = lpszWindowName;
236 cs.hOwner = hInstance;
237 cs.x = x;
238 cs.y = y;
239 cs.cx = nHeight;
240 cs.cy = nWidth;
241 cs.style = dwStyle;
242 cs.lParam = lParam;
243
244 return window->SendMessageA(WM_MDICREATE, 0, (LPARAM)&cs);
245}
246//******************************************************************************
247//******************************************************************************
248HWND WIN32API CreateMDIWindowW(LPCWSTR lpszClassName, LPCWSTR lpszWindowName,
249 DWORD dwStyle, int x, int y, int nWidth,
250 int nHeight, HWND hwndParent,
251 HINSTANCE hInstance, LPARAM lParam )
252{
253 HWND hwnd;
254 MDICREATESTRUCTW cs;
255 Win32BaseWindow *window;
256
257 window = Win32BaseWindow::GetWindowFromHandle(hwndParent);
258 if(!window) {
259 dprintf(("CreateMDIWindowW, window %x not found", hwndParent));
260 SetLastError(ERROR_INVALID_WINDOW_HANDLE);
261 return 0;
262 }
263
264 dprintf(("USER32: CreateMDIWindowW\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->SendMessageW(WM_MDICREATE, 0, (LPARAM)&cs);
276}
277//******************************************************************************
278//******************************************************************************
279BOOL WIN32API DestroyWindow(HWND hwnd)
280{
281 Win32BaseWindow *window;
282
283 window = Win32BaseWindow::GetWindowFromHandle(hwnd);
284 if(!window) {
285 dprintf(("DestroyWindow, window %x not found", hwnd));
286 SetLastError(ERROR_INVALID_WINDOW_HANDLE);
287 return 0;
288 }
289 dprintf(("DestroyWindow %x", hwnd));
290 return window->DestroyWindow();
291}
292//******************************************************************************
293//******************************************************************************
294HWND WIN32API SetActiveWindow( HWND hwnd)
295{
296 Win32BaseWindow *window;
297
298 window = Win32BaseWindow::GetWindowFromHandle(hwnd);
299 if(!window) {
300 dprintf(("SetActiveWindow, window %x not found", hwnd));
301 SetLastError(ERROR_INVALID_WINDOW_HANDLE);
302 return 0;
303 }
304 dprintf(("SetActiveWindow %x", hwnd));
305 return window->SetActiveWindow();
306}
307//******************************************************************************
308//******************************************************************************
309HWND WIN32API GetParent( HWND hwnd)
310{
311 Win32BaseWindow *window;
312
313 window = Win32BaseWindow::GetWindowFromHandle(hwnd);
314 if(!window) {
315 dprintf(("GetParent, window %x not found", hwnd));
316 SetLastError(ERROR_INVALID_WINDOW_HANDLE);
317 return 0;
318 }
319 dprintf(("GetParent %x", hwnd));
320 return window->GetParent();
321}
322//******************************************************************************
323//******************************************************************************
324HWND WIN32API SetParent( HWND hwndChild, HWND hwndNewParent)
325{
326 Win32BaseWindow *window;
327
328 window = Win32BaseWindow::GetWindowFromHandle(hwndChild);
329 if(!window) {
330 dprintf(("SetParent, window %x not found", hwndChild));
331 SetLastError(ERROR_INVALID_WINDOW_HANDLE);
332 return 0;
333 }
334 dprintf(("SetParent %x %x", hwndChild, hwndNewParent));
335 return window->SetParent(hwndNewParent);
336}
337//******************************************************************************
338//******************************************************************************
339BOOL WIN32API IsChild( HWND hwndParent, HWND hwnd)
340{
341 Win32BaseWindow *window;
342
343 window = Win32BaseWindow::GetWindowFromHandle(hwnd);
344 if(!window) {
345 dprintf(("IsChild, window %x not found", hwnd));
346 SetLastError(ERROR_INVALID_WINDOW_HANDLE);
347 return 0;
348 }
349 dprintf(("IsChild %x %x", hwndParent, hwnd));
350 return window->IsChild(hwndParent);
351}
352//******************************************************************************
353//******************************************************************************
354HWND WIN32API GetTopWindow( HWND hwnd)
355{
356 Win32BaseWindow *window;
357
358 window = Win32BaseWindow::GetWindowFromHandle(hwnd);
359 if(!window) {
360 dprintf(("GetTopWindow, window %x not found", hwnd));
361 SetLastError(ERROR_INVALID_WINDOW_HANDLE);
362 return 0;
363 }
364 return window->GetTopWindow();
365}
366//******************************************************************************
367//******************************************************************************
368#if 0
369BOOL WIN32API UpdateWindow(HWND hwnd)
370{
371 Win32BaseWindow *window;
372
373 window = Win32BaseWindow::GetWindowFromHandle(hwnd);
374 if(!window) {
375 dprintf(("UpdateWindow, window %x not found", hwnd));
376 return 0;
377 }
378 dprintf(("UpdateWindow %x", hwnd));
379 return window->UpdateWindow();
380}
381#endif
382//******************************************************************************
383//******************************************************************************
384BOOL WIN32API IsIconic( HWND hwnd)
385{
386 Win32BaseWindow *window;
387
388 window = Win32BaseWindow::GetWindowFromHandle(hwnd);
389 if(!window) {
390 dprintf(("IsIconic, window %x not found", hwnd));
391 SetLastError(ERROR_INVALID_WINDOW_HANDLE);
392 return 0;
393 }
394 dprintf(("IsIconic %x", hwnd));
395 return window->IsIconic();
396}
397//******************************************************************************
398//******************************************************************************
399HWND WIN32API GetWindow(HWND hwnd, UINT uCmd)
400{
401 Win32BaseWindow *window;
402
403 window = Win32BaseWindow::GetWindowFromHandle(hwnd);
404 if(!window) {
405 dprintf(("GetWindow, window %x not found", hwnd));
406 SetLastError(ERROR_INVALID_WINDOW_HANDLE);
407 return 0;
408 }
409 dprintf(("GetWindow %x %d", hwnd, uCmd));
410 return window->GetWindow(uCmd);
411}
412//******************************************************************************
413//******************************************************************************
414BOOL WIN32API EnableWindow( HWND hwnd, BOOL fEnable)
415{
416 Win32BaseWindow *window;
417
418 window = Win32BaseWindow::GetWindowFromHandle(hwnd);
419 if(!window) {
420 dprintf(("EnableWindow, window %x not found", hwnd));
421 SetLastError(ERROR_INVALID_WINDOW_HANDLE);
422 return 0;
423 }
424 dprintf(("EnableWindow %x %d", hwnd, fEnable));
425 return window->EnableWindow(fEnable);
426}
427//******************************************************************************
428//******************************************************************************
429BOOL WIN32API BringWindowToTop(HWND hwnd)
430{
431 return SetWindowPos( hwnd, HWND_TOP, 0, 0, 0, 0, SWP_NOMOVE|SWP_NOSIZE );
432}
433//******************************************************************************
434//******************************************************************************
435HWND WIN32API GetActiveWindow()
436{
437 return Win32BaseWindow::GetActiveWindow();
438}
439//******************************************************************************
440//******************************************************************************
441BOOL WIN32API ShowWindow(HWND hwnd, int nCmdShow)
442{
443 Win32BaseWindow *window;
444
445 window = Win32BaseWindow::GetWindowFromHandle(hwnd);
446 if(!window) {
447 dprintf(("ShowWindow, window %x not found", hwnd));
448 SetLastError(ERROR_INVALID_WINDOW_HANDLE);
449 return 0;
450 }
451 dprintf(("ShowWindow %x", hwnd));
452 return window->ShowWindow(nCmdShow);
453}
454//******************************************************************************
455//******************************************************************************
456BOOL WIN32API SetWindowPos(HWND hwnd, HWND hwndInsertAfter, int x, int y, int cx, int cy, UINT fuFlags)
457{
458 Win32BaseWindow *window;
459
460 window = Win32BaseWindow::GetWindowFromHandle(hwnd);
461 if(!window) {
462 dprintf(("SetWindowPos, window %x not found", hwnd));
463 SetLastError(ERROR_INVALID_WINDOW_HANDLE);
464 return 0;
465 }
466 dprintf(("SetWindowPos %x %x x=%d y=%d cx=%d cy=%d %x", hwnd, hwndInsertAfter, x, y, cx, cy, fuFlags));
467 return window->SetWindowPos(hwndInsertAfter, x, y, cx, cy, fuFlags);
468}
469//******************************************************************************
470//******************************************************************************
471BOOL WIN32API SetWindowPlacement( HWND arg1, const WINDOWPLACEMENT * arg2)
472{
473 dprintf(("USER32: SetWindowPlacement\n"));
474 return O32_SetWindowPlacement(arg1, arg2);
475}
476//******************************************************************************
477//******************************************************************************
478BOOL WIN32API GetWindowPlacement( HWND arg1, LPWINDOWPLACEMENT arg2)
479{
480#ifdef DEBUG
481 WriteLog("USER32: GetWindowPlacement\n");
482#endif
483 return O32_GetWindowPlacement(arg1, arg2);
484}
485//******************************************************************************
486//******************************************************************************
487BOOL WIN32API IsWindow( HWND hwnd)
488{
489 Win32BaseWindow *window;
490
491 window = Win32BaseWindow::GetWindowFromHandle(hwnd);
492 if(!window) {
493 dprintf(("IsWindow, window %x not found", hwnd));
494 return FALSE;
495 }
496 dprintf(("IsWindow %x", hwnd));
497 return window->IsWindow();
498}
499//******************************************************************************
500//******************************************************************************
501BOOL WIN32API IsWindowEnabled( HWND hwnd)
502{
503 Win32BaseWindow *window;
504
505 window = Win32BaseWindow::GetWindowFromHandle(hwnd);
506 if(!window) {
507 dprintf(("IsWindowEnabled, window %x not found", hwnd));
508 return 0;
509 }
510 dprintf(("IsWindowEnabled %x", hwnd));
511 return window->IsWindowEnabled();
512}
513//******************************************************************************
514//******************************************************************************
515BOOL WIN32API IsWindowVisible( HWND hwnd)
516{
517 Win32BaseWindow *window;
518
519 window = Win32BaseWindow::GetWindowFromHandle(hwnd);
520 if(!window) {
521 dprintf(("IsWindowVisible, window %x not found", hwnd));
522 SetLastError(ERROR_INVALID_WINDOW_HANDLE);
523 return 0;
524 }
525 dprintf(("IsWindowVisible %x", hwnd));
526 return window->IsWindowVisible();
527}
528//******************************************************************************
529//******************************************************************************
530HWND WIN32API SetFocus (HWND hwnd)
531{
532 HWND lastFocus, lastFocus_W, hwnd_O;
533 BOOL activate;
534
535 hwnd_O = Win32BaseWindow::Win32ToOS2Handle (hwnd);
536 lastFocus = OSLibWinQueryFocus (OSLIB_HWND_DESKTOP);
537 activate = ((hwnd_O == lastFocus) || OSLibWinIsChild (lastFocus, hwnd_O));
538 lastFocus_W = Win32BaseWindow::OS2ToWin32Handle (lastFocus);
539
540 dprintf(("SetFocus %x (%x) -> %x (%x)\n", lastFocus_W, lastFocus, hwnd, hwnd_O));
541
542 return (OSLibWinSetFocus (OSLIB_HWND_DESKTOP, hwnd_O, activate)) ? lastFocus_W : 0;
543}
544//******************************************************************************
545//******************************************************************************
546HWND WIN32API GetFocus(void)
547{
548 HWND hwnd;
549
550 hwnd = OSLibWinQueryFocus(OSLIB_HWND_DESKTOP);
551 dprintf(("USER32: GetFocus %x\n", hwnd));
552 hwnd = Win32BaseWindow::OS2ToWin32Handle(hwnd);
553 return hwnd;
554}
555//******************************************************************************
556//******************************************************************************
557/***********************************************************************
558 * GetInternalWindowPos (USER32.245)
559 */
560UINT WIN32API GetInternalWindowPos(HWND hwnd,
561 LPRECT rectWnd,
562 LPPOINT ptIcon )
563{
564 WINDOWPLACEMENT wndpl;
565
566 dprintf(("USER32: GetInternalWindowPos(%08xh,%08xh,%08xh)\n",
567 hwnd,
568 rectWnd,
569 ptIcon));
570
571 if (GetWindowPlacement( hwnd, &wndpl ))
572 {
573 if (rectWnd) *rectWnd = wndpl.rcNormalPosition;
574 if (ptIcon) *ptIcon = wndpl.ptMinPosition;
575 return wndpl.showCmd;
576 }
577 return 0;
578}
579//******************************************************************************
580//******************************************************************************
581BOOL WIN32API IsZoomed( HWND arg1)
582{
583#ifdef DEBUG
584 WriteLog("USER32: IsZoomed\n");
585#endif
586 return O32_IsZoomed(arg1);
587}
588//******************************************************************************
589//******************************************************************************
590BOOL WIN32API LockWindowUpdate( HWND arg1)
591{
592#ifdef DEBUG
593 WriteLog("USER32: LockWindowUpdate\n");
594#endif
595 return O32_LockWindowUpdate(arg1);
596}
597//******************************************************************************
598//******************************************************************************
599
600#if 0
601BOOL WIN32API RedrawWindow( HWND arg1, const RECT * arg2, HRGN arg3, UINT arg4)
602{
603 BOOL rc;
604
605 rc = O32_RedrawWindow(arg1, arg2, arg3, arg4);
606#ifdef DEBUG
607 WriteLog("USER32: RedrawWindow %X , %X, %X, %X returned %d\n", arg1, arg2, arg3, arg4, rc);
608#endif
609 InvalidateRect(arg1, arg2, TRUE);
610 UpdateWindow(arg1);
611 SendMessageA(arg1, WM_PAINT, 0, 0);
612 return(rc);
613}
614#endif
615//******************************************************************************
616//******************************************************************************
617BOOL WIN32API GetWindowRect( HWND hwnd, PRECT pRect)
618{
619 Win32BaseWindow *window;
620 BOOL rc;
621
622 window = Win32BaseWindow::GetWindowFromHandle(hwnd);
623 if(!window) {
624 dprintf(("GetWindowRect, window %x not found", hwnd));
625 SetLastError(ERROR_INVALID_WINDOW_HANDLE);
626 return 0;
627 }
628 rc = window->GetWindowRect(pRect);
629 dprintf(("GetWindowRect %x (%d,%d) (%d,%d)", hwnd, pRect->left, pRect->top, pRect->right, pRect->bottom));
630 return rc;
631}
632//******************************************************************************
633//******************************************************************************
634int WIN32API GetWindowTextLengthA( HWND hwnd)
635{
636 Win32BaseWindow *window;
637
638 window = Win32BaseWindow::GetWindowFromHandle(hwnd);
639 if(!window) {
640 dprintf(("GetWindowTextLength, window %x not found", hwnd));
641 SetLastError(ERROR_INVALID_WINDOW_HANDLE);
642 return 0;
643 }
644 dprintf(("GetWindowTextLength %x", hwnd));
645 return window->GetWindowTextLength();
646}
647//******************************************************************************
648//******************************************************************************
649int WIN32API GetWindowTextA( HWND hwnd, LPSTR lpsz, int cch)
650{
651 Win32BaseWindow *window;
652 int rc;
653
654 window = Win32BaseWindow::GetWindowFromHandle(hwnd);
655 if(!window) {
656 dprintf(("GetWindowTextA, window %x not found", hwnd));
657 SetLastError(ERROR_INVALID_WINDOW_HANDLE);
658 return 0;
659 }
660 rc = window->GetWindowTextA(lpsz, cch);
661 dprintf(("GetWindowTextA %x %s", hwnd, lpsz));
662 return rc;
663}
664//******************************************************************************
665//******************************************************************************
666int WIN32API GetWindowTextLengthW( HWND hwnd)
667{
668 dprintf(("USER32: GetWindowTextLengthW\n"));
669 return GetWindowTextLengthA(hwnd);
670}
671//******************************************************************************
672//******************************************************************************
673int WIN32API GetWindowTextW(HWND hwnd, LPWSTR lpsz, int cch)
674{
675 Win32BaseWindow *window;
676
677 window = Win32BaseWindow::GetWindowFromHandle(hwnd);
678 if(!window) {
679 dprintf(("GetWindowTextW, window %x not found", hwnd));
680 SetLastError(ERROR_INVALID_WINDOW_HANDLE);
681 return 0;
682 }
683 dprintf(("GetWindowTextW %x", hwnd));
684 return window->GetWindowTextW(lpsz, cch);
685}
686//******************************************************************************
687//******************************************************************************
688BOOL WIN32API SetWindowTextA(HWND hwnd, LPCSTR lpsz)
689{
690 Win32BaseWindow *window;
691
692 window = Win32BaseWindow::GetWindowFromHandle(hwnd);
693 if(!window) {
694 dprintf(("SetWindowTextA, window %x not found", hwnd));
695 SetLastError(ERROR_INVALID_WINDOW_HANDLE);
696 return 0;
697 }
698 dprintf(("SetWindowTextA %x %s", hwnd, lpsz));
699 return window->SetWindowTextA((LPSTR)lpsz);
700}
701//******************************************************************************
702//******************************************************************************
703BOOL WIN32API SetWindowTextW( HWND hwnd, LPCWSTR lpsz)
704{
705 Win32BaseWindow *window;
706
707 window = Win32BaseWindow::GetWindowFromHandle(hwnd);
708 if(!window) {
709 dprintf(("SetWindowTextA, window %x not found", hwnd));
710 SetLastError(ERROR_INVALID_WINDOW_HANDLE);
711 return 0;
712 }
713 dprintf(("SetWindowTextW %x", hwnd));
714 return window->SetWindowTextW((LPWSTR)lpsz);
715}
716/*******************************************************************
717 * InternalGetWindowText (USER32.326)
718 */
719int WIN32API InternalGetWindowText(HWND hwnd,
720 LPWSTR lpString,
721 INT nMaxCount )
722{
723 dprintf(("USER32: InternalGetWindowText(%08xh,%08xh,%08xh) not properly implemented.\n",
724 hwnd,
725 lpString,
726 nMaxCount));
727
728 return GetWindowTextW(hwnd,lpString,nMaxCount);
729}
730//******************************************************************************
731//TODO: Correct?
732//******************************************************************************
733BOOL WIN32API SetForegroundWindow(HWND hwnd)
734{
735 dprintf((" SetForegroundWindow %x", hwnd));
736
737 return SetWindowPos( hwnd, HWND_TOP, 0, 0, 0, 0, SWP_NOMOVE | SWP_NOSIZE | SWP_NOZORDER );
738}
739//******************************************************************************
740//******************************************************************************
741BOOL WIN32API GetClientRect( HWND hwnd, PRECT pRect)
742{
743 BOOL rc;
744 HWND hwndWin32 = hwnd;
745
746 hwnd = Win32BaseWindow::Win32ToOS2Handle(hwnd);
747 rc = OSLibWinQueryWindowRect(hwnd, pRect);
748 dprintf(("GetClientRect of %X returned (%d,%d) (%d,%d)\n", hwndWin32, pRect->left, pRect->top, pRect->right, pRect->bottom));
749 return rc;
750}
751//******************************************************************************
752//******************************************************************************
753BOOL WIN32API AdjustWindowRect( PRECT arg1, DWORD arg2, BOOL arg3)
754{
755#ifdef DEBUG
756 WriteLog("USER32: AdjustWindowRect\n");
757#endif
758 return O32_AdjustWindowRect(arg1, arg2, arg3);
759}
760//******************************************************************************
761//******************************************************************************
762BOOL WIN32API AdjustWindowRectEx( PRECT arg1, DWORD arg2, BOOL arg3, DWORD arg4)
763{
764#ifdef DEBUG
765 WriteLog("USER32: AdjustWindowRectEx\n");
766#endif
767 return O32_AdjustWindowRectEx(arg1, arg2, arg3, arg4);
768}
769//******************************************************************************
770//******************************************************************************
771HWND WIN32API GetDesktopWindow(void)
772{
773 dprintf(("USER32: GetDesktopWindow\n"));
774 return windowDesktop->getWindowHandle();
775}
776//******************************************************************************
777//******************************************************************************
778HWND WIN32API FindWindowA(LPCSTR lpszClass, LPCSTR lpszWindow)
779{
780 if(!lpszClass) {
781 SetLastError(ERROR_INVALID_PARAMETER);
782 return 0;
783 }
784 if(HIWORD(lpszClass)) {
785 dprintf(("USER32: FindWindow %s %s\n", lpszClass, lpszWindow));
786 }
787 else dprintf(("USER32: FindWindow %x %s\n", lpszClass, lpszWindow));
788
789 return Win32BaseWindow::FindWindowEx(OSLIB_HWND_DESKTOP, 0, (LPSTR)lpszClass, (LPSTR)lpszWindow);
790}
791//******************************************************************************
792//******************************************************************************
793HWND WIN32API FindWindowExA(HWND hwndParent, HWND hwndChildAfter, LPCSTR lpszClass, LPCSTR lpszWindow)
794{
795 if(!lpszClass) {
796 SetLastError(ERROR_INVALID_PARAMETER);
797 return 0;
798 }
799 if(HIWORD(lpszClass)) {
800 dprintf(("USER32: FindWindowExA (%x,%x) %s %s\n", hwndParent, hwndChildAfter, lpszClass, lpszWindow));
801 }
802 else dprintf(("USER32: FindWindowExA (%x,%x)%x %s\n", hwndParent, hwndChildAfter, lpszClass, lpszWindow));
803
804 return Win32BaseWindow::FindWindowEx(hwndParent, hwndChildAfter, (LPSTR)lpszClass, (LPSTR)lpszWindow);
805}
806/*****************************************************************************
807 * Name : HWND WIN32API FindWindowExW
808 * Purpose : The FindWindowEx function retrieves the handle of a window whose
809 * class name and window name match the specified strings. The
810 * function searches child windows, beginning with the one following
811 * the given child window.
812 * Parameters: HWND hwndParent handle of parent window
813 * HWND hwndChildAfter handle of a child window
814 * LPCTSTR lpszClass address of class name
815 * LPCTSTR lpszWindow address of window name
816 * Variables :
817 * Result : If the function succeeds, the return value is the handle of the
818 * window that has the specified class and window names.
819 * If the function fails, the return value is NULL. To get extended
820 * error information, call GetLastError.
821 * Remark :
822 * Status : UNTESTED STUB
823 *
824 * Author : Patrick Haller [Thu, 1998/02/26 11:55]
825 *****************************************************************************/
826
827HWND WIN32API FindWindowExW(HWND hwndParent,
828 HWND hwndChildAfter,
829 LPCWSTR lpszClass,
830 LPCWSTR lpszWindow)
831{
832 if(!lpszClass) {
833 SetLastError(ERROR_INVALID_PARAMETER);
834 return 0;
835 }
836 dprintf(("USER32: FindWindowExW (%x,%x) %x %s\n", hwndParent, hwndChildAfter, lpszClass, lpszWindow));
837
838 return Win32BaseWindow::FindWindowEx(hwndParent, hwndChildAfter, (LPSTR)lpszClass, (LPSTR)lpszWindow);
839}
840//******************************************************************************
841//******************************************************************************
842BOOL WIN32API FlashWindow(HWND hwnd, BOOL fFlash)
843{
844 dprintf(("FlashWindow %x %d\n", hwnd, fFlash));
845 return OSLibWinFlashWindow(Win32BaseWindow::Win32ToOS2Handle(hwnd), fFlash);
846}
847//******************************************************************************
848//******************************************************************************
849BOOL WIN32API MoveWindow( HWND hwnd, INT x, INT y, INT cx, INT cy,
850 BOOL repaint )
851{
852 int flags = SWP_NOZORDER | SWP_NOACTIVATE;
853
854 if (!repaint) flags |= SWP_NOREDRAW;
855 dprintf(("MoveWindow: %04x %d,%d %dx%d %d\n", hwnd, x, y, cx, cy, repaint ));
856
857 return SetWindowPos( hwnd, 0, x, y, cx, cy, flags );
858}
859//******************************************************************************
860//******************************************************************************
861BOOL WIN32API ClientToScreen (HWND hwnd, PPOINT pt)
862{
863#ifdef DEBUG
864 WriteLog("USER32: ClientToScreen\n");
865#endif
866 Win32BaseWindow *wnd;
867 PRECT rcl;
868
869 if (!hwnd) {
870 SetLastError(ERROR_INVALID_PARAMETER);
871 return (FALSE);
872 }
873 wnd = Win32BaseWindow::GetWindowFromHandle (hwnd);
874 if (!wnd) {
875 SetLastError(ERROR_INVALID_WINDOW_HANDLE);
876 return (FALSE);
877 }
878
879 rcl = wnd->getClientRect();
880 pt->y = (rcl->bottom - rcl->top) - pt->y;
881 OSLibWinMapWindowPoints (wnd->getOS2WindowHandle(), OSLIB_HWND_DESKTOP, (OSLIBPOINT *)pt, 1);
882 pt->y = ScreenHeight - pt->y;
883 return (TRUE);
884}
885//******************************************************************************
886//******************************************************************************
887HDWP WIN32API BeginDeferWindowPos( int arg1)
888{
889#ifdef DEBUG
890 WriteLog("USER32: BeginDeferWindowPos\n");
891#endif
892 return O32_BeginDeferWindowPos(arg1);
893}
894//******************************************************************************
895//******************************************************************************
896HDWP WIN32API DeferWindowPos( HDWP arg1, HWND arg2, HWND arg3, int arg4, int arg5, int arg6, int arg7, UINT arg8)
897{
898#ifdef DEBUG
899 WriteLog("USER32: DeferWindowPos\n");
900#endif
901 return O32_DeferWindowPos(arg1, arg2, arg3, arg4, arg5, arg6, arg7, arg8);
902}
903//******************************************************************************
904//******************************************************************************
905HWND WIN32API ChildWindowFromPoint( HWND hwnd, POINT pt)
906{
907 dprintf(("USER32: ChildWindowFromPoint\n"));
908// return O32_ChildWindowFromPoint(arg1, arg2);
909 return ChildWindowFromPointEx(hwnd, pt, 0);
910}
911//******************************************************************************
912//******************************************************************************
913/*****************************************************************************
914 * Name : HWND WIN32API ChildWindowFromPointEx
915 * Purpose : The GetWindowRect function retrieves the dimensions of the
916 * bounding rectangle of the specified window. The dimensions are
917 * given in screen coordinates that are relative to the upper-left
918 * corner of the screen.
919 * Parameters:
920 * Variables :
921 * Result : If the function succeeds, the return value is the window handle.
922 * If the function fails, the return value is zero
923 * Remark :
924 * Status : FULLY IMPLEMENTED AND TESTED
925 *
926 * Author : Rene Pronk [Sun, 1999/08/08 23:30]
927 *****************************************************************************/
928
929HWND WIN32API ChildWindowFromPointEx (HWND hwndParent, POINT pt, UINT uFlags)
930{
931 RECT rect;
932 HWND hWnd;
933 POINT absolutePt;
934
935 dprintf(("ChildWindowFromPointEx(%08xh,%08xh,%08xh).\n",
936 hwndParent, pt, uFlags));
937
938 if (GetWindowRect (hwndParent, &rect) == 0) {
939 // oops, invalid handle
940 SetLastError(ERROR_INVALID_WINDOW_HANDLE);
941 return NULL;
942 }
943
944 // absolutePt has its top in the upper-left corner of the screen
945 absolutePt = pt;
946 ClientToScreen (hwndParent, &absolutePt);
947
948 // make rect the size of the parent window
949 GetWindowRect (hwndParent, &rect);
950 rect.right = rect.right - rect.left;
951 rect.bottom = rect.bottom - rect.top;
952 rect.left = 0;
953 rect.top = 0;
954
955 if (PtInRect (&rect, pt) == 0) {
956 // point is outside window
957 return NULL;
958 }
959
960 // get first child
961 hWnd = GetWindow (hwndParent, GW_CHILD);
962
963 while (hWnd != NULL) {
964
965 // do I need to skip this window?
966 if (((uFlags & CWP_SKIPINVISIBLE) &&
967 (IsWindowVisible (hWnd) == FALSE)) ||
968 ((uFlags & CWP_SKIPDISABLED) &&
969 (IsWindowEnabled (hWnd) == FALSE)) ||
970 ((uFlags & CWP_SKIPTRANSPARENT) &&
971 (GetWindowLongA (hWnd, GWL_EXSTYLE) & WS_EX_TRANSPARENT)))
972
973 {
974 hWnd = GetWindow (hWnd, GW_HWNDNEXT);
975 continue;
976 }
977
978 // is the point in this window's rect?
979 GetWindowRect (hWnd, &rect);
980 if (PtInRect (&rect, absolutePt) == FALSE) {
981 hWnd = GetWindow (hWnd, GW_HWNDNEXT);
982 continue;
983 }
984
985 dprintf(("ChildWindowFromPointEx returned %x", hWnd));
986 // found it!
987 return hWnd;
988 }
989
990 // the point is in the parentwindow but the parentwindow has no child
991 // at this coordinate
992 dprintf(("ChildWindowFromPointEx returned parent %x", hwndParent));
993 return hwndParent;
994}
995//******************************************************************************
996//******************************************************************************
997BOOL WIN32API CloseWindow(HWND hwnd)
998{
999 Win32BaseWindow *window;
1000
1001 window = Win32BaseWindow::GetWindowFromHandle(hwnd);
1002 if(!window) {
1003 dprintf(("CloseWindow, window %x not found", hwnd));
1004 SetLastError(ERROR_INVALID_WINDOW_HANDLE);
1005 return 0;
1006 }
1007 dprintf(("CloseWindow %x\n", hwnd));
1008 return window->CloseWindow();
1009}
1010//******************************************************************************
1011//TODO: Does this return handles of hidden or disabled windows?
1012//******************************************************************************
1013HWND WIN32API WindowFromPoint( POINT point)
1014{
1015 HWND hwnd;
1016
1017 dprintf(("WindowFromPoint (%d,%d)\n", point.x, point.y));
1018 hwnd = OSLibWinWindowFromPoint(OSLIB_HWND_DESKTOP, (PVOID)&point);
1019 if(hwnd) {
1020 return Win32BaseWindow::OS2ToWin32Handle(hwnd);
1021 }
1022 return 0;
1023}
1024//******************************************************************************
1025//******************************************************************************
1026BOOL WIN32API IsWindowUnicode(HWND hwnd)
1027{
1028 Win32BaseWindow *window;
1029
1030 window = Win32BaseWindow::GetWindowFromHandle(hwnd);
1031 if(!window) {
1032 dprintf(("IsWindowUnicode, window %x not found", hwnd));
1033 SetLastError(ERROR_INVALID_WINDOW_HANDLE);
1034 return 0;
1035 }
1036 return window->IsUnicode();
1037}
1038/*****************************************************************************
1039 * Name : WORD WIN32API CascadeWindows
1040 * Purpose : The CascadeWindows function cascades the specified windows or
1041 * the child windows of the specified parent window.
1042 * Parameters: HWND hwndParent handle of parent window
1043 * UINT wHow types of windows not to arrange
1044 * CONST RECT * lpRect rectangle to arrange windows in
1045 * UINT cKids number of windows to arrange
1046 * const HWND FAR * lpKids array of window handles
1047 * Variables :
1048 * Result : If the function succeeds, the return value is the number of windows arranged.
1049 * If the function fails, the return value is zero.
1050 * Remark :
1051 * Status : UNTESTED STUB
1052 *
1053 * Author : Patrick Haller [Thu, 1998/02/26 11:55]
1054 *****************************************************************************/
1055
1056WORD WIN32API CascadeWindows(HWND hwndParent,
1057 UINT wHow,
1058 CONST LPRECT lpRect,
1059 UINT cKids,
1060 const HWND *lpKids)
1061{
1062 dprintf(("USER32:CascadeWindows(%08xh,%u,%08xh,%u,%08x) not implemented.\n",
1063 hwndParent,
1064 wHow,
1065 lpRect,
1066 cKids,
1067 lpKids));
1068
1069 return (0);
1070}
1071/*****************************************************************************
1072 * Name : BOOL WIN32API SwitchToThisWindow
1073 * Purpose : Unknown
1074 * Parameters: Unknown
1075 * Variables :
1076 * Result :
1077 * Remark :
1078 * Status : UNTESTED UNKNOWN STUB
1079 *
1080 * Author : Patrick Haller [Wed, 1998/06/16 11:55]
1081 *****************************************************************************/
1082
1083BOOL WIN32API SwitchToThisWindow(HWND hwnd,
1084 BOOL x2)
1085{
1086 dprintf(("USER32: SwitchToThisWindow(%08xh,%08xh) not implemented.\n",
1087 hwnd,
1088 x2));
1089
1090 return (FALSE); /* default */
1091}
1092//******************************************************************************
1093//******************************************************************************
1094BOOL WIN32API EnumThreadWindows(DWORD dwThreadId, WNDENUMPROC lpfn, LPARAM lParam)
1095{
1096 Win32BaseWindow *window;
1097 BOOL rc;
1098 ULONG henum;
1099 HWND hwndNext;
1100 ULONG tid;
1101 ULONG pid, curpid;
1102
1103 dprintf(("EnumThreadWindows\n"));
1104
1105 curpid = GetCurrentProcessId();
1106
1107 henum = OSLibWinBeginEnumWindows(OSLIB_HWND_DESKTOP);
1108 while ((hwndNext = OSLibWinGetNextWindow(henum)) != 0)
1109 {
1110 OSLibWinQueryWindowProcess(hwndNext, &pid, &tid);
1111 if(!(curpid == pid && dwThreadId == tid))
1112 continue;
1113
1114 window = Win32BaseWindow::GetWindowFromHandle(hwndNext);
1115 if(window == NULL) {
1116 //OS/2 window or non-frame window, so skip it
1117 continue;
1118 }
1119 if((rc = lpfn(window->getWindowHandle(), lParam)) == FALSE)
1120 break;
1121 }
1122 OSLibWinEndEnumWindows (henum);
1123 return TRUE;
1124}
1125//******************************************************************************
1126//******************************************************************************
1127BOOL WIN32API EnumChildWindows(HWND hwnd, WNDENUMPROC lpfn, LPARAM lParam)
1128{
1129 Win32BaseWindow *window, *parentwindow;
1130 BOOL rc = TRUE;
1131 ULONG henum;
1132 HWND hwndNext;
1133
1134 dprintf(("EnumChildWindows %x %x\n", hwnd, lParam));
1135
1136 parentwindow = Win32BaseWindow::GetWindowFromHandle(hwnd);
1137 if(!parentwindow) {
1138 dprintf(("EnumChildWindows, window %x not found", hwnd));
1139 SetLastError(ERROR_INVALID_WINDOW_HANDLE);
1140 return FALSE;
1141 }
1142
1143 henum = OSLibWinBeginEnumWindows(OSLIB_HWND_DESKTOP);
1144 while ((hwndNext = OSLibWinGetNextWindow(henum)) != 0)
1145 {
1146 window = Win32BaseWindow::GetWindowFromHandle(hwndNext);
1147 if(window == NULL) {
1148 //OS/2 window or non-frame window, so skip it
1149 continue;
1150 }
1151 if((rc = lpfn(window->getWindowHandle(), lParam)) == FALSE)
1152 {
1153 rc = FALSE;
1154 break;
1155 }
1156 }
1157 OSLibWinEndEnumWindows(henum);
1158 return rc;
1159}
1160//******************************************************************************
1161//******************************************************************************
1162BOOL WIN32API EnumWindows(WNDENUMPROC lpfn, LPARAM lParam)
1163{
1164 Win32BaseWindow *window;
1165 BOOL rc;
1166 ULONG henum;
1167 HWND hwndNext, hwndParent = OSLIB_HWND_DESKTOP;
1168
1169 dprintf(("EnumThreadWindows\n"));
1170
1171 do {
1172 henum = OSLibWinBeginEnumWindows(hwndParent);
1173 while ((hwndNext = OSLibWinGetNextWindow(henum)) != 0)
1174 {
1175 window = Win32BaseWindow::GetWindowFromHandle(hwndNext);
1176 if(window == NULL) {
1177 //OS/2 window or non-frame window, so skip it
1178 continue;
1179 }
1180 if((rc = lpfn(window->getWindowHandle(), lParam)) == FALSE) {
1181 goto Abort;
1182 }
1183 }
1184 if(hwndParent == OSLIB_HWND_OBJECT)
1185 break;
1186 hwndParent = OSLIB_HWND_OBJECT;
1187 OSLibWinEndEnumWindows(henum);
1188 }
1189 while(TRUE);
1190
1191Abort:
1192 OSLibWinEndEnumWindows(henum);
1193 return TRUE;
1194}
1195//******************************************************************************
1196//******************************************************************************
1197#if 0
1198BOOL WIN32API GetUpdateRect( HWND hwnd, PRECT lpRect, BOOL bErase)
1199{
1200 dprintf(("GetUpdateRect %x %d\n", hwnd, bErase));
1201 if (!lpRect) return FALSE;
1202
1203 return OSLibWinQueryUpdateRect(Win32BaseWindow::Win32ToOS2Handle(hwnd), lpRect);
1204}
1205#endif
1206//******************************************************************************
1207//******************************************************************************
1208#if 0
1209BOOL WIN32API InvalidateRect(HWND hWnd, const RECT *lpRect, BOOL bErase)
1210{
1211#ifdef DEBUG
1212 if(lpRect)
1213 WriteLog("USER32: InvalidateRect for window %X (%d,%d)(%d,%d) %d\n", hWnd, lpRect->left, lpRect->top, lpRect->right, lpRect->bottom, bErase);
1214 else WriteLog("USER32: InvalidateRect for window %X NULL, %d\n", hWnd, bErase);
1215#endif
1216
1217 //CB: bErase no quite the same
1218 hWnd = Win32BaseWindow::Win32ToOS2Handle(hWnd);
1219 if (lpRect)
1220 {
1221 return OSLibWinInvalidateRect(hWnd, (PRECT)lpRect, bErase);
1222 }
1223 else return OSLibWinInvalidateRect(hWnd,NULL,bErase);
1224}
1225#endif
1226//******************************************************************************
1227//******************************************************************************
1228UINT WIN32API ArrangeIconicWindows( HWND arg1)
1229{
1230#ifdef DEBUG
1231 WriteLog("USER32: ArrangeIconicWindows\n");
1232#endif
1233 return O32_ArrangeIconicWindows(arg1);
1234}
1235//******************************************************************************
1236//restores iconized window to previous size/position
1237//******************************************************************************
1238BOOL WIN32API OpenIcon(HWND hwnd)
1239{
1240#ifdef DEBUG
1241 WriteLog("USER32: OpenIcon\n");
1242#endif
1243 if(!IsIconic(hwnd))
1244 return FALSE;
1245 ShowWindow(hwnd, SW_SHOWNORMAL);
1246 return TRUE;
1247}
1248//******************************************************************************
1249//******************************************************************************
1250BOOL WIN32API ShowOwnedPopups( HWND arg1, BOOL arg2)
1251{
1252 dprintf(("USER32: ShowOwnedPopups\n"));
1253 return O32_ShowOwnedPopups(arg1, arg2);
1254}
1255//******************************************************************************
1256//******************************************************************************
1257
Note: See TracBrowser for help on using the repository browser.