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

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

* empty log message *

File size: 13.8 KB
Line 
1/* $Id: oslibwin.cpp,v 1.20 1999-07-26 09:01:34 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 == OSLIB_HWND_DESKTOP) {
51 hwndParent = HWND_DESKTOP;
52 }
53 if(Owner == OSLIB_HWND_DESKTOP) {
54 Owner = HWND_DESKTOP;
55 }
56
57 if(dwFrameStyle) {
58 dwWinStyle &= ~WS_CLIPCHILDREN; //invalid style according to docs
59 if(pszName)
60 dwFrameStyle |= FCF_TITLEBAR;
61
62 dwFrameStyle |= FCF_TASKLIST;
63 *hwndFrame = WinCreateStdWindow(hwndParent, dwWinStyle,
64 &dwFrameStyle, WIN32_STDCLASS,
65 "", 0, 0, 0, &hwndClient);
66 if(*hwndFrame) {
67 if(pszName) {
68 WinSetWindowText(*hwndFrame, pszName);
69 }
70 return hwndClient;
71 }
72 dprintf(("OSLibWinCreateWindow: WinCreateStdWindow failed (%x)", WinGetLastError(GetThreadHAB())));
73 return 0;
74 }
75 hwndClient = WinCreateWindow(hwndParent, WIN32_STDCLASS, pszName, dwWinStyle, 0, 0, 0, 0,
76 Owner, (fHWND_BOTTOM) ? HWND_BOTTOM :HWND_TOP, 0, NULL,
77 NULL);
78 *hwndFrame = hwndClient;
79 return hwndClient;
80}
81//******************************************************************************
82//******************************************************************************
83BOOL OSLibWinConvertStyle(ULONG dwStyle, ULONG dwExStyle, ULONG *OSWinStyle, ULONG *OSFrameStyle)
84{
85 *OSWinStyle = 0;
86 *OSFrameStyle = 0;
87
88 /* Window styles */
89 if(dwStyle & WINWS_MINIMIZE)
90 *OSWinStyle |= WS_MINIMIZED;
91//Done explicitely in CreateWindowExA
92#if 0
93 if(dwStyle & WINWS_VISIBLE)
94 *OSWinStyle |= WS_VISIBLE;
95#endif
96 if(dwStyle & WINWS_DISABLED)
97 *OSWinStyle |= WS_DISABLED;
98 if(dwStyle & WINWS_CLIPSIBLINGS)
99 *OSWinStyle |= WS_CLIPSIBLINGS;
100 if(dwStyle & WINWS_CLIPCHILDREN)
101 *OSWinStyle |= WS_CLIPCHILDREN;
102 if(dwStyle & WINWS_MAXIMIZE)
103 *OSWinStyle |= WS_MAXIMIZED;
104 if(dwStyle & WINWS_GROUP)
105 *OSWinStyle |= WS_GROUP;
106 if(dwStyle & WINWS_TABSTOP)
107 *OSWinStyle |= WS_TABSTOP;
108
109 if(dwStyle & WINWS_CAPTION)
110 *OSFrameStyle |= FCF_TITLEBAR;
111 if(dwStyle & WINWS_BORDER)
112 *OSFrameStyle |= FCF_BORDER;
113 if(dwStyle & WINWS_DLGFRAME)
114 *OSFrameStyle |= FCF_DLGBORDER;
115 if(dwStyle & WINWS_VSCROLL)
116 *OSFrameStyle |= FCF_VERTSCROLL;
117 if(dwStyle & WINWS_HSCROLL)
118 *OSFrameStyle |= FCF_HORZSCROLL;
119 if(dwStyle & WINWS_SYSMENU)
120 *OSFrameStyle |= FCF_SYSMENU;
121 if(dwStyle & WINWS_THICKFRAME)
122 *OSFrameStyle |= FCF_SIZEBORDER; //??
123 if(dwStyle & WINWS_MINIMIZEBOX)
124 *OSFrameStyle |= FCF_MINBUTTON;
125 if(dwStyle & WINWS_MAXIMIZEBOX)
126 *OSFrameStyle |= FCF_MAXBUTTON;
127
128 if(dwExStyle & WINWS_EX_DLGMODALFRAME)
129 *OSFrameStyle |= FCF_DLGBORDER;
130
131 return TRUE;
132}
133//******************************************************************************
134//******************************************************************************
135BOOL OSLibWinSetWindowULong(HWND hwnd, ULONG offset, ULONG value)
136{
137 return WinSetWindowULong(hwnd, offset, value);
138}
139//******************************************************************************
140//******************************************************************************
141ULONG OSLibWinGetWindowULong(HWND hwnd, ULONG offset)
142{
143 return WinQueryWindowULong(hwnd, offset);
144}
145//******************************************************************************
146//******************************************************************************
147BOOL OSLibPostMessage(HWND hwnd, ULONG msg, ULONG wParam, ULONG lParam)
148{
149 return WinPostMsg(hwnd, msg, (MPARAM)wParam, (MPARAM)lParam);
150}
151//******************************************************************************
152//******************************************************************************
153//******************************************************************************
154//******************************************************************************
155BOOL OSLibWinAlarm(HWND hwndDeskTop,ULONG flStyle)
156{
157 return WinAlarm(hwndDeskTop,flStyle);
158}
159//******************************************************************************
160//******************************************************************************
161APIRET OSLibDosBeep(ULONG freg,ULONG dur)
162{
163 return DosBeep(freg,dur);
164}
165//******************************************************************************
166//******************************************************************************
167HWND OSLibWinQueryFocus(HWND hwndDeskTop)
168{
169 return WinQueryFocus(hwndDeskTop);
170}
171//******************************************************************************
172//******************************************************************************
173HWND OSLibWinWindowFromID(HWND hwndParent,ULONG id)
174{
175 return WinWindowFromID(hwndParent,id);
176}
177//******************************************************************************
178//******************************************************************************
179BOOL OSLibWinSetFocus(HWND hwndDeskTop,HWND hwndNewFocus)
180{
181 return WinSetFocus(hwndDeskTop,hwndNewFocus);
182}
183//******************************************************************************
184//******************************************************************************
185ULONG OSLibGetWindowHeight(HWND hwnd)
186{
187 RECTL rect;
188
189 return (WinQueryWindowRect(hwnd,&rect)) ? rect.yTop-rect.yBottom:0;
190}
191//******************************************************************************
192//******************************************************************************
193LONG OSLibWinQuerySysValue(HWND hwndDeskTop,LONG iSysValue)
194{
195 return WinQuerySysValue(hwndDeskTop,iSysValue);
196}
197//******************************************************************************
198//******************************************************************************
199ULONG OSLibWinQueryDlgItemText(HWND hwndDlg,ULONG idItem,LONG cchBufferMax,char* pchBuffer)
200{
201 return WinQueryDlgItemText(hwndDlg,idItem,cchBufferMax,pchBuffer);
202}
203//******************************************************************************
204//******************************************************************************
205BOOL OSLibWinSetDlgItemText(HWND hwndDlg,ULONG idItem,char* pszText)
206{
207 return WinSetDlgItemText(hwndDlg,idItem,pszText);
208}
209//******************************************************************************
210//******************************************************************************
211BOOL OSLibWinQueryPointerPos(HWND hwndDeskTop,PPOINT pptlPoint)
212{
213 return WinQueryPointerPos(hwndDeskTop,(PPOINTL)pptlPoint);
214}
215//******************************************************************************
216//******************************************************************************
217HWND OSLibWinQueryWindow(HWND hwnd, ULONG lCode)
218{
219 return WinQueryWindow(hwnd, lCode);
220}
221//******************************************************************************
222//******************************************************************************
223BOOL OSLibWinSetWindowPos(HWND hwnd, HWND hwndInsertBehind, LONG x, LONG y, LONG cx,
224 LONG cy, ULONG fl)
225{
226 HWND hwndParent = hwndInsertBehind;
227 BOOL rc;
228
229 if(fl & SWP_MOVE) {
230 switch(hwndParent)
231 {
232 case HWNDOS_TOP:
233 case HWNDOS_BOTTOM:
234 hwndParent = HWND_DESKTOP;
235 break;
236 }
237 y = MapOS2ToWin32Y(hwndParent, cy, y);
238 }
239 rc = WinSetWindowPos(hwnd, hwndInsertBehind, x, y, cx, cy, fl);
240 dprintf(("WinSetWindowPos %x %x %d %d %d %d %x returned %d (%x)", hwnd, hwndInsertBehind, x, y, cx, cy, fl, rc, WinGetLastError(GetThreadHAB())));
241 return rc;
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//******************************************************************************
267BOOL OSLibWinQueryWindowRect(HWND hwnd, PRECT pRect, int RelativeTo)
268{
269 BOOL rc;
270 RECTLOS2 rectl;
271
272 rc = WinQueryWindowRect(hwnd, (PRECTL)&rectl);
273 if(rc) {
274 if(RelativeTo == RELATIVE_TO_SCREEN) {
275 MapOS2ToWin32Rectl(OSLIB_HWND_DESKTOP, hwnd, &rectl, pRect);
276 }
277 else MapOS2ToWin32Rectl(&rectl, pRect);
278 }
279 else memset(pRect, 0, sizeof(RECT));
280 return rc;
281}
282//******************************************************************************
283//******************************************************************************
284BOOL OSLibWinIsIconic(HWND hwnd)
285{
286 SWP swp;
287 BOOL rc;
288
289 rc = WinQueryWindowPos(hwnd, &swp);
290 if(rc == FALSE) {
291 dprintf(("OSLibWinIsIconic: WinQueryWindowPos %x failed", hwnd));
292 return FALSE;
293 }
294
295 if(swp.fl & SWP_MINIMIZE)
296 return TRUE;
297 else return FALSE;
298}
299//******************************************************************************
300//******************************************************************************
301BOOL OSLibWinSetActiveWindow(HWND hwnd)
302{
303 return WinSetActiveWindow(HWND_DESKTOP, hwnd);
304}
305//******************************************************************************
306//******************************************************************************
307BOOL OSLibWinSetFocus(HWND hwnd)
308{
309 return WinSetFocus(HWND_DESKTOP, hwnd);
310}
311//******************************************************************************
312//******************************************************************************
313BOOL OSLibWinEnableWindow(HWND hwnd, BOOL fEnable)
314{
315 return WinEnableWindow(hwnd, fEnable);
316}
317//******************************************************************************
318//******************************************************************************
319BOOL OSLibWinIsWindowEnabled(HWND hwnd)
320{
321 return WinIsWindowEnabled(hwnd);
322}
323//******************************************************************************
324//******************************************************************************
325BOOL OSLibWinIsWindowVisible(HWND hwnd)
326{
327 return WinIsWindowVisible(hwnd);
328}
329//******************************************************************************
330//******************************************************************************
331BOOL OSLibWinQueryActiveWindow()
332{
333 return WinQueryActiveWindow(HWND_DESKTOP);
334}
335//******************************************************************************
336//******************************************************************************
337LONG OSLibWinQueryWindowTextLength(HWND hwnd)
338{
339 return WinQueryWindowTextLength(hwnd);
340}
341//******************************************************************************
342//******************************************************************************
343LONG OSLibWinQueryWindowText(HWND hwnd, LONG length, LPSTR lpsz)
344{
345 return WinQueryWindowText(hwnd, length, lpsz);
346}
347//******************************************************************************
348//******************************************************************************
349BOOL OSLibWinSetWindowText(HWND hwnd, LPSTR lpsz)
350{
351 return WinSetWindowText(hwnd, lpsz);
352}
353//******************************************************************************
354//******************************************************************************
355BOOL OSLibWinFlashWindow(HWND hwnd, BOOL fFlash)
356{
357 return WinFlashWindow(hwnd, fFlash);
358}
359//******************************************************************************
360//******************************************************************************
361HWND OSLibWinWindowFromPoint(HWND hwnd, PVOID ppoint)
362{
363 return WinWindowFromPoint((hwnd == OSLIB_HWND_DESKTOP) ? HWND_DESKTOP : hwnd, (PPOINTL)ppoint, TRUE);
364}
365//******************************************************************************
366//******************************************************************************
367BOOL OSLibWinMinimizeWindow(HWND hwnd)
368{
369 return WinSetWindowPos(hwnd, 0, 0, 0, 0, 0, SWP_MINIMIZE);
370}
371//******************************************************************************
372//******************************************************************************
373
Note: See TracBrowser for help on using the repository browser.