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
;
20 // ----------------------------------------------------------------------------
22 // ----------------------------------------------------------------------------
24 class WXDLLIMPEXP_CORE wxTextEntryBase
27 wxTextEntryBase() { m_eventsBlock
= 0; }
28 virtual ~wxTextEntryBase() { }
31 // accessing the value
32 // -------------------
34 // SetValue() generates a text change event, ChangeValue() doesn't
35 virtual void SetValue(const wxString
& value
)
36 { DoSetValue(value
, SetValue_SendEvent
); }
37 virtual void ChangeValue(const wxString
& value
)
38 { DoSetValue(value
, SetValue_NoEvent
); }
40 // writing text inserts it at the current position replacing any current
41 // selection, appending always inserts it at the end and doesn't remove any
42 // existing text (but it will reset the selection if there is any)
43 virtual void WriteText(const wxString
& text
) = 0;
44 virtual void AppendText(const wxString
& text
);
46 virtual wxString
GetValue() const = 0;
47 virtual wxString
GetRange(long from
, long to
) const;
48 bool IsEmpty() const { return GetValue().empty(); }
54 virtual void Replace(long from
, long to
, const wxString
& value
);
55 virtual void Remove(long from
, long to
) = 0;
56 virtual void Clear() { SetValue(wxString()); }
59 // clipboard operations
60 // --------------------
62 virtual void Copy() = 0;
63 virtual void Cut() = 0;
64 virtual void Paste() = 0;
66 virtual bool CanCopy() const;
67 virtual bool CanCut() const;
68 virtual bool CanPaste() const;
73 virtual void Undo() = 0;
74 virtual void Redo() = 0;
76 virtual bool CanUndo() const = 0;
77 virtual bool CanRedo() const = 0;
83 // note that moving insertion point removes any current selection
84 virtual void SetInsertionPoint(long pos
) = 0;
85 virtual void SetInsertionPointEnd() { SetInsertionPoint(-1); }
86 virtual long GetInsertionPoint() const = 0;
87 virtual long GetLastPosition() const = 0;
93 virtual void SetSelection(long from
, long to
) = 0;
94 virtual void SelectAll() { SetSelection(0, GetLastPosition()); }
95 virtual void GetSelection(long *from
, long *to
) const = 0;
96 bool HasSelection() const;
97 virtual wxString
GetStringSelection() const;
103 // these functions allow to auto-complete the text already entered into the
104 // control using either the given fixed list of strings, the paths from the
105 // file system or, in the future, an arbitrary user-defined completer
107 // they all return true if completion was enabled or false on error (most
108 // commonly meaning that this functionality is not available under the
111 virtual bool AutoComplete(const wxArrayString
& WXUNUSED(choices
))
116 virtual bool AutoCompleteFileNames() { return false; }
122 virtual bool IsEditable() const = 0;
123 virtual void SetEditable(bool editable
) = 0;
126 // set the max number of characters which may be entered in a single line
128 virtual void SetMaxLength(unsigned long WXUNUSED(len
)) { }
132 // flags for DoSetValue(): common part of SetValue() and ChangeValue() and
133 // also used to implement WriteText() in wxMSW
136 SetValue_NoEvent
= 0,
137 SetValue_SendEvent
= 1,
138 SetValue_SelectionOnly
= 2
141 virtual void DoSetValue(const wxString
& value
, int flags
);
143 // class which should be used to temporarily disable text change events
145 // if suppress argument in ctor is false, nothing is done
146 class EventsSuppressor
149 EventsSuppressor(wxTextEntryBase
*text
, bool suppress
= true)
154 m_text
->SuppressTextChangedEvents();
160 m_text
->ResumeTextChangedEvents();
164 wxTextEntryBase
*m_text
;
168 friend class EventsSuppressor
;
170 // return true if the events are currently not suppressed
171 bool EventsAllowed() const { return m_eventsBlock
== 0; }
174 // suppress or resume the text changed events generation: don't use these
175 // functions directly, use EventsSuppressor class above instead
176 void SuppressTextChangedEvents()
178 if ( !m_eventsBlock
++ )
179 EnableTextChangedEvents(false);
182 void ResumeTextChangedEvents()
184 if ( !--m_eventsBlock
)
185 EnableTextChangedEvents(true);
189 // this must be overridden in the derived classes if our implementation of
190 // SetValue() or Replace() is used to disable (and enable back) generation
191 // of the text changed events
193 // initially the generation of the events is enabled
194 virtual void EnableTextChangedEvents(bool WXUNUSED(enable
)) { }
196 // if this counter is non-null, events are blocked
197 unsigned m_eventsBlock
;
200 #ifdef __WXUNIVERSAL__
201 // TODO: we need to use wxTextEntryDelegate here, but for now just prevent
202 // the GTK/MSW classes from being used in wxUniv build
203 class WXDLLIMPEXP_CORE wxTextEntry
: public wxTextEntryBase
206 #elif defined(__WXGTK20__)
207 #include "wx/gtk/textentry.h"
208 #elif defined(__WXMSW__)
209 #include "wx/msw/textentry.h"
210 #elif defined(__WXMOTIF__)
211 #include "wx/motif/textentry.h"
212 #elif defined(__WXPM__)
213 #include "wx/os2/textentry.h"
215 // no platform-specific implementation of wxTextEntry yet
216 class WXDLLIMPEXP_CORE wxTextEntry
: public wxTextEntryBase
221 #endif // _WX_TEXTENTRY_H_