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

  1. #ifndef _LBOXITEM_
  2. #define _LBOXITEM_
  3. //************************************************************
  4. // Direct Manipulation - List Box Example
  5. //
  6. // Copyright (C) 1994, Law, Leong, Love, Olson, Tsuji.
  7. // Copyright (c) 1997 John Wiley & Sons, Inc. 
  8. // All Rights Reserved.
  9. //************************************************************
  10.  
  11. #include <idmitem.hpp>
  12. #include <idmprov.hpp>
  13.  
  14. class IListBox;
  15. class IDMSourceOperation;
  16. class IDMSourceDiscardEvent;
  17. class IDMTargetDropEvent;
  18. class IDMTargetEvent;
  19. class IPoint;
  20.  
  21. class ListBoxItem : public IDMItem {
  22. typedef IDMItem
  23.   Inherited;
  24. /*******************************************************************************
  25. * Objects of this class represent items being dragged from or dropped on       *
  26. * a listbox during direct manipulation (drag/drop).                            *
  27. *******************************************************************************/
  28. public:
  29. /*------------------------- Constructors/Destructor ----------------------------
  30. | This class provides two constructors:                                        |
  31. |   o One that gets called to construct items being dragged from a             |
  32. |     list box.                                                                |
  33. |   o One that gets called to construct items when the user drags              |
  34. |     something over a list box.                                               |
  35. |                                                                              |
  36. | The static function generateSourceItems is called by the template class      |
  37. | IDMItemProviderFor<ListBoxItem>; it invokes the source constructor.          |
  38. ------------------------------------------------------------------------------*/
  39.   ListBoxItem ( IDMSourceOperation*    srcOp,
  40.                 IListBox*              srcLB,
  41.                 unsigned               index );
  42.   ListBoxItem ( const IDMItem::Handle& dragItem );
  43.  
  44. virtual
  45.   ~ListBoxItem ( );
  46.  
  47. static Boolean
  48.   generateSourceItems( IDMSourceOperation* srcOp );
  49.  
  50. /*------------------------------ Implementation --------------------------------
  51. | These functions provide utilities used to implement this class:              |
  52. |   LocType                - Enumeration of location types (before, on, after) |
  53. |   TgtLocation            - Nested class representing a drop location.        |
  54. |   sourceIndex            - Returns index of item at source drag position.    |
  55. |   itemHeight             - Returns height of items in the listbox.           |
  56. |   horizontalScrollHeight - Returns height of the horizontal scroll bar.      |
  57. |   verticalScrollWidth    - Returns width of the vertical scroll bar.         |
  58. |   targetLocation         - Returns TgtLocation at dragover/drop point.       |
  59. ------------------------------------------------------------------------------*/
  60. enum LocType
  61.   {
  62.   before,
  63.   on,
  64.   after
  65.   };
  66.  
  67. struct TgtLocation {
  68.   TgtLocation ( LocType type, unsigned index );
  69. Boolean
  70.   operator == ( const TgtLocation& loc ) const;
  71. LocType
  72.   type;
  73. unsigned
  74.   index;
  75. };
  76.  
  77. static TgtLocation
  78.   targetLocation ( IListBox* pLB, const IPoint& pt );
  79.  
  80. static unsigned
  81.   sourceIndex            ( IListBox* pLB, const IPoint& pt ),
  82.   itemHeight             ( IListBox* pLB ),
  83. #ifdef IC_WIN
  84.   horizontalScrollHeight ( ),
  85. #endif
  86.   verticalScrollWidth    ( IListBox* pLB );
  87.  
  88. /*-------------------------------- Overrides -----------------------------------
  89. | These functions are overridden in this class to tailor drag/drop for         |
  90. | the list box:                                                                |
  91. |   targetDrop    - Handles dropping on the list box.                          |
  92. |   sourceEnd     - Handles completion of operation (deletion if move).        |
  93. |   sourceDiscard - Handles dropping on the shredder (OS/2 only).              |
  94. ------------------------------------------------------------------------------*/
  95. virtual Boolean
  96.   sourceEnd     ( IDMSourceEndEvent&     event ),
  97. #ifdef IC_PM
  98.   sourceDiscard ( IDMSourceDiscardEvent& event ),
  99. #endif
  100.   targetDrop    ( IDMTargetDropEvent&    event );
  101.  
  102. }; // class ListBoxItem
  103.  
  104. class ListBoxItemProvider : public IDMItemProviderFor<ListBoxItem> {
  105. typedef IDMItemProviderFor<ListBoxItem>
  106.   Inherited;
  107. /*******************************************************************************
  108. * Objects of this class are attached to listboxes in order to provide          *
  109. * drag/drop support (using ListBoxItems).                                      *
  110. *******************************************************************************/
  111. public:
  112. /*------------------------- Constructors/Destructor ----------------------------
  113. | The constructor takes an optional list box (which will autoamtically         |
  114. | be attached to).                                                             |
  115. ------------------------------------------------------------------------------*/
  116.   ListBoxItemProvider ( IListBox* listBox = 0 );
  117.  
  118. /*-------------------------------- Attaching -----------------------------------
  119. | This function ensures we attach only to listbox controls.                    |
  120. ------------------------------------------------------------------------------*/
  121. virtual ListBoxItemProvider
  122.  &provideItemsFor( IListBox* listBox );
  123.  
  124. /*----------------------------- Target Emphasis --------------------------------
  125. | drawEmphasis - Draws target emphasis.                                        |
  126. ------------------------------------------------------------------------------*/
  127. virtual ListBoxItemProvider
  128.  &drawEmphasis ( IListBox*                       listBox,
  129.                  IDMTargetEvent&                 event,
  130.                  const ListBoxItem::TgtLocation& target );
  131.  
  132. /*-------------------------------- Overrides -----------------------------------
  133. | This class overrides these functions:                                        |
  134. |   provideLeaveSupport  - Removes target emphasis.                            |
  135. |   provideEnterSupport  - Draws target emphasis and checks operation.         |
  136. ------------------------------------------------------------------------------*/
  137. virtual Boolean
  138.   provideLeaveSupport( IDMTargetLeaveEvent& event ),
  139.   provideEnterSupport( IDMTargetEnterEvent& event );
  140.  
  141. private:
  142. // Make operator private to prevent attaching to wrong control.
  143. ListBoxItemProvider
  144.  *operator & ();
  145. };
  146.  
  147. #endif // _LBOXITEM_
  148.