]> git.saurik.com Git - wxWidgets.git/blame - include/wx/textentry.h
Override AdjustForParentClientOrigin() in wxNonOwnedWindow to do nothing.
[wxWidgets.git] / include / wx / textentry.h
CommitLineData
0ec1179b
VZ
1///////////////////////////////////////////////////////////////////////////////
2// Name: wx/textentry.h
3// Purpose: declares wxTextEntry interface defining a simple text entry
4// Author: Vadim Zeitlin
5// Created: 2007-09-24
6// RCS-ID: $Id$
7// Copyright: (c) 2007 Vadim Zeitlin <vadim@wxwindows.org>
8// Licence: wxWindows licence
9///////////////////////////////////////////////////////////////////////////////
10
11#ifndef _WX_TEXTENTRY_H_
12#define _WX_TEXTENTRY_H_
13
14// wxTextPos is the position in the text (currently it's hardly used anywhere
15// and should probably be replaced with int anyhow)
16typedef long wxTextPos;
17
b4782e57 18class WXDLLIMPEXP_FWD_BASE wxArrayString;
ea98f11c 19class WXDLLIMPEXP_FWD_CORE wxTextCompleter;
63f7d502 20class WXDLLIMPEXP_FWD_CORE wxTextEntryHintData;
a95f37bc 21class WXDLLIMPEXP_FWD_CORE wxWindow;
b4782e57 22
03dede4d 23#include "wx/filefn.h" // for wxFILE and wxDIR only
4516928a
VZ
24#include "wx/gdicmn.h" // for wxPoint
25
0ec1179b
VZ
26// ----------------------------------------------------------------------------
27// wxTextEntryBase
28// ----------------------------------------------------------------------------
29
30class WXDLLIMPEXP_CORE wxTextEntryBase
31{
32public:
63f7d502
VZ
33 wxTextEntryBase() { m_eventsBlock = 0; m_hintData = NULL; }
34 virtual ~wxTextEntryBase();
0ec1179b
VZ
35
36
37 // accessing the value
38 // -------------------
39
40 // SetValue() generates a text change event, ChangeValue() doesn't
41 virtual void SetValue(const wxString& value)
42 { DoSetValue(value, SetValue_SendEvent); }
7bfc104b 43 virtual void ChangeValue(const wxString& value);
0ec1179b
VZ
44
45 // writing text inserts it at the current position replacing any current
46 // selection, appending always inserts it at the end and doesn't remove any
47 // existing text (but it will reset the selection if there is any)
48 virtual void WriteText(const wxString& text) = 0;
49 virtual void AppendText(const wxString& text);
50
135b23b2 51 virtual wxString GetValue() const;
0ec1179b 52 virtual wxString GetRange(long from, long to) const;
a7507230 53 bool IsEmpty() const { return GetLastPosition() <= 0; }
0ec1179b
VZ
54
55
56 // editing operations
57 // ------------------
58
59 virtual void Replace(long from, long to, const wxString& value);
60 virtual void Remove(long from, long to) = 0;
61 virtual void Clear() { SetValue(wxString()); }
5a25f858 62 void RemoveSelection();
0ec1179b
VZ
63
64
65 // clipboard operations
66 // --------------------
67
68 virtual void Copy() = 0;
69 virtual void Cut() = 0;
70 virtual void Paste() = 0;
71
72 virtual bool CanCopy() const;
73 virtual bool CanCut() const;
74 virtual bool CanPaste() const;
75
76 // undo/redo
77 // ---------
78
79 virtual void Undo() = 0;
80 virtual void Redo() = 0;
81
82 virtual bool CanUndo() const = 0;
83 virtual bool CanRedo() const = 0;
84
85
86 // insertion point
87 // ---------------
88
89 // note that moving insertion point removes any current selection
90 virtual void SetInsertionPoint(long pos) = 0;
91 virtual void SetInsertionPointEnd() { SetInsertionPoint(-1); }
92 virtual long GetInsertionPoint() const = 0;
93 virtual long GetLastPosition() const = 0;
94
95
96 // selection
97 // ---------
98
99 virtual void SetSelection(long from, long to) = 0;
e0721133 100 virtual void SelectAll() { SetSelection(-1, -1); }
0ec1179b
VZ
101 virtual void GetSelection(long *from, long *to) const = 0;
102 bool HasSelection() const;
103 virtual wxString GetStringSelection() const;
104
978c6e41 105
ecaed0bc
VZ
106 // auto-completion
107 // ---------------
108
59396417
VZ
109 // these functions allow to auto-complete the text already entered into the
110 // control using either the given fixed list of strings, the paths from the
ea98f11c 111 // file system or an arbitrary user-defined completer
59396417
VZ
112 //
113 // they all return true if completion was enabled or false on error (most
114 // commonly meaning that this functionality is not available under the
115 // current platform)
116
574479e8
VZ
117 bool AutoComplete(const wxArrayString& choices)
118 { return DoAutoCompleteStrings(choices); }
59396417 119
574479e8 120 bool AutoCompleteFileNames()
03dede4d
VZ
121 { return DoAutoCompleteFileNames(wxFILE); }
122
123 bool AutoCompleteDirectories()
124 { return DoAutoCompleteFileNames(wxDIR); }
ecaed0bc 125
ea98f11c
VZ
126 // notice that we take ownership of the pointer and will delete it
127 //
128 // if the pointer is NULL auto-completion is disabled
129 bool AutoComplete(wxTextCompleter *completer)
130 { return DoAutoCompleteCustom(completer); }
131
0ec1179b
VZ
132
133 // status
134 // ------
ecaed0bc 135
0ec1179b
VZ
136 virtual bool IsEditable() const = 0;
137 virtual void SetEditable(bool editable) = 0;
138
139
140 // set the max number of characters which may be entered in a single line
141 // text control
142 virtual void SetMaxLength(unsigned long WXUNUSED(len)) { }
143
144
63f7d502
VZ
145 // hints
146 // -----
147
148 // hint is the (usually greyed out) text shown in the control as long as
149 // it's empty and doesn't have focus, it is typically used in controls used
150 // for searching to let the user know what is supposed to be entered there
151
152 virtual bool SetHint(const wxString& hint);
153 virtual wxString GetHint() const;
154
155
0847e36e
JS
156 // margins
157 // -------
158
159 // margins are the empty space between borders of control and the text
160 // itself. When setting margin, use value -1 to indicate that specific
161 // margin should not be changed.
162
163 bool SetMargins(const wxPoint& pt)
164 { return DoSetMargins(pt); }
165 bool SetMargins(wxCoord left, wxCoord top = -1)
166 { return DoSetMargins(wxPoint(left, top)); }
167 wxPoint GetMargins() const
168 { return DoGetMargins(); }
169
50135807 170
356fd0b5
VZ
171 // implementation only
172 // -------------------
50135807
VZ
173
174 // generate the wxEVT_COMMAND_TEXT_UPDATED event for GetEditableWindow(),
175 // like SetValue() does and return true if the event was processed
176 //
177 // NB: this is public for wxRichTextCtrl use only right now, do not call it
178 static bool SendTextUpdatedEvent(wxWindow *win);
179
e793ec14
VZ
180 // generate the wxEVT_COMMAND_TEXT_UPDATED event for this window
181 bool SendTextUpdatedEvent()
182 {
183 return SendTextUpdatedEvent(GetEditableWindow());
184 }
185
186
4275201b
SC
187 // generate the wxEVT_COMMAND_TEXT_UPDATED event for this window if the
188 // events are not currently disabled
189 void SendTextUpdatedEventIfAllowed()
190 {
191 if ( EventsAllowed() )
192 SendTextUpdatedEvent();
193 }
194
356fd0b5
VZ
195 // this function is provided solely for the purpose of forwarding text
196 // change notifications state from one control to another, e.g. it can be
197 // used by a wxComboBox which derives from wxTextEntry if it delegates all
198 // of its methods to another wxTextCtrl
199 void ForwardEnableTextChangedEvents(bool enable)
200 {
201 // it's important to call the functions which update m_eventsBlock here
202 // and not just our own EnableTextChangedEvents() because our state
203 // (i.e. the result of EventsAllowed()) must change as well
204 if ( enable )
205 ResumeTextChangedEvents();
206 else
207 SuppressTextChangedEvents();
208 }
209
0ec1179b
VZ
210protected:
211 // flags for DoSetValue(): common part of SetValue() and ChangeValue() and
212 // also used to implement WriteText() in wxMSW
213 enum
214 {
215 SetValue_NoEvent = 0,
216 SetValue_SendEvent = 1,
217 SetValue_SelectionOnly = 2
218 };
219
220 virtual void DoSetValue(const wxString& value, int flags);
135b23b2 221 virtual wxString DoGetValue() const = 0;
0ec1179b 222
4ba5f250
VZ
223 // override this to return the associated window, it will be used for event
224 // generation and also by generic hints implementation
225 virtual wxWindow *GetEditableWindow() = 0;
226
0847e36e
JS
227 // margins functions
228 virtual bool DoSetMargins(const wxPoint& pt);
229 virtual wxPoint DoGetMargins() const;
230
574479e8
VZ
231 // the derived classes should override these virtual methods to implement
232 // auto-completion, they do the same thing as their public counterparts but
233 // have different names to allow overriding just one of them without hiding
234 // the other one(s)
235 virtual bool DoAutoCompleteStrings(const wxArrayString& WXUNUSED(choices))
236 { return false; }
03dede4d
VZ
237 virtual bool DoAutoCompleteFileNames(int WXUNUSED(flags)) // wxFILE | wxDIR
238 { return false; }
ea98f11c 239 virtual bool DoAutoCompleteCustom(wxTextCompleter *completer);
574479e8 240
4ba5f250 241
0ec1179b
VZ
242 // class which should be used to temporarily disable text change events
243 //
244 // if suppress argument in ctor is false, nothing is done
245 class EventsSuppressor
246 {
247 public:
248 EventsSuppressor(wxTextEntryBase *text, bool suppress = true)
3b49331b
VZ
249 : m_text(text),
250 m_suppress(suppress)
0ec1179b 251 {
0ec1179b 252 if ( m_suppress )
0ec1179b 253 m_text->SuppressTextChangedEvents();
0ec1179b
VZ
254 }
255
256 ~EventsSuppressor()
257 {
258 if ( m_suppress )
259 m_text->ResumeTextChangedEvents();
260 }
261
262 private:
263 wxTextEntryBase *m_text;
264 bool m_suppress;
265 };
3b49331b 266
558820fd 267 friend class EventsSuppressor;
0ec1179b 268
0ec1179b
VZ
269private:
270 // suppress or resume the text changed events generation: don't use these
271 // functions directly, use EventsSuppressor class above instead
272 void SuppressTextChangedEvents()
273 {
274 if ( !m_eventsBlock++ )
275 EnableTextChangedEvents(false);
276 }
277
278 void ResumeTextChangedEvents()
279 {
280 if ( !--m_eventsBlock )
281 EnableTextChangedEvents(true);
282 }
283
284
285 // this must be overridden in the derived classes if our implementation of
286 // SetValue() or Replace() is used to disable (and enable back) generation
287 // of the text changed events
288 //
289 // initially the generation of the events is enabled
290 virtual void EnableTextChangedEvents(bool WXUNUSED(enable)) { }
291
50135807
VZ
292 // return true if the events are currently not suppressed
293 bool EventsAllowed() const { return m_eventsBlock == 0; }
294
295
0ec1179b
VZ
296 // if this counter is non-null, events are blocked
297 unsigned m_eventsBlock;
63f7d502
VZ
298
299 // hint-related stuff, only allocated if/when SetHint() is used
300 wxTextEntryHintData *m_hintData;
a7aeddac
VZ
301
302 // It needs to call our Do{Get,Set}Value() to work with the real control
303 // contents.
304 friend class wxTextEntryHintData;
0ec1179b
VZ
305};
306
2978a784
VZ
307#ifdef __WXUNIVERSAL__
308 // TODO: we need to use wxTextEntryDelegate here, but for now just prevent
309 // the GTK/MSW classes from being used in wxUniv build
310 class WXDLLIMPEXP_CORE wxTextEntry : public wxTextEntryBase
311 {
312 };
313#elif defined(__WXGTK20__)
0ec1179b 314 #include "wx/gtk/textentry.h"
c84030e0
KO
315#elif defined(__WXMAC__)
316 #include "wx/osx/textentry.h"
fa2f57be
VZ
317#elif defined(__WXMSW__)
318 #include "wx/msw/textentry.h"
978c6e41
VZ
319#elif defined(__WXMOTIF__)
320 #include "wx/motif/textentry.h"
72cb72bf
SN
321#elif defined(__WXPM__)
322 #include "wx/os2/textentry.h"
0ec1179b
VZ
323#else
324 // no platform-specific implementation of wxTextEntry yet
325 class WXDLLIMPEXP_CORE wxTextEntry : public wxTextEntryBase
326 {
327 };
328#endif
329
330#endif // _WX_TEXTENTRY_H_
331