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

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

Corrected position of PM titlebar control

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