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 #ifndef NO_TEXT_WINDOW_STREAM
35 #if wxUSE_STD_IOSTREAM
36 #include "wx/ioswrap.h" // for iostream classes if we need them
37 #else // !wxUSE_STD_IOSTREAM
38 // can't compile this feature in if we don't use streams at all
39 #define NO_TEXT_WINDOW_STREAM
40 #endif // wxUSE_STD_IOSTREAM/!wxUSE_STD_IOSTREAM
43 class WXDLLEXPORT wxTextCtrl
;
45 // ----------------------------------------------------------------------------
47 // ----------------------------------------------------------------------------
49 WXDLLEXPORT_DATA(extern const wxChar
*) wxTextCtrlNameStr
;
50 WXDLLEXPORT_DATA(extern const wxChar
*) wxEmptyString
;
52 // ----------------------------------------------------------------------------
53 // wxTextAttr: a structure containing the visual attributes of a text
54 // ----------------------------------------------------------------------------
56 class WXDLLEXPORT wxTextAttr
61 wxTextAttr(const wxColour
& colText
,
62 const wxColour
& colBack
= wxNullColour
,
63 const wxFont
& font
= wxNullFont
)
64 : m_colText(colText
), m_colBack(colBack
), m_font(font
) { }
67 void SetTextColour(const wxColour
& colText
) { m_colText
= colText
; }
68 void SetBackgroundColour(const wxColour
& colBack
) { m_colBack
= colBack
; }
69 void SetFont(const wxFont
& font
) { m_font
= font
; }
72 bool HasTextColour() const { return m_colText
.Ok(); }
73 bool HasBackgroundColour() const { return m_colBack
.Ok(); }
74 bool HasFont() const { return m_font
.Ok(); }
76 const wxColour
& GetTextColour() const { return m_colText
; }
77 const wxColour
& GetBackgroundColour() const { return m_colBack
; }
78 const wxFont
& GetFont() const { return m_font
; }
86 // ----------------------------------------------------------------------------
87 // wxTextCtrl: a single or multiple line text zone where user can enter and
89 // ----------------------------------------------------------------------------
91 class WXDLLEXPORT wxTextCtrlBase
: public wxControl
92 #ifndef NO_TEXT_WINDOW_STREAM
107 virtual wxString
GetValue() const = 0;
108 virtual void SetValue(const wxString
& value
) = 0;
110 virtual int GetLineLength(long lineNo
) const = 0;
111 virtual wxString
GetLineText(long lineNo
) const = 0;
112 virtual int GetNumberOfLines() const = 0;
114 virtual bool IsModified() const = 0;
115 virtual bool IsEditable() const = 0;
117 // If the return values from and to are the same, there is no selection.
118 virtual void GetSelection(long* from
, long* to
) const = 0;
124 virtual void Clear() = 0;
125 virtual void Replace(long from
, long to
, const wxString
& value
) = 0;
126 virtual void Remove(long from
, long to
) = 0;
128 // load/save the controls contents from/to the file
129 virtual bool LoadFile(const wxString
& file
);
130 virtual bool SaveFile(const wxString
& file
= wxEmptyString
);
132 // clears the dirty flag
133 virtual void DiscardEdits() = 0;
135 // writing text inserts it at the current position, appending always
136 // inserts it at the end
137 virtual void WriteText(const wxString
& text
) = 0;
138 virtual void AppendText(const wxString
& text
) = 0;
140 // text control under some platforms supports the text styles: these
141 // methods allow to apply the given text style to the given selection or to
142 // set/get the style which will be used for all appended text
143 virtual bool SetStyle(long start
, long end
, const wxTextAttr
& style
);
144 virtual bool SetDefaultStyle(const wxTextAttr
& style
);
145 virtual const wxTextAttr
& GetDefaultStyle() const;
147 // translate between the position (which is just an index in the text ctrl
148 // considering all its contents as a single strings) and (x, y) coordinates
149 // which represent column and line.
150 virtual long XYToPosition(long x
, long y
) const = 0;
151 virtual bool PositionToXY(long pos
, long *x
, long *y
) const = 0;
153 virtual void ShowPosition(long pos
) = 0;
155 // Clipboard operations
156 virtual void Copy() = 0;
157 virtual void Cut() = 0;
158 virtual void Paste() = 0;
160 virtual bool CanCopy() const = 0;
161 virtual bool CanCut() const = 0;
162 virtual bool CanPaste() const = 0;
165 virtual void Undo() = 0;
166 virtual void Redo() = 0;
168 virtual bool CanUndo() const = 0;
169 virtual bool CanRedo() const = 0;
172 virtual void SetInsertionPoint(long pos
) = 0;
173 virtual void SetInsertionPointEnd() = 0;
174 virtual long GetInsertionPoint() const = 0;
175 virtual long GetLastPosition() const = 0;
177 virtual void SetSelection(long from
, long to
) = 0;
178 virtual void SetEditable(bool editable
) = 0;
181 #ifndef NO_TEXT_WINDOW_STREAM
185 #endif // NO_TEXT_WINDOW_STREAM
187 // stream-like insertion operators: these are always available, whether we
188 // were, or not, compiled with streambuf support
189 wxTextCtrl
& operator<<(const wxString
& s
);
190 wxTextCtrl
& operator<<(int i
);
191 wxTextCtrl
& operator<<(long i
);
192 wxTextCtrl
& operator<<(float f
);
193 wxTextCtrl
& operator<<(double d
);
194 wxTextCtrl
& operator<<(const wxChar c
);
196 // obsolete functions
197 #if WXWIN_COMPATIBILITY
198 bool Modified() const { return IsModified(); }
202 // the name of the last file loaded with LoadFile() which will be used by
203 // SaveFile() by default
206 // the text style which will be used for any new text added to the control
207 wxTextAttr m_defaultStyle
;
210 #ifndef NO_TEXT_WINDOW_STREAM
217 // ----------------------------------------------------------------------------
218 // include the platform-dependent class definition
219 // ----------------------------------------------------------------------------
221 #if defined(__WXMSW__)
222 #include "wx/msw/textctrl.h"
223 #elif defined(__WXMOTIF__)
224 #include "wx/motif/textctrl.h"
225 #elif defined(__WXGTK__)
226 #include "wx/gtk/textctrl.h"
227 #elif defined(__WXQT__)
228 #include "wx/qt/textctrl.h"
229 #elif defined(__WXMAC__)
230 #include "wx/mac/textctrl.h"
231 #elif defined(__WXPM__)
232 #include "wx/os2/textctrl.h"
233 #elif defined(__WXSTUBS__)
234 #include "wx/stubs/textctrl.h"
238 // _WX_TEXTCTRL_H_BASE_