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