]> git.saurik.com Git - wxWidgets.git/blame - include/wx/textctrl.h
added [bzip-]dist-only targets to the makefile
[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"
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
dd107c50
VZ
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
a1b82138 41#ifndef NO_TEXT_WINDOW_STREAM
324dbfec 42 #if wxUSE_STD_IOSTREAM
bac507e0 43 #include "wx/ioswrap.h" // for iostream classes if we need them
a1b82138
VZ
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
0efe5ba7
VZ
50class WXDLLEXPORT wxTextCtrl;
51
a1b82138
VZ
52// ----------------------------------------------------------------------------
53// constants
54// ----------------------------------------------------------------------------
55
56WXDLLEXPORT_DATA(extern const wxChar*) wxTextCtrlNameStr;
57WXDLLEXPORT_DATA(extern const wxChar*) wxEmptyString;
58
4bc1afd5
VZ
59// ----------------------------------------------------------------------------
60// wxTextAttr: a structure containing the visual attributes of a text
61// ----------------------------------------------------------------------------
62
63class WXDLLEXPORT wxTextAttr
64{
65public:
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
17665a2b 83 // setters
4bc1afd5
VZ
84 const wxColour& GetTextColour() const { return m_colText; }
85 const wxColour& GetBackgroundColour() const { return m_colBack; }
86 const wxFont& GetFont() const { return m_font; }
87
17665a2b
VZ
88 // returns false if we have any attributes set, true otherwise
89 bool IsDefault() const
90 {
91 return !HasTextColour() && !HasBackgroundColour() && !HasFont();
92 }
93
4bc1afd5
VZ
94private:
95 wxColour m_colText,
96 m_colBack;
97 wxFont m_font;
98};
99
a1b82138
VZ
100// ----------------------------------------------------------------------------
101// wxTextCtrl: a single or multiple line text zone where user can enter and
102// edit text
103// ----------------------------------------------------------------------------
104
105class WXDLLEXPORT wxTextCtrlBase : public wxControl
106#ifndef NO_TEXT_WINDOW_STREAM
107 , public streambuf
108#endif
109
110{
111public:
112 // creation
113 // --------
114
115 wxTextCtrlBase();
fa40e7a1 116 ~wxTextCtrlBase();
a1b82138
VZ
117
118 // accessors
119 // ---------
120
121 virtual wxString GetValue() const = 0;
122 virtual void SetValue(const wxString& value) = 0;
123
124 virtual int GetLineLength(long lineNo) const = 0;
125 virtual wxString GetLineText(long lineNo) const = 0;
126 virtual int GetNumberOfLines() const = 0;
127
128 virtual bool IsModified() const = 0;
129 virtual bool IsEditable() const = 0;
130
131 // If the return values from and to are the same, there is no selection.
132 virtual void GetSelection(long* from, long* to) const = 0;
133
134 // operations
135 // ----------
136
137 // editing
138 virtual void Clear() = 0;
139 virtual void Replace(long from, long to, const wxString& value) = 0;
140 virtual void Remove(long from, long to) = 0;
141
142 // load/save the controls contents from/to the file
143 virtual bool LoadFile(const wxString& file);
144 virtual bool SaveFile(const wxString& file = wxEmptyString);
145
146 // clears the dirty flag
147 virtual void DiscardEdits() = 0;
148
149 // writing text inserts it at the current position, appending always
150 // inserts it at the end
151 virtual void WriteText(const wxString& text) = 0;
152 virtual void AppendText(const wxString& text) = 0;
153
4bc1afd5
VZ
154 // text control under some platforms supports the text styles: these
155 // methods allow to apply the given text style to the given selection or to
156 // set/get the style which will be used for all appended text
157 virtual bool SetStyle(long start, long end, const wxTextAttr& style);
158 virtual bool SetDefaultStyle(const wxTextAttr& style);
159 virtual const wxTextAttr& GetDefaultStyle() const;
160
a1b82138
VZ
161 // translate between the position (which is just an index in the text ctrl
162 // considering all its contents as a single strings) and (x, y) coordinates
163 // which represent column and line.
164 virtual long XYToPosition(long x, long y) const = 0;
0efe5ba7 165 virtual bool PositionToXY(long pos, long *x, long *y) const = 0;
a1b82138
VZ
166
167 virtual void ShowPosition(long pos) = 0;
168
169 // Clipboard operations
170 virtual void Copy() = 0;
171 virtual void Cut() = 0;
172 virtual void Paste() = 0;
173
174 virtual bool CanCopy() const = 0;
175 virtual bool CanCut() const = 0;
176 virtual bool CanPaste() const = 0;
177
178 // Undo/redo
179 virtual void Undo() = 0;
180 virtual void Redo() = 0;
181
182 virtual bool CanUndo() const = 0;
183 virtual bool CanRedo() const = 0;
184
185 // Insertion point
186 virtual void SetInsertionPoint(long pos) = 0;
187 virtual void SetInsertionPointEnd() = 0;
188 virtual long GetInsertionPoint() const = 0;
189 virtual long GetLastPosition() const = 0;
190
191 virtual void SetSelection(long from, long to) = 0;
192 virtual void SetEditable(bool editable) = 0;
193
194 // streambuf methods
195#ifndef NO_TEXT_WINDOW_STREAM
196 int overflow(int i);
197 int sync();
198 int underflow();
199#endif // NO_TEXT_WINDOW_STREAM
200
201 // stream-like insertion operators: these are always available, whether we
202 // were, or not, compiled with streambuf support
203 wxTextCtrl& operator<<(const wxString& s);
204 wxTextCtrl& operator<<(int i);
205 wxTextCtrl& operator<<(long i);
206 wxTextCtrl& operator<<(float f);
207 wxTextCtrl& operator<<(double d);
a324a7bc 208 wxTextCtrl& operator<<(const wxChar c);
a1b82138
VZ
209
210 // obsolete functions
211#if WXWIN_COMPATIBILITY
212 bool Modified() const { return IsModified(); }
213#endif
214
5bd3a2da 215protected:
a1b82138
VZ
216 // the name of the last file loaded with LoadFile() which will be used by
217 // SaveFile() by default
218 wxString m_filename;
fa40e7a1 219
4bc1afd5
VZ
220 // the text style which will be used for any new text added to the control
221 wxTextAttr m_defaultStyle;
222
fa40e7a1
SB
223private:
224#ifndef NO_TEXT_WINDOW_STREAM
225#if !wxUSE_IOSTREAMH
226 char *m_streambuf;
227#endif
228#endif
a1b82138
VZ
229};
230
231// ----------------------------------------------------------------------------
232// include the platform-dependent class definition
233// ----------------------------------------------------------------------------
234
2049ba38 235#if defined(__WXMSW__)
a1b82138 236 #include "wx/msw/textctrl.h"
2049ba38 237#elif defined(__WXMOTIF__)
a1b82138 238 #include "wx/motif/textctrl.h"
2049ba38 239#elif defined(__WXGTK__)
a1b82138 240 #include "wx/gtk/textctrl.h"
b4e76e0d 241#elif defined(__WXQT__)
a1b82138 242 #include "wx/qt/textctrl.h"
34138703 243#elif defined(__WXMAC__)
a1b82138 244 #include "wx/mac/textctrl.h"
1777b9bb
DW
245#elif defined(__WXPM__)
246 #include "wx/os2/textctrl.h"
34138703 247#elif defined(__WXSTUBS__)
a1b82138 248 #include "wx/stubs/textctrl.h"
c801d85f
KB
249#endif
250
251#endif
34138703 252 // _WX_TEXTCTRL_H_BASE_