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
) ;
122 classtype
* m_object
;
123 param1type m_param1
;
126 function m_function
;
127 ref_function m_refFunction
;
131 template<typename classtype
, typename param1type
>
132 void* wxMacMPRemoteCall( classtype
*object
, void (classtype::*function
)( param1type p1
) , param1type p1
)
134 wxMacObjectFunctor1
<classtype
,param1type
> params(object
,function
,p1
) ;
136 MPRemoteCall( wxMacFunctor::CallBackProc
, ¶ms
, kMPOwningProcessRemoteContext
) ;
140 template<typename classtype
, typename param1type
>
141 void* wxMacMPRemoteCall( classtype
*object
, void (classtype::*function
)( const param1type
& p1
) , param1type p1
)
143 wxMacObjectFunctor1
<classtype
,param1type
> params(object
,function
,p1
) ;
145 MPRemoteCall( wxMacFunctor::CallBackProc
, ¶ms
, kMPOwningProcessRemoteContext
) ;
149 template<typename classtype
, typename param1type
>
150 void* wxMacMPRemoteGUICall( classtype
*object
, void (classtype::*function
)( param1type p1
) , param1type p1
)
153 void *result
= wxMacMPRemoteCall( object
, function
, p1
) ;
158 template<typename classtype
, typename param1type
>
159 void* wxMacMPRemoteGUICall( classtype
*object
, void (classtype::*function
)( const param1type
& p1
) , param1type p1
)
162 void *result
= wxMacMPRemoteCall( object
, function
, p1
) ;
167 // common interface for all implementations
168 class wxMacTextControl
: public wxMacControl
171 wxMacTextControl( wxTextCtrl
*peer
) ;
172 ~wxMacTextControl() ;
174 virtual wxString
GetStringValue() const = 0 ;
175 virtual void SetStringValue( const wxString
&val
) = 0 ;
176 virtual void SetStyle(long start
, long end
, const wxTextAttr
& style
) ;
177 virtual void Copy() ;
179 virtual void Paste() ;
180 virtual bool CanPaste() const ;
181 virtual void SetEditable(bool editable
) ;
182 virtual wxTextPos
GetLastPosition() const ;
183 virtual void Replace( long from
, long to
, const wxString
&str
) ;
184 virtual void Remove( long from
, long to
) ;
185 virtual void SetSelection( long from
, long to
) = 0 ;
186 virtual void GetSelection( long* from
, long* to
) const = 0 ;
187 virtual void WriteText(const wxString
& str
) = 0 ;
188 virtual bool HasOwnContextMenu() const { return false ; }
190 virtual void Clear() ;
191 virtual bool CanUndo() const;
192 virtual void Undo() ;
193 virtual bool CanRedo() const;
194 virtual void Redo() ;
195 virtual int GetNumberOfLines() const ;
196 virtual long XYToPosition(long x
, long y
) const;
197 virtual bool PositionToXY(long pos
, long *x
, long *y
) const ;
198 virtual void ShowPosition( long WXUNUSED(pos
) ) ;
199 virtual int GetLineLength(long lineNo
) const ;
200 virtual wxString
GetLineText(long lineNo
) const ;
201 virtual bool SetupCursor( const wxPoint
& pt
) { return false ; }
203 #ifndef __WXMAC_OSX__
204 virtual void MacControlUserPaneDrawProc(wxInt16 part
) = 0 ;
205 virtual wxInt16
MacControlUserPaneHitTestProc(wxInt16 x
, wxInt16 y
) = 0 ;
206 virtual wxInt16
MacControlUserPaneTrackingProc(wxInt16 x
, wxInt16 y
, void* actionProc
) = 0 ;
207 virtual void MacControlUserPaneIdleProc() = 0 ;
208 virtual wxInt16
MacControlUserPaneKeyDownProc(wxInt16 keyCode
, wxInt16 charCode
, wxInt16 modifiers
) = 0 ;
209 virtual void MacControlUserPaneActivateProc(bool activating
) = 0 ;
210 virtual wxInt16
MacControlUserPaneFocusProc(wxInt16 action
) = 0 ;
211 virtual void MacControlUserPaneBackgroundProc(void* info
) = 0 ;
215 // common parts for implementations based on MLTE
217 class wxMacMLTEControl
: public wxMacTextControl
220 wxMacMLTEControl( wxTextCtrl
*peer
) ;
221 virtual wxString
GetStringValue() const ;
222 virtual void SetStringValue( const wxString
&str
) ;
224 static TXNFrameOptions
FrameOptionsFromWXStyle( long wxStyle
) ;
225 void AdjustCreationAttributes( const wxColour
& background
, bool visible
) ;
227 virtual void SetFont( const wxFont
& font
, const wxColour
& foreground
, long windowStyle
) ;
228 virtual void SetBackground( const wxBrush
&brush
) ;
229 virtual void SetStyle(long start
, long end
, const wxTextAttr
& style
) ;
230 virtual void Copy() ;
232 virtual void Paste() ;
233 virtual bool CanPaste() const ;
234 virtual void SetEditable(bool editable
) ;
235 virtual wxTextPos
GetLastPosition() const ;
236 virtual void Replace( long from
, long to
, const wxString
&str
) ;
237 virtual void Remove( long from
, long to
) ;
238 virtual void GetSelection( long* from
, long* to
) const ;
239 virtual void SetSelection( long from
, long to
) ;
241 virtual void WriteText(const wxString
& str
) ;
242 virtual bool HasOwnContextMenu() const
244 #if MAC_OS_X_VERSION_MAX_ALLOWED >= MAC_OS_X_VERSION_10_4
245 if ( UMAGetSystemVersion() >= 0x1040 )
247 TXNCommandEventSupportOptions options
;
248 TXNGetCommandEventSupport( m_txn
, & options
) ;
249 return options
& kTXNSupportEditCommandProcessing
;
255 virtual void Clear() ;
257 virtual bool CanUndo() const ;
258 virtual void Undo() ;
259 virtual bool CanRedo() const;
260 virtual void Redo() ;
261 virtual int GetNumberOfLines() const ;
262 virtual long XYToPosition(long x
, long y
) const ;
263 virtual bool PositionToXY(long pos
, long *x
, long *y
) const ;
264 virtual void ShowPosition( long pos
) ;
265 virtual int GetLineLength(long lineNo
) const ;
266 virtual wxString
GetLineText(long lineNo
) const ;
268 void SetTXNData( const wxString
& st
, TXNOffset start
, TXNOffset end
) ;
271 void TXNSetAttribute( const wxTextAttr
& style
, long from
, long to
) ;
275 #if TARGET_API_MAC_OSX
277 // implementation available under OSX
279 #if MAC_OS_X_VERSION_MAX_ALLOWED > MAC_OS_X_VERSION_10_2
281 class wxMacMLTEHIViewControl
: public wxMacMLTEControl
284 wxMacMLTEHIViewControl( wxTextCtrl
*wxPeer
,
287 const wxSize
& size
, long style
) ;
288 virtual OSStatus
SetFocus( ControlFocusPart focusPart
) ;
289 virtual bool HasFocus() const ;
290 virtual void SetBackground( const wxBrush
&brush
) ;
293 HIViewRef m_scrollView
;
294 HIViewRef m_textView
;
299 class wxMacUnicodeTextControl
: public wxMacTextControl
302 wxMacUnicodeTextControl( wxTextCtrl
*wxPeer
,
305 const wxSize
& size
, long style
) ;
306 ~wxMacUnicodeTextControl();
307 virtual void VisibilityChanged(bool shown
);
308 virtual wxString
GetStringValue() const ;
309 virtual void SetStringValue( const wxString
&str
) ;
312 virtual void Paste();
313 virtual bool CanPaste() const;
314 virtual void SetEditable(bool editable
) ;
315 virtual void GetSelection( long* from
, long* to
) const ;
316 virtual void SetSelection( long from
, long to
) ;
317 virtual void WriteText(const wxString
& str
) ;
320 // contains the tag for the content (is different for password and non-password controls)
326 // 'classic' MLTE implementation
328 class wxMacMLTEClassicControl
: public wxMacMLTEControl
331 wxMacMLTEClassicControl( wxTextCtrl
*wxPeer
,
334 const wxSize
& size
, long style
) ;
335 ~wxMacMLTEClassicControl() ;
336 virtual void VisibilityChanged(bool shown
) ;
337 virtual void SuperChangedPosition() ;
339 virtual void MacControlUserPaneDrawProc(wxInt16 part
) ;
340 virtual wxInt16
MacControlUserPaneHitTestProc(wxInt16 x
, wxInt16 y
) ;
341 virtual wxInt16
MacControlUserPaneTrackingProc(wxInt16 x
, wxInt16 y
, void* actionProc
) ;
342 virtual void MacControlUserPaneIdleProc() ;
343 virtual wxInt16
MacControlUserPaneKeyDownProc(wxInt16 keyCode
, wxInt16 charCode
, wxInt16 modifiers
) ;
344 virtual void MacControlUserPaneActivateProc(bool activating
) ;
345 virtual wxInt16
MacControlUserPaneFocusProc(wxInt16 action
) ;
346 virtual void MacControlUserPaneBackgroundProc(void* info
) ;
348 virtual bool SetupCursor( const wxPoint
& WXUNUSED(pt
) ) { MacControlUserPaneIdleProc() ; return true ;}
350 virtual void SetRect( Rect
*r
) ;
355 void MacUpdatePosition() ;
356 void MacActivatePaneText(Boolean setActive
) ;
357 void MacFocusPaneText(Boolean setFocus
) ;
359 void MacSetObjectVisibility(Boolean vis
) ;
362 TXNFrameID m_txnFrameID
;
364 WindowRef m_txnWindow
;
365 // bounds of the control as we last did set the txn frames
366 Rect m_txnControlBounds
;
367 Rect m_txnVisBounds
;
369 static pascal void TXNScrollInfoProc (SInt32 iValue
, SInt32 iMaximumValue
,
370 TXNScrollBarOrientation iScrollBarOrientation
, SInt32 iRefCon
) ;
371 static pascal void TXNScrollActionProc( ControlRef controlRef
, ControlPartCode partCode
) ;
372 ControlRef m_sbHorizontal
;
373 SInt32 m_lastHorizontalValue
;
374 ControlRef m_sbVertical
;
375 SInt32 m_lastVerticalValue
;
379 #define TE_UNLIMITED_LENGTH 0xFFFFFFFFUL
381 IMPLEMENT_DYNAMIC_CLASS(wxTextCtrl
, wxControl
)
383 BEGIN_EVENT_TABLE(wxTextCtrl
, wxControl
)
384 EVT_ERASE_BACKGROUND( wxTextCtrl::OnEraseBackground
)
385 EVT_DROP_FILES(wxTextCtrl::OnDropFiles
)
386 EVT_CHAR(wxTextCtrl::OnChar
)
387 EVT_MENU(wxID_CUT
, wxTextCtrl::OnCut
)
388 EVT_MENU(wxID_COPY
, wxTextCtrl::OnCopy
)
389 EVT_MENU(wxID_PASTE
, wxTextCtrl::OnPaste
)
390 EVT_MENU(wxID_UNDO
, wxTextCtrl::OnUndo
)
391 EVT_MENU(wxID_REDO
, wxTextCtrl::OnRedo
)
392 EVT_MENU(wxID_CLEAR
, wxTextCtrl::OnDelete
)
393 EVT_MENU(wxID_SELECTALL
, wxTextCtrl::OnSelectAll
)
395 EVT_CONTEXT_MENU(wxTextCtrl::OnContextMenu
)
397 EVT_UPDATE_UI(wxID_CUT
, wxTextCtrl::OnUpdateCut
)
398 EVT_UPDATE_UI(wxID_COPY
, wxTextCtrl::OnUpdateCopy
)
399 EVT_UPDATE_UI(wxID_PASTE
, wxTextCtrl::OnUpdatePaste
)
400 EVT_UPDATE_UI(wxID_UNDO
, wxTextCtrl::OnUpdateUndo
)
401 EVT_UPDATE_UI(wxID_REDO
, wxTextCtrl::OnUpdateRedo
)
402 EVT_UPDATE_UI(wxID_CLEAR
, wxTextCtrl::OnUpdateDelete
)
403 EVT_UPDATE_UI(wxID_SELECTALL
, wxTextCtrl::OnUpdateSelectAll
)
407 void wxTextCtrl::Init()
412 m_privateContextMenu
= NULL
;
414 m_maxLength
= TE_UNLIMITED_LENGTH
;
417 wxTextCtrl::~wxTextCtrl()
419 delete m_privateContextMenu
;
422 bool wxTextCtrl::Create(wxWindow
*parent
, wxWindowID id
,
425 const wxSize
& size
, long style
,
426 const wxValidator
& validator
,
427 const wxString
& name
)
429 m_macIsUserPane
= false ;
432 if ( ! ( style
& wxNO_BORDER
) )
433 style
= ( style
& ~wxBORDER_MASK
) | wxSUNKEN_BORDER
;
435 if ( !wxTextCtrlBase::Create(parent
, id
, pos
, size
, style
& ~(wxHSCROLL
|wxVSCROLL
), validator
, name
) )
438 if ( m_windowStyle
& wxTE_MULTILINE
)
440 wxASSERT_MSG( !(m_windowStyle
& wxTE_PROCESS_ENTER
),
441 wxT("wxTE_PROCESS_ENTER style is ignored for multiline text controls (they always process it)") );
443 m_windowStyle
|= wxTE_PROCESS_ENTER
;
444 style
|= wxTE_PROCESS_ENTER
;
447 bool forceMLTE
= false ;
448 #if wxUSE_SYSTEM_OPTIONS
449 if ( (wxSystemOptions::HasOption(wxMAC_TEXTCONTROL_USE_MLTE
) ) && ( wxSystemOptions::GetOptionInt( wxMAC_TEXTCONTROL_USE_MLTE
) == 1) )
456 #if MAC_OS_X_VERSION_MAX_ALLOWED > MAC_OS_X_VERSION_10_2
457 if ( UMAGetSystemVersion() >= 0x1030 && forceMLTE
== false )
459 if ( m_windowStyle
& wxTE_MULTILINE
)
460 m_peer
= new wxMacMLTEHIViewControl( this , str
, pos
, size
, style
) ;
465 if ( !(m_windowStyle
& wxTE_MULTILINE
) && forceMLTE
== false )
466 m_peer
= new wxMacUnicodeTextControl( this , str
, pos
, size
, style
) ;
471 m_peer
= new wxMacMLTEClassicControl( this , str
, pos
, size
, style
) ;
474 MacPostControlCreate(pos
,size
) ;
476 // only now the embedding is correct and we can do a positioning update
478 MacSuperChangedPosition() ;
480 if ( m_windowStyle
& wxTE_READONLY
)
481 SetEditable( false ) ;
483 SetCursor( wxCursor( wxCURSOR_IBEAM
) ) ;
488 void wxTextCtrl::MacSuperChangedPosition()
490 wxWindow::MacSuperChangedPosition() ;
491 GetPeer()->SuperChangedPosition() ;
494 void wxTextCtrl::MacVisibilityChanged()
496 GetPeer()->VisibilityChanged( MacIsReallyShown() ) ;
499 void wxTextCtrl::MacEnabledStateChanged()
503 wxString
wxTextCtrl::GetValue() const
505 return GetPeer()->GetStringValue() ;
508 void wxTextCtrl::GetSelection(long* from
, long* to
) const
510 GetPeer()->GetSelection( from
, to
) ;
513 void wxTextCtrl::SetValue(const wxString
& str
)
516 if ( GetValue() == str
)
519 GetPeer()->SetStringValue(str
) ;
521 wxCommandEvent
event(wxEVT_COMMAND_TEXT_UPDATED
, m_windowId
);
522 event
.SetString( GetValue() ) ;
523 event
.SetEventObject( this );
524 GetEventHandler()->ProcessEvent(event
);
527 void wxTextCtrl::SetMaxLength(unsigned long len
)
532 bool wxTextCtrl::SetFont( const wxFont
& font
)
534 if ( !wxTextCtrlBase::SetFont( font
) )
537 GetPeer()->SetFont( font
, GetForegroundColour() , GetWindowStyle() ) ;
541 bool wxTextCtrl::SetStyle(long start
, long end
, const wxTextAttr
& style
)
543 GetPeer()->SetStyle( start
, end
, style
) ;
547 bool wxTextCtrl::SetDefaultStyle(const wxTextAttr
& style
)
549 wxTextCtrlBase::SetDefaultStyle( style
) ;
550 SetStyle( kTXNUseCurrentSelection
, kTXNUseCurrentSelection
, GetDefaultStyle() ) ;
554 // Clipboard operations
555 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
599 // Can cut if there's a selection
601 GetSelection(& from
, & to
);
605 bool wxTextCtrl::CanPaste() const
610 return GetPeer()->CanPaste() ;
613 void wxTextCtrl::SetEditable(bool editable
)
615 if ( editable
!= m_editable
)
617 m_editable
= editable
;
618 GetPeer()->SetEditable( editable
) ;
622 void wxTextCtrl::SetInsertionPoint(long pos
)
624 SetSelection( pos
, pos
) ;
627 void wxTextCtrl::SetInsertionPointEnd()
629 wxTextPos pos
= GetLastPosition();
630 SetInsertionPoint(pos
);
633 long wxTextCtrl::GetInsertionPoint() const
636 GetSelection( &begin
, &end
) ;
640 wxTextPos
wxTextCtrl::GetLastPosition() const
642 return GetPeer()->GetLastPosition( ) ;
645 void wxTextCtrl::Replace(long from
, long to
, const wxString
& str
)
647 GetPeer()->Replace( from
, to
, str
) ;
650 void wxTextCtrl::Remove(long from
, long to
)
652 GetPeer()->Remove( from
, to
) ;
655 void wxTextCtrl::SetSelection(long from
, long to
)
657 GetPeer()->SetSelection( from
, to
) ;
660 bool wxTextCtrl::LoadFile(const wxString
& file
)
662 if ( wxTextCtrlBase::LoadFile(file
) )
668 void wxTextCtrl::WriteText(const wxString
& str
)
670 // TODO this MPRemoting will be moved into a remoting peer proxy for any command
671 if ( !wxIsMainThread() )
673 // unfortunately CW 8 is not able to correctly deduce the template types, so we have
674 // to instantiate explicitly
675 wxMacMPRemoteGUICall
<wxTextCtrl
,wxString
>( this , &wxTextCtrl::WriteText
, str
) ;
680 GetPeer()->WriteText( str
) ;
684 void wxTextCtrl::AppendText(const wxString
& text
)
686 SetInsertionPointEnd();
690 void wxTextCtrl::Clear()
695 bool wxTextCtrl::IsModified() const
700 bool wxTextCtrl::IsEditable() const
702 return IsEnabled() && m_editable
;
705 bool wxTextCtrl::AcceptsFocus() const
707 // we don't want focus if we can't be edited
708 return /*IsEditable() && */ wxControl::AcceptsFocus();
711 wxSize
wxTextCtrl::DoGetBestSize() const
717 // these are the numbers from the HIG:
718 // we reduce them by the borders first
720 switch( m_windowVariant
)
722 case wxWINDOW_VARIANT_NORMAL
:
726 case wxWINDOW_VARIANT_SMALL
:
730 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
)
744 if ( !HasFlag(wxNO_BORDER
) )
747 return wxSize(wText
, hText
);
750 // ----------------------------------------------------------------------------
752 // ----------------------------------------------------------------------------
754 void wxTextCtrl::Undo()
760 void wxTextCtrl::Redo()
766 bool wxTextCtrl::CanUndo() const
771 return GetPeer()->CanUndo() ;
774 bool wxTextCtrl::CanRedo() const
779 return GetPeer()->CanRedo() ;
782 void wxTextCtrl::MarkDirty()
787 void wxTextCtrl::DiscardEdits()
792 int wxTextCtrl::GetNumberOfLines() const
794 return GetPeer()->GetNumberOfLines() ;
797 long wxTextCtrl::XYToPosition(long x
, long y
) const
799 return GetPeer()->XYToPosition( x
, y
) ;
802 bool wxTextCtrl::PositionToXY(long pos
, long *x
, long *y
) const
804 return GetPeer()->PositionToXY(pos
, x
, y
) ;
807 void wxTextCtrl::ShowPosition(long pos
)
809 return GetPeer()->ShowPosition(pos
) ;
812 int wxTextCtrl::GetLineLength(long lineNo
) const
814 return GetPeer()->GetLineLength(lineNo
) ;
817 wxString
wxTextCtrl::GetLineText(long lineNo
) const
819 return GetPeer()->GetLineText(lineNo
) ;
822 void wxTextCtrl::Command(wxCommandEvent
& event
)
824 SetValue (event
.GetString());
825 ProcessCommand (event
);
828 void wxTextCtrl::OnDropFiles(wxDropFilesEvent
& event
)
830 // By default, load the first file into the text window.
831 if (event
.GetNumberOfFiles() > 0)
832 LoadFile(event
.GetFiles()[0]);
835 void wxTextCtrl::OnEraseBackground(wxEraseEvent
& event
)
837 // all erasing should be done by the real mac control implementation
838 // while this is true for MLTE under classic, the HITextView is somehow
839 // transparent but background erase is not working correctly, so intercept
840 // things while we can...
844 void wxTextCtrl::OnChar(wxKeyEvent
& event
)
846 int key
= event
.GetKeyCode() ;
847 bool eat_key
= false ;
849 if ( key
== 'c' && event
.MetaDown() )
856 if ( !IsEditable() && key
!= WXK_LEFT
&& key
!= WXK_RIGHT
&& key
!= WXK_DOWN
&& key
!= WXK_UP
&& key
!= WXK_TAB
&&
857 !( key
== WXK_RETURN
&& ( (m_windowStyle
& wxPROCESS_ENTER
) || (m_windowStyle
& wxTE_MULTILINE
) ) )
858 /* && key != WXK_PRIOR && key != WXK_NEXT && key != WXK_HOME && key != WXK_END */
865 // Check if we have reached the max # of chars, but still allow navigation and deletion
866 if ( !IsMultiLine() && GetValue().Length() >= m_maxLength
&&
867 key
!= WXK_LEFT
&& key
!= WXK_RIGHT
&& key
!= WXK_TAB
&&
868 key
!= WXK_BACK
&& !( key
== WXK_RETURN
&& (m_windowStyle
& wxPROCESS_ENTER
) )
871 // eat it, we don't want to add more than allowed # of characters
875 // assume that any key not processed yet is going to modify the control
878 if ( key
== 'v' && event
.MetaDown() )
884 if ( key
== 'x' && event
.MetaDown() )
894 if (m_windowStyle
& wxPROCESS_ENTER
)
896 wxCommandEvent
event(wxEVT_COMMAND_TEXT_ENTER
, m_windowId
);
897 event
.SetEventObject( this );
898 event
.SetString( GetValue() );
899 if ( GetEventHandler()->ProcessEvent(event
) )
902 if ( !(m_windowStyle
& wxTE_MULTILINE
) )
904 wxWindow
*parent
= GetParent();
905 while( parent
&& !parent
->IsTopLevel() && parent
->GetDefaultItem() == NULL
) {
906 parent
= parent
->GetParent() ;
908 if ( parent
&& parent
->GetDefaultItem() )
910 wxButton
*def
= wxDynamicCast(parent
->GetDefaultItem(),
912 if ( def
&& def
->IsEnabled() )
914 wxCommandEvent
event(wxEVT_COMMAND_BUTTON_CLICKED
, def
->GetId() );
915 event
.SetEventObject(def
);
921 // this will make wxWidgets eat the ENTER key so that
922 // we actually prevent line wrapping in a single line
929 if ( !(m_windowStyle
& wxTE_PROCESS_TAB
))
932 if (!event
.ShiftDown())
933 flags
|= wxNavigationKeyEvent::IsForward
;
934 if (event
.ControlDown())
935 flags
|= wxNavigationKeyEvent::WinChange
;
941 // This is necessary (don't know why) or the tab will not
943 WriteText(wxT("\t"));
953 // perform keystroke handling
954 if ( wxTheApp
->MacGetCurrentEvent() != NULL
&& wxTheApp
->MacGetCurrentEventHandlerCallRef() != NULL
)
955 CallNextEventHandler((EventHandlerCallRef
)wxTheApp
->MacGetCurrentEventHandlerCallRef() , (EventRef
) wxTheApp
->MacGetCurrentEvent() ) ;
959 if ( wxMacConvertEventToRecord( (EventRef
) wxTheApp
->MacGetCurrentEvent() , &rec
) )
961 EventRecord
*ev
= &rec
;
964 keychar
= short(ev
->message
& charCodeMask
);
965 keycode
= short(ev
->message
& keyCodeMask
) >> 8 ;
967 m_peer
->HandleKey( keycode
, keychar
, ev
->modifiers
) ;
972 if ( ( key
>= 0x20 && key
< WXK_START
) ||
977 wxCommandEvent
event1(wxEVT_COMMAND_TEXT_UPDATED
, m_windowId
);
978 event1
.SetEventObject( this );
979 wxPostEvent(GetEventHandler(),event1
);
983 // ----------------------------------------------------------------------------
984 // standard handlers for standard edit menu events
985 // ----------------------------------------------------------------------------
987 void wxTextCtrl::OnCut(wxCommandEvent
& WXUNUSED(event
))
992 void wxTextCtrl::OnCopy(wxCommandEvent
& WXUNUSED(event
))
997 void wxTextCtrl::OnPaste(wxCommandEvent
& WXUNUSED(event
))
1002 void wxTextCtrl::OnUndo(wxCommandEvent
& WXUNUSED(event
))
1007 void wxTextCtrl::OnRedo(wxCommandEvent
& WXUNUSED(event
))
1012 void wxTextCtrl::OnDelete(wxCommandEvent
& WXUNUSED(event
))
1015 GetSelection(& from
, & to
);
1016 if (from
!= -1 && to
!= -1)
1020 void wxTextCtrl::OnSelectAll(wxCommandEvent
& WXUNUSED(event
))
1022 SetSelection(-1, -1);
1025 void wxTextCtrl::OnUpdateCut(wxUpdateUIEvent
& event
)
1027 event
.Enable( CanCut() );
1030 void wxTextCtrl::OnUpdateCopy(wxUpdateUIEvent
& event
)
1032 event
.Enable( CanCopy() );
1035 void wxTextCtrl::OnUpdatePaste(wxUpdateUIEvent
& event
)
1037 event
.Enable( CanPaste() );
1040 void wxTextCtrl::OnUpdateUndo(wxUpdateUIEvent
& event
)
1042 event
.Enable( CanUndo() );
1045 void wxTextCtrl::OnUpdateRedo(wxUpdateUIEvent
& event
)
1047 event
.Enable( CanRedo() );
1050 void wxTextCtrl::OnUpdateDelete(wxUpdateUIEvent
& event
)
1053 GetSelection(& from
, & to
);
1054 event
.Enable(from
!= -1 && to
!= -1 && from
!= to
&& IsEditable()) ;
1057 void wxTextCtrl::OnUpdateSelectAll(wxUpdateUIEvent
& event
)
1059 event
.Enable(GetLastPosition() > 0);
1062 // CS: Context Menus only work with MLTE implementations or non-multiline HIViews at the moment
1064 void wxTextCtrl::OnContextMenu(wxContextMenuEvent
& event
)
1066 if ( GetPeer()->HasOwnContextMenu() )
1072 if (m_privateContextMenu
== NULL
)
1074 m_privateContextMenu
= new wxMenu
;
1075 m_privateContextMenu
->Append(wxID_UNDO
, _("&Undo"));
1076 m_privateContextMenu
->Append(wxID_REDO
, _("&Redo"));
1077 m_privateContextMenu
->AppendSeparator();
1078 m_privateContextMenu
->Append(wxID_CUT
, _("Cu&t"));
1079 m_privateContextMenu
->Append(wxID_COPY
, _("&Copy"));
1080 m_privateContextMenu
->Append(wxID_PASTE
, _("&Paste"));
1081 m_privateContextMenu
->Append(wxID_CLEAR
, _("&Delete"));
1082 m_privateContextMenu
->AppendSeparator();
1083 m_privateContextMenu
->Append(wxID_SELECTALL
, _("Select &All"));
1086 if (m_privateContextMenu
!= NULL
)
1087 PopupMenu(m_privateContextMenu
);
1090 bool wxTextCtrl::MacSetupCursor( const wxPoint
& pt
)
1092 if ( !GetPeer()->SetupCursor(pt
) )
1093 return wxWindow::MacSetupCursor( pt
) ;
1098 #if !TARGET_API_MAC_OSX
1100 // user pane implementation
1102 void wxTextCtrl::MacControlUserPaneDrawProc(wxInt16 part
)
1104 GetPeer()->MacControlUserPaneDrawProc( part
) ;
1107 wxInt16
wxTextCtrl::MacControlUserPaneHitTestProc(wxInt16 x
, wxInt16 y
)
1109 return GetPeer()->MacControlUserPaneHitTestProc( x
, y
) ;
1112 wxInt16
wxTextCtrl::MacControlUserPaneTrackingProc(wxInt16 x
, wxInt16 y
, void* actionProc
)
1114 return GetPeer()->MacControlUserPaneTrackingProc( x
, y
, actionProc
) ;
1117 void wxTextCtrl::MacControlUserPaneIdleProc()
1119 GetPeer()->MacControlUserPaneIdleProc( ) ;
1122 wxInt16
wxTextCtrl::MacControlUserPaneKeyDownProc(wxInt16 keyCode
, wxInt16 charCode
, wxInt16 modifiers
)
1124 return GetPeer()->MacControlUserPaneKeyDownProc( keyCode
, charCode
, modifiers
) ;
1127 void wxTextCtrl::MacControlUserPaneActivateProc(bool activating
)
1129 GetPeer()->MacControlUserPaneActivateProc( activating
) ;
1132 wxInt16
wxTextCtrl::MacControlUserPaneFocusProc(wxInt16 action
)
1134 return GetPeer()->MacControlUserPaneFocusProc( action
) ;
1137 void wxTextCtrl::MacControlUserPaneBackgroundProc(void* info
)
1139 GetPeer()->MacControlUserPaneBackgroundProc( info
) ;
1144 // ----------------------------------------------------------------------------
1145 // implementation base class
1146 // ----------------------------------------------------------------------------
1148 wxMacTextControl::wxMacTextControl(wxTextCtrl
* peer
) :
1149 wxMacControl( peer
)
1153 wxMacTextControl::~wxMacTextControl()
1157 void wxMacTextControl::SetStyle(long start
, long end
, const wxTextAttr
& style
)
1161 void wxMacTextControl::Copy()
1165 void wxMacTextControl::Cut()
1169 void wxMacTextControl::Paste()
1173 bool wxMacTextControl::CanPaste() const
1178 void wxMacTextControl::SetEditable(bool editable
)
1182 wxTextPos
wxMacTextControl::GetLastPosition() const
1184 return GetStringValue().Length() ;
1187 void wxMacTextControl::Replace( long from
, long to
, const wxString
&val
)
1189 SetSelection( from
, to
) ;
1193 void wxMacTextControl::Remove( long from
, long to
)
1195 SetSelection( from
, to
) ;
1196 WriteText( wxEmptyString
) ;
1199 void wxMacTextControl::Clear()
1201 SetStringValue( wxEmptyString
) ;
1204 bool wxMacTextControl::CanUndo() const
1209 void wxMacTextControl::Undo()
1213 bool wxMacTextControl::CanRedo() const
1218 void wxMacTextControl::Redo()
1222 long wxMacTextControl::XYToPosition(long x
, long y
) const
1227 bool wxMacTextControl::PositionToXY(long pos
, long *x
, long *y
) const
1232 void wxMacTextControl::ShowPosition( long WXUNUSED(pos
) )
1236 int wxMacTextControl::GetNumberOfLines() const
1238 ItemCount lines
= 0 ;
1239 wxString content
= GetStringValue() ;
1241 for (size_t i
= 0; i
< content
.Length() ; i
++)
1243 if (content
[i
] == '\r') lines
++;
1249 wxString
wxMacTextControl::GetLineText(long lineNo
) const
1251 // TODO change this if possible to reflect real lines
1252 wxString content
= GetStringValue() ;
1256 for (size_t i
= 0; i
< content
.Length() ; i
++)
1258 if (count
== lineNo
)
1260 // Add chars in line then
1263 for (size_t j
= i
; j
< content
.Length(); j
++)
1265 if (content
[j
] == '\n')
1274 if (content
[i
] == '\n') count
++;
1277 return wxEmptyString
;
1280 int wxMacTextControl::GetLineLength(long lineNo
) const
1282 // TODO change this if possible to reflect real lines
1283 wxString content
= GetStringValue() ;
1287 for (size_t i
= 0; i
< content
.Length() ; i
++)
1289 if (count
== lineNo
)
1291 // Count chars in line then
1293 for (size_t j
= i
; j
< content
.Length(); j
++)
1296 if (content
[j
] == '\n')
1303 if (content
[i
] == '\n') count
++;
1309 // ----------------------------------------------------------------------------
1310 // standard unicode control implementation
1311 // ----------------------------------------------------------------------------
1313 #if TARGET_API_MAC_OSX
1315 wxMacUnicodeTextControl::wxMacUnicodeTextControl( wxTextCtrl
*wxPeer
,
1316 const wxString
& str
,
1318 const wxSize
& size
, long style
) : wxMacTextControl( wxPeer
)
1320 m_font
= wxPeer
->GetFont() ;
1321 m_windowStyle
= style
;
1322 Rect bounds
= wxMacGetBoundsForControl( wxPeer
, pos
, size
) ;
1324 wxMacConvertNewlines10To13( &st
) ;
1325 wxMacCFStringHolder
cf(st
, m_font
.GetEncoding()) ;
1326 CFStringRef cfr
= cf
;
1327 Boolean isPassword
= ( m_windowStyle
& wxTE_PASSWORD
) != 0 ;
1328 m_valueTag
= isPassword
? kControlEditTextPasswordCFStringTag
: kControlEditTextCFStringTag
;
1329 CreateEditUnicodeTextControl( MAC_WXHWND(wxPeer
->MacGetTopLevelWindowRef()), &bounds
, cfr
, isPassword
, NULL
, &m_controlRef
) ;
1331 if ( !(m_windowStyle
& wxTE_MULTILINE
) )
1332 SetData
<Boolean
>( kControlEditTextPart
, kControlEditTextSingleLineTag
, true ) ;
1335 wxMacUnicodeTextControl::~wxMacUnicodeTextControl()
1339 void wxMacUnicodeTextControl::VisibilityChanged(bool shown
)
1341 if ( !(m_windowStyle
& wxTE_MULTILINE
) && shown
)
1343 // work around a refresh issue insofar as not always the entire content is shown even if this would be possible
1344 ControlEditTextSelectionRec sel
;
1345 CFStringRef value
= NULL
;
1347 verify_noerr( GetData
<ControlEditTextSelectionRec
>( 0, kControlEditTextSelectionTag
, &sel
) );
1348 verify_noerr( GetData
<CFStringRef
>( 0, m_valueTag
, &value
) );
1349 verify_noerr( SetData
<CFStringRef
>( 0, m_valueTag
, &value
) );
1350 verify_noerr( SetData
<ControlEditTextSelectionRec
>( 0, kControlEditTextSelectionTag
, &sel
) );
1352 CFRelease( value
) ;
1356 wxString
wxMacUnicodeTextControl::GetStringValue() const
1359 CFStringRef value
= GetData
<CFStringRef
>(0,m_valueTag
) ;
1362 wxMacCFStringHolder
cf(value
) ;
1363 result
= cf
.AsString() ;
1367 wxMacConvertNewlines13To10( &result
) ;
1369 wxMacConvertNewlines10To13( &result
) ;
1375 void wxMacUnicodeTextControl::SetStringValue( const wxString
&str
)
1378 wxMacConvertNewlines10To13( &st
) ;
1379 wxMacCFStringHolder
cf(st
, m_font
.GetEncoding() ) ;
1380 verify_noerr( SetData
<CFStringRef
>( 0, m_valueTag
, cf
) ) ;
1383 void wxMacUnicodeTextControl::Copy()
1385 SendHICommand( kHICommandCopy
) ;
1388 void wxMacUnicodeTextControl::Cut()
1390 SendHICommand( kHICommandCut
) ;
1393 void wxMacUnicodeTextControl::Paste()
1395 SendHICommand( kHICommandPaste
) ;
1398 bool wxMacUnicodeTextControl::CanPaste() const
1403 void wxMacUnicodeTextControl::SetEditable(bool editable
)
1405 SetData
<Boolean
>( 0 , kControlEditTextLockedTag
, (Boolean
) !editable
) ;
1408 void wxMacUnicodeTextControl::GetSelection( long* from
, long* to
) const
1410 ControlEditTextSelectionRec sel
;
1411 verify_noerr(GetData
<ControlEditTextSelectionRec
>( 0, kControlEditTextSelectionTag
, &sel
) ) ;
1412 if ( from
) *from
= sel
.selStart
;
1413 if ( to
) *to
= sel
.selEnd
;
1416 void wxMacUnicodeTextControl::SetSelection( long from
, long to
)
1418 ControlEditTextSelectionRec sel
;
1419 if ((from
== -1) && (to
== -1))
1422 to
= 32767 ; // sel has 16 bit signed values, max is 32767
1425 sel
.selStart
= from
;
1427 SetData
<ControlEditTextSelectionRec
>( 0 , kControlEditTextSelectionTag
, &sel
) ;
1430 void wxMacUnicodeTextControl::WriteText(const wxString
& str
)
1433 wxMacConvertNewlines10To13( &st
) ;
1434 #if MAC_OS_X_VERSION_MAX_ALLOWED > MAC_OS_X_VERSION_10_2
1435 wxMacCFStringHolder
cf(st
, m_font
.GetEncoding() ) ;
1436 CFStringRef value
= cf
;
1437 SetData
<CFStringRef
>( 0, kControlEditTextInsertCFStringRefTag
, &value
);
1439 wxString val
= GetStringValue() ;
1441 GetSelection( &start
, &end
) ;
1442 val
.Remove( start
, end
- start
) ;
1443 val
.insert( start
, str
) ;
1444 SetStringValue( val
) ;
1445 SetSelection( start
+ str
.Length() , start
+ str
.Length() ) ;
1451 // ----------------------------------------------------------------------------
1452 // MLTE control implementation (common part)
1453 // ----------------------------------------------------------------------------
1455 // if MTLE is read only, no changes at all are allowed, not even from
1456 // procedural API, in order to allow changes via API all the same we must undo
1457 // the readonly status while we are executing, this class helps to do so
1459 class wxMacEditHelper
1462 wxMacEditHelper( TXNObject txn
)
1464 TXNControlTag tag
[] = { kTXNIOPrivilegesTag
} ;
1466 TXNGetTXNObjectControls( m_txn
, 1 , tag
, m_data
) ;
1467 if ( m_data
[0].uValue
== kTXNReadOnly
)
1469 TXNControlData data
[] = { { kTXNReadWrite
} } ;
1470 TXNSetTXNObjectControls( m_txn
, false , 1 , tag
, data
) ;
1476 TXNControlTag tag
[] = { kTXNIOPrivilegesTag
} ;
1477 if ( m_data
[0].uValue
== kTXNReadOnly
)
1478 TXNSetTXNObjectControls( m_txn
, false , 1 , tag
, m_data
) ;
1483 TXNControlData m_data
[1] ;
1486 wxMacMLTEControl::wxMacMLTEControl( wxTextCtrl
*peer
) : wxMacTextControl( peer
)
1488 SetNeedsFocusRect( true ) ;
1491 wxString
wxMacMLTEControl::GetStringValue() const
1495 Size actualSize
= 0;
1499 err
= TXNGetDataEncoded( m_txn
, kTXNStartOffset
, kTXNEndOffset
, &theText
, kTXNUnicodeTextData
);
1507 actualSize
= GetHandleSize( theText
) / sizeof( UniChar
) ;
1508 if ( actualSize
> 0 )
1510 wxChar
*ptr
= NULL
;
1511 #if SIZEOF_WCHAR_T == 2
1512 ptr
= new wxChar
[actualSize
+ 1 ] ;
1513 wxStrncpy( ptr
, (wxChar
*) *theText
, actualSize
) ;
1515 SetHandleSize( theText
, ( actualSize
+ 1 ) * sizeof( UniChar
) ) ;
1517 (((UniChar
*)*theText
)[actualSize
]) = 0 ;
1518 wxMBConvUTF16 converter
;
1519 size_t noChars
= converter
.MB2WC( NULL
, (const char*)*theText
, 0 ) ;
1520 ptr
= new wxChar
[noChars
+ 1] ;
1522 noChars
= converter
.MB2WC( ptr
, (const char*)*theText
, noChars
) ;
1524 HUnlock( theText
) ;
1526 ptr
[actualSize
] = 0 ;
1527 result
= wxString( ptr
) ;
1531 DisposeHandle( theText
) ;
1535 err
= TXNGetDataEncoded( m_txn
, kTXNStartOffset
, kTXNEndOffset
, &theText
, kTXNTextData
);
1543 actualSize
= GetHandleSize( theText
) ;
1544 if ( actualSize
> 0 )
1547 result
= wxString( *theText
, wxConvLocal
, actualSize
) ;
1548 HUnlock( theText
) ;
1551 DisposeHandle( theText
) ;
1557 wxMacConvertNewlines13To10( &result
) ;
1559 wxMacConvertNewlines10To13( &result
) ;
1565 void wxMacMLTEControl::SetStringValue( const wxString
&str
)
1569 wxMacConvertNewlines10To13( &st
) ;
1571 wxMacWindowClipper
c( m_peer
) ;
1573 wxMacEditHelper
help(m_txn
) ;
1574 SetTXNData( st
, kTXNStartOffset
, kTXNEndOffset
) ;
1576 TXNSetSelection( m_txn
, 0, 0);
1577 TXNShowSelection( m_txn
, kTXNShowStart
);
1581 TXNFrameOptions
wxMacMLTEControl::FrameOptionsFromWXStyle( long wxStyle
)
1583 TXNFrameOptions frameOptions
=
1584 kTXNDontDrawCaretWhenInactiveMask
1585 #if MAC_OS_X_VERSION_MAX_ALLOWED >= MAC_OS_X_VERSION_10_3
1586 | kTXNDoFontSubstitutionMask
1590 if ( ! ( wxStyle
& wxTE_NOHIDESEL
) )
1591 frameOptions
|= kTXNDontDrawSelectionWhenInactiveMask
;
1593 if ( wxStyle
& wxTE_MULTILINE
)
1595 if ( ! ( wxStyle
& wxTE_DONTWRAP
) )
1596 frameOptions
|= kTXNAlwaysWrapAtViewEdgeMask
;
1599 frameOptions
|= kTXNAlwaysWrapAtViewEdgeMask
;
1600 frameOptions
|= kTXNWantHScrollBarMask
;
1603 if ( !(wxStyle
& wxTE_NO_VSCROLL
) )
1605 frameOptions
|= kTXNWantVScrollBarMask
;
1606 if ( frameOptions
& kTXNWantHScrollBarMask
)
1607 frameOptions
|= kTXNDrawGrowIconMask
;
1611 frameOptions
|= kTXNSingleLineOnlyMask
;
1613 if ( wxStyle
& wxHSCROLL
)
1614 frameOptions
|= kTXNWantHScrollBarMask
;
1616 return frameOptions
;
1619 void wxMacMLTEControl::AdjustCreationAttributes( const wxColour
&background
, bool visible
)
1621 TXNControlTag iControlTags
[] =
1623 kTXNDoFontSubstitution
,
1624 kTXNWordWrapStateTag
,
1626 TXNControlData iControlData
[] =
1632 int toptag
= WXSIZEOF( iControlTags
) ;
1634 if ( m_windowStyle
& wxTE_MULTILINE
)
1636 if (m_windowStyle
& wxTE_DONTWRAP
)
1637 iControlData
[1].uValue
= kTXNNoAutoWrap
;
1639 iControlData
[1].uValue
= kTXNAutoWrap
;
1641 verify_noerr( TXNSetTXNObjectControls( m_txn
, false, toptag
,
1642 iControlTags
, iControlData
)) ;
1644 // setting the default font
1645 // under 10.2 this causes a visible caret, therefore we avoid it
1647 if ( UMAGetSystemVersion() >= 0x1030 )
1653 GetThemeFont(kThemeSystemFont
, GetApplicationScript() , fontName
, &fontSize
, &fontStyle
) ;
1655 TXNTypeAttributes typeAttr
[] =
1657 { kTXNQDFontNameAttribute
, kTXNQDFontNameAttributeSize
, { (void*) fontName
} } ,
1658 { kTXNQDFontSizeAttribute
, kTXNFontSizeAttributeSize
, { (void*) (fontSize
<< 16) } } ,
1659 { kTXNQDFontStyleAttribute
, kTXNQDFontStyleAttributeSize
, { (void*) normal
} } ,
1662 verify_noerr( TXNSetTypeAttributes (m_txn
, sizeof( typeAttr
) / sizeof(TXNTypeAttributes
) , typeAttr
,
1667 if ( m_windowStyle
& wxTE_PASSWORD
)
1670 verify_noerr(TXNEchoMode( m_txn
, c
, 0 , true )) ;
1673 TXNBackground tback
;
1674 tback
.bgType
= kTXNBackgroundTypeRGB
;
1675 tback
.bg
.color
= MAC_WXCOLORREF( background
.GetPixel() );
1676 TXNSetBackground( m_txn
, &tback
);
1678 #if MAC_OS_X_VERSION_MAX_ALLOWED >= MAC_OS_X_VERSION_10_4
1679 if ( UMAGetSystemVersion() >= 0x1040 )
1681 TXNCommandEventSupportOptions options
;
1682 if ( TXNGetCommandEventSupport( m_txn
, &options
) == noErr
)
1684 options
|= kTXNSupportEditCommandProcessing
;
1685 options
|= kTXNSupportSpellCheckCommandProcessing
;
1686 options
|= kTXNSupportFontCommandProcessing
;
1687 options
|= kTXNSupportFontCommandUpdating
;
1689 TXNSetCommandEventSupport( m_txn
, options
) ;
1695 void wxMacMLTEControl::SetBackground( const wxBrush
&brush
)
1697 // currently only solid background are supported
1698 TXNBackground tback
;
1699 tback
.bgType
= kTXNBackgroundTypeRGB
;
1700 tback
.bg
.color
= MAC_WXCOLORREF( brush
.GetColour().GetPixel() );
1701 TXNSetBackground( m_txn
, &tback
);
1704 void wxMacMLTEControl::TXNSetAttribute( const wxTextAttr
& style
, long from
, long to
)
1706 TXNTypeAttributes typeAttr
[4] ;
1707 Str255 fontName
= "\pMonaco" ;
1708 SInt16 fontSize
= 12 ;
1709 Style fontStyle
= normal
;
1711 int attrCounter
= 0 ;
1712 if ( style
.HasFont() )
1714 const wxFont
&font
= style
.GetFont() ;
1715 wxMacStringToPascal( font
.GetFaceName() , fontName
) ;
1716 fontSize
= font
.GetPointSize() ;
1717 if ( font
.GetUnderlined() )
1718 fontStyle
|= underline
;
1719 if ( font
.GetWeight() == wxBOLD
)
1721 if ( font
.GetStyle() == wxITALIC
)
1722 fontStyle
|= italic
;
1724 typeAttr
[attrCounter
].tag
= kTXNQDFontNameAttribute
;
1725 typeAttr
[attrCounter
].size
= kTXNQDFontNameAttributeSize
;
1726 typeAttr
[attrCounter
].data
.dataPtr
= (void*) fontName
;
1727 typeAttr
[attrCounter
+1].tag
= kTXNQDFontSizeAttribute
;
1728 typeAttr
[attrCounter
+1].size
= kTXNFontSizeAttributeSize
;
1729 typeAttr
[attrCounter
+1].data
.dataValue
= (fontSize
<< 16) ;
1730 typeAttr
[attrCounter
+2].tag
= kTXNQDFontStyleAttribute
;
1731 typeAttr
[attrCounter
+2].size
= kTXNQDFontStyleAttributeSize
;
1732 typeAttr
[attrCounter
+2].data
.dataValue
= fontStyle
;
1735 if ( style
.HasTextColour() )
1737 typeAttr
[attrCounter
].tag
= kTXNQDFontColorAttribute
;
1738 typeAttr
[attrCounter
].size
= kTXNQDFontColorAttributeSize
;
1739 typeAttr
[attrCounter
].data
.dataPtr
= (void*) &color
;
1740 color
= MAC_WXCOLORREF(style
.GetTextColour().GetPixel()) ;
1743 if ( attrCounter
> 0 )
1745 verify_noerr( TXNSetTypeAttributes ( m_txn
, attrCounter
, typeAttr
, from
, to
) );
1749 void wxMacMLTEControl::SetFont( const wxFont
& font
, const wxColour
& foreground
, long windowStyle
)
1751 wxMacEditHelper
help(m_txn
) ;
1752 TXNSetAttribute( wxTextAttr(foreground
,wxNullColour
,font
) , kTXNStartOffset
,kTXNEndOffset
) ;
1755 void wxMacMLTEControl::SetStyle(long start
, long end
, const wxTextAttr
& style
)
1757 wxMacEditHelper
help(m_txn
) ;
1758 TXNSetAttribute( style
, start
,end
) ;
1761 void wxMacMLTEControl::Copy()
1763 ClearCurrentScrap();
1765 TXNConvertToPublicScrap();
1768 void wxMacMLTEControl::Cut()
1770 ClearCurrentScrap();
1772 TXNConvertToPublicScrap();
1775 void wxMacMLTEControl::Paste()
1777 TXNConvertFromPublicScrap();
1781 bool wxMacMLTEControl::CanPaste() const
1783 return TXNIsScrapPastable() ;
1786 void wxMacMLTEControl::SetEditable(bool editable
)
1788 TXNControlTag tag
[] = { kTXNIOPrivilegesTag
} ;
1789 TXNControlData data
[] = { { editable
? kTXNReadWrite
: kTXNReadOnly
} } ;
1790 TXNSetTXNObjectControls( m_txn
, false , WXSIZEOF(tag
) , tag
, data
) ;
1793 wxTextPos
wxMacMLTEControl::GetLastPosition() const
1795 wxTextPos actualsize
= 0 ;
1798 OSErr err
= TXNGetDataEncoded( m_txn
, kTXNStartOffset
, kTXNEndOffset
, &theText
, kTXNTextData
);
1806 actualsize
= GetHandleSize( theText
) ;
1807 DisposeHandle( theText
) ;
1813 void wxMacMLTEControl::Replace( long from
, long to
, const wxString
&str
)
1815 wxString value
= str
;
1816 wxMacConvertNewlines10To13( &value
) ;
1818 wxMacEditHelper
help( m_txn
) ;
1819 wxMacWindowClipper
c( m_peer
) ;
1821 TXNSetSelection(m_txn
, from
, to
) ;
1823 SetTXNData( value
, kTXNUseCurrentSelection
, kTXNUseCurrentSelection
) ;
1826 void wxMacMLTEControl::Remove( long from
, long to
)
1828 wxMacWindowClipper
c( m_peer
) ;
1829 wxMacEditHelper
help( m_txn
) ;
1830 TXNSetSelection(m_txn
, from
, to
) ;
1834 void wxMacMLTEControl::GetSelection( long* from
, long* to
) const
1836 TXNGetSelection( m_txn
, (TXNOffset
*) from
, (TXNOffset
*) to
) ;
1839 void wxMacMLTEControl::SetSelection( long from
, long to
)
1841 wxMacWindowClipper
c( m_peer
) ;
1842 /* change the selection */
1843 if ((from
== -1) && (to
== -1))
1844 TXNSelectAll(m_txn
);
1846 TXNSetSelection( m_txn
, from
, to
);
1847 TXNShowSelection( m_txn
, kTXNShowStart
);
1850 void wxMacMLTEControl::WriteText(const wxString
& str
)
1853 wxMacConvertNewlines10To13( &st
) ;
1855 long start
, end
, dummy
;
1856 GetSelection( &start
, &dummy
) ;
1857 wxMacWindowClipper
c( m_peer
) ;
1859 wxMacEditHelper
helper( m_txn
) ;
1860 SetTXNData( st
, kTXNUseCurrentSelection
, kTXNUseCurrentSelection
) ;
1863 GetSelection( &dummy
, &end
) ;
1864 // TODO SetStyle( start , end , GetDefaultStyle() ) ;
1867 void wxMacMLTEControl::Clear()
1869 wxMacWindowClipper
c( m_peer
) ;
1870 wxMacEditHelper
st(m_txn
) ;
1871 TXNSetSelection( m_txn
, kTXNStartOffset
, kTXNEndOffset
) ;
1875 bool wxMacMLTEControl::CanUndo() const
1877 return TXNCanUndo( m_txn
, NULL
) ;
1880 void wxMacMLTEControl::Undo()
1885 bool wxMacMLTEControl::CanRedo() const
1887 return TXNCanRedo( m_txn
, NULL
) ;
1890 void wxMacMLTEControl::Redo()
1895 int wxMacMLTEControl::GetNumberOfLines() const
1897 ItemCount lines
= 0 ;
1898 TXNGetLineCount(m_txn
, &lines
) ;
1902 long wxMacMLTEControl::XYToPosition(long x
, long y
) const
1906 wxTextPos lastpos
= GetLastPosition() ;
1908 // TODO find a better implementation : while we can get the
1909 // line metrics of a certain line, we don't get its starting
1910 // position, so it would probably be rather a binary search
1911 // for the start position
1914 int lastHeight
= 0 ;
1917 for ( n
= 0 ; n
<= (ItemCount
) lastpos
; ++n
)
1919 if ( y
== ypos
&& x
== xpos
)
1922 TXNOffsetToPoint( m_txn
, n
, &curpt
);
1924 if ( curpt
.v
> lastHeight
)
1929 lastHeight
= curpt
.v
;
1938 bool wxMacMLTEControl::PositionToXY(long pos
, long *x
, long *y
) const
1942 wxTextPos lastpos
= GetLastPosition() ;
1947 if ( pos
<= lastpos
)
1949 // TODO find a better implementation : while we can get the
1950 // line metrics of a certain line, we don't get its starting
1951 // position, so it would probably be rather a binary search
1952 // for the start position
1955 int lastHeight
= 0 ;
1958 for ( n
= 0 ; n
<= (ItemCount
) pos
; ++n
)
1960 TXNOffsetToPoint(m_txn
, n
, &curpt
);
1962 if ( curpt
.v
> lastHeight
)
1967 lastHeight
= curpt
.v
;
1973 if ( y
) *y
= ypos
;
1974 if ( x
) *x
= xpos
;
1980 void wxMacMLTEControl::ShowPosition( long pos
)
1982 #if TARGET_RT_MAC_MACHO && defined(AVAILABLE_MAC_OS_X_VERSION_10_2_AND_LATER)
1986 TXNOffset selstart
, selend
;
1987 TXNGetSelection( m_txn
, &selstart
, &selend
) ;
1988 TXNOffsetToPoint( m_txn
, selstart
, ¤t
);
1989 TXNOffsetToPoint( m_txn
, pos
, &desired
);
1990 //TODO use HIPoints for 10.3 and above
1991 if ( (UInt32
) TXNScroll
!= (UInt32
) kUnresolvedCFragSymbolAddress
)
1993 OSErr theErr
= noErr
;
1994 SInt32 dv
= desired
.v
- current
.v
;
1995 SInt32 dh
= desired
.h
- current
.h
;
1996 TXNShowSelection( m_txn
, true ) ;
1997 theErr
= TXNScroll( m_txn
, kTXNScrollUnitsInPixels
, kTXNScrollUnitsInPixels
, &dv
, &dh
);
1998 // there will be an error returned for classic mlte implementation when the control is
1999 // invisible, but HITextView works correctly, so we don't assert that one
2000 // wxASSERT_MSG( theErr == noErr, _T("TXNScroll returned an error!") );
2006 void wxMacMLTEControl::SetTXNData( const wxString
& st
, TXNOffset start
, TXNOffset end
)
2009 #if SIZEOF_WCHAR_T == 2
2010 size_t len
= st
.Len() ;
2011 TXNSetData( m_txn
, kTXNUnicodeTextData
, (void*)st
.wc_str(), len
* 2,
2014 wxMBConvUTF16 converter
;
2015 ByteCount byteBufferLen
= converter
.WC2MB( NULL
, st
.wc_str() , 0 ) ;
2016 UniChar
*unibuf
= (UniChar
*) malloc(byteBufferLen
) ;
2017 converter
.WC2MB( (char*) unibuf
, st
.wc_str() , byteBufferLen
) ;
2018 TXNSetData( m_txn
, kTXNUnicodeTextData
, (void*)unibuf
, byteBufferLen
,
2023 wxCharBuffer text
= st
.mb_str(wxConvLocal
) ;
2024 TXNSetData( m_txn
, kTXNTextData
, (void*)text
.data(), strlen( text
) ,
2029 wxString
wxMacMLTEControl::GetLineText(long lineNo
) const
2033 if ( lineNo
< GetNumberOfLines() )
2041 // get the first possible position in the control
2043 TXNOffsetToPoint(m_txn
, 0, &firstPoint
);
2045 // Iterate through the lines until we reach the one we want,
2046 // adding to our current y pixel point position
2047 while (ypos
< lineNo
)
2049 TXNGetLineMetrics(m_txn
, ypos
++, &lineWidth
, &lineHeight
);
2050 currentHeight
+= lineHeight
;
2053 Point thePoint
= { firstPoint
.v
+ (currentHeight
>> 16), firstPoint
.h
+ (0) };
2054 TXNOffset theOffset
;
2055 TXNPointToOffset(m_txn
, thePoint
, &theOffset
);
2057 wxString content
= GetStringValue() ;
2058 Point currentPoint
= thePoint
;
2059 while(thePoint
.v
== currentPoint
.v
&& theOffset
< content
.length())
2061 line
+= content
[theOffset
];
2062 TXNOffsetToPoint(m_txn
, ++theOffset
, ¤tPoint
);
2068 int wxMacMLTEControl::GetLineLength(long lineNo
) const
2072 if ( lineNo
< GetNumberOfLines() )
2080 // get the first possible position in the control
2082 TXNOffsetToPoint(m_txn
, 0, &firstPoint
);
2084 // Iterate through the lines until we reach the one we want,
2085 // adding to our current y pixel point position
2086 while (ypos
< lineNo
)
2088 TXNGetLineMetrics(m_txn
, ypos
++, &lineWidth
, &lineHeight
);
2089 currentHeight
+= lineHeight
;
2092 Point thePoint
= { firstPoint
.v
+ (currentHeight
>> 16), firstPoint
.h
+ (0) };
2093 TXNOffset theOffset
;
2094 TXNPointToOffset(m_txn
, thePoint
, &theOffset
);
2096 wxString content
= GetStringValue() ;
2097 Point currentPoint
= thePoint
;
2098 while(thePoint
.v
== currentPoint
.v
&& theOffset
< content
.length())
2101 TXNOffsetToPoint(m_txn
, ++theOffset
, ¤tPoint
);
2108 // ----------------------------------------------------------------------------
2109 // MLTE control implementation (classic part)
2110 // ----------------------------------------------------------------------------
2112 // OS X Notes : We still don't have a full replacement for MLTE, so this implementation
2113 // has to live on. We have different problems coming from outdated implementations on the
2114 // various OS X versions. Most deal with the scrollbars: they are not correctly embedded
2115 // while this can be solved on 10.3 by reassigning them the correct place, on 10.2 there is
2116 // no way out, therefore we are using our own implementation and our own scrollbars ....
2118 #ifdef __WXMAC_OSX__
2120 TXNScrollInfoUPP gTXNScrollInfoProc
= NULL
;
2121 ControlActionUPP gTXNScrollActionProc
= NULL
;
2123 pascal void wxMacMLTEClassicControl::TXNScrollInfoProc (SInt32 iValue
, SInt32 iMaximumValue
, TXNScrollBarOrientation
2124 iScrollBarOrientation
, SInt32 iRefCon
)
2126 wxMacMLTEClassicControl
* mlte
= (wxMacMLTEClassicControl
*) iRefCon
;
2127 SInt32 value
= wxMax( iValue
, 0 ) ;
2128 SInt32 maximum
= wxMax( iMaximumValue
, 0 ) ;
2130 if ( iScrollBarOrientation
== kTXNHorizontal
)
2132 if ( mlte
->m_sbHorizontal
)
2134 SetControl32BitValue( mlte
->m_sbHorizontal
, value
) ;
2135 SetControl32BitMaximum( mlte
->m_sbHorizontal
, maximum
) ;
2136 mlte
->m_lastHorizontalValue
= value
;
2139 else if ( iScrollBarOrientation
== kTXNVertical
)
2141 if ( mlte
->m_sbVertical
)
2143 SetControl32BitValue( mlte
->m_sbVertical
, value
) ;
2144 SetControl32BitMaximum( mlte
->m_sbVertical
, maximum
) ;
2145 mlte
->m_lastVerticalValue
= value
;
2150 pascal void wxMacMLTEClassicControl::TXNScrollActionProc( ControlRef controlRef
, ControlPartCode partCode
)
2153 wxMacMLTEClassicControl
* mlte
= (wxMacMLTEClassicControl
*) GetControlReference( controlRef
) ;
2157 if ( controlRef
!= mlte
->m_sbVertical
&& controlRef
!= mlte
->m_sbHorizontal
)
2160 bool isHorizontal
= ( controlRef
== mlte
->m_sbHorizontal
) ;
2162 SInt32 minimum
= 0 ;
2163 SInt32 maximum
= GetControl32BitMaximum( controlRef
) ;
2164 SInt32 value
= GetControl32BitValue( controlRef
) ;
2168 case kControlDownButtonPart
:
2171 case kControlUpButtonPart
:
2174 case kControlPageDownPart
:
2175 delta
= GetControlViewSize( controlRef
) ;
2177 case kControlPageUpPart
:
2178 delta
= -GetControlViewSize( controlRef
) ;
2180 case kControlIndicatorPart
:
2182 ( isHorizontal
? mlte
->m_lastHorizontalValue
: mlte
->m_lastVerticalValue
) ;
2189 SInt32 newValue
= value
;
2191 if ( partCode
!= kControlIndicatorPart
)
2193 if( value
+ delta
< minimum
)
2194 delta
= minimum
- value
;
2195 if ( value
+ delta
> maximum
)
2196 delta
= maximum
- value
;
2198 SetControl32BitValue( controlRef
, value
+ delta
) ;
2199 newValue
= value
+ delta
;
2202 SInt32 verticalDelta
= isHorizontal
? 0 : delta
;
2203 SInt32 horizontalDelta
= isHorizontal
? delta
: 0 ;
2205 err
= TXNScroll( mlte
->m_txn
, kTXNScrollUnitsInPixels
, kTXNScrollUnitsInPixels
,
2206 &verticalDelta
, &horizontalDelta
);
2209 mlte
->m_lastHorizontalValue
= newValue
;
2211 mlte
->m_lastVerticalValue
= newValue
;
2216 // make correct activations
2217 void wxMacMLTEClassicControl::MacActivatePaneText(Boolean setActive
)
2219 wxTextCtrl
* textctrl
= (wxTextCtrl
*) GetControlReference(m_controlRef
);
2221 wxMacWindowClipper
clipper( textctrl
) ;
2222 TXNActivate(m_txn
, m_txnFrameID
, setActive
);
2224 ControlRef controlFocus
= 0 ;
2225 GetKeyboardFocus( m_txnWindow
, &controlFocus
) ;
2226 if ( controlFocus
== m_controlRef
)
2227 TXNFocus( m_txn
, setActive
);
2230 void wxMacMLTEClassicControl::MacFocusPaneText(Boolean setFocus
)
2232 TXNFocus( m_txn
, setFocus
);
2235 // guards against inappropriate redraw (hidden objects drawing onto window)
2237 void wxMacMLTEClassicControl::MacSetObjectVisibility(Boolean vis
)
2239 ControlRef controlFocus
= 0 ;
2240 GetKeyboardFocus( m_txnWindow
, &controlFocus
) ;
2242 if ( controlFocus
== m_controlRef
&& vis
== false )
2244 SetKeyboardFocus( m_txnWindow
, m_controlRef
, kControlFocusNoPart
) ;
2247 TXNControlTag iControlTags
[1] = { kTXNVisibilityTag
};
2248 TXNControlData iControlData
[1] = { {(UInt32
) false } };
2250 verify_noerr( TXNGetTXNObjectControls( m_txn
, 1,
2251 iControlTags
, iControlData
) ) ;
2253 if ( iControlData
[0].uValue
!= vis
)
2255 iControlData
[0].uValue
= vis
;
2256 verify_noerr( TXNSetTXNObjectControls( m_txn
, false , 1,
2257 iControlTags
, iControlData
)) ;
2259 // we right now are always clipping as partial visibility (overlapped) visibility
2260 // is also a problem, if we run into further problems we might set the FrameBounds to an empty
2264 // make sure that the TXNObject is at the right position
2266 void wxMacMLTEClassicControl::MacUpdatePosition()
2268 wxTextCtrl
* textctrl
= (wxTextCtrl
*) GetControlReference(m_controlRef
);
2269 if ( textctrl
== NULL
)
2273 UMAGetControlBoundsInWindowCoords(m_controlRef
, &bounds
);
2275 wxRect visRect
= textctrl
->MacGetClippedClientRect() ;
2276 Rect visBounds
= { visRect
.y
, visRect
.x
, visRect
.y
+ visRect
.height
, visRect
.x
+ visRect
.width
} ;
2279 textctrl
->MacWindowToRootWindow( &x
, &y
) ;
2280 OffsetRect( &visBounds
, x
, y
) ;
2282 if ( !EqualRect( &bounds
, &m_txnControlBounds
) || !EqualRect( &visBounds
, &m_txnVisBounds
) )
2284 m_txnControlBounds
= bounds
;
2285 m_txnVisBounds
= visBounds
;
2286 wxMacWindowClipper
cl(textctrl
) ;
2288 #ifdef __WXMAC_OSX__
2289 bool isCompositing
= textctrl
->MacGetTopLevelWindow()->MacUsesCompositing() ;
2290 if ( m_sbHorizontal
|| m_sbVertical
)
2292 int w
= bounds
.right
- bounds
.left
;
2293 int h
= bounds
.bottom
- bounds
.top
;
2295 if ( m_sbHorizontal
)
2299 sbBounds
.left
= -1 ;
2300 sbBounds
.top
= h
- 14 ;
2301 sbBounds
.right
= w
+ 1 ;
2302 sbBounds
.bottom
= h
+ 1 ;
2304 if ( !isCompositing
)
2305 OffsetRect( &sbBounds
, m_txnControlBounds
.left
, m_txnControlBounds
.top
) ;
2307 SetControlBounds( m_sbHorizontal
, &sbBounds
) ;
2308 SetControlViewSize( m_sbHorizontal
, w
) ;
2314 sbBounds
.left
= w
- 14 ;
2316 sbBounds
.right
= w
+ 1 ;
2317 sbBounds
.bottom
= m_sbHorizontal
? h
- 14 : h
+ 1 ;
2319 if ( !isCompositing
)
2320 OffsetRect( &sbBounds
, m_txnControlBounds
.left
, m_txnControlBounds
.top
) ;
2322 SetControlBounds( m_sbVertical
, &sbBounds
) ;
2323 SetControlViewSize( m_sbVertical
, h
) ;
2328 TXNLongRect olddestRect
;
2329 TXNGetRectBounds( m_txn
, &oldviewRect
, &olddestRect
, NULL
) ;
2331 Rect viewRect
= { m_txnControlBounds
.top
, m_txnControlBounds
.left
,
2332 m_txnControlBounds
.bottom
- ( m_sbHorizontal
? 14 : 0 ) , m_txnControlBounds
.right
- ( m_sbVertical
? 14 : 0 ) } ;
2333 TXNLongRect destRect
= { m_txnControlBounds
.top
, m_txnControlBounds
.left
,
2334 m_txnControlBounds
.bottom
- ( m_sbHorizontal
? 14 : 0 ) , m_txnControlBounds
.right
- ( m_sbVertical
? 14 : 0 ) } ;
2336 if ( olddestRect
.right
>= 10000 )
2337 destRect
.right
= destRect
.left
+ 32000 ;
2339 if ( olddestRect
.bottom
>= 0x20000000 )
2340 destRect
.bottom
= destRect
.top
+ 0x40000000 ;
2342 SectRect( &viewRect
, &visBounds
, &viewRect
) ;
2343 TXNSetRectBounds( m_txn
, &viewRect
, &destRect
, true ) ;
2345 TXNSetFrameBounds( m_txn, m_txnControlBounds.top, m_txnControlBounds.left,
2346 m_txnControlBounds.bottom - ( m_sbHorizontal ? 14 : 0 ) , m_txnControlBounds.right - ( m_sbVertical ? 14 : 0 ), m_txnFrameID);
2350 TXNSetFrameBounds( m_txn
, m_txnControlBounds
.top
, m_txnControlBounds
.left
,
2351 wxMax( m_txnControlBounds
.bottom
, m_txnControlBounds
.top
) ,
2352 wxMax( m_txnControlBounds
.right
, m_txnControlBounds
.left
) , m_txnFrameID
);
2354 // the SetFrameBounds method unter classic sometimes does not correctly scroll a selection into sight after a
2355 // movement, therefore we have to force it
2357 // according to David Surovell this problem also sometimes occurs under OSX, so we use this as well
2359 TXNLongRect textRect
;
2360 TXNGetRectBounds( m_txn
, NULL
, NULL
, &textRect
) ;
2361 if ( textRect
.left
< m_txnControlBounds
.left
)
2363 TXNShowSelection( m_txn
, false ) ;
2368 void wxMacMLTEClassicControl::SetRect( Rect
*r
)
2370 wxMacControl::SetRect( r
) ;
2371 MacUpdatePosition() ;
2374 void wxMacMLTEClassicControl::MacControlUserPaneDrawProc(wxInt16 thePart
)
2376 wxTextCtrl
* textctrl
= (wxTextCtrl
*) GetControlReference(m_controlRef
);
2377 if ( textctrl
== NULL
)
2380 if ( textctrl
->MacIsReallyShown() )
2382 wxMacWindowClipper
clipper( textctrl
) ;
2383 TXNDraw( m_txn
, NULL
) ;
2387 wxInt16
wxMacMLTEClassicControl::MacControlUserPaneHitTestProc(wxInt16 x
, wxInt16 y
)
2389 Point where
= { y
, x
} ;
2390 ControlPartCode result
= kControlNoPart
;
2392 wxTextCtrl
* textctrl
= (wxTextCtrl
*) GetControlReference(m_controlRef
);
2393 if ( (textctrl
!= NULL
) && textctrl
->MacIsReallyShown() )
2395 if (PtInRect(where
, &m_txnControlBounds
))
2396 result
= kControlEditTextPart
;
2399 // sometimes we get the coords also in control local coordinates, therefore test again
2400 if ( textctrl
->MacGetTopLevelWindow()->MacUsesCompositing() )
2403 textctrl
->MacClientToRootWindow( &x
, &y
) ;
2407 if (PtInRect(where
, &m_txnControlBounds
))
2408 result
= kControlEditTextPart
;
2415 wxInt16
wxMacMLTEClassicControl::MacControlUserPaneTrackingProc( wxInt16 x
, wxInt16 y
, void* actionProc
)
2417 ControlPartCode result
= kControlNoPart
;
2419 wxTextCtrl
* textctrl
= (wxTextCtrl
*) GetControlReference(m_controlRef
);
2420 if ( (textctrl
!= NULL
) && textctrl
->MacIsReallyShown() )
2422 Point startPt
= { y
, x
} ;
2423 // for compositing, we must convert these into toplevel window coordinates, because hittesting expects them
2424 if ( textctrl
->MacGetTopLevelWindow()->MacUsesCompositing() )
2427 textctrl
->MacClientToRootWindow( &x
, &y
) ;
2432 switch (MacControlUserPaneHitTestProc( startPt
.h
, startPt
.v
))
2434 case kControlEditTextPart
:
2436 wxMacWindowClipper
clipper( textctrl
) ;
2439 ConvertEventRefToEventRecord( (EventRef
) wxTheApp
->MacGetCurrentEvent() , &rec
) ;
2440 TXNClick( m_txn
, &rec
);
2452 void wxMacMLTEClassicControl::MacControlUserPaneIdleProc()
2454 wxTextCtrl
* textctrl
= (wxTextCtrl
*) GetControlReference(m_controlRef
);
2455 if ( textctrl
== NULL
)
2458 if (textctrl
->MacIsReallyShown())
2460 if (IsControlActive(m_controlRef
))
2464 wxMacWindowClipper
clipper( textctrl
) ;
2469 if (PtInRect(mousep
, &m_txnControlBounds
))
2472 RectRgn((theRgn
= NewRgn()), &m_txnControlBounds
);
2473 TXNAdjustCursor(m_txn
, theRgn
);
2480 wxInt16
wxMacMLTEClassicControl::MacControlUserPaneKeyDownProc (wxInt16 keyCode
, wxInt16 charCode
, wxInt16 modifiers
)
2482 wxTextCtrl
* textctrl
= (wxTextCtrl
*) GetControlReference(m_controlRef
);
2483 if ( textctrl
== NULL
)
2484 return kControlNoPart
;
2486 wxMacWindowClipper
clipper( textctrl
) ;
2489 memset( &ev
, 0 , sizeof( ev
) ) ;
2491 ev
.modifiers
= modifiers
;
2492 ev
.message
= (( keyCode
<< 8 ) & keyCodeMask
) + ( charCode
& charCodeMask
) ;
2493 TXNKeyDown( m_txn
, &ev
);
2495 return kControlEntireControl
;
2498 void wxMacMLTEClassicControl::MacControlUserPaneActivateProc( bool activating
)
2500 MacActivatePaneText( activating
);
2503 wxInt16
wxMacMLTEClassicControl::MacControlUserPaneFocusProc(wxInt16 action
)
2505 ControlPartCode focusResult
;
2507 focusResult
= kControlFocusNoPart
;
2508 wxTextCtrl
* textctrl
= (wxTextCtrl
*) GetControlReference(m_controlRef
);
2509 if ( textctrl
== NULL
)
2512 wxMacWindowClipper
clipper( textctrl
) ;
2514 ControlRef controlFocus
= NULL
;
2515 GetKeyboardFocus( m_txnWindow
, &controlFocus
) ;
2516 bool wasFocused
= ( controlFocus
== m_controlRef
) ;
2520 case kControlFocusPrevPart
:
2521 case kControlFocusNextPart
:
2522 MacFocusPaneText( ( !wasFocused
));
2523 focusResult
= (!wasFocused
) ? (ControlPartCode
) kControlEditTextPart
: (ControlPartCode
) kControlFocusNoPart
;
2526 case kControlFocusNoPart
:
2528 MacFocusPaneText( false );
2529 focusResult
= kControlFocusNoPart
;
2536 void wxMacMLTEClassicControl::MacControlUserPaneBackgroundProc( void *info
)
2540 wxMacMLTEClassicControl::wxMacMLTEClassicControl( wxTextCtrl
*wxPeer
,
2541 const wxString
& str
,
2543 const wxSize
& size
, long style
) : wxMacMLTEControl( wxPeer
)
2545 m_font
= wxPeer
->GetFont() ;
2546 m_windowStyle
= style
;
2547 Rect bounds
= wxMacGetBoundsForControl( wxPeer
, pos
, size
) ;
2551 featureSet
= kControlSupportsEmbedding
| kControlSupportsFocus
| kControlWantsIdle
2552 | kControlWantsActivate
| kControlHandlesTracking
// | kControlHasSpecialBackground
2553 | kControlGetsFocusOnClick
| kControlSupportsLiveFeedback
;
2555 verify_noerr( ::CreateUserPaneControl( MAC_WXHWND(wxPeer
->GetParent()->MacGetTopLevelWindowRef()), &bounds
, featureSet
, &m_controlRef
) );
2559 AdjustCreationAttributes( *wxWHITE
, true ) ;
2561 MacSetObjectVisibility( wxPeer
->MacIsReallyShown() ) ;
2565 wxMacConvertNewlines10To13( &st
) ;
2566 wxMacWindowClipper
clipper( m_peer
) ;
2567 SetTXNData( st
, kTXNStartOffset
, kTXNEndOffset
) ;
2568 TXNSetSelection( m_txn
, 0, 0);
2572 wxMacMLTEClassicControl::~wxMacMLTEClassicControl()
2574 TXNDeleteObject(m_txn
);
2578 void wxMacMLTEClassicControl::VisibilityChanged(bool shown
)
2580 MacSetObjectVisibility( shown
) ;
2581 wxMacControl::VisibilityChanged( shown
) ;
2584 void wxMacMLTEClassicControl::SuperChangedPosition()
2586 MacUpdatePosition() ;
2587 wxMacControl::SuperChangedPosition() ;
2590 #ifdef __WXMAC_OSX__
2592 ControlUserPaneDrawUPP gTPDrawProc
= NULL
;
2593 ControlUserPaneHitTestUPP gTPHitProc
= NULL
;
2594 ControlUserPaneTrackingUPP gTPTrackProc
= NULL
;
2595 ControlUserPaneIdleUPP gTPIdleProc
= NULL
;
2596 ControlUserPaneKeyDownUPP gTPKeyProc
= NULL
;
2597 ControlUserPaneActivateUPP gTPActivateProc
= NULL
;
2598 ControlUserPaneFocusUPP gTPFocusProc
= NULL
;
2600 static pascal void wxMacControlUserPaneDrawProc(ControlRef control
, SInt16 part
)
2602 wxTextCtrl
*textCtrl
= wxDynamicCast( wxFindControlFromMacControl(control
) , wxTextCtrl
) ;
2603 wxMacMLTEClassicControl
* win
= textCtrl
? (wxMacMLTEClassicControl
*)(textCtrl
->GetPeer()) : NULL
;
2605 win
->MacControlUserPaneDrawProc(part
) ;
2608 static pascal ControlPartCode
wxMacControlUserPaneHitTestProc(ControlRef control
, Point where
)
2610 wxTextCtrl
*textCtrl
= wxDynamicCast( wxFindControlFromMacControl(control
) , wxTextCtrl
) ;
2611 wxMacMLTEClassicControl
* win
= textCtrl
? (wxMacMLTEClassicControl
*)(textCtrl
->GetPeer()) : NULL
;
2613 return win
->MacControlUserPaneHitTestProc(where
.h
, where
.v
) ;
2615 return kControlNoPart
;
2618 static pascal ControlPartCode
wxMacControlUserPaneTrackingProc(ControlRef control
, Point startPt
, ControlActionUPP actionProc
)
2620 wxTextCtrl
*textCtrl
= wxDynamicCast( wxFindControlFromMacControl(control
) , wxTextCtrl
) ;
2621 wxMacMLTEClassicControl
* win
= textCtrl
? (wxMacMLTEClassicControl
*)(textCtrl
->GetPeer()) : NULL
;
2623 return win
->MacControlUserPaneTrackingProc( startPt
.h
, startPt
.v
, (void*) actionProc
) ;
2625 return kControlNoPart
;
2628 static pascal void wxMacControlUserPaneIdleProc(ControlRef control
)
2630 wxTextCtrl
*textCtrl
= wxDynamicCast( wxFindControlFromMacControl(control
) , wxTextCtrl
) ;
2631 wxMacMLTEClassicControl
* win
= textCtrl
? (wxMacMLTEClassicControl
*)(textCtrl
->GetPeer()) : NULL
;
2633 win
->MacControlUserPaneIdleProc() ;
2636 static pascal ControlPartCode
wxMacControlUserPaneKeyDownProc(ControlRef control
, SInt16 keyCode
, SInt16 charCode
, SInt16 modifiers
)
2638 wxTextCtrl
*textCtrl
= wxDynamicCast( wxFindControlFromMacControl(control
) , wxTextCtrl
) ;
2639 wxMacMLTEClassicControl
* win
= textCtrl
? (wxMacMLTEClassicControl
*)(textCtrl
->GetPeer()) : NULL
;
2641 return win
->MacControlUserPaneKeyDownProc(keyCode
,charCode
,modifiers
) ;
2643 return kControlNoPart
;
2646 static pascal void wxMacControlUserPaneActivateProc(ControlRef control
, Boolean activating
)
2648 wxTextCtrl
*textCtrl
= wxDynamicCast( wxFindControlFromMacControl(control
) , wxTextCtrl
) ;
2649 wxMacMLTEClassicControl
* win
= textCtrl
? (wxMacMLTEClassicControl
*)(textCtrl
->GetPeer()) : NULL
;
2651 win
->MacControlUserPaneActivateProc(activating
) ;
2654 static pascal ControlPartCode
wxMacControlUserPaneFocusProc(ControlRef control
, ControlFocusPart action
)
2656 wxTextCtrl
*textCtrl
= wxDynamicCast( wxFindControlFromMacControl(control
) , wxTextCtrl
) ;
2657 wxMacMLTEClassicControl
* win
= textCtrl
? (wxMacMLTEClassicControl
*)(textCtrl
->GetPeer()) : NULL
;
2659 return win
->MacControlUserPaneFocusProc(action
) ;
2661 return kControlNoPart
;
2665 static pascal void wxMacControlUserPaneBackgroundProc(ControlRef control, ControlBackgroundPtr info)
2667 wxTextCtrl *textCtrl = wxDynamicCast( wxFindControlFromMacControl(control) , wxTextCtrl ) ;
2668 wxMacMLTEClassicControl * win = textCtrl ? (wxMacMLTEClassicControl*)(textCtrl->GetPeer()) : NULL ;
2670 win->MacControlUserPaneBackgroundProc(info) ;
2675 // TXNRegisterScrollInfoProc
2677 OSStatus
wxMacMLTEClassicControl::DoCreate()
2681 OSStatus err
= noErr
;
2683 /* set up our globals */
2684 #ifdef __WXMAC_OSX__
2685 if (gTPDrawProc
== NULL
) gTPDrawProc
= NewControlUserPaneDrawUPP(wxMacControlUserPaneDrawProc
);
2686 if (gTPHitProc
== NULL
) gTPHitProc
= NewControlUserPaneHitTestUPP(wxMacControlUserPaneHitTestProc
);
2687 if (gTPTrackProc
== NULL
) gTPTrackProc
= NewControlUserPaneTrackingUPP(wxMacControlUserPaneTrackingProc
);
2688 if (gTPIdleProc
== NULL
) gTPIdleProc
= NewControlUserPaneIdleUPP(wxMacControlUserPaneIdleProc
);
2689 if (gTPKeyProc
== NULL
) gTPKeyProc
= NewControlUserPaneKeyDownUPP(wxMacControlUserPaneKeyDownProc
);
2690 if (gTPActivateProc
== NULL
) gTPActivateProc
= NewControlUserPaneActivateUPP(wxMacControlUserPaneActivateProc
);
2691 if (gTPFocusProc
== NULL
) gTPFocusProc
= NewControlUserPaneFocusUPP(wxMacControlUserPaneFocusProc
);
2693 if (gTXNScrollInfoProc
== NULL
) gTXNScrollInfoProc
= NewTXNScrollInfoUPP(TXNScrollInfoProc
) ;
2694 if (gTXNScrollActionProc
== NULL
) gTXNScrollActionProc
= NewControlActionUPP(TXNScrollActionProc
) ;
2697 /* set the initial settings for our private data */
2699 m_txnWindow
= GetControlOwner(m_controlRef
);
2700 m_txnPort
= (GrafPtr
) GetWindowPort(m_txnWindow
);
2702 #ifdef __WXMAC_OSX__
2703 /* set up the user pane procedures */
2704 SetControlData(m_controlRef
, kControlEntireControl
, kControlUserPaneDrawProcTag
, sizeof(gTPDrawProc
), &gTPDrawProc
);
2705 SetControlData(m_controlRef
, kControlEntireControl
, kControlUserPaneHitTestProcTag
, sizeof(gTPHitProc
), &gTPHitProc
);
2706 SetControlData(m_controlRef
, kControlEntireControl
, kControlUserPaneTrackingProcTag
, sizeof(gTPTrackProc
), &gTPTrackProc
);
2707 SetControlData(m_controlRef
, kControlEntireControl
, kControlUserPaneIdleProcTag
, sizeof(gTPIdleProc
), &gTPIdleProc
);
2708 SetControlData(m_controlRef
, kControlEntireControl
, kControlUserPaneKeyDownProcTag
, sizeof(gTPKeyProc
), &gTPKeyProc
);
2709 SetControlData(m_controlRef
, kControlEntireControl
, kControlUserPaneActivateProcTag
, sizeof(gTPActivateProc
), &gTPActivateProc
);
2710 SetControlData(m_controlRef
, kControlEntireControl
, kControlUserPaneFocusProcTag
, sizeof(gTPFocusProc
), &gTPFocusProc
);
2712 /* calculate the rectangles used by the control */
2713 UMAGetControlBoundsInWindowCoords(m_controlRef
, &bounds
);
2715 m_txnControlBounds
= bounds
;
2716 m_txnVisBounds
= bounds
;
2718 CGrafPtr origPort
= NULL
;
2719 GDHandle origDev
= NULL
;
2720 GetGWorld( &origPort
, &origDev
) ;
2723 /* create the new edit field */
2725 TXNFrameOptions frameOptions
= FrameOptionsFromWXStyle( m_windowStyle
) ;
2727 #ifdef __WXMAC_OSX__
2729 // the scrollbars are not correctly embedded but are inserted at the root
2730 // this gives us problems as we have erratic redraws even over the structure
2733 m_sbHorizontal
= 0 ;
2735 m_lastHorizontalValue
= 0 ;
2736 m_lastVerticalValue
= 0 ;
2738 Rect sb
= { 0 , 0 , 0 , 0 } ;
2739 if ( frameOptions
& kTXNWantVScrollBarMask
)
2741 CreateScrollBarControl( m_txnWindow
, &sb
, 0 , 0 , 100 , 1 , true , gTXNScrollActionProc
, &m_sbVertical
) ;
2742 SetControlReference( m_sbVertical
, (SInt32
) this ) ;
2743 SetControlAction( m_sbVertical
, gTXNScrollActionProc
);
2744 ShowControl( m_sbVertical
) ;
2745 EmbedControl( m_sbVertical
, m_controlRef
) ;
2746 frameOptions
&= ~kTXNWantVScrollBarMask
;
2748 if ( frameOptions
& kTXNWantHScrollBarMask
)
2750 CreateScrollBarControl( m_txnWindow
, &sb
, 0 , 0 , 100 , 1 , true , gTXNScrollActionProc
, &m_sbHorizontal
) ;
2751 SetControlReference( m_sbHorizontal
, (SInt32
) this ) ;
2752 SetControlAction( m_sbHorizontal
, gTXNScrollActionProc
);
2753 ShowControl( m_sbHorizontal
) ;
2754 EmbedControl( m_sbHorizontal
, m_controlRef
) ;
2755 frameOptions
&= ~(kTXNWantHScrollBarMask
| kTXNDrawGrowIconMask
);
2760 verify_noerr(TXNNewObject(NULL
, m_txnWindow
, &bounds
,
2762 kTXNTextEditStyleFrameType
,
2764 kTXNSystemDefaultEncoding
,
2765 &m_txn
, &m_txnFrameID
, NULL
) );
2767 TXNCarbonEventInfo cInfo ;
2769 cInfo.useCarbonEvents = false ;
2772 cInfo.fDictionary = NULL ;
2774 TXNControlTag iControlTags[] =
2776 kTXNUseCarbonEvents ,
2778 TXNControlData iControlData[] =
2783 int toptag = WXSIZEOF( iControlTags ) ;
2785 verify_noerr( TXNSetTXNObjectControls( m_txn, false , toptag,
2786 iControlTags, iControlData )) ;
2789 #ifdef __WXMAC_OSX__
2790 TXNRegisterScrollInfoProc( m_txn
, gTXNScrollInfoProc
, (SInt32
) this);
2793 SetGWorld( origPort
, origDev
) ;
2797 // ----------------------------------------------------------------------------
2798 // MLTE control implementation (OSX part)
2799 // ----------------------------------------------------------------------------
2801 #if TARGET_API_MAC_OSX
2803 #if MAC_OS_X_VERSION_MAX_ALLOWED > MAC_OS_X_VERSION_10_2
2805 wxMacMLTEHIViewControl::wxMacMLTEHIViewControl( wxTextCtrl
*wxPeer
,
2806 const wxString
& str
,
2808 const wxSize
& size
, long style
) : wxMacMLTEControl( wxPeer
)
2810 m_font
= wxPeer
->GetFont() ;
2811 m_windowStyle
= style
;
2812 Rect bounds
= wxMacGetBoundsForControl( wxPeer
, pos
, size
) ;
2814 wxMacConvertNewlines10To13( &st
) ;
2816 HIRect hr
= { { bounds
.left
, bounds
.top
} ,
2817 { bounds
.right
- bounds
.left
, bounds
.bottom
- bounds
.top
} } ;
2819 m_scrollView
= NULL
;
2820 TXNFrameOptions frameOptions
= FrameOptionsFromWXStyle( style
) ;
2821 if ( frameOptions
& (kTXNWantVScrollBarMask
|kTXNWantHScrollBarMask
) )
2823 HIScrollViewCreate(( frameOptions
& kTXNWantHScrollBarMask
? kHIScrollViewOptionsHorizScroll
: 0) |
2824 ( frameOptions
& kTXNWantVScrollBarMask
? kHIScrollViewOptionsVertScroll
: 0 ) , &m_scrollView
) ;
2826 HIViewSetFrame( m_scrollView
, &hr
);
2827 HIViewSetVisible( m_scrollView
, true );
2831 HITextViewCreate( NULL
, 0, frameOptions
, &m_textView
) ;
2832 m_txn
= HITextViewGetTXNObject( m_textView
) ;
2833 HIViewSetVisible( m_textView
, true ) ;
2836 HIViewAddSubview( m_scrollView
, m_textView
) ;
2837 m_controlRef
= m_scrollView
;
2838 wxPeer
->MacInstallEventHandler( (WXWidget
) m_textView
) ;
2842 HIViewSetFrame( m_textView
, &hr
);
2843 m_controlRef
= m_textView
;
2846 AdjustCreationAttributes( *wxWHITE
, true ) ;
2848 wxMacWindowClipper
c( m_peer
) ;
2849 SetTXNData( st
, kTXNStartOffset
, kTXNEndOffset
) ;
2851 TXNSetSelection( m_txn
, 0, 0);
2852 TXNShowSelection( m_txn
, kTXNShowStart
);
2855 OSStatus
wxMacMLTEHIViewControl::SetFocus( ControlFocusPart focusPart
)
2857 return SetKeyboardFocus( GetControlOwner( m_textView
) ,
2858 m_textView
, focusPart
) ;
2861 bool wxMacMLTEHIViewControl::HasFocus() const
2863 ControlRef control
;
2864 GetKeyboardFocus( GetUserFocusWindow() , &control
) ;
2865 return control
== m_textView
;
2868 void wxMacMLTEHIViewControl::SetBackground( const wxBrush
&brush
)
2870 wxMacMLTEControl::SetBackground( brush
) ;
2872 CGColorSpaceRef rgbSpace = CGColorSpaceCreateDeviceRGB();
2873 RGBColor col = MAC_WXCOLORREF(brush.GetColour().GetPixel()) ;
2875 float component[4] ;
2876 component[0] = col.red / 65536.0 ;
2877 component[1] = col.green / 65536.0 ;
2878 component[2] = col.blue / 65536.0 ;
2879 component[3] = 1.0 ; // alpha
2881 CGColorRef color = CGColorCreate (rgbSpace , component );
2882 HITextViewSetBackgroundColor( m_textView , color ) ;
2883 CGColorSpaceRelease( rgbSpace );
2887 #endif // MAC_OS_X_VERSION_MAX_ALLOWED > MAC_OS_X_VERSION_10_2
2892 #endif // wxUSE_TEXTCTRL