X-Git-Url: https://git.saurik.com/wxWidgets.git/blobdiff_plain/3306aec1240b38347abda1ad776df32b6687ad01..3115bfa8a41372ecfd505f22c6a0eb9abc2bc96b:/include/wx/textctrl.h?ds=sidebyside diff --git a/include/wx/textctrl.h b/include/wx/textctrl.h index 204c28b7df..7c8be51720 100644 --- a/include/wx/textctrl.h +++ b/include/wx/textctrl.h @@ -21,6 +21,7 @@ #if wxUSE_TEXTCTRL #include "wx/control.h" // the base class +#include "wx/textentry.h" // single-line text entry interface #include "wx/dynarray.h" // wxArrayInt #include "wx/gdicmn.h" // wxPoint @@ -39,21 +40,13 @@ #define wxHAS_TEXT_WINDOW_STREAM 0 #endif -#if WXWIN_COMPATIBILITY_2_4 && !wxHAS_TEXT_WINDOW_STREAM - // define old flag if one could use it somewhere - #define NO_TEXT_WINDOW_STREAM -#endif - -class WXDLLEXPORT wxTextCtrl; -class WXDLLEXPORT wxTextCtrlBase; +class WXDLLIMPEXP_FWD_CORE wxTextCtrl; +class WXDLLIMPEXP_FWD_CORE wxTextCtrlBase; // ---------------------------------------------------------------------------- // wxTextCtrl types // ---------------------------------------------------------------------------- -// wxTextPos is the position in the text -typedef long wxTextPos; - // wxTextCoord is the line or row number (which should have been unsigned but // is long for backwards compatibility) typedef long wxTextCoord; @@ -277,64 +270,35 @@ private: }; // ---------------------------------------------------------------------------- -// wxTextCtrl: a single or multiple line text zone where user can enter and -// edit text +// wxTextAreaBase: multiline text control specific methods // ---------------------------------------------------------------------------- -class WXDLLEXPORT wxTextCtrlBase : public wxControl -#if wxHAS_TEXT_WINDOW_STREAM - , public wxSTD streambuf -#endif - +class WXDLLIMPEXP_CORE wxTextAreaBase { public: - // creation - // -------- - - wxTextCtrlBase(){} - virtual ~wxTextCtrlBase(){} - - // accessors - // --------- + wxTextAreaBase() { } + virtual ~wxTextAreaBase() { } - virtual wxString GetValue() const = 0; - virtual void SetValue(const wxString& value) = 0; - - virtual wxString GetRange(long from, long to) const; + // lines access + // ------------ virtual int GetLineLength(long lineNo) const = 0; virtual wxString GetLineText(long lineNo) const = 0; virtual int GetNumberOfLines() const = 0; - virtual bool IsModified() const = 0; - virtual bool IsEditable() const = 0; - - // more readable flag testing methods - bool IsSingleLine() const { return !HasFlag(wxTE_MULTILINE); } - bool IsMultiLine() const { return !IsSingleLine(); } - // If the return values from and to are the same, there is no selection. - virtual void GetSelection(long* from, long* to) const = 0; + // file IO + // ------- - virtual wxString GetStringSelection() const; + bool LoadFile(const wxString& file, int fileType = wxTEXT_TYPE_ANY) + { return DoLoadFile(file, fileType); } + bool SaveFile(const wxString& file = wxEmptyString, + int fileType = wxTEXT_TYPE_ANY); - // operations - // ---------- - - // editing - virtual void Clear() = 0; - virtual void Replace(long from, long to, const wxString& value) = 0; - virtual void Remove(long from, long to) = 0; - - // load/save the control's contents from/to a file - bool LoadFile(const wxString& file, int fileType = wxTEXT_TYPE_ANY) { return DoLoadFile(file, fileType); } - bool SaveFile(const wxString& file = wxEmptyString, int fileType = wxTEXT_TYPE_ANY); - - // implementation for loading/saving - virtual bool DoLoadFile(const wxString& file, int fileType); - virtual bool DoSaveFile(const wxString& file, int fileType); + // dirty flag handling + // ------------------- - // sets/clears the dirty flag + virtual bool IsModified() const = 0; virtual void MarkDirty() = 0; virtual void DiscardEdits() = 0; void SetModified(bool modified) @@ -345,26 +309,21 @@ public: DiscardEdits(); } - // set the max number of characters which may be entered in a single line - // text control - virtual void SetMaxLength(unsigned long WXUNUSED(len)) { } - - // writing text inserts it at the current position, appending always - // inserts it at the end - virtual void WriteText(const wxString& text) = 0; - virtual void AppendText(const wxString& text) = 0; - // insert the character which would have resulted from this key event, - // return true if anything has been inserted - virtual bool EmulateKeyPress(const wxKeyEvent& event); + // styles handling + // --------------- // text control under some platforms supports the text styles: these // methods allow to apply the given text style to the given selection or to // set/get the style which will be used for all appended text - virtual bool SetStyle(long start, long end, const wxTextAttr& style); - virtual bool GetStyle(long position, wxTextAttr& style); - virtual bool SetDefaultStyle(const wxTextAttr& style); - virtual const wxTextAttr& GetDefaultStyle() const; + virtual bool SetStyle(long start, long end, const wxTextAttr& style) = 0; + virtual bool GetStyle(long position, wxTextAttr& style) = 0; + virtual bool SetDefaultStyle(const wxTextAttr& style) = 0; + virtual const wxTextAttr& GetDefaultStyle() const { return m_defaultStyle; } + + + // coordinates translation + // ----------------------- // translate between the position (which is just an index in the text ctrl // considering all its contents as a single strings) and (x, y) coordinates @@ -383,31 +342,60 @@ public: wxTextCoord *col, wxTextCoord *row) const; - // Clipboard operations - virtual void Copy() = 0; - virtual void Cut() = 0; - virtual void Paste() = 0; +protected: + // implementation of loading/saving + virtual bool DoLoadFile(const wxString& file, int fileType) = 0; + virtual bool DoSaveFile(const wxString& file, int fileType) = 0; - virtual bool CanCopy() const; - virtual bool CanCut() const; - virtual bool CanPaste() const; - // Undo/redo - virtual void Undo() = 0; - virtual void Redo() = 0; + // the name of the last file loaded with LoadFile() which will be used by + // SaveFile() by default + wxString m_filename; - virtual bool CanUndo() const = 0; - virtual bool CanRedo() const = 0; + // the text style which will be used for any new text added to the control + wxTextAttr m_defaultStyle; - // Insertion point - virtual void SetInsertionPoint(long pos) = 0; - virtual void SetInsertionPointEnd() = 0; - virtual long GetInsertionPoint() const = 0; - virtual wxTextPos GetLastPosition() const = 0; - virtual void SetSelection(long from, long to) = 0; - virtual void SelectAll(); - virtual void SetEditable(bool editable) = 0; + DECLARE_NO_COPY_CLASS(wxTextAreaBase) +}; + +// this class defines wxTextCtrl interface, wxTextCtrlBase actually implements +// too much things because it derives from wxTextEntry and not wxTextEntryBase +// and so any classes which "look like" wxTextCtrl (such as wxRichTextCtrl) +// but don't need the (native) implementation bits from wxTextEntry should +// actually derive from this one and not wxTextCtrlBase +class WXDLLIMPEXP_CORE wxTextCtrlIface : public wxTextAreaBase, + public wxTextEntryBase +{ +public: + wxTextCtrlIface() { } + +private: + DECLARE_NO_COPY_CLASS(wxTextCtrlIface) +}; + +// ---------------------------------------------------------------------------- +// wxTextCtrl: a single or multiple line text zone where user can edit text +// ---------------------------------------------------------------------------- + +class WXDLLEXPORT wxTextCtrlBase : public wxControl, +#if wxHAS_TEXT_WINDOW_STREAM + public wxSTD streambuf, +#endif + public wxTextAreaBase, + public wxTextEntry +{ +public: + // creation + // -------- + + wxTextCtrlBase() { } + virtual ~wxTextCtrlBase() { } + + + // more readable flag testing methods + bool IsSingleLine() const { return !HasFlag(wxTE_MULTILINE); } + bool IsMultiLine() const { return !IsSingleLine(); } // stream-like insertion operators: these are always available, whether we // were, or not, compiled with streambuf support @@ -418,23 +406,50 @@ public: wxTextCtrl& operator<<(double d); wxTextCtrl& operator<<(const wxChar c); + // insert the character which would have resulted from this key event, + // return true if anything has been inserted + virtual bool EmulateKeyPress(const wxKeyEvent& event); + + + // generate the wxEVT_COMMAND_TEXT_UPDATED event, like SetValue() does and + // return true if the event was processed + static bool SendTextUpdatedEvent(wxWindow *win); + bool SendTextUpdatedEvent() { return SendTextUpdatedEvent(this); } + // do the window-specific processing after processing the update event virtual void DoUpdateWindowUI(wxUpdateUIEvent& event); virtual bool ShouldInheritColours() const { return false; } + // work around the problem with having HitTest() both in wxControl and + // wxTextAreaBase base classes + virtual wxTextCtrlHitTestResult HitTest(const wxPoint& pt, long *pos) const + { + return wxTextAreaBase::HitTest(pt, pos); + } + + virtual wxTextCtrlHitTestResult HitTest(const wxPoint& pt, + wxTextCoord *col, + wxTextCoord *row) const + { + return wxTextAreaBase::HitTest(pt, col, row); + } + + // we provide stubs for these functions as not all platforms have styles + // support, but we really should leave them pure virtual here + virtual bool SetStyle(long start, long end, const wxTextAttr& style); + virtual bool GetStyle(long position, wxTextAttr& style); + virtual bool SetDefaultStyle(const wxTextAttr& style); + protected: // override streambuf method #if wxHAS_TEXT_WINDOW_STREAM int overflow(int i); #endif // wxHAS_TEXT_WINDOW_STREAM - // the name of the last file loaded with LoadFile() which will be used by - // SaveFile() by default - wxString m_filename; + virtual bool DoLoadFile(const wxString& file, int fileType); + virtual bool DoSaveFile(const wxString& file, int fileType); - // the text style which will be used for any new text added to the control - wxTextAttr m_defaultStyle; DECLARE_NO_COPY_CLASS(wxTextCtrlBase) DECLARE_ABSTRACT_CLASS(wxTextCtrlBase)