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