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 #if defined(__BORLANDC__) && !defined(__WIN32__)
50 #elif !defined(__MWERKS__) && !defined(__GNUWIN32) && !defined(__DARWIN__)
59 #include <MacTextEditor.h>
60 #include <ATSUnicode.h>
61 #include <TextCommon.h>
62 #include <TextEncodingConverter.h>
65 #include "wx/mac/uma.h"
66 #include "wx/mac/carbon/private/mactext.h"
71 kTXNVisibilityTag
= 'visb' // set the visibility state of the object
80 virtual ~wxMacFunctor() {}
82 virtual void* operator()() = 0 ;
84 static void* CallBackProc( void *param
)
86 wxMacFunctor
* f
= (wxMacFunctor
*) param
;
87 void *result
= (*f
)() ;
92 template<typename classtype
, typename param1type
>
94 class wxMacObjectFunctor1
: public wxMacFunctor
96 typedef void (classtype::*function
)( param1type p1
) ;
97 typedef void (classtype::*ref_function
)( const param1type
& p1
) ;
99 wxMacObjectFunctor1( classtype
*obj
, function f
, param1type p1
) :
107 wxMacObjectFunctor1( classtype
*obj
, ref_function f
, param1type p1
) :
115 virtual ~wxMacObjectFunctor1() {}
117 virtual void* operator()()
119 (m_object
->*m_function
)( m_param1
) ;
124 classtype
* m_object
;
125 param1type m_param1
;
128 function m_function
;
129 ref_function m_refFunction
;
133 template<typename classtype
, typename param1type
>
134 void* wxMacMPRemoteCall( classtype
*object
, void (classtype::*function
)( param1type p1
) , param1type p1
)
136 wxMacObjectFunctor1
<classtype
, param1type
> params(object
, function
, p1
) ;
138 MPRemoteCall( wxMacFunctor::CallBackProc
, ¶ms
, kMPOwningProcessRemoteContext
) ;
142 template<typename classtype
, typename param1type
>
143 void* wxMacMPRemoteCall( classtype
*object
, void (classtype::*function
)( const param1type
& p1
) , param1type p1
)
145 wxMacObjectFunctor1
<classtype
,param1type
> params(object
, function
, p1
) ;
147 MPRemoteCall( wxMacFunctor::CallBackProc
, ¶ms
, kMPOwningProcessRemoteContext
) ;
151 template<typename classtype
, typename param1type
>
152 void* wxMacMPRemoteGUICall( classtype
*object
, void (classtype::*function
)( param1type p1
) , param1type p1
)
155 void *result
= wxMacMPRemoteCall( object
, function
, p1
) ;
160 template<typename classtype
, typename param1type
>
161 void* wxMacMPRemoteGUICall( classtype
*object
, void (classtype::*function
)( const param1type
& p1
) , param1type p1
)
164 void *result
= wxMacMPRemoteCall( object
, function
, p1
) ;
170 // common parts for implementations based on MLTE
172 class wxMacMLTEControl
: public wxMacTextControl
175 wxMacMLTEControl( wxTextCtrl
*peer
) ;
177 virtual wxString
GetStringValue() const ;
178 virtual void SetStringValue( const wxString
&str
) ;
180 static TXNFrameOptions
FrameOptionsFromWXStyle( long wxStyle
) ;
182 void AdjustCreationAttributes( const wxColour
& background
, bool visible
) ;
184 virtual void SetFont( const wxFont
& font
, const wxColour
& foreground
, long windowStyle
) ;
185 virtual void SetBackground( const wxBrush
&brush
) ;
186 virtual void SetStyle( long start
, long end
, const wxTextAttr
& style
) ;
187 virtual void Copy() ;
189 virtual void Paste() ;
190 virtual bool CanPaste() const ;
191 virtual void SetEditable( bool editable
) ;
192 virtual wxTextPos
GetLastPosition() const ;
193 virtual void Replace( long from
, long to
, const wxString
&str
) ;
194 virtual void Remove( long from
, long to
) ;
195 virtual void GetSelection( long* from
, long* to
) const ;
196 virtual void SetSelection( long from
, long to
) ;
198 virtual void WriteText( const wxString
& str
) ;
200 virtual bool HasOwnContextMenu() const
202 #if MAC_OS_X_VERSION_MAX_ALLOWED >= MAC_OS_X_VERSION_10_4
203 if ( UMAGetSystemVersion() >= 0x1040 )
205 TXNCommandEventSupportOptions options
;
206 TXNGetCommandEventSupport( m_txn
, & options
) ;
207 return options
& kTXNSupportEditCommandProcessing
;
214 virtual void CheckSpelling(bool check
)
216 #if MAC_OS_X_VERSION_MAX_ALLOWED >= MAC_OS_X_VERSION_10_4
217 TXNSetSpellCheckAsYouType( m_txn
, (Boolean
) check
);
220 virtual void Clear() ;
222 virtual bool CanUndo() const ;
223 virtual void Undo() ;
224 virtual bool CanRedo() const;
225 virtual void Redo() ;
226 virtual int GetNumberOfLines() const ;
227 virtual long XYToPosition(long x
, long y
) const ;
228 virtual bool PositionToXY(long pos
, long *x
, long *y
) const ;
229 virtual void ShowPosition( long pos
) ;
230 virtual int GetLineLength(long lineNo
) const ;
231 virtual wxString
GetLineText(long lineNo
) const ;
233 void SetTXNData( const wxString
& st
, TXNOffset start
, TXNOffset end
) ;
234 TXNObject
GetTXNObject() { return m_txn
; }
237 void TXNSetAttribute( const wxTextAttr
& style
, long from
, long to
) ;
242 #if TARGET_API_MAC_OSX
244 // implementation available under OSX
246 #if MAC_OS_X_VERSION_MAX_ALLOWED > MAC_OS_X_VERSION_10_2
248 class wxMacMLTEHIViewControl
: public wxMacMLTEControl
251 wxMacMLTEHIViewControl( wxTextCtrl
*wxPeer
,
254 const wxSize
& size
, long style
) ;
255 virtual ~wxMacMLTEHIViewControl() ;
257 virtual OSStatus
SetFocus( ControlFocusPart focusPart
) ;
258 virtual bool HasFocus() const ;
259 virtual void SetBackground( const wxBrush
&brush
) ;
262 HIViewRef m_scrollView
;
263 HIViewRef m_textView
;
264 EventHandlerRef m_textEventHandlerRef
;
271 // 'classic' MLTE implementation
273 class wxMacMLTEClassicControl
: public wxMacMLTEControl
276 wxMacMLTEClassicControl( wxTextCtrl
*wxPeer
,
279 const wxSize
& size
, long style
) ;
280 virtual ~wxMacMLTEClassicControl() ;
282 virtual void VisibilityChanged(bool shown
) ;
283 virtual void SuperChangedPosition() ;
285 virtual void MacControlUserPaneDrawProc(wxInt16 part
) ;
286 virtual wxInt16
MacControlUserPaneHitTestProc(wxInt16 x
, wxInt16 y
) ;
287 virtual wxInt16
MacControlUserPaneTrackingProc(wxInt16 x
, wxInt16 y
, void* actionProc
) ;
288 virtual void MacControlUserPaneIdleProc() ;
289 virtual wxInt16
MacControlUserPaneKeyDownProc(wxInt16 keyCode
, wxInt16 charCode
, wxInt16 modifiers
) ;
290 virtual void MacControlUserPaneActivateProc(bool activating
) ;
291 virtual wxInt16
MacControlUserPaneFocusProc(wxInt16 action
) ;
292 virtual void MacControlUserPaneBackgroundProc(void* info
) ;
294 virtual bool SetupCursor( const wxPoint
& WXUNUSED(pt
) )
296 MacControlUserPaneIdleProc();
300 virtual void SetRect( Rect
*r
) ;
305 void MacUpdatePosition() ;
306 void MacActivatePaneText(bool setActive
) ;
307 void MacFocusPaneText(bool setFocus
) ;
308 void MacSetObjectVisibility(bool vis
) ;
311 TXNFrameID m_txnFrameID
;
313 WindowRef m_txnWindow
;
314 // bounds of the control as we last did set the txn frames
315 Rect m_txnControlBounds
;
316 Rect m_txnVisBounds
;
319 static pascal void TXNScrollActionProc( ControlRef controlRef
, ControlPartCode partCode
) ;
320 static pascal void TXNScrollInfoProc(
321 SInt32 iValue
, SInt32 iMaximumValue
,
322 TXNScrollBarOrientation iScrollBarOrientation
, SInt32 iRefCon
) ;
324 ControlRef m_sbHorizontal
;
325 SInt32 m_lastHorizontalValue
;
326 ControlRef m_sbVertical
;
327 SInt32 m_lastVerticalValue
;
332 IMPLEMENT_DYNAMIC_CLASS(wxTextCtrl
, wxTextCtrlBase
)
334 BEGIN_EVENT_TABLE(wxTextCtrl
, wxTextCtrlBase
)
335 EVT_ERASE_BACKGROUND( wxTextCtrl::OnEraseBackground
)
336 EVT_DROP_FILES(wxTextCtrl::OnDropFiles
)
337 EVT_CHAR(wxTextCtrl::OnChar
)
338 EVT_MENU(wxID_CUT
, wxTextCtrl::OnCut
)
339 EVT_MENU(wxID_COPY
, wxTextCtrl::OnCopy
)
340 EVT_MENU(wxID_PASTE
, wxTextCtrl::OnPaste
)
341 EVT_MENU(wxID_UNDO
, wxTextCtrl::OnUndo
)
342 EVT_MENU(wxID_REDO
, wxTextCtrl::OnRedo
)
343 EVT_MENU(wxID_CLEAR
, wxTextCtrl::OnDelete
)
344 EVT_MENU(wxID_SELECTALL
, wxTextCtrl::OnSelectAll
)
346 EVT_CONTEXT_MENU(wxTextCtrl::OnContextMenu
)
348 EVT_UPDATE_UI(wxID_CUT
, wxTextCtrl::OnUpdateCut
)
349 EVT_UPDATE_UI(wxID_COPY
, wxTextCtrl::OnUpdateCopy
)
350 EVT_UPDATE_UI(wxID_PASTE
, wxTextCtrl::OnUpdatePaste
)
351 EVT_UPDATE_UI(wxID_UNDO
, wxTextCtrl::OnUpdateUndo
)
352 EVT_UPDATE_UI(wxID_REDO
, wxTextCtrl::OnUpdateRedo
)
353 EVT_UPDATE_UI(wxID_CLEAR
, wxTextCtrl::OnUpdateDelete
)
354 EVT_UPDATE_UI(wxID_SELECTALL
, wxTextCtrl::OnUpdateSelectAll
)
358 void wxTextCtrl::Init()
364 m_privateContextMenu
= NULL
;
365 m_triggerOnSetValue
= true ;
368 wxTextCtrl::~wxTextCtrl()
370 delete m_privateContextMenu
;
373 bool wxTextCtrl::Create( wxWindow
*parent
,
379 const wxValidator
& validator
,
380 const wxString
& name
)
382 m_macIsUserPane
= false ;
385 if ( ! (style
& wxNO_BORDER
) )
386 style
= (style
& ~wxBORDER_MASK
) | wxSUNKEN_BORDER
;
388 if ( !wxTextCtrlBase::Create( parent
, id
, pos
, size
, style
& ~(wxHSCROLL
| wxVSCROLL
), validator
, name
) )
391 if ( m_windowStyle
& wxTE_MULTILINE
)
393 // always turn on this style for multi-line controls
394 m_windowStyle
|= wxTE_PROCESS_ENTER
;
395 style
|= wxTE_PROCESS_ENTER
;
398 CreatePeer( str
, pos
, size
, style
);
400 MacPostControlCreate(pos
, size
) ;
402 // only now the embedding is correct and we can do a positioning update
404 MacSuperChangedPosition() ;
406 if ( m_windowStyle
& wxTE_READONLY
)
407 SetEditable( false ) ;
409 SetCursor( wxCursor( wxCURSOR_IBEAM
) ) ;
414 void wxTextCtrl::CreatePeer(
417 const wxSize
& size
, long style
)
419 bool forceMLTE
= false ;
421 #if wxUSE_SYSTEM_OPTIONS
422 if (wxSystemOptions::HasOption( wxMAC_TEXTCONTROL_USE_MLTE
) && (wxSystemOptions::GetOptionInt( wxMAC_TEXTCONTROL_USE_MLTE
) == 1))
427 #if MAC_OS_X_VERSION_MAX_ALLOWED >= MAC_OS_X_VERSION_10_5
432 #if MAC_OS_X_VERSION_MAX_ALLOWED > MAC_OS_X_VERSION_10_2
433 if ( UMAGetSystemVersion() >= 0x1030 && !forceMLTE
)
435 if ( m_windowStyle
& wxTE_MULTILINE
)
436 m_peer
= new wxMacMLTEHIViewControl( this , str
, pos
, size
, style
) ;
442 #if MAC_OS_X_VERSION_MAX_ALLOWED < MAC_OS_X_VERSION_10_5
443 if ( !(m_windowStyle
& wxTE_MULTILINE
) && !forceMLTE
)
446 m_peer
= new wxMacUnicodeTextControl( this , str
, pos
, size
, style
) ;
451 // the horizontal single line scrolling bug that made us keep
452 #if MAC_OS_X_VERSION_MAX_ALLOWED < MAC_OS_X_VERSION_10_5
454 m_peer
= new wxMacMLTEClassicControl( this , str
, pos
, size
, style
) ;
458 void wxTextCtrl::MacSuperChangedPosition()
460 wxWindow::MacSuperChangedPosition() ;
461 GetPeer()->SuperChangedPosition() ;
464 void wxTextCtrl::MacVisibilityChanged()
466 GetPeer()->VisibilityChanged( MacIsReallyShown() ) ;
469 void wxTextCtrl::MacEnabledStateChanged()
473 void wxTextCtrl::MacCheckSpelling(bool check
)
475 GetPeer()->CheckSpelling(check
);
478 wxString
wxTextCtrl::GetValue() const
480 return GetPeer()->GetStringValue() ;
483 void wxTextCtrl::GetSelection(long* from
, long* to
) const
485 GetPeer()->GetSelection( from
, to
) ;
488 void wxTextCtrl::DoSetValue(const wxString
& str
, int flags
)
491 if ( GetValue() == str
)
494 GetPeer()->SetStringValue( str
) ;
496 if ( (flags
& SetValue_SendEvent
) && m_triggerOnSetValue
)
498 SendTextUpdatedEvent();
502 void wxTextCtrl::SetMaxLength(unsigned long len
)
507 bool wxTextCtrl::SetFont( const wxFont
& font
)
509 if ( !wxTextCtrlBase::SetFont( font
) )
512 GetPeer()->SetFont( font
, GetForegroundColour() , GetWindowStyle() ) ;
517 bool wxTextCtrl::SetStyle(long start
, long end
, const wxTextAttr
& style
)
519 GetPeer()->SetStyle( start
, end
, style
) ;
524 bool wxTextCtrl::SetDefaultStyle(const wxTextAttr
& style
)
526 wxTextCtrlBase::SetDefaultStyle( style
) ;
527 SetStyle( kTXNUseCurrentSelection
, kTXNUseCurrentSelection
, GetDefaultStyle() ) ;
532 // Clipboard operations
534 void wxTextCtrl::Copy()
540 void wxTextCtrl::Cut()
546 wxCommandEvent
event( wxEVT_COMMAND_TEXT_UPDATED
, m_windowId
);
547 event
.SetEventObject( this );
548 GetEventHandler()->ProcessEvent( event
);
552 void wxTextCtrl::Paste()
558 // TODO: eventually we should add setting the default style again
560 wxCommandEvent
event( wxEVT_COMMAND_TEXT_UPDATED
, m_windowId
);
561 event
.SetEventObject( this );
562 GetEventHandler()->ProcessEvent( event
);
566 bool wxTextCtrl::CanCopy() const
568 // Can copy if there's a selection
570 GetSelection( &from
, &to
);
575 bool wxTextCtrl::CanCut() const
580 // Can cut if there's a selection
582 GetSelection( &from
, &to
);
587 bool wxTextCtrl::CanPaste() const
592 return GetPeer()->CanPaste() ;
595 void wxTextCtrl::SetEditable(bool editable
)
597 if ( editable
!= m_editable
)
599 m_editable
= editable
;
600 GetPeer()->SetEditable( editable
) ;
604 void wxTextCtrl::SetInsertionPoint(long pos
)
606 SetSelection( pos
, pos
) ;
609 void wxTextCtrl::SetInsertionPointEnd()
611 wxTextPos pos
= GetLastPosition();
612 SetInsertionPoint( pos
);
615 long wxTextCtrl::GetInsertionPoint() const
618 GetSelection( &begin
, &end
) ;
623 wxTextPos
wxTextCtrl::GetLastPosition() const
625 return GetPeer()->GetLastPosition() ;
628 void wxTextCtrl::Replace(long from
, long to
, const wxString
& str
)
630 GetPeer()->Replace( from
, to
, str
) ;
633 void wxTextCtrl::Remove(long from
, long to
)
635 GetPeer()->Remove( from
, to
) ;
638 void wxTextCtrl::SetSelection(long from
, long to
)
640 GetPeer()->SetSelection( from
, to
) ;
643 void wxTextCtrl::WriteText(const wxString
& str
)
645 // TODO: this MPRemoting will be moved into a remoting peer proxy for any command
646 if ( !wxIsMainThread() )
648 // unfortunately CW 8 is not able to correctly deduce the template types,
649 // so we have to instantiate explicitly
650 wxMacMPRemoteGUICall
<wxTextCtrl
,wxString
>( this , &wxTextCtrl::WriteText
, str
) ;
655 GetPeer()->WriteText( str
) ;
658 void wxTextCtrl::AppendText(const wxString
& text
)
660 SetInsertionPointEnd();
664 void wxTextCtrl::Clear()
669 bool wxTextCtrl::IsModified() const
674 bool wxTextCtrl::IsEditable() const
676 return IsEnabled() && m_editable
;
679 bool wxTextCtrl::AcceptsFocus() const
681 // we don't want focus if we can't be edited
682 return /*IsEditable() && */ wxControl::AcceptsFocus();
685 wxSize
wxTextCtrl::DoGetBestSize() const
689 // these are the numbers from the HIG:
690 // we reduce them by the borders first
693 switch ( m_windowVariant
)
695 case wxWINDOW_VARIANT_NORMAL
:
699 case wxWINDOW_VARIANT_SMALL
:
703 case wxWINDOW_VARIANT_MINI
:
712 // as the above numbers have some free space around the text
713 // we get 5 lines like this anyway
714 if ( m_windowStyle
& wxTE_MULTILINE
)
717 if ( !HasFlag(wxNO_BORDER
) )
720 return wxSize(wText
, hText
);
723 // ----------------------------------------------------------------------------
725 // ----------------------------------------------------------------------------
727 void wxTextCtrl::Undo()
733 void wxTextCtrl::Redo()
739 bool wxTextCtrl::CanUndo() const
744 return GetPeer()->CanUndo() ;
747 bool wxTextCtrl::CanRedo() const
752 return GetPeer()->CanRedo() ;
755 void wxTextCtrl::MarkDirty()
760 void wxTextCtrl::DiscardEdits()
765 int wxTextCtrl::GetNumberOfLines() const
767 return GetPeer()->GetNumberOfLines() ;
770 long wxTextCtrl::XYToPosition(long x
, long y
) const
772 return GetPeer()->XYToPosition( x
, y
) ;
775 bool wxTextCtrl::PositionToXY(long pos
, long *x
, long *y
) const
777 return GetPeer()->PositionToXY( pos
, x
, y
) ;
780 void wxTextCtrl::ShowPosition(long pos
)
782 return GetPeer()->ShowPosition(pos
) ;
785 int wxTextCtrl::GetLineLength(long lineNo
) const
787 return GetPeer()->GetLineLength(lineNo
) ;
790 wxString
wxTextCtrl::GetLineText(long lineNo
) const
792 return GetPeer()->GetLineText(lineNo
) ;
795 void wxTextCtrl::Command(wxCommandEvent
& event
)
797 SetValue(event
.GetString());
798 ProcessCommand(event
);
801 void wxTextCtrl::OnDropFiles(wxDropFilesEvent
& event
)
803 // By default, load the first file into the text window.
804 if (event
.GetNumberOfFiles() > 0)
805 LoadFile( event
.GetFiles()[0] );
808 void wxTextCtrl::OnEraseBackground(wxEraseEvent
& event
)
810 // all erasing should be done by the real mac control implementation
811 // while this is true for MLTE under classic, the HITextView is somehow
812 // transparent but background erase is not working correctly, so intercept
813 // things while we can...
817 void wxTextCtrl::OnChar(wxKeyEvent
& event
)
819 int key
= event
.GetKeyCode() ;
820 bool eat_key
= false ;
822 if ( key
== 'a' && event
.MetaDown() )
829 if ( key
== 'c' && event
.MetaDown() )
837 if ( !IsEditable() && key
!= WXK_LEFT
&& key
!= WXK_RIGHT
&& key
!= WXK_DOWN
&& key
!= WXK_UP
&& key
!= WXK_TAB
&&
838 !( key
== WXK_RETURN
&& ( (m_windowStyle
& wxTE_PROCESS_ENTER
) || (m_windowStyle
& wxTE_MULTILINE
) ) )
839 // && key != WXK_PAGEUP && key != WXK_PAGEDOWN && key != WXK_HOME && key != WXK_END
846 // Check if we have reached the max # of chars (if it is set), but still
847 // allow navigation and deletion
848 if ( !IsMultiLine() && m_maxLength
&& GetValue().length() >= m_maxLength
&&
849 key
!= WXK_LEFT
&& key
!= WXK_RIGHT
&& key
!= WXK_TAB
&&
850 key
!= WXK_BACK
&& !( key
== WXK_RETURN
&& (m_windowStyle
& wxTE_PROCESS_ENTER
) )
853 // eat it, we don't want to add more than allowed # of characters
855 // TODO: generate EVT_TEXT_MAXLEN()
859 // assume that any key not processed yet is going to modify the control
862 if ( key
== 'v' && event
.MetaDown() )
870 if ( key
== 'x' && event
.MetaDown() )
881 if (m_windowStyle
& wxTE_PROCESS_ENTER
)
883 wxCommandEvent
event(wxEVT_COMMAND_TEXT_ENTER
, m_windowId
);
884 event
.SetEventObject( this );
885 event
.SetString( GetValue() );
886 if ( GetEventHandler()->ProcessEvent(event
) )
890 if ( !(m_windowStyle
& wxTE_MULTILINE
) )
892 wxTopLevelWindow
*tlw
= wxDynamicCast(wxGetTopLevelParent(this), wxTopLevelWindow
);
893 if ( tlw
&& tlw
->GetDefaultItem() )
895 wxButton
*def
= wxDynamicCast(tlw
->GetDefaultItem(), wxButton
);
896 if ( def
&& def
->IsEnabled() )
898 wxCommandEvent
event(wxEVT_COMMAND_BUTTON_CLICKED
, def
->GetId() );
899 event
.SetEventObject(def
);
906 // this will make wxWidgets eat the ENTER key so that
907 // we actually prevent line wrapping in a single line text control
913 if ( !(m_windowStyle
& wxTE_PROCESS_TAB
))
916 if (!event
.ShiftDown())
917 flags
|= wxNavigationKeyEvent::IsForward
;
918 if (event
.ControlDown())
919 flags
|= wxNavigationKeyEvent::WinChange
;
926 // This is necessary (don't know why);
927 // otherwise the tab will not be inserted.
928 WriteText(wxT("\t"));
939 // perform keystroke handling
943 if ( ( key
>= 0x20 && key
< WXK_START
) ||
944 ( key
>= WXK_NUMPAD0
&& key
<= WXK_DIVIDE
) ||
949 wxCommandEvent
event1(wxEVT_COMMAND_TEXT_UPDATED
, m_windowId
);
950 event1
.SetEventObject( this );
951 wxPostEvent( GetEventHandler(), event1
);
955 // ----------------------------------------------------------------------------
956 // standard handlers for standard edit menu events
957 // ----------------------------------------------------------------------------
959 void wxTextCtrl::OnCut(wxCommandEvent
& WXUNUSED(event
))
964 void wxTextCtrl::OnCopy(wxCommandEvent
& WXUNUSED(event
))
969 void wxTextCtrl::OnPaste(wxCommandEvent
& WXUNUSED(event
))
974 void wxTextCtrl::OnUndo(wxCommandEvent
& WXUNUSED(event
))
979 void wxTextCtrl::OnRedo(wxCommandEvent
& WXUNUSED(event
))
984 void wxTextCtrl::OnDelete(wxCommandEvent
& WXUNUSED(event
))
988 GetSelection( &from
, &to
);
989 if (from
!= -1 && to
!= -1)
993 void wxTextCtrl::OnSelectAll(wxCommandEvent
& WXUNUSED(event
))
995 SetSelection(-1, -1);
998 void wxTextCtrl::OnUpdateCut(wxUpdateUIEvent
& event
)
1000 event
.Enable( CanCut() );
1003 void wxTextCtrl::OnUpdateCopy(wxUpdateUIEvent
& event
)
1005 event
.Enable( CanCopy() );
1008 void wxTextCtrl::OnUpdatePaste(wxUpdateUIEvent
& event
)
1010 event
.Enable( CanPaste() );
1013 void wxTextCtrl::OnUpdateUndo(wxUpdateUIEvent
& event
)
1015 event
.Enable( CanUndo() );
1018 void wxTextCtrl::OnUpdateRedo(wxUpdateUIEvent
& event
)
1020 event
.Enable( CanRedo() );
1023 void wxTextCtrl::OnUpdateDelete(wxUpdateUIEvent
& event
)
1027 GetSelection( &from
, &to
);
1028 event
.Enable( from
!= -1 && to
!= -1 && from
!= to
&& IsEditable() ) ;
1031 void wxTextCtrl::OnUpdateSelectAll(wxUpdateUIEvent
& event
)
1033 event
.Enable(GetLastPosition() > 0);
1036 // CS: Context Menus only work with MLTE implementations or non-multiline HIViews at the moment
1038 void wxTextCtrl::OnContextMenu(wxContextMenuEvent
& event
)
1040 if ( GetPeer()->HasOwnContextMenu() )
1046 if (m_privateContextMenu
== NULL
)
1048 m_privateContextMenu
= new wxMenu
;
1049 m_privateContextMenu
->Append(wxID_UNDO
, _("&Undo"));
1050 m_privateContextMenu
->Append(wxID_REDO
, _("&Redo"));
1051 m_privateContextMenu
->AppendSeparator();
1052 m_privateContextMenu
->Append(wxID_CUT
, _("Cu&t"));
1053 m_privateContextMenu
->Append(wxID_COPY
, _("&Copy"));
1054 m_privateContextMenu
->Append(wxID_PASTE
, _("&Paste"));
1055 m_privateContextMenu
->Append(wxID_CLEAR
, _("&Delete"));
1056 m_privateContextMenu
->AppendSeparator();
1057 m_privateContextMenu
->Append(wxID_SELECTALL
, _("Select &All"));
1060 if (m_privateContextMenu
!= NULL
)
1061 PopupMenu(m_privateContextMenu
);
1064 bool wxTextCtrl::MacSetupCursor( const wxPoint
& pt
)
1066 if ( !GetPeer()->SetupCursor( pt
) )
1067 return wxWindow::MacSetupCursor( pt
) ;
1072 #if !TARGET_API_MAC_OSX
1074 // user pane implementation
1076 void wxTextCtrl::MacControlUserPaneDrawProc(wxInt16 part
)
1078 GetPeer()->MacControlUserPaneDrawProc( part
) ;
1081 wxInt16
wxTextCtrl::MacControlUserPaneHitTestProc(wxInt16 x
, wxInt16 y
)
1083 return GetPeer()->MacControlUserPaneHitTestProc( x
, y
) ;
1086 wxInt16
wxTextCtrl::MacControlUserPaneTrackingProc(wxInt16 x
, wxInt16 y
, void* actionProc
)
1088 return GetPeer()->MacControlUserPaneTrackingProc( x
, y
, actionProc
) ;
1091 void wxTextCtrl::MacControlUserPaneIdleProc()
1093 GetPeer()->MacControlUserPaneIdleProc( ) ;
1096 wxInt16
wxTextCtrl::MacControlUserPaneKeyDownProc(wxInt16 keyCode
, wxInt16 charCode
, wxInt16 modifiers
)
1098 return GetPeer()->MacControlUserPaneKeyDownProc( keyCode
, charCode
, modifiers
) ;
1101 void wxTextCtrl::MacControlUserPaneActivateProc(bool activating
)
1103 GetPeer()->MacControlUserPaneActivateProc( activating
) ;
1106 wxInt16
wxTextCtrl::MacControlUserPaneFocusProc(wxInt16 action
)
1108 return GetPeer()->MacControlUserPaneFocusProc( action
) ;
1111 void wxTextCtrl::MacControlUserPaneBackgroundProc(void* info
)
1113 GetPeer()->MacControlUserPaneBackgroundProc( info
) ;
1118 // ----------------------------------------------------------------------------
1119 // implementation base class
1120 // ----------------------------------------------------------------------------
1122 wxMacTextControl::wxMacTextControl(wxTextCtrl
* peer
) :
1123 wxMacControl( peer
)
1127 wxMacTextControl::~wxMacTextControl()
1131 void wxMacTextControl::SetStyle(long WXUNUSED(start
),
1133 const wxTextAttr
& WXUNUSED(style
))
1137 void wxMacTextControl::Copy()
1141 void wxMacTextControl::Cut()
1145 void wxMacTextControl::Paste()
1149 bool wxMacTextControl::CanPaste() const
1154 void wxMacTextControl::SetEditable(bool WXUNUSED(editable
))
1158 wxTextPos
wxMacTextControl::GetLastPosition() const
1160 return GetStringValue().length() ;
1163 void wxMacTextControl::Replace( long from
, long to
, const wxString
&val
)
1165 SetSelection( from
, to
) ;
1169 void wxMacTextControl::Remove( long from
, long to
)
1171 SetSelection( from
, to
) ;
1172 WriteText( wxEmptyString
) ;
1175 void wxMacTextControl::Clear()
1177 SetStringValue( wxEmptyString
) ;
1180 bool wxMacTextControl::CanUndo() const
1185 void wxMacTextControl::Undo()
1189 bool wxMacTextControl::CanRedo() const
1194 void wxMacTextControl::Redo()
1198 long wxMacTextControl::XYToPosition(long WXUNUSED(x
), long WXUNUSED(y
)) const
1203 bool wxMacTextControl::PositionToXY(long WXUNUSED(pos
),
1205 long *WXUNUSED(y
)) const
1210 void wxMacTextControl::ShowPosition( long WXUNUSED(pos
) )
1214 int wxMacTextControl::GetNumberOfLines() const
1216 ItemCount lines
= 0 ;
1217 wxString content
= GetStringValue() ;
1220 for (size_t i
= 0; i
< content
.length() ; i
++)
1222 if (content
[i
] == '\r')
1229 wxString
wxMacTextControl::GetLineText(long lineNo
) const
1231 // TODO: change this if possible to reflect real lines
1232 wxString content
= GetStringValue() ;
1236 for (size_t i
= 0; i
< content
.length() ; i
++)
1238 if (count
== lineNo
)
1240 // Add chars in line then
1243 for (size_t j
= i
; j
< content
.length(); j
++)
1245 if (content
[j
] == '\n')
1254 if (content
[i
] == '\n')
1258 return wxEmptyString
;
1261 int wxMacTextControl::GetLineLength(long lineNo
) const
1263 // TODO: change this if possible to reflect real lines
1264 wxString content
= GetStringValue() ;
1268 for (size_t i
= 0; i
< content
.length() ; i
++)
1270 if (count
== lineNo
)
1272 // Count chars in line then
1274 for (size_t j
= i
; j
< content
.length(); j
++)
1277 if (content
[j
] == '\n')
1284 if (content
[i
] == '\n')
1291 // ----------------------------------------------------------------------------
1292 // standard unicode control implementation
1293 // ----------------------------------------------------------------------------
1295 #if TARGET_API_MAC_OSX
1297 // the current unicode textcontrol implementation has a bug : only if the control
1298 // is currently having the focus, the selection can be retrieved by the corresponding
1299 // data tag. So we have a mirroring using a member variable
1300 // TODO : build event table using virtual member functions for wxMacControl
1302 static const EventTypeSpec unicodeTextControlEventList
[] =
1304 { kEventClassControl
, kEventControlSetFocusPart
} ,
1307 static pascal OSStatus
wxMacUnicodeTextControlControlEventHandler( EventHandlerCallRef handler
, EventRef event
, void *data
)
1309 OSStatus result
= eventNotHandledErr
;
1310 wxMacUnicodeTextControl
* focus
= (wxMacUnicodeTextControl
*) data
;
1311 wxMacCarbonEvent
cEvent( event
) ;
1313 switch ( GetEventKind( event
) )
1315 case kEventControlSetFocusPart
:
1317 ControlPartCode controlPart
= cEvent
.GetParameter
<ControlPartCode
>(kEventParamControlPart
, typeControlPartCode
);
1318 if ( controlPart
== kControlFocusNoPart
)
1320 // about to loose focus -> store selection to field
1321 focus
->GetData
<ControlEditTextSelectionRec
>( 0, kControlEditTextSelectionTag
, &focus
->m_selection
);
1323 result
= CallNextEventHandler(handler
,event
) ;
1324 if ( controlPart
!= kControlFocusNoPart
)
1326 // about to gain focus -> set selection from field
1327 focus
->SetData
<ControlEditTextSelectionRec
>( 0, kControlEditTextSelectionTag
, &focus
->m_selection
);
1338 static pascal OSStatus
wxMacUnicodeTextControlEventHandler( EventHandlerCallRef handler
, EventRef event
, void *data
)
1340 OSStatus result
= eventNotHandledErr
;
1342 switch ( GetEventClass( event
) )
1344 case kEventClassControl
:
1345 result
= wxMacUnicodeTextControlControlEventHandler( handler
, event
, data
) ;
1354 DEFINE_ONE_SHOT_HANDLER_GETTER( wxMacUnicodeTextControlEventHandler
)
1356 wxMacUnicodeTextControl::wxMacUnicodeTextControl( wxTextCtrl
*wxPeer
) : wxMacTextControl( wxPeer
)
1360 wxMacUnicodeTextControl::wxMacUnicodeTextControl( wxTextCtrl
*wxPeer
,
1361 const wxString
& str
,
1363 const wxSize
& size
, long style
)
1364 : wxMacTextControl( wxPeer
)
1366 Create( wxPeer
, str
, pos
, size
, style
);
1369 bool wxMacUnicodeTextControl::Create( wxTextCtrl
*wxPeer
,
1370 const wxString
& str
,
1372 const wxSize
& size
, long style
)
1374 m_font
= wxPeer
->GetFont() ;
1375 m_windowStyle
= style
;
1376 Rect bounds
= wxMacGetBoundsForControl( wxPeer
, pos
, size
) ;
1378 wxMacConvertNewlines10To13( &st
) ;
1379 wxMacCFStringHolder
cf(st
, m_font
.GetEncoding()) ;
1380 CFStringRef cfr
= cf
;
1382 m_valueTag
= kControlEditTextCFStringTag
;
1383 CreateControl( wxPeer
, &bounds
, cfr
);
1385 if ( !(m_windowStyle
& wxTE_MULTILINE
) )
1386 SetData
<Boolean
>( kControlEditTextPart
, kControlEditTextSingleLineTag
, true ) ;
1388 InstallControlEventHandler( m_controlRef
, GetwxMacUnicodeTextControlEventHandlerUPP(),
1389 GetEventTypeCount(unicodeTextControlEventList
), unicodeTextControlEventList
, this,
1390 &m_focusHandlerRef
);
1395 wxMacUnicodeTextControl::~wxMacUnicodeTextControl()
1397 ::RemoveEventHandler( m_focusHandlerRef
);
1400 void wxMacUnicodeTextControl::VisibilityChanged(bool shown
)
1402 if ( !(m_windowStyle
& wxTE_MULTILINE
) && shown
)
1404 // work around a refresh issue insofar as not always the entire content is shown,
1405 // even if this would be possible
1406 ControlEditTextSelectionRec sel
;
1407 CFStringRef value
= NULL
;
1409 verify_noerr( GetData
<ControlEditTextSelectionRec
>( 0, kControlEditTextSelectionTag
, &sel
) );
1410 verify_noerr( GetData
<CFStringRef
>( 0, m_valueTag
, &value
) );
1411 verify_noerr( SetData
<CFStringRef
>( 0, m_valueTag
, &value
) );
1412 verify_noerr( SetData
<ControlEditTextSelectionRec
>( 0, kControlEditTextSelectionTag
, &sel
) );
1414 CFRelease( value
) ;
1418 wxString
wxMacUnicodeTextControl::GetStringValue() const
1421 CFStringRef value
= GetData
<CFStringRef
>(0, m_valueTag
) ;
1424 wxMacCFStringHolder
cf(value
) ;
1425 result
= cf
.AsString() ;
1429 wxMacConvertNewlines13To10( &result
) ;
1431 wxMacConvertNewlines10To13( &result
) ;
1437 void wxMacUnicodeTextControl::SetStringValue( const wxString
&str
)
1440 wxMacConvertNewlines10To13( &st
) ;
1441 wxMacCFStringHolder
cf( st
, m_font
.GetEncoding() ) ;
1442 verify_noerr( SetData
<CFStringRef
>( 0, m_valueTag
, cf
) ) ;
1445 void wxMacUnicodeTextControl::CreateControl( wxTextCtrl
* peer
, const Rect
* bounds
, CFStringRef cfr
)
1447 Boolean isPassword
= ( m_windowStyle
& wxTE_PASSWORD
) != 0 ;
1450 m_valueTag
= kControlEditTextPasswordCFStringTag
;
1452 OSStatus err
= CreateEditUnicodeTextControl(
1453 MAC_WXHWND(peer
->MacGetTopLevelWindowRef()), bounds
, cfr
,
1454 isPassword
, NULL
, &m_controlRef
) ;
1455 verify_noerr( err
);
1458 void wxMacUnicodeTextControl::Copy()
1460 SendHICommand( kHICommandCopy
) ;
1463 void wxMacUnicodeTextControl::Cut()
1465 SendHICommand( kHICommandCut
) ;
1468 void wxMacUnicodeTextControl::Paste()
1470 SendHICommand( kHICommandPaste
) ;
1473 bool wxMacUnicodeTextControl::CanPaste() const
1478 void wxMacUnicodeTextControl::SetEditable(bool WXUNUSED(editable
))
1480 #if 0 // leads to problem because text cannot be selected anymore
1481 SetData
<Boolean
>( kControlEditTextPart
, kControlEditTextLockedTag
, (Boolean
) !editable
) ;
1485 void wxMacUnicodeTextControl::GetSelection( long* from
, long* to
) const
1487 ControlEditTextSelectionRec sel
;
1489 verify_noerr( GetData
<ControlEditTextSelectionRec
>( 0, kControlEditTextSelectionTag
, &sel
) ) ;
1494 *from
= sel
.selStart
;
1499 void wxMacUnicodeTextControl::SetSelection( long from
, long to
)
1501 ControlEditTextSelectionRec sel
;
1503 int textLength
= 0 ;
1504 CFStringRef value
= GetData
<CFStringRef
>(0, m_valueTag
) ;
1507 wxMacCFStringHolder
cf(value
) ;
1508 textLength
= cf
.AsString().length() ;
1511 if ((from
== -1) && (to
== -1))
1518 from
= wxMin(textLength
,wxMax(from
,0)) ;
1519 to
= wxMax(0,wxMin(textLength
,to
)) ;
1522 sel
.selStart
= from
;
1525 SetData
<ControlEditTextSelectionRec
>( 0, kControlEditTextSelectionTag
, &sel
) ;
1530 void wxMacUnicodeTextControl::WriteText( const wxString
& str
)
1533 wxMacConvertNewlines10To13( &st
) ;
1535 #if MAC_OS_X_VERSION_MAX_ALLOWED > MAC_OS_X_VERSION_10_2
1538 wxMacCFStringHolder
cf(st
, m_font
.GetEncoding() ) ;
1539 CFStringRef value
= cf
;
1540 SetData
<CFStringRef
>( 0, kControlEditTextInsertCFStringRefTag
, &value
);
1545 wxString val
= GetStringValue() ;
1547 GetSelection( &start
, &end
) ;
1548 val
.Remove( start
, end
- start
) ;
1549 val
.insert( start
, str
) ;
1550 SetStringValue( val
) ;
1551 SetSelection( start
+ str
.length() , start
+ str
.length() ) ;
1557 // ----------------------------------------------------------------------------
1558 // MLTE control implementation (common part)
1559 // ----------------------------------------------------------------------------
1561 // if MTLE is read only, no changes at all are allowed, not even from
1562 // procedural API, in order to allow changes via API all the same we must undo
1563 // the readonly status while we are executing, this class helps to do so
1565 class wxMacEditHelper
1568 wxMacEditHelper( TXNObject txn
)
1570 TXNControlTag tag
[] = { kTXNIOPrivilegesTag
} ;
1572 TXNGetTXNObjectControls( m_txn
, 1 , tag
, m_data
) ;
1573 if ( m_data
[0].uValue
== kTXNReadOnly
)
1575 TXNControlData data
[] = { { kTXNReadWrite
} } ;
1576 TXNSetTXNObjectControls( m_txn
, false , 1 , tag
, data
) ;
1582 TXNControlTag tag
[] = { kTXNIOPrivilegesTag
} ;
1583 if ( m_data
[0].uValue
== kTXNReadOnly
)
1584 TXNSetTXNObjectControls( m_txn
, false , 1 , tag
, m_data
) ;
1589 TXNControlData m_data
[1] ;
1592 wxMacMLTEControl::wxMacMLTEControl( wxTextCtrl
*peer
)
1593 : wxMacTextControl( peer
)
1595 SetNeedsFocusRect( true ) ;
1598 wxString
wxMacMLTEControl::GetStringValue() const
1602 Size actualSize
= 0;
1607 err
= TXNGetDataEncoded( m_txn
, kTXNStartOffset
, kTXNEndOffset
, &theText
, kTXNUnicodeTextData
);
1616 actualSize
= GetHandleSize( theText
) / sizeof(UniChar
) ;
1617 if ( actualSize
> 0 )
1619 wxChar
*ptr
= NULL
;
1621 #if SIZEOF_WCHAR_T == 2
1622 ptr
= new wxChar
[actualSize
+ 1] ;
1623 wxStrncpy( ptr
, (wxChar
*)(*theText
) , actualSize
) ;
1625 SetHandleSize( theText
, (actualSize
+ 1) * sizeof(UniChar
) ) ;
1627 (((UniChar
*)*theText
)[actualSize
]) = 0 ;
1628 wxMBConvUTF16 converter
;
1629 size_t noChars
= converter
.MB2WC( NULL
, (const char*)*theText
, 0 ) ;
1630 wxASSERT_MSG( noChars
!= wxCONV_FAILED
, _T("Unable to count the number of characters in this string!") );
1631 ptr
= new wxChar
[noChars
+ 1] ;
1633 noChars
= converter
.MB2WC( ptr
, (const char*)*theText
, noChars
+ 1 ) ;
1634 wxASSERT_MSG( noChars
!= wxCONV_FAILED
, _T("Conversion of string failed!") );
1636 HUnlock( theText
) ;
1639 ptr
[actualSize
] = 0 ;
1640 result
= wxString( ptr
) ;
1644 DisposeHandle( theText
) ;
1648 err
= TXNGetDataEncoded( m_txn
, kTXNStartOffset
, kTXNEndOffset
, &theText
, kTXNTextData
);
1657 actualSize
= GetHandleSize( theText
) ;
1658 if ( actualSize
> 0 )
1661 result
= wxString( *theText
, wxConvLocal
, actualSize
) ;
1662 HUnlock( theText
) ;
1665 DisposeHandle( theText
) ;
1671 wxMacConvertNewlines13To10( &result
) ;
1673 wxMacConvertNewlines10To13( &result
) ;
1679 void wxMacMLTEControl::SetStringValue( const wxString
&str
)
1682 wxMacConvertNewlines10To13( &st
);
1686 wxMacWindowClipper
c( m_peer
) ;
1690 wxMacEditHelper
help( m_txn
);
1691 SetTXNData( st
, kTXNStartOffset
, kTXNEndOffset
);
1694 TXNSetSelection( m_txn
, 0, 0 );
1695 TXNShowSelection( m_txn
, kTXNShowStart
);
1699 TXNFrameOptions
wxMacMLTEControl::FrameOptionsFromWXStyle( long wxStyle
)
1701 TXNFrameOptions frameOptions
= kTXNDontDrawCaretWhenInactiveMask
;
1703 #if MAC_OS_X_VERSION_MAX_ALLOWED >= MAC_OS_X_VERSION_10_3
1704 frameOptions
|= kTXNDoFontSubstitutionMask
;
1707 if ( ! (wxStyle
& wxTE_NOHIDESEL
) )
1708 frameOptions
|= kTXNDontDrawSelectionWhenInactiveMask
;
1710 if ( wxStyle
& (wxHSCROLL
| wxTE_DONTWRAP
) )
1711 frameOptions
|= kTXNWantHScrollBarMask
;
1713 if ( wxStyle
& wxTE_MULTILINE
)
1715 frameOptions
|= kTXNAlwaysWrapAtViewEdgeMask
;
1717 if ( !(wxStyle
& wxTE_NO_VSCROLL
) )
1719 frameOptions
|= kTXNWantVScrollBarMask
;
1721 // The following code causes drawing problems on 10.4. Perhaps it can be restored for
1722 // older versions of the OS, but I'm not sure it's appropriate to put a grow icon here
1723 // anyways, as AFAIK users can't actually use it to resize the text ctrl.
1724 // if ( frameOptions & kTXNWantHScrollBarMask )
1725 // frameOptions |= kTXNDrawGrowIconMask ;
1730 frameOptions
|= kTXNSingleLineOnlyMask
;
1733 return frameOptions
;
1736 void wxMacMLTEControl::AdjustCreationAttributes(const wxColour
&background
,
1737 bool WXUNUSED(visible
))
1739 TXNControlTag iControlTags
[] =
1741 kTXNDoFontSubstitution
,
1742 kTXNWordWrapStateTag
,
1744 TXNControlData iControlData
[] =
1750 int toptag
= WXSIZEOF( iControlTags
) ;
1752 if ( m_windowStyle
& wxTE_MULTILINE
)
1754 iControlData
[1].uValue
=
1755 (m_windowStyle
& wxTE_DONTWRAP
)
1760 OSStatus err
= TXNSetTXNObjectControls( m_txn
, false, toptag
, iControlTags
, iControlData
) ;
1761 verify_noerr( err
);
1763 // setting the default font:
1764 // under 10.2 this causes a visible caret, therefore we avoid it
1766 if ( UMAGetSystemVersion() >= 0x1030 )
1772 GetThemeFont( kThemeSystemFont
, GetApplicationScript() , fontName
, &fontSize
, &fontStyle
) ;
1774 TXNTypeAttributes typeAttr
[] =
1776 { kTXNQDFontNameAttribute
, kTXNQDFontNameAttributeSize
, { (void*) fontName
} } ,
1777 { kTXNQDFontSizeAttribute
, kTXNFontSizeAttributeSize
, { (void*) (fontSize
<< 16) } } ,
1778 { kTXNQDFontStyleAttribute
, kTXNQDFontStyleAttributeSize
, { (void*) normal
} } ,
1781 err
= TXNSetTypeAttributes(
1782 m_txn
, sizeof(typeAttr
) / sizeof(TXNTypeAttributes
),
1783 typeAttr
, kTXNStartOffset
, kTXNEndOffset
);
1784 verify_noerr( err
);
1787 if ( m_windowStyle
& wxTE_PASSWORD
)
1789 UniChar c
= 0x00A5 ;
1790 err
= TXNEchoMode( m_txn
, c
, 0 , true );
1791 verify_noerr( err
);
1794 TXNBackground tback
;
1795 tback
.bgType
= kTXNBackgroundTypeRGB
;
1796 tback
.bg
.color
= MAC_WXCOLORREF( background
.GetPixel() );
1797 TXNSetBackground( m_txn
, &tback
);
1799 #if MAC_OS_X_VERSION_MAX_ALLOWED >= MAC_OS_X_VERSION_10_4
1800 if ( UMAGetSystemVersion() >= 0x1040 )
1802 TXNCommandEventSupportOptions options
;
1803 if ( TXNGetCommandEventSupport( m_txn
, &options
) == noErr
)
1806 kTXNSupportEditCommandProcessing
1807 | kTXNSupportEditCommandUpdating
1808 | kTXNSupportSpellCheckCommandProcessing
1809 | kTXNSupportSpellCheckCommandUpdating
1810 | kTXNSupportFontCommandProcessing
1811 | kTXNSupportFontCommandUpdating
;
1813 TXNSetCommandEventSupport( m_txn
, options
) ;
1819 void wxMacMLTEControl::SetBackground( const wxBrush
&brush
)
1821 // currently only solid background are supported
1822 TXNBackground tback
;
1824 tback
.bgType
= kTXNBackgroundTypeRGB
;
1825 tback
.bg
.color
= MAC_WXCOLORREF( brush
.GetColour().GetPixel() );
1826 TXNSetBackground( m_txn
, &tback
);
1829 void wxMacMLTEControl::TXNSetAttribute( const wxTextAttr
& style
, long from
, long to
)
1831 TXNTypeAttributes typeAttr
[4] ;
1835 if ( style
.HasFont() )
1837 wxFont
font(style
.GetFont()) ;
1839 #if 0 // old version
1840 Str255 fontName
= "\pMonaco" ;
1841 SInt16 fontSize
= 12 ;
1842 Style fontStyle
= normal
;
1843 wxMacStringToPascal( font
.GetFaceName() , fontName
) ;
1844 fontSize
= font
.GetPointSize() ;
1845 if ( font
.GetUnderlined() )
1846 fontStyle
|= underline
;
1847 if ( font
.GetWeight() == wxBOLD
)
1849 if ( font
.GetStyle() == wxITALIC
)
1850 fontStyle
|= italic
;
1852 typeAttr
[attrCount
].tag
= kTXNQDFontNameAttribute
;
1853 typeAttr
[attrCount
].size
= kTXNQDFontNameAttributeSize
;
1854 typeAttr
[attrCount
].data
.dataPtr
= (void*)fontName
;
1857 typeAttr
[attrCount
].tag
= kTXNQDFontSizeAttribute
;
1858 typeAttr
[attrCount
].size
= kTXNFontSizeAttributeSize
;
1859 typeAttr
[attrCount
].data
.dataValue
= (fontSize
<< 16) ;
1862 typeAttr
[attrCount
].tag
= kTXNQDFontStyleAttribute
;
1863 typeAttr
[attrCount
].size
= kTXNQDFontStyleAttributeSize
;
1864 typeAttr
[attrCount
].data
.dataValue
= fontStyle
;
1867 typeAttr
[attrCount
].tag
= kTXNATSUIStyle
;
1868 typeAttr
[attrCount
].size
= kTXNATSUIStyleSize
;
1869 typeAttr
[attrCount
].data
.dataPtr
= font
.MacGetATSUStyle() ;
1874 if ( style
.HasTextColour() )
1876 color
= MAC_WXCOLORREF(style
.GetTextColour().GetPixel()) ;
1878 typeAttr
[attrCount
].tag
= kTXNQDFontColorAttribute
;
1879 typeAttr
[attrCount
].size
= kTXNQDFontColorAttributeSize
;
1880 typeAttr
[attrCount
].data
.dataPtr
= (void*) &color
;
1884 if ( attrCount
> 0 )
1886 verify_noerr( TXNSetTypeAttributes( m_txn
, attrCount
, typeAttr
, from
, to
) );
1887 // unfortunately the relayout is not automatic
1888 TXNRecalcTextLayout( m_txn
);
1892 void wxMacMLTEControl::SetFont(const wxFont
& font
,
1893 const wxColour
& foreground
,
1894 long WXUNUSED(windowStyle
))
1896 wxMacEditHelper
help( m_txn
) ;
1897 TXNSetAttribute( wxTextAttr( foreground
, wxNullColour
, font
), kTXNStartOffset
, kTXNEndOffset
) ;
1900 void wxMacMLTEControl::SetStyle( long start
, long end
, const wxTextAttr
& style
)
1902 wxMacEditHelper
help( m_txn
) ;
1903 TXNSetAttribute( style
, start
, end
) ;
1906 void wxMacMLTEControl::Copy()
1908 ClearCurrentScrap();
1910 TXNConvertToPublicScrap();
1913 void wxMacMLTEControl::Cut()
1915 ClearCurrentScrap();
1917 TXNConvertToPublicScrap();
1920 void wxMacMLTEControl::Paste()
1922 TXNConvertFromPublicScrap();
1926 bool wxMacMLTEControl::CanPaste() const
1928 return TXNIsScrapPastable() ;
1931 void wxMacMLTEControl::SetEditable(bool editable
)
1933 TXNControlTag tag
[] = { kTXNIOPrivilegesTag
} ;
1934 TXNControlData data
[] = { { editable
? kTXNReadWrite
: kTXNReadOnly
} } ;
1935 TXNSetTXNObjectControls( m_txn
, false, WXSIZEOF(tag
), tag
, data
) ;
1938 wxTextPos
wxMacMLTEControl::GetLastPosition() const
1940 wxTextPos actualsize
= 0 ;
1943 OSErr err
= TXNGetDataEncoded( m_txn
, kTXNStartOffset
, kTXNEndOffset
, &theText
, kTXNTextData
);
1948 actualsize
= GetHandleSize( theText
) ;
1949 DisposeHandle( theText
) ;
1959 void wxMacMLTEControl::Replace( long from
, long to
, const wxString
&str
)
1961 wxString value
= str
;
1962 wxMacConvertNewlines10To13( &value
) ;
1964 wxMacEditHelper
help( m_txn
) ;
1966 wxMacWindowClipper
c( m_peer
) ;
1969 TXNSetSelection( m_txn
, from
, to
) ;
1971 SetTXNData( value
, kTXNUseCurrentSelection
, kTXNUseCurrentSelection
) ;
1974 void wxMacMLTEControl::Remove( long from
, long to
)
1977 wxMacWindowClipper
c( m_peer
) ;
1979 wxMacEditHelper
help( m_txn
) ;
1980 TXNSetSelection( m_txn
, from
, to
) ;
1984 void wxMacMLTEControl::GetSelection( long* from
, long* to
) const
1986 TXNGetSelection( m_txn
, (TXNOffset
*) from
, (TXNOffset
*) to
) ;
1989 void wxMacMLTEControl::SetSelection( long from
, long to
)
1992 wxMacWindowClipper
c( m_peer
) ;
1995 // change the selection
1996 if ((from
== -1) && (to
== -1))
1997 TXNSelectAll( m_txn
);
1999 TXNSetSelection( m_txn
, from
, to
);
2001 TXNShowSelection( m_txn
, kTXNShowStart
);
2004 void wxMacMLTEControl::WriteText( const wxString
& str
)
2007 wxMacConvertNewlines10To13( &st
) ;
2009 long start
, end
, dummy
;
2011 GetSelection( &start
, &dummy
) ;
2013 wxMacWindowClipper
c( m_peer
) ;
2017 wxMacEditHelper
helper( m_txn
) ;
2018 SetTXNData( st
, kTXNUseCurrentSelection
, kTXNUseCurrentSelection
) ;
2021 GetSelection( &dummy
, &end
) ;
2023 // TODO: SetStyle( start , end , GetDefaultStyle() ) ;
2026 void wxMacMLTEControl::Clear()
2029 wxMacWindowClipper
c( m_peer
) ;
2031 wxMacEditHelper
st( m_txn
) ;
2032 TXNSetSelection( m_txn
, kTXNStartOffset
, kTXNEndOffset
) ;
2036 bool wxMacMLTEControl::CanUndo() const
2038 return TXNCanUndo( m_txn
, NULL
) ;
2041 void wxMacMLTEControl::Undo()
2046 bool wxMacMLTEControl::CanRedo() const
2048 return TXNCanRedo( m_txn
, NULL
) ;
2051 void wxMacMLTEControl::Redo()
2056 int wxMacMLTEControl::GetNumberOfLines() const
2058 ItemCount lines
= 0 ;
2059 TXNGetLineCount( m_txn
, &lines
) ;
2064 long wxMacMLTEControl::XYToPosition(long x
, long y
) const
2069 // TODO: find a better implementation : while we can get the
2070 // line metrics of a certain line, we don't get its starting
2071 // position, so it would probably be rather a binary search
2072 // for the start position
2073 long xpos
= 0, ypos
= 0 ;
2074 int lastHeight
= 0 ;
2077 lastpos
= GetLastPosition() ;
2078 for ( n
= 0 ; n
<= (ItemCount
) lastpos
; ++n
)
2080 if ( y
== ypos
&& x
== xpos
)
2083 TXNOffsetToPoint( m_txn
, n
, &curpt
) ;
2085 if ( curpt
.v
> lastHeight
)
2091 lastHeight
= curpt
.v
;
2100 bool wxMacMLTEControl::PositionToXY( long pos
, long *x
, long *y
) const
2110 lastpos
= GetLastPosition() ;
2111 if ( pos
<= lastpos
)
2113 // TODO: find a better implementation - while we can get the
2114 // line metrics of a certain line, we don't get its starting
2115 // position, so it would probably be rather a binary search
2116 // for the start position
2117 long xpos
= 0, ypos
= 0 ;
2118 int lastHeight
= 0 ;
2121 for ( n
= 0 ; n
<= (ItemCount
) pos
; ++n
)
2123 TXNOffsetToPoint( m_txn
, n
, &curpt
) ;
2125 if ( curpt
.v
> lastHeight
)
2131 lastHeight
= curpt
.v
;
2146 void wxMacMLTEControl::ShowPosition( long pos
)
2148 Point current
, desired
;
2149 TXNOffset selstart
, selend
;
2151 TXNGetSelection( m_txn
, &selstart
, &selend
);
2152 TXNOffsetToPoint( m_txn
, selstart
, ¤t
);
2153 TXNOffsetToPoint( m_txn
, pos
, &desired
);
2155 // TODO: use HIPoints for 10.3 and above
2157 OSErr theErr
= noErr
;
2158 long dv
= desired
.v
- current
.v
;
2159 long dh
= desired
.h
- current
.h
;
2160 TXNShowSelection( m_txn
, kTXNShowStart
) ; // NB: should this be kTXNShowStart or kTXNShowEnd ??
2161 theErr
= TXNScroll( m_txn
, kTXNScrollUnitsInPixels
, kTXNScrollUnitsInPixels
, &dv
, &dh
);
2163 // there will be an error returned for classic MLTE implementation when the control is
2164 // invisible, but HITextView works correctly, so we don't assert that one
2165 // wxASSERT_MSG( theErr == noErr, _T("TXNScroll returned an error!") );
2168 void wxMacMLTEControl::SetTXNData( const wxString
& st
, TXNOffset start
, TXNOffset end
)
2171 #if SIZEOF_WCHAR_T == 2
2172 size_t len
= st
.length() ;
2173 TXNSetData( m_txn
, kTXNUnicodeTextData
, (void*)st
.wc_str(), len
* 2, start
, end
);
2175 wxMBConvUTF16 converter
;
2176 ByteCount byteBufferLen
= converter
.WC2MB( NULL
, st
.wc_str(), 0 ) ;
2177 UniChar
*unibuf
= (UniChar
*)malloc( byteBufferLen
) ;
2178 converter
.WC2MB( (char*)unibuf
, st
.wc_str(), byteBufferLen
) ;
2179 TXNSetData( m_txn
, kTXNUnicodeTextData
, (void*)unibuf
, byteBufferLen
, start
, end
) ;
2183 wxCharBuffer text
= st
.mb_str( wxConvLocal
) ;
2184 TXNSetData( m_txn
, kTXNTextData
, (void*)text
.data(), strlen( text
), start
, end
) ;
2188 wxString
wxMacMLTEControl::GetLineText(long lineNo
) const
2192 if ( lineNo
< GetNumberOfLines() )
2195 Fixed lineWidth
, lineHeight
, currentHeight
;
2198 // get the first possible position in the control
2199 TXNOffsetToPoint(m_txn
, 0, &firstPoint
);
2201 // Iterate through the lines until we reach the one we want,
2202 // adding to our current y pixel point position
2205 while (ypos
< lineNo
)
2207 TXNGetLineMetrics(m_txn
, ypos
++, &lineWidth
, &lineHeight
);
2208 currentHeight
+= lineHeight
;
2211 Point thePoint
= { firstPoint
.v
+ (currentHeight
>> 16), firstPoint
.h
+ (0) };
2212 TXNOffset theOffset
;
2213 TXNPointToOffset(m_txn
, thePoint
, &theOffset
);
2215 wxString content
= GetStringValue() ;
2216 Point currentPoint
= thePoint
;
2217 while (thePoint
.v
== currentPoint
.v
&& theOffset
< content
.length())
2219 line
+= content
[theOffset
];
2220 TXNOffsetToPoint(m_txn
, ++theOffset
, ¤tPoint
);
2227 int wxMacMLTEControl::GetLineLength(long lineNo
) const
2231 if ( lineNo
< GetNumberOfLines() )
2234 Fixed lineWidth
, lineHeight
, currentHeight
;
2237 // get the first possible position in the control
2238 TXNOffsetToPoint(m_txn
, 0, &firstPoint
);
2240 // Iterate through the lines until we reach the one we want,
2241 // adding to our current y pixel point position
2244 while (ypos
< lineNo
)
2246 TXNGetLineMetrics(m_txn
, ypos
++, &lineWidth
, &lineHeight
);
2247 currentHeight
+= lineHeight
;
2250 Point thePoint
= { firstPoint
.v
+ (currentHeight
>> 16), firstPoint
.h
+ (0) };
2251 TXNOffset theOffset
;
2252 TXNPointToOffset(m_txn
, thePoint
, &theOffset
);
2254 wxString content
= GetStringValue() ;
2255 Point currentPoint
= thePoint
;
2256 while (thePoint
.v
== currentPoint
.v
&& theOffset
< content
.length())
2259 TXNOffsetToPoint(m_txn
, ++theOffset
, ¤tPoint
);
2266 #if MAC_OS_X_VERSION_MAX_ALLOWED < MAC_OS_X_VERSION_10_5
2268 // ----------------------------------------------------------------------------
2269 // MLTE control implementation (classic part)
2270 // ----------------------------------------------------------------------------
2272 // OS X Notes : We still don't have a full replacement for MLTE, so this implementation
2273 // has to live on. We have different problems coming from outdated implementations on the
2274 // various OS X versions. Most deal with the scrollbars: they are not correctly embedded
2275 // while this can be solved on 10.3 by reassigning them the correct place, on 10.2 there is
2276 // no way out, therefore we are using our own implementation and our own scrollbars ....
2278 #ifdef __WXMAC_OSX__
2280 TXNScrollInfoUPP gTXNScrollInfoProc
= NULL
;
2281 ControlActionUPP gTXNScrollActionProc
= NULL
;
2283 pascal void wxMacMLTEClassicControl::TXNScrollInfoProc(
2284 SInt32 iValue
, SInt32 iMaximumValue
,
2285 TXNScrollBarOrientation iScrollBarOrientation
, SInt32 iRefCon
)
2287 wxMacMLTEClassicControl
* mlte
= (wxMacMLTEClassicControl
*) iRefCon
;
2288 SInt32 value
= wxMax( iValue
, 0 ) ;
2289 SInt32 maximum
= wxMax( iMaximumValue
, 0 ) ;
2291 if ( iScrollBarOrientation
== kTXNHorizontal
)
2293 if ( mlte
->m_sbHorizontal
)
2295 SetControl32BitValue( mlte
->m_sbHorizontal
, value
) ;
2296 SetControl32BitMaximum( mlte
->m_sbHorizontal
, maximum
) ;
2297 mlte
->m_lastHorizontalValue
= value
;
2300 else if ( iScrollBarOrientation
== kTXNVertical
)
2302 if ( mlte
->m_sbVertical
)
2304 SetControl32BitValue( mlte
->m_sbVertical
, value
) ;
2305 SetControl32BitMaximum( mlte
->m_sbVertical
, maximum
) ;
2306 mlte
->m_lastVerticalValue
= value
;
2311 pascal void wxMacMLTEClassicControl::TXNScrollActionProc( ControlRef controlRef
, ControlPartCode partCode
)
2313 wxMacMLTEClassicControl
* mlte
= (wxMacMLTEClassicControl
*) GetControlReference( controlRef
) ;
2317 if ( controlRef
!= mlte
->m_sbVertical
&& controlRef
!= mlte
->m_sbHorizontal
)
2321 bool isHorizontal
= ( controlRef
== mlte
->m_sbHorizontal
) ;
2323 SInt32 minimum
= 0 ;
2324 SInt32 maximum
= GetControl32BitMaximum( controlRef
) ;
2325 SInt32 value
= GetControl32BitValue( controlRef
) ;
2330 case kControlDownButtonPart
:
2334 case kControlUpButtonPart
:
2338 case kControlPageDownPart
:
2339 delta
= GetControlViewSize( controlRef
) ;
2342 case kControlPageUpPart
:
2343 delta
= -GetControlViewSize( controlRef
) ;
2346 case kControlIndicatorPart
:
2347 delta
= value
- (isHorizontal
? mlte
->m_lastHorizontalValue
: mlte
->m_lastVerticalValue
) ;
2356 SInt32 newValue
= value
;
2358 if ( partCode
!= kControlIndicatorPart
)
2360 if ( value
+ delta
< minimum
)
2361 delta
= minimum
- value
;
2362 if ( value
+ delta
> maximum
)
2363 delta
= maximum
- value
;
2365 SetControl32BitValue( controlRef
, value
+ delta
) ;
2366 newValue
= value
+ delta
;
2369 SInt32 verticalDelta
= isHorizontal
? 0 : delta
;
2370 SInt32 horizontalDelta
= isHorizontal
? delta
: 0 ;
2373 mlte
->m_txn
, kTXNScrollUnitsInPixels
, kTXNScrollUnitsInPixels
,
2374 &verticalDelta
, &horizontalDelta
);
2375 verify_noerr( err
);
2378 mlte
->m_lastHorizontalValue
= newValue
;
2380 mlte
->m_lastVerticalValue
= newValue
;
2385 // make correct activations
2386 void wxMacMLTEClassicControl::MacActivatePaneText(bool setActive
)
2388 wxTextCtrl
* textctrl
= (wxTextCtrl
*) GetControlReference(m_controlRef
);
2390 wxMacWindowClipper
clipper( textctrl
) ;
2391 TXNActivate( m_txn
, m_txnFrameID
, setActive
);
2393 ControlRef controlFocus
= 0 ;
2394 GetKeyboardFocus( m_txnWindow
, &controlFocus
) ;
2395 if ( controlFocus
== m_controlRef
)
2396 TXNFocus( m_txn
, setActive
);
2399 void wxMacMLTEClassicControl::MacFocusPaneText(bool setFocus
)
2401 TXNFocus( m_txn
, setFocus
);
2404 // guards against inappropriate redraw (hidden objects drawing onto window)
2406 void wxMacMLTEClassicControl::MacSetObjectVisibility(bool vis
)
2408 ControlRef controlFocus
= 0 ;
2409 GetKeyboardFocus( m_txnWindow
, &controlFocus
) ;
2411 if ( !vis
&& (controlFocus
== m_controlRef
) )
2412 SetKeyboardFocus( m_txnWindow
, m_controlRef
, kControlFocusNoPart
) ;
2414 TXNControlTag iControlTags
[1] = { kTXNVisibilityTag
};
2415 TXNControlData iControlData
[1] = { { (UInt32
)false } };
2417 verify_noerr( TXNGetTXNObjectControls( m_txn
, 1, iControlTags
, iControlData
) ) ;
2419 if ( iControlData
[0].uValue
!= vis
)
2421 iControlData
[0].uValue
= vis
;
2422 verify_noerr( TXNSetTXNObjectControls( m_txn
, false , 1, iControlTags
, iControlData
) ) ;
2425 // currently, we always clip as partial visibility (overlapped) visibility is also a problem,
2426 // if we run into further problems we might set the FrameBounds to an empty rect here
2429 // make sure that the TXNObject is at the right position
2431 void wxMacMLTEClassicControl::MacUpdatePosition()
2433 wxTextCtrl
* textctrl
= (wxTextCtrl
*)GetControlReference( m_controlRef
);
2434 if ( textctrl
== NULL
)
2438 UMAGetControlBoundsInWindowCoords( m_controlRef
, &bounds
);
2440 wxRect visRect
= textctrl
->MacGetClippedClientRect() ;
2441 Rect visBounds
= { visRect
.y
, visRect
.x
, visRect
.y
+ visRect
.height
, visRect
.x
+ visRect
.width
} ;
2444 textctrl
->MacWindowToRootWindow( &x
, &y
) ;
2445 OffsetRect( &visBounds
, x
, y
) ;
2447 if ( !EqualRect( &bounds
, &m_txnControlBounds
) || !EqualRect( &visBounds
, &m_txnVisBounds
) )
2449 m_txnControlBounds
= bounds
;
2450 m_txnVisBounds
= visBounds
;
2451 wxMacWindowClipper
cl( textctrl
) ;
2453 #ifdef __WXMAC_OSX__
2454 if ( m_sbHorizontal
|| m_sbVertical
)
2456 int w
= bounds
.right
- bounds
.left
;
2457 int h
= bounds
.bottom
- bounds
.top
;
2459 if ( m_sbHorizontal
)
2463 sbBounds
.left
= -1 ;
2464 sbBounds
.top
= h
- 14 ;
2465 sbBounds
.right
= w
+ 1 ;
2466 sbBounds
.bottom
= h
+ 1 ;
2468 SetControlBounds( m_sbHorizontal
, &sbBounds
) ;
2469 SetControlViewSize( m_sbHorizontal
, w
) ;
2476 sbBounds
.left
= w
- 14 ;
2478 sbBounds
.right
= w
+ 1 ;
2479 sbBounds
.bottom
= m_sbHorizontal
? h
- 14 : h
+ 1 ;
2481 SetControlBounds( m_sbVertical
, &sbBounds
) ;
2482 SetControlViewSize( m_sbVertical
, h
) ;
2487 TXNLongRect olddestRect
;
2488 TXNGetRectBounds( m_txn
, &oldviewRect
, &olddestRect
, NULL
) ;
2490 Rect viewRect
= { m_txnControlBounds
.top
, m_txnControlBounds
.left
,
2491 m_txnControlBounds
.bottom
- ( m_sbHorizontal
? 14 : 0 ) ,
2492 m_txnControlBounds
.right
- ( m_sbVertical
? 14 : 0 ) } ;
2493 TXNLongRect destRect
= { m_txnControlBounds
.top
, m_txnControlBounds
.left
,
2494 m_txnControlBounds
.bottom
- ( m_sbHorizontal
? 14 : 0 ) ,
2495 m_txnControlBounds
.right
- ( m_sbVertical
? 14 : 0 ) } ;
2497 if ( olddestRect
.right
>= 10000 )
2498 destRect
.right
= destRect
.left
+ 32000 ;
2500 if ( olddestRect
.bottom
>= 0x20000000 )
2501 destRect
.bottom
= destRect
.top
+ 0x40000000 ;
2503 SectRect( &viewRect
, &visBounds
, &viewRect
) ;
2504 TXNSetRectBounds( m_txn
, &viewRect
, &destRect
, true ) ;
2509 m_txnControlBounds
.top
,
2510 m_txnControlBounds
.left
,
2511 m_txnControlBounds
.bottom
- (m_sbHorizontal
? 14 : 0),
2512 m_txnControlBounds
.right
- (m_sbVertical
? 14 : 0),
2518 m_txn
, m_txnControlBounds
.top
, m_txnControlBounds
.left
,
2519 wxMax( m_txnControlBounds
.bottom
, m_txnControlBounds
.top
),
2520 wxMax( m_txnControlBounds
.right
, m_txnControlBounds
.left
), m_txnFrameID
);
2523 // the SetFrameBounds method under Classic sometimes does not correctly scroll a selection into sight after a
2524 // movement, therefore we have to force it
2526 // this problem has been reported in OSX as well, so we use this here once again
2528 TXNLongRect textRect
;
2529 TXNGetRectBounds( m_txn
, NULL
, NULL
, &textRect
) ;
2530 if ( textRect
.left
< m_txnControlBounds
.left
)
2531 TXNShowSelection( m_txn
, kTXNShowStart
) ;
2535 void wxMacMLTEClassicControl::SetRect( Rect
*r
)
2537 wxMacControl::SetRect( r
) ;
2538 MacUpdatePosition() ;
2541 void wxMacMLTEClassicControl::MacControlUserPaneDrawProc(wxInt16
WXUNUSED(thePart
))
2543 wxTextCtrl
* textctrl
= (wxTextCtrl
*)GetControlReference( m_controlRef
);
2544 if ( textctrl
== NULL
)
2547 if ( textctrl
->MacIsReallyShown() )
2549 wxMacWindowClipper
clipper( textctrl
) ;
2550 TXNDraw( m_txn
, NULL
) ;
2554 wxInt16
wxMacMLTEClassicControl::MacControlUserPaneHitTestProc(wxInt16 x
, wxInt16 y
)
2556 Point where
= { y
, x
} ;
2557 ControlPartCode result
= kControlNoPart
;
2559 wxTextCtrl
* textctrl
= (wxTextCtrl
*) GetControlReference( m_controlRef
);
2560 if ( (textctrl
!= NULL
) && textctrl
->MacIsReallyShown() )
2562 if (PtInRect( where
, &m_txnControlBounds
))
2564 result
= kControlEditTextPart
;
2568 // sometimes we get the coords also in control local coordinates, therefore test again
2570 textctrl
->MacClientToRootWindow( &x
, &y
) ;
2574 if (PtInRect( where
, &m_txnControlBounds
))
2575 result
= kControlEditTextPart
;
2582 wxInt16
wxMacMLTEClassicControl::MacControlUserPaneTrackingProc( wxInt16 x
, wxInt16 y
, void* WXUNUSED(actionProc
) )
2584 ControlPartCode result
= kControlNoPart
;
2586 wxTextCtrl
* textctrl
= (wxTextCtrl
*) GetControlReference( m_controlRef
);
2587 if ( (textctrl
!= NULL
) && textctrl
->MacIsReallyShown() )
2589 Point startPt
= { y
, x
} ;
2591 // for compositing, we must convert these into toplevel window coordinates, because hittesting expects them
2593 textctrl
->MacClientToRootWindow( &x
, &y
) ;
2597 switch (MacControlUserPaneHitTestProc( startPt
.h
, startPt
.v
))
2599 case kControlEditTextPart
:
2601 wxMacWindowClipper
clipper( textctrl
) ;
2604 ConvertEventRefToEventRecord( (EventRef
) wxTheApp
->MacGetCurrentEvent() , &rec
) ;
2605 TXNClick( m_txn
, &rec
);
2617 void wxMacMLTEClassicControl::MacControlUserPaneIdleProc()
2619 wxTextCtrl
* textctrl
= (wxTextCtrl
*)GetControlReference( m_controlRef
);
2620 if ( textctrl
== NULL
)
2623 if (textctrl
->MacIsReallyShown())
2625 if (IsControlActive(m_controlRef
))
2629 wxMacWindowClipper
clipper( textctrl
) ;
2634 if (PtInRect(mousep
, &m_txnControlBounds
))
2636 RgnHandle theRgn
= NewRgn();
2637 RectRgn(theRgn
, &m_txnControlBounds
);
2638 TXNAdjustCursor(m_txn
, theRgn
);
2645 wxInt16
wxMacMLTEClassicControl::MacControlUserPaneKeyDownProc (wxInt16 keyCode
, wxInt16 charCode
, wxInt16 modifiers
)
2647 wxTextCtrl
* textctrl
= (wxTextCtrl
*)GetControlReference( m_controlRef
);
2648 if ( textctrl
== NULL
)
2649 return kControlNoPart
;
2651 wxMacWindowClipper
clipper( textctrl
) ;
2654 memset( &ev
, 0 , sizeof( ev
) ) ;
2656 ev
.modifiers
= modifiers
;
2657 ev
.message
= ((keyCode
<< 8) & keyCodeMask
) | (charCode
& charCodeMask
);
2658 TXNKeyDown( m_txn
, &ev
);
2660 return kControlEntireControl
;
2663 void wxMacMLTEClassicControl::MacControlUserPaneActivateProc(bool activating
)
2665 MacActivatePaneText( activating
);
2668 wxInt16
wxMacMLTEClassicControl::MacControlUserPaneFocusProc(wxInt16 action
)
2670 ControlPartCode focusResult
= kControlFocusNoPart
;
2672 wxTextCtrl
* textctrl
= (wxTextCtrl
*)GetControlReference( m_controlRef
);
2673 if ( textctrl
== NULL
)
2676 wxMacWindowClipper
clipper( textctrl
) ;
2678 ControlRef controlFocus
= NULL
;
2679 GetKeyboardFocus( m_txnWindow
, &controlFocus
) ;
2680 bool wasFocused
= ( controlFocus
== m_controlRef
) ;
2684 case kControlFocusPrevPart
:
2685 case kControlFocusNextPart
:
2686 MacFocusPaneText( !wasFocused
);
2687 focusResult
= (!wasFocused
? (ControlPartCode
) kControlEditTextPart
: (ControlPartCode
) kControlFocusNoPart
);
2690 case kControlFocusNoPart
:
2692 MacFocusPaneText( false );
2693 focusResult
= kControlFocusNoPart
;
2700 void wxMacMLTEClassicControl::MacControlUserPaneBackgroundProc( void *WXUNUSED(info
) )
2704 wxMacMLTEClassicControl::wxMacMLTEClassicControl( wxTextCtrl
*wxPeer
,
2705 const wxString
& str
,
2707 const wxSize
& size
, long style
)
2708 : wxMacMLTEControl( wxPeer
)
2710 m_font
= wxPeer
->GetFont() ;
2711 m_windowStyle
= style
;
2712 Rect bounds
= wxMacGetBoundsForControl( wxPeer
, pos
, size
) ;
2715 kControlSupportsEmbedding
| kControlSupportsFocus
| kControlWantsIdle
2716 | kControlWantsActivate
| kControlHandlesTracking
2717 // | kControlHasSpecialBackground
2718 | kControlGetsFocusOnClick
| kControlSupportsLiveFeedback
;
2720 OSStatus err
= ::CreateUserPaneControl(
2721 MAC_WXHWND(wxPeer
->GetParent()->MacGetTopLevelWindowRef()),
2722 &bounds
, featureSet
, &m_controlRef
);
2723 verify_noerr( err
);
2727 AdjustCreationAttributes( *wxWHITE
, true ) ;
2729 MacSetObjectVisibility( wxPeer
->MacIsReallyShown() ) ;
2733 wxMacConvertNewlines10To13( &st
) ;
2734 wxMacWindowClipper
clipper( m_peer
) ;
2735 SetTXNData( st
, kTXNStartOffset
, kTXNEndOffset
) ;
2736 TXNSetSelection( m_txn
, 0, 0 ) ;
2740 wxMacMLTEClassicControl::~wxMacMLTEClassicControl()
2742 TXNDeleteObject( m_txn
);
2746 void wxMacMLTEClassicControl::VisibilityChanged(bool shown
)
2748 MacSetObjectVisibility( shown
) ;
2749 wxMacControl::VisibilityChanged( shown
) ;
2752 void wxMacMLTEClassicControl::SuperChangedPosition()
2754 MacUpdatePosition() ;
2755 wxMacControl::SuperChangedPosition() ;
2758 #ifdef __WXMAC_OSX__
2760 ControlUserPaneDrawUPP gTPDrawProc
= NULL
;
2761 ControlUserPaneHitTestUPP gTPHitProc
= NULL
;
2762 ControlUserPaneTrackingUPP gTPTrackProc
= NULL
;
2763 ControlUserPaneIdleUPP gTPIdleProc
= NULL
;
2764 ControlUserPaneKeyDownUPP gTPKeyProc
= NULL
;
2765 ControlUserPaneActivateUPP gTPActivateProc
= NULL
;
2766 ControlUserPaneFocusUPP gTPFocusProc
= NULL
;
2768 static pascal void wxMacControlUserPaneDrawProc(ControlRef control
, SInt16 part
)
2770 wxTextCtrl
*textCtrl
= wxDynamicCast( wxFindControlFromMacControl(control
) , wxTextCtrl
) ;
2771 wxMacMLTEClassicControl
* win
= textCtrl
? (wxMacMLTEClassicControl
*)(textCtrl
->GetPeer()) : NULL
;
2773 win
->MacControlUserPaneDrawProc( part
) ;
2776 static pascal ControlPartCode
wxMacControlUserPaneHitTestProc(ControlRef control
, Point where
)
2778 wxTextCtrl
*textCtrl
= wxDynamicCast( wxFindControlFromMacControl(control
) , wxTextCtrl
) ;
2779 wxMacMLTEClassicControl
* win
= textCtrl
? (wxMacMLTEClassicControl
*)(textCtrl
->GetPeer()) : NULL
;
2781 return win
->MacControlUserPaneHitTestProc( where
.h
, where
.v
) ;
2783 return kControlNoPart
;
2786 static pascal ControlPartCode
wxMacControlUserPaneTrackingProc(ControlRef control
, Point startPt
, ControlActionUPP actionProc
)
2788 wxTextCtrl
*textCtrl
= wxDynamicCast( wxFindControlFromMacControl(control
) , wxTextCtrl
) ;
2789 wxMacMLTEClassicControl
* win
= textCtrl
? (wxMacMLTEClassicControl
*)(textCtrl
->GetPeer()) : NULL
;
2791 return win
->MacControlUserPaneTrackingProc( startPt
.h
, startPt
.v
, (void*) actionProc
) ;
2793 return kControlNoPart
;
2796 static pascal void wxMacControlUserPaneIdleProc(ControlRef control
)
2798 wxTextCtrl
*textCtrl
= wxDynamicCast( wxFindControlFromMacControl(control
) , wxTextCtrl
) ;
2799 wxMacMLTEClassicControl
* win
= textCtrl
? (wxMacMLTEClassicControl
*)(textCtrl
->GetPeer()) : NULL
;
2801 win
->MacControlUserPaneIdleProc() ;
2804 static pascal ControlPartCode
wxMacControlUserPaneKeyDownProc(ControlRef control
, SInt16 keyCode
, SInt16 charCode
, SInt16 modifiers
)
2806 wxTextCtrl
*textCtrl
= wxDynamicCast( wxFindControlFromMacControl(control
) , wxTextCtrl
) ;
2807 wxMacMLTEClassicControl
* win
= textCtrl
? (wxMacMLTEClassicControl
*)(textCtrl
->GetPeer()) : NULL
;
2809 return win
->MacControlUserPaneKeyDownProc( keyCode
, charCode
, modifiers
) ;
2811 return kControlNoPart
;
2814 static pascal void wxMacControlUserPaneActivateProc(ControlRef control
, Boolean activating
)
2816 wxTextCtrl
*textCtrl
= wxDynamicCast( wxFindControlFromMacControl(control
) , wxTextCtrl
) ;
2817 wxMacMLTEClassicControl
* win
= textCtrl
? (wxMacMLTEClassicControl
*)(textCtrl
->GetPeer()) : NULL
;
2819 win
->MacControlUserPaneActivateProc( activating
) ;
2822 static pascal ControlPartCode
wxMacControlUserPaneFocusProc(ControlRef control
, ControlFocusPart action
)
2824 wxTextCtrl
*textCtrl
= wxDynamicCast( wxFindControlFromMacControl(control
) , wxTextCtrl
) ;
2825 wxMacMLTEClassicControl
* win
= textCtrl
? (wxMacMLTEClassicControl
*)(textCtrl
->GetPeer()) : NULL
;
2827 return win
->MacControlUserPaneFocusProc( action
) ;
2829 return kControlNoPart
;
2833 static pascal void wxMacControlUserPaneBackgroundProc(ControlRef control
, ControlBackgroundPtr info
)
2835 wxTextCtrl
*textCtrl
= wxDynamicCast( wxFindControlFromMacControl(control
) , wxTextCtrl
) ;
2836 wxMacMLTEClassicControl
* win
= textCtrl
? (wxMacMLTEClassicControl
*)(textCtrl
->GetPeer()) : NULL
;
2838 win
->MacControlUserPaneBackgroundProc(info
) ;
2842 #endif // __WXMAC_OSX__
2844 // TXNRegisterScrollInfoProc
2846 OSStatus
wxMacMLTEClassicControl::DoCreate()
2849 OSStatus err
= noErr
;
2851 // set up our globals
2852 #ifdef __WXMAC_OSX__
2853 if (gTPDrawProc
== NULL
) gTPDrawProc
= NewControlUserPaneDrawUPP(wxMacControlUserPaneDrawProc
);
2854 if (gTPHitProc
== NULL
) gTPHitProc
= NewControlUserPaneHitTestUPP(wxMacControlUserPaneHitTestProc
);
2855 if (gTPTrackProc
== NULL
) gTPTrackProc
= NewControlUserPaneTrackingUPP(wxMacControlUserPaneTrackingProc
);
2856 if (gTPIdleProc
== NULL
) gTPIdleProc
= NewControlUserPaneIdleUPP(wxMacControlUserPaneIdleProc
);
2857 if (gTPKeyProc
== NULL
) gTPKeyProc
= NewControlUserPaneKeyDownUPP(wxMacControlUserPaneKeyDownProc
);
2858 if (gTPActivateProc
== NULL
) gTPActivateProc
= NewControlUserPaneActivateUPP(wxMacControlUserPaneActivateProc
);
2859 if (gTPFocusProc
== NULL
) gTPFocusProc
= NewControlUserPaneFocusUPP(wxMacControlUserPaneFocusProc
);
2861 if (gTXNScrollInfoProc
== NULL
) gTXNScrollInfoProc
= NewTXNScrollInfoUPP(TXNScrollInfoProc
) ;
2862 if (gTXNScrollActionProc
== NULL
) gTXNScrollActionProc
= NewControlActionUPP(TXNScrollActionProc
) ;
2865 // set the initial settings for our private data
2867 m_txnWindow
= GetControlOwner(m_controlRef
);
2868 m_txnPort
= (GrafPtr
) GetWindowPort(m_txnWindow
);
2870 #ifdef __WXMAC_OSX__
2871 // set up the user pane procedures
2872 SetControlData(m_controlRef
, kControlEntireControl
, kControlUserPaneDrawProcTag
, sizeof(gTPDrawProc
), &gTPDrawProc
);
2873 SetControlData(m_controlRef
, kControlEntireControl
, kControlUserPaneHitTestProcTag
, sizeof(gTPHitProc
), &gTPHitProc
);
2874 SetControlData(m_controlRef
, kControlEntireControl
, kControlUserPaneTrackingProcTag
, sizeof(gTPTrackProc
), &gTPTrackProc
);
2875 SetControlData(m_controlRef
, kControlEntireControl
, kControlUserPaneIdleProcTag
, sizeof(gTPIdleProc
), &gTPIdleProc
);
2876 SetControlData(m_controlRef
, kControlEntireControl
, kControlUserPaneKeyDownProcTag
, sizeof(gTPKeyProc
), &gTPKeyProc
);
2877 SetControlData(m_controlRef
, kControlEntireControl
, kControlUserPaneActivateProcTag
, sizeof(gTPActivateProc
), &gTPActivateProc
);
2878 SetControlData(m_controlRef
, kControlEntireControl
, kControlUserPaneFocusProcTag
, sizeof(gTPFocusProc
), &gTPFocusProc
);
2881 // calculate the rectangles used by the control
2882 UMAGetControlBoundsInWindowCoords( m_controlRef
, &bounds
);
2884 m_txnControlBounds
= bounds
;
2885 m_txnVisBounds
= bounds
;
2890 GetGWorld( &origPort
, &origDev
) ;
2891 SetPort( m_txnPort
);
2893 // create the new edit field
2894 TXNFrameOptions frameOptions
= FrameOptionsFromWXStyle( m_windowStyle
);
2896 #ifdef __WXMAC_OSX__
2897 // the scrollbars are not correctly embedded but are inserted at the root:
2898 // this gives us problems as we have erratic redraws even over the structure area
2900 m_sbHorizontal
= 0 ;
2902 m_lastHorizontalValue
= 0 ;
2903 m_lastVerticalValue
= 0 ;
2905 Rect sb
= { 0 , 0 , 0 , 0 } ;
2906 if ( frameOptions
& kTXNWantVScrollBarMask
)
2908 CreateScrollBarControl( m_txnWindow
, &sb
, 0, 0, 100, 1, true, gTXNScrollActionProc
, &m_sbVertical
);
2909 SetControlReference( m_sbVertical
, (SInt32
)this );
2910 SetControlAction( m_sbVertical
, gTXNScrollActionProc
);
2911 ShowControl( m_sbVertical
);
2912 EmbedControl( m_sbVertical
, m_controlRef
);
2913 frameOptions
&= ~kTXNWantVScrollBarMask
;
2916 if ( frameOptions
& kTXNWantHScrollBarMask
)
2918 CreateScrollBarControl( m_txnWindow
, &sb
, 0, 0, 100, 1, true, gTXNScrollActionProc
, &m_sbHorizontal
);
2919 SetControlReference( m_sbHorizontal
, (SInt32
)this );
2920 SetControlAction( m_sbHorizontal
, gTXNScrollActionProc
);
2921 ShowControl( m_sbHorizontal
);
2922 EmbedControl( m_sbHorizontal
, m_controlRef
);
2923 frameOptions
&= ~(kTXNWantHScrollBarMask
| kTXNDrawGrowIconMask
);
2929 NULL
, m_txnWindow
, &bounds
, frameOptions
,
2930 kTXNTextEditStyleFrameType
, kTXNTextensionFile
, kTXNSystemDefaultEncoding
,
2931 &m_txn
, &m_txnFrameID
, NULL
);
2932 verify_noerr( err
);
2935 TXNControlTag iControlTags
[] = { kTXNUseCarbonEvents
};
2936 TXNControlData iControlData
[] = { { (UInt32
)&cInfo
} };
2937 int toptag
= WXSIZEOF( iControlTags
) ;
2938 TXNCarbonEventInfo cInfo
;
2939 cInfo
.useCarbonEvents
= false ;
2942 cInfo
.fDictionary
= NULL
;
2944 verify_noerr( TXNSetTXNObjectControls( m_txn
, false, toptag
, iControlTags
, iControlData
) );
2947 #ifdef __WXMAC_OSX__
2948 TXNRegisterScrollInfoProc( m_txn
, gTXNScrollInfoProc
, (SInt32
)this );
2951 SetGWorld( origPort
, origDev
) ;
2957 // ----------------------------------------------------------------------------
2958 // MLTE control implementation (OSX part)
2959 // ----------------------------------------------------------------------------
2961 #if TARGET_API_MAC_OSX
2963 #if MAC_OS_X_VERSION_MAX_ALLOWED > MAC_OS_X_VERSION_10_2
2965 // tiger multi-line textcontrols with no CR in the entire content
2966 // don't scroll automatically, so we need a hack.
2967 // This attempt only works 'before' the key (ie before CallNextEventHandler)
2968 // is processed, thus the scrolling always occurs one character too late, but
2969 // better than nothing ...
2971 static const EventTypeSpec eventList
[] =
2973 { kEventClassTextInput
, kEventTextInputUnicodeForKeyEvent
} ,
2976 static pascal OSStatus
wxMacUnicodeTextEventHandler( EventHandlerCallRef handler
, EventRef event
, void *data
)
2978 OSStatus result
= eventNotHandledErr
;
2979 wxMacMLTEHIViewControl
* focus
= (wxMacMLTEHIViewControl
*) data
;
2981 switch ( GetEventKind( event
) )
2983 case kEventTextInputUnicodeForKeyEvent
:
2985 if ( UMAGetSystemVersion() >= 0x1040 )
2987 TXNOffset from
, to
;
2988 TXNGetSelection( focus
->GetTXNObject() , &from
, &to
) ;
2990 TXNShowSelection( focus
->GetTXNObject() , kTXNShowStart
);
2992 result
= CallNextEventHandler(handler
,event
);
3002 static pascal OSStatus
wxMacTextControlEventHandler( EventHandlerCallRef handler
, EventRef event
, void *data
)
3004 OSStatus result
= eventNotHandledErr
;
3006 switch ( GetEventClass( event
) )
3008 case kEventClassTextInput
:
3009 result
= wxMacUnicodeTextEventHandler( handler
, event
, data
) ;
3018 DEFINE_ONE_SHOT_HANDLER_GETTER( wxMacTextControlEventHandler
)
3020 wxMacMLTEHIViewControl::wxMacMLTEHIViewControl( wxTextCtrl
*wxPeer
,
3021 const wxString
& str
,
3023 const wxSize
& size
, long style
) : wxMacMLTEControl( wxPeer
)
3025 m_font
= wxPeer
->GetFont() ;
3026 m_windowStyle
= style
;
3027 Rect bounds
= wxMacGetBoundsForControl( wxPeer
, pos
, size
) ;
3029 wxMacConvertNewlines10To13( &st
) ;
3032 { bounds
.left
, bounds
.top
},
3033 { bounds
.right
- bounds
.left
, bounds
.bottom
- bounds
.top
} } ;
3035 m_scrollView
= NULL
;
3036 TXNFrameOptions frameOptions
= FrameOptionsFromWXStyle( style
) ;
3037 if (( frameOptions
& (kTXNWantVScrollBarMask
| kTXNWantHScrollBarMask
)) || !(frameOptions
&kTXNSingleLineOnlyMask
))
3039 if ( frameOptions
& (kTXNWantVScrollBarMask
| kTXNWantHScrollBarMask
) )
3042 (frameOptions
& kTXNWantHScrollBarMask
? kHIScrollViewOptionsHorizScroll
: 0)
3043 | (frameOptions
& kTXNWantVScrollBarMask
? kHIScrollViewOptionsVertScroll
: 0) ,
3048 HIScrollViewCreate(kHIScrollViewOptionsVertScroll
,&m_scrollView
);
3049 HIScrollViewSetScrollBarAutoHide(m_scrollView
,true);
3052 HIViewSetFrame( m_scrollView
, &hr
);
3053 HIViewSetVisible( m_scrollView
, true );
3057 HITextViewCreate( NULL
, 0, frameOptions
, &m_textView
) ;
3058 m_txn
= HITextViewGetTXNObject( m_textView
) ;
3059 HIViewSetVisible( m_textView
, true ) ;
3062 HIViewAddSubview( m_scrollView
, m_textView
) ;
3063 m_controlRef
= m_scrollView
;
3064 wxPeer
->MacInstallEventHandler( (WXWidget
) m_textView
) ;
3068 HIViewSetFrame( m_textView
, &hr
);
3069 m_controlRef
= m_textView
;
3072 AdjustCreationAttributes( *wxWHITE
, true ) ;
3074 wxMacWindowClipper
c( m_peer
) ;
3076 SetTXNData( st
, kTXNStartOffset
, kTXNEndOffset
) ;
3078 TXNSetSelection( m_txn
, 0, 0 );
3079 TXNShowSelection( m_txn
, kTXNShowStart
);
3081 InstallControlEventHandler( m_textView
, GetwxMacTextControlEventHandlerUPP(),
3082 GetEventTypeCount(eventList
), eventList
, this,
3083 &m_textEventHandlerRef
);
3086 wxMacMLTEHIViewControl::~wxMacMLTEHIViewControl()
3088 ::RemoveEventHandler( m_textEventHandlerRef
) ;
3091 OSStatus
wxMacMLTEHIViewControl::SetFocus( ControlFocusPart focusPart
)
3093 return SetKeyboardFocus( GetControlOwner( m_textView
), m_textView
, focusPart
) ;
3096 bool wxMacMLTEHIViewControl::HasFocus() const
3098 ControlRef control
;
3099 GetKeyboardFocus( GetUserFocusWindow() , &control
) ;
3100 return control
== m_textView
;
3103 void wxMacMLTEHIViewControl::SetBackground( const wxBrush
&brush
)
3105 wxMacMLTEControl::SetBackground( brush
) ;
3108 CGColorSpaceRef rgbSpace
= CGColorSpaceCreateDeviceRGB();
3109 RGBColor col
= MAC_WXCOLORREF(brush
.GetColour().GetPixel()) ;
3111 float component
[4] ;
3112 component
[0] = col
.red
/ 65536.0 ;
3113 component
[1] = col
.green
/ 65536.0 ;
3114 component
[2] = col
.blue
/ 65536.0 ;
3115 component
[3] = 1.0 ; // alpha
3117 CGColorRef color
= CGColorCreate( rgbSpace
, component
);
3118 HITextViewSetBackgroundColor( m_textView
, color
);
3119 CGColorSpaceRelease( rgbSpace
);
3123 #endif // MAC_OS_X_VERSION_MAX_ALLOWED > MAC_OS_X_VERSION_10_2
3128 #endif // wxUSE_TEXTCTRL