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

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

Dialog, style + window handle translation bugfixes

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