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.

210 lines
4.6 KiB

  1. #ifndef __UNDO_H__
  2. #define __UNDO_H__
  3. // A CBmObjSequence holds the codes for one undo or redo operation.
  4. class CBmObjSequence : public CByteArray
  5. {
  6. public:
  7. CBmObjSequence();
  8. ~CBmObjSequence();
  9. void Retrieve(BYTE* rgb, int cb);
  10. void RetrieveStr(CString& str);
  11. inline void RetrieveByte(BYTE& b) { Retrieve(&b, 1); }
  12. inline void RetrieveInt(int& n) { Retrieve((BYTE*)&n , sizeof (int)); }
  13. inline void RetrieveLong(long& n) { Retrieve((BYTE*)&n , sizeof (long)); }
  14. inline void RetrieveNum(double& num) { Retrieve((BYTE*)&num, sizeof (double)); }
  15. inline void RetrievePtr(CBitmapObj*& ptr) { Retrieve((BYTE*)&ptr, sizeof (CBitmapObj*)); }
  16. inline void RetrieveRect(CRect& rc) { Retrieve((BYTE*)&rc , sizeof (rc)); }
  17. inline void RetrievePoint(CPoint& pt) { Retrieve((BYTE*)&pt , sizeof (pt)); }
  18. void Cleanup();
  19. BOOL IsUseful(CBitmapObj*&, int&);
  20. void Apply();
  21. #ifdef _DEBUG
  22. void Dump();
  23. #endif
  24. int m_nCursor;
  25. CString m_strDescription;
  26. };
  27. class CUndoBmObj : public CBitmapObj
  28. {
  29. DECLARE_DYNAMIC(CUndoBmObj)
  30. public:
  31. CUndoBmObj();
  32. ~CUndoBmObj();
  33. void BeginUndo(const TCHAR* szCmd, BOOL bResetCursor = TRUE);
  34. void BeginUndo(const UINT idCmd, BOOL bResetCursor = TRUE);
  35. void EndUndo();
  36. inline BOOL CanUndo() const
  37. { return m_nRedoSeqs < m_seqs.GetCount(); }
  38. inline BOOL CanRedo() const
  39. { return m_nRedoSeqs > 0; }
  40. inline BOOL InUndoRedo() const
  41. { return m_bPerformingUndoRedo; }
  42. void GetUndoString(CString& strUndo);
  43. void GetRedoString(CString& strRedo);
  44. void DoUndo();
  45. void DoRedo();
  46. void SetMaxLevels(int nLevels);
  47. int GetMaxLevels() const;
  48. void OnSetIntProp( CBitmapObj* pChangedSlob, UINT nPropID, UINT nOldVal );
  49. #ifdef _DEBUG
  50. void Dump();
  51. #endif
  52. inline BOOL IsRecording() { return m_nRecording != 0 && m_nPauseLevel == 0; }
  53. inline void Pause() { m_nPauseLevel += 1; }
  54. inline void Resume() { ASSERT(m_nPauseLevel > 0); m_nPauseLevel -= 1; }
  55. enum
  56. {
  57. // Note correspondence with PRD
  58. opStart,
  59. opEnd,
  60. opAction,
  61. opIntProp,
  62. opLongProp,
  63. opBoolProp,
  64. opDoubleProp,
  65. opStrProp,
  66. opSlobProp,
  67. opRectProp,
  68. opPointProp
  69. };
  70. UINT Insert(const void* rgb, int cb);
  71. UINT InsertStr(const TCHAR* sz);
  72. inline UINT InsertByte(BYTE b) { return Insert(&b, 1); }
  73. inline UINT InsertInt(int n) { return Insert((BYTE*)&n, sizeof (int)); }
  74. inline UINT InsertLong(long n) { return Insert((BYTE*)&n, sizeof (long)); }
  75. inline UINT InsertNum(double num) { return Insert((BYTE*)&num, sizeof (double)); }
  76. inline UINT InsertPtr(const void* ptr)
  77. {
  78. if (ptr != NULL)
  79. {
  80. ASSERT(((CObject*)ptr)->IsKindOf(RUNTIME_CLASS(CBitmapObj)));
  81. ((CBitmapObj*)ptr)->AddDependant(this);
  82. }
  83. return Insert((BYTE*)&ptr, sizeof (CBitmapObj*));
  84. }
  85. inline UINT InsertRect(const CRect& rc) { return Insert((BYTE*)&rc, sizeof (CRect)); }
  86. inline UINT InsertPoint(const CPoint& pt) { return Insert((BYTE*)&pt, sizeof (CPoint)); }
  87. void Flush();
  88. void OnInform(CBitmapObj* pChangedSlob, UINT idChange);
  89. void FlushLast();
  90. private:
  91. void Truncate();
  92. int m_nRecording; // BeginUndo() nesting count
  93. int m_nPauseLevel; // Pause() nesting count
  94. int m_cbUndo;
  95. // These ?Last* variables are used to coalesce consecutive changes
  96. // to the same property...
  97. CBitmapObj* m_pLastSlob;
  98. int m_nLastPropID;
  99. // Properties...
  100. int m_nMaxLevels;
  101. CObList m_seqs; // pointers to CBmObjSequences
  102. int m_nRedoSeqs;
  103. CBmObjSequence* m_pCurSeq;
  104. BOOL m_bPerformingUndoRedo;
  105. friend class CBmObjSequence;
  106. };
  107. #pragma pack(1)
  108. class CUndoRecord
  109. {
  110. public:
  111. BYTE m_op;
  112. CBitmapObj* m_pBitmapObj;
  113. UINT m_nPropID;
  114. };
  115. class CIntUndoRecord : public CUndoRecord
  116. {
  117. public:
  118. int m_nOldVal;
  119. };
  120. class CLongUndoRecord : public CUndoRecord
  121. {
  122. public:
  123. long m_nOldVal;
  124. };
  125. class CDoubleUndoRecord : public CUndoRecord
  126. {
  127. public:
  128. double m_numOldVal;
  129. };
  130. class CRectUndoRecord : public CUndoRecord
  131. {
  132. public:
  133. CRect m_rectOldVal;
  134. };
  135. class CPointUndoRecord : public CUndoRecord
  136. {
  137. public:
  138. CPoint m_ptOldVal;
  139. };
  140. class CBitmapObjUndoRecord : public CUndoRecord
  141. {
  142. public:
  143. const CBitmapObj* m_pOldVal;
  144. };
  145. #pragma pack()
  146. extern CUndoBmObj NEAR theUndo;
  147. #endif // __UNDO_H__