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"
70 kTXNVisibilityTag
= 'visb' // set the visibility state of the object
79 virtual ~wxMacFunctor() {}
81 virtual void* operator()() = 0 ;
83 static void* CallBackProc( void *param
)
85 wxMacFunctor
* f
= (wxMacFunctor
*) param
;
86 void *result
= (*f
)() ;
91 template<typename classtype
, typename param1type
>
93 class wxMacObjectFunctor1
: public wxMacFunctor
95 typedef void (classtype::*function
)( param1type p1
) ;
96 typedef void (classtype::*ref_function
)( const param1type
& p1
) ;
98 wxMacObjectFunctor1( classtype
*obj
, function f
, param1type p1
) :
106 wxMacObjectFunctor1( classtype
*obj
, ref_function f
, param1type p1
) :
114 virtual ~wxMacObjectFunctor1() {}
116 virtual void* operator()()
118 (m_object
->*m_function
)( m_param1
) ;
123 classtype
* m_object
;
124 param1type m_param1
;
127 function m_function
;
128 ref_function m_refFunction
;
132 template<typename classtype
, typename param1type
>
133 void* wxMacMPRemoteCall( classtype
*object
, void (classtype::*function
)( param1type p1
) , param1type p1
)
135 wxMacObjectFunctor1
<classtype
, param1type
> params(object
, function
, p1
) ;
137 MPRemoteCall( wxMacFunctor::CallBackProc
, ¶ms
, kMPOwningProcessRemoteContext
) ;
141 template<typename classtype
, typename param1type
>
142 void* wxMacMPRemoteCall( classtype
*object
, void (classtype::*function
)( const param1type
& p1
) , param1type p1
)
144 wxMacObjectFunctor1
<classtype
,param1type
> params(object
, function
, p1
) ;
146 MPRemoteCall( wxMacFunctor::CallBackProc
, ¶ms
, kMPOwningProcessRemoteContext
) ;
150 template<typename classtype
, typename param1type
>
151 void* wxMacMPRemoteGUICall( classtype
*object
, void (classtype::*function
)( param1type p1
) , param1type p1
)
154 void *result
= wxMacMPRemoteCall( object
, function
, p1
) ;
159 template<typename classtype
, typename param1type
>
160 void* wxMacMPRemoteGUICall( classtype
*object
, void (classtype::*function
)( const param1type
& p1
) , param1type p1
)
163 void *result
= wxMacMPRemoteCall( object
, function
, p1
) ;
168 // common interface for all implementations
169 class wxMacTextControl
: public wxMacControl
172 wxMacTextControl( wxTextCtrl
*peer
) ;
173 virtual ~wxMacTextControl() ;
175 virtual wxString
GetStringValue() const = 0 ;
176 virtual void SetStringValue( const wxString
&val
) = 0 ;
177 virtual void SetSelection( long from
, long to
) = 0 ;
178 virtual void GetSelection( long* from
, long* to
) const = 0 ;
179 virtual void WriteText( const wxString
& str
) = 0 ;
181 virtual void SetStyle( long start
, long end
, const wxTextAttr
& style
) ;
182 virtual void Copy() ;
184 virtual void Paste() ;
185 virtual bool CanPaste() const ;
186 virtual void SetEditable( bool editable
) ;
187 virtual wxTextPos
GetLastPosition() const ;
188 virtual void Replace( long from
, long to
, const wxString
&str
) ;
189 virtual void Remove( long from
, long to
) ;
192 virtual bool HasOwnContextMenu() const
195 virtual bool SetupCursor( const wxPoint
& pt
)
198 virtual void Clear() ;
199 virtual bool CanUndo() const;
200 virtual void Undo() ;
201 virtual bool CanRedo() const;
202 virtual void Redo() ;
203 virtual int GetNumberOfLines() const ;
204 virtual long XYToPosition(long x
, long y
) const;
205 virtual bool PositionToXY(long pos
, long *x
, long *y
) const ;
206 virtual void ShowPosition(long WXUNUSED(pos
)) ;
207 virtual int GetLineLength(long lineNo
) const ;
208 virtual wxString
GetLineText(long lineNo
) const ;
209 virtual void CheckSpelling(bool check
) { }
211 #ifndef __WXMAC_OSX__
212 virtual void MacControlUserPaneDrawProc(wxInt16 part
) = 0 ;
213 virtual wxInt16
MacControlUserPaneHitTestProc(wxInt16 x
, wxInt16 y
) = 0 ;
214 virtual wxInt16
MacControlUserPaneTrackingProc(wxInt16 x
, wxInt16 y
, void* actionProc
) = 0 ;
215 virtual void MacControlUserPaneIdleProc() = 0 ;
216 virtual wxInt16
MacControlUserPaneKeyDownProc(wxInt16 keyCode
, wxInt16 charCode
, wxInt16 modifiers
) = 0 ;
217 virtual void MacControlUserPaneActivateProc(bool activating
) = 0 ;
218 virtual wxInt16
MacControlUserPaneFocusProc(wxInt16 action
) = 0 ;
219 virtual void MacControlUserPaneBackgroundProc(void* info
) = 0 ;
223 // common parts for implementations based on MLTE
225 class wxMacMLTEControl
: public wxMacTextControl
228 wxMacMLTEControl( wxTextCtrl
*peer
) ;
230 virtual wxString
GetStringValue() const ;
231 virtual void SetStringValue( const wxString
&str
) ;
233 static TXNFrameOptions
FrameOptionsFromWXStyle( long wxStyle
) ;
235 void AdjustCreationAttributes( const wxColour
& background
, bool visible
) ;
237 virtual void SetFont( const wxFont
& font
, const wxColour
& foreground
, long windowStyle
) ;
238 virtual void SetBackground( const wxBrush
&brush
) ;
239 virtual void SetStyle( long start
, long end
, const wxTextAttr
& style
) ;
240 virtual void Copy() ;
242 virtual void Paste() ;
243 virtual bool CanPaste() const ;
244 virtual void SetEditable( bool editable
) ;
245 virtual wxTextPos
GetLastPosition() const ;
246 virtual void Replace( long from
, long to
, const wxString
&str
) ;
247 virtual void Remove( long from
, long to
) ;
248 virtual void GetSelection( long* from
, long* to
) const ;
249 virtual void SetSelection( long from
, long to
) ;
251 virtual void WriteText( const wxString
& str
) ;
253 virtual bool HasOwnContextMenu() const
255 #if MAC_OS_X_VERSION_MAX_ALLOWED >= MAC_OS_X_VERSION_10_4
256 if ( UMAGetSystemVersion() >= 0x1040 )
258 TXNCommandEventSupportOptions options
;
259 TXNGetCommandEventSupport( m_txn
, & options
) ;
260 return options
& kTXNSupportEditCommandProcessing
;
267 virtual void CheckSpelling(bool check
)
269 #if MAC_OS_X_VERSION_MAX_ALLOWED >= MAC_OS_X_VERSION_10_4
270 TXNSetSpellCheckAsYouType( m_txn
, (Boolean
) check
);
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))
491 #if MAC_OS_X_VERSION_MAX_ALLOWED >= MAC_OS_X_VERSION_10_5
496 #if MAC_OS_X_VERSION_MAX_ALLOWED > MAC_OS_X_VERSION_10_2
497 if ( UMAGetSystemVersion() >= 0x1030 && !forceMLTE
)
499 if ( m_windowStyle
& wxTE_MULTILINE
)
500 m_peer
= new wxMacMLTEHIViewControl( this , str
, pos
, size
, style
) ;
506 #if MAC_OS_X_VERSION_MAX_ALLOWED < MAC_OS_X_VERSION_10_5
507 if ( !(m_windowStyle
& wxTE_MULTILINE
) && !forceMLTE
)
510 m_peer
= new wxMacUnicodeTextControl( this , str
, pos
, size
, style
) ;
515 // the horizontal single line scrolling bug that made us keep
516 #if MAC_OS_X_VERSION_MAX_ALLOWED < MAC_OS_X_VERSION_10_5
518 m_peer
= new wxMacMLTEClassicControl( this , str
, pos
, size
, style
) ;
521 MacPostControlCreate(pos
, size
) ;
523 // only now the embedding is correct and we can do a positioning update
525 MacSuperChangedPosition() ;
527 if ( m_windowStyle
& wxTE_READONLY
)
528 SetEditable( false ) ;
530 SetCursor( wxCursor( wxCURSOR_IBEAM
) ) ;
535 void wxTextCtrl::MacSuperChangedPosition()
537 wxWindow::MacSuperChangedPosition() ;
538 GetPeer()->SuperChangedPosition() ;
541 void wxTextCtrl::MacVisibilityChanged()
543 GetPeer()->VisibilityChanged( MacIsReallyShown() ) ;
546 void wxTextCtrl::MacEnabledStateChanged()
550 void wxTextCtrl::MacCheckSpelling(bool check
)
552 GetPeer()->CheckSpelling(check
);
555 wxString
wxTextCtrl::GetValue() const
557 return GetPeer()->GetStringValue() ;
560 void wxTextCtrl::GetSelection(long* from
, long* to
) const
562 GetPeer()->GetSelection( from
, to
) ;
565 void wxTextCtrl::DoSetValue(const wxString
& str
, int flags
)
568 if ( GetValue() == str
)
571 GetPeer()->SetStringValue( str
) ;
573 if ( (flags
& SetValue_SendEvent
) && m_triggerOnSetValue
)
575 SendTextUpdatedEvent();
579 void wxTextCtrl::SetMaxLength(unsigned long len
)
584 bool wxTextCtrl::SetFont( const wxFont
& font
)
586 if ( !wxTextCtrlBase::SetFont( font
) )
589 GetPeer()->SetFont( font
, GetForegroundColour() , GetWindowStyle() ) ;
594 bool wxTextCtrl::SetStyle(long start
, long end
, const wxTextAttr
& style
)
596 GetPeer()->SetStyle( start
, end
, style
) ;
601 bool wxTextCtrl::SetDefaultStyle(const wxTextAttr
& style
)
603 wxTextCtrlBase::SetDefaultStyle( style
) ;
604 SetStyle( kTXNUseCurrentSelection
, kTXNUseCurrentSelection
, GetDefaultStyle() ) ;
609 // Clipboard operations
611 void wxTextCtrl::Copy()
617 void wxTextCtrl::Cut()
623 wxCommandEvent
event( wxEVT_COMMAND_TEXT_UPDATED
, m_windowId
);
624 event
.SetEventObject( this );
625 GetEventHandler()->ProcessEvent( event
);
629 void wxTextCtrl::Paste()
635 // TODO: eventually we should add setting the default style again
637 wxCommandEvent
event( wxEVT_COMMAND_TEXT_UPDATED
, m_windowId
);
638 event
.SetEventObject( this );
639 GetEventHandler()->ProcessEvent( event
);
643 bool wxTextCtrl::CanCopy() const
645 // Can copy if there's a selection
647 GetSelection( &from
, &to
);
652 bool wxTextCtrl::CanCut() const
657 // Can cut if there's a selection
659 GetSelection( &from
, &to
);
664 bool wxTextCtrl::CanPaste() const
669 return GetPeer()->CanPaste() ;
672 void wxTextCtrl::SetEditable(bool editable
)
674 if ( editable
!= m_editable
)
676 m_editable
= editable
;
677 GetPeer()->SetEditable( editable
) ;
681 void wxTextCtrl::SetInsertionPoint(long pos
)
683 SetSelection( pos
, pos
) ;
686 void wxTextCtrl::SetInsertionPointEnd()
688 wxTextPos pos
= GetLastPosition();
689 SetInsertionPoint( pos
);
692 long wxTextCtrl::GetInsertionPoint() const
695 GetSelection( &begin
, &end
) ;
700 wxTextPos
wxTextCtrl::GetLastPosition() const
702 return GetPeer()->GetLastPosition() ;
705 void wxTextCtrl::Replace(long from
, long to
, const wxString
& str
)
707 GetPeer()->Replace( from
, to
, str
) ;
710 void wxTextCtrl::Remove(long from
, long to
)
712 GetPeer()->Remove( from
, to
) ;
715 void wxTextCtrl::SetSelection(long from
, long to
)
717 GetPeer()->SetSelection( from
, to
) ;
720 void wxTextCtrl::WriteText(const wxString
& str
)
722 // TODO: this MPRemoting will be moved into a remoting peer proxy for any command
723 if ( !wxIsMainThread() )
725 // unfortunately CW 8 is not able to correctly deduce the template types,
726 // so we have to instantiate explicitly
727 wxMacMPRemoteGUICall
<wxTextCtrl
,wxString
>( this , &wxTextCtrl::WriteText
, str
) ;
732 GetPeer()->WriteText( str
) ;
735 void wxTextCtrl::AppendText(const wxString
& text
)
737 SetInsertionPointEnd();
741 void wxTextCtrl::Clear()
746 bool wxTextCtrl::IsModified() const
751 bool wxTextCtrl::IsEditable() const
753 return IsEnabled() && m_editable
;
756 bool wxTextCtrl::AcceptsFocus() const
758 // we don't want focus if we can't be edited
759 return /*IsEditable() && */ wxControl::AcceptsFocus();
762 wxSize
wxTextCtrl::DoGetBestSize() const
766 // these are the numbers from the HIG:
767 // we reduce them by the borders first
770 switch ( m_windowVariant
)
772 case wxWINDOW_VARIANT_NORMAL
:
776 case wxWINDOW_VARIANT_SMALL
:
780 case wxWINDOW_VARIANT_MINI
:
789 // as the above numbers have some free space around the text
790 // we get 5 lines like this anyway
791 if ( m_windowStyle
& wxTE_MULTILINE
)
794 if ( !HasFlag(wxNO_BORDER
) )
797 return wxSize(wText
, hText
);
800 // ----------------------------------------------------------------------------
802 // ----------------------------------------------------------------------------
804 void wxTextCtrl::Undo()
810 void wxTextCtrl::Redo()
816 bool wxTextCtrl::CanUndo() const
821 return GetPeer()->CanUndo() ;
824 bool wxTextCtrl::CanRedo() const
829 return GetPeer()->CanRedo() ;
832 void wxTextCtrl::MarkDirty()
837 void wxTextCtrl::DiscardEdits()
842 int wxTextCtrl::GetNumberOfLines() const
844 return GetPeer()->GetNumberOfLines() ;
847 long wxTextCtrl::XYToPosition(long x
, long y
) const
849 return GetPeer()->XYToPosition( x
, y
) ;
852 bool wxTextCtrl::PositionToXY(long pos
, long *x
, long *y
) const
854 return GetPeer()->PositionToXY( pos
, x
, y
) ;
857 void wxTextCtrl::ShowPosition(long pos
)
859 return GetPeer()->ShowPosition(pos
) ;
862 int wxTextCtrl::GetLineLength(long lineNo
) const
864 return GetPeer()->GetLineLength(lineNo
) ;
867 wxString
wxTextCtrl::GetLineText(long lineNo
) const
869 return GetPeer()->GetLineText(lineNo
) ;
872 void wxTextCtrl::Command(wxCommandEvent
& event
)
874 SetValue(event
.GetString());
875 ProcessCommand(event
);
878 void wxTextCtrl::OnDropFiles(wxDropFilesEvent
& event
)
880 // By default, load the first file into the text window.
881 if (event
.GetNumberOfFiles() > 0)
882 LoadFile( event
.GetFiles()[0] );
885 void wxTextCtrl::OnEraseBackground(wxEraseEvent
& event
)
887 // all erasing should be done by the real mac control implementation
888 // while this is true for MLTE under classic, the HITextView is somehow
889 // transparent but background erase is not working correctly, so intercept
890 // things while we can...
894 void wxTextCtrl::OnChar(wxKeyEvent
& event
)
896 int key
= event
.GetKeyCode() ;
897 bool eat_key
= false ;
899 if ( key
== 'a' && event
.MetaDown() )
906 if ( key
== 'c' && event
.MetaDown() )
914 if ( !IsEditable() && key
!= WXK_LEFT
&& key
!= WXK_RIGHT
&& key
!= WXK_DOWN
&& key
!= WXK_UP
&& key
!= WXK_TAB
&&
915 !( key
== WXK_RETURN
&& ( (m_windowStyle
& wxTE_PROCESS_ENTER
) || (m_windowStyle
& wxTE_MULTILINE
) ) )
916 // && key != WXK_PAGEUP && key != WXK_PAGEDOWN && key != WXK_HOME && key != WXK_END
923 // Check if we have reached the max # of chars (if it is set), but still
924 // allow navigation and deletion
925 if ( !IsMultiLine() && m_maxLength
&& GetValue().length() >= m_maxLength
&&
926 key
!= WXK_LEFT
&& key
!= WXK_RIGHT
&& key
!= WXK_TAB
&&
927 key
!= WXK_BACK
&& !( key
== WXK_RETURN
&& (m_windowStyle
& wxTE_PROCESS_ENTER
) )
930 // eat it, we don't want to add more than allowed # of characters
932 // TODO: generate EVT_TEXT_MAXLEN()
936 // assume that any key not processed yet is going to modify the control
939 if ( key
== 'v' && event
.MetaDown() )
947 if ( key
== 'x' && event
.MetaDown() )
958 if (m_windowStyle
& wxTE_PROCESS_ENTER
)
960 wxCommandEvent
event(wxEVT_COMMAND_TEXT_ENTER
, m_windowId
);
961 event
.SetEventObject( this );
962 event
.SetString( GetValue() );
963 if ( GetEventHandler()->ProcessEvent(event
) )
967 if ( !(m_windowStyle
& wxTE_MULTILINE
) )
969 wxTopLevelWindow
*tlw
= wxDynamicCast(wxGetTopLevelParent(this), wxTopLevelWindow
);
970 if ( tlw
&& tlw
->GetDefaultItem() )
972 wxButton
*def
= wxDynamicCast(tlw
->GetDefaultItem(), wxButton
);
973 if ( def
&& def
->IsEnabled() )
975 wxCommandEvent
event(wxEVT_COMMAND_BUTTON_CLICKED
, def
->GetId() );
976 event
.SetEventObject(def
);
983 // this will make wxWidgets eat the ENTER key so that
984 // we actually prevent line wrapping in a single line text control
990 if ( !(m_windowStyle
& wxTE_PROCESS_TAB
))
993 if (!event
.ShiftDown())
994 flags
|= wxNavigationKeyEvent::IsForward
;
995 if (event
.ControlDown())
996 flags
|= wxNavigationKeyEvent::WinChange
;
1003 // This is necessary (don't know why);
1004 // otherwise the tab will not be inserted.
1005 WriteText(wxT("\t"));
1016 // perform keystroke handling
1020 if ( ( key
>= 0x20 && key
< WXK_START
) ||
1021 ( key
>= WXK_NUMPAD0
&& key
<= WXK_DIVIDE
) ||
1022 key
== WXK_RETURN
||
1023 key
== WXK_DELETE
||
1026 wxCommandEvent
event1(wxEVT_COMMAND_TEXT_UPDATED
, m_windowId
);
1027 event1
.SetEventObject( this );
1028 wxPostEvent( GetEventHandler(), event1
);
1032 // ----------------------------------------------------------------------------
1033 // standard handlers for standard edit menu events
1034 // ----------------------------------------------------------------------------
1036 void wxTextCtrl::OnCut(wxCommandEvent
& WXUNUSED(event
))
1041 void wxTextCtrl::OnCopy(wxCommandEvent
& WXUNUSED(event
))
1046 void wxTextCtrl::OnPaste(wxCommandEvent
& WXUNUSED(event
))
1051 void wxTextCtrl::OnUndo(wxCommandEvent
& WXUNUSED(event
))
1056 void wxTextCtrl::OnRedo(wxCommandEvent
& WXUNUSED(event
))
1061 void wxTextCtrl::OnDelete(wxCommandEvent
& WXUNUSED(event
))
1065 GetSelection( &from
, &to
);
1066 if (from
!= -1 && to
!= -1)
1070 void wxTextCtrl::OnSelectAll(wxCommandEvent
& WXUNUSED(event
))
1072 SetSelection(-1, -1);
1075 void wxTextCtrl::OnUpdateCut(wxUpdateUIEvent
& event
)
1077 event
.Enable( CanCut() );
1080 void wxTextCtrl::OnUpdateCopy(wxUpdateUIEvent
& event
)
1082 event
.Enable( CanCopy() );
1085 void wxTextCtrl::OnUpdatePaste(wxUpdateUIEvent
& event
)
1087 event
.Enable( CanPaste() );
1090 void wxTextCtrl::OnUpdateUndo(wxUpdateUIEvent
& event
)
1092 event
.Enable( CanUndo() );
1095 void wxTextCtrl::OnUpdateRedo(wxUpdateUIEvent
& event
)
1097 event
.Enable( CanRedo() );
1100 void wxTextCtrl::OnUpdateDelete(wxUpdateUIEvent
& event
)
1104 GetSelection( &from
, &to
);
1105 event
.Enable( from
!= -1 && to
!= -1 && from
!= to
&& IsEditable() ) ;
1108 void wxTextCtrl::OnUpdateSelectAll(wxUpdateUIEvent
& event
)
1110 event
.Enable(GetLastPosition() > 0);
1113 // CS: Context Menus only work with MLTE implementations or non-multiline HIViews at the moment
1115 void wxTextCtrl::OnContextMenu(wxContextMenuEvent
& event
)
1117 if ( GetPeer()->HasOwnContextMenu() )
1123 if (m_privateContextMenu
== NULL
)
1125 m_privateContextMenu
= new wxMenu
;
1126 m_privateContextMenu
->Append(wxID_UNDO
, _("&Undo"));
1127 m_privateContextMenu
->Append(wxID_REDO
, _("&Redo"));
1128 m_privateContextMenu
->AppendSeparator();
1129 m_privateContextMenu
->Append(wxID_CUT
, _("Cu&t"));
1130 m_privateContextMenu
->Append(wxID_COPY
, _("&Copy"));
1131 m_privateContextMenu
->Append(wxID_PASTE
, _("&Paste"));
1132 m_privateContextMenu
->Append(wxID_CLEAR
, _("&Delete"));
1133 m_privateContextMenu
->AppendSeparator();
1134 m_privateContextMenu
->Append(wxID_SELECTALL
, _("Select &All"));
1137 if (m_privateContextMenu
!= NULL
)
1138 PopupMenu(m_privateContextMenu
);
1141 bool wxTextCtrl::MacSetupCursor( const wxPoint
& pt
)
1143 if ( !GetPeer()->SetupCursor( pt
) )
1144 return wxWindow::MacSetupCursor( pt
) ;
1149 #if !TARGET_API_MAC_OSX
1151 // user pane implementation
1153 void wxTextCtrl::MacControlUserPaneDrawProc(wxInt16 part
)
1155 GetPeer()->MacControlUserPaneDrawProc( part
) ;
1158 wxInt16
wxTextCtrl::MacControlUserPaneHitTestProc(wxInt16 x
, wxInt16 y
)
1160 return GetPeer()->MacControlUserPaneHitTestProc( x
, y
) ;
1163 wxInt16
wxTextCtrl::MacControlUserPaneTrackingProc(wxInt16 x
, wxInt16 y
, void* actionProc
)
1165 return GetPeer()->MacControlUserPaneTrackingProc( x
, y
, actionProc
) ;
1168 void wxTextCtrl::MacControlUserPaneIdleProc()
1170 GetPeer()->MacControlUserPaneIdleProc( ) ;
1173 wxInt16
wxTextCtrl::MacControlUserPaneKeyDownProc(wxInt16 keyCode
, wxInt16 charCode
, wxInt16 modifiers
)
1175 return GetPeer()->MacControlUserPaneKeyDownProc( keyCode
, charCode
, modifiers
) ;
1178 void wxTextCtrl::MacControlUserPaneActivateProc(bool activating
)
1180 GetPeer()->MacControlUserPaneActivateProc( activating
) ;
1183 wxInt16
wxTextCtrl::MacControlUserPaneFocusProc(wxInt16 action
)
1185 return GetPeer()->MacControlUserPaneFocusProc( action
) ;
1188 void wxTextCtrl::MacControlUserPaneBackgroundProc(void* info
)
1190 GetPeer()->MacControlUserPaneBackgroundProc( info
) ;
1195 // ----------------------------------------------------------------------------
1196 // implementation base class
1197 // ----------------------------------------------------------------------------
1199 wxMacTextControl::wxMacTextControl(wxTextCtrl
* peer
) :
1200 wxMacControl( peer
)
1204 wxMacTextControl::~wxMacTextControl()
1208 void wxMacTextControl::SetStyle(long start
, long end
, const wxTextAttr
& style
)
1212 void wxMacTextControl::Copy()
1216 void wxMacTextControl::Cut()
1220 void wxMacTextControl::Paste()
1224 bool wxMacTextControl::CanPaste() const
1229 void wxMacTextControl::SetEditable(bool editable
)
1233 wxTextPos
wxMacTextControl::GetLastPosition() const
1235 return GetStringValue().length() ;
1238 void wxMacTextControl::Replace( long from
, long to
, const wxString
&val
)
1240 SetSelection( from
, to
) ;
1244 void wxMacTextControl::Remove( long from
, long to
)
1246 SetSelection( from
, to
) ;
1247 WriteText( wxEmptyString
) ;
1250 void wxMacTextControl::Clear()
1252 SetStringValue( wxEmptyString
) ;
1255 bool wxMacTextControl::CanUndo() const
1260 void wxMacTextControl::Undo()
1264 bool wxMacTextControl::CanRedo() const
1269 void wxMacTextControl::Redo()
1273 long wxMacTextControl::XYToPosition(long x
, long y
) const
1278 bool wxMacTextControl::PositionToXY(long pos
, long *x
, long *y
) const
1283 void wxMacTextControl::ShowPosition( long WXUNUSED(pos
) )
1287 int wxMacTextControl::GetNumberOfLines() const
1289 ItemCount lines
= 0 ;
1290 wxString content
= GetStringValue() ;
1293 for (size_t i
= 0; i
< content
.length() ; i
++)
1295 if (content
[i
] == '\r')
1302 wxString
wxMacTextControl::GetLineText(long lineNo
) const
1304 // TODO: change this if possible to reflect real lines
1305 wxString content
= GetStringValue() ;
1309 for (size_t i
= 0; i
< content
.length() ; i
++)
1311 if (count
== lineNo
)
1313 // Add chars in line then
1316 for (size_t j
= i
; j
< content
.length(); j
++)
1318 if (content
[j
] == '\n')
1327 if (content
[i
] == '\n')
1331 return wxEmptyString
;
1334 int wxMacTextControl::GetLineLength(long lineNo
) const
1336 // TODO: change this if possible to reflect real lines
1337 wxString content
= GetStringValue() ;
1341 for (size_t i
= 0; i
< content
.length() ; i
++)
1343 if (count
== lineNo
)
1345 // Count chars in line then
1347 for (size_t j
= i
; j
< content
.length(); j
++)
1350 if (content
[j
] == '\n')
1357 if (content
[i
] == '\n')
1364 // ----------------------------------------------------------------------------
1365 // standard unicode control implementation
1366 // ----------------------------------------------------------------------------
1368 #if TARGET_API_MAC_OSX
1370 // the current unicode textcontrol implementation has a bug : only if the control
1371 // is currently having the focus, the selection can be retrieved by the corresponding
1372 // data tag. So we have a mirroring using a member variable
1373 // TODO : build event table using virtual member functions for wxMacControl
1375 static const EventTypeSpec unicodeTextControlEventList
[] =
1377 { kEventClassControl
, kEventControlSetFocusPart
} ,
1380 static pascal OSStatus
wxMacUnicodeTextControlControlEventHandler( EventHandlerCallRef handler
, EventRef event
, void *data
)
1382 OSStatus result
= eventNotHandledErr
;
1383 wxMacUnicodeTextControl
* focus
= (wxMacUnicodeTextControl
*) data
;
1384 wxMacCarbonEvent
cEvent( event
) ;
1386 switch ( GetEventKind( event
) )
1388 case kEventControlSetFocusPart
:
1390 ControlPartCode controlPart
= cEvent
.GetParameter
<ControlPartCode
>(kEventParamControlPart
, typeControlPartCode
);
1391 if ( controlPart
== kControlFocusNoPart
)
1393 // about to loose focus -> store selection to field
1394 focus
->GetData
<ControlEditTextSelectionRec
>( 0, kControlEditTextSelectionTag
, &focus
->m_selection
);
1396 result
= CallNextEventHandler(handler
,event
) ;
1397 if ( controlPart
!= kControlFocusNoPart
)
1399 // about to gain focus -> set selection from field
1400 focus
->SetData
<ControlEditTextSelectionRec
>( 0, kControlEditTextSelectionTag
, &focus
->m_selection
);
1411 static pascal OSStatus
wxMacUnicodeTextControlEventHandler( EventHandlerCallRef handler
, EventRef event
, void *data
)
1413 OSStatus result
= eventNotHandledErr
;
1415 switch ( GetEventClass( event
) )
1417 case kEventClassControl
:
1418 result
= wxMacUnicodeTextControlControlEventHandler( handler
, event
, data
) ;
1427 DEFINE_ONE_SHOT_HANDLER_GETTER( wxMacUnicodeTextControlEventHandler
)
1429 wxMacUnicodeTextControl::wxMacUnicodeTextControl( wxTextCtrl
*wxPeer
,
1430 const wxString
& str
,
1432 const wxSize
& size
, long style
)
1433 : wxMacTextControl( wxPeer
)
1435 m_font
= wxPeer
->GetFont() ;
1436 m_windowStyle
= style
;
1437 Rect bounds
= wxMacGetBoundsForControl( wxPeer
, pos
, size
) ;
1439 wxMacConvertNewlines10To13( &st
) ;
1440 wxMacCFStringHolder
cf(st
, m_font
.GetEncoding()) ;
1441 CFStringRef cfr
= cf
;
1442 Boolean isPassword
= ( m_windowStyle
& wxTE_PASSWORD
) != 0 ;
1443 m_valueTag
= isPassword
? kControlEditTextPasswordCFStringTag
: kControlEditTextCFStringTag
;
1445 OSStatus err
= CreateEditUnicodeTextControl(
1446 MAC_WXHWND(wxPeer
->MacGetTopLevelWindowRef()), &bounds
, cfr
,
1447 isPassword
, NULL
, &m_controlRef
) ;
1448 verify_noerr( err
);
1450 if ( !(m_windowStyle
& wxTE_MULTILINE
) )
1451 SetData
<Boolean
>( kControlEditTextPart
, kControlEditTextSingleLineTag
, true ) ;
1453 InstallControlEventHandler( m_controlRef
, GetwxMacUnicodeTextControlEventHandlerUPP(),
1454 GetEventTypeCount(unicodeTextControlEventList
), unicodeTextControlEventList
, this,
1455 &m_focusHandlerRef
);
1458 wxMacUnicodeTextControl::~wxMacUnicodeTextControl()
1460 ::RemoveEventHandler( m_focusHandlerRef
);
1463 void wxMacUnicodeTextControl::VisibilityChanged(bool shown
)
1465 if ( !(m_windowStyle
& wxTE_MULTILINE
) && shown
)
1467 // work around a refresh issue insofar as not always the entire content is shown,
1468 // even if this would be possible
1469 ControlEditTextSelectionRec sel
;
1470 CFStringRef value
= NULL
;
1472 verify_noerr( GetData
<ControlEditTextSelectionRec
>( 0, kControlEditTextSelectionTag
, &sel
) );
1473 verify_noerr( GetData
<CFStringRef
>( 0, m_valueTag
, &value
) );
1474 verify_noerr( SetData
<CFStringRef
>( 0, m_valueTag
, &value
) );
1475 verify_noerr( SetData
<ControlEditTextSelectionRec
>( 0, kControlEditTextSelectionTag
, &sel
) );
1477 CFRelease( value
) ;
1481 wxString
wxMacUnicodeTextControl::GetStringValue() const
1484 CFStringRef value
= GetData
<CFStringRef
>(0, m_valueTag
) ;
1487 wxMacCFStringHolder
cf(value
) ;
1488 result
= cf
.AsString() ;
1492 wxMacConvertNewlines13To10( &result
) ;
1494 wxMacConvertNewlines10To13( &result
) ;
1500 void wxMacUnicodeTextControl::SetStringValue( const wxString
&str
)
1503 wxMacConvertNewlines10To13( &st
) ;
1504 wxMacCFStringHolder
cf( st
, m_font
.GetEncoding() ) ;
1505 verify_noerr( SetData
<CFStringRef
>( 0, m_valueTag
, cf
) ) ;
1508 void wxMacUnicodeTextControl::Copy()
1510 SendHICommand( kHICommandCopy
) ;
1513 void wxMacUnicodeTextControl::Cut()
1515 SendHICommand( kHICommandCut
) ;
1518 void wxMacUnicodeTextControl::Paste()
1520 SendHICommand( kHICommandPaste
) ;
1523 bool wxMacUnicodeTextControl::CanPaste() const
1528 void wxMacUnicodeTextControl::SetEditable(bool editable
)
1530 #if 0 // leads to problem because text cannot be selected anymore
1531 SetData
<Boolean
>( kControlEditTextPart
, kControlEditTextLockedTag
, (Boolean
) !editable
) ;
1535 void wxMacUnicodeTextControl::GetSelection( long* from
, long* to
) const
1537 ControlEditTextSelectionRec sel
;
1539 verify_noerr( GetData
<ControlEditTextSelectionRec
>( 0, kControlEditTextSelectionTag
, &sel
) ) ;
1544 *from
= sel
.selStart
;
1549 void wxMacUnicodeTextControl::SetSelection( long from
, long to
)
1551 ControlEditTextSelectionRec sel
;
1553 int textLength
= 0 ;
1554 CFStringRef value
= GetData
<CFStringRef
>(0, m_valueTag
) ;
1557 wxMacCFStringHolder
cf(value
) ;
1558 textLength
= cf
.AsString().length() ;
1561 if ((from
== -1) && (to
== -1))
1568 from
= wxMin(textLength
,wxMax(from
,0)) ;
1569 to
= wxMax(0,wxMin(textLength
,to
)) ;
1572 sel
.selStart
= from
;
1575 SetData
<ControlEditTextSelectionRec
>( 0, kControlEditTextSelectionTag
, &sel
) ;
1580 void wxMacUnicodeTextControl::WriteText( const wxString
& str
)
1583 wxMacConvertNewlines10To13( &st
) ;
1585 #if MAC_OS_X_VERSION_MAX_ALLOWED > MAC_OS_X_VERSION_10_2
1588 wxMacCFStringHolder
cf(st
, m_font
.GetEncoding() ) ;
1589 CFStringRef value
= cf
;
1590 SetData
<CFStringRef
>( 0, kControlEditTextInsertCFStringRefTag
, &value
);
1595 wxString val
= GetStringValue() ;
1597 GetSelection( &start
, &end
) ;
1598 val
.Remove( start
, end
- start
) ;
1599 val
.insert( start
, str
) ;
1600 SetStringValue( val
) ;
1601 SetSelection( start
+ str
.length() , start
+ str
.length() ) ;
1607 // ----------------------------------------------------------------------------
1608 // MLTE control implementation (common part)
1609 // ----------------------------------------------------------------------------
1611 // if MTLE is read only, no changes at all are allowed, not even from
1612 // procedural API, in order to allow changes via API all the same we must undo
1613 // the readonly status while we are executing, this class helps to do so
1615 class wxMacEditHelper
1618 wxMacEditHelper( TXNObject txn
)
1620 TXNControlTag tag
[] = { kTXNIOPrivilegesTag
} ;
1622 TXNGetTXNObjectControls( m_txn
, 1 , tag
, m_data
) ;
1623 if ( m_data
[0].uValue
== kTXNReadOnly
)
1625 TXNControlData data
[] = { { kTXNReadWrite
} } ;
1626 TXNSetTXNObjectControls( m_txn
, false , 1 , tag
, data
) ;
1632 TXNControlTag tag
[] = { kTXNIOPrivilegesTag
} ;
1633 if ( m_data
[0].uValue
== kTXNReadOnly
)
1634 TXNSetTXNObjectControls( m_txn
, false , 1 , tag
, m_data
) ;
1639 TXNControlData m_data
[1] ;
1642 wxMacMLTEControl::wxMacMLTEControl( wxTextCtrl
*peer
)
1643 : wxMacTextControl( peer
)
1645 SetNeedsFocusRect( true ) ;
1648 wxString
wxMacMLTEControl::GetStringValue() const
1652 Size actualSize
= 0;
1657 err
= TXNGetDataEncoded( m_txn
, kTXNStartOffset
, kTXNEndOffset
, &theText
, kTXNUnicodeTextData
);
1666 actualSize
= GetHandleSize( theText
) / sizeof(UniChar
) ;
1667 if ( actualSize
> 0 )
1669 wxChar
*ptr
= NULL
;
1671 #if SIZEOF_WCHAR_T == 2
1672 ptr
= new wxChar
[actualSize
+ 1] ;
1673 wxStrncpy( ptr
, (wxChar
*)(*theText
) , actualSize
) ;
1675 SetHandleSize( theText
, (actualSize
+ 1) * sizeof(UniChar
) ) ;
1677 (((UniChar
*)*theText
)[actualSize
]) = 0 ;
1678 wxMBConvUTF16 converter
;
1679 size_t noChars
= converter
.MB2WC( NULL
, (const char*)*theText
, 0 ) ;
1680 wxASSERT_MSG( noChars
!= wxCONV_FAILED
, _T("Unable to count the number of characters in this string!") );
1681 ptr
= new wxChar
[noChars
+ 1] ;
1683 noChars
= converter
.MB2WC( ptr
, (const char*)*theText
, noChars
+ 1 ) ;
1684 wxASSERT_MSG( noChars
!= wxCONV_FAILED
, _T("Conversion of string failed!") );
1686 HUnlock( theText
) ;
1689 ptr
[actualSize
] = 0 ;
1690 result
= wxString( ptr
) ;
1694 DisposeHandle( theText
) ;
1698 err
= TXNGetDataEncoded( m_txn
, kTXNStartOffset
, kTXNEndOffset
, &theText
, kTXNTextData
);
1707 actualSize
= GetHandleSize( theText
) ;
1708 if ( actualSize
> 0 )
1711 result
= wxString( *theText
, wxConvLocal
, actualSize
) ;
1712 HUnlock( theText
) ;
1715 DisposeHandle( theText
) ;
1721 wxMacConvertNewlines13To10( &result
) ;
1723 wxMacConvertNewlines10To13( &result
) ;
1729 void wxMacMLTEControl::SetStringValue( const wxString
&str
)
1732 wxMacConvertNewlines10To13( &st
);
1736 wxMacWindowClipper
c( m_peer
) ;
1740 wxMacEditHelper
help( m_txn
);
1741 SetTXNData( st
, kTXNStartOffset
, kTXNEndOffset
);
1744 TXNSetSelection( m_txn
, 0, 0 );
1745 TXNShowSelection( m_txn
, kTXNShowStart
);
1749 TXNFrameOptions
wxMacMLTEControl::FrameOptionsFromWXStyle( long wxStyle
)
1751 TXNFrameOptions frameOptions
= kTXNDontDrawCaretWhenInactiveMask
;
1753 #if MAC_OS_X_VERSION_MAX_ALLOWED >= MAC_OS_X_VERSION_10_3
1754 frameOptions
|= kTXNDoFontSubstitutionMask
;
1757 if ( ! (wxStyle
& wxTE_NOHIDESEL
) )
1758 frameOptions
|= kTXNDontDrawSelectionWhenInactiveMask
;
1760 if ( wxStyle
& (wxHSCROLL
| wxTE_DONTWRAP
) )
1761 frameOptions
|= kTXNWantHScrollBarMask
;
1763 if ( wxStyle
& wxTE_MULTILINE
)
1765 frameOptions
|= kTXNAlwaysWrapAtViewEdgeMask
;
1767 if ( !(wxStyle
& wxTE_NO_VSCROLL
) )
1769 frameOptions
|= kTXNWantVScrollBarMask
;
1771 // The following code causes drawing problems on 10.4. Perhaps it can be restored for
1772 // older versions of the OS, but I'm not sure it's appropriate to put a grow icon here
1773 // anyways, as AFAIK users can't actually use it to resize the text ctrl.
1774 // if ( frameOptions & kTXNWantHScrollBarMask )
1775 // frameOptions |= kTXNDrawGrowIconMask ;
1780 frameOptions
|= kTXNSingleLineOnlyMask
;
1783 return frameOptions
;
1786 void wxMacMLTEControl::AdjustCreationAttributes( const wxColour
&background
, bool visible
)
1788 TXNControlTag iControlTags
[] =
1790 kTXNDoFontSubstitution
,
1791 kTXNWordWrapStateTag
,
1793 TXNControlData iControlData
[] =
1799 int toptag
= WXSIZEOF( iControlTags
) ;
1801 if ( m_windowStyle
& wxTE_MULTILINE
)
1803 iControlData
[1].uValue
=
1804 (m_windowStyle
& wxTE_DONTWRAP
)
1809 OSStatus err
= TXNSetTXNObjectControls( m_txn
, false, toptag
, iControlTags
, iControlData
) ;
1810 verify_noerr( err
);
1812 // setting the default font:
1813 // under 10.2 this causes a visible caret, therefore we avoid it
1815 if ( UMAGetSystemVersion() >= 0x1030 )
1821 GetThemeFont( kThemeSystemFont
, GetApplicationScript() , fontName
, &fontSize
, &fontStyle
) ;
1823 TXNTypeAttributes typeAttr
[] =
1825 { kTXNQDFontNameAttribute
, kTXNQDFontNameAttributeSize
, { (void*) fontName
} } ,
1826 { kTXNQDFontSizeAttribute
, kTXNFontSizeAttributeSize
, { (void*) (fontSize
<< 16) } } ,
1827 { kTXNQDFontStyleAttribute
, kTXNQDFontStyleAttributeSize
, { (void*) normal
} } ,
1830 err
= TXNSetTypeAttributes(
1831 m_txn
, sizeof(typeAttr
) / sizeof(TXNTypeAttributes
),
1832 typeAttr
, kTXNStartOffset
, kTXNEndOffset
);
1833 verify_noerr( err
);
1836 if ( m_windowStyle
& wxTE_PASSWORD
)
1838 UniChar c
= 0x00A5 ;
1839 err
= TXNEchoMode( m_txn
, c
, 0 , true );
1840 verify_noerr( err
);
1843 TXNBackground tback
;
1844 tback
.bgType
= kTXNBackgroundTypeRGB
;
1845 tback
.bg
.color
= MAC_WXCOLORREF( background
.GetPixel() );
1846 TXNSetBackground( m_txn
, &tback
);
1848 #if MAC_OS_X_VERSION_MAX_ALLOWED >= MAC_OS_X_VERSION_10_4
1849 if ( UMAGetSystemVersion() >= 0x1040 )
1851 TXNCommandEventSupportOptions options
;
1852 if ( TXNGetCommandEventSupport( m_txn
, &options
) == noErr
)
1855 kTXNSupportEditCommandProcessing
1856 | kTXNSupportEditCommandUpdating
1857 | kTXNSupportSpellCheckCommandProcessing
1858 | kTXNSupportSpellCheckCommandUpdating
1859 | kTXNSupportFontCommandProcessing
1860 | kTXNSupportFontCommandUpdating
;
1862 TXNSetCommandEventSupport( m_txn
, options
) ;
1868 void wxMacMLTEControl::SetBackground( const wxBrush
&brush
)
1870 // currently only solid background are supported
1871 TXNBackground tback
;
1873 tback
.bgType
= kTXNBackgroundTypeRGB
;
1874 tback
.bg
.color
= MAC_WXCOLORREF( brush
.GetColour().GetPixel() );
1875 TXNSetBackground( m_txn
, &tback
);
1878 void wxMacMLTEControl::TXNSetAttribute( const wxTextAttr
& style
, long from
, long to
)
1880 TXNTypeAttributes typeAttr
[4] ;
1884 if ( style
.HasFont() )
1886 const wxFont
&font
= style
.GetFont() ;
1888 #if 0 // old version
1889 Str255 fontName
= "\pMonaco" ;
1890 SInt16 fontSize
= 12 ;
1891 Style fontStyle
= normal
;
1892 wxMacStringToPascal( font
.GetFaceName() , fontName
) ;
1893 fontSize
= font
.GetPointSize() ;
1894 if ( font
.GetUnderlined() )
1895 fontStyle
|= underline
;
1896 if ( font
.GetWeight() == wxBOLD
)
1898 if ( font
.GetStyle() == wxITALIC
)
1899 fontStyle
|= italic
;
1901 typeAttr
[attrCount
].tag
= kTXNQDFontNameAttribute
;
1902 typeAttr
[attrCount
].size
= kTXNQDFontNameAttributeSize
;
1903 typeAttr
[attrCount
].data
.dataPtr
= (void*)fontName
;
1906 typeAttr
[attrCount
].tag
= kTXNQDFontSizeAttribute
;
1907 typeAttr
[attrCount
].size
= kTXNFontSizeAttributeSize
;
1908 typeAttr
[attrCount
].data
.dataValue
= (fontSize
<< 16) ;
1911 typeAttr
[attrCount
].tag
= kTXNQDFontStyleAttribute
;
1912 typeAttr
[attrCount
].size
= kTXNQDFontStyleAttributeSize
;
1913 typeAttr
[attrCount
].data
.dataValue
= fontStyle
;
1916 typeAttr
[attrCount
].tag
= kTXNATSUIStyle
;
1917 typeAttr
[attrCount
].size
= kTXNATSUIStyleSize
;
1918 typeAttr
[attrCount
].data
.dataPtr
= font
.MacGetATSUStyle() ;
1923 if ( style
.HasTextColour() )
1925 color
= MAC_WXCOLORREF(style
.GetTextColour().GetPixel()) ;
1927 typeAttr
[attrCount
].tag
= kTXNQDFontColorAttribute
;
1928 typeAttr
[attrCount
].size
= kTXNQDFontColorAttributeSize
;
1929 typeAttr
[attrCount
].data
.dataPtr
= (void*) &color
;
1933 if ( attrCount
> 0 )
1935 verify_noerr( TXNSetTypeAttributes( m_txn
, attrCount
, typeAttr
, from
, to
) );
1936 // unfortunately the relayout is not automatic
1937 TXNRecalcTextLayout( m_txn
);
1941 void wxMacMLTEControl::SetFont( const wxFont
& font
, const wxColour
& foreground
, long windowStyle
)
1943 wxMacEditHelper
help( m_txn
) ;
1944 TXNSetAttribute( wxTextAttr( foreground
, wxNullColour
, font
), kTXNStartOffset
, kTXNEndOffset
) ;
1947 void wxMacMLTEControl::SetStyle( long start
, long end
, const wxTextAttr
& style
)
1949 wxMacEditHelper
help( m_txn
) ;
1950 TXNSetAttribute( style
, start
, end
) ;
1953 void wxMacMLTEControl::Copy()
1955 ClearCurrentScrap();
1957 TXNConvertToPublicScrap();
1960 void wxMacMLTEControl::Cut()
1962 ClearCurrentScrap();
1964 TXNConvertToPublicScrap();
1967 void wxMacMLTEControl::Paste()
1969 TXNConvertFromPublicScrap();
1973 bool wxMacMLTEControl::CanPaste() const
1975 return TXNIsScrapPastable() ;
1978 void wxMacMLTEControl::SetEditable(bool editable
)
1980 TXNControlTag tag
[] = { kTXNIOPrivilegesTag
} ;
1981 TXNControlData data
[] = { { editable
? kTXNReadWrite
: kTXNReadOnly
} } ;
1982 TXNSetTXNObjectControls( m_txn
, false, WXSIZEOF(tag
), tag
, data
) ;
1985 wxTextPos
wxMacMLTEControl::GetLastPosition() const
1987 wxTextPos actualsize
= 0 ;
1990 OSErr err
= TXNGetDataEncoded( m_txn
, kTXNStartOffset
, kTXNEndOffset
, &theText
, kTXNTextData
);
1995 actualsize
= GetHandleSize( theText
) ;
1996 DisposeHandle( theText
) ;
2006 void wxMacMLTEControl::Replace( long from
, long to
, const wxString
&str
)
2008 wxString value
= str
;
2009 wxMacConvertNewlines10To13( &value
) ;
2011 wxMacEditHelper
help( m_txn
) ;
2013 wxMacWindowClipper
c( m_peer
) ;
2016 TXNSetSelection( m_txn
, from
, to
) ;
2018 SetTXNData( value
, kTXNUseCurrentSelection
, kTXNUseCurrentSelection
) ;
2021 void wxMacMLTEControl::Remove( long from
, long to
)
2024 wxMacWindowClipper
c( m_peer
) ;
2026 wxMacEditHelper
help( m_txn
) ;
2027 TXNSetSelection( m_txn
, from
, to
) ;
2031 void wxMacMLTEControl::GetSelection( long* from
, long* to
) const
2033 TXNGetSelection( m_txn
, (TXNOffset
*) from
, (TXNOffset
*) to
) ;
2036 void wxMacMLTEControl::SetSelection( long from
, long to
)
2039 wxMacWindowClipper
c( m_peer
) ;
2042 // change the selection
2043 if ((from
== -1) && (to
== -1))
2044 TXNSelectAll( m_txn
);
2046 TXNSetSelection( m_txn
, from
, to
);
2048 TXNShowSelection( m_txn
, kTXNShowStart
);
2051 void wxMacMLTEControl::WriteText( const wxString
& str
)
2054 wxMacConvertNewlines10To13( &st
) ;
2056 long start
, end
, dummy
;
2058 GetSelection( &start
, &dummy
) ;
2060 wxMacWindowClipper
c( m_peer
) ;
2064 wxMacEditHelper
helper( m_txn
) ;
2065 SetTXNData( st
, kTXNUseCurrentSelection
, kTXNUseCurrentSelection
) ;
2068 GetSelection( &dummy
, &end
) ;
2070 // TODO: SetStyle( start , end , GetDefaultStyle() ) ;
2073 void wxMacMLTEControl::Clear()
2076 wxMacWindowClipper
c( m_peer
) ;
2078 wxMacEditHelper
st( m_txn
) ;
2079 TXNSetSelection( m_txn
, kTXNStartOffset
, kTXNEndOffset
) ;
2083 bool wxMacMLTEControl::CanUndo() const
2085 return TXNCanUndo( m_txn
, NULL
) ;
2088 void wxMacMLTEControl::Undo()
2093 bool wxMacMLTEControl::CanRedo() const
2095 return TXNCanRedo( m_txn
, NULL
) ;
2098 void wxMacMLTEControl::Redo()
2103 int wxMacMLTEControl::GetNumberOfLines() const
2105 ItemCount lines
= 0 ;
2106 TXNGetLineCount( m_txn
, &lines
) ;
2111 long wxMacMLTEControl::XYToPosition(long x
, long y
) const
2116 // TODO: find a better implementation : while we can get the
2117 // line metrics of a certain line, we don't get its starting
2118 // position, so it would probably be rather a binary search
2119 // for the start position
2120 long xpos
= 0, ypos
= 0 ;
2121 int lastHeight
= 0 ;
2124 lastpos
= GetLastPosition() ;
2125 for ( n
= 0 ; n
<= (ItemCount
) lastpos
; ++n
)
2127 if ( y
== ypos
&& x
== xpos
)
2130 TXNOffsetToPoint( m_txn
, n
, &curpt
) ;
2132 if ( curpt
.v
> lastHeight
)
2138 lastHeight
= curpt
.v
;
2147 bool wxMacMLTEControl::PositionToXY( long pos
, long *x
, long *y
) const
2157 lastpos
= GetLastPosition() ;
2158 if ( pos
<= lastpos
)
2160 // TODO: find a better implementation - while we can get the
2161 // line metrics of a certain line, we don't get its starting
2162 // position, so it would probably be rather a binary search
2163 // for the start position
2164 long xpos
= 0, ypos
= 0 ;
2165 int lastHeight
= 0 ;
2168 for ( n
= 0 ; n
<= (ItemCount
) pos
; ++n
)
2170 TXNOffsetToPoint( m_txn
, n
, &curpt
) ;
2172 if ( curpt
.v
> lastHeight
)
2178 lastHeight
= curpt
.v
;
2193 void wxMacMLTEControl::ShowPosition( long pos
)
2195 Point current
, desired
;
2196 TXNOffset selstart
, selend
;
2198 TXNGetSelection( m_txn
, &selstart
, &selend
);
2199 TXNOffsetToPoint( m_txn
, selstart
, ¤t
);
2200 TXNOffsetToPoint( m_txn
, pos
, &desired
);
2202 // TODO: use HIPoints for 10.3 and above
2204 OSErr theErr
= noErr
;
2205 long dv
= desired
.v
- current
.v
;
2206 long dh
= desired
.h
- current
.h
;
2207 TXNShowSelection( m_txn
, kTXNShowStart
) ; // NB: should this be kTXNShowStart or kTXNShowEnd ??
2208 theErr
= TXNScroll( m_txn
, kTXNScrollUnitsInPixels
, kTXNScrollUnitsInPixels
, &dv
, &dh
);
2210 // there will be an error returned for classic MLTE implementation when the control is
2211 // invisible, but HITextView works correctly, so we don't assert that one
2212 // wxASSERT_MSG( theErr == noErr, _T("TXNScroll returned an error!") );
2215 void wxMacMLTEControl::SetTXNData( const wxString
& st
, TXNOffset start
, TXNOffset end
)
2218 #if SIZEOF_WCHAR_T == 2
2219 size_t len
= st
.length() ;
2220 TXNSetData( m_txn
, kTXNUnicodeTextData
, (void*)st
.wc_str(), len
* 2, start
, end
);
2222 wxMBConvUTF16 converter
;
2223 ByteCount byteBufferLen
= converter
.WC2MB( NULL
, st
.wc_str(), 0 ) ;
2224 UniChar
*unibuf
= (UniChar
*)malloc( byteBufferLen
) ;
2225 converter
.WC2MB( (char*)unibuf
, st
.wc_str(), byteBufferLen
) ;
2226 TXNSetData( m_txn
, kTXNUnicodeTextData
, (void*)unibuf
, byteBufferLen
, start
, end
) ;
2230 wxCharBuffer text
= st
.mb_str( wxConvLocal
) ;
2231 TXNSetData( m_txn
, kTXNTextData
, (void*)text
.data(), strlen( text
), start
, end
) ;
2235 wxString
wxMacMLTEControl::GetLineText(long lineNo
) const
2239 if ( lineNo
< GetNumberOfLines() )
2242 Fixed lineWidth
, lineHeight
, currentHeight
;
2245 // get the first possible position in the control
2246 TXNOffsetToPoint(m_txn
, 0, &firstPoint
);
2248 // Iterate through the lines until we reach the one we want,
2249 // adding to our current y pixel point position
2252 while (ypos
< lineNo
)
2254 TXNGetLineMetrics(m_txn
, ypos
++, &lineWidth
, &lineHeight
);
2255 currentHeight
+= lineHeight
;
2258 Point thePoint
= { firstPoint
.v
+ (currentHeight
>> 16), firstPoint
.h
+ (0) };
2259 TXNOffset theOffset
;
2260 TXNPointToOffset(m_txn
, thePoint
, &theOffset
);
2262 wxString content
= GetStringValue() ;
2263 Point currentPoint
= thePoint
;
2264 while (thePoint
.v
== currentPoint
.v
&& theOffset
< content
.length())
2266 line
+= content
[theOffset
];
2267 TXNOffsetToPoint(m_txn
, ++theOffset
, ¤tPoint
);
2274 int wxMacMLTEControl::GetLineLength(long lineNo
) const
2278 if ( lineNo
< GetNumberOfLines() )
2281 Fixed lineWidth
, lineHeight
, currentHeight
;
2284 // get the first possible position in the control
2285 TXNOffsetToPoint(m_txn
, 0, &firstPoint
);
2287 // Iterate through the lines until we reach the one we want,
2288 // adding to our current y pixel point position
2291 while (ypos
< lineNo
)
2293 TXNGetLineMetrics(m_txn
, ypos
++, &lineWidth
, &lineHeight
);
2294 currentHeight
+= lineHeight
;
2297 Point thePoint
= { firstPoint
.v
+ (currentHeight
>> 16), firstPoint
.h
+ (0) };
2298 TXNOffset theOffset
;
2299 TXNPointToOffset(m_txn
, thePoint
, &theOffset
);
2301 wxString content
= GetStringValue() ;
2302 Point currentPoint
= thePoint
;
2303 while (thePoint
.v
== currentPoint
.v
&& theOffset
< content
.length())
2306 TXNOffsetToPoint(m_txn
, ++theOffset
, ¤tPoint
);
2313 #if MAC_OS_X_VERSION_MAX_ALLOWED < MAC_OS_X_VERSION_10_5
2315 // ----------------------------------------------------------------------------
2316 // MLTE control implementation (classic part)
2317 // ----------------------------------------------------------------------------
2319 // OS X Notes : We still don't have a full replacement for MLTE, so this implementation
2320 // has to live on. We have different problems coming from outdated implementations on the
2321 // various OS X versions. Most deal with the scrollbars: they are not correctly embedded
2322 // while this can be solved on 10.3 by reassigning them the correct place, on 10.2 there is
2323 // no way out, therefore we are using our own implementation and our own scrollbars ....
2325 #ifdef __WXMAC_OSX__
2327 TXNScrollInfoUPP gTXNScrollInfoProc
= NULL
;
2328 ControlActionUPP gTXNScrollActionProc
= NULL
;
2330 pascal void wxMacMLTEClassicControl::TXNScrollInfoProc(
2331 SInt32 iValue
, SInt32 iMaximumValue
,
2332 TXNScrollBarOrientation iScrollBarOrientation
, SInt32 iRefCon
)
2334 wxMacMLTEClassicControl
* mlte
= (wxMacMLTEClassicControl
*) iRefCon
;
2335 SInt32 value
= wxMax( iValue
, 0 ) ;
2336 SInt32 maximum
= wxMax( iMaximumValue
, 0 ) ;
2338 if ( iScrollBarOrientation
== kTXNHorizontal
)
2340 if ( mlte
->m_sbHorizontal
)
2342 SetControl32BitValue( mlte
->m_sbHorizontal
, value
) ;
2343 SetControl32BitMaximum( mlte
->m_sbHorizontal
, maximum
) ;
2344 mlte
->m_lastHorizontalValue
= value
;
2347 else if ( iScrollBarOrientation
== kTXNVertical
)
2349 if ( mlte
->m_sbVertical
)
2351 SetControl32BitValue( mlte
->m_sbVertical
, value
) ;
2352 SetControl32BitMaximum( mlte
->m_sbVertical
, maximum
) ;
2353 mlte
->m_lastVerticalValue
= value
;
2358 pascal void wxMacMLTEClassicControl::TXNScrollActionProc( ControlRef controlRef
, ControlPartCode partCode
)
2360 wxMacMLTEClassicControl
* mlte
= (wxMacMLTEClassicControl
*) GetControlReference( controlRef
) ;
2364 if ( controlRef
!= mlte
->m_sbVertical
&& controlRef
!= mlte
->m_sbHorizontal
)
2368 bool isHorizontal
= ( controlRef
== mlte
->m_sbHorizontal
) ;
2370 SInt32 minimum
= 0 ;
2371 SInt32 maximum
= GetControl32BitMaximum( controlRef
) ;
2372 SInt32 value
= GetControl32BitValue( controlRef
) ;
2377 case kControlDownButtonPart
:
2381 case kControlUpButtonPart
:
2385 case kControlPageDownPart
:
2386 delta
= GetControlViewSize( controlRef
) ;
2389 case kControlPageUpPart
:
2390 delta
= -GetControlViewSize( controlRef
) ;
2393 case kControlIndicatorPart
:
2394 delta
= value
- (isHorizontal
? mlte
->m_lastHorizontalValue
: mlte
->m_lastVerticalValue
) ;
2403 SInt32 newValue
= value
;
2405 if ( partCode
!= kControlIndicatorPart
)
2407 if ( value
+ delta
< minimum
)
2408 delta
= minimum
- value
;
2409 if ( value
+ delta
> maximum
)
2410 delta
= maximum
- value
;
2412 SetControl32BitValue( controlRef
, value
+ delta
) ;
2413 newValue
= value
+ delta
;
2416 SInt32 verticalDelta
= isHorizontal
? 0 : delta
;
2417 SInt32 horizontalDelta
= isHorizontal
? delta
: 0 ;
2420 mlte
->m_txn
, kTXNScrollUnitsInPixels
, kTXNScrollUnitsInPixels
,
2421 &verticalDelta
, &horizontalDelta
);
2422 verify_noerr( err
);
2425 mlte
->m_lastHorizontalValue
= newValue
;
2427 mlte
->m_lastVerticalValue
= newValue
;
2432 // make correct activations
2433 void wxMacMLTEClassicControl::MacActivatePaneText(bool setActive
)
2435 wxTextCtrl
* textctrl
= (wxTextCtrl
*) GetControlReference(m_controlRef
);
2437 wxMacWindowClipper
clipper( textctrl
) ;
2438 TXNActivate( m_txn
, m_txnFrameID
, setActive
);
2440 ControlRef controlFocus
= 0 ;
2441 GetKeyboardFocus( m_txnWindow
, &controlFocus
) ;
2442 if ( controlFocus
== m_controlRef
)
2443 TXNFocus( m_txn
, setActive
);
2446 void wxMacMLTEClassicControl::MacFocusPaneText(bool setFocus
)
2448 TXNFocus( m_txn
, setFocus
);
2451 // guards against inappropriate redraw (hidden objects drawing onto window)
2453 void wxMacMLTEClassicControl::MacSetObjectVisibility(bool vis
)
2455 ControlRef controlFocus
= 0 ;
2456 GetKeyboardFocus( m_txnWindow
, &controlFocus
) ;
2458 if ( !vis
&& (controlFocus
== m_controlRef
) )
2459 SetKeyboardFocus( m_txnWindow
, m_controlRef
, kControlFocusNoPart
) ;
2461 TXNControlTag iControlTags
[1] = { kTXNVisibilityTag
};
2462 TXNControlData iControlData
[1] = { { (UInt32
)false } };
2464 verify_noerr( TXNGetTXNObjectControls( m_txn
, 1, iControlTags
, iControlData
) ) ;
2466 if ( iControlData
[0].uValue
!= vis
)
2468 iControlData
[0].uValue
= vis
;
2469 verify_noerr( TXNSetTXNObjectControls( m_txn
, false , 1, iControlTags
, iControlData
) ) ;
2472 // currently, we always clip as partial visibility (overlapped) visibility is also a problem,
2473 // if we run into further problems we might set the FrameBounds to an empty rect here
2476 // make sure that the TXNObject is at the right position
2478 void wxMacMLTEClassicControl::MacUpdatePosition()
2480 wxTextCtrl
* textctrl
= (wxTextCtrl
*)GetControlReference( m_controlRef
);
2481 if ( textctrl
== NULL
)
2485 UMAGetControlBoundsInWindowCoords( m_controlRef
, &bounds
);
2487 wxRect visRect
= textctrl
->MacGetClippedClientRect() ;
2488 Rect visBounds
= { visRect
.y
, visRect
.x
, visRect
.y
+ visRect
.height
, visRect
.x
+ visRect
.width
} ;
2491 textctrl
->MacWindowToRootWindow( &x
, &y
) ;
2492 OffsetRect( &visBounds
, x
, y
) ;
2494 if ( !EqualRect( &bounds
, &m_txnControlBounds
) || !EqualRect( &visBounds
, &m_txnVisBounds
) )
2496 m_txnControlBounds
= bounds
;
2497 m_txnVisBounds
= visBounds
;
2498 wxMacWindowClipper
cl( textctrl
) ;
2500 #ifdef __WXMAC_OSX__
2501 if ( m_sbHorizontal
|| m_sbVertical
)
2503 int w
= bounds
.right
- bounds
.left
;
2504 int h
= bounds
.bottom
- bounds
.top
;
2506 if ( m_sbHorizontal
)
2510 sbBounds
.left
= -1 ;
2511 sbBounds
.top
= h
- 14 ;
2512 sbBounds
.right
= w
+ 1 ;
2513 sbBounds
.bottom
= h
+ 1 ;
2515 SetControlBounds( m_sbHorizontal
, &sbBounds
) ;
2516 SetControlViewSize( m_sbHorizontal
, w
) ;
2523 sbBounds
.left
= w
- 14 ;
2525 sbBounds
.right
= w
+ 1 ;
2526 sbBounds
.bottom
= m_sbHorizontal
? h
- 14 : h
+ 1 ;
2528 SetControlBounds( m_sbVertical
, &sbBounds
) ;
2529 SetControlViewSize( m_sbVertical
, h
) ;
2534 TXNLongRect olddestRect
;
2535 TXNGetRectBounds( m_txn
, &oldviewRect
, &olddestRect
, NULL
) ;
2537 Rect viewRect
= { m_txnControlBounds
.top
, m_txnControlBounds
.left
,
2538 m_txnControlBounds
.bottom
- ( m_sbHorizontal
? 14 : 0 ) ,
2539 m_txnControlBounds
.right
- ( m_sbVertical
? 14 : 0 ) } ;
2540 TXNLongRect destRect
= { m_txnControlBounds
.top
, m_txnControlBounds
.left
,
2541 m_txnControlBounds
.bottom
- ( m_sbHorizontal
? 14 : 0 ) ,
2542 m_txnControlBounds
.right
- ( m_sbVertical
? 14 : 0 ) } ;
2544 if ( olddestRect
.right
>= 10000 )
2545 destRect
.right
= destRect
.left
+ 32000 ;
2547 if ( olddestRect
.bottom
>= 0x20000000 )
2548 destRect
.bottom
= destRect
.top
+ 0x40000000 ;
2550 SectRect( &viewRect
, &visBounds
, &viewRect
) ;
2551 TXNSetRectBounds( m_txn
, &viewRect
, &destRect
, true ) ;
2556 m_txnControlBounds
.top
,
2557 m_txnControlBounds
.left
,
2558 m_txnControlBounds
.bottom
- (m_sbHorizontal
? 14 : 0),
2559 m_txnControlBounds
.right
- (m_sbVertical
? 14 : 0),
2565 m_txn
, m_txnControlBounds
.top
, m_txnControlBounds
.left
,
2566 wxMax( m_txnControlBounds
.bottom
, m_txnControlBounds
.top
),
2567 wxMax( m_txnControlBounds
.right
, m_txnControlBounds
.left
), m_txnFrameID
);
2570 // the SetFrameBounds method under Classic sometimes does not correctly scroll a selection into sight after a
2571 // movement, therefore we have to force it
2573 // this problem has been reported in OSX as well, so we use this here once again
2575 TXNLongRect textRect
;
2576 TXNGetRectBounds( m_txn
, NULL
, NULL
, &textRect
) ;
2577 if ( textRect
.left
< m_txnControlBounds
.left
)
2578 TXNShowSelection( m_txn
, kTXNShowStart
) ;
2582 void wxMacMLTEClassicControl::SetRect( Rect
*r
)
2584 wxMacControl::SetRect( r
) ;
2585 MacUpdatePosition() ;
2588 void wxMacMLTEClassicControl::MacControlUserPaneDrawProc(wxInt16 thePart
)
2590 wxTextCtrl
* textctrl
= (wxTextCtrl
*)GetControlReference( m_controlRef
);
2591 if ( textctrl
== NULL
)
2594 if ( textctrl
->MacIsReallyShown() )
2596 wxMacWindowClipper
clipper( textctrl
) ;
2597 TXNDraw( m_txn
, NULL
) ;
2601 wxInt16
wxMacMLTEClassicControl::MacControlUserPaneHitTestProc(wxInt16 x
, wxInt16 y
)
2603 Point where
= { y
, x
} ;
2604 ControlPartCode result
= kControlNoPart
;
2606 wxTextCtrl
* textctrl
= (wxTextCtrl
*) GetControlReference( m_controlRef
);
2607 if ( (textctrl
!= NULL
) && textctrl
->MacIsReallyShown() )
2609 if (PtInRect( where
, &m_txnControlBounds
))
2611 result
= kControlEditTextPart
;
2615 // sometimes we get the coords also in control local coordinates, therefore test again
2617 textctrl
->MacClientToRootWindow( &x
, &y
) ;
2621 if (PtInRect( where
, &m_txnControlBounds
))
2622 result
= kControlEditTextPart
;
2629 wxInt16
wxMacMLTEClassicControl::MacControlUserPaneTrackingProc( wxInt16 x
, wxInt16 y
, void* actionProc
)
2631 ControlPartCode result
= kControlNoPart
;
2633 wxTextCtrl
* textctrl
= (wxTextCtrl
*) GetControlReference( m_controlRef
);
2634 if ( (textctrl
!= NULL
) && textctrl
->MacIsReallyShown() )
2636 Point startPt
= { y
, x
} ;
2638 // for compositing, we must convert these into toplevel window coordinates, because hittesting expects them
2640 textctrl
->MacClientToRootWindow( &x
, &y
) ;
2644 switch (MacControlUserPaneHitTestProc( startPt
.h
, startPt
.v
))
2646 case kControlEditTextPart
:
2648 wxMacWindowClipper
clipper( textctrl
) ;
2651 ConvertEventRefToEventRecord( (EventRef
) wxTheApp
->MacGetCurrentEvent() , &rec
) ;
2652 TXNClick( m_txn
, &rec
);
2664 void wxMacMLTEClassicControl::MacControlUserPaneIdleProc()
2666 wxTextCtrl
* textctrl
= (wxTextCtrl
*)GetControlReference( m_controlRef
);
2667 if ( textctrl
== NULL
)
2670 if (textctrl
->MacIsReallyShown())
2672 if (IsControlActive(m_controlRef
))
2676 wxMacWindowClipper
clipper( textctrl
) ;
2681 if (PtInRect(mousep
, &m_txnControlBounds
))
2683 RgnHandle theRgn
= NewRgn();
2684 RectRgn(theRgn
, &m_txnControlBounds
);
2685 TXNAdjustCursor(m_txn
, theRgn
);
2692 wxInt16
wxMacMLTEClassicControl::MacControlUserPaneKeyDownProc (wxInt16 keyCode
, wxInt16 charCode
, wxInt16 modifiers
)
2694 wxTextCtrl
* textctrl
= (wxTextCtrl
*)GetControlReference( m_controlRef
);
2695 if ( textctrl
== NULL
)
2696 return kControlNoPart
;
2698 wxMacWindowClipper
clipper( textctrl
) ;
2701 memset( &ev
, 0 , sizeof( ev
) ) ;
2703 ev
.modifiers
= modifiers
;
2704 ev
.message
= ((keyCode
<< 8) & keyCodeMask
) | (charCode
& charCodeMask
);
2705 TXNKeyDown( m_txn
, &ev
);
2707 return kControlEntireControl
;
2710 void wxMacMLTEClassicControl::MacControlUserPaneActivateProc(bool activating
)
2712 MacActivatePaneText( activating
);
2715 wxInt16
wxMacMLTEClassicControl::MacControlUserPaneFocusProc(wxInt16 action
)
2717 ControlPartCode focusResult
= kControlFocusNoPart
;
2719 wxTextCtrl
* textctrl
= (wxTextCtrl
*)GetControlReference( m_controlRef
);
2720 if ( textctrl
== NULL
)
2723 wxMacWindowClipper
clipper( textctrl
) ;
2725 ControlRef controlFocus
= NULL
;
2726 GetKeyboardFocus( m_txnWindow
, &controlFocus
) ;
2727 bool wasFocused
= ( controlFocus
== m_controlRef
) ;
2731 case kControlFocusPrevPart
:
2732 case kControlFocusNextPart
:
2733 MacFocusPaneText( !wasFocused
);
2734 focusResult
= (!wasFocused
? (ControlPartCode
) kControlEditTextPart
: (ControlPartCode
) kControlFocusNoPart
);
2737 case kControlFocusNoPart
:
2739 MacFocusPaneText( false );
2740 focusResult
= kControlFocusNoPart
;
2747 void wxMacMLTEClassicControl::MacControlUserPaneBackgroundProc( void *info
)
2751 wxMacMLTEClassicControl::wxMacMLTEClassicControl( wxTextCtrl
*wxPeer
,
2752 const wxString
& str
,
2754 const wxSize
& size
, long style
)
2755 : wxMacMLTEControl( wxPeer
)
2757 m_font
= wxPeer
->GetFont() ;
2758 m_windowStyle
= style
;
2759 Rect bounds
= wxMacGetBoundsForControl( wxPeer
, pos
, size
) ;
2762 kControlSupportsEmbedding
| kControlSupportsFocus
| kControlWantsIdle
2763 | kControlWantsActivate
| kControlHandlesTracking
2764 // | kControlHasSpecialBackground
2765 | kControlGetsFocusOnClick
| kControlSupportsLiveFeedback
;
2767 OSStatus err
= ::CreateUserPaneControl(
2768 MAC_WXHWND(wxPeer
->GetParent()->MacGetTopLevelWindowRef()),
2769 &bounds
, featureSet
, &m_controlRef
);
2770 verify_noerr( err
);
2774 AdjustCreationAttributes( *wxWHITE
, true ) ;
2776 MacSetObjectVisibility( wxPeer
->MacIsReallyShown() ) ;
2780 wxMacConvertNewlines10To13( &st
) ;
2781 wxMacWindowClipper
clipper( m_peer
) ;
2782 SetTXNData( st
, kTXNStartOffset
, kTXNEndOffset
) ;
2783 TXNSetSelection( m_txn
, 0, 0 ) ;
2787 wxMacMLTEClassicControl::~wxMacMLTEClassicControl()
2789 TXNDeleteObject( m_txn
);
2793 void wxMacMLTEClassicControl::VisibilityChanged(bool shown
)
2795 MacSetObjectVisibility( shown
) ;
2796 wxMacControl::VisibilityChanged( shown
) ;
2799 void wxMacMLTEClassicControl::SuperChangedPosition()
2801 MacUpdatePosition() ;
2802 wxMacControl::SuperChangedPosition() ;
2805 #ifdef __WXMAC_OSX__
2807 ControlUserPaneDrawUPP gTPDrawProc
= NULL
;
2808 ControlUserPaneHitTestUPP gTPHitProc
= NULL
;
2809 ControlUserPaneTrackingUPP gTPTrackProc
= NULL
;
2810 ControlUserPaneIdleUPP gTPIdleProc
= NULL
;
2811 ControlUserPaneKeyDownUPP gTPKeyProc
= NULL
;
2812 ControlUserPaneActivateUPP gTPActivateProc
= NULL
;
2813 ControlUserPaneFocusUPP gTPFocusProc
= NULL
;
2815 static pascal void wxMacControlUserPaneDrawProc(ControlRef control
, SInt16 part
)
2817 wxTextCtrl
*textCtrl
= wxDynamicCast( wxFindControlFromMacControl(control
) , wxTextCtrl
) ;
2818 wxMacMLTEClassicControl
* win
= textCtrl
? (wxMacMLTEClassicControl
*)(textCtrl
->GetPeer()) : NULL
;
2820 win
->MacControlUserPaneDrawProc( part
) ;
2823 static pascal ControlPartCode
wxMacControlUserPaneHitTestProc(ControlRef control
, Point where
)
2825 wxTextCtrl
*textCtrl
= wxDynamicCast( wxFindControlFromMacControl(control
) , wxTextCtrl
) ;
2826 wxMacMLTEClassicControl
* win
= textCtrl
? (wxMacMLTEClassicControl
*)(textCtrl
->GetPeer()) : NULL
;
2828 return win
->MacControlUserPaneHitTestProc( where
.h
, where
.v
) ;
2830 return kControlNoPart
;
2833 static pascal ControlPartCode
wxMacControlUserPaneTrackingProc(ControlRef control
, Point startPt
, ControlActionUPP actionProc
)
2835 wxTextCtrl
*textCtrl
= wxDynamicCast( wxFindControlFromMacControl(control
) , wxTextCtrl
) ;
2836 wxMacMLTEClassicControl
* win
= textCtrl
? (wxMacMLTEClassicControl
*)(textCtrl
->GetPeer()) : NULL
;
2838 return win
->MacControlUserPaneTrackingProc( startPt
.h
, startPt
.v
, (void*) actionProc
) ;
2840 return kControlNoPart
;
2843 static pascal void wxMacControlUserPaneIdleProc(ControlRef control
)
2845 wxTextCtrl
*textCtrl
= wxDynamicCast( wxFindControlFromMacControl(control
) , wxTextCtrl
) ;
2846 wxMacMLTEClassicControl
* win
= textCtrl
? (wxMacMLTEClassicControl
*)(textCtrl
->GetPeer()) : NULL
;
2848 win
->MacControlUserPaneIdleProc() ;
2851 static pascal ControlPartCode
wxMacControlUserPaneKeyDownProc(ControlRef control
, SInt16 keyCode
, SInt16 charCode
, SInt16 modifiers
)
2853 wxTextCtrl
*textCtrl
= wxDynamicCast( wxFindControlFromMacControl(control
) , wxTextCtrl
) ;
2854 wxMacMLTEClassicControl
* win
= textCtrl
? (wxMacMLTEClassicControl
*)(textCtrl
->GetPeer()) : NULL
;
2856 return win
->MacControlUserPaneKeyDownProc( keyCode
, charCode
, modifiers
) ;
2858 return kControlNoPart
;
2861 static pascal void wxMacControlUserPaneActivateProc(ControlRef control
, Boolean activating
)
2863 wxTextCtrl
*textCtrl
= wxDynamicCast( wxFindControlFromMacControl(control
) , wxTextCtrl
) ;
2864 wxMacMLTEClassicControl
* win
= textCtrl
? (wxMacMLTEClassicControl
*)(textCtrl
->GetPeer()) : NULL
;
2866 win
->MacControlUserPaneActivateProc( activating
) ;
2869 static pascal ControlPartCode
wxMacControlUserPaneFocusProc(ControlRef control
, ControlFocusPart action
)
2871 wxTextCtrl
*textCtrl
= wxDynamicCast( wxFindControlFromMacControl(control
) , wxTextCtrl
) ;
2872 wxMacMLTEClassicControl
* win
= textCtrl
? (wxMacMLTEClassicControl
*)(textCtrl
->GetPeer()) : NULL
;
2874 return win
->MacControlUserPaneFocusProc( action
) ;
2876 return kControlNoPart
;
2880 static pascal void wxMacControlUserPaneBackgroundProc(ControlRef control
, ControlBackgroundPtr info
)
2882 wxTextCtrl
*textCtrl
= wxDynamicCast( wxFindControlFromMacControl(control
) , wxTextCtrl
) ;
2883 wxMacMLTEClassicControl
* win
= textCtrl
? (wxMacMLTEClassicControl
*)(textCtrl
->GetPeer()) : NULL
;
2885 win
->MacControlUserPaneBackgroundProc(info
) ;
2889 #endif // __WXMAC_OSX__
2891 // TXNRegisterScrollInfoProc
2893 OSStatus
wxMacMLTEClassicControl::DoCreate()
2896 OSStatus err
= noErr
;
2898 // set up our globals
2899 #ifdef __WXMAC_OSX__
2900 if (gTPDrawProc
== NULL
) gTPDrawProc
= NewControlUserPaneDrawUPP(wxMacControlUserPaneDrawProc
);
2901 if (gTPHitProc
== NULL
) gTPHitProc
= NewControlUserPaneHitTestUPP(wxMacControlUserPaneHitTestProc
);
2902 if (gTPTrackProc
== NULL
) gTPTrackProc
= NewControlUserPaneTrackingUPP(wxMacControlUserPaneTrackingProc
);
2903 if (gTPIdleProc
== NULL
) gTPIdleProc
= NewControlUserPaneIdleUPP(wxMacControlUserPaneIdleProc
);
2904 if (gTPKeyProc
== NULL
) gTPKeyProc
= NewControlUserPaneKeyDownUPP(wxMacControlUserPaneKeyDownProc
);
2905 if (gTPActivateProc
== NULL
) gTPActivateProc
= NewControlUserPaneActivateUPP(wxMacControlUserPaneActivateProc
);
2906 if (gTPFocusProc
== NULL
) gTPFocusProc
= NewControlUserPaneFocusUPP(wxMacControlUserPaneFocusProc
);
2908 if (gTXNScrollInfoProc
== NULL
) gTXNScrollInfoProc
= NewTXNScrollInfoUPP(TXNScrollInfoProc
) ;
2909 if (gTXNScrollActionProc
== NULL
) gTXNScrollActionProc
= NewControlActionUPP(TXNScrollActionProc
) ;
2912 // set the initial settings for our private data
2914 m_txnWindow
= GetControlOwner(m_controlRef
);
2915 m_txnPort
= (GrafPtr
) GetWindowPort(m_txnWindow
);
2917 #ifdef __WXMAC_OSX__
2918 // set up the user pane procedures
2919 SetControlData(m_controlRef
, kControlEntireControl
, kControlUserPaneDrawProcTag
, sizeof(gTPDrawProc
), &gTPDrawProc
);
2920 SetControlData(m_controlRef
, kControlEntireControl
, kControlUserPaneHitTestProcTag
, sizeof(gTPHitProc
), &gTPHitProc
);
2921 SetControlData(m_controlRef
, kControlEntireControl
, kControlUserPaneTrackingProcTag
, sizeof(gTPTrackProc
), &gTPTrackProc
);
2922 SetControlData(m_controlRef
, kControlEntireControl
, kControlUserPaneIdleProcTag
, sizeof(gTPIdleProc
), &gTPIdleProc
);
2923 SetControlData(m_controlRef
, kControlEntireControl
, kControlUserPaneKeyDownProcTag
, sizeof(gTPKeyProc
), &gTPKeyProc
);
2924 SetControlData(m_controlRef
, kControlEntireControl
, kControlUserPaneActivateProcTag
, sizeof(gTPActivateProc
), &gTPActivateProc
);
2925 SetControlData(m_controlRef
, kControlEntireControl
, kControlUserPaneFocusProcTag
, sizeof(gTPFocusProc
), &gTPFocusProc
);
2928 // calculate the rectangles used by the control
2929 UMAGetControlBoundsInWindowCoords( m_controlRef
, &bounds
);
2931 m_txnControlBounds
= bounds
;
2932 m_txnVisBounds
= bounds
;
2937 GetGWorld( &origPort
, &origDev
) ;
2938 SetPort( m_txnPort
);
2940 // create the new edit field
2941 TXNFrameOptions frameOptions
= FrameOptionsFromWXStyle( m_windowStyle
);
2943 #ifdef __WXMAC_OSX__
2944 // the scrollbars are not correctly embedded but are inserted at the root:
2945 // this gives us problems as we have erratic redraws even over the structure area
2947 m_sbHorizontal
= 0 ;
2949 m_lastHorizontalValue
= 0 ;
2950 m_lastVerticalValue
= 0 ;
2952 Rect sb
= { 0 , 0 , 0 , 0 } ;
2953 if ( frameOptions
& kTXNWantVScrollBarMask
)
2955 CreateScrollBarControl( m_txnWindow
, &sb
, 0, 0, 100, 1, true, gTXNScrollActionProc
, &m_sbVertical
);
2956 SetControlReference( m_sbVertical
, (SInt32
)this );
2957 SetControlAction( m_sbVertical
, gTXNScrollActionProc
);
2958 ShowControl( m_sbVertical
);
2959 EmbedControl( m_sbVertical
, m_controlRef
);
2960 frameOptions
&= ~kTXNWantVScrollBarMask
;
2963 if ( frameOptions
& kTXNWantHScrollBarMask
)
2965 CreateScrollBarControl( m_txnWindow
, &sb
, 0, 0, 100, 1, true, gTXNScrollActionProc
, &m_sbHorizontal
);
2966 SetControlReference( m_sbHorizontal
, (SInt32
)this );
2967 SetControlAction( m_sbHorizontal
, gTXNScrollActionProc
);
2968 ShowControl( m_sbHorizontal
);
2969 EmbedControl( m_sbHorizontal
, m_controlRef
);
2970 frameOptions
&= ~(kTXNWantHScrollBarMask
| kTXNDrawGrowIconMask
);
2976 NULL
, m_txnWindow
, &bounds
, frameOptions
,
2977 kTXNTextEditStyleFrameType
, kTXNTextensionFile
, kTXNSystemDefaultEncoding
,
2978 &m_txn
, &m_txnFrameID
, NULL
);
2979 verify_noerr( err
);
2982 TXNControlTag iControlTags
[] = { kTXNUseCarbonEvents
};
2983 TXNControlData iControlData
[] = { { (UInt32
)&cInfo
} };
2984 int toptag
= WXSIZEOF( iControlTags
) ;
2985 TXNCarbonEventInfo cInfo
;
2986 cInfo
.useCarbonEvents
= false ;
2989 cInfo
.fDictionary
= NULL
;
2991 verify_noerr( TXNSetTXNObjectControls( m_txn
, false, toptag
, iControlTags
, iControlData
) );
2994 #ifdef __WXMAC_OSX__
2995 TXNRegisterScrollInfoProc( m_txn
, gTXNScrollInfoProc
, (SInt32
)this );
2998 SetGWorld( origPort
, origDev
) ;
3004 // ----------------------------------------------------------------------------
3005 // MLTE control implementation (OSX part)
3006 // ----------------------------------------------------------------------------
3008 #if TARGET_API_MAC_OSX
3010 #if MAC_OS_X_VERSION_MAX_ALLOWED > MAC_OS_X_VERSION_10_2
3012 // tiger multi-line textcontrols with no CR in the entire content
3013 // don't scroll automatically, so we need a hack.
3014 // This attempt only works 'before' the key (ie before CallNextEventHandler)
3015 // is processed, thus the scrolling always occurs one character too late, but
3016 // better than nothing ...
3018 static const EventTypeSpec eventList
[] =
3020 { kEventClassTextInput
, kEventTextInputUnicodeForKeyEvent
} ,
3023 static pascal OSStatus
wxMacUnicodeTextEventHandler( EventHandlerCallRef handler
, EventRef event
, void *data
)
3025 OSStatus result
= eventNotHandledErr
;
3026 wxMacMLTEHIViewControl
* focus
= (wxMacMLTEHIViewControl
*) data
;
3028 switch ( GetEventKind( event
) )
3030 case kEventTextInputUnicodeForKeyEvent
:
3032 if ( UMAGetSystemVersion() >= 0x1040 )
3034 TXNOffset from
, to
;
3035 TXNGetSelection( focus
->GetTXNObject() , &from
, &to
) ;
3037 TXNShowSelection( focus
->GetTXNObject() , kTXNShowStart
);
3039 result
= CallNextEventHandler(handler
,event
);
3049 static pascal OSStatus
wxMacTextControlEventHandler( EventHandlerCallRef handler
, EventRef event
, void *data
)
3051 OSStatus result
= eventNotHandledErr
;
3053 switch ( GetEventClass( event
) )
3055 case kEventClassTextInput
:
3056 result
= wxMacUnicodeTextEventHandler( handler
, event
, data
) ;
3065 DEFINE_ONE_SHOT_HANDLER_GETTER( wxMacTextControlEventHandler
)
3067 wxMacMLTEHIViewControl::wxMacMLTEHIViewControl( wxTextCtrl
*wxPeer
,
3068 const wxString
& str
,
3070 const wxSize
& size
, long style
) : wxMacMLTEControl( wxPeer
)
3072 m_font
= wxPeer
->GetFont() ;
3073 m_windowStyle
= style
;
3074 Rect bounds
= wxMacGetBoundsForControl( wxPeer
, pos
, size
) ;
3076 wxMacConvertNewlines10To13( &st
) ;
3079 { bounds
.left
, bounds
.top
},
3080 { bounds
.right
- bounds
.left
, bounds
.bottom
- bounds
.top
} } ;
3082 m_scrollView
= NULL
;
3083 TXNFrameOptions frameOptions
= FrameOptionsFromWXStyle( style
) ;
3084 if ( frameOptions
& (kTXNWantVScrollBarMask
| kTXNWantHScrollBarMask
) )
3087 (frameOptions
& kTXNWantHScrollBarMask
? kHIScrollViewOptionsHorizScroll
: 0)
3088 | (frameOptions
& kTXNWantVScrollBarMask
? kHIScrollViewOptionsVertScroll
: 0) ,
3091 HIViewSetFrame( m_scrollView
, &hr
);
3092 HIViewSetVisible( m_scrollView
, true );
3096 HITextViewCreate( NULL
, 0, frameOptions
, &m_textView
) ;
3097 m_txn
= HITextViewGetTXNObject( m_textView
) ;
3098 HIViewSetVisible( m_textView
, true ) ;
3101 HIViewAddSubview( m_scrollView
, m_textView
) ;
3102 m_controlRef
= m_scrollView
;
3103 wxPeer
->MacInstallEventHandler( (WXWidget
) m_textView
) ;
3107 HIViewSetFrame( m_textView
, &hr
);
3108 m_controlRef
= m_textView
;
3111 AdjustCreationAttributes( *wxWHITE
, true ) ;
3113 wxMacWindowClipper
c( m_peer
) ;
3115 SetTXNData( st
, kTXNStartOffset
, kTXNEndOffset
) ;
3117 TXNSetSelection( m_txn
, 0, 0 );
3118 TXNShowSelection( m_txn
, kTXNShowStart
);
3120 InstallControlEventHandler( m_textView
, GetwxMacTextControlEventHandlerUPP(),
3121 GetEventTypeCount(eventList
), eventList
, this,
3122 &m_textEventHandlerRef
);
3125 wxMacMLTEHIViewControl::~wxMacMLTEHIViewControl()
3127 ::RemoveEventHandler( m_textEventHandlerRef
) ;
3130 OSStatus
wxMacMLTEHIViewControl::SetFocus( ControlFocusPart focusPart
)
3132 return SetKeyboardFocus( GetControlOwner( m_textView
), m_textView
, focusPart
) ;
3135 bool wxMacMLTEHIViewControl::HasFocus() const
3137 ControlRef control
;
3138 GetKeyboardFocus( GetUserFocusWindow() , &control
) ;
3139 return control
== m_textView
;
3142 void wxMacMLTEHIViewControl::SetBackground( const wxBrush
&brush
)
3144 wxMacMLTEControl::SetBackground( brush
) ;
3147 CGColorSpaceRef rgbSpace
= CGColorSpaceCreateDeviceRGB();
3148 RGBColor col
= MAC_WXCOLORREF(brush
.GetColour().GetPixel()) ;
3150 float component
[4] ;
3151 component
[0] = col
.red
/ 65536.0 ;
3152 component
[1] = col
.green
/ 65536.0 ;
3153 component
[2] = col
.blue
/ 65536.0 ;
3154 component
[3] = 1.0 ; // alpha
3156 CGColorRef color
= CGColorCreate( rgbSpace
, component
);
3157 HITextViewSetBackgroundColor( m_textView
, color
);
3158 CGColorSpaceRelease( rgbSpace
);
3162 #endif // MAC_OS_X_VERSION_MAX_ALLOWED > MAC_OS_X_VERSION_10_2
3167 #endif // wxUSE_TEXTCTRL