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
963 if ( !(m_windowStyle
& wxTE_PROCESS_TAB
))
966 if (!event
.ShiftDown())
967 flags
|= wxNavigationKeyEvent::IsForward
;
968 if (event
.ControlDown())
969 flags
|= wxNavigationKeyEvent::WinChange
;
976 // This is necessary (don't know why);
977 // otherwise the tab will not be inserted.
978 WriteText(wxT("\t"));
988 // perform keystroke handling
989 if ( wxTheApp
->MacGetCurrentEvent() != NULL
&& wxTheApp
->MacGetCurrentEventHandlerCallRef() != NULL
)
990 CallNextEventHandler((EventHandlerCallRef
)wxTheApp
->MacGetCurrentEventHandlerCallRef() , (EventRef
) wxTheApp
->MacGetCurrentEvent() ) ;
994 if ( wxMacConvertEventToRecord( (EventRef
) wxTheApp
->MacGetCurrentEvent() , &rec
) )
996 EventRecord
*ev
= &rec
;
999 keychar
= short(ev
->message
& charCodeMask
);
1000 keycode
= short(ev
->message
& keyCodeMask
) >> 8 ;
1002 m_peer
->HandleKey( keycode
, keychar
, ev
->modifiers
) ;
1007 if ( ( key
>= 0x20 && key
< WXK_START
) ||
1008 key
== WXK_RETURN
||
1009 key
== WXK_DELETE
||
1012 wxCommandEvent
event1(wxEVT_COMMAND_TEXT_UPDATED
, m_windowId
);
1013 event1
.SetEventObject( this );
1014 wxPostEvent(GetEventHandler(),event1
);
1018 // ----------------------------------------------------------------------------
1019 // standard handlers for standard edit menu events
1020 // ----------------------------------------------------------------------------
1022 void wxTextCtrl::OnCut(wxCommandEvent
& WXUNUSED(event
))
1027 void wxTextCtrl::OnCopy(wxCommandEvent
& WXUNUSED(event
))
1032 void wxTextCtrl::OnPaste(wxCommandEvent
& WXUNUSED(event
))
1037 void wxTextCtrl::OnUndo(wxCommandEvent
& WXUNUSED(event
))
1042 void wxTextCtrl::OnRedo(wxCommandEvent
& WXUNUSED(event
))
1047 void wxTextCtrl::OnDelete(wxCommandEvent
& WXUNUSED(event
))
1050 GetSelection(& from
, & to
);
1051 if (from
!= -1 && to
!= -1)
1055 void wxTextCtrl::OnSelectAll(wxCommandEvent
& WXUNUSED(event
))
1057 SetSelection(-1, -1);
1060 void wxTextCtrl::OnUpdateCut(wxUpdateUIEvent
& event
)
1062 event
.Enable( CanCut() );
1065 void wxTextCtrl::OnUpdateCopy(wxUpdateUIEvent
& event
)
1067 event
.Enable( CanCopy() );
1070 void wxTextCtrl::OnUpdatePaste(wxUpdateUIEvent
& event
)
1072 event
.Enable( CanPaste() );
1075 void wxTextCtrl::OnUpdateUndo(wxUpdateUIEvent
& event
)
1077 event
.Enable( CanUndo() );
1080 void wxTextCtrl::OnUpdateRedo(wxUpdateUIEvent
& event
)
1082 event
.Enable( CanRedo() );
1085 void wxTextCtrl::OnUpdateDelete(wxUpdateUIEvent
& event
)
1088 GetSelection(& from
, & to
);
1089 event
.Enable(from
!= -1 && to
!= -1 && from
!= to
&& IsEditable()) ;
1092 void wxTextCtrl::OnUpdateSelectAll(wxUpdateUIEvent
& event
)
1094 event
.Enable(GetLastPosition() > 0);
1097 // CS: Context Menus only work with MLTE implementations or non-multiline HIViews at the moment
1099 void wxTextCtrl::OnContextMenu(wxContextMenuEvent
& event
)
1101 if ( GetPeer()->HasOwnContextMenu() )
1107 if (m_privateContextMenu
== NULL
)
1109 m_privateContextMenu
= new wxMenu
;
1110 m_privateContextMenu
->Append(wxID_UNDO
, _("&Undo"));
1111 m_privateContextMenu
->Append(wxID_REDO
, _("&Redo"));
1112 m_privateContextMenu
->AppendSeparator();
1113 m_privateContextMenu
->Append(wxID_CUT
, _("Cu&t"));
1114 m_privateContextMenu
->Append(wxID_COPY
, _("&Copy"));
1115 m_privateContextMenu
->Append(wxID_PASTE
, _("&Paste"));
1116 m_privateContextMenu
->Append(wxID_CLEAR
, _("&Delete"));
1117 m_privateContextMenu
->AppendSeparator();
1118 m_privateContextMenu
->Append(wxID_SELECTALL
, _("Select &All"));
1121 if (m_privateContextMenu
!= NULL
)
1122 PopupMenu(m_privateContextMenu
);
1125 bool wxTextCtrl::MacSetupCursor( const wxPoint
& pt
)
1127 if ( !GetPeer()->SetupCursor(pt
) )
1128 return wxWindow::MacSetupCursor( pt
) ;
1133 #if !TARGET_API_MAC_OSX
1135 // user pane implementation
1137 void wxTextCtrl::MacControlUserPaneDrawProc(wxInt16 part
)
1139 GetPeer()->MacControlUserPaneDrawProc( part
) ;
1142 wxInt16
wxTextCtrl::MacControlUserPaneHitTestProc(wxInt16 x
, wxInt16 y
)
1144 return GetPeer()->MacControlUserPaneHitTestProc( x
, y
) ;
1147 wxInt16
wxTextCtrl::MacControlUserPaneTrackingProc(wxInt16 x
, wxInt16 y
, void* actionProc
)
1149 return GetPeer()->MacControlUserPaneTrackingProc( x
, y
, actionProc
) ;
1152 void wxTextCtrl::MacControlUserPaneIdleProc()
1154 GetPeer()->MacControlUserPaneIdleProc( ) ;
1157 wxInt16
wxTextCtrl::MacControlUserPaneKeyDownProc(wxInt16 keyCode
, wxInt16 charCode
, wxInt16 modifiers
)
1159 return GetPeer()->MacControlUserPaneKeyDownProc( keyCode
, charCode
, modifiers
) ;
1162 void wxTextCtrl::MacControlUserPaneActivateProc(bool activating
)
1164 GetPeer()->MacControlUserPaneActivateProc( activating
) ;
1167 wxInt16
wxTextCtrl::MacControlUserPaneFocusProc(wxInt16 action
)
1169 return GetPeer()->MacControlUserPaneFocusProc( action
) ;
1172 void wxTextCtrl::MacControlUserPaneBackgroundProc(void* info
)
1174 GetPeer()->MacControlUserPaneBackgroundProc( info
) ;
1179 // ----------------------------------------------------------------------------
1180 // implementation base class
1181 // ----------------------------------------------------------------------------
1183 wxMacTextControl::wxMacTextControl(wxTextCtrl
* peer
) :
1184 wxMacControl( peer
)
1188 wxMacTextControl::~wxMacTextControl()
1192 void wxMacTextControl::SetStyle(long start
, long end
, const wxTextAttr
& style
)
1196 void wxMacTextControl::Copy()
1200 void wxMacTextControl::Cut()
1204 void wxMacTextControl::Paste()
1208 bool wxMacTextControl::CanPaste() const
1213 void wxMacTextControl::SetEditable(bool editable
)
1217 wxTextPos
wxMacTextControl::GetLastPosition() const
1219 return GetStringValue().Length() ;
1222 void wxMacTextControl::Replace( long from
, long to
, const wxString
&val
)
1224 SetSelection( from
, to
) ;
1228 void wxMacTextControl::Remove( long from
, long to
)
1230 SetSelection( from
, to
) ;
1231 WriteText( wxEmptyString
) ;
1234 void wxMacTextControl::Clear()
1236 SetStringValue( wxEmptyString
) ;
1239 bool wxMacTextControl::CanUndo() const
1244 void wxMacTextControl::Undo()
1248 bool wxMacTextControl::CanRedo() const
1253 void wxMacTextControl::Redo()
1257 long wxMacTextControl::XYToPosition(long x
, long y
) const
1262 bool wxMacTextControl::PositionToXY(long pos
, long *x
, long *y
) const
1267 void wxMacTextControl::ShowPosition( long WXUNUSED(pos
) )
1271 int wxMacTextControl::GetNumberOfLines() const
1273 ItemCount lines
= 0 ;
1274 wxString content
= GetStringValue() ;
1277 for (size_t i
= 0; i
< content
.Length() ; i
++)
1279 if (content
[i
] == '\r')
1286 wxString
wxMacTextControl::GetLineText(long lineNo
) const
1288 // TODO: change this if possible to reflect real lines
1289 wxString content
= GetStringValue() ;
1293 for (size_t i
= 0; i
< content
.Length() ; i
++)
1295 if (count
== lineNo
)
1297 // Add chars in line then
1300 for (size_t j
= i
; j
< content
.Length(); j
++)
1302 if (content
[j
] == '\n')
1311 if (content
[i
] == '\n')
1315 return wxEmptyString
;
1318 int wxMacTextControl::GetLineLength(long lineNo
) const
1320 // TODO: change this if possible to reflect real lines
1321 wxString content
= GetStringValue() ;
1325 for (size_t i
= 0; i
< content
.Length() ; i
++)
1327 if (count
== lineNo
)
1329 // Count chars in line then
1331 for (size_t j
= i
; j
< content
.Length(); j
++)
1334 if (content
[j
] == '\n')
1341 if (content
[i
] == '\n')
1348 // ----------------------------------------------------------------------------
1349 // standard unicode control implementation
1350 // ----------------------------------------------------------------------------
1352 #if TARGET_API_MAC_OSX
1354 wxMacUnicodeTextControl::wxMacUnicodeTextControl( wxTextCtrl
*wxPeer
,
1355 const wxString
& str
,
1357 const wxSize
& size
, long style
) : wxMacTextControl( wxPeer
)
1359 m_font
= wxPeer
->GetFont() ;
1360 m_windowStyle
= style
;
1361 Rect bounds
= wxMacGetBoundsForControl( wxPeer
, pos
, size
) ;
1363 wxMacConvertNewlines10To13( &st
) ;
1364 wxMacCFStringHolder
cf(st
, m_font
.GetEncoding()) ;
1365 CFStringRef cfr
= cf
;
1366 Boolean isPassword
= ( m_windowStyle
& wxTE_PASSWORD
) != 0 ;
1367 m_valueTag
= isPassword
? kControlEditTextPasswordCFStringTag
: kControlEditTextCFStringTag
;
1368 CreateEditUnicodeTextControl(
1369 MAC_WXHWND(wxPeer
->MacGetTopLevelWindowRef()), &bounds
, cfr
,
1370 isPassword
, NULL
, &m_controlRef
) ;
1372 if ( !(m_windowStyle
& wxTE_MULTILINE
) )
1373 SetData
<Boolean
>( kControlEditTextPart
, kControlEditTextSingleLineTag
, true ) ;
1376 wxMacUnicodeTextControl::~wxMacUnicodeTextControl()
1380 void wxMacUnicodeTextControl::VisibilityChanged(bool shown
)
1382 if ( !(m_windowStyle
& wxTE_MULTILINE
) && shown
)
1384 // work around a refresh issue insofar as not always the entire content is shown,
1385 // even if this would be possible
1386 ControlEditTextSelectionRec sel
;
1387 CFStringRef value
= NULL
;
1389 verify_noerr( GetData
<ControlEditTextSelectionRec
>( 0, kControlEditTextSelectionTag
, &sel
) );
1390 verify_noerr( GetData
<CFStringRef
>( 0, m_valueTag
, &value
) );
1391 verify_noerr( SetData
<CFStringRef
>( 0, m_valueTag
, &value
) );
1392 verify_noerr( SetData
<ControlEditTextSelectionRec
>( 0, kControlEditTextSelectionTag
, &sel
) );
1394 CFRelease( value
) ;
1398 wxString
wxMacUnicodeTextControl::GetStringValue() const
1401 CFStringRef value
= GetData
<CFStringRef
>(0,m_valueTag
) ;
1404 wxMacCFStringHolder
cf(value
) ;
1405 result
= cf
.AsString() ;
1409 wxMacConvertNewlines13To10( &result
) ;
1411 wxMacConvertNewlines10To13( &result
) ;
1417 void wxMacUnicodeTextControl::SetStringValue( const wxString
&str
)
1420 wxMacConvertNewlines10To13( &st
) ;
1421 wxMacCFStringHolder
cf(st
, m_font
.GetEncoding() ) ;
1422 verify_noerr( SetData
<CFStringRef
>( 0, m_valueTag
, cf
) ) ;
1425 void wxMacUnicodeTextControl::Copy()
1427 SendHICommand( kHICommandCopy
) ;
1430 void wxMacUnicodeTextControl::Cut()
1432 SendHICommand( kHICommandCut
) ;
1435 void wxMacUnicodeTextControl::Paste()
1437 SendHICommand( kHICommandPaste
) ;
1440 bool wxMacUnicodeTextControl::CanPaste() const
1445 void wxMacUnicodeTextControl::SetEditable(bool editable
)
1447 SetData
<Boolean
>( 0 , kControlEditTextLockedTag
, (Boolean
) !editable
) ;
1450 void wxMacUnicodeTextControl::GetSelection( long* from
, long* to
) const
1452 ControlEditTextSelectionRec sel
;
1453 verify_noerr(GetData
<ControlEditTextSelectionRec
>( 0, kControlEditTextSelectionTag
, &sel
) ) ;
1454 if ( from
) *from
= sel
.selStart
;
1455 if ( to
) *to
= sel
.selEnd
;
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
) ;
1476 #if MAC_OS_X_VERSION_MAX_ALLOWED > MAC_OS_X_VERSION_10_2
1477 wxMacCFStringHolder
cf(st
, m_font
.GetEncoding() ) ;
1478 CFStringRef value
= cf
;
1479 SetData
<CFStringRef
>( 0, kControlEditTextInsertCFStringRefTag
, &value
);
1481 wxString val
= GetStringValue() ;
1483 GetSelection( &start
, &end
) ;
1484 val
.Remove( start
, end
- start
) ;
1485 val
.insert( start
, str
) ;
1486 SetStringValue( val
) ;
1487 SetSelection( start
+ str
.Length() , start
+ str
.Length() ) ;
1493 // ----------------------------------------------------------------------------
1494 // MLTE control implementation (common part)
1495 // ----------------------------------------------------------------------------
1497 // if MTLE is read only, no changes at all are allowed, not even from
1498 // procedural API, in order to allow changes via API all the same we must undo
1499 // the readonly status while we are executing, this class helps to do so
1501 class wxMacEditHelper
1504 wxMacEditHelper( TXNObject txn
)
1506 TXNControlTag tag
[] = { kTXNIOPrivilegesTag
} ;
1508 TXNGetTXNObjectControls( m_txn
, 1 , tag
, m_data
) ;
1509 if ( m_data
[0].uValue
== kTXNReadOnly
)
1511 TXNControlData data
[] = { { kTXNReadWrite
} } ;
1512 TXNSetTXNObjectControls( m_txn
, false , 1 , tag
, data
) ;
1518 TXNControlTag tag
[] = { kTXNIOPrivilegesTag
} ;
1519 if ( m_data
[0].uValue
== kTXNReadOnly
)
1520 TXNSetTXNObjectControls( m_txn
, false , 1 , tag
, m_data
) ;
1525 TXNControlData m_data
[1] ;
1528 wxMacMLTEControl::wxMacMLTEControl( wxTextCtrl
*peer
) : wxMacTextControl( peer
)
1530 SetNeedsFocusRect( true ) ;
1533 wxString
wxMacMLTEControl::GetStringValue() const
1537 Size actualSize
= 0;
1541 err
= TXNGetDataEncoded( m_txn
, kTXNStartOffset
, kTXNEndOffset
, &theText
, kTXNUnicodeTextData
);
1550 actualSize
= GetHandleSize( theText
) / sizeof( UniChar
) ;
1551 if ( actualSize
> 0 )
1553 wxChar
*ptr
= NULL
;
1555 #if SIZEOF_WCHAR_T == 2
1556 ptr
= new wxChar
[actualSize
+ 1 ] ;
1557 wxStrncpy( ptr
, (wxChar
*) *theText
, actualSize
) ;
1559 SetHandleSize( theText
, ( actualSize
+ 1 ) * sizeof( UniChar
) ) ;
1561 (((UniChar
*)*theText
)[actualSize
]) = 0 ;
1562 wxMBConvUTF16 converter
;
1563 size_t noChars
= converter
.MB2WC( NULL
, (const char*)*theText
, 0 ) ;
1564 ptr
= new wxChar
[noChars
+ 1] ;
1566 noChars
= converter
.MB2WC( ptr
, (const char*)*theText
, noChars
) ;
1568 HUnlock( theText
) ;
1571 ptr
[actualSize
] = 0 ;
1572 result
= wxString( ptr
) ;
1576 DisposeHandle( theText
) ;
1580 err
= TXNGetDataEncoded( m_txn
, kTXNStartOffset
, kTXNEndOffset
, &theText
, kTXNTextData
);
1588 actualSize
= GetHandleSize( theText
) ;
1589 if ( actualSize
> 0 )
1592 result
= wxString( *theText
, wxConvLocal
, actualSize
) ;
1593 HUnlock( theText
) ;
1596 DisposeHandle( theText
) ;
1602 wxMacConvertNewlines13To10( &result
) ;
1604 wxMacConvertNewlines10To13( &result
) ;
1610 void wxMacMLTEControl::SetStringValue( const wxString
&str
)
1614 wxMacConvertNewlines10To13( &st
) ;
1616 wxMacWindowClipper
c( m_peer
) ;
1618 wxMacEditHelper
help(m_txn
) ;
1619 SetTXNData( st
, kTXNStartOffset
, kTXNEndOffset
) ;
1621 TXNSetSelection( m_txn
, 0, 0 );
1622 TXNShowSelection( m_txn
, kTXNShowStart
);
1626 TXNFrameOptions
wxMacMLTEControl::FrameOptionsFromWXStyle( long wxStyle
)
1628 TXNFrameOptions frameOptions
=
1629 kTXNDontDrawCaretWhenInactiveMask
1630 #if MAC_OS_X_VERSION_MAX_ALLOWED >= MAC_OS_X_VERSION_10_3
1631 | kTXNDoFontSubstitutionMask
1635 if ( ! ( wxStyle
& wxTE_NOHIDESEL
) )
1636 frameOptions
|= kTXNDontDrawSelectionWhenInactiveMask
;
1638 if ( wxStyle
& wxTE_MULTILINE
)
1640 if ( ! ( wxStyle
& wxTE_DONTWRAP
) )
1641 frameOptions
|= kTXNAlwaysWrapAtViewEdgeMask
;
1644 frameOptions
|= kTXNAlwaysWrapAtViewEdgeMask
;
1645 frameOptions
|= kTXNWantHScrollBarMask
;
1648 if ( !(wxStyle
& wxTE_NO_VSCROLL
) )
1650 frameOptions
|= kTXNWantVScrollBarMask
;
1651 if ( frameOptions
& kTXNWantHScrollBarMask
)
1652 frameOptions
|= kTXNDrawGrowIconMask
;
1656 frameOptions
|= kTXNSingleLineOnlyMask
;
1658 if ( wxStyle
& wxHSCROLL
)
1659 frameOptions
|= kTXNWantHScrollBarMask
;
1661 return frameOptions
;
1664 void wxMacMLTEControl::AdjustCreationAttributes( const wxColour
&background
, bool visible
)
1666 TXNControlTag iControlTags
[] =
1668 kTXNDoFontSubstitution
,
1669 kTXNWordWrapStateTag
,
1671 TXNControlData iControlData
[] =
1677 int toptag
= WXSIZEOF( iControlTags
) ;
1679 if ( m_windowStyle
& wxTE_MULTILINE
)
1681 if (m_windowStyle
& wxTE_DONTWRAP
)
1682 iControlData
[1].uValue
= kTXNNoAutoWrap
;
1684 iControlData
[1].uValue
= kTXNAutoWrap
;
1686 verify_noerr( TXNSetTXNObjectControls( m_txn
, false, toptag
,
1687 iControlTags
, iControlData
)) ;
1689 // setting the default font:
1690 // under 10.2 this causes a visible caret, therefore we avoid it
1692 if ( UMAGetSystemVersion() >= 0x1030 )
1698 GetThemeFont(kThemeSystemFont
, GetApplicationScript() , fontName
, &fontSize
, &fontStyle
) ;
1700 TXNTypeAttributes typeAttr
[] =
1702 { kTXNQDFontNameAttribute
, kTXNQDFontNameAttributeSize
, { (void*) fontName
} } ,
1703 { kTXNQDFontSizeAttribute
, kTXNFontSizeAttributeSize
, { (void*) (fontSize
<< 16) } } ,
1704 { kTXNQDFontStyleAttribute
, kTXNQDFontStyleAttributeSize
, { (void*) normal
} } ,
1707 verify_noerr( TXNSetTypeAttributes (m_txn
, sizeof( typeAttr
) / sizeof(TXNTypeAttributes
) , typeAttr
,
1712 if ( m_windowStyle
& wxTE_PASSWORD
)
1715 verify_noerr(TXNEchoMode( m_txn
, c
, 0 , true )) ;
1718 TXNBackground tback
;
1719 tback
.bgType
= kTXNBackgroundTypeRGB
;
1720 tback
.bg
.color
= MAC_WXCOLORREF( background
.GetPixel() );
1721 TXNSetBackground( m_txn
, &tback
);
1723 #if MAC_OS_X_VERSION_MAX_ALLOWED >= MAC_OS_X_VERSION_10_4
1724 if ( UMAGetSystemVersion() >= 0x1040 )
1726 TXNCommandEventSupportOptions options
;
1727 if ( TXNGetCommandEventSupport( m_txn
, &options
) == noErr
)
1730 kTXNSupportEditCommandProcessing
1731 | kTXNSupportEditCommandUpdating
1732 | kTXNSupportSpellCheckCommandProcessing
1733 | kTXNSupportSpellCheckCommandUpdating
1734 | kTXNSupportFontCommandProcessing
1735 | kTXNSupportFontCommandUpdating
;
1737 TXNSetCommandEventSupport( m_txn
, options
) ;
1743 void wxMacMLTEControl::SetBackground( const wxBrush
&brush
)
1745 // currently only solid background are supported
1746 TXNBackground tback
;
1747 tback
.bgType
= kTXNBackgroundTypeRGB
;
1748 tback
.bg
.color
= MAC_WXCOLORREF( brush
.GetColour().GetPixel() );
1749 TXNSetBackground( m_txn
, &tback
);
1752 void wxMacMLTEControl::TXNSetAttribute( const wxTextAttr
& style
, long from
, long to
)
1754 TXNTypeAttributes typeAttr
[4] ;
1755 Str255 fontName
= "\pMonaco" ;
1756 SInt16 fontSize
= 12 ;
1757 Style fontStyle
= normal
;
1759 int attrCounter
= 0 ;
1761 if ( style
.HasFont() )
1763 const wxFont
&font
= style
.GetFont() ;
1764 wxMacStringToPascal( font
.GetFaceName() , fontName
) ;
1765 fontSize
= font
.GetPointSize() ;
1766 if ( font
.GetUnderlined() )
1767 fontStyle
|= underline
;
1768 if ( font
.GetWeight() == wxBOLD
)
1770 if ( font
.GetStyle() == wxITALIC
)
1771 fontStyle
|= italic
;
1773 typeAttr
[attrCounter
].tag
= kTXNQDFontNameAttribute
;
1774 typeAttr
[attrCounter
].size
= kTXNQDFontNameAttributeSize
;
1775 typeAttr
[attrCounter
].data
.dataPtr
= (void*) fontName
;
1776 typeAttr
[attrCounter
+1].tag
= kTXNQDFontSizeAttribute
;
1777 typeAttr
[attrCounter
+1].size
= kTXNFontSizeAttributeSize
;
1778 typeAttr
[attrCounter
+1].data
.dataValue
= (fontSize
<< 16) ;
1779 typeAttr
[attrCounter
+2].tag
= kTXNQDFontStyleAttribute
;
1780 typeAttr
[attrCounter
+2].size
= kTXNQDFontStyleAttributeSize
;
1781 typeAttr
[attrCounter
+2].data
.dataValue
= fontStyle
;
1785 if ( style
.HasTextColour() )
1787 typeAttr
[attrCounter
].tag
= kTXNQDFontColorAttribute
;
1788 typeAttr
[attrCounter
].size
= kTXNQDFontColorAttributeSize
;
1789 typeAttr
[attrCounter
].data
.dataPtr
= (void*) &color
;
1790 color
= MAC_WXCOLORREF(style
.GetTextColour().GetPixel()) ;
1794 if ( attrCounter
> 0 )
1796 verify_noerr( TXNSetTypeAttributes ( m_txn
, attrCounter
, typeAttr
, from
, to
) );
1800 void wxMacMLTEControl::SetFont( const wxFont
& font
, const wxColour
& foreground
, long windowStyle
)
1802 wxMacEditHelper
help(m_txn
) ;
1803 TXNSetAttribute( wxTextAttr(foreground
,wxNullColour
,font
) , kTXNStartOffset
,kTXNEndOffset
) ;
1806 void wxMacMLTEControl::SetStyle(long start
, long end
, const wxTextAttr
& style
)
1808 wxMacEditHelper
help(m_txn
) ;
1809 TXNSetAttribute( style
, start
,end
) ;
1812 void wxMacMLTEControl::Copy()
1814 ClearCurrentScrap();
1816 TXNConvertToPublicScrap();
1819 void wxMacMLTEControl::Cut()
1821 ClearCurrentScrap();
1823 TXNConvertToPublicScrap();
1826 void wxMacMLTEControl::Paste()
1828 TXNConvertFromPublicScrap();
1832 bool wxMacMLTEControl::CanPaste() const
1834 return TXNIsScrapPastable() ;
1837 void wxMacMLTEControl::SetEditable(bool editable
)
1839 TXNControlTag tag
[] = { kTXNIOPrivilegesTag
} ;
1840 TXNControlData data
[] = { { editable
? kTXNReadWrite
: kTXNReadOnly
} } ;
1841 TXNSetTXNObjectControls( m_txn
, false , WXSIZEOF(tag
) , tag
, data
) ;
1844 wxTextPos
wxMacMLTEControl::GetLastPosition() const
1846 wxTextPos actualsize
= 0 ;
1849 OSErr err
= TXNGetDataEncoded( m_txn
, kTXNStartOffset
, kTXNEndOffset
, &theText
, kTXNTextData
);
1854 actualsize
= GetHandleSize( theText
) ;
1855 DisposeHandle( theText
) ;
1865 void wxMacMLTEControl::Replace( long from
, long to
, const wxString
&str
)
1867 wxString value
= str
;
1868 wxMacConvertNewlines10To13( &value
) ;
1870 wxMacEditHelper
help( m_txn
) ;
1871 wxMacWindowClipper
c( m_peer
) ;
1873 TXNSetSelection(m_txn
, from
, to
) ;
1875 SetTXNData( value
, kTXNUseCurrentSelection
, kTXNUseCurrentSelection
) ;
1878 void wxMacMLTEControl::Remove( long from
, long to
)
1880 wxMacWindowClipper
c( m_peer
) ;
1881 wxMacEditHelper
help( m_txn
) ;
1882 TXNSetSelection(m_txn
, from
, to
) ;
1886 void wxMacMLTEControl::GetSelection( long* from
, long* to
) const
1888 TXNGetSelection( m_txn
, (TXNOffset
*) from
, (TXNOffset
*) to
) ;
1891 void wxMacMLTEControl::SetSelection( long from
, long to
)
1893 wxMacWindowClipper
c( m_peer
) ;
1895 // change the selection
1896 if ((from
== -1) && (to
== -1))
1897 TXNSelectAll(m_txn
);
1899 TXNSetSelection( m_txn
, from
, to
);
1900 TXNShowSelection( m_txn
, kTXNShowStart
);
1903 void wxMacMLTEControl::WriteText(const wxString
& str
)
1906 wxMacConvertNewlines10To13( &st
) ;
1908 long start
, end
, dummy
;
1909 GetSelection( &start
, &dummy
) ;
1910 wxMacWindowClipper
c( m_peer
) ;
1912 wxMacEditHelper
helper( m_txn
) ;
1913 SetTXNData( st
, kTXNUseCurrentSelection
, kTXNUseCurrentSelection
) ;
1916 GetSelection( &dummy
, &end
) ;
1918 // TODO: SetStyle( start , end , GetDefaultStyle() ) ;
1921 void wxMacMLTEControl::Clear()
1923 wxMacWindowClipper
c( m_peer
) ;
1924 wxMacEditHelper
st(m_txn
) ;
1925 TXNSetSelection( m_txn
, kTXNStartOffset
, kTXNEndOffset
) ;
1929 bool wxMacMLTEControl::CanUndo() const
1931 return TXNCanUndo( m_txn
, NULL
) ;
1934 void wxMacMLTEControl::Undo()
1939 bool wxMacMLTEControl::CanRedo() const
1941 return TXNCanRedo( m_txn
, NULL
) ;
1944 void wxMacMLTEControl::Redo()
1949 int wxMacMLTEControl::GetNumberOfLines() const
1951 ItemCount lines
= 0 ;
1952 TXNGetLineCount( m_txn
, &lines
) ;
1957 long wxMacMLTEControl::XYToPosition(long x
, long y
) const
1962 // TODO: find a better implementation : while we can get the
1963 // line metrics of a certain line, we don't get its starting
1964 // position, so it would probably be rather a binary search
1965 // for the start position
1968 int lastHeight
= 0 ;
1971 lastpos
= GetLastPosition() ;
1972 for ( n
= 0 ; n
<= (ItemCount
) lastpos
; ++n
)
1974 if ( y
== ypos
&& x
== xpos
)
1977 TXNOffsetToPoint( m_txn
, n
, &curpt
);
1979 if ( curpt
.v
> lastHeight
)
1984 lastHeight
= curpt
.v
;
1993 bool wxMacMLTEControl::PositionToXY(long pos
, long *x
, long *y
) const
2003 lastpos
= GetLastPosition() ;
2004 if ( pos
<= lastpos
)
2006 // TODO find a better implementation : while we can get the
2007 // line metrics of a certain line, we don't get its starting
2008 // position, so it would probably be rather a binary search
2009 // for the start position
2012 int lastHeight
= 0 ;
2015 for ( n
= 0 ; n
<= (ItemCount
) pos
; ++n
)
2017 TXNOffsetToPoint(m_txn
, n
, &curpt
);
2019 if ( curpt
.v
> lastHeight
)
2024 lastHeight
= curpt
.v
;
2039 void wxMacMLTEControl::ShowPosition( long pos
)
2041 #if TARGET_RT_MAC_MACHO && defined(AVAILABLE_MAC_OS_X_VERSION_10_2_AND_LATER)
2043 Point current
, desired
;
2044 TXNOffset selstart
, selend
;
2046 TXNGetSelection( m_txn
, &selstart
, &selend
);
2047 TXNOffsetToPoint( m_txn
, selstart
, ¤t
);
2048 TXNOffsetToPoint( m_txn
, pos
, &desired
);
2050 // TODO: use HIPoints for 10.3 and above
2051 if ( (UInt32
)TXNScroll
!= (UInt32
)kUnresolvedCFragSymbolAddress
)
2053 OSErr theErr
= noErr
;
2054 SInt32 dv
= desired
.v
- current
.v
;
2055 SInt32 dh
= desired
.h
- current
.h
;
2056 TXNShowSelection( m_txn
, kTXNShowEnd
) ; // NB: should this be kTXNShowStart or kTXNShowEnd ??
2057 theErr
= TXNScroll( m_txn
, kTXNScrollUnitsInPixels
, kTXNScrollUnitsInPixels
, &dv
, &dh
);
2059 // there will be an error returned for classic MLTE implementation when the control is
2060 // invisible, but HITextView works correctly, so we don't assert that one
2061 // wxASSERT_MSG( theErr == noErr, _T("TXNScroll returned an error!") );
2067 void wxMacMLTEControl::SetTXNData( const wxString
& st
, TXNOffset start
, TXNOffset end
)
2070 #if SIZEOF_WCHAR_T == 2
2071 size_t len
= st
.Len() ;
2072 TXNSetData( m_txn
, kTXNUnicodeTextData
, (void*)st
.wc_str(), len
* 2, start
, end
);
2074 wxMBConvUTF16 converter
;
2075 ByteCount byteBufferLen
= converter
.WC2MB( NULL
, st
.wc_str() , 0 ) ;
2076 UniChar
*unibuf
= (UniChar
*) malloc( byteBufferLen
) ;
2077 converter
.WC2MB( (char*)unibuf
, st
.wc_str(), byteBufferLen
) ;
2078 TXNSetData( m_txn
, kTXNUnicodeTextData
, (void*)unibuf
, byteBufferLen
, start
, end
) ;
2082 wxCharBuffer text
= st
.mb_str(wxConvLocal
) ;
2083 TXNSetData( m_txn
, kTXNTextData
, (void*)text
.data(), strlen( text
), start
, end
) ;
2087 wxString
wxMacMLTEControl::GetLineText(long lineNo
) const
2091 if ( lineNo
< GetNumberOfLines() )
2094 Fixed lineWidth
, lineHeight
, currentHeight
;
2097 // get the first possible position in the control
2098 TXNOffsetToPoint(m_txn
, 0, &firstPoint
);
2100 // Iterate through the lines until we reach the one we want,
2101 // adding to our current y pixel point position
2104 while (ypos
< lineNo
)
2106 TXNGetLineMetrics(m_txn
, ypos
++, &lineWidth
, &lineHeight
);
2107 currentHeight
+= lineHeight
;
2110 Point thePoint
= { firstPoint
.v
+ (currentHeight
>> 16), firstPoint
.h
+ (0) };
2111 TXNOffset theOffset
;
2112 TXNPointToOffset(m_txn
, thePoint
, &theOffset
);
2114 wxString content
= GetStringValue() ;
2115 Point currentPoint
= thePoint
;
2116 while (thePoint
.v
== currentPoint
.v
&& theOffset
< content
.length())
2118 line
+= content
[theOffset
];
2119 TXNOffsetToPoint(m_txn
, ++theOffset
, ¤tPoint
);
2126 int wxMacMLTEControl::GetLineLength(long lineNo
) const
2130 if ( lineNo
< GetNumberOfLines() )
2133 Fixed lineWidth
, lineHeight
, currentHeight
;
2136 // get the first possible position in the control
2137 TXNOffsetToPoint(m_txn
, 0, &firstPoint
);
2139 // Iterate through the lines until we reach the one we want,
2140 // adding to our current y pixel point position
2143 while (ypos
< lineNo
)
2145 TXNGetLineMetrics(m_txn
, ypos
++, &lineWidth
, &lineHeight
);
2146 currentHeight
+= lineHeight
;
2149 Point thePoint
= { firstPoint
.v
+ (currentHeight
>> 16), firstPoint
.h
+ (0) };
2150 TXNOffset theOffset
;
2151 TXNPointToOffset(m_txn
, thePoint
, &theOffset
);
2153 wxString content
= GetStringValue() ;
2154 Point currentPoint
= thePoint
;
2155 while (thePoint
.v
== currentPoint
.v
&& theOffset
< content
.length())
2158 TXNOffsetToPoint(m_txn
, ++theOffset
, ¤tPoint
);
2166 // ----------------------------------------------------------------------------
2167 // MLTE control implementation (classic part)
2168 // ----------------------------------------------------------------------------
2170 // OS X Notes : We still don't have a full replacement for MLTE, so this implementation
2171 // has to live on. We have different problems coming from outdated implementations on the
2172 // various OS X versions. Most deal with the scrollbars: they are not correctly embedded
2173 // while this can be solved on 10.3 by reassigning them the correct place, on 10.2 there is
2174 // no way out, therefore we are using our own implementation and our own scrollbars ....
2176 #ifdef __WXMAC_OSX__
2178 TXNScrollInfoUPP gTXNScrollInfoProc
= NULL
;
2179 ControlActionUPP gTXNScrollActionProc
= NULL
;
2181 pascal void wxMacMLTEClassicControl::TXNScrollInfoProc(
2182 SInt32 iValue
, SInt32 iMaximumValue
,
2183 TXNScrollBarOrientation iScrollBarOrientation
, SInt32 iRefCon
)
2185 wxMacMLTEClassicControl
* mlte
= (wxMacMLTEClassicControl
*) iRefCon
;
2186 SInt32 value
= wxMax( iValue
, 0 ) ;
2187 SInt32 maximum
= wxMax( iMaximumValue
, 0 ) ;
2189 if ( iScrollBarOrientation
== kTXNHorizontal
)
2191 if ( mlte
->m_sbHorizontal
)
2193 SetControl32BitValue( mlte
->m_sbHorizontal
, value
) ;
2194 SetControl32BitMaximum( mlte
->m_sbHorizontal
, maximum
) ;
2195 mlte
->m_lastHorizontalValue
= value
;
2198 else if ( iScrollBarOrientation
== kTXNVertical
)
2200 if ( mlte
->m_sbVertical
)
2202 SetControl32BitValue( mlte
->m_sbVertical
, value
) ;
2203 SetControl32BitMaximum( mlte
->m_sbVertical
, maximum
) ;
2204 mlte
->m_lastVerticalValue
= value
;
2209 pascal void wxMacMLTEClassicControl::TXNScrollActionProc( ControlRef controlRef
, ControlPartCode partCode
)
2211 wxMacMLTEClassicControl
* mlte
= (wxMacMLTEClassicControl
*) GetControlReference( controlRef
) ;
2215 if ( controlRef
!= mlte
->m_sbVertical
&& controlRef
!= mlte
->m_sbHorizontal
)
2219 bool isHorizontal
= ( controlRef
== mlte
->m_sbHorizontal
) ;
2221 SInt32 minimum
= 0 ;
2222 SInt32 maximum
= GetControl32BitMaximum( controlRef
) ;
2223 SInt32 value
= GetControl32BitValue( controlRef
) ;
2229 case kControlDownButtonPart
:
2233 case kControlUpButtonPart
:
2237 case kControlPageDownPart
:
2238 delta
= GetControlViewSize( controlRef
) ;
2241 case kControlPageUpPart
:
2242 delta
= -GetControlViewSize( controlRef
) ;
2245 case kControlIndicatorPart
:
2247 ( isHorizontal
? mlte
->m_lastHorizontalValue
: mlte
->m_lastVerticalValue
) ;
2256 SInt32 newValue
= value
;
2258 if ( partCode
!= kControlIndicatorPart
)
2260 if ( value
+ delta
< minimum
)
2261 delta
= minimum
- value
;
2262 if ( value
+ delta
> maximum
)
2263 delta
= maximum
- value
;
2265 SetControl32BitValue( controlRef
, value
+ delta
) ;
2266 newValue
= value
+ delta
;
2269 SInt32 verticalDelta
= isHorizontal
? 0 : delta
;
2270 SInt32 horizontalDelta
= isHorizontal
? delta
: 0 ;
2272 err
= TXNScroll( mlte
->m_txn
, kTXNScrollUnitsInPixels
, kTXNScrollUnitsInPixels
,
2273 &verticalDelta
, &horizontalDelta
);
2276 mlte
->m_lastHorizontalValue
= newValue
;
2278 mlte
->m_lastVerticalValue
= newValue
;
2283 // make correct activations
2284 void wxMacMLTEClassicControl::MacActivatePaneText(bool setActive
)
2286 wxTextCtrl
* textctrl
= (wxTextCtrl
*) GetControlReference(m_controlRef
);
2288 wxMacWindowClipper
clipper( textctrl
) ;
2289 TXNActivate(m_txn
, m_txnFrameID
, setActive
);
2291 ControlRef controlFocus
= 0 ;
2292 GetKeyboardFocus( m_txnWindow
, &controlFocus
) ;
2293 if ( controlFocus
== m_controlRef
)
2294 TXNFocus( m_txn
, setActive
);
2297 void wxMacMLTEClassicControl::MacFocusPaneText(bool setFocus
)
2299 TXNFocus( m_txn
, setFocus
);
2302 // guards against inappropriate redraw (hidden objects drawing onto window)
2304 void wxMacMLTEClassicControl::MacSetObjectVisibility(bool vis
)
2306 ControlRef controlFocus
= 0 ;
2307 GetKeyboardFocus( m_txnWindow
, &controlFocus
) ;
2309 if ( !vis
&& (controlFocus
== m_controlRef
) )
2310 SetKeyboardFocus( m_txnWindow
, m_controlRef
, kControlFocusNoPart
) ;
2312 TXNControlTag iControlTags
[1] = { kTXNVisibilityTag
};
2313 TXNControlData iControlData
[1] = { {(UInt32
) false } };
2315 verify_noerr( TXNGetTXNObjectControls( m_txn
, 1, iControlTags
, iControlData
) ) ;
2317 if ( iControlData
[0].uValue
!= vis
)
2319 iControlData
[0].uValue
= vis
;
2320 verify_noerr( TXNSetTXNObjectControls( m_txn
, false , 1, iControlTags
, iControlData
)) ;
2323 // we right now are always clipping as partial visibility (overlapped) visibility
2324 // is also a problem, if we run into further problems we might set the FrameBounds to an empty
2328 // make sure that the TXNObject is at the right position
2330 void wxMacMLTEClassicControl::MacUpdatePosition()
2332 wxTextCtrl
* textctrl
= (wxTextCtrl
*) GetControlReference(m_controlRef
);
2333 if ( textctrl
== NULL
)
2337 UMAGetControlBoundsInWindowCoords(m_controlRef
, &bounds
);
2339 wxRect visRect
= textctrl
->MacGetClippedClientRect() ;
2340 Rect visBounds
= { visRect
.y
, visRect
.x
, visRect
.y
+ visRect
.height
, visRect
.x
+ visRect
.width
} ;
2343 textctrl
->MacWindowToRootWindow( &x
, &y
) ;
2344 OffsetRect( &visBounds
, x
, y
) ;
2346 if ( !EqualRect( &bounds
, &m_txnControlBounds
) || !EqualRect( &visBounds
, &m_txnVisBounds
) )
2348 m_txnControlBounds
= bounds
;
2349 m_txnVisBounds
= visBounds
;
2350 wxMacWindowClipper
cl(textctrl
) ;
2352 #ifdef __WXMAC_OSX__
2353 bool isCompositing
= textctrl
->MacGetTopLevelWindow()->MacUsesCompositing() ;
2354 if ( m_sbHorizontal
|| m_sbVertical
)
2356 int w
= bounds
.right
- bounds
.left
;
2357 int h
= bounds
.bottom
- bounds
.top
;
2359 if ( m_sbHorizontal
)
2363 sbBounds
.left
= -1 ;
2364 sbBounds
.top
= h
- 14 ;
2365 sbBounds
.right
= w
+ 1 ;
2366 sbBounds
.bottom
= h
+ 1 ;
2368 if ( !isCompositing
)
2369 OffsetRect( &sbBounds
, m_txnControlBounds
.left
, m_txnControlBounds
.top
) ;
2371 SetControlBounds( m_sbHorizontal
, &sbBounds
) ;
2372 SetControlViewSize( m_sbHorizontal
, w
) ;
2378 sbBounds
.left
= w
- 14 ;
2380 sbBounds
.right
= w
+ 1 ;
2381 sbBounds
.bottom
= m_sbHorizontal
? h
- 14 : h
+ 1 ;
2383 if ( !isCompositing
)
2384 OffsetRect( &sbBounds
, m_txnControlBounds
.left
, m_txnControlBounds
.top
) ;
2386 SetControlBounds( m_sbVertical
, &sbBounds
) ;
2387 SetControlViewSize( m_sbVertical
, h
) ;
2392 TXNLongRect olddestRect
;
2393 TXNGetRectBounds( m_txn
, &oldviewRect
, &olddestRect
, NULL
) ;
2395 Rect viewRect
= { m_txnControlBounds
.top
, m_txnControlBounds
.left
,
2396 m_txnControlBounds
.bottom
- ( m_sbHorizontal
? 14 : 0 ) ,
2397 m_txnControlBounds
.right
- ( m_sbVertical
? 14 : 0 ) } ;
2398 TXNLongRect destRect
= { m_txnControlBounds
.top
, m_txnControlBounds
.left
,
2399 m_txnControlBounds
.bottom
- ( m_sbHorizontal
? 14 : 0 ) ,
2400 m_txnControlBounds
.right
- ( m_sbVertical
? 14 : 0 ) } ;
2402 if ( olddestRect
.right
>= 10000 )
2403 destRect
.right
= destRect
.left
+ 32000 ;
2405 if ( olddestRect
.bottom
>= 0x20000000 )
2406 destRect
.bottom
= destRect
.top
+ 0x40000000 ;
2408 SectRect( &viewRect
, &visBounds
, &viewRect
) ;
2409 TXNSetRectBounds( m_txn
, &viewRect
, &destRect
, true ) ;
2414 m_txnControlBounds
.top
,
2415 m_txnControlBounds
.left
,
2416 m_txnControlBounds
.bottom
- (m_sbHorizontal
? 14 : 0),
2417 m_txnControlBounds
.right
- (m_sbVertical
? 14 : 0),
2422 TXNSetFrameBounds( m_txn
, m_txnControlBounds
.top
, m_txnControlBounds
.left
,
2423 wxMax( m_txnControlBounds
.bottom
, m_txnControlBounds
.top
) ,
2424 wxMax( m_txnControlBounds
.right
, m_txnControlBounds
.left
) , m_txnFrameID
);
2426 // the SetFrameBounds method unter classic sometimes does not correctly scroll a selection into sight after a
2427 // movement, therefore we have to force it
2429 // this problem has been reported in OSX as well, so we use this here once again
2431 TXNLongRect textRect
;
2432 TXNGetRectBounds( m_txn
, NULL
, NULL
, &textRect
) ;
2433 if ( textRect
.left
< m_txnControlBounds
.left
)
2434 TXNShowSelection( m_txn
, kTXNShowStart
) ;
2438 void wxMacMLTEClassicControl::SetRect( Rect
*r
)
2440 wxMacControl::SetRect( r
) ;
2441 MacUpdatePosition() ;
2444 void wxMacMLTEClassicControl::MacControlUserPaneDrawProc(wxInt16 thePart
)
2446 wxTextCtrl
* textctrl
= (wxTextCtrl
*) GetControlReference(m_controlRef
);
2447 if ( textctrl
== NULL
)
2450 if ( textctrl
->MacIsReallyShown() )
2452 wxMacWindowClipper
clipper( textctrl
) ;
2453 TXNDraw( m_txn
, NULL
) ;
2457 wxInt16
wxMacMLTEClassicControl::MacControlUserPaneHitTestProc(wxInt16 x
, wxInt16 y
)
2459 Point where
= { y
, x
} ;
2460 ControlPartCode result
= kControlNoPart
;
2462 wxTextCtrl
* textctrl
= (wxTextCtrl
*) GetControlReference(m_controlRef
);
2463 if ( (textctrl
!= NULL
) && textctrl
->MacIsReallyShown() )
2465 if (PtInRect( where
, &m_txnControlBounds
))
2467 result
= kControlEditTextPart
;
2471 // sometimes we get the coords also in control local coordinates, therefore test again
2472 if ( textctrl
->MacGetTopLevelWindow()->MacUsesCompositing() )
2475 textctrl
->MacClientToRootWindow( &x
, &y
) ;
2480 if (PtInRect(where
, &m_txnControlBounds
))
2481 result
= kControlEditTextPart
;
2488 wxInt16
wxMacMLTEClassicControl::MacControlUserPaneTrackingProc( wxInt16 x
, wxInt16 y
, void* actionProc
)
2490 ControlPartCode result
= kControlNoPart
;
2492 wxTextCtrl
* textctrl
= (wxTextCtrl
*) GetControlReference(m_controlRef
);
2493 if ( (textctrl
!= NULL
) && textctrl
->MacIsReallyShown() )
2495 Point startPt
= { y
, x
} ;
2496 // for compositing, we must convert these into toplevel window coordinates, because hittesting expects them
2497 if ( textctrl
->MacGetTopLevelWindow()->MacUsesCompositing() )
2500 textctrl
->MacClientToRootWindow( &x
, &y
) ;
2505 switch (MacControlUserPaneHitTestProc( startPt
.h
, startPt
.v
))
2507 case kControlEditTextPart
:
2509 wxMacWindowClipper
clipper( textctrl
) ;
2512 ConvertEventRefToEventRecord( (EventRef
) wxTheApp
->MacGetCurrentEvent() , &rec
) ;
2513 TXNClick( m_txn
, &rec
);
2525 void wxMacMLTEClassicControl::MacControlUserPaneIdleProc()
2527 wxTextCtrl
* textctrl
= (wxTextCtrl
*) GetControlReference(m_controlRef
);
2528 if ( textctrl
== NULL
)
2531 if (textctrl
->MacIsReallyShown())
2533 if (IsControlActive(m_controlRef
))
2537 wxMacWindowClipper
clipper( textctrl
) ;
2542 if (PtInRect(mousep
, &m_txnControlBounds
))
2544 RgnHandle theRgn
= NewRgn();
2545 RectRgn(theRgn
, &m_txnControlBounds
);
2546 TXNAdjustCursor(m_txn
, theRgn
);
2553 wxInt16
wxMacMLTEClassicControl::MacControlUserPaneKeyDownProc (wxInt16 keyCode
, wxInt16 charCode
, wxInt16 modifiers
)
2555 wxTextCtrl
* textctrl
= (wxTextCtrl
*) GetControlReference(m_controlRef
);
2556 if ( textctrl
== NULL
)
2557 return kControlNoPart
;
2559 wxMacWindowClipper
clipper( textctrl
) ;
2562 memset( &ev
, 0 , sizeof( ev
) ) ;
2564 ev
.modifiers
= modifiers
;
2565 ev
.message
= ((keyCode
<< 8) & keyCodeMask
) | (charCode
& charCodeMask
);
2566 TXNKeyDown( m_txn
, &ev
);
2568 return kControlEntireControl
;
2571 void wxMacMLTEClassicControl::MacControlUserPaneActivateProc( bool activating
)
2573 MacActivatePaneText( activating
);
2576 wxInt16
wxMacMLTEClassicControl::MacControlUserPaneFocusProc(wxInt16 action
)
2578 ControlPartCode focusResult
;
2580 focusResult
= kControlFocusNoPart
;
2581 wxTextCtrl
* textctrl
= (wxTextCtrl
*) GetControlReference(m_controlRef
);
2582 if ( textctrl
== NULL
)
2585 wxMacWindowClipper
clipper( textctrl
) ;
2587 ControlRef controlFocus
= NULL
;
2588 GetKeyboardFocus( m_txnWindow
, &controlFocus
) ;
2589 bool wasFocused
= ( controlFocus
== m_controlRef
) ;
2593 case kControlFocusPrevPart
:
2594 case kControlFocusNextPart
:
2595 MacFocusPaneText( ( !wasFocused
));
2596 focusResult
= (!wasFocused
) ? (ControlPartCode
) kControlEditTextPart
: (ControlPartCode
) kControlFocusNoPart
;
2599 case kControlFocusNoPart
:
2601 MacFocusPaneText( false );
2602 focusResult
= kControlFocusNoPart
;
2609 void wxMacMLTEClassicControl::MacControlUserPaneBackgroundProc( void *info
)
2613 wxMacMLTEClassicControl::wxMacMLTEClassicControl( wxTextCtrl
*wxPeer
,
2614 const wxString
& str
,
2616 const wxSize
& size
, long style
) : wxMacMLTEControl( wxPeer
)
2618 m_font
= wxPeer
->GetFont() ;
2619 m_windowStyle
= style
;
2620 Rect bounds
= wxMacGetBoundsForControl( wxPeer
, pos
, size
) ;
2624 featureSet
= kControlSupportsEmbedding
| kControlSupportsFocus
| kControlWantsIdle
2625 | kControlWantsActivate
| kControlHandlesTracking
// | kControlHasSpecialBackground
2626 | kControlGetsFocusOnClick
| kControlSupportsLiveFeedback
;
2628 verify_noerr( ::CreateUserPaneControl( MAC_WXHWND(wxPeer
->GetParent()->MacGetTopLevelWindowRef()), &bounds
, featureSet
, &m_controlRef
) );
2632 AdjustCreationAttributes( *wxWHITE
, true ) ;
2634 MacSetObjectVisibility( wxPeer
->MacIsReallyShown() ) ;
2638 wxMacConvertNewlines10To13( &st
) ;
2639 wxMacWindowClipper
clipper( m_peer
) ;
2640 SetTXNData( st
, kTXNStartOffset
, kTXNEndOffset
) ;
2641 TXNSetSelection( m_txn
, 0, 0);
2645 wxMacMLTEClassicControl::~wxMacMLTEClassicControl()
2647 TXNDeleteObject(m_txn
);
2651 void wxMacMLTEClassicControl::VisibilityChanged(bool shown
)
2653 MacSetObjectVisibility( shown
) ;
2654 wxMacControl::VisibilityChanged( shown
) ;
2657 void wxMacMLTEClassicControl::SuperChangedPosition()
2659 MacUpdatePosition() ;
2660 wxMacControl::SuperChangedPosition() ;
2663 #ifdef __WXMAC_OSX__
2665 ControlUserPaneDrawUPP gTPDrawProc
= NULL
;
2666 ControlUserPaneHitTestUPP gTPHitProc
= NULL
;
2667 ControlUserPaneTrackingUPP gTPTrackProc
= NULL
;
2668 ControlUserPaneIdleUPP gTPIdleProc
= NULL
;
2669 ControlUserPaneKeyDownUPP gTPKeyProc
= NULL
;
2670 ControlUserPaneActivateUPP gTPActivateProc
= NULL
;
2671 ControlUserPaneFocusUPP gTPFocusProc
= NULL
;
2673 static pascal void wxMacControlUserPaneDrawProc(ControlRef control
, SInt16 part
)
2675 wxTextCtrl
*textCtrl
= wxDynamicCast( wxFindControlFromMacControl(control
) , wxTextCtrl
) ;
2676 wxMacMLTEClassicControl
* win
= textCtrl
? (wxMacMLTEClassicControl
*)(textCtrl
->GetPeer()) : NULL
;
2678 win
->MacControlUserPaneDrawProc(part
) ;
2681 static pascal ControlPartCode
wxMacControlUserPaneHitTestProc(ControlRef control
, Point where
)
2683 wxTextCtrl
*textCtrl
= wxDynamicCast( wxFindControlFromMacControl(control
) , wxTextCtrl
) ;
2684 wxMacMLTEClassicControl
* win
= textCtrl
? (wxMacMLTEClassicControl
*)(textCtrl
->GetPeer()) : NULL
;
2686 return win
->MacControlUserPaneHitTestProc(where
.h
, where
.v
) ;
2688 return kControlNoPart
;
2691 static pascal ControlPartCode
wxMacControlUserPaneTrackingProc(ControlRef control
, Point startPt
, ControlActionUPP actionProc
)
2693 wxTextCtrl
*textCtrl
= wxDynamicCast( wxFindControlFromMacControl(control
) , wxTextCtrl
) ;
2694 wxMacMLTEClassicControl
* win
= textCtrl
? (wxMacMLTEClassicControl
*)(textCtrl
->GetPeer()) : NULL
;
2696 return win
->MacControlUserPaneTrackingProc( startPt
.h
, startPt
.v
, (void*) actionProc
) ;
2698 return kControlNoPart
;
2701 static pascal void wxMacControlUserPaneIdleProc(ControlRef control
)
2703 wxTextCtrl
*textCtrl
= wxDynamicCast( wxFindControlFromMacControl(control
) , wxTextCtrl
) ;
2704 wxMacMLTEClassicControl
* win
= textCtrl
? (wxMacMLTEClassicControl
*)(textCtrl
->GetPeer()) : NULL
;
2706 win
->MacControlUserPaneIdleProc() ;
2709 static pascal ControlPartCode
wxMacControlUserPaneKeyDownProc(ControlRef control
, SInt16 keyCode
, SInt16 charCode
, SInt16 modifiers
)
2711 wxTextCtrl
*textCtrl
= wxDynamicCast( wxFindControlFromMacControl(control
) , wxTextCtrl
) ;
2712 wxMacMLTEClassicControl
* win
= textCtrl
? (wxMacMLTEClassicControl
*)(textCtrl
->GetPeer()) : NULL
;
2714 return win
->MacControlUserPaneKeyDownProc(keyCode
,charCode
,modifiers
) ;
2716 return kControlNoPart
;
2719 static pascal void wxMacControlUserPaneActivateProc(ControlRef control
, Boolean activating
)
2721 wxTextCtrl
*textCtrl
= wxDynamicCast( wxFindControlFromMacControl(control
) , wxTextCtrl
) ;
2722 wxMacMLTEClassicControl
* win
= textCtrl
? (wxMacMLTEClassicControl
*)(textCtrl
->GetPeer()) : NULL
;
2724 win
->MacControlUserPaneActivateProc(activating
) ;
2727 static pascal ControlPartCode
wxMacControlUserPaneFocusProc(ControlRef control
, ControlFocusPart action
)
2729 wxTextCtrl
*textCtrl
= wxDynamicCast( wxFindControlFromMacControl(control
) , wxTextCtrl
) ;
2730 wxMacMLTEClassicControl
* win
= textCtrl
? (wxMacMLTEClassicControl
*)(textCtrl
->GetPeer()) : NULL
;
2732 return win
->MacControlUserPaneFocusProc(action
) ;
2734 return kControlNoPart
;
2738 static pascal void wxMacControlUserPaneBackgroundProc(ControlRef control
, ControlBackgroundPtr info
)
2740 wxTextCtrl
*textCtrl
= wxDynamicCast( wxFindControlFromMacControl(control
) , wxTextCtrl
) ;
2741 wxMacMLTEClassicControl
* win
= textCtrl
? (wxMacMLTEClassicControl
*)(textCtrl
->GetPeer()) : NULL
;
2743 win
->MacControlUserPaneBackgroundProc(info
) ;
2747 #endif // __WXMAC_OSX__
2749 // TXNRegisterScrollInfoProc
2751 OSStatus
wxMacMLTEClassicControl::DoCreate()
2755 OSStatus err
= noErr
;
2757 // set up our globals
2758 #ifdef __WXMAC_OSX__
2759 if (gTPDrawProc
== NULL
) gTPDrawProc
= NewControlUserPaneDrawUPP(wxMacControlUserPaneDrawProc
);
2760 if (gTPHitProc
== NULL
) gTPHitProc
= NewControlUserPaneHitTestUPP(wxMacControlUserPaneHitTestProc
);
2761 if (gTPTrackProc
== NULL
) gTPTrackProc
= NewControlUserPaneTrackingUPP(wxMacControlUserPaneTrackingProc
);
2762 if (gTPIdleProc
== NULL
) gTPIdleProc
= NewControlUserPaneIdleUPP(wxMacControlUserPaneIdleProc
);
2763 if (gTPKeyProc
== NULL
) gTPKeyProc
= NewControlUserPaneKeyDownUPP(wxMacControlUserPaneKeyDownProc
);
2764 if (gTPActivateProc
== NULL
) gTPActivateProc
= NewControlUserPaneActivateUPP(wxMacControlUserPaneActivateProc
);
2765 if (gTPFocusProc
== NULL
) gTPFocusProc
= NewControlUserPaneFocusUPP(wxMacControlUserPaneFocusProc
);
2767 if (gTXNScrollInfoProc
== NULL
) gTXNScrollInfoProc
= NewTXNScrollInfoUPP(TXNScrollInfoProc
) ;
2768 if (gTXNScrollActionProc
== NULL
) gTXNScrollActionProc
= NewControlActionUPP(TXNScrollActionProc
) ;
2771 // set the initial settings for our private data
2773 m_txnWindow
= GetControlOwner(m_controlRef
);
2774 m_txnPort
= (GrafPtr
) GetWindowPort(m_txnWindow
);
2776 #ifdef __WXMAC_OSX__
2777 // set up the user pane procedures
2778 SetControlData(m_controlRef
, kControlEntireControl
, kControlUserPaneDrawProcTag
, sizeof(gTPDrawProc
), &gTPDrawProc
);
2779 SetControlData(m_controlRef
, kControlEntireControl
, kControlUserPaneHitTestProcTag
, sizeof(gTPHitProc
), &gTPHitProc
);
2780 SetControlData(m_controlRef
, kControlEntireControl
, kControlUserPaneTrackingProcTag
, sizeof(gTPTrackProc
), &gTPTrackProc
);
2781 SetControlData(m_controlRef
, kControlEntireControl
, kControlUserPaneIdleProcTag
, sizeof(gTPIdleProc
), &gTPIdleProc
);
2782 SetControlData(m_controlRef
, kControlEntireControl
, kControlUserPaneKeyDownProcTag
, sizeof(gTPKeyProc
), &gTPKeyProc
);
2783 SetControlData(m_controlRef
, kControlEntireControl
, kControlUserPaneActivateProcTag
, sizeof(gTPActivateProc
), &gTPActivateProc
);
2784 SetControlData(m_controlRef
, kControlEntireControl
, kControlUserPaneFocusProcTag
, sizeof(gTPFocusProc
), &gTPFocusProc
);
2786 // calculate the rectangles used by the control
2787 UMAGetControlBoundsInWindowCoords(m_controlRef
, &bounds
);
2789 m_txnControlBounds
= bounds
;
2790 m_txnVisBounds
= bounds
;
2795 GetGWorld( &origPort
, &origDev
) ;
2796 SetPort( m_txnPort
);
2798 // create the new edit field
2799 TXNFrameOptions frameOptions
= FrameOptionsFromWXStyle( m_windowStyle
) ;
2801 #ifdef __WXMAC_OSX__
2802 // the scrollbars are not correctly embedded but are inserted at the root:
2803 // this gives us problems as we have erratic redraws even over the structure area
2805 m_sbHorizontal
= 0 ;
2807 m_lastHorizontalValue
= 0 ;
2808 m_lastVerticalValue
= 0 ;
2810 Rect sb
= { 0 , 0 , 0 , 0 } ;
2811 if ( frameOptions
& kTXNWantVScrollBarMask
)
2813 CreateScrollBarControl( m_txnWindow
, &sb
, 0 , 0 , 100 , 1 , true , gTXNScrollActionProc
, &m_sbVertical
) ;
2814 SetControlReference( m_sbVertical
, (SInt32
) this ) ;
2815 SetControlAction( m_sbVertical
, gTXNScrollActionProc
);
2816 ShowControl( m_sbVertical
) ;
2817 EmbedControl( m_sbVertical
, m_controlRef
) ;
2818 frameOptions
&= ~kTXNWantVScrollBarMask
;
2821 if ( frameOptions
& kTXNWantHScrollBarMask
)
2823 CreateScrollBarControl( m_txnWindow
, &sb
, 0 , 0 , 100 , 1 , true , gTXNScrollActionProc
, &m_sbHorizontal
) ;
2824 SetControlReference( m_sbHorizontal
, (SInt32
) this ) ;
2825 SetControlAction( m_sbHorizontal
, gTXNScrollActionProc
);
2826 ShowControl( m_sbHorizontal
) ;
2827 EmbedControl( m_sbHorizontal
, m_controlRef
) ;
2828 frameOptions
&= ~(kTXNWantHScrollBarMask
| kTXNDrawGrowIconMask
);
2833 verify_noerr(TXNNewObject(NULL
, m_txnWindow
, &bounds
,
2835 kTXNTextEditStyleFrameType
,
2837 kTXNSystemDefaultEncoding
,
2838 &m_txn
, &m_txnFrameID
, NULL
) );
2841 TXNControlTag iControlTags
[] = { kTXNUseCarbonEvents
};
2842 TXNControlData iControlData
[] = { {(UInt32
) &cInfo
} };
2843 int toptag
= WXSIZEOF( iControlTags
) ;
2844 TXNCarbonEventInfo cInfo
;
2845 cInfo
.useCarbonEvents
= false ;
2848 cInfo
.fDictionary
= NULL
;
2850 verify_noerr( TXNSetTXNObjectControls( m_txn
, false , toptag
, iControlTags
, iControlData
)) ;
2853 #ifdef __WXMAC_OSX__
2854 TXNRegisterScrollInfoProc( m_txn
, gTXNScrollInfoProc
, (SInt32
) this);
2857 SetGWorld( origPort
, origDev
) ;
2861 // ----------------------------------------------------------------------------
2862 // MLTE control implementation (OSX part)
2863 // ----------------------------------------------------------------------------
2865 #if TARGET_API_MAC_OSX
2867 #if MAC_OS_X_VERSION_MAX_ALLOWED > MAC_OS_X_VERSION_10_2
2869 wxMacMLTEHIViewControl::wxMacMLTEHIViewControl( wxTextCtrl
*wxPeer
,
2870 const wxString
& str
,
2872 const wxSize
& size
, long style
) : wxMacMLTEControl( wxPeer
)
2874 m_font
= wxPeer
->GetFont() ;
2875 m_windowStyle
= style
;
2876 Rect bounds
= wxMacGetBoundsForControl( wxPeer
, pos
, size
) ;
2878 wxMacConvertNewlines10To13( &st
) ;
2880 HIRect hr
= { { bounds
.left
, bounds
.top
} ,
2881 { bounds
.right
- bounds
.left
, bounds
.bottom
- bounds
.top
} } ;
2883 m_scrollView
= NULL
;
2884 TXNFrameOptions frameOptions
= FrameOptionsFromWXStyle( style
) ;
2885 if ( frameOptions
& (kTXNWantVScrollBarMask
|kTXNWantHScrollBarMask
) )
2887 HIScrollViewCreate(( frameOptions
& kTXNWantHScrollBarMask
? kHIScrollViewOptionsHorizScroll
: 0) |
2888 ( frameOptions
& kTXNWantVScrollBarMask
? kHIScrollViewOptionsVertScroll
: 0 ) , &m_scrollView
) ;
2890 HIViewSetFrame( m_scrollView
, &hr
);
2891 HIViewSetVisible( m_scrollView
, true );
2895 HITextViewCreate( NULL
, 0, frameOptions
, &m_textView
) ;
2896 m_txn
= HITextViewGetTXNObject( m_textView
) ;
2897 HIViewSetVisible( m_textView
, true ) ;
2900 HIViewAddSubview( m_scrollView
, m_textView
) ;
2901 m_controlRef
= m_scrollView
;
2902 wxPeer
->MacInstallEventHandler( (WXWidget
) m_textView
) ;
2906 HIViewSetFrame( m_textView
, &hr
);
2907 m_controlRef
= m_textView
;
2910 AdjustCreationAttributes( *wxWHITE
, true ) ;
2912 wxMacWindowClipper
c( m_peer
) ;
2913 SetTXNData( st
, kTXNStartOffset
, kTXNEndOffset
) ;
2915 TXNSetSelection( m_txn
, 0, 0 );
2916 TXNShowSelection( m_txn
, kTXNShowStart
);
2919 OSStatus
wxMacMLTEHIViewControl::SetFocus( ControlFocusPart focusPart
)
2921 return SetKeyboardFocus( GetControlOwner( m_textView
), m_textView
, focusPart
) ;
2924 bool wxMacMLTEHIViewControl::HasFocus() const
2926 ControlRef control
;
2927 GetKeyboardFocus( GetUserFocusWindow() , &control
) ;
2928 return control
== m_textView
;
2931 void wxMacMLTEHIViewControl::SetBackground( const wxBrush
&brush
)
2933 wxMacMLTEControl::SetBackground( brush
) ;
2936 CGColorSpaceRef rgbSpace
= CGColorSpaceCreateDeviceRGB();
2937 RGBColor col
= MAC_WXCOLORREF(brush
.GetColour().GetPixel()) ;
2939 float component
[4] ;
2940 component
[0] = col
.red
/ 65536.0 ;
2941 component
[1] = col
.green
/ 65536.0 ;
2942 component
[2] = col
.blue
/ 65536.0 ;
2943 component
[3] = 1.0 ; // alpha
2945 CGColorRef color
= CGColorCreate (rgbSpace
, component
);
2946 HITextViewSetBackgroundColor( m_textView
, color
) ;
2947 CGColorSpaceRelease( rgbSpace
);
2951 #endif // MAC_OS_X_VERSION_MAX_ALLOWED > MAC_OS_X_VERSION_10_2
2956 #endif // wxUSE_TEXTCTRL