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"
48 #include "wx/mac/uma.h"
49 #include "wx/mac/carbon/private/mactext.h"
55 virtual ~wxMacFunctor() {}
57 virtual void* operator()() = 0 ;
59 static void* CallBackProc( void *param
)
61 wxMacFunctor
* f
= (wxMacFunctor
*) param
;
62 void *result
= (*f
)() ;
67 template<typename classtype
, typename param1type
>
69 class wxMacObjectFunctor1
: public wxMacFunctor
71 typedef void (classtype::*function
)( param1type p1
) ;
72 typedef void (classtype::*ref_function
)( const param1type
& p1
) ;
74 wxMacObjectFunctor1( classtype
*obj
, function f
, param1type p1
) :
82 wxMacObjectFunctor1( classtype
*obj
, ref_function f
, param1type p1
) :
90 virtual ~wxMacObjectFunctor1() {}
92 virtual void* operator()()
94 (m_object
->*m_function
)( m_param1
) ;
100 param1type m_param1
;
103 function m_function
;
104 ref_function m_refFunction
;
108 template<typename classtype
, typename param1type
>
109 void* wxMacMPRemoteCall( classtype
*object
, void (classtype::*function
)( param1type p1
) , param1type p1
)
111 wxMacObjectFunctor1
<classtype
, param1type
> params(object
, function
, p1
) ;
113 MPRemoteCall( wxMacFunctor::CallBackProc
, ¶ms
, kMPOwningProcessRemoteContext
) ;
117 template<typename classtype
, typename param1type
>
118 void* wxMacMPRemoteCall( classtype
*object
, void (classtype::*function
)( const param1type
& p1
) , param1type p1
)
120 wxMacObjectFunctor1
<classtype
,param1type
> params(object
, function
, p1
) ;
122 MPRemoteCall( wxMacFunctor::CallBackProc
, ¶ms
, kMPOwningProcessRemoteContext
) ;
126 template<typename classtype
, typename param1type
>
127 void* wxMacMPRemoteGUICall( classtype
*object
, void (classtype::*function
)( param1type p1
) , param1type p1
)
130 void *result
= wxMacMPRemoteCall( object
, function
, p1
) ;
135 template<typename classtype
, typename param1type
>
136 void* wxMacMPRemoteGUICall( classtype
*object
, void (classtype::*function
)( const param1type
& p1
) , param1type p1
)
139 void *result
= wxMacMPRemoteCall( object
, function
, p1
) ;
145 // common parts for implementations based on MLTE
147 class wxMacMLTEControl
: public wxMacTextControl
150 wxMacMLTEControl( wxTextCtrl
*peer
) ;
152 virtual wxString
GetStringValue() const ;
153 virtual void SetStringValue( const wxString
&str
) ;
155 static TXNFrameOptions
FrameOptionsFromWXStyle( long wxStyle
) ;
157 void AdjustCreationAttributes( const wxColour
& background
, bool visible
) ;
159 virtual void SetFont( const wxFont
& font
, const wxColour
& foreground
, long windowStyle
) ;
160 virtual void SetBackground( const wxBrush
&brush
) ;
161 virtual void SetStyle( long start
, long end
, const wxTextAttr
& style
) ;
162 virtual void Copy() ;
164 virtual void Paste() ;
165 virtual bool CanPaste() const ;
166 virtual void SetEditable( bool editable
) ;
167 virtual wxTextPos
GetLastPosition() const ;
168 virtual void Replace( long from
, long to
, const wxString
&str
) ;
169 virtual void Remove( long from
, long to
) ;
170 virtual void GetSelection( long* from
, long* to
) const ;
171 virtual void SetSelection( long from
, long to
) ;
173 virtual void WriteText( const wxString
& str
) ;
175 virtual bool HasOwnContextMenu() const
177 TXNCommandEventSupportOptions options
;
178 TXNGetCommandEventSupport( m_txn
, & options
) ;
179 return options
& kTXNSupportEditCommandProcessing
;
182 virtual void CheckSpelling(bool check
)
184 TXNSetSpellCheckAsYouType( m_txn
, (Boolean
) check
);
186 virtual void Clear() ;
188 virtual bool CanUndo() const ;
189 virtual void Undo() ;
190 virtual bool CanRedo() const;
191 virtual void Redo() ;
192 virtual int GetNumberOfLines() const ;
193 virtual long XYToPosition(long x
, long y
) const ;
194 virtual bool PositionToXY(long pos
, long *x
, long *y
) const ;
195 virtual void ShowPosition( long pos
) ;
196 virtual int GetLineLength(long lineNo
) const ;
197 virtual wxString
GetLineText(long lineNo
) const ;
199 void SetTXNData( const wxString
& st
, TXNOffset start
, TXNOffset end
) ;
200 TXNObject
GetTXNObject() { return m_txn
; }
203 void TXNSetAttribute( const wxTextAttr
& style
, long from
, long to
) ;
208 // implementation available under OSX
210 class wxMacMLTEHIViewControl
: public wxMacMLTEControl
213 wxMacMLTEHIViewControl( wxTextCtrl
*wxPeer
,
216 const wxSize
& size
, long style
) ;
217 virtual ~wxMacMLTEHIViewControl() ;
219 virtual OSStatus
SetFocus( ControlFocusPart focusPart
) ;
220 virtual bool HasFocus() const ;
221 virtual void SetBackground( const wxBrush
&brush
) ;
224 HIViewRef m_scrollView
;
225 HIViewRef m_textView
;
228 // 'classic' MLTE implementation
230 class wxMacMLTEClassicControl
: public wxMacMLTEControl
233 wxMacMLTEClassicControl( wxTextCtrl
*wxPeer
,
236 const wxSize
& size
, long style
) ;
237 virtual ~wxMacMLTEClassicControl() ;
239 virtual void VisibilityChanged(bool shown
) ;
240 virtual void SuperChangedPosition() ;
242 virtual void MacControlUserPaneDrawProc(wxInt16 part
) ;
243 virtual wxInt16
MacControlUserPaneHitTestProc(wxInt16 x
, wxInt16 y
) ;
244 virtual wxInt16
MacControlUserPaneTrackingProc(wxInt16 x
, wxInt16 y
, void* actionProc
) ;
245 virtual void MacControlUserPaneIdleProc() ;
246 virtual wxInt16
MacControlUserPaneKeyDownProc(wxInt16 keyCode
, wxInt16 charCode
, wxInt16 modifiers
) ;
247 virtual void MacControlUserPaneActivateProc(bool activating
) ;
248 virtual wxInt16
MacControlUserPaneFocusProc(wxInt16 action
) ;
249 virtual void MacControlUserPaneBackgroundProc(void* info
) ;
251 virtual bool SetupCursor( const wxPoint
& WXUNUSED(pt
) )
253 MacControlUserPaneIdleProc();
257 virtual void SetRect( Rect
*r
) ;
262 void MacUpdatePosition() ;
263 void MacActivatePaneText(bool setActive
) ;
264 void MacFocusPaneText(bool setFocus
) ;
265 void MacSetObjectVisibility(bool vis
) ;
268 TXNFrameID m_txnFrameID
;
270 WindowRef m_txnWindow
;
271 // bounds of the control as we last did set the txn frames
272 Rect m_txnControlBounds
;
273 Rect m_txnVisBounds
;
275 static pascal void TXNScrollActionProc( ControlRef controlRef
, ControlPartCode partCode
) ;
276 static pascal void TXNScrollInfoProc(
277 SInt32 iValue
, SInt32 iMaximumValue
,
278 TXNScrollBarOrientation iScrollBarOrientation
, SInt32 iRefCon
) ;
280 ControlRef m_sbHorizontal
;
281 SInt32 m_lastHorizontalValue
;
282 ControlRef m_sbVertical
;
283 SInt32 m_lastVerticalValue
;
287 IMPLEMENT_DYNAMIC_CLASS(wxTextCtrl
, wxTextCtrlBase
)
289 BEGIN_EVENT_TABLE(wxTextCtrl
, wxTextCtrlBase
)
290 EVT_ERASE_BACKGROUND( wxTextCtrl::OnEraseBackground
)
291 EVT_DROP_FILES(wxTextCtrl::OnDropFiles
)
292 EVT_CHAR(wxTextCtrl::OnChar
)
293 EVT_MENU(wxID_CUT
, wxTextCtrl::OnCut
)
294 EVT_MENU(wxID_COPY
, wxTextCtrl::OnCopy
)
295 EVT_MENU(wxID_PASTE
, wxTextCtrl::OnPaste
)
296 EVT_MENU(wxID_UNDO
, wxTextCtrl::OnUndo
)
297 EVT_MENU(wxID_REDO
, wxTextCtrl::OnRedo
)
298 EVT_MENU(wxID_CLEAR
, wxTextCtrl::OnDelete
)
299 EVT_MENU(wxID_SELECTALL
, wxTextCtrl::OnSelectAll
)
301 EVT_CONTEXT_MENU(wxTextCtrl::OnContextMenu
)
303 EVT_UPDATE_UI(wxID_CUT
, wxTextCtrl::OnUpdateCut
)
304 EVT_UPDATE_UI(wxID_COPY
, wxTextCtrl::OnUpdateCopy
)
305 EVT_UPDATE_UI(wxID_PASTE
, wxTextCtrl::OnUpdatePaste
)
306 EVT_UPDATE_UI(wxID_UNDO
, wxTextCtrl::OnUpdateUndo
)
307 EVT_UPDATE_UI(wxID_REDO
, wxTextCtrl::OnUpdateRedo
)
308 EVT_UPDATE_UI(wxID_CLEAR
, wxTextCtrl::OnUpdateDelete
)
309 EVT_UPDATE_UI(wxID_SELECTALL
, wxTextCtrl::OnUpdateSelectAll
)
313 void wxTextCtrl::Init()
319 m_privateContextMenu
= NULL
;
320 m_triggerOnSetValue
= true ;
323 wxTextCtrl::~wxTextCtrl()
325 delete m_privateContextMenu
;
328 bool wxTextCtrl::Create( wxWindow
*parent
,
334 const wxValidator
& validator
,
335 const wxString
& name
)
337 m_macIsUserPane
= false ;
340 if ( ! (style
& wxNO_BORDER
) )
341 style
= (style
& ~wxBORDER_MASK
) | wxSUNKEN_BORDER
;
343 if ( !wxTextCtrlBase::Create( parent
, id
, pos
, size
, style
& ~(wxHSCROLL
| wxVSCROLL
), validator
, name
) )
346 if ( m_windowStyle
& wxTE_MULTILINE
)
348 // always turn on this style for multi-line controls
349 m_windowStyle
|= wxTE_PROCESS_ENTER
;
350 style
|= wxTE_PROCESS_ENTER
;
353 CreatePeer( str
, pos
, size
, style
);
355 MacPostControlCreate(pos
, size
) ;
357 // only now the embedding is correct and we can do a positioning update
359 MacSuperChangedPosition() ;
361 if ( m_windowStyle
& wxTE_READONLY
)
362 SetEditable( false ) ;
364 SetCursor( wxCursor( wxCURSOR_IBEAM
) ) ;
369 void wxTextCtrl::CreatePeer(
372 const wxSize
& size
, long style
)
374 bool forceMLTE
= false ;
376 #if wxUSE_SYSTEM_OPTIONS
377 if (wxSystemOptions::HasOption( wxMAC_TEXTCONTROL_USE_MLTE
) && (wxSystemOptions::GetOptionInt( wxMAC_TEXTCONTROL_USE_MLTE
) == 1))
383 if ( UMAGetSystemVersion() >= 0x1050 )
388 if ( m_windowStyle
& wxTE_MULTILINE
)
389 m_peer
= new wxMacMLTEHIViewControl( this , str
, pos
, size
, style
) ;
394 if ( !(m_windowStyle
& wxTE_MULTILINE
) && !forceMLTE
)
396 m_peer
= new wxMacUnicodeTextControl( this , str
, pos
, size
, style
) ;
400 // the horizontal single line scrolling bug that made us keep the classic implementation
402 #if MAC_OS_X_VERSION_MIN_REQUIRED < MAC_OS_X_VERSION_10_5
404 m_peer
= new wxMacMLTEClassicControl( this , str
, pos
, size
, style
) ;
408 void wxTextCtrl::MacSuperChangedPosition()
410 wxWindow::MacSuperChangedPosition() ;
411 GetPeer()->SuperChangedPosition() ;
414 void wxTextCtrl::MacVisibilityChanged()
416 GetPeer()->VisibilityChanged( MacIsReallyShown() ) ;
419 void wxTextCtrl::MacCheckSpelling(bool check
)
421 GetPeer()->CheckSpelling(check
);
424 wxString
wxTextCtrl::GetValue() const
426 return GetPeer()->GetStringValue() ;
429 void wxTextCtrl::GetSelection(long* from
, long* to
) const
431 GetPeer()->GetSelection( from
, to
) ;
434 void wxTextCtrl::DoSetValue(const wxString
& str
, int flags
)
437 if ( GetValue() == str
)
440 GetPeer()->SetStringValue( str
) ;
442 if ( (flags
& SetValue_SendEvent
) && m_triggerOnSetValue
)
444 SendTextUpdatedEvent();
448 void wxTextCtrl::SetMaxLength(unsigned long len
)
453 bool wxTextCtrl::SetFont( const wxFont
& font
)
455 if ( !wxTextCtrlBase::SetFont( font
) )
458 GetPeer()->SetFont( font
, GetForegroundColour() , GetWindowStyle() ) ;
463 bool wxTextCtrl::SetStyle(long start
, long end
, const wxTextAttr
& style
)
465 GetPeer()->SetStyle( start
, end
, style
) ;
470 bool wxTextCtrl::SetDefaultStyle(const wxTextAttr
& style
)
472 wxTextCtrlBase::SetDefaultStyle( style
) ;
473 SetStyle( kTXNUseCurrentSelection
, kTXNUseCurrentSelection
, GetDefaultStyle() ) ;
478 // Clipboard operations
480 void wxTextCtrl::Copy()
486 void wxTextCtrl::Cut()
492 wxCommandEvent
event( wxEVT_COMMAND_TEXT_UPDATED
, m_windowId
);
493 event
.SetEventObject( this );
494 GetEventHandler()->ProcessEvent( event
);
498 void wxTextCtrl::Paste()
504 // TODO: eventually we should add setting the default style again
506 wxCommandEvent
event( wxEVT_COMMAND_TEXT_UPDATED
, m_windowId
);
507 event
.SetEventObject( this );
508 GetEventHandler()->ProcessEvent( event
);
512 bool wxTextCtrl::CanCopy() const
514 // Can copy if there's a selection
516 GetSelection( &from
, &to
);
521 bool wxTextCtrl::CanCut() const
526 // Can cut if there's a selection
528 GetSelection( &from
, &to
);
533 bool wxTextCtrl::CanPaste() const
538 return GetPeer()->CanPaste() ;
541 void wxTextCtrl::SetEditable(bool editable
)
543 if ( editable
!= m_editable
)
545 m_editable
= editable
;
546 GetPeer()->SetEditable( editable
) ;
550 void wxTextCtrl::SetInsertionPoint(long pos
)
552 SetSelection( pos
, pos
) ;
555 void wxTextCtrl::SetInsertionPointEnd()
557 wxTextPos pos
= GetLastPosition();
558 SetInsertionPoint( pos
);
561 long wxTextCtrl::GetInsertionPoint() const
564 GetSelection( &begin
, &end
) ;
569 wxTextPos
wxTextCtrl::GetLastPosition() const
571 return GetPeer()->GetLastPosition() ;
574 void wxTextCtrl::Replace(long from
, long to
, const wxString
& str
)
576 GetPeer()->Replace( from
, to
, str
) ;
579 void wxTextCtrl::Remove(long from
, long to
)
581 GetPeer()->Remove( from
, to
) ;
584 void wxTextCtrl::SetSelection(long from
, long to
)
586 GetPeer()->SetSelection( from
, to
) ;
589 void wxTextCtrl::WriteText(const wxString
& str
)
591 // TODO: this MPRemoting will be moved into a remoting peer proxy for any command
592 if ( !wxIsMainThread() )
594 // unfortunately CW 8 is not able to correctly deduce the template types,
595 // so we have to instantiate explicitly
596 wxMacMPRemoteGUICall
<wxTextCtrl
,wxString
>( this , &wxTextCtrl::WriteText
, str
) ;
601 GetPeer()->WriteText( str
) ;
604 void wxTextCtrl::AppendText(const wxString
& text
)
606 SetInsertionPointEnd();
610 void wxTextCtrl::Clear()
615 bool wxTextCtrl::IsModified() const
620 bool wxTextCtrl::IsEditable() const
622 return IsEnabled() && m_editable
;
625 bool wxTextCtrl::AcceptsFocus() const
627 // we don't want focus if we can't be edited
628 return /*IsEditable() && */ wxControl::AcceptsFocus();
631 wxSize
wxTextCtrl::DoGetBestSize() const
635 // these are the numbers from the HIG:
636 // we reduce them by the borders first
639 switch ( m_windowVariant
)
641 case wxWINDOW_VARIANT_NORMAL
:
645 case wxWINDOW_VARIANT_SMALL
:
649 case wxWINDOW_VARIANT_MINI
:
658 // as the above numbers have some free space around the text
659 // we get 5 lines like this anyway
660 if ( m_windowStyle
& wxTE_MULTILINE
)
663 if ( !HasFlag(wxNO_BORDER
) )
666 return wxSize(wText
, hText
);
669 // ----------------------------------------------------------------------------
671 // ----------------------------------------------------------------------------
673 void wxTextCtrl::Undo()
679 void wxTextCtrl::Redo()
685 bool wxTextCtrl::CanUndo() const
690 return GetPeer()->CanUndo() ;
693 bool wxTextCtrl::CanRedo() const
698 return GetPeer()->CanRedo() ;
701 void wxTextCtrl::MarkDirty()
706 void wxTextCtrl::DiscardEdits()
711 int wxTextCtrl::GetNumberOfLines() const
713 return GetPeer()->GetNumberOfLines() ;
716 long wxTextCtrl::XYToPosition(long x
, long y
) const
718 return GetPeer()->XYToPosition( x
, y
) ;
721 bool wxTextCtrl::PositionToXY(long pos
, long *x
, long *y
) const
723 return GetPeer()->PositionToXY( pos
, x
, y
) ;
726 void wxTextCtrl::ShowPosition(long pos
)
728 return GetPeer()->ShowPosition(pos
) ;
731 int wxTextCtrl::GetLineLength(long lineNo
) const
733 return GetPeer()->GetLineLength(lineNo
) ;
736 wxString
wxTextCtrl::GetLineText(long lineNo
) const
738 return GetPeer()->GetLineText(lineNo
) ;
741 void wxTextCtrl::Command(wxCommandEvent
& event
)
743 SetValue(event
.GetString());
744 ProcessCommand(event
);
747 void wxTextCtrl::OnDropFiles(wxDropFilesEvent
& event
)
749 // By default, load the first file into the text window.
750 if (event
.GetNumberOfFiles() > 0)
751 LoadFile( event
.GetFiles()[0] );
754 void wxTextCtrl::OnEraseBackground(wxEraseEvent
& event
)
756 // all erasing should be done by the real mac control implementation
757 // while this is true for MLTE under classic, the HITextView is somehow
758 // transparent but background erase is not working correctly, so intercept
759 // things while we can...
763 void wxTextCtrl::OnChar(wxKeyEvent
& event
)
765 int key
= event
.GetKeyCode() ;
766 bool eat_key
= false ;
768 if ( key
== 'a' && event
.MetaDown() )
775 if ( key
== 'c' && event
.MetaDown() )
783 if ( !IsEditable() && key
!= WXK_LEFT
&& key
!= WXK_RIGHT
&& key
!= WXK_DOWN
&& key
!= WXK_UP
&& key
!= WXK_TAB
&&
784 !( key
== WXK_RETURN
&& ( (m_windowStyle
& wxTE_PROCESS_ENTER
) || (m_windowStyle
& wxTE_MULTILINE
) ) )
785 // && key != WXK_PAGEUP && key != WXK_PAGEDOWN && key != WXK_HOME && key != WXK_END
792 // Check if we have reached the max # of chars (if it is set), but still
793 // allow navigation and deletion
794 if ( !IsMultiLine() && m_maxLength
&& GetValue().length() >= m_maxLength
&&
795 key
!= WXK_LEFT
&& key
!= WXK_RIGHT
&& key
!= WXK_TAB
&&
796 key
!= WXK_BACK
&& !( key
== WXK_RETURN
&& (m_windowStyle
& wxTE_PROCESS_ENTER
) )
799 // eat it, we don't want to add more than allowed # of characters
801 // TODO: generate EVT_TEXT_MAXLEN()
805 // assume that any key not processed yet is going to modify the control
808 if ( key
== 'v' && event
.MetaDown() )
816 if ( key
== 'x' && event
.MetaDown() )
827 if (m_windowStyle
& wxTE_PROCESS_ENTER
)
829 wxCommandEvent
event(wxEVT_COMMAND_TEXT_ENTER
, m_windowId
);
830 event
.SetEventObject( this );
831 event
.SetString( GetValue() );
832 if ( GetEventHandler()->ProcessEvent(event
) )
836 if ( !(m_windowStyle
& wxTE_MULTILINE
) )
838 wxTopLevelWindow
*tlw
= wxDynamicCast(wxGetTopLevelParent(this), wxTopLevelWindow
);
839 if ( tlw
&& tlw
->GetDefaultItem() )
841 wxButton
*def
= wxDynamicCast(tlw
->GetDefaultItem(), wxButton
);
842 if ( def
&& def
->IsEnabled() )
844 wxCommandEvent
event(wxEVT_COMMAND_BUTTON_CLICKED
, def
->GetId() );
845 event
.SetEventObject(def
);
852 // this will make wxWidgets eat the ENTER key so that
853 // we actually prevent line wrapping in a single line text control
859 if ( !(m_windowStyle
& wxTE_PROCESS_TAB
))
862 if (!event
.ShiftDown())
863 flags
|= wxNavigationKeyEvent::IsForward
;
864 if (event
.ControlDown())
865 flags
|= wxNavigationKeyEvent::WinChange
;
872 // This is necessary (don't know why);
873 // otherwise the tab will not be inserted.
874 WriteText(wxT("\t"));
885 // perform keystroke handling
889 if ( ( key
>= 0x20 && key
< WXK_START
) ||
890 ( key
>= WXK_NUMPAD0
&& key
<= WXK_DIVIDE
) ||
895 wxCommandEvent
event1(wxEVT_COMMAND_TEXT_UPDATED
, m_windowId
);
896 event1
.SetEventObject( this );
897 wxPostEvent( GetEventHandler(), event1
);
901 // ----------------------------------------------------------------------------
902 // standard handlers for standard edit menu events
903 // ----------------------------------------------------------------------------
905 void wxTextCtrl::OnCut(wxCommandEvent
& WXUNUSED(event
))
910 void wxTextCtrl::OnCopy(wxCommandEvent
& WXUNUSED(event
))
915 void wxTextCtrl::OnPaste(wxCommandEvent
& WXUNUSED(event
))
920 void wxTextCtrl::OnUndo(wxCommandEvent
& WXUNUSED(event
))
925 void wxTextCtrl::OnRedo(wxCommandEvent
& WXUNUSED(event
))
930 void wxTextCtrl::OnDelete(wxCommandEvent
& WXUNUSED(event
))
934 GetSelection( &from
, &to
);
935 if (from
!= -1 && to
!= -1)
939 void wxTextCtrl::OnSelectAll(wxCommandEvent
& WXUNUSED(event
))
941 SetSelection(-1, -1);
944 void wxTextCtrl::OnUpdateCut(wxUpdateUIEvent
& event
)
946 event
.Enable( CanCut() );
949 void wxTextCtrl::OnUpdateCopy(wxUpdateUIEvent
& event
)
951 event
.Enable( CanCopy() );
954 void wxTextCtrl::OnUpdatePaste(wxUpdateUIEvent
& event
)
956 event
.Enable( CanPaste() );
959 void wxTextCtrl::OnUpdateUndo(wxUpdateUIEvent
& event
)
961 event
.Enable( CanUndo() );
964 void wxTextCtrl::OnUpdateRedo(wxUpdateUIEvent
& event
)
966 event
.Enable( CanRedo() );
969 void wxTextCtrl::OnUpdateDelete(wxUpdateUIEvent
& event
)
973 GetSelection( &from
, &to
);
974 event
.Enable( from
!= -1 && to
!= -1 && from
!= to
&& IsEditable() ) ;
977 void wxTextCtrl::OnUpdateSelectAll(wxUpdateUIEvent
& event
)
979 event
.Enable(GetLastPosition() > 0);
982 // CS: Context Menus only work with MLTE implementations or non-multiline HIViews at the moment
984 void wxTextCtrl::OnContextMenu(wxContextMenuEvent
& event
)
986 if ( GetPeer()->HasOwnContextMenu() )
992 if (m_privateContextMenu
== NULL
)
994 m_privateContextMenu
= new wxMenu
;
995 m_privateContextMenu
->Append(wxID_UNDO
, _("&Undo"));
996 m_privateContextMenu
->Append(wxID_REDO
, _("&Redo"));
997 m_privateContextMenu
->AppendSeparator();
998 m_privateContextMenu
->Append(wxID_CUT
, _("Cu&t"));
999 m_privateContextMenu
->Append(wxID_COPY
, _("&Copy"));
1000 m_privateContextMenu
->Append(wxID_PASTE
, _("&Paste"));
1001 m_privateContextMenu
->Append(wxID_CLEAR
, _("&Delete"));
1002 m_privateContextMenu
->AppendSeparator();
1003 m_privateContextMenu
->Append(wxID_SELECTALL
, _("Select &All"));
1006 if (m_privateContextMenu
!= NULL
)
1007 PopupMenu(m_privateContextMenu
);
1010 bool wxTextCtrl::MacSetupCursor( const wxPoint
& pt
)
1012 if ( !GetPeer()->SetupCursor( pt
) )
1013 return wxWindow::MacSetupCursor( pt
) ;
1018 // ----------------------------------------------------------------------------
1019 // implementation base class
1020 // ----------------------------------------------------------------------------
1022 wxMacTextControl::wxMacTextControl(wxTextCtrl
* peer
) :
1023 wxMacControl( peer
)
1027 wxMacTextControl::~wxMacTextControl()
1031 void wxMacTextControl::SetStyle(long WXUNUSED(start
),
1033 const wxTextAttr
& WXUNUSED(style
))
1037 void wxMacTextControl::Copy()
1041 void wxMacTextControl::Cut()
1045 void wxMacTextControl::Paste()
1049 bool wxMacTextControl::CanPaste() const
1054 void wxMacTextControl::SetEditable(bool WXUNUSED(editable
))
1058 wxTextPos
wxMacTextControl::GetLastPosition() const
1060 return GetStringValue().length() ;
1063 void wxMacTextControl::Replace( long from
, long to
, const wxString
&val
)
1065 SetSelection( from
, to
) ;
1069 void wxMacTextControl::Remove( long from
, long to
)
1071 SetSelection( from
, to
) ;
1072 WriteText( wxEmptyString
) ;
1075 void wxMacTextControl::Clear()
1077 SetStringValue( wxEmptyString
) ;
1080 bool wxMacTextControl::CanUndo() const
1085 void wxMacTextControl::Undo()
1089 bool wxMacTextControl::CanRedo() const
1094 void wxMacTextControl::Redo()
1098 long wxMacTextControl::XYToPosition(long WXUNUSED(x
), long WXUNUSED(y
)) const
1103 bool wxMacTextControl::PositionToXY(long WXUNUSED(pos
),
1105 long *WXUNUSED(y
)) const
1110 void wxMacTextControl::ShowPosition( long WXUNUSED(pos
) )
1114 int wxMacTextControl::GetNumberOfLines() const
1116 ItemCount lines
= 0 ;
1117 wxString content
= GetStringValue() ;
1120 for (size_t i
= 0; i
< content
.length() ; i
++)
1122 if (content
[i
] == '\r')
1129 wxString
wxMacTextControl::GetLineText(long lineNo
) const
1131 // TODO: change this if possible to reflect real lines
1132 wxString content
= GetStringValue() ;
1136 for (size_t i
= 0; i
< content
.length() ; i
++)
1138 if (count
== lineNo
)
1140 // Add chars in line then
1143 for (size_t j
= i
; j
< content
.length(); j
++)
1145 if (content
[j
] == '\n')
1154 if (content
[i
] == '\n')
1158 return wxEmptyString
;
1161 int wxMacTextControl::GetLineLength(long lineNo
) const
1163 // TODO: change this if possible to reflect real lines
1164 wxString content
= GetStringValue() ;
1168 for (size_t i
= 0; i
< content
.length() ; i
++)
1170 if (count
== lineNo
)
1172 // Count chars in line then
1174 for (size_t j
= i
; j
< content
.length(); j
++)
1177 if (content
[j
] == '\n')
1184 if (content
[i
] == '\n')
1191 // ----------------------------------------------------------------------------
1192 // standard unicode control implementation
1193 // ----------------------------------------------------------------------------
1195 // the current unicode textcontrol implementation has a bug : only if the control
1196 // is currently having the focus, the selection can be retrieved by the corresponding
1197 // data tag. So we have a mirroring using a member variable
1198 // TODO : build event table using virtual member functions for wxMacControl
1200 static const EventTypeSpec unicodeTextControlEventList
[] =
1202 { kEventClassControl
, kEventControlSetFocusPart
} ,
1205 static pascal OSStatus
wxMacUnicodeTextControlControlEventHandler( EventHandlerCallRef handler
, EventRef event
, void *data
)
1207 OSStatus result
= eventNotHandledErr
;
1208 wxMacUnicodeTextControl
* focus
= (wxMacUnicodeTextControl
*) data
;
1209 wxMacCarbonEvent
cEvent( event
) ;
1211 switch ( GetEventKind( event
) )
1213 case kEventControlSetFocusPart
:
1215 ControlPartCode controlPart
= cEvent
.GetParameter
<ControlPartCode
>(kEventParamControlPart
, typeControlPartCode
);
1216 if ( controlPart
== kControlFocusNoPart
)
1218 // about to loose focus -> store selection to field
1219 focus
->GetData
<ControlEditTextSelectionRec
>( 0, kControlEditTextSelectionTag
, &focus
->m_selection
);
1221 result
= CallNextEventHandler(handler
,event
) ;
1222 if ( controlPart
!= kControlFocusNoPart
)
1224 // about to gain focus -> set selection from field
1225 focus
->SetData
<ControlEditTextSelectionRec
>( 0, kControlEditTextSelectionTag
, &focus
->m_selection
);
1236 static pascal OSStatus
wxMacUnicodeTextControlEventHandler( EventHandlerCallRef handler
, EventRef event
, void *data
)
1238 OSStatus result
= eventNotHandledErr
;
1240 switch ( GetEventClass( event
) )
1242 case kEventClassControl
:
1243 result
= wxMacUnicodeTextControlControlEventHandler( handler
, event
, data
) ;
1252 DEFINE_ONE_SHOT_HANDLER_GETTER( wxMacUnicodeTextControlEventHandler
)
1254 wxMacUnicodeTextControl::wxMacUnicodeTextControl( wxTextCtrl
*wxPeer
) : wxMacTextControl( wxPeer
)
1258 wxMacUnicodeTextControl::wxMacUnicodeTextControl( wxTextCtrl
*wxPeer
,
1259 const wxString
& str
,
1261 const wxSize
& size
, long style
)
1262 : wxMacTextControl( wxPeer
)
1264 Create( wxPeer
, str
, pos
, size
, style
);
1267 bool wxMacUnicodeTextControl::Create( wxTextCtrl
*wxPeer
,
1268 const wxString
& str
,
1270 const wxSize
& size
, long style
)
1272 m_font
= wxPeer
->GetFont() ;
1273 m_windowStyle
= style
;
1274 m_selection
.selStart
= m_selection
.selEnd
= 0;
1275 Rect bounds
= wxMacGetBoundsForControl( wxPeer
, pos
, size
) ;
1277 wxMacConvertNewlines10To13( &st
) ;
1278 wxMacCFStringHolder
cf(st
, m_font
.GetEncoding()) ;
1279 CFStringRef cfr
= cf
;
1281 m_valueTag
= kControlEditTextCFStringTag
;
1282 CreateControl( wxPeer
, &bounds
, cfr
);
1284 if ( !(m_windowStyle
& wxTE_MULTILINE
) )
1285 SetData
<Boolean
>( kControlEditTextPart
, kControlEditTextSingleLineTag
, true ) ;
1287 InstallControlEventHandler( m_controlRef
, GetwxMacUnicodeTextControlEventHandlerUPP(),
1288 GetEventTypeCount(unicodeTextControlEventList
), unicodeTextControlEventList
, this,
1294 wxMacUnicodeTextControl::~wxMacUnicodeTextControl()
1298 void wxMacUnicodeTextControl::VisibilityChanged(bool shown
)
1300 if ( !(m_windowStyle
& wxTE_MULTILINE
) && shown
)
1302 // work around a refresh issue insofar as not always the entire content is shown,
1303 // even if this would be possible
1304 ControlEditTextSelectionRec sel
;
1305 CFStringRef value
= NULL
;
1307 verify_noerr( GetData
<ControlEditTextSelectionRec
>( 0, kControlEditTextSelectionTag
, &sel
) );
1308 verify_noerr( GetData
<CFStringRef
>( 0, m_valueTag
, &value
) );
1309 verify_noerr( SetData
<CFStringRef
>( 0, m_valueTag
, &value
) );
1310 verify_noerr( SetData
<ControlEditTextSelectionRec
>( 0, kControlEditTextSelectionTag
, &sel
) );
1312 CFRelease( value
) ;
1316 wxString
wxMacUnicodeTextControl::GetStringValue() const
1319 CFStringRef value
= GetData
<CFStringRef
>(0, m_valueTag
) ;
1322 wxMacCFStringHolder
cf(value
) ;
1323 result
= cf
.AsString() ;
1327 wxMacConvertNewlines13To10( &result
) ;
1329 wxMacConvertNewlines10To13( &result
) ;
1335 void wxMacUnicodeTextControl::SetStringValue( const wxString
&str
)
1338 wxMacConvertNewlines10To13( &st
) ;
1339 wxMacCFStringHolder
cf( st
, m_font
.GetEncoding() ) ;
1340 verify_noerr( SetData
<CFStringRef
>( 0, m_valueTag
, cf
) ) ;
1343 void wxMacUnicodeTextControl::CreateControl( wxTextCtrl
* peer
, const Rect
* bounds
, CFStringRef cfr
)
1345 Boolean isPassword
= ( m_windowStyle
& wxTE_PASSWORD
) != 0 ;
1348 m_valueTag
= kControlEditTextPasswordCFStringTag
;
1350 OSStatus err
= CreateEditUnicodeTextControl(
1351 MAC_WXHWND(peer
->MacGetTopLevelWindowRef()), bounds
, cfr
,
1352 isPassword
, NULL
, &m_controlRef
) ;
1353 verify_noerr( err
);
1356 void wxMacUnicodeTextControl::Copy()
1358 SendHICommand( kHICommandCopy
) ;
1361 void wxMacUnicodeTextControl::Cut()
1363 SendHICommand( kHICommandCut
) ;
1366 void wxMacUnicodeTextControl::Paste()
1368 SendHICommand( kHICommandPaste
) ;
1371 bool wxMacUnicodeTextControl::CanPaste() const
1376 void wxMacUnicodeTextControl::SetEditable(bool WXUNUSED(editable
))
1378 #if 0 // leads to problem because text cannot be selected anymore
1379 SetData
<Boolean
>( kControlEditTextPart
, kControlEditTextLockedTag
, (Boolean
) !editable
) ;
1383 void wxMacUnicodeTextControl::GetSelection( long* from
, long* to
) const
1385 ControlEditTextSelectionRec sel
;
1387 verify_noerr( GetData
<ControlEditTextSelectionRec
>( 0, kControlEditTextSelectionTag
, &sel
) ) ;
1392 *from
= sel
.selStart
;
1397 void wxMacUnicodeTextControl::SetSelection( long from
, long to
)
1399 ControlEditTextSelectionRec sel
;
1401 int textLength
= 0 ;
1402 CFStringRef value
= GetData
<CFStringRef
>(0, m_valueTag
) ;
1405 wxMacCFStringHolder
cf(value
) ;
1406 textLength
= cf
.AsString().length() ;
1409 if ((from
== -1) && (to
== -1))
1416 from
= wxMin(textLength
,wxMax(from
,0)) ;
1420 to
= wxMax(0,wxMin(textLength
,to
)) ;
1423 sel
.selStart
= from
;
1426 SetData
<ControlEditTextSelectionRec
>( 0, kControlEditTextSelectionTag
, &sel
) ;
1431 void wxMacUnicodeTextControl::WriteText( const wxString
& str
)
1434 wxMacConvertNewlines10To13( &st
) ;
1438 wxMacCFStringHolder
cf(st
, m_font
.GetEncoding() ) ;
1439 CFStringRef value
= cf
;
1440 SetData
<CFStringRef
>( 0, kControlEditTextInsertCFStringRefTag
, &value
);
1444 wxString val
= GetStringValue() ;
1446 GetSelection( &start
, &end
) ;
1447 val
.Remove( start
, end
- start
) ;
1448 val
.insert( start
, str
) ;
1449 SetStringValue( val
) ;
1450 SetSelection( start
+ str
.length() , start
+ str
.length() ) ;
1454 // ----------------------------------------------------------------------------
1455 // MLTE control implementation (common part)
1456 // ----------------------------------------------------------------------------
1458 // if MTLE is read only, no changes at all are allowed, not even from
1459 // procedural API, in order to allow changes via API all the same we must undo
1460 // the readonly status while we are executing, this class helps to do so
1462 class wxMacEditHelper
1465 wxMacEditHelper( TXNObject txn
)
1467 TXNControlTag tag
[] = { kTXNIOPrivilegesTag
} ;
1469 TXNGetTXNObjectControls( m_txn
, 1 , tag
, m_data
) ;
1470 if ( m_data
[0].uValue
== kTXNReadOnly
)
1472 TXNControlData data
[] = { { kTXNReadWrite
} } ;
1473 TXNSetTXNObjectControls( m_txn
, false , 1 , tag
, data
) ;
1479 TXNControlTag tag
[] = { kTXNIOPrivilegesTag
} ;
1480 if ( m_data
[0].uValue
== kTXNReadOnly
)
1481 TXNSetTXNObjectControls( m_txn
, false , 1 , tag
, m_data
) ;
1486 TXNControlData m_data
[1] ;
1489 wxMacMLTEControl::wxMacMLTEControl( wxTextCtrl
*peer
)
1490 : wxMacTextControl( peer
)
1492 SetNeedsFocusRect( true ) ;
1495 wxString
wxMacMLTEControl::GetStringValue() const
1499 Size actualSize
= 0;
1504 err
= TXNGetDataEncoded( m_txn
, kTXNStartOffset
, kTXNEndOffset
, &theText
, kTXNUnicodeTextData
);
1513 actualSize
= GetHandleSize( theText
) / sizeof(UniChar
) ;
1514 if ( actualSize
> 0 )
1516 wxChar
*ptr
= NULL
;
1518 #if SIZEOF_WCHAR_T == 2
1519 ptr
= new wxChar
[actualSize
+ 1] ;
1520 wxStrncpy( ptr
, (wxChar
*)(*theText
) , actualSize
) ;
1522 SetHandleSize( theText
, (actualSize
+ 1) * sizeof(UniChar
) ) ;
1524 (((UniChar
*)*theText
)[actualSize
]) = 0 ;
1525 wxMBConvUTF16 converter
;
1526 size_t noChars
= converter
.MB2WC( NULL
, (const char*)*theText
, 0 ) ;
1527 wxASSERT_MSG( noChars
!= wxCONV_FAILED
, _T("Unable to count the number of characters in this string!") );
1528 ptr
= new wxChar
[noChars
+ 1] ;
1530 noChars
= converter
.MB2WC( ptr
, (const char*)*theText
, noChars
+ 1 ) ;
1531 wxASSERT_MSG( noChars
!= wxCONV_FAILED
, _T("Conversion of string failed!") );
1533 HUnlock( theText
) ;
1536 ptr
[actualSize
] = 0 ;
1537 result
= wxString( ptr
) ;
1541 DisposeHandle( theText
) ;
1545 err
= TXNGetDataEncoded( m_txn
, kTXNStartOffset
, kTXNEndOffset
, &theText
, kTXNTextData
);
1554 actualSize
= GetHandleSize( theText
) ;
1555 if ( actualSize
> 0 )
1558 result
= wxString( *theText
, wxConvLocal
, actualSize
) ;
1559 HUnlock( theText
) ;
1562 DisposeHandle( theText
) ;
1568 wxMacConvertNewlines13To10( &result
) ;
1570 wxMacConvertNewlines10To13( &result
) ;
1576 void wxMacMLTEControl::SetStringValue( const wxString
&str
)
1579 wxMacConvertNewlines10To13( &st
);
1583 wxMacWindowClipper
c( m_peer
) ;
1587 wxMacEditHelper
help( m_txn
);
1588 SetTXNData( st
, kTXNStartOffset
, kTXNEndOffset
);
1591 TXNSetSelection( m_txn
, 0, 0 );
1592 TXNShowSelection( m_txn
, kTXNShowStart
);
1596 TXNFrameOptions
wxMacMLTEControl::FrameOptionsFromWXStyle( long wxStyle
)
1598 TXNFrameOptions frameOptions
= kTXNDontDrawCaretWhenInactiveMask
;
1600 frameOptions
|= kTXNDoFontSubstitutionMask
;
1602 if ( ! (wxStyle
& wxTE_NOHIDESEL
) )
1603 frameOptions
|= kTXNDontDrawSelectionWhenInactiveMask
;
1605 if ( wxStyle
& (wxHSCROLL
| wxTE_DONTWRAP
) )
1606 frameOptions
|= kTXNWantHScrollBarMask
;
1608 if ( wxStyle
& wxTE_MULTILINE
)
1610 frameOptions
|= kTXNAlwaysWrapAtViewEdgeMask
;
1612 if ( !(wxStyle
& wxTE_NO_VSCROLL
) )
1614 frameOptions
|= kTXNWantVScrollBarMask
;
1616 // The following code causes drawing problems on 10.4. Perhaps it can be restored for
1617 // older versions of the OS, but I'm not sure it's appropriate to put a grow icon here
1618 // anyways, as AFAIK users can't actually use it to resize the text ctrl.
1619 // if ( frameOptions & kTXNWantHScrollBarMask )
1620 // frameOptions |= kTXNDrawGrowIconMask ;
1625 frameOptions
|= kTXNSingleLineOnlyMask
;
1628 return frameOptions
;
1631 void wxMacMLTEControl::AdjustCreationAttributes(const wxColour
&background
,
1632 bool WXUNUSED(visible
))
1634 TXNControlTag iControlTags
[] =
1636 kTXNDoFontSubstitution
,
1637 kTXNWordWrapStateTag
,
1639 TXNControlData iControlData
[] =
1645 int toptag
= WXSIZEOF( iControlTags
) ;
1647 if ( m_windowStyle
& wxTE_MULTILINE
)
1649 iControlData
[1].uValue
=
1650 (m_windowStyle
& wxTE_DONTWRAP
)
1655 OSStatus err
= TXNSetTXNObjectControls( m_txn
, false, toptag
, iControlTags
, iControlData
) ;
1656 verify_noerr( err
);
1658 // setting the default font:
1659 // under 10.2 this causes a visible caret, therefore we avoid it
1665 GetThemeFont( kThemeSystemFont
, GetApplicationScript() , fontName
, &fontSize
, &fontStyle
) ;
1667 TXNTypeAttributes typeAttr
[] =
1669 { kTXNQDFontNameAttribute
, kTXNQDFontNameAttributeSize
, { (void*) fontName
} } ,
1670 { kTXNQDFontSizeAttribute
, kTXNFontSizeAttributeSize
, { (void*) (fontSize
<< 16) } } ,
1671 { kTXNQDFontStyleAttribute
, kTXNQDFontStyleAttributeSize
, { (void*) normal
} } ,
1674 err
= TXNSetTypeAttributes(
1675 m_txn
, sizeof(typeAttr
) / sizeof(TXNTypeAttributes
),
1676 typeAttr
, kTXNStartOffset
, kTXNEndOffset
);
1677 verify_noerr( err
);
1679 if ( m_windowStyle
& wxTE_PASSWORD
)
1681 UniChar c
= 0x00A5 ;
1682 err
= TXNEchoMode( m_txn
, c
, 0 , true );
1683 verify_noerr( err
);
1686 TXNBackground tback
;
1687 tback
.bgType
= kTXNBackgroundTypeRGB
;
1688 background
.GetRGBColor( &tback
.bg
.color
);
1689 TXNSetBackground( m_txn
, &tback
);
1692 TXNCommandEventSupportOptions options
;
1693 if ( TXNGetCommandEventSupport( m_txn
, &options
) == noErr
)
1696 kTXNSupportEditCommandProcessing
1697 | kTXNSupportEditCommandUpdating
1698 | kTXNSupportFontCommandProcessing
1699 | kTXNSupportFontCommandUpdating
;
1701 // only spell check when not read-only
1702 // use system options for the default
1703 bool checkSpelling
= false ;
1704 if ( !(m_windowStyle
& wxTE_READONLY
) )
1706 #if wxUSE_SYSTEM_OPTIONS
1707 if ( wxSystemOptions::HasOption( wxMAC_TEXTCONTROL_USE_SPELL_CHECKER
) && (wxSystemOptions::GetOptionInt( wxMAC_TEXTCONTROL_USE_SPELL_CHECKER
) == 1) )
1709 checkSpelling
= true ;
1714 if ( checkSpelling
)
1716 kTXNSupportSpellCheckCommandProcessing
1717 | kTXNSupportSpellCheckCommandUpdating
;
1719 TXNSetCommandEventSupport( m_txn
, options
) ;
1723 void wxMacMLTEControl::SetBackground( const wxBrush
&brush
)
1725 // currently only solid background are supported
1726 TXNBackground tback
;
1728 tback
.bgType
= kTXNBackgroundTypeRGB
;
1729 brush
.GetColour().GetRGBColor(&tback
.bg
.color
);
1730 TXNSetBackground( m_txn
, &tback
);
1733 static inline int wxConvertToTXN(int x
)
1735 return wx_static_cast(int, x
/ 254.0 * 72 + 0.5);
1738 void wxMacMLTEControl::TXNSetAttribute( const wxTextAttr
& style
, long from
, long to
)
1740 TXNTypeAttributes typeAttr
[4] ;
1742 size_t typeAttrCount
= 0 ;
1745 TXNControlTag controlTags
[4];
1746 TXNControlData controlData
[4];
1747 size_t controlAttrCount
= 0;
1749 TXNTab
* tabs
= NULL
;
1751 bool relayout
= false;
1753 if ( style
.HasFont() )
1755 wxASSERT( typeAttrCount
< WXSIZEOF(typeAttr
) );
1756 const wxFont
&font
= style
.GetFont() ;
1757 typeAttr
[typeAttrCount
].tag
= kTXNATSUIStyle
;
1758 typeAttr
[typeAttrCount
].size
= kTXNATSUIStyleSize
;
1759 typeAttr
[typeAttrCount
].data
.dataPtr
= font
.MacGetATSUStyle() ;
1763 if ( style
.HasTextColour() )
1765 wxASSERT( typeAttrCount
< WXSIZEOF(typeAttr
) );
1766 style
.GetTextColour().GetRGBColor( &color
);
1767 typeAttr
[typeAttrCount
].tag
= kTXNQDFontColorAttribute
;
1768 typeAttr
[typeAttrCount
].size
= kTXNQDFontColorAttributeSize
;
1769 typeAttr
[typeAttrCount
].data
.dataPtr
= (void*) &color
;
1773 if ( style
.HasAlignment() )
1775 wxASSERT( controlAttrCount
< WXSIZEOF(controlTags
) );
1778 switch ( style
.GetAlignment() )
1780 case wxTEXT_ALIGNMENT_LEFT
:
1781 align
= kTXNFlushLeft
;
1783 case wxTEXT_ALIGNMENT_CENTRE
:
1786 case wxTEXT_ALIGNMENT_RIGHT
:
1787 align
= kTXNFlushRight
;
1789 case wxTEXT_ALIGNMENT_JUSTIFIED
:
1790 align
= kTXNFullJust
;
1793 case wxTEXT_ALIGNMENT_DEFAULT
:
1794 align
= kTXNFlushDefault
;
1798 controlTags
[controlAttrCount
] = kTXNJustificationTag
;
1799 controlData
[controlAttrCount
].sValue
= align
;
1800 controlAttrCount
++ ;
1803 if ( style
.HasLeftIndent() || style
.HasRightIndent() )
1805 wxASSERT( controlAttrCount
< WXSIZEOF(controlTags
) );
1806 controlTags
[controlAttrCount
] = kTXNMarginsTag
;
1807 controlData
[controlAttrCount
].marginsPtr
= &margins
;
1808 verify_noerr( TXNGetTXNObjectControls (m_txn
, 1 ,
1809 &controlTags
[controlAttrCount
], &controlData
[controlAttrCount
]) );
1810 if ( style
.HasLeftIndent() )
1812 margins
.leftMargin
= wxConvertToTXN(style
.GetLeftIndent());
1814 if ( style
.HasRightIndent() )
1816 margins
.rightMargin
= wxConvertToTXN(style
.GetRightIndent());
1818 controlAttrCount
++ ;
1821 if ( style
.HasTabs() )
1823 const wxArrayInt
& tabarray
= style
.GetTabs();
1824 // unfortunately Mac only applies a tab distance, not individually different tabs
1825 controlTags
[controlAttrCount
] = kTXNTabSettingsTag
;
1826 if ( tabarray
.size() > 0 )
1827 controlData
[controlAttrCount
].tabValue
.value
= wxConvertToTXN(tabarray
[0]);
1829 controlData
[controlAttrCount
].tabValue
.value
= 72 ;
1831 controlData
[controlAttrCount
].tabValue
.tabType
= kTXNLeftTab
;
1832 controlAttrCount
++ ;
1835 // unfortunately the relayout is not automatic
1836 if ( controlAttrCount
> 0 )
1838 verify_noerr( TXNSetTXNObjectControls (m_txn
, false /* don't clear all */, controlAttrCount
,
1839 controlTags
, controlData
) );
1843 if ( typeAttrCount
> 0 )
1845 verify_noerr( TXNSetTypeAttributes( m_txn
, typeAttrCount
, typeAttr
, from
, to
) );
1856 TXNRecalcTextLayout( m_txn
);
1860 void wxMacMLTEControl::SetFont(const wxFont
& font
,
1861 const wxColour
& foreground
,
1862 long WXUNUSED(windowStyle
))
1864 wxMacEditHelper
help( m_txn
) ;
1865 TXNSetAttribute( wxTextAttr( foreground
, wxNullColour
, font
), kTXNStartOffset
, kTXNEndOffset
) ;
1868 void wxMacMLTEControl::SetStyle( long start
, long end
, const wxTextAttr
& style
)
1870 wxMacEditHelper
help( m_txn
) ;
1871 TXNSetAttribute( style
, start
, end
) ;
1874 void wxMacMLTEControl::Copy()
1879 void wxMacMLTEControl::Cut()
1884 void wxMacMLTEControl::Paste()
1889 bool wxMacMLTEControl::CanPaste() const
1891 return TXNIsScrapPastable() ;
1894 void wxMacMLTEControl::SetEditable(bool editable
)
1896 TXNControlTag tag
[] = { kTXNIOPrivilegesTag
} ;
1897 TXNControlData data
[] = { { editable
? kTXNReadWrite
: kTXNReadOnly
} } ;
1898 TXNSetTXNObjectControls( m_txn
, false, WXSIZEOF(tag
), tag
, data
) ;
1901 wxTextPos
wxMacMLTEControl::GetLastPosition() const
1903 wxTextPos actualsize
= 0 ;
1906 OSErr err
= TXNGetDataEncoded( m_txn
, kTXNStartOffset
, kTXNEndOffset
, &theText
, kTXNTextData
);
1911 actualsize
= GetHandleSize( theText
) ;
1912 DisposeHandle( theText
) ;
1922 void wxMacMLTEControl::Replace( long from
, long to
, const wxString
&str
)
1924 wxString value
= str
;
1925 wxMacConvertNewlines10To13( &value
) ;
1927 wxMacEditHelper
help( m_txn
) ;
1929 wxMacWindowClipper
c( m_peer
) ;
1932 TXNSetSelection( m_txn
, from
, to
== -1 ? kTXNEndOffset
: to
) ;
1934 SetTXNData( value
, kTXNUseCurrentSelection
, kTXNUseCurrentSelection
) ;
1937 void wxMacMLTEControl::Remove( long from
, long to
)
1940 wxMacWindowClipper
c( m_peer
) ;
1942 wxMacEditHelper
help( m_txn
) ;
1943 TXNSetSelection( m_txn
, from
, to
) ;
1947 void wxMacMLTEControl::GetSelection( long* from
, long* to
) const
1950 TXNGetSelection( m_txn
, &f
, &t
) ;
1955 void wxMacMLTEControl::SetSelection( long from
, long to
)
1958 wxMacWindowClipper
c( m_peer
) ;
1961 // change the selection
1962 if ((from
== -1) && (to
== -1))
1963 TXNSelectAll( m_txn
);
1965 TXNSetSelection( m_txn
, from
, to
== -1 ? kTXNEndOffset
: to
);
1967 TXNShowSelection( m_txn
, kTXNShowStart
);
1970 void wxMacMLTEControl::WriteText( const wxString
& str
)
1973 wxMacConvertNewlines10To13( &st
) ;
1975 long start
, end
, dummy
;
1977 GetSelection( &start
, &dummy
) ;
1979 wxMacWindowClipper
c( m_peer
) ;
1983 wxMacEditHelper
helper( m_txn
) ;
1984 SetTXNData( st
, kTXNUseCurrentSelection
, kTXNUseCurrentSelection
) ;
1987 GetSelection( &dummy
, &end
) ;
1989 // TODO: SetStyle( start , end , GetDefaultStyle() ) ;
1992 void wxMacMLTEControl::Clear()
1995 wxMacWindowClipper
c( m_peer
) ;
1997 wxMacEditHelper
st( m_txn
) ;
1998 TXNSetSelection( m_txn
, kTXNStartOffset
, kTXNEndOffset
) ;
2002 bool wxMacMLTEControl::CanUndo() const
2004 return TXNCanUndo( m_txn
, NULL
) ;
2007 void wxMacMLTEControl::Undo()
2012 bool wxMacMLTEControl::CanRedo() const
2014 return TXNCanRedo( m_txn
, NULL
) ;
2017 void wxMacMLTEControl::Redo()
2022 int wxMacMLTEControl::GetNumberOfLines() const
2024 ItemCount lines
= 0 ;
2025 TXNGetLineCount( m_txn
, &lines
) ;
2030 long wxMacMLTEControl::XYToPosition(long x
, long y
) const
2035 // TODO: find a better implementation : while we can get the
2036 // line metrics of a certain line, we don't get its starting
2037 // position, so it would probably be rather a binary search
2038 // for the start position
2039 long xpos
= 0, ypos
= 0 ;
2040 int lastHeight
= 0 ;
2043 lastpos
= GetLastPosition() ;
2044 for ( n
= 0 ; n
<= (ItemCount
) lastpos
; ++n
)
2046 if ( y
== ypos
&& x
== xpos
)
2049 TXNOffsetToPoint( m_txn
, n
, &curpt
) ;
2051 if ( curpt
.v
> lastHeight
)
2057 lastHeight
= curpt
.v
;
2066 bool wxMacMLTEControl::PositionToXY( long pos
, long *x
, long *y
) const
2076 lastpos
= GetLastPosition() ;
2077 if ( pos
<= lastpos
)
2079 // TODO: find a better implementation - while we can get the
2080 // line metrics of a certain line, we don't get its starting
2081 // position, so it would probably be rather a binary search
2082 // for the start position
2083 long xpos
= 0, ypos
= 0 ;
2084 int lastHeight
= 0 ;
2087 for ( n
= 0 ; n
<= (ItemCount
) pos
; ++n
)
2089 TXNOffsetToPoint( m_txn
, n
, &curpt
) ;
2091 if ( curpt
.v
> lastHeight
)
2097 lastHeight
= curpt
.v
;
2112 void wxMacMLTEControl::ShowPosition( long pos
)
2114 Point current
, desired
;
2115 TXNOffset selstart
, selend
;
2117 TXNGetSelection( m_txn
, &selstart
, &selend
);
2118 TXNOffsetToPoint( m_txn
, selstart
, ¤t
);
2119 TXNOffsetToPoint( m_txn
, pos
, &desired
);
2121 // TODO: use HIPoints for 10.3 and above
2123 OSErr theErr
= noErr
;
2124 long dv
= desired
.v
- current
.v
;
2125 long dh
= desired
.h
- current
.h
;
2126 TXNShowSelection( m_txn
, kTXNShowStart
) ; // NB: should this be kTXNShowStart or kTXNShowEnd ??
2127 theErr
= TXNScroll( m_txn
, kTXNScrollUnitsInPixels
, kTXNScrollUnitsInPixels
, &dv
, &dh
);
2129 // there will be an error returned for classic MLTE implementation when the control is
2130 // invisible, but HITextView works correctly, so we don't assert that one
2131 // wxASSERT_MSG( theErr == noErr, _T("TXNScroll returned an error!") );
2134 void wxMacMLTEControl::SetTXNData( const wxString
& st
, TXNOffset start
, TXNOffset end
)
2137 #if SIZEOF_WCHAR_T == 2
2138 size_t len
= st
.length() ;
2139 TXNSetData( m_txn
, kTXNUnicodeTextData
, (void*)st
.wc_str(), len
* 2, start
, end
);
2141 wxMBConvUTF16 converter
;
2142 ByteCount byteBufferLen
= converter
.WC2MB( NULL
, st
.wc_str(), 0 ) ;
2143 UniChar
*unibuf
= (UniChar
*)malloc( byteBufferLen
) ;
2144 converter
.WC2MB( (char*)unibuf
, st
.wc_str(), byteBufferLen
) ;
2145 TXNSetData( m_txn
, kTXNUnicodeTextData
, (void*)unibuf
, byteBufferLen
, start
, end
) ;
2149 wxCharBuffer text
= st
.mb_str( wxConvLocal
) ;
2150 TXNSetData( m_txn
, kTXNTextData
, (void*)text
.data(), strlen( text
), start
, end
) ;
2154 wxString
wxMacMLTEControl::GetLineText(long lineNo
) const
2158 if ( lineNo
< GetNumberOfLines() )
2161 Fixed lineWidth
, lineHeight
, currentHeight
;
2164 // get the first possible position in the control
2165 TXNOffsetToPoint(m_txn
, 0, &firstPoint
);
2167 // Iterate through the lines until we reach the one we want,
2168 // adding to our current y pixel point position
2171 while (ypos
< lineNo
)
2173 TXNGetLineMetrics(m_txn
, ypos
++, &lineWidth
, &lineHeight
);
2174 currentHeight
+= lineHeight
;
2177 Point thePoint
= { firstPoint
.v
+ (currentHeight
>> 16), firstPoint
.h
+ (0) };
2178 TXNOffset theOffset
;
2179 TXNPointToOffset(m_txn
, thePoint
, &theOffset
);
2181 wxString content
= GetStringValue() ;
2182 Point currentPoint
= thePoint
;
2183 while (thePoint
.v
== currentPoint
.v
&& theOffset
< content
.length())
2185 line
+= content
[theOffset
];
2186 TXNOffsetToPoint(m_txn
, ++theOffset
, ¤tPoint
);
2193 int wxMacMLTEControl::GetLineLength(long lineNo
) const
2197 if ( lineNo
< GetNumberOfLines() )
2200 Fixed lineWidth
, lineHeight
, currentHeight
;
2203 // get the first possible position in the control
2204 TXNOffsetToPoint(m_txn
, 0, &firstPoint
);
2206 // Iterate through the lines until we reach the one we want,
2207 // adding to our current y pixel point position
2210 while (ypos
< lineNo
)
2212 TXNGetLineMetrics(m_txn
, ypos
++, &lineWidth
, &lineHeight
);
2213 currentHeight
+= lineHeight
;
2216 Point thePoint
= { firstPoint
.v
+ (currentHeight
>> 16), firstPoint
.h
+ (0) };
2217 TXNOffset theOffset
;
2218 TXNPointToOffset(m_txn
, thePoint
, &theOffset
);
2220 wxString content
= GetStringValue() ;
2221 Point currentPoint
= thePoint
;
2222 while (thePoint
.v
== currentPoint
.v
&& theOffset
< content
.length())
2225 TXNOffsetToPoint(m_txn
, ++theOffset
, ¤tPoint
);
2232 #if MAC_OS_X_VERSION_MIN_REQUIRED < MAC_OS_X_VERSION_10_5
2234 // ----------------------------------------------------------------------------
2235 // MLTE control implementation (classic part)
2236 // ----------------------------------------------------------------------------
2238 // OS X Notes : We still don't have a full replacement for MLTE, so this implementation
2239 // has to live on. We have different problems coming from outdated implementations on the
2240 // various OS X versions. Most deal with the scrollbars: they are not correctly embedded
2241 // while this can be solved on 10.3 by reassigning them the correct place, on 10.2 there is
2242 // no way out, therefore we are using our own implementation and our own scrollbars ....
2244 TXNScrollInfoUPP gTXNScrollInfoProc
= NULL
;
2245 ControlActionUPP gTXNScrollActionProc
= NULL
;
2247 pascal void wxMacMLTEClassicControl::TXNScrollInfoProc(
2248 SInt32 iValue
, SInt32 iMaximumValue
,
2249 TXNScrollBarOrientation iScrollBarOrientation
, SInt32 iRefCon
)
2251 wxMacMLTEClassicControl
* mlte
= (wxMacMLTEClassicControl
*) iRefCon
;
2252 SInt32 value
= wxMax( iValue
, 0 ) ;
2253 SInt32 maximum
= wxMax( iMaximumValue
, 0 ) ;
2255 if ( iScrollBarOrientation
== kTXNHorizontal
)
2257 if ( mlte
->m_sbHorizontal
)
2259 SetControl32BitValue( mlte
->m_sbHorizontal
, value
) ;
2260 SetControl32BitMaximum( mlte
->m_sbHorizontal
, maximum
) ;
2261 mlte
->m_lastHorizontalValue
= value
;
2264 else if ( iScrollBarOrientation
== kTXNVertical
)
2266 if ( mlte
->m_sbVertical
)
2268 SetControl32BitValue( mlte
->m_sbVertical
, value
) ;
2269 SetControl32BitMaximum( mlte
->m_sbVertical
, maximum
) ;
2270 mlte
->m_lastVerticalValue
= value
;
2275 pascal void wxMacMLTEClassicControl::TXNScrollActionProc( ControlRef controlRef
, ControlPartCode partCode
)
2277 wxMacMLTEClassicControl
* mlte
= (wxMacMLTEClassicControl
*) GetControlReference( controlRef
) ;
2281 if ( controlRef
!= mlte
->m_sbVertical
&& controlRef
!= mlte
->m_sbHorizontal
)
2285 bool isHorizontal
= ( controlRef
== mlte
->m_sbHorizontal
) ;
2287 SInt32 minimum
= 0 ;
2288 SInt32 maximum
= GetControl32BitMaximum( controlRef
) ;
2289 SInt32 value
= GetControl32BitValue( controlRef
) ;
2294 case kControlDownButtonPart
:
2298 case kControlUpButtonPart
:
2302 case kControlPageDownPart
:
2303 delta
= GetControlViewSize( controlRef
) ;
2306 case kControlPageUpPart
:
2307 delta
= -GetControlViewSize( controlRef
) ;
2310 case kControlIndicatorPart
:
2311 delta
= value
- (isHorizontal
? mlte
->m_lastHorizontalValue
: mlte
->m_lastVerticalValue
) ;
2320 SInt32 newValue
= value
;
2322 if ( partCode
!= kControlIndicatorPart
)
2324 if ( value
+ delta
< minimum
)
2325 delta
= minimum
- value
;
2326 if ( value
+ delta
> maximum
)
2327 delta
= maximum
- value
;
2329 SetControl32BitValue( controlRef
, value
+ delta
) ;
2330 newValue
= value
+ delta
;
2333 SInt32 verticalDelta
= isHorizontal
? 0 : delta
;
2334 SInt32 horizontalDelta
= isHorizontal
? delta
: 0 ;
2337 mlte
->m_txn
, kTXNScrollUnitsInPixels
, kTXNScrollUnitsInPixels
,
2338 &verticalDelta
, &horizontalDelta
);
2339 verify_noerr( err
);
2342 mlte
->m_lastHorizontalValue
= newValue
;
2344 mlte
->m_lastVerticalValue
= newValue
;
2348 // make correct activations
2349 void wxMacMLTEClassicControl::MacActivatePaneText(bool setActive
)
2351 wxTextCtrl
* textctrl
= (wxTextCtrl
*) GetControlReference(m_controlRef
);
2353 wxMacWindowClipper
clipper( textctrl
) ;
2354 TXNActivate( m_txn
, m_txnFrameID
, setActive
);
2356 ControlRef controlFocus
= 0 ;
2357 GetKeyboardFocus( m_txnWindow
, &controlFocus
) ;
2358 if ( controlFocus
== m_controlRef
)
2359 TXNFocus( m_txn
, setActive
);
2362 void wxMacMLTEClassicControl::MacFocusPaneText(bool setFocus
)
2364 TXNFocus( m_txn
, setFocus
);
2367 // guards against inappropriate redraw (hidden objects drawing onto window)
2369 void wxMacMLTEClassicControl::MacSetObjectVisibility(bool vis
)
2371 ControlRef controlFocus
= 0 ;
2372 GetKeyboardFocus( m_txnWindow
, &controlFocus
) ;
2374 if ( !vis
&& (controlFocus
== m_controlRef
) )
2375 SetKeyboardFocus( m_txnWindow
, m_controlRef
, kControlFocusNoPart
) ;
2377 TXNControlTag iControlTags
[1] = { kTXNVisibilityTag
};
2378 TXNControlData iControlData
[1] = { { (UInt32
)false } };
2380 verify_noerr( TXNGetTXNObjectControls( m_txn
, 1, iControlTags
, iControlData
) ) ;
2382 if ( iControlData
[0].uValue
!= vis
)
2384 iControlData
[0].uValue
= vis
;
2385 verify_noerr( TXNSetTXNObjectControls( m_txn
, false , 1, iControlTags
, iControlData
) ) ;
2388 // currently, we always clip as partial visibility (overlapped) visibility is also a problem,
2389 // if we run into further problems we might set the FrameBounds to an empty rect here
2392 // make sure that the TXNObject is at the right position
2394 void wxMacMLTEClassicControl::MacUpdatePosition()
2396 wxTextCtrl
* textctrl
= (wxTextCtrl
*)GetControlReference( m_controlRef
);
2397 if ( textctrl
== NULL
)
2401 UMAGetControlBoundsInWindowCoords( m_controlRef
, &bounds
);
2403 wxRect visRect
= textctrl
->MacGetClippedClientRect() ;
2404 Rect visBounds
= { visRect
.y
, visRect
.x
, visRect
.y
+ visRect
.height
, visRect
.x
+ visRect
.width
} ;
2407 textctrl
->MacWindowToRootWindow( &x
, &y
) ;
2408 OffsetRect( &visBounds
, x
, y
) ;
2410 if ( !EqualRect( &bounds
, &m_txnControlBounds
) || !EqualRect( &visBounds
, &m_txnVisBounds
) )
2412 m_txnControlBounds
= bounds
;
2413 m_txnVisBounds
= visBounds
;
2414 wxMacWindowClipper
cl( textctrl
) ;
2416 if ( m_sbHorizontal
|| m_sbVertical
)
2418 int w
= bounds
.right
- bounds
.left
;
2419 int h
= bounds
.bottom
- bounds
.top
;
2421 if ( m_sbHorizontal
)
2425 sbBounds
.left
= -1 ;
2426 sbBounds
.top
= h
- 14 ;
2427 sbBounds
.right
= w
+ 1 ;
2428 sbBounds
.bottom
= h
+ 1 ;
2430 SetControlBounds( m_sbHorizontal
, &sbBounds
) ;
2431 SetControlViewSize( m_sbHorizontal
, w
) ;
2438 sbBounds
.left
= w
- 14 ;
2440 sbBounds
.right
= w
+ 1 ;
2441 sbBounds
.bottom
= m_sbHorizontal
? h
- 14 : h
+ 1 ;
2443 SetControlBounds( m_sbVertical
, &sbBounds
) ;
2444 SetControlViewSize( m_sbVertical
, h
) ;
2449 TXNLongRect olddestRect
;
2450 TXNGetRectBounds( m_txn
, &oldviewRect
, &olddestRect
, NULL
) ;
2452 Rect viewRect
= { m_txnControlBounds
.top
, m_txnControlBounds
.left
,
2453 m_txnControlBounds
.bottom
- ( m_sbHorizontal
? 14 : 0 ) ,
2454 m_txnControlBounds
.right
- ( m_sbVertical
? 14 : 0 ) } ;
2455 TXNLongRect destRect
= { m_txnControlBounds
.top
, m_txnControlBounds
.left
,
2456 m_txnControlBounds
.bottom
- ( m_sbHorizontal
? 14 : 0 ) ,
2457 m_txnControlBounds
.right
- ( m_sbVertical
? 14 : 0 ) } ;
2459 if ( olddestRect
.right
>= 10000 )
2460 destRect
.right
= destRect
.left
+ 32000 ;
2462 if ( olddestRect
.bottom
>= 0x20000000 )
2463 destRect
.bottom
= destRect
.top
+ 0x40000000 ;
2465 SectRect( &viewRect
, &visBounds
, &viewRect
) ;
2466 TXNSetRectBounds( m_txn
, &viewRect
, &destRect
, true ) ;
2471 m_txnControlBounds
.top
,
2472 m_txnControlBounds
.left
,
2473 m_txnControlBounds
.bottom
- (m_sbHorizontal
? 14 : 0),
2474 m_txnControlBounds
.right
- (m_sbVertical
? 14 : 0),
2478 // the SetFrameBounds method under Classic sometimes does not correctly scroll a selection into sight after a
2479 // movement, therefore we have to force it
2481 // this problem has been reported in OSX as well, so we use this here once again
2483 TXNLongRect textRect
;
2484 TXNGetRectBounds( m_txn
, NULL
, NULL
, &textRect
) ;
2485 if ( textRect
.left
< m_txnControlBounds
.left
)
2486 TXNShowSelection( m_txn
, kTXNShowStart
) ;
2490 void wxMacMLTEClassicControl::SetRect( Rect
*r
)
2492 wxMacControl::SetRect( r
) ;
2493 MacUpdatePosition() ;
2496 void wxMacMLTEClassicControl::MacControlUserPaneDrawProc(wxInt16
WXUNUSED(thePart
))
2498 wxTextCtrl
* textctrl
= (wxTextCtrl
*)GetControlReference( m_controlRef
);
2499 if ( textctrl
== NULL
)
2502 if ( textctrl
->MacIsReallyShown() )
2504 wxMacWindowClipper
clipper( textctrl
) ;
2505 TXNDraw( m_txn
, NULL
) ;
2509 wxInt16
wxMacMLTEClassicControl::MacControlUserPaneHitTestProc(wxInt16 x
, wxInt16 y
)
2511 Point where
= { y
, x
} ;
2512 ControlPartCode result
= kControlNoPart
;
2514 wxTextCtrl
* textctrl
= (wxTextCtrl
*) GetControlReference( m_controlRef
);
2515 if ( (textctrl
!= NULL
) && textctrl
->MacIsReallyShown() )
2517 if (PtInRect( where
, &m_txnControlBounds
))
2519 result
= kControlEditTextPart
;
2523 // sometimes we get the coords also in control local coordinates, therefore test again
2525 textctrl
->MacClientToRootWindow( &x
, &y
) ;
2529 if (PtInRect( where
, &m_txnControlBounds
))
2530 result
= kControlEditTextPart
;
2537 wxInt16
wxMacMLTEClassicControl::MacControlUserPaneTrackingProc( wxInt16 x
, wxInt16 y
, void* WXUNUSED(actionProc
) )
2539 ControlPartCode result
= kControlNoPart
;
2541 wxTextCtrl
* textctrl
= (wxTextCtrl
*) GetControlReference( m_controlRef
);
2542 if ( (textctrl
!= NULL
) && textctrl
->MacIsReallyShown() )
2544 Point startPt
= { y
, x
} ;
2546 // for compositing, we must convert these into toplevel window coordinates, because hittesting expects them
2548 textctrl
->MacClientToRootWindow( &x
, &y
) ;
2552 switch (MacControlUserPaneHitTestProc( startPt
.h
, startPt
.v
))
2554 case kControlEditTextPart
:
2556 wxMacWindowClipper
clipper( textctrl
) ;
2559 ConvertEventRefToEventRecord( (EventRef
) wxTheApp
->MacGetCurrentEvent() , &rec
) ;
2560 TXNClick( m_txn
, &rec
);
2572 void wxMacMLTEClassicControl::MacControlUserPaneIdleProc()
2574 wxTextCtrl
* textctrl
= (wxTextCtrl
*)GetControlReference( m_controlRef
);
2575 if ( textctrl
== NULL
)
2578 if (textctrl
->MacIsReallyShown())
2580 if (IsControlActive(m_controlRef
))
2584 wxMacWindowClipper
clipper( textctrl
) ;
2589 if (PtInRect(mousep
, &m_txnControlBounds
))
2591 RgnHandle theRgn
= NewRgn();
2592 RectRgn(theRgn
, &m_txnControlBounds
);
2593 TXNAdjustCursor(m_txn
, theRgn
);
2600 wxInt16
wxMacMLTEClassicControl::MacControlUserPaneKeyDownProc (wxInt16 keyCode
, wxInt16 charCode
, wxInt16 modifiers
)
2602 wxTextCtrl
* textctrl
= (wxTextCtrl
*)GetControlReference( m_controlRef
);
2603 if ( textctrl
== NULL
)
2604 return kControlNoPart
;
2606 wxMacWindowClipper
clipper( textctrl
) ;
2609 memset( &ev
, 0 , sizeof( ev
) ) ;
2611 ev
.modifiers
= modifiers
;
2612 ev
.message
= ((keyCode
<< 8) & keyCodeMask
) | (charCode
& charCodeMask
);
2613 TXNKeyDown( m_txn
, &ev
);
2615 return kControlEntireControl
;
2618 void wxMacMLTEClassicControl::MacControlUserPaneActivateProc(bool activating
)
2620 MacActivatePaneText( activating
);
2623 wxInt16
wxMacMLTEClassicControl::MacControlUserPaneFocusProc(wxInt16 action
)
2625 ControlPartCode focusResult
= kControlFocusNoPart
;
2627 wxTextCtrl
* textctrl
= (wxTextCtrl
*)GetControlReference( m_controlRef
);
2628 if ( textctrl
== NULL
)
2631 wxMacWindowClipper
clipper( textctrl
) ;
2633 ControlRef controlFocus
= NULL
;
2634 GetKeyboardFocus( m_txnWindow
, &controlFocus
) ;
2635 bool wasFocused
= ( controlFocus
== m_controlRef
) ;
2639 case kControlFocusPrevPart
:
2640 case kControlFocusNextPart
:
2641 MacFocusPaneText( !wasFocused
);
2642 focusResult
= (!wasFocused
? (ControlPartCode
) kControlEditTextPart
: (ControlPartCode
) kControlFocusNoPart
);
2645 case kControlFocusNoPart
:
2647 MacFocusPaneText( false );
2648 focusResult
= kControlFocusNoPart
;
2655 void wxMacMLTEClassicControl::MacControlUserPaneBackgroundProc( void *WXUNUSED(info
) )
2659 wxMacMLTEClassicControl::wxMacMLTEClassicControl( wxTextCtrl
*wxPeer
,
2660 const wxString
& str
,
2662 const wxSize
& size
, long style
)
2663 : wxMacMLTEControl( wxPeer
)
2665 m_font
= wxPeer
->GetFont() ;
2666 m_windowStyle
= style
;
2667 Rect bounds
= wxMacGetBoundsForControl( wxPeer
, pos
, size
) ;
2670 kControlSupportsEmbedding
| kControlSupportsFocus
| kControlWantsIdle
2671 | kControlWantsActivate
| kControlHandlesTracking
2672 // | kControlHasSpecialBackground
2673 | kControlGetsFocusOnClick
| kControlSupportsLiveFeedback
;
2675 OSStatus err
= ::CreateUserPaneControl(
2676 MAC_WXHWND(wxPeer
->GetParent()->MacGetTopLevelWindowRef()),
2677 &bounds
, featureSet
, &m_controlRef
);
2678 verify_noerr( err
);
2682 AdjustCreationAttributes( *wxWHITE
, true ) ;
2684 MacSetObjectVisibility( wxPeer
->MacIsReallyShown() ) ;
2688 wxMacConvertNewlines10To13( &st
) ;
2689 wxMacWindowClipper
clipper( m_peer
) ;
2690 SetTXNData( st
, kTXNStartOffset
, kTXNEndOffset
) ;
2691 TXNSetSelection( m_txn
, 0, 0 ) ;
2695 wxMacMLTEClassicControl::~wxMacMLTEClassicControl()
2697 TXNDeleteObject( m_txn
);
2701 void wxMacMLTEClassicControl::VisibilityChanged(bool shown
)
2703 MacSetObjectVisibility( shown
) ;
2704 wxMacControl::VisibilityChanged( shown
) ;
2707 void wxMacMLTEClassicControl::SuperChangedPosition()
2709 MacUpdatePosition() ;
2710 wxMacControl::SuperChangedPosition() ;
2713 ControlUserPaneDrawUPP gTPDrawProc
= NULL
;
2714 ControlUserPaneHitTestUPP gTPHitProc
= NULL
;
2715 ControlUserPaneTrackingUPP gTPTrackProc
= NULL
;
2716 ControlUserPaneIdleUPP gTPIdleProc
= NULL
;
2717 ControlUserPaneKeyDownUPP gTPKeyProc
= NULL
;
2718 ControlUserPaneActivateUPP gTPActivateProc
= NULL
;
2719 ControlUserPaneFocusUPP gTPFocusProc
= NULL
;
2721 static pascal void wxMacControlUserPaneDrawProc(ControlRef control
, SInt16 part
)
2723 wxTextCtrl
*textCtrl
= wxDynamicCast( wxFindControlFromMacControl(control
) , wxTextCtrl
) ;
2724 wxMacMLTEClassicControl
* win
= textCtrl
? (wxMacMLTEClassicControl
*)(textCtrl
->GetPeer()) : NULL
;
2726 win
->MacControlUserPaneDrawProc( part
) ;
2729 static pascal ControlPartCode
wxMacControlUserPaneHitTestProc(ControlRef control
, Point where
)
2731 wxTextCtrl
*textCtrl
= wxDynamicCast( wxFindControlFromMacControl(control
) , wxTextCtrl
) ;
2732 wxMacMLTEClassicControl
* win
= textCtrl
? (wxMacMLTEClassicControl
*)(textCtrl
->GetPeer()) : NULL
;
2734 return win
->MacControlUserPaneHitTestProc( where
.h
, where
.v
) ;
2736 return kControlNoPart
;
2739 static pascal ControlPartCode
wxMacControlUserPaneTrackingProc(ControlRef control
, Point startPt
, ControlActionUPP actionProc
)
2741 wxTextCtrl
*textCtrl
= wxDynamicCast( wxFindControlFromMacControl(control
) , wxTextCtrl
) ;
2742 wxMacMLTEClassicControl
* win
= textCtrl
? (wxMacMLTEClassicControl
*)(textCtrl
->GetPeer()) : NULL
;
2744 return win
->MacControlUserPaneTrackingProc( startPt
.h
, startPt
.v
, (void*) actionProc
) ;
2746 return kControlNoPart
;
2749 static pascal void wxMacControlUserPaneIdleProc(ControlRef control
)
2751 wxTextCtrl
*textCtrl
= wxDynamicCast( wxFindControlFromMacControl(control
) , wxTextCtrl
) ;
2752 wxMacMLTEClassicControl
* win
= textCtrl
? (wxMacMLTEClassicControl
*)(textCtrl
->GetPeer()) : NULL
;
2754 win
->MacControlUserPaneIdleProc() ;
2757 static pascal ControlPartCode
wxMacControlUserPaneKeyDownProc(ControlRef control
, SInt16 keyCode
, SInt16 charCode
, SInt16 modifiers
)
2759 wxTextCtrl
*textCtrl
= wxDynamicCast( wxFindControlFromMacControl(control
) , wxTextCtrl
) ;
2760 wxMacMLTEClassicControl
* win
= textCtrl
? (wxMacMLTEClassicControl
*)(textCtrl
->GetPeer()) : NULL
;
2762 return win
->MacControlUserPaneKeyDownProc( keyCode
, charCode
, modifiers
) ;
2764 return kControlNoPart
;
2767 static pascal void wxMacControlUserPaneActivateProc(ControlRef control
, Boolean activating
)
2769 wxTextCtrl
*textCtrl
= wxDynamicCast( wxFindControlFromMacControl(control
) , wxTextCtrl
) ;
2770 wxMacMLTEClassicControl
* win
= textCtrl
? (wxMacMLTEClassicControl
*)(textCtrl
->GetPeer()) : NULL
;
2772 win
->MacControlUserPaneActivateProc( activating
) ;
2775 static pascal ControlPartCode
wxMacControlUserPaneFocusProc(ControlRef control
, ControlFocusPart action
)
2777 wxTextCtrl
*textCtrl
= wxDynamicCast( wxFindControlFromMacControl(control
) , wxTextCtrl
) ;
2778 wxMacMLTEClassicControl
* win
= textCtrl
? (wxMacMLTEClassicControl
*)(textCtrl
->GetPeer()) : NULL
;
2780 return win
->MacControlUserPaneFocusProc( action
) ;
2782 return kControlNoPart
;
2786 static pascal void wxMacControlUserPaneBackgroundProc(ControlRef control
, ControlBackgroundPtr info
)
2788 wxTextCtrl
*textCtrl
= wxDynamicCast( wxFindControlFromMacControl(control
) , wxTextCtrl
) ;
2789 wxMacMLTEClassicControl
* win
= textCtrl
? (wxMacMLTEClassicControl
*)(textCtrl
->GetPeer()) : NULL
;
2791 win
->MacControlUserPaneBackgroundProc(info
) ;
2795 // TXNRegisterScrollInfoProc
2797 OSStatus
wxMacMLTEClassicControl::DoCreate()
2800 OSStatus err
= noErr
;
2802 // set up our globals
2803 if (gTPDrawProc
== NULL
) gTPDrawProc
= NewControlUserPaneDrawUPP(wxMacControlUserPaneDrawProc
);
2804 if (gTPHitProc
== NULL
) gTPHitProc
= NewControlUserPaneHitTestUPP(wxMacControlUserPaneHitTestProc
);
2805 if (gTPTrackProc
== NULL
) gTPTrackProc
= NewControlUserPaneTrackingUPP(wxMacControlUserPaneTrackingProc
);
2806 if (gTPIdleProc
== NULL
) gTPIdleProc
= NewControlUserPaneIdleUPP(wxMacControlUserPaneIdleProc
);
2807 if (gTPKeyProc
== NULL
) gTPKeyProc
= NewControlUserPaneKeyDownUPP(wxMacControlUserPaneKeyDownProc
);
2808 if (gTPActivateProc
== NULL
) gTPActivateProc
= NewControlUserPaneActivateUPP(wxMacControlUserPaneActivateProc
);
2809 if (gTPFocusProc
== NULL
) gTPFocusProc
= NewControlUserPaneFocusUPP(wxMacControlUserPaneFocusProc
);
2811 if (gTXNScrollInfoProc
== NULL
) gTXNScrollInfoProc
= NewTXNScrollInfoUPP(TXNScrollInfoProc
) ;
2812 if (gTXNScrollActionProc
== NULL
) gTXNScrollActionProc
= NewControlActionUPP(TXNScrollActionProc
) ;
2814 // set the initial settings for our private data
2816 m_txnWindow
= GetControlOwner(m_controlRef
);
2817 m_txnPort
= (GrafPtr
) GetWindowPort(m_txnWindow
);
2819 // set up the user pane procedures
2820 SetControlData(m_controlRef
, kControlEntireControl
, kControlUserPaneDrawProcTag
, sizeof(gTPDrawProc
), &gTPDrawProc
);
2821 SetControlData(m_controlRef
, kControlEntireControl
, kControlUserPaneHitTestProcTag
, sizeof(gTPHitProc
), &gTPHitProc
);
2822 SetControlData(m_controlRef
, kControlEntireControl
, kControlUserPaneTrackingProcTag
, sizeof(gTPTrackProc
), &gTPTrackProc
);
2823 SetControlData(m_controlRef
, kControlEntireControl
, kControlUserPaneIdleProcTag
, sizeof(gTPIdleProc
), &gTPIdleProc
);
2824 SetControlData(m_controlRef
, kControlEntireControl
, kControlUserPaneKeyDownProcTag
, sizeof(gTPKeyProc
), &gTPKeyProc
);
2825 SetControlData(m_controlRef
, kControlEntireControl
, kControlUserPaneActivateProcTag
, sizeof(gTPActivateProc
), &gTPActivateProc
);
2826 SetControlData(m_controlRef
, kControlEntireControl
, kControlUserPaneFocusProcTag
, sizeof(gTPFocusProc
), &gTPFocusProc
);
2828 // calculate the rectangles used by the control
2829 UMAGetControlBoundsInWindowCoords( m_controlRef
, &bounds
);
2831 m_txnControlBounds
= bounds
;
2832 m_txnVisBounds
= bounds
;
2837 GetGWorld( &origPort
, &origDev
) ;
2838 SetPort( m_txnPort
);
2840 // create the new edit field
2841 TXNFrameOptions frameOptions
= FrameOptionsFromWXStyle( m_windowStyle
);
2843 // the scrollbars are not correctly embedded but are inserted at the root:
2844 // this gives us problems as we have erratic redraws even over the structure area
2846 m_sbHorizontal
= 0 ;
2848 m_lastHorizontalValue
= 0 ;
2849 m_lastVerticalValue
= 0 ;
2851 Rect sb
= { 0 , 0 , 0 , 0 } ;
2852 if ( frameOptions
& kTXNWantVScrollBarMask
)
2854 CreateScrollBarControl( m_txnWindow
, &sb
, 0, 0, 100, 1, true, gTXNScrollActionProc
, &m_sbVertical
);
2855 SetControlReference( m_sbVertical
, (SInt32
)this );
2856 SetControlAction( m_sbVertical
, gTXNScrollActionProc
);
2857 ShowControl( m_sbVertical
);
2858 EmbedControl( m_sbVertical
, m_controlRef
);
2859 frameOptions
&= ~kTXNWantVScrollBarMask
;
2862 if ( frameOptions
& kTXNWantHScrollBarMask
)
2864 CreateScrollBarControl( m_txnWindow
, &sb
, 0, 0, 100, 1, true, gTXNScrollActionProc
, &m_sbHorizontal
);
2865 SetControlReference( m_sbHorizontal
, (SInt32
)this );
2866 SetControlAction( m_sbHorizontal
, gTXNScrollActionProc
);
2867 ShowControl( m_sbHorizontal
);
2868 EmbedControl( m_sbHorizontal
, m_controlRef
);
2869 frameOptions
&= ~(kTXNWantHScrollBarMask
| kTXNDrawGrowIconMask
);
2873 NULL
, m_txnWindow
, &bounds
, frameOptions
,
2874 kTXNTextEditStyleFrameType
, kTXNTextensionFile
, kTXNSystemDefaultEncoding
,
2875 &m_txn
, &m_txnFrameID
, NULL
);
2876 verify_noerr( err
);
2879 TXNControlTag iControlTags
[] = { kTXNUseCarbonEvents
};
2880 TXNControlData iControlData
[] = { { (UInt32
)&cInfo
} };
2881 int toptag
= WXSIZEOF( iControlTags
) ;
2882 TXNCarbonEventInfo cInfo
;
2883 cInfo
.useCarbonEvents
= false ;
2886 cInfo
.fDictionary
= NULL
;
2888 verify_noerr( TXNSetTXNObjectControls( m_txn
, false, toptag
, iControlTags
, iControlData
) );
2891 TXNRegisterScrollInfoProc( m_txn
, gTXNScrollInfoProc
, (SInt32
)this );
2893 SetGWorld( origPort
, origDev
) ;
2899 // ----------------------------------------------------------------------------
2900 // MLTE control implementation (OSX part)
2901 // ----------------------------------------------------------------------------
2903 // tiger multi-line textcontrols with no CR in the entire content
2904 // don't scroll automatically, so we need a hack.
2905 // This attempt only works 'before' the key (ie before CallNextEventHandler)
2906 // is processed, thus the scrolling always occurs one character too late, but
2907 // better than nothing ...
2909 static const EventTypeSpec eventList
[] =
2911 { kEventClassTextInput
, kEventTextInputUnicodeForKeyEvent
} ,
2914 static pascal OSStatus
wxMacUnicodeTextEventHandler( EventHandlerCallRef handler
, EventRef event
, void *data
)
2916 OSStatus result
= eventNotHandledErr
;
2917 wxMacMLTEHIViewControl
* focus
= (wxMacMLTEHIViewControl
*) data
;
2919 switch ( GetEventKind( event
) )
2921 case kEventTextInputUnicodeForKeyEvent
:
2923 TXNOffset from
, to
;
2924 TXNGetSelection( focus
->GetTXNObject() , &from
, &to
) ;
2926 TXNShowSelection( focus
->GetTXNObject() , kTXNShowStart
);
2927 result
= CallNextEventHandler(handler
,event
);
2937 static pascal OSStatus
wxMacTextControlEventHandler( EventHandlerCallRef handler
, EventRef event
, void *data
)
2939 OSStatus result
= eventNotHandledErr
;
2941 switch ( GetEventClass( event
) )
2943 case kEventClassTextInput
:
2944 result
= wxMacUnicodeTextEventHandler( handler
, event
, data
) ;
2953 DEFINE_ONE_SHOT_HANDLER_GETTER( wxMacTextControlEventHandler
)
2955 wxMacMLTEHIViewControl::wxMacMLTEHIViewControl( wxTextCtrl
*wxPeer
,
2956 const wxString
& str
,
2958 const wxSize
& size
, long style
) : wxMacMLTEControl( wxPeer
)
2960 m_font
= wxPeer
->GetFont() ;
2961 m_windowStyle
= style
;
2962 Rect bounds
= wxMacGetBoundsForControl( wxPeer
, pos
, size
) ;
2964 wxMacConvertNewlines10To13( &st
) ;
2967 { bounds
.left
, bounds
.top
},
2968 { bounds
.right
- bounds
.left
, bounds
.bottom
- bounds
.top
} } ;
2970 m_scrollView
= NULL
;
2971 TXNFrameOptions frameOptions
= FrameOptionsFromWXStyle( style
) ;
2972 if (( frameOptions
& (kTXNWantVScrollBarMask
| kTXNWantHScrollBarMask
)) || !(frameOptions
&kTXNSingleLineOnlyMask
))
2974 if ( frameOptions
& (kTXNWantVScrollBarMask
| kTXNWantHScrollBarMask
) )
2977 (frameOptions
& kTXNWantHScrollBarMask
? kHIScrollViewOptionsHorizScroll
: 0)
2978 | (frameOptions
& kTXNWantVScrollBarMask
? kHIScrollViewOptionsVertScroll
: 0) ,
2983 HIScrollViewCreate(kHIScrollViewOptionsVertScroll
,&m_scrollView
);
2984 HIScrollViewSetScrollBarAutoHide(m_scrollView
,true);
2987 HIViewSetFrame( m_scrollView
, &hr
);
2988 HIViewSetVisible( m_scrollView
, true );
2992 HITextViewCreate( NULL
, 0, frameOptions
, &m_textView
) ;
2993 m_txn
= HITextViewGetTXNObject( m_textView
) ;
2994 HIViewSetVisible( m_textView
, true ) ;
2997 HIViewAddSubview( m_scrollView
, m_textView
) ;
2998 m_controlRef
= m_scrollView
;
2999 wxPeer
->MacInstallEventHandler( (WXWidget
) m_textView
) ;
3003 HIViewSetFrame( m_textView
, &hr
);
3004 m_controlRef
= m_textView
;
3007 AdjustCreationAttributes( *wxWHITE
, true ) ;
3009 wxMacWindowClipper
c( m_peer
) ;
3011 SetTXNData( st
, kTXNStartOffset
, kTXNEndOffset
) ;
3013 TXNSetSelection( m_txn
, 0, 0 );
3014 TXNShowSelection( m_txn
, kTXNShowStart
);
3016 InstallControlEventHandler( m_textView
, GetwxMacTextControlEventHandlerUPP(),
3017 GetEventTypeCount(eventList
), eventList
, this,
3021 wxMacMLTEHIViewControl::~wxMacMLTEHIViewControl()
3025 OSStatus
wxMacMLTEHIViewControl::SetFocus( ControlFocusPart focusPart
)
3027 return SetKeyboardFocus( GetControlOwner( m_textView
), m_textView
, focusPart
) ;
3030 bool wxMacMLTEHIViewControl::HasFocus() const
3032 ControlRef control
;
3033 if ( GetUserFocusWindow() == NULL
)
3036 GetKeyboardFocus( GetUserFocusWindow() , &control
) ;
3037 return control
== m_textView
;
3040 void wxMacMLTEHIViewControl::SetBackground( const wxBrush
&brush
)
3042 wxMacMLTEControl::SetBackground( brush
) ;
3045 CGColorSpaceRef rgbSpace
= CGColorSpaceCreateDeviceRGB();
3047 brush
.GetColour().GetRGBColor(&col
) ;
3049 float component
[4] ;
3050 component
[0] = col
.red
/ 65536.0 ;
3051 component
[1] = col
.green
/ 65536.0 ;
3052 component
[2] = col
.blue
/ 65536.0 ;
3053 component
[3] = 1.0 ; // alpha
3055 CGColorRef color
= CGColorCreate( rgbSpace
, component
);
3056 HITextViewSetBackgroundColor( m_textView
, color
);
3057 CGColorSpaceRelease( rgbSpace
);
3061 #endif // wxUSE_TEXTCTRL