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"
18 #include <sys/types.h>
24 #include "wx/msgdlg.h"
26 #if wxUSE_STD_IOSTREAM
36 #include "wx/button.h"
37 #include "wx/toplevel.h"
38 #include "wx/textctrl.h"
39 #include "wx/settings.h"
40 #include "wx/filefn.h"
42 #include "wx/sysopt.h"
46 #if defined(__BORLANDC__) && !defined(__WIN32__)
48 #elif !defined(__MWERKS__) && !defined(__GNUWIN32) && !defined(__DARWIN__)
57 #include <MacTextEditor.h>
58 #include <ATSUnicode.h>
59 #include <TextCommon.h>
60 #include <TextEncodingConverter.h>
63 #include "wx/mac/uma.h"
66 // if this is set to 1 then under OSX 10.2 the 'classic' MLTE implementation will be used
67 // if set to 0 then the unicode textctrl will be used
68 #ifndef wxMAC_AWAYS_USE_MLTE
69 #define wxMAC_AWAYS_USE_MLTE 1
75 kTXNVisibilityTag
= 'visb' // set the visibility state of the object
84 virtual ~wxMacFunctor() {}
86 virtual void* operator()() = 0 ;
88 static void* CallBackProc( void *param
)
90 wxMacFunctor
* f
= (wxMacFunctor
*) param
;
91 void *result
= (*f
)() ;
96 template<typename classtype
, typename param1type
>
98 class wxMacObjectFunctor1
: public wxMacFunctor
100 typedef void (classtype::*function
)( param1type p1
) ;
101 typedef void (classtype::*ref_function
)( const param1type
& p1
) ;
103 wxMacObjectFunctor1( classtype
*obj
, function f
, param1type p1
) :
111 wxMacObjectFunctor1( classtype
*obj
, ref_function f
, param1type p1
) :
119 ~wxMacObjectFunctor1() {}
121 virtual void* operator()()
123 (m_object
->*m_function
)( m_param1
) ;
128 classtype
* m_object
;
129 param1type m_param1
;
132 function m_function
;
133 ref_function m_refFunction
;
137 template<typename classtype
, typename param1type
>
138 void* wxMacMPRemoteCall( classtype
*object
, void (classtype::*function
)( param1type p1
) , param1type p1
)
140 wxMacObjectFunctor1
<classtype
, param1type
> params(object
, function
, p1
) ;
142 MPRemoteCall( wxMacFunctor::CallBackProc
, ¶ms
, kMPOwningProcessRemoteContext
) ;
146 template<typename classtype
, typename param1type
>
147 void* wxMacMPRemoteCall( classtype
*object
, void (classtype::*function
)( const param1type
& p1
) , param1type p1
)
149 wxMacObjectFunctor1
<classtype
,param1type
> params(object
, function
, p1
) ;
151 MPRemoteCall( wxMacFunctor::CallBackProc
, ¶ms
, kMPOwningProcessRemoteContext
) ;
155 template<typename classtype
, typename param1type
>
156 void* wxMacMPRemoteGUICall( classtype
*object
, void (classtype::*function
)( param1type p1
) , param1type p1
)
159 void *result
= wxMacMPRemoteCall( object
, function
, p1
) ;
164 template<typename classtype
, typename param1type
>
165 void* wxMacMPRemoteGUICall( classtype
*object
, void (classtype::*function
)( const param1type
& p1
) , param1type p1
)
168 void *result
= wxMacMPRemoteCall( object
, function
, p1
) ;
173 // common interface for all implementations
174 class wxMacTextControl
: public wxMacControl
177 wxMacTextControl( wxTextCtrl
*peer
) ;
178 ~wxMacTextControl() ;
180 virtual wxString
GetStringValue() const = 0 ;
181 virtual void SetStringValue( const wxString
&val
) = 0 ;
182 virtual void SetSelection( long from
, long to
) = 0 ;
183 virtual void GetSelection( long* from
, long* to
) const = 0 ;
184 virtual void WriteText( const wxString
& str
) = 0 ;
186 virtual void SetStyle( long start
, long end
, const wxTextAttr
& style
) ;
187 virtual void Copy() ;
189 virtual void Paste() ;
190 virtual bool CanPaste() const ;
191 virtual void SetEditable( bool editable
) ;
192 virtual wxTextPos
GetLastPosition() const ;
193 virtual void Replace( long from
, long to
, const wxString
&str
) ;
194 virtual void Remove( long from
, long to
) ;
197 virtual bool HasOwnContextMenu() const
200 virtual bool SetupCursor( const wxPoint
& pt
)
203 virtual void Clear() ;
204 virtual bool CanUndo() const;
205 virtual void Undo() ;
206 virtual bool CanRedo() const;
207 virtual void Redo() ;
208 virtual int GetNumberOfLines() const ;
209 virtual long XYToPosition(long x
, long y
) const;
210 virtual bool PositionToXY(long pos
, long *x
, long *y
) const ;
211 virtual void ShowPosition(long WXUNUSED(pos
)) ;
212 virtual int GetLineLength(long lineNo
) const ;
213 virtual wxString
GetLineText(long lineNo
) const ;
215 #ifndef __WXMAC_OSX__
216 virtual void MacControlUserPaneDrawProc(wxInt16 part
) = 0 ;
217 virtual wxInt16
MacControlUserPaneHitTestProc(wxInt16 x
, wxInt16 y
) = 0 ;
218 virtual wxInt16
MacControlUserPaneTrackingProc(wxInt16 x
, wxInt16 y
, void* actionProc
) = 0 ;
219 virtual void MacControlUserPaneIdleProc() = 0 ;
220 virtual wxInt16
MacControlUserPaneKeyDownProc(wxInt16 keyCode
, wxInt16 charCode
, wxInt16 modifiers
) = 0 ;
221 virtual void MacControlUserPaneActivateProc(bool activating
) = 0 ;
222 virtual wxInt16
MacControlUserPaneFocusProc(wxInt16 action
) = 0 ;
223 virtual void MacControlUserPaneBackgroundProc(void* info
) = 0 ;
227 // common parts for implementations based on MLTE
229 class wxMacMLTEControl
: public wxMacTextControl
232 wxMacMLTEControl( wxTextCtrl
*peer
) ;
234 virtual wxString
GetStringValue() const ;
235 virtual void SetStringValue( const wxString
&str
) ;
237 static TXNFrameOptions
FrameOptionsFromWXStyle( long wxStyle
) ;
239 void AdjustCreationAttributes( const wxColour
& background
, bool visible
) ;
241 virtual void SetFont( const wxFont
& font
, const wxColour
& foreground
, long windowStyle
) ;
242 virtual void SetBackground( const wxBrush
&brush
) ;
243 virtual void SetStyle( long start
, long end
, const wxTextAttr
& style
) ;
244 virtual void Copy() ;
246 virtual void Paste() ;
247 virtual bool CanPaste() const ;
248 virtual void SetEditable( bool editable
) ;
249 virtual wxTextPos
GetLastPosition() const ;
250 virtual void Replace( long from
, long to
, const wxString
&str
) ;
251 virtual void Remove( long from
, long to
) ;
252 virtual void GetSelection( long* from
, long* to
) const ;
253 virtual void SetSelection( long from
, long to
) ;
255 virtual void WriteText( const wxString
& str
) ;
257 virtual bool HasOwnContextMenu() const
259 #if MAC_OS_X_VERSION_MAX_ALLOWED >= MAC_OS_X_VERSION_10_4
260 if ( UMAGetSystemVersion() >= 0x1040 )
262 TXNCommandEventSupportOptions options
;
263 TXNGetCommandEventSupport( m_txn
, & options
) ;
264 return options
& kTXNSupportEditCommandProcessing
;
271 virtual void Clear() ;
273 virtual bool CanUndo() const ;
274 virtual void Undo() ;
275 virtual bool CanRedo() const;
276 virtual void Redo() ;
277 virtual int GetNumberOfLines() const ;
278 virtual long XYToPosition(long x
, long y
) const ;
279 virtual bool PositionToXY(long pos
, long *x
, long *y
) const ;
280 virtual void ShowPosition( long pos
) ;
281 virtual int GetLineLength(long lineNo
) const ;
282 virtual wxString
GetLineText(long lineNo
) const ;
284 void SetTXNData( const wxString
& st
, TXNOffset start
, TXNOffset end
) ;
287 void TXNSetAttribute( const wxTextAttr
& style
, long from
, long to
) ;
292 #if TARGET_API_MAC_OSX
294 // implementation available under OSX
296 #if MAC_OS_X_VERSION_MAX_ALLOWED > MAC_OS_X_VERSION_10_2
298 class wxMacMLTEHIViewControl
: public wxMacMLTEControl
301 wxMacMLTEHIViewControl( wxTextCtrl
*wxPeer
,
304 const wxSize
& size
, long style
) ;
305 virtual OSStatus
SetFocus( ControlFocusPart focusPart
) ;
306 virtual bool HasFocus() const ;
307 virtual void SetBackground( const wxBrush
&brush
) ;
310 HIViewRef m_scrollView
;
311 HIViewRef m_textView
;
316 class wxMacUnicodeTextControl
: public wxMacTextControl
319 wxMacUnicodeTextControl( wxTextCtrl
*wxPeer
,
322 const wxSize
& size
, long style
) ;
323 ~wxMacUnicodeTextControl();
325 virtual void VisibilityChanged(bool shown
);
326 virtual wxString
GetStringValue() const ;
327 virtual void SetStringValue( const wxString
&str
) ;
330 virtual void Paste();
331 virtual bool CanPaste() const;
332 virtual void SetEditable(bool editable
) ;
333 virtual void GetSelection( long* from
, long* to
) const ;
334 virtual void SetSelection( long from
, long to
) ;
335 virtual void WriteText(const wxString
& str
) ;
338 // contains the tag for the content (is different for password and non-password controls)
344 // 'classic' MLTE implementation
346 class wxMacMLTEClassicControl
: public wxMacMLTEControl
349 wxMacMLTEClassicControl( wxTextCtrl
*wxPeer
,
352 const wxSize
& size
, long style
) ;
353 ~wxMacMLTEClassicControl() ;
355 virtual void VisibilityChanged(bool shown
) ;
356 virtual void SuperChangedPosition() ;
358 virtual void MacControlUserPaneDrawProc(wxInt16 part
) ;
359 virtual wxInt16
MacControlUserPaneHitTestProc(wxInt16 x
, wxInt16 y
) ;
360 virtual wxInt16
MacControlUserPaneTrackingProc(wxInt16 x
, wxInt16 y
, void* actionProc
) ;
361 virtual void MacControlUserPaneIdleProc() ;
362 virtual wxInt16
MacControlUserPaneKeyDownProc(wxInt16 keyCode
, wxInt16 charCode
, wxInt16 modifiers
) ;
363 virtual void MacControlUserPaneActivateProc(bool activating
) ;
364 virtual wxInt16
MacControlUserPaneFocusProc(wxInt16 action
) ;
365 virtual void MacControlUserPaneBackgroundProc(void* info
) ;
367 virtual bool SetupCursor( const wxPoint
& WXUNUSED(pt
) )
369 MacControlUserPaneIdleProc();
373 virtual void SetRect( Rect
*r
) ;
378 void MacUpdatePosition() ;
379 void MacActivatePaneText(bool setActive
) ;
380 void MacFocusPaneText(bool setFocus
) ;
381 void MacSetObjectVisibility(bool vis
) ;
384 TXNFrameID m_txnFrameID
;
386 WindowRef m_txnWindow
;
387 // bounds of the control as we last did set the txn frames
388 Rect m_txnControlBounds
;
389 Rect m_txnVisBounds
;
392 static pascal void TXNScrollActionProc( ControlRef controlRef
, ControlPartCode partCode
) ;
393 static pascal void TXNScrollInfoProc(
394 SInt32 iValue
, SInt32 iMaximumValue
,
395 TXNScrollBarOrientation iScrollBarOrientation
, SInt32 iRefCon
) ;
397 ControlRef m_sbHorizontal
;
398 SInt32 m_lastHorizontalValue
;
399 ControlRef m_sbVertical
;
400 SInt32 m_lastVerticalValue
;
405 IMPLEMENT_DYNAMIC_CLASS(wxTextCtrl
, wxControl
)
407 BEGIN_EVENT_TABLE(wxTextCtrl
, wxControl
)
408 EVT_ERASE_BACKGROUND( wxTextCtrl::OnEraseBackground
)
409 EVT_DROP_FILES(wxTextCtrl::OnDropFiles
)
410 EVT_CHAR(wxTextCtrl::OnChar
)
411 EVT_MENU(wxID_CUT
, wxTextCtrl::OnCut
)
412 EVT_MENU(wxID_COPY
, wxTextCtrl::OnCopy
)
413 EVT_MENU(wxID_PASTE
, wxTextCtrl::OnPaste
)
414 EVT_MENU(wxID_UNDO
, wxTextCtrl::OnUndo
)
415 EVT_MENU(wxID_REDO
, wxTextCtrl::OnRedo
)
416 EVT_MENU(wxID_CLEAR
, wxTextCtrl::OnDelete
)
417 EVT_MENU(wxID_SELECTALL
, wxTextCtrl::OnSelectAll
)
419 EVT_CONTEXT_MENU(wxTextCtrl::OnContextMenu
)
421 EVT_UPDATE_UI(wxID_CUT
, wxTextCtrl::OnUpdateCut
)
422 EVT_UPDATE_UI(wxID_COPY
, wxTextCtrl::OnUpdateCopy
)
423 EVT_UPDATE_UI(wxID_PASTE
, wxTextCtrl::OnUpdatePaste
)
424 EVT_UPDATE_UI(wxID_UNDO
, wxTextCtrl::OnUpdateUndo
)
425 EVT_UPDATE_UI(wxID_REDO
, wxTextCtrl::OnUpdateRedo
)
426 EVT_UPDATE_UI(wxID_CLEAR
, wxTextCtrl::OnUpdateDelete
)
427 EVT_UPDATE_UI(wxID_SELECTALL
, wxTextCtrl::OnUpdateSelectAll
)
431 void wxTextCtrl::Init()
437 m_privateContextMenu
= NULL
;
438 m_triggerOnSetValue
= true ;
441 wxTextCtrl::~wxTextCtrl()
443 delete m_privateContextMenu
;
446 bool wxTextCtrl::Create( wxWindow
*parent
,
452 const wxValidator
& validator
,
453 const wxString
& name
)
455 m_macIsUserPane
= false ;
458 if ( ! (style
& wxNO_BORDER
) )
459 style
= (style
& ~wxBORDER_MASK
) | wxSUNKEN_BORDER
;
461 if ( !wxTextCtrlBase::Create( parent
, id
, pos
, size
, style
& ~(wxHSCROLL
| wxVSCROLL
), validator
, name
) )
464 if ( m_windowStyle
& wxTE_MULTILINE
)
467 !(m_windowStyle
& wxTE_PROCESS_ENTER
),
468 wxT("wxTE_PROCESS_ENTER style is ignored for multiline text controls (they always process it)") );
470 m_windowStyle
|= wxTE_PROCESS_ENTER
;
471 style
|= wxTE_PROCESS_ENTER
;
474 bool forceMLTE
= false ;
476 #if wxUSE_SYSTEM_OPTIONS
477 if (wxSystemOptions::HasOption( wxMAC_TEXTCONTROL_USE_MLTE
) && (wxSystemOptions::GetOptionInt( wxMAC_TEXTCONTROL_USE_MLTE
) == 1))
484 #if MAC_OS_X_VERSION_MAX_ALLOWED > MAC_OS_X_VERSION_10_2
485 if ( UMAGetSystemVersion() >= 0x1030 && !forceMLTE
)
487 if ( m_windowStyle
& wxTE_MULTILINE
)
488 m_peer
= new wxMacMLTEHIViewControl( this , str
, pos
, size
, style
) ;
494 if ( !(m_windowStyle
& wxTE_MULTILINE
) && !forceMLTE
)
495 m_peer
= new wxMacUnicodeTextControl( this , str
, pos
, size
, style
) ;
500 m_peer
= new wxMacMLTEClassicControl( this , str
, pos
, size
, style
) ;
502 MacPostControlCreate(pos
, size
) ;
504 // only now the embedding is correct and we can do a positioning update
506 MacSuperChangedPosition() ;
508 if ( m_windowStyle
& wxTE_READONLY
)
509 SetEditable( false ) ;
511 SetCursor( wxCursor( wxCURSOR_IBEAM
) ) ;
516 void wxTextCtrl::MacSuperChangedPosition()
518 wxWindow::MacSuperChangedPosition() ;
519 GetPeer()->SuperChangedPosition() ;
522 void wxTextCtrl::MacVisibilityChanged()
524 GetPeer()->VisibilityChanged( MacIsReallyShown() ) ;
527 void wxTextCtrl::MacEnabledStateChanged()
531 wxString
wxTextCtrl::GetValue() const
533 return GetPeer()->GetStringValue() ;
536 void wxTextCtrl::GetSelection(long* from
, long* to
) const
538 GetPeer()->GetSelection( from
, to
) ;
541 void wxTextCtrl::SetValue(const wxString
& str
)
544 if ( GetValue() == str
)
547 GetPeer()->SetStringValue( str
) ;
549 if ( m_triggerOnSetValue
)
551 wxCommandEvent
event( wxEVT_COMMAND_TEXT_UPDATED
, m_windowId
);
552 event
.SetString( GetValue() );
553 event
.SetEventObject( this );
554 GetEventHandler()->ProcessEvent( event
);
558 void wxTextCtrl::SetMaxLength(unsigned long len
)
563 bool wxTextCtrl::SetFont( const wxFont
& font
)
565 if ( !wxTextCtrlBase::SetFont( font
) )
568 GetPeer()->SetFont( font
, GetForegroundColour() , GetWindowStyle() ) ;
573 bool wxTextCtrl::SetStyle(long start
, long end
, const wxTextAttr
& style
)
575 GetPeer()->SetStyle( start
, end
, style
) ;
580 bool wxTextCtrl::SetDefaultStyle(const wxTextAttr
& style
)
582 wxTextCtrlBase::SetDefaultStyle( style
) ;
583 SetStyle( kTXNUseCurrentSelection
, kTXNUseCurrentSelection
, GetDefaultStyle() ) ;
588 // Clipboard operations
590 void wxTextCtrl::Copy()
596 void wxTextCtrl::Cut()
602 wxCommandEvent
event( wxEVT_COMMAND_TEXT_UPDATED
, m_windowId
);
603 event
.SetEventObject( this );
604 GetEventHandler()->ProcessEvent( event
);
608 void wxTextCtrl::Paste()
614 // TODO: eventually we should add setting the default style again
616 wxCommandEvent
event( wxEVT_COMMAND_TEXT_UPDATED
, m_windowId
);
617 event
.SetEventObject( this );
618 GetEventHandler()->ProcessEvent( event
);
622 bool wxTextCtrl::CanCopy() const
624 // Can copy if there's a selection
626 GetSelection( &from
, &to
);
631 bool wxTextCtrl::CanCut() const
636 // Can cut if there's a selection
638 GetSelection( &from
, &to
);
643 bool wxTextCtrl::CanPaste() const
648 return GetPeer()->CanPaste() ;
651 void wxTextCtrl::SetEditable(bool editable
)
653 if ( editable
!= m_editable
)
655 m_editable
= editable
;
656 GetPeer()->SetEditable( editable
) ;
660 void wxTextCtrl::SetInsertionPoint(long pos
)
662 SetSelection( pos
, pos
) ;
665 void wxTextCtrl::SetInsertionPointEnd()
667 wxTextPos pos
= GetLastPosition();
668 SetInsertionPoint( pos
);
671 long wxTextCtrl::GetInsertionPoint() const
674 GetSelection( &begin
, &end
) ;
679 wxTextPos
wxTextCtrl::GetLastPosition() const
681 return GetPeer()->GetLastPosition() ;
684 void wxTextCtrl::Replace(long from
, long to
, const wxString
& str
)
686 GetPeer()->Replace( from
, to
, str
) ;
689 void wxTextCtrl::Remove(long from
, long to
)
691 GetPeer()->Remove( from
, to
) ;
694 void wxTextCtrl::SetSelection(long from
, long to
)
696 GetPeer()->SetSelection( from
, to
) ;
699 bool wxTextCtrl::LoadFile(const wxString
& file
)
701 return wxTextCtrlBase::LoadFile( file
);
704 void wxTextCtrl::WriteText(const wxString
& str
)
706 // TODO: this MPRemoting will be moved into a remoting peer proxy for any command
707 if ( !wxIsMainThread() )
709 // unfortunately CW 8 is not able to correctly deduce the template types,
710 // so we have to instantiate explicitly
711 wxMacMPRemoteGUICall
<wxTextCtrl
,wxString
>( this , &wxTextCtrl::WriteText
, str
) ;
716 GetPeer()->WriteText( str
) ;
719 void wxTextCtrl::AppendText(const wxString
& text
)
721 SetInsertionPointEnd();
725 void wxTextCtrl::Clear()
730 bool wxTextCtrl::IsModified() const
735 bool wxTextCtrl::IsEditable() const
737 return IsEnabled() && m_editable
;
740 bool wxTextCtrl::AcceptsFocus() const
742 // we don't want focus if we can't be edited
743 return /*IsEditable() && */ wxControl::AcceptsFocus();
746 wxSize
wxTextCtrl::DoGetBestSize() const
750 // these are the numbers from the HIG:
751 // we reduce them by the borders first
754 switch ( m_windowVariant
)
756 case wxWINDOW_VARIANT_NORMAL
:
760 case wxWINDOW_VARIANT_SMALL
:
764 case wxWINDOW_VARIANT_MINI
:
773 // as the above numbers have some free space around the text
774 // we get 5 lines like this anyway
775 if ( m_windowStyle
& wxTE_MULTILINE
)
778 if ( !HasFlag(wxNO_BORDER
) )
781 return wxSize(wText
, hText
);
784 // ----------------------------------------------------------------------------
786 // ----------------------------------------------------------------------------
788 void wxTextCtrl::Undo()
794 void wxTextCtrl::Redo()
800 bool wxTextCtrl::CanUndo() const
805 return GetPeer()->CanUndo() ;
808 bool wxTextCtrl::CanRedo() const
813 return GetPeer()->CanRedo() ;
816 void wxTextCtrl::MarkDirty()
821 void wxTextCtrl::DiscardEdits()
826 int wxTextCtrl::GetNumberOfLines() const
828 return GetPeer()->GetNumberOfLines() ;
831 long wxTextCtrl::XYToPosition(long x
, long y
) const
833 return GetPeer()->XYToPosition( x
, y
) ;
836 bool wxTextCtrl::PositionToXY(long pos
, long *x
, long *y
) const
838 return GetPeer()->PositionToXY( pos
, x
, y
) ;
841 void wxTextCtrl::ShowPosition(long pos
)
843 return GetPeer()->ShowPosition(pos
) ;
846 int wxTextCtrl::GetLineLength(long lineNo
) const
848 return GetPeer()->GetLineLength(lineNo
) ;
851 wxString
wxTextCtrl::GetLineText(long lineNo
) const
853 return GetPeer()->GetLineText(lineNo
) ;
856 void wxTextCtrl::Command(wxCommandEvent
& event
)
858 SetValue(event
.GetString());
859 ProcessCommand(event
);
862 void wxTextCtrl::OnDropFiles(wxDropFilesEvent
& event
)
864 // By default, load the first file into the text window.
865 if (event
.GetNumberOfFiles() > 0)
866 LoadFile( event
.GetFiles()[0] );
869 void wxTextCtrl::OnEraseBackground(wxEraseEvent
& event
)
871 // all erasing should be done by the real mac control implementation
872 // while this is true for MLTE under classic, the HITextView is somehow
873 // transparent but background erase is not working correctly, so intercept
874 // things while we can...
878 void wxTextCtrl::OnChar(wxKeyEvent
& event
)
880 int key
= event
.GetKeyCode() ;
881 bool eat_key
= false ;
883 if ( key
== 'a' && event
.MetaDown() )
890 if ( key
== 'c' && event
.MetaDown() )
898 if ( !IsEditable() && key
!= WXK_LEFT
&& key
!= WXK_RIGHT
&& key
!= WXK_DOWN
&& key
!= WXK_UP
&& key
!= WXK_TAB
&&
899 !( key
== WXK_RETURN
&& ( (m_windowStyle
& wxTE_PROCESS_ENTER
) || (m_windowStyle
& wxTE_MULTILINE
) ) )
900 // && key != WXK_PAGEUP && key != WXK_PAGEDOWN && key != WXK_HOME && key != WXK_END
907 // Check if we have reached the max # of chars (if it is set), but still
908 // allow navigation and deletion
909 if ( !IsMultiLine() && m_maxLength
&& GetValue().length() >= m_maxLength
&&
910 key
!= WXK_LEFT
&& key
!= WXK_RIGHT
&& key
!= WXK_TAB
&&
911 key
!= WXK_BACK
&& !( key
== WXK_RETURN
&& (m_windowStyle
& wxTE_PROCESS_ENTER
) )
914 // eat it, we don't want to add more than allowed # of characters
916 // TODO: generate EVT_TEXT_MAXLEN()
920 // assume that any key not processed yet is going to modify the control
923 if ( key
== 'v' && event
.MetaDown() )
931 if ( key
== 'x' && event
.MetaDown() )
942 if (m_windowStyle
& wxTE_PROCESS_ENTER
)
944 wxCommandEvent
event(wxEVT_COMMAND_TEXT_ENTER
, m_windowId
);
945 event
.SetEventObject( this );
946 event
.SetString( GetValue() );
947 if ( GetEventHandler()->ProcessEvent(event
) )
951 if ( !(m_windowStyle
& wxTE_MULTILINE
) )
953 wxWindow
*parent
= GetParent();
954 while ( parent
&& !parent
->IsTopLevel() && parent
->GetDefaultItem() == NULL
)
956 parent
= parent
->GetParent() ;
959 if ( parent
&& parent
->GetDefaultItem() )
961 wxButton
*def
= wxDynamicCast(parent
->GetDefaultItem(), wxButton
);
962 if ( def
&& def
->IsEnabled() )
964 wxCommandEvent
event(wxEVT_COMMAND_BUTTON_CLICKED
, def
->GetId() );
965 event
.SetEventObject(def
);
972 // this will make wxWidgets eat the ENTER key so that
973 // we actually prevent line wrapping in a single line text control
979 if ( !(m_windowStyle
& wxTE_PROCESS_TAB
))
982 if (!event
.ShiftDown())
983 flags
|= wxNavigationKeyEvent::IsForward
;
984 if (event
.ControlDown())
985 flags
|= wxNavigationKeyEvent::WinChange
;
992 // This is necessary (don't know why);
993 // otherwise the tab will not be inserted.
994 WriteText(wxT("\t"));
1004 // perform keystroke handling
1008 if ( ( key
>= 0x20 && key
< WXK_START
) ||
1009 key
== WXK_RETURN
||
1010 key
== WXK_DELETE
||
1013 wxCommandEvent
event1(wxEVT_COMMAND_TEXT_UPDATED
, m_windowId
);
1014 event1
.SetEventObject( this );
1015 wxPostEvent( GetEventHandler(), event1
);
1019 // ----------------------------------------------------------------------------
1020 // standard handlers for standard edit menu events
1021 // ----------------------------------------------------------------------------
1023 void wxTextCtrl::OnCut(wxCommandEvent
& WXUNUSED(event
))
1028 void wxTextCtrl::OnCopy(wxCommandEvent
& WXUNUSED(event
))
1033 void wxTextCtrl::OnPaste(wxCommandEvent
& WXUNUSED(event
))
1038 void wxTextCtrl::OnUndo(wxCommandEvent
& WXUNUSED(event
))
1043 void wxTextCtrl::OnRedo(wxCommandEvent
& WXUNUSED(event
))
1048 void wxTextCtrl::OnDelete(wxCommandEvent
& WXUNUSED(event
))
1052 GetSelection( &from
, &to
);
1053 if (from
!= -1 && to
!= -1)
1057 void wxTextCtrl::OnSelectAll(wxCommandEvent
& WXUNUSED(event
))
1059 SetSelection(-1, -1);
1062 void wxTextCtrl::OnUpdateCut(wxUpdateUIEvent
& event
)
1064 event
.Enable( CanCut() );
1067 void wxTextCtrl::OnUpdateCopy(wxUpdateUIEvent
& event
)
1069 event
.Enable( CanCopy() );
1072 void wxTextCtrl::OnUpdatePaste(wxUpdateUIEvent
& event
)
1074 event
.Enable( CanPaste() );
1077 void wxTextCtrl::OnUpdateUndo(wxUpdateUIEvent
& event
)
1079 event
.Enable( CanUndo() );
1082 void wxTextCtrl::OnUpdateRedo(wxUpdateUIEvent
& event
)
1084 event
.Enable( CanRedo() );
1087 void wxTextCtrl::OnUpdateDelete(wxUpdateUIEvent
& event
)
1091 GetSelection( &from
, &to
);
1092 event
.Enable( from
!= -1 && to
!= -1 && from
!= to
&& IsEditable() ) ;
1095 void wxTextCtrl::OnUpdateSelectAll(wxUpdateUIEvent
& event
)
1097 event
.Enable(GetLastPosition() > 0);
1100 // CS: Context Menus only work with MLTE implementations or non-multiline HIViews at the moment
1102 void wxTextCtrl::OnContextMenu(wxContextMenuEvent
& event
)
1104 if ( GetPeer()->HasOwnContextMenu() )
1110 if (m_privateContextMenu
== NULL
)
1112 m_privateContextMenu
= new wxMenu
;
1113 m_privateContextMenu
->Append(wxID_UNDO
, _("&Undo"));
1114 m_privateContextMenu
->Append(wxID_REDO
, _("&Redo"));
1115 m_privateContextMenu
->AppendSeparator();
1116 m_privateContextMenu
->Append(wxID_CUT
, _("Cu&t"));
1117 m_privateContextMenu
->Append(wxID_COPY
, _("&Copy"));
1118 m_privateContextMenu
->Append(wxID_PASTE
, _("&Paste"));
1119 m_privateContextMenu
->Append(wxID_CLEAR
, _("&Delete"));
1120 m_privateContextMenu
->AppendSeparator();
1121 m_privateContextMenu
->Append(wxID_SELECTALL
, _("Select &All"));
1124 if (m_privateContextMenu
!= NULL
)
1125 PopupMenu(m_privateContextMenu
);
1128 bool wxTextCtrl::MacSetupCursor( const wxPoint
& pt
)
1130 if ( !GetPeer()->SetupCursor( pt
) )
1131 return wxWindow::MacSetupCursor( pt
) ;
1136 #if !TARGET_API_MAC_OSX
1138 // user pane implementation
1140 void wxTextCtrl::MacControlUserPaneDrawProc(wxInt16 part
)
1142 GetPeer()->MacControlUserPaneDrawProc( part
) ;
1145 wxInt16
wxTextCtrl::MacControlUserPaneHitTestProc(wxInt16 x
, wxInt16 y
)
1147 return GetPeer()->MacControlUserPaneHitTestProc( x
, y
) ;
1150 wxInt16
wxTextCtrl::MacControlUserPaneTrackingProc(wxInt16 x
, wxInt16 y
, void* actionProc
)
1152 return GetPeer()->MacControlUserPaneTrackingProc( x
, y
, actionProc
) ;
1155 void wxTextCtrl::MacControlUserPaneIdleProc()
1157 GetPeer()->MacControlUserPaneIdleProc( ) ;
1160 wxInt16
wxTextCtrl::MacControlUserPaneKeyDownProc(wxInt16 keyCode
, wxInt16 charCode
, wxInt16 modifiers
)
1162 return GetPeer()->MacControlUserPaneKeyDownProc( keyCode
, charCode
, modifiers
) ;
1165 void wxTextCtrl::MacControlUserPaneActivateProc(bool activating
)
1167 GetPeer()->MacControlUserPaneActivateProc( activating
) ;
1170 wxInt16
wxTextCtrl::MacControlUserPaneFocusProc(wxInt16 action
)
1172 return GetPeer()->MacControlUserPaneFocusProc( action
) ;
1175 void wxTextCtrl::MacControlUserPaneBackgroundProc(void* info
)
1177 GetPeer()->MacControlUserPaneBackgroundProc( info
) ;
1182 // ----------------------------------------------------------------------------
1183 // implementation base class
1184 // ----------------------------------------------------------------------------
1186 wxMacTextControl::wxMacTextControl(wxTextCtrl
* peer
) :
1187 wxMacControl( peer
)
1191 wxMacTextControl::~wxMacTextControl()
1195 void wxMacTextControl::SetStyle(long start
, long end
, const wxTextAttr
& style
)
1199 void wxMacTextControl::Copy()
1203 void wxMacTextControl::Cut()
1207 void wxMacTextControl::Paste()
1211 bool wxMacTextControl::CanPaste() const
1216 void wxMacTextControl::SetEditable(bool editable
)
1220 wxTextPos
wxMacTextControl::GetLastPosition() const
1222 return GetStringValue().length() ;
1225 void wxMacTextControl::Replace( long from
, long to
, const wxString
&val
)
1227 SetSelection( from
, to
) ;
1231 void wxMacTextControl::Remove( long from
, long to
)
1233 SetSelection( from
, to
) ;
1234 WriteText( wxEmptyString
) ;
1237 void wxMacTextControl::Clear()
1239 SetStringValue( wxEmptyString
) ;
1242 bool wxMacTextControl::CanUndo() const
1247 void wxMacTextControl::Undo()
1251 bool wxMacTextControl::CanRedo() const
1256 void wxMacTextControl::Redo()
1260 long wxMacTextControl::XYToPosition(long x
, long y
) const
1265 bool wxMacTextControl::PositionToXY(long pos
, long *x
, long *y
) const
1270 void wxMacTextControl::ShowPosition( long WXUNUSED(pos
) )
1274 int wxMacTextControl::GetNumberOfLines() const
1276 ItemCount lines
= 0 ;
1277 wxString content
= GetStringValue() ;
1280 for (size_t i
= 0; i
< content
.length() ; i
++)
1282 if (content
[i
] == '\r')
1289 wxString
wxMacTextControl::GetLineText(long lineNo
) const
1291 // TODO: change this if possible to reflect real lines
1292 wxString content
= GetStringValue() ;
1296 for (size_t i
= 0; i
< content
.length() ; i
++)
1298 if (count
== lineNo
)
1300 // Add chars in line then
1303 for (size_t j
= i
; j
< content
.length(); j
++)
1305 if (content
[j
] == '\n')
1314 if (content
[i
] == '\n')
1318 return wxEmptyString
;
1321 int wxMacTextControl::GetLineLength(long lineNo
) const
1323 // TODO: change this if possible to reflect real lines
1324 wxString content
= GetStringValue() ;
1328 for (size_t i
= 0; i
< content
.length() ; i
++)
1330 if (count
== lineNo
)
1332 // Count chars in line then
1334 for (size_t j
= i
; j
< content
.length(); j
++)
1337 if (content
[j
] == '\n')
1344 if (content
[i
] == '\n')
1351 // ----------------------------------------------------------------------------
1352 // standard unicode control implementation
1353 // ----------------------------------------------------------------------------
1355 #if TARGET_API_MAC_OSX
1357 wxMacUnicodeTextControl::wxMacUnicodeTextControl( wxTextCtrl
*wxPeer
,
1358 const wxString
& str
,
1360 const wxSize
& size
, long style
)
1361 : wxMacTextControl( wxPeer
)
1363 m_font
= wxPeer
->GetFont() ;
1364 m_windowStyle
= style
;
1365 Rect bounds
= wxMacGetBoundsForControl( wxPeer
, pos
, size
) ;
1367 wxMacConvertNewlines10To13( &st
) ;
1368 wxMacCFStringHolder
cf(st
, m_font
.GetEncoding()) ;
1369 CFStringRef cfr
= cf
;
1370 Boolean isPassword
= ( m_windowStyle
& wxTE_PASSWORD
) != 0 ;
1371 m_valueTag
= isPassword
? kControlEditTextPasswordCFStringTag
: kControlEditTextCFStringTag
;
1373 OSStatus err
= CreateEditUnicodeTextControl(
1374 MAC_WXHWND(wxPeer
->MacGetTopLevelWindowRef()), &bounds
, cfr
,
1375 isPassword
, NULL
, &m_controlRef
) ;
1376 verify_noerr( err
);
1378 if ( !(m_windowStyle
& wxTE_MULTILINE
) )
1379 SetData
<Boolean
>( kControlEditTextPart
, kControlEditTextSingleLineTag
, true ) ;
1382 wxMacUnicodeTextControl::~wxMacUnicodeTextControl()
1386 void wxMacUnicodeTextControl::VisibilityChanged(bool shown
)
1388 if ( !(m_windowStyle
& wxTE_MULTILINE
) && shown
)
1390 // work around a refresh issue insofar as not always the entire content is shown,
1391 // even if this would be possible
1392 ControlEditTextSelectionRec sel
;
1393 CFStringRef value
= NULL
;
1395 verify_noerr( GetData
<ControlEditTextSelectionRec
>( 0, kControlEditTextSelectionTag
, &sel
) );
1396 verify_noerr( GetData
<CFStringRef
>( 0, m_valueTag
, &value
) );
1397 verify_noerr( SetData
<CFStringRef
>( 0, m_valueTag
, &value
) );
1398 verify_noerr( SetData
<ControlEditTextSelectionRec
>( 0, kControlEditTextSelectionTag
, &sel
) );
1400 CFRelease( value
) ;
1404 wxString
wxMacUnicodeTextControl::GetStringValue() const
1407 CFStringRef value
= GetData
<CFStringRef
>(0, m_valueTag
) ;
1410 wxMacCFStringHolder
cf(value
) ;
1411 result
= cf
.AsString() ;
1415 wxMacConvertNewlines13To10( &result
) ;
1417 wxMacConvertNewlines10To13( &result
) ;
1423 void wxMacUnicodeTextControl::SetStringValue( const wxString
&str
)
1426 wxMacConvertNewlines10To13( &st
) ;
1427 wxMacCFStringHolder
cf( st
, m_font
.GetEncoding() ) ;
1428 verify_noerr( SetData
<CFStringRef
>( 0, m_valueTag
, cf
) ) ;
1431 void wxMacUnicodeTextControl::Copy()
1433 SendHICommand( kHICommandCopy
) ;
1436 void wxMacUnicodeTextControl::Cut()
1438 SendHICommand( kHICommandCut
) ;
1441 void wxMacUnicodeTextControl::Paste()
1443 SendHICommand( kHICommandPaste
) ;
1446 bool wxMacUnicodeTextControl::CanPaste() const
1451 void wxMacUnicodeTextControl::SetEditable(bool editable
)
1453 #if 0 // leads to problem because text cannot be selected anymore
1454 SetData
<Boolean
>( kControlEditTextPart
, kControlEditTextLockedTag
, (Boolean
) !editable
) ;
1458 void wxMacUnicodeTextControl::GetSelection( long* from
, long* to
) const
1460 ControlEditTextSelectionRec sel
;
1461 verify_noerr( GetData
<ControlEditTextSelectionRec
>( 0, kControlEditTextSelectionTag
, &sel
) ) ;
1463 *from
= sel
.selStart
;
1468 void wxMacUnicodeTextControl::SetSelection( long from
, long to
)
1470 ControlEditTextSelectionRec sel
;
1471 if ((from
== -1) && (to
== -1))
1474 to
= 32767 ; // sel has 16 bit signed values, max is 32767
1477 sel
.selStart
= from
;
1479 SetData
<ControlEditTextSelectionRec
>( 0, kControlEditTextSelectionTag
, &sel
) ;
1482 void wxMacUnicodeTextControl::WriteText( const wxString
& str
)
1485 wxMacConvertNewlines10To13( &st
) ;
1487 #if MAC_OS_X_VERSION_MAX_ALLOWED > MAC_OS_X_VERSION_10_2
1488 wxMacCFStringHolder
cf(st
, m_font
.GetEncoding() ) ;
1489 CFStringRef value
= cf
;
1490 SetData
<CFStringRef
>( 0, kControlEditTextInsertCFStringRefTag
, &value
);
1492 wxString val
= GetStringValue() ;
1494 GetSelection( &start
, &end
) ;
1495 val
.Remove( start
, end
- start
) ;
1496 val
.insert( start
, str
) ;
1497 SetStringValue( val
) ;
1498 SetSelection( start
+ str
.length() , start
+ str
.length() ) ;
1504 // ----------------------------------------------------------------------------
1505 // MLTE control implementation (common part)
1506 // ----------------------------------------------------------------------------
1508 // if MTLE is read only, no changes at all are allowed, not even from
1509 // procedural API, in order to allow changes via API all the same we must undo
1510 // the readonly status while we are executing, this class helps to do so
1512 class wxMacEditHelper
1515 wxMacEditHelper( TXNObject txn
)
1517 TXNControlTag tag
[] = { kTXNIOPrivilegesTag
} ;
1519 TXNGetTXNObjectControls( m_txn
, 1 , tag
, m_data
) ;
1520 if ( m_data
[0].uValue
== kTXNReadOnly
)
1522 TXNControlData data
[] = { { kTXNReadWrite
} } ;
1523 TXNSetTXNObjectControls( m_txn
, false , 1 , tag
, data
) ;
1529 TXNControlTag tag
[] = { kTXNIOPrivilegesTag
} ;
1530 if ( m_data
[0].uValue
== kTXNReadOnly
)
1531 TXNSetTXNObjectControls( m_txn
, false , 1 , tag
, m_data
) ;
1536 TXNControlData m_data
[1] ;
1539 wxMacMLTEControl::wxMacMLTEControl( wxTextCtrl
*peer
)
1540 : wxMacTextControl( peer
)
1542 SetNeedsFocusRect( true ) ;
1545 wxString
wxMacMLTEControl::GetStringValue() const
1549 Size actualSize
= 0;
1554 err
= TXNGetDataEncoded( m_txn
, kTXNStartOffset
, kTXNEndOffset
, &theText
, kTXNUnicodeTextData
);
1563 actualSize
= GetHandleSize( theText
) / sizeof(UniChar
) ;
1564 if ( actualSize
> 0 )
1566 wxChar
*ptr
= NULL
;
1568 #if SIZEOF_WCHAR_T == 2
1569 ptr
= new wxChar
[actualSize
+ 1] ;
1570 wxStrncpy( ptr
, (wxChar
*)(*theText
) , actualSize
) ;
1572 SetHandleSize( theText
, (actualSize
+ 1) * sizeof(UniChar
) ) ;
1574 (((UniChar
*)*theText
)[actualSize
]) = 0 ;
1575 wxMBConvUTF16 converter
;
1576 size_t noChars
= converter
.MB2WC( NULL
, (const char*)*theText
, 0 ) ;
1577 ptr
= new wxChar
[noChars
+ 1] ;
1579 noChars
= converter
.MB2WC( ptr
, (const char*)*theText
, noChars
) ;
1581 HUnlock( theText
) ;
1584 ptr
[actualSize
] = 0 ;
1585 result
= wxString( ptr
) ;
1589 DisposeHandle( theText
) ;
1593 err
= TXNGetDataEncoded( m_txn
, kTXNStartOffset
, kTXNEndOffset
, &theText
, kTXNTextData
);
1602 actualSize
= GetHandleSize( theText
) ;
1603 if ( actualSize
> 0 )
1606 result
= wxString( *theText
, wxConvLocal
, actualSize
) ;
1607 HUnlock( theText
) ;
1610 DisposeHandle( theText
) ;
1616 wxMacConvertNewlines13To10( &result
) ;
1618 wxMacConvertNewlines10To13( &result
) ;
1624 void wxMacMLTEControl::SetStringValue( const wxString
&str
)
1627 wxMacConvertNewlines10To13( &st
);
1630 wxMacWindowClipper
c( m_peer
);
1633 wxMacEditHelper
help( m_txn
);
1634 SetTXNData( st
, kTXNStartOffset
, kTXNEndOffset
);
1637 TXNSetSelection( m_txn
, 0, 0 );
1638 TXNShowSelection( m_txn
, kTXNShowStart
);
1642 TXNFrameOptions
wxMacMLTEControl::FrameOptionsFromWXStyle( long wxStyle
)
1644 TXNFrameOptions frameOptions
= kTXNDontDrawCaretWhenInactiveMask
;
1646 #if MAC_OS_X_VERSION_MAX_ALLOWED >= MAC_OS_X_VERSION_10_3
1647 frameOptions
|= kTXNDoFontSubstitutionMask
;
1650 if ( ! (wxStyle
& wxTE_NOHIDESEL
) )
1651 frameOptions
|= kTXNDontDrawSelectionWhenInactiveMask
;
1653 if ( wxStyle
& (wxHSCROLL
| wxTE_DONTWRAP
) )
1654 frameOptions
|= kTXNWantHScrollBarMask
;
1656 if ( wxStyle
& wxTE_MULTILINE
)
1658 frameOptions
|= kTXNAlwaysWrapAtViewEdgeMask
;
1660 if ( !(wxStyle
& wxTE_NO_VSCROLL
) )
1662 frameOptions
|= kTXNWantVScrollBarMask
;
1664 // The following code causes drawing problems on 10.4. Perhaps it can be restored for
1665 // older versions of the OS, but I'm not sure it's appropriate to put a grow icon here
1666 // anyways, as AFAIK users can't actually use it to resize the text ctrl.
1667 // if ( frameOptions & kTXNWantHScrollBarMask )
1668 // frameOptions |= kTXNDrawGrowIconMask ;
1673 frameOptions
|= kTXNSingleLineOnlyMask
;
1676 return frameOptions
;
1679 void wxMacMLTEControl::AdjustCreationAttributes( const wxColour
&background
, bool visible
)
1681 TXNControlTag iControlTags
[] =
1683 kTXNDoFontSubstitution
,
1684 kTXNWordWrapStateTag
,
1686 TXNControlData iControlData
[] =
1692 int toptag
= WXSIZEOF( iControlTags
) ;
1694 if ( m_windowStyle
& wxTE_MULTILINE
)
1696 iControlData
[1].uValue
=
1697 (m_windowStyle
& wxTE_DONTWRAP
)
1702 OSStatus err
= TXNSetTXNObjectControls( m_txn
, false, toptag
, iControlTags
, iControlData
) ;
1703 verify_noerr( err
);
1705 // setting the default font:
1706 // under 10.2 this causes a visible caret, therefore we avoid it
1708 if ( UMAGetSystemVersion() >= 0x1030 )
1714 GetThemeFont( kThemeSystemFont
, GetApplicationScript() , fontName
, &fontSize
, &fontStyle
) ;
1716 TXNTypeAttributes typeAttr
[] =
1718 { kTXNQDFontNameAttribute
, kTXNQDFontNameAttributeSize
, { (void*) fontName
} } ,
1719 { kTXNQDFontSizeAttribute
, kTXNFontSizeAttributeSize
, { (void*) (fontSize
<< 16) } } ,
1720 { kTXNQDFontStyleAttribute
, kTXNQDFontStyleAttributeSize
, { (void*) normal
} } ,
1723 err
= TXNSetTypeAttributes(
1724 m_txn
, sizeof(typeAttr
) / sizeof(TXNTypeAttributes
),
1725 typeAttr
, kTXNStartOffset
, kTXNEndOffset
);
1726 verify_noerr( err
);
1729 if ( m_windowStyle
& wxTE_PASSWORD
)
1731 UniChar c
= 0x00A5 ;
1732 err
= TXNEchoMode( m_txn
, c
, 0 , true );
1733 verify_noerr( err
);
1736 TXNBackground tback
;
1737 tback
.bgType
= kTXNBackgroundTypeRGB
;
1738 tback
.bg
.color
= MAC_WXCOLORREF( background
.GetPixel() );
1739 TXNSetBackground( m_txn
, &tback
);
1741 #if MAC_OS_X_VERSION_MAX_ALLOWED >= MAC_OS_X_VERSION_10_4
1742 if ( UMAGetSystemVersion() >= 0x1040 )
1744 TXNCommandEventSupportOptions options
;
1745 if ( TXNGetCommandEventSupport( m_txn
, &options
) == noErr
)
1748 kTXNSupportEditCommandProcessing
1749 | kTXNSupportEditCommandUpdating
1750 | kTXNSupportSpellCheckCommandProcessing
1751 | kTXNSupportSpellCheckCommandUpdating
1752 | kTXNSupportFontCommandProcessing
1753 | kTXNSupportFontCommandUpdating
;
1755 TXNSetCommandEventSupport( m_txn
, options
) ;
1761 void wxMacMLTEControl::SetBackground( const wxBrush
&brush
)
1763 // currently only solid background are supported
1764 TXNBackground tback
;
1766 tback
.bgType
= kTXNBackgroundTypeRGB
;
1767 tback
.bg
.color
= MAC_WXCOLORREF( brush
.GetColour().GetPixel() );
1768 TXNSetBackground( m_txn
, &tback
);
1771 void wxMacMLTEControl::TXNSetAttribute( const wxTextAttr
& style
, long from
, long to
)
1773 TXNTypeAttributes typeAttr
[4] ;
1774 Str255 fontName
= "\pMonaco" ;
1775 SInt16 fontSize
= 12 ;
1776 Style fontStyle
= normal
;
1780 if ( style
.HasFont() )
1782 const wxFont
&font
= style
.GetFont() ;
1783 wxMacStringToPascal( font
.GetFaceName() , fontName
) ;
1784 fontSize
= font
.GetPointSize() ;
1785 if ( font
.GetUnderlined() )
1786 fontStyle
|= underline
;
1787 if ( font
.GetWeight() == wxBOLD
)
1789 if ( font
.GetStyle() == wxITALIC
)
1790 fontStyle
|= italic
;
1792 typeAttr
[attrCount
].tag
= kTXNQDFontNameAttribute
;
1793 typeAttr
[attrCount
].size
= kTXNQDFontNameAttributeSize
;
1794 typeAttr
[attrCount
].data
.dataPtr
= (void*)fontName
;
1797 typeAttr
[attrCount
].tag
= kTXNQDFontSizeAttribute
;
1798 typeAttr
[attrCount
].size
= kTXNFontSizeAttributeSize
;
1799 typeAttr
[attrCount
].data
.dataValue
= (fontSize
<< 16) ;
1802 typeAttr
[attrCount
].tag
= kTXNQDFontStyleAttribute
;
1803 typeAttr
[attrCount
].size
= kTXNQDFontStyleAttributeSize
;
1804 typeAttr
[attrCount
].data
.dataValue
= fontStyle
;
1808 if ( style
.HasTextColour() )
1810 color
= MAC_WXCOLORREF(style
.GetTextColour().GetPixel()) ;
1812 typeAttr
[attrCount
].tag
= kTXNQDFontColorAttribute
;
1813 typeAttr
[attrCount
].size
= kTXNQDFontColorAttributeSize
;
1814 typeAttr
[attrCount
].data
.dataPtr
= (void*) &color
;
1818 if ( attrCount
> 0 )
1820 verify_noerr( TXNSetTypeAttributes( m_txn
, attrCount
, typeAttr
, from
, to
) );
1824 void wxMacMLTEControl::SetFont( const wxFont
& font
, const wxColour
& foreground
, long windowStyle
)
1826 wxMacEditHelper
help( m_txn
) ;
1827 TXNSetAttribute( wxTextAttr( foreground
, wxNullColour
, font
), kTXNStartOffset
, kTXNEndOffset
) ;
1830 void wxMacMLTEControl::SetStyle( long start
, long end
, const wxTextAttr
& style
)
1832 wxMacEditHelper
help( m_txn
) ;
1833 TXNSetAttribute( style
, start
, end
) ;
1836 void wxMacMLTEControl::Copy()
1838 ClearCurrentScrap();
1840 TXNConvertToPublicScrap();
1843 void wxMacMLTEControl::Cut()
1845 ClearCurrentScrap();
1847 TXNConvertToPublicScrap();
1850 void wxMacMLTEControl::Paste()
1852 TXNConvertFromPublicScrap();
1856 bool wxMacMLTEControl::CanPaste() const
1858 return TXNIsScrapPastable() ;
1861 void wxMacMLTEControl::SetEditable(bool editable
)
1863 TXNControlTag tag
[] = { kTXNIOPrivilegesTag
} ;
1864 TXNControlData data
[] = { { editable
? kTXNReadWrite
: kTXNReadOnly
} } ;
1865 TXNSetTXNObjectControls( m_txn
, false, WXSIZEOF(tag
), tag
, data
) ;
1868 wxTextPos
wxMacMLTEControl::GetLastPosition() const
1870 wxTextPos actualsize
= 0 ;
1873 OSErr err
= TXNGetDataEncoded( m_txn
, kTXNStartOffset
, kTXNEndOffset
, &theText
, kTXNTextData
);
1878 actualsize
= GetHandleSize( theText
) ;
1879 DisposeHandle( theText
) ;
1889 void wxMacMLTEControl::Replace( long from
, long to
, const wxString
&str
)
1891 wxString value
= str
;
1892 wxMacConvertNewlines10To13( &value
) ;
1894 wxMacEditHelper
help( m_txn
) ;
1895 wxMacWindowClipper
c( m_peer
) ;
1897 TXNSetSelection( m_txn
, from
, to
) ;
1899 SetTXNData( value
, kTXNUseCurrentSelection
, kTXNUseCurrentSelection
) ;
1902 void wxMacMLTEControl::Remove( long from
, long to
)
1904 wxMacWindowClipper
c( m_peer
) ;
1905 wxMacEditHelper
help( m_txn
) ;
1906 TXNSetSelection( m_txn
, from
, to
) ;
1910 void wxMacMLTEControl::GetSelection( long* from
, long* to
) const
1912 TXNGetSelection( m_txn
, (TXNOffset
*) from
, (TXNOffset
*) to
) ;
1915 void wxMacMLTEControl::SetSelection( long from
, long to
)
1917 wxMacWindowClipper
c( m_peer
) ;
1919 // change the selection
1920 if ((from
== -1) && (to
== -1))
1921 TXNSelectAll( m_txn
);
1923 TXNSetSelection( m_txn
, from
, to
);
1925 TXNShowSelection( m_txn
, kTXNShowStart
);
1928 void wxMacMLTEControl::WriteText( const wxString
& str
)
1931 wxMacConvertNewlines10To13( &st
) ;
1933 long start
, end
, dummy
;
1935 GetSelection( &start
, &dummy
) ;
1936 wxMacWindowClipper
c( m_peer
) ;
1939 wxMacEditHelper
helper( m_txn
) ;
1940 SetTXNData( st
, kTXNUseCurrentSelection
, kTXNUseCurrentSelection
) ;
1943 GetSelection( &dummy
, &end
) ;
1945 // TODO: SetStyle( start , end , GetDefaultStyle() ) ;
1948 void wxMacMLTEControl::Clear()
1950 wxMacWindowClipper
c( m_peer
) ;
1951 wxMacEditHelper
st( m_txn
) ;
1952 TXNSetSelection( m_txn
, kTXNStartOffset
, kTXNEndOffset
) ;
1956 bool wxMacMLTEControl::CanUndo() const
1958 return TXNCanUndo( m_txn
, NULL
) ;
1961 void wxMacMLTEControl::Undo()
1966 bool wxMacMLTEControl::CanRedo() const
1968 return TXNCanRedo( m_txn
, NULL
) ;
1971 void wxMacMLTEControl::Redo()
1976 int wxMacMLTEControl::GetNumberOfLines() const
1978 ItemCount lines
= 0 ;
1979 TXNGetLineCount( m_txn
, &lines
) ;
1984 long wxMacMLTEControl::XYToPosition(long x
, long y
) const
1989 // TODO: find a better implementation : while we can get the
1990 // line metrics of a certain line, we don't get its starting
1991 // position, so it would probably be rather a binary search
1992 // for the start position
1993 long xpos
= 0, ypos
= 0 ;
1994 int lastHeight
= 0 ;
1997 lastpos
= GetLastPosition() ;
1998 for ( n
= 0 ; n
<= (ItemCount
) lastpos
; ++n
)
2000 if ( y
== ypos
&& x
== xpos
)
2003 TXNOffsetToPoint( m_txn
, n
, &curpt
) ;
2005 if ( curpt
.v
> lastHeight
)
2011 lastHeight
= curpt
.v
;
2020 bool wxMacMLTEControl::PositionToXY( long pos
, long *x
, long *y
) const
2030 lastpos
= GetLastPosition() ;
2031 if ( pos
<= lastpos
)
2033 // TODO: find a better implementation - while we can get the
2034 // line metrics of a certain line, we don't get its starting
2035 // position, so it would probably be rather a binary search
2036 // for the start position
2037 long xpos
= 0, ypos
= 0 ;
2038 int lastHeight
= 0 ;
2041 for ( n
= 0 ; n
<= (ItemCount
) pos
; ++n
)
2043 TXNOffsetToPoint( m_txn
, n
, &curpt
) ;
2045 if ( curpt
.v
> lastHeight
)
2051 lastHeight
= curpt
.v
;
2066 void wxMacMLTEControl::ShowPosition( long pos
)
2068 #if TARGET_RT_MAC_MACHO && defined(AVAILABLE_MAC_OS_X_VERSION_10_2_AND_LATER)
2070 Point current
, desired
;
2071 TXNOffset selstart
, selend
;
2073 TXNGetSelection( m_txn
, &selstart
, &selend
);
2074 TXNOffsetToPoint( m_txn
, selstart
, ¤t
);
2075 TXNOffsetToPoint( m_txn
, pos
, &desired
);
2077 // TODO: use HIPoints for 10.3 and above
2078 if ( (UInt32
)TXNScroll
!= (UInt32
)kUnresolvedCFragSymbolAddress
)
2080 OSErr theErr
= noErr
;
2081 SInt32 dv
= desired
.v
- current
.v
;
2082 SInt32 dh
= desired
.h
- current
.h
;
2083 TXNShowSelection( m_txn
, kTXNShowStart
) ; // NB: should this be kTXNShowStart or kTXNShowEnd ??
2084 theErr
= TXNScroll( m_txn
, kTXNScrollUnitsInPixels
, kTXNScrollUnitsInPixels
, &dv
, &dh
);
2086 // there will be an error returned for classic MLTE implementation when the control is
2087 // invisible, but HITextView works correctly, so we don't assert that one
2088 // wxASSERT_MSG( theErr == noErr, _T("TXNScroll returned an error!") );
2094 void wxMacMLTEControl::SetTXNData( const wxString
& st
, TXNOffset start
, TXNOffset end
)
2097 #if SIZEOF_WCHAR_T == 2
2098 size_t len
= st
.Len() ;
2099 TXNSetData( m_txn
, kTXNUnicodeTextData
, (void*)st
.wc_str(), len
* 2, start
, end
);
2101 wxMBConvUTF16 converter
;
2102 ByteCount byteBufferLen
= converter
.WC2MB( NULL
, st
.wc_str(), 0 ) ;
2103 UniChar
*unibuf
= (UniChar
*)malloc( byteBufferLen
) ;
2104 converter
.WC2MB( (char*)unibuf
, st
.wc_str(), byteBufferLen
) ;
2105 TXNSetData( m_txn
, kTXNUnicodeTextData
, (void*)unibuf
, byteBufferLen
, start
, end
) ;
2109 wxCharBuffer text
= st
.mb_str( wxConvLocal
) ;
2110 TXNSetData( m_txn
, kTXNTextData
, (void*)text
.data(), strlen( text
), start
, end
) ;
2114 wxString
wxMacMLTEControl::GetLineText(long lineNo
) const
2118 if ( lineNo
< GetNumberOfLines() )
2121 Fixed lineWidth
, lineHeight
, currentHeight
;
2124 // get the first possible position in the control
2125 TXNOffsetToPoint(m_txn
, 0, &firstPoint
);
2127 // Iterate through the lines until we reach the one we want,
2128 // adding to our current y pixel point position
2131 while (ypos
< lineNo
)
2133 TXNGetLineMetrics(m_txn
, ypos
++, &lineWidth
, &lineHeight
);
2134 currentHeight
+= lineHeight
;
2137 Point thePoint
= { firstPoint
.v
+ (currentHeight
>> 16), firstPoint
.h
+ (0) };
2138 TXNOffset theOffset
;
2139 TXNPointToOffset(m_txn
, thePoint
, &theOffset
);
2141 wxString content
= GetStringValue() ;
2142 Point currentPoint
= thePoint
;
2143 while (thePoint
.v
== currentPoint
.v
&& theOffset
< content
.length())
2145 line
+= content
[theOffset
];
2146 TXNOffsetToPoint(m_txn
, ++theOffset
, ¤tPoint
);
2153 int wxMacMLTEControl::GetLineLength(long lineNo
) const
2157 if ( lineNo
< GetNumberOfLines() )
2160 Fixed lineWidth
, lineHeight
, currentHeight
;
2163 // get the first possible position in the control
2164 TXNOffsetToPoint(m_txn
, 0, &firstPoint
);
2166 // Iterate through the lines until we reach the one we want,
2167 // adding to our current y pixel point position
2170 while (ypos
< lineNo
)
2172 TXNGetLineMetrics(m_txn
, ypos
++, &lineWidth
, &lineHeight
);
2173 currentHeight
+= lineHeight
;
2176 Point thePoint
= { firstPoint
.v
+ (currentHeight
>> 16), firstPoint
.h
+ (0) };
2177 TXNOffset theOffset
;
2178 TXNPointToOffset(m_txn
, thePoint
, &theOffset
);
2180 wxString content
= GetStringValue() ;
2181 Point currentPoint
= thePoint
;
2182 while (thePoint
.v
== currentPoint
.v
&& theOffset
< content
.length())
2185 TXNOffsetToPoint(m_txn
, ++theOffset
, ¤tPoint
);
2192 // ----------------------------------------------------------------------------
2193 // MLTE control implementation (classic part)
2194 // ----------------------------------------------------------------------------
2196 // OS X Notes : We still don't have a full replacement for MLTE, so this implementation
2197 // has to live on. We have different problems coming from outdated implementations on the
2198 // various OS X versions. Most deal with the scrollbars: they are not correctly embedded
2199 // while this can be solved on 10.3 by reassigning them the correct place, on 10.2 there is
2200 // no way out, therefore we are using our own implementation and our own scrollbars ....
2202 #ifdef __WXMAC_OSX__
2204 TXNScrollInfoUPP gTXNScrollInfoProc
= NULL
;
2205 ControlActionUPP gTXNScrollActionProc
= NULL
;
2207 pascal void wxMacMLTEClassicControl::TXNScrollInfoProc(
2208 SInt32 iValue
, SInt32 iMaximumValue
,
2209 TXNScrollBarOrientation iScrollBarOrientation
, SInt32 iRefCon
)
2211 wxMacMLTEClassicControl
* mlte
= (wxMacMLTEClassicControl
*) iRefCon
;
2212 SInt32 value
= wxMax( iValue
, 0 ) ;
2213 SInt32 maximum
= wxMax( iMaximumValue
, 0 ) ;
2215 if ( iScrollBarOrientation
== kTXNHorizontal
)
2217 if ( mlte
->m_sbHorizontal
)
2219 SetControl32BitValue( mlte
->m_sbHorizontal
, value
) ;
2220 SetControl32BitMaximum( mlte
->m_sbHorizontal
, maximum
) ;
2221 mlte
->m_lastHorizontalValue
= value
;
2224 else if ( iScrollBarOrientation
== kTXNVertical
)
2226 if ( mlte
->m_sbVertical
)
2228 SetControl32BitValue( mlte
->m_sbVertical
, value
) ;
2229 SetControl32BitMaximum( mlte
->m_sbVertical
, maximum
) ;
2230 mlte
->m_lastVerticalValue
= value
;
2235 pascal void wxMacMLTEClassicControl::TXNScrollActionProc( ControlRef controlRef
, ControlPartCode partCode
)
2237 wxMacMLTEClassicControl
* mlte
= (wxMacMLTEClassicControl
*) GetControlReference( controlRef
) ;
2241 if ( controlRef
!= mlte
->m_sbVertical
&& controlRef
!= mlte
->m_sbHorizontal
)
2245 bool isHorizontal
= ( controlRef
== mlte
->m_sbHorizontal
) ;
2247 SInt32 minimum
= 0 ;
2248 SInt32 maximum
= GetControl32BitMaximum( controlRef
) ;
2249 SInt32 value
= GetControl32BitValue( controlRef
) ;
2254 case kControlDownButtonPart
:
2258 case kControlUpButtonPart
:
2262 case kControlPageDownPart
:
2263 delta
= GetControlViewSize( controlRef
) ;
2266 case kControlPageUpPart
:
2267 delta
= -GetControlViewSize( controlRef
) ;
2270 case kControlIndicatorPart
:
2271 delta
= value
- (isHorizontal
? mlte
->m_lastHorizontalValue
: mlte
->m_lastVerticalValue
) ;
2280 SInt32 newValue
= value
;
2282 if ( partCode
!= kControlIndicatorPart
)
2284 if ( value
+ delta
< minimum
)
2285 delta
= minimum
- value
;
2286 if ( value
+ delta
> maximum
)
2287 delta
= maximum
- value
;
2289 SetControl32BitValue( controlRef
, value
+ delta
) ;
2290 newValue
= value
+ delta
;
2293 SInt32 verticalDelta
= isHorizontal
? 0 : delta
;
2294 SInt32 horizontalDelta
= isHorizontal
? delta
: 0 ;
2297 mlte
->m_txn
, kTXNScrollUnitsInPixels
, kTXNScrollUnitsInPixels
,
2298 &verticalDelta
, &horizontalDelta
);
2299 verify_noerr( err
);
2302 mlte
->m_lastHorizontalValue
= newValue
;
2304 mlte
->m_lastVerticalValue
= newValue
;
2309 // make correct activations
2310 void wxMacMLTEClassicControl::MacActivatePaneText(bool setActive
)
2312 wxTextCtrl
* textctrl
= (wxTextCtrl
*) GetControlReference(m_controlRef
);
2314 wxMacWindowClipper
clipper( textctrl
) ;
2315 TXNActivate( m_txn
, m_txnFrameID
, setActive
);
2317 ControlRef controlFocus
= 0 ;
2318 GetKeyboardFocus( m_txnWindow
, &controlFocus
) ;
2319 if ( controlFocus
== m_controlRef
)
2320 TXNFocus( m_txn
, setActive
);
2323 void wxMacMLTEClassicControl::MacFocusPaneText(bool setFocus
)
2325 TXNFocus( m_txn
, setFocus
);
2328 // guards against inappropriate redraw (hidden objects drawing onto window)
2330 void wxMacMLTEClassicControl::MacSetObjectVisibility(bool vis
)
2332 ControlRef controlFocus
= 0 ;
2333 GetKeyboardFocus( m_txnWindow
, &controlFocus
) ;
2335 if ( !vis
&& (controlFocus
== m_controlRef
) )
2336 SetKeyboardFocus( m_txnWindow
, m_controlRef
, kControlFocusNoPart
) ;
2338 TXNControlTag iControlTags
[1] = { kTXNVisibilityTag
};
2339 TXNControlData iControlData
[1] = { { (UInt32
)false } };
2341 verify_noerr( TXNGetTXNObjectControls( m_txn
, 1, iControlTags
, iControlData
) ) ;
2343 if ( iControlData
[0].uValue
!= vis
)
2345 iControlData
[0].uValue
= vis
;
2346 verify_noerr( TXNSetTXNObjectControls( m_txn
, false , 1, iControlTags
, iControlData
) ) ;
2349 // currently, we always clip as partial visibility (overlapped) visibility is also a problem,
2350 // if we run into further problems we might set the FrameBounds to an empty rect here
2353 // make sure that the TXNObject is at the right position
2355 void wxMacMLTEClassicControl::MacUpdatePosition()
2357 wxTextCtrl
* textctrl
= (wxTextCtrl
*)GetControlReference( m_controlRef
);
2358 if ( textctrl
== NULL
)
2362 UMAGetControlBoundsInWindowCoords( m_controlRef
, &bounds
);
2364 wxRect visRect
= textctrl
->MacGetClippedClientRect() ;
2365 Rect visBounds
= { visRect
.y
, visRect
.x
, visRect
.y
+ visRect
.height
, visRect
.x
+ visRect
.width
} ;
2368 textctrl
->MacWindowToRootWindow( &x
, &y
) ;
2369 OffsetRect( &visBounds
, x
, y
) ;
2371 if ( !EqualRect( &bounds
, &m_txnControlBounds
) || !EqualRect( &visBounds
, &m_txnVisBounds
) )
2373 m_txnControlBounds
= bounds
;
2374 m_txnVisBounds
= visBounds
;
2375 wxMacWindowClipper
cl( textctrl
) ;
2377 #ifdef __WXMAC_OSX__
2378 bool isCompositing
= textctrl
->MacGetTopLevelWindow()->MacUsesCompositing() ;
2379 if ( m_sbHorizontal
|| m_sbVertical
)
2381 int w
= bounds
.right
- bounds
.left
;
2382 int h
= bounds
.bottom
- bounds
.top
;
2384 if ( m_sbHorizontal
)
2388 sbBounds
.left
= -1 ;
2389 sbBounds
.top
= h
- 14 ;
2390 sbBounds
.right
= w
+ 1 ;
2391 sbBounds
.bottom
= h
+ 1 ;
2393 if ( !isCompositing
)
2394 OffsetRect( &sbBounds
, m_txnControlBounds
.left
, m_txnControlBounds
.top
) ;
2396 SetControlBounds( m_sbHorizontal
, &sbBounds
) ;
2397 SetControlViewSize( m_sbHorizontal
, w
) ;
2404 sbBounds
.left
= w
- 14 ;
2406 sbBounds
.right
= w
+ 1 ;
2407 sbBounds
.bottom
= m_sbHorizontal
? h
- 14 : h
+ 1 ;
2409 if ( !isCompositing
)
2410 OffsetRect( &sbBounds
, m_txnControlBounds
.left
, m_txnControlBounds
.top
) ;
2412 SetControlBounds( m_sbVertical
, &sbBounds
) ;
2413 SetControlViewSize( m_sbVertical
, h
) ;
2418 TXNLongRect olddestRect
;
2419 TXNGetRectBounds( m_txn
, &oldviewRect
, &olddestRect
, NULL
) ;
2421 Rect viewRect
= { m_txnControlBounds
.top
, m_txnControlBounds
.left
,
2422 m_txnControlBounds
.bottom
- ( m_sbHorizontal
? 14 : 0 ) ,
2423 m_txnControlBounds
.right
- ( m_sbVertical
? 14 : 0 ) } ;
2424 TXNLongRect destRect
= { m_txnControlBounds
.top
, m_txnControlBounds
.left
,
2425 m_txnControlBounds
.bottom
- ( m_sbHorizontal
? 14 : 0 ) ,
2426 m_txnControlBounds
.right
- ( m_sbVertical
? 14 : 0 ) } ;
2428 if ( olddestRect
.right
>= 10000 )
2429 destRect
.right
= destRect
.left
+ 32000 ;
2431 if ( olddestRect
.bottom
>= 0x20000000 )
2432 destRect
.bottom
= destRect
.top
+ 0x40000000 ;
2434 SectRect( &viewRect
, &visBounds
, &viewRect
) ;
2435 TXNSetRectBounds( m_txn
, &viewRect
, &destRect
, true ) ;
2440 m_txnControlBounds
.top
,
2441 m_txnControlBounds
.left
,
2442 m_txnControlBounds
.bottom
- (m_sbHorizontal
? 14 : 0),
2443 m_txnControlBounds
.right
- (m_sbVertical
? 14 : 0),
2449 m_txn
, m_txnControlBounds
.top
, m_txnControlBounds
.left
,
2450 wxMax( m_txnControlBounds
.bottom
, m_txnControlBounds
.top
),
2451 wxMax( m_txnControlBounds
.right
, m_txnControlBounds
.left
), m_txnFrameID
);
2454 // the SetFrameBounds method under Classic sometimes does not correctly scroll a selection into sight after a
2455 // movement, therefore we have to force it
2457 // this problem has been reported in OSX as well, so we use this here once again
2459 TXNLongRect textRect
;
2460 TXNGetRectBounds( m_txn
, NULL
, NULL
, &textRect
) ;
2461 if ( textRect
.left
< m_txnControlBounds
.left
)
2462 TXNShowSelection( m_txn
, kTXNShowStart
) ;
2466 void wxMacMLTEClassicControl::SetRect( Rect
*r
)
2468 wxMacControl::SetRect( r
) ;
2469 MacUpdatePosition() ;
2472 void wxMacMLTEClassicControl::MacControlUserPaneDrawProc(wxInt16 thePart
)
2474 wxTextCtrl
* textctrl
= (wxTextCtrl
*)GetControlReference( m_controlRef
);
2475 if ( textctrl
== NULL
)
2478 if ( textctrl
->MacIsReallyShown() )
2480 wxMacWindowClipper
clipper( textctrl
) ;
2481 TXNDraw( m_txn
, NULL
) ;
2485 wxInt16
wxMacMLTEClassicControl::MacControlUserPaneHitTestProc(wxInt16 x
, wxInt16 y
)
2487 Point where
= { y
, x
} ;
2488 ControlPartCode result
= kControlNoPart
;
2490 wxTextCtrl
* textctrl
= (wxTextCtrl
*) GetControlReference( m_controlRef
);
2491 if ( (textctrl
!= NULL
) && textctrl
->MacIsReallyShown() )
2493 if (PtInRect( where
, &m_txnControlBounds
))
2495 result
= kControlEditTextPart
;
2499 // sometimes we get the coords also in control local coordinates, therefore test again
2500 if ( textctrl
->MacGetTopLevelWindow()->MacUsesCompositing() )
2503 textctrl
->MacClientToRootWindow( &x
, &y
) ;
2508 if (PtInRect( where
, &m_txnControlBounds
))
2509 result
= kControlEditTextPart
;
2516 wxInt16
wxMacMLTEClassicControl::MacControlUserPaneTrackingProc( wxInt16 x
, wxInt16 y
, void* actionProc
)
2518 ControlPartCode result
= kControlNoPart
;
2520 wxTextCtrl
* textctrl
= (wxTextCtrl
*) GetControlReference( m_controlRef
);
2521 if ( (textctrl
!= NULL
) && textctrl
->MacIsReallyShown() )
2523 Point startPt
= { y
, x
} ;
2524 // for compositing, we must convert these into toplevel window coordinates, because hittesting expects them
2525 if ( textctrl
->MacGetTopLevelWindow()->MacUsesCompositing() )
2528 textctrl
->MacClientToRootWindow( &x
, &y
) ;
2533 switch (MacControlUserPaneHitTestProc( startPt
.h
, startPt
.v
))
2535 case kControlEditTextPart
:
2537 wxMacWindowClipper
clipper( textctrl
) ;
2540 ConvertEventRefToEventRecord( (EventRef
) wxTheApp
->MacGetCurrentEvent() , &rec
) ;
2541 TXNClick( m_txn
, &rec
);
2553 void wxMacMLTEClassicControl::MacControlUserPaneIdleProc()
2555 wxTextCtrl
* textctrl
= (wxTextCtrl
*)GetControlReference( m_controlRef
);
2556 if ( textctrl
== NULL
)
2559 if (textctrl
->MacIsReallyShown())
2561 if (IsControlActive(m_controlRef
))
2565 wxMacWindowClipper
clipper( textctrl
) ;
2570 if (PtInRect(mousep
, &m_txnControlBounds
))
2572 RgnHandle theRgn
= NewRgn();
2573 RectRgn(theRgn
, &m_txnControlBounds
);
2574 TXNAdjustCursor(m_txn
, theRgn
);
2581 wxInt16
wxMacMLTEClassicControl::MacControlUserPaneKeyDownProc (wxInt16 keyCode
, wxInt16 charCode
, wxInt16 modifiers
)
2583 wxTextCtrl
* textctrl
= (wxTextCtrl
*)GetControlReference( m_controlRef
);
2584 if ( textctrl
== NULL
)
2585 return kControlNoPart
;
2587 wxMacWindowClipper
clipper( textctrl
) ;
2590 memset( &ev
, 0 , sizeof( ev
) ) ;
2592 ev
.modifiers
= modifiers
;
2593 ev
.message
= ((keyCode
<< 8) & keyCodeMask
) | (charCode
& charCodeMask
);
2594 TXNKeyDown( m_txn
, &ev
);
2596 return kControlEntireControl
;
2599 void wxMacMLTEClassicControl::MacControlUserPaneActivateProc(bool activating
)
2601 MacActivatePaneText( activating
);
2604 wxInt16
wxMacMLTEClassicControl::MacControlUserPaneFocusProc(wxInt16 action
)
2606 ControlPartCode focusResult
= kControlFocusNoPart
;
2608 wxTextCtrl
* textctrl
= (wxTextCtrl
*)GetControlReference( m_controlRef
);
2609 if ( textctrl
== NULL
)
2612 wxMacWindowClipper
clipper( textctrl
) ;
2614 ControlRef controlFocus
= NULL
;
2615 GetKeyboardFocus( m_txnWindow
, &controlFocus
) ;
2616 bool wasFocused
= ( controlFocus
== m_controlRef
) ;
2620 case kControlFocusPrevPart
:
2621 case kControlFocusNextPart
:
2622 MacFocusPaneText( !wasFocused
);
2623 focusResult
= (!wasFocused
? (ControlPartCode
) kControlEditTextPart
: (ControlPartCode
) kControlFocusNoPart
);
2626 case kControlFocusNoPart
:
2628 MacFocusPaneText( false );
2629 focusResult
= kControlFocusNoPart
;
2636 void wxMacMLTEClassicControl::MacControlUserPaneBackgroundProc( void *info
)
2640 wxMacMLTEClassicControl::wxMacMLTEClassicControl( wxTextCtrl
*wxPeer
,
2641 const wxString
& str
,
2643 const wxSize
& size
, long style
)
2644 : wxMacMLTEControl( wxPeer
)
2646 m_font
= wxPeer
->GetFont() ;
2647 m_windowStyle
= style
;
2648 Rect bounds
= wxMacGetBoundsForControl( wxPeer
, pos
, size
) ;
2651 kControlSupportsEmbedding
| kControlSupportsFocus
| kControlWantsIdle
2652 | kControlWantsActivate
| kControlHandlesTracking
2653 // | kControlHasSpecialBackground
2654 | kControlGetsFocusOnClick
| kControlSupportsLiveFeedback
;
2656 OSStatus err
= ::CreateUserPaneControl(
2657 MAC_WXHWND(wxPeer
->GetParent()->MacGetTopLevelWindowRef()),
2658 &bounds
, featureSet
, &m_controlRef
);
2659 verify_noerr( err
);
2663 AdjustCreationAttributes( *wxWHITE
, true ) ;
2665 MacSetObjectVisibility( wxPeer
->MacIsReallyShown() ) ;
2669 wxMacConvertNewlines10To13( &st
) ;
2670 wxMacWindowClipper
clipper( m_peer
) ;
2671 SetTXNData( st
, kTXNStartOffset
, kTXNEndOffset
) ;
2672 TXNSetSelection( m_txn
, 0, 0 ) ;
2676 wxMacMLTEClassicControl::~wxMacMLTEClassicControl()
2678 TXNDeleteObject( m_txn
);
2682 void wxMacMLTEClassicControl::VisibilityChanged(bool shown
)
2684 MacSetObjectVisibility( shown
) ;
2685 wxMacControl::VisibilityChanged( shown
) ;
2688 void wxMacMLTEClassicControl::SuperChangedPosition()
2690 MacUpdatePosition() ;
2691 wxMacControl::SuperChangedPosition() ;
2694 #ifdef __WXMAC_OSX__
2696 ControlUserPaneDrawUPP gTPDrawProc
= NULL
;
2697 ControlUserPaneHitTestUPP gTPHitProc
= NULL
;
2698 ControlUserPaneTrackingUPP gTPTrackProc
= NULL
;
2699 ControlUserPaneIdleUPP gTPIdleProc
= NULL
;
2700 ControlUserPaneKeyDownUPP gTPKeyProc
= NULL
;
2701 ControlUserPaneActivateUPP gTPActivateProc
= NULL
;
2702 ControlUserPaneFocusUPP gTPFocusProc
= NULL
;
2704 static pascal void wxMacControlUserPaneDrawProc(ControlRef control
, SInt16 part
)
2706 wxTextCtrl
*textCtrl
= wxDynamicCast( wxFindControlFromMacControl(control
) , wxTextCtrl
) ;
2707 wxMacMLTEClassicControl
* win
= textCtrl
? (wxMacMLTEClassicControl
*)(textCtrl
->GetPeer()) : NULL
;
2709 win
->MacControlUserPaneDrawProc( part
) ;
2712 static pascal ControlPartCode
wxMacControlUserPaneHitTestProc(ControlRef control
, Point where
)
2714 wxTextCtrl
*textCtrl
= wxDynamicCast( wxFindControlFromMacControl(control
) , wxTextCtrl
) ;
2715 wxMacMLTEClassicControl
* win
= textCtrl
? (wxMacMLTEClassicControl
*)(textCtrl
->GetPeer()) : NULL
;
2717 return win
->MacControlUserPaneHitTestProc( where
.h
, where
.v
) ;
2719 return kControlNoPart
;
2722 static pascal ControlPartCode
wxMacControlUserPaneTrackingProc(ControlRef control
, Point startPt
, ControlActionUPP actionProc
)
2724 wxTextCtrl
*textCtrl
= wxDynamicCast( wxFindControlFromMacControl(control
) , wxTextCtrl
) ;
2725 wxMacMLTEClassicControl
* win
= textCtrl
? (wxMacMLTEClassicControl
*)(textCtrl
->GetPeer()) : NULL
;
2727 return win
->MacControlUserPaneTrackingProc( startPt
.h
, startPt
.v
, (void*) actionProc
) ;
2729 return kControlNoPart
;
2732 static pascal void wxMacControlUserPaneIdleProc(ControlRef control
)
2734 wxTextCtrl
*textCtrl
= wxDynamicCast( wxFindControlFromMacControl(control
) , wxTextCtrl
) ;
2735 wxMacMLTEClassicControl
* win
= textCtrl
? (wxMacMLTEClassicControl
*)(textCtrl
->GetPeer()) : NULL
;
2737 win
->MacControlUserPaneIdleProc() ;
2740 static pascal ControlPartCode
wxMacControlUserPaneKeyDownProc(ControlRef control
, SInt16 keyCode
, SInt16 charCode
, SInt16 modifiers
)
2742 wxTextCtrl
*textCtrl
= wxDynamicCast( wxFindControlFromMacControl(control
) , wxTextCtrl
) ;
2743 wxMacMLTEClassicControl
* win
= textCtrl
? (wxMacMLTEClassicControl
*)(textCtrl
->GetPeer()) : NULL
;
2745 return win
->MacControlUserPaneKeyDownProc( keyCode
, charCode
, modifiers
) ;
2747 return kControlNoPart
;
2750 static pascal void wxMacControlUserPaneActivateProc(ControlRef control
, Boolean activating
)
2752 wxTextCtrl
*textCtrl
= wxDynamicCast( wxFindControlFromMacControl(control
) , wxTextCtrl
) ;
2753 wxMacMLTEClassicControl
* win
= textCtrl
? (wxMacMLTEClassicControl
*)(textCtrl
->GetPeer()) : NULL
;
2755 win
->MacControlUserPaneActivateProc( activating
) ;
2758 static pascal ControlPartCode
wxMacControlUserPaneFocusProc(ControlRef control
, ControlFocusPart action
)
2760 wxTextCtrl
*textCtrl
= wxDynamicCast( wxFindControlFromMacControl(control
) , wxTextCtrl
) ;
2761 wxMacMLTEClassicControl
* win
= textCtrl
? (wxMacMLTEClassicControl
*)(textCtrl
->GetPeer()) : NULL
;
2763 return win
->MacControlUserPaneFocusProc( action
) ;
2765 return kControlNoPart
;
2769 static pascal void wxMacControlUserPaneBackgroundProc(ControlRef control
, ControlBackgroundPtr info
)
2771 wxTextCtrl
*textCtrl
= wxDynamicCast( wxFindControlFromMacControl(control
) , wxTextCtrl
) ;
2772 wxMacMLTEClassicControl
* win
= textCtrl
? (wxMacMLTEClassicControl
*)(textCtrl
->GetPeer()) : NULL
;
2774 win
->MacControlUserPaneBackgroundProc(info
) ;
2778 #endif // __WXMAC_OSX__
2780 // TXNRegisterScrollInfoProc
2782 OSStatus
wxMacMLTEClassicControl::DoCreate()
2785 OSStatus err
= noErr
;
2787 // set up our globals
2788 #ifdef __WXMAC_OSX__
2789 if (gTPDrawProc
== NULL
) gTPDrawProc
= NewControlUserPaneDrawUPP(wxMacControlUserPaneDrawProc
);
2790 if (gTPHitProc
== NULL
) gTPHitProc
= NewControlUserPaneHitTestUPP(wxMacControlUserPaneHitTestProc
);
2791 if (gTPTrackProc
== NULL
) gTPTrackProc
= NewControlUserPaneTrackingUPP(wxMacControlUserPaneTrackingProc
);
2792 if (gTPIdleProc
== NULL
) gTPIdleProc
= NewControlUserPaneIdleUPP(wxMacControlUserPaneIdleProc
);
2793 if (gTPKeyProc
== NULL
) gTPKeyProc
= NewControlUserPaneKeyDownUPP(wxMacControlUserPaneKeyDownProc
);
2794 if (gTPActivateProc
== NULL
) gTPActivateProc
= NewControlUserPaneActivateUPP(wxMacControlUserPaneActivateProc
);
2795 if (gTPFocusProc
== NULL
) gTPFocusProc
= NewControlUserPaneFocusUPP(wxMacControlUserPaneFocusProc
);
2797 if (gTXNScrollInfoProc
== NULL
) gTXNScrollInfoProc
= NewTXNScrollInfoUPP(TXNScrollInfoProc
) ;
2798 if (gTXNScrollActionProc
== NULL
) gTXNScrollActionProc
= NewControlActionUPP(TXNScrollActionProc
) ;
2801 // set the initial settings for our private data
2803 m_txnWindow
= GetControlOwner(m_controlRef
);
2804 m_txnPort
= (GrafPtr
) GetWindowPort(m_txnWindow
);
2806 #ifdef __WXMAC_OSX__
2807 // set up the user pane procedures
2808 SetControlData(m_controlRef
, kControlEntireControl
, kControlUserPaneDrawProcTag
, sizeof(gTPDrawProc
), &gTPDrawProc
);
2809 SetControlData(m_controlRef
, kControlEntireControl
, kControlUserPaneHitTestProcTag
, sizeof(gTPHitProc
), &gTPHitProc
);
2810 SetControlData(m_controlRef
, kControlEntireControl
, kControlUserPaneTrackingProcTag
, sizeof(gTPTrackProc
), &gTPTrackProc
);
2811 SetControlData(m_controlRef
, kControlEntireControl
, kControlUserPaneIdleProcTag
, sizeof(gTPIdleProc
), &gTPIdleProc
);
2812 SetControlData(m_controlRef
, kControlEntireControl
, kControlUserPaneKeyDownProcTag
, sizeof(gTPKeyProc
), &gTPKeyProc
);
2813 SetControlData(m_controlRef
, kControlEntireControl
, kControlUserPaneActivateProcTag
, sizeof(gTPActivateProc
), &gTPActivateProc
);
2814 SetControlData(m_controlRef
, kControlEntireControl
, kControlUserPaneFocusProcTag
, sizeof(gTPFocusProc
), &gTPFocusProc
);
2817 // calculate the rectangles used by the control
2818 UMAGetControlBoundsInWindowCoords( m_controlRef
, &bounds
);
2820 m_txnControlBounds
= bounds
;
2821 m_txnVisBounds
= bounds
;
2826 GetGWorld( &origPort
, &origDev
) ;
2827 SetPort( m_txnPort
);
2829 // create the new edit field
2830 TXNFrameOptions frameOptions
= FrameOptionsFromWXStyle( m_windowStyle
);
2832 #ifdef __WXMAC_OSX__
2833 // the scrollbars are not correctly embedded but are inserted at the root:
2834 // this gives us problems as we have erratic redraws even over the structure area
2836 m_sbHorizontal
= 0 ;
2838 m_lastHorizontalValue
= 0 ;
2839 m_lastVerticalValue
= 0 ;
2841 Rect sb
= { 0 , 0 , 0 , 0 } ;
2842 if ( frameOptions
& kTXNWantVScrollBarMask
)
2844 CreateScrollBarControl( m_txnWindow
, &sb
, 0, 0, 100, 1, true, gTXNScrollActionProc
, &m_sbVertical
);
2845 SetControlReference( m_sbVertical
, (SInt32
)this );
2846 SetControlAction( m_sbVertical
, gTXNScrollActionProc
);
2847 ShowControl( m_sbVertical
);
2848 EmbedControl( m_sbVertical
, m_controlRef
);
2849 frameOptions
&= ~kTXNWantVScrollBarMask
;
2852 if ( frameOptions
& kTXNWantHScrollBarMask
)
2854 CreateScrollBarControl( m_txnWindow
, &sb
, 0, 0, 100, 1, true, gTXNScrollActionProc
, &m_sbHorizontal
);
2855 SetControlReference( m_sbHorizontal
, (SInt32
)this );
2856 SetControlAction( m_sbHorizontal
, gTXNScrollActionProc
);
2857 ShowControl( m_sbHorizontal
);
2858 EmbedControl( m_sbHorizontal
, m_controlRef
);
2859 frameOptions
&= ~(kTXNWantHScrollBarMask
| kTXNDrawGrowIconMask
);
2865 NULL
, m_txnWindow
, &bounds
, frameOptions
,
2866 kTXNTextEditStyleFrameType
, kTXNTextensionFile
, kTXNSystemDefaultEncoding
,
2867 &m_txn
, &m_txnFrameID
, NULL
);
2868 verify_noerr( err
);
2871 TXNControlTag iControlTags
[] = { kTXNUseCarbonEvents
};
2872 TXNControlData iControlData
[] = { { (UInt32
)&cInfo
} };
2873 int toptag
= WXSIZEOF( iControlTags
) ;
2874 TXNCarbonEventInfo cInfo
;
2875 cInfo
.useCarbonEvents
= false ;
2878 cInfo
.fDictionary
= NULL
;
2880 verify_noerr( TXNSetTXNObjectControls( m_txn
, false, toptag
, iControlTags
, iControlData
) );
2883 #ifdef __WXMAC_OSX__
2884 TXNRegisterScrollInfoProc( m_txn
, gTXNScrollInfoProc
, (SInt32
)this );
2887 SetGWorld( origPort
, origDev
) ;
2892 // ----------------------------------------------------------------------------
2893 // MLTE control implementation (OSX part)
2894 // ----------------------------------------------------------------------------
2896 #if TARGET_API_MAC_OSX
2898 #if MAC_OS_X_VERSION_MAX_ALLOWED > MAC_OS_X_VERSION_10_2
2900 wxMacMLTEHIViewControl::wxMacMLTEHIViewControl( wxTextCtrl
*wxPeer
,
2901 const wxString
& str
,
2903 const wxSize
& size
, long style
) : wxMacMLTEControl( wxPeer
)
2905 m_font
= wxPeer
->GetFont() ;
2906 m_windowStyle
= style
;
2907 Rect bounds
= wxMacGetBoundsForControl( wxPeer
, pos
, size
) ;
2909 wxMacConvertNewlines10To13( &st
) ;
2912 { bounds
.left
, bounds
.top
},
2913 { bounds
.right
- bounds
.left
, bounds
.bottom
- bounds
.top
} } ;
2915 m_scrollView
= NULL
;
2916 TXNFrameOptions frameOptions
= FrameOptionsFromWXStyle( style
) ;
2917 if ( frameOptions
& (kTXNWantVScrollBarMask
| kTXNWantHScrollBarMask
) )
2920 (frameOptions
& kTXNWantHScrollBarMask
? kHIScrollViewOptionsHorizScroll
: 0)
2921 | (frameOptions
& kTXNWantVScrollBarMask
? kHIScrollViewOptionsVertScroll
: 0) ,
2924 HIViewSetFrame( m_scrollView
, &hr
);
2925 HIViewSetVisible( m_scrollView
, true );
2929 HITextViewCreate( NULL
, 0, frameOptions
, &m_textView
) ;
2930 m_txn
= HITextViewGetTXNObject( m_textView
) ;
2931 HIViewSetVisible( m_textView
, true ) ;
2934 HIViewAddSubview( m_scrollView
, m_textView
) ;
2935 m_controlRef
= m_scrollView
;
2936 wxPeer
->MacInstallEventHandler( (WXWidget
) m_textView
) ;
2940 HIViewSetFrame( m_textView
, &hr
);
2941 m_controlRef
= m_textView
;
2944 AdjustCreationAttributes( *wxWHITE
, true ) ;
2946 wxMacWindowClipper
c( m_peer
) ;
2947 SetTXNData( st
, kTXNStartOffset
, kTXNEndOffset
) ;
2949 TXNSetSelection( m_txn
, 0, 0 );
2950 TXNShowSelection( m_txn
, kTXNShowStart
);
2953 OSStatus
wxMacMLTEHIViewControl::SetFocus( ControlFocusPart focusPart
)
2955 return SetKeyboardFocus( GetControlOwner( m_textView
), m_textView
, focusPart
) ;
2958 bool wxMacMLTEHIViewControl::HasFocus() const
2960 ControlRef control
;
2961 GetKeyboardFocus( GetUserFocusWindow() , &control
) ;
2962 return control
== m_textView
;
2965 void wxMacMLTEHIViewControl::SetBackground( const wxBrush
&brush
)
2967 wxMacMLTEControl::SetBackground( brush
) ;
2970 CGColorSpaceRef rgbSpace
= CGColorSpaceCreateDeviceRGB();
2971 RGBColor col
= MAC_WXCOLORREF(brush
.GetColour().GetPixel()) ;
2973 float component
[4] ;
2974 component
[0] = col
.red
/ 65536.0 ;
2975 component
[1] = col
.green
/ 65536.0 ;
2976 component
[2] = col
.blue
/ 65536.0 ;
2977 component
[3] = 1.0 ; // alpha
2979 CGColorRef color
= CGColorCreate( rgbSpace
, component
);
2980 HITextViewSetBackgroundColor( m_textView
, color
);
2981 CGColorSpaceRelease( rgbSpace
);
2985 #endif // MAC_OS_X_VERSION_MAX_ALLOWED > MAC_OS_X_VERSION_10_2
2990 #endif // wxUSE_TEXTCTRL