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

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

move process id setup to OSLibWinQueryWindowProcess

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