1 /////////////////////////////////////////////////////////////////////////////
4 // Author: Stefan Csomor
5 // Modified by: Ryan Norton (MLTE GetLineLength and GetLineText)
8 // Copyright: (c) Stefan Csomor
9 // Licence: wxWindows licence
10 /////////////////////////////////////////////////////////////////////////////
12 #include "wx/wxprec.h"
18 #include <sys/types.h>
24 #include "wx/msgdlg.h"
26 #if wxUSE_STD_IOSTREAM
36 #include "wx/button.h"
37 #include "wx/toplevel.h"
38 #include "wx/textctrl.h"
39 #include "wx/settings.h"
40 #include "wx/filefn.h"
42 #include "wx/sysopt.h"
46 #if defined(__BORLANDC__) && !defined(__WIN32__)
48 #elif !defined(__MWERKS__) && !defined(__GNUWIN32) && !defined(__DARWIN__)
57 #include <MacTextEditor.h>
58 #include <ATSUnicode.h>
59 #include <TextCommon.h>
60 #include <TextEncodingConverter.h>
63 #include "wx/mac/uma.h"
66 // if this is set to 1 then under OSX 10.2 the 'classic' MLTE implementation will be used
67 // if set to 0 then the unicode textctrl will be used
68 #ifndef wxMAC_AWAYS_USE_MLTE
69 #define wxMAC_AWAYS_USE_MLTE 1
75 kTXNVisibilityTag
= 'visb' // set the visibility state of the object
84 virtual ~wxMacFunctor() {}
86 virtual void* operator()() = 0 ;
88 static void* CallBackProc( void *param
)
90 wxMacFunctor
* f
= (wxMacFunctor
*) param
;
91 void *result
= (*f
)() ;
96 template<typename classtype
, typename param1type
>
98 class wxMacObjectFunctor1
: public wxMacFunctor
100 typedef void (classtype::*function
)( param1type p1
) ;
101 typedef void (classtype::*ref_function
)( const param1type
& p1
) ;
103 wxMacObjectFunctor1( classtype
*obj
, function f
, param1type p1
) :
111 wxMacObjectFunctor1( classtype
*obj
, ref_function f
, param1type p1
) :
119 ~wxMacObjectFunctor1() {}
121 virtual void* operator()()
123 (m_object
->*m_function
)( m_param1
) ;
128 classtype
* m_object
;
129 param1type m_param1
;
132 function m_function
;
133 ref_function m_refFunction
;
137 template<typename classtype
, typename param1type
>
138 void* wxMacMPRemoteCall( classtype
*object
, void (classtype::*function
)( param1type p1
) , param1type p1
)
140 wxMacObjectFunctor1
<classtype
, param1type
> params(object
, function
, p1
) ;
142 MPRemoteCall( wxMacFunctor::CallBackProc
, ¶ms
, kMPOwningProcessRemoteContext
) ;
146 template<typename classtype
, typename param1type
>
147 void* wxMacMPRemoteCall( classtype
*object
, void (classtype::*function
)( const param1type
& p1
) , param1type p1
)
149 wxMacObjectFunctor1
<classtype
,param1type
> params(object
, function
, p1
) ;
151 MPRemoteCall( wxMacFunctor::CallBackProc
, ¶ms
, kMPOwningProcessRemoteContext
) ;
155 template<typename classtype
, typename param1type
>
156 void* wxMacMPRemoteGUICall( classtype
*object
, void (classtype::*function
)( param1type p1
) , param1type p1
)
159 void *result
= wxMacMPRemoteCall( object
, function
, p1
) ;
164 template<typename classtype
, typename param1type
>
165 void* wxMacMPRemoteGUICall( classtype
*object
, void (classtype::*function
)( const param1type
& p1
) , param1type p1
)
168 void *result
= wxMacMPRemoteCall( object
, function
, p1
) ;
173 // common interface for all implementations
174 class wxMacTextControl
: public wxMacControl
177 wxMacTextControl( wxTextCtrl
*peer
) ;
178 ~wxMacTextControl() ;
180 virtual wxString
GetStringValue() const = 0 ;
181 virtual void SetStringValue( const wxString
&val
) = 0 ;
182 virtual void SetSelection( long from
, long to
) = 0 ;
183 virtual void GetSelection( long* from
, long* to
) const = 0 ;
184 virtual void WriteText( const wxString
& str
) = 0 ;
186 virtual void SetStyle( long start
, long end
, const wxTextAttr
& style
) ;
187 virtual void Copy() ;
189 virtual void Paste() ;
190 virtual bool CanPaste() const ;
191 virtual void SetEditable( bool editable
) ;
192 virtual wxTextPos
GetLastPosition() const ;
193 virtual void Replace( long from
, long to
, const wxString
&str
) ;
194 virtual void Remove( long from
, long to
) ;
197 virtual bool HasOwnContextMenu() const
200 virtual bool SetupCursor( const wxPoint
& pt
)
203 virtual void Clear() ;
204 virtual bool CanUndo() const;
205 virtual void Undo() ;
206 virtual bool CanRedo() const;
207 virtual void Redo() ;
208 virtual int GetNumberOfLines() const ;
209 virtual long XYToPosition(long x
, long y
) const;
210 virtual bool PositionToXY(long pos
, long *x
, long *y
) const ;
211 virtual void ShowPosition(long WXUNUSED(pos
)) ;
212 virtual int GetLineLength(long lineNo
) const ;
213 virtual wxString
GetLineText(long lineNo
) const ;
215 #ifndef __WXMAC_OSX__
216 virtual void MacControlUserPaneDrawProc(wxInt16 part
) = 0 ;
217 virtual wxInt16
MacControlUserPaneHitTestProc(wxInt16 x
, wxInt16 y
) = 0 ;
218 virtual wxInt16
MacControlUserPaneTrackingProc(wxInt16 x
, wxInt16 y
, void* actionProc
) = 0 ;
219 virtual void MacControlUserPaneIdleProc() = 0 ;
220 virtual wxInt16
MacControlUserPaneKeyDownProc(wxInt16 keyCode
, wxInt16 charCode
, wxInt16 modifiers
) = 0 ;
221 virtual void MacControlUserPaneActivateProc(bool activating
) = 0 ;
222 virtual wxInt16
MacControlUserPaneFocusProc(wxInt16 action
) = 0 ;
223 virtual void MacControlUserPaneBackgroundProc(void* info
) = 0 ;
227 // common parts for implementations based on MLTE
229 class wxMacMLTEControl
: public wxMacTextControl
232 wxMacMLTEControl( wxTextCtrl
*peer
) ;
234 virtual wxString
GetStringValue() const ;
235 virtual void SetStringValue( const wxString
&str
) ;
237 static TXNFrameOptions
FrameOptionsFromWXStyle( long wxStyle
) ;
239 void AdjustCreationAttributes( const wxColour
& background
, bool visible
) ;
241 virtual void SetFont( const wxFont
& font
, const wxColour
& foreground
, long windowStyle
) ;
242 virtual void SetBackground( const wxBrush
&brush
) ;
243 virtual void SetStyle( long start
, long end
, const wxTextAttr
& style
) ;
244 virtual void Copy() ;
246 virtual void Paste() ;
247 virtual bool CanPaste() const ;
248 virtual void SetEditable( bool editable
) ;
249 virtual wxTextPos
GetLastPosition() const ;
250 virtual void Replace( long from
, long to
, const wxString
&str
) ;
251 virtual void Remove( long from
, long to
) ;
252 virtual void GetSelection( long* from
, long* to
) const ;
253 virtual void SetSelection( long from
, long to
) ;
255 virtual void WriteText( const wxString
& str
) ;
257 virtual bool HasOwnContextMenu() const
259 #if MAC_OS_X_VERSION_MAX_ALLOWED >= MAC_OS_X_VERSION_10_4
260 if ( UMAGetSystemVersion() >= 0x1040 )
262 TXNCommandEventSupportOptions options
;
263 TXNGetCommandEventSupport( m_txn
, & options
) ;
264 return options
& kTXNSupportEditCommandProcessing
;
271 virtual void Clear() ;
273 virtual bool CanUndo() const ;
274 virtual void Undo() ;
275 virtual bool CanRedo() const;
276 virtual void Redo() ;
277 virtual int GetNumberOfLines() const ;
278 virtual long XYToPosition(long x
, long y
) const ;
279 virtual bool PositionToXY(long pos
, long *x
, long *y
) const ;
280 virtual void ShowPosition( long pos
) ;
281 virtual int GetLineLength(long lineNo
) const ;
282 virtual wxString
GetLineText(long lineNo
) const ;
284 void SetTXNData( const wxString
& st
, TXNOffset start
, TXNOffset end
) ;
287 void TXNSetAttribute( const wxTextAttr
& style
, long from
, long to
) ;
292 #if TARGET_API_MAC_OSX
294 // implementation available under OSX
296 #if MAC_OS_X_VERSION_MAX_ALLOWED > MAC_OS_X_VERSION_10_2
298 class wxMacMLTEHIViewControl
: public wxMacMLTEControl
301 wxMacMLTEHIViewControl( wxTextCtrl
*wxPeer
,
304 const wxSize
& size
, long style
) ;
305 virtual OSStatus
SetFocus( ControlFocusPart focusPart
) ;
306 virtual bool HasFocus() const ;
307 virtual void SetBackground( const wxBrush
&brush
) ;
310 HIViewRef m_scrollView
;
311 HIViewRef m_textView
;
316 class wxMacUnicodeTextControl
: public wxMacTextControl
319 wxMacUnicodeTextControl( wxTextCtrl
*wxPeer
,
322 const wxSize
& size
, long style
) ;
323 ~wxMacUnicodeTextControl();
325 virtual void VisibilityChanged(bool shown
);
326 virtual wxString
GetStringValue() const ;
327 virtual void SetStringValue( const wxString
&str
) ;
330 virtual void Paste();
331 virtual bool CanPaste() const;
332 virtual void SetEditable(bool editable
) ;
333 virtual void GetSelection( long* from
, long* to
) const ;
334 virtual void SetSelection( long from
, long to
) ;
335 virtual void WriteText(const wxString
& str
) ;
338 // contains the tag for the content (is different for password and non-password controls)
344 // 'classic' MLTE implementation
346 class wxMacMLTEClassicControl
: public wxMacMLTEControl
349 wxMacMLTEClassicControl( wxTextCtrl
*wxPeer
,
352 const wxSize
& size
, long style
) ;
353 ~wxMacMLTEClassicControl() ;
355 virtual void VisibilityChanged(bool shown
) ;
356 virtual void SuperChangedPosition() ;
358 virtual void MacControlUserPaneDrawProc(wxInt16 part
) ;
359 virtual wxInt16
MacControlUserPaneHitTestProc(wxInt16 x
, wxInt16 y
) ;
360 virtual wxInt16
MacControlUserPaneTrackingProc(wxInt16 x
, wxInt16 y
, void* actionProc
) ;
361 virtual void MacControlUserPaneIdleProc() ;
362 virtual wxInt16
MacControlUserPaneKeyDownProc(wxInt16 keyCode
, wxInt16 charCode
, wxInt16 modifiers
) ;
363 virtual void MacControlUserPaneActivateProc(bool activating
) ;
364 virtual wxInt16
MacControlUserPaneFocusProc(wxInt16 action
) ;
365 virtual void MacControlUserPaneBackgroundProc(void* info
) ;
367 virtual bool SetupCursor( const wxPoint
& WXUNUSED(pt
) )
369 MacControlUserPaneIdleProc();
373 virtual void SetRect( Rect
*r
) ;
378 void MacUpdatePosition() ;
379 void MacActivatePaneText(bool setActive
) ;
380 void MacFocusPaneText(bool setFocus
) ;
381 void MacSetObjectVisibility(bool vis
) ;
384 TXNFrameID m_txnFrameID
;
386 WindowRef m_txnWindow
;
387 // bounds of the control as we last did set the txn frames
388 Rect m_txnControlBounds
;
389 Rect m_txnVisBounds
;
392 static pascal void TXNScrollActionProc( ControlRef controlRef
, ControlPartCode partCode
) ;
393 static pascal void TXNScrollInfoProc(
394 SInt32 iValue
, SInt32 iMaximumValue
,
395 TXNScrollBarOrientation iScrollBarOrientation
, SInt32 iRefCon
) ;
397 ControlRef m_sbHorizontal
;
398 SInt32 m_lastHorizontalValue
;
399 ControlRef m_sbVertical
;
400 SInt32 m_lastVerticalValue
;
404 #define TE_UNLIMITED_LENGTH 0xFFFFFFFFUL
407 IMPLEMENT_DYNAMIC_CLASS(wxTextCtrl
, wxControl
)
409 BEGIN_EVENT_TABLE(wxTextCtrl
, wxControl
)
410 EVT_ERASE_BACKGROUND( wxTextCtrl::OnEraseBackground
)
411 EVT_DROP_FILES(wxTextCtrl::OnDropFiles
)
412 EVT_CHAR(wxTextCtrl::OnChar
)
413 EVT_MENU(wxID_CUT
, wxTextCtrl::OnCut
)
414 EVT_MENU(wxID_COPY
, wxTextCtrl::OnCopy
)
415 EVT_MENU(wxID_PASTE
, wxTextCtrl::OnPaste
)
416 EVT_MENU(wxID_UNDO
, wxTextCtrl::OnUndo
)
417 EVT_MENU(wxID_REDO
, wxTextCtrl::OnRedo
)
418 EVT_MENU(wxID_CLEAR
, wxTextCtrl::OnDelete
)
419 EVT_MENU(wxID_SELECTALL
, wxTextCtrl::OnSelectAll
)
421 EVT_CONTEXT_MENU(wxTextCtrl::OnContextMenu
)
423 EVT_UPDATE_UI(wxID_CUT
, wxTextCtrl::OnUpdateCut
)
424 EVT_UPDATE_UI(wxID_COPY
, wxTextCtrl::OnUpdateCopy
)
425 EVT_UPDATE_UI(wxID_PASTE
, wxTextCtrl::OnUpdatePaste
)
426 EVT_UPDATE_UI(wxID_UNDO
, wxTextCtrl::OnUpdateUndo
)
427 EVT_UPDATE_UI(wxID_REDO
, wxTextCtrl::OnUpdateRedo
)
428 EVT_UPDATE_UI(wxID_CLEAR
, wxTextCtrl::OnUpdateDelete
)
429 EVT_UPDATE_UI(wxID_SELECTALL
, wxTextCtrl::OnUpdateSelectAll
)
433 void wxTextCtrl::Init()
438 m_maxLength
= TE_UNLIMITED_LENGTH
;
439 m_privateContextMenu
= NULL
;
442 wxTextCtrl::~wxTextCtrl()
444 delete m_privateContextMenu
;
447 bool wxTextCtrl::Create( wxWindow
*parent
,
453 const wxValidator
& validator
,
454 const wxString
& name
)
456 m_macIsUserPane
= false ;
459 if ( ! (style
& wxNO_BORDER
) )
460 style
= (style
& ~wxBORDER_MASK
) | wxSUNKEN_BORDER
;
462 if ( !wxTextCtrlBase::Create( parent
, id
, pos
, size
, style
& ~(wxHSCROLL
| wxVSCROLL
), validator
, name
) )
465 if ( m_windowStyle
& wxTE_MULTILINE
)
468 !(m_windowStyle
& wxTE_PROCESS_ENTER
),
469 wxT("wxTE_PROCESS_ENTER style is ignored for multiline text controls (they always process it)") );
471 m_windowStyle
|= wxTE_PROCESS_ENTER
;
472 style
|= wxTE_PROCESS_ENTER
;
475 bool forceMLTE
= false ;
477 #if wxUSE_SYSTEM_OPTIONS
478 if (wxSystemOptions::HasOption( wxMAC_TEXTCONTROL_USE_MLTE
) && (wxSystemOptions::GetOptionInt( wxMAC_TEXTCONTROL_USE_MLTE
) == 1))
485 #if MAC_OS_X_VERSION_MAX_ALLOWED > MAC_OS_X_VERSION_10_2
486 if ( UMAGetSystemVersion() >= 0x1030 && !forceMLTE
)
488 if ( m_windowStyle
& wxTE_MULTILINE
)
489 m_peer
= new wxMacMLTEHIViewControl( this , str
, pos
, size
, style
) ;
495 if ( !(m_windowStyle
& wxTE_MULTILINE
) && !forceMLTE
)
496 m_peer
= new wxMacUnicodeTextControl( this , str
, pos
, size
, style
) ;
501 m_peer
= new wxMacMLTEClassicControl( this , str
, pos
, size
, style
) ;
503 MacPostControlCreate(pos
, size
) ;
505 // only now the embedding is correct and we can do a positioning update
507 MacSuperChangedPosition() ;
509 if ( m_windowStyle
& wxTE_READONLY
)
510 SetEditable( false ) ;
512 SetCursor( wxCursor( wxCURSOR_IBEAM
) ) ;
517 void wxTextCtrl::MacSuperChangedPosition()
519 wxWindow::MacSuperChangedPosition() ;
520 GetPeer()->SuperChangedPosition() ;
523 void wxTextCtrl::MacVisibilityChanged()
525 GetPeer()->VisibilityChanged( MacIsReallyShown() ) ;
528 void wxTextCtrl::MacEnabledStateChanged()
532 wxString
wxTextCtrl::GetValue() const
534 return GetPeer()->GetStringValue() ;
537 void wxTextCtrl::GetSelection(long* from
, long* to
) const
539 GetPeer()->GetSelection( from
, to
) ;
542 void wxTextCtrl::SetValue(const wxString
& str
)
545 if ( GetValue() == str
)
548 GetPeer()->SetStringValue( str
) ;
550 wxCommandEvent
event( wxEVT_COMMAND_TEXT_UPDATED
, m_windowId
);
551 event
.SetString( GetValue() );
552 event
.SetEventObject( this );
553 GetEventHandler()->ProcessEvent( event
);
556 void wxTextCtrl::SetMaxLength(unsigned long len
)
561 bool wxTextCtrl::SetFont( const wxFont
& font
)
563 if ( !wxTextCtrlBase::SetFont( font
) )
566 GetPeer()->SetFont( font
, GetForegroundColour() , GetWindowStyle() ) ;
571 bool wxTextCtrl::SetStyle(long start
, long end
, const wxTextAttr
& style
)
573 GetPeer()->SetStyle( start
, end
, style
) ;
578 bool wxTextCtrl::SetDefaultStyle(const wxTextAttr
& style
)
580 wxTextCtrlBase::SetDefaultStyle( style
) ;
581 SetStyle( kTXNUseCurrentSelection
, kTXNUseCurrentSelection
, GetDefaultStyle() ) ;
586 // Clipboard operations
588 void wxTextCtrl::Copy()
594 void wxTextCtrl::Cut()
600 wxCommandEvent
event( wxEVT_COMMAND_TEXT_UPDATED
, m_windowId
);
601 event
.SetEventObject( this );
602 GetEventHandler()->ProcessEvent( event
);
606 void wxTextCtrl::Paste()
612 // TODO: eventually we should add setting the default style again
614 wxCommandEvent
event( wxEVT_COMMAND_TEXT_UPDATED
, m_windowId
);
615 event
.SetEventObject( this );
616 GetEventHandler()->ProcessEvent( event
);
620 bool wxTextCtrl::CanCopy() const
622 // Can copy if there's a selection
624 GetSelection( &from
, &to
);
629 bool wxTextCtrl::CanCut() const
634 // Can cut if there's a selection
636 GetSelection( &from
, &to
);
641 bool wxTextCtrl::CanPaste() const
646 return GetPeer()->CanPaste() ;
649 void wxTextCtrl::SetEditable(bool editable
)
651 if ( editable
!= m_editable
)
653 m_editable
= editable
;
654 GetPeer()->SetEditable( editable
) ;
658 void wxTextCtrl::SetInsertionPoint(long pos
)
660 SetSelection( pos
, pos
) ;
663 void wxTextCtrl::SetInsertionPointEnd()
665 wxTextPos pos
= GetLastPosition();
666 SetInsertionPoint( pos
);
669 long wxTextCtrl::GetInsertionPoint() const
672 GetSelection( &begin
, &end
) ;
677 wxTextPos
wxTextCtrl::GetLastPosition() const
679 return GetPeer()->GetLastPosition() ;
682 void wxTextCtrl::Replace(long from
, long to
, const wxString
& str
)
684 GetPeer()->Replace( from
, to
, str
) ;
687 void wxTextCtrl::Remove(long from
, long to
)
689 GetPeer()->Remove( from
, to
) ;
692 void wxTextCtrl::SetSelection(long from
, long to
)
694 GetPeer()->SetSelection( from
, to
) ;
697 bool wxTextCtrl::LoadFile(const wxString
& file
)
699 return wxTextCtrlBase::LoadFile( file
);
702 void wxTextCtrl::WriteText(const wxString
& str
)
704 // TODO: this MPRemoting will be moved into a remoting peer proxy for any command
705 if ( !wxIsMainThread() )
707 // unfortunately CW 8 is not able to correctly deduce the template types,
708 // so we have to instantiate explicitly
709 wxMacMPRemoteGUICall
<wxTextCtrl
,wxString
>( this , &wxTextCtrl::WriteText
, str
) ;
714 GetPeer()->WriteText( str
) ;
717 void wxTextCtrl::AppendText(const wxString
& text
)
719 SetInsertionPointEnd();
723 void wxTextCtrl::Clear()
728 bool wxTextCtrl::IsModified() const
733 bool wxTextCtrl::IsEditable() const
735 return IsEnabled() && m_editable
;
738 bool wxTextCtrl::AcceptsFocus() const
740 // we don't want focus if we can't be edited
741 return /*IsEditable() && */ wxControl::AcceptsFocus();
744 wxSize
wxTextCtrl::DoGetBestSize() const
748 // these are the numbers from the HIG:
749 // we reduce them by the borders first
752 switch ( m_windowVariant
)
754 case wxWINDOW_VARIANT_NORMAL
:
758 case wxWINDOW_VARIANT_SMALL
:
762 case wxWINDOW_VARIANT_MINI
:
771 // as the above numbers have some free space around the text
772 // we get 5 lines like this anyway
773 if ( m_windowStyle
& wxTE_MULTILINE
)
776 if ( !HasFlag(wxNO_BORDER
) )
779 return wxSize(wText
, hText
);
782 // ----------------------------------------------------------------------------
784 // ----------------------------------------------------------------------------
786 void wxTextCtrl::Undo()
792 void wxTextCtrl::Redo()
798 bool wxTextCtrl::CanUndo() const
803 return GetPeer()->CanUndo() ;
806 bool wxTextCtrl::CanRedo() const
811 return GetPeer()->CanRedo() ;
814 void wxTextCtrl::MarkDirty()
819 void wxTextCtrl::DiscardEdits()
824 int wxTextCtrl::GetNumberOfLines() const
826 return GetPeer()->GetNumberOfLines() ;
829 long wxTextCtrl::XYToPosition(long x
, long y
) const
831 return GetPeer()->XYToPosition( x
, y
) ;
834 bool wxTextCtrl::PositionToXY(long pos
, long *x
, long *y
) const
836 return GetPeer()->PositionToXY( pos
, x
, y
) ;
839 void wxTextCtrl::ShowPosition(long pos
)
841 return GetPeer()->ShowPosition(pos
) ;
844 int wxTextCtrl::GetLineLength(long lineNo
) const
846 return GetPeer()->GetLineLength(lineNo
) ;
849 wxString
wxTextCtrl::GetLineText(long lineNo
) const
851 return GetPeer()->GetLineText(lineNo
) ;
854 void wxTextCtrl::Command(wxCommandEvent
& event
)
856 SetValue(event
.GetString());
857 ProcessCommand(event
);
860 void wxTextCtrl::OnDropFiles(wxDropFilesEvent
& event
)
862 // By default, load the first file into the text window.
863 if (event
.GetNumberOfFiles() > 0)
864 LoadFile( event
.GetFiles()[0] );
867 void wxTextCtrl::OnEraseBackground(wxEraseEvent
& event
)
869 // all erasing should be done by the real mac control implementation
870 // while this is true for MLTE under classic, the HITextView is somehow
871 // transparent but background erase is not working correctly, so intercept
872 // things while we can...
876 void wxTextCtrl::OnChar(wxKeyEvent
& event
)
878 int key
= event
.GetKeyCode() ;
879 bool eat_key
= false ;
881 if ( key
== 'c' && event
.MetaDown() )
889 if ( !IsEditable() && key
!= WXK_LEFT
&& key
!= WXK_RIGHT
&& key
!= WXK_DOWN
&& key
!= WXK_UP
&& key
!= WXK_TAB
&&
890 !( key
== WXK_RETURN
&& ( (m_windowStyle
& wxPROCESS_ENTER
) || (m_windowStyle
& wxTE_MULTILINE
) ) )
891 // && key != WXK_PRIOR && key != WXK_NEXT && key != WXK_HOME && key != WXK_END
898 // Check if we have reached the max # of chars, but still allow navigation and deletion
899 if ( !IsMultiLine() && GetValue().Length() >= m_maxLength
&&
900 key
!= WXK_LEFT
&& key
!= WXK_RIGHT
&& key
!= WXK_TAB
&&
901 key
!= WXK_BACK
&& !( key
== WXK_RETURN
&& (m_windowStyle
& wxPROCESS_ENTER
) )
904 // eat it, we don't want to add more than allowed # of characters
908 // assume that any key not processed yet is going to modify the control
911 if ( key
== 'v' && event
.MetaDown() )
919 if ( key
== 'x' && event
.MetaDown() )
930 if (m_windowStyle
& wxPROCESS_ENTER
)
932 wxCommandEvent
event(wxEVT_COMMAND_TEXT_ENTER
, m_windowId
);
933 event
.SetEventObject( this );
934 event
.SetString( GetValue() );
935 if ( GetEventHandler()->ProcessEvent(event
) )
939 if ( !(m_windowStyle
& wxTE_MULTILINE
) )
941 wxWindow
*parent
= GetParent();
942 while ( parent
&& !parent
->IsTopLevel() && parent
->GetDefaultItem() == NULL
)
944 parent
= parent
->GetParent() ;
947 if ( parent
&& parent
->GetDefaultItem() )
949 wxButton
*def
= wxDynamicCast(parent
->GetDefaultItem(), wxButton
);
950 if ( def
&& def
->IsEnabled() )
952 wxCommandEvent
event(wxEVT_COMMAND_BUTTON_CLICKED
, def
->GetId() );
953 event
.SetEventObject(def
);
960 // this will make wxWidgets eat the ENTER key so that
961 // we actually prevent line wrapping in a single line text control
967 if ( !(m_windowStyle
& wxTE_PROCESS_TAB
))
970 if (!event
.ShiftDown())
971 flags
|= wxNavigationKeyEvent::IsForward
;
972 if (event
.ControlDown())
973 flags
|= wxNavigationKeyEvent::WinChange
;
980 // This is necessary (don't know why);
981 // otherwise the tab will not be inserted.
982 WriteText(wxT("\t"));
992 // perform keystroke handling
993 if ( wxTheApp
->MacGetCurrentEvent() != NULL
&& wxTheApp
->MacGetCurrentEventHandlerCallRef() != NULL
)
995 CallNextEventHandler( (EventHandlerCallRef
)wxTheApp
->MacGetCurrentEventHandlerCallRef(), (EventRef
)wxTheApp
->MacGetCurrentEvent() ) ;
1000 if ( wxMacConvertEventToRecord( (EventRef
) wxTheApp
->MacGetCurrentEvent() , &rec
) )
1002 short keycode
, keychar
;
1003 EventRecord
*ev
= &rec
;
1004 keychar
= short(ev
->message
& charCodeMask
);
1005 keycode
= short(ev
->message
& keyCodeMask
) >> 8 ;
1007 m_peer
->HandleKey( keycode
, keychar
, ev
->modifiers
) ;
1012 if ( ( key
>= 0x20 && key
< WXK_START
) ||
1013 key
== WXK_RETURN
||
1014 key
== WXK_DELETE
||
1017 wxCommandEvent
event1(wxEVT_COMMAND_TEXT_UPDATED
, m_windowId
);
1018 event1
.SetEventObject( this );
1019 wxPostEvent( GetEventHandler(), event1
);
1023 // ----------------------------------------------------------------------------
1024 // standard handlers for standard edit menu events
1025 // ----------------------------------------------------------------------------
1027 void wxTextCtrl::OnCut(wxCommandEvent
& WXUNUSED(event
))
1032 void wxTextCtrl::OnCopy(wxCommandEvent
& WXUNUSED(event
))
1037 void wxTextCtrl::OnPaste(wxCommandEvent
& WXUNUSED(event
))
1042 void wxTextCtrl::OnUndo(wxCommandEvent
& WXUNUSED(event
))
1047 void wxTextCtrl::OnRedo(wxCommandEvent
& WXUNUSED(event
))
1052 void wxTextCtrl::OnDelete(wxCommandEvent
& WXUNUSED(event
))
1056 GetSelection( &from
, &to
);
1057 if (from
!= -1 && to
!= -1)
1061 void wxTextCtrl::OnSelectAll(wxCommandEvent
& WXUNUSED(event
))
1063 SetSelection(-1, -1);
1066 void wxTextCtrl::OnUpdateCut(wxUpdateUIEvent
& event
)
1068 event
.Enable( CanCut() );
1071 void wxTextCtrl::OnUpdateCopy(wxUpdateUIEvent
& event
)
1073 event
.Enable( CanCopy() );
1076 void wxTextCtrl::OnUpdatePaste(wxUpdateUIEvent
& event
)
1078 event
.Enable( CanPaste() );
1081 void wxTextCtrl::OnUpdateUndo(wxUpdateUIEvent
& event
)
1083 event
.Enable( CanUndo() );
1086 void wxTextCtrl::OnUpdateRedo(wxUpdateUIEvent
& event
)
1088 event
.Enable( CanRedo() );
1091 void wxTextCtrl::OnUpdateDelete(wxUpdateUIEvent
& event
)
1095 GetSelection( &from
, &to
);
1096 event
.Enable( from
!= -1 && to
!= -1 && from
!= to
&& IsEditable() ) ;
1099 void wxTextCtrl::OnUpdateSelectAll(wxUpdateUIEvent
& event
)
1101 event
.Enable(GetLastPosition() > 0);
1104 // CS: Context Menus only work with MLTE implementations or non-multiline HIViews at the moment
1106 void wxTextCtrl::OnContextMenu(wxContextMenuEvent
& event
)
1108 if ( GetPeer()->HasOwnContextMenu() )
1114 if (m_privateContextMenu
== NULL
)
1116 m_privateContextMenu
= new wxMenu
;
1117 m_privateContextMenu
->Append(wxID_UNDO
, _("&Undo"));
1118 m_privateContextMenu
->Append(wxID_REDO
, _("&Redo"));
1119 m_privateContextMenu
->AppendSeparator();
1120 m_privateContextMenu
->Append(wxID_CUT
, _("Cu&t"));
1121 m_privateContextMenu
->Append(wxID_COPY
, _("&Copy"));
1122 m_privateContextMenu
->Append(wxID_PASTE
, _("&Paste"));
1123 m_privateContextMenu
->Append(wxID_CLEAR
, _("&Delete"));
1124 m_privateContextMenu
->AppendSeparator();
1125 m_privateContextMenu
->Append(wxID_SELECTALL
, _("Select &All"));
1128 if (m_privateContextMenu
!= NULL
)
1129 PopupMenu(m_privateContextMenu
);
1132 bool wxTextCtrl::MacSetupCursor( const wxPoint
& pt
)
1134 if ( !GetPeer()->SetupCursor( pt
) )
1135 return wxWindow::MacSetupCursor( pt
) ;
1140 #if !TARGET_API_MAC_OSX
1142 // user pane implementation
1144 void wxTextCtrl::MacControlUserPaneDrawProc(wxInt16 part
)
1146 GetPeer()->MacControlUserPaneDrawProc( part
) ;
1149 wxInt16
wxTextCtrl::MacControlUserPaneHitTestProc(wxInt16 x
, wxInt16 y
)
1151 return GetPeer()->MacControlUserPaneHitTestProc( x
, y
) ;
1154 wxInt16
wxTextCtrl::MacControlUserPaneTrackingProc(wxInt16 x
, wxInt16 y
, void* actionProc
)
1156 return GetPeer()->MacControlUserPaneTrackingProc( x
, y
, actionProc
) ;
1159 void wxTextCtrl::MacControlUserPaneIdleProc()
1161 GetPeer()->MacControlUserPaneIdleProc( ) ;
1164 wxInt16
wxTextCtrl::MacControlUserPaneKeyDownProc(wxInt16 keyCode
, wxInt16 charCode
, wxInt16 modifiers
)
1166 return GetPeer()->MacControlUserPaneKeyDownProc( keyCode
, charCode
, modifiers
) ;
1169 void wxTextCtrl::MacControlUserPaneActivateProc(bool activating
)
1171 GetPeer()->MacControlUserPaneActivateProc( activating
) ;
1174 wxInt16
wxTextCtrl::MacControlUserPaneFocusProc(wxInt16 action
)
1176 return GetPeer()->MacControlUserPaneFocusProc( action
) ;
1179 void wxTextCtrl::MacControlUserPaneBackgroundProc(void* info
)
1181 GetPeer()->MacControlUserPaneBackgroundProc( info
) ;
1186 // ----------------------------------------------------------------------------
1187 // implementation base class
1188 // ----------------------------------------------------------------------------
1190 wxMacTextControl::wxMacTextControl(wxTextCtrl
* peer
) :
1191 wxMacControl( peer
)
1195 wxMacTextControl::~wxMacTextControl()
1199 void wxMacTextControl::SetStyle(long start
, long end
, const wxTextAttr
& style
)
1203 void wxMacTextControl::Copy()
1207 void wxMacTextControl::Cut()
1211 void wxMacTextControl::Paste()
1215 bool wxMacTextControl::CanPaste() const
1220 void wxMacTextControl::SetEditable(bool editable
)
1224 wxTextPos
wxMacTextControl::GetLastPosition() const
1226 return GetStringValue().Length() ;
1229 void wxMacTextControl::Replace( long from
, long to
, const wxString
&val
)
1231 SetSelection( from
, to
) ;
1235 void wxMacTextControl::Remove( long from
, long to
)
1237 SetSelection( from
, to
) ;
1238 WriteText( wxEmptyString
) ;
1241 void wxMacTextControl::Clear()
1243 SetStringValue( wxEmptyString
) ;
1246 bool wxMacTextControl::CanUndo() const
1251 void wxMacTextControl::Undo()
1255 bool wxMacTextControl::CanRedo() const
1260 void wxMacTextControl::Redo()
1264 long wxMacTextControl::XYToPosition(long x
, long y
) const
1269 bool wxMacTextControl::PositionToXY(long pos
, long *x
, long *y
) const
1274 void wxMacTextControl::ShowPosition( long WXUNUSED(pos
) )
1278 int wxMacTextControl::GetNumberOfLines() const
1280 ItemCount lines
= 0 ;
1281 wxString content
= GetStringValue() ;
1284 for (size_t i
= 0; i
< content
.Length() ; i
++)
1286 if (content
[i
] == '\r')
1293 wxString
wxMacTextControl::GetLineText(long lineNo
) const
1295 // TODO: change this if possible to reflect real lines
1296 wxString content
= GetStringValue() ;
1300 for (size_t i
= 0; i
< content
.Length() ; i
++)
1302 if (count
== lineNo
)
1304 // Add chars in line then
1307 for (size_t j
= i
; j
< content
.Length(); j
++)
1309 if (content
[j
] == '\n')
1318 if (content
[i
] == '\n')
1322 return wxEmptyString
;
1325 int wxMacTextControl::GetLineLength(long lineNo
) const
1327 // TODO: change this if possible to reflect real lines
1328 wxString content
= GetStringValue() ;
1332 for (size_t i
= 0; i
< content
.Length() ; i
++)
1334 if (count
== lineNo
)
1336 // Count chars in line then
1338 for (size_t j
= i
; j
< content
.Length(); j
++)
1341 if (content
[j
] == '\n')
1348 if (content
[i
] == '\n')
1355 // ----------------------------------------------------------------------------
1356 // standard unicode control implementation
1357 // ----------------------------------------------------------------------------
1359 #if TARGET_API_MAC_OSX
1361 wxMacUnicodeTextControl::wxMacUnicodeTextControl( wxTextCtrl
*wxPeer
,
1362 const wxString
& str
,
1364 const wxSize
& size
, long style
)
1365 : wxMacTextControl( wxPeer
)
1367 m_font
= wxPeer
->GetFont() ;
1368 m_windowStyle
= style
;
1369 Rect bounds
= wxMacGetBoundsForControl( wxPeer
, pos
, size
) ;
1371 wxMacConvertNewlines10To13( &st
) ;
1372 wxMacCFStringHolder
cf(st
, m_font
.GetEncoding()) ;
1373 CFStringRef cfr
= cf
;
1374 Boolean isPassword
= ( m_windowStyle
& wxTE_PASSWORD
) != 0 ;
1375 m_valueTag
= isPassword
? kControlEditTextPasswordCFStringTag
: kControlEditTextCFStringTag
;
1377 OSStatus err
= CreateEditUnicodeTextControl(
1378 MAC_WXHWND(wxPeer
->MacGetTopLevelWindowRef()), &bounds
, cfr
,
1379 isPassword
, NULL
, &m_controlRef
) ;
1380 verify_noerr( err
);
1382 if ( !(m_windowStyle
& wxTE_MULTILINE
) )
1383 SetData
<Boolean
>( kControlEditTextPart
, kControlEditTextSingleLineTag
, true ) ;
1386 wxMacUnicodeTextControl::~wxMacUnicodeTextControl()
1390 void wxMacUnicodeTextControl::VisibilityChanged(bool shown
)
1392 if ( !(m_windowStyle
& wxTE_MULTILINE
) && shown
)
1394 // work around a refresh issue insofar as not always the entire content is shown,
1395 // even if this would be possible
1396 ControlEditTextSelectionRec sel
;
1397 CFStringRef value
= NULL
;
1399 verify_noerr( GetData
<ControlEditTextSelectionRec
>( 0, kControlEditTextSelectionTag
, &sel
) );
1400 verify_noerr( GetData
<CFStringRef
>( 0, m_valueTag
, &value
) );
1401 verify_noerr( SetData
<CFStringRef
>( 0, m_valueTag
, &value
) );
1402 verify_noerr( SetData
<ControlEditTextSelectionRec
>( 0, kControlEditTextSelectionTag
, &sel
) );
1404 CFRelease( value
) ;
1408 wxString
wxMacUnicodeTextControl::GetStringValue() const
1411 CFStringRef value
= GetData
<CFStringRef
>(0, m_valueTag
) ;
1414 wxMacCFStringHolder
cf(value
) ;
1415 result
= cf
.AsString() ;
1419 wxMacConvertNewlines13To10( &result
) ;
1421 wxMacConvertNewlines10To13( &result
) ;
1427 void wxMacUnicodeTextControl::SetStringValue( const wxString
&str
)
1430 wxMacConvertNewlines10To13( &st
) ;
1431 wxMacCFStringHolder
cf( st
, m_font
.GetEncoding() ) ;
1432 verify_noerr( SetData
<CFStringRef
>( 0, m_valueTag
, cf
) ) ;
1435 void wxMacUnicodeTextControl::Copy()
1437 SendHICommand( kHICommandCopy
) ;
1440 void wxMacUnicodeTextControl::Cut()
1442 SendHICommand( kHICommandCut
) ;
1445 void wxMacUnicodeTextControl::Paste()
1447 SendHICommand( kHICommandPaste
) ;
1450 bool wxMacUnicodeTextControl::CanPaste() const
1455 void wxMacUnicodeTextControl::SetEditable(bool editable
)
1457 SetData
<Boolean
>( 0 , kControlEditTextLockedTag
, (Boolean
) !editable
) ;
1460 void wxMacUnicodeTextControl::GetSelection( long* from
, long* to
) const
1462 ControlEditTextSelectionRec sel
;
1463 verify_noerr( GetData
<ControlEditTextSelectionRec
>( 0, kControlEditTextSelectionTag
, &sel
) ) ;
1465 *from
= sel
.selStart
;
1470 void wxMacUnicodeTextControl::SetSelection( long from
, long to
)
1472 ControlEditTextSelectionRec sel
;
1473 if ((from
== -1) && (to
== -1))
1476 to
= 32767 ; // sel has 16 bit signed values, max is 32767
1479 sel
.selStart
= from
;
1481 SetData
<ControlEditTextSelectionRec
>( 0, kControlEditTextSelectionTag
, &sel
) ;
1484 void wxMacUnicodeTextControl::WriteText( const wxString
& str
)
1487 wxMacConvertNewlines10To13( &st
) ;
1489 #if MAC_OS_X_VERSION_MAX_ALLOWED > MAC_OS_X_VERSION_10_2
1490 wxMacCFStringHolder
cf(st
, m_font
.GetEncoding() ) ;
1491 CFStringRef value
= cf
;
1492 SetData
<CFStringRef
>( 0, kControlEditTextInsertCFStringRefTag
, &value
);
1494 wxString val
= GetStringValue() ;
1496 GetSelection( &start
, &end
) ;
1497 val
.Remove( start
, end
- start
) ;
1498 val
.insert( start
, str
) ;
1499 SetStringValue( val
) ;
1500 SetSelection( start
+ str
.Length() , start
+ str
.Length() ) ;
1506 // ----------------------------------------------------------------------------
1507 // MLTE control implementation (common part)
1508 // ----------------------------------------------------------------------------
1510 // if MTLE is read only, no changes at all are allowed, not even from
1511 // procedural API, in order to allow changes via API all the same we must undo
1512 // the readonly status while we are executing, this class helps to do so
1514 class wxMacEditHelper
1517 wxMacEditHelper( TXNObject txn
)
1519 TXNControlTag tag
[] = { kTXNIOPrivilegesTag
} ;
1521 TXNGetTXNObjectControls( m_txn
, 1 , tag
, m_data
) ;
1522 if ( m_data
[0].uValue
== kTXNReadOnly
)
1524 TXNControlData data
[] = { { kTXNReadWrite
} } ;
1525 TXNSetTXNObjectControls( m_txn
, false , 1 , tag
, data
) ;
1531 TXNControlTag tag
[] = { kTXNIOPrivilegesTag
} ;
1532 if ( m_data
[0].uValue
== kTXNReadOnly
)
1533 TXNSetTXNObjectControls( m_txn
, false , 1 , tag
, m_data
) ;
1538 TXNControlData m_data
[1] ;
1541 wxMacMLTEControl::wxMacMLTEControl( wxTextCtrl
*peer
)
1542 : wxMacTextControl( peer
)
1544 SetNeedsFocusRect( true ) ;
1547 wxString
wxMacMLTEControl::GetStringValue() const
1551 Size actualSize
= 0;
1556 err
= TXNGetDataEncoded( m_txn
, kTXNStartOffset
, kTXNEndOffset
, &theText
, kTXNUnicodeTextData
);
1565 actualSize
= GetHandleSize( theText
) / sizeof(UniChar
) ;
1566 if ( actualSize
> 0 )
1568 wxChar
*ptr
= NULL
;
1570 #if SIZEOF_WCHAR_T == 2
1571 ptr
= new wxChar
[actualSize
+ 1] ;
1572 wxStrncpy( ptr
, (wxChar
*)(*theText
) , actualSize
) ;
1574 SetHandleSize( theText
, (actualSize
+ 1) * sizeof(UniChar
) ) ;
1576 (((UniChar
*)*theText
)[actualSize
]) = 0 ;
1577 wxMBConvUTF16 converter
;
1578 size_t noChars
= converter
.MB2WC( NULL
, (const char*)*theText
, 0 ) ;
1579 ptr
= new wxChar
[noChars
+ 1] ;
1581 noChars
= converter
.MB2WC( ptr
, (const char*)*theText
, noChars
) ;
1583 HUnlock( theText
) ;
1586 ptr
[actualSize
] = 0 ;
1587 result
= wxString( ptr
) ;
1591 DisposeHandle( theText
) ;
1595 err
= TXNGetDataEncoded( m_txn
, kTXNStartOffset
, kTXNEndOffset
, &theText
, kTXNTextData
);
1604 actualSize
= GetHandleSize( theText
) ;
1605 if ( actualSize
> 0 )
1608 result
= wxString( *theText
, wxConvLocal
, actualSize
) ;
1609 HUnlock( theText
) ;
1612 DisposeHandle( theText
) ;
1618 wxMacConvertNewlines13To10( &result
) ;
1620 wxMacConvertNewlines10To13( &result
) ;
1626 void wxMacMLTEControl::SetStringValue( const wxString
&str
)
1629 wxMacConvertNewlines10To13( &st
);
1632 wxMacWindowClipper
c( m_peer
);
1635 wxMacEditHelper
help( m_txn
);
1636 SetTXNData( st
, kTXNStartOffset
, kTXNEndOffset
);
1639 TXNSetSelection( m_txn
, 0, 0 );
1640 TXNShowSelection( m_txn
, kTXNShowStart
);
1644 TXNFrameOptions
wxMacMLTEControl::FrameOptionsFromWXStyle( long wxStyle
)
1646 TXNFrameOptions frameOptions
= kTXNDontDrawCaretWhenInactiveMask
;
1648 #if MAC_OS_X_VERSION_MAX_ALLOWED >= MAC_OS_X_VERSION_10_3
1649 frameOptions
|= kTXNDoFontSubstitutionMask
;
1652 if ( ! (wxStyle
& wxTE_NOHIDESEL
) )
1653 frameOptions
|= kTXNDontDrawSelectionWhenInactiveMask
;
1655 if ( wxStyle
& (wxHSCROLL
| wxTE_DONTWRAP
) )
1656 frameOptions
|= kTXNWantHScrollBarMask
;
1658 if ( wxStyle
& wxTE_MULTILINE
)
1660 frameOptions
|= kTXNAlwaysWrapAtViewEdgeMask
;
1662 if ( !(wxStyle
& wxTE_NO_VSCROLL
) )
1664 frameOptions
|= kTXNWantVScrollBarMask
;
1666 // The following code causes drawing problems on 10.4. Perhaps it can be restored for
1667 // older versions of the OS, but I'm not sure it's appropriate to put a grow icon here
1668 // anyways, as AFAIK users can't actually use it to resize the text ctrl.
1669 // if ( frameOptions & kTXNWantHScrollBarMask )
1670 // frameOptions |= kTXNDrawGrowIconMask ;
1675 frameOptions
|= kTXNSingleLineOnlyMask
;
1678 return frameOptions
;
1681 void wxMacMLTEControl::AdjustCreationAttributes( const wxColour
&background
, bool visible
)
1683 TXNControlTag iControlTags
[] =
1685 kTXNDoFontSubstitution
,
1686 kTXNWordWrapStateTag
,
1688 TXNControlData iControlData
[] =
1694 int toptag
= WXSIZEOF( iControlTags
) ;
1696 if ( m_windowStyle
& wxTE_MULTILINE
)
1698 iControlData
[1].uValue
=
1699 (m_windowStyle
& wxTE_DONTWRAP
)
1704 OSStatus err
= TXNSetTXNObjectControls( m_txn
, false, toptag
, iControlTags
, iControlData
) ;
1705 verify_noerr( err
);
1707 // setting the default font:
1708 // under 10.2 this causes a visible caret, therefore we avoid it
1710 if ( UMAGetSystemVersion() >= 0x1030 )
1716 GetThemeFont( kThemeSystemFont
, GetApplicationScript() , fontName
, &fontSize
, &fontStyle
) ;
1718 TXNTypeAttributes typeAttr
[] =
1720 { kTXNQDFontNameAttribute
, kTXNQDFontNameAttributeSize
, { (void*) fontName
} } ,
1721 { kTXNQDFontSizeAttribute
, kTXNFontSizeAttributeSize
, { (void*) (fontSize
<< 16) } } ,
1722 { kTXNQDFontStyleAttribute
, kTXNQDFontStyleAttributeSize
, { (void*) normal
} } ,
1725 err
= TXNSetTypeAttributes(
1726 m_txn
, sizeof(typeAttr
) / sizeof(TXNTypeAttributes
),
1727 typeAttr
, kTXNStartOffset
, kTXNEndOffset
);
1728 verify_noerr( err
);
1731 if ( m_windowStyle
& wxTE_PASSWORD
)
1733 UniChar c
= 0x00A5 ;
1734 err
= TXNEchoMode( m_txn
, c
, 0 , true );
1735 verify_noerr( err
);
1738 TXNBackground tback
;
1739 tback
.bgType
= kTXNBackgroundTypeRGB
;
1740 tback
.bg
.color
= MAC_WXCOLORREF( background
.GetPixel() );
1741 TXNSetBackground( m_txn
, &tback
);
1743 #if MAC_OS_X_VERSION_MAX_ALLOWED >= MAC_OS_X_VERSION_10_4
1744 if ( UMAGetSystemVersion() >= 0x1040 )
1746 TXNCommandEventSupportOptions options
;
1747 if ( TXNGetCommandEventSupport( m_txn
, &options
) == noErr
)
1750 kTXNSupportEditCommandProcessing
1751 | kTXNSupportEditCommandUpdating
1752 | kTXNSupportSpellCheckCommandProcessing
1753 | kTXNSupportSpellCheckCommandUpdating
1754 | kTXNSupportFontCommandProcessing
1755 | kTXNSupportFontCommandUpdating
;
1757 TXNSetCommandEventSupport( m_txn
, options
) ;
1763 void wxMacMLTEControl::SetBackground( const wxBrush
&brush
)
1765 // currently only solid background are supported
1766 TXNBackground tback
;
1768 tback
.bgType
= kTXNBackgroundTypeRGB
;
1769 tback
.bg
.color
= MAC_WXCOLORREF( brush
.GetColour().GetPixel() );
1770 TXNSetBackground( m_txn
, &tback
);
1773 void wxMacMLTEControl::TXNSetAttribute( const wxTextAttr
& style
, long from
, long to
)
1775 TXNTypeAttributes typeAttr
[4] ;
1776 Str255 fontName
= "\pMonaco" ;
1777 SInt16 fontSize
= 12 ;
1778 Style fontStyle
= normal
;
1782 if ( style
.HasFont() )
1784 const wxFont
&font
= style
.GetFont() ;
1785 wxMacStringToPascal( font
.GetFaceName() , fontName
) ;
1786 fontSize
= font
.GetPointSize() ;
1787 if ( font
.GetUnderlined() )
1788 fontStyle
|= underline
;
1789 if ( font
.GetWeight() == wxBOLD
)
1791 if ( font
.GetStyle() == wxITALIC
)
1792 fontStyle
|= italic
;
1794 typeAttr
[attrCount
].tag
= kTXNQDFontNameAttribute
;
1795 typeAttr
[attrCount
].size
= kTXNQDFontNameAttributeSize
;
1796 typeAttr
[attrCount
].data
.dataPtr
= (void*)fontName
;
1799 typeAttr
[attrCount
].tag
= kTXNQDFontSizeAttribute
;
1800 typeAttr
[attrCount
].size
= kTXNFontSizeAttributeSize
;
1801 typeAttr
[attrCount
].data
.dataValue
= (fontSize
<< 16) ;
1804 typeAttr
[attrCount
].tag
= kTXNQDFontStyleAttribute
;
1805 typeAttr
[attrCount
].size
= kTXNQDFontStyleAttributeSize
;
1806 typeAttr
[attrCount
].data
.dataValue
= fontStyle
;
1810 if ( style
.HasTextColour() )
1812 color
= MAC_WXCOLORREF(style
.GetTextColour().GetPixel()) ;
1814 typeAttr
[attrCount
].tag
= kTXNQDFontColorAttribute
;
1815 typeAttr
[attrCount
].size
= kTXNQDFontColorAttributeSize
;
1816 typeAttr
[attrCount
].data
.dataPtr
= (void*) &color
;
1820 if ( attrCount
> 0 )
1822 verify_noerr( TXNSetTypeAttributes( m_txn
, attrCount
, typeAttr
, from
, to
) );
1826 void wxMacMLTEControl::SetFont( const wxFont
& font
, const wxColour
& foreground
, long windowStyle
)
1828 wxMacEditHelper
help( m_txn
) ;
1829 TXNSetAttribute( wxTextAttr( foreground
, wxNullColour
, font
), kTXNStartOffset
, kTXNEndOffset
) ;
1832 void wxMacMLTEControl::SetStyle( long start
, long end
, const wxTextAttr
& style
)
1834 wxMacEditHelper
help( m_txn
) ;
1835 TXNSetAttribute( style
, start
, end
) ;
1838 void wxMacMLTEControl::Copy()
1840 ClearCurrentScrap();
1842 TXNConvertToPublicScrap();
1845 void wxMacMLTEControl::Cut()
1847 ClearCurrentScrap();
1849 TXNConvertToPublicScrap();
1852 void wxMacMLTEControl::Paste()
1854 TXNConvertFromPublicScrap();
1858 bool wxMacMLTEControl::CanPaste() const
1860 return TXNIsScrapPastable() ;
1863 void wxMacMLTEControl::SetEditable(bool editable
)
1865 TXNControlTag tag
[] = { kTXNIOPrivilegesTag
} ;
1866 TXNControlData data
[] = { { editable
? kTXNReadWrite
: kTXNReadOnly
} } ;
1867 TXNSetTXNObjectControls( m_txn
, false, WXSIZEOF(tag
), tag
, data
) ;
1870 wxTextPos
wxMacMLTEControl::GetLastPosition() const
1872 wxTextPos actualsize
= 0 ;
1875 OSErr err
= TXNGetDataEncoded( m_txn
, kTXNStartOffset
, kTXNEndOffset
, &theText
, kTXNTextData
);
1880 actualsize
= GetHandleSize( theText
) ;
1881 DisposeHandle( theText
) ;
1891 void wxMacMLTEControl::Replace( long from
, long to
, const wxString
&str
)
1893 wxString value
= str
;
1894 wxMacConvertNewlines10To13( &value
) ;
1896 wxMacEditHelper
help( m_txn
) ;
1897 wxMacWindowClipper
c( m_peer
) ;
1899 TXNSetSelection( m_txn
, from
, to
) ;
1901 SetTXNData( value
, kTXNUseCurrentSelection
, kTXNUseCurrentSelection
) ;
1904 void wxMacMLTEControl::Remove( long from
, long to
)
1906 wxMacWindowClipper
c( m_peer
) ;
1907 wxMacEditHelper
help( m_txn
) ;
1908 TXNSetSelection( m_txn
, from
, to
) ;
1912 void wxMacMLTEControl::GetSelection( long* from
, long* to
) const
1914 TXNGetSelection( m_txn
, (TXNOffset
*) from
, (TXNOffset
*) to
) ;
1917 void wxMacMLTEControl::SetSelection( long from
, long to
)
1919 wxMacWindowClipper
c( m_peer
) ;
1921 // change the selection
1922 if ((from
== -1) && (to
== -1))
1923 TXNSelectAll( m_txn
);
1925 TXNSetSelection( m_txn
, from
, to
);
1927 TXNShowSelection( m_txn
, kTXNShowStart
);
1930 void wxMacMLTEControl::WriteText( const wxString
& str
)
1933 wxMacConvertNewlines10To13( &st
) ;
1935 long start
, end
, dummy
;
1937 GetSelection( &start
, &dummy
) ;
1938 wxMacWindowClipper
c( m_peer
) ;
1941 wxMacEditHelper
helper( m_txn
) ;
1942 SetTXNData( st
, kTXNUseCurrentSelection
, kTXNUseCurrentSelection
) ;
1945 GetSelection( &dummy
, &end
) ;
1947 // TODO: SetStyle( start , end , GetDefaultStyle() ) ;
1950 void wxMacMLTEControl::Clear()
1952 wxMacWindowClipper
c( m_peer
) ;
1953 wxMacEditHelper
st( m_txn
) ;
1954 TXNSetSelection( m_txn
, kTXNStartOffset
, kTXNEndOffset
) ;
1958 bool wxMacMLTEControl::CanUndo() const
1960 return TXNCanUndo( m_txn
, NULL
) ;
1963 void wxMacMLTEControl::Undo()
1968 bool wxMacMLTEControl::CanRedo() const
1970 return TXNCanRedo( m_txn
, NULL
) ;
1973 void wxMacMLTEControl::Redo()
1978 int wxMacMLTEControl::GetNumberOfLines() const
1980 ItemCount lines
= 0 ;
1981 TXNGetLineCount( m_txn
, &lines
) ;
1986 long wxMacMLTEControl::XYToPosition(long x
, long y
) const
1991 // TODO: find a better implementation : while we can get the
1992 // line metrics of a certain line, we don't get its starting
1993 // position, so it would probably be rather a binary search
1994 // for the start position
1995 long xpos
= 0, ypos
= 0 ;
1996 int lastHeight
= 0 ;
1999 lastpos
= GetLastPosition() ;
2000 for ( n
= 0 ; n
<= (ItemCount
) lastpos
; ++n
)
2002 if ( y
== ypos
&& x
== xpos
)
2005 TXNOffsetToPoint( m_txn
, n
, &curpt
) ;
2007 if ( curpt
.v
> lastHeight
)
2013 lastHeight
= curpt
.v
;
2022 bool wxMacMLTEControl::PositionToXY( long pos
, long *x
, long *y
) const
2032 lastpos
= GetLastPosition() ;
2033 if ( pos
<= lastpos
)
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 for ( n
= 0 ; n
<= (ItemCount
) pos
; ++n
)
2045 TXNOffsetToPoint( m_txn
, n
, &curpt
) ;
2047 if ( curpt
.v
> lastHeight
)
2053 lastHeight
= curpt
.v
;
2068 void wxMacMLTEControl::ShowPosition( long pos
)
2070 #if TARGET_RT_MAC_MACHO && defined(AVAILABLE_MAC_OS_X_VERSION_10_2_AND_LATER)
2072 Point current
, desired
;
2073 TXNOffset selstart
, selend
;
2075 TXNGetSelection( m_txn
, &selstart
, &selend
);
2076 TXNOffsetToPoint( m_txn
, selstart
, ¤t
);
2077 TXNOffsetToPoint( m_txn
, pos
, &desired
);
2079 // TODO: use HIPoints for 10.3 and above
2080 if ( (UInt32
)TXNScroll
!= (UInt32
)kUnresolvedCFragSymbolAddress
)
2082 OSErr theErr
= noErr
;
2083 SInt32 dv
= desired
.v
- current
.v
;
2084 SInt32 dh
= desired
.h
- current
.h
;
2085 TXNShowSelection( m_txn
, kTXNShowStart
) ; // NB: should this be kTXNShowStart or kTXNShowEnd ??
2086 theErr
= TXNScroll( m_txn
, kTXNScrollUnitsInPixels
, kTXNScrollUnitsInPixels
, &dv
, &dh
);
2088 // there will be an error returned for classic MLTE implementation when the control is
2089 // invisible, but HITextView works correctly, so we don't assert that one
2090 // wxASSERT_MSG( theErr == noErr, _T("TXNScroll returned an error!") );
2096 void wxMacMLTEControl::SetTXNData( const wxString
& st
, TXNOffset start
, TXNOffset end
)
2099 #if SIZEOF_WCHAR_T == 2
2100 size_t len
= st
.Len() ;
2101 TXNSetData( m_txn
, kTXNUnicodeTextData
, (void*)st
.wc_str(), len
* 2, start
, end
);
2103 wxMBConvUTF16 converter
;
2104 ByteCount byteBufferLen
= converter
.WC2MB( NULL
, st
.wc_str(), 0 ) ;
2105 UniChar
*unibuf
= (UniChar
*)malloc( byteBufferLen
) ;
2106 converter
.WC2MB( (char*)unibuf
, st
.wc_str(), byteBufferLen
) ;
2107 TXNSetData( m_txn
, kTXNUnicodeTextData
, (void*)unibuf
, byteBufferLen
, start
, end
) ;
2111 wxCharBuffer text
= st
.mb_str( wxConvLocal
) ;
2112 TXNSetData( m_txn
, kTXNTextData
, (void*)text
.data(), strlen( text
), start
, end
) ;
2116 wxString
wxMacMLTEControl::GetLineText(long lineNo
) const
2120 if ( lineNo
< GetNumberOfLines() )
2123 Fixed lineWidth
, lineHeight
, currentHeight
;
2126 // get the first possible position in the control
2127 TXNOffsetToPoint(m_txn
, 0, &firstPoint
);
2129 // Iterate through the lines until we reach the one we want,
2130 // adding to our current y pixel point position
2133 while (ypos
< lineNo
)
2135 TXNGetLineMetrics(m_txn
, ypos
++, &lineWidth
, &lineHeight
);
2136 currentHeight
+= lineHeight
;
2139 Point thePoint
= { firstPoint
.v
+ (currentHeight
>> 16), firstPoint
.h
+ (0) };
2140 TXNOffset theOffset
;
2141 TXNPointToOffset(m_txn
, thePoint
, &theOffset
);
2143 wxString content
= GetStringValue() ;
2144 Point currentPoint
= thePoint
;
2145 while (thePoint
.v
== currentPoint
.v
&& theOffset
< content
.length())
2147 line
+= content
[theOffset
];
2148 TXNOffsetToPoint(m_txn
, ++theOffset
, ¤tPoint
);
2155 int wxMacMLTEControl::GetLineLength(long lineNo
) const
2159 if ( lineNo
< GetNumberOfLines() )
2162 Fixed lineWidth
, lineHeight
, currentHeight
;
2165 // get the first possible position in the control
2166 TXNOffsetToPoint(m_txn
, 0, &firstPoint
);
2168 // Iterate through the lines until we reach the one we want,
2169 // adding to our current y pixel point position
2172 while (ypos
< lineNo
)
2174 TXNGetLineMetrics(m_txn
, ypos
++, &lineWidth
, &lineHeight
);
2175 currentHeight
+= lineHeight
;
2178 Point thePoint
= { firstPoint
.v
+ (currentHeight
>> 16), firstPoint
.h
+ (0) };
2179 TXNOffset theOffset
;
2180 TXNPointToOffset(m_txn
, thePoint
, &theOffset
);
2182 wxString content
= GetStringValue() ;
2183 Point currentPoint
= thePoint
;
2184 while (thePoint
.v
== currentPoint
.v
&& theOffset
< content
.length())
2187 TXNOffsetToPoint(m_txn
, ++theOffset
, ¤tPoint
);
2194 // ----------------------------------------------------------------------------
2195 // MLTE control implementation (classic part)
2196 // ----------------------------------------------------------------------------
2198 // OS X Notes : We still don't have a full replacement for MLTE, so this implementation
2199 // has to live on. We have different problems coming from outdated implementations on the
2200 // various OS X versions. Most deal with the scrollbars: they are not correctly embedded
2201 // while this can be solved on 10.3 by reassigning them the correct place, on 10.2 there is
2202 // no way out, therefore we are using our own implementation and our own scrollbars ....
2204 #ifdef __WXMAC_OSX__
2206 TXNScrollInfoUPP gTXNScrollInfoProc
= NULL
;
2207 ControlActionUPP gTXNScrollActionProc
= NULL
;
2209 pascal void wxMacMLTEClassicControl::TXNScrollInfoProc(
2210 SInt32 iValue
, SInt32 iMaximumValue
,
2211 TXNScrollBarOrientation iScrollBarOrientation
, SInt32 iRefCon
)
2213 wxMacMLTEClassicControl
* mlte
= (wxMacMLTEClassicControl
*) iRefCon
;
2214 SInt32 value
= wxMax( iValue
, 0 ) ;
2215 SInt32 maximum
= wxMax( iMaximumValue
, 0 ) ;
2217 if ( iScrollBarOrientation
== kTXNHorizontal
)
2219 if ( mlte
->m_sbHorizontal
)
2221 SetControl32BitValue( mlte
->m_sbHorizontal
, value
) ;
2222 SetControl32BitMaximum( mlte
->m_sbHorizontal
, maximum
) ;
2223 mlte
->m_lastHorizontalValue
= value
;
2226 else if ( iScrollBarOrientation
== kTXNVertical
)
2228 if ( mlte
->m_sbVertical
)
2230 SetControl32BitValue( mlte
->m_sbVertical
, value
) ;
2231 SetControl32BitMaximum( mlte
->m_sbVertical
, maximum
) ;
2232 mlte
->m_lastVerticalValue
= value
;
2237 pascal void wxMacMLTEClassicControl::TXNScrollActionProc( ControlRef controlRef
, ControlPartCode partCode
)
2239 wxMacMLTEClassicControl
* mlte
= (wxMacMLTEClassicControl
*) GetControlReference( controlRef
) ;
2243 if ( controlRef
!= mlte
->m_sbVertical
&& controlRef
!= mlte
->m_sbHorizontal
)
2247 bool isHorizontal
= ( controlRef
== mlte
->m_sbHorizontal
) ;
2249 SInt32 minimum
= 0 ;
2250 SInt32 maximum
= GetControl32BitMaximum( controlRef
) ;
2251 SInt32 value
= GetControl32BitValue( controlRef
) ;
2256 case kControlDownButtonPart
:
2260 case kControlUpButtonPart
:
2264 case kControlPageDownPart
:
2265 delta
= GetControlViewSize( controlRef
) ;
2268 case kControlPageUpPart
:
2269 delta
= -GetControlViewSize( controlRef
) ;
2272 case kControlIndicatorPart
:
2273 delta
= value
- (isHorizontal
? mlte
->m_lastHorizontalValue
: mlte
->m_lastVerticalValue
) ;
2282 SInt32 newValue
= value
;
2284 if ( partCode
!= kControlIndicatorPart
)
2286 if ( value
+ delta
< minimum
)
2287 delta
= minimum
- value
;
2288 if ( value
+ delta
> maximum
)
2289 delta
= maximum
- value
;
2291 SetControl32BitValue( controlRef
, value
+ delta
) ;
2292 newValue
= value
+ delta
;
2295 SInt32 verticalDelta
= isHorizontal
? 0 : delta
;
2296 SInt32 horizontalDelta
= isHorizontal
? delta
: 0 ;
2299 mlte
->m_txn
, kTXNScrollUnitsInPixels
, kTXNScrollUnitsInPixels
,
2300 &verticalDelta
, &horizontalDelta
);
2301 verify_noerr( err
);
2304 mlte
->m_lastHorizontalValue
= newValue
;
2306 mlte
->m_lastVerticalValue
= newValue
;
2311 // make correct activations
2312 void wxMacMLTEClassicControl::MacActivatePaneText(bool setActive
)
2314 wxTextCtrl
* textctrl
= (wxTextCtrl
*) GetControlReference(m_controlRef
);
2316 wxMacWindowClipper
clipper( textctrl
) ;
2317 TXNActivate( m_txn
, m_txnFrameID
, setActive
);
2319 ControlRef controlFocus
= 0 ;
2320 GetKeyboardFocus( m_txnWindow
, &controlFocus
) ;
2321 if ( controlFocus
== m_controlRef
)
2322 TXNFocus( m_txn
, setActive
);
2325 void wxMacMLTEClassicControl::MacFocusPaneText(bool setFocus
)
2327 TXNFocus( m_txn
, setFocus
);
2330 // guards against inappropriate redraw (hidden objects drawing onto window)
2332 void wxMacMLTEClassicControl::MacSetObjectVisibility(bool vis
)
2334 ControlRef controlFocus
= 0 ;
2335 GetKeyboardFocus( m_txnWindow
, &controlFocus
) ;
2337 if ( !vis
&& (controlFocus
== m_controlRef
) )
2338 SetKeyboardFocus( m_txnWindow
, m_controlRef
, kControlFocusNoPart
) ;
2340 TXNControlTag iControlTags
[1] = { kTXNVisibilityTag
};
2341 TXNControlData iControlData
[1] = { { (UInt32
)false } };
2343 verify_noerr( TXNGetTXNObjectControls( m_txn
, 1, iControlTags
, iControlData
) ) ;
2345 if ( iControlData
[0].uValue
!= vis
)
2347 iControlData
[0].uValue
= vis
;
2348 verify_noerr( TXNSetTXNObjectControls( m_txn
, false , 1, iControlTags
, iControlData
) ) ;
2351 // currently, we always clip as partial visibility (overlapped) visibility is also a problem,
2352 // if we run into further problems we might set the FrameBounds to an empty rect here
2355 // make sure that the TXNObject is at the right position
2357 void wxMacMLTEClassicControl::MacUpdatePosition()
2359 wxTextCtrl
* textctrl
= (wxTextCtrl
*)GetControlReference( m_controlRef
);
2360 if ( textctrl
== NULL
)
2364 UMAGetControlBoundsInWindowCoords( m_controlRef
, &bounds
);
2366 wxRect visRect
= textctrl
->MacGetClippedClientRect() ;
2367 Rect visBounds
= { visRect
.y
, visRect
.x
, visRect
.y
+ visRect
.height
, visRect
.x
+ visRect
.width
} ;
2370 textctrl
->MacWindowToRootWindow( &x
, &y
) ;
2371 OffsetRect( &visBounds
, x
, y
) ;
2373 if ( !EqualRect( &bounds
, &m_txnControlBounds
) || !EqualRect( &visBounds
, &m_txnVisBounds
) )
2375 m_txnControlBounds
= bounds
;
2376 m_txnVisBounds
= visBounds
;
2377 wxMacWindowClipper
cl( textctrl
) ;
2379 #ifdef __WXMAC_OSX__
2380 bool isCompositing
= textctrl
->MacGetTopLevelWindow()->MacUsesCompositing() ;
2381 if ( m_sbHorizontal
|| m_sbVertical
)
2383 int w
= bounds
.right
- bounds
.left
;
2384 int h
= bounds
.bottom
- bounds
.top
;
2386 if ( m_sbHorizontal
)
2390 sbBounds
.left
= -1 ;
2391 sbBounds
.top
= h
- 14 ;
2392 sbBounds
.right
= w
+ 1 ;
2393 sbBounds
.bottom
= h
+ 1 ;
2395 if ( !isCompositing
)
2396 OffsetRect( &sbBounds
, m_txnControlBounds
.left
, m_txnControlBounds
.top
) ;
2398 SetControlBounds( m_sbHorizontal
, &sbBounds
) ;
2399 SetControlViewSize( m_sbHorizontal
, w
) ;
2406 sbBounds
.left
= w
- 14 ;
2408 sbBounds
.right
= w
+ 1 ;
2409 sbBounds
.bottom
= m_sbHorizontal
? h
- 14 : h
+ 1 ;
2411 if ( !isCompositing
)
2412 OffsetRect( &sbBounds
, m_txnControlBounds
.left
, m_txnControlBounds
.top
) ;
2414 SetControlBounds( m_sbVertical
, &sbBounds
) ;
2415 SetControlViewSize( m_sbVertical
, h
) ;
2420 TXNLongRect olddestRect
;
2421 TXNGetRectBounds( m_txn
, &oldviewRect
, &olddestRect
, NULL
) ;
2423 Rect viewRect
= { m_txnControlBounds
.top
, m_txnControlBounds
.left
,
2424 m_txnControlBounds
.bottom
- ( m_sbHorizontal
? 14 : 0 ) ,
2425 m_txnControlBounds
.right
- ( m_sbVertical
? 14 : 0 ) } ;
2426 TXNLongRect destRect
= { m_txnControlBounds
.top
, m_txnControlBounds
.left
,
2427 m_txnControlBounds
.bottom
- ( m_sbHorizontal
? 14 : 0 ) ,
2428 m_txnControlBounds
.right
- ( m_sbVertical
? 14 : 0 ) } ;
2430 if ( olddestRect
.right
>= 10000 )
2431 destRect
.right
= destRect
.left
+ 32000 ;
2433 if ( olddestRect
.bottom
>= 0x20000000 )
2434 destRect
.bottom
= destRect
.top
+ 0x40000000 ;
2436 SectRect( &viewRect
, &visBounds
, &viewRect
) ;
2437 TXNSetRectBounds( m_txn
, &viewRect
, &destRect
, true ) ;
2442 m_txnControlBounds
.top
,
2443 m_txnControlBounds
.left
,
2444 m_txnControlBounds
.bottom
- (m_sbHorizontal
? 14 : 0),
2445 m_txnControlBounds
.right
- (m_sbVertical
? 14 : 0),
2451 m_txn
, m_txnControlBounds
.top
, m_txnControlBounds
.left
,
2452 wxMax( m_txnControlBounds
.bottom
, m_txnControlBounds
.top
),
2453 wxMax( m_txnControlBounds
.right
, m_txnControlBounds
.left
), m_txnFrameID
);
2456 // the SetFrameBounds method under Classic sometimes does not correctly scroll a selection into sight after a
2457 // movement, therefore we have to force it
2459 // this problem has been reported in OSX as well, so we use this here once again
2461 TXNLongRect textRect
;
2462 TXNGetRectBounds( m_txn
, NULL
, NULL
, &textRect
) ;
2463 if ( textRect
.left
< m_txnControlBounds
.left
)
2464 TXNShowSelection( m_txn
, kTXNShowStart
) ;
2468 void wxMacMLTEClassicControl::SetRect( Rect
*r
)
2470 wxMacControl::SetRect( r
) ;
2471 MacUpdatePosition() ;
2474 void wxMacMLTEClassicControl::MacControlUserPaneDrawProc(wxInt16 thePart
)
2476 wxTextCtrl
* textctrl
= (wxTextCtrl
*)GetControlReference( m_controlRef
);
2477 if ( textctrl
== NULL
)
2480 if ( textctrl
->MacIsReallyShown() )
2482 wxMacWindowClipper
clipper( textctrl
) ;
2483 TXNDraw( m_txn
, NULL
) ;
2487 wxInt16
wxMacMLTEClassicControl::MacControlUserPaneHitTestProc(wxInt16 x
, wxInt16 y
)
2489 Point where
= { y
, x
} ;
2490 ControlPartCode result
= kControlNoPart
;
2492 wxTextCtrl
* textctrl
= (wxTextCtrl
*) GetControlReference( m_controlRef
);
2493 if ( (textctrl
!= NULL
) && textctrl
->MacIsReallyShown() )
2495 if (PtInRect( where
, &m_txnControlBounds
))
2497 result
= kControlEditTextPart
;
2501 // sometimes we get the coords also in control local coordinates, therefore test again
2502 if ( textctrl
->MacGetTopLevelWindow()->MacUsesCompositing() )
2505 textctrl
->MacClientToRootWindow( &x
, &y
) ;
2510 if (PtInRect( where
, &m_txnControlBounds
))
2511 result
= kControlEditTextPart
;
2518 wxInt16
wxMacMLTEClassicControl::MacControlUserPaneTrackingProc( wxInt16 x
, wxInt16 y
, void* actionProc
)
2520 ControlPartCode result
= kControlNoPart
;
2522 wxTextCtrl
* textctrl
= (wxTextCtrl
*) GetControlReference( m_controlRef
);
2523 if ( (textctrl
!= NULL
) && textctrl
->MacIsReallyShown() )
2525 Point startPt
= { y
, x
} ;
2526 // for compositing, we must convert these into toplevel window coordinates, because hittesting expects them
2527 if ( textctrl
->MacGetTopLevelWindow()->MacUsesCompositing() )
2530 textctrl
->MacClientToRootWindow( &x
, &y
) ;
2535 switch (MacControlUserPaneHitTestProc( startPt
.h
, startPt
.v
))
2537 case kControlEditTextPart
:
2539 wxMacWindowClipper
clipper( textctrl
) ;
2542 ConvertEventRefToEventRecord( (EventRef
) wxTheApp
->MacGetCurrentEvent() , &rec
) ;
2543 TXNClick( m_txn
, &rec
);
2555 void wxMacMLTEClassicControl::MacControlUserPaneIdleProc()
2557 wxTextCtrl
* textctrl
= (wxTextCtrl
*)GetControlReference( m_controlRef
);
2558 if ( textctrl
== NULL
)
2561 if (textctrl
->MacIsReallyShown())
2563 if (IsControlActive(m_controlRef
))
2567 wxMacWindowClipper
clipper( textctrl
) ;
2572 if (PtInRect(mousep
, &m_txnControlBounds
))
2574 RgnHandle theRgn
= NewRgn();
2575 RectRgn(theRgn
, &m_txnControlBounds
);
2576 TXNAdjustCursor(m_txn
, theRgn
);
2583 wxInt16
wxMacMLTEClassicControl::MacControlUserPaneKeyDownProc (wxInt16 keyCode
, wxInt16 charCode
, wxInt16 modifiers
)
2585 wxTextCtrl
* textctrl
= (wxTextCtrl
*)GetControlReference( m_controlRef
);
2586 if ( textctrl
== NULL
)
2587 return kControlNoPart
;
2589 wxMacWindowClipper
clipper( textctrl
) ;
2592 memset( &ev
, 0 , sizeof( ev
) ) ;
2594 ev
.modifiers
= modifiers
;
2595 ev
.message
= ((keyCode
<< 8) & keyCodeMask
) | (charCode
& charCodeMask
);
2596 TXNKeyDown( m_txn
, &ev
);
2598 return kControlEntireControl
;
2601 void wxMacMLTEClassicControl::MacControlUserPaneActivateProc(bool activating
)
2603 MacActivatePaneText( activating
);
2606 wxInt16
wxMacMLTEClassicControl::MacControlUserPaneFocusProc(wxInt16 action
)
2608 ControlPartCode focusResult
= kControlFocusNoPart
;
2610 wxTextCtrl
* textctrl
= (wxTextCtrl
*)GetControlReference( m_controlRef
);
2611 if ( textctrl
== NULL
)
2614 wxMacWindowClipper
clipper( textctrl
) ;
2616 ControlRef controlFocus
= NULL
;
2617 GetKeyboardFocus( m_txnWindow
, &controlFocus
) ;
2618 bool wasFocused
= ( controlFocus
== m_controlRef
) ;
2622 case kControlFocusPrevPart
:
2623 case kControlFocusNextPart
:
2624 MacFocusPaneText( !wasFocused
);
2625 focusResult
= (!wasFocused
? (ControlPartCode
) kControlEditTextPart
: (ControlPartCode
) kControlFocusNoPart
);
2628 case kControlFocusNoPart
:
2630 MacFocusPaneText( false );
2631 focusResult
= kControlFocusNoPart
;
2638 void wxMacMLTEClassicControl::MacControlUserPaneBackgroundProc( void *info
)
2642 wxMacMLTEClassicControl::wxMacMLTEClassicControl( wxTextCtrl
*wxPeer
,
2643 const wxString
& str
,
2645 const wxSize
& size
, long style
)
2646 : wxMacMLTEControl( wxPeer
)
2648 m_font
= wxPeer
->GetFont() ;
2649 m_windowStyle
= style
;
2650 Rect bounds
= wxMacGetBoundsForControl( wxPeer
, pos
, size
) ;
2653 kControlSupportsEmbedding
| kControlSupportsFocus
| kControlWantsIdle
2654 | kControlWantsActivate
| kControlHandlesTracking
2655 // | kControlHasSpecialBackground
2656 | kControlGetsFocusOnClick
| kControlSupportsLiveFeedback
;
2658 OSStatus err
= ::CreateUserPaneControl(
2659 MAC_WXHWND(wxPeer
->GetParent()->MacGetTopLevelWindowRef()),
2660 &bounds
, featureSet
, &m_controlRef
);
2661 verify_noerr( err
);
2665 AdjustCreationAttributes( *wxWHITE
, true ) ;
2667 MacSetObjectVisibility( wxPeer
->MacIsReallyShown() ) ;
2671 wxMacConvertNewlines10To13( &st
) ;
2672 wxMacWindowClipper
clipper( m_peer
) ;
2673 SetTXNData( st
, kTXNStartOffset
, kTXNEndOffset
) ;
2674 TXNSetSelection( m_txn
, 0, 0 ) ;
2678 wxMacMLTEClassicControl::~wxMacMLTEClassicControl()
2680 TXNDeleteObject( m_txn
);
2684 void wxMacMLTEClassicControl::VisibilityChanged(bool shown
)
2686 MacSetObjectVisibility( shown
) ;
2687 wxMacControl::VisibilityChanged( shown
) ;
2690 void wxMacMLTEClassicControl::SuperChangedPosition()
2692 MacUpdatePosition() ;
2693 wxMacControl::SuperChangedPosition() ;
2696 #ifdef __WXMAC_OSX__
2698 ControlUserPaneDrawUPP gTPDrawProc
= NULL
;
2699 ControlUserPaneHitTestUPP gTPHitProc
= NULL
;
2700 ControlUserPaneTrackingUPP gTPTrackProc
= NULL
;
2701 ControlUserPaneIdleUPP gTPIdleProc
= NULL
;
2702 ControlUserPaneKeyDownUPP gTPKeyProc
= NULL
;
2703 ControlUserPaneActivateUPP gTPActivateProc
= NULL
;
2704 ControlUserPaneFocusUPP gTPFocusProc
= NULL
;
2706 static pascal void wxMacControlUserPaneDrawProc(ControlRef control
, SInt16 part
)
2708 wxTextCtrl
*textCtrl
= wxDynamicCast( wxFindControlFromMacControl(control
) , wxTextCtrl
) ;
2709 wxMacMLTEClassicControl
* win
= textCtrl
? (wxMacMLTEClassicControl
*)(textCtrl
->GetPeer()) : NULL
;
2711 win
->MacControlUserPaneDrawProc( part
) ;
2714 static pascal ControlPartCode
wxMacControlUserPaneHitTestProc(ControlRef control
, Point where
)
2716 wxTextCtrl
*textCtrl
= wxDynamicCast( wxFindControlFromMacControl(control
) , wxTextCtrl
) ;
2717 wxMacMLTEClassicControl
* win
= textCtrl
? (wxMacMLTEClassicControl
*)(textCtrl
->GetPeer()) : NULL
;
2719 return win
->MacControlUserPaneHitTestProc( where
.h
, where
.v
) ;
2721 return kControlNoPart
;
2724 static pascal ControlPartCode
wxMacControlUserPaneTrackingProc(ControlRef control
, Point startPt
, ControlActionUPP actionProc
)
2726 wxTextCtrl
*textCtrl
= wxDynamicCast( wxFindControlFromMacControl(control
) , wxTextCtrl
) ;
2727 wxMacMLTEClassicControl
* win
= textCtrl
? (wxMacMLTEClassicControl
*)(textCtrl
->GetPeer()) : NULL
;
2729 return win
->MacControlUserPaneTrackingProc( startPt
.h
, startPt
.v
, (void*) actionProc
) ;
2731 return kControlNoPart
;
2734 static pascal void wxMacControlUserPaneIdleProc(ControlRef control
)
2736 wxTextCtrl
*textCtrl
= wxDynamicCast( wxFindControlFromMacControl(control
) , wxTextCtrl
) ;
2737 wxMacMLTEClassicControl
* win
= textCtrl
? (wxMacMLTEClassicControl
*)(textCtrl
->GetPeer()) : NULL
;
2739 win
->MacControlUserPaneIdleProc() ;
2742 static pascal ControlPartCode
wxMacControlUserPaneKeyDownProc(ControlRef control
, SInt16 keyCode
, SInt16 charCode
, SInt16 modifiers
)
2744 wxTextCtrl
*textCtrl
= wxDynamicCast( wxFindControlFromMacControl(control
) , wxTextCtrl
) ;
2745 wxMacMLTEClassicControl
* win
= textCtrl
? (wxMacMLTEClassicControl
*)(textCtrl
->GetPeer()) : NULL
;
2747 return win
->MacControlUserPaneKeyDownProc( keyCode
, charCode
, modifiers
) ;
2749 return kControlNoPart
;
2752 static pascal void wxMacControlUserPaneActivateProc(ControlRef control
, Boolean activating
)
2754 wxTextCtrl
*textCtrl
= wxDynamicCast( wxFindControlFromMacControl(control
) , wxTextCtrl
) ;
2755 wxMacMLTEClassicControl
* win
= textCtrl
? (wxMacMLTEClassicControl
*)(textCtrl
->GetPeer()) : NULL
;
2757 win
->MacControlUserPaneActivateProc( activating
) ;
2760 static pascal ControlPartCode
wxMacControlUserPaneFocusProc(ControlRef control
, ControlFocusPart action
)
2762 wxTextCtrl
*textCtrl
= wxDynamicCast( wxFindControlFromMacControl(control
) , wxTextCtrl
) ;
2763 wxMacMLTEClassicControl
* win
= textCtrl
? (wxMacMLTEClassicControl
*)(textCtrl
->GetPeer()) : NULL
;
2765 return win
->MacControlUserPaneFocusProc( action
) ;
2767 return kControlNoPart
;
2771 static pascal void wxMacControlUserPaneBackgroundProc(ControlRef control
, ControlBackgroundPtr info
)
2773 wxTextCtrl
*textCtrl
= wxDynamicCast( wxFindControlFromMacControl(control
) , wxTextCtrl
) ;
2774 wxMacMLTEClassicControl
* win
= textCtrl
? (wxMacMLTEClassicControl
*)(textCtrl
->GetPeer()) : NULL
;
2776 win
->MacControlUserPaneBackgroundProc(info
) ;
2780 #endif // __WXMAC_OSX__
2782 // TXNRegisterScrollInfoProc
2784 OSStatus
wxMacMLTEClassicControl::DoCreate()
2787 OSStatus err
= noErr
;
2789 // set up our globals
2790 #ifdef __WXMAC_OSX__
2791 if (gTPDrawProc
== NULL
) gTPDrawProc
= NewControlUserPaneDrawUPP(wxMacControlUserPaneDrawProc
);
2792 if (gTPHitProc
== NULL
) gTPHitProc
= NewControlUserPaneHitTestUPP(wxMacControlUserPaneHitTestProc
);
2793 if (gTPTrackProc
== NULL
) gTPTrackProc
= NewControlUserPaneTrackingUPP(wxMacControlUserPaneTrackingProc
);
2794 if (gTPIdleProc
== NULL
) gTPIdleProc
= NewControlUserPaneIdleUPP(wxMacControlUserPaneIdleProc
);
2795 if (gTPKeyProc
== NULL
) gTPKeyProc
= NewControlUserPaneKeyDownUPP(wxMacControlUserPaneKeyDownProc
);
2796 if (gTPActivateProc
== NULL
) gTPActivateProc
= NewControlUserPaneActivateUPP(wxMacControlUserPaneActivateProc
);
2797 if (gTPFocusProc
== NULL
) gTPFocusProc
= NewControlUserPaneFocusUPP(wxMacControlUserPaneFocusProc
);
2799 if (gTXNScrollInfoProc
== NULL
) gTXNScrollInfoProc
= NewTXNScrollInfoUPP(TXNScrollInfoProc
) ;
2800 if (gTXNScrollActionProc
== NULL
) gTXNScrollActionProc
= NewControlActionUPP(TXNScrollActionProc
) ;
2803 // set the initial settings for our private data
2805 m_txnWindow
= GetControlOwner(m_controlRef
);
2806 m_txnPort
= (GrafPtr
) GetWindowPort(m_txnWindow
);
2808 #ifdef __WXMAC_OSX__
2809 // set up the user pane procedures
2810 SetControlData(m_controlRef
, kControlEntireControl
, kControlUserPaneDrawProcTag
, sizeof(gTPDrawProc
), &gTPDrawProc
);
2811 SetControlData(m_controlRef
, kControlEntireControl
, kControlUserPaneHitTestProcTag
, sizeof(gTPHitProc
), &gTPHitProc
);
2812 SetControlData(m_controlRef
, kControlEntireControl
, kControlUserPaneTrackingProcTag
, sizeof(gTPTrackProc
), &gTPTrackProc
);
2813 SetControlData(m_controlRef
, kControlEntireControl
, kControlUserPaneIdleProcTag
, sizeof(gTPIdleProc
), &gTPIdleProc
);
2814 SetControlData(m_controlRef
, kControlEntireControl
, kControlUserPaneKeyDownProcTag
, sizeof(gTPKeyProc
), &gTPKeyProc
);
2815 SetControlData(m_controlRef
, kControlEntireControl
, kControlUserPaneActivateProcTag
, sizeof(gTPActivateProc
), &gTPActivateProc
);
2816 SetControlData(m_controlRef
, kControlEntireControl
, kControlUserPaneFocusProcTag
, sizeof(gTPFocusProc
), &gTPFocusProc
);
2819 // calculate the rectangles used by the control
2820 UMAGetControlBoundsInWindowCoords( m_controlRef
, &bounds
);
2822 m_txnControlBounds
= bounds
;
2823 m_txnVisBounds
= bounds
;
2828 GetGWorld( &origPort
, &origDev
) ;
2829 SetPort( m_txnPort
);
2831 // create the new edit field
2832 TXNFrameOptions frameOptions
= FrameOptionsFromWXStyle( m_windowStyle
);
2834 #ifdef __WXMAC_OSX__
2835 // the scrollbars are not correctly embedded but are inserted at the root:
2836 // this gives us problems as we have erratic redraws even over the structure area
2838 m_sbHorizontal
= 0 ;
2840 m_lastHorizontalValue
= 0 ;
2841 m_lastVerticalValue
= 0 ;
2843 Rect sb
= { 0 , 0 , 0 , 0 } ;
2844 if ( frameOptions
& kTXNWantVScrollBarMask
)
2846 CreateScrollBarControl( m_txnWindow
, &sb
, 0, 0, 100, 1, true, gTXNScrollActionProc
, &m_sbVertical
);
2847 SetControlReference( m_sbVertical
, (SInt32
)this );
2848 SetControlAction( m_sbVertical
, gTXNScrollActionProc
);
2849 ShowControl( m_sbVertical
);
2850 EmbedControl( m_sbVertical
, m_controlRef
);
2851 frameOptions
&= ~kTXNWantVScrollBarMask
;
2854 if ( frameOptions
& kTXNWantHScrollBarMask
)
2856 CreateScrollBarControl( m_txnWindow
, &sb
, 0, 0, 100, 1, true, gTXNScrollActionProc
, &m_sbHorizontal
);
2857 SetControlReference( m_sbHorizontal
, (SInt32
)this );
2858 SetControlAction( m_sbHorizontal
, gTXNScrollActionProc
);
2859 ShowControl( m_sbHorizontal
);
2860 EmbedControl( m_sbHorizontal
, m_controlRef
);
2861 frameOptions
&= ~(kTXNWantHScrollBarMask
| kTXNDrawGrowIconMask
);
2867 NULL
, m_txnWindow
, &bounds
, frameOptions
,
2868 kTXNTextEditStyleFrameType
, kTXNTextensionFile
, kTXNSystemDefaultEncoding
,
2869 &m_txn
, &m_txnFrameID
, NULL
);
2870 verify_noerr( err
);
2873 TXNControlTag iControlTags
[] = { kTXNUseCarbonEvents
};
2874 TXNControlData iControlData
[] = { { (UInt32
)&cInfo
} };
2875 int toptag
= WXSIZEOF( iControlTags
) ;
2876 TXNCarbonEventInfo cInfo
;
2877 cInfo
.useCarbonEvents
= false ;
2880 cInfo
.fDictionary
= NULL
;
2882 verify_noerr( TXNSetTXNObjectControls( m_txn
, false, toptag
, iControlTags
, iControlData
) );
2885 #ifdef __WXMAC_OSX__
2886 TXNRegisterScrollInfoProc( m_txn
, gTXNScrollInfoProc
, (SInt32
)this );
2889 SetGWorld( origPort
, origDev
) ;
2894 // ----------------------------------------------------------------------------
2895 // MLTE control implementation (OSX part)
2896 // ----------------------------------------------------------------------------
2898 #if TARGET_API_MAC_OSX
2900 #if MAC_OS_X_VERSION_MAX_ALLOWED > MAC_OS_X_VERSION_10_2
2902 wxMacMLTEHIViewControl::wxMacMLTEHIViewControl( wxTextCtrl
*wxPeer
,
2903 const wxString
& str
,
2905 const wxSize
& size
, long style
) : wxMacMLTEControl( wxPeer
)
2907 m_font
= wxPeer
->GetFont() ;
2908 m_windowStyle
= style
;
2909 Rect bounds
= wxMacGetBoundsForControl( wxPeer
, pos
, size
) ;
2911 wxMacConvertNewlines10To13( &st
) ;
2914 { bounds
.left
, bounds
.top
},
2915 { bounds
.right
- bounds
.left
, bounds
.bottom
- bounds
.top
} } ;
2917 m_scrollView
= NULL
;
2918 TXNFrameOptions frameOptions
= FrameOptionsFromWXStyle( style
) ;
2919 if ( frameOptions
& (kTXNWantVScrollBarMask
| kTXNWantHScrollBarMask
) )
2922 (frameOptions
& kTXNWantHScrollBarMask
? kHIScrollViewOptionsHorizScroll
: 0)
2923 | (frameOptions
& kTXNWantVScrollBarMask
? kHIScrollViewOptionsVertScroll
: 0) ,
2926 HIViewSetFrame( m_scrollView
, &hr
);
2927 HIViewSetVisible( m_scrollView
, true );
2931 HITextViewCreate( NULL
, 0, frameOptions
, &m_textView
) ;
2932 m_txn
= HITextViewGetTXNObject( m_textView
) ;
2933 HIViewSetVisible( m_textView
, true ) ;
2936 HIViewAddSubview( m_scrollView
, m_textView
) ;
2937 m_controlRef
= m_scrollView
;
2938 wxPeer
->MacInstallEventHandler( (WXWidget
) m_textView
) ;
2942 HIViewSetFrame( m_textView
, &hr
);
2943 m_controlRef
= m_textView
;
2946 AdjustCreationAttributes( *wxWHITE
, true ) ;
2948 wxMacWindowClipper
c( m_peer
) ;
2949 SetTXNData( st
, kTXNStartOffset
, kTXNEndOffset
) ;
2951 TXNSetSelection( m_txn
, 0, 0 );
2952 TXNShowSelection( m_txn
, kTXNShowStart
);
2955 OSStatus
wxMacMLTEHIViewControl::SetFocus( ControlFocusPart focusPart
)
2957 return SetKeyboardFocus( GetControlOwner( m_textView
), m_textView
, focusPart
) ;
2960 bool wxMacMLTEHIViewControl::HasFocus() const
2962 ControlRef control
;
2963 GetKeyboardFocus( GetUserFocusWindow() , &control
) ;
2964 return control
== m_textView
;
2967 void wxMacMLTEHIViewControl::SetBackground( const wxBrush
&brush
)
2969 wxMacMLTEControl::SetBackground( brush
) ;
2972 CGColorSpaceRef rgbSpace
= CGColorSpaceCreateDeviceRGB();
2973 RGBColor col
= MAC_WXCOLORREF(brush
.GetColour().GetPixel()) ;
2975 float component
[4] ;
2976 component
[0] = col
.red
/ 65536.0 ;
2977 component
[1] = col
.green
/ 65536.0 ;
2978 component
[2] = col
.blue
/ 65536.0 ;
2979 component
[3] = 1.0 ; // alpha
2981 CGColorRef color
= CGColorCreate( rgbSpace
, component
);
2982 HITextViewSetBackgroundColor( m_textView
, color
);
2983 CGColorSpaceRelease( rgbSpace
);
2987 #endif // MAC_OS_X_VERSION_MAX_ALLOWED > MAC_OS_X_VERSION_10_2
2992 #endif // wxUSE_TEXTCTRL