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