]> git.saurik.com Git - wxWidgets.git/blame - include/wx/textctrl.h
changed wxUSE_DRAGIMAG to wxUSE_DRAGIMAGE and use it everywhere now
[wxWidgets.git] / include / wx / textctrl.h
CommitLineData
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"
1e6feb95
VZ
24
25#if wxUSE_TEXTCTRL
26
a1b82138
VZ
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
dd107c50
VZ
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
a1b82138 44#ifndef NO_TEXT_WINDOW_STREAM
324dbfec 45 #if wxUSE_STD_IOSTREAM
bac507e0 46 #include "wx/ioswrap.h" // for iostream classes if we need them
a1b82138
VZ
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
0efe5ba7
VZ
53class WXDLLEXPORT wxTextCtrl;
54
a1b82138
VZ
55// ----------------------------------------------------------------------------
56// constants
57// ----------------------------------------------------------------------------
58
59WXDLLEXPORT_DATA(extern const wxChar*) wxTextCtrlNameStr;
60WXDLLEXPORT_DATA(extern const wxChar*) wxEmptyString;
61
4bc1afd5
VZ
62// ----------------------------------------------------------------------------
63// wxTextAttr: a structure containing the visual attributes of a text
64// ----------------------------------------------------------------------------
65
66class WXDLLEXPORT wxTextAttr
67{
68public:
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
17665a2b 86 // setters
4bc1afd5
VZ
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
17665a2b
VZ
91 // returns false if we have any attributes set, true otherwise
92 bool IsDefault() const
93 {
94 return !HasTextColour() && !HasBackgroundColour() && !HasFont();
95 }
96
4bc1afd5
VZ
97private:
98 wxColour m_colText,
99 m_colBack;
100 wxFont m_font;
101};
102
a1b82138
VZ
103// ----------------------------------------------------------------------------
104// wxTextCtrl: a single or multiple line text zone where user can enter and
105// edit text
106// ----------------------------------------------------------------------------
107
108class WXDLLEXPORT wxTextCtrlBase : public wxControl
109#ifndef NO_TEXT_WINDOW_STREAM
110 , public streambuf
111#endif
112
113{
114public:
115 // creation
116 // --------
117
118 wxTextCtrlBase();
fa40e7a1 119 ~wxTextCtrlBase();
a1b82138
VZ
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
4bc1afd5
VZ
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
a1b82138
VZ
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;
0efe5ba7 168 virtual bool PositionToXY(long pos, long *x, long *y) const = 0;
a1b82138
VZ
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
1e6feb95
VZ
177 virtual bool CanCopy() const;
178 virtual bool CanCut() const;
179 virtual bool CanPaste() const;
a1b82138
VZ
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;
1e6feb95 195 virtual void SelectAll();
a1b82138
VZ
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);
a324a7bc 212 wxTextCtrl& operator<<(const wxChar c);
a1b82138
VZ
213
214 // obsolete functions
215#if WXWIN_COMPATIBILITY
216 bool Modified() const { return IsModified(); }
217#endif
218
5bd3a2da 219protected:
a1b82138
VZ
220 // the name of the last file loaded with LoadFile() which will be used by
221 // SaveFile() by default
222 wxString m_filename;
fa40e7a1 223
4bc1afd5
VZ
224 // the text style which will be used for any new text added to the control
225 wxTextAttr m_defaultStyle;
226
fa40e7a1
SB
227private:
228#ifndef NO_TEXT_WINDOW_STREAM
229#if !wxUSE_IOSTREAMH
1e6feb95 230 char *m_streambuf;
fa40e7a1
SB
231#endif
232#endif
a1b82138
VZ
233};
234
235// ----------------------------------------------------------------------------
236// include the platform-dependent class definition
237// ----------------------------------------------------------------------------
238
1e6feb95
VZ
239#if defined(__WXUNIVERSAL__)
240 #include "wx/univ/textctrl.h"
241#elif defined(__WXMSW__)
a1b82138 242 #include "wx/msw/textctrl.h"
2049ba38 243#elif defined(__WXMOTIF__)
a1b82138 244 #include "wx/motif/textctrl.h"
2049ba38 245#elif defined(__WXGTK__)
a1b82138 246 #include "wx/gtk/textctrl.h"
b4e76e0d 247#elif defined(__WXQT__)
a1b82138 248 #include "wx/qt/textctrl.h"
34138703 249#elif defined(__WXMAC__)
a1b82138 250 #include "wx/mac/textctrl.h"
1777b9bb
DW
251#elif defined(__WXPM__)
252 #include "wx/os2/textctrl.h"
34138703 253#elif defined(__WXSTUBS__)
a1b82138 254 #include "wx/stubs/textctrl.h"
c801d85f
KB
255#endif
256
1e6feb95
VZ
257#endif // wxUSE_TEXTCTRL
258
c801d85f 259#endif
34138703 260 // _WX_TEXTCTRL_H_BASE_