1 /////////////////////////////////////////////////////////////////////////////
2 // Name: src/mac/carbon/textctrl.cpp
4 // Author: Stefan Csomor
5 // Modified by: Ryan Norton (MLTE GetLineLength and GetLineText)
8 // Copyright: (c) Stefan Csomor
9 // Licence: wxWindows licence
10 /////////////////////////////////////////////////////////////////////////////
12 #include "wx/wxprec.h"
16 #include "wx/textctrl.h"
23 #include "wx/button.h"
25 #include "wx/settings.h"
26 #include "wx/msgdlg.h"
27 #include "wx/toplevel.h"
31 #include <sys/types.h>
37 #if wxUSE_STD_IOSTREAM
45 #include "wx/filefn.h"
46 #include "wx/sysopt.h"
47 #include "wx/thread.h"
49 #include "wx/mac/uma.h"
50 #include "wx/mac/carbon/private/mactext.h"
56 virtual ~wxMacFunctor() {}
58 virtual void* operator()() = 0 ;
60 static void* CallBackProc( void *param
)
62 wxMacFunctor
* f
= (wxMacFunctor
*) param
;
63 void *result
= (*f
)() ;
68 template<typename classtype
, typename param1type
>
70 class wxMacObjectFunctor1
: public wxMacFunctor
72 typedef void (classtype::*function
)( param1type p1
) ;
73 typedef void (classtype::*ref_function
)( const param1type
& p1
) ;
75 wxMacObjectFunctor1( classtype
*obj
, function f
, param1type p1
) :
83 wxMacObjectFunctor1( classtype
*obj
, ref_function f
, param1type p1
) :
91 virtual ~wxMacObjectFunctor1() {}
93 virtual void* operator()()
95 (m_object
->*m_function
)( m_param1
) ;
100 classtype
* m_object
;
101 param1type m_param1
;
104 function m_function
;
105 ref_function m_refFunction
;
109 template<typename classtype
, typename param1type
>
110 void* wxMacMPRemoteCall( classtype
*object
, void (classtype::*function
)( param1type p1
) , param1type p1
)
112 wxMacObjectFunctor1
<classtype
, param1type
> params(object
, function
, p1
) ;
114 MPRemoteCall( wxMacFunctor::CallBackProc
, ¶ms
, kMPOwningProcessRemoteContext
) ;
118 template<typename classtype
, typename param1type
>
119 void* wxMacMPRemoteCall( classtype
*object
, void (classtype::*function
)( const param1type
& p1
) , param1type p1
)
121 wxMacObjectFunctor1
<classtype
,param1type
> params(object
, function
, p1
) ;
123 MPRemoteCall( wxMacFunctor::CallBackProc
, ¶ms
, kMPOwningProcessRemoteContext
) ;
127 template<typename classtype
, typename param1type
>
128 void* wxMacMPRemoteGUICall( classtype
*object
, void (classtype::*function
)( param1type p1
) , param1type p1
)
131 void *result
= wxMacMPRemoteCall( object
, function
, p1
) ;
136 template<typename classtype
, typename param1type
>
137 void* wxMacMPRemoteGUICall( classtype
*object
, void (classtype::*function
)( const param1type
& p1
) , param1type p1
)
140 void *result
= wxMacMPRemoteCall( object
, function
, p1
) ;
145 class WXDLLEXPORT wxMacPortSaver
147 DECLARE_NO_COPY_CLASS(wxMacPortSaver
)
150 wxMacPortSaver( GrafPtr port
);
158 Clips to the visible region of a control within the current port
161 class WXDLLEXPORT wxMacWindowClipper
: public wxMacPortSaver
163 DECLARE_NO_COPY_CLASS(wxMacWindowClipper
)
166 wxMacWindowClipper( const wxWindow
* win
);
167 ~wxMacWindowClipper();
170 RgnHandle m_formerClip
;
174 wxMacPortSaver::wxMacPortSaver( GrafPtr port
)
176 ::GetPort( &m_port
);
180 wxMacPortSaver::~wxMacPortSaver()
185 wxMacWindowClipper::wxMacWindowClipper( const wxWindow
* win
) :
186 wxMacPortSaver( (GrafPtr
) GetWindowPort( (WindowRef
) win
->MacGetTopLevelWindowRef() ) )
188 m_newPort
= (GrafPtr
) GetWindowPort( (WindowRef
) win
->MacGetTopLevelWindowRef() ) ;
189 m_formerClip
= NewRgn() ;
190 m_newClip
= NewRgn() ;
191 GetClip( m_formerClip
) ;
195 // guard against half constructed objects, this just leads to a empty clip
196 if ( win
->GetPeer() )
199 win
->MacWindowToRootWindow( &x
, &y
) ;
201 // get area including focus rect
202 HIShapeGetAsQDRgn( ((wxWindow
*)win
)->MacGetVisibleRegion(true).GetWXHRGN() , m_newClip
);
203 if ( !EmptyRgn( m_newClip
) )
204 OffsetRgn( m_newClip
, x
, y
) ;
207 SetClip( m_newClip
) ;
211 wxMacWindowClipper::~wxMacWindowClipper()
213 SetPort( m_newPort
) ;
214 SetClip( m_formerClip
) ;
215 DisposeRgn( m_newClip
) ;
216 DisposeRgn( m_formerClip
) ;
219 // common parts for implementations based on MLTE
221 class wxMacMLTEControl
: public wxMacTextControl
224 wxMacMLTEControl( wxTextCtrl
*peer
) ;
226 virtual wxString
GetStringValue() const ;
227 virtual void SetStringValue( const wxString
&str
) ;
229 static TXNFrameOptions
FrameOptionsFromWXStyle( long wxStyle
) ;
231 void AdjustCreationAttributes( const wxColour
& background
, bool visible
) ;
233 virtual void SetFont( const wxFont
& font
, const wxColour
& foreground
, long windowStyle
) ;
234 virtual void SetBackgroundColour(const wxColour
& col
);
235 virtual void SetStyle( long start
, long end
, const wxTextAttr
& style
) ;
236 virtual void Copy() ;
238 virtual void Paste() ;
239 virtual bool CanPaste() const ;
240 virtual void SetEditable( bool editable
) ;
241 virtual wxTextPos
GetLastPosition() const ;
242 virtual void Replace( long from
, long to
, const wxString
&str
) ;
243 virtual void Remove( long from
, long to
) ;
244 virtual void GetSelection( long* from
, long* to
) const ;
245 virtual void SetSelection( long from
, long to
) ;
247 virtual void WriteText( const wxString
& str
) ;
249 virtual bool HasOwnContextMenu() const
251 TXNCommandEventSupportOptions options
;
252 TXNGetCommandEventSupport( m_txn
, & options
) ;
253 return options
& kTXNSupportEditCommandProcessing
;
256 virtual void CheckSpelling(bool check
)
258 TXNSetSpellCheckAsYouType( m_txn
, (Boolean
) check
);
260 virtual void Clear() ;
262 virtual bool CanUndo() const ;
263 virtual void Undo() ;
264 virtual bool CanRedo() const;
265 virtual void Redo() ;
266 virtual int GetNumberOfLines() const ;
267 virtual long XYToPosition(long x
, long y
) const ;
268 virtual bool PositionToXY(long pos
, long *x
, long *y
) const ;
269 virtual void ShowPosition( long pos
) ;
270 virtual int GetLineLength(long lineNo
) const ;
271 virtual wxString
GetLineText(long lineNo
) const ;
273 void SetTXNData( const wxString
& st
, TXNOffset start
, TXNOffset end
) ;
274 TXNObject
GetTXNObject() { return m_txn
; }
277 void TXNSetAttribute( const wxTextAttr
& style
, long from
, long to
) ;
282 // implementation available under OSX
284 class wxMacMLTEHIViewControl
: public wxMacMLTEControl
287 wxMacMLTEHIViewControl( wxTextCtrl
*wxPeer
,
290 const wxSize
& size
, long style
) ;
291 virtual ~wxMacMLTEHIViewControl() ;
293 virtual OSStatus
SetFocus( ControlFocusPart focusPart
) ;
294 virtual bool HasFocus() const ;
295 virtual void SetBackgroundColour(const wxColour
& col
) ;
298 HIViewRef m_scrollView
;
299 HIViewRef m_textView
;
302 // 'classic' MLTE implementation
304 class wxMacMLTEClassicControl
: public wxMacMLTEControl
307 wxMacMLTEClassicControl( wxTextCtrl
*wxPeer
,
310 const wxSize
& size
, long style
) ;
311 virtual ~wxMacMLTEClassicControl() ;
313 virtual void VisibilityChanged(bool shown
) ;
314 virtual void SuperChangedPosition() ;
316 virtual void MacControlUserPaneDrawProc(wxInt16 part
) ;
317 virtual wxInt16
MacControlUserPaneHitTestProc(wxInt16 x
, wxInt16 y
) ;
318 virtual wxInt16
MacControlUserPaneTrackingProc(wxInt16 x
, wxInt16 y
, void* actionProc
) ;
319 virtual void MacControlUserPaneIdleProc() ;
320 virtual wxInt16
MacControlUserPaneKeyDownProc(wxInt16 keyCode
, wxInt16 charCode
, wxInt16 modifiers
) ;
321 virtual void MacControlUserPaneActivateProc(bool activating
) ;
322 virtual wxInt16
MacControlUserPaneFocusProc(wxInt16 action
) ;
323 virtual void MacControlUserPaneBackgroundProc(void* info
) ;
325 virtual bool SetupCursor( const wxPoint
& WXUNUSED(pt
) )
327 MacControlUserPaneIdleProc();
331 virtual void SetRect( Rect
*r
) ;
336 void MacUpdatePosition() ;
337 void MacActivatePaneText(bool setActive
) ;
338 void MacFocusPaneText(bool setFocus
) ;
339 void MacSetObjectVisibility(bool vis
) ;
342 TXNFrameID m_txnFrameID
;
344 WindowRef m_txnWindow
;
345 // bounds of the control as we last did set the txn frames
346 Rect m_txnControlBounds
;
347 Rect m_txnVisBounds
;
349 static pascal void TXNScrollActionProc( ControlRef controlRef
, ControlPartCode partCode
) ;
350 static pascal void TXNScrollInfoProc(
351 SInt32 iValue
, SInt32 iMaximumValue
,
352 TXNScrollBarOrientation iScrollBarOrientation
, SInt32 iRefCon
) ;
354 ControlRef m_sbHorizontal
;
355 SInt32 m_lastHorizontalValue
;
356 ControlRef m_sbVertical
;
357 SInt32 m_lastVerticalValue
;
361 IMPLEMENT_DYNAMIC_CLASS(wxTextCtrl
, wxTextCtrlBase
)
363 BEGIN_EVENT_TABLE(wxTextCtrl
, wxTextCtrlBase
)
364 EVT_DROP_FILES(wxTextCtrl::OnDropFiles
)
365 EVT_CHAR(wxTextCtrl::OnChar
)
366 EVT_MENU(wxID_CUT
, wxTextCtrl::OnCut
)
367 EVT_MENU(wxID_COPY
, wxTextCtrl::OnCopy
)
368 EVT_MENU(wxID_PASTE
, wxTextCtrl::OnPaste
)
369 EVT_MENU(wxID_UNDO
, wxTextCtrl::OnUndo
)
370 EVT_MENU(wxID_REDO
, wxTextCtrl::OnRedo
)
371 EVT_MENU(wxID_CLEAR
, wxTextCtrl::OnDelete
)
372 EVT_MENU(wxID_SELECTALL
, wxTextCtrl::OnSelectAll
)
374 EVT_CONTEXT_MENU(wxTextCtrl::OnContextMenu
)
376 EVT_UPDATE_UI(wxID_CUT
, wxTextCtrl::OnUpdateCut
)
377 EVT_UPDATE_UI(wxID_COPY
, wxTextCtrl::OnUpdateCopy
)
378 EVT_UPDATE_UI(wxID_PASTE
, wxTextCtrl::OnUpdatePaste
)
379 EVT_UPDATE_UI(wxID_UNDO
, wxTextCtrl::OnUpdateUndo
)
380 EVT_UPDATE_UI(wxID_REDO
, wxTextCtrl::OnUpdateRedo
)
381 EVT_UPDATE_UI(wxID_CLEAR
, wxTextCtrl::OnUpdateDelete
)
382 EVT_UPDATE_UI(wxID_SELECTALL
, wxTextCtrl::OnUpdateSelectAll
)
386 void wxTextCtrl::Init()
392 m_privateContextMenu
= NULL
;
393 m_triggerOnSetValue
= true ;
396 wxTextCtrl::~wxTextCtrl()
398 delete m_privateContextMenu
;
401 bool wxTextCtrl::Create( wxWindow
*parent
,
407 const wxValidator
& validator
,
408 const wxString
& name
)
410 m_macIsUserPane
= false ;
413 if ( ! (style
& wxNO_BORDER
) )
414 style
= (style
& ~wxBORDER_MASK
) | wxSUNKEN_BORDER
;
416 if ( !wxTextCtrlBase::Create( parent
, id
, pos
, size
, style
& ~(wxHSCROLL
| wxVSCROLL
), validator
, name
) )
419 if ( m_windowStyle
& wxTE_MULTILINE
)
421 // always turn on this style for multi-line controls
422 m_windowStyle
|= wxTE_PROCESS_ENTER
;
423 style
|= wxTE_PROCESS_ENTER
;
426 CreatePeer( str
, pos
, size
, style
);
428 MacPostControlCreate(pos
, size
) ;
430 // only now the embedding is correct and we can do a positioning update
432 MacSuperChangedPosition() ;
434 if ( m_windowStyle
& wxTE_READONLY
)
435 SetEditable( false ) ;
437 SetCursor( wxCursor( wxCURSOR_IBEAM
) ) ;
442 void wxTextCtrl::CreatePeer(
445 const wxSize
& size
, long style
)
447 bool forceMLTE
= false ;
449 #if wxUSE_SYSTEM_OPTIONS
450 if (wxSystemOptions::HasOption( wxMAC_TEXTCONTROL_USE_MLTE
) && (wxSystemOptions::GetOptionInt( wxMAC_TEXTCONTROL_USE_MLTE
) == 1))
456 if ( UMAGetSystemVersion() >= 0x1050 )
461 if ( m_windowStyle
& wxTE_MULTILINE
|| ( UMAGetSystemVersion() >= 0x1050 ) )
462 m_peer
= new wxMacMLTEHIViewControl( this , str
, pos
, size
, style
) ;
467 if ( !(m_windowStyle
& wxTE_MULTILINE
) && !forceMLTE
)
469 m_peer
= new wxMacUnicodeTextControl( this , str
, pos
, size
, style
) ;
473 // the horizontal single line scrolling bug that made us keep the classic implementation
475 #if MAC_OS_X_VERSION_MIN_REQUIRED < MAC_OS_X_VERSION_10_5
477 m_peer
= new wxMacMLTEClassicControl( this , str
, pos
, size
, style
) ;
481 void wxTextCtrl::MacSuperChangedPosition()
483 wxWindow::MacSuperChangedPosition() ;
484 GetPeer()->SuperChangedPosition() ;
487 void wxTextCtrl::MacVisibilityChanged()
489 GetPeer()->VisibilityChanged( GetPeer()->IsVisible() );
492 void wxTextCtrl::MacCheckSpelling(bool check
)
494 GetPeer()->CheckSpelling(check
);
497 wxString
wxTextCtrl::GetValue() const
499 return GetPeer()->GetStringValue() ;
502 void wxTextCtrl::GetSelection(long* from
, long* to
) const
504 GetPeer()->GetSelection( from
, to
) ;
507 void wxTextCtrl::DoSetValue(const wxString
& str
, int flags
)
510 if ( GetValue() == str
)
513 GetPeer()->SetStringValue( str
) ;
515 if ( (flags
& SetValue_SendEvent
) && m_triggerOnSetValue
)
517 SendTextUpdatedEvent();
521 void wxTextCtrl::SetMaxLength(unsigned long len
)
526 bool wxTextCtrl::SetFont( const wxFont
& font
)
528 if ( !wxTextCtrlBase::SetFont( font
) )
531 GetPeer()->SetFont( font
, GetForegroundColour() , GetWindowStyle() ) ;
536 bool wxTextCtrl::SetStyle(long start
, long end
, const wxTextAttr
& style
)
538 GetPeer()->SetStyle( start
, end
, style
) ;
543 bool wxTextCtrl::SetDefaultStyle(const wxTextAttr
& style
)
545 wxTextCtrlBase::SetDefaultStyle( style
) ;
546 SetStyle( kTXNUseCurrentSelection
, kTXNUseCurrentSelection
, GetDefaultStyle() ) ;
551 // Clipboard operations
553 void wxTextCtrl::Copy()
559 void wxTextCtrl::Cut()
565 wxCommandEvent
event( wxEVT_COMMAND_TEXT_UPDATED
, m_windowId
);
566 event
.SetEventObject( this );
567 HandleWindowEvent( event
);
571 void wxTextCtrl::Paste()
577 // TODO: eventually we should add setting the default style again
579 wxCommandEvent
event( wxEVT_COMMAND_TEXT_UPDATED
, m_windowId
);
580 event
.SetEventObject( this );
581 HandleWindowEvent( event
);
585 bool wxTextCtrl::CanCopy() const
587 // Can copy if there's a selection
589 GetSelection( &from
, &to
);
594 bool wxTextCtrl::CanCut() const
599 // Can cut if there's a selection
601 GetSelection( &from
, &to
);
606 bool wxTextCtrl::CanPaste() const
611 return GetPeer()->CanPaste() ;
614 void wxTextCtrl::SetEditable(bool editable
)
616 if ( editable
!= m_editable
)
618 m_editable
= editable
;
619 GetPeer()->SetEditable( editable
) ;
623 void wxTextCtrl::SetInsertionPoint(long pos
)
625 SetSelection( pos
, pos
) ;
628 void wxTextCtrl::SetInsertionPointEnd()
630 wxTextPos pos
= GetLastPosition();
631 SetInsertionPoint( pos
);
634 long wxTextCtrl::GetInsertionPoint() const
637 GetSelection( &begin
, &end
) ;
642 wxTextPos
wxTextCtrl::GetLastPosition() const
644 return GetPeer()->GetLastPosition() ;
647 void wxTextCtrl::Replace(long from
, long to
, const wxString
& str
)
649 GetPeer()->Replace( from
, to
, str
) ;
652 void wxTextCtrl::Remove(long from
, long to
)
654 GetPeer()->Remove( from
, to
) ;
657 void wxTextCtrl::SetSelection(long from
, long to
)
659 GetPeer()->SetSelection( from
, to
) ;
662 void wxTextCtrl::WriteText(const wxString
& str
)
664 // TODO: this MPRemoting will be moved into a remoting peer proxy for any command
665 if ( !wxIsMainThread() )
667 // unfortunately CW 8 is not able to correctly deduce the template types,
668 // so we have to instantiate explicitly
669 wxMacMPRemoteGUICall
<wxTextCtrl
,wxString
>( this , &wxTextCtrl::WriteText
, str
) ;
674 GetPeer()->WriteText( str
) ;
677 void wxTextCtrl::AppendText(const wxString
& text
)
679 SetInsertionPointEnd();
683 void wxTextCtrl::Clear()
688 bool wxTextCtrl::IsModified() const
693 bool wxTextCtrl::IsEditable() const
695 return IsEnabled() && m_editable
;
698 bool wxTextCtrl::AcceptsFocus() const
700 // we don't want focus if we can't be edited
701 return /*IsEditable() && */ wxControl::AcceptsFocus();
704 wxSize
wxTextCtrl::DoGetBestSize() const
708 // these are the numbers from the HIG:
709 // we reduce them by the borders first
712 switch ( m_windowVariant
)
714 case wxWINDOW_VARIANT_NORMAL
:
718 case wxWINDOW_VARIANT_SMALL
:
722 case wxWINDOW_VARIANT_MINI
:
731 // as the above numbers have some free space around the text
732 // we get 5 lines like this anyway
733 if ( m_windowStyle
& wxTE_MULTILINE
)
736 if ( !HasFlag(wxNO_BORDER
) )
739 return wxSize(wText
, hText
);
742 // ----------------------------------------------------------------------------
744 // ----------------------------------------------------------------------------
746 void wxTextCtrl::Undo()
752 void wxTextCtrl::Redo()
758 bool wxTextCtrl::CanUndo() const
763 return GetPeer()->CanUndo() ;
766 bool wxTextCtrl::CanRedo() const
771 return GetPeer()->CanRedo() ;
774 void wxTextCtrl::MarkDirty()
779 void wxTextCtrl::DiscardEdits()
784 int wxTextCtrl::GetNumberOfLines() const
786 return GetPeer()->GetNumberOfLines() ;
789 long wxTextCtrl::XYToPosition(long x
, long y
) const
791 return GetPeer()->XYToPosition( x
, y
) ;
794 bool wxTextCtrl::PositionToXY(long pos
, long *x
, long *y
) const
796 return GetPeer()->PositionToXY( pos
, x
, y
) ;
799 void wxTextCtrl::ShowPosition(long pos
)
801 return GetPeer()->ShowPosition(pos
) ;
804 int wxTextCtrl::GetLineLength(long lineNo
) const
806 return GetPeer()->GetLineLength(lineNo
) ;
809 wxString
wxTextCtrl::GetLineText(long lineNo
) const
811 return GetPeer()->GetLineText(lineNo
) ;
814 void wxTextCtrl::Command(wxCommandEvent
& event
)
816 SetValue(event
.GetString());
817 ProcessCommand(event
);
820 void wxTextCtrl::OnDropFiles(wxDropFilesEvent
& event
)
822 // By default, load the first file into the text window.
823 if (event
.GetNumberOfFiles() > 0)
824 LoadFile( event
.GetFiles()[0] );
827 void wxTextCtrl::OnChar(wxKeyEvent
& event
)
829 int key
= event
.GetKeyCode() ;
830 bool eat_key
= false ;
833 if ( key
== 'a' && event
.MetaDown() )
840 if ( key
== 'c' && event
.MetaDown() )
848 if ( !IsEditable() && key
!= WXK_LEFT
&& key
!= WXK_RIGHT
&& key
!= WXK_DOWN
&& key
!= WXK_UP
&& key
!= WXK_TAB
&&
849 !( key
== WXK_RETURN
&& ( (m_windowStyle
& wxTE_PROCESS_ENTER
) || (m_windowStyle
& wxTE_MULTILINE
) ) )
850 // && key != WXK_PAGEUP && key != WXK_PAGEDOWN && key != WXK_HOME && key != WXK_END
857 // Check if we have reached the max # of chars (if it is set), but still
858 // allow navigation and deletion
859 GetSelection( &from
, &to
);
860 if ( !IsMultiLine() && m_maxLength
&& GetValue().length() >= m_maxLength
&&
861 key
!= WXK_LEFT
&& key
!= WXK_RIGHT
&& key
!= WXK_TAB
&&
862 key
!= WXK_BACK
&& key
!= WXK_DELETE
&& !( key
== WXK_RETURN
&& (m_windowStyle
& wxTE_PROCESS_ENTER
) ) &&
865 // eat it, we don't want to add more than allowed # of characters
867 // TODO: generate EVT_TEXT_MAXLEN()
871 // assume that any key not processed yet is going to modify the control
874 if ( key
== 'v' && event
.MetaDown() )
882 if ( key
== 'x' && event
.MetaDown() )
893 if (m_windowStyle
& wxTE_PROCESS_ENTER
)
895 wxCommandEvent
event(wxEVT_COMMAND_TEXT_ENTER
, m_windowId
);
896 event
.SetEventObject( this );
897 event
.SetString( GetValue() );
898 if ( HandleWindowEvent(event
) )
902 if ( !(m_windowStyle
& wxTE_MULTILINE
) )
904 wxTopLevelWindow
*tlw
= wxDynamicCast(wxGetTopLevelParent(this), wxTopLevelWindow
);
905 if ( tlw
&& tlw
->GetDefaultItem() )
907 wxButton
*def
= wxDynamicCast(tlw
->GetDefaultItem(), wxButton
);
908 if ( def
&& def
->IsEnabled() )
910 wxCommandEvent
event(wxEVT_COMMAND_BUTTON_CLICKED
, def
->GetId() );
911 event
.SetEventObject(def
);
918 // this will make wxWidgets eat the ENTER key so that
919 // we actually prevent line wrapping in a single line text control
925 if ( !(m_windowStyle
& wxTE_PROCESS_TAB
))
928 if (!event
.ShiftDown())
929 flags
|= wxNavigationKeyEvent::IsForward
;
930 if (event
.ControlDown())
931 flags
|= wxNavigationKeyEvent::WinChange
;
938 // This is necessary (don't know why);
939 // otherwise the tab will not be inserted.
940 WriteText(wxT("\t"));
951 // perform keystroke handling
955 if ( ( key
>= 0x20 && key
< WXK_START
) ||
956 ( key
>= WXK_NUMPAD0
&& key
<= WXK_DIVIDE
) ||
961 wxCommandEvent
event1(wxEVT_COMMAND_TEXT_UPDATED
, m_windowId
);
962 event1
.SetEventObject( this );
963 wxPostEvent( GetEventHandler(), event1
);
967 // ----------------------------------------------------------------------------
968 // standard handlers for standard edit menu events
969 // ----------------------------------------------------------------------------
971 void wxTextCtrl::OnCut(wxCommandEvent
& WXUNUSED(event
))
976 void wxTextCtrl::OnCopy(wxCommandEvent
& WXUNUSED(event
))
981 void wxTextCtrl::OnPaste(wxCommandEvent
& WXUNUSED(event
))
986 void wxTextCtrl::OnUndo(wxCommandEvent
& WXUNUSED(event
))
991 void wxTextCtrl::OnRedo(wxCommandEvent
& WXUNUSED(event
))
996 void wxTextCtrl::OnDelete(wxCommandEvent
& WXUNUSED(event
))
1000 GetSelection( &from
, &to
);
1001 if (from
!= -1 && to
!= -1)
1005 void wxTextCtrl::OnSelectAll(wxCommandEvent
& WXUNUSED(event
))
1007 SetSelection(-1, -1);
1010 void wxTextCtrl::OnUpdateCut(wxUpdateUIEvent
& event
)
1012 event
.Enable( CanCut() );
1015 void wxTextCtrl::OnUpdateCopy(wxUpdateUIEvent
& event
)
1017 event
.Enable( CanCopy() );
1020 void wxTextCtrl::OnUpdatePaste(wxUpdateUIEvent
& event
)
1022 event
.Enable( CanPaste() );
1025 void wxTextCtrl::OnUpdateUndo(wxUpdateUIEvent
& event
)
1027 event
.Enable( CanUndo() );
1030 void wxTextCtrl::OnUpdateRedo(wxUpdateUIEvent
& event
)
1032 event
.Enable( CanRedo() );
1035 void wxTextCtrl::OnUpdateDelete(wxUpdateUIEvent
& event
)
1039 GetSelection( &from
, &to
);
1040 event
.Enable( from
!= -1 && to
!= -1 && from
!= to
&& IsEditable() ) ;
1043 void wxTextCtrl::OnUpdateSelectAll(wxUpdateUIEvent
& event
)
1045 event
.Enable(GetLastPosition() > 0);
1048 // CS: Context Menus only work with MLTE implementations or non-multiline HIViews at the moment
1050 void wxTextCtrl::OnContextMenu(wxContextMenuEvent
& event
)
1052 if ( GetPeer()->HasOwnContextMenu() )
1058 if (m_privateContextMenu
== NULL
)
1060 m_privateContextMenu
= new wxMenu
;
1061 m_privateContextMenu
->Append(wxID_UNDO
, _("&Undo"));
1062 m_privateContextMenu
->Append(wxID_REDO
, _("&Redo"));
1063 m_privateContextMenu
->AppendSeparator();
1064 m_privateContextMenu
->Append(wxID_CUT
, _("Cu&t"));
1065 m_privateContextMenu
->Append(wxID_COPY
, _("&Copy"));
1066 m_privateContextMenu
->Append(wxID_PASTE
, _("&Paste"));
1067 m_privateContextMenu
->Append(wxID_CLEAR
, _("&Delete"));
1068 m_privateContextMenu
->AppendSeparator();
1069 m_privateContextMenu
->Append(wxID_SELECTALL
, _("Select &All"));
1072 if (m_privateContextMenu
!= NULL
)
1073 PopupMenu(m_privateContextMenu
);
1076 bool wxTextCtrl::MacSetupCursor( const wxPoint
& pt
)
1078 if ( !GetPeer()->SetupCursor( pt
) )
1079 return wxWindow::MacSetupCursor( pt
) ;
1084 // ----------------------------------------------------------------------------
1085 // implementation base class
1086 // ----------------------------------------------------------------------------
1088 wxMacTextControl::wxMacTextControl(wxTextCtrl
* peer
) :
1089 wxMacControl( peer
)
1093 wxMacTextControl::~wxMacTextControl()
1097 void wxMacTextControl::SetStyle(long WXUNUSED(start
),
1099 const wxTextAttr
& WXUNUSED(style
))
1103 void wxMacTextControl::Copy()
1107 void wxMacTextControl::Cut()
1111 void wxMacTextControl::Paste()
1115 bool wxMacTextControl::CanPaste() const
1120 void wxMacTextControl::SetEditable(bool WXUNUSED(editable
))
1124 wxTextPos
wxMacTextControl::GetLastPosition() const
1126 return GetStringValue().length() ;
1129 void wxMacTextControl::Replace( long from
, long to
, const wxString
&val
)
1131 SetSelection( from
, to
) ;
1135 void wxMacTextControl::Remove( long from
, long to
)
1137 SetSelection( from
, to
) ;
1138 WriteText( wxEmptyString
) ;
1141 void wxMacTextControl::Clear()
1143 SetStringValue( wxEmptyString
) ;
1146 bool wxMacTextControl::CanUndo() const
1151 void wxMacTextControl::Undo()
1155 bool wxMacTextControl::CanRedo() const
1160 void wxMacTextControl::Redo()
1164 long wxMacTextControl::XYToPosition(long WXUNUSED(x
), long WXUNUSED(y
)) const
1169 bool wxMacTextControl::PositionToXY(long WXUNUSED(pos
),
1171 long *WXUNUSED(y
)) const
1176 void wxMacTextControl::ShowPosition( long WXUNUSED(pos
) )
1180 int wxMacTextControl::GetNumberOfLines() const
1182 ItemCount lines
= 0 ;
1183 wxString content
= GetStringValue() ;
1186 for (size_t i
= 0; i
< content
.length() ; i
++)
1188 if (content
[i
] == '\r')
1195 wxString
wxMacTextControl::GetLineText(long lineNo
) const
1197 // TODO: change this if possible to reflect real lines
1198 wxString content
= GetStringValue() ;
1202 for (size_t i
= 0; i
< content
.length() ; i
++)
1204 if (count
== lineNo
)
1206 // Add chars in line then
1209 for (size_t j
= i
; j
< content
.length(); j
++)
1211 if (content
[j
] == '\n')
1220 if (content
[i
] == '\n')
1224 return wxEmptyString
;
1227 int wxMacTextControl::GetLineLength(long lineNo
) const
1229 // TODO: change this if possible to reflect real lines
1230 wxString content
= GetStringValue() ;
1234 for (size_t i
= 0; i
< content
.length() ; i
++)
1236 if (count
== lineNo
)
1238 // Count chars in line then
1240 for (size_t j
= i
; j
< content
.length(); j
++)
1243 if (content
[j
] == '\n')
1250 if (content
[i
] == '\n')
1257 // ----------------------------------------------------------------------------
1258 // standard unicode control implementation
1259 // ----------------------------------------------------------------------------
1261 // the current unicode textcontrol implementation has a bug : only if the control
1262 // is currently having the focus, the selection can be retrieved by the corresponding
1263 // data tag. So we have a mirroring using a member variable
1264 // TODO : build event table using virtual member functions for wxMacControl
1266 static const EventTypeSpec unicodeTextControlEventList
[] =
1268 { kEventClassControl
, kEventControlSetFocusPart
} ,
1271 static pascal OSStatus
wxMacUnicodeTextControlControlEventHandler( EventHandlerCallRef handler
, EventRef event
, void *data
)
1273 OSStatus result
= eventNotHandledErr
;
1274 wxMacUnicodeTextControl
* focus
= (wxMacUnicodeTextControl
*) data
;
1275 wxMacCarbonEvent
cEvent( event
) ;
1277 switch ( GetEventKind( event
) )
1279 case kEventControlSetFocusPart
:
1281 ControlPartCode controlPart
= cEvent
.GetParameter
<ControlPartCode
>(kEventParamControlPart
, typeControlPartCode
);
1282 if ( controlPart
== kControlFocusNoPart
)
1284 // about to loose focus -> store selection to field
1285 focus
->GetData
<ControlEditTextSelectionRec
>( 0, kControlEditTextSelectionTag
, &focus
->m_selection
);
1287 result
= CallNextEventHandler(handler
,event
) ;
1288 if ( controlPart
!= kControlFocusNoPart
)
1290 // about to gain focus -> set selection from field
1291 focus
->SetData
<ControlEditTextSelectionRec
>( 0, kControlEditTextSelectionTag
, &focus
->m_selection
);
1302 static pascal OSStatus
wxMacUnicodeTextControlEventHandler( EventHandlerCallRef handler
, EventRef event
, void *data
)
1304 OSStatus result
= eventNotHandledErr
;
1306 switch ( GetEventClass( event
) )
1308 case kEventClassControl
:
1309 result
= wxMacUnicodeTextControlControlEventHandler( handler
, event
, data
) ;
1318 DEFINE_ONE_SHOT_HANDLER_GETTER( wxMacUnicodeTextControlEventHandler
)
1320 wxMacUnicodeTextControl::wxMacUnicodeTextControl( wxTextCtrl
*wxPeer
) : wxMacTextControl( wxPeer
)
1324 wxMacUnicodeTextControl::wxMacUnicodeTextControl( wxTextCtrl
*wxPeer
,
1325 const wxString
& str
,
1327 const wxSize
& size
, long style
)
1328 : wxMacTextControl( wxPeer
)
1330 Create( wxPeer
, str
, pos
, size
, style
);
1333 bool wxMacUnicodeTextControl::Create( wxTextCtrl
*wxPeer
,
1334 const wxString
& str
,
1336 const wxSize
& size
, long style
)
1338 m_font
= wxPeer
->GetFont() ;
1339 m_windowStyle
= style
;
1340 m_selection
.selStart
= m_selection
.selEnd
= 0;
1341 Rect bounds
= wxMacGetBoundsForControl( wxPeer
, pos
, size
) ;
1343 wxMacConvertNewlines10To13( &st
) ;
1344 wxCFStringRef
cf(st
, m_font
.GetEncoding()) ;
1345 CFStringRef cfr
= cf
;
1347 m_valueTag
= kControlEditTextCFStringTag
;
1348 CreateControl( wxPeer
, &bounds
, cfr
);
1350 if ( !(m_windowStyle
& wxTE_MULTILINE
) )
1351 SetData
<Boolean
>( kControlEditTextPart
, kControlEditTextSingleLineTag
, true ) ;
1353 InstallControlEventHandler( m_controlRef
, GetwxMacUnicodeTextControlEventHandlerUPP(),
1354 GetEventTypeCount(unicodeTextControlEventList
), unicodeTextControlEventList
, this,
1360 wxMacUnicodeTextControl::~wxMacUnicodeTextControl()
1364 void wxMacUnicodeTextControl::VisibilityChanged(bool shown
)
1366 if ( !(m_windowStyle
& wxTE_MULTILINE
) && shown
)
1368 // work around a refresh issue insofar as not always the entire content is shown,
1369 // even if this would be possible
1370 ControlEditTextSelectionRec sel
;
1371 CFStringRef value
= NULL
;
1373 verify_noerr( GetData
<ControlEditTextSelectionRec
>( 0, kControlEditTextSelectionTag
, &sel
) );
1374 verify_noerr( GetData
<CFStringRef
>( 0, m_valueTag
, &value
) );
1375 verify_noerr( SetData
<CFStringRef
>( 0, m_valueTag
, &value
) );
1376 verify_noerr( SetData
<ControlEditTextSelectionRec
>( 0, kControlEditTextSelectionTag
, &sel
) );
1378 CFRelease( value
) ;
1382 wxString
wxMacUnicodeTextControl::GetStringValue() const
1385 CFStringRef value
= GetData
<CFStringRef
>(0, m_valueTag
) ;
1388 wxCFStringRef
cf(value
) ;
1389 result
= cf
.AsString() ;
1393 wxMacConvertNewlines13To10( &result
) ;
1395 wxMacConvertNewlines10To13( &result
) ;
1401 void wxMacUnicodeTextControl::SetStringValue( const wxString
&str
)
1404 wxMacConvertNewlines10To13( &st
) ;
1405 wxCFStringRef
cf( st
, m_font
.GetEncoding() ) ;
1406 verify_noerr( SetData
<CFStringRef
>( 0, m_valueTag
, cf
) ) ;
1409 void wxMacUnicodeTextControl::CreateControl( wxTextCtrl
* peer
, const Rect
* bounds
, CFStringRef cfr
)
1411 Boolean isPassword
= ( m_windowStyle
& wxTE_PASSWORD
) != 0 ;
1414 m_valueTag
= kControlEditTextPasswordCFStringTag
;
1416 OSStatus err
= CreateEditUnicodeTextControl(
1417 MAC_WXHWND(peer
->MacGetTopLevelWindowRef()), bounds
, cfr
,
1418 isPassword
, NULL
, &m_controlRef
) ;
1419 verify_noerr( err
);
1422 void wxMacUnicodeTextControl::Copy()
1424 SendHICommand( kHICommandCopy
) ;
1427 void wxMacUnicodeTextControl::Cut()
1429 SendHICommand( kHICommandCut
) ;
1432 void wxMacUnicodeTextControl::Paste()
1434 SendHICommand( kHICommandPaste
) ;
1437 bool wxMacUnicodeTextControl::CanPaste() const
1442 void wxMacUnicodeTextControl::SetEditable(bool WXUNUSED(editable
))
1444 #if 0 // leads to problem because text cannot be selected anymore
1445 SetData
<Boolean
>( kControlEditTextPart
, kControlEditTextLockedTag
, (Boolean
) !editable
) ;
1449 void wxMacUnicodeTextControl::GetSelection( long* from
, long* to
) const
1451 ControlEditTextSelectionRec sel
;
1453 verify_noerr( GetData
<ControlEditTextSelectionRec
>( 0, kControlEditTextSelectionTag
, &sel
) ) ;
1458 *from
= sel
.selStart
;
1463 void wxMacUnicodeTextControl::SetSelection( long from
, long to
)
1465 ControlEditTextSelectionRec sel
;
1467 int textLength
= 0 ;
1468 CFStringRef value
= GetData
<CFStringRef
>(0, m_valueTag
) ;
1471 wxCFStringRef
cf(value
) ;
1472 textLength
= cf
.AsString().length() ;
1475 if ((from
== -1) && (to
== -1))
1482 from
= wxMin(textLength
,wxMax(from
,0)) ;
1486 to
= wxMax(0,wxMin(textLength
,to
)) ;
1489 sel
.selStart
= from
;
1492 SetData
<ControlEditTextSelectionRec
>( 0, kControlEditTextSelectionTag
, &sel
) ;
1497 void wxMacUnicodeTextControl::WriteText( const wxString
& str
)
1500 wxMacConvertNewlines10To13( &st
) ;
1504 wxCFStringRef
cf(st
, m_font
.GetEncoding() ) ;
1505 CFStringRef value
= cf
;
1506 SetData
<CFStringRef
>( 0, kControlEditTextInsertCFStringRefTag
, &value
);
1510 wxString val
= GetStringValue() ;
1512 GetSelection( &start
, &end
) ;
1513 val
.Remove( start
, end
- start
) ;
1514 val
.insert( start
, str
) ;
1515 SetStringValue( val
) ;
1516 SetSelection( start
+ str
.length() , start
+ str
.length() ) ;
1520 // ----------------------------------------------------------------------------
1521 // MLTE control implementation (common part)
1522 // ----------------------------------------------------------------------------
1524 // if MTLE is read only, no changes at all are allowed, not even from
1525 // procedural API, in order to allow changes via API all the same we must undo
1526 // the readonly status while we are executing, this class helps to do so
1528 class wxMacEditHelper
1531 wxMacEditHelper( TXNObject txn
)
1533 TXNControlTag tag
[] = { kTXNIOPrivilegesTag
} ;
1535 TXNGetTXNObjectControls( m_txn
, 1 , tag
, m_data
) ;
1536 if ( m_data
[0].uValue
== kTXNReadOnly
)
1538 TXNControlData data
[] = { { kTXNReadWrite
} } ;
1539 TXNSetTXNObjectControls( m_txn
, false , 1 , tag
, data
) ;
1545 TXNControlTag tag
[] = { kTXNIOPrivilegesTag
} ;
1546 if ( m_data
[0].uValue
== kTXNReadOnly
)
1547 TXNSetTXNObjectControls( m_txn
, false , 1 , tag
, m_data
) ;
1552 TXNControlData m_data
[1] ;
1555 wxMacMLTEControl::wxMacMLTEControl( wxTextCtrl
*peer
)
1556 : wxMacTextControl( peer
)
1558 SetNeedsFocusRect( true ) ;
1561 wxString
wxMacMLTEControl::GetStringValue() const
1565 Size actualSize
= 0;
1570 err
= TXNGetDataEncoded( m_txn
, kTXNStartOffset
, kTXNEndOffset
, &theText
, kTXNUnicodeTextData
);
1579 actualSize
= GetHandleSize( theText
) / sizeof(UniChar
) ;
1580 if ( actualSize
> 0 )
1582 wxChar
*ptr
= NULL
;
1584 #if SIZEOF_WCHAR_T == 2
1585 ptr
= new wxChar
[actualSize
+ 1] ;
1586 wxStrncpy( ptr
, (wxChar
*)(*theText
) , actualSize
) ;
1588 SetHandleSize( theText
, (actualSize
+ 1) * sizeof(UniChar
) ) ;
1590 (((UniChar
*)*theText
)[actualSize
]) = 0 ;
1591 wxMBConvUTF16 converter
;
1592 size_t noChars
= converter
.MB2WC( NULL
, (const char*)*theText
, 0 ) ;
1593 wxASSERT_MSG( noChars
!= wxCONV_FAILED
, _T("Unable to count the number of characters in this string!") );
1594 ptr
= new wxChar
[noChars
+ 1] ;
1596 noChars
= converter
.MB2WC( ptr
, (const char*)*theText
, noChars
+ 1 ) ;
1597 wxASSERT_MSG( noChars
!= wxCONV_FAILED
, _T("Conversion of string failed!") );
1599 HUnlock( theText
) ;
1602 ptr
[actualSize
] = 0 ;
1603 result
= wxString( ptr
) ;
1607 DisposeHandle( theText
) ;
1611 err
= TXNGetDataEncoded( m_txn
, kTXNStartOffset
, kTXNEndOffset
, &theText
, kTXNTextData
);
1620 actualSize
= GetHandleSize( theText
) ;
1621 if ( actualSize
> 0 )
1624 result
= wxString( *theText
, wxConvLocal
, actualSize
) ;
1625 HUnlock( theText
) ;
1628 DisposeHandle( theText
) ;
1634 wxMacConvertNewlines13To10( &result
) ;
1636 wxMacConvertNewlines10To13( &result
) ;
1642 void wxMacMLTEControl::SetStringValue( const wxString
&str
)
1645 wxMacConvertNewlines10To13( &st
);
1649 wxMacWindowClipper
c( m_peer
) ;
1653 wxMacEditHelper
help( m_txn
);
1654 SetTXNData( st
, kTXNStartOffset
, kTXNEndOffset
);
1657 TXNSetSelection( m_txn
, 0, 0 );
1658 TXNShowSelection( m_txn
, kTXNShowStart
);
1662 TXNFrameOptions
wxMacMLTEControl::FrameOptionsFromWXStyle( long wxStyle
)
1664 TXNFrameOptions frameOptions
= kTXNDontDrawCaretWhenInactiveMask
;
1666 frameOptions
|= kTXNDoFontSubstitutionMask
;
1668 if ( ! (wxStyle
& wxTE_NOHIDESEL
) )
1669 frameOptions
|= kTXNDontDrawSelectionWhenInactiveMask
;
1671 if ( wxStyle
& (wxHSCROLL
| wxTE_DONTWRAP
) )
1672 frameOptions
|= kTXNWantHScrollBarMask
;
1674 if ( wxStyle
& wxTE_MULTILINE
)
1676 if ( ! (wxStyle
& wxTE_DONTWRAP
) )
1677 frameOptions
|= kTXNAlwaysWrapAtViewEdgeMask
;
1679 if ( !(wxStyle
& wxTE_NO_VSCROLL
) )
1681 frameOptions
|= kTXNWantVScrollBarMask
;
1683 // The following code causes drawing problems on 10.4. Perhaps it can be restored for
1684 // older versions of the OS, but I'm not sure it's appropriate to put a grow icon here
1685 // anyways, as AFAIK users can't actually use it to resize the text ctrl.
1686 // if ( frameOptions & kTXNWantHScrollBarMask )
1687 // frameOptions |= kTXNDrawGrowIconMask ;
1692 frameOptions
|= kTXNSingleLineOnlyMask
;
1695 return frameOptions
;
1698 void wxMacMLTEControl::AdjustCreationAttributes(const wxColour
&background
,
1699 bool WXUNUSED(visible
))
1701 TXNControlTag iControlTags
[] =
1703 kTXNDoFontSubstitution
,
1704 kTXNWordWrapStateTag
,
1706 TXNControlData iControlData
[] =
1712 int toptag
= WXSIZEOF( iControlTags
) ;
1714 if ( m_windowStyle
& wxTE_MULTILINE
)
1716 iControlData
[1].uValue
=
1717 (m_windowStyle
& wxTE_DONTWRAP
)
1722 OSStatus err
= TXNSetTXNObjectControls( m_txn
, false, toptag
, iControlTags
, iControlData
) ;
1723 verify_noerr( err
);
1725 // setting the default font:
1726 // under 10.2 this causes a visible caret, therefore we avoid it
1732 GetThemeFont( kThemeSystemFont
, GetApplicationScript() , fontName
, &fontSize
, &fontStyle
) ;
1734 TXNTypeAttributes typeAttr
[] =
1736 { kTXNQDFontNameAttribute
, kTXNQDFontNameAttributeSize
, { (void*) fontName
} } ,
1737 { kTXNQDFontSizeAttribute
, kTXNFontSizeAttributeSize
, { (void*) (fontSize
<< 16) } } ,
1738 { kTXNQDFontStyleAttribute
, kTXNQDFontStyleAttributeSize
, { (void*) normal
} } ,
1741 err
= TXNSetTypeAttributes(
1742 m_txn
, sizeof(typeAttr
) / sizeof(TXNTypeAttributes
),
1743 typeAttr
, kTXNStartOffset
, kTXNEndOffset
);
1744 verify_noerr( err
);
1746 if ( m_windowStyle
& wxTE_PASSWORD
)
1748 UniChar c
= 0x00A5 ;
1749 err
= TXNEchoMode( m_txn
, c
, 0 , true );
1750 verify_noerr( err
);
1753 TXNBackground tback
;
1754 tback
.bgType
= kTXNBackgroundTypeRGB
;
1755 background
.GetRGBColor( &tback
.bg
.color
);
1756 TXNSetBackground( m_txn
, &tback
);
1759 TXNCommandEventSupportOptions options
;
1760 if ( TXNGetCommandEventSupport( m_txn
, &options
) == noErr
)
1763 kTXNSupportEditCommandProcessing
1764 | kTXNSupportEditCommandUpdating
1765 | kTXNSupportFontCommandProcessing
1766 | kTXNSupportFontCommandUpdating
;
1768 // only spell check when not read-only
1769 // use system options for the default
1770 bool checkSpelling
= false ;
1771 if ( !(m_windowStyle
& wxTE_READONLY
) )
1773 #if wxUSE_SYSTEM_OPTIONS
1774 if ( wxSystemOptions::HasOption( wxMAC_TEXTCONTROL_USE_SPELL_CHECKER
) && (wxSystemOptions::GetOptionInt( wxMAC_TEXTCONTROL_USE_SPELL_CHECKER
) == 1) )
1776 checkSpelling
= true ;
1781 if ( checkSpelling
)
1783 kTXNSupportSpellCheckCommandProcessing
1784 | kTXNSupportSpellCheckCommandUpdating
;
1786 TXNSetCommandEventSupport( m_txn
, options
) ;
1790 void wxMacMLTEControl::SetBackgroundColour(const wxColour
& col
)
1792 TXNBackground tback
;
1793 tback
.bgType
= kTXNBackgroundTypeRGB
;
1794 col
.GetRGBColor(&tback
.bg
.color
);
1795 TXNSetBackground( m_txn
, &tback
);
1798 static inline int wxConvertToTXN(int x
)
1800 return wx_static_cast(int, x
/ 254.0 * 72 + 0.5);
1803 void wxMacMLTEControl::TXNSetAttribute( const wxTextAttr
& style
, long from
, long to
)
1805 TXNTypeAttributes typeAttr
[4] ;
1807 size_t typeAttrCount
= 0 ;
1810 TXNControlTag controlTags
[4];
1811 TXNControlData controlData
[4];
1812 size_t controlAttrCount
= 0;
1814 TXNTab
* tabs
= NULL
;
1816 bool relayout
= false;
1819 if ( style
.HasFont() )
1821 wxASSERT( typeAttrCount
< WXSIZEOF(typeAttr
) );
1822 font
= style
.GetFont() ;
1823 typeAttr
[typeAttrCount
].tag
= kTXNATSUIStyle
;
1824 typeAttr
[typeAttrCount
].size
= kTXNATSUIStyleSize
;
1825 typeAttr
[typeAttrCount
].data
.dataPtr
= font
.MacGetATSUStyle() ;
1829 if ( style
.HasTextColour() )
1831 wxASSERT( typeAttrCount
< WXSIZEOF(typeAttr
) );
1832 style
.GetTextColour().GetRGBColor( &color
);
1833 typeAttr
[typeAttrCount
].tag
= kTXNQDFontColorAttribute
;
1834 typeAttr
[typeAttrCount
].size
= kTXNQDFontColorAttributeSize
;
1835 typeAttr
[typeAttrCount
].data
.dataPtr
= (void*) &color
;
1839 if ( style
.HasAlignment() )
1841 wxASSERT( controlAttrCount
< WXSIZEOF(controlTags
) );
1844 switch ( style
.GetAlignment() )
1846 case wxTEXT_ALIGNMENT_LEFT
:
1847 align
= kTXNFlushLeft
;
1849 case wxTEXT_ALIGNMENT_CENTRE
:
1852 case wxTEXT_ALIGNMENT_RIGHT
:
1853 align
= kTXNFlushRight
;
1855 case wxTEXT_ALIGNMENT_JUSTIFIED
:
1856 align
= kTXNFullJust
;
1859 case wxTEXT_ALIGNMENT_DEFAULT
:
1860 align
= kTXNFlushDefault
;
1864 controlTags
[controlAttrCount
] = kTXNJustificationTag
;
1865 controlData
[controlAttrCount
].sValue
= align
;
1866 controlAttrCount
++ ;
1869 if ( style
.HasLeftIndent() || style
.HasRightIndent() )
1871 wxASSERT( controlAttrCount
< WXSIZEOF(controlTags
) );
1872 controlTags
[controlAttrCount
] = kTXNMarginsTag
;
1873 controlData
[controlAttrCount
].marginsPtr
= &margins
;
1874 verify_noerr( TXNGetTXNObjectControls (m_txn
, 1 ,
1875 &controlTags
[controlAttrCount
], &controlData
[controlAttrCount
]) );
1876 if ( style
.HasLeftIndent() )
1878 margins
.leftMargin
= wxConvertToTXN(style
.GetLeftIndent());
1880 if ( style
.HasRightIndent() )
1882 margins
.rightMargin
= wxConvertToTXN(style
.GetRightIndent());
1884 controlAttrCount
++ ;
1887 if ( style
.HasTabs() )
1889 const wxArrayInt
& tabarray
= style
.GetTabs();
1890 // unfortunately Mac only applies a tab distance, not individually different tabs
1891 controlTags
[controlAttrCount
] = kTXNTabSettingsTag
;
1892 if ( tabarray
.size() > 0 )
1893 controlData
[controlAttrCount
].tabValue
.value
= wxConvertToTXN(tabarray
[0]);
1895 controlData
[controlAttrCount
].tabValue
.value
= 72 ;
1897 controlData
[controlAttrCount
].tabValue
.tabType
= kTXNLeftTab
;
1898 controlAttrCount
++ ;
1901 // unfortunately the relayout is not automatic
1902 if ( controlAttrCount
> 0 )
1904 verify_noerr( TXNSetTXNObjectControls (m_txn
, false /* don't clear all */, controlAttrCount
,
1905 controlTags
, controlData
) );
1909 if ( typeAttrCount
> 0 )
1911 verify_noerr( TXNSetTypeAttributes( m_txn
, typeAttrCount
, typeAttr
, from
, to
) );
1922 TXNRecalcTextLayout( m_txn
);
1926 void wxMacMLTEControl::SetFont(const wxFont
& font
,
1927 const wxColour
& foreground
,
1928 long WXUNUSED(windowStyle
))
1930 wxMacEditHelper
help( m_txn
) ;
1931 TXNSetAttribute( wxTextAttr( foreground
, wxNullColour
, font
), kTXNStartOffset
, kTXNEndOffset
) ;
1934 void wxMacMLTEControl::SetStyle( long start
, long end
, const wxTextAttr
& style
)
1936 wxMacEditHelper
help( m_txn
) ;
1937 TXNSetAttribute( style
, start
, end
) ;
1940 void wxMacMLTEControl::Copy()
1945 void wxMacMLTEControl::Cut()
1950 void wxMacMLTEControl::Paste()
1955 bool wxMacMLTEControl::CanPaste() const
1957 return TXNIsScrapPastable() ;
1960 void wxMacMLTEControl::SetEditable(bool editable
)
1962 TXNControlTag tag
[] = { kTXNIOPrivilegesTag
} ;
1963 TXNControlData data
[] = { { editable
? kTXNReadWrite
: kTXNReadOnly
} } ;
1964 TXNSetTXNObjectControls( m_txn
, false, WXSIZEOF(tag
), tag
, data
) ;
1967 wxTextPos
wxMacMLTEControl::GetLastPosition() const
1969 wxTextPos actualsize
= 0 ;
1972 OSErr err
= TXNGetDataEncoded( m_txn
, kTXNStartOffset
, kTXNEndOffset
, &theText
, kTXNTextData
);
1977 actualsize
= GetHandleSize( theText
) ;
1978 DisposeHandle( theText
) ;
1988 void wxMacMLTEControl::Replace( long from
, long to
, const wxString
&str
)
1990 wxString value
= str
;
1991 wxMacConvertNewlines10To13( &value
) ;
1993 wxMacEditHelper
help( m_txn
) ;
1995 wxMacWindowClipper
c( m_peer
) ;
1998 TXNSetSelection( m_txn
, from
, to
== -1 ? kTXNEndOffset
: to
) ;
2000 SetTXNData( value
, kTXNUseCurrentSelection
, kTXNUseCurrentSelection
) ;
2003 void wxMacMLTEControl::Remove( long from
, long to
)
2006 wxMacWindowClipper
c( m_peer
) ;
2008 wxMacEditHelper
help( m_txn
) ;
2009 TXNSetSelection( m_txn
, from
, to
) ;
2013 void wxMacMLTEControl::GetSelection( long* from
, long* to
) const
2016 TXNGetSelection( m_txn
, &f
, &t
) ;
2021 void wxMacMLTEControl::SetSelection( long from
, long to
)
2024 wxMacWindowClipper
c( m_peer
) ;
2027 // change the selection
2028 if ((from
== -1) && (to
== -1))
2029 TXNSelectAll( m_txn
);
2031 TXNSetSelection( m_txn
, from
, to
== -1 ? kTXNEndOffset
: to
);
2033 TXNShowSelection( m_txn
, kTXNShowStart
);
2036 void wxMacMLTEControl::WriteText( const wxString
& str
)
2039 wxMacConvertNewlines10To13( &st
) ;
2041 long start
, end
, dummy
;
2043 GetSelection( &start
, &dummy
) ;
2045 wxMacWindowClipper
c( m_peer
) ;
2049 wxMacEditHelper
helper( m_txn
) ;
2050 SetTXNData( st
, kTXNUseCurrentSelection
, kTXNUseCurrentSelection
) ;
2053 GetSelection( &dummy
, &end
) ;
2055 // TODO: SetStyle( start , end , GetDefaultStyle() ) ;
2058 void wxMacMLTEControl::Clear()
2061 wxMacWindowClipper
c( m_peer
) ;
2063 wxMacEditHelper
st( m_txn
) ;
2064 TXNSetSelection( m_txn
, kTXNStartOffset
, kTXNEndOffset
) ;
2068 bool wxMacMLTEControl::CanUndo() const
2070 return TXNCanUndo( m_txn
, NULL
) ;
2073 void wxMacMLTEControl::Undo()
2078 bool wxMacMLTEControl::CanRedo() const
2080 return TXNCanRedo( m_txn
, NULL
) ;
2083 void wxMacMLTEControl::Redo()
2088 int wxMacMLTEControl::GetNumberOfLines() const
2090 ItemCount lines
= 0 ;
2091 TXNGetLineCount( m_txn
, &lines
) ;
2096 long wxMacMLTEControl::XYToPosition(long x
, long y
) const
2101 // TODO: find a better implementation : while we can get the
2102 // line metrics of a certain line, we don't get its starting
2103 // position, so it would probably be rather a binary search
2104 // for the start position
2105 long xpos
= 0, ypos
= 0 ;
2106 int lastHeight
= 0 ;
2109 lastpos
= GetLastPosition() ;
2110 for ( n
= 0 ; n
<= (ItemCount
) lastpos
; ++n
)
2112 if ( y
== ypos
&& x
== xpos
)
2115 TXNOffsetToPoint( m_txn
, n
, &curpt
) ;
2117 if ( curpt
.v
> lastHeight
)
2123 lastHeight
= curpt
.v
;
2132 bool wxMacMLTEControl::PositionToXY( long pos
, long *x
, long *y
) const
2142 lastpos
= GetLastPosition() ;
2143 if ( pos
<= lastpos
)
2145 // TODO: find a better implementation - while we can get the
2146 // line metrics of a certain line, we don't get its starting
2147 // position, so it would probably be rather a binary search
2148 // for the start position
2149 long xpos
= 0, ypos
= 0 ;
2150 int lastHeight
= 0 ;
2153 for ( n
= 0 ; n
<= (ItemCount
) pos
; ++n
)
2155 TXNOffsetToPoint( m_txn
, n
, &curpt
) ;
2157 if ( curpt
.v
> lastHeight
)
2163 lastHeight
= curpt
.v
;
2178 void wxMacMLTEControl::ShowPosition( long pos
)
2180 Point current
, desired
;
2181 TXNOffset selstart
, selend
;
2183 TXNGetSelection( m_txn
, &selstart
, &selend
);
2184 TXNOffsetToPoint( m_txn
, selstart
, ¤t
);
2185 TXNOffsetToPoint( m_txn
, pos
, &desired
);
2187 // TODO: use HIPoints for 10.3 and above
2189 OSErr theErr
= noErr
;
2190 long dv
= desired
.v
- current
.v
;
2191 long dh
= desired
.h
- current
.h
;
2192 TXNShowSelection( m_txn
, kTXNShowStart
) ; // NB: should this be kTXNShowStart or kTXNShowEnd ??
2193 theErr
= TXNScroll( m_txn
, kTXNScrollUnitsInPixels
, kTXNScrollUnitsInPixels
, &dv
, &dh
);
2195 // there will be an error returned for classic MLTE implementation when the control is
2196 // invisible, but HITextView works correctly, so we don't assert that one
2197 // wxASSERT_MSG( theErr == noErr, _T("TXNScroll returned an error!") );
2200 void wxMacMLTEControl::SetTXNData( const wxString
& st
, TXNOffset start
, TXNOffset end
)
2203 #if SIZEOF_WCHAR_T == 2
2204 size_t len
= st
.length() ;
2205 TXNSetData( m_txn
, kTXNUnicodeTextData
, (void*)st
.wc_str(), len
* 2, start
, end
);
2207 wxMBConvUTF16 converter
;
2208 ByteCount byteBufferLen
= converter
.WC2MB( NULL
, st
.wc_str(), 0 ) ;
2209 UniChar
*unibuf
= (UniChar
*)malloc( byteBufferLen
) ;
2210 converter
.WC2MB( (char*)unibuf
, st
.wc_str(), byteBufferLen
) ;
2211 TXNSetData( m_txn
, kTXNUnicodeTextData
, (void*)unibuf
, byteBufferLen
, start
, end
) ;
2215 wxCharBuffer text
= st
.mb_str( wxConvLocal
) ;
2216 TXNSetData( m_txn
, kTXNTextData
, (void*)text
.data(), strlen( text
), start
, end
) ;
2220 wxString
wxMacMLTEControl::GetLineText(long lineNo
) const
2224 if ( lineNo
< GetNumberOfLines() )
2227 Fixed lineWidth
, lineHeight
, currentHeight
;
2230 // get the first possible position in the control
2231 TXNOffsetToPoint(m_txn
, 0, &firstPoint
);
2233 // Iterate through the lines until we reach the one we want,
2234 // adding to our current y pixel point position
2237 while (ypos
< lineNo
)
2239 TXNGetLineMetrics(m_txn
, ypos
++, &lineWidth
, &lineHeight
);
2240 currentHeight
+= lineHeight
;
2243 Point thePoint
= { firstPoint
.v
+ (currentHeight
>> 16), firstPoint
.h
+ (0) };
2244 TXNOffset theOffset
;
2245 TXNPointToOffset(m_txn
, thePoint
, &theOffset
);
2247 wxString content
= GetStringValue() ;
2248 Point currentPoint
= thePoint
;
2249 while (thePoint
.v
== currentPoint
.v
&& theOffset
< content
.length())
2251 line
+= content
[theOffset
];
2252 TXNOffsetToPoint(m_txn
, ++theOffset
, ¤tPoint
);
2259 int wxMacMLTEControl::GetLineLength(long lineNo
) const
2263 if ( lineNo
< GetNumberOfLines() )
2266 Fixed lineWidth
, lineHeight
, currentHeight
;
2269 // get the first possible position in the control
2270 TXNOffsetToPoint(m_txn
, 0, &firstPoint
);
2272 // Iterate through the lines until we reach the one we want,
2273 // adding to our current y pixel point position
2276 while (ypos
< lineNo
)
2278 TXNGetLineMetrics(m_txn
, ypos
++, &lineWidth
, &lineHeight
);
2279 currentHeight
+= lineHeight
;
2282 Point thePoint
= { firstPoint
.v
+ (currentHeight
>> 16), firstPoint
.h
+ (0) };
2283 TXNOffset theOffset
;
2284 TXNPointToOffset(m_txn
, thePoint
, &theOffset
);
2286 wxString content
= GetStringValue() ;
2287 Point currentPoint
= thePoint
;
2288 while (thePoint
.v
== currentPoint
.v
&& theOffset
< content
.length())
2291 TXNOffsetToPoint(m_txn
, ++theOffset
, ¤tPoint
);
2298 #if MAC_OS_X_VERSION_MIN_REQUIRED < MAC_OS_X_VERSION_10_5
2300 // ----------------------------------------------------------------------------
2301 // MLTE control implementation (classic part)
2302 // ----------------------------------------------------------------------------
2304 // OS X Notes : We still don't have a full replacement for MLTE, so this implementation
2305 // has to live on. We have different problems coming from outdated implementations on the
2306 // various OS X versions. Most deal with the scrollbars: they are not correctly embedded
2307 // while this can be solved on 10.3 by reassigning them the correct place, on 10.2 there is
2308 // no way out, therefore we are using our own implementation and our own scrollbars ....
2310 TXNScrollInfoUPP gTXNScrollInfoProc
= NULL
;
2311 ControlActionUPP gTXNScrollActionProc
= NULL
;
2313 pascal void wxMacMLTEClassicControl::TXNScrollInfoProc(
2314 SInt32 iValue
, SInt32 iMaximumValue
,
2315 TXNScrollBarOrientation iScrollBarOrientation
, SInt32 iRefCon
)
2317 wxMacMLTEClassicControl
* mlte
= (wxMacMLTEClassicControl
*) iRefCon
;
2318 SInt32 value
= wxMax( iValue
, 0 ) ;
2319 SInt32 maximum
= wxMax( iMaximumValue
, 0 ) ;
2321 if ( iScrollBarOrientation
== kTXNHorizontal
)
2323 if ( mlte
->m_sbHorizontal
)
2325 SetControl32BitValue( mlte
->m_sbHorizontal
, value
) ;
2326 SetControl32BitMaximum( mlte
->m_sbHorizontal
, maximum
) ;
2327 mlte
->m_lastHorizontalValue
= value
;
2330 else if ( iScrollBarOrientation
== kTXNVertical
)
2332 if ( mlte
->m_sbVertical
)
2334 SetControl32BitValue( mlte
->m_sbVertical
, value
) ;
2335 SetControl32BitMaximum( mlte
->m_sbVertical
, maximum
) ;
2336 mlte
->m_lastVerticalValue
= value
;
2341 pascal void wxMacMLTEClassicControl::TXNScrollActionProc( ControlRef controlRef
, ControlPartCode partCode
)
2343 wxMacMLTEClassicControl
* mlte
= (wxMacMLTEClassicControl
*) GetControlReference( controlRef
) ;
2347 if ( controlRef
!= mlte
->m_sbVertical
&& controlRef
!= mlte
->m_sbHorizontal
)
2351 bool isHorizontal
= ( controlRef
== mlte
->m_sbHorizontal
) ;
2353 SInt32 minimum
= 0 ;
2354 SInt32 maximum
= GetControl32BitMaximum( controlRef
) ;
2355 SInt32 value
= GetControl32BitValue( controlRef
) ;
2360 case kControlDownButtonPart
:
2364 case kControlUpButtonPart
:
2368 case kControlPageDownPart
:
2369 delta
= GetControlViewSize( controlRef
) ;
2372 case kControlPageUpPart
:
2373 delta
= -GetControlViewSize( controlRef
) ;
2376 case kControlIndicatorPart
:
2377 delta
= value
- (isHorizontal
? mlte
->m_lastHorizontalValue
: mlte
->m_lastVerticalValue
) ;
2386 SInt32 newValue
= value
;
2388 if ( partCode
!= kControlIndicatorPart
)
2390 if ( value
+ delta
< minimum
)
2391 delta
= minimum
- value
;
2392 if ( value
+ delta
> maximum
)
2393 delta
= maximum
- value
;
2395 SetControl32BitValue( controlRef
, value
+ delta
) ;
2396 newValue
= value
+ delta
;
2399 SInt32 verticalDelta
= isHorizontal
? 0 : delta
;
2400 SInt32 horizontalDelta
= isHorizontal
? delta
: 0 ;
2403 mlte
->m_txn
, kTXNScrollUnitsInPixels
, kTXNScrollUnitsInPixels
,
2404 &verticalDelta
, &horizontalDelta
);
2405 verify_noerr( err
);
2408 mlte
->m_lastHorizontalValue
= newValue
;
2410 mlte
->m_lastVerticalValue
= newValue
;
2414 // make correct activations
2415 void wxMacMLTEClassicControl::MacActivatePaneText(bool setActive
)
2417 wxTextCtrl
* textctrl
= (wxTextCtrl
*) GetControlReference(m_controlRef
);
2419 wxMacWindowClipper
clipper( textctrl
) ;
2420 TXNActivate( m_txn
, m_txnFrameID
, setActive
);
2422 ControlRef controlFocus
= 0 ;
2423 GetKeyboardFocus( m_txnWindow
, &controlFocus
) ;
2424 if ( controlFocus
== m_controlRef
)
2425 TXNFocus( m_txn
, setActive
);
2428 void wxMacMLTEClassicControl::MacFocusPaneText(bool setFocus
)
2430 TXNFocus( m_txn
, setFocus
);
2433 // guards against inappropriate redraw (hidden objects drawing onto window)
2435 void wxMacMLTEClassicControl::MacSetObjectVisibility(bool vis
)
2437 ControlRef controlFocus
= 0 ;
2438 GetKeyboardFocus( m_txnWindow
, &controlFocus
) ;
2440 if ( !vis
&& (controlFocus
== m_controlRef
) )
2441 SetKeyboardFocus( m_txnWindow
, m_controlRef
, kControlFocusNoPart
) ;
2443 TXNControlTag iControlTags
[1] = { kTXNVisibilityTag
};
2444 TXNControlData iControlData
[1] = { { (UInt32
)false } };
2446 verify_noerr( TXNGetTXNObjectControls( m_txn
, 1, iControlTags
, iControlData
) ) ;
2448 if ( iControlData
[0].uValue
!= vis
)
2450 iControlData
[0].uValue
= vis
;
2451 verify_noerr( TXNSetTXNObjectControls( m_txn
, false , 1, iControlTags
, iControlData
) ) ;
2454 // currently, we always clip as partial visibility (overlapped) visibility is also a problem,
2455 // if we run into further problems we might set the FrameBounds to an empty rect here
2458 // make sure that the TXNObject is at the right position
2460 void wxMacMLTEClassicControl::MacUpdatePosition()
2462 wxTextCtrl
* textctrl
= (wxTextCtrl
*)GetControlReference( m_controlRef
);
2463 if ( textctrl
== NULL
)
2467 GetRectInWindowCoords( &bounds
);
2469 wxRect visRect
= textctrl
->MacGetClippedClientRect() ;
2470 Rect visBounds
= { visRect
.y
, visRect
.x
, visRect
.y
+ visRect
.height
, visRect
.x
+ visRect
.width
} ;
2473 textctrl
->MacWindowToRootWindow( &x
, &y
) ;
2474 OffsetRect( &visBounds
, x
, y
) ;
2476 if ( !EqualRect( &bounds
, &m_txnControlBounds
) || !EqualRect( &visBounds
, &m_txnVisBounds
) )
2478 m_txnControlBounds
= bounds
;
2479 m_txnVisBounds
= visBounds
;
2480 wxMacWindowClipper
cl( textctrl
) ;
2482 if ( m_sbHorizontal
|| m_sbVertical
)
2484 int w
= bounds
.right
- bounds
.left
;
2485 int h
= bounds
.bottom
- bounds
.top
;
2487 if ( m_sbHorizontal
)
2491 sbBounds
.left
= -1 ;
2492 sbBounds
.top
= h
- 14 ;
2493 sbBounds
.right
= w
+ 1 ;
2494 sbBounds
.bottom
= h
+ 1 ;
2496 SetControlBounds( m_sbHorizontal
, &sbBounds
) ;
2497 SetControlViewSize( m_sbHorizontal
, w
) ;
2504 sbBounds
.left
= w
- 14 ;
2506 sbBounds
.right
= w
+ 1 ;
2507 sbBounds
.bottom
= m_sbHorizontal
? h
- 14 : h
+ 1 ;
2509 SetControlBounds( m_sbVertical
, &sbBounds
) ;
2510 SetControlViewSize( m_sbVertical
, h
) ;
2515 TXNLongRect olddestRect
;
2516 TXNGetRectBounds( m_txn
, &oldviewRect
, &olddestRect
, NULL
) ;
2518 Rect viewRect
= { m_txnControlBounds
.top
, m_txnControlBounds
.left
,
2519 m_txnControlBounds
.bottom
- ( m_sbHorizontal
? 14 : 0 ) ,
2520 m_txnControlBounds
.right
- ( m_sbVertical
? 14 : 0 ) } ;
2521 TXNLongRect destRect
= { m_txnControlBounds
.top
, m_txnControlBounds
.left
,
2522 m_txnControlBounds
.bottom
- ( m_sbHorizontal
? 14 : 0 ) ,
2523 m_txnControlBounds
.right
- ( m_sbVertical
? 14 : 0 ) } ;
2525 if ( olddestRect
.right
>= 10000 )
2526 destRect
.right
= destRect
.left
+ 32000 ;
2528 if ( olddestRect
.bottom
>= 0x20000000 )
2529 destRect
.bottom
= destRect
.top
+ 0x40000000 ;
2531 SectRect( &viewRect
, &visBounds
, &viewRect
) ;
2532 TXNSetRectBounds( m_txn
, &viewRect
, &destRect
, true ) ;
2537 m_txnControlBounds
.top
,
2538 m_txnControlBounds
.left
,
2539 m_txnControlBounds
.bottom
- (m_sbHorizontal
? 14 : 0),
2540 m_txnControlBounds
.right
- (m_sbVertical
? 14 : 0),
2544 // the SetFrameBounds method under Classic sometimes does not correctly scroll a selection into sight after a
2545 // movement, therefore we have to force it
2547 // this problem has been reported in OSX as well, so we use this here once again
2549 TXNLongRect textRect
;
2550 TXNGetRectBounds( m_txn
, NULL
, NULL
, &textRect
) ;
2551 if ( textRect
.left
< m_txnControlBounds
.left
)
2552 TXNShowSelection( m_txn
, kTXNShowStart
) ;
2556 void wxMacMLTEClassicControl::SetRect( Rect
*r
)
2558 wxMacControl::SetRect( r
) ;
2559 MacUpdatePosition() ;
2562 void wxMacMLTEClassicControl::MacControlUserPaneDrawProc(wxInt16
WXUNUSED(thePart
))
2564 wxTextCtrl
* textctrl
= (wxTextCtrl
*)GetControlReference( m_controlRef
);
2565 if ( textctrl
== NULL
)
2568 if ( textctrl
->IsShownOnScreen() )
2570 wxMacWindowClipper
clipper( textctrl
) ;
2571 TXNDraw( m_txn
, NULL
) ;
2575 wxInt16
wxMacMLTEClassicControl::MacControlUserPaneHitTestProc(wxInt16 x
, wxInt16 y
)
2577 Point where
= { y
, x
} ;
2578 ControlPartCode result
= kControlNoPart
;
2580 wxTextCtrl
* textctrl
= (wxTextCtrl
*) GetControlReference( m_controlRef
);
2581 if ( (textctrl
!= NULL
) && textctrl
->IsShownOnScreen() )
2583 if (PtInRect( where
, &m_txnControlBounds
))
2585 result
= kControlEditTextPart
;
2589 // sometimes we get the coords also in control local coordinates, therefore test again
2591 textctrl
->MacClientToRootWindow( &x
, &y
) ;
2595 if (PtInRect( where
, &m_txnControlBounds
))
2596 result
= kControlEditTextPart
;
2603 wxInt16
wxMacMLTEClassicControl::MacControlUserPaneTrackingProc( wxInt16 x
, wxInt16 y
, void* WXUNUSED(actionProc
) )
2605 ControlPartCode result
= kControlNoPart
;
2607 wxTextCtrl
* textctrl
= (wxTextCtrl
*) GetControlReference( m_controlRef
);
2608 if ( (textctrl
!= NULL
) && textctrl
->IsShownOnScreen() )
2610 Point startPt
= { y
, x
} ;
2612 // for compositing, we must convert these into toplevel window coordinates, because hittesting expects them
2614 textctrl
->MacClientToRootWindow( &x
, &y
) ;
2618 switch (MacControlUserPaneHitTestProc( startPt
.h
, startPt
.v
))
2620 case kControlEditTextPart
:
2622 wxMacWindowClipper
clipper( textctrl
) ;
2625 ConvertEventRefToEventRecord( (EventRef
) wxTheApp
->MacGetCurrentEvent() , &rec
) ;
2626 TXNClick( m_txn
, &rec
);
2638 void wxMacMLTEClassicControl::MacControlUserPaneIdleProc()
2640 wxTextCtrl
* textctrl
= (wxTextCtrl
*)GetControlReference( m_controlRef
);
2641 if ( textctrl
== NULL
)
2644 if (textctrl
->IsShownOnScreen())
2646 if (IsControlActive(m_controlRef
))
2650 wxMacWindowClipper
clipper( textctrl
) ;
2655 if (PtInRect(mousep
, &m_txnControlBounds
))
2657 RgnHandle theRgn
= NewRgn();
2658 RectRgn(theRgn
, &m_txnControlBounds
);
2659 TXNAdjustCursor(m_txn
, theRgn
);
2666 wxInt16
wxMacMLTEClassicControl::MacControlUserPaneKeyDownProc (wxInt16 keyCode
, wxInt16 charCode
, wxInt16 modifiers
)
2668 wxTextCtrl
* textctrl
= (wxTextCtrl
*)GetControlReference( m_controlRef
);
2669 if ( textctrl
== NULL
)
2670 return kControlNoPart
;
2672 wxMacWindowClipper
clipper( textctrl
) ;
2675 memset( &ev
, 0 , sizeof( ev
) ) ;
2677 ev
.modifiers
= modifiers
;
2678 ev
.message
= ((keyCode
<< 8) & keyCodeMask
) | (charCode
& charCodeMask
);
2679 TXNKeyDown( m_txn
, &ev
);
2681 return kControlEntireControl
;
2684 void wxMacMLTEClassicControl::MacControlUserPaneActivateProc(bool activating
)
2686 MacActivatePaneText( activating
);
2689 wxInt16
wxMacMLTEClassicControl::MacControlUserPaneFocusProc(wxInt16 action
)
2691 ControlPartCode focusResult
= kControlFocusNoPart
;
2693 wxTextCtrl
* textctrl
= (wxTextCtrl
*)GetControlReference( m_controlRef
);
2694 if ( textctrl
== NULL
)
2697 wxMacWindowClipper
clipper( textctrl
) ;
2699 ControlRef controlFocus
= NULL
;
2700 GetKeyboardFocus( m_txnWindow
, &controlFocus
) ;
2701 bool wasFocused
= ( controlFocus
== m_controlRef
) ;
2705 case kControlFocusPrevPart
:
2706 case kControlFocusNextPart
:
2707 MacFocusPaneText( !wasFocused
);
2708 focusResult
= (!wasFocused
? (ControlPartCode
) kControlEditTextPart
: (ControlPartCode
) kControlFocusNoPart
);
2711 case kControlFocusNoPart
:
2713 MacFocusPaneText( false );
2714 focusResult
= kControlFocusNoPart
;
2721 void wxMacMLTEClassicControl::MacControlUserPaneBackgroundProc( void *WXUNUSED(info
) )
2725 wxMacMLTEClassicControl::wxMacMLTEClassicControl( wxTextCtrl
*wxPeer
,
2726 const wxString
& str
,
2728 const wxSize
& size
, long style
)
2729 : wxMacMLTEControl( wxPeer
)
2731 m_font
= wxPeer
->GetFont() ;
2732 m_windowStyle
= style
;
2733 Rect bounds
= wxMacGetBoundsForControl( wxPeer
, pos
, size
) ;
2736 kControlSupportsEmbedding
| kControlSupportsFocus
| kControlWantsIdle
2737 | kControlWantsActivate
| kControlHandlesTracking
2738 // | kControlHasSpecialBackground
2739 | kControlGetsFocusOnClick
| kControlSupportsLiveFeedback
;
2741 OSStatus err
= ::CreateUserPaneControl(
2742 MAC_WXHWND(wxPeer
->GetParent()->MacGetTopLevelWindowRef()),
2743 &bounds
, featureSet
, &m_controlRef
);
2744 verify_noerr( err
);
2748 AdjustCreationAttributes( *wxWHITE
, true ) ;
2750 MacSetObjectVisibility( wxPeer
->IsShownOnScreen() ) ;
2754 wxMacConvertNewlines10To13( &st
) ;
2755 wxMacWindowClipper
clipper( m_peer
) ;
2756 SetTXNData( st
, kTXNStartOffset
, kTXNEndOffset
) ;
2757 TXNSetSelection( m_txn
, 0, 0 ) ;
2761 wxMacMLTEClassicControl::~wxMacMLTEClassicControl()
2763 TXNDeleteObject( m_txn
);
2767 void wxMacMLTEClassicControl::VisibilityChanged(bool shown
)
2769 MacSetObjectVisibility( shown
) ;
2770 wxMacControl::VisibilityChanged( shown
) ;
2773 void wxMacMLTEClassicControl::SuperChangedPosition()
2775 MacUpdatePosition() ;
2776 wxMacControl::SuperChangedPosition() ;
2779 ControlUserPaneDrawUPP gTPDrawProc
= NULL
;
2780 ControlUserPaneHitTestUPP gTPHitProc
= NULL
;
2781 ControlUserPaneTrackingUPP gTPTrackProc
= NULL
;
2782 ControlUserPaneIdleUPP gTPIdleProc
= NULL
;
2783 ControlUserPaneKeyDownUPP gTPKeyProc
= NULL
;
2784 ControlUserPaneActivateUPP gTPActivateProc
= NULL
;
2785 ControlUserPaneFocusUPP gTPFocusProc
= NULL
;
2787 static pascal void wxMacControlUserPaneDrawProc(ControlRef control
, SInt16 part
)
2789 wxTextCtrl
*textCtrl
= wxDynamicCast( wxFindControlFromMacControl(control
) , wxTextCtrl
) ;
2790 wxMacMLTEClassicControl
* win
= textCtrl
? (wxMacMLTEClassicControl
*)(textCtrl
->GetPeer()) : NULL
;
2792 win
->MacControlUserPaneDrawProc( part
) ;
2795 static pascal ControlPartCode
wxMacControlUserPaneHitTestProc(ControlRef control
, Point where
)
2797 wxTextCtrl
*textCtrl
= wxDynamicCast( wxFindControlFromMacControl(control
) , wxTextCtrl
) ;
2798 wxMacMLTEClassicControl
* win
= textCtrl
? (wxMacMLTEClassicControl
*)(textCtrl
->GetPeer()) : NULL
;
2800 return win
->MacControlUserPaneHitTestProc( where
.h
, where
.v
) ;
2802 return kControlNoPart
;
2805 static pascal ControlPartCode
wxMacControlUserPaneTrackingProc(ControlRef control
, Point startPt
, ControlActionUPP actionProc
)
2807 wxTextCtrl
*textCtrl
= wxDynamicCast( wxFindControlFromMacControl(control
) , wxTextCtrl
) ;
2808 wxMacMLTEClassicControl
* win
= textCtrl
? (wxMacMLTEClassicControl
*)(textCtrl
->GetPeer()) : NULL
;
2810 return win
->MacControlUserPaneTrackingProc( startPt
.h
, startPt
.v
, (void*) actionProc
) ;
2812 return kControlNoPart
;
2815 static pascal void wxMacControlUserPaneIdleProc(ControlRef control
)
2817 wxTextCtrl
*textCtrl
= wxDynamicCast( wxFindControlFromMacControl(control
) , wxTextCtrl
) ;
2818 wxMacMLTEClassicControl
* win
= textCtrl
? (wxMacMLTEClassicControl
*)(textCtrl
->GetPeer()) : NULL
;
2820 win
->MacControlUserPaneIdleProc() ;
2823 static pascal ControlPartCode
wxMacControlUserPaneKeyDownProc(ControlRef control
, SInt16 keyCode
, SInt16 charCode
, SInt16 modifiers
)
2825 wxTextCtrl
*textCtrl
= wxDynamicCast( wxFindControlFromMacControl(control
) , wxTextCtrl
) ;
2826 wxMacMLTEClassicControl
* win
= textCtrl
? (wxMacMLTEClassicControl
*)(textCtrl
->GetPeer()) : NULL
;
2828 return win
->MacControlUserPaneKeyDownProc( keyCode
, charCode
, modifiers
) ;
2830 return kControlNoPart
;
2833 static pascal void wxMacControlUserPaneActivateProc(ControlRef control
, Boolean activating
)
2835 wxTextCtrl
*textCtrl
= wxDynamicCast( wxFindControlFromMacControl(control
) , wxTextCtrl
) ;
2836 wxMacMLTEClassicControl
* win
= textCtrl
? (wxMacMLTEClassicControl
*)(textCtrl
->GetPeer()) : NULL
;
2838 win
->MacControlUserPaneActivateProc( activating
) ;
2841 static pascal ControlPartCode
wxMacControlUserPaneFocusProc(ControlRef control
, ControlFocusPart action
)
2843 wxTextCtrl
*textCtrl
= wxDynamicCast( wxFindControlFromMacControl(control
) , wxTextCtrl
) ;
2844 wxMacMLTEClassicControl
* win
= textCtrl
? (wxMacMLTEClassicControl
*)(textCtrl
->GetPeer()) : NULL
;
2846 return win
->MacControlUserPaneFocusProc( action
) ;
2848 return kControlNoPart
;
2852 static pascal void wxMacControlUserPaneBackgroundProc(ControlRef control
, ControlBackgroundPtr info
)
2854 wxTextCtrl
*textCtrl
= wxDynamicCast( wxFindControlFromMacControl(control
) , wxTextCtrl
) ;
2855 wxMacMLTEClassicControl
* win
= textCtrl
? (wxMacMLTEClassicControl
*)(textCtrl
->GetPeer()) : NULL
;
2857 win
->MacControlUserPaneBackgroundProc(info
) ;
2861 // TXNRegisterScrollInfoProc
2863 OSStatus
wxMacMLTEClassicControl::DoCreate()
2866 OSStatus err
= noErr
;
2868 // set up our globals
2869 if (gTPDrawProc
== NULL
) gTPDrawProc
= NewControlUserPaneDrawUPP(wxMacControlUserPaneDrawProc
);
2870 if (gTPHitProc
== NULL
) gTPHitProc
= NewControlUserPaneHitTestUPP(wxMacControlUserPaneHitTestProc
);
2871 if (gTPTrackProc
== NULL
) gTPTrackProc
= NewControlUserPaneTrackingUPP(wxMacControlUserPaneTrackingProc
);
2872 if (gTPIdleProc
== NULL
) gTPIdleProc
= NewControlUserPaneIdleUPP(wxMacControlUserPaneIdleProc
);
2873 if (gTPKeyProc
== NULL
) gTPKeyProc
= NewControlUserPaneKeyDownUPP(wxMacControlUserPaneKeyDownProc
);
2874 if (gTPActivateProc
== NULL
) gTPActivateProc
= NewControlUserPaneActivateUPP(wxMacControlUserPaneActivateProc
);
2875 if (gTPFocusProc
== NULL
) gTPFocusProc
= NewControlUserPaneFocusUPP(wxMacControlUserPaneFocusProc
);
2877 if (gTXNScrollInfoProc
== NULL
) gTXNScrollInfoProc
= NewTXNScrollInfoUPP(TXNScrollInfoProc
) ;
2878 if (gTXNScrollActionProc
== NULL
) gTXNScrollActionProc
= NewControlActionUPP(TXNScrollActionProc
) ;
2880 // set the initial settings for our private data
2882 m_txnWindow
= GetControlOwner(m_controlRef
);
2883 m_txnPort
= (GrafPtr
) GetWindowPort(m_txnWindow
);
2885 // set up the user pane procedures
2886 SetControlData(m_controlRef
, kControlEntireControl
, kControlUserPaneDrawProcTag
, sizeof(gTPDrawProc
), &gTPDrawProc
);
2887 SetControlData(m_controlRef
, kControlEntireControl
, kControlUserPaneHitTestProcTag
, sizeof(gTPHitProc
), &gTPHitProc
);
2888 SetControlData(m_controlRef
, kControlEntireControl
, kControlUserPaneTrackingProcTag
, sizeof(gTPTrackProc
), &gTPTrackProc
);
2889 SetControlData(m_controlRef
, kControlEntireControl
, kControlUserPaneIdleProcTag
, sizeof(gTPIdleProc
), &gTPIdleProc
);
2890 SetControlData(m_controlRef
, kControlEntireControl
, kControlUserPaneKeyDownProcTag
, sizeof(gTPKeyProc
), &gTPKeyProc
);
2891 SetControlData(m_controlRef
, kControlEntireControl
, kControlUserPaneActivateProcTag
, sizeof(gTPActivateProc
), &gTPActivateProc
);
2892 SetControlData(m_controlRef
, kControlEntireControl
, kControlUserPaneFocusProcTag
, sizeof(gTPFocusProc
), &gTPFocusProc
);
2894 // calculate the rectangles used by the control
2895 GetRectInWindowCoords( &bounds
);
2897 m_txnControlBounds
= bounds
;
2898 m_txnVisBounds
= bounds
;
2903 GetGWorld( &origPort
, &origDev
) ;
2904 SetPort( m_txnPort
);
2906 // create the new edit field
2907 TXNFrameOptions frameOptions
= FrameOptionsFromWXStyle( m_windowStyle
);
2909 // the scrollbars are not correctly embedded but are inserted at the root:
2910 // this gives us problems as we have erratic redraws even over the structure area
2912 m_sbHorizontal
= 0 ;
2914 m_lastHorizontalValue
= 0 ;
2915 m_lastVerticalValue
= 0 ;
2917 Rect sb
= { 0 , 0 , 0 , 0 } ;
2918 if ( frameOptions
& kTXNWantVScrollBarMask
)
2920 CreateScrollBarControl( m_txnWindow
, &sb
, 0, 0, 100, 1, true, gTXNScrollActionProc
, &m_sbVertical
);
2921 SetControlReference( m_sbVertical
, (SInt32
)this );
2922 SetControlAction( m_sbVertical
, gTXNScrollActionProc
);
2923 ShowControl( m_sbVertical
);
2924 EmbedControl( m_sbVertical
, m_controlRef
);
2925 frameOptions
&= ~kTXNWantVScrollBarMask
;
2928 if ( frameOptions
& kTXNWantHScrollBarMask
)
2930 CreateScrollBarControl( m_txnWindow
, &sb
, 0, 0, 100, 1, true, gTXNScrollActionProc
, &m_sbHorizontal
);
2931 SetControlReference( m_sbHorizontal
, (SInt32
)this );
2932 SetControlAction( m_sbHorizontal
, gTXNScrollActionProc
);
2933 ShowControl( m_sbHorizontal
);
2934 EmbedControl( m_sbHorizontal
, m_controlRef
);
2935 frameOptions
&= ~(kTXNWantHScrollBarMask
| kTXNDrawGrowIconMask
);
2939 NULL
, m_txnWindow
, &bounds
, frameOptions
,
2940 kTXNTextEditStyleFrameType
, kTXNTextensionFile
, kTXNSystemDefaultEncoding
,
2941 &m_txn
, &m_txnFrameID
, NULL
);
2942 verify_noerr( err
);
2945 TXNControlTag iControlTags
[] = { kTXNUseCarbonEvents
};
2946 TXNControlData iControlData
[] = { { (UInt32
)&cInfo
} };
2947 int toptag
= WXSIZEOF( iControlTags
) ;
2948 TXNCarbonEventInfo cInfo
;
2949 cInfo
.useCarbonEvents
= false ;
2952 cInfo
.fDictionary
= NULL
;
2954 verify_noerr( TXNSetTXNObjectControls( m_txn
, false, toptag
, iControlTags
, iControlData
) );
2957 TXNRegisterScrollInfoProc( m_txn
, gTXNScrollInfoProc
, (SInt32
)this );
2959 SetGWorld( origPort
, origDev
) ;
2965 // ----------------------------------------------------------------------------
2966 // MLTE control implementation (OSX part)
2967 // ----------------------------------------------------------------------------
2969 // tiger multi-line textcontrols with no CR in the entire content
2970 // don't scroll automatically, so we need a hack.
2971 // This attempt only works 'before' the key (ie before CallNextEventHandler)
2972 // is processed, thus the scrolling always occurs one character too late, but
2973 // better than nothing ...
2975 static const EventTypeSpec eventList
[] =
2977 { kEventClassTextInput
, kEventTextInputUnicodeForKeyEvent
} ,
2980 static pascal OSStatus
wxMacUnicodeTextEventHandler( EventHandlerCallRef handler
, EventRef event
, void *data
)
2982 OSStatus result
= eventNotHandledErr
;
2983 wxMacMLTEHIViewControl
* focus
= (wxMacMLTEHIViewControl
*) data
;
2985 switch ( GetEventKind( event
) )
2987 case kEventTextInputUnicodeForKeyEvent
:
2989 TXNOffset from
, to
;
2990 TXNGetSelection( focus
->GetTXNObject() , &from
, &to
) ;
2992 TXNShowSelection( focus
->GetTXNObject() , kTXNShowStart
);
2993 result
= CallNextEventHandler(handler
,event
);
3003 static pascal OSStatus
wxMacTextControlEventHandler( EventHandlerCallRef handler
, EventRef event
, void *data
)
3005 OSStatus result
= eventNotHandledErr
;
3007 switch ( GetEventClass( event
) )
3009 case kEventClassTextInput
:
3010 result
= wxMacUnicodeTextEventHandler( handler
, event
, data
) ;
3019 DEFINE_ONE_SHOT_HANDLER_GETTER( wxMacTextControlEventHandler
)
3021 wxMacMLTEHIViewControl::wxMacMLTEHIViewControl( wxTextCtrl
*wxPeer
,
3022 const wxString
& str
,
3024 const wxSize
& size
, long style
) : wxMacMLTEControl( wxPeer
)
3026 m_font
= wxPeer
->GetFont() ;
3027 m_windowStyle
= style
;
3028 Rect bounds
= wxMacGetBoundsForControl( wxPeer
, pos
, size
) ;
3030 wxMacConvertNewlines10To13( &st
) ;
3033 { bounds
.left
, bounds
.top
},
3034 { bounds
.right
- bounds
.left
, bounds
.bottom
- bounds
.top
} } ;
3036 m_scrollView
= NULL
;
3037 TXNFrameOptions frameOptions
= FrameOptionsFromWXStyle( style
) ;
3038 if (( frameOptions
& (kTXNWantVScrollBarMask
| kTXNWantHScrollBarMask
)) || (frameOptions
&kTXNSingleLineOnlyMask
))
3040 if ( frameOptions
& (kTXNWantVScrollBarMask
| kTXNWantHScrollBarMask
) )
3043 (frameOptions
& kTXNWantHScrollBarMask
? kHIScrollViewOptionsHorizScroll
: 0)
3044 | (frameOptions
& kTXNWantVScrollBarMask
? kHIScrollViewOptionsVertScroll
: 0) ,
3049 HIScrollViewCreate(kHIScrollViewOptionsVertScroll
,&m_scrollView
);
3050 HIScrollViewSetScrollBarAutoHide(m_scrollView
,true);
3053 HIViewSetFrame( m_scrollView
, &hr
);
3054 HIViewSetVisible( m_scrollView
, true );
3058 HITextViewCreate( NULL
, 0, frameOptions
, &m_textView
) ;
3059 m_txn
= HITextViewGetTXNObject( m_textView
) ;
3060 HIViewSetVisible( m_textView
, true ) ;
3063 HIViewAddSubview( m_scrollView
, m_textView
) ;
3064 m_controlRef
= m_scrollView
;
3065 wxPeer
->MacInstallEventHandler( (WXWidget
) m_textView
) ;
3069 HIViewSetFrame( m_textView
, &hr
);
3070 m_controlRef
= m_textView
;
3073 AdjustCreationAttributes( *wxWHITE
, true ) ;
3075 wxMacWindowClipper
c( m_peer
) ;
3077 SetTXNData( st
, kTXNStartOffset
, kTXNEndOffset
) ;
3079 TXNSetSelection( m_txn
, 0, 0 );
3080 TXNShowSelection( m_txn
, kTXNShowStart
);
3082 InstallControlEventHandler( m_textView
, GetwxMacTextControlEventHandlerUPP(),
3083 GetEventTypeCount(eventList
), eventList
, this,
3087 wxMacMLTEHIViewControl::~wxMacMLTEHIViewControl()
3091 OSStatus
wxMacMLTEHIViewControl::SetFocus( ControlFocusPart focusPart
)
3093 return SetKeyboardFocus( GetControlOwner( m_textView
), m_textView
, focusPart
) ;
3096 bool wxMacMLTEHIViewControl::HasFocus() const
3098 ControlRef control
;
3099 if ( GetUserFocusWindow() == NULL
)
3102 GetKeyboardFocus( GetUserFocusWindow() , &control
) ;
3103 return control
== m_textView
;
3106 void wxMacMLTEHIViewControl::SetBackgroundColour(const wxColour
& col
)
3108 HITextViewSetBackgroundColor( m_textView
, col
.GetPixel() );
3111 #endif // wxUSE_TEXTCTRL