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.

277 lines
7.1 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-2000, 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(); //@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, LONG cp, CFormatRunPtr &rp, LONG cch,
  108. IFormatCache *pf, BOOL fPara);
  109. ~CReplaceFormattingAE(); //@cmember Destuctor
  110. LONG _cp; //@cmember cp at formatting start
  111. LONG _cRuns; //@cmember # of format runs
  112. CFormatRun *_prgRuns; //@cmember format runs
  113. BOOL _fPara; //@cmember TRUE if para format
  114. friend class CAntiEventDispenser;
  115. };
  116. /*
  117. * CReplaceObjectAE
  118. *
  119. * @class
  120. * an anti-event object that undoes the deletion of an object
  121. *
  122. * @base public | CBaseAE
  123. */
  124. class CReplaceObjectAE : public CBaseAE
  125. {
  126. //@access Public methods
  127. public:
  128. //
  129. // IAntiEvent methods
  130. //
  131. virtual void Destroy(void); //@cmember Destroy
  132. //@cmember Undo
  133. virtual HRESULT Undo(CTxtEdit *ped, IUndoBuilder *publdr);
  134. virtual void OnCommit(CTxtEdit *ped); //@cmember called when
  135. // committed
  136. private:
  137. CReplaceObjectAE(COleObject *pobj); //@cmember Constructor
  138. ~CReplaceObjectAE(); //@cmember Destructor
  139. COleObject * _pobj; //@cmember pointer to the
  140. // deleted object
  141. BOOL _fUndoInvoked; //@cmember undo was invoked
  142. // on this object.
  143. friend class CAntiEventDispenser;
  144. };
  145. /*
  146. * CResizeObjectAE
  147. *
  148. * @class
  149. * an anti-event object that undoes the resizing of an object
  150. *
  151. * @base public | CBaseAE
  152. */
  153. class CResizeObjectAE : public CBaseAE
  154. {
  155. //@access Public methods
  156. public:
  157. //
  158. // IAntiEvent methods
  159. //
  160. virtual void Destroy(void); //@cmember Destroy
  161. //@cmember Undo
  162. virtual HRESULT Undo(CTxtEdit *ped, IUndoBuilder *publdr);
  163. virtual void OnCommit(CTxtEdit *ped); //@cmember called when
  164. // committed
  165. private:
  166. CResizeObjectAE(COleObject *pobj, SIZEUV size); //@cmember Constructor
  167. ~CResizeObjectAE(); //@cmember Destructor
  168. COleObject * _pobj; //@cmember pointer to the
  169. // deleted object
  170. SIZEUV _size; //@cmember The old size
  171. BOOL _fUndoInvoked; //@cmember undo was invoked
  172. // on this object.
  173. friend class CAntiEventDispenser;
  174. };
  175. /*
  176. * CSelectionAE
  177. *
  178. * @class
  179. * an anti-event object to restore a selection
  180. *
  181. * @base public | CBaseAE
  182. */
  183. class CSelectionAE : public CBaseAE
  184. {
  185. //@access Public methods
  186. public:
  187. //
  188. // IAntiEvent methods
  189. //
  190. virtual void Destroy(void); //@cmember Destroy
  191. //@cmember Undo
  192. virtual HRESULT Undo(CTxtEdit *ped, IUndoBuilder *publdr);
  193. virtual HRESULT MergeData( DWORD dwDataType, void *pdata); //@cmember
  194. // Merges undo data into the
  195. // current context
  196. private:
  197. //@cmember Constructor
  198. CSelectionAE(LONG cp, LONG cch, LONG cpNext, LONG cchNext);
  199. ~CSelectionAE(); //@cmember Destructor
  200. LONG _cp; //@cmember Active end
  201. LONG _cch; //@cmember Signed extension
  202. LONG _cpNext; //@cmember Next active end
  203. LONG _cchNext; //@cmember Next extension
  204. friend class CAntiEventDispenser;
  205. };
  206. /*
  207. * CAntiEventDispenser
  208. *
  209. * @class
  210. * creates anti events and caches them intelligently to provide
  211. * for efficient multi-level undo
  212. */
  213. class CAntiEventDispenser
  214. {
  215. //@access Public methods
  216. public:
  217. // no memory mgmt routines; the dispenser is global
  218. //@cmember text antievent
  219. IAntiEvent * CreateReplaceRangeAE( CTxtEdit *ped, LONG cpMin,
  220. LONG cpMax, LONG cchDel, TCHAR *pchDel,
  221. IAntiEvent *paeCF, IAntiEvent *paePF );
  222. //@cmember formatting AE
  223. IAntiEvent * CreateReplaceFormattingAE( CTxtEdit *ped,
  224. LONG cp, CFormatRunPtr &rp, LONG cch,
  225. IFormatCache *pf, BOOL fPara );
  226. //@cmember Object AE
  227. IAntiEvent * CreateReplaceObjectAE(CTxtEdit *ped, COleObject *pobj);
  228. //@cmember Object AE
  229. IAntiEvent * CreateResizeObjectAE(CTxtEdit *ped, COleObject *pobj, SIZEUV size);
  230. //@cmember Selection AE
  231. IAntiEvent * CreateSelectionAE(CTxtEdit *ped, LONG cp, LONG cch,
  232. LONG cpNext, LONG cchNext);
  233. private:
  234. // FUTURE (alexgo): we'll want to maintain an allocation cache of
  235. // anti-events
  236. };
  237. // NB!! Global variable.
  238. extern class CAntiEventDispenser gAEDispenser;
  239. #endif // !__ANTIEVNT_H__