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