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