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"
27 #include "wx/control.h" // the base class
29 // 16-bit Borland 4.0 doesn't seem to allow multiple inheritance with wxWindow
30 // and streambuf: it complains about deriving a huge class from the huge class
31 // streambuf. !! Also, can't use streambuf if making or using a DLL :-(
33 #if (defined(__BORLANDC__)) || defined(__MWERKS__) || defined(_WINDLL) || defined(WXUSINGDLL) || defined(WXMAKINGDLL)
34 #define NO_TEXT_WINDOW_STREAM
37 // the streambuf which is used in the declaration of wxTextCtrlBase below is not compatible
38 // with the standard-conforming implementation found in newer egcs versions
39 // (that is, the libstdc++ v3 that is shipped with it)
40 #if defined(__GNUC__)&&( (__GNUC__>2) ||( (__GNUC__==2)&&(__GNUC_MINOR__>97) ) )
41 #define NO_TEXT_WINDOW_STREAM
44 #ifndef NO_TEXT_WINDOW_STREAM
45 #if wxUSE_STD_IOSTREAM
46 #include "wx/ioswrap.h" // for iostream classes if we need them
47 #else // !wxUSE_STD_IOSTREAM
48 // can't compile this feature in if we don't use streams at all
49 #define NO_TEXT_WINDOW_STREAM
50 #endif // wxUSE_STD_IOSTREAM/!wxUSE_STD_IOSTREAM
53 class WXDLLEXPORT wxTextCtrl
;
55 // ----------------------------------------------------------------------------
57 // ----------------------------------------------------------------------------
59 WXDLLEXPORT_DATA(extern const wxChar
*) wxTextCtrlNameStr
;
60 WXDLLEXPORT_DATA(extern const wxChar
*) wxEmptyString
;
62 // ----------------------------------------------------------------------------
63 // wxTextAttr: a structure containing the visual attributes of a text
64 // ----------------------------------------------------------------------------
66 class WXDLLEXPORT wxTextAttr
71 wxTextAttr(const wxColour
& colText
,
72 const wxColour
& colBack
= wxNullColour
,
73 const wxFont
& font
= wxNullFont
)
74 : m_colText(colText
), m_colBack(colBack
), m_font(font
) { }
77 void SetTextColour(const wxColour
& colText
) { m_colText
= colText
; }
78 void SetBackgroundColour(const wxColour
& colBack
) { m_colBack
= colBack
; }
79 void SetFont(const wxFont
& font
) { m_font
= font
; }
82 bool HasTextColour() const { return m_colText
.Ok(); }
83 bool HasBackgroundColour() const { return m_colBack
.Ok(); }
84 bool HasFont() const { return m_font
.Ok(); }
87 const wxColour
& GetTextColour() const { return m_colText
; }
88 const wxColour
& GetBackgroundColour() const { return m_colBack
; }
89 const wxFont
& GetFont() const { return m_font
; }
91 // returns false if we have any attributes set, true otherwise
92 bool IsDefault() const
94 return !HasTextColour() && !HasBackgroundColour() && !HasFont();
103 // ----------------------------------------------------------------------------
104 // wxTextCtrl: a single or multiple line text zone where user can enter and
106 // ----------------------------------------------------------------------------
108 class WXDLLEXPORT wxTextCtrlBase
: public wxControl
109 #ifndef NO_TEXT_WINDOW_STREAM
124 virtual wxString
GetValue() const = 0;
125 virtual void SetValue(const wxString
& value
) = 0;
127 virtual int GetLineLength(long lineNo
) const = 0;
128 virtual wxString
GetLineText(long lineNo
) const = 0;
129 virtual int GetNumberOfLines() const = 0;
131 virtual bool IsModified() const = 0;
132 virtual bool IsEditable() const = 0;
134 // If the return values from and to are the same, there is no selection.
135 virtual void GetSelection(long* from
, long* to
) const = 0;
141 virtual void Clear() = 0;
142 virtual void Replace(long from
, long to
, const wxString
& value
) = 0;
143 virtual void Remove(long from
, long to
) = 0;
145 // load/save the controls contents from/to the file
146 virtual bool LoadFile(const wxString
& file
);
147 virtual bool SaveFile(const wxString
& file
= wxEmptyString
);
149 // clears the dirty flag
150 virtual void DiscardEdits() = 0;
152 // writing text inserts it at the current position, appending always
153 // inserts it at the end
154 virtual void WriteText(const wxString
& text
) = 0;
155 virtual void AppendText(const wxString
& text
) = 0;
157 // text control under some platforms supports the text styles: these
158 // methods allow to apply the given text style to the given selection or to
159 // set/get the style which will be used for all appended text
160 virtual bool SetStyle(long start
, long end
, const wxTextAttr
& style
);
161 virtual bool SetDefaultStyle(const wxTextAttr
& style
);
162 virtual const wxTextAttr
& GetDefaultStyle() const;
164 // translate between the position (which is just an index in the text ctrl
165 // considering all its contents as a single strings) and (x, y) coordinates
166 // which represent column and line.
167 virtual long XYToPosition(long x
, long y
) const = 0;
168 virtual bool PositionToXY(long pos
, long *x
, long *y
) const = 0;
170 virtual void ShowPosition(long pos
) = 0;
172 // Clipboard operations
173 virtual void Copy() = 0;
174 virtual void Cut() = 0;
175 virtual void Paste() = 0;
177 virtual bool CanCopy() const;
178 virtual bool CanCut() const;
179 virtual bool CanPaste() const;
182 virtual void Undo() = 0;
183 virtual void Redo() = 0;
185 virtual bool CanUndo() const = 0;
186 virtual bool CanRedo() const = 0;
189 virtual void SetInsertionPoint(long pos
) = 0;
190 virtual void SetInsertionPointEnd() = 0;
191 virtual long GetInsertionPoint() const = 0;
192 virtual long GetLastPosition() const = 0;
194 virtual void SetSelection(long from
, long to
) = 0;
195 virtual void SelectAll();
196 virtual void SetEditable(bool editable
) = 0;
199 #ifndef NO_TEXT_WINDOW_STREAM
203 #endif // NO_TEXT_WINDOW_STREAM
205 // stream-like insertion operators: these are always available, whether we
206 // were, or not, compiled with streambuf support
207 wxTextCtrl
& operator<<(const wxString
& s
);
208 wxTextCtrl
& operator<<(int i
);
209 wxTextCtrl
& operator<<(long i
);
210 wxTextCtrl
& operator<<(float f
);
211 wxTextCtrl
& operator<<(double d
);
212 wxTextCtrl
& operator<<(const wxChar c
);
214 // obsolete functions
215 #if WXWIN_COMPATIBILITY
216 bool Modified() const { return IsModified(); }
220 // the name of the last file loaded with LoadFile() which will be used by
221 // SaveFile() by default
224 // the text style which will be used for any new text added to the control
225 wxTextAttr m_defaultStyle
;
228 #ifndef NO_TEXT_WINDOW_STREAM
235 // ----------------------------------------------------------------------------
236 // include the platform-dependent class definition
237 // ----------------------------------------------------------------------------
239 #if defined(__WXUNIVERSAL__)
240 #include "wx/univ/textctrl.h"
241 #elif defined(__WXMSW__)
242 #include "wx/msw/textctrl.h"
243 #elif defined(__WXMOTIF__)
244 #include "wx/motif/textctrl.h"
245 #elif defined(__WXGTK__)
246 #include "wx/gtk/textctrl.h"
247 #elif defined(__WXQT__)
248 #include "wx/qt/textctrl.h"
249 #elif defined(__WXMAC__)
250 #include "wx/mac/textctrl.h"
251 #elif defined(__WXPM__)
252 #include "wx/os2/textctrl.h"
253 #elif defined(__WXSTUBS__)
254 #include "wx/stubs/textctrl.h"
257 #endif // wxUSE_TEXTCTRL
260 // _WX_TEXTCTRL_H_BASE_