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