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