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 // ----------------------------------------------------------------------------
20 // ----------------------------------------------------------------------------
22 class WXDLLIMPEXP_CORE wxTextEntryBase
25 wxTextEntryBase() { m_eventsBlock
= 0; }
26 virtual ~wxTextEntryBase() { }
29 // accessing the value
30 // -------------------
32 // SetValue() generates a text change event, ChangeValue() doesn't
33 virtual void SetValue(const wxString
& value
)
34 { DoSetValue(value
, SetValue_SendEvent
); }
35 virtual void ChangeValue(const wxString
& value
)
36 { DoSetValue(value
, SetValue_NoEvent
); }
38 // writing text inserts it at the current position replacing any current
39 // selection, appending always inserts it at the end and doesn't remove any
40 // existing text (but it will reset the selection if there is any)
41 virtual void WriteText(const wxString
& text
) = 0;
42 virtual void AppendText(const wxString
& text
);
44 virtual wxString
GetValue() const = 0;
45 virtual wxString
GetRange(long from
, long to
) const;
46 bool IsEmpty() const { return GetValue().empty(); }
52 virtual void Replace(long from
, long to
, const wxString
& value
);
53 virtual void Remove(long from
, long to
) = 0;
54 virtual void Clear() { SetValue(wxString()); }
57 // clipboard operations
58 // --------------------
60 virtual void Copy() = 0;
61 virtual void Cut() = 0;
62 virtual void Paste() = 0;
64 virtual bool CanCopy() const;
65 virtual bool CanCut() const;
66 virtual bool CanPaste() const;
71 virtual void Undo() = 0;
72 virtual void Redo() = 0;
74 virtual bool CanUndo() const = 0;
75 virtual bool CanRedo() const = 0;
81 // note that moving insertion point removes any current selection
82 virtual void SetInsertionPoint(long pos
) = 0;
83 virtual void SetInsertionPointEnd() { SetInsertionPoint(-1); }
84 virtual long GetInsertionPoint() const = 0;
85 virtual long GetLastPosition() const = 0;
91 virtual void SetSelection(long from
, long to
) = 0;
92 virtual void SelectAll() { SetSelection(0, GetLastPosition()); }
93 virtual void GetSelection(long *from
, long *to
) const = 0;
94 bool HasSelection() const;
95 virtual wxString
GetStringSelection() const;
101 virtual void AutoComplete(const wxArrayString
& WXUNUSED(choices
)) { }
107 virtual bool IsEditable() const = 0;
108 virtual void SetEditable(bool editable
) = 0;
111 // set the max number of characters which may be entered in a single line
113 virtual void SetMaxLength(unsigned long WXUNUSED(len
)) { }
117 // flags for DoSetValue(): common part of SetValue() and ChangeValue() and
118 // also used to implement WriteText() in wxMSW
121 SetValue_NoEvent
= 0,
122 SetValue_SendEvent
= 1,
123 SetValue_SelectionOnly
= 2
126 virtual void DoSetValue(const wxString
& value
, int flags
);
128 // class which should be used to temporarily disable text change events
130 // if suppress argument in ctor is false, nothing is done
131 class EventsSuppressor
134 EventsSuppressor(wxTextEntryBase
*text
, bool suppress
= true)
139 m_text
->SuppressTextChangedEvents();
145 m_text
->ResumeTextChangedEvents();
149 wxTextEntryBase
*m_text
;
153 friend class EventsSuppressor
;
155 // return true if the events are currently not suppressed
156 bool EventsAllowed() const { return m_eventsBlock
== 0; }
159 // suppress or resume the text changed events generation: don't use these
160 // functions directly, use EventsSuppressor class above instead
161 void SuppressTextChangedEvents()
163 if ( !m_eventsBlock
++ )
164 EnableTextChangedEvents(false);
167 void ResumeTextChangedEvents()
169 if ( !--m_eventsBlock
)
170 EnableTextChangedEvents(true);
174 // this must be overridden in the derived classes if our implementation of
175 // SetValue() or Replace() is used to disable (and enable back) generation
176 // of the text changed events
178 // initially the generation of the events is enabled
179 virtual void EnableTextChangedEvents(bool WXUNUSED(enable
)) { }
181 // if this counter is non-null, events are blocked
182 unsigned m_eventsBlock
;
185 #ifdef __WXUNIVERSAL__
186 // TODO: we need to use wxTextEntryDelegate here, but for now just prevent
187 // the GTK/MSW classes from being used in wxUniv build
188 class WXDLLIMPEXP_CORE wxTextEntry
: public wxTextEntryBase
191 #elif defined(__WXGTK20__)
192 #include "wx/gtk/textentry.h"
193 #elif defined(__WXMSW__)
194 #include "wx/msw/textentry.h"
196 // no platform-specific implementation of wxTextEntry yet
197 class WXDLLIMPEXP_CORE wxTextEntry
: public wxTextEntryBase
202 #endif // _WX_TEXTENTRY_H_