home *** CD-ROM | disk | FTP | other *** search
/ OS/2 Shareware BBS: 10 Tools / 10-Tools.zip / deans.zip / BASE.CPP next >
C/C++ Source or Header  |  1994-09-03  |  45KB  |  1,633 lines

  1. //
  2. // NAME: CIDLib_Base.Cpp
  3. //
  4. // DESCRIPTION:
  5. //
  6. //    This module implements a number of simple classes that provide workhorse
  7. //  types. None of these involve any system resources or anything like that.
  8. //
  9. //
  10. // AUTHOR: Dean Roddey
  11. //
  12. // CREATE DATE: 05/23/93
  13. //
  14. // COPYRIGHT: 1992..1994, 'CIDCorp
  15. //
  16. // CAVEATS/GOTCHAS: 
  17. //
  18. // MODIFICATION LOG:
  19. //
  20.  
  21.  
  22. // -----------------------------------------------------------------------------
  23. //  Local defines
  24. // -----------------------------------------------------------------------------
  25. #define        CIDGUI_BASE_CPP
  26.  
  27. #define     INCL_CIDGUI_ERRORIDS
  28. #define     INCL_CIDGUI_FACOBJECT
  29.  
  30.  
  31. // -----------------------------------------------------------------------------
  32. //  Facility specific includes
  33. // -----------------------------------------------------------------------------
  34. #include    "CIDGui_.Hpp"
  35.  
  36.  
  37.  
  38. // -----------------------------------------------------------------------------
  39. //   CLASS: AREA
  40. //  PREFIX: area
  41. //
  42. //  This class defines a rectangular area
  43. // -----------------------------------------------------------------------------
  44.  
  45. // -----------------------------------------------------------------------------
  46. //  AREA: Constructor and Destructor
  47. // -----------------------------------------------------------------------------
  48.  
  49. //
  50. // FUNCTION/METHOD NAME: AREA()
  51. //                       AREA(i4X, i4Y, c4CX, c4CY)
  52. //                       AREA(rectlSrc, eInclusive)
  53. //                       AREA(ptlLLeft, ptlURt)
  54. //                       AREA(pntLLeft, pntURt)
  55. //                       AREA(swpSrc)
  56. //
  57. // DESCRIPTION:
  58. //
  59. //  This constructor will create an area from various components.
  60. // ---------------------------------------
  61. //   INPUT: i4X, i4Y, c4CX, c4CY are the origin and size to contruct from
  62. //          rectlSrc is the source rectangle to construct from
  63. //          ptlLLeft, ptlURt are two POINTLs to construct from
  64. //          pntLLeft, pntURt are two POINT objects to construct from
  65. //          eInclusive indicates whether the rectangle is inclusive or not.
  66. //
  67. //  OUTPUT: None
  68. //
  69. //  RETURN: None
  70. //
  71. PROCEXP AREA::AREA(const RECTL& rectlSrc, tCIDGui::eRECTLTYPE eInclusive) :
  72.  
  73.     __i4X(MinVal(rectlSrc.xLeft, rectlSrc.xRight))
  74.     , __i4Y(MinVal(rectlSrc.yBottom, rectlSrc.yTop))
  75.     , __c4CX(rectlSrc.xLeft > rectlSrc.xRight ?
  76.                 rectlSrc.xLeft-rectlSrc.xRight :
  77.                 rectlSrc.xRight-rectlSrc.xLeft)
  78.     , __c4CY(rectlSrc.yBottom > rectlSrc.yTop ?
  79.                 rectlSrc.yTop - rectlSrc.yBottom :
  80.                 rectlSrc.yTop-rectlSrc.yBottom)
  81. {
  82.     if (eInclusive == tCIDGui::eRECTL_INCLUSIVE)
  83.     {
  84.         // Be careful of an empty rectangle
  85.         if (__c4CX)
  86.             __c4CX++;
  87.  
  88.         if (__c4CY)
  89.             __c4CY++;
  90.     }
  91. }
  92.  
  93. PROCEXP AREA::AREA(const POINTL& ptlLLeft, const POINTL& ptlURt) :
  94.  
  95.     __i4X(MinVal(ptlLLeft.x, ptlURt.x))
  96.     , __c4CX(ptlLLeft.x > ptlURt.x ? ptlLLeft.x-ptlURt.x : ptlURt.x-ptlLLeft.x)
  97.     , __i4Y(MinVal(ptlLLeft.y, ptlURt.y))
  98.     , __c4CY(ptlLLeft.y > ptlURt.y ? ptlLLeft.y-ptlURt.y : ptlURt.y-ptlLLeft.y)
  99. {
  100.     // Bump up the sizes to make them right
  101.     __c4CX++;
  102.     __c4CY++;
  103. }
  104.  
  105. PROCEXP AREA::AREA(const POINT& pntLLeft, const POINT& pntURt)
  106. {
  107.     // Get the values out of the points for greater efficiency
  108.     tCIDLib::INT4 i4X1 = pntLLeft.i4X();
  109.     tCIDLib::INT4 i4Y1 = pntLLeft.i4Y();
  110.     tCIDLib::INT4 i4X2 = pntURt.i4X();
  111.     tCIDLib::INT4 i4Y2 = pntURt.i4Y();
  112.  
  113.     __i4X   = MinVal(i4X1, i4X2);
  114.     __c4CX  = i4X1 > i4X2 ? i4X1-i4X2 : i4X2-i4X1;
  115.     __i4Y   = MinVal(i4Y1, i4Y2);
  116.     __c4CY  = i4Y1 > i4Y2 ? i4Y1-i4Y2 : i4Y2-i4Y1;
  117.  
  118.     // Bump up the sizes to make them right
  119.     __c4CX++;
  120.     __c4CY++;
  121. }
  122.  
  123. PROCEXP AREA::AREA(const SWP& swpSrc) :
  124.  
  125.     __i4X(swpSrc.x)
  126.     , __c4CX(swpSrc.cx)
  127.     , __i4Y(swpSrc.y)
  128.     , __c4CY(swpSrc.cy)
  129. {
  130. }
  131.  
  132. PROCEXP AREA::AREA( tCIDLib::INT4       x
  133.                     , tCIDLib::INT4     y
  134.                     , tCIDLib::CARD4    cx
  135.                     , tCIDLib::CARD4    cy) :
  136.     __i4X(x)
  137.     , __i4Y(y)
  138.     , __c4CX(cx)
  139.     , __c4CY(cy)
  140. {
  141. }
  142.  
  143. PROCEXP AREA::AREA() :
  144.  
  145.     __i4X(0)
  146.     , __i4Y(0)
  147.     , __c4CX(0)
  148.     , __c4CY(0)
  149. {
  150. }
  151.  
  152. PROCEXP AREA::AREA(const AREA& areaSrc) :
  153.  
  154.     __i4X(areaSrc.__i4X)
  155.     , __i4Y(areaSrc.__i4Y)
  156.     , __c4CX(areaSrc.__c4CX)
  157.     , __c4CY(areaSrc.__c4CY)
  158. {
  159. }
  160.  
  161.  
  162. // -----------------------------------------------------------------------------
  163. //  AREA: Public, inherited methods
  164. // -----------------------------------------------------------------------------
  165.  
  166. //
  167. // FUNCTION/METHOD NAME: FormatAt(pszBuf, c4CurInd);
  168. //
  169. // DESCRIPTION:
  170. //
  171. //  This message is called to format this class' members into the passed
  172. //  buffer.
  173. // ---------------------------------------
  174. //   INPUT: pszBuf is a pointer to the buffer to format into
  175. //          c4CurInd is the index at which this class should start formatting.
  176. //
  177. //  OUTPUT: None
  178. //
  179. //  RETURN: None
  180. //
  181. tCIDLib::VOID PROCEXP AREA::FormatAt(   tCIDLib::CH*        pszBuf
  182.                                         , tCIDLib::CARD4&   c4CurInd) const
  183. {
  184.     tCIDLib::CH*    pszTmp;
  185.     tCIDLib::CH*    pszStart;
  186.  
  187.     // Call our parent's version
  188.     CIDSTORABLE::FormatAt(pszBuf, c4CurInd);
  189.  
  190.     //
  191.     //  Address our starting position in the buffer and remember where we
  192.     //  started.
  193.     //
  194.     pszTmp      = &pszBuf[c4CurInd];
  195.     pszStart    = pszTmp;
  196.  
  197.     // Write out the origin and size information
  198.     *(tCIDLib::INT4*)pszTmp = __i4X;
  199.     pszTmp += sizeof(__i4X);
  200.  
  201.     *(tCIDLib::INT4*)pszTmp = __i4Y;
  202.     pszTmp += sizeof(__i4Y);
  203.  
  204.     *(tCIDLib::CARD4*)pszTmp = __c4CX;
  205.     pszTmp += sizeof(__c4CX);
  206.  
  207.     *(tCIDLib::CARD4*)pszTmp = __c4CY;
  208.     pszTmp += sizeof(__c4CY);
  209.  
  210.     // Bump up cCurInd by the bytes we used
  211.     c4CurInd += tCIDLib::CARD4(pszTmp-pszStart);
  212. }
  213.  
  214.  
  215. //
  216. // FUNCTION/METHOD NAME: FormatToStr(strbDest) const
  217. //
  218. // DESCRIPTION:
  219. //
  220. //  This method will format the data members into the passed string buffer
  221. // ---------------------------------------
  222. //   INPUT: None
  223. //
  224. //  OUTPUT: strbDest is the buffer to format into
  225. //
  226. //  RETURN: None
  227. //
  228. tCIDLib::VOID PROCEXP AREA::FormatToStr(STRGBUF& strbDest) const
  229. {
  230.     strbDest << "X=" << __i4X << ",Y=" << __i4Y;
  231.     strbDest << ",cX=" << __c4CX << ",cY=" << __c4CY;
  232. }
  233.  
  234.  
  235. //
  236. // FUNCTION/METHOD NAME: ParseAt(pszBuf, c4CurInd)
  237. //
  238. // DESCRIPTION:
  239. //
  240. //  This method will parse the data from the passed buffer into this object.
  241. //  We first call our parent class, then parse out our data members.
  242. // ---------------------------------------
  243. //   INPUT: pszBuf is the buffer to parse from.
  244. //          c4CurInd is where we start parsing from.
  245. //
  246. //  OUTPUT: c4CurInd is bumped up by the number of bytes parsed at this
  247. //              level and all below us
  248. //
  249. //  RETURN: None
  250. //
  251. tCIDLib::VOID PROCEXP AREA::ParseAt(const   tCIDLib::CH*    pszBuf
  252.                                     ,       tCIDLib::CARD4& c4CurInd)
  253. {
  254.     // Call our parent's version
  255.     CIDSTORABLE::ParseAt(pszBuf, c4CurInd);
  256.  
  257.     //
  258.     //  Address our starting position in the buffer and remember where we
  259.     //  started.
  260.     //
  261.     const tCIDLib::CH*  pszTmp      = &pszBuf[c4CurInd];
  262.     const tCIDLib::CH*  pszStart    = pszTmp;
  263.  
  264.     // Get the origin and size values
  265.     __i4X = *(tCIDLib::INT4*)pszTmp;
  266.     pszTmp += sizeof(__i4X);
  267.  
  268.     __i4Y = *(tCIDLib::INT4*)pszTmp;
  269.     pszTmp += sizeof(__i4Y);
  270.  
  271.     __c4CX = *(tCIDLib::CARD4*)pszTmp;
  272.     pszTmp += sizeof(__c4CX);
  273.  
  274.     __c4CY = *(tCIDLib::CARD4*)pszTmp;
  275.     pszTmp += sizeof(__c4CY);
  276.  
  277.     // Bump up cCurInd by the bytes we used
  278.     c4CurInd += tCIDLib::CARD4(pszTmp-pszStart);
  279. }
  280.  
  281.  
  282. // -----------------------------------------------------------------------------
  283. //  AREA: Public, non-virtual methods
  284. // -----------------------------------------------------------------------------
  285.  
  286. //
  287. // FUNCTION/METHOD NAME: operator+(areaSrc)
  288. //                       operator+=(areaSrc)
  289. //
  290. // DESCRIPTION:
  291. //
  292. //  This method will add two areas, creating a union of the two and leaving
  293. //  the  result in this object.
  294. // ---------------------------------------
  295. //   INPUT: areaSrc is the area to add
  296. //
  297. //  OUTPUT: None
  298. //
  299. //  RETURN: A reference to this object for += or a new AREA object for +.
  300. //
  301. AREA AREA::operator+(const AREA& areaSrc)
  302. {
  303.     tCIDLib::CARD4  c4CX, c4CY;
  304.     tCIDLib::INT4   i4X, i4Y;
  305.  
  306.     // If the same object, then return a copy of this object
  307.     if (&areaSrc == this)
  308.         return *this;
  309.  
  310.     i4X = MinVal(areaSrc.__i4X, __i4X);
  311.     i4Y = MinVal(areaSrc.__i4Y, __i4Y);
  312.     c4CX = MaxVal(areaSrc.i4XRight(), i4XRight()) - i4X;
  313.     c4CY = MaxVal(areaSrc.i4YTop(), i4YTop()) - i4Y;
  314.  
  315.     return AREA(i4X, i4Y, c4CX, c4CY);
  316. }
  317.  
  318. tCIDLib::VOID AREA::operator+=(const AREA& areaSrc)
  319. {
  320.     tCIDLib::CARD4  c4CX, c4CY;
  321.     tCIDLib::INT4   i4X, i4Y;
  322.  
  323.     // If the same object, then nothing to do
  324.     if (&areaSrc == this)
  325.         return;
  326.  
  327.     i4X = MinVal(areaSrc.__i4X, __i4X);
  328.     i4Y = MinVal(areaSrc.__i4Y, __i4Y);
  329.     c4CX = MaxVal(areaSrc.i4XRight(), i4XRight()) - i4X;
  330.     c4CY = MaxVal(areaSrc.i4YTop(), i4YTop()) - i4Y;
  331.  
  332.     __i4X   = i4X;
  333.     __i4Y   = i4Y;
  334.     __c4CX  = c4CX;
  335.     __c4CY  = c4CY;
  336. }
  337.  
  338.  
  339. //
  340. // FUNCTION/METHOD NAME: operator-(areaSrc)
  341. //                       operator-=(areaSrc)
  342. //
  343. // DESCRIPTION:
  344. //
  345. //  This method will add subtract two areas, creating an area that is the
  346. //  intersection of the two areas. If they just touch on a side, this is not
  347. //  overlapping
  348. // ---------------------------------------
  349. //   INPUT: areaSrc is the area to intersect with this object.
  350. //
  351. //  OUTPUT: None
  352. //
  353. //  RETURN: A reference to this object for -= or a new AREA object for -.
  354. //
  355. AREA PROCEXP AREA::operator-(const AREA& areaSrc)
  356. {
  357.     // If the same object, then return a copy of this object
  358.     if (&areaSrc == this)
  359.         return *this;
  360.  
  361.     // Check for no intersection
  362.     if (areaSrc.i4XRight() <= __i4X)
  363.         return AREA(0,0,0,0);
  364.  
  365.     if (i4XRight() <= areaSrc.__i4X)
  366.         return AREA(0,0,0,0);
  367.  
  368.     if (areaSrc.i4YTop() <= __i4Y)
  369.         return AREA(0,0,0,0);
  370.  
  371.     if (i4YTop() <= areaSrc.__i4Y)
  372.         return AREA(0,0,0,0);
  373.  
  374.     //
  375.     //  Check for identical position and size. Then just return a copy of
  376.     //  this rectangle.
  377.     //
  378.     if ((areaSrc.__i4X  == __i4X)
  379.     &&  (areaSrc.__i4Y  == __i4Y)
  380.     &&  (areaSrc.__c4CX == __c4CX)
  381.     &&  (areaSrc.__c4CY == __c4CY))
  382.     {
  383.         return *this;
  384.     }
  385.  
  386.     //
  387.     //  They intersect, so we need to find the one with the lower origin.
  388.     //  It's upper right corner becomes the upper right of the result. The
  389.     //  other one's lower left corner becomes the lower left.
  390.     //
  391.     if (areaSrc.__i4X < __i4X)
  392.     {
  393.         return AREA(__i4X
  394.                     , __i4Y
  395.                     , areaSrc.i4XRight()-__i4X
  396.                     , areaSrc.i4YTop()-__i4Y);
  397.     }
  398.     return AREA(areaSrc.__i4X
  399.                 , areaSrc.__i4Y
  400.                 , i4XRight()-areaSrc.__i4X
  401.                 , i4YTop()-areaSrc.__i4Y);
  402. }
  403.  
  404. tCIDLib::VOID PROCEXP AREA::operator-=(const AREA& areaSrc)
  405. {
  406.     // If the same object, then return
  407.     if (&areaSrc == this)
  408.         return;
  409.  
  410.     //
  411.     //  Check for identical position and size. If so just return
  412.     //
  413.     if ((areaSrc.__i4X  == __i4X)
  414.     &&  (areaSrc.__i4Y  == __i4Y)
  415.     &&  (areaSrc.__c4CX == __c4CX)
  416.     &&  (areaSrc.__c4CY == __c4CY))
  417.     {
  418.         return;
  419.     }
  420.  
  421.     // Set this area to empty as a default
  422.     __i4X   = 0;
  423.     __i4Y   = 0;
  424.     __c4CX  = 0;
  425.     __c4CY  = 0;
  426.  
  427.     // Check for no intersection
  428.     if (areaSrc.i4XRight() <= __i4X)
  429.         return;
  430.  
  431.     if (i4XRight() <= areaSrc.__i4X)
  432.         return;
  433.  
  434.     if (areaSrc.i4YTop() <= __i4Y)
  435.         return;
  436.  
  437.     if (i4YTop() <= areaSrc.__i4Y)
  438.         return;
  439.  
  440.     //
  441.     //  They intersect, so we need to find the one with the lower origin.
  442.     //  It's upper right corner becomes the upper right of the result. The
  443.     //  other one's lower left corner becomes the lower left.
  444.     //
  445.     if (areaSrc.__i4X < __i4X)
  446.     {
  447.         __c4CX  = areaSrc.i4XRight()-__i4X;
  448.         __c4CY  = areaSrc.i4YTop()-__i4Y;
  449.     }
  450.      else
  451.     {
  452.         __i4X   = areaSrc.__i4Y;
  453.         __i4Y   = areaSrc.__i4Y;
  454.         __c4CX  = i4XRight()-areaSrc.__i4X;
  455.         __c4CY  = i4YTop()-areaSrc.__i4Y;
  456.     }
  457. }
  458.  
  459.  
  460. //
  461. // FUNCTION/METHOD NAME: AdjustOrg(i4XOfs, i4YOfs)
  462. //                       AdjustOrg(pntOfs)
  463. //
  464. // DESCRIPTION:
  465. //
  466. //  This method will adjust the origin of the area by the passed offsets.
  467. // ---------------------------------------
  468. //   INPUT: i4XOfs, i4YOfs are the offsets
  469. //          pntOfs provides both offsets at once
  470. //
  471. //  OUTPUT: None
  472. //
  473. //  RETURN: None
  474. //
  475. tCIDLib::VOID PROCEXP AREA::AdjustOrg(  tCIDLib::INT4   i4XOfs
  476.                                         , tCIDLib::INT4 i4YOfs)
  477. {
  478.     __i4X += i4XOfs;
  479.     __i4Y += i4YOfs;
  480. }
  481.  
  482. tCIDLib::VOID PROCEXP AREA::AdjustOrg(const POINT& pntOfs)
  483. {
  484.     __i4X += pntOfs.i4X();
  485.     __i4Y += pntOfs.i4Y();
  486. }
  487.  
  488.  
  489. //
  490. // FUNCTION/METHOD NAME: AdjustSides(i4XOfs, i4YOfs)
  491. //
  492. // DESCRIPTION:
  493. //
  494. //  This method will adjust the sides of the area by the given x and y
  495. //  offsets. Negative values will cause the area to become smaller and
  496. //  positive values will cause it to become larger. Both sides are pushed
  497. //  outward or inward by the offset amount.
  498. // ---------------------------------------
  499. //   INPUT: i4XOfs, i4YOfs are the offsets to adjust the sides by
  500. //
  501. //  OUTPUT: None
  502. //
  503. //  RETURN: None
  504. //
  505. tCIDLib::VOID PROCEXP AREA::AdjustSides(tCIDLib::INT4   i4XOfs
  506.                                         , tCIDLib::INT4 i4YOfs)
  507. {
  508.     tCIDLib::eBOOL   bNegX, bNegY;
  509.  
  510.     //
  511.     //  If the x offset is negative, then see if the area is large enough to
  512.     //  adjust by this offset. If not, then set the offset to the best we can
  513.     //  do, which is to make it a 0 sized area with a new origin that is at
  514.     //  the middle of the old size. Do the same thing for the y offset also.
  515.     //
  516.     if (i4XOfs < 0)
  517.     {
  518.         bNegX = tCIDLib::eTRUE;
  519.         i4XOfs *= -1;
  520.     }
  521.      else
  522.     {
  523.         bNegX = tCIDLib::eFALSE;
  524.     }
  525.     if ((i4XOfs << 1) >= __c4CX)
  526.         i4XOfs = tCIDLib::INT4(__c4CX >> 1);
  527.  
  528.     if (i4YOfs < 0)
  529.     {
  530.         bNegY = tCIDLib::eTRUE;
  531.         i4YOfs *= -1;
  532.     }
  533.      else
  534.     {
  535.         bNegY = tCIDLib::eFALSE;
  536.     }
  537.     if ((i4YOfs << 1) >= __c4CY)
  538.         i4YOfs = tCIDLib::INT4(__c4CY >> 1);
  539.  
  540.     //
  541.     //  Now adjust the sides. Adjust the orgin first, then adjust the length
  542.     //  and width. When doing the length and width, be careful to check for
  543.     //  a potential underflow of the __c4CX and __c4CY values. Despite the
  544.     //  checks done above, the offset may have been an odd number, in which
  545.     //  case there could still be an overflow of 1. The division done above
  546.     //  was via a shift operation, which would just truncate the extra odd
  547.     //  bit.
  548.     //
  549.     if (bNegX)
  550.     {
  551.         __i4X += i4XOfs;
  552.         if (__c4CX <= i4XOfs * 2)
  553.             __c4CX = 0;
  554.          else
  555.             __c4CX -= (i4XOfs * 2);
  556.     }
  557.      else
  558.     {
  559.         __i4X  -= i4XOfs;
  560.         __c4CX += (i4XOfs * 2);
  561.     }
  562.  
  563.     if (bNegY)
  564.     {
  565.         __i4Y += i4YOfs;
  566.         if (__c4CY <= i4YOfs * 2)
  567.             __c4CY = 0;
  568.          else
  569.             __c4CY -= (i4YOfs * 2);
  570.     }
  571.      else
  572.     {
  573.         __i4Y  -= i4YOfs;
  574.         __c4CY += (i4YOfs * 2);
  575.     }
  576. }
  577.  
  578.  
  579. //
  580. // FUNCTION/METHOD NAME: AdjustSize(i4CXOfs, i4CYOfs)
  581. //
  582. // DESCRIPTION:
  583. //
  584. //  This method will adjust the cx and cy values of the area by the passed
  585. //  values. Trying to size an area below 0 length is an error.
  586. // ---------------------------------------
  587. //   INPUT: i4CXOfs, i4CYOfs are the offsets to apply to the current area size.
  588. //              They should be negative to make the size smaller, or positive
  589. //              to make it larger.
  590. //
  591. //  OUTPUT: None
  592. //
  593. //  RETURN: None
  594. //
  595. tCIDLib::VOID PROCEXP AREA::AdjustSize( tCIDLib::INT4   i4CXOfs
  596.                                         , tCIDLib::INT4 i4CYOfs)
  597. {
  598.     tCIDLib::CARD4  c4AbsCXOfs  = i4CXOfs < 0 ? i4CXOfs * -1 : i4CXOfs;
  599.     tCIDLib::CARD4  c4AbsCYOfs  = i4CYOfs < 0 ? i4CYOfs * -1 : i4CYOfs;
  600.  
  601.     // Check for underflows first
  602.     if (c4AbsCXOfs > __c4CX)
  603.     {
  604.         facCIDGui.LogErr(   __FILE__
  605.                             , "AREA::AdjustSize"
  606.                             , __LINE__
  607.                             , GUIERR_COORD_AREA_UNDERFLOW
  608.                             , "(Horizontal)"
  609.                             , tCIDLib::eSEV_PROCESS_FATAL
  610.                             , tCIDLib::eCLASS_BADPARMS
  611.                             , INTEGER(i4CXOfs)
  612.                             , CARDINAL(__c4CX));
  613.     }
  614.  
  615.     if (c4AbsCYOfs > __c4CY)
  616.     {
  617.         facCIDGui.LogErr(   __FILE__
  618.                             , "AREA::AdjustSize"
  619.                             , __LINE__
  620.                             , GUIERR_COORD_AREA_UNDERFLOW
  621.                             , "(Vertical)"
  622.                             , tCIDLib::eSEV_PROCESS_FATAL
  623.                             , tCIDLib::eCLASS_BADPARMS
  624.                             , INTEGER(i4CYOfs)
  625.                             , CARDINAL(__c4CY));
  626.     }
  627.  
  628.     // Go ahead and modify the size
  629.     __c4CX += i4CXOfs;
  630.     __c4CY += i4CYOfs;
  631. }
  632.  
  633.  
  634. //
  635. // FUNCTION/METHOD NAME: areaHorzPercent(c4Percent) const
  636. //                       areaVertPercent(c4Percent) const
  637. //
  638. // DESCRIPTION:
  639. //
  640. //  These methods will return areas that represent percentages of this area.
  641. //  The indicated direction is the one that is calculated and the other is left
  642. //  at the full size of this area.
  643. // ---------------------------------------
  644. //   INPUT: c4Percent is percent of the area to calculate
  645. //
  646. //  OUTPUT: None
  647. //
  648. //  RETURN: The percentage area
  649. //
  650. AREA PROCEXP AREA::areaHorzPercent(tCIDLib::CARD4 c4Percent) const
  651. {
  652.     if (c4Percent > 100)
  653.     {
  654.         facCIDGui.LogErr(   __FILE__
  655.                             , "AREA::areaHorzPercent"
  656.                             , __LINE__
  657.                             , GUIERR_GEN_PERCENT_RANGE
  658.                             , tCIDLib::eSEV_PROCESS_FATAL
  659.                             , tCIDLib::eCLASS_BADPARMS
  660.                             , CARDINAL(c4Percent));
  661.     }
  662.  
  663.     if (!c4Percent)
  664.         return AREA(__i4X, __i4Y, 0, 0);
  665.  
  666.     tCIDLib::FLOAT4 f4Per = tCIDLib::FLOAT4(c4Percent) / 100.0;
  667.  
  668.     return AREA(__i4X, __i4Y, tCIDLib::CARD4(__c4CX * f4Per), __c4CY);
  669. }
  670.  
  671. AREA PROCEXP AREA::areaVertPercent(tCIDLib::CARD4 c4Percent) const
  672. {
  673.     if (c4Percent > 100)
  674.     {
  675.         facCIDGui.LogErr(   __FILE__
  676.                             , "AREA::areaVertPercent"
  677.                             , __LINE__
  678.                             , GUIERR_GEN_PERCENT_RANGE
  679.                             , tCIDLib::eSEV_PROCESS_FATAL
  680.                             , tCIDLib::eCLASS_BADPARMS
  681.                             , CARDINAL(c4Percent));
  682.     }
  683.  
  684.     if (!c4Percent)
  685.         return AREA(__i4X, __i4Y, 0, 0);
  686.  
  687.     tCIDLib::FLOAT4 f4Per = tCIDLib::FLOAT4(c4Percent) / 100.0;
  688.  
  689.     return AREA(__i4X, __i4Y, __c4CX, tCIDLib::CARD4(__c4CY * f4Per));
  690. }
  691.  
  692.  
  693. //
  694. // FUNCTION/METHOD NAME: bEmpty() const
  695. //
  696. // DESCRIPTION:
  697. //
  698. //  This method will return eTRUE if either the cx or cy is 0.
  699. // ---------------------------------------
  700. //   INPUT: None
  701. //
  702. //  OUTPUT: None
  703. //
  704. //  RETURN: eTRUE if the area is empty, else eFALSE
  705. //
  706. tCIDLib::eBOOL PROCEXP AREA::bEmpty() const
  707. {
  708.     return (!__c4CX || !__c4CY) ? tCIDLib::eTRUE : tCIDLib::eFALSE;
  709. }
  710.  
  711.  
  712. //
  713. // FUNCTION/METHOD NAME: bIntersects(areaTest) const
  714. //
  715. // DESCRIPTION:
  716. //
  717. //  This method will see if this area intersects the passed one.
  718. // ---------------------------------------
  719. //   INPUT: areaTest is the area to test this area agaisnt for intersection.
  720. //
  721. //  OUTPUT: None
  722. //
  723. //  RETURN: eTRUE if the areas intersect, else eFALSE.
  724. //
  725. tCIDLib::eBOOL PROCEXP AREA::bIntersects(const AREA& areaTest) const
  726. {
  727.     // If either is empty, then cannot intersect
  728.     if (bEmpty() || areaTest.bEmpty())
  729.         return tCIDLib::eFALSE;
  730.  
  731.     // Get the upper extremes of each area
  732.     tCIDLib::INT4   i4ThisXRight    = i4XRight();
  733.     tCIDLib::INT4   i4ThisYTop      = i4YTop();
  734.     tCIDLib::INT4   i4TestXRight    = areaTest.i4XRight();
  735.     tCIDLib::INT4   i4TestYTop      = areaTest.i4YTop();
  736.  
  737.     // Check the sides
  738.     if (areaTest.__i4X > i4ThisXRight)
  739.         return tCIDLib::eFALSE;
  740.     if (__i4X > i4TestXRight)
  741.         return tCIDLib::eFALSE;
  742.  
  743.     if (areaTest.__i4Y > i4ThisYTop)
  744.         return tCIDLib::eFALSE;
  745.     if (__i4Y > i4TestYTop)
  746.         return tCIDLib::eFALSE;
  747.  
  748.     // They intersect
  749.     return tCIDLib::eTRUE;
  750. }
  751.  
  752.  
  753. //
  754. // FUNCTION/METHOD NAME: FromPnts(pntLLeft, pntlURight)
  755. //
  756. // DESCRIPTION:
  757. //
  758. //  This will convert the two passed points, which represent the lower left and
  759. //  upper right corners of a rectangle, into an area.
  760. //
  761. //  NOTE:   The points may be rearranged if the lower left point is actually
  762. //          greater than the upper right.
  763. // ---------------------------------------
  764. //   INPUT: pntLLeft, pntURight are the two points that define the area.
  765. //
  766. //  OUTPUT: None
  767. //
  768. //  RETURN: None
  769. //
  770. tCIDLib::VOID PROCEXP AREA::FromPnts(   const   POINT& pntLLeft
  771.                                         , const POINT& pntURight)
  772. {
  773.     if (pntLLeft.i4X() > pntURight.i4X())
  774.     {
  775.         __i4X  = pntURight.i4X();
  776.         __c4CX = (pntLLeft.i4X()-pntURight.i4X()) + 1;
  777.     }
  778.      else
  779.     {
  780.         __i4X  = pntLLeft.i4X();
  781.         __c4CX = (pntURight.i4X()-pntLLeft.i4X()) + 1;
  782.     }
  783.  
  784.     if (pntLLeft.i4Y() > pntURight.i4Y())
  785.     {
  786.         __i4Y  = pntURight.i4Y();
  787.         __c4CY = (pntLLeft.i4Y()-pntURight.i4Y()) + 1;
  788.     }
  789.      else
  790.     {
  791.         __i4Y  = pntLLeft.i4Y();
  792.         __c4CY = (pntURight.i4Y()-pntLLeft.i4Y()) + 1;
  793.     }
  794. }
  795.  
  796.  
  797. //
  798. // FUNCTION/METHOD NAME: FromPtls(ptlLLeft, ptlURight)
  799. //
  800. // DESCRIPTION:
  801. //
  802. //  This will convert the two passed points, which represent the lower left and
  803. //  upper right corners of a rectangle, into an area.
  804. //
  805. //  NOTE:   The points may be rearranged if the lower left point is actually
  806. //          greater than the upper right.
  807. // ---------------------------------------
  808. //   INPUT: ptlLLeft, ptlURight are the two points that define the area.
  809. //
  810. //  OUTPUT: None
  811. //
  812. //  RETURN: None
  813. //
  814. tCIDLib::VOID PROCEXP AREA::FromPtls(   const   POINTL& ptlLLeft
  815.                                         , const POINTL& ptlURight)
  816. {
  817.     if (ptlLLeft.x > ptlURight.x)
  818.     {
  819.         __i4X  = tCIDLib::CARD4(ptlURight.x);
  820.         __c4CX = tCIDLib::CARD4(ptlLLeft.x-ptlURight.x)+1;
  821.     }
  822.      else
  823.     {
  824.         __i4X  = tCIDLib::CARD4(ptlLLeft.x);
  825.         __c4CX = tCIDLib::CARD4(ptlURight.x-ptlLLeft.x)+1;
  826.     }
  827.  
  828.     if (ptlLLeft.y > ptlURight.y)
  829.     {
  830.         __i4Y  = tCIDLib::CARD4(ptlURight.y);
  831.         __c4CY = tCIDLib::CARD4(ptlLLeft.y-ptlURight.y)+1;
  832.     }
  833.      else
  834.     {
  835.         __i4Y  = tCIDLib::CARD4(ptlLLeft.y);
  836.         __c4CY = tCIDLib::CARD4(ptlURight.y-ptlLLeft.y)+1;
  837.     }
  838. }
  839.  
  840.  
  841.  
  842. //
  843. // FUNCTION/METHOD NAME: FromRectl(rectlSrc, eInclusive)
  844. //
  845. // DESCRIPTION:
  846. //
  847. //  This method will convert the passed PM RECTL into the area object
  848. //
  849. //  NOTE: This guy is NOT exported
  850. // ---------------------------------------
  851. //   INPUT: rectlSrc is the source rectangle to convert
  852. //          eInclusive indicates whether the rectangle is an inclusive one
  853. //
  854. //  OUTPUT: None
  855. //
  856. //  RETURN: None
  857. //
  858. tCIDLib::VOID PROCEXP AREA::FromRectl(  const   RECTL&              rectlSrc
  859.                                         ,       tCIDGui::eRECTLTYPE eInclusive)
  860. {
  861.     if (rectlSrc.xLeft > rectlSrc.xRight)
  862.     {
  863.         __i4X = rectlSrc.xRight;
  864.         __c4CX = (rectlSrc.xLeft-rectlSrc.xRight);
  865.     }
  866.      else
  867.     {
  868.         __i4X  = rectlSrc.xLeft;
  869.         __c4CX = (rectlSrc.xRight-rectlSrc.xLeft);
  870.     }
  871.  
  872.     if (rectlSrc.yBottom > rectlSrc.yTop)
  873.     {
  874.         __i4Y  = rectlSrc.yTop;
  875.         __c4CY = (rectlSrc.yBottom-rectlSrc.yTop);
  876.     }
  877.      else
  878.     {
  879.         __i4Y  = rectlSrc.yBottom;
  880.         __c4CY = (rectlSrc.yTop-rectlSrc.yBottom);
  881.     }
  882.  
  883.     // If inclusive, bump up the sizes by 1 if not empty
  884.     if (eInclusive == tCIDGui::eRECTL_INCLUSIVE)
  885.     {
  886.         if (__c4CX)
  887.             __c4CX++;
  888.  
  889.         if (__c4CY)
  890.             __c4CY++;
  891.     }
  892. }
  893.  
  894.  
  895. //
  896. // FUNCTION/METHOD NAME: FromSwp(swpSrc)
  897. //
  898. // DESCRIPTION:
  899. //
  900. //  This method will convert the passed PM SWP into the area object.
  901. //
  902. //  NOTE: This guy is NOT exported
  903. // ---------------------------------------
  904. //   INPUT: swpSrc is the source SWP structure to convert
  905. //
  906. //  OUTPUT: None
  907. //
  908. //  RETURN: None
  909. //
  910. tCIDLib::VOID PROCEXP AREA::FromSwp(const SWP& swpSrc)
  911. {
  912.     __i4X  = swpSrc.x;
  913.     __i4Y  = swpSrc.y;
  914.     __c4CX = tCIDLib::CARD4(swpSrc.cx);
  915.     __c4CY = tCIDLib::CARD4(swpSrc.cy);
  916. }
  917.  
  918.  
  919. //
  920. // FUNCTION/METHOD NAME: i4XRight()
  921. //                       i4XRight(i4NewXRight)
  922. //                       i4YTop()
  923. //                       i4YTop(i4NewYTop)
  924. //
  925. // DESCRIPTION:
  926. //
  927. //  These methods will return the right or top most pixel. They have no choice
  928. //  but to return the same value for an empty or 1 pixel sized area. There is
  929. //  a second version of each that allows it to be set. These are just indirect
  930. //  methods for setting the size, which is a great convenience.
  931. // ---------------------------------------
  932. //   INPUT: i4NewXRight, i4NewYTop are the new right or top side when setting.
  933. //
  934. //  OUTPUT: None
  935. //
  936. //  RETURN: The coordinate of the right or top most pixel.
  937. //
  938. tCIDLib:: INT4 PROCEXP AREA::i4XRight() const
  939. {
  940.     if (__c4CX)
  941.         return (__i4X+__c4CX)-1;
  942.      else
  943.         return (__i4X);
  944. }
  945.  
  946. tCIDLib:: INT4 PROCEXP AREA::i4XRight(tCIDLib::INT4 i4NewXRight)
  947. {
  948.     // Make sure that it is not less than the origin
  949.     if (i4NewXRight < __i4X)
  950.     {
  951.         facCIDGui.LogErr(   __FILE__
  952.                             , "AREA::i4XRight"
  953.                             , __LINE__
  954.                             , GUIERR_COORD_AREA_BEHIND_ORG
  955.                             , "(Horizontal)"
  956.                             , tCIDLib::eSEV_PROCESS_FATAL
  957.                             , tCIDLib::eCLASS_BADPARMS
  958.                             , INTEGER(i4NewXRight)
  959.                             , INTEGER(__i4X));
  960.     }
  961.     __c4CX = (i4NewXRight-__i4X)+1;
  962.     return i4NewXRight;
  963. }
  964.  
  965. tCIDLib::INT4 PROCEXP AREA::i4YTop() const
  966. {
  967.     if (__c4CY)
  968.         return (__i4Y+__c4CY)-1;
  969.      else
  970.         return (__i4Y);
  971. }
  972.  
  973. tCIDLib::INT4 PROCEXP AREA::i4YTop(tCIDLib::INT4 i4NewYTop)
  974. {
  975.     // Make sure that it is not less than the origin
  976.     if (i4NewYTop < __i4Y)
  977.     {
  978.         facCIDGui.LogErr(   __FILE__
  979.                             , "AREA::i4YTop"
  980.                             , __LINE__
  981.                             , GUIERR_COORD_AREA_BEHIND_ORG
  982.                             , "(Vertical)"
  983.                             , tCIDLib::eSEV_PROCESS_FATAL
  984.                             , tCIDLib::eCLASS_BADPARMS
  985.                             , INTEGER(i4NewYTop)
  986.                             , INTEGER(__i4Y));
  987.     }
  988.     __c4CY = (i4NewYTop-__i4Y)+1;
  989.     return i4NewYTop;
  990. }
  991.  
  992.  
  993. //
  994. // FUNCTION/METHOD NAME: JustifyIn(areaTarget, eHJustify, eVJustify)
  995. //
  996. // DESCRIPTION:
  997. //
  998. //  This method will justify this area within the passed target area, using the
  999. //  passed justification flags.
  1000. // ---------------------------------------
  1001. //   INPUT: areaTarget is area to justify to
  1002. //          eHJustify, eVJustify are the justification flags
  1003. //
  1004. //  OUTPUT: None
  1005. //
  1006. //  RETURN: None
  1007. //
  1008. tCIDLib::VOID PROCEXP AREA::JustifyIn(  const   AREA&               areaTarget
  1009.                                         ,       tCIDLib::eHJUSTIFY  eHJustify
  1010.                                         ,       tCIDLib::eVJUSTIFY  eVJustify)
  1011. {
  1012.     //
  1013.     //  Handle the horizontal justification
  1014.     //
  1015.     switch(eHJustify)
  1016.     {
  1017.         case tCIDLib::eHJUSTIFY_LEFT    :
  1018.             //  Set the x origin of this area to that of the target
  1019.             __i4X = areaTarget.__i4X;
  1020.             break;
  1021.  
  1022.         case tCIDLib::eHJUSTIFY_CENTER  :
  1023.             // Set the y to target.center/2 - cx/2
  1024.             __i4X = areaTarget.__i4X+(areaTarget.__c4CX >> 1);
  1025.             __i4X -= (__c4CX >> 1);
  1026.             break;
  1027.  
  1028.         case tCIDLib::eHJUSTIFY_RIGHT   :
  1029.             //  Set the x origin of this area to target.right-cx
  1030.             __i4X = (areaTarget.__i4X+areaTarget.__c4CX)-__c4CX;
  1031.             break;
  1032.  
  1033.         default         :
  1034.             facCIDGui.LogMsg(   __FILE__
  1035.                                 , "AREA::JustifyIn"
  1036.                                 , __LINE__
  1037.                                 , "Unknown horizontal justification"
  1038.                                 , tCIDLib::eSEV_PROCESS_FATAL);
  1039.             break;
  1040.     }
  1041.  
  1042.     //
  1043.     //  Handle the veritical justification
  1044.     //
  1045.     switch(eVJustify)
  1046.     {
  1047.         case tCIDLib::eVJUSTIFY_BOTTOM  :
  1048.             //  Set the y origin of this area to that of the target
  1049.             __i4Y = areaTarget.__i4Y;
  1050.             break;
  1051.  
  1052.         case tCIDLib::eVJUSTIFY_CENTER  :
  1053.             // Set the y to target.center/2 - cy/2
  1054.             __i4Y = areaTarget.__i4Y+(areaTarget.__c4CY >> 1);
  1055.             __i4Y -= (__c4CY >> 1);
  1056.             break;
  1057.  
  1058.         case tCIDLib::eVJUSTIFY_TOP     :
  1059.             //  Set the y origin of this area to target.top-cy
  1060.             __i4Y = (areaTarget.__i4Y+areaTarget.__c4CY)-__c4CY;
  1061.             break;
  1062.  
  1063.         default         :
  1064.             facCIDGui.LogMsg(   __FILE__
  1065.                                 , "AREA::JustifyIn"
  1066.                                 , __LINE__
  1067.                                 , "Unknown vertical justification"
  1068.                                 , tCIDLib::eSEV_PROCESS_FATAL);
  1069.             break;
  1070.     }
  1071. }
  1072.  
  1073.  
  1074. //
  1075. // FUNCTION/METHOD NAME: ToPtlArray(aptlTarget)
  1076. //
  1077. // DESCRIPTION:
  1078. //
  1079. //  This method will convert the passed area to an array of POINT structures
  1080. //  that start and end at the lower left corner and go clockwise.
  1081. // ---------------------------------------
  1082. //   INPUT: None
  1083. //
  1084. //  OUTPUT: aptlTarget is a pointer to an array of 5 POINTL structures.
  1085. //
  1086. //  RETURN: None
  1087. //
  1088. tCIDLib::VOID PROCEXP AREA::ToPtlArray(POINTL* aptlTarget)
  1089. {
  1090.     aptlTarget[0].x = __i4X;
  1091.     aptlTarget[0].y = __i4Y;
  1092.  
  1093.     aptlTarget[1].x = __i4X;
  1094.  
  1095.     if (__c4CY)
  1096.     {
  1097.         aptlTarget[1].y = (__i4Y + tCIDLib::INT4(__c4CY)) - 1;
  1098.         aptlTarget[2].y = (__i4Y + tCIDLib::INT4(__c4CY)) - 1;
  1099.     }
  1100.      else
  1101.     {
  1102.         aptlTarget[1].y = __i4Y;
  1103.         aptlTarget[2].y = __i4Y;
  1104.     }
  1105.  
  1106.     if (__c4CX)
  1107.     {
  1108.         aptlTarget[2].x = (__i4X + tCIDLib::INT4(__c4CX))-1;
  1109.         aptlTarget[3].x = (__i4X + tCIDLib::INT4(__c4CX))-1;
  1110.     }
  1111.      else
  1112.     {
  1113.         aptlTarget[2].x = __i4X;
  1114.         aptlTarget[3].x = __i4X;
  1115.     }
  1116.  
  1117.     aptlTarget[3].y = __i4Y;
  1118.  
  1119.     aptlTarget[4].x = __i4X;
  1120.     aptlTarget[4].y = __i4Y;
  1121. }
  1122.  
  1123.  
  1124. //
  1125. // FUNCTION/METHOD NAME: ToCornerPtls(ptlLLeft, ptlULeft, ptlURight, ptlLRight)
  1126. //
  1127. // DESCRIPTION:
  1128. //
  1129. //  This method will fill in the passed POINTL objects with the corners of the
  1130. //  area.
  1131. // ---------------------------------------
  1132. //   INPUT: None
  1133. //
  1134. //  OUTPUT: ptlLLeft, ptlULeft, ptlURight, ptlLRight are the POINTL structures
  1135. //              to fill in.
  1136. //
  1137. //  RETURN: None
  1138. //
  1139. tCIDLib::VOID PROCEXP AREA::ToCornerPtls(   POINTL&     ptlLLeft
  1140.                                             , POINTL&   ptlULeft
  1141.                                             , POINTL&   ptlURight
  1142.                                             , POINTL&   ptlLRight) const
  1143. {
  1144.     ptlLLeft.x  = __i4X;
  1145.     ptlLLeft.y  = __i4Y;
  1146.  
  1147.     ptlULeft.x  = __i4X;
  1148.  
  1149.     if (__c4CY)
  1150.     {
  1151.         ptlULeft.y  = (__i4Y + tCIDLib::INT4(__c4CY))-1;
  1152.         ptlURight.y = (__i4Y + tCIDLib::INT4(__c4CY))-1;
  1153.     }
  1154.      else
  1155.     {
  1156.         ptlULeft.y  = __i4Y;
  1157.         ptlURight.y = __i4Y;
  1158.     }
  1159.  
  1160.     if (__c4CX)
  1161.     {
  1162.         ptlURight.x = (__i4X + tCIDLib::INT4(__c4CX))-1;
  1163.         ptlLRight.x = (__i4X + tCIDLib::INT4(__c4CX))-1;
  1164.     }
  1165.      else
  1166.     {
  1167.         ptlURight.x = __i4X;
  1168.         ptlLRight.x = __i4X;
  1169.     }
  1170.  
  1171.     ptlLRight.y = __i4Y;
  1172. }
  1173.  
  1174.  
  1175. //
  1176. // FUNCTION/METHOD NAME: ToCornerPnts(pntLLeft, pntULeft, pntURight, pntLRight)
  1177. //
  1178. // DESCRIPTION:
  1179. //
  1180. //  This method will convert the area to 4 POINT objects that represent the
  1181. //  corners of the box.
  1182. // ---------------------------------------
  1183. //   INPUT: None
  1184. //
  1185. //  OUTPUT: pntLLeft, pntULeft, pntURight, pntLRight are the POINT objects to
  1186. //              fill in.
  1187. //
  1188. //  RETURN: None
  1189. //
  1190. tCIDLib::VOID PROCEXP AREA::ToCornerPnts(   POINT&      pntLLeft
  1191.                                             , POINT&    pntULeft
  1192.                                             , POINT&    pntURight
  1193.                                             , POINT&    pntLRight) const
  1194. {
  1195.     pntLLeft.i4X(__i4X);
  1196.     pntLLeft.i4Y(__i4Y);
  1197.  
  1198.     pntULeft.i4X(__i4X);
  1199.  
  1200.     if (__c4CY)
  1201.     {
  1202.         pntULeft.i4Y((__i4Y+__c4CY)-1);
  1203.         pntURight.i4Y((__i4Y+__c4CY)-1);
  1204.     }
  1205.      else
  1206.     {
  1207.         pntULeft.i4Y(__i4Y);
  1208.         pntURight.i4Y(__i4Y);
  1209.     }
  1210.  
  1211.     if (__c4CX)
  1212.     {
  1213.         pntURight.i4X((__i4X+__c4CX)-1);
  1214.         pntLRight.i4X((__i4X+__c4CX)-1);
  1215.     }
  1216.      else
  1217.     {
  1218.         pntURight.i4X(__i4X);
  1219.         pntLRight.i4X(__i4X);
  1220.     }
  1221.  
  1222.     pntLRight.i4Y(__i4Y);
  1223. }
  1224.  
  1225.  
  1226. //
  1227. // FUNCTION/METHOD NAME: ToPtls(ptlLLeft, ptlURight)
  1228. //
  1229. // DESCRIPTION:
  1230. //
  1231. //  This method will convert this area to a set of PM POINTL structures.
  1232. // ---------------------------------------
  1233. //   INPUT: None
  1234. //
  1235. //  OUTPUT: ptlLLeft, ptlURight are the two points that will be filled in
  1236. //
  1237. //  RETURN: None
  1238. //
  1239. tCIDLib::VOID PROCEXP AREA::ToPtls(POINTL& ptlLLeft, POINTL& ptlURight) const
  1240. {
  1241.     ptlLLeft.x = __i4X;
  1242.     ptlLLeft.y = __i4Y;
  1243.  
  1244.     if (__c4CX)
  1245.         ptlURight.x = (__i4X + tCIDLib::INT4(__c4CX))-1;
  1246.      else
  1247.         ptlURight.x = __i4X;
  1248.  
  1249.     if (__c4CY)
  1250.         ptlURight.y = (__i4Y + tCIDLib::INT4(__c4CY))-1;
  1251.      else
  1252.         ptlURight.y = __i4Y;
  1253. }
  1254.  
  1255.  
  1256. //
  1257. // FUNCTION/METHOD NAME: ToRectl(rectlDest, eInclusive)
  1258. //
  1259. // DESCRIPTION:
  1260. //
  1261. //  This guy will convert the area to a rectangle, which is either inclusive or
  1262. //  non-inclusive
  1263. //
  1264. //  NOTE: This guy is NOT exported
  1265. // ---------------------------------------
  1266. //   INPUT: eInclusive indicates whether the destination rectangle should be
  1267. //              an inclusive one or not.
  1268. //
  1269. //  OUTPUT: rectlDest is the destination rectangle to convert to.
  1270. //
  1271. //  RETURN: None
  1272. //
  1273. tCIDLib::VOID PROCEXP AREA::ToRectl(RECTL&                  rectlDest
  1274.                                     , tCIDGui::eRECTLTYPE   eInclusive) const
  1275. {
  1276.     // Create a inclusive rectangle
  1277.     rectlDest.xLeft     = __i4X;
  1278.     rectlDest.yBottom   = __i4Y;
  1279.  
  1280.     rectlDest.xRight    = __i4X+tCIDLib::INT4(__c4CX);
  1281.     rectlDest.yTop      = __i4Y+tCIDLib::INT4(__c4CY);
  1282.  
  1283.     //
  1284.     //  If the rectangle is inclusive, then bump down the upper right corner
  1285.     //  so that it lies on the upper right sides.
  1286.     //
  1287.     if (eInclusive == tCIDGui::eRECTL_INCLUSIVE)
  1288.     {
  1289.         if (__c4CX)
  1290.             rectlDest.xRight--;
  1291.         if (__c4CY)
  1292.             rectlDest.yTop--;
  1293.     }
  1294. }
  1295.  
  1296.  
  1297. //
  1298. // FUNCTION/METHOD NAME: ToSwp(swpDest)
  1299. //
  1300. // DESCRIPTION:
  1301. //
  1302. //  This method will convert this area object to the destination SWP structure.
  1303. //
  1304. //  NOTE: This guy is NOT exported
  1305. // ---------------------------------------
  1306. //   INPUT: None
  1307. //
  1308. //  OUTPUT: swpDest is the destination SWP structure to convert to
  1309. //
  1310. //  RETURN: None
  1311. //
  1312. tCIDLib::VOID PROCEXP AREA::ToSwp(SWP& swpSrc) const
  1313. {
  1314.     swpSrc.x    = __i4X;
  1315.     swpSrc.y    = __i4Y;
  1316.     swpSrc.cx   = tCIDLib::INT4(__c4CX);
  1317.     swpSrc.cy   = tCIDLib::INT4(__c4CY);
  1318. }
  1319.  
  1320.  
  1321. // -----------------------------------------------------------------------------
  1322. //  AREA: Protected, inherited methods
  1323. // -----------------------------------------------------------------------------
  1324.  
  1325. //
  1326. // FUNCTION/METHOD NAME: _bIsEqual(objTarget) const
  1327. //
  1328. // DESCRIPTION:
  1329. //
  1330. // ---------------------------------------
  1331. //   INPUT: objTarget is the target object to compare against
  1332. //
  1333. //  OUTPUT: None
  1334. //
  1335. //  RETURN: eTRUE if the objects are equal, else eFALSE.
  1336. //
  1337. tCIDLib::eBOOL PROCEXP AREA::_bIsEqual(const CIDOBJECT& objTarget) const
  1338. {
  1339.     // Call our parent version first
  1340.     if (!CIDSTORABLE::_bIsEqual(objTarget))
  1341.         return tCIDLib::eFALSE;
  1342.  
  1343.     // Look at the object as a window
  1344.     AREA* pareaTarget = (AREA*)(&objTarget);
  1345.  
  1346.     if (pareaTarget->__i4X != __i4X)   return tCIDLib::eFALSE;
  1347.     if (pareaTarget->__i4Y != __i4Y)   return tCIDLib::eFALSE;
  1348.     if (pareaTarget->__c4CX != __c4CX) return tCIDLib::eFALSE;
  1349.     if (pareaTarget->__c4CY != __c4CY) return tCIDLib::eFALSE;
  1350.  
  1351.     return tCIDLib::eTRUE;
  1352. }
  1353.  
  1354.  
  1355.  
  1356. // -----------------------------------------------------------------------------
  1357. //   CLASS: POINT
  1358. //  PREFIX: pnt
  1359. //
  1360. //  This class defines a 2 dimensional point.
  1361. // -----------------------------------------------------------------------------
  1362.  
  1363. // -----------------------------------------------------------------------------
  1364. //  POINT: Constructors and Destructors
  1365. // -----------------------------------------------------------------------------
  1366.  
  1367. //
  1368. // FUNCTION/METHOD NAME: POINT(pntSrc)
  1369. //                       POINT()
  1370. //                       POINT(x, y)
  1371. //                       POINT(ptlSrc)
  1372. //
  1373. // DESCRIPTION:
  1374. //
  1375. //  These are the various constructors for the POINT class.
  1376. // ---------------------------------------
  1377. //   INPUT: pntSrc is the source POINT for the copy constructor
  1378. //          i4X, i4Y are the x,y values to construct from separate x,y values.
  1379. //          ptlSrc is the PM POINTL struct to construct from.
  1380. //
  1381. //  OUTPUT: None
  1382. //
  1383. //  RETURN: None
  1384. //
  1385. PROCEXP POINT::POINT(const POINT& pntSrc) :
  1386.  
  1387.     __i4X(pntSrc.__i4X)
  1388.     , __i4Y(pntSrc.__i4Y)
  1389. {
  1390. }
  1391.  
  1392. PROCEXP POINT::POINT() :
  1393.  
  1394.     __i4X(0)
  1395.     , __i4Y(0)
  1396. {
  1397. }
  1398.  
  1399. PROCEXP POINT::POINT(const POINTL& ptlSrc) :
  1400.  
  1401.     __i4X(ptlSrc.x)
  1402.     , __i4Y(ptlSrc.y)
  1403. {
  1404. }
  1405.  
  1406. PROCEXP POINT::POINT(tCIDLib::INT4 i4X, tCIDLib::INT4 i4Y) :
  1407.  
  1408.     __i4X(i4X)
  1409.     , __i4Y(i4Y)
  1410. {
  1411. }
  1412.  
  1413.  
  1414. // -----------------------------------------------------------------------------
  1415. //  POINT: Public, inherited methods
  1416. // -----------------------------------------------------------------------------
  1417.  
  1418. //
  1419. // FUNCTION/METHOD NAME: FormatAt(pszBuf, c4CurInd);
  1420. //
  1421. // DESCRIPTION:
  1422. //
  1423. //  This message is called to format this class' members into the passed buffer.
  1424. // ---------------------------------------
  1425. //   INPUT: pszBuf is a pointer to the buffer to format into
  1426. //          c4CurInd is the index at which this class should start formatting.
  1427. //
  1428. //  OUTPUT: None
  1429. //
  1430. //  RETURN: None
  1431. //
  1432. tCIDLib::VOID PROCEXP
  1433.         POINT::FormatAt(tCIDLib::CH* pszBuf, tCIDLib::CARD4& c4CurInd) const
  1434. {
  1435.     // Call our parent's version
  1436.     CIDSTORABLE::FormatAt(pszBuf, c4CurInd);
  1437.  
  1438.     // Address our starting position in the buffer and remember where we started
  1439.     tCIDLib::CH* pszTmp     = &pszBuf[c4CurInd];
  1440.     tCIDLib::CH* pszStart   = pszTmp;
  1441.  
  1442.     // Write out the origin and size information
  1443.     *(tCIDLib::INT4*)pszTmp = __i4X;
  1444.     pszTmp += sizeof(__i4X);
  1445.  
  1446.     *(tCIDLib::INT4*)pszTmp = __i4Y;
  1447.     pszTmp += sizeof(__i4Y);
  1448.  
  1449.     // Bump up cCurInd by the bytes we used
  1450.     c4CurInd += tCIDLib::CARD4(pszTmp-pszStart);
  1451. }
  1452.  
  1453.  
  1454. //
  1455. // FUNCTION/METHOD NAME: FormatToStr(strbDest) const
  1456. //
  1457. // DESCRIPTION:
  1458. //
  1459. //  This method will format the data members into the passed string buffer
  1460. // ---------------------------------------
  1461. //   INPUT: None
  1462. //
  1463. //  OUTPUT: strbDest is the buffer to format into
  1464. //
  1465. //  RETURN: None
  1466. //
  1467. tCIDLib::VOID PROCEXP POINT::FormatToStr(STRGBUF& strbDest) const
  1468. {
  1469.     strbDest << "X=" << __i4X << ",Y=" << __i4Y;
  1470. }
  1471.  
  1472.  
  1473. //
  1474. // FUNCTION/METHOD NAME: ParseAt(pszBuf, c4CurInd)
  1475. //
  1476. // DESCRIPTION:
  1477. //
  1478. //  This method will parse the data from the passed buffer into this object. We
  1479. //  first call our parent class, then parse out our data members.
  1480. // ---------------------------------------
  1481. //   INPUT: pszBuf is the buffer to parse from.
  1482. //          c4CurInd is where we start parsing from.
  1483. //
  1484. //  OUTPUT: c4CurInd is bumped up by the number of bytes parsed at this level
  1485. //              and all below us
  1486. //
  1487. //  RETURN: None
  1488. //
  1489. tCIDLib::VOID PROCEXP
  1490.         POINT::ParseAt(const tCIDLib::CH* pszBuf, tCIDLib::CARD4& c4CurInd)
  1491. {
  1492.     // Call our parent's version
  1493.     CIDSTORABLE::ParseAt(pszBuf, c4CurInd);
  1494.  
  1495.     // Address our starting position in the buffer
  1496.     const tCIDLib::CH* pszTmp   = &pszBuf[c4CurInd];
  1497.     const tCIDLib::CH* pszStart = pszTmp;
  1498.  
  1499.     // Get the vector value
  1500.     __i4X = *(tCIDLib::CARD4*)pszTmp;
  1501.     pszTmp += sizeof(__i4X);
  1502.  
  1503.     __i4Y = *(tCIDLib::CARD4*)pszTmp;
  1504.     pszTmp += sizeof(__i4Y);
  1505.  
  1506.     // Bump up cCurInd by the bytes we used
  1507.     c4CurInd += tCIDLib::CARD4(pszTmp-pszStart);
  1508. }
  1509.  
  1510.  
  1511. // -----------------------------------------------------------------------------
  1512. //  POINT: Public, non-virtual methods
  1513. // -----------------------------------------------------------------------------
  1514.  
  1515. //
  1516. // FUNCTION/METHOD NAME: operator POINT*() const
  1517. //
  1518. // DESCRIPTION:
  1519. //
  1520. //  This guy allows us to pass point objects straight to POINTL pointers
  1521. //  internally.
  1522. // ---------------------------------------
  1523. //   INPUT: None
  1524. //
  1525. //  OUTPUT: None
  1526. //
  1527. //  RETURN: A pointer to the __i4X element, cast to a POINTL*
  1528. //
  1529. PROCEXP POINT::operator POINTL*() const
  1530. {
  1531.     return (POINTL*)&__i4X;
  1532. }
  1533.  
  1534.  
  1535. //
  1536. // FUNCTION/METHOD NAME: bInArea(areaTarget) const
  1537. //
  1538. // DESCRIPTION:
  1539. //
  1540. //  This method checks to see if the point is in the passed area.
  1541. // ---------------------------------------
  1542. //   INPUT: areaTarget is the area to check against
  1543. //
  1544. //  OUTPUT: None
  1545. //
  1546. //  RETURN: eTRUE if the point is in the passed area, else eFALSE.
  1547. //
  1548. tCIDLib::eBOOL PROCEXP POINT::bInArea(const AREA& areaTarget) const
  1549. {
  1550.     if ((__i4X < areaTarget.i4X())
  1551.     ||  (__i4Y < areaTarget.i4Y())
  1552.     ||  (__i4X > areaTarget.i4XRight())
  1553.     ||  (__i4Y > areaTarget.i4YTop()))
  1554.     {
  1555.         return tCIDLib::eFALSE;
  1556.     }
  1557.     return tCIDLib::eTRUE;
  1558. }
  1559.  
  1560.  
  1561. //
  1562. // FUNCTION/METHOD NAME: FromPtl(ptlSrc)
  1563. //
  1564. // DESCRIPTION:
  1565. //
  1566. //  This method will parse the passed PM POINTL into this object
  1567. // ---------------------------------------
  1568. //   INPUT: ptlSrc is the source PM POINT to parse
  1569. //
  1570. //  OUTPUT: None
  1571. //
  1572. //  RETURN: None
  1573. //
  1574. tCIDLib::VOID PROCEXP POINT::FromPtl(const POINTL& ptlSrc)
  1575. {
  1576.     __i4X = ptlSrc.x;
  1577.     __i4Y = ptlSrc.y;
  1578. }
  1579.  
  1580.  
  1581. //
  1582. // FUNCTION/METHOD NAME: ToPtl(ptlTarget)
  1583. //
  1584. // DESCRIPTION:
  1585. //
  1586. //  This method will fill the passed PM POINTL with this object's point info
  1587. // ---------------------------------------
  1588. //   INPUT: None
  1589. //
  1590. //  OUTPUT: ptlTarget is the target of the point information
  1591. //
  1592. //  RETURN: None
  1593. //
  1594. tCIDLib::VOID PROCEXP POINT::ToPtl(POINTL& ptlTarget) const
  1595. {
  1596.     ptlTarget.x    = __i4X;
  1597.     ptlTarget.y    = __i4Y;
  1598. }
  1599.  
  1600.  
  1601. // -----------------------------------------------------------------------------
  1602. //  POINT: Protected, inherited methods
  1603. // -----------------------------------------------------------------------------
  1604.  
  1605. //
  1606. // FUNCTION/METHOD NAME: _bIsEqual(objTarget) const
  1607. //
  1608. // DESCRIPTION:
  1609. //
  1610. //  This method will compare this object's members at this class level with
  1611. //  those of the target object.
  1612. // ---------------------------------------
  1613. //   INPUT: objTarget is the target object to compare against
  1614. //
  1615. //  OUTPUT: None
  1616. //
  1617. //  RETURN: eTRUE if the objects are equal, else eFALSE.
  1618. //
  1619. tCIDLib::eBOOL PROCEXP POINT::_bIsEqual(const CIDOBJECT& objTarget) const
  1620. {
  1621.     // Call our parent's version first
  1622.     if (!CIDSTORABLE::_bIsEqual(objTarget))
  1623.         return tCIDLib::eFALSE;
  1624.  
  1625.     // Look at the object as a window
  1626.     POINT* ppntTarget = (POINT*)(&objTarget);
  1627.  
  1628.     if (ppntTarget->__i4X != __i4X)   return tCIDLib::eFALSE;
  1629.     if (ppntTarget->__i4Y != __i4Y)   return tCIDLib::eFALSE;
  1630.  
  1631.     return tCIDLib::eTRUE;
  1632. }
  1633.