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

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

Many bugfixes

File size: 34.7 KB
Line 
1/* $Id: oslibwin.cpp,v 1.63 2000-01-21 13:30:34 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//******************************************************************************
30//******************************************************************************
31BOOL OSLibWinSetParent(HWND hwnd, HWND hwndParent, ULONG fRedraw)
32{
33 if(hwndParent == OSLIB_HWND_DESKTOP)
34 {
35 hwndParent = HWND_DESKTOP;
36 }
37 else
38 if(hwndParent == OSLIB_HWND_OBJECT) {
39 hwndParent = HWND_OBJECT;
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,
52 char *pszName, HWND Owner, ULONG fHWND_BOTTOM, HWND *hwndFrame,
53 ULONG id, BOOL fTaskList,BOOL saveBits)
54{
55 HWND hwndClient;
56
57 dprintf(("WinCreateWindow %x %s", hwndParent, 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 ULONG dwClientStyle = 0;
69 ULONG dwFrameStyle = 0;
70#if 1
71
72 BOOL TopLevel = hwndParent == HWND_DESKTOP;
73
74 FRAMECDATA FCData = {sizeof (FRAMECDATA), 0, 0, 0};
75
76 dwClientStyle = dwWinStyle & ~(WS_TABSTOP | WS_GROUP | WS_CLIPSIBLINGS);
77 if (saveBits) dwWinStyle |= WS_SAVEBITS;
78
79 dwFrameStyle |= FCF_NOBYTEALIGN;
80 if(fTaskList)
81 {
82 dwFrameStyle |= FCF_TASKLIST | FCF_NOMOVEWITHOWNER;
83 }
84
85 dwWinStyle &= ~WS_CLIPCHILDREN;
86 FCData.flCreateFlags = dwFrameStyle;
87
88 *hwndFrame = WinCreateWindow (hwndParent,
89 TopLevel ? WC_FRAME : WIN32_INNERFRAME,
90 pszName, dwWinStyle, 0, 0, 0, 0,
91 hwndParent, HWND_TOP,
92 id, &FCData, NULL);
93
94 if (*hwndFrame) {
95 hwndClient = WinCreateWindow (*hwndFrame,saveBits ? WIN32_STDCLASS:WIN32_STDCLASS2,
96 NULL, dwClientStyle, 0, 0, 0, 0,
97 *hwndFrame, HWND_TOP, FID_CLIENT, NULL, NULL);
98 return hwndClient;
99 }
100 dprintf(("OSLibWinCreateWindow: (FRAME) WinCreateStdWindow failed (%x)", WinGetLastError(GetThreadHAB())));
101 return 0;
102#else
103 dwClientStyle = dwWinStyle & ~(WS_TABSTOP | WS_GROUP);
104
105 dwFrameStyle |= FCF_NOBYTEALIGN;
106 if ((hwndParent == HWND_DESKTOP) && (dwFrameStyle & FCF_TITLEBAR))
107 dwFrameStyle |= FCF_TASKLIST | FCF_NOMOVEWITHOWNER;
108
109 dwWinStyle &= ~WS_CLIPCHILDREN;
110
111 *hwndFrame = WinCreateStdWindow(hwndParent, dwWinStyle,
112 &dwFrameStyle, WIN32_STDCLASS,
113 "", dwClientStyle, 0, id, &hwndClient);
114 if(*hwndFrame) {
115 if(pszName) {
116 WinSetWindowText(*hwndFrame, pszName);
117 }
118 return hwndClient;
119 }
120 dprintf(("OSLibWinCreateWindow: (FRAME) WinCreateStdWindow failed (%x)", WinGetLastError(GetThreadHAB())));
121 return 0;
122#endif
123}
124//******************************************************************************
125//******************************************************************************
126BOOL OSLibWinConvertStyle(ULONG dwStyle, ULONG *dwExStyle, ULONG *OSWinStyle, ULONG *OSFrameStyle, ULONG *borderWidth, ULONG *borderHeight)
127{
128 *OSWinStyle = 0;
129 *OSFrameStyle = 0;
130 *borderWidth = 0;
131 *borderHeight = 0;
132
133 /* Window styles */
134 if(dwStyle & WS_MINIMIZE_W)
135 *OSWinStyle |= WS_MINIMIZED;
136//Done explicitely in CreateWindowExA
137#if 1
138 if(dwStyle & WS_VISIBLE_W)
139 *OSWinStyle |= WS_VISIBLE;
140#endif
141 if(dwStyle & WS_DISABLED_W)
142 *OSWinStyle |= WS_DISABLED;
143 if(dwStyle & WS_CLIPSIBLINGS_W)
144 *OSWinStyle |= WS_CLIPSIBLINGS;
145 if(dwStyle & WS_CLIPCHILDREN_W)
146 *OSWinStyle |= WS_CLIPCHILDREN;
147 if(dwStyle & WS_MAXIMIZE_W)
148 *OSWinStyle |= WS_MAXIMIZED;
149 if(dwStyle & WS_GROUP_W)
150 *OSWinStyle |= WS_GROUP;
151 if(dwStyle & WS_TABSTOP_W)
152 *OSWinStyle |= WS_TABSTOP;
153
154 if(dwStyle & WS_CHILD_W && !((dwStyle & WS_CAPTION_W) == WS_CAPTION_W))
155 {
156//SvL: Causes crash in VPBuddy if enabled -> find bug
157#if 0
158 if (!HAS_3DFRAME(*dwExStyle) && (dwStyle & (WS_DLGFRAME_W | WS_THICKFRAME_W))) *dwExStyle |= WS_EX_DLGMODALFRAME_W;
159#endif
160
161 if (*dwExStyle & WS_EX_CLIENTEDGE_W)
162 {
163 *OSFrameStyle |= FCF_SIZEBORDER;
164 *borderHeight = *borderWidth = 2;
165 }
166 else
167 if (*dwExStyle & WS_EX_DLGMODALFRAME_W)
168 {
169 *OSFrameStyle |= FCF_SIZEBORDER;
170 *borderHeight = *borderWidth = 3;
171 }
172 else
173 if (*dwExStyle & WS_EX_STATICEDGE_W)
174 {
175 *OSFrameStyle |= FCF_SIZEBORDER;
176 *borderHeight = *borderWidth = 2;
177 }
178 else
179 if(dwStyle & WS_BORDER_W)
180 {
181 *OSFrameStyle |= FCF_BORDER;
182 *borderHeight = *borderWidth = 1;
183 }
184 else if (*dwExStyle & WS_EX_WINDOWEDGE_W); //no border
185
186 if(dwStyle & WS_VSCROLL_W)
187 *OSFrameStyle |= FCF_VERTSCROLL;
188 if(dwStyle & WS_HSCROLL_W)
189 *OSFrameStyle |= FCF_HORZSCROLL;
190 }
191 else
192 {
193 if((dwStyle & WS_CAPTION_W) == WS_DLGFRAME_W)
194 *OSFrameStyle |= FCF_DLGBORDER;
195 else
196 {
197 if((dwStyle & WS_CAPTION_W) == WS_CAPTION_W)
198 *OSFrameStyle |= (FCF_TITLEBAR | FCF_BORDER);
199 else
200 if(dwStyle & WS_BORDER_W)
201 *OSFrameStyle |= FCF_BORDER;
202 }
203
204 if(dwStyle & WS_VSCROLL_W)
205 *OSFrameStyle |= FCF_VERTSCROLL;
206 if(dwStyle & WS_HSCROLL_W)
207 *OSFrameStyle |= FCF_HORZSCROLL;
208
209 if(dwStyle & WS_SYSMENU_W)
210 *OSFrameStyle |= FCF_SYSMENU;
211 if(dwStyle & WS_THICKFRAME_W)
212 *OSFrameStyle |= FCF_SIZEBORDER; //??
213 if(dwStyle & WS_MINIMIZEBOX_W)
214 *OSFrameStyle |= FCF_MINBUTTON;
215 if(dwStyle & WS_MAXIMIZEBOX_W)
216 *OSFrameStyle |= FCF_MAXBUTTON;
217
218 if(*dwExStyle & WS_EX_DLGMODALFRAME_W)
219 *OSFrameStyle |= FCF_DLGBORDER;
220 }
221
222 //Clear certain frame bits when the window doesn't have a titlebar
223 if(!(*OSFrameStyle & FCF_TITLEBAR)) {
224 *OSFrameStyle &= ~(FCF_MINBUTTON|FCF_MAXBUTTON|FCF_SYSMENU);
225 }
226 return TRUE;
227}
228//******************************************************************************
229//******************************************************************************
230BOOL OSLibWinSetWindowULong(HWND hwnd, ULONG offset, ULONG value)
231{
232 if(offset == OSLIB_QWL_USER)
233 offset = QWL_USER;
234
235 return WinSetWindowULong(hwnd, offset, value);
236}
237//******************************************************************************
238//******************************************************************************
239ULONG OSLibWinGetWindowULong(HWND hwnd, ULONG offset)
240{
241 if(offset == OSLIB_QWL_USER)
242 offset = QWL_USER;
243
244 return WinQueryWindowULong(hwnd, offset);
245}
246//******************************************************************************
247//******************************************************************************
248BOOL OSLibWinAlarm(HWND hwndDeskTop,ULONG flStyle)
249{
250 return WinAlarm(hwndDeskTop,flStyle);
251}
252//******************************************************************************
253//******************************************************************************
254APIRET OSLibDosBeep(ULONG freg,ULONG dur)
255{
256 return DosBeep(freg,dur);
257}
258//******************************************************************************
259//******************************************************************************
260HWND OSLibWinQueryFocus(HWND hwndDeskTop)
261{
262 return WinQueryFocus(hwndDeskTop);
263}
264//******************************************************************************
265//******************************************************************************
266HWND OSLibWinWindowFromID(HWND hwndParent,ULONG id)
267{
268 return WinWindowFromID(hwndParent,id);
269}
270//******************************************************************************
271//******************************************************************************
272BOOL OSLibWinSetFocus(HWND hwndDeskTop,HWND hwndNewFocus, BOOL activate)
273{
274 return WinFocusChange (hwndDeskTop, hwndNewFocus, activate ? FC_NOLOSEACTIVE : 0);
275}
276//******************************************************************************
277//******************************************************************************
278BOOL OSLibWinIsChild (HWND hwnd, HWND hwndOf)
279{
280 return WinIsChild (hwnd, hwndOf);
281}
282//******************************************************************************
283//******************************************************************************
284ULONG OSLibGetWindowHeight(HWND hwnd)
285{
286 RECTL rect;
287
288 return (WinQueryWindowRect(hwnd,&rect)) ? rect.yTop-rect.yBottom:0;
289}
290//******************************************************************************
291//******************************************************************************
292LONG OSLibWinQuerySysValue(HWND hwndDeskTop,LONG iSysValue)
293{
294 return WinQuerySysValue(hwndDeskTop,iSysValue);
295}
296//******************************************************************************
297//******************************************************************************
298ULONG OSLibWinQueryDlgItemText(HWND hwndDlg,ULONG idItem,LONG cchBufferMax,char* pchBuffer)
299{
300 return WinQueryDlgItemText(hwndDlg,idItem,cchBufferMax,pchBuffer);
301}
302//******************************************************************************
303//******************************************************************************
304BOOL OSLibWinSetDlgItemText(HWND hwndDlg,ULONG idItem,char* pszText)
305{
306 return WinSetDlgItemText(hwndDlg,idItem,pszText);
307}
308//******************************************************************************
309//******************************************************************************
310BOOL OSLibWinQueryPointerPos(HWND hwndDeskTop,PPOINT pptlPoint)
311{
312 return WinQueryPointerPos(hwndDeskTop,(PPOINTL)pptlPoint);
313}
314//******************************************************************************
315//******************************************************************************
316HWND OSLibWinQueryWindow(HWND hwnd, ULONG lCode)
317{
318 return WinQueryWindow(hwnd, lCode);
319}
320//******************************************************************************
321//******************************************************************************
322BOOL OSLibWinSetMultWindowPos(PSWP pswp, ULONG num)
323{
324 return WinSetMultWindowPos(GetThreadHAB(), pswp, num);
325}
326//******************************************************************************
327//******************************************************************************
328BOOL OSLibWinShowWindow(HWND hwnd, ULONG fl)
329{
330 BOOL rc = 1;
331
332 if(fl & SWP_SHOW) {
333 rc = WinShowWindow(hwnd, TRUE);
334 }
335 if(rc == 0)
336 dprintf(("WinShowWindow %x failed %x", hwnd, WinGetLastError(GetThreadHAB())));
337 rc = WinSetWindowPos(hwnd, 0, 0, 0, 0, 0, fl);
338 if(rc == 0)
339 dprintf(("WinShowWindow %x failed %x", hwnd, WinGetLastError(GetThreadHAB())));
340 return rc;
341}
342//******************************************************************************
343//******************************************************************************
344BOOL OSLibWinDestroyWindow(HWND hwnd)
345{
346 return WinDestroyWindow(hwnd);
347}
348//******************************************************************************
349//******************************************************************************
350BOOL OSLibWinQueryWindowRect(HWND hwnd, PRECT pRect, int RelativeTo)
351{
352 BOOL rc;
353 RECTLOS2 rectl;
354
355 rc = WinQueryWindowRect(hwnd, (PRECTL)&rectl);
356 if(rc) {
357 if(RelativeTo == RELATIVE_TO_SCREEN) {
358 mapOS2ToWin32Rect(hwnd,OSLIB_HWND_DESKTOP,&rectl,pRect);
359 }
360 else mapOS2ToWin32Rect(hwnd,&rectl,pRect);
361 }
362 else memset(pRect, 0, sizeof(RECT));
363 return rc;
364}
365//******************************************************************************
366//******************************************************************************
367BOOL OSLibWinIsIconic(HWND hwnd)
368{
369 SWP swp;
370 BOOL rc;
371
372 rc = WinQueryWindowPos(hwnd, &swp);
373 if(rc == FALSE) {
374 dprintf(("OSLibWinIsIconic: WinQueryWindowPos %x failed", hwnd));
375 return FALSE;
376 }
377
378 if(swp.fl & SWP_MINIMIZE)
379 return TRUE;
380 else return FALSE;
381}
382//******************************************************************************
383//******************************************************************************
384BOOL OSLibWinSetActiveWindow(HWND hwnd)
385{
386 return WinSetActiveWindow(HWND_DESKTOP, hwnd);
387}
388//******************************************************************************
389//******************************************************************************
390BOOL OSLibWinSetFocus(HWND hwnd)
391{
392 return WinSetFocus(HWND_DESKTOP, hwnd);
393}
394//******************************************************************************
395//******************************************************************************
396BOOL OSLibWinEnableWindow(HWND hwnd, BOOL fEnable)
397{
398 BOOL rc;
399 HWND hwndClient;
400
401 rc = WinEnableWindow(hwnd, fEnable);
402 hwndClient = WinWindowFromID(hwnd, FID_CLIENT);
403 if(hwndClient) {
404 WinEnableWindow(hwndClient, fEnable);
405 }
406 return rc;
407}
408//******************************************************************************
409//******************************************************************************
410BOOL OSLibWinIsWindowEnabled(HWND hwnd)
411{
412 return WinIsWindowEnabled(hwnd);
413}
414//******************************************************************************
415//******************************************************************************
416BOOL OSLibWinIsWindowVisible(HWND hwnd)
417{
418 return WinIsWindowVisible(hwnd);
419}
420//******************************************************************************
421//******************************************************************************
422BOOL OSLibWinQueryActiveWindow()
423{
424 return WinQueryActiveWindow(HWND_DESKTOP);
425}
426//******************************************************************************
427//******************************************************************************
428LONG OSLibWinQueryWindowTextLength(HWND hwnd)
429{
430 return WinQueryWindowTextLength(hwnd);
431}
432//******************************************************************************
433//******************************************************************************
434LONG OSLibWinQueryWindowText(HWND hwnd, LONG length, LPSTR lpsz)
435{
436 return WinQueryWindowText(hwnd, length, lpsz);
437}
438//******************************************************************************
439//******************************************************************************
440BOOL OSLibWinSetWindowText(HWND hwnd, LPSTR lpsz)
441{
442 return WinSetWindowText(hwnd, lpsz);
443}
444//******************************************************************************
445//******************************************************************************
446BOOL OSLibWinFlashWindow(HWND hwnd, BOOL fFlash)
447{
448 return WinFlashWindow(hwnd, fFlash);
449}
450//******************************************************************************
451//******************************************************************************
452HWND OSLibWinWindowFromPoint(HWND hwnd, PVOID ppoint)
453{
454 return WinWindowFromPoint((hwnd == OSLIB_HWND_DESKTOP) ? HWND_DESKTOP : hwnd, (PPOINTL)ppoint, TRUE);
455}
456//******************************************************************************
457//******************************************************************************
458BOOL OSLibWinMinimizeWindow(HWND hwnd)
459{
460 return WinSetWindowPos(hwnd, 0, 0, 0, 0, 0, SWP_MINIMIZE);
461}
462//******************************************************************************
463//******************************************************************************
464BOOL OSLibWinGetBorderSize(HWND hwnd, OSLIBPOINT *pointl)
465{
466 pointl->x = 0;
467 pointl->y = 0;
468 return (BOOL) WinSendMsg(hwnd, WM_QUERYBORDERSIZE, MPFROMP( &pointl), 0);
469}
470//******************************************************************************
471//******************************************************************************
472BOOL OSLibWinSetIcon(HWND hwnd, HANDLE hIcon)
473{
474 return (BOOL) WinSendMsg(hwnd, WM_SETICON, (MPARAM)hIcon, 0);
475}
476//******************************************************************************
477//******************************************************************************
478BOOL OSLibWinQueryWindowPos (HWND hwnd, PSWP pswp)
479{
480 return WinQueryWindowPos(hwnd, pswp);
481}
482//******************************************************************************
483//******************************************************************************
484void OSLibMapSWPtoWINDOWPOS(PSWP pswp, PWINDOWPOS pwpos, PSWP pswpOld, HWND hParent, HWND hFrame)
485{
486 HWND hWindow = pswp->hwnd;
487 HWND hWndInsertAfter = pswp->hwndInsertBehind;
488 long x = pswp->x;
489 long y = pswp->y;
490 long cx = pswp->cx;
491 long cy = pswp->cy;
492 UINT fuFlags = (UINT)pswp->fl;
493 ULONG parentHeight;
494
495 HWND hWinAfter;
496 ULONG flags = 0;
497 SWP swpFrame, swpClient;
498 POINTL point;
499
500 HWND hWnd = (hWindow == HWND_DESKTOP) ? HWND_DESKTOP_W: hWindow;
501
502 if (hWndInsertAfter == HWND_TOP)
503 hWinAfter = HWND_TOP_W;
504 else if (hWndInsertAfter == HWND_BOTTOM)
505 hWinAfter = HWND_BOTTOM_W;
506 else
507 hWinAfter = (HWND) hWndInsertAfter;
508
509 //***********************************
510 // convert PM flags to Windows flags
511 //***********************************
512 if (!(fuFlags & SWP_SIZE)) flags |= SWP_NOSIZE_W;
513 if (!(fuFlags & SWP_MOVE)) flags |= SWP_NOMOVE_W;
514 if (!(fuFlags & SWP_ZORDER)) flags |= SWP_NOZORDER_W;
515 if ( fuFlags & SWP_NOREDRAW) flags |= SWP_NOREDRAW_W;
516 if (!(fuFlags & SWP_ACTIVATE)) flags |= SWP_NOACTIVATE_W;
517 if ( fuFlags & SWP_SHOW) flags |= SWP_SHOWWINDOW_W;
518 if ( fuFlags & SWP_HIDE) flags |= SWP_HIDEWINDOW_W;
519 if ( fuFlags & SWP_NOADJUST) flags |= SWP_NOSENDCHANGING_W;
520
521 WinQueryWindowPos(hFrame, &swpFrame);
522
523 if(fuFlags & (SWP_MOVE | SWP_SIZE))
524 {
525 point.x = swpFrame.x;
526 point.y = swpFrame.y;
527 if(hParent)
528 {
529 WinMapWindowPoints(hParent, HWND_DESKTOP, &point, 1);
530 }
531 point.y = ScreenHeight-point.y-swpFrame.cy;
532
533 cy = swpFrame.cy;
534 cx = swpFrame.cx;
535 x = point.x;
536 y = point.y;
537
538 if ((pswp->x == pswpOld->x) && (pswp->y == pswpOld->y))
539 flags |= SWP_NOMOVE_W;
540
541 if ((pswp->cx == pswpOld->cx) && (pswp->cy == pswpOld->cy))
542 flags |= SWP_NOSIZE_W;
543
544 if (fuFlags & SWP_SIZE)
545 {
546 if (pswp->cy != pswpOld->cy)
547 {
548 flags &= ~SWP_NOMOVE_W;
549 }
550 }
551 }
552
553 pswpOld->x = pswp->x;
554 pswpOld->y = swpFrame.cy-pswp->y-pswp->cy;
555 pswpOld->cx = pswp->cx;
556 pswpOld->cy = pswp->cy;
557
558 dprintf(("window (%d,%d)(%d,%d) client (%d,%d)(%d,%d)",
559 x,y,cx,cy, pswpOld->x,pswpOld->y,pswpOld->cx,pswpOld->cy));
560
561 pwpos->flags = (UINT)flags;
562 pwpos->cy = cy;
563 pwpos->cx = cx;
564 pwpos->x = x;
565 pwpos->y = y;
566 pwpos->hwndInsertAfter = hWinAfter;
567 pwpos->hwnd = hWindow;
568}
569//******************************************************************************
570//******************************************************************************
571void OSLibMapSWPtoWINDOWPOSFrame(PSWP pswp, struct tagWINDOWPOS *pwpos, PSWP pswpOld, HWND hParent, HWND hFrame)
572{
573 HWND hWindow = pswp->hwnd;
574 HWND hWndInsertAfter = pswp->hwndInsertBehind;
575 long x = pswp->x;
576 long y = pswp->y;
577 long cx = pswp->cx;
578 long cy = pswp->cy;
579 UINT fuFlags = (UINT)pswp->fl;
580 ULONG parentHeight;
581
582 HWND hWinAfter;
583 ULONG flags = 0;
584 SWP swpClient;
585 POINTL point;
586
587 HWND hWnd = (hWindow == HWND_DESKTOP) ? HWND_DESKTOP_W: hWindow;
588
589 if (hWndInsertAfter == HWND_TOP)
590 hWinAfter = HWND_TOP_W;
591 else if (hWndInsertAfter == HWND_BOTTOM)
592 hWinAfter = HWND_BOTTOM_W;
593 else
594 hWinAfter = (HWND) hWndInsertAfter;
595
596 //***********************************
597 // convert PM flags to Windows flags
598 //***********************************
599 if (!(fuFlags & SWP_SIZE)) flags |= SWP_NOSIZE_W;
600 if (!(fuFlags & SWP_MOVE)) flags |= SWP_NOMOVE_W;
601 if (!(fuFlags & SWP_ZORDER)) flags |= SWP_NOZORDER_W;
602 if ( fuFlags & SWP_NOREDRAW) flags |= SWP_NOREDRAW_W;
603 if (!(fuFlags & SWP_ACTIVATE)) flags |= SWP_NOACTIVATE_W;
604 if ( fuFlags & SWP_SHOW) flags |= SWP_SHOWWINDOW_W;
605 if ( fuFlags & SWP_HIDE) flags |= SWP_HIDEWINDOW_W;
606 if ( fuFlags & SWP_NOADJUST) flags |= SWP_NOSENDCHANGING_W;
607
608 WinQueryWindowPos(WinWindowFromID(hFrame, FID_CLIENT), &swpClient);
609
610 if(fuFlags & (SWP_MOVE | SWP_SIZE))
611 {
612 point.x = x;
613 point.y = y;
614
615 if(hParent)
616 {
617 WinMapWindowPoints(hParent, HWND_DESKTOP, &point, 1);
618 }
619 point.y = ScreenHeight-point.y-cy;
620
621 x = point.x;
622 y = point.y;
623
624 if ((pswp->x == pswpOld->x) && (pswp->y == pswpOld->y))
625 flags |= SWP_NOMOVE_W;
626
627 if ((pswp->cx == pswpOld->cx) && (pswp->cy == pswpOld->cy))
628 flags |= SWP_NOSIZE_W;
629
630 if (fuFlags & SWP_SIZE)
631 {
632 if (pswp->cy != pswpOld->cy)
633 {
634 flags &= ~SWP_NOMOVE_W;
635 }
636 }
637 }
638
639 pswpOld->x = swpClient.x;
640 pswpOld->y = pswp->cy-swpClient.y-swpClient.cy;
641 pswpOld->cx = swpClient.cx;
642 pswpOld->cy = swpClient.cy;
643
644 dprintf(("window (%d,%d)(%d,%d) client (%d,%d)(%d,%d)",
645 x,y,cx,cy, pswpOld->x,pswpOld->y,pswpOld->cx,pswpOld->cy));
646
647 pwpos->flags = (UINT)flags;
648 pwpos->cy = cy;
649 pwpos->cx = cx;
650 pwpos->x = x;
651 pwpos->y = y;
652 pwpos->hwndInsertAfter = hWinAfter;
653 pwpos->hwnd = hWindow;
654}
655//******************************************************************************
656//******************************************************************************
657void OSLibMapWINDOWPOStoSWP(PWINDOWPOS pwpos, PSWP pswp, PSWP pswpOld, HWND hParent, HWND hFrame)
658{
659 BOOL fCvt = FALSE;
660
661 HWND hWnd = pwpos->hwnd;
662 HWND hWndInsertAfter = pwpos->hwndInsertAfter;
663 long x = pwpos->x;
664 long y = pwpos->y;
665 long cx = pwpos->cx;
666 long cy = pwpos->cy;
667 UINT fuFlags = pwpos->flags;
668 ULONG parentHeight;
669
670 HWND hWinAfter;
671 ULONG flags = 0;
672 HWND hWindow = hWnd ? (HWND)hWnd : HWND_DESKTOP;
673
674 if (hWndInsertAfter == HWND_TOPMOST_W)
675// hWinAfter = HWND_TOPMOST;
676 hWinAfter = HWND_TOP;
677 else if (hWndInsertAfter == HWND_NOTOPMOST_W)
678// hWinAfter = HWND_NOTOPMOST;
679 hWinAfter = HWND_TOP;
680 else if (hWndInsertAfter == HWND_TOP_W)
681 hWinAfter = HWND_TOP;
682 else if (hWndInsertAfter == HWND_BOTTOM_W)
683 hWinAfter = HWND_BOTTOM;
684 else
685 hWinAfter = (HWND) hWndInsertAfter;
686
687 if (!(fuFlags & SWP_NOSIZE_W )) flags |= SWP_SIZE;
688 if (!(fuFlags & SWP_NOMOVE_W )) flags |= SWP_MOVE;
689 if (!(fuFlags & SWP_NOZORDER_W )) flags |= SWP_ZORDER;
690 if ( fuFlags & SWP_NOREDRAW_W ) flags |= SWP_NOREDRAW;
691 if (!(fuFlags & SWP_NOACTIVATE_W)) flags |= SWP_ACTIVATE;
692 if ( fuFlags & SWP_SHOWWINDOW_W) flags |= SWP_SHOW;
693 if ( fuFlags & SWP_HIDEWINDOW_W) flags |= SWP_HIDE;
694 if ( fuFlags & SWP_NOSENDCHANGING_W) flags |= SWP_NOADJUST;
695
696 if (flags & (SWP_MOVE | SWP_SIZE))
697 {
698 if (hParent == NULLHANDLE)
699 parentHeight = ScreenHeight;
700 else
701 parentHeight = OSLibGetWindowHeight(hParent);
702
703 if ((flags & SWP_MOVE) == 0)
704 {
705 x = pswpOld->x;
706 y = pswpOld->y;
707
708 if (!((y == 0) && (pswpOld->cy == 0)))
709 {
710 y = parentHeight-y-pswpOld->cy;
711 }
712 }
713
714 if (flags & SWP_SIZE)
715 {
716 if (cy != pswpOld->cy)
717 flags |= SWP_MOVE;
718 }
719 else
720 {
721 cx = pswpOld->cx;
722 cy = pswpOld->cy;
723 }
724 y = parentHeight-y-cy;
725
726
727 if ((pswpOld->x == x) && (pswpOld->y == y))
728 flags &= ~SWP_MOVE;
729
730 if ((pswpOld->cx == cx) && (pswpOld->cy == cy))
731 flags &= ~SWP_SIZE;
732 }
733
734 pswp->fl = flags;
735 pswp->cy = cy;
736 pswp->cx = cx;
737 pswp->x = x;
738 pswp->y = y;
739 pswp->hwndInsertBehind = hWinAfter;
740 pswp->hwnd = hWindow;
741 pswp->ulReserved1 = 0;
742 pswp->ulReserved2 = 0;
743}
744//******************************************************************************
745//Position in screen coordinates
746//******************************************************************************
747void OSLibMapWINDOWPOStoSWPFrame(PWINDOWPOS pwpos, PSWP pswp, PSWP pswpOld, HWND hParent, HWND hFrame)
748{
749 BOOL fCvt = FALSE;
750
751 HWND hWnd = pwpos->hwnd;
752 HWND hWndInsertAfter = pwpos->hwndInsertAfter;
753 long x = pwpos->x;
754 long y = pwpos->y;
755 long cx = pwpos->cx;
756 long cy = pwpos->cy;
757 UINT fuFlags = pwpos->flags;
758 ULONG parentHeight;
759 POINTL point;
760
761 HWND hWinAfter;
762 ULONG flags = 0;
763 HWND hWindow = hWnd ? (HWND)hWnd : HWND_DESKTOP;
764
765 if (hWndInsertAfter == HWND_TOPMOST_W)
766// hWinAfter = HWND_TOPMOST;
767 hWinAfter = HWND_TOP;
768 else if (hWndInsertAfter == HWND_NOTOPMOST_W)
769// hWinAfter = HWND_NOTOPMOST;
770 hWinAfter = HWND_TOP;
771 else if (hWndInsertAfter == HWND_TOP_W)
772 hWinAfter = HWND_TOP;
773 else if (hWndInsertAfter == HWND_BOTTOM_W)
774 hWinAfter = HWND_BOTTOM;
775 else
776 hWinAfter = (HWND) hWndInsertAfter;
777
778 if (!(fuFlags & SWP_NOSIZE_W )) flags |= SWP_SIZE;
779 if (!(fuFlags & SWP_NOMOVE_W )) flags |= SWP_MOVE;
780 if (!(fuFlags & SWP_NOZORDER_W )) flags |= SWP_ZORDER;
781 if ( fuFlags & SWP_NOREDRAW_W ) flags |= SWP_NOREDRAW;
782 if (!(fuFlags & SWP_NOACTIVATE_W)) flags |= SWP_ACTIVATE;
783 if ( fuFlags & SWP_SHOWWINDOW_W) flags |= SWP_SHOW;
784 if ( fuFlags & SWP_HIDEWINDOW_W) flags |= SWP_HIDE;
785 if ( fuFlags & SWP_NOSENDCHANGING_W) flags |= SWP_NOADJUST;
786
787 if (flags & (SWP_MOVE | SWP_SIZE))
788 {
789 point.x = x;
790 point.y = y;
791
792 if(hParent) {
793 parentHeight = OSLibGetWindowHeight(hParent);
794
795 point.y = ScreenHeight-point.y-cy;
796 WinMapWindowPoints(HWND_DESKTOP, hParent, &point, 1);
797 point.y = parentHeight-point.y-cy;
798 }
799 else parentHeight = ScreenHeight;
800
801 x = point.x;
802 y = point.y;
803
804 if (flags & SWP_SIZE)
805 {
806 if (cy != pswpOld->cy)
807 flags |= SWP_MOVE;
808 }
809 else
810 {
811 cx = pswpOld->cx;
812 cy = pswpOld->cy;
813 }
814 y = parentHeight-y-cy;
815
816
817 if ((pswpOld->x == x) && (pswpOld->y == y))
818 flags &= ~SWP_MOVE;
819
820 if ((pswpOld->cx == cx) && (pswpOld->cy == cy))
821 flags &= ~SWP_SIZE;
822 }
823
824 pswp->fl = flags;
825 pswp->cy = cy;
826 pswp->cx = cx;
827 pswp->x = x;
828 pswp->y = y;
829 pswp->hwndInsertBehind = hWinAfter;
830 pswp->hwnd = hWindow;
831 pswp->ulReserved1 = 0;
832 pswp->ulReserved2 = 0;
833}
834//******************************************************************************
835//******************************************************************************
836BOOL OSLibWinCalcFrameRect(HWND hwndFrame, RECT *pRect, BOOL fClient)
837{
838 BOOL rc;
839
840 WinMapWindowPoints(hwndFrame, HWND_DESKTOP, (PPOINTL)pRect, 2);
841
842 rc = WinCalcFrameRect(hwndFrame, (PRECTL)pRect, fClient);
843 WinMapWindowPoints(HWND_DESKTOP, hwndFrame, (PPOINTL)pRect, 2);
844
845 return rc;
846}
847//******************************************************************************
848//******************************************************************************
849BOOL OSLibGetMinMaxInfo(HWND hwndFrame, MINMAXINFO *pMinMax)
850{
851 TRACKINFO tinfo;
852
853 memset(&tinfo, 0, sizeof(TRACKINFO));
854 WinSendMsg(hwndFrame, WM_QUERYTRACKINFO, (MPARAM)0,(MPARAM)&tinfo);
855
856 pMinMax->ptMinTrackSize.x = tinfo.ptlMinTrackSize.x;
857 pMinMax->ptMinTrackSize.y = tinfo.ptlMinTrackSize.y;
858 pMinMax->ptMaxTrackSize.x = tinfo.ptlMaxTrackSize.x;
859 pMinMax->ptMaxTrackSize.y = tinfo.ptlMaxTrackSize.y;
860 return TRUE;
861}
862//******************************************************************************
863//******************************************************************************
864HWND OSLibWinBeginEnumWindows(HWND hwnd)
865{
866 if(hwnd == OSLIB_HWND_DESKTOP) hwnd = HWND_DESKTOP;
867 else
868 if(hwnd == OSLIB_HWND_OBJECT) hwnd = HWND_OBJECT;
869
870 return WinBeginEnumWindows(hwnd);
871}
872//******************************************************************************
873//******************************************************************************
874HWND OSLibWinGetNextWindow(HWND hwndEnum)
875{
876 return WinGetNextWindow(hwndEnum);
877}
878//******************************************************************************
879//******************************************************************************
880HWND OSLibWinQueryClientWindow(HWND hwndFrame)
881{
882 HWND hwndClient = 0;
883
884 if(((ULONG)WinSendMsg(hwndFrame, WM_QUERYFRAMEINFO, NULL, NULL)) & FI_FRAME)
885 hwndClient = WinWindowFromID(hwndFrame, FID_CLIENT);
886
887 return hwndClient;
888}
889//******************************************************************************
890//******************************************************************************
891BOOL OSLibWinEndEnumWindows(HWND hwndEnum)
892{
893 return WinEndEnumWindows(hwndEnum);
894}
895//******************************************************************************
896//******************************************************************************
897BOOL OSLibWinQueryWindowProcess(HWND hwnd, ULONG *pid, ULONG *tid)
898{
899 return WinQueryWindowProcess(hwnd, pid, tid);
900}
901//******************************************************************************
902//******************************************************************************
903BOOL OSLibWinMapWindowPoints (HWND hwndFrom, HWND hwndTo, OSLIBPOINT *pptl, ULONG num)
904{
905 return WinMapWindowPoints (hwndFrom, hwndTo, (PPOINTL)pptl, num);
906}
907//******************************************************************************
908//******************************************************************************
909HWND OSLibWinQueryObjectWindow(VOID)
910{
911 return WinQueryObjectWindow(HWND_DESKTOP);
912}
913//******************************************************************************
914//******************************************************************************
915HWND OSLibWinObjectWindowFromID(HWND hwndOwner, ULONG ID)
916{
917 HWND hwndNext, hwndFound=0;
918 HENUM henum;
919
920 henum = WinBeginEnumWindows(HWND_OBJECT);
921 while ((hwndNext = WinGetNextWindow(henum)) != 0)
922 {
923 if(WinQueryWindow(hwndNext, QW_OWNER) == hwndOwner &&
924 WinQueryWindowUShort(hwndNext, QWS_ID) == ID)
925 {
926 hwndFound = hwndNext;
927 break;
928 }
929 }
930 WinEndEnumWindows(henum);
931 return hwndFound;
932}
933//******************************************************************************
934//******************************************************************************
935BOOL OSLibSetWindowID(HWND hwnd, ULONG value)
936{
937 dprintf(("OSLibSetWindowID hwnd:%x ID:%x", hwnd, value));
938 return WinSetWindowULong(hwnd, QWS_ID, value);
939}
940//******************************************************************************
941//******************************************************************************
942PVOID OSLibWinSubclassWindow(HWND hwnd,PVOID newWndProc)
943{
944 return WinSubclassWindow(hwnd,(PFNWP)newWndProc);
945}
946//******************************************************************************
947//******************************************************************************
948BOOL OSLibSetWindowRestoreRect(HWND hwnd, PRECT pRect)
949{
950 ULONG yHeight = OSLibGetWindowHeight(WinQueryWindow(hwnd, QW_PARENT));
951
952 WinSetWindowUShort(hwnd, QWS_XRESTORE, (USHORT)pRect->left );
953 WinSetWindowUShort(hwnd, QWS_YRESTORE, (USHORT)(yHeight - pRect->top -
954 (pRect->bottom - pRect->top)));
955 WinSetWindowUShort(hwnd, QWS_CXRESTORE, (USHORT)(pRect->right - pRect->left));
956 WinSetWindowUShort(hwnd, QWS_CYRESTORE, (USHORT)(pRect->bottom - pRect->top));
957 return TRUE;
958}
959//******************************************************************************
960//******************************************************************************
961BOOL OSLibSetWindowMinPos(HWND hwnd, ULONG x, ULONG y)
962{
963 ULONG yHeight = OSLibGetWindowHeight(WinQueryWindow(hwnd, QW_PARENT));
964
965 WinSetWindowUShort(hwnd, QWS_XMINIMIZE, (USHORT)x );
966 WinSetWindowUShort(hwnd, QWS_YMINIMIZE, (USHORT)(yHeight - y -
967 ( 2 * WinQuerySysValue( HWND_DESKTOP, SV_CYSIZEBORDER)) -
968 WinQuerySysValue( HWND_DESKTOP, SV_CYICON)));
969 return TRUE;
970}
971//******************************************************************************
972//******************************************************************************
973BOOL OSLibWinGetKeyboardStateTable(unsigned char *PMKeyState)
974{
975 return WinSetKeyboardStateTable(HWND_DESKTOP, (PBYTE)&PMKeyState, FALSE );
976}
977//******************************************************************************
978//******************************************************************************
979BOOL OSLibWinSetKeyboardStateTable(unsigned char *PMKeyState)
980{
981 return WinSetKeyboardStateTable(HWND_DESKTOP, (PBYTE)&PMKeyState, TRUE );
982}
983//******************************************************************************
984//******************************************************************************
985BOOL OSLibWinEnableWindowUpdate(HWND hwnd,BOOL fEnable)
986{
987 return WinEnableWindowUpdate(hwnd,fEnable);
988}
989//******************************************************************************
990//******************************************************************************
991ULONG OSLibWinGetLastError()
992{
993 return WinGetLastError(GetThreadHAB()) & 0xFFFF;
994}
995//******************************************************************************
996//******************************************************************************
997void OSLibWinShowTaskList(HWND hwndFrame)
998{
999 //CB: don't know if this works on all machines
1000 WinSetActiveWindow(HWND_DESKTOP,0x8000000E);
1001}
1002//******************************************************************************
1003//******************************************************************************
Note: See TracBrowser for help on using the repository browser.