]>
Commit | Line | Data |
---|---|---|
c84030e0 KO |
1 | ///////////////////////////////////////////////////////////////////////////// |
2 | // Name: src/osx/textentry_osx.cpp | |
3 | // Purpose: wxTextEntry | |
4 | // Author: Stefan Csomor | |
5 | // Modified by: Kevin Ollivier | |
6 | // Created: 1998-01-01 | |
b5b208a1 | 7 | // RCS-ID: $Id$ |
c84030e0 KO |
8 | // Copyright: (c) Stefan Csomor |
9 | // Licence: wxWindows licence | |
10 | ///////////////////////////////////////////////////////////////////////////// | |
11 | ||
12 | #include "wx/wxprec.h" | |
13 | ||
14 | #if wxUSE_TEXTCTRL | |
15 | ||
16 | #include "wx/textctrl.h" | |
17 | ||
18 | #ifndef WX_PRECOMP | |
19 | #include "wx/intl.h" | |
20 | #include "wx/app.h" | |
21 | #include "wx/utils.h" | |
22 | #include "wx/dc.h" | |
23 | #include "wx/button.h" | |
24 | #include "wx/menu.h" | |
25 | #include "wx/settings.h" | |
26 | #include "wx/msgdlg.h" | |
27 | #include "wx/toplevel.h" | |
28 | #endif | |
29 | ||
30 | #ifdef __DARWIN__ | |
31 | #include <sys/types.h> | |
32 | #include <sys/stat.h> | |
33 | #else | |
34 | #include <stat.h> | |
35 | #endif | |
36 | ||
37 | #if wxUSE_STD_IOSTREAM | |
38 | #if wxUSE_IOSTREAMH | |
39 | #include <fstream.h> | |
40 | #else | |
41 | #include <fstream> | |
42 | #endif | |
43 | #endif | |
44 | ||
45 | #include "wx/filefn.h" | |
46 | #include "wx/sysopt.h" | |
47 | #include "wx/thread.h" | |
c729f16f | 48 | #include "wx/textcompleter.h" |
c84030e0 KO |
49 | |
50 | #include "wx/osx/private.h" | |
51 | ||
c729f16f VZ |
52 | wxTextEntry::wxTextEntry() |
53 | { | |
54 | m_completer = NULL; | |
55 | m_editable = true; | |
56 | m_maxLength = 0; | |
57 | } | |
58 | ||
59 | wxTextEntry::~wxTextEntry() | |
60 | { | |
61 | delete m_completer; | |
62 | } | |
63 | ||
c84030e0 KO |
64 | wxString wxTextEntry::DoGetValue() const |
65 | { | |
66 | return GetTextPeer()->GetStringValue() ; | |
67 | } | |
68 | ||
69 | void wxTextEntry::GetSelection(long* from, long* to) const | |
70 | { | |
71 | GetTextPeer()->GetSelection( from , to ) ; | |
72 | } | |
73 | ||
74 | void wxTextEntry::SetMaxLength(unsigned long len) | |
75 | { | |
76 | m_maxLength = len ; | |
77 | } | |
78 | ||
79 | // Clipboard operations | |
80 | ||
81 | void wxTextEntry::Copy() | |
82 | { | |
83 | if (CanCopy()) | |
84 | GetTextPeer()->Copy() ; | |
85 | } | |
86 | ||
87 | void wxTextEntry::Cut() | |
88 | { | |
89 | if (CanCut()) | |
90 | GetTextPeer()->Cut() ; | |
91 | } | |
92 | ||
93 | void wxTextEntry::Paste() | |
94 | { | |
95 | if (CanPaste()) | |
96 | GetTextPeer()->Paste() ; | |
97 | } | |
98 | ||
99 | bool wxTextEntry::CanCopy() const | |
100 | { | |
101 | // Can copy if there's a selection | |
102 | long from, to; | |
103 | GetSelection( &from, &to ); | |
104 | ||
105 | return (from != to); | |
106 | } | |
107 | ||
108 | bool wxTextEntry::CanCut() const | |
109 | { | |
110 | if ( !IsEditable() ) | |
111 | return false; | |
112 | ||
113 | // Can cut if there's a selection | |
114 | long from, to; | |
115 | GetSelection( &from, &to ); | |
116 | ||
117 | return (from != to); | |
118 | } | |
119 | ||
120 | bool wxTextEntry::CanPaste() const | |
121 | { | |
122 | if (!IsEditable()) | |
123 | return false; | |
124 | ||
125 | return GetTextPeer()->CanPaste() ; | |
126 | } | |
127 | ||
128 | void wxTextEntry::SetEditable(bool editable) | |
129 | { | |
130 | if ( editable != m_editable ) | |
131 | { | |
132 | m_editable = editable ; | |
133 | GetTextPeer()->SetEditable( editable ) ; | |
134 | } | |
135 | } | |
136 | ||
137 | void wxTextEntry::SetInsertionPoint(long pos) | |
138 | { | |
139 | SetSelection( pos , pos ) ; | |
140 | } | |
141 | ||
142 | void wxTextEntry::SetInsertionPointEnd() | |
143 | { | |
144 | long pos = GetLastPosition(); | |
145 | SetInsertionPoint( pos ); | |
146 | } | |
147 | ||
148 | long wxTextEntry::GetInsertionPoint() const | |
149 | { | |
150 | long begin, end ; | |
151 | GetSelection( &begin , &end ) ; | |
152 | ||
153 | return begin ; | |
154 | } | |
155 | ||
156 | wxTextPos wxTextEntry::GetLastPosition() const | |
157 | { | |
158 | return GetTextPeer()->GetLastPosition() ; | |
159 | } | |
160 | ||
161 | void wxTextEntry::Remove(long from, long to) | |
162 | { | |
4275201b SC |
163 | { |
164 | EventsSuppressor noevents(this); | |
165 | GetTextPeer()->Remove( from , to ); | |
166 | } | |
ce00f59b | 167 | |
e567904a | 168 | SendTextUpdatedEventIfAllowed(); |
c84030e0 KO |
169 | } |
170 | ||
171 | void wxTextEntry::SetSelection(long from, long to) | |
172 | { | |
173 | GetTextPeer()->SetSelection( from , to ) ; | |
174 | } | |
175 | ||
176 | void wxTextEntry::WriteText(const wxString& str) | |
177 | { | |
4275201b SC |
178 | { |
179 | EventsSuppressor noevents(this); | |
180 | GetTextPeer()->WriteText( str ); | |
181 | } | |
e567904a VZ |
182 | |
183 | SendTextUpdatedEventIfAllowed(); | |
c84030e0 KO |
184 | } |
185 | ||
186 | void wxTextEntry::Clear() | |
187 | { | |
4275201b SC |
188 | { |
189 | EventsSuppressor noevents(this); | |
190 | GetTextPeer()->Clear(); | |
191 | } | |
e567904a VZ |
192 | |
193 | SendTextUpdatedEventIfAllowed(); | |
c84030e0 KO |
194 | } |
195 | ||
196 | bool wxTextEntry::IsEditable() const | |
197 | { | |
198 | return m_editable ; | |
199 | } | |
200 | ||
201 | // ---------------------------------------------------------------------------- | |
202 | // Undo/redo | |
203 | // ---------------------------------------------------------------------------- | |
204 | ||
205 | void wxTextEntry::Undo() | |
206 | { | |
207 | if (CanUndo()) | |
208 | GetTextPeer()->Undo() ; | |
209 | } | |
210 | ||
211 | void wxTextEntry::Redo() | |
212 | { | |
213 | if (CanRedo()) | |
214 | GetTextPeer()->Redo() ; | |
215 | } | |
216 | ||
217 | bool wxTextEntry::CanUndo() const | |
218 | { | |
219 | if ( !IsEditable() ) | |
220 | return false ; | |
221 | ||
222 | return GetTextPeer()->CanUndo() ; | |
223 | } | |
224 | ||
225 | bool wxTextEntry::CanRedo() const | |
226 | { | |
227 | if ( !IsEditable() ) | |
228 | return false ; | |
229 | ||
230 | return GetTextPeer()->CanRedo() ; | |
231 | } | |
232 | ||
233 | wxTextWidgetImpl * wxTextEntry::GetTextPeer() const | |
234 | { | |
005ac806 VZ |
235 | wxWindow * const win = const_cast<wxTextEntry *>(this)->GetEditableWindow(); |
236 | ||
237 | return win ? dynamic_cast<wxTextWidgetImpl *>(win->GetPeer()) : NULL; | |
c84030e0 | 238 | } |
005ac806 | 239 | |
c729f16f VZ |
240 | // ---------------------------------------------------------------------------- |
241 | // Auto-completion | |
242 | // ---------------------------------------------------------------------------- | |
243 | ||
244 | bool wxTextEntry::DoAutoCompleteStrings(const wxArrayString& choices) | |
245 | { | |
246 | wxTextCompleterFixed * const completer = new wxTextCompleterFixed; | |
247 | completer->SetCompletions(choices); | |
248 | ||
249 | return DoAutoCompleteCustom(completer); | |
250 | } | |
251 | ||
252 | bool wxTextEntry::DoAutoCompleteCustom(wxTextCompleter *completer) | |
253 | { | |
254 | m_completer = completer; | |
255 | ||
256 | return true; | |
257 | } | |
258 | ||
c84030e0 | 259 | #endif // wxUSE_TEXTCTRL |