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(); }
83 const wxColour
& GetTextColour() const { return m_colText
; }
84 const wxColour
& GetBackgroundColour() const { return m_colBack
; }
85 const wxFont
& GetFont() const { return m_font
; }
93 // ----------------------------------------------------------------------------
94 // wxTextCtrl: a single or multiple line text zone where user can enter and
96 // ----------------------------------------------------------------------------
98 class WXDLLEXPORT wxTextCtrlBase
: public wxControl
99 #ifndef NO_TEXT_WINDOW_STREAM
114 virtual wxString
GetValue() const = 0;
115 virtual void SetValue(const wxString
& value
) = 0;
117 virtual int GetLineLength(long lineNo
) const = 0;
118 virtual wxString
GetLineText(long lineNo
) const = 0;
119 virtual int GetNumberOfLines() const = 0;
121 virtual bool IsModified() const = 0;
122 virtual bool IsEditable() const = 0;
124 // If the return values from and to are the same, there is no selection.
125 virtual void GetSelection(long* from
, long* to
) const = 0;
131 virtual void Clear() = 0;
132 virtual void Replace(long from
, long to
, const wxString
& value
) = 0;
133 virtual void Remove(long from
, long to
) = 0;
135 // load/save the controls contents from/to the file
136 virtual bool LoadFile(const wxString
& file
);
137 virtual bool SaveFile(const wxString
& file
= wxEmptyString
);
139 // clears the dirty flag
140 virtual void DiscardEdits() = 0;
142 // writing text inserts it at the current position, appending always
143 // inserts it at the end
144 virtual void WriteText(const wxString
& text
) = 0;
145 virtual void AppendText(const wxString
& text
) = 0;
147 // text control under some platforms supports the text styles: these
148 // methods allow to apply the given text style to the given selection or to
149 // set/get the style which will be used for all appended text
150 virtual bool SetStyle(long start
, long end
, const wxTextAttr
& style
);
151 virtual bool SetDefaultStyle(const wxTextAttr
& style
);
152 virtual const wxTextAttr
& GetDefaultStyle() const;
154 // translate between the position (which is just an index in the text ctrl
155 // considering all its contents as a single strings) and (x, y) coordinates
156 // which represent column and line.
157 virtual long XYToPosition(long x
, long y
) const = 0;
158 virtual bool PositionToXY(long pos
, long *x
, long *y
) const = 0;
160 virtual void ShowPosition(long pos
) = 0;
162 // Clipboard operations
163 virtual void Copy() = 0;
164 virtual void Cut() = 0;
165 virtual void Paste() = 0;
167 virtual bool CanCopy() const = 0;
168 virtual bool CanCut() const = 0;
169 virtual bool CanPaste() const = 0;
172 virtual void Undo() = 0;
173 virtual void Redo() = 0;
175 virtual bool CanUndo() const = 0;
176 virtual bool CanRedo() const = 0;
179 virtual void SetInsertionPoint(long pos
) = 0;
180 virtual void SetInsertionPointEnd() = 0;
181 virtual long GetInsertionPoint() const = 0;
182 virtual long GetLastPosition() const = 0;
184 virtual void SetSelection(long from
, long to
) = 0;
185 virtual void SetEditable(bool editable
) = 0;
188 #ifndef NO_TEXT_WINDOW_STREAM
192 #endif // NO_TEXT_WINDOW_STREAM
194 // stream-like insertion operators: these are always available, whether we
195 // were, or not, compiled with streambuf support
196 wxTextCtrl
& operator<<(const wxString
& s
);
197 wxTextCtrl
& operator<<(int i
);
198 wxTextCtrl
& operator<<(long i
);
199 wxTextCtrl
& operator<<(float f
);
200 wxTextCtrl
& operator<<(double d
);
201 wxTextCtrl
& operator<<(const wxChar c
);
203 // obsolete functions
204 #if WXWIN_COMPATIBILITY
205 bool Modified() const { return IsModified(); }
209 // the name of the last file loaded with LoadFile() which will be used by
210 // SaveFile() by default
213 // the text style which will be used for any new text added to the control
214 wxTextAttr m_defaultStyle
;
217 #ifndef NO_TEXT_WINDOW_STREAM
224 // ----------------------------------------------------------------------------
225 // include the platform-dependent class definition
226 // ----------------------------------------------------------------------------
228 #if defined(__WXMSW__)
229 #include "wx/msw/textctrl.h"
230 #elif defined(__WXMOTIF__)
231 #include "wx/motif/textctrl.h"
232 #elif defined(__WXGTK__)
233 #include "wx/gtk/textctrl.h"
234 #elif defined(__WXQT__)
235 #include "wx/qt/textctrl.h"
236 #elif defined(__WXMAC__)
237 #include "wx/mac/textctrl.h"
238 #elif defined(__WXPM__)
239 #include "wx/os2/textctrl.h"
240 #elif defined(__WXSTUBS__)
241 #include "wx/stubs/textctrl.h"
245 // _WX_TEXTCTRL_H_BASE_