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
)
479 !(m_windowStyle
& wxTE_PROCESS_ENTER
),
480 wxT("wxTE_PROCESS_ENTER style is ignored for multiline text controls (they always process it)") );
482 m_windowStyle
|= wxTE_PROCESS_ENTER
;
483 style
|= wxTE_PROCESS_ENTER
;
486 bool forceMLTE
= false ;
488 #if wxUSE_SYSTEM_OPTIONS
489 if (wxSystemOptions::HasOption( wxMAC_TEXTCONTROL_USE_MLTE
) && (wxSystemOptions::GetOptionInt( wxMAC_TEXTCONTROL_USE_MLTE
) == 1))
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 ( !(m_windowStyle
& wxTE_MULTILINE
) && !forceMLTE
)
507 m_peer
= new wxMacUnicodeTextControl( this , str
, pos
, size
, style
) ;
512 m_peer
= new wxMacMLTEClassicControl( this , str
, pos
, size
, style
) ;
514 MacPostControlCreate(pos
, size
) ;
516 // only now the embedding is correct and we can do a positioning update
518 MacSuperChangedPosition() ;
520 if ( m_windowStyle
& wxTE_READONLY
)
521 SetEditable( false ) ;
523 SetCursor( wxCursor( wxCURSOR_IBEAM
) ) ;
528 void wxTextCtrl::MacSuperChangedPosition()
530 wxWindow::MacSuperChangedPosition() ;
531 GetPeer()->SuperChangedPosition() ;
534 void wxTextCtrl::MacVisibilityChanged()
536 GetPeer()->VisibilityChanged( MacIsReallyShown() ) ;
539 void wxTextCtrl::MacEnabledStateChanged()
543 wxString
wxTextCtrl::GetValue() const
545 return GetPeer()->GetStringValue() ;
548 void wxTextCtrl::GetSelection(long* from
, long* to
) const
550 GetPeer()->GetSelection( from
, to
) ;
553 void wxTextCtrl::SetValue(const wxString
& str
)
556 if ( GetValue() == str
)
559 GetPeer()->SetStringValue( str
) ;
561 if ( m_triggerOnSetValue
)
563 wxCommandEvent
event( wxEVT_COMMAND_TEXT_UPDATED
, m_windowId
);
564 event
.SetString( GetValue() );
565 event
.SetEventObject( this );
566 GetEventHandler()->ProcessEvent( event
);
570 void wxTextCtrl::SetMaxLength(unsigned long len
)
575 bool wxTextCtrl::SetFont( const wxFont
& font
)
577 if ( !wxTextCtrlBase::SetFont( font
) )
580 GetPeer()->SetFont( font
, GetForegroundColour() , GetWindowStyle() ) ;
585 bool wxTextCtrl::SetStyle(long start
, long end
, const wxTextAttr
& style
)
587 GetPeer()->SetStyle( start
, end
, style
) ;
592 bool wxTextCtrl::SetDefaultStyle(const wxTextAttr
& style
)
594 wxTextCtrlBase::SetDefaultStyle( style
) ;
595 SetStyle( kTXNUseCurrentSelection
, kTXNUseCurrentSelection
, GetDefaultStyle() ) ;
600 // Clipboard operations
602 void wxTextCtrl::Copy()
608 void wxTextCtrl::Cut()
614 wxCommandEvent
event( wxEVT_COMMAND_TEXT_UPDATED
, m_windowId
);
615 event
.SetEventObject( this );
616 GetEventHandler()->ProcessEvent( event
);
620 void wxTextCtrl::Paste()
626 // TODO: eventually we should add setting the default style again
628 wxCommandEvent
event( wxEVT_COMMAND_TEXT_UPDATED
, m_windowId
);
629 event
.SetEventObject( this );
630 GetEventHandler()->ProcessEvent( event
);
634 bool wxTextCtrl::CanCopy() const
636 // Can copy if there's a selection
638 GetSelection( &from
, &to
);
643 bool wxTextCtrl::CanCut() const
648 // Can cut if there's a selection
650 GetSelection( &from
, &to
);
655 bool wxTextCtrl::CanPaste() const
660 return GetPeer()->CanPaste() ;
663 void wxTextCtrl::SetEditable(bool editable
)
665 if ( editable
!= m_editable
)
667 m_editable
= editable
;
668 GetPeer()->SetEditable( editable
) ;
672 void wxTextCtrl::SetInsertionPoint(long pos
)
674 SetSelection( pos
, pos
) ;
677 void wxTextCtrl::SetInsertionPointEnd()
679 wxTextPos pos
= GetLastPosition();
680 SetInsertionPoint( pos
);
683 long wxTextCtrl::GetInsertionPoint() const
686 GetSelection( &begin
, &end
) ;
691 wxTextPos
wxTextCtrl::GetLastPosition() const
693 return GetPeer()->GetLastPosition() ;
696 void wxTextCtrl::Replace(long from
, long to
, const wxString
& str
)
698 GetPeer()->Replace( from
, to
, str
) ;
701 void wxTextCtrl::Remove(long from
, long to
)
703 GetPeer()->Remove( from
, to
) ;
706 void wxTextCtrl::SetSelection(long from
, long to
)
708 GetPeer()->SetSelection( from
, to
) ;
711 bool wxTextCtrl::LoadFile(const wxString
& file
)
713 return wxTextCtrlBase::LoadFile( file
);
716 void wxTextCtrl::WriteText(const wxString
& str
)
718 // TODO: this MPRemoting will be moved into a remoting peer proxy for any command
719 if ( !wxIsMainThread() )
721 // unfortunately CW 8 is not able to correctly deduce the template types,
722 // so we have to instantiate explicitly
723 wxMacMPRemoteGUICall
<wxTextCtrl
,wxString
>( this , &wxTextCtrl::WriteText
, str
) ;
728 GetPeer()->WriteText( str
) ;
731 void wxTextCtrl::AppendText(const wxString
& text
)
733 SetInsertionPointEnd();
737 void wxTextCtrl::Clear()
742 bool wxTextCtrl::IsModified() const
747 bool wxTextCtrl::IsEditable() const
749 return IsEnabled() && m_editable
;
752 bool wxTextCtrl::AcceptsFocus() const
754 // we don't want focus if we can't be edited
755 return /*IsEditable() && */ wxControl::AcceptsFocus();
758 wxSize
wxTextCtrl::DoGetBestSize() const
762 // these are the numbers from the HIG:
763 // we reduce them by the borders first
766 switch ( m_windowVariant
)
768 case wxWINDOW_VARIANT_NORMAL
:
772 case wxWINDOW_VARIANT_SMALL
:
776 case wxWINDOW_VARIANT_MINI
:
785 // as the above numbers have some free space around the text
786 // we get 5 lines like this anyway
787 if ( m_windowStyle
& wxTE_MULTILINE
)
790 if ( !HasFlag(wxNO_BORDER
) )
793 return wxSize(wText
, hText
);
796 // ----------------------------------------------------------------------------
798 // ----------------------------------------------------------------------------
800 void wxTextCtrl::Undo()
806 void wxTextCtrl::Redo()
812 bool wxTextCtrl::CanUndo() const
817 return GetPeer()->CanUndo() ;
820 bool wxTextCtrl::CanRedo() const
825 return GetPeer()->CanRedo() ;
828 void wxTextCtrl::MarkDirty()
833 void wxTextCtrl::DiscardEdits()
838 int wxTextCtrl::GetNumberOfLines() const
840 return GetPeer()->GetNumberOfLines() ;
843 long wxTextCtrl::XYToPosition(long x
, long y
) const
845 return GetPeer()->XYToPosition( x
, y
) ;
848 bool wxTextCtrl::PositionToXY(long pos
, long *x
, long *y
) const
850 return GetPeer()->PositionToXY( pos
, x
, y
) ;
853 void wxTextCtrl::ShowPosition(long pos
)
855 return GetPeer()->ShowPosition(pos
) ;
858 int wxTextCtrl::GetLineLength(long lineNo
) const
860 return GetPeer()->GetLineLength(lineNo
) ;
863 wxString
wxTextCtrl::GetLineText(long lineNo
) const
865 return GetPeer()->GetLineText(lineNo
) ;
868 void wxTextCtrl::Command(wxCommandEvent
& event
)
870 SetValue(event
.GetString());
871 ProcessCommand(event
);
874 void wxTextCtrl::OnDropFiles(wxDropFilesEvent
& event
)
876 // By default, load the first file into the text window.
877 if (event
.GetNumberOfFiles() > 0)
878 LoadFile( event
.GetFiles()[0] );
881 void wxTextCtrl::OnEraseBackground(wxEraseEvent
& event
)
883 // all erasing should be done by the real mac control implementation
884 // while this is true for MLTE under classic, the HITextView is somehow
885 // transparent but background erase is not working correctly, so intercept
886 // things while we can...
890 void wxTextCtrl::OnChar(wxKeyEvent
& event
)
892 int key
= event
.GetKeyCode() ;
893 bool eat_key
= false ;
895 if ( key
== 'a' && event
.MetaDown() )
902 if ( key
== 'c' && event
.MetaDown() )
910 if ( !IsEditable() && key
!= WXK_LEFT
&& key
!= WXK_RIGHT
&& key
!= WXK_DOWN
&& key
!= WXK_UP
&& key
!= WXK_TAB
&&
911 !( key
== WXK_RETURN
&& ( (m_windowStyle
& wxTE_PROCESS_ENTER
) || (m_windowStyle
& wxTE_MULTILINE
) ) )
912 // && key != WXK_PAGEUP && key != WXK_PAGEDOWN && key != WXK_HOME && key != WXK_END
919 // Check if we have reached the max # of chars (if it is set), but still
920 // allow navigation and deletion
921 if ( !IsMultiLine() && m_maxLength
&& GetValue().length() >= m_maxLength
&&
922 key
!= WXK_LEFT
&& key
!= WXK_RIGHT
&& key
!= WXK_TAB
&&
923 key
!= WXK_BACK
&& !( key
== WXK_RETURN
&& (m_windowStyle
& wxTE_PROCESS_ENTER
) )
926 // eat it, we don't want to add more than allowed # of characters
928 // TODO: generate EVT_TEXT_MAXLEN()
932 // assume that any key not processed yet is going to modify the control
935 if ( key
== 'v' && event
.MetaDown() )
943 if ( key
== 'x' && event
.MetaDown() )
954 if (m_windowStyle
& wxTE_PROCESS_ENTER
)
956 wxCommandEvent
event(wxEVT_COMMAND_TEXT_ENTER
, m_windowId
);
957 event
.SetEventObject( this );
958 event
.SetString( GetValue() );
959 if ( GetEventHandler()->ProcessEvent(event
) )
963 if ( !(m_windowStyle
& wxTE_MULTILINE
) )
965 wxTopLevelWindow
*tlw
= wxDynamicCast(wxGetTopLevelParent(this), wxTopLevelWindow
);
966 if ( tlw
&& tlw
->GetDefaultItem() )
968 wxButton
*def
= wxDynamicCast(tlw
->GetDefaultItem(), wxButton
);
969 if ( def
&& def
->IsEnabled() )
971 wxCommandEvent
event(wxEVT_COMMAND_BUTTON_CLICKED
, def
->GetId() );
972 event
.SetEventObject(def
);
979 // this will make wxWidgets eat the ENTER key so that
980 // we actually prevent line wrapping in a single line text control
986 if ( !(m_windowStyle
& wxTE_PROCESS_TAB
))
989 if (!event
.ShiftDown())
990 flags
|= wxNavigationKeyEvent::IsForward
;
991 if (event
.ControlDown())
992 flags
|= wxNavigationKeyEvent::WinChange
;
999 // This is necessary (don't know why);
1000 // otherwise the tab will not be inserted.
1001 WriteText(wxT("\t"));
1012 // perform keystroke handling
1016 if ( ( key
>= 0x20 && key
< WXK_START
) ||
1017 ( key
>= WXK_NUMPAD0
&& key
<= WXK_DIVIDE
) ||
1018 key
== WXK_RETURN
||
1019 key
== WXK_DELETE
||
1022 wxCommandEvent
event1(wxEVT_COMMAND_TEXT_UPDATED
, m_windowId
);
1023 event1
.SetEventObject( this );
1024 wxPostEvent( GetEventHandler(), event1
);
1028 // ----------------------------------------------------------------------------
1029 // standard handlers for standard edit menu events
1030 // ----------------------------------------------------------------------------
1032 void wxTextCtrl::OnCut(wxCommandEvent
& WXUNUSED(event
))
1037 void wxTextCtrl::OnCopy(wxCommandEvent
& WXUNUSED(event
))
1042 void wxTextCtrl::OnPaste(wxCommandEvent
& WXUNUSED(event
))
1047 void wxTextCtrl::OnUndo(wxCommandEvent
& WXUNUSED(event
))
1052 void wxTextCtrl::OnRedo(wxCommandEvent
& WXUNUSED(event
))
1057 void wxTextCtrl::OnDelete(wxCommandEvent
& WXUNUSED(event
))
1061 GetSelection( &from
, &to
);
1062 if (from
!= -1 && to
!= -1)
1066 void wxTextCtrl::OnSelectAll(wxCommandEvent
& WXUNUSED(event
))
1068 SetSelection(-1, -1);
1071 void wxTextCtrl::OnUpdateCut(wxUpdateUIEvent
& event
)
1073 event
.Enable( CanCut() );
1076 void wxTextCtrl::OnUpdateCopy(wxUpdateUIEvent
& event
)
1078 event
.Enable( CanCopy() );
1081 void wxTextCtrl::OnUpdatePaste(wxUpdateUIEvent
& event
)
1083 event
.Enable( CanPaste() );
1086 void wxTextCtrl::OnUpdateUndo(wxUpdateUIEvent
& event
)
1088 event
.Enable( CanUndo() );
1091 void wxTextCtrl::OnUpdateRedo(wxUpdateUIEvent
& event
)
1093 event
.Enable( CanRedo() );
1096 void wxTextCtrl::OnUpdateDelete(wxUpdateUIEvent
& event
)
1100 GetSelection( &from
, &to
);
1101 event
.Enable( from
!= -1 && to
!= -1 && from
!= to
&& IsEditable() ) ;
1104 void wxTextCtrl::OnUpdateSelectAll(wxUpdateUIEvent
& event
)
1106 event
.Enable(GetLastPosition() > 0);
1109 // CS: Context Menus only work with MLTE implementations or non-multiline HIViews at the moment
1111 void wxTextCtrl::OnContextMenu(wxContextMenuEvent
& event
)
1113 if ( GetPeer()->HasOwnContextMenu() )
1119 if (m_privateContextMenu
== NULL
)
1121 m_privateContextMenu
= new wxMenu
;
1122 m_privateContextMenu
->Append(wxID_UNDO
, _("&Undo"));
1123 m_privateContextMenu
->Append(wxID_REDO
, _("&Redo"));
1124 m_privateContextMenu
->AppendSeparator();
1125 m_privateContextMenu
->Append(wxID_CUT
, _("Cu&t"));
1126 m_privateContextMenu
->Append(wxID_COPY
, _("&Copy"));
1127 m_privateContextMenu
->Append(wxID_PASTE
, _("&Paste"));
1128 m_privateContextMenu
->Append(wxID_CLEAR
, _("&Delete"));
1129 m_privateContextMenu
->AppendSeparator();
1130 m_privateContextMenu
->Append(wxID_SELECTALL
, _("Select &All"));
1133 if (m_privateContextMenu
!= NULL
)
1134 PopupMenu(m_privateContextMenu
);
1137 bool wxTextCtrl::MacSetupCursor( const wxPoint
& pt
)
1139 if ( !GetPeer()->SetupCursor( pt
) )
1140 return wxWindow::MacSetupCursor( pt
) ;
1145 #if !TARGET_API_MAC_OSX
1147 // user pane implementation
1149 void wxTextCtrl::MacControlUserPaneDrawProc(wxInt16 part
)
1151 GetPeer()->MacControlUserPaneDrawProc( part
) ;
1154 wxInt16
wxTextCtrl::MacControlUserPaneHitTestProc(wxInt16 x
, wxInt16 y
)
1156 return GetPeer()->MacControlUserPaneHitTestProc( x
, y
) ;
1159 wxInt16
wxTextCtrl::MacControlUserPaneTrackingProc(wxInt16 x
, wxInt16 y
, void* actionProc
)
1161 return GetPeer()->MacControlUserPaneTrackingProc( x
, y
, actionProc
) ;
1164 void wxTextCtrl::MacControlUserPaneIdleProc()
1166 GetPeer()->MacControlUserPaneIdleProc( ) ;
1169 wxInt16
wxTextCtrl::MacControlUserPaneKeyDownProc(wxInt16 keyCode
, wxInt16 charCode
, wxInt16 modifiers
)
1171 return GetPeer()->MacControlUserPaneKeyDownProc( keyCode
, charCode
, modifiers
) ;
1174 void wxTextCtrl::MacControlUserPaneActivateProc(bool activating
)
1176 GetPeer()->MacControlUserPaneActivateProc( activating
) ;
1179 wxInt16
wxTextCtrl::MacControlUserPaneFocusProc(wxInt16 action
)
1181 return GetPeer()->MacControlUserPaneFocusProc( action
) ;
1184 void wxTextCtrl::MacControlUserPaneBackgroundProc(void* info
)
1186 GetPeer()->MacControlUserPaneBackgroundProc( info
) ;
1191 // ----------------------------------------------------------------------------
1192 // implementation base class
1193 // ----------------------------------------------------------------------------
1195 wxMacTextControl::wxMacTextControl(wxTextCtrl
* peer
) :
1196 wxMacControl( peer
)
1200 wxMacTextControl::~wxMacTextControl()
1204 void wxMacTextControl::SetStyle(long start
, long end
, const wxTextAttr
& style
)
1208 void wxMacTextControl::Copy()
1212 void wxMacTextControl::Cut()
1216 void wxMacTextControl::Paste()
1220 bool wxMacTextControl::CanPaste() const
1225 void wxMacTextControl::SetEditable(bool editable
)
1229 wxTextPos
wxMacTextControl::GetLastPosition() const
1231 return GetStringValue().length() ;
1234 void wxMacTextControl::Replace( long from
, long to
, const wxString
&val
)
1236 SetSelection( from
, to
) ;
1240 void wxMacTextControl::Remove( long from
, long to
)
1242 SetSelection( from
, to
) ;
1243 WriteText( wxEmptyString
) ;
1246 void wxMacTextControl::Clear()
1248 SetStringValue( wxEmptyString
) ;
1251 bool wxMacTextControl::CanUndo() const
1256 void wxMacTextControl::Undo()
1260 bool wxMacTextControl::CanRedo() const
1265 void wxMacTextControl::Redo()
1269 long wxMacTextControl::XYToPosition(long x
, long y
) const
1274 bool wxMacTextControl::PositionToXY(long pos
, long *x
, long *y
) const
1279 void wxMacTextControl::ShowPosition( long WXUNUSED(pos
) )
1283 int wxMacTextControl::GetNumberOfLines() const
1285 ItemCount lines
= 0 ;
1286 wxString content
= GetStringValue() ;
1289 for (size_t i
= 0; i
< content
.length() ; i
++)
1291 if (content
[i
] == '\r')
1298 wxString
wxMacTextControl::GetLineText(long lineNo
) const
1300 // TODO: change this if possible to reflect real lines
1301 wxString content
= GetStringValue() ;
1305 for (size_t i
= 0; i
< content
.length() ; i
++)
1307 if (count
== lineNo
)
1309 // Add chars in line then
1312 for (size_t j
= i
; j
< content
.length(); j
++)
1314 if (content
[j
] == '\n')
1323 if (content
[i
] == '\n')
1327 return wxEmptyString
;
1330 int wxMacTextControl::GetLineLength(long lineNo
) const
1332 // TODO: change this if possible to reflect real lines
1333 wxString content
= GetStringValue() ;
1337 for (size_t i
= 0; i
< content
.length() ; i
++)
1339 if (count
== lineNo
)
1341 // Count chars in line then
1343 for (size_t j
= i
; j
< content
.length(); j
++)
1346 if (content
[j
] == '\n')
1353 if (content
[i
] == '\n')
1360 // ----------------------------------------------------------------------------
1361 // standard unicode control implementation
1362 // ----------------------------------------------------------------------------
1364 #if TARGET_API_MAC_OSX
1366 // the current unicode textcontrol implementation has a bug : only if the control
1367 // is currently having the focus, the selection can be retrieved by the corresponding
1368 // data tag. So we have a mirroring using a member variable
1369 // TODO : build event table using virtual member functions for wxMacControl
1371 static const EventTypeSpec unicodeTextControlEventList
[] =
1373 { kEventClassControl
, kEventControlSetFocusPart
} ,
1376 static pascal OSStatus
wxMacUnicodeTextControlControlEventHandler( EventHandlerCallRef handler
, EventRef event
, void *data
)
1378 OSStatus result
= eventNotHandledErr
;
1379 wxMacUnicodeTextControl
* focus
= (wxMacUnicodeTextControl
*) data
;
1380 wxMacCarbonEvent
cEvent( event
) ;
1382 switch ( GetEventKind( event
) )
1384 case kEventControlSetFocusPart
:
1386 ControlPartCode controlPart
= cEvent
.GetParameter
<ControlPartCode
>(kEventParamControlPart
, typeControlPartCode
);
1387 if ( controlPart
== kControlFocusNoPart
)
1389 // about to loose focus -> store selection to field
1390 focus
->GetData
<ControlEditTextSelectionRec
>( 0, kControlEditTextSelectionTag
, &focus
->m_selection
);
1392 result
= CallNextEventHandler(handler
,event
) ;
1393 if ( controlPart
!= kControlFocusNoPart
)
1395 // about to gain focus -> set selection from field
1396 focus
->SetData
<ControlEditTextSelectionRec
>( 0, kControlEditTextSelectionTag
, &focus
->m_selection
);
1407 static pascal OSStatus
wxMacUnicodeTextControlEventHandler( EventHandlerCallRef handler
, EventRef event
, void *data
)
1409 OSStatus result
= eventNotHandledErr
;
1411 switch ( GetEventClass( event
) )
1413 case kEventClassControl
:
1414 result
= wxMacUnicodeTextControlControlEventHandler( handler
, event
, data
) ;
1423 DEFINE_ONE_SHOT_HANDLER_GETTER( wxMacUnicodeTextControlEventHandler
)
1425 wxMacUnicodeTextControl::wxMacUnicodeTextControl( wxTextCtrl
*wxPeer
,
1426 const wxString
& str
,
1428 const wxSize
& size
, long style
)
1429 : wxMacTextControl( wxPeer
)
1431 m_font
= wxPeer
->GetFont() ;
1432 m_windowStyle
= style
;
1433 Rect bounds
= wxMacGetBoundsForControl( wxPeer
, pos
, size
) ;
1435 wxMacConvertNewlines10To13( &st
) ;
1436 wxMacCFStringHolder
cf(st
, m_font
.GetEncoding()) ;
1437 CFStringRef cfr
= cf
;
1438 Boolean isPassword
= ( m_windowStyle
& wxTE_PASSWORD
) != 0 ;
1439 m_valueTag
= isPassword
? kControlEditTextPasswordCFStringTag
: kControlEditTextCFStringTag
;
1441 OSStatus err
= CreateEditUnicodeTextControl(
1442 MAC_WXHWND(wxPeer
->MacGetTopLevelWindowRef()), &bounds
, cfr
,
1443 isPassword
, NULL
, &m_controlRef
) ;
1444 verify_noerr( err
);
1446 if ( !(m_windowStyle
& wxTE_MULTILINE
) )
1447 SetData
<Boolean
>( kControlEditTextPart
, kControlEditTextSingleLineTag
, true ) ;
1449 InstallControlEventHandler( m_controlRef
, GetwxMacUnicodeTextControlEventHandlerUPP(),
1450 GetEventTypeCount(unicodeTextControlEventList
), unicodeTextControlEventList
, this,
1451 &m_focusHandlerRef
);
1454 wxMacUnicodeTextControl::~wxMacUnicodeTextControl()
1456 ::RemoveEventHandler( m_focusHandlerRef
);
1459 void wxMacUnicodeTextControl::VisibilityChanged(bool shown
)
1461 if ( !(m_windowStyle
& wxTE_MULTILINE
) && shown
)
1463 // work around a refresh issue insofar as not always the entire content is shown,
1464 // even if this would be possible
1465 ControlEditTextSelectionRec sel
;
1466 CFStringRef value
= NULL
;
1468 verify_noerr( GetData
<ControlEditTextSelectionRec
>( 0, kControlEditTextSelectionTag
, &sel
) );
1469 verify_noerr( GetData
<CFStringRef
>( 0, m_valueTag
, &value
) );
1470 verify_noerr( SetData
<CFStringRef
>( 0, m_valueTag
, &value
) );
1471 verify_noerr( SetData
<ControlEditTextSelectionRec
>( 0, kControlEditTextSelectionTag
, &sel
) );
1473 CFRelease( value
) ;
1477 wxString
wxMacUnicodeTextControl::GetStringValue() const
1480 CFStringRef value
= GetData
<CFStringRef
>(0, m_valueTag
) ;
1483 wxMacCFStringHolder
cf(value
) ;
1484 result
= cf
.AsString() ;
1488 wxMacConvertNewlines13To10( &result
) ;
1490 wxMacConvertNewlines10To13( &result
) ;
1496 void wxMacUnicodeTextControl::SetStringValue( const wxString
&str
)
1499 wxMacConvertNewlines10To13( &st
) ;
1500 wxMacCFStringHolder
cf( st
, m_font
.GetEncoding() ) ;
1501 verify_noerr( SetData
<CFStringRef
>( 0, m_valueTag
, cf
) ) ;
1504 void wxMacUnicodeTextControl::Copy()
1506 SendHICommand( kHICommandCopy
) ;
1509 void wxMacUnicodeTextControl::Cut()
1511 SendHICommand( kHICommandCut
) ;
1514 void wxMacUnicodeTextControl::Paste()
1516 SendHICommand( kHICommandPaste
) ;
1519 bool wxMacUnicodeTextControl::CanPaste() const
1524 void wxMacUnicodeTextControl::SetEditable(bool editable
)
1526 #if 0 // leads to problem because text cannot be selected anymore
1527 SetData
<Boolean
>( kControlEditTextPart
, kControlEditTextLockedTag
, (Boolean
) !editable
) ;
1531 void wxMacUnicodeTextControl::GetSelection( long* from
, long* to
) const
1533 ControlEditTextSelectionRec sel
;
1535 verify_noerr( GetData
<ControlEditTextSelectionRec
>( 0, kControlEditTextSelectionTag
, &sel
) ) ;
1540 *from
= sel
.selStart
;
1545 void wxMacUnicodeTextControl::SetSelection( long from
, long to
)
1547 ControlEditTextSelectionRec sel
;
1549 int textLength
= 0 ;
1550 CFStringRef value
= GetData
<CFStringRef
>(0, m_valueTag
) ;
1553 wxMacCFStringHolder
cf(value
) ;
1554 textLength
= cf
.AsString().length() ;
1557 if ((from
== -1) && (to
== -1))
1564 from
= wxMin(textLength
,wxMax(from
,0)) ;
1565 to
= wxMax(0,wxMin(textLength
,to
)) ;
1568 sel
.selStart
= from
;
1571 SetData
<ControlEditTextSelectionRec
>( 0, kControlEditTextSelectionTag
, &sel
) ;
1576 void wxMacUnicodeTextControl::WriteText( const wxString
& str
)
1579 wxMacConvertNewlines10To13( &st
) ;
1581 #if MAC_OS_X_VERSION_MAX_ALLOWED > MAC_OS_X_VERSION_10_2
1584 wxMacCFStringHolder
cf(st
, m_font
.GetEncoding() ) ;
1585 CFStringRef value
= cf
;
1586 SetData
<CFStringRef
>( 0, kControlEditTextInsertCFStringRefTag
, &value
);
1591 wxString val
= GetStringValue() ;
1593 GetSelection( &start
, &end
) ;
1594 val
.Remove( start
, end
- start
) ;
1595 val
.insert( start
, str
) ;
1596 SetStringValue( val
) ;
1597 SetSelection( start
+ str
.length() , start
+ str
.length() ) ;
1603 // ----------------------------------------------------------------------------
1604 // MLTE control implementation (common part)
1605 // ----------------------------------------------------------------------------
1607 // if MTLE is read only, no changes at all are allowed, not even from
1608 // procedural API, in order to allow changes via API all the same we must undo
1609 // the readonly status while we are executing, this class helps to do so
1611 class wxMacEditHelper
1614 wxMacEditHelper( TXNObject txn
)
1616 TXNControlTag tag
[] = { kTXNIOPrivilegesTag
} ;
1618 TXNGetTXNObjectControls( m_txn
, 1 , tag
, m_data
) ;
1619 if ( m_data
[0].uValue
== kTXNReadOnly
)
1621 TXNControlData data
[] = { { kTXNReadWrite
} } ;
1622 TXNSetTXNObjectControls( m_txn
, false , 1 , tag
, data
) ;
1628 TXNControlTag tag
[] = { kTXNIOPrivilegesTag
} ;
1629 if ( m_data
[0].uValue
== kTXNReadOnly
)
1630 TXNSetTXNObjectControls( m_txn
, false , 1 , tag
, m_data
) ;
1635 TXNControlData m_data
[1] ;
1638 wxMacMLTEControl::wxMacMLTEControl( wxTextCtrl
*peer
)
1639 : wxMacTextControl( peer
)
1641 SetNeedsFocusRect( true ) ;
1644 wxString
wxMacMLTEControl::GetStringValue() const
1648 Size actualSize
= 0;
1653 err
= TXNGetDataEncoded( m_txn
, kTXNStartOffset
, kTXNEndOffset
, &theText
, kTXNUnicodeTextData
);
1662 actualSize
= GetHandleSize( theText
) / sizeof(UniChar
) ;
1663 if ( actualSize
> 0 )
1665 wxChar
*ptr
= NULL
;
1667 #if SIZEOF_WCHAR_T == 2
1668 ptr
= new wxChar
[actualSize
+ 1] ;
1669 wxStrncpy( ptr
, (wxChar
*)(*theText
) , actualSize
) ;
1671 SetHandleSize( theText
, (actualSize
+ 1) * sizeof(UniChar
) ) ;
1673 (((UniChar
*)*theText
)[actualSize
]) = 0 ;
1674 wxMBConvUTF16 converter
;
1675 size_t noChars
= converter
.MB2WC( NULL
, (const char*)*theText
, 0 ) ;
1676 wxASSERT_MSG( noChars
!= wxCONV_FAILED
, _T("Unable to count the number of characters in this string!") );
1677 ptr
= new wxChar
[noChars
+ 1] ;
1679 noChars
= converter
.MB2WC( ptr
, (const char*)*theText
, noChars
+ 1 ) ;
1680 wxASSERT_MSG( noChars
!= wxCONV_FAILED
, _T("Conversion of string failed!") );
1682 HUnlock( theText
) ;
1685 ptr
[actualSize
] = 0 ;
1686 result
= wxString( ptr
) ;
1690 DisposeHandle( theText
) ;
1694 err
= TXNGetDataEncoded( m_txn
, kTXNStartOffset
, kTXNEndOffset
, &theText
, kTXNTextData
);
1703 actualSize
= GetHandleSize( theText
) ;
1704 if ( actualSize
> 0 )
1707 result
= wxString( *theText
, wxConvLocal
, actualSize
) ;
1708 HUnlock( theText
) ;
1711 DisposeHandle( theText
) ;
1717 wxMacConvertNewlines13To10( &result
) ;
1719 wxMacConvertNewlines10To13( &result
) ;
1725 void wxMacMLTEControl::SetStringValue( const wxString
&str
)
1728 wxMacConvertNewlines10To13( &st
);
1731 wxMacWindowClipper
c( m_peer
);
1734 wxMacEditHelper
help( m_txn
);
1735 SetTXNData( st
, kTXNStartOffset
, kTXNEndOffset
);
1738 TXNSetSelection( m_txn
, 0, 0 );
1739 TXNShowSelection( m_txn
, kTXNShowStart
);
1743 TXNFrameOptions
wxMacMLTEControl::FrameOptionsFromWXStyle( long wxStyle
)
1745 TXNFrameOptions frameOptions
= kTXNDontDrawCaretWhenInactiveMask
;
1747 #if MAC_OS_X_VERSION_MAX_ALLOWED >= MAC_OS_X_VERSION_10_3
1748 frameOptions
|= kTXNDoFontSubstitutionMask
;
1751 if ( ! (wxStyle
& wxTE_NOHIDESEL
) )
1752 frameOptions
|= kTXNDontDrawSelectionWhenInactiveMask
;
1754 if ( wxStyle
& (wxHSCROLL
| wxTE_DONTWRAP
) )
1755 frameOptions
|= kTXNWantHScrollBarMask
;
1757 if ( wxStyle
& wxTE_MULTILINE
)
1759 frameOptions
|= kTXNAlwaysWrapAtViewEdgeMask
;
1761 if ( !(wxStyle
& wxTE_NO_VSCROLL
) )
1763 frameOptions
|= kTXNWantVScrollBarMask
;
1765 // The following code causes drawing problems on 10.4. Perhaps it can be restored for
1766 // older versions of the OS, but I'm not sure it's appropriate to put a grow icon here
1767 // anyways, as AFAIK users can't actually use it to resize the text ctrl.
1768 // if ( frameOptions & kTXNWantHScrollBarMask )
1769 // frameOptions |= kTXNDrawGrowIconMask ;
1774 frameOptions
|= kTXNSingleLineOnlyMask
;
1777 return frameOptions
;
1780 void wxMacMLTEControl::AdjustCreationAttributes( const wxColour
&background
, bool visible
)
1782 TXNControlTag iControlTags
[] =
1784 kTXNDoFontSubstitution
,
1785 kTXNWordWrapStateTag
,
1787 TXNControlData iControlData
[] =
1793 int toptag
= WXSIZEOF( iControlTags
) ;
1795 if ( m_windowStyle
& wxTE_MULTILINE
)
1797 iControlData
[1].uValue
=
1798 (m_windowStyle
& wxTE_DONTWRAP
)
1803 OSStatus err
= TXNSetTXNObjectControls( m_txn
, false, toptag
, iControlTags
, iControlData
) ;
1804 verify_noerr( err
);
1806 // setting the default font:
1807 // under 10.2 this causes a visible caret, therefore we avoid it
1809 if ( UMAGetSystemVersion() >= 0x1030 )
1815 GetThemeFont( kThemeSystemFont
, GetApplicationScript() , fontName
, &fontSize
, &fontStyle
) ;
1817 TXNTypeAttributes typeAttr
[] =
1819 { kTXNQDFontNameAttribute
, kTXNQDFontNameAttributeSize
, { (void*) fontName
} } ,
1820 { kTXNQDFontSizeAttribute
, kTXNFontSizeAttributeSize
, { (void*) (fontSize
<< 16) } } ,
1821 { kTXNQDFontStyleAttribute
, kTXNQDFontStyleAttributeSize
, { (void*) normal
} } ,
1824 err
= TXNSetTypeAttributes(
1825 m_txn
, sizeof(typeAttr
) / sizeof(TXNTypeAttributes
),
1826 typeAttr
, kTXNStartOffset
, kTXNEndOffset
);
1827 verify_noerr( err
);
1830 if ( m_windowStyle
& wxTE_PASSWORD
)
1832 UniChar c
= 0x00A5 ;
1833 err
= TXNEchoMode( m_txn
, c
, 0 , true );
1834 verify_noerr( err
);
1837 TXNBackground tback
;
1838 tback
.bgType
= kTXNBackgroundTypeRGB
;
1839 tback
.bg
.color
= MAC_WXCOLORREF( background
.GetPixel() );
1840 TXNSetBackground( m_txn
, &tback
);
1842 #if MAC_OS_X_VERSION_MAX_ALLOWED >= MAC_OS_X_VERSION_10_4
1843 if ( UMAGetSystemVersion() >= 0x1040 )
1845 TXNCommandEventSupportOptions options
;
1846 if ( TXNGetCommandEventSupport( m_txn
, &options
) == noErr
)
1849 kTXNSupportEditCommandProcessing
1850 | kTXNSupportEditCommandUpdating
1851 | kTXNSupportSpellCheckCommandProcessing
1852 | kTXNSupportSpellCheckCommandUpdating
1853 | kTXNSupportFontCommandProcessing
1854 | kTXNSupportFontCommandUpdating
;
1856 TXNSetCommandEventSupport( m_txn
, options
) ;
1862 void wxMacMLTEControl::SetBackground( const wxBrush
&brush
)
1864 // currently only solid background are supported
1865 TXNBackground tback
;
1867 tback
.bgType
= kTXNBackgroundTypeRGB
;
1868 tback
.bg
.color
= MAC_WXCOLORREF( brush
.GetColour().GetPixel() );
1869 TXNSetBackground( m_txn
, &tback
);
1872 void wxMacMLTEControl::TXNSetAttribute( const wxTextAttr
& style
, long from
, long to
)
1874 TXNTypeAttributes typeAttr
[4] ;
1878 if ( style
.HasFont() )
1880 const wxFont
&font
= style
.GetFont() ;
1882 #if 0 // old version
1883 Str255 fontName
= "\pMonaco" ;
1884 SInt16 fontSize
= 12 ;
1885 Style fontStyle
= normal
;
1886 wxMacStringToPascal( font
.GetFaceName() , fontName
) ;
1887 fontSize
= font
.GetPointSize() ;
1888 if ( font
.GetUnderlined() )
1889 fontStyle
|= underline
;
1890 if ( font
.GetWeight() == wxBOLD
)
1892 if ( font
.GetStyle() == wxITALIC
)
1893 fontStyle
|= italic
;
1895 typeAttr
[attrCount
].tag
= kTXNQDFontNameAttribute
;
1896 typeAttr
[attrCount
].size
= kTXNQDFontNameAttributeSize
;
1897 typeAttr
[attrCount
].data
.dataPtr
= (void*)fontName
;
1900 typeAttr
[attrCount
].tag
= kTXNQDFontSizeAttribute
;
1901 typeAttr
[attrCount
].size
= kTXNFontSizeAttributeSize
;
1902 typeAttr
[attrCount
].data
.dataValue
= (fontSize
<< 16) ;
1905 typeAttr
[attrCount
].tag
= kTXNQDFontStyleAttribute
;
1906 typeAttr
[attrCount
].size
= kTXNQDFontStyleAttributeSize
;
1907 typeAttr
[attrCount
].data
.dataValue
= fontStyle
;
1910 typeAttr
[attrCount
].tag
= kTXNATSUIStyle
;
1911 typeAttr
[attrCount
].size
= kTXNATSUIStyleSize
;
1912 typeAttr
[attrCount
].data
.dataValue
= (UInt32
)font
.MacGetATSUStyle() ;
1917 if ( style
.HasTextColour() )
1919 color
= MAC_WXCOLORREF(style
.GetTextColour().GetPixel()) ;
1921 typeAttr
[attrCount
].tag
= kTXNQDFontColorAttribute
;
1922 typeAttr
[attrCount
].size
= kTXNQDFontColorAttributeSize
;
1923 typeAttr
[attrCount
].data
.dataPtr
= (void*) &color
;
1927 if ( attrCount
> 0 )
1929 verify_noerr( TXNSetTypeAttributes( m_txn
, attrCount
, typeAttr
, from
, to
) );
1930 // unfortunately the relayout is not automatic
1931 TXNRecalcTextLayout( m_txn
);
1935 void wxMacMLTEControl::SetFont( const wxFont
& font
, const wxColour
& foreground
, long windowStyle
)
1937 wxMacEditHelper
help( m_txn
) ;
1938 TXNSetAttribute( wxTextAttr( foreground
, wxNullColour
, font
), kTXNStartOffset
, kTXNEndOffset
) ;
1941 void wxMacMLTEControl::SetStyle( long start
, long end
, const wxTextAttr
& style
)
1943 wxMacEditHelper
help( m_txn
) ;
1944 TXNSetAttribute( style
, start
, end
) ;
1947 void wxMacMLTEControl::Copy()
1949 ClearCurrentScrap();
1951 TXNConvertToPublicScrap();
1954 void wxMacMLTEControl::Cut()
1956 ClearCurrentScrap();
1958 TXNConvertToPublicScrap();
1961 void wxMacMLTEControl::Paste()
1963 TXNConvertFromPublicScrap();
1967 bool wxMacMLTEControl::CanPaste() const
1969 return TXNIsScrapPastable() ;
1972 void wxMacMLTEControl::SetEditable(bool editable
)
1974 TXNControlTag tag
[] = { kTXNIOPrivilegesTag
} ;
1975 TXNControlData data
[] = { { editable
? kTXNReadWrite
: kTXNReadOnly
} } ;
1976 TXNSetTXNObjectControls( m_txn
, false, WXSIZEOF(tag
), tag
, data
) ;
1979 wxTextPos
wxMacMLTEControl::GetLastPosition() const
1981 wxTextPos actualsize
= 0 ;
1984 OSErr err
= TXNGetDataEncoded( m_txn
, kTXNStartOffset
, kTXNEndOffset
, &theText
, kTXNTextData
);
1989 actualsize
= GetHandleSize( theText
) ;
1990 DisposeHandle( theText
) ;
2000 void wxMacMLTEControl::Replace( long from
, long to
, const wxString
&str
)
2002 wxString value
= str
;
2003 wxMacConvertNewlines10To13( &value
) ;
2005 wxMacEditHelper
help( m_txn
) ;
2006 wxMacWindowClipper
c( m_peer
) ;
2008 TXNSetSelection( m_txn
, from
, to
) ;
2010 SetTXNData( value
, kTXNUseCurrentSelection
, kTXNUseCurrentSelection
) ;
2013 void wxMacMLTEControl::Remove( long from
, long to
)
2015 wxMacWindowClipper
c( m_peer
) ;
2016 wxMacEditHelper
help( m_txn
) ;
2017 TXNSetSelection( m_txn
, from
, to
) ;
2021 void wxMacMLTEControl::GetSelection( long* from
, long* to
) const
2023 TXNGetSelection( m_txn
, (TXNOffset
*) from
, (TXNOffset
*) to
) ;
2026 void wxMacMLTEControl::SetSelection( long from
, long to
)
2028 wxMacWindowClipper
c( m_peer
) ;
2030 // change the selection
2031 if ((from
== -1) && (to
== -1))
2032 TXNSelectAll( m_txn
);
2034 TXNSetSelection( m_txn
, from
, to
);
2036 TXNShowSelection( m_txn
, kTXNShowStart
);
2039 void wxMacMLTEControl::WriteText( const wxString
& str
)
2042 wxMacConvertNewlines10To13( &st
) ;
2044 long start
, end
, dummy
;
2046 GetSelection( &start
, &dummy
) ;
2047 wxMacWindowClipper
c( m_peer
) ;
2050 wxMacEditHelper
helper( m_txn
) ;
2051 SetTXNData( st
, kTXNUseCurrentSelection
, kTXNUseCurrentSelection
) ;
2054 GetSelection( &dummy
, &end
) ;
2056 // TODO: SetStyle( start , end , GetDefaultStyle() ) ;
2059 void wxMacMLTEControl::Clear()
2061 wxMacWindowClipper
c( m_peer
) ;
2062 wxMacEditHelper
st( m_txn
) ;
2063 TXNSetSelection( m_txn
, kTXNStartOffset
, kTXNEndOffset
) ;
2067 bool wxMacMLTEControl::CanUndo() const
2069 return TXNCanUndo( m_txn
, NULL
) ;
2072 void wxMacMLTEControl::Undo()
2077 bool wxMacMLTEControl::CanRedo() const
2079 return TXNCanRedo( m_txn
, NULL
) ;
2082 void wxMacMLTEControl::Redo()
2087 int wxMacMLTEControl::GetNumberOfLines() const
2089 ItemCount lines
= 0 ;
2090 TXNGetLineCount( m_txn
, &lines
) ;
2095 long wxMacMLTEControl::XYToPosition(long x
, long y
) const
2100 // TODO: find a better implementation : while we can get the
2101 // line metrics of a certain line, we don't get its starting
2102 // position, so it would probably be rather a binary search
2103 // for the start position
2104 long xpos
= 0, ypos
= 0 ;
2105 int lastHeight
= 0 ;
2108 lastpos
= GetLastPosition() ;
2109 for ( n
= 0 ; n
<= (ItemCount
) lastpos
; ++n
)
2111 if ( y
== ypos
&& x
== xpos
)
2114 TXNOffsetToPoint( m_txn
, n
, &curpt
) ;
2116 if ( curpt
.v
> lastHeight
)
2122 lastHeight
= curpt
.v
;
2131 bool wxMacMLTEControl::PositionToXY( long pos
, long *x
, long *y
) const
2141 lastpos
= GetLastPosition() ;
2142 if ( pos
<= lastpos
)
2144 // TODO: find a better implementation - while we can get the
2145 // line metrics of a certain line, we don't get its starting
2146 // position, so it would probably be rather a binary search
2147 // for the start position
2148 long xpos
= 0, ypos
= 0 ;
2149 int lastHeight
= 0 ;
2152 for ( n
= 0 ; n
<= (ItemCount
) pos
; ++n
)
2154 TXNOffsetToPoint( m_txn
, n
, &curpt
) ;
2156 if ( curpt
.v
> lastHeight
)
2162 lastHeight
= curpt
.v
;
2177 void wxMacMLTEControl::ShowPosition( long pos
)
2179 #if TARGET_RT_MAC_MACHO && defined(AVAILABLE_MAC_OS_X_VERSION_10_2_AND_LATER)
2181 Point current
, desired
;
2182 TXNOffset selstart
, selend
;
2184 TXNGetSelection( m_txn
, &selstart
, &selend
);
2185 TXNOffsetToPoint( m_txn
, selstart
, ¤t
);
2186 TXNOffsetToPoint( m_txn
, pos
, &desired
);
2188 // TODO: use HIPoints for 10.3 and above
2189 if ( (UInt32
)TXNScroll
!= (UInt32
)kUnresolvedCFragSymbolAddress
)
2191 OSErr theErr
= noErr
;
2192 SInt32 dv
= desired
.v
- current
.v
;
2193 SInt32 dh
= desired
.h
- current
.h
;
2194 TXNShowSelection( m_txn
, kTXNShowStart
) ; // NB: should this be kTXNShowStart or kTXNShowEnd ??
2195 theErr
= TXNScroll( m_txn
, kTXNScrollUnitsInPixels
, kTXNScrollUnitsInPixels
, &dv
, &dh
);
2197 // there will be an error returned for classic MLTE implementation when the control is
2198 // invisible, but HITextView works correctly, so we don't assert that one
2199 // wxASSERT_MSG( theErr == noErr, _T("TXNScroll returned an error!") );
2205 void wxMacMLTEControl::SetTXNData( const wxString
& st
, TXNOffset start
, TXNOffset end
)
2208 #if SIZEOF_WCHAR_T == 2
2209 size_t len
= st
.length() ;
2210 TXNSetData( m_txn
, kTXNUnicodeTextData
, (void*)st
.wc_str(), len
* 2, start
, end
);
2212 wxMBConvUTF16 converter
;
2213 ByteCount byteBufferLen
= converter
.WC2MB( NULL
, st
.wc_str(), 0 ) ;
2214 UniChar
*unibuf
= (UniChar
*)malloc( byteBufferLen
) ;
2215 converter
.WC2MB( (char*)unibuf
, st
.wc_str(), byteBufferLen
) ;
2216 TXNSetData( m_txn
, kTXNUnicodeTextData
, (void*)unibuf
, byteBufferLen
, start
, end
) ;
2220 wxCharBuffer text
= st
.mb_str( wxConvLocal
) ;
2221 TXNSetData( m_txn
, kTXNTextData
, (void*)text
.data(), strlen( text
), start
, end
) ;
2225 wxString
wxMacMLTEControl::GetLineText(long lineNo
) const
2229 if ( lineNo
< GetNumberOfLines() )
2232 Fixed lineWidth
, lineHeight
, currentHeight
;
2235 // get the first possible position in the control
2236 TXNOffsetToPoint(m_txn
, 0, &firstPoint
);
2238 // Iterate through the lines until we reach the one we want,
2239 // adding to our current y pixel point position
2242 while (ypos
< lineNo
)
2244 TXNGetLineMetrics(m_txn
, ypos
++, &lineWidth
, &lineHeight
);
2245 currentHeight
+= lineHeight
;
2248 Point thePoint
= { firstPoint
.v
+ (currentHeight
>> 16), firstPoint
.h
+ (0) };
2249 TXNOffset theOffset
;
2250 TXNPointToOffset(m_txn
, thePoint
, &theOffset
);
2252 wxString content
= GetStringValue() ;
2253 Point currentPoint
= thePoint
;
2254 while (thePoint
.v
== currentPoint
.v
&& theOffset
< content
.length())
2256 line
+= content
[theOffset
];
2257 TXNOffsetToPoint(m_txn
, ++theOffset
, ¤tPoint
);
2264 int wxMacMLTEControl::GetLineLength(long lineNo
) const
2268 if ( lineNo
< GetNumberOfLines() )
2271 Fixed lineWidth
, lineHeight
, currentHeight
;
2274 // get the first possible position in the control
2275 TXNOffsetToPoint(m_txn
, 0, &firstPoint
);
2277 // Iterate through the lines until we reach the one we want,
2278 // adding to our current y pixel point position
2281 while (ypos
< lineNo
)
2283 TXNGetLineMetrics(m_txn
, ypos
++, &lineWidth
, &lineHeight
);
2284 currentHeight
+= lineHeight
;
2287 Point thePoint
= { firstPoint
.v
+ (currentHeight
>> 16), firstPoint
.h
+ (0) };
2288 TXNOffset theOffset
;
2289 TXNPointToOffset(m_txn
, thePoint
, &theOffset
);
2291 wxString content
= GetStringValue() ;
2292 Point currentPoint
= thePoint
;
2293 while (thePoint
.v
== currentPoint
.v
&& theOffset
< content
.length())
2296 TXNOffsetToPoint(m_txn
, ++theOffset
, ¤tPoint
);
2303 // ----------------------------------------------------------------------------
2304 // MLTE control implementation (classic part)
2305 // ----------------------------------------------------------------------------
2307 // OS X Notes : We still don't have a full replacement for MLTE, so this implementation
2308 // has to live on. We have different problems coming from outdated implementations on the
2309 // various OS X versions. Most deal with the scrollbars: they are not correctly embedded
2310 // while this can be solved on 10.3 by reassigning them the correct place, on 10.2 there is
2311 // no way out, therefore we are using our own implementation and our own scrollbars ....
2313 #ifdef __WXMAC_OSX__
2315 TXNScrollInfoUPP gTXNScrollInfoProc
= NULL
;
2316 ControlActionUPP gTXNScrollActionProc
= NULL
;
2318 pascal void wxMacMLTEClassicControl::TXNScrollInfoProc(
2319 SInt32 iValue
, SInt32 iMaximumValue
,
2320 TXNScrollBarOrientation iScrollBarOrientation
, SInt32 iRefCon
)
2322 wxMacMLTEClassicControl
* mlte
= (wxMacMLTEClassicControl
*) iRefCon
;
2323 SInt32 value
= wxMax( iValue
, 0 ) ;
2324 SInt32 maximum
= wxMax( iMaximumValue
, 0 ) ;
2326 if ( iScrollBarOrientation
== kTXNHorizontal
)
2328 if ( mlte
->m_sbHorizontal
)
2330 SetControl32BitValue( mlte
->m_sbHorizontal
, value
) ;
2331 SetControl32BitMaximum( mlte
->m_sbHorizontal
, maximum
) ;
2332 mlte
->m_lastHorizontalValue
= value
;
2335 else if ( iScrollBarOrientation
== kTXNVertical
)
2337 if ( mlte
->m_sbVertical
)
2339 SetControl32BitValue( mlte
->m_sbVertical
, value
) ;
2340 SetControl32BitMaximum( mlte
->m_sbVertical
, maximum
) ;
2341 mlte
->m_lastVerticalValue
= value
;
2346 pascal void wxMacMLTEClassicControl::TXNScrollActionProc( ControlRef controlRef
, ControlPartCode partCode
)
2348 wxMacMLTEClassicControl
* mlte
= (wxMacMLTEClassicControl
*) GetControlReference( controlRef
) ;
2352 if ( controlRef
!= mlte
->m_sbVertical
&& controlRef
!= mlte
->m_sbHorizontal
)
2356 bool isHorizontal
= ( controlRef
== mlte
->m_sbHorizontal
) ;
2358 SInt32 minimum
= 0 ;
2359 SInt32 maximum
= GetControl32BitMaximum( controlRef
) ;
2360 SInt32 value
= GetControl32BitValue( controlRef
) ;
2365 case kControlDownButtonPart
:
2369 case kControlUpButtonPart
:
2373 case kControlPageDownPart
:
2374 delta
= GetControlViewSize( controlRef
) ;
2377 case kControlPageUpPart
:
2378 delta
= -GetControlViewSize( controlRef
) ;
2381 case kControlIndicatorPart
:
2382 delta
= value
- (isHorizontal
? mlte
->m_lastHorizontalValue
: mlte
->m_lastVerticalValue
) ;
2391 SInt32 newValue
= value
;
2393 if ( partCode
!= kControlIndicatorPart
)
2395 if ( value
+ delta
< minimum
)
2396 delta
= minimum
- value
;
2397 if ( value
+ delta
> maximum
)
2398 delta
= maximum
- value
;
2400 SetControl32BitValue( controlRef
, value
+ delta
) ;
2401 newValue
= value
+ delta
;
2404 SInt32 verticalDelta
= isHorizontal
? 0 : delta
;
2405 SInt32 horizontalDelta
= isHorizontal
? delta
: 0 ;
2408 mlte
->m_txn
, kTXNScrollUnitsInPixels
, kTXNScrollUnitsInPixels
,
2409 &verticalDelta
, &horizontalDelta
);
2410 verify_noerr( err
);
2413 mlte
->m_lastHorizontalValue
= newValue
;
2415 mlte
->m_lastVerticalValue
= newValue
;
2420 // make correct activations
2421 void wxMacMLTEClassicControl::MacActivatePaneText(bool setActive
)
2423 wxTextCtrl
* textctrl
= (wxTextCtrl
*) GetControlReference(m_controlRef
);
2425 wxMacWindowClipper
clipper( textctrl
) ;
2426 TXNActivate( m_txn
, m_txnFrameID
, setActive
);
2428 ControlRef controlFocus
= 0 ;
2429 GetKeyboardFocus( m_txnWindow
, &controlFocus
) ;
2430 if ( controlFocus
== m_controlRef
)
2431 TXNFocus( m_txn
, setActive
);
2434 void wxMacMLTEClassicControl::MacFocusPaneText(bool setFocus
)
2436 TXNFocus( m_txn
, setFocus
);
2439 // guards against inappropriate redraw (hidden objects drawing onto window)
2441 void wxMacMLTEClassicControl::MacSetObjectVisibility(bool vis
)
2443 ControlRef controlFocus
= 0 ;
2444 GetKeyboardFocus( m_txnWindow
, &controlFocus
) ;
2446 if ( !vis
&& (controlFocus
== m_controlRef
) )
2447 SetKeyboardFocus( m_txnWindow
, m_controlRef
, kControlFocusNoPart
) ;
2449 TXNControlTag iControlTags
[1] = { kTXNVisibilityTag
};
2450 TXNControlData iControlData
[1] = { { (UInt32
)false } };
2452 verify_noerr( TXNGetTXNObjectControls( m_txn
, 1, iControlTags
, iControlData
) ) ;
2454 if ( iControlData
[0].uValue
!= vis
)
2456 iControlData
[0].uValue
= vis
;
2457 verify_noerr( TXNSetTXNObjectControls( m_txn
, false , 1, iControlTags
, iControlData
) ) ;
2460 // currently, we always clip as partial visibility (overlapped) visibility is also a problem,
2461 // if we run into further problems we might set the FrameBounds to an empty rect here
2464 // make sure that the TXNObject is at the right position
2466 void wxMacMLTEClassicControl::MacUpdatePosition()
2468 wxTextCtrl
* textctrl
= (wxTextCtrl
*)GetControlReference( m_controlRef
);
2469 if ( textctrl
== NULL
)
2473 UMAGetControlBoundsInWindowCoords( m_controlRef
, &bounds
);
2475 wxRect visRect
= textctrl
->MacGetClippedClientRect() ;
2476 Rect visBounds
= { visRect
.y
, visRect
.x
, visRect
.y
+ visRect
.height
, visRect
.x
+ visRect
.width
} ;
2479 textctrl
->MacWindowToRootWindow( &x
, &y
) ;
2480 OffsetRect( &visBounds
, x
, y
) ;
2482 if ( !EqualRect( &bounds
, &m_txnControlBounds
) || !EqualRect( &visBounds
, &m_txnVisBounds
) )
2484 m_txnControlBounds
= bounds
;
2485 m_txnVisBounds
= visBounds
;
2486 wxMacWindowClipper
cl( textctrl
) ;
2488 #ifdef __WXMAC_OSX__
2489 if ( m_sbHorizontal
|| m_sbVertical
)
2491 int w
= bounds
.right
- bounds
.left
;
2492 int h
= bounds
.bottom
- bounds
.top
;
2494 if ( m_sbHorizontal
)
2498 sbBounds
.left
= -1 ;
2499 sbBounds
.top
= h
- 14 ;
2500 sbBounds
.right
= w
+ 1 ;
2501 sbBounds
.bottom
= h
+ 1 ;
2503 SetControlBounds( m_sbHorizontal
, &sbBounds
) ;
2504 SetControlViewSize( m_sbHorizontal
, w
) ;
2511 sbBounds
.left
= w
- 14 ;
2513 sbBounds
.right
= w
+ 1 ;
2514 sbBounds
.bottom
= m_sbHorizontal
? h
- 14 : h
+ 1 ;
2516 SetControlBounds( m_sbVertical
, &sbBounds
) ;
2517 SetControlViewSize( m_sbVertical
, h
) ;
2522 TXNLongRect olddestRect
;
2523 TXNGetRectBounds( m_txn
, &oldviewRect
, &olddestRect
, NULL
) ;
2525 Rect viewRect
= { m_txnControlBounds
.top
, m_txnControlBounds
.left
,
2526 m_txnControlBounds
.bottom
- ( m_sbHorizontal
? 14 : 0 ) ,
2527 m_txnControlBounds
.right
- ( m_sbVertical
? 14 : 0 ) } ;
2528 TXNLongRect destRect
= { m_txnControlBounds
.top
, m_txnControlBounds
.left
,
2529 m_txnControlBounds
.bottom
- ( m_sbHorizontal
? 14 : 0 ) ,
2530 m_txnControlBounds
.right
- ( m_sbVertical
? 14 : 0 ) } ;
2532 if ( olddestRect
.right
>= 10000 )
2533 destRect
.right
= destRect
.left
+ 32000 ;
2535 if ( olddestRect
.bottom
>= 0x20000000 )
2536 destRect
.bottom
= destRect
.top
+ 0x40000000 ;
2538 SectRect( &viewRect
, &visBounds
, &viewRect
) ;
2539 TXNSetRectBounds( m_txn
, &viewRect
, &destRect
, true ) ;
2544 m_txnControlBounds
.top
,
2545 m_txnControlBounds
.left
,
2546 m_txnControlBounds
.bottom
- (m_sbHorizontal
? 14 : 0),
2547 m_txnControlBounds
.right
- (m_sbVertical
? 14 : 0),
2553 m_txn
, m_txnControlBounds
.top
, m_txnControlBounds
.left
,
2554 wxMax( m_txnControlBounds
.bottom
, m_txnControlBounds
.top
),
2555 wxMax( m_txnControlBounds
.right
, m_txnControlBounds
.left
), m_txnFrameID
);
2558 // the SetFrameBounds method under Classic sometimes does not correctly scroll a selection into sight after a
2559 // movement, therefore we have to force it
2561 // this problem has been reported in OSX as well, so we use this here once again
2563 TXNLongRect textRect
;
2564 TXNGetRectBounds( m_txn
, NULL
, NULL
, &textRect
) ;
2565 if ( textRect
.left
< m_txnControlBounds
.left
)
2566 TXNShowSelection( m_txn
, kTXNShowStart
) ;
2570 void wxMacMLTEClassicControl::SetRect( Rect
*r
)
2572 wxMacControl::SetRect( r
) ;
2573 MacUpdatePosition() ;
2576 void wxMacMLTEClassicControl::MacControlUserPaneDrawProc(wxInt16 thePart
)
2578 wxTextCtrl
* textctrl
= (wxTextCtrl
*)GetControlReference( m_controlRef
);
2579 if ( textctrl
== NULL
)
2582 if ( textctrl
->MacIsReallyShown() )
2584 wxMacWindowClipper
clipper( textctrl
) ;
2585 TXNDraw( m_txn
, NULL
) ;
2589 wxInt16
wxMacMLTEClassicControl::MacControlUserPaneHitTestProc(wxInt16 x
, wxInt16 y
)
2591 Point where
= { y
, x
} ;
2592 ControlPartCode result
= kControlNoPart
;
2594 wxTextCtrl
* textctrl
= (wxTextCtrl
*) GetControlReference( m_controlRef
);
2595 if ( (textctrl
!= NULL
) && textctrl
->MacIsReallyShown() )
2597 if (PtInRect( where
, &m_txnControlBounds
))
2599 result
= kControlEditTextPart
;
2603 // sometimes we get the coords also in control local coordinates, therefore test again
2605 textctrl
->MacClientToRootWindow( &x
, &y
) ;
2609 if (PtInRect( where
, &m_txnControlBounds
))
2610 result
= kControlEditTextPart
;
2617 wxInt16
wxMacMLTEClassicControl::MacControlUserPaneTrackingProc( wxInt16 x
, wxInt16 y
, void* actionProc
)
2619 ControlPartCode result
= kControlNoPart
;
2621 wxTextCtrl
* textctrl
= (wxTextCtrl
*) GetControlReference( m_controlRef
);
2622 if ( (textctrl
!= NULL
) && textctrl
->MacIsReallyShown() )
2624 Point startPt
= { y
, x
} ;
2626 // for compositing, we must convert these into toplevel window coordinates, because hittesting expects them
2628 textctrl
->MacClientToRootWindow( &x
, &y
) ;
2632 switch (MacControlUserPaneHitTestProc( startPt
.h
, startPt
.v
))
2634 case kControlEditTextPart
:
2636 wxMacWindowClipper
clipper( textctrl
) ;
2639 ConvertEventRefToEventRecord( (EventRef
) wxTheApp
->MacGetCurrentEvent() , &rec
) ;
2640 TXNClick( m_txn
, &rec
);
2652 void wxMacMLTEClassicControl::MacControlUserPaneIdleProc()
2654 wxTextCtrl
* textctrl
= (wxTextCtrl
*)GetControlReference( m_controlRef
);
2655 if ( textctrl
== NULL
)
2658 if (textctrl
->MacIsReallyShown())
2660 if (IsControlActive(m_controlRef
))
2664 wxMacWindowClipper
clipper( textctrl
) ;
2669 if (PtInRect(mousep
, &m_txnControlBounds
))
2671 RgnHandle theRgn
= NewRgn();
2672 RectRgn(theRgn
, &m_txnControlBounds
);
2673 TXNAdjustCursor(m_txn
, theRgn
);
2680 wxInt16
wxMacMLTEClassicControl::MacControlUserPaneKeyDownProc (wxInt16 keyCode
, wxInt16 charCode
, wxInt16 modifiers
)
2682 wxTextCtrl
* textctrl
= (wxTextCtrl
*)GetControlReference( m_controlRef
);
2683 if ( textctrl
== NULL
)
2684 return kControlNoPart
;
2686 wxMacWindowClipper
clipper( textctrl
) ;
2689 memset( &ev
, 0 , sizeof( ev
) ) ;
2691 ev
.modifiers
= modifiers
;
2692 ev
.message
= ((keyCode
<< 8) & keyCodeMask
) | (charCode
& charCodeMask
);
2693 TXNKeyDown( m_txn
, &ev
);
2695 return kControlEntireControl
;
2698 void wxMacMLTEClassicControl::MacControlUserPaneActivateProc(bool activating
)
2700 MacActivatePaneText( activating
);
2703 wxInt16
wxMacMLTEClassicControl::MacControlUserPaneFocusProc(wxInt16 action
)
2705 ControlPartCode focusResult
= kControlFocusNoPart
;
2707 wxTextCtrl
* textctrl
= (wxTextCtrl
*)GetControlReference( m_controlRef
);
2708 if ( textctrl
== NULL
)
2711 wxMacWindowClipper
clipper( textctrl
) ;
2713 ControlRef controlFocus
= NULL
;
2714 GetKeyboardFocus( m_txnWindow
, &controlFocus
) ;
2715 bool wasFocused
= ( controlFocus
== m_controlRef
) ;
2719 case kControlFocusPrevPart
:
2720 case kControlFocusNextPart
:
2721 MacFocusPaneText( !wasFocused
);
2722 focusResult
= (!wasFocused
? (ControlPartCode
) kControlEditTextPart
: (ControlPartCode
) kControlFocusNoPart
);
2725 case kControlFocusNoPart
:
2727 MacFocusPaneText( false );
2728 focusResult
= kControlFocusNoPart
;
2735 void wxMacMLTEClassicControl::MacControlUserPaneBackgroundProc( void *info
)
2739 wxMacMLTEClassicControl::wxMacMLTEClassicControl( wxTextCtrl
*wxPeer
,
2740 const wxString
& str
,
2742 const wxSize
& size
, long style
)
2743 : wxMacMLTEControl( wxPeer
)
2745 m_font
= wxPeer
->GetFont() ;
2746 m_windowStyle
= style
;
2747 Rect bounds
= wxMacGetBoundsForControl( wxPeer
, pos
, size
) ;
2750 kControlSupportsEmbedding
| kControlSupportsFocus
| kControlWantsIdle
2751 | kControlWantsActivate
| kControlHandlesTracking
2752 // | kControlHasSpecialBackground
2753 | kControlGetsFocusOnClick
| kControlSupportsLiveFeedback
;
2755 OSStatus err
= ::CreateUserPaneControl(
2756 MAC_WXHWND(wxPeer
->GetParent()->MacGetTopLevelWindowRef()),
2757 &bounds
, featureSet
, &m_controlRef
);
2758 verify_noerr( err
);
2762 AdjustCreationAttributes( *wxWHITE
, true ) ;
2764 MacSetObjectVisibility( wxPeer
->MacIsReallyShown() ) ;
2768 wxMacConvertNewlines10To13( &st
) ;
2769 wxMacWindowClipper
clipper( m_peer
) ;
2770 SetTXNData( st
, kTXNStartOffset
, kTXNEndOffset
) ;
2771 TXNSetSelection( m_txn
, 0, 0 ) ;
2775 wxMacMLTEClassicControl::~wxMacMLTEClassicControl()
2777 TXNDeleteObject( m_txn
);
2781 void wxMacMLTEClassicControl::VisibilityChanged(bool shown
)
2783 MacSetObjectVisibility( shown
) ;
2784 wxMacControl::VisibilityChanged( shown
) ;
2787 void wxMacMLTEClassicControl::SuperChangedPosition()
2789 MacUpdatePosition() ;
2790 wxMacControl::SuperChangedPosition() ;
2793 #ifdef __WXMAC_OSX__
2795 ControlUserPaneDrawUPP gTPDrawProc
= NULL
;
2796 ControlUserPaneHitTestUPP gTPHitProc
= NULL
;
2797 ControlUserPaneTrackingUPP gTPTrackProc
= NULL
;
2798 ControlUserPaneIdleUPP gTPIdleProc
= NULL
;
2799 ControlUserPaneKeyDownUPP gTPKeyProc
= NULL
;
2800 ControlUserPaneActivateUPP gTPActivateProc
= NULL
;
2801 ControlUserPaneFocusUPP gTPFocusProc
= NULL
;
2803 static pascal void wxMacControlUserPaneDrawProc(ControlRef control
, SInt16 part
)
2805 wxTextCtrl
*textCtrl
= wxDynamicCast( wxFindControlFromMacControl(control
) , wxTextCtrl
) ;
2806 wxMacMLTEClassicControl
* win
= textCtrl
? (wxMacMLTEClassicControl
*)(textCtrl
->GetPeer()) : NULL
;
2808 win
->MacControlUserPaneDrawProc( part
) ;
2811 static pascal ControlPartCode
wxMacControlUserPaneHitTestProc(ControlRef control
, Point where
)
2813 wxTextCtrl
*textCtrl
= wxDynamicCast( wxFindControlFromMacControl(control
) , wxTextCtrl
) ;
2814 wxMacMLTEClassicControl
* win
= textCtrl
? (wxMacMLTEClassicControl
*)(textCtrl
->GetPeer()) : NULL
;
2816 return win
->MacControlUserPaneHitTestProc( where
.h
, where
.v
) ;
2818 return kControlNoPart
;
2821 static pascal ControlPartCode
wxMacControlUserPaneTrackingProc(ControlRef control
, Point startPt
, ControlActionUPP actionProc
)
2823 wxTextCtrl
*textCtrl
= wxDynamicCast( wxFindControlFromMacControl(control
) , wxTextCtrl
) ;
2824 wxMacMLTEClassicControl
* win
= textCtrl
? (wxMacMLTEClassicControl
*)(textCtrl
->GetPeer()) : NULL
;
2826 return win
->MacControlUserPaneTrackingProc( startPt
.h
, startPt
.v
, (void*) actionProc
) ;
2828 return kControlNoPart
;
2831 static pascal void wxMacControlUserPaneIdleProc(ControlRef control
)
2833 wxTextCtrl
*textCtrl
= wxDynamicCast( wxFindControlFromMacControl(control
) , wxTextCtrl
) ;
2834 wxMacMLTEClassicControl
* win
= textCtrl
? (wxMacMLTEClassicControl
*)(textCtrl
->GetPeer()) : NULL
;
2836 win
->MacControlUserPaneIdleProc() ;
2839 static pascal ControlPartCode
wxMacControlUserPaneKeyDownProc(ControlRef control
, SInt16 keyCode
, SInt16 charCode
, SInt16 modifiers
)
2841 wxTextCtrl
*textCtrl
= wxDynamicCast( wxFindControlFromMacControl(control
) , wxTextCtrl
) ;
2842 wxMacMLTEClassicControl
* win
= textCtrl
? (wxMacMLTEClassicControl
*)(textCtrl
->GetPeer()) : NULL
;
2844 return win
->MacControlUserPaneKeyDownProc( keyCode
, charCode
, modifiers
) ;
2846 return kControlNoPart
;
2849 static pascal void wxMacControlUserPaneActivateProc(ControlRef control
, Boolean activating
)
2851 wxTextCtrl
*textCtrl
= wxDynamicCast( wxFindControlFromMacControl(control
) , wxTextCtrl
) ;
2852 wxMacMLTEClassicControl
* win
= textCtrl
? (wxMacMLTEClassicControl
*)(textCtrl
->GetPeer()) : NULL
;
2854 win
->MacControlUserPaneActivateProc( activating
) ;
2857 static pascal ControlPartCode
wxMacControlUserPaneFocusProc(ControlRef control
, ControlFocusPart action
)
2859 wxTextCtrl
*textCtrl
= wxDynamicCast( wxFindControlFromMacControl(control
) , wxTextCtrl
) ;
2860 wxMacMLTEClassicControl
* win
= textCtrl
? (wxMacMLTEClassicControl
*)(textCtrl
->GetPeer()) : NULL
;
2862 return win
->MacControlUserPaneFocusProc( action
) ;
2864 return kControlNoPart
;
2868 static pascal void wxMacControlUserPaneBackgroundProc(ControlRef control
, ControlBackgroundPtr info
)
2870 wxTextCtrl
*textCtrl
= wxDynamicCast( wxFindControlFromMacControl(control
) , wxTextCtrl
) ;
2871 wxMacMLTEClassicControl
* win
= textCtrl
? (wxMacMLTEClassicControl
*)(textCtrl
->GetPeer()) : NULL
;
2873 win
->MacControlUserPaneBackgroundProc(info
) ;
2877 #endif // __WXMAC_OSX__
2879 // TXNRegisterScrollInfoProc
2881 OSStatus
wxMacMLTEClassicControl::DoCreate()
2884 OSStatus err
= noErr
;
2886 // set up our globals
2887 #ifdef __WXMAC_OSX__
2888 if (gTPDrawProc
== NULL
) gTPDrawProc
= NewControlUserPaneDrawUPP(wxMacControlUserPaneDrawProc
);
2889 if (gTPHitProc
== NULL
) gTPHitProc
= NewControlUserPaneHitTestUPP(wxMacControlUserPaneHitTestProc
);
2890 if (gTPTrackProc
== NULL
) gTPTrackProc
= NewControlUserPaneTrackingUPP(wxMacControlUserPaneTrackingProc
);
2891 if (gTPIdleProc
== NULL
) gTPIdleProc
= NewControlUserPaneIdleUPP(wxMacControlUserPaneIdleProc
);
2892 if (gTPKeyProc
== NULL
) gTPKeyProc
= NewControlUserPaneKeyDownUPP(wxMacControlUserPaneKeyDownProc
);
2893 if (gTPActivateProc
== NULL
) gTPActivateProc
= NewControlUserPaneActivateUPP(wxMacControlUserPaneActivateProc
);
2894 if (gTPFocusProc
== NULL
) gTPFocusProc
= NewControlUserPaneFocusUPP(wxMacControlUserPaneFocusProc
);
2896 if (gTXNScrollInfoProc
== NULL
) gTXNScrollInfoProc
= NewTXNScrollInfoUPP(TXNScrollInfoProc
) ;
2897 if (gTXNScrollActionProc
== NULL
) gTXNScrollActionProc
= NewControlActionUPP(TXNScrollActionProc
) ;
2900 // set the initial settings for our private data
2902 m_txnWindow
= GetControlOwner(m_controlRef
);
2903 m_txnPort
= (GrafPtr
) GetWindowPort(m_txnWindow
);
2905 #ifdef __WXMAC_OSX__
2906 // set up the user pane procedures
2907 SetControlData(m_controlRef
, kControlEntireControl
, kControlUserPaneDrawProcTag
, sizeof(gTPDrawProc
), &gTPDrawProc
);
2908 SetControlData(m_controlRef
, kControlEntireControl
, kControlUserPaneHitTestProcTag
, sizeof(gTPHitProc
), &gTPHitProc
);
2909 SetControlData(m_controlRef
, kControlEntireControl
, kControlUserPaneTrackingProcTag
, sizeof(gTPTrackProc
), &gTPTrackProc
);
2910 SetControlData(m_controlRef
, kControlEntireControl
, kControlUserPaneIdleProcTag
, sizeof(gTPIdleProc
), &gTPIdleProc
);
2911 SetControlData(m_controlRef
, kControlEntireControl
, kControlUserPaneKeyDownProcTag
, sizeof(gTPKeyProc
), &gTPKeyProc
);
2912 SetControlData(m_controlRef
, kControlEntireControl
, kControlUserPaneActivateProcTag
, sizeof(gTPActivateProc
), &gTPActivateProc
);
2913 SetControlData(m_controlRef
, kControlEntireControl
, kControlUserPaneFocusProcTag
, sizeof(gTPFocusProc
), &gTPFocusProc
);
2916 // calculate the rectangles used by the control
2917 UMAGetControlBoundsInWindowCoords( m_controlRef
, &bounds
);
2919 m_txnControlBounds
= bounds
;
2920 m_txnVisBounds
= bounds
;
2925 GetGWorld( &origPort
, &origDev
) ;
2926 SetPort( m_txnPort
);
2928 // create the new edit field
2929 TXNFrameOptions frameOptions
= FrameOptionsFromWXStyle( m_windowStyle
);
2931 #ifdef __WXMAC_OSX__
2932 // the scrollbars are not correctly embedded but are inserted at the root:
2933 // this gives us problems as we have erratic redraws even over the structure area
2935 m_sbHorizontal
= 0 ;
2937 m_lastHorizontalValue
= 0 ;
2938 m_lastVerticalValue
= 0 ;
2940 Rect sb
= { 0 , 0 , 0 , 0 } ;
2941 if ( frameOptions
& kTXNWantVScrollBarMask
)
2943 CreateScrollBarControl( m_txnWindow
, &sb
, 0, 0, 100, 1, true, gTXNScrollActionProc
, &m_sbVertical
);
2944 SetControlReference( m_sbVertical
, (SInt32
)this );
2945 SetControlAction( m_sbVertical
, gTXNScrollActionProc
);
2946 ShowControl( m_sbVertical
);
2947 EmbedControl( m_sbVertical
, m_controlRef
);
2948 frameOptions
&= ~kTXNWantVScrollBarMask
;
2951 if ( frameOptions
& kTXNWantHScrollBarMask
)
2953 CreateScrollBarControl( m_txnWindow
, &sb
, 0, 0, 100, 1, true, gTXNScrollActionProc
, &m_sbHorizontal
);
2954 SetControlReference( m_sbHorizontal
, (SInt32
)this );
2955 SetControlAction( m_sbHorizontal
, gTXNScrollActionProc
);
2956 ShowControl( m_sbHorizontal
);
2957 EmbedControl( m_sbHorizontal
, m_controlRef
);
2958 frameOptions
&= ~(kTXNWantHScrollBarMask
| kTXNDrawGrowIconMask
);
2964 NULL
, m_txnWindow
, &bounds
, frameOptions
,
2965 kTXNTextEditStyleFrameType
, kTXNTextensionFile
, kTXNSystemDefaultEncoding
,
2966 &m_txn
, &m_txnFrameID
, NULL
);
2967 verify_noerr( err
);
2970 TXNControlTag iControlTags
[] = { kTXNUseCarbonEvents
};
2971 TXNControlData iControlData
[] = { { (UInt32
)&cInfo
} };
2972 int toptag
= WXSIZEOF( iControlTags
) ;
2973 TXNCarbonEventInfo cInfo
;
2974 cInfo
.useCarbonEvents
= false ;
2977 cInfo
.fDictionary
= NULL
;
2979 verify_noerr( TXNSetTXNObjectControls( m_txn
, false, toptag
, iControlTags
, iControlData
) );
2982 #ifdef __WXMAC_OSX__
2983 TXNRegisterScrollInfoProc( m_txn
, gTXNScrollInfoProc
, (SInt32
)this );
2986 SetGWorld( origPort
, origDev
) ;
2991 // ----------------------------------------------------------------------------
2992 // MLTE control implementation (OSX part)
2993 // ----------------------------------------------------------------------------
2995 #if TARGET_API_MAC_OSX
2997 #if MAC_OS_X_VERSION_MAX_ALLOWED > MAC_OS_X_VERSION_10_2
2999 // tiger multi-line textcontrols with no CR in the entire content
3000 // don't scroll automatically, so we need a hack.
3001 // This attempt only works 'before' the key (ie before CallNextEventHandler)
3002 // is processed, thus the scrolling always occurs one character too late, but
3003 // better than nothing ...
3005 static const EventTypeSpec eventList
[] =
3007 { kEventClassTextInput
, kEventTextInputUnicodeForKeyEvent
} ,
3010 static pascal OSStatus
wxMacUnicodeTextEventHandler( EventHandlerCallRef handler
, EventRef event
, void *data
)
3012 OSStatus result
= eventNotHandledErr
;
3013 wxMacMLTEHIViewControl
* focus
= (wxMacMLTEHIViewControl
*) data
;
3015 switch ( GetEventKind( event
) )
3017 case kEventTextInputUnicodeForKeyEvent
:
3019 if ( UMAGetSystemVersion() >= 0x1040 )
3021 TXNOffset from
, to
;
3022 TXNGetSelection( focus
->GetTXNObject() , &from
, &to
) ;
3024 TXNShowSelection( focus
->GetTXNObject() , kTXNShowStart
);
3026 result
= CallNextEventHandler(handler
,event
);
3036 static pascal OSStatus
wxMacTextControlEventHandler( EventHandlerCallRef handler
, EventRef event
, void *data
)
3038 OSStatus result
= eventNotHandledErr
;
3040 switch ( GetEventClass( event
) )
3042 case kEventClassTextInput
:
3043 result
= wxMacUnicodeTextEventHandler( handler
, event
, data
) ;
3052 DEFINE_ONE_SHOT_HANDLER_GETTER( wxMacTextControlEventHandler
)
3054 wxMacMLTEHIViewControl::wxMacMLTEHIViewControl( wxTextCtrl
*wxPeer
,
3055 const wxString
& str
,
3057 const wxSize
& size
, long style
) : wxMacMLTEControl( wxPeer
)
3059 m_font
= wxPeer
->GetFont() ;
3060 m_windowStyle
= style
;
3061 Rect bounds
= wxMacGetBoundsForControl( wxPeer
, pos
, size
) ;
3063 wxMacConvertNewlines10To13( &st
) ;
3066 { bounds
.left
, bounds
.top
},
3067 { bounds
.right
- bounds
.left
, bounds
.bottom
- bounds
.top
} } ;
3069 m_scrollView
= NULL
;
3070 TXNFrameOptions frameOptions
= FrameOptionsFromWXStyle( style
) ;
3071 if ( frameOptions
& (kTXNWantVScrollBarMask
| kTXNWantHScrollBarMask
) )
3074 (frameOptions
& kTXNWantHScrollBarMask
? kHIScrollViewOptionsHorizScroll
: 0)
3075 | (frameOptions
& kTXNWantVScrollBarMask
? kHIScrollViewOptionsVertScroll
: 0) ,
3078 HIViewSetFrame( m_scrollView
, &hr
);
3079 HIViewSetVisible( m_scrollView
, true );
3083 HITextViewCreate( NULL
, 0, frameOptions
, &m_textView
) ;
3084 m_txn
= HITextViewGetTXNObject( m_textView
) ;
3085 HIViewSetVisible( m_textView
, true ) ;
3088 HIViewAddSubview( m_scrollView
, m_textView
) ;
3089 m_controlRef
= m_scrollView
;
3090 wxPeer
->MacInstallEventHandler( (WXWidget
) m_textView
) ;
3094 HIViewSetFrame( m_textView
, &hr
);
3095 m_controlRef
= m_textView
;
3098 AdjustCreationAttributes( *wxWHITE
, true ) ;
3100 wxMacWindowClipper
c( m_peer
) ;
3101 SetTXNData( st
, kTXNStartOffset
, kTXNEndOffset
) ;
3103 TXNSetSelection( m_txn
, 0, 0 );
3104 TXNShowSelection( m_txn
, kTXNShowStart
);
3106 InstallControlEventHandler( m_textView
, GetwxMacTextControlEventHandlerUPP(),
3107 GetEventTypeCount(eventList
), eventList
, this,
3108 &m_textEventHandlerRef
);
3111 wxMacMLTEHIViewControl::~wxMacMLTEHIViewControl()
3113 ::RemoveEventHandler( m_textEventHandlerRef
) ;
3116 OSStatus
wxMacMLTEHIViewControl::SetFocus( ControlFocusPart focusPart
)
3118 return SetKeyboardFocus( GetControlOwner( m_textView
), m_textView
, focusPart
) ;
3121 bool wxMacMLTEHIViewControl::HasFocus() const
3123 ControlRef control
;
3124 GetKeyboardFocus( GetUserFocusWindow() , &control
) ;
3125 return control
== m_textView
;
3128 void wxMacMLTEHIViewControl::SetBackground( const wxBrush
&brush
)
3130 wxMacMLTEControl::SetBackground( brush
) ;
3133 CGColorSpaceRef rgbSpace
= CGColorSpaceCreateDeviceRGB();
3134 RGBColor col
= MAC_WXCOLORREF(brush
.GetColour().GetPixel()) ;
3136 float component
[4] ;
3137 component
[0] = col
.red
/ 65536.0 ;
3138 component
[1] = col
.green
/ 65536.0 ;
3139 component
[2] = col
.blue
/ 65536.0 ;
3140 component
[3] = 1.0 ; // alpha
3142 CGColorRef color
= CGColorCreate( rgbSpace
, component
);
3143 HITextViewSetBackgroundColor( m_textView
, color
);
3144 CGColorSpaceRelease( rgbSpace
);
3148 #endif // MAC_OS_X_VERSION_MAX_ALLOWED > MAC_OS_X_VERSION_10_2
3153 #endif // wxUSE_TEXTCTRL