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__)
56 // if this is set to 1 then under OSX 10.2 the 'classic' MLTE implementation will be used
57 // if set to 0 then the unicode textctrl will be used
58 #ifndef wxMAC_AWAYS_USE_MLTE
59 #define wxMAC_AWAYS_USE_MLTE 1
65 kTXNVisibilityTag
= 'visb' /*set the visibility state of the object */
70 #include <MacTextEditor.h>
71 #include <ATSUnicode.h>
72 #include <TextCommon.h>
73 #include <TextEncodingConverter.h>
75 #include "wx/mac/uma.h"
81 virtual ~wxMacFunctor() {}
82 virtual void* operator()() = 0 ;
83 static void* CallBackProc(void *param
)
85 wxMacFunctor
* f
= (wxMacFunctor
*) param
;
86 void *result
= (*f
)() ;
91 template<typename classtype
,typename param1type
>
92 class wxMacObjectFunctor1
: public wxMacFunctor
94 typedef void (classtype::*function
)( param1type p1
) ;
95 typedef void (classtype::*ref_function
)( const param1type
& p1
) ;
97 wxMacObjectFunctor1( classtype
*obj
, function f
, param1type p1
) :
105 wxMacObjectFunctor1( classtype
*obj
, ref_function f
, param1type p1
) :
113 ~wxMacObjectFunctor1() {}
115 virtual void* operator()()
117 (m_object
->*m_function
)(m_param1
) ;
121 classtype
* m_object
;
122 param1type m_param1
;
125 function m_function
;
126 ref_function m_refFunction
;
130 template<typename classtype
, typename param1type
>
131 void* wxMacMPRemoteCall( classtype
*object
, void (classtype::*function
)( param1type p1
) , param1type p1
)
133 wxMacObjectFunctor1
<classtype
,param1type
> params(object
,function
,p1
) ;
135 MPRemoteCall( wxMacFunctor::CallBackProc
, ¶ms
, kMPOwningProcessRemoteContext
) ;
139 template<typename classtype
, typename param1type
>
140 void* wxMacMPRemoteCall( classtype
*object
, void (classtype::*function
)( const param1type
& p1
) , param1type p1
)
142 wxMacObjectFunctor1
<classtype
,param1type
> params(object
,function
,p1
) ;
144 MPRemoteCall( wxMacFunctor::CallBackProc
, ¶ms
, kMPOwningProcessRemoteContext
) ;
148 template<typename classtype
, typename param1type
>
149 void* wxMacMPRemoteGUICall( classtype
*object
, void (classtype::*function
)( param1type p1
) , param1type p1
)
152 void *result
= wxMacMPRemoteCall( object
, function
, p1
) ;
157 template<typename classtype
, typename param1type
>
158 void* wxMacMPRemoteGUICall( classtype
*object
, void (classtype::*function
)( const param1type
& p1
) , param1type p1
)
161 void *result
= wxMacMPRemoteCall( object
, function
, p1
) ;
165 // common interface for all implementations
166 class wxMacTextControl
: public wxMacControl
169 wxMacTextControl( wxTextCtrl
*peer
) ;
170 ~wxMacTextControl() ;
172 virtual wxString
GetStringValue() const = 0 ;
173 virtual void SetStringValue( const wxString
&val
) = 0 ;
174 virtual void SetStyle(long start
, long end
, const wxTextAttr
& style
) ;
175 virtual void Copy() ;
177 virtual void Paste() ;
178 virtual bool CanPaste() const ;
179 virtual void SetEditable(bool editable
) ;
180 virtual wxTextPos
GetLastPosition() const ;
181 virtual void Replace( long from
, long to
, const wxString
&str
) ;
182 virtual void Remove( long from
, long to
) ;
183 virtual void SetSelection( long from
, long to
) = 0 ;
184 virtual void GetSelection( long* from
, long* to
) const = 0 ;
185 virtual void WriteText(const wxString
& str
) = 0 ;
186 virtual bool HasOwnContextMenu() const { return false ; }
188 virtual void Clear() ;
189 virtual bool CanUndo() const;
190 virtual void Undo() ;
191 virtual bool CanRedo() const;
192 virtual void Redo() ;
193 virtual int GetNumberOfLines() const ;
194 virtual long XYToPosition(long x
, long y
) const;
195 virtual bool PositionToXY(long pos
, long *x
, long *y
) const ;
196 virtual void ShowPosition( long WXUNUSED(pos
) ) ;
197 virtual int GetLineLength(long lineNo
) const ;
198 virtual wxString
GetLineText(long lineNo
) const ;
199 virtual bool SetupCursor( const wxPoint
& pt
) { return false ; }
201 #ifndef __WXMAC_OSX__
202 virtual void MacControlUserPaneDrawProc(wxInt16 part
) = 0 ;
203 virtual wxInt16
MacControlUserPaneHitTestProc(wxInt16 x
, wxInt16 y
) = 0 ;
204 virtual wxInt16
MacControlUserPaneTrackingProc(wxInt16 x
, wxInt16 y
, void* actionProc
) = 0 ;
205 virtual void MacControlUserPaneIdleProc() = 0 ;
206 virtual wxInt16
MacControlUserPaneKeyDownProc(wxInt16 keyCode
, wxInt16 charCode
, wxInt16 modifiers
) = 0 ;
207 virtual void MacControlUserPaneActivateProc(bool activating
) = 0 ;
208 virtual wxInt16
MacControlUserPaneFocusProc(wxInt16 action
) = 0 ;
209 virtual void MacControlUserPaneBackgroundProc(void* info
) = 0 ;
213 // common parts for implementations based on MLTE
215 class wxMacMLTEControl
: public wxMacTextControl
218 wxMacMLTEControl( wxTextCtrl
*peer
) ;
219 virtual wxString
GetStringValue() const ;
220 virtual void SetStringValue( const wxString
&str
) ;
222 static TXNFrameOptions
FrameOptionsFromWXStyle( long wxStyle
) ;
223 void AdjustCreationAttributes( const wxColour
& background
, bool visible
) ;
225 virtual void SetFont( const wxFont
& font
, const wxColour
& foreground
, long windowStyle
) ;
226 virtual void SetBackground( const wxBrush
&brush
) ;
227 virtual void SetStyle(long start
, long end
, const wxTextAttr
& style
) ;
228 virtual void Copy() ;
230 virtual void Paste() ;
231 virtual bool CanPaste() const ;
232 virtual void SetEditable(bool editable
) ;
233 virtual wxTextPos
GetLastPosition() const ;
234 virtual void Replace( long from
, long to
, const wxString
&str
) ;
235 virtual void Remove( long from
, long to
) ;
236 virtual void GetSelection( long* from
, long* to
) const ;
237 virtual void SetSelection( long from
, long to
) ;
239 virtual void WriteText(const wxString
& str
) ;
240 virtual bool HasOwnContextMenu() const
242 #if MAC_OS_X_VERSION_MAX_ALLOWED >= MAC_OS_X_VERSION_10_4
243 if ( UMAGetSystemVersion() >= 0x1040 )
245 TXNCommandEventSupportOptions options
;
246 TXNGetCommandEventSupport( m_txn
, & options
) ;
247 return options
& kTXNSupportEditCommandProcessing
;
253 virtual void Clear() ;
255 virtual bool CanUndo() const ;
256 virtual void Undo() ;
257 virtual bool CanRedo() const;
258 virtual void Redo() ;
259 virtual int GetNumberOfLines() const ;
260 virtual long XYToPosition(long x
, long y
) const ;
261 virtual bool PositionToXY(long pos
, long *x
, long *y
) const ;
262 virtual void ShowPosition( long pos
) ;
263 virtual int GetLineLength(long lineNo
) const ;
264 virtual wxString
GetLineText(long lineNo
) const ;
266 void SetTXNData( const wxString
& st
, TXNOffset start
, TXNOffset end
) ;
269 void TXNSetAttribute( const wxTextAttr
& style
, long from
, long to
) ;
273 #if TARGET_API_MAC_OSX
275 // implementation available under OSX
277 #if MAC_OS_X_VERSION_MAX_ALLOWED > MAC_OS_X_VERSION_10_2
279 class wxMacMLTEHIViewControl
: public wxMacMLTEControl
282 wxMacMLTEHIViewControl( wxTextCtrl
*wxPeer
,
285 const wxSize
& size
, long style
) ;
286 virtual OSStatus
SetFocus( ControlFocusPart focusPart
) ;
287 virtual bool HasFocus() const ;
288 virtual void SetBackground( const wxBrush
&brush
) ;
290 HIViewRef m_scrollView
;
291 HIViewRef m_textView
;
296 class wxMacUnicodeTextControl
: public wxMacTextControl
299 wxMacUnicodeTextControl( wxTextCtrl
*wxPeer
,
302 const wxSize
& size
, long style
) ;
303 ~wxMacUnicodeTextControl();
304 virtual void VisibilityChanged(bool shown
);
305 virtual wxString
GetStringValue() const ;
306 virtual void SetStringValue( const wxString
&str
) ;
309 virtual void Paste();
310 virtual bool CanPaste() const;
311 virtual void SetEditable(bool editable
) ;
312 virtual void GetSelection( long* from
, long* to
) const ;
313 virtual void SetSelection( long from
, long to
) ;
314 virtual void WriteText(const wxString
& str
) ;
316 // contains the tag for the content (is different for password and non-password controls)
322 // 'classic' MLTE implementation
324 class wxMacMLTEClassicControl
: public wxMacMLTEControl
327 wxMacMLTEClassicControl( wxTextCtrl
*wxPeer
,
330 const wxSize
& size
, long style
) ;
331 ~wxMacMLTEClassicControl() ;
332 virtual void VisibilityChanged(bool shown
) ;
333 virtual void SuperChangedPosition() ;
335 virtual void MacControlUserPaneDrawProc(wxInt16 part
) ;
336 virtual wxInt16
MacControlUserPaneHitTestProc(wxInt16 x
, wxInt16 y
) ;
337 virtual wxInt16
MacControlUserPaneTrackingProc(wxInt16 x
, wxInt16 y
, void* actionProc
) ;
338 virtual void MacControlUserPaneIdleProc() ;
339 virtual wxInt16
MacControlUserPaneKeyDownProc(wxInt16 keyCode
, wxInt16 charCode
, wxInt16 modifiers
) ;
340 virtual void MacControlUserPaneActivateProc(bool activating
) ;
341 virtual wxInt16
MacControlUserPaneFocusProc(wxInt16 action
) ;
342 virtual void MacControlUserPaneBackgroundProc(void* info
) ;
344 virtual bool SetupCursor( const wxPoint
& WXUNUSED(pt
) ) { MacControlUserPaneIdleProc() ; return true ;}
346 virtual void SetRect( Rect
*r
) ;
351 void MacUpdatePosition() ;
352 void MacActivatePaneText(Boolean setActive
) ;
353 void MacFocusPaneText(Boolean setFocus
) ;
355 void MacSetObjectVisibility(Boolean vis
) ;
357 TXNFrameID m_txnFrameID
;
359 WindowRef m_txnWindow
;
360 // bounds of the control as we last did set the txn frames
361 Rect m_txnControlBounds
;
362 Rect m_txnVisBounds
;
364 static pascal void TXNScrollInfoProc (SInt32 iValue
, SInt32 iMaximumValue
,
365 TXNScrollBarOrientation iScrollBarOrientation
, SInt32 iRefCon
) ;
366 static pascal void TXNScrollActionProc( ControlRef controlRef
, ControlPartCode partCode
) ;
367 ControlRef m_sbHorizontal
;
368 SInt32 m_lastHorizontalValue
;
369 ControlRef m_sbVertical
;
370 SInt32 m_lastVerticalValue
;
374 #define TE_UNLIMITED_LENGTH 0xFFFFFFFFUL
376 IMPLEMENT_DYNAMIC_CLASS(wxTextCtrl
, wxControl
)
378 BEGIN_EVENT_TABLE(wxTextCtrl
, wxControl
)
379 EVT_ERASE_BACKGROUND( wxTextCtrl::OnEraseBackground
)
380 EVT_DROP_FILES(wxTextCtrl::OnDropFiles
)
381 EVT_CHAR(wxTextCtrl::OnChar
)
382 EVT_MENU(wxID_CUT
, wxTextCtrl::OnCut
)
383 EVT_MENU(wxID_COPY
, wxTextCtrl::OnCopy
)
384 EVT_MENU(wxID_PASTE
, wxTextCtrl::OnPaste
)
385 EVT_MENU(wxID_UNDO
, wxTextCtrl::OnUndo
)
386 EVT_MENU(wxID_REDO
, wxTextCtrl::OnRedo
)
387 EVT_MENU(wxID_CLEAR
, wxTextCtrl::OnDelete
)
388 EVT_MENU(wxID_SELECTALL
, wxTextCtrl::OnSelectAll
)
390 EVT_CONTEXT_MENU(wxTextCtrl::OnContextMenu
)
392 EVT_UPDATE_UI(wxID_CUT
, wxTextCtrl::OnUpdateCut
)
393 EVT_UPDATE_UI(wxID_COPY
, wxTextCtrl::OnUpdateCopy
)
394 EVT_UPDATE_UI(wxID_PASTE
, wxTextCtrl::OnUpdatePaste
)
395 EVT_UPDATE_UI(wxID_UNDO
, wxTextCtrl::OnUpdateUndo
)
396 EVT_UPDATE_UI(wxID_REDO
, wxTextCtrl::OnUpdateRedo
)
397 EVT_UPDATE_UI(wxID_CLEAR
, wxTextCtrl::OnUpdateDelete
)
398 EVT_UPDATE_UI(wxID_SELECTALL
, wxTextCtrl::OnUpdateSelectAll
)
402 void wxTextCtrl::Init()
407 m_privateContextMenu
= NULL
;
409 m_maxLength
= TE_UNLIMITED_LENGTH
;
412 wxTextCtrl::~wxTextCtrl()
414 delete m_privateContextMenu
;
418 bool wxTextCtrl::Create(wxWindow
*parent
, wxWindowID id
,
421 const wxSize
& size
, long style
,
422 const wxValidator
& validator
,
423 const wxString
& name
)
425 m_macIsUserPane
= false ;
428 if ( ! ( style
& wxNO_BORDER
) )
429 style
= ( style
& ~wxBORDER_MASK
) | wxSUNKEN_BORDER
;
431 if ( !wxTextCtrlBase::Create(parent
, id
, pos
, size
, style
& ~(wxHSCROLL
|wxVSCROLL
), validator
, name
) )
434 if ( m_windowStyle
& wxTE_MULTILINE
)
436 wxASSERT_MSG( !(m_windowStyle
& wxTE_PROCESS_ENTER
),
437 wxT("wxTE_PROCESS_ENTER style is ignored for multiline text controls (they always process it)") );
439 m_windowStyle
|= wxTE_PROCESS_ENTER
;
440 style
|= wxTE_PROCESS_ENTER
;
443 bool forceMLTE
= false ;
444 #if wxUSE_SYSTEM_OPTIONS
445 if ( (wxSystemOptions::HasOption(wxMAC_TEXTCONTROL_USE_MLTE
) ) && ( wxSystemOptions::GetOptionInt( wxMAC_TEXTCONTROL_USE_MLTE
) == 1) )
452 #if MAC_OS_X_VERSION_MAX_ALLOWED > MAC_OS_X_VERSION_10_2
453 if ( UMAGetSystemVersion() >= 0x1030 && forceMLTE
== false )
455 if ( m_windowStyle
& wxTE_MULTILINE
)
456 m_peer
= new wxMacMLTEHIViewControl( this , str
, pos
, size
, style
) ;
461 if ( !(m_windowStyle
& wxTE_MULTILINE
) && forceMLTE
== false )
462 m_peer
= new wxMacUnicodeTextControl( this , str
, pos
, size
, style
) ;
467 m_peer
= new wxMacMLTEClassicControl( this , str
, pos
, size
, style
) ;
470 MacPostControlCreate(pos
,size
) ;
472 // only now the embedding is correct and we can do a positioning update
474 MacSuperChangedPosition() ;
476 if ( m_windowStyle
& wxTE_READONLY
)
478 SetEditable( false ) ;
481 SetCursor( wxCursor( wxCURSOR_IBEAM
) ) ;
486 void wxTextCtrl::MacSuperChangedPosition()
488 wxWindow::MacSuperChangedPosition() ;
489 GetPeer()->SuperChangedPosition() ;
492 void wxTextCtrl::MacVisibilityChanged()
494 GetPeer()->VisibilityChanged( MacIsReallyShown() ) ;
497 void wxTextCtrl::MacEnabledStateChanged()
501 wxString
wxTextCtrl::GetValue() const
503 return GetPeer()->GetStringValue() ;
506 void wxTextCtrl::GetSelection(long* from
, long* to
) const
508 GetPeer()->GetSelection( from
, to
) ;
511 void wxTextCtrl::SetValue(const wxString
& str
)
514 if ( GetValue() == str
)
517 GetPeer()->SetStringValue(str
) ;
519 wxCommandEvent
event(wxEVT_COMMAND_TEXT_UPDATED
, m_windowId
);
520 event
.SetString( GetValue() ) ;
521 event
.SetEventObject( this );
522 GetEventHandler()->ProcessEvent(event
);
525 void wxTextCtrl::SetMaxLength(unsigned long len
)
530 bool wxTextCtrl::SetFont( const wxFont
& font
)
532 if ( !wxTextCtrlBase::SetFont( font
) )
535 GetPeer()->SetFont( font
, GetForegroundColour() , GetWindowStyle() ) ;
539 bool wxTextCtrl::SetStyle(long start
, long end
, const wxTextAttr
& style
)
541 GetPeer()->SetStyle( start
, end
, style
) ;
545 bool wxTextCtrl::SetDefaultStyle(const wxTextAttr
& style
)
547 wxTextCtrlBase::SetDefaultStyle( style
) ;
548 SetStyle( kTXNUseCurrentSelection
, kTXNUseCurrentSelection
, GetDefaultStyle() ) ;
552 // Clipboard operations
553 void wxTextCtrl::Copy()
561 void wxTextCtrl::Cut()
567 wxCommandEvent
event(wxEVT_COMMAND_TEXT_UPDATED
, m_windowId
);
568 event
.SetEventObject( this );
569 GetEventHandler()->ProcessEvent(event
);
573 void wxTextCtrl::Paste()
578 // eventually we should add setting the default style again
580 wxCommandEvent
event(wxEVT_COMMAND_TEXT_UPDATED
, m_windowId
);
581 event
.SetEventObject( this );
582 GetEventHandler()->ProcessEvent(event
);
586 bool wxTextCtrl::CanCopy() const
588 // Can copy if there's a selection
590 GetSelection(& from
, & to
);
594 bool wxTextCtrl::CanCut() const
600 // Can cut if there's a selection
602 GetSelection(& from
, & to
);
606 bool wxTextCtrl::CanPaste() const
611 return GetPeer()->CanPaste() ;
614 void wxTextCtrl::SetEditable(bool editable
)
616 if ( editable
!= m_editable
)
618 m_editable
= editable
;
619 GetPeer()->SetEditable( editable
) ;
623 void wxTextCtrl::SetInsertionPoint(long pos
)
625 SetSelection( pos
, pos
) ;
628 void wxTextCtrl::SetInsertionPointEnd()
630 wxTextPos pos
= GetLastPosition();
631 SetInsertionPoint(pos
);
634 long wxTextCtrl::GetInsertionPoint() const
637 GetSelection( &begin
, &end
) ;
641 wxTextPos
wxTextCtrl::GetLastPosition() const
643 return GetPeer()->GetLastPosition( ) ;
646 void wxTextCtrl::Replace(long from
, long to
, const wxString
& str
)
648 GetPeer()->Replace( from
, to
, str
) ;
651 void wxTextCtrl::Remove(long from
, long to
)
653 GetPeer()->Remove( from
, to
) ;
656 void wxTextCtrl::SetSelection(long from
, long to
)
658 GetPeer()->SetSelection( from
, to
) ;
661 bool wxTextCtrl::LoadFile(const wxString
& file
)
663 if ( wxTextCtrlBase::LoadFile(file
) )
671 void wxTextCtrl::WriteText(const wxString
& str
)
673 // TODO this MPRemoting will be moved into a remoting peer proxy for any command
674 if ( !wxIsMainThread() )
676 // unfortunately CW 8 is not able to correctly deduce the template types, so we have
677 // to instantiate explicitly
678 wxMacMPRemoteGUICall
<wxTextCtrl
,wxString
>( this , &wxTextCtrl::WriteText
, str
) ;
683 GetPeer()->WriteText( str
) ;
687 void wxTextCtrl::AppendText(const wxString
& text
)
689 SetInsertionPointEnd();
693 void wxTextCtrl::Clear()
698 bool wxTextCtrl::IsModified() const
703 bool wxTextCtrl::IsEditable() const
705 return IsEnabled() && m_editable
;
708 bool wxTextCtrl::AcceptsFocus() const
710 // we don't want focus if we can't be edited
711 return /*IsEditable() && */ wxControl::AcceptsFocus();
714 wxSize
wxTextCtrl::DoGetBestSize() const
720 // these are the numbers from the HIG, we reduce them by the borders
723 switch( m_windowVariant
)
725 case wxWINDOW_VARIANT_NORMAL
:
728 case wxWINDOW_VARIANT_SMALL
:
731 case wxWINDOW_VARIANT_MINI
:
739 // as the above numbers have some free space around the text
740 // we get 5 lines like this anyway
741 if ( m_windowStyle
& wxTE_MULTILINE
)
746 if ( !HasFlag(wxNO_BORDER
) )
749 return wxSize(wText
, hText
);
752 // ----------------------------------------------------------------------------
754 // ----------------------------------------------------------------------------
756 void wxTextCtrl::Undo()
764 void wxTextCtrl::Redo()
772 bool wxTextCtrl::CanUndo() const
778 return GetPeer()->CanUndo() ;
781 bool wxTextCtrl::CanRedo() const
787 return GetPeer()->CanRedo() ;
790 void wxTextCtrl::MarkDirty()
795 void wxTextCtrl::DiscardEdits()
800 int wxTextCtrl::GetNumberOfLines() const
802 return GetPeer()->GetNumberOfLines() ;
805 long wxTextCtrl::XYToPosition(long x
, long y
) const
807 return GetPeer()->XYToPosition( x
, y
) ;
810 bool wxTextCtrl::PositionToXY(long pos
, long *x
, long *y
) const
812 return GetPeer()->PositionToXY(pos
, x
, y
) ;
815 void wxTextCtrl::ShowPosition(long pos
)
817 return GetPeer()->ShowPosition(pos
) ;
820 int wxTextCtrl::GetLineLength(long lineNo
) const
822 return GetPeer()->GetLineLength(lineNo
) ;
825 wxString
wxTextCtrl::GetLineText(long lineNo
) const
827 return GetPeer()->GetLineText(lineNo
) ;
834 void wxTextCtrl::Command(wxCommandEvent
& event
)
836 SetValue (event
.GetString());
837 ProcessCommand (event
);
840 void wxTextCtrl::OnDropFiles(wxDropFilesEvent
& event
)
842 // By default, load the first file into the text window.
843 if (event
.GetNumberOfFiles() > 0)
845 LoadFile(event
.GetFiles()[0]);
849 void wxTextCtrl::OnEraseBackground(wxEraseEvent
& event
)
851 // all erasing should be done by the real mac control implementation
852 // while this is true for MLTE under classic, the HITextView is somehow
853 // transparent but background erase is not working correctly, so intercept
854 // things while we can...
858 void wxTextCtrl::OnChar(wxKeyEvent
& event
)
860 int key
= event
.GetKeyCode() ;
861 bool eat_key
= false ;
863 if ( key
== 'c' && event
.MetaDown() )
870 if ( !IsEditable() && key
!= WXK_LEFT
&& key
!= WXK_RIGHT
&& key
!= WXK_DOWN
&& key
!= WXK_UP
&& key
!= WXK_TAB
&&
871 !( key
== WXK_RETURN
&& ( (m_windowStyle
& wxPROCESS_ENTER
) || (m_windowStyle
& wxTE_MULTILINE
) ) )
872 /* && key != WXK_PRIOR && key != WXK_NEXT && key != WXK_HOME && key != WXK_END */
879 // Check if we have reached the max # of chars, but still allow navigation and deletion
880 if ( !IsMultiLine() && GetValue().Length() >= m_maxLength
&&
881 key
!= WXK_LEFT
&& key
!= WXK_RIGHT
&& key
!= WXK_TAB
&&
882 key
!= WXK_BACK
&& !( key
== WXK_RETURN
&& (m_windowStyle
& wxPROCESS_ENTER
) )
885 // eat it, we don't want to add more than allowed # of characters
889 // assume that any key not processed yet is going to modify the control
892 if ( key
== 'v' && event
.MetaDown() )
898 if ( key
== 'x' && event
.MetaDown() )
907 if (m_windowStyle
& wxPROCESS_ENTER
)
909 wxCommandEvent
event(wxEVT_COMMAND_TEXT_ENTER
, m_windowId
);
910 event
.SetEventObject( this );
911 event
.SetString( GetValue() );
912 if ( GetEventHandler()->ProcessEvent(event
) )
915 if ( !(m_windowStyle
& wxTE_MULTILINE
) )
917 wxWindow
*parent
= GetParent();
918 while( parent
&& !parent
->IsTopLevel() && parent
->GetDefaultItem() == NULL
) {
919 parent
= parent
->GetParent() ;
921 if ( parent
&& parent
->GetDefaultItem() )
923 wxButton
*def
= wxDynamicCast(parent
->GetDefaultItem(),
925 if ( def
&& def
->IsEnabled() )
927 wxCommandEvent
event(wxEVT_COMMAND_BUTTON_CLICKED
, def
->GetId() );
928 event
.SetEventObject(def
);
934 // this will make wxWidgets eat the ENTER key so that
935 // we actually prevent line wrapping in a single line
943 if ( !(m_windowStyle
& wxTE_PROCESS_TAB
))
946 if (!event
.ShiftDown())
947 flags
|= wxNavigationKeyEvent::IsForward
;
948 if (event
.ControlDown())
949 flags
|= wxNavigationKeyEvent::WinChange
;
955 // This is necessary (don't know why) or the tab will not
957 WriteText(wxT("\t"));
965 // perform keystroke handling
966 if ( wxTheApp
->MacGetCurrentEvent() != NULL
&& wxTheApp
->MacGetCurrentEventHandlerCallRef() != NULL
)
967 CallNextEventHandler((EventHandlerCallRef
)wxTheApp
->MacGetCurrentEventHandlerCallRef() , (EventRef
) wxTheApp
->MacGetCurrentEvent() ) ;
971 if ( wxMacConvertEventToRecord( (EventRef
) wxTheApp
->MacGetCurrentEvent() , &rec
) )
973 EventRecord
*ev
= &rec
;
976 keychar
= short(ev
->message
& charCodeMask
);
977 keycode
= short(ev
->message
& keyCodeMask
) >> 8 ;
979 m_peer
->HandleKey( keycode
, keychar
, ev
->modifiers
) ;
983 if ( ( key
>= 0x20 && key
< WXK_START
) ||
988 wxCommandEvent
event1(wxEVT_COMMAND_TEXT_UPDATED
, m_windowId
);
989 event1
.SetEventObject( this );
990 wxPostEvent(GetEventHandler(),event1
);
994 // ----------------------------------------------------------------------------
995 // standard handlers for standard edit menu events
996 // ----------------------------------------------------------------------------
998 void wxTextCtrl::OnCut(wxCommandEvent
& WXUNUSED(event
))
1003 void wxTextCtrl::OnCopy(wxCommandEvent
& WXUNUSED(event
))
1008 void wxTextCtrl::OnPaste(wxCommandEvent
& WXUNUSED(event
))
1013 void wxTextCtrl::OnUndo(wxCommandEvent
& WXUNUSED(event
))
1018 void wxTextCtrl::OnRedo(wxCommandEvent
& WXUNUSED(event
))
1023 void wxTextCtrl::OnDelete(wxCommandEvent
& WXUNUSED(event
))
1026 GetSelection(& from
, & to
);
1027 if (from
!= -1 && to
!= -1)
1031 void wxTextCtrl::OnSelectAll(wxCommandEvent
& WXUNUSED(event
))
1033 SetSelection(-1, -1);
1036 void wxTextCtrl::OnUpdateCut(wxUpdateUIEvent
& event
)
1038 event
.Enable( CanCut() );
1041 void wxTextCtrl::OnUpdateCopy(wxUpdateUIEvent
& event
)
1043 event
.Enable( CanCopy() );
1046 void wxTextCtrl::OnUpdatePaste(wxUpdateUIEvent
& event
)
1048 event
.Enable( CanPaste() );
1051 void wxTextCtrl::OnUpdateUndo(wxUpdateUIEvent
& event
)
1053 event
.Enable( CanUndo() );
1056 void wxTextCtrl::OnUpdateRedo(wxUpdateUIEvent
& event
)
1058 event
.Enable( CanRedo() );
1061 void wxTextCtrl::OnUpdateDelete(wxUpdateUIEvent
& event
)
1064 GetSelection(& from
, & to
);
1065 event
.Enable(from
!= -1 && to
!= -1 && from
!= to
&& IsEditable()) ;
1068 void wxTextCtrl::OnUpdateSelectAll(wxUpdateUIEvent
& event
)
1070 event
.Enable(GetLastPosition() > 0);
1073 // CS: Context Menus only work with mlte implementations or non-multiline HIViews at the moment
1075 void wxTextCtrl::OnContextMenu(wxContextMenuEvent
& event
)
1077 if ( GetPeer()->HasOwnContextMenu() )
1083 if (m_privateContextMenu
== NULL
)
1085 m_privateContextMenu
= new wxMenu
;
1086 m_privateContextMenu
->Append(wxID_UNDO
, _("&Undo"));
1087 m_privateContextMenu
->Append(wxID_REDO
, _("&Redo"));
1088 m_privateContextMenu
->AppendSeparator();
1089 m_privateContextMenu
->Append(wxID_CUT
, _("Cu&t"));
1090 m_privateContextMenu
->Append(wxID_COPY
, _("&Copy"));
1091 m_privateContextMenu
->Append(wxID_PASTE
, _("&Paste"));
1092 m_privateContextMenu
->Append(wxID_CLEAR
, _("&Delete"));
1093 m_privateContextMenu
->AppendSeparator();
1094 m_privateContextMenu
->Append(wxID_SELECTALL
, _("Select &All"));
1097 if (m_privateContextMenu
!= NULL
)
1098 PopupMenu(m_privateContextMenu
);
1101 bool wxTextCtrl::MacSetupCursor( const wxPoint
& pt
)
1103 if ( !GetPeer()->SetupCursor(pt
) )
1104 return wxWindow::MacSetupCursor( pt
) ;
1108 #if !TARGET_API_MAC_OSX
1110 // user pane implementation
1112 void wxTextCtrl::MacControlUserPaneDrawProc(wxInt16 part
)
1114 GetPeer()->MacControlUserPaneDrawProc( part
) ;
1117 wxInt16
wxTextCtrl::MacControlUserPaneHitTestProc(wxInt16 x
, wxInt16 y
)
1119 return GetPeer()->MacControlUserPaneHitTestProc( x
, y
) ;
1122 wxInt16
wxTextCtrl::MacControlUserPaneTrackingProc(wxInt16 x
, wxInt16 y
, void* actionProc
)
1124 return GetPeer()->MacControlUserPaneTrackingProc( x
, y
, actionProc
) ;
1127 void wxTextCtrl::MacControlUserPaneIdleProc()
1129 GetPeer()->MacControlUserPaneIdleProc( ) ;
1132 wxInt16
wxTextCtrl::MacControlUserPaneKeyDownProc(wxInt16 keyCode
, wxInt16 charCode
, wxInt16 modifiers
)
1134 return GetPeer()->MacControlUserPaneKeyDownProc( keyCode
, charCode
, modifiers
) ;
1137 void wxTextCtrl::MacControlUserPaneActivateProc(bool activating
)
1139 GetPeer()->MacControlUserPaneActivateProc( activating
) ;
1142 wxInt16
wxTextCtrl::MacControlUserPaneFocusProc(wxInt16 action
)
1144 return GetPeer()->MacControlUserPaneFocusProc( action
) ;
1147 void wxTextCtrl::MacControlUserPaneBackgroundProc(void* info
)
1149 GetPeer()->MacControlUserPaneBackgroundProc( info
) ;
1153 // ----------------------------------------------------------------------------
1154 // implementation base class
1155 // ----------------------------------------------------------------------------
1157 wxMacTextControl::wxMacTextControl(wxTextCtrl
* peer
) :
1158 wxMacControl( peer
)
1162 wxMacTextControl::~wxMacTextControl()
1166 void wxMacTextControl::SetStyle(long start
, long end
, const wxTextAttr
& style
)
1170 void wxMacTextControl::Copy()
1174 void wxMacTextControl::Cut()
1178 void wxMacTextControl::Paste()
1182 bool wxMacTextControl::CanPaste() const
1187 void wxMacTextControl::SetEditable(bool editable
)
1191 wxTextPos
wxMacTextControl::GetLastPosition() const
1193 return GetStringValue().Length() ;
1196 void wxMacTextControl::Replace( long from
, long to
, const wxString
&val
)
1198 SetSelection( from
, to
) ;
1202 void wxMacTextControl::Remove( long from
, long to
)
1204 SetSelection( from
, to
) ;
1205 WriteText( wxEmptyString
) ;
1208 void wxMacTextControl::Clear()
1210 SetStringValue( wxEmptyString
) ;
1213 bool wxMacTextControl::CanUndo() const
1218 void wxMacTextControl::Undo() { }
1220 bool wxMacTextControl::CanRedo() const
1225 void wxMacTextControl::Redo()
1229 long wxMacTextControl::XYToPosition(long x
, long y
) const
1234 bool wxMacTextControl::PositionToXY(long pos
, long *x
, long *y
) const
1239 void wxMacTextControl::ShowPosition( long WXUNUSED(pos
) )
1243 int wxMacTextControl::GetNumberOfLines() const
1245 ItemCount lines
= 0 ;
1246 wxString content
= GetStringValue() ;
1248 for (size_t i
= 0; i
< content
.Length() ; i
++)
1250 if (content
[i
] == '\r') lines
++;
1255 wxString
wxMacTextControl::GetLineText(long lineNo
) const
1257 // TODO change this if possible to reflect real lines
1258 wxString content
= GetStringValue() ;
1262 for (size_t i
= 0; i
< content
.Length() ; i
++)
1264 if (count
== lineNo
)
1266 // Add chars in line then
1269 for (size_t j
= i
; j
< content
.Length(); j
++)
1271 if (content
[j
] == '\n')
1279 if (content
[i
] == '\n') count
++;
1281 return wxEmptyString
;
1284 int wxMacTextControl::GetLineLength(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 // Count chars in line then
1297 for (size_t j
= i
; j
< content
.Length(); j
++)
1300 if (content
[j
] == '\n') return count
;
1305 if (content
[i
] == '\n') count
++;
1310 // ----------------------------------------------------------------------------
1311 // standard unicode control implementation
1312 // ----------------------------------------------------------------------------
1314 #if TARGET_API_MAC_OSX
1316 wxMacUnicodeTextControl::wxMacUnicodeTextControl( wxTextCtrl
*wxPeer
,
1317 const wxString
& str
,
1319 const wxSize
& size
, long style
) : wxMacTextControl( wxPeer
)
1321 m_font
= wxPeer
->GetFont() ;
1322 m_windowStyle
= style
;
1323 Rect bounds
= wxMacGetBoundsForControl( wxPeer
, pos
, size
) ;
1325 wxMacConvertNewlines10To13( &st
) ;
1326 wxMacCFStringHolder
cf(st
, m_font
.GetEncoding()) ;
1327 CFStringRef cfr
= cf
;
1328 Boolean isPassword
= ( m_windowStyle
& wxTE_PASSWORD
) != 0 ;
1329 m_valueTag
= isPassword
? kControlEditTextPasswordCFStringTag
: kControlEditTextCFStringTag
;
1330 CreateEditUnicodeTextControl( MAC_WXHWND(wxPeer
->MacGetTopLevelWindowRef()), &bounds
, cfr
, isPassword
, NULL
, &m_controlRef
) ;
1332 if ( !(m_windowStyle
& wxTE_MULTILINE
) )
1334 SetData
<Boolean
>( kControlEditTextPart
, kControlEditTextSingleLineTag
, true ) ;
1338 wxMacUnicodeTextControl::~wxMacUnicodeTextControl()
1342 void wxMacUnicodeTextControl::VisibilityChanged(bool shown
)
1344 if ( !(m_windowStyle
& wxTE_MULTILINE
) && shown
)
1346 // work around a refresh issue insofar as not always the entire content is shown even if this would be possible
1347 ControlEditTextSelectionRec sel
;
1348 CFStringRef value
= NULL
;
1350 verify_noerr( GetData
<ControlEditTextSelectionRec
>( 0, kControlEditTextSelectionTag
, &sel
) );
1351 verify_noerr( GetData
<CFStringRef
>( 0, m_valueTag
, &value
) );
1352 verify_noerr( SetData
<CFStringRef
>( 0, m_valueTag
, &value
) );
1353 verify_noerr( SetData
<ControlEditTextSelectionRec
>( 0, kControlEditTextSelectionTag
, &sel
) );
1355 CFRelease( value
) ;
1358 wxString
wxMacUnicodeTextControl::GetStringValue() const
1361 CFStringRef value
= GetData
<CFStringRef
>(0,m_valueTag
) ;
1364 wxMacCFStringHolder
cf(value
) ;
1365 result
= cf
.AsString() ;
1368 wxMacConvertNewlines13To10( &result
) ;
1370 wxMacConvertNewlines10To13( &result
) ;
1374 void wxMacUnicodeTextControl::SetStringValue( const wxString
&str
)
1377 wxMacConvertNewlines10To13( &st
) ;
1378 wxMacCFStringHolder
cf(st
, m_font
.GetEncoding() ) ;
1379 verify_noerr( SetData
<CFStringRef
>( 0, m_valueTag
, cf
) ) ;
1381 void wxMacUnicodeTextControl::Copy()
1383 SendHICommand( kHICommandCopy
) ;
1385 void wxMacUnicodeTextControl::Cut()
1387 SendHICommand( kHICommandCut
) ;
1389 void wxMacUnicodeTextControl::Paste()
1391 SendHICommand( kHICommandPaste
) ;
1393 bool wxMacUnicodeTextControl::CanPaste() const
1397 void wxMacUnicodeTextControl::SetEditable(bool editable
)
1399 SetData
<Boolean
>( 0 , kControlEditTextLockedTag
, (Boolean
) !editable
) ;
1402 void wxMacUnicodeTextControl::GetSelection( long* from
, long* to
) const
1404 ControlEditTextSelectionRec sel
;
1405 verify_noerr(GetData
<ControlEditTextSelectionRec
>( 0, kControlEditTextSelectionTag
, &sel
) ) ;
1406 if ( from
) *from
= sel
.selStart
;
1407 if ( to
) *to
= sel
.selEnd
;
1410 void wxMacUnicodeTextControl::SetSelection( long from
, long to
)
1412 ControlEditTextSelectionRec sel
;
1413 if ((from
== -1) && (to
== -1))
1416 to
= 32767 ; // sel has 16 bit signed values, max is 32767
1418 sel
.selStart
= from
;
1420 SetData
<ControlEditTextSelectionRec
>( 0 , kControlEditTextSelectionTag
, &sel
) ;
1423 void wxMacUnicodeTextControl::WriteText(const wxString
& str
)
1426 wxMacConvertNewlines10To13( &st
) ;
1427 #if MAC_OS_X_VERSION_MAX_ALLOWED > MAC_OS_X_VERSION_10_2
1428 wxMacCFStringHolder
cf(st
, m_font
.GetEncoding() ) ;
1429 CFStringRef value
= cf
;
1430 SetData
<CFStringRef
>( 0, kControlEditTextInsertCFStringRefTag
, &value
);
1432 wxString val
= GetStringValue() ;
1434 GetSelection( &start
, &end
) ;
1435 val
.Remove( start
, end
- start
) ;
1436 val
.insert( start
, str
) ;
1437 SetStringValue( val
) ;
1438 SetSelection( start
+ str
.Length() , start
+ str
.Length() ) ;
1444 // ----------------------------------------------------------------------------
1445 // MLTE control implementation (common part)
1446 // ----------------------------------------------------------------------------
1448 // if mlte is on read only , no changes at all are allowed, not even from
1449 // procedural API, in order to allow changes via API all the same we must undo
1450 // the readonly status while we are executing, this class helps to do so
1452 class wxMacEditHelper
1455 wxMacEditHelper( TXNObject txn
)
1457 TXNControlTag tag
[] = { kTXNIOPrivilegesTag
} ;
1459 TXNGetTXNObjectControls( m_txn
, 1 , tag
, m_data
) ;
1460 if ( m_data
[0].uValue
== kTXNReadOnly
)
1462 TXNControlData data
[] = { { kTXNReadWrite
} } ;
1463 TXNSetTXNObjectControls( m_txn
, false , 1 , tag
, data
) ;
1468 TXNControlTag tag
[] = { kTXNIOPrivilegesTag
} ;
1469 if ( m_data
[0].uValue
== kTXNReadOnly
)
1471 TXNSetTXNObjectControls( m_txn
, false , 1 , tag
, m_data
) ;
1476 TXNControlData m_data
[1] ;
1479 wxMacMLTEControl::wxMacMLTEControl( wxTextCtrl
*peer
) : wxMacTextControl( peer
)
1481 SetNeedsFocusRect( true ) ;
1484 wxString
wxMacMLTEControl::GetStringValue() const
1488 Size actualSize
= 0;
1492 err
= TXNGetDataEncoded( m_txn
, kTXNStartOffset
, kTXNEndOffset
, &theText
, kTXNUnicodeTextData
);
1500 actualSize
= GetHandleSize( theText
) / sizeof( UniChar
) ;
1501 if ( actualSize
> 0 )
1503 wxChar
*ptr
= NULL
;
1504 #if SIZEOF_WCHAR_T == 2
1505 ptr
= new wxChar
[actualSize
+ 1 ] ;
1506 wxStrncpy( ptr
, (wxChar
*) *theText
, actualSize
) ;
1508 SetHandleSize( theText
, ( actualSize
+ 1 ) * sizeof( UniChar
) ) ;
1510 (((UniChar
*)*theText
)[actualSize
]) = 0 ;
1511 wxMBConvUTF16 converter
;
1512 size_t noChars
= converter
.MB2WC( NULL
, (const char*)*theText
, 0 ) ;
1513 ptr
= new wxChar
[noChars
+ 1] ;
1515 noChars
= converter
.MB2WC( ptr
, (const char*)*theText
, noChars
) ;
1517 HUnlock( theText
) ;
1519 ptr
[actualSize
] = 0 ;
1520 result
= wxString( ptr
) ;
1523 DisposeHandle( theText
) ;
1527 err
= TXNGetDataEncoded( m_txn
, kTXNStartOffset
, kTXNEndOffset
, &theText
, kTXNTextData
);
1535 actualSize
= GetHandleSize( theText
) ;
1536 if ( actualSize
> 0 )
1539 result
= wxString( *theText
, wxConvLocal
, actualSize
) ;
1540 HUnlock( theText
) ;
1542 DisposeHandle( theText
) ;
1547 wxMacConvertNewlines13To10( &result
) ;
1549 wxMacConvertNewlines10To13( &result
) ;
1554 void wxMacMLTEControl::SetStringValue( const wxString
&str
)
1558 wxMacConvertNewlines10To13( &st
) ;
1560 wxMacWindowClipper
c( m_peer
) ;
1562 wxMacEditHelper
help(m_txn
) ;
1563 SetTXNData( st
, kTXNStartOffset
, kTXNEndOffset
) ;
1565 TXNSetSelection( m_txn
, 0, 0);
1566 TXNShowSelection( m_txn
, kTXNShowStart
);
1570 TXNFrameOptions
wxMacMLTEControl::FrameOptionsFromWXStyle( long wxStyle
)
1572 TXNFrameOptions frameOptions
=
1573 kTXNDontDrawCaretWhenInactiveMask
1574 #if MAC_OS_X_VERSION_MAX_ALLOWED >= MAC_OS_X_VERSION_10_3
1575 | kTXNDoFontSubstitutionMask
1579 if ( ! ( wxStyle
& wxTE_NOHIDESEL
) )
1580 frameOptions
|= kTXNDontDrawSelectionWhenInactiveMask
;
1582 if ( wxStyle
& wxTE_MULTILINE
)
1584 if ( ! ( wxStyle
& wxTE_DONTWRAP
) )
1585 frameOptions
|= kTXNAlwaysWrapAtViewEdgeMask
;
1588 frameOptions
|= kTXNAlwaysWrapAtViewEdgeMask
;
1589 frameOptions
|= kTXNWantHScrollBarMask
;
1592 if ( !(wxStyle
& wxTE_NO_VSCROLL
) )
1594 frameOptions
|= kTXNWantVScrollBarMask
;
1595 if ( frameOptions
& kTXNWantHScrollBarMask
)
1596 frameOptions
|= kTXNDrawGrowIconMask
;
1600 frameOptions
|= kTXNSingleLineOnlyMask
;
1602 if ( wxStyle
& wxHSCROLL
)
1603 frameOptions
|= kTXNWantHScrollBarMask
;
1605 return frameOptions
;
1608 void wxMacMLTEControl::AdjustCreationAttributes( const wxColour
&background
, bool visible
)
1610 TXNControlTag iControlTags
[] =
1612 kTXNDoFontSubstitution
,
1613 kTXNWordWrapStateTag
,
1615 TXNControlData iControlData
[] =
1621 int toptag
= WXSIZEOF( iControlTags
) ;
1623 if ( m_windowStyle
& wxTE_MULTILINE
)
1625 if (m_windowStyle
& wxTE_DONTWRAP
)
1626 iControlData
[1].uValue
= kTXNNoAutoWrap
;
1628 iControlData
[1].uValue
= kTXNAutoWrap
;
1630 verify_noerr( TXNSetTXNObjectControls( m_txn
, false, toptag
,
1631 iControlTags
, iControlData
)) ;
1633 // setting the default font
1634 // under 10.2 this causes a visible caret, therefore we avoid it
1636 if ( UMAGetSystemVersion() >= 0x1030 )
1642 GetThemeFont(kThemeSystemFont
, GetApplicationScript() , fontName
, &fontSize
, &fontStyle
) ;
1644 TXNTypeAttributes typeAttr
[] =
1646 { kTXNQDFontNameAttribute
, kTXNQDFontNameAttributeSize
, { (void*) fontName
} } ,
1647 { kTXNQDFontSizeAttribute
, kTXNFontSizeAttributeSize
, { (void*) (fontSize
<< 16) } } ,
1648 { kTXNQDFontStyleAttribute
, kTXNQDFontStyleAttributeSize
, { (void*) normal
} } ,
1651 verify_noerr( TXNSetTypeAttributes (m_txn
, sizeof( typeAttr
) / sizeof(TXNTypeAttributes
) , typeAttr
,
1656 if ( m_windowStyle
& wxTE_PASSWORD
)
1659 verify_noerr(TXNEchoMode( m_txn
, c
, 0 , true )) ;
1662 TXNBackground tback
;
1663 tback
.bgType
= kTXNBackgroundTypeRGB
;
1664 tback
.bg
.color
= MAC_WXCOLORREF( background
.GetPixel() );
1665 TXNSetBackground( m_txn
, &tback
);
1666 #if MAC_OS_X_VERSION_MAX_ALLOWED >= MAC_OS_X_VERSION_10_4
1667 if ( UMAGetSystemVersion() >= 0x1040 )
1669 TXNCommandEventSupportOptions options
;
1670 if ( TXNGetCommandEventSupport( m_txn
, &options
) == noErr
)
1672 options
|= kTXNSupportEditCommandProcessing
;
1673 options
|= kTXNSupportSpellCheckCommandProcessing
;
1674 options
|= kTXNSupportFontCommandProcessing
;
1675 options
|= kTXNSupportFontCommandUpdating
;
1677 TXNSetCommandEventSupport( m_txn
, options
) ;
1683 void wxMacMLTEControl::SetBackground( const wxBrush
&brush
)
1685 // currently only solid background are supported
1686 TXNBackground tback
;
1687 tback
.bgType
= kTXNBackgroundTypeRGB
;
1688 tback
.bg
.color
= MAC_WXCOLORREF( brush
.GetColour().GetPixel() );
1689 TXNSetBackground( m_txn
, &tback
);
1692 void wxMacMLTEControl::TXNSetAttribute( const wxTextAttr
& style
, long from
, long to
)
1694 TXNTypeAttributes typeAttr
[4] ;
1695 Str255 fontName
= "\pMonaco" ;
1696 SInt16 fontSize
= 12 ;
1697 Style fontStyle
= normal
;
1699 int attrCounter
= 0 ;
1700 if ( style
.HasFont() )
1702 const wxFont
&font
= style
.GetFont() ;
1703 wxMacStringToPascal( font
.GetFaceName() , fontName
) ;
1704 fontSize
= font
.GetPointSize() ;
1705 if ( font
.GetUnderlined() )
1706 fontStyle
|= underline
;
1707 if ( font
.GetWeight() == wxBOLD
)
1709 if ( font
.GetStyle() == wxITALIC
)
1710 fontStyle
|= italic
;
1712 typeAttr
[attrCounter
].tag
= kTXNQDFontNameAttribute
;
1713 typeAttr
[attrCounter
].size
= kTXNQDFontNameAttributeSize
;
1714 typeAttr
[attrCounter
].data
.dataPtr
= (void*) fontName
;
1715 typeAttr
[attrCounter
+1].tag
= kTXNQDFontSizeAttribute
;
1716 typeAttr
[attrCounter
+1].size
= kTXNFontSizeAttributeSize
;
1717 typeAttr
[attrCounter
+1].data
.dataValue
= (fontSize
<< 16) ;
1718 typeAttr
[attrCounter
+2].tag
= kTXNQDFontStyleAttribute
;
1719 typeAttr
[attrCounter
+2].size
= kTXNQDFontStyleAttributeSize
;
1720 typeAttr
[attrCounter
+2].data
.dataValue
= fontStyle
;
1723 if ( style
.HasTextColour() )
1725 typeAttr
[attrCounter
].tag
= kTXNQDFontColorAttribute
;
1726 typeAttr
[attrCounter
].size
= kTXNQDFontColorAttributeSize
;
1727 typeAttr
[attrCounter
].data
.dataPtr
= (void*) &color
;
1728 color
= MAC_WXCOLORREF(style
.GetTextColour().GetPixel()) ;
1731 if ( attrCounter
> 0 )
1733 verify_noerr( TXNSetTypeAttributes ( m_txn
, attrCounter
, typeAttr
, from
, to
) );
1737 void wxMacMLTEControl::SetFont( const wxFont
& font
, const wxColour
& foreground
, long windowStyle
)
1739 wxMacEditHelper
help(m_txn
) ;
1740 TXNSetAttribute( wxTextAttr(foreground
,wxNullColour
,font
) , kTXNStartOffset
,kTXNEndOffset
) ;
1742 void wxMacMLTEControl::SetStyle(long start
, long end
, const wxTextAttr
& style
)
1744 wxMacEditHelper
help(m_txn
) ;
1745 TXNSetAttribute( style
, start
,end
) ;
1748 void wxMacMLTEControl::Copy()
1750 ClearCurrentScrap();
1752 TXNConvertToPublicScrap();
1755 void wxMacMLTEControl::Cut()
1757 ClearCurrentScrap();
1759 TXNConvertToPublicScrap();
1762 void wxMacMLTEControl::Paste()
1764 TXNConvertFromPublicScrap();
1768 bool wxMacMLTEControl::CanPaste() const
1770 return TXNIsScrapPastable() ;
1773 void wxMacMLTEControl::SetEditable(bool editable
)
1775 TXNControlTag tag
[] = { kTXNIOPrivilegesTag
} ;
1776 TXNControlData data
[] = { { editable
? kTXNReadWrite
: kTXNReadOnly
} } ;
1777 TXNSetTXNObjectControls( m_txn
, false , WXSIZEOF(tag
) , tag
, data
) ;
1780 wxTextPos
wxMacMLTEControl::GetLastPosition() const
1782 wxTextPos actualsize
= 0 ;
1785 OSErr err
= TXNGetDataEncoded( m_txn
, kTXNStartOffset
, kTXNEndOffset
, &theText
, kTXNTextData
);
1793 actualsize
= GetHandleSize( theText
) ;
1794 DisposeHandle( theText
) ;
1800 void wxMacMLTEControl::Replace( long from
, long to
, const wxString
&str
)
1802 wxString value
= str
;
1803 wxMacConvertNewlines10To13( &value
) ;
1805 wxMacEditHelper
help( m_txn
) ;
1806 wxMacWindowClipper
c( m_peer
) ;
1808 TXNSetSelection(m_txn
, from
, to
) ;
1810 SetTXNData( value
, kTXNUseCurrentSelection
, kTXNUseCurrentSelection
) ;
1813 void wxMacMLTEControl::Remove( long from
, long to
)
1815 wxMacWindowClipper
c( m_peer
) ;
1816 wxMacEditHelper
help( m_txn
) ;
1817 TXNSetSelection(m_txn
, from
, to
) ;
1821 void wxMacMLTEControl::GetSelection( long* from
, long* to
) const
1823 TXNGetSelection( m_txn
, (TXNOffset
*) from
, (TXNOffset
*) to
) ;
1826 void wxMacMLTEControl::SetSelection( long from
, long to
)
1828 wxMacWindowClipper
c( m_peer
) ;
1829 /* change the selection */
1830 if ((from
== -1) && (to
== -1))
1831 TXNSelectAll(m_txn
);
1833 TXNSetSelection( m_txn
, from
, to
);
1834 TXNShowSelection( m_txn
, kTXNShowStart
);
1837 void wxMacMLTEControl::WriteText(const wxString
& str
)
1840 wxMacConvertNewlines10To13( &st
) ;
1842 long start
, end
, dummy
;
1843 GetSelection( &start
, &dummy
) ;
1844 wxMacWindowClipper
c( m_peer
) ;
1846 wxMacEditHelper
helper( m_txn
) ;
1847 SetTXNData( st
, kTXNUseCurrentSelection
, kTXNUseCurrentSelection
) ;
1849 GetSelection( &dummy
, &end
) ;
1850 // TODO SetStyle( start , end , GetDefaultStyle() ) ;
1853 void wxMacMLTEControl::Clear()
1855 wxMacWindowClipper
c( m_peer
) ;
1856 wxMacEditHelper
st(m_txn
) ;
1857 TXNSetSelection( m_txn
, kTXNStartOffset
, kTXNEndOffset
) ;
1861 bool wxMacMLTEControl::CanUndo() const
1863 return TXNCanUndo( m_txn
, NULL
) ;
1866 void wxMacMLTEControl::Undo()
1871 bool wxMacMLTEControl::CanRedo() const
1873 return TXNCanRedo( m_txn
, NULL
) ;
1876 void wxMacMLTEControl::Redo()
1881 int wxMacMLTEControl::GetNumberOfLines() const
1883 ItemCount lines
= 0 ;
1884 TXNGetLineCount(m_txn
, &lines
) ;
1888 long wxMacMLTEControl::XYToPosition(long x
, long y
) const
1892 wxTextPos lastpos
= GetLastPosition() ;
1894 // TODO find a better implementation : while we can get the
1895 // line metrics of a certain line, we don't get its starting
1896 // position, so it would probably be rather a binary search
1897 // for the start position
1900 int lastHeight
= 0 ;
1903 for ( n
= 0 ; n
<= (ItemCount
) lastpos
; ++n
)
1905 if ( y
== ypos
&& x
== xpos
)
1908 TXNOffsetToPoint( m_txn
, n
, &curpt
);
1910 if ( curpt
.v
> lastHeight
)
1915 lastHeight
= curpt
.v
;
1923 bool wxMacMLTEControl::PositionToXY(long pos
, long *x
, long *y
) const
1927 wxTextPos lastpos
= GetLastPosition() ;
1932 if ( pos
<= lastpos
)
1934 // TODO find a better implementation : while we can get the
1935 // line metrics of a certain line, we don't get its starting
1936 // position, so it would probably be rather a binary search
1937 // for the start position
1940 int lastHeight
= 0 ;
1943 for ( n
= 0 ; n
<= (ItemCount
) pos
; ++n
)
1945 TXNOffsetToPoint(m_txn
, n
, &curpt
);
1947 if ( curpt
.v
> lastHeight
)
1952 lastHeight
= curpt
.v
;
1957 if ( y
) *y
= ypos
;
1958 if ( x
) *x
= xpos
;
1964 void wxMacMLTEControl::ShowPosition( long pos
)
1966 #if TARGET_RT_MAC_MACHO && defined(AVAILABLE_MAC_OS_X_VERSION_10_2_AND_LATER)
1970 TXNOffset selstart
, selend
;
1971 TXNGetSelection( m_txn
, &selstart
, &selend
) ;
1972 TXNOffsetToPoint( m_txn
, selstart
, ¤t
);
1973 TXNOffsetToPoint( m_txn
, pos
, &desired
);
1974 //TODO use HIPoints for 10.3 and above
1975 if ( (UInt32
) TXNScroll
!= (UInt32
) kUnresolvedCFragSymbolAddress
)
1977 OSErr theErr
= noErr
;
1978 SInt32 dv
= desired
.v
- current
.v
;
1979 SInt32 dh
= desired
.h
- current
.h
;
1980 TXNShowSelection( m_txn
, true ) ;
1981 theErr
= TXNScroll( m_txn
, kTXNScrollUnitsInPixels
, kTXNScrollUnitsInPixels
, &dv
, &dh
);
1982 // there will be an error returned for classic mlte implementation when the control is
1983 // invisible, but HITextView works correctly, so we don't assert that one
1984 // wxASSERT_MSG( theErr == noErr, _T("TXNScroll returned an error!") );
1990 void wxMacMLTEControl::SetTXNData( const wxString
& st
, TXNOffset start
, TXNOffset end
)
1993 #if SIZEOF_WCHAR_T == 2
1994 size_t len
= st
.Len() ;
1995 TXNSetData( m_txn
, kTXNUnicodeTextData
, (void*)st
.wc_str(), len
* 2,
1998 wxMBConvUTF16 converter
;
1999 ByteCount byteBufferLen
= converter
.WC2MB( NULL
, st
.wc_str() , 0 ) ;
2000 UniChar
*unibuf
= (UniChar
*) malloc(byteBufferLen
) ;
2001 converter
.WC2MB( (char*) unibuf
, st
.wc_str() , byteBufferLen
) ;
2002 TXNSetData( m_txn
, kTXNUnicodeTextData
, (void*)unibuf
, byteBufferLen
,
2007 wxCharBuffer text
= st
.mb_str(wxConvLocal
) ;
2008 TXNSetData( m_txn
, kTXNTextData
, (void*)text
.data(), strlen( text
) ,
2014 wxString
wxMacMLTEControl::GetLineText(long lineNo
) const
2018 if ( lineNo
< GetNumberOfLines() )
2026 // get the first possible position in the control
2028 TXNOffsetToPoint(m_txn
, 0, &firstPoint
);
2030 // Iterate through the lines until we reach the one we want,
2031 // adding to our current y pixel point position
2032 while (ypos
< lineNo
)
2034 TXNGetLineMetrics(m_txn
, ypos
++, &lineWidth
, &lineHeight
);
2035 currentHeight
+= lineHeight
;
2038 Point thePoint
= { firstPoint
.v
+ (currentHeight
>> 16), firstPoint
.h
+ (0) };
2039 TXNOffset theOffset
;
2040 TXNPointToOffset(m_txn
, thePoint
, &theOffset
);
2042 wxString content
= GetStringValue() ;
2043 Point currentPoint
= thePoint
;
2044 while(thePoint
.v
== currentPoint
.v
&& theOffset
< content
.length())
2046 line
+= content
[theOffset
];
2047 TXNOffsetToPoint(m_txn
, ++theOffset
, ¤tPoint
);
2053 int wxMacMLTEControl::GetLineLength(long lineNo
) const
2057 if ( lineNo
< GetNumberOfLines() )
2065 // get the first possible position in the control
2067 TXNOffsetToPoint(m_txn
, 0, &firstPoint
);
2069 // Iterate through the lines until we reach the one we want,
2070 // adding to our current y pixel point position
2071 while (ypos
< lineNo
)
2073 TXNGetLineMetrics(m_txn
, ypos
++, &lineWidth
, &lineHeight
);
2074 currentHeight
+= lineHeight
;
2077 Point thePoint
= { firstPoint
.v
+ (currentHeight
>> 16), firstPoint
.h
+ (0) };
2078 TXNOffset theOffset
;
2079 TXNPointToOffset(m_txn
, thePoint
, &theOffset
);
2081 wxString content
= GetStringValue() ;
2082 Point currentPoint
= thePoint
;
2083 while(thePoint
.v
== currentPoint
.v
&& theOffset
< content
.length())
2086 TXNOffsetToPoint(m_txn
, ++theOffset
, ¤tPoint
);
2093 // ----------------------------------------------------------------------------
2094 // MLTE control implementation (classic part)
2095 // ----------------------------------------------------------------------------
2097 // OS X Notes : We still don't have a full replacement for MLTE, so this implementation
2098 // has to live on. We have different problems coming from outdated implementations on the
2099 // various OS X versions. Most deal with the scrollbars: they are not correctly embedded
2100 // while this can be solved on 10.3 by reassigning them the correct place, on 10.2 there is
2101 // no way out, therefore we are using our own implementation and our own scrollbars ....
2103 #ifdef __WXMAC_OSX__
2105 TXNScrollInfoUPP gTXNScrollInfoProc
= NULL
;
2106 ControlActionUPP gTXNScrollActionProc
= NULL
;
2108 pascal void wxMacMLTEClassicControl::TXNScrollInfoProc (SInt32 iValue
, SInt32 iMaximumValue
, TXNScrollBarOrientation
2109 iScrollBarOrientation
, SInt32 iRefCon
)
2111 wxMacMLTEClassicControl
* mlte
= (wxMacMLTEClassicControl
*) iRefCon
;
2112 SInt32 value
= wxMax( iValue
, 0 ) ;
2113 SInt32 maximum
= wxMax( iMaximumValue
, 0 ) ;
2115 if ( iScrollBarOrientation
== kTXNHorizontal
)
2117 if ( mlte
->m_sbHorizontal
)
2119 SetControl32BitValue( mlte
->m_sbHorizontal
, value
) ;
2120 SetControl32BitMaximum( mlte
->m_sbHorizontal
, maximum
) ;
2121 mlte
->m_lastHorizontalValue
= value
;
2124 else if ( iScrollBarOrientation
== kTXNVertical
)
2126 if ( mlte
->m_sbVertical
)
2128 SetControl32BitValue( mlte
->m_sbVertical
, value
) ;
2129 SetControl32BitMaximum( mlte
->m_sbVertical
, maximum
) ;
2130 mlte
->m_lastVerticalValue
= value
;
2135 pascal void wxMacMLTEClassicControl::TXNScrollActionProc( ControlRef controlRef
, ControlPartCode partCode
)
2138 wxMacMLTEClassicControl
* mlte
= (wxMacMLTEClassicControl
*) GetControlReference( controlRef
) ;
2142 if ( controlRef
!= mlte
->m_sbVertical
&& controlRef
!= mlte
->m_sbHorizontal
)
2145 bool isHorizontal
= ( controlRef
== mlte
->m_sbHorizontal
) ;
2147 SInt32 minimum
= 0 ;
2148 SInt32 maximum
= GetControl32BitMaximum( controlRef
) ;
2149 SInt32 value
= GetControl32BitValue( controlRef
) ;
2153 case kControlDownButtonPart
:
2156 case kControlUpButtonPart
:
2159 case kControlPageDownPart
:
2160 delta
= GetControlViewSize( controlRef
) ;
2162 case kControlPageUpPart
:
2163 delta
= -GetControlViewSize( controlRef
) ;
2165 case kControlIndicatorPart
:
2167 ( isHorizontal
? mlte
->m_lastHorizontalValue
: mlte
->m_lastVerticalValue
) ;
2174 SInt32 newValue
= value
;
2176 if ( partCode
!= kControlIndicatorPart
)
2178 if( value
+ delta
< minimum
)
2179 delta
= minimum
- value
;
2180 if ( value
+ delta
> maximum
)
2181 delta
= maximum
- value
;
2183 SetControl32BitValue( controlRef
, value
+ delta
) ;
2184 newValue
= value
+ delta
;
2187 SInt32 verticalDelta
= isHorizontal
? 0 : delta
;
2188 SInt32 horizontalDelta
= isHorizontal
? delta
: 0 ;
2190 err
= TXNScroll( mlte
->m_txn
, kTXNScrollUnitsInPixels
, kTXNScrollUnitsInPixels
,
2191 &verticalDelta
, &horizontalDelta
);
2194 mlte
->m_lastHorizontalValue
= newValue
;
2196 mlte
->m_lastVerticalValue
= newValue
;
2201 // make correct activations
2202 void wxMacMLTEClassicControl::MacActivatePaneText(Boolean setActive
)
2204 wxTextCtrl
* textctrl
= (wxTextCtrl
*) GetControlReference(m_controlRef
);
2206 wxMacWindowClipper
clipper( textctrl
) ;
2207 TXNActivate(m_txn
, m_txnFrameID
, setActive
);
2209 ControlRef controlFocus
= 0 ;
2210 GetKeyboardFocus( m_txnWindow
, &controlFocus
) ;
2211 if ( controlFocus
== m_controlRef
)
2212 TXNFocus( m_txn
, setActive
);
2215 void wxMacMLTEClassicControl::MacFocusPaneText(Boolean setFocus
)
2217 TXNFocus( m_txn
, setFocus
);
2220 // guards against inappropriate redraw (hidden objects drawing onto window)
2222 void wxMacMLTEClassicControl::MacSetObjectVisibility(Boolean vis
)
2224 ControlRef controlFocus
= 0 ;
2225 GetKeyboardFocus( m_txnWindow
, &controlFocus
) ;
2227 if ( controlFocus
== m_controlRef
&& vis
== false )
2229 SetKeyboardFocus( m_txnWindow
, m_controlRef
, kControlFocusNoPart
) ;
2232 TXNControlTag iControlTags
[1] = { kTXNVisibilityTag
};
2233 TXNControlData iControlData
[1] = { {(UInt32
) false } };
2235 verify_noerr( TXNGetTXNObjectControls( m_txn
, 1,
2236 iControlTags
, iControlData
) ) ;
2238 if ( iControlData
[0].uValue
!= vis
)
2240 iControlData
[0].uValue
= vis
;
2241 verify_noerr( TXNSetTXNObjectControls( m_txn
, false , 1,
2242 iControlTags
, iControlData
)) ;
2244 // we right now are always clipping as partial visibility (overlapped) visibility
2245 // is also a problem, if we run into further problems we might set the FrameBounds to an empty
2249 // make sure that the TXNObject is at the right position
2251 void wxMacMLTEClassicControl::MacUpdatePosition()
2253 wxTextCtrl
* textctrl
= (wxTextCtrl
*) GetControlReference(m_controlRef
);
2254 if ( textctrl
== NULL
)
2258 UMAGetControlBoundsInWindowCoords(m_controlRef
, &bounds
);
2260 wxRect visRect
= textctrl
->MacGetClippedClientRect() ;
2261 Rect visBounds
= { visRect
.y
, visRect
.x
, visRect
.y
+ visRect
.height
, visRect
.x
+ visRect
.width
} ;
2264 textctrl
->MacWindowToRootWindow( &x
, &y
) ;
2265 OffsetRect( &visBounds
, x
, y
) ;
2267 if ( !EqualRect( &bounds
, &m_txnControlBounds
) || !EqualRect( &visBounds
, &m_txnVisBounds
) )
2269 m_txnControlBounds
= bounds
;
2270 m_txnVisBounds
= visBounds
;
2271 wxMacWindowClipper
cl(textctrl
) ;
2273 #ifdef __WXMAC_OSX__
2274 bool isCompositing
= textctrl
->MacGetTopLevelWindow()->MacUsesCompositing() ;
2275 if ( m_sbHorizontal
|| m_sbVertical
)
2277 int w
= bounds
.right
- bounds
.left
;
2278 int h
= bounds
.bottom
- bounds
.top
;
2280 if ( m_sbHorizontal
)
2284 sbBounds
.left
= -1 ;
2285 sbBounds
.top
= h
- 14 ;
2286 sbBounds
.right
= w
+ 1 ;
2287 sbBounds
.bottom
= h
+ 1 ;
2289 if ( !isCompositing
)
2290 OffsetRect( &sbBounds
, m_txnControlBounds
.left
, m_txnControlBounds
.top
) ;
2292 SetControlBounds( m_sbHorizontal
, &sbBounds
) ;
2293 SetControlViewSize( m_sbHorizontal
, w
) ;
2299 sbBounds
.left
= w
- 14 ;
2301 sbBounds
.right
= w
+ 1 ;
2302 sbBounds
.bottom
= m_sbHorizontal
? h
- 14 : h
+ 1 ;
2304 if ( !isCompositing
)
2305 OffsetRect( &sbBounds
, m_txnControlBounds
.left
, m_txnControlBounds
.top
) ;
2307 SetControlBounds( m_sbVertical
, &sbBounds
) ;
2308 SetControlViewSize( m_sbVertical
, h
) ;
2313 TXNLongRect olddestRect
;
2314 TXNGetRectBounds( m_txn
, &oldviewRect
, &olddestRect
, NULL
) ;
2316 Rect viewRect
= { m_txnControlBounds
.top
, m_txnControlBounds
.left
,
2317 m_txnControlBounds
.bottom
- ( m_sbHorizontal
? 14 : 0 ) , m_txnControlBounds
.right
- ( m_sbVertical
? 14 : 0 ) } ;
2318 TXNLongRect destRect
= { m_txnControlBounds
.top
, m_txnControlBounds
.left
,
2319 m_txnControlBounds
.bottom
- ( m_sbHorizontal
? 14 : 0 ) , m_txnControlBounds
.right
- ( m_sbVertical
? 14 : 0 ) } ;
2321 if ( olddestRect
.right
>= 10000 )
2322 destRect
.right
= destRect
.left
+ 32000 ;
2324 if ( olddestRect
.bottom
>= 0x20000000 )
2325 destRect
.bottom
= destRect
.top
+ 0x40000000 ;
2327 SectRect( &viewRect
, &visBounds
, &viewRect
) ;
2328 TXNSetRectBounds( m_txn
, &viewRect
, &destRect
, true ) ;
2330 TXNSetFrameBounds( m_txn, m_txnControlBounds.top, m_txnControlBounds.left,
2331 m_txnControlBounds.bottom - ( m_sbHorizontal ? 14 : 0 ) , m_txnControlBounds.right - ( m_sbVertical ? 14 : 0 ), m_txnFrameID);
2335 TXNSetFrameBounds( m_txn
, m_txnControlBounds
.top
, m_txnControlBounds
.left
,
2336 wxMax( m_txnControlBounds
.bottom
, m_txnControlBounds
.top
) ,
2337 wxMax( m_txnControlBounds
.right
, m_txnControlBounds
.left
) , m_txnFrameID
);
2339 // the SetFrameBounds method unter classic sometimes does not correctly scroll a selection into sight after a
2340 // movement, therefore we have to force it
2342 // according to David Surovell this problem also sometimes occurs under OSX, so we use this as well
2344 TXNLongRect textRect
;
2345 TXNGetRectBounds( m_txn
, NULL
, NULL
, &textRect
) ;
2346 if ( textRect
.left
< m_txnControlBounds
.left
)
2348 TXNShowSelection( m_txn
, false ) ;
2353 void wxMacMLTEClassicControl::SetRect( Rect
*r
)
2355 wxMacControl::SetRect( r
) ;
2356 MacUpdatePosition() ;
2359 void wxMacMLTEClassicControl::MacControlUserPaneDrawProc(wxInt16 thePart
)
2361 wxTextCtrl
* textctrl
= (wxTextCtrl
*) GetControlReference(m_controlRef
);
2362 if ( textctrl
== NULL
)
2365 if ( textctrl
->MacIsReallyShown() )
2367 wxMacWindowClipper
clipper( textctrl
) ;
2368 TXNDraw( m_txn
, NULL
) ;
2372 wxInt16
wxMacMLTEClassicControl::MacControlUserPaneHitTestProc(wxInt16 x
, wxInt16 y
)
2374 Point where
= { y
, x
} ;
2375 ControlPartCode result
;
2378 wxTextCtrl
* textctrl
= (wxTextCtrl
*) GetControlReference(m_controlRef
);
2379 if ( textctrl
== NULL
)
2382 if (textctrl
->MacIsReallyShown() )
2384 if (PtInRect(where
, &m_txnControlBounds
))
2385 result
= kControlEditTextPart
;
2388 // sometimes we get the coords also in control local coordinates, therefore test again
2389 if ( textctrl
->MacGetTopLevelWindow()->MacUsesCompositing() )
2392 textctrl
->MacClientToRootWindow( &x
, &y
) ;
2396 if (PtInRect(where
, &m_txnControlBounds
))
2397 result
= kControlEditTextPart
;
2405 wxInt16
wxMacMLTEClassicControl::MacControlUserPaneTrackingProc( wxInt16 x
, wxInt16 y
, void* actionProc
)
2407 wxTextCtrl
* textctrl
= (wxTextCtrl
*) GetControlReference(m_controlRef
);
2408 if ( textctrl
== NULL
)
2411 ControlPartCode partCodeResult
= 0;
2413 if (textctrl
->MacIsReallyShown() )
2415 Point startPt
= { y
,x
} ;
2416 // for compositing, we must convert these into toplevel window coordinates, because hittesting expects them
2417 if ( textctrl
->MacGetTopLevelWindow()->MacUsesCompositing() )
2420 textctrl
->MacClientToRootWindow( &x
, &y
) ;
2425 switch (MacControlUserPaneHitTestProc( startPt
.h
, startPt
.v
))
2427 case kControlEditTextPart
:
2429 wxMacWindowClipper
clipper( textctrl
) ;
2432 ConvertEventRefToEventRecord( (EventRef
) wxTheApp
->MacGetCurrentEvent() , &rec
) ;
2433 TXNClick( m_txn
, &rec
);
2439 return partCodeResult
;
2442 void wxMacMLTEClassicControl::MacControlUserPaneIdleProc()
2444 wxTextCtrl
* textctrl
= (wxTextCtrl
*) GetControlReference(m_controlRef
);
2445 if ( textctrl
== NULL
)
2448 if (textctrl
->MacIsReallyShown())
2450 if (IsControlActive(m_controlRef
))
2454 wxMacWindowClipper
clipper( textctrl
) ;
2459 if (PtInRect(mousep
, &m_txnControlBounds
))
2462 RectRgn((theRgn
= NewRgn()), &m_txnControlBounds
);
2463 TXNAdjustCursor(m_txn
, theRgn
);
2470 wxInt16
wxMacMLTEClassicControl::MacControlUserPaneKeyDownProc (wxInt16 keyCode
, wxInt16 charCode
, wxInt16 modifiers
)
2472 wxTextCtrl
* textctrl
= (wxTextCtrl
*) GetControlReference(m_controlRef
);
2473 if ( textctrl
== NULL
)
2476 wxMacWindowClipper
clipper( textctrl
) ;
2479 memset( &ev
, 0 , sizeof( ev
) ) ;
2481 ev
.modifiers
= modifiers
;
2482 ev
.message
= (( keyCode
<< 8 ) & keyCodeMask
) + ( charCode
& charCodeMask
) ;
2483 TXNKeyDown( m_txn
, &ev
);
2485 return kControlEntireControl
;
2488 void wxMacMLTEClassicControl::MacControlUserPaneActivateProc( bool activating
)
2490 MacActivatePaneText( activating
);
2493 wxInt16
wxMacMLTEClassicControl::MacControlUserPaneFocusProc(wxInt16 action
)
2495 ControlPartCode focusResult
;
2497 focusResult
= kControlFocusNoPart
;
2498 wxTextCtrl
* textctrl
= (wxTextCtrl
*) GetControlReference(m_controlRef
);
2499 if ( textctrl
== NULL
)
2502 wxMacWindowClipper
clipper( textctrl
) ;
2504 ControlRef controlFocus
= 0 ;
2505 GetKeyboardFocus( m_txnWindow
, &controlFocus
) ;
2506 bool wasFocused
= ( controlFocus
== m_controlRef
) ;
2510 case kControlFocusPrevPart
:
2511 case kControlFocusNextPart
:
2512 MacFocusPaneText( ( !wasFocused
));
2513 focusResult
= (!wasFocused
) ? (ControlPartCode
) kControlEditTextPart
: (ControlPartCode
) kControlFocusNoPart
;
2516 case kControlFocusNoPart
:
2518 MacFocusPaneText( false);
2519 focusResult
= kControlFocusNoPart
;
2526 void wxMacMLTEClassicControl::MacControlUserPaneBackgroundProc( void *info
)
2530 wxMacMLTEClassicControl::wxMacMLTEClassicControl( wxTextCtrl
*wxPeer
,
2531 const wxString
& str
,
2533 const wxSize
& size
, long style
) : wxMacMLTEControl( wxPeer
)
2535 m_font
= wxPeer
->GetFont() ;
2536 m_windowStyle
= style
;
2537 Rect bounds
= wxMacGetBoundsForControl( wxPeer
, pos
, size
) ;
2541 featurSet
= kControlSupportsEmbedding
| kControlSupportsFocus
| kControlWantsIdle
2542 | kControlWantsActivate
| kControlHandlesTracking
// | kControlHasSpecialBackground
2543 | kControlGetsFocusOnClick
| kControlSupportsLiveFeedback
;
2545 verify_noerr( ::CreateUserPaneControl( MAC_WXHWND(wxPeer
->GetParent()->MacGetTopLevelWindowRef()), &bounds
, featurSet
, &m_controlRef
) );
2549 AdjustCreationAttributes( *wxWHITE
, true) ;
2551 MacSetObjectVisibility( wxPeer
->MacIsReallyShown() ) ;
2555 wxMacConvertNewlines10To13( &st
) ;
2556 wxMacWindowClipper
clipper( m_peer
) ;
2557 SetTXNData( st
, kTXNStartOffset
, kTXNEndOffset
) ;
2558 TXNSetSelection( m_txn
, 0, 0);
2562 wxMacMLTEClassicControl::~wxMacMLTEClassicControl()
2564 TXNDeleteObject(m_txn
);
2568 void wxMacMLTEClassicControl::VisibilityChanged(bool shown
)
2570 MacSetObjectVisibility( shown
) ;
2571 wxMacControl::VisibilityChanged( shown
) ;
2574 void wxMacMLTEClassicControl::SuperChangedPosition()
2576 MacUpdatePosition() ;
2577 wxMacControl::SuperChangedPosition() ;
2580 #ifdef __WXMAC_OSX__
2582 ControlUserPaneDrawUPP gTPDrawProc
= NULL
;
2583 ControlUserPaneHitTestUPP gTPHitProc
= NULL
;
2584 ControlUserPaneTrackingUPP gTPTrackProc
= NULL
;
2585 ControlUserPaneIdleUPP gTPIdleProc
= NULL
;
2586 ControlUserPaneKeyDownUPP gTPKeyProc
= NULL
;
2587 ControlUserPaneActivateUPP gTPActivateProc
= NULL
;
2588 ControlUserPaneFocusUPP gTPFocusProc
= NULL
;
2590 static pascal void wxMacControlUserPaneDrawProc(ControlRef control
, SInt16 part
)
2592 wxTextCtrl
*textCtrl
= wxDynamicCast( wxFindControlFromMacControl(control
) , wxTextCtrl
) ;
2593 wxMacMLTEClassicControl
* win
= textCtrl
? (wxMacMLTEClassicControl
*)(textCtrl
->GetPeer()) : NULL
;
2595 win
->MacControlUserPaneDrawProc(part
) ;
2598 static pascal ControlPartCode
wxMacControlUserPaneHitTestProc(ControlRef control
, Point where
)
2600 wxTextCtrl
*textCtrl
= wxDynamicCast( wxFindControlFromMacControl(control
) , wxTextCtrl
) ;
2601 wxMacMLTEClassicControl
* win
= textCtrl
? (wxMacMLTEClassicControl
*)(textCtrl
->GetPeer()) : NULL
;
2603 return win
->MacControlUserPaneHitTestProc(where
.h
, where
.v
) ;
2605 return kControlNoPart
;
2608 static pascal ControlPartCode
wxMacControlUserPaneTrackingProc(ControlRef control
, Point startPt
, ControlActionUPP actionProc
)
2610 wxTextCtrl
*textCtrl
= wxDynamicCast( wxFindControlFromMacControl(control
) , wxTextCtrl
) ;
2611 wxMacMLTEClassicControl
* win
= textCtrl
? (wxMacMLTEClassicControl
*)(textCtrl
->GetPeer()) : NULL
;
2613 return win
->MacControlUserPaneTrackingProc( startPt
.h
, startPt
.v
, (void*) actionProc
) ;
2615 return kControlNoPart
;
2618 static pascal void wxMacControlUserPaneIdleProc(ControlRef control
)
2620 wxTextCtrl
*textCtrl
= wxDynamicCast( wxFindControlFromMacControl(control
) , wxTextCtrl
) ;
2621 wxMacMLTEClassicControl
* win
= textCtrl
? (wxMacMLTEClassicControl
*)(textCtrl
->GetPeer()) : NULL
;
2623 win
->MacControlUserPaneIdleProc() ;
2626 static pascal ControlPartCode
wxMacControlUserPaneKeyDownProc(ControlRef control
, SInt16 keyCode
, SInt16 charCode
, SInt16 modifiers
)
2628 wxTextCtrl
*textCtrl
= wxDynamicCast( wxFindControlFromMacControl(control
) , wxTextCtrl
) ;
2629 wxMacMLTEClassicControl
* win
= textCtrl
? (wxMacMLTEClassicControl
*)(textCtrl
->GetPeer()) : NULL
;
2631 return win
->MacControlUserPaneKeyDownProc(keyCode
,charCode
,modifiers
) ;
2633 return kControlNoPart
;
2636 static pascal void wxMacControlUserPaneActivateProc(ControlRef control
, Boolean activating
)
2638 wxTextCtrl
*textCtrl
= wxDynamicCast( wxFindControlFromMacControl(control
) , wxTextCtrl
) ;
2639 wxMacMLTEClassicControl
* win
= textCtrl
? (wxMacMLTEClassicControl
*)(textCtrl
->GetPeer()) : NULL
;
2641 win
->MacControlUserPaneActivateProc(activating
) ;
2644 static pascal ControlPartCode
wxMacControlUserPaneFocusProc(ControlRef control
, ControlFocusPart action
)
2646 wxTextCtrl
*textCtrl
= wxDynamicCast( wxFindControlFromMacControl(control
) , wxTextCtrl
) ;
2647 wxMacMLTEClassicControl
* win
= textCtrl
? (wxMacMLTEClassicControl
*)(textCtrl
->GetPeer()) : NULL
;
2649 return win
->MacControlUserPaneFocusProc(action
) ;
2651 return kControlNoPart
;
2655 static pascal void wxMacControlUserPaneBackgroundProc(ControlRef control, ControlBackgroundPtr info)
2657 wxTextCtrl *textCtrl = wxDynamicCast( wxFindControlFromMacControl(control) , wxTextCtrl ) ;
2658 wxMacMLTEClassicControl * win = textCtrl ? (wxMacMLTEClassicControl*)(textCtrl->GetPeer()) : NULL ;
2660 win->MacControlUserPaneBackgroundProc(info) ;
2665 // TXNRegisterScrollInfoProc
2667 OSStatus
wxMacMLTEClassicControl::DoCreate()
2671 OSStatus err
= noErr
;
2673 /* set up our globals */
2674 #ifdef __WXMAC_OSX__
2675 if (gTPDrawProc
== NULL
) gTPDrawProc
= NewControlUserPaneDrawUPP(wxMacControlUserPaneDrawProc
);
2676 if (gTPHitProc
== NULL
) gTPHitProc
= NewControlUserPaneHitTestUPP(wxMacControlUserPaneHitTestProc
);
2677 if (gTPTrackProc
== NULL
) gTPTrackProc
= NewControlUserPaneTrackingUPP(wxMacControlUserPaneTrackingProc
);
2678 if (gTPIdleProc
== NULL
) gTPIdleProc
= NewControlUserPaneIdleUPP(wxMacControlUserPaneIdleProc
);
2679 if (gTPKeyProc
== NULL
) gTPKeyProc
= NewControlUserPaneKeyDownUPP(wxMacControlUserPaneKeyDownProc
);
2680 if (gTPActivateProc
== NULL
) gTPActivateProc
= NewControlUserPaneActivateUPP(wxMacControlUserPaneActivateProc
);
2681 if (gTPFocusProc
== NULL
) gTPFocusProc
= NewControlUserPaneFocusUPP(wxMacControlUserPaneFocusProc
);
2683 if (gTXNScrollInfoProc
== NULL
) gTXNScrollInfoProc
= NewTXNScrollInfoUPP(TXNScrollInfoProc
) ;
2684 if (gTXNScrollActionProc
== NULL
) gTXNScrollActionProc
= NewControlActionUPP(TXNScrollActionProc
) ;
2687 /* set the initial settings for our private data */
2689 m_txnWindow
=GetControlOwner(m_controlRef
);
2690 m_txnPort
= (GrafPtr
) GetWindowPort(m_txnWindow
);
2692 #ifdef __WXMAC_OSX__
2693 /* set up the user pane procedures */
2694 SetControlData(m_controlRef
, kControlEntireControl
, kControlUserPaneDrawProcTag
, sizeof(gTPDrawProc
), &gTPDrawProc
);
2695 SetControlData(m_controlRef
, kControlEntireControl
, kControlUserPaneHitTestProcTag
, sizeof(gTPHitProc
), &gTPHitProc
);
2696 SetControlData(m_controlRef
, kControlEntireControl
, kControlUserPaneTrackingProcTag
, sizeof(gTPTrackProc
), &gTPTrackProc
);
2697 SetControlData(m_controlRef
, kControlEntireControl
, kControlUserPaneIdleProcTag
, sizeof(gTPIdleProc
), &gTPIdleProc
);
2698 SetControlData(m_controlRef
, kControlEntireControl
, kControlUserPaneKeyDownProcTag
, sizeof(gTPKeyProc
), &gTPKeyProc
);
2699 SetControlData(m_controlRef
, kControlEntireControl
, kControlUserPaneActivateProcTag
, sizeof(gTPActivateProc
), &gTPActivateProc
);
2700 SetControlData(m_controlRef
, kControlEntireControl
, kControlUserPaneFocusProcTag
, sizeof(gTPFocusProc
), &gTPFocusProc
);
2702 /* calculate the rectangles used by the control */
2703 UMAGetControlBoundsInWindowCoords(m_controlRef
, &bounds
);
2705 m_txnControlBounds
= bounds
;
2706 m_txnVisBounds
= bounds
;
2708 CGrafPtr origPort
= NULL
;
2709 GDHandle origDev
= NULL
;
2710 GetGWorld( &origPort
, &origDev
) ;
2713 /* create the new edit field */
2715 TXNFrameOptions frameOptions
= FrameOptionsFromWXStyle( m_windowStyle
) ;
2717 #ifdef __WXMAC_OSX__
2719 // the scrollbars are not correctly embedded but are inserted at the root
2720 // this gives us problems as we have erratic redraws even over the structure
2723 m_sbHorizontal
= 0 ;
2725 m_lastHorizontalValue
= 0 ;
2726 m_lastVerticalValue
= 0 ;
2728 Rect sb
= { 0 , 0 , 0 , 0 } ;
2729 if ( frameOptions
& kTXNWantVScrollBarMask
)
2731 CreateScrollBarControl( m_txnWindow
, &sb
, 0 , 0 , 100 , 1 , true , gTXNScrollActionProc
, &m_sbVertical
) ;
2732 SetControlReference( m_sbVertical
, (SInt32
) this ) ;
2733 SetControlAction( m_sbVertical
, gTXNScrollActionProc
);
2734 ShowControl( m_sbVertical
) ;
2735 EmbedControl( m_sbVertical
, m_controlRef
) ;
2736 frameOptions
&= ~kTXNWantVScrollBarMask
;
2738 if ( frameOptions
& kTXNWantHScrollBarMask
)
2740 CreateScrollBarControl( m_txnWindow
, &sb
, 0 , 0 , 100 , 1 , true , gTXNScrollActionProc
, &m_sbHorizontal
) ;
2741 SetControlReference( m_sbHorizontal
, (SInt32
) this ) ;
2742 SetControlAction( m_sbHorizontal
, gTXNScrollActionProc
);
2743 ShowControl( m_sbHorizontal
) ;
2744 EmbedControl( m_sbHorizontal
, m_controlRef
) ;
2745 frameOptions
&= ~(kTXNWantHScrollBarMask
| kTXNDrawGrowIconMask
);
2750 verify_noerr(TXNNewObject(NULL
, m_txnWindow
, &bounds
,
2752 kTXNTextEditStyleFrameType
,
2754 kTXNSystemDefaultEncoding
,
2755 &m_txn
, &m_txnFrameID
, NULL
) );
2757 TXNCarbonEventInfo cInfo ;
2759 cInfo.useCarbonEvents = false ;
2762 cInfo.fDictionary = NULL ;
2764 TXNControlTag iControlTags[] =
2766 kTXNUseCarbonEvents ,
2768 TXNControlData iControlData[] =
2773 int toptag = WXSIZEOF( iControlTags ) ;
2775 verify_noerr( TXNSetTXNObjectControls( m_txn, false , toptag,
2776 iControlTags, iControlData )) ;
2779 #ifdef __WXMAC_OSX__
2780 TXNRegisterScrollInfoProc( m_txn
, gTXNScrollInfoProc
, (SInt32
) this);
2783 SetGWorld( origPort
, origDev
) ;
2787 // ----------------------------------------------------------------------------
2788 // MLTE control implementation (OSX part)
2789 // ----------------------------------------------------------------------------
2791 #if TARGET_API_MAC_OSX
2793 #if MAC_OS_X_VERSION_MAX_ALLOWED > MAC_OS_X_VERSION_10_2
2795 wxMacMLTEHIViewControl::wxMacMLTEHIViewControl( wxTextCtrl
*wxPeer
,
2796 const wxString
& str
,
2798 const wxSize
& size
, long style
) : wxMacMLTEControl( wxPeer
)
2800 m_font
= wxPeer
->GetFont() ;
2801 m_windowStyle
= style
;
2802 Rect bounds
= wxMacGetBoundsForControl( wxPeer
, pos
, size
) ;
2804 wxMacConvertNewlines10To13( &st
) ;
2806 HIRect hr
= { { bounds
.left
, bounds
.top
} ,
2807 { bounds
.right
- bounds
.left
, bounds
.bottom
- bounds
.top
} } ;
2809 m_scrollView
= NULL
;
2810 TXNFrameOptions frameOptions
= FrameOptionsFromWXStyle( style
) ;
2811 if ( frameOptions
& (kTXNWantVScrollBarMask
|kTXNWantHScrollBarMask
) )
2813 HIScrollViewCreate(( frameOptions
& kTXNWantHScrollBarMask
? kHIScrollViewOptionsHorizScroll
: 0) |
2814 ( frameOptions
& kTXNWantVScrollBarMask
? kHIScrollViewOptionsVertScroll
: 0 ) , &m_scrollView
) ;
2816 HIViewSetFrame( m_scrollView
, &hr
);
2817 HIViewSetVisible( m_scrollView
, true );
2821 HITextViewCreate( NULL
, 0, frameOptions
, &m_textView
) ;
2822 m_txn
= HITextViewGetTXNObject( m_textView
) ;
2823 HIViewSetVisible( m_textView
, true ) ;
2826 HIViewAddSubview( m_scrollView
, m_textView
) ;
2827 m_controlRef
= m_scrollView
;
2828 wxPeer
->MacInstallEventHandler( (WXWidget
) m_textView
) ;
2832 HIViewSetFrame( m_textView
, &hr
);
2833 m_controlRef
= m_textView
;
2836 AdjustCreationAttributes( *wxWHITE
, true ) ;
2838 wxMacWindowClipper
c( m_peer
) ;
2839 SetTXNData( st
, kTXNStartOffset
, kTXNEndOffset
) ;
2841 TXNSetSelection( m_txn
, 0, 0);
2842 TXNShowSelection( m_txn
, kTXNShowStart
);
2846 OSStatus
wxMacMLTEHIViewControl::SetFocus( ControlFocusPart focusPart
)
2848 return SetKeyboardFocus( GetControlOwner( m_textView
) ,
2849 m_textView
, focusPart
) ;
2852 bool wxMacMLTEHIViewControl::HasFocus() const
2854 ControlRef control
;
2855 GetKeyboardFocus( GetUserFocusWindow() , &control
) ;
2856 return control
== m_textView
;
2859 #if MAC_OS_X_VERSION_MAX_ALLOWED < MAC_OS_X_VERSION_10_4
2860 #define kCGColorSpaceGenericRGB CFSTR("kCGColorSpaceGenericRGB")
2863 void wxMacMLTEHIViewControl::SetBackground( const wxBrush
&brush
)
2865 wxMacMLTEControl::SetBackground( brush
) ;
2867 CGColorSpaceRef rgbSpace = CGColorSpaceCreateDeviceRGB();
2868 RGBColor col = MAC_WXCOLORREF(brush.GetColour().GetPixel()) ;
2870 float component[4] ;
2871 component[0] = col.red / 65536.0 ;
2872 component[1] = col.green / 65536.0 ;
2873 component[2] = col.blue / 65536.0 ;
2874 component[3] = 1.0 ; // alpha
2876 CGColorRef color = CGColorCreate (rgbSpace , component );
2877 HITextViewSetBackgroundColor( m_textView , color ) ;
2878 CGColorSpaceRelease( rgbSpace );
2882 #endif // MAC_OS_X_VERSION_MAX_ALLOWED > MAC_OS_X_VERSION_10_2
2887 #endif // wxUSE_TEXTCTRL