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

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

bugfixes + os/2 look support added

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