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

Last change on this file since 6395 was 6395, checked in by sandervl, 24 years ago

rewrote some functions

File size: 39.9 KB
Line 
1/* $Id: oslibwin.cpp,v 1.107 2001-07-28 13:43:53 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#define INCL_WINSWITCHLIST
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 <winuser32.h>
24#include "oslibwin.h"
25#include "oslibutil.h"
26#include "oslibmsg.h"
27#include "oslibgdi.h"
28#include "pmwindow.h"
29#include "initterm.h"
30
31#define DBG_LOCALLOG DBG_oslibwin
32#include "dbglocal.h"
33
34//******************************************************************************
35//******************************************************************************
36BOOL OSLibWinSetParent(HWND hwnd, HWND hwndParent, ULONG fRedraw)
37{
38 if(hwndParent == OSLIB_HWND_DESKTOP)
39 {
40 hwndParent = HWND_DESKTOP;
41 }
42 else
43 if(hwndParent == OSLIB_HWND_OBJECT) {
44 hwndParent = HWND_OBJECT;
45 }
46 return (WinSetParent(hwnd, hwndParent, fRedraw) == 0);
47}
48//******************************************************************************
49//******************************************************************************
50BOOL OSLibWinSetOwner(HWND hwnd, HWND hwndOwner)
51{
52 return WinSetOwner(hwnd, hwndOwner);
53}
54//******************************************************************************
55//******************************************************************************
56HWND OSLibWinCreateWindow(HWND hwndParent,ULONG dwWinStyle, ULONG dwOSFrameStyle,
57 char *pszName, HWND Owner, ULONG fHWND_BOTTOM,
58 ULONG id, BOOL fTaskList,BOOL fShellPosition,
59 int classStyle, HWND *hwndFrame)
60{
61 HWND hwndClient;
62 ULONG dwFrameStyle = 0;
63
64 if(pszName && *pszName == 0) {
65 pszName = NULL;
66 }
67 if(hwndParent == OSLIB_HWND_DESKTOP) {
68 hwndParent = HWND_DESKTOP;
69 }
70 if(Owner == OSLIB_HWND_DESKTOP) {
71 Owner = HWND_DESKTOP;
72 }
73
74 if(classStyle & CS_SAVEBITS_W) dwWinStyle |= WS_SAVEBITS;
75 if(classStyle & CS_PARENTDC_W) dwWinStyle |= WS_PARENTCLIP;
76
77 dwWinStyle = dwWinStyle & ~(WS_TABSTOP | WS_GROUP);
78
79 if(fTaskList)
80 {
81 dwFrameStyle |= FCF_NOMOVEWITHOWNER;
82 }
83 if (fShellPosition) dwFrameStyle |= FCF_SHELLPOSITION;
84
85 FRAMECDATA FCData = {sizeof (FRAMECDATA), 0, 0, 0};
86 FCData.flCreateFlags = dwFrameStyle;
87
88 dprintf(("WinCreateWindow %x %s %x task %d shell %d classstyle %x winstyle %x bottom %d", hwndParent, pszName, id, fTaskList, fShellPosition, classStyle, dwWinStyle, fHWND_BOTTOM));
89
90 //Must not use WS_CLIPCHILDREN style with frame window. Transparency won't work otherwise.
91 //Eg: dialog parent, groupbox; invalidate part of groupbox -> painting algorithm stops when it finds
92 // a window with WS_CLIPCHILDREN -> result: dialog window won't update groupbox background as groupbox only draws the border
93 *hwndFrame = WinCreateWindow(hwndParent,
94 WIN32_STDFRAMECLASS,
95 pszName, (dwWinStyle & ~WS_CLIPCHILDREN), 0, 0, 0, 0,
96 Owner, (fHWND_BOTTOM) ? HWND_BOTTOM : HWND_TOP,
97 id, (PVOID)&FCData, NULL);
98 if(fOS2Look && *hwndFrame) {
99 FCData.flCreateFlags = dwOSFrameStyle;
100// FCData.flCreateFlags = FCF_TITLEBAR|FCF_SYSMENU|FCF_MINMAX;
101 WinCreateFrameControls(*hwndFrame, &FCData, NULL);
102 }
103 hwndClient = WinCreateWindow (*hwndFrame, WIN32_STDCLASS,
104 NULL, dwWinStyle | WS_VISIBLE, 0, 0, 0, 0,
105 *hwndFrame, HWND_TOP, FID_CLIENT, NULL, NULL);
106
107 return hwndClient;
108}
109//******************************************************************************
110//Note: Also check OSLibSetWindowStyle when changing this!!
111//******************************************************************************
112BOOL OSLibWinConvertStyle(ULONG dwStyle, ULONG dwExStyle, ULONG *OSWinStyle, ULONG *OSFrameStyle)
113{
114 *OSWinStyle = 0;
115 *OSFrameStyle = 0;
116
117 /* Window styles */
118 if(dwStyle & WS_DISABLED_W)
119 *OSWinStyle |= WS_DISABLED;
120 if(dwStyle & WS_CLIPSIBLINGS_W)
121 *OSWinStyle |= WS_CLIPSIBLINGS;
122 if(dwStyle & WS_CLIPCHILDREN_W)
123 *OSWinStyle |= WS_CLIPCHILDREN;
124
125 if(fOS2Look) {
126 if((dwStyle & WS_CAPTION_W) == WS_CAPTION_W) {
127 *OSFrameStyle = FCF_TITLEBAR;
128 if((dwStyle & WS_SYSMENU_W) && !(dwExStyle & WS_EX_TOOLWINDOW_W))
129 {
130 *OSFrameStyle |= FCF_SYSMENU;
131 }
132 if((dwStyle & WS_MINIMIZEBOX_W) || (dwStyle & WS_MAXIMIZEBOX_W)) {
133 *OSFrameStyle |= FCF_MINMAX;
134 }
135 else
136 if(dwStyle & WS_SYSMENU_W) {
137 *OSFrameStyle |= FCF_CLOSEBUTTON;
138 }
139 }
140 }
141 return TRUE;
142}
143//******************************************************************************
144//******************************************************************************
145BOOL OSLibWinPositionFrameControls(HWND hwndFrame, RECTLOS2 *pRect, DWORD dwStyle,
146 DWORD dwExStyle, HICON hSysMenuIcon)
147{
148 SWP swp[3];
149 HWND hwndControl;
150 int i = 0;
151 static int minmaxwidth = 0;
152 static int minmaxheight = 0;
153
154 if(minmaxwidth == 0) {
155 minmaxwidth = WinQuerySysValue(HWND_DESKTOP, SV_CXMINMAXBUTTON);
156 minmaxheight = WinQuerySysValue(HWND_DESKTOP, SV_CYMINMAXBUTTON);
157 }
158
159#if 0
160 hwndControl = WinWindowFromID(hwndFrame, FID_SYSMENU);
161 if(hwndControl) {
162 swp[i].hwnd = hwndControl;
163 swp[i].hwndInsertBehind = HWND_TOP;
164 swp[i].x = pRect->xLeft;
165 swp[i].y = pRect->yBottom;
166 if(pRect->yTop - pRect->yBottom > minmaxheight) {
167 swp[i].y += pRect->yTop - pRect->yBottom - minmaxheight;
168 }
169 swp[i].cx = minmaxwidth/2;
170 swp[i].cy = minmaxheight;;
171 swp[i].fl = SWP_SIZE | SWP_MOVE | SWP_SHOW;
172 dprintf(("FID_SYSMENU (%d,%d)(%d,%d)", swp[i].x, swp[i].y, swp[i].cx, swp[i].cy));
173 pRect->xLeft += minmaxwidth/2;
174 i++;
175 }
176#else
177 if((dwStyle & WS_SYSMENU_W) && !(dwExStyle & WS_EX_TOOLWINDOW_W) && hSysMenuIcon) {
178 pRect->xLeft += minmaxwidth/2;
179 }
180#endif
181 if((dwStyle & WS_CAPTION_W) == WS_CAPTION_W) {
182 hwndControl = WinWindowFromID(hwndFrame, FID_TITLEBAR);
183 if(hwndControl) {
184 swp[i].hwnd = hwndControl;
185 swp[i].hwndInsertBehind = HWND_TOP;
186 swp[i].x = pRect->xLeft;
187 swp[i].y = pRect->yBottom;
188 if(pRect->yTop - pRect->yBottom > minmaxheight) {
189 swp[i].y += pRect->yTop - pRect->yBottom - minmaxheight;
190 }
191 swp[i].cx = pRect->xRight - pRect->xLeft;
192 if((dwStyle & WS_MINIMIZEBOX_W) || (dwStyle & WS_MAXIMIZEBOX_W)) {
193 swp[i].cx -= minmaxwidth;
194 }
195 //there is no close button in warp 3
196 if((dwStyle & WS_SYSMENU_W) && !fVersionWarp3) {
197 swp[i].cx -= minmaxwidth/2;
198 }
199 swp[i].cy = minmaxheight;
200 swp[i].fl = SWP_SIZE | SWP_MOVE | SWP_SHOW;
201 dprintf(("FID_TITLEBAR (%d,%d)(%d,%d)", swp[i].x, swp[i].y, swp[i].cx, swp[i].cy));
202 pRect->xLeft += swp[i].cx;
203 i++;
204 }
205 else return FALSE; //no titlebar -> no frame controls
206 }
207 if((dwStyle & WS_MINIMIZEBOX_W) || (dwStyle & WS_MAXIMIZEBOX_W) || (dwStyle & WS_SYSMENU_W)) {
208 hwndControl = WinWindowFromID(hwndFrame, FID_MINMAX);
209 if(hwndControl) {
210 swp[i].hwnd = hwndControl;
211 swp[i].hwndInsertBehind = HWND_TOP;
212 swp[i].x = pRect->xLeft;
213 swp[i].y = pRect->yBottom;
214 if(pRect->yTop - pRect->yBottom > minmaxheight) {
215 swp[i].y += pRect->yTop - pRect->yBottom - minmaxheight;
216 }
217 swp[i].cx = 0;
218 if((dwStyle & WS_MINIMIZEBOX_W) || (dwStyle & WS_MAXIMIZEBOX_W)) {
219 swp[i].cx += minmaxwidth;
220 }
221 //there is no close button in warp 3
222 if((dwStyle & WS_SYSMENU_W) && !fVersionWarp3) {
223 swp[i].cx += minmaxwidth/2;
224 }
225 swp[i].cy = minmaxheight;
226 swp[i].fl = SWP_SIZE | SWP_MOVE | SWP_SHOW;
227 dprintf(("FID_MINMAX (%d,%d)(%d,%d)", swp[i].x, swp[i].y, swp[i].cx, swp[i].cy));
228 pRect->xLeft += swp[i].cx;
229 i++;
230 }
231 }
232 return WinSetMultWindowPos(GetThreadHAB(), swp, i);
233}
234//******************************************************************************
235//******************************************************************************
236BOOL OSLibWinSetWindowULong(HWND hwnd, ULONG offset, ULONG value)
237{
238 if(offset == OSLIB_QWL_USER)
239 offset = QWL_USER;
240
241 return WinSetWindowULong(hwnd, offset, value);
242}
243//******************************************************************************
244//******************************************************************************
245ULONG OSLibWinGetWindowULong(HWND hwnd, ULONG offset)
246{
247 if(offset == OSLIB_QWL_USER)
248 offset = QWL_USER;
249
250 return WinQueryWindowULong(hwnd, offset);
251}
252//******************************************************************************
253//******************************************************************************
254BOOL OSLibWinAlarm(HWND hwndDeskTop,ULONG flStyle)
255{
256 return WinAlarm(hwndDeskTop,flStyle);
257}
258//******************************************************************************
259//******************************************************************************
260APIRET OSLibDosBeep(ULONG freg,ULONG dur)
261{
262 return DosBeep(freg,dur);
263}
264//******************************************************************************
265//******************************************************************************
266HWND OSLibWinQueryFocus(HWND hwndDeskTop)
267{
268 return WinQueryFocus(hwndDeskTop);
269}
270//******************************************************************************
271//******************************************************************************
272HWND OSLibWinWindowFromID(HWND hwndParent,ULONG id)
273{
274 return WinWindowFromID(hwndParent,id);
275}
276//******************************************************************************
277//******************************************************************************
278BOOL OSLibWinSetFocus(HWND hwndDeskTop,HWND hwndNewFocus, BOOL activate)
279{
280 return WinFocusChange (hwndDeskTop, hwndNewFocus, activate ? 0 : FC_NOSETACTIVE);
281}
282//******************************************************************************
283//******************************************************************************
284BOOL OSLibWinIsChild (HWND hwnd, HWND hwndOf)
285{
286 return WinIsChild (hwnd, hwndOf);
287}
288//******************************************************************************
289//******************************************************************************
290ULONG OSLibGetWindowHeight(HWND hwnd)
291{
292 RECTL rect;
293
294 return (WinQueryWindowRect(hwnd,&rect)) ? rect.yTop-rect.yBottom:0;
295}
296//******************************************************************************
297//******************************************************************************
298LONG OSLibWinQuerySysValue(LONG iSysValue)
299{
300 return WinQuerySysValue(HWND_DESKTOP,iSysValue);
301}
302//******************************************************************************
303//******************************************************************************
304BOOL OSLibWinSetSysValue(LONG iSysValue, ULONG val)
305{
306 return WinQuerySysValue(iSysValue, val);
307}
308//******************************************************************************
309//******************************************************************************
310ULONG OSLibWinQueryDlgItemText(HWND hwndDlg,ULONG idItem,LONG cchBufferMax,char* pchBuffer)
311{
312 return WinQueryDlgItemText(hwndDlg,idItem,cchBufferMax,pchBuffer);
313}
314//******************************************************************************
315//******************************************************************************
316BOOL OSLibWinSetDlgItemText(HWND hwndDlg,ULONG idItem,char* pszText)
317{
318 return WinSetDlgItemText(hwndDlg,idItem,pszText);
319}
320//******************************************************************************
321//******************************************************************************
322BOOL OSLibWinQueryPointerPos(PPOINT pptlPoint)
323{
324 return WinQueryPointerPos(HWND_DESKTOP,(PPOINTL)pptlPoint);
325}
326//******************************************************************************
327//******************************************************************************
328BOOL OSLibWinSetPointerPos(int x, int y)
329{
330 return WinSetPointerPos(HWND_DESKTOP, x, y);
331}
332//******************************************************************************
333//******************************************************************************
334HWND OSLibWinQueryWindow(HWND hwnd, ULONG lCode)
335{
336 return WinQueryWindow(hwnd, lCode);
337}
338//******************************************************************************
339//******************************************************************************
340BOOL OSLibWinSetMultWindowPos(PSWP pswp, ULONG num)
341{
342 return WinSetMultWindowPos(GetThreadHAB(), pswp, num);
343}
344//******************************************************************************
345//******************************************************************************
346BOOL OSLibWinShowWindow(HWND hwnd, ULONG fl)
347{
348 BOOL rc = 1;
349
350 if(fl & SWP_SHOW) {
351 rc = WinShowWindow(hwnd, TRUE);
352 }
353 if(rc == 0)
354 dprintf(("WinShowWindow %x failed %x", hwnd, WinGetLastError(GetThreadHAB())));
355 rc = WinSetWindowPos(hwnd, 0, 0, 0, 0, 0, fl);
356 if(rc == 0)
357 dprintf(("WinShowWindow %x failed %x", hwnd, WinGetLastError(GetThreadHAB())));
358 return rc;
359}
360//******************************************************************************
361//******************************************************************************
362BOOL OSLibWinDestroyWindow(HWND hwnd)
363{
364 return WinDestroyWindow(hwnd);
365}
366//******************************************************************************
367//******************************************************************************
368#if 0
369BOOL OSLibWinQueryWindowRect(Win32BaseWindow *window, PRECT pRect, int RelativeTo)
370{
371 BOOL rc;
372 RECTLOS2 rectl;
373
374 rc = WinQueryWindowRect(window->getOS2WindowHandle(), (PRECTL)&rectl);
375 if(rc) {
376 if(RelativeTo == RELATIVE_TO_SCREEN) {
377 mapOS2ToWin32RectFrame(window,windowDesktop,&rectl,pRect);
378 }
379 else mapOS2ToWin32RectFrame(window,&rectl,pRect);
380 }
381 else memset(pRect, 0, sizeof(RECT));
382 return rc;
383}
384#endif
385//******************************************************************************
386//******************************************************************************
387BOOL OSLibWinIsIconic(HWND hwnd)
388{
389 SWP swp;
390 BOOL rc;
391
392 rc = WinQueryWindowPos(hwnd, &swp);
393 if(rc == FALSE) {
394 dprintf(("OSLibWinIsIconic: WinQueryWindowPos %x failed", hwnd));
395 return FALSE;
396 }
397
398 if(swp.fl & SWP_MINIMIZE)
399 return TRUE;
400 else return FALSE;
401}
402//******************************************************************************
403//******************************************************************************
404BOOL OSLibWinSetActiveWindow(HWND hwnd)
405{
406 BOOL rc;
407
408 rc = WinSetActiveWindow(HWND_DESKTOP, hwnd);
409 if(rc == FALSE) {
410 dprintf(("WinSetActiveWindow %x failure: %x", hwnd, OSLibWinGetLastError()));
411 }
412 return rc;
413}
414//******************************************************************************
415//******************************************************************************
416BOOL OSLibWinSetFocus(HWND hwnd)
417{
418 return WinSetFocus(HWND_DESKTOP, hwnd);
419}
420//******************************************************************************
421//******************************************************************************
422BOOL OSLibWinEnableWindow(HWND hwnd, BOOL fEnable)
423{
424 BOOL rc;
425 HWND hwndClient;
426
427 rc = WinEnableWindow(hwnd, fEnable);
428 hwndClient = WinWindowFromID(hwnd, FID_CLIENT);
429 if(hwndClient) {
430 WinEnableWindow(hwndClient, fEnable);
431 }
432 return rc;
433}
434//******************************************************************************
435//******************************************************************************
436BOOL OSLibWinIsWindowEnabled(HWND hwnd)
437{
438 return WinIsWindowEnabled(hwnd);
439}
440//******************************************************************************
441//******************************************************************************
442BOOL OSLibWinIsWindowVisible(HWND hwnd)
443{
444 return WinIsWindowVisible(hwnd);
445}
446//******************************************************************************
447//******************************************************************************
448HWND OSLibWinQueryActiveWindow()
449{
450 return WinQueryActiveWindow(HWND_DESKTOP);
451}
452//******************************************************************************
453//******************************************************************************
454LONG OSLibWinQueryWindowTextLength(HWND hwnd)
455{
456 return WinQueryWindowTextLength(hwnd);
457}
458//******************************************************************************
459//******************************************************************************
460LONG OSLibWinQueryWindowText(HWND hwnd, LONG length, LPSTR lpsz)
461{
462 return WinQueryWindowText(hwnd, length, lpsz);
463}
464//******************************************************************************
465//******************************************************************************
466BOOL OSLibWinSetWindowText(HWND hwnd, LPSTR lpsz)
467{
468 return WinSetWindowText(hwnd, lpsz);
469}
470//******************************************************************************
471//******************************************************************************
472BOOL OSLibWinSetTitleBarText(HWND hwnd, LPSTR lpsz)
473{
474 return WinSetWindowText(WinWindowFromID(hwnd, FID_TITLEBAR), lpsz);
475}
476//******************************************************************************
477//******************************************************************************
478BOOL OSLibWinFlashWindow(HWND hwnd, BOOL fFlash)
479{
480 return WinFlashWindow(hwnd, fFlash);
481}
482//******************************************************************************
483//******************************************************************************
484HWND OSLibWinWindowFromPoint(HWND hwnd, PVOID ppoint)
485{
486 return WinWindowFromPoint((hwnd == OSLIB_HWND_DESKTOP) ? HWND_DESKTOP : hwnd, (PPOINTL)ppoint, TRUE);
487}
488//******************************************************************************
489//******************************************************************************
490BOOL OSLibWinMinimizeWindow(HWND hwnd)
491{
492 return WinSetWindowPos(hwnd, 0, 0, 0, 0, 0, SWP_MINIMIZE);
493}
494//******************************************************************************
495//******************************************************************************
496BOOL OSLibWinGetBorderSize(HWND hwnd, OSLIBPOINT *pointl)
497{
498 pointl->x = 0;
499 pointl->y = 0;
500 return (BOOL) WinSendMsg(hwnd, WM_QUERYBORDERSIZE, MPFROMP( &pointl), 0);
501}
502//******************************************************************************
503//******************************************************************************
504BOOL OSLibWinSetIcon(HWND hwnd, HANDLE hIcon)
505{
506 ULONG hIconOS2 = GetOS2Icon(hIcon);
507 if(hIconOS2)
508 return (BOOL) WinSendMsg(hwnd, WM_SETICON, (MPARAM)hIconOS2, 0);
509 return FALSE;
510}
511//******************************************************************************
512//******************************************************************************
513BOOL OSLibWinQueryWindowPos (HWND hwnd, PSWP pswp)
514{
515 return WinQueryWindowPos(hwnd, pswp);
516}
517//******************************************************************************
518//******************************************************************************
519void OSLibMapSWPtoWINDOWPOS(PSWP pswp, PWINDOWPOS pwpos, PSWP pswpOld,
520 int parentHeight, HWND hwnd)
521{
522 HWND hWindow = pswp->hwnd;
523 HWND hWndInsertAfter = pswp->hwndInsertBehind;
524 long x = pswp->x;
525 long y = pswp->y;
526 long cx = pswp->cx;
527 long cy = pswp->cy;
528 UINT fuFlags = (UINT)pswp->fl;
529
530 HWND hWinAfter;
531 ULONG flags = 0;
532
533 HWND hWnd = (hWindow == HWND_DESKTOP) ? HWND_DESKTOP_W: hWindow;
534
535 if (hWndInsertAfter == HWND_TOP)
536 hWinAfter = HWND_TOP_W;
537 else if (hWndInsertAfter == HWND_BOTTOM)
538 hWinAfter = HWND_BOTTOM_W;
539 else
540 hWinAfter = (HWND) hWndInsertAfter;
541
542 //***********************************
543 // convert PM flags to Windows flags
544 //***********************************
545 if (!(fuFlags & SWP_SIZE)) flags |= SWP_NOSIZE_W;
546 if (!(fuFlags & SWP_MOVE)) flags |= SWP_NOMOVE_W;
547 if (!(fuFlags & SWP_ZORDER)) flags |= SWP_NOZORDER_W;
548 if ( fuFlags & SWP_NOREDRAW) flags |= SWP_NOREDRAW_W;
549 if (!(fuFlags & SWP_ACTIVATE)) flags |= SWP_NOACTIVATE_W;
550 if ( fuFlags & SWP_SHOW) flags |= SWP_SHOWWINDOW_W;
551 if ( fuFlags & SWP_HIDE) flags |= SWP_HIDEWINDOW_W;
552 if ( fuFlags & SWP_NOADJUST) flags |= SWP_NOSENDCHANGING_W;
553
554 if(fuFlags & (SWP_MOVE | SWP_SIZE))
555 {
556 y = parentHeight - y - pswp->cy;
557
558 if ((pswp->x == pswpOld->x) && (pswp->y == pswpOld->y))
559 flags |= SWP_NOMOVE_W;
560
561 if ((pswp->cx == pswpOld->cx) && (pswp->cy == pswpOld->cy))
562 flags |= SWP_NOSIZE_W;
563
564 if (fuFlags & SWP_SIZE)
565 {
566 if (pswp->cy != pswpOld->cy)
567 {
568 flags &= ~SWP_NOMOVE_W;
569 }
570 }
571 }
572
573 pswpOld->x = pswp->x;
574 pswpOld->y = parentHeight-pswp->y-pswp->cy;
575 pswpOld->cx = pswp->cx;
576 pswpOld->cy = pswp->cy;
577
578 dprintf(("window (%d,%d)(%d,%d) client (%d,%d)(%d,%d)",
579 x,y,cx,cy, pswpOld->x,pswpOld->y,pswpOld->cx,pswpOld->cy));
580
581 pwpos->flags = (UINT)flags;
582 pwpos->cy = cy;
583 pwpos->cx = cx;
584 pwpos->x = x;
585 pwpos->y = y;
586 pwpos->hwndInsertAfter = hWinAfter;
587 pwpos->hwnd = hWindow;
588}
589//******************************************************************************
590//******************************************************************************
591void OSLibMapWINDOWPOStoSWP(struct tagWINDOWPOS *pwpos, PSWP pswp, PSWP pswpOld,
592 int parentHeight, HWND hFrame)
593{
594 BOOL fCvt = FALSE;
595
596 HWND hWnd = pwpos->hwnd;
597 HWND hWndInsertAfter = pwpos->hwndInsertAfter;
598 long x = pwpos->x;
599 long y = pwpos->y;
600 long cx = pwpos->cx;
601 long cy = pwpos->cy;
602 UINT fuFlags = pwpos->flags;
603
604 HWND hWinAfter;
605 ULONG flags = 0;
606 HWND hWindow = hWnd ? (HWND)hWnd : HWND_DESKTOP;
607
608 if (hWndInsertAfter == HWND_TOPMOST_W)
609// hWinAfter = HWND_TOPMOST;
610 hWinAfter = HWND_TOP;
611 else if (hWndInsertAfter == HWND_NOTOPMOST_W)
612// hWinAfter = HWND_NOTOPMOST;
613 hWinAfter = HWND_TOP;
614 else if (hWndInsertAfter == HWND_TOP_W)
615 hWinAfter = HWND_TOP;
616 else if (hWndInsertAfter == HWND_BOTTOM_W)
617 hWinAfter = HWND_BOTTOM;
618 else
619 hWinAfter = (HWND) hWndInsertAfter;
620
621 if (!(fuFlags & SWP_NOSIZE_W )) flags |= SWP_SIZE;
622 if (!(fuFlags & SWP_NOMOVE_W )) flags |= SWP_MOVE;
623 if (!(fuFlags & SWP_NOZORDER_W )) flags |= SWP_ZORDER;
624 if ( fuFlags & SWP_NOREDRAW_W ) flags |= SWP_NOREDRAW;
625 if (!(fuFlags & SWP_NOACTIVATE_W)) flags |= SWP_ACTIVATE;
626 if ( fuFlags & SWP_SHOWWINDOW_W) flags |= SWP_SHOW;
627 if ( fuFlags & SWP_HIDEWINDOW_W) flags |= SWP_HIDE;
628 if ( fuFlags & SWP_NOSENDCHANGING_W) flags |= SWP_NOADJUST;
629
630 if(flags & (SWP_MOVE | SWP_SIZE))
631 {
632 if((flags & SWP_MOVE) == 0)
633 {
634 x = pswpOld->x;
635 y = pswpOld->y;
636
637 y = parentHeight - y - pswpOld->cy;
638 }
639
640 if(flags & SWP_SIZE)
641 {
642 if (cy != pswpOld->cy)
643 flags |= SWP_MOVE;
644 }
645 else
646 {
647 cx = pswpOld->cx;
648 cy = pswpOld->cy;
649 }
650 y = parentHeight - y - cy;
651
652 if ((pswpOld->x == x) && (pswpOld->y == y))
653 flags &= ~SWP_MOVE;
654
655 if ((pswpOld->cx == cx) && (pswpOld->cy == cy))
656 flags &= ~SWP_SIZE;
657 }
658
659 pswp->fl = flags;
660 pswp->cy = cy;
661 pswp->cx = cx;
662 pswp->x = x;
663 pswp->y = y;
664 pswp->hwndInsertBehind = hWinAfter;
665 pswp->hwnd = hWindow;
666 pswp->ulReserved1 = 0;
667 pswp->ulReserved2 = 0;
668}
669//******************************************************************************
670//******************************************************************************
671void OSLibWinSetClientPos(HWND hwnd, int x, int y, int cx, int cy, int parentHeight)
672{
673 SWP swp;
674 BOOL rc;
675
676 swp.hwnd = hwnd;
677 swp.hwndInsertBehind = 0;
678 swp.x = x;
679 swp.y = parentHeight - y - cy;
680 swp.cx = cx;
681 swp.cy = cy;
682 swp.fl = SWP_MOVE | SWP_SIZE;
683
684 dprintf(("OSLibWinSetClientPos (%d,%d) (%d,%d) -> (%d,%d) (%d,%d)", x, y, x+cx, y+cy, swp.x, swp.y, swp.x+swp.cx, swp.y+swp.cy));
685
686 rc = WinSetMultWindowPos(GetThreadHAB(), &swp, 1);
687 if(rc == FALSE) {
688 dprintf(("OSLibWinSetClientPos: WinSetMultWindowPos %x failed %x", hwnd, WinGetLastError(GetThreadHAB())));
689 }
690}
691//******************************************************************************
692//******************************************************************************
693BOOL OSLibWinCalcFrameRect(HWND hwndFrame, RECT *pRect, BOOL fClient)
694{
695 BOOL rc;
696
697 WinMapWindowPoints(hwndFrame, HWND_DESKTOP, (PPOINTL)pRect, 2);
698
699 rc = WinCalcFrameRect(hwndFrame, (PRECTL)pRect, fClient);
700 WinMapWindowPoints(HWND_DESKTOP, hwndFrame, (PPOINTL)pRect, 2);
701
702 return rc;
703}
704//******************************************************************************
705//******************************************************************************
706BOOL OSLibGetMinMaxInfo(HWND hwndFrame, MINMAXINFO *pMinMax)
707{
708 TRACKINFO tinfo;
709
710 memset(&tinfo, 0, sizeof(TRACKINFO));
711 WinSendMsg(hwndFrame, WM_QUERYTRACKINFO, (MPARAM)0,(MPARAM)&tinfo);
712
713 pMinMax->ptMinTrackSize.x = tinfo.ptlMinTrackSize.x;
714 pMinMax->ptMinTrackSize.y = tinfo.ptlMinTrackSize.y;
715 pMinMax->ptMaxTrackSize.x = tinfo.ptlMaxTrackSize.x;
716 pMinMax->ptMaxTrackSize.y = tinfo.ptlMaxTrackSize.y;
717 return TRUE;
718}
719//******************************************************************************
720//******************************************************************************
721HWND OSLibWinBeginEnumWindows(HWND hwnd)
722{
723 if(hwnd == OSLIB_HWND_DESKTOP) hwnd = HWND_DESKTOP;
724 else
725 if(hwnd == OSLIB_HWND_OBJECT) hwnd = HWND_OBJECT;
726
727 return WinBeginEnumWindows(hwnd);
728}
729//******************************************************************************
730//******************************************************************************
731HWND OSLibWinGetNextWindow(HWND hwndEnum)
732{
733 return WinGetNextWindow(hwndEnum);
734}
735//******************************************************************************
736//******************************************************************************
737HWND OSLibWinQueryClientWindow(HWND hwndFrame)
738{
739 HWND hwndClient = 0;
740
741 if(((ULONG)WinSendMsg(hwndFrame, WM_QUERYFRAMEINFO, NULL, NULL)) & FI_FRAME)
742 hwndClient = WinWindowFromID(hwndFrame, FID_CLIENT);
743
744 return hwndClient;
745}
746//******************************************************************************
747//******************************************************************************
748BOOL OSLibWinEndEnumWindows(HWND hwndEnum)
749{
750 return WinEndEnumWindows(hwndEnum);
751}
752//******************************************************************************
753//******************************************************************************
754BOOL OSLibWinQueryWindowProcess(HWND hwnd, ULONG *pid, ULONG *tid)
755{
756 return WinQueryWindowProcess(hwnd, pid, tid);
757}
758//******************************************************************************
759//******************************************************************************
760BOOL OSLibWinMapWindowPoints (HWND hwndFrom, HWND hwndTo, OSLIBPOINT *pptl, ULONG num)
761{
762 return WinMapWindowPoints (hwndFrom, hwndTo, (PPOINTL)pptl, num);
763}
764//******************************************************************************
765//******************************************************************************
766HWND OSLibWinQueryObjectWindow(VOID)
767{
768 return WinQueryObjectWindow(HWND_DESKTOP);
769}
770//******************************************************************************
771//******************************************************************************
772HWND OSLibWinObjectWindowFromID(HWND hwndOwner, ULONG ID)
773{
774 HWND hwndNext, hwndFound=0;
775 HENUM henum;
776
777 henum = WinBeginEnumWindows(HWND_OBJECT);
778 while ((hwndNext = WinGetNextWindow(henum)) != 0)
779 {
780 if(WinQueryWindow(hwndNext, QW_OWNER) == hwndOwner &&
781 WinQueryWindowUShort(hwndNext, QWS_ID) == ID)
782 {
783 hwndFound = hwndNext;
784 break;
785 }
786 }
787 WinEndEnumWindows(henum);
788 return hwndFound;
789}
790//******************************************************************************
791//******************************************************************************
792BOOL OSLibSetWindowID(HWND hwnd, ULONG value)
793{
794 dprintf(("OSLibSetWindowID hwnd:%x ID:%x", hwnd, value));
795 return WinSetWindowULong(hwnd, QWS_ID, value);
796}
797//******************************************************************************
798//******************************************************************************
799PVOID OSLibWinSubclassWindow(HWND hwnd,PVOID newWndProc)
800{
801 return WinSubclassWindow(hwnd,(PFNWP)newWndProc);
802}
803//******************************************************************************
804//******************************************************************************
805BOOL OSLibSetWindowRestoreRect(HWND hwnd, PRECT pRect)
806{
807 ULONG yHeight = OSLibGetWindowHeight(WinQueryWindow(hwnd, QW_PARENT));
808
809 WinSetWindowUShort(hwnd, QWS_XRESTORE, (USHORT)pRect->left );
810 WinSetWindowUShort(hwnd, QWS_YRESTORE, (USHORT)(yHeight - pRect->top -
811 (pRect->bottom - pRect->top)));
812 WinSetWindowUShort(hwnd, QWS_CXRESTORE, (USHORT)(pRect->right - pRect->left));
813 WinSetWindowUShort(hwnd, QWS_CYRESTORE, (USHORT)(pRect->bottom - pRect->top));
814 return TRUE;
815}
816//******************************************************************************
817//******************************************************************************
818BOOL OSLibSetWindowMinPos(HWND hwnd, ULONG x, ULONG y)
819{
820 ULONG yHeight = OSLibGetWindowHeight(WinQueryWindow(hwnd, QW_PARENT));
821
822 WinSetWindowUShort(hwnd, QWS_XMINIMIZE, (USHORT)x );
823 WinSetWindowUShort(hwnd, QWS_YMINIMIZE, (USHORT)(yHeight - y -
824 ( 2 * WinQuerySysValue( HWND_DESKTOP, SV_CYSIZEBORDER)) -
825 WinQuerySysValue( HWND_DESKTOP, SV_CYICON)));
826 return TRUE;
827}
828//******************************************************************************
829//******************************************************************************
830BOOL OSLibWinGetKeyboardStateTable(unsigned char *PMKeyState)
831{
832 return WinSetKeyboardStateTable(HWND_DESKTOP, (PBYTE)PMKeyState, FALSE );
833}
834//******************************************************************************
835//******************************************************************************
836BOOL OSLibWinSetKeyboardStateTable(unsigned char *PMKeyState)
837{
838 return WinSetKeyboardStateTable(HWND_DESKTOP, (PBYTE)PMKeyState, TRUE );
839}
840//******************************************************************************
841//******************************************************************************
842USHORT APIENTRY WinTranslateChar2( USHORT /* Codepage (currently ignored) */
843 , PUSHORT /* Ptr to char to translate */
844 , PULONG /* Ptr to deadkey save info */
845 , USHORT /* Translation option (TC_xxx) */
846 , PUSHORT /* Ptr to shift state (TCF_xxx) */
847 );
848//******************************************************************************
849//******************************************************************************
850USHORT OSLibWinTranslateChar(USHORT usScanCode, ULONG type, USHORT shiftstate)
851{
852 WinTranslateChar2(0, &usScanCode, NULL, type, &shiftstate);
853 return usScanCode;
854}
855//******************************************************************************
856//******************************************************************************
857BOOL OSLibWinEnableWindowUpdate(HWND hwndFrame, HWND hwndClient ,BOOL fEnable)
858{
859 WinEnableWindowUpdate(hwndFrame, fEnable);
860 return WinEnableWindowUpdate(hwndClient, fEnable);
861}
862//******************************************************************************
863//******************************************************************************
864ULONG OSLibWinGetLastError()
865{
866 return WinGetLastError(GetThreadHAB()) & 0xFFFF;
867}
868//******************************************************************************
869//******************************************************************************
870void OSLibWinShowTaskList(HWND hwndFrame)
871{
872 //CB: don't know if this works on all machines
873 WinSetActiveWindow(HWND_DESKTOP,0x8000000E);
874}
875//******************************************************************************
876//******************************************************************************
877void OSLibSetWindowStyle(HWND hwndFrame, HWND hwndClient, ULONG dwStyle, ULONG dwExStyle)
878{
879 ULONG dwWinStyle;
880 ULONG dwOldWinStyle;
881
882 //client window:
883 dwWinStyle = WinQueryWindowULong(hwndClient, QWL_STYLE);
884 dwOldWinStyle = dwWinStyle;
885
886 if(dwStyle & WS_CLIPCHILDREN_W) {
887 dwWinStyle |= WS_CLIPCHILDREN;
888 }
889 else dwWinStyle &= ~WS_CLIPCHILDREN;
890
891 if(dwWinStyle != dwOldWinStyle) {
892 WinSetWindowULong(hwndClient, QWL_STYLE, dwWinStyle);
893 }
894
895 //Frame window
896 dwWinStyle = WinQueryWindowULong(hwndFrame, QWL_STYLE);
897 dwOldWinStyle = dwWinStyle;
898 if(dwStyle & WS_DISABLED_W) {
899 dwWinStyle |= WS_DISABLED;
900 }
901 else dwWinStyle &= ~WS_DISABLED;
902
903 if(dwStyle & WS_CLIPSIBLINGS_W) {
904 dwWinStyle |= WS_CLIPSIBLINGS;
905 }
906 else dwWinStyle &= ~WS_CLIPSIBLINGS;
907
908 if(dwStyle & WS_MINIMIZE_W) {
909 dwWinStyle |= WS_MINIMIZED;
910 }
911 else dwWinStyle &= ~WS_MINIMIZED;
912
913 if(dwStyle & WS_MAXIMIZE_W) {
914 dwWinStyle |= WS_MAXIMIZED;
915 }
916 else dwWinStyle &= ~WS_MAXIMIZED;
917
918 if(dwWinStyle != dwOldWinStyle) {
919 WinSetWindowULong(hwndFrame, QWL_STYLE, dwWinStyle);
920 }
921 if(fOS2Look) {
922 ULONG OSFrameStyle = 0;
923 if((dwStyle & WS_CAPTION_W) == WS_CAPTION_W) {
924 if(WinWindowFromID(hwndFrame, FID_TITLEBAR) == 0) {
925 OSFrameStyle = FCF_TITLEBAR;
926 }
927 if((dwStyle & WS_SYSMENU_W) && !(dwExStyle & WS_EX_TOOLWINDOW_W))
928 {
929 if(WinWindowFromID(hwndFrame, FID_SYSMENU) == 0) {
930 OSFrameStyle |= FCF_SYSMENU;
931 }
932 }
933 if((dwStyle & WS_MINIMIZEBOX_W) || (dwStyle & WS_MAXIMIZEBOX_W)) {
934 if(WinWindowFromID(hwndFrame, FID_MINMAX) == 0) {
935 OSFrameStyle |= FCF_MINMAX;
936 }
937 }
938 else
939 if(dwStyle & WS_SYSMENU_W) {
940 if(WinWindowFromID(hwndFrame, FID_MINMAX) == 0) {
941 OSFrameStyle |= FCF_CLOSEBUTTON;
942 }
943 }
944 }
945 if(OSFrameStyle) {
946 FRAMECDATA FCData = {sizeof (FRAMECDATA), 0, 0, 0};
947
948 FCData.flCreateFlags = OSFrameStyle;
949 WinCreateFrameControls(hwndFrame, &FCData, NULL);
950 }
951 }
952}
953//******************************************************************************
954//******************************************************************************
955DWORD OSLibQueryWindowStyle(HWND hwnd)
956{
957 return WinQueryWindowULong(hwnd, QWL_STYLE);
958}
959//******************************************************************************
960//******************************************************************************
961void OSLibWinSetVisibleRegionNotify(HWND hwnd, BOOL fNotify)
962{
963 WinSetVisibleRegionNotify(hwnd, fNotify);
964}
965//******************************************************************************
966//******************************************************************************
967HWND OSLibWinQueryCapture()
968{
969 return WinQueryCapture(HWND_DESKTOP);
970}
971//******************************************************************************
972//******************************************************************************
973BOOL OSLibWinSetCapture(HWND hwnd)
974{
975 return WinSetCapture(HWND_DESKTOP, hwnd);
976}
977//******************************************************************************
978//******************************************************************************
979BOOL OSLibWinRemoveFromTasklist(HANDLE hTaskList)
980{
981 return (WinRemoveSwitchEntry(hTaskList)) ? FALSE : TRUE;
982}
983//******************************************************************************
984//******************************************************************************
985HANDLE OSLibWinAddToTaskList(HWND hwndFrame, char *title, BOOL fVisible)
986{
987 SWCNTRL swctrl;
988 ULONG tid;
989
990 swctrl.hwnd = hwndFrame;
991 swctrl.hwndIcon = 0;
992 swctrl.hprog = 0;
993 WinQueryWindowProcess(hwndFrame, (PPID)&swctrl.idProcess, (PTID)&tid);
994 swctrl.idSession = 0;
995 swctrl.uchVisibility = (fVisible) ? SWL_VISIBLE : SWL_INVISIBLE;
996 swctrl.fbJump = SWL_JUMPABLE;
997 swctrl.bProgType = PROG_PM;
998 if(title) {
999 strncpy(swctrl.szSwtitle, title, MAXNAMEL+4);
1000 swctrl.szSwtitle[MAXNAMEL+4-1] = 0;
1001 }
1002 else {
1003 swctrl.szSwtitle[0] = 0;
1004 swctrl.uchVisibility = SWL_INVISIBLE;
1005 }
1006 return WinAddSwitchEntry(&swctrl);
1007}
1008//******************************************************************************
1009//******************************************************************************
1010BOOL OSLibWinChangeTaskList(HANDLE hTaskList, HWND hwndFrame, char *title, BOOL fVisible)
1011{
1012 SWCNTRL swctrl;
1013 ULONG tid;
1014
1015 swctrl.hwnd = hwndFrame;
1016 swctrl.hwndIcon = 0;
1017 swctrl.hprog = 0;
1018 WinQueryWindowProcess(hwndFrame, (PPID)&swctrl.idProcess, (PTID)&tid);
1019 swctrl.idSession = 0;
1020 swctrl.uchVisibility = (fVisible) ? SWL_VISIBLE : SWL_INVISIBLE;
1021 swctrl.fbJump = SWL_JUMPABLE;
1022 swctrl.bProgType = PROG_PM;
1023 if(title) {
1024 strncpy(swctrl.szSwtitle, title, MAXNAMEL+4);
1025 swctrl.szSwtitle[MAXNAMEL+4-1] = 0;
1026 }
1027 else {
1028 swctrl.szSwtitle[0] = 0;
1029 swctrl.uchVisibility = SWL_INVISIBLE;
1030 }
1031 return (WinChangeSwitchEntry(hTaskList, &swctrl)) ? FALSE : TRUE;
1032}
1033//******************************************************************************
1034//******************************************************************************
1035BOOL OSLibWinLockWindowUpdate(HWND hwnd)
1036{
1037 return WinLockWindowUpdate(HWND_DESKTOP, (HWND)hwnd);
1038}
1039//******************************************************************************
1040//******************************************************************************
1041ULONG OSLibGetScreenHeight()
1042{
1043 return ScreenHeight;
1044}
1045//******************************************************************************
1046//******************************************************************************
1047ULONG OSLibGetScreenWidth()
1048{
1049 return ScreenWidth;
1050}
1051//******************************************************************************
1052//Returns the maximum position for a window
1053//Should only be used from toplevel windows
1054//******************************************************************************
1055BOOL OSLibWinGetMaxPosition(HWND hwndOS2, RECT *rect)
1056{
1057 SWP swp;
1058
1059 if(!WinGetMaxPosition(hwndOS2, &swp)) {
1060 dprintf(("WARNING: WinGetMaxPosition %x returned FALSE", hwndOS2));
1061 return FALSE;
1062 }
1063 rect->left = swp.x;
1064 rect->right = swp.x + swp.cx;
1065 rect->top = ScreenHeight - (swp.y + swp.cy);
1066 rect->bottom = ScreenHeight - swp.y;
1067 return TRUE;
1068}
1069//******************************************************************************
1070//******************************************************************************
1071BOOL OSLibWinShowPointer(BOOL fShow)
1072{
1073 return WinShowPointer(HWND_DESKTOP, fShow);
1074}
1075//******************************************************************************
1076//******************************************************************************
Note: See TracBrowser for help on using the repository browser.