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

Last change on this file since 5215 was 5215, checked in by sandervl, 25 years ago

ScrollWindow, maximized window + system menu fixes

File size: 30.7 KB
Line 
1/* $Id: oslibwin.cpp,v 1.88 2001-02-20 15:40:22 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 "oslibwin.h"
24#include "oslibutil.h"
25#include "oslibmsg.h"
26#include "oslibgdi.h"
27#include "pmwindow.h"
28
29#define DBG_LOCALLOG DBG_oslibwin
30#include "dbglocal.h"
31
32//******************************************************************************
33//******************************************************************************
34BOOL OSLibWinSetParent(HWND hwnd, HWND hwndParent, ULONG fRedraw)
35{
36 if(hwndParent == OSLIB_HWND_DESKTOP)
37 {
38 hwndParent = HWND_DESKTOP;
39 }
40 else
41 if(hwndParent == OSLIB_HWND_OBJECT) {
42 hwndParent = HWND_OBJECT;
43 }
44 return (WinSetParent(hwnd, hwndParent, fRedraw) == 0);
45}
46//******************************************************************************
47//******************************************************************************
48BOOL OSLibWinSetOwner(HWND hwnd, HWND hwndOwner)
49{
50 return WinSetOwner(hwnd, hwndOwner);
51}
52//******************************************************************************
53//******************************************************************************
54HWND OSLibWinCreateWindow(HWND hwndParent,ULONG dwWinStyle,
55 char *pszName, HWND Owner, ULONG fHWND_BOTTOM,
56 ULONG id, BOOL fTaskList,BOOL fShellPosition,
57 int classStyle)
58{
59 HWND hwndClient;
60 ULONG dwFrameStyle = 0;
61
62 if(pszName && *pszName == 0) {
63 pszName = NULL;
64 }
65 if(hwndParent == OSLIB_HWND_DESKTOP) {
66 hwndParent = HWND_DESKTOP;
67 }
68 if(Owner == OSLIB_HWND_DESKTOP) {
69 Owner = HWND_DESKTOP;
70 }
71
72 if(classStyle & CS_SAVEBITS_W) dwWinStyle |= WS_SAVEBITS;
73 if(classStyle & CS_PARENTDC_W) dwWinStyle |= WS_PARENTCLIP;
74
75 dwWinStyle = dwWinStyle & ~(WS_TABSTOP | WS_GROUP);
76
77 if(fTaskList)
78 {
79 dwFrameStyle |= FCF_NOMOVEWITHOWNER;
80 }
81 if (fShellPosition) dwFrameStyle |= FCF_SHELLPOSITION;
82
83 FRAMECDATA FCData = {sizeof (FRAMECDATA), 0, 0, 0};
84 FCData.flCreateFlags = dwFrameStyle;
85
86 dprintf(("WinCreateWindow %x %s %x task %d shell %d classstyle %x winstyle %x bottom %d", hwndParent, pszName, id, fTaskList, fShellPosition, classStyle, dwWinStyle, fHWND_BOTTOM));
87
88 return WinCreateWindow (hwndParent,
89 (hwndParent == HWND_DESKTOP) ? WIN32_STDFRAMECLASS : WIN32_STDCLASS,
90 pszName, dwWinStyle, 0, 0, 0, 0,
91 Owner, (fHWND_BOTTOM) ? HWND_BOTTOM : HWND_TOP,
92 id, NULL, NULL);
93}
94//******************************************************************************
95//******************************************************************************
96BOOL OSLibWinConvertStyle(ULONG dwStyle, ULONG dwExStyle, ULONG *OSWinStyle)
97{
98 *OSWinStyle = 0;
99
100 /* Window styles */
101 if(dwStyle & WS_MINIMIZE_W)
102 *OSWinStyle |= WS_MINIMIZED;
103//Done explicitely in CreateWindowExA
104#if 0
105 if(dwStyle & WS_VISIBLE_W)
106 *OSWinStyle |= WS_VISIBLE;
107#endif
108 if(dwStyle & WS_DISABLED_W)
109 *OSWinStyle |= WS_DISABLED;
110 if(dwStyle & WS_CLIPSIBLINGS_W)
111 *OSWinStyle |= WS_CLIPSIBLINGS;
112 if(dwStyle & WS_CLIPCHILDREN_W)
113 *OSWinStyle |= WS_CLIPCHILDREN;
114 if(dwStyle & WS_MAXIMIZE_W)
115 *OSWinStyle |= WS_MAXIMIZED;
116 if(dwStyle & WS_GROUP_W)
117 *OSWinStyle |= WS_GROUP;
118 if(dwStyle & WS_TABSTOP_W)
119 *OSWinStyle |= WS_TABSTOP;
120
121 return TRUE;
122}
123//******************************************************************************
124//******************************************************************************
125BOOL OSLibWinSetWindowULong(HWND hwnd, ULONG offset, ULONG value)
126{
127 if(offset == OSLIB_QWL_USER)
128 offset = QWL_USER;
129
130 return WinSetWindowULong(hwnd, offset, value);
131}
132//******************************************************************************
133//******************************************************************************
134ULONG OSLibWinGetWindowULong(HWND hwnd, ULONG offset)
135{
136 if(offset == OSLIB_QWL_USER)
137 offset = QWL_USER;
138
139 return WinQueryWindowULong(hwnd, offset);
140}
141//******************************************************************************
142//******************************************************************************
143BOOL OSLibWinAlarm(HWND hwndDeskTop,ULONG flStyle)
144{
145 return WinAlarm(hwndDeskTop,flStyle);
146}
147//******************************************************************************
148//******************************************************************************
149APIRET OSLibDosBeep(ULONG freg,ULONG dur)
150{
151 return DosBeep(freg,dur);
152}
153//******************************************************************************
154//******************************************************************************
155HWND OSLibWinQueryFocus(HWND hwndDeskTop)
156{
157 return WinQueryFocus(hwndDeskTop);
158}
159//******************************************************************************
160//******************************************************************************
161HWND OSLibWinWindowFromID(HWND hwndParent,ULONG id)
162{
163 return WinWindowFromID(hwndParent,id);
164}
165//******************************************************************************
166//******************************************************************************
167BOOL OSLibWinSetFocus(HWND hwndDeskTop,HWND hwndNewFocus, BOOL activate)
168{
169 return WinFocusChange (hwndDeskTop, hwndNewFocus, activate ? FC_NOLOSEACTIVE : 0);
170}
171//******************************************************************************
172//******************************************************************************
173BOOL OSLibWinIsChild (HWND hwnd, HWND hwndOf)
174{
175 return WinIsChild (hwnd, hwndOf);
176}
177//******************************************************************************
178//******************************************************************************
179ULONG OSLibGetWindowHeight(HWND hwnd)
180{
181 RECTL rect;
182
183 return (WinQueryWindowRect(hwnd,&rect)) ? rect.yTop-rect.yBottom:0;
184}
185//******************************************************************************
186//******************************************************************************
187LONG OSLibWinQuerySysValue(LONG iSysValue)
188{
189 return WinQuerySysValue(HWND_DESKTOP,iSysValue);
190}
191//******************************************************************************
192//******************************************************************************
193ULONG OSLibWinQueryDlgItemText(HWND hwndDlg,ULONG idItem,LONG cchBufferMax,char* pchBuffer)
194{
195 return WinQueryDlgItemText(hwndDlg,idItem,cchBufferMax,pchBuffer);
196}
197//******************************************************************************
198//******************************************************************************
199BOOL OSLibWinSetDlgItemText(HWND hwndDlg,ULONG idItem,char* pszText)
200{
201 return WinSetDlgItemText(hwndDlg,idItem,pszText);
202}
203//******************************************************************************
204//******************************************************************************
205BOOL OSLibWinQueryPointerPos(PPOINT pptlPoint)
206{
207 return WinQueryPointerPos(HWND_DESKTOP,(PPOINTL)pptlPoint);
208}
209//******************************************************************************
210//******************************************************************************
211HWND OSLibWinQueryWindow(HWND hwnd, ULONG lCode)
212{
213 return WinQueryWindow(hwnd, lCode);
214}
215//******************************************************************************
216//******************************************************************************
217BOOL OSLibWinSetMultWindowPos(PSWP pswp, ULONG num)
218{
219 return WinSetMultWindowPos(GetThreadHAB(), pswp, num);
220}
221//******************************************************************************
222//******************************************************************************
223BOOL OSLibWinShowWindow(HWND hwnd, ULONG fl)
224{
225 BOOL rc = 1;
226
227 if(fl & SWP_SHOW) {
228 rc = WinShowWindow(hwnd, TRUE);
229 }
230 if(rc == 0)
231 dprintf(("WinShowWindow %x failed %x", hwnd, WinGetLastError(GetThreadHAB())));
232 rc = WinSetWindowPos(hwnd, 0, 0, 0, 0, 0, fl);
233 if(rc == 0)
234 dprintf(("WinShowWindow %x failed %x", hwnd, WinGetLastError(GetThreadHAB())));
235 return rc;
236}
237//******************************************************************************
238//******************************************************************************
239BOOL OSLibWinDestroyWindow(HWND hwnd)
240{
241 return WinDestroyWindow(hwnd);
242}
243//******************************************************************************
244//******************************************************************************
245#if 0
246BOOL OSLibWinQueryWindowRect(Win32BaseWindow *window, PRECT pRect, int RelativeTo)
247{
248 BOOL rc;
249 RECTLOS2 rectl;
250
251 rc = WinQueryWindowRect(window->getOS2WindowHandle(), (PRECTL)&rectl);
252 if(rc) {
253 if(RelativeTo == RELATIVE_TO_SCREEN) {
254 mapOS2ToWin32RectFrame(window,windowDesktop,&rectl,pRect);
255 }
256 else mapOS2ToWin32RectFrame(window,&rectl,pRect);
257 }
258 else memset(pRect, 0, sizeof(RECT));
259 return rc;
260}
261#endif
262//******************************************************************************
263//******************************************************************************
264BOOL OSLibWinIsIconic(HWND hwnd)
265{
266 SWP swp;
267 BOOL rc;
268
269 rc = WinQueryWindowPos(hwnd, &swp);
270 if(rc == FALSE) {
271 dprintf(("OSLibWinIsIconic: WinQueryWindowPos %x failed", hwnd));
272 return FALSE;
273 }
274
275 if(swp.fl & SWP_MINIMIZE)
276 return TRUE;
277 else return FALSE;
278}
279//******************************************************************************
280//******************************************************************************
281BOOL OSLibWinSetActiveWindow(HWND hwnd)
282{
283 BOOL rc;
284
285 rc = WinSetActiveWindow(HWND_DESKTOP, hwnd);
286 if(rc == FALSE) {
287 dprintf(("WinSetActiveWindow %x failure: %x", hwnd, OSLibWinGetLastError()));
288 }
289 return rc;
290}
291//******************************************************************************
292//******************************************************************************
293BOOL OSLibWinSetFocus(HWND hwnd)
294{
295 return WinSetFocus(HWND_DESKTOP, hwnd);
296}
297//******************************************************************************
298//******************************************************************************
299BOOL OSLibWinEnableWindow(HWND hwnd, BOOL fEnable)
300{
301 BOOL rc;
302 HWND hwndClient;
303
304 rc = WinEnableWindow(hwnd, fEnable);
305 hwndClient = WinWindowFromID(hwnd, FID_CLIENT);
306 if(hwndClient) {
307 WinEnableWindow(hwndClient, fEnable);
308 }
309 return rc;
310}
311//******************************************************************************
312//******************************************************************************
313BOOL OSLibWinIsWindowEnabled(HWND hwnd)
314{
315 return WinIsWindowEnabled(hwnd);
316}
317//******************************************************************************
318//******************************************************************************
319BOOL OSLibWinIsWindowVisible(HWND hwnd)
320{
321 return WinIsWindowVisible(hwnd);
322}
323//******************************************************************************
324//******************************************************************************
325HWND OSLibWinQueryActiveWindow()
326{
327 return WinQueryActiveWindow(HWND_DESKTOP);
328}
329//******************************************************************************
330//******************************************************************************
331LONG OSLibWinQueryWindowTextLength(HWND hwnd)
332{
333 return WinQueryWindowTextLength(hwnd);
334}
335//******************************************************************************
336//******************************************************************************
337LONG OSLibWinQueryWindowText(HWND hwnd, LONG length, LPSTR lpsz)
338{
339 return WinQueryWindowText(hwnd, length, lpsz);
340}
341//******************************************************************************
342//******************************************************************************
343BOOL OSLibWinSetWindowText(HWND hwnd, LPSTR lpsz)
344{
345 return WinSetWindowText(hwnd, lpsz);
346}
347//******************************************************************************
348//******************************************************************************
349BOOL OSLibWinFlashWindow(HWND hwnd, BOOL fFlash)
350{
351 return WinFlashWindow(hwnd, fFlash);
352}
353//******************************************************************************
354//******************************************************************************
355HWND OSLibWinWindowFromPoint(HWND hwnd, PVOID ppoint)
356{
357 return WinWindowFromPoint((hwnd == OSLIB_HWND_DESKTOP) ? HWND_DESKTOP : hwnd, (PPOINTL)ppoint, TRUE);
358}
359//******************************************************************************
360//******************************************************************************
361BOOL OSLibWinMinimizeWindow(HWND hwnd)
362{
363 return WinSetWindowPos(hwnd, 0, 0, 0, 0, 0, SWP_MINIMIZE);
364}
365//******************************************************************************
366//******************************************************************************
367BOOL OSLibWinGetBorderSize(HWND hwnd, OSLIBPOINT *pointl)
368{
369 pointl->x = 0;
370 pointl->y = 0;
371 return (BOOL) WinSendMsg(hwnd, WM_QUERYBORDERSIZE, MPFROMP( &pointl), 0);
372}
373//******************************************************************************
374//******************************************************************************
375BOOL OSLibWinSetIcon(HWND hwnd, HANDLE hIcon)
376{
377 return (BOOL) WinSendMsg(hwnd, WM_SETICON, (MPARAM)hIcon, 0);
378}
379//******************************************************************************
380//******************************************************************************
381BOOL OSLibWinQueryWindowPos (HWND hwnd, PSWP pswp)
382{
383 return WinQueryWindowPos(hwnd, pswp);
384}
385//******************************************************************************
386//******************************************************************************
387void OSLibMapSWPtoWINDOWPOS(PSWP pswp, PWINDOWPOS pwpos, PSWP pswpOld,
388 int parentHeight, int clientOrgX, int clientOrgY,
389 HWND hwnd)
390{
391 HWND hWindow = pswp->hwnd;
392 HWND hWndInsertAfter = pswp->hwndInsertBehind;
393 long x = pswp->x - clientOrgX;
394 long y = pswp->y + clientOrgY;
395 long cx = pswp->cx;
396 long cy = pswp->cy;
397 UINT fuFlags = (UINT)pswp->fl;
398
399 HWND hWinAfter;
400 ULONG flags = 0;
401
402 HWND hWnd = (hWindow == HWND_DESKTOP) ? HWND_DESKTOP_W: hWindow;
403
404 if (hWndInsertAfter == HWND_TOP)
405 hWinAfter = HWND_TOP_W;
406 else if (hWndInsertAfter == HWND_BOTTOM)
407 hWinAfter = HWND_BOTTOM_W;
408 else
409 hWinAfter = (HWND) hWndInsertAfter;
410
411 //***********************************
412 // convert PM flags to Windows flags
413 //***********************************
414 if (!(fuFlags & SWP_SIZE)) flags |= SWP_NOSIZE_W;
415 if (!(fuFlags & SWP_MOVE)) flags |= SWP_NOMOVE_W;
416 if (!(fuFlags & SWP_ZORDER)) flags |= SWP_NOZORDER_W;
417 if ( fuFlags & SWP_NOREDRAW) flags |= SWP_NOREDRAW_W;
418 if (!(fuFlags & SWP_ACTIVATE)) flags |= SWP_NOACTIVATE_W;
419 if ( fuFlags & SWP_SHOW) flags |= SWP_SHOWWINDOW_W;
420 if ( fuFlags & SWP_HIDE) flags |= SWP_HIDEWINDOW_W;
421 if ( fuFlags & SWP_NOADJUST) flags |= SWP_NOSENDCHANGING_W;
422
423 if(fuFlags & (SWP_MOVE | SWP_SIZE))
424 {
425 y = parentHeight - y - pswp->cy;
426
427 if ((pswp->x == pswpOld->x) && (pswp->y == pswpOld->y))
428 flags |= SWP_NOMOVE_W;
429
430 if ((pswp->cx == pswpOld->cx) && (pswp->cy == pswpOld->cy))
431 flags |= SWP_NOSIZE_W;
432
433 if (fuFlags & SWP_SIZE)
434 {
435 if (pswp->cy != pswpOld->cy)
436 {
437 flags &= ~SWP_NOMOVE_W;
438 }
439 }
440 }
441
442 pswpOld->x = pswp->x;
443 pswpOld->y = parentHeight-pswp->y-pswp->cy;
444 pswpOld->cx = pswp->cx;
445 pswpOld->cy = pswp->cy;
446
447 dprintf(("window (%d,%d)(%d,%d) client (%d,%d)(%d,%d)",
448 x,y,cx,cy, pswpOld->x,pswpOld->y,pswpOld->cx,pswpOld->cy));
449
450 pwpos->flags = (UINT)flags;
451 pwpos->cy = cy;
452 pwpos->cx = cx;
453 pwpos->x = x;
454 pwpos->y = y;
455 pwpos->hwndInsertAfter = hWinAfter;
456 pwpos->hwnd = hWindow;
457}
458//******************************************************************************
459//******************************************************************************
460void OSLibMapWINDOWPOStoSWP(struct tagWINDOWPOS *pwpos, PSWP pswp, PSWP pswpOld,
461 int parentHeight, int clientOrgX, int clientOrgY, HWND hFrame)
462{
463 BOOL fCvt = FALSE;
464
465 HWND hWnd = pwpos->hwnd;
466 HWND hWndInsertAfter = pwpos->hwndInsertAfter;
467 long x = pwpos->x + clientOrgX;
468 long y = pwpos->y + clientOrgY;
469 long cx = pwpos->cx;
470 long cy = pwpos->cy;
471 UINT fuFlags = pwpos->flags;
472
473 HWND hWinAfter;
474 ULONG flags = 0;
475 HWND hWindow = hWnd ? (HWND)hWnd : HWND_DESKTOP;
476
477 if (hWndInsertAfter == HWND_TOPMOST_W)
478// hWinAfter = HWND_TOPMOST;
479 hWinAfter = HWND_TOP;
480 else if (hWndInsertAfter == HWND_NOTOPMOST_W)
481// hWinAfter = HWND_NOTOPMOST;
482 hWinAfter = HWND_TOP;
483 else if (hWndInsertAfter == HWND_TOP_W)
484 hWinAfter = HWND_TOP;
485 else if (hWndInsertAfter == HWND_BOTTOM_W)
486 hWinAfter = HWND_BOTTOM;
487 else
488 hWinAfter = (HWND) hWndInsertAfter;
489
490 if (!(fuFlags & SWP_NOSIZE_W )) flags |= SWP_SIZE;
491 if (!(fuFlags & SWP_NOMOVE_W )) flags |= SWP_MOVE;
492 if (!(fuFlags & SWP_NOZORDER_W )) flags |= SWP_ZORDER;
493 if ( fuFlags & SWP_NOREDRAW_W ) flags |= SWP_NOREDRAW;
494 if (!(fuFlags & SWP_NOACTIVATE_W)) flags |= SWP_ACTIVATE;
495 if ( fuFlags & SWP_SHOWWINDOW_W) flags |= SWP_SHOW;
496 if ( fuFlags & SWP_HIDEWINDOW_W) flags |= SWP_HIDE;
497 if ( fuFlags & SWP_NOSENDCHANGING_W) flags |= SWP_NOADJUST;
498
499 if(flags & (SWP_MOVE | SWP_SIZE))
500 {
501 if((flags & SWP_MOVE) == 0)
502 {
503 x = pswpOld->x;
504 y = pswpOld->y;
505
506 y = parentHeight - y - pswpOld->cy;
507 }
508
509 if(flags & SWP_SIZE)
510 {
511 if (cy != pswpOld->cy)
512 flags |= SWP_MOVE;
513 }
514 else
515 {
516 cx = pswpOld->cx;
517 cy = pswpOld->cy;
518 }
519 y = parentHeight - y - cy;
520
521 if ((pswpOld->x == x) && (pswpOld->y == y))
522 flags &= ~SWP_MOVE;
523
524 if ((pswpOld->cx == cx) && (pswpOld->cy == cy))
525 flags &= ~SWP_SIZE;
526 }
527
528 pswp->fl = flags;
529 pswp->cy = cy;
530 pswp->cx = cx;
531 pswp->x = x;
532 pswp->y = y;
533 pswp->hwndInsertBehind = hWinAfter;
534 pswp->hwnd = hWindow;
535 pswp->ulReserved1 = 0;
536 pswp->ulReserved2 = 0;
537}
538//******************************************************************************
539//Position in screen coordinates
540//******************************************************************************
541BOOL OSLibWinCalcFrameRect(HWND hwndFrame, RECT *pRect, BOOL fClient)
542{
543 BOOL rc;
544
545 WinMapWindowPoints(hwndFrame, HWND_DESKTOP, (PPOINTL)pRect, 2);
546
547 rc = WinCalcFrameRect(hwndFrame, (PRECTL)pRect, fClient);
548 WinMapWindowPoints(HWND_DESKTOP, hwndFrame, (PPOINTL)pRect, 2);
549
550 return rc;
551}
552//******************************************************************************
553//******************************************************************************
554BOOL OSLibGetMinMaxInfo(HWND hwndFrame, MINMAXINFO *pMinMax)
555{
556 TRACKINFO tinfo;
557
558 memset(&tinfo, 0, sizeof(TRACKINFO));
559 WinSendMsg(hwndFrame, WM_QUERYTRACKINFO, (MPARAM)0,(MPARAM)&tinfo);
560
561 pMinMax->ptMinTrackSize.x = tinfo.ptlMinTrackSize.x;
562 pMinMax->ptMinTrackSize.y = tinfo.ptlMinTrackSize.y;
563 pMinMax->ptMaxTrackSize.x = tinfo.ptlMaxTrackSize.x;
564 pMinMax->ptMaxTrackSize.y = tinfo.ptlMaxTrackSize.y;
565 return TRUE;
566}
567//******************************************************************************
568//******************************************************************************
569HWND OSLibWinBeginEnumWindows(HWND hwnd)
570{
571 if(hwnd == OSLIB_HWND_DESKTOP) hwnd = HWND_DESKTOP;
572 else
573 if(hwnd == OSLIB_HWND_OBJECT) hwnd = HWND_OBJECT;
574
575 return WinBeginEnumWindows(hwnd);
576}
577//******************************************************************************
578//******************************************************************************
579HWND OSLibWinGetNextWindow(HWND hwndEnum)
580{
581 return WinGetNextWindow(hwndEnum);
582}
583//******************************************************************************
584//******************************************************************************
585HWND OSLibWinQueryClientWindow(HWND hwndFrame)
586{
587 HWND hwndClient = 0;
588
589 if(((ULONG)WinSendMsg(hwndFrame, WM_QUERYFRAMEINFO, NULL, NULL)) & FI_FRAME)
590 hwndClient = WinWindowFromID(hwndFrame, FID_CLIENT);
591
592 return hwndClient;
593}
594//******************************************************************************
595//******************************************************************************
596BOOL OSLibWinEndEnumWindows(HWND hwndEnum)
597{
598 return WinEndEnumWindows(hwndEnum);
599}
600//******************************************************************************
601//******************************************************************************
602BOOL OSLibWinQueryWindowProcess(HWND hwnd, ULONG *pid, ULONG *tid)
603{
604 return WinQueryWindowProcess(hwnd, pid, tid);
605}
606//******************************************************************************
607//******************************************************************************
608BOOL OSLibWinMapWindowPoints (HWND hwndFrom, HWND hwndTo, OSLIBPOINT *pptl, ULONG num)
609{
610 return WinMapWindowPoints (hwndFrom, hwndTo, (PPOINTL)pptl, num);
611}
612//******************************************************************************
613//******************************************************************************
614HWND OSLibWinQueryObjectWindow(VOID)
615{
616 return WinQueryObjectWindow(HWND_DESKTOP);
617}
618//******************************************************************************
619//******************************************************************************
620HWND OSLibWinObjectWindowFromID(HWND hwndOwner, ULONG ID)
621{
622 HWND hwndNext, hwndFound=0;
623 HENUM henum;
624
625 henum = WinBeginEnumWindows(HWND_OBJECT);
626 while ((hwndNext = WinGetNextWindow(henum)) != 0)
627 {
628 if(WinQueryWindow(hwndNext, QW_OWNER) == hwndOwner &&
629 WinQueryWindowUShort(hwndNext, QWS_ID) == ID)
630 {
631 hwndFound = hwndNext;
632 break;
633 }
634 }
635 WinEndEnumWindows(henum);
636 return hwndFound;
637}
638//******************************************************************************
639//******************************************************************************
640BOOL OSLibSetWindowID(HWND hwnd, ULONG value)
641{
642 dprintf(("OSLibSetWindowID hwnd:%x ID:%x", hwnd, value));
643 return WinSetWindowULong(hwnd, QWS_ID, value);
644}
645//******************************************************************************
646//******************************************************************************
647PVOID OSLibWinSubclassWindow(HWND hwnd,PVOID newWndProc)
648{
649 return WinSubclassWindow(hwnd,(PFNWP)newWndProc);
650}
651//******************************************************************************
652//******************************************************************************
653BOOL OSLibSetWindowRestoreRect(HWND hwnd, PRECT pRect)
654{
655 ULONG yHeight = OSLibGetWindowHeight(WinQueryWindow(hwnd, QW_PARENT));
656
657 WinSetWindowUShort(hwnd, QWS_XRESTORE, (USHORT)pRect->left );
658 WinSetWindowUShort(hwnd, QWS_YRESTORE, (USHORT)(yHeight - pRect->top -
659 (pRect->bottom - pRect->top)));
660 WinSetWindowUShort(hwnd, QWS_CXRESTORE, (USHORT)(pRect->right - pRect->left));
661 WinSetWindowUShort(hwnd, QWS_CYRESTORE, (USHORT)(pRect->bottom - pRect->top));
662 return TRUE;
663}
664//******************************************************************************
665//******************************************************************************
666BOOL OSLibSetWindowMinPos(HWND hwnd, ULONG x, ULONG y)
667{
668 ULONG yHeight = OSLibGetWindowHeight(WinQueryWindow(hwnd, QW_PARENT));
669
670 WinSetWindowUShort(hwnd, QWS_XMINIMIZE, (USHORT)x );
671 WinSetWindowUShort(hwnd, QWS_YMINIMIZE, (USHORT)(yHeight - y -
672 ( 2 * WinQuerySysValue( HWND_DESKTOP, SV_CYSIZEBORDER)) -
673 WinQuerySysValue( HWND_DESKTOP, SV_CYICON)));
674 return TRUE;
675}
676//******************************************************************************
677//******************************************************************************
678BOOL OSLibWinGetKeyboardStateTable(unsigned char *PMKeyState)
679{
680 return WinSetKeyboardStateTable(HWND_DESKTOP, (PBYTE)&PMKeyState, FALSE );
681}
682//******************************************************************************
683//******************************************************************************
684BOOL OSLibWinSetKeyboardStateTable(unsigned char *PMKeyState)
685{
686 return WinSetKeyboardStateTable(HWND_DESKTOP, (PBYTE)&PMKeyState, TRUE );
687}
688//******************************************************************************
689//******************************************************************************
690BOOL OSLibWinEnableWindowUpdate(HWND hwnd,BOOL fEnable)
691{
692 return WinEnableWindowUpdate(hwnd,fEnable);
693}
694//******************************************************************************
695//******************************************************************************
696ULONG OSLibWinGetLastError()
697{
698 return WinGetLastError(GetThreadHAB()) & 0xFFFF;
699}
700//******************************************************************************
701//******************************************************************************
702void OSLibWinShowTaskList(HWND hwndFrame)
703{
704 //CB: don't know if this works on all machines
705 WinSetActiveWindow(HWND_DESKTOP,0x8000000E);
706}
707//******************************************************************************
708//******************************************************************************
709void OSLibSetWindowStyle(HWND hwnd, ULONG dwStyle, ULONG dwExStyle, BOOL saveBits)
710{
711 ULONG dwWinStyle;
712
713 OSLibWinConvertStyle(dwStyle, dwExStyle, &dwWinStyle);
714
715 dwWinStyle = dwWinStyle & ~(WS_TABSTOP | WS_GROUP | WS_CLIPCHILDREN);
716 if(saveBits) dwWinStyle |= WS_SAVEBITS;
717 if(dwStyle & WS_VISIBLE_W)
718 dwWinStyle |= WS_VISIBLE;
719
720 WinSetWindowULong(hwnd, QWL_STYLE,
721 (WinQueryWindowULong(hwnd, QWL_STYLE) & ~0xffff0000) |
722 dwWinStyle);
723}
724//******************************************************************************
725//******************************************************************************
726DWORD OSLibQueryWindowStyle(HWND hwnd)
727{
728 return WinQueryWindowULong(hwnd, QWL_STYLE);
729}
730//******************************************************************************
731//******************************************************************************
732void OSLibWinSetVisibleRegionNotify(HWND hwnd, BOOL fNotify)
733{
734 WinSetVisibleRegionNotify(hwnd, fNotify);
735}
736//******************************************************************************
737//******************************************************************************
738HWND OSLibWinQueryCapture()
739{
740 return WinQueryCapture(HWND_DESKTOP);
741}
742//******************************************************************************
743//******************************************************************************
744BOOL OSLibWinSetCapture(HWND hwnd)
745{
746 return WinSetCapture(HWND_DESKTOP, hwnd);
747}
748//******************************************************************************
749//******************************************************************************
750BOOL OSLibWinRemoveFromTasklist(HANDLE hTaskList)
751{
752 return (WinRemoveSwitchEntry(hTaskList)) ? FALSE : TRUE;
753}
754//******************************************************************************
755//******************************************************************************
756HANDLE OSLibWinAddToTaskList(HWND hwndFrame, char *title, BOOL fVisible)
757{
758 SWCNTRL swctrl;
759 ULONG tid;
760
761 swctrl.hwnd = hwndFrame;
762 swctrl.hwndIcon = 0;
763 swctrl.hprog = 0;
764 WinQueryWindowProcess(hwndFrame, (PPID)&swctrl.idProcess, (PTID)&tid);
765 swctrl.idSession = 0;
766 swctrl.uchVisibility = (fVisible) ? SWL_VISIBLE : SWL_INVISIBLE;
767 swctrl.fbJump = SWL_JUMPABLE;
768 swctrl.bProgType = PROG_PM;
769 if(title) {
770 strncpy(swctrl.szSwtitle, title, MAXNAMEL+4);
771 swctrl.szSwtitle[MAXNAMEL+4-1] = 0;
772 }
773 else {
774 swctrl.szSwtitle[0] = 0;
775 swctrl.uchVisibility = SWL_INVISIBLE;
776 }
777 return WinAddSwitchEntry(&swctrl);
778}
779//******************************************************************************
780//******************************************************************************
781BOOL OSLibWinChangeTaskList(HANDLE hTaskList, HWND hwndFrame, char *title, BOOL fVisible)
782{
783 SWCNTRL swctrl;
784 ULONG tid;
785
786 swctrl.hwnd = hwndFrame;
787 swctrl.hwndIcon = 0;
788 swctrl.hprog = 0;
789 WinQueryWindowProcess(hwndFrame, (PPID)&swctrl.idProcess, (PTID)&tid);
790 swctrl.idSession = 0;
791 swctrl.uchVisibility = (fVisible) ? SWL_VISIBLE : SWL_INVISIBLE;
792 swctrl.fbJump = SWL_JUMPABLE;
793 swctrl.bProgType = PROG_PM;
794 if(title) {
795 strncpy(swctrl.szSwtitle, title, MAXNAMEL+4);
796 swctrl.szSwtitle[MAXNAMEL+4-1] = 0;
797 }
798 else {
799 swctrl.szSwtitle[0] = 0;
800 swctrl.uchVisibility = SWL_INVISIBLE;
801 }
802 return (WinChangeSwitchEntry(hTaskList, &swctrl)) ? FALSE : TRUE;
803}
804//******************************************************************************
805//******************************************************************************
806BOOL OSLibWinLockWindowUpdate(HWND hwnd)
807{
808 return WinLockWindowUpdate(HWND_DESKTOP, (HWND)hwnd);
809}
810//******************************************************************************
811//******************************************************************************
812ULONG OSLibGetScreenHeight()
813{
814 return ScreenHeight;
815}
816//******************************************************************************
817//******************************************************************************
818ULONG OSLibGetScreenWidth()
819{
820 return ScreenWidth;
821}
822//******************************************************************************
823//Returns the maximum position for a window
824//Should only be used from toplevel windows
825//******************************************************************************
826BOOL OSLibWinGetMaxPosition(HWND hwndOS2, RECT *rect)
827{
828 SWP swp;
829
830 if(!WinGetMaxPosition(hwndOS2, &swp)) {
831 dprintf(("WARNING: WinGetMaxPosition %x returned FALSE", hwndOS2));
832 return FALSE;
833 }
834 rect->left = swp.x;
835 rect->right = swp.x + swp.cx;
836 rect->top = ScreenHeight - (swp.y + swp.cy);
837 rect->bottom = ScreenHeight - swp.y;
838 return TRUE;
839}
840//******************************************************************************
841//******************************************************************************
Note: See TracBrowser for help on using the repository browser.