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::ChangeValue(const wxString
& str
)
570 if ( GetValue() == str
)
573 GetPeer()->SetStringValue( str
) ;
576 void wxTextCtrl::SetMaxLength(unsigned long len
)
581 bool wxTextCtrl::SetFont( const wxFont
& font
)
583 if ( !wxTextCtrlBase::SetFont( font
) )
586 GetPeer()->SetFont( font
, GetForegroundColour() , GetWindowStyle() ) ;
591 bool wxTextCtrl::SetStyle(long start
, long end
, const wxTextAttr
& style
)
593 GetPeer()->SetStyle( start
, end
, style
) ;
598 bool wxTextCtrl::SetDefaultStyle(const wxTextAttr
& style
)
600 wxTextCtrlBase::SetDefaultStyle( style
) ;
601 SetStyle( kTXNUseCurrentSelection
, kTXNUseCurrentSelection
, GetDefaultStyle() ) ;
606 // Clipboard operations
608 void wxTextCtrl::Copy()
614 void wxTextCtrl::Cut()
620 wxCommandEvent
event( wxEVT_COMMAND_TEXT_UPDATED
, m_windowId
);
621 event
.SetEventObject( this );
622 GetEventHandler()->ProcessEvent( event
);
626 void wxTextCtrl::Paste()
632 // TODO: eventually we should add setting the default style again
634 wxCommandEvent
event( wxEVT_COMMAND_TEXT_UPDATED
, m_windowId
);
635 event
.SetEventObject( this );
636 GetEventHandler()->ProcessEvent( event
);
640 bool wxTextCtrl::CanCopy() const
642 // Can copy if there's a selection
644 GetSelection( &from
, &to
);
649 bool wxTextCtrl::CanCut() const
654 // Can cut if there's a selection
656 GetSelection( &from
, &to
);
661 bool wxTextCtrl::CanPaste() const
666 return GetPeer()->CanPaste() ;
669 void wxTextCtrl::SetEditable(bool editable
)
671 if ( editable
!= m_editable
)
673 m_editable
= editable
;
674 GetPeer()->SetEditable( editable
) ;
678 void wxTextCtrl::SetInsertionPoint(long pos
)
680 SetSelection( pos
, pos
) ;
683 void wxTextCtrl::SetInsertionPointEnd()
685 wxTextPos pos
= GetLastPosition();
686 SetInsertionPoint( pos
);
689 long wxTextCtrl::GetInsertionPoint() const
692 GetSelection( &begin
, &end
) ;
697 wxTextPos
wxTextCtrl::GetLastPosition() const
699 return GetPeer()->GetLastPosition() ;
702 void wxTextCtrl::Replace(long from
, long to
, const wxString
& str
)
704 GetPeer()->Replace( from
, to
, str
) ;
707 void wxTextCtrl::Remove(long from
, long to
)
709 GetPeer()->Remove( from
, to
) ;
712 void wxTextCtrl::SetSelection(long from
, long to
)
714 GetPeer()->SetSelection( from
, to
) ;
717 void wxTextCtrl::WriteText(const wxString
& str
)
719 // TODO: this MPRemoting will be moved into a remoting peer proxy for any command
720 if ( !wxIsMainThread() )
722 // unfortunately CW 8 is not able to correctly deduce the template types,
723 // so we have to instantiate explicitly
724 wxMacMPRemoteGUICall
<wxTextCtrl
,wxString
>( this , &wxTextCtrl::WriteText
, str
) ;
729 GetPeer()->WriteText( str
) ;
732 void wxTextCtrl::AppendText(const wxString
& text
)
734 SetInsertionPointEnd();
738 void wxTextCtrl::Clear()
743 bool wxTextCtrl::IsModified() const
748 bool wxTextCtrl::IsEditable() const
750 return IsEnabled() && m_editable
;
753 bool wxTextCtrl::AcceptsFocus() const
755 // we don't want focus if we can't be edited
756 return /*IsEditable() && */ wxControl::AcceptsFocus();
759 wxSize
wxTextCtrl::DoGetBestSize() const
763 // these are the numbers from the HIG:
764 // we reduce them by the borders first
767 switch ( m_windowVariant
)
769 case wxWINDOW_VARIANT_NORMAL
:
773 case wxWINDOW_VARIANT_SMALL
:
777 case wxWINDOW_VARIANT_MINI
:
786 // as the above numbers have some free space around the text
787 // we get 5 lines like this anyway
788 if ( m_windowStyle
& wxTE_MULTILINE
)
791 if ( !HasFlag(wxNO_BORDER
) )
794 return wxSize(wText
, hText
);
797 // ----------------------------------------------------------------------------
799 // ----------------------------------------------------------------------------
801 void wxTextCtrl::Undo()
807 void wxTextCtrl::Redo()
813 bool wxTextCtrl::CanUndo() const
818 return GetPeer()->CanUndo() ;
821 bool wxTextCtrl::CanRedo() const
826 return GetPeer()->CanRedo() ;
829 void wxTextCtrl::MarkDirty()
834 void wxTextCtrl::DiscardEdits()
839 int wxTextCtrl::GetNumberOfLines() const
841 return GetPeer()->GetNumberOfLines() ;
844 long wxTextCtrl::XYToPosition(long x
, long y
) const
846 return GetPeer()->XYToPosition( x
, y
) ;
849 bool wxTextCtrl::PositionToXY(long pos
, long *x
, long *y
) const
851 return GetPeer()->PositionToXY( pos
, x
, y
) ;
854 void wxTextCtrl::ShowPosition(long pos
)
856 return GetPeer()->ShowPosition(pos
) ;
859 int wxTextCtrl::GetLineLength(long lineNo
) const
861 return GetPeer()->GetLineLength(lineNo
) ;
864 wxString
wxTextCtrl::GetLineText(long lineNo
) const
866 return GetPeer()->GetLineText(lineNo
) ;
869 void wxTextCtrl::Command(wxCommandEvent
& event
)
871 SetValue(event
.GetString());
872 ProcessCommand(event
);
875 void wxTextCtrl::OnDropFiles(wxDropFilesEvent
& event
)
877 // By default, load the first file into the text window.
878 if (event
.GetNumberOfFiles() > 0)
879 LoadFile( event
.GetFiles()[0] );
882 void wxTextCtrl::OnEraseBackground(wxEraseEvent
& event
)
884 // all erasing should be done by the real mac control implementation
885 // while this is true for MLTE under classic, the HITextView is somehow
886 // transparent but background erase is not working correctly, so intercept
887 // things while we can...
891 void wxTextCtrl::OnChar(wxKeyEvent
& event
)
893 int key
= event
.GetKeyCode() ;
894 bool eat_key
= false ;
896 if ( key
== 'a' && event
.MetaDown() )
903 if ( key
== 'c' && event
.MetaDown() )
911 if ( !IsEditable() && key
!= WXK_LEFT
&& key
!= WXK_RIGHT
&& key
!= WXK_DOWN
&& key
!= WXK_UP
&& key
!= WXK_TAB
&&
912 !( key
== WXK_RETURN
&& ( (m_windowStyle
& wxTE_PROCESS_ENTER
) || (m_windowStyle
& wxTE_MULTILINE
) ) )
913 // && key != WXK_PAGEUP && key != WXK_PAGEDOWN && key != WXK_HOME && key != WXK_END
920 // Check if we have reached the max # of chars (if it is set), but still
921 // allow navigation and deletion
922 if ( !IsMultiLine() && m_maxLength
&& GetValue().length() >= m_maxLength
&&
923 key
!= WXK_LEFT
&& key
!= WXK_RIGHT
&& key
!= WXK_TAB
&&
924 key
!= WXK_BACK
&& !( key
== WXK_RETURN
&& (m_windowStyle
& wxTE_PROCESS_ENTER
) )
927 // eat it, we don't want to add more than allowed # of characters
929 // TODO: generate EVT_TEXT_MAXLEN()
933 // assume that any key not processed yet is going to modify the control
936 if ( key
== 'v' && event
.MetaDown() )
944 if ( key
== 'x' && event
.MetaDown() )
955 if (m_windowStyle
& wxTE_PROCESS_ENTER
)
957 wxCommandEvent
event(wxEVT_COMMAND_TEXT_ENTER
, m_windowId
);
958 event
.SetEventObject( this );
959 event
.SetString( GetValue() );
960 if ( GetEventHandler()->ProcessEvent(event
) )
964 if ( !(m_windowStyle
& wxTE_MULTILINE
) )
966 wxTopLevelWindow
*tlw
= wxDynamicCast(wxGetTopLevelParent(this), wxTopLevelWindow
);
967 if ( tlw
&& tlw
->GetDefaultItem() )
969 wxButton
*def
= wxDynamicCast(tlw
->GetDefaultItem(), wxButton
);
970 if ( def
&& def
->IsEnabled() )
972 wxCommandEvent
event(wxEVT_COMMAND_BUTTON_CLICKED
, def
->GetId() );
973 event
.SetEventObject(def
);
980 // this will make wxWidgets eat the ENTER key so that
981 // we actually prevent line wrapping in a single line text control
987 if ( !(m_windowStyle
& wxTE_PROCESS_TAB
))
990 if (!event
.ShiftDown())
991 flags
|= wxNavigationKeyEvent::IsForward
;
992 if (event
.ControlDown())
993 flags
|= wxNavigationKeyEvent::WinChange
;
1000 // This is necessary (don't know why);
1001 // otherwise the tab will not be inserted.
1002 WriteText(wxT("\t"));
1013 // perform keystroke handling
1017 if ( ( key
>= 0x20 && key
< WXK_START
) ||
1018 ( key
>= WXK_NUMPAD0
&& key
<= WXK_DIVIDE
) ||
1019 key
== WXK_RETURN
||
1020 key
== WXK_DELETE
||
1023 wxCommandEvent
event1(wxEVT_COMMAND_TEXT_UPDATED
, m_windowId
);
1024 event1
.SetEventObject( this );
1025 wxPostEvent( GetEventHandler(), event1
);
1029 // ----------------------------------------------------------------------------
1030 // standard handlers for standard edit menu events
1031 // ----------------------------------------------------------------------------
1033 void wxTextCtrl::OnCut(wxCommandEvent
& WXUNUSED(event
))
1038 void wxTextCtrl::OnCopy(wxCommandEvent
& WXUNUSED(event
))
1043 void wxTextCtrl::OnPaste(wxCommandEvent
& WXUNUSED(event
))
1048 void wxTextCtrl::OnUndo(wxCommandEvent
& WXUNUSED(event
))
1053 void wxTextCtrl::OnRedo(wxCommandEvent
& WXUNUSED(event
))
1058 void wxTextCtrl::OnDelete(wxCommandEvent
& WXUNUSED(event
))
1062 GetSelection( &from
, &to
);
1063 if (from
!= -1 && to
!= -1)
1067 void wxTextCtrl::OnSelectAll(wxCommandEvent
& WXUNUSED(event
))
1069 SetSelection(-1, -1);
1072 void wxTextCtrl::OnUpdateCut(wxUpdateUIEvent
& event
)
1074 event
.Enable( CanCut() );
1077 void wxTextCtrl::OnUpdateCopy(wxUpdateUIEvent
& event
)
1079 event
.Enable( CanCopy() );
1082 void wxTextCtrl::OnUpdatePaste(wxUpdateUIEvent
& event
)
1084 event
.Enable( CanPaste() );
1087 void wxTextCtrl::OnUpdateUndo(wxUpdateUIEvent
& event
)
1089 event
.Enable( CanUndo() );
1092 void wxTextCtrl::OnUpdateRedo(wxUpdateUIEvent
& event
)
1094 event
.Enable( CanRedo() );
1097 void wxTextCtrl::OnUpdateDelete(wxUpdateUIEvent
& event
)
1101 GetSelection( &from
, &to
);
1102 event
.Enable( from
!= -1 && to
!= -1 && from
!= to
&& IsEditable() ) ;
1105 void wxTextCtrl::OnUpdateSelectAll(wxUpdateUIEvent
& event
)
1107 event
.Enable(GetLastPosition() > 0);
1110 // CS: Context Menus only work with MLTE implementations or non-multiline HIViews at the moment
1112 void wxTextCtrl::OnContextMenu(wxContextMenuEvent
& event
)
1114 if ( GetPeer()->HasOwnContextMenu() )
1120 if (m_privateContextMenu
== NULL
)
1122 m_privateContextMenu
= new wxMenu
;
1123 m_privateContextMenu
->Append(wxID_UNDO
, _("&Undo"));
1124 m_privateContextMenu
->Append(wxID_REDO
, _("&Redo"));
1125 m_privateContextMenu
->AppendSeparator();
1126 m_privateContextMenu
->Append(wxID_CUT
, _("Cu&t"));
1127 m_privateContextMenu
->Append(wxID_COPY
, _("&Copy"));
1128 m_privateContextMenu
->Append(wxID_PASTE
, _("&Paste"));
1129 m_privateContextMenu
->Append(wxID_CLEAR
, _("&Delete"));
1130 m_privateContextMenu
->AppendSeparator();
1131 m_privateContextMenu
->Append(wxID_SELECTALL
, _("Select &All"));
1134 if (m_privateContextMenu
!= NULL
)
1135 PopupMenu(m_privateContextMenu
);
1138 bool wxTextCtrl::MacSetupCursor( const wxPoint
& pt
)
1140 if ( !GetPeer()->SetupCursor( pt
) )
1141 return wxWindow::MacSetupCursor( pt
) ;
1146 #if !TARGET_API_MAC_OSX
1148 // user pane implementation
1150 void wxTextCtrl::MacControlUserPaneDrawProc(wxInt16 part
)
1152 GetPeer()->MacControlUserPaneDrawProc( part
) ;
1155 wxInt16
wxTextCtrl::MacControlUserPaneHitTestProc(wxInt16 x
, wxInt16 y
)
1157 return GetPeer()->MacControlUserPaneHitTestProc( x
, y
) ;
1160 wxInt16
wxTextCtrl::MacControlUserPaneTrackingProc(wxInt16 x
, wxInt16 y
, void* actionProc
)
1162 return GetPeer()->MacControlUserPaneTrackingProc( x
, y
, actionProc
) ;
1165 void wxTextCtrl::MacControlUserPaneIdleProc()
1167 GetPeer()->MacControlUserPaneIdleProc( ) ;
1170 wxInt16
wxTextCtrl::MacControlUserPaneKeyDownProc(wxInt16 keyCode
, wxInt16 charCode
, wxInt16 modifiers
)
1172 return GetPeer()->MacControlUserPaneKeyDownProc( keyCode
, charCode
, modifiers
) ;
1175 void wxTextCtrl::MacControlUserPaneActivateProc(bool activating
)
1177 GetPeer()->MacControlUserPaneActivateProc( activating
) ;
1180 wxInt16
wxTextCtrl::MacControlUserPaneFocusProc(wxInt16 action
)
1182 return GetPeer()->MacControlUserPaneFocusProc( action
) ;
1185 void wxTextCtrl::MacControlUserPaneBackgroundProc(void* info
)
1187 GetPeer()->MacControlUserPaneBackgroundProc( info
) ;
1192 // ----------------------------------------------------------------------------
1193 // implementation base class
1194 // ----------------------------------------------------------------------------
1196 wxMacTextControl::wxMacTextControl(wxTextCtrl
* peer
) :
1197 wxMacControl( peer
)
1201 wxMacTextControl::~wxMacTextControl()
1205 void wxMacTextControl::SetStyle(long start
, long end
, const wxTextAttr
& style
)
1209 void wxMacTextControl::Copy()
1213 void wxMacTextControl::Cut()
1217 void wxMacTextControl::Paste()
1221 bool wxMacTextControl::CanPaste() const
1226 void wxMacTextControl::SetEditable(bool editable
)
1230 wxTextPos
wxMacTextControl::GetLastPosition() const
1232 return GetStringValue().length() ;
1235 void wxMacTextControl::Replace( long from
, long to
, const wxString
&val
)
1237 SetSelection( from
, to
) ;
1241 void wxMacTextControl::Remove( long from
, long to
)
1243 SetSelection( from
, to
) ;
1244 WriteText( wxEmptyString
) ;
1247 void wxMacTextControl::Clear()
1249 SetStringValue( wxEmptyString
) ;
1252 bool wxMacTextControl::CanUndo() const
1257 void wxMacTextControl::Undo()
1261 bool wxMacTextControl::CanRedo() const
1266 void wxMacTextControl::Redo()
1270 long wxMacTextControl::XYToPosition(long x
, long y
) const
1275 bool wxMacTextControl::PositionToXY(long pos
, long *x
, long *y
) const
1280 void wxMacTextControl::ShowPosition( long WXUNUSED(pos
) )
1284 int wxMacTextControl::GetNumberOfLines() const
1286 ItemCount lines
= 0 ;
1287 wxString content
= GetStringValue() ;
1290 for (size_t i
= 0; i
< content
.length() ; i
++)
1292 if (content
[i
] == '\r')
1299 wxString
wxMacTextControl::GetLineText(long lineNo
) const
1301 // TODO: change this if possible to reflect real lines
1302 wxString content
= GetStringValue() ;
1306 for (size_t i
= 0; i
< content
.length() ; i
++)
1308 if (count
== lineNo
)
1310 // Add chars in line then
1313 for (size_t j
= i
; j
< content
.length(); j
++)
1315 if (content
[j
] == '\n')
1324 if (content
[i
] == '\n')
1328 return wxEmptyString
;
1331 int wxMacTextControl::GetLineLength(long lineNo
) const
1333 // TODO: change this if possible to reflect real lines
1334 wxString content
= GetStringValue() ;
1338 for (size_t i
= 0; i
< content
.length() ; i
++)
1340 if (count
== lineNo
)
1342 // Count chars in line then
1344 for (size_t j
= i
; j
< content
.length(); j
++)
1347 if (content
[j
] == '\n')
1354 if (content
[i
] == '\n')
1361 // ----------------------------------------------------------------------------
1362 // standard unicode control implementation
1363 // ----------------------------------------------------------------------------
1365 #if TARGET_API_MAC_OSX
1367 // the current unicode textcontrol implementation has a bug : only if the control
1368 // is currently having the focus, the selection can be retrieved by the corresponding
1369 // data tag. So we have a mirroring using a member variable
1370 // TODO : build event table using virtual member functions for wxMacControl
1372 static const EventTypeSpec unicodeTextControlEventList
[] =
1374 { kEventClassControl
, kEventControlSetFocusPart
} ,
1377 static pascal OSStatus
wxMacUnicodeTextControlControlEventHandler( EventHandlerCallRef handler
, EventRef event
, void *data
)
1379 OSStatus result
= eventNotHandledErr
;
1380 wxMacUnicodeTextControl
* focus
= (wxMacUnicodeTextControl
*) data
;
1381 wxMacCarbonEvent
cEvent( event
) ;
1383 switch ( GetEventKind( event
) )
1385 case kEventControlSetFocusPart
:
1387 ControlPartCode controlPart
= cEvent
.GetParameter
<ControlPartCode
>(kEventParamControlPart
, typeControlPartCode
);
1388 if ( controlPart
== kControlFocusNoPart
)
1390 // about to loose focus -> store selection to field
1391 focus
->GetData
<ControlEditTextSelectionRec
>( 0, kControlEditTextSelectionTag
, &focus
->m_selection
);
1393 result
= CallNextEventHandler(handler
,event
) ;
1394 if ( controlPart
!= kControlFocusNoPart
)
1396 // about to gain focus -> set selection from field
1397 focus
->SetData
<ControlEditTextSelectionRec
>( 0, kControlEditTextSelectionTag
, &focus
->m_selection
);
1408 static pascal OSStatus
wxMacUnicodeTextControlEventHandler( EventHandlerCallRef handler
, EventRef event
, void *data
)
1410 OSStatus result
= eventNotHandledErr
;
1412 switch ( GetEventClass( event
) )
1414 case kEventClassControl
:
1415 result
= wxMacUnicodeTextControlControlEventHandler( handler
, event
, data
) ;
1424 DEFINE_ONE_SHOT_HANDLER_GETTER( wxMacUnicodeTextControlEventHandler
)
1426 wxMacUnicodeTextControl::wxMacUnicodeTextControl( wxTextCtrl
*wxPeer
,
1427 const wxString
& str
,
1429 const wxSize
& size
, long style
)
1430 : wxMacTextControl( wxPeer
)
1432 m_font
= wxPeer
->GetFont() ;
1433 m_windowStyle
= style
;
1434 Rect bounds
= wxMacGetBoundsForControl( wxPeer
, pos
, size
) ;
1436 wxMacConvertNewlines10To13( &st
) ;
1437 wxMacCFStringHolder
cf(st
, m_font
.GetEncoding()) ;
1438 CFStringRef cfr
= cf
;
1439 Boolean isPassword
= ( m_windowStyle
& wxTE_PASSWORD
) != 0 ;
1440 m_valueTag
= isPassword
? kControlEditTextPasswordCFStringTag
: kControlEditTextCFStringTag
;
1442 OSStatus err
= CreateEditUnicodeTextControl(
1443 MAC_WXHWND(wxPeer
->MacGetTopLevelWindowRef()), &bounds
, cfr
,
1444 isPassword
, NULL
, &m_controlRef
) ;
1445 verify_noerr( err
);
1447 if ( !(m_windowStyle
& wxTE_MULTILINE
) )
1448 SetData
<Boolean
>( kControlEditTextPart
, kControlEditTextSingleLineTag
, true ) ;
1450 InstallControlEventHandler( m_controlRef
, GetwxMacUnicodeTextControlEventHandlerUPP(),
1451 GetEventTypeCount(unicodeTextControlEventList
), unicodeTextControlEventList
, this,
1452 &m_focusHandlerRef
);
1455 wxMacUnicodeTextControl::~wxMacUnicodeTextControl()
1457 ::RemoveEventHandler( m_focusHandlerRef
);
1460 void wxMacUnicodeTextControl::VisibilityChanged(bool shown
)
1462 if ( !(m_windowStyle
& wxTE_MULTILINE
) && shown
)
1464 // work around a refresh issue insofar as not always the entire content is shown,
1465 // even if this would be possible
1466 ControlEditTextSelectionRec sel
;
1467 CFStringRef value
= NULL
;
1469 verify_noerr( GetData
<ControlEditTextSelectionRec
>( 0, kControlEditTextSelectionTag
, &sel
) );
1470 verify_noerr( GetData
<CFStringRef
>( 0, m_valueTag
, &value
) );
1471 verify_noerr( SetData
<CFStringRef
>( 0, m_valueTag
, &value
) );
1472 verify_noerr( SetData
<ControlEditTextSelectionRec
>( 0, kControlEditTextSelectionTag
, &sel
) );
1474 CFRelease( value
) ;
1478 wxString
wxMacUnicodeTextControl::GetStringValue() const
1481 CFStringRef value
= GetData
<CFStringRef
>(0, m_valueTag
) ;
1484 wxMacCFStringHolder
cf(value
) ;
1485 result
= cf
.AsString() ;
1489 wxMacConvertNewlines13To10( &result
) ;
1491 wxMacConvertNewlines10To13( &result
) ;
1497 void wxMacUnicodeTextControl::SetStringValue( const wxString
&str
)
1500 wxMacConvertNewlines10To13( &st
) ;
1501 wxMacCFStringHolder
cf( st
, m_font
.GetEncoding() ) ;
1502 verify_noerr( SetData
<CFStringRef
>( 0, m_valueTag
, cf
) ) ;
1505 void wxMacUnicodeTextControl::Copy()
1507 SendHICommand( kHICommandCopy
) ;
1510 void wxMacUnicodeTextControl::Cut()
1512 SendHICommand( kHICommandCut
) ;
1515 void wxMacUnicodeTextControl::Paste()
1517 SendHICommand( kHICommandPaste
) ;
1520 bool wxMacUnicodeTextControl::CanPaste() const
1525 void wxMacUnicodeTextControl::SetEditable(bool editable
)
1527 #if 0 // leads to problem because text cannot be selected anymore
1528 SetData
<Boolean
>( kControlEditTextPart
, kControlEditTextLockedTag
, (Boolean
) !editable
) ;
1532 void wxMacUnicodeTextControl::GetSelection( long* from
, long* to
) const
1534 ControlEditTextSelectionRec sel
;
1536 verify_noerr( GetData
<ControlEditTextSelectionRec
>( 0, kControlEditTextSelectionTag
, &sel
) ) ;
1541 *from
= sel
.selStart
;
1546 void wxMacUnicodeTextControl::SetSelection( long from
, long to
)
1548 ControlEditTextSelectionRec sel
;
1550 int textLength
= 0 ;
1551 CFStringRef value
= GetData
<CFStringRef
>(0, m_valueTag
) ;
1554 wxMacCFStringHolder
cf(value
) ;
1555 textLength
= cf
.AsString().length() ;
1558 if ((from
== -1) && (to
== -1))
1565 from
= wxMin(textLength
,wxMax(from
,0)) ;
1566 to
= wxMax(0,wxMin(textLength
,to
)) ;
1569 sel
.selStart
= from
;
1572 SetData
<ControlEditTextSelectionRec
>( 0, kControlEditTextSelectionTag
, &sel
) ;
1577 void wxMacUnicodeTextControl::WriteText( const wxString
& str
)
1580 wxMacConvertNewlines10To13( &st
) ;
1582 #if MAC_OS_X_VERSION_MAX_ALLOWED > MAC_OS_X_VERSION_10_2
1585 wxMacCFStringHolder
cf(st
, m_font
.GetEncoding() ) ;
1586 CFStringRef value
= cf
;
1587 SetData
<CFStringRef
>( 0, kControlEditTextInsertCFStringRefTag
, &value
);
1592 wxString val
= GetStringValue() ;
1594 GetSelection( &start
, &end
) ;
1595 val
.Remove( start
, end
- start
) ;
1596 val
.insert( start
, str
) ;
1597 SetStringValue( val
) ;
1598 SetSelection( start
+ str
.length() , start
+ str
.length() ) ;
1604 // ----------------------------------------------------------------------------
1605 // MLTE control implementation (common part)
1606 // ----------------------------------------------------------------------------
1608 // if MTLE is read only, no changes at all are allowed, not even from
1609 // procedural API, in order to allow changes via API all the same we must undo
1610 // the readonly status while we are executing, this class helps to do so
1612 class wxMacEditHelper
1615 wxMacEditHelper( TXNObject txn
)
1617 TXNControlTag tag
[] = { kTXNIOPrivilegesTag
} ;
1619 TXNGetTXNObjectControls( m_txn
, 1 , tag
, m_data
) ;
1620 if ( m_data
[0].uValue
== kTXNReadOnly
)
1622 TXNControlData data
[] = { { kTXNReadWrite
} } ;
1623 TXNSetTXNObjectControls( m_txn
, false , 1 , tag
, data
) ;
1629 TXNControlTag tag
[] = { kTXNIOPrivilegesTag
} ;
1630 if ( m_data
[0].uValue
== kTXNReadOnly
)
1631 TXNSetTXNObjectControls( m_txn
, false , 1 , tag
, m_data
) ;
1636 TXNControlData m_data
[1] ;
1639 wxMacMLTEControl::wxMacMLTEControl( wxTextCtrl
*peer
)
1640 : wxMacTextControl( peer
)
1642 SetNeedsFocusRect( true ) ;
1645 wxString
wxMacMLTEControl::GetStringValue() const
1649 Size actualSize
= 0;
1654 err
= TXNGetDataEncoded( m_txn
, kTXNStartOffset
, kTXNEndOffset
, &theText
, kTXNUnicodeTextData
);
1663 actualSize
= GetHandleSize( theText
) / sizeof(UniChar
) ;
1664 if ( actualSize
> 0 )
1666 wxChar
*ptr
= NULL
;
1668 #if SIZEOF_WCHAR_T == 2
1669 ptr
= new wxChar
[actualSize
+ 1] ;
1670 wxStrncpy( ptr
, (wxChar
*)(*theText
) , actualSize
) ;
1672 SetHandleSize( theText
, (actualSize
+ 1) * sizeof(UniChar
) ) ;
1674 (((UniChar
*)*theText
)[actualSize
]) = 0 ;
1675 wxMBConvUTF16 converter
;
1676 size_t noChars
= converter
.MB2WC( NULL
, (const char*)*theText
, 0 ) ;
1677 wxASSERT_MSG( noChars
!= wxCONV_FAILED
, _T("Unable to count the number of characters in this string!") );
1678 ptr
= new wxChar
[noChars
+ 1] ;
1680 noChars
= converter
.MB2WC( ptr
, (const char*)*theText
, noChars
+ 1 ) ;
1681 wxASSERT_MSG( noChars
!= wxCONV_FAILED
, _T("Conversion of string failed!") );
1683 HUnlock( theText
) ;
1686 ptr
[actualSize
] = 0 ;
1687 result
= wxString( ptr
) ;
1691 DisposeHandle( theText
) ;
1695 err
= TXNGetDataEncoded( m_txn
, kTXNStartOffset
, kTXNEndOffset
, &theText
, kTXNTextData
);
1704 actualSize
= GetHandleSize( theText
) ;
1705 if ( actualSize
> 0 )
1708 result
= wxString( *theText
, wxConvLocal
, actualSize
) ;
1709 HUnlock( theText
) ;
1712 DisposeHandle( theText
) ;
1718 wxMacConvertNewlines13To10( &result
) ;
1720 wxMacConvertNewlines10To13( &result
) ;
1726 void wxMacMLTEControl::SetStringValue( const wxString
&str
)
1729 wxMacConvertNewlines10To13( &st
);
1732 wxMacWindowClipper
c( m_peer
);
1735 wxMacEditHelper
help( m_txn
);
1736 SetTXNData( st
, kTXNStartOffset
, kTXNEndOffset
);
1739 TXNSetSelection( m_txn
, 0, 0 );
1740 TXNShowSelection( m_txn
, kTXNShowStart
);
1744 TXNFrameOptions
wxMacMLTEControl::FrameOptionsFromWXStyle( long wxStyle
)
1746 TXNFrameOptions frameOptions
= kTXNDontDrawCaretWhenInactiveMask
;
1748 #if MAC_OS_X_VERSION_MAX_ALLOWED >= MAC_OS_X_VERSION_10_3
1749 frameOptions
|= kTXNDoFontSubstitutionMask
;
1752 if ( ! (wxStyle
& wxTE_NOHIDESEL
) )
1753 frameOptions
|= kTXNDontDrawSelectionWhenInactiveMask
;
1755 if ( wxStyle
& (wxHSCROLL
| wxTE_DONTWRAP
) )
1756 frameOptions
|= kTXNWantHScrollBarMask
;
1758 if ( wxStyle
& wxTE_MULTILINE
)
1760 frameOptions
|= kTXNAlwaysWrapAtViewEdgeMask
;
1762 if ( !(wxStyle
& wxTE_NO_VSCROLL
) )
1764 frameOptions
|= kTXNWantVScrollBarMask
;
1766 // The following code causes drawing problems on 10.4. Perhaps it can be restored for
1767 // older versions of the OS, but I'm not sure it's appropriate to put a grow icon here
1768 // anyways, as AFAIK users can't actually use it to resize the text ctrl.
1769 // if ( frameOptions & kTXNWantHScrollBarMask )
1770 // frameOptions |= kTXNDrawGrowIconMask ;
1775 frameOptions
|= kTXNSingleLineOnlyMask
;
1778 return frameOptions
;
1781 void wxMacMLTEControl::AdjustCreationAttributes( const wxColour
&background
, bool visible
)
1783 TXNControlTag iControlTags
[] =
1785 kTXNDoFontSubstitution
,
1786 kTXNWordWrapStateTag
,
1788 TXNControlData iControlData
[] =
1794 int toptag
= WXSIZEOF( iControlTags
) ;
1796 if ( m_windowStyle
& wxTE_MULTILINE
)
1798 iControlData
[1].uValue
=
1799 (m_windowStyle
& wxTE_DONTWRAP
)
1804 OSStatus err
= TXNSetTXNObjectControls( m_txn
, false, toptag
, iControlTags
, iControlData
) ;
1805 verify_noerr( err
);
1807 // setting the default font:
1808 // under 10.2 this causes a visible caret, therefore we avoid it
1810 if ( UMAGetSystemVersion() >= 0x1030 )
1816 GetThemeFont( kThemeSystemFont
, GetApplicationScript() , fontName
, &fontSize
, &fontStyle
) ;
1818 TXNTypeAttributes typeAttr
[] =
1820 { kTXNQDFontNameAttribute
, kTXNQDFontNameAttributeSize
, { (void*) fontName
} } ,
1821 { kTXNQDFontSizeAttribute
, kTXNFontSizeAttributeSize
, { (void*) (fontSize
<< 16) } } ,
1822 { kTXNQDFontStyleAttribute
, kTXNQDFontStyleAttributeSize
, { (void*) normal
} } ,
1825 err
= TXNSetTypeAttributes(
1826 m_txn
, sizeof(typeAttr
) / sizeof(TXNTypeAttributes
),
1827 typeAttr
, kTXNStartOffset
, kTXNEndOffset
);
1828 verify_noerr( err
);
1831 if ( m_windowStyle
& wxTE_PASSWORD
)
1833 UniChar c
= 0x00A5 ;
1834 err
= TXNEchoMode( m_txn
, c
, 0 , true );
1835 verify_noerr( err
);
1838 TXNBackground tback
;
1839 tback
.bgType
= kTXNBackgroundTypeRGB
;
1840 tback
.bg
.color
= MAC_WXCOLORREF( background
.GetPixel() );
1841 TXNSetBackground( m_txn
, &tback
);
1843 #if MAC_OS_X_VERSION_MAX_ALLOWED >= MAC_OS_X_VERSION_10_4
1844 if ( UMAGetSystemVersion() >= 0x1040 )
1846 TXNCommandEventSupportOptions options
;
1847 if ( TXNGetCommandEventSupport( m_txn
, &options
) == noErr
)
1850 kTXNSupportEditCommandProcessing
1851 | kTXNSupportEditCommandUpdating
1852 | kTXNSupportSpellCheckCommandProcessing
1853 | kTXNSupportSpellCheckCommandUpdating
1854 | kTXNSupportFontCommandProcessing
1855 | kTXNSupportFontCommandUpdating
;
1857 TXNSetCommandEventSupport( m_txn
, options
) ;
1863 void wxMacMLTEControl::SetBackground( const wxBrush
&brush
)
1865 // currently only solid background are supported
1866 TXNBackground tback
;
1868 tback
.bgType
= kTXNBackgroundTypeRGB
;
1869 tback
.bg
.color
= MAC_WXCOLORREF( brush
.GetColour().GetPixel() );
1870 TXNSetBackground( m_txn
, &tback
);
1873 void wxMacMLTEControl::TXNSetAttribute( const wxTextAttr
& style
, long from
, long to
)
1875 TXNTypeAttributes typeAttr
[4] ;
1879 if ( style
.HasFont() )
1881 const wxFont
&font
= style
.GetFont() ;
1883 #if 0 // old version
1884 Str255 fontName
= "\pMonaco" ;
1885 SInt16 fontSize
= 12 ;
1886 Style fontStyle
= normal
;
1887 wxMacStringToPascal( font
.GetFaceName() , fontName
) ;
1888 fontSize
= font
.GetPointSize() ;
1889 if ( font
.GetUnderlined() )
1890 fontStyle
|= underline
;
1891 if ( font
.GetWeight() == wxBOLD
)
1893 if ( font
.GetStyle() == wxITALIC
)
1894 fontStyle
|= italic
;
1896 typeAttr
[attrCount
].tag
= kTXNQDFontNameAttribute
;
1897 typeAttr
[attrCount
].size
= kTXNQDFontNameAttributeSize
;
1898 typeAttr
[attrCount
].data
.dataPtr
= (void*)fontName
;
1901 typeAttr
[attrCount
].tag
= kTXNQDFontSizeAttribute
;
1902 typeAttr
[attrCount
].size
= kTXNFontSizeAttributeSize
;
1903 typeAttr
[attrCount
].data
.dataValue
= (fontSize
<< 16) ;
1906 typeAttr
[attrCount
].tag
= kTXNQDFontStyleAttribute
;
1907 typeAttr
[attrCount
].size
= kTXNQDFontStyleAttributeSize
;
1908 typeAttr
[attrCount
].data
.dataValue
= fontStyle
;
1911 typeAttr
[attrCount
].tag
= kTXNATSUIStyle
;
1912 typeAttr
[attrCount
].size
= kTXNATSUIStyleSize
;
1913 typeAttr
[attrCount
].data
.dataValue
= (UInt32
)font
.MacGetATSUStyle() ;
1918 if ( style
.HasTextColour() )
1920 color
= MAC_WXCOLORREF(style
.GetTextColour().GetPixel()) ;
1922 typeAttr
[attrCount
].tag
= kTXNQDFontColorAttribute
;
1923 typeAttr
[attrCount
].size
= kTXNQDFontColorAttributeSize
;
1924 typeAttr
[attrCount
].data
.dataPtr
= (void*) &color
;
1928 if ( attrCount
> 0 )
1930 verify_noerr( TXNSetTypeAttributes( m_txn
, attrCount
, typeAttr
, from
, to
) );
1931 // unfortunately the relayout is not automatic
1932 TXNRecalcTextLayout( m_txn
);
1936 void wxMacMLTEControl::SetFont( const wxFont
& font
, const wxColour
& foreground
, long windowStyle
)
1938 wxMacEditHelper
help( m_txn
) ;
1939 TXNSetAttribute( wxTextAttr( foreground
, wxNullColour
, font
), kTXNStartOffset
, kTXNEndOffset
) ;
1942 void wxMacMLTEControl::SetStyle( long start
, long end
, const wxTextAttr
& style
)
1944 wxMacEditHelper
help( m_txn
) ;
1945 TXNSetAttribute( style
, start
, end
) ;
1948 void wxMacMLTEControl::Copy()
1950 ClearCurrentScrap();
1952 TXNConvertToPublicScrap();
1955 void wxMacMLTEControl::Cut()
1957 ClearCurrentScrap();
1959 TXNConvertToPublicScrap();
1962 void wxMacMLTEControl::Paste()
1964 TXNConvertFromPublicScrap();
1968 bool wxMacMLTEControl::CanPaste() const
1970 return TXNIsScrapPastable() ;
1973 void wxMacMLTEControl::SetEditable(bool editable
)
1975 TXNControlTag tag
[] = { kTXNIOPrivilegesTag
} ;
1976 TXNControlData data
[] = { { editable
? kTXNReadWrite
: kTXNReadOnly
} } ;
1977 TXNSetTXNObjectControls( m_txn
, false, WXSIZEOF(tag
), tag
, data
) ;
1980 wxTextPos
wxMacMLTEControl::GetLastPosition() const
1982 wxTextPos actualsize
= 0 ;
1985 OSErr err
= TXNGetDataEncoded( m_txn
, kTXNStartOffset
, kTXNEndOffset
, &theText
, kTXNTextData
);
1990 actualsize
= GetHandleSize( theText
) ;
1991 DisposeHandle( theText
) ;
2001 void wxMacMLTEControl::Replace( long from
, long to
, const wxString
&str
)
2003 wxString value
= str
;
2004 wxMacConvertNewlines10To13( &value
) ;
2006 wxMacEditHelper
help( m_txn
) ;
2007 wxMacWindowClipper
c( m_peer
) ;
2009 TXNSetSelection( m_txn
, from
, to
) ;
2011 SetTXNData( value
, kTXNUseCurrentSelection
, kTXNUseCurrentSelection
) ;
2014 void wxMacMLTEControl::Remove( long from
, long to
)
2016 wxMacWindowClipper
c( m_peer
) ;
2017 wxMacEditHelper
help( m_txn
) ;
2018 TXNSetSelection( m_txn
, from
, to
) ;
2022 void wxMacMLTEControl::GetSelection( long* from
, long* to
) const
2024 TXNGetSelection( m_txn
, (TXNOffset
*) from
, (TXNOffset
*) to
) ;
2027 void wxMacMLTEControl::SetSelection( long from
, long to
)
2029 wxMacWindowClipper
c( m_peer
) ;
2031 // change the selection
2032 if ((from
== -1) && (to
== -1))
2033 TXNSelectAll( m_txn
);
2035 TXNSetSelection( m_txn
, from
, to
);
2037 TXNShowSelection( m_txn
, kTXNShowStart
);
2040 void wxMacMLTEControl::WriteText( const wxString
& str
)
2043 wxMacConvertNewlines10To13( &st
) ;
2045 long start
, end
, dummy
;
2047 GetSelection( &start
, &dummy
) ;
2048 wxMacWindowClipper
c( m_peer
) ;
2051 wxMacEditHelper
helper( m_txn
) ;
2052 SetTXNData( st
, kTXNUseCurrentSelection
, kTXNUseCurrentSelection
) ;
2055 GetSelection( &dummy
, &end
) ;
2057 // TODO: SetStyle( start , end , GetDefaultStyle() ) ;
2060 void wxMacMLTEControl::Clear()
2062 wxMacWindowClipper
c( m_peer
) ;
2063 wxMacEditHelper
st( m_txn
) ;
2064 TXNSetSelection( m_txn
, kTXNStartOffset
, kTXNEndOffset
) ;
2068 bool wxMacMLTEControl::CanUndo() const
2070 return TXNCanUndo( m_txn
, NULL
) ;
2073 void wxMacMLTEControl::Undo()
2078 bool wxMacMLTEControl::CanRedo() const
2080 return TXNCanRedo( m_txn
, NULL
) ;
2083 void wxMacMLTEControl::Redo()
2088 int wxMacMLTEControl::GetNumberOfLines() const
2090 ItemCount lines
= 0 ;
2091 TXNGetLineCount( m_txn
, &lines
) ;
2096 long wxMacMLTEControl::XYToPosition(long x
, long y
) const
2101 // TODO: find a better implementation : while we can get the
2102 // line metrics of a certain line, we don't get its starting
2103 // position, so it would probably be rather a binary search
2104 // for the start position
2105 long xpos
= 0, ypos
= 0 ;
2106 int lastHeight
= 0 ;
2109 lastpos
= GetLastPosition() ;
2110 for ( n
= 0 ; n
<= (ItemCount
) lastpos
; ++n
)
2112 if ( y
== ypos
&& x
== xpos
)
2115 TXNOffsetToPoint( m_txn
, n
, &curpt
) ;
2117 if ( curpt
.v
> lastHeight
)
2123 lastHeight
= curpt
.v
;
2132 bool wxMacMLTEControl::PositionToXY( long pos
, long *x
, long *y
) const
2142 lastpos
= GetLastPosition() ;
2143 if ( pos
<= lastpos
)
2145 // TODO: find a better implementation - while we can get the
2146 // line metrics of a certain line, we don't get its starting
2147 // position, so it would probably be rather a binary search
2148 // for the start position
2149 long xpos
= 0, ypos
= 0 ;
2150 int lastHeight
= 0 ;
2153 for ( n
= 0 ; n
<= (ItemCount
) pos
; ++n
)
2155 TXNOffsetToPoint( m_txn
, n
, &curpt
) ;
2157 if ( curpt
.v
> lastHeight
)
2163 lastHeight
= curpt
.v
;
2178 void wxMacMLTEControl::ShowPosition( long pos
)
2180 #if TARGET_RT_MAC_MACHO && defined(AVAILABLE_MAC_OS_X_VERSION_10_2_AND_LATER)
2182 Point current
, desired
;
2183 TXNOffset selstart
, selend
;
2185 TXNGetSelection( m_txn
, &selstart
, &selend
);
2186 TXNOffsetToPoint( m_txn
, selstart
, ¤t
);
2187 TXNOffsetToPoint( m_txn
, pos
, &desired
);
2189 // TODO: use HIPoints for 10.3 and above
2190 if ( (UInt32
)TXNScroll
!= (UInt32
)kUnresolvedCFragSymbolAddress
)
2192 OSErr theErr
= noErr
;
2193 SInt32 dv
= desired
.v
- current
.v
;
2194 SInt32 dh
= desired
.h
- current
.h
;
2195 TXNShowSelection( m_txn
, kTXNShowStart
) ; // NB: should this be kTXNShowStart or kTXNShowEnd ??
2196 theErr
= TXNScroll( m_txn
, kTXNScrollUnitsInPixels
, kTXNScrollUnitsInPixels
, &dv
, &dh
);
2198 // there will be an error returned for classic MLTE implementation when the control is
2199 // invisible, but HITextView works correctly, so we don't assert that one
2200 // wxASSERT_MSG( theErr == noErr, _T("TXNScroll returned an error!") );
2206 void wxMacMLTEControl::SetTXNData( const wxString
& st
, TXNOffset start
, TXNOffset end
)
2209 #if SIZEOF_WCHAR_T == 2
2210 size_t len
= st
.length() ;
2211 TXNSetData( m_txn
, kTXNUnicodeTextData
, (void*)st
.wc_str(), len
* 2, start
, end
);
2213 wxMBConvUTF16 converter
;
2214 ByteCount byteBufferLen
= converter
.WC2MB( NULL
, st
.wc_str(), 0 ) ;
2215 UniChar
*unibuf
= (UniChar
*)malloc( byteBufferLen
) ;
2216 converter
.WC2MB( (char*)unibuf
, st
.wc_str(), byteBufferLen
) ;
2217 TXNSetData( m_txn
, kTXNUnicodeTextData
, (void*)unibuf
, byteBufferLen
, start
, end
) ;
2221 wxCharBuffer text
= st
.mb_str( wxConvLocal
) ;
2222 TXNSetData( m_txn
, kTXNTextData
, (void*)text
.data(), strlen( text
), start
, end
) ;
2226 wxString
wxMacMLTEControl::GetLineText(long lineNo
) const
2230 if ( lineNo
< GetNumberOfLines() )
2233 Fixed lineWidth
, lineHeight
, currentHeight
;
2236 // get the first possible position in the control
2237 TXNOffsetToPoint(m_txn
, 0, &firstPoint
);
2239 // Iterate through the lines until we reach the one we want,
2240 // adding to our current y pixel point position
2243 while (ypos
< lineNo
)
2245 TXNGetLineMetrics(m_txn
, ypos
++, &lineWidth
, &lineHeight
);
2246 currentHeight
+= lineHeight
;
2249 Point thePoint
= { firstPoint
.v
+ (currentHeight
>> 16), firstPoint
.h
+ (0) };
2250 TXNOffset theOffset
;
2251 TXNPointToOffset(m_txn
, thePoint
, &theOffset
);
2253 wxString content
= GetStringValue() ;
2254 Point currentPoint
= thePoint
;
2255 while (thePoint
.v
== currentPoint
.v
&& theOffset
< content
.length())
2257 line
+= content
[theOffset
];
2258 TXNOffsetToPoint(m_txn
, ++theOffset
, ¤tPoint
);
2265 int wxMacMLTEControl::GetLineLength(long lineNo
) const
2269 if ( lineNo
< GetNumberOfLines() )
2272 Fixed lineWidth
, lineHeight
, currentHeight
;
2275 // get the first possible position in the control
2276 TXNOffsetToPoint(m_txn
, 0, &firstPoint
);
2278 // Iterate through the lines until we reach the one we want,
2279 // adding to our current y pixel point position
2282 while (ypos
< lineNo
)
2284 TXNGetLineMetrics(m_txn
, ypos
++, &lineWidth
, &lineHeight
);
2285 currentHeight
+= lineHeight
;
2288 Point thePoint
= { firstPoint
.v
+ (currentHeight
>> 16), firstPoint
.h
+ (0) };
2289 TXNOffset theOffset
;
2290 TXNPointToOffset(m_txn
, thePoint
, &theOffset
);
2292 wxString content
= GetStringValue() ;
2293 Point currentPoint
= thePoint
;
2294 while (thePoint
.v
== currentPoint
.v
&& theOffset
< content
.length())
2297 TXNOffsetToPoint(m_txn
, ++theOffset
, ¤tPoint
);
2304 // ----------------------------------------------------------------------------
2305 // MLTE control implementation (classic part)
2306 // ----------------------------------------------------------------------------
2308 // OS X Notes : We still don't have a full replacement for MLTE, so this implementation
2309 // has to live on. We have different problems coming from outdated implementations on the
2310 // various OS X versions. Most deal with the scrollbars: they are not correctly embedded
2311 // while this can be solved on 10.3 by reassigning them the correct place, on 10.2 there is
2312 // no way out, therefore we are using our own implementation and our own scrollbars ....
2314 #ifdef __WXMAC_OSX__
2316 TXNScrollInfoUPP gTXNScrollInfoProc
= NULL
;
2317 ControlActionUPP gTXNScrollActionProc
= NULL
;
2319 pascal void wxMacMLTEClassicControl::TXNScrollInfoProc(
2320 SInt32 iValue
, SInt32 iMaximumValue
,
2321 TXNScrollBarOrientation iScrollBarOrientation
, SInt32 iRefCon
)
2323 wxMacMLTEClassicControl
* mlte
= (wxMacMLTEClassicControl
*) iRefCon
;
2324 SInt32 value
= wxMax( iValue
, 0 ) ;
2325 SInt32 maximum
= wxMax( iMaximumValue
, 0 ) ;
2327 if ( iScrollBarOrientation
== kTXNHorizontal
)
2329 if ( mlte
->m_sbHorizontal
)
2331 SetControl32BitValue( mlte
->m_sbHorizontal
, value
) ;
2332 SetControl32BitMaximum( mlte
->m_sbHorizontal
, maximum
) ;
2333 mlte
->m_lastHorizontalValue
= value
;
2336 else if ( iScrollBarOrientation
== kTXNVertical
)
2338 if ( mlte
->m_sbVertical
)
2340 SetControl32BitValue( mlte
->m_sbVertical
, value
) ;
2341 SetControl32BitMaximum( mlte
->m_sbVertical
, maximum
) ;
2342 mlte
->m_lastVerticalValue
= value
;
2347 pascal void wxMacMLTEClassicControl::TXNScrollActionProc( ControlRef controlRef
, ControlPartCode partCode
)
2349 wxMacMLTEClassicControl
* mlte
= (wxMacMLTEClassicControl
*) GetControlReference( controlRef
) ;
2353 if ( controlRef
!= mlte
->m_sbVertical
&& controlRef
!= mlte
->m_sbHorizontal
)
2357 bool isHorizontal
= ( controlRef
== mlte
->m_sbHorizontal
) ;
2359 SInt32 minimum
= 0 ;
2360 SInt32 maximum
= GetControl32BitMaximum( controlRef
) ;
2361 SInt32 value
= GetControl32BitValue( controlRef
) ;
2366 case kControlDownButtonPart
:
2370 case kControlUpButtonPart
:
2374 case kControlPageDownPart
:
2375 delta
= GetControlViewSize( controlRef
) ;
2378 case kControlPageUpPart
:
2379 delta
= -GetControlViewSize( controlRef
) ;
2382 case kControlIndicatorPart
:
2383 delta
= value
- (isHorizontal
? mlte
->m_lastHorizontalValue
: mlte
->m_lastVerticalValue
) ;
2392 SInt32 newValue
= value
;
2394 if ( partCode
!= kControlIndicatorPart
)
2396 if ( value
+ delta
< minimum
)
2397 delta
= minimum
- value
;
2398 if ( value
+ delta
> maximum
)
2399 delta
= maximum
- value
;
2401 SetControl32BitValue( controlRef
, value
+ delta
) ;
2402 newValue
= value
+ delta
;
2405 SInt32 verticalDelta
= isHorizontal
? 0 : delta
;
2406 SInt32 horizontalDelta
= isHorizontal
? delta
: 0 ;
2409 mlte
->m_txn
, kTXNScrollUnitsInPixels
, kTXNScrollUnitsInPixels
,
2410 &verticalDelta
, &horizontalDelta
);
2411 verify_noerr( err
);
2414 mlte
->m_lastHorizontalValue
= newValue
;
2416 mlte
->m_lastVerticalValue
= newValue
;
2421 // make correct activations
2422 void wxMacMLTEClassicControl::MacActivatePaneText(bool setActive
)
2424 wxTextCtrl
* textctrl
= (wxTextCtrl
*) GetControlReference(m_controlRef
);
2426 wxMacWindowClipper
clipper( textctrl
) ;
2427 TXNActivate( m_txn
, m_txnFrameID
, setActive
);
2429 ControlRef controlFocus
= 0 ;
2430 GetKeyboardFocus( m_txnWindow
, &controlFocus
) ;
2431 if ( controlFocus
== m_controlRef
)
2432 TXNFocus( m_txn
, setActive
);
2435 void wxMacMLTEClassicControl::MacFocusPaneText(bool setFocus
)
2437 TXNFocus( m_txn
, setFocus
);
2440 // guards against inappropriate redraw (hidden objects drawing onto window)
2442 void wxMacMLTEClassicControl::MacSetObjectVisibility(bool vis
)
2444 ControlRef controlFocus
= 0 ;
2445 GetKeyboardFocus( m_txnWindow
, &controlFocus
) ;
2447 if ( !vis
&& (controlFocus
== m_controlRef
) )
2448 SetKeyboardFocus( m_txnWindow
, m_controlRef
, kControlFocusNoPart
) ;
2450 TXNControlTag iControlTags
[1] = { kTXNVisibilityTag
};
2451 TXNControlData iControlData
[1] = { { (UInt32
)false } };
2453 verify_noerr( TXNGetTXNObjectControls( m_txn
, 1, iControlTags
, iControlData
) ) ;
2455 if ( iControlData
[0].uValue
!= vis
)
2457 iControlData
[0].uValue
= vis
;
2458 verify_noerr( TXNSetTXNObjectControls( m_txn
, false , 1, iControlTags
, iControlData
) ) ;
2461 // currently, we always clip as partial visibility (overlapped) visibility is also a problem,
2462 // if we run into further problems we might set the FrameBounds to an empty rect here
2465 // make sure that the TXNObject is at the right position
2467 void wxMacMLTEClassicControl::MacUpdatePosition()
2469 wxTextCtrl
* textctrl
= (wxTextCtrl
*)GetControlReference( m_controlRef
);
2470 if ( textctrl
== NULL
)
2474 UMAGetControlBoundsInWindowCoords( m_controlRef
, &bounds
);
2476 wxRect visRect
= textctrl
->MacGetClippedClientRect() ;
2477 Rect visBounds
= { visRect
.y
, visRect
.x
, visRect
.y
+ visRect
.height
, visRect
.x
+ visRect
.width
} ;
2480 textctrl
->MacWindowToRootWindow( &x
, &y
) ;
2481 OffsetRect( &visBounds
, x
, y
) ;
2483 if ( !EqualRect( &bounds
, &m_txnControlBounds
) || !EqualRect( &visBounds
, &m_txnVisBounds
) )
2485 m_txnControlBounds
= bounds
;
2486 m_txnVisBounds
= visBounds
;
2487 wxMacWindowClipper
cl( textctrl
) ;
2489 #ifdef __WXMAC_OSX__
2490 if ( m_sbHorizontal
|| m_sbVertical
)
2492 int w
= bounds
.right
- bounds
.left
;
2493 int h
= bounds
.bottom
- bounds
.top
;
2495 if ( m_sbHorizontal
)
2499 sbBounds
.left
= -1 ;
2500 sbBounds
.top
= h
- 14 ;
2501 sbBounds
.right
= w
+ 1 ;
2502 sbBounds
.bottom
= h
+ 1 ;
2504 SetControlBounds( m_sbHorizontal
, &sbBounds
) ;
2505 SetControlViewSize( m_sbHorizontal
, w
) ;
2512 sbBounds
.left
= w
- 14 ;
2514 sbBounds
.right
= w
+ 1 ;
2515 sbBounds
.bottom
= m_sbHorizontal
? h
- 14 : h
+ 1 ;
2517 SetControlBounds( m_sbVertical
, &sbBounds
) ;
2518 SetControlViewSize( m_sbVertical
, h
) ;
2523 TXNLongRect olddestRect
;
2524 TXNGetRectBounds( m_txn
, &oldviewRect
, &olddestRect
, NULL
) ;
2526 Rect viewRect
= { m_txnControlBounds
.top
, m_txnControlBounds
.left
,
2527 m_txnControlBounds
.bottom
- ( m_sbHorizontal
? 14 : 0 ) ,
2528 m_txnControlBounds
.right
- ( m_sbVertical
? 14 : 0 ) } ;
2529 TXNLongRect destRect
= { m_txnControlBounds
.top
, m_txnControlBounds
.left
,
2530 m_txnControlBounds
.bottom
- ( m_sbHorizontal
? 14 : 0 ) ,
2531 m_txnControlBounds
.right
- ( m_sbVertical
? 14 : 0 ) } ;
2533 if ( olddestRect
.right
>= 10000 )
2534 destRect
.right
= destRect
.left
+ 32000 ;
2536 if ( olddestRect
.bottom
>= 0x20000000 )
2537 destRect
.bottom
= destRect
.top
+ 0x40000000 ;
2539 SectRect( &viewRect
, &visBounds
, &viewRect
) ;
2540 TXNSetRectBounds( m_txn
, &viewRect
, &destRect
, true ) ;
2545 m_txnControlBounds
.top
,
2546 m_txnControlBounds
.left
,
2547 m_txnControlBounds
.bottom
- (m_sbHorizontal
? 14 : 0),
2548 m_txnControlBounds
.right
- (m_sbVertical
? 14 : 0),
2554 m_txn
, m_txnControlBounds
.top
, m_txnControlBounds
.left
,
2555 wxMax( m_txnControlBounds
.bottom
, m_txnControlBounds
.top
),
2556 wxMax( m_txnControlBounds
.right
, m_txnControlBounds
.left
), m_txnFrameID
);
2559 // the SetFrameBounds method under Classic sometimes does not correctly scroll a selection into sight after a
2560 // movement, therefore we have to force it
2562 // this problem has been reported in OSX as well, so we use this here once again
2564 TXNLongRect textRect
;
2565 TXNGetRectBounds( m_txn
, NULL
, NULL
, &textRect
) ;
2566 if ( textRect
.left
< m_txnControlBounds
.left
)
2567 TXNShowSelection( m_txn
, kTXNShowStart
) ;
2571 void wxMacMLTEClassicControl::SetRect( Rect
*r
)
2573 wxMacControl::SetRect( r
) ;
2574 MacUpdatePosition() ;
2577 void wxMacMLTEClassicControl::MacControlUserPaneDrawProc(wxInt16 thePart
)
2579 wxTextCtrl
* textctrl
= (wxTextCtrl
*)GetControlReference( m_controlRef
);
2580 if ( textctrl
== NULL
)
2583 if ( textctrl
->MacIsReallyShown() )
2585 wxMacWindowClipper
clipper( textctrl
) ;
2586 TXNDraw( m_txn
, NULL
) ;
2590 wxInt16
wxMacMLTEClassicControl::MacControlUserPaneHitTestProc(wxInt16 x
, wxInt16 y
)
2592 Point where
= { y
, x
} ;
2593 ControlPartCode result
= kControlNoPart
;
2595 wxTextCtrl
* textctrl
= (wxTextCtrl
*) GetControlReference( m_controlRef
);
2596 if ( (textctrl
!= NULL
) && textctrl
->MacIsReallyShown() )
2598 if (PtInRect( where
, &m_txnControlBounds
))
2600 result
= kControlEditTextPart
;
2604 // sometimes we get the coords also in control local coordinates, therefore test again
2606 textctrl
->MacClientToRootWindow( &x
, &y
) ;
2610 if (PtInRect( where
, &m_txnControlBounds
))
2611 result
= kControlEditTextPart
;
2618 wxInt16
wxMacMLTEClassicControl::MacControlUserPaneTrackingProc( wxInt16 x
, wxInt16 y
, void* actionProc
)
2620 ControlPartCode result
= kControlNoPart
;
2622 wxTextCtrl
* textctrl
= (wxTextCtrl
*) GetControlReference( m_controlRef
);
2623 if ( (textctrl
!= NULL
) && textctrl
->MacIsReallyShown() )
2625 Point startPt
= { y
, x
} ;
2627 // for compositing, we must convert these into toplevel window coordinates, because hittesting expects them
2629 textctrl
->MacClientToRootWindow( &x
, &y
) ;
2633 switch (MacControlUserPaneHitTestProc( startPt
.h
, startPt
.v
))
2635 case kControlEditTextPart
:
2637 wxMacWindowClipper
clipper( textctrl
) ;
2640 ConvertEventRefToEventRecord( (EventRef
) wxTheApp
->MacGetCurrentEvent() , &rec
) ;
2641 TXNClick( m_txn
, &rec
);
2653 void wxMacMLTEClassicControl::MacControlUserPaneIdleProc()
2655 wxTextCtrl
* textctrl
= (wxTextCtrl
*)GetControlReference( m_controlRef
);
2656 if ( textctrl
== NULL
)
2659 if (textctrl
->MacIsReallyShown())
2661 if (IsControlActive(m_controlRef
))
2665 wxMacWindowClipper
clipper( textctrl
) ;
2670 if (PtInRect(mousep
, &m_txnControlBounds
))
2672 RgnHandle theRgn
= NewRgn();
2673 RectRgn(theRgn
, &m_txnControlBounds
);
2674 TXNAdjustCursor(m_txn
, theRgn
);
2681 wxInt16
wxMacMLTEClassicControl::MacControlUserPaneKeyDownProc (wxInt16 keyCode
, wxInt16 charCode
, wxInt16 modifiers
)
2683 wxTextCtrl
* textctrl
= (wxTextCtrl
*)GetControlReference( m_controlRef
);
2684 if ( textctrl
== NULL
)
2685 return kControlNoPart
;
2687 wxMacWindowClipper
clipper( textctrl
) ;
2690 memset( &ev
, 0 , sizeof( ev
) ) ;
2692 ev
.modifiers
= modifiers
;
2693 ev
.message
= ((keyCode
<< 8) & keyCodeMask
) | (charCode
& charCodeMask
);
2694 TXNKeyDown( m_txn
, &ev
);
2696 return kControlEntireControl
;
2699 void wxMacMLTEClassicControl::MacControlUserPaneActivateProc(bool activating
)
2701 MacActivatePaneText( activating
);
2704 wxInt16
wxMacMLTEClassicControl::MacControlUserPaneFocusProc(wxInt16 action
)
2706 ControlPartCode focusResult
= kControlFocusNoPart
;
2708 wxTextCtrl
* textctrl
= (wxTextCtrl
*)GetControlReference( m_controlRef
);
2709 if ( textctrl
== NULL
)
2712 wxMacWindowClipper
clipper( textctrl
) ;
2714 ControlRef controlFocus
= NULL
;
2715 GetKeyboardFocus( m_txnWindow
, &controlFocus
) ;
2716 bool wasFocused
= ( controlFocus
== m_controlRef
) ;
2720 case kControlFocusPrevPart
:
2721 case kControlFocusNextPart
:
2722 MacFocusPaneText( !wasFocused
);
2723 focusResult
= (!wasFocused
? (ControlPartCode
) kControlEditTextPart
: (ControlPartCode
) kControlFocusNoPart
);
2726 case kControlFocusNoPart
:
2728 MacFocusPaneText( false );
2729 focusResult
= kControlFocusNoPart
;
2736 void wxMacMLTEClassicControl::MacControlUserPaneBackgroundProc( void *info
)
2740 wxMacMLTEClassicControl::wxMacMLTEClassicControl( wxTextCtrl
*wxPeer
,
2741 const wxString
& str
,
2743 const wxSize
& size
, long style
)
2744 : wxMacMLTEControl( wxPeer
)
2746 m_font
= wxPeer
->GetFont() ;
2747 m_windowStyle
= style
;
2748 Rect bounds
= wxMacGetBoundsForControl( wxPeer
, pos
, size
) ;
2751 kControlSupportsEmbedding
| kControlSupportsFocus
| kControlWantsIdle
2752 | kControlWantsActivate
| kControlHandlesTracking
2753 // | kControlHasSpecialBackground
2754 | kControlGetsFocusOnClick
| kControlSupportsLiveFeedback
;
2756 OSStatus err
= ::CreateUserPaneControl(
2757 MAC_WXHWND(wxPeer
->GetParent()->MacGetTopLevelWindowRef()),
2758 &bounds
, featureSet
, &m_controlRef
);
2759 verify_noerr( err
);
2763 AdjustCreationAttributes( *wxWHITE
, true ) ;
2765 MacSetObjectVisibility( wxPeer
->MacIsReallyShown() ) ;
2769 wxMacConvertNewlines10To13( &st
) ;
2770 wxMacWindowClipper
clipper( m_peer
) ;
2771 SetTXNData( st
, kTXNStartOffset
, kTXNEndOffset
) ;
2772 TXNSetSelection( m_txn
, 0, 0 ) ;
2776 wxMacMLTEClassicControl::~wxMacMLTEClassicControl()
2778 TXNDeleteObject( m_txn
);
2782 void wxMacMLTEClassicControl::VisibilityChanged(bool shown
)
2784 MacSetObjectVisibility( shown
) ;
2785 wxMacControl::VisibilityChanged( shown
) ;
2788 void wxMacMLTEClassicControl::SuperChangedPosition()
2790 MacUpdatePosition() ;
2791 wxMacControl::SuperChangedPosition() ;
2794 #ifdef __WXMAC_OSX__
2796 ControlUserPaneDrawUPP gTPDrawProc
= NULL
;
2797 ControlUserPaneHitTestUPP gTPHitProc
= NULL
;
2798 ControlUserPaneTrackingUPP gTPTrackProc
= NULL
;
2799 ControlUserPaneIdleUPP gTPIdleProc
= NULL
;
2800 ControlUserPaneKeyDownUPP gTPKeyProc
= NULL
;
2801 ControlUserPaneActivateUPP gTPActivateProc
= NULL
;
2802 ControlUserPaneFocusUPP gTPFocusProc
= NULL
;
2804 static pascal void wxMacControlUserPaneDrawProc(ControlRef control
, SInt16 part
)
2806 wxTextCtrl
*textCtrl
= wxDynamicCast( wxFindControlFromMacControl(control
) , wxTextCtrl
) ;
2807 wxMacMLTEClassicControl
* win
= textCtrl
? (wxMacMLTEClassicControl
*)(textCtrl
->GetPeer()) : NULL
;
2809 win
->MacControlUserPaneDrawProc( part
) ;
2812 static pascal ControlPartCode
wxMacControlUserPaneHitTestProc(ControlRef control
, Point where
)
2814 wxTextCtrl
*textCtrl
= wxDynamicCast( wxFindControlFromMacControl(control
) , wxTextCtrl
) ;
2815 wxMacMLTEClassicControl
* win
= textCtrl
? (wxMacMLTEClassicControl
*)(textCtrl
->GetPeer()) : NULL
;
2817 return win
->MacControlUserPaneHitTestProc( where
.h
, where
.v
) ;
2819 return kControlNoPart
;
2822 static pascal ControlPartCode
wxMacControlUserPaneTrackingProc(ControlRef control
, Point startPt
, ControlActionUPP actionProc
)
2824 wxTextCtrl
*textCtrl
= wxDynamicCast( wxFindControlFromMacControl(control
) , wxTextCtrl
) ;
2825 wxMacMLTEClassicControl
* win
= textCtrl
? (wxMacMLTEClassicControl
*)(textCtrl
->GetPeer()) : NULL
;
2827 return win
->MacControlUserPaneTrackingProc( startPt
.h
, startPt
.v
, (void*) actionProc
) ;
2829 return kControlNoPart
;
2832 static pascal void wxMacControlUserPaneIdleProc(ControlRef control
)
2834 wxTextCtrl
*textCtrl
= wxDynamicCast( wxFindControlFromMacControl(control
) , wxTextCtrl
) ;
2835 wxMacMLTEClassicControl
* win
= textCtrl
? (wxMacMLTEClassicControl
*)(textCtrl
->GetPeer()) : NULL
;
2837 win
->MacControlUserPaneIdleProc() ;
2840 static pascal ControlPartCode
wxMacControlUserPaneKeyDownProc(ControlRef control
, SInt16 keyCode
, SInt16 charCode
, SInt16 modifiers
)
2842 wxTextCtrl
*textCtrl
= wxDynamicCast( wxFindControlFromMacControl(control
) , wxTextCtrl
) ;
2843 wxMacMLTEClassicControl
* win
= textCtrl
? (wxMacMLTEClassicControl
*)(textCtrl
->GetPeer()) : NULL
;
2845 return win
->MacControlUserPaneKeyDownProc( keyCode
, charCode
, modifiers
) ;
2847 return kControlNoPart
;
2850 static pascal void wxMacControlUserPaneActivateProc(ControlRef control
, Boolean activating
)
2852 wxTextCtrl
*textCtrl
= wxDynamicCast( wxFindControlFromMacControl(control
) , wxTextCtrl
) ;
2853 wxMacMLTEClassicControl
* win
= textCtrl
? (wxMacMLTEClassicControl
*)(textCtrl
->GetPeer()) : NULL
;
2855 win
->MacControlUserPaneActivateProc( activating
) ;
2858 static pascal ControlPartCode
wxMacControlUserPaneFocusProc(ControlRef control
, ControlFocusPart action
)
2860 wxTextCtrl
*textCtrl
= wxDynamicCast( wxFindControlFromMacControl(control
) , wxTextCtrl
) ;
2861 wxMacMLTEClassicControl
* win
= textCtrl
? (wxMacMLTEClassicControl
*)(textCtrl
->GetPeer()) : NULL
;
2863 return win
->MacControlUserPaneFocusProc( action
) ;
2865 return kControlNoPart
;
2869 static pascal void wxMacControlUserPaneBackgroundProc(ControlRef control
, ControlBackgroundPtr info
)
2871 wxTextCtrl
*textCtrl
= wxDynamicCast( wxFindControlFromMacControl(control
) , wxTextCtrl
) ;
2872 wxMacMLTEClassicControl
* win
= textCtrl
? (wxMacMLTEClassicControl
*)(textCtrl
->GetPeer()) : NULL
;
2874 win
->MacControlUserPaneBackgroundProc(info
) ;
2878 #endif // __WXMAC_OSX__
2880 // TXNRegisterScrollInfoProc
2882 OSStatus
wxMacMLTEClassicControl::DoCreate()
2885 OSStatus err
= noErr
;
2887 // set up our globals
2888 #ifdef __WXMAC_OSX__
2889 if (gTPDrawProc
== NULL
) gTPDrawProc
= NewControlUserPaneDrawUPP(wxMacControlUserPaneDrawProc
);
2890 if (gTPHitProc
== NULL
) gTPHitProc
= NewControlUserPaneHitTestUPP(wxMacControlUserPaneHitTestProc
);
2891 if (gTPTrackProc
== NULL
) gTPTrackProc
= NewControlUserPaneTrackingUPP(wxMacControlUserPaneTrackingProc
);
2892 if (gTPIdleProc
== NULL
) gTPIdleProc
= NewControlUserPaneIdleUPP(wxMacControlUserPaneIdleProc
);
2893 if (gTPKeyProc
== NULL
) gTPKeyProc
= NewControlUserPaneKeyDownUPP(wxMacControlUserPaneKeyDownProc
);
2894 if (gTPActivateProc
== NULL
) gTPActivateProc
= NewControlUserPaneActivateUPP(wxMacControlUserPaneActivateProc
);
2895 if (gTPFocusProc
== NULL
) gTPFocusProc
= NewControlUserPaneFocusUPP(wxMacControlUserPaneFocusProc
);
2897 if (gTXNScrollInfoProc
== NULL
) gTXNScrollInfoProc
= NewTXNScrollInfoUPP(TXNScrollInfoProc
) ;
2898 if (gTXNScrollActionProc
== NULL
) gTXNScrollActionProc
= NewControlActionUPP(TXNScrollActionProc
) ;
2901 // set the initial settings for our private data
2903 m_txnWindow
= GetControlOwner(m_controlRef
);
2904 m_txnPort
= (GrafPtr
) GetWindowPort(m_txnWindow
);
2906 #ifdef __WXMAC_OSX__
2907 // set up the user pane procedures
2908 SetControlData(m_controlRef
, kControlEntireControl
, kControlUserPaneDrawProcTag
, sizeof(gTPDrawProc
), &gTPDrawProc
);
2909 SetControlData(m_controlRef
, kControlEntireControl
, kControlUserPaneHitTestProcTag
, sizeof(gTPHitProc
), &gTPHitProc
);
2910 SetControlData(m_controlRef
, kControlEntireControl
, kControlUserPaneTrackingProcTag
, sizeof(gTPTrackProc
), &gTPTrackProc
);
2911 SetControlData(m_controlRef
, kControlEntireControl
, kControlUserPaneIdleProcTag
, sizeof(gTPIdleProc
), &gTPIdleProc
);
2912 SetControlData(m_controlRef
, kControlEntireControl
, kControlUserPaneKeyDownProcTag
, sizeof(gTPKeyProc
), &gTPKeyProc
);
2913 SetControlData(m_controlRef
, kControlEntireControl
, kControlUserPaneActivateProcTag
, sizeof(gTPActivateProc
), &gTPActivateProc
);
2914 SetControlData(m_controlRef
, kControlEntireControl
, kControlUserPaneFocusProcTag
, sizeof(gTPFocusProc
), &gTPFocusProc
);
2917 // calculate the rectangles used by the control
2918 UMAGetControlBoundsInWindowCoords( m_controlRef
, &bounds
);
2920 m_txnControlBounds
= bounds
;
2921 m_txnVisBounds
= bounds
;
2926 GetGWorld( &origPort
, &origDev
) ;
2927 SetPort( m_txnPort
);
2929 // create the new edit field
2930 TXNFrameOptions frameOptions
= FrameOptionsFromWXStyle( m_windowStyle
);
2932 #ifdef __WXMAC_OSX__
2933 // the scrollbars are not correctly embedded but are inserted at the root:
2934 // this gives us problems as we have erratic redraws even over the structure area
2936 m_sbHorizontal
= 0 ;
2938 m_lastHorizontalValue
= 0 ;
2939 m_lastVerticalValue
= 0 ;
2941 Rect sb
= { 0 , 0 , 0 , 0 } ;
2942 if ( frameOptions
& kTXNWantVScrollBarMask
)
2944 CreateScrollBarControl( m_txnWindow
, &sb
, 0, 0, 100, 1, true, gTXNScrollActionProc
, &m_sbVertical
);
2945 SetControlReference( m_sbVertical
, (SInt32
)this );
2946 SetControlAction( m_sbVertical
, gTXNScrollActionProc
);
2947 ShowControl( m_sbVertical
);
2948 EmbedControl( m_sbVertical
, m_controlRef
);
2949 frameOptions
&= ~kTXNWantVScrollBarMask
;
2952 if ( frameOptions
& kTXNWantHScrollBarMask
)
2954 CreateScrollBarControl( m_txnWindow
, &sb
, 0, 0, 100, 1, true, gTXNScrollActionProc
, &m_sbHorizontal
);
2955 SetControlReference( m_sbHorizontal
, (SInt32
)this );
2956 SetControlAction( m_sbHorizontal
, gTXNScrollActionProc
);
2957 ShowControl( m_sbHorizontal
);
2958 EmbedControl( m_sbHorizontal
, m_controlRef
);
2959 frameOptions
&= ~(kTXNWantHScrollBarMask
| kTXNDrawGrowIconMask
);
2965 NULL
, m_txnWindow
, &bounds
, frameOptions
,
2966 kTXNTextEditStyleFrameType
, kTXNTextensionFile
, kTXNSystemDefaultEncoding
,
2967 &m_txn
, &m_txnFrameID
, NULL
);
2968 verify_noerr( err
);
2971 TXNControlTag iControlTags
[] = { kTXNUseCarbonEvents
};
2972 TXNControlData iControlData
[] = { { (UInt32
)&cInfo
} };
2973 int toptag
= WXSIZEOF( iControlTags
) ;
2974 TXNCarbonEventInfo cInfo
;
2975 cInfo
.useCarbonEvents
= false ;
2978 cInfo
.fDictionary
= NULL
;
2980 verify_noerr( TXNSetTXNObjectControls( m_txn
, false, toptag
, iControlTags
, iControlData
) );
2983 #ifdef __WXMAC_OSX__
2984 TXNRegisterScrollInfoProc( m_txn
, gTXNScrollInfoProc
, (SInt32
)this );
2987 SetGWorld( origPort
, origDev
) ;
2992 // ----------------------------------------------------------------------------
2993 // MLTE control implementation (OSX part)
2994 // ----------------------------------------------------------------------------
2996 #if TARGET_API_MAC_OSX
2998 #if MAC_OS_X_VERSION_MAX_ALLOWED > MAC_OS_X_VERSION_10_2
3000 // tiger multi-line textcontrols with no CR in the entire content
3001 // don't scroll automatically, so we need a hack.
3002 // This attempt only works 'before' the key (ie before CallNextEventHandler)
3003 // is processed, thus the scrolling always occurs one character too late, but
3004 // better than nothing ...
3006 static const EventTypeSpec eventList
[] =
3008 { kEventClassTextInput
, kEventTextInputUnicodeForKeyEvent
} ,
3011 static pascal OSStatus
wxMacUnicodeTextEventHandler( EventHandlerCallRef handler
, EventRef event
, void *data
)
3013 OSStatus result
= eventNotHandledErr
;
3014 wxMacMLTEHIViewControl
* focus
= (wxMacMLTEHIViewControl
*) data
;
3016 switch ( GetEventKind( event
) )
3018 case kEventTextInputUnicodeForKeyEvent
:
3020 if ( UMAGetSystemVersion() >= 0x1040 )
3022 TXNOffset from
, to
;
3023 TXNGetSelection( focus
->GetTXNObject() , &from
, &to
) ;
3025 TXNShowSelection( focus
->GetTXNObject() , kTXNShowStart
);
3027 result
= CallNextEventHandler(handler
,event
);
3037 static pascal OSStatus
wxMacTextControlEventHandler( EventHandlerCallRef handler
, EventRef event
, void *data
)
3039 OSStatus result
= eventNotHandledErr
;
3041 switch ( GetEventClass( event
) )
3043 case kEventClassTextInput
:
3044 result
= wxMacUnicodeTextEventHandler( handler
, event
, data
) ;
3053 DEFINE_ONE_SHOT_HANDLER_GETTER( wxMacTextControlEventHandler
)
3055 wxMacMLTEHIViewControl::wxMacMLTEHIViewControl( wxTextCtrl
*wxPeer
,
3056 const wxString
& str
,
3058 const wxSize
& size
, long style
) : wxMacMLTEControl( wxPeer
)
3060 m_font
= wxPeer
->GetFont() ;
3061 m_windowStyle
= style
;
3062 Rect bounds
= wxMacGetBoundsForControl( wxPeer
, pos
, size
) ;
3064 wxMacConvertNewlines10To13( &st
) ;
3067 { bounds
.left
, bounds
.top
},
3068 { bounds
.right
- bounds
.left
, bounds
.bottom
- bounds
.top
} } ;
3070 m_scrollView
= NULL
;
3071 TXNFrameOptions frameOptions
= FrameOptionsFromWXStyle( style
) ;
3072 if ( frameOptions
& (kTXNWantVScrollBarMask
| kTXNWantHScrollBarMask
) )
3075 (frameOptions
& kTXNWantHScrollBarMask
? kHIScrollViewOptionsHorizScroll
: 0)
3076 | (frameOptions
& kTXNWantVScrollBarMask
? kHIScrollViewOptionsVertScroll
: 0) ,
3079 HIViewSetFrame( m_scrollView
, &hr
);
3080 HIViewSetVisible( m_scrollView
, true );
3084 HITextViewCreate( NULL
, 0, frameOptions
, &m_textView
) ;
3085 m_txn
= HITextViewGetTXNObject( m_textView
) ;
3086 HIViewSetVisible( m_textView
, true ) ;
3089 HIViewAddSubview( m_scrollView
, m_textView
) ;
3090 m_controlRef
= m_scrollView
;
3091 wxPeer
->MacInstallEventHandler( (WXWidget
) m_textView
) ;
3095 HIViewSetFrame( m_textView
, &hr
);
3096 m_controlRef
= m_textView
;
3099 AdjustCreationAttributes( *wxWHITE
, true ) ;
3101 wxMacWindowClipper
c( m_peer
) ;
3102 SetTXNData( st
, kTXNStartOffset
, kTXNEndOffset
) ;
3104 TXNSetSelection( m_txn
, 0, 0 );
3105 TXNShowSelection( m_txn
, kTXNShowStart
);
3107 InstallControlEventHandler( m_textView
, GetwxMacTextControlEventHandlerUPP(),
3108 GetEventTypeCount(eventList
), eventList
, this,
3109 &m_textEventHandlerRef
);
3112 wxMacMLTEHIViewControl::~wxMacMLTEHIViewControl()
3114 ::RemoveEventHandler( m_textEventHandlerRef
) ;
3117 OSStatus
wxMacMLTEHIViewControl::SetFocus( ControlFocusPart focusPart
)
3119 return SetKeyboardFocus( GetControlOwner( m_textView
), m_textView
, focusPart
) ;
3122 bool wxMacMLTEHIViewControl::HasFocus() const
3124 ControlRef control
;
3125 GetKeyboardFocus( GetUserFocusWindow() , &control
) ;
3126 return control
== m_textView
;
3129 void wxMacMLTEHIViewControl::SetBackground( const wxBrush
&brush
)
3131 wxMacMLTEControl::SetBackground( brush
) ;
3134 CGColorSpaceRef rgbSpace
= CGColorSpaceCreateDeviceRGB();
3135 RGBColor col
= MAC_WXCOLORREF(brush
.GetColour().GetPixel()) ;
3137 float component
[4] ;
3138 component
[0] = col
.red
/ 65536.0 ;
3139 component
[1] = col
.green
/ 65536.0 ;
3140 component
[2] = col
.blue
/ 65536.0 ;
3141 component
[3] = 1.0 ; // alpha
3143 CGColorRef color
= CGColorCreate( rgbSpace
, component
);
3144 HITextViewSetBackgroundColor( m_textView
, color
);
3145 CGColorSpaceRelease( rgbSpace
);
3149 #endif // MAC_OS_X_VERSION_MAX_ALLOWED > MAC_OS_X_VERSION_10_2
3154 #endif // wxUSE_TEXTCTRL