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

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

Accelerator support (not working) + bugfixes

File size: 14.3 KB
Line 
1/* $Id: oslibwin.cpp,v 1.17 1999-07-20 07:42:35 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 OSLibWinSetAccelTable(HWND hwnd, PVOID acceltemplate)
152{
153 HACCEL haccel;
154 HAB hab = WinQueryAnchorBlock(hwnd);
155
156 haccel = WinCreateAccelTable(hab, (PACCELTABLE)acceltemplate);
157 if(haccel == 0) {
158 dprintf(("OSLibWinSetAccelTable: WinCreateAccelTable returned 0"));
159 return FALSE;
160 }
161 return WinSetAccelTable(hab, haccel, hwnd);
162}
163//******************************************************************************
164//******************************************************************************
165BOOL OSLibWinAlarm(HWND hwndDeskTop,ULONG flStyle)
166{
167 return WinAlarm(hwndDeskTop,flStyle);
168}
169//******************************************************************************
170//******************************************************************************
171APIRET OSLibDosBeep(ULONG freg,ULONG dur)
172{
173 return DosBeep(freg,dur);
174}
175//******************************************************************************
176//******************************************************************************
177HWND OSLibWinQueryFocus(HWND hwndDeskTop)
178{
179 return WinQueryFocus(hwndDeskTop);
180}
181//******************************************************************************
182//******************************************************************************
183HWND OSLibWinWindowFromID(HWND hwndParent,ULONG id)
184{
185 return WinWindowFromID(hwndParent,id);
186}
187//******************************************************************************
188//******************************************************************************
189BOOL OSLibWinSetFocus(HWND hwndDeskTop,HWND hwndNewFocus)
190{
191 return WinSetFocus(hwndDeskTop,hwndNewFocus);
192}
193//******************************************************************************
194//******************************************************************************
195ULONG OSLibGetWindowHeight(HWND hwnd)
196{
197 RECTL rect;
198
199 return (WinQueryWindowRect(hwnd,&rect)) ? rect.yTop-rect.yBottom:0;
200}
201//******************************************************************************
202//******************************************************************************
203BOOL OSLibWinInvalidateRect(HWND hwnd,POSRECTL pwrc,BOOL fIncludeChildren)
204{
205 return WinInvalidateRect(hwnd,(PRECTL)pwrc,fIncludeChildren);
206}
207//******************************************************************************
208//******************************************************************************
209LONG OSLibWinQuerySysValue(HWND hwndDeskTop,LONG iSysValue)
210{
211 return WinQuerySysValue(hwndDeskTop,iSysValue);
212}
213//******************************************************************************
214//******************************************************************************
215ULONG OSLibWinQueryDlgItemText(HWND hwndDlg,ULONG idItem,LONG cchBufferMax,char* pchBuffer)
216{
217 return WinQueryDlgItemText(hwndDlg,idItem,cchBufferMax,pchBuffer);
218}
219//******************************************************************************
220//******************************************************************************
221BOOL OSLibWinSetDlgItemText(HWND hwndDlg,ULONG idItem,char* pszText)
222{
223 return WinSetDlgItemText(hwndDlg,idItem,pszText);
224}
225//******************************************************************************
226//******************************************************************************
227BOOL OSLibWinQueryPointerPos(HWND hwndDeskTop,PPOINT pptlPoint)
228{
229 return WinQueryPointerPos(hwndDeskTop,(PPOINTL)pptlPoint);
230}
231//******************************************************************************
232//******************************************************************************
233HWND OSLibWinQueryWindow(HWND hwnd, ULONG lCode)
234{
235 return WinQueryWindow(hwnd, lCode);
236}
237//******************************************************************************
238//******************************************************************************
239BOOL OSLibWinSetWindowPos(HWND hwnd, HWND hwndInsertBehind, LONG x, LONG y, LONG cx,
240 LONG cy, ULONG fl)
241{
242 HWND hwndParent = hwndInsertBehind;
243
244 if(fl & SWP_MOVE) {
245 switch(hwndParent)
246 {
247 case HWNDOS_TOP:
248 case HWNDOS_BOTTOM:
249 hwndParent = HWND_DESKTOP;
250 break;
251 }
252 y = MapOS2ToWin32Y(hwndParent, cy, y);
253 }
254 dprintf(("WinSetWindowPos %x %x %d %d %d %d %x", hwnd, hwndInsertBehind, x, y, cx, cy, fl));
255 return WinSetWindowPos(hwnd, hwndInsertBehind, x, y, cx, cy, fl);
256}
257//******************************************************************************
258//******************************************************************************
259BOOL OSLibWinShowWindow(HWND hwnd, ULONG fl)
260{
261 BOOL rc;
262
263 if(fl & SWP_SHOW) {
264 rc = WinShowWindow(hwnd, TRUE);
265 }
266 if(rc == 0)
267 dprintf(("WinShowWindow %x failed %x", hwnd, WinGetLastError(GetThreadHAB())));
268 rc = WinSetWindowPos(hwnd, HWND_TOP, 0, 0, 0, 0, fl);
269 if(rc == 0)
270 dprintf(("WinShowWindow %x failed %x", hwnd, WinGetLastError(GetThreadHAB())));
271 return rc;
272}
273//******************************************************************************
274//******************************************************************************
275BOOL OSLibWinDestroyWindow(HWND hwnd)
276{
277 return WinDestroyWindow(hwnd);
278}
279//******************************************************************************
280//Returns rectangle in Win32 window coordinates
281//******************************************************************************
282BOOL OSLibWinQueryUpdateRect(HWND hwnd, PVOID pRect)
283{
284 BOOL rc;
285 RECTLOS2 rectl;
286
287 rc = WinQueryUpdateRect(hwnd, (PRECTL)&rectl);
288 if(rc) {
289 MapOS2ToWin32Rectl(&rectl, (PRECT)pRect);
290 }
291 else memset(pRect, 0, sizeof(RECT));
292 return rc;
293}
294//******************************************************************************
295//******************************************************************************
296BOOL OSLibWinIsIconic(HWND hwnd)
297{
298 SWP swp;
299 BOOL rc;
300
301 rc = WinQueryWindowPos(hwnd, &swp);
302 if(rc == FALSE) {
303 dprintf(("OSLibWinIsIconic: WinQueryWindowPos %x failed", hwnd));
304 return FALSE;
305 }
306
307 if(swp.fl & SWP_MINIMIZE)
308 return TRUE;
309 else return FALSE;
310}
311//******************************************************************************
312//******************************************************************************
313BOOL OSLibWinSetActiveWindow(HWND hwnd)
314{
315 return WinSetActiveWindow(HWND_DESKTOP, hwnd);
316}
317//******************************************************************************
318//******************************************************************************
319BOOL OSLibWinSetFocus(HWND hwnd)
320{
321 return WinSetFocus(HWND_DESKTOP, hwnd);
322}
323//******************************************************************************
324//******************************************************************************
325BOOL OSLibWinEnableWindow(HWND hwnd, BOOL fEnable)
326{
327 return WinEnableWindow(hwnd, fEnable);
328}
329//******************************************************************************
330//******************************************************************************
331BOOL OSLibWinIsWindowEnabled(HWND hwnd)
332{
333 return WinIsWindowEnabled(hwnd);
334}
335//******************************************************************************
336//******************************************************************************
337BOOL OSLibWinIsWindowVisible(HWND hwnd)
338{
339 return WinIsWindowVisible(hwnd);
340}
341//******************************************************************************
342//******************************************************************************
343BOOL OSLibWinQueryActiveWindow()
344{
345 return WinQueryActiveWindow(HWND_DESKTOP);
346}
347//******************************************************************************
348//******************************************************************************
349LONG OSLibWinQueryWindowTextLength(HWND hwnd)
350{
351 return WinQueryWindowTextLength(hwnd);
352}
353//******************************************************************************
354//******************************************************************************
355LONG OSLibWinQueryWindowText(HWND hwnd, LONG length, LPSTR lpsz)
356{
357 return WinQueryWindowText(hwnd, length, lpsz);
358}
359//******************************************************************************
360//******************************************************************************
361BOOL OSLibWinSetWindowText(HWND hwnd, LPSTR lpsz)
362{
363 return WinSetWindowText(hwnd, lpsz);
364}
365//******************************************************************************
366//******************************************************************************
367BOOL OSLibWinFlashWindow(HWND hwnd, BOOL fFlash)
368{
369 return WinFlashWindow(hwnd, fFlash);
370}
371//******************************************************************************
372//******************************************************************************
373HWND OSLibWinWindowFromPoint(HWND hwnd, PVOID ppoint)
374{
375 return WinWindowFromPoint((hwnd == OSLIB_HWND_DESKTOP) ? HWND_DESKTOP : hwnd, (PPOINTL)ppoint, TRUE);
376}
377//******************************************************************************
378//******************************************************************************
379BOOL OSLibWinMinimizeWindow(HWND hwnd)
380{
381 return WinSetWindowPos(hwnd, 0, 0, 0, 0, 0, SWP_MINIMIZE);
382}
383//******************************************************************************
384//******************************************************************************
385
Note: See TracBrowser for help on using the repository browser.