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() ;
354 virtual void VisibilityChanged(bool shown
) ;
355 virtual void SuperChangedPosition() ;
357 virtual void MacControlUserPaneDrawProc(wxInt16 part
) ;
358 virtual wxInt16
MacControlUserPaneHitTestProc(wxInt16 x
, wxInt16 y
) ;
359 virtual wxInt16
MacControlUserPaneTrackingProc(wxInt16 x
, wxInt16 y
, void* actionProc
) ;
360 virtual void MacControlUserPaneIdleProc() ;
361 virtual wxInt16
MacControlUserPaneKeyDownProc(wxInt16 keyCode
, wxInt16 charCode
, wxInt16 modifiers
) ;
362 virtual void MacControlUserPaneActivateProc(bool activating
) ;
363 virtual wxInt16
MacControlUserPaneFocusProc(wxInt16 action
) ;
364 virtual void MacControlUserPaneBackgroundProc(void* info
) ;
366 virtual bool SetupCursor( const wxPoint
& WXUNUSED(pt
) ) { MacControlUserPaneIdleProc() ; return true ;}
368 virtual void SetRect( Rect
*r
) ;
373 void MacUpdatePosition() ;
374 void MacActivatePaneText(bool setActive
) ;
375 void MacFocusPaneText(bool setFocus
) ;
376 void MacSetObjectVisibility(bool vis
) ;
379 TXNFrameID m_txnFrameID
;
381 WindowRef m_txnWindow
;
382 // bounds of the control as we last did set the txn frames
383 Rect m_txnControlBounds
;
384 Rect m_txnVisBounds
;
387 static pascal void TXNScrollActionProc( ControlRef controlRef
, ControlPartCode partCode
) ;
388 static pascal void TXNScrollInfoProc(
389 SInt32 iValue
, SInt32 iMaximumValue
,
390 TXNScrollBarOrientation iScrollBarOrientation
, SInt32 iRefCon
) ;
392 ControlRef m_sbHorizontal
;
393 SInt32 m_lastHorizontalValue
;
394 ControlRef m_sbVertical
;
395 SInt32 m_lastVerticalValue
;
399 #define TE_UNLIMITED_LENGTH 0xFFFFFFFFUL
402 IMPLEMENT_DYNAMIC_CLASS(wxTextCtrl
, wxControl
)
404 BEGIN_EVENT_TABLE(wxTextCtrl
, wxControl
)
405 EVT_ERASE_BACKGROUND( wxTextCtrl::OnEraseBackground
)
406 EVT_DROP_FILES(wxTextCtrl::OnDropFiles
)
407 EVT_CHAR(wxTextCtrl::OnChar
)
408 EVT_MENU(wxID_CUT
, wxTextCtrl::OnCut
)
409 EVT_MENU(wxID_COPY
, wxTextCtrl::OnCopy
)
410 EVT_MENU(wxID_PASTE
, wxTextCtrl::OnPaste
)
411 EVT_MENU(wxID_UNDO
, wxTextCtrl::OnUndo
)
412 EVT_MENU(wxID_REDO
, wxTextCtrl::OnRedo
)
413 EVT_MENU(wxID_CLEAR
, wxTextCtrl::OnDelete
)
414 EVT_MENU(wxID_SELECTALL
, wxTextCtrl::OnSelectAll
)
416 EVT_CONTEXT_MENU(wxTextCtrl::OnContextMenu
)
418 EVT_UPDATE_UI(wxID_CUT
, wxTextCtrl::OnUpdateCut
)
419 EVT_UPDATE_UI(wxID_COPY
, wxTextCtrl::OnUpdateCopy
)
420 EVT_UPDATE_UI(wxID_PASTE
, wxTextCtrl::OnUpdatePaste
)
421 EVT_UPDATE_UI(wxID_UNDO
, wxTextCtrl::OnUpdateUndo
)
422 EVT_UPDATE_UI(wxID_REDO
, wxTextCtrl::OnUpdateRedo
)
423 EVT_UPDATE_UI(wxID_CLEAR
, wxTextCtrl::OnUpdateDelete
)
424 EVT_UPDATE_UI(wxID_SELECTALL
, wxTextCtrl::OnUpdateSelectAll
)
428 void wxTextCtrl::Init()
433 m_maxLength
= TE_UNLIMITED_LENGTH
;
434 m_privateContextMenu
= NULL
;
437 wxTextCtrl::~wxTextCtrl()
439 delete m_privateContextMenu
;
442 bool wxTextCtrl::Create(wxWindow
*parent
,
448 const wxValidator
& validator
,
449 const wxString
& name
)
451 m_macIsUserPane
= false ;
454 if ( ! (style
& wxNO_BORDER
) )
455 style
= (style
& ~wxBORDER_MASK
) | wxSUNKEN_BORDER
;
457 if ( !wxTextCtrlBase::Create(parent
, id
, pos
, size
, style
& ~(wxHSCROLL
|wxVSCROLL
), validator
, name
) )
460 if ( m_windowStyle
& wxTE_MULTILINE
)
463 !(m_windowStyle
& wxTE_PROCESS_ENTER
),
464 wxT("wxTE_PROCESS_ENTER style is ignored for multiline text controls (they always process it)") );
466 m_windowStyle
|= wxTE_PROCESS_ENTER
;
467 style
|= wxTE_PROCESS_ENTER
;
470 bool forceMLTE
= false ;
472 #if wxUSE_SYSTEM_OPTIONS
473 if ( wxSystemOptions::HasOption( wxMAC_TEXTCONTROL_USE_MLTE
) && ( wxSystemOptions::GetOptionInt( wxMAC_TEXTCONTROL_USE_MLTE
) == 1) )
480 #if MAC_OS_X_VERSION_MAX_ALLOWED > MAC_OS_X_VERSION_10_2
481 if ( UMAGetSystemVersion() >= 0x1030 && !forceMLTE
)
483 if ( m_windowStyle
& wxTE_MULTILINE
)
484 m_peer
= new wxMacMLTEHIViewControl( this , str
, pos
, size
, style
) ;
490 if ( !(m_windowStyle
& wxTE_MULTILINE
) && !forceMLTE
)
491 m_peer
= new wxMacUnicodeTextControl( this , str
, pos
, size
, style
) ;
496 m_peer
= new wxMacMLTEClassicControl( this , str
, pos
, size
, style
) ;
498 MacPostControlCreate(pos
, size
) ;
500 // only now the embedding is correct and we can do a positioning update
502 MacSuperChangedPosition() ;
504 if ( m_windowStyle
& wxTE_READONLY
)
505 SetEditable( false ) ;
507 SetCursor( wxCursor( wxCURSOR_IBEAM
) ) ;
512 void wxTextCtrl::MacSuperChangedPosition()
514 wxWindow::MacSuperChangedPosition() ;
515 GetPeer()->SuperChangedPosition() ;
518 void wxTextCtrl::MacVisibilityChanged()
520 GetPeer()->VisibilityChanged( MacIsReallyShown() ) ;
523 void wxTextCtrl::MacEnabledStateChanged()
527 wxString
wxTextCtrl::GetValue() const
529 return GetPeer()->GetStringValue() ;
532 void wxTextCtrl::GetSelection(long* from
, long* to
) const
534 GetPeer()->GetSelection( from
, to
) ;
537 void wxTextCtrl::SetValue(const wxString
& str
)
540 if ( GetValue() == str
)
543 GetPeer()->SetStringValue( str
) ;
545 wxCommandEvent
event( wxEVT_COMMAND_TEXT_UPDATED
, m_windowId
);
546 event
.SetString( GetValue() );
547 event
.SetEventObject( this );
548 GetEventHandler()->ProcessEvent( event
);
551 void wxTextCtrl::SetMaxLength(unsigned long len
)
556 bool wxTextCtrl::SetFont( const wxFont
& font
)
558 if ( !wxTextCtrlBase::SetFont( font
) )
561 GetPeer()->SetFont( font
, GetForegroundColour() , GetWindowStyle() ) ;
566 bool wxTextCtrl::SetStyle(long start
, long end
, const wxTextAttr
& style
)
568 GetPeer()->SetStyle( start
, end
, style
) ;
573 bool wxTextCtrl::SetDefaultStyle(const wxTextAttr
& style
)
575 wxTextCtrlBase::SetDefaultStyle( style
) ;
576 SetStyle( kTXNUseCurrentSelection
, kTXNUseCurrentSelection
, GetDefaultStyle() ) ;
581 // Clipboard operations
583 void wxTextCtrl::Copy()
589 void wxTextCtrl::Cut()
595 wxCommandEvent
event( wxEVT_COMMAND_TEXT_UPDATED
, m_windowId
);
596 event
.SetEventObject( this );
597 GetEventHandler()->ProcessEvent( event
);
601 void wxTextCtrl::Paste()
607 // TODO: eventually we should add setting the default style again
609 wxCommandEvent
event( wxEVT_COMMAND_TEXT_UPDATED
, m_windowId
);
610 event
.SetEventObject( this );
611 GetEventHandler()->ProcessEvent( event
);
615 bool wxTextCtrl::CanCopy() const
617 // Can copy if there's a selection
619 GetSelection( &from
, &to
);
623 bool wxTextCtrl::CanCut() const
628 // Can cut if there's a selection
630 GetSelection( &from
, &to
);
634 bool wxTextCtrl::CanPaste() const
639 return GetPeer()->CanPaste() ;
642 void wxTextCtrl::SetEditable(bool editable
)
644 if ( editable
!= m_editable
)
646 m_editable
= editable
;
647 GetPeer()->SetEditable( editable
) ;
651 void wxTextCtrl::SetInsertionPoint(long pos
)
653 SetSelection( pos
, pos
) ;
656 void wxTextCtrl::SetInsertionPointEnd()
658 wxTextPos pos
= GetLastPosition();
659 SetInsertionPoint(pos
);
662 long wxTextCtrl::GetInsertionPoint() const
665 GetSelection( &begin
, &end
) ;
669 wxTextPos
wxTextCtrl::GetLastPosition() const
671 return GetPeer()->GetLastPosition() ;
674 void wxTextCtrl::Replace(long from
, long to
, const wxString
& str
)
676 GetPeer()->Replace( from
, to
, str
) ;
679 void wxTextCtrl::Remove(long from
, long to
)
681 GetPeer()->Remove( from
, to
) ;
684 void wxTextCtrl::SetSelection(long from
, long to
)
686 GetPeer()->SetSelection( from
, to
) ;
689 bool wxTextCtrl::LoadFile(const wxString
& file
)
691 if ( wxTextCtrlBase::LoadFile(file
) )
697 void wxTextCtrl::WriteText(const wxString
& str
)
699 // TODO: this MPRemoting will be moved into a remoting peer proxy for any command
700 if ( !wxIsMainThread() )
702 // unfortunately CW 8 is not able to correctly deduce the template types,
703 // so we have to instantiate explicitly
704 wxMacMPRemoteGUICall
<wxTextCtrl
,wxString
>( this , &wxTextCtrl::WriteText
, str
) ;
709 GetPeer()->WriteText( str
) ;
713 void wxTextCtrl::AppendText(const wxString
& text
)
715 SetInsertionPointEnd();
719 void wxTextCtrl::Clear()
724 bool wxTextCtrl::IsModified() const
729 bool wxTextCtrl::IsEditable() const
731 return IsEnabled() && m_editable
;
734 bool wxTextCtrl::AcceptsFocus() const
736 // we don't want focus if we can't be edited
737 return /*IsEditable() && */ wxControl::AcceptsFocus();
740 wxSize
wxTextCtrl::DoGetBestSize() const
744 // these are the numbers from the HIG:
745 // we reduce them by the borders first
748 switch ( m_windowVariant
)
750 case wxWINDOW_VARIANT_NORMAL
:
754 case wxWINDOW_VARIANT_SMALL
:
758 case wxWINDOW_VARIANT_MINI
:
767 // as the above numbers have some free space around the text
768 // we get 5 lines like this anyway
769 if ( m_windowStyle
& wxTE_MULTILINE
)
772 if ( !HasFlag(wxNO_BORDER
) )
775 return wxSize(wText
, hText
);
778 // ----------------------------------------------------------------------------
780 // ----------------------------------------------------------------------------
782 void wxTextCtrl::Undo()
788 void wxTextCtrl::Redo()
794 bool wxTextCtrl::CanUndo() const
799 return GetPeer()->CanUndo() ;
802 bool wxTextCtrl::CanRedo() const
807 return GetPeer()->CanRedo() ;
810 void wxTextCtrl::MarkDirty()
815 void wxTextCtrl::DiscardEdits()
820 int wxTextCtrl::GetNumberOfLines() const
822 return GetPeer()->GetNumberOfLines() ;
825 long wxTextCtrl::XYToPosition(long x
, long y
) const
827 return GetPeer()->XYToPosition( x
, y
) ;
830 bool wxTextCtrl::PositionToXY(long pos
, long *x
, long *y
) const
832 return GetPeer()->PositionToXY(pos
, x
, y
) ;
835 void wxTextCtrl::ShowPosition(long pos
)
837 return GetPeer()->ShowPosition(pos
) ;
840 int wxTextCtrl::GetLineLength(long lineNo
) const
842 return GetPeer()->GetLineLength(lineNo
) ;
845 wxString
wxTextCtrl::GetLineText(long lineNo
) const
847 return GetPeer()->GetLineText(lineNo
) ;
850 void wxTextCtrl::Command(wxCommandEvent
& event
)
852 SetValue(event
.GetString());
853 ProcessCommand(event
);
856 void wxTextCtrl::OnDropFiles(wxDropFilesEvent
& event
)
858 // By default, load the first file into the text window.
859 if (event
.GetNumberOfFiles() > 0)
860 LoadFile(event
.GetFiles()[0]);
863 void wxTextCtrl::OnEraseBackground(wxEraseEvent
& event
)
865 // all erasing should be done by the real mac control implementation
866 // while this is true for MLTE under classic, the HITextView is somehow
867 // transparent but background erase is not working correctly, so intercept
868 // things while we can...
872 void wxTextCtrl::OnChar(wxKeyEvent
& event
)
874 int key
= event
.GetKeyCode() ;
875 bool eat_key
= false ;
877 if ( key
== 'c' && event
.MetaDown() )
885 if ( !IsEditable() && key
!= WXK_LEFT
&& key
!= WXK_RIGHT
&& key
!= WXK_DOWN
&& key
!= WXK_UP
&& key
!= WXK_TAB
&&
886 !( key
== WXK_RETURN
&& ( (m_windowStyle
& wxPROCESS_ENTER
) || (m_windowStyle
& wxTE_MULTILINE
) ) )
887 // && key != WXK_PRIOR && key != WXK_NEXT && key != WXK_HOME && key != WXK_END
894 // Check if we have reached the max # of chars, but still allow navigation and deletion
895 if ( !IsMultiLine() && GetValue().Length() >= m_maxLength
&&
896 key
!= WXK_LEFT
&& key
!= WXK_RIGHT
&& key
!= WXK_TAB
&&
897 key
!= WXK_BACK
&& !( key
== WXK_RETURN
&& (m_windowStyle
& wxPROCESS_ENTER
) )
900 // eat it, we don't want to add more than allowed # of characters
904 // assume that any key not processed yet is going to modify the control
907 if ( key
== 'v' && event
.MetaDown() )
915 if ( key
== 'x' && event
.MetaDown() )
926 if (m_windowStyle
& wxPROCESS_ENTER
)
928 wxCommandEvent
event(wxEVT_COMMAND_TEXT_ENTER
, m_windowId
);
929 event
.SetEventObject( this );
930 event
.SetString( GetValue() );
931 if ( GetEventHandler()->ProcessEvent(event
) )
935 if ( !(m_windowStyle
& wxTE_MULTILINE
) )
937 wxWindow
*parent
= GetParent();
938 while ( parent
&& !parent
->IsTopLevel() && parent
->GetDefaultItem() == NULL
)
940 parent
= parent
->GetParent() ;
943 if ( parent
&& parent
->GetDefaultItem() )
945 wxButton
*def
= wxDynamicCast(parent
->GetDefaultItem(), wxButton
);
946 if ( def
&& def
->IsEnabled() )
948 wxCommandEvent
event(wxEVT_COMMAND_BUTTON_CLICKED
, def
->GetId() );
949 event
.SetEventObject(def
);
956 // this will make wxWidgets eat the ENTER key so that
957 // we actually prevent line wrapping in a single line text control
963 if ( !(m_windowStyle
& wxTE_PROCESS_TAB
))
966 if (!event
.ShiftDown())
967 flags
|= wxNavigationKeyEvent::IsForward
;
968 if (event
.ControlDown())
969 flags
|= wxNavigationKeyEvent::WinChange
;
976 // This is necessary (don't know why);
977 // otherwise the tab will not be inserted.
978 WriteText(wxT("\t"));
988 // perform keystroke handling
989 if ( wxTheApp
->MacGetCurrentEvent() != NULL
&& wxTheApp
->MacGetCurrentEventHandlerCallRef() != NULL
)
991 CallNextEventHandler( (EventHandlerCallRef
)wxTheApp
->MacGetCurrentEventHandlerCallRef(), (EventRef
)wxTheApp
->MacGetCurrentEvent() ) ;
996 if ( wxMacConvertEventToRecord( (EventRef
) wxTheApp
->MacGetCurrentEvent() , &rec
) )
998 short keycode
, keychar
;
999 EventRecord
*ev
= &rec
;
1000 keychar
= short(ev
->message
& charCodeMask
);
1001 keycode
= short(ev
->message
& keyCodeMask
) >> 8 ;
1003 m_peer
->HandleKey( keycode
, keychar
, ev
->modifiers
) ;
1008 if ( ( key
>= 0x20 && key
< WXK_START
) ||
1009 key
== WXK_RETURN
||
1010 key
== WXK_DELETE
||
1013 wxCommandEvent
event1(wxEVT_COMMAND_TEXT_UPDATED
, m_windowId
);
1014 event1
.SetEventObject( this );
1015 wxPostEvent( GetEventHandler(), event1
);
1019 // ----------------------------------------------------------------------------
1020 // standard handlers for standard edit menu events
1021 // ----------------------------------------------------------------------------
1023 void wxTextCtrl::OnCut(wxCommandEvent
& WXUNUSED(event
))
1028 void wxTextCtrl::OnCopy(wxCommandEvent
& WXUNUSED(event
))
1033 void wxTextCtrl::OnPaste(wxCommandEvent
& WXUNUSED(event
))
1038 void wxTextCtrl::OnUndo(wxCommandEvent
& WXUNUSED(event
))
1043 void wxTextCtrl::OnRedo(wxCommandEvent
& WXUNUSED(event
))
1048 void wxTextCtrl::OnDelete(wxCommandEvent
& WXUNUSED(event
))
1051 GetSelection( &from
, &to
);
1052 if (from
!= -1 && to
!= -1)
1056 void wxTextCtrl::OnSelectAll(wxCommandEvent
& WXUNUSED(event
))
1058 SetSelection(-1, -1);
1061 void wxTextCtrl::OnUpdateCut(wxUpdateUIEvent
& event
)
1063 event
.Enable( CanCut() );
1066 void wxTextCtrl::OnUpdateCopy(wxUpdateUIEvent
& event
)
1068 event
.Enable( CanCopy() );
1071 void wxTextCtrl::OnUpdatePaste(wxUpdateUIEvent
& event
)
1073 event
.Enable( CanPaste() );
1076 void wxTextCtrl::OnUpdateUndo(wxUpdateUIEvent
& event
)
1078 event
.Enable( CanUndo() );
1081 void wxTextCtrl::OnUpdateRedo(wxUpdateUIEvent
& event
)
1083 event
.Enable( CanRedo() );
1086 void wxTextCtrl::OnUpdateDelete(wxUpdateUIEvent
& event
)
1089 GetSelection( &from
, &to
);
1090 event
.Enable( from
!= -1 && to
!= -1 && from
!= to
&& IsEditable() ) ;
1093 void wxTextCtrl::OnUpdateSelectAll(wxUpdateUIEvent
& event
)
1095 event
.Enable(GetLastPosition() > 0);
1098 // CS: Context Menus only work with MLTE implementations or non-multiline HIViews at the moment
1100 void wxTextCtrl::OnContextMenu(wxContextMenuEvent
& event
)
1102 if ( GetPeer()->HasOwnContextMenu() )
1108 if (m_privateContextMenu
== NULL
)
1110 m_privateContextMenu
= new wxMenu
;
1111 m_privateContextMenu
->Append(wxID_UNDO
, _("&Undo"));
1112 m_privateContextMenu
->Append(wxID_REDO
, _("&Redo"));
1113 m_privateContextMenu
->AppendSeparator();
1114 m_privateContextMenu
->Append(wxID_CUT
, _("Cu&t"));
1115 m_privateContextMenu
->Append(wxID_COPY
, _("&Copy"));
1116 m_privateContextMenu
->Append(wxID_PASTE
, _("&Paste"));
1117 m_privateContextMenu
->Append(wxID_CLEAR
, _("&Delete"));
1118 m_privateContextMenu
->AppendSeparator();
1119 m_privateContextMenu
->Append(wxID_SELECTALL
, _("Select &All"));
1122 if (m_privateContextMenu
!= NULL
)
1123 PopupMenu(m_privateContextMenu
);
1126 bool wxTextCtrl::MacSetupCursor( const wxPoint
& pt
)
1128 if ( !GetPeer()->SetupCursor( pt
) )
1129 return wxWindow::MacSetupCursor( pt
) ;
1134 #if !TARGET_API_MAC_OSX
1136 // user pane implementation
1138 void wxTextCtrl::MacControlUserPaneDrawProc(wxInt16 part
)
1140 GetPeer()->MacControlUserPaneDrawProc( part
) ;
1143 wxInt16
wxTextCtrl::MacControlUserPaneHitTestProc(wxInt16 x
, wxInt16 y
)
1145 return GetPeer()->MacControlUserPaneHitTestProc( x
, y
) ;
1148 wxInt16
wxTextCtrl::MacControlUserPaneTrackingProc(wxInt16 x
, wxInt16 y
, void* actionProc
)
1150 return GetPeer()->MacControlUserPaneTrackingProc( x
, y
, actionProc
) ;
1153 void wxTextCtrl::MacControlUserPaneIdleProc()
1155 GetPeer()->MacControlUserPaneIdleProc( ) ;
1158 wxInt16
wxTextCtrl::MacControlUserPaneKeyDownProc(wxInt16 keyCode
, wxInt16 charCode
, wxInt16 modifiers
)
1160 return GetPeer()->MacControlUserPaneKeyDownProc( keyCode
, charCode
, modifiers
) ;
1163 void wxTextCtrl::MacControlUserPaneActivateProc(bool activating
)
1165 GetPeer()->MacControlUserPaneActivateProc( activating
) ;
1168 wxInt16
wxTextCtrl::MacControlUserPaneFocusProc(wxInt16 action
)
1170 return GetPeer()->MacControlUserPaneFocusProc( action
) ;
1173 void wxTextCtrl::MacControlUserPaneBackgroundProc(void* info
)
1175 GetPeer()->MacControlUserPaneBackgroundProc( info
) ;
1180 // ----------------------------------------------------------------------------
1181 // implementation base class
1182 // ----------------------------------------------------------------------------
1184 wxMacTextControl::wxMacTextControl(wxTextCtrl
* peer
) :
1185 wxMacControl( peer
)
1189 wxMacTextControl::~wxMacTextControl()
1193 void wxMacTextControl::SetStyle(long start
, long end
, const wxTextAttr
& style
)
1197 void wxMacTextControl::Copy()
1201 void wxMacTextControl::Cut()
1205 void wxMacTextControl::Paste()
1209 bool wxMacTextControl::CanPaste() const
1214 void wxMacTextControl::SetEditable(bool editable
)
1218 wxTextPos
wxMacTextControl::GetLastPosition() const
1220 return GetStringValue().Length() ;
1223 void wxMacTextControl::Replace( long from
, long to
, const wxString
&val
)
1225 SetSelection( from
, to
) ;
1229 void wxMacTextControl::Remove( long from
, long to
)
1231 SetSelection( from
, to
) ;
1232 WriteText( wxEmptyString
) ;
1235 void wxMacTextControl::Clear()
1237 SetStringValue( wxEmptyString
) ;
1240 bool wxMacTextControl::CanUndo() const
1245 void wxMacTextControl::Undo()
1249 bool wxMacTextControl::CanRedo() const
1254 void wxMacTextControl::Redo()
1258 long wxMacTextControl::XYToPosition(long x
, long y
) const
1263 bool wxMacTextControl::PositionToXY(long pos
, long *x
, long *y
) const
1268 void wxMacTextControl::ShowPosition( long WXUNUSED(pos
) )
1272 int wxMacTextControl::GetNumberOfLines() const
1274 ItemCount lines
= 0 ;
1275 wxString content
= GetStringValue() ;
1278 for (size_t i
= 0; i
< content
.Length() ; i
++)
1280 if (content
[i
] == '\r')
1287 wxString
wxMacTextControl::GetLineText(long lineNo
) const
1289 // TODO: change this if possible to reflect real lines
1290 wxString content
= GetStringValue() ;
1294 for (size_t i
= 0; i
< content
.Length() ; i
++)
1296 if (count
== lineNo
)
1298 // Add chars in line then
1301 for (size_t j
= i
; j
< content
.Length(); j
++)
1303 if (content
[j
] == '\n')
1312 if (content
[i
] == '\n')
1316 return wxEmptyString
;
1319 int wxMacTextControl::GetLineLength(long lineNo
) const
1321 // TODO: change this if possible to reflect real lines
1322 wxString content
= GetStringValue() ;
1326 for (size_t i
= 0; i
< content
.Length() ; i
++)
1328 if (count
== lineNo
)
1330 // Count chars in line then
1332 for (size_t j
= i
; j
< content
.Length(); j
++)
1335 if (content
[j
] == '\n')
1342 if (content
[i
] == '\n')
1349 // ----------------------------------------------------------------------------
1350 // standard unicode control implementation
1351 // ----------------------------------------------------------------------------
1353 #if TARGET_API_MAC_OSX
1355 wxMacUnicodeTextControl::wxMacUnicodeTextControl( wxTextCtrl
*wxPeer
,
1356 const wxString
& str
,
1358 const wxSize
& size
, long style
) : wxMacTextControl( wxPeer
)
1360 m_font
= wxPeer
->GetFont() ;
1361 m_windowStyle
= style
;
1362 Rect bounds
= wxMacGetBoundsForControl( wxPeer
, pos
, size
) ;
1364 wxMacConvertNewlines10To13( &st
) ;
1365 wxMacCFStringHolder
cf(st
, m_font
.GetEncoding()) ;
1366 CFStringRef cfr
= cf
;
1367 Boolean isPassword
= ( m_windowStyle
& wxTE_PASSWORD
) != 0 ;
1368 m_valueTag
= isPassword
? kControlEditTextPasswordCFStringTag
: kControlEditTextCFStringTag
;
1369 CreateEditUnicodeTextControl(
1370 MAC_WXHWND(wxPeer
->MacGetTopLevelWindowRef()), &bounds
, cfr
,
1371 isPassword
, NULL
, &m_controlRef
) ;
1373 if ( !(m_windowStyle
& wxTE_MULTILINE
) )
1374 SetData
<Boolean
>( kControlEditTextPart
, kControlEditTextSingleLineTag
, true ) ;
1377 wxMacUnicodeTextControl::~wxMacUnicodeTextControl()
1381 void wxMacUnicodeTextControl::VisibilityChanged(bool shown
)
1383 if ( !(m_windowStyle
& wxTE_MULTILINE
) && shown
)
1385 // work around a refresh issue insofar as not always the entire content is shown,
1386 // even if this would be possible
1387 ControlEditTextSelectionRec sel
;
1388 CFStringRef value
= NULL
;
1390 verify_noerr( GetData
<ControlEditTextSelectionRec
>( 0, kControlEditTextSelectionTag
, &sel
) );
1391 verify_noerr( GetData
<CFStringRef
>( 0, m_valueTag
, &value
) );
1392 verify_noerr( SetData
<CFStringRef
>( 0, m_valueTag
, &value
) );
1393 verify_noerr( SetData
<ControlEditTextSelectionRec
>( 0, kControlEditTextSelectionTag
, &sel
) );
1395 CFRelease( value
) ;
1399 wxString
wxMacUnicodeTextControl::GetStringValue() const
1402 CFStringRef value
= GetData
<CFStringRef
>(0, m_valueTag
) ;
1405 wxMacCFStringHolder
cf(value
) ;
1406 result
= cf
.AsString() ;
1410 wxMacConvertNewlines13To10( &result
) ;
1412 wxMacConvertNewlines10To13( &result
) ;
1418 void wxMacUnicodeTextControl::SetStringValue( const wxString
&str
)
1421 wxMacConvertNewlines10To13( &st
) ;
1422 wxMacCFStringHolder
cf(st
, m_font
.GetEncoding() ) ;
1423 verify_noerr( SetData
<CFStringRef
>( 0, m_valueTag
, cf
) ) ;
1426 void wxMacUnicodeTextControl::Copy()
1428 SendHICommand( kHICommandCopy
) ;
1431 void wxMacUnicodeTextControl::Cut()
1433 SendHICommand( kHICommandCut
) ;
1436 void wxMacUnicodeTextControl::Paste()
1438 SendHICommand( kHICommandPaste
) ;
1441 bool wxMacUnicodeTextControl::CanPaste() const
1446 void wxMacUnicodeTextControl::SetEditable(bool editable
)
1448 SetData
<Boolean
>( 0 , kControlEditTextLockedTag
, (Boolean
) !editable
) ;
1451 void wxMacUnicodeTextControl::GetSelection( long* from
, long* to
) const
1453 ControlEditTextSelectionRec sel
;
1454 verify_noerr( GetData
<ControlEditTextSelectionRec
>( 0, kControlEditTextSelectionTag
, &sel
) ) ;
1456 *from
= sel
.selStart
;
1461 void wxMacUnicodeTextControl::SetSelection( long from
, long to
)
1463 ControlEditTextSelectionRec sel
;
1464 if ((from
== -1) && (to
== -1))
1467 to
= 32767 ; // sel has 16 bit signed values, max is 32767
1470 sel
.selStart
= from
;
1472 SetData
<ControlEditTextSelectionRec
>( 0, kControlEditTextSelectionTag
, &sel
) ;
1475 void wxMacUnicodeTextControl::WriteText( const wxString
& str
)
1478 wxMacConvertNewlines10To13( &st
) ;
1480 #if MAC_OS_X_VERSION_MAX_ALLOWED > MAC_OS_X_VERSION_10_2
1481 wxMacCFStringHolder
cf(st
, m_font
.GetEncoding() ) ;
1482 CFStringRef value
= cf
;
1483 SetData
<CFStringRef
>( 0, kControlEditTextInsertCFStringRefTag
, &value
);
1485 wxString val
= GetStringValue() ;
1487 GetSelection( &start
, &end
) ;
1488 val
.Remove( start
, end
- start
) ;
1489 val
.insert( start
, str
) ;
1490 SetStringValue( val
) ;
1491 SetSelection( start
+ str
.Length() , start
+ str
.Length() ) ;
1497 // ----------------------------------------------------------------------------
1498 // MLTE control implementation (common part)
1499 // ----------------------------------------------------------------------------
1501 // if MTLE is read only, no changes at all are allowed, not even from
1502 // procedural API, in order to allow changes via API all the same we must undo
1503 // the readonly status while we are executing, this class helps to do so
1505 class wxMacEditHelper
1508 wxMacEditHelper( TXNObject txn
)
1510 TXNControlTag tag
[] = { kTXNIOPrivilegesTag
} ;
1512 TXNGetTXNObjectControls( m_txn
, 1 , tag
, m_data
) ;
1513 if ( m_data
[0].uValue
== kTXNReadOnly
)
1515 TXNControlData data
[] = { { kTXNReadWrite
} } ;
1516 TXNSetTXNObjectControls( m_txn
, false , 1 , tag
, data
) ;
1522 TXNControlTag tag
[] = { kTXNIOPrivilegesTag
} ;
1523 if ( m_data
[0].uValue
== kTXNReadOnly
)
1524 TXNSetTXNObjectControls( m_txn
, false , 1 , tag
, m_data
) ;
1529 TXNControlData m_data
[1] ;
1532 wxMacMLTEControl::wxMacMLTEControl( wxTextCtrl
*peer
) : wxMacTextControl( peer
)
1534 SetNeedsFocusRect( true ) ;
1537 wxString
wxMacMLTEControl::GetStringValue() const
1541 Size actualSize
= 0;
1546 err
= TXNGetDataEncoded( m_txn
, kTXNStartOffset
, kTXNEndOffset
, &theText
, kTXNUnicodeTextData
);
1555 actualSize
= GetHandleSize( theText
) / sizeof(UniChar
) ;
1556 if ( actualSize
> 0 )
1558 wxChar
*ptr
= NULL
;
1560 #if SIZEOF_WCHAR_T == 2
1561 ptr
= new wxChar
[actualSize
+ 1] ;
1562 wxStrncpy( ptr
, (wxChar
*)(*theText
) , actualSize
) ;
1564 SetHandleSize( theText
, (actualSize
+ 1) * sizeof(UniChar
) ) ;
1566 (((UniChar
*)*theText
)[actualSize
]) = 0 ;
1567 wxMBConvUTF16 converter
;
1568 size_t noChars
= converter
.MB2WC( NULL
, (const char*)*theText
, 0 ) ;
1569 ptr
= new wxChar
[noChars
+ 1] ;
1571 noChars
= converter
.MB2WC( ptr
, (const char*)*theText
, noChars
) ;
1573 HUnlock( theText
) ;
1576 ptr
[actualSize
] = 0 ;
1577 result
= wxString( ptr
) ;
1581 DisposeHandle( theText
) ;
1585 err
= TXNGetDataEncoded( m_txn
, kTXNStartOffset
, kTXNEndOffset
, &theText
, kTXNTextData
);
1594 actualSize
= GetHandleSize( theText
) ;
1595 if ( actualSize
> 0 )
1598 result
= wxString( *theText
, wxConvLocal
, actualSize
) ;
1599 HUnlock( theText
) ;
1602 DisposeHandle( theText
) ;
1608 wxMacConvertNewlines13To10( &result
) ;
1610 wxMacConvertNewlines10To13( &result
) ;
1616 void wxMacMLTEControl::SetStringValue( const wxString
&str
)
1619 wxMacConvertNewlines10To13( &st
);
1622 wxMacWindowClipper
c( m_peer
);
1625 wxMacEditHelper
help( m_txn
);
1626 SetTXNData( st
, kTXNStartOffset
, kTXNEndOffset
);
1629 TXNSetSelection( m_txn
, 0, 0 );
1630 TXNShowSelection( m_txn
, kTXNShowStart
);
1634 TXNFrameOptions
wxMacMLTEControl::FrameOptionsFromWXStyle( long wxStyle
)
1636 TXNFrameOptions frameOptions
= kTXNDontDrawCaretWhenInactiveMask
;
1638 #if MAC_OS_X_VERSION_MAX_ALLOWED >= MAC_OS_X_VERSION_10_3
1639 frameOptions
|= kTXNDoFontSubstitutionMask
;
1642 if ( ! (wxStyle
& wxTE_NOHIDESEL
) )
1643 frameOptions
|= kTXNDontDrawSelectionWhenInactiveMask
;
1645 if ( wxStyle
& (wxHSCROLL
| wxTE_DONTWRAP
) )
1646 frameOptions
|= kTXNWantHScrollBarMask
;
1648 if ( wxStyle
& wxTE_MULTILINE
)
1650 frameOptions
|= kTXNAlwaysWrapAtViewEdgeMask
;
1652 if ( !(wxStyle
& wxTE_NO_VSCROLL
) )
1654 frameOptions
|= kTXNWantVScrollBarMask
;
1656 // The following code causes drawing problems on 10.4. Perhaps it can be restored for
1657 // older versions of the OS, but I'm not sure it's appropriate to put a grow icon here
1658 // anyways, as AFAIK users can't actually use it to resize the text ctrl.
1659 // if ( frameOptions & kTXNWantHScrollBarMask )
1660 // frameOptions |= kTXNDrawGrowIconMask ;
1665 frameOptions
|= kTXNSingleLineOnlyMask
;
1668 return frameOptions
;
1671 void wxMacMLTEControl::AdjustCreationAttributes( const wxColour
&background
, bool visible
)
1673 TXNControlTag iControlTags
[] =
1675 kTXNDoFontSubstitution
,
1676 kTXNWordWrapStateTag
,
1678 TXNControlData iControlData
[] =
1684 int toptag
= WXSIZEOF( iControlTags
) ;
1686 if ( m_windowStyle
& wxTE_MULTILINE
)
1688 iControlData
[1].uValue
=
1689 (m_windowStyle
& wxTE_DONTWRAP
)
1694 verify_noerr( TXNSetTXNObjectControls( m_txn
, false, toptag
, iControlTags
, iControlData
) ) ;
1696 // setting the default font:
1697 // under 10.2 this causes a visible caret, therefore we avoid it
1699 if ( UMAGetSystemVersion() >= 0x1030 )
1705 GetThemeFont(kThemeSystemFont
, GetApplicationScript() , fontName
, &fontSize
, &fontStyle
) ;
1707 TXNTypeAttributes typeAttr
[] =
1709 { kTXNQDFontNameAttribute
, kTXNQDFontNameAttributeSize
, { (void*) fontName
} } ,
1710 { kTXNQDFontSizeAttribute
, kTXNFontSizeAttributeSize
, { (void*) (fontSize
<< 16) } } ,
1711 { kTXNQDFontStyleAttribute
, kTXNQDFontStyleAttributeSize
, { (void*) normal
} } ,
1715 TXNSetTypeAttributes(
1716 m_txn
, sizeof(typeAttr
) / sizeof(TXNTypeAttributes
),
1717 typeAttr
, kTXNStartOffset
, kTXNEndOffset
) );
1720 if ( m_windowStyle
& wxTE_PASSWORD
)
1723 verify_noerr (TXNEchoMode( m_txn
, c
, 0 , true ) );
1726 TXNBackground tback
;
1727 tback
.bgType
= kTXNBackgroundTypeRGB
;
1728 tback
.bg
.color
= MAC_WXCOLORREF( background
.GetPixel() );
1729 TXNSetBackground( m_txn
, &tback
);
1731 #if MAC_OS_X_VERSION_MAX_ALLOWED >= MAC_OS_X_VERSION_10_4
1732 if ( UMAGetSystemVersion() >= 0x1040 )
1734 TXNCommandEventSupportOptions options
;
1735 if ( TXNGetCommandEventSupport( m_txn
, &options
) == noErr
)
1738 kTXNSupportEditCommandProcessing
1739 | kTXNSupportEditCommandUpdating
1740 | kTXNSupportSpellCheckCommandProcessing
1741 | kTXNSupportSpellCheckCommandUpdating
1742 | kTXNSupportFontCommandProcessing
1743 | kTXNSupportFontCommandUpdating
;
1745 TXNSetCommandEventSupport( m_txn
, options
) ;
1751 void wxMacMLTEControl::SetBackground( const wxBrush
&brush
)
1753 // currently only solid background are supported
1754 TXNBackground tback
;
1756 tback
.bgType
= kTXNBackgroundTypeRGB
;
1757 tback
.bg
.color
= MAC_WXCOLORREF( brush
.GetColour().GetPixel() );
1758 TXNSetBackground( m_txn
, &tback
);
1761 void wxMacMLTEControl::TXNSetAttribute( const wxTextAttr
& style
, long from
, long to
)
1763 TXNTypeAttributes typeAttr
[4] ;
1764 Str255 fontName
= "\pMonaco" ;
1765 SInt16 fontSize
= 12 ;
1766 Style fontStyle
= normal
;
1770 if ( style
.HasFont() )
1772 const wxFont
&font
= style
.GetFont() ;
1773 wxMacStringToPascal( font
.GetFaceName() , fontName
) ;
1774 fontSize
= font
.GetPointSize() ;
1775 if ( font
.GetUnderlined() )
1776 fontStyle
|= underline
;
1777 if ( font
.GetWeight() == wxBOLD
)
1779 if ( font
.GetStyle() == wxITALIC
)
1780 fontStyle
|= italic
;
1782 typeAttr
[attrCount
].tag
= kTXNQDFontNameAttribute
;
1783 typeAttr
[attrCount
].size
= kTXNQDFontNameAttributeSize
;
1784 typeAttr
[attrCount
].data
.dataPtr
= (void*)fontName
;
1787 typeAttr
[attrCount
].tag
= kTXNQDFontSizeAttribute
;
1788 typeAttr
[attrCount
].size
= kTXNFontSizeAttributeSize
;
1789 typeAttr
[attrCount
].data
.dataValue
= (fontSize
<< 16) ;
1792 typeAttr
[attrCount
].tag
= kTXNQDFontStyleAttribute
;
1793 typeAttr
[attrCount
].size
= kTXNQDFontStyleAttributeSize
;
1794 typeAttr
[attrCount
].data
.dataValue
= fontStyle
;
1798 if ( style
.HasTextColour() )
1800 color
= MAC_WXCOLORREF(style
.GetTextColour().GetPixel()) ;
1802 typeAttr
[attrCount
].tag
= kTXNQDFontColorAttribute
;
1803 typeAttr
[attrCount
].size
= kTXNQDFontColorAttributeSize
;
1804 typeAttr
[attrCount
].data
.dataPtr
= (void*) &color
;
1808 if ( attrCount
> 0 )
1810 verify_noerr( TXNSetTypeAttributes( m_txn
, attrCount
, typeAttr
, from
, to
) );
1814 void wxMacMLTEControl::SetFont( const wxFont
& font
, const wxColour
& foreground
, long windowStyle
)
1816 wxMacEditHelper
help( m_txn
) ;
1817 TXNSetAttribute( wxTextAttr( foreground
, wxNullColour
, font
), kTXNStartOffset
, kTXNEndOffset
) ;
1820 void wxMacMLTEControl::SetStyle( long start
, long end
, const wxTextAttr
& style
)
1822 wxMacEditHelper
help( m_txn
) ;
1823 TXNSetAttribute( style
, start
, end
) ;
1826 void wxMacMLTEControl::Copy()
1828 ClearCurrentScrap();
1830 TXNConvertToPublicScrap();
1833 void wxMacMLTEControl::Cut()
1835 ClearCurrentScrap();
1837 TXNConvertToPublicScrap();
1840 void wxMacMLTEControl::Paste()
1842 TXNConvertFromPublicScrap();
1846 bool wxMacMLTEControl::CanPaste() const
1848 return TXNIsScrapPastable() ;
1851 void wxMacMLTEControl::SetEditable(bool editable
)
1853 TXNControlTag tag
[] = { kTXNIOPrivilegesTag
} ;
1854 TXNControlData data
[] = { { editable
? kTXNReadWrite
: kTXNReadOnly
} } ;
1855 TXNSetTXNObjectControls( m_txn
, false, WXSIZEOF(tag
), tag
, data
) ;
1858 wxTextPos
wxMacMLTEControl::GetLastPosition() const
1860 wxTextPos actualsize
= 0 ;
1863 OSErr err
= TXNGetDataEncoded( m_txn
, kTXNStartOffset
, kTXNEndOffset
, &theText
, kTXNTextData
);
1868 actualsize
= GetHandleSize( theText
) ;
1869 DisposeHandle( theText
) ;
1879 void wxMacMLTEControl::Replace( long from
, long to
, const wxString
&str
)
1881 wxString value
= str
;
1882 wxMacConvertNewlines10To13( &value
) ;
1884 wxMacEditHelper
help( m_txn
) ;
1885 wxMacWindowClipper
c( m_peer
) ;
1887 TXNSetSelection( m_txn
, from
, to
) ;
1889 SetTXNData( value
, kTXNUseCurrentSelection
, kTXNUseCurrentSelection
) ;
1892 void wxMacMLTEControl::Remove( long from
, long to
)
1894 wxMacWindowClipper
c( m_peer
) ;
1895 wxMacEditHelper
help( m_txn
) ;
1896 TXNSetSelection( m_txn
, from
, to
) ;
1900 void wxMacMLTEControl::GetSelection( long* from
, long* to
) const
1902 TXNGetSelection( m_txn
, (TXNOffset
*) from
, (TXNOffset
*) to
) ;
1905 void wxMacMLTEControl::SetSelection( long from
, long to
)
1907 wxMacWindowClipper
c( m_peer
) ;
1909 // change the selection
1910 if ((from
== -1) && (to
== -1))
1911 TXNSelectAll( m_txn
);
1913 TXNSetSelection( m_txn
, from
, to
);
1915 TXNShowSelection( m_txn
, kTXNShowStart
);
1918 void wxMacMLTEControl::WriteText( const wxString
& str
)
1921 wxMacConvertNewlines10To13( &st
) ;
1923 long start
, end
, dummy
;
1925 GetSelection( &start
, &dummy
) ;
1926 wxMacWindowClipper
c( m_peer
) ;
1929 wxMacEditHelper
helper( m_txn
) ;
1930 SetTXNData( st
, kTXNUseCurrentSelection
, kTXNUseCurrentSelection
) ;
1933 GetSelection( &dummy
, &end
) ;
1935 // TODO: SetStyle( start , end , GetDefaultStyle() ) ;
1938 void wxMacMLTEControl::Clear()
1940 wxMacWindowClipper
c( m_peer
) ;
1941 wxMacEditHelper
st( m_txn
) ;
1942 TXNSetSelection( m_txn
, kTXNStartOffset
, kTXNEndOffset
) ;
1946 bool wxMacMLTEControl::CanUndo() const
1948 return TXNCanUndo( m_txn
, NULL
) ;
1951 void wxMacMLTEControl::Undo()
1956 bool wxMacMLTEControl::CanRedo() const
1958 return TXNCanRedo( m_txn
, NULL
) ;
1961 void wxMacMLTEControl::Redo()
1966 int wxMacMLTEControl::GetNumberOfLines() const
1968 ItemCount lines
= 0 ;
1969 TXNGetLineCount( m_txn
, &lines
) ;
1974 long wxMacMLTEControl::XYToPosition(long x
, long y
) const
1979 // TODO: find a better implementation : while we can get the
1980 // line metrics of a certain line, we don't get its starting
1981 // position, so it would probably be rather a binary search
1982 // for the start position
1983 long xpos
= 0, ypos
= 0 ;
1984 int lastHeight
= 0 ;
1987 lastpos
= GetLastPosition() ;
1988 for ( n
= 0 ; n
<= (ItemCount
) lastpos
; ++n
)
1990 if ( y
== ypos
&& x
== xpos
)
1993 TXNOffsetToPoint( m_txn
, n
, &curpt
);
1995 if ( curpt
.v
> lastHeight
)
2001 lastHeight
= curpt
.v
;
2010 bool wxMacMLTEControl::PositionToXY( long pos
, long *x
, long *y
) const
2020 lastpos
= GetLastPosition() ;
2021 if ( pos
<= lastpos
)
2023 // TODO: find a better implementation - while we can get the
2024 // line metrics of a certain line, we don't get its starting
2025 // position, so it would probably be rather a binary search
2026 // for the start position
2027 long xpos
= 0, ypos
= 0 ;
2028 int lastHeight
= 0 ;
2031 for ( n
= 0 ; n
<= (ItemCount
) pos
; ++n
)
2033 TXNOffsetToPoint(m_txn
, n
, &curpt
);
2035 if ( curpt
.v
> lastHeight
)
2041 lastHeight
= curpt
.v
;
2056 void wxMacMLTEControl::ShowPosition( long pos
)
2058 #if TARGET_RT_MAC_MACHO && defined(AVAILABLE_MAC_OS_X_VERSION_10_2_AND_LATER)
2060 Point current
, desired
;
2061 TXNOffset selstart
, selend
;
2063 TXNGetSelection( m_txn
, &selstart
, &selend
);
2064 TXNOffsetToPoint( m_txn
, selstart
, ¤t
);
2065 TXNOffsetToPoint( m_txn
, pos
, &desired
);
2067 // TODO: use HIPoints for 10.3 and above
2068 if ( (UInt32
)TXNScroll
!= (UInt32
)kUnresolvedCFragSymbolAddress
)
2070 OSErr theErr
= noErr
;
2071 SInt32 dv
= desired
.v
- current
.v
;
2072 SInt32 dh
= desired
.h
- current
.h
;
2073 TXNShowSelection( m_txn
, kTXNShowEnd
); // NB: should this be kTXNShowStart or kTXNShowEnd ??
2074 theErr
= TXNScroll( m_txn
, kTXNScrollUnitsInPixels
, kTXNScrollUnitsInPixels
, &dv
, &dh
);
2076 // there will be an error returned for classic MLTE implementation when the control is
2077 // invisible, but HITextView works correctly, so we don't assert that one
2078 // wxASSERT_MSG( theErr == noErr, _T("TXNScroll returned an error!") );
2084 void wxMacMLTEControl::SetTXNData( const wxString
& st
, TXNOffset start
, TXNOffset end
)
2087 #if SIZEOF_WCHAR_T == 2
2088 size_t len
= st
.Len() ;
2089 TXNSetData( m_txn
, kTXNUnicodeTextData
, (void*)st
.wc_str(), len
* 2, start
, end
);
2091 wxMBConvUTF16 converter
;
2092 ByteCount byteBufferLen
= converter
.WC2MB( NULL
, st
.wc_str(), 0 ) ;
2093 UniChar
*unibuf
= (UniChar
*)malloc( byteBufferLen
) ;
2094 converter
.WC2MB( (char*)unibuf
, st
.wc_str(), byteBufferLen
) ;
2095 TXNSetData( m_txn
, kTXNUnicodeTextData
, (void*)unibuf
, byteBufferLen
, start
, end
) ;
2099 wxCharBuffer text
= st
.mb_str( wxConvLocal
) ;
2100 TXNSetData( m_txn
, kTXNTextData
, (void*)text
.data(), strlen( text
), start
, end
) ;
2104 wxString
wxMacMLTEControl::GetLineText(long lineNo
) const
2108 if ( lineNo
< GetNumberOfLines() )
2111 Fixed lineWidth
, lineHeight
, currentHeight
;
2114 // get the first possible position in the control
2115 TXNOffsetToPoint(m_txn
, 0, &firstPoint
);
2117 // Iterate through the lines until we reach the one we want,
2118 // adding to our current y pixel point position
2121 while (ypos
< lineNo
)
2123 TXNGetLineMetrics(m_txn
, ypos
++, &lineWidth
, &lineHeight
);
2124 currentHeight
+= lineHeight
;
2127 Point thePoint
= { firstPoint
.v
+ (currentHeight
>> 16), firstPoint
.h
+ (0) };
2128 TXNOffset theOffset
;
2129 TXNPointToOffset(m_txn
, thePoint
, &theOffset
);
2131 wxString content
= GetStringValue() ;
2132 Point currentPoint
= thePoint
;
2133 while (thePoint
.v
== currentPoint
.v
&& theOffset
< content
.length())
2135 line
+= content
[theOffset
];
2136 TXNOffsetToPoint(m_txn
, ++theOffset
, ¤tPoint
);
2143 int wxMacMLTEControl::GetLineLength(long lineNo
) const
2147 if ( lineNo
< GetNumberOfLines() )
2150 Fixed lineWidth
, lineHeight
, currentHeight
;
2153 // get the first possible position in the control
2154 TXNOffsetToPoint(m_txn
, 0, &firstPoint
);
2156 // Iterate through the lines until we reach the one we want,
2157 // adding to our current y pixel point position
2160 while (ypos
< lineNo
)
2162 TXNGetLineMetrics(m_txn
, ypos
++, &lineWidth
, &lineHeight
);
2163 currentHeight
+= lineHeight
;
2166 Point thePoint
= { firstPoint
.v
+ (currentHeight
>> 16), firstPoint
.h
+ (0) };
2167 TXNOffset theOffset
;
2168 TXNPointToOffset(m_txn
, thePoint
, &theOffset
);
2170 wxString content
= GetStringValue() ;
2171 Point currentPoint
= thePoint
;
2172 while (thePoint
.v
== currentPoint
.v
&& theOffset
< content
.length())
2175 TXNOffsetToPoint(m_txn
, ++theOffset
, ¤tPoint
);
2182 // ----------------------------------------------------------------------------
2183 // MLTE control implementation (classic part)
2184 // ----------------------------------------------------------------------------
2186 // OS X Notes : We still don't have a full replacement for MLTE, so this implementation
2187 // has to live on. We have different problems coming from outdated implementations on the
2188 // various OS X versions. Most deal with the scrollbars: they are not correctly embedded
2189 // while this can be solved on 10.3 by reassigning them the correct place, on 10.2 there is
2190 // no way out, therefore we are using our own implementation and our own scrollbars ....
2192 #ifdef __WXMAC_OSX__
2194 TXNScrollInfoUPP gTXNScrollInfoProc
= NULL
;
2195 ControlActionUPP gTXNScrollActionProc
= NULL
;
2197 pascal void wxMacMLTEClassicControl::TXNScrollInfoProc(
2198 SInt32 iValue
, SInt32 iMaximumValue
,
2199 TXNScrollBarOrientation iScrollBarOrientation
, SInt32 iRefCon
)
2201 wxMacMLTEClassicControl
* mlte
= (wxMacMLTEClassicControl
*) iRefCon
;
2202 SInt32 value
= wxMax( iValue
, 0 ) ;
2203 SInt32 maximum
= wxMax( iMaximumValue
, 0 ) ;
2205 if ( iScrollBarOrientation
== kTXNHorizontal
)
2207 if ( mlte
->m_sbHorizontal
)
2209 SetControl32BitValue( mlte
->m_sbHorizontal
, value
) ;
2210 SetControl32BitMaximum( mlte
->m_sbHorizontal
, maximum
) ;
2211 mlte
->m_lastHorizontalValue
= value
;
2214 else if ( iScrollBarOrientation
== kTXNVertical
)
2216 if ( mlte
->m_sbVertical
)
2218 SetControl32BitValue( mlte
->m_sbVertical
, value
) ;
2219 SetControl32BitMaximum( mlte
->m_sbVertical
, maximum
) ;
2220 mlte
->m_lastVerticalValue
= value
;
2225 pascal void wxMacMLTEClassicControl::TXNScrollActionProc( ControlRef controlRef
, ControlPartCode partCode
)
2227 wxMacMLTEClassicControl
* mlte
= (wxMacMLTEClassicControl
*) GetControlReference( controlRef
) ;
2231 if ( controlRef
!= mlte
->m_sbVertical
&& controlRef
!= mlte
->m_sbHorizontal
)
2235 bool isHorizontal
= ( controlRef
== mlte
->m_sbHorizontal
) ;
2237 SInt32 minimum
= 0 ;
2238 SInt32 maximum
= GetControl32BitMaximum( controlRef
) ;
2239 SInt32 value
= GetControl32BitValue( controlRef
) ;
2245 case kControlDownButtonPart
:
2249 case kControlUpButtonPart
:
2253 case kControlPageDownPart
:
2254 delta
= GetControlViewSize( controlRef
) ;
2257 case kControlPageUpPart
:
2258 delta
= -GetControlViewSize( controlRef
) ;
2261 case kControlIndicatorPart
:
2262 delta
= value
- (isHorizontal
? mlte
->m_lastHorizontalValue
: mlte
->m_lastVerticalValue
) ;
2271 SInt32 newValue
= value
;
2273 if ( partCode
!= kControlIndicatorPart
)
2275 if ( value
+ delta
< minimum
)
2276 delta
= minimum
- value
;
2277 if ( value
+ delta
> maximum
)
2278 delta
= maximum
- value
;
2280 SetControl32BitValue( controlRef
, value
+ delta
) ;
2281 newValue
= value
+ delta
;
2284 SInt32 verticalDelta
= isHorizontal
? 0 : delta
;
2285 SInt32 horizontalDelta
= isHorizontal
? delta
: 0 ;
2288 mlte
->m_txn
, kTXNScrollUnitsInPixels
, kTXNScrollUnitsInPixels
,
2289 &verticalDelta
, &horizontalDelta
);
2292 mlte
->m_lastHorizontalValue
= newValue
;
2294 mlte
->m_lastVerticalValue
= newValue
;
2299 // make correct activations
2300 void wxMacMLTEClassicControl::MacActivatePaneText(bool setActive
)
2302 wxTextCtrl
* textctrl
= (wxTextCtrl
*) GetControlReference(m_controlRef
);
2304 wxMacWindowClipper
clipper( textctrl
) ;
2305 TXNActivate( m_txn
, m_txnFrameID
, setActive
);
2307 ControlRef controlFocus
= 0 ;
2308 GetKeyboardFocus( m_txnWindow
, &controlFocus
) ;
2309 if ( controlFocus
== m_controlRef
)
2310 TXNFocus( m_txn
, setActive
);
2313 void wxMacMLTEClassicControl::MacFocusPaneText(bool setFocus
)
2315 TXNFocus( m_txn
, setFocus
);
2318 // guards against inappropriate redraw (hidden objects drawing onto window)
2320 void wxMacMLTEClassicControl::MacSetObjectVisibility(bool vis
)
2322 ControlRef controlFocus
= 0 ;
2323 GetKeyboardFocus( m_txnWindow
, &controlFocus
) ;
2325 if ( !vis
&& (controlFocus
== m_controlRef
) )
2326 SetKeyboardFocus( m_txnWindow
, m_controlRef
, kControlFocusNoPart
) ;
2328 TXNControlTag iControlTags
[1] = { kTXNVisibilityTag
};
2329 TXNControlData iControlData
[1] = { { (UInt32
)false } };
2331 verify_noerr( TXNGetTXNObjectControls( m_txn
, 1, iControlTags
, iControlData
) ) ;
2333 if ( iControlData
[0].uValue
!= vis
)
2335 iControlData
[0].uValue
= vis
;
2336 verify_noerr( TXNSetTXNObjectControls( m_txn
, false , 1, iControlTags
, iControlData
) ) ;
2339 // currently, we always clip as partial visibility (overlapped) visibility is also a problem,
2340 // if we run into further problems we might set the FrameBounds to an empty rect here
2343 // make sure that the TXNObject is at the right position
2345 void wxMacMLTEClassicControl::MacUpdatePosition()
2347 wxTextCtrl
* textctrl
= (wxTextCtrl
*)GetControlReference( m_controlRef
);
2348 if ( textctrl
== NULL
)
2352 UMAGetControlBoundsInWindowCoords( m_controlRef
, &bounds
);
2354 wxRect visRect
= textctrl
->MacGetClippedClientRect() ;
2355 Rect visBounds
= { visRect
.y
, visRect
.x
, visRect
.y
+ visRect
.height
, visRect
.x
+ visRect
.width
} ;
2358 textctrl
->MacWindowToRootWindow( &x
, &y
) ;
2359 OffsetRect( &visBounds
, x
, y
) ;
2361 if ( !EqualRect( &bounds
, &m_txnControlBounds
) || !EqualRect( &visBounds
, &m_txnVisBounds
) )
2363 m_txnControlBounds
= bounds
;
2364 m_txnVisBounds
= visBounds
;
2365 wxMacWindowClipper
cl( textctrl
) ;
2367 #ifdef __WXMAC_OSX__
2368 bool isCompositing
= textctrl
->MacGetTopLevelWindow()->MacUsesCompositing() ;
2369 if ( m_sbHorizontal
|| m_sbVertical
)
2371 int w
= bounds
.right
- bounds
.left
;
2372 int h
= bounds
.bottom
- bounds
.top
;
2374 if ( m_sbHorizontal
)
2378 sbBounds
.left
= -1 ;
2379 sbBounds
.top
= h
- 14 ;
2380 sbBounds
.right
= w
+ 1 ;
2381 sbBounds
.bottom
= h
+ 1 ;
2383 if ( !isCompositing
)
2384 OffsetRect( &sbBounds
, m_txnControlBounds
.left
, m_txnControlBounds
.top
) ;
2386 SetControlBounds( m_sbHorizontal
, &sbBounds
) ;
2387 SetControlViewSize( m_sbHorizontal
, w
) ;
2394 sbBounds
.left
= w
- 14 ;
2396 sbBounds
.right
= w
+ 1 ;
2397 sbBounds
.bottom
= m_sbHorizontal
? h
- 14 : h
+ 1 ;
2399 if ( !isCompositing
)
2400 OffsetRect( &sbBounds
, m_txnControlBounds
.left
, m_txnControlBounds
.top
) ;
2402 SetControlBounds( m_sbVertical
, &sbBounds
) ;
2403 SetControlViewSize( m_sbVertical
, h
) ;
2408 TXNLongRect olddestRect
;
2409 TXNGetRectBounds( m_txn
, &oldviewRect
, &olddestRect
, NULL
) ;
2411 Rect viewRect
= { m_txnControlBounds
.top
, m_txnControlBounds
.left
,
2412 m_txnControlBounds
.bottom
- ( m_sbHorizontal
? 14 : 0 ) ,
2413 m_txnControlBounds
.right
- ( m_sbVertical
? 14 : 0 ) } ;
2414 TXNLongRect destRect
= { m_txnControlBounds
.top
, m_txnControlBounds
.left
,
2415 m_txnControlBounds
.bottom
- ( m_sbHorizontal
? 14 : 0 ) ,
2416 m_txnControlBounds
.right
- ( m_sbVertical
? 14 : 0 ) } ;
2418 if ( olddestRect
.right
>= 10000 )
2419 destRect
.right
= destRect
.left
+ 32000 ;
2421 if ( olddestRect
.bottom
>= 0x20000000 )
2422 destRect
.bottom
= destRect
.top
+ 0x40000000 ;
2424 SectRect( &viewRect
, &visBounds
, &viewRect
) ;
2425 TXNSetRectBounds( m_txn
, &viewRect
, &destRect
, true ) ;
2430 m_txnControlBounds
.top
,
2431 m_txnControlBounds
.left
,
2432 m_txnControlBounds
.bottom
- (m_sbHorizontal
? 14 : 0),
2433 m_txnControlBounds
.right
- (m_sbVertical
? 14 : 0),
2439 m_txn
, m_txnControlBounds
.top
, m_txnControlBounds
.left
,
2440 wxMax( m_txnControlBounds
.bottom
, m_txnControlBounds
.top
),
2441 wxMax( m_txnControlBounds
.right
, m_txnControlBounds
.left
), m_txnFrameID
);
2444 // the SetFrameBounds method under Classic sometimes does not correctly scroll a selection into sight after a
2445 // movement, therefore we have to force it
2447 // this problem has been reported in OSX as well, so we use this here once again
2449 TXNLongRect textRect
;
2450 TXNGetRectBounds( m_txn
, NULL
, NULL
, &textRect
) ;
2451 if ( textRect
.left
< m_txnControlBounds
.left
)
2452 TXNShowSelection( m_txn
, kTXNShowStart
) ;
2456 void wxMacMLTEClassicControl::SetRect( Rect
*r
)
2458 wxMacControl::SetRect( r
) ;
2459 MacUpdatePosition() ;
2462 void wxMacMLTEClassicControl::MacControlUserPaneDrawProc(wxInt16 thePart
)
2464 wxTextCtrl
* textctrl
= (wxTextCtrl
*)GetControlReference( m_controlRef
);
2465 if ( textctrl
== NULL
)
2468 if ( textctrl
->MacIsReallyShown() )
2470 wxMacWindowClipper
clipper( textctrl
) ;
2471 TXNDraw( m_txn
, NULL
) ;
2475 wxInt16
wxMacMLTEClassicControl::MacControlUserPaneHitTestProc(wxInt16 x
, wxInt16 y
)
2477 Point where
= { y
, x
} ;
2478 ControlPartCode result
= kControlNoPart
;
2480 wxTextCtrl
* textctrl
= (wxTextCtrl
*) GetControlReference( m_controlRef
);
2481 if ( (textctrl
!= NULL
) && textctrl
->MacIsReallyShown() )
2483 if (PtInRect( where
, &m_txnControlBounds
))
2485 result
= kControlEditTextPart
;
2489 // sometimes we get the coords also in control local coordinates, therefore test again
2490 if ( textctrl
->MacGetTopLevelWindow()->MacUsesCompositing() )
2493 textctrl
->MacClientToRootWindow( &x
, &y
) ;
2498 if (PtInRect( where
, &m_txnControlBounds
))
2499 result
= kControlEditTextPart
;
2506 wxInt16
wxMacMLTEClassicControl::MacControlUserPaneTrackingProc( wxInt16 x
, wxInt16 y
, void* actionProc
)
2508 ControlPartCode result
= kControlNoPart
;
2510 wxTextCtrl
* textctrl
= (wxTextCtrl
*) GetControlReference( m_controlRef
);
2511 if ( (textctrl
!= NULL
) && textctrl
->MacIsReallyShown() )
2513 Point startPt
= { y
, x
} ;
2514 // for compositing, we must convert these into toplevel window coordinates, because hittesting expects them
2515 if ( textctrl
->MacGetTopLevelWindow()->MacUsesCompositing() )
2518 textctrl
->MacClientToRootWindow( &x
, &y
) ;
2523 switch (MacControlUserPaneHitTestProc( startPt
.h
, startPt
.v
))
2525 case kControlEditTextPart
:
2527 wxMacWindowClipper
clipper( textctrl
) ;
2530 ConvertEventRefToEventRecord( (EventRef
) wxTheApp
->MacGetCurrentEvent() , &rec
) ;
2531 TXNClick( m_txn
, &rec
);
2543 void wxMacMLTEClassicControl::MacControlUserPaneIdleProc()
2545 wxTextCtrl
* textctrl
= (wxTextCtrl
*)GetControlReference( m_controlRef
);
2546 if ( textctrl
== NULL
)
2549 if (textctrl
->MacIsReallyShown())
2551 if (IsControlActive(m_controlRef
))
2555 wxMacWindowClipper
clipper( textctrl
) ;
2560 if (PtInRect(mousep
, &m_txnControlBounds
))
2562 RgnHandle theRgn
= NewRgn();
2563 RectRgn(theRgn
, &m_txnControlBounds
);
2564 TXNAdjustCursor(m_txn
, theRgn
);
2571 wxInt16
wxMacMLTEClassicControl::MacControlUserPaneKeyDownProc (wxInt16 keyCode
, wxInt16 charCode
, wxInt16 modifiers
)
2573 wxTextCtrl
* textctrl
= (wxTextCtrl
*)GetControlReference( m_controlRef
);
2574 if ( textctrl
== NULL
)
2575 return kControlNoPart
;
2577 wxMacWindowClipper
clipper( textctrl
) ;
2580 memset( &ev
, 0 , sizeof( ev
) ) ;
2582 ev
.modifiers
= modifiers
;
2583 ev
.message
= ((keyCode
<< 8) & keyCodeMask
) | (charCode
& charCodeMask
);
2584 TXNKeyDown( m_txn
, &ev
);
2586 return kControlEntireControl
;
2589 void wxMacMLTEClassicControl::MacControlUserPaneActivateProc(bool activating
)
2591 MacActivatePaneText( activating
);
2594 wxInt16
wxMacMLTEClassicControl::MacControlUserPaneFocusProc(wxInt16 action
)
2596 ControlPartCode focusResult
= kControlFocusNoPart
;
2598 wxTextCtrl
* textctrl
= (wxTextCtrl
*)GetControlReference( m_controlRef
);
2599 if ( textctrl
== NULL
)
2602 wxMacWindowClipper
clipper( textctrl
) ;
2604 ControlRef controlFocus
= NULL
;
2605 GetKeyboardFocus( m_txnWindow
, &controlFocus
) ;
2606 bool wasFocused
= ( controlFocus
== m_controlRef
) ;
2610 case kControlFocusPrevPart
:
2611 case kControlFocusNextPart
:
2612 MacFocusPaneText( !wasFocused
);
2613 focusResult
= (!wasFocused
? (ControlPartCode
) kControlEditTextPart
: (ControlPartCode
) kControlFocusNoPart
);
2616 case kControlFocusNoPart
:
2618 MacFocusPaneText( false );
2619 focusResult
= kControlFocusNoPart
;
2626 void wxMacMLTEClassicControl::MacControlUserPaneBackgroundProc( void *info
)
2630 wxMacMLTEClassicControl::wxMacMLTEClassicControl( wxTextCtrl
*wxPeer
,
2631 const wxString
& str
,
2633 const wxSize
& size
, long style
) : 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
;
2646 ::CreateUserPaneControl(
2647 MAC_WXHWND(wxPeer
->GetParent()->MacGetTopLevelWindowRef()),
2648 &bounds
, featureSet
, &m_controlRef
) );
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()
2775 OSStatus err
= noErr
;
2777 // set up our globals
2778 #ifdef __WXMAC_OSX__
2779 if (gTPDrawProc
== NULL
) gTPDrawProc
= NewControlUserPaneDrawUPP(wxMacControlUserPaneDrawProc
);
2780 if (gTPHitProc
== NULL
) gTPHitProc
= NewControlUserPaneHitTestUPP(wxMacControlUserPaneHitTestProc
);
2781 if (gTPTrackProc
== NULL
) gTPTrackProc
= NewControlUserPaneTrackingUPP(wxMacControlUserPaneTrackingProc
);
2782 if (gTPIdleProc
== NULL
) gTPIdleProc
= NewControlUserPaneIdleUPP(wxMacControlUserPaneIdleProc
);
2783 if (gTPKeyProc
== NULL
) gTPKeyProc
= NewControlUserPaneKeyDownUPP(wxMacControlUserPaneKeyDownProc
);
2784 if (gTPActivateProc
== NULL
) gTPActivateProc
= NewControlUserPaneActivateUPP(wxMacControlUserPaneActivateProc
);
2785 if (gTPFocusProc
== NULL
) gTPFocusProc
= NewControlUserPaneFocusUPP(wxMacControlUserPaneFocusProc
);
2787 if (gTXNScrollInfoProc
== NULL
) gTXNScrollInfoProc
= NewTXNScrollInfoUPP(TXNScrollInfoProc
) ;
2788 if (gTXNScrollActionProc
== NULL
) gTXNScrollActionProc
= NewControlActionUPP(TXNScrollActionProc
) ;
2791 // set the initial settings for our private data
2793 m_txnWindow
= GetControlOwner(m_controlRef
);
2794 m_txnPort
= (GrafPtr
) GetWindowPort(m_txnWindow
);
2796 #ifdef __WXMAC_OSX__
2797 // set up the user pane procedures
2798 SetControlData(m_controlRef
, kControlEntireControl
, kControlUserPaneDrawProcTag
, sizeof(gTPDrawProc
), &gTPDrawProc
);
2799 SetControlData(m_controlRef
, kControlEntireControl
, kControlUserPaneHitTestProcTag
, sizeof(gTPHitProc
), &gTPHitProc
);
2800 SetControlData(m_controlRef
, kControlEntireControl
, kControlUserPaneTrackingProcTag
, sizeof(gTPTrackProc
), &gTPTrackProc
);
2801 SetControlData(m_controlRef
, kControlEntireControl
, kControlUserPaneIdleProcTag
, sizeof(gTPIdleProc
), &gTPIdleProc
);
2802 SetControlData(m_controlRef
, kControlEntireControl
, kControlUserPaneKeyDownProcTag
, sizeof(gTPKeyProc
), &gTPKeyProc
);
2803 SetControlData(m_controlRef
, kControlEntireControl
, kControlUserPaneActivateProcTag
, sizeof(gTPActivateProc
), &gTPActivateProc
);
2804 SetControlData(m_controlRef
, kControlEntireControl
, kControlUserPaneFocusProcTag
, sizeof(gTPFocusProc
), &gTPFocusProc
);
2807 // calculate the rectangles used by the control
2808 UMAGetControlBoundsInWindowCoords( m_controlRef
, &bounds
);
2810 m_txnControlBounds
= bounds
;
2811 m_txnVisBounds
= bounds
;
2816 GetGWorld( &origPort
, &origDev
) ;
2817 SetPort( m_txnPort
);
2819 // create the new edit field
2820 TXNFrameOptions frameOptions
= FrameOptionsFromWXStyle( m_windowStyle
);
2822 #ifdef __WXMAC_OSX__
2823 // the scrollbars are not correctly embedded but are inserted at the root:
2824 // this gives us problems as we have erratic redraws even over the structure area
2826 m_sbHorizontal
= 0 ;
2828 m_lastHorizontalValue
= 0 ;
2829 m_lastVerticalValue
= 0 ;
2831 Rect sb
= { 0 , 0 , 0 , 0 } ;
2832 if ( frameOptions
& kTXNWantVScrollBarMask
)
2834 CreateScrollBarControl( m_txnWindow
, &sb
, 0, 0, 100, 1, true, gTXNScrollActionProc
, &m_sbVertical
);
2835 SetControlReference( m_sbVertical
, (SInt32
)this );
2836 SetControlAction( m_sbVertical
, gTXNScrollActionProc
);
2837 ShowControl( m_sbVertical
);
2838 EmbedControl( m_sbVertical
, m_controlRef
);
2839 frameOptions
&= ~kTXNWantVScrollBarMask
;
2842 if ( frameOptions
& kTXNWantHScrollBarMask
)
2844 CreateScrollBarControl( m_txnWindow
, &sb
, 0, 0, 100, 1, true, gTXNScrollActionProc
, &m_sbHorizontal
);
2845 SetControlReference( m_sbHorizontal
, (SInt32
)this );
2846 SetControlAction( m_sbHorizontal
, gTXNScrollActionProc
);
2847 ShowControl( m_sbHorizontal
);
2848 EmbedControl( m_sbHorizontal
, m_controlRef
);
2849 frameOptions
&= ~(kTXNWantHScrollBarMask
| kTXNDrawGrowIconMask
);
2856 NULL
, m_txnWindow
, &bounds
, frameOptions
,
2857 kTXNTextEditStyleFrameType
, kTXNTextensionFile
, kTXNSystemDefaultEncoding
,
2858 &m_txn
, &m_txnFrameID
, NULL
) );
2861 TXNControlTag iControlTags
[] = { kTXNUseCarbonEvents
};
2862 TXNControlData iControlData
[] = { { (UInt32
)&cInfo
} };
2863 int toptag
= WXSIZEOF( iControlTags
) ;
2864 TXNCarbonEventInfo cInfo
;
2865 cInfo
.useCarbonEvents
= false ;
2868 cInfo
.fDictionary
= NULL
;
2870 verify_noerr( TXNSetTXNObjectControls( m_txn
, false, toptag
, iControlTags
, iControlData
) );
2873 #ifdef __WXMAC_OSX__
2874 TXNRegisterScrollInfoProc( m_txn
, gTXNScrollInfoProc
, (SInt32
)this );
2877 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
) ;
2900 HIRect hr
= { { bounds
.left
, bounds
.top
} ,
2901 { bounds
.right
- bounds
.left
, bounds
.bottom
- bounds
.top
} } ;
2903 m_scrollView
= NULL
;
2904 TXNFrameOptions frameOptions
= FrameOptionsFromWXStyle( style
) ;
2905 if ( frameOptions
& (kTXNWantVScrollBarMask
| kTXNWantHScrollBarMask
) )
2908 (frameOptions
& kTXNWantHScrollBarMask
? kHIScrollViewOptionsHorizScroll
: 0)
2909 | (frameOptions
& kTXNWantVScrollBarMask
? kHIScrollViewOptionsVertScroll
: 0) ,
2912 HIViewSetFrame( m_scrollView
, &hr
);
2913 HIViewSetVisible( m_scrollView
, true );
2917 HITextViewCreate( NULL
, 0, frameOptions
, &m_textView
) ;
2918 m_txn
= HITextViewGetTXNObject( m_textView
) ;
2919 HIViewSetVisible( m_textView
, true ) ;
2922 HIViewAddSubview( m_scrollView
, m_textView
) ;
2923 m_controlRef
= m_scrollView
;
2924 wxPeer
->MacInstallEventHandler( (WXWidget
) m_textView
) ;
2928 HIViewSetFrame( m_textView
, &hr
);
2929 m_controlRef
= m_textView
;
2932 AdjustCreationAttributes( *wxWHITE
, true ) ;
2934 wxMacWindowClipper
c( m_peer
) ;
2935 SetTXNData( st
, kTXNStartOffset
, kTXNEndOffset
) ;
2937 TXNSetSelection( m_txn
, 0, 0 );
2938 TXNShowSelection( m_txn
, kTXNShowStart
);
2941 OSStatus
wxMacMLTEHIViewControl::SetFocus( ControlFocusPart focusPart
)
2943 return SetKeyboardFocus( GetControlOwner( m_textView
), m_textView
, focusPart
) ;
2946 bool wxMacMLTEHIViewControl::HasFocus() const
2948 ControlRef control
;
2949 GetKeyboardFocus( GetUserFocusWindow() , &control
) ;
2950 return control
== m_textView
;
2953 void wxMacMLTEHIViewControl::SetBackground( const wxBrush
&brush
)
2955 wxMacMLTEControl::SetBackground( brush
) ;
2958 CGColorSpaceRef rgbSpace
= CGColorSpaceCreateDeviceRGB();
2959 RGBColor col
= MAC_WXCOLORREF(brush
.GetColour().GetPixel()) ;
2961 float component
[4] ;
2962 component
[0] = col
.red
/ 65536.0 ;
2963 component
[1] = col
.green
/ 65536.0 ;
2964 component
[2] = col
.blue
/ 65536.0 ;
2965 component
[3] = 1.0 ; // alpha
2967 CGColorRef color
= CGColorCreate (rgbSpace
, component
);
2968 HITextViewSetBackgroundColor( m_textView
, color
) ;
2969 CGColorSpaceRelease( rgbSpace
);
2973 #endif // MAC_OS_X_VERSION_MAX_ALLOWED > MAC_OS_X_VERSION_10_2
2978 #endif // wxUSE_TEXTCTRL