1 | /* $Id: oslibwin.cpp,v 1.7 1999-07-17 12:49:40 cbratschi 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, ULONG x, ULONG y, ULONG cx, ULONG cy,
|
---|
41 | HWND Owner, ULONG fHWND_BOTTOM, HWND *hwndFrame)
|
---|
42 | {
|
---|
43 | HWND hwndClient;
|
---|
44 | RECTL rectl;
|
---|
45 |
|
---|
46 | if(hwndParent == 0) {
|
---|
47 | hwndParent = HWND_DESKTOP;
|
---|
48 | }
|
---|
49 | if(WinQueryWindowRect(hwndParent, &rectl) == TRUE) {
|
---|
50 | y = OS2TOWIN32POINT(rectl.yTop - rectl.yBottom, y);
|
---|
51 | }
|
---|
52 | if(dwFrameStyle) {
|
---|
53 | dwWinStyle &= ~WS_CLIPCHILDREN; //invalid style according to docs
|
---|
54 | *hwndFrame = WinCreateStdWindow(hwndParent, dwWinStyle,
|
---|
55 | &dwFrameStyle, WIN32_STDCLASS,
|
---|
56 | "", 0, 0, 0, &hwndClient) != 0;
|
---|
57 | if(*hwndFrame) {
|
---|
58 | if(pszName) {
|
---|
59 | WinSetWindowText(*hwndFrame, pszName);
|
---|
60 | }
|
---|
61 | WinSetWindowPos(*hwndFrame, (fHWND_BOTTOM) ? HWND_BOTTOM :HWND_TOP,
|
---|
62 | x, y, cx, cy, SWP_SIZE | SWP_MOVE);
|
---|
63 |
|
---|
64 | return hwndClient;
|
---|
65 | }
|
---|
66 | dprintf(("OSLibWinCreateWindow: WinCreateStdWindow failed (%x)", WinGetLastError(GetThreadHAB())));
|
---|
67 | return 0;
|
---|
68 | }
|
---|
69 | hwndClient = WinCreateWindow(hwndParent, WIN32_STDCLASS, pszName, dwWinStyle, x, y, cx, cy,
|
---|
70 | Owner, (fHWND_BOTTOM) ? HWND_BOTTOM :HWND_TOP, 0, NULL,
|
---|
71 | NULL);
|
---|
72 | *hwndFrame = hwndClient;
|
---|
73 | return hwndClient;
|
---|
74 | }
|
---|
75 | //******************************************************************************
|
---|
76 | //******************************************************************************
|
---|
77 | BOOL OSLibWinConvertStyle(ULONG dwStyle, ULONG *OSWinStyle, ULONG *OSFrameStyle)
|
---|
78 | {
|
---|
79 | *OSWinStyle = 0;
|
---|
80 | *OSFrameStyle = 0;
|
---|
81 |
|
---|
82 | /* Window styles */
|
---|
83 | if(dwStyle & WINWS_MINIMIZE)
|
---|
84 | *OSWinStyle |= WS_MINIMIZED;
|
---|
85 | if(dwStyle & WINWS_VISIBLE)
|
---|
86 | *OSWinStyle |= WS_VISIBLE;
|
---|
87 | if(dwStyle & WINWS_DISABLED)
|
---|
88 | *OSWinStyle |= WS_DISABLED;
|
---|
89 | if(dwStyle & WINWS_CLIPSIBLINGS)
|
---|
90 | *OSWinStyle |= WS_CLIPSIBLINGS;
|
---|
91 | if(dwStyle & WINWS_CLIPCHILDREN)
|
---|
92 | *OSWinStyle |= WS_CLIPCHILDREN;
|
---|
93 | if(dwStyle & WINWS_MAXIMIZE)
|
---|
94 | *OSWinStyle |= WS_MAXIMIZED;
|
---|
95 | if(dwStyle & WINWS_GROUP)
|
---|
96 | *OSWinStyle |= WS_GROUP;
|
---|
97 | if(dwStyle & WINWS_TABSTOP)
|
---|
98 | *OSWinStyle |= WS_TABSTOP;
|
---|
99 |
|
---|
100 | if(dwStyle & WINWS_CAPTION)
|
---|
101 | *OSFrameStyle |= FCF_TITLEBAR;
|
---|
102 | if(dwStyle & WINWS_BORDER)
|
---|
103 | *OSFrameStyle |= FCF_BORDER;
|
---|
104 | if(dwStyle & WINWS_DLGFRAME)
|
---|
105 | *OSFrameStyle |= FCF_DLGBORDER;
|
---|
106 | if(dwStyle & WINWS_VSCROLL)
|
---|
107 | *OSFrameStyle |= FCF_VERTSCROLL;
|
---|
108 | if(dwStyle & WINWS_HSCROLL)
|
---|
109 | *OSFrameStyle |= FCF_HORZSCROLL;
|
---|
110 | if(dwStyle & WINWS_SYSMENU)
|
---|
111 | *OSFrameStyle |= FCF_SYSMENU;
|
---|
112 | if(dwStyle & WINWS_THICKFRAME)
|
---|
113 | *OSFrameStyle |= FCF_SIZEBORDER; //??
|
---|
114 | if(dwStyle & WINWS_MINIMIZEBOX)
|
---|
115 | *OSFrameStyle |= FCF_MINBUTTON;
|
---|
116 | if(dwStyle & WINWS_MAXIMIZEBOX)
|
---|
117 | *OSFrameStyle |= FCF_MAXBUTTON;
|
---|
118 |
|
---|
119 | return TRUE;
|
---|
120 | }
|
---|
121 | //******************************************************************************
|
---|
122 | //******************************************************************************
|
---|
123 | BOOL OSLibWinSetWindowULong(HWND hwnd, ULONG offset, ULONG value)
|
---|
124 | {
|
---|
125 | return WinSetWindowULong(hwnd, offset, value);
|
---|
126 | }
|
---|
127 | //******************************************************************************
|
---|
128 | //******************************************************************************
|
---|
129 | ULONG OSLibWinGetWindowULong(HWND hwnd, ULONG offset)
|
---|
130 | {
|
---|
131 | return WinQueryWindowULong(hwnd, offset);
|
---|
132 | }
|
---|
133 | //******************************************************************************
|
---|
134 | //******************************************************************************
|
---|
135 | BOOL OSLibPostMessage(HWND hwnd, ULONG msg, ULONG wParam, ULONG lParam)
|
---|
136 | {
|
---|
137 | return WinPostMsg(hwnd, msg, (MPARAM)wParam, (MPARAM)lParam);
|
---|
138 | }
|
---|
139 | //******************************************************************************
|
---|
140 | //******************************************************************************
|
---|
141 | HWND OSLibWinCreateMenu(HWND hwndParent, PVOID menutemplate)
|
---|
142 | {
|
---|
143 | return WinCreateMenu(hwndParent, menutemplate);
|
---|
144 | }
|
---|
145 | //******************************************************************************
|
---|
146 | //******************************************************************************
|
---|
147 | BOOL OSLibWinAlarm(HWND hwndDeskTop,ULONG flStyle)
|
---|
148 | {
|
---|
149 | return WinAlarm(hwndDeskTop,flStyle);
|
---|
150 | }
|
---|
151 | //******************************************************************************
|
---|
152 | //******************************************************************************
|
---|
153 | APIRET OSLibDosBeep(ULONG freg,ULONG dur)
|
---|
154 | {
|
---|
155 | return DosBeep(freg,dur);
|
---|
156 | }
|
---|
157 | //******************************************************************************
|
---|
158 | //******************************************************************************
|
---|
159 | LONG OSLibWinQueryWindowTextLength(HWND hwnd)
|
---|
160 | {
|
---|
161 | return WinQueryWindowTextLength(hwnd);
|
---|
162 | }
|
---|
163 | //******************************************************************************
|
---|
164 | //******************************************************************************
|
---|
165 | LONG OSLibWinQueryWindowText(HWND hwnd,LONG lLength,char* pun)
|
---|
166 | {
|
---|
167 | return WinQueryWindowText(hwnd,lLength,pun);
|
---|
168 | }
|
---|
169 | //******************************************************************************
|
---|
170 | //******************************************************************************
|
---|
171 | HWND OSLibWinQueryWindow(HWND hwnd, ULONG lCode)
|
---|
172 | {
|
---|
173 | return WinQueryWindow(hwnd, lCode);
|
---|
174 | }
|
---|
175 | //******************************************************************************
|
---|
176 | //******************************************************************************
|
---|
177 | BOOL OSLibWinSetWindowPos(HWND hwnd, HWND hwndInsertBehind, LONG x, LONG y, LONG cx,
|
---|
178 | LONG cy, ULONG fl)
|
---|
179 | {
|
---|
180 | return WinSetWindowPos(hwnd, hwndInsertBehind, x, y, cx, cy, fl);
|
---|
181 | }
|
---|
182 | //******************************************************************************
|
---|
183 | //******************************************************************************
|
---|
184 | BOOL OSLibWinShowWindow(HWND hwnd, ULONG fl)
|
---|
185 | {
|
---|
186 | return WinSetWindowPos(hwnd, 0, 0, 0, 0, 0, fl);
|
---|
187 | }
|
---|
188 | //******************************************************************************
|
---|
189 | //******************************************************************************
|
---|
190 | BOOL OSLibWinDestroyWindow(HWND hwnd)
|
---|
191 | {
|
---|
192 | return WinDestroyWindow(hwnd);
|
---|
193 | }
|
---|
194 | //******************************************************************************
|
---|
195 | //******************************************************************************
|
---|
196 | BOOL OSLibWinQueryUpdateRect(HWND hwnd, PVOID pRect)
|
---|
197 | {
|
---|
198 | return WinQueryUpdateRect(hwnd, (RECTL *)pRect);
|
---|
199 | }
|
---|
200 | //******************************************************************************
|
---|
201 | //******************************************************************************
|
---|
202 | BOOL OSLibWinIsIconic(HWND hwnd)
|
---|
203 | {
|
---|
204 | SWP swp;
|
---|
205 | BOOL rc;
|
---|
206 |
|
---|
207 | rc = WinQueryWindowPos(hwnd, &swp);
|
---|
208 | if(rc == FALSE) {
|
---|
209 | dprintf(("OSLibWinIsIconic: WinQueryWindowPos %x failed", hwnd));
|
---|
210 | return FALSE;
|
---|
211 | }
|
---|
212 |
|
---|
213 | if(swp.fl & SWP_MINIMIZE)
|
---|
214 | return TRUE;
|
---|
215 | else return FALSE;
|
---|
216 | }
|
---|
217 | //******************************************************************************
|
---|
218 | //******************************************************************************
|
---|
219 | BOOL OSLibWinSetActiveWindow(HWND hwnd)
|
---|
220 | {
|
---|
221 | return WinSetActiveWindow(HWND_DESKTOP, hwnd);
|
---|
222 | }
|
---|
223 | //******************************************************************************
|
---|
224 | //******************************************************************************
|
---|
225 | BOOL OSLibWinSetFocus(HWND hwnd)
|
---|
226 | {
|
---|
227 | return WinSetFocus(HWND_DESKTOP, hwnd);
|
---|
228 | }
|
---|
229 | //******************************************************************************
|
---|
230 | //******************************************************************************
|
---|
231 | BOOL OSLibWinEnableWindow(HWND hwnd, BOOL fEnable)
|
---|
232 | {
|
---|
233 | return WinEnableWindow(hwnd, fEnable);
|
---|
234 | }
|
---|
235 | //******************************************************************************
|
---|
236 | //******************************************************************************
|
---|
237 | BOOL OSLibWinIsWindowEnabled(HWND hwnd)
|
---|
238 | {
|
---|
239 | return WinIsWindowEnabled(hwnd);
|
---|
240 | }
|
---|
241 | //******************************************************************************
|
---|
242 | //******************************************************************************
|
---|
243 | BOOL OSLibWinIsWindowVisible(HWND hwnd)
|
---|
244 | {
|
---|
245 | return WinIsWindowVisible(hwnd);
|
---|
246 | }
|
---|
247 | //******************************************************************************
|
---|
248 | //******************************************************************************
|
---|
249 | BOOL OSLibWinQueryActiveWindow()
|
---|
250 | {
|
---|
251 | return WinQueryActiveWindow(HWND_DESKTOP);
|
---|
252 | }
|
---|
253 | //******************************************************************************
|
---|
254 | //******************************************************************************
|
---|
255 | void OSLibWinPostQuitMessage(ULONG nExitCode)
|
---|
256 | {
|
---|
257 | WinPostQueueMsg(GetThreadMessageQueue(), WM_QUIT, (MPARAM)nExitCode, 0);
|
---|
258 | }
|
---|
259 | //******************************************************************************
|
---|
260 | //******************************************************************************
|
---|
261 | LONG OSLibWinDispatchMsg(MSG *msg, BOOL isUnicode)
|
---|
262 | {
|
---|
263 | QMSG qmsg;
|
---|
264 |
|
---|
265 | WinToOS2MsgTranslate(msg, &qmsg, isUnicode);
|
---|
266 | return (LONG)WinDispatchMsg(GetThreadHAB(), &qmsg);
|
---|
267 | }
|
---|
268 | //******************************************************************************
|
---|
269 | //******************************************************************************
|
---|
270 | BOOL OSLibWinGetMsg(LPMSG pMsg, HWND hwnd, UINT uMsgFilterMin, UINT uMsgFilterMax, BOOL isUnicode)
|
---|
271 | {
|
---|
272 | QMSG qmsg;
|
---|
273 | BOOL rc;
|
---|
274 |
|
---|
275 | rc = WinGetMsg(GetThreadHAB(), &qmsg, TranslateWinMsg(uMsgFilterMin), TranslateWinMsg(uMsgFilterMax), 0);
|
---|
276 | OS2ToWinMsgTranslate(&qmsg, pMsg, isUnicode);
|
---|
277 | return rc;
|
---|
278 | }
|
---|
279 | //******************************************************************************
|
---|
280 | //******************************************************************************
|
---|
281 |
|
---|