1 ////////////////////////////////////////////////////////////////////////////
2 // File: ccrystaltextbuffer.h
4 // Created: 29-Dec-1998
6 // Author: Stcherbatchenko Andrei
7 // E-mail: windfall@gmx.de
9 // Interface of the CCrystalTextBuffer class, a part of Crystal Edit -
10 // syntax coloring text editor.
12 // You are free to use or modify this code to the following restrictions:
13 // - Acknowledge me somewhere in your about box, simple "Parts of code by.."
14 // will be enough. If you can't (or don't want to), contact me personally.
15 // - LEAVE THIS HEADER INTACT
16 ////////////////////////////////////////////////////////////////////////////
18 ////////////////////////////////////////////////////////////////////////////
21 // + FEATURE: see cpps ...
23 // ... it's being edited very rapidly so sorry for non-commented
24 // and maybe "ugly" code ...
25 ////////////////////////////////////////////////////////////////////////////
27 #if !defined(AFX_CCRYSTALTEXTBUFFER_H__AD7F2F49_6CB3_11D2_8C32_0080ADB86836__INCLUDED_)
28 #define AFX_CCRYSTALTEXTBUFFER_H__AD7F2F49_6CB3_11D2_8C32_0080ADB86836__INCLUDED_
32 #endif // _MSC_VER >= 1000
34 #include "ccrystaltextview.h"
36 #ifndef __AFXTEMPL_H__
37 #pragma message("Include <afxtempl.h> in your stdafx.h to avoid this message")
41 #define UNDO_DESCRIP_BUF 32
45 LF_BOOKMARK_FIRST = 0x00000001L,
46 LF_EXECUTION = 0x00010000L,
47 LF_BREAKPOINT = 0x00020000L,
48 LF_COMPILATION_ERROR = 0x00040000L,
49 LF_BOOKMARKS = 0x00080000L,
50 LF_INVALID_BREAKPOINT = 0x00100000L
53 #define LF_BOOKMARK(id) (LF_BOOKMARK_FIRST << id)
57 CRLF_STYLE_AUTOMATIC = -1,
65 CE_ACTION_UNKNOWN = 0,
70 CE_ACTION_BACKSPACE = 5,
72 CE_ACTION_DRAGDROP = 7,
73 CE_ACTION_REPLACE = 8,
75 CE_ACTION_AUTOINDENT = 10,
76 CE_ACTION_AUTOCOMPLETE = 11,
77 CE_ACTION_AUTOEXPAND = 12,
78 CE_ACTION_LOWERCASE = 13,
79 CE_ACTION_UPPERCASE = 14,
80 CE_ACTION_SWAPCASE = 15,
81 CE_ACTION_CAPITALIZE = 16,
82 CE_ACTION_SENTENCIZE = 17,
83 CE_ACTION_RECODE = 18,
86 // Expandable: user actions allowed
90 /////////////////////////////////////////////////////////////////////////////
91 // CUpdateContext class
93 class EDITPADC_CLASS CUpdateContext
96 virtual void RecalcPoint (CPoint & ptPoint) = 0;
100 /////////////////////////////////////////////////////////////////////////////
101 // CCrystalTextBuffer command target
103 class EDITPADC_CLASS CCrystalTextBuffer : public CCmdTarget
106 DECLARE_DYNCREATE (CCrystalTextBuffer)
108 int m_nSourceEncoding;
109 static int m_nDefaultEncoding;
110 DWORD m_dwCurrentRevisionNumber;
111 DWORD m_dwRevisionNumberOnSave;
112 BOOL IsTextBufferInitialized () const { return m_bInit; }
120 BOOL m_bCreateBackupFile;
124 int FindLineWithFlag (DWORD dwFlag);
127 #pragma pack(push, 1)
128 // Nested class declarations
132 int m_nLength, m_nMax;
133 int m_nEolChars; // # of eolchars
135 DWORD m_dwRevisionNumber;
137 int FullLength() const { return m_nLength+m_nEolChars; }
138 int Length() const { return m_nLength; }
142 memset (this, 0, sizeof (SLineInfo));
148 UNDO_INSERT = 0x0001,
149 UNDO_BEGINGROUP = 0x0100
152 // [JRT] Support For Descriptions On Undo/Redo Actions
157 CPoint m_ptStartPos, m_ptEndPos; // Block of text participating
158 int m_nAction; // For information only: action type
159 CDWordArray *m_paSavedRevisonNumbers;
163 // Since in most cases we have 1 character here,
164 // we should invent a better way. Note: 2 * sizeof(WORD) <= sizeof(TCHAR*)
166 // Here we will use the following trick: on Win32 platforms high-order word
167 // of any pointer will be != 0. So we can store 1 character strings without
168 // allocating memory.
173 TCHAR *m_pszText; // For cases when we have > 1 character strings
174 TCHAR m_szText[2]; // For single-character strings
178 SUndoRecord () // default constructor
180 memset (this, 0, sizeof (SUndoRecord));
182 SUndoRecord (const SUndoRecord & src) // copy constructor
184 memset (this, 0, sizeof (SUndoRecord));
187 SUndoRecord & operator=(const SUndoRecord & src) // copy assignment
189 m_dwFlags = src.m_dwFlags;
190 m_ptStartPos = src.m_ptStartPos;
191 m_ptEndPos = src.m_ptEndPos;
192 m_nAction = src.m_nAction;
193 SetText(src.GetText());
194 INT_PTR size = src.m_paSavedRevisonNumbers->GetSize();
195 m_paSavedRevisonNumbers = new CDWordArray();
196 m_paSavedRevisonNumbers->SetSize(size);
198 for (i = 0; i < size; i++)
199 (*m_paSavedRevisonNumbers)[i] = (*src.m_paSavedRevisonNumbers)[i];
202 ~SUndoRecord () // destructor
205 if (m_paSavedRevisonNumbers)
206 delete m_paSavedRevisonNumbers;
209 void SetText (LPCTSTR pszText);
212 LPCTSTR GetText () const
214 // see the m_szText/m_pszText definition about the use of HIWORD
215 if (HIWORD ((DWORD) m_pszText) != 0)
223 class EDITPADC_CLASS CInsertContext : public CUpdateContext
226 CPoint m_ptStart, m_ptEnd;
227 virtual void RecalcPoint (CPoint & ptPoint);
230 class EDITPADC_CLASS CDeleteContext : public CUpdateContext
233 CPoint m_ptStart, m_ptEnd;
234 virtual void RecalcPoint (CPoint & ptPoint);
238 CArray < SLineInfo, SLineInfo & >m_aLines;
241 CArray < SUndoRecord, SUndoRecord & >m_aUndoBuf;
244 BOOL m_bUndoGroup, m_bUndoBeginGroup;
247 /** Position where the last change was made. */
248 CPoint m_ptLastChange;
252 CList < CCrystalTextView *, CCrystalTextView * >m_lpViews;
255 void InsertLine (LPCTSTR pszLine, int nLength = -1, int nPosition = -1, int nCount = 1);
256 void AppendLine (int nLineIndex, LPCTSTR pszChars, int nLength = -1);
257 void MoveLine(int line1, int line2, int newline1);
258 void SetEmptyLine(int nPosition, int nCount = 1);
261 BOOL InternalInsertText (CCrystalTextView * pSource, int nLine, int nPos, LPCTSTR pszText, int &nEndLine, int &nEndChar);
262 BOOL InternalDeleteText (CCrystalTextView * pSource, int nStartLine, int nStartPos, int nEndLine, int nEndPos);
263 CString StripTail (int i, int bytes);
265 // [JRT] Support For Descriptions On Undo/Redo Actions
266 virtual void AddUndoRecord (BOOL bInsert, const CPoint & ptStartPos, const CPoint & ptEndPos,
267 LPCTSTR pszText, int nActionType = CE_ACTION_UNKNOWN, CDWordArray *paSavedRevisonNumbers = NULL);
269 // Overridable: provide action description
270 virtual BOOL GetActionDescription (int nAction, CString & desc);
274 // Construction/destruction code
275 CCrystalTextBuffer ();
276 ~CCrystalTextBuffer ();
279 BOOL InitNew (int nCrlfStyle = CRLF_STYLE_DOS);
281 // WinMerge has own routines for loading and saving
282 #ifdef CRYSTALEDIT_ENABLELOADER
283 BOOL LoadFromFile (LPCTSTR pszFileName, int nCrlfStyle = CRLF_STYLE_AUTOMATIC);
285 #ifdef CRYSTALEDIT_ENABLESAVER
286 BOOL SaveToFile(LPCTSTR pszFileName, int nCrlfStyle = CRLF_STYLE_AUTOMATIC,
287 BOOL bClearModifiedFlag = TRUE);
292 void ResetInit() { FreeAll(); InitNew(); } // reset new or used buffer
295 virtual void SetModified (BOOL bModified = TRUE);
296 BOOL IsModified () const;
298 // Connect/disconnect views
299 void AddView (CCrystalTextView * pView);
300 void RemoveView (CCrystalTextView * pView);
302 // Text access functions
303 int GetLineCount () const;
304 int GetLineLength (int nLine) const;
305 int GetFullLineLength (int nLine) const; // including EOLs
306 LPCTSTR GetLineEol (int nLine) const;
307 BOOL ChangeLineEol (int nLine, LPCTSTR lpEOL);
308 LPTSTR GetLineChars (int nLine) const;
309 DWORD GetLineFlags (int nLine) const;
310 DWORD GetLineRevisionNumber (int nLine) const;
311 int GetLineWithFlag (DWORD dwFlag);
312 void SetLineFlag (int nLine, DWORD dwFlag, BOOL bSet, BOOL bRemoveFromPreviousLine = TRUE, BOOL bUpdate=TRUE);
313 void GetText (int nStartLine, int nStartChar, int nEndLine, int nEndChar, CString & text, LPCTSTR pszCRLF = NULL);
314 virtual void GetTextWithoutEmptys (int nStartLine, int nStartChar, int nEndLine, int nEndChar, CString &text, int nCrlfStyle =CRLF_STYLE_AUTOMATIC );
318 void SetCRLFMode (int nCRLFMode);
319 /// Adjust all the lines in the buffer to the buffer default EOL Mode
320 virtual BOOL applyEOLMode();
321 LPCTSTR CCrystalTextBuffer::GetDefaultEol() const;
322 LPCTSTR CCrystalTextBuffer::GetStringEol(int nCRLFMode) const;
323 BOOL GetReadOnly () const;
324 void SetReadOnly (BOOL bReadOnly = TRUE);
326 void SetIgnoreEol(BOOL IgnoreEol) { m_IgnoreEol = IgnoreEol; }
328 // Text modification functions
329 virtual BOOL InsertText (CCrystalTextView * pSource, int nLine, int nPos, LPCTSTR pszText, int &nEndLine, int &nEndChar, int nAction = CE_ACTION_UNKNOWN, BOOL bHistory =TRUE);
330 virtual BOOL DeleteText (CCrystalTextView * pSource, int nStartLine, int nStartPos, int nEndLine, int nEndPos, int nAction = CE_ACTION_UNKNOWN, BOOL bHistory =TRUE);
335 virtual BOOL Undo (CCrystalTextView * pSource, CPoint & ptCursorPos);
336 virtual BOOL Redo (CCrystalTextView * pSource, CPoint & ptCursorPos);
339 virtual void BeginUndoGroup (BOOL bMergeWithPrevious = FALSE);
340 virtual void FlushUndoGroup (CCrystalTextView * pSource);
344 Returns the position where the last changes where made.
346 CPoint GetLastChangePos() const;
348 void RestoreLastChangePos(CPoint pt);
349 void DeleteLine(int line, int nCount = 1);
352 // Browse undo sequence
353 POSITION GetUndoActionCode (int & nAction, POSITION pos = NULL);
354 POSITION GetRedoActionCode (int & nAction, POSITION pos = NULL);
355 POSITION GetUndoDescription (CString & desc, POSITION pos = NULL);
356 POSITION GetRedoDescription (CString & desc, POSITION pos = NULL);
358 // Notify all connected views about changes in name of file
359 CCrystalTextView::TextDefinition *RetypeViews (LPCTSTR lpszFileName);
360 // Notify all connected views about changes in text
361 void UpdateViews (CCrystalTextView * pSource, CUpdateContext * pContext,
362 DWORD dwUpdateFlags, int nLineIndex = -1);
364 // Tabs/space inserting
365 BOOL GetInsertTabs() const;
366 void SetInsertTabs(BOOL bInsertTabs);
370 void SetTabSize(int nTabSize);
373 int FindNextBookmarkLine (int nCurrentLine = 0);
374 int FindPrevBookmarkLine (int nCurrentLine = 0);
376 BOOL IsMBSLead (int nLine, int nCol);
377 BOOL IsMBSTrail (int nLine, int nCol);
380 // ClassWizard generated virtual function overrides
381 //{{AFX_VIRTUAL(CCrystalTextBuffer)
385 // Generated message map functions
386 //{{AFX_MSG(CCrystalTextBuffer)
389 DECLARE_MESSAGE_MAP ()
392 #if ! (defined(CE_FROM_DLL) || defined(CE_DLL_BUILD))
393 #include "ccrystaltextbuffer.inl"
396 /////////////////////////////////////////////////////////////////////////////
398 //{{AFX_INSERT_LOCATION}}
399 // Microsoft Developer Studio will insert additional declarations immediately before the previous line.
401 #endif // !defined(AFX_CCRYSTALTEXTBUFFER_H__AD7F2F49_6CB3_11D2_8C32_0080ADB86836__INCLUDED_)