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 <sys/types.h>
29 #include "wx/msgdlg.h"
31 #if wxUSE_STD_IOSTREAM
41 #include "wx/button.h"
42 #include "wx/toplevel.h"
43 #include "wx/settings.h"
44 #include "wx/filefn.h"
46 #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() ;
1788 wxMacStringToPascal( font
.GetFaceName() , fontName
) ;
1789 fontSize
= font
.GetPointSize() ;
1790 if ( font
.GetUnderlined() )
1791 fontStyle
|= underline
;
1792 if ( font
.GetWeight() == wxBOLD
)
1794 if ( font
.GetStyle() == wxITALIC
)
1795 fontStyle
|= italic
;
1797 typeAttr
[attrCount
].tag
= kTXNQDFontNameAttribute
;
1798 typeAttr
[attrCount
].size
= kTXNQDFontNameAttributeSize
;
1799 typeAttr
[attrCount
].data
.dataPtr
= (void*)fontName
;
1802 typeAttr
[attrCount
].tag
= kTXNQDFontSizeAttribute
;
1803 typeAttr
[attrCount
].size
= kTXNFontSizeAttributeSize
;
1804 typeAttr
[attrCount
].data
.dataValue
= (fontSize
<< 16) ;
1807 typeAttr
[attrCount
].tag
= kTXNQDFontStyleAttribute
;
1808 typeAttr
[attrCount
].size
= kTXNQDFontStyleAttributeSize
;
1809 typeAttr
[attrCount
].data
.dataValue
= fontStyle
;
1813 if ( style
.HasTextColour() )
1815 color
= MAC_WXCOLORREF(style
.GetTextColour().GetPixel()) ;
1817 typeAttr
[attrCount
].tag
= kTXNQDFontColorAttribute
;
1818 typeAttr
[attrCount
].size
= kTXNQDFontColorAttributeSize
;
1819 typeAttr
[attrCount
].data
.dataPtr
= (void*) &color
;
1823 if ( attrCount
> 0 )
1825 verify_noerr( TXNSetTypeAttributes( m_txn
, attrCount
, typeAttr
, from
, to
) );
1829 void wxMacMLTEControl::SetFont( const wxFont
& font
, const wxColour
& foreground
, long windowStyle
)
1831 wxMacEditHelper
help( m_txn
) ;
1832 TXNSetAttribute( wxTextAttr( foreground
, wxNullColour
, font
), kTXNStartOffset
, kTXNEndOffset
) ;
1835 void wxMacMLTEControl::SetStyle( long start
, long end
, const wxTextAttr
& style
)
1837 wxMacEditHelper
help( m_txn
) ;
1838 TXNSetAttribute( style
, start
, end
) ;
1841 void wxMacMLTEControl::Copy()
1843 ClearCurrentScrap();
1845 TXNConvertToPublicScrap();
1848 void wxMacMLTEControl::Cut()
1850 ClearCurrentScrap();
1852 TXNConvertToPublicScrap();
1855 void wxMacMLTEControl::Paste()
1857 TXNConvertFromPublicScrap();
1861 bool wxMacMLTEControl::CanPaste() const
1863 return TXNIsScrapPastable() ;
1866 void wxMacMLTEControl::SetEditable(bool editable
)
1868 TXNControlTag tag
[] = { kTXNIOPrivilegesTag
} ;
1869 TXNControlData data
[] = { { editable
? kTXNReadWrite
: kTXNReadOnly
} } ;
1870 TXNSetTXNObjectControls( m_txn
, false, WXSIZEOF(tag
), tag
, data
) ;
1873 wxTextPos
wxMacMLTEControl::GetLastPosition() const
1875 wxTextPos actualsize
= 0 ;
1878 OSErr err
= TXNGetDataEncoded( m_txn
, kTXNStartOffset
, kTXNEndOffset
, &theText
, kTXNTextData
);
1883 actualsize
= GetHandleSize( theText
) ;
1884 DisposeHandle( theText
) ;
1894 void wxMacMLTEControl::Replace( long from
, long to
, const wxString
&str
)
1896 wxString value
= str
;
1897 wxMacConvertNewlines10To13( &value
) ;
1899 wxMacEditHelper
help( m_txn
) ;
1900 wxMacWindowClipper
c( m_peer
) ;
1902 TXNSetSelection( m_txn
, from
, to
) ;
1904 SetTXNData( value
, kTXNUseCurrentSelection
, kTXNUseCurrentSelection
) ;
1907 void wxMacMLTEControl::Remove( long from
, long to
)
1909 wxMacWindowClipper
c( m_peer
) ;
1910 wxMacEditHelper
help( m_txn
) ;
1911 TXNSetSelection( m_txn
, from
, to
) ;
1915 void wxMacMLTEControl::GetSelection( long* from
, long* to
) const
1917 TXNGetSelection( m_txn
, (TXNOffset
*) from
, (TXNOffset
*) to
) ;
1920 void wxMacMLTEControl::SetSelection( long from
, long to
)
1922 wxMacWindowClipper
c( m_peer
) ;
1924 // change the selection
1925 if ((from
== -1) && (to
== -1))
1926 TXNSelectAll( m_txn
);
1928 TXNSetSelection( m_txn
, from
, to
);
1930 TXNShowSelection( m_txn
, kTXNShowStart
);
1933 void wxMacMLTEControl::WriteText( const wxString
& str
)
1936 wxMacConvertNewlines10To13( &st
) ;
1938 long start
, end
, dummy
;
1940 GetSelection( &start
, &dummy
) ;
1941 wxMacWindowClipper
c( m_peer
) ;
1944 wxMacEditHelper
helper( m_txn
) ;
1945 SetTXNData( st
, kTXNUseCurrentSelection
, kTXNUseCurrentSelection
) ;
1948 GetSelection( &dummy
, &end
) ;
1950 // TODO: SetStyle( start , end , GetDefaultStyle() ) ;
1953 void wxMacMLTEControl::Clear()
1955 wxMacWindowClipper
c( m_peer
) ;
1956 wxMacEditHelper
st( m_txn
) ;
1957 TXNSetSelection( m_txn
, kTXNStartOffset
, kTXNEndOffset
) ;
1961 bool wxMacMLTEControl::CanUndo() const
1963 return TXNCanUndo( m_txn
, NULL
) ;
1966 void wxMacMLTEControl::Undo()
1971 bool wxMacMLTEControl::CanRedo() const
1973 return TXNCanRedo( m_txn
, NULL
) ;
1976 void wxMacMLTEControl::Redo()
1981 int wxMacMLTEControl::GetNumberOfLines() const
1983 ItemCount lines
= 0 ;
1984 TXNGetLineCount( m_txn
, &lines
) ;
1989 long wxMacMLTEControl::XYToPosition(long x
, long y
) const
1994 // TODO: find a better implementation : while we can get the
1995 // line metrics of a certain line, we don't get its starting
1996 // position, so it would probably be rather a binary search
1997 // for the start position
1998 long xpos
= 0, ypos
= 0 ;
1999 int lastHeight
= 0 ;
2002 lastpos
= GetLastPosition() ;
2003 for ( n
= 0 ; n
<= (ItemCount
) lastpos
; ++n
)
2005 if ( y
== ypos
&& x
== xpos
)
2008 TXNOffsetToPoint( m_txn
, n
, &curpt
) ;
2010 if ( curpt
.v
> lastHeight
)
2016 lastHeight
= curpt
.v
;
2025 bool wxMacMLTEControl::PositionToXY( long pos
, long *x
, long *y
) const
2035 lastpos
= GetLastPosition() ;
2036 if ( pos
<= lastpos
)
2038 // TODO: find a better implementation - while we can get the
2039 // line metrics of a certain line, we don't get its starting
2040 // position, so it would probably be rather a binary search
2041 // for the start position
2042 long xpos
= 0, ypos
= 0 ;
2043 int lastHeight
= 0 ;
2046 for ( n
= 0 ; n
<= (ItemCount
) pos
; ++n
)
2048 TXNOffsetToPoint( m_txn
, n
, &curpt
) ;
2050 if ( curpt
.v
> lastHeight
)
2056 lastHeight
= curpt
.v
;
2071 void wxMacMLTEControl::ShowPosition( long pos
)
2073 #if TARGET_RT_MAC_MACHO && defined(AVAILABLE_MAC_OS_X_VERSION_10_2_AND_LATER)
2075 Point current
, desired
;
2076 TXNOffset selstart
, selend
;
2078 TXNGetSelection( m_txn
, &selstart
, &selend
);
2079 TXNOffsetToPoint( m_txn
, selstart
, ¤t
);
2080 TXNOffsetToPoint( m_txn
, pos
, &desired
);
2082 // TODO: use HIPoints for 10.3 and above
2083 if ( (UInt32
)TXNScroll
!= (UInt32
)kUnresolvedCFragSymbolAddress
)
2085 OSErr theErr
= noErr
;
2086 SInt32 dv
= desired
.v
- current
.v
;
2087 SInt32 dh
= desired
.h
- current
.h
;
2088 TXNShowSelection( m_txn
, kTXNShowStart
) ; // NB: should this be kTXNShowStart or kTXNShowEnd ??
2089 theErr
= TXNScroll( m_txn
, kTXNScrollUnitsInPixels
, kTXNScrollUnitsInPixels
, &dv
, &dh
);
2091 // there will be an error returned for classic MLTE implementation when the control is
2092 // invisible, but HITextView works correctly, so we don't assert that one
2093 // wxASSERT_MSG( theErr == noErr, _T("TXNScroll returned an error!") );
2099 void wxMacMLTEControl::SetTXNData( const wxString
& st
, TXNOffset start
, TXNOffset end
)
2102 #if SIZEOF_WCHAR_T == 2
2103 size_t len
= st
.Len() ;
2104 TXNSetData( m_txn
, kTXNUnicodeTextData
, (void*)st
.wc_str(), len
* 2, start
, end
);
2106 wxMBConvUTF16 converter
;
2107 ByteCount byteBufferLen
= converter
.WC2MB( NULL
, st
.wc_str(), 0 ) ;
2108 UniChar
*unibuf
= (UniChar
*)malloc( byteBufferLen
) ;
2109 converter
.WC2MB( (char*)unibuf
, st
.wc_str(), byteBufferLen
) ;
2110 TXNSetData( m_txn
, kTXNUnicodeTextData
, (void*)unibuf
, byteBufferLen
, start
, end
) ;
2114 wxCharBuffer text
= st
.mb_str( wxConvLocal
) ;
2115 TXNSetData( m_txn
, kTXNTextData
, (void*)text
.data(), strlen( text
), start
, end
) ;
2119 wxString
wxMacMLTEControl::GetLineText(long lineNo
) const
2123 if ( lineNo
< GetNumberOfLines() )
2126 Fixed lineWidth
, lineHeight
, currentHeight
;
2129 // get the first possible position in the control
2130 TXNOffsetToPoint(m_txn
, 0, &firstPoint
);
2132 // Iterate through the lines until we reach the one we want,
2133 // adding to our current y pixel point position
2136 while (ypos
< lineNo
)
2138 TXNGetLineMetrics(m_txn
, ypos
++, &lineWidth
, &lineHeight
);
2139 currentHeight
+= lineHeight
;
2142 Point thePoint
= { firstPoint
.v
+ (currentHeight
>> 16), firstPoint
.h
+ (0) };
2143 TXNOffset theOffset
;
2144 TXNPointToOffset(m_txn
, thePoint
, &theOffset
);
2146 wxString content
= GetStringValue() ;
2147 Point currentPoint
= thePoint
;
2148 while (thePoint
.v
== currentPoint
.v
&& theOffset
< content
.length())
2150 line
+= content
[theOffset
];
2151 TXNOffsetToPoint(m_txn
, ++theOffset
, ¤tPoint
);
2158 int wxMacMLTEControl::GetLineLength(long lineNo
) const
2162 if ( lineNo
< GetNumberOfLines() )
2165 Fixed lineWidth
, lineHeight
, currentHeight
;
2168 // get the first possible position in the control
2169 TXNOffsetToPoint(m_txn
, 0, &firstPoint
);
2171 // Iterate through the lines until we reach the one we want,
2172 // adding to our current y pixel point position
2175 while (ypos
< lineNo
)
2177 TXNGetLineMetrics(m_txn
, ypos
++, &lineWidth
, &lineHeight
);
2178 currentHeight
+= lineHeight
;
2181 Point thePoint
= { firstPoint
.v
+ (currentHeight
>> 16), firstPoint
.h
+ (0) };
2182 TXNOffset theOffset
;
2183 TXNPointToOffset(m_txn
, thePoint
, &theOffset
);
2185 wxString content
= GetStringValue() ;
2186 Point currentPoint
= thePoint
;
2187 while (thePoint
.v
== currentPoint
.v
&& theOffset
< content
.length())
2190 TXNOffsetToPoint(m_txn
, ++theOffset
, ¤tPoint
);
2197 // ----------------------------------------------------------------------------
2198 // MLTE control implementation (classic part)
2199 // ----------------------------------------------------------------------------
2201 // OS X Notes : We still don't have a full replacement for MLTE, so this implementation
2202 // has to live on. We have different problems coming from outdated implementations on the
2203 // various OS X versions. Most deal with the scrollbars: they are not correctly embedded
2204 // while this can be solved on 10.3 by reassigning them the correct place, on 10.2 there is
2205 // no way out, therefore we are using our own implementation and our own scrollbars ....
2207 #ifdef __WXMAC_OSX__
2209 TXNScrollInfoUPP gTXNScrollInfoProc
= NULL
;
2210 ControlActionUPP gTXNScrollActionProc
= NULL
;
2212 pascal void wxMacMLTEClassicControl::TXNScrollInfoProc(
2213 SInt32 iValue
, SInt32 iMaximumValue
,
2214 TXNScrollBarOrientation iScrollBarOrientation
, SInt32 iRefCon
)
2216 wxMacMLTEClassicControl
* mlte
= (wxMacMLTEClassicControl
*) iRefCon
;
2217 SInt32 value
= wxMax( iValue
, 0 ) ;
2218 SInt32 maximum
= wxMax( iMaximumValue
, 0 ) ;
2220 if ( iScrollBarOrientation
== kTXNHorizontal
)
2222 if ( mlte
->m_sbHorizontal
)
2224 SetControl32BitValue( mlte
->m_sbHorizontal
, value
) ;
2225 SetControl32BitMaximum( mlte
->m_sbHorizontal
, maximum
) ;
2226 mlte
->m_lastHorizontalValue
= value
;
2229 else if ( iScrollBarOrientation
== kTXNVertical
)
2231 if ( mlte
->m_sbVertical
)
2233 SetControl32BitValue( mlte
->m_sbVertical
, value
) ;
2234 SetControl32BitMaximum( mlte
->m_sbVertical
, maximum
) ;
2235 mlte
->m_lastVerticalValue
= value
;
2240 pascal void wxMacMLTEClassicControl::TXNScrollActionProc( ControlRef controlRef
, ControlPartCode partCode
)
2242 wxMacMLTEClassicControl
* mlte
= (wxMacMLTEClassicControl
*) GetControlReference( controlRef
) ;
2246 if ( controlRef
!= mlte
->m_sbVertical
&& controlRef
!= mlte
->m_sbHorizontal
)
2250 bool isHorizontal
= ( controlRef
== mlte
->m_sbHorizontal
) ;
2252 SInt32 minimum
= 0 ;
2253 SInt32 maximum
= GetControl32BitMaximum( controlRef
) ;
2254 SInt32 value
= GetControl32BitValue( controlRef
) ;
2259 case kControlDownButtonPart
:
2263 case kControlUpButtonPart
:
2267 case kControlPageDownPart
:
2268 delta
= GetControlViewSize( controlRef
) ;
2271 case kControlPageUpPart
:
2272 delta
= -GetControlViewSize( controlRef
) ;
2275 case kControlIndicatorPart
:
2276 delta
= value
- (isHorizontal
? mlte
->m_lastHorizontalValue
: mlte
->m_lastVerticalValue
) ;
2285 SInt32 newValue
= value
;
2287 if ( partCode
!= kControlIndicatorPart
)
2289 if ( value
+ delta
< minimum
)
2290 delta
= minimum
- value
;
2291 if ( value
+ delta
> maximum
)
2292 delta
= maximum
- value
;
2294 SetControl32BitValue( controlRef
, value
+ delta
) ;
2295 newValue
= value
+ delta
;
2298 SInt32 verticalDelta
= isHorizontal
? 0 : delta
;
2299 SInt32 horizontalDelta
= isHorizontal
? delta
: 0 ;
2302 mlte
->m_txn
, kTXNScrollUnitsInPixels
, kTXNScrollUnitsInPixels
,
2303 &verticalDelta
, &horizontalDelta
);
2304 verify_noerr( err
);
2307 mlte
->m_lastHorizontalValue
= newValue
;
2309 mlte
->m_lastVerticalValue
= newValue
;
2314 // make correct activations
2315 void wxMacMLTEClassicControl::MacActivatePaneText(bool setActive
)
2317 wxTextCtrl
* textctrl
= (wxTextCtrl
*) GetControlReference(m_controlRef
);
2319 wxMacWindowClipper
clipper( textctrl
) ;
2320 TXNActivate( m_txn
, m_txnFrameID
, setActive
);
2322 ControlRef controlFocus
= 0 ;
2323 GetKeyboardFocus( m_txnWindow
, &controlFocus
) ;
2324 if ( controlFocus
== m_controlRef
)
2325 TXNFocus( m_txn
, setActive
);
2328 void wxMacMLTEClassicControl::MacFocusPaneText(bool setFocus
)
2330 TXNFocus( m_txn
, setFocus
);
2333 // guards against inappropriate redraw (hidden objects drawing onto window)
2335 void wxMacMLTEClassicControl::MacSetObjectVisibility(bool vis
)
2337 ControlRef controlFocus
= 0 ;
2338 GetKeyboardFocus( m_txnWindow
, &controlFocus
) ;
2340 if ( !vis
&& (controlFocus
== m_controlRef
) )
2341 SetKeyboardFocus( m_txnWindow
, m_controlRef
, kControlFocusNoPart
) ;
2343 TXNControlTag iControlTags
[1] = { kTXNVisibilityTag
};
2344 TXNControlData iControlData
[1] = { { (UInt32
)false } };
2346 verify_noerr( TXNGetTXNObjectControls( m_txn
, 1, iControlTags
, iControlData
) ) ;
2348 if ( iControlData
[0].uValue
!= vis
)
2350 iControlData
[0].uValue
= vis
;
2351 verify_noerr( TXNSetTXNObjectControls( m_txn
, false , 1, iControlTags
, iControlData
) ) ;
2354 // currently, we always clip as partial visibility (overlapped) visibility is also a problem,
2355 // if we run into further problems we might set the FrameBounds to an empty rect here
2358 // make sure that the TXNObject is at the right position
2360 void wxMacMLTEClassicControl::MacUpdatePosition()
2362 wxTextCtrl
* textctrl
= (wxTextCtrl
*)GetControlReference( m_controlRef
);
2363 if ( textctrl
== NULL
)
2367 UMAGetControlBoundsInWindowCoords( m_controlRef
, &bounds
);
2369 wxRect visRect
= textctrl
->MacGetClippedClientRect() ;
2370 Rect visBounds
= { visRect
.y
, visRect
.x
, visRect
.y
+ visRect
.height
, visRect
.x
+ visRect
.width
} ;
2373 textctrl
->MacWindowToRootWindow( &x
, &y
) ;
2374 OffsetRect( &visBounds
, x
, y
) ;
2376 if ( !EqualRect( &bounds
, &m_txnControlBounds
) || !EqualRect( &visBounds
, &m_txnVisBounds
) )
2378 m_txnControlBounds
= bounds
;
2379 m_txnVisBounds
= visBounds
;
2380 wxMacWindowClipper
cl( textctrl
) ;
2382 #ifdef __WXMAC_OSX__
2383 bool isCompositing
= textctrl
->MacGetTopLevelWindow()->MacUsesCompositing() ;
2384 if ( m_sbHorizontal
|| m_sbVertical
)
2386 int w
= bounds
.right
- bounds
.left
;
2387 int h
= bounds
.bottom
- bounds
.top
;
2389 if ( m_sbHorizontal
)
2393 sbBounds
.left
= -1 ;
2394 sbBounds
.top
= h
- 14 ;
2395 sbBounds
.right
= w
+ 1 ;
2396 sbBounds
.bottom
= h
+ 1 ;
2398 if ( !isCompositing
)
2399 OffsetRect( &sbBounds
, m_txnControlBounds
.left
, m_txnControlBounds
.top
) ;
2401 SetControlBounds( m_sbHorizontal
, &sbBounds
) ;
2402 SetControlViewSize( m_sbHorizontal
, w
) ;
2409 sbBounds
.left
= w
- 14 ;
2411 sbBounds
.right
= w
+ 1 ;
2412 sbBounds
.bottom
= m_sbHorizontal
? h
- 14 : h
+ 1 ;
2414 if ( !isCompositing
)
2415 OffsetRect( &sbBounds
, m_txnControlBounds
.left
, m_txnControlBounds
.top
) ;
2417 SetControlBounds( m_sbVertical
, &sbBounds
) ;
2418 SetControlViewSize( m_sbVertical
, h
) ;
2423 TXNLongRect olddestRect
;
2424 TXNGetRectBounds( m_txn
, &oldviewRect
, &olddestRect
, NULL
) ;
2426 Rect viewRect
= { m_txnControlBounds
.top
, m_txnControlBounds
.left
,
2427 m_txnControlBounds
.bottom
- ( m_sbHorizontal
? 14 : 0 ) ,
2428 m_txnControlBounds
.right
- ( m_sbVertical
? 14 : 0 ) } ;
2429 TXNLongRect destRect
= { m_txnControlBounds
.top
, m_txnControlBounds
.left
,
2430 m_txnControlBounds
.bottom
- ( m_sbHorizontal
? 14 : 0 ) ,
2431 m_txnControlBounds
.right
- ( m_sbVertical
? 14 : 0 ) } ;
2433 if ( olddestRect
.right
>= 10000 )
2434 destRect
.right
= destRect
.left
+ 32000 ;
2436 if ( olddestRect
.bottom
>= 0x20000000 )
2437 destRect
.bottom
= destRect
.top
+ 0x40000000 ;
2439 SectRect( &viewRect
, &visBounds
, &viewRect
) ;
2440 TXNSetRectBounds( m_txn
, &viewRect
, &destRect
, true ) ;
2445 m_txnControlBounds
.top
,
2446 m_txnControlBounds
.left
,
2447 m_txnControlBounds
.bottom
- (m_sbHorizontal
? 14 : 0),
2448 m_txnControlBounds
.right
- (m_sbVertical
? 14 : 0),
2454 m_txn
, m_txnControlBounds
.top
, m_txnControlBounds
.left
,
2455 wxMax( m_txnControlBounds
.bottom
, m_txnControlBounds
.top
),
2456 wxMax( m_txnControlBounds
.right
, m_txnControlBounds
.left
), m_txnFrameID
);
2459 // the SetFrameBounds method under Classic sometimes does not correctly scroll a selection into sight after a
2460 // movement, therefore we have to force it
2462 // this problem has been reported in OSX as well, so we use this here once again
2464 TXNLongRect textRect
;
2465 TXNGetRectBounds( m_txn
, NULL
, NULL
, &textRect
) ;
2466 if ( textRect
.left
< m_txnControlBounds
.left
)
2467 TXNShowSelection( m_txn
, kTXNShowStart
) ;
2471 void wxMacMLTEClassicControl::SetRect( Rect
*r
)
2473 wxMacControl::SetRect( r
) ;
2474 MacUpdatePosition() ;
2477 void wxMacMLTEClassicControl::MacControlUserPaneDrawProc(wxInt16 thePart
)
2479 wxTextCtrl
* textctrl
= (wxTextCtrl
*)GetControlReference( m_controlRef
);
2480 if ( textctrl
== NULL
)
2483 if ( textctrl
->MacIsReallyShown() )
2485 wxMacWindowClipper
clipper( textctrl
) ;
2486 TXNDraw( m_txn
, NULL
) ;
2490 wxInt16
wxMacMLTEClassicControl::MacControlUserPaneHitTestProc(wxInt16 x
, wxInt16 y
)
2492 Point where
= { y
, x
} ;
2493 ControlPartCode result
= kControlNoPart
;
2495 wxTextCtrl
* textctrl
= (wxTextCtrl
*) GetControlReference( m_controlRef
);
2496 if ( (textctrl
!= NULL
) && textctrl
->MacIsReallyShown() )
2498 if (PtInRect( where
, &m_txnControlBounds
))
2500 result
= kControlEditTextPart
;
2504 // sometimes we get the coords also in control local coordinates, therefore test again
2505 if ( textctrl
->MacGetTopLevelWindow()->MacUsesCompositing() )
2508 textctrl
->MacClientToRootWindow( &x
, &y
) ;
2513 if (PtInRect( where
, &m_txnControlBounds
))
2514 result
= kControlEditTextPart
;
2521 wxInt16
wxMacMLTEClassicControl::MacControlUserPaneTrackingProc( wxInt16 x
, wxInt16 y
, void* actionProc
)
2523 ControlPartCode result
= kControlNoPart
;
2525 wxTextCtrl
* textctrl
= (wxTextCtrl
*) GetControlReference( m_controlRef
);
2526 if ( (textctrl
!= NULL
) && textctrl
->MacIsReallyShown() )
2528 Point startPt
= { y
, x
} ;
2529 // for compositing, we must convert these into toplevel window coordinates, because hittesting expects them
2530 if ( textctrl
->MacGetTopLevelWindow()->MacUsesCompositing() )
2533 textctrl
->MacClientToRootWindow( &x
, &y
) ;
2538 switch (MacControlUserPaneHitTestProc( startPt
.h
, startPt
.v
))
2540 case kControlEditTextPart
:
2542 wxMacWindowClipper
clipper( textctrl
) ;
2545 ConvertEventRefToEventRecord( (EventRef
) wxTheApp
->MacGetCurrentEvent() , &rec
) ;
2546 TXNClick( m_txn
, &rec
);
2558 void wxMacMLTEClassicControl::MacControlUserPaneIdleProc()
2560 wxTextCtrl
* textctrl
= (wxTextCtrl
*)GetControlReference( m_controlRef
);
2561 if ( textctrl
== NULL
)
2564 if (textctrl
->MacIsReallyShown())
2566 if (IsControlActive(m_controlRef
))
2570 wxMacWindowClipper
clipper( textctrl
) ;
2575 if (PtInRect(mousep
, &m_txnControlBounds
))
2577 RgnHandle theRgn
= NewRgn();
2578 RectRgn(theRgn
, &m_txnControlBounds
);
2579 TXNAdjustCursor(m_txn
, theRgn
);
2586 wxInt16
wxMacMLTEClassicControl::MacControlUserPaneKeyDownProc (wxInt16 keyCode
, wxInt16 charCode
, wxInt16 modifiers
)
2588 wxTextCtrl
* textctrl
= (wxTextCtrl
*)GetControlReference( m_controlRef
);
2589 if ( textctrl
== NULL
)
2590 return kControlNoPart
;
2592 wxMacWindowClipper
clipper( textctrl
) ;
2595 memset( &ev
, 0 , sizeof( ev
) ) ;
2597 ev
.modifiers
= modifiers
;
2598 ev
.message
= ((keyCode
<< 8) & keyCodeMask
) | (charCode
& charCodeMask
);
2599 TXNKeyDown( m_txn
, &ev
);
2601 return kControlEntireControl
;
2604 void wxMacMLTEClassicControl::MacControlUserPaneActivateProc(bool activating
)
2606 MacActivatePaneText( activating
);
2609 wxInt16
wxMacMLTEClassicControl::MacControlUserPaneFocusProc(wxInt16 action
)
2611 ControlPartCode focusResult
= kControlFocusNoPart
;
2613 wxTextCtrl
* textctrl
= (wxTextCtrl
*)GetControlReference( m_controlRef
);
2614 if ( textctrl
== NULL
)
2617 wxMacWindowClipper
clipper( textctrl
) ;
2619 ControlRef controlFocus
= NULL
;
2620 GetKeyboardFocus( m_txnWindow
, &controlFocus
) ;
2621 bool wasFocused
= ( controlFocus
== m_controlRef
) ;
2625 case kControlFocusPrevPart
:
2626 case kControlFocusNextPart
:
2627 MacFocusPaneText( !wasFocused
);
2628 focusResult
= (!wasFocused
? (ControlPartCode
) kControlEditTextPart
: (ControlPartCode
) kControlFocusNoPart
);
2631 case kControlFocusNoPart
:
2633 MacFocusPaneText( false );
2634 focusResult
= kControlFocusNoPart
;
2641 void wxMacMLTEClassicControl::MacControlUserPaneBackgroundProc( void *info
)
2645 wxMacMLTEClassicControl::wxMacMLTEClassicControl( wxTextCtrl
*wxPeer
,
2646 const wxString
& str
,
2648 const wxSize
& size
, long style
)
2649 : wxMacMLTEControl( wxPeer
)
2651 m_font
= wxPeer
->GetFont() ;
2652 m_windowStyle
= style
;
2653 Rect bounds
= wxMacGetBoundsForControl( wxPeer
, pos
, size
) ;
2656 kControlSupportsEmbedding
| kControlSupportsFocus
| kControlWantsIdle
2657 | kControlWantsActivate
| kControlHandlesTracking
2658 // | kControlHasSpecialBackground
2659 | kControlGetsFocusOnClick
| kControlSupportsLiveFeedback
;
2661 OSStatus err
= ::CreateUserPaneControl(
2662 MAC_WXHWND(wxPeer
->GetParent()->MacGetTopLevelWindowRef()),
2663 &bounds
, featureSet
, &m_controlRef
);
2664 verify_noerr( err
);
2668 AdjustCreationAttributes( *wxWHITE
, true ) ;
2670 MacSetObjectVisibility( wxPeer
->MacIsReallyShown() ) ;
2674 wxMacConvertNewlines10To13( &st
) ;
2675 wxMacWindowClipper
clipper( m_peer
) ;
2676 SetTXNData( st
, kTXNStartOffset
, kTXNEndOffset
) ;
2677 TXNSetSelection( m_txn
, 0, 0 ) ;
2681 wxMacMLTEClassicControl::~wxMacMLTEClassicControl()
2683 TXNDeleteObject( m_txn
);
2687 void wxMacMLTEClassicControl::VisibilityChanged(bool shown
)
2689 MacSetObjectVisibility( shown
) ;
2690 wxMacControl::VisibilityChanged( shown
) ;
2693 void wxMacMLTEClassicControl::SuperChangedPosition()
2695 MacUpdatePosition() ;
2696 wxMacControl::SuperChangedPosition() ;
2699 #ifdef __WXMAC_OSX__
2701 ControlUserPaneDrawUPP gTPDrawProc
= NULL
;
2702 ControlUserPaneHitTestUPP gTPHitProc
= NULL
;
2703 ControlUserPaneTrackingUPP gTPTrackProc
= NULL
;
2704 ControlUserPaneIdleUPP gTPIdleProc
= NULL
;
2705 ControlUserPaneKeyDownUPP gTPKeyProc
= NULL
;
2706 ControlUserPaneActivateUPP gTPActivateProc
= NULL
;
2707 ControlUserPaneFocusUPP gTPFocusProc
= NULL
;
2709 static pascal void wxMacControlUserPaneDrawProc(ControlRef control
, SInt16 part
)
2711 wxTextCtrl
*textCtrl
= wxDynamicCast( wxFindControlFromMacControl(control
) , wxTextCtrl
) ;
2712 wxMacMLTEClassicControl
* win
= textCtrl
? (wxMacMLTEClassicControl
*)(textCtrl
->GetPeer()) : NULL
;
2714 win
->MacControlUserPaneDrawProc( part
) ;
2717 static pascal ControlPartCode
wxMacControlUserPaneHitTestProc(ControlRef control
, Point where
)
2719 wxTextCtrl
*textCtrl
= wxDynamicCast( wxFindControlFromMacControl(control
) , wxTextCtrl
) ;
2720 wxMacMLTEClassicControl
* win
= textCtrl
? (wxMacMLTEClassicControl
*)(textCtrl
->GetPeer()) : NULL
;
2722 return win
->MacControlUserPaneHitTestProc( where
.h
, where
.v
) ;
2724 return kControlNoPart
;
2727 static pascal ControlPartCode
wxMacControlUserPaneTrackingProc(ControlRef control
, Point startPt
, ControlActionUPP actionProc
)
2729 wxTextCtrl
*textCtrl
= wxDynamicCast( wxFindControlFromMacControl(control
) , wxTextCtrl
) ;
2730 wxMacMLTEClassicControl
* win
= textCtrl
? (wxMacMLTEClassicControl
*)(textCtrl
->GetPeer()) : NULL
;
2732 return win
->MacControlUserPaneTrackingProc( startPt
.h
, startPt
.v
, (void*) actionProc
) ;
2734 return kControlNoPart
;
2737 static pascal void wxMacControlUserPaneIdleProc(ControlRef control
)
2739 wxTextCtrl
*textCtrl
= wxDynamicCast( wxFindControlFromMacControl(control
) , wxTextCtrl
) ;
2740 wxMacMLTEClassicControl
* win
= textCtrl
? (wxMacMLTEClassicControl
*)(textCtrl
->GetPeer()) : NULL
;
2742 win
->MacControlUserPaneIdleProc() ;
2745 static pascal ControlPartCode
wxMacControlUserPaneKeyDownProc(ControlRef control
, SInt16 keyCode
, SInt16 charCode
, SInt16 modifiers
)
2747 wxTextCtrl
*textCtrl
= wxDynamicCast( wxFindControlFromMacControl(control
) , wxTextCtrl
) ;
2748 wxMacMLTEClassicControl
* win
= textCtrl
? (wxMacMLTEClassicControl
*)(textCtrl
->GetPeer()) : NULL
;
2750 return win
->MacControlUserPaneKeyDownProc( keyCode
, charCode
, modifiers
) ;
2752 return kControlNoPart
;
2755 static pascal void wxMacControlUserPaneActivateProc(ControlRef control
, Boolean activating
)
2757 wxTextCtrl
*textCtrl
= wxDynamicCast( wxFindControlFromMacControl(control
) , wxTextCtrl
) ;
2758 wxMacMLTEClassicControl
* win
= textCtrl
? (wxMacMLTEClassicControl
*)(textCtrl
->GetPeer()) : NULL
;
2760 win
->MacControlUserPaneActivateProc( activating
) ;
2763 static pascal ControlPartCode
wxMacControlUserPaneFocusProc(ControlRef control
, ControlFocusPart action
)
2765 wxTextCtrl
*textCtrl
= wxDynamicCast( wxFindControlFromMacControl(control
) , wxTextCtrl
) ;
2766 wxMacMLTEClassicControl
* win
= textCtrl
? (wxMacMLTEClassicControl
*)(textCtrl
->GetPeer()) : NULL
;
2768 return win
->MacControlUserPaneFocusProc( action
) ;
2770 return kControlNoPart
;
2774 static pascal void wxMacControlUserPaneBackgroundProc(ControlRef control
, ControlBackgroundPtr info
)
2776 wxTextCtrl
*textCtrl
= wxDynamicCast( wxFindControlFromMacControl(control
) , wxTextCtrl
) ;
2777 wxMacMLTEClassicControl
* win
= textCtrl
? (wxMacMLTEClassicControl
*)(textCtrl
->GetPeer()) : NULL
;
2779 win
->MacControlUserPaneBackgroundProc(info
) ;
2783 #endif // __WXMAC_OSX__
2785 // TXNRegisterScrollInfoProc
2787 OSStatus
wxMacMLTEClassicControl::DoCreate()
2790 OSStatus err
= noErr
;
2792 // set up our globals
2793 #ifdef __WXMAC_OSX__
2794 if (gTPDrawProc
== NULL
) gTPDrawProc
= NewControlUserPaneDrawUPP(wxMacControlUserPaneDrawProc
);
2795 if (gTPHitProc
== NULL
) gTPHitProc
= NewControlUserPaneHitTestUPP(wxMacControlUserPaneHitTestProc
);
2796 if (gTPTrackProc
== NULL
) gTPTrackProc
= NewControlUserPaneTrackingUPP(wxMacControlUserPaneTrackingProc
);
2797 if (gTPIdleProc
== NULL
) gTPIdleProc
= NewControlUserPaneIdleUPP(wxMacControlUserPaneIdleProc
);
2798 if (gTPKeyProc
== NULL
) gTPKeyProc
= NewControlUserPaneKeyDownUPP(wxMacControlUserPaneKeyDownProc
);
2799 if (gTPActivateProc
== NULL
) gTPActivateProc
= NewControlUserPaneActivateUPP(wxMacControlUserPaneActivateProc
);
2800 if (gTPFocusProc
== NULL
) gTPFocusProc
= NewControlUserPaneFocusUPP(wxMacControlUserPaneFocusProc
);
2802 if (gTXNScrollInfoProc
== NULL
) gTXNScrollInfoProc
= NewTXNScrollInfoUPP(TXNScrollInfoProc
) ;
2803 if (gTXNScrollActionProc
== NULL
) gTXNScrollActionProc
= NewControlActionUPP(TXNScrollActionProc
) ;
2806 // set the initial settings for our private data
2808 m_txnWindow
= GetControlOwner(m_controlRef
);
2809 m_txnPort
= (GrafPtr
) GetWindowPort(m_txnWindow
);
2811 #ifdef __WXMAC_OSX__
2812 // set up the user pane procedures
2813 SetControlData(m_controlRef
, kControlEntireControl
, kControlUserPaneDrawProcTag
, sizeof(gTPDrawProc
), &gTPDrawProc
);
2814 SetControlData(m_controlRef
, kControlEntireControl
, kControlUserPaneHitTestProcTag
, sizeof(gTPHitProc
), &gTPHitProc
);
2815 SetControlData(m_controlRef
, kControlEntireControl
, kControlUserPaneTrackingProcTag
, sizeof(gTPTrackProc
), &gTPTrackProc
);
2816 SetControlData(m_controlRef
, kControlEntireControl
, kControlUserPaneIdleProcTag
, sizeof(gTPIdleProc
), &gTPIdleProc
);
2817 SetControlData(m_controlRef
, kControlEntireControl
, kControlUserPaneKeyDownProcTag
, sizeof(gTPKeyProc
), &gTPKeyProc
);
2818 SetControlData(m_controlRef
, kControlEntireControl
, kControlUserPaneActivateProcTag
, sizeof(gTPActivateProc
), &gTPActivateProc
);
2819 SetControlData(m_controlRef
, kControlEntireControl
, kControlUserPaneFocusProcTag
, sizeof(gTPFocusProc
), &gTPFocusProc
);
2822 // calculate the rectangles used by the control
2823 UMAGetControlBoundsInWindowCoords( m_controlRef
, &bounds
);
2825 m_txnControlBounds
= bounds
;
2826 m_txnVisBounds
= bounds
;
2831 GetGWorld( &origPort
, &origDev
) ;
2832 SetPort( m_txnPort
);
2834 // create the new edit field
2835 TXNFrameOptions frameOptions
= FrameOptionsFromWXStyle( m_windowStyle
);
2837 #ifdef __WXMAC_OSX__
2838 // the scrollbars are not correctly embedded but are inserted at the root:
2839 // this gives us problems as we have erratic redraws even over the structure area
2841 m_sbHorizontal
= 0 ;
2843 m_lastHorizontalValue
= 0 ;
2844 m_lastVerticalValue
= 0 ;
2846 Rect sb
= { 0 , 0 , 0 , 0 } ;
2847 if ( frameOptions
& kTXNWantVScrollBarMask
)
2849 CreateScrollBarControl( m_txnWindow
, &sb
, 0, 0, 100, 1, true, gTXNScrollActionProc
, &m_sbVertical
);
2850 SetControlReference( m_sbVertical
, (SInt32
)this );
2851 SetControlAction( m_sbVertical
, gTXNScrollActionProc
);
2852 ShowControl( m_sbVertical
);
2853 EmbedControl( m_sbVertical
, m_controlRef
);
2854 frameOptions
&= ~kTXNWantVScrollBarMask
;
2857 if ( frameOptions
& kTXNWantHScrollBarMask
)
2859 CreateScrollBarControl( m_txnWindow
, &sb
, 0, 0, 100, 1, true, gTXNScrollActionProc
, &m_sbHorizontal
);
2860 SetControlReference( m_sbHorizontal
, (SInt32
)this );
2861 SetControlAction( m_sbHorizontal
, gTXNScrollActionProc
);
2862 ShowControl( m_sbHorizontal
);
2863 EmbedControl( m_sbHorizontal
, m_controlRef
);
2864 frameOptions
&= ~(kTXNWantHScrollBarMask
| kTXNDrawGrowIconMask
);
2870 NULL
, m_txnWindow
, &bounds
, frameOptions
,
2871 kTXNTextEditStyleFrameType
, kTXNTextensionFile
, kTXNSystemDefaultEncoding
,
2872 &m_txn
, &m_txnFrameID
, NULL
);
2873 verify_noerr( err
);
2876 TXNControlTag iControlTags
[] = { kTXNUseCarbonEvents
};
2877 TXNControlData iControlData
[] = { { (UInt32
)&cInfo
} };
2878 int toptag
= WXSIZEOF( iControlTags
) ;
2879 TXNCarbonEventInfo cInfo
;
2880 cInfo
.useCarbonEvents
= false ;
2883 cInfo
.fDictionary
= NULL
;
2885 verify_noerr( TXNSetTXNObjectControls( m_txn
, false, toptag
, iControlTags
, iControlData
) );
2888 #ifdef __WXMAC_OSX__
2889 TXNRegisterScrollInfoProc( m_txn
, gTXNScrollInfoProc
, (SInt32
)this );
2892 SetGWorld( origPort
, origDev
) ;
2897 // ----------------------------------------------------------------------------
2898 // MLTE control implementation (OSX part)
2899 // ----------------------------------------------------------------------------
2901 #if TARGET_API_MAC_OSX
2903 #if MAC_OS_X_VERSION_MAX_ALLOWED > MAC_OS_X_VERSION_10_2
2905 wxMacMLTEHIViewControl::wxMacMLTEHIViewControl( wxTextCtrl
*wxPeer
,
2906 const wxString
& str
,
2908 const wxSize
& size
, long style
) : wxMacMLTEControl( wxPeer
)
2910 m_font
= wxPeer
->GetFont() ;
2911 m_windowStyle
= style
;
2912 Rect bounds
= wxMacGetBoundsForControl( wxPeer
, pos
, size
) ;
2914 wxMacConvertNewlines10To13( &st
) ;
2917 { bounds
.left
, bounds
.top
},
2918 { bounds
.right
- bounds
.left
, bounds
.bottom
- bounds
.top
} } ;
2920 m_scrollView
= NULL
;
2921 TXNFrameOptions frameOptions
= FrameOptionsFromWXStyle( style
) ;
2922 if ( frameOptions
& (kTXNWantVScrollBarMask
| kTXNWantHScrollBarMask
) )
2925 (frameOptions
& kTXNWantHScrollBarMask
? kHIScrollViewOptionsHorizScroll
: 0)
2926 | (frameOptions
& kTXNWantVScrollBarMask
? kHIScrollViewOptionsVertScroll
: 0) ,
2929 HIViewSetFrame( m_scrollView
, &hr
);
2930 HIViewSetVisible( m_scrollView
, true );
2934 HITextViewCreate( NULL
, 0, frameOptions
, &m_textView
) ;
2935 m_txn
= HITextViewGetTXNObject( m_textView
) ;
2936 HIViewSetVisible( m_textView
, true ) ;
2939 HIViewAddSubview( m_scrollView
, m_textView
) ;
2940 m_controlRef
= m_scrollView
;
2941 wxPeer
->MacInstallEventHandler( (WXWidget
) m_textView
) ;
2945 HIViewSetFrame( m_textView
, &hr
);
2946 m_controlRef
= m_textView
;
2949 AdjustCreationAttributes( *wxWHITE
, true ) ;
2951 wxMacWindowClipper
c( m_peer
) ;
2952 SetTXNData( st
, kTXNStartOffset
, kTXNEndOffset
) ;
2954 TXNSetSelection( m_txn
, 0, 0 );
2955 TXNShowSelection( m_txn
, kTXNShowStart
);
2958 OSStatus
wxMacMLTEHIViewControl::SetFocus( ControlFocusPart focusPart
)
2960 return SetKeyboardFocus( GetControlOwner( m_textView
), m_textView
, focusPart
) ;
2963 bool wxMacMLTEHIViewControl::HasFocus() const
2965 ControlRef control
;
2966 GetKeyboardFocus( GetUserFocusWindow() , &control
) ;
2967 return control
== m_textView
;
2970 void wxMacMLTEHIViewControl::SetBackground( const wxBrush
&brush
)
2972 wxMacMLTEControl::SetBackground( brush
) ;
2975 CGColorSpaceRef rgbSpace
= CGColorSpaceCreateDeviceRGB();
2976 RGBColor col
= MAC_WXCOLORREF(brush
.GetColour().GetPixel()) ;
2978 float component
[4] ;
2979 component
[0] = col
.red
/ 65536.0 ;
2980 component
[1] = col
.green
/ 65536.0 ;
2981 component
[2] = col
.blue
/ 65536.0 ;
2982 component
[3] = 1.0 ; // alpha
2984 CGColorRef color
= CGColorCreate( rgbSpace
, component
);
2985 HITextViewSetBackgroundColor( m_textView
, color
);
2986 CGColorSpaceRelease( rgbSpace
);
2990 #endif // MAC_OS_X_VERSION_MAX_ALLOWED > MAC_OS_X_VERSION_10_2
2995 #endif // wxUSE_TEXTCTRL