1 | /* $Id: oslibwin.cpp,v 1.9 1999-07-17 18:30:51 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 "pmwindow.h"
|
---|
25 |
|
---|
26 | //******************************************************************************
|
---|
27 | //******************************************************************************
|
---|
28 | BOOL OSLibWinSetParent(HWND hwnd, HWND hwndParent, ULONG fRedraw)
|
---|
29 | {
|
---|
30 | if(hwndParent == OSLIB_HWND_DESKTOP)
|
---|
31 | {
|
---|
32 | hwndParent = HWND_DESKTOP;
|
---|
33 | }
|
---|
34 |
|
---|
35 | return (WinSetParent(hwnd, hwndParent, fRedraw) == 0);
|
---|
36 | }
|
---|
37 | //******************************************************************************
|
---|
38 | //******************************************************************************
|
---|
39 | HWND OSLibWinCreateWindow(HWND hwndParent, ULONG dwWinStyle, ULONG dwFrameStyle,
|
---|
40 | char *pszName, HWND Owner, ULONG fHWND_BOTTOM, HWND *hwndFrame)
|
---|
41 | {
|
---|
42 | HWND hwndClient;
|
---|
43 | RECTL rectl;
|
---|
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 | *hwndFrame = WinCreateStdWindow(hwndParent, dwWinStyle,
|
---|
56 | &dwFrameStyle, WIN32_STDCLASS,
|
---|
57 | "", 0, 0, 0, &hwndClient) != 0;
|
---|
58 | if(*hwndFrame) {
|
---|
59 | if(pszName) {
|
---|
60 | WinSetWindowText(*hwndFrame, pszName);
|
---|
61 | }
|
---|
62 | return hwndClient;
|
---|
63 | }
|
---|
64 | dprintf(("OSLibWinCreateWindow: WinCreateStdWindow failed (%x)", WinGetLastError(GetThreadHAB())));
|
---|
65 | return 0;
|
---|
66 | }
|
---|
67 | hwndClient = WinCreateWindow(hwndParent, WIN32_STDCLASS, pszName, dwWinStyle, 0, 0, 0, 0,
|
---|
68 | Owner, (fHWND_BOTTOM) ? HWND_BOTTOM :HWND_TOP, 0, NULL,
|
---|
69 | NULL);
|
---|
70 | *hwndFrame = hwndClient;
|
---|
71 | return hwndClient;
|
---|
72 | }
|
---|
73 | //******************************************************************************
|
---|
74 | //******************************************************************************
|
---|
75 | BOOL OSLibWinConvertStyle(ULONG dwStyle, ULONG *OSWinStyle, ULONG *OSFrameStyle)
|
---|
76 | {
|
---|
77 | *OSWinStyle = 0;
|
---|
78 | *OSFrameStyle = 0;
|
---|
79 |
|
---|
80 | /* Window styles */
|
---|
81 | if(dwStyle & WINWS_MINIMIZE)
|
---|
82 | *OSWinStyle |= WS_MINIMIZED;
|
---|
83 | //Done explicitely in CreateWindowExA
|
---|
84 | #if 0
|
---|
85 | if(dwStyle & WINWS_VISIBLE)
|
---|
86 | *OSWinStyle |= WS_VISIBLE;
|
---|
87 | #endif
|
---|
88 | if(dwStyle & WINWS_DISABLED)
|
---|
89 | *OSWinStyle |= WS_DISABLED;
|
---|
90 | if(dwStyle & WINWS_CLIPSIBLINGS)
|
---|
91 | *OSWinStyle |= WS_CLIPSIBLINGS;
|
---|
92 | if(dwStyle & WINWS_CLIPCHILDREN)
|
---|
93 | *OSWinStyle |= WS_CLIPCHILDREN;
|
---|
94 | if(dwStyle & WINWS_MAXIMIZE)
|
---|
95 | *OSWinStyle |= WS_MAXIMIZED;
|
---|
96 | if(dwStyle & WINWS_GROUP)
|
---|
97 | *OSWinStyle |= WS_GROUP;
|
---|
98 | if(dwStyle & WINWS_TABSTOP)
|
---|
99 | *OSWinStyle |= WS_TABSTOP;
|
---|
100 |
|
---|
101 | if(dwStyle & WINWS_CAPTION)
|
---|
102 | *OSFrameStyle |= FCF_TITLEBAR;
|
---|
103 | if(dwStyle & WINWS_BORDER)
|
---|
104 | *OSFrameStyle |= FCF_BORDER;
|
---|
105 | if(dwStyle & WINWS_DLGFRAME)
|
---|
106 | *OSFrameStyle |= FCF_DLGBORDER;
|
---|
107 | if(dwStyle & WINWS_VSCROLL)
|
---|
108 | *OSFrameStyle |= FCF_VERTSCROLL;
|
---|
109 | if(dwStyle & WINWS_HSCROLL)
|
---|
110 | *OSFrameStyle |= FCF_HORZSCROLL;
|
---|
111 | if(dwStyle & WINWS_SYSMENU)
|
---|
112 | *OSFrameStyle |= FCF_SYSMENU;
|
---|
113 | if(dwStyle & WINWS_THICKFRAME)
|
---|
114 | *OSFrameStyle |= FCF_SIZEBORDER; //??
|
---|
115 | if(dwStyle & WINWS_MINIMIZEBOX)
|
---|
116 | *OSFrameStyle |= FCF_MINBUTTON;
|
---|
117 | if(dwStyle & WINWS_MAXIMIZEBOX)
|
---|
118 | *OSFrameStyle |= FCF_MAXBUTTON;
|
---|
119 |
|
---|
120 | return TRUE;
|
---|
121 | }
|
---|
122 | //******************************************************************************
|
---|
123 | //******************************************************************************
|
---|
124 | BOOL OSLibWinSetWindowULong(HWND hwnd, ULONG offset, ULONG value)
|
---|
125 | {
|
---|
126 | return WinSetWindowULong(hwnd, offset, value);
|
---|
127 | }
|
---|
128 | //******************************************************************************
|
---|
129 | //******************************************************************************
|
---|
130 | ULONG OSLibWinGetWindowULong(HWND hwnd, ULONG offset)
|
---|
131 | {
|
---|
132 | return WinQueryWindowULong(hwnd, offset);
|
---|
133 | }
|
---|
134 | //******************************************************************************
|
---|
135 | //******************************************************************************
|
---|
136 | BOOL OSLibPostMessage(HWND hwnd, ULONG msg, ULONG wParam, ULONG lParam)
|
---|
137 | {
|
---|
138 | return WinPostMsg(hwnd, msg, (MPARAM)wParam, (MPARAM)lParam);
|
---|
139 | }
|
---|
140 | //******************************************************************************
|
---|
141 | //******************************************************************************
|
---|
142 | HWND OSLibWinCreateMenu(HWND hwndParent, PVOID menutemplate)
|
---|
143 | {
|
---|
144 | return WinCreateMenu(hwndParent, menutemplate);
|
---|
145 | }
|
---|
146 | //******************************************************************************
|
---|
147 | //******************************************************************************
|
---|
148 | BOOL OSLibWinAlarm(HWND hwndDeskTop,ULONG flStyle)
|
---|
149 | {
|
---|
150 | return WinAlarm(hwndDeskTop,flStyle);
|
---|
151 | }
|
---|
152 | //******************************************************************************
|
---|
153 | //******************************************************************************
|
---|
154 | APIRET OSLibDosBeep(ULONG freg,ULONG dur)
|
---|
155 | {
|
---|
156 | return DosBeep(freg,dur);
|
---|
157 | }
|
---|
158 | //******************************************************************************
|
---|
159 | //******************************************************************************
|
---|
160 | LONG OSLibWinQueryWindowTextLength(HWND hwnd)
|
---|
161 | {
|
---|
162 | return WinQueryWindowTextLength(hwnd);
|
---|
163 | }
|
---|
164 | //******************************************************************************
|
---|
165 | //******************************************************************************
|
---|
166 | LONG OSLibWinQueryWindowText(HWND hwnd,LONG lLength,char* pun)
|
---|
167 | {
|
---|
168 | return WinQueryWindowText(hwnd,lLength,pun);
|
---|
169 | }
|
---|
170 | //******************************************************************************
|
---|
171 | //******************************************************************************
|
---|
172 | HWND OSLibWinQueryWindow(HWND hwnd, ULONG lCode)
|
---|
173 | {
|
---|
174 | return WinQueryWindow(hwnd, lCode);
|
---|
175 | }
|
---|
176 | //******************************************************************************
|
---|
177 | //******************************************************************************
|
---|
178 | BOOL OSLibWinSetWindowPos(HWND hwnd, HWND hwndInsertBehind, LONG x, LONG y, LONG cx,
|
---|
179 | LONG cy, ULONG fl)
|
---|
180 | {
|
---|
181 | RECTL rectl;
|
---|
182 | HWND hwndParent;
|
---|
183 |
|
---|
184 | if(fl & SWP_MOVE) {
|
---|
185 | y = MapOS2ToWin32Y(hwnd, y);
|
---|
186 | }
|
---|
187 | return WinSetWindowPos(hwnd, hwndInsertBehind, x, y, cx, cy, fl);
|
---|
188 | }
|
---|
189 | //******************************************************************************
|
---|
190 | //******************************************************************************
|
---|
191 | BOOL OSLibWinShowWindow(HWND hwnd, ULONG fl)
|
---|
192 | {
|
---|
193 | BOOL rc;
|
---|
194 |
|
---|
195 | if(fl & SWP_SHOW) {
|
---|
196 | rc = WinShowWindow(hwnd, TRUE);
|
---|
197 | }
|
---|
198 | if(rc == 0)
|
---|
199 | dprintf(("WinShowWindow %x failed %x", hwnd, WinGetLastError(GetThreadHAB())));
|
---|
200 | rc = WinSetWindowPos(hwnd, 0, 0, 0, 0, 0, fl);
|
---|
201 | if(rc == 0)
|
---|
202 | dprintf(("WinShowWindow %x failed %x", hwnd, WinGetLastError(GetThreadHAB())));
|
---|
203 | return rc;
|
---|
204 | }
|
---|
205 | //******************************************************************************
|
---|
206 | //******************************************************************************
|
---|
207 | BOOL OSLibWinDestroyWindow(HWND hwnd)
|
---|
208 | {
|
---|
209 | return WinDestroyWindow(hwnd);
|
---|
210 | }
|
---|
211 | //******************************************************************************
|
---|
212 | //******************************************************************************
|
---|
213 | BOOL OSLibWinQueryUpdateRect(HWND hwnd, PVOID pRect)
|
---|
214 | {
|
---|
215 | return WinQueryUpdateRect(hwnd, (RECTL *)pRect);
|
---|
216 | }
|
---|
217 | //******************************************************************************
|
---|
218 | //******************************************************************************
|
---|
219 | BOOL OSLibWinIsIconic(HWND hwnd)
|
---|
220 | {
|
---|
221 | SWP swp;
|
---|
222 | BOOL rc;
|
---|
223 |
|
---|
224 | rc = WinQueryWindowPos(hwnd, &swp);
|
---|
225 | if(rc == FALSE) {
|
---|
226 | dprintf(("OSLibWinIsIconic: WinQueryWindowPos %x failed", hwnd));
|
---|
227 | return FALSE;
|
---|
228 | }
|
---|
229 |
|
---|
230 | if(swp.fl & SWP_MINIMIZE)
|
---|
231 | return TRUE;
|
---|
232 | else return FALSE;
|
---|
233 | }
|
---|
234 | //******************************************************************************
|
---|
235 | //******************************************************************************
|
---|
236 | BOOL OSLibWinSetActiveWindow(HWND hwnd)
|
---|
237 | {
|
---|
238 | return WinSetActiveWindow(HWND_DESKTOP, hwnd);
|
---|
239 | }
|
---|
240 | //******************************************************************************
|
---|
241 | //******************************************************************************
|
---|
242 | BOOL OSLibWinSetFocus(HWND hwnd)
|
---|
243 | {
|
---|
244 | return WinSetFocus(HWND_DESKTOP, hwnd);
|
---|
245 | }
|
---|
246 | //******************************************************************************
|
---|
247 | //******************************************************************************
|
---|
248 | BOOL OSLibWinEnableWindow(HWND hwnd, BOOL fEnable)
|
---|
249 | {
|
---|
250 | return WinEnableWindow(hwnd, fEnable);
|
---|
251 | }
|
---|
252 | //******************************************************************************
|
---|
253 | //******************************************************************************
|
---|
254 | BOOL OSLibWinIsWindowEnabled(HWND hwnd)
|
---|
255 | {
|
---|
256 | return WinIsWindowEnabled(hwnd);
|
---|
257 | }
|
---|
258 | //******************************************************************************
|
---|
259 | //******************************************************************************
|
---|
260 | BOOL OSLibWinIsWindowVisible(HWND hwnd)
|
---|
261 | {
|
---|
262 | return WinIsWindowVisible(hwnd);
|
---|
263 | }
|
---|
264 | //******************************************************************************
|
---|
265 | //******************************************************************************
|
---|
266 | BOOL OSLibWinQueryActiveWindow()
|
---|
267 | {
|
---|
268 | return WinQueryActiveWindow(HWND_DESKTOP);
|
---|
269 | }
|
---|
270 | //******************************************************************************
|
---|
271 | //******************************************************************************
|
---|
272 | void OSLibWinPostQuitMessage(ULONG nExitCode)
|
---|
273 | {
|
---|
274 | WinPostQueueMsg(GetThreadMessageQueue(), WM_QUIT, (MPARAM)nExitCode, 0);
|
---|
275 | }
|
---|
276 | //******************************************************************************
|
---|
277 | //******************************************************************************
|
---|
278 | LONG OSLibWinDispatchMsg(MSG *msg, BOOL isUnicode)
|
---|
279 | {
|
---|
280 | QMSG qmsg;
|
---|
281 |
|
---|
282 | WinToOS2MsgTranslate(msg, &qmsg, isUnicode);
|
---|
283 | return (LONG)WinDispatchMsg(GetThreadHAB(), &qmsg);
|
---|
284 | }
|
---|
285 | //******************************************************************************
|
---|
286 | //******************************************************************************
|
---|
287 | BOOL OSLibWinGetMsg(LPMSG pMsg, HWND hwnd, UINT uMsgFilterMin, UINT uMsgFilterMax, BOOL isUnicode)
|
---|
288 | {
|
---|
289 | QMSG qmsg;
|
---|
290 | BOOL rc;
|
---|
291 |
|
---|
292 | rc = WinGetMsg(GetThreadHAB(), &qmsg, TranslateWinMsg(uMsgFilterMin), TranslateWinMsg(uMsgFilterMax), 0);
|
---|
293 | OS2ToWinMsgTranslate(&qmsg, pMsg, isUnicode);
|
---|
294 | return rc;
|
---|
295 | }
|
---|
296 | //******************************************************************************
|
---|
297 | //******************************************************************************
|
---|
298 | inline ULONG OS2TOWIN32POINT(RECTL *parent, RECTL *child, ULONG y)
|
---|
299 | {
|
---|
300 | return (parent->yTop - parent->yBottom - (child->yTop - child->yBottom) - y - 1);
|
---|
301 | }
|
---|
302 | //******************************************************************************
|
---|
303 | //******************************************************************************
|
---|
304 | ULONG MapOS2ToWin32Y(HWND hwndChild)
|
---|
305 | {
|
---|
306 | HWND hwndParent;
|
---|
307 | RECTL rectParent = {0}, rectChild = {0};
|
---|
308 |
|
---|
309 | WinQueryWindowRect(hwndChild, &rectChild);
|
---|
310 | hwndParent = WinQueryWindow(hwndChild, QW_PARENT);
|
---|
311 | WinQueryWindowRect(hwndParent, &rectParent);
|
---|
312 | return OS2TOWIN32POINT(&rectParent, &rectChild, rectChild.yBottom);
|
---|
313 | }
|
---|
314 | //******************************************************************************
|
---|
315 | //******************************************************************************
|
---|
316 | ULONG MapOS2ToWin32Y(HWND hwndChild, ULONG y)
|
---|
317 | {
|
---|
318 | HWND hwndParent;
|
---|
319 | RECTL rectParent = {0}, rectChild = {0};
|
---|
320 |
|
---|
321 | WinQueryWindowRect(hwndChild, &rectChild);
|
---|
322 | hwndParent = WinQueryWindow(hwndChild, QW_PARENT);
|
---|
323 | WinQueryWindowRect(hwndParent, &rectParent);
|
---|
324 | return OS2TOWIN32POINT(&rectParent, &rectChild, y);
|
---|
325 | }
|
---|
326 | //******************************************************************************
|
---|
327 | //******************************************************************************
|
---|
328 | ULONG MapOS2ToWin32Y(PRECTL rectParent, PRECTL rectChild, ULONG y)
|
---|
329 | {
|
---|
330 | return OS2TOWIN32POINT(rectParent, rectChild, y);
|
---|
331 | }
|
---|
332 | //******************************************************************************
|
---|
333 | //******************************************************************************
|
---|
334 | ULONG MapOS2ToWin32Y(PRECTL rectParent, HWND hwndChild, ULONG y)
|
---|
335 | {
|
---|
336 | RECTL rectChild = {0};
|
---|
337 |
|
---|
338 | WinQueryWindowRect(hwndChild, &rectChild);
|
---|
339 | return OS2TOWIN32POINT(rectParent, &rectChild, y);
|
---|
340 | }
|
---|
341 | //******************************************************************************
|
---|
342 | //******************************************************************************
|
---|
343 | ULONG MapOS2ToWin32Y(HWND hwndChild, PRECTL rectChild, ULONG y)
|
---|
344 | {
|
---|
345 | HWND hwndParent;
|
---|
346 | RECTL rectParent = {0};
|
---|
347 |
|
---|
348 | hwndParent = WinQueryWindow(hwndChild, QW_PARENT);
|
---|
349 | WinQueryWindowRect(hwndParent, &rectParent);
|
---|
350 | return OS2TOWIN32POINT(&rectParent, rectChild, y);
|
---|
351 | }
|
---|
352 | //******************************************************************************
|
---|
353 | //******************************************************************************
|
---|