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

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

OS/2 looks changes + fixes

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