1 ///////////////////////////////////////////////////////////////////////////////
3 // Purpose: wxTextCtrlBase class - the interface of wxTextCtrl
4 // Author: Vadim Zeitlin
8 // Copyright: (c) wxWindows team
9 // Licence: wxWindows licence
10 ///////////////////////////////////////////////////////////////////////////////
12 #ifndef _WX_TEXTCTRL_H_BASE_
13 #define _WX_TEXTCTRL_H_BASE_
15 // ----------------------------------------------------------------------------
17 // ----------------------------------------------------------------------------
20 #pragma interface "textctrlbase.h"
24 #include "wx/control.h" // the base class
26 // 16-bit Borland 4.0 doesn't seem to allow multiple inheritance with wxWindow
27 // and streambuf: it complains about deriving a huge class from the huge class
28 // streambuf. !! Also, can't use streambuf if making or using a DLL :-(
30 #if (defined(__BORLANDC__)) || defined(__MWERKS__) || defined(_WINDLL) || defined(WXUSINGDLL) || defined(WXMAKINGDLL)
31 #define NO_TEXT_WINDOW_STREAM
34 // the streambuf which is used in the declaration of wxTextCtrlBase below is not compatible
35 // with the standard-conforming implementation found in newer egcs versions
36 // (that is, the libstdc++ v3 that is shipped with it)
37 #if defined(__GNUC__)&&( (__GNUC__>2) ||( (__GNUC__==2)&&(__GNUC_MINOR__>97) ) )
38 #define NO_TEXT_WINDOW_STREAM
41 #ifndef NO_TEXT_WINDOW_STREAM
42 #if wxUSE_STD_IOSTREAM
43 #include "wx/ioswrap.h" // for iostream classes if we need them
44 #else // !wxUSE_STD_IOSTREAM
45 // can't compile this feature in if we don't use streams at all
46 #define NO_TEXT_WINDOW_STREAM
47 #endif // wxUSE_STD_IOSTREAM/!wxUSE_STD_IOSTREAM
50 class WXDLLEXPORT wxTextCtrl
;
52 // ----------------------------------------------------------------------------
54 // ----------------------------------------------------------------------------
56 WXDLLEXPORT_DATA(extern const wxChar
*) wxTextCtrlNameStr
;
57 WXDLLEXPORT_DATA(extern const wxChar
*) wxEmptyString
;
59 // ----------------------------------------------------------------------------
60 // wxTextAttr: a structure containing the visual attributes of a text
61 // ----------------------------------------------------------------------------
63 class WXDLLEXPORT wxTextAttr
68 wxTextAttr(const wxColour
& colText
,
69 const wxColour
& colBack
= wxNullColour
,
70 const wxFont
& font
= wxNullFont
)
71 : m_colText(colText
), m_colBack(colBack
), m_font(font
) { }
74 void SetTextColour(const wxColour
& colText
) { m_colText
= colText
; }
75 void SetBackgroundColour(const wxColour
& colBack
) { m_colBack
= colBack
; }
76 void SetFont(const wxFont
& font
) { m_font
= font
; }
79 bool HasTextColour() const { return m_colText
.Ok(); }
80 bool HasBackgroundColour() const { return m_colBack
.Ok(); }
81 bool HasFont() const { return m_font
.Ok(); }
84 const wxColour
& GetTextColour() const { return m_colText
; }
85 const wxColour
& GetBackgroundColour() const { return m_colBack
; }
86 const wxFont
& GetFont() const { return m_font
; }
88 // returns false if we have any attributes set, true otherwise
89 bool IsDefault() const
91 return !HasTextColour() && !HasBackgroundColour() && !HasFont();
100 // ----------------------------------------------------------------------------
101 // wxTextCtrl: a single or multiple line text zone where user can enter and
103 // ----------------------------------------------------------------------------
105 class WXDLLEXPORT wxTextCtrlBase
: public wxControl
106 #ifndef NO_TEXT_WINDOW_STREAM
121 virtual wxString
GetValue() const = 0;
122 virtual void SetValue(const wxString
& value
) = 0;
124 virtual int GetLineLength(long lineNo
) const = 0;
125 virtual wxString
GetLineText(long lineNo
) const = 0;
126 virtual int GetNumberOfLines() const = 0;
128 virtual bool IsModified() const = 0;
129 virtual bool IsEditable() const = 0;
131 // If the return values from and to are the same, there is no selection.
132 virtual void GetSelection(long* from
, long* to
) const = 0;
138 virtual void Clear() = 0;
139 virtual void Replace(long from
, long to
, const wxString
& value
) = 0;
140 virtual void Remove(long from
, long to
) = 0;
142 // load/save the controls contents from/to the file
143 virtual bool LoadFile(const wxString
& file
);
144 virtual bool SaveFile(const wxString
& file
= wxEmptyString
);
146 // clears the dirty flag
147 virtual void DiscardEdits() = 0;
149 // writing text inserts it at the current position, appending always
150 // inserts it at the end
151 virtual void WriteText(const wxString
& text
) = 0;
152 virtual void AppendText(const wxString
& text
) = 0;
154 // text control under some platforms supports the text styles: these
155 // methods allow to apply the given text style to the given selection or to
156 // set/get the style which will be used for all appended text
157 virtual bool SetStyle(long start
, long end
, const wxTextAttr
& style
);
158 virtual bool SetDefaultStyle(const wxTextAttr
& style
);
159 virtual const wxTextAttr
& GetDefaultStyle() const;
161 // translate between the position (which is just an index in the text ctrl
162 // considering all its contents as a single strings) and (x, y) coordinates
163 // which represent column and line.
164 virtual long XYToPosition(long x
, long y
) const = 0;
165 virtual bool PositionToXY(long pos
, long *x
, long *y
) const = 0;
167 virtual void ShowPosition(long pos
) = 0;
169 // Clipboard operations
170 virtual void Copy() = 0;
171 virtual void Cut() = 0;
172 virtual void Paste() = 0;
174 virtual bool CanCopy() const = 0;
175 virtual bool CanCut() const = 0;
176 virtual bool CanPaste() const = 0;
179 virtual void Undo() = 0;
180 virtual void Redo() = 0;
182 virtual bool CanUndo() const = 0;
183 virtual bool CanRedo() const = 0;
186 virtual void SetInsertionPoint(long pos
) = 0;
187 virtual void SetInsertionPointEnd() = 0;
188 virtual long GetInsertionPoint() const = 0;
189 virtual long GetLastPosition() const = 0;
191 virtual void SetSelection(long from
, long to
) = 0;
192 virtual void SetEditable(bool editable
) = 0;
195 #ifndef NO_TEXT_WINDOW_STREAM
199 #endif // NO_TEXT_WINDOW_STREAM
201 // stream-like insertion operators: these are always available, whether we
202 // were, or not, compiled with streambuf support
203 wxTextCtrl
& operator<<(const wxString
& s
);
204 wxTextCtrl
& operator<<(int i
);
205 wxTextCtrl
& operator<<(long i
);
206 wxTextCtrl
& operator<<(float f
);
207 wxTextCtrl
& operator<<(double d
);
208 wxTextCtrl
& operator<<(const wxChar c
);
210 // obsolete functions
211 #if WXWIN_COMPATIBILITY
212 bool Modified() const { return IsModified(); }
216 // the name of the last file loaded with LoadFile() which will be used by
217 // SaveFile() by default
220 // the text style which will be used for any new text added to the control
221 wxTextAttr m_defaultStyle
;
224 #ifndef NO_TEXT_WINDOW_STREAM
231 // ----------------------------------------------------------------------------
232 // include the platform-dependent class definition
233 // ----------------------------------------------------------------------------
235 #if defined(__WXMSW__)
236 #include "wx/msw/textctrl.h"
237 #elif defined(__WXMOTIF__)
238 #include "wx/motif/textctrl.h"
239 #elif defined(__WXGTK__)
240 #include "wx/gtk/textctrl.h"
241 #elif defined(__WXQT__)
242 #include "wx/qt/textctrl.h"
243 #elif defined(__WXMAC__)
244 #include "wx/mac/textctrl.h"
245 #elif defined(__WXPM__)
246 #include "wx/os2/textctrl.h"
247 #elif defined(__WXSTUBS__)
248 #include "wx/stubs/textctrl.h"
252 // _WX_TEXTCTRL_H_BASE_