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

Last change on this file since 1202 was 1202, checked in by cbratschi, 26 years ago

SendDlgItemMessage fixed

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