1 /////////////////////////////////////////////////////////////////////////////
2 // Name: src/mac/carbon/textctrl.cpp
4 // Author: Stefan Csomor
5 // Modified by: Ryan Norton (MLTE GetLineLength and GetLineText)
8 // Copyright: (c) Stefan Csomor
9 // Licence: wxWindows licence
10 /////////////////////////////////////////////////////////////////////////////
12 #include "wx/wxprec.h"
16 #include "wx/textctrl.h"
23 #include "wx/button.h"
25 #include "wx/settings.h"
26 #include "wx/msgdlg.h"
27 #include "wx/toplevel.h"
31 #include <sys/types.h>
37 #if wxUSE_STD_IOSTREAM
45 #include "wx/filefn.h"
46 #include "wx/sysopt.h"
48 #if defined(__BORLANDC__) && !defined(__WIN32__)
50 #elif !defined(__MWERKS__) && !defined(__GNUWIN32) && !defined(__DARWIN__)
59 #include <MacTextEditor.h>
60 #include <ATSUnicode.h>
61 #include <TextCommon.h>
62 #include <TextEncodingConverter.h>
65 #include "wx/mac/uma.h"
68 // if this is set to 1 then under OSX 10.2 the 'classic' MLTE implementation will be used
69 // if set to 0 then the unicode textctrl will be used
70 #ifndef wxMAC_AWAYS_USE_MLTE
71 #define wxMAC_AWAYS_USE_MLTE 1
77 kTXNVisibilityTag
= 'visb' // set the visibility state of the object
86 virtual ~wxMacFunctor() {}
88 virtual void* operator()() = 0 ;
90 static void* CallBackProc( void *param
)
92 wxMacFunctor
* f
= (wxMacFunctor
*) param
;
93 void *result
= (*f
)() ;
98 template<typename classtype
, typename param1type
>
100 class wxMacObjectFunctor1
: public wxMacFunctor
102 typedef void (classtype::*function
)( param1type p1
) ;
103 typedef void (classtype::*ref_function
)( const param1type
& p1
) ;
105 wxMacObjectFunctor1( classtype
*obj
, function f
, param1type p1
) :
113 wxMacObjectFunctor1( classtype
*obj
, ref_function f
, param1type p1
) :
121 virtual ~wxMacObjectFunctor1() {}
123 virtual void* operator()()
125 (m_object
->*m_function
)( m_param1
) ;
130 classtype
* m_object
;
131 param1type m_param1
;
134 function m_function
;
135 ref_function m_refFunction
;
139 template<typename classtype
, typename param1type
>
140 void* wxMacMPRemoteCall( classtype
*object
, void (classtype::*function
)( param1type p1
) , param1type p1
)
142 wxMacObjectFunctor1
<classtype
, param1type
> params(object
, function
, p1
) ;
144 MPRemoteCall( wxMacFunctor::CallBackProc
, ¶ms
, kMPOwningProcessRemoteContext
) ;
148 template<typename classtype
, typename param1type
>
149 void* wxMacMPRemoteCall( classtype
*object
, void (classtype::*function
)( const param1type
& p1
) , param1type p1
)
151 wxMacObjectFunctor1
<classtype
,param1type
> params(object
, function
, p1
) ;
153 MPRemoteCall( wxMacFunctor::CallBackProc
, ¶ms
, kMPOwningProcessRemoteContext
) ;
157 template<typename classtype
, typename param1type
>
158 void* wxMacMPRemoteGUICall( classtype
*object
, void (classtype::*function
)( param1type p1
) , param1type p1
)
161 void *result
= wxMacMPRemoteCall( object
, function
, p1
) ;
166 template<typename classtype
, typename param1type
>
167 void* wxMacMPRemoteGUICall( classtype
*object
, void (classtype::*function
)( const param1type
& p1
) , param1type p1
)
170 void *result
= wxMacMPRemoteCall( object
, function
, p1
) ;
175 // common interface for all implementations
176 class wxMacTextControl
: public wxMacControl
179 wxMacTextControl( wxTextCtrl
*peer
) ;
180 virtual ~wxMacTextControl() ;
182 virtual wxString
GetStringValue() const = 0 ;
183 virtual void SetStringValue( const wxString
&val
) = 0 ;
184 virtual void SetSelection( long from
, long to
) = 0 ;
185 virtual void GetSelection( long* from
, long* to
) const = 0 ;
186 virtual void WriteText( const wxString
& str
) = 0 ;
188 virtual void SetStyle( long start
, long end
, const wxTextAttr
& style
) ;
189 virtual void Copy() ;
191 virtual void Paste() ;
192 virtual bool CanPaste() const ;
193 virtual void SetEditable( bool editable
) ;
194 virtual wxTextPos
GetLastPosition() const ;
195 virtual void Replace( long from
, long to
, const wxString
&str
) ;
196 virtual void Remove( long from
, long to
) ;
199 virtual bool HasOwnContextMenu() const
202 virtual bool SetupCursor( const wxPoint
& pt
)
205 virtual void Clear() ;
206 virtual bool CanUndo() const;
207 virtual void Undo() ;
208 virtual bool CanRedo() const;
209 virtual void Redo() ;
210 virtual int GetNumberOfLines() const ;
211 virtual long XYToPosition(long x
, long y
) const;
212 virtual bool PositionToXY(long pos
, long *x
, long *y
) const ;
213 virtual void ShowPosition(long WXUNUSED(pos
)) ;
214 virtual int GetLineLength(long lineNo
) const ;
215 virtual wxString
GetLineText(long lineNo
) const ;
217 #ifndef __WXMAC_OSX__
218 virtual void MacControlUserPaneDrawProc(wxInt16 part
) = 0 ;
219 virtual wxInt16
MacControlUserPaneHitTestProc(wxInt16 x
, wxInt16 y
) = 0 ;
220 virtual wxInt16
MacControlUserPaneTrackingProc(wxInt16 x
, wxInt16 y
, void* actionProc
) = 0 ;
221 virtual void MacControlUserPaneIdleProc() = 0 ;
222 virtual wxInt16
MacControlUserPaneKeyDownProc(wxInt16 keyCode
, wxInt16 charCode
, wxInt16 modifiers
) = 0 ;
223 virtual void MacControlUserPaneActivateProc(bool activating
) = 0 ;
224 virtual wxInt16
MacControlUserPaneFocusProc(wxInt16 action
) = 0 ;
225 virtual void MacControlUserPaneBackgroundProc(void* info
) = 0 ;
229 // common parts for implementations based on MLTE
231 class wxMacMLTEControl
: public wxMacTextControl
234 wxMacMLTEControl( wxTextCtrl
*peer
) ;
236 virtual wxString
GetStringValue() const ;
237 virtual void SetStringValue( const wxString
&str
) ;
239 static TXNFrameOptions
FrameOptionsFromWXStyle( long wxStyle
) ;
241 void AdjustCreationAttributes( const wxColour
& background
, bool visible
) ;
243 virtual void SetFont( const wxFont
& font
, const wxColour
& foreground
, long windowStyle
) ;
244 virtual void SetBackground( const wxBrush
&brush
) ;
245 virtual void SetStyle( long start
, long end
, const wxTextAttr
& style
) ;
246 virtual void Copy() ;
248 virtual void Paste() ;
249 virtual bool CanPaste() const ;
250 virtual void SetEditable( bool editable
) ;
251 virtual wxTextPos
GetLastPosition() const ;
252 virtual void Replace( long from
, long to
, const wxString
&str
) ;
253 virtual void Remove( long from
, long to
) ;
254 virtual void GetSelection( long* from
, long* to
) const ;
255 virtual void SetSelection( long from
, long to
) ;
257 virtual void WriteText( const wxString
& str
) ;
259 virtual bool HasOwnContextMenu() const
261 #if MAC_OS_X_VERSION_MAX_ALLOWED >= MAC_OS_X_VERSION_10_4
262 if ( UMAGetSystemVersion() >= 0x1040 )
264 TXNCommandEventSupportOptions options
;
265 TXNGetCommandEventSupport( m_txn
, & options
) ;
266 return options
& kTXNSupportEditCommandProcessing
;
273 virtual void Clear() ;
275 virtual bool CanUndo() const ;
276 virtual void Undo() ;
277 virtual bool CanRedo() const;
278 virtual void Redo() ;
279 virtual int GetNumberOfLines() const ;
280 virtual long XYToPosition(long x
, long y
) const ;
281 virtual bool PositionToXY(long pos
, long *x
, long *y
) const ;
282 virtual void ShowPosition( long pos
) ;
283 virtual int GetLineLength(long lineNo
) const ;
284 virtual wxString
GetLineText(long lineNo
) const ;
286 void SetTXNData( const wxString
& st
, TXNOffset start
, TXNOffset end
) ;
287 TXNObject
GetTXNObject() { return m_txn
; }
290 void TXNSetAttribute( const wxTextAttr
& style
, long from
, long to
) ;
295 #if TARGET_API_MAC_OSX
297 // implementation available under OSX
299 #if MAC_OS_X_VERSION_MAX_ALLOWED > MAC_OS_X_VERSION_10_2
301 class wxMacMLTEHIViewControl
: public wxMacMLTEControl
304 wxMacMLTEHIViewControl( wxTextCtrl
*wxPeer
,
307 const wxSize
& size
, long style
) ;
308 virtual ~wxMacMLTEHIViewControl() ;
310 virtual OSStatus
SetFocus( ControlFocusPart focusPart
) ;
311 virtual bool HasFocus() const ;
312 virtual void SetBackground( const wxBrush
&brush
) ;
315 HIViewRef m_scrollView
;
316 HIViewRef m_textView
;
317 EventHandlerRef m_textEventHandlerRef
;
322 class wxMacUnicodeTextControl
: public wxMacTextControl
325 wxMacUnicodeTextControl( wxTextCtrl
*wxPeer
,
328 const wxSize
& size
, long style
) ;
329 virtual ~wxMacUnicodeTextControl();
331 virtual void VisibilityChanged(bool shown
);
332 virtual wxString
GetStringValue() const ;
333 virtual void SetStringValue( const wxString
&str
) ;
336 virtual void Paste();
337 virtual bool CanPaste() const;
338 virtual void SetEditable(bool editable
) ;
339 virtual void GetSelection( long* from
, long* to
) const ;
340 virtual void SetSelection( long from
, long to
) ;
341 virtual void WriteText(const wxString
& str
) ;
344 // contains the tag for the content (is different for password and non-password controls)
347 // as the selection tag only works correctly when the control has the focus we have to mirror the
349 EventHandlerRef m_focusHandlerRef
;
351 ControlEditTextSelectionRec m_selection
;
356 // 'classic' MLTE implementation
358 class wxMacMLTEClassicControl
: public wxMacMLTEControl
361 wxMacMLTEClassicControl( wxTextCtrl
*wxPeer
,
364 const wxSize
& size
, long style
) ;
365 virtual ~wxMacMLTEClassicControl() ;
367 virtual void VisibilityChanged(bool shown
) ;
368 virtual void SuperChangedPosition() ;
370 virtual void MacControlUserPaneDrawProc(wxInt16 part
) ;
371 virtual wxInt16
MacControlUserPaneHitTestProc(wxInt16 x
, wxInt16 y
) ;
372 virtual wxInt16
MacControlUserPaneTrackingProc(wxInt16 x
, wxInt16 y
, void* actionProc
) ;
373 virtual void MacControlUserPaneIdleProc() ;
374 virtual wxInt16
MacControlUserPaneKeyDownProc(wxInt16 keyCode
, wxInt16 charCode
, wxInt16 modifiers
) ;
375 virtual void MacControlUserPaneActivateProc(bool activating
) ;
376 virtual wxInt16
MacControlUserPaneFocusProc(wxInt16 action
) ;
377 virtual void MacControlUserPaneBackgroundProc(void* info
) ;
379 virtual bool SetupCursor( const wxPoint
& WXUNUSED(pt
) )
381 MacControlUserPaneIdleProc();
385 virtual void SetRect( Rect
*r
) ;
390 void MacUpdatePosition() ;
391 void MacActivatePaneText(bool setActive
) ;
392 void MacFocusPaneText(bool setFocus
) ;
393 void MacSetObjectVisibility(bool vis
) ;
396 TXNFrameID m_txnFrameID
;
398 WindowRef m_txnWindow
;
399 // bounds of the control as we last did set the txn frames
400 Rect m_txnControlBounds
;
401 Rect m_txnVisBounds
;
404 static pascal void TXNScrollActionProc( ControlRef controlRef
, ControlPartCode partCode
) ;
405 static pascal void TXNScrollInfoProc(
406 SInt32 iValue
, SInt32 iMaximumValue
,
407 TXNScrollBarOrientation iScrollBarOrientation
, SInt32 iRefCon
) ;
409 ControlRef m_sbHorizontal
;
410 SInt32 m_lastHorizontalValue
;
411 ControlRef m_sbVertical
;
412 SInt32 m_lastVerticalValue
;
417 IMPLEMENT_DYNAMIC_CLASS(wxTextCtrl
, wxTextCtrlBase
)
419 BEGIN_EVENT_TABLE(wxTextCtrl
, wxTextCtrlBase
)
420 EVT_ERASE_BACKGROUND( wxTextCtrl::OnEraseBackground
)
421 EVT_DROP_FILES(wxTextCtrl::OnDropFiles
)
422 EVT_CHAR(wxTextCtrl::OnChar
)
423 EVT_MENU(wxID_CUT
, wxTextCtrl::OnCut
)
424 EVT_MENU(wxID_COPY
, wxTextCtrl::OnCopy
)
425 EVT_MENU(wxID_PASTE
, wxTextCtrl::OnPaste
)
426 EVT_MENU(wxID_UNDO
, wxTextCtrl::OnUndo
)
427 EVT_MENU(wxID_REDO
, wxTextCtrl::OnRedo
)
428 EVT_MENU(wxID_CLEAR
, wxTextCtrl::OnDelete
)
429 EVT_MENU(wxID_SELECTALL
, wxTextCtrl::OnSelectAll
)
431 EVT_CONTEXT_MENU(wxTextCtrl::OnContextMenu
)
433 EVT_UPDATE_UI(wxID_CUT
, wxTextCtrl::OnUpdateCut
)
434 EVT_UPDATE_UI(wxID_COPY
, wxTextCtrl::OnUpdateCopy
)
435 EVT_UPDATE_UI(wxID_PASTE
, wxTextCtrl::OnUpdatePaste
)
436 EVT_UPDATE_UI(wxID_UNDO
, wxTextCtrl::OnUpdateUndo
)
437 EVT_UPDATE_UI(wxID_REDO
, wxTextCtrl::OnUpdateRedo
)
438 EVT_UPDATE_UI(wxID_CLEAR
, wxTextCtrl::OnUpdateDelete
)
439 EVT_UPDATE_UI(wxID_SELECTALL
, wxTextCtrl::OnUpdateSelectAll
)
443 void wxTextCtrl::Init()
449 m_privateContextMenu
= NULL
;
450 m_triggerOnSetValue
= true ;
453 wxTextCtrl::~wxTextCtrl()
455 delete m_privateContextMenu
;
458 bool wxTextCtrl::Create( wxWindow
*parent
,
464 const wxValidator
& validator
,
465 const wxString
& name
)
467 m_macIsUserPane
= false ;
470 if ( ! (style
& wxNO_BORDER
) )
471 style
= (style
& ~wxBORDER_MASK
) | wxSUNKEN_BORDER
;
473 if ( !wxTextCtrlBase::Create( parent
, id
, pos
, size
, style
& ~(wxHSCROLL
| wxVSCROLL
), validator
, name
) )
476 if ( m_windowStyle
& wxTE_MULTILINE
)
478 // always turn on this style for multi-line controls
479 m_windowStyle
|= wxTE_PROCESS_ENTER
;
480 style
|= wxTE_PROCESS_ENTER
;
483 bool forceMLTE
= false ;
485 #if wxUSE_SYSTEM_OPTIONS
486 if (wxSystemOptions::HasOption( wxMAC_TEXTCONTROL_USE_MLTE
) && (wxSystemOptions::GetOptionInt( wxMAC_TEXTCONTROL_USE_MLTE
) == 1))
493 #if MAC_OS_X_VERSION_MAX_ALLOWED > MAC_OS_X_VERSION_10_2
494 if ( UMAGetSystemVersion() >= 0x1030 && !forceMLTE
)
496 if ( m_windowStyle
& wxTE_MULTILINE
)
497 m_peer
= new wxMacMLTEHIViewControl( this , str
, pos
, size
, style
) ;
503 if ( !(m_windowStyle
& wxTE_MULTILINE
) && !forceMLTE
)
504 m_peer
= new wxMacUnicodeTextControl( this , str
, pos
, size
, style
) ;
509 m_peer
= new wxMacMLTEClassicControl( this , str
, pos
, size
, style
) ;
511 MacPostControlCreate(pos
, size
) ;
513 // only now the embedding is correct and we can do a positioning update
515 MacSuperChangedPosition() ;
517 if ( m_windowStyle
& wxTE_READONLY
)
518 SetEditable( false ) ;
520 SetCursor( wxCursor( wxCURSOR_IBEAM
) ) ;
525 void wxTextCtrl::MacSuperChangedPosition()
527 wxWindow::MacSuperChangedPosition() ;
528 GetPeer()->SuperChangedPosition() ;
531 void wxTextCtrl::MacVisibilityChanged()
533 GetPeer()->VisibilityChanged( MacIsReallyShown() ) ;
536 void wxTextCtrl::MacEnabledStateChanged()
540 wxString
wxTextCtrl::GetValue() const
542 return GetPeer()->GetStringValue() ;
545 void wxTextCtrl::GetSelection(long* from
, long* to
) const
547 GetPeer()->GetSelection( from
, to
) ;
550 void wxTextCtrl::SetValue(const wxString
& str
)
553 if ( GetValue() == str
)
556 GetPeer()->SetStringValue( str
) ;
558 if ( m_triggerOnSetValue
)
560 wxCommandEvent
event( wxEVT_COMMAND_TEXT_UPDATED
, m_windowId
);
561 event
.SetString( GetValue() );
562 event
.SetEventObject( this );
563 GetEventHandler()->ProcessEvent( event
);
567 void wxTextCtrl::SetMaxLength(unsigned long len
)
572 bool wxTextCtrl::SetFont( const wxFont
& font
)
574 if ( !wxTextCtrlBase::SetFont( font
) )
577 GetPeer()->SetFont( font
, GetForegroundColour() , GetWindowStyle() ) ;
582 bool wxTextCtrl::SetStyle(long start
, long end
, const wxTextAttr
& style
)
584 GetPeer()->SetStyle( start
, end
, style
) ;
589 bool wxTextCtrl::SetDefaultStyle(const wxTextAttr
& style
)
591 wxTextCtrlBase::SetDefaultStyle( style
) ;
592 SetStyle( kTXNUseCurrentSelection
, kTXNUseCurrentSelection
, GetDefaultStyle() ) ;
597 // Clipboard operations
599 void wxTextCtrl::Copy()
605 void wxTextCtrl::Cut()
611 wxCommandEvent
event( wxEVT_COMMAND_TEXT_UPDATED
, m_windowId
);
612 event
.SetEventObject( this );
613 GetEventHandler()->ProcessEvent( event
);
617 void wxTextCtrl::Paste()
623 // TODO: eventually we should add setting the default style again
625 wxCommandEvent
event( wxEVT_COMMAND_TEXT_UPDATED
, m_windowId
);
626 event
.SetEventObject( this );
627 GetEventHandler()->ProcessEvent( event
);
631 bool wxTextCtrl::CanCopy() const
633 // Can copy if there's a selection
635 GetSelection( &from
, &to
);
640 bool wxTextCtrl::CanCut() const
645 // Can cut if there's a selection
647 GetSelection( &from
, &to
);
652 bool wxTextCtrl::CanPaste() const
657 return GetPeer()->CanPaste() ;
660 void wxTextCtrl::SetEditable(bool editable
)
662 if ( editable
!= m_editable
)
664 m_editable
= editable
;
665 GetPeer()->SetEditable( editable
) ;
669 void wxTextCtrl::SetInsertionPoint(long pos
)
671 SetSelection( pos
, pos
) ;
674 void wxTextCtrl::SetInsertionPointEnd()
676 wxTextPos pos
= GetLastPosition();
677 SetInsertionPoint( pos
);
680 long wxTextCtrl::GetInsertionPoint() const
683 GetSelection( &begin
, &end
) ;
688 wxTextPos
wxTextCtrl::GetLastPosition() const
690 return GetPeer()->GetLastPosition() ;
693 void wxTextCtrl::Replace(long from
, long to
, const wxString
& str
)
695 GetPeer()->Replace( from
, to
, str
) ;
698 void wxTextCtrl::Remove(long from
, long to
)
700 GetPeer()->Remove( from
, to
) ;
703 void wxTextCtrl::SetSelection(long from
, long to
)
705 GetPeer()->SetSelection( from
, to
) ;
708 bool wxTextCtrl::LoadFile(const wxString
& file
)
710 return wxTextCtrlBase::LoadFile( file
);
713 void wxTextCtrl::WriteText(const wxString
& str
)
715 // TODO: this MPRemoting will be moved into a remoting peer proxy for any command
716 if ( !wxIsMainThread() )
718 // unfortunately CW 8 is not able to correctly deduce the template types,
719 // so we have to instantiate explicitly
720 wxMacMPRemoteGUICall
<wxTextCtrl
,wxString
>( this , &wxTextCtrl::WriteText
, str
) ;
725 GetPeer()->WriteText( str
) ;
728 void wxTextCtrl::AppendText(const wxString
& text
)
730 SetInsertionPointEnd();
734 void wxTextCtrl::Clear()
739 bool wxTextCtrl::IsModified() const
744 bool wxTextCtrl::IsEditable() const
746 return IsEnabled() && m_editable
;
749 bool wxTextCtrl::AcceptsFocus() const
751 // we don't want focus if we can't be edited
752 return /*IsEditable() && */ wxControl::AcceptsFocus();
755 wxSize
wxTextCtrl::DoGetBestSize() const
759 // these are the numbers from the HIG:
760 // we reduce them by the borders first
763 switch ( m_windowVariant
)
765 case wxWINDOW_VARIANT_NORMAL
:
769 case wxWINDOW_VARIANT_SMALL
:
773 case wxWINDOW_VARIANT_MINI
:
782 // as the above numbers have some free space around the text
783 // we get 5 lines like this anyway
784 if ( m_windowStyle
& wxTE_MULTILINE
)
787 if ( !HasFlag(wxNO_BORDER
) )
790 return wxSize(wText
, hText
);
793 // ----------------------------------------------------------------------------
795 // ----------------------------------------------------------------------------
797 void wxTextCtrl::Undo()
803 void wxTextCtrl::Redo()
809 bool wxTextCtrl::CanUndo() const
814 return GetPeer()->CanUndo() ;
817 bool wxTextCtrl::CanRedo() const
822 return GetPeer()->CanRedo() ;
825 void wxTextCtrl::MarkDirty()
830 void wxTextCtrl::DiscardEdits()
835 int wxTextCtrl::GetNumberOfLines() const
837 return GetPeer()->GetNumberOfLines() ;
840 long wxTextCtrl::XYToPosition(long x
, long y
) const
842 return GetPeer()->XYToPosition( x
, y
) ;
845 bool wxTextCtrl::PositionToXY(long pos
, long *x
, long *y
) const
847 return GetPeer()->PositionToXY( pos
, x
, y
) ;
850 void wxTextCtrl::ShowPosition(long pos
)
852 return GetPeer()->ShowPosition(pos
) ;
855 int wxTextCtrl::GetLineLength(long lineNo
) const
857 return GetPeer()->GetLineLength(lineNo
) ;
860 wxString
wxTextCtrl::GetLineText(long lineNo
) const
862 return GetPeer()->GetLineText(lineNo
) ;
865 void wxTextCtrl::Command(wxCommandEvent
& event
)
867 SetValue(event
.GetString());
868 ProcessCommand(event
);
871 void wxTextCtrl::OnDropFiles(wxDropFilesEvent
& event
)
873 // By default, load the first file into the text window.
874 if (event
.GetNumberOfFiles() > 0)
875 LoadFile( event
.GetFiles()[0] );
878 void wxTextCtrl::OnEraseBackground(wxEraseEvent
& event
)
880 // all erasing should be done by the real mac control implementation
881 // while this is true for MLTE under classic, the HITextView is somehow
882 // transparent but background erase is not working correctly, so intercept
883 // things while we can...
887 void wxTextCtrl::OnChar(wxKeyEvent
& event
)
889 int key
= event
.GetKeyCode() ;
890 bool eat_key
= false ;
892 if ( key
== 'a' && event
.MetaDown() )
899 if ( key
== 'c' && event
.MetaDown() )
907 if ( !IsEditable() && key
!= WXK_LEFT
&& key
!= WXK_RIGHT
&& key
!= WXK_DOWN
&& key
!= WXK_UP
&& key
!= WXK_TAB
&&
908 !( key
== WXK_RETURN
&& ( (m_windowStyle
& wxTE_PROCESS_ENTER
) || (m_windowStyle
& wxTE_MULTILINE
) ) )
909 // && key != WXK_PAGEUP && key != WXK_PAGEDOWN && key != WXK_HOME && key != WXK_END
916 // Check if we have reached the max # of chars (if it is set), but still
917 // allow navigation and deletion
918 if ( !IsMultiLine() && m_maxLength
&& GetValue().length() >= m_maxLength
&&
919 key
!= WXK_LEFT
&& key
!= WXK_RIGHT
&& key
!= WXK_TAB
&&
920 key
!= WXK_BACK
&& !( key
== WXK_RETURN
&& (m_windowStyle
& wxTE_PROCESS_ENTER
) )
923 // eat it, we don't want to add more than allowed # of characters
925 // TODO: generate EVT_TEXT_MAXLEN()
929 // assume that any key not processed yet is going to modify the control
932 if ( key
== 'v' && event
.MetaDown() )
940 if ( key
== 'x' && event
.MetaDown() )
951 if (m_windowStyle
& wxTE_PROCESS_ENTER
)
953 wxCommandEvent
event(wxEVT_COMMAND_TEXT_ENTER
, m_windowId
);
954 event
.SetEventObject( this );
955 event
.SetString( GetValue() );
956 if ( GetEventHandler()->ProcessEvent(event
) )
960 if ( !(m_windowStyle
& wxTE_MULTILINE
) )
962 wxTopLevelWindow
*tlw
= wxDynamicCast(wxGetTopLevelParent(this), wxTopLevelWindow
);
963 if ( tlw
&& tlw
->GetDefaultItem() )
965 wxButton
*def
= wxDynamicCast(tlw
->GetDefaultItem(), wxButton
);
966 if ( def
&& def
->IsEnabled() )
968 wxCommandEvent
event(wxEVT_COMMAND_BUTTON_CLICKED
, def
->GetId() );
969 event
.SetEventObject(def
);
976 // this will make wxWidgets eat the ENTER key so that
977 // we actually prevent line wrapping in a single line text control
983 if ( !(m_windowStyle
& wxTE_PROCESS_TAB
))
986 if (!event
.ShiftDown())
987 flags
|= wxNavigationKeyEvent::IsForward
;
988 if (event
.ControlDown())
989 flags
|= wxNavigationKeyEvent::WinChange
;
996 // This is necessary (don't know why);
997 // otherwise the tab will not be inserted.
998 WriteText(wxT("\t"));
1009 // perform keystroke handling
1013 if ( ( key
>= 0x20 && key
< WXK_START
) ||
1014 ( key
>= WXK_NUMPAD0
&& key
<= WXK_DIVIDE
) ||
1015 key
== WXK_RETURN
||
1016 key
== WXK_DELETE
||
1019 wxCommandEvent
event1(wxEVT_COMMAND_TEXT_UPDATED
, m_windowId
);
1020 event1
.SetEventObject( this );
1021 wxPostEvent( GetEventHandler(), event1
);
1025 // ----------------------------------------------------------------------------
1026 // standard handlers for standard edit menu events
1027 // ----------------------------------------------------------------------------
1029 void wxTextCtrl::OnCut(wxCommandEvent
& WXUNUSED(event
))
1034 void wxTextCtrl::OnCopy(wxCommandEvent
& WXUNUSED(event
))
1039 void wxTextCtrl::OnPaste(wxCommandEvent
& WXUNUSED(event
))
1044 void wxTextCtrl::OnUndo(wxCommandEvent
& WXUNUSED(event
))
1049 void wxTextCtrl::OnRedo(wxCommandEvent
& WXUNUSED(event
))
1054 void wxTextCtrl::OnDelete(wxCommandEvent
& WXUNUSED(event
))
1058 GetSelection( &from
, &to
);
1059 if (from
!= -1 && to
!= -1)
1063 void wxTextCtrl::OnSelectAll(wxCommandEvent
& WXUNUSED(event
))
1065 SetSelection(-1, -1);
1068 void wxTextCtrl::OnUpdateCut(wxUpdateUIEvent
& event
)
1070 event
.Enable( CanCut() );
1073 void wxTextCtrl::OnUpdateCopy(wxUpdateUIEvent
& event
)
1075 event
.Enable( CanCopy() );
1078 void wxTextCtrl::OnUpdatePaste(wxUpdateUIEvent
& event
)
1080 event
.Enable( CanPaste() );
1083 void wxTextCtrl::OnUpdateUndo(wxUpdateUIEvent
& event
)
1085 event
.Enable( CanUndo() );
1088 void wxTextCtrl::OnUpdateRedo(wxUpdateUIEvent
& event
)
1090 event
.Enable( CanRedo() );
1093 void wxTextCtrl::OnUpdateDelete(wxUpdateUIEvent
& event
)
1097 GetSelection( &from
, &to
);
1098 event
.Enable( from
!= -1 && to
!= -1 && from
!= to
&& IsEditable() ) ;
1101 void wxTextCtrl::OnUpdateSelectAll(wxUpdateUIEvent
& event
)
1103 event
.Enable(GetLastPosition() > 0);
1106 // CS: Context Menus only work with MLTE implementations or non-multiline HIViews at the moment
1108 void wxTextCtrl::OnContextMenu(wxContextMenuEvent
& event
)
1110 if ( GetPeer()->HasOwnContextMenu() )
1116 if (m_privateContextMenu
== NULL
)
1118 m_privateContextMenu
= new wxMenu
;
1119 m_privateContextMenu
->Append(wxID_UNDO
, _("&Undo"));
1120 m_privateContextMenu
->Append(wxID_REDO
, _("&Redo"));
1121 m_privateContextMenu
->AppendSeparator();
1122 m_privateContextMenu
->Append(wxID_CUT
, _("Cu&t"));
1123 m_privateContextMenu
->Append(wxID_COPY
, _("&Copy"));
1124 m_privateContextMenu
->Append(wxID_PASTE
, _("&Paste"));
1125 m_privateContextMenu
->Append(wxID_CLEAR
, _("&Delete"));
1126 m_privateContextMenu
->AppendSeparator();
1127 m_privateContextMenu
->Append(wxID_SELECTALL
, _("Select &All"));
1130 if (m_privateContextMenu
!= NULL
)
1131 PopupMenu(m_privateContextMenu
);
1134 bool wxTextCtrl::MacSetupCursor( const wxPoint
& pt
)
1136 if ( !GetPeer()->SetupCursor( pt
) )
1137 return wxWindow::MacSetupCursor( pt
) ;
1142 #if !TARGET_API_MAC_OSX
1144 // user pane implementation
1146 void wxTextCtrl::MacControlUserPaneDrawProc(wxInt16 part
)
1148 GetPeer()->MacControlUserPaneDrawProc( part
) ;
1151 wxInt16
wxTextCtrl::MacControlUserPaneHitTestProc(wxInt16 x
, wxInt16 y
)
1153 return GetPeer()->MacControlUserPaneHitTestProc( x
, y
) ;
1156 wxInt16
wxTextCtrl::MacControlUserPaneTrackingProc(wxInt16 x
, wxInt16 y
, void* actionProc
)
1158 return GetPeer()->MacControlUserPaneTrackingProc( x
, y
, actionProc
) ;
1161 void wxTextCtrl::MacControlUserPaneIdleProc()
1163 GetPeer()->MacControlUserPaneIdleProc( ) ;
1166 wxInt16
wxTextCtrl::MacControlUserPaneKeyDownProc(wxInt16 keyCode
, wxInt16 charCode
, wxInt16 modifiers
)
1168 return GetPeer()->MacControlUserPaneKeyDownProc( keyCode
, charCode
, modifiers
) ;
1171 void wxTextCtrl::MacControlUserPaneActivateProc(bool activating
)
1173 GetPeer()->MacControlUserPaneActivateProc( activating
) ;
1176 wxInt16
wxTextCtrl::MacControlUserPaneFocusProc(wxInt16 action
)
1178 return GetPeer()->MacControlUserPaneFocusProc( action
) ;
1181 void wxTextCtrl::MacControlUserPaneBackgroundProc(void* info
)
1183 GetPeer()->MacControlUserPaneBackgroundProc( info
) ;
1188 // ----------------------------------------------------------------------------
1189 // implementation base class
1190 // ----------------------------------------------------------------------------
1192 wxMacTextControl::wxMacTextControl(wxTextCtrl
* peer
) :
1193 wxMacControl( peer
)
1197 wxMacTextControl::~wxMacTextControl()
1201 void wxMacTextControl::SetStyle(long start
, long end
, const wxTextAttr
& style
)
1205 void wxMacTextControl::Copy()
1209 void wxMacTextControl::Cut()
1213 void wxMacTextControl::Paste()
1217 bool wxMacTextControl::CanPaste() const
1222 void wxMacTextControl::SetEditable(bool editable
)
1226 wxTextPos
wxMacTextControl::GetLastPosition() const
1228 return GetStringValue().length() ;
1231 void wxMacTextControl::Replace( long from
, long to
, const wxString
&val
)
1233 SetSelection( from
, to
) ;
1237 void wxMacTextControl::Remove( long from
, long to
)
1239 SetSelection( from
, to
) ;
1240 WriteText( wxEmptyString
) ;
1243 void wxMacTextControl::Clear()
1245 SetStringValue( wxEmptyString
) ;
1248 bool wxMacTextControl::CanUndo() const
1253 void wxMacTextControl::Undo()
1257 bool wxMacTextControl::CanRedo() const
1262 void wxMacTextControl::Redo()
1266 long wxMacTextControl::XYToPosition(long x
, long y
) const
1271 bool wxMacTextControl::PositionToXY(long pos
, long *x
, long *y
) const
1276 void wxMacTextControl::ShowPosition( long WXUNUSED(pos
) )
1280 int wxMacTextControl::GetNumberOfLines() const
1282 ItemCount lines
= 0 ;
1283 wxString content
= GetStringValue() ;
1286 for (size_t i
= 0; i
< content
.length() ; i
++)
1288 if (content
[i
] == '\r')
1295 wxString
wxMacTextControl::GetLineText(long lineNo
) const
1297 // TODO: change this if possible to reflect real lines
1298 wxString content
= GetStringValue() ;
1302 for (size_t i
= 0; i
< content
.length() ; i
++)
1304 if (count
== lineNo
)
1306 // Add chars in line then
1309 for (size_t j
= i
; j
< content
.length(); j
++)
1311 if (content
[j
] == '\n')
1320 if (content
[i
] == '\n')
1324 return wxEmptyString
;
1327 int wxMacTextControl::GetLineLength(long lineNo
) const
1329 // TODO: change this if possible to reflect real lines
1330 wxString content
= GetStringValue() ;
1334 for (size_t i
= 0; i
< content
.length() ; i
++)
1336 if (count
== lineNo
)
1338 // Count chars in line then
1340 for (size_t j
= i
; j
< content
.length(); j
++)
1343 if (content
[j
] == '\n')
1350 if (content
[i
] == '\n')
1357 // ----------------------------------------------------------------------------
1358 // standard unicode control implementation
1359 // ----------------------------------------------------------------------------
1361 #if TARGET_API_MAC_OSX
1363 // the current unicode textcontrol implementation has a bug : only if the control
1364 // is currently having the focus, the selection can be retrieved by the corresponding
1365 // data tag. So we have a mirroring using a member variable
1366 // TODO : build event table using virtual member functions for wxMacControl
1368 static const EventTypeSpec unicodeTextControlEventList
[] =
1370 { kEventClassControl
, kEventControlSetFocusPart
} ,
1373 static pascal OSStatus
wxMacUnicodeTextControlControlEventHandler( EventHandlerCallRef handler
, EventRef event
, void *data
)
1375 OSStatus result
= eventNotHandledErr
;
1376 wxMacUnicodeTextControl
* focus
= (wxMacUnicodeTextControl
*) data
;
1377 wxMacCarbonEvent
cEvent( event
) ;
1379 switch ( GetEventKind( event
) )
1381 case kEventControlSetFocusPart
:
1383 ControlPartCode controlPart
= cEvent
.GetParameter
<ControlPartCode
>(kEventParamControlPart
, typeControlPartCode
);
1384 if ( controlPart
== kControlFocusNoPart
)
1386 // about to loose focus -> store selection to field
1387 focus
->GetData
<ControlEditTextSelectionRec
>( 0, kControlEditTextSelectionTag
, &focus
->m_selection
);
1389 result
= CallNextEventHandler(handler
,event
) ;
1390 if ( controlPart
!= kControlFocusNoPart
)
1392 // about to gain focus -> set selection from field
1393 focus
->SetData
<ControlEditTextSelectionRec
>( 0, kControlEditTextSelectionTag
, &focus
->m_selection
);
1404 static pascal OSStatus
wxMacUnicodeTextControlEventHandler( EventHandlerCallRef handler
, EventRef event
, void *data
)
1406 OSStatus result
= eventNotHandledErr
;
1408 switch ( GetEventClass( event
) )
1410 case kEventClassControl
:
1411 result
= wxMacUnicodeTextControlControlEventHandler( handler
, event
, data
) ;
1420 DEFINE_ONE_SHOT_HANDLER_GETTER( wxMacUnicodeTextControlEventHandler
)
1422 wxMacUnicodeTextControl::wxMacUnicodeTextControl( wxTextCtrl
*wxPeer
,
1423 const wxString
& str
,
1425 const wxSize
& size
, long style
)
1426 : wxMacTextControl( wxPeer
)
1428 m_font
= wxPeer
->GetFont() ;
1429 m_windowStyle
= style
;
1430 Rect bounds
= wxMacGetBoundsForControl( wxPeer
, pos
, size
) ;
1432 wxMacConvertNewlines10To13( &st
) ;
1433 wxMacCFStringHolder
cf(st
, m_font
.GetEncoding()) ;
1434 CFStringRef cfr
= cf
;
1435 Boolean isPassword
= ( m_windowStyle
& wxTE_PASSWORD
) != 0 ;
1436 m_valueTag
= isPassword
? kControlEditTextPasswordCFStringTag
: kControlEditTextCFStringTag
;
1438 OSStatus err
= CreateEditUnicodeTextControl(
1439 MAC_WXHWND(wxPeer
->MacGetTopLevelWindowRef()), &bounds
, cfr
,
1440 isPassword
, NULL
, &m_controlRef
) ;
1441 verify_noerr( err
);
1443 if ( !(m_windowStyle
& wxTE_MULTILINE
) )
1444 SetData
<Boolean
>( kControlEditTextPart
, kControlEditTextSingleLineTag
, true ) ;
1446 InstallControlEventHandler( m_controlRef
, GetwxMacUnicodeTextControlEventHandlerUPP(),
1447 GetEventTypeCount(unicodeTextControlEventList
), unicodeTextControlEventList
, this,
1448 &m_focusHandlerRef
);
1451 wxMacUnicodeTextControl::~wxMacUnicodeTextControl()
1453 ::RemoveEventHandler( m_focusHandlerRef
);
1456 void wxMacUnicodeTextControl::VisibilityChanged(bool shown
)
1458 if ( !(m_windowStyle
& wxTE_MULTILINE
) && shown
)
1460 // work around a refresh issue insofar as not always the entire content is shown,
1461 // even if this would be possible
1462 ControlEditTextSelectionRec sel
;
1463 CFStringRef value
= NULL
;
1465 verify_noerr( GetData
<ControlEditTextSelectionRec
>( 0, kControlEditTextSelectionTag
, &sel
) );
1466 verify_noerr( GetData
<CFStringRef
>( 0, m_valueTag
, &value
) );
1467 verify_noerr( SetData
<CFStringRef
>( 0, m_valueTag
, &value
) );
1468 verify_noerr( SetData
<ControlEditTextSelectionRec
>( 0, kControlEditTextSelectionTag
, &sel
) );
1470 CFRelease( value
) ;
1474 wxString
wxMacUnicodeTextControl::GetStringValue() const
1477 CFStringRef value
= GetData
<CFStringRef
>(0, m_valueTag
) ;
1480 wxMacCFStringHolder
cf(value
) ;
1481 result
= cf
.AsString() ;
1485 wxMacConvertNewlines13To10( &result
) ;
1487 wxMacConvertNewlines10To13( &result
) ;
1493 void wxMacUnicodeTextControl::SetStringValue( const wxString
&str
)
1496 wxMacConvertNewlines10To13( &st
) ;
1497 wxMacCFStringHolder
cf( st
, m_font
.GetEncoding() ) ;
1498 verify_noerr( SetData
<CFStringRef
>( 0, m_valueTag
, cf
) ) ;
1501 void wxMacUnicodeTextControl::Copy()
1503 SendHICommand( kHICommandCopy
) ;
1506 void wxMacUnicodeTextControl::Cut()
1508 SendHICommand( kHICommandCut
) ;
1511 void wxMacUnicodeTextControl::Paste()
1513 SendHICommand( kHICommandPaste
) ;
1516 bool wxMacUnicodeTextControl::CanPaste() const
1521 void wxMacUnicodeTextControl::SetEditable(bool editable
)
1523 #if 0 // leads to problem because text cannot be selected anymore
1524 SetData
<Boolean
>( kControlEditTextPart
, kControlEditTextLockedTag
, (Boolean
) !editable
) ;
1528 void wxMacUnicodeTextControl::GetSelection( long* from
, long* to
) const
1530 ControlEditTextSelectionRec sel
;
1532 verify_noerr( GetData
<ControlEditTextSelectionRec
>( 0, kControlEditTextSelectionTag
, &sel
) ) ;
1537 *from
= sel
.selStart
;
1542 void wxMacUnicodeTextControl::SetSelection( long from
, long to
)
1544 ControlEditTextSelectionRec sel
;
1546 int textLength
= 0 ;
1547 CFStringRef value
= GetData
<CFStringRef
>(0, m_valueTag
) ;
1550 wxMacCFStringHolder
cf(value
) ;
1551 textLength
= cf
.AsString().length() ;
1554 if ((from
== -1) && (to
== -1))
1561 from
= wxMin(textLength
,wxMax(from
,0)) ;
1562 to
= wxMax(0,wxMin(textLength
,to
)) ;
1565 sel
.selStart
= from
;
1568 SetData
<ControlEditTextSelectionRec
>( 0, kControlEditTextSelectionTag
, &sel
) ;
1573 void wxMacUnicodeTextControl::WriteText( const wxString
& str
)
1576 wxMacConvertNewlines10To13( &st
) ;
1578 #if MAC_OS_X_VERSION_MAX_ALLOWED > MAC_OS_X_VERSION_10_2
1581 wxMacCFStringHolder
cf(st
, m_font
.GetEncoding() ) ;
1582 CFStringRef value
= cf
;
1583 SetData
<CFStringRef
>( 0, kControlEditTextInsertCFStringRefTag
, &value
);
1588 wxString val
= GetStringValue() ;
1590 GetSelection( &start
, &end
) ;
1591 val
.Remove( start
, end
- start
) ;
1592 val
.insert( start
, str
) ;
1593 SetStringValue( val
) ;
1594 SetSelection( start
+ str
.length() , start
+ str
.length() ) ;
1600 // ----------------------------------------------------------------------------
1601 // MLTE control implementation (common part)
1602 // ----------------------------------------------------------------------------
1604 // if MTLE is read only, no changes at all are allowed, not even from
1605 // procedural API, in order to allow changes via API all the same we must undo
1606 // the readonly status while we are executing, this class helps to do so
1608 class wxMacEditHelper
1611 wxMacEditHelper( TXNObject txn
)
1613 TXNControlTag tag
[] = { kTXNIOPrivilegesTag
} ;
1615 TXNGetTXNObjectControls( m_txn
, 1 , tag
, m_data
) ;
1616 if ( m_data
[0].uValue
== kTXNReadOnly
)
1618 TXNControlData data
[] = { { kTXNReadWrite
} } ;
1619 TXNSetTXNObjectControls( m_txn
, false , 1 , tag
, data
) ;
1625 TXNControlTag tag
[] = { kTXNIOPrivilegesTag
} ;
1626 if ( m_data
[0].uValue
== kTXNReadOnly
)
1627 TXNSetTXNObjectControls( m_txn
, false , 1 , tag
, m_data
) ;
1632 TXNControlData m_data
[1] ;
1635 wxMacMLTEControl::wxMacMLTEControl( wxTextCtrl
*peer
)
1636 : wxMacTextControl( peer
)
1638 SetNeedsFocusRect( true ) ;
1641 wxString
wxMacMLTEControl::GetStringValue() const
1645 Size actualSize
= 0;
1650 err
= TXNGetDataEncoded( m_txn
, kTXNStartOffset
, kTXNEndOffset
, &theText
, kTXNUnicodeTextData
);
1659 actualSize
= GetHandleSize( theText
) / sizeof(UniChar
) ;
1660 if ( actualSize
> 0 )
1662 wxChar
*ptr
= NULL
;
1664 #if SIZEOF_WCHAR_T == 2
1665 ptr
= new wxChar
[actualSize
+ 1] ;
1666 wxStrncpy( ptr
, (wxChar
*)(*theText
) , actualSize
) ;
1668 SetHandleSize( theText
, (actualSize
+ 1) * sizeof(UniChar
) ) ;
1670 (((UniChar
*)*theText
)[actualSize
]) = 0 ;
1671 wxMBConvUTF16 converter
;
1672 size_t noChars
= converter
.MB2WC( NULL
, (const char*)*theText
, 0 ) ;
1673 wxASSERT_MSG( noChars
!= wxCONV_FAILED
, _T("Unable to count the number of characters in this string!") );
1674 ptr
= new wxChar
[noChars
+ 1] ;
1676 noChars
= converter
.MB2WC( ptr
, (const char*)*theText
, noChars
+ 1 ) ;
1677 wxASSERT_MSG( noChars
!= wxCONV_FAILED
, _T("Conversion of string failed!") );
1679 HUnlock( theText
) ;
1682 ptr
[actualSize
] = 0 ;
1683 result
= wxString( ptr
) ;
1687 DisposeHandle( theText
) ;
1691 err
= TXNGetDataEncoded( m_txn
, kTXNStartOffset
, kTXNEndOffset
, &theText
, kTXNTextData
);
1700 actualSize
= GetHandleSize( theText
) ;
1701 if ( actualSize
> 0 )
1704 result
= wxString( *theText
, wxConvLocal
, actualSize
) ;
1705 HUnlock( theText
) ;
1708 DisposeHandle( theText
) ;
1714 wxMacConvertNewlines13To10( &result
) ;
1716 wxMacConvertNewlines10To13( &result
) ;
1722 void wxMacMLTEControl::SetStringValue( const wxString
&str
)
1725 wxMacConvertNewlines10To13( &st
);
1728 wxMacWindowClipper
c( m_peer
);
1731 wxMacEditHelper
help( m_txn
);
1732 SetTXNData( st
, kTXNStartOffset
, kTXNEndOffset
);
1735 TXNSetSelection( m_txn
, 0, 0 );
1736 TXNShowSelection( m_txn
, kTXNShowStart
);
1740 TXNFrameOptions
wxMacMLTEControl::FrameOptionsFromWXStyle( long wxStyle
)
1742 TXNFrameOptions frameOptions
= kTXNDontDrawCaretWhenInactiveMask
;
1744 #if MAC_OS_X_VERSION_MAX_ALLOWED >= MAC_OS_X_VERSION_10_3
1745 frameOptions
|= kTXNDoFontSubstitutionMask
;
1748 if ( ! (wxStyle
& wxTE_NOHIDESEL
) )
1749 frameOptions
|= kTXNDontDrawSelectionWhenInactiveMask
;
1751 if ( wxStyle
& (wxHSCROLL
| wxTE_DONTWRAP
) )
1752 frameOptions
|= kTXNWantHScrollBarMask
;
1754 if ( wxStyle
& wxTE_MULTILINE
)
1756 frameOptions
|= kTXNAlwaysWrapAtViewEdgeMask
;
1758 if ( !(wxStyle
& wxTE_NO_VSCROLL
) )
1760 frameOptions
|= kTXNWantVScrollBarMask
;
1762 // The following code causes drawing problems on 10.4. Perhaps it can be restored for
1763 // older versions of the OS, but I'm not sure it's appropriate to put a grow icon here
1764 // anyways, as AFAIK users can't actually use it to resize the text ctrl.
1765 // if ( frameOptions & kTXNWantHScrollBarMask )
1766 // frameOptions |= kTXNDrawGrowIconMask ;
1771 frameOptions
|= kTXNSingleLineOnlyMask
;
1774 return frameOptions
;
1777 void wxMacMLTEControl::AdjustCreationAttributes( const wxColour
&background
, bool visible
)
1779 TXNControlTag iControlTags
[] =
1781 kTXNDoFontSubstitution
,
1782 kTXNWordWrapStateTag
,
1784 TXNControlData iControlData
[] =
1790 int toptag
= WXSIZEOF( iControlTags
) ;
1792 if ( m_windowStyle
& wxTE_MULTILINE
)
1794 iControlData
[1].uValue
=
1795 (m_windowStyle
& wxTE_DONTWRAP
)
1800 OSStatus err
= TXNSetTXNObjectControls( m_txn
, false, toptag
, iControlTags
, iControlData
) ;
1801 verify_noerr( err
);
1803 // setting the default font:
1804 // under 10.2 this causes a visible caret, therefore we avoid it
1806 if ( UMAGetSystemVersion() >= 0x1030 )
1812 GetThemeFont( kThemeSystemFont
, GetApplicationScript() , fontName
, &fontSize
, &fontStyle
) ;
1814 TXNTypeAttributes typeAttr
[] =
1816 { kTXNQDFontNameAttribute
, kTXNQDFontNameAttributeSize
, { (void*) fontName
} } ,
1817 { kTXNQDFontSizeAttribute
, kTXNFontSizeAttributeSize
, { (void*) (fontSize
<< 16) } } ,
1818 { kTXNQDFontStyleAttribute
, kTXNQDFontStyleAttributeSize
, { (void*) normal
} } ,
1821 err
= TXNSetTypeAttributes(
1822 m_txn
, sizeof(typeAttr
) / sizeof(TXNTypeAttributes
),
1823 typeAttr
, kTXNStartOffset
, kTXNEndOffset
);
1824 verify_noerr( err
);
1827 if ( m_windowStyle
& wxTE_PASSWORD
)
1829 UniChar c
= 0x00A5 ;
1830 err
= TXNEchoMode( m_txn
, c
, 0 , true );
1831 verify_noerr( err
);
1834 TXNBackground tback
;
1835 tback
.bgType
= kTXNBackgroundTypeRGB
;
1836 tback
.bg
.color
= MAC_WXCOLORREF( background
.GetPixel() );
1837 TXNSetBackground( m_txn
, &tback
);
1839 #if MAC_OS_X_VERSION_MAX_ALLOWED >= MAC_OS_X_VERSION_10_4
1840 if ( UMAGetSystemVersion() >= 0x1040 )
1842 TXNCommandEventSupportOptions options
;
1843 if ( TXNGetCommandEventSupport( m_txn
, &options
) == noErr
)
1846 kTXNSupportEditCommandProcessing
1847 | kTXNSupportEditCommandUpdating
1848 | kTXNSupportSpellCheckCommandProcessing
1849 | kTXNSupportSpellCheckCommandUpdating
1850 | kTXNSupportFontCommandProcessing
1851 | kTXNSupportFontCommandUpdating
;
1853 TXNSetCommandEventSupport( m_txn
, options
) ;
1859 void wxMacMLTEControl::SetBackground( const wxBrush
&brush
)
1861 // currently only solid background are supported
1862 TXNBackground tback
;
1864 tback
.bgType
= kTXNBackgroundTypeRGB
;
1865 tback
.bg
.color
= MAC_WXCOLORREF( brush
.GetColour().GetPixel() );
1866 TXNSetBackground( m_txn
, &tback
);
1869 void wxMacMLTEControl::TXNSetAttribute( const wxTextAttr
& style
, long from
, long to
)
1871 TXNTypeAttributes typeAttr
[4] ;
1875 if ( style
.HasFont() )
1877 const wxFont
&font
= style
.GetFont() ;
1879 #if 0 // old version
1880 Str255 fontName
= "\pMonaco" ;
1881 SInt16 fontSize
= 12 ;
1882 Style fontStyle
= normal
;
1883 wxMacStringToPascal( font
.GetFaceName() , fontName
) ;
1884 fontSize
= font
.GetPointSize() ;
1885 if ( font
.GetUnderlined() )
1886 fontStyle
|= underline
;
1887 if ( font
.GetWeight() == wxBOLD
)
1889 if ( font
.GetStyle() == wxITALIC
)
1890 fontStyle
|= italic
;
1892 typeAttr
[attrCount
].tag
= kTXNQDFontNameAttribute
;
1893 typeAttr
[attrCount
].size
= kTXNQDFontNameAttributeSize
;
1894 typeAttr
[attrCount
].data
.dataPtr
= (void*)fontName
;
1897 typeAttr
[attrCount
].tag
= kTXNQDFontSizeAttribute
;
1898 typeAttr
[attrCount
].size
= kTXNFontSizeAttributeSize
;
1899 typeAttr
[attrCount
].data
.dataValue
= (fontSize
<< 16) ;
1902 typeAttr
[attrCount
].tag
= kTXNQDFontStyleAttribute
;
1903 typeAttr
[attrCount
].size
= kTXNQDFontStyleAttributeSize
;
1904 typeAttr
[attrCount
].data
.dataValue
= fontStyle
;
1907 typeAttr
[attrCount
].tag
= kTXNATSUIStyle
;
1908 typeAttr
[attrCount
].size
= kTXNATSUIStyleSize
;
1909 typeAttr
[attrCount
].data
.dataValue
= (UInt32
)font
.MacGetATSUStyle() ;
1914 if ( style
.HasTextColour() )
1916 color
= MAC_WXCOLORREF(style
.GetTextColour().GetPixel()) ;
1918 typeAttr
[attrCount
].tag
= kTXNQDFontColorAttribute
;
1919 typeAttr
[attrCount
].size
= kTXNQDFontColorAttributeSize
;
1920 typeAttr
[attrCount
].data
.dataPtr
= (void*) &color
;
1924 if ( attrCount
> 0 )
1926 verify_noerr( TXNSetTypeAttributes( m_txn
, attrCount
, typeAttr
, from
, to
) );
1927 // unfortunately the relayout is not automatic
1928 TXNRecalcTextLayout( m_txn
);
1932 void wxMacMLTEControl::SetFont( const wxFont
& font
, const wxColour
& foreground
, long windowStyle
)
1934 wxMacEditHelper
help( m_txn
) ;
1935 TXNSetAttribute( wxTextAttr( foreground
, wxNullColour
, font
), kTXNStartOffset
, kTXNEndOffset
) ;
1938 void wxMacMLTEControl::SetStyle( long start
, long end
, const wxTextAttr
& style
)
1940 wxMacEditHelper
help( m_txn
) ;
1941 TXNSetAttribute( style
, start
, end
) ;
1944 void wxMacMLTEControl::Copy()
1946 ClearCurrentScrap();
1948 TXNConvertToPublicScrap();
1951 void wxMacMLTEControl::Cut()
1953 ClearCurrentScrap();
1955 TXNConvertToPublicScrap();
1958 void wxMacMLTEControl::Paste()
1960 TXNConvertFromPublicScrap();
1964 bool wxMacMLTEControl::CanPaste() const
1966 return TXNIsScrapPastable() ;
1969 void wxMacMLTEControl::SetEditable(bool editable
)
1971 TXNControlTag tag
[] = { kTXNIOPrivilegesTag
} ;
1972 TXNControlData data
[] = { { editable
? kTXNReadWrite
: kTXNReadOnly
} } ;
1973 TXNSetTXNObjectControls( m_txn
, false, WXSIZEOF(tag
), tag
, data
) ;
1976 wxTextPos
wxMacMLTEControl::GetLastPosition() const
1978 wxTextPos actualsize
= 0 ;
1981 OSErr err
= TXNGetDataEncoded( m_txn
, kTXNStartOffset
, kTXNEndOffset
, &theText
, kTXNTextData
);
1986 actualsize
= GetHandleSize( theText
) ;
1987 DisposeHandle( theText
) ;
1997 void wxMacMLTEControl::Replace( long from
, long to
, const wxString
&str
)
1999 wxString value
= str
;
2000 wxMacConvertNewlines10To13( &value
) ;
2002 wxMacEditHelper
help( m_txn
) ;
2003 wxMacWindowClipper
c( m_peer
) ;
2005 TXNSetSelection( m_txn
, from
, to
) ;
2007 SetTXNData( value
, kTXNUseCurrentSelection
, kTXNUseCurrentSelection
) ;
2010 void wxMacMLTEControl::Remove( long from
, long to
)
2012 wxMacWindowClipper
c( m_peer
) ;
2013 wxMacEditHelper
help( m_txn
) ;
2014 TXNSetSelection( m_txn
, from
, to
) ;
2018 void wxMacMLTEControl::GetSelection( long* from
, long* to
) const
2020 TXNGetSelection( m_txn
, (TXNOffset
*) from
, (TXNOffset
*) to
) ;
2023 void wxMacMLTEControl::SetSelection( long from
, long to
)
2025 wxMacWindowClipper
c( m_peer
) ;
2027 // change the selection
2028 if ((from
== -1) && (to
== -1))
2029 TXNSelectAll( m_txn
);
2031 TXNSetSelection( m_txn
, from
, to
);
2033 TXNShowSelection( m_txn
, kTXNShowStart
);
2036 void wxMacMLTEControl::WriteText( const wxString
& str
)
2039 wxMacConvertNewlines10To13( &st
) ;
2041 long start
, end
, dummy
;
2043 GetSelection( &start
, &dummy
) ;
2044 wxMacWindowClipper
c( m_peer
) ;
2047 wxMacEditHelper
helper( m_txn
) ;
2048 SetTXNData( st
, kTXNUseCurrentSelection
, kTXNUseCurrentSelection
) ;
2051 GetSelection( &dummy
, &end
) ;
2053 // TODO: SetStyle( start , end , GetDefaultStyle() ) ;
2056 void wxMacMLTEControl::Clear()
2058 wxMacWindowClipper
c( m_peer
) ;
2059 wxMacEditHelper
st( m_txn
) ;
2060 TXNSetSelection( m_txn
, kTXNStartOffset
, kTXNEndOffset
) ;
2064 bool wxMacMLTEControl::CanUndo() const
2066 return TXNCanUndo( m_txn
, NULL
) ;
2069 void wxMacMLTEControl::Undo()
2074 bool wxMacMLTEControl::CanRedo() const
2076 return TXNCanRedo( m_txn
, NULL
) ;
2079 void wxMacMLTEControl::Redo()
2084 int wxMacMLTEControl::GetNumberOfLines() const
2086 ItemCount lines
= 0 ;
2087 TXNGetLineCount( m_txn
, &lines
) ;
2092 long wxMacMLTEControl::XYToPosition(long x
, long y
) const
2097 // TODO: find a better implementation : while we can get the
2098 // line metrics of a certain line, we don't get its starting
2099 // position, so it would probably be rather a binary search
2100 // for the start position
2101 long xpos
= 0, ypos
= 0 ;
2102 int lastHeight
= 0 ;
2105 lastpos
= GetLastPosition() ;
2106 for ( n
= 0 ; n
<= (ItemCount
) lastpos
; ++n
)
2108 if ( y
== ypos
&& x
== xpos
)
2111 TXNOffsetToPoint( m_txn
, n
, &curpt
) ;
2113 if ( curpt
.v
> lastHeight
)
2119 lastHeight
= curpt
.v
;
2128 bool wxMacMLTEControl::PositionToXY( long pos
, long *x
, long *y
) const
2138 lastpos
= GetLastPosition() ;
2139 if ( pos
<= lastpos
)
2141 // TODO: find a better implementation - while we can get the
2142 // line metrics of a certain line, we don't get its starting
2143 // position, so it would probably be rather a binary search
2144 // for the start position
2145 long xpos
= 0, ypos
= 0 ;
2146 int lastHeight
= 0 ;
2149 for ( n
= 0 ; n
<= (ItemCount
) pos
; ++n
)
2151 TXNOffsetToPoint( m_txn
, n
, &curpt
) ;
2153 if ( curpt
.v
> lastHeight
)
2159 lastHeight
= curpt
.v
;
2174 void wxMacMLTEControl::ShowPosition( long pos
)
2176 #if TARGET_RT_MAC_MACHO && defined(AVAILABLE_MAC_OS_X_VERSION_10_2_AND_LATER)
2178 Point current
, desired
;
2179 TXNOffset selstart
, selend
;
2181 TXNGetSelection( m_txn
, &selstart
, &selend
);
2182 TXNOffsetToPoint( m_txn
, selstart
, ¤t
);
2183 TXNOffsetToPoint( m_txn
, pos
, &desired
);
2185 // TODO: use HIPoints for 10.3 and above
2186 if ( (UInt32
)TXNScroll
!= (UInt32
)kUnresolvedCFragSymbolAddress
)
2188 OSErr theErr
= noErr
;
2189 SInt32 dv
= desired
.v
- current
.v
;
2190 SInt32 dh
= desired
.h
- current
.h
;
2191 TXNShowSelection( m_txn
, kTXNShowStart
) ; // NB: should this be kTXNShowStart or kTXNShowEnd ??
2192 theErr
= TXNScroll( m_txn
, kTXNScrollUnitsInPixels
, kTXNScrollUnitsInPixels
, &dv
, &dh
);
2194 // there will be an error returned for classic MLTE implementation when the control is
2195 // invisible, but HITextView works correctly, so we don't assert that one
2196 // wxASSERT_MSG( theErr == noErr, _T("TXNScroll returned an error!") );
2202 void wxMacMLTEControl::SetTXNData( const wxString
& st
, TXNOffset start
, TXNOffset end
)
2205 #if SIZEOF_WCHAR_T == 2
2206 size_t len
= st
.length() ;
2207 TXNSetData( m_txn
, kTXNUnicodeTextData
, (void*)st
.wc_str(), len
* 2, start
, end
);
2209 wxMBConvUTF16 converter
;
2210 ByteCount byteBufferLen
= converter
.WC2MB( NULL
, st
.wc_str(), 0 ) ;
2211 UniChar
*unibuf
= (UniChar
*)malloc( byteBufferLen
) ;
2212 converter
.WC2MB( (char*)unibuf
, st
.wc_str(), byteBufferLen
) ;
2213 TXNSetData( m_txn
, kTXNUnicodeTextData
, (void*)unibuf
, byteBufferLen
, start
, end
) ;
2217 wxCharBuffer text
= st
.mb_str( wxConvLocal
) ;
2218 TXNSetData( m_txn
, kTXNTextData
, (void*)text
.data(), strlen( text
), start
, end
) ;
2222 wxString
wxMacMLTEControl::GetLineText(long lineNo
) const
2226 if ( lineNo
< GetNumberOfLines() )
2229 Fixed lineWidth
, lineHeight
, currentHeight
;
2232 // get the first possible position in the control
2233 TXNOffsetToPoint(m_txn
, 0, &firstPoint
);
2235 // Iterate through the lines until we reach the one we want,
2236 // adding to our current y pixel point position
2239 while (ypos
< lineNo
)
2241 TXNGetLineMetrics(m_txn
, ypos
++, &lineWidth
, &lineHeight
);
2242 currentHeight
+= lineHeight
;
2245 Point thePoint
= { firstPoint
.v
+ (currentHeight
>> 16), firstPoint
.h
+ (0) };
2246 TXNOffset theOffset
;
2247 TXNPointToOffset(m_txn
, thePoint
, &theOffset
);
2249 wxString content
= GetStringValue() ;
2250 Point currentPoint
= thePoint
;
2251 while (thePoint
.v
== currentPoint
.v
&& theOffset
< content
.length())
2253 line
+= content
[theOffset
];
2254 TXNOffsetToPoint(m_txn
, ++theOffset
, ¤tPoint
);
2261 int wxMacMLTEControl::GetLineLength(long lineNo
) const
2265 if ( lineNo
< GetNumberOfLines() )
2268 Fixed lineWidth
, lineHeight
, currentHeight
;
2271 // get the first possible position in the control
2272 TXNOffsetToPoint(m_txn
, 0, &firstPoint
);
2274 // Iterate through the lines until we reach the one we want,
2275 // adding to our current y pixel point position
2278 while (ypos
< lineNo
)
2280 TXNGetLineMetrics(m_txn
, ypos
++, &lineWidth
, &lineHeight
);
2281 currentHeight
+= lineHeight
;
2284 Point thePoint
= { firstPoint
.v
+ (currentHeight
>> 16), firstPoint
.h
+ (0) };
2285 TXNOffset theOffset
;
2286 TXNPointToOffset(m_txn
, thePoint
, &theOffset
);
2288 wxString content
= GetStringValue() ;
2289 Point currentPoint
= thePoint
;
2290 while (thePoint
.v
== currentPoint
.v
&& theOffset
< content
.length())
2293 TXNOffsetToPoint(m_txn
, ++theOffset
, ¤tPoint
);
2300 // ----------------------------------------------------------------------------
2301 // MLTE control implementation (classic part)
2302 // ----------------------------------------------------------------------------
2304 // OS X Notes : We still don't have a full replacement for MLTE, so this implementation
2305 // has to live on. We have different problems coming from outdated implementations on the
2306 // various OS X versions. Most deal with the scrollbars: they are not correctly embedded
2307 // while this can be solved on 10.3 by reassigning them the correct place, on 10.2 there is
2308 // no way out, therefore we are using our own implementation and our own scrollbars ....
2310 #ifdef __WXMAC_OSX__
2312 TXNScrollInfoUPP gTXNScrollInfoProc
= NULL
;
2313 ControlActionUPP gTXNScrollActionProc
= NULL
;
2315 pascal void wxMacMLTEClassicControl::TXNScrollInfoProc(
2316 SInt32 iValue
, SInt32 iMaximumValue
,
2317 TXNScrollBarOrientation iScrollBarOrientation
, SInt32 iRefCon
)
2319 wxMacMLTEClassicControl
* mlte
= (wxMacMLTEClassicControl
*) iRefCon
;
2320 SInt32 value
= wxMax( iValue
, 0 ) ;
2321 SInt32 maximum
= wxMax( iMaximumValue
, 0 ) ;
2323 if ( iScrollBarOrientation
== kTXNHorizontal
)
2325 if ( mlte
->m_sbHorizontal
)
2327 SetControl32BitValue( mlte
->m_sbHorizontal
, value
) ;
2328 SetControl32BitMaximum( mlte
->m_sbHorizontal
, maximum
) ;
2329 mlte
->m_lastHorizontalValue
= value
;
2332 else if ( iScrollBarOrientation
== kTXNVertical
)
2334 if ( mlte
->m_sbVertical
)
2336 SetControl32BitValue( mlte
->m_sbVertical
, value
) ;
2337 SetControl32BitMaximum( mlte
->m_sbVertical
, maximum
) ;
2338 mlte
->m_lastVerticalValue
= value
;
2343 pascal void wxMacMLTEClassicControl::TXNScrollActionProc( ControlRef controlRef
, ControlPartCode partCode
)
2345 wxMacMLTEClassicControl
* mlte
= (wxMacMLTEClassicControl
*) GetControlReference( controlRef
) ;
2349 if ( controlRef
!= mlte
->m_sbVertical
&& controlRef
!= mlte
->m_sbHorizontal
)
2353 bool isHorizontal
= ( controlRef
== mlte
->m_sbHorizontal
) ;
2355 SInt32 minimum
= 0 ;
2356 SInt32 maximum
= GetControl32BitMaximum( controlRef
) ;
2357 SInt32 value
= GetControl32BitValue( controlRef
) ;
2362 case kControlDownButtonPart
:
2366 case kControlUpButtonPart
:
2370 case kControlPageDownPart
:
2371 delta
= GetControlViewSize( controlRef
) ;
2374 case kControlPageUpPart
:
2375 delta
= -GetControlViewSize( controlRef
) ;
2378 case kControlIndicatorPart
:
2379 delta
= value
- (isHorizontal
? mlte
->m_lastHorizontalValue
: mlte
->m_lastVerticalValue
) ;
2388 SInt32 newValue
= value
;
2390 if ( partCode
!= kControlIndicatorPart
)
2392 if ( value
+ delta
< minimum
)
2393 delta
= minimum
- value
;
2394 if ( value
+ delta
> maximum
)
2395 delta
= maximum
- value
;
2397 SetControl32BitValue( controlRef
, value
+ delta
) ;
2398 newValue
= value
+ delta
;
2401 SInt32 verticalDelta
= isHorizontal
? 0 : delta
;
2402 SInt32 horizontalDelta
= isHorizontal
? delta
: 0 ;
2405 mlte
->m_txn
, kTXNScrollUnitsInPixels
, kTXNScrollUnitsInPixels
,
2406 &verticalDelta
, &horizontalDelta
);
2407 verify_noerr( err
);
2410 mlte
->m_lastHorizontalValue
= newValue
;
2412 mlte
->m_lastVerticalValue
= newValue
;
2417 // make correct activations
2418 void wxMacMLTEClassicControl::MacActivatePaneText(bool setActive
)
2420 wxTextCtrl
* textctrl
= (wxTextCtrl
*) GetControlReference(m_controlRef
);
2422 wxMacWindowClipper
clipper( textctrl
) ;
2423 TXNActivate( m_txn
, m_txnFrameID
, setActive
);
2425 ControlRef controlFocus
= 0 ;
2426 GetKeyboardFocus( m_txnWindow
, &controlFocus
) ;
2427 if ( controlFocus
== m_controlRef
)
2428 TXNFocus( m_txn
, setActive
);
2431 void wxMacMLTEClassicControl::MacFocusPaneText(bool setFocus
)
2433 TXNFocus( m_txn
, setFocus
);
2436 // guards against inappropriate redraw (hidden objects drawing onto window)
2438 void wxMacMLTEClassicControl::MacSetObjectVisibility(bool vis
)
2440 ControlRef controlFocus
= 0 ;
2441 GetKeyboardFocus( m_txnWindow
, &controlFocus
) ;
2443 if ( !vis
&& (controlFocus
== m_controlRef
) )
2444 SetKeyboardFocus( m_txnWindow
, m_controlRef
, kControlFocusNoPart
) ;
2446 TXNControlTag iControlTags
[1] = { kTXNVisibilityTag
};
2447 TXNControlData iControlData
[1] = { { (UInt32
)false } };
2449 verify_noerr( TXNGetTXNObjectControls( m_txn
, 1, iControlTags
, iControlData
) ) ;
2451 if ( iControlData
[0].uValue
!= vis
)
2453 iControlData
[0].uValue
= vis
;
2454 verify_noerr( TXNSetTXNObjectControls( m_txn
, false , 1, iControlTags
, iControlData
) ) ;
2457 // currently, we always clip as partial visibility (overlapped) visibility is also a problem,
2458 // if we run into further problems we might set the FrameBounds to an empty rect here
2461 // make sure that the TXNObject is at the right position
2463 void wxMacMLTEClassicControl::MacUpdatePosition()
2465 wxTextCtrl
* textctrl
= (wxTextCtrl
*)GetControlReference( m_controlRef
);
2466 if ( textctrl
== NULL
)
2470 UMAGetControlBoundsInWindowCoords( m_controlRef
, &bounds
);
2472 wxRect visRect
= textctrl
->MacGetClippedClientRect() ;
2473 Rect visBounds
= { visRect
.y
, visRect
.x
, visRect
.y
+ visRect
.height
, visRect
.x
+ visRect
.width
} ;
2476 textctrl
->MacWindowToRootWindow( &x
, &y
) ;
2477 OffsetRect( &visBounds
, x
, y
) ;
2479 if ( !EqualRect( &bounds
, &m_txnControlBounds
) || !EqualRect( &visBounds
, &m_txnVisBounds
) )
2481 m_txnControlBounds
= bounds
;
2482 m_txnVisBounds
= visBounds
;
2483 wxMacWindowClipper
cl( textctrl
) ;
2485 #ifdef __WXMAC_OSX__
2486 if ( m_sbHorizontal
|| m_sbVertical
)
2488 int w
= bounds
.right
- bounds
.left
;
2489 int h
= bounds
.bottom
- bounds
.top
;
2491 if ( m_sbHorizontal
)
2495 sbBounds
.left
= -1 ;
2496 sbBounds
.top
= h
- 14 ;
2497 sbBounds
.right
= w
+ 1 ;
2498 sbBounds
.bottom
= h
+ 1 ;
2500 SetControlBounds( m_sbHorizontal
, &sbBounds
) ;
2501 SetControlViewSize( m_sbHorizontal
, w
) ;
2508 sbBounds
.left
= w
- 14 ;
2510 sbBounds
.right
= w
+ 1 ;
2511 sbBounds
.bottom
= m_sbHorizontal
? h
- 14 : h
+ 1 ;
2513 SetControlBounds( m_sbVertical
, &sbBounds
) ;
2514 SetControlViewSize( m_sbVertical
, h
) ;
2519 TXNLongRect olddestRect
;
2520 TXNGetRectBounds( m_txn
, &oldviewRect
, &olddestRect
, NULL
) ;
2522 Rect viewRect
= { m_txnControlBounds
.top
, m_txnControlBounds
.left
,
2523 m_txnControlBounds
.bottom
- ( m_sbHorizontal
? 14 : 0 ) ,
2524 m_txnControlBounds
.right
- ( m_sbVertical
? 14 : 0 ) } ;
2525 TXNLongRect destRect
= { m_txnControlBounds
.top
, m_txnControlBounds
.left
,
2526 m_txnControlBounds
.bottom
- ( m_sbHorizontal
? 14 : 0 ) ,
2527 m_txnControlBounds
.right
- ( m_sbVertical
? 14 : 0 ) } ;
2529 if ( olddestRect
.right
>= 10000 )
2530 destRect
.right
= destRect
.left
+ 32000 ;
2532 if ( olddestRect
.bottom
>= 0x20000000 )
2533 destRect
.bottom
= destRect
.top
+ 0x40000000 ;
2535 SectRect( &viewRect
, &visBounds
, &viewRect
) ;
2536 TXNSetRectBounds( m_txn
, &viewRect
, &destRect
, true ) ;
2541 m_txnControlBounds
.top
,
2542 m_txnControlBounds
.left
,
2543 m_txnControlBounds
.bottom
- (m_sbHorizontal
? 14 : 0),
2544 m_txnControlBounds
.right
- (m_sbVertical
? 14 : 0),
2550 m_txn
, m_txnControlBounds
.top
, m_txnControlBounds
.left
,
2551 wxMax( m_txnControlBounds
.bottom
, m_txnControlBounds
.top
),
2552 wxMax( m_txnControlBounds
.right
, m_txnControlBounds
.left
), m_txnFrameID
);
2555 // the SetFrameBounds method under Classic sometimes does not correctly scroll a selection into sight after a
2556 // movement, therefore we have to force it
2558 // this problem has been reported in OSX as well, so we use this here once again
2560 TXNLongRect textRect
;
2561 TXNGetRectBounds( m_txn
, NULL
, NULL
, &textRect
) ;
2562 if ( textRect
.left
< m_txnControlBounds
.left
)
2563 TXNShowSelection( m_txn
, kTXNShowStart
) ;
2567 void wxMacMLTEClassicControl::SetRect( Rect
*r
)
2569 wxMacControl::SetRect( r
) ;
2570 MacUpdatePosition() ;
2573 void wxMacMLTEClassicControl::MacControlUserPaneDrawProc(wxInt16 thePart
)
2575 wxTextCtrl
* textctrl
= (wxTextCtrl
*)GetControlReference( m_controlRef
);
2576 if ( textctrl
== NULL
)
2579 if ( textctrl
->MacIsReallyShown() )
2581 wxMacWindowClipper
clipper( textctrl
) ;
2582 TXNDraw( m_txn
, NULL
) ;
2586 wxInt16
wxMacMLTEClassicControl::MacControlUserPaneHitTestProc(wxInt16 x
, wxInt16 y
)
2588 Point where
= { y
, x
} ;
2589 ControlPartCode result
= kControlNoPart
;
2591 wxTextCtrl
* textctrl
= (wxTextCtrl
*) GetControlReference( m_controlRef
);
2592 if ( (textctrl
!= NULL
) && textctrl
->MacIsReallyShown() )
2594 if (PtInRect( where
, &m_txnControlBounds
))
2596 result
= kControlEditTextPart
;
2600 // sometimes we get the coords also in control local coordinates, therefore test again
2602 textctrl
->MacClientToRootWindow( &x
, &y
) ;
2606 if (PtInRect( where
, &m_txnControlBounds
))
2607 result
= kControlEditTextPart
;
2614 wxInt16
wxMacMLTEClassicControl::MacControlUserPaneTrackingProc( wxInt16 x
, wxInt16 y
, void* actionProc
)
2616 ControlPartCode result
= kControlNoPart
;
2618 wxTextCtrl
* textctrl
= (wxTextCtrl
*) GetControlReference( m_controlRef
);
2619 if ( (textctrl
!= NULL
) && textctrl
->MacIsReallyShown() )
2621 Point startPt
= { y
, x
} ;
2623 // for compositing, we must convert these into toplevel window coordinates, because hittesting expects them
2625 textctrl
->MacClientToRootWindow( &x
, &y
) ;
2629 switch (MacControlUserPaneHitTestProc( startPt
.h
, startPt
.v
))
2631 case kControlEditTextPart
:
2633 wxMacWindowClipper
clipper( textctrl
) ;
2636 ConvertEventRefToEventRecord( (EventRef
) wxTheApp
->MacGetCurrentEvent() , &rec
) ;
2637 TXNClick( m_txn
, &rec
);
2649 void wxMacMLTEClassicControl::MacControlUserPaneIdleProc()
2651 wxTextCtrl
* textctrl
= (wxTextCtrl
*)GetControlReference( m_controlRef
);
2652 if ( textctrl
== NULL
)
2655 if (textctrl
->MacIsReallyShown())
2657 if (IsControlActive(m_controlRef
))
2661 wxMacWindowClipper
clipper( textctrl
) ;
2666 if (PtInRect(mousep
, &m_txnControlBounds
))
2668 RgnHandle theRgn
= NewRgn();
2669 RectRgn(theRgn
, &m_txnControlBounds
);
2670 TXNAdjustCursor(m_txn
, theRgn
);
2677 wxInt16
wxMacMLTEClassicControl::MacControlUserPaneKeyDownProc (wxInt16 keyCode
, wxInt16 charCode
, wxInt16 modifiers
)
2679 wxTextCtrl
* textctrl
= (wxTextCtrl
*)GetControlReference( m_controlRef
);
2680 if ( textctrl
== NULL
)
2681 return kControlNoPart
;
2683 wxMacWindowClipper
clipper( textctrl
) ;
2686 memset( &ev
, 0 , sizeof( ev
) ) ;
2688 ev
.modifiers
= modifiers
;
2689 ev
.message
= ((keyCode
<< 8) & keyCodeMask
) | (charCode
& charCodeMask
);
2690 TXNKeyDown( m_txn
, &ev
);
2692 return kControlEntireControl
;
2695 void wxMacMLTEClassicControl::MacControlUserPaneActivateProc(bool activating
)
2697 MacActivatePaneText( activating
);
2700 wxInt16
wxMacMLTEClassicControl::MacControlUserPaneFocusProc(wxInt16 action
)
2702 ControlPartCode focusResult
= kControlFocusNoPart
;
2704 wxTextCtrl
* textctrl
= (wxTextCtrl
*)GetControlReference( m_controlRef
);
2705 if ( textctrl
== NULL
)
2708 wxMacWindowClipper
clipper( textctrl
) ;
2710 ControlRef controlFocus
= NULL
;
2711 GetKeyboardFocus( m_txnWindow
, &controlFocus
) ;
2712 bool wasFocused
= ( controlFocus
== m_controlRef
) ;
2716 case kControlFocusPrevPart
:
2717 case kControlFocusNextPart
:
2718 MacFocusPaneText( !wasFocused
);
2719 focusResult
= (!wasFocused
? (ControlPartCode
) kControlEditTextPart
: (ControlPartCode
) kControlFocusNoPart
);
2722 case kControlFocusNoPart
:
2724 MacFocusPaneText( false );
2725 focusResult
= kControlFocusNoPart
;
2732 void wxMacMLTEClassicControl::MacControlUserPaneBackgroundProc( void *info
)
2736 wxMacMLTEClassicControl::wxMacMLTEClassicControl( wxTextCtrl
*wxPeer
,
2737 const wxString
& str
,
2739 const wxSize
& size
, long style
)
2740 : wxMacMLTEControl( wxPeer
)
2742 m_font
= wxPeer
->GetFont() ;
2743 m_windowStyle
= style
;
2744 Rect bounds
= wxMacGetBoundsForControl( wxPeer
, pos
, size
) ;
2747 kControlSupportsEmbedding
| kControlSupportsFocus
| kControlWantsIdle
2748 | kControlWantsActivate
| kControlHandlesTracking
2749 // | kControlHasSpecialBackground
2750 | kControlGetsFocusOnClick
| kControlSupportsLiveFeedback
;
2752 OSStatus err
= ::CreateUserPaneControl(
2753 MAC_WXHWND(wxPeer
->GetParent()->MacGetTopLevelWindowRef()),
2754 &bounds
, featureSet
, &m_controlRef
);
2755 verify_noerr( err
);
2759 AdjustCreationAttributes( *wxWHITE
, true ) ;
2761 MacSetObjectVisibility( wxPeer
->MacIsReallyShown() ) ;
2765 wxMacConvertNewlines10To13( &st
) ;
2766 wxMacWindowClipper
clipper( m_peer
) ;
2767 SetTXNData( st
, kTXNStartOffset
, kTXNEndOffset
) ;
2768 TXNSetSelection( m_txn
, 0, 0 ) ;
2772 wxMacMLTEClassicControl::~wxMacMLTEClassicControl()
2774 TXNDeleteObject( m_txn
);
2778 void wxMacMLTEClassicControl::VisibilityChanged(bool shown
)
2780 MacSetObjectVisibility( shown
) ;
2781 wxMacControl::VisibilityChanged( shown
) ;
2784 void wxMacMLTEClassicControl::SuperChangedPosition()
2786 MacUpdatePosition() ;
2787 wxMacControl::SuperChangedPosition() ;
2790 #ifdef __WXMAC_OSX__
2792 ControlUserPaneDrawUPP gTPDrawProc
= NULL
;
2793 ControlUserPaneHitTestUPP gTPHitProc
= NULL
;
2794 ControlUserPaneTrackingUPP gTPTrackProc
= NULL
;
2795 ControlUserPaneIdleUPP gTPIdleProc
= NULL
;
2796 ControlUserPaneKeyDownUPP gTPKeyProc
= NULL
;
2797 ControlUserPaneActivateUPP gTPActivateProc
= NULL
;
2798 ControlUserPaneFocusUPP gTPFocusProc
= NULL
;
2800 static pascal void wxMacControlUserPaneDrawProc(ControlRef control
, SInt16 part
)
2802 wxTextCtrl
*textCtrl
= wxDynamicCast( wxFindControlFromMacControl(control
) , wxTextCtrl
) ;
2803 wxMacMLTEClassicControl
* win
= textCtrl
? (wxMacMLTEClassicControl
*)(textCtrl
->GetPeer()) : NULL
;
2805 win
->MacControlUserPaneDrawProc( part
) ;
2808 static pascal ControlPartCode
wxMacControlUserPaneHitTestProc(ControlRef control
, Point where
)
2810 wxTextCtrl
*textCtrl
= wxDynamicCast( wxFindControlFromMacControl(control
) , wxTextCtrl
) ;
2811 wxMacMLTEClassicControl
* win
= textCtrl
? (wxMacMLTEClassicControl
*)(textCtrl
->GetPeer()) : NULL
;
2813 return win
->MacControlUserPaneHitTestProc( where
.h
, where
.v
) ;
2815 return kControlNoPart
;
2818 static pascal ControlPartCode
wxMacControlUserPaneTrackingProc(ControlRef control
, Point startPt
, ControlActionUPP actionProc
)
2820 wxTextCtrl
*textCtrl
= wxDynamicCast( wxFindControlFromMacControl(control
) , wxTextCtrl
) ;
2821 wxMacMLTEClassicControl
* win
= textCtrl
? (wxMacMLTEClassicControl
*)(textCtrl
->GetPeer()) : NULL
;
2823 return win
->MacControlUserPaneTrackingProc( startPt
.h
, startPt
.v
, (void*) actionProc
) ;
2825 return kControlNoPart
;
2828 static pascal void wxMacControlUserPaneIdleProc(ControlRef control
)
2830 wxTextCtrl
*textCtrl
= wxDynamicCast( wxFindControlFromMacControl(control
) , wxTextCtrl
) ;
2831 wxMacMLTEClassicControl
* win
= textCtrl
? (wxMacMLTEClassicControl
*)(textCtrl
->GetPeer()) : NULL
;
2833 win
->MacControlUserPaneIdleProc() ;
2836 static pascal ControlPartCode
wxMacControlUserPaneKeyDownProc(ControlRef control
, SInt16 keyCode
, SInt16 charCode
, SInt16 modifiers
)
2838 wxTextCtrl
*textCtrl
= wxDynamicCast( wxFindControlFromMacControl(control
) , wxTextCtrl
) ;
2839 wxMacMLTEClassicControl
* win
= textCtrl
? (wxMacMLTEClassicControl
*)(textCtrl
->GetPeer()) : NULL
;
2841 return win
->MacControlUserPaneKeyDownProc( keyCode
, charCode
, modifiers
) ;
2843 return kControlNoPart
;
2846 static pascal void wxMacControlUserPaneActivateProc(ControlRef control
, Boolean activating
)
2848 wxTextCtrl
*textCtrl
= wxDynamicCast( wxFindControlFromMacControl(control
) , wxTextCtrl
) ;
2849 wxMacMLTEClassicControl
* win
= textCtrl
? (wxMacMLTEClassicControl
*)(textCtrl
->GetPeer()) : NULL
;
2851 win
->MacControlUserPaneActivateProc( activating
) ;
2854 static pascal ControlPartCode
wxMacControlUserPaneFocusProc(ControlRef control
, ControlFocusPart action
)
2856 wxTextCtrl
*textCtrl
= wxDynamicCast( wxFindControlFromMacControl(control
) , wxTextCtrl
) ;
2857 wxMacMLTEClassicControl
* win
= textCtrl
? (wxMacMLTEClassicControl
*)(textCtrl
->GetPeer()) : NULL
;
2859 return win
->MacControlUserPaneFocusProc( action
) ;
2861 return kControlNoPart
;
2865 static pascal void wxMacControlUserPaneBackgroundProc(ControlRef control
, ControlBackgroundPtr info
)
2867 wxTextCtrl
*textCtrl
= wxDynamicCast( wxFindControlFromMacControl(control
) , wxTextCtrl
) ;
2868 wxMacMLTEClassicControl
* win
= textCtrl
? (wxMacMLTEClassicControl
*)(textCtrl
->GetPeer()) : NULL
;
2870 win
->MacControlUserPaneBackgroundProc(info
) ;
2874 #endif // __WXMAC_OSX__
2876 // TXNRegisterScrollInfoProc
2878 OSStatus
wxMacMLTEClassicControl::DoCreate()
2881 OSStatus err
= noErr
;
2883 // set up our globals
2884 #ifdef __WXMAC_OSX__
2885 if (gTPDrawProc
== NULL
) gTPDrawProc
= NewControlUserPaneDrawUPP(wxMacControlUserPaneDrawProc
);
2886 if (gTPHitProc
== NULL
) gTPHitProc
= NewControlUserPaneHitTestUPP(wxMacControlUserPaneHitTestProc
);
2887 if (gTPTrackProc
== NULL
) gTPTrackProc
= NewControlUserPaneTrackingUPP(wxMacControlUserPaneTrackingProc
);
2888 if (gTPIdleProc
== NULL
) gTPIdleProc
= NewControlUserPaneIdleUPP(wxMacControlUserPaneIdleProc
);
2889 if (gTPKeyProc
== NULL
) gTPKeyProc
= NewControlUserPaneKeyDownUPP(wxMacControlUserPaneKeyDownProc
);
2890 if (gTPActivateProc
== NULL
) gTPActivateProc
= NewControlUserPaneActivateUPP(wxMacControlUserPaneActivateProc
);
2891 if (gTPFocusProc
== NULL
) gTPFocusProc
= NewControlUserPaneFocusUPP(wxMacControlUserPaneFocusProc
);
2893 if (gTXNScrollInfoProc
== NULL
) gTXNScrollInfoProc
= NewTXNScrollInfoUPP(TXNScrollInfoProc
) ;
2894 if (gTXNScrollActionProc
== NULL
) gTXNScrollActionProc
= NewControlActionUPP(TXNScrollActionProc
) ;
2897 // set the initial settings for our private data
2899 m_txnWindow
= GetControlOwner(m_controlRef
);
2900 m_txnPort
= (GrafPtr
) GetWindowPort(m_txnWindow
);
2902 #ifdef __WXMAC_OSX__
2903 // set up the user pane procedures
2904 SetControlData(m_controlRef
, kControlEntireControl
, kControlUserPaneDrawProcTag
, sizeof(gTPDrawProc
), &gTPDrawProc
);
2905 SetControlData(m_controlRef
, kControlEntireControl
, kControlUserPaneHitTestProcTag
, sizeof(gTPHitProc
), &gTPHitProc
);
2906 SetControlData(m_controlRef
, kControlEntireControl
, kControlUserPaneTrackingProcTag
, sizeof(gTPTrackProc
), &gTPTrackProc
);
2907 SetControlData(m_controlRef
, kControlEntireControl
, kControlUserPaneIdleProcTag
, sizeof(gTPIdleProc
), &gTPIdleProc
);
2908 SetControlData(m_controlRef
, kControlEntireControl
, kControlUserPaneKeyDownProcTag
, sizeof(gTPKeyProc
), &gTPKeyProc
);
2909 SetControlData(m_controlRef
, kControlEntireControl
, kControlUserPaneActivateProcTag
, sizeof(gTPActivateProc
), &gTPActivateProc
);
2910 SetControlData(m_controlRef
, kControlEntireControl
, kControlUserPaneFocusProcTag
, sizeof(gTPFocusProc
), &gTPFocusProc
);
2913 // calculate the rectangles used by the control
2914 UMAGetControlBoundsInWindowCoords( m_controlRef
, &bounds
);
2916 m_txnControlBounds
= bounds
;
2917 m_txnVisBounds
= bounds
;
2922 GetGWorld( &origPort
, &origDev
) ;
2923 SetPort( m_txnPort
);
2925 // create the new edit field
2926 TXNFrameOptions frameOptions
= FrameOptionsFromWXStyle( m_windowStyle
);
2928 #ifdef __WXMAC_OSX__
2929 // the scrollbars are not correctly embedded but are inserted at the root:
2930 // this gives us problems as we have erratic redraws even over the structure area
2932 m_sbHorizontal
= 0 ;
2934 m_lastHorizontalValue
= 0 ;
2935 m_lastVerticalValue
= 0 ;
2937 Rect sb
= { 0 , 0 , 0 , 0 } ;
2938 if ( frameOptions
& kTXNWantVScrollBarMask
)
2940 CreateScrollBarControl( m_txnWindow
, &sb
, 0, 0, 100, 1, true, gTXNScrollActionProc
, &m_sbVertical
);
2941 SetControlReference( m_sbVertical
, (SInt32
)this );
2942 SetControlAction( m_sbVertical
, gTXNScrollActionProc
);
2943 ShowControl( m_sbVertical
);
2944 EmbedControl( m_sbVertical
, m_controlRef
);
2945 frameOptions
&= ~kTXNWantVScrollBarMask
;
2948 if ( frameOptions
& kTXNWantHScrollBarMask
)
2950 CreateScrollBarControl( m_txnWindow
, &sb
, 0, 0, 100, 1, true, gTXNScrollActionProc
, &m_sbHorizontal
);
2951 SetControlReference( m_sbHorizontal
, (SInt32
)this );
2952 SetControlAction( m_sbHorizontal
, gTXNScrollActionProc
);
2953 ShowControl( m_sbHorizontal
);
2954 EmbedControl( m_sbHorizontal
, m_controlRef
);
2955 frameOptions
&= ~(kTXNWantHScrollBarMask
| kTXNDrawGrowIconMask
);
2961 NULL
, m_txnWindow
, &bounds
, frameOptions
,
2962 kTXNTextEditStyleFrameType
, kTXNTextensionFile
, kTXNSystemDefaultEncoding
,
2963 &m_txn
, &m_txnFrameID
, NULL
);
2964 verify_noerr( err
);
2967 TXNControlTag iControlTags
[] = { kTXNUseCarbonEvents
};
2968 TXNControlData iControlData
[] = { { (UInt32
)&cInfo
} };
2969 int toptag
= WXSIZEOF( iControlTags
) ;
2970 TXNCarbonEventInfo cInfo
;
2971 cInfo
.useCarbonEvents
= false ;
2974 cInfo
.fDictionary
= NULL
;
2976 verify_noerr( TXNSetTXNObjectControls( m_txn
, false, toptag
, iControlTags
, iControlData
) );
2979 #ifdef __WXMAC_OSX__
2980 TXNRegisterScrollInfoProc( m_txn
, gTXNScrollInfoProc
, (SInt32
)this );
2983 SetGWorld( origPort
, origDev
) ;
2988 // ----------------------------------------------------------------------------
2989 // MLTE control implementation (OSX part)
2990 // ----------------------------------------------------------------------------
2992 #if TARGET_API_MAC_OSX
2994 #if MAC_OS_X_VERSION_MAX_ALLOWED > MAC_OS_X_VERSION_10_2
2996 // tiger multi-line textcontrols with no CR in the entire content
2997 // don't scroll automatically, so we need a hack.
2998 // This attempt only works 'before' the key (ie before CallNextEventHandler)
2999 // is processed, thus the scrolling always occurs one character too late, but
3000 // better than nothing ...
3002 static const EventTypeSpec eventList
[] =
3004 { kEventClassTextInput
, kEventTextInputUnicodeForKeyEvent
} ,
3007 static pascal OSStatus
wxMacUnicodeTextEventHandler( EventHandlerCallRef handler
, EventRef event
, void *data
)
3009 OSStatus result
= eventNotHandledErr
;
3010 wxMacMLTEHIViewControl
* focus
= (wxMacMLTEHIViewControl
*) data
;
3012 switch ( GetEventKind( event
) )
3014 case kEventTextInputUnicodeForKeyEvent
:
3016 if ( UMAGetSystemVersion() >= 0x1040 )
3018 TXNOffset from
, to
;
3019 TXNGetSelection( focus
->GetTXNObject() , &from
, &to
) ;
3021 TXNShowSelection( focus
->GetTXNObject() , kTXNShowStart
);
3023 result
= CallNextEventHandler(handler
,event
);
3033 static pascal OSStatus
wxMacTextControlEventHandler( EventHandlerCallRef handler
, EventRef event
, void *data
)
3035 OSStatus result
= eventNotHandledErr
;
3037 switch ( GetEventClass( event
) )
3039 case kEventClassTextInput
:
3040 result
= wxMacUnicodeTextEventHandler( handler
, event
, data
) ;
3049 DEFINE_ONE_SHOT_HANDLER_GETTER( wxMacTextControlEventHandler
)
3051 wxMacMLTEHIViewControl::wxMacMLTEHIViewControl( wxTextCtrl
*wxPeer
,
3052 const wxString
& str
,
3054 const wxSize
& size
, long style
) : wxMacMLTEControl( wxPeer
)
3056 m_font
= wxPeer
->GetFont() ;
3057 m_windowStyle
= style
;
3058 Rect bounds
= wxMacGetBoundsForControl( wxPeer
, pos
, size
) ;
3060 wxMacConvertNewlines10To13( &st
) ;
3063 { bounds
.left
, bounds
.top
},
3064 { bounds
.right
- bounds
.left
, bounds
.bottom
- bounds
.top
} } ;
3066 m_scrollView
= NULL
;
3067 TXNFrameOptions frameOptions
= FrameOptionsFromWXStyle( style
) ;
3068 if ( frameOptions
& (kTXNWantVScrollBarMask
| kTXNWantHScrollBarMask
) )
3071 (frameOptions
& kTXNWantHScrollBarMask
? kHIScrollViewOptionsHorizScroll
: 0)
3072 | (frameOptions
& kTXNWantVScrollBarMask
? kHIScrollViewOptionsVertScroll
: 0) ,
3075 HIViewSetFrame( m_scrollView
, &hr
);
3076 HIViewSetVisible( m_scrollView
, true );
3080 HITextViewCreate( NULL
, 0, frameOptions
, &m_textView
) ;
3081 m_txn
= HITextViewGetTXNObject( m_textView
) ;
3082 HIViewSetVisible( m_textView
, true ) ;
3085 HIViewAddSubview( m_scrollView
, m_textView
) ;
3086 m_controlRef
= m_scrollView
;
3087 wxPeer
->MacInstallEventHandler( (WXWidget
) m_textView
) ;
3091 HIViewSetFrame( m_textView
, &hr
);
3092 m_controlRef
= m_textView
;
3095 AdjustCreationAttributes( *wxWHITE
, true ) ;
3097 wxMacWindowClipper
c( m_peer
) ;
3098 SetTXNData( st
, kTXNStartOffset
, kTXNEndOffset
) ;
3100 TXNSetSelection( m_txn
, 0, 0 );
3101 TXNShowSelection( m_txn
, kTXNShowStart
);
3103 InstallControlEventHandler( m_textView
, GetwxMacTextControlEventHandlerUPP(),
3104 GetEventTypeCount(eventList
), eventList
, this,
3105 &m_textEventHandlerRef
);
3108 wxMacMLTEHIViewControl::~wxMacMLTEHIViewControl()
3110 ::RemoveEventHandler( m_textEventHandlerRef
) ;
3113 OSStatus
wxMacMLTEHIViewControl::SetFocus( ControlFocusPart focusPart
)
3115 return SetKeyboardFocus( GetControlOwner( m_textView
), m_textView
, focusPart
) ;
3118 bool wxMacMLTEHIViewControl::HasFocus() const
3120 ControlRef control
;
3121 GetKeyboardFocus( GetUserFocusWindow() , &control
) ;
3122 return control
== m_textView
;
3125 void wxMacMLTEHIViewControl::SetBackground( const wxBrush
&brush
)
3127 wxMacMLTEControl::SetBackground( brush
) ;
3130 CGColorSpaceRef rgbSpace
= CGColorSpaceCreateDeviceRGB();
3131 RGBColor col
= MAC_WXCOLORREF(brush
.GetColour().GetPixel()) ;
3133 float component
[4] ;
3134 component
[0] = col
.red
/ 65536.0 ;
3135 component
[1] = col
.green
/ 65536.0 ;
3136 component
[2] = col
.blue
/ 65536.0 ;
3137 component
[3] = 1.0 ; // alpha
3139 CGColorRef color
= CGColorCreate( rgbSpace
, component
);
3140 HITextViewSetBackgroundColor( m_textView
, color
);
3141 CGColorSpaceRelease( rgbSpace
);
3145 #endif // MAC_OS_X_VERSION_MAX_ALLOWED > MAC_OS_X_VERSION_10_2
3150 #endif // wxUSE_TEXTCTRL