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 SetStyle(long start
, long end
, const wxTextAttr
& style
) ;
183 virtual void Copy() ;
185 virtual void Paste() ;
186 virtual bool CanPaste() const ;
187 virtual void SetEditable(bool editable
) ;
188 virtual wxTextPos
GetLastPosition() const ;
189 virtual void Replace( long from
, long to
, const wxString
&str
) ;
190 virtual void Remove( long from
, long to
) ;
191 virtual void SetSelection( long from
, long to
) = 0 ;
192 virtual void GetSelection( long* from
, long* to
) const = 0 ;
193 virtual void WriteText(const wxString
& str
) = 0 ;
195 virtual bool HasOwnContextMenu() const
198 virtual bool SetupCursor( const wxPoint
& pt
)
201 virtual void Clear() ;
202 virtual bool CanUndo() const;
203 virtual void Undo() ;
204 virtual bool CanRedo() const;
205 virtual void Redo() ;
206 virtual int GetNumberOfLines() const ;
207 virtual long XYToPosition(long x
, long y
) const;
208 virtual bool PositionToXY(long pos
, long *x
, long *y
) const ;
209 virtual void ShowPosition( long WXUNUSED(pos
) ) ;
210 virtual int GetLineLength(long lineNo
) const ;
211 virtual wxString
GetLineText(long lineNo
) const ;
213 #ifndef __WXMAC_OSX__
214 virtual void MacControlUserPaneDrawProc(wxInt16 part
) = 0 ;
215 virtual wxInt16
MacControlUserPaneHitTestProc(wxInt16 x
, wxInt16 y
) = 0 ;
216 virtual wxInt16
MacControlUserPaneTrackingProc(wxInt16 x
, wxInt16 y
, void* actionProc
) = 0 ;
217 virtual void MacControlUserPaneIdleProc() = 0 ;
218 virtual wxInt16
MacControlUserPaneKeyDownProc(wxInt16 keyCode
, wxInt16 charCode
, wxInt16 modifiers
) = 0 ;
219 virtual void MacControlUserPaneActivateProc(bool activating
) = 0 ;
220 virtual wxInt16
MacControlUserPaneFocusProc(wxInt16 action
) = 0 ;
221 virtual void MacControlUserPaneBackgroundProc(void* info
) = 0 ;
225 // common parts for implementations based on MLTE
227 class wxMacMLTEControl
: public wxMacTextControl
230 wxMacMLTEControl( wxTextCtrl
*peer
) ;
231 virtual wxString
GetStringValue() const ;
232 virtual void SetStringValue( const wxString
&str
) ;
234 static TXNFrameOptions
FrameOptionsFromWXStyle( long wxStyle
) ;
236 void AdjustCreationAttributes( const wxColour
& background
, bool visible
) ;
238 virtual void SetFont( const wxFont
& font
, const wxColour
& foreground
, long windowStyle
) ;
239 virtual void SetBackground( const wxBrush
&brush
) ;
240 virtual void SetStyle(long start
, long end
, const wxTextAttr
& style
) ;
241 virtual void Copy() ;
243 virtual void Paste() ;
244 virtual bool CanPaste() const ;
245 virtual void SetEditable(bool editable
) ;
246 virtual wxTextPos
GetLastPosition() const ;
247 virtual void Replace( long from
, long to
, const wxString
&str
) ;
248 virtual void Remove( long from
, long to
) ;
249 virtual void GetSelection( long* from
, long* to
) const ;
250 virtual void SetSelection( long from
, long to
) ;
252 virtual void WriteText(const wxString
& str
) ;
254 virtual bool HasOwnContextMenu() const
256 #if MAC_OS_X_VERSION_MAX_ALLOWED >= MAC_OS_X_VERSION_10_4
257 if ( UMAGetSystemVersion() >= 0x1040 )
259 TXNCommandEventSupportOptions options
;
260 TXNGetCommandEventSupport( m_txn
, & options
) ;
261 return options
& kTXNSupportEditCommandProcessing
;
268 virtual void Clear() ;
270 virtual bool CanUndo() const ;
271 virtual void Undo() ;
272 virtual bool CanRedo() const;
273 virtual void Redo() ;
274 virtual int GetNumberOfLines() const ;
275 virtual long XYToPosition(long x
, long y
) const ;
276 virtual bool PositionToXY(long pos
, long *x
, long *y
) const ;
277 virtual void ShowPosition( long pos
) ;
278 virtual int GetLineLength(long lineNo
) const ;
279 virtual wxString
GetLineText(long lineNo
) const ;
281 void SetTXNData( const wxString
& st
, TXNOffset start
, TXNOffset end
) ;
284 void TXNSetAttribute( const wxTextAttr
& style
, long from
, long to
) ;
289 #if TARGET_API_MAC_OSX
291 // implementation available under OSX
293 #if MAC_OS_X_VERSION_MAX_ALLOWED > MAC_OS_X_VERSION_10_2
295 class wxMacMLTEHIViewControl
: public wxMacMLTEControl
298 wxMacMLTEHIViewControl( wxTextCtrl
*wxPeer
,
301 const wxSize
& size
, long style
) ;
302 virtual OSStatus
SetFocus( ControlFocusPart focusPart
) ;
303 virtual bool HasFocus() const ;
304 virtual void SetBackground( const wxBrush
&brush
) ;
307 HIViewRef m_scrollView
;
308 HIViewRef m_textView
;
313 class wxMacUnicodeTextControl
: public wxMacTextControl
316 wxMacUnicodeTextControl( wxTextCtrl
*wxPeer
,
319 const wxSize
& size
, long style
) ;
320 ~wxMacUnicodeTextControl();
322 virtual void VisibilityChanged(bool shown
);
323 virtual wxString
GetStringValue() const ;
324 virtual void SetStringValue( const wxString
&str
) ;
327 virtual void Paste();
328 virtual bool CanPaste() const;
329 virtual void SetEditable(bool editable
) ;
330 virtual void GetSelection( long* from
, long* to
) const ;
331 virtual void SetSelection( long from
, long to
) ;
332 virtual void WriteText(const wxString
& str
) ;
335 // contains the tag for the content (is different for password and non-password controls)
341 // 'classic' MLTE implementation
343 class wxMacMLTEClassicControl
: public wxMacMLTEControl
346 wxMacMLTEClassicControl( wxTextCtrl
*wxPeer
,
349 const wxSize
& size
, long style
) ;
350 ~wxMacMLTEClassicControl() ;
351 virtual void VisibilityChanged(bool shown
) ;
352 virtual void SuperChangedPosition() ;
354 virtual void MacControlUserPaneDrawProc(wxInt16 part
) ;
355 virtual wxInt16
MacControlUserPaneHitTestProc(wxInt16 x
, wxInt16 y
) ;
356 virtual wxInt16
MacControlUserPaneTrackingProc(wxInt16 x
, wxInt16 y
, void* actionProc
) ;
357 virtual void MacControlUserPaneIdleProc() ;
358 virtual wxInt16
MacControlUserPaneKeyDownProc(wxInt16 keyCode
, wxInt16 charCode
, wxInt16 modifiers
) ;
359 virtual void MacControlUserPaneActivateProc(bool activating
) ;
360 virtual wxInt16
MacControlUserPaneFocusProc(wxInt16 action
) ;
361 virtual void MacControlUserPaneBackgroundProc(void* info
) ;
363 virtual bool SetupCursor( const wxPoint
& WXUNUSED(pt
) ) { MacControlUserPaneIdleProc() ; return true ;}
365 virtual void SetRect( Rect
*r
) ;
370 void MacUpdatePosition() ;
371 void MacActivatePaneText(bool setActive
) ;
372 void MacFocusPaneText(bool setFocus
) ;
373 void MacSetObjectVisibility(bool vis
) ;
376 TXNFrameID m_txnFrameID
;
378 WindowRef m_txnWindow
;
379 // bounds of the control as we last did set the txn frames
380 Rect m_txnControlBounds
;
381 Rect m_txnVisBounds
;
384 static pascal void TXNScrollActionProc( ControlRef controlRef
, ControlPartCode partCode
) ;
385 static pascal void TXNScrollInfoProc(
386 SInt32 iValue
, SInt32 iMaximumValue
,
387 TXNScrollBarOrientation iScrollBarOrientation
, SInt32 iRefCon
) ;
389 ControlRef m_sbHorizontal
;
390 SInt32 m_lastHorizontalValue
;
391 ControlRef m_sbVertical
;
392 SInt32 m_lastVerticalValue
;
396 #define TE_UNLIMITED_LENGTH 0xFFFFFFFFUL
399 IMPLEMENT_DYNAMIC_CLASS(wxTextCtrl
, wxControl
)
401 BEGIN_EVENT_TABLE(wxTextCtrl
, wxControl
)
402 EVT_ERASE_BACKGROUND( wxTextCtrl
::OnEraseBackground
)
403 EVT_DROP_FILES(wxTextCtrl
::OnDropFiles
)
404 EVT_CHAR(wxTextCtrl
::OnChar
)
405 EVT_MENU(wxID_CUT
, wxTextCtrl
::OnCut
)
406 EVT_MENU(wxID_COPY
, wxTextCtrl
::OnCopy
)
407 EVT_MENU(wxID_PASTE
, wxTextCtrl
::OnPaste
)
408 EVT_MENU(wxID_UNDO
, wxTextCtrl
::OnUndo
)
409 EVT_MENU(wxID_REDO
, wxTextCtrl
::OnRedo
)
410 EVT_MENU(wxID_CLEAR
, wxTextCtrl
::OnDelete
)
411 EVT_MENU(wxID_SELECTALL
, wxTextCtrl
::OnSelectAll
)
413 EVT_CONTEXT_MENU(wxTextCtrl
::OnContextMenu
)
415 EVT_UPDATE_UI(wxID_CUT
, wxTextCtrl
::OnUpdateCut
)
416 EVT_UPDATE_UI(wxID_COPY
, wxTextCtrl
::OnUpdateCopy
)
417 EVT_UPDATE_UI(wxID_PASTE
, wxTextCtrl
::OnUpdatePaste
)
418 EVT_UPDATE_UI(wxID_UNDO
, wxTextCtrl
::OnUpdateUndo
)
419 EVT_UPDATE_UI(wxID_REDO
, wxTextCtrl
::OnUpdateRedo
)
420 EVT_UPDATE_UI(wxID_CLEAR
, wxTextCtrl
::OnUpdateDelete
)
421 EVT_UPDATE_UI(wxID_SELECTALL
, wxTextCtrl
::OnUpdateSelectAll
)
426 void wxTextCtrl
::Init()
431 m_privateContextMenu
= NULL
;
433 m_maxLength
= TE_UNLIMITED_LENGTH
;
436 wxTextCtrl
::~wxTextCtrl()
438 delete m_privateContextMenu
;
441 bool wxTextCtrl
::Create(wxWindow
*parent
, wxWindowID id
,
444 const wxSize
& size
, long style
,
445 const wxValidator
& validator
,
446 const wxString
& name
)
448 m_macIsUserPane
= false ;
451 if ( ! ( style
& wxNO_BORDER
) )
452 style
= ( style
& ~wxBORDER_MASK
) | wxSUNKEN_BORDER
;
454 if ( !wxTextCtrlBase
::Create(parent
, id
, pos
, size
, style
& ~(wxHSCROLL
|wxVSCROLL
), validator
, name
) )
457 if ( m_windowStyle
& wxTE_MULTILINE
)
459 wxASSERT_MSG( !(m_windowStyle
& wxTE_PROCESS_ENTER
),
460 wxT("wxTE_PROCESS_ENTER style is ignored for multiline text controls (they always process it)") );
462 m_windowStyle
|= wxTE_PROCESS_ENTER
;
463 style
|= wxTE_PROCESS_ENTER
;
466 bool forceMLTE
= false ;
468 #if wxUSE_SYSTEM_OPTIONS
469 if ( (wxSystemOptions
::HasOption(wxMAC_TEXTCONTROL_USE_MLTE
) ) && ( wxSystemOptions
::GetOptionInt( wxMAC_TEXTCONTROL_USE_MLTE
) == 1) )
476 #if MAC_OS_X_VERSION_MAX_ALLOWED > MAC_OS_X_VERSION_10_2
477 if ( UMAGetSystemVersion() >= 0x1030 && forceMLTE
== false )
479 if ( m_windowStyle
& wxTE_MULTILINE
)
480 m_peer
= new wxMacMLTEHIViewControl( this , str
, pos
, size
, style
) ;
486 if ( !(m_windowStyle
& wxTE_MULTILINE
) && forceMLTE
== false )
487 m_peer
= new wxMacUnicodeTextControl( this , str
, pos
, size
, style
) ;
493 m_peer
= new wxMacMLTEClassicControl( this , str
, pos
, size
, style
) ;
496 MacPostControlCreate(pos
,size
) ;
498 // only now the embedding is correct and we can do a positioning update
500 MacSuperChangedPosition() ;
502 if ( m_windowStyle
& wxTE_READONLY
)
503 SetEditable( false ) ;
505 SetCursor( wxCursor( wxCURSOR_IBEAM
) ) ;
510 void wxTextCtrl
::MacSuperChangedPosition()
512 wxWindow
::MacSuperChangedPosition() ;
513 GetPeer()->SuperChangedPosition() ;
516 void wxTextCtrl
::MacVisibilityChanged()
518 GetPeer()->VisibilityChanged( MacIsReallyShown() ) ;
521 void wxTextCtrl
::MacEnabledStateChanged()
525 wxString wxTextCtrl
::GetValue() const
527 return GetPeer()->GetStringValue() ;
530 void wxTextCtrl
::GetSelection(long* from
, long* to
) const
532 GetPeer()->GetSelection( from
, to
) ;
535 void wxTextCtrl
::SetValue(const wxString
& str
)
538 if ( GetValue() == str
)
541 GetPeer()->SetStringValue(str
) ;
543 wxCommandEvent
event(wxEVT_COMMAND_TEXT_UPDATED
, m_windowId
);
544 event
.SetString( GetValue() ) ;
545 event
.SetEventObject( this );
546 GetEventHandler()->ProcessEvent(event
);
549 void wxTextCtrl
::SetMaxLength(unsigned long len
)
554 bool wxTextCtrl
::SetFont( const wxFont
& font
)
556 if ( !wxTextCtrlBase
::SetFont( font
) )
559 GetPeer()->SetFont( font
, GetForegroundColour() , GetWindowStyle() ) ;
564 bool wxTextCtrl
::SetStyle(long start
, long end
, const wxTextAttr
& style
)
566 GetPeer()->SetStyle( start
, end
, style
) ;
571 bool wxTextCtrl
::SetDefaultStyle(const wxTextAttr
& style
)
573 wxTextCtrlBase
::SetDefaultStyle( style
) ;
574 SetStyle( kTXNUseCurrentSelection
, kTXNUseCurrentSelection
, GetDefaultStyle() ) ;
579 // Clipboard operations
581 void wxTextCtrl
::Copy()
587 void wxTextCtrl
::Cut()
593 wxCommandEvent
event(wxEVT_COMMAND_TEXT_UPDATED
, m_windowId
);
594 event
.SetEventObject( this );
595 GetEventHandler()->ProcessEvent(event
);
599 void wxTextCtrl
::Paste()
605 // TODO: eventually we should add setting the default style again
607 wxCommandEvent
event(wxEVT_COMMAND_TEXT_UPDATED
, m_windowId
);
608 event
.SetEventObject( this );
609 GetEventHandler()->ProcessEvent(event
);
613 bool wxTextCtrl
::CanCopy() const
615 // Can copy if there's a selection
617 GetSelection(& from
, & to
);
621 bool wxTextCtrl
::CanCut() const
626 // Can cut if there's a selection
628 GetSelection(& from
, & to
);
632 bool wxTextCtrl
::CanPaste() const
637 return GetPeer()->CanPaste() ;
640 void wxTextCtrl
::SetEditable(bool editable
)
642 if ( editable
!= m_editable
)
644 m_editable
= editable
;
645 GetPeer()->SetEditable( editable
) ;
649 void wxTextCtrl
::SetInsertionPoint(long pos
)
651 SetSelection( pos
, pos
) ;
654 void wxTextCtrl
::SetInsertionPointEnd()
656 wxTextPos pos
= GetLastPosition();
657 SetInsertionPoint(pos
);
660 long wxTextCtrl
::GetInsertionPoint() const
663 GetSelection( &begin
, &end
) ;
667 wxTextPos wxTextCtrl
::GetLastPosition() const
669 return GetPeer()->GetLastPosition( ) ;
672 void wxTextCtrl
::Replace(long from
, long to
, const wxString
& str
)
674 GetPeer()->Replace( from
, to
, str
) ;
677 void wxTextCtrl
::Remove(long from
, long to
)
679 GetPeer()->Remove( from
, to
) ;
682 void wxTextCtrl
::SetSelection(long from
, long to
)
684 GetPeer()->SetSelection( from
, to
) ;
687 bool wxTextCtrl
::LoadFile(const wxString
& file
)
689 if ( wxTextCtrlBase
::LoadFile(file
) )
695 void wxTextCtrl
::WriteText(const wxString
& str
)
697 // TODO: this MPRemoting will be moved into a remoting peer proxy for any command
698 if ( !wxIsMainThread() )
700 // unfortunately CW 8 is not able to correctly deduce the template types,
701 // so we have to instantiate explicitly
702 wxMacMPRemoteGUICall
<wxTextCtrl
,wxString
>( this , &wxTextCtrl
::WriteText
, str
) ;
707 GetPeer()->WriteText( str
) ;
711 void wxTextCtrl
::AppendText(const wxString
& text
)
713 SetInsertionPointEnd();
717 void wxTextCtrl
::Clear()
722 bool wxTextCtrl
::IsModified() const
727 bool wxTextCtrl
::IsEditable() const
729 return IsEnabled() && m_editable
;
732 bool wxTextCtrl
::AcceptsFocus() const
734 // we don't want focus if we can't be edited
735 return /*IsEditable() && */ wxControl
::AcceptsFocus();
738 wxSize wxTextCtrl
::DoGetBestSize() const
744 // these are the numbers from the HIG:
745 // we reduce them by the borders first
747 switch ( m_windowVariant
)
749 case wxWINDOW_VARIANT_NORMAL
:
753 case wxWINDOW_VARIANT_SMALL
:
757 case wxWINDOW_VARIANT_MINI
:
766 // as the above numbers have some free space around the text
767 // we get 5 lines like this anyway
768 if ( m_windowStyle
& wxTE_MULTILINE
)
771 if ( !HasFlag(wxNO_BORDER
) )
774 return wxSize(wText
, hText
);
777 // ----------------------------------------------------------------------------
779 // ----------------------------------------------------------------------------
781 void wxTextCtrl
::Undo()
787 void wxTextCtrl
::Redo()
793 bool wxTextCtrl
::CanUndo() const
798 return GetPeer()->CanUndo() ;
801 bool wxTextCtrl
::CanRedo() const
806 return GetPeer()->CanRedo() ;
809 void wxTextCtrl
::MarkDirty()
814 void wxTextCtrl
::DiscardEdits()
819 int wxTextCtrl
::GetNumberOfLines() const
821 return GetPeer()->GetNumberOfLines() ;
824 long wxTextCtrl
::XYToPosition(long x
, long y
) const
826 return GetPeer()->XYToPosition( x
, y
) ;
829 bool wxTextCtrl
::PositionToXY(long pos
, long *x
, long *y
) const
831 return GetPeer()->PositionToXY(pos
, x
, y
) ;
834 void wxTextCtrl
::ShowPosition(long pos
)
836 return GetPeer()->ShowPosition(pos
) ;
839 int wxTextCtrl
::GetLineLength(long lineNo
) const
841 return GetPeer()->GetLineLength(lineNo
) ;
844 wxString wxTextCtrl
::GetLineText(long lineNo
) const
846 return GetPeer()->GetLineText(lineNo
) ;
849 void wxTextCtrl
::Command(wxCommandEvent
& event
)
851 SetValue (event
.GetString());
852 ProcessCommand (event
);
855 void wxTextCtrl
::OnDropFiles(wxDropFilesEvent
& event
)
857 // By default, load the first file into the text window.
858 if (event
.GetNumberOfFiles() > 0)
859 LoadFile(event
.GetFiles()[0]);
862 void wxTextCtrl
::OnEraseBackground(wxEraseEvent
& event
)
864 // all erasing should be done by the real mac control implementation
865 // while this is true for MLTE under classic, the HITextView is somehow
866 // transparent but background erase is not working correctly, so intercept
867 // things while we can...
871 void wxTextCtrl
::OnChar(wxKeyEvent
& event
)
873 int key
= event
.GetKeyCode() ;
874 bool eat_key
= false ;
876 if ( key
== 'c' && event
.MetaDown() )
884 if ( !IsEditable() && key
!= WXK_LEFT
&& key
!= WXK_RIGHT
&& key
!= WXK_DOWN
&& key
!= WXK_UP
&& key
!= WXK_TAB
&&
885 !( key
== WXK_RETURN
&& ( (m_windowStyle
& wxPROCESS_ENTER
) || (m_windowStyle
& wxTE_MULTILINE
) ) )
886 // && key != WXK_PRIOR && key != WXK_NEXT && key != WXK_HOME && key != WXK_END
893 // Check if we have reached the max # of chars, but still allow navigation and deletion
894 if ( !IsMultiLine() && GetValue().Length() >= m_maxLength
&&
895 key
!= WXK_LEFT
&& key
!= WXK_RIGHT
&& key
!= WXK_TAB
&&
896 key
!= WXK_BACK
&& !( key
== WXK_RETURN
&& (m_windowStyle
& wxPROCESS_ENTER
) )
899 // eat it, we don't want to add more than allowed # of characters
903 // assume that any key not processed yet is going to modify the control
906 if ( key
== 'v' && event
.MetaDown() )
914 if ( key
== 'x' && event
.MetaDown() )
925 if (m_windowStyle
& wxPROCESS_ENTER
)
927 wxCommandEvent
event(wxEVT_COMMAND_TEXT_ENTER
, m_windowId
);
928 event
.SetEventObject( this );
929 event
.SetString( GetValue() );
930 if ( GetEventHandler()->ProcessEvent(event
) )
934 if ( !(m_windowStyle
& wxTE_MULTILINE
) )
936 wxWindow
*parent
= GetParent();
937 while ( parent
&& !parent
->IsTopLevel() && parent
->GetDefaultItem() == NULL
)
939 parent
= parent
->GetParent() ;
942 if ( parent
&& parent
->GetDefaultItem() )
944 wxButton
*def
= wxDynamicCast(parent
->GetDefaultItem(), wxButton
);
945 if ( def
&& def
->IsEnabled() )
947 wxCommandEvent
event(wxEVT_COMMAND_BUTTON_CLICKED
, def
->GetId() );
948 event
.SetEventObject(def
);
955 // this will make wxWidgets eat the ENTER key so that
956 // we actually prevent line wrapping in a single line text control
962 if ( !(m_windowStyle
& wxTE_PROCESS_TAB
))
965 if (!event
.ShiftDown())
966 flags
|= wxNavigationKeyEvent
::IsForward
;
967 if (event
.ControlDown())
968 flags
|= wxNavigationKeyEvent
::WinChange
;
975 // This is necessary (don't know why);
976 // otherwise the tab will not be inserted.
977 WriteText(wxT("\t"));
987 // perform keystroke handling
988 if ( wxTheApp
->MacGetCurrentEvent() != NULL
&& wxTheApp
->MacGetCurrentEventHandlerCallRef() != NULL
)
989 CallNextEventHandler((EventHandlerCallRef
)wxTheApp
->MacGetCurrentEventHandlerCallRef() , (EventRef
) wxTheApp
->MacGetCurrentEvent() ) ;
993 if ( wxMacConvertEventToRecord( (EventRef
) wxTheApp
->MacGetCurrentEvent() , &rec
) )
995 EventRecord
*ev
= &rec
;
996 short keycode
, keychar
;
997 keychar
= short(ev
->message
& charCodeMask
);
998 keycode
= short(ev
->message
& keyCodeMask
) >> 8 ;
1000 m_peer
->HandleKey( keycode
, keychar
, ev
->modifiers
) ;
1005 if ( ( key
>= 0x20 && key
< WXK_START
) ||
1006 key
== WXK_RETURN
||
1007 key
== WXK_DELETE
||
1010 wxCommandEvent
event1(wxEVT_COMMAND_TEXT_UPDATED
, m_windowId
);
1011 event1
.SetEventObject( this );
1012 wxPostEvent(GetEventHandler(),event1
);
1016 // ----------------------------------------------------------------------------
1017 // standard handlers for standard edit menu events
1018 // ----------------------------------------------------------------------------
1020 void wxTextCtrl
::OnCut(wxCommandEvent
& WXUNUSED(event
))
1025 void wxTextCtrl
::OnCopy(wxCommandEvent
& WXUNUSED(event
))
1030 void wxTextCtrl
::OnPaste(wxCommandEvent
& WXUNUSED(event
))
1035 void wxTextCtrl
::OnUndo(wxCommandEvent
& WXUNUSED(event
))
1040 void wxTextCtrl
::OnRedo(wxCommandEvent
& WXUNUSED(event
))
1045 void wxTextCtrl
::OnDelete(wxCommandEvent
& WXUNUSED(event
))
1048 GetSelection(& from
, & to
);
1049 if (from
!= -1 && to
!= -1)
1053 void wxTextCtrl
::OnSelectAll(wxCommandEvent
& WXUNUSED(event
))
1055 SetSelection(-1, -1);
1058 void wxTextCtrl
::OnUpdateCut(wxUpdateUIEvent
& event
)
1060 event
.Enable( CanCut() );
1063 void wxTextCtrl
::OnUpdateCopy(wxUpdateUIEvent
& event
)
1065 event
.Enable( CanCopy() );
1068 void wxTextCtrl
::OnUpdatePaste(wxUpdateUIEvent
& event
)
1070 event
.Enable( CanPaste() );
1073 void wxTextCtrl
::OnUpdateUndo(wxUpdateUIEvent
& event
)
1075 event
.Enable( CanUndo() );
1078 void wxTextCtrl
::OnUpdateRedo(wxUpdateUIEvent
& event
)
1080 event
.Enable( CanRedo() );
1083 void wxTextCtrl
::OnUpdateDelete(wxUpdateUIEvent
& event
)
1086 GetSelection(& from
, & to
);
1087 event
.Enable( from
!= -1 && to
!= -1 && from
!= to
&& IsEditable() ) ;
1090 void wxTextCtrl
::OnUpdateSelectAll(wxUpdateUIEvent
& event
)
1092 event
.Enable(GetLastPosition() > 0);
1095 // CS: Context Menus only work with MLTE implementations or non-multiline HIViews at the moment
1097 void wxTextCtrl
::OnContextMenu(wxContextMenuEvent
& event
)
1099 if ( GetPeer()->HasOwnContextMenu() )
1105 if (m_privateContextMenu
== NULL
)
1107 m_privateContextMenu
= new wxMenu
;
1108 m_privateContextMenu
->Append(wxID_UNDO
, _("&Undo"));
1109 m_privateContextMenu
->Append(wxID_REDO
, _("&Redo"));
1110 m_privateContextMenu
->AppendSeparator();
1111 m_privateContextMenu
->Append(wxID_CUT
, _("Cu&t"));
1112 m_privateContextMenu
->Append(wxID_COPY
, _("&Copy"));
1113 m_privateContextMenu
->Append(wxID_PASTE
, _("&Paste"));
1114 m_privateContextMenu
->Append(wxID_CLEAR
, _("&Delete"));
1115 m_privateContextMenu
->AppendSeparator();
1116 m_privateContextMenu
->Append(wxID_SELECTALL
, _("Select &All"));
1119 if (m_privateContextMenu
!= NULL
)
1120 PopupMenu(m_privateContextMenu
);
1123 bool wxTextCtrl
::MacSetupCursor( const wxPoint
& pt
)
1125 if ( !GetPeer()->SetupCursor( pt
) )
1126 return wxWindow
::MacSetupCursor( pt
) ;
1131 #if !TARGET_API_MAC_OSX
1133 // user pane implementation
1135 void wxTextCtrl
::MacControlUserPaneDrawProc(wxInt16 part
)
1137 GetPeer()->MacControlUserPaneDrawProc( part
) ;
1140 wxInt16 wxTextCtrl
::MacControlUserPaneHitTestProc(wxInt16 x
, wxInt16 y
)
1142 return GetPeer()->MacControlUserPaneHitTestProc( x
, y
) ;
1145 wxInt16 wxTextCtrl
::MacControlUserPaneTrackingProc(wxInt16 x
, wxInt16 y
, void* actionProc
)
1147 return GetPeer()->MacControlUserPaneTrackingProc( x
, y
, actionProc
) ;
1150 void wxTextCtrl
::MacControlUserPaneIdleProc()
1152 GetPeer()->MacControlUserPaneIdleProc( ) ;
1155 wxInt16 wxTextCtrl
::MacControlUserPaneKeyDownProc(wxInt16 keyCode
, wxInt16 charCode
, wxInt16 modifiers
)
1157 return GetPeer()->MacControlUserPaneKeyDownProc( keyCode
, charCode
, modifiers
) ;
1160 void wxTextCtrl
::MacControlUserPaneActivateProc(bool activating
)
1162 GetPeer()->MacControlUserPaneActivateProc( activating
) ;
1165 wxInt16 wxTextCtrl
::MacControlUserPaneFocusProc(wxInt16 action
)
1167 return GetPeer()->MacControlUserPaneFocusProc( action
) ;
1170 void wxTextCtrl
::MacControlUserPaneBackgroundProc(void* info
)
1172 GetPeer()->MacControlUserPaneBackgroundProc( info
) ;
1177 // ----------------------------------------------------------------------------
1178 // implementation base class
1179 // ----------------------------------------------------------------------------
1181 wxMacTextControl
::wxMacTextControl(wxTextCtrl
* peer
) :
1182 wxMacControl( peer
)
1186 wxMacTextControl
::~wxMacTextControl()
1190 void wxMacTextControl
::SetStyle(long start
, long end
, const wxTextAttr
& style
)
1194 void wxMacTextControl
::Copy()
1198 void wxMacTextControl
::Cut()
1202 void wxMacTextControl
::Paste()
1206 bool wxMacTextControl
::CanPaste() const
1211 void wxMacTextControl
::SetEditable(bool editable
)
1215 wxTextPos wxMacTextControl
::GetLastPosition() const
1217 return GetStringValue().Length() ;
1220 void wxMacTextControl
::Replace( long from
, long to
, const wxString
&val
)
1222 SetSelection( from
, to
) ;
1226 void wxMacTextControl
::Remove( long from
, long to
)
1228 SetSelection( from
, to
) ;
1229 WriteText( wxEmptyString
) ;
1232 void wxMacTextControl
::Clear()
1234 SetStringValue( wxEmptyString
) ;
1237 bool wxMacTextControl
::CanUndo() const
1242 void wxMacTextControl
::Undo()
1246 bool wxMacTextControl
::CanRedo() const
1251 void wxMacTextControl
::Redo()
1255 long wxMacTextControl
::XYToPosition(long x
, long y
) const
1260 bool wxMacTextControl
::PositionToXY(long pos
, long *x
, long *y
) const
1265 void wxMacTextControl
::ShowPosition( long WXUNUSED(pos
) )
1269 int wxMacTextControl
::GetNumberOfLines() const
1271 ItemCount lines
= 0 ;
1272 wxString content
= GetStringValue() ;
1275 for (size_t i
= 0; i
< content
.Length() ; i
++)
1277 if (content
[i
] == '\r')
1284 wxString wxMacTextControl
::GetLineText(long lineNo
) const
1286 // TODO: change this if possible to reflect real lines
1287 wxString content
= GetStringValue() ;
1291 for (size_t i
= 0; i
< content
.Length() ; i
++)
1293 if (count
== lineNo
)
1295 // Add chars in line then
1298 for (size_t j
= i
; j
< content
.Length(); j
++)
1300 if (content
[j
] == '\n')
1309 if (content
[i
] == '\n')
1313 return wxEmptyString
;
1316 int wxMacTextControl
::GetLineLength(long lineNo
) const
1318 // TODO: change this if possible to reflect real lines
1319 wxString content
= GetStringValue() ;
1323 for (size_t i
= 0; i
< content
.Length() ; i
++)
1325 if (count
== lineNo
)
1327 // Count chars in line then
1329 for (size_t j
= i
; j
< content
.Length(); j
++)
1332 if (content
[j
] == '\n')
1339 if (content
[i
] == '\n')
1346 // ----------------------------------------------------------------------------
1347 // standard unicode control implementation
1348 // ----------------------------------------------------------------------------
1350 #if TARGET_API_MAC_OSX
1352 wxMacUnicodeTextControl
::wxMacUnicodeTextControl( wxTextCtrl
*wxPeer
,
1353 const wxString
& str
,
1355 const wxSize
& size
, long style
) : wxMacTextControl( wxPeer
)
1357 m_font
= wxPeer
->GetFont() ;
1358 m_windowStyle
= style
;
1359 Rect bounds
= wxMacGetBoundsForControl( wxPeer
, pos
, size
) ;
1361 wxMacConvertNewlines10To13( &st
) ;
1362 wxMacCFStringHolder
cf(st
, m_font
.GetEncoding()) ;
1363 CFStringRef cfr
= cf
;
1364 Boolean isPassword
= ( m_windowStyle
& wxTE_PASSWORD
) != 0 ;
1365 m_valueTag
= isPassword ? kControlEditTextPasswordCFStringTag
: kControlEditTextCFStringTag
;
1366 CreateEditUnicodeTextControl(
1367 MAC_WXHWND(wxPeer
->MacGetTopLevelWindowRef()), &bounds
, cfr
,
1368 isPassword
, NULL
, &m_controlRef
) ;
1370 if ( !(m_windowStyle
& wxTE_MULTILINE
) )
1371 SetData
<Boolean
>( kControlEditTextPart
, kControlEditTextSingleLineTag
, true ) ;
1374 wxMacUnicodeTextControl
::~wxMacUnicodeTextControl()
1378 void wxMacUnicodeTextControl
::VisibilityChanged(bool shown
)
1380 if ( !(m_windowStyle
& wxTE_MULTILINE
) && shown
)
1382 // work around a refresh issue insofar as not always the entire content is shown,
1383 // even if this would be possible
1384 ControlEditTextSelectionRec sel
;
1385 CFStringRef value
= NULL
;
1387 verify_noerr( GetData
<ControlEditTextSelectionRec
>( 0, kControlEditTextSelectionTag
, &sel
) );
1388 verify_noerr( GetData
<CFStringRef
>( 0, m_valueTag
, &value
) );
1389 verify_noerr( SetData
<CFStringRef
>( 0, m_valueTag
, &value
) );
1390 verify_noerr( SetData
<ControlEditTextSelectionRec
>( 0, kControlEditTextSelectionTag
, &sel
) );
1392 CFRelease( value
) ;
1396 wxString wxMacUnicodeTextControl
::GetStringValue() const
1399 CFStringRef value
= GetData
<CFStringRef
>(0,m_valueTag
) ;
1402 wxMacCFStringHolder
cf(value
) ;
1403 result
= cf
.AsString() ;
1407 wxMacConvertNewlines13To10( &result
) ;
1409 wxMacConvertNewlines10To13( &result
) ;
1415 void wxMacUnicodeTextControl
::SetStringValue( const wxString
&str
)
1418 wxMacConvertNewlines10To13( &st
) ;
1419 wxMacCFStringHolder
cf(st
, m_font
.GetEncoding() ) ;
1420 verify_noerr( SetData
<CFStringRef
>( 0, m_valueTag
, cf
) ) ;
1423 void wxMacUnicodeTextControl
::Copy()
1425 SendHICommand( kHICommandCopy
) ;
1428 void wxMacUnicodeTextControl
::Cut()
1430 SendHICommand( kHICommandCut
) ;
1433 void wxMacUnicodeTextControl
::Paste()
1435 SendHICommand( kHICommandPaste
) ;
1438 bool wxMacUnicodeTextControl
::CanPaste() const
1443 void wxMacUnicodeTextControl
::SetEditable(bool editable
)
1445 SetData
<Boolean
>( 0 , kControlEditTextLockedTag
, (Boolean
) !editable
) ;
1448 void wxMacUnicodeTextControl
::GetSelection( long* from
, long* to
) const
1450 ControlEditTextSelectionRec sel
;
1451 verify_noerr( GetData
<ControlEditTextSelectionRec
>( 0, kControlEditTextSelectionTag
, &sel
) ) ;
1453 *from
= sel
.selStart
;
1458 void wxMacUnicodeTextControl
::SetSelection( long from
, long to
)
1460 ControlEditTextSelectionRec sel
;
1461 if ((from
== -1) && (to
== -1))
1464 to
= 32767 ; // sel has 16 bit signed values, max is 32767
1467 sel
.selStart
= from
;
1469 SetData
<ControlEditTextSelectionRec
>( 0, kControlEditTextSelectionTag
, &sel
) ;
1472 void wxMacUnicodeTextControl
::WriteText(const wxString
& str
)
1475 wxMacConvertNewlines10To13( &st
) ;
1477 #if MAC_OS_X_VERSION_MAX_ALLOWED > MAC_OS_X_VERSION_10_2
1478 wxMacCFStringHolder
cf(st
, m_font
.GetEncoding() ) ;
1479 CFStringRef value
= cf
;
1480 SetData
<CFStringRef
>( 0, kControlEditTextInsertCFStringRefTag
, &value
);
1482 wxString val
= GetStringValue() ;
1484 GetSelection( &start
, &end
) ;
1485 val
.Remove( start
, end
- start
) ;
1486 val
.insert( start
, str
) ;
1487 SetStringValue( val
) ;
1488 SetSelection( start
+ str
.Length() , start
+ str
.Length() ) ;
1494 // ----------------------------------------------------------------------------
1495 // MLTE control implementation (common part)
1496 // ----------------------------------------------------------------------------
1498 // if MTLE is read only, no changes at all are allowed, not even from
1499 // procedural API, in order to allow changes via API all the same we must undo
1500 // the readonly status while we are executing, this class helps to do so
1502 class wxMacEditHelper
1505 wxMacEditHelper( TXNObject txn
)
1507 TXNControlTag tag
[] = { kTXNIOPrivilegesTag
} ;
1509 TXNGetTXNObjectControls( m_txn
, 1 , tag
, m_data
) ;
1510 if ( m_data
[0].uValue
== kTXNReadOnly
)
1512 TXNControlData data
[] = { { kTXNReadWrite
} } ;
1513 TXNSetTXNObjectControls( m_txn
, false , 1 , tag
, data
) ;
1519 TXNControlTag tag
[] = { kTXNIOPrivilegesTag
} ;
1520 if ( m_data
[0].uValue
== kTXNReadOnly
)
1521 TXNSetTXNObjectControls( m_txn
, false , 1 , tag
, m_data
) ;
1526 TXNControlData m_data
[1] ;
1529 wxMacMLTEControl
::wxMacMLTEControl( wxTextCtrl
*peer
) : wxMacTextControl( peer
)
1531 SetNeedsFocusRect( true ) ;
1534 wxString wxMacMLTEControl
::GetStringValue() const
1538 Size actualSize
= 0;
1542 err
= TXNGetDataEncoded( m_txn
, kTXNStartOffset
, kTXNEndOffset
, &theText
, kTXNUnicodeTextData
);
1551 actualSize
= GetHandleSize( theText
) / sizeof( UniChar
) ;
1552 if ( actualSize
> 0 )
1554 wxChar
*ptr
= NULL
;
1556 #if SIZEOF_WCHAR_T == 2
1557 ptr
= new wxChar
[actualSize
+ 1 ] ;
1558 wxStrncpy( ptr
, (wxChar
*) *theText
, actualSize
) ;
1560 SetHandleSize( theText
, ( actualSize
+ 1 ) * sizeof( UniChar
) ) ;
1562 (((UniChar
*)*theText
)[actualSize
]) = 0 ;
1563 wxMBConvUTF16 converter
;
1564 size_t noChars
= converter
.MB2WC( NULL
, (const char*)*theText
, 0 ) ;
1565 ptr
= new wxChar
[noChars
+ 1] ;
1567 noChars
= converter
.MB2WC( ptr
, (const char*)*theText
, noChars
) ;
1569 HUnlock( theText
) ;
1572 ptr
[actualSize
] = 0 ;
1573 result
= wxString( ptr
) ;
1577 DisposeHandle( theText
) ;
1581 err
= TXNGetDataEncoded( m_txn
, kTXNStartOffset
, kTXNEndOffset
, &theText
, kTXNTextData
);
1590 actualSize
= GetHandleSize( theText
) ;
1591 if ( actualSize
> 0 )
1594 result
= wxString( *theText
, wxConvLocal
, actualSize
) ;
1595 HUnlock( theText
) ;
1598 DisposeHandle( theText
) ;
1604 wxMacConvertNewlines13To10( &result
) ;
1606 wxMacConvertNewlines10To13( &result
) ;
1612 void wxMacMLTEControl
::SetStringValue( const wxString
&str
)
1616 wxMacConvertNewlines10To13( &st
) ;
1618 wxMacWindowClipper
c( m_peer
) ;
1621 wxMacEditHelper
help(m_txn
) ;
1622 SetTXNData( st
, kTXNStartOffset
, kTXNEndOffset
) ;
1625 TXNSetSelection( m_txn
, 0, 0 );
1626 TXNShowSelection( m_txn
, kTXNShowStart
);
1630 TXNFrameOptions wxMacMLTEControl
::FrameOptionsFromWXStyle( long wxStyle
)
1632 TXNFrameOptions frameOptions
=
1633 kTXNDontDrawCaretWhenInactiveMask
1634 #if MAC_OS_X_VERSION_MAX_ALLOWED >= MAC_OS_X_VERSION_10_3
1635 | kTXNDoFontSubstitutionMask
1639 if ( ! ( wxStyle
& wxTE_NOHIDESEL
) )
1640 frameOptions
|= kTXNDontDrawSelectionWhenInactiveMask
;
1642 if ( wxStyle
& wxTE_MULTILINE
)
1644 if ( ! ( wxStyle
& wxTE_DONTWRAP
) )
1645 frameOptions
|= kTXNAlwaysWrapAtViewEdgeMask
;
1648 frameOptions
|= kTXNAlwaysWrapAtViewEdgeMask
;
1649 frameOptions
|= kTXNWantHScrollBarMask
;
1652 if ( !(wxStyle
& wxTE_NO_VSCROLL
) )
1654 frameOptions
|= kTXNWantVScrollBarMask
;
1655 if ( frameOptions
& kTXNWantHScrollBarMask
)
1656 frameOptions
|= kTXNDrawGrowIconMask
;
1660 frameOptions
|= kTXNSingleLineOnlyMask
;
1662 if ( wxStyle
& wxHSCROLL
)
1663 frameOptions
|= kTXNWantHScrollBarMask
;
1665 return frameOptions
;
1668 void wxMacMLTEControl
::AdjustCreationAttributes( const wxColour
&background
, bool visible
)
1670 TXNControlTag iControlTags
[] =
1672 kTXNDoFontSubstitution
,
1673 kTXNWordWrapStateTag
,
1675 TXNControlData iControlData
[] =
1681 int toptag
= WXSIZEOF( iControlTags
) ;
1683 if ( m_windowStyle
& wxTE_MULTILINE
)
1685 if (m_windowStyle
& wxTE_DONTWRAP
)
1686 iControlData
[1].uValue
= kTXNNoAutoWrap
;
1688 iControlData
[1].uValue
= kTXNAutoWrap
;
1691 verify_noerr( TXNSetTXNObjectControls( m_txn
, false, toptag
, iControlTags
, iControlData
)) ;
1693 // setting the default font:
1694 // under 10.2 this causes a visible caret, therefore we avoid it
1696 if ( UMAGetSystemVersion() >= 0x1030 )
1702 GetThemeFont(kThemeSystemFont
, GetApplicationScript() , fontName
, &fontSize
, &fontStyle
) ;
1704 TXNTypeAttributes typeAttr
[] =
1706 { kTXNQDFontNameAttribute
, kTXNQDFontNameAttributeSize
, { (void*) fontName
} } ,
1707 { kTXNQDFontSizeAttribute
, kTXNFontSizeAttributeSize
, { (void*) (fontSize
<< 16) } } ,
1708 { kTXNQDFontStyleAttribute
, kTXNQDFontStyleAttributeSize
, { (void*) normal
} } ,
1711 verify_noerr( TXNSetTypeAttributes (m_txn
, sizeof( typeAttr
) / sizeof(TXNTypeAttributes
) , typeAttr
,
1716 if ( m_windowStyle
& wxTE_PASSWORD
)
1719 verify_noerr(TXNEchoMode( m_txn
, c
, 0 , true )) ;
1722 TXNBackground tback
;
1723 tback
.bgType
= kTXNBackgroundTypeRGB
;
1724 tback
.bg
.color
= MAC_WXCOLORREF( background
.GetPixel() );
1725 TXNSetBackground( m_txn
, &tback
);
1727 #if MAC_OS_X_VERSION_MAX_ALLOWED >= MAC_OS_X_VERSION_10_4
1728 if ( UMAGetSystemVersion() >= 0x1040 )
1730 TXNCommandEventSupportOptions options
;
1731 if ( TXNGetCommandEventSupport( m_txn
, &options
) == noErr
)
1734 kTXNSupportEditCommandProcessing
1735 | kTXNSupportEditCommandUpdating
1736 | kTXNSupportSpellCheckCommandProcessing
1737 | kTXNSupportSpellCheckCommandUpdating
1738 | kTXNSupportFontCommandProcessing
1739 | kTXNSupportFontCommandUpdating
;
1741 TXNSetCommandEventSupport( m_txn
, options
) ;
1747 void wxMacMLTEControl
::SetBackground( const wxBrush
&brush
)
1749 // currently only solid background are supported
1750 TXNBackground tback
;
1752 tback
.bgType
= kTXNBackgroundTypeRGB
;
1753 tback
.bg
.color
= MAC_WXCOLORREF( brush
.GetColour().GetPixel() );
1754 TXNSetBackground( m_txn
, &tback
);
1757 void wxMacMLTEControl
::TXNSetAttribute( const wxTextAttr
& style
, long from
, long to
)
1759 TXNTypeAttributes typeAttr
[4] ;
1760 Str255 fontName
= "\pMonaco" ;
1761 SInt16 fontSize
= 12 ;
1762 Style fontStyle
= normal
;
1766 if ( style
.HasFont() )
1768 const wxFont
&font
= style
.GetFont() ;
1769 wxMacStringToPascal( font
.GetFaceName() , fontName
) ;
1770 fontSize
= font
.GetPointSize() ;
1771 if ( font
.GetUnderlined() )
1772 fontStyle
|= underline
;
1773 if ( font
.GetWeight() == wxBOLD
)
1775 if ( font
.GetStyle() == wxITALIC
)
1776 fontStyle
|= italic
;
1778 typeAttr
[attrCount
].tag
= kTXNQDFontNameAttribute
;
1779 typeAttr
[attrCount
].size
= kTXNQDFontNameAttributeSize
;
1780 typeAttr
[attrCount
].data
.dataPtr
= (void*)fontName
;
1783 typeAttr
[attrCount
].tag
= kTXNQDFontSizeAttribute
;
1784 typeAttr
[attrCount
].size
= kTXNFontSizeAttributeSize
;
1785 typeAttr
[attrCount
].data
.dataValue
= (fontSize
<< 16) ;
1788 typeAttr
[attrCount
].tag
= kTXNQDFontStyleAttribute
;
1789 typeAttr
[attrCount
].size
= kTXNQDFontStyleAttributeSize
;
1790 typeAttr
[attrCount
].data
.dataValue
= fontStyle
;
1794 if ( style
.HasTextColour() )
1796 color
= MAC_WXCOLORREF(style
.GetTextColour().GetPixel()) ;
1798 typeAttr
[attrCount
].tag
= kTXNQDFontColorAttribute
;
1799 typeAttr
[attrCount
].size
= kTXNQDFontColorAttributeSize
;
1800 typeAttr
[attrCount
].data
.dataPtr
= (void*) &color
;
1804 if ( attrCount
> 0 )
1806 verify_noerr( TXNSetTypeAttributes( m_txn
, attrCount
, typeAttr
, from
, to
) );
1810 void wxMacMLTEControl
::SetFont( const wxFont
& font
, const wxColour
& foreground
, long windowStyle
)
1812 wxMacEditHelper
help( m_txn
) ;
1813 TXNSetAttribute( wxTextAttr( foreground
, wxNullColour
, font
), kTXNStartOffset
, kTXNEndOffset
) ;
1816 void wxMacMLTEControl
::SetStyle( long start
, long end
, const wxTextAttr
& style
)
1818 wxMacEditHelper
help( m_txn
) ;
1819 TXNSetAttribute( style
, start
, end
) ;
1822 void wxMacMLTEControl
::Copy()
1824 ClearCurrentScrap();
1826 TXNConvertToPublicScrap();
1829 void wxMacMLTEControl
::Cut()
1831 ClearCurrentScrap();
1833 TXNConvertToPublicScrap();
1836 void wxMacMLTEControl
::Paste()
1838 TXNConvertFromPublicScrap();
1842 bool wxMacMLTEControl
::CanPaste() const
1844 return TXNIsScrapPastable() ;
1847 void wxMacMLTEControl
::SetEditable(bool editable
)
1849 TXNControlTag tag
[] = { kTXNIOPrivilegesTag
} ;
1850 TXNControlData data
[] = { { editable ? kTXNReadWrite
: kTXNReadOnly
} } ;
1851 TXNSetTXNObjectControls( m_txn
, false , WXSIZEOF(tag
) , tag
, data
) ;
1854 wxTextPos wxMacMLTEControl
::GetLastPosition() const
1856 wxTextPos actualsize
= 0 ;
1859 OSErr err
= TXNGetDataEncoded( m_txn
, kTXNStartOffset
, kTXNEndOffset
, &theText
, kTXNTextData
);
1864 actualsize
= GetHandleSize( theText
) ;
1865 DisposeHandle( theText
) ;
1875 void wxMacMLTEControl
::Replace( long from
, long to
, const wxString
&str
)
1877 wxString value
= str
;
1878 wxMacConvertNewlines10To13( &value
) ;
1880 wxMacEditHelper
help( m_txn
) ;
1881 wxMacWindowClipper
c( m_peer
) ;
1883 TXNSetSelection( m_txn
, from
, to
) ;
1885 SetTXNData( value
, kTXNUseCurrentSelection
, kTXNUseCurrentSelection
) ;
1888 void wxMacMLTEControl
::Remove( long from
, long to
)
1890 wxMacWindowClipper
c( m_peer
) ;
1891 wxMacEditHelper
help( m_txn
) ;
1892 TXNSetSelection( m_txn
, from
, to
) ;
1896 void wxMacMLTEControl
::GetSelection( long* from
, long* to
) const
1898 TXNGetSelection( m_txn
, (TXNOffset
*) from
, (TXNOffset
*) to
) ;
1901 void wxMacMLTEControl
::SetSelection( long from
, long to
)
1903 wxMacWindowClipper
c( m_peer
) ;
1905 // change the selection
1906 if ((from
== -1) && (to
== -1))
1907 TXNSelectAll( m_txn
);
1909 TXNSetSelection( m_txn
, from
, to
);
1911 TXNShowSelection( m_txn
, kTXNShowStart
);
1914 void wxMacMLTEControl
::WriteText(const wxString
& str
)
1917 wxMacConvertNewlines10To13( &st
) ;
1919 long start
, end
, dummy
;
1921 GetSelection( &start
, &dummy
) ;
1922 wxMacWindowClipper
c( m_peer
) ;
1925 wxMacEditHelper
helper( m_txn
) ;
1926 SetTXNData( st
, kTXNUseCurrentSelection
, kTXNUseCurrentSelection
) ;
1929 GetSelection( &dummy
, &end
) ;
1931 // TODO: SetStyle( start , end , GetDefaultStyle() ) ;
1934 void wxMacMLTEControl
::Clear()
1936 wxMacWindowClipper
c( m_peer
) ;
1937 wxMacEditHelper
st( m_txn
) ;
1938 TXNSetSelection( m_txn
, kTXNStartOffset
, kTXNEndOffset
) ;
1942 bool wxMacMLTEControl
::CanUndo() const
1944 return TXNCanUndo( m_txn
, NULL
) ;
1947 void wxMacMLTEControl
::Undo()
1952 bool wxMacMLTEControl
::CanRedo() const
1954 return TXNCanRedo( m_txn
, NULL
) ;
1957 void wxMacMLTEControl
::Redo()
1962 int wxMacMLTEControl
::GetNumberOfLines() const
1964 ItemCount lines
= 0 ;
1965 TXNGetLineCount( m_txn
, &lines
) ;
1970 long wxMacMLTEControl
::XYToPosition(long x
, long y
) const
1975 // TODO: find a better implementation : while we can get the
1976 // line metrics of a certain line, we don't get its starting
1977 // position, so it would probably be rather a binary search
1978 // for the start position
1981 int lastHeight
= 0 ;
1984 lastpos
= GetLastPosition() ;
1985 for ( n
= 0 ; n
<= (ItemCount
) lastpos
; ++n
)
1987 if ( y
== ypos
&& x
== xpos
)
1990 TXNOffsetToPoint( m_txn
, n
, &curpt
);
1992 if ( curpt
.v
> lastHeight
)
1998 lastHeight
= curpt
.v
;
2007 bool wxMacMLTEControl
::PositionToXY(long pos
, long *x
, long *y
) const
2017 lastpos
= GetLastPosition() ;
2018 if ( pos
<= lastpos
)
2020 // TODO: find a better implementation : while we can get the
2021 // line metrics of a certain line, we don't get its starting
2022 // position, so it would probably be rather a binary search
2023 // for the start position
2024 long xpos
= 0, ypos
= 0 ;
2025 int lastHeight
= 0 ;
2028 for ( n
= 0 ; n
<= (ItemCount
) pos
; ++n
)
2030 TXNOffsetToPoint(m_txn
, n
, &curpt
);
2032 if ( curpt
.v
> lastHeight
)
2038 lastHeight
= curpt
.v
;
2053 void wxMacMLTEControl
::ShowPosition( long pos
)
2055 #if TARGET_RT_MAC_MACHO && defined(AVAILABLE_MAC_OS_X_VERSION_10_2_AND_LATER)
2057 Point current
, desired
;
2058 TXNOffset selstart
, selend
;
2060 TXNGetSelection( m_txn
, &selstart
, &selend
);
2061 TXNOffsetToPoint( m_txn
, selstart
, ¤t
);
2062 TXNOffsetToPoint( m_txn
, pos
, &desired
);
2064 // TODO: use HIPoints for 10.3 and above
2065 if ( (UInt32
)TXNScroll
!= (UInt32
)kUnresolvedCFragSymbolAddress
)
2067 OSErr theErr
= noErr
;
2068 SInt32 dv
= desired
.v
- current
.v
;
2069 SInt32 dh
= desired
.h
- current
.h
;
2070 TXNShowSelection( m_txn
, kTXNShowEnd
) ; // NB: should this be kTXNShowStart or kTXNShowEnd ??
2071 theErr
= TXNScroll( m_txn
, kTXNScrollUnitsInPixels
, kTXNScrollUnitsInPixels
, &dv
, &dh
);
2073 // there will be an error returned for classic MLTE implementation when the control is
2074 // invisible, but HITextView works correctly, so we don't assert that one
2075 // wxASSERT_MSG( theErr == noErr, _T("TXNScroll returned an error!") );
2081 void wxMacMLTEControl
::SetTXNData( const wxString
& st
, TXNOffset start
, TXNOffset end
)
2084 #if SIZEOF_WCHAR_T == 2
2085 size_t len
= st
.Len() ;
2086 TXNSetData( m_txn
, kTXNUnicodeTextData
, (void*)st
.wc_str(), len
* 2, start
, end
);
2088 wxMBConvUTF16 converter
;
2089 ByteCount byteBufferLen
= converter
.WC2MB( NULL
, st
.wc_str() , 0 ) ;
2090 UniChar
*unibuf
= (UniChar
*) malloc( byteBufferLen
) ;
2091 converter
.WC2MB( (char*)unibuf
, st
.wc_str(), byteBufferLen
) ;
2092 TXNSetData( m_txn
, kTXNUnicodeTextData
, (void*)unibuf
, byteBufferLen
, start
, end
) ;
2096 wxCharBuffer text
= st
.mb_str(wxConvLocal
) ;
2097 TXNSetData( m_txn
, kTXNTextData
, (void*)text
.data(), strlen( text
), start
, end
) ;
2101 wxString wxMacMLTEControl
::GetLineText(long lineNo
) const
2105 if ( lineNo
< GetNumberOfLines() )
2108 Fixed lineWidth
, lineHeight
, currentHeight
;
2111 // get the first possible position in the control
2112 TXNOffsetToPoint(m_txn
, 0, &firstPoint
);
2114 // Iterate through the lines until we reach the one we want,
2115 // adding to our current y pixel point position
2118 while (ypos
< lineNo
)
2120 TXNGetLineMetrics(m_txn
, ypos
++, &lineWidth
, &lineHeight
);
2121 currentHeight
+= lineHeight
;
2124 Point thePoint
= { firstPoint
.v
+ (currentHeight
>> 16), firstPoint
.h
+ (0) };
2125 TXNOffset theOffset
;
2126 TXNPointToOffset(m_txn
, thePoint
, &theOffset
);
2128 wxString content
= GetStringValue() ;
2129 Point currentPoint
= thePoint
;
2130 while (thePoint
.v
== currentPoint
.v
&& theOffset
< content
.length())
2132 line
+= content
[theOffset
];
2133 TXNOffsetToPoint(m_txn
, ++theOffset
, ¤tPoint
);
2140 int wxMacMLTEControl
::GetLineLength(long lineNo
) const
2144 if ( lineNo
< GetNumberOfLines() )
2147 Fixed lineWidth
, lineHeight
, currentHeight
;
2150 // get the first possible position in the control
2151 TXNOffsetToPoint(m_txn
, 0, &firstPoint
);
2153 // Iterate through the lines until we reach the one we want,
2154 // adding to our current y pixel point position
2157 while (ypos
< lineNo
)
2159 TXNGetLineMetrics(m_txn
, ypos
++, &lineWidth
, &lineHeight
);
2160 currentHeight
+= lineHeight
;
2163 Point thePoint
= { firstPoint
.v
+ (currentHeight
>> 16), firstPoint
.h
+ (0) };
2164 TXNOffset theOffset
;
2165 TXNPointToOffset(m_txn
, thePoint
, &theOffset
);
2167 wxString content
= GetStringValue() ;
2168 Point currentPoint
= thePoint
;
2169 while (thePoint
.v
== currentPoint
.v
&& theOffset
< content
.length())
2172 TXNOffsetToPoint(m_txn
, ++theOffset
, ¤tPoint
);
2179 // ----------------------------------------------------------------------------
2180 // MLTE control implementation (classic part)
2181 // ----------------------------------------------------------------------------
2183 // OS X Notes : We still don't have a full replacement for MLTE, so this implementation
2184 // has to live on. We have different problems coming from outdated implementations on the
2185 // various OS X versions. Most deal with the scrollbars: they are not correctly embedded
2186 // while this can be solved on 10.3 by reassigning them the correct place, on 10.2 there is
2187 // no way out, therefore we are using our own implementation and our own scrollbars ....
2189 #ifdef __WXMAC_OSX__
2191 TXNScrollInfoUPP gTXNScrollInfoProc
= NULL
;
2192 ControlActionUPP gTXNScrollActionProc
= NULL
;
2194 pascal void wxMacMLTEClassicControl
::TXNScrollInfoProc(
2195 SInt32 iValue
, SInt32 iMaximumValue
,
2196 TXNScrollBarOrientation iScrollBarOrientation
, SInt32 iRefCon
)
2198 wxMacMLTEClassicControl
* mlte
= (wxMacMLTEClassicControl
*) iRefCon
;
2199 SInt32 value
= wxMax( iValue
, 0 ) ;
2200 SInt32 maximum
= wxMax( iMaximumValue
, 0 ) ;
2202 if ( iScrollBarOrientation
== kTXNHorizontal
)
2204 if ( mlte
->m_sbHorizontal
)
2206 SetControl32BitValue( mlte
->m_sbHorizontal
, value
) ;
2207 SetControl32BitMaximum( mlte
->m_sbHorizontal
, maximum
) ;
2208 mlte
->m_lastHorizontalValue
= value
;
2211 else if ( iScrollBarOrientation
== kTXNVertical
)
2213 if ( mlte
->m_sbVertical
)
2215 SetControl32BitValue( mlte
->m_sbVertical
, value
) ;
2216 SetControl32BitMaximum( mlte
->m_sbVertical
, maximum
) ;
2217 mlte
->m_lastVerticalValue
= value
;
2222 pascal void wxMacMLTEClassicControl
::TXNScrollActionProc( ControlRef controlRef
, ControlPartCode partCode
)
2224 wxMacMLTEClassicControl
* mlte
= (wxMacMLTEClassicControl
*) GetControlReference( controlRef
) ;
2228 if ( controlRef
!= mlte
->m_sbVertical
&& controlRef
!= mlte
->m_sbHorizontal
)
2232 bool isHorizontal
= ( controlRef
== mlte
->m_sbHorizontal
) ;
2234 SInt32 minimum
= 0 ;
2235 SInt32 maximum
= GetControl32BitMaximum( controlRef
) ;
2236 SInt32 value
= GetControl32BitValue( controlRef
) ;
2242 case kControlDownButtonPart
:
2246 case kControlUpButtonPart
:
2250 case kControlPageDownPart
:
2251 delta
= GetControlViewSize( controlRef
) ;
2254 case kControlPageUpPart
:
2255 delta
= -GetControlViewSize( controlRef
) ;
2258 case kControlIndicatorPart
:
2260 ( isHorizontal ? mlte
->m_lastHorizontalValue
: mlte
->m_lastVerticalValue
) ;
2269 SInt32 newValue
= value
;
2271 if ( partCode
!= kControlIndicatorPart
)
2273 if ( value
+ delta
< minimum
)
2274 delta
= minimum
- value
;
2275 if ( value
+ delta
> maximum
)
2276 delta
= maximum
- value
;
2278 SetControl32BitValue( controlRef
, value
+ delta
) ;
2279 newValue
= value
+ delta
;
2282 SInt32 verticalDelta
= isHorizontal ?
0 : delta
;
2283 SInt32 horizontalDelta
= isHorizontal ? delta
: 0 ;
2286 mlte
->m_txn
, kTXNScrollUnitsInPixels
, kTXNScrollUnitsInPixels
,
2287 &verticalDelta
, &horizontalDelta
);
2290 mlte
->m_lastHorizontalValue
= newValue
;
2292 mlte
->m_lastVerticalValue
= newValue
;
2297 // make correct activations
2298 void wxMacMLTEClassicControl
::MacActivatePaneText(bool setActive
)
2300 wxTextCtrl
* textctrl
= (wxTextCtrl
*) GetControlReference(m_controlRef
);
2302 wxMacWindowClipper
clipper( textctrl
) ;
2303 TXNActivate(m_txn
, m_txnFrameID
, setActive
);
2305 ControlRef controlFocus
= 0 ;
2306 GetKeyboardFocus( m_txnWindow
, &controlFocus
) ;
2307 if ( controlFocus
== m_controlRef
)
2308 TXNFocus( m_txn
, setActive
);
2311 void wxMacMLTEClassicControl
::MacFocusPaneText(bool setFocus
)
2313 TXNFocus( m_txn
, setFocus
);
2316 // guards against inappropriate redraw (hidden objects drawing onto window)
2318 void wxMacMLTEClassicControl
::MacSetObjectVisibility(bool vis
)
2320 ControlRef controlFocus
= 0 ;
2321 GetKeyboardFocus( m_txnWindow
, &controlFocus
) ;
2323 if ( !vis
&& (controlFocus
== m_controlRef
) )
2324 SetKeyboardFocus( m_txnWindow
, m_controlRef
, kControlFocusNoPart
) ;
2326 TXNControlTag iControlTags
[1] = { kTXNVisibilityTag
};
2327 TXNControlData iControlData
[1] = { {(UInt32
) false } };
2329 verify_noerr( TXNGetTXNObjectControls( m_txn
, 1, iControlTags
, iControlData
) ) ;
2331 if ( iControlData
[0].uValue
!= vis
)
2333 iControlData
[0].uValue
= vis
;
2334 verify_noerr( TXNSetTXNObjectControls( m_txn
, false , 1, iControlTags
, iControlData
) ) ;
2337 // currently, we always clip as partial visibility (overlapped) visibility is also a problem,
2338 // if we run into further problems we might set the FrameBounds to an empty rect here
2341 // make sure that the TXNObject is at the right position
2343 void wxMacMLTEClassicControl
::MacUpdatePosition()
2345 wxTextCtrl
* textctrl
= (wxTextCtrl
*) GetControlReference(m_controlRef
);
2346 if ( textctrl
== NULL
)
2350 UMAGetControlBoundsInWindowCoords(m_controlRef
, &bounds
);
2352 wxRect visRect
= textctrl
->MacGetClippedClientRect() ;
2353 Rect visBounds
= { visRect
.y
, visRect
.x
, visRect
.y
+ visRect
.height
, visRect
.x
+ visRect
.width
} ;
2356 textctrl
->MacWindowToRootWindow( &x
, &y
) ;
2357 OffsetRect( &visBounds
, x
, y
) ;
2359 if ( !EqualRect( &bounds
, &m_txnControlBounds
) || !EqualRect( &visBounds
, &m_txnVisBounds
) )
2361 m_txnControlBounds
= bounds
;
2362 m_txnVisBounds
= visBounds
;
2363 wxMacWindowClipper
cl(textctrl
) ;
2365 #ifdef __WXMAC_OSX__
2366 bool isCompositing
= textctrl
->MacGetTopLevelWindow()->MacUsesCompositing() ;
2367 if ( m_sbHorizontal
|| m_sbVertical
)
2369 int w
= bounds
.right
- bounds
.left
;
2370 int h
= bounds
.bottom
- bounds
.top
;
2372 if ( m_sbHorizontal
)
2376 sbBounds
.left
= -1 ;
2377 sbBounds
.top
= h
- 14 ;
2378 sbBounds
.right
= w
+ 1 ;
2379 sbBounds
.bottom
= h
+ 1 ;
2381 if ( !isCompositing
)
2382 OffsetRect( &sbBounds
, m_txnControlBounds
.left
, m_txnControlBounds
.top
) ;
2384 SetControlBounds( m_sbHorizontal
, &sbBounds
) ;
2385 SetControlViewSize( m_sbHorizontal
, w
) ;
2392 sbBounds
.left
= w
- 14 ;
2394 sbBounds
.right
= w
+ 1 ;
2395 sbBounds
.bottom
= m_sbHorizontal ? h
- 14 : h
+ 1 ;
2397 if ( !isCompositing
)
2398 OffsetRect( &sbBounds
, m_txnControlBounds
.left
, m_txnControlBounds
.top
) ;
2400 SetControlBounds( m_sbVertical
, &sbBounds
) ;
2401 SetControlViewSize( m_sbVertical
, h
) ;
2406 TXNLongRect olddestRect
;
2407 TXNGetRectBounds( m_txn
, &oldviewRect
, &olddestRect
, NULL
) ;
2409 Rect viewRect
= { m_txnControlBounds
.top
, m_txnControlBounds
.left
,
2410 m_txnControlBounds
.bottom
- ( m_sbHorizontal ?
14 : 0 ) ,
2411 m_txnControlBounds
.right
- ( m_sbVertical ?
14 : 0 ) } ;
2412 TXNLongRect destRect
= { m_txnControlBounds
.top
, m_txnControlBounds
.left
,
2413 m_txnControlBounds
.bottom
- ( m_sbHorizontal ?
14 : 0 ) ,
2414 m_txnControlBounds
.right
- ( m_sbVertical ?
14 : 0 ) } ;
2416 if ( olddestRect
.right
>= 10000 )
2417 destRect
.right
= destRect
.left
+ 32000 ;
2419 if ( olddestRect
.bottom
>= 0x20000000 )
2420 destRect
.bottom
= destRect
.top
+ 0x40000000 ;
2422 SectRect( &viewRect
, &visBounds
, &viewRect
) ;
2423 TXNSetRectBounds( m_txn
, &viewRect
, &destRect
, true ) ;
2428 m_txnControlBounds
.top
,
2429 m_txnControlBounds
.left
,
2430 m_txnControlBounds
.bottom
- (m_sbHorizontal ?
14 : 0),
2431 m_txnControlBounds
.right
- (m_sbVertical ?
14 : 0),
2436 TXNSetFrameBounds( m_txn
, m_txnControlBounds
.top
, m_txnControlBounds
.left
,
2437 wxMax( m_txnControlBounds
.bottom
, m_txnControlBounds
.top
) ,
2438 wxMax( m_txnControlBounds
.right
, m_txnControlBounds
.left
) , m_txnFrameID
);
2440 // the SetFrameBounds method unter classic sometimes does not correctly scroll a selection into sight after a
2441 // movement, therefore we have to force it
2443 // this problem has been reported in OSX as well, so we use this here once again
2445 TXNLongRect textRect
;
2446 TXNGetRectBounds( m_txn
, NULL
, NULL
, &textRect
) ;
2447 if ( textRect
.left
< m_txnControlBounds
.left
)
2448 TXNShowSelection( m_txn
, kTXNShowStart
) ;
2452 void wxMacMLTEClassicControl
::SetRect( Rect
*r
)
2454 wxMacControl
::SetRect( r
) ;
2455 MacUpdatePosition() ;
2458 void wxMacMLTEClassicControl
::MacControlUserPaneDrawProc(wxInt16 thePart
)
2460 wxTextCtrl
* textctrl
= (wxTextCtrl
*) GetControlReference(m_controlRef
);
2461 if ( textctrl
== NULL
)
2464 if ( textctrl
->MacIsReallyShown() )
2466 wxMacWindowClipper
clipper( textctrl
) ;
2467 TXNDraw( m_txn
, NULL
) ;
2471 wxInt16 wxMacMLTEClassicControl
::MacControlUserPaneHitTestProc(wxInt16 x
, wxInt16 y
)
2473 Point where
= { y
, x
} ;
2474 ControlPartCode result
= kControlNoPart
;
2476 wxTextCtrl
* textctrl
= (wxTextCtrl
*) GetControlReference( m_controlRef
);
2477 if ( (textctrl
!= NULL
) && textctrl
->MacIsReallyShown() )
2479 if (PtInRect( where
, &m_txnControlBounds
))
2481 result
= kControlEditTextPart
;
2485 // sometimes we get the coords also in control local coordinates, therefore test again
2486 if ( textctrl
->MacGetTopLevelWindow()->MacUsesCompositing() )
2489 textctrl
->MacClientToRootWindow( &x
, &y
) ;
2494 if (PtInRect( where
, &m_txnControlBounds
))
2495 result
= kControlEditTextPart
;
2502 wxInt16 wxMacMLTEClassicControl
::MacControlUserPaneTrackingProc( wxInt16 x
, wxInt16 y
, void* actionProc
)
2504 ControlPartCode result
= kControlNoPart
;
2506 wxTextCtrl
* textctrl
= (wxTextCtrl
*) GetControlReference( m_controlRef
);
2507 if ( (textctrl
!= NULL
) && textctrl
->MacIsReallyShown() )
2509 Point startPt
= { y
, x
} ;
2510 // for compositing, we must convert these into toplevel window coordinates, because hittesting expects them
2511 if ( textctrl
->MacGetTopLevelWindow()->MacUsesCompositing() )
2514 textctrl
->MacClientToRootWindow( &x
, &y
) ;
2519 switch (MacControlUserPaneHitTestProc( startPt
.h
, startPt
.v
))
2521 case kControlEditTextPart
:
2523 wxMacWindowClipper
clipper( textctrl
) ;
2526 ConvertEventRefToEventRecord( (EventRef
) wxTheApp
->MacGetCurrentEvent() , &rec
) ;
2527 TXNClick( m_txn
, &rec
);
2539 void wxMacMLTEClassicControl
::MacControlUserPaneIdleProc()
2541 wxTextCtrl
* textctrl
= (wxTextCtrl
*) GetControlReference(m_controlRef
);
2542 if ( textctrl
== NULL
)
2545 if (textctrl
->MacIsReallyShown())
2547 if (IsControlActive(m_controlRef
))
2551 wxMacWindowClipper
clipper( textctrl
) ;
2556 if (PtInRect(mousep
, &m_txnControlBounds
))
2558 RgnHandle theRgn
= NewRgn();
2559 RectRgn(theRgn
, &m_txnControlBounds
);
2560 TXNAdjustCursor(m_txn
, theRgn
);
2567 wxInt16 wxMacMLTEClassicControl
::MacControlUserPaneKeyDownProc (wxInt16 keyCode
, wxInt16 charCode
, wxInt16 modifiers
)
2569 wxTextCtrl
* textctrl
= (wxTextCtrl
*) GetControlReference(m_controlRef
);
2570 if ( textctrl
== NULL
)
2571 return kControlNoPart
;
2573 wxMacWindowClipper
clipper( textctrl
) ;
2576 memset( &ev
, 0 , sizeof( ev
) ) ;
2578 ev
.modifiers
= modifiers
;
2579 ev
.message
= ((keyCode
<< 8) & keyCodeMask
) | (charCode
& charCodeMask
);
2580 TXNKeyDown( m_txn
, &ev
);
2582 return kControlEntireControl
;
2585 void wxMacMLTEClassicControl
::MacControlUserPaneActivateProc( bool activating
)
2587 MacActivatePaneText( activating
);
2590 wxInt16 wxMacMLTEClassicControl
::MacControlUserPaneFocusProc(wxInt16 action
)
2592 ControlPartCode focusResult
;
2594 focusResult
= kControlFocusNoPart
;
2595 wxTextCtrl
* textctrl
= (wxTextCtrl
*) GetControlReference(m_controlRef
);
2596 if ( textctrl
== NULL
)
2599 wxMacWindowClipper
clipper( textctrl
) ;
2601 ControlRef controlFocus
= NULL
;
2602 GetKeyboardFocus( m_txnWindow
, &controlFocus
) ;
2603 bool wasFocused
= ( controlFocus
== m_controlRef
) ;
2607 case kControlFocusPrevPart
:
2608 case kControlFocusNextPart
:
2609 MacFocusPaneText( !wasFocused
);
2610 focusResult
= (!wasFocused ?
(ControlPartCode
) kControlEditTextPart
: (ControlPartCode
) kControlFocusNoPart
);
2613 case kControlFocusNoPart
:
2615 MacFocusPaneText( false );
2616 focusResult
= kControlFocusNoPart
;
2623 void wxMacMLTEClassicControl
::MacControlUserPaneBackgroundProc( void *info
)
2627 wxMacMLTEClassicControl
::wxMacMLTEClassicControl( wxTextCtrl
*wxPeer
,
2628 const wxString
& str
,
2630 const wxSize
& size
, long style
) : wxMacMLTEControl( wxPeer
)
2632 m_font
= wxPeer
->GetFont() ;
2633 m_windowStyle
= style
;
2634 Rect bounds
= wxMacGetBoundsForControl( wxPeer
, pos
, size
) ;
2639 kControlSupportsEmbedding
| kControlSupportsFocus
| kControlWantsIdle
2640 | kControlWantsActivate
| kControlHandlesTracking
2641 // | kControlHasSpecialBackground
2642 | kControlGetsFocusOnClick
| kControlSupportsLiveFeedback
;
2645 ::CreateUserPaneControl(
2646 MAC_WXHWND(wxPeer
->GetParent()->MacGetTopLevelWindowRef()),
2647 &bounds
, featureSet
, &m_controlRef
) );
2651 AdjustCreationAttributes( *wxWHITE
, true ) ;
2653 MacSetObjectVisibility( wxPeer
->MacIsReallyShown() ) ;
2657 wxMacConvertNewlines10To13( &st
) ;
2658 wxMacWindowClipper
clipper( m_peer
) ;
2659 SetTXNData( st
, kTXNStartOffset
, kTXNEndOffset
) ;
2660 TXNSetSelection( m_txn
, 0, 0 ) ;
2664 wxMacMLTEClassicControl
::~wxMacMLTEClassicControl()
2666 TXNDeleteObject( m_txn
);
2670 void wxMacMLTEClassicControl
::VisibilityChanged(bool shown
)
2672 MacSetObjectVisibility( shown
) ;
2673 wxMacControl
::VisibilityChanged( shown
) ;
2676 void wxMacMLTEClassicControl
::SuperChangedPosition()
2678 MacUpdatePosition() ;
2679 wxMacControl
::SuperChangedPosition() ;
2682 #ifdef __WXMAC_OSX__
2684 ControlUserPaneDrawUPP gTPDrawProc
= NULL
;
2685 ControlUserPaneHitTestUPP gTPHitProc
= NULL
;
2686 ControlUserPaneTrackingUPP gTPTrackProc
= NULL
;
2687 ControlUserPaneIdleUPP gTPIdleProc
= NULL
;
2688 ControlUserPaneKeyDownUPP gTPKeyProc
= NULL
;
2689 ControlUserPaneActivateUPP gTPActivateProc
= NULL
;
2690 ControlUserPaneFocusUPP gTPFocusProc
= NULL
;
2692 static pascal void wxMacControlUserPaneDrawProc(ControlRef control
, SInt16 part
)
2694 wxTextCtrl
*textCtrl
= wxDynamicCast( wxFindControlFromMacControl(control
) , wxTextCtrl
) ;
2695 wxMacMLTEClassicControl
* win
= textCtrl ?
(wxMacMLTEClassicControl
*)(textCtrl
->GetPeer()) : NULL
;
2697 win
->MacControlUserPaneDrawProc(part
) ;
2700 static pascal ControlPartCode
wxMacControlUserPaneHitTestProc(ControlRef control
, Point where
)
2702 wxTextCtrl
*textCtrl
= wxDynamicCast( wxFindControlFromMacControl(control
) , wxTextCtrl
) ;
2703 wxMacMLTEClassicControl
* win
= textCtrl ?
(wxMacMLTEClassicControl
*)(textCtrl
->GetPeer()) : NULL
;
2705 return win
->MacControlUserPaneHitTestProc(where
.h
, where
.v
) ;
2707 return kControlNoPart
;
2710 static pascal ControlPartCode
wxMacControlUserPaneTrackingProc(ControlRef control
, Point startPt
, ControlActionUPP actionProc
)
2712 wxTextCtrl
*textCtrl
= wxDynamicCast( wxFindControlFromMacControl(control
) , wxTextCtrl
) ;
2713 wxMacMLTEClassicControl
* win
= textCtrl ?
(wxMacMLTEClassicControl
*)(textCtrl
->GetPeer()) : NULL
;
2715 return win
->MacControlUserPaneTrackingProc( startPt
.h
, startPt
.v
, (void*) actionProc
) ;
2717 return kControlNoPart
;
2720 static pascal void wxMacControlUserPaneIdleProc(ControlRef control
)
2722 wxTextCtrl
*textCtrl
= wxDynamicCast( wxFindControlFromMacControl(control
) , wxTextCtrl
) ;
2723 wxMacMLTEClassicControl
* win
= textCtrl ?
(wxMacMLTEClassicControl
*)(textCtrl
->GetPeer()) : NULL
;
2725 win
->MacControlUserPaneIdleProc() ;
2728 static pascal ControlPartCode
wxMacControlUserPaneKeyDownProc(ControlRef control
, SInt16 keyCode
, SInt16 charCode
, SInt16 modifiers
)
2730 wxTextCtrl
*textCtrl
= wxDynamicCast( wxFindControlFromMacControl(control
) , wxTextCtrl
) ;
2731 wxMacMLTEClassicControl
* win
= textCtrl ?
(wxMacMLTEClassicControl
*)(textCtrl
->GetPeer()) : NULL
;
2733 return win
->MacControlUserPaneKeyDownProc(keyCode
,charCode
,modifiers
) ;
2735 return kControlNoPart
;
2738 static pascal void wxMacControlUserPaneActivateProc(ControlRef control
, Boolean activating
)
2740 wxTextCtrl
*textCtrl
= wxDynamicCast( wxFindControlFromMacControl(control
) , wxTextCtrl
) ;
2741 wxMacMLTEClassicControl
* win
= textCtrl ?
(wxMacMLTEClassicControl
*)(textCtrl
->GetPeer()) : NULL
;
2743 win
->MacControlUserPaneActivateProc(activating
) ;
2746 static pascal ControlPartCode
wxMacControlUserPaneFocusProc(ControlRef control
, ControlFocusPart action
)
2748 wxTextCtrl
*textCtrl
= wxDynamicCast( wxFindControlFromMacControl(control
) , wxTextCtrl
) ;
2749 wxMacMLTEClassicControl
* win
= textCtrl ?
(wxMacMLTEClassicControl
*)(textCtrl
->GetPeer()) : NULL
;
2751 return win
->MacControlUserPaneFocusProc(action
) ;
2753 return kControlNoPart
;
2757 static pascal void wxMacControlUserPaneBackgroundProc(ControlRef control
, ControlBackgroundPtr info
)
2759 wxTextCtrl
*textCtrl
= wxDynamicCast( wxFindControlFromMacControl(control
) , wxTextCtrl
) ;
2760 wxMacMLTEClassicControl
* win
= textCtrl ?
(wxMacMLTEClassicControl
*)(textCtrl
->GetPeer()) : NULL
;
2762 win
->MacControlUserPaneBackgroundProc(info
) ;
2766 #endif // __WXMAC_OSX__
2768 // TXNRegisterScrollInfoProc
2770 OSStatus wxMacMLTEClassicControl
::DoCreate()
2774 OSStatus err
= noErr
;
2776 // set up our globals
2777 #ifdef __WXMAC_OSX__
2778 if (gTPDrawProc
== NULL
) gTPDrawProc
= NewControlUserPaneDrawUPP(wxMacControlUserPaneDrawProc
);
2779 if (gTPHitProc
== NULL
) gTPHitProc
= NewControlUserPaneHitTestUPP(wxMacControlUserPaneHitTestProc
);
2780 if (gTPTrackProc
== NULL
) gTPTrackProc
= NewControlUserPaneTrackingUPP(wxMacControlUserPaneTrackingProc
);
2781 if (gTPIdleProc
== NULL
) gTPIdleProc
= NewControlUserPaneIdleUPP(wxMacControlUserPaneIdleProc
);
2782 if (gTPKeyProc
== NULL
) gTPKeyProc
= NewControlUserPaneKeyDownUPP(wxMacControlUserPaneKeyDownProc
);
2783 if (gTPActivateProc
== NULL
) gTPActivateProc
= NewControlUserPaneActivateUPP(wxMacControlUserPaneActivateProc
);
2784 if (gTPFocusProc
== NULL
) gTPFocusProc
= NewControlUserPaneFocusUPP(wxMacControlUserPaneFocusProc
);
2786 if (gTXNScrollInfoProc
== NULL
) gTXNScrollInfoProc
= NewTXNScrollInfoUPP(TXNScrollInfoProc
) ;
2787 if (gTXNScrollActionProc
== NULL
) gTXNScrollActionProc
= NewControlActionUPP(TXNScrollActionProc
) ;
2790 // set the initial settings for our private data
2792 m_txnWindow
= GetControlOwner(m_controlRef
);
2793 m_txnPort
= (GrafPtr
) GetWindowPort(m_txnWindow
);
2795 #ifdef __WXMAC_OSX__
2796 // set up the user pane procedures
2797 SetControlData(m_controlRef
, kControlEntireControl
, kControlUserPaneDrawProcTag
, sizeof(gTPDrawProc
), &gTPDrawProc
);
2798 SetControlData(m_controlRef
, kControlEntireControl
, kControlUserPaneHitTestProcTag
, sizeof(gTPHitProc
), &gTPHitProc
);
2799 SetControlData(m_controlRef
, kControlEntireControl
, kControlUserPaneTrackingProcTag
, sizeof(gTPTrackProc
), &gTPTrackProc
);
2800 SetControlData(m_controlRef
, kControlEntireControl
, kControlUserPaneIdleProcTag
, sizeof(gTPIdleProc
), &gTPIdleProc
);
2801 SetControlData(m_controlRef
, kControlEntireControl
, kControlUserPaneKeyDownProcTag
, sizeof(gTPKeyProc
), &gTPKeyProc
);
2802 SetControlData(m_controlRef
, kControlEntireControl
, kControlUserPaneActivateProcTag
, sizeof(gTPActivateProc
), &gTPActivateProc
);
2803 SetControlData(m_controlRef
, kControlEntireControl
, kControlUserPaneFocusProcTag
, sizeof(gTPFocusProc
), &gTPFocusProc
);
2805 // calculate the rectangles used by the control
2806 UMAGetControlBoundsInWindowCoords(m_controlRef
, &bounds
);
2808 m_txnControlBounds
= bounds
;
2809 m_txnVisBounds
= bounds
;
2814 GetGWorld( &origPort
, &origDev
) ;
2815 SetPort( m_txnPort
);
2817 // create the new edit field
2818 TXNFrameOptions frameOptions
= FrameOptionsFromWXStyle( m_windowStyle
) ;
2820 #ifdef __WXMAC_OSX__
2821 // the scrollbars are not correctly embedded but are inserted at the root:
2822 // this gives us problems as we have erratic redraws even over the structure area
2824 m_sbHorizontal
= 0 ;
2826 m_lastHorizontalValue
= 0 ;
2827 m_lastVerticalValue
= 0 ;
2829 Rect sb
= { 0 , 0 , 0 , 0 } ;
2830 if ( frameOptions
& kTXNWantVScrollBarMask
)
2832 CreateScrollBarControl( m_txnWindow
, &sb
, 0 , 0 , 100 , 1 , true , gTXNScrollActionProc
, &m_sbVertical
) ;
2833 SetControlReference( m_sbVertical
, (SInt32
) this ) ;
2834 SetControlAction( m_sbVertical
, gTXNScrollActionProc
);
2835 ShowControl( m_sbVertical
) ;
2836 EmbedControl( m_sbVertical
, m_controlRef
) ;
2837 frameOptions
&= ~kTXNWantVScrollBarMask
;
2840 if ( frameOptions
& kTXNWantHScrollBarMask
)
2842 CreateScrollBarControl( m_txnWindow
, &sb
, 0 , 0 , 100 , 1 , true , gTXNScrollActionProc
, &m_sbHorizontal
) ;
2843 SetControlReference( m_sbHorizontal
, (SInt32
) this ) ;
2844 SetControlAction( m_sbHorizontal
, gTXNScrollActionProc
);
2845 ShowControl( m_sbHorizontal
) ;
2846 EmbedControl( m_sbHorizontal
, m_controlRef
) ;
2847 frameOptions
&= ~(kTXNWantHScrollBarMask
| kTXNDrawGrowIconMask
);
2852 verify_noerr(TXNNewObject(NULL
, m_txnWindow
, &bounds
,
2854 kTXNTextEditStyleFrameType
,
2856 kTXNSystemDefaultEncoding
,
2857 &m_txn
, &m_txnFrameID
, NULL
) );
2860 TXNControlTag iControlTags
[] = { kTXNUseCarbonEvents
};
2861 TXNControlData iControlData
[] = { {(UInt32
) &cInfo
} };
2862 int toptag
= WXSIZEOF( iControlTags
) ;
2863 TXNCarbonEventInfo cInfo
;
2864 cInfo
.useCarbonEvents
= false ;
2867 cInfo
.fDictionary
= NULL
;
2869 verify_noerr( TXNSetTXNObjectControls( m_txn
, false , toptag
, iControlTags
, iControlData
)) ;
2872 #ifdef __WXMAC_OSX__
2873 TXNRegisterScrollInfoProc( m_txn
, gTXNScrollInfoProc
, (SInt32
) this);
2876 SetGWorld( origPort
, origDev
) ;
2880 // ----------------------------------------------------------------------------
2881 // MLTE control implementation (OSX part)
2882 // ----------------------------------------------------------------------------
2884 #if TARGET_API_MAC_OSX
2886 #if MAC_OS_X_VERSION_MAX_ALLOWED > MAC_OS_X_VERSION_10_2
2888 wxMacMLTEHIViewControl
::wxMacMLTEHIViewControl( wxTextCtrl
*wxPeer
,
2889 const wxString
& str
,
2891 const wxSize
& size
, long style
) : wxMacMLTEControl( wxPeer
)
2893 m_font
= wxPeer
->GetFont() ;
2894 m_windowStyle
= style
;
2895 Rect bounds
= wxMacGetBoundsForControl( wxPeer
, pos
, size
) ;
2897 wxMacConvertNewlines10To13( &st
) ;
2899 HIRect hr
= { { bounds
.left
, bounds
.top
} ,
2900 { bounds
.right
- bounds
.left
, bounds
.bottom
- bounds
.top
} } ;
2902 m_scrollView
= NULL
;
2903 TXNFrameOptions frameOptions
= FrameOptionsFromWXStyle( style
) ;
2904 if ( frameOptions
& (kTXNWantVScrollBarMask
| kTXNWantHScrollBarMask
) )
2907 (frameOptions
& kTXNWantHScrollBarMask ? kHIScrollViewOptionsHorizScroll
: 0)
2908 | (frameOptions
& kTXNWantVScrollBarMask ? kHIScrollViewOptionsVertScroll
: 0) ,
2911 HIViewSetFrame( m_scrollView
, &hr
);
2912 HIViewSetVisible( m_scrollView
, true );
2916 HITextViewCreate( NULL
, 0, frameOptions
, &m_textView
) ;
2917 m_txn
= HITextViewGetTXNObject( m_textView
) ;
2918 HIViewSetVisible( m_textView
, true ) ;
2921 HIViewAddSubview( m_scrollView
, m_textView
) ;
2922 m_controlRef
= m_scrollView
;
2923 wxPeer
->MacInstallEventHandler( (WXWidget
) m_textView
) ;
2927 HIViewSetFrame( m_textView
, &hr
);
2928 m_controlRef
= m_textView
;
2931 AdjustCreationAttributes( *wxWHITE
, true ) ;
2933 wxMacWindowClipper
c( m_peer
) ;
2934 SetTXNData( st
, kTXNStartOffset
, kTXNEndOffset
) ;
2936 TXNSetSelection( m_txn
, 0, 0 );
2937 TXNShowSelection( m_txn
, kTXNShowStart
);
2940 OSStatus wxMacMLTEHIViewControl
::SetFocus( ControlFocusPart focusPart
)
2942 return SetKeyboardFocus( GetControlOwner( m_textView
), m_textView
, focusPart
) ;
2945 bool wxMacMLTEHIViewControl
::HasFocus() const
2947 ControlRef control
;
2948 GetKeyboardFocus( GetUserFocusWindow() , &control
) ;
2949 return control
== m_textView
;
2952 void wxMacMLTEHIViewControl
::SetBackground( const wxBrush
&brush
)
2954 wxMacMLTEControl
::SetBackground( brush
) ;
2957 CGColorSpaceRef rgbSpace
= CGColorSpaceCreateDeviceRGB();
2958 RGBColor col
= MAC_WXCOLORREF(brush
.GetColour().GetPixel()) ;
2960 float component
[4] ;
2961 component
[0] = col
.red
/ 65536.0 ;
2962 component
[1] = col
.green
/ 65536.0 ;
2963 component
[2] = col
.blue
/ 65536.0 ;
2964 component
[3] = 1.0 ; // alpha
2966 CGColorRef color
= CGColorCreate (rgbSpace
, component
);
2967 HITextViewSetBackgroundColor( m_textView
, color
) ;
2968 CGColorSpaceRelease( rgbSpace
);
2972 #endif // MAC_OS_X_VERSION_MAX_ALLOWED > MAC_OS_X_VERSION_10_2
2977 #endif // wxUSE_TEXTCTRL