]> git.saurik.com Git - wxWidgets.git/blob - src/osx/textentry_osx.cpp
Draw the underline 1 pixel higher in wxDC::DrawLabel().
[wxWidgets.git] / src / osx / textentry_osx.cpp
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
7 // RCS-ID: $Id$
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"
48
49 #include "wx/osx/private.h"
50
51 wxString wxTextEntry::DoGetValue() const
52 {
53 return GetTextPeer()->GetStringValue() ;
54 }
55
56 void wxTextEntry::GetSelection(long* from, long* to) const
57 {
58 GetTextPeer()->GetSelection( from , to ) ;
59 }
60
61 void wxTextEntry::SetMaxLength(unsigned long len)
62 {
63 m_maxLength = len ;
64 }
65
66 // Clipboard operations
67
68 void wxTextEntry::Copy()
69 {
70 if (CanCopy())
71 GetTextPeer()->Copy() ;
72 }
73
74 void wxTextEntry::Cut()
75 {
76 if (CanCut())
77 GetTextPeer()->Cut() ;
78 }
79
80 void wxTextEntry::Paste()
81 {
82 if (CanPaste())
83 GetTextPeer()->Paste() ;
84 }
85
86 bool wxTextEntry::CanCopy() const
87 {
88 // Can copy if there's a selection
89 long from, to;
90 GetSelection( &from, &to );
91
92 return (from != to);
93 }
94
95 bool wxTextEntry::CanCut() const
96 {
97 if ( !IsEditable() )
98 return false;
99
100 // Can cut if there's a selection
101 long from, to;
102 GetSelection( &from, &to );
103
104 return (from != to);
105 }
106
107 bool wxTextEntry::CanPaste() const
108 {
109 if (!IsEditable())
110 return false;
111
112 return GetTextPeer()->CanPaste() ;
113 }
114
115 void wxTextEntry::SetEditable(bool editable)
116 {
117 if ( editable != m_editable )
118 {
119 m_editable = editable ;
120 GetTextPeer()->SetEditable( editable ) ;
121 }
122 }
123
124 void wxTextEntry::SetInsertionPoint(long pos)
125 {
126 SetSelection( pos , pos ) ;
127 }
128
129 void wxTextEntry::SetInsertionPointEnd()
130 {
131 long pos = GetLastPosition();
132 SetInsertionPoint( pos );
133 }
134
135 long wxTextEntry::GetInsertionPoint() const
136 {
137 long begin, end ;
138 GetSelection( &begin , &end ) ;
139
140 return begin ;
141 }
142
143 wxTextPos wxTextEntry::GetLastPosition() const
144 {
145 return GetTextPeer()->GetLastPosition() ;
146 }
147
148 void wxTextEntry::Remove(long from, long to)
149 {
150 {
151 EventsSuppressor noevents(this);
152 GetTextPeer()->Remove( from , to );
153 }
154
155 SendTextUpdatedEventIfAllowed();
156 }
157
158 void wxTextEntry::SetSelection(long from, long to)
159 {
160 GetTextPeer()->SetSelection( from , to ) ;
161 }
162
163 void wxTextEntry::WriteText(const wxString& str)
164 {
165 {
166 EventsSuppressor noevents(this);
167 GetTextPeer()->WriteText( str );
168 }
169
170 SendTextUpdatedEventIfAllowed();
171 }
172
173 void wxTextEntry::Clear()
174 {
175 {
176 EventsSuppressor noevents(this);
177 GetTextPeer()->Clear();
178 }
179
180 SendTextUpdatedEventIfAllowed();
181 }
182
183 bool wxTextEntry::IsEditable() const
184 {
185 return m_editable ;
186 }
187
188 // ----------------------------------------------------------------------------
189 // Undo/redo
190 // ----------------------------------------------------------------------------
191
192 void wxTextEntry::Undo()
193 {
194 if (CanUndo())
195 GetTextPeer()->Undo() ;
196 }
197
198 void wxTextEntry::Redo()
199 {
200 if (CanRedo())
201 GetTextPeer()->Redo() ;
202 }
203
204 bool wxTextEntry::CanUndo() const
205 {
206 if ( !IsEditable() )
207 return false ;
208
209 return GetTextPeer()->CanUndo() ;
210 }
211
212 bool wxTextEntry::CanRedo() const
213 {
214 if ( !IsEditable() )
215 return false ;
216
217 return GetTextPeer()->CanRedo() ;
218 }
219
220 wxTextWidgetImpl * wxTextEntry::GetTextPeer() const
221 {
222 wxWindow * const win = const_cast<wxTextEntry *>(this)->GetEditableWindow();
223
224 return win ? dynamic_cast<wxTextWidgetImpl *>(win->GetPeer()) : NULL;
225 }
226
227 #endif // wxUSE_TEXTCTRL