home *** CD-ROM | disk | FTP | other *** search
/ Power GUI Programming with VisualAge C++ / powergui.iso / powergui / extlib / valueset / valueset.hpp < prev    next >
Encoding:
C/C++ Source or Header  |  1996-10-29  |  15.1 KB  |  405 lines

  1. #ifndef _VALUESET_
  2. #define _VALUESET_
  3. //************************************************************
  4. // Extending the Library - Value Set Example
  5. //
  6. // Copyright (C) 1994, Law, Leong, Love, Olson, Tsuji.
  7. // All Rights Reserved.
  8. //************************************************************
  9.  
  10. #ifndef _ICONTROL_
  11.   #include <icontrol.hpp>
  12. #endif
  13.  
  14. #ifndef _ISTRING_
  15.   #include <istring.hpp>
  16. #endif
  17.  
  18. #ifndef _IRECT_
  19.   #include <irect.hpp>
  20. #endif
  21.  
  22. #ifndef _ICOLOR_
  23.   #include <icolor.hpp>
  24. #endif
  25.  
  26. class IResourceId;
  27.  
  28.  
  29. class ValueSet : public IControl {
  30. typedef IControl
  31.   Inherited;
  32. public:
  33. class Style;
  34. /*------------------------------- Constructors ---------------------------------
  35. | Constructors provide for creating ValueSets:                                 |
  36. |   o from a specification of the value set attibutes, including the           |
  37. |     "dimensions" (number of rows and columns);                               |
  38. |   o from a parent window and id of a value set child control,                |
  39. |     this constructor is used to wrapper a control on a dialog loaded         |
  40. |     from a dialog template;                                                  |
  41. |   o from the window handle of a previously created WC_VALUESET window.       |
  42. ------------------------------------------------------------------------------*/
  43.   ValueSet ( unsigned long        id,
  44.              IWindow             *parent,
  45.              IWindow             *owner,
  46.              const ISize         &dimensions,
  47.              const IRectangle    &sizeAndPosition = IRectangle(),
  48.              const Style         &style = defaultStyle() );
  49.   ValueSet ( unsigned long        id,
  50.              IWindow             *parent,
  51.              IWindow             *owner,
  52.              const IRectangle    &sizeAndPosition = IRectangle(),
  53.              const Style         &style = defaultStyle() );
  54.   ValueSet ( IWindow             *parent,
  55.              unsigned long        id );
  56.   ValueSet ( const IWindowHandle &hwnd );
  57. virtual
  58.   ~ValueSet ();
  59.  
  60. /*---------------------------------- Style -------------------------------------
  61. | Style - Nested class defining the type of the value set style flags.         |
  62. |         These style values can be mixed with IControl::Style and             |
  63. |         IWindow::Style values.                                               |
  64. ------------------------------------------------------------------------------*/
  65. INESTEDBITFLAGCLASSDEF2( Style, ValueSet, IWindow, IControl);
  66.  
  67. static const Style
  68.   border,
  69.   itemBorder,
  70.   rightToLeft,
  71.   scaleBitmaps,
  72.   drawItem,
  73.   classDefaultStyle;
  74.  
  75. /*------------------------- Style Get/Set Functions ----------------------------
  76. | These functions let you query or set the various style attributes.  Note     |
  77. | that the "right to left" style can only be set at creation time.             |
  78. ------------------------------------------------------------------------------*/
  79. static Style
  80.    defaultStyle();
  81. static void
  82.    setDefaultStyle( const Style &style );
  83.  
  84. Boolean
  85.   hasBorder        ( ) const,
  86.   hasItemBorder    ( ) const,
  87.   isRightToLeft    ( ) const,
  88.   willScaleBitmaps ( ) const,
  89.   isDrawItem       ( ) const;
  90.                           
  91. virtual ValueSet
  92.  &enableBorder         ( Boolean flag = true ),
  93.  &disableBorder        ( ),
  94.  &enableItemBorder     ( Boolean flag = true ),
  95.  &disableItemBorder    ( ),
  96.  &enableBitmapScaling  ( Boolean flag = true ),
  97.  &disableBitmapScaling ( ),
  98.  &enableDrawItem       ( Boolean flag = true ),
  99.  &disableDrawItem      ( );
  100.  
  101. /*-------------------------------- Dimensions ----------------------------------
  102. | Use these functions to query or set the value set dimensions (number of      |
  103. | rows and number of columns).                                                 |
  104. ------------------------------------------------------------------------------*/
  105. virtual ISize
  106.   dimensions ( ) const;
  107.  
  108. virtual unsigned long
  109.   numberOfRows    ( ) const,
  110.   numberOfColumns ( ) const;
  111.  
  112. virtual ValueSet
  113.  &setDimensions      ( const ISize &dimensions ),
  114.  &setNumberOfRows    ( unsigned long rows ),
  115.  &setNumberOfColumns ( unsigned long columns );
  116.  
  117. /*---------------------------- ItemStyle/ItemType ------------------------------
  118. | The ItemStyle nested class defines the type of values used to represent      |
  119. | the style of specific value set items.                                       |
  120. |                                                                              |
  121. | The ItemType enumeration provides an argument to distinguish the type        |
  122. | of resource identified by an IResourceId on various ValueSet and             |
  123. | ValueSet::Item functions.                                                    |
  124. ------------------------------------------------------------------------------*/
  125. INESTEDBITFLAGCLASSDEF0( ItemStyle, ValueSet );
  126.  
  127. static const ItemStyle
  128.   noItemStyle,
  129.   disabled,
  130.   dragSource,
  131.   dropTarget,
  132.   itemOwnerDraw;
  133.  
  134. enum ItemType
  135.   {
  136.   bitmapItem,
  137.   iconItem,
  138.   textItem
  139.   };
  140.  
  141. class Item {
  142. /*******************************************************************************
  143. * Objects of the ValueSet::Item class represent the individual items that      *
  144. * are contained in a ValueSet.  You can get and set these items and the        *
  145. * attributes of these items using various ValueSet functions (see below).      *
  146. *******************************************************************************/
  147. public:
  148. /*------------------------------- Constructors ---------------------------------
  149. | There are 5 kinds of Items:                                                  |
  150. |   o empty (default constructor)                                              |
  151. |   o a bitmap (constructed from a bitmap handle or bitmap resource).          |
  152. |   o an icon (constructed from a pointer handle or pointer resource).         |
  153. |   o text (constructed from a char* pointer or string resource).              |
  154. |   o a color (constructed from an IColor)                                     |
  155. | Each constructor also accepts an optional ItemStyle argument.  If not        |
  156. | specified, the item style defaults to ValueSet::Item::defaultStyle().        |
  157. |                                                                              |
  158. | This class also provides a copy constructor.                                 |
  159. ------------------------------------------------------------------------------*/
  160.   Item ( );
  161.   Item ( const IResourceId    &resId,
  162.          ItemType              type,
  163.          const ItemStyle      &style );
  164.   Item ( const IBitmapHandle  &bmp,
  165.          const ItemStyle      &style = Item::defaultStyle() );
  166.   Item ( const IPointerHandle &ptr,
  167.          const ItemStyle      &style = Item::defaultStyle() );
  168.   Item ( const IString        &text,
  169.          const ItemStyle      &style = Item::defaultStyle() );
  170.   Item ( const IColor         &color,
  171.          const ItemStyle      &style = Item::defaultStyle() );
  172.   Item ( const Item           &item );
  173.   ~Item ( );
  174.  
  175. /*---------------------------------- Style -------------------------------------
  176. | You can use these functions to query or change the style of an item:         |
  177. |   style        - Returns the item's style                                    |
  178. |   setStyle     - Sets the item's style                                       |
  179. |   defaultStyle - Returns the default item style.                             |
  180. |   setDefaultStyle - Sets the default style.                                  |
  181. |   isDisabled      - Returns true if the item is disabled.                    |
  182. |   isEnabled       - Returns true if the item is enabled.                     |
  183. |   canBeDragged    - Returns true if the item has the dragSource style.       |
  184. |   canBeDroppedOn  - Returns true if the item has the dropTarget style.       |
  185. |   isOwnerDraw     - Returns true if the item has the ownerDraw style.        |
  186. |   enable          - Turns the disable style off (or on).                     |
  187. |   disable         - Turns the disable style on.                              |
  188. |   enableDrag  - Turns on (or off) the dragSource style.                      |
  189. |   disableDrag - Turns off the dragSource style.                              |
  190. |   enableDrop  - Turns on (or off) the dropTarget style.                      |
  191. |   disableDrop - Turns off the dropTarget style.                              |
  192. |   setOwnerDraw - Turns on (or off) the ownerDraw style.                      |
  193. ------------------------------------------------------------------------------*/
  194. ItemStyle
  195.   style ( ) const;
  196.  
  197. Item
  198.  &setStyle ( const ItemStyle &style );
  199.  
  200. static ItemStyle
  201.   defaultStyle ( );
  202.  
  203. static void
  204.   setDefaultStyle ( const ItemStyle &style );
  205.  
  206. Boolean
  207.   isDisabled ( ) const,
  208.   isEnabled ( ) const,
  209.   canBeDragged ( ) const,
  210.   canBeDroppedOn ( ) const,
  211.   isOwnerDraw ( ) const;
  212.  
  213. Item
  214.  &enable ( Boolean enable = true ),
  215.  &disable ( ),
  216.  &enableDrag ( Boolean enable = true ),
  217.  &disableDrag ( ),
  218.  &enableDrop ( Boolean enable = true ),
  219.  &disableDrop ( ),
  220.  &setOwnerDraw ( Boolean setting = true );
  221.  
  222. /*--------------------------------- Contents -----------------------------------
  223. | You call these functions to query the type of the item contents and the      |
  224. | item contents themselves.  If the item doesn't have the corresponding type   |
  225. | then the content query function will return 0 (or its equivalent).           |
  226. |   isEmpty        - Returns true if the item is empty.                        |
  227. |   containsBitmap - Returns true if the item contains a bitmap.               |
  228. |   containsIcon   - Returns true if the item contains an icon.                |
  229. |   containsText   - Returns true if the item contains text.                   |
  230. |   containsColor  - Returns true if the item contains a color.                |
  231. |   bitmap         - Returns the item's bitmap handle (0 if not a bitmap).     |
  232. |   icon           - Returns the item's pointer handle (0 if not an icon).     |
  233. |   text           - Returns the item's text (a null string if not a text      |
  234. |                    item).  Note that the item's text might also be null.     |
  235. |   color          - Returns the item's color (0 if not a color).              |
  236. ------------------------------------------------------------------------------*/
  237. Boolean
  238.   isEmpty ( ) const,
  239.   containsBitmap ( ) const,
  240.   containsIcon   ( ) const,
  241.   containsText   ( ) const,
  242.   containsColor  ( ) const;
  243.  
  244. IBitmapHandle
  245.   bitmap ( ) const;
  246.  
  247. IPointerHandle
  248.   icon ( ) const;
  249.  
  250. IString
  251.   text ( ) const;
  252.  
  253. IColor
  254.   color ( ) const;
  255.  
  256. private:
  257. enum Type { emptyItem, bitmapItem, iconItem, textItem, colorItem };
  258. Type
  259.   itemType;
  260. IBitmapHandle
  261.   itemBmpHandle;
  262. IPointerHandle
  263.   itemPtrHandle;
  264. IColor
  265.   itemColor;
  266. IString
  267.   itemText;
  268. ItemStyle
  269.   itemStyle;
  270. static ItemStyle
  271.   dfltStyle;
  272. friend class ValueSet;
  273. }; // class ValueSet::Item
  274.  
  275. /*------------------------------- Item Get/Set ---------------------------------
  276. | You use these functions to query or modify the individual items contained    |
  277. | by the value set.                                                            |
  278. ------------------------------------------------------------------------------*/
  279. Item
  280.   item ( unsigned long row, 
  281.          unsigned long column ) const;
  282.  
  283. ValueSet
  284.  &setItem ( unsigned long  row,
  285.             unsigned long  column,
  286.             const Item    &item ),
  287.  
  288.  &setItemContents ( unsigned long         row,
  289.                     unsigned long         column,
  290.                     const IResourceId    &resId,
  291.                     ItemType              type ),
  292.  &setItemContents ( unsigned long         row,
  293.                     unsigned long         column,
  294.                     const IBitmapHandle  &bmp ),
  295.  &setItemContents ( unsigned long         row,
  296.                     unsigned long         column,
  297.                     const IPointerHandle &icon ),
  298.  &setItemContents ( unsigned long         row,
  299.                     unsigned long         column,
  300.                     const IString        &text ),
  301.  &setItemContents ( unsigned long         row,
  302.                     unsigned long         column,
  303.                     const IColor         &color ),
  304.  
  305.  &setItemStyle ( unsigned long            row,
  306.                  unsigned long            column,
  307.                  const ItemStyle         &style );
  308.  
  309. /*-------------------------------- Selection -----------------------------------
  310. | You use these functions to query or set the selected item in the value set.  |
  311. ------------------------------------------------------------------------------*/
  312. Boolean
  313.   hasSelection ( ) const;
  314.  
  315. ValueSet
  316.  &setSelection ( unsigned row, unsigned column );
  317.  
  318. Item
  319.   selectedItem ( ) const;
  320.  
  321. IPoint
  322.   selection ( ) const;
  323.  
  324. unsigned long
  325.   selectedRow    ( ) const,
  326.   selectedColumn ( ) const;
  327.  
  328. /*-------------------------- Item Size and Spacing -----------------------------
  329. | You can call these functions to query or set the value set's item size       |
  330. | or item spacing.                                                             |
  331. ------------------------------------------------------------------------------*/
  332. ISize
  333.   itemSize    ( ) const,
  334.   itemSpacing ( ) const;
  335.  
  336. ValueSet
  337.  &setItemSize    ( const ISize &size ),
  338.  &setItemSpacing ( const ISize &size );
  339.  
  340. /*---------------------------------- Colors ------------------------------------
  341. | You use these functions to query and set the colors that the value set       |
  342. | uses.                                                                        |
  343. ------------------------------------------------------------------------------*/
  344. enum ColorArea
  345.   {
  346.   borders,
  347.   foreground,
  348.   background,
  349.   highlightBackground
  350.   };
  351.  
  352. IColor
  353.   color ( ColorArea area ) const;
  354.  
  355. ValueSet
  356.  &setColor ( ColorArea     area,
  357.              const IColor &color );
  358.  
  359. protected:
  360. /*------------------------------ Implementation --------------------------------
  361. | These functions provide services used to implement this class.               |
  362. ------------------------------------------------------------------------------*/
  363. void 
  364.   initialize ( const IWindowHandle &hwnd ),
  365.   initialize ( const ISize         &size,
  366.                unsigned long        id,
  367.                IWindow             *parent,
  368.                IWindow             *owner,
  369.                const IRectangle    &initial,
  370.                const Style         &style ),
  371.  
  372.   setItemAttributes ( unsigned long row,
  373.                       unsigned long column,
  374.                       const IEventParameter2 &attr ),
  375.  
  376.   setItem ( unsigned long row,
  377.             unsigned long column,
  378.             const IEventParameter2 &contents ),
  379.  
  380.   setMetrics ( const IEventParameter1 &mp1,
  381.                const ISize            &size );
  382.  
  383. static IString
  384.   controlData ( const ISize &size );
  385.  
  386. unsigned long
  387.   itemHandle ( unsigned long row,
  388.                unsigned long column ) const;
  389.  
  390. ISize
  391.   metrics         ( const IEventParameter1 &mp1 ) const,
  392.   calcMinimumSize ( ) const;
  393.  
  394. private:
  395. static Style
  396.   dfltStyle;
  397. ValueSet (const ValueSet&);
  398. ValueSet& operator= (const ValueSet&);
  399. }; // class ValueSet
  400.  
  401.  
  402. INESTEDBITFLAGCLASSFUNCS( Style, ValueSet );
  403.  
  404. #endif // _VALUESET_
  405.