]> git.saurik.com Git - wxWidgets.git/blob - include/wx/textctrl.h
changed wxUSE_DRAGIMAG to wxUSE_DRAGIMAGE and use it everywhere now
[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
25 #if wxUSE_TEXTCTRL
26
27 #include "wx/control.h" // the base class
28
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 :-(
32
33 #if (defined(__BORLANDC__)) || defined(__MWERKS__) || defined(_WINDLL) || defined(WXUSINGDLL) || defined(WXMAKINGDLL)
34 #define NO_TEXT_WINDOW_STREAM
35 #endif
36
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
42 #endif
43
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
51 #endif
52
53 class WXDLLEXPORT wxTextCtrl;
54
55 // ----------------------------------------------------------------------------
56 // constants
57 // ----------------------------------------------------------------------------
58
59 WXDLLEXPORT_DATA(extern const wxChar*) wxTextCtrlNameStr;
60 WXDLLEXPORT_DATA(extern const wxChar*) wxEmptyString;
61
62 // ----------------------------------------------------------------------------
63 // wxTextAttr: a structure containing the visual attributes of a text
64 // ----------------------------------------------------------------------------
65
66 class WXDLLEXPORT wxTextAttr
67 {
68 public:
69 // ctors
70 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) { }
75
76 // setters
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; }
80
81 // accessors
82 bool HasTextColour() const { return m_colText.Ok(); }
83 bool HasBackgroundColour() const { return m_colBack.Ok(); }
84 bool HasFont() const { return m_font.Ok(); }
85
86 // setters
87 const wxColour& GetTextColour() const { return m_colText; }
88 const wxColour& GetBackgroundColour() const { return m_colBack; }
89 const wxFont& GetFont() const { return m_font; }
90
91 // returns false if we have any attributes set, true otherwise
92 bool IsDefault() const
93 {
94 return !HasTextColour() && !HasBackgroundColour() && !HasFont();
95 }
96
97 private:
98 wxColour m_colText,
99 m_colBack;
100 wxFont m_font;
101 };
102
103 // ----------------------------------------------------------------------------
104 // wxTextCtrl: a single or multiple line text zone where user can enter and
105 // edit text
106 // ----------------------------------------------------------------------------
107
108 class WXDLLEXPORT wxTextCtrlBase : public wxControl
109 #ifndef NO_TEXT_WINDOW_STREAM
110 , public streambuf
111 #endif
112
113 {
114 public:
115 // creation
116 // --------
117
118 wxTextCtrlBase();
119 ~wxTextCtrlBase();
120
121 // accessors
122 // ---------
123
124 virtual wxString GetValue() const = 0;
125 virtual void SetValue(const wxString& value) = 0;
126
127 virtual int GetLineLength(long lineNo) const = 0;
128 virtual wxString GetLineText(long lineNo) const = 0;
129 virtual int GetNumberOfLines() const = 0;
130
131 virtual bool IsModified() const = 0;
132 virtual bool IsEditable() const = 0;
133
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;
136
137 // operations
138 // ----------
139
140 // editing
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;
144
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);
148
149 // clears the dirty flag
150 virtual void DiscardEdits() = 0;
151
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;
156
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;
163
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;
169
170 virtual void ShowPosition(long pos) = 0;
171
172 // Clipboard operations
173 virtual void Copy() = 0;
174 virtual void Cut() = 0;
175 virtual void Paste() = 0;
176
177 virtual bool CanCopy() const;
178 virtual bool CanCut() const;
179 virtual bool CanPaste() const;
180
181 // Undo/redo
182 virtual void Undo() = 0;
183 virtual void Redo() = 0;
184
185 virtual bool CanUndo() const = 0;
186 virtual bool CanRedo() const = 0;
187
188 // Insertion point
189 virtual void SetInsertionPoint(long pos) = 0;
190 virtual void SetInsertionPointEnd() = 0;
191 virtual long GetInsertionPoint() const = 0;
192 virtual long GetLastPosition() const = 0;
193
194 virtual void SetSelection(long from, long to) = 0;
195 virtual void SelectAll();
196 virtual void SetEditable(bool editable) = 0;
197
198 // streambuf methods
199 #ifndef NO_TEXT_WINDOW_STREAM
200 int overflow(int i);
201 int sync();
202 int underflow();
203 #endif // NO_TEXT_WINDOW_STREAM
204
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);
213
214 // obsolete functions
215 #if WXWIN_COMPATIBILITY
216 bool Modified() const { return IsModified(); }
217 #endif
218
219 protected:
220 // the name of the last file loaded with LoadFile() which will be used by
221 // SaveFile() by default
222 wxString m_filename;
223
224 // the text style which will be used for any new text added to the control
225 wxTextAttr m_defaultStyle;
226
227 private:
228 #ifndef NO_TEXT_WINDOW_STREAM
229 #if !wxUSE_IOSTREAMH
230 char *m_streambuf;
231 #endif
232 #endif
233 };
234
235 // ----------------------------------------------------------------------------
236 // include the platform-dependent class definition
237 // ----------------------------------------------------------------------------
238
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"
255 #endif
256
257 #endif // wxUSE_TEXTCTRL
258
259 #endif
260 // _WX_TEXTCTRL_H_BASE_