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

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

lots of changes

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