]>
Commit | Line | Data |
---|---|---|
e9576ca5 | 1 | ///////////////////////////////////////////////////////////////////////////// |
faa94f3e | 2 | // Name: src/mac/carbon/textctrl.cpp |
e9576ca5 | 3 | // Purpose: wxTextCtrl |
a31a5f85 | 4 | // Author: Stefan Csomor |
6af16761 | 5 | // Modified by: Ryan Norton (MLTE GetLineLength and GetLineText) |
a31a5f85 | 6 | // Created: 1998-01-01 |
e9576ca5 | 7 | // RCS-ID: $Id$ |
a31a5f85 | 8 | // Copyright: (c) Stefan Csomor |
65571936 | 9 | // Licence: wxWindows licence |
e9576ca5 SC |
10 | ///////////////////////////////////////////////////////////////////////////// |
11 | ||
3d1a4878 | 12 | #include "wx/wxprec.h" |
fedad417 GD |
13 | |
14 | #if wxUSE_TEXTCTRL | |
15 | ||
88a7a4e1 WS |
16 | #include "wx/textctrl.h" |
17 | ||
18 | #ifndef WX_PRECOMP | |
19 | #include "wx/intl.h" | |
670f9935 | 20 | #include "wx/app.h" |
de6185e2 | 21 | #include "wx/utils.h" |
da80ae71 | 22 | #include "wx/dc.h" |
f1e01716 | 23 | #include "wx/button.h" |
3b3dc801 | 24 | #include "wx/menu.h" |
9eddec69 | 25 | #include "wx/settings.h" |
246c5004 | 26 | #include "wx/msgdlg.h" |
1832043f | 27 | #include "wx/toplevel.h" |
88a7a4e1 | 28 | #endif |
5ca0d812 | 29 | |
f5c6eb5c | 30 | #ifdef __DARWIN__ |
88a7a4e1 WS |
31 | #include <sys/types.h> |
32 | #include <sys/stat.h> | |
e9576ca5 | 33 | #else |
88a7a4e1 | 34 | #include <stat.h> |
e9576ca5 | 35 | #endif |
2b5f62a0 VZ |
36 | |
37 | #if wxUSE_STD_IOSTREAM | |
38 | #if wxUSE_IOSTREAMH | |
39 | #include <fstream.h> | |
40 | #else | |
41 | #include <fstream> | |
42 | #endif | |
43 | #endif | |
e9576ca5 | 44 | |
e9576ca5 | 45 | #include "wx/filefn.h" |
823c4e96 | 46 | #include "wx/sysopt.h" |
e9576ca5 | 47 | |
fef981b4 | 48 | #include "wx/mac/uma.h" |
3f7f284d | 49 | #include "wx/mac/carbon/private/mactext.h" |
fef981b4 | 50 | |
5ca0d812 | 51 | class wxMacFunctor |
587bc950 | 52 | { |
7d8268a1 | 53 | public : |
a8d2fb31 | 54 | wxMacFunctor() {} |
5ca0d812 | 55 | virtual ~wxMacFunctor() {} |
fef981b4 | 56 | |
5ca0d812 | 57 | virtual void* operator()() = 0 ; |
fef981b4 | 58 | |
c88b7d28 | 59 | static void* CallBackProc( void *param ) |
587bc950 | 60 | { |
5ca0d812 SC |
61 | wxMacFunctor* f = (wxMacFunctor*) param ; |
62 | void *result = (*f)() ; | |
63 | return result ; | |
587bc950 | 64 | } |
5ca0d812 | 65 | } ; |
587bc950 | 66 | |
fef981b4 DS |
67 | template<typename classtype, typename param1type> |
68 | ||
5ca0d812 | 69 | class wxMacObjectFunctor1 : public wxMacFunctor |
587bc950 | 70 | { |
5ca0d812 SC |
71 | typedef void (classtype::*function)( param1type p1 ) ; |
72 | typedef void (classtype::*ref_function)( const param1type& p1 ) ; | |
7d8268a1 | 73 | public : |
5ca0d812 | 74 | wxMacObjectFunctor1( classtype *obj , function f , param1type p1 ) : |
fef981b4 | 75 | wxMacFunctor() |
587bc950 | 76 | { |
5ca0d812 SC |
77 | m_object = obj ; |
78 | m_function = f ; | |
79 | m_param1 = p1 ; | |
587bc950 | 80 | } |
587bc950 | 81 | |
5ca0d812 | 82 | wxMacObjectFunctor1( classtype *obj , ref_function f , param1type p1 ) : |
fef981b4 | 83 | wxMacFunctor() |
5ca0d812 SC |
84 | { |
85 | m_object = obj ; | |
86 | m_refFunction = f ; | |
87 | m_param1 = p1 ; | |
88 | } | |
587bc950 | 89 | |
d3c7fc99 | 90 | virtual ~wxMacObjectFunctor1() {} |
7d8268a1 WS |
91 | |
92 | virtual void* operator()() | |
587bc950 | 93 | { |
c88b7d28 | 94 | (m_object->*m_function)( m_param1 ) ; |
5ca0d812 SC |
95 | return NULL ; |
96 | } | |
a8d2fb31 | 97 | |
5ca0d812 SC |
98 | private : |
99 | classtype* m_object ; | |
100 | param1type m_param1 ; | |
101 | union | |
102 | { | |
fef981b4 DS |
103 | function m_function ; |
104 | ref_function m_refFunction ; | |
587bc950 | 105 | } ; |
5ca0d812 | 106 | } ; |
587bc950 | 107 | |
7d8268a1 | 108 | template<typename classtype, typename param1type> |
5ca0d812 SC |
109 | void* wxMacMPRemoteCall( classtype *object , void (classtype::*function)( param1type p1 ) , param1type p1 ) |
110 | { | |
fef981b4 | 111 | wxMacObjectFunctor1<classtype, param1type> params(object, function, p1) ; |
7d8268a1 | 112 | void *result = |
fef981b4 | 113 | MPRemoteCall( wxMacFunctor::CallBackProc , ¶ms , kMPOwningProcessRemoteContext ) ; |
5ca0d812 SC |
114 | return result ; |
115 | } | |
587bc950 | 116 | |
7d8268a1 | 117 | template<typename classtype, typename param1type> |
5ca0d812 SC |
118 | void* wxMacMPRemoteCall( classtype *object , void (classtype::*function)( const param1type& p1 ) , param1type p1 ) |
119 | { | |
fef981b4 | 120 | wxMacObjectFunctor1<classtype,param1type> params(object, function, p1) ; |
7d8268a1 | 121 | void *result = |
fef981b4 | 122 | MPRemoteCall( wxMacFunctor::CallBackProc , ¶ms , kMPOwningProcessRemoteContext ) ; |
5ca0d812 | 123 | return result ; |
587bc950 SC |
124 | } |
125 | ||
7d8268a1 | 126 | template<typename classtype, typename param1type> |
5ca0d812 SC |
127 | void* wxMacMPRemoteGUICall( classtype *object , void (classtype::*function)( param1type p1 ) , param1type p1 ) |
128 | { | |
129 | wxMutexGuiLeave() ; | |
130 | void *result = wxMacMPRemoteCall( object , function , p1 ) ; | |
131 | wxMutexGuiEnter() ; | |
132 | return result ; | |
133 | } | |
29b30405 | 134 | |
7d8268a1 | 135 | template<typename classtype, typename param1type> |
5ca0d812 SC |
136 | void* wxMacMPRemoteGUICall( classtype *object , void (classtype::*function)( const param1type& p1 ) , param1type p1 ) |
137 | { | |
138 | wxMutexGuiLeave() ; | |
139 | void *result = wxMacMPRemoteCall( object , function , p1 ) ; | |
140 | wxMutexGuiEnter() ; | |
141 | return result ; | |
142 | } | |
a8d2fb31 | 143 | |
72055702 | 144 | |
5ca0d812 | 145 | // common parts for implementations based on MLTE |
72055702 | 146 | |
5ca0d812 SC |
147 | class wxMacMLTEControl : public wxMacTextControl |
148 | { | |
149 | public : | |
789ae0cf | 150 | wxMacMLTEControl( wxTextCtrl *peer ) ; |
c88b7d28 | 151 | |
5ca0d812 | 152 | virtual wxString GetStringValue() const ; |
c88b7d28 | 153 | virtual void SetStringValue( const wxString &str ) ; |
7d8268a1 | 154 | |
5ca0d812 | 155 | static TXNFrameOptions FrameOptionsFromWXStyle( long wxStyle ) ; |
fef981b4 | 156 | |
c88b7d28 | 157 | void AdjustCreationAttributes( const wxColour& background, bool visible ) ; |
5ca0d812 | 158 | |
c88b7d28 DS |
159 | virtual void SetFont( const wxFont & font, const wxColour& foreground, long windowStyle ) ; |
160 | virtual void SetBackground( const wxBrush &brush ) ; | |
161 | virtual void SetStyle( long start, long end, const wxTextAttr& style ) ; | |
5ca0d812 SC |
162 | virtual void Copy() ; |
163 | virtual void Cut() ; | |
164 | virtual void Paste() ; | |
165 | virtual bool CanPaste() const ; | |
c88b7d28 | 166 | virtual void SetEditable( bool editable ) ; |
7d8268a1 | 167 | virtual wxTextPos GetLastPosition() const ; |
c88b7d28 DS |
168 | virtual void Replace( long from, long to, const wxString &str ) ; |
169 | virtual void Remove( long from, long to ) ; | |
170 | virtual void GetSelection( long* from, long* to ) const ; | |
171 | virtual void SetSelection( long from, long to ) ; | |
7d8268a1 | 172 | |
c88b7d28 | 173 | virtual void WriteText( const wxString& str ) ; |
fef981b4 | 174 | |
0207e969 DS |
175 | virtual bool HasOwnContextMenu() const |
176 | { | |
d8f3e9da SC |
177 | TXNCommandEventSupportOptions options ; |
178 | TXNGetCommandEventSupport( m_txn , & options ) ; | |
179 | return options & kTXNSupportEditCommandProcessing ; | |
64bd657c SC |
180 | } |
181 | ||
6df87058 KO |
182 | virtual void CheckSpelling(bool check) |
183 | { | |
d8f3e9da | 184 | TXNSetSpellCheckAsYouType( m_txn, (Boolean) check ); |
6df87058 | 185 | } |
5ca0d812 SC |
186 | virtual void Clear() ; |
187 | ||
188 | virtual bool CanUndo() const ; | |
189 | virtual void Undo() ; | |
190 | virtual bool CanRedo() const; | |
191 | virtual void Redo() ; | |
192 | virtual int GetNumberOfLines() const ; | |
193 | virtual long XYToPosition(long x, long y) const ; | |
194 | virtual bool PositionToXY(long pos, long *x, long *y) const ; | |
195 | virtual void ShowPosition( long pos ) ; | |
196 | virtual int GetLineLength(long lineNo) const ; | |
197 | virtual wxString GetLineText(long lineNo) const ; | |
198 | ||
199 | void SetTXNData( const wxString& st , TXNOffset start , TXNOffset end ) ; | |
09660720 | 200 | TXNObject GetTXNObject() { return m_txn ; } |
5ca0d812 SC |
201 | |
202 | protected : | |
8623a883 | 203 | void TXNSetAttribute( const wxTextAttr& style , long from , long to ) ; |
fef981b4 | 204 | |
5ca0d812 SC |
205 | TXNObject m_txn ; |
206 | } ; | |
72055702 | 207 | |
5ca0d812 SC |
208 | // implementation available under OSX |
209 | ||
7d8268a1 | 210 | class wxMacMLTEHIViewControl : public wxMacMLTEControl |
5ca0d812 SC |
211 | { |
212 | public : | |
0f7817ab | 213 | wxMacMLTEHIViewControl( wxTextCtrl *wxPeer, |
5ca0d812 SC |
214 | const wxString& str, |
215 | const wxPoint& pos, | |
216 | const wxSize& size, long style ) ; | |
d3c7fc99 | 217 | virtual ~wxMacMLTEHIViewControl() ; |
9eddec69 | 218 | |
5ca0d812 SC |
219 | virtual OSStatus SetFocus( ControlFocusPart focusPart ) ; |
220 | virtual bool HasFocus() const ; | |
44aa865d | 221 | virtual void SetBackground( const wxBrush &brush) ; |
a8d2fb31 | 222 | |
5ca0d812 SC |
223 | protected : |
224 | HIViewRef m_scrollView ; | |
225 | HIViewRef m_textView ; | |
fef981b4 | 226 | }; |
ef4a634b | 227 | |
24260aae | 228 | // 'classic' MLTE implementation |
72055702 | 229 | |
5ca0d812 SC |
230 | class wxMacMLTEClassicControl : public wxMacMLTEControl |
231 | { | |
232 | public : | |
0f7817ab | 233 | wxMacMLTEClassicControl( wxTextCtrl *wxPeer, |
5ca0d812 SC |
234 | const wxString& str, |
235 | const wxPoint& pos, | |
236 | const wxSize& size, long style ) ; | |
d3c7fc99 | 237 | virtual ~wxMacMLTEClassicControl() ; |
ffafe6ca | 238 | |
5ca0d812 | 239 | virtual void VisibilityChanged(bool shown) ; |
4e477040 | 240 | virtual void SuperChangedPosition() ; |
24260aae SC |
241 | |
242 | virtual void MacControlUserPaneDrawProc(wxInt16 part) ; | |
243 | virtual wxInt16 MacControlUserPaneHitTestProc(wxInt16 x, wxInt16 y) ; | |
244 | virtual wxInt16 MacControlUserPaneTrackingProc(wxInt16 x, wxInt16 y, void* actionProc) ; | |
245 | virtual void MacControlUserPaneIdleProc() ; | |
246 | virtual wxInt16 MacControlUserPaneKeyDownProc(wxInt16 keyCode, wxInt16 charCode, wxInt16 modifiers) ; | |
247 | virtual void MacControlUserPaneActivateProc(bool activating) ; | |
248 | virtual wxInt16 MacControlUserPaneFocusProc(wxInt16 action) ; | |
249 | virtual void MacControlUserPaneBackgroundProc(void* info) ; | |
250 | ||
ffafe6ca DS |
251 | virtual bool SetupCursor( const wxPoint& WXUNUSED(pt) ) |
252 | { | |
253 | MacControlUserPaneIdleProc(); | |
254 | return true; | |
255 | } | |
f2c3f2a8 | 256 | |
0f7817ab SC |
257 | virtual void SetRect( Rect *r ) ; |
258 | ||
5ca0d812 SC |
259 | protected : |
260 | OSStatus DoCreate(); | |
3dee36ae | 261 | |
0f7817ab | 262 | void MacUpdatePosition() ; |
fef981b4 DS |
263 | void MacActivatePaneText(bool setActive) ; |
264 | void MacFocusPaneText(bool setFocus) ; | |
265 | void MacSetObjectVisibility(bool vis) ; | |
a8d2fb31 | 266 | |
0f7817ab SC |
267 | private : |
268 | TXNFrameID m_txnFrameID ; | |
269 | GrafPtr m_txnPort ; | |
5de694f0 | 270 | WindowRef m_txnWindow ; |
0f7817ab SC |
271 | // bounds of the control as we last did set the txn frames |
272 | Rect m_txnControlBounds ; | |
ba75e603 | 273 | Rect m_txnVisBounds ; |
fef981b4 | 274 | |
fef981b4 DS |
275 | static pascal void TXNScrollActionProc( ControlRef controlRef , ControlPartCode partCode ) ; |
276 | static pascal void TXNScrollInfoProc( | |
277 | SInt32 iValue, SInt32 iMaximumValue, | |
278 | TXNScrollBarOrientation iScrollBarOrientation, SInt32 iRefCon ) ; | |
279 | ||
4e477040 | 280 | ControlRef m_sbHorizontal ; |
5de694f0 | 281 | SInt32 m_lastHorizontalValue ; |
4e477040 | 282 | ControlRef m_sbVertical ; |
5de694f0 | 283 | SInt32 m_lastVerticalValue ; |
fef981b4 | 284 | }; |
facd6764 | 285 | |
fef981b4 | 286 | |
9d112688 | 287 | IMPLEMENT_DYNAMIC_CLASS(wxTextCtrl, wxTextCtrlBase) |
72055702 | 288 | |
9d112688 | 289 | BEGIN_EVENT_TABLE(wxTextCtrl, wxTextCtrlBase) |
7ea087b7 | 290 | EVT_ERASE_BACKGROUND( wxTextCtrl::OnEraseBackground ) |
5ca0d812 SC |
291 | EVT_DROP_FILES(wxTextCtrl::OnDropFiles) |
292 | EVT_CHAR(wxTextCtrl::OnChar) | |
293 | EVT_MENU(wxID_CUT, wxTextCtrl::OnCut) | |
294 | EVT_MENU(wxID_COPY, wxTextCtrl::OnCopy) | |
295 | EVT_MENU(wxID_PASTE, wxTextCtrl::OnPaste) | |
296 | EVT_MENU(wxID_UNDO, wxTextCtrl::OnUndo) | |
297 | EVT_MENU(wxID_REDO, wxTextCtrl::OnRedo) | |
24eef584 SC |
298 | EVT_MENU(wxID_CLEAR, wxTextCtrl::OnDelete) |
299 | EVT_MENU(wxID_SELECTALL, wxTextCtrl::OnSelectAll) | |
300 | ||
301 | EVT_CONTEXT_MENU(wxTextCtrl::OnContextMenu) | |
5ca0d812 SC |
302 | |
303 | EVT_UPDATE_UI(wxID_CUT, wxTextCtrl::OnUpdateCut) | |
304 | EVT_UPDATE_UI(wxID_COPY, wxTextCtrl::OnUpdateCopy) | |
305 | EVT_UPDATE_UI(wxID_PASTE, wxTextCtrl::OnUpdatePaste) | |
306 | EVT_UPDATE_UI(wxID_UNDO, wxTextCtrl::OnUpdateUndo) | |
307 | EVT_UPDATE_UI(wxID_REDO, wxTextCtrl::OnUpdateRedo) | |
24eef584 SC |
308 | EVT_UPDATE_UI(wxID_CLEAR, wxTextCtrl::OnUpdateDelete) |
309 | EVT_UPDATE_UI(wxID_SELECTALL, wxTextCtrl::OnUpdateSelectAll) | |
5ca0d812 | 310 | END_EVENT_TABLE() |
5ca0d812 | 311 | |
fef981b4 | 312 | |
a8d2fb31 | 313 | void wxTextCtrl::Init() |
facd6764 | 314 | { |
24eef584 SC |
315 | m_editable = true ; |
316 | m_dirty = false; | |
5ca0d812 | 317 | |
b9bae707 | 318 | m_maxLength = 0; |
c88b7d28 | 319 | m_privateContextMenu = NULL; |
51478cd6 | 320 | m_triggerOnSetValue = true ; |
facd6764 SC |
321 | } |
322 | ||
5ca0d812 | 323 | wxTextCtrl::~wxTextCtrl() |
facd6764 | 324 | { |
24eef584 | 325 | delete m_privateContextMenu; |
facd6764 SC |
326 | } |
327 | ||
ffafe6ca | 328 | bool wxTextCtrl::Create( wxWindow *parent, |
c88b7d28 DS |
329 | wxWindowID id, |
330 | const wxString& str, | |
331 | const wxPoint& pos, | |
332 | const wxSize& size, | |
333 | long style, | |
334 | const wxValidator& validator, | |
ffafe6ca | 335 | const wxString& name ) |
5ca0d812 | 336 | { |
7d8268a1 | 337 | m_macIsUserPane = false ; |
5ca0d812 SC |
338 | m_editable = true ; |
339 | ||
c88b7d28 DS |
340 | if ( ! (style & wxNO_BORDER) ) |
341 | style = (style & ~wxBORDER_MASK) | wxSUNKEN_BORDER ; | |
7d8268a1 | 342 | |
ffafe6ca | 343 | if ( !wxTextCtrlBase::Create( parent, id, pos, size, style & ~(wxHSCROLL | wxVSCROLL), validator, name ) ) |
7d8268a1 | 344 | return false; |
ef4a634b | 345 | |
5ca0d812 | 346 | if ( m_windowStyle & wxTE_MULTILINE ) |
facd6764 | 347 | { |
9e15c718 | 348 | // always turn on this style for multi-line controls |
5ca0d812 SC |
349 | m_windowStyle |= wxTE_PROCESS_ENTER; |
350 | style |= wxTE_PROCESS_ENTER ; | |
ed8c2780 | 351 | } |
3556e470 | 352 | |
3f7f284d RD |
353 | CreatePeer( str, pos, size, style ); |
354 | ||
355 | MacPostControlCreate(pos, size) ; | |
356 | ||
357 | // only now the embedding is correct and we can do a positioning update | |
358 | ||
359 | MacSuperChangedPosition() ; | |
360 | ||
361 | if ( m_windowStyle & wxTE_READONLY) | |
362 | SetEditable( false ) ; | |
363 | ||
364 | SetCursor( wxCursor( wxCURSOR_IBEAM ) ) ; | |
365 | ||
366 | return true; | |
367 | } | |
368 | ||
369 | void wxTextCtrl::CreatePeer( | |
370 | const wxString& str, | |
371 | const wxPoint& pos, | |
372 | const wxSize& size, long style ) | |
373 | { | |
4d7528a1 | 374 | bool forceMLTE = false ; |
fef981b4 | 375 | |
823c4e96 | 376 | #if wxUSE_SYSTEM_OPTIONS |
ffafe6ca | 377 | if (wxSystemOptions::HasOption( wxMAC_TEXTCONTROL_USE_MLTE ) && (wxSystemOptions::GetOptionInt( wxMAC_TEXTCONTROL_USE_MLTE ) == 1)) |
823c4e96 | 378 | { |
4d7528a1 | 379 | forceMLTE = true ; |
823c4e96 SC |
380 | } |
381 | #endif | |
4d7528a1 | 382 | |
6239ee05 SC |
383 | if ( UMAGetSystemVersion() >= 0x1050 ) |
384 | forceMLTE = false; | |
385 | ||
9d463591 | 386 | if ( !forceMLTE ) |
788e118f | 387 | { |
4d7528a1 SC |
388 | if ( m_windowStyle & wxTE_MULTILINE ) |
389 | m_peer = new wxMacMLTEHIViewControl( this , str , pos , size , style ) ; | |
788e118f | 390 | } |
fef981b4 | 391 | |
3556e470 | 392 | if ( !m_peer ) |
7d8268a1 | 393 | { |
c88b7d28 | 394 | if ( !(m_windowStyle & wxTE_MULTILINE) && !forceMLTE ) |
4f74e0d1 | 395 | { |
4d7528a1 | 396 | m_peer = new wxMacUnicodeTextControl( this , str , pos , size , style ) ; |
4f74e0d1 | 397 | } |
788e118f | 398 | } |
fef981b4 | 399 | |
6239ee05 SC |
400 | // the horizontal single line scrolling bug that made us keep the classic implementation |
401 | // is fixed in 10.5 | |
402 | #if MAC_OS_X_VERSION_MIN_REQUIRED < MAC_OS_X_VERSION_10_5 | |
3556e470 | 403 | if ( !m_peer ) |
3556e470 | 404 | m_peer = new wxMacMLTEClassicControl( this , str , pos , size , style ) ; |
4f74e0d1 | 405 | #endif |
facd6764 SC |
406 | } |
407 | ||
3dee36ae | 408 | void wxTextCtrl::MacSuperChangedPosition() |
4e477040 SC |
409 | { |
410 | wxWindow::MacSuperChangedPosition() ; | |
411 | GetPeer()->SuperChangedPosition() ; | |
412 | } | |
413 | ||
7d8268a1 | 414 | void wxTextCtrl::MacVisibilityChanged() |
5ca0d812 SC |
415 | { |
416 | GetPeer()->VisibilityChanged( MacIsReallyShown() ) ; | |
417 | } | |
facd6764 | 418 | |
7d8268a1 | 419 | void wxTextCtrl::MacEnabledStateChanged() |
5ca0d812 | 420 | { |
72055702 SC |
421 | } |
422 | ||
6df87058 KO |
423 | void wxTextCtrl::MacCheckSpelling(bool check) |
424 | { | |
425 | GetPeer()->CheckSpelling(check); | |
426 | } | |
427 | ||
5ca0d812 SC |
428 | wxString wxTextCtrl::GetValue() const |
429 | { | |
430 | return GetPeer()->GetStringValue() ; | |
431 | } | |
ef4a634b | 432 | |
5ca0d812 | 433 | void wxTextCtrl::GetSelection(long* from, long* to) const |
7d8268a1 | 434 | { |
5ca0d812 SC |
435 | GetPeer()->GetSelection( from , to ) ; |
436 | } | |
437 | ||
ee2ec18e | 438 | void wxTextCtrl::DoSetValue(const wxString& str, int flags) |
5ca0d812 SC |
439 | { |
440 | // optimize redraws | |
441 | if ( GetValue() == str ) | |
ee2ec18e | 442 | return; |
facd6764 | 443 | |
c88b7d28 | 444 | GetPeer()->SetStringValue( str ) ; |
e8b4fd4b | 445 | |
ee2ec18e | 446 | if ( (flags & SetValue_SendEvent) && m_triggerOnSetValue ) |
51478cd6 | 447 | { |
ee2ec18e | 448 | SendTextUpdatedEvent(); |
51478cd6 | 449 | } |
72055702 SC |
450 | } |
451 | ||
5ca0d812 SC |
452 | void wxTextCtrl::SetMaxLength(unsigned long len) |
453 | { | |
454 | m_maxLength = len ; | |
455 | } | |
72055702 | 456 | |
5ca0d812 SC |
457 | bool wxTextCtrl::SetFont( const wxFont& font ) |
458 | { | |
459 | if ( !wxTextCtrlBase::SetFont( font ) ) | |
7d8268a1 WS |
460 | return false ; |
461 | ||
5ca0d812 | 462 | GetPeer()->SetFont( font , GetForegroundColour() , GetWindowStyle() ) ; |
fef981b4 | 463 | |
5ca0d812 SC |
464 | return true ; |
465 | } | |
466 | ||
467 | bool wxTextCtrl::SetStyle(long start, long end, const wxTextAttr& style) | |
468 | { | |
469 | GetPeer()->SetStyle( start , end , style ) ; | |
fef981b4 | 470 | |
5ca0d812 SC |
471 | return true ; |
472 | } | |
473 | ||
474 | bool wxTextCtrl::SetDefaultStyle(const wxTextAttr& style) | |
475 | { | |
476 | wxTextCtrlBase::SetDefaultStyle( style ) ; | |
477 | SetStyle( kTXNUseCurrentSelection , kTXNUseCurrentSelection , GetDefaultStyle() ) ; | |
fef981b4 | 478 | |
7d8268a1 | 479 | return true ; |
5ca0d812 SC |
480 | } |
481 | ||
482 | // Clipboard operations | |
fef981b4 | 483 | |
5ca0d812 SC |
484 | void wxTextCtrl::Copy() |
485 | { | |
486 | if (CanCopy()) | |
7d8268a1 | 487 | GetPeer()->Copy() ; |
72055702 SC |
488 | } |
489 | ||
5ca0d812 SC |
490 | void wxTextCtrl::Cut() |
491 | { | |
492 | if (CanCut()) | |
493 | { | |
7d8268a1 | 494 | GetPeer()->Cut() ; |
72055702 | 495 | |
c88b7d28 | 496 | wxCommandEvent event( wxEVT_COMMAND_TEXT_UPDATED, m_windowId ); |
5ca0d812 | 497 | event.SetEventObject( this ); |
c88b7d28 | 498 | GetEventHandler()->ProcessEvent( event ); |
5ca0d812 SC |
499 | } |
500 | } | |
72055702 | 501 | |
5ca0d812 SC |
502 | void wxTextCtrl::Paste() |
503 | { | |
504 | if (CanPaste()) | |
505 | { | |
7d8268a1 | 506 | GetPeer()->Paste() ; |
fef981b4 DS |
507 | |
508 | // TODO: eventually we should add setting the default style again | |
72055702 | 509 | |
c88b7d28 | 510 | wxCommandEvent event( wxEVT_COMMAND_TEXT_UPDATED, m_windowId ); |
5ca0d812 | 511 | event.SetEventObject( this ); |
c88b7d28 | 512 | GetEventHandler()->ProcessEvent( event ); |
5ca0d812 SC |
513 | } |
514 | } | |
72055702 | 515 | |
5ca0d812 SC |
516 | bool wxTextCtrl::CanCopy() const |
517 | { | |
518 | // Can copy if there's a selection | |
519 | long from, to; | |
c88b7d28 | 520 | GetSelection( &from, &to ); |
ffafe6ca | 521 | |
5ca0d812 SC |
522 | return (from != to); |
523 | } | |
ef4a634b | 524 | |
5ca0d812 SC |
525 | bool wxTextCtrl::CanCut() const |
526 | { | |
527 | if ( !IsEditable() ) | |
c88b7d28 | 528 | return false; |
a8d2fb31 | 529 | |
5ca0d812 SC |
530 | // Can cut if there's a selection |
531 | long from, to; | |
c88b7d28 | 532 | GetSelection( &from, &to ); |
ffafe6ca | 533 | |
5ca0d812 | 534 | return (from != to); |
72055702 SC |
535 | } |
536 | ||
5ca0d812 SC |
537 | bool wxTextCtrl::CanPaste() const |
538 | { | |
539 | if (!IsEditable()) | |
7d8268a1 | 540 | return false; |
72055702 | 541 | |
5ca0d812 SC |
542 | return GetPeer()->CanPaste() ; |
543 | } | |
facd6764 | 544 | |
5ca0d812 SC |
545 | void wxTextCtrl::SetEditable(bool editable) |
546 | { | |
547 | if ( editable != m_editable ) | |
548 | { | |
549 | m_editable = editable ; | |
550 | GetPeer()->SetEditable( editable ) ; | |
ed8c2780 | 551 | } |
72055702 SC |
552 | } |
553 | ||
5ca0d812 SC |
554 | void wxTextCtrl::SetInsertionPoint(long pos) |
555 | { | |
556 | SetSelection( pos , pos ) ; | |
557 | } | |
72055702 | 558 | |
5ca0d812 SC |
559 | void wxTextCtrl::SetInsertionPointEnd() |
560 | { | |
7d8268a1 | 561 | wxTextPos pos = GetLastPosition(); |
ffafe6ca | 562 | SetInsertionPoint( pos ); |
5ca0d812 | 563 | } |
facd6764 | 564 | |
5ca0d812 SC |
565 | long wxTextCtrl::GetInsertionPoint() const |
566 | { | |
ffafe6ca | 567 | long begin, end ; |
5ca0d812 | 568 | GetSelection( &begin , &end ) ; |
ffafe6ca | 569 | |
5ca0d812 SC |
570 | return begin ; |
571 | } | |
facd6764 | 572 | |
7d8268a1 | 573 | wxTextPos wxTextCtrl::GetLastPosition() const |
5ca0d812 | 574 | { |
c88b7d28 | 575 | return GetPeer()->GetLastPosition() ; |
72055702 SC |
576 | } |
577 | ||
5ca0d812 SC |
578 | void wxTextCtrl::Replace(long from, long to, const wxString& str) |
579 | { | |
ffafe6ca | 580 | GetPeer()->Replace( from , to , str ) ; |
5ca0d812 | 581 | } |
72055702 | 582 | |
5ca0d812 SC |
583 | void wxTextCtrl::Remove(long from, long to) |
584 | { | |
585 | GetPeer()->Remove( from , to ) ; | |
586 | } | |
facd6764 | 587 | |
5ca0d812 SC |
588 | void wxTextCtrl::SetSelection(long from, long to) |
589 | { | |
590 | GetPeer()->SetSelection( from , to ) ; | |
591 | } | |
592 | ||
5ca0d812 SC |
593 | void wxTextCtrl::WriteText(const wxString& str) |
594 | { | |
fef981b4 | 595 | // TODO: this MPRemoting will be moved into a remoting peer proxy for any command |
5ca0d812 SC |
596 | if ( !wxIsMainThread() ) |
597 | { | |
fef981b4 DS |
598 | // unfortunately CW 8 is not able to correctly deduce the template types, |
599 | // so we have to instantiate explicitly | |
5ca0d812 | 600 | wxMacMPRemoteGUICall<wxTextCtrl,wxString>( this , &wxTextCtrl::WriteText , str ) ; |
ffafe6ca | 601 | |
5ca0d812 SC |
602 | return ; |
603 | } | |
ffafe6ca DS |
604 | |
605 | GetPeer()->WriteText( str ) ; | |
5ca0d812 | 606 | } |
72055702 | 607 | |
5ca0d812 SC |
608 | void wxTextCtrl::AppendText(const wxString& text) |
609 | { | |
610 | SetInsertionPointEnd(); | |
ffafe6ca | 611 | WriteText( text ); |
5ca0d812 | 612 | } |
facd6764 | 613 | |
5ca0d812 SC |
614 | void wxTextCtrl::Clear() |
615 | { | |
616 | GetPeer()->Clear() ; | |
617 | } | |
facd6764 | 618 | |
5ca0d812 SC |
619 | bool wxTextCtrl::IsModified() const |
620 | { | |
621 | return m_dirty; | |
622 | } | |
facd6764 | 623 | |
5ca0d812 SC |
624 | bool wxTextCtrl::IsEditable() const |
625 | { | |
626 | return IsEnabled() && m_editable ; | |
72055702 SC |
627 | } |
628 | ||
5ca0d812 SC |
629 | bool wxTextCtrl::AcceptsFocus() const |
630 | { | |
631 | // we don't want focus if we can't be edited | |
632 | return /*IsEditable() && */ wxControl::AcceptsFocus(); | |
633 | } | |
72055702 | 634 | |
5ca0d812 | 635 | wxSize wxTextCtrl::DoGetBestSize() const |
1b2b1638 | 636 | { |
c88b7d28 | 637 | int wText, hText; |
ef4a634b | 638 | |
a8d2fb31 DS |
639 | // these are the numbers from the HIG: |
640 | // we reduce them by the borders first | |
c88b7d28 | 641 | wText = 100 ; |
72463754 | 642 | |
fef981b4 | 643 | switch ( m_windowVariant ) |
5ca0d812 SC |
644 | { |
645 | case wxWINDOW_VARIANT_NORMAL : | |
72463754 | 646 | hText = 22 - 6 ; |
5ca0d812 | 647 | break ; |
a8d2fb31 | 648 | |
5ca0d812 | 649 | case wxWINDOW_VARIANT_SMALL : |
72463754 | 650 | hText = 19 - 6 ; |
5ca0d812 | 651 | break ; |
a8d2fb31 | 652 | |
5ca0d812 | 653 | case wxWINDOW_VARIANT_MINI : |
c88b7d28 | 654 | hText = 15 - 6 ; |
5ca0d812 | 655 | break ; |
a8d2fb31 | 656 | |
5ca0d812 | 657 | default : |
72463754 | 658 | hText = 22 - 6; |
7d8268a1 | 659 | break ; |
5ca0d812 | 660 | } |
72055702 | 661 | |
72463754 SC |
662 | // as the above numbers have some free space around the text |
663 | // we get 5 lines like this anyway | |
5ca0d812 | 664 | if ( m_windowStyle & wxTE_MULTILINE ) |
5ca0d812 | 665 | hText *= 5 ; |
ef4a634b | 666 | |
72463754 SC |
667 | if ( !HasFlag(wxNO_BORDER) ) |
668 | hText += 6 ; | |
669 | ||
5ca0d812 SC |
670 | return wxSize(wText, hText); |
671 | } | |
ef4a634b | 672 | |
5ca0d812 SC |
673 | // ---------------------------------------------------------------------------- |
674 | // Undo/redo | |
675 | // ---------------------------------------------------------------------------- | |
facd6764 | 676 | |
5ca0d812 SC |
677 | void wxTextCtrl::Undo() |
678 | { | |
679 | if (CanUndo()) | |
5ca0d812 | 680 | GetPeer()->Undo() ; |
72055702 SC |
681 | } |
682 | ||
5ca0d812 | 683 | void wxTextCtrl::Redo() |
587bc950 | 684 | { |
5ca0d812 | 685 | if (CanRedo()) |
5ca0d812 | 686 | GetPeer()->Redo() ; |
5ca0d812 | 687 | } |
1b2b1638 | 688 | |
5ca0d812 SC |
689 | bool wxTextCtrl::CanUndo() const |
690 | { | |
7d8268a1 | 691 | if ( !IsEditable() ) |
7d8268a1 | 692 | return false ; |
a8d2fb31 | 693 | |
5ca0d812 SC |
694 | return GetPeer()->CanUndo() ; |
695 | } | |
72055702 | 696 | |
5ca0d812 | 697 | bool wxTextCtrl::CanRedo() const |
6bdd4f5d | 698 | { |
7d8268a1 | 699 | if ( !IsEditable() ) |
7d8268a1 | 700 | return false ; |
a8d2fb31 | 701 | |
5ca0d812 | 702 | return GetPeer()->CanRedo() ; |
6bdd4f5d SC |
703 | } |
704 | ||
5ca0d812 SC |
705 | void wxTextCtrl::MarkDirty() |
706 | { | |
707 | m_dirty = true; | |
708 | } | |
587bc950 | 709 | |
5ca0d812 SC |
710 | void wxTextCtrl::DiscardEdits() |
711 | { | |
712 | m_dirty = false; | |
713 | } | |
587bc950 | 714 | |
5ca0d812 SC |
715 | int wxTextCtrl::GetNumberOfLines() const |
716 | { | |
717 | return GetPeer()->GetNumberOfLines() ; | |
718 | } | |
587bc950 | 719 | |
5ca0d812 SC |
720 | long wxTextCtrl::XYToPosition(long x, long y) const |
721 | { | |
722 | return GetPeer()->XYToPosition( x , y ) ; | |
723 | } | |
587bc950 | 724 | |
5ca0d812 | 725 | bool wxTextCtrl::PositionToXY(long pos, long *x, long *y) const |
72055702 | 726 | { |
ffafe6ca | 727 | return GetPeer()->PositionToXY( pos , x , y ) ; |
5ca0d812 | 728 | } |
1fa29bdc | 729 | |
5ca0d812 SC |
730 | void wxTextCtrl::ShowPosition(long pos) |
731 | { | |
732 | return GetPeer()->ShowPosition(pos) ; | |
733 | } | |
1fa29bdc | 734 | |
5ca0d812 SC |
735 | int wxTextCtrl::GetLineLength(long lineNo) const |
736 | { | |
737 | return GetPeer()->GetLineLength(lineNo) ; | |
1b2b1638 SC |
738 | } |
739 | ||
5ca0d812 | 740 | wxString wxTextCtrl::GetLineText(long lineNo) const |
1b2b1638 | 741 | { |
5ca0d812 | 742 | return GetPeer()->GetLineText(lineNo) ; |
72055702 SC |
743 | } |
744 | ||
5ca0d812 | 745 | void wxTextCtrl::Command(wxCommandEvent & event) |
72055702 | 746 | { |
c88b7d28 DS |
747 | SetValue(event.GetString()); |
748 | ProcessCommand(event); | |
5ca0d812 | 749 | } |
72055702 | 750 | |
5ca0d812 SC |
751 | void wxTextCtrl::OnDropFiles(wxDropFilesEvent& event) |
752 | { | |
753 | // By default, load the first file into the text window. | |
754 | if (event.GetNumberOfFiles() > 0) | |
ffafe6ca | 755 | LoadFile( event.GetFiles()[0] ); |
5ca0d812 | 756 | } |
ef4a634b | 757 | |
7ea087b7 SC |
758 | void wxTextCtrl::OnEraseBackground(wxEraseEvent& event) |
759 | { | |
760 | // all erasing should be done by the real mac control implementation | |
761 | // while this is true for MLTE under classic, the HITextView is somehow | |
762 | // transparent but background erase is not working correctly, so intercept | |
763 | // things while we can... | |
395480fb | 764 | event.Skip() ; |
7ea087b7 SC |
765 | } |
766 | ||
5ca0d812 SC |
767 | void wxTextCtrl::OnChar(wxKeyEvent& event) |
768 | { | |
769 | int key = event.GetKeyCode() ; | |
770 | bool eat_key = false ; | |
72055702 | 771 | |
c4d9fc39 SC |
772 | if ( key == 'a' && event.MetaDown() ) |
773 | { | |
88a7a4e1 WS |
774 | SelectAll() ; |
775 | ||
c4d9fc39 SC |
776 | return ; |
777 | } | |
778 | ||
5ca0d812 | 779 | if ( key == 'c' && event.MetaDown() ) |
72055702 | 780 | { |
5ca0d812 SC |
781 | if ( CanCopy() ) |
782 | Copy() ; | |
fef981b4 | 783 | |
5ca0d812 | 784 | return ; |
72055702 SC |
785 | } |
786 | ||
5ca0d812 | 787 | if ( !IsEditable() && key != WXK_LEFT && key != WXK_RIGHT && key != WXK_DOWN && key != WXK_UP && key != WXK_TAB && |
8e13c1ec | 788 | !( key == WXK_RETURN && ( (m_windowStyle & wxTE_PROCESS_ENTER) || (m_windowStyle & wxTE_MULTILINE) ) ) |
faa94f3e | 789 | // && key != WXK_PAGEUP && key != WXK_PAGEDOWN && key != WXK_HOME && key != WXK_END |
5ca0d812 | 790 | ) |
29e4a190 | 791 | { |
5ca0d812 SC |
792 | // eat it |
793 | return ; | |
794 | } | |
d3016f30 | 795 | |
b9bae707 VZ |
796 | // Check if we have reached the max # of chars (if it is set), but still |
797 | // allow navigation and deletion | |
faa94f3e | 798 | if ( !IsMultiLine() && m_maxLength && GetValue().length() >= m_maxLength && |
bdf0c19c | 799 | key != WXK_LEFT && key != WXK_RIGHT && key != WXK_TAB && |
8e13c1ec | 800 | key != WXK_BACK && !( key == WXK_RETURN && (m_windowStyle & wxTE_PROCESS_ENTER) ) |
bdf0c19c KH |
801 | ) |
802 | { | |
803 | // eat it, we don't want to add more than allowed # of characters | |
b9bae707 VZ |
804 | |
805 | // TODO: generate EVT_TEXT_MAXLEN() | |
bdf0c19c KH |
806 | return; |
807 | } | |
808 | ||
5ca0d812 SC |
809 | // assume that any key not processed yet is going to modify the control |
810 | m_dirty = true; | |
587bc950 | 811 | |
5ca0d812 SC |
812 | if ( key == 'v' && event.MetaDown() ) |
813 | { | |
814 | if ( CanPaste() ) | |
815 | Paste() ; | |
0207e969 | 816 | |
5ca0d812 | 817 | return ; |
29e4a190 | 818 | } |
fef981b4 | 819 | |
5ca0d812 | 820 | if ( key == 'x' && event.MetaDown() ) |
ed8c2780 | 821 | { |
5ca0d812 SC |
822 | if ( CanCut() ) |
823 | Cut() ; | |
fef981b4 | 824 | |
5ca0d812 | 825 | return ; |
1b2b1638 | 826 | } |
a8d2fb31 | 827 | |
5ca0d812 SC |
828 | switch ( key ) |
829 | { | |
830 | case WXK_RETURN: | |
8e13c1ec | 831 | if (m_windowStyle & wxTE_PROCESS_ENTER) |
5ca0d812 SC |
832 | { |
833 | wxCommandEvent event(wxEVT_COMMAND_TEXT_ENTER, m_windowId); | |
834 | event.SetEventObject( this ); | |
835 | event.SetString( GetValue() ); | |
836 | if ( GetEventHandler()->ProcessEvent(event) ) | |
837 | return; | |
838 | } | |
fef981b4 | 839 | |
5ca0d812 SC |
840 | if ( !(m_windowStyle & wxTE_MULTILINE) ) |
841 | { | |
6c20e8f8 VZ |
842 | wxTopLevelWindow *tlw = wxDynamicCast(wxGetTopLevelParent(this), wxTopLevelWindow); |
843 | if ( tlw && tlw->GetDefaultItem() ) | |
fef981b4 | 844 | { |
6c20e8f8 | 845 | wxButton *def = wxDynamicCast(tlw->GetDefaultItem(), wxButton); |
5ca0d812 SC |
846 | if ( def && def->IsEnabled() ) |
847 | { | |
848 | wxCommandEvent event(wxEVT_COMMAND_BUTTON_CLICKED, def->GetId() ); | |
849 | event.SetEventObject(def); | |
850 | def->Command(event); | |
fef981b4 | 851 | |
5ca0d812 | 852 | return ; |
3dee36ae | 853 | } |
5ca0d812 SC |
854 | } |
855 | ||
856 | // this will make wxWidgets eat the ENTER key so that | |
0207e969 | 857 | // we actually prevent line wrapping in a single line text control |
7d8268a1 | 858 | eat_key = true; |
5ca0d812 | 859 | } |
5ca0d812 | 860 | break; |
facd6764 | 861 | |
5ca0d812 SC |
862 | case WXK_TAB: |
863 | if ( !(m_windowStyle & wxTE_PROCESS_TAB)) | |
864 | { | |
865 | int flags = 0; | |
866 | if (!event.ShiftDown()) | |
867 | flags |= wxNavigationKeyEvent::IsForward ; | |
868 | if (event.ControlDown()) | |
869 | flags |= wxNavigationKeyEvent::WinChange ; | |
870 | Navigate(flags); | |
fef981b4 | 871 | |
5ca0d812 SC |
872 | return; |
873 | } | |
874 | else | |
875 | { | |
fef981b4 DS |
876 | // This is necessary (don't know why); |
877 | // otherwise the tab will not be inserted. | |
5ca0d812 | 878 | WriteText(wxT("\t")); |
4e6cc020 | 879 | eat_key = true; |
5ca0d812 | 880 | } |
a8d2fb31 | 881 | break; |
7d8268a1 | 882 | |
a8d2fb31 | 883 | default: |
5ca0d812 SC |
884 | break; |
885 | } | |
facd6764 | 886 | |
5ca0d812 | 887 | if (!eat_key) |
7f1de2b2 | 888 | { |
5ca0d812 | 889 | // perform keystroke handling |
665b537f | 890 | event.Skip(true) ; |
7f1de2b2 | 891 | } |
a8d2fb31 | 892 | |
5ca0d812 | 893 | if ( ( key >= 0x20 && key < WXK_START ) || |
fce161de | 894 | ( key >= WXK_NUMPAD0 && key <= WXK_DIVIDE ) || |
5ca0d812 SC |
895 | key == WXK_RETURN || |
896 | key == WXK_DELETE || | |
897 | key == WXK_BACK) | |
7f1de2b2 | 898 | { |
5ca0d812 | 899 | wxCommandEvent event1(wxEVT_COMMAND_TEXT_UPDATED, m_windowId); |
5ca0d812 | 900 | event1.SetEventObject( this ); |
c88b7d28 | 901 | wxPostEvent( GetEventHandler(), event1 ); |
7f1de2b2 | 902 | } |
5ca0d812 | 903 | } |
facd6764 | 904 | |
5ca0d812 SC |
905 | // ---------------------------------------------------------------------------- |
906 | // standard handlers for standard edit menu events | |
907 | // ---------------------------------------------------------------------------- | |
908 | ||
909 | void wxTextCtrl::OnCut(wxCommandEvent& WXUNUSED(event)) | |
910 | { | |
911 | Cut(); | |
72055702 SC |
912 | } |
913 | ||
5ca0d812 | 914 | void wxTextCtrl::OnCopy(wxCommandEvent& WXUNUSED(event)) |
facd6764 | 915 | { |
5ca0d812 SC |
916 | Copy(); |
917 | } | |
7f1de2b2 | 918 | |
5ca0d812 SC |
919 | void wxTextCtrl::OnPaste(wxCommandEvent& WXUNUSED(event)) |
920 | { | |
921 | Paste(); | |
facd6764 SC |
922 | } |
923 | ||
5ca0d812 | 924 | void wxTextCtrl::OnUndo(wxCommandEvent& WXUNUSED(event)) |
facd6764 | 925 | { |
5ca0d812 | 926 | Undo(); |
facd6764 SC |
927 | } |
928 | ||
5ca0d812 SC |
929 | void wxTextCtrl::OnRedo(wxCommandEvent& WXUNUSED(event)) |
930 | { | |
931 | Redo(); | |
932 | } | |
facd6764 | 933 | |
24eef584 SC |
934 | void wxTextCtrl::OnDelete(wxCommandEvent& WXUNUSED(event)) |
935 | { | |
936 | long from, to; | |
ffafe6ca | 937 | |
c88b7d28 | 938 | GetSelection( &from, &to ); |
24eef584 | 939 | if (from != -1 && to != -1) |
c88b7d28 | 940 | Remove( from, to ); |
24eef584 SC |
941 | } |
942 | ||
943 | void wxTextCtrl::OnSelectAll(wxCommandEvent& WXUNUSED(event)) | |
944 | { | |
945 | SetSelection(-1, -1); | |
946 | } | |
947 | ||
5ca0d812 | 948 | void wxTextCtrl::OnUpdateCut(wxUpdateUIEvent& event) |
72055702 | 949 | { |
5ca0d812 | 950 | event.Enable( CanCut() ); |
72055702 SC |
951 | } |
952 | ||
5ca0d812 SC |
953 | void wxTextCtrl::OnUpdateCopy(wxUpdateUIEvent& event) |
954 | { | |
955 | event.Enable( CanCopy() ); | |
72055702 SC |
956 | } |
957 | ||
5ca0d812 | 958 | void wxTextCtrl::OnUpdatePaste(wxUpdateUIEvent& event) |
72055702 | 959 | { |
5ca0d812 | 960 | event.Enable( CanPaste() ); |
72055702 SC |
961 | } |
962 | ||
5ca0d812 | 963 | void wxTextCtrl::OnUpdateUndo(wxUpdateUIEvent& event) |
29b30405 | 964 | { |
5ca0d812 | 965 | event.Enable( CanUndo() ); |
29b30405 SC |
966 | } |
967 | ||
5ca0d812 | 968 | void wxTextCtrl::OnUpdateRedo(wxUpdateUIEvent& event) |
facd6764 | 969 | { |
5ca0d812 | 970 | event.Enable( CanRedo() ); |
facd6764 SC |
971 | } |
972 | ||
24eef584 SC |
973 | void wxTextCtrl::OnUpdateDelete(wxUpdateUIEvent& event) |
974 | { | |
975 | long from, to; | |
ffafe6ca | 976 | |
c88b7d28 | 977 | GetSelection( &from, &to ); |
0207e969 | 978 | event.Enable( from != -1 && to != -1 && from != to && IsEditable() ) ; |
24eef584 SC |
979 | } |
980 | ||
981 | void wxTextCtrl::OnUpdateSelectAll(wxUpdateUIEvent& event) | |
982 | { | |
983 | event.Enable(GetLastPosition() > 0); | |
984 | } | |
985 | ||
a8d2fb31 | 986 | // CS: Context Menus only work with MLTE implementations or non-multiline HIViews at the moment |
24eef584 SC |
987 | |
988 | void wxTextCtrl::OnContextMenu(wxContextMenuEvent& event) | |
989 | { | |
64bd657c SC |
990 | if ( GetPeer()->HasOwnContextMenu() ) |
991 | { | |
992 | event.Skip() ; | |
993 | return ; | |
994 | } | |
0207e969 | 995 | |
24eef584 SC |
996 | if (m_privateContextMenu == NULL) |
997 | { | |
998 | m_privateContextMenu = new wxMenu; | |
999 | m_privateContextMenu->Append(wxID_UNDO, _("&Undo")); | |
1000 | m_privateContextMenu->Append(wxID_REDO, _("&Redo")); | |
1001 | m_privateContextMenu->AppendSeparator(); | |
1002 | m_privateContextMenu->Append(wxID_CUT, _("Cu&t")); | |
1003 | m_privateContextMenu->Append(wxID_COPY, _("&Copy")); | |
1004 | m_privateContextMenu->Append(wxID_PASTE, _("&Paste")); | |
1005 | m_privateContextMenu->Append(wxID_CLEAR, _("&Delete")); | |
1006 | m_privateContextMenu->AppendSeparator(); | |
1007 | m_privateContextMenu->Append(wxID_SELECTALL, _("Select &All")); | |
1008 | } | |
faa94f3e | 1009 | |
24eef584 SC |
1010 | if (m_privateContextMenu != NULL) |
1011 | PopupMenu(m_privateContextMenu); | |
1012 | } | |
1013 | ||
5ca0d812 | 1014 | bool wxTextCtrl::MacSetupCursor( const wxPoint& pt ) |
29b30405 | 1015 | { |
0207e969 | 1016 | if ( !GetPeer()->SetupCursor( pt ) ) |
f2c3f2a8 SC |
1017 | return wxWindow::MacSetupCursor( pt ) ; |
1018 | else | |
1019 | return true ; | |
5ca0d812 | 1020 | } |
a8d2fb31 | 1021 | |
5ca0d812 SC |
1022 | // ---------------------------------------------------------------------------- |
1023 | // implementation base class | |
1024 | // ---------------------------------------------------------------------------- | |
1025 | ||
0f7817ab SC |
1026 | wxMacTextControl::wxMacTextControl(wxTextCtrl* peer) : |
1027 | wxMacControl( peer ) | |
5ca0d812 | 1028 | { |
72055702 SC |
1029 | } |
1030 | ||
7d8268a1 | 1031 | wxMacTextControl::~wxMacTextControl() |
72055702 | 1032 | { |
72055702 SC |
1033 | } |
1034 | ||
89954433 VZ |
1035 | void wxMacTextControl::SetStyle(long WXUNUSED(start), |
1036 | long WXUNUSED(end), | |
1037 | const wxTextAttr& WXUNUSED(style)) | |
72055702 | 1038 | { |
72055702 SC |
1039 | } |
1040 | ||
7d8268a1 | 1041 | void wxMacTextControl::Copy() |
72055702 | 1042 | { |
72055702 SC |
1043 | } |
1044 | ||
7d8268a1 | 1045 | void wxMacTextControl::Cut() |
72055702 | 1046 | { |
72055702 SC |
1047 | } |
1048 | ||
7d8268a1 | 1049 | void wxMacTextControl::Paste() |
72055702 | 1050 | { |
72055702 SC |
1051 | } |
1052 | ||
7d8268a1 WS |
1053 | bool wxMacTextControl::CanPaste() const |
1054 | { | |
5ca0d812 SC |
1055 | return false ; |
1056 | } | |
1057 | ||
89954433 | 1058 | void wxMacTextControl::SetEditable(bool WXUNUSED(editable)) |
72055702 | 1059 | { |
7d8268a1 | 1060 | } |
facd6764 | 1061 | |
7d8268a1 | 1062 | wxTextPos wxMacTextControl::GetLastPosition() const |
5ca0d812 | 1063 | { |
faa94f3e | 1064 | return GetStringValue().length() ; |
5ca0d812 | 1065 | } |
facd6764 | 1066 | |
44aa865d SC |
1067 | void wxMacTextControl::Replace( long from , long to , const wxString &val ) |
1068 | { | |
1069 | SetSelection( from , to ) ; | |
fef981b4 | 1070 | WriteText( val ) ; |
44aa865d SC |
1071 | } |
1072 | ||
1073 | void wxMacTextControl::Remove( long from , long to ) | |
5ca0d812 | 1074 | { |
44aa865d SC |
1075 | SetSelection( from , to ) ; |
1076 | WriteText( wxEmptyString) ; | |
72055702 SC |
1077 | } |
1078 | ||
7d8268a1 | 1079 | void wxMacTextControl::Clear() |
72055702 | 1080 | { |
5ca0d812 | 1081 | SetStringValue( wxEmptyString ) ; |
72055702 SC |
1082 | } |
1083 | ||
7d8268a1 | 1084 | bool wxMacTextControl::CanUndo() const |
72055702 | 1085 | { |
5ca0d812 SC |
1086 | return false ; |
1087 | } | |
587bc950 | 1088 | |
a8d2fb31 DS |
1089 | void wxMacTextControl::Undo() |
1090 | { | |
1091 | } | |
5ca0d812 SC |
1092 | |
1093 | bool wxMacTextControl::CanRedo() const | |
1094 | { | |
1095 | return false ; | |
7d8268a1 | 1096 | } |
5ca0d812 | 1097 | |
7d8268a1 | 1098 | void wxMacTextControl::Redo() |
5ca0d812 | 1099 | { |
72055702 SC |
1100 | } |
1101 | ||
89954433 | 1102 | long wxMacTextControl::XYToPosition(long WXUNUSED(x), long WXUNUSED(y)) const |
72055702 | 1103 | { |
5ca0d812 SC |
1104 | return 0 ; |
1105 | } | |
72055702 | 1106 | |
89954433 VZ |
1107 | bool wxMacTextControl::PositionToXY(long WXUNUSED(pos), |
1108 | long *WXUNUSED(x), | |
1109 | long *WXUNUSED(y)) const | |
5ca0d812 SC |
1110 | { |
1111 | return false ; | |
72055702 SC |
1112 | } |
1113 | ||
7d8268a1 WS |
1114 | void wxMacTextControl::ShowPosition( long WXUNUSED(pos) ) |
1115 | { | |
1116 | } | |
5ca0d812 | 1117 | |
7d8268a1 | 1118 | int wxMacTextControl::GetNumberOfLines() const |
7548762c | 1119 | { |
5ca0d812 SC |
1120 | ItemCount lines = 0 ; |
1121 | wxString content = GetStringValue() ; | |
1122 | lines = 1; | |
fef981b4 | 1123 | |
faa94f3e | 1124 | for (size_t i = 0; i < content.length() ; i++) |
7548762c | 1125 | { |
fef981b4 DS |
1126 | if (content[i] == '\r') |
1127 | lines++; | |
7548762c | 1128 | } |
a8d2fb31 | 1129 | |
5ca0d812 SC |
1130 | return lines ; |
1131 | } | |
7548762c | 1132 | |
5ca0d812 | 1133 | wxString wxMacTextControl::GetLineText(long lineNo) const |
7548762c | 1134 | { |
fef981b4 | 1135 | // TODO: change this if possible to reflect real lines |
5ca0d812 | 1136 | wxString content = GetStringValue() ; |
7d8268a1 | 1137 | |
5ca0d812 SC |
1138 | // Find line first |
1139 | int count = 0; | |
faa94f3e | 1140 | for (size_t i = 0; i < content.length() ; i++) |
7548762c | 1141 | { |
5ca0d812 SC |
1142 | if (count == lineNo) |
1143 | { | |
1144 | // Add chars in line then | |
1145 | wxString tmp; | |
7d8268a1 | 1146 | |
faa94f3e | 1147 | for (size_t j = i; j < content.length(); j++) |
5ca0d812 SC |
1148 | { |
1149 | if (content[j] == '\n') | |
1150 | return tmp; | |
7d8268a1 | 1151 | |
5ca0d812 SC |
1152 | tmp += content[j]; |
1153 | } | |
7d8268a1 | 1154 | |
5ca0d812 SC |
1155 | return tmp; |
1156 | } | |
a8d2fb31 | 1157 | |
fef981b4 DS |
1158 | if (content[i] == '\n') |
1159 | count++; | |
7548762c | 1160 | } |
a8d2fb31 | 1161 | |
5ca0d812 SC |
1162 | return wxEmptyString ; |
1163 | } | |
7548762c | 1164 | |
a8d2fb31 | 1165 | int wxMacTextControl::GetLineLength(long lineNo) const |
5ca0d812 | 1166 | { |
fef981b4 | 1167 | // TODO: change this if possible to reflect real lines |
5ca0d812 | 1168 | wxString content = GetStringValue() ; |
7d8268a1 | 1169 | |
5ca0d812 SC |
1170 | // Find line first |
1171 | int count = 0; | |
faa94f3e | 1172 | for (size_t i = 0; i < content.length() ; i++) |
7548762c | 1173 | { |
5ca0d812 SC |
1174 | if (count == lineNo) |
1175 | { | |
1176 | // Count chars in line then | |
1177 | count = 0; | |
faa94f3e | 1178 | for (size_t j = i; j < content.length(); j++) |
5ca0d812 SC |
1179 | { |
1180 | count++; | |
a8d2fb31 DS |
1181 | if (content[j] == '\n') |
1182 | return count; | |
5ca0d812 | 1183 | } |
7d8268a1 | 1184 | |
5ca0d812 SC |
1185 | return count; |
1186 | } | |
a8d2fb31 | 1187 | |
fef981b4 DS |
1188 | if (content[i] == '\n') |
1189 | count++; | |
7548762c | 1190 | } |
a8d2fb31 | 1191 | |
5ca0d812 SC |
1192 | return 0 ; |
1193 | } | |
7548762c | 1194 | |
5ca0d812 SC |
1195 | // ---------------------------------------------------------------------------- |
1196 | // standard unicode control implementation | |
1197 | // ---------------------------------------------------------------------------- | |
1198 | ||
ad604d0f SC |
1199 | // the current unicode textcontrol implementation has a bug : only if the control |
1200 | // is currently having the focus, the selection can be retrieved by the corresponding | |
1201 | // data tag. So we have a mirroring using a member variable | |
1202 | // TODO : build event table using virtual member functions for wxMacControl | |
1203 | ||
1204 | static const EventTypeSpec unicodeTextControlEventList[] = | |
1205 | { | |
1206 | { kEventClassControl , kEventControlSetFocusPart } , | |
1207 | } ; | |
1208 | ||
1209 | static pascal OSStatus wxMacUnicodeTextControlControlEventHandler( EventHandlerCallRef handler , EventRef event , void *data ) | |
1210 | { | |
1211 | OSStatus result = eventNotHandledErr ; | |
1212 | wxMacUnicodeTextControl* focus = (wxMacUnicodeTextControl*) data ; | |
1213 | wxMacCarbonEvent cEvent( event ) ; | |
9eddec69 | 1214 | |
ad604d0f SC |
1215 | switch ( GetEventKind( event ) ) |
1216 | { | |
1217 | case kEventControlSetFocusPart : | |
1218 | { | |
1219 | ControlPartCode controlPart = cEvent.GetParameter<ControlPartCode>(kEventParamControlPart , typeControlPartCode ); | |
1220 | if ( controlPart == kControlFocusNoPart ) | |
1221 | { | |
1222 | // about to loose focus -> store selection to field | |
1223 | focus->GetData<ControlEditTextSelectionRec>( 0, kControlEditTextSelectionTag, &focus->m_selection ); | |
1224 | } | |
1225 | result = CallNextEventHandler(handler,event) ; | |
1226 | if ( controlPart != kControlFocusNoPart ) | |
1227 | { | |
1228 | // about to gain focus -> set selection from field | |
1229 | focus->SetData<ControlEditTextSelectionRec>( 0, kControlEditTextSelectionTag, &focus->m_selection ); | |
1230 | } | |
1231 | break; | |
1232 | } | |
1233 | default: | |
1234 | break ; | |
1235 | } | |
9eddec69 | 1236 | |
ad604d0f SC |
1237 | return result ; |
1238 | } | |
1239 | ||
1240 | static pascal OSStatus wxMacUnicodeTextControlEventHandler( EventHandlerCallRef handler , EventRef event , void *data ) | |
1241 | { | |
1242 | OSStatus result = eventNotHandledErr ; | |
9eddec69 | 1243 | |
ad604d0f SC |
1244 | switch ( GetEventClass( event ) ) |
1245 | { | |
1246 | case kEventClassControl : | |
1247 | result = wxMacUnicodeTextControlControlEventHandler( handler , event , data ) ; | |
1248 | break ; | |
9eddec69 | 1249 | |
ad604d0f SC |
1250 | default : |
1251 | break ; | |
1252 | } | |
1253 | return result ; | |
1254 | } | |
1255 | ||
1256 | DEFINE_ONE_SHOT_HANDLER_GETTER( wxMacUnicodeTextControlEventHandler ) | |
1257 | ||
3f7f284d RD |
1258 | wxMacUnicodeTextControl::wxMacUnicodeTextControl( wxTextCtrl *wxPeer ) : wxMacTextControl( wxPeer ) |
1259 | { | |
1260 | } | |
1261 | ||
0f7817ab | 1262 | wxMacUnicodeTextControl::wxMacUnicodeTextControl( wxTextCtrl *wxPeer, |
ffafe6ca DS |
1263 | const wxString& str, |
1264 | const wxPoint& pos, | |
1265 | const wxSize& size, long style ) | |
1266 | : wxMacTextControl( wxPeer ) | |
3f7f284d RD |
1267 | { |
1268 | Create( wxPeer, str, pos, size, style ); | |
1269 | } | |
1270 | ||
1271 | bool wxMacUnicodeTextControl::Create( wxTextCtrl *wxPeer, | |
1272 | const wxString& str, | |
1273 | const wxPoint& pos, | |
1274 | const wxSize& size, long style ) | |
5ca0d812 SC |
1275 | { |
1276 | m_font = wxPeer->GetFont() ; | |
1277 | m_windowStyle = style ; | |
6239ee05 | 1278 | m_selection.selStart = m_selection.selEnd = 0; |
7d8268a1 | 1279 | Rect bounds = wxMacGetBoundsForControl( wxPeer , pos , size ) ; |
5ca0d812 | 1280 | wxString st = str ; |
395480fb | 1281 | wxMacConvertNewlines10To13( &st ) ; |
5ca0d812 SC |
1282 | wxMacCFStringHolder cf(st , m_font.GetEncoding()) ; |
1283 | CFStringRef cfr = cf ; | |
44cc96a8 | 1284 | |
3f7f284d RD |
1285 | m_valueTag = kControlEditTextCFStringTag ; |
1286 | CreateControl( wxPeer, &bounds, cfr ); | |
7d8268a1 | 1287 | |
5ca0d812 | 1288 | if ( !(m_windowStyle & wxTE_MULTILINE) ) |
5ca0d812 | 1289 | SetData<Boolean>( kControlEditTextPart , kControlEditTextSingleLineTag , true ) ; |
ad604d0f SC |
1290 | |
1291 | InstallControlEventHandler( m_controlRef , GetwxMacUnicodeTextControlEventHandlerUPP(), | |
1292 | GetEventTypeCount(unicodeTextControlEventList), unicodeTextControlEventList, this, | |
6239ee05 | 1293 | NULL); |
44cc96a8 | 1294 | |
3f7f284d | 1295 | return true; |
5ca0d812 | 1296 | } |
7548762c | 1297 | |
5ca0d812 | 1298 | wxMacUnicodeTextControl::~wxMacUnicodeTextControl() |
7548762c | 1299 | { |
7548762c SC |
1300 | } |
1301 | ||
7d8268a1 | 1302 | void wxMacUnicodeTextControl::VisibilityChanged(bool shown) |
7548762c | 1303 | { |
5ca0d812 SC |
1304 | if ( !(m_windowStyle & wxTE_MULTILINE) && shown ) |
1305 | { | |
fef981b4 DS |
1306 | // work around a refresh issue insofar as not always the entire content is shown, |
1307 | // even if this would be possible | |
5ca0d812 SC |
1308 | ControlEditTextSelectionRec sel ; |
1309 | CFStringRef value = NULL ; | |
7548762c | 1310 | |
5ca0d812 | 1311 | verify_noerr( GetData<ControlEditTextSelectionRec>( 0, kControlEditTextSelectionTag, &sel ) ); |
c88b7d28 | 1312 | verify_noerr( GetData<CFStringRef>( 0, m_valueTag, &value ) ); |
5ca0d812 SC |
1313 | verify_noerr( SetData<CFStringRef>( 0, m_valueTag, &value ) ); |
1314 | verify_noerr( SetData<ControlEditTextSelectionRec>( 0, kControlEditTextSelectionTag, &sel ) ); | |
7d8268a1 | 1315 | |
5ca0d812 SC |
1316 | CFRelease( value ) ; |
1317 | } | |
1318 | } | |
a8d2fb31 | 1319 | |
7d8268a1 | 1320 | wxString wxMacUnicodeTextControl::GetStringValue() const |
7548762c | 1321 | { |
5ca0d812 | 1322 | wxString result ; |
c88b7d28 | 1323 | CFStringRef value = GetData<CFStringRef>(0, m_valueTag) ; |
5ca0d812 SC |
1324 | if ( value ) |
1325 | { | |
1326 | wxMacCFStringHolder cf(value) ; | |
1327 | result = cf.AsString() ; | |
1328 | } | |
a8d2fb31 | 1329 | |
2e7573f7 | 1330 | #if '\n' == 10 |
395480fb SC |
1331 | wxMacConvertNewlines13To10( &result ) ; |
1332 | #else | |
5ca0d812 | 1333 | wxMacConvertNewlines10To13( &result ) ; |
395480fb | 1334 | #endif |
a8d2fb31 | 1335 | |
7548762c SC |
1336 | return result ; |
1337 | } | |
a8d2fb31 | 1338 | |
c88b7d28 | 1339 | void wxMacUnicodeTextControl::SetStringValue( const wxString &str ) |
5ca0d812 SC |
1340 | { |
1341 | wxString st = str ; | |
395480fb | 1342 | wxMacConvertNewlines10To13( &st ) ; |
ffafe6ca | 1343 | wxMacCFStringHolder cf( st , m_font.GetEncoding() ) ; |
0207e969 | 1344 | verify_noerr( SetData<CFStringRef>( 0, m_valueTag , cf ) ) ; |
5ca0d812 | 1345 | } |
a8d2fb31 | 1346 | |
3f7f284d RD |
1347 | void wxMacUnicodeTextControl::CreateControl( wxTextCtrl* peer, const Rect* bounds, CFStringRef cfr ) |
1348 | { | |
1349 | Boolean isPassword = ( m_windowStyle & wxTE_PASSWORD ) != 0 ; | |
1350 | if ( isPassword ) | |
1351 | { | |
1352 | m_valueTag = kControlEditTextPasswordCFStringTag ; | |
1353 | } | |
1354 | OSStatus err = CreateEditUnicodeTextControl( | |
1355 | MAC_WXHWND(peer->MacGetTopLevelWindowRef()), bounds , cfr , | |
1356 | isPassword , NULL , &m_controlRef ) ; | |
1357 | verify_noerr( err ); | |
1358 | } | |
1359 | ||
5ca0d812 SC |
1360 | void wxMacUnicodeTextControl::Copy() |
1361 | { | |
1362 | SendHICommand( kHICommandCopy ) ; | |
1363 | } | |
a8d2fb31 | 1364 | |
5ca0d812 SC |
1365 | void wxMacUnicodeTextControl::Cut() |
1366 | { | |
1367 | SendHICommand( kHICommandCut ) ; | |
1368 | } | |
a8d2fb31 | 1369 | |
5ca0d812 SC |
1370 | void wxMacUnicodeTextControl::Paste() |
1371 | { | |
1372 | SendHICommand( kHICommandPaste ) ; | |
1373 | } | |
a8d2fb31 | 1374 | |
5ca0d812 SC |
1375 | bool wxMacUnicodeTextControl::CanPaste() const |
1376 | { | |
1377 | return true ; | |
1378 | } | |
a8d2fb31 | 1379 | |
89954433 | 1380 | void wxMacUnicodeTextControl::SetEditable(bool WXUNUSED(editable)) |
5ca0d812 | 1381 | { |
35d9ac06 SC |
1382 | #if 0 // leads to problem because text cannot be selected anymore |
1383 | SetData<Boolean>( kControlEditTextPart , kControlEditTextLockedTag , (Boolean) !editable ) ; | |
1384 | #endif | |
5ca0d812 | 1385 | } |
7548762c | 1386 | |
0207e969 | 1387 | void wxMacUnicodeTextControl::GetSelection( long* from, long* to ) const |
7548762c | 1388 | { |
5ca0d812 | 1389 | ControlEditTextSelectionRec sel ; |
ad604d0f SC |
1390 | if (HasFocus()) |
1391 | verify_noerr( GetData<ControlEditTextSelectionRec>( 0, kControlEditTextSelectionTag, &sel ) ) ; | |
1392 | else | |
1393 | sel = m_selection ; | |
9eddec69 | 1394 | |
0207e969 DS |
1395 | if ( from ) |
1396 | *from = sel.selStart ; | |
1397 | if ( to ) | |
1398 | *to = sel.selEnd ; | |
7548762c SC |
1399 | } |
1400 | ||
7d8268a1 | 1401 | void wxMacUnicodeTextControl::SetSelection( long from , long to ) |
ef4a634b | 1402 | { |
5ca0d812 | 1403 | ControlEditTextSelectionRec sel ; |
ad604d0f SC |
1404 | wxString result ; |
1405 | int textLength = 0 ; | |
1406 | CFStringRef value = GetData<CFStringRef>(0, m_valueTag) ; | |
1407 | if ( value ) | |
1408 | { | |
1409 | wxMacCFStringHolder cf(value) ; | |
1832043f | 1410 | textLength = cf.AsString().length() ; |
ad604d0f SC |
1411 | } |
1412 | ||
1a535eb9 SC |
1413 | if ((from == -1) && (to == -1)) |
1414 | { | |
1415 | from = 0 ; | |
9eddec69 | 1416 | to = textLength ; |
ad604d0f SC |
1417 | } |
1418 | else | |
1419 | { | |
1420 | from = wxMin(textLength,wxMax(from,0)) ; | |
1421 | to = wxMax(0,wxMin(textLength,to)) ; | |
1a535eb9 | 1422 | } |
a8d2fb31 | 1423 | |
5ca0d812 SC |
1424 | sel.selStart = from ; |
1425 | sel.selEnd = to ; | |
ad604d0f SC |
1426 | if ( HasFocus() ) |
1427 | SetData<ControlEditTextSelectionRec>( 0, kControlEditTextSelectionTag, &sel ) ; | |
1428 | else | |
1429 | m_selection = sel; | |
5ca0d812 | 1430 | } |
facd6764 | 1431 | |
c88b7d28 | 1432 | void wxMacUnicodeTextControl::WriteText( const wxString& str ) |
5ca0d812 SC |
1433 | { |
1434 | wxString st = str ; | |
395480fb | 1435 | wxMacConvertNewlines10To13( &st ) ; |
0207e969 | 1436 | |
ad604d0f SC |
1437 | if ( HasFocus() ) |
1438 | { | |
7548762c SC |
1439 | wxMacCFStringHolder cf(st , m_font.GetEncoding() ) ; |
1440 | CFStringRef value = cf ; | |
5ca0d812 | 1441 | SetData<CFStringRef>( 0, kControlEditTextInsertCFStringRefTag, &value ); |
ad604d0f | 1442 | } |
df39467f | 1443 | else |
ad604d0f | 1444 | { |
5ca0d812 | 1445 | wxString val = GetStringValue() ; |
7548762c SC |
1446 | long start , end ; |
1447 | GetSelection( &start , &end ) ; | |
1448 | val.Remove( start , end - start ) ; | |
1449 | val.insert( start , str ) ; | |
5ca0d812 | 1450 | SetStringValue( val ) ; |
faa94f3e | 1451 | SetSelection( start + str.length() , start + str.length() ) ; |
ad604d0f | 1452 | } |
72055702 SC |
1453 | } |
1454 | ||
5ca0d812 SC |
1455 | // ---------------------------------------------------------------------------- |
1456 | // MLTE control implementation (common part) | |
1457 | // ---------------------------------------------------------------------------- | |
facd6764 | 1458 | |
a8d2fb31 | 1459 | // if MTLE is read only, no changes at all are allowed, not even from |
5ca0d812 SC |
1460 | // procedural API, in order to allow changes via API all the same we must undo |
1461 | // the readonly status while we are executing, this class helps to do so | |
72055702 | 1462 | |
5de694f0 | 1463 | class wxMacEditHelper |
72055702 | 1464 | { |
5ca0d812 | 1465 | public : |
5de694f0 | 1466 | wxMacEditHelper( TXNObject txn ) |
5ca0d812 SC |
1467 | { |
1468 | TXNControlTag tag[] = { kTXNIOPrivilegesTag } ; | |
1469 | m_txn = txn ; | |
1470 | TXNGetTXNObjectControls( m_txn , 1 , tag , m_data ) ; | |
1471 | if ( m_data[0].uValue == kTXNReadOnly ) | |
1472 | { | |
1473 | TXNControlData data[] = { { kTXNReadWrite } } ; | |
1474 | TXNSetTXNObjectControls( m_txn , false , 1 , tag , data ) ; | |
1475 | } | |
1476 | } | |
a8d2fb31 | 1477 | |
5de694f0 | 1478 | ~wxMacEditHelper() |
5ca0d812 SC |
1479 | { |
1480 | TXNControlTag tag[] = { kTXNIOPrivilegesTag } ; | |
1481 | if ( m_data[0].uValue == kTXNReadOnly ) | |
5ca0d812 | 1482 | TXNSetTXNObjectControls( m_txn , false , 1 , tag , m_data ) ; |
5ca0d812 | 1483 | } |
a8d2fb31 | 1484 | |
fef981b4 DS |
1485 | protected : |
1486 | TXNObject m_txn ; | |
1487 | TXNControlData m_data[1] ; | |
5ca0d812 | 1488 | } ; |
72055702 | 1489 | |
ffafe6ca DS |
1490 | wxMacMLTEControl::wxMacMLTEControl( wxTextCtrl *peer ) |
1491 | : wxMacTextControl( peer ) | |
789ae0cf | 1492 | { |
3dee36ae | 1493 | SetNeedsFocusRect( true ) ; |
789ae0cf SC |
1494 | } |
1495 | ||
7d8268a1 | 1496 | wxString wxMacMLTEControl::GetStringValue() const |
72055702 | 1497 | { |
5ca0d812 SC |
1498 | wxString result ; |
1499 | OSStatus err ; | |
1500 | Size actualSize = 0; | |
c88b7d28 | 1501 | |
5ca0d812 SC |
1502 | { |
1503 | #if wxUSE_UNICODE | |
1504 | Handle theText ; | |
c88b7d28 | 1505 | err = TXNGetDataEncoded( m_txn, kTXNStartOffset, kTXNEndOffset, &theText, kTXNUnicodeTextData ); |
fef981b4 | 1506 | |
5ca0d812 | 1507 | // all done |
fef981b4 | 1508 | if ( err != noErr ) |
5ca0d812 SC |
1509 | { |
1510 | actualSize = 0 ; | |
1511 | } | |
1512 | else | |
1513 | { | |
c88b7d28 | 1514 | actualSize = GetHandleSize( theText ) / sizeof(UniChar) ; |
5ca0d812 SC |
1515 | if ( actualSize > 0 ) |
1516 | { | |
1517 | wxChar *ptr = NULL ; | |
fef981b4 | 1518 | |
7d8268a1 | 1519 | #if SIZEOF_WCHAR_T == 2 |
c88b7d28 DS |
1520 | ptr = new wxChar[actualSize + 1] ; |
1521 | wxStrncpy( ptr , (wxChar*)(*theText) , actualSize ) ; | |
5ca0d812 | 1522 | #else |
c88b7d28 | 1523 | SetHandleSize( theText, (actualSize + 1) * sizeof(UniChar) ) ; |
5ca0d812 SC |
1524 | HLock( theText ) ; |
1525 | (((UniChar*)*theText)[actualSize]) = 0 ; | |
d9d488cf | 1526 | wxMBConvUTF16 converter ; |
5ca0d812 | 1527 | size_t noChars = converter.MB2WC( NULL , (const char*)*theText , 0 ) ; |
88a7a4e1 | 1528 | wxASSERT_MSG( noChars != wxCONV_FAILED, _T("Unable to count the number of characters in this string!") ); |
5ca0d812 | 1529 | ptr = new wxChar[noChars + 1] ; |
7d8268a1 | 1530 | |
f3097709 | 1531 | noChars = converter.MB2WC( ptr , (const char*)*theText , noChars + 1 ) ; |
88a7a4e1 | 1532 | wxASSERT_MSG( noChars != wxCONV_FAILED, _T("Conversion of string failed!") ); |
5ca0d812 SC |
1533 | ptr[noChars] = 0 ; |
1534 | HUnlock( theText ) ; | |
1535 | #endif | |
fef981b4 | 1536 | |
5ca0d812 SC |
1537 | ptr[actualSize] = 0 ; |
1538 | result = wxString( ptr ) ; | |
c88b7d28 | 1539 | delete [] ptr ; |
5ca0d812 | 1540 | } |
a8d2fb31 | 1541 | |
5ca0d812 SC |
1542 | DisposeHandle( theText ) ; |
1543 | } | |
1544 | #else | |
1545 | Handle theText ; | |
c88b7d28 | 1546 | err = TXNGetDataEncoded( m_txn , kTXNStartOffset, kTXNEndOffset, &theText, kTXNTextData ); |
0207e969 | 1547 | |
5ca0d812 | 1548 | // all done |
0207e969 | 1549 | if ( err != noErr ) |
5ca0d812 SC |
1550 | { |
1551 | actualSize = 0 ; | |
1552 | } | |
1553 | else | |
1554 | { | |
1555 | actualSize = GetHandleSize( theText ) ; | |
1556 | if ( actualSize > 0 ) | |
1557 | { | |
1558 | HLock( theText ) ; | |
1559 | result = wxString( *theText , wxConvLocal , actualSize ) ; | |
1560 | HUnlock( theText ) ; | |
1561 | } | |
a8d2fb31 | 1562 | |
5ca0d812 SC |
1563 | DisposeHandle( theText ) ; |
1564 | } | |
1565 | #endif | |
1566 | } | |
a8d2fb31 | 1567 | |
2e7573f7 | 1568 | #if '\n' == 10 |
395480fb SC |
1569 | wxMacConvertNewlines13To10( &result ) ; |
1570 | #else | |
5ca0d812 | 1571 | wxMacConvertNewlines10To13( &result ) ; |
395480fb | 1572 | #endif |
a8d2fb31 | 1573 | |
5ca0d812 | 1574 | return result ; |
72055702 SC |
1575 | } |
1576 | ||
0207e969 | 1577 | void wxMacMLTEControl::SetStringValue( const wxString &str ) |
72055702 | 1578 | { |
c88b7d28 DS |
1579 | wxString st = str; |
1580 | wxMacConvertNewlines10To13( &st ); | |
395480fb | 1581 | |
5de694f0 | 1582 | { |
4f74e0d1 SC |
1583 | #ifndef __LP64__ |
1584 | wxMacWindowClipper c( m_peer ) ; | |
1585 | #endif | |
0207e969 | 1586 | |
5de694f0 | 1587 | { |
c88b7d28 DS |
1588 | wxMacEditHelper help( m_txn ); |
1589 | SetTXNData( st, kTXNStartOffset, kTXNEndOffset ); | |
5de694f0 | 1590 | } |
0207e969 | 1591 | |
fef981b4 DS |
1592 | TXNSetSelection( m_txn, 0, 0 ); |
1593 | TXNShowSelection( m_txn, kTXNShowStart ); | |
5de694f0 | 1594 | } |
5ca0d812 | 1595 | } |
facd6764 | 1596 | |
5ca0d812 SC |
1597 | TXNFrameOptions wxMacMLTEControl::FrameOptionsFromWXStyle( long wxStyle ) |
1598 | { | |
c88b7d28 DS |
1599 | TXNFrameOptions frameOptions = kTXNDontDrawCaretWhenInactiveMask; |
1600 | ||
c88b7d28 | 1601 | frameOptions |= kTXNDoFontSubstitutionMask; |
4d7528a1 | 1602 | |
c88b7d28 | 1603 | if ( ! (wxStyle & wxTE_NOHIDESEL) ) |
5ca0d812 SC |
1604 | frameOptions |= kTXNDontDrawSelectionWhenInactiveMask ; |
1605 | ||
c88b7d28 DS |
1606 | if ( wxStyle & (wxHSCROLL | wxTE_DONTWRAP) ) |
1607 | frameOptions |= kTXNWantHScrollBarMask ; | |
1608 | ||
5ca0d812 | 1609 | if ( wxStyle & wxTE_MULTILINE ) |
29e4a190 | 1610 | { |
c88b7d28 | 1611 | frameOptions |= kTXNAlwaysWrapAtViewEdgeMask ; |
72055702 | 1612 | |
c88b7d28 | 1613 | if ( !(wxStyle & wxTE_NO_VSCROLL) ) |
5de694f0 | 1614 | { |
5ca0d812 | 1615 | frameOptions |= kTXNWantVScrollBarMask ; |
c88b7d28 | 1616 | |
04c3457a DS |
1617 | // The following code causes drawing problems on 10.4. Perhaps it can be restored for |
1618 | // older versions of the OS, but I'm not sure it's appropriate to put a grow icon here | |
1619 | // anyways, as AFAIK users can't actually use it to resize the text ctrl. | |
1620 | // if ( frameOptions & kTXNWantHScrollBarMask ) | |
1621 | // frameOptions |= kTXNDrawGrowIconMask ; | |
5de694f0 | 1622 | } |
5ca0d812 SC |
1623 | } |
1624 | else | |
c88b7d28 | 1625 | { |
5ca0d812 | 1626 | frameOptions |= kTXNSingleLineOnlyMask ; |
c88b7d28 | 1627 | } |
7d8268a1 | 1628 | |
5ca0d812 SC |
1629 | return frameOptions ; |
1630 | } | |
cfeff6f7 | 1631 | |
89954433 VZ |
1632 | void wxMacMLTEControl::AdjustCreationAttributes(const wxColour &background, |
1633 | bool WXUNUSED(visible)) | |
5ca0d812 | 1634 | { |
3dee36ae WS |
1635 | TXNControlTag iControlTags[] = |
1636 | { | |
1637 | kTXNDoFontSubstitution, | |
5de694f0 SC |
1638 | kTXNWordWrapStateTag , |
1639 | }; | |
3dee36ae WS |
1640 | TXNControlData iControlData[] = |
1641 | { | |
c88b7d28 DS |
1642 | { true }, |
1643 | { kTXNNoAutoWrap }, | |
5de694f0 | 1644 | }; |
3dee36ae | 1645 | |
5de694f0 | 1646 | int toptag = WXSIZEOF( iControlTags ) ; |
7d8268a1 | 1647 | |
72055702 SC |
1648 | if ( m_windowStyle & wxTE_MULTILINE ) |
1649 | { | |
c88b7d28 DS |
1650 | iControlData[1].uValue = |
1651 | (m_windowStyle & wxTE_DONTWRAP) | |
1652 | ? kTXNNoAutoWrap | |
1653 | : kTXNAutoWrap; | |
72055702 | 1654 | } |
0207e969 | 1655 | |
ffafe6ca DS |
1656 | OSStatus err = TXNSetTXNObjectControls( m_txn, false, toptag, iControlTags, iControlData ) ; |
1657 | verify_noerr( err ); | |
facd6764 | 1658 | |
fef981b4 | 1659 | // setting the default font: |
8e15e610 | 1660 | // under 10.2 this causes a visible caret, therefore we avoid it |
72055702 | 1661 | |
9d463591 SC |
1662 | Str255 fontName ; |
1663 | SInt16 fontSize ; | |
1664 | Style fontStyle ; | |
5ca0d812 | 1665 | |
9d463591 | 1666 | GetThemeFont( kThemeSystemFont , GetApplicationScript() , fontName , &fontSize , &fontStyle ) ; |
5ca0d812 | 1667 | |
9d463591 SC |
1668 | TXNTypeAttributes typeAttr[] = |
1669 | { | |
1670 | { kTXNQDFontNameAttribute , kTXNQDFontNameAttributeSize , { (void*) fontName } } , | |
1671 | { kTXNQDFontSizeAttribute , kTXNFontSizeAttributeSize , { (void*) (fontSize << 16) } } , | |
1672 | { kTXNQDFontStyleAttribute , kTXNQDFontStyleAttributeSize , { (void*) normal } } , | |
1673 | } ; | |
1674 | ||
1675 | err = TXNSetTypeAttributes( | |
1676 | m_txn, sizeof(typeAttr) / sizeof(TXNTypeAttributes), | |
1677 | typeAttr, kTXNStartOffset, kTXNEndOffset ); | |
1678 | verify_noerr( err ); | |
3dee36ae | 1679 | |
5ca0d812 SC |
1680 | if ( m_windowStyle & wxTE_PASSWORD ) |
1681 | { | |
ffafe6ca DS |
1682 | UniChar c = 0x00A5 ; |
1683 | err = TXNEchoMode( m_txn , c , 0 , true ); | |
1684 | verify_noerr( err ); | |
72055702 | 1685 | } |
5ca0d812 SC |
1686 | |
1687 | TXNBackground tback; | |
1688 | tback.bgType = kTXNBackgroundTypeRGB; | |
1689 | tback.bg.color = MAC_WXCOLORREF( background.GetPixel() ); | |
0207e969 | 1690 | TXNSetBackground( m_txn , &tback ); |
a8d2fb31 | 1691 | |
d8f3e9da SC |
1692 | |
1693 | TXNCommandEventSupportOptions options ; | |
1694 | if ( TXNGetCommandEventSupport( m_txn, &options ) == noErr ) | |
64bd657c | 1695 | { |
d8f3e9da SC |
1696 | options |= |
1697 | kTXNSupportEditCommandProcessing | |
1698 | | kTXNSupportEditCommandUpdating | |
1699 | | kTXNSupportFontCommandProcessing | |
1700 | | kTXNSupportFontCommandUpdating; | |
1701 | ||
1702 | // only spell check when not read-only | |
1703 | // use system options for the default | |
1704 | bool checkSpelling = false ; | |
1705 | if ( !(m_windowStyle & wxTE_READONLY) ) | |
1706 | { | |
6239ee05 | 1707 | #if wxUSE_SYSTEM_OPTIONS |
d8f3e9da SC |
1708 | if ( wxSystemOptions::HasOption( wxMAC_TEXTCONTROL_USE_SPELL_CHECKER ) && (wxSystemOptions::GetOptionInt( wxMAC_TEXTCONTROL_USE_SPELL_CHECKER ) == 1) ) |
1709 | { | |
1710 | checkSpelling = true ; | |
6239ee05 | 1711 | } |
d8f3e9da | 1712 | #endif |
64bd657c | 1713 | } |
d8f3e9da SC |
1714 | |
1715 | if ( checkSpelling ) | |
1716 | options |= | |
1717 | kTXNSupportSpellCheckCommandProcessing | |
1718 | | kTXNSupportSpellCheckCommandUpdating; | |
1719 | ||
1720 | TXNSetCommandEventSupport( m_txn , options ) ; | |
64bd657c | 1721 | } |
72055702 SC |
1722 | } |
1723 | ||
7d8268a1 | 1724 | void wxMacMLTEControl::SetBackground( const wxBrush &brush ) |
7ea087b7 SC |
1725 | { |
1726 | // currently only solid background are supported | |
1727 | TXNBackground tback; | |
0207e969 | 1728 | |
7ea087b7 SC |
1729 | tback.bgType = kTXNBackgroundTypeRGB; |
1730 | tback.bg.color = MAC_WXCOLORREF( brush.GetColour().GetPixel() ); | |
0207e969 | 1731 | TXNSetBackground( m_txn , &tback ); |
7ea087b7 SC |
1732 | } |
1733 | ||
31c1cbc7 VZ |
1734 | static inline int wxConvertToTXN(int x) |
1735 | { | |
1736 | return wx_static_cast(int, x / 254.0 * 72 + 0.5); | |
1737 | } | |
1738 | ||
0207e969 | 1739 | void wxMacMLTEControl::TXNSetAttribute( const wxTextAttr& style , long from , long to ) |
72055702 | 1740 | { |
7d8268a1 | 1741 | TXNTypeAttributes typeAttr[4] ; |
5ca0d812 | 1742 | RGBColor color ; |
6239ee05 SC |
1743 | size_t typeAttrCount = 0 ; |
1744 | ||
1745 | TXNMargins margins; | |
1746 | TXNControlTag controlTags[4]; | |
1747 | TXNControlData controlData[4]; | |
1748 | size_t controlAttrCount = 0; | |
31c1cbc7 | 1749 | |
6239ee05 | 1750 | TXNTab* tabs = NULL; |
31c1cbc7 | 1751 | |
6239ee05 | 1752 | bool relayout = false; |
fef981b4 | 1753 | |
5ca0d812 | 1754 | if ( style.HasFont() ) |
72055702 | 1755 | { |
6239ee05 SC |
1756 | wxASSERT( typeAttrCount < WXSIZEOF(typeAttr) ); |
1757 | const wxFont &font = style.GetFont() ; | |
1758 | typeAttr[typeAttrCount].tag = kTXNATSUIStyle ; | |
1759 | typeAttr[typeAttrCount].size = kTXNATSUIStyleSize ; | |
1760 | typeAttr[typeAttrCount].data.dataPtr = font.MacGetATSUStyle() ; | |
1761 | typeAttrCount++ ; | |
5ca0d812 | 1762 | } |
fef981b4 | 1763 | |
5ca0d812 SC |
1764 | if ( style.HasTextColour() ) |
1765 | { | |
6239ee05 | 1766 | wxASSERT( typeAttrCount < WXSIZEOF(typeAttr) ); |
5ca0d812 | 1767 | color = MAC_WXCOLORREF(style.GetTextColour().GetPixel()) ; |
0207e969 | 1768 | |
6239ee05 SC |
1769 | typeAttr[typeAttrCount].tag = kTXNQDFontColorAttribute ; |
1770 | typeAttr[typeAttrCount].size = kTXNQDFontColorAttributeSize ; | |
1771 | typeAttr[typeAttrCount].data.dataPtr = (void*) &color ; | |
1772 | typeAttrCount++ ; | |
72055702 | 1773 | } |
31c1cbc7 | 1774 | |
6239ee05 SC |
1775 | if ( style.HasAlignment() ) |
1776 | { | |
1777 | wxASSERT( controlAttrCount < WXSIZEOF(controlTags) ); | |
1778 | SInt32 align; | |
31c1cbc7 | 1779 | |
6239ee05 SC |
1780 | switch ( style.GetAlignment() ) |
1781 | { | |
1782 | case wxTEXT_ALIGNMENT_LEFT: | |
1783 | align = kTXNFlushLeft; | |
1784 | break; | |
1785 | case wxTEXT_ALIGNMENT_CENTRE: | |
1786 | align = kTXNCenter; | |
1787 | break; | |
1788 | case wxTEXT_ALIGNMENT_RIGHT: | |
1789 | align = kTXNFlushRight; | |
1790 | break; | |
1791 | case wxTEXT_ALIGNMENT_JUSTIFIED: | |
1792 | align = kTXNFullJust; | |
31c1cbc7 | 1793 | break; |
6239ee05 SC |
1794 | default : |
1795 | case wxTEXT_ALIGNMENT_DEFAULT: | |
1796 | align = kTXNFlushDefault; | |
1797 | break; | |
1798 | } | |
31c1cbc7 | 1799 | |
6239ee05 SC |
1800 | controlTags[controlAttrCount] = kTXNJustificationTag ; |
1801 | controlData[controlAttrCount].sValue = align ; | |
1802 | controlAttrCount++ ; | |
1803 | } | |
1804 | ||
1805 | if ( style.HasLeftIndent() || style.HasRightIndent() ) | |
1806 | { | |
1807 | wxASSERT( controlAttrCount < WXSIZEOF(controlTags) ); | |
1808 | controlTags[controlAttrCount] = kTXNMarginsTag; | |
1809 | controlData[controlAttrCount].marginsPtr = &margins; | |
1810 | verify_noerr( TXNGetTXNObjectControls (m_txn, 1 , | |
1811 | &controlTags[controlAttrCount], &controlData[controlAttrCount]) ); | |
1812 | if ( style.HasLeftIndent() ) | |
1813 | { | |
31c1cbc7 | 1814 | margins.leftMargin = wxConvertToTXN(style.GetLeftIndent()); |
6239ee05 SC |
1815 | } |
1816 | if ( style.HasRightIndent() ) | |
1817 | { | |
31c1cbc7 | 1818 | margins.rightMargin = wxConvertToTXN(style.GetRightIndent()); |
6239ee05 SC |
1819 | } |
1820 | controlAttrCount++ ; | |
1821 | } | |
31c1cbc7 | 1822 | |
6239ee05 SC |
1823 | if ( style.HasTabs() ) |
1824 | { | |
1825 | const wxArrayInt& tabarray = style.GetTabs(); | |
1826 | // unfortunately Mac only applies a tab distance, not individually different tabs | |
1827 | controlTags[controlAttrCount] = kTXNTabSettingsTag; | |
1828 | if ( tabarray.size() > 0 ) | |
31c1cbc7 | 1829 | controlData[controlAttrCount].tabValue.value = wxConvertToTXN(tabarray[0]); |
6239ee05 | 1830 | else |
31c1cbc7 | 1831 | controlData[controlAttrCount].tabValue.value = 72 ; |
fef981b4 | 1832 | |
6239ee05 SC |
1833 | controlData[controlAttrCount].tabValue.tabType = kTXNLeftTab; |
1834 | controlAttrCount++ ; | |
1835 | } | |
31c1cbc7 | 1836 | |
6239ee05 SC |
1837 | // unfortunately the relayout is not automatic |
1838 | if ( controlAttrCount > 0 ) | |
1839 | { | |
1840 | verify_noerr( TXNSetTXNObjectControls (m_txn, false /* don't clear all */, controlAttrCount, | |
1841 | controlTags, controlData) ); | |
1842 | relayout = true; | |
1843 | } | |
31c1cbc7 | 1844 | |
6239ee05 SC |
1845 | if ( typeAttrCount > 0 ) |
1846 | { | |
1847 | verify_noerr( TXNSetTypeAttributes( m_txn , typeAttrCount, typeAttr, from , to ) ); | |
1848 | relayout = true; | |
1849 | } | |
31c1cbc7 | 1850 | |
6239ee05 SC |
1851 | if ( tabs != NULL ) |
1852 | { | |
1853 | delete[] tabs; | |
1854 | } | |
31c1cbc7 | 1855 | |
6239ee05 | 1856 | if ( relayout ) |
8623a883 | 1857 | { |
09660720 | 1858 | TXNRecalcTextLayout( m_txn ); |
8623a883 | 1859 | } |
72055702 SC |
1860 | } |
1861 | ||
89954433 VZ |
1862 | void wxMacMLTEControl::SetFont(const wxFont & font, |
1863 | const wxColour& foreground, | |
1864 | long WXUNUSED(windowStyle)) | |
72055702 | 1865 | { |
0207e969 DS |
1866 | wxMacEditHelper help( m_txn ) ; |
1867 | TXNSetAttribute( wxTextAttr( foreground, wxNullColour, font ), kTXNStartOffset, kTXNEndOffset ) ; | |
72055702 | 1868 | } |
a8d2fb31 | 1869 | |
0207e969 | 1870 | void wxMacMLTEControl::SetStyle( long start, long end, const wxTextAttr& style ) |
7d8268a1 | 1871 | { |
0207e969 DS |
1872 | wxMacEditHelper help( m_txn ) ; |
1873 | TXNSetAttribute( style, start, end ) ; | |
7d8268a1 WS |
1874 | } |
1875 | ||
1876 | void wxMacMLTEControl::Copy() | |
5ca0d812 | 1877 | { |
0207e969 | 1878 | TXNCopy( m_txn ); |
72055702 SC |
1879 | } |
1880 | ||
7d8268a1 | 1881 | void wxMacMLTEControl::Cut() |
3a9fa0d6 | 1882 | { |
0207e969 | 1883 | TXNCut( m_txn ); |
3a9fa0d6 VZ |
1884 | } |
1885 | ||
7d8268a1 | 1886 | void wxMacMLTEControl::Paste() |
72055702 | 1887 | { |
0207e969 | 1888 | TXNPaste( m_txn ); |
72055702 SC |
1889 | } |
1890 | ||
5ca0d812 | 1891 | bool wxMacMLTEControl::CanPaste() const |
72055702 | 1892 | { |
5ca0d812 | 1893 | return TXNIsScrapPastable() ; |
72055702 SC |
1894 | } |
1895 | ||
7d8268a1 | 1896 | void wxMacMLTEControl::SetEditable(bool editable) |
72055702 | 1897 | { |
5ca0d812 SC |
1898 | TXNControlTag tag[] = { kTXNIOPrivilegesTag } ; |
1899 | TXNControlData data[] = { { editable ? kTXNReadWrite : kTXNReadOnly } } ; | |
c88b7d28 | 1900 | TXNSetTXNObjectControls( m_txn, false, WXSIZEOF(tag), tag, data ) ; |
5ca0d812 | 1901 | } |
bd3169a7 | 1902 | |
7d8268a1 | 1903 | wxTextPos wxMacMLTEControl::GetLastPosition() const |
5ca0d812 | 1904 | { |
7d8268a1 | 1905 | wxTextPos actualsize = 0 ; |
5ca0d812 SC |
1906 | |
1907 | Handle theText ; | |
0207e969 | 1908 | OSErr err = TXNGetDataEncoded( m_txn, kTXNStartOffset, kTXNEndOffset, &theText, kTXNTextData ); |
fef981b4 DS |
1909 | |
1910 | // all done | |
1911 | if ( err == noErr ) | |
5ca0d812 | 1912 | { |
fef981b4 DS |
1913 | actualsize = GetHandleSize( theText ) ; |
1914 | DisposeHandle( theText ) ; | |
5ca0d812 SC |
1915 | } |
1916 | else | |
1917 | { | |
fef981b4 | 1918 | actualsize = 0 ; |
5ca0d812 SC |
1919 | } |
1920 | ||
1921 | return actualsize ; | |
1922 | } | |
1923 | ||
44aa865d | 1924 | void wxMacMLTEControl::Replace( long from , long to , const wxString &str ) |
5ca0d812 SC |
1925 | { |
1926 | wxString value = str ; | |
395480fb | 1927 | wxMacConvertNewlines10To13( &value ) ; |
5ca0d812 | 1928 | |
5de694f0 | 1929 | wxMacEditHelper help( m_txn ) ; |
4f74e0d1 | 1930 | #ifndef __LP64__ |
0f7817ab | 1931 | wxMacWindowClipper c( m_peer ) ; |
4f74e0d1 | 1932 | #endif |
5ca0d812 | 1933 | |
0207e969 | 1934 | TXNSetSelection( m_txn, from, to ) ; |
5ca0d812 | 1935 | TXNClear( m_txn ) ; |
0207e969 | 1936 | SetTXNData( value, kTXNUseCurrentSelection, kTXNUseCurrentSelection ) ; |
5ca0d812 SC |
1937 | } |
1938 | ||
1939 | void wxMacMLTEControl::Remove( long from , long to ) | |
1940 | { | |
4f74e0d1 | 1941 | #ifndef __LP64__ |
0f7817ab | 1942 | wxMacWindowClipper c( m_peer ) ; |
4f74e0d1 | 1943 | #endif |
5de694f0 | 1944 | wxMacEditHelper help( m_txn ) ; |
0207e969 | 1945 | TXNSetSelection( m_txn , from , to ) ; |
5ca0d812 SC |
1946 | TXNClear( m_txn ) ; |
1947 | } | |
1948 | ||
1949 | void wxMacMLTEControl::GetSelection( long* from, long* to) const | |
1950 | { | |
6239ee05 SC |
1951 | TXNOffset f,t ; |
1952 | TXNGetSelection( m_txn , &f , &t ) ; | |
1953 | *from = f; | |
1954 | *to = t; | |
5ca0d812 SC |
1955 | } |
1956 | ||
7d8268a1 | 1957 | void wxMacMLTEControl::SetSelection( long from , long to ) |
5ca0d812 | 1958 | { |
4f74e0d1 | 1959 | #ifndef __LP64__ |
0f7817ab | 1960 | wxMacWindowClipper c( m_peer ) ; |
4f74e0d1 | 1961 | #endif |
fef981b4 DS |
1962 | |
1963 | // change the selection | |
5ca0d812 | 1964 | if ((from == -1) && (to == -1)) |
0207e969 | 1965 | TXNSelectAll( m_txn ); |
5ca0d812 | 1966 | else |
fef981b4 | 1967 | TXNSetSelection( m_txn, from, to ); |
0207e969 | 1968 | |
fef981b4 | 1969 | TXNShowSelection( m_txn, kTXNShowStart ); |
5ca0d812 SC |
1970 | } |
1971 | ||
c88b7d28 | 1972 | void wxMacMLTEControl::WriteText( const wxString& str ) |
5ca0d812 | 1973 | { |
5ca0d812 | 1974 | wxString st = str ; |
395480fb | 1975 | wxMacConvertNewlines10To13( &st ) ; |
5ca0d812 SC |
1976 | |
1977 | long start , end , dummy ; | |
0207e969 | 1978 | |
5ca0d812 | 1979 | GetSelection( &start , &dummy ) ; |
4f74e0d1 | 1980 | #ifndef __LP64__ |
5de694f0 | 1981 | wxMacWindowClipper c( m_peer ) ; |
4f74e0d1 | 1982 | #endif |
0207e969 | 1983 | |
5de694f0 SC |
1984 | { |
1985 | wxMacEditHelper helper( m_txn ) ; | |
c88b7d28 | 1986 | SetTXNData( st, kTXNUseCurrentSelection, kTXNUseCurrentSelection ) ; |
5de694f0 | 1987 | } |
a8d2fb31 | 1988 | |
c88b7d28 | 1989 | GetSelection( &dummy, &end ) ; |
fef981b4 DS |
1990 | |
1991 | // TODO: SetStyle( start , end , GetDefaultStyle() ) ; | |
5ca0d812 SC |
1992 | } |
1993 | ||
7d8268a1 | 1994 | void wxMacMLTEControl::Clear() |
5ca0d812 | 1995 | { |
4f74e0d1 | 1996 | #ifndef __LP64__ |
0f7817ab | 1997 | wxMacWindowClipper c( m_peer ) ; |
4f74e0d1 | 1998 | #endif |
0207e969 | 1999 | wxMacEditHelper st( m_txn ) ; |
5ca0d812 | 2000 | TXNSetSelection( m_txn , kTXNStartOffset , kTXNEndOffset ) ; |
c88b7d28 | 2001 | TXNClear( m_txn ) ; |
5ca0d812 SC |
2002 | } |
2003 | ||
7d8268a1 | 2004 | bool wxMacMLTEControl::CanUndo() const |
5ca0d812 SC |
2005 | { |
2006 | return TXNCanUndo( m_txn , NULL ) ; | |
2007 | } | |
2008 | ||
7d8268a1 | 2009 | void wxMacMLTEControl::Undo() |
5ca0d812 | 2010 | { |
7d8268a1 WS |
2011 | TXNUndo( m_txn ) ; |
2012 | } | |
5ca0d812 | 2013 | |
fef981b4 | 2014 | bool wxMacMLTEControl::CanRedo() const |
5ca0d812 SC |
2015 | { |
2016 | return TXNCanRedo( m_txn , NULL ) ; | |
7d8268a1 | 2017 | } |
5ca0d812 | 2018 | |
7d8268a1 WS |
2019 | void wxMacMLTEControl::Redo() |
2020 | { | |
5ca0d812 SC |
2021 | TXNRedo( m_txn ) ; |
2022 | } | |
2023 | ||
7d8268a1 | 2024 | int wxMacMLTEControl::GetNumberOfLines() const |
5ca0d812 SC |
2025 | { |
2026 | ItemCount lines = 0 ; | |
fef981b4 DS |
2027 | TXNGetLineCount( m_txn, &lines ) ; |
2028 | ||
5ca0d812 SC |
2029 | return lines ; |
2030 | } | |
2031 | ||
2032 | long wxMacMLTEControl::XYToPosition(long x, long y) const | |
2033 | { | |
2034 | Point curpt ; | |
fef981b4 | 2035 | wxTextPos lastpos ; |
7d8268a1 | 2036 | |
fef981b4 | 2037 | // TODO: find a better implementation : while we can get the |
5ca0d812 SC |
2038 | // line metrics of a certain line, we don't get its starting |
2039 | // position, so it would probably be rather a binary search | |
2040 | // for the start position | |
c88b7d28 | 2041 | long xpos = 0, ypos = 0 ; |
5ca0d812 | 2042 | int lastHeight = 0 ; |
5ca0d812 | 2043 | ItemCount n ; |
fef981b4 DS |
2044 | |
2045 | lastpos = GetLastPosition() ; | |
ebe86b1e | 2046 | for ( n = 0 ; n <= (ItemCount) lastpos ; ++n ) |
bd3169a7 SC |
2047 | { |
2048 | if ( y == ypos && x == xpos ) | |
2049 | return n ; | |
7d8268a1 | 2050 | |
ffafe6ca | 2051 | TXNOffsetToPoint( m_txn, n, &curpt ) ; |
bd3169a7 SC |
2052 | |
2053 | if ( curpt.v > lastHeight ) | |
2054 | { | |
2055 | xpos = 0 ; | |
2056 | if ( n > 0 ) | |
2057 | ++ypos ; | |
0207e969 | 2058 | |
bd3169a7 SC |
2059 | lastHeight = curpt.v ; |
2060 | } | |
2061 | else | |
2062 | ++xpos ; | |
2063 | } | |
a8d2fb31 | 2064 | |
5ca0d812 | 2065 | return 0 ; |
72055702 SC |
2066 | } |
2067 | ||
c88b7d28 | 2068 | bool wxMacMLTEControl::PositionToXY( long pos, long *x, long *y ) const |
72055702 | 2069 | { |
bd3169a7 | 2070 | Point curpt ; |
fef981b4 | 2071 | wxTextPos lastpos ; |
7d8268a1 | 2072 | |
fef981b4 DS |
2073 | if ( y ) |
2074 | *y = 0 ; | |
2075 | if ( x ) | |
2076 | *x = 0 ; | |
7d8268a1 | 2077 | |
fef981b4 | 2078 | lastpos = GetLastPosition() ; |
bd3169a7 SC |
2079 | if ( pos <= lastpos ) |
2080 | { | |
c88b7d28 | 2081 | // TODO: find a better implementation - while we can get the |
bd3169a7 SC |
2082 | // line metrics of a certain line, we don't get its starting |
2083 | // position, so it would probably be rather a binary search | |
2084 | // for the start position | |
0207e969 | 2085 | long xpos = 0, ypos = 0 ; |
bd3169a7 | 2086 | int lastHeight = 0 ; |
bd3169a7 | 2087 | ItemCount n ; |
0207e969 | 2088 | |
ebe86b1e | 2089 | for ( n = 0 ; n <= (ItemCount) pos ; ++n ) |
bd3169a7 | 2090 | { |
ffafe6ca | 2091 | TXNOffsetToPoint( m_txn, n, &curpt ) ; |
bd3169a7 SC |
2092 | |
2093 | if ( curpt.v > lastHeight ) | |
2094 | { | |
2095 | xpos = 0 ; | |
2096 | if ( n > 0 ) | |
2097 | ++ypos ; | |
0207e969 | 2098 | |
bd3169a7 SC |
2099 | lastHeight = curpt.v ; |
2100 | } | |
2101 | else | |
2102 | ++xpos ; | |
2103 | } | |
a8d2fb31 | 2104 | |
fef981b4 DS |
2105 | if ( y ) |
2106 | *y = ypos ; | |
2107 | if ( x ) | |
2108 | *x = xpos ; | |
bd3169a7 | 2109 | } |
5ca0d812 | 2110 | |
7d8268a1 | 2111 | return false ; |
72055702 SC |
2112 | } |
2113 | ||
7d8268a1 | 2114 | void wxMacMLTEControl::ShowPosition( long pos ) |
72055702 | 2115 | { |
4f74e0d1 SC |
2116 | Point current, desired ; |
2117 | TXNOffset selstart, selend; | |
fef981b4 | 2118 | |
4f74e0d1 SC |
2119 | TXNGetSelection( m_txn, &selstart, &selend ); |
2120 | TXNOffsetToPoint( m_txn, selstart, ¤t ); | |
2121 | TXNOffsetToPoint( m_txn, pos, &desired ); | |
fef981b4 | 2122 | |
4f74e0d1 SC |
2123 | // TODO: use HIPoints for 10.3 and above |
2124 | ||
2125 | OSErr theErr = noErr; | |
2126 | long dv = desired.v - current.v; | |
2127 | long dh = desired.h - current.h; | |
2128 | TXNShowSelection( m_txn, kTXNShowStart ) ; // NB: should this be kTXNShowStart or kTXNShowEnd ?? | |
2129 | theErr = TXNScroll( m_txn, kTXNScrollUnitsInPixels, kTXNScrollUnitsInPixels, &dv, &dh ); | |
2130 | ||
2131 | // there will be an error returned for classic MLTE implementation when the control is | |
2132 | // invisible, but HITextView works correctly, so we don't assert that one | |
2133 | // wxASSERT_MSG( theErr == noErr, _T("TXNScroll returned an error!") ); | |
5ca0d812 SC |
2134 | } |
2135 | ||
fef981b4 | 2136 | void wxMacMLTEControl::SetTXNData( const wxString& st, TXNOffset start, TXNOffset end ) |
5ca0d812 SC |
2137 | { |
2138 | #if wxUSE_UNICODE | |
2139 | #if SIZEOF_WCHAR_T == 2 | |
1832043f | 2140 | size_t len = st.length() ; |
fef981b4 | 2141 | TXNSetData( m_txn, kTXNUnicodeTextData, (void*)st.wc_str(), len * 2, start, end ); |
5ca0d812 | 2142 | #else |
d9d488cf | 2143 | wxMBConvUTF16 converter ; |
c88b7d28 DS |
2144 | ByteCount byteBufferLen = converter.WC2MB( NULL, st.wc_str(), 0 ) ; |
2145 | UniChar *unibuf = (UniChar*)malloc( byteBufferLen ) ; | |
fef981b4 DS |
2146 | converter.WC2MB( (char*)unibuf, st.wc_str(), byteBufferLen ) ; |
2147 | TXNSetData( m_txn, kTXNUnicodeTextData, (void*)unibuf, byteBufferLen, start, end ) ; | |
7d8268a1 | 2148 | free( unibuf ) ; |
587bc950 | 2149 | #endif |
5ca0d812 | 2150 | #else |
c88b7d28 | 2151 | wxCharBuffer text = st.mb_str( wxConvLocal ) ; |
fef981b4 | 2152 | TXNSetData( m_txn, kTXNTextData, (void*)text.data(), strlen( text ), start, end ) ; |
7d8268a1 | 2153 | #endif |
72055702 SC |
2154 | } |
2155 | ||
5ca0d812 | 2156 | wxString wxMacMLTEControl::GetLineText(long lineNo) const |
72055702 | 2157 | { |
5ca0d812 | 2158 | wxString line ; |
5ca0d812 | 2159 | |
bd3169a7 | 2160 | if ( lineNo < GetNumberOfLines() ) |
32b5be3d | 2161 | { |
fef981b4 DS |
2162 | Point firstPoint; |
2163 | Fixed lineWidth, lineHeight, currentHeight; | |
2164 | long ypos ; | |
7d8268a1 | 2165 | |
ae25e5cc | 2166 | // get the first possible position in the control |
ae25e5cc | 2167 | TXNOffsetToPoint(m_txn, 0, &firstPoint); |
7d8268a1 | 2168 | |
ae25e5cc RN |
2169 | // Iterate through the lines until we reach the one we want, |
2170 | // adding to our current y pixel point position | |
fef981b4 DS |
2171 | ypos = 0 ; |
2172 | currentHeight = 0; | |
ae25e5cc | 2173 | while (ypos < lineNo) |
32b5be3d | 2174 | { |
ae25e5cc RN |
2175 | TXNGetLineMetrics(m_txn, ypos++, &lineWidth, &lineHeight); |
2176 | currentHeight += lineHeight; | |
2177 | } | |
7d8268a1 | 2178 | |
eab19a7c | 2179 | Point thePoint = { firstPoint.v + (currentHeight >> 16), firstPoint.h + (0) }; |
ae25e5cc RN |
2180 | TXNOffset theOffset; |
2181 | TXNPointToOffset(m_txn, thePoint, &theOffset); | |
7d8268a1 | 2182 | |
ae25e5cc RN |
2183 | wxString content = GetStringValue() ; |
2184 | Point currentPoint = thePoint; | |
fef981b4 | 2185 | while (thePoint.v == currentPoint.v && theOffset < content.length()) |
ae25e5cc RN |
2186 | { |
2187 | line += content[theOffset]; | |
2188 | TXNOffsetToPoint(m_txn, ++theOffset, ¤tPoint); | |
21fd5529 | 2189 | } |
21fd5529 | 2190 | } |
fef981b4 | 2191 | |
5ca0d812 | 2192 | return line ; |
72055702 SC |
2193 | } |
2194 | ||
ffafe6ca | 2195 | int wxMacMLTEControl::GetLineLength(long lineNo) const |
72055702 | 2196 | { |
ae25e5cc RN |
2197 | int theLength = 0; |
2198 | ||
bd3169a7 | 2199 | if ( lineNo < GetNumberOfLines() ) |
32b5be3d | 2200 | { |
fef981b4 DS |
2201 | Point firstPoint; |
2202 | Fixed lineWidth, lineHeight, currentHeight; | |
ffafe6ca | 2203 | long ypos; |
7d8268a1 | 2204 | |
ae25e5cc | 2205 | // get the first possible position in the control |
ae25e5cc | 2206 | TXNOffsetToPoint(m_txn, 0, &firstPoint); |
7d8268a1 | 2207 | |
ae25e5cc RN |
2208 | // Iterate through the lines until we reach the one we want, |
2209 | // adding to our current y pixel point position | |
fef981b4 DS |
2210 | ypos = 0; |
2211 | currentHeight = 0; | |
ae25e5cc | 2212 | while (ypos < lineNo) |
32b5be3d | 2213 | { |
ae25e5cc RN |
2214 | TXNGetLineMetrics(m_txn, ypos++, &lineWidth, &lineHeight); |
2215 | currentHeight += lineHeight; | |
2216 | } | |
7d8268a1 | 2217 | |
eab19a7c | 2218 | Point thePoint = { firstPoint.v + (currentHeight >> 16), firstPoint.h + (0) }; |
ae25e5cc RN |
2219 | TXNOffset theOffset; |
2220 | TXNPointToOffset(m_txn, thePoint, &theOffset); | |
7d8268a1 | 2221 | |
ae25e5cc RN |
2222 | wxString content = GetStringValue() ; |
2223 | Point currentPoint = thePoint; | |
fef981b4 | 2224 | while (thePoint.v == currentPoint.v && theOffset < content.length()) |
ae25e5cc RN |
2225 | { |
2226 | ++theLength; | |
2227 | TXNOffsetToPoint(m_txn, ++theOffset, ¤tPoint); | |
29e4a190 | 2228 | } |
29e4a190 | 2229 | } |
fef981b4 | 2230 | |
ae25e5cc | 2231 | return theLength ; |
5ca0d812 | 2232 | } |
21fd5529 | 2233 | |
6239ee05 | 2234 | #if MAC_OS_X_VERSION_MIN_REQUIRED < MAC_OS_X_VERSION_10_5 |
4f74e0d1 | 2235 | |
5ca0d812 SC |
2236 | // ---------------------------------------------------------------------------- |
2237 | // MLTE control implementation (classic part) | |
2238 | // ---------------------------------------------------------------------------- | |
21fd5529 | 2239 | |
5de694f0 SC |
2240 | // OS X Notes : We still don't have a full replacement for MLTE, so this implementation |
2241 | // has to live on. We have different problems coming from outdated implementations on the | |
2242 | // various OS X versions. Most deal with the scrollbars: they are not correctly embedded | |
2243 | // while this can be solved on 10.3 by reassigning them the correct place, on 10.2 there is | |
2244 | // no way out, therefore we are using our own implementation and our own scrollbars .... | |
5ca0d812 | 2245 | |
5de694f0 SC |
2246 | TXNScrollInfoUPP gTXNScrollInfoProc = NULL ; |
2247 | ControlActionUPP gTXNScrollActionProc = NULL ; | |
0f7817ab | 2248 | |
fef981b4 DS |
2249 | pascal void wxMacMLTEClassicControl::TXNScrollInfoProc( |
2250 | SInt32 iValue, SInt32 iMaximumValue, | |
0207e969 | 2251 | TXNScrollBarOrientation iScrollBarOrientation, SInt32 iRefCon ) |
0f7817ab | 2252 | { |
5de694f0 SC |
2253 | wxMacMLTEClassicControl* mlte = (wxMacMLTEClassicControl*) iRefCon ; |
2254 | SInt32 value = wxMax( iValue , 0 ) ; | |
2255 | SInt32 maximum = wxMax( iMaximumValue , 0 ) ; | |
3dee36ae | 2256 | |
5de694f0 SC |
2257 | if ( iScrollBarOrientation == kTXNHorizontal ) |
2258 | { | |
2259 | if ( mlte->m_sbHorizontal ) | |
2260 | { | |
2261 | SetControl32BitValue( mlte->m_sbHorizontal , value ) ; | |
2262 | SetControl32BitMaximum( mlte->m_sbHorizontal , maximum ) ; | |
2263 | mlte->m_lastHorizontalValue = value ; | |
2264 | } | |
2265 | } | |
2266 | else if ( iScrollBarOrientation == kTXNVertical ) | |
5ca0d812 | 2267 | { |
5de694f0 SC |
2268 | if ( mlte->m_sbVertical ) |
2269 | { | |
2270 | SetControl32BitValue( mlte->m_sbVertical , value ) ; | |
2271 | SetControl32BitMaximum( mlte->m_sbVertical , maximum ) ; | |
2272 | mlte->m_lastVerticalValue = value ; | |
2273 | } | |
72055702 SC |
2274 | } |
2275 | } | |
2276 | ||
5de694f0 | 2277 | pascal void wxMacMLTEClassicControl::TXNScrollActionProc( ControlRef controlRef , ControlPartCode partCode ) |
72055702 | 2278 | { |
5de694f0 SC |
2279 | wxMacMLTEClassicControl* mlte = (wxMacMLTEClassicControl*) GetControlReference( controlRef ) ; |
2280 | if ( mlte == NULL ) | |
2281 | return ; | |
3dee36ae | 2282 | |
5de694f0 | 2283 | if ( controlRef != mlte->m_sbVertical && controlRef != mlte->m_sbHorizontal ) |
3dee36ae WS |
2284 | return ; |
2285 | ||
fef981b4 | 2286 | OSStatus err ; |
3dee36ae WS |
2287 | bool isHorizontal = ( controlRef == mlte->m_sbHorizontal ) ; |
2288 | ||
5de694f0 SC |
2289 | SInt32 minimum = 0 ; |
2290 | SInt32 maximum = GetControl32BitMaximum( controlRef ) ; | |
2291 | SInt32 value = GetControl32BitValue( controlRef ) ; | |
2292 | SInt32 delta = 0; | |
fef981b4 | 2293 | |
5de694f0 SC |
2294 | switch ( partCode ) |
2295 | { | |
2296 | case kControlDownButtonPart : | |
2297 | delta = 10 ; | |
2298 | break ; | |
fef981b4 | 2299 | |
5de694f0 SC |
2300 | case kControlUpButtonPart : |
2301 | delta = -10 ; | |
2302 | break ; | |
fef981b4 | 2303 | |
5de694f0 SC |
2304 | case kControlPageDownPart : |
2305 | delta = GetControlViewSize( controlRef ) ; | |
2306 | break ; | |
fef981b4 | 2307 | |
5de694f0 | 2308 | case kControlPageUpPart : |
fef981b4 | 2309 | delta = -GetControlViewSize( controlRef ) ; |
5de694f0 | 2310 | break ; |
fef981b4 | 2311 | |
5de694f0 | 2312 | case kControlIndicatorPart : |
c88b7d28 | 2313 | delta = value - (isHorizontal ? mlte->m_lastHorizontalValue : mlte->m_lastVerticalValue) ; |
5de694f0 | 2314 | break ; |
fef981b4 | 2315 | |
5de694f0 SC |
2316 | default : |
2317 | break ; | |
2318 | } | |
fef981b4 | 2319 | |
5de694f0 | 2320 | if ( delta != 0 ) |
e600c175 | 2321 | { |
5de694f0 | 2322 | SInt32 newValue = value ; |
3dee36ae | 2323 | |
5de694f0 SC |
2324 | if ( partCode != kControlIndicatorPart ) |
2325 | { | |
fef981b4 | 2326 | if ( value + delta < minimum ) |
5de694f0 SC |
2327 | delta = minimum - value ; |
2328 | if ( value + delta > maximum ) | |
2329 | delta = maximum - value ; | |
2330 | ||
2331 | SetControl32BitValue( controlRef , value + delta ) ; | |
2332 | newValue = value + delta ; | |
2333 | } | |
3dee36ae | 2334 | |
5de694f0 SC |
2335 | SInt32 verticalDelta = isHorizontal ? 0 : delta ; |
2336 | SInt32 horizontalDelta = isHorizontal ? delta : 0 ; | |
3dee36ae | 2337 | |
0207e969 DS |
2338 | err = TXNScroll( |
2339 | mlte->m_txn, kTXNScrollUnitsInPixels, kTXNScrollUnitsInPixels, | |
2340 | &verticalDelta, &horizontalDelta ); | |
ffafe6ca | 2341 | verify_noerr( err ); |
3dee36ae | 2342 | |
5de694f0 SC |
2343 | if ( isHorizontal ) |
2344 | mlte->m_lastHorizontalValue = newValue ; | |
2345 | else | |
2346 | mlte->m_lastVerticalValue = newValue ; | |
5ca0d812 | 2347 | } |
5ca0d812 | 2348 | } |
7d8268a1 | 2349 | |
0f7817ab | 2350 | // make correct activations |
fef981b4 | 2351 | void wxMacMLTEClassicControl::MacActivatePaneText(bool setActive) |
0f7817ab SC |
2352 | { |
2353 | wxTextCtrl* textctrl = (wxTextCtrl*) GetControlReference(m_controlRef); | |
ef4a634b | 2354 | |
5de694f0 | 2355 | wxMacWindowClipper clipper( textctrl ) ; |
c88b7d28 | 2356 | TXNActivate( m_txn, m_txnFrameID, setActive ); |
0f7817ab | 2357 | |
5de694f0 SC |
2358 | ControlRef controlFocus = 0 ; |
2359 | GetKeyboardFocus( m_txnWindow , &controlFocus ) ; | |
2360 | if ( controlFocus == m_controlRef ) | |
fef981b4 | 2361 | TXNFocus( m_txn, setActive ); |
5de694f0 SC |
2362 | } |
2363 | ||
fef981b4 | 2364 | void wxMacMLTEClassicControl::MacFocusPaneText(bool setFocus) |
5de694f0 | 2365 | { |
0207e969 | 2366 | TXNFocus( m_txn, setFocus ); |
5ca0d812 | 2367 | } |
1fa29bdc | 2368 | |
3dee36ae | 2369 | // guards against inappropriate redraw (hidden objects drawing onto window) |
0f7817ab | 2370 | |
fef981b4 | 2371 | void wxMacMLTEClassicControl::MacSetObjectVisibility(bool vis) |
0f7817ab | 2372 | { |
789ae0cf SC |
2373 | ControlRef controlFocus = 0 ; |
2374 | GetKeyboardFocus( m_txnWindow , &controlFocus ) ; | |
3dee36ae | 2375 | |
fef981b4 | 2376 | if ( !vis && (controlFocus == m_controlRef ) ) |
789ae0cf | 2377 | SetKeyboardFocus( m_txnWindow , m_controlRef , kControlFocusNoPart ) ; |
3dee36ae | 2378 | |
4611a719 | 2379 | TXNControlTag iControlTags[1] = { kTXNVisibilityTag }; |
c88b7d28 | 2380 | TXNControlData iControlData[1] = { { (UInt32)false } }; |
bd2213c2 | 2381 | |
fef981b4 | 2382 | verify_noerr( TXNGetTXNObjectControls( m_txn , 1, iControlTags, iControlData ) ) ; |
3dee36ae | 2383 | |
bd2213c2 SC |
2384 | if ( iControlData[0].uValue != vis ) |
2385 | { | |
2386 | iControlData[0].uValue = vis ; | |
0207e969 | 2387 | verify_noerr( TXNSetTXNObjectControls( m_txn, false , 1, iControlTags, iControlData ) ) ; |
bd2213c2 | 2388 | } |
fef981b4 | 2389 | |
0207e969 DS |
2390 | // currently, we always clip as partial visibility (overlapped) visibility is also a problem, |
2391 | // if we run into further problems we might set the FrameBounds to an empty rect here | |
5ca0d812 | 2392 | } |
1fa29bdc | 2393 | |
0f7817ab | 2394 | // make sure that the TXNObject is at the right position |
5de694f0 | 2395 | |
3dee36ae | 2396 | void wxMacMLTEClassicControl::MacUpdatePosition() |
0f7817ab | 2397 | { |
c88b7d28 | 2398 | wxTextCtrl* textctrl = (wxTextCtrl*)GetControlReference( m_controlRef ); |
0f7817ab SC |
2399 | if ( textctrl == NULL ) |
2400 | return ; | |
7d8268a1 | 2401 | |
0f7817ab | 2402 | Rect bounds ; |
c88b7d28 | 2403 | UMAGetControlBoundsInWindowCoords( m_controlRef, &bounds ); |
3dee36ae | 2404 | |
ba75e603 SC |
2405 | wxRect visRect = textctrl->MacGetClippedClientRect() ; |
2406 | Rect visBounds = { visRect.y , visRect.x , visRect.y + visRect.height , visRect.x + visRect.width } ; | |
2407 | int x , y ; | |
2408 | x = y = 0 ; | |
2409 | textctrl->MacWindowToRootWindow( &x , &y ) ; | |
2410 | OffsetRect( &visBounds , x , y ) ; | |
3dee36ae | 2411 | |
c88b7d28 | 2412 | if ( !EqualRect( &bounds, &m_txnControlBounds ) || !EqualRect( &visBounds, &m_txnVisBounds ) ) |
0f7817ab | 2413 | { |
0f7817ab | 2414 | m_txnControlBounds = bounds ; |
ba75e603 | 2415 | m_txnVisBounds = visBounds ; |
c88b7d28 | 2416 | wxMacWindowClipper cl( textctrl ) ; |
5de694f0 | 2417 | |
4e477040 SC |
2418 | if ( m_sbHorizontal || m_sbVertical ) |
2419 | { | |
5de694f0 SC |
2420 | int w = bounds.right - bounds.left ; |
2421 | int h = bounds.bottom - bounds.top ; | |
4e477040 SC |
2422 | |
2423 | if ( m_sbHorizontal ) | |
2424 | { | |
2425 | Rect sbBounds ; | |
5de694f0 | 2426 | |
4e477040 | 2427 | sbBounds.left = -1 ; |
5de694f0 SC |
2428 | sbBounds.top = h - 14 ; |
2429 | sbBounds.right = w + 1 ; | |
2430 | sbBounds.bottom = h + 1 ; | |
3dee36ae | 2431 | |
4e477040 | 2432 | SetControlBounds( m_sbHorizontal , &sbBounds ) ; |
5de694f0 | 2433 | SetControlViewSize( m_sbHorizontal , w ) ; |
4e477040 | 2434 | } |
0207e969 | 2435 | |
4e477040 SC |
2436 | if ( m_sbVertical ) |
2437 | { | |
2438 | Rect sbBounds ; | |
5de694f0 SC |
2439 | |
2440 | sbBounds.left = w - 14 ; | |
4e477040 | 2441 | sbBounds.top = -1 ; |
5de694f0 | 2442 | sbBounds.right = w + 1 ; |
fef981b4 | 2443 | sbBounds.bottom = m_sbHorizontal ? h - 14 : h + 1 ; |
3dee36ae | 2444 | |
4e477040 | 2445 | SetControlBounds( m_sbVertical , &sbBounds ) ; |
5de694f0 | 2446 | SetControlViewSize( m_sbVertical , h ) ; |
4e477040 SC |
2447 | } |
2448 | } | |
3dee36ae | 2449 | |
c447d5a9 SC |
2450 | Rect oldviewRect ; |
2451 | TXNLongRect olddestRect ; | |
2452 | TXNGetRectBounds( m_txn , &oldviewRect , &olddestRect , NULL ) ; | |
3dee36ae | 2453 | |
c447d5a9 | 2454 | Rect viewRect = { m_txnControlBounds.top, m_txnControlBounds.left, |
fef981b4 DS |
2455 | m_txnControlBounds.bottom - ( m_sbHorizontal ? 14 : 0 ) , |
2456 | m_txnControlBounds.right - ( m_sbVertical ? 14 : 0 ) } ; | |
c447d5a9 | 2457 | TXNLongRect destRect = { m_txnControlBounds.top, m_txnControlBounds.left, |
fef981b4 DS |
2458 | m_txnControlBounds.bottom - ( m_sbHorizontal ? 14 : 0 ) , |
2459 | m_txnControlBounds.right - ( m_sbVertical ? 14 : 0 ) } ; | |
3dee36ae | 2460 | |
c447d5a9 SC |
2461 | if ( olddestRect.right >= 10000 ) |
2462 | destRect.right = destRect.left + 32000 ; | |
3dee36ae | 2463 | |
c447d5a9 SC |
2464 | if ( olddestRect.bottom >= 0x20000000 ) |
2465 | destRect.bottom = destRect.top + 0x40000000 ; | |
3dee36ae WS |
2466 | |
2467 | SectRect( &viewRect , &visBounds , &viewRect ) ; | |
823c4e96 | 2468 | TXNSetRectBounds( m_txn , &viewRect , &destRect , true ) ; |
fef981b4 DS |
2469 | |
2470 | #if 0 | |
2471 | TXNSetFrameBounds( | |
2472 | m_txn, | |
2473 | m_txnControlBounds.top, | |
2474 | m_txnControlBounds.left, | |
2475 | m_txnControlBounds.bottom - (m_sbHorizontal ? 14 : 0), | |
2476 | m_txnControlBounds.right - (m_sbVertical ? 14 : 0), | |
2477 | m_txnFrameID ); | |
2478 | #endif | |
c88b7d28 DS |
2479 | |
2480 | // the SetFrameBounds method under Classic sometimes does not correctly scroll a selection into sight after a | |
5de694f0 SC |
2481 | // movement, therefore we have to force it |
2482 | ||
fef981b4 | 2483 | // this problem has been reported in OSX as well, so we use this here once again |
0207e969 | 2484 | |
5de694f0 | 2485 | TXNLongRect textRect ; |
3dee36ae | 2486 | TXNGetRectBounds( m_txn , NULL , NULL , &textRect ) ; |
5de694f0 | 2487 | if ( textRect.left < m_txnControlBounds.left ) |
fef981b4 | 2488 | TXNShowSelection( m_txn , kTXNShowStart ) ; |
e600c175 | 2489 | } |
5ca0d812 SC |
2490 | } |
2491 | ||
3dee36ae | 2492 | void wxMacMLTEClassicControl::SetRect( Rect *r ) |
0f7817ab SC |
2493 | { |
2494 | wxMacControl::SetRect( r ) ; | |
2495 | MacUpdatePosition() ; | |
2496 | } | |
2497 | ||
89954433 | 2498 | void wxMacMLTEClassicControl::MacControlUserPaneDrawProc(wxInt16 WXUNUSED(thePart)) |
24260aae | 2499 | { |
c88b7d28 | 2500 | wxTextCtrl* textctrl = (wxTextCtrl*)GetControlReference( m_controlRef ); |
5ca0d812 | 2501 | if ( textctrl == NULL ) |
e600c175 | 2502 | return ; |
7d8268a1 | 2503 | |
5ca0d812 SC |
2504 | if ( textctrl->MacIsReallyShown() ) |
2505 | { | |
2506 | wxMacWindowClipper clipper( textctrl ) ; | |
0f7817ab | 2507 | TXNDraw( m_txn , NULL ) ; |
e600c175 | 2508 | } |
5ca0d812 SC |
2509 | } |
2510 | ||
3dee36ae | 2511 | wxInt16 wxMacMLTEClassicControl::MacControlUserPaneHitTestProc(wxInt16 x, wxInt16 y) |
24260aae SC |
2512 | { |
2513 | Point where = { y , x } ; | |
a8d2fb31 | 2514 | ControlPartCode result = kControlNoPart; |
5de694f0 | 2515 | |
0207e969 | 2516 | wxTextCtrl* textctrl = (wxTextCtrl*) GetControlReference( m_controlRef ); |
a8d2fb31 | 2517 | if ( (textctrl != NULL) && textctrl->MacIsReallyShown() ) |
72055702 | 2518 | { |
fef981b4 DS |
2519 | if (PtInRect( where, &m_txnControlBounds )) |
2520 | { | |
5de694f0 | 2521 | result = kControlEditTextPart ; |
fef981b4 | 2522 | } |
7d8268a1 | 2523 | else |
3556e470 SC |
2524 | { |
2525 | // sometimes we get the coords also in control local coordinates, therefore test again | |
ab346e1c VZ |
2526 | int x = 0 , y = 0 ; |
2527 | textctrl->MacClientToRootWindow( &x , &y ) ; | |
2528 | where.h += x ; | |
2529 | where.v += y ; | |
fef981b4 | 2530 | |
0207e969 | 2531 | if (PtInRect( where, &m_txnControlBounds )) |
5de694f0 | 2532 | result = kControlEditTextPart ; |
3556e470 | 2533 | } |
5ca0d812 | 2534 | } |
a8d2fb31 | 2535 | |
5ca0d812 SC |
2536 | return result; |
2537 | } | |
2538 | ||
89954433 | 2539 | wxInt16 wxMacMLTEClassicControl::MacControlUserPaneTrackingProc( wxInt16 x, wxInt16 y, void* WXUNUSED(actionProc) ) |
24260aae | 2540 | { |
a8d2fb31 | 2541 | ControlPartCode result = kControlNoPart; |
5de694f0 | 2542 | |
0207e969 | 2543 | wxTextCtrl* textctrl = (wxTextCtrl*) GetControlReference( m_controlRef ); |
a8d2fb31 | 2544 | if ( (textctrl != NULL) && textctrl->MacIsReallyShown() ) |
7d8268a1 | 2545 | { |
a8d2fb31 | 2546 | Point startPt = { y , x } ; |
ab346e1c | 2547 | |
5ca0d812 | 2548 | // for compositing, we must convert these into toplevel window coordinates, because hittesting expects them |
ab346e1c VZ |
2549 | int x = 0 , y = 0 ; |
2550 | textctrl->MacClientToRootWindow( &x , &y ) ; | |
2551 | startPt.h += x ; | |
2552 | startPt.v += y ; | |
7d8268a1 | 2553 | |
24260aae | 2554 | switch (MacControlUserPaneHitTestProc( startPt.h , startPt.v )) |
5ca0d812 | 2555 | { |
5de694f0 | 2556 | case kControlEditTextPart : |
7d8268a1 WS |
2557 | { |
2558 | wxMacWindowClipper clipper( textctrl ) ; | |
7d8268a1 | 2559 | EventRecord rec ; |
c88b7d28 | 2560 | |
7d8268a1 | 2561 | ConvertEventRefToEventRecord( (EventRef) wxTheApp->MacGetCurrentEvent() , &rec ) ; |
24260aae | 2562 | TXNClick( m_txn, &rec ); |
7d8268a1 | 2563 | } |
fef981b4 | 2564 | break; |
a8d2fb31 | 2565 | |
fef981b4 DS |
2566 | default : |
2567 | break; | |
5ca0d812 SC |
2568 | } |
2569 | } | |
a8d2fb31 DS |
2570 | |
2571 | return result; | |
5ca0d812 SC |
2572 | } |
2573 | ||
3dee36ae | 2574 | void wxMacMLTEClassicControl::MacControlUserPaneIdleProc() |
24260aae | 2575 | { |
c88b7d28 | 2576 | wxTextCtrl* textctrl = (wxTextCtrl*)GetControlReference( m_controlRef ); |
5ca0d812 SC |
2577 | if ( textctrl == NULL ) |
2578 | return ; | |
24260aae | 2579 | |
3dee36ae | 2580 | if (textctrl->MacIsReallyShown()) |
24260aae | 2581 | { |
3dee36ae | 2582 | if (IsControlActive(m_controlRef)) |
24260aae | 2583 | { |
5ca0d812 | 2584 | Point mousep; |
7d8268a1 | 2585 | |
5ca0d812 SC |
2586 | wxMacWindowClipper clipper( textctrl ) ; |
2587 | GetMouse(&mousep); | |
5de694f0 SC |
2588 | |
2589 | TXNIdle(m_txn); | |
2590 | ||
3dee36ae | 2591 | if (PtInRect(mousep, &m_txnControlBounds)) |
24260aae | 2592 | { |
fef981b4 DS |
2593 | RgnHandle theRgn = NewRgn(); |
2594 | RectRgn(theRgn, &m_txnControlBounds); | |
5de694f0 SC |
2595 | TXNAdjustCursor(m_txn, theRgn); |
2596 | DisposeRgn(theRgn); | |
72055702 | 2597 | } |
5ca0d812 SC |
2598 | } |
2599 | } | |
2600 | } | |
72055702 | 2601 | |
3dee36ae | 2602 | wxInt16 wxMacMLTEClassicControl::MacControlUserPaneKeyDownProc (wxInt16 keyCode, wxInt16 charCode, wxInt16 modifiers) |
24260aae | 2603 | { |
c88b7d28 | 2604 | wxTextCtrl* textctrl = (wxTextCtrl*)GetControlReference( m_controlRef ); |
5ca0d812 | 2605 | if ( textctrl == NULL ) |
a8d2fb31 | 2606 | return kControlNoPart; |
7d8268a1 | 2607 | |
5de694f0 | 2608 | wxMacWindowClipper clipper( textctrl ) ; |
ef4a634b | 2609 | |
5de694f0 SC |
2610 | EventRecord ev ; |
2611 | memset( &ev , 0 , sizeof( ev ) ) ; | |
2612 | ev.what = keyDown ; | |
2613 | ev.modifiers = modifiers ; | |
fef981b4 DS |
2614 | ev.message = ((keyCode << 8) & keyCodeMask) | (charCode & charCodeMask); |
2615 | TXNKeyDown( m_txn , &ev ); | |
3dee36ae | 2616 | |
5de694f0 SC |
2617 | return kControlEntireControl; |
2618 | } | |
24260aae | 2619 | |
c88b7d28 | 2620 | void wxMacMLTEClassicControl::MacControlUserPaneActivateProc(bool activating) |
24260aae | 2621 | { |
5de694f0 | 2622 | MacActivatePaneText( activating ); |
72055702 SC |
2623 | } |
2624 | ||
3dee36ae | 2625 | wxInt16 wxMacMLTEClassicControl::MacControlUserPaneFocusProc(wxInt16 action) |
24260aae | 2626 | { |
c88b7d28 | 2627 | ControlPartCode focusResult = kControlFocusNoPart; |
7d8268a1 | 2628 | |
c88b7d28 | 2629 | wxTextCtrl* textctrl = (wxTextCtrl*)GetControlReference( m_controlRef ); |
5ca0d812 | 2630 | if ( textctrl == NULL ) |
c88b7d28 | 2631 | return focusResult; |
0f7817ab SC |
2632 | |
2633 | wxMacWindowClipper clipper( textctrl ) ; | |
3dee36ae | 2634 | |
a8d2fb31 | 2635 | ControlRef controlFocus = NULL ; |
5de694f0 SC |
2636 | GetKeyboardFocus( m_txnWindow , &controlFocus ) ; |
2637 | bool wasFocused = ( controlFocus == m_controlRef ) ; | |
2638 | ||
3dee36ae | 2639 | switch (action) |
24260aae | 2640 | { |
5de694f0 SC |
2641 | case kControlFocusPrevPart: |
2642 | case kControlFocusNextPart: | |
0207e969 DS |
2643 | MacFocusPaneText( !wasFocused ); |
2644 | focusResult = (!wasFocused ? (ControlPartCode) kControlEditTextPart : (ControlPartCode) kControlFocusNoPart); | |
5de694f0 | 2645 | break; |
3dee36ae | 2646 | |
5ca0d812 | 2647 | case kControlFocusNoPart: |
5de694f0 | 2648 | default: |
a8d2fb31 | 2649 | MacFocusPaneText( false ); |
5ca0d812 SC |
2650 | focusResult = kControlFocusNoPart; |
2651 | break; | |
5ca0d812 | 2652 | } |
0f7817ab | 2653 | |
5ca0d812 | 2654 | return focusResult; |
72055702 SC |
2655 | } |
2656 | ||
89954433 | 2657 | void wxMacMLTEClassicControl::MacControlUserPaneBackgroundProc( void *WXUNUSED(info) ) |
24260aae SC |
2658 | { |
2659 | } | |
2660 | ||
0f7817ab | 2661 | wxMacMLTEClassicControl::wxMacMLTEClassicControl( wxTextCtrl *wxPeer, |
ffafe6ca DS |
2662 | const wxString& str, |
2663 | const wxPoint& pos, | |
2664 | const wxSize& size, long style ) | |
2665 | : wxMacMLTEControl( wxPeer ) | |
72055702 | 2666 | { |
5ca0d812 SC |
2667 | m_font = wxPeer->GetFont() ; |
2668 | m_windowStyle = style ; | |
7d8268a1 | 2669 | Rect bounds = wxMacGetBoundsForControl( wxPeer , pos , size ) ; |
72055702 | 2670 | |
c88b7d28 | 2671 | short featureSet = |
0207e969 DS |
2672 | kControlSupportsEmbedding | kControlSupportsFocus | kControlWantsIdle |
2673 | | kControlWantsActivate | kControlHandlesTracking | |
2674 | // | kControlHasSpecialBackground | |
2675 | | kControlGetsFocusOnClick | kControlSupportsLiveFeedback; | |
72055702 | 2676 | |
ffafe6ca DS |
2677 | OSStatus err = ::CreateUserPaneControl( |
2678 | MAC_WXHWND(wxPeer->GetParent()->MacGetTopLevelWindowRef()), | |
2679 | &bounds, featureSet, &m_controlRef ); | |
2680 | verify_noerr( err ); | |
7d8268a1 | 2681 | |
0f7817ab | 2682 | DoCreate(); |
7d8268a1 | 2683 | |
a8d2fb31 | 2684 | AdjustCreationAttributes( *wxWHITE , true ) ; |
5ca0d812 | 2685 | |
bd2213c2 SC |
2686 | MacSetObjectVisibility( wxPeer->MacIsReallyShown() ) ; |
2687 | ||
24eef584 SC |
2688 | { |
2689 | wxString st = str ; | |
2690 | wxMacConvertNewlines10To13( &st ) ; | |
2691 | wxMacWindowClipper clipper( m_peer ) ; | |
2692 | SetTXNData( st , kTXNStartOffset, kTXNEndOffset ) ; | |
0207e969 | 2693 | TXNSetSelection( m_txn, 0, 0 ) ; |
24eef584 | 2694 | } |
72055702 SC |
2695 | } |
2696 | ||
5ca0d812 | 2697 | wxMacMLTEClassicControl::~wxMacMLTEClassicControl() |
72055702 | 2698 | { |
0207e969 | 2699 | TXNDeleteObject( m_txn ); |
5de694f0 | 2700 | m_txn = NULL ; |
72055702 SC |
2701 | } |
2702 | ||
7d8268a1 | 2703 | void wxMacMLTEClassicControl::VisibilityChanged(bool shown) |
72055702 | 2704 | { |
0f7817ab | 2705 | MacSetObjectVisibility( shown ) ; |
4e477040 SC |
2706 | wxMacControl::VisibilityChanged( shown ) ; |
2707 | } | |
2708 | ||
2709 | void wxMacMLTEClassicControl::SuperChangedPosition() | |
2710 | { | |
2711 | MacUpdatePosition() ; | |
2712 | wxMacControl::SuperChangedPosition() ; | |
72055702 SC |
2713 | } |
2714 | ||
5de694f0 SC |
2715 | ControlUserPaneDrawUPP gTPDrawProc = NULL; |
2716 | ControlUserPaneHitTestUPP gTPHitProc = NULL; | |
2717 | ControlUserPaneTrackingUPP gTPTrackProc = NULL; | |
2718 | ControlUserPaneIdleUPP gTPIdleProc = NULL; | |
2719 | ControlUserPaneKeyDownUPP gTPKeyProc = NULL; | |
2720 | ControlUserPaneActivateUPP gTPActivateProc = NULL; | |
2721 | ControlUserPaneFocusUPP gTPFocusProc = NULL; | |
2722 | ||
24260aae SC |
2723 | static pascal void wxMacControlUserPaneDrawProc(ControlRef control, SInt16 part) |
2724 | { | |
2725 | wxTextCtrl *textCtrl = wxDynamicCast( wxFindControlFromMacControl(control) , wxTextCtrl ) ; | |
bc8f7aee | 2726 | wxMacMLTEClassicControl * win = textCtrl ? (wxMacMLTEClassicControl*)(textCtrl->GetPeer()) : NULL ; |
24260aae | 2727 | if ( win ) |
ffafe6ca | 2728 | win->MacControlUserPaneDrawProc( part ) ; |
24260aae SC |
2729 | } |
2730 | ||
c7fe80e2 | 2731 | static pascal ControlPartCode wxMacControlUserPaneHitTestProc(ControlRef control, Point where) |
24260aae SC |
2732 | { |
2733 | wxTextCtrl *textCtrl = wxDynamicCast( wxFindControlFromMacControl(control) , wxTextCtrl ) ; | |
bc8f7aee | 2734 | wxMacMLTEClassicControl * win = textCtrl ? (wxMacMLTEClassicControl*)(textCtrl->GetPeer()) : NULL ; |
24260aae | 2735 | if ( win ) |
ffafe6ca | 2736 | return win->MacControlUserPaneHitTestProc( where.h , where.v ) ; |
24260aae SC |
2737 | else |
2738 | return kControlNoPart ; | |
2739 | } | |
2740 | ||
c7fe80e2 | 2741 | static pascal ControlPartCode wxMacControlUserPaneTrackingProc(ControlRef control, Point startPt, ControlActionUPP actionProc) |
24260aae SC |
2742 | { |
2743 | wxTextCtrl *textCtrl = wxDynamicCast( wxFindControlFromMacControl(control) , wxTextCtrl ) ; | |
bc8f7aee | 2744 | wxMacMLTEClassicControl * win = textCtrl ? (wxMacMLTEClassicControl*)(textCtrl->GetPeer()) : NULL ; |
24260aae | 2745 | if ( win ) |
ffafe6ca | 2746 | return win->MacControlUserPaneTrackingProc( startPt.h , startPt.v , (void*) actionProc ) ; |
24260aae SC |
2747 | else |
2748 | return kControlNoPart ; | |
2749 | } | |
2750 | ||
2751 | static pascal void wxMacControlUserPaneIdleProc(ControlRef control) | |
2752 | { | |
2753 | wxTextCtrl *textCtrl = wxDynamicCast( wxFindControlFromMacControl(control) , wxTextCtrl ) ; | |
bc8f7aee | 2754 | wxMacMLTEClassicControl * win = textCtrl ? (wxMacMLTEClassicControl*)(textCtrl->GetPeer()) : NULL ; |
24260aae SC |
2755 | if ( win ) |
2756 | win->MacControlUserPaneIdleProc() ; | |
2757 | } | |
2758 | ||
2759 | static pascal ControlPartCode wxMacControlUserPaneKeyDownProc(ControlRef control, SInt16 keyCode, SInt16 charCode, SInt16 modifiers) | |
2760 | { | |
2761 | wxTextCtrl *textCtrl = wxDynamicCast( wxFindControlFromMacControl(control) , wxTextCtrl ) ; | |
bc8f7aee | 2762 | wxMacMLTEClassicControl * win = textCtrl ? (wxMacMLTEClassicControl*)(textCtrl->GetPeer()) : NULL ; |
24260aae | 2763 | if ( win ) |
ffafe6ca | 2764 | return win->MacControlUserPaneKeyDownProc( keyCode, charCode, modifiers ) ; |
24260aae SC |
2765 | else |
2766 | return kControlNoPart ; | |
2767 | } | |
2768 | ||
2769 | static pascal void wxMacControlUserPaneActivateProc(ControlRef control, Boolean activating) | |
2770 | { | |
2771 | wxTextCtrl *textCtrl = wxDynamicCast( wxFindControlFromMacControl(control) , wxTextCtrl ) ; | |
bc8f7aee | 2772 | wxMacMLTEClassicControl * win = textCtrl ? (wxMacMLTEClassicControl*)(textCtrl->GetPeer()) : NULL ; |
24260aae | 2773 | if ( win ) |
ffafe6ca | 2774 | win->MacControlUserPaneActivateProc( activating ) ; |
24260aae SC |
2775 | } |
2776 | ||
2777 | static pascal ControlPartCode wxMacControlUserPaneFocusProc(ControlRef control, ControlFocusPart action) | |
2778 | { | |
2779 | wxTextCtrl *textCtrl = wxDynamicCast( wxFindControlFromMacControl(control) , wxTextCtrl ) ; | |
bc8f7aee | 2780 | wxMacMLTEClassicControl * win = textCtrl ? (wxMacMLTEClassicControl*)(textCtrl->GetPeer()) : NULL ; |
24260aae | 2781 | if ( win ) |
ffafe6ca | 2782 | return win->MacControlUserPaneFocusProc( action ) ; |
24260aae SC |
2783 | else |
2784 | return kControlNoPart ; | |
2785 | } | |
2786 | ||
fef981b4 | 2787 | #if 0 |
24260aae SC |
2788 | static pascal void wxMacControlUserPaneBackgroundProc(ControlRef control, ControlBackgroundPtr info) |
2789 | { | |
2790 | wxTextCtrl *textCtrl = wxDynamicCast( wxFindControlFromMacControl(control) , wxTextCtrl ) ; | |
bc8f7aee | 2791 | wxMacMLTEClassicControl * win = textCtrl ? (wxMacMLTEClassicControl*)(textCtrl->GetPeer()) : NULL ; |
24260aae SC |
2792 | if ( win ) |
2793 | win->MacControlUserPaneBackgroundProc(info) ; | |
2794 | } | |
2795 | #endif | |
2796 | ||
5de694f0 SC |
2797 | // TXNRegisterScrollInfoProc |
2798 | ||
5ca0d812 | 2799 | OSStatus wxMacMLTEClassicControl::DoCreate() |
2b5f62a0 | 2800 | { |
5ca0d812 | 2801 | Rect bounds; |
5ca0d812 | 2802 | OSStatus err = noErr ; |
7d8268a1 | 2803 | |
fef981b4 | 2804 | // set up our globals |
24260aae SC |
2805 | if (gTPDrawProc == NULL) gTPDrawProc = NewControlUserPaneDrawUPP(wxMacControlUserPaneDrawProc); |
2806 | if (gTPHitProc == NULL) gTPHitProc = NewControlUserPaneHitTestUPP(wxMacControlUserPaneHitTestProc); | |
2807 | if (gTPTrackProc == NULL) gTPTrackProc = NewControlUserPaneTrackingUPP(wxMacControlUserPaneTrackingProc); | |
2808 | if (gTPIdleProc == NULL) gTPIdleProc = NewControlUserPaneIdleUPP(wxMacControlUserPaneIdleProc); | |
2809 | if (gTPKeyProc == NULL) gTPKeyProc = NewControlUserPaneKeyDownUPP(wxMacControlUserPaneKeyDownProc); | |
2810 | if (gTPActivateProc == NULL) gTPActivateProc = NewControlUserPaneActivateUPP(wxMacControlUserPaneActivateProc); | |
2811 | if (gTPFocusProc == NULL) gTPFocusProc = NewControlUserPaneFocusUPP(wxMacControlUserPaneFocusProc); | |
5de694f0 SC |
2812 | |
2813 | if (gTXNScrollInfoProc == NULL ) gTXNScrollInfoProc = NewTXNScrollInfoUPP(TXNScrollInfoProc) ; | |
2814 | if (gTXNScrollActionProc == NULL ) gTXNScrollActionProc = NewControlActionUPP(TXNScrollActionProc) ; | |
7d8268a1 | 2815 | |
fef981b4 | 2816 | // set the initial settings for our private data |
7d8268a1 | 2817 | |
a8d2fb31 | 2818 | m_txnWindow = GetControlOwner(m_controlRef); |
5de694f0 | 2819 | m_txnPort = (GrafPtr) GetWindowPort(m_txnWindow); |
7d8268a1 | 2820 | |
fef981b4 | 2821 | // set up the user pane procedures |
5ca0d812 SC |
2822 | SetControlData(m_controlRef, kControlEntireControl, kControlUserPaneDrawProcTag, sizeof(gTPDrawProc), &gTPDrawProc); |
2823 | SetControlData(m_controlRef, kControlEntireControl, kControlUserPaneHitTestProcTag, sizeof(gTPHitProc), &gTPHitProc); | |
2824 | SetControlData(m_controlRef, kControlEntireControl, kControlUserPaneTrackingProcTag, sizeof(gTPTrackProc), &gTPTrackProc); | |
2825 | SetControlData(m_controlRef, kControlEntireControl, kControlUserPaneIdleProcTag, sizeof(gTPIdleProc), &gTPIdleProc); | |
2826 | SetControlData(m_controlRef, kControlEntireControl, kControlUserPaneKeyDownProcTag, sizeof(gTPKeyProc), &gTPKeyProc); | |
2827 | SetControlData(m_controlRef, kControlEntireControl, kControlUserPaneActivateProcTag, sizeof(gTPActivateProc), &gTPActivateProc); | |
2828 | SetControlData(m_controlRef, kControlEntireControl, kControlUserPaneFocusProcTag, sizeof(gTPFocusProc), &gTPFocusProc); | |
c88b7d28 | 2829 | |
fef981b4 | 2830 | // calculate the rectangles used by the control |
c88b7d28 | 2831 | UMAGetControlBoundsInWindowCoords( m_controlRef, &bounds ); |
3dee36ae | 2832 | |
0f7817ab | 2833 | m_txnControlBounds = bounds ; |
ba75e603 | 2834 | m_txnVisBounds = bounds ; |
3dee36ae | 2835 | |
fef981b4 DS |
2836 | CGrafPtr origPort ; |
2837 | GDHandle origDev ; | |
7d8268a1 | 2838 | |
c88b7d28 | 2839 | GetGWorld( &origPort, &origDev ) ; |
fef981b4 | 2840 | SetPort( m_txnPort ); |
7d8268a1 | 2841 | |
fef981b4 | 2842 | // create the new edit field |
c88b7d28 | 2843 | TXNFrameOptions frameOptions = FrameOptionsFromWXStyle( m_windowStyle ); |
7d8268a1 | 2844 | |
fef981b4 DS |
2845 | // the scrollbars are not correctly embedded but are inserted at the root: |
2846 | // this gives us problems as we have erratic redraws even over the structure area | |
4e477040 | 2847 | |
5de694f0 SC |
2848 | m_sbHorizontal = 0 ; |
2849 | m_sbVertical = 0 ; | |
2850 | m_lastHorizontalValue = 0 ; | |
2851 | m_lastVerticalValue = 0 ; | |
3dee36ae | 2852 | |
5de694f0 SC |
2853 | Rect sb = { 0 , 0 , 0 , 0 } ; |
2854 | if ( frameOptions & kTXNWantVScrollBarMask ) | |
2855 | { | |
c88b7d28 DS |
2856 | CreateScrollBarControl( m_txnWindow, &sb, 0, 0, 100, 1, true, gTXNScrollActionProc, &m_sbVertical ); |
2857 | SetControlReference( m_sbVertical, (SInt32)this ); | |
5de694f0 | 2858 | SetControlAction( m_sbVertical, gTXNScrollActionProc ); |
c88b7d28 DS |
2859 | ShowControl( m_sbVertical ); |
2860 | EmbedControl( m_sbVertical , m_controlRef ); | |
2861 | frameOptions &= ~kTXNWantVScrollBarMask; | |
5de694f0 | 2862 | } |
fef981b4 | 2863 | |
5de694f0 SC |
2864 | if ( frameOptions & kTXNWantHScrollBarMask ) |
2865 | { | |
c88b7d28 DS |
2866 | CreateScrollBarControl( m_txnWindow, &sb, 0, 0, 100, 1, true, gTXNScrollActionProc, &m_sbHorizontal ); |
2867 | SetControlReference( m_sbHorizontal, (SInt32)this ); | |
5de694f0 | 2868 | SetControlAction( m_sbHorizontal, gTXNScrollActionProc ); |
c88b7d28 DS |
2869 | ShowControl( m_sbHorizontal ); |
2870 | EmbedControl( m_sbHorizontal, m_controlRef ); | |
5de694f0 SC |
2871 | frameOptions &= ~(kTXNWantHScrollBarMask | kTXNDrawGrowIconMask); |
2872 | } | |
4e477040 | 2873 | |
ffafe6ca DS |
2874 | err = TXNNewObject( |
2875 | NULL, m_txnWindow, &bounds, frameOptions, | |
2876 | kTXNTextEditStyleFrameType, kTXNTextensionFile, kTXNSystemDefaultEncoding, | |
2877 | &m_txn, &m_txnFrameID, NULL ); | |
2878 | verify_noerr( err ); | |
3dee36ae | 2879 | |
fef981b4 DS |
2880 | #if 0 |
2881 | TXNControlTag iControlTags[] = { kTXNUseCarbonEvents }; | |
c88b7d28 | 2882 | TXNControlData iControlData[] = { { (UInt32)&cInfo } }; |
fef981b4 DS |
2883 | int toptag = WXSIZEOF( iControlTags ) ; |
2884 | TXNCarbonEventInfo cInfo ; | |
55d0b180 SC |
2885 | cInfo.useCarbonEvents = false ; |
2886 | cInfo.filler = 0 ; | |
2887 | cInfo.flags = 0 ; | |
2888 | cInfo.fDictionary = NULL ; | |
2889 | ||
c88b7d28 | 2890 | verify_noerr( TXNSetTXNObjectControls( m_txn, false, toptag, iControlTags, iControlData ) ); |
fef981b4 | 2891 | #endif |
55d0b180 | 2892 | |
c88b7d28 | 2893 | TXNRegisterScrollInfoProc( m_txn, gTXNScrollInfoProc, (SInt32)this ); |
4e477040 | 2894 | |
0f7817ab | 2895 | SetGWorld( origPort , origDev ) ; |
ffafe6ca | 2896 | |
5ca0d812 | 2897 | return err; |
facd6764 | 2898 | } |
4f74e0d1 | 2899 | #endif |
facd6764 | 2900 | |
5ca0d812 SC |
2901 | // ---------------------------------------------------------------------------- |
2902 | // MLTE control implementation (OSX part) | |
2903 | // ---------------------------------------------------------------------------- | |
facd6764 | 2904 | |
09660720 | 2905 | // tiger multi-line textcontrols with no CR in the entire content |
9eddec69 | 2906 | // don't scroll automatically, so we need a hack. |
09660720 SC |
2907 | // This attempt only works 'before' the key (ie before CallNextEventHandler) |
2908 | // is processed, thus the scrolling always occurs one character too late, but | |
2909 | // better than nothing ... | |
2910 | ||
2911 | static const EventTypeSpec eventList[] = | |
2912 | { | |
2913 | { kEventClassTextInput, kEventTextInputUnicodeForKeyEvent } , | |
2914 | } ; | |
9eddec69 | 2915 | |
09660720 SC |
2916 | static pascal OSStatus wxMacUnicodeTextEventHandler( EventHandlerCallRef handler , EventRef event , void *data ) |
2917 | { | |
2918 | OSStatus result = eventNotHandledErr ; | |
2919 | wxMacMLTEHIViewControl* focus = (wxMacMLTEHIViewControl*) data ; | |
9eddec69 | 2920 | |
09660720 SC |
2921 | switch ( GetEventKind( event ) ) |
2922 | { | |
2923 | case kEventTextInputUnicodeForKeyEvent : | |
2924 | { | |
d8f3e9da SC |
2925 | TXNOffset from , to ; |
2926 | TXNGetSelection( focus->GetTXNObject() , &from , &to ) ; | |
2927 | if ( from == to ) | |
2928 | TXNShowSelection( focus->GetTXNObject() , kTXNShowStart ); | |
09660720 SC |
2929 | result = CallNextEventHandler(handler,event); |
2930 | break; | |
2931 | } | |
2932 | default: | |
2933 | break ; | |
2934 | } | |
9eddec69 | 2935 | |
09660720 SC |
2936 | return result ; |
2937 | } | |
2938 | ||
2939 | static pascal OSStatus wxMacTextControlEventHandler( EventHandlerCallRef handler , EventRef event , void *data ) | |
2940 | { | |
2941 | OSStatus result = eventNotHandledErr ; | |
9eddec69 | 2942 | |
09660720 SC |
2943 | switch ( GetEventClass( event ) ) |
2944 | { | |
2945 | case kEventClassTextInput : | |
2946 | result = wxMacUnicodeTextEventHandler( handler , event , data ) ; | |
2947 | break ; | |
9eddec69 | 2948 | |
09660720 SC |
2949 | default : |
2950 | break ; | |
2951 | } | |
2952 | return result ; | |
2953 | } | |
2954 | ||
2955 | DEFINE_ONE_SHOT_HANDLER_GETTER( wxMacTextControlEventHandler ) | |
2956 | ||
0f7817ab | 2957 | wxMacMLTEHIViewControl::wxMacMLTEHIViewControl( wxTextCtrl *wxPeer, |
ffafe6ca DS |
2958 | const wxString& str, |
2959 | const wxPoint& pos, | |
2960 | const wxSize& size, long style ) : wxMacMLTEControl( wxPeer ) | |
facd6764 | 2961 | { |
5ca0d812 SC |
2962 | m_font = wxPeer->GetFont() ; |
2963 | m_windowStyle = style ; | |
7d8268a1 | 2964 | Rect bounds = wxMacGetBoundsForControl( wxPeer , pos , size ) ; |
5ca0d812 | 2965 | wxString st = str ; |
395480fb | 2966 | wxMacConvertNewlines10To13( &st ) ; |
7d8268a1 | 2967 | |
ffafe6ca DS |
2968 | HIRect hr = { |
2969 | { bounds.left , bounds.top }, | |
2970 | { bounds.right - bounds.left, bounds.bottom - bounds.top } } ; | |
facd6764 | 2971 | |
5ca0d812 SC |
2972 | m_scrollView = NULL ; |
2973 | TXNFrameOptions frameOptions = FrameOptionsFromWXStyle( style ) ; | |
6cfe4844 | 2974 | if (( frameOptions & (kTXNWantVScrollBarMask | kTXNWantHScrollBarMask)) || !(frameOptions &kTXNSingleLineOnlyMask)) |
5ca0d812 | 2975 | { |
6cfe4844 SC |
2976 | if ( frameOptions & (kTXNWantVScrollBarMask | kTXNWantHScrollBarMask) ) |
2977 | { | |
2978 | HIScrollViewCreate( | |
2979 | (frameOptions & kTXNWantHScrollBarMask ? kHIScrollViewOptionsHorizScroll : 0) | |
2980 | | (frameOptions & kTXNWantVScrollBarMask ? kHIScrollViewOptionsVertScroll : 0) , | |
2981 | &m_scrollView ) ; | |
2982 | } | |
2983 | else | |
2984 | { | |
2985 | HIScrollViewCreate(kHIScrollViewOptionsVertScroll,&m_scrollView); | |
2986 | HIScrollViewSetScrollBarAutoHide(m_scrollView,true); | |
2987 | } | |
7d8268a1 WS |
2988 | |
2989 | HIViewSetFrame( m_scrollView, &hr ); | |
2990 | HIViewSetVisible( m_scrollView, true ); | |
5ca0d812 | 2991 | } |
7d8268a1 | 2992 | |
5ca0d812 SC |
2993 | m_textView = NULL ; |
2994 | HITextViewCreate( NULL , 0, frameOptions , &m_textView ) ; | |
0207e969 | 2995 | m_txn = HITextViewGetTXNObject( m_textView ) ; |
5ca0d812 SC |
2996 | HIViewSetVisible( m_textView , true ) ; |
2997 | if ( m_scrollView ) | |
2998 | { | |
2999 | HIViewAddSubview( m_scrollView , m_textView ) ; | |
3000 | m_controlRef = m_scrollView ; | |
0207e969 | 3001 | wxPeer->MacInstallEventHandler( (WXWidget) m_textView ) ; |
5ca0d812 SC |
3002 | } |
3003 | else | |
3004 | { | |
7d8268a1 | 3005 | HIViewSetFrame( m_textView, &hr ); |
5ca0d812 SC |
3006 | m_controlRef = m_textView ; |
3007 | } | |
7d8268a1 | 3008 | |
0f7817ab | 3009 | AdjustCreationAttributes( *wxWHITE , true ) ; |
4f74e0d1 | 3010 | #ifndef __LP64__ |
0f7817ab | 3011 | wxMacWindowClipper c( m_peer ) ; |
4f74e0d1 | 3012 | #endif |
5ca0d812 SC |
3013 | SetTXNData( st , kTXNStartOffset, kTXNEndOffset ) ; |
3014 | ||
fef981b4 DS |
3015 | TXNSetSelection( m_txn, 0, 0 ); |
3016 | TXNShowSelection( m_txn, kTXNShowStart ); | |
09660720 SC |
3017 | |
3018 | InstallControlEventHandler( m_textView , GetwxMacTextControlEventHandlerUPP(), | |
3019 | GetEventTypeCount(eventList), eventList, this, | |
6239ee05 | 3020 | NULL); |
09660720 SC |
3021 | } |
3022 | ||
3023 | wxMacMLTEHIViewControl::~wxMacMLTEHIViewControl() | |
3024 | { | |
facd6764 SC |
3025 | } |
3026 | ||
7d8268a1 | 3027 | OSStatus wxMacMLTEHIViewControl::SetFocus( ControlFocusPart focusPart ) |
facd6764 | 3028 | { |
fef981b4 | 3029 | return SetKeyboardFocus( GetControlOwner( m_textView ), m_textView, focusPart ) ; |
facd6764 SC |
3030 | } |
3031 | ||
7d8268a1 | 3032 | bool wxMacMLTEHIViewControl::HasFocus() const |
facd6764 | 3033 | { |
5ca0d812 | 3034 | ControlRef control ; |
6239ee05 SC |
3035 | if ( GetUserFocusWindow() == NULL ) |
3036 | return false; | |
31c1cbc7 | 3037 | |
5ca0d812 SC |
3038 | GetKeyboardFocus( GetUserFocusWindow() , &control ) ; |
3039 | return control == m_textView ; | |
facd6764 SC |
3040 | } |
3041 | ||
44aa865d SC |
3042 | void wxMacMLTEHIViewControl::SetBackground( const wxBrush &brush ) |
3043 | { | |
3044 | wxMacMLTEControl::SetBackground( brush ) ; | |
fef981b4 DS |
3045 | |
3046 | #if 0 | |
44aa865d SC |
3047 | CGColorSpaceRef rgbSpace = CGColorSpaceCreateDeviceRGB(); |
3048 | RGBColor col = MAC_WXCOLORREF(brush.GetColour().GetPixel()) ; | |
3049 | ||
3050 | float component[4] ; | |
3051 | component[0] = col.red / 65536.0 ; | |
3052 | component[1] = col.green / 65536.0 ; | |
3053 | component[2] = col.blue / 65536.0 ; | |
3054 | component[3] = 1.0 ; // alpha | |
0207e969 | 3055 | |
ffafe6ca DS |
3056 | CGColorRef color = CGColorCreate( rgbSpace , component ); |
3057 | HITextViewSetBackgroundColor( m_textView , color ); | |
44aa865d | 3058 | CGColorSpaceRelease( rgbSpace ); |
fef981b4 | 3059 | #endif |
44aa865d SC |
3060 | } |
3061 | ||
5ca0d812 | 3062 | #endif // wxUSE_TEXTCTRL |