home *** CD-ROM | disk | FTP | other *** search
/ OS/2 Professional Developers Kit 1992 November / Disc01 / Disc01.mdf / runnable / ibmc / ibmclass / icnrobj.hpp < prev    next >
Encoding:
C/C++ Source or Header  |  1992-10-26  |  17.8 KB  |  398 lines

  1. #ifndef _ICNROBJ_
  2.   #define _ICNROBJ_
  3. /*******************************************************************************
  4. * FILE NAME: icnrobj.hpp                                                       *
  5. *                                                                              *
  6. * DESCRIPTION:                                                                 *
  7. *   Declaration of the class(es):                                              *
  8. *     IContainerObject - Base container object class                           *
  9. *                                                                              *
  10. * COPYRIGHT:                                                                   *
  11. *   (C) Copyright IBM Corporation 1992                                         *
  12. *   All Rights Reserved                                                        *
  13. *   Licensed Materials * Property of IBM                                       *
  14. *                                                                              *
  15. * HISTORY:                                                                     *
  16. * $Log:   R:/ibmclass/icnr/vcs/icnrobj.hpv  $
  17. //
  18. //   Rev 1.12   25 Oct 1992 19:26:40   BOBLOVE
  19. //Updated documentation
  20. //
  21. //   Rev 1.11   25 Oct 1992 16:28:04   nunn
  22. //changed library name to ICLUI
  23. //
  24. //   Rev 1.10   25 Oct 1992 12:49:58   BOBLOVE
  25. //Added inline for setBase function
  26. //
  27. //   Rev 1.9   25 Oct 1992 11:17:40   BOBLOVE
  28. //External Beta Release
  29. *                                                                              *
  30. *******************************************************************************/
  31. #if !defined(_IVBASE_)
  32.   #include <ivbase.hpp>
  33. #endif
  34.  
  35. #if !defined(_ISTRING_)
  36.   #include <istring.hpp>
  37. #endif
  38.  
  39. #if !defined(_IBITFLAG_)
  40.   #include <ibitflag.hpp>
  41. #endif
  42.  
  43. #if !defined(_IHANDLE_)
  44.   #include <ihandle.hpp>
  45. #endif
  46.  
  47.  
  48. /* Change to BB */
  49. #ifdef _USEBB_
  50.   #include <isrtset.h>
  51. #else
  52.   #include <iset.hpp>
  53. #endif
  54.                                                   
  55.  
  56. // Class Forward Declarations  
  57. class IContainerObject;
  58. class IMiniCnrRecord;
  59. class IContainerControl;
  60. class IResourceId;
  61.  
  62.  
  63.  
  64. class IContainerObject : public IVBase
  65. {
  66. /*******************************************************************************
  67. * IContainerObject is the base class of all objects stored in a container.     *
  68. * This object is required to be subclassed to support additional data in the   *
  69. * Details View but may be used as is in other views. All instances of          *
  70. * this class must be created using operator new which is overloaded here       *
  71. * to provide the storage allocation required by the underlying OS/2 container  *
  72. * control.                                                                     *
  73. *                                                                              *
  74. * If this object is subclassed and data added for the details view, the data   *
  75. * must be contiguous with the data of this class and be one of the supported   *
  76. * types defined in IContainerColumn.  It is important to note that only the    *
  77. * string type can be edited.  The IString class is the recommended way to      *
  78. * store text data in an object subclass.                                       *
  79. *                                                                              *
  80. * Container initialization normally occurs when the first IContainerControl    *
  81. * is instantiated.  If container objects need to be instantiated earlier, the  *
  82. * function IContainerControl::initialize() should be called prior to the first *
  83. * instantiation but after the presentation environment has been initialized.   *
  84. *                                                                              *
  85. * It is recommended that you use a ResourceLibrary to load icons as it         *
  86. * is capable of satisfying multiple requests for the same icon with a          *
  87. * single load and will manage multiple references to the same object. Actual   *
  88. * icon deletion occurs when the use count reaches zero.                        *
  89. *                                                                              *
  90. * IContainerObjects can be added to multiple container at the same time. When  *
  91. * functions in this class modify an objects characteristics, they do so in     *
  92. * ALL containers that hold the object.  Functions exist in IContainerControl   *
  93. * that can be used to modify an object in a single container.                  *
  94. *                                                                              *
  95. *                                                                              *
  96. * EXAMPLE:                                                                     *
  97. *                                                                              *
  98. *                                                                              *
  99. * class Customer : public IContainerObject                                     *
  100. * {                                                                            *
  101. * public:                                                                      *
  102. *    Customer(const IString& Name,                                             *
  103. *             const IPointerHandle& Icon = 0,                                  *
  104. *             const IString& Address = IString(),                              *
  105. *             const IString& Phone = IString(),                                *
  106. *             unsigned long Age = 0)                                           *
  107. *       : IContainerObject(Name, hptrIcon),                                    *
  108. *         strCustomerAddress(Address),                                         *
  109. *         strCustomerPhone(Phone),                                             *
  110. *         ulCustomerAge(Age) {  }                                              *
  111. *                                                                              *
  112. * private:                                                                     *
  113. *   IString strCustomerAddress;                                                *
  114. *   IString strCustomerPhone;                                                  *
  115. *  unsigned long ulCustomerAge;                                                *
  116. * };                                                                           *
  117. *                                                                              *
  118. *                                                                              *
  119. * Customer ski("Blacky Diamond", 10, "Park City, Utah", "1-800-SKI-JUMP", 39); *
  120. *                                                                              *
  121. *                                                                              *
  122. *                                                                              *
  123. *******************************************************************************/
  124. friend class IContainerControl;
  125. friend class IContainerObject;
  126. friend class IMiniCnrRecord;
  127. friend IMiniCnrRecord* IRecFromObj( const IContainerObject* pcnrobj);
  128.  
  129. public:
  130.  
  131. enum emphasis { none, cursored, inuse, selected};
  132. enum state { ok=1, opened=2, noInvalidate=4, oneParent=8,
  133.                 multipleParents=16, noRefresh=32, invalid=64};
  134.  
  135. /*------------------------ CONSTRUCTORS/DESTRUCTORS ----------------------------
  136. | There are 4 ways to construct instances of this class:                       |
  137. |   1. By providing a character array for text and an IPointerHandle for the   |
  138. |      icon.                                                                   |
  139. |                                                                              |
  140. |   2. By providing an IString for text and an IPointerHandle for the          |
  141. |      icon.                                                                   |
  142. |                                                                              |
  143. |   3. By providing resource id's for both the text and icon.                  |
  144. |      icon.                                                                   |
  145. |                                                                              |
  146. |   4. From a copy of an existing object.  If the object is subclassed this    |
  147. |      copy constructor must be overloaded to ensure that the object is        |
  148. |      is copied correctly.                                                    |
  149. ------------------------------------------------------------------------------*/
  150.   IContainerObject( const char* Name = 0,
  151.                     const IPointerHandle& Icon = 0);
  152.  
  153.   IContainerObject( const IString& str = IString(),
  154.                     const IPointerHandle& Icon = 0);
  155.  
  156.   IContainerObject( const IResourceId& NameID,
  157.                     const IResourceId& IconId);
  158.  
  159.  
  160.   IContainerObject( const IContainerObject& cnrobj);
  161.  
  162. virtual
  163.   ~IContainerObject();
  164.  
  165. /*-------------------------------- ACCESSORS -----------------------------------
  166. | These functions provide means of getting and setting the accessible          |
  167. | attributes of instances of this class:                                       |
  168. |                                                                              |
  169. | setIcon               - Set new text for an object.                          |
  170. | setIconText           - Set a new icon for an object.                        |
  171. | icon                  - Return the icon handle of an object.                 |
  172. | iconText              - Return the text of an object.                        |
  173. | setInUse              - Set In-use emphasis for this object in all           |
  174. |                         containers.                                          |
  175. | removeInUse           - Remove In-use emphasis for this object in all        |
  176. |                         containers.                                          |
  177. | enableDataUpdate      - Enable this object to be updated in all containers.  |
  178. | disableDataUpdate     - Disable update of this object in all containers.     |
  179. | refresh               - Refresh this object in all containers.               |
  180. | enableDrop            - Enable this object to be dropped in all containers.  |
  181. | disableDrop           - Disable this object being dropped in all containers. |
  182. | setRefreshOn          - Set this objects state to refreshable.               |
  183. | setRefreshOff         - Inhibit refresh of this object.                      |
  184. | isInUse               - Return true if this object has In-use emphasis.      |
  185. | isReadOnly            - Return true if this object is read-only.             |
  186. | isDropOnAble          - Return true if this object can accept a drop.        |
  187. | isRefreshOn           - Return true if this object is in refresh state.      |
  188. | iconOffset            - Return the offset of the Objects IPointerHandle for  |
  189. |                         the icon. This allows the icon to be used in a       |
  190. |                         column of the details view.                          |
  191. | iconTextOffset        - Return the offset of the objects IString. This       |
  192. |                         allows the IString to be used in a                   |
  193. |                         column of the details view.                          |
  194. | setOpen               - Set open emphasis in all containers.                 |
  195. | setClose              - Remove open emphasis in all containers.              |
  196. | isOpen                - Return true if this object is open in all containers.|
  197. |                                                                              |
  198. ------------------------------------------------------------------------------*/
  199. IContainerObject
  200.  &setIcon( const IPointerHandle& Icon),
  201.  &setIcon( const IResourceId&  IconId),
  202.  &setIcon( unsigned long  IconId),
  203.  
  204.  &setIconText( const char* IconText),
  205.  &setIconText( const IString& IconText),
  206.  &setIconText( const IResourceId& IconTextId);
  207.  
  208. IPointerHandle 
  209.   icon() const;
  210. IString 
  211.   iconText() const;
  212.  
  213. IContainerObject
  214.  &setInUse(),
  215.  &removeInUse(),
  216.  
  217.  &enableDataUpdate(),
  218.  &disableDataUpdate(),
  219.  
  220.  
  221.  &enableDrop(),
  222.  &disableDrop(),
  223.  
  224.  &refresh(),
  225.  &setRefreshOn(),
  226.  &setRefreshOff();
  227.  
  228. Boolean
  229.   isInUse() const,
  230.   isReadOnly() const,
  231.   isDropOnAble() const,
  232.   isRefreshOn() const;
  233.  
  234. static unsigned long 
  235.   iconOffset(),
  236.   iconTextOffset();
  237.  
  238.  
  239. IContainerObject
  240.   &setOpen(),
  241.   &setClose();
  242. Boolean 
  243.   isOpen();
  244.  
  245.  
  246. /*------------------------ OBJECT ALLOCATION -----------------------------------
  247. | These functions provide all object allocation and deallocation for instances |
  248. | of the class.  Stack and static instances of this class are not allowed.     |
  249. | new      -   Allocate storage for a class instance.                          |
  250. | delete   -   Deallocate the storage of a class instance.                     |
  251. |                                                                              |
  252. ------------------------------------------------------------------------------*/
  253. void
  254.   *operator new(size_t size),
  255.    operator delete(void* );
  256.  
  257.  
  258. /*------------------------ SUBCLASS PROVIDED FUNCTIONS -------------------------
  259. | These functions must be provided by the subclass if the behavior is          |
  260. | required.                                                                    |
  261. | handleOpen - Called when Enter is pressed on an object or a mouse double     |
  262. |              click.                                                          |
  263. | objectCopy - Called when it is necessary to make a copy of an object. This   |
  264. |              occurs when "IContainerControl::copyObjectTo" is called.        |
  265. | operator== - Returns true if the objects are at the same storage location.   |
  266. ------------------------------------------------------------------------------*/
  267. virtual void
  268.   handleOpen(IContainerControl* pcnrctl);
  269.  
  270. virtual IContainerObject
  271.  *objectCopy();
  272.  
  273. Boolean 
  274.   operator== (const IContainerObject& cnrobj);
  275.  
  276.  
  277. /* The following will shortly be obsolete */
  278. const char
  279.  *iconTextRef() const;
  280.  
  281. #if 0
  282.       void setPopUpMenu(IPopUpMenu* const ppumn);
  283. #endif
  284.  
  285.  
  286. protected:
  287. /*----------------------------- IMPLEMENTATION ---------------------------------
  288. | The following functions are used in the implementation of the class:         |
  289. |   setEmphasis       - Set the passed emphasis attribute on or off.           |
  290. |   setAttributes     - Set some attributes off while setting others on. Used  |
  291. |                       to toggle the state of mutually exclusive attributes.  |
  292. |   incrementUseCount - Increase the count of containers with this object.     |
  293. |   decrementUseCount - Decrease the count of containers with this object.     |
  294. |   setBase           - Store the address of the real base of this object.     |
  295. |   baseRecord        - Return the address of the real base of this object.    |
  296. |   useCount          - Returns the number of containers with this object.     |
  297. |   isAttribute       - Returns true if the passed attribute is on.            |
  298. ------------------------------------------------------------------------------*/
  299. virtual void
  300.   setEmphasis( unsigned long ulEmphasisAttribute,
  301.                Boolean fOn=true),
  302.   setAttributes( unsigned long flAttrOff,
  303.                  unsigned long flAttrOn),
  304.   incrementUseCount() const,
  305.   decrementUseCount() const,
  306.   setBase( const IMiniCnrRecord* pcnrrec);
  307.  
  308. IMiniCnrRecord
  309.  *baseRecord();
  310.  
  311. virtual unsigned long
  312.   useCount() const;
  313.  
  314. virtual Boolean
  315.   isAttribute(unsigned long flAttribute) const;
  316.  
  317. private:
  318. /*--------------------------------- PRIVATE ----------------------------------*/
  319. IContainerObject() {;}
  320.  
  321. unsigned long 
  322.   iconTextLength() const;
  323.  
  324. int  
  325.   flClState;
  326. unsigned long  
  327.   ulClUseCount;
  328. IContainerObject
  329.  *pcnrobjClParent;
  330. IMiniCnrRecord
  331.  *pbase;
  332. /* IPopUpMenu* ppumnCl; */
  333. } ;
  334.  
  335. /*----------------------------------------------------------*/
  336. /* Object Collection Definition.                            */
  337. /*----------------------------------------------------------*/
  338. #ifdef _USEBB_
  339.    class ICnrObjectSet : public ISortedSet<IContainerObject*>
  340.    {
  341.    public:
  342.          ICnrObjectSet()   : ISortedSet<IContainerObject*>() {}
  343.  
  344.    };
  345. #else
  346.    declare(IGSet1,       IContainerObject);
  347.    
  348.    class ICnrObjectSet : public IGSet1(IContainerObject)
  349.    {
  350.    public:
  351.          ICnrObjectSet()   : IGSet1(IContainerObject)() {}    // RDL 32 bit
  352.    };
  353.    
  354. #endif
  355.  
  356. /*----------------------------------------------------------*/
  357. /*               Inline Functions                           */
  358. /*----------------------------------------------------------*/
  359.  
  360.  
  361. // inline Boolean IContainerObject :: isDropAcceptable(const ICnrDragOverEvent& evt)
  362. //    { return(false); };
  363.  
  364.  
  365.  
  366.  
  367.  
  368. inline void IContainerObject ::  incrementUseCount() const
  369.     { ((IContainerObject*)this)->ulClUseCount++; }
  370. inline void IContainerObject ::  decrementUseCount() const
  371.     { ((IContainerObject*)this)->ulClUseCount--;  }
  372. inline unsigned long IContainerObject ::  useCount() const
  373.     { return((IContainerObject*)this)->ulClUseCount; }
  374. inline IMiniCnrRecord* IContainerObject ::  baseRecord()
  375.     { return((IContainerObject*)this)->pbase; }
  376. inline void IContainerObject :: setBase( const IMiniCnrRecord* pcnrrec)
  377.     { this->pbase = (IMiniCnrRecord*)pcnrrec; }
  378.  
  379.  
  380. inline IContainerObject& IContainerObject :: setRefreshOff()
  381.     { flClState |=  noRefresh; return *this;}
  382. inline IContainerObject& IContainerObject :: setRefreshOn()
  383.     { flClState &= ~noRefresh; return *this;}
  384. inline Boolean IContainerObject :: isRefreshOn() const
  385.     { return !(flClState&noRefresh); }
  386.  
  387. inline IContainerObject& IContainerObject ::setOpen()
  388.   { flClState |= opened; setInUse();  return *this; }
  389. inline IContainerObject& IContainerObject ::setClose()
  390.   { flClState &= ~opened; removeInUse();  return *this; }
  391. inline void IContainerObject :: handleOpen(IContainerControl* pcnrctl)
  392.   { setOpen(); }
  393. inline Boolean IContainerObject :: isOpen()
  394.   { return isInUse(); }
  395.  
  396.  
  397. #endif  // _ICNROBJ_
  398.