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

  1. #ifndef _IDRGTXT_
  2.   #define _IDRGTXT_
  3. /*--------------------------------------------------------------*/
  4. /* CLASS NAMES:   IDragTextItem                                 */
  5. /*                IDragWinTextItem                              */
  6. /*                IDragEFItem                                   */
  7. /*                IDropTextCatcher                              */
  8. /*                IDropWinTextCatcher                           */
  9. /*                IDragDropEFHandler                            */
  10. /*                                                              */
  11. /* DESCRIPTION  : Drag by text classes.                         */
  12. /*                                                              */
  13. /*                                                              */
  14. /* CHANGE ACTIVITY:                                             */
  15. /* ---------------                                              */
  16. /*   DATE:     INITIAL:       DESCRIPTION:                      */
  17. /* 09/11/92    PHG            Created                           */
  18. /*--------------------------------------------------------------*/
  19. /* Copyright (c) IBM Corporation 1991                           */
  20. /*--------------------------------------------------------------*/
  21.  
  22. #ifndef _ITEXTCTL_
  23.   #include <itextctl.hpp>
  24. #endif
  25.  
  26. #ifndef _IENTRYFD_
  27.   #include <ientryfd.hpp>
  28. #endif
  29.  
  30. #ifndef _IDRGSRCH_
  31.   #include <idrgsrch.hpp>
  32. #endif
  33.  
  34. #ifndef _IDRGTGTH_
  35.   #include <idrgtgth.hpp>
  36. #endif
  37.  
  38. #ifndef _IDRGITM_
  39.   #include <idrgitm.hpp>
  40. #endif
  41.  
  42. #ifndef _IDRPCTCH_
  43.   #include <idrpctch.hpp>
  44. #endif
  45.  
  46.  
  47. class IDragTextItem : public IDragItem {
  48. /**************************************************************************
  49. *  These classes are subclasses of the base drag&drop classes tailored    *
  50. *  to support Drag&Drop of text either within the same process or across  *
  51. *  processes.                                                             *
  52. *  To this effect, two new RMFs are defined:                              *
  53. *    <DRM_BUFFERpid,DRF_ZSTRING> used as native RMF to drag a string      *
  54. *      pointer valid within process 'pid'. The string pointer is held     *
  55. *      in the itemId.                                                     *
  56. *    <DRM_SHRBUFFER,DRF_ZSTRING> used as alternative RMF to drag a string *
  57. *      from one process to another. This mechanism requires rendering in  *
  58. *      order allow the copy of the string to a shared buffer              *
  59. *                                                                         *
  60. * EXAMPLE:                                                                *
  61. *  {IDragTextItem* ptxtitm=new IDragTextItem("Text to Drag");             *
  62. *   IDragSourceHandler psrch=new IDragSourceHandler();                    *
  63. *   IWindow* pwnd=new IWindow(...);                                       *
  64. *                                                                         *
  65. *    psrch->dragItemList().add(ptxtitm);                                  *
  66. *    pwnd->addHandler(psrch);                                             *
  67. *  }                                                                      *
  68. **************************************************************************/
  69. public:
  70.  
  71.   static const char* pszDefaultType;
  72.  
  73. /*------------------------ CONSTRUCTORS/DESTRUCTORS ----------------------+
  74. | There is one default way to construct instances of this class:          |
  75. |   1. provide text string to drag, supported operations and type         |
  76. +------------------------------------------------------------------------*/
  77.   IDragTextItem(const char *pszDragText=0,
  78.                 const SupportedOps& drgsupops=copyable,
  79.                 const ITypesString& strTypes=pszDefaultType);
  80.  
  81. /*-------------------------------- ACCESSORS -----------------------------+
  82. | These function provide means of setting the accessible attributes of    |
  83. | instances of this lass:                                                 |
  84. |   setDragString - sets the string to drag                               |
  85. +------------------------------------------------------------------------*/
  86. void
  87.   setDragString(const IString& strDrag);
  88.  
  89.  
  90. protected:
  91. /*-------------------------------- CALLBACKS -----------------------------+
  92. | These functions are intended to be overridden by the user to implement  |
  93. | his own specific behavior                                               |
  94. |   dragString - return the drag string, default returns the instance str |
  95. +------------------------------------------------------------------------*/
  96. virtual IString
  97.   dragString(const IBeginDragEvent& begdrgevt) const;
  98.  
  99. private:
  100. /*-------------------------------- OVERRIDES -----------------------------+
  101. | This class overrides the following inherited functions:                 |
  102. |  setupForDrag - prepare to be dragged                                   |
  103. |  render       - renders the string to shared buffer                     |
  104. |  conversationEnded - clean-up once conversation is finished             |
  105. +------------------------------------------------------------------------*/
  106. virtual Boolean
  107.   setupForDrag(const IBeginDragEvent& begdrgevt);
  108.  
  109. virtual Boolean
  110.   render(const IDragSourceHandler* pdrgsrch,
  111.          IRenderEvent& rendevt);
  112.  
  113. virtual Boolean
  114.   conversationEnded(const IDragSourceHandler* pdrgsrch,
  115.                     const IEndConversationEvent& endcvevt);
  116.  
  117. private:
  118. /*------------------------------ DATA MEMBERS ----------------------------+
  119. |  strClDrag - Local copy of string to drag                               |
  120. +------------------------------------------------------------------------*/
  121.   IString strClDrag;
  122.  
  123. }; // IDragTextItem
  124.  
  125.  
  126. class IDragWinTextItem : public IDragTextItem {
  127. /**************************************************************************
  128. *  This class is specifically designed to drag a text control's text      *
  129. *  Whenever a drag operation is started, the cnotrol's text will be       *
  130. *  queried and used as drag string.                                       *
  131. *                                                                         *
  132. * EXAMPLE:                                                                *
  133. *  {IStaticText ptxt=new IStaticText(...);                                *
  134. *   IDragWinTextItem* pwintxtitm=new IDragWinTextItem(ptxt);              *
  135. *   IDragSourceHandler psrch=new IDragSourceHandler();                    *
  136. *                                                                         *
  137. *    psrch->dragItemList().add(pwintxtitm);                               *
  138. *    ptxt->addHandler(psrch);                                             *
  139. *  }                                                                      *
  140. **************************************************************************/
  141. public:
  142. /*------------------------ CONSTRUCTORS/DESTRUCTORS ----------------------+
  143. | There is one default way to construct instances of this class:          |
  144. |   1. Supply the text control that is to be dragged, and optionally      |
  145. |      the operations and types                                           |
  146. +------------------------------------------------------------------------*/
  147.   IDragWinTextItem(ITextControl* pwndText,
  148.                    const SupportedOps& drgsupops=copyable,
  149.                    const ITypesString& strTypes=IDragTextItem::pszDefaultType);
  150.  
  151. protected:
  152. /*-------------------------------- OVERRIDES -----------------------------+
  153. | This class overrides the following inherited functions:                 |
  154. |   dragString - to get the drag string from the window text              |
  155. +------------------------------------------------------------------------*/
  156. virtual IString
  157.   dragString(const IBeginDragEvent& begdrgevt) const;
  158.  
  159. private:
  160. /*------------------------------ DATA MEMBERS ----------------------------+
  161. |  pwndClText - Text control on which we apply                            |
  162. +------------------------------------------------------------------------*/
  163.   ITextControl* pwndClText;
  164. }; // IDragWinTextItem
  165.  
  166.  
  167. class IDragEFItem : public IDragTextItem {
  168. /**************************************************************************
  169. *  This class is specifically designed to drag an entry field's text      *
  170. *  or marked text if any.                                                 *
  171. *                                                                         *
  172. *  NOTE: These items should be added *only* source handlers which are     *
  173. *        themselves added to instances of descendants of the IEntryField  *
  174. *        class. Failure to do so is a coding error and will result in     *
  175. *        unpredictable behavior                                           *
  176. *                                                                         *
  177. * EXAMPLE:                                                                *
  178. *  {IEntryField pef=new IEntryField(...);                                 *
  179. *   IDragEFItem* pefitm=new IDragEFItem();                                *
  180. *   IDragSourceHandler psrch=new IDragSourceHandler();                    *
  181. *                                                                         *
  182. *    psrch->dragItemList().add(pefitm);                                   *
  183. *    pef->addHandler(psrch);                                              *
  184. *  }                                                                      *
  185. **************************************************************************/
  186. public:
  187. /*------------------------ CONSTRUCTORS/DESTRUCTORS ----------------------+
  188. | There is one way to construct instances of this class:                  |
  189. |  - Construct from an IEntryField pointer                                |
  190. +------------------------------------------------------------------------*/
  191.   IDragEFItem(const SupportedOps& drgsupops=copyable,
  192.               const ITypesString& strTypes=IDragTextItem::pszDefaultType);
  193.  
  194. protected:
  195. /*-------------------------------- OVERRIDES -----------------------------+
  196. | This class overrides the following inherited functions:                 |
  197. |   dragString - return the string to drag for this event                 |
  198. +------------------------------------------------------------------------*/
  199. virtual IString
  200.   dragString(const IBeginDragEvent& begdrgevt) const;
  201.  
  202. }; // IDragEFItem
  203.  
  204.  
  205. class IDropTextCatcher : public IDropCatcher {
  206. /**************************************************************************
  207. *  This class is specifically designed to catch drops of text according   *
  208. *  to the protocol set forth by IDragTextItem                             *
  209. *  This class is typically used through a subclass that overloads the     *
  210. *  'textDropped' virtual function to use the dropped text.                *
  211. *                                                                         *
  212. * EXAMPLE:                                                                *
  213. **************************************************************************/
  214. public:
  215.   static const char* pszDefaultType;
  216. /*------------------------ CONSTRUCTORS/DESTRUCTORS ----------------------+
  217. | There is one default way to construct instances of this class:          |
  218. |   1. Specifying the type of items                                       |
  219. +------------------------------------------------------------------------*/
  220.   IDropTextCatcher(const ITypesString& pszTypes=pszDefaultType);
  221.  
  222. protected:
  223. /*-------------------------------- CALLBACKS -----------------------------+
  224. | These functions are intended to be overridden by the user to implement  |
  225. | his own specific behavior                                               |
  226. |  textDropped - pure virtual called when text is dropped                 |
  227. +------------------------------------------------------------------------*/
  228. virtual void
  229.   textDropped(const char *pszText,
  230.               const IEvent& evt) = 0;
  231.  
  232. private:
  233. /*-------------------------------- OVERRIDES -----------------------------+
  234. | This class overrides the following inherited functions:                 |
  235. |   itemRendered - To handle same-process drops                           |
  236. |   itemRendered - To handle cross-process drops                          |
  237. +------------------------------------------------------------------------*/
  238. /* call-back functions overloads */
  239. virtual Boolean
  240.   itemRendered(const IDragItem& drgitm,
  241.                const IDropOnEvent& drpevt);
  242. virtual Boolean
  243.   itemRendered(const IDragItem& drgitm,
  244.                const IRMFsString& strRMFs,
  245.                const IString& strRenderToName,
  246.                unsigned long ulTargetInfo,
  247.                const IRenderCompleteEvent& rendcevt);
  248.  
  249. }; // IDropTextCatcher
  250.  
  251. class IDropWinTextCatcher : public IDropTextCatcher {
  252. /**************************************************************************
  253. *  This class is specifically designed to catch drops of text on a text   *
  254. *  control.                                                               *
  255. *                                                                         *
  256. *  NOTE: This catchers should be added *only* target handlers which are   *
  257. *        themselves added to instances of descendants of the ITextControl *
  258. *        class. Failure to do so is a coding error and will result in     *
  259. *        unpredictable behavior                                           *
  260. *                                                                         *
  261. * EXAMPLE:                                                                *
  262. *   {IDragTargetHandler* ptgth=new IDragTargetHandler();                  *
  263. *    IDropWinTextCatcher* pwintxtctch= new IDropTextCatcher();            *
  264. *    IStaticText* ptxt=new IStaticText(...);                              *
  265. *                                                                         *
  266. *     ptgth->dropCatcherList().add(pwintxtctch);                          *
  267. *     ptxt->addHandler(ptgth);                                            *
  268. *                                                                         *
  269. *   }                                                                     *
  270. **************************************************************************/
  271. public:
  272. /*------------------------ CONSTRUCTORS/DESTRUCTORS ----------------------+
  273. | There is one default way to construct instances of this class:          |
  274. |   1. Optionally specify the acceptable type of items                    |
  275. +------------------------------------------------------------------------*/
  276.   IDropWinTextCatcher(const ITypesString& strTypes=
  277.                         IDropTextCatcher::pszDefaultType);
  278.  
  279. protected:
  280. /*-------------------------------- OVERRIDES -----------------------------+
  281. | This class overrides the following inherited functions:                 |
  282. |   textDropped - set window text when dropped                            |
  283. +------------------------------------------------------------------------*/
  284. virtual void
  285.   textDropped(const char * pszText,
  286.               const IEvent& evt);
  287.  
  288. }; // IDropWinTextCatcher
  289.  
  290.  
  291. class IDragDropEFHandler : public IDragSourceHandler, public IDragTargetHandler {
  292. /**************************************************************************
  293. * This class is a wrap-up of EntryField drag&drop for both source and     *
  294. * target operations.                                                      *
  295. * An instance of this class can be used to handle more than one           *
  296. * IEntryField, provided they all support the same types                   *
  297. *                                                                         *
  298. * EXAMPLE:                                                                *
  299. * {IDragDropEFHandler* pddefh= new IDragDropEFHandler();                  *
  300. *  IEntryField pef1=new IEntryField(...);                                 *
  301. *  IEntryField pef2=new IEntryField(...);                                 *
  302. *                                                                         *
  303. *   pddefh->startHandlingEFDragDrop(pef1);                                *
  304. *   pddefh->startHandlingEFDragDrop(pef2);                                *
  305. * }                                                                       *
  306. **************************************************************************/
  307. public:
  308. /*------------------------ CONSTRUCTORS/DESTRUCTORS ----------------------+
  309. | There is one way to construct instances of this class:                  |
  310. |   1 - from an optional IEntryfield pointer                              |
  311. +------------------------------------------------------------------------*/
  312.   IDragDropEFHandler(IEntryField* pef=0,
  313.                      const ITypesString& strTypes=IDragTextItem::pszDefaultType);
  314.  
  315. /*------------------------ HANDLER ACTIVATION ----------------------------+
  316. | These functions start and stop handling drag&drop events for entryfields|
  317. |  startHandlingEFDragDrop - start handling D&D                           |
  318. |  stopHandlingEFDragDrop  - stop handling D&D                            |
  319. +------------------------------------------------------------------------*/
  320. void
  321.   startHandlingEFDragDrop(IEntryField* pef) const,
  322.   stopHandlingEFDragDrop(IEntryField* pef) const;
  323.  
  324. }; // IDragDropEFHandler
  325.  
  326.  
  327. /*=========================================================================
  328. | Inlines for IDragTextItem                                     PHG 26/10 |
  329. =========================================================================*/
  330. inline void IDragTextItem :: setDragString(const IString& strDrag)
  331. { strClDrag=strDrag; }
  332.  
  333. /*=========================================================================
  334. | Inlines for IDropWinTextCatcher                               PHG 26/10 |
  335. =========================================================================*/
  336. inline IDropWinTextCatcher :: IDropWinTextCatcher(const ITypesString& strTypes)
  337. : IDropTextCatcher(strTypes) { }
  338.  
  339. #endif  // def _IDRGTXT_
  340.