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

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

PM frame control positioning fixes

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