From 935789271447807376993f92acf6397e3f1e79a5 Mon Sep 17 00:00:00 2001 From: Vadim Zeitlin Date: Sun, 15 Jun 2008 01:16:52 +0000 Subject: [PATCH] derive wxSTC from wxTextEntryBase to provide even more wxTextCtrl-like methods (see #9114) git-svn-id: https://svn.wxwidgets.org/svn/wx/wxWidgets/trunk@54226 c3d73ce0-8a6f-49c7-b76d-6d57e0e08775 --- include/wx/stc/stc.h | 72 +++++++++++++++++++++++++++++++++++++++----- src/stc/gen_iface.py | 6 ++-- src/stc/stc.cpp | 6 ++-- src/stc/stc.h.in | 66 +++++++++++++++++++++++++++++++++++++--- 4 files changed, 134 insertions(+), 16 deletions(-) diff --git a/include/wx/stc/stc.h b/include/wx/stc/stc.h index c766ced458..9ff6d84e1e 100644 --- a/include/wx/stc/stc.h +++ b/include/wx/stc/stc.h @@ -39,6 +39,7 @@ #include "wx/dnd.h" #include "wx/stopwatch.h" +#include "wx/textentry.h" #if wxUSE_TEXTCTRL #include "wx/textctrl.h" #endif // wxUSE_TEXTCTRL @@ -1985,6 +1986,7 @@ class WXDLLIMPEXP_FWD_STC wxStyledTextEvent; //---------------------------------------------------------------------- class WXDLLIMPEXP_STC wxStyledTextCtrl : public wxControl + , public wxTextEntryBase #if wxUSE_TEXTCTRL , public wxTextAreaBase #endif // wxUSE_TEXTCTRL @@ -2069,7 +2071,7 @@ public: wxMemoryBuffer GetStyledText(int startPos, int endPos); // Are there any redoable actions in the undo history? - bool CanRedo(); + bool CanRedo() const; // Retrieve the line number at which a particular marker is located. int MarkerLineFromHandle(int handle); @@ -2647,7 +2649,7 @@ public: bool CanPaste(); // Are there any undoable actions in the undo history? - bool CanUndo(); + bool CanUndo() const; // Delete the undo history. void EmptyUndoBuffer(); @@ -2671,7 +2673,7 @@ public: void SetText(const wxString& text); // Retrieve all the text in the document. - wxString GetText(); + wxString GetText() const; // Retrieve the number of characters in the document. int GetTextLength() const; @@ -3653,6 +3655,65 @@ public: #endif + // implement wxTextEntryBase pure virtual methods + // ---------------------------------------------- + + virtual void WriteText(const wxString& text) { AddText(text); } + virtual wxString GetValue() const { return GetText(); } + virtual void Remove(long from, long to) + { + Replace(from, to, ""); + } + virtual void Replace(long from, long to, const wxString& text) + { + SetTargetStart(from); + SetTargetEnd(to); + ReplaceTarget(text); + } + + /* + These functions are already declared in the generated section. + + virtual void Copy(); + virtual void Cut(); + virtual void Paste(); + + virtual void Undo(); + virtual void Redo(); + + virtual bool CanUndo() const; + virtual bool CanRedo() const; + + */ + + virtual void SetInsertionPoint(long pos) { SetCurrentPos(pos); } + virtual long GetInsertionPoint() const { return GetCurrentPos(); } + virtual long GetLastPosition() const { return GetTextLength(); } + + virtual void SetSelection(long from, long to) + { + if ( from == -1 && to == -1 ) + { + SelectAll(); + } + else + { + SetSelectionStart(from); + SetSelectionEnd(to); + } + } + + virtual void GetSelection(long *from, long *to) const + { + if ( from ) + *from = GetSelectionStart(); + if ( to ) + *to = GetSelectionEnd(); + } + + virtual bool IsEditable() const { return !GetReadOnly(); } + virtual void SetEditable(bool editable) { SetReadOnly(!editable); } + // implement wxTextAreaBase pure virtual methods // --------------------------------------------- @@ -3709,10 +3770,7 @@ public: return true; } - virtual void ShowPosition(long pos) - { - EnsureVisible(LineFromPosition(pos)); - } + virtual void ShowPosition(long pos) { GotoPos(pos); } using wxWindow::HitTest; diff --git a/src/stc/gen_iface.py b/src/stc/gen_iface.py index 7dbc277c21..b4cccc4d3a 100755 --- a/src/stc/gen_iface.py +++ b/src/stc/gen_iface.py @@ -483,9 +483,9 @@ methodOverrideMap = { 'GetText' : (0, - 'wxString %s();', + 'wxString %s() const;', - '''wxString %s() { + '''wxString %s() const { int len = GetTextLength(); wxMemoryBuffer mbuf(len+1); // leave room for the null... char* buf = (char*)mbuf.GetWriteBuf(len+1); @@ -663,6 +663,8 @@ constNonGetterMethods = set(( 'LineFromPosition', 'PositionFromLine', 'LineLength', + 'CanRedo', + 'CanUndo', )) #---------------------------------------------------------------------------- diff --git a/src/stc/stc.cpp b/src/stc/stc.cpp index 1b03a9725c..84b9f6e36b 100644 --- a/src/stc/stc.cpp +++ b/src/stc/stc.cpp @@ -356,7 +356,7 @@ wxMemoryBuffer wxStyledTextCtrl::GetStyledText(int startPos, int endPos) { } // Are there any redoable actions in the undo history? -bool wxStyledTextCtrl::CanRedo() +bool wxStyledTextCtrl::CanRedo() const { return SendMsg(2016, 0, 0) != 0; } @@ -1580,7 +1580,7 @@ bool wxStyledTextCtrl::CanPaste() } // Are there any undoable actions in the undo history? -bool wxStyledTextCtrl::CanUndo() +bool wxStyledTextCtrl::CanUndo() const { return SendMsg(2174, 0, 0) != 0; } @@ -1628,7 +1628,7 @@ void wxStyledTextCtrl::SetText(const wxString& text) } // Retrieve all the text in the document. -wxString wxStyledTextCtrl::GetText() { +wxString wxStyledTextCtrl::GetText() const { int len = GetTextLength(); wxMemoryBuffer mbuf(len+1); // leave room for the null... char* buf = (char*)mbuf.GetWriteBuf(len+1); diff --git a/src/stc/stc.h.in b/src/stc/stc.h.in index 8a6abafc25..003706e370 100644 --- a/src/stc/stc.h.in +++ b/src/stc/stc.h.in @@ -39,6 +39,7 @@ #include "wx/dnd.h" #include "wx/stopwatch.h" +#include "wx/textentry.h" #if wxUSE_TEXTCTRL #include "wx/textctrl.h" #endif // wxUSE_TEXTCTRL @@ -84,6 +85,7 @@ class WXDLLIMPEXP_FWD_STC wxStyledTextEvent; //---------------------------------------------------------------------- class WXDLLIMPEXP_STC wxStyledTextCtrl : public wxControl + , public wxTextEntryBase #if wxUSE_TEXTCTRL , public wxTextAreaBase #endif // wxUSE_TEXTCTRL @@ -286,6 +288,65 @@ public: #endif + // implement wxTextEntryBase pure virtual methods + // ---------------------------------------------- + + virtual void WriteText(const wxString& text) { AddText(text); } + virtual wxString GetValue() const { return GetText(); } + virtual void Remove(long from, long to) + { + Replace(from, to, ""); + } + virtual void Replace(long from, long to, const wxString& text) + { + SetTargetStart(from); + SetTargetEnd(to); + ReplaceTarget(text); + } + + /* + These functions are already declared in the generated section. + + virtual void Copy(); + virtual void Cut(); + virtual void Paste(); + + virtual void Undo(); + virtual void Redo(); + + virtual bool CanUndo() const; + virtual bool CanRedo() const; + + */ + + virtual void SetInsertionPoint(long pos) { SetCurrentPos(pos); } + virtual long GetInsertionPoint() const { return GetCurrentPos(); } + virtual long GetLastPosition() const { return GetTextLength(); } + + virtual void SetSelection(long from, long to) + { + if ( from == -1 && to == -1 ) + { + SelectAll(); + } + else + { + SetSelectionStart(from); + SetSelectionEnd(to); + } + } + + virtual void GetSelection(long *from, long *to) const + { + if ( from ) + *from = GetSelectionStart(); + if ( to ) + *to = GetSelectionEnd(); + } + + virtual bool IsEditable() const { return !GetReadOnly(); } + virtual void SetEditable(bool editable) { SetReadOnly(!editable); } + // implement wxTextAreaBase pure virtual methods // --------------------------------------------- @@ -342,10 +403,7 @@ public: return true; } - virtual void ShowPosition(long pos) - { - EnsureVisible(LineFromPosition(pos)); - } + virtual void ShowPosition(long pos) { GotoPos(pos); } using wxWindow::HitTest; -- 2.45.2