]> git.saurik.com Git - wxWidgets.git/blob - include/wx/textctrl.h
applied patch 433352 (fix for wxTextCtrl::SetForegroundColor())
[wxWidgets.git] / include / wx / textctrl.h
1 ///////////////////////////////////////////////////////////////////////////////
2 // Name: textctrl.h
3 // Purpose: wxTextCtrlBase class - the interface of wxTextCtrl
4 // Author: Vadim Zeitlin
5 // Modified by:
6 // Created: 13.07.99
7 // RCS-ID: $Id$
8 // Copyright: (c) wxWindows team
9 // Licence: wxWindows licence
10 ///////////////////////////////////////////////////////////////////////////////
11
12 #ifndef _WX_TEXTCTRL_H_BASE_
13 #define _WX_TEXTCTRL_H_BASE_
14
15 // ----------------------------------------------------------------------------
16 // headers
17 // ----------------------------------------------------------------------------
18
19 #ifdef __GNUG__
20 #pragma interface "textctrlbase.h"
21 #endif
22
23 #include "wx/defs.h"
24 #include "wx/control.h" // the base class
25
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 :-(
29
30 #if (defined(__BORLANDC__)) || defined(__MWERKS__) || defined(_WINDLL) || defined(WXUSINGDLL) || defined(WXMAKINGDLL)
31 #define NO_TEXT_WINDOW_STREAM
32 #endif
33
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
39 #endif
40
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
48 #endif
49
50 class WXDLLEXPORT wxTextCtrl;
51
52 // ----------------------------------------------------------------------------
53 // constants
54 // ----------------------------------------------------------------------------
55
56 WXDLLEXPORT_DATA(extern const wxChar*) wxTextCtrlNameStr;
57 WXDLLEXPORT_DATA(extern const wxChar*) wxEmptyString;
58
59 // ----------------------------------------------------------------------------
60 // wxTextAttr: a structure containing the visual attributes of a text
61 // ----------------------------------------------------------------------------
62
63 class WXDLLEXPORT wxTextAttr
64 {
65 public:
66 // ctors
67 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) { }
72
73 // setters
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; }
77
78 // accessors
79 bool HasTextColour() const { return m_colText.Ok(); }
80 bool HasBackgroundColour() const { return m_colBack.Ok(); }
81 bool HasFont() const { return m_font.Ok(); }
82
83 const wxColour& GetTextColour() const { return m_colText; }
84 const wxColour& GetBackgroundColour() const { return m_colBack; }
85 const wxFont& GetFont() const { return m_font; }
86
87 private:
88 wxColour m_colText,
89 m_colBack;
90 wxFont m_font;
91 };
92
93 // ----------------------------------------------------------------------------
94 // wxTextCtrl: a single or multiple line text zone where user can enter and
95 // edit text
96 // ----------------------------------------------------------------------------
97
98 class WXDLLEXPORT wxTextCtrlBase : public wxControl
99 #ifndef NO_TEXT_WINDOW_STREAM
100 , public streambuf
101 #endif
102
103 {
104 public:
105 // creation
106 // --------
107
108 wxTextCtrlBase();
109 ~wxTextCtrlBase();
110
111 // accessors
112 // ---------
113
114 virtual wxString GetValue() const = 0;
115 virtual void SetValue(const wxString& value) = 0;
116
117 virtual int GetLineLength(long lineNo) const = 0;
118 virtual wxString GetLineText(long lineNo) const = 0;
119 virtual int GetNumberOfLines() const = 0;
120
121 virtual bool IsModified() const = 0;
122 virtual bool IsEditable() const = 0;
123
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;
126
127 // operations
128 // ----------
129
130 // editing
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;
134
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);
138
139 // clears the dirty flag
140 virtual void DiscardEdits() = 0;
141
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;
146
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;
153
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;
159
160 virtual void ShowPosition(long pos) = 0;
161
162 // Clipboard operations
163 virtual void Copy() = 0;
164 virtual void Cut() = 0;
165 virtual void Paste() = 0;
166
167 virtual bool CanCopy() const = 0;
168 virtual bool CanCut() const = 0;
169 virtual bool CanPaste() const = 0;
170
171 // Undo/redo
172 virtual void Undo() = 0;
173 virtual void Redo() = 0;
174
175 virtual bool CanUndo() const = 0;
176 virtual bool CanRedo() const = 0;
177
178 // Insertion point
179 virtual void SetInsertionPoint(long pos) = 0;
180 virtual void SetInsertionPointEnd() = 0;
181 virtual long GetInsertionPoint() const = 0;
182 virtual long GetLastPosition() const = 0;
183
184 virtual void SetSelection(long from, long to) = 0;
185 virtual void SetEditable(bool editable) = 0;
186
187 // streambuf methods
188 #ifndef NO_TEXT_WINDOW_STREAM
189 int overflow(int i);
190 int sync();
191 int underflow();
192 #endif // NO_TEXT_WINDOW_STREAM
193
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);
202
203 // obsolete functions
204 #if WXWIN_COMPATIBILITY
205 bool Modified() const { return IsModified(); }
206 #endif
207
208 protected:
209 // the name of the last file loaded with LoadFile() which will be used by
210 // SaveFile() by default
211 wxString m_filename;
212
213 // the text style which will be used for any new text added to the control
214 wxTextAttr m_defaultStyle;
215
216 private:
217 #ifndef NO_TEXT_WINDOW_STREAM
218 #if !wxUSE_IOSTREAMH
219 char *m_streambuf;
220 #endif
221 #endif
222 };
223
224 // ----------------------------------------------------------------------------
225 // include the platform-dependent class definition
226 // ----------------------------------------------------------------------------
227
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"
242 #endif
243
244 #endif
245 // _WX_TEXTCTRL_H_BASE_