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

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

* empty log message *

File size: 14.5 KB
Line 
1/* $Id: oslibwin.cpp,v 1.15 1999-07-18 18:04:29 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 if(fl & SWP_MOVE) {
229 y = MapOS2ToWin32Y(hwnd, cy, y);
230 }
231 dprintf(("WinSetWindowPos %x %x %d %d %d %d %x", hwnd, hwndInsertBehind, x, y, cx, cy, fl));
232 return WinSetWindowPos(hwnd, hwndInsertBehind, x, y, cx, cy, fl);
233}
234//******************************************************************************
235//******************************************************************************
236BOOL OSLibWinShowWindow(HWND hwnd, ULONG fl)
237{
238 BOOL rc;
239
240 if(fl & SWP_SHOW) {
241 rc = WinShowWindow(hwnd, TRUE);
242 }
243 if(rc == 0)
244 dprintf(("WinShowWindow %x failed %x", hwnd, WinGetLastError(GetThreadHAB())));
245 rc = WinSetWindowPos(hwnd, HWND_TOP, 0, 0, 0, 0, fl);
246 if(rc == 0)
247 dprintf(("WinShowWindow %x failed %x", hwnd, WinGetLastError(GetThreadHAB())));
248 return rc;
249}
250//******************************************************************************
251//******************************************************************************
252BOOL OSLibWinDestroyWindow(HWND hwnd)
253{
254 return WinDestroyWindow(hwnd);
255}
256//******************************************************************************
257//******************************************************************************
258BOOL OSLibWinQueryUpdateRect(HWND hwnd, PVOID pRect)
259{
260 BOOL rc;
261 RECTLOS2 rectl;
262
263 rc = WinQueryUpdateRect(hwnd, (PRECTL)&rectl);
264 if(rc) {
265 MapOS2ToWin32Rectl(hwnd, &rectl, (PRECT)pRect);
266 }
267 return rc;
268}
269//******************************************************************************
270//******************************************************************************
271BOOL OSLibWinIsIconic(HWND hwnd)
272{
273 SWP swp;
274 BOOL rc;
275
276 rc = WinQueryWindowPos(hwnd, &swp);
277 if(rc == FALSE) {
278 dprintf(("OSLibWinIsIconic: WinQueryWindowPos %x failed", hwnd));
279 return FALSE;
280 }
281
282 if(swp.fl & SWP_MINIMIZE)
283 return TRUE;
284 else return FALSE;
285}
286//******************************************************************************
287//******************************************************************************
288BOOL OSLibWinSetActiveWindow(HWND hwnd)
289{
290 return WinSetActiveWindow(HWND_DESKTOP, hwnd);
291}
292//******************************************************************************
293//******************************************************************************
294BOOL OSLibWinSetFocus(HWND hwnd)
295{
296 return WinSetFocus(HWND_DESKTOP, hwnd);
297}
298//******************************************************************************
299//******************************************************************************
300BOOL OSLibWinEnableWindow(HWND hwnd, BOOL fEnable)
301{
302 return WinEnableWindow(hwnd, fEnable);
303}
304//******************************************************************************
305//******************************************************************************
306BOOL OSLibWinIsWindowEnabled(HWND hwnd)
307{
308 return WinIsWindowEnabled(hwnd);
309}
310//******************************************************************************
311//******************************************************************************
312BOOL OSLibWinIsWindowVisible(HWND hwnd)
313{
314 return WinIsWindowVisible(hwnd);
315}
316//******************************************************************************
317//******************************************************************************
318BOOL OSLibWinQueryActiveWindow()
319{
320 return WinQueryActiveWindow(HWND_DESKTOP);
321}
322//******************************************************************************
323//******************************************************************************
324void OSLibWinPostQuitMessage(ULONG nExitCode)
325{
326 WinPostQueueMsg(GetThreadMessageQueue(), WM_QUIT, (MPARAM)nExitCode, 0);
327}
328//******************************************************************************
329//******************************************************************************
330LONG OSLibWinDispatchMsg(MSG *msg, BOOL isUnicode)
331{
332 QMSG qmsg;
333
334 WinToOS2MsgTranslate(msg, &qmsg, isUnicode);
335 return (LONG)WinDispatchMsg(GetThreadHAB(), &qmsg);
336}
337//******************************************************************************
338//******************************************************************************
339BOOL OSLibWinGetMsg(LPMSG pMsg, HWND hwnd, UINT uMsgFilterMin, UINT uMsgFilterMax, BOOL isUnicode)
340{
341 QMSG qmsg;
342 BOOL rc;
343
344 rc = WinGetMsg(GetThreadHAB(), &qmsg, TranslateWinMsg(uMsgFilterMin), TranslateWinMsg(uMsgFilterMax), 0);
345 OS2ToWinMsgTranslate(&qmsg, pMsg, isUnicode);
346 return rc;
347}
348//******************************************************************************
349//******************************************************************************
350LONG OSLibWinQueryWindowTextLength(HWND hwnd)
351{
352 return WinQueryWindowTextLength(hwnd);
353}
354//******************************************************************************
355//******************************************************************************
356LONG OSLibWinQueryWindowText(HWND hwnd, LONG length, LPSTR lpsz)
357{
358 return WinQueryWindowText(hwnd, length, lpsz);
359}
360//******************************************************************************
361//******************************************************************************
362BOOL OSLibWinSetWindowText(HWND hwnd, LPSTR lpsz)
363{
364 return WinSetWindowText(hwnd, lpsz);
365}
366//******************************************************************************
367//******************************************************************************
368BOOL OSLibWinFlashWindow(HWND hwnd, BOOL fFlash)
369{
370 return WinFlashWindow(hwnd, fFlash);
371}
372//******************************************************************************
373//******************************************************************************
374HWND OSLibWinWindowFromPoint(HWND hwnd, PVOID ppoint)
375{
376 return WinWindowFromPoint((hwnd == OSLIB_HWND_DESKTOP) ? HWND_DESKTOP : hwnd, (PPOINTL)ppoint, TRUE);
377}
378//******************************************************************************
379//******************************************************************************
380BOOL OSLibWinMinimizeWindow(HWND hwnd)
381{
382 return WinSetWindowPos(hwnd, 0, 0, 0, 0, 0, SWP_MINIMIZE);
383}
384//******************************************************************************
385//******************************************************************************
386
Note: See TracBrowser for help on using the repository browser.