source: trunk/src/gdi32/oslibgpi.cpp@ 4170

Last change on this file since 4170 was 4170, checked in by sandervl, 25 years ago

WinDrawTabbedText fs corruption fixed

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