source: trunk/src/user32/new/oslibwin.cpp@ 340

Last change on this file since 340 was 340, checked in by sandervl, 26 years ago

Point/Rectangle bug fixes

File size: 14.8 KB
Line 
1/* $Id: oslibwin.cpp,v 1.16 1999-07-19 18:40:43 sandervl Exp $ */
2/*
3 * Window API wrappers for OS/2
4 *
5 *
6 * Copyright 1999 Sander van Leeuwen (sandervl@xs4all.nl)
7 *
8 *
9 * Project Odin Software License can be found in LICENSE.TXT
10 *
11 */
12#define INCL_WIN
13#define INCL_PM
14#include <os2.h>
15#include <os2wrap.h>
16#include <stdlib.h>
17#include <string.h>
18
19#include <misc.h>
20#include <oslibwin.h>
21#include "oslibstyle.h"
22#include "oslibutil.h"
23#include "oslibmsg.h"
24#include "oslibgdi.h"
25#include "pmwindow.h"
26
27//******************************************************************************
28//******************************************************************************
29BOOL OSLibWinSetParent(HWND hwnd, HWND hwndParent, ULONG fRedraw)
30{
31 if(hwndParent == OSLIB_HWND_DESKTOP)
32 {
33 hwndParent = HWND_DESKTOP;
34 }
35
36 return (WinSetParent(hwnd, hwndParent, fRedraw) == 0);
37}
38//******************************************************************************
39//******************************************************************************
40HWND OSLibWinCreateWindow(HWND hwndParent, ULONG dwWinStyle, ULONG dwFrameStyle,
41 char *pszName, HWND Owner, ULONG fHWND_BOTTOM, HWND *hwndFrame)
42{
43 HWND hwndClient;
44
45 dprintf(("WinCreateWindow %x %x %x %s", hwndParent, dwWinStyle, dwFrameStyle, pszName));
46
47 if(pszName && *pszName == 0) {
48 pszName = NULL;
49 }
50 if(hwndParent == 0) {
51 hwndParent = HWND_DESKTOP;
52 }
53 if(dwFrameStyle) {
54 dwWinStyle &= ~WS_CLIPCHILDREN; //invalid style according to docs
55 if(pszName)
56 dwFrameStyle |= FCF_TITLEBAR;
57
58 *hwndFrame = WinCreateStdWindow(hwndParent, dwWinStyle,
59 &dwFrameStyle, WIN32_STDCLASS,
60 "", 0, 0, 0, &hwndClient);
61 if(*hwndFrame) {
62 if(pszName) {
63 WinSetWindowText(*hwndFrame, pszName);
64 }
65 return hwndClient;
66 }
67 dprintf(("OSLibWinCreateWindow: WinCreateStdWindow failed (%x)", WinGetLastError(GetThreadHAB())));
68 return 0;
69 }
70 hwndClient = WinCreateWindow(hwndParent, WIN32_STDCLASS, pszName, dwWinStyle, 0, 0, 0, 0,
71 Owner, (fHWND_BOTTOM) ? HWND_BOTTOM :HWND_TOP, 0, NULL,
72 NULL);
73 *hwndFrame = hwndClient;
74 return hwndClient;
75}
76//******************************************************************************
77//******************************************************************************
78BOOL OSLibWinConvertStyle(ULONG dwStyle, ULONG *OSWinStyle, ULONG *OSFrameStyle)
79{
80 *OSWinStyle = 0;
81 *OSFrameStyle = 0;
82
83 /* Window styles */
84 if(dwStyle & WINWS_MINIMIZE)
85 *OSWinStyle |= WS_MINIMIZED;
86//Done explicitely in CreateWindowExA
87#if 0
88 if(dwStyle & WINWS_VISIBLE)
89 *OSWinStyle |= WS_VISIBLE;
90#endif
91 if(dwStyle & WINWS_DISABLED)
92 *OSWinStyle |= WS_DISABLED;
93 if(dwStyle & WINWS_CLIPSIBLINGS)
94 *OSWinStyle |= WS_CLIPSIBLINGS;
95 if(dwStyle & WINWS_CLIPCHILDREN)
96 *OSWinStyle |= WS_CLIPCHILDREN;
97 if(dwStyle & WINWS_MAXIMIZE)
98 *OSWinStyle |= WS_MAXIMIZED;
99 if(dwStyle & WINWS_GROUP)
100 *OSWinStyle |= WS_GROUP;
101 if(dwStyle & WINWS_TABSTOP)
102 *OSWinStyle |= WS_TABSTOP;
103
104 if(dwStyle & WINWS_CAPTION)
105 *OSFrameStyle |= FCF_TITLEBAR;
106 if(dwStyle & WINWS_BORDER)
107 *OSFrameStyle |= FCF_BORDER;
108 if(dwStyle & WINWS_DLGFRAME)
109 *OSFrameStyle |= FCF_DLGBORDER;
110 if(dwStyle & WINWS_VSCROLL)
111 *OSFrameStyle |= FCF_VERTSCROLL;
112 if(dwStyle & WINWS_HSCROLL)
113 *OSFrameStyle |= FCF_HORZSCROLL;
114 if(dwStyle & WINWS_SYSMENU)
115 *OSFrameStyle |= FCF_SYSMENU;
116 if(dwStyle & WINWS_THICKFRAME)
117 *OSFrameStyle |= FCF_SIZEBORDER; //??
118 if(dwStyle & WINWS_MINIMIZEBOX)
119 *OSFrameStyle |= FCF_MINBUTTON;
120 if(dwStyle & WINWS_MAXIMIZEBOX)
121 *OSFrameStyle |= FCF_MAXBUTTON;
122
123 return TRUE;
124}
125//******************************************************************************
126//******************************************************************************
127BOOL OSLibWinSetWindowULong(HWND hwnd, ULONG offset, ULONG value)
128{
129 return WinSetWindowULong(hwnd, offset, value);
130}
131//******************************************************************************
132//******************************************************************************
133ULONG OSLibWinGetWindowULong(HWND hwnd, ULONG offset)
134{
135 return WinQueryWindowULong(hwnd, offset);
136}
137//******************************************************************************
138//******************************************************************************
139BOOL OSLibPostMessage(HWND hwnd, ULONG msg, ULONG wParam, ULONG lParam)
140{
141 return WinPostMsg(hwnd, msg, (MPARAM)wParam, (MPARAM)lParam);
142}
143//******************************************************************************
144//******************************************************************************
145HWND OSLibWinCreateMenu(HWND hwndParent, PVOID menutemplate)
146{
147 return WinCreateMenu(hwndParent, menutemplate);
148}
149//******************************************************************************
150//******************************************************************************
151BOOL OSLibWinAlarm(HWND hwndDeskTop,ULONG flStyle)
152{
153 return WinAlarm(hwndDeskTop,flStyle);
154}
155//******************************************************************************
156//******************************************************************************
157APIRET OSLibDosBeep(ULONG freg,ULONG dur)
158{
159 return DosBeep(freg,dur);
160}
161//******************************************************************************
162//******************************************************************************
163HWND OSLibWinQueryFocus(HWND hwndDeskTop)
164{
165 return WinQueryFocus(hwndDeskTop);
166}
167//******************************************************************************
168//******************************************************************************
169HWND OSLibWinWindowFromID(HWND hwndParent,ULONG id)
170{
171 return WinWindowFromID(hwndParent,id);
172}
173//******************************************************************************
174//******************************************************************************
175BOOL OSLibWinSetFocus(HWND hwndDeskTop,HWND hwndNewFocus)
176{
177 return WinSetFocus(hwndDeskTop,hwndNewFocus);
178}
179//******************************************************************************
180//******************************************************************************
181ULONG OSLibGetWindowHeight(HWND hwnd)
182{
183 RECTL rect;
184
185 return (WinQueryWindowRect(hwnd,&rect)) ? rect.yTop-rect.yBottom:0;
186}
187//******************************************************************************
188//******************************************************************************
189BOOL OSLibWinInvalidateRect(HWND hwnd,POSRECTL pwrc,BOOL fIncludeChildren)
190{
191 return WinInvalidateRect(hwnd,(PRECTL)pwrc,fIncludeChildren);
192}
193//******************************************************************************
194//******************************************************************************
195LONG OSLibWinQuerySysValue(HWND hwndDeskTop,LONG iSysValue)
196{
197 return WinQuerySysValue(hwndDeskTop,iSysValue);
198}
199//******************************************************************************
200//******************************************************************************
201ULONG OSLibWinQueryDlgItemText(HWND hwndDlg,ULONG idItem,LONG cchBufferMax,char* pchBuffer)
202{
203 return WinQueryDlgItemText(hwndDlg,idItem,cchBufferMax,pchBuffer);
204}
205//******************************************************************************
206//******************************************************************************
207BOOL OSLibWinSetDlgItemText(HWND hwndDlg,ULONG idItem,char* pszText)
208{
209 return WinSetDlgItemText(hwndDlg,idItem,pszText);
210}
211//******************************************************************************
212//******************************************************************************
213BOOL OSLibWinQueryPointerPos(HWND hwndDeskTop,PPOINT pptlPoint)
214{
215 return WinQueryPointerPos(hwndDeskTop,(PPOINTL)pptlPoint);
216}
217//******************************************************************************
218//******************************************************************************
219HWND OSLibWinQueryWindow(HWND hwnd, ULONG lCode)
220{
221 return WinQueryWindow(hwnd, lCode);
222}
223//******************************************************************************
224//******************************************************************************
225BOOL OSLibWinSetWindowPos(HWND hwnd, HWND hwndInsertBehind, LONG x, LONG y, LONG cx,
226 LONG cy, ULONG fl)
227{
228 HWND hwndParent = hwndInsertBehind;
229
230 if(fl & SWP_MOVE) {
231 switch(hwndParent)
232 {
233 case HWNDOS_TOP:
234 case HWNDOS_BOTTOM:
235 hwndParent = HWND_DESKTOP;
236 break;
237 }
238 y = MapOS2ToWin32Y(hwndParent, cy, y);
239 }
240 dprintf(("WinSetWindowPos %x %x %d %d %d %d %x", hwnd, hwndInsertBehind, x, y, cx, cy, fl));
241 return WinSetWindowPos(hwnd, hwndInsertBehind, x, y, cx, cy, fl);
242}
243//******************************************************************************
244//******************************************************************************
245BOOL OSLibWinShowWindow(HWND hwnd, ULONG fl)
246{
247 BOOL rc;
248
249 if(fl & SWP_SHOW) {
250 rc = WinShowWindow(hwnd, TRUE);
251 }
252 if(rc == 0)
253 dprintf(("WinShowWindow %x failed %x", hwnd, WinGetLastError(GetThreadHAB())));
254 rc = WinSetWindowPos(hwnd, HWND_TOP, 0, 0, 0, 0, fl);
255 if(rc == 0)
256 dprintf(("WinShowWindow %x failed %x", hwnd, WinGetLastError(GetThreadHAB())));
257 return rc;
258}
259//******************************************************************************
260//******************************************************************************
261BOOL OSLibWinDestroyWindow(HWND hwnd)
262{
263 return WinDestroyWindow(hwnd);
264}
265//******************************************************************************
266//Returns rectangle in Win32 window coordinates
267//******************************************************************************
268BOOL OSLibWinQueryUpdateRect(HWND hwnd, PVOID pRect)
269{
270 BOOL rc;
271 RECTLOS2 rectl;
272
273 rc = WinQueryUpdateRect(hwnd, (PRECTL)&rectl);
274 if(rc) {
275 MapOS2ToWin32Rectl(&rectl, (PRECT)pRect);
276 }
277 else memset(pRect, 0, sizeof(RECT));
278 return rc;
279}
280//******************************************************************************
281//******************************************************************************
282BOOL OSLibWinIsIconic(HWND hwnd)
283{
284 SWP swp;
285 BOOL rc;
286
287 rc = WinQueryWindowPos(hwnd, &swp);
288 if(rc == FALSE) {
289 dprintf(("OSLibWinIsIconic: WinQueryWindowPos %x failed", hwnd));
290 return FALSE;
291 }
292
293 if(swp.fl & SWP_MINIMIZE)
294 return TRUE;
295 else return FALSE;
296}
297//******************************************************************************
298//******************************************************************************
299BOOL OSLibWinSetActiveWindow(HWND hwnd)
300{
301 return WinSetActiveWindow(HWND_DESKTOP, hwnd);
302}
303//******************************************************************************
304//******************************************************************************
305BOOL OSLibWinSetFocus(HWND hwnd)
306{
307 return WinSetFocus(HWND_DESKTOP, hwnd);
308}
309//******************************************************************************
310//******************************************************************************
311BOOL OSLibWinEnableWindow(HWND hwnd, BOOL fEnable)
312{
313 return WinEnableWindow(hwnd, fEnable);
314}
315//******************************************************************************
316//******************************************************************************
317BOOL OSLibWinIsWindowEnabled(HWND hwnd)
318{
319 return WinIsWindowEnabled(hwnd);
320}
321//******************************************************************************
322//******************************************************************************
323BOOL OSLibWinIsWindowVisible(HWND hwnd)
324{
325 return WinIsWindowVisible(hwnd);
326}
327//******************************************************************************
328//******************************************************************************
329BOOL OSLibWinQueryActiveWindow()
330{
331 return WinQueryActiveWindow(HWND_DESKTOP);
332}
333//******************************************************************************
334//******************************************************************************
335void OSLibWinPostQuitMessage(ULONG nExitCode)
336{
337 WinPostQueueMsg(GetThreadMessageQueue(), WM_QUIT, (MPARAM)nExitCode, 0);
338}
339//******************************************************************************
340//******************************************************************************
341LONG OSLibWinDispatchMsg(MSG *msg, BOOL isUnicode)
342{
343 QMSG qmsg;
344
345 WinToOS2MsgTranslate(msg, &qmsg, isUnicode);
346 return (LONG)WinDispatchMsg(GetThreadHAB(), &qmsg);
347}
348//******************************************************************************
349//******************************************************************************
350BOOL OSLibWinGetMsg(LPMSG pMsg, HWND hwnd, UINT uMsgFilterMin, UINT uMsgFilterMax, BOOL isUnicode)
351{
352 QMSG qmsg;
353 BOOL rc;
354
355 rc = WinGetMsg(GetThreadHAB(), &qmsg, TranslateWinMsg(uMsgFilterMin), TranslateWinMsg(uMsgFilterMax), 0);
356 OS2ToWinMsgTranslate(&qmsg, pMsg, isUnicode);
357 return rc;
358}
359//******************************************************************************
360//******************************************************************************
361LONG OSLibWinQueryWindowTextLength(HWND hwnd)
362{
363 return WinQueryWindowTextLength(hwnd);
364}
365//******************************************************************************
366//******************************************************************************
367LONG OSLibWinQueryWindowText(HWND hwnd, LONG length, LPSTR lpsz)
368{
369 return WinQueryWindowText(hwnd, length, lpsz);
370}
371//******************************************************************************
372//******************************************************************************
373BOOL OSLibWinSetWindowText(HWND hwnd, LPSTR lpsz)
374{
375 return WinSetWindowText(hwnd, lpsz);
376}
377//******************************************************************************
378//******************************************************************************
379BOOL OSLibWinFlashWindow(HWND hwnd, BOOL fFlash)
380{
381 return WinFlashWindow(hwnd, fFlash);
382}
383//******************************************************************************
384//******************************************************************************
385HWND OSLibWinWindowFromPoint(HWND hwnd, PVOID ppoint)
386{
387 return WinWindowFromPoint((hwnd == OSLIB_HWND_DESKTOP) ? HWND_DESKTOP : hwnd, (PPOINTL)ppoint, TRUE);
388}
389//******************************************************************************
390//******************************************************************************
391BOOL OSLibWinMinimizeWindow(HWND hwnd)
392{
393 return WinSetWindowPos(hwnd, 0, 0, 0, 0, 0, SWP_MINIMIZE);
394}
395//******************************************************************************
396//******************************************************************************
397
Note: See TracBrowser for help on using the repository browser.