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

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

Bugfix for SetPos bugfix, Edit controls now work, experimental fix in Edit control for VPBuddy

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