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

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

MDI fix, extra message support etc

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