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

Last change on this file since 1186 was 1186, checked in by sandervl, 26 years ago

WS_DISABLED fix + removed frame + poschanged bugfixes

File size: 32.2 KB
Line 
1/* $Id: oslibwin.cpp,v 1.16 1999-10-08 14:57:17 sandervl Exp $ */
2/*
3 * Window API wrappers for OS/2
4 *
5 *
6 * Copyright 1999 Sander van Leeuwen (sandervl@xs4all.nl)
7 * Copyright 1999 Daniela Engert (dani@ngrt.de)
8 *
9 *
10 * Project Odin Software License can be found in LICENSE.TXT
11 *
12 */
13#define INCL_WIN
14#define INCL_PM
15#include <os2.h>
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 HAS_3DFRAME(exStyle) \
30 ((exStyle & WS_EX_CLIENTEDGE_W) || (exStyle & WS_EX_STATICEDGE_W) || (exStyle & WS_EX_WINDOWEDGE_W))
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
41 return (WinSetParent(hwnd, hwndParent, fRedraw) == 0);
42}
43//******************************************************************************
44//******************************************************************************
45HWND OSLibWinCreateWindow(HWND hwndParent, ULONG dwWinStyle, ULONG dwFrameStyle,
46 char *pszName, HWND Owner, ULONG fHWND_BOTTOM, HWND *hwndFrame)
47{
48 HWND hwndClient;
49
50 dprintf(("WinCreateWindow %x %x %x %s", hwndParent, dwWinStyle, dwFrameStyle, pszName));
51
52 if(pszName && *pszName == 0) {
53 pszName = NULL;
54 }
55 if(hwndParent == OSLIB_HWND_DESKTOP) {
56 hwndParent = HWND_DESKTOP;
57 }
58 if(Owner == OSLIB_HWND_DESKTOP) {
59 Owner = HWND_DESKTOP;
60 }
61
62 if(dwFrameStyle || hwndParent == HWND_DESKTOP) {
63 ULONG dwClientStyle;
64
65 dwClientStyle = dwWinStyle & ~(WS_TABSTOP | WS_GROUP);
66// if(pszName)
67// dwFrameStyle |= FCF_TITLEBAR;
68
69 dwFrameStyle |= FCF_TASKLIST | FCF_NOMOVEWITHOWNER | FCF_NOBYTEALIGN;
70 dwWinStyle &= ~WS_CLIPCHILDREN;
71
72 *hwndFrame = WinCreateStdWindow(hwndParent, dwWinStyle,
73 &dwFrameStyle, WIN32_STDCLASS,
74 "", dwClientStyle, 0, 0, &hwndClient);
75 if(*hwndFrame) {
76 if(pszName) {
77 WinSetWindowText(*hwndFrame, pszName);
78 }
79 return hwndClient;
80 }
81 dprintf(("OSLibWinCreateWindow: WinCreateStdWindow failed (%x)", WinGetLastError(GetThreadHAB())));
82 return 0;
83 }
84 hwndClient = WinCreateWindow(hwndParent, WIN32_STDCLASS, pszName, dwWinStyle, 0, 0, 0, 0,
85 Owner, (fHWND_BOTTOM) ? HWND_BOTTOM :HWND_TOP, 0, NULL,
86 NULL);
87 *hwndFrame = hwndClient;
88 return hwndClient;
89}
90//******************************************************************************
91//******************************************************************************
92BOOL OSLibWinConvertStyle(ULONG dwStyle, ULONG dwExStyle, ULONG *OSWinStyle, ULONG *OSFrameStyle)
93{
94 *OSWinStyle = 0;
95 *OSFrameStyle = 0;
96
97 /* Window styles */
98 if(dwStyle & WS_MINIMIZE_W)
99 *OSWinStyle |= WS_MINIMIZED;
100//Done explicitely in CreateWindowExA
101#if 1
102 if(dwStyle & WS_VISIBLE_W)
103 *OSWinStyle |= WS_VISIBLE;
104#endif
105 if(dwStyle & WS_DISABLED_W)
106 *OSWinStyle |= WS_DISABLED;
107 if(dwStyle & WS_CLIPSIBLINGS_W)
108 *OSWinStyle |= WS_CLIPSIBLINGS;
109 if(dwStyle & WS_CLIPCHILDREN_W)
110 *OSWinStyle |= WS_CLIPCHILDREN;
111 if(dwStyle & WS_MAXIMIZE_W)
112 *OSWinStyle |= WS_MAXIMIZED;
113 if(dwStyle & WS_GROUP_W)
114 *OSWinStyle |= WS_GROUP;
115 if(dwStyle & WS_TABSTOP_W)
116 *OSWinStyle |= WS_TABSTOP;
117
118 if (dwStyle & WS_CHILD_W)
119 {
120 if (dwStyle & WS_BORDER_W ||
121 dwStyle & WS_DLGFRAME_W ||
122 dwStyle & WS_THICKFRAME_W)
123 if (!HAS_3DFRAME(*OSFrameStyle)) *OSFrameStyle |= WS_EX_WINDOWEDGE_W;
124
125 if (dwExStyle & WS_EX_CLIENTEDGE_W ||
126 dwExStyle & WS_EX_STATICEDGE_W ||
127 dwExStyle & WS_EX_WINDOWEDGE_W)
128 *OSFrameStyle |= FCF_DLGBORDER;
129
130 if(dwStyle & WS_VSCROLL_W)
131 *OSFrameStyle |= FCF_VERTSCROLL;
132 if(dwStyle & WS_HSCROLL_W)
133 *OSFrameStyle |= FCF_HORZSCROLL;
134 } else
135 {
136 if((dwStyle & WS_CAPTION_W) == WS_CAPTION_W)
137 *OSFrameStyle |= FCF_TITLEBAR;
138 if(dwStyle & WS_DLGFRAME_W)
139 *OSFrameStyle |= FCF_DLGBORDER;
140 else
141 if(dwStyle & WS_BORDER_W)
142 *OSFrameStyle |= FCF_BORDER;
143
144 if(dwStyle & WS_VSCROLL_W)
145 *OSFrameStyle |= FCF_VERTSCROLL;
146 if(dwStyle & WS_HSCROLL_W)
147 *OSFrameStyle |= FCF_HORZSCROLL;
148
149 if(dwStyle & WS_SYSMENU_W)
150 *OSFrameStyle |= FCF_SYSMENU;
151 if(dwStyle & WS_THICKFRAME_W)
152 *OSFrameStyle |= FCF_SIZEBORDER; //??
153 if(dwStyle & WS_MINIMIZEBOX_W)
154 *OSFrameStyle |= FCF_MINBUTTON;
155 if(dwStyle & WS_MAXIMIZEBOX_W)
156 *OSFrameStyle |= FCF_MAXBUTTON;
157
158 if(dwExStyle & WS_EX_DLGMODALFRAME_W)
159 *OSFrameStyle |= FCF_DLGBORDER;
160 }
161
162 return TRUE;
163}
164//******************************************************************************
165//******************************************************************************
166BOOL OSLibWinSetWindowULong(HWND hwnd, ULONG offset, ULONG value)
167{
168 return WinSetWindowULong(hwnd, offset, value);
169}
170//******************************************************************************
171//******************************************************************************
172ULONG OSLibWinGetWindowULong(HWND hwnd, ULONG offset)
173{
174 return WinQueryWindowULong(hwnd, offset);
175}
176//******************************************************************************
177//******************************************************************************
178BOOL OSLibPostMessage(HWND hwnd, ULONG msg, ULONG wParam, ULONG lParam)
179{
180 return WinPostMsg(hwnd, msg, (MPARAM)wParam, (MPARAM)lParam);
181}
182//******************************************************************************
183//******************************************************************************
184ULONG OSLibSendMessage(HWND hwnd, ULONG msg, ULONG wParam, ULONG lParam)
185{
186 return (ULONG)WinSendMsg(hwnd, msg, (MPARAM)wParam, (MPARAM)lParam);
187}
188//******************************************************************************
189//******************************************************************************
190//******************************************************************************
191//******************************************************************************
192BOOL OSLibWinAlarm(HWND hwndDeskTop,ULONG flStyle)
193{
194 return WinAlarm(hwndDeskTop,flStyle);
195}
196//******************************************************************************
197//******************************************************************************
198APIRET OSLibDosBeep(ULONG freg,ULONG dur)
199{
200 return DosBeep(freg,dur);
201}
202//******************************************************************************
203//******************************************************************************
204HWND OSLibWinQueryFocus(HWND hwndDeskTop)
205{
206 return WinQueryFocus(hwndDeskTop);
207}
208//******************************************************************************
209//******************************************************************************
210HWND OSLibWinWindowFromID(HWND hwndParent,ULONG id)
211{
212 return WinWindowFromID(hwndParent,id);
213}
214//******************************************************************************
215//******************************************************************************
216BOOL OSLibWinSetFocus(HWND hwndDeskTop,HWND hwndNewFocus, BOOL activate)
217{
218 return WinFocusChange (hwndDeskTop, hwndNewFocus, activate ? FC_NOLOSEACTIVE : 0);
219}
220//******************************************************************************
221//******************************************************************************
222BOOL OSLibWinIsChild (HWND hwnd, HWND hwndOf)
223{
224 return WinIsChild (hwnd, hwndOf);
225}
226//******************************************************************************
227//******************************************************************************
228ULONG OSLibGetWindowHeight(HWND hwnd)
229{
230 RECTL rect;
231
232 return (WinQueryWindowRect(hwnd,&rect)) ? rect.yTop-rect.yBottom:0;
233}
234//******************************************************************************
235//******************************************************************************
236LONG OSLibWinQuerySysValue(HWND hwndDeskTop,LONG iSysValue)
237{
238 return WinQuerySysValue(hwndDeskTop,iSysValue);
239}
240//******************************************************************************
241//******************************************************************************
242ULONG OSLibWinQueryDlgItemText(HWND hwndDlg,ULONG idItem,LONG cchBufferMax,char* pchBuffer)
243{
244 return WinQueryDlgItemText(hwndDlg,idItem,cchBufferMax,pchBuffer);
245}
246//******************************************************************************
247//******************************************************************************
248BOOL OSLibWinSetDlgItemText(HWND hwndDlg,ULONG idItem,char* pszText)
249{
250 return WinSetDlgItemText(hwndDlg,idItem,pszText);
251}
252//******************************************************************************
253//******************************************************************************
254BOOL OSLibWinQueryPointerPos(HWND hwndDeskTop,PPOINT pptlPoint)
255{
256 return WinQueryPointerPos(hwndDeskTop,(PPOINTL)pptlPoint);
257}
258//******************************************************************************
259//******************************************************************************
260HWND OSLibWinQueryWindow(HWND hwnd, ULONG lCode)
261{
262 return WinQueryWindow(hwnd, lCode);
263}
264//******************************************************************************
265//******************************************************************************
266BOOL OSLibWinSetWindowPos(HWND hwnd, HWND hwndInsertBehind, LONG x, LONG y, LONG cx,
267 LONG cy, ULONG fl)
268{
269 HWND hwndParent = hwndInsertBehind;
270 BOOL rc;
271
272 if(fl & SWP_MOVE) {
273 switch(hwndParent)
274 {
275 case HWNDOS_TOP:
276 case HWNDOS_BOTTOM:
277 hwndParent = HWND_DESKTOP;
278 break;
279 }
280 y = MapOS2ToWin32Y(hwndParent, cy, y);
281 }
282 rc = WinSetWindowPos(hwnd, hwndInsertBehind, x, y, cx, cy, fl);
283 dprintf(("WinSetWindowPos %x %x %d %d %d %d %x returned %d (%x)", hwnd, hwndInsertBehind, x, y, cx, cy, fl, rc, WinGetLastError(GetThreadHAB())));
284 return rc;
285}
286//******************************************************************************
287//******************************************************************************
288BOOL OSLibWinSetMultWindowPos(PSWP pswp, ULONG num)
289{
290 return WinSetMultWindowPos(GetThreadHAB(), pswp, num);
291}
292//******************************************************************************
293//******************************************************************************
294BOOL OSLibWinShowWindow(HWND hwnd, ULONG fl)
295{
296 BOOL rc;
297
298 if(fl & SWP_SHOW) {
299 rc = WinShowWindow(hwnd, TRUE);
300 }
301 if(rc == 0)
302 dprintf(("WinShowWindow %x failed %x", hwnd, WinGetLastError(GetThreadHAB())));
303 rc = WinSetWindowPos(hwnd, HWND_TOP, 0, 0, 0, 0, fl);
304 if(rc == 0)
305 dprintf(("WinShowWindow %x failed %x", hwnd, WinGetLastError(GetThreadHAB())));
306 return rc;
307}
308//******************************************************************************
309//******************************************************************************
310BOOL OSLibWinDestroyWindow(HWND hwnd)
311{
312 return WinDestroyWindow(hwnd);
313}
314//******************************************************************************
315//******************************************************************************
316BOOL OSLibWinQueryWindowRect(HWND hwnd, PRECT pRect, int RelativeTo)
317{
318 BOOL rc;
319 RECTLOS2 rectl;
320
321 rc = WinQueryWindowRect(hwnd, (PRECTL)&rectl);
322 if(rc) {
323 if(RelativeTo == RELATIVE_TO_SCREEN) {
324 MapOS2ToWin32Rectl(OSLIB_HWND_DESKTOP, hwnd, &rectl, pRect);
325 }
326 else MapOS2ToWin32Rectl(&rectl, pRect);
327 }
328 else memset(pRect, 0, sizeof(RECT));
329 return rc;
330}
331//******************************************************************************
332//******************************************************************************
333BOOL OSLibWinIsIconic(HWND hwnd)
334{
335 SWP swp;
336 BOOL rc;
337
338 rc = WinQueryWindowPos(hwnd, &swp);
339 if(rc == FALSE) {
340 dprintf(("OSLibWinIsIconic: WinQueryWindowPos %x failed", hwnd));
341 return FALSE;
342 }
343
344 if(swp.fl & SWP_MINIMIZE)
345 return TRUE;
346 else return FALSE;
347}
348//******************************************************************************
349//******************************************************************************
350BOOL OSLibWinSetActiveWindow(HWND hwnd)
351{
352 return WinSetActiveWindow(HWND_DESKTOP, hwnd);
353}
354//******************************************************************************
355//******************************************************************************
356BOOL OSLibWinSetFocus(HWND hwnd)
357{
358 return WinSetFocus(HWND_DESKTOP, hwnd);
359}
360//******************************************************************************
361//******************************************************************************
362BOOL OSLibWinEnableWindow(HWND hwnd, BOOL fEnable)
363{
364 return WinEnableWindow(hwnd, fEnable);
365}
366//******************************************************************************
367//******************************************************************************
368BOOL OSLibWinIsWindowEnabled(HWND hwnd)
369{
370 return WinIsWindowEnabled(hwnd);
371}
372//******************************************************************************
373//******************************************************************************
374BOOL OSLibWinIsWindowVisible(HWND hwnd)
375{
376 return WinIsWindowVisible(hwnd);
377}
378//******************************************************************************
379//******************************************************************************
380BOOL OSLibWinQueryActiveWindow()
381{
382 return WinQueryActiveWindow(HWND_DESKTOP);
383}
384//******************************************************************************
385//******************************************************************************
386LONG OSLibWinQueryWindowTextLength(HWND hwnd)
387{
388 return WinQueryWindowTextLength(hwnd);
389}
390//******************************************************************************
391//******************************************************************************
392LONG OSLibWinQueryWindowText(HWND hwnd, LONG length, LPSTR lpsz)
393{
394 return WinQueryWindowText(hwnd, length, lpsz);
395}
396//******************************************************************************
397//******************************************************************************
398BOOL OSLibWinSetWindowText(HWND hwnd, LPSTR lpsz)
399{
400 return WinSetWindowText(hwnd, lpsz);
401}
402//******************************************************************************
403//******************************************************************************
404BOOL OSLibWinFlashWindow(HWND hwnd, BOOL fFlash)
405{
406 return WinFlashWindow(hwnd, fFlash);
407}
408//******************************************************************************
409//******************************************************************************
410HWND OSLibWinWindowFromPoint(HWND hwnd, PVOID ppoint)
411{
412 return WinWindowFromPoint((hwnd == OSLIB_HWND_DESKTOP) ? HWND_DESKTOP : hwnd, (PPOINTL)ppoint, TRUE);
413}
414//******************************************************************************
415//******************************************************************************
416BOOL OSLibWinMinimizeWindow(HWND hwnd)
417{
418 return WinSetWindowPos(hwnd, 0, 0, 0, 0, 0, SWP_MINIMIZE);
419}
420//******************************************************************************
421//******************************************************************************
422BOOL OSLibWinGetBorderSize(HWND hwnd, OSLIBPOINT *pointl)
423{
424 pointl->x = 0;
425 pointl->y = 0;
426 return (BOOL) WinSendMsg(hwnd, WM_QUERYBORDERSIZE, MPFROMP( &pointl), 0);
427}
428//******************************************************************************
429//******************************************************************************
430BOOL OSLibWinSetIcon(HWND hwnd, HANDLE hIcon)
431{
432 return (BOOL) WinSendMsg(hwnd, WM_SETICON, (MPARAM)hIcon, 0);
433}
434//******************************************************************************
435//******************************************************************************
436BOOL OSLibWinQueryWindowPos (HWND hwnd, PSWP pswp)
437{
438 return WinQueryWindowPos(hwnd, pswp);
439}
440//******************************************************************************
441//******************************************************************************
442void OSLibMapSWPtoWINDOWPOS(PSWP pswp, PWINDOWPOS pwpos, PSWP pswpOld, HWND hParent, HWND hFrame)
443{
444 HWND hWindow = pswp->hwnd;
445 HWND hWndInsertAfter = pswp->hwndInsertBehind;
446 long x = pswp->x;
447 long y = pswp->y;
448 long cx = pswp->cx;
449 long cy = pswp->cy;
450 UINT fuFlags = (UINT)pswp->fl;
451 ULONG parentHeight;
452
453 HWND hWinAfter;
454 ULONG flags = 0;
455
456 HWND hWnd = (hWindow == HWND_DESKTOP) ? HWND_DESKTOP_W: hWindow;
457
458 if (hWndInsertAfter == HWND_TOP)
459 hWinAfter = HWND_TOP_W;
460 else if (hWndInsertAfter == HWND_BOTTOM)
461 hWinAfter = HWND_BOTTOM_W;
462 else
463 hWinAfter = (HWND) hWndInsertAfter;
464
465 //***********************************
466 // convert PM flags to Windows flags
467 //***********************************
468 if (!(fuFlags & SWP_SIZE)) flags |= SWP_NOSIZE_W;
469 if (!(fuFlags & SWP_MOVE)) flags |= SWP_NOMOVE_W;
470 if (!(fuFlags & SWP_ZORDER)) flags |= SWP_NOZORDER_W;
471 if ( fuFlags & SWP_NOREDRAW) flags |= SWP_NOREDRAW_W;
472 if (!(fuFlags & SWP_ACTIVATE)) flags |= SWP_NOACTIVATE_W;
473 if ( fuFlags & SWP_SHOW) flags |= SWP_SHOWWINDOW_W;
474 if ( fuFlags & SWP_HIDE) flags |= SWP_HIDEWINDOW_W;
475
476 if (fuFlags & (SWP_MOVE | SWP_SIZE))
477 {
478 if (hParent == NULLHANDLE)
479 {
480 ULONG Offset;
481 POINTL pt = {0, 0};
482
483 Offset = OSLibGetWindowHeight(hFrame) - cy;
484 parentHeight = ScreenHeight;
485
486 cx += 2 * x;
487 cy += Offset;
488 WinMapWindowPoints (hFrame, HWND_DESKTOP, &pt, 1);
489 x = pt.x;
490 y = pt.y;
491
492 pswpOld->cx += 2 * pswpOld->x;
493 pswpOld->cy += Offset;
494 pswpOld->x = pt.x;
495 pswpOld->y = pt.y;
496 }
497 else
498 {
499 parentHeight = OSLibGetWindowHeight(hParent);
500 }
501
502 if (fuFlags & SWP_SIZE)
503 {
504 if (cy != pswpOld->cy)
505 {
506 flags &= ~SWP_NOMOVE_W;
507 }
508 }
509 else
510 {
511 cx = pswpOld->cx;
512 cy = pswpOld->cy;
513 }
514
515 if ((fuFlags & SWP_MOVE) == 0)
516 {
517 x = pswpOld->x;
518 y = pswpOld->y;
519 }
520
521 y = parentHeight - y - cy;
522 LONG oldY = parentHeight - pswpOld->y - pswpOld->cy;
523
524 if ((pswpOld->x == x) && (oldY == y))
525 flags |= SWP_NOMOVE_W;
526
527 if ((pswpOld->cx == cx) && (pswpOld->cy == cy))
528 flags |= SWP_NOSIZE_W;
529 }
530
531 if (hParent == NULLHANDLE)
532 {
533 pswpOld->x = x + pswp->x;
534 pswpOld->y = y + cy - pswp->y - pswp->cy;
535 }
536 else {
537 pswpOld->x = pswp->x;
538 pswpOld->y = parentHeight - pswp->y - cy;
539 }
540 pswpOld->cx = pswp->cx;
541 pswpOld->cy = pswp->cy;
542
543dprintf(("window (%d,%d)(%d,%d) client (%d,%d)(%d,%d)",
544 x,y,cx,cy, pswpOld->x,pswpOld->y,pswpOld->cx,pswpOld->cy));
545
546 pwpos->flags = (UINT)flags;
547 pwpos->cy = (int)cy;
548 pwpos->cx = (int)cx;
549 pwpos->x = (int)x;
550 pwpos->y = (int)y;
551 pwpos->hwndInsertAfter = hWinAfter;
552 pwpos->hwnd = hWindow;
553}
554//******************************************************************************
555//******************************************************************************
556void OSLibMapWINDOWPOStoSWP(PWINDOWPOS pwpos, PSWP pswp, PSWP pswpOld, HWND hParent, HWND hFrame)
557{
558 HWND hWnd = pwpos->hwnd;
559 HWND hWndInsertAfter = pwpos->hwndInsertAfter;
560 long x = pwpos->x;
561 long y = pwpos->y;
562 long cx = pwpos->cx;
563 long cy = pwpos->cy;
564 UINT fuFlags = pwpos->flags;
565 ULONG parentHeight;
566
567 HWND hWinAfter;
568 ULONG flags = 0;
569 HWND hWindow = hWnd ? (HWND)hWnd : HWND_DESKTOP;
570
571 if (hWndInsertAfter == HWND_TOPMOST_W)
572// hWinAfter = HWND_TOPMOST;
573 hWinAfter = HWND_TOP;
574 else if (hWndInsertAfter == HWND_NOTOPMOST_W)
575// hWinAfter = HWND_NOTOPMOST;
576 hWinAfter = HWND_TOP;
577 else if (hWndInsertAfter == HWND_TOP_W)
578 hWinAfter = HWND_TOP;
579 else if (hWndInsertAfter == HWND_BOTTOM_W)
580 hWinAfter = HWND_BOTTOM;
581 else
582 hWinAfter = (HWND) hWndInsertAfter;
583
584 if (!(fuFlags & SWP_NOSIZE_W )) flags |= SWP_SIZE;
585 if (!(fuFlags & SWP_NOMOVE_W )) flags |= SWP_MOVE;
586 if (!(fuFlags & SWP_NOZORDER_W )) flags |= SWP_ZORDER;
587 if ( fuFlags & SWP_NOREDRAW_W ) flags |= SWP_NOREDRAW;
588 if (!(fuFlags & SWP_NOACTIVATE_W)) flags |= SWP_ACTIVATE;
589 if ( fuFlags & SWP_SHOWWINDOW_W) flags |= SWP_SHOW;
590 if ( fuFlags & SWP_HIDEWINDOW_W) flags |= SWP_HIDE;
591
592 if (flags & (SWP_MOVE | SWP_SIZE))
593 {
594 if (hParent == NULLHANDLE)
595 parentHeight = ScreenHeight;
596 else
597 parentHeight = OSLibGetWindowHeight(hParent);
598
599 if ((flags & SWP_MOVE) == 0)
600 {
601 x = pswpOld->x;
602 y = pswpOld->y;
603
604 if (!((y == 0) && (pswpOld->cy == 0)))
605 {
606 y = parentHeight - y - pswpOld->cy;
607 }
608 }
609
610 if (flags & SWP_SIZE)
611 {
612 if (cy != pswpOld->cy)
613 flags |= SWP_MOVE;
614 }
615 else
616 {
617 cx = pswpOld->cx;
618 cy = pswpOld->cy;
619 }
620
621 y = parentHeight - y - cy;
622
623 if ((pswpOld->x == x) && (pswpOld->y == y))
624 flags &= ~SWP_MOVE;
625
626 if ((pswpOld->cx == cx) && (pswpOld->cy == cy))
627 flags &= ~SWP_SIZE;
628 }
629
630 pswp->fl = flags;
631 pswp->cy = cy;
632 pswp->cx = cx;
633 pswp->x = x;
634 pswp->y = y;
635 pswp->hwndInsertBehind = hWinAfter;
636 pswp->hwnd = hWindow;
637 pswp->ulReserved1 = 0;
638 pswp->ulReserved2 = 0;
639}
640//******************************************************************************
641//******************************************************************************
642BOOL OSLibWinCalcFrameRect(HWND hwndFrame, RECTLOS2 *pRect, BOOL fClient)
643{
644 return WinCalcFrameRect(hwndFrame, (PRECTL)pRect, fClient);
645}
646//******************************************************************************
647//******************************************************************************
648BOOL OSLibGetMinMaxInfo(HWND hwndFrame, MINMAXINFO *pMinMax)
649{
650 TRACKINFO tinfo;
651
652 memset(&tinfo, 0, sizeof(TRACKINFO));
653 WinSendMsg(hwndFrame, WM_QUERYTRACKINFO, (MPARAM)0,(MPARAM)&tinfo);
654
655 pMinMax->ptMinTrackSize.x = tinfo.ptlMinTrackSize.x;
656 pMinMax->ptMinTrackSize.y = tinfo.ptlMinTrackSize.y;
657 pMinMax->ptMaxTrackSize.x = tinfo.ptlMaxTrackSize.x;
658 pMinMax->ptMaxTrackSize.y = tinfo.ptlMaxTrackSize.y;
659 return TRUE;
660}
661//******************************************************************************
662//******************************************************************************
663HWND OSLibWinBeginEnumWindows(HWND hwnd)
664{
665 if(hwnd == OSLIB_HWND_DESKTOP) hwnd = HWND_DESKTOP;
666 else
667 if(hwnd == OSLIB_HWND_OBJECT) hwnd = HWND_OBJECT;
668
669 return WinBeginEnumWindows(hwnd);
670}
671//******************************************************************************
672//******************************************************************************
673HWND OSLibWinGetNextWindow(HWND hwndEnum)
674{
675 return WinGetNextWindow(hwndEnum);
676}
677//******************************************************************************
678//******************************************************************************
679HWND OSLibWinQueryClientWindow(HWND hwndFrame)
680{
681 HWND hwndClient = 0;
682
683 if(((ULONG)WinSendMsg(hwndFrame, WM_QUERYFRAMEINFO, NULL, NULL)) & FI_FRAME)
684 hwndClient = WinWindowFromID(hwndFrame, FID_CLIENT);
685
686 return hwndClient;
687}
688//******************************************************************************
689//******************************************************************************
690BOOL OSLibWinEndEnumWindows(HWND hwndEnum)
691{
692 return WinEndEnumWindows(hwndEnum);
693}
694//******************************************************************************
695//******************************************************************************
696BOOL OSLibWinQueryWindowProcess(HWND hwnd, ULONG *pid, ULONG *tid)
697{
698 return WinQueryWindowProcess(hwnd, pid, tid);
699}
700//******************************************************************************
701//******************************************************************************
702BOOL OSLibWinMapWindowPoints (HWND hwndFrom, HWND hwndTo, OSLIBPOINT *pptl, ULONG num)
703{
704 return WinMapWindowPoints (hwndFrom, hwndTo, (PPOINTL)pptl, num);
705}
706//******************************************************************************
707//******************************************************************************
708BOOL OSLibWinEnableScrollBar(HWND hwndParent, int scrollBar, BOOL fEnable)
709{
710 HWND hwndScroll;
711
712 if(scrollBar == OSLIB_VSCROLL) {
713 hwndScroll = WinWindowFromID(hwndParent, FID_VERTSCROLL);
714 }
715 else hwndScroll = WinWindowFromID(hwndParent, FID_HORZSCROLL);
716
717 if(hwndScroll == NULL)
718 return FALSE;
719
720 return WinEnableWindow(hwndScroll, fEnable);
721}
722//******************************************************************************
723//******************************************************************************
724BOOL OSLibWinShowScrollBar(HWND hwndParent, HWND hwndScroll, int scrollBar, BOOL fShow)
725{
726 if(hwndScroll == NULL) {
727 dprintf(("OSLibWinShowScrollBar: scrollbar %d (parent %x) not found!", scrollBar, hwndParent));
728 return FALSE;
729 }
730
731 if(fShow != WinIsWindowVisible(hwndScroll))
732 {
733 WinSetParent(hwndScroll, fShow ? hwndParent : HWND_OBJECT, FALSE);
734 WinSendMsg(hwndParent, WM_UPDATEFRAME,
735 MPFROMLONG( ( scrollBar == OSLIB_VSCROLL ) ? FCF_VERTSCROLL
736 : FCF_HORZSCROLL),
737 MPVOID );
738
739 WinShowWindow(hwndScroll, fShow);
740 }
741 return TRUE;
742}
743//******************************************************************************
744//******************************************************************************
745HWND OSLibWinQueryScrollBarHandle(HWND hwndParent, int scrollBar)
746{
747 if(scrollBar == OSLIB_VSCROLL) {
748 return WinWindowFromID(hwndParent, FID_VERTSCROLL);
749 }
750 else return WinWindowFromID(hwndParent, FID_HORZSCROLL);
751}
752//******************************************************************************
753//******************************************************************************
754ULONG OSLibWinGetScrollPos(HWND hwndParent, HWND hwndScroll)
755{
756 if(hwndScroll == NULL)
757 return 0;
758
759 return (ULONG)WinSendMsg(hwndScroll, SBM_QUERYPOS, 0, 0);
760}
761//******************************************************************************
762//******************************************************************************
763ULONG OSLibWinSetScrollPos(HWND hwndParent, HWND hwndScroll, int pos, int fRedraw)
764{
765 ULONG oldPos;
766
767 if(hwndScroll == NULL)
768 return 0;
769
770 oldPos = (ULONG)WinSendMsg(hwndScroll, SBM_QUERYPOS, 0, 0);
771
772 if(WinSendMsg(hwndScroll, SBM_SETPOS, MPFROMSHORT(pos), MPFROMLONG(fRedraw)) == FALSE)
773 return 0;
774
775 return oldPos;
776}
777//******************************************************************************
778//******************************************************************************
779BOOL OSLibWinSetScrollRange(HWND hwndParent, HWND hwndScroll, int minpos,
780 int maxpos, int fRedraw)
781{
782 if(hwndScroll == NULL)
783 return 0;
784
785 return (BOOL)WinSendMsg( hwndScroll, SBM_SETSCROLLBAR,
786 MPFROMLONG(WinSendMsg(hwndScroll, SBM_QUERYPOS, 0, 0)),
787 MPFROM2SHORT( minpos ,maxpos ) );
788}
789//******************************************************************************
790//******************************************************************************
791BOOL OSLibWinSetScrollPageSize(HWND hwndParent, HWND hwndScroll, int pagesize,
792 int totalsize, int fRedraw)
793{
794 if(hwndScroll == NULL)
795 return 0;
796
797 return (BOOL)WinSendMsg( hwndScroll, SBM_SETTHUMBSIZE,
798 MPFROM2SHORT(pagesize, totalsize),
799 0);
800}
801//******************************************************************************
802//******************************************************************************
803void OSLibTranslateScrollCmdAndMsg(ULONG *msg, ULONG *scrollcmd)
804{
805 switch(*scrollcmd)
806 {
807 case SB_LINEUP:
808 *scrollcmd = SB_LINEUP_W;
809 break;
810 case SB_LINEDOWN:
811 *scrollcmd = SB_LINEDOWN_W;
812 break;
813 case SB_PAGEUP:
814 *scrollcmd = SB_PAGEUP_W;
815 break;
816 case SB_PAGEDOWN:
817 *scrollcmd = SB_PAGEDOWN_W;
818 break;
819 case SB_SLIDERTRACK:
820 *scrollcmd = SB_THUMBTRACK_W;
821 break;
822 case SB_SLIDERPOSITION:
823 *scrollcmd = SB_THUMBPOSITION_W;
824 break;
825 case SB_ENDSCROLL:
826 *scrollcmd = SB_ENDSCROLL_W;
827 break;
828 }
829 *msg = (*msg == WM_HSCROLL) ? WM_HSCROLL_W : WM_VSCROLL_W;
830 return;
831}
832//******************************************************************************
833//******************************************************************************
834void OSLibSetWindowStyle(HWND hwnd, ULONG dwStyle)
835{
836 ULONG OSWinStyle, OSFrameStyle;
837
838 OSLibWinConvertStyle(dwStyle, 0, &OSWinStyle, &OSFrameStyle);
839
840 WinSetWindowULong(hwnd, QWL_STYLE,
841 (WinQueryWindowULong(hwnd, QWL_STYLE) & ~0xffff0000) |
842 OSWinStyle);
843
844 if(OSFrameStyle != 0) // maybe WinQueryClassName == WC_FRAME is better
845 {
846 if(OSFrameStyle & FCF_TITLEBAR)
847 {
848 WinSetParent(OSLibWinObjectWindowFromID(hwnd, FID_TITLEBAR), hwnd, FALSE);
849 WinSetParent(OSLibWinObjectWindowFromID(hwnd, FID_MENU), hwnd, FALSE);
850 }
851 else
852 {
853 WinSetParent(WinWindowFromID(hwnd, FID_TITLEBAR), HWND_OBJECT, FALSE);
854 WinSetParent(WinWindowFromID(hwnd, FID_MENU), HWND_OBJECT, FALSE);
855 }
856 if(OSFrameStyle & FCF_SYSMENU)
857 WinSetParent(OSLibWinObjectWindowFromID(hwnd, FID_SYSMENU), hwnd, FALSE);
858 else
859 WinSetParent(WinWindowFromID(hwnd, FID_SYSMENU), HWND_OBJECT, FALSE);
860
861 if(OSFrameStyle & FCF_MINBUTTON | OSFrameStyle & FCF_MAXBUTTON)
862 WinSetParent(OSLibWinObjectWindowFromID(hwnd, FID_MINMAX), hwnd, FALSE);
863 else
864 WinSetParent(WinWindowFromID(hwnd, FID_MINMAX), HWND_OBJECT, FALSE);
865
866 if(OSFrameStyle & FCF_VERTSCROLL)
867 WinSetParent(OSLibWinObjectWindowFromID(hwnd, FID_VERTSCROLL), hwnd, FALSE);
868 else
869 WinSetParent(WinWindowFromID(hwnd, FID_VERTSCROLL), HWND_OBJECT, FALSE);
870
871 if(OSFrameStyle & FCF_HORZSCROLL)
872 WinSetParent(OSLibWinObjectWindowFromID(hwnd, FID_HORZSCROLL), hwnd, FALSE);
873 else
874 WinSetParent(WinWindowFromID(hwnd, FID_HORZSCROLL), HWND_OBJECT, FALSE);
875
876 WinSendMsg(hwnd, WM_UPDATEFRAME,
877 MPFROMLONG(FCF_TITLEBAR | FCF_SYSMENU | FCF_MINMAX |
878 FCF_MENU | FCF_VERTSCROLL | FCF_HORZSCROLL),
879 MPVOID);
880 }
881}
882//******************************************************************************
883//******************************************************************************
884HWND OSLibWinObjectWindowFromID(HWND hwndOwner, ULONG ID)
885{
886 HWND hwndNext, hwndFound=0;
887 HENUM henum;
888
889 henum = WinBeginEnumWindows(HWND_OBJECT);
890 while ((hwndNext = WinGetNextWindow(henum)) != 0)
891 {
892 if(WinQueryWindow(hwndNext, QW_OWNER) == hwndOwner &&
893 WinQueryWindowUShort(hwndNext, QWS_ID) == ID)
894 {
895 hwndFound = hwndNext;
896 break;
897 }
898 }
899 WinEndEnumWindows(henum);
900 return hwndFound;
901}
902//******************************************************************************
903//******************************************************************************
904BOOL OSLibSetWindowID(HWND hwnd, ULONG value)
905{
906 dprintf(("OSLibSetWindowID hwnd:%x ID:%x", hwnd, value));
907 return WinSetWindowULong(hwnd, QWS_ID, value);
908}
909//******************************************************************************
910//******************************************************************************
Note: See TracBrowser for help on using the repository browser.