home *** CD-ROM | disk | FTP | other *** search
/ OS/2 Professional Developers Kit 1992 November / Disc01 / Disc01.mdf / cppbeta / ibmcli / idrgitm.hp_ / IDRGITM.HPP
Encoding:
C/C++ Source or Header  |  1992-10-26  |  14.4 KB  |  360 lines

  1. #ifndef _IDRGITM_
  2.   #define _IDRGITM_
  3. /*--------------------------------------------------------------*/
  4. /* CLASSES NAMES: IDragItem                                     */
  5. /*                ITextDragItem                                 */
  6. /*                IObjectDragItem                               */
  7. /*                IFileDragItem                                 */
  8. /*                                                              */
  9. /* DESCRIPTION  :                                               */
  10. /*                                                              */
  11. /*                                                              */
  12. /* CHANGE ACTIVITY:                                             */
  13. /* ---------------                                              */
  14. /*   DATE:     INITIAL:       DESCRIPTION:                      */
  15. /*                                                              */
  16. /* 03/01/91    KKL            Design & architecture             */
  17. /* 05/30/91    PHG            Original Implementation           */
  18. /* 11/19/91    DH             Start Re-design                   */
  19. /* 12/23/91    RDL            Complete Re-design and implement  */
  20. /* 08/13/92    PHG            Modified for Giverny              */
  21. /*--------------------------------------------------------------*/
  22. /* Copyright (c) IBM Corporation 1991                           */
  23. /*--------------------------------------------------------------*/
  24.  
  25. // forward class references
  26. class IDragSourceHandler;
  27. class IBeginDragEvent;
  28.  
  29.  
  30. // include library's common stuff
  31. #ifndef _IBASETYP_
  32.   #include <ibasetyp.hpp>
  33. #endif
  34.  
  35. #ifndef _ISTRING_
  36.   #include <istring.hpp>
  37. #endif
  38.  
  39. #ifndef _IPOINT_
  40.   #include <ipoint.hpp>
  41. #endif
  42.  
  43. #ifndef _IRESLIB_
  44.   #include <ireslib.hpp>
  45. #endif
  46.  
  47. #ifndef _IWINDOW_
  48.   #include <iwindow.hpp>
  49. #endif
  50.  
  51. // include our own stuff
  52. #ifndef _IDRGSTYL_
  53.   #include <idrgstyl.hpp>
  54. #endif
  55. #ifndef _IDRGEVT_
  56.   #include <idrgevt.hpp>
  57. #endif
  58. #ifndef _IDRGIMG_
  59.   #include <idrgimg.hpp>
  60. #endif
  61. #ifndef _IDRGSTR_
  62.   #include <idrgstr.hpp>
  63. #endif
  64.  
  65. class IDragItem  : public IVBase {
  66. /**************************************************************************
  67. *  This is an encapsulation of a PM DRAGITEM structure                    *
  68. *                                                                         *
  69. *  It can be constructed either:                                          *
  70. *   - from C++ objects (IStrings and such), when used from                *
  71. *     the source (drag) side.                                             *
  72. *   - from a PM PDRAGITEM passed in a IDragOperation event,               *
  73. *     for instanciation from the target (drop) side                       *
  74. *  HUngarian is 'drgitm'                                                  *
  75. **************************************************************************/
  76. public:
  77.  
  78. INESTEDBITFLAGCLASSDEF0(SupportedOps,IDragItem);
  79. static const SupportedOps
  80.   nosupop,
  81.   copyable,
  82.   moveable,
  83.   linkable;
  84.  
  85. INESTEDBITFLAGCLASSDEF0(Control,IDragItem);
  86. static const Control
  87.   nocontrol,
  88.   open,
  89.   ref,
  90.   group,
  91.   container,
  92.   prepare,
  93.   removeablemedia;
  94.  
  95. /*-------------------- FLAGS & HELPER FUNCTIONS --------------------------+
  96. | These are the declaration of nested flags classes and their tester      |
  97. | helper functions                                                        |
  98. |  SupportedOps - Emulate the PM item supported operations flags          |
  99. |    isCopyable - Test if item is copyable                                |
  100. |    isMoveable - Test if item is moveable                                |
  101. |    isLinkable - Test if item is linkable                                |
  102. |  Control - Emulate the PM source control flags                          |
  103. |    isOpen            - Test if item is opened                           |
  104. |    isReference       - Test if item is a reference                      |
  105. |    isGroup           - Test if item represents a group of objects       |
  106. |    isContainer       - Test if item is a container                      |
  107. |    requiresDMPrepare - Test if item requires a renderprepare message    |
  108. |    isRemovableMedia  - Test if item represents a removeable media       |
  109. +------------------------------------------------------------------------*/
  110. Boolean
  111.   isCopyable() const,
  112.   isMoveable() const,
  113.   isLinkable() const;
  114.  
  115. Boolean
  116.   isOpen() const,
  117.   isReference() const,
  118.   isGroup() const,
  119.   isContainer() const,
  120.   requiresDMPrepare() const,
  121.   isRemovableMedia() const;
  122.  
  123. /*------------------------ CONSTRUCTORS/DESTRUCTORS ----------------------+
  124. | There are 3 ways to construct instances of this class:                  |
  125. |  1. Construction from scratch specifying drag items's characteristics   |
  126. |  2. Instantiation from a IDragOperation event's dragged items list      |
  127. |  3. Instantiation from a PDRAGITEM pointer                              |
  128. +------------------------------------------------------------------------*/
  129.   IDragItem(IWindow* pwndItem,
  130.             unsigned long ulItemId,
  131.             const ITypesString& strTypes,
  132.             const IRMFsString& strRMFs,
  133.             const SupportedOps& drgsupops,
  134.             const Control& drgctrl=nocontrol);
  135.  
  136.   IDragItem(const IDragOperationEvent& drgopevt,
  137.             unsigned long ulItem);
  138.  
  139.   IDragItem(void* pdragitem);
  140.  
  141. virtual
  142.   ~IDragItem();
  143.  
  144. /*-------------------------------- ACCESSORS -----------------------------+
  145. | These function provide means of getting and setting the accessible      |
  146. | attributes of instances of this class:                                  |
  147. |  id    - retunrs the item ID                                            |
  148. |  setId - sets the item ID                                               |
  149. |  window - returns the item's IWindow pointer if any                     |
  150. |  windowHandle - returns the window handle                               |
  151. |  setWindow - set the IWindow pointer (and handle, as side effect)       |
  152. |  types - return the types supported by the item                         |
  153. |  setTypes - set the types supported by the item                         |
  154. |  RMFs - return the RMFs supported by the item                           |
  155. |  setRMFs - set the RMFs supported by the item                           |
  156. |  containerName - return the container name for item                     |
  157. |  setContainerName - set the container name for item                     |
  158. |  sourceName - return the source name for item                           |
  159. |  setSourceName - set the source name for item                           |
  160. |  targetName - return the target name for item                           |
  161. |  setTargetName - set the target name for item                           |
  162. |  dragImage - return the IDragImage pointer for item, or 0 if none       |
  163. |  setDragImage - set or remove the item's IDragImage pointer             |
  164. |  dragControl - return the control flags for item                        |
  165. |  setDragControl - set the control flags for item                        |
  166. |  dragSupOps - return the operations supported by item                   |
  167. |  setDragSupOps - set the operations supported by item                   |
  168. |  origin - return the item's origin offset from mouse hotspot            |
  169. |  setOrigin - set the item's origin offset from mouse hotspot            |
  170. +------------------------------------------------------------------------*/
  171. unsigned long
  172.   id() const;
  173. IDragItem
  174.   &setId(unsigned long ulId);
  175. const IWindow*
  176.   window() const;
  177. IWindowHandle
  178.   windowHandle() const;
  179. IDragItem
  180.   &setWindow(IWindow* pwndItem);
  181. ITypesString
  182.   types() const;
  183. IDragItem
  184.   &setTypes(const ITypesString& strTypes);
  185. IRMFsString
  186.   RMFs() const;
  187. IDragItem
  188.   &setRMFs(const IRMFsString& strRMFs);
  189. IString
  190.   containerName() const;
  191. IDragItem
  192.   &setContainerName(const char* pszContainerName);
  193. IString
  194.   sourceName() const;
  195. IDragItem
  196.   &setSourceName(const char* pszSourceName);
  197. IString
  198.   targetName() const;
  199. IDragItem
  200.   &setTargetName(const char* pszTargetName);
  201. IDragImage*
  202.   dragImage() const;
  203. IDragItem
  204.   &setDragImage(IDragImage* pdrgimg, Boolean bAutoDelete=true);
  205. Control
  206.   dragControl() const;
  207. IDragItem
  208.   &setDragControl(Control& drgctrl);
  209. SupportedOps
  210.   dragSupOps() const;
  211. IDragItem
  212.   &setDragSupOps(SupportedOps& drgsupops);
  213. ISize
  214.   origin() const;
  215. IDragItem
  216.   &setOrigin(const ISize& sizOrigin);
  217.  
  218.  
  219. /*-------------------------------- OPERATORS -----------------------------+
  220. | Operators defined on DragItems                                          |
  221. |   operator== required for sets                                          |
  222. +------------------------------------------------------------------------*/
  223. Boolean
  224.   operator==(IDragItem& drgit);
  225.  
  226. /*-------------------------------- UTILITY -------------------------------+
  227. | Utility functions to access and handle PM-specific data                 |
  228. |  dragitemPtr        - returns the external PDRAGITEM pointer if exists  |
  229. |  dragitemStruct     - fills-in a dragitem structure with item's data    |
  230. |  dragitemPtrInvalid - sets the DragItemPtr to 0 when freed from outside |
  231. +------------------------------------------------------------------------*/
  232. void*
  233.   dragitemPtr() const;
  234. void
  235.   dragitemStruct(void* pdragitem, unsigned long ulSize) const;
  236. Boolean
  237.   dragitemPtrInvalid(void* pdragitem);
  238.  
  239.  
  240. /*-------------------------------- CALLBACKS -----------------------------+
  241. | These functions are intended to be overridden by the user to implement  |
  242. | his own specific behavior                                               |
  243. |  setupForDrag - Called on an item so that it can be set to be dragged   |
  244. |  render       - Called on an item for it to render itself               |
  245. |  conversationEnded - Called when conversation for this item has ended   |
  246. +------------------------------------------------------------------------*/
  247. virtual Boolean
  248.   setupForDrag(const IBeginDragEvent& begdrgevt) { return(false); };
  249.  
  250. virtual Boolean
  251.   render(const IDragSourceHandler* pdrgsrch,
  252.          IRenderEvent& rendevt);
  253.  
  254. virtual Boolean
  255.   conversationEnded(const IDragSourceHandler* pdrgsrch,
  256.                     const IEndConversationEvent& endcvevt);
  257.  
  258. /*-------------------------------- UTILITY -------------------------------+
  259. | Utility functions to convert to/from string handles                     |
  260. |  handleFromString - create a string handle from an IString              |
  261. |  stringFromHandle - returns the string represented by a string handle   |
  262. +------------------------------------------------------------------------*/
  263. IStringHandle
  264.   handleFromString(const char* pszIn) const;
  265. IString
  266.   stringFromHandle(IStringHandle strhIn) const;
  267.  
  268. private:
  269. /*------------------------------ DATA MEMBERS ----------------------------+
  270. | These are instance variables for the item                               |
  271. |  pdragitemCl - set when constructed from an outside pointer             |
  272. |  pwndClItem  - item's IWindow*, 0 if constructed from an outside pointer|
  273. |  wndhClItem  - item's window handle                                     |
  274. |  ulClItemId  - item's ID                                                |
  275. |  sizClOrigin - item's position from mouse hotspot                       |
  276. |  drgctrlCl   - drag control flags                                       |
  277. |  drgsupopsCl - supported operations flags                               |
  278. |  pdrgimageCl - item's drag image, 0 if none                             |
  279. |  bClAutoDelImage - autodelete image pointer if set                      |
  280. |  strClTypes         - Item's types          !                           |
  281. |  strClRMFs          - Item's supported RMFs ! These are not set         |
  282. |  strClContainerName - Item's container name ! if constructed from       |
  283. |  strClSourceName    - Item's source name    ! an outside pointer        |
  284. |  strClTargetName    - Item's target name    !                           |
  285. +------------------------------------------------------------------------*/
  286. void*             pdragitemCl;
  287. IWindow*          pwndClItem;
  288.  
  289. IWindowHandle     wndhClItem;
  290. unsigned long     ulClItemId;
  291. ISize             sizClOrigin;
  292. Control           drgctrlCl;
  293. SupportedOps      drgsupopsCl;
  294. IDragImage*       pdrgimageCl;
  295. Boolean           bClAutoDelImage;
  296.  
  297. ITypesString      strClTypes;
  298. IRMFsString       strClRMFs;
  299. IString           strClContainerName;
  300. IString           strClSourceName;
  301. IString           strClTargetName;
  302.  
  303. }; // IDragItem
  304.  
  305. /*=========================================================================
  306. | Inlines for IDragItem                                         PHG 21/10 |
  307. =========================================================================*/
  308. inline IDragItem::Control IDragItem :: dragControl() const
  309. { return drgctrlCl; }
  310.  
  311. inline IDragItem::SupportedOps IDragItem :: dragSupOps() const
  312. { return drgsupopsCl; }
  313.  
  314. inline Boolean IDragItem :: isCopyable() const
  315. { return( (dragSupOps().asUnsignedLong() & copyable.asUnsignedLong())!=0 ); }
  316.  
  317. inline Boolean IDragItem :: isMoveable() const
  318. { return( (dragSupOps().asUnsignedLong() & moveable.asUnsignedLong())!=0 ); }
  319.  
  320. inline Boolean IDragItem :: isLinkable() const
  321. { return( (dragSupOps().asUnsignedLong() & linkable.asUnsignedLong())!=0 ); }
  322.  
  323. inline Boolean IDragItem :: isOpen()            const
  324. { return( (dragControl().asUnsignedLong() & open.asUnsignedLong())!=0 ); }
  325.  
  326. inline Boolean IDragItem :: isReference()       const
  327. { return( (dragControl().asUnsignedLong() & ref.asUnsignedLong())!=0 ); }
  328.  
  329. inline Boolean IDragItem :: isGroup()           const
  330. { return( (dragControl().asUnsignedLong() & group.asUnsignedLong())!=0 ); }
  331.  
  332. inline Boolean IDragItem :: isContainer()       const
  333. { return( (dragControl().asUnsignedLong() & container.asUnsignedLong())!=0 ); }
  334.  
  335. inline Boolean IDragItem :: requiresDMPrepare() const
  336. { return( (dragControl().asUnsignedLong() & prepare.asUnsignedLong())!=0 ); }
  337.  
  338. inline Boolean IDragItem :: isRemovableMedia()  const
  339. { return( (dragControl().asUnsignedLong() & removeablemedia.asUnsignedLong())!=0 ); }
  340.  
  341. inline unsigned long IDragItem :: id() const
  342. { return ulClItemId; }
  343.  
  344. inline const IWindow* IDragItem :: window() const
  345. { return pwndClItem; }
  346.  
  347. inline IWindowHandle IDragItem :: windowHandle() const
  348. { return wndhClItem; }
  349.  
  350. inline ISize IDragItem :: origin() const
  351. { return sizClOrigin; }
  352.  
  353. inline IDragImage* IDragItem :: dragImage() const
  354. { return pdrgimageCl; }
  355.  
  356. inline Boolean IDragItem :: operator==(IDragItem& drgit)
  357. { return &drgit == this; }
  358.  
  359. #endif /* ndef _IDRGITM_ */
  360.