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
;
405 IMPLEMENT_DYNAMIC_CLASS(wxTextCtrl
, wxControl
)
407 BEGIN_EVENT_TABLE(wxTextCtrl
, wxControl
)
408 EVT_ERASE_BACKGROUND( wxTextCtrl::OnEraseBackground
)
409 EVT_DROP_FILES(wxTextCtrl::OnDropFiles
)
410 EVT_CHAR(wxTextCtrl::OnChar
)
411 EVT_MENU(wxID_CUT
, wxTextCtrl::OnCut
)
412 EVT_MENU(wxID_COPY
, wxTextCtrl::OnCopy
)
413 EVT_MENU(wxID_PASTE
, wxTextCtrl::OnPaste
)
414 EVT_MENU(wxID_UNDO
, wxTextCtrl::OnUndo
)
415 EVT_MENU(wxID_REDO
, wxTextCtrl::OnRedo
)
416 EVT_MENU(wxID_CLEAR
, wxTextCtrl::OnDelete
)
417 EVT_MENU(wxID_SELECTALL
, wxTextCtrl::OnSelectAll
)
419 EVT_CONTEXT_MENU(wxTextCtrl::OnContextMenu
)
421 EVT_UPDATE_UI(wxID_CUT
, wxTextCtrl::OnUpdateCut
)
422 EVT_UPDATE_UI(wxID_COPY
, wxTextCtrl::OnUpdateCopy
)
423 EVT_UPDATE_UI(wxID_PASTE
, wxTextCtrl::OnUpdatePaste
)
424 EVT_UPDATE_UI(wxID_UNDO
, wxTextCtrl::OnUpdateUndo
)
425 EVT_UPDATE_UI(wxID_REDO
, wxTextCtrl::OnUpdateRedo
)
426 EVT_UPDATE_UI(wxID_CLEAR
, wxTextCtrl::OnUpdateDelete
)
427 EVT_UPDATE_UI(wxID_SELECTALL
, wxTextCtrl::OnUpdateSelectAll
)
431 void wxTextCtrl::Init()
437 m_privateContextMenu
= NULL
;
440 wxTextCtrl::~wxTextCtrl()
442 delete m_privateContextMenu
;
445 bool wxTextCtrl::Create( wxWindow
*parent
,
451 const wxValidator
& validator
,
452 const wxString
& name
)
454 m_macIsUserPane
= false ;
457 if ( ! (style
& wxNO_BORDER
) )
458 style
= (style
& ~wxBORDER_MASK
) | wxSUNKEN_BORDER
;
460 if ( !wxTextCtrlBase::Create( parent
, id
, pos
, size
, style
& ~(wxHSCROLL
| wxVSCROLL
), validator
, name
) )
463 if ( m_windowStyle
& wxTE_MULTILINE
)
466 !(m_windowStyle
& wxTE_PROCESS_ENTER
),
467 wxT("wxTE_PROCESS_ENTER style is ignored for multiline text controls (they always process it)") );
469 m_windowStyle
|= wxTE_PROCESS_ENTER
;
470 style
|= wxTE_PROCESS_ENTER
;
473 bool forceMLTE
= false ;
475 #if wxUSE_SYSTEM_OPTIONS
476 if (wxSystemOptions::HasOption( wxMAC_TEXTCONTROL_USE_MLTE
) && (wxSystemOptions::GetOptionInt( wxMAC_TEXTCONTROL_USE_MLTE
) == 1))
483 #if MAC_OS_X_VERSION_MAX_ALLOWED > MAC_OS_X_VERSION_10_2
484 if ( UMAGetSystemVersion() >= 0x1030 && !forceMLTE
)
486 if ( m_windowStyle
& wxTE_MULTILINE
)
487 m_peer
= new wxMacMLTEHIViewControl( this , str
, pos
, size
, style
) ;
493 if ( !(m_windowStyle
& wxTE_MULTILINE
) && !forceMLTE
)
494 m_peer
= new wxMacUnicodeTextControl( this , str
, pos
, size
, style
) ;
499 m_peer
= new wxMacMLTEClassicControl( this , str
, pos
, size
, style
) ;
501 MacPostControlCreate(pos
, size
) ;
503 // only now the embedding is correct and we can do a positioning update
505 MacSuperChangedPosition() ;
507 if ( m_windowStyle
& wxTE_READONLY
)
508 SetEditable( false ) ;
510 SetCursor( wxCursor( wxCURSOR_IBEAM
) ) ;
515 void wxTextCtrl::MacSuperChangedPosition()
517 wxWindow::MacSuperChangedPosition() ;
518 GetPeer()->SuperChangedPosition() ;
521 void wxTextCtrl::MacVisibilityChanged()
523 GetPeer()->VisibilityChanged( MacIsReallyShown() ) ;
526 void wxTextCtrl::MacEnabledStateChanged()
530 wxString
wxTextCtrl::GetValue() const
532 return GetPeer()->GetStringValue() ;
535 void wxTextCtrl::GetSelection(long* from
, long* to
) const
537 GetPeer()->GetSelection( from
, to
) ;
540 void wxTextCtrl::SetValue(const wxString
& str
)
543 if ( GetValue() == str
)
546 GetPeer()->SetStringValue( str
) ;
548 wxCommandEvent
event( wxEVT_COMMAND_TEXT_UPDATED
, m_windowId
);
549 event
.SetString( GetValue() );
550 event
.SetEventObject( this );
551 GetEventHandler()->ProcessEvent( event
);
554 void wxTextCtrl::SetMaxLength(unsigned long len
)
559 bool wxTextCtrl::SetFont( const wxFont
& font
)
561 if ( !wxTextCtrlBase::SetFont( font
) )
564 GetPeer()->SetFont( font
, GetForegroundColour() , GetWindowStyle() ) ;
569 bool wxTextCtrl::SetStyle(long start
, long end
, const wxTextAttr
& style
)
571 GetPeer()->SetStyle( start
, end
, style
) ;
576 bool wxTextCtrl::SetDefaultStyle(const wxTextAttr
& style
)
578 wxTextCtrlBase::SetDefaultStyle( style
) ;
579 SetStyle( kTXNUseCurrentSelection
, kTXNUseCurrentSelection
, GetDefaultStyle() ) ;
584 // Clipboard operations
586 void wxTextCtrl::Copy()
592 void wxTextCtrl::Cut()
598 wxCommandEvent
event( wxEVT_COMMAND_TEXT_UPDATED
, m_windowId
);
599 event
.SetEventObject( this );
600 GetEventHandler()->ProcessEvent( event
);
604 void wxTextCtrl::Paste()
610 // TODO: eventually we should add setting the default style again
612 wxCommandEvent
event( wxEVT_COMMAND_TEXT_UPDATED
, m_windowId
);
613 event
.SetEventObject( this );
614 GetEventHandler()->ProcessEvent( event
);
618 bool wxTextCtrl::CanCopy() const
620 // Can copy if there's a selection
622 GetSelection( &from
, &to
);
627 bool wxTextCtrl::CanCut() const
632 // Can cut if there's a selection
634 GetSelection( &from
, &to
);
639 bool wxTextCtrl::CanPaste() const
644 return GetPeer()->CanPaste() ;
647 void wxTextCtrl::SetEditable(bool editable
)
649 if ( editable
!= m_editable
)
651 m_editable
= editable
;
652 GetPeer()->SetEditable( editable
) ;
656 void wxTextCtrl::SetInsertionPoint(long pos
)
658 SetSelection( pos
, pos
) ;
661 void wxTextCtrl::SetInsertionPointEnd()
663 wxTextPos pos
= GetLastPosition();
664 SetInsertionPoint( pos
);
667 long wxTextCtrl::GetInsertionPoint() const
670 GetSelection( &begin
, &end
) ;
675 wxTextPos
wxTextCtrl::GetLastPosition() const
677 return GetPeer()->GetLastPosition() ;
680 void wxTextCtrl::Replace(long from
, long to
, const wxString
& str
)
682 GetPeer()->Replace( from
, to
, str
) ;
685 void wxTextCtrl::Remove(long from
, long to
)
687 GetPeer()->Remove( from
, to
) ;
690 void wxTextCtrl::SetSelection(long from
, long to
)
692 GetPeer()->SetSelection( from
, to
) ;
695 bool wxTextCtrl::LoadFile(const wxString
& file
)
697 return wxTextCtrlBase::LoadFile( file
);
700 void wxTextCtrl::WriteText(const wxString
& str
)
702 // TODO: this MPRemoting will be moved into a remoting peer proxy for any command
703 if ( !wxIsMainThread() )
705 // unfortunately CW 8 is not able to correctly deduce the template types,
706 // so we have to instantiate explicitly
707 wxMacMPRemoteGUICall
<wxTextCtrl
,wxString
>( this , &wxTextCtrl::WriteText
, str
) ;
712 GetPeer()->WriteText( str
) ;
715 void wxTextCtrl::AppendText(const wxString
& text
)
717 SetInsertionPointEnd();
721 void wxTextCtrl::Clear()
726 bool wxTextCtrl::IsModified() const
731 bool wxTextCtrl::IsEditable() const
733 return IsEnabled() && m_editable
;
736 bool wxTextCtrl::AcceptsFocus() const
738 // we don't want focus if we can't be edited
739 return /*IsEditable() && */ wxControl::AcceptsFocus();
742 wxSize
wxTextCtrl::DoGetBestSize() const
746 // these are the numbers from the HIG:
747 // we reduce them by the borders first
750 switch ( m_windowVariant
)
752 case wxWINDOW_VARIANT_NORMAL
:
756 case wxWINDOW_VARIANT_SMALL
:
760 case wxWINDOW_VARIANT_MINI
:
769 // as the above numbers have some free space around the text
770 // we get 5 lines like this anyway
771 if ( m_windowStyle
& wxTE_MULTILINE
)
774 if ( !HasFlag(wxNO_BORDER
) )
777 return wxSize(wText
, hText
);
780 // ----------------------------------------------------------------------------
782 // ----------------------------------------------------------------------------
784 void wxTextCtrl::Undo()
790 void wxTextCtrl::Redo()
796 bool wxTextCtrl::CanUndo() const
801 return GetPeer()->CanUndo() ;
804 bool wxTextCtrl::CanRedo() const
809 return GetPeer()->CanRedo() ;
812 void wxTextCtrl::MarkDirty()
817 void wxTextCtrl::DiscardEdits()
822 int wxTextCtrl::GetNumberOfLines() const
824 return GetPeer()->GetNumberOfLines() ;
827 long wxTextCtrl::XYToPosition(long x
, long y
) const
829 return GetPeer()->XYToPosition( x
, y
) ;
832 bool wxTextCtrl::PositionToXY(long pos
, long *x
, long *y
) const
834 return GetPeer()->PositionToXY( pos
, x
, y
) ;
837 void wxTextCtrl::ShowPosition(long pos
)
839 return GetPeer()->ShowPosition(pos
) ;
842 int wxTextCtrl::GetLineLength(long lineNo
) const
844 return GetPeer()->GetLineLength(lineNo
) ;
847 wxString
wxTextCtrl::GetLineText(long lineNo
) const
849 return GetPeer()->GetLineText(lineNo
) ;
852 void wxTextCtrl::Command(wxCommandEvent
& event
)
854 SetValue(event
.GetString());
855 ProcessCommand(event
);
858 void wxTextCtrl::OnDropFiles(wxDropFilesEvent
& event
)
860 // By default, load the first file into the text window.
861 if (event
.GetNumberOfFiles() > 0)
862 LoadFile( event
.GetFiles()[0] );
865 void wxTextCtrl::OnEraseBackground(wxEraseEvent
& event
)
867 // all erasing should be done by the real mac control implementation
868 // while this is true for MLTE under classic, the HITextView is somehow
869 // transparent but background erase is not working correctly, so intercept
870 // things while we can...
874 void wxTextCtrl::OnChar(wxKeyEvent
& event
)
876 int key
= event
.GetKeyCode() ;
877 bool eat_key
= false ;
879 if ( key
== 'c' && event
.MetaDown() )
887 if ( !IsEditable() && key
!= WXK_LEFT
&& key
!= WXK_RIGHT
&& key
!= WXK_DOWN
&& key
!= WXK_UP
&& key
!= WXK_TAB
&&
888 !( key
== WXK_RETURN
&& ( (m_windowStyle
& wxPROCESS_ENTER
) || (m_windowStyle
& wxTE_MULTILINE
) ) )
889 // && key != WXK_PRIOR && key != WXK_NEXT && key != WXK_HOME && key != WXK_END
896 // Check if we have reached the max # of chars (if it is set), but still
897 // allow navigation and deletion
898 if ( !IsMultiLine() && m_maxLength
&& GetValue().Length() >= m_maxLength
&&
899 key
!= WXK_LEFT
&& key
!= WXK_RIGHT
&& key
!= WXK_TAB
&&
900 key
!= WXK_BACK
&& !( key
== WXK_RETURN
&& (m_windowStyle
& wxPROCESS_ENTER
) )
903 // eat it, we don't want to add more than allowed # of characters
905 // TODO: generate EVT_TEXT_MAXLEN()
909 // assume that any key not processed yet is going to modify the control
912 if ( key
== 'v' && event
.MetaDown() )
920 if ( key
== 'x' && event
.MetaDown() )
931 if (m_windowStyle
& wxPROCESS_ENTER
)
933 wxCommandEvent
event(wxEVT_COMMAND_TEXT_ENTER
, m_windowId
);
934 event
.SetEventObject( this );
935 event
.SetString( GetValue() );
936 if ( GetEventHandler()->ProcessEvent(event
) )
940 if ( !(m_windowStyle
& wxTE_MULTILINE
) )
942 wxWindow
*parent
= GetParent();
943 while ( parent
&& !parent
->IsTopLevel() && parent
->GetDefaultItem() == NULL
)
945 parent
= parent
->GetParent() ;
948 if ( parent
&& parent
->GetDefaultItem() )
950 wxButton
*def
= wxDynamicCast(parent
->GetDefaultItem(), wxButton
);
951 if ( def
&& def
->IsEnabled() )
953 wxCommandEvent
event(wxEVT_COMMAND_BUTTON_CLICKED
, def
->GetId() );
954 event
.SetEventObject(def
);
961 // this will make wxWidgets eat the ENTER key so that
962 // we actually prevent line wrapping in a single line text control
968 if ( !(m_windowStyle
& wxTE_PROCESS_TAB
))
971 if (!event
.ShiftDown())
972 flags
|= wxNavigationKeyEvent::IsForward
;
973 if (event
.ControlDown())
974 flags
|= wxNavigationKeyEvent::WinChange
;
981 // This is necessary (don't know why);
982 // otherwise the tab will not be inserted.
983 WriteText(wxT("\t"));
993 // perform keystroke handling
997 if ( ( key
>= 0x20 && key
< WXK_START
) ||
1002 wxCommandEvent
event1(wxEVT_COMMAND_TEXT_UPDATED
, m_windowId
);
1003 event1
.SetEventObject( this );
1004 wxPostEvent( GetEventHandler(), event1
);
1008 // ----------------------------------------------------------------------------
1009 // standard handlers for standard edit menu events
1010 // ----------------------------------------------------------------------------
1012 void wxTextCtrl::OnCut(wxCommandEvent
& WXUNUSED(event
))
1017 void wxTextCtrl::OnCopy(wxCommandEvent
& WXUNUSED(event
))
1022 void wxTextCtrl::OnPaste(wxCommandEvent
& WXUNUSED(event
))
1027 void wxTextCtrl::OnUndo(wxCommandEvent
& WXUNUSED(event
))
1032 void wxTextCtrl::OnRedo(wxCommandEvent
& WXUNUSED(event
))
1037 void wxTextCtrl::OnDelete(wxCommandEvent
& WXUNUSED(event
))
1041 GetSelection( &from
, &to
);
1042 if (from
!= -1 && to
!= -1)
1046 void wxTextCtrl::OnSelectAll(wxCommandEvent
& WXUNUSED(event
))
1048 SetSelection(-1, -1);
1051 void wxTextCtrl::OnUpdateCut(wxUpdateUIEvent
& event
)
1053 event
.Enable( CanCut() );
1056 void wxTextCtrl::OnUpdateCopy(wxUpdateUIEvent
& event
)
1058 event
.Enable( CanCopy() );
1061 void wxTextCtrl::OnUpdatePaste(wxUpdateUIEvent
& event
)
1063 event
.Enable( CanPaste() );
1066 void wxTextCtrl::OnUpdateUndo(wxUpdateUIEvent
& event
)
1068 event
.Enable( CanUndo() );
1071 void wxTextCtrl::OnUpdateRedo(wxUpdateUIEvent
& event
)
1073 event
.Enable( CanRedo() );
1076 void wxTextCtrl::OnUpdateDelete(wxUpdateUIEvent
& event
)
1080 GetSelection( &from
, &to
);
1081 event
.Enable( from
!= -1 && to
!= -1 && from
!= to
&& IsEditable() ) ;
1084 void wxTextCtrl::OnUpdateSelectAll(wxUpdateUIEvent
& event
)
1086 event
.Enable(GetLastPosition() > 0);
1089 // CS: Context Menus only work with MLTE implementations or non-multiline HIViews at the moment
1091 void wxTextCtrl::OnContextMenu(wxContextMenuEvent
& event
)
1093 if ( GetPeer()->HasOwnContextMenu() )
1099 if (m_privateContextMenu
== NULL
)
1101 m_privateContextMenu
= new wxMenu
;
1102 m_privateContextMenu
->Append(wxID_UNDO
, _("&Undo"));
1103 m_privateContextMenu
->Append(wxID_REDO
, _("&Redo"));
1104 m_privateContextMenu
->AppendSeparator();
1105 m_privateContextMenu
->Append(wxID_CUT
, _("Cu&t"));
1106 m_privateContextMenu
->Append(wxID_COPY
, _("&Copy"));
1107 m_privateContextMenu
->Append(wxID_PASTE
, _("&Paste"));
1108 m_privateContextMenu
->Append(wxID_CLEAR
, _("&Delete"));
1109 m_privateContextMenu
->AppendSeparator();
1110 m_privateContextMenu
->Append(wxID_SELECTALL
, _("Select &All"));
1113 if (m_privateContextMenu
!= NULL
)
1114 PopupMenu(m_privateContextMenu
);
1117 bool wxTextCtrl::MacSetupCursor( const wxPoint
& pt
)
1119 if ( !GetPeer()->SetupCursor( pt
) )
1120 return wxWindow::MacSetupCursor( pt
) ;
1125 #if !TARGET_API_MAC_OSX
1127 // user pane implementation
1129 void wxTextCtrl::MacControlUserPaneDrawProc(wxInt16 part
)
1131 GetPeer()->MacControlUserPaneDrawProc( part
) ;
1134 wxInt16
wxTextCtrl::MacControlUserPaneHitTestProc(wxInt16 x
, wxInt16 y
)
1136 return GetPeer()->MacControlUserPaneHitTestProc( x
, y
) ;
1139 wxInt16
wxTextCtrl::MacControlUserPaneTrackingProc(wxInt16 x
, wxInt16 y
, void* actionProc
)
1141 return GetPeer()->MacControlUserPaneTrackingProc( x
, y
, actionProc
) ;
1144 void wxTextCtrl::MacControlUserPaneIdleProc()
1146 GetPeer()->MacControlUserPaneIdleProc( ) ;
1149 wxInt16
wxTextCtrl::MacControlUserPaneKeyDownProc(wxInt16 keyCode
, wxInt16 charCode
, wxInt16 modifiers
)
1151 return GetPeer()->MacControlUserPaneKeyDownProc( keyCode
, charCode
, modifiers
) ;
1154 void wxTextCtrl::MacControlUserPaneActivateProc(bool activating
)
1156 GetPeer()->MacControlUserPaneActivateProc( activating
) ;
1159 wxInt16
wxTextCtrl::MacControlUserPaneFocusProc(wxInt16 action
)
1161 return GetPeer()->MacControlUserPaneFocusProc( action
) ;
1164 void wxTextCtrl::MacControlUserPaneBackgroundProc(void* info
)
1166 GetPeer()->MacControlUserPaneBackgroundProc( info
) ;
1171 // ----------------------------------------------------------------------------
1172 // implementation base class
1173 // ----------------------------------------------------------------------------
1175 wxMacTextControl::wxMacTextControl(wxTextCtrl
* peer
) :
1176 wxMacControl( peer
)
1180 wxMacTextControl::~wxMacTextControl()
1184 void wxMacTextControl::SetStyle(long start
, long end
, const wxTextAttr
& style
)
1188 void wxMacTextControl::Copy()
1192 void wxMacTextControl::Cut()
1196 void wxMacTextControl::Paste()
1200 bool wxMacTextControl::CanPaste() const
1205 void wxMacTextControl::SetEditable(bool editable
)
1209 wxTextPos
wxMacTextControl::GetLastPosition() const
1211 return GetStringValue().Length() ;
1214 void wxMacTextControl::Replace( long from
, long to
, const wxString
&val
)
1216 SetSelection( from
, to
) ;
1220 void wxMacTextControl::Remove( long from
, long to
)
1222 SetSelection( from
, to
) ;
1223 WriteText( wxEmptyString
) ;
1226 void wxMacTextControl::Clear()
1228 SetStringValue( wxEmptyString
) ;
1231 bool wxMacTextControl::CanUndo() const
1236 void wxMacTextControl::Undo()
1240 bool wxMacTextControl::CanRedo() const
1245 void wxMacTextControl::Redo()
1249 long wxMacTextControl::XYToPosition(long x
, long y
) const
1254 bool wxMacTextControl::PositionToXY(long pos
, long *x
, long *y
) const
1259 void wxMacTextControl::ShowPosition( long WXUNUSED(pos
) )
1263 int wxMacTextControl::GetNumberOfLines() const
1265 ItemCount lines
= 0 ;
1266 wxString content
= GetStringValue() ;
1269 for (size_t i
= 0; i
< content
.Length() ; i
++)
1271 if (content
[i
] == '\r')
1278 wxString
wxMacTextControl::GetLineText(long lineNo
) const
1280 // TODO: change this if possible to reflect real lines
1281 wxString content
= GetStringValue() ;
1285 for (size_t i
= 0; i
< content
.Length() ; i
++)
1287 if (count
== lineNo
)
1289 // Add chars in line then
1292 for (size_t j
= i
; j
< content
.Length(); j
++)
1294 if (content
[j
] == '\n')
1303 if (content
[i
] == '\n')
1307 return wxEmptyString
;
1310 int wxMacTextControl::GetLineLength(long lineNo
) const
1312 // TODO: change this if possible to reflect real lines
1313 wxString content
= GetStringValue() ;
1317 for (size_t i
= 0; i
< content
.Length() ; i
++)
1319 if (count
== lineNo
)
1321 // Count chars in line then
1323 for (size_t j
= i
; j
< content
.Length(); j
++)
1326 if (content
[j
] == '\n')
1333 if (content
[i
] == '\n')
1340 // ----------------------------------------------------------------------------
1341 // standard unicode control implementation
1342 // ----------------------------------------------------------------------------
1344 #if TARGET_API_MAC_OSX
1346 wxMacUnicodeTextControl::wxMacUnicodeTextControl( wxTextCtrl
*wxPeer
,
1347 const wxString
& str
,
1349 const wxSize
& size
, long style
)
1350 : wxMacTextControl( wxPeer
)
1352 m_font
= wxPeer
->GetFont() ;
1353 m_windowStyle
= style
;
1354 Rect bounds
= wxMacGetBoundsForControl( wxPeer
, pos
, size
) ;
1356 wxMacConvertNewlines10To13( &st
) ;
1357 wxMacCFStringHolder
cf(st
, m_font
.GetEncoding()) ;
1358 CFStringRef cfr
= cf
;
1359 Boolean isPassword
= ( m_windowStyle
& wxTE_PASSWORD
) != 0 ;
1360 m_valueTag
= isPassword
? kControlEditTextPasswordCFStringTag
: kControlEditTextCFStringTag
;
1362 OSStatus err
= CreateEditUnicodeTextControl(
1363 MAC_WXHWND(wxPeer
->MacGetTopLevelWindowRef()), &bounds
, cfr
,
1364 isPassword
, NULL
, &m_controlRef
) ;
1365 verify_noerr( err
);
1367 if ( !(m_windowStyle
& wxTE_MULTILINE
) )
1368 SetData
<Boolean
>( kControlEditTextPart
, kControlEditTextSingleLineTag
, true ) ;
1371 wxMacUnicodeTextControl::~wxMacUnicodeTextControl()
1375 void wxMacUnicodeTextControl::VisibilityChanged(bool shown
)
1377 if ( !(m_windowStyle
& wxTE_MULTILINE
) && shown
)
1379 // work around a refresh issue insofar as not always the entire content is shown,
1380 // even if this would be possible
1381 ControlEditTextSelectionRec sel
;
1382 CFStringRef value
= NULL
;
1384 verify_noerr( GetData
<ControlEditTextSelectionRec
>( 0, kControlEditTextSelectionTag
, &sel
) );
1385 verify_noerr( GetData
<CFStringRef
>( 0, m_valueTag
, &value
) );
1386 verify_noerr( SetData
<CFStringRef
>( 0, m_valueTag
, &value
) );
1387 verify_noerr( SetData
<ControlEditTextSelectionRec
>( 0, kControlEditTextSelectionTag
, &sel
) );
1389 CFRelease( value
) ;
1393 wxString
wxMacUnicodeTextControl::GetStringValue() const
1396 CFStringRef value
= GetData
<CFStringRef
>(0, m_valueTag
) ;
1399 wxMacCFStringHolder
cf(value
) ;
1400 result
= cf
.AsString() ;
1404 wxMacConvertNewlines13To10( &result
) ;
1406 wxMacConvertNewlines10To13( &result
) ;
1412 void wxMacUnicodeTextControl::SetStringValue( const wxString
&str
)
1415 wxMacConvertNewlines10To13( &st
) ;
1416 wxMacCFStringHolder
cf( st
, m_font
.GetEncoding() ) ;
1417 verify_noerr( SetData
<CFStringRef
>( 0, m_valueTag
, cf
) ) ;
1420 void wxMacUnicodeTextControl::Copy()
1422 SendHICommand( kHICommandCopy
) ;
1425 void wxMacUnicodeTextControl::Cut()
1427 SendHICommand( kHICommandCut
) ;
1430 void wxMacUnicodeTextControl::Paste()
1432 SendHICommand( kHICommandPaste
) ;
1435 bool wxMacUnicodeTextControl::CanPaste() const
1440 void wxMacUnicodeTextControl::SetEditable(bool editable
)
1442 #if 0 // leads to problem because text cannot be selected anymore
1443 SetData
<Boolean
>( kControlEditTextPart
, kControlEditTextLockedTag
, (Boolean
) !editable
) ;
1447 void wxMacUnicodeTextControl::GetSelection( long* from
, long* to
) const
1449 ControlEditTextSelectionRec sel
;
1450 verify_noerr( GetData
<ControlEditTextSelectionRec
>( 0, kControlEditTextSelectionTag
, &sel
) ) ;
1452 *from
= sel
.selStart
;
1457 void wxMacUnicodeTextControl::SetSelection( long from
, long to
)
1459 ControlEditTextSelectionRec sel
;
1460 if ((from
== -1) && (to
== -1))
1463 to
= 32767 ; // sel has 16 bit signed values, max is 32767
1466 sel
.selStart
= from
;
1468 SetData
<ControlEditTextSelectionRec
>( 0, kControlEditTextSelectionTag
, &sel
) ;
1471 void wxMacUnicodeTextControl::WriteText( const wxString
& str
)
1474 wxMacConvertNewlines10To13( &st
) ;
1476 #if MAC_OS_X_VERSION_MAX_ALLOWED > MAC_OS_X_VERSION_10_2
1477 wxMacCFStringHolder
cf(st
, m_font
.GetEncoding() ) ;
1478 CFStringRef value
= cf
;
1479 SetData
<CFStringRef
>( 0, kControlEditTextInsertCFStringRefTag
, &value
);
1481 wxString val
= GetStringValue() ;
1483 GetSelection( &start
, &end
) ;
1484 val
.Remove( start
, end
- start
) ;
1485 val
.insert( start
, str
) ;
1486 SetStringValue( val
) ;
1487 SetSelection( start
+ str
.Length() , start
+ str
.Length() ) ;
1493 // ----------------------------------------------------------------------------
1494 // MLTE control implementation (common part)
1495 // ----------------------------------------------------------------------------
1497 // if MTLE is read only, no changes at all are allowed, not even from
1498 // procedural API, in order to allow changes via API all the same we must undo
1499 // the readonly status while we are executing, this class helps to do so
1501 class wxMacEditHelper
1504 wxMacEditHelper( TXNObject txn
)
1506 TXNControlTag tag
[] = { kTXNIOPrivilegesTag
} ;
1508 TXNGetTXNObjectControls( m_txn
, 1 , tag
, m_data
) ;
1509 if ( m_data
[0].uValue
== kTXNReadOnly
)
1511 TXNControlData data
[] = { { kTXNReadWrite
} } ;
1512 TXNSetTXNObjectControls( m_txn
, false , 1 , tag
, data
) ;
1518 TXNControlTag tag
[] = { kTXNIOPrivilegesTag
} ;
1519 if ( m_data
[0].uValue
== kTXNReadOnly
)
1520 TXNSetTXNObjectControls( m_txn
, false , 1 , tag
, m_data
) ;
1525 TXNControlData m_data
[1] ;
1528 wxMacMLTEControl::wxMacMLTEControl( wxTextCtrl
*peer
)
1529 : wxMacTextControl( peer
)
1531 SetNeedsFocusRect( true ) ;
1534 wxString
wxMacMLTEControl::GetStringValue() const
1538 Size actualSize
= 0;
1543 err
= TXNGetDataEncoded( m_txn
, kTXNStartOffset
, kTXNEndOffset
, &theText
, kTXNUnicodeTextData
);
1552 actualSize
= GetHandleSize( theText
) / sizeof(UniChar
) ;
1553 if ( actualSize
> 0 )
1555 wxChar
*ptr
= NULL
;
1557 #if SIZEOF_WCHAR_T == 2
1558 ptr
= new wxChar
[actualSize
+ 1] ;
1559 wxStrncpy( ptr
, (wxChar
*)(*theText
) , actualSize
) ;
1561 SetHandleSize( theText
, (actualSize
+ 1) * sizeof(UniChar
) ) ;
1563 (((UniChar
*)*theText
)[actualSize
]) = 0 ;
1564 wxMBConvUTF16 converter
;
1565 size_t noChars
= converter
.MB2WC( NULL
, (const char*)*theText
, 0 ) ;
1566 ptr
= new wxChar
[noChars
+ 1] ;
1568 noChars
= converter
.MB2WC( ptr
, (const char*)*theText
, noChars
) ;
1570 HUnlock( theText
) ;
1573 ptr
[actualSize
] = 0 ;
1574 result
= wxString( ptr
) ;
1578 DisposeHandle( theText
) ;
1582 err
= TXNGetDataEncoded( m_txn
, kTXNStartOffset
, kTXNEndOffset
, &theText
, kTXNTextData
);
1591 actualSize
= GetHandleSize( theText
) ;
1592 if ( actualSize
> 0 )
1595 result
= wxString( *theText
, wxConvLocal
, actualSize
) ;
1596 HUnlock( theText
) ;
1599 DisposeHandle( theText
) ;
1605 wxMacConvertNewlines13To10( &result
) ;
1607 wxMacConvertNewlines10To13( &result
) ;
1613 void wxMacMLTEControl::SetStringValue( const wxString
&str
)
1616 wxMacConvertNewlines10To13( &st
);
1619 wxMacWindowClipper
c( m_peer
);
1622 wxMacEditHelper
help( m_txn
);
1623 SetTXNData( st
, kTXNStartOffset
, kTXNEndOffset
);
1626 TXNSetSelection( m_txn
, 0, 0 );
1627 TXNShowSelection( m_txn
, kTXNShowStart
);
1631 TXNFrameOptions
wxMacMLTEControl::FrameOptionsFromWXStyle( long wxStyle
)
1633 TXNFrameOptions frameOptions
= kTXNDontDrawCaretWhenInactiveMask
;
1635 #if MAC_OS_X_VERSION_MAX_ALLOWED >= MAC_OS_X_VERSION_10_3
1636 frameOptions
|= kTXNDoFontSubstitutionMask
;
1639 if ( ! (wxStyle
& wxTE_NOHIDESEL
) )
1640 frameOptions
|= kTXNDontDrawSelectionWhenInactiveMask
;
1642 if ( wxStyle
& (wxHSCROLL
| wxTE_DONTWRAP
) )
1643 frameOptions
|= kTXNWantHScrollBarMask
;
1645 if ( wxStyle
& wxTE_MULTILINE
)
1647 frameOptions
|= kTXNAlwaysWrapAtViewEdgeMask
;
1649 if ( !(wxStyle
& wxTE_NO_VSCROLL
) )
1651 frameOptions
|= kTXNWantVScrollBarMask
;
1653 // The following code causes drawing problems on 10.4. Perhaps it can be restored for
1654 // older versions of the OS, but I'm not sure it's appropriate to put a grow icon here
1655 // anyways, as AFAIK users can't actually use it to resize the text ctrl.
1656 // if ( frameOptions & kTXNWantHScrollBarMask )
1657 // frameOptions |= kTXNDrawGrowIconMask ;
1662 frameOptions
|= kTXNSingleLineOnlyMask
;
1665 return frameOptions
;
1668 void wxMacMLTEControl::AdjustCreationAttributes( const wxColour
&background
, bool visible
)
1670 TXNControlTag iControlTags
[] =
1672 kTXNDoFontSubstitution
,
1673 kTXNWordWrapStateTag
,
1675 TXNControlData iControlData
[] =
1681 int toptag
= WXSIZEOF( iControlTags
) ;
1683 if ( m_windowStyle
& wxTE_MULTILINE
)
1685 iControlData
[1].uValue
=
1686 (m_windowStyle
& wxTE_DONTWRAP
)
1691 OSStatus err
= TXNSetTXNObjectControls( m_txn
, false, toptag
, iControlTags
, iControlData
) ;
1692 verify_noerr( err
);
1694 // setting the default font:
1695 // under 10.2 this causes a visible caret, therefore we avoid it
1697 if ( UMAGetSystemVersion() >= 0x1030 )
1703 GetThemeFont( kThemeSystemFont
, GetApplicationScript() , fontName
, &fontSize
, &fontStyle
) ;
1705 TXNTypeAttributes typeAttr
[] =
1707 { kTXNQDFontNameAttribute
, kTXNQDFontNameAttributeSize
, { (void*) fontName
} } ,
1708 { kTXNQDFontSizeAttribute
, kTXNFontSizeAttributeSize
, { (void*) (fontSize
<< 16) } } ,
1709 { kTXNQDFontStyleAttribute
, kTXNQDFontStyleAttributeSize
, { (void*) normal
} } ,
1712 err
= TXNSetTypeAttributes(
1713 m_txn
, sizeof(typeAttr
) / sizeof(TXNTypeAttributes
),
1714 typeAttr
, kTXNStartOffset
, kTXNEndOffset
);
1715 verify_noerr( err
);
1718 if ( m_windowStyle
& wxTE_PASSWORD
)
1720 UniChar c
= 0x00A5 ;
1721 err
= TXNEchoMode( m_txn
, c
, 0 , true );
1722 verify_noerr( err
);
1725 TXNBackground tback
;
1726 tback
.bgType
= kTXNBackgroundTypeRGB
;
1727 tback
.bg
.color
= MAC_WXCOLORREF( background
.GetPixel() );
1728 TXNSetBackground( m_txn
, &tback
);
1730 #if MAC_OS_X_VERSION_MAX_ALLOWED >= MAC_OS_X_VERSION_10_4
1731 if ( UMAGetSystemVersion() >= 0x1040 )
1733 TXNCommandEventSupportOptions options
;
1734 if ( TXNGetCommandEventSupport( m_txn
, &options
) == noErr
)
1737 kTXNSupportEditCommandProcessing
1738 | kTXNSupportEditCommandUpdating
1739 | kTXNSupportSpellCheckCommandProcessing
1740 | kTXNSupportSpellCheckCommandUpdating
1741 | kTXNSupportFontCommandProcessing
1742 | kTXNSupportFontCommandUpdating
;
1744 TXNSetCommandEventSupport( m_txn
, options
) ;
1750 void wxMacMLTEControl::SetBackground( const wxBrush
&brush
)
1752 // currently only solid background are supported
1753 TXNBackground tback
;
1755 tback
.bgType
= kTXNBackgroundTypeRGB
;
1756 tback
.bg
.color
= MAC_WXCOLORREF( brush
.GetColour().GetPixel() );
1757 TXNSetBackground( m_txn
, &tback
);
1760 void wxMacMLTEControl::TXNSetAttribute( const wxTextAttr
& style
, long from
, long to
)
1762 TXNTypeAttributes typeAttr
[4] ;
1763 Str255 fontName
= "\pMonaco" ;
1764 SInt16 fontSize
= 12 ;
1765 Style fontStyle
= normal
;
1769 if ( style
.HasFont() )
1771 const wxFont
&font
= style
.GetFont() ;
1772 wxMacStringToPascal( font
.GetFaceName() , fontName
) ;
1773 fontSize
= font
.GetPointSize() ;
1774 if ( font
.GetUnderlined() )
1775 fontStyle
|= underline
;
1776 if ( font
.GetWeight() == wxBOLD
)
1778 if ( font
.GetStyle() == wxITALIC
)
1779 fontStyle
|= italic
;
1781 typeAttr
[attrCount
].tag
= kTXNQDFontNameAttribute
;
1782 typeAttr
[attrCount
].size
= kTXNQDFontNameAttributeSize
;
1783 typeAttr
[attrCount
].data
.dataPtr
= (void*)fontName
;
1786 typeAttr
[attrCount
].tag
= kTXNQDFontSizeAttribute
;
1787 typeAttr
[attrCount
].size
= kTXNFontSizeAttributeSize
;
1788 typeAttr
[attrCount
].data
.dataValue
= (fontSize
<< 16) ;
1791 typeAttr
[attrCount
].tag
= kTXNQDFontStyleAttribute
;
1792 typeAttr
[attrCount
].size
= kTXNQDFontStyleAttributeSize
;
1793 typeAttr
[attrCount
].data
.dataValue
= fontStyle
;
1797 if ( style
.HasTextColour() )
1799 color
= MAC_WXCOLORREF(style
.GetTextColour().GetPixel()) ;
1801 typeAttr
[attrCount
].tag
= kTXNQDFontColorAttribute
;
1802 typeAttr
[attrCount
].size
= kTXNQDFontColorAttributeSize
;
1803 typeAttr
[attrCount
].data
.dataPtr
= (void*) &color
;
1807 if ( attrCount
> 0 )
1809 verify_noerr( TXNSetTypeAttributes( m_txn
, attrCount
, typeAttr
, from
, to
) );
1813 void wxMacMLTEControl::SetFont( const wxFont
& font
, const wxColour
& foreground
, long windowStyle
)
1815 wxMacEditHelper
help( m_txn
) ;
1816 TXNSetAttribute( wxTextAttr( foreground
, wxNullColour
, font
), kTXNStartOffset
, kTXNEndOffset
) ;
1819 void wxMacMLTEControl::SetStyle( long start
, long end
, const wxTextAttr
& style
)
1821 wxMacEditHelper
help( m_txn
) ;
1822 TXNSetAttribute( style
, start
, end
) ;
1825 void wxMacMLTEControl::Copy()
1827 ClearCurrentScrap();
1829 TXNConvertToPublicScrap();
1832 void wxMacMLTEControl::Cut()
1834 ClearCurrentScrap();
1836 TXNConvertToPublicScrap();
1839 void wxMacMLTEControl::Paste()
1841 TXNConvertFromPublicScrap();
1845 bool wxMacMLTEControl::CanPaste() const
1847 return TXNIsScrapPastable() ;
1850 void wxMacMLTEControl::SetEditable(bool editable
)
1852 TXNControlTag tag
[] = { kTXNIOPrivilegesTag
} ;
1853 TXNControlData data
[] = { { editable
? kTXNReadWrite
: kTXNReadOnly
} } ;
1854 TXNSetTXNObjectControls( m_txn
, false, WXSIZEOF(tag
), tag
, data
) ;
1857 wxTextPos
wxMacMLTEControl::GetLastPosition() const
1859 wxTextPos actualsize
= 0 ;
1862 OSErr err
= TXNGetDataEncoded( m_txn
, kTXNStartOffset
, kTXNEndOffset
, &theText
, kTXNTextData
);
1867 actualsize
= GetHandleSize( theText
) ;
1868 DisposeHandle( theText
) ;
1878 void wxMacMLTEControl::Replace( long from
, long to
, const wxString
&str
)
1880 wxString value
= str
;
1881 wxMacConvertNewlines10To13( &value
) ;
1883 wxMacEditHelper
help( m_txn
) ;
1884 wxMacWindowClipper
c( m_peer
) ;
1886 TXNSetSelection( m_txn
, from
, to
) ;
1888 SetTXNData( value
, kTXNUseCurrentSelection
, kTXNUseCurrentSelection
) ;
1891 void wxMacMLTEControl::Remove( long from
, long to
)
1893 wxMacWindowClipper
c( m_peer
) ;
1894 wxMacEditHelper
help( m_txn
) ;
1895 TXNSetSelection( m_txn
, from
, to
) ;
1899 void wxMacMLTEControl::GetSelection( long* from
, long* to
) const
1901 TXNGetSelection( m_txn
, (TXNOffset
*) from
, (TXNOffset
*) to
) ;
1904 void wxMacMLTEControl::SetSelection( long from
, long to
)
1906 wxMacWindowClipper
c( m_peer
) ;
1908 // change the selection
1909 if ((from
== -1) && (to
== -1))
1910 TXNSelectAll( m_txn
);
1912 TXNSetSelection( m_txn
, from
, to
);
1914 TXNShowSelection( m_txn
, kTXNShowStart
);
1917 void wxMacMLTEControl::WriteText( const wxString
& str
)
1920 wxMacConvertNewlines10To13( &st
) ;
1922 long start
, end
, dummy
;
1924 GetSelection( &start
, &dummy
) ;
1925 wxMacWindowClipper
c( m_peer
) ;
1928 wxMacEditHelper
helper( m_txn
) ;
1929 SetTXNData( st
, kTXNUseCurrentSelection
, kTXNUseCurrentSelection
) ;
1932 GetSelection( &dummy
, &end
) ;
1934 // TODO: SetStyle( start , end , GetDefaultStyle() ) ;
1937 void wxMacMLTEControl::Clear()
1939 wxMacWindowClipper
c( m_peer
) ;
1940 wxMacEditHelper
st( m_txn
) ;
1941 TXNSetSelection( m_txn
, kTXNStartOffset
, kTXNEndOffset
) ;
1945 bool wxMacMLTEControl::CanUndo() const
1947 return TXNCanUndo( m_txn
, NULL
) ;
1950 void wxMacMLTEControl::Undo()
1955 bool wxMacMLTEControl::CanRedo() const
1957 return TXNCanRedo( m_txn
, NULL
) ;
1960 void wxMacMLTEControl::Redo()
1965 int wxMacMLTEControl::GetNumberOfLines() const
1967 ItemCount lines
= 0 ;
1968 TXNGetLineCount( m_txn
, &lines
) ;
1973 long wxMacMLTEControl::XYToPosition(long x
, long y
) const
1978 // TODO: find a better implementation : while we can get the
1979 // line metrics of a certain line, we don't get its starting
1980 // position, so it would probably be rather a binary search
1981 // for the start position
1982 long xpos
= 0, ypos
= 0 ;
1983 int lastHeight
= 0 ;
1986 lastpos
= GetLastPosition() ;
1987 for ( n
= 0 ; n
<= (ItemCount
) lastpos
; ++n
)
1989 if ( y
== ypos
&& x
== xpos
)
1992 TXNOffsetToPoint( m_txn
, n
, &curpt
) ;
1994 if ( curpt
.v
> lastHeight
)
2000 lastHeight
= curpt
.v
;
2009 bool wxMacMLTEControl::PositionToXY( long pos
, long *x
, long *y
) const
2019 lastpos
= GetLastPosition() ;
2020 if ( pos
<= lastpos
)
2022 // TODO: find a better implementation - while we can get the
2023 // line metrics of a certain line, we don't get its starting
2024 // position, so it would probably be rather a binary search
2025 // for the start position
2026 long xpos
= 0, ypos
= 0 ;
2027 int lastHeight
= 0 ;
2030 for ( n
= 0 ; n
<= (ItemCount
) pos
; ++n
)
2032 TXNOffsetToPoint( m_txn
, n
, &curpt
) ;
2034 if ( curpt
.v
> lastHeight
)
2040 lastHeight
= curpt
.v
;
2055 void wxMacMLTEControl::ShowPosition( long pos
)
2057 #if TARGET_RT_MAC_MACHO && defined(AVAILABLE_MAC_OS_X_VERSION_10_2_AND_LATER)
2059 Point current
, desired
;
2060 TXNOffset selstart
, selend
;
2062 TXNGetSelection( m_txn
, &selstart
, &selend
);
2063 TXNOffsetToPoint( m_txn
, selstart
, ¤t
);
2064 TXNOffsetToPoint( m_txn
, pos
, &desired
);
2066 // TODO: use HIPoints for 10.3 and above
2067 if ( (UInt32
)TXNScroll
!= (UInt32
)kUnresolvedCFragSymbolAddress
)
2069 OSErr theErr
= noErr
;
2070 SInt32 dv
= desired
.v
- current
.v
;
2071 SInt32 dh
= desired
.h
- current
.h
;
2072 TXNShowSelection( m_txn
, kTXNShowStart
) ; // NB: should this be kTXNShowStart or kTXNShowEnd ??
2073 theErr
= TXNScroll( m_txn
, kTXNScrollUnitsInPixels
, kTXNScrollUnitsInPixels
, &dv
, &dh
);
2075 // there will be an error returned for classic MLTE implementation when the control is
2076 // invisible, but HITextView works correctly, so we don't assert that one
2077 // wxASSERT_MSG( theErr == noErr, _T("TXNScroll returned an error!") );
2083 void wxMacMLTEControl::SetTXNData( const wxString
& st
, TXNOffset start
, TXNOffset end
)
2086 #if SIZEOF_WCHAR_T == 2
2087 size_t len
= st
.Len() ;
2088 TXNSetData( m_txn
, kTXNUnicodeTextData
, (void*)st
.wc_str(), len
* 2, start
, end
);
2090 wxMBConvUTF16 converter
;
2091 ByteCount byteBufferLen
= converter
.WC2MB( NULL
, st
.wc_str(), 0 ) ;
2092 UniChar
*unibuf
= (UniChar
*)malloc( byteBufferLen
) ;
2093 converter
.WC2MB( (char*)unibuf
, st
.wc_str(), byteBufferLen
) ;
2094 TXNSetData( m_txn
, kTXNUnicodeTextData
, (void*)unibuf
, byteBufferLen
, start
, end
) ;
2098 wxCharBuffer text
= st
.mb_str( wxConvLocal
) ;
2099 TXNSetData( m_txn
, kTXNTextData
, (void*)text
.data(), strlen( text
), start
, end
) ;
2103 wxString
wxMacMLTEControl::GetLineText(long lineNo
) const
2107 if ( lineNo
< GetNumberOfLines() )
2110 Fixed lineWidth
, lineHeight
, currentHeight
;
2113 // get the first possible position in the control
2114 TXNOffsetToPoint(m_txn
, 0, &firstPoint
);
2116 // Iterate through the lines until we reach the one we want,
2117 // adding to our current y pixel point position
2120 while (ypos
< lineNo
)
2122 TXNGetLineMetrics(m_txn
, ypos
++, &lineWidth
, &lineHeight
);
2123 currentHeight
+= lineHeight
;
2126 Point thePoint
= { firstPoint
.v
+ (currentHeight
>> 16), firstPoint
.h
+ (0) };
2127 TXNOffset theOffset
;
2128 TXNPointToOffset(m_txn
, thePoint
, &theOffset
);
2130 wxString content
= GetStringValue() ;
2131 Point currentPoint
= thePoint
;
2132 while (thePoint
.v
== currentPoint
.v
&& theOffset
< content
.length())
2134 line
+= content
[theOffset
];
2135 TXNOffsetToPoint(m_txn
, ++theOffset
, ¤tPoint
);
2142 int wxMacMLTEControl::GetLineLength(long lineNo
) const
2146 if ( lineNo
< GetNumberOfLines() )
2149 Fixed lineWidth
, lineHeight
, currentHeight
;
2152 // get the first possible position in the control
2153 TXNOffsetToPoint(m_txn
, 0, &firstPoint
);
2155 // Iterate through the lines until we reach the one we want,
2156 // adding to our current y pixel point position
2159 while (ypos
< lineNo
)
2161 TXNGetLineMetrics(m_txn
, ypos
++, &lineWidth
, &lineHeight
);
2162 currentHeight
+= lineHeight
;
2165 Point thePoint
= { firstPoint
.v
+ (currentHeight
>> 16), firstPoint
.h
+ (0) };
2166 TXNOffset theOffset
;
2167 TXNPointToOffset(m_txn
, thePoint
, &theOffset
);
2169 wxString content
= GetStringValue() ;
2170 Point currentPoint
= thePoint
;
2171 while (thePoint
.v
== currentPoint
.v
&& theOffset
< content
.length())
2174 TXNOffsetToPoint(m_txn
, ++theOffset
, ¤tPoint
);
2181 // ----------------------------------------------------------------------------
2182 // MLTE control implementation (classic part)
2183 // ----------------------------------------------------------------------------
2185 // OS X Notes : We still don't have a full replacement for MLTE, so this implementation
2186 // has to live on. We have different problems coming from outdated implementations on the
2187 // various OS X versions. Most deal with the scrollbars: they are not correctly embedded
2188 // while this can be solved on 10.3 by reassigning them the correct place, on 10.2 there is
2189 // no way out, therefore we are using our own implementation and our own scrollbars ....
2191 #ifdef __WXMAC_OSX__
2193 TXNScrollInfoUPP gTXNScrollInfoProc
= NULL
;
2194 ControlActionUPP gTXNScrollActionProc
= NULL
;
2196 pascal void wxMacMLTEClassicControl::TXNScrollInfoProc(
2197 SInt32 iValue
, SInt32 iMaximumValue
,
2198 TXNScrollBarOrientation iScrollBarOrientation
, SInt32 iRefCon
)
2200 wxMacMLTEClassicControl
* mlte
= (wxMacMLTEClassicControl
*) iRefCon
;
2201 SInt32 value
= wxMax( iValue
, 0 ) ;
2202 SInt32 maximum
= wxMax( iMaximumValue
, 0 ) ;
2204 if ( iScrollBarOrientation
== kTXNHorizontal
)
2206 if ( mlte
->m_sbHorizontal
)
2208 SetControl32BitValue( mlte
->m_sbHorizontal
, value
) ;
2209 SetControl32BitMaximum( mlte
->m_sbHorizontal
, maximum
) ;
2210 mlte
->m_lastHorizontalValue
= value
;
2213 else if ( iScrollBarOrientation
== kTXNVertical
)
2215 if ( mlte
->m_sbVertical
)
2217 SetControl32BitValue( mlte
->m_sbVertical
, value
) ;
2218 SetControl32BitMaximum( mlte
->m_sbVertical
, maximum
) ;
2219 mlte
->m_lastVerticalValue
= value
;
2224 pascal void wxMacMLTEClassicControl::TXNScrollActionProc( ControlRef controlRef
, ControlPartCode partCode
)
2226 wxMacMLTEClassicControl
* mlte
= (wxMacMLTEClassicControl
*) GetControlReference( controlRef
) ;
2230 if ( controlRef
!= mlte
->m_sbVertical
&& controlRef
!= mlte
->m_sbHorizontal
)
2234 bool isHorizontal
= ( controlRef
== mlte
->m_sbHorizontal
) ;
2236 SInt32 minimum
= 0 ;
2237 SInt32 maximum
= GetControl32BitMaximum( controlRef
) ;
2238 SInt32 value
= GetControl32BitValue( controlRef
) ;
2243 case kControlDownButtonPart
:
2247 case kControlUpButtonPart
:
2251 case kControlPageDownPart
:
2252 delta
= GetControlViewSize( controlRef
) ;
2255 case kControlPageUpPart
:
2256 delta
= -GetControlViewSize( controlRef
) ;
2259 case kControlIndicatorPart
:
2260 delta
= value
- (isHorizontal
? mlte
->m_lastHorizontalValue
: mlte
->m_lastVerticalValue
) ;
2269 SInt32 newValue
= value
;
2271 if ( partCode
!= kControlIndicatorPart
)
2273 if ( value
+ delta
< minimum
)
2274 delta
= minimum
- value
;
2275 if ( value
+ delta
> maximum
)
2276 delta
= maximum
- value
;
2278 SetControl32BitValue( controlRef
, value
+ delta
) ;
2279 newValue
= value
+ delta
;
2282 SInt32 verticalDelta
= isHorizontal
? 0 : delta
;
2283 SInt32 horizontalDelta
= isHorizontal
? delta
: 0 ;
2286 mlte
->m_txn
, kTXNScrollUnitsInPixels
, kTXNScrollUnitsInPixels
,
2287 &verticalDelta
, &horizontalDelta
);
2288 verify_noerr( err
);
2291 mlte
->m_lastHorizontalValue
= newValue
;
2293 mlte
->m_lastVerticalValue
= newValue
;
2298 // make correct activations
2299 void wxMacMLTEClassicControl::MacActivatePaneText(bool setActive
)
2301 wxTextCtrl
* textctrl
= (wxTextCtrl
*) GetControlReference(m_controlRef
);
2303 wxMacWindowClipper
clipper( textctrl
) ;
2304 TXNActivate( m_txn
, m_txnFrameID
, setActive
);
2306 ControlRef controlFocus
= 0 ;
2307 GetKeyboardFocus( m_txnWindow
, &controlFocus
) ;
2308 if ( controlFocus
== m_controlRef
)
2309 TXNFocus( m_txn
, setActive
);
2312 void wxMacMLTEClassicControl::MacFocusPaneText(bool setFocus
)
2314 TXNFocus( m_txn
, setFocus
);
2317 // guards against inappropriate redraw (hidden objects drawing onto window)
2319 void wxMacMLTEClassicControl::MacSetObjectVisibility(bool vis
)
2321 ControlRef controlFocus
= 0 ;
2322 GetKeyboardFocus( m_txnWindow
, &controlFocus
) ;
2324 if ( !vis
&& (controlFocus
== m_controlRef
) )
2325 SetKeyboardFocus( m_txnWindow
, m_controlRef
, kControlFocusNoPart
) ;
2327 TXNControlTag iControlTags
[1] = { kTXNVisibilityTag
};
2328 TXNControlData iControlData
[1] = { { (UInt32
)false } };
2330 verify_noerr( TXNGetTXNObjectControls( m_txn
, 1, iControlTags
, iControlData
) ) ;
2332 if ( iControlData
[0].uValue
!= vis
)
2334 iControlData
[0].uValue
= vis
;
2335 verify_noerr( TXNSetTXNObjectControls( m_txn
, false , 1, iControlTags
, iControlData
) ) ;
2338 // currently, we always clip as partial visibility (overlapped) visibility is also a problem,
2339 // if we run into further problems we might set the FrameBounds to an empty rect here
2342 // make sure that the TXNObject is at the right position
2344 void wxMacMLTEClassicControl::MacUpdatePosition()
2346 wxTextCtrl
* textctrl
= (wxTextCtrl
*)GetControlReference( m_controlRef
);
2347 if ( textctrl
== NULL
)
2351 UMAGetControlBoundsInWindowCoords( m_controlRef
, &bounds
);
2353 wxRect visRect
= textctrl
->MacGetClippedClientRect() ;
2354 Rect visBounds
= { visRect
.y
, visRect
.x
, visRect
.y
+ visRect
.height
, visRect
.x
+ visRect
.width
} ;
2357 textctrl
->MacWindowToRootWindow( &x
, &y
) ;
2358 OffsetRect( &visBounds
, x
, y
) ;
2360 if ( !EqualRect( &bounds
, &m_txnControlBounds
) || !EqualRect( &visBounds
, &m_txnVisBounds
) )
2362 m_txnControlBounds
= bounds
;
2363 m_txnVisBounds
= visBounds
;
2364 wxMacWindowClipper
cl( textctrl
) ;
2366 #ifdef __WXMAC_OSX__
2367 bool isCompositing
= textctrl
->MacGetTopLevelWindow()->MacUsesCompositing() ;
2368 if ( m_sbHorizontal
|| m_sbVertical
)
2370 int w
= bounds
.right
- bounds
.left
;
2371 int h
= bounds
.bottom
- bounds
.top
;
2373 if ( m_sbHorizontal
)
2377 sbBounds
.left
= -1 ;
2378 sbBounds
.top
= h
- 14 ;
2379 sbBounds
.right
= w
+ 1 ;
2380 sbBounds
.bottom
= h
+ 1 ;
2382 if ( !isCompositing
)
2383 OffsetRect( &sbBounds
, m_txnControlBounds
.left
, m_txnControlBounds
.top
) ;
2385 SetControlBounds( m_sbHorizontal
, &sbBounds
) ;
2386 SetControlViewSize( m_sbHorizontal
, w
) ;
2393 sbBounds
.left
= w
- 14 ;
2395 sbBounds
.right
= w
+ 1 ;
2396 sbBounds
.bottom
= m_sbHorizontal
? h
- 14 : h
+ 1 ;
2398 if ( !isCompositing
)
2399 OffsetRect( &sbBounds
, m_txnControlBounds
.left
, m_txnControlBounds
.top
) ;
2401 SetControlBounds( m_sbVertical
, &sbBounds
) ;
2402 SetControlViewSize( m_sbVertical
, h
) ;
2407 TXNLongRect olddestRect
;
2408 TXNGetRectBounds( m_txn
, &oldviewRect
, &olddestRect
, NULL
) ;
2410 Rect viewRect
= { m_txnControlBounds
.top
, m_txnControlBounds
.left
,
2411 m_txnControlBounds
.bottom
- ( m_sbHorizontal
? 14 : 0 ) ,
2412 m_txnControlBounds
.right
- ( m_sbVertical
? 14 : 0 ) } ;
2413 TXNLongRect destRect
= { m_txnControlBounds
.top
, m_txnControlBounds
.left
,
2414 m_txnControlBounds
.bottom
- ( m_sbHorizontal
? 14 : 0 ) ,
2415 m_txnControlBounds
.right
- ( m_sbVertical
? 14 : 0 ) } ;
2417 if ( olddestRect
.right
>= 10000 )
2418 destRect
.right
= destRect
.left
+ 32000 ;
2420 if ( olddestRect
.bottom
>= 0x20000000 )
2421 destRect
.bottom
= destRect
.top
+ 0x40000000 ;
2423 SectRect( &viewRect
, &visBounds
, &viewRect
) ;
2424 TXNSetRectBounds( m_txn
, &viewRect
, &destRect
, true ) ;
2429 m_txnControlBounds
.top
,
2430 m_txnControlBounds
.left
,
2431 m_txnControlBounds
.bottom
- (m_sbHorizontal
? 14 : 0),
2432 m_txnControlBounds
.right
- (m_sbVertical
? 14 : 0),
2438 m_txn
, m_txnControlBounds
.top
, m_txnControlBounds
.left
,
2439 wxMax( m_txnControlBounds
.bottom
, m_txnControlBounds
.top
),
2440 wxMax( m_txnControlBounds
.right
, m_txnControlBounds
.left
), m_txnFrameID
);
2443 // the SetFrameBounds method under Classic sometimes does not correctly scroll a selection into sight after a
2444 // movement, therefore we have to force it
2446 // this problem has been reported in OSX as well, so we use this here once again
2448 TXNLongRect textRect
;
2449 TXNGetRectBounds( m_txn
, NULL
, NULL
, &textRect
) ;
2450 if ( textRect
.left
< m_txnControlBounds
.left
)
2451 TXNShowSelection( m_txn
, kTXNShowStart
) ;
2455 void wxMacMLTEClassicControl::SetRect( Rect
*r
)
2457 wxMacControl::SetRect( r
) ;
2458 MacUpdatePosition() ;
2461 void wxMacMLTEClassicControl::MacControlUserPaneDrawProc(wxInt16 thePart
)
2463 wxTextCtrl
* textctrl
= (wxTextCtrl
*)GetControlReference( m_controlRef
);
2464 if ( textctrl
== NULL
)
2467 if ( textctrl
->MacIsReallyShown() )
2469 wxMacWindowClipper
clipper( textctrl
) ;
2470 TXNDraw( m_txn
, NULL
) ;
2474 wxInt16
wxMacMLTEClassicControl::MacControlUserPaneHitTestProc(wxInt16 x
, wxInt16 y
)
2476 Point where
= { y
, x
} ;
2477 ControlPartCode result
= kControlNoPart
;
2479 wxTextCtrl
* textctrl
= (wxTextCtrl
*) GetControlReference( m_controlRef
);
2480 if ( (textctrl
!= NULL
) && textctrl
->MacIsReallyShown() )
2482 if (PtInRect( where
, &m_txnControlBounds
))
2484 result
= kControlEditTextPart
;
2488 // sometimes we get the coords also in control local coordinates, therefore test again
2489 if ( textctrl
->MacGetTopLevelWindow()->MacUsesCompositing() )
2492 textctrl
->MacClientToRootWindow( &x
, &y
) ;
2497 if (PtInRect( where
, &m_txnControlBounds
))
2498 result
= kControlEditTextPart
;
2505 wxInt16
wxMacMLTEClassicControl::MacControlUserPaneTrackingProc( wxInt16 x
, wxInt16 y
, void* actionProc
)
2507 ControlPartCode result
= kControlNoPart
;
2509 wxTextCtrl
* textctrl
= (wxTextCtrl
*) GetControlReference( m_controlRef
);
2510 if ( (textctrl
!= NULL
) && textctrl
->MacIsReallyShown() )
2512 Point startPt
= { y
, x
} ;
2513 // for compositing, we must convert these into toplevel window coordinates, because hittesting expects them
2514 if ( textctrl
->MacGetTopLevelWindow()->MacUsesCompositing() )
2517 textctrl
->MacClientToRootWindow( &x
, &y
) ;
2522 switch (MacControlUserPaneHitTestProc( startPt
.h
, startPt
.v
))
2524 case kControlEditTextPart
:
2526 wxMacWindowClipper
clipper( textctrl
) ;
2529 ConvertEventRefToEventRecord( (EventRef
) wxTheApp
->MacGetCurrentEvent() , &rec
) ;
2530 TXNClick( m_txn
, &rec
);
2542 void wxMacMLTEClassicControl::MacControlUserPaneIdleProc()
2544 wxTextCtrl
* textctrl
= (wxTextCtrl
*)GetControlReference( m_controlRef
);
2545 if ( textctrl
== NULL
)
2548 if (textctrl
->MacIsReallyShown())
2550 if (IsControlActive(m_controlRef
))
2554 wxMacWindowClipper
clipper( textctrl
) ;
2559 if (PtInRect(mousep
, &m_txnControlBounds
))
2561 RgnHandle theRgn
= NewRgn();
2562 RectRgn(theRgn
, &m_txnControlBounds
);
2563 TXNAdjustCursor(m_txn
, theRgn
);
2570 wxInt16
wxMacMLTEClassicControl::MacControlUserPaneKeyDownProc (wxInt16 keyCode
, wxInt16 charCode
, wxInt16 modifiers
)
2572 wxTextCtrl
* textctrl
= (wxTextCtrl
*)GetControlReference( m_controlRef
);
2573 if ( textctrl
== NULL
)
2574 return kControlNoPart
;
2576 wxMacWindowClipper
clipper( textctrl
) ;
2579 memset( &ev
, 0 , sizeof( ev
) ) ;
2581 ev
.modifiers
= modifiers
;
2582 ev
.message
= ((keyCode
<< 8) & keyCodeMask
) | (charCode
& charCodeMask
);
2583 TXNKeyDown( m_txn
, &ev
);
2585 return kControlEntireControl
;
2588 void wxMacMLTEClassicControl::MacControlUserPaneActivateProc(bool activating
)
2590 MacActivatePaneText( activating
);
2593 wxInt16
wxMacMLTEClassicControl::MacControlUserPaneFocusProc(wxInt16 action
)
2595 ControlPartCode focusResult
= kControlFocusNoPart
;
2597 wxTextCtrl
* textctrl
= (wxTextCtrl
*)GetControlReference( m_controlRef
);
2598 if ( textctrl
== NULL
)
2601 wxMacWindowClipper
clipper( textctrl
) ;
2603 ControlRef controlFocus
= NULL
;
2604 GetKeyboardFocus( m_txnWindow
, &controlFocus
) ;
2605 bool wasFocused
= ( controlFocus
== m_controlRef
) ;
2609 case kControlFocusPrevPart
:
2610 case kControlFocusNextPart
:
2611 MacFocusPaneText( !wasFocused
);
2612 focusResult
= (!wasFocused
? (ControlPartCode
) kControlEditTextPart
: (ControlPartCode
) kControlFocusNoPart
);
2615 case kControlFocusNoPart
:
2617 MacFocusPaneText( false );
2618 focusResult
= kControlFocusNoPart
;
2625 void wxMacMLTEClassicControl::MacControlUserPaneBackgroundProc( void *info
)
2629 wxMacMLTEClassicControl::wxMacMLTEClassicControl( wxTextCtrl
*wxPeer
,
2630 const wxString
& str
,
2632 const wxSize
& size
, long style
)
2633 : wxMacMLTEControl( wxPeer
)
2635 m_font
= wxPeer
->GetFont() ;
2636 m_windowStyle
= style
;
2637 Rect bounds
= wxMacGetBoundsForControl( wxPeer
, pos
, size
) ;
2640 kControlSupportsEmbedding
| kControlSupportsFocus
| kControlWantsIdle
2641 | kControlWantsActivate
| kControlHandlesTracking
2642 // | kControlHasSpecialBackground
2643 | kControlGetsFocusOnClick
| kControlSupportsLiveFeedback
;
2645 OSStatus err
= ::CreateUserPaneControl(
2646 MAC_WXHWND(wxPeer
->GetParent()->MacGetTopLevelWindowRef()),
2647 &bounds
, featureSet
, &m_controlRef
);
2648 verify_noerr( err
);
2652 AdjustCreationAttributes( *wxWHITE
, true ) ;
2654 MacSetObjectVisibility( wxPeer
->MacIsReallyShown() ) ;
2658 wxMacConvertNewlines10To13( &st
) ;
2659 wxMacWindowClipper
clipper( m_peer
) ;
2660 SetTXNData( st
, kTXNStartOffset
, kTXNEndOffset
) ;
2661 TXNSetSelection( m_txn
, 0, 0 ) ;
2665 wxMacMLTEClassicControl::~wxMacMLTEClassicControl()
2667 TXNDeleteObject( m_txn
);
2671 void wxMacMLTEClassicControl::VisibilityChanged(bool shown
)
2673 MacSetObjectVisibility( shown
) ;
2674 wxMacControl::VisibilityChanged( shown
) ;
2677 void wxMacMLTEClassicControl::SuperChangedPosition()
2679 MacUpdatePosition() ;
2680 wxMacControl::SuperChangedPosition() ;
2683 #ifdef __WXMAC_OSX__
2685 ControlUserPaneDrawUPP gTPDrawProc
= NULL
;
2686 ControlUserPaneHitTestUPP gTPHitProc
= NULL
;
2687 ControlUserPaneTrackingUPP gTPTrackProc
= NULL
;
2688 ControlUserPaneIdleUPP gTPIdleProc
= NULL
;
2689 ControlUserPaneKeyDownUPP gTPKeyProc
= NULL
;
2690 ControlUserPaneActivateUPP gTPActivateProc
= NULL
;
2691 ControlUserPaneFocusUPP gTPFocusProc
= NULL
;
2693 static pascal void wxMacControlUserPaneDrawProc(ControlRef control
, SInt16 part
)
2695 wxTextCtrl
*textCtrl
= wxDynamicCast( wxFindControlFromMacControl(control
) , wxTextCtrl
) ;
2696 wxMacMLTEClassicControl
* win
= textCtrl
? (wxMacMLTEClassicControl
*)(textCtrl
->GetPeer()) : NULL
;
2698 win
->MacControlUserPaneDrawProc( part
) ;
2701 static pascal ControlPartCode
wxMacControlUserPaneHitTestProc(ControlRef control
, Point where
)
2703 wxTextCtrl
*textCtrl
= wxDynamicCast( wxFindControlFromMacControl(control
) , wxTextCtrl
) ;
2704 wxMacMLTEClassicControl
* win
= textCtrl
? (wxMacMLTEClassicControl
*)(textCtrl
->GetPeer()) : NULL
;
2706 return win
->MacControlUserPaneHitTestProc( where
.h
, where
.v
) ;
2708 return kControlNoPart
;
2711 static pascal ControlPartCode
wxMacControlUserPaneTrackingProc(ControlRef control
, Point startPt
, ControlActionUPP actionProc
)
2713 wxTextCtrl
*textCtrl
= wxDynamicCast( wxFindControlFromMacControl(control
) , wxTextCtrl
) ;
2714 wxMacMLTEClassicControl
* win
= textCtrl
? (wxMacMLTEClassicControl
*)(textCtrl
->GetPeer()) : NULL
;
2716 return win
->MacControlUserPaneTrackingProc( startPt
.h
, startPt
.v
, (void*) actionProc
) ;
2718 return kControlNoPart
;
2721 static pascal void wxMacControlUserPaneIdleProc(ControlRef control
)
2723 wxTextCtrl
*textCtrl
= wxDynamicCast( wxFindControlFromMacControl(control
) , wxTextCtrl
) ;
2724 wxMacMLTEClassicControl
* win
= textCtrl
? (wxMacMLTEClassicControl
*)(textCtrl
->GetPeer()) : NULL
;
2726 win
->MacControlUserPaneIdleProc() ;
2729 static pascal ControlPartCode
wxMacControlUserPaneKeyDownProc(ControlRef control
, SInt16 keyCode
, SInt16 charCode
, SInt16 modifiers
)
2731 wxTextCtrl
*textCtrl
= wxDynamicCast( wxFindControlFromMacControl(control
) , wxTextCtrl
) ;
2732 wxMacMLTEClassicControl
* win
= textCtrl
? (wxMacMLTEClassicControl
*)(textCtrl
->GetPeer()) : NULL
;
2734 return win
->MacControlUserPaneKeyDownProc( keyCode
, charCode
, modifiers
) ;
2736 return kControlNoPart
;
2739 static pascal void wxMacControlUserPaneActivateProc(ControlRef control
, Boolean activating
)
2741 wxTextCtrl
*textCtrl
= wxDynamicCast( wxFindControlFromMacControl(control
) , wxTextCtrl
) ;
2742 wxMacMLTEClassicControl
* win
= textCtrl
? (wxMacMLTEClassicControl
*)(textCtrl
->GetPeer()) : NULL
;
2744 win
->MacControlUserPaneActivateProc( activating
) ;
2747 static pascal ControlPartCode
wxMacControlUserPaneFocusProc(ControlRef control
, ControlFocusPart action
)
2749 wxTextCtrl
*textCtrl
= wxDynamicCast( wxFindControlFromMacControl(control
) , wxTextCtrl
) ;
2750 wxMacMLTEClassicControl
* win
= textCtrl
? (wxMacMLTEClassicControl
*)(textCtrl
->GetPeer()) : NULL
;
2752 return win
->MacControlUserPaneFocusProc( action
) ;
2754 return kControlNoPart
;
2758 static pascal void wxMacControlUserPaneBackgroundProc(ControlRef control
, ControlBackgroundPtr info
)
2760 wxTextCtrl
*textCtrl
= wxDynamicCast( wxFindControlFromMacControl(control
) , wxTextCtrl
) ;
2761 wxMacMLTEClassicControl
* win
= textCtrl
? (wxMacMLTEClassicControl
*)(textCtrl
->GetPeer()) : NULL
;
2763 win
->MacControlUserPaneBackgroundProc(info
) ;
2767 #endif // __WXMAC_OSX__
2769 // TXNRegisterScrollInfoProc
2771 OSStatus
wxMacMLTEClassicControl::DoCreate()
2774 OSStatus err
= noErr
;
2776 // set up our globals
2777 #ifdef __WXMAC_OSX__
2778 if (gTPDrawProc
== NULL
) gTPDrawProc
= NewControlUserPaneDrawUPP(wxMacControlUserPaneDrawProc
);
2779 if (gTPHitProc
== NULL
) gTPHitProc
= NewControlUserPaneHitTestUPP(wxMacControlUserPaneHitTestProc
);
2780 if (gTPTrackProc
== NULL
) gTPTrackProc
= NewControlUserPaneTrackingUPP(wxMacControlUserPaneTrackingProc
);
2781 if (gTPIdleProc
== NULL
) gTPIdleProc
= NewControlUserPaneIdleUPP(wxMacControlUserPaneIdleProc
);
2782 if (gTPKeyProc
== NULL
) gTPKeyProc
= NewControlUserPaneKeyDownUPP(wxMacControlUserPaneKeyDownProc
);
2783 if (gTPActivateProc
== NULL
) gTPActivateProc
= NewControlUserPaneActivateUPP(wxMacControlUserPaneActivateProc
);
2784 if (gTPFocusProc
== NULL
) gTPFocusProc
= NewControlUserPaneFocusUPP(wxMacControlUserPaneFocusProc
);
2786 if (gTXNScrollInfoProc
== NULL
) gTXNScrollInfoProc
= NewTXNScrollInfoUPP(TXNScrollInfoProc
) ;
2787 if (gTXNScrollActionProc
== NULL
) gTXNScrollActionProc
= NewControlActionUPP(TXNScrollActionProc
) ;
2790 // set the initial settings for our private data
2792 m_txnWindow
= GetControlOwner(m_controlRef
);
2793 m_txnPort
= (GrafPtr
) GetWindowPort(m_txnWindow
);
2795 #ifdef __WXMAC_OSX__
2796 // set up the user pane procedures
2797 SetControlData(m_controlRef
, kControlEntireControl
, kControlUserPaneDrawProcTag
, sizeof(gTPDrawProc
), &gTPDrawProc
);
2798 SetControlData(m_controlRef
, kControlEntireControl
, kControlUserPaneHitTestProcTag
, sizeof(gTPHitProc
), &gTPHitProc
);
2799 SetControlData(m_controlRef
, kControlEntireControl
, kControlUserPaneTrackingProcTag
, sizeof(gTPTrackProc
), &gTPTrackProc
);
2800 SetControlData(m_controlRef
, kControlEntireControl
, kControlUserPaneIdleProcTag
, sizeof(gTPIdleProc
), &gTPIdleProc
);
2801 SetControlData(m_controlRef
, kControlEntireControl
, kControlUserPaneKeyDownProcTag
, sizeof(gTPKeyProc
), &gTPKeyProc
);
2802 SetControlData(m_controlRef
, kControlEntireControl
, kControlUserPaneActivateProcTag
, sizeof(gTPActivateProc
), &gTPActivateProc
);
2803 SetControlData(m_controlRef
, kControlEntireControl
, kControlUserPaneFocusProcTag
, sizeof(gTPFocusProc
), &gTPFocusProc
);
2806 // calculate the rectangles used by the control
2807 UMAGetControlBoundsInWindowCoords( m_controlRef
, &bounds
);
2809 m_txnControlBounds
= bounds
;
2810 m_txnVisBounds
= bounds
;
2815 GetGWorld( &origPort
, &origDev
) ;
2816 SetPort( m_txnPort
);
2818 // create the new edit field
2819 TXNFrameOptions frameOptions
= FrameOptionsFromWXStyle( m_windowStyle
);
2821 #ifdef __WXMAC_OSX__
2822 // the scrollbars are not correctly embedded but are inserted at the root:
2823 // this gives us problems as we have erratic redraws even over the structure area
2825 m_sbHorizontal
= 0 ;
2827 m_lastHorizontalValue
= 0 ;
2828 m_lastVerticalValue
= 0 ;
2830 Rect sb
= { 0 , 0 , 0 , 0 } ;
2831 if ( frameOptions
& kTXNWantVScrollBarMask
)
2833 CreateScrollBarControl( m_txnWindow
, &sb
, 0, 0, 100, 1, true, gTXNScrollActionProc
, &m_sbVertical
);
2834 SetControlReference( m_sbVertical
, (SInt32
)this );
2835 SetControlAction( m_sbVertical
, gTXNScrollActionProc
);
2836 ShowControl( m_sbVertical
);
2837 EmbedControl( m_sbVertical
, m_controlRef
);
2838 frameOptions
&= ~kTXNWantVScrollBarMask
;
2841 if ( frameOptions
& kTXNWantHScrollBarMask
)
2843 CreateScrollBarControl( m_txnWindow
, &sb
, 0, 0, 100, 1, true, gTXNScrollActionProc
, &m_sbHorizontal
);
2844 SetControlReference( m_sbHorizontal
, (SInt32
)this );
2845 SetControlAction( m_sbHorizontal
, gTXNScrollActionProc
);
2846 ShowControl( m_sbHorizontal
);
2847 EmbedControl( m_sbHorizontal
, m_controlRef
);
2848 frameOptions
&= ~(kTXNWantHScrollBarMask
| kTXNDrawGrowIconMask
);
2854 NULL
, m_txnWindow
, &bounds
, frameOptions
,
2855 kTXNTextEditStyleFrameType
, kTXNTextensionFile
, kTXNSystemDefaultEncoding
,
2856 &m_txn
, &m_txnFrameID
, NULL
);
2857 verify_noerr( err
);
2860 TXNControlTag iControlTags
[] = { kTXNUseCarbonEvents
};
2861 TXNControlData iControlData
[] = { { (UInt32
)&cInfo
} };
2862 int toptag
= WXSIZEOF( iControlTags
) ;
2863 TXNCarbonEventInfo cInfo
;
2864 cInfo
.useCarbonEvents
= false ;
2867 cInfo
.fDictionary
= NULL
;
2869 verify_noerr( TXNSetTXNObjectControls( m_txn
, false, toptag
, iControlTags
, iControlData
) );
2872 #ifdef __WXMAC_OSX__
2873 TXNRegisterScrollInfoProc( m_txn
, gTXNScrollInfoProc
, (SInt32
)this );
2876 SetGWorld( origPort
, origDev
) ;
2881 // ----------------------------------------------------------------------------
2882 // MLTE control implementation (OSX part)
2883 // ----------------------------------------------------------------------------
2885 #if TARGET_API_MAC_OSX
2887 #if MAC_OS_X_VERSION_MAX_ALLOWED > MAC_OS_X_VERSION_10_2
2889 wxMacMLTEHIViewControl::wxMacMLTEHIViewControl( wxTextCtrl
*wxPeer
,
2890 const wxString
& str
,
2892 const wxSize
& size
, long style
) : wxMacMLTEControl( wxPeer
)
2894 m_font
= wxPeer
->GetFont() ;
2895 m_windowStyle
= style
;
2896 Rect bounds
= wxMacGetBoundsForControl( wxPeer
, pos
, size
) ;
2898 wxMacConvertNewlines10To13( &st
) ;
2901 { bounds
.left
, bounds
.top
},
2902 { bounds
.right
- bounds
.left
, bounds
.bottom
- bounds
.top
} } ;
2904 m_scrollView
= NULL
;
2905 TXNFrameOptions frameOptions
= FrameOptionsFromWXStyle( style
) ;
2906 if ( frameOptions
& (kTXNWantVScrollBarMask
| kTXNWantHScrollBarMask
) )
2909 (frameOptions
& kTXNWantHScrollBarMask
? kHIScrollViewOptionsHorizScroll
: 0)
2910 | (frameOptions
& kTXNWantVScrollBarMask
? kHIScrollViewOptionsVertScroll
: 0) ,
2913 HIViewSetFrame( m_scrollView
, &hr
);
2914 HIViewSetVisible( m_scrollView
, true );
2918 HITextViewCreate( NULL
, 0, frameOptions
, &m_textView
) ;
2919 m_txn
= HITextViewGetTXNObject( m_textView
) ;
2920 HIViewSetVisible( m_textView
, true ) ;
2923 HIViewAddSubview( m_scrollView
, m_textView
) ;
2924 m_controlRef
= m_scrollView
;
2925 wxPeer
->MacInstallEventHandler( (WXWidget
) m_textView
) ;
2929 HIViewSetFrame( m_textView
, &hr
);
2930 m_controlRef
= m_textView
;
2933 AdjustCreationAttributes( *wxWHITE
, true ) ;
2935 wxMacWindowClipper
c( m_peer
) ;
2936 SetTXNData( st
, kTXNStartOffset
, kTXNEndOffset
) ;
2938 TXNSetSelection( m_txn
, 0, 0 );
2939 TXNShowSelection( m_txn
, kTXNShowStart
);
2942 OSStatus
wxMacMLTEHIViewControl::SetFocus( ControlFocusPart focusPart
)
2944 return SetKeyboardFocus( GetControlOwner( m_textView
), m_textView
, focusPart
) ;
2947 bool wxMacMLTEHIViewControl::HasFocus() const
2949 ControlRef control
;
2950 GetKeyboardFocus( GetUserFocusWindow() , &control
) ;
2951 return control
== m_textView
;
2954 void wxMacMLTEHIViewControl::SetBackground( const wxBrush
&brush
)
2956 wxMacMLTEControl::SetBackground( brush
) ;
2959 CGColorSpaceRef rgbSpace
= CGColorSpaceCreateDeviceRGB();
2960 RGBColor col
= MAC_WXCOLORREF(brush
.GetColour().GetPixel()) ;
2962 float component
[4] ;
2963 component
[0] = col
.red
/ 65536.0 ;
2964 component
[1] = col
.green
/ 65536.0 ;
2965 component
[2] = col
.blue
/ 65536.0 ;
2966 component
[3] = 1.0 ; // alpha
2968 CGColorRef color
= CGColorCreate( rgbSpace
, component
);
2969 HITextViewSetBackgroundColor( m_textView
, color
);
2970 CGColorSpaceRelease( rgbSpace
);
2974 #endif // MAC_OS_X_VERSION_MAX_ALLOWED > MAC_OS_X_VERSION_10_2
2979 #endif // wxUSE_TEXTCTRL