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"
28 #include <sys/types.h>
34 #include "wx/msgdlg.h"
36 #if wxUSE_STD_IOSTREAM
44 #include "wx/toplevel.h"
45 #include "wx/settings.h"
46 #include "wx/filefn.h"
47 #include "wx/sysopt.h"
49 #if defined(__BORLANDC__) && !defined(__WIN32__)
51 #elif !defined(__MWERKS__) && !defined(__GNUWIN32) && !defined(__DARWIN__)
60 #include <MacTextEditor.h>
61 #include <ATSUnicode.h>
62 #include <TextCommon.h>
63 #include <TextEncodingConverter.h>
66 #include "wx/mac/uma.h"
69 // if this is set to 1 then under OSX 10.2 the 'classic' MLTE implementation will be used
70 // if set to 0 then the unicode textctrl will be used
71 #ifndef wxMAC_AWAYS_USE_MLTE
72 #define wxMAC_AWAYS_USE_MLTE 1
78 kTXNVisibilityTag
= 'visb' // set the visibility state of the object
87 virtual ~wxMacFunctor() {}
89 virtual void* operator()() = 0 ;
91 static void* CallBackProc( void *param
)
93 wxMacFunctor
* f
= (wxMacFunctor
*) param
;
94 void *result
= (*f
)() ;
99 template<typename classtype
, typename param1type
>
101 class wxMacObjectFunctor1
: public wxMacFunctor
103 typedef void (classtype::*function
)( param1type p1
) ;
104 typedef void (classtype::*ref_function
)( const param1type
& p1
) ;
106 wxMacObjectFunctor1( classtype
*obj
, function f
, param1type p1
) :
114 wxMacObjectFunctor1( classtype
*obj
, ref_function f
, param1type p1
) :
122 ~wxMacObjectFunctor1() {}
124 virtual void* operator()()
126 (m_object
->*m_function
)( m_param1
) ;
131 classtype
* m_object
;
132 param1type m_param1
;
135 function m_function
;
136 ref_function m_refFunction
;
140 template<typename classtype
, typename param1type
>
141 void* wxMacMPRemoteCall( classtype
*object
, void (classtype::*function
)( param1type p1
) , param1type p1
)
143 wxMacObjectFunctor1
<classtype
, param1type
> params(object
, function
, p1
) ;
145 MPRemoteCall( wxMacFunctor::CallBackProc
, ¶ms
, kMPOwningProcessRemoteContext
) ;
149 template<typename classtype
, typename param1type
>
150 void* wxMacMPRemoteCall( classtype
*object
, void (classtype::*function
)( const param1type
& p1
) , param1type p1
)
152 wxMacObjectFunctor1
<classtype
,param1type
> params(object
, function
, p1
) ;
154 MPRemoteCall( wxMacFunctor::CallBackProc
, ¶ms
, kMPOwningProcessRemoteContext
) ;
158 template<typename classtype
, typename param1type
>
159 void* wxMacMPRemoteGUICall( classtype
*object
, void (classtype::*function
)( param1type p1
) , param1type p1
)
162 void *result
= wxMacMPRemoteCall( object
, function
, p1
) ;
167 template<typename classtype
, typename param1type
>
168 void* wxMacMPRemoteGUICall( classtype
*object
, void (classtype::*function
)( const param1type
& p1
) , param1type p1
)
171 void *result
= wxMacMPRemoteCall( object
, function
, p1
) ;
176 // common interface for all implementations
177 class wxMacTextControl
: public wxMacControl
180 wxMacTextControl( wxTextCtrl
*peer
) ;
181 ~wxMacTextControl() ;
183 virtual wxString
GetStringValue() const = 0 ;
184 virtual void SetStringValue( const wxString
&val
) = 0 ;
185 virtual void SetSelection( long from
, long to
) = 0 ;
186 virtual void GetSelection( long* from
, long* to
) const = 0 ;
187 virtual void WriteText( const wxString
& str
) = 0 ;
189 virtual void SetStyle( long start
, long end
, const wxTextAttr
& style
) ;
190 virtual void Copy() ;
192 virtual void Paste() ;
193 virtual bool CanPaste() const ;
194 virtual void SetEditable( bool editable
) ;
195 virtual wxTextPos
GetLastPosition() const ;
196 virtual void Replace( long from
, long to
, const wxString
&str
) ;
197 virtual void Remove( long from
, long to
) ;
200 virtual bool HasOwnContextMenu() const
203 virtual bool SetupCursor( const wxPoint
& pt
)
206 virtual void Clear() ;
207 virtual bool CanUndo() const;
208 virtual void Undo() ;
209 virtual bool CanRedo() const;
210 virtual void Redo() ;
211 virtual int GetNumberOfLines() const ;
212 virtual long XYToPosition(long x
, long y
) const;
213 virtual bool PositionToXY(long pos
, long *x
, long *y
) const ;
214 virtual void ShowPosition(long WXUNUSED(pos
)) ;
215 virtual int GetLineLength(long lineNo
) const ;
216 virtual wxString
GetLineText(long lineNo
) const ;
218 #ifndef __WXMAC_OSX__
219 virtual void MacControlUserPaneDrawProc(wxInt16 part
) = 0 ;
220 virtual wxInt16
MacControlUserPaneHitTestProc(wxInt16 x
, wxInt16 y
) = 0 ;
221 virtual wxInt16
MacControlUserPaneTrackingProc(wxInt16 x
, wxInt16 y
, void* actionProc
) = 0 ;
222 virtual void MacControlUserPaneIdleProc() = 0 ;
223 virtual wxInt16
MacControlUserPaneKeyDownProc(wxInt16 keyCode
, wxInt16 charCode
, wxInt16 modifiers
) = 0 ;
224 virtual void MacControlUserPaneActivateProc(bool activating
) = 0 ;
225 virtual wxInt16
MacControlUserPaneFocusProc(wxInt16 action
) = 0 ;
226 virtual void MacControlUserPaneBackgroundProc(void* info
) = 0 ;
230 // common parts for implementations based on MLTE
232 class wxMacMLTEControl
: public wxMacTextControl
235 wxMacMLTEControl( wxTextCtrl
*peer
) ;
237 virtual wxString
GetStringValue() const ;
238 virtual void SetStringValue( const wxString
&str
) ;
240 static TXNFrameOptions
FrameOptionsFromWXStyle( long wxStyle
) ;
242 void AdjustCreationAttributes( const wxColour
& background
, bool visible
) ;
244 virtual void SetFont( const wxFont
& font
, const wxColour
& foreground
, long windowStyle
) ;
245 virtual void SetBackground( const wxBrush
&brush
) ;
246 virtual void SetStyle( long start
, long end
, const wxTextAttr
& style
) ;
247 virtual void Copy() ;
249 virtual void Paste() ;
250 virtual bool CanPaste() const ;
251 virtual void SetEditable( bool editable
) ;
252 virtual wxTextPos
GetLastPosition() const ;
253 virtual void Replace( long from
, long to
, const wxString
&str
) ;
254 virtual void Remove( long from
, long to
) ;
255 virtual void GetSelection( long* from
, long* to
) const ;
256 virtual void SetSelection( long from
, long to
) ;
258 virtual void WriteText( const wxString
& str
) ;
260 virtual bool HasOwnContextMenu() const
262 #if MAC_OS_X_VERSION_MAX_ALLOWED >= MAC_OS_X_VERSION_10_4
263 if ( UMAGetSystemVersion() >= 0x1040 )
265 TXNCommandEventSupportOptions options
;
266 TXNGetCommandEventSupport( m_txn
, & options
) ;
267 return options
& kTXNSupportEditCommandProcessing
;
274 virtual void Clear() ;
276 virtual bool CanUndo() const ;
277 virtual void Undo() ;
278 virtual bool CanRedo() const;
279 virtual void Redo() ;
280 virtual int GetNumberOfLines() const ;
281 virtual long XYToPosition(long x
, long y
) const ;
282 virtual bool PositionToXY(long pos
, long *x
, long *y
) const ;
283 virtual void ShowPosition( long pos
) ;
284 virtual int GetLineLength(long lineNo
) const ;
285 virtual wxString
GetLineText(long lineNo
) const ;
287 void SetTXNData( const wxString
& st
, TXNOffset start
, TXNOffset end
) ;
290 void TXNSetAttribute( const wxTextAttr
& style
, long from
, long to
) ;
295 #if TARGET_API_MAC_OSX
297 // implementation available under OSX
299 #if MAC_OS_X_VERSION_MAX_ALLOWED > MAC_OS_X_VERSION_10_2
301 class wxMacMLTEHIViewControl
: public wxMacMLTEControl
304 wxMacMLTEHIViewControl( wxTextCtrl
*wxPeer
,
307 const wxSize
& size
, long style
) ;
308 virtual OSStatus
SetFocus( ControlFocusPart focusPart
) ;
309 virtual bool HasFocus() const ;
310 virtual void SetBackground( const wxBrush
&brush
) ;
313 HIViewRef m_scrollView
;
314 HIViewRef m_textView
;
319 class wxMacUnicodeTextControl
: public wxMacTextControl
322 wxMacUnicodeTextControl( wxTextCtrl
*wxPeer
,
325 const wxSize
& size
, long style
) ;
326 ~wxMacUnicodeTextControl();
328 virtual void VisibilityChanged(bool shown
);
329 virtual wxString
GetStringValue() const ;
330 virtual void SetStringValue( const wxString
&str
) ;
333 virtual void Paste();
334 virtual bool CanPaste() const;
335 virtual void SetEditable(bool editable
) ;
336 virtual void GetSelection( long* from
, long* to
) const ;
337 virtual void SetSelection( long from
, long to
) ;
338 virtual void WriteText(const wxString
& str
) ;
341 // contains the tag for the content (is different for password and non-password controls)
347 // 'classic' MLTE implementation
349 class wxMacMLTEClassicControl
: public wxMacMLTEControl
352 wxMacMLTEClassicControl( wxTextCtrl
*wxPeer
,
355 const wxSize
& size
, long style
) ;
356 ~wxMacMLTEClassicControl() ;
358 virtual void VisibilityChanged(bool shown
) ;
359 virtual void SuperChangedPosition() ;
361 virtual void MacControlUserPaneDrawProc(wxInt16 part
) ;
362 virtual wxInt16
MacControlUserPaneHitTestProc(wxInt16 x
, wxInt16 y
) ;
363 virtual wxInt16
MacControlUserPaneTrackingProc(wxInt16 x
, wxInt16 y
, void* actionProc
) ;
364 virtual void MacControlUserPaneIdleProc() ;
365 virtual wxInt16
MacControlUserPaneKeyDownProc(wxInt16 keyCode
, wxInt16 charCode
, wxInt16 modifiers
) ;
366 virtual void MacControlUserPaneActivateProc(bool activating
) ;
367 virtual wxInt16
MacControlUserPaneFocusProc(wxInt16 action
) ;
368 virtual void MacControlUserPaneBackgroundProc(void* info
) ;
370 virtual bool SetupCursor( const wxPoint
& WXUNUSED(pt
) )
372 MacControlUserPaneIdleProc();
376 virtual void SetRect( Rect
*r
) ;
381 void MacUpdatePosition() ;
382 void MacActivatePaneText(bool setActive
) ;
383 void MacFocusPaneText(bool setFocus
) ;
384 void MacSetObjectVisibility(bool vis
) ;
387 TXNFrameID m_txnFrameID
;
389 WindowRef m_txnWindow
;
390 // bounds of the control as we last did set the txn frames
391 Rect m_txnControlBounds
;
392 Rect m_txnVisBounds
;
395 static pascal void TXNScrollActionProc( ControlRef controlRef
, ControlPartCode partCode
) ;
396 static pascal void TXNScrollInfoProc(
397 SInt32 iValue
, SInt32 iMaximumValue
,
398 TXNScrollBarOrientation iScrollBarOrientation
, SInt32 iRefCon
) ;
400 ControlRef m_sbHorizontal
;
401 SInt32 m_lastHorizontalValue
;
402 ControlRef m_sbVertical
;
403 SInt32 m_lastVerticalValue
;
408 IMPLEMENT_DYNAMIC_CLASS(wxTextCtrl
, wxControl
)
410 BEGIN_EVENT_TABLE(wxTextCtrl
, wxControl
)
411 EVT_ERASE_BACKGROUND( wxTextCtrl::OnEraseBackground
)
412 EVT_DROP_FILES(wxTextCtrl::OnDropFiles
)
413 EVT_CHAR(wxTextCtrl::OnChar
)
414 EVT_MENU(wxID_CUT
, wxTextCtrl::OnCut
)
415 EVT_MENU(wxID_COPY
, wxTextCtrl::OnCopy
)
416 EVT_MENU(wxID_PASTE
, wxTextCtrl::OnPaste
)
417 EVT_MENU(wxID_UNDO
, wxTextCtrl::OnUndo
)
418 EVT_MENU(wxID_REDO
, wxTextCtrl::OnRedo
)
419 EVT_MENU(wxID_CLEAR
, wxTextCtrl::OnDelete
)
420 EVT_MENU(wxID_SELECTALL
, wxTextCtrl::OnSelectAll
)
422 EVT_CONTEXT_MENU(wxTextCtrl::OnContextMenu
)
424 EVT_UPDATE_UI(wxID_CUT
, wxTextCtrl::OnUpdateCut
)
425 EVT_UPDATE_UI(wxID_COPY
, wxTextCtrl::OnUpdateCopy
)
426 EVT_UPDATE_UI(wxID_PASTE
, wxTextCtrl::OnUpdatePaste
)
427 EVT_UPDATE_UI(wxID_UNDO
, wxTextCtrl::OnUpdateUndo
)
428 EVT_UPDATE_UI(wxID_REDO
, wxTextCtrl::OnUpdateRedo
)
429 EVT_UPDATE_UI(wxID_CLEAR
, wxTextCtrl::OnUpdateDelete
)
430 EVT_UPDATE_UI(wxID_SELECTALL
, wxTextCtrl::OnUpdateSelectAll
)
434 void wxTextCtrl::Init()
440 m_privateContextMenu
= NULL
;
441 m_triggerOnSetValue
= true ;
444 wxTextCtrl::~wxTextCtrl()
446 delete m_privateContextMenu
;
449 bool wxTextCtrl::Create( wxWindow
*parent
,
455 const wxValidator
& validator
,
456 const wxString
& name
)
458 m_macIsUserPane
= false ;
461 if ( ! (style
& wxNO_BORDER
) )
462 style
= (style
& ~wxBORDER_MASK
) | wxSUNKEN_BORDER
;
464 if ( !wxTextCtrlBase::Create( parent
, id
, pos
, size
, style
& ~(wxHSCROLL
| wxVSCROLL
), validator
, name
) )
467 if ( m_windowStyle
& wxTE_MULTILINE
)
470 !(m_windowStyle
& wxTE_PROCESS_ENTER
),
471 wxT("wxTE_PROCESS_ENTER style is ignored for multiline text controls (they always process it)") );
473 m_windowStyle
|= wxTE_PROCESS_ENTER
;
474 style
|= wxTE_PROCESS_ENTER
;
477 bool forceMLTE
= false ;
479 #if wxUSE_SYSTEM_OPTIONS
480 if (wxSystemOptions::HasOption( wxMAC_TEXTCONTROL_USE_MLTE
) && (wxSystemOptions::GetOptionInt( wxMAC_TEXTCONTROL_USE_MLTE
) == 1))
487 #if MAC_OS_X_VERSION_MAX_ALLOWED > MAC_OS_X_VERSION_10_2
488 if ( UMAGetSystemVersion() >= 0x1030 && !forceMLTE
)
490 if ( m_windowStyle
& wxTE_MULTILINE
)
491 m_peer
= new wxMacMLTEHIViewControl( this , str
, pos
, size
, style
) ;
497 if ( !(m_windowStyle
& wxTE_MULTILINE
) && !forceMLTE
)
498 m_peer
= new wxMacUnicodeTextControl( this , str
, pos
, size
, style
) ;
503 m_peer
= new wxMacMLTEClassicControl( this , str
, pos
, size
, style
) ;
505 MacPostControlCreate(pos
, size
) ;
507 // only now the embedding is correct and we can do a positioning update
509 MacSuperChangedPosition() ;
511 if ( m_windowStyle
& wxTE_READONLY
)
512 SetEditable( false ) ;
514 SetCursor( wxCursor( wxCURSOR_IBEAM
) ) ;
519 void wxTextCtrl::MacSuperChangedPosition()
521 wxWindow::MacSuperChangedPosition() ;
522 GetPeer()->SuperChangedPosition() ;
525 void wxTextCtrl::MacVisibilityChanged()
527 GetPeer()->VisibilityChanged( MacIsReallyShown() ) ;
530 void wxTextCtrl::MacEnabledStateChanged()
534 wxString
wxTextCtrl::GetValue() const
536 return GetPeer()->GetStringValue() ;
539 void wxTextCtrl::GetSelection(long* from
, long* to
) const
541 GetPeer()->GetSelection( from
, to
) ;
544 void wxTextCtrl::SetValue(const wxString
& str
)
547 if ( GetValue() == str
)
550 GetPeer()->SetStringValue( str
) ;
552 if ( m_triggerOnSetValue
)
554 wxCommandEvent
event( wxEVT_COMMAND_TEXT_UPDATED
, m_windowId
);
555 event
.SetString( GetValue() );
556 event
.SetEventObject( this );
557 GetEventHandler()->ProcessEvent( event
);
561 void wxTextCtrl::SetMaxLength(unsigned long len
)
566 bool wxTextCtrl::SetFont( const wxFont
& font
)
568 if ( !wxTextCtrlBase::SetFont( font
) )
571 GetPeer()->SetFont( font
, GetForegroundColour() , GetWindowStyle() ) ;
576 bool wxTextCtrl::SetStyle(long start
, long end
, const wxTextAttr
& style
)
578 GetPeer()->SetStyle( start
, end
, style
) ;
583 bool wxTextCtrl::SetDefaultStyle(const wxTextAttr
& style
)
585 wxTextCtrlBase::SetDefaultStyle( style
) ;
586 SetStyle( kTXNUseCurrentSelection
, kTXNUseCurrentSelection
, GetDefaultStyle() ) ;
591 // Clipboard operations
593 void wxTextCtrl::Copy()
599 void wxTextCtrl::Cut()
605 wxCommandEvent
event( wxEVT_COMMAND_TEXT_UPDATED
, m_windowId
);
606 event
.SetEventObject( this );
607 GetEventHandler()->ProcessEvent( event
);
611 void wxTextCtrl::Paste()
617 // TODO: eventually we should add setting the default style again
619 wxCommandEvent
event( wxEVT_COMMAND_TEXT_UPDATED
, m_windowId
);
620 event
.SetEventObject( this );
621 GetEventHandler()->ProcessEvent( event
);
625 bool wxTextCtrl::CanCopy() const
627 // Can copy if there's a selection
629 GetSelection( &from
, &to
);
634 bool wxTextCtrl::CanCut() const
639 // Can cut if there's a selection
641 GetSelection( &from
, &to
);
646 bool wxTextCtrl::CanPaste() const
651 return GetPeer()->CanPaste() ;
654 void wxTextCtrl::SetEditable(bool editable
)
656 if ( editable
!= m_editable
)
658 m_editable
= editable
;
659 GetPeer()->SetEditable( editable
) ;
663 void wxTextCtrl::SetInsertionPoint(long pos
)
665 SetSelection( pos
, pos
) ;
668 void wxTextCtrl::SetInsertionPointEnd()
670 wxTextPos pos
= GetLastPosition();
671 SetInsertionPoint( pos
);
674 long wxTextCtrl::GetInsertionPoint() const
677 GetSelection( &begin
, &end
) ;
682 wxTextPos
wxTextCtrl::GetLastPosition() const
684 return GetPeer()->GetLastPosition() ;
687 void wxTextCtrl::Replace(long from
, long to
, const wxString
& str
)
689 GetPeer()->Replace( from
, to
, str
) ;
692 void wxTextCtrl::Remove(long from
, long to
)
694 GetPeer()->Remove( from
, to
) ;
697 void wxTextCtrl::SetSelection(long from
, long to
)
699 GetPeer()->SetSelection( from
, to
) ;
702 bool wxTextCtrl::LoadFile(const wxString
& file
)
704 return wxTextCtrlBase::LoadFile( file
);
707 void wxTextCtrl::WriteText(const wxString
& str
)
709 // TODO: this MPRemoting will be moved into a remoting peer proxy for any command
710 if ( !wxIsMainThread() )
712 // unfortunately CW 8 is not able to correctly deduce the template types,
713 // so we have to instantiate explicitly
714 wxMacMPRemoteGUICall
<wxTextCtrl
,wxString
>( this , &wxTextCtrl::WriteText
, str
) ;
719 GetPeer()->WriteText( str
) ;
722 void wxTextCtrl::AppendText(const wxString
& text
)
724 SetInsertionPointEnd();
728 void wxTextCtrl::Clear()
733 bool wxTextCtrl::IsModified() const
738 bool wxTextCtrl::IsEditable() const
740 return IsEnabled() && m_editable
;
743 bool wxTextCtrl::AcceptsFocus() const
745 // we don't want focus if we can't be edited
746 return /*IsEditable() && */ wxControl::AcceptsFocus();
749 wxSize
wxTextCtrl::DoGetBestSize() const
753 // these are the numbers from the HIG:
754 // we reduce them by the borders first
757 switch ( m_windowVariant
)
759 case wxWINDOW_VARIANT_NORMAL
:
763 case wxWINDOW_VARIANT_SMALL
:
767 case wxWINDOW_VARIANT_MINI
:
776 // as the above numbers have some free space around the text
777 // we get 5 lines like this anyway
778 if ( m_windowStyle
& wxTE_MULTILINE
)
781 if ( !HasFlag(wxNO_BORDER
) )
784 return wxSize(wText
, hText
);
787 // ----------------------------------------------------------------------------
789 // ----------------------------------------------------------------------------
791 void wxTextCtrl::Undo()
797 void wxTextCtrl::Redo()
803 bool wxTextCtrl::CanUndo() const
808 return GetPeer()->CanUndo() ;
811 bool wxTextCtrl::CanRedo() const
816 return GetPeer()->CanRedo() ;
819 void wxTextCtrl::MarkDirty()
824 void wxTextCtrl::DiscardEdits()
829 int wxTextCtrl::GetNumberOfLines() const
831 return GetPeer()->GetNumberOfLines() ;
834 long wxTextCtrl::XYToPosition(long x
, long y
) const
836 return GetPeer()->XYToPosition( x
, y
) ;
839 bool wxTextCtrl::PositionToXY(long pos
, long *x
, long *y
) const
841 return GetPeer()->PositionToXY( pos
, x
, y
) ;
844 void wxTextCtrl::ShowPosition(long pos
)
846 return GetPeer()->ShowPosition(pos
) ;
849 int wxTextCtrl::GetLineLength(long lineNo
) const
851 return GetPeer()->GetLineLength(lineNo
) ;
854 wxString
wxTextCtrl::GetLineText(long lineNo
) const
856 return GetPeer()->GetLineText(lineNo
) ;
859 void wxTextCtrl::Command(wxCommandEvent
& event
)
861 SetValue(event
.GetString());
862 ProcessCommand(event
);
865 void wxTextCtrl::OnDropFiles(wxDropFilesEvent
& event
)
867 // By default, load the first file into the text window.
868 if (event
.GetNumberOfFiles() > 0)
869 LoadFile( event
.GetFiles()[0] );
872 void wxTextCtrl::OnEraseBackground(wxEraseEvent
& event
)
874 // all erasing should be done by the real mac control implementation
875 // while this is true for MLTE under classic, the HITextView is somehow
876 // transparent but background erase is not working correctly, so intercept
877 // things while we can...
881 void wxTextCtrl::OnChar(wxKeyEvent
& event
)
883 int key
= event
.GetKeyCode() ;
884 bool eat_key
= false ;
886 if ( key
== 'a' && event
.MetaDown() )
893 if ( key
== 'c' && event
.MetaDown() )
901 if ( !IsEditable() && key
!= WXK_LEFT
&& key
!= WXK_RIGHT
&& key
!= WXK_DOWN
&& key
!= WXK_UP
&& key
!= WXK_TAB
&&
902 !( key
== WXK_RETURN
&& ( (m_windowStyle
& wxTE_PROCESS_ENTER
) || (m_windowStyle
& wxTE_MULTILINE
) ) )
903 // && key != WXK_PAGEUP && key != WXK_PAGEDOWN && key != WXK_HOME && key != WXK_END
910 // Check if we have reached the max # of chars (if it is set), but still
911 // allow navigation and deletion
912 if ( !IsMultiLine() && m_maxLength
&& GetValue().length() >= m_maxLength
&&
913 key
!= WXK_LEFT
&& key
!= WXK_RIGHT
&& key
!= WXK_TAB
&&
914 key
!= WXK_BACK
&& !( key
== WXK_RETURN
&& (m_windowStyle
& wxTE_PROCESS_ENTER
) )
917 // eat it, we don't want to add more than allowed # of characters
919 // TODO: generate EVT_TEXT_MAXLEN()
923 // assume that any key not processed yet is going to modify the control
926 if ( key
== 'v' && event
.MetaDown() )
934 if ( key
== 'x' && event
.MetaDown() )
945 if (m_windowStyle
& wxTE_PROCESS_ENTER
)
947 wxCommandEvent
event(wxEVT_COMMAND_TEXT_ENTER
, m_windowId
);
948 event
.SetEventObject( this );
949 event
.SetString( GetValue() );
950 if ( GetEventHandler()->ProcessEvent(event
) )
954 if ( !(m_windowStyle
& wxTE_MULTILINE
) )
956 wxWindow
*parent
= GetParent();
957 while ( parent
&& !parent
->IsTopLevel() && parent
->GetDefaultItem() == NULL
)
959 parent
= parent
->GetParent() ;
962 if ( parent
&& parent
->GetDefaultItem() )
964 wxButton
*def
= wxDynamicCast(parent
->GetDefaultItem(), wxButton
);
965 if ( def
&& def
->IsEnabled() )
967 wxCommandEvent
event(wxEVT_COMMAND_BUTTON_CLICKED
, def
->GetId() );
968 event
.SetEventObject(def
);
975 // this will make wxWidgets eat the ENTER key so that
976 // we actually prevent line wrapping in a single line text control
982 if ( !(m_windowStyle
& wxTE_PROCESS_TAB
))
985 if (!event
.ShiftDown())
986 flags
|= wxNavigationKeyEvent::IsForward
;
987 if (event
.ControlDown())
988 flags
|= wxNavigationKeyEvent::WinChange
;
995 // This is necessary (don't know why);
996 // otherwise the tab will not be inserted.
997 WriteText(wxT("\t"));
1007 // perform keystroke handling
1011 if ( ( key
>= 0x20 && key
< WXK_START
) ||
1012 key
== WXK_RETURN
||
1013 key
== WXK_DELETE
||
1016 wxCommandEvent
event1(wxEVT_COMMAND_TEXT_UPDATED
, m_windowId
);
1017 event1
.SetEventObject( this );
1018 wxPostEvent( GetEventHandler(), event1
);
1022 // ----------------------------------------------------------------------------
1023 // standard handlers for standard edit menu events
1024 // ----------------------------------------------------------------------------
1026 void wxTextCtrl::OnCut(wxCommandEvent
& WXUNUSED(event
))
1031 void wxTextCtrl::OnCopy(wxCommandEvent
& WXUNUSED(event
))
1036 void wxTextCtrl::OnPaste(wxCommandEvent
& WXUNUSED(event
))
1041 void wxTextCtrl::OnUndo(wxCommandEvent
& WXUNUSED(event
))
1046 void wxTextCtrl::OnRedo(wxCommandEvent
& WXUNUSED(event
))
1051 void wxTextCtrl::OnDelete(wxCommandEvent
& WXUNUSED(event
))
1055 GetSelection( &from
, &to
);
1056 if (from
!= -1 && to
!= -1)
1060 void wxTextCtrl::OnSelectAll(wxCommandEvent
& WXUNUSED(event
))
1062 SetSelection(-1, -1);
1065 void wxTextCtrl::OnUpdateCut(wxUpdateUIEvent
& event
)
1067 event
.Enable( CanCut() );
1070 void wxTextCtrl::OnUpdateCopy(wxUpdateUIEvent
& event
)
1072 event
.Enable( CanCopy() );
1075 void wxTextCtrl::OnUpdatePaste(wxUpdateUIEvent
& event
)
1077 event
.Enable( CanPaste() );
1080 void wxTextCtrl::OnUpdateUndo(wxUpdateUIEvent
& event
)
1082 event
.Enable( CanUndo() );
1085 void wxTextCtrl::OnUpdateRedo(wxUpdateUIEvent
& event
)
1087 event
.Enable( CanRedo() );
1090 void wxTextCtrl::OnUpdateDelete(wxUpdateUIEvent
& event
)
1094 GetSelection( &from
, &to
);
1095 event
.Enable( from
!= -1 && to
!= -1 && from
!= to
&& IsEditable() ) ;
1098 void wxTextCtrl::OnUpdateSelectAll(wxUpdateUIEvent
& event
)
1100 event
.Enable(GetLastPosition() > 0);
1103 // CS: Context Menus only work with MLTE implementations or non-multiline HIViews at the moment
1105 void wxTextCtrl::OnContextMenu(wxContextMenuEvent
& event
)
1107 if ( GetPeer()->HasOwnContextMenu() )
1113 if (m_privateContextMenu
== NULL
)
1115 m_privateContextMenu
= new wxMenu
;
1116 m_privateContextMenu
->Append(wxID_UNDO
, _("&Undo"));
1117 m_privateContextMenu
->Append(wxID_REDO
, _("&Redo"));
1118 m_privateContextMenu
->AppendSeparator();
1119 m_privateContextMenu
->Append(wxID_CUT
, _("Cu&t"));
1120 m_privateContextMenu
->Append(wxID_COPY
, _("&Copy"));
1121 m_privateContextMenu
->Append(wxID_PASTE
, _("&Paste"));
1122 m_privateContextMenu
->Append(wxID_CLEAR
, _("&Delete"));
1123 m_privateContextMenu
->AppendSeparator();
1124 m_privateContextMenu
->Append(wxID_SELECTALL
, _("Select &All"));
1127 if (m_privateContextMenu
!= NULL
)
1128 PopupMenu(m_privateContextMenu
);
1131 bool wxTextCtrl::MacSetupCursor( const wxPoint
& pt
)
1133 if ( !GetPeer()->SetupCursor( pt
) )
1134 return wxWindow::MacSetupCursor( pt
) ;
1139 #if !TARGET_API_MAC_OSX
1141 // user pane implementation
1143 void wxTextCtrl::MacControlUserPaneDrawProc(wxInt16 part
)
1145 GetPeer()->MacControlUserPaneDrawProc( part
) ;
1148 wxInt16
wxTextCtrl::MacControlUserPaneHitTestProc(wxInt16 x
, wxInt16 y
)
1150 return GetPeer()->MacControlUserPaneHitTestProc( x
, y
) ;
1153 wxInt16
wxTextCtrl::MacControlUserPaneTrackingProc(wxInt16 x
, wxInt16 y
, void* actionProc
)
1155 return GetPeer()->MacControlUserPaneTrackingProc( x
, y
, actionProc
) ;
1158 void wxTextCtrl::MacControlUserPaneIdleProc()
1160 GetPeer()->MacControlUserPaneIdleProc( ) ;
1163 wxInt16
wxTextCtrl::MacControlUserPaneKeyDownProc(wxInt16 keyCode
, wxInt16 charCode
, wxInt16 modifiers
)
1165 return GetPeer()->MacControlUserPaneKeyDownProc( keyCode
, charCode
, modifiers
) ;
1168 void wxTextCtrl::MacControlUserPaneActivateProc(bool activating
)
1170 GetPeer()->MacControlUserPaneActivateProc( activating
) ;
1173 wxInt16
wxTextCtrl::MacControlUserPaneFocusProc(wxInt16 action
)
1175 return GetPeer()->MacControlUserPaneFocusProc( action
) ;
1178 void wxTextCtrl::MacControlUserPaneBackgroundProc(void* info
)
1180 GetPeer()->MacControlUserPaneBackgroundProc( info
) ;
1185 // ----------------------------------------------------------------------------
1186 // implementation base class
1187 // ----------------------------------------------------------------------------
1189 wxMacTextControl::wxMacTextControl(wxTextCtrl
* peer
) :
1190 wxMacControl( peer
)
1194 wxMacTextControl::~wxMacTextControl()
1198 void wxMacTextControl::SetStyle(long start
, long end
, const wxTextAttr
& style
)
1202 void wxMacTextControl::Copy()
1206 void wxMacTextControl::Cut()
1210 void wxMacTextControl::Paste()
1214 bool wxMacTextControl::CanPaste() const
1219 void wxMacTextControl::SetEditable(bool editable
)
1223 wxTextPos
wxMacTextControl::GetLastPosition() const
1225 return GetStringValue().length() ;
1228 void wxMacTextControl::Replace( long from
, long to
, const wxString
&val
)
1230 SetSelection( from
, to
) ;
1234 void wxMacTextControl::Remove( long from
, long to
)
1236 SetSelection( from
, to
) ;
1237 WriteText( wxEmptyString
) ;
1240 void wxMacTextControl::Clear()
1242 SetStringValue( wxEmptyString
) ;
1245 bool wxMacTextControl::CanUndo() const
1250 void wxMacTextControl::Undo()
1254 bool wxMacTextControl::CanRedo() const
1259 void wxMacTextControl::Redo()
1263 long wxMacTextControl::XYToPosition(long x
, long y
) const
1268 bool wxMacTextControl::PositionToXY(long pos
, long *x
, long *y
) const
1273 void wxMacTextControl::ShowPosition( long WXUNUSED(pos
) )
1277 int wxMacTextControl::GetNumberOfLines() const
1279 ItemCount lines
= 0 ;
1280 wxString content
= GetStringValue() ;
1283 for (size_t i
= 0; i
< content
.length() ; i
++)
1285 if (content
[i
] == '\r')
1292 wxString
wxMacTextControl::GetLineText(long lineNo
) const
1294 // TODO: change this if possible to reflect real lines
1295 wxString content
= GetStringValue() ;
1299 for (size_t i
= 0; i
< content
.length() ; i
++)
1301 if (count
== lineNo
)
1303 // Add chars in line then
1306 for (size_t j
= i
; j
< content
.length(); j
++)
1308 if (content
[j
] == '\n')
1317 if (content
[i
] == '\n')
1321 return wxEmptyString
;
1324 int wxMacTextControl::GetLineLength(long lineNo
) const
1326 // TODO: change this if possible to reflect real lines
1327 wxString content
= GetStringValue() ;
1331 for (size_t i
= 0; i
< content
.length() ; i
++)
1333 if (count
== lineNo
)
1335 // Count chars in line then
1337 for (size_t j
= i
; j
< content
.length(); j
++)
1340 if (content
[j
] == '\n')
1347 if (content
[i
] == '\n')
1354 // ----------------------------------------------------------------------------
1355 // standard unicode control implementation
1356 // ----------------------------------------------------------------------------
1358 #if TARGET_API_MAC_OSX
1360 wxMacUnicodeTextControl::wxMacUnicodeTextControl( wxTextCtrl
*wxPeer
,
1361 const wxString
& str
,
1363 const wxSize
& size
, long style
)
1364 : wxMacTextControl( wxPeer
)
1366 m_font
= wxPeer
->GetFont() ;
1367 m_windowStyle
= style
;
1368 Rect bounds
= wxMacGetBoundsForControl( wxPeer
, pos
, size
) ;
1370 wxMacConvertNewlines10To13( &st
) ;
1371 wxMacCFStringHolder
cf(st
, m_font
.GetEncoding()) ;
1372 CFStringRef cfr
= cf
;
1373 Boolean isPassword
= ( m_windowStyle
& wxTE_PASSWORD
) != 0 ;
1374 m_valueTag
= isPassword
? kControlEditTextPasswordCFStringTag
: kControlEditTextCFStringTag
;
1376 OSStatus err
= CreateEditUnicodeTextControl(
1377 MAC_WXHWND(wxPeer
->MacGetTopLevelWindowRef()), &bounds
, cfr
,
1378 isPassword
, NULL
, &m_controlRef
) ;
1379 verify_noerr( err
);
1381 if ( !(m_windowStyle
& wxTE_MULTILINE
) )
1382 SetData
<Boolean
>( kControlEditTextPart
, kControlEditTextSingleLineTag
, true ) ;
1385 wxMacUnicodeTextControl::~wxMacUnicodeTextControl()
1389 void wxMacUnicodeTextControl::VisibilityChanged(bool shown
)
1391 if ( !(m_windowStyle
& wxTE_MULTILINE
) && shown
)
1393 // work around a refresh issue insofar as not always the entire content is shown,
1394 // even if this would be possible
1395 ControlEditTextSelectionRec sel
;
1396 CFStringRef value
= NULL
;
1398 verify_noerr( GetData
<ControlEditTextSelectionRec
>( 0, kControlEditTextSelectionTag
, &sel
) );
1399 verify_noerr( GetData
<CFStringRef
>( 0, m_valueTag
, &value
) );
1400 verify_noerr( SetData
<CFStringRef
>( 0, m_valueTag
, &value
) );
1401 verify_noerr( SetData
<ControlEditTextSelectionRec
>( 0, kControlEditTextSelectionTag
, &sel
) );
1403 CFRelease( value
) ;
1407 wxString
wxMacUnicodeTextControl::GetStringValue() const
1410 CFStringRef value
= GetData
<CFStringRef
>(0, m_valueTag
) ;
1413 wxMacCFStringHolder
cf(value
) ;
1414 result
= cf
.AsString() ;
1418 wxMacConvertNewlines13To10( &result
) ;
1420 wxMacConvertNewlines10To13( &result
) ;
1426 void wxMacUnicodeTextControl::SetStringValue( const wxString
&str
)
1429 wxMacConvertNewlines10To13( &st
) ;
1430 wxMacCFStringHolder
cf( st
, m_font
.GetEncoding() ) ;
1431 verify_noerr( SetData
<CFStringRef
>( 0, m_valueTag
, cf
) ) ;
1434 void wxMacUnicodeTextControl::Copy()
1436 SendHICommand( kHICommandCopy
) ;
1439 void wxMacUnicodeTextControl::Cut()
1441 SendHICommand( kHICommandCut
) ;
1444 void wxMacUnicodeTextControl::Paste()
1446 SendHICommand( kHICommandPaste
) ;
1449 bool wxMacUnicodeTextControl::CanPaste() const
1454 void wxMacUnicodeTextControl::SetEditable(bool editable
)
1456 #if 0 // leads to problem because text cannot be selected anymore
1457 SetData
<Boolean
>( kControlEditTextPart
, kControlEditTextLockedTag
, (Boolean
) !editable
) ;
1461 void wxMacUnicodeTextControl::GetSelection( long* from
, long* to
) const
1463 ControlEditTextSelectionRec sel
;
1464 verify_noerr( GetData
<ControlEditTextSelectionRec
>( 0, kControlEditTextSelectionTag
, &sel
) ) ;
1466 *from
= sel
.selStart
;
1471 void wxMacUnicodeTextControl::SetSelection( long from
, long to
)
1473 ControlEditTextSelectionRec sel
;
1474 if ((from
== -1) && (to
== -1))
1477 to
= 32767 ; // sel has 16 bit signed values, max is 32767
1480 sel
.selStart
= from
;
1482 SetData
<ControlEditTextSelectionRec
>( 0, kControlEditTextSelectionTag
, &sel
) ;
1485 void wxMacUnicodeTextControl::WriteText( const wxString
& str
)
1488 wxMacConvertNewlines10To13( &st
) ;
1490 #if MAC_OS_X_VERSION_MAX_ALLOWED > MAC_OS_X_VERSION_10_2
1491 wxMacCFStringHolder
cf(st
, m_font
.GetEncoding() ) ;
1492 CFStringRef value
= cf
;
1493 SetData
<CFStringRef
>( 0, kControlEditTextInsertCFStringRefTag
, &value
);
1495 wxString val
= GetStringValue() ;
1497 GetSelection( &start
, &end
) ;
1498 val
.Remove( start
, end
- start
) ;
1499 val
.insert( start
, str
) ;
1500 SetStringValue( val
) ;
1501 SetSelection( start
+ str
.length() , start
+ str
.length() ) ;
1507 // ----------------------------------------------------------------------------
1508 // MLTE control implementation (common part)
1509 // ----------------------------------------------------------------------------
1511 // if MTLE is read only, no changes at all are allowed, not even from
1512 // procedural API, in order to allow changes via API all the same we must undo
1513 // the readonly status while we are executing, this class helps to do so
1515 class wxMacEditHelper
1518 wxMacEditHelper( TXNObject txn
)
1520 TXNControlTag tag
[] = { kTXNIOPrivilegesTag
} ;
1522 TXNGetTXNObjectControls( m_txn
, 1 , tag
, m_data
) ;
1523 if ( m_data
[0].uValue
== kTXNReadOnly
)
1525 TXNControlData data
[] = { { kTXNReadWrite
} } ;
1526 TXNSetTXNObjectControls( m_txn
, false , 1 , tag
, data
) ;
1532 TXNControlTag tag
[] = { kTXNIOPrivilegesTag
} ;
1533 if ( m_data
[0].uValue
== kTXNReadOnly
)
1534 TXNSetTXNObjectControls( m_txn
, false , 1 , tag
, m_data
) ;
1539 TXNControlData m_data
[1] ;
1542 wxMacMLTEControl::wxMacMLTEControl( wxTextCtrl
*peer
)
1543 : wxMacTextControl( peer
)
1545 SetNeedsFocusRect( true ) ;
1548 wxString
wxMacMLTEControl::GetStringValue() const
1552 Size actualSize
= 0;
1557 err
= TXNGetDataEncoded( m_txn
, kTXNStartOffset
, kTXNEndOffset
, &theText
, kTXNUnicodeTextData
);
1566 actualSize
= GetHandleSize( theText
) / sizeof(UniChar
) ;
1567 if ( actualSize
> 0 )
1569 wxChar
*ptr
= NULL
;
1571 #if SIZEOF_WCHAR_T == 2
1572 ptr
= new wxChar
[actualSize
+ 1] ;
1573 wxStrncpy( ptr
, (wxChar
*)(*theText
) , actualSize
) ;
1575 SetHandleSize( theText
, (actualSize
+ 1) * sizeof(UniChar
) ) ;
1577 (((UniChar
*)*theText
)[actualSize
]) = 0 ;
1578 wxMBConvUTF16 converter
;
1579 size_t noChars
= converter
.MB2WC( NULL
, (const char*)*theText
, 0 ) ;
1580 wxASSERT_MSG( noChars
!= wxCONV_FAILED
, _T("Unable to count the number of characters in this string!") );
1581 ptr
= new wxChar
[noChars
+ 1] ;
1583 noChars
= converter
.MB2WC( ptr
, (const char*)*theText
, noChars
+ 1 ) ;
1584 wxASSERT_MSG( noChars
!= wxCONV_FAILED
, _T("Conversion of string failed!") );
1586 HUnlock( theText
) ;
1589 ptr
[actualSize
] = 0 ;
1590 result
= wxString( ptr
) ;
1594 DisposeHandle( theText
) ;
1598 err
= TXNGetDataEncoded( m_txn
, kTXNStartOffset
, kTXNEndOffset
, &theText
, kTXNTextData
);
1607 actualSize
= GetHandleSize( theText
) ;
1608 if ( actualSize
> 0 )
1611 result
= wxString( *theText
, wxConvLocal
, actualSize
) ;
1612 HUnlock( theText
) ;
1615 DisposeHandle( theText
) ;
1621 wxMacConvertNewlines13To10( &result
) ;
1623 wxMacConvertNewlines10To13( &result
) ;
1629 void wxMacMLTEControl::SetStringValue( const wxString
&str
)
1632 wxMacConvertNewlines10To13( &st
);
1635 wxMacWindowClipper
c( m_peer
);
1638 wxMacEditHelper
help( m_txn
);
1639 SetTXNData( st
, kTXNStartOffset
, kTXNEndOffset
);
1642 TXNSetSelection( m_txn
, 0, 0 );
1643 TXNShowSelection( m_txn
, kTXNShowStart
);
1647 TXNFrameOptions
wxMacMLTEControl::FrameOptionsFromWXStyle( long wxStyle
)
1649 TXNFrameOptions frameOptions
= kTXNDontDrawCaretWhenInactiveMask
;
1651 #if MAC_OS_X_VERSION_MAX_ALLOWED >= MAC_OS_X_VERSION_10_3
1652 frameOptions
|= kTXNDoFontSubstitutionMask
;
1655 if ( ! (wxStyle
& wxTE_NOHIDESEL
) )
1656 frameOptions
|= kTXNDontDrawSelectionWhenInactiveMask
;
1658 if ( wxStyle
& (wxHSCROLL
| wxTE_DONTWRAP
) )
1659 frameOptions
|= kTXNWantHScrollBarMask
;
1661 if ( wxStyle
& wxTE_MULTILINE
)
1663 frameOptions
|= kTXNAlwaysWrapAtViewEdgeMask
;
1665 if ( !(wxStyle
& wxTE_NO_VSCROLL
) )
1667 frameOptions
|= kTXNWantVScrollBarMask
;
1669 // The following code causes drawing problems on 10.4. Perhaps it can be restored for
1670 // older versions of the OS, but I'm not sure it's appropriate to put a grow icon here
1671 // anyways, as AFAIK users can't actually use it to resize the text ctrl.
1672 // if ( frameOptions & kTXNWantHScrollBarMask )
1673 // frameOptions |= kTXNDrawGrowIconMask ;
1678 frameOptions
|= kTXNSingleLineOnlyMask
;
1681 return frameOptions
;
1684 void wxMacMLTEControl::AdjustCreationAttributes( const wxColour
&background
, bool visible
)
1686 TXNControlTag iControlTags
[] =
1688 kTXNDoFontSubstitution
,
1689 kTXNWordWrapStateTag
,
1691 TXNControlData iControlData
[] =
1697 int toptag
= WXSIZEOF( iControlTags
) ;
1699 if ( m_windowStyle
& wxTE_MULTILINE
)
1701 iControlData
[1].uValue
=
1702 (m_windowStyle
& wxTE_DONTWRAP
)
1707 OSStatus err
= TXNSetTXNObjectControls( m_txn
, false, toptag
, iControlTags
, iControlData
) ;
1708 verify_noerr( err
);
1710 // setting the default font:
1711 // under 10.2 this causes a visible caret, therefore we avoid it
1713 if ( UMAGetSystemVersion() >= 0x1030 )
1719 GetThemeFont( kThemeSystemFont
, GetApplicationScript() , fontName
, &fontSize
, &fontStyle
) ;
1721 TXNTypeAttributes typeAttr
[] =
1723 { kTXNQDFontNameAttribute
, kTXNQDFontNameAttributeSize
, { (void*) fontName
} } ,
1724 { kTXNQDFontSizeAttribute
, kTXNFontSizeAttributeSize
, { (void*) (fontSize
<< 16) } } ,
1725 { kTXNQDFontStyleAttribute
, kTXNQDFontStyleAttributeSize
, { (void*) normal
} } ,
1728 err
= TXNSetTypeAttributes(
1729 m_txn
, sizeof(typeAttr
) / sizeof(TXNTypeAttributes
),
1730 typeAttr
, kTXNStartOffset
, kTXNEndOffset
);
1731 verify_noerr( err
);
1734 if ( m_windowStyle
& wxTE_PASSWORD
)
1736 UniChar c
= 0x00A5 ;
1737 err
= TXNEchoMode( m_txn
, c
, 0 , true );
1738 verify_noerr( err
);
1741 TXNBackground tback
;
1742 tback
.bgType
= kTXNBackgroundTypeRGB
;
1743 tback
.bg
.color
= MAC_WXCOLORREF( background
.GetPixel() );
1744 TXNSetBackground( m_txn
, &tback
);
1746 #if MAC_OS_X_VERSION_MAX_ALLOWED >= MAC_OS_X_VERSION_10_4
1747 if ( UMAGetSystemVersion() >= 0x1040 )
1749 TXNCommandEventSupportOptions options
;
1750 if ( TXNGetCommandEventSupport( m_txn
, &options
) == noErr
)
1753 kTXNSupportEditCommandProcessing
1754 | kTXNSupportEditCommandUpdating
1755 | kTXNSupportSpellCheckCommandProcessing
1756 | kTXNSupportSpellCheckCommandUpdating
1757 | kTXNSupportFontCommandProcessing
1758 | kTXNSupportFontCommandUpdating
;
1760 TXNSetCommandEventSupport( m_txn
, options
) ;
1766 void wxMacMLTEControl::SetBackground( const wxBrush
&brush
)
1768 // currently only solid background are supported
1769 TXNBackground tback
;
1771 tback
.bgType
= kTXNBackgroundTypeRGB
;
1772 tback
.bg
.color
= MAC_WXCOLORREF( brush
.GetColour().GetPixel() );
1773 TXNSetBackground( m_txn
, &tback
);
1776 void wxMacMLTEControl::TXNSetAttribute( const wxTextAttr
& style
, long from
, long to
)
1778 TXNTypeAttributes typeAttr
[4] ;
1779 Str255 fontName
= "\pMonaco" ;
1780 SInt16 fontSize
= 12 ;
1781 Style fontStyle
= normal
;
1785 if ( style
.HasFont() )
1787 const wxFont
&font
= style
.GetFont() ;
1789 #if 0 // old version
1790 wxMacStringToPascal( font
.GetFaceName() , fontName
) ;
1791 fontSize
= font
.GetPointSize() ;
1792 if ( font
.GetUnderlined() )
1793 fontStyle
|= underline
;
1794 if ( font
.GetWeight() == wxBOLD
)
1796 if ( font
.GetStyle() == wxITALIC
)
1797 fontStyle
|= italic
;
1799 typeAttr
[attrCount
].tag
= kTXNQDFontNameAttribute
;
1800 typeAttr
[attrCount
].size
= kTXNQDFontNameAttributeSize
;
1801 typeAttr
[attrCount
].data
.dataPtr
= (void*)fontName
;
1804 typeAttr
[attrCount
].tag
= kTXNQDFontSizeAttribute
;
1805 typeAttr
[attrCount
].size
= kTXNFontSizeAttributeSize
;
1806 typeAttr
[attrCount
].data
.dataValue
= (fontSize
<< 16) ;
1809 typeAttr
[attrCount
].tag
= kTXNQDFontStyleAttribute
;
1810 typeAttr
[attrCount
].size
= kTXNQDFontStyleAttributeSize
;
1811 typeAttr
[attrCount
].data
.dataValue
= fontStyle
;
1814 typeAttr
[attrCount
].tag
= kTXNATSUIStyle
;
1815 typeAttr
[attrCount
].size
= kTXNATSUIStyleSize
;
1816 typeAttr
[attrCount
].data
.dataValue
= (UInt32
)font
.MacGetATSUStyle() ;
1821 if ( style
.HasTextColour() )
1823 color
= MAC_WXCOLORREF(style
.GetTextColour().GetPixel()) ;
1825 typeAttr
[attrCount
].tag
= kTXNQDFontColorAttribute
;
1826 typeAttr
[attrCount
].size
= kTXNQDFontColorAttributeSize
;
1827 typeAttr
[attrCount
].data
.dataPtr
= (void*) &color
;
1831 if ( attrCount
> 0 )
1833 verify_noerr( TXNSetTypeAttributes( m_txn
, attrCount
, typeAttr
, from
, to
) );
1837 void wxMacMLTEControl::SetFont( const wxFont
& font
, const wxColour
& foreground
, long windowStyle
)
1839 wxMacEditHelper
help( m_txn
) ;
1840 TXNSetAttribute( wxTextAttr( foreground
, wxNullColour
, font
), kTXNStartOffset
, kTXNEndOffset
) ;
1843 void wxMacMLTEControl::SetStyle( long start
, long end
, const wxTextAttr
& style
)
1845 wxMacEditHelper
help( m_txn
) ;
1846 TXNSetAttribute( style
, start
, end
) ;
1849 void wxMacMLTEControl::Copy()
1851 ClearCurrentScrap();
1853 TXNConvertToPublicScrap();
1856 void wxMacMLTEControl::Cut()
1858 ClearCurrentScrap();
1860 TXNConvertToPublicScrap();
1863 void wxMacMLTEControl::Paste()
1865 TXNConvertFromPublicScrap();
1869 bool wxMacMLTEControl::CanPaste() const
1871 return TXNIsScrapPastable() ;
1874 void wxMacMLTEControl::SetEditable(bool editable
)
1876 TXNControlTag tag
[] = { kTXNIOPrivilegesTag
} ;
1877 TXNControlData data
[] = { { editable
? kTXNReadWrite
: kTXNReadOnly
} } ;
1878 TXNSetTXNObjectControls( m_txn
, false, WXSIZEOF(tag
), tag
, data
) ;
1881 wxTextPos
wxMacMLTEControl::GetLastPosition() const
1883 wxTextPos actualsize
= 0 ;
1886 OSErr err
= TXNGetDataEncoded( m_txn
, kTXNStartOffset
, kTXNEndOffset
, &theText
, kTXNTextData
);
1891 actualsize
= GetHandleSize( theText
) ;
1892 DisposeHandle( theText
) ;
1902 void wxMacMLTEControl::Replace( long from
, long to
, const wxString
&str
)
1904 wxString value
= str
;
1905 wxMacConvertNewlines10To13( &value
) ;
1907 wxMacEditHelper
help( m_txn
) ;
1908 wxMacWindowClipper
c( m_peer
) ;
1910 TXNSetSelection( m_txn
, from
, to
) ;
1912 SetTXNData( value
, kTXNUseCurrentSelection
, kTXNUseCurrentSelection
) ;
1915 void wxMacMLTEControl::Remove( long from
, long to
)
1917 wxMacWindowClipper
c( m_peer
) ;
1918 wxMacEditHelper
help( m_txn
) ;
1919 TXNSetSelection( m_txn
, from
, to
) ;
1923 void wxMacMLTEControl::GetSelection( long* from
, long* to
) const
1925 TXNGetSelection( m_txn
, (TXNOffset
*) from
, (TXNOffset
*) to
) ;
1928 void wxMacMLTEControl::SetSelection( long from
, long to
)
1930 wxMacWindowClipper
c( m_peer
) ;
1932 // change the selection
1933 if ((from
== -1) && (to
== -1))
1934 TXNSelectAll( m_txn
);
1936 TXNSetSelection( m_txn
, from
, to
);
1938 TXNShowSelection( m_txn
, kTXNShowStart
);
1941 void wxMacMLTEControl::WriteText( const wxString
& str
)
1944 wxMacConvertNewlines10To13( &st
) ;
1946 long start
, end
, dummy
;
1948 GetSelection( &start
, &dummy
) ;
1949 wxMacWindowClipper
c( m_peer
) ;
1952 wxMacEditHelper
helper( m_txn
) ;
1953 SetTXNData( st
, kTXNUseCurrentSelection
, kTXNUseCurrentSelection
) ;
1956 GetSelection( &dummy
, &end
) ;
1958 // TODO: SetStyle( start , end , GetDefaultStyle() ) ;
1961 void wxMacMLTEControl::Clear()
1963 wxMacWindowClipper
c( m_peer
) ;
1964 wxMacEditHelper
st( m_txn
) ;
1965 TXNSetSelection( m_txn
, kTXNStartOffset
, kTXNEndOffset
) ;
1969 bool wxMacMLTEControl::CanUndo() const
1971 return TXNCanUndo( m_txn
, NULL
) ;
1974 void wxMacMLTEControl::Undo()
1979 bool wxMacMLTEControl::CanRedo() const
1981 return TXNCanRedo( m_txn
, NULL
) ;
1984 void wxMacMLTEControl::Redo()
1989 int wxMacMLTEControl::GetNumberOfLines() const
1991 ItemCount lines
= 0 ;
1992 TXNGetLineCount( m_txn
, &lines
) ;
1997 long wxMacMLTEControl::XYToPosition(long x
, long y
) const
2002 // TODO: find a better implementation : while we can get the
2003 // line metrics of a certain line, we don't get its starting
2004 // position, so it would probably be rather a binary search
2005 // for the start position
2006 long xpos
= 0, ypos
= 0 ;
2007 int lastHeight
= 0 ;
2010 lastpos
= GetLastPosition() ;
2011 for ( n
= 0 ; n
<= (ItemCount
) lastpos
; ++n
)
2013 if ( y
== ypos
&& x
== xpos
)
2016 TXNOffsetToPoint( m_txn
, n
, &curpt
) ;
2018 if ( curpt
.v
> lastHeight
)
2024 lastHeight
= curpt
.v
;
2033 bool wxMacMLTEControl::PositionToXY( long pos
, long *x
, long *y
) const
2043 lastpos
= GetLastPosition() ;
2044 if ( pos
<= lastpos
)
2046 // TODO: find a better implementation - while we can get the
2047 // line metrics of a certain line, we don't get its starting
2048 // position, so it would probably be rather a binary search
2049 // for the start position
2050 long xpos
= 0, ypos
= 0 ;
2051 int lastHeight
= 0 ;
2054 for ( n
= 0 ; n
<= (ItemCount
) pos
; ++n
)
2056 TXNOffsetToPoint( m_txn
, n
, &curpt
) ;
2058 if ( curpt
.v
> lastHeight
)
2064 lastHeight
= curpt
.v
;
2079 void wxMacMLTEControl::ShowPosition( long pos
)
2081 #if TARGET_RT_MAC_MACHO && defined(AVAILABLE_MAC_OS_X_VERSION_10_2_AND_LATER)
2083 Point current
, desired
;
2084 TXNOffset selstart
, selend
;
2086 TXNGetSelection( m_txn
, &selstart
, &selend
);
2087 TXNOffsetToPoint( m_txn
, selstart
, ¤t
);
2088 TXNOffsetToPoint( m_txn
, pos
, &desired
);
2090 // TODO: use HIPoints for 10.3 and above
2091 if ( (UInt32
)TXNScroll
!= (UInt32
)kUnresolvedCFragSymbolAddress
)
2093 OSErr theErr
= noErr
;
2094 SInt32 dv
= desired
.v
- current
.v
;
2095 SInt32 dh
= desired
.h
- current
.h
;
2096 TXNShowSelection( m_txn
, kTXNShowStart
) ; // NB: should this be kTXNShowStart or kTXNShowEnd ??
2097 theErr
= TXNScroll( m_txn
, kTXNScrollUnitsInPixels
, kTXNScrollUnitsInPixels
, &dv
, &dh
);
2099 // there will be an error returned for classic MLTE implementation when the control is
2100 // invisible, but HITextView works correctly, so we don't assert that one
2101 // wxASSERT_MSG( theErr == noErr, _T("TXNScroll returned an error!") );
2107 void wxMacMLTEControl::SetTXNData( const wxString
& st
, TXNOffset start
, TXNOffset end
)
2110 #if SIZEOF_WCHAR_T == 2
2111 size_t len
= st
.Len() ;
2112 TXNSetData( m_txn
, kTXNUnicodeTextData
, (void*)st
.wc_str(), len
* 2, start
, end
);
2114 wxMBConvUTF16 converter
;
2115 ByteCount byteBufferLen
= converter
.WC2MB( NULL
, st
.wc_str(), 0 ) ;
2116 UniChar
*unibuf
= (UniChar
*)malloc( byteBufferLen
) ;
2117 converter
.WC2MB( (char*)unibuf
, st
.wc_str(), byteBufferLen
) ;
2118 TXNSetData( m_txn
, kTXNUnicodeTextData
, (void*)unibuf
, byteBufferLen
, start
, end
) ;
2122 wxCharBuffer text
= st
.mb_str( wxConvLocal
) ;
2123 TXNSetData( m_txn
, kTXNTextData
, (void*)text
.data(), strlen( text
), start
, end
) ;
2127 wxString
wxMacMLTEControl::GetLineText(long lineNo
) const
2131 if ( lineNo
< GetNumberOfLines() )
2134 Fixed lineWidth
, lineHeight
, currentHeight
;
2137 // get the first possible position in the control
2138 TXNOffsetToPoint(m_txn
, 0, &firstPoint
);
2140 // Iterate through the lines until we reach the one we want,
2141 // adding to our current y pixel point position
2144 while (ypos
< lineNo
)
2146 TXNGetLineMetrics(m_txn
, ypos
++, &lineWidth
, &lineHeight
);
2147 currentHeight
+= lineHeight
;
2150 Point thePoint
= { firstPoint
.v
+ (currentHeight
>> 16), firstPoint
.h
+ (0) };
2151 TXNOffset theOffset
;
2152 TXNPointToOffset(m_txn
, thePoint
, &theOffset
);
2154 wxString content
= GetStringValue() ;
2155 Point currentPoint
= thePoint
;
2156 while (thePoint
.v
== currentPoint
.v
&& theOffset
< content
.length())
2158 line
+= content
[theOffset
];
2159 TXNOffsetToPoint(m_txn
, ++theOffset
, ¤tPoint
);
2166 int wxMacMLTEControl::GetLineLength(long lineNo
) const
2170 if ( lineNo
< GetNumberOfLines() )
2173 Fixed lineWidth
, lineHeight
, currentHeight
;
2176 // get the first possible position in the control
2177 TXNOffsetToPoint(m_txn
, 0, &firstPoint
);
2179 // Iterate through the lines until we reach the one we want,
2180 // adding to our current y pixel point position
2183 while (ypos
< lineNo
)
2185 TXNGetLineMetrics(m_txn
, ypos
++, &lineWidth
, &lineHeight
);
2186 currentHeight
+= lineHeight
;
2189 Point thePoint
= { firstPoint
.v
+ (currentHeight
>> 16), firstPoint
.h
+ (0) };
2190 TXNOffset theOffset
;
2191 TXNPointToOffset(m_txn
, thePoint
, &theOffset
);
2193 wxString content
= GetStringValue() ;
2194 Point currentPoint
= thePoint
;
2195 while (thePoint
.v
== currentPoint
.v
&& theOffset
< content
.length())
2198 TXNOffsetToPoint(m_txn
, ++theOffset
, ¤tPoint
);
2205 // ----------------------------------------------------------------------------
2206 // MLTE control implementation (classic part)
2207 // ----------------------------------------------------------------------------
2209 // OS X Notes : We still don't have a full replacement for MLTE, so this implementation
2210 // has to live on. We have different problems coming from outdated implementations on the
2211 // various OS X versions. Most deal with the scrollbars: they are not correctly embedded
2212 // while this can be solved on 10.3 by reassigning them the correct place, on 10.2 there is
2213 // no way out, therefore we are using our own implementation and our own scrollbars ....
2215 #ifdef __WXMAC_OSX__
2217 TXNScrollInfoUPP gTXNScrollInfoProc
= NULL
;
2218 ControlActionUPP gTXNScrollActionProc
= NULL
;
2220 pascal void wxMacMLTEClassicControl::TXNScrollInfoProc(
2221 SInt32 iValue
, SInt32 iMaximumValue
,
2222 TXNScrollBarOrientation iScrollBarOrientation
, SInt32 iRefCon
)
2224 wxMacMLTEClassicControl
* mlte
= (wxMacMLTEClassicControl
*) iRefCon
;
2225 SInt32 value
= wxMax( iValue
, 0 ) ;
2226 SInt32 maximum
= wxMax( iMaximumValue
, 0 ) ;
2228 if ( iScrollBarOrientation
== kTXNHorizontal
)
2230 if ( mlte
->m_sbHorizontal
)
2232 SetControl32BitValue( mlte
->m_sbHorizontal
, value
) ;
2233 SetControl32BitMaximum( mlte
->m_sbHorizontal
, maximum
) ;
2234 mlte
->m_lastHorizontalValue
= value
;
2237 else if ( iScrollBarOrientation
== kTXNVertical
)
2239 if ( mlte
->m_sbVertical
)
2241 SetControl32BitValue( mlte
->m_sbVertical
, value
) ;
2242 SetControl32BitMaximum( mlte
->m_sbVertical
, maximum
) ;
2243 mlte
->m_lastVerticalValue
= value
;
2248 pascal void wxMacMLTEClassicControl::TXNScrollActionProc( ControlRef controlRef
, ControlPartCode partCode
)
2250 wxMacMLTEClassicControl
* mlte
= (wxMacMLTEClassicControl
*) GetControlReference( controlRef
) ;
2254 if ( controlRef
!= mlte
->m_sbVertical
&& controlRef
!= mlte
->m_sbHorizontal
)
2258 bool isHorizontal
= ( controlRef
== mlte
->m_sbHorizontal
) ;
2260 SInt32 minimum
= 0 ;
2261 SInt32 maximum
= GetControl32BitMaximum( controlRef
) ;
2262 SInt32 value
= GetControl32BitValue( controlRef
) ;
2267 case kControlDownButtonPart
:
2271 case kControlUpButtonPart
:
2275 case kControlPageDownPart
:
2276 delta
= GetControlViewSize( controlRef
) ;
2279 case kControlPageUpPart
:
2280 delta
= -GetControlViewSize( controlRef
) ;
2283 case kControlIndicatorPart
:
2284 delta
= value
- (isHorizontal
? mlte
->m_lastHorizontalValue
: mlte
->m_lastVerticalValue
) ;
2293 SInt32 newValue
= value
;
2295 if ( partCode
!= kControlIndicatorPart
)
2297 if ( value
+ delta
< minimum
)
2298 delta
= minimum
- value
;
2299 if ( value
+ delta
> maximum
)
2300 delta
= maximum
- value
;
2302 SetControl32BitValue( controlRef
, value
+ delta
) ;
2303 newValue
= value
+ delta
;
2306 SInt32 verticalDelta
= isHorizontal
? 0 : delta
;
2307 SInt32 horizontalDelta
= isHorizontal
? delta
: 0 ;
2310 mlte
->m_txn
, kTXNScrollUnitsInPixels
, kTXNScrollUnitsInPixels
,
2311 &verticalDelta
, &horizontalDelta
);
2312 verify_noerr( err
);
2315 mlte
->m_lastHorizontalValue
= newValue
;
2317 mlte
->m_lastVerticalValue
= newValue
;
2322 // make correct activations
2323 void wxMacMLTEClassicControl::MacActivatePaneText(bool setActive
)
2325 wxTextCtrl
* textctrl
= (wxTextCtrl
*) GetControlReference(m_controlRef
);
2327 wxMacWindowClipper
clipper( textctrl
) ;
2328 TXNActivate( m_txn
, m_txnFrameID
, setActive
);
2330 ControlRef controlFocus
= 0 ;
2331 GetKeyboardFocus( m_txnWindow
, &controlFocus
) ;
2332 if ( controlFocus
== m_controlRef
)
2333 TXNFocus( m_txn
, setActive
);
2336 void wxMacMLTEClassicControl::MacFocusPaneText(bool setFocus
)
2338 TXNFocus( m_txn
, setFocus
);
2341 // guards against inappropriate redraw (hidden objects drawing onto window)
2343 void wxMacMLTEClassicControl::MacSetObjectVisibility(bool vis
)
2345 ControlRef controlFocus
= 0 ;
2346 GetKeyboardFocus( m_txnWindow
, &controlFocus
) ;
2348 if ( !vis
&& (controlFocus
== m_controlRef
) )
2349 SetKeyboardFocus( m_txnWindow
, m_controlRef
, kControlFocusNoPart
) ;
2351 TXNControlTag iControlTags
[1] = { kTXNVisibilityTag
};
2352 TXNControlData iControlData
[1] = { { (UInt32
)false } };
2354 verify_noerr( TXNGetTXNObjectControls( m_txn
, 1, iControlTags
, iControlData
) ) ;
2356 if ( iControlData
[0].uValue
!= vis
)
2358 iControlData
[0].uValue
= vis
;
2359 verify_noerr( TXNSetTXNObjectControls( m_txn
, false , 1, iControlTags
, iControlData
) ) ;
2362 // currently, we always clip as partial visibility (overlapped) visibility is also a problem,
2363 // if we run into further problems we might set the FrameBounds to an empty rect here
2366 // make sure that the TXNObject is at the right position
2368 void wxMacMLTEClassicControl::MacUpdatePosition()
2370 wxTextCtrl
* textctrl
= (wxTextCtrl
*)GetControlReference( m_controlRef
);
2371 if ( textctrl
== NULL
)
2375 UMAGetControlBoundsInWindowCoords( m_controlRef
, &bounds
);
2377 wxRect visRect
= textctrl
->MacGetClippedClientRect() ;
2378 Rect visBounds
= { visRect
.y
, visRect
.x
, visRect
.y
+ visRect
.height
, visRect
.x
+ visRect
.width
} ;
2381 textctrl
->MacWindowToRootWindow( &x
, &y
) ;
2382 OffsetRect( &visBounds
, x
, y
) ;
2384 if ( !EqualRect( &bounds
, &m_txnControlBounds
) || !EqualRect( &visBounds
, &m_txnVisBounds
) )
2386 m_txnControlBounds
= bounds
;
2387 m_txnVisBounds
= visBounds
;
2388 wxMacWindowClipper
cl( textctrl
) ;
2390 #ifdef __WXMAC_OSX__
2391 bool isCompositing
= textctrl
->MacGetTopLevelWindow()->MacUsesCompositing() ;
2392 if ( m_sbHorizontal
|| m_sbVertical
)
2394 int w
= bounds
.right
- bounds
.left
;
2395 int h
= bounds
.bottom
- bounds
.top
;
2397 if ( m_sbHorizontal
)
2401 sbBounds
.left
= -1 ;
2402 sbBounds
.top
= h
- 14 ;
2403 sbBounds
.right
= w
+ 1 ;
2404 sbBounds
.bottom
= h
+ 1 ;
2406 if ( !isCompositing
)
2407 OffsetRect( &sbBounds
, m_txnControlBounds
.left
, m_txnControlBounds
.top
) ;
2409 SetControlBounds( m_sbHorizontal
, &sbBounds
) ;
2410 SetControlViewSize( m_sbHorizontal
, w
) ;
2417 sbBounds
.left
= w
- 14 ;
2419 sbBounds
.right
= w
+ 1 ;
2420 sbBounds
.bottom
= m_sbHorizontal
? h
- 14 : h
+ 1 ;
2422 if ( !isCompositing
)
2423 OffsetRect( &sbBounds
, m_txnControlBounds
.left
, m_txnControlBounds
.top
) ;
2425 SetControlBounds( m_sbVertical
, &sbBounds
) ;
2426 SetControlViewSize( m_sbVertical
, h
) ;
2431 TXNLongRect olddestRect
;
2432 TXNGetRectBounds( m_txn
, &oldviewRect
, &olddestRect
, NULL
) ;
2434 Rect viewRect
= { m_txnControlBounds
.top
, m_txnControlBounds
.left
,
2435 m_txnControlBounds
.bottom
- ( m_sbHorizontal
? 14 : 0 ) ,
2436 m_txnControlBounds
.right
- ( m_sbVertical
? 14 : 0 ) } ;
2437 TXNLongRect destRect
= { m_txnControlBounds
.top
, m_txnControlBounds
.left
,
2438 m_txnControlBounds
.bottom
- ( m_sbHorizontal
? 14 : 0 ) ,
2439 m_txnControlBounds
.right
- ( m_sbVertical
? 14 : 0 ) } ;
2441 if ( olddestRect
.right
>= 10000 )
2442 destRect
.right
= destRect
.left
+ 32000 ;
2444 if ( olddestRect
.bottom
>= 0x20000000 )
2445 destRect
.bottom
= destRect
.top
+ 0x40000000 ;
2447 SectRect( &viewRect
, &visBounds
, &viewRect
) ;
2448 TXNSetRectBounds( m_txn
, &viewRect
, &destRect
, true ) ;
2453 m_txnControlBounds
.top
,
2454 m_txnControlBounds
.left
,
2455 m_txnControlBounds
.bottom
- (m_sbHorizontal
? 14 : 0),
2456 m_txnControlBounds
.right
- (m_sbVertical
? 14 : 0),
2462 m_txn
, m_txnControlBounds
.top
, m_txnControlBounds
.left
,
2463 wxMax( m_txnControlBounds
.bottom
, m_txnControlBounds
.top
),
2464 wxMax( m_txnControlBounds
.right
, m_txnControlBounds
.left
), m_txnFrameID
);
2467 // the SetFrameBounds method under Classic sometimes does not correctly scroll a selection into sight after a
2468 // movement, therefore we have to force it
2470 // this problem has been reported in OSX as well, so we use this here once again
2472 TXNLongRect textRect
;
2473 TXNGetRectBounds( m_txn
, NULL
, NULL
, &textRect
) ;
2474 if ( textRect
.left
< m_txnControlBounds
.left
)
2475 TXNShowSelection( m_txn
, kTXNShowStart
) ;
2479 void wxMacMLTEClassicControl::SetRect( Rect
*r
)
2481 wxMacControl::SetRect( r
) ;
2482 MacUpdatePosition() ;
2485 void wxMacMLTEClassicControl::MacControlUserPaneDrawProc(wxInt16 thePart
)
2487 wxTextCtrl
* textctrl
= (wxTextCtrl
*)GetControlReference( m_controlRef
);
2488 if ( textctrl
== NULL
)
2491 if ( textctrl
->MacIsReallyShown() )
2493 wxMacWindowClipper
clipper( textctrl
) ;
2494 TXNDraw( m_txn
, NULL
) ;
2498 wxInt16
wxMacMLTEClassicControl::MacControlUserPaneHitTestProc(wxInt16 x
, wxInt16 y
)
2500 Point where
= { y
, x
} ;
2501 ControlPartCode result
= kControlNoPart
;
2503 wxTextCtrl
* textctrl
= (wxTextCtrl
*) GetControlReference( m_controlRef
);
2504 if ( (textctrl
!= NULL
) && textctrl
->MacIsReallyShown() )
2506 if (PtInRect( where
, &m_txnControlBounds
))
2508 result
= kControlEditTextPart
;
2512 // sometimes we get the coords also in control local coordinates, therefore test again
2513 if ( textctrl
->MacGetTopLevelWindow()->MacUsesCompositing() )
2516 textctrl
->MacClientToRootWindow( &x
, &y
) ;
2521 if (PtInRect( where
, &m_txnControlBounds
))
2522 result
= kControlEditTextPart
;
2529 wxInt16
wxMacMLTEClassicControl::MacControlUserPaneTrackingProc( wxInt16 x
, wxInt16 y
, void* actionProc
)
2531 ControlPartCode result
= kControlNoPart
;
2533 wxTextCtrl
* textctrl
= (wxTextCtrl
*) GetControlReference( m_controlRef
);
2534 if ( (textctrl
!= NULL
) && textctrl
->MacIsReallyShown() )
2536 Point startPt
= { y
, x
} ;
2537 // for compositing, we must convert these into toplevel window coordinates, because hittesting expects them
2538 if ( textctrl
->MacGetTopLevelWindow()->MacUsesCompositing() )
2541 textctrl
->MacClientToRootWindow( &x
, &y
) ;
2546 switch (MacControlUserPaneHitTestProc( startPt
.h
, startPt
.v
))
2548 case kControlEditTextPart
:
2550 wxMacWindowClipper
clipper( textctrl
) ;
2553 ConvertEventRefToEventRecord( (EventRef
) wxTheApp
->MacGetCurrentEvent() , &rec
) ;
2554 TXNClick( m_txn
, &rec
);
2566 void wxMacMLTEClassicControl::MacControlUserPaneIdleProc()
2568 wxTextCtrl
* textctrl
= (wxTextCtrl
*)GetControlReference( m_controlRef
);
2569 if ( textctrl
== NULL
)
2572 if (textctrl
->MacIsReallyShown())
2574 if (IsControlActive(m_controlRef
))
2578 wxMacWindowClipper
clipper( textctrl
) ;
2583 if (PtInRect(mousep
, &m_txnControlBounds
))
2585 RgnHandle theRgn
= NewRgn();
2586 RectRgn(theRgn
, &m_txnControlBounds
);
2587 TXNAdjustCursor(m_txn
, theRgn
);
2594 wxInt16
wxMacMLTEClassicControl::MacControlUserPaneKeyDownProc (wxInt16 keyCode
, wxInt16 charCode
, wxInt16 modifiers
)
2596 wxTextCtrl
* textctrl
= (wxTextCtrl
*)GetControlReference( m_controlRef
);
2597 if ( textctrl
== NULL
)
2598 return kControlNoPart
;
2600 wxMacWindowClipper
clipper( textctrl
) ;
2603 memset( &ev
, 0 , sizeof( ev
) ) ;
2605 ev
.modifiers
= modifiers
;
2606 ev
.message
= ((keyCode
<< 8) & keyCodeMask
) | (charCode
& charCodeMask
);
2607 TXNKeyDown( m_txn
, &ev
);
2609 return kControlEntireControl
;
2612 void wxMacMLTEClassicControl::MacControlUserPaneActivateProc(bool activating
)
2614 MacActivatePaneText( activating
);
2617 wxInt16
wxMacMLTEClassicControl::MacControlUserPaneFocusProc(wxInt16 action
)
2619 ControlPartCode focusResult
= kControlFocusNoPart
;
2621 wxTextCtrl
* textctrl
= (wxTextCtrl
*)GetControlReference( m_controlRef
);
2622 if ( textctrl
== NULL
)
2625 wxMacWindowClipper
clipper( textctrl
) ;
2627 ControlRef controlFocus
= NULL
;
2628 GetKeyboardFocus( m_txnWindow
, &controlFocus
) ;
2629 bool wasFocused
= ( controlFocus
== m_controlRef
) ;
2633 case kControlFocusPrevPart
:
2634 case kControlFocusNextPart
:
2635 MacFocusPaneText( !wasFocused
);
2636 focusResult
= (!wasFocused
? (ControlPartCode
) kControlEditTextPart
: (ControlPartCode
) kControlFocusNoPart
);
2639 case kControlFocusNoPart
:
2641 MacFocusPaneText( false );
2642 focusResult
= kControlFocusNoPart
;
2649 void wxMacMLTEClassicControl::MacControlUserPaneBackgroundProc( void *info
)
2653 wxMacMLTEClassicControl::wxMacMLTEClassicControl( wxTextCtrl
*wxPeer
,
2654 const wxString
& str
,
2656 const wxSize
& size
, long style
)
2657 : wxMacMLTEControl( wxPeer
)
2659 m_font
= wxPeer
->GetFont() ;
2660 m_windowStyle
= style
;
2661 Rect bounds
= wxMacGetBoundsForControl( wxPeer
, pos
, size
) ;
2664 kControlSupportsEmbedding
| kControlSupportsFocus
| kControlWantsIdle
2665 | kControlWantsActivate
| kControlHandlesTracking
2666 // | kControlHasSpecialBackground
2667 | kControlGetsFocusOnClick
| kControlSupportsLiveFeedback
;
2669 OSStatus err
= ::CreateUserPaneControl(
2670 MAC_WXHWND(wxPeer
->GetParent()->MacGetTopLevelWindowRef()),
2671 &bounds
, featureSet
, &m_controlRef
);
2672 verify_noerr( err
);
2676 AdjustCreationAttributes( *wxWHITE
, true ) ;
2678 MacSetObjectVisibility( wxPeer
->MacIsReallyShown() ) ;
2682 wxMacConvertNewlines10To13( &st
) ;
2683 wxMacWindowClipper
clipper( m_peer
) ;
2684 SetTXNData( st
, kTXNStartOffset
, kTXNEndOffset
) ;
2685 TXNSetSelection( m_txn
, 0, 0 ) ;
2689 wxMacMLTEClassicControl::~wxMacMLTEClassicControl()
2691 TXNDeleteObject( m_txn
);
2695 void wxMacMLTEClassicControl::VisibilityChanged(bool shown
)
2697 MacSetObjectVisibility( shown
) ;
2698 wxMacControl::VisibilityChanged( shown
) ;
2701 void wxMacMLTEClassicControl::SuperChangedPosition()
2703 MacUpdatePosition() ;
2704 wxMacControl::SuperChangedPosition() ;
2707 #ifdef __WXMAC_OSX__
2709 ControlUserPaneDrawUPP gTPDrawProc
= NULL
;
2710 ControlUserPaneHitTestUPP gTPHitProc
= NULL
;
2711 ControlUserPaneTrackingUPP gTPTrackProc
= NULL
;
2712 ControlUserPaneIdleUPP gTPIdleProc
= NULL
;
2713 ControlUserPaneKeyDownUPP gTPKeyProc
= NULL
;
2714 ControlUserPaneActivateUPP gTPActivateProc
= NULL
;
2715 ControlUserPaneFocusUPP gTPFocusProc
= NULL
;
2717 static pascal void wxMacControlUserPaneDrawProc(ControlRef control
, SInt16 part
)
2719 wxTextCtrl
*textCtrl
= wxDynamicCast( wxFindControlFromMacControl(control
) , wxTextCtrl
) ;
2720 wxMacMLTEClassicControl
* win
= textCtrl
? (wxMacMLTEClassicControl
*)(textCtrl
->GetPeer()) : NULL
;
2722 win
->MacControlUserPaneDrawProc( part
) ;
2725 static pascal ControlPartCode
wxMacControlUserPaneHitTestProc(ControlRef control
, Point where
)
2727 wxTextCtrl
*textCtrl
= wxDynamicCast( wxFindControlFromMacControl(control
) , wxTextCtrl
) ;
2728 wxMacMLTEClassicControl
* win
= textCtrl
? (wxMacMLTEClassicControl
*)(textCtrl
->GetPeer()) : NULL
;
2730 return win
->MacControlUserPaneHitTestProc( where
.h
, where
.v
) ;
2732 return kControlNoPart
;
2735 static pascal ControlPartCode
wxMacControlUserPaneTrackingProc(ControlRef control
, Point startPt
, ControlActionUPP actionProc
)
2737 wxTextCtrl
*textCtrl
= wxDynamicCast( wxFindControlFromMacControl(control
) , wxTextCtrl
) ;
2738 wxMacMLTEClassicControl
* win
= textCtrl
? (wxMacMLTEClassicControl
*)(textCtrl
->GetPeer()) : NULL
;
2740 return win
->MacControlUserPaneTrackingProc( startPt
.h
, startPt
.v
, (void*) actionProc
) ;
2742 return kControlNoPart
;
2745 static pascal void wxMacControlUserPaneIdleProc(ControlRef control
)
2747 wxTextCtrl
*textCtrl
= wxDynamicCast( wxFindControlFromMacControl(control
) , wxTextCtrl
) ;
2748 wxMacMLTEClassicControl
* win
= textCtrl
? (wxMacMLTEClassicControl
*)(textCtrl
->GetPeer()) : NULL
;
2750 win
->MacControlUserPaneIdleProc() ;
2753 static pascal ControlPartCode
wxMacControlUserPaneKeyDownProc(ControlRef control
, SInt16 keyCode
, SInt16 charCode
, SInt16 modifiers
)
2755 wxTextCtrl
*textCtrl
= wxDynamicCast( wxFindControlFromMacControl(control
) , wxTextCtrl
) ;
2756 wxMacMLTEClassicControl
* win
= textCtrl
? (wxMacMLTEClassicControl
*)(textCtrl
->GetPeer()) : NULL
;
2758 return win
->MacControlUserPaneKeyDownProc( keyCode
, charCode
, modifiers
) ;
2760 return kControlNoPart
;
2763 static pascal void wxMacControlUserPaneActivateProc(ControlRef control
, Boolean activating
)
2765 wxTextCtrl
*textCtrl
= wxDynamicCast( wxFindControlFromMacControl(control
) , wxTextCtrl
) ;
2766 wxMacMLTEClassicControl
* win
= textCtrl
? (wxMacMLTEClassicControl
*)(textCtrl
->GetPeer()) : NULL
;
2768 win
->MacControlUserPaneActivateProc( activating
) ;
2771 static pascal ControlPartCode
wxMacControlUserPaneFocusProc(ControlRef control
, ControlFocusPart action
)
2773 wxTextCtrl
*textCtrl
= wxDynamicCast( wxFindControlFromMacControl(control
) , wxTextCtrl
) ;
2774 wxMacMLTEClassicControl
* win
= textCtrl
? (wxMacMLTEClassicControl
*)(textCtrl
->GetPeer()) : NULL
;
2776 return win
->MacControlUserPaneFocusProc( action
) ;
2778 return kControlNoPart
;
2782 static pascal void wxMacControlUserPaneBackgroundProc(ControlRef control
, ControlBackgroundPtr info
)
2784 wxTextCtrl
*textCtrl
= wxDynamicCast( wxFindControlFromMacControl(control
) , wxTextCtrl
) ;
2785 wxMacMLTEClassicControl
* win
= textCtrl
? (wxMacMLTEClassicControl
*)(textCtrl
->GetPeer()) : NULL
;
2787 win
->MacControlUserPaneBackgroundProc(info
) ;
2791 #endif // __WXMAC_OSX__
2793 // TXNRegisterScrollInfoProc
2795 OSStatus
wxMacMLTEClassicControl::DoCreate()
2798 OSStatus err
= noErr
;
2800 // set up our globals
2801 #ifdef __WXMAC_OSX__
2802 if (gTPDrawProc
== NULL
) gTPDrawProc
= NewControlUserPaneDrawUPP(wxMacControlUserPaneDrawProc
);
2803 if (gTPHitProc
== NULL
) gTPHitProc
= NewControlUserPaneHitTestUPP(wxMacControlUserPaneHitTestProc
);
2804 if (gTPTrackProc
== NULL
) gTPTrackProc
= NewControlUserPaneTrackingUPP(wxMacControlUserPaneTrackingProc
);
2805 if (gTPIdleProc
== NULL
) gTPIdleProc
= NewControlUserPaneIdleUPP(wxMacControlUserPaneIdleProc
);
2806 if (gTPKeyProc
== NULL
) gTPKeyProc
= NewControlUserPaneKeyDownUPP(wxMacControlUserPaneKeyDownProc
);
2807 if (gTPActivateProc
== NULL
) gTPActivateProc
= NewControlUserPaneActivateUPP(wxMacControlUserPaneActivateProc
);
2808 if (gTPFocusProc
== NULL
) gTPFocusProc
= NewControlUserPaneFocusUPP(wxMacControlUserPaneFocusProc
);
2810 if (gTXNScrollInfoProc
== NULL
) gTXNScrollInfoProc
= NewTXNScrollInfoUPP(TXNScrollInfoProc
) ;
2811 if (gTXNScrollActionProc
== NULL
) gTXNScrollActionProc
= NewControlActionUPP(TXNScrollActionProc
) ;
2814 // set the initial settings for our private data
2816 m_txnWindow
= GetControlOwner(m_controlRef
);
2817 m_txnPort
= (GrafPtr
) GetWindowPort(m_txnWindow
);
2819 #ifdef __WXMAC_OSX__
2820 // set up the user pane procedures
2821 SetControlData(m_controlRef
, kControlEntireControl
, kControlUserPaneDrawProcTag
, sizeof(gTPDrawProc
), &gTPDrawProc
);
2822 SetControlData(m_controlRef
, kControlEntireControl
, kControlUserPaneHitTestProcTag
, sizeof(gTPHitProc
), &gTPHitProc
);
2823 SetControlData(m_controlRef
, kControlEntireControl
, kControlUserPaneTrackingProcTag
, sizeof(gTPTrackProc
), &gTPTrackProc
);
2824 SetControlData(m_controlRef
, kControlEntireControl
, kControlUserPaneIdleProcTag
, sizeof(gTPIdleProc
), &gTPIdleProc
);
2825 SetControlData(m_controlRef
, kControlEntireControl
, kControlUserPaneKeyDownProcTag
, sizeof(gTPKeyProc
), &gTPKeyProc
);
2826 SetControlData(m_controlRef
, kControlEntireControl
, kControlUserPaneActivateProcTag
, sizeof(gTPActivateProc
), &gTPActivateProc
);
2827 SetControlData(m_controlRef
, kControlEntireControl
, kControlUserPaneFocusProcTag
, sizeof(gTPFocusProc
), &gTPFocusProc
);
2830 // calculate the rectangles used by the control
2831 UMAGetControlBoundsInWindowCoords( m_controlRef
, &bounds
);
2833 m_txnControlBounds
= bounds
;
2834 m_txnVisBounds
= bounds
;
2839 GetGWorld( &origPort
, &origDev
) ;
2840 SetPort( m_txnPort
);
2842 // create the new edit field
2843 TXNFrameOptions frameOptions
= FrameOptionsFromWXStyle( m_windowStyle
);
2845 #ifdef __WXMAC_OSX__
2846 // the scrollbars are not correctly embedded but are inserted at the root:
2847 // this gives us problems as we have erratic redraws even over the structure area
2849 m_sbHorizontal
= 0 ;
2851 m_lastHorizontalValue
= 0 ;
2852 m_lastVerticalValue
= 0 ;
2854 Rect sb
= { 0 , 0 , 0 , 0 } ;
2855 if ( frameOptions
& kTXNWantVScrollBarMask
)
2857 CreateScrollBarControl( m_txnWindow
, &sb
, 0, 0, 100, 1, true, gTXNScrollActionProc
, &m_sbVertical
);
2858 SetControlReference( m_sbVertical
, (SInt32
)this );
2859 SetControlAction( m_sbVertical
, gTXNScrollActionProc
);
2860 ShowControl( m_sbVertical
);
2861 EmbedControl( m_sbVertical
, m_controlRef
);
2862 frameOptions
&= ~kTXNWantVScrollBarMask
;
2865 if ( frameOptions
& kTXNWantHScrollBarMask
)
2867 CreateScrollBarControl( m_txnWindow
, &sb
, 0, 0, 100, 1, true, gTXNScrollActionProc
, &m_sbHorizontal
);
2868 SetControlReference( m_sbHorizontal
, (SInt32
)this );
2869 SetControlAction( m_sbHorizontal
, gTXNScrollActionProc
);
2870 ShowControl( m_sbHorizontal
);
2871 EmbedControl( m_sbHorizontal
, m_controlRef
);
2872 frameOptions
&= ~(kTXNWantHScrollBarMask
| kTXNDrawGrowIconMask
);
2878 NULL
, m_txnWindow
, &bounds
, frameOptions
,
2879 kTXNTextEditStyleFrameType
, kTXNTextensionFile
, kTXNSystemDefaultEncoding
,
2880 &m_txn
, &m_txnFrameID
, NULL
);
2881 verify_noerr( err
);
2884 TXNControlTag iControlTags
[] = { kTXNUseCarbonEvents
};
2885 TXNControlData iControlData
[] = { { (UInt32
)&cInfo
} };
2886 int toptag
= WXSIZEOF( iControlTags
) ;
2887 TXNCarbonEventInfo cInfo
;
2888 cInfo
.useCarbonEvents
= false ;
2891 cInfo
.fDictionary
= NULL
;
2893 verify_noerr( TXNSetTXNObjectControls( m_txn
, false, toptag
, iControlTags
, iControlData
) );
2896 #ifdef __WXMAC_OSX__
2897 TXNRegisterScrollInfoProc( m_txn
, gTXNScrollInfoProc
, (SInt32
)this );
2900 SetGWorld( origPort
, origDev
) ;
2905 // ----------------------------------------------------------------------------
2906 // MLTE control implementation (OSX part)
2907 // ----------------------------------------------------------------------------
2909 #if TARGET_API_MAC_OSX
2911 #if MAC_OS_X_VERSION_MAX_ALLOWED > MAC_OS_X_VERSION_10_2
2913 wxMacMLTEHIViewControl::wxMacMLTEHIViewControl( wxTextCtrl
*wxPeer
,
2914 const wxString
& str
,
2916 const wxSize
& size
, long style
) : wxMacMLTEControl( wxPeer
)
2918 m_font
= wxPeer
->GetFont() ;
2919 m_windowStyle
= style
;
2920 Rect bounds
= wxMacGetBoundsForControl( wxPeer
, pos
, size
) ;
2922 wxMacConvertNewlines10To13( &st
) ;
2925 { bounds
.left
, bounds
.top
},
2926 { bounds
.right
- bounds
.left
, bounds
.bottom
- bounds
.top
} } ;
2928 m_scrollView
= NULL
;
2929 TXNFrameOptions frameOptions
= FrameOptionsFromWXStyle( style
) ;
2930 if ( frameOptions
& (kTXNWantVScrollBarMask
| kTXNWantHScrollBarMask
) )
2933 (frameOptions
& kTXNWantHScrollBarMask
? kHIScrollViewOptionsHorizScroll
: 0)
2934 | (frameOptions
& kTXNWantVScrollBarMask
? kHIScrollViewOptionsVertScroll
: 0) ,
2937 HIViewSetFrame( m_scrollView
, &hr
);
2938 HIViewSetVisible( m_scrollView
, true );
2942 HITextViewCreate( NULL
, 0, frameOptions
, &m_textView
) ;
2943 m_txn
= HITextViewGetTXNObject( m_textView
) ;
2944 HIViewSetVisible( m_textView
, true ) ;
2947 HIViewAddSubview( m_scrollView
, m_textView
) ;
2948 m_controlRef
= m_scrollView
;
2949 wxPeer
->MacInstallEventHandler( (WXWidget
) m_textView
) ;
2953 HIViewSetFrame( m_textView
, &hr
);
2954 m_controlRef
= m_textView
;
2957 AdjustCreationAttributes( *wxWHITE
, true ) ;
2959 wxMacWindowClipper
c( m_peer
) ;
2960 SetTXNData( st
, kTXNStartOffset
, kTXNEndOffset
) ;
2962 TXNSetSelection( m_txn
, 0, 0 );
2963 TXNShowSelection( m_txn
, kTXNShowStart
);
2966 OSStatus
wxMacMLTEHIViewControl::SetFocus( ControlFocusPart focusPart
)
2968 return SetKeyboardFocus( GetControlOwner( m_textView
), m_textView
, focusPart
) ;
2971 bool wxMacMLTEHIViewControl::HasFocus() const
2973 ControlRef control
;
2974 GetKeyboardFocus( GetUserFocusWindow() , &control
) ;
2975 return control
== m_textView
;
2978 void wxMacMLTEHIViewControl::SetBackground( const wxBrush
&brush
)
2980 wxMacMLTEControl::SetBackground( brush
) ;
2983 CGColorSpaceRef rgbSpace
= CGColorSpaceCreateDeviceRGB();
2984 RGBColor col
= MAC_WXCOLORREF(brush
.GetColour().GetPixel()) ;
2986 float component
[4] ;
2987 component
[0] = col
.red
/ 65536.0 ;
2988 component
[1] = col
.green
/ 65536.0 ;
2989 component
[2] = col
.blue
/ 65536.0 ;
2990 component
[3] = 1.0 ; // alpha
2992 CGColorRef color
= CGColorCreate( rgbSpace
, component
);
2993 HITextViewSetBackgroundColor( m_textView
, color
);
2994 CGColorSpaceRelease( rgbSpace
);
2998 #endif // MAC_OS_X_VERSION_MAX_ALLOWED > MAC_OS_X_VERSION_10_2
3003 #endif // wxUSE_TEXTCTRL