]> git.saurik.com Git - wxWidgets.git/blame - include/wx/textentry.h
Extract wxFDIOHandler in its own header.
[wxWidgets.git] / include / wx / textentry.h
CommitLineData
0ec1179b
VZ
1///////////////////////////////////////////////////////////////////////////////
2// Name: wx/textentry.h
3// Purpose: declares wxTextEntry interface defining a simple text entry
4// Author: Vadim Zeitlin
5// Created: 2007-09-24
6// RCS-ID: $Id$
7// Copyright: (c) 2007 Vadim Zeitlin <vadim@wxwindows.org>
8// Licence: wxWindows licence
9///////////////////////////////////////////////////////////////////////////////
10
11#ifndef _WX_TEXTENTRY_H_
12#define _WX_TEXTENTRY_H_
13
14// wxTextPos is the position in the text (currently it's hardly used anywhere
15// and should probably be replaced with int anyhow)
16typedef long wxTextPos;
17
b4782e57 18class WXDLLIMPEXP_FWD_BASE wxArrayString;
63f7d502 19class WXDLLIMPEXP_FWD_CORE wxTextEntryHintData;
a95f37bc 20class WXDLLIMPEXP_FWD_CORE wxWindow;
b4782e57 21
0ec1179b
VZ
22// ----------------------------------------------------------------------------
23// wxTextEntryBase
24// ----------------------------------------------------------------------------
25
26class WXDLLIMPEXP_CORE wxTextEntryBase
27{
28public:
63f7d502
VZ
29 wxTextEntryBase() { m_eventsBlock = 0; m_hintData = NULL; }
30 virtual ~wxTextEntryBase();
0ec1179b
VZ
31
32
33 // accessing the value
34 // -------------------
35
36 // SetValue() generates a text change event, ChangeValue() doesn't
37 virtual void SetValue(const wxString& value)
38 { DoSetValue(value, SetValue_SendEvent); }
39 virtual void ChangeValue(const wxString& value)
40 { DoSetValue(value, SetValue_NoEvent); }
41
42 // writing text inserts it at the current position replacing any current
43 // selection, appending always inserts it at the end and doesn't remove any
44 // existing text (but it will reset the selection if there is any)
45 virtual void WriteText(const wxString& text) = 0;
46 virtual void AppendText(const wxString& text);
47
135b23b2 48 virtual wxString GetValue() const;
0ec1179b 49 virtual wxString GetRange(long from, long to) const;
a7507230 50 bool IsEmpty() const { return GetLastPosition() <= 0; }
0ec1179b
VZ
51
52
53 // editing operations
54 // ------------------
55
56 virtual void Replace(long from, long to, const wxString& value);
57 virtual void Remove(long from, long to) = 0;
58 virtual void Clear() { SetValue(wxString()); }
5a25f858 59 void RemoveSelection();
0ec1179b
VZ
60
61
62 // clipboard operations
63 // --------------------
64
65 virtual void Copy() = 0;
66 virtual void Cut() = 0;
67 virtual void Paste() = 0;
68
69 virtual bool CanCopy() const;
70 virtual bool CanCut() const;
71 virtual bool CanPaste() const;
72
73 // undo/redo
74 // ---------
75
76 virtual void Undo() = 0;
77 virtual void Redo() = 0;
78
79 virtual bool CanUndo() const = 0;
80 virtual bool CanRedo() const = 0;
81
82
83 // insertion point
84 // ---------------
85
86 // note that moving insertion point removes any current selection
87 virtual void SetInsertionPoint(long pos) = 0;
88 virtual void SetInsertionPointEnd() { SetInsertionPoint(-1); }
89 virtual long GetInsertionPoint() const = 0;
90 virtual long GetLastPosition() const = 0;
91
92
93 // selection
94 // ---------
95
96 virtual void SetSelection(long from, long to) = 0;
e0721133 97 virtual void SelectAll() { SetSelection(-1, -1); }
0ec1179b
VZ
98 virtual void GetSelection(long *from, long *to) const = 0;
99 bool HasSelection() const;
100 virtual wxString GetStringSelection() const;
101
978c6e41 102
ecaed0bc
VZ
103 // auto-completion
104 // ---------------
105
59396417
VZ
106 // these functions allow to auto-complete the text already entered into the
107 // control using either the given fixed list of strings, the paths from the
108 // file system or, in the future, an arbitrary user-defined completer
109 //
110 // they all return true if completion was enabled or false on error (most
111 // commonly meaning that this functionality is not available under the
112 // current platform)
113
114 virtual bool AutoComplete(const wxArrayString& WXUNUSED(choices))
115 {
116 return false;
117 }
118
119 virtual bool AutoCompleteFileNames() { return false; }
ecaed0bc 120
0ec1179b
VZ
121
122 // status
123 // ------
ecaed0bc 124
0ec1179b
VZ
125 virtual bool IsEditable() const = 0;
126 virtual void SetEditable(bool editable) = 0;
127
128
129 // set the max number of characters which may be entered in a single line
130 // text control
131 virtual void SetMaxLength(unsigned long WXUNUSED(len)) { }
132
133
63f7d502
VZ
134 // hints
135 // -----
136
137 // hint is the (usually greyed out) text shown in the control as long as
138 // it's empty and doesn't have focus, it is typically used in controls used
139 // for searching to let the user know what is supposed to be entered there
140
141 virtual bool SetHint(const wxString& hint);
142 virtual wxString GetHint() const;
143
144
0ec1179b
VZ
145protected:
146 // flags for DoSetValue(): common part of SetValue() and ChangeValue() and
147 // also used to implement WriteText() in wxMSW
148 enum
149 {
150 SetValue_NoEvent = 0,
151 SetValue_SendEvent = 1,
152 SetValue_SelectionOnly = 2
153 };
154
155 virtual void DoSetValue(const wxString& value, int flags);
135b23b2 156 virtual wxString DoGetValue() const = 0;
0ec1179b 157
4ba5f250
VZ
158 // override this to return the associated window, it will be used for event
159 // generation and also by generic hints implementation
160 virtual wxWindow *GetEditableWindow() = 0;
161
162
0ec1179b
VZ
163 // class which should be used to temporarily disable text change events
164 //
165 // if suppress argument in ctor is false, nothing is done
166 class EventsSuppressor
167 {
168 public:
169 EventsSuppressor(wxTextEntryBase *text, bool suppress = true)
3b49331b
VZ
170 : m_text(text),
171 m_suppress(suppress)
0ec1179b 172 {
0ec1179b 173 if ( m_suppress )
0ec1179b 174 m_text->SuppressTextChangedEvents();
0ec1179b
VZ
175 }
176
177 ~EventsSuppressor()
178 {
179 if ( m_suppress )
180 m_text->ResumeTextChangedEvents();
181 }
182
183 private:
184 wxTextEntryBase *m_text;
185 bool m_suppress;
186 };
3b49331b 187
558820fd 188 friend class EventsSuppressor;
0ec1179b
VZ
189
190 // return true if the events are currently not suppressed
191 bool EventsAllowed() const { return m_eventsBlock == 0; }
192
193private:
194 // suppress or resume the text changed events generation: don't use these
195 // functions directly, use EventsSuppressor class above instead
196 void SuppressTextChangedEvents()
197 {
198 if ( !m_eventsBlock++ )
199 EnableTextChangedEvents(false);
200 }
201
202 void ResumeTextChangedEvents()
203 {
204 if ( !--m_eventsBlock )
205 EnableTextChangedEvents(true);
206 }
207
208
209 // this must be overridden in the derived classes if our implementation of
210 // SetValue() or Replace() is used to disable (and enable back) generation
211 // of the text changed events
212 //
213 // initially the generation of the events is enabled
214 virtual void EnableTextChangedEvents(bool WXUNUSED(enable)) { }
215
0ec1179b
VZ
216 // if this counter is non-null, events are blocked
217 unsigned m_eventsBlock;
63f7d502
VZ
218
219 // hint-related stuff, only allocated if/when SetHint() is used
220 wxTextEntryHintData *m_hintData;
0ec1179b
VZ
221};
222
2978a784
VZ
223#ifdef __WXUNIVERSAL__
224 // TODO: we need to use wxTextEntryDelegate here, but for now just prevent
225 // the GTK/MSW classes from being used in wxUniv build
226 class WXDLLIMPEXP_CORE wxTextEntry : public wxTextEntryBase
227 {
228 };
229#elif defined(__WXGTK20__)
0ec1179b 230 #include "wx/gtk/textentry.h"
fa2f57be
VZ
231#elif defined(__WXMSW__)
232 #include "wx/msw/textentry.h"
978c6e41
VZ
233#elif defined(__WXMOTIF__)
234 #include "wx/motif/textentry.h"
72cb72bf
SN
235#elif defined(__WXPM__)
236 #include "wx/os2/textentry.h"
0ec1179b
VZ
237#else
238 // no platform-specific implementation of wxTextEntry yet
239 class WXDLLIMPEXP_CORE wxTextEntry : public wxTextEntryBase
240 {
241 };
242#endif
243
244#endif // _WX_TEXTENTRY_H_
245