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