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