X-Git-Url: https://git.saurik.com/wxWidgets.git/blobdiff_plain/a3a584a7a6ade199990dd4463488e4bbf3545349..77f2f1d3c2c7fb3b301f12c469158dce523d7656:/include/wx/textbuf.h diff --git a/include/wx/textbuf.h b/include/wx/textbuf.h index f5a44afe68..170c28b931 100644 --- a/include/wx/textbuf.h +++ b/include/wx/textbuf.h @@ -6,17 +6,18 @@ // Created: 14.11.01 // Author: Morten Hanssen, Vadim Zeitlin // Copyright: (c) 1998-2001 wxWindows team -// Licence: wxWindows license +// Licence: wxWindows licence /////////////////////////////////////////////////////////////////////////////// #ifndef _WX_TEXTBUFFER_H #define _WX_TEXTBUFFER_H -#ifdef __GNUG__ +#if defined(__GNUG__) && !defined(NO_GCC_PRAGMA) #pragma interface "textbuf.h" #endif #include "wx/defs.h" +#include "wx/arrstr.h" // ---------------------------------------------------------------------------- // constants @@ -42,11 +43,13 @@ enum wxTextFileType // wxTextBuffer // ---------------------------------------------------------------------------- -WX_DEFINE_EXPORTED_ARRAY(wxTextFileType, ArrayFileType); +WX_DEFINE_USER_EXPORTED_ARRAY_INT(wxTextFileType, + wxArrayLinesType, + class WXDLLIMPEXP_BASE); #endif // wxUSE_TEXTBUFFER -class WXDLLEXPORT wxTextBuffer +class WXDLLIMPEXP_BASE wxTextBuffer { public: // constants and static functions @@ -81,10 +84,10 @@ public: bool Create(const wxString& strBufferName); // Open() also loads buffer in memory on success - bool Open(wxMBConv& conv = wxConvLibc); + bool Open(wxMBConv& conv = wxConvUTF8); // same as Open() but with (another) buffer name - bool Open(const wxString& strBufferName, wxMBConv& conv = wxConvLibc); + bool Open(const wxString& strBufferName, wxMBConv& conv = wxConvUTF8); // closes the buffer and frees memory, losing all changes bool Close(); @@ -96,18 +99,18 @@ public: // --------- // get the number of lines in the buffer - size_t GetLineCount() const { return m_aLines.Count(); } + size_t GetLineCount() const { return m_aLines.size(); } // the returned line may be modified (but don't add CR/LF at the end!) - wxString& GetLine(size_t n) const { return m_aLines[n]; } - wxString& operator[](size_t n) const { return m_aLines[n]; } + wxString& GetLine(size_t n) const { return (wxString&)m_aLines[n]; } + wxString& operator[](size_t n) const { return (wxString&)m_aLines[n]; } // the current line has meaning only when you're using // GetFirstLine()/GetNextLine() functions, it doesn't get updated when // you're using "direct access" i.e. GetLine() size_t GetCurrentLine() const { return m_nCurLine; } void GoToLine(size_t n) { m_nCurLine = n; } - bool Eof() const { return (m_aLines.Count() == 0 || m_nCurLine == m_aLines.Count() - 1); } + bool Eof() const { return (m_aLines.size() == 0 || m_nCurLine == m_aLines.size() - 1); } // these methods allow more "iterator-like" traversal of the list of // lines, i.e. you may write something like: @@ -120,7 +123,7 @@ public: wxString& GetPrevLine() /* const */ { wxASSERT(m_nCurLine > 0); return m_aLines[--m_nCurLine]; } wxString& GetLastLine() /* const */ - { return m_aLines[m_nCurLine = m_aLines.Count() - 1]; } + { return m_aLines[m_nCurLine = m_aLines.size() - 1]; } // get the type of the line (see also GetEOL) wxTextFileType GetLineType(size_t n) const { return m_aTypes[n]; } @@ -136,19 +139,30 @@ public: // add a line to the end void AddLine(const wxString& str, wxTextFileType type = typeDefault) - { m_aLines.Add(str); m_aTypes.Add(type); } + { m_aLines.push_back(str); m_aTypes.push_back(type); } // insert a line before the line number n void InsertLine(const wxString& str, size_t n, wxTextFileType type = typeDefault) - { m_aLines.Insert(str, n); m_aTypes.Insert(type, n); } + { + m_aLines.insert(m_aLines.begin() + n, str); + m_aTypes.insert(m_aTypes.begin()+n, type); + } + // delete one line - void RemoveLine(size_t n) { m_aLines.RemoveAt(n); m_aTypes.RemoveAt(n); } + void RemoveLine(size_t n) + { + m_aLines.erase(m_aLines.begin() + n); + m_aTypes.erase(m_aTypes.begin() + n); + } + + // remove all lines + void Clear() { m_aLines.clear(); m_nCurLine = 0; } // change the buffer (default argument means "don't change type") // possibly in another format bool Write(wxTextFileType typeNew = wxTextFileType_None, - wxMBConv& conv = wxConvLibc); + wxMBConv& conv = wxConvUTF8); // dtor virtual ~wxTextBuffer(); @@ -158,7 +172,7 @@ protected: // ----- // default ctor, use Open(string) - wxTextBuffer() { } + wxTextBuffer() { m_isOpened = false; } // ctor from filename wxTextBuffer(const wxString& strBufferName); @@ -171,14 +185,13 @@ protected: wxTextBufferOpenMode openmode) = 0; virtual bool OnClose() = 0; virtual bool OnRead(wxMBConv& conv) = 0; - virtual bool OnWrite(wxTextFileType typeNew, - wxMBConv& conv = wxConvLibc) = 0; + virtual bool OnWrite(wxTextFileType typeNew, wxMBConv& conv) = 0; wxString m_strBufferName; // name of the buffer private: - ArrayFileType m_aTypes; // type of each line - wxArrayString m_aLines; // lines of file + wxArrayLinesType m_aTypes; // type of each line + wxArrayString m_aLines; // lines of file size_t m_nCurLine; // number of current line in the buffer