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 void wxTextCtrl::WriteText(const wxString
& str
)
710 // TODO: this MPRemoting will be moved into a remoting peer proxy for any command
711 if ( !wxIsMainThread() )
713 // unfortunately CW 8 is not able to correctly deduce the template types,
714 // so we have to instantiate explicitly
715 wxMacMPRemoteGUICall
<wxTextCtrl
,wxString
>( this , &wxTextCtrl::WriteText
, str
) ;
720 GetPeer()->WriteText( str
) ;
723 void wxTextCtrl::AppendText(const wxString
& text
)
725 SetInsertionPointEnd();
729 void wxTextCtrl::Clear()
734 bool wxTextCtrl::IsModified() const
739 bool wxTextCtrl::IsEditable() const
741 return IsEnabled() && m_editable
;
744 bool wxTextCtrl::AcceptsFocus() const
746 // we don't want focus if we can't be edited
747 return /*IsEditable() && */ wxControl::AcceptsFocus();
750 wxSize
wxTextCtrl::DoGetBestSize() const
754 // these are the numbers from the HIG:
755 // we reduce them by the borders first
758 switch ( m_windowVariant
)
760 case wxWINDOW_VARIANT_NORMAL
:
764 case wxWINDOW_VARIANT_SMALL
:
768 case wxWINDOW_VARIANT_MINI
:
777 // as the above numbers have some free space around the text
778 // we get 5 lines like this anyway
779 if ( m_windowStyle
& wxTE_MULTILINE
)
782 if ( !HasFlag(wxNO_BORDER
) )
785 return wxSize(wText
, hText
);
788 // ----------------------------------------------------------------------------
790 // ----------------------------------------------------------------------------
792 void wxTextCtrl::Undo()
798 void wxTextCtrl::Redo()
804 bool wxTextCtrl::CanUndo() const
809 return GetPeer()->CanUndo() ;
812 bool wxTextCtrl::CanRedo() const
817 return GetPeer()->CanRedo() ;
820 void wxTextCtrl::MarkDirty()
825 void wxTextCtrl::DiscardEdits()
830 int wxTextCtrl::GetNumberOfLines() const
832 return GetPeer()->GetNumberOfLines() ;
835 long wxTextCtrl::XYToPosition(long x
, long y
) const
837 return GetPeer()->XYToPosition( x
, y
) ;
840 bool wxTextCtrl::PositionToXY(long pos
, long *x
, long *y
) const
842 return GetPeer()->PositionToXY( pos
, x
, y
) ;
845 void wxTextCtrl::ShowPosition(long pos
)
847 return GetPeer()->ShowPosition(pos
) ;
850 int wxTextCtrl::GetLineLength(long lineNo
) const
852 return GetPeer()->GetLineLength(lineNo
) ;
855 wxString
wxTextCtrl::GetLineText(long lineNo
) const
857 return GetPeer()->GetLineText(lineNo
) ;
860 void wxTextCtrl::Command(wxCommandEvent
& event
)
862 SetValue(event
.GetString());
863 ProcessCommand(event
);
866 void wxTextCtrl::OnDropFiles(wxDropFilesEvent
& event
)
868 // By default, load the first file into the text window.
869 if (event
.GetNumberOfFiles() > 0)
870 LoadFile( event
.GetFiles()[0] );
873 void wxTextCtrl::OnEraseBackground(wxEraseEvent
& event
)
875 // all erasing should be done by the real mac control implementation
876 // while this is true for MLTE under classic, the HITextView is somehow
877 // transparent but background erase is not working correctly, so intercept
878 // things while we can...
882 void wxTextCtrl::OnChar(wxKeyEvent
& event
)
884 int key
= event
.GetKeyCode() ;
885 bool eat_key
= false ;
887 if ( key
== 'a' && event
.MetaDown() )
894 if ( key
== 'c' && event
.MetaDown() )
902 if ( !IsEditable() && key
!= WXK_LEFT
&& key
!= WXK_RIGHT
&& key
!= WXK_DOWN
&& key
!= WXK_UP
&& key
!= WXK_TAB
&&
903 !( key
== WXK_RETURN
&& ( (m_windowStyle
& wxTE_PROCESS_ENTER
) || (m_windowStyle
& wxTE_MULTILINE
) ) )
904 // && key != WXK_PAGEUP && key != WXK_PAGEDOWN && key != WXK_HOME && key != WXK_END
911 // Check if we have reached the max # of chars (if it is set), but still
912 // allow navigation and deletion
913 if ( !IsMultiLine() && m_maxLength
&& GetValue().length() >= m_maxLength
&&
914 key
!= WXK_LEFT
&& key
!= WXK_RIGHT
&& key
!= WXK_TAB
&&
915 key
!= WXK_BACK
&& !( key
== WXK_RETURN
&& (m_windowStyle
& wxTE_PROCESS_ENTER
) )
918 // eat it, we don't want to add more than allowed # of characters
920 // TODO: generate EVT_TEXT_MAXLEN()
924 // assume that any key not processed yet is going to modify the control
927 if ( key
== 'v' && event
.MetaDown() )
935 if ( key
== 'x' && event
.MetaDown() )
946 if (m_windowStyle
& wxTE_PROCESS_ENTER
)
948 wxCommandEvent
event(wxEVT_COMMAND_TEXT_ENTER
, m_windowId
);
949 event
.SetEventObject( this );
950 event
.SetString( GetValue() );
951 if ( GetEventHandler()->ProcessEvent(event
) )
955 if ( !(m_windowStyle
& wxTE_MULTILINE
) )
957 wxTopLevelWindow
*tlw
= wxDynamicCast(wxGetTopLevelParent(this), wxTopLevelWindow
);
958 if ( tlw
&& tlw
->GetDefaultItem() )
960 wxButton
*def
= wxDynamicCast(tlw
->GetDefaultItem(), wxButton
);
961 if ( def
&& def
->IsEnabled() )
963 wxCommandEvent
event(wxEVT_COMMAND_BUTTON_CLICKED
, def
->GetId() );
964 event
.SetEventObject(def
);
971 // this will make wxWidgets eat the ENTER key so that
972 // we actually prevent line wrapping in a single line text control
978 if ( !(m_windowStyle
& wxTE_PROCESS_TAB
))
981 if (!event
.ShiftDown())
982 flags
|= wxNavigationKeyEvent::IsForward
;
983 if (event
.ControlDown())
984 flags
|= wxNavigationKeyEvent::WinChange
;
991 // This is necessary (don't know why);
992 // otherwise the tab will not be inserted.
993 WriteText(wxT("\t"));
1004 // perform keystroke handling
1008 if ( ( key
>= 0x20 && key
< WXK_START
) ||
1009 ( key
>= WXK_NUMPAD0
&& key
<= WXK_DIVIDE
) ||
1010 key
== WXK_RETURN
||
1011 key
== WXK_DELETE
||
1014 wxCommandEvent
event1(wxEVT_COMMAND_TEXT_UPDATED
, m_windowId
);
1015 event1
.SetEventObject( this );
1016 wxPostEvent( GetEventHandler(), event1
);
1020 // ----------------------------------------------------------------------------
1021 // standard handlers for standard edit menu events
1022 // ----------------------------------------------------------------------------
1024 void wxTextCtrl::OnCut(wxCommandEvent
& WXUNUSED(event
))
1029 void wxTextCtrl::OnCopy(wxCommandEvent
& WXUNUSED(event
))
1034 void wxTextCtrl::OnPaste(wxCommandEvent
& WXUNUSED(event
))
1039 void wxTextCtrl::OnUndo(wxCommandEvent
& WXUNUSED(event
))
1044 void wxTextCtrl::OnRedo(wxCommandEvent
& WXUNUSED(event
))
1049 void wxTextCtrl::OnDelete(wxCommandEvent
& WXUNUSED(event
))
1053 GetSelection( &from
, &to
);
1054 if (from
!= -1 && to
!= -1)
1058 void wxTextCtrl::OnSelectAll(wxCommandEvent
& WXUNUSED(event
))
1060 SetSelection(-1, -1);
1063 void wxTextCtrl::OnUpdateCut(wxUpdateUIEvent
& event
)
1065 event
.Enable( CanCut() );
1068 void wxTextCtrl::OnUpdateCopy(wxUpdateUIEvent
& event
)
1070 event
.Enable( CanCopy() );
1073 void wxTextCtrl::OnUpdatePaste(wxUpdateUIEvent
& event
)
1075 event
.Enable( CanPaste() );
1078 void wxTextCtrl::OnUpdateUndo(wxUpdateUIEvent
& event
)
1080 event
.Enable( CanUndo() );
1083 void wxTextCtrl::OnUpdateRedo(wxUpdateUIEvent
& event
)
1085 event
.Enable( CanRedo() );
1088 void wxTextCtrl::OnUpdateDelete(wxUpdateUIEvent
& event
)
1092 GetSelection( &from
, &to
);
1093 event
.Enable( from
!= -1 && to
!= -1 && from
!= to
&& IsEditable() ) ;
1096 void wxTextCtrl::OnUpdateSelectAll(wxUpdateUIEvent
& event
)
1098 event
.Enable(GetLastPosition() > 0);
1101 // CS: Context Menus only work with MLTE implementations or non-multiline HIViews at the moment
1103 void wxTextCtrl::OnContextMenu(wxContextMenuEvent
& event
)
1105 if ( GetPeer()->HasOwnContextMenu() )
1111 if (m_privateContextMenu
== NULL
)
1113 m_privateContextMenu
= new wxMenu
;
1114 m_privateContextMenu
->Append(wxID_UNDO
, _("&Undo"));
1115 m_privateContextMenu
->Append(wxID_REDO
, _("&Redo"));
1116 m_privateContextMenu
->AppendSeparator();
1117 m_privateContextMenu
->Append(wxID_CUT
, _("Cu&t"));
1118 m_privateContextMenu
->Append(wxID_COPY
, _("&Copy"));
1119 m_privateContextMenu
->Append(wxID_PASTE
, _("&Paste"));
1120 m_privateContextMenu
->Append(wxID_CLEAR
, _("&Delete"));
1121 m_privateContextMenu
->AppendSeparator();
1122 m_privateContextMenu
->Append(wxID_SELECTALL
, _("Select &All"));
1125 if (m_privateContextMenu
!= NULL
)
1126 PopupMenu(m_privateContextMenu
);
1129 bool wxTextCtrl::MacSetupCursor( const wxPoint
& pt
)
1131 if ( !GetPeer()->SetupCursor( pt
) )
1132 return wxWindow::MacSetupCursor( pt
) ;
1137 #if !TARGET_API_MAC_OSX
1139 // user pane implementation
1141 void wxTextCtrl::MacControlUserPaneDrawProc(wxInt16 part
)
1143 GetPeer()->MacControlUserPaneDrawProc( part
) ;
1146 wxInt16
wxTextCtrl::MacControlUserPaneHitTestProc(wxInt16 x
, wxInt16 y
)
1148 return GetPeer()->MacControlUserPaneHitTestProc( x
, y
) ;
1151 wxInt16
wxTextCtrl::MacControlUserPaneTrackingProc(wxInt16 x
, wxInt16 y
, void* actionProc
)
1153 return GetPeer()->MacControlUserPaneTrackingProc( x
, y
, actionProc
) ;
1156 void wxTextCtrl::MacControlUserPaneIdleProc()
1158 GetPeer()->MacControlUserPaneIdleProc( ) ;
1161 wxInt16
wxTextCtrl::MacControlUserPaneKeyDownProc(wxInt16 keyCode
, wxInt16 charCode
, wxInt16 modifiers
)
1163 return GetPeer()->MacControlUserPaneKeyDownProc( keyCode
, charCode
, modifiers
) ;
1166 void wxTextCtrl::MacControlUserPaneActivateProc(bool activating
)
1168 GetPeer()->MacControlUserPaneActivateProc( activating
) ;
1171 wxInt16
wxTextCtrl::MacControlUserPaneFocusProc(wxInt16 action
)
1173 return GetPeer()->MacControlUserPaneFocusProc( action
) ;
1176 void wxTextCtrl::MacControlUserPaneBackgroundProc(void* info
)
1178 GetPeer()->MacControlUserPaneBackgroundProc( info
) ;
1183 // ----------------------------------------------------------------------------
1184 // implementation base class
1185 // ----------------------------------------------------------------------------
1187 wxMacTextControl::wxMacTextControl(wxTextCtrl
* peer
) :
1188 wxMacControl( peer
)
1192 wxMacTextControl::~wxMacTextControl()
1196 void wxMacTextControl::SetStyle(long start
, long end
, const wxTextAttr
& style
)
1200 void wxMacTextControl::Copy()
1204 void wxMacTextControl::Cut()
1208 void wxMacTextControl::Paste()
1212 bool wxMacTextControl::CanPaste() const
1217 void wxMacTextControl::SetEditable(bool editable
)
1221 wxTextPos
wxMacTextControl::GetLastPosition() const
1223 return GetStringValue().length() ;
1226 void wxMacTextControl::Replace( long from
, long to
, const wxString
&val
)
1228 SetSelection( from
, to
) ;
1232 void wxMacTextControl::Remove( long from
, long to
)
1234 SetSelection( from
, to
) ;
1235 WriteText( wxEmptyString
) ;
1238 void wxMacTextControl::Clear()
1240 SetStringValue( wxEmptyString
) ;
1243 bool wxMacTextControl::CanUndo() const
1248 void wxMacTextControl::Undo()
1252 bool wxMacTextControl::CanRedo() const
1257 void wxMacTextControl::Redo()
1261 long wxMacTextControl::XYToPosition(long x
, long y
) const
1266 bool wxMacTextControl::PositionToXY(long pos
, long *x
, long *y
) const
1271 void wxMacTextControl::ShowPosition( long WXUNUSED(pos
) )
1275 int wxMacTextControl::GetNumberOfLines() const
1277 ItemCount lines
= 0 ;
1278 wxString content
= GetStringValue() ;
1281 for (size_t i
= 0; i
< content
.length() ; i
++)
1283 if (content
[i
] == '\r')
1290 wxString
wxMacTextControl::GetLineText(long lineNo
) const
1292 // TODO: change this if possible to reflect real lines
1293 wxString content
= GetStringValue() ;
1297 for (size_t i
= 0; i
< content
.length() ; i
++)
1299 if (count
== lineNo
)
1301 // Add chars in line then
1304 for (size_t j
= i
; j
< content
.length(); j
++)
1306 if (content
[j
] == '\n')
1315 if (content
[i
] == '\n')
1319 return wxEmptyString
;
1322 int wxMacTextControl::GetLineLength(long lineNo
) const
1324 // TODO: change this if possible to reflect real lines
1325 wxString content
= GetStringValue() ;
1329 for (size_t i
= 0; i
< content
.length() ; i
++)
1331 if (count
== lineNo
)
1333 // Count chars in line then
1335 for (size_t j
= i
; j
< content
.length(); j
++)
1338 if (content
[j
] == '\n')
1345 if (content
[i
] == '\n')
1352 // ----------------------------------------------------------------------------
1353 // standard unicode control implementation
1354 // ----------------------------------------------------------------------------
1356 #if TARGET_API_MAC_OSX
1358 // the current unicode textcontrol implementation has a bug : only if the control
1359 // is currently having the focus, the selection can be retrieved by the corresponding
1360 // data tag. So we have a mirroring using a member variable
1361 // TODO : build event table using virtual member functions for wxMacControl
1363 static const EventTypeSpec unicodeTextControlEventList
[] =
1365 { kEventClassControl
, kEventControlSetFocusPart
} ,
1368 static pascal OSStatus
wxMacUnicodeTextControlControlEventHandler( EventHandlerCallRef handler
, EventRef event
, void *data
)
1370 OSStatus result
= eventNotHandledErr
;
1371 wxMacUnicodeTextControl
* focus
= (wxMacUnicodeTextControl
*) data
;
1372 wxMacCarbonEvent
cEvent( event
) ;
1374 switch ( GetEventKind( event
) )
1376 case kEventControlSetFocusPart
:
1378 ControlPartCode controlPart
= cEvent
.GetParameter
<ControlPartCode
>(kEventParamControlPart
, typeControlPartCode
);
1379 if ( controlPart
== kControlFocusNoPart
)
1381 // about to loose focus -> store selection to field
1382 focus
->GetData
<ControlEditTextSelectionRec
>( 0, kControlEditTextSelectionTag
, &focus
->m_selection
);
1384 result
= CallNextEventHandler(handler
,event
) ;
1385 if ( controlPart
!= kControlFocusNoPart
)
1387 // about to gain focus -> set selection from field
1388 focus
->SetData
<ControlEditTextSelectionRec
>( 0, kControlEditTextSelectionTag
, &focus
->m_selection
);
1399 static pascal OSStatus
wxMacUnicodeTextControlEventHandler( EventHandlerCallRef handler
, EventRef event
, void *data
)
1401 OSStatus result
= eventNotHandledErr
;
1403 switch ( GetEventClass( event
) )
1405 case kEventClassControl
:
1406 result
= wxMacUnicodeTextControlControlEventHandler( handler
, event
, data
) ;
1415 DEFINE_ONE_SHOT_HANDLER_GETTER( wxMacUnicodeTextControlEventHandler
)
1417 wxMacUnicodeTextControl::wxMacUnicodeTextControl( wxTextCtrl
*wxPeer
,
1418 const wxString
& str
,
1420 const wxSize
& size
, long style
)
1421 : wxMacTextControl( wxPeer
)
1423 m_font
= wxPeer
->GetFont() ;
1424 m_windowStyle
= style
;
1425 Rect bounds
= wxMacGetBoundsForControl( wxPeer
, pos
, size
) ;
1427 wxMacConvertNewlines10To13( &st
) ;
1428 wxMacCFStringHolder
cf(st
, m_font
.GetEncoding()) ;
1429 CFStringRef cfr
= cf
;
1430 Boolean isPassword
= ( m_windowStyle
& wxTE_PASSWORD
) != 0 ;
1431 m_valueTag
= isPassword
? kControlEditTextPasswordCFStringTag
: kControlEditTextCFStringTag
;
1433 OSStatus err
= CreateEditUnicodeTextControl(
1434 MAC_WXHWND(wxPeer
->MacGetTopLevelWindowRef()), &bounds
, cfr
,
1435 isPassword
, NULL
, &m_controlRef
) ;
1436 verify_noerr( err
);
1438 if ( !(m_windowStyle
& wxTE_MULTILINE
) )
1439 SetData
<Boolean
>( kControlEditTextPart
, kControlEditTextSingleLineTag
, true ) ;
1441 InstallControlEventHandler( m_controlRef
, GetwxMacUnicodeTextControlEventHandlerUPP(),
1442 GetEventTypeCount(unicodeTextControlEventList
), unicodeTextControlEventList
, this,
1443 &m_focusHandlerRef
);
1446 wxMacUnicodeTextControl::~wxMacUnicodeTextControl()
1448 ::RemoveEventHandler( m_focusHandlerRef
);
1451 void wxMacUnicodeTextControl::VisibilityChanged(bool shown
)
1453 if ( !(m_windowStyle
& wxTE_MULTILINE
) && shown
)
1455 // work around a refresh issue insofar as not always the entire content is shown,
1456 // even if this would be possible
1457 ControlEditTextSelectionRec sel
;
1458 CFStringRef value
= NULL
;
1460 verify_noerr( GetData
<ControlEditTextSelectionRec
>( 0, kControlEditTextSelectionTag
, &sel
) );
1461 verify_noerr( GetData
<CFStringRef
>( 0, m_valueTag
, &value
) );
1462 verify_noerr( SetData
<CFStringRef
>( 0, m_valueTag
, &value
) );
1463 verify_noerr( SetData
<ControlEditTextSelectionRec
>( 0, kControlEditTextSelectionTag
, &sel
) );
1465 CFRelease( value
) ;
1469 wxString
wxMacUnicodeTextControl::GetStringValue() const
1472 CFStringRef value
= GetData
<CFStringRef
>(0, m_valueTag
) ;
1475 wxMacCFStringHolder
cf(value
) ;
1476 result
= cf
.AsString() ;
1480 wxMacConvertNewlines13To10( &result
) ;
1482 wxMacConvertNewlines10To13( &result
) ;
1488 void wxMacUnicodeTextControl::SetStringValue( const wxString
&str
)
1491 wxMacConvertNewlines10To13( &st
) ;
1492 wxMacCFStringHolder
cf( st
, m_font
.GetEncoding() ) ;
1493 verify_noerr( SetData
<CFStringRef
>( 0, m_valueTag
, cf
) ) ;
1496 void wxMacUnicodeTextControl::Copy()
1498 SendHICommand( kHICommandCopy
) ;
1501 void wxMacUnicodeTextControl::Cut()
1503 SendHICommand( kHICommandCut
) ;
1506 void wxMacUnicodeTextControl::Paste()
1508 SendHICommand( kHICommandPaste
) ;
1511 bool wxMacUnicodeTextControl::CanPaste() const
1516 void wxMacUnicodeTextControl::SetEditable(bool editable
)
1518 #if 0 // leads to problem because text cannot be selected anymore
1519 SetData
<Boolean
>( kControlEditTextPart
, kControlEditTextLockedTag
, (Boolean
) !editable
) ;
1523 void wxMacUnicodeTextControl::GetSelection( long* from
, long* to
) const
1525 ControlEditTextSelectionRec sel
;
1527 verify_noerr( GetData
<ControlEditTextSelectionRec
>( 0, kControlEditTextSelectionTag
, &sel
) ) ;
1532 *from
= sel
.selStart
;
1537 void wxMacUnicodeTextControl::SetSelection( long from
, long to
)
1539 ControlEditTextSelectionRec sel
;
1541 int textLength
= 0 ;
1542 CFStringRef value
= GetData
<CFStringRef
>(0, m_valueTag
) ;
1545 wxMacCFStringHolder
cf(value
) ;
1546 textLength
= cf
.AsString().length() ;
1549 if ((from
== -1) && (to
== -1))
1556 from
= wxMin(textLength
,wxMax(from
,0)) ;
1557 to
= wxMax(0,wxMin(textLength
,to
)) ;
1560 sel
.selStart
= from
;
1563 SetData
<ControlEditTextSelectionRec
>( 0, kControlEditTextSelectionTag
, &sel
) ;
1568 void wxMacUnicodeTextControl::WriteText( const wxString
& str
)
1571 wxMacConvertNewlines10To13( &st
) ;
1573 #if MAC_OS_X_VERSION_MAX_ALLOWED > MAC_OS_X_VERSION_10_2
1576 wxMacCFStringHolder
cf(st
, m_font
.GetEncoding() ) ;
1577 CFStringRef value
= cf
;
1578 SetData
<CFStringRef
>( 0, kControlEditTextInsertCFStringRefTag
, &value
);
1583 wxString val
= GetStringValue() ;
1585 GetSelection( &start
, &end
) ;
1586 val
.Remove( start
, end
- start
) ;
1587 val
.insert( start
, str
) ;
1588 SetStringValue( val
) ;
1589 SetSelection( start
+ str
.length() , start
+ str
.length() ) ;
1595 // ----------------------------------------------------------------------------
1596 // MLTE control implementation (common part)
1597 // ----------------------------------------------------------------------------
1599 // if MTLE is read only, no changes at all are allowed, not even from
1600 // procedural API, in order to allow changes via API all the same we must undo
1601 // the readonly status while we are executing, this class helps to do so
1603 class wxMacEditHelper
1606 wxMacEditHelper( TXNObject txn
)
1608 TXNControlTag tag
[] = { kTXNIOPrivilegesTag
} ;
1610 TXNGetTXNObjectControls( m_txn
, 1 , tag
, m_data
) ;
1611 if ( m_data
[0].uValue
== kTXNReadOnly
)
1613 TXNControlData data
[] = { { kTXNReadWrite
} } ;
1614 TXNSetTXNObjectControls( m_txn
, false , 1 , tag
, data
) ;
1620 TXNControlTag tag
[] = { kTXNIOPrivilegesTag
} ;
1621 if ( m_data
[0].uValue
== kTXNReadOnly
)
1622 TXNSetTXNObjectControls( m_txn
, false , 1 , tag
, m_data
) ;
1627 TXNControlData m_data
[1] ;
1630 wxMacMLTEControl::wxMacMLTEControl( wxTextCtrl
*peer
)
1631 : wxMacTextControl( peer
)
1633 SetNeedsFocusRect( true ) ;
1636 wxString
wxMacMLTEControl::GetStringValue() const
1640 Size actualSize
= 0;
1645 err
= TXNGetDataEncoded( m_txn
, kTXNStartOffset
, kTXNEndOffset
, &theText
, kTXNUnicodeTextData
);
1654 actualSize
= GetHandleSize( theText
) / sizeof(UniChar
) ;
1655 if ( actualSize
> 0 )
1657 wxChar
*ptr
= NULL
;
1659 #if SIZEOF_WCHAR_T == 2
1660 ptr
= new wxChar
[actualSize
+ 1] ;
1661 wxStrncpy( ptr
, (wxChar
*)(*theText
) , actualSize
) ;
1663 SetHandleSize( theText
, (actualSize
+ 1) * sizeof(UniChar
) ) ;
1665 (((UniChar
*)*theText
)[actualSize
]) = 0 ;
1666 wxMBConvUTF16 converter
;
1667 size_t noChars
= converter
.MB2WC( NULL
, (const char*)*theText
, 0 ) ;
1668 wxASSERT_MSG( noChars
!= wxCONV_FAILED
, _T("Unable to count the number of characters in this string!") );
1669 ptr
= new wxChar
[noChars
+ 1] ;
1671 noChars
= converter
.MB2WC( ptr
, (const char*)*theText
, noChars
+ 1 ) ;
1672 wxASSERT_MSG( noChars
!= wxCONV_FAILED
, _T("Conversion of string failed!") );
1674 HUnlock( theText
) ;
1677 ptr
[actualSize
] = 0 ;
1678 result
= wxString( ptr
) ;
1682 DisposeHandle( theText
) ;
1686 err
= TXNGetDataEncoded( m_txn
, kTXNStartOffset
, kTXNEndOffset
, &theText
, kTXNTextData
);
1695 actualSize
= GetHandleSize( theText
) ;
1696 if ( actualSize
> 0 )
1699 result
= wxString( *theText
, wxConvLocal
, actualSize
) ;
1700 HUnlock( theText
) ;
1703 DisposeHandle( theText
) ;
1709 wxMacConvertNewlines13To10( &result
) ;
1711 wxMacConvertNewlines10To13( &result
) ;
1717 void wxMacMLTEControl::SetStringValue( const wxString
&str
)
1720 wxMacConvertNewlines10To13( &st
);
1723 wxMacWindowClipper
c( m_peer
);
1726 wxMacEditHelper
help( m_txn
);
1727 SetTXNData( st
, kTXNStartOffset
, kTXNEndOffset
);
1730 TXNSetSelection( m_txn
, 0, 0 );
1731 TXNShowSelection( m_txn
, kTXNShowStart
);
1735 TXNFrameOptions
wxMacMLTEControl::FrameOptionsFromWXStyle( long wxStyle
)
1737 TXNFrameOptions frameOptions
= kTXNDontDrawCaretWhenInactiveMask
;
1739 #if MAC_OS_X_VERSION_MAX_ALLOWED >= MAC_OS_X_VERSION_10_3
1740 frameOptions
|= kTXNDoFontSubstitutionMask
;
1743 if ( ! (wxStyle
& wxTE_NOHIDESEL
) )
1744 frameOptions
|= kTXNDontDrawSelectionWhenInactiveMask
;
1746 if ( wxStyle
& (wxHSCROLL
| wxTE_DONTWRAP
) )
1747 frameOptions
|= kTXNWantHScrollBarMask
;
1749 if ( wxStyle
& wxTE_MULTILINE
)
1751 frameOptions
|= kTXNAlwaysWrapAtViewEdgeMask
;
1753 if ( !(wxStyle
& wxTE_NO_VSCROLL
) )
1755 frameOptions
|= kTXNWantVScrollBarMask
;
1757 // The following code causes drawing problems on 10.4. Perhaps it can be restored for
1758 // older versions of the OS, but I'm not sure it's appropriate to put a grow icon here
1759 // anyways, as AFAIK users can't actually use it to resize the text ctrl.
1760 // if ( frameOptions & kTXNWantHScrollBarMask )
1761 // frameOptions |= kTXNDrawGrowIconMask ;
1766 frameOptions
|= kTXNSingleLineOnlyMask
;
1769 return frameOptions
;
1772 void wxMacMLTEControl::AdjustCreationAttributes( const wxColour
&background
, bool visible
)
1774 TXNControlTag iControlTags
[] =
1776 kTXNDoFontSubstitution
,
1777 kTXNWordWrapStateTag
,
1779 TXNControlData iControlData
[] =
1785 int toptag
= WXSIZEOF( iControlTags
) ;
1787 if ( m_windowStyle
& wxTE_MULTILINE
)
1789 iControlData
[1].uValue
=
1790 (m_windowStyle
& wxTE_DONTWRAP
)
1795 OSStatus err
= TXNSetTXNObjectControls( m_txn
, false, toptag
, iControlTags
, iControlData
) ;
1796 verify_noerr( err
);
1798 // setting the default font:
1799 // under 10.2 this causes a visible caret, therefore we avoid it
1801 if ( UMAGetSystemVersion() >= 0x1030 )
1807 GetThemeFont( kThemeSystemFont
, GetApplicationScript() , fontName
, &fontSize
, &fontStyle
) ;
1809 TXNTypeAttributes typeAttr
[] =
1811 { kTXNQDFontNameAttribute
, kTXNQDFontNameAttributeSize
, { (void*) fontName
} } ,
1812 { kTXNQDFontSizeAttribute
, kTXNFontSizeAttributeSize
, { (void*) (fontSize
<< 16) } } ,
1813 { kTXNQDFontStyleAttribute
, kTXNQDFontStyleAttributeSize
, { (void*) normal
} } ,
1816 err
= TXNSetTypeAttributes(
1817 m_txn
, sizeof(typeAttr
) / sizeof(TXNTypeAttributes
),
1818 typeAttr
, kTXNStartOffset
, kTXNEndOffset
);
1819 verify_noerr( err
);
1822 if ( m_windowStyle
& wxTE_PASSWORD
)
1824 UniChar c
= 0x00A5 ;
1825 err
= TXNEchoMode( m_txn
, c
, 0 , true );
1826 verify_noerr( err
);
1829 TXNBackground tback
;
1830 tback
.bgType
= kTXNBackgroundTypeRGB
;
1831 tback
.bg
.color
= MAC_WXCOLORREF( background
.GetPixel() );
1832 TXNSetBackground( m_txn
, &tback
);
1834 #if MAC_OS_X_VERSION_MAX_ALLOWED >= MAC_OS_X_VERSION_10_4
1835 if ( UMAGetSystemVersion() >= 0x1040 )
1837 TXNCommandEventSupportOptions options
;
1838 if ( TXNGetCommandEventSupport( m_txn
, &options
) == noErr
)
1841 kTXNSupportEditCommandProcessing
1842 | kTXNSupportEditCommandUpdating
1843 | kTXNSupportSpellCheckCommandProcessing
1844 | kTXNSupportSpellCheckCommandUpdating
1845 | kTXNSupportFontCommandProcessing
1846 | kTXNSupportFontCommandUpdating
;
1848 TXNSetCommandEventSupport( m_txn
, options
) ;
1854 void wxMacMLTEControl::SetBackground( const wxBrush
&brush
)
1856 // currently only solid background are supported
1857 TXNBackground tback
;
1859 tback
.bgType
= kTXNBackgroundTypeRGB
;
1860 tback
.bg
.color
= MAC_WXCOLORREF( brush
.GetColour().GetPixel() );
1861 TXNSetBackground( m_txn
, &tback
);
1864 void wxMacMLTEControl::TXNSetAttribute( const wxTextAttr
& style
, long from
, long to
)
1866 TXNTypeAttributes typeAttr
[4] ;
1870 if ( style
.HasFont() )
1872 const wxFont
&font
= style
.GetFont() ;
1874 #if 0 // old version
1875 Str255 fontName
= "\pMonaco" ;
1876 SInt16 fontSize
= 12 ;
1877 Style fontStyle
= normal
;
1878 wxMacStringToPascal( font
.GetFaceName() , fontName
) ;
1879 fontSize
= font
.GetPointSize() ;
1880 if ( font
.GetUnderlined() )
1881 fontStyle
|= underline
;
1882 if ( font
.GetWeight() == wxBOLD
)
1884 if ( font
.GetStyle() == wxITALIC
)
1885 fontStyle
|= italic
;
1887 typeAttr
[attrCount
].tag
= kTXNQDFontNameAttribute
;
1888 typeAttr
[attrCount
].size
= kTXNQDFontNameAttributeSize
;
1889 typeAttr
[attrCount
].data
.dataPtr
= (void*)fontName
;
1892 typeAttr
[attrCount
].tag
= kTXNQDFontSizeAttribute
;
1893 typeAttr
[attrCount
].size
= kTXNFontSizeAttributeSize
;
1894 typeAttr
[attrCount
].data
.dataValue
= (fontSize
<< 16) ;
1897 typeAttr
[attrCount
].tag
= kTXNQDFontStyleAttribute
;
1898 typeAttr
[attrCount
].size
= kTXNQDFontStyleAttributeSize
;
1899 typeAttr
[attrCount
].data
.dataValue
= fontStyle
;
1902 typeAttr
[attrCount
].tag
= kTXNATSUIStyle
;
1903 typeAttr
[attrCount
].size
= kTXNATSUIStyleSize
;
1904 typeAttr
[attrCount
].data
.dataValue
= (UInt32
)font
.MacGetATSUStyle() ;
1909 if ( style
.HasTextColour() )
1911 color
= MAC_WXCOLORREF(style
.GetTextColour().GetPixel()) ;
1913 typeAttr
[attrCount
].tag
= kTXNQDFontColorAttribute
;
1914 typeAttr
[attrCount
].size
= kTXNQDFontColorAttributeSize
;
1915 typeAttr
[attrCount
].data
.dataPtr
= (void*) &color
;
1919 if ( attrCount
> 0 )
1921 verify_noerr( TXNSetTypeAttributes( m_txn
, attrCount
, typeAttr
, from
, to
) );
1922 // unfortunately the relayout is not automatic
1923 TXNRecalcTextLayout( m_txn
);
1927 void wxMacMLTEControl::SetFont( const wxFont
& font
, const wxColour
& foreground
, long windowStyle
)
1929 wxMacEditHelper
help( m_txn
) ;
1930 TXNSetAttribute( wxTextAttr( foreground
, wxNullColour
, font
), kTXNStartOffset
, kTXNEndOffset
) ;
1933 void wxMacMLTEControl::SetStyle( long start
, long end
, const wxTextAttr
& style
)
1935 wxMacEditHelper
help( m_txn
) ;
1936 TXNSetAttribute( style
, start
, end
) ;
1939 void wxMacMLTEControl::Copy()
1941 ClearCurrentScrap();
1943 TXNConvertToPublicScrap();
1946 void wxMacMLTEControl::Cut()
1948 ClearCurrentScrap();
1950 TXNConvertToPublicScrap();
1953 void wxMacMLTEControl::Paste()
1955 TXNConvertFromPublicScrap();
1959 bool wxMacMLTEControl::CanPaste() const
1961 return TXNIsScrapPastable() ;
1964 void wxMacMLTEControl::SetEditable(bool editable
)
1966 TXNControlTag tag
[] = { kTXNIOPrivilegesTag
} ;
1967 TXNControlData data
[] = { { editable
? kTXNReadWrite
: kTXNReadOnly
} } ;
1968 TXNSetTXNObjectControls( m_txn
, false, WXSIZEOF(tag
), tag
, data
) ;
1971 wxTextPos
wxMacMLTEControl::GetLastPosition() const
1973 wxTextPos actualsize
= 0 ;
1976 OSErr err
= TXNGetDataEncoded( m_txn
, kTXNStartOffset
, kTXNEndOffset
, &theText
, kTXNTextData
);
1981 actualsize
= GetHandleSize( theText
) ;
1982 DisposeHandle( theText
) ;
1992 void wxMacMLTEControl::Replace( long from
, long to
, const wxString
&str
)
1994 wxString value
= str
;
1995 wxMacConvertNewlines10To13( &value
) ;
1997 wxMacEditHelper
help( m_txn
) ;
1998 wxMacWindowClipper
c( m_peer
) ;
2000 TXNSetSelection( m_txn
, from
, to
) ;
2002 SetTXNData( value
, kTXNUseCurrentSelection
, kTXNUseCurrentSelection
) ;
2005 void wxMacMLTEControl::Remove( long from
, long to
)
2007 wxMacWindowClipper
c( m_peer
) ;
2008 wxMacEditHelper
help( m_txn
) ;
2009 TXNSetSelection( m_txn
, from
, to
) ;
2013 void wxMacMLTEControl::GetSelection( long* from
, long* to
) const
2015 TXNGetSelection( m_txn
, (TXNOffset
*) from
, (TXNOffset
*) to
) ;
2018 void wxMacMLTEControl::SetSelection( long from
, long to
)
2020 wxMacWindowClipper
c( m_peer
) ;
2022 // change the selection
2023 if ((from
== -1) && (to
== -1))
2024 TXNSelectAll( m_txn
);
2026 TXNSetSelection( m_txn
, from
, to
);
2028 TXNShowSelection( m_txn
, kTXNShowStart
);
2031 void wxMacMLTEControl::WriteText( const wxString
& str
)
2034 wxMacConvertNewlines10To13( &st
) ;
2036 long start
, end
, dummy
;
2038 GetSelection( &start
, &dummy
) ;
2039 wxMacWindowClipper
c( m_peer
) ;
2042 wxMacEditHelper
helper( m_txn
) ;
2043 SetTXNData( st
, kTXNUseCurrentSelection
, kTXNUseCurrentSelection
) ;
2046 GetSelection( &dummy
, &end
) ;
2048 // TODO: SetStyle( start , end , GetDefaultStyle() ) ;
2051 void wxMacMLTEControl::Clear()
2053 wxMacWindowClipper
c( m_peer
) ;
2054 wxMacEditHelper
st( m_txn
) ;
2055 TXNSetSelection( m_txn
, kTXNStartOffset
, kTXNEndOffset
) ;
2059 bool wxMacMLTEControl::CanUndo() const
2061 return TXNCanUndo( m_txn
, NULL
) ;
2064 void wxMacMLTEControl::Undo()
2069 bool wxMacMLTEControl::CanRedo() const
2071 return TXNCanRedo( m_txn
, NULL
) ;
2074 void wxMacMLTEControl::Redo()
2079 int wxMacMLTEControl::GetNumberOfLines() const
2081 ItemCount lines
= 0 ;
2082 TXNGetLineCount( m_txn
, &lines
) ;
2087 long wxMacMLTEControl::XYToPosition(long x
, long y
) const
2092 // TODO: find a better implementation : while we can get the
2093 // line metrics of a certain line, we don't get its starting
2094 // position, so it would probably be rather a binary search
2095 // for the start position
2096 long xpos
= 0, ypos
= 0 ;
2097 int lastHeight
= 0 ;
2100 lastpos
= GetLastPosition() ;
2101 for ( n
= 0 ; n
<= (ItemCount
) lastpos
; ++n
)
2103 if ( y
== ypos
&& x
== xpos
)
2106 TXNOffsetToPoint( m_txn
, n
, &curpt
) ;
2108 if ( curpt
.v
> lastHeight
)
2114 lastHeight
= curpt
.v
;
2123 bool wxMacMLTEControl::PositionToXY( long pos
, long *x
, long *y
) const
2133 lastpos
= GetLastPosition() ;
2134 if ( pos
<= lastpos
)
2136 // TODO: find a better implementation - while we can get the
2137 // line metrics of a certain line, we don't get its starting
2138 // position, so it would probably be rather a binary search
2139 // for the start position
2140 long xpos
= 0, ypos
= 0 ;
2141 int lastHeight
= 0 ;
2144 for ( n
= 0 ; n
<= (ItemCount
) pos
; ++n
)
2146 TXNOffsetToPoint( m_txn
, n
, &curpt
) ;
2148 if ( curpt
.v
> lastHeight
)
2154 lastHeight
= curpt
.v
;
2169 void wxMacMLTEControl::ShowPosition( long pos
)
2171 #if TARGET_RT_MAC_MACHO && defined(AVAILABLE_MAC_OS_X_VERSION_10_2_AND_LATER)
2173 Point current
, desired
;
2174 TXNOffset selstart
, selend
;
2176 TXNGetSelection( m_txn
, &selstart
, &selend
);
2177 TXNOffsetToPoint( m_txn
, selstart
, ¤t
);
2178 TXNOffsetToPoint( m_txn
, pos
, &desired
);
2180 // TODO: use HIPoints for 10.3 and above
2181 if ( (UInt32
)TXNScroll
!= (UInt32
)kUnresolvedCFragSymbolAddress
)
2183 OSErr theErr
= noErr
;
2184 SInt32 dv
= desired
.v
- current
.v
;
2185 SInt32 dh
= desired
.h
- current
.h
;
2186 TXNShowSelection( m_txn
, kTXNShowStart
) ; // NB: should this be kTXNShowStart or kTXNShowEnd ??
2187 theErr
= TXNScroll( m_txn
, kTXNScrollUnitsInPixels
, kTXNScrollUnitsInPixels
, &dv
, &dh
);
2189 // there will be an error returned for classic MLTE implementation when the control is
2190 // invisible, but HITextView works correctly, so we don't assert that one
2191 // wxASSERT_MSG( theErr == noErr, _T("TXNScroll returned an error!") );
2197 void wxMacMLTEControl::SetTXNData( const wxString
& st
, TXNOffset start
, TXNOffset end
)
2200 #if SIZEOF_WCHAR_T == 2
2201 size_t len
= st
.length() ;
2202 TXNSetData( m_txn
, kTXNUnicodeTextData
, (void*)st
.wc_str(), len
* 2, start
, end
);
2204 wxMBConvUTF16 converter
;
2205 ByteCount byteBufferLen
= converter
.WC2MB( NULL
, st
.wc_str(), 0 ) ;
2206 UniChar
*unibuf
= (UniChar
*)malloc( byteBufferLen
) ;
2207 converter
.WC2MB( (char*)unibuf
, st
.wc_str(), byteBufferLen
) ;
2208 TXNSetData( m_txn
, kTXNUnicodeTextData
, (void*)unibuf
, byteBufferLen
, start
, end
) ;
2212 wxCharBuffer text
= st
.mb_str( wxConvLocal
) ;
2213 TXNSetData( m_txn
, kTXNTextData
, (void*)text
.data(), strlen( text
), start
, end
) ;
2217 wxString
wxMacMLTEControl::GetLineText(long lineNo
) const
2221 if ( lineNo
< GetNumberOfLines() )
2224 Fixed lineWidth
, lineHeight
, currentHeight
;
2227 // get the first possible position in the control
2228 TXNOffsetToPoint(m_txn
, 0, &firstPoint
);
2230 // Iterate through the lines until we reach the one we want,
2231 // adding to our current y pixel point position
2234 while (ypos
< lineNo
)
2236 TXNGetLineMetrics(m_txn
, ypos
++, &lineWidth
, &lineHeight
);
2237 currentHeight
+= lineHeight
;
2240 Point thePoint
= { firstPoint
.v
+ (currentHeight
>> 16), firstPoint
.h
+ (0) };
2241 TXNOffset theOffset
;
2242 TXNPointToOffset(m_txn
, thePoint
, &theOffset
);
2244 wxString content
= GetStringValue() ;
2245 Point currentPoint
= thePoint
;
2246 while (thePoint
.v
== currentPoint
.v
&& theOffset
< content
.length())
2248 line
+= content
[theOffset
];
2249 TXNOffsetToPoint(m_txn
, ++theOffset
, ¤tPoint
);
2256 int wxMacMLTEControl::GetLineLength(long lineNo
) const
2260 if ( lineNo
< GetNumberOfLines() )
2263 Fixed lineWidth
, lineHeight
, currentHeight
;
2266 // get the first possible position in the control
2267 TXNOffsetToPoint(m_txn
, 0, &firstPoint
);
2269 // Iterate through the lines until we reach the one we want,
2270 // adding to our current y pixel point position
2273 while (ypos
< lineNo
)
2275 TXNGetLineMetrics(m_txn
, ypos
++, &lineWidth
, &lineHeight
);
2276 currentHeight
+= lineHeight
;
2279 Point thePoint
= { firstPoint
.v
+ (currentHeight
>> 16), firstPoint
.h
+ (0) };
2280 TXNOffset theOffset
;
2281 TXNPointToOffset(m_txn
, thePoint
, &theOffset
);
2283 wxString content
= GetStringValue() ;
2284 Point currentPoint
= thePoint
;
2285 while (thePoint
.v
== currentPoint
.v
&& theOffset
< content
.length())
2288 TXNOffsetToPoint(m_txn
, ++theOffset
, ¤tPoint
);
2295 // ----------------------------------------------------------------------------
2296 // MLTE control implementation (classic part)
2297 // ----------------------------------------------------------------------------
2299 // OS X Notes : We still don't have a full replacement for MLTE, so this implementation
2300 // has to live on. We have different problems coming from outdated implementations on the
2301 // various OS X versions. Most deal with the scrollbars: they are not correctly embedded
2302 // while this can be solved on 10.3 by reassigning them the correct place, on 10.2 there is
2303 // no way out, therefore we are using our own implementation and our own scrollbars ....
2305 #ifdef __WXMAC_OSX__
2307 TXNScrollInfoUPP gTXNScrollInfoProc
= NULL
;
2308 ControlActionUPP gTXNScrollActionProc
= NULL
;
2310 pascal void wxMacMLTEClassicControl::TXNScrollInfoProc(
2311 SInt32 iValue
, SInt32 iMaximumValue
,
2312 TXNScrollBarOrientation iScrollBarOrientation
, SInt32 iRefCon
)
2314 wxMacMLTEClassicControl
* mlte
= (wxMacMLTEClassicControl
*) iRefCon
;
2315 SInt32 value
= wxMax( iValue
, 0 ) ;
2316 SInt32 maximum
= wxMax( iMaximumValue
, 0 ) ;
2318 if ( iScrollBarOrientation
== kTXNHorizontal
)
2320 if ( mlte
->m_sbHorizontal
)
2322 SetControl32BitValue( mlte
->m_sbHorizontal
, value
) ;
2323 SetControl32BitMaximum( mlte
->m_sbHorizontal
, maximum
) ;
2324 mlte
->m_lastHorizontalValue
= value
;
2327 else if ( iScrollBarOrientation
== kTXNVertical
)
2329 if ( mlte
->m_sbVertical
)
2331 SetControl32BitValue( mlte
->m_sbVertical
, value
) ;
2332 SetControl32BitMaximum( mlte
->m_sbVertical
, maximum
) ;
2333 mlte
->m_lastVerticalValue
= value
;
2338 pascal void wxMacMLTEClassicControl::TXNScrollActionProc( ControlRef controlRef
, ControlPartCode partCode
)
2340 wxMacMLTEClassicControl
* mlte
= (wxMacMLTEClassicControl
*) GetControlReference( controlRef
) ;
2344 if ( controlRef
!= mlte
->m_sbVertical
&& controlRef
!= mlte
->m_sbHorizontal
)
2348 bool isHorizontal
= ( controlRef
== mlte
->m_sbHorizontal
) ;
2350 SInt32 minimum
= 0 ;
2351 SInt32 maximum
= GetControl32BitMaximum( controlRef
) ;
2352 SInt32 value
= GetControl32BitValue( controlRef
) ;
2357 case kControlDownButtonPart
:
2361 case kControlUpButtonPart
:
2365 case kControlPageDownPart
:
2366 delta
= GetControlViewSize( controlRef
) ;
2369 case kControlPageUpPart
:
2370 delta
= -GetControlViewSize( controlRef
) ;
2373 case kControlIndicatorPart
:
2374 delta
= value
- (isHorizontal
? mlte
->m_lastHorizontalValue
: mlte
->m_lastVerticalValue
) ;
2383 SInt32 newValue
= value
;
2385 if ( partCode
!= kControlIndicatorPart
)
2387 if ( value
+ delta
< minimum
)
2388 delta
= minimum
- value
;
2389 if ( value
+ delta
> maximum
)
2390 delta
= maximum
- value
;
2392 SetControl32BitValue( controlRef
, value
+ delta
) ;
2393 newValue
= value
+ delta
;
2396 SInt32 verticalDelta
= isHorizontal
? 0 : delta
;
2397 SInt32 horizontalDelta
= isHorizontal
? delta
: 0 ;
2400 mlte
->m_txn
, kTXNScrollUnitsInPixels
, kTXNScrollUnitsInPixels
,
2401 &verticalDelta
, &horizontalDelta
);
2402 verify_noerr( err
);
2405 mlte
->m_lastHorizontalValue
= newValue
;
2407 mlte
->m_lastVerticalValue
= newValue
;
2412 // make correct activations
2413 void wxMacMLTEClassicControl::MacActivatePaneText(bool setActive
)
2415 wxTextCtrl
* textctrl
= (wxTextCtrl
*) GetControlReference(m_controlRef
);
2417 wxMacWindowClipper
clipper( textctrl
) ;
2418 TXNActivate( m_txn
, m_txnFrameID
, setActive
);
2420 ControlRef controlFocus
= 0 ;
2421 GetKeyboardFocus( m_txnWindow
, &controlFocus
) ;
2422 if ( controlFocus
== m_controlRef
)
2423 TXNFocus( m_txn
, setActive
);
2426 void wxMacMLTEClassicControl::MacFocusPaneText(bool setFocus
)
2428 TXNFocus( m_txn
, setFocus
);
2431 // guards against inappropriate redraw (hidden objects drawing onto window)
2433 void wxMacMLTEClassicControl::MacSetObjectVisibility(bool vis
)
2435 ControlRef controlFocus
= 0 ;
2436 GetKeyboardFocus( m_txnWindow
, &controlFocus
) ;
2438 if ( !vis
&& (controlFocus
== m_controlRef
) )
2439 SetKeyboardFocus( m_txnWindow
, m_controlRef
, kControlFocusNoPart
) ;
2441 TXNControlTag iControlTags
[1] = { kTXNVisibilityTag
};
2442 TXNControlData iControlData
[1] = { { (UInt32
)false } };
2444 verify_noerr( TXNGetTXNObjectControls( m_txn
, 1, iControlTags
, iControlData
) ) ;
2446 if ( iControlData
[0].uValue
!= vis
)
2448 iControlData
[0].uValue
= vis
;
2449 verify_noerr( TXNSetTXNObjectControls( m_txn
, false , 1, iControlTags
, iControlData
) ) ;
2452 // currently, we always clip as partial visibility (overlapped) visibility is also a problem,
2453 // if we run into further problems we might set the FrameBounds to an empty rect here
2456 // make sure that the TXNObject is at the right position
2458 void wxMacMLTEClassicControl::MacUpdatePosition()
2460 wxTextCtrl
* textctrl
= (wxTextCtrl
*)GetControlReference( m_controlRef
);
2461 if ( textctrl
== NULL
)
2465 UMAGetControlBoundsInWindowCoords( m_controlRef
, &bounds
);
2467 wxRect visRect
= textctrl
->MacGetClippedClientRect() ;
2468 Rect visBounds
= { visRect
.y
, visRect
.x
, visRect
.y
+ visRect
.height
, visRect
.x
+ visRect
.width
} ;
2471 textctrl
->MacWindowToRootWindow( &x
, &y
) ;
2472 OffsetRect( &visBounds
, x
, y
) ;
2474 if ( !EqualRect( &bounds
, &m_txnControlBounds
) || !EqualRect( &visBounds
, &m_txnVisBounds
) )
2476 m_txnControlBounds
= bounds
;
2477 m_txnVisBounds
= visBounds
;
2478 wxMacWindowClipper
cl( textctrl
) ;
2480 #ifdef __WXMAC_OSX__
2481 if ( m_sbHorizontal
|| m_sbVertical
)
2483 int w
= bounds
.right
- bounds
.left
;
2484 int h
= bounds
.bottom
- bounds
.top
;
2486 if ( m_sbHorizontal
)
2490 sbBounds
.left
= -1 ;
2491 sbBounds
.top
= h
- 14 ;
2492 sbBounds
.right
= w
+ 1 ;
2493 sbBounds
.bottom
= h
+ 1 ;
2495 SetControlBounds( m_sbHorizontal
, &sbBounds
) ;
2496 SetControlViewSize( m_sbHorizontal
, w
) ;
2503 sbBounds
.left
= w
- 14 ;
2505 sbBounds
.right
= w
+ 1 ;
2506 sbBounds
.bottom
= m_sbHorizontal
? h
- 14 : h
+ 1 ;
2508 SetControlBounds( m_sbVertical
, &sbBounds
) ;
2509 SetControlViewSize( m_sbVertical
, h
) ;
2514 TXNLongRect olddestRect
;
2515 TXNGetRectBounds( m_txn
, &oldviewRect
, &olddestRect
, NULL
) ;
2517 Rect viewRect
= { m_txnControlBounds
.top
, m_txnControlBounds
.left
,
2518 m_txnControlBounds
.bottom
- ( m_sbHorizontal
? 14 : 0 ) ,
2519 m_txnControlBounds
.right
- ( m_sbVertical
? 14 : 0 ) } ;
2520 TXNLongRect destRect
= { m_txnControlBounds
.top
, m_txnControlBounds
.left
,
2521 m_txnControlBounds
.bottom
- ( m_sbHorizontal
? 14 : 0 ) ,
2522 m_txnControlBounds
.right
- ( m_sbVertical
? 14 : 0 ) } ;
2524 if ( olddestRect
.right
>= 10000 )
2525 destRect
.right
= destRect
.left
+ 32000 ;
2527 if ( olddestRect
.bottom
>= 0x20000000 )
2528 destRect
.bottom
= destRect
.top
+ 0x40000000 ;
2530 SectRect( &viewRect
, &visBounds
, &viewRect
) ;
2531 TXNSetRectBounds( m_txn
, &viewRect
, &destRect
, true ) ;
2536 m_txnControlBounds
.top
,
2537 m_txnControlBounds
.left
,
2538 m_txnControlBounds
.bottom
- (m_sbHorizontal
? 14 : 0),
2539 m_txnControlBounds
.right
- (m_sbVertical
? 14 : 0),
2545 m_txn
, m_txnControlBounds
.top
, m_txnControlBounds
.left
,
2546 wxMax( m_txnControlBounds
.bottom
, m_txnControlBounds
.top
),
2547 wxMax( m_txnControlBounds
.right
, m_txnControlBounds
.left
), m_txnFrameID
);
2550 // the SetFrameBounds method under Classic sometimes does not correctly scroll a selection into sight after a
2551 // movement, therefore we have to force it
2553 // this problem has been reported in OSX as well, so we use this here once again
2555 TXNLongRect textRect
;
2556 TXNGetRectBounds( m_txn
, NULL
, NULL
, &textRect
) ;
2557 if ( textRect
.left
< m_txnControlBounds
.left
)
2558 TXNShowSelection( m_txn
, kTXNShowStart
) ;
2562 void wxMacMLTEClassicControl::SetRect( Rect
*r
)
2564 wxMacControl::SetRect( r
) ;
2565 MacUpdatePosition() ;
2568 void wxMacMLTEClassicControl::MacControlUserPaneDrawProc(wxInt16 thePart
)
2570 wxTextCtrl
* textctrl
= (wxTextCtrl
*)GetControlReference( m_controlRef
);
2571 if ( textctrl
== NULL
)
2574 if ( textctrl
->MacIsReallyShown() )
2576 wxMacWindowClipper
clipper( textctrl
) ;
2577 TXNDraw( m_txn
, NULL
) ;
2581 wxInt16
wxMacMLTEClassicControl::MacControlUserPaneHitTestProc(wxInt16 x
, wxInt16 y
)
2583 Point where
= { y
, x
} ;
2584 ControlPartCode result
= kControlNoPart
;
2586 wxTextCtrl
* textctrl
= (wxTextCtrl
*) GetControlReference( m_controlRef
);
2587 if ( (textctrl
!= NULL
) && textctrl
->MacIsReallyShown() )
2589 if (PtInRect( where
, &m_txnControlBounds
))
2591 result
= kControlEditTextPart
;
2595 // sometimes we get the coords also in control local coordinates, therefore test again
2597 textctrl
->MacClientToRootWindow( &x
, &y
) ;
2601 if (PtInRect( where
, &m_txnControlBounds
))
2602 result
= kControlEditTextPart
;
2609 wxInt16
wxMacMLTEClassicControl::MacControlUserPaneTrackingProc( wxInt16 x
, wxInt16 y
, void* actionProc
)
2611 ControlPartCode result
= kControlNoPart
;
2613 wxTextCtrl
* textctrl
= (wxTextCtrl
*) GetControlReference( m_controlRef
);
2614 if ( (textctrl
!= NULL
) && textctrl
->MacIsReallyShown() )
2616 Point startPt
= { y
, x
} ;
2618 // for compositing, we must convert these into toplevel window coordinates, because hittesting expects them
2620 textctrl
->MacClientToRootWindow( &x
, &y
) ;
2624 switch (MacControlUserPaneHitTestProc( startPt
.h
, startPt
.v
))
2626 case kControlEditTextPart
:
2628 wxMacWindowClipper
clipper( textctrl
) ;
2631 ConvertEventRefToEventRecord( (EventRef
) wxTheApp
->MacGetCurrentEvent() , &rec
) ;
2632 TXNClick( m_txn
, &rec
);
2644 void wxMacMLTEClassicControl::MacControlUserPaneIdleProc()
2646 wxTextCtrl
* textctrl
= (wxTextCtrl
*)GetControlReference( m_controlRef
);
2647 if ( textctrl
== NULL
)
2650 if (textctrl
->MacIsReallyShown())
2652 if (IsControlActive(m_controlRef
))
2656 wxMacWindowClipper
clipper( textctrl
) ;
2661 if (PtInRect(mousep
, &m_txnControlBounds
))
2663 RgnHandle theRgn
= NewRgn();
2664 RectRgn(theRgn
, &m_txnControlBounds
);
2665 TXNAdjustCursor(m_txn
, theRgn
);
2672 wxInt16
wxMacMLTEClassicControl::MacControlUserPaneKeyDownProc (wxInt16 keyCode
, wxInt16 charCode
, wxInt16 modifiers
)
2674 wxTextCtrl
* textctrl
= (wxTextCtrl
*)GetControlReference( m_controlRef
);
2675 if ( textctrl
== NULL
)
2676 return kControlNoPart
;
2678 wxMacWindowClipper
clipper( textctrl
) ;
2681 memset( &ev
, 0 , sizeof( ev
) ) ;
2683 ev
.modifiers
= modifiers
;
2684 ev
.message
= ((keyCode
<< 8) & keyCodeMask
) | (charCode
& charCodeMask
);
2685 TXNKeyDown( m_txn
, &ev
);
2687 return kControlEntireControl
;
2690 void wxMacMLTEClassicControl::MacControlUserPaneActivateProc(bool activating
)
2692 MacActivatePaneText( activating
);
2695 wxInt16
wxMacMLTEClassicControl::MacControlUserPaneFocusProc(wxInt16 action
)
2697 ControlPartCode focusResult
= kControlFocusNoPart
;
2699 wxTextCtrl
* textctrl
= (wxTextCtrl
*)GetControlReference( m_controlRef
);
2700 if ( textctrl
== NULL
)
2703 wxMacWindowClipper
clipper( textctrl
) ;
2705 ControlRef controlFocus
= NULL
;
2706 GetKeyboardFocus( m_txnWindow
, &controlFocus
) ;
2707 bool wasFocused
= ( controlFocus
== m_controlRef
) ;
2711 case kControlFocusPrevPart
:
2712 case kControlFocusNextPart
:
2713 MacFocusPaneText( !wasFocused
);
2714 focusResult
= (!wasFocused
? (ControlPartCode
) kControlEditTextPart
: (ControlPartCode
) kControlFocusNoPart
);
2717 case kControlFocusNoPart
:
2719 MacFocusPaneText( false );
2720 focusResult
= kControlFocusNoPart
;
2727 void wxMacMLTEClassicControl::MacControlUserPaneBackgroundProc( void *info
)
2731 wxMacMLTEClassicControl::wxMacMLTEClassicControl( wxTextCtrl
*wxPeer
,
2732 const wxString
& str
,
2734 const wxSize
& size
, long style
)
2735 : wxMacMLTEControl( wxPeer
)
2737 m_font
= wxPeer
->GetFont() ;
2738 m_windowStyle
= style
;
2739 Rect bounds
= wxMacGetBoundsForControl( wxPeer
, pos
, size
) ;
2742 kControlSupportsEmbedding
| kControlSupportsFocus
| kControlWantsIdle
2743 | kControlWantsActivate
| kControlHandlesTracking
2744 // | kControlHasSpecialBackground
2745 | kControlGetsFocusOnClick
| kControlSupportsLiveFeedback
;
2747 OSStatus err
= ::CreateUserPaneControl(
2748 MAC_WXHWND(wxPeer
->GetParent()->MacGetTopLevelWindowRef()),
2749 &bounds
, featureSet
, &m_controlRef
);
2750 verify_noerr( err
);
2754 AdjustCreationAttributes( *wxWHITE
, true ) ;
2756 MacSetObjectVisibility( wxPeer
->MacIsReallyShown() ) ;
2760 wxMacConvertNewlines10To13( &st
) ;
2761 wxMacWindowClipper
clipper( m_peer
) ;
2762 SetTXNData( st
, kTXNStartOffset
, kTXNEndOffset
) ;
2763 TXNSetSelection( m_txn
, 0, 0 ) ;
2767 wxMacMLTEClassicControl::~wxMacMLTEClassicControl()
2769 TXNDeleteObject( m_txn
);
2773 void wxMacMLTEClassicControl::VisibilityChanged(bool shown
)
2775 MacSetObjectVisibility( shown
) ;
2776 wxMacControl::VisibilityChanged( shown
) ;
2779 void wxMacMLTEClassicControl::SuperChangedPosition()
2781 MacUpdatePosition() ;
2782 wxMacControl::SuperChangedPosition() ;
2785 #ifdef __WXMAC_OSX__
2787 ControlUserPaneDrawUPP gTPDrawProc
= NULL
;
2788 ControlUserPaneHitTestUPP gTPHitProc
= NULL
;
2789 ControlUserPaneTrackingUPP gTPTrackProc
= NULL
;
2790 ControlUserPaneIdleUPP gTPIdleProc
= NULL
;
2791 ControlUserPaneKeyDownUPP gTPKeyProc
= NULL
;
2792 ControlUserPaneActivateUPP gTPActivateProc
= NULL
;
2793 ControlUserPaneFocusUPP gTPFocusProc
= NULL
;
2795 static pascal void wxMacControlUserPaneDrawProc(ControlRef control
, SInt16 part
)
2797 wxTextCtrl
*textCtrl
= wxDynamicCast( wxFindControlFromMacControl(control
) , wxTextCtrl
) ;
2798 wxMacMLTEClassicControl
* win
= textCtrl
? (wxMacMLTEClassicControl
*)(textCtrl
->GetPeer()) : NULL
;
2800 win
->MacControlUserPaneDrawProc( part
) ;
2803 static pascal ControlPartCode
wxMacControlUserPaneHitTestProc(ControlRef control
, Point where
)
2805 wxTextCtrl
*textCtrl
= wxDynamicCast( wxFindControlFromMacControl(control
) , wxTextCtrl
) ;
2806 wxMacMLTEClassicControl
* win
= textCtrl
? (wxMacMLTEClassicControl
*)(textCtrl
->GetPeer()) : NULL
;
2808 return win
->MacControlUserPaneHitTestProc( where
.h
, where
.v
) ;
2810 return kControlNoPart
;
2813 static pascal ControlPartCode
wxMacControlUserPaneTrackingProc(ControlRef control
, Point startPt
, ControlActionUPP actionProc
)
2815 wxTextCtrl
*textCtrl
= wxDynamicCast( wxFindControlFromMacControl(control
) , wxTextCtrl
) ;
2816 wxMacMLTEClassicControl
* win
= textCtrl
? (wxMacMLTEClassicControl
*)(textCtrl
->GetPeer()) : NULL
;
2818 return win
->MacControlUserPaneTrackingProc( startPt
.h
, startPt
.v
, (void*) actionProc
) ;
2820 return kControlNoPart
;
2823 static pascal void wxMacControlUserPaneIdleProc(ControlRef control
)
2825 wxTextCtrl
*textCtrl
= wxDynamicCast( wxFindControlFromMacControl(control
) , wxTextCtrl
) ;
2826 wxMacMLTEClassicControl
* win
= textCtrl
? (wxMacMLTEClassicControl
*)(textCtrl
->GetPeer()) : NULL
;
2828 win
->MacControlUserPaneIdleProc() ;
2831 static pascal ControlPartCode
wxMacControlUserPaneKeyDownProc(ControlRef control
, SInt16 keyCode
, SInt16 charCode
, SInt16 modifiers
)
2833 wxTextCtrl
*textCtrl
= wxDynamicCast( wxFindControlFromMacControl(control
) , wxTextCtrl
) ;
2834 wxMacMLTEClassicControl
* win
= textCtrl
? (wxMacMLTEClassicControl
*)(textCtrl
->GetPeer()) : NULL
;
2836 return win
->MacControlUserPaneKeyDownProc( keyCode
, charCode
, modifiers
) ;
2838 return kControlNoPart
;
2841 static pascal void wxMacControlUserPaneActivateProc(ControlRef control
, Boolean activating
)
2843 wxTextCtrl
*textCtrl
= wxDynamicCast( wxFindControlFromMacControl(control
) , wxTextCtrl
) ;
2844 wxMacMLTEClassicControl
* win
= textCtrl
? (wxMacMLTEClassicControl
*)(textCtrl
->GetPeer()) : NULL
;
2846 win
->MacControlUserPaneActivateProc( activating
) ;
2849 static pascal ControlPartCode
wxMacControlUserPaneFocusProc(ControlRef control
, ControlFocusPart action
)
2851 wxTextCtrl
*textCtrl
= wxDynamicCast( wxFindControlFromMacControl(control
) , wxTextCtrl
) ;
2852 wxMacMLTEClassicControl
* win
= textCtrl
? (wxMacMLTEClassicControl
*)(textCtrl
->GetPeer()) : NULL
;
2854 return win
->MacControlUserPaneFocusProc( action
) ;
2856 return kControlNoPart
;
2860 static pascal void wxMacControlUserPaneBackgroundProc(ControlRef control
, ControlBackgroundPtr info
)
2862 wxTextCtrl
*textCtrl
= wxDynamicCast( wxFindControlFromMacControl(control
) , wxTextCtrl
) ;
2863 wxMacMLTEClassicControl
* win
= textCtrl
? (wxMacMLTEClassicControl
*)(textCtrl
->GetPeer()) : NULL
;
2865 win
->MacControlUserPaneBackgroundProc(info
) ;
2869 #endif // __WXMAC_OSX__
2871 // TXNRegisterScrollInfoProc
2873 OSStatus
wxMacMLTEClassicControl::DoCreate()
2876 OSStatus err
= noErr
;
2878 // set up our globals
2879 #ifdef __WXMAC_OSX__
2880 if (gTPDrawProc
== NULL
) gTPDrawProc
= NewControlUserPaneDrawUPP(wxMacControlUserPaneDrawProc
);
2881 if (gTPHitProc
== NULL
) gTPHitProc
= NewControlUserPaneHitTestUPP(wxMacControlUserPaneHitTestProc
);
2882 if (gTPTrackProc
== NULL
) gTPTrackProc
= NewControlUserPaneTrackingUPP(wxMacControlUserPaneTrackingProc
);
2883 if (gTPIdleProc
== NULL
) gTPIdleProc
= NewControlUserPaneIdleUPP(wxMacControlUserPaneIdleProc
);
2884 if (gTPKeyProc
== NULL
) gTPKeyProc
= NewControlUserPaneKeyDownUPP(wxMacControlUserPaneKeyDownProc
);
2885 if (gTPActivateProc
== NULL
) gTPActivateProc
= NewControlUserPaneActivateUPP(wxMacControlUserPaneActivateProc
);
2886 if (gTPFocusProc
== NULL
) gTPFocusProc
= NewControlUserPaneFocusUPP(wxMacControlUserPaneFocusProc
);
2888 if (gTXNScrollInfoProc
== NULL
) gTXNScrollInfoProc
= NewTXNScrollInfoUPP(TXNScrollInfoProc
) ;
2889 if (gTXNScrollActionProc
== NULL
) gTXNScrollActionProc
= NewControlActionUPP(TXNScrollActionProc
) ;
2892 // set the initial settings for our private data
2894 m_txnWindow
= GetControlOwner(m_controlRef
);
2895 m_txnPort
= (GrafPtr
) GetWindowPort(m_txnWindow
);
2897 #ifdef __WXMAC_OSX__
2898 // set up the user pane procedures
2899 SetControlData(m_controlRef
, kControlEntireControl
, kControlUserPaneDrawProcTag
, sizeof(gTPDrawProc
), &gTPDrawProc
);
2900 SetControlData(m_controlRef
, kControlEntireControl
, kControlUserPaneHitTestProcTag
, sizeof(gTPHitProc
), &gTPHitProc
);
2901 SetControlData(m_controlRef
, kControlEntireControl
, kControlUserPaneTrackingProcTag
, sizeof(gTPTrackProc
), &gTPTrackProc
);
2902 SetControlData(m_controlRef
, kControlEntireControl
, kControlUserPaneIdleProcTag
, sizeof(gTPIdleProc
), &gTPIdleProc
);
2903 SetControlData(m_controlRef
, kControlEntireControl
, kControlUserPaneKeyDownProcTag
, sizeof(gTPKeyProc
), &gTPKeyProc
);
2904 SetControlData(m_controlRef
, kControlEntireControl
, kControlUserPaneActivateProcTag
, sizeof(gTPActivateProc
), &gTPActivateProc
);
2905 SetControlData(m_controlRef
, kControlEntireControl
, kControlUserPaneFocusProcTag
, sizeof(gTPFocusProc
), &gTPFocusProc
);
2908 // calculate the rectangles used by the control
2909 UMAGetControlBoundsInWindowCoords( m_controlRef
, &bounds
);
2911 m_txnControlBounds
= bounds
;
2912 m_txnVisBounds
= bounds
;
2917 GetGWorld( &origPort
, &origDev
) ;
2918 SetPort( m_txnPort
);
2920 // create the new edit field
2921 TXNFrameOptions frameOptions
= FrameOptionsFromWXStyle( m_windowStyle
);
2923 #ifdef __WXMAC_OSX__
2924 // the scrollbars are not correctly embedded but are inserted at the root:
2925 // this gives us problems as we have erratic redraws even over the structure area
2927 m_sbHorizontal
= 0 ;
2929 m_lastHorizontalValue
= 0 ;
2930 m_lastVerticalValue
= 0 ;
2932 Rect sb
= { 0 , 0 , 0 , 0 } ;
2933 if ( frameOptions
& kTXNWantVScrollBarMask
)
2935 CreateScrollBarControl( m_txnWindow
, &sb
, 0, 0, 100, 1, true, gTXNScrollActionProc
, &m_sbVertical
);
2936 SetControlReference( m_sbVertical
, (SInt32
)this );
2937 SetControlAction( m_sbVertical
, gTXNScrollActionProc
);
2938 ShowControl( m_sbVertical
);
2939 EmbedControl( m_sbVertical
, m_controlRef
);
2940 frameOptions
&= ~kTXNWantVScrollBarMask
;
2943 if ( frameOptions
& kTXNWantHScrollBarMask
)
2945 CreateScrollBarControl( m_txnWindow
, &sb
, 0, 0, 100, 1, true, gTXNScrollActionProc
, &m_sbHorizontal
);
2946 SetControlReference( m_sbHorizontal
, (SInt32
)this );
2947 SetControlAction( m_sbHorizontal
, gTXNScrollActionProc
);
2948 ShowControl( m_sbHorizontal
);
2949 EmbedControl( m_sbHorizontal
, m_controlRef
);
2950 frameOptions
&= ~(kTXNWantHScrollBarMask
| kTXNDrawGrowIconMask
);
2956 NULL
, m_txnWindow
, &bounds
, frameOptions
,
2957 kTXNTextEditStyleFrameType
, kTXNTextensionFile
, kTXNSystemDefaultEncoding
,
2958 &m_txn
, &m_txnFrameID
, NULL
);
2959 verify_noerr( err
);
2962 TXNControlTag iControlTags
[] = { kTXNUseCarbonEvents
};
2963 TXNControlData iControlData
[] = { { (UInt32
)&cInfo
} };
2964 int toptag
= WXSIZEOF( iControlTags
) ;
2965 TXNCarbonEventInfo cInfo
;
2966 cInfo
.useCarbonEvents
= false ;
2969 cInfo
.fDictionary
= NULL
;
2971 verify_noerr( TXNSetTXNObjectControls( m_txn
, false, toptag
, iControlTags
, iControlData
) );
2974 #ifdef __WXMAC_OSX__
2975 TXNRegisterScrollInfoProc( m_txn
, gTXNScrollInfoProc
, (SInt32
)this );
2978 SetGWorld( origPort
, origDev
) ;
2983 // ----------------------------------------------------------------------------
2984 // MLTE control implementation (OSX part)
2985 // ----------------------------------------------------------------------------
2987 #if TARGET_API_MAC_OSX
2989 #if MAC_OS_X_VERSION_MAX_ALLOWED > MAC_OS_X_VERSION_10_2
2991 // tiger multi-line textcontrols with no CR in the entire content
2992 // don't scroll automatically, so we need a hack.
2993 // This attempt only works 'before' the key (ie before CallNextEventHandler)
2994 // is processed, thus the scrolling always occurs one character too late, but
2995 // better than nothing ...
2997 static const EventTypeSpec eventList
[] =
2999 { kEventClassTextInput
, kEventTextInputUnicodeForKeyEvent
} ,
3002 static pascal OSStatus
wxMacUnicodeTextEventHandler( EventHandlerCallRef handler
, EventRef event
, void *data
)
3004 OSStatus result
= eventNotHandledErr
;
3005 wxMacMLTEHIViewControl
* focus
= (wxMacMLTEHIViewControl
*) data
;
3007 switch ( GetEventKind( event
) )
3009 case kEventTextInputUnicodeForKeyEvent
:
3011 if ( UMAGetSystemVersion() >= 0x1040 )
3013 TXNOffset from
, to
;
3014 TXNGetSelection( focus
->GetTXNObject() , &from
, &to
) ;
3016 TXNShowSelection( focus
->GetTXNObject() , kTXNShowStart
);
3018 result
= CallNextEventHandler(handler
,event
);
3028 static pascal OSStatus
wxMacTextControlEventHandler( EventHandlerCallRef handler
, EventRef event
, void *data
)
3030 OSStatus result
= eventNotHandledErr
;
3032 switch ( GetEventClass( event
) )
3034 case kEventClassTextInput
:
3035 result
= wxMacUnicodeTextEventHandler( handler
, event
, data
) ;
3044 DEFINE_ONE_SHOT_HANDLER_GETTER( wxMacTextControlEventHandler
)
3046 wxMacMLTEHIViewControl::wxMacMLTEHIViewControl( wxTextCtrl
*wxPeer
,
3047 const wxString
& str
,
3049 const wxSize
& size
, long style
) : wxMacMLTEControl( wxPeer
)
3051 m_font
= wxPeer
->GetFont() ;
3052 m_windowStyle
= style
;
3053 Rect bounds
= wxMacGetBoundsForControl( wxPeer
, pos
, size
) ;
3055 wxMacConvertNewlines10To13( &st
) ;
3058 { bounds
.left
, bounds
.top
},
3059 { bounds
.right
- bounds
.left
, bounds
.bottom
- bounds
.top
} } ;
3061 m_scrollView
= NULL
;
3062 TXNFrameOptions frameOptions
= FrameOptionsFromWXStyle( style
) ;
3063 if ( frameOptions
& (kTXNWantVScrollBarMask
| kTXNWantHScrollBarMask
) )
3066 (frameOptions
& kTXNWantHScrollBarMask
? kHIScrollViewOptionsHorizScroll
: 0)
3067 | (frameOptions
& kTXNWantVScrollBarMask
? kHIScrollViewOptionsVertScroll
: 0) ,
3070 HIViewSetFrame( m_scrollView
, &hr
);
3071 HIViewSetVisible( m_scrollView
, true );
3075 HITextViewCreate( NULL
, 0, frameOptions
, &m_textView
) ;
3076 m_txn
= HITextViewGetTXNObject( m_textView
) ;
3077 HIViewSetVisible( m_textView
, true ) ;
3080 HIViewAddSubview( m_scrollView
, m_textView
) ;
3081 m_controlRef
= m_scrollView
;
3082 wxPeer
->MacInstallEventHandler( (WXWidget
) m_textView
) ;
3086 HIViewSetFrame( m_textView
, &hr
);
3087 m_controlRef
= m_textView
;
3090 AdjustCreationAttributes( *wxWHITE
, true ) ;
3092 wxMacWindowClipper
c( m_peer
) ;
3093 SetTXNData( st
, kTXNStartOffset
, kTXNEndOffset
) ;
3095 TXNSetSelection( m_txn
, 0, 0 );
3096 TXNShowSelection( m_txn
, kTXNShowStart
);
3098 InstallControlEventHandler( m_textView
, GetwxMacTextControlEventHandlerUPP(),
3099 GetEventTypeCount(eventList
), eventList
, this,
3100 &m_textEventHandlerRef
);
3103 wxMacMLTEHIViewControl::~wxMacMLTEHIViewControl()
3105 ::RemoveEventHandler( m_textEventHandlerRef
) ;
3108 OSStatus
wxMacMLTEHIViewControl::SetFocus( ControlFocusPart focusPart
)
3110 return SetKeyboardFocus( GetControlOwner( m_textView
), m_textView
, focusPart
) ;
3113 bool wxMacMLTEHIViewControl::HasFocus() const
3115 ControlRef control
;
3116 GetKeyboardFocus( GetUserFocusWindow() , &control
) ;
3117 return control
== m_textView
;
3120 void wxMacMLTEHIViewControl::SetBackground( const wxBrush
&brush
)
3122 wxMacMLTEControl::SetBackground( brush
) ;
3125 CGColorSpaceRef rgbSpace
= CGColorSpaceCreateDeviceRGB();
3126 RGBColor col
= MAC_WXCOLORREF(brush
.GetColour().GetPixel()) ;
3128 float component
[4] ;
3129 component
[0] = col
.red
/ 65536.0 ;
3130 component
[1] = col
.green
/ 65536.0 ;
3131 component
[2] = col
.blue
/ 65536.0 ;
3132 component
[3] = 1.0 ; // alpha
3134 CGColorRef color
= CGColorCreate( rgbSpace
, component
);
3135 HITextViewSetBackgroundColor( m_textView
, color
);
3136 CGColorSpaceRelease( rgbSpace
);
3140 #endif // MAC_OS_X_VERSION_MAX_ALLOWED > MAC_OS_X_VERSION_10_2
3145 #endif // wxUSE_TEXTCTRL