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

Last change on this file since 10583 was 10583, checked in by sandervl, 21 years ago

updates

File size: 14.9 KB
Line 
1/* $Id: oslibgpi.cpp,v 1.18 2004-04-14 09:44:13 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_GPIERRORS
14#define INCL_WIN
15#include <os2wrap.h> //Odin32 OS/2 api wrappers
16#include <stdlib.h>
17#include <string.h>
18#include <math.h>
19#include "win32type.h"
20#include <winconst.h>
21#include "oslibgpi.h"
22#include <dcdata.h>
23#include <misc.h>
24
25#define DBG_LOCALLOG DBG_oslibgpi
26#include "dbglocal.h"
27
28#define GetDCData(a) ((pDCData)a)
29
30LONG APIENTRY _GpiQueryTabbedTextExtent(HPS hps,LONG lCount,PCH pchString,LONG lTabCount,PULONG puTabStops);
31
32inline LONG GpiQueryTabbedTextExtent(HPS hps,LONG lCount,PCH pchString,LONG lTabCount,PULONG puTabStops)
33{
34 LONG yyrc;
35 USHORT sel = RestoreOS2FS();
36
37 yyrc = _GpiQueryTabbedTextExtent(hps,lCount,pchString,lTabCount,puTabStops);
38 SetFS(sel);
39
40 return yyrc;
41}
42
43LONG APIENTRY _GpiTabbedCharStringAt(HPS hps,PPOINTL pPtStart,PRECTL prclRect,ULONG flOptions,LONG lCount,PCH pchString,LONG lTabCount,PULONG puTabStops,LONG lTabOrigin);
44
45inline LONG GpiTabbedCharStringAt(HPS hps,PPOINTL pPtStart,PRECTL prclRect,ULONG flOptions,LONG lCount,PCH pchString,LONG lTabCount,PULONG puTabStops,LONG lTabOrigin)
46{
47 LONG yyrc;
48 USHORT sel = RestoreOS2FS();
49
50 yyrc = _GpiTabbedCharStringAt(hps,pPtStart,prclRect,flOptions,lCount,pchString,lTabCount,puTabStops,lTabOrigin);
51 SetFS(sel);
52
53 return yyrc;
54}
55
56LONG APIENTRY WinDrawTabbedText(HPS hps,LONG cchText,LONG lTabWidth,PCH lpchText,PRECTL prcl,LONG clrFore,LONG clrBack,ULONG flCmd);
57
58inline LONG _WinDrawTabbedText(HPS hps,LONG cchText,LONG lTabWidth,PCH lpchText,PRECTL prcl,LONG clrFore,LONG clrBack,ULONG flCmd)
59{
60 LONG yyrc;
61 USHORT sel = RestoreOS2FS();
62
63 yyrc = WinDrawTabbedText(hps,cchText,lTabWidth,lpchText,prcl,clrFore,clrBack,flCmd);
64 SetFS(sel);
65
66 return yyrc;
67}
68
69#undef WinDrawTabbedText
70#define WinDrawTabbedText _WinDrawTabbedText
71
72void inline swap(LONG &a,LONG &b)
73{
74 LONG temp = a;
75
76 a = b;
77 b = temp;
78}
79
80void inline swap(int &a,int &b)
81{
82 int temp = a;
83
84 a = b;
85 b = temp;
86}
87
88void inline sortAscending(LONG &a,LONG &b)
89{
90 if (a > b) swap(a,b);
91}
92
93void inline sortAscending(int &a,int &b)
94{
95 if (a > b) swap(a,b);
96}
97
98void inline sortAscending(POINTLOS2 &a,POINTLOS2 &b)
99{
100 sortAscending(a.x,b.x);
101 sortAscending(a.y,b.y);
102}
103
104BOOL excludeBottomRightPoint(PVOID pHps,PPOINTLOS2 pptl)
105{
106 sortAscending(pptl[0],pptl[1]);
107
108 if (GetDCData(pHps)->graphicsMode != GM_COMPATIBLE_W)
109 {
110 return TRUE;
111 }
112
113 if (pptl[0].x == pptl[1].x || pptl[0].y == pptl[1].y)
114 {
115 return FALSE;
116 }
117
118 if (abs((int)GetDCData(pHps)->viewportXExt) <= abs((int)GetDCData(pHps)->windowExt.cx))
119 {
120 if (GetDCData(pHps)->isLeftLeft)
121 pptl[1].x -= abs(GetDCData(pHps)->worldXDeltaFor1Pixel);
122 else
123 pptl[0].x += abs(GetDCData(pHps)->worldXDeltaFor1Pixel);
124 }
125
126 if (abs((int)GetDCData(pHps)->viewportYExt) <= abs((int)GetDCData(pHps)->windowExt.cy))
127 {
128 if (GetDCData(pHps)->isTopTop)
129 pptl[1].y -= abs(GetDCData(pHps)->worldYDeltaFor1Pixel);
130 else
131 pptl[0].y += abs(GetDCData(pHps)->worldYDeltaFor1Pixel);
132 }
133
134 sortAscending(pptl[0], pptl[1]);
135
136 return TRUE;
137}
138
139BOOL includeBottomRightPoint(PVOID pHps,PPOINTLOS2 pptl)
140{
141 if(GetDCData(pHps)->graphicsMode != GM_COMPATIBLE_W)
142 {
143 return TRUE; // already inclusive/inclusive
144 }
145
146 if(GetDCData(pHps)->isLeftLeft)
147 {
148 pptl[1].x += abs(GetDCData(pHps)->worldXDeltaFor1Pixel);
149 sortAscending(pptl[0].x, pptl[1].x);
150 }
151 else
152 {
153 pptl[0].x -= abs(GetDCData(pHps)->worldXDeltaFor1Pixel);
154 sortAscending(pptl[1].x, pptl[0].x);
155 }
156
157 if(GetDCData(pHps)->isTopTop)
158 {
159 pptl[1].y += abs(GetDCData(pHps)->worldYDeltaFor1Pixel);
160 sortAscending(pptl[1].y, pptl[0].y);
161 }
162 else
163 {
164 pptl[0].y -= abs(GetDCData(pHps)->worldYDeltaFor1Pixel);
165 sortAscending(pptl[0].y, pptl[1].y);
166 }
167 return TRUE;
168}
169
170BOOL getAlignUpdateCP(PVOID pHps)
171{
172 return GetDCData(pHps)->alignUpdateCP;
173}
174
175INT getWorldYDeltaFor1Pixel(PVOID pHps)
176{
177 return GetDCData(pHps)->worldYDeltaFor1Pixel;
178}
179
180INT getWorldXDeltaFor1Pixel(PVOID pHps)
181{
182 return GetDCData(pHps)->worldXDeltaFor1Pixel;
183}
184
185BOOL getInPath(PVOID pHps)
186{
187 return GetDCData(pHps)->inPath;
188}
189
190VOID setInPath(PVOID pHps,BOOL inPath)
191{
192 GetDCData(pHps)->inPath = inPath;
193}
194
195BOOL getIsWideLine(PVOID pHps)
196{
197 return GetDCData(pHps)->isWideLine;
198}
199
200BOOL getIsTopTop(PVOID pHps)
201{
202 return GetDCData(pHps)->isTopTop;
203}
204
205ULONG getMapMode(PVOID pHps)
206{
207 return GetDCData(pHps)->MapMode;
208}
209
210BOOL OSLibGpiQueryCurrentPosition(PVOID pHps,PPOINTLOS2 ptl)
211{
212 return GpiQueryCurrentPosition(GetDCData(pHps)->hps,(PPOINTL)ptl);
213}
214
215BOOL OSLibGpiSetCurrentPosition(PVOID pHps,PPOINTLOS2 ptl)
216{
217 return GpiSetCurrentPosition(GetDCData(pHps)->hps,(PPOINTL)ptl);
218}
219
220BOOL OSLibGpiCharStringPosAt(PVOID pHps,PPOINTLOS2 ptl,PRECTLOS2 rct,ULONG flOptions,LONG lCount,LPCSTR pchString,CONST INT *alAdx)
221{
222 return GpiCharStringPosAt(GetDCData(pHps)->hps,(PPOINTL)ptl,(PRECTL)rct,flOptions,lCount,(PCH)pchString,(PLONG)alAdx);
223}
224
225BOOL OSLibGpiQueryCharStringPosAt(PVOID pHps,PPOINTLOS2 ptl,ULONG flOptions,LONG lCount,LPCSTR pchString,CONST INT *alAdx,PPOINTLOS2 aptlPos)
226{
227 return GpiQueryCharStringPosAt(GetDCData(pHps)->hps,(PPOINTL)ptl,flOptions,lCount,(PCH)pchString,(PLONG)alAdx,(PPOINTL)aptlPos);
228}
229
230BOOL OSLibGpiSetTextAlignment(PVOID pHps,LONG lHoriz,LONG lVert)
231{
232 return GpiSetTextAlignment(GetDCData(pHps)->hps,lHoriz,lVert);
233}
234
235BOOL OSLibGpiQueryTextAlignment(PVOID pHps,PLONG plHoriz,PLONG plVert)
236{
237 return GpiQueryTextAlignment(GetDCData(pHps)->hps,plHoriz,plVert);
238}
239
240LONG OSLibGpiQueryTabbedTextExtent(pDCData pHps,INT lCount,LPCSTR pchString,INT lTabCount,PINT puTabStops)
241{
242 return GpiQueryTabbedTextExtent(pHps->hps,lCount,(PCH)pchString,lTabCount,(PULONG)puTabStops);
243}
244
245LONG OSLibGpiTabbedCharStringAt(PVOID pHps,PPOINTLOS2 pPtStart,PRECTLOS2 prclRect,ULONG flOptions,INT lCount,LPCSTR pchString,INT lTabCount,PINT puTabStops,INT lTabOrigin)
246{
247 return GpiTabbedCharStringAt(GetDCData(pHps)->hps,(PPOINTL)pPtStart,(PRECTL)prclRect,flOptions,lCount,(PCH)pchString,lTabCount,(PULONG)puTabStops,lTabOrigin);
248}
249
250BOOL OSLibGpiQueryTextBox(pDCData pHps,LONG lCount1,LPCSTR pchString,LONG lCount2,PPOINTLOS2 aptlPoints)
251{
252 return GpiQueryTextBox(pHps->hps,lCount1,(PCH)pchString,lCount2,(PPOINTL)aptlPoints);
253}
254
255VOID calcDimensions(POINTLOS2 box[],PPOINTLOS2 point)
256{
257 ULONG cx;
258 ULONG cy;
259
260 //ignore underhang (just like GetTextExtentPoint does in Windows)
261 if (box[TXTBOX_BOTTOMLEFT].x < 0) {
262 dprintf(("WARNING: Ignoring underhang!!"));
263 box[TXTBOX_BOTTOMLEFT].x = 0;
264 }
265
266 if (box[TXTBOX_BOTTOMLEFT].y == box[TXTBOX_BOTTOMRIGHT].y)
267 {
268 point->y = labs (box[TXTBOX_BOTTOMLEFT].y-box[TXTBOX_TOPLEFT].y);
269 point->x = labs (box[TXTBOX_CONCAT].x - box[TXTBOX_BOTTOMLEFT].x);
270
271 if (box[TXTBOX_BOTTOMLEFT].x != box[TXTBOX_TOPLEFT].x)
272 {
273 if (point->y < 25)
274 cx = 2;
275 else
276 cx = ((point->y*10)+50)/100;
277 point->x += cx;
278 }
279 } else
280 {
281 cx = labs (box[TXTBOX_BOTTOMLEFT].x-box[TXTBOX_TOPLEFT].x);
282 cy = labs (box[TXTBOX_BOTTOMLEFT].y-box[TXTBOX_TOPLEFT].y);
283 point->y = (ULONG)hypot(cx,cy);
284
285 cx = labs (box[TXTBOX_TOPRIGHT].x-box[TXTBOX_TOPLEFT].x);
286 cy = labs (box[TXTBOX_TOPRIGHT].y-box[TXTBOX_TOPLEFT].y);
287 point->x = (ULONG)hypot(cx,cy);
288 }
289}
290
291LONG OSLibGpiQueryBackMix(PVOID pHps)
292{
293 return GpiQueryBackMix(GetDCData(pHps)->hps);
294}
295
296BOOL doesYAxisGrowNorth(PVOID pHps)
297{
298 if ((GetDCData(pHps)->windowExt.cy < 0 && GetDCData(pHps)->viewportYExt > 0.0) ||
299 (GetDCData(pHps)->windowExt.cy > 0 && GetDCData(pHps)->viewportYExt < 0.0))
300 {
301 if (GetDCData(pHps)->graphicsMode == GM_COMPATIBLE_W ||
302 (GetDCData(pHps)->graphicsMode == GM_ADVANCED_W && GetDCData(pHps)->xform.eM22 >= 0.0))
303 return TRUE;
304 } else
305 {
306 if (GetDCData(pHps)->graphicsMode == GM_ADVANCED_W && GetDCData(pHps)->xform.eM22 < 0.0)
307 return TRUE;
308 }
309
310 return FALSE;
311}
312
313LONG OSLibWinDrawTabbedText(PVOID pHps,LONG cchText,LONG lTabs,LPCSTR lpchText,PVOID prcl,LONG clrFore,LONG clrBack,ULONG flCmd)
314{
315 return WinDrawTabbedText(GetDCData(pHps)->hps,cchText,lTabs,(PCH)lpchText,(PRECTL)prcl,clrFore,clrBack,flCmd);
316}
317
318BOOL OSLibGpiMove(PVOID pHps,PPOINTLOS2 pptlPoint)
319{
320 return GpiMove(GetDCData(pHps)->hps,(PPOINTL)pptlPoint);
321}
322
323BOOL OSLibGpiLine(PVOID pHps,PPOINTLOS2 pptlEndPoint)
324{
325 LONG ret = GpiLine(GetDCData(pHps)->hps,(PPOINTL)pptlEndPoint);
326 if(ret != GPI_OK) {
327 dprintf(("GpiLine failed with error %x", WinGetLastError(0)));
328 }
329 return (ret == GPI_OK);
330}
331
332#define FSP_ENDPATH 0x00000010
333#define FSP_FILL 0x00000020
334#define FSP_CLOSEPATH 0x00000040
335
336BOOL APIENTRY _PaxStrokeAndFillPath(HPS hPS,ULONG ulAction,ULONG ulStrokeAttrs,PAREABUNDLE pPenStroke);
337
338inline BOOL PaxStrokeAndFillPath(HPS hPS,ULONG ulAction,ULONG ulStrokeAttrs,PAREABUNDLE pPenStroke)
339{
340 BOOL yyrc;
341 USHORT sel = RestoreOS2FS();
342
343 yyrc = _PaxStrokeAndFillPath(hPS,ulAction,ulStrokeAttrs,pPenStroke);
344 SetFS(sel);
345
346 return yyrc;
347}
348
349
350BOOL OSLibGpiEndPath(PVOID pHps)
351{
352 return GpiEndPath(GetDCData(pHps)->hps);
353}
354
355BOOL drawLinePointCircle(PVOID pHps,INT width,INT height,LONG color)
356{
357 ARCPARAMS arcp;
358 BOOL rc = TRUE;
359
360 arcp.lP = 1;
361 arcp.lQ = 1;
362 arcp.lR = 0;
363 arcp.lS = 0;
364 if (!GpiSetArcParams(GetDCData(pHps)->hps,&arcp))
365 return FALSE;
366
367 AREABUNDLE newAreaBundle, oldAreaBundle;
368 LINEBUNDLE lineBundle;
369
370 GpiQueryAttrs(GetDCData(pHps)->hps,PRIM_AREA,ABB_COLOR | ABB_MIX_MODE | ABB_SET | ABB_SYMBOL,(PBUNDLE)&oldAreaBundle);
371 GpiQueryAttrs(GetDCData(pHps)->hps,PRIM_LINE,LBB_MIX_MODE, (PBUNDLE)&lineBundle);
372
373 newAreaBundle = oldAreaBundle;
374 newAreaBundle.lColor = color;
375 newAreaBundle.usMixMode = lineBundle.usMixMode;
376 newAreaBundle.usSet = LCID_DEFAULT;
377 newAreaBundle.usSymbol = PATSYM_SOLID;
378
379 if (!GpiSetAttrs(GetDCData(pHps)->hps,PRIM_AREA,ABB_COLOR | ABB_MIX_MODE | ABB_SET | ABB_SYMBOL,0,(PBUNDLE)&newAreaBundle))
380 return FALSE;
381
382 if (GpiFullArc(GetDCData(pHps)->hps,DRO_FILL,MAKEFIXED((width-1)>>1,0)) == GPI_ERROR)
383 rc = FALSE;
384 GpiSetAttrs(GetDCData(pHps)->hps,PRIM_AREA,ABB_COLOR | ABB_MIX_MODE | ABB_SET | ABB_SYMBOL,0,(PBUNDLE)&oldAreaBundle);
385
386 return rc;
387}
388
389BOOL drawLinePoint(PVOID pHps,PPOINTLOS2 pt,LONG color)
390{
391 LINEBUNDLE lbOld, lbNew;
392 LONG defaults = GpiQueryAttrs(GetDCData(pHps)->hps, PRIM_LINE, LBB_COLOR, &lbOld);
393
394 lbNew.lColor = color;
395 BOOL rc = GpiSetAttrs(GetDCData(pHps)->hps,PRIM_LINE,LBB_COLOR,0,&lbNew);
396 if(rc == FALSE) {
397 dprintf(("GpiSetAttrs failed with %x", WinGetLastError(0)));
398 }
399 else {
400 rc = GpiSetPel(GetDCData(pHps)->hps,(PPOINTL)pt) != GPI_ERROR;
401 if(rc == FALSE) {
402 dprintf(("WARNING: GpiSetPel failed %x (invalid in path?); retrying with GpiLine", WinGetLastError(0)));
403 rc = GpiLine(GetDCData(pHps)->hps,(PPOINTL)pt) != GPI_ERROR;
404 }
405 }
406 if(rc == FALSE) {
407 dprintf(("GpiSetPel/GpiLine failed with %x", WinGetLastError(0)));
408 }
409
410 GpiSetAttrs(GetDCData(pHps)->hps,PRIM_LINE,LBB_COLOR,defaults,&lbOld);
411
412 return rc;
413}
414
415ULONG OSLibGpiQueryCp(HDC hdc)
416{
417 return GpiQueryCp(hdc);
418}
419
420BOOL OSLibGpiSetCp(HDC hdc, ULONG codepage)
421{
422 return GpiSetCp(hdc, codepage);
423}
424
425
426int OSLibGpiQueryFontMaxHeight(HDC hdc)
427{
428 FONTMETRICS metrics;
429 BOOL rc;
430
431 rc = GpiQueryFontMetrics(hdc, sizeof(metrics), &metrics);
432 if(rc) {
433 return max(metrics.lMaxBaselineExt,
434 max(metrics.lMaxAscender+metrics.lMaxDescender,
435 metrics.lInternalLeading+metrics.lEmHeight));
436 }
437 else {
438 dprintf(("GpiQueryFontMetrics returned FALSE!!"));
439 return 0;
440 }
441}
442
443#ifdef DEBUG
444void dprintfOrigin(HDC hdc)
445{
446 POINTL point;
447
448 pDCData pHps = (pDCData)OSLibGpiQueryDCData((HPS)hdc);
449 if(!pHps)
450 {
451 return;
452 }
453
454 GreGetDCOrigin(pHps->hps, &point);
455 dprintf2(("HDC %x origin (%d,%d) org (%d,%d)", hdc, point.x, point.y, pHps->ptlOrigin.x, pHps->ptlOrigin.y));
456}
457#endif
458//******************************************************************************
459//******************************************************************************
460BOOL OSLibDevQueryCaps(pDCData pHps, LONG lStart, LONG lCount, LONG *alArray)
461{
462 return DevQueryCaps(pHps->hdc, lStart, lCount, alArray);
463}
464//******************************************************************************
465//******************************************************************************
466BOOL OSLibGpiLoadFonts(LPSTR lpszFontFile)
467{
468 BOOL ret;
469
470 //We must use GpiLoadPublicFonts here. GpiLoadFonts cannot be used for
471 //queued printer device contexts
472 //-> NOTE: this is no longer the case as we spool printer specific data now (not metafiles)
473 ret = GpiLoadFonts(0, lpszFontFile);
474 if(ret == FALSE) {
475 dprintf(("GpiLoadPublicFonts %s failed with %x", lpszFontFile, WinGetLastError(0)));
476 }
477 return ret;
478}
479//******************************************************************************
480//******************************************************************************
481BOOL OSLibGpiUnloadFonts(LPSTR lpszFontFile)
482{
483 return GpiUnloadFonts(0, lpszFontFile);
484}
485//******************************************************************************
486//******************************************************************************
487BOOL OSLibGpiQueryFontName(LPSTR lpszFileName, LPSTR lpszFamily, LPSTR lpszFace, int cbString)
488{
489 LONG cFonts = 0, cRemFonts;
490 PFFDESCS pffd = NULL;
491 ULONG cb;
492
493 cRemFonts = GpiQueryFontFileDescriptions(0, lpszFileName, &cFonts, NULL);
494 if(cRemFonts == GPI_ALTERROR) {
495 DebugInt3();
496 return FALSE;
497 }
498
499 cFonts = max(cFonts, cRemFonts);
500 cb = cFonts * sizeof(FFDESCS) + 100; // must allocate extra
501 pffd = (PFFDESCS)malloc(cb);
502 if(pffd == NULL) {
503 DebugInt3();
504 return FALSE;
505 }
506
507 memset(pffd, 0, cb);
508
509 //assuming one font for now
510 cFonts = 1;
511 if(GpiQueryFontFileDescriptions(0, lpszFileName, &cFonts, pffd) == 0)
512 {
513 strncpy(lpszFamily, (char *)pffd, cbString);
514 strncpy(lpszFace, (char *)pffd + FACESIZE, cbString);
515 }
516 free(pffd);
517 return TRUE;
518}
519//******************************************************************************
520//******************************************************************************
521BOOL ReallySetCharAttrs(PVOID lpHps)
522{
523 BOOL bRet = FALSE;
524 pDCData pHps = (pDCData)lpHps;
525
526 if(pHps)
527 {
528 if(!pHps->bAttrSet)
529 {
530 if (!pHps->bFirstSet) {
531 pHps->bFirstSet = TRUE;
532 }
533 if (pHps->ulCharMask) {
534 bRet = GpiSetAttrs(pHps->hps, PRIM_CHAR, pHps->ulCharMask, 0, &pHps->CBundle);
535 } else {
536 bRet = TRUE;
537 }
538 if(bRet == TRUE) {
539 pHps->CSetBundle = pHps->CBundle;
540 pHps->ulCharMask = 0;
541 pHps->bAttrSet = TRUE;
542 }
543 }
544 }
545 return(bRet);
546}
547//******************************************************************************
548//******************************************************************************
Note: See TracBrowser for help on using the repository browser.