1 | /* $Id: oslibgpi.cpp,v 1.5 2000-06-14 13:17:51 sandervl Exp $ */
|
---|
2 |
|
---|
3 | /*
|
---|
4 | * GPI interface code
|
---|
5 | *
|
---|
6 | * Copyright 1999 Christoph Bratschi (cbratschi@datacomm.ch)
|
---|
7 | *
|
---|
8 | * Project Odin Software License can be found in LICENSE.TXT
|
---|
9 | *
|
---|
10 | */
|
---|
11 |
|
---|
12 | #define INCL_GPI
|
---|
13 | #define INCL_WIN
|
---|
14 | #include <os2wrap.h> //Odin32 OS/2 api wrappers
|
---|
15 | #include <stdlib.h>
|
---|
16 | #include <string.h>
|
---|
17 | #include <math.h>
|
---|
18 | #include "win32type.h"
|
---|
19 | #include <winconst.h>
|
---|
20 | #include "oslibgpi.h"
|
---|
21 | #include "dcdata.h"
|
---|
22 |
|
---|
23 | #define DBG_LOCALLOG DBG_oslibgpi
|
---|
24 | #include "dbglocal.h"
|
---|
25 |
|
---|
26 | #define GetDCData(a) ((pDCData)a)
|
---|
27 |
|
---|
28 | LONG APIENTRY _GpiQueryTabbedTextExtent(HPS hps,LONG lCount,PCH pchString,LONG lTabCount,PULONG puTabStops);
|
---|
29 |
|
---|
30 | inline LONG GpiQueryTabbedTextExtent(HPS hps,LONG lCount,PCH pchString,LONG lTabCount,PULONG puTabStops)
|
---|
31 | {
|
---|
32 | LONG yyrc;
|
---|
33 | USHORT sel = RestoreOS2FS();
|
---|
34 |
|
---|
35 | yyrc = _GpiQueryTabbedTextExtent(hps,lCount,pchString,lTabCount,puTabStops);
|
---|
36 | SetFS(sel);
|
---|
37 |
|
---|
38 | return yyrc;
|
---|
39 | }
|
---|
40 |
|
---|
41 | LONG APIENTRY _GpiTabbedCharStringAt(HPS hps,PPOINTL pPtStart,PRECTL prclRect,ULONG flOptions,LONG lCount,PCH pchString,LONG lTabCount,PULONG puTabStops,LONG lTabOrigin);
|
---|
42 |
|
---|
43 | inline LONG GpiTabbedCharStringAt(HPS hps,PPOINTL pPtStart,PRECTL prclRect,ULONG flOptions,LONG lCount,PCH pchString,LONG lTabCount,PULONG puTabStops,LONG lTabOrigin)
|
---|
44 | {
|
---|
45 | LONG yyrc;
|
---|
46 | USHORT sel = RestoreOS2FS();
|
---|
47 |
|
---|
48 | yyrc = _GpiTabbedCharStringAt(hps,pPtStart,prclRect,flOptions,lCount,pchString,lTabCount,puTabStops,lTabOrigin);
|
---|
49 | SetFS(sel);
|
---|
50 |
|
---|
51 | return yyrc;
|
---|
52 | }
|
---|
53 |
|
---|
54 | void inline swap(LONG &a,LONG &b)
|
---|
55 | {
|
---|
56 | LONG temp = a;
|
---|
57 |
|
---|
58 | a = b;
|
---|
59 | b = temp;
|
---|
60 | }
|
---|
61 |
|
---|
62 | void inline swap(int &a,int &b)
|
---|
63 | {
|
---|
64 | int temp = a;
|
---|
65 |
|
---|
66 | a = b;
|
---|
67 | b = temp;
|
---|
68 | }
|
---|
69 |
|
---|
70 | void inline sortAscending(LONG &a,LONG &b)
|
---|
71 | {
|
---|
72 | if (a > b) swap(a,b);
|
---|
73 | }
|
---|
74 |
|
---|
75 | void inline sortAscending(int &a,int &b)
|
---|
76 | {
|
---|
77 | if (a > b) swap(a,b);
|
---|
78 | }
|
---|
79 |
|
---|
80 | void inline sortAscending(POINTLOS2 &a,POINTLOS2 &b)
|
---|
81 | {
|
---|
82 | sortAscending(a.x,b.x);
|
---|
83 | sortAscending(a.y,b.y);
|
---|
84 | }
|
---|
85 |
|
---|
86 | BOOL excludeBottomRightPoint(PVOID pHps,PPOINTLOS2 pptl)
|
---|
87 | {
|
---|
88 | sortAscending(pptl[0],pptl[1]);
|
---|
89 |
|
---|
90 | if (GetDCData(pHps)->graphicsMode != GM_COMPATIBLE_W)
|
---|
91 | {
|
---|
92 | return TRUE;
|
---|
93 | }
|
---|
94 |
|
---|
95 | if (pptl[0].x == pptl[1].x || pptl[0].y == pptl[1].y)
|
---|
96 | {
|
---|
97 | return FALSE;
|
---|
98 | }
|
---|
99 |
|
---|
100 | if (abs((int)GetDCData(pHps)->viewportXExt) <= abs((int)GetDCData(pHps)->windowExt.cx))
|
---|
101 | {
|
---|
102 | if (GetDCData(pHps)->isLeftLeft)
|
---|
103 | pptl[1].x -= abs(GetDCData(pHps)->worldXDeltaFor1Pixel);
|
---|
104 | else
|
---|
105 | pptl[0].x += abs(GetDCData(pHps)->worldXDeltaFor1Pixel);
|
---|
106 | }
|
---|
107 |
|
---|
108 | if (abs((int)GetDCData(pHps)->viewportYExt) <= abs((int)GetDCData(pHps)->windowExt.cy))
|
---|
109 | {
|
---|
110 | if (GetDCData(pHps)->isTopTop)
|
---|
111 | pptl[1].y -= abs(GetDCData(pHps)->worldYDeltaFor1Pixel);
|
---|
112 | else
|
---|
113 | pptl[0].y += abs(GetDCData(pHps)->worldYDeltaFor1Pixel);
|
---|
114 | }
|
---|
115 |
|
---|
116 | sortAscending(pptl[0], pptl[1]);
|
---|
117 |
|
---|
118 | return TRUE;
|
---|
119 | }
|
---|
120 |
|
---|
121 | BOOL includeBottomRightPoint(PVOID pHps,PPOINTLOS2 pptl)
|
---|
122 | {
|
---|
123 | if(GetDCData(pHps)->graphicsMode != GM_COMPATIBLE_W)
|
---|
124 | {
|
---|
125 | return TRUE; // already inclusive/inclusive
|
---|
126 | }
|
---|
127 |
|
---|
128 | if(pptl[0].x == pptl[1].x || pptl[0].y == pptl[1].y)
|
---|
129 | {
|
---|
130 | return FALSE; // empty rectangle
|
---|
131 | }
|
---|
132 |
|
---|
133 | if(GetDCData(pHps)->isLeftLeft)
|
---|
134 | {
|
---|
135 | pptl[1].x += abs(GetDCData(pHps)->worldXDeltaFor1Pixel);
|
---|
136 | sortAscending(pptl[0].x, pptl[1].x);
|
---|
137 | }
|
---|
138 | else
|
---|
139 | {
|
---|
140 | pptl[0].x -= abs(GetDCData(pHps)->worldXDeltaFor1Pixel);
|
---|
141 | sortAscending(pptl[1].x, pptl[0].x);
|
---|
142 | }
|
---|
143 |
|
---|
144 | if(GetDCData(pHps)->isTopTop)
|
---|
145 | {
|
---|
146 | pptl[1].y += abs(GetDCData(pHps)->worldYDeltaFor1Pixel);
|
---|
147 | sortAscending(pptl[1].y, pptl[0].y);
|
---|
148 | }
|
---|
149 | else
|
---|
150 | {
|
---|
151 | pptl[0].y -= abs(GetDCData(pHps)->worldYDeltaFor1Pixel);
|
---|
152 | sortAscending(pptl[0].y, pptl[1].y);
|
---|
153 | }
|
---|
154 | return TRUE;
|
---|
155 | }
|
---|
156 |
|
---|
157 | BOOL getAlignUpdateCP(PVOID pHps)
|
---|
158 | {
|
---|
159 | return GetDCData(pHps)->alignUpdateCP;
|
---|
160 | }
|
---|
161 |
|
---|
162 | INT getWorldYDeltaFor1Pixel(PVOID pHps)
|
---|
163 | {
|
---|
164 | return GetDCData(pHps)->worldYDeltaFor1Pixel;
|
---|
165 | }
|
---|
166 |
|
---|
167 | INT getWorldXDeltaFor1Pixel(PVOID pHps)
|
---|
168 | {
|
---|
169 | return GetDCData(pHps)->worldXDeltaFor1Pixel;
|
---|
170 | }
|
---|
171 |
|
---|
172 | BOOL getInPath(PVOID pHps)
|
---|
173 | {
|
---|
174 | return GetDCData(pHps)->inPath;
|
---|
175 | }
|
---|
176 |
|
---|
177 | VOID setInPath(PVOID pHps,BOOL inPath)
|
---|
178 | {
|
---|
179 | GetDCData(pHps)->inPath = inPath;
|
---|
180 | }
|
---|
181 |
|
---|
182 | BOOL getIsWideLine(PVOID pHps)
|
---|
183 | {
|
---|
184 | return GetDCData(pHps)->isWideLine;
|
---|
185 | }
|
---|
186 |
|
---|
187 | BOOL getIsTopTop(PVOID pHps)
|
---|
188 | {
|
---|
189 | return GetDCData(pHps)->isTopTop;
|
---|
190 | }
|
---|
191 |
|
---|
192 | ULONG getMapMode(PVOID pHps)
|
---|
193 | {
|
---|
194 | return GetDCData(pHps)->MapMode;
|
---|
195 | }
|
---|
196 |
|
---|
197 | BOOL OSLibGpiQueryCurrentPosition(PVOID pHps,PPOINTLOS2 ptl)
|
---|
198 | {
|
---|
199 | return GpiQueryCurrentPosition(GetDCData(pHps)->hps,(PPOINTL)ptl);
|
---|
200 | }
|
---|
201 |
|
---|
202 | BOOL OSLibGpiSetCurrentPosition(PVOID pHps,PPOINTLOS2 ptl)
|
---|
203 | {
|
---|
204 | return GpiSetCurrentPosition(GetDCData(pHps)->hps,(PPOINTL)ptl);
|
---|
205 | }
|
---|
206 |
|
---|
207 | BOOL OSLibGpiCharStringPosAt(PVOID pHps,PPOINTLOS2 ptl,PRECTLOS2 rct,ULONG flOptions,LONG lCount,LPCSTR pchString,CONST INT *alAdx)
|
---|
208 | {
|
---|
209 | return GpiCharStringPosAt(GetDCData(pHps)->hps,(PPOINTL)ptl,(PRECTL)rct,flOptions,lCount,(PCH)pchString,(PLONG)alAdx);
|
---|
210 | }
|
---|
211 |
|
---|
212 | BOOL OSLibGpiQueryCharStringPosAt(PVOID pHps,PPOINTLOS2 ptl,ULONG flOptions,LONG lCount,LPCSTR pchString,CONST INT *alAdx,PPOINTLOS2 aptlPos)
|
---|
213 | {
|
---|
214 | return GpiQueryCharStringPosAt(GetDCData(pHps)->hps,(PPOINTL)ptl,flOptions,lCount,(PCH)pchString,(PLONG)alAdx,(PPOINTL)aptlPos);
|
---|
215 | }
|
---|
216 |
|
---|
217 | BOOL OSLibGpiSetTextAlignment(PVOID pHps,LONG lHoriz,LONG lVert)
|
---|
218 | {
|
---|
219 | return GpiSetTextAlignment(GetDCData(pHps)->hps,lHoriz,lVert);
|
---|
220 | }
|
---|
221 |
|
---|
222 | BOOL OSLibGpiQueryTextAlignment(PVOID pHps,PLONG plHoriz,PLONG plVert)
|
---|
223 | {
|
---|
224 | return GpiQueryTextAlignment(GetDCData(pHps)->hps,plHoriz,plVert);
|
---|
225 | }
|
---|
226 |
|
---|
227 | LONG OSLibGpiQueryTabbedTextExtent(PVOID pHps,INT lCount,LPCSTR pchString,INT lTabCount,PINT puTabStops)
|
---|
228 | {
|
---|
229 | return GpiQueryTabbedTextExtent(GetDCData(pHps)->hps,lCount,(PCH)pchString,lTabCount,(PULONG)puTabStops);
|
---|
230 | }
|
---|
231 |
|
---|
232 | LONG OSLibGpiTabbedCharStringAt(PVOID pHps,PPOINTLOS2 pPtStart,PRECTLOS2 prclRect,ULONG flOptions,INT lCount,LPCSTR pchString,INT lTabCount,PINT puTabStops,INT lTabOrigin)
|
---|
233 | {
|
---|
234 | return GpiTabbedCharStringAt(GetDCData(pHps)->hps,(PPOINTL)pPtStart,(PRECTL)prclRect,flOptions,lCount,(PCH)pchString,lTabCount,(PULONG)puTabStops,lTabOrigin);
|
---|
235 | }
|
---|
236 |
|
---|
237 | BOOL OSLibGpiQueryTextBox(PVOID pHps,LONG lCount1,LPCSTR pchString,LONG lCount2,PPOINTLOS2 aptlPoints)
|
---|
238 | {
|
---|
239 | return GpiQueryTextBox(GetDCData(pHps)->hps,lCount1,(PCH)pchString,lCount2,(PPOINTL)aptlPoints);
|
---|
240 | }
|
---|
241 |
|
---|
242 | VOID calcDimensions(POINTLOS2 box[],PPOINTLOS2 point)
|
---|
243 | {
|
---|
244 | ULONG cx;
|
---|
245 | ULONG cy;
|
---|
246 |
|
---|
247 | if (box[TXTBOX_BOTTOMLEFT].y == box[TXTBOX_BOTTOMRIGHT].y)
|
---|
248 | {
|
---|
249 | point->y = labs (box[TXTBOX_BOTTOMLEFT].y-box[TXTBOX_TOPLEFT].y);
|
---|
250 | point->x = labs (box[TXTBOX_CONCAT].x-box[TXTBOX_BOTTOMLEFT].x);
|
---|
251 |
|
---|
252 | if (box[TXTBOX_BOTTOMLEFT].x != box[TXTBOX_TOPLEFT].x)
|
---|
253 | {
|
---|
254 | if (point->y < 25)
|
---|
255 | cx = 2;
|
---|
256 | else
|
---|
257 | cx = ((point->y*10)+50)/100;
|
---|
258 | point->x += cx;
|
---|
259 | }
|
---|
260 | } else
|
---|
261 | {
|
---|
262 | cx = labs (box[TXTBOX_BOTTOMLEFT].x-box[TXTBOX_TOPLEFT].x);
|
---|
263 | cy = labs (box[TXTBOX_BOTTOMLEFT].y-box[TXTBOX_TOPLEFT].y);
|
---|
264 | point->y = (ULONG)hypot(cx,cy);
|
---|
265 |
|
---|
266 | cx = labs (box[TXTBOX_TOPRIGHT].x-box[TXTBOX_TOPLEFT].x);
|
---|
267 | cy = labs (box[TXTBOX_TOPRIGHT].y-box[TXTBOX_TOPLEFT].y);
|
---|
268 | point->x = (ULONG)hypot(cx,cy);
|
---|
269 | }
|
---|
270 | }
|
---|
271 |
|
---|
272 | LONG OSLibGpiQueryBackMix(PVOID pHps)
|
---|
273 | {
|
---|
274 | return GpiQueryBackMix(GetDCData(pHps)->hps);
|
---|
275 | }
|
---|
276 |
|
---|
277 | BOOL doesYAxisGrowNorth(PVOID pHps)
|
---|
278 | {
|
---|
279 | if ((GetDCData(pHps)->windowExt.cy < 0 && GetDCData(pHps)->viewportYExt > 0.0) ||
|
---|
280 | (GetDCData(pHps)->windowExt.cy > 0 && GetDCData(pHps)->viewportYExt < 0.0))
|
---|
281 | {
|
---|
282 | if (GetDCData(pHps)->graphicsMode == GM_COMPATIBLE_W ||
|
---|
283 | (GetDCData(pHps)->graphicsMode == GM_ADVANCED_W && GetDCData(pHps)->xform.eM22 >= 0.0))
|
---|
284 | return TRUE;
|
---|
285 | } else
|
---|
286 | {
|
---|
287 | if (GetDCData(pHps)->graphicsMode == GM_ADVANCED_W && GetDCData(pHps)->xform.eM22 < 0.0)
|
---|
288 | return TRUE;
|
---|
289 | }
|
---|
290 |
|
---|
291 | return FALSE;
|
---|
292 | }
|
---|
293 |
|
---|
294 | LONG OSLibWinDrawTabbedText(PVOID pHps,LONG cchText,LONG lTabs,LPCSTR lpchText,PVOID prcl,LONG clrFore,LONG clrBack,ULONG flCmd)
|
---|
295 | {
|
---|
296 | //return WinDraw
|
---|
297 | //undocumented
|
---|
298 | return 0;
|
---|
299 | }
|
---|
300 |
|
---|
301 | BOOL OSLibGpiMove(PVOID pHps,PPOINTLOS2 pptlPoint)
|
---|
302 | {
|
---|
303 | return GpiMove(GetDCData(pHps)->hps,(PPOINTL)pptlPoint);
|
---|
304 | }
|
---|
305 |
|
---|
306 | LONG OSLibGpiLine(PVOID pHps,PPOINTLOS2 pptlEndPoint)
|
---|
307 | {
|
---|
308 | return GpiLine(GetDCData(pHps)->hps,(PPOINTL)pptlEndPoint);
|
---|
309 | }
|
---|
310 |
|
---|
311 | #define FSP_ENDPATH 0x00000010
|
---|
312 | #define FSP_FILL 0x00000020
|
---|
313 | #define FSP_CLOSEPATH 0x00000040
|
---|
314 |
|
---|
315 | BOOL APIENTRY _PaxStrokeAndFillPath(HPS hPS,ULONG ulAction,ULONG ulStrokeAttrs,PAREABUNDLE pPenStroke);
|
---|
316 |
|
---|
317 | inline BOOL PaxStrokeAndFillPath(HPS hPS,ULONG ulAction,ULONG ulStrokeAttrs,PAREABUNDLE pPenStroke)
|
---|
318 | {
|
---|
319 | BOOL yyrc;
|
---|
320 | USHORT sel = RestoreOS2FS();
|
---|
321 |
|
---|
322 | yyrc = _PaxStrokeAndFillPath(hPS,ulAction,ulStrokeAttrs,pPenStroke);
|
---|
323 | SetFS(sel);
|
---|
324 |
|
---|
325 | return yyrc;
|
---|
326 | }
|
---|
327 |
|
---|
328 | BOOL OSLibGpiEndPath(PVOID pHps)
|
---|
329 | {
|
---|
330 | return GpiEndPath(GetDCData(pHps)->hps);
|
---|
331 | }
|
---|
332 |
|
---|
333 | BOOL drawLinePointCircle(PVOID pHps,INT width,INT height,LONG color)
|
---|
334 | {
|
---|
335 | ARCPARAMS arcp;
|
---|
336 | BOOL rc = TRUE;
|
---|
337 |
|
---|
338 | arcp.lP = 1;
|
---|
339 | arcp.lQ = 1;
|
---|
340 | arcp.lR = 0;
|
---|
341 | arcp.lS = 0;
|
---|
342 | if (!GpiSetArcParams(GetDCData(pHps)->hps,&arcp))
|
---|
343 | return FALSE;
|
---|
344 |
|
---|
345 | AREABUNDLE newAreaBundle, oldAreaBundle;
|
---|
346 | LINEBUNDLE lineBundle;
|
---|
347 |
|
---|
348 | GpiQueryAttrs(GetDCData(pHps)->hps,PRIM_AREA,ABB_COLOR | ABB_MIX_MODE | ABB_SET | ABB_SYMBOL,(PBUNDLE)&oldAreaBundle);
|
---|
349 | GpiQueryAttrs(GetDCData(pHps)->hps,PRIM_LINE,LBB_MIX_MODE, (PBUNDLE)&lineBundle);
|
---|
350 |
|
---|
351 | newAreaBundle = oldAreaBundle;
|
---|
352 | newAreaBundle.lColor = color;
|
---|
353 | newAreaBundle.usMixMode = lineBundle.usMixMode;
|
---|
354 | newAreaBundle.usSet = LCID_DEFAULT;
|
---|
355 | newAreaBundle.usSymbol = PATSYM_SOLID;
|
---|
356 |
|
---|
357 | if (!GpiSetAttrs(GetDCData(pHps)->hps,PRIM_AREA,ABB_COLOR | ABB_MIX_MODE | ABB_SET | ABB_SYMBOL,0,(PBUNDLE)&newAreaBundle))
|
---|
358 | return FALSE;
|
---|
359 |
|
---|
360 | if (GpiFullArc(GetDCData(pHps)->hps,DRO_FILL,MAKEFIXED((width-1)>>1,0)) == GPI_ERROR)
|
---|
361 | rc = FALSE;
|
---|
362 | GpiSetAttrs(GetDCData(pHps)->hps,PRIM_AREA,ABB_COLOR | ABB_MIX_MODE | ABB_SET | ABB_SYMBOL,0,(PBUNDLE)&oldAreaBundle);
|
---|
363 |
|
---|
364 | return rc;
|
---|
365 | }
|
---|
366 |
|
---|
367 | BOOL drawLinePoint(PVOID pHps,PPOINTLOS2 pt,LONG color)
|
---|
368 | {
|
---|
369 | LINEBUNDLE lbOld, lbNew;
|
---|
370 | LONG defaults = GpiQueryAttrs(GetDCData(pHps)->hps, PRIM_LINE, LBB_COLOR, &lbOld);
|
---|
371 |
|
---|
372 | lbNew.lColor = color;
|
---|
373 | BOOL rc = GpiSetAttrs(GetDCData(pHps)->hps,PRIM_LINE,LBB_COLOR,0,&lbNew) && GpiSetPel(GetDCData(pHps)->hps,(PPOINTL)pt) != GPI_ERROR;
|
---|
374 |
|
---|
375 | GpiSetAttrs(GetDCData(pHps)->hps,PRIM_LINE,LBB_COLOR,defaults,&lbOld);
|
---|
376 |
|
---|
377 | return rc;
|
---|
378 | }
|
---|
379 |
|
---|
380 | ULONG OSLibGpiQueryCp(HDC hdc)
|
---|
381 | {
|
---|
382 | return GpiQueryCp(hdc);
|
---|
383 | }
|
---|
384 |
|
---|
385 | BOOL OSLibGpiSetCp(HDC hdc, ULONG codepage)
|
---|
386 | {
|
---|
387 | return GpiSetCp(hdc, codepage);
|
---|
388 | }
|
---|
389 |
|
---|
390 |
|
---|