X-Git-Url: https://git.saurik.com/wxWidgets.git/blobdiff_plain/df5168c427b51f1ab2b3200a5c8f7626b3d24aae..c0430d964dca888a28eff26436e6360a7b79b65f:/include/wx/textbuf.h diff --git a/include/wx/textbuf.h b/include/wx/textbuf.h index 2b25b2d470..0db6a65279 100644 --- a/include/wx/textbuf.h +++ b/include/wx/textbuf.h @@ -5,19 +5,16 @@ // differences between platforms. // Created: 14.11.01 // Author: Morten Hanssen, Vadim Zeitlin -// Copyright: (c) 1998-2001 wxWindows team +// Copyright: (c) 1998-2001 Morten Hanssen, Vadim Zeitlin // Licence: wxWindows licence /////////////////////////////////////////////////////////////////////////////// #ifndef _WX_TEXTBUFFER_H #define _WX_TEXTBUFFER_H -#if defined(__GNUG__) && !defined(__APPLE__) - #pragma interface "textbuf.h" -#endif - #include "wx/defs.h" #include "wx/arrstr.h" +#include "wx/convauto.h" // ---------------------------------------------------------------------------- // constants @@ -43,7 +40,9 @@ enum wxTextFileType // wxTextBuffer // ---------------------------------------------------------------------------- -WX_DEFINE_EXPORTED_ARRAY_INT(wxTextFileType, ArrayFileType); +WX_DEFINE_USER_EXPORTED_ARRAY_INT(wxTextFileType, + wxArrayLinesType, + class WXDLLIMPEXP_BASE); #endif // wxUSE_TEXTBUFFER @@ -82,10 +81,10 @@ public: bool Create(const wxString& strBufferName); // Open() also loads buffer in memory on success - bool Open(wxMBConv& conv = wxConvUTF8); + bool Open(const wxMBConv& conv = wxConvAuto()); // same as Open() but with (another) buffer name - bool Open(const wxString& strBufferName, wxMBConv& conv = wxConvUTF8); + bool Open(const wxString& strBufferName, const wxMBConv& conv = wxConvAuto()); // closes the buffer and frees memory, losing all changes bool Close(); @@ -100,15 +99,17 @@ public: 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 (wxString&)m_aLines[n]; } - wxString& operator[](size_t n) const { return (wxString&)m_aLines[n]; } + wxString& GetLine(size_t n) { return m_aLines[n]; } + const wxString& GetLine(size_t n) const { return m_aLines[n]; } + wxString& operator[](size_t n) { return m_aLines[n]; } + const wxString& operator[](size_t n) const { return 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.size() == 0 || m_nCurLine == m_aLines.size() - 1); } + bool Eof() const { return m_nCurLine == m_aLines.size(); } // these methods allow more "iterator-like" traversal of the list of // lines, i.e. you may write something like: @@ -116,12 +117,15 @@ public: // NB: const is commented out because not all compilers understand // 'mutable' keyword yet (m_nCurLine should be mutable) - wxString& GetFirstLine() /* const */ { return m_aLines[m_nCurLine = 0]; } - wxString& GetNextLine() /* const */ { return m_aLines[++m_nCurLine]; } + wxString& GetFirstLine() /* const */ + { return m_aLines.empty() ? ms_eof : m_aLines[m_nCurLine = 0]; } + wxString& GetNextLine() /* const */ + { return ++m_nCurLine == m_aLines.size() ? ms_eof + : m_aLines[m_nCurLine]; } wxString& GetPrevLine() /* const */ - { wxASSERT(m_nCurLine > 0); return m_aLines[--m_nCurLine]; } + { wxASSERT(m_nCurLine > 0); return m_aLines[--m_nCurLine]; } wxString& GetLastLine() /* const */ - { return m_aLines[m_nCurLine = m_aLines.size() - 1]; } + { m_nCurLine = m_aLines.size() - 1; return m_aLines.Last(); } // get the type of the line (see also GetEOL) wxTextFileType GetLineType(size_t n) const { return m_aTypes[n]; } @@ -130,7 +134,7 @@ public: wxTextFileType GuessType() const; // get the name of the buffer - const wxChar *GetName() const { return m_strBufferName.c_str(); } + const wxString& GetName() const { return m_strBufferName; } // add/remove lines // ---------------- @@ -143,24 +147,24 @@ public: size_t n, wxTextFileType type = typeDefault) { - m_aLines.insert(m_aLines.begin() + n, str); - m_aTypes.insert(m_aTypes.begin()+n, type); + 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.erase(m_aLines.begin() + n); - m_aTypes.erase(m_aTypes.begin() + n); + m_aTypes.erase(m_aTypes.begin() + n); } // remove all lines - void Clear() { m_aLines.clear(); m_nCurLine = 0; } + void Clear() { m_aLines.clear(); m_aTypes.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 = wxConvUTF8); + const wxMBConv& conv = wxConvAuto()); // dtor virtual ~wxTextBuffer(); @@ -170,7 +174,7 @@ protected: // ----- // default ctor, use Open(string) - wxTextBuffer() { m_isOpened = false; } + wxTextBuffer() { m_nCurLine = 0; m_isOpened = false; } // ctor from filename wxTextBuffer(const wxString& strBufferName); @@ -182,14 +186,15 @@ protected: virtual bool OnOpen(const wxString &strBufferName, wxTextBufferOpenMode openmode) = 0; virtual bool OnClose() = 0; - virtual bool OnRead(wxMBConv& conv) = 0; - virtual bool OnWrite(wxTextFileType typeNew, wxMBConv& conv) = 0; + virtual bool OnRead(const wxMBConv& conv) = 0; + virtual bool OnWrite(wxTextFileType typeNew, const wxMBConv& conv) = 0; - wxString m_strBufferName; // name of the buffer + static wxString ms_eof; // dummy string returned at EOF + 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