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

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

dispatch untranslated msgs + frame control button changes (manually change restore/min/max)

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