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

Last change on this file since 8035 was 8035, checked in by sandervl, 23 years ago

Allow single minimize or maximize button in titlebar (os/2 appearance)

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