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