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
;
21 // ----------------------------------------------------------------------------
23 // ----------------------------------------------------------------------------
25 class WXDLLIMPEXP_CORE wxTextEntryBase
28 wxTextEntryBase() { m_eventsBlock
= 0; m_hintData
= NULL
; }
29 virtual ~wxTextEntryBase();
32 // accessing the value
33 // -------------------
35 // SetValue() generates a text change event, ChangeValue() doesn't
36 virtual void SetValue(const wxString
& value
)
37 { DoSetValue(value
, SetValue_SendEvent
); }
38 virtual void ChangeValue(const wxString
& value
)
39 { DoSetValue(value
, SetValue_NoEvent
); }
41 // writing text inserts it at the current position replacing any current
42 // selection, appending always inserts it at the end and doesn't remove any
43 // existing text (but it will reset the selection if there is any)
44 virtual void WriteText(const wxString
& text
) = 0;
45 virtual void AppendText(const wxString
& text
);
47 virtual wxString
GetValue() const;
48 virtual wxString
GetRange(long from
, long to
) const;
49 bool IsEmpty() const { return GetLastPosition() <= 0; }
55 virtual void Replace(long from
, long to
, const wxString
& value
);
56 virtual void Remove(long from
, long to
) = 0;
57 virtual void Clear() { SetValue(wxString()); }
58 void RemoveSelection();
61 // clipboard operations
62 // --------------------
64 virtual void Copy() = 0;
65 virtual void Cut() = 0;
66 virtual void Paste() = 0;
68 virtual bool CanCopy() const;
69 virtual bool CanCut() const;
70 virtual bool CanPaste() const;
75 virtual void Undo() = 0;
76 virtual void Redo() = 0;
78 virtual bool CanUndo() const = 0;
79 virtual bool CanRedo() const = 0;
85 // note that moving insertion point removes any current selection
86 virtual void SetInsertionPoint(long pos
) = 0;
87 virtual void SetInsertionPointEnd() { SetInsertionPoint(-1); }
88 virtual long GetInsertionPoint() const = 0;
89 virtual long GetLastPosition() const = 0;
95 virtual void SetSelection(long from
, long to
) = 0;
96 virtual void SelectAll() { SetSelection(-1, -1); }
97 virtual void GetSelection(long *from
, long *to
) const = 0;
98 bool HasSelection() const;
99 virtual wxString
GetStringSelection() const;
105 // these functions allow to auto-complete the text already entered into the
106 // control using either the given fixed list of strings, the paths from the
107 // file system or, in the future, an arbitrary user-defined completer
109 // they all return true if completion was enabled or false on error (most
110 // commonly meaning that this functionality is not available under the
113 virtual bool AutoComplete(const wxArrayString
& WXUNUSED(choices
))
118 virtual bool AutoCompleteFileNames() { return false; }
124 virtual bool IsEditable() const = 0;
125 virtual void SetEditable(bool editable
) = 0;
128 // set the max number of characters which may be entered in a single line
130 virtual void SetMaxLength(unsigned long WXUNUSED(len
)) { }
136 // hint is the (usually greyed out) text shown in the control as long as
137 // it's empty and doesn't have focus, it is typically used in controls used
138 // for searching to let the user know what is supposed to be entered there
140 virtual bool SetHint(const wxString
& hint
);
141 virtual wxString
GetHint() const;
145 // flags for DoSetValue(): common part of SetValue() and ChangeValue() and
146 // also used to implement WriteText() in wxMSW
149 SetValue_NoEvent
= 0,
150 SetValue_SendEvent
= 1,
151 SetValue_SelectionOnly
= 2
154 virtual void DoSetValue(const wxString
& value
, int flags
);
155 virtual wxString
DoGetValue() const = 0;
157 // override this to return the associated window, it will be used for event
158 // generation and also by generic hints implementation
159 virtual wxWindow
*GetEditableWindow() = 0;
162 // class which should be used to temporarily disable text change events
164 // if suppress argument in ctor is false, nothing is done
165 class EventsSuppressor
168 EventsSuppressor(wxTextEntryBase
*text
, bool suppress
= true)
173 m_text
->SuppressTextChangedEvents();
179 m_text
->ResumeTextChangedEvents();
183 wxTextEntryBase
*m_text
;
187 friend class EventsSuppressor
;
189 // return true if the events are currently not suppressed
190 bool EventsAllowed() const { return m_eventsBlock
== 0; }
193 // suppress or resume the text changed events generation: don't use these
194 // functions directly, use EventsSuppressor class above instead
195 void SuppressTextChangedEvents()
197 if ( !m_eventsBlock
++ )
198 EnableTextChangedEvents(false);
201 void ResumeTextChangedEvents()
203 if ( !--m_eventsBlock
)
204 EnableTextChangedEvents(true);
208 // this must be overridden in the derived classes if our implementation of
209 // SetValue() or Replace() is used to disable (and enable back) generation
210 // of the text changed events
212 // initially the generation of the events is enabled
213 virtual void EnableTextChangedEvents(bool WXUNUSED(enable
)) { }
215 // if this counter is non-null, events are blocked
216 unsigned m_eventsBlock
;
218 // hint-related stuff, only allocated if/when SetHint() is used
219 wxTextEntryHintData
*m_hintData
;
222 #ifdef __WXUNIVERSAL__
223 // TODO: we need to use wxTextEntryDelegate here, but for now just prevent
224 // the GTK/MSW classes from being used in wxUniv build
225 class WXDLLIMPEXP_CORE wxTextEntry
: public wxTextEntryBase
228 #elif defined(__WXGTK20__)
229 #include "wx/gtk/textentry.h"
230 #elif defined(__WXMSW__)
231 #include "wx/msw/textentry.h"
232 #elif defined(__WXMOTIF__)
233 #include "wx/motif/textentry.h"
234 #elif defined(__WXPM__)
235 #include "wx/os2/textentry.h"
237 // no platform-specific implementation of wxTextEntry yet
238 class WXDLLIMPEXP_CORE wxTextEntry
: public wxTextEntryBase
243 #endif // _WX_TEXTENTRY_H_