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