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

Last change on this file since 8097 was 8097, checked in by sandervl, 23 years ago

PF: fix for 24 bpp bitmaps

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