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/osx/uma.h"
50 #include "wx/osx/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 Move(int x
, int y
, int width
, int height
);
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
&& key
!= WXK_UP
&& key
!= WXK_DOWN
&&
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 void wxMacTextControl::SetFont( const wxFont
& font
, const wxColour
& foreground
, long windowStyle
)
1259 wxMacControl::SetFont(font
, foreground
, windowStyle
);
1262 // overrule the barrier in wxMacControl for supporting disabled controls, in order to support
1263 // setting the color to eg red and back to black by controllers
1265 if ( foreground
== *wxBLACK
)
1267 ControlFontStyleRec fontStyle
;
1268 fontStyle
.foreColor
.red
= fontStyle
.foreColor
.green
= fontStyle
.foreColor
.blue
= 0;
1269 fontStyle
.flags
= kControlUseForeColorMask
;
1270 ::SetControlFontStyle( m_controlRef
, &fontStyle
);
1275 // ----------------------------------------------------------------------------
1276 // standard unicode control implementation
1277 // ----------------------------------------------------------------------------
1279 // the current unicode textcontrol implementation has a bug : only if the control
1280 // is currently having the focus, the selection can be retrieved by the corresponding
1281 // data tag. So we have a mirroring using a member variable
1282 // TODO : build event table using virtual member functions for wxMacControl
1284 static const EventTypeSpec unicodeTextControlEventList
[] =
1286 { kEventClassControl
, kEventControlSetFocusPart
} ,
1289 static pascal OSStatus
wxMacUnicodeTextControlControlEventHandler( EventHandlerCallRef handler
, EventRef event
, void *data
)
1291 OSStatus result
= eventNotHandledErr
;
1292 wxMacUnicodeTextControl
* focus
= (wxMacUnicodeTextControl
*) data
;
1293 wxMacCarbonEvent
cEvent( event
) ;
1295 switch ( GetEventKind( event
) )
1297 case kEventControlSetFocusPart
:
1299 ControlPartCode controlPart
= cEvent
.GetParameter
<ControlPartCode
>(kEventParamControlPart
, typeControlPartCode
);
1300 if ( controlPart
== kControlFocusNoPart
)
1302 // about to loose focus -> store selection to field
1303 focus
->GetData
<ControlEditTextSelectionRec
>( 0, kControlEditTextSelectionTag
, &focus
->m_selection
);
1305 result
= CallNextEventHandler(handler
,event
) ;
1306 if ( controlPart
!= kControlFocusNoPart
)
1308 // about to gain focus -> set selection from field
1309 focus
->SetData
<ControlEditTextSelectionRec
>( 0, kControlEditTextSelectionTag
, &focus
->m_selection
);
1320 static pascal OSStatus
wxMacUnicodeTextControlEventHandler( EventHandlerCallRef handler
, EventRef event
, void *data
)
1322 OSStatus result
= eventNotHandledErr
;
1324 switch ( GetEventClass( event
) )
1326 case kEventClassControl
:
1327 result
= wxMacUnicodeTextControlControlEventHandler( handler
, event
, data
) ;
1336 DEFINE_ONE_SHOT_HANDLER_GETTER( wxMacUnicodeTextControlEventHandler
)
1338 wxMacUnicodeTextControl::wxMacUnicodeTextControl( wxTextCtrl
*wxPeer
) : wxMacTextControl( wxPeer
)
1342 wxMacUnicodeTextControl::wxMacUnicodeTextControl( wxTextCtrl
*wxPeer
,
1343 const wxString
& str
,
1345 const wxSize
& size
, long style
)
1346 : wxMacTextControl( wxPeer
)
1348 Create( wxPeer
, str
, pos
, size
, style
);
1351 bool wxMacUnicodeTextControl::Create( wxTextCtrl
*wxPeer
,
1352 const wxString
& str
,
1354 const wxSize
& size
, long style
)
1356 m_font
= wxPeer
->GetFont() ;
1357 m_windowStyle
= style
;
1358 m_selection
.selStart
= m_selection
.selEnd
= 0;
1359 Rect bounds
= wxMacGetBoundsForControl( wxPeer
, pos
, size
) ;
1361 wxMacConvertNewlines10To13( &st
) ;
1362 wxCFStringRef
cf(st
, m_font
.GetEncoding()) ;
1363 CFStringRef cfr
= cf
;
1365 m_valueTag
= kControlEditTextCFStringTag
;
1366 CreateControl( wxPeer
, &bounds
, cfr
);
1368 if ( !(m_windowStyle
& wxTE_MULTILINE
) )
1369 SetData
<Boolean
>( kControlEditTextPart
, kControlEditTextSingleLineTag
, true ) ;
1371 ::InstallControlEventHandler( m_controlRef
, GetwxMacUnicodeTextControlEventHandlerUPP(),
1372 GetEventTypeCount(unicodeTextControlEventList
), unicodeTextControlEventList
, this,
1378 wxMacUnicodeTextControl::~wxMacUnicodeTextControl()
1382 void wxMacUnicodeTextControl::VisibilityChanged(bool shown
)
1384 if ( !(m_windowStyle
& wxTE_MULTILINE
) && shown
)
1386 // work around a refresh issue insofar as not always the entire content is shown,
1387 // even if this would be possible
1388 ControlEditTextSelectionRec sel
;
1389 CFStringRef value
= NULL
;
1391 verify_noerr( GetData
<ControlEditTextSelectionRec
>( 0, kControlEditTextSelectionTag
, &sel
) );
1392 verify_noerr( GetData
<CFStringRef
>( 0, m_valueTag
, &value
) );
1393 verify_noerr( SetData
<CFStringRef
>( 0, m_valueTag
, &value
) );
1394 verify_noerr( SetData
<ControlEditTextSelectionRec
>( 0, kControlEditTextSelectionTag
, &sel
) );
1396 CFRelease( value
) ;
1400 wxString
wxMacUnicodeTextControl::GetStringValue() const
1403 CFStringRef value
= GetData
<CFStringRef
>(0, m_valueTag
) ;
1406 wxCFStringRef
cf(value
) ;
1407 result
= cf
.AsString() ;
1411 wxMacConvertNewlines13To10( &result
) ;
1413 wxMacConvertNewlines10To13( &result
) ;
1419 void wxMacUnicodeTextControl::SetStringValue( const wxString
&str
)
1422 wxMacConvertNewlines10To13( &st
) ;
1423 wxCFStringRef
cf( st
, m_font
.GetEncoding() ) ;
1424 verify_noerr( SetData
<CFStringRef
>( 0, m_valueTag
, cf
) ) ;
1427 void wxMacUnicodeTextControl::CreateControl( wxTextCtrl
* peer
, const Rect
* bounds
, CFStringRef cfr
)
1429 Boolean isPassword
= ( m_windowStyle
& wxTE_PASSWORD
) != 0 ;
1432 m_valueTag
= kControlEditTextPasswordCFStringTag
;
1434 OSStatus err
= CreateEditUnicodeTextControl(
1435 MAC_WXHWND(peer
->MacGetTopLevelWindowRef()), bounds
, cfr
,
1436 isPassword
, NULL
, &m_controlRef
) ;
1437 verify_noerr( err
);
1440 void wxMacUnicodeTextControl::Copy()
1442 SendHICommand( kHICommandCopy
) ;
1445 void wxMacUnicodeTextControl::Cut()
1447 SendHICommand( kHICommandCut
) ;
1450 void wxMacUnicodeTextControl::Paste()
1452 SendHICommand( kHICommandPaste
) ;
1455 bool wxMacUnicodeTextControl::CanPaste() const
1460 void wxMacUnicodeTextControl::SetEditable(bool WXUNUSED(editable
))
1462 #if 0 // leads to problem because text cannot be selected anymore
1463 SetData
<Boolean
>( kControlEditTextPart
, kControlEditTextLockedTag
, (Boolean
) !editable
) ;
1467 void wxMacUnicodeTextControl::GetSelection( long* from
, long* to
) const
1469 ControlEditTextSelectionRec sel
;
1471 verify_noerr( GetData
<ControlEditTextSelectionRec
>( 0, kControlEditTextSelectionTag
, &sel
) ) ;
1476 *from
= sel
.selStart
;
1481 void wxMacUnicodeTextControl::SetSelection( long from
, long to
)
1483 ControlEditTextSelectionRec sel
;
1485 int textLength
= 0 ;
1486 CFStringRef value
= GetData
<CFStringRef
>(0, m_valueTag
) ;
1489 wxCFStringRef
cf(value
) ;
1490 textLength
= cf
.AsString().length() ;
1493 if ((from
== -1) && (to
== -1))
1500 from
= wxMin(textLength
,wxMax(from
,0)) ;
1504 to
= wxMax(0,wxMin(textLength
,to
)) ;
1507 sel
.selStart
= from
;
1510 SetData
<ControlEditTextSelectionRec
>( 0, kControlEditTextSelectionTag
, &sel
) ;
1515 void wxMacUnicodeTextControl::WriteText( const wxString
& str
)
1518 wxMacConvertNewlines10To13( &st
) ;
1522 wxCFStringRef
cf(st
, m_font
.GetEncoding() ) ;
1523 CFStringRef value
= cf
;
1524 SetData
<CFStringRef
>( 0, kControlEditTextInsertCFStringRefTag
, &value
);
1528 wxString val
= GetStringValue() ;
1530 GetSelection( &start
, &end
) ;
1531 val
.Remove( start
, end
- start
) ;
1532 val
.insert( start
, str
) ;
1533 SetStringValue( val
) ;
1534 SetSelection( start
+ str
.length() , start
+ str
.length() ) ;
1538 // ----------------------------------------------------------------------------
1539 // MLTE control implementation (common part)
1540 // ----------------------------------------------------------------------------
1542 // if MTLE is read only, no changes at all are allowed, not even from
1543 // procedural API, in order to allow changes via API all the same we must undo
1544 // the readonly status while we are executing, this class helps to do so
1546 class wxMacEditHelper
1549 wxMacEditHelper( TXNObject txn
)
1551 TXNControlTag tag
[] = { kTXNIOPrivilegesTag
} ;
1553 TXNGetTXNObjectControls( m_txn
, 1 , tag
, m_data
) ;
1554 if ( m_data
[0].uValue
== kTXNReadOnly
)
1556 TXNControlData data
[] = { { kTXNReadWrite
} } ;
1557 TXNSetTXNObjectControls( m_txn
, false , 1 , tag
, data
) ;
1563 TXNControlTag tag
[] = { kTXNIOPrivilegesTag
} ;
1564 if ( m_data
[0].uValue
== kTXNReadOnly
)
1565 TXNSetTXNObjectControls( m_txn
, false , 1 , tag
, m_data
) ;
1570 TXNControlData m_data
[1] ;
1573 wxMacMLTEControl::wxMacMLTEControl( wxTextCtrl
*peer
)
1574 : wxMacTextControl( peer
)
1576 SetNeedsFocusRect( true ) ;
1579 wxString
wxMacMLTEControl::GetStringValue() const
1583 Size actualSize
= 0;
1588 err
= TXNGetDataEncoded( m_txn
, kTXNStartOffset
, kTXNEndOffset
, &theText
, kTXNUnicodeTextData
);
1597 actualSize
= GetHandleSize( theText
) / sizeof(UniChar
) ;
1598 if ( actualSize
> 0 )
1600 wxChar
*ptr
= NULL
;
1602 #if SIZEOF_WCHAR_T == 2
1603 ptr
= new wxChar
[actualSize
+ 1] ;
1604 wxStrncpy( ptr
, (wxChar
*)(*theText
) , actualSize
) ;
1606 SetHandleSize( theText
, (actualSize
+ 1) * sizeof(UniChar
) ) ;
1608 (((UniChar
*)*theText
)[actualSize
]) = 0 ;
1609 wxMBConvUTF16 converter
;
1610 size_t noChars
= converter
.MB2WC( NULL
, (const char*)*theText
, 0 ) ;
1611 wxASSERT_MSG( noChars
!= wxCONV_FAILED
, _T("Unable to count the number of characters in this string!") );
1612 ptr
= new wxChar
[noChars
+ 1] ;
1614 noChars
= converter
.MB2WC( ptr
, (const char*)*theText
, noChars
+ 1 ) ;
1615 wxASSERT_MSG( noChars
!= wxCONV_FAILED
, _T("Conversion of string failed!") );
1617 HUnlock( theText
) ;
1620 ptr
[actualSize
] = 0 ;
1621 result
= wxString( ptr
) ;
1625 DisposeHandle( theText
) ;
1629 err
= TXNGetDataEncoded( m_txn
, kTXNStartOffset
, kTXNEndOffset
, &theText
, kTXNTextData
);
1638 actualSize
= GetHandleSize( theText
) ;
1639 if ( actualSize
> 0 )
1642 result
= wxString( *theText
, wxConvLocal
, actualSize
) ;
1643 HUnlock( theText
) ;
1646 DisposeHandle( theText
) ;
1652 wxMacConvertNewlines13To10( &result
) ;
1654 wxMacConvertNewlines10To13( &result
) ;
1660 void wxMacMLTEControl::SetStringValue( const wxString
&str
)
1663 wxMacConvertNewlines10To13( &st
);
1667 wxMacWindowClipper
c( GetWXPeer() ) ;
1671 wxMacEditHelper
help( m_txn
);
1672 SetTXNData( st
, kTXNStartOffset
, kTXNEndOffset
);
1675 TXNSetSelection( m_txn
, 0, 0 );
1676 TXNShowSelection( m_txn
, kTXNShowStart
);
1680 TXNFrameOptions
wxMacMLTEControl::FrameOptionsFromWXStyle( long wxStyle
)
1682 TXNFrameOptions frameOptions
= kTXNDontDrawCaretWhenInactiveMask
;
1684 frameOptions
|= kTXNDoFontSubstitutionMask
;
1686 if ( ! (wxStyle
& wxTE_NOHIDESEL
) )
1687 frameOptions
|= kTXNDontDrawSelectionWhenInactiveMask
;
1689 if ( wxStyle
& (wxHSCROLL
| wxTE_DONTWRAP
) )
1690 frameOptions
|= kTXNWantHScrollBarMask
;
1692 if ( wxStyle
& wxTE_MULTILINE
)
1694 if ( ! (wxStyle
& wxTE_DONTWRAP
) )
1695 frameOptions
|= kTXNAlwaysWrapAtViewEdgeMask
;
1697 if ( !(wxStyle
& wxTE_NO_VSCROLL
) )
1699 frameOptions
|= kTXNWantVScrollBarMask
;
1701 // The following code causes drawing problems on 10.4. Perhaps it can be restored for
1702 // older versions of the OS, but I'm not sure it's appropriate to put a grow icon here
1703 // anyways, as AFAIK users can't actually use it to resize the text ctrl.
1704 // if ( frameOptions & kTXNWantHScrollBarMask )
1705 // frameOptions |= kTXNDrawGrowIconMask ;
1710 frameOptions
|= kTXNSingleLineOnlyMask
;
1713 return frameOptions
;
1716 void wxMacMLTEControl::AdjustCreationAttributes(const wxColour
&background
,
1717 bool WXUNUSED(visible
))
1719 TXNControlTag iControlTags
[] =
1721 kTXNDoFontSubstitution
,
1722 kTXNWordWrapStateTag
,
1724 TXNControlData iControlData
[] =
1730 int toptag
= WXSIZEOF( iControlTags
) ;
1732 if ( m_windowStyle
& wxTE_MULTILINE
)
1734 iControlData
[1].uValue
=
1735 (m_windowStyle
& wxTE_DONTWRAP
)
1740 OSStatus err
= TXNSetTXNObjectControls( m_txn
, false, toptag
, iControlTags
, iControlData
) ;
1741 verify_noerr( err
);
1743 // setting the default font:
1744 // under 10.2 this causes a visible caret, therefore we avoid it
1750 GetThemeFont( kThemeSystemFont
, GetApplicationScript() , fontName
, &fontSize
, &fontStyle
) ;
1752 TXNTypeAttributes typeAttr
[] =
1754 { kTXNQDFontNameAttribute
, kTXNQDFontNameAttributeSize
, { (void*) fontName
} } ,
1755 { kTXNQDFontSizeAttribute
, kTXNFontSizeAttributeSize
, { (void*) (fontSize
<< 16) } } ,
1756 { kTXNQDFontStyleAttribute
, kTXNQDFontStyleAttributeSize
, { (void*) normal
} } ,
1759 err
= TXNSetTypeAttributes(
1760 m_txn
, sizeof(typeAttr
) / sizeof(TXNTypeAttributes
),
1761 typeAttr
, kTXNStartOffset
, kTXNEndOffset
);
1762 verify_noerr( err
);
1764 if ( m_windowStyle
& wxTE_PASSWORD
)
1766 UniChar c
= 0x00A5 ;
1767 err
= TXNEchoMode( m_txn
, c
, 0 , true );
1768 verify_noerr( err
);
1771 TXNBackground tback
;
1772 tback
.bgType
= kTXNBackgroundTypeRGB
;
1773 background
.GetRGBColor( &tback
.bg
.color
);
1774 TXNSetBackground( m_txn
, &tback
);
1777 TXNCommandEventSupportOptions options
;
1778 if ( TXNGetCommandEventSupport( m_txn
, &options
) == noErr
)
1781 kTXNSupportEditCommandProcessing
1782 | kTXNSupportEditCommandUpdating
1783 | kTXNSupportFontCommandProcessing
1784 | kTXNSupportFontCommandUpdating
;
1786 // only spell check when not read-only
1787 // use system options for the default
1788 bool checkSpelling
= false ;
1789 if ( !(m_windowStyle
& wxTE_READONLY
) )
1791 #if wxUSE_SYSTEM_OPTIONS
1792 if ( wxSystemOptions::HasOption( wxMAC_TEXTCONTROL_USE_SPELL_CHECKER
) && (wxSystemOptions::GetOptionInt( wxMAC_TEXTCONTROL_USE_SPELL_CHECKER
) == 1) )
1794 checkSpelling
= true ;
1799 if ( checkSpelling
)
1801 kTXNSupportSpellCheckCommandProcessing
1802 | kTXNSupportSpellCheckCommandUpdating
;
1804 TXNSetCommandEventSupport( m_txn
, options
) ;
1808 void wxMacMLTEControl::SetBackgroundColour(const wxColour
& col
)
1810 TXNBackground tback
;
1811 tback
.bgType
= kTXNBackgroundTypeRGB
;
1812 col
.GetRGBColor(&tback
.bg
.color
);
1813 TXNSetBackground( m_txn
, &tback
);
1816 static inline int wxConvertToTXN(int x
)
1818 return wx_static_cast(int, x
/ 254.0 * 72 + 0.5);
1821 void wxMacMLTEControl::TXNSetAttribute( const wxTextAttr
& style
, long from
, long to
)
1823 TXNTypeAttributes typeAttr
[4] ;
1825 size_t typeAttrCount
= 0 ;
1828 TXNControlTag controlTags
[4];
1829 TXNControlData controlData
[4];
1830 size_t controlAttrCount
= 0;
1832 TXNTab
* tabs
= NULL
;
1834 bool relayout
= false;
1837 if ( style
.HasFont() )
1839 wxASSERT( typeAttrCount
< WXSIZEOF(typeAttr
) );
1840 font
= style
.GetFont() ;
1841 typeAttr
[typeAttrCount
].tag
= kTXNATSUIStyle
;
1842 typeAttr
[typeAttrCount
].size
= kTXNATSUIStyleSize
;
1843 typeAttr
[typeAttrCount
].data
.dataPtr
= font
.MacGetATSUStyle() ;
1847 if ( style
.HasTextColour() )
1849 wxASSERT( typeAttrCount
< WXSIZEOF(typeAttr
) );
1850 style
.GetTextColour().GetRGBColor( &color
);
1851 typeAttr
[typeAttrCount
].tag
= kTXNQDFontColorAttribute
;
1852 typeAttr
[typeAttrCount
].size
= kTXNQDFontColorAttributeSize
;
1853 typeAttr
[typeAttrCount
].data
.dataPtr
= (void*) &color
;
1857 if ( style
.HasAlignment() )
1859 wxASSERT( controlAttrCount
< WXSIZEOF(controlTags
) );
1862 switch ( style
.GetAlignment() )
1864 case wxTEXT_ALIGNMENT_LEFT
:
1865 align
= kTXNFlushLeft
;
1867 case wxTEXT_ALIGNMENT_CENTRE
:
1870 case wxTEXT_ALIGNMENT_RIGHT
:
1871 align
= kTXNFlushRight
;
1873 case wxTEXT_ALIGNMENT_JUSTIFIED
:
1874 align
= kTXNFullJust
;
1877 case wxTEXT_ALIGNMENT_DEFAULT
:
1878 align
= kTXNFlushDefault
;
1882 controlTags
[controlAttrCount
] = kTXNJustificationTag
;
1883 controlData
[controlAttrCount
].sValue
= align
;
1884 controlAttrCount
++ ;
1887 if ( style
.HasLeftIndent() || style
.HasRightIndent() )
1889 wxASSERT( controlAttrCount
< WXSIZEOF(controlTags
) );
1890 controlTags
[controlAttrCount
] = kTXNMarginsTag
;
1891 controlData
[controlAttrCount
].marginsPtr
= &margins
;
1892 verify_noerr( TXNGetTXNObjectControls (m_txn
, 1 ,
1893 &controlTags
[controlAttrCount
], &controlData
[controlAttrCount
]) );
1894 if ( style
.HasLeftIndent() )
1896 margins
.leftMargin
= wxConvertToTXN(style
.GetLeftIndent());
1898 if ( style
.HasRightIndent() )
1900 margins
.rightMargin
= wxConvertToTXN(style
.GetRightIndent());
1902 controlAttrCount
++ ;
1905 if ( style
.HasTabs() )
1907 const wxArrayInt
& tabarray
= style
.GetTabs();
1908 // unfortunately Mac only applies a tab distance, not individually different tabs
1909 controlTags
[controlAttrCount
] = kTXNTabSettingsTag
;
1910 if ( tabarray
.size() > 0 )
1911 controlData
[controlAttrCount
].tabValue
.value
= wxConvertToTXN(tabarray
[0]);
1913 controlData
[controlAttrCount
].tabValue
.value
= 72 ;
1915 controlData
[controlAttrCount
].tabValue
.tabType
= kTXNLeftTab
;
1916 controlAttrCount
++ ;
1919 // unfortunately the relayout is not automatic
1920 if ( controlAttrCount
> 0 )
1922 verify_noerr( TXNSetTXNObjectControls (m_txn
, false /* don't clear all */, controlAttrCount
,
1923 controlTags
, controlData
) );
1927 if ( typeAttrCount
> 0 )
1929 verify_noerr( TXNSetTypeAttributes( m_txn
, typeAttrCount
, typeAttr
, from
, to
) );
1940 TXNRecalcTextLayout( m_txn
);
1944 void wxMacMLTEControl::SetFont(const wxFont
& font
,
1945 const wxColour
& foreground
,
1946 long WXUNUSED(windowStyle
))
1948 wxMacEditHelper
help( m_txn
) ;
1949 TXNSetAttribute( wxTextAttr( foreground
, wxNullColour
, font
), kTXNStartOffset
, kTXNEndOffset
) ;
1952 void wxMacMLTEControl::SetStyle( long start
, long end
, const wxTextAttr
& style
)
1954 wxMacEditHelper
help( m_txn
) ;
1955 TXNSetAttribute( style
, start
, end
) ;
1958 void wxMacMLTEControl::Copy()
1963 void wxMacMLTEControl::Cut()
1968 void wxMacMLTEControl::Paste()
1973 bool wxMacMLTEControl::CanPaste() const
1975 return TXNIsScrapPastable() ;
1978 void wxMacMLTEControl::SetEditable(bool editable
)
1980 TXNControlTag tag
[] = { kTXNIOPrivilegesTag
} ;
1981 TXNControlData data
[] = { { editable
? kTXNReadWrite
: kTXNReadOnly
} } ;
1982 TXNSetTXNObjectControls( m_txn
, false, WXSIZEOF(tag
), tag
, data
) ;
1985 wxTextPos
wxMacMLTEControl::GetLastPosition() const
1987 wxTextPos actualsize
= 0 ;
1990 OSErr err
= TXNGetDataEncoded( m_txn
, kTXNStartOffset
, kTXNEndOffset
, &theText
, kTXNTextData
);
1995 actualsize
= GetHandleSize( theText
) ;
1996 DisposeHandle( theText
) ;
2006 void wxMacMLTEControl::Replace( long from
, long to
, const wxString
&str
)
2008 wxString value
= str
;
2009 wxMacConvertNewlines10To13( &value
) ;
2011 wxMacEditHelper
help( m_txn
) ;
2013 wxMacWindowClipper
c( GetWXPeer() ) ;
2016 TXNSetSelection( m_txn
, from
, to
== -1 ? kTXNEndOffset
: to
) ;
2018 SetTXNData( value
, kTXNUseCurrentSelection
, kTXNUseCurrentSelection
) ;
2021 void wxMacMLTEControl::Remove( long from
, long to
)
2024 wxMacWindowClipper
c( GetWXPeer() ) ;
2026 wxMacEditHelper
help( m_txn
) ;
2027 TXNSetSelection( m_txn
, from
, to
) ;
2031 void wxMacMLTEControl::GetSelection( long* from
, long* to
) const
2034 TXNGetSelection( m_txn
, &f
, &t
) ;
2039 void wxMacMLTEControl::SetSelection( long from
, long to
)
2042 wxMacWindowClipper
c( GetWXPeer() ) ;
2045 // change the selection
2046 if ((from
== -1) && (to
== -1))
2047 TXNSelectAll( m_txn
);
2049 TXNSetSelection( m_txn
, from
, to
== -1 ? kTXNEndOffset
: to
);
2051 TXNShowSelection( m_txn
, kTXNShowStart
);
2054 void wxMacMLTEControl::WriteText( const wxString
& str
)
2057 wxMacConvertNewlines10To13( &st
) ;
2059 long start
, end
, dummy
;
2061 GetSelection( &start
, &dummy
) ;
2063 wxMacWindowClipper
c( GetWXPeer() ) ;
2067 wxMacEditHelper
helper( m_txn
) ;
2068 SetTXNData( st
, kTXNUseCurrentSelection
, kTXNUseCurrentSelection
) ;
2071 GetSelection( &dummy
, &end
) ;
2073 // TODO: SetStyle( start , end , GetDefaultStyle() ) ;
2076 void wxMacMLTEControl::Clear()
2079 wxMacWindowClipper
c( GetWXPeer() ) ;
2081 wxMacEditHelper
st( m_txn
) ;
2082 TXNSetSelection( m_txn
, kTXNStartOffset
, kTXNEndOffset
) ;
2086 bool wxMacMLTEControl::CanUndo() const
2088 return TXNCanUndo( m_txn
, NULL
) ;
2091 void wxMacMLTEControl::Undo()
2096 bool wxMacMLTEControl::CanRedo() const
2098 return TXNCanRedo( m_txn
, NULL
) ;
2101 void wxMacMLTEControl::Redo()
2106 int wxMacMLTEControl::GetNumberOfLines() const
2108 ItemCount lines
= 0 ;
2109 TXNGetLineCount( m_txn
, &lines
) ;
2114 long wxMacMLTEControl::XYToPosition(long x
, long y
) const
2119 // TODO: find a better implementation : while we can get the
2120 // line metrics of a certain line, we don't get its starting
2121 // position, so it would probably be rather a binary search
2122 // for the start position
2123 long xpos
= 0, ypos
= 0 ;
2124 int lastHeight
= 0 ;
2127 lastpos
= GetLastPosition() ;
2128 for ( n
= 0 ; n
<= (ItemCount
) lastpos
; ++n
)
2130 if ( y
== ypos
&& x
== xpos
)
2133 TXNOffsetToPoint( m_txn
, n
, &curpt
) ;
2135 if ( curpt
.v
> lastHeight
)
2141 lastHeight
= curpt
.v
;
2150 bool wxMacMLTEControl::PositionToXY( long pos
, long *x
, long *y
) const
2160 lastpos
= GetLastPosition() ;
2161 if ( pos
<= lastpos
)
2163 // TODO: find a better implementation - while we can get the
2164 // line metrics of a certain line, we don't get its starting
2165 // position, so it would probably be rather a binary search
2166 // for the start position
2167 long xpos
= 0, ypos
= 0 ;
2168 int lastHeight
= 0 ;
2171 for ( n
= 0 ; n
<= (ItemCount
) pos
; ++n
)
2173 TXNOffsetToPoint( m_txn
, n
, &curpt
) ;
2175 if ( curpt
.v
> lastHeight
)
2181 lastHeight
= curpt
.v
;
2196 void wxMacMLTEControl::ShowPosition( long pos
)
2198 Point current
, desired
;
2199 TXNOffset selstart
, selend
;
2201 TXNGetSelection( m_txn
, &selstart
, &selend
);
2202 TXNOffsetToPoint( m_txn
, selstart
, ¤t
);
2203 TXNOffsetToPoint( m_txn
, pos
, &desired
);
2205 // TODO: use HIPoints for 10.3 and above
2207 OSErr theErr
= noErr
;
2208 long dv
= desired
.v
- current
.v
;
2209 long dh
= desired
.h
- current
.h
;
2210 TXNShowSelection( m_txn
, kTXNShowStart
) ; // NB: should this be kTXNShowStart or kTXNShowEnd ??
2211 theErr
= TXNScroll( m_txn
, kTXNScrollUnitsInPixels
, kTXNScrollUnitsInPixels
, &dv
, &dh
);
2213 // there will be an error returned for classic MLTE implementation when the control is
2214 // invisible, but HITextView works correctly, so we don't assert that one
2215 // wxASSERT_MSG( theErr == noErr, _T("TXNScroll returned an error!") );
2218 void wxMacMLTEControl::SetTXNData( const wxString
& st
, TXNOffset start
, TXNOffset end
)
2221 #if SIZEOF_WCHAR_T == 2
2222 size_t len
= st
.length() ;
2223 TXNSetData( m_txn
, kTXNUnicodeTextData
, (void*)st
.wc_str(), len
* 2, start
, end
);
2225 wxMBConvUTF16 converter
;
2226 ByteCount byteBufferLen
= converter
.WC2MB( NULL
, st
.wc_str(), 0 ) ;
2227 UniChar
*unibuf
= (UniChar
*)malloc( byteBufferLen
) ;
2228 converter
.WC2MB( (char*)unibuf
, st
.wc_str(), byteBufferLen
) ;
2229 TXNSetData( m_txn
, kTXNUnicodeTextData
, (void*)unibuf
, byteBufferLen
, start
, end
) ;
2233 wxCharBuffer text
= st
.mb_str( wxConvLocal
) ;
2234 TXNSetData( m_txn
, kTXNTextData
, (void*)text
.data(), strlen( text
), start
, end
) ;
2238 wxString
wxMacMLTEControl::GetLineText(long lineNo
) const
2242 if ( lineNo
< GetNumberOfLines() )
2245 Fixed lineWidth
, lineHeight
, currentHeight
;
2248 // get the first possible position in the control
2249 TXNOffsetToPoint(m_txn
, 0, &firstPoint
);
2251 // Iterate through the lines until we reach the one we want,
2252 // adding to our current y pixel point position
2255 while (ypos
< lineNo
)
2257 TXNGetLineMetrics(m_txn
, ypos
++, &lineWidth
, &lineHeight
);
2258 currentHeight
+= lineHeight
;
2261 Point thePoint
= { firstPoint
.v
+ (currentHeight
>> 16), firstPoint
.h
+ (0) };
2262 TXNOffset theOffset
;
2263 TXNPointToOffset(m_txn
, thePoint
, &theOffset
);
2265 wxString content
= GetStringValue() ;
2266 Point currentPoint
= thePoint
;
2267 while (thePoint
.v
== currentPoint
.v
&& theOffset
< content
.length())
2269 line
+= content
[theOffset
];
2270 TXNOffsetToPoint(m_txn
, ++theOffset
, ¤tPoint
);
2277 int wxMacMLTEControl::GetLineLength(long lineNo
) const
2281 if ( lineNo
< GetNumberOfLines() )
2284 Fixed lineWidth
, lineHeight
, currentHeight
;
2287 // get the first possible position in the control
2288 TXNOffsetToPoint(m_txn
, 0, &firstPoint
);
2290 // Iterate through the lines until we reach the one we want,
2291 // adding to our current y pixel point position
2294 while (ypos
< lineNo
)
2296 TXNGetLineMetrics(m_txn
, ypos
++, &lineWidth
, &lineHeight
);
2297 currentHeight
+= lineHeight
;
2300 Point thePoint
= { firstPoint
.v
+ (currentHeight
>> 16), firstPoint
.h
+ (0) };
2301 TXNOffset theOffset
;
2302 TXNPointToOffset(m_txn
, thePoint
, &theOffset
);
2304 wxString content
= GetStringValue() ;
2305 Point currentPoint
= thePoint
;
2306 while (thePoint
.v
== currentPoint
.v
&& theOffset
< content
.length())
2309 TXNOffsetToPoint(m_txn
, ++theOffset
, ¤tPoint
);
2316 #if MAC_OS_X_VERSION_MIN_REQUIRED < MAC_OS_X_VERSION_10_5
2318 // ----------------------------------------------------------------------------
2319 // MLTE control implementation (classic part)
2320 // ----------------------------------------------------------------------------
2322 // OS X Notes : We still don't have a full replacement for MLTE, so this implementation
2323 // has to live on. We have different problems coming from outdated implementations on the
2324 // various OS X versions. Most deal with the scrollbars: they are not correctly embedded
2325 // while this can be solved on 10.3 by reassigning them the correct place, on 10.2 there is
2326 // no way out, therefore we are using our own implementation and our own scrollbars ....
2328 TXNScrollInfoUPP gTXNScrollInfoProc
= NULL
;
2329 ControlActionUPP gTXNScrollActionProc
= NULL
;
2331 pascal void wxMacMLTEClassicControl::TXNScrollInfoProc(
2332 SInt32 iValue
, SInt32 iMaximumValue
,
2333 TXNScrollBarOrientation iScrollBarOrientation
, SInt32 iRefCon
)
2335 wxMacMLTEClassicControl
* mlte
= (wxMacMLTEClassicControl
*) iRefCon
;
2336 SInt32 value
= wxMax( iValue
, 0 ) ;
2337 SInt32 maximum
= wxMax( iMaximumValue
, 0 ) ;
2339 if ( iScrollBarOrientation
== kTXNHorizontal
)
2341 if ( mlte
->m_sbHorizontal
)
2343 SetControl32BitValue( mlte
->m_sbHorizontal
, value
) ;
2344 SetControl32BitMaximum( mlte
->m_sbHorizontal
, maximum
) ;
2345 mlte
->m_lastHorizontalValue
= value
;
2348 else if ( iScrollBarOrientation
== kTXNVertical
)
2350 if ( mlte
->m_sbVertical
)
2352 SetControl32BitValue( mlte
->m_sbVertical
, value
) ;
2353 SetControl32BitMaximum( mlte
->m_sbVertical
, maximum
) ;
2354 mlte
->m_lastVerticalValue
= value
;
2359 pascal void wxMacMLTEClassicControl::TXNScrollActionProc( ControlRef controlRef
, ControlPartCode partCode
)
2361 wxMacMLTEClassicControl
* mlte
= (wxMacMLTEClassicControl
*) GetControlReference( controlRef
) ;
2365 if ( controlRef
!= mlte
->m_sbVertical
&& controlRef
!= mlte
->m_sbHorizontal
)
2369 bool isHorizontal
= ( controlRef
== mlte
->m_sbHorizontal
) ;
2371 SInt32 minimum
= 0 ;
2372 SInt32 maximum
= GetControl32BitMaximum( controlRef
) ;
2373 SInt32 value
= GetControl32BitValue( controlRef
) ;
2378 case kControlDownButtonPart
:
2382 case kControlUpButtonPart
:
2386 case kControlPageDownPart
:
2387 delta
= GetControlViewSize( controlRef
) ;
2390 case kControlPageUpPart
:
2391 delta
= -GetControlViewSize( controlRef
) ;
2394 case kControlIndicatorPart
:
2395 delta
= value
- (isHorizontal
? mlte
->m_lastHorizontalValue
: mlte
->m_lastVerticalValue
) ;
2404 SInt32 newValue
= value
;
2406 if ( partCode
!= kControlIndicatorPart
)
2408 if ( value
+ delta
< minimum
)
2409 delta
= minimum
- value
;
2410 if ( value
+ delta
> maximum
)
2411 delta
= maximum
- value
;
2413 SetControl32BitValue( controlRef
, value
+ delta
) ;
2414 newValue
= value
+ delta
;
2417 SInt32 verticalDelta
= isHorizontal
? 0 : delta
;
2418 SInt32 horizontalDelta
= isHorizontal
? delta
: 0 ;
2421 mlte
->m_txn
, kTXNScrollUnitsInPixels
, kTXNScrollUnitsInPixels
,
2422 &verticalDelta
, &horizontalDelta
);
2423 verify_noerr( err
);
2426 mlte
->m_lastHorizontalValue
= newValue
;
2428 mlte
->m_lastVerticalValue
= newValue
;
2432 // make correct activations
2433 void wxMacMLTEClassicControl::MacActivatePaneText(bool setActive
)
2435 wxTextCtrl
* textctrl
= (wxTextCtrl
*) GetControlReference(m_controlRef
);
2437 wxMacWindowClipper
clipper( textctrl
) ;
2438 TXNActivate( m_txn
, m_txnFrameID
, setActive
);
2440 ControlRef controlFocus
= 0 ;
2441 GetKeyboardFocus( m_txnWindow
, &controlFocus
) ;
2442 if ( controlFocus
== m_controlRef
)
2443 TXNFocus( m_txn
, setActive
);
2446 void wxMacMLTEClassicControl::MacFocusPaneText(bool setFocus
)
2448 TXNFocus( m_txn
, setFocus
);
2451 // guards against inappropriate redraw (hidden objects drawing onto window)
2453 void wxMacMLTEClassicControl::MacSetObjectVisibility(bool vis
)
2455 ControlRef controlFocus
= 0 ;
2456 GetKeyboardFocus( m_txnWindow
, &controlFocus
) ;
2458 if ( !vis
&& (controlFocus
== m_controlRef
) )
2459 SetKeyboardFocus( m_txnWindow
, m_controlRef
, kControlFocusNoPart
) ;
2461 TXNControlTag iControlTags
[1] = { kTXNVisibilityTag
};
2462 TXNControlData iControlData
[1] = { { (UInt32
)false } };
2464 verify_noerr( TXNGetTXNObjectControls( m_txn
, 1, iControlTags
, iControlData
) ) ;
2466 if ( iControlData
[0].uValue
!= vis
)
2468 iControlData
[0].uValue
= vis
;
2469 verify_noerr( TXNSetTXNObjectControls( m_txn
, false , 1, iControlTags
, iControlData
) ) ;
2472 // currently, we always clip as partial visibility (overlapped) visibility is also a problem,
2473 // if we run into further problems we might set the FrameBounds to an empty rect here
2476 // make sure that the TXNObject is at the right position
2478 void wxMacMLTEClassicControl::MacUpdatePosition()
2480 wxTextCtrl
* textctrl
= (wxTextCtrl
*)GetControlReference( m_controlRef
);
2481 if ( textctrl
== NULL
)
2485 GetRectInWindowCoords( &bounds
);
2487 wxRect visRect
= textctrl
->MacGetClippedClientRect() ;
2488 Rect visBounds
= { visRect
.y
, visRect
.x
, visRect
.y
+ visRect
.height
, visRect
.x
+ visRect
.width
} ;
2491 textctrl
->MacWindowToRootWindow( &x
, &y
) ;
2492 OffsetRect( &visBounds
, x
, y
) ;
2494 if ( !EqualRect( &bounds
, &m_txnControlBounds
) || !EqualRect( &visBounds
, &m_txnVisBounds
) )
2496 m_txnControlBounds
= bounds
;
2497 m_txnVisBounds
= visBounds
;
2498 wxMacWindowClipper
cl( textctrl
) ;
2500 if ( m_sbHorizontal
|| m_sbVertical
)
2502 int w
= bounds
.right
- bounds
.left
;
2503 int h
= bounds
.bottom
- bounds
.top
;
2505 if ( m_sbHorizontal
)
2509 sbBounds
.left
= -1 ;
2510 sbBounds
.top
= h
- 14 ;
2511 sbBounds
.right
= w
+ 1 ;
2512 sbBounds
.bottom
= h
+ 1 ;
2514 SetControlBounds( m_sbHorizontal
, &sbBounds
) ;
2515 SetControlViewSize( m_sbHorizontal
, w
) ;
2522 sbBounds
.left
= w
- 14 ;
2524 sbBounds
.right
= w
+ 1 ;
2525 sbBounds
.bottom
= m_sbHorizontal
? h
- 14 : h
+ 1 ;
2527 SetControlBounds( m_sbVertical
, &sbBounds
) ;
2528 SetControlViewSize( m_sbVertical
, h
) ;
2533 TXNLongRect olddestRect
;
2534 TXNGetRectBounds( m_txn
, &oldviewRect
, &olddestRect
, NULL
) ;
2536 Rect viewRect
= { m_txnControlBounds
.top
, m_txnControlBounds
.left
,
2537 m_txnControlBounds
.bottom
- ( m_sbHorizontal
? 14 : 0 ) ,
2538 m_txnControlBounds
.right
- ( m_sbVertical
? 14 : 0 ) } ;
2539 TXNLongRect destRect
= { m_txnControlBounds
.top
, m_txnControlBounds
.left
,
2540 m_txnControlBounds
.bottom
- ( m_sbHorizontal
? 14 : 0 ) ,
2541 m_txnControlBounds
.right
- ( m_sbVertical
? 14 : 0 ) } ;
2543 if ( olddestRect
.right
>= 10000 )
2544 destRect
.right
= destRect
.left
+ 32000 ;
2546 if ( olddestRect
.bottom
>= 0x20000000 )
2547 destRect
.bottom
= destRect
.top
+ 0x40000000 ;
2549 SectRect( &viewRect
, &visBounds
, &viewRect
) ;
2550 TXNSetRectBounds( m_txn
, &viewRect
, &destRect
, true ) ;
2555 m_txnControlBounds
.top
,
2556 m_txnControlBounds
.left
,
2557 m_txnControlBounds
.bottom
- (m_sbHorizontal
? 14 : 0),
2558 m_txnControlBounds
.right
- (m_sbVertical
? 14 : 0),
2562 // the SetFrameBounds method under Classic sometimes does not correctly scroll a selection into sight after a
2563 // movement, therefore we have to force it
2565 // this problem has been reported in OSX as well, so we use this here once again
2567 TXNLongRect textRect
;
2568 TXNGetRectBounds( m_txn
, NULL
, NULL
, &textRect
) ;
2569 if ( textRect
.left
< m_txnControlBounds
.left
)
2570 TXNShowSelection( m_txn
, kTXNShowStart
) ;
2574 void wxMacMLTEClassicControl::Move(int x
, int y
, int width
, int height
)
2576 wxMacControl::Move(x
,y
,width
,height
) ;
2577 MacUpdatePosition() ;
2580 void wxMacMLTEClassicControl::MacControlUserPaneDrawProc(wxInt16
WXUNUSED(thePart
))
2582 wxTextCtrl
* textctrl
= (wxTextCtrl
*)GetControlReference( m_controlRef
);
2583 if ( textctrl
== NULL
)
2586 if ( textctrl
->IsShownOnScreen() )
2588 wxMacWindowClipper
clipper( textctrl
) ;
2589 TXNDraw( m_txn
, NULL
) ;
2593 wxInt16
wxMacMLTEClassicControl::MacControlUserPaneHitTestProc(wxInt16 x
, wxInt16 y
)
2595 Point where
= { y
, x
} ;
2596 ControlPartCode result
= kControlNoPart
;
2598 wxTextCtrl
* textctrl
= (wxTextCtrl
*) GetControlReference( m_controlRef
);
2599 if ( (textctrl
!= NULL
) && textctrl
->IsShownOnScreen() )
2601 if (PtInRect( where
, &m_txnControlBounds
))
2603 result
= kControlEditTextPart
;
2607 // sometimes we get the coords also in control local coordinates, therefore test again
2609 textctrl
->MacClientToRootWindow( &x
, &y
) ;
2613 if (PtInRect( where
, &m_txnControlBounds
))
2614 result
= kControlEditTextPart
;
2621 wxInt16
wxMacMLTEClassicControl::MacControlUserPaneTrackingProc( wxInt16 x
, wxInt16 y
, void* WXUNUSED(actionProc
) )
2623 ControlPartCode result
= kControlNoPart
;
2625 wxTextCtrl
* textctrl
= (wxTextCtrl
*) GetControlReference( m_controlRef
);
2626 if ( (textctrl
!= NULL
) && textctrl
->IsShownOnScreen() )
2628 Point startPt
= { y
, x
} ;
2630 // for compositing, we must convert these into toplevel window coordinates, because hittesting expects them
2632 textctrl
->MacClientToRootWindow( &x
, &y
) ;
2636 switch (MacControlUserPaneHitTestProc( startPt
.h
, startPt
.v
))
2638 case kControlEditTextPart
:
2640 wxMacWindowClipper
clipper( textctrl
) ;
2643 ConvertEventRefToEventRecord( (EventRef
) wxTheApp
->MacGetCurrentEvent() , &rec
) ;
2644 TXNClick( m_txn
, &rec
);
2656 void wxMacMLTEClassicControl::MacControlUserPaneIdleProc()
2658 wxTextCtrl
* textctrl
= (wxTextCtrl
*)GetControlReference( m_controlRef
);
2659 if ( textctrl
== NULL
)
2662 if (textctrl
->IsShownOnScreen())
2664 if (IsControlActive(m_controlRef
))
2668 wxMacWindowClipper
clipper( textctrl
) ;
2673 if (PtInRect(mousep
, &m_txnControlBounds
))
2675 RgnHandle theRgn
= NewRgn();
2676 RectRgn(theRgn
, &m_txnControlBounds
);
2677 TXNAdjustCursor(m_txn
, theRgn
);
2684 wxInt16
wxMacMLTEClassicControl::MacControlUserPaneKeyDownProc (wxInt16 keyCode
, wxInt16 charCode
, wxInt16 modifiers
)
2686 wxTextCtrl
* textctrl
= (wxTextCtrl
*)GetControlReference( m_controlRef
);
2687 if ( textctrl
== NULL
)
2688 return kControlNoPart
;
2690 wxMacWindowClipper
clipper( textctrl
) ;
2693 memset( &ev
, 0 , sizeof( ev
) ) ;
2695 ev
.modifiers
= modifiers
;
2696 ev
.message
= ((keyCode
<< 8) & keyCodeMask
) | (charCode
& charCodeMask
);
2697 TXNKeyDown( m_txn
, &ev
);
2699 return kControlEntireControl
;
2702 void wxMacMLTEClassicControl::MacControlUserPaneActivateProc(bool activating
)
2704 MacActivatePaneText( activating
);
2707 wxInt16
wxMacMLTEClassicControl::MacControlUserPaneFocusProc(wxInt16 action
)
2709 ControlPartCode focusResult
= kControlFocusNoPart
;
2711 wxTextCtrl
* textctrl
= (wxTextCtrl
*)GetControlReference( m_controlRef
);
2712 if ( textctrl
== NULL
)
2715 wxMacWindowClipper
clipper( textctrl
) ;
2717 ControlRef controlFocus
= NULL
;
2718 GetKeyboardFocus( m_txnWindow
, &controlFocus
) ;
2719 bool wasFocused
= ( controlFocus
== m_controlRef
) ;
2723 case kControlFocusPrevPart
:
2724 case kControlFocusNextPart
:
2725 MacFocusPaneText( !wasFocused
);
2726 focusResult
= (!wasFocused
? (ControlPartCode
) kControlEditTextPart
: (ControlPartCode
) kControlFocusNoPart
);
2729 case kControlFocusNoPart
:
2731 MacFocusPaneText( false );
2732 focusResult
= kControlFocusNoPart
;
2739 void wxMacMLTEClassicControl::MacControlUserPaneBackgroundProc( void *WXUNUSED(info
) )
2743 wxMacMLTEClassicControl::wxMacMLTEClassicControl( wxTextCtrl
*wxPeer
,
2744 const wxString
& str
,
2746 const wxSize
& size
, long style
)
2747 : wxMacMLTEControl( wxPeer
)
2749 m_font
= wxPeer
->GetFont() ;
2750 m_windowStyle
= style
;
2751 Rect bounds
= wxMacGetBoundsForControl( wxPeer
, pos
, size
) ;
2754 kControlSupportsEmbedding
| kControlSupportsFocus
| kControlWantsIdle
2755 | kControlWantsActivate
| kControlHandlesTracking
2756 // | kControlHasSpecialBackground
2757 | kControlGetsFocusOnClick
| kControlSupportsLiveFeedback
;
2759 OSStatus err
= ::CreateUserPaneControl(
2760 MAC_WXHWND(wxPeer
->GetParent()->MacGetTopLevelWindowRef()),
2761 &bounds
, featureSet
, &m_controlRef
);
2762 verify_noerr( err
);
2766 AdjustCreationAttributes( *wxWHITE
, true ) ;
2768 MacSetObjectVisibility( wxPeer
->IsShownOnScreen() ) ;
2772 wxMacConvertNewlines10To13( &st
) ;
2773 wxMacWindowClipper
clipper( GetWXPeer() ) ;
2774 SetTXNData( st
, kTXNStartOffset
, kTXNEndOffset
) ;
2775 TXNSetSelection( m_txn
, 0, 0 ) ;
2779 wxMacMLTEClassicControl::~wxMacMLTEClassicControl()
2781 TXNDeleteObject( m_txn
);
2785 void wxMacMLTEClassicControl::VisibilityChanged(bool shown
)
2787 MacSetObjectVisibility( shown
) ;
2788 wxMacControl::VisibilityChanged( shown
) ;
2791 void wxMacMLTEClassicControl::SuperChangedPosition()
2793 MacUpdatePosition() ;
2794 wxMacControl::SuperChangedPosition() ;
2797 ControlUserPaneDrawUPP gTPDrawProc
= NULL
;
2798 ControlUserPaneHitTestUPP gTPHitProc
= NULL
;
2799 ControlUserPaneTrackingUPP gTPTrackProc
= NULL
;
2800 ControlUserPaneIdleUPP gTPIdleProc
= NULL
;
2801 ControlUserPaneKeyDownUPP gTPKeyProc
= NULL
;
2802 ControlUserPaneActivateUPP gTPActivateProc
= NULL
;
2803 ControlUserPaneFocusUPP gTPFocusProc
= NULL
;
2805 static pascal void wxMacControlUserPaneDrawProc(ControlRef control
, SInt16 part
)
2807 wxTextCtrl
*textCtrl
= wxDynamicCast( wxFindWindowFromWXWidget( (WXWidget
) control
) , wxTextCtrl
) ;
2808 wxMacMLTEClassicControl
* win
= textCtrl
? (wxMacMLTEClassicControl
*)(textCtrl
->GetPeer()) : NULL
;
2810 win
->MacControlUserPaneDrawProc( part
) ;
2813 static pascal ControlPartCode
wxMacControlUserPaneHitTestProc(ControlRef control
, Point where
)
2815 wxTextCtrl
*textCtrl
= wxDynamicCast( wxFindWindowFromWXWidget( (WXWidget
) control
) , wxTextCtrl
) ;
2816 wxMacMLTEClassicControl
* win
= textCtrl
? (wxMacMLTEClassicControl
*)(textCtrl
->GetPeer()) : NULL
;
2818 return win
->MacControlUserPaneHitTestProc( where
.h
, where
.v
) ;
2820 return kControlNoPart
;
2823 static pascal ControlPartCode
wxMacControlUserPaneTrackingProc(ControlRef control
, Point startPt
, ControlActionUPP actionProc
)
2825 wxTextCtrl
*textCtrl
= wxDynamicCast( wxFindWindowFromWXWidget( (WXWidget
) control
) , wxTextCtrl
) ;
2826 wxMacMLTEClassicControl
* win
= textCtrl
? (wxMacMLTEClassicControl
*)(textCtrl
->GetPeer()) : NULL
;
2828 return win
->MacControlUserPaneTrackingProc( startPt
.h
, startPt
.v
, (void*) actionProc
) ;
2830 return kControlNoPart
;
2833 static pascal void wxMacControlUserPaneIdleProc(ControlRef control
)
2835 wxTextCtrl
*textCtrl
= wxDynamicCast( wxFindWindowFromWXWidget((WXWidget
) control
) , wxTextCtrl
) ;
2836 wxMacMLTEClassicControl
* win
= textCtrl
? (wxMacMLTEClassicControl
*)(textCtrl
->GetPeer()) : NULL
;
2838 win
->MacControlUserPaneIdleProc() ;
2841 static pascal ControlPartCode
wxMacControlUserPaneKeyDownProc(ControlRef control
, SInt16 keyCode
, SInt16 charCode
, SInt16 modifiers
)
2843 wxTextCtrl
*textCtrl
= wxDynamicCast( wxFindWindowFromWXWidget((WXWidget
) control
) , wxTextCtrl
) ;
2844 wxMacMLTEClassicControl
* win
= textCtrl
? (wxMacMLTEClassicControl
*)(textCtrl
->GetPeer()) : NULL
;
2846 return win
->MacControlUserPaneKeyDownProc( keyCode
, charCode
, modifiers
) ;
2848 return kControlNoPart
;
2851 static pascal void wxMacControlUserPaneActivateProc(ControlRef control
, Boolean activating
)
2853 wxTextCtrl
*textCtrl
= wxDynamicCast( wxFindWindowFromWXWidget( (WXWidget
)control
) , wxTextCtrl
) ;
2854 wxMacMLTEClassicControl
* win
= textCtrl
? (wxMacMLTEClassicControl
*)(textCtrl
->GetPeer()) : NULL
;
2856 win
->MacControlUserPaneActivateProc( activating
) ;
2859 static pascal ControlPartCode
wxMacControlUserPaneFocusProc(ControlRef control
, ControlFocusPart action
)
2861 wxTextCtrl
*textCtrl
= wxDynamicCast( wxFindWindowFromWXWidget((WXWidget
) control
) , wxTextCtrl
) ;
2862 wxMacMLTEClassicControl
* win
= textCtrl
? (wxMacMLTEClassicControl
*)(textCtrl
->GetPeer()) : NULL
;
2864 return win
->MacControlUserPaneFocusProc( action
) ;
2866 return kControlNoPart
;
2870 static pascal void wxMacControlUserPaneBackgroundProc(ControlRef control
, ControlBackgroundPtr info
)
2872 wxTextCtrl
*textCtrl
= wxDynamicCast( wxFindWindowFromWXWidget(control
) , wxTextCtrl
) ;
2873 wxMacMLTEClassicControl
* win
= textCtrl
? (wxMacMLTEClassicControl
*)(textCtrl
->GetPeer()) : NULL
;
2875 win
->MacControlUserPaneBackgroundProc(info
) ;
2879 // TXNRegisterScrollInfoProc
2881 OSStatus
wxMacMLTEClassicControl::DoCreate()
2884 OSStatus err
= noErr
;
2886 // set up our globals
2887 if (gTPDrawProc
== NULL
) gTPDrawProc
= NewControlUserPaneDrawUPP(wxMacControlUserPaneDrawProc
);
2888 if (gTPHitProc
== NULL
) gTPHitProc
= NewControlUserPaneHitTestUPP(wxMacControlUserPaneHitTestProc
);
2889 if (gTPTrackProc
== NULL
) gTPTrackProc
= NewControlUserPaneTrackingUPP(wxMacControlUserPaneTrackingProc
);
2890 if (gTPIdleProc
== NULL
) gTPIdleProc
= NewControlUserPaneIdleUPP(wxMacControlUserPaneIdleProc
);
2891 if (gTPKeyProc
== NULL
) gTPKeyProc
= NewControlUserPaneKeyDownUPP(wxMacControlUserPaneKeyDownProc
);
2892 if (gTPActivateProc
== NULL
) gTPActivateProc
= NewControlUserPaneActivateUPP(wxMacControlUserPaneActivateProc
);
2893 if (gTPFocusProc
== NULL
) gTPFocusProc
= NewControlUserPaneFocusUPP(wxMacControlUserPaneFocusProc
);
2895 if (gTXNScrollInfoProc
== NULL
) gTXNScrollInfoProc
= NewTXNScrollInfoUPP(TXNScrollInfoProc
) ;
2896 if (gTXNScrollActionProc
== NULL
) gTXNScrollActionProc
= NewControlActionUPP(TXNScrollActionProc
) ;
2898 // set the initial settings for our private data
2900 m_txnWindow
= GetControlOwner(m_controlRef
);
2901 m_txnPort
= (GrafPtr
) GetWindowPort(m_txnWindow
);
2903 // set up the user pane procedures
2904 SetControlData(m_controlRef
, kControlEntireControl
, kControlUserPaneDrawProcTag
, sizeof(gTPDrawProc
), &gTPDrawProc
);
2905 SetControlData(m_controlRef
, kControlEntireControl
, kControlUserPaneHitTestProcTag
, sizeof(gTPHitProc
), &gTPHitProc
);
2906 SetControlData(m_controlRef
, kControlEntireControl
, kControlUserPaneTrackingProcTag
, sizeof(gTPTrackProc
), &gTPTrackProc
);
2907 SetControlData(m_controlRef
, kControlEntireControl
, kControlUserPaneIdleProcTag
, sizeof(gTPIdleProc
), &gTPIdleProc
);
2908 SetControlData(m_controlRef
, kControlEntireControl
, kControlUserPaneKeyDownProcTag
, sizeof(gTPKeyProc
), &gTPKeyProc
);
2909 SetControlData(m_controlRef
, kControlEntireControl
, kControlUserPaneActivateProcTag
, sizeof(gTPActivateProc
), &gTPActivateProc
);
2910 SetControlData(m_controlRef
, kControlEntireControl
, kControlUserPaneFocusProcTag
, sizeof(gTPFocusProc
), &gTPFocusProc
);
2912 // calculate the rectangles used by the control
2913 GetRectInWindowCoords( &bounds
);
2915 m_txnControlBounds
= bounds
;
2916 m_txnVisBounds
= bounds
;
2921 GetGWorld( &origPort
, &origDev
) ;
2922 SetPort( m_txnPort
);
2924 // create the new edit field
2925 TXNFrameOptions frameOptions
= FrameOptionsFromWXStyle( m_windowStyle
);
2927 // the scrollbars are not correctly embedded but are inserted at the root:
2928 // this gives us problems as we have erratic redraws even over the structure area
2930 m_sbHorizontal
= 0 ;
2932 m_lastHorizontalValue
= 0 ;
2933 m_lastVerticalValue
= 0 ;
2935 Rect sb
= { 0 , 0 , 0 , 0 } ;
2936 if ( frameOptions
& kTXNWantVScrollBarMask
)
2938 CreateScrollBarControl( m_txnWindow
, &sb
, 0, 0, 100, 1, true, gTXNScrollActionProc
, &m_sbVertical
);
2939 SetControlReference( m_sbVertical
, (SInt32
)this );
2940 SetControlAction( m_sbVertical
, gTXNScrollActionProc
);
2941 ShowControl( m_sbVertical
);
2942 EmbedControl( m_sbVertical
, m_controlRef
);
2943 frameOptions
&= ~kTXNWantVScrollBarMask
;
2946 if ( frameOptions
& kTXNWantHScrollBarMask
)
2948 CreateScrollBarControl( m_txnWindow
, &sb
, 0, 0, 100, 1, true, gTXNScrollActionProc
, &m_sbHorizontal
);
2949 SetControlReference( m_sbHorizontal
, (SInt32
)this );
2950 SetControlAction( m_sbHorizontal
, gTXNScrollActionProc
);
2951 ShowControl( m_sbHorizontal
);
2952 EmbedControl( m_sbHorizontal
, m_controlRef
);
2953 frameOptions
&= ~(kTXNWantHScrollBarMask
| kTXNDrawGrowIconMask
);
2957 NULL
, m_txnWindow
, &bounds
, frameOptions
,
2958 kTXNTextEditStyleFrameType
, kTXNTextensionFile
, kTXNSystemDefaultEncoding
,
2959 &m_txn
, &m_txnFrameID
, NULL
);
2960 verify_noerr( err
);
2963 TXNControlTag iControlTags
[] = { kTXNUseCarbonEvents
};
2964 TXNControlData iControlData
[] = { { (UInt32
)&cInfo
} };
2965 int toptag
= WXSIZEOF( iControlTags
) ;
2966 TXNCarbonEventInfo cInfo
;
2967 cInfo
.useCarbonEvents
= false ;
2970 cInfo
.fDictionary
= NULL
;
2972 verify_noerr( TXNSetTXNObjectControls( m_txn
, false, toptag
, iControlTags
, iControlData
) );
2975 TXNRegisterScrollInfoProc( m_txn
, gTXNScrollInfoProc
, (SInt32
)this );
2977 SetGWorld( origPort
, origDev
) ;
2983 // ----------------------------------------------------------------------------
2984 // MLTE control implementation (OSX part)
2985 // ----------------------------------------------------------------------------
2987 // tiger multi-line textcontrols with no CR in the entire content
2988 // don't scroll automatically, so we need a hack.
2989 // This attempt only works 'before' the key (ie before CallNextEventHandler)
2990 // is processed, thus the scrolling always occurs one character too late, but
2991 // better than nothing ...
2993 static const EventTypeSpec eventList
[] =
2995 { kEventClassTextInput
, kEventTextInputUnicodeForKeyEvent
} ,
2998 static pascal OSStatus
wxMacUnicodeTextEventHandler( EventHandlerCallRef handler
, EventRef event
, void *data
)
3000 OSStatus result
= eventNotHandledErr
;
3001 wxMacMLTEHIViewControl
* focus
= (wxMacMLTEHIViewControl
*) data
;
3003 switch ( GetEventKind( event
) )
3005 case kEventTextInputUnicodeForKeyEvent
:
3007 TXNOffset from
, to
;
3008 TXNGetSelection( focus
->GetTXNObject() , &from
, &to
) ;
3010 TXNShowSelection( focus
->GetTXNObject() , kTXNShowStart
);
3011 result
= CallNextEventHandler(handler
,event
);
3021 static pascal OSStatus
wxMacTextControlEventHandler( EventHandlerCallRef handler
, EventRef event
, void *data
)
3023 OSStatus result
= eventNotHandledErr
;
3025 switch ( GetEventClass( event
) )
3027 case kEventClassTextInput
:
3028 result
= wxMacUnicodeTextEventHandler( handler
, event
, data
) ;
3037 DEFINE_ONE_SHOT_HANDLER_GETTER( wxMacTextControlEventHandler
)
3039 wxMacMLTEHIViewControl::wxMacMLTEHIViewControl( wxTextCtrl
*wxPeer
,
3040 const wxString
& str
,
3042 const wxSize
& size
, long style
) : wxMacMLTEControl( wxPeer
)
3044 m_font
= wxPeer
->GetFont() ;
3045 m_windowStyle
= style
;
3046 Rect bounds
= wxMacGetBoundsForControl( wxPeer
, pos
, size
) ;
3048 wxMacConvertNewlines10To13( &st
) ;
3051 { bounds
.left
, bounds
.top
},
3052 { bounds
.right
- bounds
.left
, bounds
.bottom
- bounds
.top
} } ;
3054 m_scrollView
= NULL
;
3055 TXNFrameOptions frameOptions
= FrameOptionsFromWXStyle( style
) ;
3056 if (( frameOptions
& (kTXNWantVScrollBarMask
| kTXNWantHScrollBarMask
)) || (frameOptions
&kTXNSingleLineOnlyMask
))
3058 if ( frameOptions
& (kTXNWantVScrollBarMask
| kTXNWantHScrollBarMask
) )
3061 (frameOptions
& kTXNWantHScrollBarMask
? kHIScrollViewOptionsHorizScroll
: 0)
3062 | (frameOptions
& kTXNWantVScrollBarMask
? kHIScrollViewOptionsVertScroll
: 0) ,
3067 HIScrollViewCreate(kHIScrollViewOptionsVertScroll
,&m_scrollView
);
3068 HIScrollViewSetScrollBarAutoHide(m_scrollView
,true);
3071 HIViewSetFrame( m_scrollView
, &hr
);
3072 HIViewSetVisible( m_scrollView
, true );
3076 HITextViewCreate( NULL
, 0, frameOptions
, &m_textView
) ;
3077 m_txn
= HITextViewGetTXNObject( m_textView
) ;
3078 HIViewSetVisible( m_textView
, true ) ;
3081 HIViewAddSubview( m_scrollView
, m_textView
) ;
3082 m_controlRef
= m_scrollView
;
3083 wxMacControl::MacInstallEventHandler( m_textView
, wxPeer
) ;
3087 HIViewSetFrame( m_textView
, &hr
);
3088 m_controlRef
= m_textView
;
3091 AdjustCreationAttributes( *wxWHITE
, true ) ;
3093 wxMacWindowClipper
c( GetWXPeer() ) ;
3095 SetTXNData( st
, kTXNStartOffset
, kTXNEndOffset
) ;
3097 TXNSetSelection( m_txn
, 0, 0 );
3098 TXNShowSelection( m_txn
, kTXNShowStart
);
3100 ::InstallControlEventHandler( m_textView
, GetwxMacTextControlEventHandlerUPP(),
3101 GetEventTypeCount(eventList
), eventList
, this,
3105 wxMacMLTEHIViewControl::~wxMacMLTEHIViewControl()
3109 OSStatus
wxMacMLTEHIViewControl::SetFocus( ControlFocusPart focusPart
)
3111 return SetKeyboardFocus( GetControlOwner( m_textView
), m_textView
, focusPart
) ;
3114 bool wxMacMLTEHIViewControl::HasFocus() const
3116 ControlRef control
;
3117 if ( GetUserFocusWindow() == NULL
)
3120 GetKeyboardFocus( GetUserFocusWindow() , &control
) ;
3121 return control
== m_textView
;
3124 void wxMacMLTEHIViewControl::SetBackgroundColour(const wxColour
& col
)
3126 HITextViewSetBackgroundColor( m_textView
, col
.GetPixel() );
3129 #endif // wxUSE_TEXTCTRL