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

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

wm_adjustwindowpos & combobox fixes

File size: 35.1 KB
Line 
1/* $Id: oslibwin.cpp,v 1.33 1999-10-21 12:19: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, swpClient;
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 if ( fuFlags & SWP_NOADJUST) flags |= SWP_NOSENDCHANGING_W;
511
512 WinQueryWindowPos(hFrame, &swpFrame);
513
514 if ( fuFlags & SWP_NOADJUST) {
515 WinQueryWindowPos(WinWindowFromID(hFrame, FID_CLIENT), &swpClient);
516 x = swpClient.x;
517 cx = swpClient.cx;
518 y = swpClient.y;
519 cy = swpClient.cy;
520 }
521
522 if(fuFlags & (SWP_MOVE | SWP_SIZE))
523 {
524 point.x = swpFrame.x;
525 point.y = swpFrame.y;
526 if(hParent)
527 {
528 WinMapWindowPoints(hParent, HWND_DESKTOP, &point, 1);
529 }
530 point.y = OSLibQueryScreenHeight() - point.y - swpFrame.cy;
531
532 cy = swpFrame.cy;
533 cx = swpFrame.cx;
534 x = point.x;
535 y = point.y;
536
537 if ((pswp->x == pswpOld->x) && (pswp->y == pswpOld->y))
538 flags |= SWP_NOMOVE_W;
539
540 if ((pswp->cx == pswpOld->cx) && (pswp->cy == pswpOld->cy))
541 flags |= SWP_NOSIZE_W;
542
543 if (fuFlags & SWP_SIZE)
544 {
545 if (pswp->cy != pswpOld->cy)
546 {
547 flags &= ~SWP_NOMOVE_W;
548 }
549 }
550 }
551
552 pswpOld->x = pswp->x;
553 pswpOld->y = swpFrame.cy - pswp->y - pswp->cy;
554 pswpOld->cx = pswp->cx;
555 pswpOld->cy = pswp->cy;
556
557 dprintf(("window (%d,%d)(%d,%d) client (%d,%d)(%d,%d)",
558 x,y,cx,cy, pswpOld->x,pswpOld->y,pswpOld->cx,pswpOld->cy));
559
560 pwpos->flags = (UINT)flags;
561 pwpos->cy = cy;
562 pwpos->cx = cx;
563 pwpos->x = x;
564 pwpos->y = y;
565 pwpos->hwndInsertAfter = hWinAfter;
566 pwpos->hwnd = hWindow;
567}
568//******************************************************************************
569//******************************************************************************
570void OSLibMapWINDOWPOStoSWP(PWINDOWPOS pwpos, PSWP pswp, PSWP pswpOld, HWND hParent, HWND hFrame)
571{
572 BOOL fCvt = FALSE;
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 if ( fuFlags & SWP_NOSENDCHANGING_W) flags |= SWP_NOADJUST;
608
609 if (flags & (SWP_MOVE | SWP_SIZE))
610 {
611 if (hParent == NULLHANDLE)
612 parentHeight = ScreenHeight;
613 else
614 parentHeight = OSLibGetWindowHeight(hParent);
615
616 if ((flags & SWP_MOVE) == 0)
617 {
618 x = pswpOld->x;
619 y = pswpOld->y;
620
621 if (!((y == 0) && (pswpOld->cy == 0)))
622 {
623 y = parentHeight - y - pswpOld->cy;
624 }
625 }
626
627 if (flags & SWP_SIZE)
628 {
629 if (cy != pswpOld->cy)
630 flags |= SWP_MOVE;
631 }
632 else
633 {
634 cx = pswpOld->cx;
635 cy = pswpOld->cy;
636 }
637 y = parentHeight - y - cy;
638
639
640 if ((pswpOld->x == x) && (pswpOld->y == y))
641 flags &= ~SWP_MOVE;
642
643 if ((pswpOld->cx == cx) && (pswpOld->cy == cy))
644 flags &= ~SWP_SIZE;
645 }
646
647 pswp->fl = flags;
648 pswp->cy = cy;
649 pswp->cx = cx;
650 pswp->x = x;
651 pswp->y = y;
652 pswp->hwndInsertBehind = hWinAfter;
653 pswp->hwnd = hWindow;
654 pswp->ulReserved1 = 0;
655 pswp->ulReserved2 = 0;
656}
657//******************************************************************************
658//******************************************************************************
659BOOL OSLibWinCalcFrameRect(HWND hwndFrame, RECT *pRect, BOOL fClient)
660{
661 BOOL rc;
662
663 WinMapWindowPoints(hwndFrame, HWND_DESKTOP, (PPOINTL)pRect, 2);
664
665 rc = WinCalcFrameRect(hwndFrame, (PRECTL)pRect, fClient);
666 WinMapWindowPoints(HWND_DESKTOP, hwndFrame, (PPOINTL)pRect, 2);
667
668 return rc;
669}
670//******************************************************************************
671//******************************************************************************
672BOOL OSLibGetMinMaxInfo(HWND hwndFrame, MINMAXINFO *pMinMax)
673{
674 TRACKINFO tinfo;
675
676 memset(&tinfo, 0, sizeof(TRACKINFO));
677 WinSendMsg(hwndFrame, WM_QUERYTRACKINFO, (MPARAM)0,(MPARAM)&tinfo);
678
679 pMinMax->ptMinTrackSize.x = tinfo.ptlMinTrackSize.x;
680 pMinMax->ptMinTrackSize.y = tinfo.ptlMinTrackSize.y;
681 pMinMax->ptMaxTrackSize.x = tinfo.ptlMaxTrackSize.x;
682 pMinMax->ptMaxTrackSize.y = tinfo.ptlMaxTrackSize.y;
683 return TRUE;
684}
685//******************************************************************************
686//******************************************************************************
687HWND OSLibWinBeginEnumWindows(HWND hwnd)
688{
689 if(hwnd == OSLIB_HWND_DESKTOP) hwnd = HWND_DESKTOP;
690 else
691 if(hwnd == OSLIB_HWND_OBJECT) hwnd = HWND_OBJECT;
692
693 return WinBeginEnumWindows(hwnd);
694}
695//******************************************************************************
696//******************************************************************************
697HWND OSLibWinGetNextWindow(HWND hwndEnum)
698{
699 return WinGetNextWindow(hwndEnum);
700}
701//******************************************************************************
702//******************************************************************************
703HWND OSLibWinQueryClientWindow(HWND hwndFrame)
704{
705 HWND hwndClient = 0;
706
707 if(((ULONG)WinSendMsg(hwndFrame, WM_QUERYFRAMEINFO, NULL, NULL)) & FI_FRAME)
708 hwndClient = WinWindowFromID(hwndFrame, FID_CLIENT);
709
710 return hwndClient;
711}
712//******************************************************************************
713//******************************************************************************
714BOOL OSLibWinEndEnumWindows(HWND hwndEnum)
715{
716 return WinEndEnumWindows(hwndEnum);
717}
718//******************************************************************************
719//******************************************************************************
720BOOL OSLibWinQueryWindowProcess(HWND hwnd, ULONG *pid, ULONG *tid)
721{
722 return WinQueryWindowProcess(hwnd, pid, tid);
723}
724//******************************************************************************
725//******************************************************************************
726BOOL OSLibWinMapWindowPoints (HWND hwndFrom, HWND hwndTo, OSLIBPOINT *pptl, ULONG num)
727{
728 return WinMapWindowPoints (hwndFrom, hwndTo, (PPOINTL)pptl, num);
729}
730//******************************************************************************
731//******************************************************************************
732BOOL OSLibWinEnableScrollBar(HWND hwndParent, int scrollBar, BOOL fEnable)
733{
734 HWND hwndScroll;
735
736 if(scrollBar == OSLIB_VSCROLL) {
737 hwndScroll = WinWindowFromID(hwndParent, FID_VERTSCROLL);
738 }
739 else hwndScroll = WinWindowFromID(hwndParent, FID_HORZSCROLL);
740
741 if(hwndScroll == NULL)
742 return FALSE;
743
744 return WinEnableWindow(hwndScroll, fEnable);
745}
746//******************************************************************************
747//******************************************************************************
748BOOL OSLibWinShowScrollBar(HWND hwndParent, HWND hwndScroll, int scrollBar,
749 BOOL fShow, BOOL fForceChange)
750{
751 if(hwndScroll == NULL) {
752 dprintf(("OSLibWinShowScrollBar: scrollbar %d (parent %x) not found!", scrollBar, hwndParent));
753 return FALSE;
754 }
755
756 if(fShow != WinIsWindowVisible(hwndScroll) || fForceChange)
757 {
758 WinSetParent(hwndScroll, fShow ? hwndParent : HWND_OBJECT, FALSE);
759 WinSendMsg(hwndParent, WM_UPDATEFRAME,
760 MPFROMLONG( ( scrollBar == OSLIB_VSCROLL ) ? FCF_VERTSCROLL
761 : FCF_HORZSCROLL),
762 MPVOID );
763
764 WinShowWindow(hwndScroll, fShow);
765 }
766 return TRUE;
767}
768//******************************************************************************
769//******************************************************************************
770HWND OSLibWinQueryScrollBarHandle(HWND hwndParent, int scrollBar)
771{
772 if(scrollBar == OSLIB_VSCROLL) {
773 return WinWindowFromID(hwndParent, FID_VERTSCROLL);
774 }
775 else return WinWindowFromID(hwndParent, FID_HORZSCROLL);
776}
777//******************************************************************************
778//******************************************************************************
779ULONG OSLibWinGetScrollPos(HWND hwndParent, HWND hwndScroll)
780{
781 if(hwndScroll == NULL)
782 return 0;
783
784 return (ULONG)WinSendMsg(hwndScroll, SBM_QUERYPOS, 0, 0);
785}
786//******************************************************************************
787//******************************************************************************
788ULONG OSLibWinSetScrollPos(HWND hwndParent, HWND hwndScroll, int pos, int fRedraw)
789{
790 ULONG oldPos;
791
792 if(hwndScroll == NULL)
793 return 0;
794
795 oldPos = (ULONG)WinSendMsg(hwndScroll, SBM_QUERYPOS, 0, 0);
796
797 if(WinSendMsg(hwndScroll, SBM_SETPOS, MPFROMSHORT(pos), MPFROMLONG(fRedraw)) == FALSE)
798 return 0;
799
800 return oldPos;
801}
802//******************************************************************************
803//******************************************************************************
804BOOL OSLibWinSetScrollRange(HWND hwndParent, HWND hwndScroll, int minpos,
805 int maxpos, int fRedraw)
806{
807 if(hwndScroll == NULL)
808 return 0;
809
810 return (BOOL)WinSendMsg( hwndScroll, SBM_SETSCROLLBAR,
811 MPFROMLONG(WinSendMsg(hwndScroll, SBM_QUERYPOS, 0, 0)),
812 MPFROM2SHORT( minpos ,maxpos ) );
813}
814//******************************************************************************
815//******************************************************************************
816BOOL OSLibWinSetScrollPageSize(HWND hwndParent, HWND hwndScroll, int pagesize,
817 int totalsize, int fRedraw)
818{
819 if(hwndScroll == NULL)
820 return 0;
821
822 return (BOOL)WinSendMsg( hwndScroll, SBM_SETTHUMBSIZE,
823 MPFROM2SHORT(pagesize, totalsize),
824 0);
825}
826//******************************************************************************
827//******************************************************************************
828void OSLibTranslateScrollCmdAndMsg(ULONG *msg, ULONG *scrollcmd)
829{
830 switch(*scrollcmd)
831 {
832 case SB_LINEUP:
833 *scrollcmd = SB_LINEUP_W;
834 break;
835 case SB_LINEDOWN:
836 *scrollcmd = SB_LINEDOWN_W;
837 break;
838 case SB_PAGEUP:
839 *scrollcmd = SB_PAGEUP_W;
840 break;
841 case SB_PAGEDOWN:
842 *scrollcmd = SB_PAGEDOWN_W;
843 break;
844 case SB_SLIDERTRACK:
845 *scrollcmd = SB_THUMBTRACK_W;
846 break;
847 case SB_SLIDERPOSITION:
848 *scrollcmd = SB_THUMBPOSITION_W;
849 break;
850 case SB_ENDSCROLL:
851 *scrollcmd = SB_ENDSCROLL_W;
852 break;
853 }
854 *msg = (*msg == WM_HSCROLL) ? WM_HSCROLL_W : WM_VSCROLL_W;
855 return;
856}
857//******************************************************************************
858//******************************************************************************
859void OSLibSetWindowStyle(HWND hwnd, ULONG dwStyle)
860{
861 ULONG OSWinStyle, OSFrameStyle, borderWidth, borderHeight,dwExStyle;
862
863 OSLibWinConvertStyle(dwStyle, &dwExStyle, &OSWinStyle, &OSFrameStyle, &borderWidth, &borderHeight);
864
865 OSWinStyle = OSWinStyle & ~(WS_TABSTOP | WS_GROUP | WS_CLIPCHILDREN);
866
867 WinSetWindowULong(hwnd, QWL_STYLE,
868 (WinQueryWindowULong(hwnd, QWL_STYLE) & ~0xffff0000) |
869 OSWinStyle);
870
871 //CB: bug: it doesn't work with child windows!
872
873 if(OSFrameStyle != 0) // maybe WinQueryClassName == WC_FRAME is better
874 {
875 if(OSFrameStyle & FCF_TITLEBAR)
876 {
877 WinSetParent(OSLibWinObjectWindowFromID(hwnd, FID_TITLEBAR), hwnd, FALSE);
878 WinSetParent(OSLibWinObjectWindowFromID(hwnd, FID_MENU), hwnd, FALSE);
879 }
880 else
881 {
882 WinSetParent(WinWindowFromID(hwnd, FID_TITLEBAR), HWND_OBJECT, FALSE);
883 WinSetParent(WinWindowFromID(hwnd, FID_MENU), HWND_OBJECT, FALSE);
884 }
885 if(OSFrameStyle & FCF_SYSMENU)
886 WinSetParent(OSLibWinObjectWindowFromID(hwnd, FID_SYSMENU), hwnd, FALSE);
887 else
888 WinSetParent(WinWindowFromID(hwnd, FID_SYSMENU), HWND_OBJECT, FALSE);
889
890 if(OSFrameStyle & FCF_MINBUTTON | OSFrameStyle & FCF_MAXBUTTON)
891 WinSetParent(OSLibWinObjectWindowFromID(hwnd, FID_MINMAX), hwnd, FALSE);
892 else
893 WinSetParent(WinWindowFromID(hwnd, FID_MINMAX), HWND_OBJECT, FALSE);
894
895 if(OSFrameStyle & FCF_VERTSCROLL)
896 WinSetParent(OSLibWinObjectWindowFromID(hwnd, FID_VERTSCROLL), hwnd, FALSE);
897 else
898 WinSetParent(WinWindowFromID(hwnd, FID_VERTSCROLL), HWND_OBJECT, FALSE);
899
900 if(OSFrameStyle & FCF_HORZSCROLL)
901 WinSetParent(OSLibWinObjectWindowFromID(hwnd, FID_HORZSCROLL), hwnd, FALSE);
902 else
903 WinSetParent(WinWindowFromID(hwnd, FID_HORZSCROLL), HWND_OBJECT, FALSE);
904
905 WinSendMsg(hwnd, WM_UPDATEFRAME,
906 MPFROMLONG(FCF_TITLEBAR | FCF_SYSMENU | FCF_MINMAX |
907 FCF_MENU | FCF_VERTSCROLL | FCF_HORZSCROLL),
908 MPVOID);
909 }
910}
911//******************************************************************************
912//******************************************************************************
913HWND OSLibWinObjectWindowFromID(HWND hwndOwner, ULONG ID)
914{
915 HWND hwndNext, hwndFound=0;
916 HENUM henum;
917
918 henum = WinBeginEnumWindows(HWND_OBJECT);
919 while ((hwndNext = WinGetNextWindow(henum)) != 0)
920 {
921 if(WinQueryWindow(hwndNext, QW_OWNER) == hwndOwner &&
922 WinQueryWindowUShort(hwndNext, QWS_ID) == ID)
923 {
924 hwndFound = hwndNext;
925 break;
926 }
927 }
928 WinEndEnumWindows(henum);
929 return hwndFound;
930}
931//******************************************************************************
932//******************************************************************************
933BOOL OSLibSetWindowID(HWND hwnd, ULONG value)
934{
935 dprintf(("OSLibSetWindowID hwnd:%x ID:%x", hwnd, value));
936 return WinSetWindowULong(hwnd, QWS_ID, value);
937}
938//******************************************************************************
939//******************************************************************************
940PVOID OSLibWinSubclassWindow(HWND hwnd,PVOID newWndProc)
941{
942 return WinSubclassWindow(hwnd,(PFNWP)newWndProc);
943}
944//******************************************************************************
945//******************************************************************************
946BOOL OSLibSetWindowRestoreRect(HWND hwnd, PRECT pRect)
947{
948 ULONG yHeight = OSLibGetWindowHeight(WinQueryWindow(hwnd, QW_PARENT));
949
950 WinSetWindowUShort(hwnd, QWS_XRESTORE, (USHORT)pRect->left );
951 WinSetWindowUShort(hwnd, QWS_YRESTORE, (USHORT)(yHeight - pRect->top -
952 (pRect->bottom - pRect->top)));
953 WinSetWindowUShort(hwnd, QWS_CXRESTORE, (USHORT)(pRect->right - pRect->left));
954 WinSetWindowUShort(hwnd, QWS_CYRESTORE, (USHORT)(pRect->bottom - pRect->top));
955 return TRUE;
956}
957//******************************************************************************
958//******************************************************************************
959BOOL OSLibSetWindowMinPos(HWND hwnd, ULONG x, ULONG y)
960{
961 ULONG yHeight = OSLibGetWindowHeight(WinQueryWindow(hwnd, QW_PARENT));
962
963 WinSetWindowUShort(hwnd, QWS_XMINIMIZE, (USHORT)x );
964 WinSetWindowUShort(hwnd, QWS_YMINIMIZE, (USHORT)(yHeight - y -
965 ( 2 * WinQuerySysValue( HWND_DESKTOP, SV_CYSIZEBORDER)) -
966 WinQuerySysValue( HWND_DESKTOP, SV_CYICON)));
967 return TRUE;
968}
969//******************************************************************************
970//******************************************************************************
Note: See TracBrowser for help on using the repository browser.