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

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

WM_SETREDRAW fix

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