]>
Commit | Line | Data |
---|---|---|
a1b82138 VZ |
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 | ||
34138703 JS |
12 | #ifndef _WX_TEXTCTRL_H_BASE_ |
13 | #define _WX_TEXTCTRL_H_BASE_ | |
c801d85f | 14 | |
a1b82138 VZ |
15 | // ---------------------------------------------------------------------------- |
16 | // headers | |
17 | // ---------------------------------------------------------------------------- | |
4bc1afd5 | 18 | |
bf3e0fbd KB |
19 | #ifdef __GNUG__ |
20 | #pragma interface "textctrlbase.h" | |
4bc1afd5 | 21 | #endif |
a1b82138 VZ |
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 | |
324dbfec | 35 | #if wxUSE_STD_IOSTREAM |
bac507e0 | 36 | #include "wx/ioswrap.h" // for iostream classes if we need them |
a1b82138 VZ |
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 | ||
0efe5ba7 VZ |
43 | class WXDLLEXPORT wxTextCtrl; |
44 | ||
a1b82138 VZ |
45 | // ---------------------------------------------------------------------------- |
46 | // constants | |
47 | // ---------------------------------------------------------------------------- | |
48 | ||
49 | WXDLLEXPORT_DATA(extern const wxChar*) wxTextCtrlNameStr; | |
50 | WXDLLEXPORT_DATA(extern const wxChar*) wxEmptyString; | |
51 | ||
4bc1afd5 VZ |
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 | ||
a1b82138 VZ |
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(); | |
fa40e7a1 | 102 | ~wxTextCtrlBase(); |
a1b82138 VZ |
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 | ||
4bc1afd5 VZ |
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 | ||
a1b82138 VZ |
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; | |
0efe5ba7 | 151 | virtual bool PositionToXY(long pos, long *x, long *y) const = 0; |
a1b82138 VZ |
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); | |
a324a7bc | 194 | wxTextCtrl& operator<<(const wxChar c); |
a1b82138 VZ |
195 | |
196 | // obsolete functions | |
197 | #if WXWIN_COMPATIBILITY | |
198 | bool Modified() const { return IsModified(); } | |
199 | #endif | |
200 | ||
5bd3a2da | 201 | protected: |
a1b82138 VZ |
202 | // the name of the last file loaded with LoadFile() which will be used by |
203 | // SaveFile() by default | |
204 | wxString m_filename; | |
fa40e7a1 | 205 | |
4bc1afd5 VZ |
206 | // the text style which will be used for any new text added to the control |
207 | wxTextAttr m_defaultStyle; | |
208 | ||
fa40e7a1 SB |
209 | private: |
210 | #ifndef NO_TEXT_WINDOW_STREAM | |
211 | #if !wxUSE_IOSTREAMH | |
212 | char *m_streambuf; | |
213 | #endif | |
214 | #endif | |
a1b82138 VZ |
215 | }; |
216 | ||
217 | // ---------------------------------------------------------------------------- | |
218 | // include the platform-dependent class definition | |
219 | // ---------------------------------------------------------------------------- | |
220 | ||
2049ba38 | 221 | #if defined(__WXMSW__) |
a1b82138 | 222 | #include "wx/msw/textctrl.h" |
2049ba38 | 223 | #elif defined(__WXMOTIF__) |
a1b82138 | 224 | #include "wx/motif/textctrl.h" |
2049ba38 | 225 | #elif defined(__WXGTK__) |
a1b82138 | 226 | #include "wx/gtk/textctrl.h" |
b4e76e0d | 227 | #elif defined(__WXQT__) |
a1b82138 | 228 | #include "wx/qt/textctrl.h" |
34138703 | 229 | #elif defined(__WXMAC__) |
a1b82138 | 230 | #include "wx/mac/textctrl.h" |
1777b9bb DW |
231 | #elif defined(__WXPM__) |
232 | #include "wx/os2/textctrl.h" | |
34138703 | 233 | #elif defined(__WXSTUBS__) |
a1b82138 | 234 | #include "wx/stubs/textctrl.h" |
c801d85f KB |
235 | #endif |
236 | ||
237 | #endif | |
34138703 | 238 | // _WX_TEXTCTRL_H_BASE_ |