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 #include "wx/mac/uma.h"
49 #include "wx/mac/carbon/private/mactext.h"
55 virtual ~wxMacFunctor() {}
57 virtual void* operator()() = 0 ;
59 static void* CallBackProc( void *param
)
61 wxMacFunctor
* f
= (wxMacFunctor
*) param
;
62 void *result
= (*f
)() ;
67 template<typename classtype
, typename param1type
>
69 class wxMacObjectFunctor1
: public wxMacFunctor
71 typedef void (classtype::*function
)( param1type p1
) ;
72 typedef void (classtype::*ref_function
)( const param1type
& p1
) ;
74 wxMacObjectFunctor1( classtype
*obj
, function f
, param1type p1
) :
82 wxMacObjectFunctor1( classtype
*obj
, ref_function f
, param1type p1
) :
90 virtual ~wxMacObjectFunctor1() {}
92 virtual void* operator()()
94 (m_object
->*m_function
)( m_param1
) ;
100 param1type m_param1
;
103 function m_function
;
104 ref_function m_refFunction
;
108 template<typename classtype
, typename param1type
>
109 void* wxMacMPRemoteCall( classtype
*object
, void (classtype::*function
)( param1type p1
) , param1type p1
)
111 wxMacObjectFunctor1
<classtype
, param1type
> params(object
, function
, p1
) ;
113 MPRemoteCall( wxMacFunctor::CallBackProc
, ¶ms
, kMPOwningProcessRemoteContext
) ;
117 template<typename classtype
, typename param1type
>
118 void* wxMacMPRemoteCall( classtype
*object
, void (classtype::*function
)( const param1type
& p1
) , param1type p1
)
120 wxMacObjectFunctor1
<classtype
,param1type
> params(object
, function
, p1
) ;
122 MPRemoteCall( wxMacFunctor::CallBackProc
, ¶ms
, kMPOwningProcessRemoteContext
) ;
126 template<typename classtype
, typename param1type
>
127 void* wxMacMPRemoteGUICall( classtype
*object
, void (classtype::*function
)( param1type p1
) , param1type p1
)
130 void *result
= wxMacMPRemoteCall( object
, function
, p1
) ;
135 template<typename classtype
, typename param1type
>
136 void* wxMacMPRemoteGUICall( classtype
*object
, void (classtype::*function
)( const param1type
& p1
) , param1type p1
)
139 void *result
= wxMacMPRemoteCall( object
, function
, p1
) ;
145 // common parts for implementations based on MLTE
147 class wxMacMLTEControl
: public wxMacTextControl
150 wxMacMLTEControl( wxTextCtrl
*peer
) ;
152 virtual wxString
GetStringValue() const ;
153 virtual void SetStringValue( const wxString
&str
) ;
155 static TXNFrameOptions
FrameOptionsFromWXStyle( long wxStyle
) ;
157 void AdjustCreationAttributes( const wxColour
& background
, bool visible
) ;
159 virtual void SetFont( const wxFont
& font
, const wxColour
& foreground
, long windowStyle
) ;
160 virtual void SetBackground( const wxBrush
&brush
) ;
161 virtual void SetStyle( long start
, long end
, const wxTextAttr
& style
) ;
162 virtual void Copy() ;
164 virtual void Paste() ;
165 virtual bool CanPaste() const ;
166 virtual void SetEditable( bool editable
) ;
167 virtual wxTextPos
GetLastPosition() const ;
168 virtual void Replace( long from
, long to
, const wxString
&str
) ;
169 virtual void Remove( long from
, long to
) ;
170 virtual void GetSelection( long* from
, long* to
) const ;
171 virtual void SetSelection( long from
, long to
) ;
173 virtual void WriteText( const wxString
& str
) ;
175 virtual bool HasOwnContextMenu() const
177 #if MAC_OS_X_VERSION_MAX_ALLOWED >= MAC_OS_X_VERSION_10_4
178 if ( UMAGetSystemVersion() >= 0x1040 )
180 TXNCommandEventSupportOptions options
;
181 TXNGetCommandEventSupport( m_txn
, & options
) ;
182 return options
& kTXNSupportEditCommandProcessing
;
189 virtual void CheckSpelling(bool check
)
191 #if MAC_OS_X_VERSION_MAX_ALLOWED >= MAC_OS_X_VERSION_10_4
192 TXNSetSpellCheckAsYouType( m_txn
, (Boolean
) check
);
195 virtual void Clear() ;
197 virtual bool CanUndo() const ;
198 virtual void Undo() ;
199 virtual bool CanRedo() const;
200 virtual void Redo() ;
201 virtual int GetNumberOfLines() const ;
202 virtual long XYToPosition(long x
, long y
) const ;
203 virtual bool PositionToXY(long pos
, long *x
, long *y
) const ;
204 virtual void ShowPosition( long pos
) ;
205 virtual int GetLineLength(long lineNo
) const ;
206 virtual wxString
GetLineText(long lineNo
) const ;
208 void SetTXNData( const wxString
& st
, TXNOffset start
, TXNOffset end
) ;
209 TXNObject
GetTXNObject() { return m_txn
; }
212 void TXNSetAttribute( const wxTextAttr
& style
, long from
, long to
) ;
217 // implementation available under OSX
219 class wxMacMLTEHIViewControl
: public wxMacMLTEControl
222 wxMacMLTEHIViewControl( wxTextCtrl
*wxPeer
,
225 const wxSize
& size
, long style
) ;
226 virtual ~wxMacMLTEHIViewControl() ;
228 virtual OSStatus
SetFocus( ControlFocusPart focusPart
) ;
229 virtual bool HasFocus() const ;
230 virtual void SetBackground( const wxBrush
&brush
) ;
233 HIViewRef m_scrollView
;
234 HIViewRef m_textView
;
237 // 'classic' MLTE implementation
239 class wxMacMLTEClassicControl
: public wxMacMLTEControl
242 wxMacMLTEClassicControl( wxTextCtrl
*wxPeer
,
245 const wxSize
& size
, long style
) ;
246 virtual ~wxMacMLTEClassicControl() ;
248 virtual void VisibilityChanged(bool shown
) ;
249 virtual void SuperChangedPosition() ;
251 virtual void MacControlUserPaneDrawProc(wxInt16 part
) ;
252 virtual wxInt16
MacControlUserPaneHitTestProc(wxInt16 x
, wxInt16 y
) ;
253 virtual wxInt16
MacControlUserPaneTrackingProc(wxInt16 x
, wxInt16 y
, void* actionProc
) ;
254 virtual void MacControlUserPaneIdleProc() ;
255 virtual wxInt16
MacControlUserPaneKeyDownProc(wxInt16 keyCode
, wxInt16 charCode
, wxInt16 modifiers
) ;
256 virtual void MacControlUserPaneActivateProc(bool activating
) ;
257 virtual wxInt16
MacControlUserPaneFocusProc(wxInt16 action
) ;
258 virtual void MacControlUserPaneBackgroundProc(void* info
) ;
260 virtual bool SetupCursor( const wxPoint
& WXUNUSED(pt
) )
262 MacControlUserPaneIdleProc();
266 virtual void SetRect( Rect
*r
) ;
271 void MacUpdatePosition() ;
272 void MacActivatePaneText(bool setActive
) ;
273 void MacFocusPaneText(bool setFocus
) ;
274 void MacSetObjectVisibility(bool vis
) ;
277 TXNFrameID m_txnFrameID
;
279 WindowRef m_txnWindow
;
280 // bounds of the control as we last did set the txn frames
281 Rect m_txnControlBounds
;
282 Rect m_txnVisBounds
;
284 static pascal void TXNScrollActionProc( ControlRef controlRef
, ControlPartCode partCode
) ;
285 static pascal void TXNScrollInfoProc(
286 SInt32 iValue
, SInt32 iMaximumValue
,
287 TXNScrollBarOrientation iScrollBarOrientation
, SInt32 iRefCon
) ;
289 ControlRef m_sbHorizontal
;
290 SInt32 m_lastHorizontalValue
;
291 ControlRef m_sbVertical
;
292 SInt32 m_lastVerticalValue
;
296 IMPLEMENT_DYNAMIC_CLASS(wxTextCtrl
, wxTextCtrlBase
)
298 BEGIN_EVENT_TABLE(wxTextCtrl
, wxTextCtrlBase
)
299 EVT_ERASE_BACKGROUND( wxTextCtrl::OnEraseBackground
)
300 EVT_DROP_FILES(wxTextCtrl::OnDropFiles
)
301 EVT_CHAR(wxTextCtrl::OnChar
)
302 EVT_MENU(wxID_CUT
, wxTextCtrl::OnCut
)
303 EVT_MENU(wxID_COPY
, wxTextCtrl::OnCopy
)
304 EVT_MENU(wxID_PASTE
, wxTextCtrl::OnPaste
)
305 EVT_MENU(wxID_UNDO
, wxTextCtrl::OnUndo
)
306 EVT_MENU(wxID_REDO
, wxTextCtrl::OnRedo
)
307 EVT_MENU(wxID_CLEAR
, wxTextCtrl::OnDelete
)
308 EVT_MENU(wxID_SELECTALL
, wxTextCtrl::OnSelectAll
)
310 EVT_CONTEXT_MENU(wxTextCtrl::OnContextMenu
)
312 EVT_UPDATE_UI(wxID_CUT
, wxTextCtrl::OnUpdateCut
)
313 EVT_UPDATE_UI(wxID_COPY
, wxTextCtrl::OnUpdateCopy
)
314 EVT_UPDATE_UI(wxID_PASTE
, wxTextCtrl::OnUpdatePaste
)
315 EVT_UPDATE_UI(wxID_UNDO
, wxTextCtrl::OnUpdateUndo
)
316 EVT_UPDATE_UI(wxID_REDO
, wxTextCtrl::OnUpdateRedo
)
317 EVT_UPDATE_UI(wxID_CLEAR
, wxTextCtrl::OnUpdateDelete
)
318 EVT_UPDATE_UI(wxID_SELECTALL
, wxTextCtrl::OnUpdateSelectAll
)
322 void wxTextCtrl::Init()
328 m_privateContextMenu
= NULL
;
329 m_triggerOnSetValue
= true ;
332 wxTextCtrl::~wxTextCtrl()
334 delete m_privateContextMenu
;
337 bool wxTextCtrl::Create( wxWindow
*parent
,
343 const wxValidator
& validator
,
344 const wxString
& name
)
346 m_macIsUserPane
= false ;
349 if ( ! (style
& wxNO_BORDER
) )
350 style
= (style
& ~wxBORDER_MASK
) | wxSUNKEN_BORDER
;
352 if ( !wxTextCtrlBase::Create( parent
, id
, pos
, size
, style
& ~(wxHSCROLL
| wxVSCROLL
), validator
, name
) )
355 if ( m_windowStyle
& wxTE_MULTILINE
)
357 // always turn on this style for multi-line controls
358 m_windowStyle
|= wxTE_PROCESS_ENTER
;
359 style
|= wxTE_PROCESS_ENTER
;
362 CreatePeer( str
, pos
, size
, style
);
364 MacPostControlCreate(pos
, size
) ;
366 // only now the embedding is correct and we can do a positioning update
368 MacSuperChangedPosition() ;
370 if ( m_windowStyle
& wxTE_READONLY
)
371 SetEditable( false ) ;
373 SetCursor( wxCursor( wxCURSOR_IBEAM
) ) ;
378 void wxTextCtrl::CreatePeer(
381 const wxSize
& size
, long style
)
383 bool forceMLTE
= false ;
385 #if wxUSE_SYSTEM_OPTIONS
386 if (wxSystemOptions::HasOption( wxMAC_TEXTCONTROL_USE_MLTE
) && (wxSystemOptions::GetOptionInt( wxMAC_TEXTCONTROL_USE_MLTE
) == 1))
392 if ( UMAGetSystemVersion() >= 0x1050 )
397 if ( m_windowStyle
& wxTE_MULTILINE
)
398 m_peer
= new wxMacMLTEHIViewControl( this , str
, pos
, size
, style
) ;
403 if ( !(m_windowStyle
& wxTE_MULTILINE
) && !forceMLTE
)
405 m_peer
= new wxMacUnicodeTextControl( this , str
, pos
, size
, style
) ;
409 // the horizontal single line scrolling bug that made us keep the classic implementation
411 #if MAC_OS_X_VERSION_MIN_REQUIRED < MAC_OS_X_VERSION_10_5
413 m_peer
= new wxMacMLTEClassicControl( this , str
, pos
, size
, style
) ;
417 void wxTextCtrl::MacSuperChangedPosition()
419 wxWindow::MacSuperChangedPosition() ;
420 GetPeer()->SuperChangedPosition() ;
423 void wxTextCtrl::MacVisibilityChanged()
425 GetPeer()->VisibilityChanged( MacIsReallyShown() ) ;
428 void wxTextCtrl::MacEnabledStateChanged()
432 void wxTextCtrl::MacCheckSpelling(bool check
)
434 GetPeer()->CheckSpelling(check
);
437 wxString
wxTextCtrl::GetValue() const
439 return GetPeer()->GetStringValue() ;
442 void wxTextCtrl::GetSelection(long* from
, long* to
) const
444 GetPeer()->GetSelection( from
, to
) ;
447 void wxTextCtrl::DoSetValue(const wxString
& str
, int flags
)
450 if ( GetValue() == str
)
453 GetPeer()->SetStringValue( str
) ;
455 if ( (flags
& SetValue_SendEvent
) && m_triggerOnSetValue
)
457 SendTextUpdatedEvent();
461 void wxTextCtrl::SetMaxLength(unsigned long len
)
466 bool wxTextCtrl::SetFont( const wxFont
& font
)
468 if ( !wxTextCtrlBase::SetFont( font
) )
471 GetPeer()->SetFont( font
, GetForegroundColour() , GetWindowStyle() ) ;
476 bool wxTextCtrl::SetStyle(long start
, long end
, const wxTextAttr
& style
)
478 GetPeer()->SetStyle( start
, end
, style
) ;
483 bool wxTextCtrl::SetDefaultStyle(const wxTextAttr
& style
)
485 wxTextCtrlBase::SetDefaultStyle( style
) ;
486 SetStyle( kTXNUseCurrentSelection
, kTXNUseCurrentSelection
, GetDefaultStyle() ) ;
491 // Clipboard operations
493 void wxTextCtrl::Copy()
499 void wxTextCtrl::Cut()
505 wxCommandEvent
event( wxEVT_COMMAND_TEXT_UPDATED
, m_windowId
);
506 event
.SetEventObject( this );
507 GetEventHandler()->ProcessEvent( event
);
511 void wxTextCtrl::Paste()
517 // TODO: eventually we should add setting the default style again
519 wxCommandEvent
event( wxEVT_COMMAND_TEXT_UPDATED
, m_windowId
);
520 event
.SetEventObject( this );
521 GetEventHandler()->ProcessEvent( event
);
525 bool wxTextCtrl::CanCopy() const
527 // Can copy if there's a selection
529 GetSelection( &from
, &to
);
534 bool wxTextCtrl::CanCut() const
539 // Can cut if there's a selection
541 GetSelection( &from
, &to
);
546 bool wxTextCtrl::CanPaste() const
551 return GetPeer()->CanPaste() ;
554 void wxTextCtrl::SetEditable(bool editable
)
556 if ( editable
!= m_editable
)
558 m_editable
= editable
;
559 GetPeer()->SetEditable( editable
) ;
563 void wxTextCtrl::SetInsertionPoint(long pos
)
565 SetSelection( pos
, pos
) ;
568 void wxTextCtrl::SetInsertionPointEnd()
570 wxTextPos pos
= GetLastPosition();
571 SetInsertionPoint( pos
);
574 long wxTextCtrl::GetInsertionPoint() const
577 GetSelection( &begin
, &end
) ;
582 wxTextPos
wxTextCtrl::GetLastPosition() const
584 return GetPeer()->GetLastPosition() ;
587 void wxTextCtrl::Replace(long from
, long to
, const wxString
& str
)
589 GetPeer()->Replace( from
, to
, str
) ;
592 void wxTextCtrl::Remove(long from
, long to
)
594 GetPeer()->Remove( from
, to
) ;
597 void wxTextCtrl::SetSelection(long from
, long to
)
599 GetPeer()->SetSelection( from
, to
) ;
602 void wxTextCtrl::WriteText(const wxString
& str
)
604 // TODO: this MPRemoting will be moved into a remoting peer proxy for any command
605 if ( !wxIsMainThread() )
607 // unfortunately CW 8 is not able to correctly deduce the template types,
608 // so we have to instantiate explicitly
609 wxMacMPRemoteGUICall
<wxTextCtrl
,wxString
>( this , &wxTextCtrl::WriteText
, str
) ;
614 GetPeer()->WriteText( str
) ;
617 void wxTextCtrl::AppendText(const wxString
& text
)
619 SetInsertionPointEnd();
623 void wxTextCtrl::Clear()
628 bool wxTextCtrl::IsModified() const
633 bool wxTextCtrl::IsEditable() const
635 return IsEnabled() && m_editable
;
638 bool wxTextCtrl::AcceptsFocus() const
640 // we don't want focus if we can't be edited
641 return /*IsEditable() && */ wxControl::AcceptsFocus();
644 wxSize
wxTextCtrl::DoGetBestSize() const
648 // these are the numbers from the HIG:
649 // we reduce them by the borders first
652 switch ( m_windowVariant
)
654 case wxWINDOW_VARIANT_NORMAL
:
658 case wxWINDOW_VARIANT_SMALL
:
662 case wxWINDOW_VARIANT_MINI
:
671 // as the above numbers have some free space around the text
672 // we get 5 lines like this anyway
673 if ( m_windowStyle
& wxTE_MULTILINE
)
676 if ( !HasFlag(wxNO_BORDER
) )
679 return wxSize(wText
, hText
);
682 // ----------------------------------------------------------------------------
684 // ----------------------------------------------------------------------------
686 void wxTextCtrl::Undo()
692 void wxTextCtrl::Redo()
698 bool wxTextCtrl::CanUndo() const
703 return GetPeer()->CanUndo() ;
706 bool wxTextCtrl::CanRedo() const
711 return GetPeer()->CanRedo() ;
714 void wxTextCtrl::MarkDirty()
719 void wxTextCtrl::DiscardEdits()
724 int wxTextCtrl::GetNumberOfLines() const
726 return GetPeer()->GetNumberOfLines() ;
729 long wxTextCtrl::XYToPosition(long x
, long y
) const
731 return GetPeer()->XYToPosition( x
, y
) ;
734 bool wxTextCtrl::PositionToXY(long pos
, long *x
, long *y
) const
736 return GetPeer()->PositionToXY( pos
, x
, y
) ;
739 void wxTextCtrl::ShowPosition(long pos
)
741 return GetPeer()->ShowPosition(pos
) ;
744 int wxTextCtrl::GetLineLength(long lineNo
) const
746 return GetPeer()->GetLineLength(lineNo
) ;
749 wxString
wxTextCtrl::GetLineText(long lineNo
) const
751 return GetPeer()->GetLineText(lineNo
) ;
754 void wxTextCtrl::Command(wxCommandEvent
& event
)
756 SetValue(event
.GetString());
757 ProcessCommand(event
);
760 void wxTextCtrl::OnDropFiles(wxDropFilesEvent
& event
)
762 // By default, load the first file into the text window.
763 if (event
.GetNumberOfFiles() > 0)
764 LoadFile( event
.GetFiles()[0] );
767 void wxTextCtrl::OnEraseBackground(wxEraseEvent
& event
)
769 // all erasing should be done by the real mac control implementation
770 // while this is true for MLTE under classic, the HITextView is somehow
771 // transparent but background erase is not working correctly, so intercept
772 // things while we can...
776 void wxTextCtrl::OnChar(wxKeyEvent
& event
)
778 int key
= event
.GetKeyCode() ;
779 bool eat_key
= false ;
781 if ( key
== 'a' && event
.MetaDown() )
788 if ( key
== 'c' && event
.MetaDown() )
796 if ( !IsEditable() && key
!= WXK_LEFT
&& key
!= WXK_RIGHT
&& key
!= WXK_DOWN
&& key
!= WXK_UP
&& key
!= WXK_TAB
&&
797 !( key
== WXK_RETURN
&& ( (m_windowStyle
& wxTE_PROCESS_ENTER
) || (m_windowStyle
& wxTE_MULTILINE
) ) )
798 // && key != WXK_PAGEUP && key != WXK_PAGEDOWN && key != WXK_HOME && key != WXK_END
805 // Check if we have reached the max # of chars (if it is set), but still
806 // allow navigation and deletion
807 if ( !IsMultiLine() && m_maxLength
&& GetValue().length() >= m_maxLength
&&
808 key
!= WXK_LEFT
&& key
!= WXK_RIGHT
&& key
!= WXK_TAB
&&
809 key
!= WXK_BACK
&& !( key
== WXK_RETURN
&& (m_windowStyle
& wxTE_PROCESS_ENTER
) )
812 // eat it, we don't want to add more than allowed # of characters
814 // TODO: generate EVT_TEXT_MAXLEN()
818 // assume that any key not processed yet is going to modify the control
821 if ( key
== 'v' && event
.MetaDown() )
829 if ( key
== 'x' && event
.MetaDown() )
840 if (m_windowStyle
& wxTE_PROCESS_ENTER
)
842 wxCommandEvent
event(wxEVT_COMMAND_TEXT_ENTER
, m_windowId
);
843 event
.SetEventObject( this );
844 event
.SetString( GetValue() );
845 if ( GetEventHandler()->ProcessEvent(event
) )
849 if ( !(m_windowStyle
& wxTE_MULTILINE
) )
851 wxTopLevelWindow
*tlw
= wxDynamicCast(wxGetTopLevelParent(this), wxTopLevelWindow
);
852 if ( tlw
&& tlw
->GetDefaultItem() )
854 wxButton
*def
= wxDynamicCast(tlw
->GetDefaultItem(), wxButton
);
855 if ( def
&& def
->IsEnabled() )
857 wxCommandEvent
event(wxEVT_COMMAND_BUTTON_CLICKED
, def
->GetId() );
858 event
.SetEventObject(def
);
865 // this will make wxWidgets eat the ENTER key so that
866 // we actually prevent line wrapping in a single line text control
872 if ( !(m_windowStyle
& wxTE_PROCESS_TAB
))
875 if (!event
.ShiftDown())
876 flags
|= wxNavigationKeyEvent::IsForward
;
877 if (event
.ControlDown())
878 flags
|= wxNavigationKeyEvent::WinChange
;
885 // This is necessary (don't know why);
886 // otherwise the tab will not be inserted.
887 WriteText(wxT("\t"));
898 // perform keystroke handling
902 if ( ( key
>= 0x20 && key
< WXK_START
) ||
903 ( key
>= WXK_NUMPAD0
&& key
<= WXK_DIVIDE
) ||
908 wxCommandEvent
event1(wxEVT_COMMAND_TEXT_UPDATED
, m_windowId
);
909 event1
.SetEventObject( this );
910 wxPostEvent( GetEventHandler(), event1
);
914 // ----------------------------------------------------------------------------
915 // standard handlers for standard edit menu events
916 // ----------------------------------------------------------------------------
918 void wxTextCtrl::OnCut(wxCommandEvent
& WXUNUSED(event
))
923 void wxTextCtrl::OnCopy(wxCommandEvent
& WXUNUSED(event
))
928 void wxTextCtrl::OnPaste(wxCommandEvent
& WXUNUSED(event
))
933 void wxTextCtrl::OnUndo(wxCommandEvent
& WXUNUSED(event
))
938 void wxTextCtrl::OnRedo(wxCommandEvent
& WXUNUSED(event
))
943 void wxTextCtrl::OnDelete(wxCommandEvent
& WXUNUSED(event
))
947 GetSelection( &from
, &to
);
948 if (from
!= -1 && to
!= -1)
952 void wxTextCtrl::OnSelectAll(wxCommandEvent
& WXUNUSED(event
))
954 SetSelection(-1, -1);
957 void wxTextCtrl::OnUpdateCut(wxUpdateUIEvent
& event
)
959 event
.Enable( CanCut() );
962 void wxTextCtrl::OnUpdateCopy(wxUpdateUIEvent
& event
)
964 event
.Enable( CanCopy() );
967 void wxTextCtrl::OnUpdatePaste(wxUpdateUIEvent
& event
)
969 event
.Enable( CanPaste() );
972 void wxTextCtrl::OnUpdateUndo(wxUpdateUIEvent
& event
)
974 event
.Enable( CanUndo() );
977 void wxTextCtrl::OnUpdateRedo(wxUpdateUIEvent
& event
)
979 event
.Enable( CanRedo() );
982 void wxTextCtrl::OnUpdateDelete(wxUpdateUIEvent
& event
)
986 GetSelection( &from
, &to
);
987 event
.Enable( from
!= -1 && to
!= -1 && from
!= to
&& IsEditable() ) ;
990 void wxTextCtrl::OnUpdateSelectAll(wxUpdateUIEvent
& event
)
992 event
.Enable(GetLastPosition() > 0);
995 // CS: Context Menus only work with MLTE implementations or non-multiline HIViews at the moment
997 void wxTextCtrl::OnContextMenu(wxContextMenuEvent
& event
)
999 if ( GetPeer()->HasOwnContextMenu() )
1005 if (m_privateContextMenu
== NULL
)
1007 m_privateContextMenu
= new wxMenu
;
1008 m_privateContextMenu
->Append(wxID_UNDO
, _("&Undo"));
1009 m_privateContextMenu
->Append(wxID_REDO
, _("&Redo"));
1010 m_privateContextMenu
->AppendSeparator();
1011 m_privateContextMenu
->Append(wxID_CUT
, _("Cu&t"));
1012 m_privateContextMenu
->Append(wxID_COPY
, _("&Copy"));
1013 m_privateContextMenu
->Append(wxID_PASTE
, _("&Paste"));
1014 m_privateContextMenu
->Append(wxID_CLEAR
, _("&Delete"));
1015 m_privateContextMenu
->AppendSeparator();
1016 m_privateContextMenu
->Append(wxID_SELECTALL
, _("Select &All"));
1019 if (m_privateContextMenu
!= NULL
)
1020 PopupMenu(m_privateContextMenu
);
1023 bool wxTextCtrl::MacSetupCursor( const wxPoint
& pt
)
1025 if ( !GetPeer()->SetupCursor( pt
) )
1026 return wxWindow::MacSetupCursor( pt
) ;
1031 #if !TARGET_API_MAC_OSX
1033 // user pane implementation
1035 void wxTextCtrl::MacControlUserPaneDrawProc(wxInt16 part
)
1037 GetPeer()->MacControlUserPaneDrawProc( part
) ;
1040 wxInt16
wxTextCtrl::MacControlUserPaneHitTestProc(wxInt16 x
, wxInt16 y
)
1042 return GetPeer()->MacControlUserPaneHitTestProc( x
, y
) ;
1045 wxInt16
wxTextCtrl::MacControlUserPaneTrackingProc(wxInt16 x
, wxInt16 y
, void* actionProc
)
1047 return GetPeer()->MacControlUserPaneTrackingProc( x
, y
, actionProc
) ;
1050 void wxTextCtrl::MacControlUserPaneIdleProc()
1052 GetPeer()->MacControlUserPaneIdleProc( ) ;
1055 wxInt16
wxTextCtrl::MacControlUserPaneKeyDownProc(wxInt16 keyCode
, wxInt16 charCode
, wxInt16 modifiers
)
1057 return GetPeer()->MacControlUserPaneKeyDownProc( keyCode
, charCode
, modifiers
) ;
1060 void wxTextCtrl::MacControlUserPaneActivateProc(bool activating
)
1062 GetPeer()->MacControlUserPaneActivateProc( activating
) ;
1065 wxInt16
wxTextCtrl::MacControlUserPaneFocusProc(wxInt16 action
)
1067 return GetPeer()->MacControlUserPaneFocusProc( action
) ;
1070 void wxTextCtrl::MacControlUserPaneBackgroundProc(void* info
)
1072 GetPeer()->MacControlUserPaneBackgroundProc( info
) ;
1077 // ----------------------------------------------------------------------------
1078 // implementation base class
1079 // ----------------------------------------------------------------------------
1081 wxMacTextControl::wxMacTextControl(wxTextCtrl
* peer
) :
1082 wxMacControl( peer
)
1086 wxMacTextControl::~wxMacTextControl()
1090 void wxMacTextControl::SetStyle(long WXUNUSED(start
),
1092 const wxTextAttr
& WXUNUSED(style
))
1096 void wxMacTextControl::Copy()
1100 void wxMacTextControl::Cut()
1104 void wxMacTextControl::Paste()
1108 bool wxMacTextControl::CanPaste() const
1113 void wxMacTextControl::SetEditable(bool WXUNUSED(editable
))
1117 wxTextPos
wxMacTextControl::GetLastPosition() const
1119 return GetStringValue().length() ;
1122 void wxMacTextControl::Replace( long from
, long to
, const wxString
&val
)
1124 SetSelection( from
, to
) ;
1128 void wxMacTextControl::Remove( long from
, long to
)
1130 SetSelection( from
, to
) ;
1131 WriteText( wxEmptyString
) ;
1134 void wxMacTextControl::Clear()
1136 SetStringValue( wxEmptyString
) ;
1139 bool wxMacTextControl::CanUndo() const
1144 void wxMacTextControl::Undo()
1148 bool wxMacTextControl::CanRedo() const
1153 void wxMacTextControl::Redo()
1157 long wxMacTextControl::XYToPosition(long WXUNUSED(x
), long WXUNUSED(y
)) const
1162 bool wxMacTextControl::PositionToXY(long WXUNUSED(pos
),
1164 long *WXUNUSED(y
)) const
1169 void wxMacTextControl::ShowPosition( long WXUNUSED(pos
) )
1173 int wxMacTextControl::GetNumberOfLines() const
1175 ItemCount lines
= 0 ;
1176 wxString content
= GetStringValue() ;
1179 for (size_t i
= 0; i
< content
.length() ; i
++)
1181 if (content
[i
] == '\r')
1188 wxString
wxMacTextControl::GetLineText(long lineNo
) const
1190 // TODO: change this if possible to reflect real lines
1191 wxString content
= GetStringValue() ;
1195 for (size_t i
= 0; i
< content
.length() ; i
++)
1197 if (count
== lineNo
)
1199 // Add chars in line then
1202 for (size_t j
= i
; j
< content
.length(); j
++)
1204 if (content
[j
] == '\n')
1213 if (content
[i
] == '\n')
1217 return wxEmptyString
;
1220 int wxMacTextControl::GetLineLength(long lineNo
) const
1222 // TODO: change this if possible to reflect real lines
1223 wxString content
= GetStringValue() ;
1227 for (size_t i
= 0; i
< content
.length() ; i
++)
1229 if (count
== lineNo
)
1231 // Count chars in line then
1233 for (size_t j
= i
; j
< content
.length(); j
++)
1236 if (content
[j
] == '\n')
1243 if (content
[i
] == '\n')
1250 // ----------------------------------------------------------------------------
1251 // standard unicode control implementation
1252 // ----------------------------------------------------------------------------
1254 #if TARGET_API_MAC_OSX
1256 // the current unicode textcontrol implementation has a bug : only if the control
1257 // is currently having the focus, the selection can be retrieved by the corresponding
1258 // data tag. So we have a mirroring using a member variable
1259 // TODO : build event table using virtual member functions for wxMacControl
1261 static const EventTypeSpec unicodeTextControlEventList
[] =
1263 { kEventClassControl
, kEventControlSetFocusPart
} ,
1266 static pascal OSStatus
wxMacUnicodeTextControlControlEventHandler( EventHandlerCallRef handler
, EventRef event
, void *data
)
1268 OSStatus result
= eventNotHandledErr
;
1269 wxMacUnicodeTextControl
* focus
= (wxMacUnicodeTextControl
*) data
;
1270 wxMacCarbonEvent
cEvent( event
) ;
1272 switch ( GetEventKind( event
) )
1274 case kEventControlSetFocusPart
:
1276 ControlPartCode controlPart
= cEvent
.GetParameter
<ControlPartCode
>(kEventParamControlPart
, typeControlPartCode
);
1277 if ( controlPart
== kControlFocusNoPart
)
1279 // about to loose focus -> store selection to field
1280 focus
->GetData
<ControlEditTextSelectionRec
>( 0, kControlEditTextSelectionTag
, &focus
->m_selection
);
1282 result
= CallNextEventHandler(handler
,event
) ;
1283 if ( controlPart
!= kControlFocusNoPart
)
1285 // about to gain focus -> set selection from field
1286 focus
->SetData
<ControlEditTextSelectionRec
>( 0, kControlEditTextSelectionTag
, &focus
->m_selection
);
1297 static pascal OSStatus
wxMacUnicodeTextControlEventHandler( EventHandlerCallRef handler
, EventRef event
, void *data
)
1299 OSStatus result
= eventNotHandledErr
;
1301 switch ( GetEventClass( event
) )
1303 case kEventClassControl
:
1304 result
= wxMacUnicodeTextControlControlEventHandler( handler
, event
, data
) ;
1313 DEFINE_ONE_SHOT_HANDLER_GETTER( wxMacUnicodeTextControlEventHandler
)
1315 wxMacUnicodeTextControl::wxMacUnicodeTextControl( wxTextCtrl
*wxPeer
) : wxMacTextControl( wxPeer
)
1319 wxMacUnicodeTextControl::wxMacUnicodeTextControl( wxTextCtrl
*wxPeer
,
1320 const wxString
& str
,
1322 const wxSize
& size
, long style
)
1323 : wxMacTextControl( wxPeer
)
1325 Create( wxPeer
, str
, pos
, size
, style
);
1328 bool wxMacUnicodeTextControl::Create( wxTextCtrl
*wxPeer
,
1329 const wxString
& str
,
1331 const wxSize
& size
, long style
)
1333 m_font
= wxPeer
->GetFont() ;
1334 m_windowStyle
= style
;
1335 m_selection
.selStart
= m_selection
.selEnd
= 0;
1336 Rect bounds
= wxMacGetBoundsForControl( wxPeer
, pos
, size
) ;
1338 wxMacConvertNewlines10To13( &st
) ;
1339 wxMacCFStringHolder
cf(st
, m_font
.GetEncoding()) ;
1340 CFStringRef cfr
= cf
;
1342 m_valueTag
= kControlEditTextCFStringTag
;
1343 CreateControl( wxPeer
, &bounds
, cfr
);
1345 if ( !(m_windowStyle
& wxTE_MULTILINE
) )
1346 SetData
<Boolean
>( kControlEditTextPart
, kControlEditTextSingleLineTag
, true ) ;
1348 InstallControlEventHandler( m_controlRef
, GetwxMacUnicodeTextControlEventHandlerUPP(),
1349 GetEventTypeCount(unicodeTextControlEventList
), unicodeTextControlEventList
, this,
1355 wxMacUnicodeTextControl::~wxMacUnicodeTextControl()
1359 void wxMacUnicodeTextControl::VisibilityChanged(bool shown
)
1361 if ( !(m_windowStyle
& wxTE_MULTILINE
) && shown
)
1363 // work around a refresh issue insofar as not always the entire content is shown,
1364 // even if this would be possible
1365 ControlEditTextSelectionRec sel
;
1366 CFStringRef value
= NULL
;
1368 verify_noerr( GetData
<ControlEditTextSelectionRec
>( 0, kControlEditTextSelectionTag
, &sel
) );
1369 verify_noerr( GetData
<CFStringRef
>( 0, m_valueTag
, &value
) );
1370 verify_noerr( SetData
<CFStringRef
>( 0, m_valueTag
, &value
) );
1371 verify_noerr( SetData
<ControlEditTextSelectionRec
>( 0, kControlEditTextSelectionTag
, &sel
) );
1373 CFRelease( value
) ;
1377 wxString
wxMacUnicodeTextControl::GetStringValue() const
1380 CFStringRef value
= GetData
<CFStringRef
>(0, m_valueTag
) ;
1383 wxMacCFStringHolder
cf(value
) ;
1384 result
= cf
.AsString() ;
1388 wxMacConvertNewlines13To10( &result
) ;
1390 wxMacConvertNewlines10To13( &result
) ;
1396 void wxMacUnicodeTextControl::SetStringValue( const wxString
&str
)
1399 wxMacConvertNewlines10To13( &st
) ;
1400 wxMacCFStringHolder
cf( st
, m_font
.GetEncoding() ) ;
1401 verify_noerr( SetData
<CFStringRef
>( 0, m_valueTag
, cf
) ) ;
1404 void wxMacUnicodeTextControl::CreateControl( wxTextCtrl
* peer
, const Rect
* bounds
, CFStringRef cfr
)
1406 Boolean isPassword
= ( m_windowStyle
& wxTE_PASSWORD
) != 0 ;
1409 m_valueTag
= kControlEditTextPasswordCFStringTag
;
1411 OSStatus err
= CreateEditUnicodeTextControl(
1412 MAC_WXHWND(peer
->MacGetTopLevelWindowRef()), bounds
, cfr
,
1413 isPassword
, NULL
, &m_controlRef
) ;
1414 verify_noerr( err
);
1417 void wxMacUnicodeTextControl::Copy()
1419 SendHICommand( kHICommandCopy
) ;
1422 void wxMacUnicodeTextControl::Cut()
1424 SendHICommand( kHICommandCut
) ;
1427 void wxMacUnicodeTextControl::Paste()
1429 SendHICommand( kHICommandPaste
) ;
1432 bool wxMacUnicodeTextControl::CanPaste() const
1437 void wxMacUnicodeTextControl::SetEditable(bool WXUNUSED(editable
))
1439 #if 0 // leads to problem because text cannot be selected anymore
1440 SetData
<Boolean
>( kControlEditTextPart
, kControlEditTextLockedTag
, (Boolean
) !editable
) ;
1444 void wxMacUnicodeTextControl::GetSelection( long* from
, long* to
) const
1446 ControlEditTextSelectionRec sel
;
1448 verify_noerr( GetData
<ControlEditTextSelectionRec
>( 0, kControlEditTextSelectionTag
, &sel
) ) ;
1453 *from
= sel
.selStart
;
1458 void wxMacUnicodeTextControl::SetSelection( long from
, long to
)
1460 ControlEditTextSelectionRec sel
;
1462 int textLength
= 0 ;
1463 CFStringRef value
= GetData
<CFStringRef
>(0, m_valueTag
) ;
1466 wxMacCFStringHolder
cf(value
) ;
1467 textLength
= cf
.AsString().length() ;
1470 if ((from
== -1) && (to
== -1))
1477 from
= wxMin(textLength
,wxMax(from
,0)) ;
1478 to
= wxMax(0,wxMin(textLength
,to
)) ;
1481 sel
.selStart
= from
;
1484 SetData
<ControlEditTextSelectionRec
>( 0, kControlEditTextSelectionTag
, &sel
) ;
1489 void wxMacUnicodeTextControl::WriteText( const wxString
& str
)
1492 wxMacConvertNewlines10To13( &st
) ;
1496 wxMacCFStringHolder
cf(st
, m_font
.GetEncoding() ) ;
1497 CFStringRef value
= cf
;
1498 SetData
<CFStringRef
>( 0, kControlEditTextInsertCFStringRefTag
, &value
);
1502 wxString val
= GetStringValue() ;
1504 GetSelection( &start
, &end
) ;
1505 val
.Remove( start
, end
- start
) ;
1506 val
.insert( start
, str
) ;
1507 SetStringValue( val
) ;
1508 SetSelection( start
+ str
.length() , start
+ str
.length() ) ;
1514 // ----------------------------------------------------------------------------
1515 // MLTE control implementation (common part)
1516 // ----------------------------------------------------------------------------
1518 // if MTLE is read only, no changes at all are allowed, not even from
1519 // procedural API, in order to allow changes via API all the same we must undo
1520 // the readonly status while we are executing, this class helps to do so
1522 class wxMacEditHelper
1525 wxMacEditHelper( TXNObject txn
)
1527 TXNControlTag tag
[] = { kTXNIOPrivilegesTag
} ;
1529 TXNGetTXNObjectControls( m_txn
, 1 , tag
, m_data
) ;
1530 if ( m_data
[0].uValue
== kTXNReadOnly
)
1532 TXNControlData data
[] = { { kTXNReadWrite
} } ;
1533 TXNSetTXNObjectControls( m_txn
, false , 1 , tag
, data
) ;
1539 TXNControlTag tag
[] = { kTXNIOPrivilegesTag
} ;
1540 if ( m_data
[0].uValue
== kTXNReadOnly
)
1541 TXNSetTXNObjectControls( m_txn
, false , 1 , tag
, m_data
) ;
1546 TXNControlData m_data
[1] ;
1549 wxMacMLTEControl::wxMacMLTEControl( wxTextCtrl
*peer
)
1550 : wxMacTextControl( peer
)
1552 SetNeedsFocusRect( true ) ;
1555 wxString
wxMacMLTEControl::GetStringValue() const
1559 Size actualSize
= 0;
1564 err
= TXNGetDataEncoded( m_txn
, kTXNStartOffset
, kTXNEndOffset
, &theText
, kTXNUnicodeTextData
);
1573 actualSize
= GetHandleSize( theText
) / sizeof(UniChar
) ;
1574 if ( actualSize
> 0 )
1576 wxChar
*ptr
= NULL
;
1578 #if SIZEOF_WCHAR_T == 2
1579 ptr
= new wxChar
[actualSize
+ 1] ;
1580 wxStrncpy( ptr
, (wxChar
*)(*theText
) , actualSize
) ;
1582 SetHandleSize( theText
, (actualSize
+ 1) * sizeof(UniChar
) ) ;
1584 (((UniChar
*)*theText
)[actualSize
]) = 0 ;
1585 wxMBConvUTF16 converter
;
1586 size_t noChars
= converter
.MB2WC( NULL
, (const char*)*theText
, 0 ) ;
1587 wxASSERT_MSG( noChars
!= wxCONV_FAILED
, _T("Unable to count the number of characters in this string!") );
1588 ptr
= new wxChar
[noChars
+ 1] ;
1590 noChars
= converter
.MB2WC( ptr
, (const char*)*theText
, noChars
+ 1 ) ;
1591 wxASSERT_MSG( noChars
!= wxCONV_FAILED
, _T("Conversion of string failed!") );
1593 HUnlock( theText
) ;
1596 ptr
[actualSize
] = 0 ;
1597 result
= wxString( ptr
) ;
1601 DisposeHandle( theText
) ;
1605 err
= TXNGetDataEncoded( m_txn
, kTXNStartOffset
, kTXNEndOffset
, &theText
, kTXNTextData
);
1614 actualSize
= GetHandleSize( theText
) ;
1615 if ( actualSize
> 0 )
1618 result
= wxString( *theText
, wxConvLocal
, actualSize
) ;
1619 HUnlock( theText
) ;
1622 DisposeHandle( theText
) ;
1628 wxMacConvertNewlines13To10( &result
) ;
1630 wxMacConvertNewlines10To13( &result
) ;
1636 void wxMacMLTEControl::SetStringValue( const wxString
&str
)
1639 wxMacConvertNewlines10To13( &st
);
1643 wxMacWindowClipper
c( m_peer
) ;
1647 wxMacEditHelper
help( m_txn
);
1648 SetTXNData( st
, kTXNStartOffset
, kTXNEndOffset
);
1651 TXNSetSelection( m_txn
, 0, 0 );
1652 TXNShowSelection( m_txn
, kTXNShowStart
);
1656 TXNFrameOptions
wxMacMLTEControl::FrameOptionsFromWXStyle( long wxStyle
)
1658 TXNFrameOptions frameOptions
= kTXNDontDrawCaretWhenInactiveMask
;
1660 frameOptions
|= kTXNDoFontSubstitutionMask
;
1662 if ( ! (wxStyle
& wxTE_NOHIDESEL
) )
1663 frameOptions
|= kTXNDontDrawSelectionWhenInactiveMask
;
1665 if ( wxStyle
& (wxHSCROLL
| wxTE_DONTWRAP
) )
1666 frameOptions
|= kTXNWantHScrollBarMask
;
1668 if ( wxStyle
& wxTE_MULTILINE
)
1670 frameOptions
|= kTXNAlwaysWrapAtViewEdgeMask
;
1672 if ( !(wxStyle
& wxTE_NO_VSCROLL
) )
1674 frameOptions
|= kTXNWantVScrollBarMask
;
1676 // The following code causes drawing problems on 10.4. Perhaps it can be restored for
1677 // older versions of the OS, but I'm not sure it's appropriate to put a grow icon here
1678 // anyways, as AFAIK users can't actually use it to resize the text ctrl.
1679 // if ( frameOptions & kTXNWantHScrollBarMask )
1680 // frameOptions |= kTXNDrawGrowIconMask ;
1685 frameOptions
|= kTXNSingleLineOnlyMask
;
1688 return frameOptions
;
1691 void wxMacMLTEControl::AdjustCreationAttributes(const wxColour
&background
,
1692 bool WXUNUSED(visible
))
1694 TXNControlTag iControlTags
[] =
1696 kTXNDoFontSubstitution
,
1697 kTXNWordWrapStateTag
,
1699 TXNControlData iControlData
[] =
1705 int toptag
= WXSIZEOF( iControlTags
) ;
1707 if ( m_windowStyle
& wxTE_MULTILINE
)
1709 iControlData
[1].uValue
=
1710 (m_windowStyle
& wxTE_DONTWRAP
)
1715 OSStatus err
= TXNSetTXNObjectControls( m_txn
, false, toptag
, iControlTags
, iControlData
) ;
1716 verify_noerr( err
);
1718 // setting the default font:
1719 // under 10.2 this causes a visible caret, therefore we avoid it
1725 GetThemeFont( kThemeSystemFont
, GetApplicationScript() , fontName
, &fontSize
, &fontStyle
) ;
1727 TXNTypeAttributes typeAttr
[] =
1729 { kTXNQDFontNameAttribute
, kTXNQDFontNameAttributeSize
, { (void*) fontName
} } ,
1730 { kTXNQDFontSizeAttribute
, kTXNFontSizeAttributeSize
, { (void*) (fontSize
<< 16) } } ,
1731 { kTXNQDFontStyleAttribute
, kTXNQDFontStyleAttributeSize
, { (void*) normal
} } ,
1734 err
= TXNSetTypeAttributes(
1735 m_txn
, sizeof(typeAttr
) / sizeof(TXNTypeAttributes
),
1736 typeAttr
, kTXNStartOffset
, kTXNEndOffset
);
1737 verify_noerr( err
);
1739 if ( m_windowStyle
& wxTE_PASSWORD
)
1741 UniChar c
= 0x00A5 ;
1742 err
= TXNEchoMode( m_txn
, c
, 0 , true );
1743 verify_noerr( err
);
1746 TXNBackground tback
;
1747 tback
.bgType
= kTXNBackgroundTypeRGB
;
1748 tback
.bg
.color
= MAC_WXCOLORREF( background
.GetPixel() );
1749 TXNSetBackground( m_txn
, &tback
);
1751 #if MAC_OS_X_VERSION_MAX_ALLOWED >= MAC_OS_X_VERSION_10_4
1752 if ( UMAGetSystemVersion() >= 0x1040 )
1754 TXNCommandEventSupportOptions options
;
1755 if ( TXNGetCommandEventSupport( m_txn
, &options
) == noErr
)
1758 kTXNSupportEditCommandProcessing
1759 | kTXNSupportEditCommandUpdating
1760 | kTXNSupportFontCommandProcessing
1761 | kTXNSupportFontCommandUpdating
;
1763 // only spell check when not read-only
1764 // use system options for the default
1765 bool checkSpelling
= false ;
1766 if ( !(m_windowStyle
& wxTE_READONLY
) )
1768 #if wxUSE_SYSTEM_OPTIONS
1769 if ( wxSystemOptions::HasOption( wxMAC_TEXTCONTROL_USE_SPELL_CHECKER
) && (wxSystemOptions::GetOptionInt( wxMAC_TEXTCONTROL_USE_SPELL_CHECKER
) == 1) )
1771 checkSpelling
= true ;
1776 if ( checkSpelling
)
1778 kTXNSupportSpellCheckCommandProcessing
1779 | kTXNSupportSpellCheckCommandUpdating
;
1781 TXNSetCommandEventSupport( m_txn
, options
) ;
1787 void wxMacMLTEControl::SetBackground( const wxBrush
&brush
)
1789 // currently only solid background are supported
1790 TXNBackground tback
;
1792 tback
.bgType
= kTXNBackgroundTypeRGB
;
1793 tback
.bg
.color
= MAC_WXCOLORREF( brush
.GetColour().GetPixel() );
1794 TXNSetBackground( m_txn
, &tback
);
1797 static inline int wxConvertToTXN(int x
)
1799 return wx_static_cast(int, x
/ 254.0 * 72 + 0.5);
1802 void wxMacMLTEControl::TXNSetAttribute( const wxTextAttr
& style
, long from
, long to
)
1804 TXNTypeAttributes typeAttr
[4] ;
1806 size_t typeAttrCount
= 0 ;
1809 TXNControlTag controlTags
[4];
1810 TXNControlData controlData
[4];
1811 size_t controlAttrCount
= 0;
1813 TXNTab
* tabs
= NULL
;
1815 bool relayout
= false;
1817 if ( style
.HasFont() )
1819 wxASSERT( typeAttrCount
< WXSIZEOF(typeAttr
) );
1820 const wxFont
&font
= style
.GetFont() ;
1821 typeAttr
[typeAttrCount
].tag
= kTXNATSUIStyle
;
1822 typeAttr
[typeAttrCount
].size
= kTXNATSUIStyleSize
;
1823 typeAttr
[typeAttrCount
].data
.dataPtr
= font
.MacGetATSUStyle() ;
1827 if ( style
.HasTextColour() )
1829 wxASSERT( typeAttrCount
< WXSIZEOF(typeAttr
) );
1830 color
= MAC_WXCOLORREF(style
.GetTextColour().GetPixel()) ;
1832 typeAttr
[typeAttrCount
].tag
= kTXNQDFontColorAttribute
;
1833 typeAttr
[typeAttrCount
].size
= kTXNQDFontColorAttributeSize
;
1834 typeAttr
[typeAttrCount
].data
.dataPtr
= (void*) &color
;
1838 if ( style
.HasAlignment() )
1840 wxASSERT( controlAttrCount
< WXSIZEOF(controlTags
) );
1843 switch ( style
.GetAlignment() )
1845 case wxTEXT_ALIGNMENT_LEFT
:
1846 align
= kTXNFlushLeft
;
1848 case wxTEXT_ALIGNMENT_CENTRE
:
1851 case wxTEXT_ALIGNMENT_RIGHT
:
1852 align
= kTXNFlushRight
;
1854 case wxTEXT_ALIGNMENT_JUSTIFIED
:
1855 align
= kTXNFullJust
;
1858 case wxTEXT_ALIGNMENT_DEFAULT
:
1859 align
= kTXNFlushDefault
;
1863 controlTags
[controlAttrCount
] = kTXNJustificationTag
;
1864 controlData
[controlAttrCount
].sValue
= align
;
1865 controlAttrCount
++ ;
1868 if ( style
.HasLeftIndent() || style
.HasRightIndent() )
1870 wxASSERT( controlAttrCount
< WXSIZEOF(controlTags
) );
1871 controlTags
[controlAttrCount
] = kTXNMarginsTag
;
1872 controlData
[controlAttrCount
].marginsPtr
= &margins
;
1873 verify_noerr( TXNGetTXNObjectControls (m_txn
, 1 ,
1874 &controlTags
[controlAttrCount
], &controlData
[controlAttrCount
]) );
1875 if ( style
.HasLeftIndent() )
1877 margins
.leftMargin
= wxConvertToTXN(style
.GetLeftIndent());
1879 if ( style
.HasRightIndent() )
1881 margins
.rightMargin
= wxConvertToTXN(style
.GetRightIndent());
1883 controlAttrCount
++ ;
1886 if ( style
.HasTabs() )
1888 const wxArrayInt
& tabarray
= style
.GetTabs();
1889 // unfortunately Mac only applies a tab distance, not individually different tabs
1890 controlTags
[controlAttrCount
] = kTXNTabSettingsTag
;
1891 if ( tabarray
.size() > 0 )
1892 controlData
[controlAttrCount
].tabValue
.value
= wxConvertToTXN(tabarray
[0]);
1894 controlData
[controlAttrCount
].tabValue
.value
= 72 ;
1896 controlData
[controlAttrCount
].tabValue
.tabType
= kTXNLeftTab
;
1897 controlAttrCount
++ ;
1900 // unfortunately the relayout is not automatic
1901 if ( controlAttrCount
> 0 )
1903 verify_noerr( TXNSetTXNObjectControls (m_txn
, false /* don't clear all */, controlAttrCount
,
1904 controlTags
, controlData
) );
1908 if ( typeAttrCount
> 0 )
1910 verify_noerr( TXNSetTypeAttributes( m_txn
, typeAttrCount
, typeAttr
, from
, to
) );
1921 TXNRecalcTextLayout( m_txn
);
1925 void wxMacMLTEControl::SetFont(const wxFont
& font
,
1926 const wxColour
& foreground
,
1927 long WXUNUSED(windowStyle
))
1929 wxMacEditHelper
help( m_txn
) ;
1930 TXNSetAttribute( wxTextAttr( foreground
, wxNullColour
, font
), kTXNStartOffset
, kTXNEndOffset
) ;
1933 void wxMacMLTEControl::SetStyle( long start
, long end
, const wxTextAttr
& style
)
1935 wxMacEditHelper
help( m_txn
) ;
1936 TXNSetAttribute( style
, start
, end
) ;
1939 void wxMacMLTEControl::Copy()
1944 void wxMacMLTEControl::Cut()
1949 void wxMacMLTEControl::Paste()
1954 bool wxMacMLTEControl::CanPaste() const
1956 return TXNIsScrapPastable() ;
1959 void wxMacMLTEControl::SetEditable(bool editable
)
1961 TXNControlTag tag
[] = { kTXNIOPrivilegesTag
} ;
1962 TXNControlData data
[] = { { editable
? kTXNReadWrite
: kTXNReadOnly
} } ;
1963 TXNSetTXNObjectControls( m_txn
, false, WXSIZEOF(tag
), tag
, data
) ;
1966 wxTextPos
wxMacMLTEControl::GetLastPosition() const
1968 wxTextPos actualsize
= 0 ;
1971 OSErr err
= TXNGetDataEncoded( m_txn
, kTXNStartOffset
, kTXNEndOffset
, &theText
, kTXNTextData
);
1976 actualsize
= GetHandleSize( theText
) ;
1977 DisposeHandle( theText
) ;
1987 void wxMacMLTEControl::Replace( long from
, long to
, const wxString
&str
)
1989 wxString value
= str
;
1990 wxMacConvertNewlines10To13( &value
) ;
1992 wxMacEditHelper
help( m_txn
) ;
1994 wxMacWindowClipper
c( m_peer
) ;
1997 TXNSetSelection( m_txn
, from
, to
) ;
1999 SetTXNData( value
, kTXNUseCurrentSelection
, kTXNUseCurrentSelection
) ;
2002 void wxMacMLTEControl::Remove( long from
, long to
)
2005 wxMacWindowClipper
c( m_peer
) ;
2007 wxMacEditHelper
help( m_txn
) ;
2008 TXNSetSelection( m_txn
, from
, to
) ;
2012 void wxMacMLTEControl::GetSelection( long* from
, long* to
) const
2015 TXNGetSelection( m_txn
, &f
, &t
) ;
2020 void wxMacMLTEControl::SetSelection( long from
, long to
)
2023 wxMacWindowClipper
c( m_peer
) ;
2026 // change the selection
2027 if ((from
== -1) && (to
== -1))
2028 TXNSelectAll( m_txn
);
2030 TXNSetSelection( m_txn
, from
, to
);
2032 TXNShowSelection( m_txn
, kTXNShowStart
);
2035 void wxMacMLTEControl::WriteText( const wxString
& str
)
2038 wxMacConvertNewlines10To13( &st
) ;
2040 long start
, end
, dummy
;
2042 GetSelection( &start
, &dummy
) ;
2044 wxMacWindowClipper
c( m_peer
) ;
2048 wxMacEditHelper
helper( m_txn
) ;
2049 SetTXNData( st
, kTXNUseCurrentSelection
, kTXNUseCurrentSelection
) ;
2052 GetSelection( &dummy
, &end
) ;
2054 // TODO: SetStyle( start , end , GetDefaultStyle() ) ;
2057 void wxMacMLTEControl::Clear()
2060 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 Point current
, desired
;
2180 TXNOffset selstart
, selend
;
2182 TXNGetSelection( m_txn
, &selstart
, &selend
);
2183 TXNOffsetToPoint( m_txn
, selstart
, ¤t
);
2184 TXNOffsetToPoint( m_txn
, pos
, &desired
);
2186 // TODO: use HIPoints for 10.3 and above
2188 OSErr theErr
= noErr
;
2189 long dv
= desired
.v
- current
.v
;
2190 long dh
= desired
.h
- current
.h
;
2191 TXNShowSelection( m_txn
, kTXNShowStart
) ; // NB: should this be kTXNShowStart or kTXNShowEnd ??
2192 theErr
= TXNScroll( m_txn
, kTXNScrollUnitsInPixels
, kTXNScrollUnitsInPixels
, &dv
, &dh
);
2194 // there will be an error returned for classic MLTE implementation when the control is
2195 // invisible, but HITextView works correctly, so we don't assert that one
2196 // wxASSERT_MSG( theErr == noErr, _T("TXNScroll returned an error!") );
2199 void wxMacMLTEControl::SetTXNData( const wxString
& st
, TXNOffset start
, TXNOffset end
)
2202 #if SIZEOF_WCHAR_T == 2
2203 size_t len
= st
.length() ;
2204 TXNSetData( m_txn
, kTXNUnicodeTextData
, (void*)st
.wc_str(), len
* 2, start
, end
);
2206 wxMBConvUTF16 converter
;
2207 ByteCount byteBufferLen
= converter
.WC2MB( NULL
, st
.wc_str(), 0 ) ;
2208 UniChar
*unibuf
= (UniChar
*)malloc( byteBufferLen
) ;
2209 converter
.WC2MB( (char*)unibuf
, st
.wc_str(), byteBufferLen
) ;
2210 TXNSetData( m_txn
, kTXNUnicodeTextData
, (void*)unibuf
, byteBufferLen
, start
, end
) ;
2214 wxCharBuffer text
= st
.mb_str( wxConvLocal
) ;
2215 TXNSetData( m_txn
, kTXNTextData
, (void*)text
.data(), strlen( text
), start
, end
) ;
2219 wxString
wxMacMLTEControl::GetLineText(long lineNo
) const
2223 if ( lineNo
< GetNumberOfLines() )
2226 Fixed lineWidth
, lineHeight
, currentHeight
;
2229 // get the first possible position in the control
2230 TXNOffsetToPoint(m_txn
, 0, &firstPoint
);
2232 // Iterate through the lines until we reach the one we want,
2233 // adding to our current y pixel point position
2236 while (ypos
< lineNo
)
2238 TXNGetLineMetrics(m_txn
, ypos
++, &lineWidth
, &lineHeight
);
2239 currentHeight
+= lineHeight
;
2242 Point thePoint
= { firstPoint
.v
+ (currentHeight
>> 16), firstPoint
.h
+ (0) };
2243 TXNOffset theOffset
;
2244 TXNPointToOffset(m_txn
, thePoint
, &theOffset
);
2246 wxString content
= GetStringValue() ;
2247 Point currentPoint
= thePoint
;
2248 while (thePoint
.v
== currentPoint
.v
&& theOffset
< content
.length())
2250 line
+= content
[theOffset
];
2251 TXNOffsetToPoint(m_txn
, ++theOffset
, ¤tPoint
);
2258 int wxMacMLTEControl::GetLineLength(long lineNo
) const
2262 if ( lineNo
< GetNumberOfLines() )
2265 Fixed lineWidth
, lineHeight
, currentHeight
;
2268 // get the first possible position in the control
2269 TXNOffsetToPoint(m_txn
, 0, &firstPoint
);
2271 // Iterate through the lines until we reach the one we want,
2272 // adding to our current y pixel point position
2275 while (ypos
< lineNo
)
2277 TXNGetLineMetrics(m_txn
, ypos
++, &lineWidth
, &lineHeight
);
2278 currentHeight
+= lineHeight
;
2281 Point thePoint
= { firstPoint
.v
+ (currentHeight
>> 16), firstPoint
.h
+ (0) };
2282 TXNOffset theOffset
;
2283 TXNPointToOffset(m_txn
, thePoint
, &theOffset
);
2285 wxString content
= GetStringValue() ;
2286 Point currentPoint
= thePoint
;
2287 while (thePoint
.v
== currentPoint
.v
&& theOffset
< content
.length())
2290 TXNOffsetToPoint(m_txn
, ++theOffset
, ¤tPoint
);
2297 #if MAC_OS_X_VERSION_MIN_REQUIRED < MAC_OS_X_VERSION_10_5
2299 // ----------------------------------------------------------------------------
2300 // MLTE control implementation (classic part)
2301 // ----------------------------------------------------------------------------
2303 // OS X Notes : We still don't have a full replacement for MLTE, so this implementation
2304 // has to live on. We have different problems coming from outdated implementations on the
2305 // various OS X versions. Most deal with the scrollbars: they are not correctly embedded
2306 // while this can be solved on 10.3 by reassigning them the correct place, on 10.2 there is
2307 // no way out, therefore we are using our own implementation and our own scrollbars ....
2309 TXNScrollInfoUPP gTXNScrollInfoProc
= NULL
;
2310 ControlActionUPP gTXNScrollActionProc
= NULL
;
2312 pascal void wxMacMLTEClassicControl::TXNScrollInfoProc(
2313 SInt32 iValue
, SInt32 iMaximumValue
,
2314 TXNScrollBarOrientation iScrollBarOrientation
, SInt32 iRefCon
)
2316 wxMacMLTEClassicControl
* mlte
= (wxMacMLTEClassicControl
*) iRefCon
;
2317 SInt32 value
= wxMax( iValue
, 0 ) ;
2318 SInt32 maximum
= wxMax( iMaximumValue
, 0 ) ;
2320 if ( iScrollBarOrientation
== kTXNHorizontal
)
2322 if ( mlte
->m_sbHorizontal
)
2324 SetControl32BitValue( mlte
->m_sbHorizontal
, value
) ;
2325 SetControl32BitMaximum( mlte
->m_sbHorizontal
, maximum
) ;
2326 mlte
->m_lastHorizontalValue
= value
;
2329 else if ( iScrollBarOrientation
== kTXNVertical
)
2331 if ( mlte
->m_sbVertical
)
2333 SetControl32BitValue( mlte
->m_sbVertical
, value
) ;
2334 SetControl32BitMaximum( mlte
->m_sbVertical
, maximum
) ;
2335 mlte
->m_lastVerticalValue
= value
;
2340 pascal void wxMacMLTEClassicControl::TXNScrollActionProc( ControlRef controlRef
, ControlPartCode partCode
)
2342 wxMacMLTEClassicControl
* mlte
= (wxMacMLTEClassicControl
*) GetControlReference( controlRef
) ;
2346 if ( controlRef
!= mlte
->m_sbVertical
&& controlRef
!= mlte
->m_sbHorizontal
)
2350 bool isHorizontal
= ( controlRef
== mlte
->m_sbHorizontal
) ;
2352 SInt32 minimum
= 0 ;
2353 SInt32 maximum
= GetControl32BitMaximum( controlRef
) ;
2354 SInt32 value
= GetControl32BitValue( controlRef
) ;
2359 case kControlDownButtonPart
:
2363 case kControlUpButtonPart
:
2367 case kControlPageDownPart
:
2368 delta
= GetControlViewSize( controlRef
) ;
2371 case kControlPageUpPart
:
2372 delta
= -GetControlViewSize( controlRef
) ;
2375 case kControlIndicatorPart
:
2376 delta
= value
- (isHorizontal
? mlte
->m_lastHorizontalValue
: mlte
->m_lastVerticalValue
) ;
2385 SInt32 newValue
= value
;
2387 if ( partCode
!= kControlIndicatorPart
)
2389 if ( value
+ delta
< minimum
)
2390 delta
= minimum
- value
;
2391 if ( value
+ delta
> maximum
)
2392 delta
= maximum
- value
;
2394 SetControl32BitValue( controlRef
, value
+ delta
) ;
2395 newValue
= value
+ delta
;
2398 SInt32 verticalDelta
= isHorizontal
? 0 : delta
;
2399 SInt32 horizontalDelta
= isHorizontal
? delta
: 0 ;
2402 mlte
->m_txn
, kTXNScrollUnitsInPixels
, kTXNScrollUnitsInPixels
,
2403 &verticalDelta
, &horizontalDelta
);
2404 verify_noerr( err
);
2407 mlte
->m_lastHorizontalValue
= newValue
;
2409 mlte
->m_lastVerticalValue
= newValue
;
2413 // make correct activations
2414 void wxMacMLTEClassicControl::MacActivatePaneText(bool setActive
)
2416 wxTextCtrl
* textctrl
= (wxTextCtrl
*) GetControlReference(m_controlRef
);
2418 wxMacWindowClipper
clipper( textctrl
) ;
2419 TXNActivate( m_txn
, m_txnFrameID
, setActive
);
2421 ControlRef controlFocus
= 0 ;
2422 GetKeyboardFocus( m_txnWindow
, &controlFocus
) ;
2423 if ( controlFocus
== m_controlRef
)
2424 TXNFocus( m_txn
, setActive
);
2427 void wxMacMLTEClassicControl::MacFocusPaneText(bool setFocus
)
2429 TXNFocus( m_txn
, setFocus
);
2432 // guards against inappropriate redraw (hidden objects drawing onto window)
2434 void wxMacMLTEClassicControl::MacSetObjectVisibility(bool vis
)
2436 ControlRef controlFocus
= 0 ;
2437 GetKeyboardFocus( m_txnWindow
, &controlFocus
) ;
2439 if ( !vis
&& (controlFocus
== m_controlRef
) )
2440 SetKeyboardFocus( m_txnWindow
, m_controlRef
, kControlFocusNoPart
) ;
2442 TXNControlTag iControlTags
[1] = { kTXNVisibilityTag
};
2443 TXNControlData iControlData
[1] = { { (UInt32
)false } };
2445 verify_noerr( TXNGetTXNObjectControls( m_txn
, 1, iControlTags
, iControlData
) ) ;
2447 if ( iControlData
[0].uValue
!= vis
)
2449 iControlData
[0].uValue
= vis
;
2450 verify_noerr( TXNSetTXNObjectControls( m_txn
, false , 1, iControlTags
, iControlData
) ) ;
2453 // currently, we always clip as partial visibility (overlapped) visibility is also a problem,
2454 // if we run into further problems we might set the FrameBounds to an empty rect here
2457 // make sure that the TXNObject is at the right position
2459 void wxMacMLTEClassicControl::MacUpdatePosition()
2461 wxTextCtrl
* textctrl
= (wxTextCtrl
*)GetControlReference( m_controlRef
);
2462 if ( textctrl
== NULL
)
2466 UMAGetControlBoundsInWindowCoords( m_controlRef
, &bounds
);
2468 wxRect visRect
= textctrl
->MacGetClippedClientRect() ;
2469 Rect visBounds
= { visRect
.y
, visRect
.x
, visRect
.y
+ visRect
.height
, visRect
.x
+ visRect
.width
} ;
2472 textctrl
->MacWindowToRootWindow( &x
, &y
) ;
2473 OffsetRect( &visBounds
, x
, y
) ;
2475 if ( !EqualRect( &bounds
, &m_txnControlBounds
) || !EqualRect( &visBounds
, &m_txnVisBounds
) )
2477 m_txnControlBounds
= bounds
;
2478 m_txnVisBounds
= visBounds
;
2479 wxMacWindowClipper
cl( textctrl
) ;
2481 if ( m_sbHorizontal
|| m_sbVertical
)
2483 int w
= bounds
.right
- bounds
.left
;
2484 int h
= bounds
.bottom
- bounds
.top
;
2486 if ( m_sbHorizontal
)
2490 sbBounds
.left
= -1 ;
2491 sbBounds
.top
= h
- 14 ;
2492 sbBounds
.right
= w
+ 1 ;
2493 sbBounds
.bottom
= h
+ 1 ;
2495 SetControlBounds( m_sbHorizontal
, &sbBounds
) ;
2496 SetControlViewSize( m_sbHorizontal
, w
) ;
2503 sbBounds
.left
= w
- 14 ;
2505 sbBounds
.right
= w
+ 1 ;
2506 sbBounds
.bottom
= m_sbHorizontal
? h
- 14 : h
+ 1 ;
2508 SetControlBounds( m_sbVertical
, &sbBounds
) ;
2509 SetControlViewSize( m_sbVertical
, h
) ;
2514 TXNLongRect olddestRect
;
2515 TXNGetRectBounds( m_txn
, &oldviewRect
, &olddestRect
, NULL
) ;
2517 Rect viewRect
= { m_txnControlBounds
.top
, m_txnControlBounds
.left
,
2518 m_txnControlBounds
.bottom
- ( m_sbHorizontal
? 14 : 0 ) ,
2519 m_txnControlBounds
.right
- ( m_sbVertical
? 14 : 0 ) } ;
2520 TXNLongRect destRect
= { m_txnControlBounds
.top
, m_txnControlBounds
.left
,
2521 m_txnControlBounds
.bottom
- ( m_sbHorizontal
? 14 : 0 ) ,
2522 m_txnControlBounds
.right
- ( m_sbVertical
? 14 : 0 ) } ;
2524 if ( olddestRect
.right
>= 10000 )
2525 destRect
.right
= destRect
.left
+ 32000 ;
2527 if ( olddestRect
.bottom
>= 0x20000000 )
2528 destRect
.bottom
= destRect
.top
+ 0x40000000 ;
2530 SectRect( &viewRect
, &visBounds
, &viewRect
) ;
2531 TXNSetRectBounds( m_txn
, &viewRect
, &destRect
, true ) ;
2536 m_txnControlBounds
.top
,
2537 m_txnControlBounds
.left
,
2538 m_txnControlBounds
.bottom
- (m_sbHorizontal
? 14 : 0),
2539 m_txnControlBounds
.right
- (m_sbVertical
? 14 : 0),
2543 // the SetFrameBounds method under Classic sometimes does not correctly scroll a selection into sight after a
2544 // movement, therefore we have to force it
2546 // this problem has been reported in OSX as well, so we use this here once again
2548 TXNLongRect textRect
;
2549 TXNGetRectBounds( m_txn
, NULL
, NULL
, &textRect
) ;
2550 if ( textRect
.left
< m_txnControlBounds
.left
)
2551 TXNShowSelection( m_txn
, kTXNShowStart
) ;
2555 void wxMacMLTEClassicControl::SetRect( Rect
*r
)
2557 wxMacControl::SetRect( r
) ;
2558 MacUpdatePosition() ;
2561 void wxMacMLTEClassicControl::MacControlUserPaneDrawProc(wxInt16
WXUNUSED(thePart
))
2563 wxTextCtrl
* textctrl
= (wxTextCtrl
*)GetControlReference( m_controlRef
);
2564 if ( textctrl
== NULL
)
2567 if ( textctrl
->MacIsReallyShown() )
2569 wxMacWindowClipper
clipper( textctrl
) ;
2570 TXNDraw( m_txn
, NULL
) ;
2574 wxInt16
wxMacMLTEClassicControl::MacControlUserPaneHitTestProc(wxInt16 x
, wxInt16 y
)
2576 Point where
= { y
, x
} ;
2577 ControlPartCode result
= kControlNoPart
;
2579 wxTextCtrl
* textctrl
= (wxTextCtrl
*) GetControlReference( m_controlRef
);
2580 if ( (textctrl
!= NULL
) && textctrl
->MacIsReallyShown() )
2582 if (PtInRect( where
, &m_txnControlBounds
))
2584 result
= kControlEditTextPart
;
2588 // sometimes we get the coords also in control local coordinates, therefore test again
2590 textctrl
->MacClientToRootWindow( &x
, &y
) ;
2594 if (PtInRect( where
, &m_txnControlBounds
))
2595 result
= kControlEditTextPart
;
2602 wxInt16
wxMacMLTEClassicControl::MacControlUserPaneTrackingProc( wxInt16 x
, wxInt16 y
, void* WXUNUSED(actionProc
) )
2604 ControlPartCode result
= kControlNoPart
;
2606 wxTextCtrl
* textctrl
= (wxTextCtrl
*) GetControlReference( m_controlRef
);
2607 if ( (textctrl
!= NULL
) && textctrl
->MacIsReallyShown() )
2609 Point startPt
= { y
, x
} ;
2611 // for compositing, we must convert these into toplevel window coordinates, because hittesting expects them
2613 textctrl
->MacClientToRootWindow( &x
, &y
) ;
2617 switch (MacControlUserPaneHitTestProc( startPt
.h
, startPt
.v
))
2619 case kControlEditTextPart
:
2621 wxMacWindowClipper
clipper( textctrl
) ;
2624 ConvertEventRefToEventRecord( (EventRef
) wxTheApp
->MacGetCurrentEvent() , &rec
) ;
2625 TXNClick( m_txn
, &rec
);
2637 void wxMacMLTEClassicControl::MacControlUserPaneIdleProc()
2639 wxTextCtrl
* textctrl
= (wxTextCtrl
*)GetControlReference( m_controlRef
);
2640 if ( textctrl
== NULL
)
2643 if (textctrl
->MacIsReallyShown())
2645 if (IsControlActive(m_controlRef
))
2649 wxMacWindowClipper
clipper( textctrl
) ;
2654 if (PtInRect(mousep
, &m_txnControlBounds
))
2656 RgnHandle theRgn
= NewRgn();
2657 RectRgn(theRgn
, &m_txnControlBounds
);
2658 TXNAdjustCursor(m_txn
, theRgn
);
2665 wxInt16
wxMacMLTEClassicControl::MacControlUserPaneKeyDownProc (wxInt16 keyCode
, wxInt16 charCode
, wxInt16 modifiers
)
2667 wxTextCtrl
* textctrl
= (wxTextCtrl
*)GetControlReference( m_controlRef
);
2668 if ( textctrl
== NULL
)
2669 return kControlNoPart
;
2671 wxMacWindowClipper
clipper( textctrl
) ;
2674 memset( &ev
, 0 , sizeof( ev
) ) ;
2676 ev
.modifiers
= modifiers
;
2677 ev
.message
= ((keyCode
<< 8) & keyCodeMask
) | (charCode
& charCodeMask
);
2678 TXNKeyDown( m_txn
, &ev
);
2680 return kControlEntireControl
;
2683 void wxMacMLTEClassicControl::MacControlUserPaneActivateProc(bool activating
)
2685 MacActivatePaneText( activating
);
2688 wxInt16
wxMacMLTEClassicControl::MacControlUserPaneFocusProc(wxInt16 action
)
2690 ControlPartCode focusResult
= kControlFocusNoPart
;
2692 wxTextCtrl
* textctrl
= (wxTextCtrl
*)GetControlReference( m_controlRef
);
2693 if ( textctrl
== NULL
)
2696 wxMacWindowClipper
clipper( textctrl
) ;
2698 ControlRef controlFocus
= NULL
;
2699 GetKeyboardFocus( m_txnWindow
, &controlFocus
) ;
2700 bool wasFocused
= ( controlFocus
== m_controlRef
) ;
2704 case kControlFocusPrevPart
:
2705 case kControlFocusNextPart
:
2706 MacFocusPaneText( !wasFocused
);
2707 focusResult
= (!wasFocused
? (ControlPartCode
) kControlEditTextPart
: (ControlPartCode
) kControlFocusNoPart
);
2710 case kControlFocusNoPart
:
2712 MacFocusPaneText( false );
2713 focusResult
= kControlFocusNoPart
;
2720 void wxMacMLTEClassicControl::MacControlUserPaneBackgroundProc( void *WXUNUSED(info
) )
2724 wxMacMLTEClassicControl::wxMacMLTEClassicControl( wxTextCtrl
*wxPeer
,
2725 const wxString
& str
,
2727 const wxSize
& size
, long style
)
2728 : wxMacMLTEControl( wxPeer
)
2730 m_font
= wxPeer
->GetFont() ;
2731 m_windowStyle
= style
;
2732 Rect bounds
= wxMacGetBoundsForControl( wxPeer
, pos
, size
) ;
2735 kControlSupportsEmbedding
| kControlSupportsFocus
| kControlWantsIdle
2736 | kControlWantsActivate
| kControlHandlesTracking
2737 // | kControlHasSpecialBackground
2738 | kControlGetsFocusOnClick
| kControlSupportsLiveFeedback
;
2740 OSStatus err
= ::CreateUserPaneControl(
2741 MAC_WXHWND(wxPeer
->GetParent()->MacGetTopLevelWindowRef()),
2742 &bounds
, featureSet
, &m_controlRef
);
2743 verify_noerr( err
);
2747 AdjustCreationAttributes( *wxWHITE
, true ) ;
2749 MacSetObjectVisibility( wxPeer
->MacIsReallyShown() ) ;
2753 wxMacConvertNewlines10To13( &st
) ;
2754 wxMacWindowClipper
clipper( m_peer
) ;
2755 SetTXNData( st
, kTXNStartOffset
, kTXNEndOffset
) ;
2756 TXNSetSelection( m_txn
, 0, 0 ) ;
2760 wxMacMLTEClassicControl::~wxMacMLTEClassicControl()
2762 TXNDeleteObject( m_txn
);
2766 void wxMacMLTEClassicControl::VisibilityChanged(bool shown
)
2768 MacSetObjectVisibility( shown
) ;
2769 wxMacControl::VisibilityChanged( shown
) ;
2772 void wxMacMLTEClassicControl::SuperChangedPosition()
2774 MacUpdatePosition() ;
2775 wxMacControl::SuperChangedPosition() ;
2778 ControlUserPaneDrawUPP gTPDrawProc
= NULL
;
2779 ControlUserPaneHitTestUPP gTPHitProc
= NULL
;
2780 ControlUserPaneTrackingUPP gTPTrackProc
= NULL
;
2781 ControlUserPaneIdleUPP gTPIdleProc
= NULL
;
2782 ControlUserPaneKeyDownUPP gTPKeyProc
= NULL
;
2783 ControlUserPaneActivateUPP gTPActivateProc
= NULL
;
2784 ControlUserPaneFocusUPP gTPFocusProc
= NULL
;
2786 static pascal void wxMacControlUserPaneDrawProc(ControlRef control
, SInt16 part
)
2788 wxTextCtrl
*textCtrl
= wxDynamicCast( wxFindControlFromMacControl(control
) , wxTextCtrl
) ;
2789 wxMacMLTEClassicControl
* win
= textCtrl
? (wxMacMLTEClassicControl
*)(textCtrl
->GetPeer()) : NULL
;
2791 win
->MacControlUserPaneDrawProc( part
) ;
2794 static pascal ControlPartCode
wxMacControlUserPaneHitTestProc(ControlRef control
, Point where
)
2796 wxTextCtrl
*textCtrl
= wxDynamicCast( wxFindControlFromMacControl(control
) , wxTextCtrl
) ;
2797 wxMacMLTEClassicControl
* win
= textCtrl
? (wxMacMLTEClassicControl
*)(textCtrl
->GetPeer()) : NULL
;
2799 return win
->MacControlUserPaneHitTestProc( where
.h
, where
.v
) ;
2801 return kControlNoPart
;
2804 static pascal ControlPartCode
wxMacControlUserPaneTrackingProc(ControlRef control
, Point startPt
, ControlActionUPP actionProc
)
2806 wxTextCtrl
*textCtrl
= wxDynamicCast( wxFindControlFromMacControl(control
) , wxTextCtrl
) ;
2807 wxMacMLTEClassicControl
* win
= textCtrl
? (wxMacMLTEClassicControl
*)(textCtrl
->GetPeer()) : NULL
;
2809 return win
->MacControlUserPaneTrackingProc( startPt
.h
, startPt
.v
, (void*) actionProc
) ;
2811 return kControlNoPart
;
2814 static pascal void wxMacControlUserPaneIdleProc(ControlRef control
)
2816 wxTextCtrl
*textCtrl
= wxDynamicCast( wxFindControlFromMacControl(control
) , wxTextCtrl
) ;
2817 wxMacMLTEClassicControl
* win
= textCtrl
? (wxMacMLTEClassicControl
*)(textCtrl
->GetPeer()) : NULL
;
2819 win
->MacControlUserPaneIdleProc() ;
2822 static pascal ControlPartCode
wxMacControlUserPaneKeyDownProc(ControlRef control
, SInt16 keyCode
, SInt16 charCode
, SInt16 modifiers
)
2824 wxTextCtrl
*textCtrl
= wxDynamicCast( wxFindControlFromMacControl(control
) , wxTextCtrl
) ;
2825 wxMacMLTEClassicControl
* win
= textCtrl
? (wxMacMLTEClassicControl
*)(textCtrl
->GetPeer()) : NULL
;
2827 return win
->MacControlUserPaneKeyDownProc( keyCode
, charCode
, modifiers
) ;
2829 return kControlNoPart
;
2832 static pascal void wxMacControlUserPaneActivateProc(ControlRef control
, Boolean activating
)
2834 wxTextCtrl
*textCtrl
= wxDynamicCast( wxFindControlFromMacControl(control
) , wxTextCtrl
) ;
2835 wxMacMLTEClassicControl
* win
= textCtrl
? (wxMacMLTEClassicControl
*)(textCtrl
->GetPeer()) : NULL
;
2837 win
->MacControlUserPaneActivateProc( activating
) ;
2840 static pascal ControlPartCode
wxMacControlUserPaneFocusProc(ControlRef control
, ControlFocusPart action
)
2842 wxTextCtrl
*textCtrl
= wxDynamicCast( wxFindControlFromMacControl(control
) , wxTextCtrl
) ;
2843 wxMacMLTEClassicControl
* win
= textCtrl
? (wxMacMLTEClassicControl
*)(textCtrl
->GetPeer()) : NULL
;
2845 return win
->MacControlUserPaneFocusProc( action
) ;
2847 return kControlNoPart
;
2851 static pascal void wxMacControlUserPaneBackgroundProc(ControlRef control
, ControlBackgroundPtr info
)
2853 wxTextCtrl
*textCtrl
= wxDynamicCast( wxFindControlFromMacControl(control
) , wxTextCtrl
) ;
2854 wxMacMLTEClassicControl
* win
= textCtrl
? (wxMacMLTEClassicControl
*)(textCtrl
->GetPeer()) : NULL
;
2856 win
->MacControlUserPaneBackgroundProc(info
) ;
2860 // TXNRegisterScrollInfoProc
2862 OSStatus
wxMacMLTEClassicControl::DoCreate()
2865 OSStatus err
= noErr
;
2867 // set up our globals
2868 if (gTPDrawProc
== NULL
) gTPDrawProc
= NewControlUserPaneDrawUPP(wxMacControlUserPaneDrawProc
);
2869 if (gTPHitProc
== NULL
) gTPHitProc
= NewControlUserPaneHitTestUPP(wxMacControlUserPaneHitTestProc
);
2870 if (gTPTrackProc
== NULL
) gTPTrackProc
= NewControlUserPaneTrackingUPP(wxMacControlUserPaneTrackingProc
);
2871 if (gTPIdleProc
== NULL
) gTPIdleProc
= NewControlUserPaneIdleUPP(wxMacControlUserPaneIdleProc
);
2872 if (gTPKeyProc
== NULL
) gTPKeyProc
= NewControlUserPaneKeyDownUPP(wxMacControlUserPaneKeyDownProc
);
2873 if (gTPActivateProc
== NULL
) gTPActivateProc
= NewControlUserPaneActivateUPP(wxMacControlUserPaneActivateProc
);
2874 if (gTPFocusProc
== NULL
) gTPFocusProc
= NewControlUserPaneFocusUPP(wxMacControlUserPaneFocusProc
);
2876 if (gTXNScrollInfoProc
== NULL
) gTXNScrollInfoProc
= NewTXNScrollInfoUPP(TXNScrollInfoProc
) ;
2877 if (gTXNScrollActionProc
== NULL
) gTXNScrollActionProc
= NewControlActionUPP(TXNScrollActionProc
) ;
2879 // set the initial settings for our private data
2881 m_txnWindow
= GetControlOwner(m_controlRef
);
2882 m_txnPort
= (GrafPtr
) GetWindowPort(m_txnWindow
);
2884 // set up the user pane procedures
2885 SetControlData(m_controlRef
, kControlEntireControl
, kControlUserPaneDrawProcTag
, sizeof(gTPDrawProc
), &gTPDrawProc
);
2886 SetControlData(m_controlRef
, kControlEntireControl
, kControlUserPaneHitTestProcTag
, sizeof(gTPHitProc
), &gTPHitProc
);
2887 SetControlData(m_controlRef
, kControlEntireControl
, kControlUserPaneTrackingProcTag
, sizeof(gTPTrackProc
), &gTPTrackProc
);
2888 SetControlData(m_controlRef
, kControlEntireControl
, kControlUserPaneIdleProcTag
, sizeof(gTPIdleProc
), &gTPIdleProc
);
2889 SetControlData(m_controlRef
, kControlEntireControl
, kControlUserPaneKeyDownProcTag
, sizeof(gTPKeyProc
), &gTPKeyProc
);
2890 SetControlData(m_controlRef
, kControlEntireControl
, kControlUserPaneActivateProcTag
, sizeof(gTPActivateProc
), &gTPActivateProc
);
2891 SetControlData(m_controlRef
, kControlEntireControl
, kControlUserPaneFocusProcTag
, sizeof(gTPFocusProc
), &gTPFocusProc
);
2893 // calculate the rectangles used by the control
2894 UMAGetControlBoundsInWindowCoords( m_controlRef
, &bounds
);
2896 m_txnControlBounds
= bounds
;
2897 m_txnVisBounds
= bounds
;
2902 GetGWorld( &origPort
, &origDev
) ;
2903 SetPort( m_txnPort
);
2905 // create the new edit field
2906 TXNFrameOptions frameOptions
= FrameOptionsFromWXStyle( m_windowStyle
);
2908 // the scrollbars are not correctly embedded but are inserted at the root:
2909 // this gives us problems as we have erratic redraws even over the structure area
2911 m_sbHorizontal
= 0 ;
2913 m_lastHorizontalValue
= 0 ;
2914 m_lastVerticalValue
= 0 ;
2916 Rect sb
= { 0 , 0 , 0 , 0 } ;
2917 if ( frameOptions
& kTXNWantVScrollBarMask
)
2919 CreateScrollBarControl( m_txnWindow
, &sb
, 0, 0, 100, 1, true, gTXNScrollActionProc
, &m_sbVertical
);
2920 SetControlReference( m_sbVertical
, (SInt32
)this );
2921 SetControlAction( m_sbVertical
, gTXNScrollActionProc
);
2922 ShowControl( m_sbVertical
);
2923 EmbedControl( m_sbVertical
, m_controlRef
);
2924 frameOptions
&= ~kTXNWantVScrollBarMask
;
2927 if ( frameOptions
& kTXNWantHScrollBarMask
)
2929 CreateScrollBarControl( m_txnWindow
, &sb
, 0, 0, 100, 1, true, gTXNScrollActionProc
, &m_sbHorizontal
);
2930 SetControlReference( m_sbHorizontal
, (SInt32
)this );
2931 SetControlAction( m_sbHorizontal
, gTXNScrollActionProc
);
2932 ShowControl( m_sbHorizontal
);
2933 EmbedControl( m_sbHorizontal
, m_controlRef
);
2934 frameOptions
&= ~(kTXNWantHScrollBarMask
| kTXNDrawGrowIconMask
);
2938 NULL
, m_txnWindow
, &bounds
, frameOptions
,
2939 kTXNTextEditStyleFrameType
, kTXNTextensionFile
, kTXNSystemDefaultEncoding
,
2940 &m_txn
, &m_txnFrameID
, NULL
);
2941 verify_noerr( err
);
2944 TXNControlTag iControlTags
[] = { kTXNUseCarbonEvents
};
2945 TXNControlData iControlData
[] = { { (UInt32
)&cInfo
} };
2946 int toptag
= WXSIZEOF( iControlTags
) ;
2947 TXNCarbonEventInfo cInfo
;
2948 cInfo
.useCarbonEvents
= false ;
2951 cInfo
.fDictionary
= NULL
;
2953 verify_noerr( TXNSetTXNObjectControls( m_txn
, false, toptag
, iControlTags
, iControlData
) );
2956 TXNRegisterScrollInfoProc( m_txn
, gTXNScrollInfoProc
, (SInt32
)this );
2958 SetGWorld( origPort
, origDev
) ;
2964 // ----------------------------------------------------------------------------
2965 // MLTE control implementation (OSX part)
2966 // ----------------------------------------------------------------------------
2968 // tiger multi-line textcontrols with no CR in the entire content
2969 // don't scroll automatically, so we need a hack.
2970 // This attempt only works 'before' the key (ie before CallNextEventHandler)
2971 // is processed, thus the scrolling always occurs one character too late, but
2972 // better than nothing ...
2974 static const EventTypeSpec eventList
[] =
2976 { kEventClassTextInput
, kEventTextInputUnicodeForKeyEvent
} ,
2979 static pascal OSStatus
wxMacUnicodeTextEventHandler( EventHandlerCallRef handler
, EventRef event
, void *data
)
2981 OSStatus result
= eventNotHandledErr
;
2982 wxMacMLTEHIViewControl
* focus
= (wxMacMLTEHIViewControl
*) data
;
2984 switch ( GetEventKind( event
) )
2986 case kEventTextInputUnicodeForKeyEvent
:
2988 if ( UMAGetSystemVersion() >= 0x1040 )
2990 TXNOffset from
, to
;
2991 TXNGetSelection( focus
->GetTXNObject() , &from
, &to
) ;
2993 TXNShowSelection( focus
->GetTXNObject() , kTXNShowStart
);
2995 result
= CallNextEventHandler(handler
,event
);
3005 static pascal OSStatus
wxMacTextControlEventHandler( EventHandlerCallRef handler
, EventRef event
, void *data
)
3007 OSStatus result
= eventNotHandledErr
;
3009 switch ( GetEventClass( event
) )
3011 case kEventClassTextInput
:
3012 result
= wxMacUnicodeTextEventHandler( handler
, event
, data
) ;
3021 DEFINE_ONE_SHOT_HANDLER_GETTER( wxMacTextControlEventHandler
)
3023 wxMacMLTEHIViewControl::wxMacMLTEHIViewControl( wxTextCtrl
*wxPeer
,
3024 const wxString
& str
,
3026 const wxSize
& size
, long style
) : wxMacMLTEControl( wxPeer
)
3028 m_font
= wxPeer
->GetFont() ;
3029 m_windowStyle
= style
;
3030 Rect bounds
= wxMacGetBoundsForControl( wxPeer
, pos
, size
) ;
3032 wxMacConvertNewlines10To13( &st
) ;
3035 { bounds
.left
, bounds
.top
},
3036 { bounds
.right
- bounds
.left
, bounds
.bottom
- bounds
.top
} } ;
3038 m_scrollView
= NULL
;
3039 TXNFrameOptions frameOptions
= FrameOptionsFromWXStyle( style
) ;
3040 if (( frameOptions
& (kTXNWantVScrollBarMask
| kTXNWantHScrollBarMask
)) || !(frameOptions
&kTXNSingleLineOnlyMask
))
3042 if ( frameOptions
& (kTXNWantVScrollBarMask
| kTXNWantHScrollBarMask
) )
3045 (frameOptions
& kTXNWantHScrollBarMask
? kHIScrollViewOptionsHorizScroll
: 0)
3046 | (frameOptions
& kTXNWantVScrollBarMask
? kHIScrollViewOptionsVertScroll
: 0) ,
3051 HIScrollViewCreate(kHIScrollViewOptionsVertScroll
,&m_scrollView
);
3052 HIScrollViewSetScrollBarAutoHide(m_scrollView
,true);
3055 HIViewSetFrame( m_scrollView
, &hr
);
3056 HIViewSetVisible( m_scrollView
, true );
3060 HITextViewCreate( NULL
, 0, frameOptions
, &m_textView
) ;
3061 m_txn
= HITextViewGetTXNObject( m_textView
) ;
3062 HIViewSetVisible( m_textView
, true ) ;
3065 HIViewAddSubview( m_scrollView
, m_textView
) ;
3066 m_controlRef
= m_scrollView
;
3067 wxPeer
->MacInstallEventHandler( (WXWidget
) m_textView
) ;
3071 HIViewSetFrame( m_textView
, &hr
);
3072 m_controlRef
= m_textView
;
3075 AdjustCreationAttributes( *wxWHITE
, true ) ;
3077 wxMacWindowClipper
c( m_peer
) ;
3079 SetTXNData( st
, kTXNStartOffset
, kTXNEndOffset
) ;
3081 TXNSetSelection( m_txn
, 0, 0 );
3082 TXNShowSelection( m_txn
, kTXNShowStart
);
3084 InstallControlEventHandler( m_textView
, GetwxMacTextControlEventHandlerUPP(),
3085 GetEventTypeCount(eventList
), eventList
, this,
3089 wxMacMLTEHIViewControl::~wxMacMLTEHIViewControl()
3093 OSStatus
wxMacMLTEHIViewControl::SetFocus( ControlFocusPart focusPart
)
3095 return SetKeyboardFocus( GetControlOwner( m_textView
), m_textView
, focusPart
) ;
3098 bool wxMacMLTEHIViewControl::HasFocus() const
3100 ControlRef control
;
3101 if ( GetUserFocusWindow() == NULL
)
3104 GetKeyboardFocus( GetUserFocusWindow() , &control
) ;
3105 return control
== m_textView
;
3108 void wxMacMLTEHIViewControl::SetBackground( const wxBrush
&brush
)
3110 wxMacMLTEControl::SetBackground( brush
) ;
3113 CGColorSpaceRef rgbSpace
= CGColorSpaceCreateDeviceRGB();
3114 RGBColor col
= MAC_WXCOLORREF(brush
.GetColour().GetPixel()) ;
3116 float component
[4] ;
3117 component
[0] = col
.red
/ 65536.0 ;
3118 component
[1] = col
.green
/ 65536.0 ;
3119 component
[2] = col
.blue
/ 65536.0 ;
3120 component
[3] = 1.0 ; // alpha
3122 CGColorRef color
= CGColorCreate( rgbSpace
, component
);
3123 HITextViewSetBackgroundColor( m_textView
, color
);
3124 CGColorSpaceRelease( rgbSpace
);
3128 #endif // wxUSE_TEXTCTRL