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

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

Lots of changes

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