home *** CD-ROM | disk | FTP | other *** search
/ OS/2 Shareware BBS: 10 Tools / 10-Tools.zip / deans.zip / BASE.HPP < prev    next >
Text File  |  1994-09-14  |  22KB  |  690 lines

  1. //
  2. // NAME: CIDGui_Base.Hpp
  3. //
  4. // DESCRIPTION:
  5. //
  6. //  This is the header for the CIDGui_Base.Cpp module. This module provides the
  7. //  most basic classes needed by this facility. These are classes such as AREA
  8. //  and POINT which define a rectangular area or a 2 dimensional point
  9. //  respectively. Since these are used so often for a number of operations, they
  10. //  are made classes.
  11. //
  12. //  An area with a width or height of 0 is empty. When 1 the area includes 1
  13. //  pixel.
  14. //
  15. //  The class hierarchy here is:
  16. //
  17. //              CIDOBJECT
  18. //                  |
  19. //             CIDSTORABLE
  20. //                  |
  21. //        |-----|-------|
  22. //      AREA  POINT
  23. //
  24. //
  25. // AUTHOR: Dean Roddey
  26. //
  27. // CREATE DATE: 05/23/93
  28. //
  29. // COPYRIGHT: 1992..1994, 'CIDCorp
  30. //
  31. // CAVEATS/GOTCHAS:
  32. //
  33. //  1)  Note that the methods i4XRight() and i4YTop() methods will return the
  34. //      same thing for an empty area as for an area of 1x1. There is no way to
  35. //      avoid this. Client apps must be aware of watching for empty areas.
  36. //
  37. //  2)  If you convert a non-inclusive rect to an area, but that rectangle's
  38. //      horizontal or vertical left or right are equal, that is really an
  39. //      error because no such creature exists. However, the result will just
  40. //      be an empty area.
  41. //
  42. // MODIFICATION LOG:
  43. //
  44.  
  45.  
  46. // Avoid multiple inclusions
  47. #if            !defined(CIDGUI_BASE_HPP)
  48. #define        CIDGUI_BASE_HPP
  49.  
  50. typedef struct  _POINTL POINTL;
  51. class           AREA;
  52.  
  53.  
  54. // -----------------------------------------------------------------------------
  55. //   CLASS: POINT
  56. //  PREFIX: pnt
  57. //
  58. //  This class defines a 2 dimensional point. The coordinates are 32 bit signed
  59. //  values
  60. // -----------------------------------------------------------------------------
  61. class           POINT : public CIDSTORABLE
  62. {
  63.     public      :
  64.         // ---------------------------------------------------------------------
  65.         //  Constructors and Destructors
  66.         //
  67.         //  POINT
  68.         //      We have 4 constructors, one that provides default 0 values,
  69.         //      one that accepts the x and y, one that accepts a PM POINTL,
  70.         //      and the the copy constructor.
  71.         // ---------------------------------------------------------------------
  72.         POINT();
  73.  
  74.         POINT
  75.         (
  76.             const   POINTL&                 ptlSrc
  77.         );
  78.  
  79.         POINT
  80.         (
  81.                     tCIDLib::INT4           x
  82.             ,       tCIDLib::INT4           y
  83.         );
  84.  
  85.         POINT
  86.         (
  87.             const   POINT&                  pntSrc
  88.         );
  89.  
  90.  
  91.         // ---------------------------------------------------------------------
  92.         //  Public, inherited methods
  93.         //
  94.         //  FormatAt
  95.         //      This method is called from the public pFormatToBuf() to handle
  96.         //      formatting this object into the passed buffer.
  97.         //
  98.         //  FormatToStr
  99.         //      Formats the object's data members into the string buffer
  100.         //
  101.         //  ParseAt
  102.         //      This method is called from the public bParseFromBuf() to handle
  103.         //      parsing this object's data from the passed buffer.
  104.         // ---------------------------------------------------------------------
  105.         STDVPUBMETHODS(POINT,CIDSTORABLE,tCIDLib::eFALSE);
  106.  
  107.         virtual tCIDLib::VOID FormatAt
  108.         (
  109.                     tCIDLib::CH*            pszBuf
  110.             ,       tCIDLib::CARD4&         c4CurInd
  111.         )   const;
  112.  
  113.         virtual tCIDLib::VOID FormatToStr
  114.         (
  115.                     STRGBUF&                strbDest
  116.         )   const;
  117.  
  118.         virtual tCIDLib::VOID ParseAt
  119.         (
  120.             const   tCIDLib::CH*            pszBuf
  121.             ,       tCIDLib::CARD4&         c4CurInd
  122.         );
  123.  
  124.  
  125.         // ---------------------------------------------------------------------
  126.         //  Pubic, non-virtual methods
  127.         //
  128.         //  operator POINTL*
  129.         //      This guy allows us to pass POINTL objects straight to PM
  130.         //      POINTL* parameters.
  131.         //
  132.         //  bInArea
  133.         //      Returns eTRUE if the point lies in the passed area
  134.         //
  135.         //  Exchange
  136.         //      This method will exchange the x and y components
  137.         //
  138.         //  FromPtl
  139.         //      Parses a PM POINTL into this point object
  140.         //
  141.         //  Offset
  142.         //      This method will add the passed offset values to the current x
  143.         //      and y values.
  144.         //
  145.         //  ToPtl
  146.         //      Puts the point info into a PM POINTL
  147.         //
  148.         //  x, y
  149.         //      These get/set the x and y data members.
  150.         // ---------------------------------------------------------------------
  151.         operator POINTL*() const;
  152.  
  153.         tCIDLib::eBOOL bInArea
  154.         (
  155.             const   AREA&                   areaTarget
  156.         )   const;
  157.  
  158.         tCIDLib::VOID Exchange
  159.         (
  160.         )           {tCIDLib::INT4 i4Tmp=__i4X; __i4X=__i4Y;__i4Y=i4Tmp;}
  161.  
  162.         tCIDLib::VOID FromPtl
  163.         (
  164.             const   POINTL&                 ptlSrc
  165.         );
  166.  
  167.         tCIDLib::VOID Offset
  168.         (
  169.                     tCIDLib::INT4           ofsX
  170.             ,       tCIDLib::INT4           ofsY
  171.         )           {__i4X += ofsX; __i4Y += ofsY;}
  172.  
  173.         tCIDLib::VOID ToPtl
  174.         (
  175.                     POINTL&                 ptlTarget
  176.         )   const;
  177.  
  178.         tCIDLib::INT4 i4X
  179.         (
  180.         )   const   {return __i4X;}
  181.  
  182.         tCIDLib::INT4 i4X
  183.         (
  184.                     tCIDLib::INT4           x
  185.         )           {__i4X=x;return __i4X;}
  186.  
  187.         tCIDLib::INT4 i4Y
  188.         (
  189.         )   const   {return __i4Y;}
  190.  
  191.         tCIDLib::INT4 i4Y
  192.         (
  193.                     tCIDLib::INT4           y
  194.         )           {__i4Y=y;return __i4Y;}
  195.  
  196.  
  197.     protected   :
  198.         // ---------------------------------------------------------------------
  199.         //  Protected, inherited methods
  200.         //
  201.         //  _bIsEqual
  202.         //      This method is called from the public bIsEqual, which has
  203.         //      determined that the objects are of comparable classes and
  204.         //      are not the same object. It does the comparison down the
  205.         //      class hierarchy.
  206.         //
  207.         //  _StorageBytes
  208.         //      This method will add, to c4CurCount, the number of storage
  209.         //      bytes needed to store an object of this type.
  210.         // ---------------------------------------------------------------------
  211.         virtual tCIDLib::eBOOL _bIsEqual
  212.         (
  213.             const   CIDOBJECT&              objTarget
  214.         )   const;
  215.  
  216.         virtual tCIDLib::VOID _StorageBytes
  217.         (
  218.                     tCIDLib::CARD4&         c4CurCount
  219.         )  const    {CIDSTORABLE::_StorageBytes(c4CurCount); c4CurCount += 8;}
  220.  
  221.  
  222.     private     :
  223.         // ---------------------------------------------------------------------
  224.         //  Private data members
  225.         //
  226.         //  __i4X
  227.         //  __i4Y
  228.         //      Storage for the x,y coordinates.
  229.         // ---------------------------------------------------------------------
  230.         tCIDLib::INT4           __i4X, __i4Y;
  231. };
  232.  
  233. #define NUL_POINT               (*(POINT*)0)
  234.  
  235.  
  236.  
  237. // -----------------------------------------------------------------------------
  238. //   CLASS: AREA
  239. //  PREFIX: area
  240. //
  241. //  This class defines a rectangular area with an integral x,y origin and a
  242. //  cardinal cx,cy length and width.
  243. // -----------------------------------------------------------------------------
  244. class           AREA : public CIDSTORABLE
  245. {
  246.     public      :
  247.         // ---------------------------------------------------------------------
  248.         //  Constuctors and Destructors
  249.         //
  250.         //  AREA
  251.         //      There are a number of possible constructors here since great
  252.         //      flexibility is greatly paid back. This is a heavily used class.
  253.         //      The compiler's default constructor is ok.
  254.         // ---------------------------------------------------------------------
  255.         AREA();
  256.  
  257.         AREA
  258.         (
  259.             const   RECTL&                  rectlSrc
  260.             ,       tCIDGui::eRECTLTYPE     eInclusive
  261.         );
  262.  
  263.         AREA
  264.         (
  265.             const   SWP&                    swpSrc
  266.         );
  267.  
  268.         AREA
  269.         (
  270.             const   POINTL&                 ptlLLeft
  271.             , const POINTL&                 ptlURight
  272.         );
  273.  
  274.         AREA
  275.         (
  276.             const   POINT&                  pntLLeft
  277.             , const POINT&                  pntURight
  278.         );
  279.  
  280.         AREA
  281.         (
  282.                     tCIDLib::INT4           x
  283.             ,       tCIDLib::INT4           y
  284.             ,       tCIDLib::CARD4          cx
  285.             ,       tCIDLib::CARD4          cy
  286.         );
  287.  
  288.         AREA
  289.         (
  290.             const   AREA&                   areaSrc
  291.         );
  292.  
  293.  
  294.         // ---------------------------------------------------------------------
  295.         //  Public, inherited, virtual methods
  296.         //
  297.         //  FormatAt
  298.         //      This method is called from the public pFormatToBuf() to handle
  299.         //      formatting this object into the passed buffer.
  300.         //
  301.         //  FormatToStr
  302.         //      Formats the object's data members into the string buffer
  303.         //
  304.         //  ParseAt
  305.         //      This method is called from the public bParseFromBuf() to handle
  306.         //      parsing this object's data from the passed buffer.
  307.         // ---------------------------------------------------------------------
  308.         STDVPUBMETHODS(AREA,CIDSTORABLE,tCIDLib::eFALSE);
  309.  
  310.         virtual tCIDLib::VOID FormatAt
  311.         (
  312.                     tCIDLib::CH*            pszBuf
  313.             ,       tCIDLib::CARD4&         c4CurInd
  314.         )   const;
  315.  
  316.         virtual tCIDLib::VOID FormatToStr
  317.         (
  318.                     STRGBUF&                strbDest
  319.         ) const;
  320.  
  321.         virtual tCIDLib::VOID ParseAt
  322.         (
  323.             const   tCIDLib::CH*            pszBuf
  324.             ,       tCIDLib::CARD4&         c4CurInd
  325.         );
  326.  
  327.  
  328.         // ---------------------------------------------------------------------
  329.         //  Public, non-virtual methods
  330.         //
  331.         //  operator+
  332.         //  operator+=
  333.         //      These operators will add areas. Adding creates a union of the
  334.         //      two areas, which is an area that contains both of the original
  335.         //      areas.
  336.         //
  337.         //  operator-
  338.         //  operator-=
  339.         //      These operators will create an area that is the common portion
  340.         //      of both areas. If they don't overlap at all, then the area will
  341.         //      be empty. Note that, if they just touch on a common side, that
  342.         //      does not count as overlap.
  343.         //
  344.         //  AdjustOrg
  345.         //      This method will adjust the area origin by the indicated
  346.         //      offsets.
  347.         //
  348.         //  AdjustSides
  349.         //      This method will adjust the area by the passed x and y values.
  350.         //      The left and right sides will be adjusted by i4XOfs units. The
  351.         //      top and bottom sides will be adjusted by i4YOfs. Negative makes
  352.         //      the area smaller and positive makes it larger.
  353.         //
  354.         //  AdjustSize
  355.         //      This method will just adjust the cx and cy values by the passed
  356.         //      values.
  357.         //
  358.         //  areaHorzPercent
  359.         //  areaVertPercent
  360.         //      These methods will return an area that represents a percent of
  361.         //      the area, either horizontally or vertically.
  362.         //
  363.         //  bEmpty
  364.         //      If either the cx or cy is 0, then the area is empty.
  365.         //
  366.         //  bIntersects
  367.         //      Returns eTRUE if this object intersects the passed object.
  368.         //
  369.         //  c4CX, c4CY
  370.         //      These set or return the cx and cy members
  371.         //
  372.         //  FromPnts
  373.         //  FromPtls
  374.         //  FromRectl
  375.         //  FromSwp
  376.         //      For internal use to convert PM structures into area objects.
  377.         //      These are not exported to the outside world since they are for
  378.         //      internal use only. The one for rectangles has an optional buffer
  379.         //      that indicates that the passed rectangle is inclusive or
  380.         //      non-inclusive.
  381.         //
  382.         //  i4X, i4Y
  383.         //      These set or return the x and y members
  384.         //
  385.         //  i4XRight
  386.         //      This will return the value (__i4X+__c4CX)-1 if c4CX is larger
  387.         //      than 0 or just (__i4X+__c4CX) otherwise. This means that there
  388.         //      is no way to distinguish and empty or 1 sized area by calling
  389.         //      this method. The other version allows the right side to be set.
  390.         //      This will cause the horizontal size to be recalced.
  391.         //
  392.         //  i4YTop
  393.         //      This will return the value (__i4Y+__c4CY)-1 if c4CY is larger
  394.         //      than 0 or just (__i4Y+__c4CY) otherwise. This means that there
  395.         //      is no way to distinguish and empty or 1 sized area by calling
  396.         //      this method. The other version allows the top to be set. This
  397.         //      will cause the vertical size to be recalced.
  398.         //
  399.         //  pntCenter
  400.         //      This method will return the center of the area. If the cx or cy
  401.         //      is an odd number the odd 1 bit is shifted out, which means its
  402.         //      rounds toward the origin of the area.
  403.         //
  404.         //  pntOrg
  405.         //      This method will get/set x,y origin of the area as a POINT
  406.         //      object or as individual x and y values.
  407.         //
  408.         //  SetSizes
  409.         //      This method will just set the cx and cy values to the passed
  410.         //      values.
  411.         //
  412.         //  ToPtlArray
  413.         //      Converts the area into an array of 5 POINTL structures that
  414.         //      start and end at the lower left corner and goes clockwise.
  415.         //
  416.         //  ToCornerPtls
  417.         //  ToCornerPnts
  418.         //      Converts the area into either POINTL structures or POINT objects
  419.         //      that represent the corners of the area.
  420.         //
  421.         //  ToPnts
  422.         //  ToPtls
  423.         //  ToRectl
  424.         //  ToSwp
  425.         //      The opposite of the FromXXX methods above. Converts from areas
  426.         //      to the PM types or to 2 POINT objects.
  427.         //      For ToRectl, the second parm indicates whether the resulting
  428.         //      rectangle should be inclusive or not.
  429.         // ---------------------------------------------------------------------
  430.         AREA operator+
  431.         (
  432.             const   AREA&                   areaSrc
  433.         );
  434.  
  435.         tCIDLib::VOID operator+=
  436.         (
  437.             const   AREA&                   areaSrc
  438.         );
  439.  
  440.         AREA operator-
  441.         (
  442.             const   AREA&                   areaSrc
  443.         );
  444.  
  445.         tCIDLib::VOID operator-=
  446.         (
  447.             const   AREA&                   areaSrc
  448.         );
  449.  
  450.         tCIDLib::VOID AdjustOrg 
  451.         (
  452.                     tCIDLib::INT4           i4XOfs
  453.             ,       tCIDLib::INT4           i4YOfs
  454.         );
  455.  
  456.         tCIDLib::VOID AdjustOrg
  457.         (
  458.             const   POINT&                  pntOfs
  459.         );
  460.  
  461.         tCIDLib::VOID AdjustSides
  462.         (
  463.                     tCIDLib::INT4           i4XOfs
  464.             ,       tCIDLib::INT4           i4YOfs
  465.         );
  466.  
  467.         tCIDLib::VOID AdjustSize
  468.         (
  469.                     tCIDLib::INT4           i4CXOfs
  470.             ,       tCIDLib::INT4           i4CYOfs
  471.         );
  472.  
  473.         AREA areaHorzPercent
  474.         (
  475.                     tCIDLib::CARD4          c4Percent
  476.         )  const;
  477.  
  478.         AREA areaVertPercent
  479.         (
  480.                     tCIDLib::CARD4          c4Percent
  481.         )  const;
  482.  
  483.         tCIDLib::eBOOL bEmpty
  484.         (
  485.         )   const;
  486.  
  487.         tCIDLib::eBOOL bIntersects
  488.         (
  489.             const   AREA&                   areaTest
  490.         )   const;
  491.  
  492.         tCIDLib::CARD4 c4CX
  493.         (
  494.         )   const   {return __c4CX;}
  495.  
  496.         tCIDLib::CARD4 c4CX
  497.         (
  498.                     tCIDLib::CARD4          iNewCX
  499.         )           {__c4CX=iNewCX;return __c4CX;}
  500.  
  501.         tCIDLib::CARD4 c4CY
  502.         (
  503.         )   const   {return __c4CY;}
  504.  
  505.         tCIDLib::CARD4 c4CY
  506.         (
  507.                     tCIDLib::CARD4          iNewCY
  508.         )           {__c4CY=iNewCY;return __c4CY;}
  509.  
  510.         tCIDLib::VOID FromPnts
  511.         (
  512.             const   POINT&                  pntLLeft
  513.             , const POINT&                  pntURight
  514.         );
  515.  
  516.         tCIDLib::VOID FromPtls
  517.         (
  518.             const   POINTL&                 ptlLLeft
  519.             , const POINTL&                 ptlURight
  520.         );
  521.  
  522.         tCIDLib::VOID FromRectl
  523.         (
  524.             const   RECTL&                  rectlSrc
  525.             ,       tCIDGui::eRECTLTYPE     eInclusive
  526.         );
  527.  
  528.         tCIDLib::VOID FromSwp
  529.         (
  530.             const   SWP&                    swpSrc
  531.         );
  532.  
  533.         tCIDLib::VOID JustifyIn
  534.         (
  535.             const   AREA&                   areaTarget
  536.             ,       tCIDLib::eHJUSTIFY      eHJustify
  537.             ,       tCIDLib::eVJUSTIFY      eVJustify
  538.         );
  539.  
  540.         POINT pntCenter
  541.         (
  542.         )   const   {return POINT(__i4X+(__c4CX>>1), __i4Y+(__c4CY>>1));}
  543.  
  544.         POINT pntOrg
  545.         (
  546.         )   const   {return POINT(__i4X, __i4Y);}
  547.  
  548.         POINT pntOrg
  549.         (
  550.             const   POINT&                  pntNew
  551.         )           {__i4X=pntNew.i4X();__i4Y=pntNew.i4Y();return pntNew;}
  552.  
  553.         POINT pntOrg
  554.         (
  555.                     tCIDLib::INT4           i4X
  556.             ,       tCIDLib::INT4           i4Y
  557.         )           {__i4X=i4X;__i4Y=i4Y; return POINT(i4X,i4Y);}
  558.  
  559.         tCIDLib::VOID SetSizes
  560.         (
  561.                     tCIDLib::CARD4          c4CX
  562.             ,       tCIDLib::CARD4          c4CY
  563.         )           {__c4CX=c4CX;__c4CY=c4CY;}
  564.  
  565.         tCIDLib::VOID ToPtlArray
  566.         (
  567.                     POINTL*                 aptlTarget
  568.         );
  569.  
  570.         tCIDLib::VOID ToCornerPtls
  571.         (
  572.                     POINTL&                 ptlLLeft
  573.             ,       POINTL&                 ptlULeft
  574.             ,       POINTL&                 ptlURight
  575.             ,       POINTL&                 ptlLRight
  576.         )   const;
  577.  
  578.         tCIDLib::VOID ToCornerPnts
  579.         (
  580.                     POINT&                  pntLLeft
  581.             ,       POINT&                  pntULeft
  582.             ,       POINT&                  pntURight
  583.             ,       POINT&                  pntLRight
  584.         )   const;
  585.  
  586.         tCIDLib::VOID ToPnts
  587.         (
  588.                     POINT&                  pntLLeft
  589.             ,       POINT&                  pntURight
  590.         )   const;
  591.  
  592.         tCIDLib::VOID ToPtls
  593.         (
  594.                     POINTL&                 ptlLLeft
  595.             ,       POINTL&                 ptlURight
  596.         )   const;
  597.  
  598.         tCIDLib::VOID ToRectl
  599.         (
  600.                     RECTL&                  rectlSrc
  601.             ,       tCIDGui::eRECTLTYPE     eInclusive
  602.         )   const;
  603.  
  604.         tCIDLib::VOID ToSwp
  605.         (
  606.                     SWP&                    swpSrc
  607.         )   const;
  608.  
  609.         tCIDLib::INT4 i4X
  610.         (
  611.         )   const   {return __i4X;}
  612.  
  613.         tCIDLib::INT4 i4X
  614.         (
  615.                     tCIDLib::INT4           iNewX
  616.         )           {__i4X=iNewX;return __i4X;}
  617.  
  618.         tCIDLib::INT4 i4Y
  619.         (
  620.         )   const   {return __i4Y;}
  621.  
  622.         tCIDLib::INT4 i4Y
  623.         (
  624.                     tCIDLib::INT4           iNewY
  625.         )           {__i4Y=iNewY;return __i4Y;}
  626.  
  627.         tCIDLib:: INT4 i4XRight
  628.         (
  629.         )   const;
  630.  
  631.         tCIDLib:: INT4 i4XRight
  632.         (
  633.                     tCIDLib::INT4           i4XRight
  634.         );
  635.  
  636.         tCIDLib::INT4 i4YTop
  637.         (
  638.         )   const;
  639.  
  640.         tCIDLib::INT4 i4YTop
  641.         (
  642.                     tCIDLib::INT4           i4YTop
  643.         );
  644.  
  645.  
  646.     protected           :
  647.         // ---------------------------------------------------------------------
  648.         //  Protected, inherited methods
  649.         //
  650.         //  _bIsEqual
  651.         //      This method is called from the public bIsEqual, which has
  652.         //      determined that the objects are of comparable classes and are
  653.         //      not the same object. It does the comparison down the class
  654.         //      hierarchy.
  655.         //
  656.         //  _StorageBytes
  657.         //      This method will add, to c4CurCount, the number of storage
  658.         //      bytes needed to store an object of this type.
  659.         // ---------------------------------------------------------------------
  660.         virtual tCIDLib::eBOOL _bIsEqual
  661.         (
  662.             const   CIDOBJECT&              objTarget
  663.         )   const;
  664.  
  665.         virtual tCIDLib::VOID _StorageBytes
  666.         (
  667.                     tCIDLib::CARD4&         c4CurCount
  668.         )  const    {CIDSTORABLE::_StorageBytes(c4CurCount); c4CurCount += 16;}
  669.  
  670.     private             :
  671.         // ---------------------------------------------------------------------
  672.         //  Private data members
  673.         //
  674.         //  __i4X, __i4Y
  675.         //      The origin of the area. It is signed because it could start
  676.         //      below the origin of the window it is within.
  677.         //
  678.         //  __c4CX, __c4CY
  679.         //      The length and width of the area which always must be
  680.         //      positive.
  681.         // ---------------------------------------------------------------------
  682.         tCIDLib::CARD4          __c4CX, __c4CY;
  683.         tCIDLib::INT4           __i4X, __i4Y;
  684. };
  685.  
  686. #define NUL_AREA                (*(AREA*)0)
  687.  
  688. #endif
  689.  
  690.