1 ///////////////////////////////////////////////////////////////////////////////
2 // Name: wx/textentry.h
3 // Purpose: declares wxTextEntry interface defining a simple text entry
4 // Author: Vadim Zeitlin
7 // Copyright: (c) 2007 Vadim Zeitlin <vadim@wxwindows.org>
8 // Licence: wxWindows licence
9 ///////////////////////////////////////////////////////////////////////////////
11 #ifndef _WX_TEXTENTRY_H_
12 #define _WX_TEXTENTRY_H_
14 // wxTextPos is the position in the text (currently it's hardly used anywhere
15 // and should probably be replaced with int anyhow)
16 typedef long wxTextPos
;
18 class WXDLLIMPEXP_FWD_BASE wxArrayString
;
19 class WXDLLIMPEXP_FWD_CORE wxTextEntryHintData
;
20 class WXDLLIMPEXP_FWD_CORE wxWindow
;
22 // ----------------------------------------------------------------------------
24 // ----------------------------------------------------------------------------
26 class WXDLLIMPEXP_CORE wxTextEntryBase
29 wxTextEntryBase() { m_eventsBlock
= 0; m_hintData
= NULL
; }
30 virtual ~wxTextEntryBase();
33 // accessing the value
34 // -------------------
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
); }
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
);
48 virtual wxString
GetValue() const;
49 virtual wxString
GetRange(long from
, long to
) const;
50 bool IsEmpty() const { return GetLastPosition() <= 0; }
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()); }
59 void RemoveSelection();
62 // clipboard operations
63 // --------------------
65 virtual void Copy() = 0;
66 virtual void Cut() = 0;
67 virtual void Paste() = 0;
69 virtual bool CanCopy() const;
70 virtual bool CanCut() const;
71 virtual bool CanPaste() const;
76 virtual void Undo() = 0;
77 virtual void Redo() = 0;
79 virtual bool CanUndo() const = 0;
80 virtual bool CanRedo() const = 0;
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;
96 virtual void SetSelection(long from
, long to
) = 0;
97 virtual void SelectAll() { SetSelection(-1, -1); }
98 virtual void GetSelection(long *from
, long *to
) const = 0;
99 bool HasSelection() const;
100 virtual wxString
GetStringSelection() const;
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
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
114 virtual bool AutoComplete(const wxArrayString
& WXUNUSED(choices
))
119 virtual bool AutoCompleteFileNames() { return false; }
125 virtual bool IsEditable() const = 0;
126 virtual void SetEditable(bool editable
) = 0;
129 // set the max number of characters which may be entered in a single line
131 virtual void SetMaxLength(unsigned long WXUNUSED(len
)) { }
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
141 virtual bool SetHint(const wxString
& hint
);
142 virtual wxString
GetHint() const;
146 // flags for DoSetValue(): common part of SetValue() and ChangeValue() and
147 // also used to implement WriteText() in wxMSW
150 SetValue_NoEvent
= 0,
151 SetValue_SendEvent
= 1,
152 SetValue_SelectionOnly
= 2
155 virtual void DoSetValue(const wxString
& value
, int flags
);
156 virtual wxString
DoGetValue() const = 0;
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;
163 // class which should be used to temporarily disable text change events
165 // if suppress argument in ctor is false, nothing is done
166 class EventsSuppressor
169 EventsSuppressor(wxTextEntryBase
*text
, bool suppress
= true)
174 m_text
->SuppressTextChangedEvents();
180 m_text
->ResumeTextChangedEvents();
184 wxTextEntryBase
*m_text
;
188 friend class EventsSuppressor
;
190 // return true if the events are currently not suppressed
191 bool EventsAllowed() const { return m_eventsBlock
== 0; }
194 // suppress or resume the text changed events generation: don't use these
195 // functions directly, use EventsSuppressor class above instead
196 void SuppressTextChangedEvents()
198 if ( !m_eventsBlock
++ )
199 EnableTextChangedEvents(false);
202 void ResumeTextChangedEvents()
204 if ( !--m_eventsBlock
)
205 EnableTextChangedEvents(true);
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
213 // initially the generation of the events is enabled
214 virtual void EnableTextChangedEvents(bool WXUNUSED(enable
)) { }
216 // if this counter is non-null, events are blocked
217 unsigned m_eventsBlock
;
219 // hint-related stuff, only allocated if/when SetHint() is used
220 wxTextEntryHintData
*m_hintData
;
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
229 #elif defined(__WXGTK20__)
230 #include "wx/gtk/textentry.h"
231 #elif defined(__WXMSW__)
232 #include "wx/msw/textentry.h"
233 #elif defined(__WXMOTIF__)
234 #include "wx/motif/textentry.h"
235 #elif defined(__WXPM__)
236 #include "wx/os2/textentry.h"
238 // no platform-specific implementation of wxTextEntry yet
239 class WXDLLIMPEXP_CORE wxTextEntry
: public wxTextEntryBase
244 #endif // _WX_TEXTENTRY_H_