source: trunk/src/user32/oslibwin.cpp@ 7765

Last change on this file since 7765 was 7765, checked in by sandervl, 24 years ago

CreateFakeWindowEx changes + added DestroyFakeWindow

File size: 40.5 KB
Line 
1/* $Id: oslibwin.cpp,v 1.112 2002-01-12 14:09:30 sandervl Exp $ */
2/*
3 * Window API wrappers for OS/2
4 *
5 *
6 * Copyright 1999 Sander van Leeuwen (sandervl@xs4all.nl)
7 * Copyright 1999 Daniela Engert (dani@ngrt.de)
8 *
9 *
10 * Project Odin Software License can be found in LICENSE.TXT
11 *
12 */
13#define INCL_WIN
14#define INCL_PM
15#define INCL_WINSWITCHLIST
16#include <os2wrap.h>
17#include <stdlib.h>
18#include <string.h>
19
20#include <misc.h>
21#include <win32type.h>
22#include <winconst.h>
23#include <winuser32.h>
24#include "oslibwin.h"
25#include "oslibutil.h"
26#include "oslibmsg.h"
27#include "oslibgdi.h"
28#include "pmwindow.h"
29#include "initterm.h"
30
31#define DBG_LOCALLOG DBG_oslibwin
32#include "dbglocal.h"
33
34//******************************************************************************
35//******************************************************************************
36BOOL OSLibWinSetParent(HWND hwnd, HWND hwndParent, ULONG fRedraw)
37{
38 if(hwndParent == OSLIB_HWND_DESKTOP)
39 {
40 hwndParent = HWND_DESKTOP;
41 }
42 else
43 if(hwndParent == OSLIB_HWND_OBJECT) {
44 hwndParent = HWND_OBJECT;
45 }
46 return (WinSetParent(hwnd, hwndParent, fRedraw) == 0);
47}
48//******************************************************************************
49//******************************************************************************
50BOOL OSLibWinSetOwner(HWND hwnd, HWND hwndOwner)
51{
52 return WinSetOwner(hwnd, hwndOwner);
53}
54//******************************************************************************
55//******************************************************************************
56HWND OSLibWinCreateWindow(HWND hwndParent,ULONG dwWinStyle, ULONG dwOSFrameStyle,
57 char *pszName, HWND Owner, ULONG fHWND_BOTTOM,
58 ULONG id, BOOL fTaskList,BOOL fShellPosition,
59 int classStyle, HWND *hwndFrame)
60{
61 HWND hwndClient;
62 ULONG dwFrameStyle = 0;
63
64 if(pszName && *pszName == 0) {
65 pszName = NULL;
66 }
67 if(hwndParent == OSLIB_HWND_DESKTOP) {
68 hwndParent = HWND_DESKTOP;
69 }
70 if(Owner == OSLIB_HWND_DESKTOP) {
71 Owner = HWND_DESKTOP;
72 }
73
74 if(classStyle & CS_SAVEBITS_W) dwWinStyle |= WS_SAVEBITS;
75 if(classStyle & CS_PARENTDC_W) dwWinStyle |= WS_PARENTCLIP;
76
77 dwWinStyle = dwWinStyle & ~(WS_TABSTOP | WS_GROUP);
78
79 if(fTaskList)
80 {
81 dwFrameStyle |= FCF_NOMOVEWITHOWNER;
82 }
83 if (fShellPosition) dwFrameStyle |= FCF_SHELLPOSITION;
84
85 FRAMECDATA FCData = {sizeof (FRAMECDATA), 0, 0, 0};
86 FCData.flCreateFlags = dwFrameStyle;
87
88 dprintf(("WinCreateWindow %x %s %x task %d shell %d classstyle %x winstyle %x bottom %d", hwndParent, pszName, id, fTaskList, fShellPosition, classStyle, dwWinStyle, fHWND_BOTTOM));
89
90 //Must not use WS_CLIPCHILDREN style with frame window. Transparency won't work otherwise.
91 //Eg: dialog parent, groupbox; invalidate part of groupbox -> painting algorithm stops when it finds
92 // a window with WS_CLIPCHILDREN -> result: dialog window won't update groupbox background as groupbox only draws the border
93 *hwndFrame = WinCreateWindow(hwndParent,
94 WIN32_STDFRAMECLASS,
95 pszName, (dwWinStyle & ~WS_CLIPCHILDREN), 0, 0, 0, 0,
96 Owner, (fHWND_BOTTOM) ? HWND_BOTTOM : HWND_TOP,
97 id, (PVOID)&FCData, NULL);
98 if(fOS2Look && *hwndFrame) {
99 FCData.flCreateFlags = dwOSFrameStyle;
100// FCData.flCreateFlags = FCF_TITLEBAR|FCF_SYSMENU|FCF_MINMAX;
101 WinCreateFrameControls(*hwndFrame, &FCData, NULL);
102 }
103 hwndClient = WinCreateWindow (*hwndFrame, WIN32_STDCLASS,
104 NULL, dwWinStyle | WS_VISIBLE, 0, 0, 0, 0,
105 *hwndFrame, HWND_TOP, FID_CLIENT, NULL, NULL);
106
107 return hwndClient;
108}
109//******************************************************************************
110//Note: Also check OSLibSetWindowStyle when changing this!!
111//******************************************************************************
112BOOL OSLibWinConvertStyle(ULONG dwStyle, ULONG dwExStyle, ULONG *OSWinStyle, ULONG *OSFrameStyle)
113{
114 *OSWinStyle = 0;
115 *OSFrameStyle = 0;
116
117 /* Window styles */
118 if(dwStyle & WS_DISABLED_W)
119 *OSWinStyle |= WS_DISABLED;
120 if(dwStyle & WS_CLIPSIBLINGS_W)
121 *OSWinStyle |= WS_CLIPSIBLINGS;
122 if(dwStyle & WS_CLIPCHILDREN_W)
123 *OSWinStyle |= WS_CLIPCHILDREN;
124
125 if(fOS2Look) {
126 if((dwStyle & WS_CAPTION_W) == WS_CAPTION_W) {
127 *OSFrameStyle = FCF_TITLEBAR;
128 if((dwStyle & WS_SYSMENU_W) && !(dwExStyle & WS_EX_TOOLWINDOW_W))
129 {
130 *OSFrameStyle |= FCF_SYSMENU;
131 }
132 if((dwStyle & WS_MINIMIZEBOX_W) || (dwStyle & WS_MAXIMIZEBOX_W)) {
133 *OSFrameStyle |= FCF_MINMAX;
134 }
135 else
136 if(dwStyle & WS_SYSMENU_W) {
137 *OSFrameStyle |= FCF_CLOSEBUTTON;
138 }
139 }
140 }
141 return TRUE;
142}
143//******************************************************************************
144//******************************************************************************
145BOOL OSLibWinPositionFrameControls(HWND hwndFrame, RECTLOS2 *pRect, DWORD dwStyle,
146 DWORD dwExStyle, HICON hSysMenuIcon)
147{
148 SWP swp[3];
149 HWND hwndControl;
150 int i = 0;
151 static int minmaxwidth = 0;
152 static int minmaxheight = 0;
153
154 if(minmaxwidth == 0) {
155 minmaxwidth = WinQuerySysValue(HWND_DESKTOP, SV_CXMINMAXBUTTON);
156 minmaxheight = WinQuerySysValue(HWND_DESKTOP, SV_CYMINMAXBUTTON);
157 }
158
159 if(fOS2Look == OS2_APPEARANCE_SYSMENU) {
160 hwndControl = WinWindowFromID(hwndFrame, FID_SYSMENU);
161 if(hwndControl) {
162 swp[i].hwnd = hwndControl;
163 swp[i].hwndInsertBehind = HWND_TOP;
164 swp[i].x = pRect->xLeft;
165 swp[i].y = pRect->yBottom;
166 if(pRect->yTop - pRect->yBottom > minmaxheight) {
167 swp[i].y += pRect->yTop - pRect->yBottom - minmaxheight;
168 }
169 swp[i].cx = minmaxwidth/2;
170 swp[i].cy = minmaxheight;;
171 swp[i].fl = SWP_SIZE | SWP_MOVE | SWP_SHOW;
172 dprintf(("FID_SYSMENU (%d,%d)(%d,%d)", swp[i].x, swp[i].y, swp[i].cx, swp[i].cy));
173 pRect->xLeft += minmaxwidth/2;
174 i++;
175 }
176 }
177 else
178 if((dwStyle & WS_SYSMENU_W) && !(dwExStyle & WS_EX_TOOLWINDOW_W) && hSysMenuIcon) {
179 pRect->xLeft += minmaxwidth/2;
180 }
181
182 if((dwStyle & WS_CAPTION_W) == WS_CAPTION_W) {
183 hwndControl = WinWindowFromID(hwndFrame, FID_TITLEBAR);
184 if(hwndControl) {
185 swp[i].hwnd = hwndControl;
186 swp[i].hwndInsertBehind = HWND_TOP;
187 swp[i].x = pRect->xLeft;
188 swp[i].y = pRect->yBottom;
189 if(pRect->yTop - pRect->yBottom > minmaxheight) {
190 swp[i].y += pRect->yTop - pRect->yBottom - minmaxheight;
191 }
192 swp[i].cx = pRect->xRight - pRect->xLeft;
193 if((dwStyle & WS_MINIMIZEBOX_W) || (dwStyle & WS_MAXIMIZEBOX_W)) {
194 swp[i].cx -= minmaxwidth;
195 }
196 //there is no close button in warp 3
197 if((dwStyle & WS_SYSMENU_W) && !fVersionWarp3) {
198 swp[i].cx -= minmaxwidth/2;
199 }
200 swp[i].cy = minmaxheight;
201 swp[i].fl = SWP_SIZE | SWP_MOVE | SWP_SHOW;
202 dprintf(("FID_TITLEBAR (%d,%d)(%d,%d)", swp[i].x, swp[i].y, swp[i].cx, swp[i].cy));
203 pRect->xLeft += swp[i].cx;
204 i++;
205 }
206 else return FALSE; //no titlebar -> no frame controls
207 }
208 if((dwStyle & WS_MINIMIZEBOX_W) || (dwStyle & WS_MAXIMIZEBOX_W) || (dwStyle & WS_SYSMENU_W)) {
209 hwndControl = WinWindowFromID(hwndFrame, FID_MINMAX);
210 if(hwndControl) {
211 swp[i].hwnd = hwndControl;
212 swp[i].hwndInsertBehind = HWND_TOP;
213 swp[i].x = pRect->xLeft;
214 swp[i].y = pRect->yBottom;
215 if(pRect->yTop - pRect->yBottom > minmaxheight) {
216 swp[i].y += pRect->yTop - pRect->yBottom - minmaxheight;
217 }
218 swp[i].cx = 0;
219 if((dwStyle & WS_MINIMIZEBOX_W) || (dwStyle & WS_MAXIMIZEBOX_W)) {
220 swp[i].cx += minmaxwidth;
221 }
222 //there is no close button in warp 3
223 if((dwStyle & WS_SYSMENU_W) && !fVersionWarp3) {
224 swp[i].cx += minmaxwidth/2;
225 }
226 swp[i].cy = minmaxheight;
227 swp[i].fl = SWP_SIZE | SWP_MOVE | SWP_SHOW;
228 dprintf(("FID_MINMAX (%d,%d)(%d,%d)", swp[i].x, swp[i].y, swp[i].cx, swp[i].cy));
229 pRect->xLeft += swp[i].cx;
230 i++;
231 }
232 }
233 return WinSetMultWindowPos(GetThreadHAB(), swp, i);
234}
235//******************************************************************************
236//******************************************************************************
237BOOL OSLibWinSetWindowULong(HWND hwnd, ULONG offset, ULONG value)
238{
239 if(offset == OSLIB_QWL_USER)
240 offset = QWL_USER;
241
242 return WinSetWindowULong(hwnd, offset, value);
243}
244//******************************************************************************
245//******************************************************************************
246ULONG OSLibWinGetWindowULong(HWND hwnd, ULONG offset)
247{
248 if(offset == OSLIB_QWL_USER)
249 offset = QWL_USER;
250
251 return WinQueryWindowULong(hwnd, offset);
252}
253//******************************************************************************
254//******************************************************************************
255BOOL OSLibWinAlarm(HWND hwndDeskTop,ULONG flStyle)
256{
257 return WinAlarm(hwndDeskTop,flStyle);
258}
259//******************************************************************************
260HWND OSLibWinQueryFocus(HWND hwndDeskTop)
261{
262 return WinQueryFocus(hwndDeskTop);
263}
264//******************************************************************************
265//******************************************************************************
266HWND OSLibWinWindowFromID(HWND hwndParent,ULONG id)
267{
268 return WinWindowFromID(hwndParent,id);
269}
270//******************************************************************************
271//******************************************************************************
272BOOL OSLibWinSetFocus(HWND hwndDeskTop,HWND hwndNewFocus, BOOL activate)
273{
274 return WinFocusChange (hwndDeskTop, hwndNewFocus, activate ? 0 : FC_NOSETACTIVE);
275}
276//******************************************************************************
277//******************************************************************************
278BOOL OSLibWinIsChild (HWND hwnd, HWND hwndOf)
279{
280 return WinIsChild (hwnd, hwndOf);
281}
282//******************************************************************************
283//******************************************************************************
284ULONG OSLibGetWindowHeight(HWND hwnd)
285{
286 RECTL rect;
287
288 return (WinQueryWindowRect(hwnd,&rect)) ? rect.yTop-rect.yBottom:0;
289}
290//******************************************************************************
291//******************************************************************************
292LONG OSLibWinQuerySysValue(LONG iSysValue)
293{
294 return WinQuerySysValue(HWND_DESKTOP,iSysValue);
295}
296//******************************************************************************
297//******************************************************************************
298BOOL OSLibWinSetSysValue(LONG iSysValue, ULONG val)
299{
300 return WinQuerySysValue(iSysValue, val);
301}
302//******************************************************************************
303//******************************************************************************
304ULONG OSLibWinQueryDlgItemText(HWND hwndDlg,ULONG idItem,LONG cchBufferMax,char* pchBuffer)
305{
306 return WinQueryDlgItemText(hwndDlg,idItem,cchBufferMax,pchBuffer);
307}
308//******************************************************************************
309//******************************************************************************
310BOOL OSLibWinSetDlgItemText(HWND hwndDlg,ULONG idItem,char* pszText)
311{
312 return WinSetDlgItemText(hwndDlg,idItem,pszText);
313}
314//******************************************************************************
315//******************************************************************************
316BOOL OSLibWinQueryPointerPos(PPOINT pptlPoint)
317{
318 return WinQueryPointerPos(HWND_DESKTOP,(PPOINTL)pptlPoint);
319}
320//******************************************************************************
321//******************************************************************************
322BOOL OSLibWinSetPointerPos(int x, int y)
323{
324 return WinSetPointerPos(HWND_DESKTOP, x, y);
325}
326//******************************************************************************
327//******************************************************************************
328HWND OSLibWinQueryWindow(HWND hwnd, ULONG lCode)
329{
330 return WinQueryWindow(hwnd, lCode);
331}
332//******************************************************************************
333//******************************************************************************
334BOOL OSLibWinSetMultWindowPos(PSWP pswp, ULONG num)
335{
336 return WinSetMultWindowPos(GetThreadHAB(), pswp, num);
337}
338//******************************************************************************
339//******************************************************************************
340BOOL OSLibWinShowWindow(HWND hwnd, ULONG fl)
341{
342 BOOL rc = 1;
343
344 if(fl & SWP_SHOW) {
345 rc = WinShowWindow(hwnd, TRUE);
346 }
347 if(rc == 0)
348 dprintf(("WinShowWindow %x failed %x", hwnd, WinGetLastError(GetThreadHAB())));
349 rc = WinSetWindowPos(hwnd, 0, 0, 0, 0, 0, fl);
350 if(rc == 0)
351 dprintf(("WinShowWindow %x failed %x", hwnd, WinGetLastError(GetThreadHAB())));
352 return rc;
353}
354//******************************************************************************
355//******************************************************************************
356BOOL OSLibWinDestroyWindow(HWND hwnd)
357{
358 return WinDestroyWindow(hwnd);
359}
360//******************************************************************************
361//******************************************************************************
362BOOL OSLibWinQueryWindowClientRect(HWND hwndOS2, PRECT pRect)
363{
364 BOOL rc;
365 RECTLOS2 rectl;
366
367 rc = WinQueryWindowRect(hwndOS2, (PRECTL)&rectl);
368 if(rc) {
369 pRect->left = 0;
370 pRect->right = rectl.xRight - rectl.xLeft;
371 pRect->top = 0;
372 pRect->bottom = rectl.yTop - rectl.yBottom;
373 }
374 else memset(pRect, 0, sizeof(RECT));
375 return rc;
376}
377//******************************************************************************
378//******************************************************************************
379#if 0
380BOOL OSLibWinQueryWindowRect(Win32BaseWindow *window, PRECT pRect, int RelativeTo)
381{
382 BOOL rc;
383 RECTLOS2 rectl;
384
385 rc = WinQueryWindowRect(window->getOS2WindowHandle(), (PRECTL)&rectl);
386 if(rc) {
387 if(RelativeTo == RELATIVE_TO_SCREEN) {
388 mapOS2ToWin32RectFrame(window,windowDesktop,&rectl,pRect);
389 }
390 else mapOS2ToWin32RectFrame(window,&rectl,pRect);
391 }
392 else memset(pRect, 0, sizeof(RECT));
393 return rc;
394}
395#endif
396//******************************************************************************
397//******************************************************************************
398BOOL OSLibWinIsIconic(HWND hwnd)
399{
400 SWP swp;
401 BOOL rc;
402
403 rc = WinQueryWindowPos(hwnd, &swp);
404 if(rc == FALSE) {
405 dprintf(("OSLibWinIsIconic: WinQueryWindowPos %x failed", hwnd));
406 return FALSE;
407 }
408
409 if(swp.fl & SWP_MINIMIZE)
410 return TRUE;
411 else return FALSE;
412}
413//******************************************************************************
414//******************************************************************************
415BOOL OSLibWinSetActiveWindow(HWND hwnd)
416{
417 BOOL rc;
418
419 rc = WinSetActiveWindow(HWND_DESKTOP, hwnd);
420 if(rc == FALSE) {
421 dprintf(("WinSetActiveWindow %x failure: %x", hwnd, OSLibWinGetLastError()));
422 }
423 return rc;
424}
425//******************************************************************************
426//******************************************************************************
427BOOL OSLibWinSetFocus(HWND hwnd)
428{
429 return WinSetFocus(HWND_DESKTOP, hwnd);
430}
431//******************************************************************************
432//******************************************************************************
433BOOL OSLibWinEnableWindow(HWND hwnd, BOOL fEnable)
434{
435 BOOL rc;
436 HWND hwndClient;
437
438 rc = WinEnableWindow(hwnd, fEnable);
439 hwndClient = WinWindowFromID(hwnd, FID_CLIENT);
440 if(hwndClient) {
441 WinEnableWindow(hwndClient, fEnable);
442 }
443 return rc;
444}
445//******************************************************************************
446//******************************************************************************
447BOOL OSLibWinIsWindowEnabled(HWND hwnd)
448{
449 return WinIsWindowEnabled(hwnd);
450}
451//******************************************************************************
452//******************************************************************************
453BOOL OSLibWinIsWindowVisible(HWND hwnd)
454{
455 return WinIsWindowVisible(hwnd);
456}
457//******************************************************************************
458//******************************************************************************
459HWND OSLibWinQueryActiveWindow()
460{
461 return WinQueryActiveWindow(HWND_DESKTOP);
462}
463//******************************************************************************
464//******************************************************************************
465LONG OSLibWinQueryWindowTextLength(HWND hwnd)
466{
467 return WinQueryWindowTextLength(hwnd);
468}
469//******************************************************************************
470//******************************************************************************
471LONG OSLibWinQueryWindowText(HWND hwnd, LONG length, LPSTR lpsz)
472{
473 return WinQueryWindowText(hwnd, length, lpsz);
474}
475//******************************************************************************
476//******************************************************************************
477BOOL OSLibWinSetWindowText(HWND hwnd, LPSTR lpsz)
478{
479 return WinSetWindowText(hwnd, lpsz);
480}
481//******************************************************************************
482//******************************************************************************
483BOOL OSLibWinSetTitleBarText(HWND hwnd, LPSTR lpsz)
484{
485 return WinSetWindowText(WinWindowFromID(hwnd, FID_TITLEBAR), lpsz);
486}
487//******************************************************************************
488//******************************************************************************
489BOOL OSLibWinFlashWindow(HWND hwnd, BOOL fFlash)
490{
491 return WinFlashWindow(hwnd, fFlash);
492}
493//******************************************************************************
494//******************************************************************************
495HWND OSLibWinWindowFromPoint(HWND hwnd, PVOID ppoint)
496{
497 return WinWindowFromPoint((hwnd == OSLIB_HWND_DESKTOP) ? HWND_DESKTOP : hwnd, (PPOINTL)ppoint, TRUE);
498}
499//******************************************************************************
500//******************************************************************************
501BOOL OSLibWinMinimizeWindow(HWND hwnd)
502{
503 return WinSetWindowPos(hwnd, 0, 0, 0, 0, 0, SWP_MINIMIZE);
504}
505//******************************************************************************
506//******************************************************************************
507BOOL OSLibWinGetBorderSize(HWND hwnd, OSLIBPOINT *pointl)
508{
509 pointl->x = 0;
510 pointl->y = 0;
511 return (BOOL) WinSendMsg(hwnd, WM_QUERYBORDERSIZE, MPFROMP( &pointl), 0);
512}
513//******************************************************************************
514//******************************************************************************
515BOOL OSLibWinSetIcon(HWND hwnd, HANDLE hIcon)
516{
517 ULONG hIconOS2 = GetOS2Icon(hIcon);
518 if(hIconOS2)
519 return (BOOL) WinSendMsg(hwnd, WM_SETICON, (MPARAM)hIconOS2, 0);
520 return FALSE;
521}
522//******************************************************************************
523//******************************************************************************
524BOOL OSLibWinQueryWindowPos (HWND hwnd, PSWP pswp)
525{
526 return WinQueryWindowPos(hwnd, pswp);
527}
528//******************************************************************************
529//******************************************************************************
530void OSLibMapSWPtoWINDOWPOS(PSWP pswp, PWINDOWPOS pwpos, PSWP pswpOld,
531 int parentHeight, HWND hwnd)
532{
533 HWND hWindow = pswp->hwnd;
534 HWND hWndInsertAfter = pswp->hwndInsertBehind;
535 long x = pswp->x;
536 long y = pswp->y;
537 long cx = pswp->cx;
538 long cy = pswp->cy;
539 UINT fuFlags = (UINT)pswp->fl;
540
541 HWND hWinAfter;
542 ULONG flags = 0;
543
544 HWND hWnd = (hWindow == HWND_DESKTOP) ? HWND_DESKTOP_W: hWindow;
545
546 if (hWndInsertAfter == HWND_TOP)
547 hWinAfter = HWND_TOP_W;
548 else if (hWndInsertAfter == HWND_BOTTOM)
549 hWinAfter = HWND_BOTTOM_W;
550 else
551 hWinAfter = (HWND) hWndInsertAfter;
552
553 //***********************************
554 // convert PM flags to Windows flags
555 //***********************************
556 if (!(fuFlags & SWP_SIZE)) flags |= SWP_NOSIZE_W;
557 if (!(fuFlags & SWP_MOVE)) flags |= SWP_NOMOVE_W;
558 if (!(fuFlags & SWP_ZORDER)) flags |= SWP_NOZORDER_W;
559 if ( fuFlags & SWP_NOREDRAW) flags |= SWP_NOREDRAW_W;
560 if (!(fuFlags & SWP_ACTIVATE)) flags |= SWP_NOACTIVATE_W;
561 if ( fuFlags & SWP_SHOW) flags |= SWP_SHOWWINDOW_W;
562 if ( fuFlags & SWP_HIDE) flags |= SWP_HIDEWINDOW_W;
563 if ( fuFlags & SWP_NOADJUST) flags |= SWP_NOSENDCHANGING_W;
564
565 if(fuFlags & (SWP_MOVE | SWP_SIZE))
566 {
567 y = parentHeight - y - pswp->cy;
568
569 if ((pswp->x == pswpOld->x) && (pswp->y == pswpOld->y))
570 flags |= SWP_NOMOVE_W;
571
572 if ((pswp->cx == pswpOld->cx) && (pswp->cy == pswpOld->cy))
573 flags |= SWP_NOSIZE_W;
574
575 if (fuFlags & SWP_SIZE)
576 {
577 if (pswp->cy != pswpOld->cy)
578 {
579 flags &= ~SWP_NOMOVE_W;
580 }
581 }
582 }
583
584 pswpOld->x = pswp->x;
585 pswpOld->y = parentHeight-pswp->y-pswp->cy;
586 pswpOld->cx = pswp->cx;
587 pswpOld->cy = pswp->cy;
588
589 dprintf(("window (%d,%d)(%d,%d) client (%d,%d)(%d,%d)",
590 x,y,cx,cy, pswpOld->x,pswpOld->y,pswpOld->cx,pswpOld->cy));
591
592 pwpos->flags = (UINT)flags;
593 pwpos->cy = cy;
594 pwpos->cx = cx;
595 pwpos->x = x;
596 pwpos->y = y;
597 pwpos->hwndInsertAfter = hWinAfter;
598 pwpos->hwnd = hWindow;
599}
600//******************************************************************************
601//******************************************************************************
602void OSLibMapWINDOWPOStoSWP(struct tagWINDOWPOS *pwpos, PSWP pswp, PSWP pswpOld,
603 int parentHeight, HWND hFrame)
604{
605 BOOL fCvt = FALSE;
606
607 HWND hWnd = pwpos->hwnd;
608 HWND hWndInsertAfter = pwpos->hwndInsertAfter;
609 long x = pwpos->x;
610 long y = pwpos->y;
611 long cx = pwpos->cx;
612 long cy = pwpos->cy;
613 UINT fuFlags = pwpos->flags;
614
615 HWND hWinAfter;
616 ULONG flags = 0;
617 HWND hWindow = hWnd ? (HWND)hWnd : HWND_DESKTOP;
618
619 if (hWndInsertAfter == HWND_TOPMOST_W)
620// hWinAfter = HWND_TOPMOST;
621 hWinAfter = HWND_TOP;
622 else if (hWndInsertAfter == HWND_NOTOPMOST_W)
623// hWinAfter = HWND_NOTOPMOST;
624 hWinAfter = HWND_TOP;
625 else if (hWndInsertAfter == HWND_TOP_W)
626 hWinAfter = HWND_TOP;
627 else if (hWndInsertAfter == HWND_BOTTOM_W)
628 hWinAfter = HWND_BOTTOM;
629 else
630 hWinAfter = (HWND) hWndInsertAfter;
631
632 if (!(fuFlags & SWP_NOSIZE_W )) flags |= SWP_SIZE;
633 if (!(fuFlags & SWP_NOMOVE_W )) flags |= SWP_MOVE;
634 if (!(fuFlags & SWP_NOZORDER_W )) flags |= SWP_ZORDER;
635 if ( fuFlags & SWP_NOREDRAW_W ) flags |= SWP_NOREDRAW;
636 if (!(fuFlags & SWP_NOACTIVATE_W)) flags |= SWP_ACTIVATE;
637 if ( fuFlags & SWP_SHOWWINDOW_W) flags |= SWP_SHOW;
638 if ( fuFlags & SWP_HIDEWINDOW_W) flags |= SWP_HIDE;
639 if ( fuFlags & SWP_NOSENDCHANGING_W) flags |= SWP_NOADJUST;
640
641 if(flags & (SWP_MOVE | SWP_SIZE))
642 {
643 if((flags & SWP_MOVE) == 0)
644 {
645 x = pswpOld->x;
646 y = pswpOld->y;
647
648 y = parentHeight - y - pswpOld->cy;
649 }
650
651 if(flags & SWP_SIZE)
652 {
653 if (cy != pswpOld->cy)
654 flags |= SWP_MOVE;
655 }
656 else
657 {
658 cx = pswpOld->cx;
659 cy = pswpOld->cy;
660 }
661 y = parentHeight - y - cy;
662
663 if ((pswpOld->x == x) && (pswpOld->y == y))
664 flags &= ~SWP_MOVE;
665
666 if ((pswpOld->cx == cx) && (pswpOld->cy == cy))
667 flags &= ~SWP_SIZE;
668 }
669
670 pswp->fl = flags;
671 pswp->cy = cy;
672 pswp->cx = cx;
673 pswp->x = x;
674 pswp->y = y;
675 pswp->hwndInsertBehind = hWinAfter;
676 pswp->hwnd = hWindow;
677 pswp->ulReserved1 = 0;
678 pswp->ulReserved2 = 0;
679}
680//******************************************************************************
681//******************************************************************************
682void OSLibWinSetClientPos(HWND hwnd, int x, int y, int cx, int cy, int parentHeight)
683{
684 SWP swp;
685 BOOL rc;
686
687 swp.hwnd = hwnd;
688 swp.hwndInsertBehind = 0;
689 swp.x = x;
690 swp.y = parentHeight - y - cy;
691 swp.cx = cx;
692 swp.cy = cy;
693 swp.fl = SWP_MOVE | SWP_SIZE;
694
695 dprintf(("OSLibWinSetClientPos (%d,%d) (%d,%d) -> (%d,%d) (%d,%d)", x, y, x+cx, y+cy, swp.x, swp.y, swp.x+swp.cx, swp.y+swp.cy));
696
697 rc = WinSetMultWindowPos(GetThreadHAB(), &swp, 1);
698 if(rc == FALSE) {
699 dprintf(("OSLibWinSetClientPos: WinSetMultWindowPos %x failed %x", hwnd, WinGetLastError(GetThreadHAB())));
700 }
701}
702//******************************************************************************
703//******************************************************************************
704BOOL OSLibWinCalcFrameRect(HWND hwndFrame, RECT *pRect, BOOL fClient)
705{
706 BOOL rc;
707
708 WinMapWindowPoints(hwndFrame, HWND_DESKTOP, (PPOINTL)pRect, 2);
709
710 rc = WinCalcFrameRect(hwndFrame, (PRECTL)pRect, fClient);
711 WinMapWindowPoints(HWND_DESKTOP, hwndFrame, (PPOINTL)pRect, 2);
712
713 return rc;
714}
715//******************************************************************************
716//******************************************************************************
717BOOL OSLibGetMinMaxInfo(HWND hwndFrame, MINMAXINFO *pMinMax)
718{
719 TRACKINFO tinfo;
720
721 memset(&tinfo, 0, sizeof(TRACKINFO));
722 WinSendMsg(hwndFrame, WM_QUERYTRACKINFO, (MPARAM)0,(MPARAM)&tinfo);
723
724 pMinMax->ptMinTrackSize.x = tinfo.ptlMinTrackSize.x;
725 pMinMax->ptMinTrackSize.y = tinfo.ptlMinTrackSize.y;
726 pMinMax->ptMaxTrackSize.x = tinfo.ptlMaxTrackSize.x;
727 pMinMax->ptMaxTrackSize.y = tinfo.ptlMaxTrackSize.y;
728 return TRUE;
729}
730//******************************************************************************
731//******************************************************************************
732HWND OSLibWinBeginEnumWindows(HWND hwnd)
733{
734 if(hwnd == OSLIB_HWND_DESKTOP) hwnd = HWND_DESKTOP;
735 else
736 if(hwnd == OSLIB_HWND_OBJECT) hwnd = HWND_OBJECT;
737
738 return WinBeginEnumWindows(hwnd);
739}
740//******************************************************************************
741//******************************************************************************
742HWND OSLibWinGetNextWindow(HWND hwndEnum)
743{
744 return WinGetNextWindow(hwndEnum);
745}
746//******************************************************************************
747//******************************************************************************
748HWND OSLibWinQueryClientWindow(HWND hwndFrame)
749{
750 HWND hwndClient = 0;
751
752 if(((ULONG)WinSendMsg(hwndFrame, WM_QUERYFRAMEINFO, NULL, NULL)) & FI_FRAME)
753 hwndClient = WinWindowFromID(hwndFrame, FID_CLIENT);
754
755 return hwndClient;
756}
757//******************************************************************************
758//******************************************************************************
759BOOL OSLibWinEndEnumWindows(HWND hwndEnum)
760{
761 return WinEndEnumWindows(hwndEnum);
762}
763//******************************************************************************
764//******************************************************************************
765BOOL OSLibWinQueryWindowProcess(HWND hwnd, ULONG *pid, ULONG *tid)
766{
767 return WinQueryWindowProcess(hwnd, pid, tid);
768}
769//******************************************************************************
770//******************************************************************************
771BOOL OSLibWinMapWindowPoints (HWND hwndFrom, HWND hwndTo, OSLIBPOINT *pptl, ULONG num)
772{
773 return WinMapWindowPoints (hwndFrom, hwndTo, (PPOINTL)pptl, num);
774}
775//******************************************************************************
776//******************************************************************************
777HWND OSLibWinQueryObjectWindow(VOID)
778{
779 return WinQueryObjectWindow(HWND_DESKTOP);
780}
781//******************************************************************************
782//******************************************************************************
783HWND OSLibWinObjectWindowFromID(HWND hwndOwner, ULONG ID)
784{
785 HWND hwndNext, hwndFound=0;
786 HENUM henum;
787
788 henum = WinBeginEnumWindows(HWND_OBJECT);
789 while ((hwndNext = WinGetNextWindow(henum)) != 0)
790 {
791 if(WinQueryWindow(hwndNext, QW_OWNER) == hwndOwner &&
792 WinQueryWindowUShort(hwndNext, QWS_ID) == ID)
793 {
794 hwndFound = hwndNext;
795 break;
796 }
797 }
798 WinEndEnumWindows(henum);
799 return hwndFound;
800}
801//******************************************************************************
802//******************************************************************************
803BOOL OSLibSetWindowID(HWND hwnd, ULONG value)
804{
805 dprintf(("OSLibSetWindowID hwnd:%x ID:%x", hwnd, value));
806 return WinSetWindowULong(hwnd, QWS_ID, value);
807}
808//******************************************************************************
809//******************************************************************************
810PVOID OSLibWinSubclassWindow(HWND hwnd,PVOID newWndProc)
811{
812 return WinSubclassWindow(hwnd,(PFNWP)newWndProc);
813}
814//******************************************************************************
815//******************************************************************************
816BOOL OSLibSetWindowRestoreRect(HWND hwnd, PRECT pRect)
817{
818 ULONG yHeight = OSLibGetWindowHeight(WinQueryWindow(hwnd, QW_PARENT));
819
820 WinSetWindowUShort(hwnd, QWS_XRESTORE, (USHORT)pRect->left );
821 WinSetWindowUShort(hwnd, QWS_YRESTORE, (USHORT)(yHeight - pRect->top -
822 (pRect->bottom - pRect->top)));
823 WinSetWindowUShort(hwnd, QWS_CXRESTORE, (USHORT)(pRect->right - pRect->left));
824 WinSetWindowUShort(hwnd, QWS_CYRESTORE, (USHORT)(pRect->bottom - pRect->top));
825 return TRUE;
826}
827//******************************************************************************
828//******************************************************************************
829BOOL OSLibSetWindowMinPos(HWND hwnd, ULONG x, ULONG y)
830{
831 ULONG yHeight = OSLibGetWindowHeight(WinQueryWindow(hwnd, QW_PARENT));
832
833 WinSetWindowUShort(hwnd, QWS_XMINIMIZE, (USHORT)x );
834 WinSetWindowUShort(hwnd, QWS_YMINIMIZE, (USHORT)(yHeight - y -
835 ( 2 * WinQuerySysValue( HWND_DESKTOP, SV_CYSIZEBORDER)) -
836 WinQuerySysValue( HWND_DESKTOP, SV_CYICON)));
837 return TRUE;
838}
839//******************************************************************************
840//******************************************************************************
841BOOL OSLibWinGetKeyboardStateTable(unsigned char *PMKeyState)
842{
843 return WinSetKeyboardStateTable(HWND_DESKTOP, (PBYTE)PMKeyState, FALSE );
844}
845//******************************************************************************
846//******************************************************************************
847BOOL OSLibWinSetKeyboardStateTable(unsigned char *PMKeyState)
848{
849 return WinSetKeyboardStateTable(HWND_DESKTOP, (PBYTE)PMKeyState, TRUE );
850}
851//******************************************************************************
852//******************************************************************************
853USHORT APIENTRY WinTranslateChar2( USHORT /* Codepage (currently ignored) */
854 , PUSHORT /* Ptr to char to translate */
855 , PULONG /* Ptr to deadkey save info */
856 , USHORT /* Translation option (TC_xxx) */
857 , PUSHORT /* Ptr to shift state (TCF_xxx) */
858 );
859//******************************************************************************
860//******************************************************************************
861USHORT OSLibWinTranslateChar(USHORT usScanCode, ULONG type, USHORT shiftstate)
862{
863 USHORT sel = GetFS();
864 usScanCode = WinTranslateChar2(0, &usScanCode, NULL, type, &shiftstate);
865 SetFS(sel);
866 return usScanCode;
867}
868//******************************************************************************
869//******************************************************************************
870BOOL OSLibWinEnableWindowUpdate(HWND hwndFrame, HWND hwndClient ,BOOL fEnable)
871{
872 WinEnableWindowUpdate(hwndFrame, fEnable);
873 return WinEnableWindowUpdate(hwndClient, fEnable);
874}
875//******************************************************************************
876//******************************************************************************
877ULONG OSLibWinGetLastError()
878{
879 return WinGetLastError(GetThreadHAB()) & 0xFFFF;
880}
881//******************************************************************************
882//******************************************************************************
883void OSLibWinShowTaskList(HWND hwndFrame)
884{
885 //CB: don't know if this works on all machines
886 WinSetActiveWindow(HWND_DESKTOP,0x8000000E);
887}
888//******************************************************************************
889//******************************************************************************
890void OSLibSetWindowStyle(HWND hwndFrame, HWND hwndClient, ULONG dwStyle, ULONG dwExStyle)
891{
892 ULONG dwWinStyle;
893 ULONG dwOldWinStyle;
894
895 //client window:
896 dwWinStyle = WinQueryWindowULong(hwndClient, QWL_STYLE);
897 dwOldWinStyle = dwWinStyle;
898
899 if(dwStyle & WS_CLIPCHILDREN_W) {
900 dwWinStyle |= WS_CLIPCHILDREN;
901 }
902 else dwWinStyle &= ~WS_CLIPCHILDREN;
903
904 if(dwWinStyle != dwOldWinStyle) {
905 WinSetWindowULong(hwndClient, QWL_STYLE, dwWinStyle);
906 }
907
908 //Frame window
909 dwWinStyle = WinQueryWindowULong(hwndFrame, QWL_STYLE);
910 dwOldWinStyle = dwWinStyle;
911 if(dwStyle & WS_DISABLED_W) {
912 dwWinStyle |= WS_DISABLED;
913 }
914 else dwWinStyle &= ~WS_DISABLED;
915
916 if(dwStyle & WS_CLIPSIBLINGS_W) {
917 dwWinStyle |= WS_CLIPSIBLINGS;
918 }
919 else dwWinStyle &= ~WS_CLIPSIBLINGS;
920
921 if(dwStyle & WS_MINIMIZE_W) {
922 dwWinStyle |= WS_MINIMIZED;
923 }
924 else dwWinStyle &= ~WS_MINIMIZED;
925
926 if(dwStyle & WS_MAXIMIZE_W) {
927 dwWinStyle |= WS_MAXIMIZED;
928 }
929 else dwWinStyle &= ~WS_MAXIMIZED;
930
931 if(dwWinStyle != dwOldWinStyle) {
932 WinSetWindowULong(hwndFrame, QWL_STYLE, dwWinStyle);
933 }
934 if(fOS2Look) {
935 ULONG OSFrameStyle = 0;
936 if((dwStyle & WS_CAPTION_W) == WS_CAPTION_W) {
937 if(WinWindowFromID(hwndFrame, FID_TITLEBAR) == 0) {
938 OSFrameStyle = FCF_TITLEBAR;
939 }
940 if((dwStyle & WS_SYSMENU_W) && !(dwExStyle & WS_EX_TOOLWINDOW_W))
941 {
942 if(WinWindowFromID(hwndFrame, FID_SYSMENU) == 0) {
943 OSFrameStyle |= FCF_SYSMENU;
944 }
945 }
946 if((dwStyle & WS_MINIMIZEBOX_W) || (dwStyle & WS_MAXIMIZEBOX_W)) {
947 if(WinWindowFromID(hwndFrame, FID_MINMAX) == 0) {
948 OSFrameStyle |= FCF_MINMAX;
949 }
950 }
951 else
952 if(dwStyle & WS_SYSMENU_W) {
953 if(WinWindowFromID(hwndFrame, FID_MINMAX) == 0) {
954 OSFrameStyle |= FCF_CLOSEBUTTON;
955 }
956 }
957 }
958 if(OSFrameStyle) {
959 FRAMECDATA FCData = {sizeof (FRAMECDATA), 0, 0, 0};
960
961 FCData.flCreateFlags = OSFrameStyle;
962 WinCreateFrameControls(hwndFrame, &FCData, NULL);
963 }
964 }
965}
966//******************************************************************************
967//******************************************************************************
968DWORD OSLibQueryWindowStyle(HWND hwnd)
969{
970 return WinQueryWindowULong(hwnd, QWL_STYLE);
971}
972//******************************************************************************
973//******************************************************************************
974void OSLibWinSetVisibleRegionNotify(HWND hwnd, BOOL fNotify)
975{
976 WinSetVisibleRegionNotify(hwnd, fNotify);
977}
978//******************************************************************************
979//******************************************************************************
980HWND OSLibWinQueryCapture()
981{
982 return WinQueryCapture(HWND_DESKTOP);
983}
984//******************************************************************************
985//******************************************************************************
986BOOL OSLibWinSetCapture(HWND hwnd)
987{
988 return WinSetCapture(HWND_DESKTOP, hwnd);
989}
990//******************************************************************************
991//******************************************************************************
992BOOL OSLibWinRemoveFromTasklist(HANDLE hTaskList)
993{
994 return (WinRemoveSwitchEntry(hTaskList)) ? FALSE : TRUE;
995}
996//******************************************************************************
997//******************************************************************************
998HANDLE OSLibWinAddToTaskList(HWND hwndFrame, char *title, BOOL fVisible)
999{
1000 SWCNTRL swctrl;
1001 ULONG tid;
1002
1003 swctrl.hwnd = hwndFrame;
1004 swctrl.hwndIcon = 0;
1005 swctrl.hprog = 0;
1006 WinQueryWindowProcess(hwndFrame, (PPID)&swctrl.idProcess, (PTID)&tid);
1007 swctrl.idSession = 0;
1008 swctrl.uchVisibility = (fVisible) ? SWL_VISIBLE : SWL_INVISIBLE;
1009 swctrl.fbJump = SWL_JUMPABLE;
1010 swctrl.bProgType = PROG_PM;
1011 if(title) {
1012 strncpy(swctrl.szSwtitle, title, MAXNAMEL+4);
1013 swctrl.szSwtitle[MAXNAMEL+4-1] = 0;
1014 }
1015 else {
1016 swctrl.szSwtitle[0] = 0;
1017 swctrl.uchVisibility = SWL_INVISIBLE;
1018 }
1019 return WinAddSwitchEntry(&swctrl);
1020}
1021//******************************************************************************
1022//******************************************************************************
1023BOOL OSLibWinChangeTaskList(HANDLE hTaskList, HWND hwndFrame, char *title, BOOL fVisible)
1024{
1025 SWCNTRL swctrl;
1026 ULONG tid;
1027
1028 swctrl.hwnd = hwndFrame;
1029 swctrl.hwndIcon = 0;
1030 swctrl.hprog = 0;
1031 WinQueryWindowProcess(hwndFrame, (PPID)&swctrl.idProcess, (PTID)&tid);
1032 swctrl.idSession = 0;
1033 swctrl.uchVisibility = (fVisible) ? SWL_VISIBLE : SWL_INVISIBLE;
1034 swctrl.fbJump = SWL_JUMPABLE;
1035 swctrl.bProgType = PROG_PM;
1036 if(title) {
1037 strncpy(swctrl.szSwtitle, title, MAXNAMEL+4);
1038 swctrl.szSwtitle[MAXNAMEL+4-1] = 0;
1039 }
1040 else {
1041 swctrl.szSwtitle[0] = 0;
1042 swctrl.uchVisibility = SWL_INVISIBLE;
1043 }
1044 return (WinChangeSwitchEntry(hTaskList, &swctrl)) ? FALSE : TRUE;
1045}
1046//******************************************************************************
1047//******************************************************************************
1048BOOL OSLibWinLockWindowUpdate(HWND hwnd)
1049{
1050 return WinLockWindowUpdate(HWND_DESKTOP, (HWND)hwnd);
1051}
1052//******************************************************************************
1053//******************************************************************************
1054ULONG OSLibGetScreenHeight()
1055{
1056 return ScreenHeight;
1057}
1058//******************************************************************************
1059//******************************************************************************
1060ULONG OSLibGetScreenWidth()
1061{
1062 return ScreenWidth;
1063}
1064//******************************************************************************
1065//Returns the maximum position for a window
1066//Should only be used from toplevel windows
1067//******************************************************************************
1068BOOL OSLibWinGetMaxPosition(HWND hwndOS2, RECT *rect)
1069{
1070 SWP swp;
1071
1072 if(!WinGetMaxPosition(hwndOS2, &swp)) {
1073 dprintf(("WARNING: WinGetMaxPosition %x returned FALSE", hwndOS2));
1074 return FALSE;
1075 }
1076 rect->left = swp.x;
1077 rect->right = swp.x + swp.cx;
1078 rect->top = ScreenHeight - (swp.y + swp.cy);
1079 rect->bottom = ScreenHeight - swp.y;
1080 return TRUE;
1081}
1082//******************************************************************************
1083//******************************************************************************
1084BOOL OSLibWinShowPointer(BOOL fShow)
1085{
1086 return WinShowPointer(HWND_DESKTOP, fShow);
1087}
1088//******************************************************************************
1089//******************************************************************************
1090ULONG OSLibWinQuerySysColor(int index)
1091{
1092 return CONVERT_RGB(WinQuerySysColor(HWND_DESKTOP, index, 0));
1093}
1094//******************************************************************************
1095//******************************************************************************
Note: See TracBrowser for help on using the repository browser.