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 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 verify_noerr( TXNSetTXNObjectControls( m_txn
, false, toptag
, iControlTags
, iControlData
) ) ;
1693 // setting the default font:
1694 // under 10.2 this causes a visible caret, therefore we avoid it
1696 if ( UMAGetSystemVersion() >= 0x1030 )
1702 GetThemeFont(kThemeSystemFont
, GetApplicationScript() , fontName
, &fontSize
, &fontStyle
) ;
1704 TXNTypeAttributes typeAttr
[] =
1706 { kTXNQDFontNameAttribute
, kTXNQDFontNameAttributeSize
, { (void*) fontName
} } ,
1707 { kTXNQDFontSizeAttribute
, kTXNFontSizeAttributeSize
, { (void*) (fontSize
<< 16) } } ,
1708 { kTXNQDFontStyleAttribute
, kTXNQDFontStyleAttributeSize
, { (void*) normal
} } ,
1712 TXNSetTypeAttributes(
1713 m_txn
, sizeof(typeAttr
) / sizeof(TXNTypeAttributes
),
1714 typeAttr
, kTXNStartOffset
, kTXNEndOffset
) );
1717 if ( m_windowStyle
& wxTE_PASSWORD
)
1720 verify_noerr (TXNEchoMode( m_txn
, c
, 0 , true ) );
1723 TXNBackground tback
;
1724 tback
.bgType
= kTXNBackgroundTypeRGB
;
1725 tback
.bg
.color
= MAC_WXCOLORREF( background
.GetPixel() );
1726 TXNSetBackground( m_txn
, &tback
);
1728 #if MAC_OS_X_VERSION_MAX_ALLOWED >= MAC_OS_X_VERSION_10_4
1729 if ( UMAGetSystemVersion() >= 0x1040 )
1731 TXNCommandEventSupportOptions options
;
1732 if ( TXNGetCommandEventSupport( m_txn
, &options
) == noErr
)
1735 kTXNSupportEditCommandProcessing
1736 | kTXNSupportEditCommandUpdating
1737 | kTXNSupportSpellCheckCommandProcessing
1738 | kTXNSupportSpellCheckCommandUpdating
1739 | kTXNSupportFontCommandProcessing
1740 | kTXNSupportFontCommandUpdating
;
1742 TXNSetCommandEventSupport( m_txn
, options
) ;
1748 void wxMacMLTEControl::SetBackground( const wxBrush
&brush
)
1750 // currently only solid background are supported
1751 TXNBackground tback
;
1753 tback
.bgType
= kTXNBackgroundTypeRGB
;
1754 tback
.bg
.color
= MAC_WXCOLORREF( brush
.GetColour().GetPixel() );
1755 TXNSetBackground( m_txn
, &tback
);
1758 void wxMacMLTEControl::TXNSetAttribute( const wxTextAttr
& style
, long from
, long to
)
1760 TXNTypeAttributes typeAttr
[4] ;
1761 Str255 fontName
= "\pMonaco" ;
1762 SInt16 fontSize
= 12 ;
1763 Style fontStyle
= normal
;
1767 if ( style
.HasFont() )
1769 const wxFont
&font
= style
.GetFont() ;
1770 wxMacStringToPascal( font
.GetFaceName() , fontName
) ;
1771 fontSize
= font
.GetPointSize() ;
1772 if ( font
.GetUnderlined() )
1773 fontStyle
|= underline
;
1774 if ( font
.GetWeight() == wxBOLD
)
1776 if ( font
.GetStyle() == wxITALIC
)
1777 fontStyle
|= italic
;
1779 typeAttr
[attrCount
].tag
= kTXNQDFontNameAttribute
;
1780 typeAttr
[attrCount
].size
= kTXNQDFontNameAttributeSize
;
1781 typeAttr
[attrCount
].data
.dataPtr
= (void*)fontName
;
1784 typeAttr
[attrCount
].tag
= kTXNQDFontSizeAttribute
;
1785 typeAttr
[attrCount
].size
= kTXNFontSizeAttributeSize
;
1786 typeAttr
[attrCount
].data
.dataValue
= (fontSize
<< 16) ;
1789 typeAttr
[attrCount
].tag
= kTXNQDFontStyleAttribute
;
1790 typeAttr
[attrCount
].size
= kTXNQDFontStyleAttributeSize
;
1791 typeAttr
[attrCount
].data
.dataValue
= fontStyle
;
1795 if ( style
.HasTextColour() )
1797 color
= MAC_WXCOLORREF(style
.GetTextColour().GetPixel()) ;
1799 typeAttr
[attrCount
].tag
= kTXNQDFontColorAttribute
;
1800 typeAttr
[attrCount
].size
= kTXNQDFontColorAttributeSize
;
1801 typeAttr
[attrCount
].data
.dataPtr
= (void*) &color
;
1805 if ( attrCount
> 0 )
1807 verify_noerr( TXNSetTypeAttributes( m_txn
, attrCount
, typeAttr
, from
, to
) );
1811 void wxMacMLTEControl::SetFont( const wxFont
& font
, const wxColour
& foreground
, long windowStyle
)
1813 wxMacEditHelper
help( m_txn
) ;
1814 TXNSetAttribute( wxTextAttr( foreground
, wxNullColour
, font
), kTXNStartOffset
, kTXNEndOffset
) ;
1817 void wxMacMLTEControl::SetStyle( long start
, long end
, const wxTextAttr
& style
)
1819 wxMacEditHelper
help( m_txn
) ;
1820 TXNSetAttribute( style
, start
, end
) ;
1823 void wxMacMLTEControl::Copy()
1825 ClearCurrentScrap();
1827 TXNConvertToPublicScrap();
1830 void wxMacMLTEControl::Cut()
1832 ClearCurrentScrap();
1834 TXNConvertToPublicScrap();
1837 void wxMacMLTEControl::Paste()
1839 TXNConvertFromPublicScrap();
1843 bool wxMacMLTEControl::CanPaste() const
1845 return TXNIsScrapPastable() ;
1848 void wxMacMLTEControl::SetEditable(bool editable
)
1850 TXNControlTag tag
[] = { kTXNIOPrivilegesTag
} ;
1851 TXNControlData data
[] = { { editable
? kTXNReadWrite
: kTXNReadOnly
} } ;
1852 TXNSetTXNObjectControls( m_txn
, false, WXSIZEOF(tag
), tag
, data
) ;
1855 wxTextPos
wxMacMLTEControl::GetLastPosition() const
1857 wxTextPos actualsize
= 0 ;
1860 OSErr err
= TXNGetDataEncoded( m_txn
, kTXNStartOffset
, kTXNEndOffset
, &theText
, kTXNTextData
);
1865 actualsize
= GetHandleSize( theText
) ;
1866 DisposeHandle( theText
) ;
1876 void wxMacMLTEControl::Replace( long from
, long to
, const wxString
&str
)
1878 wxString value
= str
;
1879 wxMacConvertNewlines10To13( &value
) ;
1881 wxMacEditHelper
help( m_txn
) ;
1882 wxMacWindowClipper
c( m_peer
) ;
1884 TXNSetSelection( m_txn
, from
, to
) ;
1886 SetTXNData( value
, kTXNUseCurrentSelection
, kTXNUseCurrentSelection
) ;
1889 void wxMacMLTEControl::Remove( long from
, long to
)
1891 wxMacWindowClipper
c( m_peer
) ;
1892 wxMacEditHelper
help( m_txn
) ;
1893 TXNSetSelection( m_txn
, from
, to
) ;
1897 void wxMacMLTEControl::GetSelection( long* from
, long* to
) const
1899 TXNGetSelection( m_txn
, (TXNOffset
*) from
, (TXNOffset
*) to
) ;
1902 void wxMacMLTEControl::SetSelection( long from
, long to
)
1904 wxMacWindowClipper
c( m_peer
) ;
1906 // change the selection
1907 if ((from
== -1) && (to
== -1))
1908 TXNSelectAll( m_txn
);
1910 TXNSetSelection( m_txn
, from
, to
);
1912 TXNShowSelection( m_txn
, kTXNShowStart
);
1915 void wxMacMLTEControl::WriteText( const wxString
& str
)
1918 wxMacConvertNewlines10To13( &st
) ;
1920 long start
, end
, dummy
;
1922 GetSelection( &start
, &dummy
) ;
1923 wxMacWindowClipper
c( m_peer
) ;
1926 wxMacEditHelper
helper( m_txn
) ;
1927 SetTXNData( st
, kTXNUseCurrentSelection
, kTXNUseCurrentSelection
) ;
1930 GetSelection( &dummy
, &end
) ;
1932 // TODO: SetStyle( start , end , GetDefaultStyle() ) ;
1935 void wxMacMLTEControl::Clear()
1937 wxMacWindowClipper
c( m_peer
) ;
1938 wxMacEditHelper
st( m_txn
) ;
1939 TXNSetSelection( m_txn
, kTXNStartOffset
, kTXNEndOffset
) ;
1943 bool wxMacMLTEControl::CanUndo() const
1945 return TXNCanUndo( m_txn
, NULL
) ;
1948 void wxMacMLTEControl::Undo()
1953 bool wxMacMLTEControl::CanRedo() const
1955 return TXNCanRedo( m_txn
, NULL
) ;
1958 void wxMacMLTEControl::Redo()
1963 int wxMacMLTEControl::GetNumberOfLines() const
1965 ItemCount lines
= 0 ;
1966 TXNGetLineCount( m_txn
, &lines
) ;
1971 long wxMacMLTEControl::XYToPosition(long x
, long y
) const
1976 // TODO: find a better implementation : while we can get the
1977 // line metrics of a certain line, we don't get its starting
1978 // position, so it would probably be rather a binary search
1979 // for the start position
1980 long xpos
= 0, ypos
= 0 ;
1981 int lastHeight
= 0 ;
1984 lastpos
= GetLastPosition() ;
1985 for ( n
= 0 ; n
<= (ItemCount
) lastpos
; ++n
)
1987 if ( y
== ypos
&& x
== xpos
)
1990 TXNOffsetToPoint( m_txn
, n
, &curpt
);
1992 if ( curpt
.v
> lastHeight
)
1998 lastHeight
= curpt
.v
;
2007 bool wxMacMLTEControl::PositionToXY( long pos
, long *x
, long *y
) const
2017 lastpos
= GetLastPosition() ;
2018 if ( pos
<= lastpos
)
2020 // TODO: find a better implementation - while we can get the
2021 // line metrics of a certain line, we don't get its starting
2022 // position, so it would probably be rather a binary search
2023 // for the start position
2024 long xpos
= 0, ypos
= 0 ;
2025 int lastHeight
= 0 ;
2028 for ( n
= 0 ; n
<= (ItemCount
) pos
; ++n
)
2030 TXNOffsetToPoint(m_txn
, n
, &curpt
);
2032 if ( curpt
.v
> lastHeight
)
2038 lastHeight
= curpt
.v
;
2053 void wxMacMLTEControl::ShowPosition( long pos
)
2055 #if TARGET_RT_MAC_MACHO && defined(AVAILABLE_MAC_OS_X_VERSION_10_2_AND_LATER)
2057 Point current
, desired
;
2058 TXNOffset selstart
, selend
;
2060 TXNGetSelection( m_txn
, &selstart
, &selend
);
2061 TXNOffsetToPoint( m_txn
, selstart
, ¤t
);
2062 TXNOffsetToPoint( m_txn
, pos
, &desired
);
2064 // TODO: use HIPoints for 10.3 and above
2065 if ( (UInt32
)TXNScroll
!= (UInt32
)kUnresolvedCFragSymbolAddress
)
2067 OSErr theErr
= noErr
;
2068 SInt32 dv
= desired
.v
- current
.v
;
2069 SInt32 dh
= desired
.h
- current
.h
;
2070 TXNShowSelection( m_txn
, kTXNShowEnd
); // NB: should this be kTXNShowStart or kTXNShowEnd ??
2071 theErr
= TXNScroll( m_txn
, kTXNScrollUnitsInPixels
, kTXNScrollUnitsInPixels
, &dv
, &dh
);
2073 // there will be an error returned for classic MLTE implementation when the control is
2074 // invisible, but HITextView works correctly, so we don't assert that one
2075 // wxASSERT_MSG( theErr == noErr, _T("TXNScroll returned an error!") );
2081 void wxMacMLTEControl::SetTXNData( const wxString
& st
, TXNOffset start
, TXNOffset end
)
2084 #if SIZEOF_WCHAR_T == 2
2085 size_t len
= st
.Len() ;
2086 TXNSetData( m_txn
, kTXNUnicodeTextData
, (void*)st
.wc_str(), len
* 2, start
, end
);
2088 wxMBConvUTF16 converter
;
2089 ByteCount byteBufferLen
= converter
.WC2MB( NULL
, st
.wc_str(), 0 ) ;
2090 UniChar
*unibuf
= (UniChar
*)malloc( byteBufferLen
) ;
2091 converter
.WC2MB( (char*)unibuf
, st
.wc_str(), byteBufferLen
) ;
2092 TXNSetData( m_txn
, kTXNUnicodeTextData
, (void*)unibuf
, byteBufferLen
, start
, end
) ;
2096 wxCharBuffer text
= st
.mb_str( wxConvLocal
) ;
2097 TXNSetData( m_txn
, kTXNTextData
, (void*)text
.data(), strlen( text
), start
, end
) ;
2101 wxString
wxMacMLTEControl::GetLineText(long lineNo
) const
2105 if ( lineNo
< GetNumberOfLines() )
2108 Fixed lineWidth
, lineHeight
, currentHeight
;
2111 // get the first possible position in the control
2112 TXNOffsetToPoint(m_txn
, 0, &firstPoint
);
2114 // Iterate through the lines until we reach the one we want,
2115 // adding to our current y pixel point position
2118 while (ypos
< lineNo
)
2120 TXNGetLineMetrics(m_txn
, ypos
++, &lineWidth
, &lineHeight
);
2121 currentHeight
+= lineHeight
;
2124 Point thePoint
= { firstPoint
.v
+ (currentHeight
>> 16), firstPoint
.h
+ (0) };
2125 TXNOffset theOffset
;
2126 TXNPointToOffset(m_txn
, thePoint
, &theOffset
);
2128 wxString content
= GetStringValue() ;
2129 Point currentPoint
= thePoint
;
2130 while (thePoint
.v
== currentPoint
.v
&& theOffset
< content
.length())
2132 line
+= content
[theOffset
];
2133 TXNOffsetToPoint(m_txn
, ++theOffset
, ¤tPoint
);
2140 int wxMacMLTEControl::GetLineLength(long lineNo
) const
2144 if ( lineNo
< GetNumberOfLines() )
2147 Fixed lineWidth
, lineHeight
, currentHeight
;
2150 // get the first possible position in the control
2151 TXNOffsetToPoint(m_txn
, 0, &firstPoint
);
2153 // Iterate through the lines until we reach the one we want,
2154 // adding to our current y pixel point position
2157 while (ypos
< lineNo
)
2159 TXNGetLineMetrics(m_txn
, ypos
++, &lineWidth
, &lineHeight
);
2160 currentHeight
+= lineHeight
;
2163 Point thePoint
= { firstPoint
.v
+ (currentHeight
>> 16), firstPoint
.h
+ (0) };
2164 TXNOffset theOffset
;
2165 TXNPointToOffset(m_txn
, thePoint
, &theOffset
);
2167 wxString content
= GetStringValue() ;
2168 Point currentPoint
= thePoint
;
2169 while (thePoint
.v
== currentPoint
.v
&& theOffset
< content
.length())
2172 TXNOffsetToPoint(m_txn
, ++theOffset
, ¤tPoint
);
2179 // ----------------------------------------------------------------------------
2180 // MLTE control implementation (classic part)
2181 // ----------------------------------------------------------------------------
2183 // OS X Notes : We still don't have a full replacement for MLTE, so this implementation
2184 // has to live on. We have different problems coming from outdated implementations on the
2185 // various OS X versions. Most deal with the scrollbars: they are not correctly embedded
2186 // while this can be solved on 10.3 by reassigning them the correct place, on 10.2 there is
2187 // no way out, therefore we are using our own implementation and our own scrollbars ....
2189 #ifdef __WXMAC_OSX__
2191 TXNScrollInfoUPP gTXNScrollInfoProc
= NULL
;
2192 ControlActionUPP gTXNScrollActionProc
= NULL
;
2194 pascal void wxMacMLTEClassicControl::TXNScrollInfoProc(
2195 SInt32 iValue
, SInt32 iMaximumValue
,
2196 TXNScrollBarOrientation iScrollBarOrientation
, SInt32 iRefCon
)
2198 wxMacMLTEClassicControl
* mlte
= (wxMacMLTEClassicControl
*) iRefCon
;
2199 SInt32 value
= wxMax( iValue
, 0 ) ;
2200 SInt32 maximum
= wxMax( iMaximumValue
, 0 ) ;
2202 if ( iScrollBarOrientation
== kTXNHorizontal
)
2204 if ( mlte
->m_sbHorizontal
)
2206 SetControl32BitValue( mlte
->m_sbHorizontal
, value
) ;
2207 SetControl32BitMaximum( mlte
->m_sbHorizontal
, maximum
) ;
2208 mlte
->m_lastHorizontalValue
= value
;
2211 else if ( iScrollBarOrientation
== kTXNVertical
)
2213 if ( mlte
->m_sbVertical
)
2215 SetControl32BitValue( mlte
->m_sbVertical
, value
) ;
2216 SetControl32BitMaximum( mlte
->m_sbVertical
, maximum
) ;
2217 mlte
->m_lastVerticalValue
= value
;
2222 pascal void wxMacMLTEClassicControl::TXNScrollActionProc( ControlRef controlRef
, ControlPartCode partCode
)
2224 wxMacMLTEClassicControl
* mlte
= (wxMacMLTEClassicControl
*) GetControlReference( controlRef
) ;
2228 if ( controlRef
!= mlte
->m_sbVertical
&& controlRef
!= mlte
->m_sbHorizontal
)
2232 bool isHorizontal
= ( controlRef
== mlte
->m_sbHorizontal
) ;
2234 SInt32 minimum
= 0 ;
2235 SInt32 maximum
= GetControl32BitMaximum( controlRef
) ;
2236 SInt32 value
= GetControl32BitValue( controlRef
) ;
2242 case kControlDownButtonPart
:
2246 case kControlUpButtonPart
:
2250 case kControlPageDownPart
:
2251 delta
= GetControlViewSize( controlRef
) ;
2254 case kControlPageUpPart
:
2255 delta
= -GetControlViewSize( controlRef
) ;
2258 case kControlIndicatorPart
:
2259 delta
= value
- (isHorizontal
? mlte
->m_lastHorizontalValue
: mlte
->m_lastVerticalValue
) ;
2268 SInt32 newValue
= value
;
2270 if ( partCode
!= kControlIndicatorPart
)
2272 if ( value
+ delta
< minimum
)
2273 delta
= minimum
- value
;
2274 if ( value
+ delta
> maximum
)
2275 delta
= maximum
- value
;
2277 SetControl32BitValue( controlRef
, value
+ delta
) ;
2278 newValue
= value
+ delta
;
2281 SInt32 verticalDelta
= isHorizontal
? 0 : delta
;
2282 SInt32 horizontalDelta
= isHorizontal
? delta
: 0 ;
2285 mlte
->m_txn
, kTXNScrollUnitsInPixels
, kTXNScrollUnitsInPixels
,
2286 &verticalDelta
, &horizontalDelta
);
2289 mlte
->m_lastHorizontalValue
= newValue
;
2291 mlte
->m_lastVerticalValue
= newValue
;
2296 // make correct activations
2297 void wxMacMLTEClassicControl::MacActivatePaneText(bool setActive
)
2299 wxTextCtrl
* textctrl
= (wxTextCtrl
*) GetControlReference(m_controlRef
);
2301 wxMacWindowClipper
clipper( textctrl
) ;
2302 TXNActivate( m_txn
, m_txnFrameID
, setActive
);
2304 ControlRef controlFocus
= 0 ;
2305 GetKeyboardFocus( m_txnWindow
, &controlFocus
) ;
2306 if ( controlFocus
== m_controlRef
)
2307 TXNFocus( m_txn
, setActive
);
2310 void wxMacMLTEClassicControl::MacFocusPaneText(bool setFocus
)
2312 TXNFocus( m_txn
, setFocus
);
2315 // guards against inappropriate redraw (hidden objects drawing onto window)
2317 void wxMacMLTEClassicControl::MacSetObjectVisibility(bool vis
)
2319 ControlRef controlFocus
= 0 ;
2320 GetKeyboardFocus( m_txnWindow
, &controlFocus
) ;
2322 if ( !vis
&& (controlFocus
== m_controlRef
) )
2323 SetKeyboardFocus( m_txnWindow
, m_controlRef
, kControlFocusNoPart
) ;
2325 TXNControlTag iControlTags
[1] = { kTXNVisibilityTag
};
2326 TXNControlData iControlData
[1] = { { (UInt32
)false } };
2328 verify_noerr( TXNGetTXNObjectControls( m_txn
, 1, iControlTags
, iControlData
) ) ;
2330 if ( iControlData
[0].uValue
!= vis
)
2332 iControlData
[0].uValue
= vis
;
2333 verify_noerr( TXNSetTXNObjectControls( m_txn
, false , 1, iControlTags
, iControlData
) ) ;
2336 // currently, we always clip as partial visibility (overlapped) visibility is also a problem,
2337 // if we run into further problems we might set the FrameBounds to an empty rect here
2340 // make sure that the TXNObject is at the right position
2342 void wxMacMLTEClassicControl::MacUpdatePosition()
2344 wxTextCtrl
* textctrl
= (wxTextCtrl
*)GetControlReference( m_controlRef
);
2345 if ( textctrl
== NULL
)
2349 UMAGetControlBoundsInWindowCoords( m_controlRef
, &bounds
);
2351 wxRect visRect
= textctrl
->MacGetClippedClientRect() ;
2352 Rect visBounds
= { visRect
.y
, visRect
.x
, visRect
.y
+ visRect
.height
, visRect
.x
+ visRect
.width
} ;
2355 textctrl
->MacWindowToRootWindow( &x
, &y
) ;
2356 OffsetRect( &visBounds
, x
, y
) ;
2358 if ( !EqualRect( &bounds
, &m_txnControlBounds
) || !EqualRect( &visBounds
, &m_txnVisBounds
) )
2360 m_txnControlBounds
= bounds
;
2361 m_txnVisBounds
= visBounds
;
2362 wxMacWindowClipper
cl( textctrl
) ;
2364 #ifdef __WXMAC_OSX__
2365 bool isCompositing
= textctrl
->MacGetTopLevelWindow()->MacUsesCompositing() ;
2366 if ( m_sbHorizontal
|| m_sbVertical
)
2368 int w
= bounds
.right
- bounds
.left
;
2369 int h
= bounds
.bottom
- bounds
.top
;
2371 if ( m_sbHorizontal
)
2375 sbBounds
.left
= -1 ;
2376 sbBounds
.top
= h
- 14 ;
2377 sbBounds
.right
= w
+ 1 ;
2378 sbBounds
.bottom
= h
+ 1 ;
2380 if ( !isCompositing
)
2381 OffsetRect( &sbBounds
, m_txnControlBounds
.left
, m_txnControlBounds
.top
) ;
2383 SetControlBounds( m_sbHorizontal
, &sbBounds
) ;
2384 SetControlViewSize( m_sbHorizontal
, w
) ;
2391 sbBounds
.left
= w
- 14 ;
2393 sbBounds
.right
= w
+ 1 ;
2394 sbBounds
.bottom
= m_sbHorizontal
? h
- 14 : h
+ 1 ;
2396 if ( !isCompositing
)
2397 OffsetRect( &sbBounds
, m_txnControlBounds
.left
, m_txnControlBounds
.top
) ;
2399 SetControlBounds( m_sbVertical
, &sbBounds
) ;
2400 SetControlViewSize( m_sbVertical
, h
) ;
2405 TXNLongRect olddestRect
;
2406 TXNGetRectBounds( m_txn
, &oldviewRect
, &olddestRect
, NULL
) ;
2408 Rect viewRect
= { m_txnControlBounds
.top
, m_txnControlBounds
.left
,
2409 m_txnControlBounds
.bottom
- ( m_sbHorizontal
? 14 : 0 ) ,
2410 m_txnControlBounds
.right
- ( m_sbVertical
? 14 : 0 ) } ;
2411 TXNLongRect destRect
= { m_txnControlBounds
.top
, m_txnControlBounds
.left
,
2412 m_txnControlBounds
.bottom
- ( m_sbHorizontal
? 14 : 0 ) ,
2413 m_txnControlBounds
.right
- ( m_sbVertical
? 14 : 0 ) } ;
2415 if ( olddestRect
.right
>= 10000 )
2416 destRect
.right
= destRect
.left
+ 32000 ;
2418 if ( olddestRect
.bottom
>= 0x20000000 )
2419 destRect
.bottom
= destRect
.top
+ 0x40000000 ;
2421 SectRect( &viewRect
, &visBounds
, &viewRect
) ;
2422 TXNSetRectBounds( m_txn
, &viewRect
, &destRect
, true ) ;
2427 m_txnControlBounds
.top
,
2428 m_txnControlBounds
.left
,
2429 m_txnControlBounds
.bottom
- (m_sbHorizontal
? 14 : 0),
2430 m_txnControlBounds
.right
- (m_sbVertical
? 14 : 0),
2436 m_txn
, m_txnControlBounds
.top
, m_txnControlBounds
.left
,
2437 wxMax( m_txnControlBounds
.bottom
, m_txnControlBounds
.top
),
2438 wxMax( m_txnControlBounds
.right
, m_txnControlBounds
.left
), m_txnFrameID
);
2441 // the SetFrameBounds method under Classic sometimes does not correctly scroll a selection into sight after a
2442 // movement, therefore we have to force it
2444 // this problem has been reported in OSX as well, so we use this here once again
2446 TXNLongRect textRect
;
2447 TXNGetRectBounds( m_txn
, NULL
, NULL
, &textRect
) ;
2448 if ( textRect
.left
< m_txnControlBounds
.left
)
2449 TXNShowSelection( m_txn
, kTXNShowStart
) ;
2453 void wxMacMLTEClassicControl::SetRect( Rect
*r
)
2455 wxMacControl::SetRect( r
) ;
2456 MacUpdatePosition() ;
2459 void wxMacMLTEClassicControl::MacControlUserPaneDrawProc(wxInt16 thePart
)
2461 wxTextCtrl
* textctrl
= (wxTextCtrl
*)GetControlReference( m_controlRef
);
2462 if ( textctrl
== NULL
)
2465 if ( textctrl
->MacIsReallyShown() )
2467 wxMacWindowClipper
clipper( textctrl
) ;
2468 TXNDraw( m_txn
, NULL
) ;
2472 wxInt16
wxMacMLTEClassicControl::MacControlUserPaneHitTestProc(wxInt16 x
, wxInt16 y
)
2474 Point where
= { y
, x
} ;
2475 ControlPartCode result
= kControlNoPart
;
2477 wxTextCtrl
* textctrl
= (wxTextCtrl
*) GetControlReference( m_controlRef
);
2478 if ( (textctrl
!= NULL
) && textctrl
->MacIsReallyShown() )
2480 if (PtInRect( where
, &m_txnControlBounds
))
2482 result
= kControlEditTextPart
;
2486 // sometimes we get the coords also in control local coordinates, therefore test again
2487 if ( textctrl
->MacGetTopLevelWindow()->MacUsesCompositing() )
2490 textctrl
->MacClientToRootWindow( &x
, &y
) ;
2495 if (PtInRect( where
, &m_txnControlBounds
))
2496 result
= kControlEditTextPart
;
2503 wxInt16
wxMacMLTEClassicControl::MacControlUserPaneTrackingProc( wxInt16 x
, wxInt16 y
, void* actionProc
)
2505 ControlPartCode result
= kControlNoPart
;
2507 wxTextCtrl
* textctrl
= (wxTextCtrl
*) GetControlReference( m_controlRef
);
2508 if ( (textctrl
!= NULL
) && textctrl
->MacIsReallyShown() )
2510 Point startPt
= { y
, x
} ;
2511 // for compositing, we must convert these into toplevel window coordinates, because hittesting expects them
2512 if ( textctrl
->MacGetTopLevelWindow()->MacUsesCompositing() )
2515 textctrl
->MacClientToRootWindow( &x
, &y
) ;
2520 switch (MacControlUserPaneHitTestProc( startPt
.h
, startPt
.v
))
2522 case kControlEditTextPart
:
2524 wxMacWindowClipper
clipper( textctrl
) ;
2527 ConvertEventRefToEventRecord( (EventRef
) wxTheApp
->MacGetCurrentEvent() , &rec
) ;
2528 TXNClick( m_txn
, &rec
);
2540 void wxMacMLTEClassicControl::MacControlUserPaneIdleProc()
2542 wxTextCtrl
* textctrl
= (wxTextCtrl
*)GetControlReference( m_controlRef
);
2543 if ( textctrl
== NULL
)
2546 if (textctrl
->MacIsReallyShown())
2548 if (IsControlActive(m_controlRef
))
2552 wxMacWindowClipper
clipper( textctrl
) ;
2557 if (PtInRect(mousep
, &m_txnControlBounds
))
2559 RgnHandle theRgn
= NewRgn();
2560 RectRgn(theRgn
, &m_txnControlBounds
);
2561 TXNAdjustCursor(m_txn
, theRgn
);
2568 wxInt16
wxMacMLTEClassicControl::MacControlUserPaneKeyDownProc (wxInt16 keyCode
, wxInt16 charCode
, wxInt16 modifiers
)
2570 wxTextCtrl
* textctrl
= (wxTextCtrl
*)GetControlReference( m_controlRef
);
2571 if ( textctrl
== NULL
)
2572 return kControlNoPart
;
2574 wxMacWindowClipper
clipper( textctrl
) ;
2577 memset( &ev
, 0 , sizeof( ev
) ) ;
2579 ev
.modifiers
= modifiers
;
2580 ev
.message
= ((keyCode
<< 8) & keyCodeMask
) | (charCode
& charCodeMask
);
2581 TXNKeyDown( m_txn
, &ev
);
2583 return kControlEntireControl
;
2586 void wxMacMLTEClassicControl::MacControlUserPaneActivateProc(bool activating
)
2588 MacActivatePaneText( activating
);
2591 wxInt16
wxMacMLTEClassicControl::MacControlUserPaneFocusProc(wxInt16 action
)
2593 ControlPartCode focusResult
= kControlFocusNoPart
;
2595 wxTextCtrl
* textctrl
= (wxTextCtrl
*)GetControlReference( m_controlRef
);
2596 if ( textctrl
== NULL
)
2599 wxMacWindowClipper
clipper( textctrl
) ;
2601 ControlRef controlFocus
= NULL
;
2602 GetKeyboardFocus( m_txnWindow
, &controlFocus
) ;
2603 bool wasFocused
= ( controlFocus
== m_controlRef
) ;
2607 case kControlFocusPrevPart
:
2608 case kControlFocusNextPart
:
2609 MacFocusPaneText( !wasFocused
);
2610 focusResult
= (!wasFocused
? (ControlPartCode
) kControlEditTextPart
: (ControlPartCode
) kControlFocusNoPart
);
2613 case kControlFocusNoPart
:
2615 MacFocusPaneText( false );
2616 focusResult
= kControlFocusNoPart
;
2623 void wxMacMLTEClassicControl::MacControlUserPaneBackgroundProc( void *info
)
2627 wxMacMLTEClassicControl::wxMacMLTEClassicControl( wxTextCtrl
*wxPeer
,
2628 const wxString
& str
,
2630 const wxSize
& size
, long style
) : wxMacMLTEControl( wxPeer
)
2632 m_font
= wxPeer
->GetFont() ;
2633 m_windowStyle
= style
;
2634 Rect bounds
= wxMacGetBoundsForControl( wxPeer
, pos
, size
) ;
2637 kControlSupportsEmbedding
| kControlSupportsFocus
| kControlWantsIdle
2638 | kControlWantsActivate
| kControlHandlesTracking
2639 // | kControlHasSpecialBackground
2640 | kControlGetsFocusOnClick
| kControlSupportsLiveFeedback
;
2643 ::CreateUserPaneControl(
2644 MAC_WXHWND(wxPeer
->GetParent()->MacGetTopLevelWindowRef()),
2645 &bounds
, featureSet
, &m_controlRef
) );
2649 AdjustCreationAttributes( *wxWHITE
, true ) ;
2651 MacSetObjectVisibility( wxPeer
->MacIsReallyShown() ) ;
2655 wxMacConvertNewlines10To13( &st
) ;
2656 wxMacWindowClipper
clipper( m_peer
) ;
2657 SetTXNData( st
, kTXNStartOffset
, kTXNEndOffset
) ;
2658 TXNSetSelection( m_txn
, 0, 0 ) ;
2662 wxMacMLTEClassicControl::~wxMacMLTEClassicControl()
2664 TXNDeleteObject( m_txn
);
2668 void wxMacMLTEClassicControl::VisibilityChanged(bool shown
)
2670 MacSetObjectVisibility( shown
) ;
2671 wxMacControl::VisibilityChanged( shown
) ;
2674 void wxMacMLTEClassicControl::SuperChangedPosition()
2676 MacUpdatePosition() ;
2677 wxMacControl::SuperChangedPosition() ;
2680 #ifdef __WXMAC_OSX__
2682 ControlUserPaneDrawUPP gTPDrawProc
= NULL
;
2683 ControlUserPaneHitTestUPP gTPHitProc
= NULL
;
2684 ControlUserPaneTrackingUPP gTPTrackProc
= NULL
;
2685 ControlUserPaneIdleUPP gTPIdleProc
= NULL
;
2686 ControlUserPaneKeyDownUPP gTPKeyProc
= NULL
;
2687 ControlUserPaneActivateUPP gTPActivateProc
= NULL
;
2688 ControlUserPaneFocusUPP gTPFocusProc
= NULL
;
2690 static pascal void wxMacControlUserPaneDrawProc(ControlRef control
, SInt16 part
)
2692 wxTextCtrl
*textCtrl
= wxDynamicCast( wxFindControlFromMacControl(control
) , wxTextCtrl
) ;
2693 wxMacMLTEClassicControl
* win
= textCtrl
? (wxMacMLTEClassicControl
*)(textCtrl
->GetPeer()) : NULL
;
2695 win
->MacControlUserPaneDrawProc(part
) ;
2698 static pascal ControlPartCode
wxMacControlUserPaneHitTestProc(ControlRef control
, Point where
)
2700 wxTextCtrl
*textCtrl
= wxDynamicCast( wxFindControlFromMacControl(control
) , wxTextCtrl
) ;
2701 wxMacMLTEClassicControl
* win
= textCtrl
? (wxMacMLTEClassicControl
*)(textCtrl
->GetPeer()) : NULL
;
2703 return win
->MacControlUserPaneHitTestProc(where
.h
, where
.v
) ;
2705 return kControlNoPart
;
2708 static pascal ControlPartCode
wxMacControlUserPaneTrackingProc(ControlRef control
, Point startPt
, ControlActionUPP actionProc
)
2710 wxTextCtrl
*textCtrl
= wxDynamicCast( wxFindControlFromMacControl(control
) , wxTextCtrl
) ;
2711 wxMacMLTEClassicControl
* win
= textCtrl
? (wxMacMLTEClassicControl
*)(textCtrl
->GetPeer()) : NULL
;
2713 return win
->MacControlUserPaneTrackingProc( startPt
.h
, startPt
.v
, (void*) actionProc
) ;
2715 return kControlNoPart
;
2718 static pascal void wxMacControlUserPaneIdleProc(ControlRef control
)
2720 wxTextCtrl
*textCtrl
= wxDynamicCast( wxFindControlFromMacControl(control
) , wxTextCtrl
) ;
2721 wxMacMLTEClassicControl
* win
= textCtrl
? (wxMacMLTEClassicControl
*)(textCtrl
->GetPeer()) : NULL
;
2723 win
->MacControlUserPaneIdleProc() ;
2726 static pascal ControlPartCode
wxMacControlUserPaneKeyDownProc(ControlRef control
, SInt16 keyCode
, SInt16 charCode
, SInt16 modifiers
)
2728 wxTextCtrl
*textCtrl
= wxDynamicCast( wxFindControlFromMacControl(control
) , wxTextCtrl
) ;
2729 wxMacMLTEClassicControl
* win
= textCtrl
? (wxMacMLTEClassicControl
*)(textCtrl
->GetPeer()) : NULL
;
2731 return win
->MacControlUserPaneKeyDownProc(keyCode
,charCode
,modifiers
) ;
2733 return kControlNoPart
;
2736 static pascal void wxMacControlUserPaneActivateProc(ControlRef control
, Boolean activating
)
2738 wxTextCtrl
*textCtrl
= wxDynamicCast( wxFindControlFromMacControl(control
) , wxTextCtrl
) ;
2739 wxMacMLTEClassicControl
* win
= textCtrl
? (wxMacMLTEClassicControl
*)(textCtrl
->GetPeer()) : NULL
;
2741 win
->MacControlUserPaneActivateProc(activating
) ;
2744 static pascal ControlPartCode
wxMacControlUserPaneFocusProc(ControlRef control
, ControlFocusPart action
)
2746 wxTextCtrl
*textCtrl
= wxDynamicCast( wxFindControlFromMacControl(control
) , wxTextCtrl
) ;
2747 wxMacMLTEClassicControl
* win
= textCtrl
? (wxMacMLTEClassicControl
*)(textCtrl
->GetPeer()) : NULL
;
2749 return win
->MacControlUserPaneFocusProc(action
) ;
2751 return kControlNoPart
;
2755 static pascal void wxMacControlUserPaneBackgroundProc(ControlRef control
, ControlBackgroundPtr info
)
2757 wxTextCtrl
*textCtrl
= wxDynamicCast( wxFindControlFromMacControl(control
) , wxTextCtrl
) ;
2758 wxMacMLTEClassicControl
* win
= textCtrl
? (wxMacMLTEClassicControl
*)(textCtrl
->GetPeer()) : NULL
;
2760 win
->MacControlUserPaneBackgroundProc(info
) ;
2764 #endif // __WXMAC_OSX__
2766 // TXNRegisterScrollInfoProc
2768 OSStatus
wxMacMLTEClassicControl::DoCreate()
2772 OSStatus err
= noErr
;
2774 // set up our globals
2775 #ifdef __WXMAC_OSX__
2776 if (gTPDrawProc
== NULL
) gTPDrawProc
= NewControlUserPaneDrawUPP(wxMacControlUserPaneDrawProc
);
2777 if (gTPHitProc
== NULL
) gTPHitProc
= NewControlUserPaneHitTestUPP(wxMacControlUserPaneHitTestProc
);
2778 if (gTPTrackProc
== NULL
) gTPTrackProc
= NewControlUserPaneTrackingUPP(wxMacControlUserPaneTrackingProc
);
2779 if (gTPIdleProc
== NULL
) gTPIdleProc
= NewControlUserPaneIdleUPP(wxMacControlUserPaneIdleProc
);
2780 if (gTPKeyProc
== NULL
) gTPKeyProc
= NewControlUserPaneKeyDownUPP(wxMacControlUserPaneKeyDownProc
);
2781 if (gTPActivateProc
== NULL
) gTPActivateProc
= NewControlUserPaneActivateUPP(wxMacControlUserPaneActivateProc
);
2782 if (gTPFocusProc
== NULL
) gTPFocusProc
= NewControlUserPaneFocusUPP(wxMacControlUserPaneFocusProc
);
2784 if (gTXNScrollInfoProc
== NULL
) gTXNScrollInfoProc
= NewTXNScrollInfoUPP(TXNScrollInfoProc
) ;
2785 if (gTXNScrollActionProc
== NULL
) gTXNScrollActionProc
= NewControlActionUPP(TXNScrollActionProc
) ;
2788 // set the initial settings for our private data
2790 m_txnWindow
= GetControlOwner(m_controlRef
);
2791 m_txnPort
= (GrafPtr
) GetWindowPort(m_txnWindow
);
2793 #ifdef __WXMAC_OSX__
2794 // set up the user pane procedures
2795 SetControlData(m_controlRef
, kControlEntireControl
, kControlUserPaneDrawProcTag
, sizeof(gTPDrawProc
), &gTPDrawProc
);
2796 SetControlData(m_controlRef
, kControlEntireControl
, kControlUserPaneHitTestProcTag
, sizeof(gTPHitProc
), &gTPHitProc
);
2797 SetControlData(m_controlRef
, kControlEntireControl
, kControlUserPaneTrackingProcTag
, sizeof(gTPTrackProc
), &gTPTrackProc
);
2798 SetControlData(m_controlRef
, kControlEntireControl
, kControlUserPaneIdleProcTag
, sizeof(gTPIdleProc
), &gTPIdleProc
);
2799 SetControlData(m_controlRef
, kControlEntireControl
, kControlUserPaneKeyDownProcTag
, sizeof(gTPKeyProc
), &gTPKeyProc
);
2800 SetControlData(m_controlRef
, kControlEntireControl
, kControlUserPaneActivateProcTag
, sizeof(gTPActivateProc
), &gTPActivateProc
);
2801 SetControlData(m_controlRef
, kControlEntireControl
, kControlUserPaneFocusProcTag
, sizeof(gTPFocusProc
), &gTPFocusProc
);
2804 // calculate the rectangles used by the control
2805 UMAGetControlBoundsInWindowCoords( m_controlRef
, &bounds
);
2807 m_txnControlBounds
= bounds
;
2808 m_txnVisBounds
= bounds
;
2813 GetGWorld( &origPort
, &origDev
) ;
2814 SetPort( m_txnPort
);
2816 // create the new edit field
2817 TXNFrameOptions frameOptions
= FrameOptionsFromWXStyle( m_windowStyle
);
2819 #ifdef __WXMAC_OSX__
2820 // the scrollbars are not correctly embedded but are inserted at the root:
2821 // this gives us problems as we have erratic redraws even over the structure area
2823 m_sbHorizontal
= 0 ;
2825 m_lastHorizontalValue
= 0 ;
2826 m_lastVerticalValue
= 0 ;
2828 Rect sb
= { 0 , 0 , 0 , 0 } ;
2829 if ( frameOptions
& kTXNWantVScrollBarMask
)
2831 CreateScrollBarControl( m_txnWindow
, &sb
, 0, 0, 100, 1, true, gTXNScrollActionProc
, &m_sbVertical
);
2832 SetControlReference( m_sbVertical
, (SInt32
)this );
2833 SetControlAction( m_sbVertical
, gTXNScrollActionProc
);
2834 ShowControl( m_sbVertical
);
2835 EmbedControl( m_sbVertical
, m_controlRef
);
2836 frameOptions
&= ~kTXNWantVScrollBarMask
;
2839 if ( frameOptions
& kTXNWantHScrollBarMask
)
2841 CreateScrollBarControl( m_txnWindow
, &sb
, 0, 0, 100, 1, true, gTXNScrollActionProc
, &m_sbHorizontal
);
2842 SetControlReference( m_sbHorizontal
, (SInt32
)this );
2843 SetControlAction( m_sbHorizontal
, gTXNScrollActionProc
);
2844 ShowControl( m_sbHorizontal
);
2845 EmbedControl( m_sbHorizontal
, m_controlRef
);
2846 frameOptions
&= ~(kTXNWantHScrollBarMask
| kTXNDrawGrowIconMask
);
2853 NULL
, m_txnWindow
, &bounds
, frameOptions
,
2854 kTXNTextEditStyleFrameType
, kTXNTextensionFile
, kTXNSystemDefaultEncoding
,
2855 &m_txn
, &m_txnFrameID
, NULL
) );
2858 TXNControlTag iControlTags
[] = { kTXNUseCarbonEvents
};
2859 TXNControlData iControlData
[] = { { (UInt32
)&cInfo
} };
2860 int toptag
= WXSIZEOF( iControlTags
) ;
2861 TXNCarbonEventInfo cInfo
;
2862 cInfo
.useCarbonEvents
= false ;
2865 cInfo
.fDictionary
= NULL
;
2867 verify_noerr( TXNSetTXNObjectControls( m_txn
, false, toptag
, iControlTags
, iControlData
) );
2870 #ifdef __WXMAC_OSX__
2871 TXNRegisterScrollInfoProc( m_txn
, gTXNScrollInfoProc
, (SInt32
)this );
2874 SetGWorld( origPort
, origDev
) ;
2878 // ----------------------------------------------------------------------------
2879 // MLTE control implementation (OSX part)
2880 // ----------------------------------------------------------------------------
2882 #if TARGET_API_MAC_OSX
2884 #if MAC_OS_X_VERSION_MAX_ALLOWED > MAC_OS_X_VERSION_10_2
2886 wxMacMLTEHIViewControl::wxMacMLTEHIViewControl( wxTextCtrl
*wxPeer
,
2887 const wxString
& str
,
2889 const wxSize
& size
, long style
) : wxMacMLTEControl( wxPeer
)
2891 m_font
= wxPeer
->GetFont() ;
2892 m_windowStyle
= style
;
2893 Rect bounds
= wxMacGetBoundsForControl( wxPeer
, pos
, size
) ;
2895 wxMacConvertNewlines10To13( &st
) ;
2897 HIRect hr
= { { bounds
.left
, bounds
.top
} ,
2898 { bounds
.right
- bounds
.left
, bounds
.bottom
- bounds
.top
} } ;
2900 m_scrollView
= NULL
;
2901 TXNFrameOptions frameOptions
= FrameOptionsFromWXStyle( style
) ;
2902 if ( frameOptions
& (kTXNWantVScrollBarMask
| kTXNWantHScrollBarMask
) )
2905 (frameOptions
& kTXNWantHScrollBarMask
? kHIScrollViewOptionsHorizScroll
: 0)
2906 | (frameOptions
& kTXNWantVScrollBarMask
? kHIScrollViewOptionsVertScroll
: 0) ,
2909 HIViewSetFrame( m_scrollView
, &hr
);
2910 HIViewSetVisible( m_scrollView
, true );
2914 HITextViewCreate( NULL
, 0, frameOptions
, &m_textView
) ;
2915 m_txn
= HITextViewGetTXNObject( m_textView
) ;
2916 HIViewSetVisible( m_textView
, true ) ;
2919 HIViewAddSubview( m_scrollView
, m_textView
) ;
2920 m_controlRef
= m_scrollView
;
2921 wxPeer
->MacInstallEventHandler( (WXWidget
) m_textView
) ;
2925 HIViewSetFrame( m_textView
, &hr
);
2926 m_controlRef
= m_textView
;
2929 AdjustCreationAttributes( *wxWHITE
, true ) ;
2931 wxMacWindowClipper
c( m_peer
) ;
2932 SetTXNData( st
, kTXNStartOffset
, kTXNEndOffset
) ;
2934 TXNSetSelection( m_txn
, 0, 0 );
2935 TXNShowSelection( m_txn
, kTXNShowStart
);
2938 OSStatus
wxMacMLTEHIViewControl::SetFocus( ControlFocusPart focusPart
)
2940 return SetKeyboardFocus( GetControlOwner( m_textView
), m_textView
, focusPart
) ;
2943 bool wxMacMLTEHIViewControl::HasFocus() const
2945 ControlRef control
;
2946 GetKeyboardFocus( GetUserFocusWindow() , &control
) ;
2947 return control
== m_textView
;
2950 void wxMacMLTEHIViewControl::SetBackground( const wxBrush
&brush
)
2952 wxMacMLTEControl::SetBackground( brush
) ;
2955 CGColorSpaceRef rgbSpace
= CGColorSpaceCreateDeviceRGB();
2956 RGBColor col
= MAC_WXCOLORREF(brush
.GetColour().GetPixel()) ;
2958 float component
[4] ;
2959 component
[0] = col
.red
/ 65536.0 ;
2960 component
[1] = col
.green
/ 65536.0 ;
2961 component
[2] = col
.blue
/ 65536.0 ;
2962 component
[3] = 1.0 ; // alpha
2964 CGColorRef color
= CGColorCreate (rgbSpace
, component
);
2965 HITextViewSetBackgroundColor( m_textView
, color
) ;
2966 CGColorSpaceRelease( rgbSpace
);
2970 #endif // MAC_OS_X_VERSION_MAX_ALLOWED > MAC_OS_X_VERSION_10_2
2975 #endif // wxUSE_TEXTCTRL