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 #include "wx/gdicmn.h" // for wxPoint
24 // ----------------------------------------------------------------------------
26 // ----------------------------------------------------------------------------
28 class WXDLLIMPEXP_CORE wxTextEntryBase
31 wxTextEntryBase() { m_eventsBlock
= 0; m_hintData
= NULL
; }
32 virtual ~wxTextEntryBase();
35 // accessing the value
36 // -------------------
38 // SetValue() generates a text change event, ChangeValue() doesn't
39 virtual void SetValue(const wxString
& value
)
40 { DoSetValue(value
, SetValue_SendEvent
); }
41 virtual void ChangeValue(const wxString
& value
)
42 { DoSetValue(value
, SetValue_NoEvent
); }
44 // writing text inserts it at the current position replacing any current
45 // selection, appending always inserts it at the end and doesn't remove any
46 // existing text (but it will reset the selection if there is any)
47 virtual void WriteText(const wxString
& text
) = 0;
48 virtual void AppendText(const wxString
& text
);
50 virtual wxString
GetValue() const;
51 virtual wxString
GetRange(long from
, long to
) const;
52 bool IsEmpty() const { return GetLastPosition() <= 0; }
58 virtual void Replace(long from
, long to
, const wxString
& value
);
59 virtual void Remove(long from
, long to
) = 0;
60 virtual void Clear() { SetValue(wxString()); }
61 void RemoveSelection();
64 // clipboard operations
65 // --------------------
67 virtual void Copy() = 0;
68 virtual void Cut() = 0;
69 virtual void Paste() = 0;
71 virtual bool CanCopy() const;
72 virtual bool CanCut() const;
73 virtual bool CanPaste() const;
78 virtual void Undo() = 0;
79 virtual void Redo() = 0;
81 virtual bool CanUndo() const = 0;
82 virtual bool CanRedo() const = 0;
88 // note that moving insertion point removes any current selection
89 virtual void SetInsertionPoint(long pos
) = 0;
90 virtual void SetInsertionPointEnd() { SetInsertionPoint(-1); }
91 virtual long GetInsertionPoint() const = 0;
92 virtual long GetLastPosition() const = 0;
98 virtual void SetSelection(long from
, long to
) = 0;
99 virtual void SelectAll() { SetSelection(-1, -1); }
100 virtual void GetSelection(long *from
, long *to
) const = 0;
101 bool HasSelection() const;
102 virtual wxString
GetStringSelection() const;
108 // these functions allow to auto-complete the text already entered into the
109 // control using either the given fixed list of strings, the paths from the
110 // file system or, in the future, an arbitrary user-defined completer
112 // they all return true if completion was enabled or false on error (most
113 // commonly meaning that this functionality is not available under the
116 virtual bool AutoComplete(const wxArrayString
& WXUNUSED(choices
))
121 virtual bool AutoCompleteFileNames() { return false; }
127 virtual bool IsEditable() const = 0;
128 virtual void SetEditable(bool editable
) = 0;
131 // set the max number of characters which may be entered in a single line
133 virtual void SetMaxLength(unsigned long WXUNUSED(len
)) { }
139 // hint is the (usually greyed out) text shown in the control as long as
140 // it's empty and doesn't have focus, it is typically used in controls used
141 // for searching to let the user know what is supposed to be entered there
143 virtual bool SetHint(const wxString
& hint
);
144 virtual wxString
GetHint() const;
150 // margins are the empty space between borders of control and the text
151 // itself. When setting margin, use value -1 to indicate that specific
152 // margin should not be changed.
154 bool SetMargins(const wxPoint
& pt
)
155 { return DoSetMargins(pt
); }
156 bool SetMargins(wxCoord left
, wxCoord top
= -1)
157 { return DoSetMargins(wxPoint(left
, top
)); }
158 wxPoint
GetMargins() const
159 { return DoGetMargins(); }
162 // flags for DoSetValue(): common part of SetValue() and ChangeValue() and
163 // also used to implement WriteText() in wxMSW
166 SetValue_NoEvent
= 0,
167 SetValue_SendEvent
= 1,
168 SetValue_SelectionOnly
= 2
171 virtual void DoSetValue(const wxString
& value
, int flags
);
172 virtual wxString
DoGetValue() const = 0;
174 // override this to return the associated window, it will be used for event
175 // generation and also by generic hints implementation
176 virtual wxWindow
*GetEditableWindow() = 0;
179 virtual bool DoSetMargins(const wxPoint
& pt
);
180 virtual wxPoint
DoGetMargins() const;
183 // class which should be used to temporarily disable text change events
185 // if suppress argument in ctor is false, nothing is done
186 class EventsSuppressor
189 EventsSuppressor(wxTextEntryBase
*text
, bool suppress
= true)
194 m_text
->SuppressTextChangedEvents();
200 m_text
->ResumeTextChangedEvents();
204 wxTextEntryBase
*m_text
;
208 friend class EventsSuppressor
;
210 // return true if the events are currently not suppressed
211 bool EventsAllowed() const { return m_eventsBlock
== 0; }
214 // suppress or resume the text changed events generation: don't use these
215 // functions directly, use EventsSuppressor class above instead
216 void SuppressTextChangedEvents()
218 if ( !m_eventsBlock
++ )
219 EnableTextChangedEvents(false);
222 void ResumeTextChangedEvents()
224 if ( !--m_eventsBlock
)
225 EnableTextChangedEvents(true);
229 // this must be overridden in the derived classes if our implementation of
230 // SetValue() or Replace() is used to disable (and enable back) generation
231 // of the text changed events
233 // initially the generation of the events is enabled
234 virtual void EnableTextChangedEvents(bool WXUNUSED(enable
)) { }
236 // if this counter is non-null, events are blocked
237 unsigned m_eventsBlock
;
239 // hint-related stuff, only allocated if/when SetHint() is used
240 wxTextEntryHintData
*m_hintData
;
243 #ifdef __WXUNIVERSAL__
244 // TODO: we need to use wxTextEntryDelegate here, but for now just prevent
245 // the GTK/MSW classes from being used in wxUniv build
246 class WXDLLIMPEXP_CORE wxTextEntry
: public wxTextEntryBase
249 #elif defined(__WXGTK20__)
250 #include "wx/gtk/textentry.h"
251 #elif defined(__WXMAC__)
252 #include "wx/osx/textentry.h"
253 #elif defined(__WXMSW__)
254 #include "wx/msw/textentry.h"
255 #elif defined(__WXMOTIF__)
256 #include "wx/motif/textentry.h"
257 #elif defined(__WXPM__)
258 #include "wx/os2/textentry.h"
260 // no platform-specific implementation of wxTextEntry yet
261 class WXDLLIMPEXP_CORE wxTextEntry
: public wxTextEntryBase
266 #endif // _WX_TEXTENTRY_H_