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

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

position change bugfixes

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