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