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