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

Last change on this file since 1248 was 1248, checked in by cbratschi, 26 years ago

pmframe finished

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