1 /////////////////////////////////////////////////////////////////////////////
4 // Author: Stefan Csomor
5 // Modified by: Ryan Norton (MLTE GetLineLength and GetLineText)
8 // Copyright: (c) Stefan Csomor
9 // Licence: wxWindows licence
10 /////////////////////////////////////////////////////////////////////////////
12 #include "wx/wxprec.h"
18 #include <sys/types.h>
24 #include "wx/msgdlg.h"
26 #if wxUSE_STD_IOSTREAM
36 #include "wx/button.h"
37 #include "wx/toplevel.h"
38 #include "wx/textctrl.h"
39 #include "wx/settings.h"
40 #include "wx/filefn.h"
42 #include "wx/sysopt.h"
46 #if defined(__BORLANDC__) && !defined(__WIN32__)
48 #elif !defined(__MWERKS__) && !defined(__GNUWIN32) && !defined(__DARWIN__)
57 #include <MacTextEditor.h>
58 #include <ATSUnicode.h>
59 #include <TextCommon.h>
60 #include <TextEncodingConverter.h>
63 #include "wx/mac/uma.h"
66 // if this is set to 1 then under OSX 10.2 the 'classic' MLTE implementation will be used
67 // if set to 0 then the unicode textctrl will be used
68 #ifndef wxMAC_AWAYS_USE_MLTE
69 #define wxMAC_AWAYS_USE_MLTE 1
75 kTXNVisibilityTag
= 'visb' // set the visibility state of the object
84 virtual ~wxMacFunctor() {}
86 virtual void* operator()() = 0 ;
88 static void* CallBackProc( void *param
)
90 wxMacFunctor
* f
= (wxMacFunctor
*) param
;
91 void *result
= (*f
)() ;
96 template<typename classtype
, typename param1type
>
98 class wxMacObjectFunctor1
: public wxMacFunctor
100 typedef void (classtype::*function
)( param1type p1
) ;
101 typedef void (classtype::*ref_function
)( const param1type
& p1
) ;
103 wxMacObjectFunctor1( classtype
*obj
, function f
, param1type p1
) :
111 wxMacObjectFunctor1( classtype
*obj
, ref_function f
, param1type p1
) :
119 ~wxMacObjectFunctor1() {}
121 virtual void* operator()()
123 (m_object
->*m_function
)( m_param1
) ;
128 classtype
* m_object
;
129 param1type m_param1
;
132 function m_function
;
133 ref_function m_refFunction
;
137 template<typename classtype
, typename param1type
>
138 void* wxMacMPRemoteCall( classtype
*object
, void (classtype::*function
)( param1type p1
) , param1type p1
)
140 wxMacObjectFunctor1
<classtype
, param1type
> params(object
, function
, p1
) ;
142 MPRemoteCall( wxMacFunctor::CallBackProc
, ¶ms
, kMPOwningProcessRemoteContext
) ;
146 template<typename classtype
, typename param1type
>
147 void* wxMacMPRemoteCall( classtype
*object
, void (classtype::*function
)( const param1type
& p1
) , param1type p1
)
149 wxMacObjectFunctor1
<classtype
,param1type
> params(object
, function
, p1
) ;
151 MPRemoteCall( wxMacFunctor::CallBackProc
, ¶ms
, kMPOwningProcessRemoteContext
) ;
155 template<typename classtype
, typename param1type
>
156 void* wxMacMPRemoteGUICall( classtype
*object
, void (classtype::*function
)( param1type p1
) , param1type p1
)
159 void *result
= wxMacMPRemoteCall( object
, function
, p1
) ;
164 template<typename classtype
, typename param1type
>
165 void* wxMacMPRemoteGUICall( classtype
*object
, void (classtype::*function
)( const param1type
& p1
) , param1type p1
)
168 void *result
= wxMacMPRemoteCall( object
, function
, p1
) ;
173 // common interface for all implementations
174 class wxMacTextControl
: public wxMacControl
177 wxMacTextControl( wxTextCtrl
*peer
) ;
178 ~wxMacTextControl() ;
180 virtual wxString
GetStringValue() const = 0 ;
181 virtual void SetStringValue( const wxString
&val
) = 0 ;
182 virtual void SetSelection( long from
, long to
) = 0 ;
183 virtual void GetSelection( long* from
, long* to
) const = 0 ;
184 virtual void WriteText( const wxString
& str
) = 0 ;
186 virtual void SetStyle( long start
, long end
, const wxTextAttr
& style
) ;
187 virtual void Copy() ;
189 virtual void Paste() ;
190 virtual bool CanPaste() const ;
191 virtual void SetEditable( bool editable
) ;
192 virtual wxTextPos
GetLastPosition() const ;
193 virtual void Replace( long from
, long to
, const wxString
&str
) ;
194 virtual void Remove( long from
, long to
) ;
197 virtual bool HasOwnContextMenu() const
200 virtual bool SetupCursor( const wxPoint
& pt
)
203 virtual void Clear() ;
204 virtual bool CanUndo() const;
205 virtual void Undo() ;
206 virtual bool CanRedo() const;
207 virtual void Redo() ;
208 virtual int GetNumberOfLines() const ;
209 virtual long XYToPosition(long x
, long y
) const;
210 virtual bool PositionToXY(long pos
, long *x
, long *y
) const ;
211 virtual void ShowPosition(long WXUNUSED(pos
)) ;
212 virtual int GetLineLength(long lineNo
) const ;
213 virtual wxString
GetLineText(long lineNo
) const ;
215 #ifndef __WXMAC_OSX__
216 virtual void MacControlUserPaneDrawProc(wxInt16 part
) = 0 ;
217 virtual wxInt16
MacControlUserPaneHitTestProc(wxInt16 x
, wxInt16 y
) = 0 ;
218 virtual wxInt16
MacControlUserPaneTrackingProc(wxInt16 x
, wxInt16 y
, void* actionProc
) = 0 ;
219 virtual void MacControlUserPaneIdleProc() = 0 ;
220 virtual wxInt16
MacControlUserPaneKeyDownProc(wxInt16 keyCode
, wxInt16 charCode
, wxInt16 modifiers
) = 0 ;
221 virtual void MacControlUserPaneActivateProc(bool activating
) = 0 ;
222 virtual wxInt16
MacControlUserPaneFocusProc(wxInt16 action
) = 0 ;
223 virtual void MacControlUserPaneBackgroundProc(void* info
) = 0 ;
227 // common parts for implementations based on MLTE
229 class wxMacMLTEControl
: public wxMacTextControl
232 wxMacMLTEControl( wxTextCtrl
*peer
) ;
234 virtual wxString
GetStringValue() const ;
235 virtual void SetStringValue( const wxString
&str
) ;
237 static TXNFrameOptions
FrameOptionsFromWXStyle( long wxStyle
) ;
239 void AdjustCreationAttributes( const wxColour
& background
, bool visible
) ;
241 virtual void SetFont( const wxFont
& font
, const wxColour
& foreground
, long windowStyle
) ;
242 virtual void SetBackground( const wxBrush
&brush
) ;
243 virtual void SetStyle( long start
, long end
, const wxTextAttr
& style
) ;
244 virtual void Copy() ;
246 virtual void Paste() ;
247 virtual bool CanPaste() const ;
248 virtual void SetEditable( bool editable
) ;
249 virtual wxTextPos
GetLastPosition() const ;
250 virtual void Replace( long from
, long to
, const wxString
&str
) ;
251 virtual void Remove( long from
, long to
) ;
252 virtual void GetSelection( long* from
, long* to
) const ;
253 virtual void SetSelection( long from
, long to
) ;
255 virtual void WriteText( const wxString
& str
) ;
257 virtual bool HasOwnContextMenu() const
259 #if MAC_OS_X_VERSION_MAX_ALLOWED >= MAC_OS_X_VERSION_10_4
260 if ( UMAGetSystemVersion() >= 0x1040 )
262 TXNCommandEventSupportOptions options
;
263 TXNGetCommandEventSupport( m_txn
, & options
) ;
264 return options
& kTXNSupportEditCommandProcessing
;
271 virtual void Clear() ;
273 virtual bool CanUndo() const ;
274 virtual void Undo() ;
275 virtual bool CanRedo() const;
276 virtual void Redo() ;
277 virtual int GetNumberOfLines() const ;
278 virtual long XYToPosition(long x
, long y
) const ;
279 virtual bool PositionToXY(long pos
, long *x
, long *y
) const ;
280 virtual void ShowPosition( long pos
) ;
281 virtual int GetLineLength(long lineNo
) const ;
282 virtual wxString
GetLineText(long lineNo
) const ;
284 void SetTXNData( const wxString
& st
, TXNOffset start
, TXNOffset end
) ;
287 void TXNSetAttribute( const wxTextAttr
& style
, long from
, long to
) ;
292 #if TARGET_API_MAC_OSX
294 // implementation available under OSX
296 #if MAC_OS_X_VERSION_MAX_ALLOWED > MAC_OS_X_VERSION_10_2
298 class wxMacMLTEHIViewControl
: public wxMacMLTEControl
301 wxMacMLTEHIViewControl( wxTextCtrl
*wxPeer
,
304 const wxSize
& size
, long style
) ;
305 virtual OSStatus
SetFocus( ControlFocusPart focusPart
) ;
306 virtual bool HasFocus() const ;
307 virtual void SetBackground( const wxBrush
&brush
) ;
310 HIViewRef m_scrollView
;
311 HIViewRef m_textView
;
316 class wxMacUnicodeTextControl
: public wxMacTextControl
319 wxMacUnicodeTextControl( wxTextCtrl
*wxPeer
,
322 const wxSize
& size
, long style
) ;
323 ~wxMacUnicodeTextControl();
325 virtual void VisibilityChanged(bool shown
);
326 virtual wxString
GetStringValue() const ;
327 virtual void SetStringValue( const wxString
&str
) ;
330 virtual void Paste();
331 virtual bool CanPaste() const;
332 virtual void SetEditable(bool editable
) ;
333 virtual void GetSelection( long* from
, long* to
) const ;
334 virtual void SetSelection( long from
, long to
) ;
335 virtual void WriteText(const wxString
& str
) ;
338 // contains the tag for the content (is different for password and non-password controls)
344 // 'classic' MLTE implementation
346 class wxMacMLTEClassicControl
: public wxMacMLTEControl
349 wxMacMLTEClassicControl( wxTextCtrl
*wxPeer
,
352 const wxSize
& size
, long style
) ;
353 ~wxMacMLTEClassicControl() ;
355 virtual void VisibilityChanged(bool shown
) ;
356 virtual void SuperChangedPosition() ;
358 virtual void MacControlUserPaneDrawProc(wxInt16 part
) ;
359 virtual wxInt16
MacControlUserPaneHitTestProc(wxInt16 x
, wxInt16 y
) ;
360 virtual wxInt16
MacControlUserPaneTrackingProc(wxInt16 x
, wxInt16 y
, void* actionProc
) ;
361 virtual void MacControlUserPaneIdleProc() ;
362 virtual wxInt16
MacControlUserPaneKeyDownProc(wxInt16 keyCode
, wxInt16 charCode
, wxInt16 modifiers
) ;
363 virtual void MacControlUserPaneActivateProc(bool activating
) ;
364 virtual wxInt16
MacControlUserPaneFocusProc(wxInt16 action
) ;
365 virtual void MacControlUserPaneBackgroundProc(void* info
) ;
367 virtual bool SetupCursor( const wxPoint
& WXUNUSED(pt
) )
369 MacControlUserPaneIdleProc();
373 virtual void SetRect( Rect
*r
) ;
378 void MacUpdatePosition() ;
379 void MacActivatePaneText(bool setActive
) ;
380 void MacFocusPaneText(bool setFocus
) ;
381 void MacSetObjectVisibility(bool vis
) ;
384 TXNFrameID m_txnFrameID
;
386 WindowRef m_txnWindow
;
387 // bounds of the control as we last did set the txn frames
388 Rect m_txnControlBounds
;
389 Rect m_txnVisBounds
;
392 static pascal void TXNScrollActionProc( ControlRef controlRef
, ControlPartCode partCode
) ;
393 static pascal void TXNScrollInfoProc(
394 SInt32 iValue
, SInt32 iMaximumValue
,
395 TXNScrollBarOrientation iScrollBarOrientation
, SInt32 iRefCon
) ;
397 ControlRef m_sbHorizontal
;
398 SInt32 m_lastHorizontalValue
;
399 ControlRef m_sbVertical
;
400 SInt32 m_lastVerticalValue
;
404 #define TE_UNLIMITED_LENGTH 0xFFFFFFFFUL
407 IMPLEMENT_DYNAMIC_CLASS(wxTextCtrl
, wxControl
)
409 BEGIN_EVENT_TABLE(wxTextCtrl
, wxControl
)
410 EVT_ERASE_BACKGROUND( wxTextCtrl::OnEraseBackground
)
411 EVT_DROP_FILES(wxTextCtrl::OnDropFiles
)
412 EVT_CHAR(wxTextCtrl::OnChar
)
413 EVT_MENU(wxID_CUT
, wxTextCtrl::OnCut
)
414 EVT_MENU(wxID_COPY
, wxTextCtrl::OnCopy
)
415 EVT_MENU(wxID_PASTE
, wxTextCtrl::OnPaste
)
416 EVT_MENU(wxID_UNDO
, wxTextCtrl::OnUndo
)
417 EVT_MENU(wxID_REDO
, wxTextCtrl::OnRedo
)
418 EVT_MENU(wxID_CLEAR
, wxTextCtrl::OnDelete
)
419 EVT_MENU(wxID_SELECTALL
, wxTextCtrl::OnSelectAll
)
421 EVT_CONTEXT_MENU(wxTextCtrl::OnContextMenu
)
423 EVT_UPDATE_UI(wxID_CUT
, wxTextCtrl::OnUpdateCut
)
424 EVT_UPDATE_UI(wxID_COPY
, wxTextCtrl::OnUpdateCopy
)
425 EVT_UPDATE_UI(wxID_PASTE
, wxTextCtrl::OnUpdatePaste
)
426 EVT_UPDATE_UI(wxID_UNDO
, wxTextCtrl::OnUpdateUndo
)
427 EVT_UPDATE_UI(wxID_REDO
, wxTextCtrl::OnUpdateRedo
)
428 EVT_UPDATE_UI(wxID_CLEAR
, wxTextCtrl::OnUpdateDelete
)
429 EVT_UPDATE_UI(wxID_SELECTALL
, wxTextCtrl::OnUpdateSelectAll
)
433 void wxTextCtrl::Init()
438 m_maxLength
= TE_UNLIMITED_LENGTH
;
439 m_privateContextMenu
= NULL
;
442 wxTextCtrl::~wxTextCtrl()
444 delete m_privateContextMenu
;
447 bool wxTextCtrl::Create( wxWindow
*parent
,
453 const wxValidator
& validator
,
454 const wxString
& name
)
456 m_macIsUserPane
= false ;
459 if ( ! (style
& wxNO_BORDER
) )
460 style
= (style
& ~wxBORDER_MASK
) | wxSUNKEN_BORDER
;
462 if ( !wxTextCtrlBase::Create( parent
, id
, pos
, size
, style
& ~(wxHSCROLL
| wxVSCROLL
), validator
, name
) )
465 if ( m_windowStyle
& wxTE_MULTILINE
)
468 !(m_windowStyle
& wxTE_PROCESS_ENTER
),
469 wxT("wxTE_PROCESS_ENTER style is ignored for multiline text controls (they always process it)") );
471 m_windowStyle
|= wxTE_PROCESS_ENTER
;
472 style
|= wxTE_PROCESS_ENTER
;
475 bool forceMLTE
= false ;
477 #if wxUSE_SYSTEM_OPTIONS
478 if (wxSystemOptions::HasOption( wxMAC_TEXTCONTROL_USE_MLTE
) && (wxSystemOptions::GetOptionInt( wxMAC_TEXTCONTROL_USE_MLTE
) == 1))
485 #if MAC_OS_X_VERSION_MAX_ALLOWED > MAC_OS_X_VERSION_10_2
486 if ( UMAGetSystemVersion() >= 0x1030 && !forceMLTE
)
488 if ( m_windowStyle
& wxTE_MULTILINE
)
489 m_peer
= new wxMacMLTEHIViewControl( this , str
, pos
, size
, style
) ;
495 if ( !(m_windowStyle
& wxTE_MULTILINE
) && !forceMLTE
)
496 m_peer
= new wxMacUnicodeTextControl( this , str
, pos
, size
, style
) ;
501 m_peer
= new wxMacMLTEClassicControl( this , str
, pos
, size
, style
) ;
503 MacPostControlCreate(pos
, size
) ;
505 // only now the embedding is correct and we can do a positioning update
507 MacSuperChangedPosition() ;
509 if ( m_windowStyle
& wxTE_READONLY
)
510 SetEditable( false ) ;
512 SetCursor( wxCursor( wxCURSOR_IBEAM
) ) ;
517 void wxTextCtrl::MacSuperChangedPosition()
519 wxWindow::MacSuperChangedPosition() ;
520 GetPeer()->SuperChangedPosition() ;
523 void wxTextCtrl::MacVisibilityChanged()
525 GetPeer()->VisibilityChanged( MacIsReallyShown() ) ;
528 void wxTextCtrl::MacEnabledStateChanged()
532 wxString
wxTextCtrl::GetValue() const
534 return GetPeer()->GetStringValue() ;
537 void wxTextCtrl::GetSelection(long* from
, long* to
) const
539 GetPeer()->GetSelection( from
, to
) ;
542 void wxTextCtrl::SetValue(const wxString
& str
)
545 if ( GetValue() == str
)
548 GetPeer()->SetStringValue( str
) ;
550 wxCommandEvent
event( wxEVT_COMMAND_TEXT_UPDATED
, m_windowId
);
551 event
.SetString( GetValue() );
552 event
.SetEventObject( this );
553 GetEventHandler()->ProcessEvent( event
);
556 void wxTextCtrl::SetMaxLength(unsigned long len
)
561 bool wxTextCtrl::SetFont( const wxFont
& font
)
563 if ( !wxTextCtrlBase::SetFont( font
) )
566 GetPeer()->SetFont( font
, GetForegroundColour() , GetWindowStyle() ) ;
571 bool wxTextCtrl::SetStyle(long start
, long end
, const wxTextAttr
& style
)
573 GetPeer()->SetStyle( start
, end
, style
) ;
578 bool wxTextCtrl::SetDefaultStyle(const wxTextAttr
& style
)
580 wxTextCtrlBase::SetDefaultStyle( style
) ;
581 SetStyle( kTXNUseCurrentSelection
, kTXNUseCurrentSelection
, GetDefaultStyle() ) ;
586 // Clipboard operations
588 void wxTextCtrl::Copy()
594 void wxTextCtrl::Cut()
600 wxCommandEvent
event( wxEVT_COMMAND_TEXT_UPDATED
, m_windowId
);
601 event
.SetEventObject( this );
602 GetEventHandler()->ProcessEvent( event
);
606 void wxTextCtrl::Paste()
612 // TODO: eventually we should add setting the default style again
614 wxCommandEvent
event( wxEVT_COMMAND_TEXT_UPDATED
, m_windowId
);
615 event
.SetEventObject( this );
616 GetEventHandler()->ProcessEvent( event
);
620 bool wxTextCtrl::CanCopy() const
622 // Can copy if there's a selection
624 GetSelection( &from
, &to
);
629 bool wxTextCtrl::CanCut() const
634 // Can cut if there's a selection
636 GetSelection( &from
, &to
);
641 bool wxTextCtrl::CanPaste() const
646 return GetPeer()->CanPaste() ;
649 void wxTextCtrl::SetEditable(bool editable
)
651 if ( editable
!= m_editable
)
653 m_editable
= editable
;
654 GetPeer()->SetEditable( editable
) ;
658 void wxTextCtrl::SetInsertionPoint(long pos
)
660 SetSelection( pos
, pos
) ;
663 void wxTextCtrl::SetInsertionPointEnd()
665 wxTextPos pos
= GetLastPosition();
666 SetInsertionPoint( pos
);
669 long wxTextCtrl::GetInsertionPoint() const
672 GetSelection( &begin
, &end
) ;
677 wxTextPos
wxTextCtrl::GetLastPosition() const
679 return GetPeer()->GetLastPosition() ;
682 void wxTextCtrl::Replace(long from
, long to
, const wxString
& str
)
684 GetPeer()->Replace( from
, to
, str
) ;
687 void wxTextCtrl::Remove(long from
, long to
)
689 GetPeer()->Remove( from
, to
) ;
692 void wxTextCtrl::SetSelection(long from
, long to
)
694 GetPeer()->SetSelection( from
, to
) ;
697 bool wxTextCtrl::LoadFile(const wxString
& file
)
699 return wxTextCtrlBase::LoadFile( file
);
702 void wxTextCtrl::WriteText(const wxString
& str
)
704 // TODO: this MPRemoting will be moved into a remoting peer proxy for any command
705 if ( !wxIsMainThread() )
707 // unfortunately CW 8 is not able to correctly deduce the template types,
708 // so we have to instantiate explicitly
709 wxMacMPRemoteGUICall
<wxTextCtrl
,wxString
>( this , &wxTextCtrl::WriteText
, str
) ;
714 GetPeer()->WriteText( str
) ;
717 void wxTextCtrl::AppendText(const wxString
& text
)
719 SetInsertionPointEnd();
723 void wxTextCtrl::Clear()
728 bool wxTextCtrl::IsModified() const
733 bool wxTextCtrl::IsEditable() const
735 return IsEnabled() && m_editable
;
738 bool wxTextCtrl::AcceptsFocus() const
740 // we don't want focus if we can't be edited
741 return /*IsEditable() && */ wxControl::AcceptsFocus();
744 wxSize
wxTextCtrl::DoGetBestSize() const
748 // these are the numbers from the HIG:
749 // we reduce them by the borders first
752 switch ( m_windowVariant
)
754 case wxWINDOW_VARIANT_NORMAL
:
758 case wxWINDOW_VARIANT_SMALL
:
762 case wxWINDOW_VARIANT_MINI
:
771 // as the above numbers have some free space around the text
772 // we get 5 lines like this anyway
773 if ( m_windowStyle
& wxTE_MULTILINE
)
776 if ( !HasFlag(wxNO_BORDER
) )
779 return wxSize(wText
, hText
);
782 // ----------------------------------------------------------------------------
784 // ----------------------------------------------------------------------------
786 void wxTextCtrl::Undo()
792 void wxTextCtrl::Redo()
798 bool wxTextCtrl::CanUndo() const
803 return GetPeer()->CanUndo() ;
806 bool wxTextCtrl::CanRedo() const
811 return GetPeer()->CanRedo() ;
814 void wxTextCtrl::MarkDirty()
819 void wxTextCtrl::DiscardEdits()
824 int wxTextCtrl::GetNumberOfLines() const
826 return GetPeer()->GetNumberOfLines() ;
829 long wxTextCtrl::XYToPosition(long x
, long y
) const
831 return GetPeer()->XYToPosition( x
, y
) ;
834 bool wxTextCtrl::PositionToXY(long pos
, long *x
, long *y
) const
836 return GetPeer()->PositionToXY( pos
, x
, y
) ;
839 void wxTextCtrl::ShowPosition(long pos
)
841 return GetPeer()->ShowPosition(pos
) ;
844 int wxTextCtrl::GetLineLength(long lineNo
) const
846 return GetPeer()->GetLineLength(lineNo
) ;
849 wxString
wxTextCtrl::GetLineText(long lineNo
) const
851 return GetPeer()->GetLineText(lineNo
) ;
854 void wxTextCtrl::Command(wxCommandEvent
& event
)
856 SetValue(event
.GetString());
857 ProcessCommand(event
);
860 void wxTextCtrl::OnDropFiles(wxDropFilesEvent
& event
)
862 // By default, load the first file into the text window.
863 if (event
.GetNumberOfFiles() > 0)
864 LoadFile( event
.GetFiles()[0] );
867 void wxTextCtrl::OnEraseBackground(wxEraseEvent
& event
)
869 // all erasing should be done by the real mac control implementation
870 // while this is true for MLTE under classic, the HITextView is somehow
871 // transparent but background erase is not working correctly, so intercept
872 // things while we can...
876 void wxTextCtrl::OnChar(wxKeyEvent
& event
)
878 int key
= event
.GetKeyCode() ;
879 bool eat_key
= false ;
881 if ( key
== 'c' && event
.MetaDown() )
889 if ( !IsEditable() && key
!= WXK_LEFT
&& key
!= WXK_RIGHT
&& key
!= WXK_DOWN
&& key
!= WXK_UP
&& key
!= WXK_TAB
&&
890 !( key
== WXK_RETURN
&& ( (m_windowStyle
& wxPROCESS_ENTER
) || (m_windowStyle
& wxTE_MULTILINE
) ) )
891 // && key != WXK_PRIOR && key != WXK_NEXT && key != WXK_HOME && key != WXK_END
898 // Check if we have reached the max # of chars, but still allow navigation and deletion
899 if ( !IsMultiLine() && GetValue().Length() >= m_maxLength
&&
900 key
!= WXK_LEFT
&& key
!= WXK_RIGHT
&& key
!= WXK_TAB
&&
901 key
!= WXK_BACK
&& !( key
== WXK_RETURN
&& (m_windowStyle
& wxPROCESS_ENTER
) )
904 // eat it, we don't want to add more than allowed # of characters
908 // assume that any key not processed yet is going to modify the control
911 if ( key
== 'v' && event
.MetaDown() )
919 if ( key
== 'x' && event
.MetaDown() )
930 if (m_windowStyle
& wxPROCESS_ENTER
)
932 wxCommandEvent
event(wxEVT_COMMAND_TEXT_ENTER
, m_windowId
);
933 event
.SetEventObject( this );
934 event
.SetString( GetValue() );
935 if ( GetEventHandler()->ProcessEvent(event
) )
939 if ( !(m_windowStyle
& wxTE_MULTILINE
) )
941 wxWindow
*parent
= GetParent();
942 while ( parent
&& !parent
->IsTopLevel() && parent
->GetDefaultItem() == NULL
)
944 parent
= parent
->GetParent() ;
947 if ( parent
&& parent
->GetDefaultItem() )
949 wxButton
*def
= wxDynamicCast(parent
->GetDefaultItem(), wxButton
);
950 if ( def
&& def
->IsEnabled() )
952 wxCommandEvent
event(wxEVT_COMMAND_BUTTON_CLICKED
, def
->GetId() );
953 event
.SetEventObject(def
);
960 // this will make wxWidgets eat the ENTER key so that
961 // we actually prevent line wrapping in a single line text control
967 if ( !(m_windowStyle
& wxTE_PROCESS_TAB
))
970 if (!event
.ShiftDown())
971 flags
|= wxNavigationKeyEvent::IsForward
;
972 if (event
.ControlDown())
973 flags
|= wxNavigationKeyEvent::WinChange
;
980 // This is necessary (don't know why);
981 // otherwise the tab will not be inserted.
982 WriteText(wxT("\t"));
992 // perform keystroke handling
996 if ( ( key
>= 0x20 && key
< WXK_START
) ||
1001 wxCommandEvent
event1(wxEVT_COMMAND_TEXT_UPDATED
, m_windowId
);
1002 event1
.SetEventObject( this );
1003 wxPostEvent( GetEventHandler(), event1
);
1007 // ----------------------------------------------------------------------------
1008 // standard handlers for standard edit menu events
1009 // ----------------------------------------------------------------------------
1011 void wxTextCtrl::OnCut(wxCommandEvent
& WXUNUSED(event
))
1016 void wxTextCtrl::OnCopy(wxCommandEvent
& WXUNUSED(event
))
1021 void wxTextCtrl::OnPaste(wxCommandEvent
& WXUNUSED(event
))
1026 void wxTextCtrl::OnUndo(wxCommandEvent
& WXUNUSED(event
))
1031 void wxTextCtrl::OnRedo(wxCommandEvent
& WXUNUSED(event
))
1036 void wxTextCtrl::OnDelete(wxCommandEvent
& WXUNUSED(event
))
1040 GetSelection( &from
, &to
);
1041 if (from
!= -1 && to
!= -1)
1045 void wxTextCtrl::OnSelectAll(wxCommandEvent
& WXUNUSED(event
))
1047 SetSelection(-1, -1);
1050 void wxTextCtrl::OnUpdateCut(wxUpdateUIEvent
& event
)
1052 event
.Enable( CanCut() );
1055 void wxTextCtrl::OnUpdateCopy(wxUpdateUIEvent
& event
)
1057 event
.Enable( CanCopy() );
1060 void wxTextCtrl::OnUpdatePaste(wxUpdateUIEvent
& event
)
1062 event
.Enable( CanPaste() );
1065 void wxTextCtrl::OnUpdateUndo(wxUpdateUIEvent
& event
)
1067 event
.Enable( CanUndo() );
1070 void wxTextCtrl::OnUpdateRedo(wxUpdateUIEvent
& event
)
1072 event
.Enable( CanRedo() );
1075 void wxTextCtrl::OnUpdateDelete(wxUpdateUIEvent
& event
)
1079 GetSelection( &from
, &to
);
1080 event
.Enable( from
!= -1 && to
!= -1 && from
!= to
&& IsEditable() ) ;
1083 void wxTextCtrl::OnUpdateSelectAll(wxUpdateUIEvent
& event
)
1085 event
.Enable(GetLastPosition() > 0);
1088 // CS: Context Menus only work with MLTE implementations or non-multiline HIViews at the moment
1090 void wxTextCtrl::OnContextMenu(wxContextMenuEvent
& event
)
1092 if ( GetPeer()->HasOwnContextMenu() )
1098 if (m_privateContextMenu
== NULL
)
1100 m_privateContextMenu
= new wxMenu
;
1101 m_privateContextMenu
->Append(wxID_UNDO
, _("&Undo"));
1102 m_privateContextMenu
->Append(wxID_REDO
, _("&Redo"));
1103 m_privateContextMenu
->AppendSeparator();
1104 m_privateContextMenu
->Append(wxID_CUT
, _("Cu&t"));
1105 m_privateContextMenu
->Append(wxID_COPY
, _("&Copy"));
1106 m_privateContextMenu
->Append(wxID_PASTE
, _("&Paste"));
1107 m_privateContextMenu
->Append(wxID_CLEAR
, _("&Delete"));
1108 m_privateContextMenu
->AppendSeparator();
1109 m_privateContextMenu
->Append(wxID_SELECTALL
, _("Select &All"));
1112 if (m_privateContextMenu
!= NULL
)
1113 PopupMenu(m_privateContextMenu
);
1116 bool wxTextCtrl::MacSetupCursor( const wxPoint
& pt
)
1118 if ( !GetPeer()->SetupCursor( pt
) )
1119 return wxWindow::MacSetupCursor( pt
) ;
1124 #if !TARGET_API_MAC_OSX
1126 // user pane implementation
1128 void wxTextCtrl::MacControlUserPaneDrawProc(wxInt16 part
)
1130 GetPeer()->MacControlUserPaneDrawProc( part
) ;
1133 wxInt16
wxTextCtrl::MacControlUserPaneHitTestProc(wxInt16 x
, wxInt16 y
)
1135 return GetPeer()->MacControlUserPaneHitTestProc( x
, y
) ;
1138 wxInt16
wxTextCtrl::MacControlUserPaneTrackingProc(wxInt16 x
, wxInt16 y
, void* actionProc
)
1140 return GetPeer()->MacControlUserPaneTrackingProc( x
, y
, actionProc
) ;
1143 void wxTextCtrl::MacControlUserPaneIdleProc()
1145 GetPeer()->MacControlUserPaneIdleProc( ) ;
1148 wxInt16
wxTextCtrl::MacControlUserPaneKeyDownProc(wxInt16 keyCode
, wxInt16 charCode
, wxInt16 modifiers
)
1150 return GetPeer()->MacControlUserPaneKeyDownProc( keyCode
, charCode
, modifiers
) ;
1153 void wxTextCtrl::MacControlUserPaneActivateProc(bool activating
)
1155 GetPeer()->MacControlUserPaneActivateProc( activating
) ;
1158 wxInt16
wxTextCtrl::MacControlUserPaneFocusProc(wxInt16 action
)
1160 return GetPeer()->MacControlUserPaneFocusProc( action
) ;
1163 void wxTextCtrl::MacControlUserPaneBackgroundProc(void* info
)
1165 GetPeer()->MacControlUserPaneBackgroundProc( info
) ;
1170 // ----------------------------------------------------------------------------
1171 // implementation base class
1172 // ----------------------------------------------------------------------------
1174 wxMacTextControl::wxMacTextControl(wxTextCtrl
* peer
) :
1175 wxMacControl( peer
)
1179 wxMacTextControl::~wxMacTextControl()
1183 void wxMacTextControl::SetStyle(long start
, long end
, const wxTextAttr
& style
)
1187 void wxMacTextControl::Copy()
1191 void wxMacTextControl::Cut()
1195 void wxMacTextControl::Paste()
1199 bool wxMacTextControl::CanPaste() const
1204 void wxMacTextControl::SetEditable(bool editable
)
1208 wxTextPos
wxMacTextControl::GetLastPosition() const
1210 return GetStringValue().Length() ;
1213 void wxMacTextControl::Replace( long from
, long to
, const wxString
&val
)
1215 SetSelection( from
, to
) ;
1219 void wxMacTextControl::Remove( long from
, long to
)
1221 SetSelection( from
, to
) ;
1222 WriteText( wxEmptyString
) ;
1225 void wxMacTextControl::Clear()
1227 SetStringValue( wxEmptyString
) ;
1230 bool wxMacTextControl::CanUndo() const
1235 void wxMacTextControl::Undo()
1239 bool wxMacTextControl::CanRedo() const
1244 void wxMacTextControl::Redo()
1248 long wxMacTextControl::XYToPosition(long x
, long y
) const
1253 bool wxMacTextControl::PositionToXY(long pos
, long *x
, long *y
) const
1258 void wxMacTextControl::ShowPosition( long WXUNUSED(pos
) )
1262 int wxMacTextControl::GetNumberOfLines() const
1264 ItemCount lines
= 0 ;
1265 wxString content
= GetStringValue() ;
1268 for (size_t i
= 0; i
< content
.Length() ; i
++)
1270 if (content
[i
] == '\r')
1277 wxString
wxMacTextControl::GetLineText(long lineNo
) const
1279 // TODO: change this if possible to reflect real lines
1280 wxString content
= GetStringValue() ;
1284 for (size_t i
= 0; i
< content
.Length() ; i
++)
1286 if (count
== lineNo
)
1288 // Add chars in line then
1291 for (size_t j
= i
; j
< content
.Length(); j
++)
1293 if (content
[j
] == '\n')
1302 if (content
[i
] == '\n')
1306 return wxEmptyString
;
1309 int wxMacTextControl::GetLineLength(long lineNo
) const
1311 // TODO: change this if possible to reflect real lines
1312 wxString content
= GetStringValue() ;
1316 for (size_t i
= 0; i
< content
.Length() ; i
++)
1318 if (count
== lineNo
)
1320 // Count chars in line then
1322 for (size_t j
= i
; j
< content
.Length(); j
++)
1325 if (content
[j
] == '\n')
1332 if (content
[i
] == '\n')
1339 // ----------------------------------------------------------------------------
1340 // standard unicode control implementation
1341 // ----------------------------------------------------------------------------
1343 #if TARGET_API_MAC_OSX
1345 wxMacUnicodeTextControl::wxMacUnicodeTextControl( wxTextCtrl
*wxPeer
,
1346 const wxString
& str
,
1348 const wxSize
& size
, long style
)
1349 : wxMacTextControl( wxPeer
)
1351 m_font
= wxPeer
->GetFont() ;
1352 m_windowStyle
= style
;
1353 Rect bounds
= wxMacGetBoundsForControl( wxPeer
, pos
, size
) ;
1355 wxMacConvertNewlines10To13( &st
) ;
1356 wxMacCFStringHolder
cf(st
, m_font
.GetEncoding()) ;
1357 CFStringRef cfr
= cf
;
1358 Boolean isPassword
= ( m_windowStyle
& wxTE_PASSWORD
) != 0 ;
1359 m_valueTag
= isPassword
? kControlEditTextPasswordCFStringTag
: kControlEditTextCFStringTag
;
1361 OSStatus err
= CreateEditUnicodeTextControl(
1362 MAC_WXHWND(wxPeer
->MacGetTopLevelWindowRef()), &bounds
, cfr
,
1363 isPassword
, NULL
, &m_controlRef
) ;
1364 verify_noerr( err
);
1366 if ( !(m_windowStyle
& wxTE_MULTILINE
) )
1367 SetData
<Boolean
>( kControlEditTextPart
, kControlEditTextSingleLineTag
, true ) ;
1370 wxMacUnicodeTextControl::~wxMacUnicodeTextControl()
1374 void wxMacUnicodeTextControl::VisibilityChanged(bool shown
)
1376 if ( !(m_windowStyle
& wxTE_MULTILINE
) && shown
)
1378 // work around a refresh issue insofar as not always the entire content is shown,
1379 // even if this would be possible
1380 ControlEditTextSelectionRec sel
;
1381 CFStringRef value
= NULL
;
1383 verify_noerr( GetData
<ControlEditTextSelectionRec
>( 0, kControlEditTextSelectionTag
, &sel
) );
1384 verify_noerr( GetData
<CFStringRef
>( 0, m_valueTag
, &value
) );
1385 verify_noerr( SetData
<CFStringRef
>( 0, m_valueTag
, &value
) );
1386 verify_noerr( SetData
<ControlEditTextSelectionRec
>( 0, kControlEditTextSelectionTag
, &sel
) );
1388 CFRelease( value
) ;
1392 wxString
wxMacUnicodeTextControl::GetStringValue() const
1395 CFStringRef value
= GetData
<CFStringRef
>(0, m_valueTag
) ;
1398 wxMacCFStringHolder
cf(value
) ;
1399 result
= cf
.AsString() ;
1403 wxMacConvertNewlines13To10( &result
) ;
1405 wxMacConvertNewlines10To13( &result
) ;
1411 void wxMacUnicodeTextControl::SetStringValue( const wxString
&str
)
1414 wxMacConvertNewlines10To13( &st
) ;
1415 wxMacCFStringHolder
cf( st
, m_font
.GetEncoding() ) ;
1416 verify_noerr( SetData
<CFStringRef
>( 0, m_valueTag
, cf
) ) ;
1419 void wxMacUnicodeTextControl::Copy()
1421 SendHICommand( kHICommandCopy
) ;
1424 void wxMacUnicodeTextControl::Cut()
1426 SendHICommand( kHICommandCut
) ;
1429 void wxMacUnicodeTextControl::Paste()
1431 SendHICommand( kHICommandPaste
) ;
1434 bool wxMacUnicodeTextControl::CanPaste() const
1439 void wxMacUnicodeTextControl::SetEditable(bool editable
)
1441 SetData
<Boolean
>( 0 , kControlEditTextLockedTag
, (Boolean
) !editable
) ;
1444 void wxMacUnicodeTextControl::GetSelection( long* from
, long* to
) const
1446 ControlEditTextSelectionRec sel
;
1447 verify_noerr( GetData
<ControlEditTextSelectionRec
>( 0, kControlEditTextSelectionTag
, &sel
) ) ;
1449 *from
= sel
.selStart
;
1454 void wxMacUnicodeTextControl::SetSelection( long from
, long to
)
1456 ControlEditTextSelectionRec sel
;
1457 if ((from
== -1) && (to
== -1))
1460 to
= 32767 ; // sel has 16 bit signed values, max is 32767
1463 sel
.selStart
= from
;
1465 SetData
<ControlEditTextSelectionRec
>( 0, kControlEditTextSelectionTag
, &sel
) ;
1468 void wxMacUnicodeTextControl::WriteText( const wxString
& str
)
1471 wxMacConvertNewlines10To13( &st
) ;
1473 #if MAC_OS_X_VERSION_MAX_ALLOWED > MAC_OS_X_VERSION_10_2
1474 wxMacCFStringHolder
cf(st
, m_font
.GetEncoding() ) ;
1475 CFStringRef value
= cf
;
1476 SetData
<CFStringRef
>( 0, kControlEditTextInsertCFStringRefTag
, &value
);
1478 wxString val
= GetStringValue() ;
1480 GetSelection( &start
, &end
) ;
1481 val
.Remove( start
, end
- start
) ;
1482 val
.insert( start
, str
) ;
1483 SetStringValue( val
) ;
1484 SetSelection( start
+ str
.Length() , start
+ str
.Length() ) ;
1490 // ----------------------------------------------------------------------------
1491 // MLTE control implementation (common part)
1492 // ----------------------------------------------------------------------------
1494 // if MTLE is read only, no changes at all are allowed, not even from
1495 // procedural API, in order to allow changes via API all the same we must undo
1496 // the readonly status while we are executing, this class helps to do so
1498 class wxMacEditHelper
1501 wxMacEditHelper( TXNObject txn
)
1503 TXNControlTag tag
[] = { kTXNIOPrivilegesTag
} ;
1505 TXNGetTXNObjectControls( m_txn
, 1 , tag
, m_data
) ;
1506 if ( m_data
[0].uValue
== kTXNReadOnly
)
1508 TXNControlData data
[] = { { kTXNReadWrite
} } ;
1509 TXNSetTXNObjectControls( m_txn
, false , 1 , tag
, data
) ;
1515 TXNControlTag tag
[] = { kTXNIOPrivilegesTag
} ;
1516 if ( m_data
[0].uValue
== kTXNReadOnly
)
1517 TXNSetTXNObjectControls( m_txn
, false , 1 , tag
, m_data
) ;
1522 TXNControlData m_data
[1] ;
1525 wxMacMLTEControl::wxMacMLTEControl( wxTextCtrl
*peer
)
1526 : wxMacTextControl( peer
)
1528 SetNeedsFocusRect( true ) ;
1531 wxString
wxMacMLTEControl::GetStringValue() const
1535 Size actualSize
= 0;
1540 err
= TXNGetDataEncoded( m_txn
, kTXNStartOffset
, kTXNEndOffset
, &theText
, kTXNUnicodeTextData
);
1549 actualSize
= GetHandleSize( theText
) / sizeof(UniChar
) ;
1550 if ( actualSize
> 0 )
1552 wxChar
*ptr
= NULL
;
1554 #if SIZEOF_WCHAR_T == 2
1555 ptr
= new wxChar
[actualSize
+ 1] ;
1556 wxStrncpy( ptr
, (wxChar
*)(*theText
) , actualSize
) ;
1558 SetHandleSize( theText
, (actualSize
+ 1) * sizeof(UniChar
) ) ;
1560 (((UniChar
*)*theText
)[actualSize
]) = 0 ;
1561 wxMBConvUTF16 converter
;
1562 size_t noChars
= converter
.MB2WC( NULL
, (const char*)*theText
, 0 ) ;
1563 ptr
= new wxChar
[noChars
+ 1] ;
1565 noChars
= converter
.MB2WC( ptr
, (const char*)*theText
, noChars
) ;
1567 HUnlock( theText
) ;
1570 ptr
[actualSize
] = 0 ;
1571 result
= wxString( ptr
) ;
1575 DisposeHandle( theText
) ;
1579 err
= TXNGetDataEncoded( m_txn
, kTXNStartOffset
, kTXNEndOffset
, &theText
, kTXNTextData
);
1588 actualSize
= GetHandleSize( theText
) ;
1589 if ( actualSize
> 0 )
1592 result
= wxString( *theText
, wxConvLocal
, actualSize
) ;
1593 HUnlock( theText
) ;
1596 DisposeHandle( theText
) ;
1602 wxMacConvertNewlines13To10( &result
) ;
1604 wxMacConvertNewlines10To13( &result
) ;
1610 void wxMacMLTEControl::SetStringValue( const wxString
&str
)
1613 wxMacConvertNewlines10To13( &st
);
1616 wxMacWindowClipper
c( m_peer
);
1619 wxMacEditHelper
help( m_txn
);
1620 SetTXNData( st
, kTXNStartOffset
, kTXNEndOffset
);
1623 TXNSetSelection( m_txn
, 0, 0 );
1624 TXNShowSelection( m_txn
, kTXNShowStart
);
1628 TXNFrameOptions
wxMacMLTEControl::FrameOptionsFromWXStyle( long wxStyle
)
1630 TXNFrameOptions frameOptions
= kTXNDontDrawCaretWhenInactiveMask
;
1632 #if MAC_OS_X_VERSION_MAX_ALLOWED >= MAC_OS_X_VERSION_10_3
1633 frameOptions
|= kTXNDoFontSubstitutionMask
;
1636 if ( ! (wxStyle
& wxTE_NOHIDESEL
) )
1637 frameOptions
|= kTXNDontDrawSelectionWhenInactiveMask
;
1639 if ( wxStyle
& (wxHSCROLL
| wxTE_DONTWRAP
) )
1640 frameOptions
|= kTXNWantHScrollBarMask
;
1642 if ( wxStyle
& wxTE_MULTILINE
)
1644 frameOptions
|= kTXNAlwaysWrapAtViewEdgeMask
;
1646 if ( !(wxStyle
& wxTE_NO_VSCROLL
) )
1648 frameOptions
|= kTXNWantVScrollBarMask
;
1650 // The following code causes drawing problems on 10.4. Perhaps it can be restored for
1651 // older versions of the OS, but I'm not sure it's appropriate to put a grow icon here
1652 // anyways, as AFAIK users can't actually use it to resize the text ctrl.
1653 // if ( frameOptions & kTXNWantHScrollBarMask )
1654 // frameOptions |= kTXNDrawGrowIconMask ;
1659 frameOptions
|= kTXNSingleLineOnlyMask
;
1662 return frameOptions
;
1665 void wxMacMLTEControl::AdjustCreationAttributes( const wxColour
&background
, bool visible
)
1667 TXNControlTag iControlTags
[] =
1669 kTXNDoFontSubstitution
,
1670 kTXNWordWrapStateTag
,
1672 TXNControlData iControlData
[] =
1678 int toptag
= WXSIZEOF( iControlTags
) ;
1680 if ( m_windowStyle
& wxTE_MULTILINE
)
1682 iControlData
[1].uValue
=
1683 (m_windowStyle
& wxTE_DONTWRAP
)
1688 OSStatus err
= TXNSetTXNObjectControls( m_txn
, false, toptag
, iControlTags
, iControlData
) ;
1689 verify_noerr( err
);
1691 // setting the default font:
1692 // under 10.2 this causes a visible caret, therefore we avoid it
1694 if ( UMAGetSystemVersion() >= 0x1030 )
1700 GetThemeFont( kThemeSystemFont
, GetApplicationScript() , fontName
, &fontSize
, &fontStyle
) ;
1702 TXNTypeAttributes typeAttr
[] =
1704 { kTXNQDFontNameAttribute
, kTXNQDFontNameAttributeSize
, { (void*) fontName
} } ,
1705 { kTXNQDFontSizeAttribute
, kTXNFontSizeAttributeSize
, { (void*) (fontSize
<< 16) } } ,
1706 { kTXNQDFontStyleAttribute
, kTXNQDFontStyleAttributeSize
, { (void*) normal
} } ,
1709 err
= TXNSetTypeAttributes(
1710 m_txn
, sizeof(typeAttr
) / sizeof(TXNTypeAttributes
),
1711 typeAttr
, kTXNStartOffset
, kTXNEndOffset
);
1712 verify_noerr( err
);
1715 if ( m_windowStyle
& wxTE_PASSWORD
)
1717 UniChar c
= 0x00A5 ;
1718 err
= TXNEchoMode( m_txn
, c
, 0 , true );
1719 verify_noerr( err
);
1722 TXNBackground tback
;
1723 tback
.bgType
= kTXNBackgroundTypeRGB
;
1724 tback
.bg
.color
= MAC_WXCOLORREF( background
.GetPixel() );
1725 TXNSetBackground( m_txn
, &tback
);
1727 #if MAC_OS_X_VERSION_MAX_ALLOWED >= MAC_OS_X_VERSION_10_4
1728 if ( UMAGetSystemVersion() >= 0x1040 )
1730 TXNCommandEventSupportOptions options
;
1731 if ( TXNGetCommandEventSupport( m_txn
, &options
) == noErr
)
1734 kTXNSupportEditCommandProcessing
1735 | kTXNSupportEditCommandUpdating
1736 | kTXNSupportSpellCheckCommandProcessing
1737 | kTXNSupportSpellCheckCommandUpdating
1738 | kTXNSupportFontCommandProcessing
1739 | kTXNSupportFontCommandUpdating
;
1741 TXNSetCommandEventSupport( m_txn
, options
) ;
1747 void wxMacMLTEControl::SetBackground( const wxBrush
&brush
)
1749 // currently only solid background are supported
1750 TXNBackground tback
;
1752 tback
.bgType
= kTXNBackgroundTypeRGB
;
1753 tback
.bg
.color
= MAC_WXCOLORREF( brush
.GetColour().GetPixel() );
1754 TXNSetBackground( m_txn
, &tback
);
1757 void wxMacMLTEControl::TXNSetAttribute( const wxTextAttr
& style
, long from
, long to
)
1759 TXNTypeAttributes typeAttr
[4] ;
1760 Str255 fontName
= "\pMonaco" ;
1761 SInt16 fontSize
= 12 ;
1762 Style fontStyle
= normal
;
1766 if ( style
.HasFont() )
1768 const wxFont
&font
= style
.GetFont() ;
1769 wxMacStringToPascal( font
.GetFaceName() , fontName
) ;
1770 fontSize
= font
.GetPointSize() ;
1771 if ( font
.GetUnderlined() )
1772 fontStyle
|= underline
;
1773 if ( font
.GetWeight() == wxBOLD
)
1775 if ( font
.GetStyle() == wxITALIC
)
1776 fontStyle
|= italic
;
1778 typeAttr
[attrCount
].tag
= kTXNQDFontNameAttribute
;
1779 typeAttr
[attrCount
].size
= kTXNQDFontNameAttributeSize
;
1780 typeAttr
[attrCount
].data
.dataPtr
= (void*)fontName
;
1783 typeAttr
[attrCount
].tag
= kTXNQDFontSizeAttribute
;
1784 typeAttr
[attrCount
].size
= kTXNFontSizeAttributeSize
;
1785 typeAttr
[attrCount
].data
.dataValue
= (fontSize
<< 16) ;
1788 typeAttr
[attrCount
].tag
= kTXNQDFontStyleAttribute
;
1789 typeAttr
[attrCount
].size
= kTXNQDFontStyleAttributeSize
;
1790 typeAttr
[attrCount
].data
.dataValue
= fontStyle
;
1794 if ( style
.HasTextColour() )
1796 color
= MAC_WXCOLORREF(style
.GetTextColour().GetPixel()) ;
1798 typeAttr
[attrCount
].tag
= kTXNQDFontColorAttribute
;
1799 typeAttr
[attrCount
].size
= kTXNQDFontColorAttributeSize
;
1800 typeAttr
[attrCount
].data
.dataPtr
= (void*) &color
;
1804 if ( attrCount
> 0 )
1806 verify_noerr( TXNSetTypeAttributes( m_txn
, attrCount
, typeAttr
, from
, to
) );
1810 void wxMacMLTEControl::SetFont( const wxFont
& font
, const wxColour
& foreground
, long windowStyle
)
1812 wxMacEditHelper
help( m_txn
) ;
1813 TXNSetAttribute( wxTextAttr( foreground
, wxNullColour
, font
), kTXNStartOffset
, kTXNEndOffset
) ;
1816 void wxMacMLTEControl::SetStyle( long start
, long end
, const wxTextAttr
& style
)
1818 wxMacEditHelper
help( m_txn
) ;
1819 TXNSetAttribute( style
, start
, end
) ;
1822 void wxMacMLTEControl::Copy()
1824 ClearCurrentScrap();
1826 TXNConvertToPublicScrap();
1829 void wxMacMLTEControl::Cut()
1831 ClearCurrentScrap();
1833 TXNConvertToPublicScrap();
1836 void wxMacMLTEControl::Paste()
1838 TXNConvertFromPublicScrap();
1842 bool wxMacMLTEControl::CanPaste() const
1844 return TXNIsScrapPastable() ;
1847 void wxMacMLTEControl::SetEditable(bool editable
)
1849 TXNControlTag tag
[] = { kTXNIOPrivilegesTag
} ;
1850 TXNControlData data
[] = { { editable
? kTXNReadWrite
: kTXNReadOnly
} } ;
1851 TXNSetTXNObjectControls( m_txn
, false, WXSIZEOF(tag
), tag
, data
) ;
1854 wxTextPos
wxMacMLTEControl::GetLastPosition() const
1856 wxTextPos actualsize
= 0 ;
1859 OSErr err
= TXNGetDataEncoded( m_txn
, kTXNStartOffset
, kTXNEndOffset
, &theText
, kTXNTextData
);
1864 actualsize
= GetHandleSize( theText
) ;
1865 DisposeHandle( theText
) ;
1875 void wxMacMLTEControl::Replace( long from
, long to
, const wxString
&str
)
1877 wxString value
= str
;
1878 wxMacConvertNewlines10To13( &value
) ;
1880 wxMacEditHelper
help( m_txn
) ;
1881 wxMacWindowClipper
c( m_peer
) ;
1883 TXNSetSelection( m_txn
, from
, to
) ;
1885 SetTXNData( value
, kTXNUseCurrentSelection
, kTXNUseCurrentSelection
) ;
1888 void wxMacMLTEControl::Remove( long from
, long to
)
1890 wxMacWindowClipper
c( m_peer
) ;
1891 wxMacEditHelper
help( m_txn
) ;
1892 TXNSetSelection( m_txn
, from
, to
) ;
1896 void wxMacMLTEControl::GetSelection( long* from
, long* to
) const
1898 TXNGetSelection( m_txn
, (TXNOffset
*) from
, (TXNOffset
*) to
) ;
1901 void wxMacMLTEControl::SetSelection( long from
, long to
)
1903 wxMacWindowClipper
c( m_peer
) ;
1905 // change the selection
1906 if ((from
== -1) && (to
== -1))
1907 TXNSelectAll( m_txn
);
1909 TXNSetSelection( m_txn
, from
, to
);
1911 TXNShowSelection( m_txn
, kTXNShowStart
);
1914 void wxMacMLTEControl::WriteText( const wxString
& str
)
1917 wxMacConvertNewlines10To13( &st
) ;
1919 long start
, end
, dummy
;
1921 GetSelection( &start
, &dummy
) ;
1922 wxMacWindowClipper
c( m_peer
) ;
1925 wxMacEditHelper
helper( m_txn
) ;
1926 SetTXNData( st
, kTXNUseCurrentSelection
, kTXNUseCurrentSelection
) ;
1929 GetSelection( &dummy
, &end
) ;
1931 // TODO: SetStyle( start , end , GetDefaultStyle() ) ;
1934 void wxMacMLTEControl::Clear()
1936 wxMacWindowClipper
c( m_peer
) ;
1937 wxMacEditHelper
st( m_txn
) ;
1938 TXNSetSelection( m_txn
, kTXNStartOffset
, kTXNEndOffset
) ;
1942 bool wxMacMLTEControl::CanUndo() const
1944 return TXNCanUndo( m_txn
, NULL
) ;
1947 void wxMacMLTEControl::Undo()
1952 bool wxMacMLTEControl::CanRedo() const
1954 return TXNCanRedo( m_txn
, NULL
) ;
1957 void wxMacMLTEControl::Redo()
1962 int wxMacMLTEControl::GetNumberOfLines() const
1964 ItemCount lines
= 0 ;
1965 TXNGetLineCount( m_txn
, &lines
) ;
1970 long wxMacMLTEControl::XYToPosition(long x
, long y
) const
1975 // TODO: find a better implementation : while we can get the
1976 // line metrics of a certain line, we don't get its starting
1977 // position, so it would probably be rather a binary search
1978 // for the start position
1979 long xpos
= 0, ypos
= 0 ;
1980 int lastHeight
= 0 ;
1983 lastpos
= GetLastPosition() ;
1984 for ( n
= 0 ; n
<= (ItemCount
) lastpos
; ++n
)
1986 if ( y
== ypos
&& x
== xpos
)
1989 TXNOffsetToPoint( m_txn
, n
, &curpt
) ;
1991 if ( curpt
.v
> lastHeight
)
1997 lastHeight
= curpt
.v
;
2006 bool wxMacMLTEControl::PositionToXY( long pos
, long *x
, long *y
) const
2016 lastpos
= GetLastPosition() ;
2017 if ( pos
<= lastpos
)
2019 // TODO: find a better implementation - while we can get the
2020 // line metrics of a certain line, we don't get its starting
2021 // position, so it would probably be rather a binary search
2022 // for the start position
2023 long xpos
= 0, ypos
= 0 ;
2024 int lastHeight
= 0 ;
2027 for ( n
= 0 ; n
<= (ItemCount
) pos
; ++n
)
2029 TXNOffsetToPoint( m_txn
, n
, &curpt
) ;
2031 if ( curpt
.v
> lastHeight
)
2037 lastHeight
= curpt
.v
;
2052 void wxMacMLTEControl::ShowPosition( long pos
)
2054 #if TARGET_RT_MAC_MACHO && defined(AVAILABLE_MAC_OS_X_VERSION_10_2_AND_LATER)
2056 Point current
, desired
;
2057 TXNOffset selstart
, selend
;
2059 TXNGetSelection( m_txn
, &selstart
, &selend
);
2060 TXNOffsetToPoint( m_txn
, selstart
, ¤t
);
2061 TXNOffsetToPoint( m_txn
, pos
, &desired
);
2063 // TODO: use HIPoints for 10.3 and above
2064 if ( (UInt32
)TXNScroll
!= (UInt32
)kUnresolvedCFragSymbolAddress
)
2066 OSErr theErr
= noErr
;
2067 SInt32 dv
= desired
.v
- current
.v
;
2068 SInt32 dh
= desired
.h
- current
.h
;
2069 TXNShowSelection( m_txn
, kTXNShowStart
) ; // NB: should this be kTXNShowStart or kTXNShowEnd ??
2070 theErr
= TXNScroll( m_txn
, kTXNScrollUnitsInPixels
, kTXNScrollUnitsInPixels
, &dv
, &dh
);
2072 // there will be an error returned for classic MLTE implementation when the control is
2073 // invisible, but HITextView works correctly, so we don't assert that one
2074 // wxASSERT_MSG( theErr == noErr, _T("TXNScroll returned an error!") );
2080 void wxMacMLTEControl::SetTXNData( const wxString
& st
, TXNOffset start
, TXNOffset end
)
2083 #if SIZEOF_WCHAR_T == 2
2084 size_t len
= st
.Len() ;
2085 TXNSetData( m_txn
, kTXNUnicodeTextData
, (void*)st
.wc_str(), len
* 2, start
, end
);
2087 wxMBConvUTF16 converter
;
2088 ByteCount byteBufferLen
= converter
.WC2MB( NULL
, st
.wc_str(), 0 ) ;
2089 UniChar
*unibuf
= (UniChar
*)malloc( byteBufferLen
) ;
2090 converter
.WC2MB( (char*)unibuf
, st
.wc_str(), byteBufferLen
) ;
2091 TXNSetData( m_txn
, kTXNUnicodeTextData
, (void*)unibuf
, byteBufferLen
, start
, end
) ;
2095 wxCharBuffer text
= st
.mb_str( wxConvLocal
) ;
2096 TXNSetData( m_txn
, kTXNTextData
, (void*)text
.data(), strlen( text
), start
, end
) ;
2100 wxString
wxMacMLTEControl::GetLineText(long lineNo
) const
2104 if ( lineNo
< GetNumberOfLines() )
2107 Fixed lineWidth
, lineHeight
, currentHeight
;
2110 // get the first possible position in the control
2111 TXNOffsetToPoint(m_txn
, 0, &firstPoint
);
2113 // Iterate through the lines until we reach the one we want,
2114 // adding to our current y pixel point position
2117 while (ypos
< lineNo
)
2119 TXNGetLineMetrics(m_txn
, ypos
++, &lineWidth
, &lineHeight
);
2120 currentHeight
+= lineHeight
;
2123 Point thePoint
= { firstPoint
.v
+ (currentHeight
>> 16), firstPoint
.h
+ (0) };
2124 TXNOffset theOffset
;
2125 TXNPointToOffset(m_txn
, thePoint
, &theOffset
);
2127 wxString content
= GetStringValue() ;
2128 Point currentPoint
= thePoint
;
2129 while (thePoint
.v
== currentPoint
.v
&& theOffset
< content
.length())
2131 line
+= content
[theOffset
];
2132 TXNOffsetToPoint(m_txn
, ++theOffset
, ¤tPoint
);
2139 int wxMacMLTEControl::GetLineLength(long lineNo
) const
2143 if ( lineNo
< GetNumberOfLines() )
2146 Fixed lineWidth
, lineHeight
, currentHeight
;
2149 // get the first possible position in the control
2150 TXNOffsetToPoint(m_txn
, 0, &firstPoint
);
2152 // Iterate through the lines until we reach the one we want,
2153 // adding to our current y pixel point position
2156 while (ypos
< lineNo
)
2158 TXNGetLineMetrics(m_txn
, ypos
++, &lineWidth
, &lineHeight
);
2159 currentHeight
+= lineHeight
;
2162 Point thePoint
= { firstPoint
.v
+ (currentHeight
>> 16), firstPoint
.h
+ (0) };
2163 TXNOffset theOffset
;
2164 TXNPointToOffset(m_txn
, thePoint
, &theOffset
);
2166 wxString content
= GetStringValue() ;
2167 Point currentPoint
= thePoint
;
2168 while (thePoint
.v
== currentPoint
.v
&& theOffset
< content
.length())
2171 TXNOffsetToPoint(m_txn
, ++theOffset
, ¤tPoint
);
2178 // ----------------------------------------------------------------------------
2179 // MLTE control implementation (classic part)
2180 // ----------------------------------------------------------------------------
2182 // OS X Notes : We still don't have a full replacement for MLTE, so this implementation
2183 // has to live on. We have different problems coming from outdated implementations on the
2184 // various OS X versions. Most deal with the scrollbars: they are not correctly embedded
2185 // while this can be solved on 10.3 by reassigning them the correct place, on 10.2 there is
2186 // no way out, therefore we are using our own implementation and our own scrollbars ....
2188 #ifdef __WXMAC_OSX__
2190 TXNScrollInfoUPP gTXNScrollInfoProc
= NULL
;
2191 ControlActionUPP gTXNScrollActionProc
= NULL
;
2193 pascal void wxMacMLTEClassicControl::TXNScrollInfoProc(
2194 SInt32 iValue
, SInt32 iMaximumValue
,
2195 TXNScrollBarOrientation iScrollBarOrientation
, SInt32 iRefCon
)
2197 wxMacMLTEClassicControl
* mlte
= (wxMacMLTEClassicControl
*) iRefCon
;
2198 SInt32 value
= wxMax( iValue
, 0 ) ;
2199 SInt32 maximum
= wxMax( iMaximumValue
, 0 ) ;
2201 if ( iScrollBarOrientation
== kTXNHorizontal
)
2203 if ( mlte
->m_sbHorizontal
)
2205 SetControl32BitValue( mlte
->m_sbHorizontal
, value
) ;
2206 SetControl32BitMaximum( mlte
->m_sbHorizontal
, maximum
) ;
2207 mlte
->m_lastHorizontalValue
= value
;
2210 else if ( iScrollBarOrientation
== kTXNVertical
)
2212 if ( mlte
->m_sbVertical
)
2214 SetControl32BitValue( mlte
->m_sbVertical
, value
) ;
2215 SetControl32BitMaximum( mlte
->m_sbVertical
, maximum
) ;
2216 mlte
->m_lastVerticalValue
= value
;
2221 pascal void wxMacMLTEClassicControl::TXNScrollActionProc( ControlRef controlRef
, ControlPartCode partCode
)
2223 wxMacMLTEClassicControl
* mlte
= (wxMacMLTEClassicControl
*) GetControlReference( controlRef
) ;
2227 if ( controlRef
!= mlte
->m_sbVertical
&& controlRef
!= mlte
->m_sbHorizontal
)
2231 bool isHorizontal
= ( controlRef
== mlte
->m_sbHorizontal
) ;
2233 SInt32 minimum
= 0 ;
2234 SInt32 maximum
= GetControl32BitMaximum( controlRef
) ;
2235 SInt32 value
= GetControl32BitValue( controlRef
) ;
2240 case kControlDownButtonPart
:
2244 case kControlUpButtonPart
:
2248 case kControlPageDownPart
:
2249 delta
= GetControlViewSize( controlRef
) ;
2252 case kControlPageUpPart
:
2253 delta
= -GetControlViewSize( controlRef
) ;
2256 case kControlIndicatorPart
:
2257 delta
= value
- (isHorizontal
? mlte
->m_lastHorizontalValue
: mlte
->m_lastVerticalValue
) ;
2266 SInt32 newValue
= value
;
2268 if ( partCode
!= kControlIndicatorPart
)
2270 if ( value
+ delta
< minimum
)
2271 delta
= minimum
- value
;
2272 if ( value
+ delta
> maximum
)
2273 delta
= maximum
- value
;
2275 SetControl32BitValue( controlRef
, value
+ delta
) ;
2276 newValue
= value
+ delta
;
2279 SInt32 verticalDelta
= isHorizontal
? 0 : delta
;
2280 SInt32 horizontalDelta
= isHorizontal
? delta
: 0 ;
2283 mlte
->m_txn
, kTXNScrollUnitsInPixels
, kTXNScrollUnitsInPixels
,
2284 &verticalDelta
, &horizontalDelta
);
2285 verify_noerr( err
);
2288 mlte
->m_lastHorizontalValue
= newValue
;
2290 mlte
->m_lastVerticalValue
= newValue
;
2295 // make correct activations
2296 void wxMacMLTEClassicControl::MacActivatePaneText(bool setActive
)
2298 wxTextCtrl
* textctrl
= (wxTextCtrl
*) GetControlReference(m_controlRef
);
2300 wxMacWindowClipper
clipper( textctrl
) ;
2301 TXNActivate( m_txn
, m_txnFrameID
, setActive
);
2303 ControlRef controlFocus
= 0 ;
2304 GetKeyboardFocus( m_txnWindow
, &controlFocus
) ;
2305 if ( controlFocus
== m_controlRef
)
2306 TXNFocus( m_txn
, setActive
);
2309 void wxMacMLTEClassicControl::MacFocusPaneText(bool setFocus
)
2311 TXNFocus( m_txn
, setFocus
);
2314 // guards against inappropriate redraw (hidden objects drawing onto window)
2316 void wxMacMLTEClassicControl::MacSetObjectVisibility(bool vis
)
2318 ControlRef controlFocus
= 0 ;
2319 GetKeyboardFocus( m_txnWindow
, &controlFocus
) ;
2321 if ( !vis
&& (controlFocus
== m_controlRef
) )
2322 SetKeyboardFocus( m_txnWindow
, m_controlRef
, kControlFocusNoPart
) ;
2324 TXNControlTag iControlTags
[1] = { kTXNVisibilityTag
};
2325 TXNControlData iControlData
[1] = { { (UInt32
)false } };
2327 verify_noerr( TXNGetTXNObjectControls( m_txn
, 1, iControlTags
, iControlData
) ) ;
2329 if ( iControlData
[0].uValue
!= vis
)
2331 iControlData
[0].uValue
= vis
;
2332 verify_noerr( TXNSetTXNObjectControls( m_txn
, false , 1, iControlTags
, iControlData
) ) ;
2335 // currently, we always clip as partial visibility (overlapped) visibility is also a problem,
2336 // if we run into further problems we might set the FrameBounds to an empty rect here
2339 // make sure that the TXNObject is at the right position
2341 void wxMacMLTEClassicControl::MacUpdatePosition()
2343 wxTextCtrl
* textctrl
= (wxTextCtrl
*)GetControlReference( m_controlRef
);
2344 if ( textctrl
== NULL
)
2348 UMAGetControlBoundsInWindowCoords( m_controlRef
, &bounds
);
2350 wxRect visRect
= textctrl
->MacGetClippedClientRect() ;
2351 Rect visBounds
= { visRect
.y
, visRect
.x
, visRect
.y
+ visRect
.height
, visRect
.x
+ visRect
.width
} ;
2354 textctrl
->MacWindowToRootWindow( &x
, &y
) ;
2355 OffsetRect( &visBounds
, x
, y
) ;
2357 if ( !EqualRect( &bounds
, &m_txnControlBounds
) || !EqualRect( &visBounds
, &m_txnVisBounds
) )
2359 m_txnControlBounds
= bounds
;
2360 m_txnVisBounds
= visBounds
;
2361 wxMacWindowClipper
cl( textctrl
) ;
2363 #ifdef __WXMAC_OSX__
2364 bool isCompositing
= textctrl
->MacGetTopLevelWindow()->MacUsesCompositing() ;
2365 if ( m_sbHorizontal
|| m_sbVertical
)
2367 int w
= bounds
.right
- bounds
.left
;
2368 int h
= bounds
.bottom
- bounds
.top
;
2370 if ( m_sbHorizontal
)
2374 sbBounds
.left
= -1 ;
2375 sbBounds
.top
= h
- 14 ;
2376 sbBounds
.right
= w
+ 1 ;
2377 sbBounds
.bottom
= h
+ 1 ;
2379 if ( !isCompositing
)
2380 OffsetRect( &sbBounds
, m_txnControlBounds
.left
, m_txnControlBounds
.top
) ;
2382 SetControlBounds( m_sbHorizontal
, &sbBounds
) ;
2383 SetControlViewSize( m_sbHorizontal
, w
) ;
2390 sbBounds
.left
= w
- 14 ;
2392 sbBounds
.right
= w
+ 1 ;
2393 sbBounds
.bottom
= m_sbHorizontal
? h
- 14 : h
+ 1 ;
2395 if ( !isCompositing
)
2396 OffsetRect( &sbBounds
, m_txnControlBounds
.left
, m_txnControlBounds
.top
) ;
2398 SetControlBounds( m_sbVertical
, &sbBounds
) ;
2399 SetControlViewSize( m_sbVertical
, h
) ;
2404 TXNLongRect olddestRect
;
2405 TXNGetRectBounds( m_txn
, &oldviewRect
, &olddestRect
, NULL
) ;
2407 Rect viewRect
= { m_txnControlBounds
.top
, m_txnControlBounds
.left
,
2408 m_txnControlBounds
.bottom
- ( m_sbHorizontal
? 14 : 0 ) ,
2409 m_txnControlBounds
.right
- ( m_sbVertical
? 14 : 0 ) } ;
2410 TXNLongRect destRect
= { m_txnControlBounds
.top
, m_txnControlBounds
.left
,
2411 m_txnControlBounds
.bottom
- ( m_sbHorizontal
? 14 : 0 ) ,
2412 m_txnControlBounds
.right
- ( m_sbVertical
? 14 : 0 ) } ;
2414 if ( olddestRect
.right
>= 10000 )
2415 destRect
.right
= destRect
.left
+ 32000 ;
2417 if ( olddestRect
.bottom
>= 0x20000000 )
2418 destRect
.bottom
= destRect
.top
+ 0x40000000 ;
2420 SectRect( &viewRect
, &visBounds
, &viewRect
) ;
2421 TXNSetRectBounds( m_txn
, &viewRect
, &destRect
, true ) ;
2426 m_txnControlBounds
.top
,
2427 m_txnControlBounds
.left
,
2428 m_txnControlBounds
.bottom
- (m_sbHorizontal
? 14 : 0),
2429 m_txnControlBounds
.right
- (m_sbVertical
? 14 : 0),
2435 m_txn
, m_txnControlBounds
.top
, m_txnControlBounds
.left
,
2436 wxMax( m_txnControlBounds
.bottom
, m_txnControlBounds
.top
),
2437 wxMax( m_txnControlBounds
.right
, m_txnControlBounds
.left
), m_txnFrameID
);
2440 // the SetFrameBounds method under Classic sometimes does not correctly scroll a selection into sight after a
2441 // movement, therefore we have to force it
2443 // this problem has been reported in OSX as well, so we use this here once again
2445 TXNLongRect textRect
;
2446 TXNGetRectBounds( m_txn
, NULL
, NULL
, &textRect
) ;
2447 if ( textRect
.left
< m_txnControlBounds
.left
)
2448 TXNShowSelection( m_txn
, kTXNShowStart
) ;
2452 void wxMacMLTEClassicControl::SetRect( Rect
*r
)
2454 wxMacControl::SetRect( r
) ;
2455 MacUpdatePosition() ;
2458 void wxMacMLTEClassicControl::MacControlUserPaneDrawProc(wxInt16 thePart
)
2460 wxTextCtrl
* textctrl
= (wxTextCtrl
*)GetControlReference( m_controlRef
);
2461 if ( textctrl
== NULL
)
2464 if ( textctrl
->MacIsReallyShown() )
2466 wxMacWindowClipper
clipper( textctrl
) ;
2467 TXNDraw( m_txn
, NULL
) ;
2471 wxInt16
wxMacMLTEClassicControl::MacControlUserPaneHitTestProc(wxInt16 x
, wxInt16 y
)
2473 Point where
= { y
, x
} ;
2474 ControlPartCode result
= kControlNoPart
;
2476 wxTextCtrl
* textctrl
= (wxTextCtrl
*) GetControlReference( m_controlRef
);
2477 if ( (textctrl
!= NULL
) && textctrl
->MacIsReallyShown() )
2479 if (PtInRect( where
, &m_txnControlBounds
))
2481 result
= kControlEditTextPart
;
2485 // sometimes we get the coords also in control local coordinates, therefore test again
2486 if ( textctrl
->MacGetTopLevelWindow()->MacUsesCompositing() )
2489 textctrl
->MacClientToRootWindow( &x
, &y
) ;
2494 if (PtInRect( where
, &m_txnControlBounds
))
2495 result
= kControlEditTextPart
;
2502 wxInt16
wxMacMLTEClassicControl::MacControlUserPaneTrackingProc( wxInt16 x
, wxInt16 y
, void* actionProc
)
2504 ControlPartCode result
= kControlNoPart
;
2506 wxTextCtrl
* textctrl
= (wxTextCtrl
*) GetControlReference( m_controlRef
);
2507 if ( (textctrl
!= NULL
) && textctrl
->MacIsReallyShown() )
2509 Point startPt
= { y
, x
} ;
2510 // for compositing, we must convert these into toplevel window coordinates, because hittesting expects them
2511 if ( textctrl
->MacGetTopLevelWindow()->MacUsesCompositing() )
2514 textctrl
->MacClientToRootWindow( &x
, &y
) ;
2519 switch (MacControlUserPaneHitTestProc( startPt
.h
, startPt
.v
))
2521 case kControlEditTextPart
:
2523 wxMacWindowClipper
clipper( textctrl
) ;
2526 ConvertEventRefToEventRecord( (EventRef
) wxTheApp
->MacGetCurrentEvent() , &rec
) ;
2527 TXNClick( m_txn
, &rec
);
2539 void wxMacMLTEClassicControl::MacControlUserPaneIdleProc()
2541 wxTextCtrl
* textctrl
= (wxTextCtrl
*)GetControlReference( m_controlRef
);
2542 if ( textctrl
== NULL
)
2545 if (textctrl
->MacIsReallyShown())
2547 if (IsControlActive(m_controlRef
))
2551 wxMacWindowClipper
clipper( textctrl
) ;
2556 if (PtInRect(mousep
, &m_txnControlBounds
))
2558 RgnHandle theRgn
= NewRgn();
2559 RectRgn(theRgn
, &m_txnControlBounds
);
2560 TXNAdjustCursor(m_txn
, theRgn
);
2567 wxInt16
wxMacMLTEClassicControl::MacControlUserPaneKeyDownProc (wxInt16 keyCode
, wxInt16 charCode
, wxInt16 modifiers
)
2569 wxTextCtrl
* textctrl
= (wxTextCtrl
*)GetControlReference( m_controlRef
);
2570 if ( textctrl
== NULL
)
2571 return kControlNoPart
;
2573 wxMacWindowClipper
clipper( textctrl
) ;
2576 memset( &ev
, 0 , sizeof( ev
) ) ;
2578 ev
.modifiers
= modifiers
;
2579 ev
.message
= ((keyCode
<< 8) & keyCodeMask
) | (charCode
& charCodeMask
);
2580 TXNKeyDown( m_txn
, &ev
);
2582 return kControlEntireControl
;
2585 void wxMacMLTEClassicControl::MacControlUserPaneActivateProc(bool activating
)
2587 MacActivatePaneText( activating
);
2590 wxInt16
wxMacMLTEClassicControl::MacControlUserPaneFocusProc(wxInt16 action
)
2592 ControlPartCode focusResult
= kControlFocusNoPart
;
2594 wxTextCtrl
* textctrl
= (wxTextCtrl
*)GetControlReference( m_controlRef
);
2595 if ( textctrl
== NULL
)
2598 wxMacWindowClipper
clipper( textctrl
) ;
2600 ControlRef controlFocus
= NULL
;
2601 GetKeyboardFocus( m_txnWindow
, &controlFocus
) ;
2602 bool wasFocused
= ( controlFocus
== m_controlRef
) ;
2606 case kControlFocusPrevPart
:
2607 case kControlFocusNextPart
:
2608 MacFocusPaneText( !wasFocused
);
2609 focusResult
= (!wasFocused
? (ControlPartCode
) kControlEditTextPart
: (ControlPartCode
) kControlFocusNoPart
);
2612 case kControlFocusNoPart
:
2614 MacFocusPaneText( false );
2615 focusResult
= kControlFocusNoPart
;
2622 void wxMacMLTEClassicControl::MacControlUserPaneBackgroundProc( void *info
)
2626 wxMacMLTEClassicControl::wxMacMLTEClassicControl( wxTextCtrl
*wxPeer
,
2627 const wxString
& str
,
2629 const wxSize
& size
, long style
)
2630 : wxMacMLTEControl( wxPeer
)
2632 m_font
= wxPeer
->GetFont() ;
2633 m_windowStyle
= style
;
2634 Rect bounds
= wxMacGetBoundsForControl( wxPeer
, pos
, size
) ;
2637 kControlSupportsEmbedding
| kControlSupportsFocus
| kControlWantsIdle
2638 | kControlWantsActivate
| kControlHandlesTracking
2639 // | kControlHasSpecialBackground
2640 | kControlGetsFocusOnClick
| kControlSupportsLiveFeedback
;
2642 OSStatus err
= ::CreateUserPaneControl(
2643 MAC_WXHWND(wxPeer
->GetParent()->MacGetTopLevelWindowRef()),
2644 &bounds
, featureSet
, &m_controlRef
);
2645 verify_noerr( err
);
2649 AdjustCreationAttributes( *wxWHITE
, true ) ;
2651 MacSetObjectVisibility( wxPeer
->MacIsReallyShown() ) ;
2655 wxMacConvertNewlines10To13( &st
) ;
2656 wxMacWindowClipper
clipper( m_peer
) ;
2657 SetTXNData( st
, kTXNStartOffset
, kTXNEndOffset
) ;
2658 TXNSetSelection( m_txn
, 0, 0 ) ;
2662 wxMacMLTEClassicControl::~wxMacMLTEClassicControl()
2664 TXNDeleteObject( m_txn
);
2668 void wxMacMLTEClassicControl::VisibilityChanged(bool shown
)
2670 MacSetObjectVisibility( shown
) ;
2671 wxMacControl::VisibilityChanged( shown
) ;
2674 void wxMacMLTEClassicControl::SuperChangedPosition()
2676 MacUpdatePosition() ;
2677 wxMacControl::SuperChangedPosition() ;
2680 #ifdef __WXMAC_OSX__
2682 ControlUserPaneDrawUPP gTPDrawProc
= NULL
;
2683 ControlUserPaneHitTestUPP gTPHitProc
= NULL
;
2684 ControlUserPaneTrackingUPP gTPTrackProc
= NULL
;
2685 ControlUserPaneIdleUPP gTPIdleProc
= NULL
;
2686 ControlUserPaneKeyDownUPP gTPKeyProc
= NULL
;
2687 ControlUserPaneActivateUPP gTPActivateProc
= NULL
;
2688 ControlUserPaneFocusUPP gTPFocusProc
= NULL
;
2690 static pascal void wxMacControlUserPaneDrawProc(ControlRef control
, SInt16 part
)
2692 wxTextCtrl
*textCtrl
= wxDynamicCast( wxFindControlFromMacControl(control
) , wxTextCtrl
) ;
2693 wxMacMLTEClassicControl
* win
= textCtrl
? (wxMacMLTEClassicControl
*)(textCtrl
->GetPeer()) : NULL
;
2695 win
->MacControlUserPaneDrawProc( part
) ;
2698 static pascal ControlPartCode
wxMacControlUserPaneHitTestProc(ControlRef control
, Point where
)
2700 wxTextCtrl
*textCtrl
= wxDynamicCast( wxFindControlFromMacControl(control
) , wxTextCtrl
) ;
2701 wxMacMLTEClassicControl
* win
= textCtrl
? (wxMacMLTEClassicControl
*)(textCtrl
->GetPeer()) : NULL
;
2703 return win
->MacControlUserPaneHitTestProc( where
.h
, where
.v
) ;
2705 return kControlNoPart
;
2708 static pascal ControlPartCode
wxMacControlUserPaneTrackingProc(ControlRef control
, Point startPt
, ControlActionUPP actionProc
)
2710 wxTextCtrl
*textCtrl
= wxDynamicCast( wxFindControlFromMacControl(control
) , wxTextCtrl
) ;
2711 wxMacMLTEClassicControl
* win
= textCtrl
? (wxMacMLTEClassicControl
*)(textCtrl
->GetPeer()) : NULL
;
2713 return win
->MacControlUserPaneTrackingProc( startPt
.h
, startPt
.v
, (void*) actionProc
) ;
2715 return kControlNoPart
;
2718 static pascal void wxMacControlUserPaneIdleProc(ControlRef control
)
2720 wxTextCtrl
*textCtrl
= wxDynamicCast( wxFindControlFromMacControl(control
) , wxTextCtrl
) ;
2721 wxMacMLTEClassicControl
* win
= textCtrl
? (wxMacMLTEClassicControl
*)(textCtrl
->GetPeer()) : NULL
;
2723 win
->MacControlUserPaneIdleProc() ;
2726 static pascal ControlPartCode
wxMacControlUserPaneKeyDownProc(ControlRef control
, SInt16 keyCode
, SInt16 charCode
, SInt16 modifiers
)
2728 wxTextCtrl
*textCtrl
= wxDynamicCast( wxFindControlFromMacControl(control
) , wxTextCtrl
) ;
2729 wxMacMLTEClassicControl
* win
= textCtrl
? (wxMacMLTEClassicControl
*)(textCtrl
->GetPeer()) : NULL
;
2731 return win
->MacControlUserPaneKeyDownProc( keyCode
, charCode
, modifiers
) ;
2733 return kControlNoPart
;
2736 static pascal void wxMacControlUserPaneActivateProc(ControlRef control
, Boolean activating
)
2738 wxTextCtrl
*textCtrl
= wxDynamicCast( wxFindControlFromMacControl(control
) , wxTextCtrl
) ;
2739 wxMacMLTEClassicControl
* win
= textCtrl
? (wxMacMLTEClassicControl
*)(textCtrl
->GetPeer()) : NULL
;
2741 win
->MacControlUserPaneActivateProc( activating
) ;
2744 static pascal ControlPartCode
wxMacControlUserPaneFocusProc(ControlRef control
, ControlFocusPart action
)
2746 wxTextCtrl
*textCtrl
= wxDynamicCast( wxFindControlFromMacControl(control
) , wxTextCtrl
) ;
2747 wxMacMLTEClassicControl
* win
= textCtrl
? (wxMacMLTEClassicControl
*)(textCtrl
->GetPeer()) : NULL
;
2749 return win
->MacControlUserPaneFocusProc( action
) ;
2751 return kControlNoPart
;
2755 static pascal void wxMacControlUserPaneBackgroundProc(ControlRef control
, ControlBackgroundPtr info
)
2757 wxTextCtrl
*textCtrl
= wxDynamicCast( wxFindControlFromMacControl(control
) , wxTextCtrl
) ;
2758 wxMacMLTEClassicControl
* win
= textCtrl
? (wxMacMLTEClassicControl
*)(textCtrl
->GetPeer()) : NULL
;
2760 win
->MacControlUserPaneBackgroundProc(info
) ;
2764 #endif // __WXMAC_OSX__
2766 // TXNRegisterScrollInfoProc
2768 OSStatus
wxMacMLTEClassicControl::DoCreate()
2771 OSStatus err
= noErr
;
2773 // set up our globals
2774 #ifdef __WXMAC_OSX__
2775 if (gTPDrawProc
== NULL
) gTPDrawProc
= NewControlUserPaneDrawUPP(wxMacControlUserPaneDrawProc
);
2776 if (gTPHitProc
== NULL
) gTPHitProc
= NewControlUserPaneHitTestUPP(wxMacControlUserPaneHitTestProc
);
2777 if (gTPTrackProc
== NULL
) gTPTrackProc
= NewControlUserPaneTrackingUPP(wxMacControlUserPaneTrackingProc
);
2778 if (gTPIdleProc
== NULL
) gTPIdleProc
= NewControlUserPaneIdleUPP(wxMacControlUserPaneIdleProc
);
2779 if (gTPKeyProc
== NULL
) gTPKeyProc
= NewControlUserPaneKeyDownUPP(wxMacControlUserPaneKeyDownProc
);
2780 if (gTPActivateProc
== NULL
) gTPActivateProc
= NewControlUserPaneActivateUPP(wxMacControlUserPaneActivateProc
);
2781 if (gTPFocusProc
== NULL
) gTPFocusProc
= NewControlUserPaneFocusUPP(wxMacControlUserPaneFocusProc
);
2783 if (gTXNScrollInfoProc
== NULL
) gTXNScrollInfoProc
= NewTXNScrollInfoUPP(TXNScrollInfoProc
) ;
2784 if (gTXNScrollActionProc
== NULL
) gTXNScrollActionProc
= NewControlActionUPP(TXNScrollActionProc
) ;
2787 // set the initial settings for our private data
2789 m_txnWindow
= GetControlOwner(m_controlRef
);
2790 m_txnPort
= (GrafPtr
) GetWindowPort(m_txnWindow
);
2792 #ifdef __WXMAC_OSX__
2793 // set up the user pane procedures
2794 SetControlData(m_controlRef
, kControlEntireControl
, kControlUserPaneDrawProcTag
, sizeof(gTPDrawProc
), &gTPDrawProc
);
2795 SetControlData(m_controlRef
, kControlEntireControl
, kControlUserPaneHitTestProcTag
, sizeof(gTPHitProc
), &gTPHitProc
);
2796 SetControlData(m_controlRef
, kControlEntireControl
, kControlUserPaneTrackingProcTag
, sizeof(gTPTrackProc
), &gTPTrackProc
);
2797 SetControlData(m_controlRef
, kControlEntireControl
, kControlUserPaneIdleProcTag
, sizeof(gTPIdleProc
), &gTPIdleProc
);
2798 SetControlData(m_controlRef
, kControlEntireControl
, kControlUserPaneKeyDownProcTag
, sizeof(gTPKeyProc
), &gTPKeyProc
);
2799 SetControlData(m_controlRef
, kControlEntireControl
, kControlUserPaneActivateProcTag
, sizeof(gTPActivateProc
), &gTPActivateProc
);
2800 SetControlData(m_controlRef
, kControlEntireControl
, kControlUserPaneFocusProcTag
, sizeof(gTPFocusProc
), &gTPFocusProc
);
2803 // calculate the rectangles used by the control
2804 UMAGetControlBoundsInWindowCoords( m_controlRef
, &bounds
);
2806 m_txnControlBounds
= bounds
;
2807 m_txnVisBounds
= bounds
;
2812 GetGWorld( &origPort
, &origDev
) ;
2813 SetPort( m_txnPort
);
2815 // create the new edit field
2816 TXNFrameOptions frameOptions
= FrameOptionsFromWXStyle( m_windowStyle
);
2818 #ifdef __WXMAC_OSX__
2819 // the scrollbars are not correctly embedded but are inserted at the root:
2820 // this gives us problems as we have erratic redraws even over the structure area
2822 m_sbHorizontal
= 0 ;
2824 m_lastHorizontalValue
= 0 ;
2825 m_lastVerticalValue
= 0 ;
2827 Rect sb
= { 0 , 0 , 0 , 0 } ;
2828 if ( frameOptions
& kTXNWantVScrollBarMask
)
2830 CreateScrollBarControl( m_txnWindow
, &sb
, 0, 0, 100, 1, true, gTXNScrollActionProc
, &m_sbVertical
);
2831 SetControlReference( m_sbVertical
, (SInt32
)this );
2832 SetControlAction( m_sbVertical
, gTXNScrollActionProc
);
2833 ShowControl( m_sbVertical
);
2834 EmbedControl( m_sbVertical
, m_controlRef
);
2835 frameOptions
&= ~kTXNWantVScrollBarMask
;
2838 if ( frameOptions
& kTXNWantHScrollBarMask
)
2840 CreateScrollBarControl( m_txnWindow
, &sb
, 0, 0, 100, 1, true, gTXNScrollActionProc
, &m_sbHorizontal
);
2841 SetControlReference( m_sbHorizontal
, (SInt32
)this );
2842 SetControlAction( m_sbHorizontal
, gTXNScrollActionProc
);
2843 ShowControl( m_sbHorizontal
);
2844 EmbedControl( m_sbHorizontal
, m_controlRef
);
2845 frameOptions
&= ~(kTXNWantHScrollBarMask
| kTXNDrawGrowIconMask
);
2851 NULL
, m_txnWindow
, &bounds
, frameOptions
,
2852 kTXNTextEditStyleFrameType
, kTXNTextensionFile
, kTXNSystemDefaultEncoding
,
2853 &m_txn
, &m_txnFrameID
, NULL
);
2854 verify_noerr( err
);
2857 TXNControlTag iControlTags
[] = { kTXNUseCarbonEvents
};
2858 TXNControlData iControlData
[] = { { (UInt32
)&cInfo
} };
2859 int toptag
= WXSIZEOF( iControlTags
) ;
2860 TXNCarbonEventInfo cInfo
;
2861 cInfo
.useCarbonEvents
= false ;
2864 cInfo
.fDictionary
= NULL
;
2866 verify_noerr( TXNSetTXNObjectControls( m_txn
, false, toptag
, iControlTags
, iControlData
) );
2869 #ifdef __WXMAC_OSX__
2870 TXNRegisterScrollInfoProc( m_txn
, gTXNScrollInfoProc
, (SInt32
)this );
2873 SetGWorld( origPort
, origDev
) ;
2878 // ----------------------------------------------------------------------------
2879 // MLTE control implementation (OSX part)
2880 // ----------------------------------------------------------------------------
2882 #if TARGET_API_MAC_OSX
2884 #if MAC_OS_X_VERSION_MAX_ALLOWED > MAC_OS_X_VERSION_10_2
2886 wxMacMLTEHIViewControl::wxMacMLTEHIViewControl( wxTextCtrl
*wxPeer
,
2887 const wxString
& str
,
2889 const wxSize
& size
, long style
) : wxMacMLTEControl( wxPeer
)
2891 m_font
= wxPeer
->GetFont() ;
2892 m_windowStyle
= style
;
2893 Rect bounds
= wxMacGetBoundsForControl( wxPeer
, pos
, size
) ;
2895 wxMacConvertNewlines10To13( &st
) ;
2898 { bounds
.left
, bounds
.top
},
2899 { bounds
.right
- bounds
.left
, bounds
.bottom
- bounds
.top
} } ;
2901 m_scrollView
= NULL
;
2902 TXNFrameOptions frameOptions
= FrameOptionsFromWXStyle( style
) ;
2903 if ( frameOptions
& (kTXNWantVScrollBarMask
| kTXNWantHScrollBarMask
) )
2906 (frameOptions
& kTXNWantHScrollBarMask
? kHIScrollViewOptionsHorizScroll
: 0)
2907 | (frameOptions
& kTXNWantVScrollBarMask
? kHIScrollViewOptionsVertScroll
: 0) ,
2910 HIViewSetFrame( m_scrollView
, &hr
);
2911 HIViewSetVisible( m_scrollView
, true );
2915 HITextViewCreate( NULL
, 0, frameOptions
, &m_textView
) ;
2916 m_txn
= HITextViewGetTXNObject( m_textView
) ;
2917 HIViewSetVisible( m_textView
, true ) ;
2920 HIViewAddSubview( m_scrollView
, m_textView
) ;
2921 m_controlRef
= m_scrollView
;
2922 wxPeer
->MacInstallEventHandler( (WXWidget
) m_textView
) ;
2926 HIViewSetFrame( m_textView
, &hr
);
2927 m_controlRef
= m_textView
;
2930 AdjustCreationAttributes( *wxWHITE
, true ) ;
2932 wxMacWindowClipper
c( m_peer
) ;
2933 SetTXNData( st
, kTXNStartOffset
, kTXNEndOffset
) ;
2935 TXNSetSelection( m_txn
, 0, 0 );
2936 TXNShowSelection( m_txn
, kTXNShowStart
);
2939 OSStatus
wxMacMLTEHIViewControl::SetFocus( ControlFocusPart focusPart
)
2941 return SetKeyboardFocus( GetControlOwner( m_textView
), m_textView
, focusPart
) ;
2944 bool wxMacMLTEHIViewControl::HasFocus() const
2946 ControlRef control
;
2947 GetKeyboardFocus( GetUserFocusWindow() , &control
) ;
2948 return control
== m_textView
;
2951 void wxMacMLTEHIViewControl::SetBackground( const wxBrush
&brush
)
2953 wxMacMLTEControl::SetBackground( brush
) ;
2956 CGColorSpaceRef rgbSpace
= CGColorSpaceCreateDeviceRGB();
2957 RGBColor col
= MAC_WXCOLORREF(brush
.GetColour().GetPixel()) ;
2959 float component
[4] ;
2960 component
[0] = col
.red
/ 65536.0 ;
2961 component
[1] = col
.green
/ 65536.0 ;
2962 component
[2] = col
.blue
/ 65536.0 ;
2963 component
[3] = 1.0 ; // alpha
2965 CGColorRef color
= CGColorCreate( rgbSpace
, component
);
2966 HITextViewSetBackgroundColor( m_textView
, color
);
2967 CGColorSpaceRelease( rgbSpace
);
2971 #endif // MAC_OS_X_VERSION_MAX_ALLOWED > MAC_OS_X_VERSION_10_2
2976 #endif // wxUSE_TEXTCTRL