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

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

WM_CONTEXTMENU, sysmenu changes

File size: 34.8 KB
Line 
1/* $Id: oslibwin.cpp,v 1.62 2000-01-20 16:48:55 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//******************************************************************************
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 RECTL parentRect;
618
619 WinQueryWindowRect(hParent,&parentRect);
620 point.y = parentRect.yTop-point.y-cy;
621 } else point.y = ScreenHeight-point.y-cy;
622
623 x = point.x;
624 y = point.y;
625
626 if ((pswp->x == pswpOld->x) && (pswp->y == pswpOld->y))
627 flags |= SWP_NOMOVE_W;
628
629 if ((pswp->cx == pswpOld->cx) && (pswp->cy == pswpOld->cy))
630 flags |= SWP_NOSIZE_W;
631
632 if (fuFlags & SWP_SIZE)
633 {
634 if (pswp->cy != pswpOld->cy)
635 {
636 flags &= ~SWP_NOMOVE_W;
637 }
638 }
639 }
640
641 pswpOld->x = swpClient.x;
642 pswpOld->y = pswp->cy-swpClient.y-swpClient.cy;
643 pswpOld->cx = swpClient.cx;
644 pswpOld->cy = swpClient.cy;
645
646 dprintf(("window (%d,%d)(%d,%d) client (%d,%d)(%d,%d)",
647 x,y,cx,cy, pswpOld->x,pswpOld->y,pswpOld->cx,pswpOld->cy));
648
649 pwpos->flags = (UINT)flags;
650 pwpos->cy = cy;
651 pwpos->cx = cx;
652 pwpos->x = x;
653 pwpos->y = y;
654 pwpos->hwndInsertAfter = hWinAfter;
655 pwpos->hwnd = hWindow;
656}
657//******************************************************************************
658//******************************************************************************
659void OSLibMapWINDOWPOStoSWP(PWINDOWPOS pwpos, PSWP pswp, PSWP pswpOld, HWND hParent, HWND hFrame)
660{
661 BOOL fCvt = FALSE;
662
663 HWND hWnd = pwpos->hwnd;
664 HWND hWndInsertAfter = pwpos->hwndInsertAfter;
665 long x = pwpos->x;
666 long y = pwpos->y;
667 long cx = pwpos->cx;
668 long cy = pwpos->cy;
669 UINT fuFlags = pwpos->flags;
670 ULONG parentHeight;
671
672 HWND hWinAfter;
673 ULONG flags = 0;
674 HWND hWindow = hWnd ? (HWND)hWnd : HWND_DESKTOP;
675
676 if (hWndInsertAfter == HWND_TOPMOST_W)
677// hWinAfter = HWND_TOPMOST;
678 hWinAfter = HWND_TOP;
679 else if (hWndInsertAfter == HWND_NOTOPMOST_W)
680// hWinAfter = HWND_NOTOPMOST;
681 hWinAfter = HWND_TOP;
682 else if (hWndInsertAfter == HWND_TOP_W)
683 hWinAfter = HWND_TOP;
684 else if (hWndInsertAfter == HWND_BOTTOM_W)
685 hWinAfter = HWND_BOTTOM;
686 else
687 hWinAfter = (HWND) hWndInsertAfter;
688
689 if (!(fuFlags & SWP_NOSIZE_W )) flags |= SWP_SIZE;
690 if (!(fuFlags & SWP_NOMOVE_W )) flags |= SWP_MOVE;
691 if (!(fuFlags & SWP_NOZORDER_W )) flags |= SWP_ZORDER;
692 if ( fuFlags & SWP_NOREDRAW_W ) flags |= SWP_NOREDRAW;
693 if (!(fuFlags & SWP_NOACTIVATE_W)) flags |= SWP_ACTIVATE;
694 if ( fuFlags & SWP_SHOWWINDOW_W) flags |= SWP_SHOW;
695 if ( fuFlags & SWP_HIDEWINDOW_W) flags |= SWP_HIDE;
696 if ( fuFlags & SWP_NOSENDCHANGING_W) flags |= SWP_NOADJUST;
697
698 if (flags & (SWP_MOVE | SWP_SIZE))
699 {
700 if (hParent == NULLHANDLE)
701 parentHeight = ScreenHeight;
702 else
703 parentHeight = OSLibGetWindowHeight(hParent);
704
705 if ((flags & SWP_MOVE) == 0)
706 {
707 x = pswpOld->x;
708 y = pswpOld->y;
709
710 if (!((y == 0) && (pswpOld->cy == 0)))
711 {
712 y = parentHeight-y-pswpOld->cy;
713 }
714 }
715
716 if (flags & SWP_SIZE)
717 {
718 if (cy != pswpOld->cy)
719 flags |= SWP_MOVE;
720 }
721 else
722 {
723 cx = pswpOld->cx;
724 cy = pswpOld->cy;
725 }
726 y = parentHeight-y-cy;
727
728
729 if ((pswpOld->x == x) && (pswpOld->y == y))
730 flags &= ~SWP_MOVE;
731
732 if ((pswpOld->cx == cx) && (pswpOld->cy == cy))
733 flags &= ~SWP_SIZE;
734 }
735
736 pswp->fl = flags;
737 pswp->cy = cy;
738 pswp->cx = cx;
739 pswp->x = x;
740 pswp->y = y;
741 pswp->hwndInsertBehind = hWinAfter;
742 pswp->hwnd = hWindow;
743 pswp->ulReserved1 = 0;
744 pswp->ulReserved2 = 0;
745}
746//******************************************************************************
747//Position in screen coordinates
748//******************************************************************************
749void OSLibMapWINDOWPOStoSWPFrame(PWINDOWPOS pwpos, PSWP pswp, PSWP pswpOld, HWND hParent, HWND hFrame)
750{
751 BOOL fCvt = FALSE;
752
753 HWND hWnd = pwpos->hwnd;
754 HWND hWndInsertAfter = pwpos->hwndInsertAfter;
755 long x = pwpos->x;
756 long y = pwpos->y;
757 long cx = pwpos->cx;
758 long cy = pwpos->cy;
759 UINT fuFlags = pwpos->flags;
760 ULONG parentHeight;
761 POINTL point;
762
763 HWND hWinAfter;
764 ULONG flags = 0;
765 HWND hWindow = hWnd ? (HWND)hWnd : HWND_DESKTOP;
766
767 if (hWndInsertAfter == HWND_TOPMOST_W)
768// hWinAfter = HWND_TOPMOST;
769 hWinAfter = HWND_TOP;
770 else if (hWndInsertAfter == HWND_NOTOPMOST_W)
771// hWinAfter = HWND_NOTOPMOST;
772 hWinAfter = HWND_TOP;
773 else if (hWndInsertAfter == HWND_TOP_W)
774 hWinAfter = HWND_TOP;
775 else if (hWndInsertAfter == HWND_BOTTOM_W)
776 hWinAfter = HWND_BOTTOM;
777 else
778 hWinAfter = (HWND) hWndInsertAfter;
779
780 if (!(fuFlags & SWP_NOSIZE_W )) flags |= SWP_SIZE;
781 if (!(fuFlags & SWP_NOMOVE_W )) flags |= SWP_MOVE;
782 if (!(fuFlags & SWP_NOZORDER_W )) flags |= SWP_ZORDER;
783 if ( fuFlags & SWP_NOREDRAW_W ) flags |= SWP_NOREDRAW;
784 if (!(fuFlags & SWP_NOACTIVATE_W)) flags |= SWP_ACTIVATE;
785 if ( fuFlags & SWP_SHOWWINDOW_W) flags |= SWP_SHOW;
786 if ( fuFlags & SWP_HIDEWINDOW_W) flags |= SWP_HIDE;
787 if ( fuFlags & SWP_NOSENDCHANGING_W) flags |= SWP_NOADJUST;
788
789 if (flags & (SWP_MOVE | SWP_SIZE))
790 {
791 point.x = x;
792 point.y = y;
793
794 if(hParent) {
795 parentHeight = OSLibGetWindowHeight(hParent);
796
797 point.y = ScreenHeight-point.y-cy;
798 WinMapWindowPoints(HWND_DESKTOP, hParent, &point, 1);
799 point.y = parentHeight-point.y-cy;
800 }
801 else parentHeight = ScreenHeight;
802
803 x = point.x;
804 y = point.y;
805
806 if (flags & SWP_SIZE)
807 {
808 if (cy != pswpOld->cy)
809 flags |= SWP_MOVE;
810 }
811 else
812 {
813 cx = pswpOld->cx;
814 cy = pswpOld->cy;
815 }
816 y = parentHeight-y-cy;
817
818
819 if ((pswpOld->x == x) && (pswpOld->y == y))
820 flags &= ~SWP_MOVE;
821
822 if ((pswpOld->cx == cx) && (pswpOld->cy == cy))
823 flags &= ~SWP_SIZE;
824 }
825
826 pswp->fl = flags;
827 pswp->cy = cy;
828 pswp->cx = cx;
829 pswp->x = x;
830 pswp->y = y;
831 pswp->hwndInsertBehind = hWinAfter;
832 pswp->hwnd = hWindow;
833 pswp->ulReserved1 = 0;
834 pswp->ulReserved2 = 0;
835}
836//******************************************************************************
837//******************************************************************************
838BOOL OSLibWinCalcFrameRect(HWND hwndFrame, RECT *pRect, BOOL fClient)
839{
840 BOOL rc;
841
842 WinMapWindowPoints(hwndFrame, HWND_DESKTOP, (PPOINTL)pRect, 2);
843
844 rc = WinCalcFrameRect(hwndFrame, (PRECTL)pRect, fClient);
845 WinMapWindowPoints(HWND_DESKTOP, hwndFrame, (PPOINTL)pRect, 2);
846
847 return rc;
848}
849//******************************************************************************
850//******************************************************************************
851BOOL OSLibGetMinMaxInfo(HWND hwndFrame, MINMAXINFO *pMinMax)
852{
853 TRACKINFO tinfo;
854
855 memset(&tinfo, 0, sizeof(TRACKINFO));
856 WinSendMsg(hwndFrame, WM_QUERYTRACKINFO, (MPARAM)0,(MPARAM)&tinfo);
857
858 pMinMax->ptMinTrackSize.x = tinfo.ptlMinTrackSize.x;
859 pMinMax->ptMinTrackSize.y = tinfo.ptlMinTrackSize.y;
860 pMinMax->ptMaxTrackSize.x = tinfo.ptlMaxTrackSize.x;
861 pMinMax->ptMaxTrackSize.y = tinfo.ptlMaxTrackSize.y;
862 return TRUE;
863}
864//******************************************************************************
865//******************************************************************************
866HWND OSLibWinBeginEnumWindows(HWND hwnd)
867{
868 if(hwnd == OSLIB_HWND_DESKTOP) hwnd = HWND_DESKTOP;
869 else
870 if(hwnd == OSLIB_HWND_OBJECT) hwnd = HWND_OBJECT;
871
872 return WinBeginEnumWindows(hwnd);
873}
874//******************************************************************************
875//******************************************************************************
876HWND OSLibWinGetNextWindow(HWND hwndEnum)
877{
878 return WinGetNextWindow(hwndEnum);
879}
880//******************************************************************************
881//******************************************************************************
882HWND OSLibWinQueryClientWindow(HWND hwndFrame)
883{
884 HWND hwndClient = 0;
885
886 if(((ULONG)WinSendMsg(hwndFrame, WM_QUERYFRAMEINFO, NULL, NULL)) & FI_FRAME)
887 hwndClient = WinWindowFromID(hwndFrame, FID_CLIENT);
888
889 return hwndClient;
890}
891//******************************************************************************
892//******************************************************************************
893BOOL OSLibWinEndEnumWindows(HWND hwndEnum)
894{
895 return WinEndEnumWindows(hwndEnum);
896}
897//******************************************************************************
898//******************************************************************************
899BOOL OSLibWinQueryWindowProcess(HWND hwnd, ULONG *pid, ULONG *tid)
900{
901 return WinQueryWindowProcess(hwnd, pid, tid);
902}
903//******************************************************************************
904//******************************************************************************
905BOOL OSLibWinMapWindowPoints (HWND hwndFrom, HWND hwndTo, OSLIBPOINT *pptl, ULONG num)
906{
907 return WinMapWindowPoints (hwndFrom, hwndTo, (PPOINTL)pptl, num);
908}
909//******************************************************************************
910//******************************************************************************
911HWND OSLibWinQueryObjectWindow(VOID)
912{
913 return WinQueryObjectWindow(HWND_DESKTOP);
914}
915//******************************************************************************
916//******************************************************************************
917HWND OSLibWinObjectWindowFromID(HWND hwndOwner, ULONG ID)
918{
919 HWND hwndNext, hwndFound=0;
920 HENUM henum;
921
922 henum = WinBeginEnumWindows(HWND_OBJECT);
923 while ((hwndNext = WinGetNextWindow(henum)) != 0)
924 {
925 if(WinQueryWindow(hwndNext, QW_OWNER) == hwndOwner &&
926 WinQueryWindowUShort(hwndNext, QWS_ID) == ID)
927 {
928 hwndFound = hwndNext;
929 break;
930 }
931 }
932 WinEndEnumWindows(henum);
933 return hwndFound;
934}
935//******************************************************************************
936//******************************************************************************
937BOOL OSLibSetWindowID(HWND hwnd, ULONG value)
938{
939 dprintf(("OSLibSetWindowID hwnd:%x ID:%x", hwnd, value));
940 return WinSetWindowULong(hwnd, QWS_ID, value);
941}
942//******************************************************************************
943//******************************************************************************
944PVOID OSLibWinSubclassWindow(HWND hwnd,PVOID newWndProc)
945{
946 return WinSubclassWindow(hwnd,(PFNWP)newWndProc);
947}
948//******************************************************************************
949//******************************************************************************
950BOOL OSLibSetWindowRestoreRect(HWND hwnd, PRECT pRect)
951{
952 ULONG yHeight = OSLibGetWindowHeight(WinQueryWindow(hwnd, QW_PARENT));
953
954 WinSetWindowUShort(hwnd, QWS_XRESTORE, (USHORT)pRect->left );
955 WinSetWindowUShort(hwnd, QWS_YRESTORE, (USHORT)(yHeight - pRect->top -
956 (pRect->bottom - pRect->top)));
957 WinSetWindowUShort(hwnd, QWS_CXRESTORE, (USHORT)(pRect->right - pRect->left));
958 WinSetWindowUShort(hwnd, QWS_CYRESTORE, (USHORT)(pRect->bottom - pRect->top));
959 return TRUE;
960}
961//******************************************************************************
962//******************************************************************************
963BOOL OSLibSetWindowMinPos(HWND hwnd, ULONG x, ULONG y)
964{
965 ULONG yHeight = OSLibGetWindowHeight(WinQueryWindow(hwnd, QW_PARENT));
966
967 WinSetWindowUShort(hwnd, QWS_XMINIMIZE, (USHORT)x );
968 WinSetWindowUShort(hwnd, QWS_YMINIMIZE, (USHORT)(yHeight - y -
969 ( 2 * WinQuerySysValue( HWND_DESKTOP, SV_CYSIZEBORDER)) -
970 WinQuerySysValue( HWND_DESKTOP, SV_CYICON)));
971 return TRUE;
972}
973//******************************************************************************
974//******************************************************************************
975BOOL OSLibWinGetKeyboardStateTable(unsigned char *PMKeyState)
976{
977 return WinSetKeyboardStateTable(HWND_DESKTOP, (PBYTE)&PMKeyState, FALSE );
978}
979//******************************************************************************
980//******************************************************************************
981BOOL OSLibWinSetKeyboardStateTable(unsigned char *PMKeyState)
982{
983 return WinSetKeyboardStateTable(HWND_DESKTOP, (PBYTE)&PMKeyState, TRUE );
984}
985//******************************************************************************
986//******************************************************************************
987BOOL OSLibWinEnableWindowUpdate(HWND hwnd,BOOL fEnable)
988{
989 return WinEnableWindowUpdate(hwnd,fEnable);
990}
991//******************************************************************************
992//******************************************************************************
993ULONG OSLibWinGetLastError()
994{
995 return WinGetLastError(GetThreadHAB()) & 0xFFFF;
996}
997//******************************************************************************
998//******************************************************************************
999void OSLibWinShowTaskList(HWND hwndFrame)
1000{
1001 //CB: don't know if this works on all machines
1002 WinSetActiveWindow(HWND_DESKTOP,0x8000000E);
1003}
1004//******************************************************************************
1005//******************************************************************************
Note: See TracBrowser for help on using the repository browser.