X-Git-Url: https://git.saurik.com/wxWidgets.git/blobdiff_plain/99d800190a04a2deaf769017a5fae04a4ae50378..4e0a055757f928dce8c53b8e4cb60a699ab43e07:/include/wx/textctrl.h diff --git a/include/wx/textctrl.h b/include/wx/textctrl.h index 6471019d16..1314ef112f 100644 --- a/include/wx/textctrl.h +++ b/include/wx/textctrl.h @@ -1,5 +1,5 @@ /////////////////////////////////////////////////////////////////////////////// -// Name: textctrl.h +// Name: wx/textctrl.h // Purpose: wxTextCtrlBase class - the interface of wxTextCtrl // Author: Vadim Zeitlin // Modified by: @@ -16,10 +16,6 @@ // headers // ---------------------------------------------------------------------------- -#if defined(__GNUG__) && !defined(NO_GCC_PRAGMA) - #pragma interface "textctrlbase.h" -#endif - #include "wx/defs.h" #if wxUSE_TEXTCTRL @@ -43,11 +39,6 @@ #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; @@ -66,7 +57,7 @@ typedef long wxTextCoord; // constants // ---------------------------------------------------------------------------- -extern WXDLLEXPORT_DATA(const wxChar*) wxTextCtrlNameStr; +extern WXDLLEXPORT_DATA(const wxChar) wxTextCtrlNameStr[]; // this is intentionally not enum to avoid warning fixes with // typecasting from enum type to wxTextCoord @@ -77,10 +68,6 @@ const wxTextCoord wxInvalidTextCoord = -2; // wxTextCtrl style flags // ---------------------------------------------------------------------------- -// the flag bit 0x0001 s free but should be used only for the things which -// don't make sense for a text control used by wxTextEntryDialog because they -// would otherwise conflict with wxOK, wxCANCEL, wxCENTRE - #define wxTE_NO_VSCROLL 0x0002 #define wxTE_AUTO_SCROLL 0x0008 @@ -120,8 +107,10 @@ const wxTextCoord wxInvalidTextCoord = -2; #define wxTE_WORDWRAP 0x0001 // wrap only at words boundaries #define wxTE_BESTWRAP 0x0000 // this is the default -// obsolete synonym -#define wxTE_LINEWRAP wxTE_CHARWRAP +#if WXWIN_COMPATIBILITY_2_6 + // obsolete synonym + #define wxTE_LINEWRAP wxTE_CHARWRAP +#endif // WXWIN_COMPATIBILITY_2_6 // force using RichEdit version 2.0 or 3.0 instead of 1.0 (default) for // wxTE_RICH controls - can be used together with or instead of wxTE_RICH @@ -134,6 +123,12 @@ const wxTextCoord wxInvalidTextCoord = -2; #define wxTE_CAPITALIZE 0 #endif +// ---------------------------------------------------------------------------- +// wxTextCtrl file types +// ---------------------------------------------------------------------------- + +#define wxTEXT_TYPE_ANY 0 + // ---------------------------------------------------------------------------- // wxTextCtrl::HitTest return values // ---------------------------------------------------------------------------- @@ -175,7 +170,8 @@ enum wxTextAttrAlignment #define wxTEXT_ATTR_FONT_ITALIC 0x0020 #define wxTEXT_ATTR_FONT_UNDERLINE 0x0040 #define wxTEXT_ATTR_FONT \ - wxTEXT_ATTR_FONT_FACE | wxTEXT_ATTR_FONT_SIZE | wxTEXT_ATTR_FONT_WEIGHT | wxTEXT_ATTR_FONT_ITALIC | wxTEXT_ATTR_FONT_UNDERLINE + ( wxTEXT_ATTR_FONT_FACE | wxTEXT_ATTR_FONT_SIZE | wxTEXT_ATTR_FONT_WEIGHT | \ + wxTEXT_ATTR_FONT_ITALIC | wxTEXT_ATTR_FONT_UNDERLINE ) #define wxTEXT_ATTR_ALIGNMENT 0x0080 #define wxTEXT_ATTR_LEFT_INDENT 0x0100 #define wxTEXT_ATTR_RIGHT_INDENT 0x0200 @@ -198,6 +194,22 @@ public: // operations void Init(); + // merges the attributes of the base and the overlay objects and returns + // the result; the parameter attributes take precedence + // + // WARNING: the order of arguments is the opposite of Combine() + static wxTextAttr Merge(const wxTextAttr& base, const wxTextAttr& overlay) + { + return Combine(overlay, base, NULL); + } + + // merges the attributes of this object and overlay + void Merge(const wxTextAttr& overlay) + { + *this = Merge(*this, overlay); + } + + // operators void operator= (const wxTextAttr& attr); @@ -275,13 +287,18 @@ public: // -------- wxTextCtrlBase(){} - ~wxTextCtrlBase(){} + virtual ~wxTextCtrlBase(){} // accessors // --------- virtual wxString GetValue() const = 0; - virtual void SetValue(const wxString& value) = 0; + virtual bool IsEmpty() const { return GetValue().empty(); } + + virtual void SetValue(const wxString& value) + { DoSetValue(value, SetValue_SendEvent); } + virtual void ChangeValue(const wxString& value) + { DoSetValue(value); } virtual wxString GetRange(long from, long to) const; @@ -309,13 +326,24 @@ public: virtual void Replace(long from, long to, const wxString& value) = 0; virtual void Remove(long from, long to) = 0; - // load/save the controls contents from/to the file - virtual bool LoadFile(const wxString& file); - virtual bool SaveFile(const wxString& file = wxEmptyString); + // 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); // sets/clears the dirty flag virtual void MarkDirty() = 0; virtual void DiscardEdits() = 0; + void SetModified(bool modified) + { + if ( modified ) + MarkDirty(); + else + DiscardEdits(); + } // set the max number of characters which may be entered in a single line // text control @@ -381,11 +409,6 @@ public: virtual void SelectAll(); virtual void SetEditable(bool editable) = 0; - // override streambuf method -#if wxHAS_TEXT_WINDOW_STREAM - int overflow(int i); -#endif // wxHAS_TEXT_WINDOW_STREAM - // stream-like insertion operators: these are always available, whether we // were, or not, compiled with streambuf support wxTextCtrl& operator<<(const wxString& s); @@ -395,12 +418,31 @@ public: wxTextCtrl& operator<<(double d); wxTextCtrl& operator<<(const wxChar c); + // generate the wxEVT_COMMAND_TEXT_UPDATED event, like SetValue() does + void SendTextUpdatedEvent(); + // do the window-specific processing after processing the update event virtual void DoUpdateWindowUI(wxUpdateUIEvent& event); virtual bool ShouldInheritColours() const { return false; } protected: + // override streambuf method +#if wxHAS_TEXT_WINDOW_STREAM + int overflow(int i); +#endif // wxHAS_TEXT_WINDOW_STREAM + + // flags for DoSetValue(): common part of SetValue() and ChangeValue() and + // also used to implement WriteText() in wxMSW + enum + { + SetValue_SendEvent = 1, + SetValue_SelectionOnly = 2 + }; + + virtual void DoSetValue(const wxString& value, int flags = 0) = 0; + + // the name of the last file loaded with LoadFile() which will be used by // SaveFile() by default wxString m_filename; @@ -409,6 +451,7 @@ protected: wxTextAttr m_defaultStyle; DECLARE_NO_COPY_CLASS(wxTextCtrlBase) + DECLARE_ABSTRACT_CLASS(wxTextCtrlBase) }; // ---------------------------------------------------------------------------- @@ -425,8 +468,10 @@ protected: #include "wx/msw/textctrl.h" #elif defined(__WXMOTIF__) #include "wx/motif/textctrl.h" -#elif defined(__WXGTK__) +#elif defined(__WXGTK20__) #include "wx/gtk/textctrl.h" +#elif defined(__WXGTK__) + #include "wx/gtk1/textctrl.h" #elif defined(__WXMAC__) #include "wx/mac/textctrl.h" #elif defined(__WXCOCOA__)