]> git.saurik.com Git - wxWidgets.git/blob - include/wx/textctrl.h
unnecessary ClipRects
[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 #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
41 #endif
42
43 class WXDLLEXPORT wxTextCtrl;
44
45 // ----------------------------------------------------------------------------
46 // constants
47 // ----------------------------------------------------------------------------
48
49 WXDLLEXPORT_DATA(extern const wxChar*) wxTextCtrlNameStr;
50 WXDLLEXPORT_DATA(extern const wxChar*) wxEmptyString;
51
52 // ----------------------------------------------------------------------------
53 // wxTextAttr: a structure containing the visual attributes of a text
54 // ----------------------------------------------------------------------------
55
56 class WXDLLEXPORT wxTextAttr
57 {
58 public:
59 // ctors
60 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) { }
65
66 // setters
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; }
70
71 // accessors
72 bool HasTextColour() const { return m_colText.Ok(); }
73 bool HasBackgroundColour() const { return m_colBack.Ok(); }
74 bool HasFont() const { return m_font.Ok(); }
75
76 const wxColour& GetTextColour() const { return m_colText; }
77 const wxColour& GetBackgroundColour() const { return m_colBack; }
78 const wxFont& GetFont() const { return m_font; }
79
80 private:
81 wxColour m_colText,
82 m_colBack;
83 wxFont m_font;
84 };
85
86 // ----------------------------------------------------------------------------
87 // wxTextCtrl: a single or multiple line text zone where user can enter and
88 // edit text
89 // ----------------------------------------------------------------------------
90
91 class WXDLLEXPORT wxTextCtrlBase : public wxControl
92 #ifndef NO_TEXT_WINDOW_STREAM
93 , public streambuf
94 #endif
95
96 {
97 public:
98 // creation
99 // --------
100
101 wxTextCtrlBase();
102 ~wxTextCtrlBase();
103
104 // accessors
105 // ---------
106
107 virtual wxString GetValue() const = 0;
108 virtual void SetValue(const wxString& value) = 0;
109
110 virtual int GetLineLength(long lineNo) const = 0;
111 virtual wxString GetLineText(long lineNo) const = 0;
112 virtual int GetNumberOfLines() const = 0;
113
114 virtual bool IsModified() const = 0;
115 virtual bool IsEditable() const = 0;
116
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;
119
120 // operations
121 // ----------
122
123 // editing
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;
127
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);
131
132 // clears the dirty flag
133 virtual void DiscardEdits() = 0;
134
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;
139
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;
146
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;
152
153 virtual void ShowPosition(long pos) = 0;
154
155 // Clipboard operations
156 virtual void Copy() = 0;
157 virtual void Cut() = 0;
158 virtual void Paste() = 0;
159
160 virtual bool CanCopy() const = 0;
161 virtual bool CanCut() const = 0;
162 virtual bool CanPaste() const = 0;
163
164 // Undo/redo
165 virtual void Undo() = 0;
166 virtual void Redo() = 0;
167
168 virtual bool CanUndo() const = 0;
169 virtual bool CanRedo() const = 0;
170
171 // Insertion point
172 virtual void SetInsertionPoint(long pos) = 0;
173 virtual void SetInsertionPointEnd() = 0;
174 virtual long GetInsertionPoint() const = 0;
175 virtual long GetLastPosition() const = 0;
176
177 virtual void SetSelection(long from, long to) = 0;
178 virtual void SetEditable(bool editable) = 0;
179
180 // streambuf methods
181 #ifndef NO_TEXT_WINDOW_STREAM
182 int overflow(int i);
183 int sync();
184 int underflow();
185 #endif // NO_TEXT_WINDOW_STREAM
186
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);
195
196 // obsolete functions
197 #if WXWIN_COMPATIBILITY
198 bool Modified() const { return IsModified(); }
199 #endif
200
201 protected:
202 // the name of the last file loaded with LoadFile() which will be used by
203 // SaveFile() by default
204 wxString m_filename;
205
206 // the text style which will be used for any new text added to the control
207 wxTextAttr m_defaultStyle;
208
209 private:
210 #ifndef NO_TEXT_WINDOW_STREAM
211 #if !wxUSE_IOSTREAMH
212 char *m_streambuf;
213 #endif
214 #endif
215 };
216
217 // ----------------------------------------------------------------------------
218 // include the platform-dependent class definition
219 // ----------------------------------------------------------------------------
220
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"
235 #endif
236
237 #endif
238 // _WX_TEXTCTRL_H_BASE_