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