home *** CD-ROM | disk | FTP | other *** search
/ OS/2 Shareware BBS: 10 Tools / 10-Tools.zip / ool_main.zip / ool / source / xgraphob.cpp < prev    next >
C/C++ Source or Header  |  1998-04-06  |  43KB  |  1,391 lines

  1. #include "XGraphOb.h"
  2. #include "XGraphDv.h"
  3. #include "XLine.h"
  4. #include "XColor.h"
  5. #include "XRect.h"
  6. #include "XFont.h"
  7. #include "XCircle.h"
  8. #include "XText.h"
  9. #include "XBox.h"
  10. #include "XMarker.h"
  11. #include "XBitmap.h"
  12. #include "XFile.h"
  13. #include "XFileInf.h"
  14. #include "XRes.h"
  15. #include "XResLib.h"
  16. #include "XArc.h"
  17. #include "xmsgbox.h"
  18. #include "xexcept.h"
  19. #include <stdlib.h>
  20. #include <string.h>
  21. #include "xapp.h"
  22. #include <stdlib.h>
  23.  
  24.  
  25. /*@
  26. @class XGraphicObject
  27. @parent XObject
  28. @type overview
  29. @symbol _
  30. */
  31.  
  32. /*@ XGraphicObject::Draw( XGraphicDevice * dev )
  33. @group drawing
  34. @remarks Draw the graphic primitive on a screen or printer
  35. @parameters XGraphicDevice * the device to draw on
  36. */
  37.  
  38. XGraphicObject :: XGraphicObject(const XPoint * point)
  39. {
  40.    settings = 0;
  41.    if (point)
  42.       p = *point;
  43.    color.SetColor(0);
  44. }
  45.  
  46.  
  47. XGraphicObject :: XGraphicObject(const LONG x, const LONG y)
  48. {
  49.    p.SetX(x);
  50.    p.SetY(y);
  51.    color.SetColor(0);
  52.    settings = 0;
  53. }
  54.  
  55.  
  56. /*@ XGraphicObject::Show(const BOOL show)
  57. @group misc
  58. @remarks Show/hide the object
  59. @parameters   BOOL show      TRUE=show, FALSE=hide
  60. */
  61. void XGraphicObject::Show(const BOOL show)
  62. {
  63.    if (show)
  64.    {
  65.       if (settings & GO_HIDE)
  66.          settings ^= GO_HIDE;
  67.    }
  68.    else
  69.       settings |= GO_HIDE;
  70. //   Draw();
  71. }
  72.  
  73.  
  74. XMarker :: XMarker(const XPoint * point, const SHORT t):XGraphicObject( point)
  75. {
  76.    type = t;
  77.    size.SetWidth(10);
  78.    size.SetHeight(10);
  79. }
  80.  
  81.  
  82. void XMarker::SetupDevice( XGraphicDevice * dev)
  83. {
  84.    XGraphicObject::SetupDevice(dev);
  85.    if (dev->markerType != type)
  86.    {
  87.       dev->markerType = type;
  88.       GpiSetMarker(dev->hps, type);
  89.    }
  90.    SIZEF s;
  91.  
  92.    s.cx = MAKEFIXED(size.GetWidth(), 0);
  93.    s.cy = MAKEFIXED(size.GetHeight(), 0);
  94.    GpiSetMarkerBox(dev->hps, &s);
  95. }
  96.  
  97.  
  98. void XMarker::Draw( XGraphicDevice * dev)
  99. {
  100.    if (!(settings & GO_HIDE))
  101.    {
  102.       SetupDevice(dev);
  103.       POINTL po;
  104.       po.x = p.x;
  105.       po.y = p.y;
  106.       GpiMove(dev->hps, &po);
  107.       GpiMarker(dev->hps, &po);
  108.    }
  109. }
  110.  
  111.  
  112. void XLine::SetupDevice( XGraphicDevice * dev)
  113. {
  114.    XGraphicObject::SetupDevice(dev);
  115.    if (lineJoin != dev->aktLineJoining)
  116.       dev->SetLineJoin(lineJoin);
  117.    if (lineEnd != dev->aktLineEnding)
  118.       dev->SetLineEnd(lineEnd);
  119.    if (lineWidth != dev->aktLineWidth)
  120.       dev->SetLineWidth(lineWidth);
  121.    if (lineType != dev->aktLineType)
  122.       dev->SetLineType(lineType);
  123. }
  124.  
  125.  
  126. void XLine::Draw( XGraphicDevice * dev)
  127. {
  128.    if (!(settings & GO_HIDE))
  129.    {
  130.       POINTL po;
  131.       po.x = p.x;
  132.       po.y = p.y;
  133.       SetupDevice(dev);
  134.       GpiBeginPath(dev->hps, 1);
  135.       GpiMove(dev->hps, &po);
  136.       //POINTL ptl;// = po;
  137.  
  138.       po.x = p.x + width;
  139.       po.y = p.y + height;
  140.       GpiLine(dev->hps, &po);
  141.       GpiEndPath(dev->hps);
  142.       GpiOutlinePath(dev->hps, 1, 0);
  143.    }
  144. }
  145.  
  146.  
  147. /*@
  148. @class XCircle
  149. @parent XLine
  150. @type overview
  151. @symbol _
  152. */
  153.  
  154.  
  155. /*@ XCircle :: XCircle(const XPoint * pp1, const ULONG wight, const BOOL fill, const USHORT hight, const SHORT xOff, const SHORT yOff)
  156. @group constructors/destructors
  157. @remarks Construct a circle
  158. @parameters   <t '°' c=2>
  159.             °XPoint * °position
  160.             °ULONG °width
  161.             °BOOL °TRUE=fill circle, FALSE=don∩t fill
  162.             °ULONG °if zero, height becomes width, otherwise an elipse is drawn (default is zero)
  163.             °SHORT °x-offset (default is zero)
  164.             °SHORT °y-offset (default is zero)
  165.             </t>
  166. */
  167. XCircle :: XCircle(const XPoint * pp1, const ULONG wight, const BOOL fill, const USHORT hight, const SHORT xOff, const SHORT yOff):XLine( pp1)
  168. {
  169.    w = wight;
  170.    h = (hight > 0 ? hight : wight);
  171.    x = xOff;
  172.    y = yOff;
  173.    filled = fill;
  174. }
  175.  
  176.  
  177. /*@
  178. @class XArc
  179. @parent XLine
  180. @type overview
  181. @symbol _
  182. */
  183.  
  184. /*@ XArc :: XArc(const XPoint * pp1, const SHORT wight, const SHORT startAngle, const SHORT sweepAngle, const BOOL showLines, const BOOL fill, const SHORT hight, const SHORT xOff, const SHORT yOff)
  185. @group constructors/destructors
  186. @remarks Construct an arc
  187. @parameters   <t '°' c=2>
  188.             °XPoint * °position
  189.             °SHORT °width
  190.             °SHORT °starting angle
  191.             °SHORT °ending angle
  192.             °BOOL °TRUE=fill circle, FALSE=don∩t fill
  193.             °ULONG °if zero, height becomes width, otherwise an elipse is drawn (default is zero)
  194.             °SHORT °x-offset (default is zero)
  195.             °SHORT °y-offset (default is zero)
  196.             </t>
  197. */
  198. XArc :: XArc(const XPoint * pp1, const SHORT wight, const SHORT startAngle, const SHORT sweepAngle, const BOOL showLines, const BOOL fill, const SHORT hight, const SHORT xOff, const SHORT yOff):XLine(pp1)
  199. {
  200.    settings = 0;
  201.    st = startAngle;
  202.    en = sweepAngle;
  203.    vis = showLines;
  204.    w = wight;
  205.    h = (hight > 0 ? hight : wight);
  206.    x = xOff;
  207.    y = yOff;
  208.    filled = fill;
  209. }
  210.  
  211.  
  212. void XArc::Draw( XGraphicDevice * dev)
  213. {
  214.    if (!(settings & GO_HIDE))
  215.    {
  216.       SetupDevice(dev);
  217.  
  218.       POINTL po;
  219.       po.x = p.x;
  220.       po.y = p.y;
  221.       GpiMove(dev->hps, &po);
  222.       ARCPARAMS a;
  223.  
  224.       a.lQ = w;
  225.       a.lP = h;
  226.       a.lR = x;
  227.       a.lS = y;
  228.  
  229.       GpiSetArcParams(dev->hps, &a);
  230.  
  231.       if (vis)
  232.       {
  233.          GpiBeginPath(dev->hps, 1);
  234.          GpiPartialArc(dev->hps, &po, MAKEFIXED(1, 0), MAKEFIXED(st, 0), MAKEFIXED(en, 0));
  235.          GpiLine(dev->hps, &po);
  236.          GpiEndPath(dev->hps);
  237.          if (filled)
  238.             GpiFillPath(dev->hps, 1, FPATH_WINDING);
  239.          else
  240.             GpiOutlinePath(dev->hps, 1, 0);
  241.       }
  242.       else
  243.       {
  244.          POINTL pt[3];
  245.  
  246. //berechnen!
  247.          pt[0].x = pt[0].y = 0;
  248.          GpiMove(dev->hps, &pt[0]);
  249.          pt[1].x = pt[1].y = 100;
  250.          pt[2].x = 200;
  251.          pt[2].y = 0;
  252.          GpiPointArc(dev->hps, &pt[1]);
  253.       }
  254.    }
  255. }
  256.  
  257.  
  258. void XCircle::Draw( XGraphicDevice * dev)
  259. {
  260.    if (!(settings & GO_HIDE))
  261.    {
  262. //       SHORT modify = ( w> 10 ? 10 : 1);
  263.  
  264.       SetupDevice(dev);
  265.       POINTL po;
  266.       po.x = p.x;
  267.       po.y = p.y;
  268.       GpiMove(dev->hps, &po);
  269.       ARCPARAMS a;
  270.  
  271.       a.lQ = w / 10;
  272.       a.lP = h / 10;
  273.       a.lR = x / 10;
  274.       a.lS = y / 10;
  275.       GpiSetArcParams(dev->hps, &a);
  276.       GpiFullArc(dev->hps, (filled == FALSE ? DRO_OUTLINE : DRO_FILL), MAKEFIXED(10, 0));
  277.    }
  278. }
  279.  
  280.  
  281. /*@
  282. @class XLine
  283. @parent XGraphicObject
  284. @type overview
  285. @symbol _
  286. */
  287.  
  288.  
  289. /*@ XLine :: XLine(const XPoint * pp1, const XPoint * pp2)
  290. @group constructors/destructors
  291. @remarks Construct a line object
  292. @parameters   <t '°' c=2>
  293.             °XPoint * p1                  °start point
  294.             °XPoint * p2                  °end point
  295.             </t>
  296. */
  297. XLine :: XLine(const XPoint * pp1, const XPoint * pp2):XGraphicObject(pp1)
  298. {
  299.    lineEnd = LINEEND_DEFAULT;
  300.    lineJoin = LINEJOIN_DEFAULT;
  301.    lineWidth = LINEWIDTH_DEFAULT;
  302.    lineType = LINETYPE_DEFAULT;
  303.    if (pp2)
  304.    {
  305.       width = pp2->x - p.x;
  306.       height = pp2->y - p.y;
  307.    }
  308.    else
  309.       width = height = 0;
  310. }
  311.  
  312.  
  313. /*@
  314. @class XFont
  315. @parent XObject
  316. @type overview
  317. @symbol _
  318. */
  319.  
  320. /*@ XFont :: XFont(XGraphicDevice * dev, const char *fontName, const SHORT size, const LONG options)
  321. @group constructors/destructors
  322. @remarks Construct a font
  323. @parameters   <t '°' c=2>
  324.             °XGraphicDevice * device      °owner
  325.             °char * fontName            °name of the font
  326.             °SHORT size                  °size
  327.             °LONG options               °options
  328.             </t>
  329. */
  330. XFont :: XFont(XGraphicDevice * dev, const char *fontName, const SHORT size, const LONG options)
  331. {
  332.    // dev->fontId+=1;
  333.    fontId = dev->fonts + 1;
  334.    fontSize = size;
  335.    LONG cFont;               /* Fonts Count   */
  336.    LONG lFontsTotal = 0L;      /* Fonts Total Count   */
  337.    LONG lXDeviceRes;         /* x Device Resolution  */
  338.    LONG lYDeviceRes;         /* y Device Resolution  */
  339.    PFONTMETRICS pfmSelect;      /* Font Metrics Pointer  */
  340.    FATTRS fat;               /* Font Attributes   */
  341.    register INT i;            /* Loop Counter   */
  342.  
  343.    LONG lNominalPointSize = size * 10;
  344.  
  345.    DevQueryCaps(dev->hdc, CAPS_HORIZONTAL_FONT_RES, 1L, &lXDeviceRes);
  346.    DevQueryCaps(dev->hdc, CAPS_VERTICAL_FONT_RES, 1L, &lYDeviceRes);
  347.    realSize = size;
  348.    if ((cFont = GpiQueryFonts(dev->hps, QF_PUBLIC, (PSZ) fontName, &lFontsTotal, sizeof(FONTMETRICS), (PFONTMETRICS) NULL)) != 0L)
  349.    {
  350.       DosAllocMem((PPVOID) (PVOID) & pfmSelect, (ULONG) (sizeof(FONTMETRICS) * cFont), PAG_READ | PAG_WRITE | PAG_COMMIT);
  351.  
  352.       GpiQueryFonts(dev->hps, QF_PUBLIC, (PSZ) fontName, &cFont, sizeof(FONTMETRICS), pfmSelect);
  353.  
  354.       for (i = 0; i < (INT) cFont; i++)
  355.          if ((pfmSelect[i].sXDeviceRes == (SHORT) lXDeviceRes) && (pfmSelect[i].sYDeviceRes == (SHORT) lYDeviceRes) && ((LONG) pfmSelect[i].sNominalPointSize == lNominalPointSize))
  356.          {
  357.             memset(&fat, 0, sizeof(FATTRS));
  358.             fat.usRecordLength = sizeof(FATTRS);
  359.             strcpy(fat.szFacename, fontName);
  360.             fat.lMatch = pfmSelect[i].lMatch;
  361.             fat.fsSelection = (USHORT) options;
  362.             DosFreeMem((PVOID) pfmSelect);
  363.             fixed = TRUE;
  364.             GpiCreateLogFont(dev->hps, (PSTR8) NULL, fontId, &fat);
  365.             dev->RegisterFont(this);
  366.             dev->SetFont(this);
  367.             return;
  368.          }
  369.  
  370.       for (i = 0; i < (INT) cFont; i++)
  371.          if ((pfmSelect[i].sXDeviceRes == 1000) && (pfmSelect[i].sYDeviceRes == 1000))
  372.          {
  373.             memset(&fat, 0, sizeof(FATTRS));
  374.             fat.usRecordLength = sizeof(FATTRS);
  375.             strcpy(fat.szFacename, fontName);
  376.             fat.lMatch = pfmSelect[i].lMatch;
  377.             fat.usCodePage = 850;
  378.             fat.fsFontUse = FATTR_FONTUSE_OUTLINE | FATTR_FONTUSE_TRANSFORMABLE;
  379.             fat.fsSelection = (USHORT) options;
  380.  
  381.             DosFreeMem((PVOID) pfmSelect);
  382.             GpiCreateLogFont(dev->hps, (PSTR8) NULL, fontId, &fat);
  383.             fontSize = lNominalPointSize;
  384.             fixed = FALSE;
  385.             dev->RegisterFont(this);
  386.             dev->SetFont(this);
  387.             return;
  388.          }
  389.       DosFreeMem((PVOID) pfmSelect);
  390.    }
  391. }
  392.  
  393.  
  394. /*@
  395. @class XText
  396. @parent XGraphicObject
  397. @type overview
  398. @symbol _
  399. */
  400.  
  401.  
  402. /*@ XText :: XText(const XFont * f, const XRect * rect, const char *s, const SHORT sty)
  403. @group constructors/destructors
  404. @remarks Construct a text object, this constructor should only be used with XGraphicDevice, not with XPrinterDevice
  405. @parameters   <t '°' c=2>
  406.             °XFont * font               °font to use
  407.             °XRect * rect               °rectangle
  408.             °char * text                  °the text to print
  409.             °SHORT style               °style, possible values are:
  410. <BR>
  411. TX_TOP
  412. <BR>
  413. TX_VCENTER
  414. <BR>
  415. TX_BOTTOM
  416. <BR>
  417. TX_LEFT
  418. <BR>
  419. TX_CENTER
  420. <BR>
  421. TX_RIGHT
  422. <BR>
  423. TX_WORDBREAK
  424.             </t>
  425. */
  426. XText :: XText(const XFont * f, const XRect * rect, const char *s, const SHORT sty):XGraphicObject(rect->GetX(), rect->GetY())
  427. {
  428.    font = (XFont *) f;
  429. //   dev->SetFont(font);
  430.    sh.x = sh.y = 0;
  431.    an.x = an.y = 0;
  432.    style = sty;
  433.    if (s)
  434.       text = s;
  435.    p2.x = rect->cx + rect->x;
  436.    p2.y = rect->cy + rect->y;
  437. }
  438.  
  439.  
  440. /*@ XText :: XText(const XFont * f, const XPoint * p, const char *s)
  441. @group constructors/destructors
  442. @remarks Construct a text object.
  443. @parameters   <t '°' c=2>
  444.             °XGraphicDevice * device      °owner
  445.             °XFont * font               °font to use
  446.             °XPoint * point               °base point
  447.             °char * text                  °the text to print
  448.             </t>
  449. */
  450. XText :: XText(const XFont * f, const XPoint * p, const char *s):XGraphicObject(p)
  451. {
  452.    settings = 0;
  453.    font = (XFont *) f;
  454.  
  455.    sh.x = sh.y = 0;
  456.    an.x = an.y = 0;
  457.    style = 0;
  458.    p2.x = p2.y = 0;
  459.    if (s)
  460.       text = s;
  461. }
  462.  
  463.  
  464. void XText::GetTextBox(XGraphicDevice * dev, XRect * r)
  465. {
  466.    POINTL ptl[TXTBOX_COUNT];
  467.  
  468.    SetupDevice(dev);
  469.    GpiQueryTextBox(dev->hps, text.GetLength(), (PSZ) (char*) text, TXTBOX_COUNT, ptl);
  470.    r->SetX(ptl[TXTBOX_BOTTOMLEFT].x);
  471.    r->SetWidth(ptl[TXTBOX_BOTTOMRIGHT].x - ptl[TXTBOX_BOTTOMLEFT].x);
  472.    r->SetY(ptl[TXTBOX_BOTTOMLEFT].y);
  473.    r->SetWidth(ptl[TXTBOX_TOPLEFT].y - ptl[TXTBOX_BOTTOMLEFT].y);
  474. }
  475.  
  476.  
  477. void XText::SetupDevice(XGraphicDevice * dev)
  478. {
  479.    XGraphicObject::SetupDevice(dev);
  480. //////   if (dev->aktFont != font->fontId)
  481.       dev->SetFont(font);
  482.  
  483.    GpiSetCharShear(dev->hps, &sh);
  484.    GpiSetCharAngle(dev->hps, &an);
  485. }
  486.  
  487.  
  488. void XText::Draw( XGraphicDevice * dev)
  489. {
  490.    if (!(settings & GO_HIDE))
  491.    {
  492.       SetupDevice(dev);
  493.  
  494.       if (p2.GetX() == 0)
  495.       {
  496.          POINTL pnt;
  497.  
  498.          pnt.x = p.GetX();
  499.          pnt.y = p.GetY();
  500.          GpiCharStringAt(dev->hps, &pnt, text.GetLength(), (PSZ) (char*) text);
  501.       }
  502.       else
  503.       {
  504.          RECTL rc;
  505.  
  506.          rc.yBottom = p.y + dev->yOffset;
  507.          rc.yTop = p2.y + dev->yOffset;
  508.          rc.xLeft = p.x + dev->xOffset;
  509.          rc.xRight = p2.x + dev->xOffset;
  510.          char *t = text;
  511.  
  512.          if (style & DT_WORDBREAK)
  513.          {
  514.             int drawn = 0, totalDrawn, length = text.GetLength();
  515.  
  516.             for (totalDrawn = 0; totalDrawn < length; rc.yTop -= (LONG) (font->realSize))
  517.             {
  518.                drawn = WinDrawText(dev->hps, length - totalDrawn, (PSZ) t + totalDrawn, &rc, color.GetColor(), 0, style);
  519.                if (drawn)
  520.                   totalDrawn += drawn;
  521.                else
  522.                   break;
  523.             }
  524.          }
  525.          else
  526.             WinDrawText(dev->hps, text.GetLength(), (PCH) t, &rc, color.GetColor(), 0, style);
  527.       }
  528.       return;
  529.    }
  530. }
  531.  
  532.  
  533. /*@
  534. @class XBox
  535. @parent XLine
  536. @type overview
  537. @symbol _
  538. */
  539.  
  540.  
  541. /*@ XBox :: XBox(const XPoint * pp1, const XPoint * pp2, const BOOL f)
  542. @group constructors/destructors
  543. @remarks Construct a visible rectangle/box
  544. @parameters   <t '°' c=2>
  545.             °XPoint * p1                  °left-lower corner
  546.             °XPoint * p2                  °right-upper corner
  547.             °BOOL fill                  °TRUE=fill box, FALSE=don∩t fill
  548.             </t>
  549. */
  550. XBox :: XBox(const XPoint * pp1, const XPoint * pp2, const BOOL f):XLine(pp1, pp2)
  551. {
  552.    settings = 0;
  553.    fill = f;
  554. }
  555.  
  556.  
  557. void XBox::Draw(XGraphicDevice * dev)
  558. {
  559.    if (!(settings & GO_HIDE))
  560.    {
  561.       XLine::SetupDevice(dev);
  562.  
  563.       POINTL ptl[5], po;
  564.  
  565.       po.x = p.x;
  566.       po.y = p.y;
  567.       ptl[0].x = ptl[4].x = p.x;
  568.       ptl[0].y = ptl[4].y = p.y;
  569.       ptl[1].x = p.x;
  570.       ptl[1].y = ptl[2].y = height + p.y;
  571.       ptl[3].x = ptl[2].x = width + p.x;
  572.       ptl[3].y = p.y;
  573.  
  574.       GpiBeginPath(dev->hps, 1);
  575.       GpiMove(dev->hps, &po);
  576.       GpiPolyLine(dev->hps, 5, ptl);
  577.       GpiEndPath(dev->hps);
  578.  
  579.       if (fill)
  580.          GpiFillPath(dev->hps, 1, FPATH_ALTERNATE);
  581.       else
  582.          GpiOutlinePath(dev->hps, 1, 0);
  583. //          GpiStrokePath( dev->hps, 1, 0);
  584.    }
  585. }
  586.  
  587.  
  588. char *pszdata[8] = {"Display", NULL, NULL, NULL, NULL, NULL, NULL};
  589. SIZEL g = {0, 0};
  590.  
  591.  
  592.  
  593. /*@
  594. @class XBitmap
  595. @parent XGraphicObject
  596. @type overview
  597. @symbol _
  598. */
  599.  
  600.  
  601. /*@ XBitmap: : XBitmap(const XWindow * w)
  602. @group constructors/destructors
  603. @remarks Construct a bitmap. Dont use this constructor for usage with a graphic device.
  604. @parameters   XWindow * owner      window to draw to
  605. */
  606. XBitmap :: XBitmap(const XWindow * w):XGraphicObject(NULL)
  607. {
  608.    owner = (XWindow *) w;
  609.    hps = 0;
  610.    hdc = 0;
  611.    hbm = 0;
  612.    mode = ROP_SRCCOPY;
  613.    width = height = cx = cy = 0;
  614. }
  615.  
  616.  
  617. /*@ XBitmap :: XBitmap(const XPoint * pp1, const LONG m)
  618. @group constructors/destructors
  619. @remarks Construct a bitmap
  620. @parameters   <t '°' c=2>
  621.             °XPoint * p                  °left-lower corner
  622.             °LONG mode                  °mode, default is ROP_SRCCOPY
  623.             </t>
  624. @exceptions   If the method fails an exception of the type XException is thrown.
  625. */
  626. XBitmap :: XBitmap(const XPoint * pp1, const LONG m):XGraphicObject(pp1)
  627. {
  628.    mode = m;
  629.    owner = NULL;
  630.    hdc = DevOpenDC(XApplication::GetApplication()->GetAnchorBlock(), OD_MEMORY, (PSZ) "*", 0, (PDEVOPENDATA) NULL, 0L);
  631.    if (hdc == 0)
  632.       OOLThrow("error creating device context", 4);
  633.    hps = GpiCreatePS(XApplication::GetApplication()->GetAnchorBlock(), hdc, &g, PU_PELS | GPIA_ASSOC);
  634.    if (hps == 0)
  635.       OOLThrow("error creating presentation space", 5);
  636.    width = height = cx = cy = 0;
  637. }
  638.  
  639.  
  640. void XBitmap::Draw( XGraphicDevice * dev)
  641. {
  642.    if (!(settings & GO_HIDE))
  643.    {
  644.       POINTL aptl[4];
  645.  
  646.       aptl[0].x = p.GetX() - dev->xOffset;
  647.       aptl[0].y = p.GetY() - dev->yOffset;
  648.       aptl[1].x = aptl[0].x + width;
  649.       aptl[1].y = aptl[0].y + height;
  650.       aptl[2].x = aptl[2].y = 0;
  651.       aptl[3].x = cx;
  652.       aptl[3].y = cy;
  653.       GpiSetBitmap(hps, 0);
  654.       GpiWCBitBlt(dev->hps, hbm, 4L, (PPOINTL) aptl, mode, BBO_IGNORE);
  655.    }
  656. }
  657.  
  658.  
  659. XBitmap :: ~XBitmap()
  660. {
  661.    GpiDeleteBitmap(hbm);
  662.    GpiDestroyPS(hps);
  663.    DevCloseDC(hdc);
  664.    hbm = 0;
  665.    hps = 0;
  666.    hdc = 0;
  667. }
  668.  
  669.  
  670. /*@ XBitmap::GetDimensions(XSize*)
  671. @group misc
  672. @remarks Returns the dimensions
  673. @parameters   XSize * size      buffer to hold the size
  674. */
  675. void XBitmap::GetDimensions( XSize * size) const
  676. {
  677.    BITMAPINFOHEADER phd;
  678.  
  679.    GpiQueryBitmapParameters(hbm, &phd);
  680.    size->SetWidth( phd.cx );
  681.    size->SetHeight( phd.cy );
  682. }
  683.  
  684.  
  685. void XBitmap::Load( const ULONG id, const XResourceLibrary * lib)
  686. {
  687.    if (hbm)
  688.       GpiDeleteBitmap(hbm);
  689.    if (owner && hps == 0)
  690.       hps = WinGetPS(owner->GetHandle());
  691.    hbm = GpiLoadBitmap(hps, lib->GetModuleHandle(), id, 0, 0);
  692.  
  693.    if (hbm == GPI_ERROR)
  694.    {
  695.        ULONG error = WinGetLastError(XApplication::GetApplication()->GetAnchorBlock());
  696.       OOLThrow("couldn∩t load bitmap", error);
  697.    }
  698.  
  699.    XSize s;
  700.    GetDimensions(&s);
  701.    width = cx = s.GetWidth();
  702.    height = cy = s.GetHeight();
  703. }
  704.  
  705.  
  706. /*@ XBitmap::Load(const XResource * r)
  707. @group loading a bitmap
  708. @remarks load a bitmap from a resource library
  709. @parameters   XResource * resource
  710. */
  711. void XBitmap::Load(const XResource * r)
  712. {
  713.    Load( r->GetID(), r->GetResourceLibrary());
  714. }
  715.  
  716.  
  717. void XBitmap::Load(const ULONG id)
  718. {
  719.    Load( id, XApplication::GetApplication()->GetResourceLibrary());
  720. }
  721.  
  722.  
  723. /*@ XBitmap :: Fill( XColor * color)
  724. @remarks Does not work
  725. */
  726. void XBitmap :: Fill( XColor * color)
  727. {
  728. //   LONG line[15];
  729.  
  730. //   for( int i = 0; i < 15; i++)
  731. //      line[i] = color->GetColor();
  732.    GpiSetBitmap( hps, hbm);
  733.    GpiFloodFill( hps, FF_SURFACE, color->GetColor());
  734. }
  735.  
  736.  
  737. XBitmap XBitmap::operator = (const XBitmap & b)
  738. {
  739. /****
  740.    BITMAPINFOHEADER2 * head;
  741.  
  742.    head = (BITMAPINFOHEADER2 *) malloc( sizeof(BITMAPINFOHEADER2));
  743.    owner = b.owner;
  744.  
  745.    if (owner && hps == 0)
  746.       hps = WinGetPS(owner->GetHandle());
  747.  
  748.    if (hbm != 0)
  749.       GpiDeleteBitmap(hbm);
  750.  
  751.    head->cbFix = sizeof(BITMAPINFOHEADER2);
  752.  
  753.    GpiSetBitmap(b.hps, b.hbm);
  754.    if( GpiQueryBitmapInfoHeader(b.hbm, head) == FALSE)
  755.       OOLThrow("error copying bitmap", 3);
  756.  
  757.    LONG offBits = sizeof(BITMAPINFO2) + (sizeof(RGB2) * (1 << head->cBitCount));
  758.  
  759.    LONG size = (((head->cBitCount * head->cx) + 31) / 32) * 4 * head->cPlanes * head->cy;
  760.  
  761.    head = (BITMAPINFOHEADER2 *) realloc(head, offBits);
  762.  
  763.    void * buffer = malloc(size);
  764.    if( GpiQueryBitmapBits(b.hps, 0, head->cy, (PBYTE) buffer, (BITMAPINFO2 *) head) == GPI_ALTERROR)
  765.       OOLThrow("error query bitmap data", 3);
  766.  
  767. //   hbm = GpiCreateBitmap(hps, (PBITMAPINFOHEADER2) &p->bmp, CBM_INIT, (PBYTE) p + p->offBits, (PBITMAPINFO2) &p->bmp);
  768.    hbm = GpiCreateBitmap(hps, (PBITMAPINFOHEADER2) head, CBM_INIT, (PBYTE) buffer, (PBITMAPINFO2) head);
  769.    if(hbm == 0)
  770.       XProcess::Beep(300,300);
  771.  
  772.    GpiSetBitmap(hps, hbm);
  773.  
  774.    XSize s;
  775.    b.GetDimensions(&s);
  776.    cx = s.GetWidth();
  777.    cy = s.GetHeight();
  778.  
  779.    width = b.width;
  780.    height = b.height;
  781.    p = b.p;
  782.    free(head);
  783.    free(buffer);
  784.    return *this;
  785. ****/
  786.    BITMAPFILEHEADER2 * head;
  787.  
  788.    owner = b.owner;
  789.  
  790.    if (owner && hps == 0)
  791.       hps = WinGetPS(owner->GetHandle());
  792.  
  793.    if (hbm != 0)
  794.       GpiDeleteBitmap(hbm);
  795.  
  796.    head = (BITMAPFILEHEADER2 *) malloc(sizeof(BITMAPFILEHEADER2));
  797.    head->bmp2.cbFix = sizeof(BITMAPINFOHEADER2);
  798.  
  799.    GpiQueryBitmapInfoHeader(b.hbm, &head->bmp2);
  800.    head->offBits = sizeof(BITMAPFILEHEADER2) + (sizeof(RGB2) * (1 << head->bmp2.cBitCount));
  801.    LONG size = head->offBits + (((head->bmp2.cBitCount * head->bmp2.cx) + 31) / 32) * 4 * head->bmp2.cPlanes * head->bmp2.cy;
  802.  
  803.    head = (BITMAPFILEHEADER2 *) realloc(head, size);
  804.  
  805.    head->usType = BFT_BMAP;
  806.    head->xHotspot = head->yHotspot = 0;
  807.    head->cbSize = sizeof(BITMAPFILEHEADER2);
  808.    GpiSetBitmap(hps, b.hbm);
  809. /***
  810. head->bmp2.cbFix=16;
  811. head->bmp2.cPlanes =1;
  812. head->bmp2.cBitCount = 1;
  813. ****/
  814.    GpiQueryBitmapBits(hps, 0, head->bmp2.cy, (PBYTE) head + head->offBits, (BITMAPINFO2 *) &head->bmp2);
  815.    hbm = GpiCreateBitmap(hps, (PBITMAPINFOHEADER2) &head->bmp2, CBM_INIT, (PBYTE) head + head->offBits, (PBITMAPINFO2) &head->bmp2);
  816.  
  817.    GpiSetBitmap(hps, hbm);
  818.  
  819.    XSize s;
  820.    b.GetDimensions(&s);
  821.    cx = s.GetWidth();
  822.    cy = s.GetHeight();
  823.  
  824.    width = b.width;
  825.    height = b.height;
  826.    p = b.p;
  827.    free(head);
  828.  
  829.    return *this;
  830. }
  831.  
  832.  
  833. LONG XBitmap::SetData(const BITMAPINFOHEADER2 * p, const LONG offset)
  834. {
  835.    LONG cScans;
  836.    BITMAPINFOHEADER2 *data;
  837.  
  838.    LONG size = (((((BITMAPINFOHEADER2 *) p)->cBitCount * ((BITMAPINFOHEADER2 *) p)->cx) + 31) / 32) * 4 * ((BITMAPINFOHEADER2 *) p)->cPlanes * ((BITMAPINFOHEADER2 *) p)->cy;
  839.  
  840.    data = (PBITMAPINFOHEADER2) malloc(size);
  841.    memcpy(data, p, size);
  842.  
  843.    if (data->cbFix == sizeof(BITMAPINFOHEADER))
  844.       cScans = (ULONG) ((PBITMAPINFOHEADER) data)->cy;
  845.    else
  846.       cScans = data->cy;
  847.  
  848.    if (hbm != 0)
  849.       GpiDeleteBitmap(hbm);
  850.  
  851.    hbm = GpiCreateBitmap(hps, data, CBM_INIT, (PBYTE) p + offset, (PBITMAPINFO2) data);
  852.  
  853.    if (hbm == GPI_ERROR)
  854.       OOLThrow("error creating bitmap", 3);
  855.  
  856.    free(data);
  857.  
  858.    return 0;
  859. }
  860.  
  861.  
  862. /*@ XBitmap::Copy(const XGraphicDevice * d, const XPoint * p)
  863. @group misc
  864. @remarks copy the content of the bitmap to a graphic device
  865. @parameters
  866. <t '°' c=2>
  867. °XGraphicDevice * °target
  868. °XPoint * °point to copy to
  869. </t>
  870. */
  871. void XBitmap::Copy(const XGraphicDevice * d, const XPoint * p)
  872. {
  873.    POINTL aptl[4];
  874.  
  875.    aptl[0].x = 0;
  876.    aptl[0].y = 0;
  877.    aptl[1].x = width;
  878.    aptl[1].y = height;
  879.    aptl[2].x = p->GetX();
  880.    aptl[2].y = p->GetY();
  881.    GpiBitBlt(hps, d->hps, 3, aptl, mode, BBO_IGNORE);
  882. }
  883.  
  884. BOOL XBitmap::HitTest(const LONG x, const LONG y)
  885. {
  886.    if (x > p.GetX() && x < p.GetX() + width && y > p.GetY() && y < p.GetY() + height)
  887.       return TRUE;
  888.    else
  889.       return FALSE;
  890. }
  891.  
  892.  
  893. /*@ XText::SetText()
  894. @group misc
  895. @remarks Set text to draw
  896. @parameters   char * theText
  897. */
  898.  
  899.  
  900. /*@ XText::SetStyle()
  901. @group style
  902. @remarks Set the style to use (not with XPrinterDevice)
  903. @parameters   LONG style, possible values are:
  904. <UL>
  905. <LI>TX_TOP
  906. <LI>TX_VCENTER
  907. <LI>TX_BOTTOM
  908. <LI>TX_LEFT
  909. <LI>TX_CENTER
  910. <LI>TX_RIGHT
  911. <LI>TX_WORDBREAK
  912. </UL>
  913. */
  914.  
  915.  
  916. /*@ XText::GetStyle()
  917. @group style
  918. @remarks Query the current style
  919. @returns LONG theStyle
  920. */
  921.  
  922.  
  923. /*@ XBitmap::SetOutputSize()
  924. @group misc
  925. @remarks Set the size of the bitmap to draw. If it is diferent from it physical size, the bitmap will be stretched.
  926. @parameters   XRect * rect   new rect (only width and height will be used)
  927. */
  928.  
  929.  
  930. /*@ XGraphicObject::Move()
  931. @group position/size
  932. @remarks Move the object to a new place
  933. @parameters   XPoint * p                  point to move to
  934. */
  935.  
  936.  
  937. /*@ XGraphicObject::SetPattern()
  938. @group misc
  939. @remarks Set a fill-patern for the object
  940. @parameters   SHORT patternIndex      index of fill-patern (0-255)
  941. */
  942.  
  943.  
  944. /*@ XGraphicObject::SetColor()
  945. @group color
  946. @remarks Set the color
  947. @parameters   XColor * color      the new color
  948. */
  949.  
  950.  
  951. /*@ XGraphicObject::GetColor()
  952. @group color
  953. @remarks Get the current color
  954. @parameters   XColor * color      buffer to hold the color
  955. */
  956.  
  957.  
  958. /*@ XFont::GetPixelSize()
  959. @group misc
  960. @remarks Returns the used count of pixels for the height of a single character. This size may differ
  961. from the logical size, escpacialy on a printer-device.
  962. @returns SHORT pixels
  963. */
  964.  
  965.  
  966.  
  967. /*@ XLine::SetLineWidth()
  968. @group settings
  969. @remarks Set the width of the line.
  970. @parameters SHORT width
  971. */
  972.  
  973.  
  974. /*@ XLine::SetLineJoin()
  975. @group settings
  976. @remarks Set the t<pe of the joining of lines.
  977. @parameters CHAR type
  978. */
  979.  
  980. /*@ XLine::SetLineType()
  981. @group settings
  982. @remarks Set the type of the line.
  983. @parameters CHAR type
  984. */
  985.  
  986. /*@ XLine::SetLineEnd()
  987. @group settings
  988. @remarks Set the type of line ending.
  989. @parameters CHAR type
  990. */
  991.  
  992. /*@ XBitmap::LoadBMP(const char* filename)
  993. @group loading a bitmap
  994. @remarks Load a bitmap from a file. This method works faster than Load() but can only load bitmpas in OS2-BMP format
  995. @parameters   char * fileName   filename of the file to load
  996. @exceptions   If the method fails to create a new bitmap an exception of the type XException is thrown.
  997. */
  998. void XBitmap :: LoadBMP(const char* filename)
  999. {
  1000.    if (hbm)
  1001.       GpiDeleteBitmap(hbm);
  1002.    hbm = 0;
  1003.  
  1004.    XFile file;
  1005.    PBITMAPFILEHEADER p;
  1006.    if (file.Open(filename, XFILE_FAIL_IF_NEW | XFILE_OPEN_EXISTING, XFILE_READONLY, XFILE_SHARE_DENYNONE ) == 0)
  1007.    {
  1008.       XFileInfo info;
  1009.       file.GetFileInfo(&info);
  1010.       file.Seek(0, XFILE_BEGIN);
  1011.       p = (PBITMAPFILEHEADER) malloc(info.GetFileSize());
  1012.       file.Read(p, info.GetFileSize());
  1013.       file.Close();
  1014.    }
  1015.    else
  1016.       OOLThrow( "couldn∩t open file!", -1);
  1017.  
  1018.    if (owner )
  1019.    {
  1020.       hps = WinGetPS(owner->GetHandle());
  1021.       hbm = GpiCreateBitmap(hps, (PBITMAPINFOHEADER2) &p->bmp, CBM_INIT, (PBYTE) p + p->offBits, (PBITMAPINFO2) &p->bmp);
  1022.       if(hbm == 0)
  1023.          OOLThrow("error creating bitmap", 3);
  1024.    }
  1025.    else
  1026.       SetData((BITMAPINFOHEADER2 *) &p->bmp, p->offBits);
  1027.    free(p);
  1028.    XSize s;
  1029.    GetDimensions(&s);
  1030.    width = cx = s.GetWidth();
  1031.    height = cy = s.GetHeight();
  1032.  
  1033.    if (hbm == GPI_ERROR)
  1034.    {
  1035.       ULONG error = WinGetLastError(XApplication::GetApplication()->GetAnchorBlock());
  1036.       OOLThrow("couldn∩t load bitmap", error);
  1037.    }
  1038.  
  1039.    return;
  1040. }
  1041.  
  1042.  
  1043. XBitmapFilterProfile* __XBMFProfile__ = NULL;
  1044. UCHAR                 __XBMFErrorMsg__ [1024];
  1045.  
  1046. #ifndef __IBMCPP__
  1047. typedef ULONG _System _export_ XGLibProcError (PULONG, XBitmapFilter*, PSZ, ULONG);
  1048. typedef ULONG _System _export_ XGLibProcProfInit (XBitmapFilterProfile*, ULONG, ULONG, ULONG);
  1049. typedef ULONG _System _export_ XGLibProcFltInit (const char*, XBitmapFilterProfile*, XBitmapFilter*, ULONG);
  1050. typedef ULONG _System _export_ XGLibProcSetup (HWND, const char*, XBitmapFilterProfile*, XBitmapFilter*);
  1051. typedef ULONG _System _export_ XGLibProcIO (const char*, XBitmapFilterProfile*, XBitmapFilter*, ULONG);
  1052. #else
  1053. typedef ULONG _System XGLibProcError (PULONG, XBitmapFilter*, PSZ, ULONG);
  1054. typedef ULONG _System XGLibProcProfInit (XBitmapFilterProfile*, ULONG, ULONG, ULONG);
  1055. typedef ULONG _System XGLibProcFltInit (const char*, XBitmapFilterProfile*, XBitmapFilter*, ULONG);
  1056. typedef ULONG _System XGLibProcSetup (HWND, const char*, XBitmapFilterProfile*, XBitmapFilter*);
  1057. typedef ULONG _System XGLibProcIO (const char*, XBitmapFilterProfile*, XBitmapFilter*, ULONG);
  1058. #endif
  1059. /*@ XBitmap::Load(const char* filename, XBitmapFilter * params, BOOL releaseParams)
  1060. @group loading a bitmap
  1061. @remarks Load a bitmap from a file. <P><I>If this method is used, GBM.DLL and OLLGLIB.DLL must be in the LIBPATH.</I> <P>Due a bug (?) in OS/2-GPI you should specify params->cBitCount = BFP_BPP_TRUECOLOR if you want to modify or resave the bitmap.
  1062. @parameters    <t '°' c=2>
  1063.                °char * fileName           °filename of the file to load
  1064.                °XBitmapFilter * params    °filetype specific filter informations. An initialized structure has to be created by XBitmap :: GetImportFilterStruct () or XGLibFileDialog. (default is NULL)
  1065.                °BOOL releaseParams        °filter informations will be released after usages
  1066.                <\t>
  1067. @exceptions   If the method fails to create a new bitmap an exception of the type XException is thrown.
  1068. */
  1069. void XBitmap :: Load (const char* filename, XBitmapFilter* params, BOOL releaseParams)
  1070. {
  1071.    if (hbm) GpiDeleteBitmap(hbm); hbm = NULLHANDLE;
  1072.  
  1073.    XResourceLibrary* lib = new XResourceLibrary ("OOLGLIB");
  1074.    XGLibProcIO* func = (XGLibProcIO*) lib->LoadFunction ("OOL_GLIB_IMP");
  1075.    DosSleep(100);
  1076.  
  1077.    if (NULL != func) {
  1078.       if (owner) hps = WinGetPS (owner->GetHandle());
  1079.  
  1080.       ULONG rc;
  1081.       if (NULL == params) params = GetImportFilterStruct (filename);
  1082.       params->hps = hps;
  1083.       params->hbm = hbm;
  1084.       params->hab = XApplication :: GetApplication ()->GetAnchorBlock ();
  1085.       if (BFE_OK != (rc = func (filename, __XBMFProfile__, params, 0))) {
  1086.          if (releaseParams) ReleaseFilterStruct (params);
  1087.          OOLThrow (GetLastErrorMessage (lib, &rc, params), rc);
  1088.       }
  1089.       hbm = params->hbm;
  1090.       if (releaseParams) ReleaseFilterStruct (params);
  1091.       lib->UnLoadFunction ((PFNWP) func);
  1092.    } else {
  1093.       if (releaseParams) ReleaseFilterStruct (params);
  1094.       ULONG error = WinGetLastError (XApplication :: GetApplication ()->GetAnchorBlock ());
  1095.       OOLThrow("Could not load function \"OOL_GLIB_IMP\" from library \"OOLGLIB.DLL\".", error);
  1096.    }
  1097.  
  1098.    delete lib;
  1099.    XSize s;
  1100.    GetDimensions(&s);
  1101.    width = cx = s.GetWidth();
  1102.    height = cy = s.GetHeight();
  1103. }
  1104.  
  1105. /*@ XBitmap::Save(const char* filename, XBitmapFilter * params, BOOL releaseParams)
  1106. @group saving a bitmap
  1107. @remarks Save a bitmap from a file. <P><I>If this method is used, GBM.DLL and OLLGLIB.DLL must be in the LIBPATH.</I> <P>Due a bug (?) in OS/2-GPI the bitmap should be in 24-bit-format.
  1108. @parameters    <t '°' c=2>
  1109.                °char * fileName           °filename of the file to load
  1110.                °XBitmapFilter * params    °filetype specific filter informations. An initialized structure has to be created by XBitmap :: GetImportFilterStruct () or XGLibFileDialog. (default is NULL)
  1111.                °BOOL releaseParams        °filter informations will be released after usages
  1112.                <\t>
  1113. @exceptions   If the method fails to create a new bitmap an exception of the type XException is thrown.
  1114. */
  1115. void XBitmap :: Save (const char* filename, XBitmapFilter* params, BOOL releaseParams)
  1116. {
  1117.    XResourceLibrary* lib = new XResourceLibrary ("OOLGLIB");
  1118.    XGLibProcIO* func = (XGLibProcIO*) lib->LoadFunction ("OOL_GLIB_EXP");
  1119.    DosSleep(100);
  1120.  
  1121.    if (NULL != func) {
  1122.       ULONG rc;
  1123.       if (NULL == params) params = GetExportFilterStruct (filename);
  1124.       params->hps = hps;
  1125.       params->hbm = hbm;
  1126.       params->hab = XApplication :: GetApplication ()->GetAnchorBlock ();
  1127.       if (BFE_OK != (rc = func (filename, __XBMFProfile__, params, 0))) {
  1128.          if (releaseParams) ReleaseFilterStruct (params);
  1129.          OOLThrow (GetLastErrorMessage (lib, &rc, params), rc);
  1130.       }
  1131.       if (releaseParams) ReleaseFilterStruct (params);
  1132.       lib->UnLoadFunction ((PFNWP) func);
  1133.    } else {
  1134.       if (releaseParams) ReleaseFilterStruct (params);
  1135.       ULONG error = WinGetLastError (XApplication :: GetApplication ()->GetAnchorBlock ());
  1136.       OOLThrow("Could not load function \"OOL_GLIB_EXP\" from library \"OOLGLIB.DLL\".", error);
  1137.    }
  1138.  
  1139.    delete lib;
  1140. }
  1141.  
  1142. /*@ XBitmap :: SetupImportFilter (const XWindow * owner, const char * filename, XBitmapFilter * params)
  1143. @group loading a bitmap
  1144. @remarks Opens an dialog which allows you to modify the parameters of bitmap-import-filters interactivly. <P><I>If this method is used, GBM.DLL, OLLGLIB.DLL and OOLRES.DLL must be in the LIBPATH.</I>
  1145. @parameters    <t '°' c=2>
  1146.                °XWindow * owner           °owner of the dialog
  1147.                °char * filename           °filename of the file to load (later)
  1148.                °XBitmapFilter * params    °filetype specific filter informations. An initialized structure has to be created by XBitmap :: GetImportFilterStruct () or XGLibFileDialog. (default is NULL)
  1149.                <\t>
  1150. @exceptions   If the method fails to create a new bitmap an exception of the type XException is thrown.
  1151. */
  1152. void XBitmap :: SetupImportFilter (const XWindow * owner, const char * filename, XBitmapFilter * params) {
  1153.    CheckFilterProfile ();
  1154.  
  1155.    if (NULL == owner)    OOLThrow("invalid parameters", 1);
  1156.    if (NULL == filename) OOLThrow("invalid parameters", 2);
  1157.    if (NULL == params)   OOLThrow("invalid parameters", 3);
  1158.  
  1159.    XResourceLibrary* lib = new XResourceLibrary ("OOLGLIB");
  1160.    XGLibProcSetup* func = (XGLibProcSetup*) lib->LoadFunction ("OOL_GLIB_IMP_SETUP");
  1161.    DosSleep(100);
  1162.  
  1163.    if (NULL != func) {
  1164.       ULONG rc;
  1165.  
  1166.       params->hab = XApplication :: GetApplication ()->GetAnchorBlock ();
  1167.       if (BFE_OK != (rc = func (owner->GetHandle (), filename, __XBMFProfile__, params)))
  1168.          OOLThrow (GetLastErrorMessage (lib, &rc, params), rc);
  1169.  
  1170.       lib->UnLoadFunction ((PFNWP) func);
  1171.    } else {
  1172.       ULONG error = WinGetLastError (XApplication :: GetApplication ()->GetAnchorBlock ());
  1173.       OOLThrow("Could not load function \"OOL_GLIB_IMP_SETUP\" from library \"OOLGLIB.DLL\".", error);
  1174.    }
  1175.  
  1176.    delete lib;
  1177. }
  1178.  
  1179. /*@ XBitmap :: SetupExportFilter (const XWindow * owner, const char * filename, XBitmapFilter * params)
  1180. @group saving a bitmap
  1181. @remarks Opens an dialog which allows you to modify the parameters of bitmap-export-filters interactivly. <P><I>If this method is used, GBM.DLL, OLLGLIB.DLL and OOLRES.DLL must be in the LIBPATH.</I>
  1182. @parameters    <t '°' c=2>
  1183.                °XWindow * owner           °owner of the dialog
  1184.                °char * filename           °filename of the file to load (later)
  1185.                °XBitmapFilter * params    °filetype specific filter informations. An initialized structure has to be created by XBitmap :: GetImportFilterStruct () or XGLibFileDialog. (default is NULL)
  1186.                <\t>
  1187. @exceptions   If the method fails to create a new bitmap an exception of the type XException is thrown.
  1188. */
  1189.  
  1190. void XBitmap :: SetupExportFilter (const XWindow* owner, const char* filename, XBitmapFilter* params) {
  1191.    CheckFilterProfile ();
  1192.  
  1193.    if (NULL == owner)    OOLThrow("invalid parameters", 1);
  1194.    if (NULL == filename) OOLThrow("invalid parameters", 2);
  1195.    if (NULL == params)   OOLThrow("invalid parameters", 3);
  1196.  
  1197.    XResourceLibrary* lib = new XResourceLibrary ("OOLGLIB");
  1198.    XGLibProcSetup* func = (XGLibProcSetup*) lib->LoadFunction ("OOL_GLIB_EXP_SETUP");
  1199.    DosSleep(100);
  1200.  
  1201.    if (NULL != func) {
  1202.       ULONG rc;
  1203.  
  1204.       params->hab = XApplication :: GetApplication ()->GetAnchorBlock ();
  1205.       if (BFE_OK != (rc = func (owner->GetHandle (), filename, __XBMFProfile__, params)))
  1206.          OOLThrow (GetLastErrorMessage (lib, &rc, params), rc);
  1207.  
  1208.       lib->UnLoadFunction ((PFNWP) func);
  1209.    } else {
  1210.       ULONG error = WinGetLastError (XApplication :: GetApplication ()->GetAnchorBlock ());
  1211.       OOLThrow("Could not load function \"OOL_GLIB_EXP_SETUP\" from library \"OOLGLIB.DLL\".", error);
  1212.    }
  1213.  
  1214.    delete lib;
  1215. }
  1216.  
  1217. /*@ XBitmap :: GetFilterExtensions ()
  1218. @group loading/saving a bitmap
  1219. @remarks Returns a NULL-terminated list of the file-extensions of all bitmap-formats supported by OOLGLIB. <P><I>If this method is used, GBM.DLL and OOLGLIB.DLL must be in the LIBPATH.</I>
  1220. @exceptions   If the method fails an exception of the type XException is thrown.
  1221. */
  1222.  
  1223. char** XBitmap :: GetFilterExtensions () {
  1224.    CheckFilterProfile ();
  1225.    return (char**) __XBMFProfile__->pszExtension;
  1226. }
  1227.  
  1228. /*@ XBitmap :: GetFilteNames ()
  1229. @group loading/saving a bitmap
  1230. @remarks Returns a NULL-terminated list of the names of all bitmap-formats supported by OOLGLIB. <P><I>If this method is used, GBM.DLL and OOLGLIB.DLL must be in the LIBPATH.</I>
  1231. @exceptions   If the method fails an exception of the type XException is thrown.
  1232. */
  1233.  
  1234. char** XBitmap :: GetFilterNames () {
  1235.    CheckFilterProfile ();
  1236.    return (char**) __XBMFProfile__->pszName;
  1237. }
  1238.  
  1239. /*@ XBitmap :: GetImportFilterStruct (const char* filename)
  1240. @group loading a bitmap
  1241. @remarks Returns the best matching import-filter for the file you specified. The structure returned is used a paramter for several OOLGLIB-functions. To setup the structure manually use the declarations found in oolglib.h.<P><I>If this method is used, GBM.DLL and OLLRES.DLL must be in the LIBPATH.</I>
  1242. @parameters    <t '°' c=2>
  1243.                °char * filename           °filename of the file to load (later)
  1244.                <\t>
  1245. @exceptions   If the method fails to create a new bitmap an exception of the type XException is thrown.
  1246. */
  1247.  
  1248. XBitmapFilter* XBitmap :: GetImportFilterStruct (const char* filename) {
  1249.    XBitmapFilter* filter;
  1250.    XBitmapFilter  dummy;
  1251.    dummy.cbFix = 0;
  1252.    CheckFilterProfile ();
  1253.  
  1254.    XResourceLibrary* lib = new XResourceLibrary ("OOLGLIB");
  1255.    XGLibProcFltInit* func = (XGLibProcFltInit*) lib->LoadFunction ("OOL_GLIB_IMP_INIT");
  1256.    DosSleep(100);
  1257.  
  1258.    if (NULL != func) {
  1259.       ULONG rc;
  1260.       if (0 == (rc = func (filename, __XBMFProfile__, &dummy, 0)))
  1261.          OOLThrow (GetLastErrorMessage (lib, &rc, &dummy), rc);
  1262.       DosAllocMem ((PPVOID) &filter, rc, PAG_READ | PAG_WRITE | PAG_COMMIT);
  1263.  
  1264.       filter->cbFix = rc;
  1265.       filter->hab = XApplication :: GetApplication ()->GetAnchorBlock ();
  1266.       if (BFE_OK != (rc = func (filename, __XBMFProfile__, filter, 0)))
  1267.          OOLThrow (GetLastErrorMessage (lib, &rc, filter), rc);
  1268.  
  1269.       lib->UnLoadFunction ((PFNWP) func);
  1270.    } else {
  1271.       ULONG error = WinGetLastError (XApplication :: GetApplication ()->GetAnchorBlock ());
  1272.       OOLThrow("Could not load function \"OOL_GLIB_IMP_INIT\" from library \"OOLGLIB.DLL\".", error);
  1273.    }
  1274.  
  1275.    delete lib;
  1276.    return filter;
  1277. }
  1278.  
  1279. /*@ XBitmap :: GetExportFilterStruct (const char* filename)
  1280. @group saving a bitmap
  1281. @remarks Returns the best matching export-filter for the file you specified. The structure returned is used a paramter for several OOLGLIB-functions. To setup the structure manually use the declarations found in oolglib.h.<P><I>If this method is used, GBM.DLL and OLLRES.DLL must be in the LIBPATH.</I>
  1282. @parameters    <t '°' c=2>
  1283.                °char * filename           °filename of the file to load (later)
  1284.                <\t>
  1285. @exceptions   If the method fails to create a new bitmap an exception of the type XException is thrown.
  1286. */
  1287.  
  1288. XBitmapFilter* XBitmap :: GetExportFilterStruct (const char* filename) {
  1289.    XBitmapFilter* filter;
  1290.    XBitmapFilter dummy;
  1291.    dummy.cbFix = 0;
  1292.    CheckFilterProfile ();
  1293.  
  1294.    XResourceLibrary* lib = new XResourceLibrary ("OOLGLIB");
  1295.    XGLibProcFltInit* func = (XGLibProcFltInit*) lib->LoadFunction ("OOL_GLIB_EXP_INIT");
  1296.    DosSleep(100);
  1297.  
  1298.    if (NULL != func) {
  1299.       ULONG          rc;
  1300.       if (0 == (rc = func (filename, __XBMFProfile__, NULL, 0)))
  1301.          OOLThrow (GetLastErrorMessage (lib, &rc, &dummy), rc);
  1302.       DosAllocMem ((PPVOID) &filter, rc, PAG_READ | PAG_WRITE | PAG_COMMIT);
  1303.  
  1304.       filter->cbFix = rc;
  1305.       filter->hab = XApplication :: GetApplication ()->GetAnchorBlock ();
  1306.       if (BFE_OK != (rc = func (filename, __XBMFProfile__, filter, 0)))
  1307.          OOLThrow (GetLastErrorMessage (lib, &rc, filter), rc);
  1308.  
  1309.       lib->UnLoadFunction ((PFNWP) func);
  1310.    } else {
  1311.       ULONG error = WinGetLastError (XApplication :: GetApplication ()->GetAnchorBlock ());
  1312.       OOLThrow("Could not load function \"OOL_GLIB_EXP_INIT\" from library \"OOLGLIB.DLL\".", error);
  1313.    }
  1314.  
  1315.    delete lib;
  1316.    return filter;
  1317. }
  1318.  
  1319. void XBitmap :: CheckFilterProfile () {
  1320.    if (NULL == __XBMFProfile__)  {
  1321.       XResourceLibrary*   lib = new XResourceLibrary ("OOLGLIB");
  1322.       XGLibProcProfInit* func = (XGLibProcProfInit*) lib->LoadFunction ("OOL_GLIB_INIT");
  1323.       XBitmapFilter     dummy;
  1324.       dummy.cbFix = 0;
  1325.       DosSleep(100);
  1326.  
  1327.       if (NULL != func) {
  1328.          ULONG rc;
  1329.          if (0 == (rc = func (NULL, 0, 0, 0))) {
  1330.             ULONG error = WinGetLastError (XApplication :: GetApplication ()->GetAnchorBlock ());
  1331.             OOLThrow (GetLastErrorMessage (lib, &rc, &dummy), rc);
  1332.          }
  1333.          DosAllocMem ((PPVOID) &__XBMFProfile__, rc, PAG_READ | PAG_WRITE | PAG_COMMIT);
  1334.  
  1335.          __XBMFProfile__->cbFix = rc;
  1336.          if (BFE_OK != (rc = func (__XBMFProfile__, 0, 0, 0))) {
  1337.             ULONG error = WinGetLastError (XApplication :: GetApplication ()->GetAnchorBlock ());
  1338.             OOLThrow (GetLastErrorMessage (lib, &rc, &dummy), rc);
  1339.          }
  1340.          lib->UnLoadFunction ((PFNWP) func);
  1341.       } else {
  1342.          ULONG error = WinGetLastError (XApplication :: GetApplication ()->GetAnchorBlock ());
  1343.          OOLThrow("Could not load function \"OOL_GLIB_INIT\" from library \"OOLGLIB.DLL\".", error);
  1344.       }
  1345.       delete lib;
  1346.    }
  1347. }
  1348.  
  1349. char* XBitmap :: GetLastErrorMessage (XResourceLibrary* lib, ULONG* pRC, XBitmapFilter* params) {
  1350.    XGLibProcError*  func = (XGLibProcError*) lib->LoadFunction ("OOL_GLIB_ERR");
  1351.    DosSleep(100);
  1352.  
  1353.    if (NULL != func) {
  1354.       ULONG rc;
  1355.       if (BFE_OK != (rc = func (pRC, params, (PSZ) __XBMFErrorMsg__, 1024)))
  1356.          OOLThrow ("Could not recive last error message from OOLGLIB.", rc);
  1357.       lib->UnLoadFunction ((PFNWP) func);
  1358.    } else {
  1359.       ULONG error = WinGetLastError (XApplication :: GetApplication ()->GetAnchorBlock ());
  1360.       OOLThrow("Could not load function \"OOL_GLIB_ERR\" from library \"OOLGLIB.DLL\".", error);
  1361.    }
  1362.    return (char*) __XBMFErrorMsg__;
  1363. }
  1364.  
  1365. XBitmapFilterProfile* XBitmap :: GetProfile () {
  1366.    CheckFilterProfile ();
  1367.    return __XBMFProfile__;
  1368. }
  1369.  
  1370. /*@ XBitmap :: ReleaseFilterStruct (XBitmapFilter * params)
  1371. @group loading/saving a bitmap
  1372. @remarks Released bitmap-filters created by XBitmap :: GetImportFilter/GetExportFilter and XGLibFileDialog
  1373. @parameters    <t '°' c=2>
  1374.                °char * filename           °filename of the file to load (later)
  1375.                <\t>
  1376. @exceptions   If the method fails to create a new bitmap an exception of the type XException is thrown.
  1377. */
  1378. void XBitmap :: ReleaseFilterStruct (XBitmapFilter * params) {
  1379.    int n;
  1380.    if(params)
  1381.    {
  1382.    if (BFT_TIFF == params->cFilterID)
  1383.       for (n = 0; n < BFP_TIFF_TAGCOUNT; n++) {
  1384.          free (((XTIFFExportFilter*) params)->pszTagValue [n]);
  1385.          ((XTIFFExportFilter*) params)->pszTagValue [n] = NULL;
  1386.       }
  1387.    DosFreeMem (params);
  1388.    } /* end if */
  1389.    params = NULL;
  1390. }
  1391.