Source code of Windows XP (NT5)
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

280 lines
7.2 KiB

  1. /*
  2. * @doc INTERNAL
  3. *
  4. * @module _ANTIEVT.H |
  5. *
  6. *
  7. * Purpose:
  8. * Class declarations for common anti-event objects
  9. *
  10. * Author:
  11. * alexgo 3/25/95
  12. *
  13. * Copyright (c) 1995-1997, Microsoft Corporation. All rights reserved.
  14. */
  15. #ifndef __ANTIEVT_H__
  16. #define __ANTIEVT_H__
  17. #include "_frunptr.h"
  18. class CTxtEdit;
  19. class CAntiEventDispenser;
  20. class COleObject;
  21. /*
  22. * CBaseAE
  23. *
  24. * @class
  25. * Base anti-event that manages a linked list of anti-events
  26. *
  27. */
  28. class CBaseAE : public IAntiEvent
  29. {
  30. //@access Public Methods
  31. public:
  32. virtual void Destroy(); //@cmember Destroy
  33. //@cmember Undo
  34. virtual HRESULT Undo( CTxtEdit *ped, IUndoBuilder *publdr );
  35. virtual HRESULT MergeData( DWORD dwDataType, void *pdata); //@cmember
  36. // Merges undo data into the
  37. // current context.
  38. virtual void OnCommit( CTxtEdit *ped ); //@cmember Called when AE is
  39. // committed to undo stack
  40. virtual void SetNext( IAntiEvent *pNext ); //@cmember Sets next AE
  41. virtual IAntiEvent *GetNext(); //@cmember Gets next AE
  42. //@access Protected Methods
  43. protected:
  44. // CBaseAE should only exist as a parent class
  45. CBaseAE(); //@cmember Constructor
  46. ~CBaseAE(){;}
  47. //@access Private Methods and Data
  48. private:
  49. IAntiEvent * _pnext; //@cmember Pointer to the next
  50. //AntiEvent
  51. };
  52. /*
  53. * CReplaceRangeAE
  54. *
  55. * @class
  56. * an anti-event object than undoes a CTxtPtr::ReplaceRange
  57. * operation
  58. *
  59. * @base public | CBaseAE
  60. */
  61. class CReplaceRangeAE: public CBaseAE
  62. {
  63. //@access Public Methods
  64. public:
  65. // IAntiEvent methods
  66. virtual void Destroy(); //@cmember Destroy
  67. //@cmember Undo
  68. virtual HRESULT Undo( CTxtEdit *ped, IUndoBuilder *publdr);
  69. virtual HRESULT MergeData( DWORD dwDataType, void *pdata); //@cmember
  70. // Merges undo data into the
  71. // current context
  72. //@access Private methods and data
  73. private:
  74. //@cmember Constructor
  75. CReplaceRangeAE(LONG cpMin, LONG cpMax, LONG cchDel, TCHAR *pchDel,
  76. IAntiEvent *paeCF, IAntiEvent *paePF);
  77. ~CReplaceRangeAE(); //@cmember Destructor
  78. LONG _cpMin; //@cmember cp delete start
  79. LONG _cpMax; //@cmember cp delete end
  80. LONG _cchDel; //@cmember #of chars to insert
  81. TCHAR * _pchDel; //@cmember chars to insert
  82. IAntiEvent *_paeCF; //@cmember charformat AE
  83. IAntiEvent *_paePF; //@cmember par format AE
  84. friend class CAntiEventDispenser;
  85. };
  86. /*
  87. * CReplaceFormattingAE
  88. *
  89. * @class
  90. * an anti-event object than undoes replacing multiple char formats
  91. *
  92. * @base public | CBaseAE
  93. */
  94. class CReplaceFormattingAE: public CBaseAE
  95. {
  96. //@access Public methods
  97. public:
  98. //
  99. // IAntiEvent methods
  100. //
  101. virtual void Destroy( void ); //@cmember Destroy
  102. //@cmember Undo
  103. virtual HRESULT Undo( CTxtEdit *ped, IUndoBuilder *publdr);
  104. //@access Private Methods and Data
  105. private:
  106. //@cmember Constructor
  107. CReplaceFormattingAE(CTxtEdit* ped, CFormatRunPtr &rp, LONG cch, IFormatCache *pf, BOOL fPara);
  108. ~CReplaceFormattingAE(); //@cmember Destuctor
  109. LONG _cp; //@cmember cp where formatting
  110. // should start
  111. LONG _cRuns; //@cmember # of format runs
  112. CFormatRun *_prgRuns; //@cmember format runs
  113. BOOL _fPara; //@cmember if TRUE, then
  114. // formatting is paragraph fmt
  115. friend class CAntiEventDispenser;
  116. };
  117. /*
  118. * CReplaceObjectAE
  119. *
  120. * @class
  121. * an anti-event object that undoes the deletion of an object
  122. *
  123. * @base public | CBaseAE
  124. */
  125. class CReplaceObjectAE : public CBaseAE
  126. {
  127. //@access Public methods
  128. public:
  129. //
  130. // IAntiEvent methods
  131. //
  132. virtual void Destroy(void); //@cmember Destroy
  133. //@cmember Undo
  134. virtual HRESULT Undo(CTxtEdit *ped, IUndoBuilder *publdr);
  135. virtual void OnCommit(CTxtEdit *ped); //@cmember called when
  136. // committed
  137. private:
  138. CReplaceObjectAE(COleObject *pobj); //@cmember Constructor
  139. ~CReplaceObjectAE(); //@cmember Destructor
  140. COleObject * _pobj; //@cmember pointer to the
  141. // deleted object
  142. BOOL _fUndoInvoked; //@cmember undo was invoked
  143. // on this object.
  144. friend class CAntiEventDispenser;
  145. };
  146. /*
  147. * CResizeObjectAE
  148. *
  149. * @class
  150. * an anti-event object that undoes the resizing of an object
  151. *
  152. * @base public | CBaseAE
  153. */
  154. class CResizeObjectAE : public CBaseAE
  155. {
  156. //@access Public methods
  157. public:
  158. //
  159. // IAntiEvent methods
  160. //
  161. virtual void Destroy(void); //@cmember Destroy
  162. //@cmember Undo
  163. virtual HRESULT Undo(CTxtEdit *ped, IUndoBuilder *publdr);
  164. virtual void OnCommit(CTxtEdit *ped); //@cmember called when
  165. // committed
  166. private:
  167. CResizeObjectAE(COleObject *pobj, //@cmember Constructor
  168. RECT rcPos);
  169. ~CResizeObjectAE(); //@cmember Destructor
  170. COleObject * _pobj; //@cmember pointer to the
  171. // deleted object
  172. RECT _rcPos; //@cmember The old object
  173. // position/size rectangle
  174. BOOL _fUndoInvoked; //@cmember undo was invoked
  175. // on this object.
  176. friend class CAntiEventDispenser;
  177. };
  178. /*
  179. * CSelectionAE
  180. *
  181. * @class
  182. * an anti-event object to restore a selection
  183. *
  184. * @base public | CBaseAE
  185. */
  186. class CSelectionAE : public CBaseAE
  187. {
  188. //@access Public methods
  189. public:
  190. //
  191. // IAntiEvent methods
  192. //
  193. virtual void Destroy(void); //@cmember Destroy
  194. //@cmember Undo
  195. virtual HRESULT Undo(CTxtEdit *ped, IUndoBuilder *publdr);
  196. virtual HRESULT MergeData( DWORD dwDataType, void *pdata); //@cmember
  197. // Merges undo data into the
  198. // current context
  199. private:
  200. //@cmember Constructor
  201. CSelectionAE(LONG cp, LONG cch, LONG cpNext, LONG cchNext);
  202. ~CSelectionAE(); //@cmember Destructor
  203. LONG _cp; //@cmember Active end
  204. LONG _cch; //@cmember Signed extension
  205. LONG _cpNext; //@cmember Next active end
  206. LONG _cchNext; //@cmember Next extension
  207. friend class CAntiEventDispenser;
  208. };
  209. /*
  210. * CAntiEventDispenser
  211. *
  212. * @class
  213. * creates anti events and caches them intelligently to provide
  214. * for efficient multi-level undo
  215. */
  216. class CAntiEventDispenser
  217. {
  218. //@access Public methods
  219. public:
  220. // no memory mgmt routines; the dispenser is global
  221. //@cmember text antievent
  222. IAntiEvent * CreateReplaceRangeAE( CTxtEdit *ped, LONG cpMin,
  223. LONG cpMax, LONG cchDel, TCHAR *pchDel,
  224. IAntiEvent *paeCF, IAntiEvent *paePF );
  225. //@cmember formatting AE
  226. IAntiEvent * CreateReplaceFormattingAE( CTxtEdit *ped,
  227. CFormatRunPtr &rp, LONG cch,
  228. IFormatCache *pf, BOOL fPara );
  229. //@cmember Object AE
  230. IAntiEvent * CreateReplaceObjectAE(CTxtEdit *ped, COleObject *pobj);
  231. //@cmember Object AE
  232. IAntiEvent * CreateResizeObjectAE(CTxtEdit *ped, COleObject *pobj, RECT rcPos);
  233. //@cmember Selection AE
  234. IAntiEvent * CreateSelectionAE(CTxtEdit *ped, LONG cp, LONG cch,
  235. LONG cpNext, LONG cchNext);
  236. private:
  237. // FUTURE (alexgo): we'll want to maintain an allocation cache of
  238. // anti-events
  239. };
  240. // NB!! Global variable.
  241. extern class CAntiEventDispenser gAEDispenser;
  242. #endif // !__ANTIEVNT_H__