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
) = 0 ;
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 ;
187 virtual void Clear() ;
188 virtual bool CanUndo() const;
189 virtual void Undo() ;
190 virtual bool CanRedo() const;
191 virtual void Redo() ;
192 virtual int GetNumberOfLines() const ;
193 virtual long XYToPosition(long x
, long y
) const;
194 virtual bool PositionToXY(long pos
, long *x
, long *y
) const ;
195 virtual void ShowPosition( long WXUNUSED(pos
) ) ;
196 virtual int GetLineLength(long lineNo
) const ;
197 virtual wxString
GetLineText(long lineNo
) const ;
198 virtual bool SetupCursor( const wxPoint
& pt
) { return false ; }
200 #ifndef __WXMAC_OSX__
201 virtual void MacControlUserPaneDrawProc(wxInt16 part
) = 0 ;
202 virtual wxInt16
MacControlUserPaneHitTestProc(wxInt16 x
, wxInt16 y
) = 0 ;
203 virtual wxInt16
MacControlUserPaneTrackingProc(wxInt16 x
, wxInt16 y
, void* actionProc
) = 0 ;
204 virtual void MacControlUserPaneIdleProc() = 0 ;
205 virtual wxInt16
MacControlUserPaneKeyDownProc(wxInt16 keyCode
, wxInt16 charCode
, wxInt16 modifiers
) = 0 ;
206 virtual void MacControlUserPaneActivateProc(bool activating
) = 0 ;
207 virtual wxInt16
MacControlUserPaneFocusProc(wxInt16 action
) = 0 ;
208 virtual void MacControlUserPaneBackgroundProc(void* info
) = 0 ;
212 // common parts for implementations based on MLTE
214 class wxMacMLTEControl
: public wxMacTextControl
217 wxMacMLTEControl( wxTextCtrl
*peer
) ;
218 virtual wxString
GetStringValue() const ;
219 virtual void SetStringValue( const wxString
&str
) ;
221 static TXNFrameOptions
FrameOptionsFromWXStyle( long wxStyle
) ;
222 void AdjustCreationAttributes( const wxColour
& background
, bool visible
) ;
224 virtual void SetFont( const wxFont
& font
, const wxColour
& foreground
, long windowStyle
) ;
225 virtual void SetBackground( const wxBrush
&brush
) ;
226 virtual void SetStyle(long start
, long end
, const wxTextAttr
& style
) ;
227 virtual void Copy() ;
229 virtual void Paste() ;
230 virtual bool CanPaste() const ;
231 virtual void SetEditable(bool editable
) ;
232 virtual wxTextPos
GetLastPosition() const ;
233 virtual void Replace( long from
, long to
, const wxString str
) ;
234 virtual void Remove( long from
, long to
) ;
235 virtual void GetSelection( long* from
, long* to
) const ;
236 virtual void SetSelection( long from
, long to
) ;
238 virtual void WriteText(const wxString
& str
) ;
239 virtual void Clear() ;
241 virtual bool CanUndo() const ;
242 virtual void Undo() ;
243 virtual bool CanRedo() const;
244 virtual void Redo() ;
245 virtual int GetNumberOfLines() const ;
246 virtual long XYToPosition(long x
, long y
) const ;
247 virtual bool PositionToXY(long pos
, long *x
, long *y
) const ;
248 virtual void ShowPosition( long pos
) ;
249 virtual int GetLineLength(long lineNo
) const ;
250 virtual wxString
GetLineText(long lineNo
) const ;
252 void SetTXNData( const wxString
& st
, TXNOffset start
, TXNOffset end
) ;
255 void TXNSetAttribute( const wxTextAttr
& style
, long from
, long to
) ;
259 #if TARGET_API_MAC_OSX
261 // implementation available under OSX
263 #if MAC_OS_X_VERSION_MAX_ALLOWED > MAC_OS_X_VERSION_10_2
265 class wxMacMLTEHIViewControl
: public wxMacMLTEControl
268 wxMacMLTEHIViewControl( wxTextCtrl
*wxPeer
,
271 const wxSize
& size
, long style
) ;
272 virtual OSStatus
SetFocus( ControlFocusPart focusPart
) ;
273 virtual bool HasFocus() const ;
275 HIViewRef m_scrollView
;
276 HIViewRef m_textView
;
281 class wxMacUnicodeTextControl
: public wxMacTextControl
284 wxMacUnicodeTextControl( wxTextCtrl
*wxPeer
,
287 const wxSize
& size
, long style
) ;
288 ~wxMacUnicodeTextControl();
289 virtual void VisibilityChanged(bool shown
);
290 virtual wxString
GetStringValue() const ;
291 virtual void SetStringValue( const wxString
&str
) ;
294 virtual void Paste();
295 virtual bool CanPaste() const;
296 virtual void SetEditable(bool editable
) ;
297 virtual void Remove( long from
, long to
) ;
298 virtual void GetSelection( long* from
, long* to
) const ;
299 virtual void SetSelection( long from
, long to
) ;
300 virtual void WriteText(const wxString
& str
) ;
302 // contains the tag for the content (is different for password and non-password controls)
308 // 'classic' MLTE implementation
310 class wxMacMLTEClassicControl
: public wxMacMLTEControl
313 wxMacMLTEClassicControl( wxTextCtrl
*wxPeer
,
316 const wxSize
& size
, long style
) ;
317 ~wxMacMLTEClassicControl() ;
318 virtual void VisibilityChanged(bool shown
) ;
319 virtual void SuperChangedPosition() ;
321 virtual void MacControlUserPaneDrawProc(wxInt16 part
) ;
322 virtual wxInt16
MacControlUserPaneHitTestProc(wxInt16 x
, wxInt16 y
) ;
323 virtual wxInt16
MacControlUserPaneTrackingProc(wxInt16 x
, wxInt16 y
, void* actionProc
) ;
324 virtual void MacControlUserPaneIdleProc() ;
325 virtual wxInt16
MacControlUserPaneKeyDownProc(wxInt16 keyCode
, wxInt16 charCode
, wxInt16 modifiers
) ;
326 virtual void MacControlUserPaneActivateProc(bool activating
) ;
327 virtual wxInt16
MacControlUserPaneFocusProc(wxInt16 action
) ;
328 virtual void MacControlUserPaneBackgroundProc(void* info
) ;
330 virtual bool SetupCursor( const wxPoint
& WXUNUSED(pt
) ) { MacControlUserPaneIdleProc() ; return true ;}
332 virtual void SetRect( Rect
*r
) ;
337 void MacUpdatePosition() ;
338 void MacActivatePaneText(Boolean setActive
) ;
339 void MacFocusPaneText(Boolean setFocus
) ;
341 void MacSetObjectVisibility(Boolean vis
) ;
343 TXNFrameID m_txnFrameID
;
345 WindowRef m_txnWindow
;
346 // bounds of the control as we last did set the txn frames
347 Rect m_txnControlBounds
;
348 Rect m_txnVisBounds
;
350 static pascal void TXNScrollInfoProc (SInt32 iValue
, SInt32 iMaximumValue
,
351 TXNScrollBarOrientation iScrollBarOrientation
, SInt32 iRefCon
) ;
352 static pascal void TXNScrollActionProc( ControlRef controlRef
, ControlPartCode partCode
) ;
353 ControlRef m_sbHorizontal
;
354 SInt32 m_lastHorizontalValue
;
355 ControlRef m_sbVertical
;
356 SInt32 m_lastVerticalValue
;
360 #define TE_UNLIMITED_LENGTH 0xFFFFFFFFUL
362 IMPLEMENT_DYNAMIC_CLASS(wxTextCtrl
, wxControl
)
364 BEGIN_EVENT_TABLE(wxTextCtrl
, wxControl
)
365 EVT_ERASE_BACKGROUND( wxTextCtrl::OnEraseBackground
)
366 EVT_DROP_FILES(wxTextCtrl::OnDropFiles
)
367 EVT_CHAR(wxTextCtrl::OnChar
)
368 EVT_MENU(wxID_CUT
, wxTextCtrl::OnCut
)
369 EVT_MENU(wxID_COPY
, wxTextCtrl::OnCopy
)
370 EVT_MENU(wxID_PASTE
, wxTextCtrl::OnPaste
)
371 EVT_MENU(wxID_UNDO
, wxTextCtrl::OnUndo
)
372 EVT_MENU(wxID_REDO
, wxTextCtrl::OnRedo
)
373 EVT_MENU(wxID_CLEAR
, wxTextCtrl::OnDelete
)
374 EVT_MENU(wxID_SELECTALL
, wxTextCtrl::OnSelectAll
)
376 EVT_CONTEXT_MENU(wxTextCtrl::OnContextMenu
)
378 EVT_UPDATE_UI(wxID_CUT
, wxTextCtrl::OnUpdateCut
)
379 EVT_UPDATE_UI(wxID_COPY
, wxTextCtrl::OnUpdateCopy
)
380 EVT_UPDATE_UI(wxID_PASTE
, wxTextCtrl::OnUpdatePaste
)
381 EVT_UPDATE_UI(wxID_UNDO
, wxTextCtrl::OnUpdateUndo
)
382 EVT_UPDATE_UI(wxID_REDO
, wxTextCtrl::OnUpdateRedo
)
383 EVT_UPDATE_UI(wxID_CLEAR
, wxTextCtrl::OnUpdateDelete
)
384 EVT_UPDATE_UI(wxID_SELECTALL
, wxTextCtrl::OnUpdateSelectAll
)
388 void wxTextCtrl::Init()
393 m_privateContextMenu
= NULL
;
395 m_maxLength
= TE_UNLIMITED_LENGTH
;
398 wxTextCtrl::~wxTextCtrl()
400 delete m_privateContextMenu
;
404 bool wxTextCtrl::Create(wxWindow
*parent
, wxWindowID id
,
407 const wxSize
& size
, long style
,
408 const wxValidator
& validator
,
409 const wxString
& name
)
411 m_macIsUserPane
= false ;
414 if ( ! ( style
& wxNO_BORDER
) )
415 style
= ( style
& ~wxBORDER_MASK
) | wxSUNKEN_BORDER
;
417 if ( !wxTextCtrlBase::Create(parent
, id
, pos
, size
, style
& ~(wxHSCROLL
|wxVSCROLL
), validator
, name
) )
420 if ( m_windowStyle
& wxTE_MULTILINE
)
422 wxASSERT_MSG( !(m_windowStyle
& wxTE_PROCESS_ENTER
),
423 wxT("wxTE_PROCESS_ENTER style is ignored for multiline text controls (they always process it)") );
425 m_windowStyle
|= wxTE_PROCESS_ENTER
;
426 style
|= wxTE_PROCESS_ENTER
;
429 bool forceMLTE
= false ;
430 #if wxUSE_SYSTEM_OPTIONS
431 if ( (wxSystemOptions::HasOption(wxMAC_TEXTCONTROL_USE_MLTE
) ) && ( wxSystemOptions::GetOptionInt( wxMAC_TEXTCONTROL_USE_MLTE
) == 1) )
438 #if MAC_OS_X_VERSION_MAX_ALLOWED > MAC_OS_X_VERSION_10_2
439 if ( UMAGetSystemVersion() >= 0x1030 && forceMLTE
== false )
441 if ( m_windowStyle
& wxTE_MULTILINE
)
442 m_peer
= new wxMacMLTEHIViewControl( this , str
, pos
, size
, style
) ;
447 if ( !(m_windowStyle
& wxTE_MULTILINE
) && forceMLTE
== false )
448 m_peer
= new wxMacUnicodeTextControl( this , str
, pos
, size
, style
) ;
453 m_peer
= new wxMacMLTEClassicControl( this , str
, pos
, size
, style
) ;
456 MacPostControlCreate(pos
,size
) ;
458 // only now the embedding is correct and we can do a positioning update
460 MacSuperChangedPosition() ;
462 if ( m_windowStyle
& wxTE_READONLY
)
464 SetEditable( false ) ;
467 SetCursor( wxCursor( wxCURSOR_IBEAM
) ) ;
472 void wxTextCtrl::MacSuperChangedPosition()
474 wxWindow::MacSuperChangedPosition() ;
475 GetPeer()->SuperChangedPosition() ;
478 void wxTextCtrl::MacVisibilityChanged()
480 GetPeer()->VisibilityChanged( MacIsReallyShown() ) ;
483 void wxTextCtrl::MacEnabledStateChanged()
487 wxString
wxTextCtrl::GetValue() const
489 return GetPeer()->GetStringValue() ;
492 void wxTextCtrl::GetSelection(long* from
, long* to
) const
494 GetPeer()->GetSelection( from
, to
) ;
497 void wxTextCtrl::SetValue(const wxString
& str
)
500 if ( GetValue() == str
)
503 GetPeer()->SetStringValue(str
) ;
505 wxCommandEvent
event(wxEVT_COMMAND_TEXT_UPDATED
, m_windowId
);
506 event
.SetString( GetValue() ) ;
507 event
.SetEventObject( this );
508 GetEventHandler()->ProcessEvent(event
);
511 void wxTextCtrl::SetMaxLength(unsigned long len
)
516 bool wxTextCtrl::SetFont( const wxFont
& font
)
518 if ( !wxTextCtrlBase::SetFont( font
) )
521 GetPeer()->SetFont( font
, GetForegroundColour() , GetWindowStyle() ) ;
525 bool wxTextCtrl::SetStyle(long start
, long end
, const wxTextAttr
& style
)
527 GetPeer()->SetStyle( start
, end
, style
) ;
531 bool wxTextCtrl::SetDefaultStyle(const wxTextAttr
& style
)
533 wxTextCtrlBase::SetDefaultStyle( style
) ;
534 SetStyle( kTXNUseCurrentSelection
, kTXNUseCurrentSelection
, GetDefaultStyle() ) ;
538 // Clipboard operations
539 void wxTextCtrl::Copy()
547 void wxTextCtrl::Cut()
553 wxCommandEvent
event(wxEVT_COMMAND_TEXT_UPDATED
, m_windowId
);
554 event
.SetEventObject( this );
555 GetEventHandler()->ProcessEvent(event
);
559 void wxTextCtrl::Paste()
564 // eventually we should add setting the default style again
566 wxCommandEvent
event(wxEVT_COMMAND_TEXT_UPDATED
, m_windowId
);
567 event
.SetEventObject( this );
568 GetEventHandler()->ProcessEvent(event
);
572 bool wxTextCtrl::CanCopy() const
574 // Can copy if there's a selection
576 GetSelection(& from
, & to
);
580 bool wxTextCtrl::CanCut() const
586 // Can cut if there's a selection
588 GetSelection(& from
, & to
);
592 bool wxTextCtrl::CanPaste() const
597 return GetPeer()->CanPaste() ;
600 void wxTextCtrl::SetEditable(bool editable
)
602 if ( editable
!= m_editable
)
604 m_editable
= editable
;
605 GetPeer()->SetEditable( editable
) ;
609 void wxTextCtrl::SetInsertionPoint(long pos
)
611 SetSelection( pos
, pos
) ;
614 void wxTextCtrl::SetInsertionPointEnd()
616 wxTextPos pos
= GetLastPosition();
617 SetInsertionPoint(pos
);
620 long wxTextCtrl::GetInsertionPoint() const
623 GetSelection( &begin
, &end
) ;
627 wxTextPos
wxTextCtrl::GetLastPosition() const
629 return GetPeer()->GetLastPosition( ) ;
632 void wxTextCtrl::Replace(long from
, long to
, const wxString
& str
)
634 GetPeer()->Replace( from
, to
, str
) ;
637 void wxTextCtrl::Remove(long from
, long to
)
639 GetPeer()->Remove( from
, to
) ;
642 void wxTextCtrl::SetSelection(long from
, long to
)
644 GetPeer()->SetSelection( from
, to
) ;
647 bool wxTextCtrl::LoadFile(const wxString
& file
)
649 if ( wxTextCtrlBase::LoadFile(file
) )
657 void wxTextCtrl::WriteText(const wxString
& str
)
659 // TODO this MPRemoting will be moved into a remoting peer proxy for any command
660 if ( !wxIsMainThread() )
662 // unfortunately CW 8 is not able to correctly deduce the template types, so we have
663 // to instantiate explicitly
664 wxMacMPRemoteGUICall
<wxTextCtrl
,wxString
>( this , &wxTextCtrl::WriteText
, str
) ;
669 GetPeer()->WriteText( str
) ;
673 void wxTextCtrl::AppendText(const wxString
& text
)
675 SetInsertionPointEnd();
679 void wxTextCtrl::Clear()
684 bool wxTextCtrl::IsModified() const
689 bool wxTextCtrl::IsEditable() const
691 return IsEnabled() && m_editable
;
694 bool wxTextCtrl::AcceptsFocus() const
696 // we don't want focus if we can't be edited
697 return /*IsEditable() && */ wxControl::AcceptsFocus();
700 wxSize
wxTextCtrl::DoGetBestSize() const
706 // these are the numbers from the HIG, we reduce them by the borders
709 switch( m_windowVariant
)
711 case wxWINDOW_VARIANT_NORMAL
:
714 case wxWINDOW_VARIANT_SMALL
:
717 case wxWINDOW_VARIANT_MINI
:
725 // as the above numbers have some free space around the text
726 // we get 5 lines like this anyway
727 if ( m_windowStyle
& wxTE_MULTILINE
)
732 if ( !HasFlag(wxNO_BORDER
) )
735 return wxSize(wText
, hText
);
738 // ----------------------------------------------------------------------------
740 // ----------------------------------------------------------------------------
742 void wxTextCtrl::Undo()
750 void wxTextCtrl::Redo()
758 bool wxTextCtrl::CanUndo() const
764 return GetPeer()->CanUndo() ;
767 bool wxTextCtrl::CanRedo() const
773 return GetPeer()->CanRedo() ;
776 void wxTextCtrl::MarkDirty()
781 void wxTextCtrl::DiscardEdits()
786 int wxTextCtrl::GetNumberOfLines() const
788 return GetPeer()->GetNumberOfLines() ;
791 long wxTextCtrl::XYToPosition(long x
, long y
) const
793 return GetPeer()->XYToPosition( x
, y
) ;
796 bool wxTextCtrl::PositionToXY(long pos
, long *x
, long *y
) const
798 return GetPeer()->PositionToXY(pos
, x
, y
) ;
801 void wxTextCtrl::ShowPosition(long pos
)
803 return GetPeer()->ShowPosition(pos
) ;
806 int wxTextCtrl::GetLineLength(long lineNo
) const
808 return GetPeer()->GetLineLength(lineNo
) ;
811 wxString
wxTextCtrl::GetLineText(long lineNo
) const
813 return GetPeer()->GetLineText(lineNo
) ;
820 void wxTextCtrl::Command(wxCommandEvent
& event
)
822 SetValue (event
.GetString());
823 ProcessCommand (event
);
826 void wxTextCtrl::OnDropFiles(wxDropFilesEvent
& event
)
828 // By default, load the first file into the text window.
829 if (event
.GetNumberOfFiles() > 0)
831 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() )
893 if (m_windowStyle
& wxPROCESS_ENTER
)
895 wxCommandEvent
event(wxEVT_COMMAND_TEXT_ENTER
, m_windowId
);
896 event
.SetEventObject( this );
897 event
.SetString( GetValue() );
898 if ( GetEventHandler()->ProcessEvent(event
) )
901 if ( !(m_windowStyle
& wxTE_MULTILINE
) )
903 wxWindow
*parent
= GetParent();
904 while( parent
&& !parent
->IsTopLevel() && parent
->GetDefaultItem() == NULL
) {
905 parent
= parent
->GetParent() ;
907 if ( parent
&& parent
->GetDefaultItem() )
909 wxButton
*def
= wxDynamicCast(parent
->GetDefaultItem(),
911 if ( def
&& def
->IsEnabled() )
913 wxCommandEvent
event(wxEVT_COMMAND_BUTTON_CLICKED
, def
->GetId() );
914 event
.SetEventObject(def
);
920 // this will make wxWidgets eat the ENTER key so that
921 // 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"));
951 // perform keystroke handling
952 if ( wxTheApp
->MacGetCurrentEvent() != NULL
&& wxTheApp
->MacGetCurrentEventHandlerCallRef() != NULL
)
953 CallNextEventHandler((EventHandlerCallRef
)wxTheApp
->MacGetCurrentEventHandlerCallRef() , (EventRef
) wxTheApp
->MacGetCurrentEvent() ) ;
957 if ( wxMacConvertEventToRecord( (EventRef
) wxTheApp
->MacGetCurrentEvent() , &rec
) )
959 EventRecord
*ev
= &rec
;
962 keychar
= short(ev
->message
& charCodeMask
);
963 keycode
= short(ev
->message
& keyCodeMask
) >> 8 ;
965 m_peer
->HandleKey( keycode
, keychar
, ev
->modifiers
) ;
969 if ( ( key
>= 0x20 && key
< WXK_START
) ||
974 wxCommandEvent
event1(wxEVT_COMMAND_TEXT_UPDATED
, m_windowId
);
975 event1
.SetEventObject( this );
976 wxPostEvent(GetEventHandler(),event1
);
980 // ----------------------------------------------------------------------------
981 // standard handlers for standard edit menu events
982 // ----------------------------------------------------------------------------
984 void wxTextCtrl::OnCut(wxCommandEvent
& WXUNUSED(event
))
989 void wxTextCtrl::OnCopy(wxCommandEvent
& WXUNUSED(event
))
994 void wxTextCtrl::OnPaste(wxCommandEvent
& WXUNUSED(event
))
999 void wxTextCtrl::OnUndo(wxCommandEvent
& WXUNUSED(event
))
1004 void wxTextCtrl::OnRedo(wxCommandEvent
& WXUNUSED(event
))
1009 void wxTextCtrl::OnDelete(wxCommandEvent
& WXUNUSED(event
))
1012 GetSelection(& from
, & to
);
1013 if (from
!= -1 && to
!= -1)
1017 void wxTextCtrl::OnSelectAll(wxCommandEvent
& WXUNUSED(event
))
1019 SetSelection(-1, -1);
1022 void wxTextCtrl::OnUpdateCut(wxUpdateUIEvent
& event
)
1024 event
.Enable( CanCut() );
1027 void wxTextCtrl::OnUpdateCopy(wxUpdateUIEvent
& event
)
1029 event
.Enable( CanCopy() );
1032 void wxTextCtrl::OnUpdatePaste(wxUpdateUIEvent
& event
)
1034 event
.Enable( CanPaste() );
1037 void wxTextCtrl::OnUpdateUndo(wxUpdateUIEvent
& event
)
1039 event
.Enable( CanUndo() );
1042 void wxTextCtrl::OnUpdateRedo(wxUpdateUIEvent
& event
)
1044 event
.Enable( CanRedo() );
1047 void wxTextCtrl::OnUpdateDelete(wxUpdateUIEvent
& event
)
1050 GetSelection(& from
, & to
);
1051 event
.Enable(from
!= -1 && to
!= -1 && from
!= to
&& IsEditable()) ;
1054 void wxTextCtrl::OnUpdateSelectAll(wxUpdateUIEvent
& event
)
1056 event
.Enable(GetLastPosition() > 0);
1059 // CS: Context Menus only work with mlte implementations or non-multiline HIViews at the moment
1061 void wxTextCtrl::OnContextMenu(wxContextMenuEvent
& event
)
1063 if (m_privateContextMenu
== NULL
)
1065 m_privateContextMenu
= new wxMenu
;
1066 m_privateContextMenu
->Append(wxID_UNDO
, _("&Undo"));
1067 m_privateContextMenu
->Append(wxID_REDO
, _("&Redo"));
1068 m_privateContextMenu
->AppendSeparator();
1069 m_privateContextMenu
->Append(wxID_CUT
, _("Cu&t"));
1070 m_privateContextMenu
->Append(wxID_COPY
, _("&Copy"));
1071 m_privateContextMenu
->Append(wxID_PASTE
, _("&Paste"));
1072 m_privateContextMenu
->Append(wxID_CLEAR
, _("&Delete"));
1073 m_privateContextMenu
->AppendSeparator();
1074 m_privateContextMenu
->Append(wxID_SELECTALL
, _("Select &All"));
1077 if (m_privateContextMenu
!= NULL
)
1078 PopupMenu(m_privateContextMenu
);
1081 bool wxTextCtrl::MacSetupCursor( const wxPoint
& pt
)
1083 if ( !GetPeer()->SetupCursor(pt
) )
1084 return wxWindow::MacSetupCursor( pt
) ;
1088 #if !TARGET_API_MAC_OSX
1090 // user pane implementation
1092 void wxTextCtrl::MacControlUserPaneDrawProc(wxInt16 part
)
1094 GetPeer()->MacControlUserPaneDrawProc( part
) ;
1097 wxInt16
wxTextCtrl::MacControlUserPaneHitTestProc(wxInt16 x
, wxInt16 y
)
1099 return GetPeer()->MacControlUserPaneHitTestProc( x
, y
) ;
1102 wxInt16
wxTextCtrl::MacControlUserPaneTrackingProc(wxInt16 x
, wxInt16 y
, void* actionProc
)
1104 return GetPeer()->MacControlUserPaneTrackingProc( x
, y
, actionProc
) ;
1107 void wxTextCtrl::MacControlUserPaneIdleProc()
1109 GetPeer()->MacControlUserPaneIdleProc( ) ;
1112 wxInt16
wxTextCtrl::MacControlUserPaneKeyDownProc(wxInt16 keyCode
, wxInt16 charCode
, wxInt16 modifiers
)
1114 return GetPeer()->MacControlUserPaneKeyDownProc( keyCode
, charCode
, modifiers
) ;
1117 void wxTextCtrl::MacControlUserPaneActivateProc(bool activating
)
1119 GetPeer()->MacControlUserPaneActivateProc( activating
) ;
1122 wxInt16
wxTextCtrl::MacControlUserPaneFocusProc(wxInt16 action
)
1124 return GetPeer()->MacControlUserPaneFocusProc( action
) ;
1127 void wxTextCtrl::MacControlUserPaneBackgroundProc(void* info
)
1129 GetPeer()->MacControlUserPaneBackgroundProc( info
) ;
1133 // ----------------------------------------------------------------------------
1134 // implementation base class
1135 // ----------------------------------------------------------------------------
1137 wxMacTextControl::wxMacTextControl(wxTextCtrl
* peer
) :
1138 wxMacControl( peer
)
1142 wxMacTextControl::~wxMacTextControl()
1146 void wxMacTextControl::SetStyle(long start
, long end
, const wxTextAttr
& style
)
1150 void wxMacTextControl::Copy()
1154 void wxMacTextControl::Cut()
1158 void wxMacTextControl::Paste()
1162 bool wxMacTextControl::CanPaste() const
1167 void wxMacTextControl::SetEditable(bool editable
)
1171 wxTextPos
wxMacTextControl::GetLastPosition() const
1173 return GetStringValue().Length() ;
1176 void wxMacTextControl::Replace( long from
, long to
, const wxString str
)
1180 void wxMacTextControl::Clear()
1182 SetStringValue( wxEmptyString
) ;
1185 bool wxMacTextControl::CanUndo() const
1190 void wxMacTextControl::Undo() { }
1192 bool wxMacTextControl::CanRedo() const
1197 void wxMacTextControl::Redo()
1201 long wxMacTextControl::XYToPosition(long x
, long y
) const
1206 bool wxMacTextControl::PositionToXY(long pos
, long *x
, long *y
) const
1211 void wxMacTextControl::ShowPosition( long WXUNUSED(pos
) )
1215 int wxMacTextControl::GetNumberOfLines() const
1217 ItemCount lines
= 0 ;
1218 wxString content
= GetStringValue() ;
1220 for (size_t i
= 0; i
< content
.Length() ; i
++)
1222 if (content
[i
] == '\r') lines
++;
1227 wxString
wxMacTextControl::GetLineText(long lineNo
) const
1229 // TODO change this if possible to reflect real lines
1230 wxString content
= GetStringValue() ;
1234 for (size_t i
= 0; i
< content
.Length() ; i
++)
1236 if (count
== lineNo
)
1238 // Add chars in line then
1241 for (size_t j
= i
; j
< content
.Length(); j
++)
1243 if (content
[j
] == '\n')
1251 if (content
[i
] == '\n') count
++;
1253 return wxEmptyString
;
1256 int wxMacTextControl::GetLineLength(long lineNo
) const
1258 // TODO change this if possible to reflect real lines
1259 wxString content
= GetStringValue() ;
1263 for (size_t i
= 0; i
< content
.Length() ; i
++)
1265 if (count
== lineNo
)
1267 // Count chars in line then
1269 for (size_t j
= i
; j
< content
.Length(); j
++)
1272 if (content
[j
] == '\n') return count
;
1277 if (content
[i
] == '\n') count
++;
1282 // ----------------------------------------------------------------------------
1283 // standard unicode control implementation
1284 // ----------------------------------------------------------------------------
1286 #if TARGET_API_MAC_OSX
1288 wxMacUnicodeTextControl::wxMacUnicodeTextControl( wxTextCtrl
*wxPeer
,
1289 const wxString
& str
,
1291 const wxSize
& size
, long style
) : wxMacTextControl( wxPeer
)
1293 m_font
= wxPeer
->GetFont() ;
1294 m_windowStyle
= style
;
1295 Rect bounds
= wxMacGetBoundsForControl( wxPeer
, pos
, size
) ;
1297 wxMacConvertNewlines10To13( &st
) ;
1298 wxMacCFStringHolder
cf(st
, m_font
.GetEncoding()) ;
1299 CFStringRef cfr
= cf
;
1300 Boolean isPassword
= ( m_windowStyle
& wxTE_PASSWORD
) != 0 ;
1301 m_valueTag
= isPassword
? kControlEditTextPasswordCFStringTag
: kControlEditTextCFStringTag
;
1302 CreateEditUnicodeTextControl( MAC_WXHWND(wxPeer
->MacGetTopLevelWindowRef()), &bounds
, cfr
, isPassword
, NULL
, &m_controlRef
) ;
1304 if ( !(m_windowStyle
& wxTE_MULTILINE
) )
1306 SetData
<Boolean
>( kControlEditTextPart
, kControlEditTextSingleLineTag
, true ) ;
1310 wxMacUnicodeTextControl::~wxMacUnicodeTextControl()
1314 void wxMacUnicodeTextControl::VisibilityChanged(bool shown
)
1316 if ( !(m_windowStyle
& wxTE_MULTILINE
) && shown
)
1318 // work around a refresh issue insofar as not always the entire content is shown even if this would be possible
1319 ControlEditTextSelectionRec sel
;
1320 CFStringRef value
= NULL
;
1322 verify_noerr( GetData
<ControlEditTextSelectionRec
>( 0, kControlEditTextSelectionTag
, &sel
) );
1323 verify_noerr( GetData
<CFStringRef
>( 0, m_valueTag
, &value
) );
1324 verify_noerr( SetData
<CFStringRef
>( 0, m_valueTag
, &value
) );
1325 verify_noerr( SetData
<ControlEditTextSelectionRec
>( 0, kControlEditTextSelectionTag
, &sel
) );
1327 CFRelease( value
) ;
1330 wxString
wxMacUnicodeTextControl::GetStringValue() const
1333 CFStringRef value
= GetData
<CFStringRef
>(0,m_valueTag
) ;
1336 wxMacCFStringHolder
cf(value
) ;
1337 result
= cf
.AsString() ;
1340 wxMacConvertNewlines13To10( &result
) ;
1342 wxMacConvertNewlines10To13( &result
) ;
1346 void wxMacUnicodeTextControl::SetStringValue( const wxString
&str
)
1349 wxMacConvertNewlines10To13( &st
) ;
1350 wxMacCFStringHolder
cf(st
, m_font
.GetEncoding() ) ;
1351 verify_noerr( SetData
<CFStringRef
>( 0, m_valueTag
, cf
) ) ;
1353 void wxMacUnicodeTextControl::Copy()
1355 SendHICommand( kHICommandCopy
) ;
1357 void wxMacUnicodeTextControl::Cut()
1359 SendHICommand( kHICommandCut
) ;
1361 void wxMacUnicodeTextControl::Paste()
1363 SendHICommand( kHICommandPaste
) ;
1365 bool wxMacUnicodeTextControl::CanPaste() const
1369 void wxMacUnicodeTextControl::SetEditable(bool editable
)
1371 SetData
<Boolean
>( 0 , kControlEditTextLockedTag
, (Boolean
) !editable
) ;
1373 void wxMacUnicodeTextControl::Remove( long from
, long to
)
1377 void wxMacUnicodeTextControl::GetSelection( long* from
, long* to
) const
1379 ControlEditTextSelectionRec sel
;
1380 verify_noerr(GetData
<ControlEditTextSelectionRec
>( 0, kControlEditTextSelectionTag
, &sel
) ) ;
1381 if ( from
) *from
= sel
.selStart
;
1382 if ( to
) *to
= sel
.selEnd
;
1385 void wxMacUnicodeTextControl::SetSelection( long from
, long to
)
1387 ControlEditTextSelectionRec sel
;
1388 if ((from
== -1) && (to
== -1))
1391 to
= 32767 ; // sel has 16 bit signed values, max is 32767
1393 sel
.selStart
= from
;
1395 SetData
<ControlEditTextSelectionRec
>( 0 , kControlEditTextSelectionTag
, &sel
) ;
1398 void wxMacUnicodeTextControl::WriteText(const wxString
& str
)
1401 wxMacConvertNewlines10To13( &st
) ;
1402 #if MAC_OS_X_VERSION_MAX_ALLOWED > MAC_OS_X_VERSION_10_2
1403 wxMacCFStringHolder
cf(st
, m_font
.GetEncoding() ) ;
1404 CFStringRef value
= cf
;
1405 SetData
<CFStringRef
>( 0, kControlEditTextInsertCFStringRefTag
, &value
);
1407 wxString val
= GetStringValue() ;
1409 GetSelection( &start
, &end
) ;
1410 val
.Remove( start
, end
- start
) ;
1411 val
.insert( start
, str
) ;
1412 SetStringValue( val
) ;
1413 SetSelection( start
+ str
.Length() , start
+ str
.Length() ) ;
1419 // ----------------------------------------------------------------------------
1420 // MLTE control implementation (common part)
1421 // ----------------------------------------------------------------------------
1423 // if mlte is on read only , no changes at all are allowed, not even from
1424 // procedural API, in order to allow changes via API all the same we must undo
1425 // the readonly status while we are executing, this class helps to do so
1427 class wxMacEditHelper
1430 wxMacEditHelper( TXNObject txn
)
1432 TXNControlTag tag
[] = { kTXNIOPrivilegesTag
} ;
1434 TXNGetTXNObjectControls( m_txn
, 1 , tag
, m_data
) ;
1435 if ( m_data
[0].uValue
== kTXNReadOnly
)
1437 TXNControlData data
[] = { { kTXNReadWrite
} } ;
1438 TXNSetTXNObjectControls( m_txn
, false , 1 , tag
, data
) ;
1443 TXNControlTag tag
[] = { kTXNIOPrivilegesTag
} ;
1444 if ( m_data
[0].uValue
== kTXNReadOnly
)
1446 TXNSetTXNObjectControls( m_txn
, false , 1 , tag
, m_data
) ;
1451 TXNControlData m_data
[1] ;
1454 wxMacMLTEControl::wxMacMLTEControl( wxTextCtrl
*peer
) : wxMacTextControl( peer
)
1456 SetNeedsFocusRect( true ) ;
1459 wxString
wxMacMLTEControl::GetStringValue() const
1463 Size actualSize
= 0;
1467 err
= TXNGetDataEncoded( m_txn
, kTXNStartOffset
, kTXNEndOffset
, &theText
, kTXNUnicodeTextData
);
1475 actualSize
= GetHandleSize( theText
) / sizeof( UniChar
) ;
1476 if ( actualSize
> 0 )
1478 wxChar
*ptr
= NULL
;
1479 #if SIZEOF_WCHAR_T == 2
1480 ptr
= new wxChar
[actualSize
+ 1 ] ;
1481 wxStrncpy( ptr
, (wxChar
*) *theText
, actualSize
) ;
1483 SetHandleSize( theText
, ( actualSize
+ 1 ) * sizeof( UniChar
) ) ;
1485 (((UniChar
*)*theText
)[actualSize
]) = 0 ;
1486 wxMBConvUTF16 converter
;
1487 size_t noChars
= converter
.MB2WC( NULL
, (const char*)*theText
, 0 ) ;
1488 ptr
= new wxChar
[noChars
+ 1] ;
1490 noChars
= converter
.MB2WC( ptr
, (const char*)*theText
, noChars
) ;
1492 HUnlock( theText
) ;
1494 ptr
[actualSize
] = 0 ;
1495 result
= wxString( ptr
) ;
1498 DisposeHandle( theText
) ;
1502 err
= TXNGetDataEncoded( m_txn
, kTXNStartOffset
, kTXNEndOffset
, &theText
, kTXNTextData
);
1510 actualSize
= GetHandleSize( theText
) ;
1511 if ( actualSize
> 0 )
1514 result
= wxString( *theText
, wxConvLocal
, actualSize
) ;
1515 HUnlock( theText
) ;
1517 DisposeHandle( theText
) ;
1522 wxMacConvertNewlines13To10( &result
) ;
1524 wxMacConvertNewlines10To13( &result
) ;
1529 void wxMacMLTEControl::SetStringValue( const wxString
&str
)
1533 wxMacConvertNewlines10To13( &st
) ;
1535 wxMacWindowClipper
c( m_peer
) ;
1537 wxMacEditHelper
help(m_txn
) ;
1538 SetTXNData( st
, kTXNStartOffset
, kTXNEndOffset
) ;
1540 TXNSetSelection( m_txn
, 0, 0);
1541 TXNShowSelection( m_txn
, kTXNShowStart
);
1545 TXNFrameOptions
wxMacMLTEControl::FrameOptionsFromWXStyle( long wxStyle
)
1547 TXNFrameOptions frameOptions
=
1548 kTXNDontDrawCaretWhenInactiveMask
1549 #if MAC_OS_X_VERSION_MAX_ALLOWED >= MAC_OS_X_VERSION_10_3
1550 | kTXNDoFontSubstitutionMask
1554 if ( ! ( wxStyle
& wxTE_NOHIDESEL
) )
1555 frameOptions
|= kTXNDontDrawSelectionWhenInactiveMask
;
1557 if ( wxStyle
& wxTE_MULTILINE
)
1559 if ( ! ( wxStyle
& wxTE_DONTWRAP
) )
1560 frameOptions
|= kTXNAlwaysWrapAtViewEdgeMask
;
1563 frameOptions
|= kTXNAlwaysWrapAtViewEdgeMask
;
1564 frameOptions
|= kTXNWantHScrollBarMask
;
1567 if ( !(wxStyle
& wxTE_NO_VSCROLL
) )
1569 frameOptions
|= kTXNWantVScrollBarMask
;
1570 if ( frameOptions
& kTXNWantHScrollBarMask
)
1571 frameOptions
|= kTXNDrawGrowIconMask
;
1575 frameOptions
|= kTXNSingleLineOnlyMask
;
1577 if ( wxStyle
& wxHSCROLL
)
1578 frameOptions
|= kTXNWantHScrollBarMask
;
1580 return frameOptions
;
1583 void wxMacMLTEControl::AdjustCreationAttributes( const wxColour
&background
, bool visible
)
1585 TXNControlTag iControlTags
[] =
1587 kTXNDoFontSubstitution
,
1588 kTXNWordWrapStateTag
,
1590 TXNControlData iControlData
[] =
1596 int toptag
= WXSIZEOF( iControlTags
) ;
1598 if ( m_windowStyle
& wxTE_MULTILINE
)
1600 if (m_windowStyle
& wxTE_DONTWRAP
)
1601 iControlData
[1].uValue
= kTXNNoAutoWrap
;
1603 iControlData
[1].uValue
= kTXNAutoWrap
;
1605 verify_noerr( TXNSetTXNObjectControls( m_txn
, false, toptag
,
1606 iControlTags
, iControlData
)) ;
1608 // setting the default font
1609 // under 10.2 this causes a visible caret, therefore we avoid it
1611 if ( UMAGetSystemVersion() >= 0x1030 )
1617 GetThemeFont(kThemeSystemFont
, GetApplicationScript() , fontName
, &fontSize
, &fontStyle
) ;
1619 TXNTypeAttributes typeAttr
[] =
1621 { kTXNQDFontNameAttribute
, kTXNQDFontNameAttributeSize
, { (void*) fontName
} } ,
1622 { kTXNQDFontSizeAttribute
, kTXNFontSizeAttributeSize
, { (void*) (fontSize
<< 16) } } ,
1623 { kTXNQDFontStyleAttribute
, kTXNQDFontStyleAttributeSize
, { (void*) normal
} } ,
1626 verify_noerr( TXNSetTypeAttributes (m_txn
, sizeof( typeAttr
) / sizeof(TXNTypeAttributes
) , typeAttr
,
1631 if ( m_windowStyle
& wxTE_PASSWORD
)
1634 verify_noerr(TXNEchoMode( m_txn
, c
, 0 , true )) ;
1637 TXNBackground tback
;
1638 tback
.bgType
= kTXNBackgroundTypeRGB
;
1639 tback
.bg
.color
= MAC_WXCOLORREF( background
.GetPixel() );
1640 TXNSetBackground( m_txn
, &tback
);
1643 void wxMacMLTEControl::SetBackground( const wxBrush
&brush
)
1645 // currently only solid background are supported
1646 TXNBackground tback
;
1647 tback
.bgType
= kTXNBackgroundTypeRGB
;
1648 tback
.bg
.color
= MAC_WXCOLORREF( brush
.GetColour().GetPixel() );
1649 TXNSetBackground( m_txn
, &tback
);
1652 void wxMacMLTEControl::TXNSetAttribute( const wxTextAttr
& style
, long from
, long to
)
1654 TXNTypeAttributes typeAttr
[4] ;
1655 Str255 fontName
= "\pMonaco" ;
1656 SInt16 fontSize
= 12 ;
1657 Style fontStyle
= normal
;
1659 int attrCounter
= 0 ;
1660 if ( style
.HasFont() )
1662 const wxFont
&font
= style
.GetFont() ;
1663 wxMacStringToPascal( font
.GetFaceName() , fontName
) ;
1664 fontSize
= font
.GetPointSize() ;
1665 if ( font
.GetUnderlined() )
1666 fontStyle
|= underline
;
1667 if ( font
.GetWeight() == wxBOLD
)
1669 if ( font
.GetStyle() == wxITALIC
)
1670 fontStyle
|= italic
;
1672 typeAttr
[attrCounter
].tag
= kTXNQDFontNameAttribute
;
1673 typeAttr
[attrCounter
].size
= kTXNQDFontNameAttributeSize
;
1674 typeAttr
[attrCounter
].data
.dataPtr
= (void*) fontName
;
1675 typeAttr
[attrCounter
+1].tag
= kTXNQDFontSizeAttribute
;
1676 typeAttr
[attrCounter
+1].size
= kTXNFontSizeAttributeSize
;
1677 typeAttr
[attrCounter
+1].data
.dataValue
= (fontSize
<< 16) ;
1678 typeAttr
[attrCounter
+2].tag
= kTXNQDFontStyleAttribute
;
1679 typeAttr
[attrCounter
+2].size
= kTXNQDFontStyleAttributeSize
;
1680 typeAttr
[attrCounter
+2].data
.dataValue
= fontStyle
;
1683 if ( style
.HasTextColour() )
1685 typeAttr
[attrCounter
].tag
= kTXNQDFontColorAttribute
;
1686 typeAttr
[attrCounter
].size
= kTXNQDFontColorAttributeSize
;
1687 typeAttr
[attrCounter
].data
.dataPtr
= (void*) &color
;
1688 color
= MAC_WXCOLORREF(style
.GetTextColour().GetPixel()) ;
1691 if ( attrCounter
> 0 )
1693 verify_noerr( TXNSetTypeAttributes ( m_txn
, attrCounter
, typeAttr
, from
, to
) );
1697 void wxMacMLTEControl::SetFont( const wxFont
& font
, const wxColour
& foreground
, long windowStyle
)
1699 wxMacEditHelper
help(m_txn
) ;
1700 TXNSetAttribute( wxTextAttr(foreground
,wxNullColour
,font
) , kTXNStartOffset
,kTXNEndOffset
) ;
1702 void wxMacMLTEControl::SetStyle(long start
, long end
, const wxTextAttr
& style
)
1704 wxMacEditHelper
help(m_txn
) ;
1705 TXNSetAttribute( style
, start
,end
) ;
1708 void wxMacMLTEControl::Copy()
1710 ClearCurrentScrap();
1712 TXNConvertToPublicScrap();
1715 void wxMacMLTEControl::Cut()
1717 ClearCurrentScrap();
1719 TXNConvertToPublicScrap();
1722 void wxMacMLTEControl::Paste()
1724 TXNConvertFromPublicScrap();
1728 bool wxMacMLTEControl::CanPaste() const
1730 return TXNIsScrapPastable() ;
1733 void wxMacMLTEControl::SetEditable(bool editable
)
1735 TXNControlTag tag
[] = { kTXNIOPrivilegesTag
} ;
1736 TXNControlData data
[] = { { editable
? kTXNReadWrite
: kTXNReadOnly
} } ;
1737 TXNSetTXNObjectControls( m_txn
, false , WXSIZEOF(tag
) , tag
, data
) ;
1740 wxTextPos
wxMacMLTEControl::GetLastPosition() const
1742 wxTextPos actualsize
= 0 ;
1745 OSErr err
= TXNGetDataEncoded( m_txn
, kTXNStartOffset
, kTXNEndOffset
, &theText
, kTXNTextData
);
1753 actualsize
= GetHandleSize( theText
) ;
1754 DisposeHandle( theText
) ;
1760 void wxMacMLTEControl::Replace( long from
, long to
, const wxString str
)
1762 wxString value
= str
;
1763 wxMacConvertNewlines10To13( &value
) ;
1765 wxMacEditHelper
help( m_txn
) ;
1766 wxMacWindowClipper
c( m_peer
) ;
1768 TXNSetSelection(m_txn
, from
, to
) ;
1770 SetTXNData( value
, kTXNUseCurrentSelection
, kTXNUseCurrentSelection
) ;
1773 void wxMacMLTEControl::Remove( long from
, long to
)
1775 wxMacWindowClipper
c( m_peer
) ;
1776 wxMacEditHelper
help( m_txn
) ;
1777 TXNSetSelection(m_txn
, from
, to
) ;
1781 void wxMacMLTEControl::GetSelection( long* from
, long* to
) const
1783 TXNGetSelection( m_txn
, (TXNOffset
*) from
, (TXNOffset
*) to
) ;
1786 void wxMacMLTEControl::SetSelection( long from
, long to
)
1788 wxMacWindowClipper
c( m_peer
) ;
1789 /* change the selection */
1790 if ((from
== -1) && (to
== -1))
1791 TXNSelectAll(m_txn
);
1793 TXNSetSelection( m_txn
, from
, to
);
1794 TXNShowSelection( m_txn
, kTXNShowStart
);
1797 void wxMacMLTEControl::WriteText(const wxString
& str
)
1800 wxMacConvertNewlines10To13( &st
) ;
1802 long start
, end
, dummy
;
1803 GetSelection( &start
, &dummy
) ;
1804 wxMacWindowClipper
c( m_peer
) ;
1806 wxMacEditHelper
helper( m_txn
) ;
1807 SetTXNData( st
, kTXNUseCurrentSelection
, kTXNUseCurrentSelection
) ;
1809 GetSelection( &dummy
, &end
) ;
1810 // TODO SetStyle( start , end , GetDefaultStyle() ) ;
1813 void wxMacMLTEControl::Clear()
1815 wxMacWindowClipper
c( m_peer
) ;
1816 wxMacEditHelper
st(m_txn
) ;
1817 TXNSetSelection( m_txn
, kTXNStartOffset
, kTXNEndOffset
) ;
1821 bool wxMacMLTEControl::CanUndo() const
1823 return TXNCanUndo( m_txn
, NULL
) ;
1826 void wxMacMLTEControl::Undo()
1831 bool wxMacMLTEControl::CanRedo() const
1833 return TXNCanRedo( m_txn
, NULL
) ;
1836 void wxMacMLTEControl::Redo()
1841 int wxMacMLTEControl::GetNumberOfLines() const
1843 ItemCount lines
= 0 ;
1844 TXNGetLineCount(m_txn
, &lines
) ;
1848 long wxMacMLTEControl::XYToPosition(long x
, long y
) const
1852 wxTextPos lastpos
= GetLastPosition() ;
1854 // TODO find a better implementation : while we can get the
1855 // line metrics of a certain line, we don't get its starting
1856 // position, so it would probably be rather a binary search
1857 // for the start position
1860 int lastHeight
= 0 ;
1863 for ( n
= 0 ; n
<= (ItemCount
) lastpos
; ++n
)
1865 if ( y
== ypos
&& x
== xpos
)
1868 TXNOffsetToPoint( m_txn
, n
, &curpt
);
1870 if ( curpt
.v
> lastHeight
)
1875 lastHeight
= curpt
.v
;
1883 bool wxMacMLTEControl::PositionToXY(long pos
, long *x
, long *y
) const
1887 wxTextPos lastpos
= GetLastPosition() ;
1892 if ( pos
<= lastpos
)
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
) pos
; ++n
)
1905 TXNOffsetToPoint(m_txn
, n
, &curpt
);
1907 if ( curpt
.v
> lastHeight
)
1912 lastHeight
= curpt
.v
;
1917 if ( y
) *y
= ypos
;
1918 if ( x
) *x
= xpos
;
1924 void wxMacMLTEControl::ShowPosition( long pos
)
1926 #if TARGET_RT_MAC_MACHO && defined(AVAILABLE_MAC_OS_X_VERSION_10_2_AND_LATER)
1930 TXNOffset selstart
, selend
;
1931 TXNGetSelection( m_txn
, &selstart
, &selend
) ;
1932 TXNOffsetToPoint( m_txn
, selstart
, ¤t
);
1933 TXNOffsetToPoint( m_txn
, pos
, &desired
);
1934 //TODO use HIPoints for 10.3 and above
1935 if ( (UInt32
) TXNScroll
!= (UInt32
) kUnresolvedCFragSymbolAddress
)
1937 OSErr theErr
= noErr
;
1938 SInt32 dv
= desired
.v
- current
.v
;
1939 SInt32 dh
= desired
.h
- current
.h
;
1940 TXNShowSelection( m_txn
, true ) ;
1941 theErr
= TXNScroll( m_txn
, kTXNScrollUnitsInPixels
, kTXNScrollUnitsInPixels
, &dv
, &dh
);
1942 // there will be an error returned for classic mlte implementation when the control is
1943 // invisible, but HITextView works correctly, so we don't assert that one
1944 // wxASSERT_MSG( theErr == noErr, _T("TXNScroll returned an error!") );
1950 void wxMacMLTEControl::SetTXNData( const wxString
& st
, TXNOffset start
, TXNOffset end
)
1953 #if SIZEOF_WCHAR_T == 2
1954 size_t len
= st
.Len() ;
1955 TXNSetData( m_txn
, kTXNUnicodeTextData
, (void*)st
.wc_str(), len
* 2,
1958 wxMBConvUTF16 converter
;
1959 ByteCount byteBufferLen
= converter
.WC2MB( NULL
, st
.wc_str() , 0 ) ;
1960 UniChar
*unibuf
= (UniChar
*) malloc(byteBufferLen
) ;
1961 converter
.WC2MB( (char*) unibuf
, st
.wc_str() , byteBufferLen
) ;
1962 TXNSetData( m_txn
, kTXNUnicodeTextData
, (void*)unibuf
, byteBufferLen
,
1967 wxCharBuffer text
= st
.mb_str(wxConvLocal
) ;
1968 TXNSetData( m_txn
, kTXNTextData
, (void*)text
.data(), strlen( text
) ,
1974 wxString
wxMacMLTEControl::GetLineText(long lineNo
) const
1978 if ( lineNo
< GetNumberOfLines() )
1986 // get the first possible position in the control
1988 TXNOffsetToPoint(m_txn
, 0, &firstPoint
);
1990 // Iterate through the lines until we reach the one we want,
1991 // adding to our current y pixel point position
1992 while (ypos
< lineNo
)
1994 TXNGetLineMetrics(m_txn
, ypos
++, &lineWidth
, &lineHeight
);
1995 currentHeight
+= lineHeight
;
1998 Point thePoint
= { firstPoint
.v
+ (currentHeight
>> 16), firstPoint
.h
+ (0) };
1999 TXNOffset theOffset
;
2000 TXNPointToOffset(m_txn
, thePoint
, &theOffset
);
2002 wxString content
= GetStringValue() ;
2003 Point currentPoint
= thePoint
;
2004 while(thePoint
.v
== currentPoint
.v
&& theOffset
< content
.length())
2006 line
+= content
[theOffset
];
2007 TXNOffsetToPoint(m_txn
, ++theOffset
, ¤tPoint
);
2013 int wxMacMLTEControl::GetLineLength(long lineNo
) const
2017 if ( lineNo
< GetNumberOfLines() )
2025 // get the first possible position in the control
2027 TXNOffsetToPoint(m_txn
, 0, &firstPoint
);
2029 // Iterate through the lines until we reach the one we want,
2030 // adding to our current y pixel point position
2031 while (ypos
< lineNo
)
2033 TXNGetLineMetrics(m_txn
, ypos
++, &lineWidth
, &lineHeight
);
2034 currentHeight
+= lineHeight
;
2037 Point thePoint
= { firstPoint
.v
+ (currentHeight
>> 16), firstPoint
.h
+ (0) };
2038 TXNOffset theOffset
;
2039 TXNPointToOffset(m_txn
, thePoint
, &theOffset
);
2041 wxString content
= GetStringValue() ;
2042 Point currentPoint
= thePoint
;
2043 while(thePoint
.v
== currentPoint
.v
&& theOffset
< content
.length())
2046 TXNOffsetToPoint(m_txn
, ++theOffset
, ¤tPoint
);
2053 // ----------------------------------------------------------------------------
2054 // MLTE control implementation (classic part)
2055 // ----------------------------------------------------------------------------
2057 // OS X Notes : We still don't have a full replacement for MLTE, so this implementation
2058 // has to live on. We have different problems coming from outdated implementations on the
2059 // various OS X versions. Most deal with the scrollbars: they are not correctly embedded
2060 // while this can be solved on 10.3 by reassigning them the correct place, on 10.2 there is
2061 // no way out, therefore we are using our own implementation and our own scrollbars ....
2063 #ifdef __WXMAC_OSX__
2065 TXNScrollInfoUPP gTXNScrollInfoProc
= NULL
;
2066 ControlActionUPP gTXNScrollActionProc
= NULL
;
2068 pascal void wxMacMLTEClassicControl::TXNScrollInfoProc (SInt32 iValue
, SInt32 iMaximumValue
, TXNScrollBarOrientation
2069 iScrollBarOrientation
, SInt32 iRefCon
)
2071 wxMacMLTEClassicControl
* mlte
= (wxMacMLTEClassicControl
*) iRefCon
;
2072 SInt32 value
= wxMax( iValue
, 0 ) ;
2073 SInt32 maximum
= wxMax( iMaximumValue
, 0 ) ;
2075 if ( iScrollBarOrientation
== kTXNHorizontal
)
2077 if ( mlte
->m_sbHorizontal
)
2079 SetControl32BitValue( mlte
->m_sbHorizontal
, value
) ;
2080 SetControl32BitMaximum( mlte
->m_sbHorizontal
, maximum
) ;
2081 mlte
->m_lastHorizontalValue
= value
;
2084 else if ( iScrollBarOrientation
== kTXNVertical
)
2086 if ( mlte
->m_sbVertical
)
2088 SetControl32BitValue( mlte
->m_sbVertical
, value
) ;
2089 SetControl32BitMaximum( mlte
->m_sbVertical
, maximum
) ;
2090 mlte
->m_lastVerticalValue
= value
;
2095 pascal void wxMacMLTEClassicControl::TXNScrollActionProc( ControlRef controlRef
, ControlPartCode partCode
)
2098 wxMacMLTEClassicControl
* mlte
= (wxMacMLTEClassicControl
*) GetControlReference( controlRef
) ;
2102 if ( controlRef
!= mlte
->m_sbVertical
&& controlRef
!= mlte
->m_sbHorizontal
)
2105 bool isHorizontal
= ( controlRef
== mlte
->m_sbHorizontal
) ;
2107 SInt32 minimum
= 0 ;
2108 SInt32 maximum
= GetControl32BitMaximum( controlRef
) ;
2109 SInt32 value
= GetControl32BitValue( controlRef
) ;
2113 case kControlDownButtonPart
:
2116 case kControlUpButtonPart
:
2119 case kControlPageDownPart
:
2120 delta
= GetControlViewSize( controlRef
) ;
2122 case kControlPageUpPart
:
2123 delta
= -GetControlViewSize( controlRef
) ;
2125 case kControlIndicatorPart
:
2127 ( isHorizontal
? mlte
->m_lastHorizontalValue
: mlte
->m_lastVerticalValue
) ;
2134 SInt32 newValue
= value
;
2136 if ( partCode
!= kControlIndicatorPart
)
2138 if( value
+ delta
< minimum
)
2139 delta
= minimum
- value
;
2140 if ( value
+ delta
> maximum
)
2141 delta
= maximum
- value
;
2143 SetControl32BitValue( controlRef
, value
+ delta
) ;
2144 newValue
= value
+ delta
;
2147 SInt32 verticalDelta
= isHorizontal
? 0 : delta
;
2148 SInt32 horizontalDelta
= isHorizontal
? delta
: 0 ;
2150 err
= TXNScroll( mlte
->m_txn
, kTXNScrollUnitsInPixels
, kTXNScrollUnitsInPixels
,
2151 &verticalDelta
, &horizontalDelta
);
2154 mlte
->m_lastHorizontalValue
= newValue
;
2156 mlte
->m_lastVerticalValue
= newValue
;
2161 // make correct activations
2162 void wxMacMLTEClassicControl::MacActivatePaneText(Boolean setActive
)
2164 wxTextCtrl
* textctrl
= (wxTextCtrl
*) GetControlReference(m_controlRef
);
2166 wxMacWindowClipper
clipper( textctrl
) ;
2167 TXNActivate(m_txn
, m_txnFrameID
, setActive
);
2169 ControlRef controlFocus
= 0 ;
2170 GetKeyboardFocus( m_txnWindow
, &controlFocus
) ;
2171 if ( controlFocus
== m_controlRef
)
2172 TXNFocus( m_txn
, setActive
);
2175 void wxMacMLTEClassicControl::MacFocusPaneText(Boolean setFocus
)
2177 TXNFocus( m_txn
, setFocus
);
2180 // guards against inappropriate redraw (hidden objects drawing onto window)
2182 void wxMacMLTEClassicControl::MacSetObjectVisibility(Boolean vis
)
2184 ControlRef controlFocus
= 0 ;
2185 GetKeyboardFocus( m_txnWindow
, &controlFocus
) ;
2187 if ( controlFocus
== m_controlRef
&& vis
== false )
2189 SetKeyboardFocus( m_txnWindow
, m_controlRef
, kControlFocusNoPart
) ;
2192 TXNControlTag iControlTags
[1] = { kTXNVisibilityTag
};
2193 TXNControlData iControlData
[1] = { {(UInt32
) false } };
2195 verify_noerr( TXNGetTXNObjectControls( m_txn
, 1,
2196 iControlTags
, iControlData
) ) ;
2198 if ( iControlData
[0].uValue
!= vis
)
2200 iControlData
[0].uValue
= vis
;
2201 verify_noerr( TXNSetTXNObjectControls( m_txn
, false , 1,
2202 iControlTags
, iControlData
)) ;
2204 // we right now are always clipping as partial visibility (overlapped) visibility
2205 // is also a problem, if we run into further problems we might set the FrameBounds to an empty
2209 // make sure that the TXNObject is at the right position
2211 void wxMacMLTEClassicControl::MacUpdatePosition()
2213 wxTextCtrl
* textctrl
= (wxTextCtrl
*) GetControlReference(m_controlRef
);
2214 if ( textctrl
== NULL
)
2218 UMAGetControlBoundsInWindowCoords(m_controlRef
, &bounds
);
2220 wxRect visRect
= textctrl
->MacGetClippedClientRect() ;
2221 Rect visBounds
= { visRect
.y
, visRect
.x
, visRect
.y
+ visRect
.height
, visRect
.x
+ visRect
.width
} ;
2224 textctrl
->MacWindowToRootWindow( &x
, &y
) ;
2225 OffsetRect( &visBounds
, x
, y
) ;
2227 if ( !EqualRect( &bounds
, &m_txnControlBounds
) || !EqualRect( &visBounds
, &m_txnVisBounds
) )
2229 m_txnControlBounds
= bounds
;
2230 m_txnVisBounds
= visBounds
;
2231 wxMacWindowClipper
cl(textctrl
) ;
2233 #ifdef __WXMAC_OSX__
2234 bool isCompositing
= textctrl
->MacGetTopLevelWindow()->MacUsesCompositing() ;
2235 if ( m_sbHorizontal
|| m_sbVertical
)
2237 int w
= bounds
.right
- bounds
.left
;
2238 int h
= bounds
.bottom
- bounds
.top
;
2240 if ( m_sbHorizontal
)
2244 sbBounds
.left
= -1 ;
2245 sbBounds
.top
= h
- 14 ;
2246 sbBounds
.right
= w
+ 1 ;
2247 sbBounds
.bottom
= h
+ 1 ;
2249 if ( !isCompositing
)
2250 OffsetRect( &sbBounds
, m_txnControlBounds
.left
, m_txnControlBounds
.top
) ;
2252 SetControlBounds( m_sbHorizontal
, &sbBounds
) ;
2253 SetControlViewSize( m_sbHorizontal
, w
) ;
2259 sbBounds
.left
= w
- 14 ;
2261 sbBounds
.right
= w
+ 1 ;
2262 sbBounds
.bottom
= m_sbHorizontal
? h
- 14 : h
+ 1 ;
2264 if ( !isCompositing
)
2265 OffsetRect( &sbBounds
, m_txnControlBounds
.left
, m_txnControlBounds
.top
) ;
2267 SetControlBounds( m_sbVertical
, &sbBounds
) ;
2268 SetControlViewSize( m_sbVertical
, h
) ;
2273 TXNLongRect olddestRect
;
2274 TXNGetRectBounds( m_txn
, &oldviewRect
, &olddestRect
, NULL
) ;
2276 Rect viewRect
= { m_txnControlBounds
.top
, m_txnControlBounds
.left
,
2277 m_txnControlBounds
.bottom
- ( m_sbHorizontal
? 14 : 0 ) , m_txnControlBounds
.right
- ( m_sbVertical
? 14 : 0 ) } ;
2278 TXNLongRect destRect
= { m_txnControlBounds
.top
, m_txnControlBounds
.left
,
2279 m_txnControlBounds
.bottom
- ( m_sbHorizontal
? 14 : 0 ) , m_txnControlBounds
.right
- ( m_sbVertical
? 14 : 0 ) } ;
2281 if ( olddestRect
.right
>= 10000 )
2282 destRect
.right
= destRect
.left
+ 32000 ;
2284 if ( olddestRect
.bottom
>= 0x20000000 )
2285 destRect
.bottom
= destRect
.top
+ 0x40000000 ;
2287 SectRect( &viewRect
, &visBounds
, &viewRect
) ;
2288 TXNSetRectBounds( m_txn
, &viewRect
, &destRect
, true ) ;
2290 TXNSetFrameBounds( m_txn, m_txnControlBounds.top, m_txnControlBounds.left,
2291 m_txnControlBounds.bottom - ( m_sbHorizontal ? 14 : 0 ) , m_txnControlBounds.right - ( m_sbVertical ? 14 : 0 ), m_txnFrameID);
2295 TXNSetFrameBounds( m_txn
, m_txnControlBounds
.top
, m_txnControlBounds
.left
,
2296 wxMax( m_txnControlBounds
.bottom
, m_txnControlBounds
.top
) ,
2297 wxMax( m_txnControlBounds
.right
, m_txnControlBounds
.left
) , m_txnFrameID
);
2299 // the SetFrameBounds method unter classic sometimes does not correctly scroll a selection into sight after a
2300 // movement, therefore we have to force it
2302 // according to David Surovell this problem also sometimes occurs under OSX, so we use this as well
2304 TXNLongRect textRect
;
2305 TXNGetRectBounds( m_txn
, NULL
, NULL
, &textRect
) ;
2306 if ( textRect
.left
< m_txnControlBounds
.left
)
2308 TXNShowSelection( m_txn
, false ) ;
2313 void wxMacMLTEClassicControl::SetRect( Rect
*r
)
2315 wxMacControl::SetRect( r
) ;
2316 MacUpdatePosition() ;
2319 void wxMacMLTEClassicControl::MacControlUserPaneDrawProc(wxInt16 thePart
)
2321 wxTextCtrl
* textctrl
= (wxTextCtrl
*) GetControlReference(m_controlRef
);
2322 if ( textctrl
== NULL
)
2325 if ( textctrl
->MacIsReallyShown() )
2327 wxMacWindowClipper
clipper( textctrl
) ;
2328 TXNDraw( m_txn
, NULL
) ;
2332 wxInt16
wxMacMLTEClassicControl::MacControlUserPaneHitTestProc(wxInt16 x
, wxInt16 y
)
2334 Point where
= { y
, x
} ;
2335 ControlPartCode result
;
2338 wxTextCtrl
* textctrl
= (wxTextCtrl
*) GetControlReference(m_controlRef
);
2339 if ( textctrl
== NULL
)
2342 if (textctrl
->MacIsReallyShown() )
2344 if (PtInRect(where
, &m_txnControlBounds
))
2345 result
= kControlEditTextPart
;
2348 // sometimes we get the coords also in control local coordinates, therefore test again
2349 if ( textctrl
->MacGetTopLevelWindow()->MacUsesCompositing() )
2352 textctrl
->MacClientToRootWindow( &x
, &y
) ;
2356 if (PtInRect(where
, &m_txnControlBounds
))
2357 result
= kControlEditTextPart
;
2365 wxInt16
wxMacMLTEClassicControl::MacControlUserPaneTrackingProc( wxInt16 x
, wxInt16 y
, void* actionProc
)
2367 wxTextCtrl
* textctrl
= (wxTextCtrl
*) GetControlReference(m_controlRef
);
2368 if ( textctrl
== NULL
)
2371 ControlPartCode partCodeResult
= 0;
2373 if (textctrl
->MacIsReallyShown() )
2375 Point startPt
= { y
,x
} ;
2376 // for compositing, we must convert these into toplevel window coordinates, because hittesting expects them
2377 if ( textctrl
->MacGetTopLevelWindow()->MacUsesCompositing() )
2380 textctrl
->MacClientToRootWindow( &x
, &y
) ;
2385 switch (MacControlUserPaneHitTestProc( startPt
.h
, startPt
.v
))
2387 case kControlEditTextPart
:
2389 wxMacWindowClipper
clipper( textctrl
) ;
2392 ConvertEventRefToEventRecord( (EventRef
) wxTheApp
->MacGetCurrentEvent() , &rec
) ;
2393 TXNClick( m_txn
, &rec
);
2399 return partCodeResult
;
2402 void wxMacMLTEClassicControl::MacControlUserPaneIdleProc()
2404 wxTextCtrl
* textctrl
= (wxTextCtrl
*) GetControlReference(m_controlRef
);
2405 if ( textctrl
== NULL
)
2408 if (textctrl
->MacIsReallyShown())
2410 if (IsControlActive(m_controlRef
))
2414 wxMacWindowClipper
clipper( textctrl
) ;
2419 if (PtInRect(mousep
, &m_txnControlBounds
))
2422 RectRgn((theRgn
= NewRgn()), &m_txnControlBounds
);
2423 TXNAdjustCursor(m_txn
, theRgn
);
2430 wxInt16
wxMacMLTEClassicControl::MacControlUserPaneKeyDownProc (wxInt16 keyCode
, wxInt16 charCode
, wxInt16 modifiers
)
2432 wxTextCtrl
* textctrl
= (wxTextCtrl
*) GetControlReference(m_controlRef
);
2433 if ( textctrl
== NULL
)
2436 wxMacWindowClipper
clipper( textctrl
) ;
2439 memset( &ev
, 0 , sizeof( ev
) ) ;
2441 ev
.modifiers
= modifiers
;
2442 ev
.message
= (( keyCode
<< 8 ) & keyCodeMask
) + ( charCode
& charCodeMask
) ;
2443 TXNKeyDown( m_txn
, &ev
);
2445 return kControlEntireControl
;
2448 void wxMacMLTEClassicControl::MacControlUserPaneActivateProc( bool activating
)
2450 MacActivatePaneText( activating
);
2453 wxInt16
wxMacMLTEClassicControl::MacControlUserPaneFocusProc(wxInt16 action
)
2455 ControlPartCode focusResult
;
2457 focusResult
= kControlFocusNoPart
;
2458 wxTextCtrl
* textctrl
= (wxTextCtrl
*) GetControlReference(m_controlRef
);
2459 if ( textctrl
== NULL
)
2462 wxMacWindowClipper
clipper( textctrl
) ;
2464 ControlRef controlFocus
= 0 ;
2465 GetKeyboardFocus( m_txnWindow
, &controlFocus
) ;
2466 bool wasFocused
= ( controlFocus
== m_controlRef
) ;
2470 case kControlFocusPrevPart
:
2471 case kControlFocusNextPart
:
2472 MacFocusPaneText( ( !wasFocused
));
2473 focusResult
= (!wasFocused
) ? (ControlPartCode
) kControlEditTextPart
: (ControlPartCode
) kControlFocusNoPart
;
2476 case kControlFocusNoPart
:
2478 MacFocusPaneText( false);
2479 focusResult
= kControlFocusNoPart
;
2486 void wxMacMLTEClassicControl::MacControlUserPaneBackgroundProc( void *info
)
2490 wxMacMLTEClassicControl::wxMacMLTEClassicControl( wxTextCtrl
*wxPeer
,
2491 const wxString
& str
,
2493 const wxSize
& size
, long style
) : wxMacMLTEControl( wxPeer
)
2495 m_font
= wxPeer
->GetFont() ;
2496 m_windowStyle
= style
;
2497 Rect bounds
= wxMacGetBoundsForControl( wxPeer
, pos
, size
) ;
2501 featurSet
= kControlSupportsEmbedding
| kControlSupportsFocus
| kControlWantsIdle
2502 | kControlWantsActivate
| kControlHandlesTracking
// | kControlHasSpecialBackground
2503 | kControlGetsFocusOnClick
| kControlSupportsLiveFeedback
;
2505 verify_noerr( ::CreateUserPaneControl( MAC_WXHWND(wxPeer
->GetParent()->MacGetTopLevelWindowRef()), &bounds
, featurSet
, &m_controlRef
) );
2509 AdjustCreationAttributes( *wxWHITE
, true) ;
2511 MacSetObjectVisibility( wxPeer
->MacIsReallyShown() ) ;
2515 wxMacConvertNewlines10To13( &st
) ;
2516 wxMacWindowClipper
clipper( m_peer
) ;
2517 SetTXNData( st
, kTXNStartOffset
, kTXNEndOffset
) ;
2518 TXNSetSelection( m_txn
, 0, 0);
2522 wxMacMLTEClassicControl::~wxMacMLTEClassicControl()
2524 TXNDeleteObject(m_txn
);
2528 void wxMacMLTEClassicControl::VisibilityChanged(bool shown
)
2530 MacSetObjectVisibility( shown
) ;
2531 wxMacControl::VisibilityChanged( shown
) ;
2534 void wxMacMLTEClassicControl::SuperChangedPosition()
2536 MacUpdatePosition() ;
2537 wxMacControl::SuperChangedPosition() ;
2540 #ifdef __WXMAC_OSX__
2542 ControlUserPaneDrawUPP gTPDrawProc
= NULL
;
2543 ControlUserPaneHitTestUPP gTPHitProc
= NULL
;
2544 ControlUserPaneTrackingUPP gTPTrackProc
= NULL
;
2545 ControlUserPaneIdleUPP gTPIdleProc
= NULL
;
2546 ControlUserPaneKeyDownUPP gTPKeyProc
= NULL
;
2547 ControlUserPaneActivateUPP gTPActivateProc
= NULL
;
2548 ControlUserPaneFocusUPP gTPFocusProc
= NULL
;
2550 static pascal void wxMacControlUserPaneDrawProc(ControlRef control
, SInt16 part
)
2552 wxTextCtrl
*textCtrl
= wxDynamicCast( wxFindControlFromMacControl(control
) , wxTextCtrl
) ;
2553 wxMacMLTEClassicControl
* win
= textCtrl
? (wxMacMLTEClassicControl
*)(textCtrl
->GetPeer()) : NULL
;
2555 win
->MacControlUserPaneDrawProc(part
) ;
2558 static pascal ControlPartCode
wxMacControlUserPaneHitTestProc(ControlRef control
, const Point
& where
)
2560 wxTextCtrl
*textCtrl
= wxDynamicCast( wxFindControlFromMacControl(control
) , wxTextCtrl
) ;
2561 wxMacMLTEClassicControl
* win
= textCtrl
? (wxMacMLTEClassicControl
*)(textCtrl
->GetPeer()) : NULL
;
2563 return win
->MacControlUserPaneHitTestProc(where
.h
, where
.v
) ;
2565 return kControlNoPart
;
2568 static pascal ControlPartCode
wxMacControlUserPaneTrackingProc(ControlRef control
, const Point
& startPt
, ControlActionUPP actionProc
)
2570 wxTextCtrl
*textCtrl
= wxDynamicCast( wxFindControlFromMacControl(control
) , wxTextCtrl
) ;
2571 wxMacMLTEClassicControl
* win
= textCtrl
? (wxMacMLTEClassicControl
*)(textCtrl
->GetPeer()) : NULL
;
2573 return win
->MacControlUserPaneTrackingProc( startPt
.h
, startPt
.v
, (void*) actionProc
) ;
2575 return kControlNoPart
;
2578 static pascal void wxMacControlUserPaneIdleProc(ControlRef control
)
2580 wxTextCtrl
*textCtrl
= wxDynamicCast( wxFindControlFromMacControl(control
) , wxTextCtrl
) ;
2581 wxMacMLTEClassicControl
* win
= textCtrl
? (wxMacMLTEClassicControl
*)(textCtrl
->GetPeer()) : NULL
;
2583 win
->MacControlUserPaneIdleProc() ;
2586 static pascal ControlPartCode
wxMacControlUserPaneKeyDownProc(ControlRef control
, SInt16 keyCode
, SInt16 charCode
, SInt16 modifiers
)
2588 wxTextCtrl
*textCtrl
= wxDynamicCast( wxFindControlFromMacControl(control
) , wxTextCtrl
) ;
2589 wxMacMLTEClassicControl
* win
= textCtrl
? (wxMacMLTEClassicControl
*)(textCtrl
->GetPeer()) : NULL
;
2591 return win
->MacControlUserPaneKeyDownProc(keyCode
,charCode
,modifiers
) ;
2593 return kControlNoPart
;
2596 static pascal void wxMacControlUserPaneActivateProc(ControlRef control
, Boolean activating
)
2598 wxTextCtrl
*textCtrl
= wxDynamicCast( wxFindControlFromMacControl(control
) , wxTextCtrl
) ;
2599 wxMacMLTEClassicControl
* win
= textCtrl
? (wxMacMLTEClassicControl
*)(textCtrl
->GetPeer()) : NULL
;
2601 win
->MacControlUserPaneActivateProc(activating
) ;
2604 static pascal ControlPartCode
wxMacControlUserPaneFocusProc(ControlRef control
, ControlFocusPart action
)
2606 wxTextCtrl
*textCtrl
= wxDynamicCast( wxFindControlFromMacControl(control
) , wxTextCtrl
) ;
2607 wxMacMLTEClassicControl
* win
= textCtrl
? (wxMacMLTEClassicControl
*)(textCtrl
->GetPeer()) : NULL
;
2609 return win
->MacControlUserPaneFocusProc(action
) ;
2611 return kControlNoPart
;
2615 static pascal void wxMacControlUserPaneBackgroundProc(ControlRef control, ControlBackgroundPtr info)
2617 wxTextCtrl *textCtrl = wxDynamicCast( wxFindControlFromMacControl(control) , wxTextCtrl ) ;
2618 wxMacMLTEClassicControl * win = textCtrl ? (wxMacMLTEClassicControl*)(textCtrl->GetPeer()) : NULL ;
2620 win->MacControlUserPaneBackgroundProc(info) ;
2625 // TXNRegisterScrollInfoProc
2627 OSStatus
wxMacMLTEClassicControl::DoCreate()
2631 OSStatus err
= noErr
;
2633 /* set up our globals */
2634 #ifdef __WXMAC_OSX__
2635 if (gTPDrawProc
== NULL
) gTPDrawProc
= NewControlUserPaneDrawUPP(wxMacControlUserPaneDrawProc
);
2636 if (gTPHitProc
== NULL
) gTPHitProc
= NewControlUserPaneHitTestUPP(wxMacControlUserPaneHitTestProc
);
2637 if (gTPTrackProc
== NULL
) gTPTrackProc
= NewControlUserPaneTrackingUPP(wxMacControlUserPaneTrackingProc
);
2638 if (gTPIdleProc
== NULL
) gTPIdleProc
= NewControlUserPaneIdleUPP(wxMacControlUserPaneIdleProc
);
2639 if (gTPKeyProc
== NULL
) gTPKeyProc
= NewControlUserPaneKeyDownUPP(wxMacControlUserPaneKeyDownProc
);
2640 if (gTPActivateProc
== NULL
) gTPActivateProc
= NewControlUserPaneActivateUPP(wxMacControlUserPaneActivateProc
);
2641 if (gTPFocusProc
== NULL
) gTPFocusProc
= NewControlUserPaneFocusUPP(wxMacControlUserPaneFocusProc
);
2643 if (gTXNScrollInfoProc
== NULL
) gTXNScrollInfoProc
= NewTXNScrollInfoUPP(TXNScrollInfoProc
) ;
2644 if (gTXNScrollActionProc
== NULL
) gTXNScrollActionProc
= NewControlActionUPP(TXNScrollActionProc
) ;
2647 /* set the initial settings for our private data */
2649 m_txnWindow
=GetControlOwner(m_controlRef
);
2650 m_txnPort
= (GrafPtr
) GetWindowPort(m_txnWindow
);
2652 #ifdef __WXMAC_OSX__
2653 /* set up the user pane procedures */
2654 SetControlData(m_controlRef
, kControlEntireControl
, kControlUserPaneDrawProcTag
, sizeof(gTPDrawProc
), &gTPDrawProc
);
2655 SetControlData(m_controlRef
, kControlEntireControl
, kControlUserPaneHitTestProcTag
, sizeof(gTPHitProc
), &gTPHitProc
);
2656 SetControlData(m_controlRef
, kControlEntireControl
, kControlUserPaneTrackingProcTag
, sizeof(gTPTrackProc
), &gTPTrackProc
);
2657 SetControlData(m_controlRef
, kControlEntireControl
, kControlUserPaneIdleProcTag
, sizeof(gTPIdleProc
), &gTPIdleProc
);
2658 SetControlData(m_controlRef
, kControlEntireControl
, kControlUserPaneKeyDownProcTag
, sizeof(gTPKeyProc
), &gTPKeyProc
);
2659 SetControlData(m_controlRef
, kControlEntireControl
, kControlUserPaneActivateProcTag
, sizeof(gTPActivateProc
), &gTPActivateProc
);
2660 SetControlData(m_controlRef
, kControlEntireControl
, kControlUserPaneFocusProcTag
, sizeof(gTPFocusProc
), &gTPFocusProc
);
2662 /* calculate the rectangles used by the control */
2663 UMAGetControlBoundsInWindowCoords(m_controlRef
, &bounds
);
2665 m_txnControlBounds
= bounds
;
2666 m_txnVisBounds
= bounds
;
2668 CGrafPtr origPort
= NULL
;
2669 GDHandle origDev
= NULL
;
2670 GetGWorld( &origPort
, &origDev
) ;
2673 /* create the new edit field */
2675 TXNFrameOptions frameOptions
= FrameOptionsFromWXStyle( m_windowStyle
) ;
2677 #ifdef __WXMAC_OSX__
2679 // the scrollbars are not correctly embedded but are inserted at the root
2680 // this gives us problems as we have erratic redraws even over the structure
2683 m_sbHorizontal
= 0 ;
2685 m_lastHorizontalValue
= 0 ;
2686 m_lastVerticalValue
= 0 ;
2688 Rect sb
= { 0 , 0 , 0 , 0 } ;
2689 if ( frameOptions
& kTXNWantVScrollBarMask
)
2691 CreateScrollBarControl( m_txnWindow
, &sb
, 0 , 0 , 100 , 1 , true , gTXNScrollActionProc
, &m_sbVertical
) ;
2692 SetControlReference( m_sbVertical
, (SInt32
) this ) ;
2693 SetControlAction( m_sbVertical
, gTXNScrollActionProc
);
2694 ShowControl( m_sbVertical
) ;
2695 EmbedControl( m_sbVertical
, m_controlRef
) ;
2696 frameOptions
&= ~kTXNWantVScrollBarMask
;
2698 if ( frameOptions
& kTXNWantHScrollBarMask
)
2700 CreateScrollBarControl( m_txnWindow
, &sb
, 0 , 0 , 100 , 1 , true , gTXNScrollActionProc
, &m_sbHorizontal
) ;
2701 SetControlReference( m_sbHorizontal
, (SInt32
) this ) ;
2702 SetControlAction( m_sbHorizontal
, gTXNScrollActionProc
);
2703 ShowControl( m_sbHorizontal
) ;
2704 EmbedControl( m_sbHorizontal
, m_controlRef
) ;
2705 frameOptions
&= ~(kTXNWantHScrollBarMask
| kTXNDrawGrowIconMask
);
2710 verify_noerr(TXNNewObject(NULL
, m_txnWindow
, &bounds
,
2712 kTXNTextEditStyleFrameType
,
2714 kTXNSystemDefaultEncoding
,
2715 &m_txn
, &m_txnFrameID
, NULL
) );
2717 TXNCarbonEventInfo cInfo ;
2719 cInfo.useCarbonEvents = false ;
2722 cInfo.fDictionary = NULL ;
2724 TXNControlTag iControlTags[] =
2726 kTXNUseCarbonEvents ,
2728 TXNControlData iControlData[] =
2733 int toptag = WXSIZEOF( iControlTags ) ;
2735 verify_noerr( TXNSetTXNObjectControls( m_txn, false , toptag,
2736 iControlTags, iControlData )) ;
2739 #ifdef __WXMAC_OSX__
2740 TXNRegisterScrollInfoProc( m_txn
, gTXNScrollInfoProc
, (SInt32
) this);
2743 SetGWorld( origPort
, origDev
) ;
2747 // ----------------------------------------------------------------------------
2748 // MLTE control implementation (OSX part)
2749 // ----------------------------------------------------------------------------
2751 #if TARGET_API_MAC_OSX
2753 #if MAC_OS_X_VERSION_MAX_ALLOWED > MAC_OS_X_VERSION_10_2
2755 wxMacMLTEHIViewControl::wxMacMLTEHIViewControl( wxTextCtrl
*wxPeer
,
2756 const wxString
& str
,
2758 const wxSize
& size
, long style
) : wxMacMLTEControl( wxPeer
)
2760 m_font
= wxPeer
->GetFont() ;
2761 m_windowStyle
= style
;
2762 Rect bounds
= wxMacGetBoundsForControl( wxPeer
, pos
, size
) ;
2764 wxMacConvertNewlines10To13( &st
) ;
2766 HIRect hr
= { { bounds
.left
, bounds
.top
} ,
2767 { bounds
.right
- bounds
.left
, bounds
.bottom
- bounds
.top
} } ;
2769 m_scrollView
= NULL
;
2770 TXNFrameOptions frameOptions
= FrameOptionsFromWXStyle( style
) ;
2771 if ( frameOptions
& (kTXNWantVScrollBarMask
|kTXNWantHScrollBarMask
) )
2773 HIScrollViewCreate(( frameOptions
& kTXNWantHScrollBarMask
? kHIScrollViewOptionsHorizScroll
: 0) |
2774 ( frameOptions
& kTXNWantVScrollBarMask
? kHIScrollViewOptionsVertScroll
: 0 ) , &m_scrollView
) ;
2776 HIViewSetFrame( m_scrollView
, &hr
);
2777 HIViewSetVisible( m_scrollView
, true );
2781 HITextViewCreate( NULL
, 0, frameOptions
, &m_textView
) ;
2782 m_txn
= HITextViewGetTXNObject( m_textView
) ;
2783 HIViewSetVisible( m_textView
, true ) ;
2786 HIViewAddSubview( m_scrollView
, m_textView
) ;
2787 m_controlRef
= m_scrollView
;
2788 wxPeer
->MacInstallEventHandler( (WXWidget
) m_textView
) ;
2792 HIViewSetFrame( m_textView
, &hr
);
2793 m_controlRef
= m_textView
;
2796 AdjustCreationAttributes( *wxWHITE
, true ) ;
2798 wxMacWindowClipper
c( m_peer
) ;
2799 SetTXNData( st
, kTXNStartOffset
, kTXNEndOffset
) ;
2801 TXNSetSelection( m_txn
, 0, 0);
2802 TXNShowSelection( m_txn
, kTXNShowStart
);
2806 OSStatus
wxMacMLTEHIViewControl::SetFocus( ControlFocusPart focusPart
)
2808 return SetKeyboardFocus( GetControlOwner( m_textView
) ,
2809 m_textView
, focusPart
) ;
2812 bool wxMacMLTEHIViewControl::HasFocus() const
2814 ControlRef control
;
2815 GetKeyboardFocus( GetUserFocusWindow() , &control
) ;
2816 return control
== m_textView
;
2819 #endif // MAC_OS_X_VERSION_MAX_ALLOWED > MAC_OS_X_VERSION_10_2
2824 #endif // wxUSE_TEXTCTRL