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 #if defined(__GNUG__) && !defined(NO_GCC_PRAGMA)
13 #pragma implementation "textctrl.h"
16 #include "wx/wxprec.h"
22 #include <sys/types.h>
28 #include "wx/msgdlg.h"
30 #if wxUSE_STD_IOSTREAM
40 #include "wx/button.h"
41 #include "wx/toplevel.h"
42 #include "wx/textctrl.h"
43 #include "wx/notebook.h"
44 #include "wx/tabctrl.h"
45 #include "wx/settings.h"
46 #include "wx/filefn.h"
49 #if defined(__BORLANDC__) && !defined(__WIN32__)
51 #elif !defined(__MWERKS__) && !defined(__GNUWIN32) && !defined(__DARWIN__)
59 // if this is set to 1 then under OSX 10.2 the 'classic' MLTE implementation will be used
60 // if set to 0 then the unicode textctrl will be used
61 #ifndef wxMAC_AWAYS_USE_MLTE
62 #define wxMAC_AWAYS_USE_MLTE 1
68 kTXNVisibilityTag
= 'visb' /*set the visibility state of the object */
72 #include <MacTextEditor.h>
73 #include <ATSUnicode.h>
74 #include <TextCommon.h>
75 #include <TextEncodingConverter.h>
76 #include "wx/mac/uma.h"
82 virtual ~wxMacFunctor() {}
83 virtual void* operator()() = 0 ;
84 static void* CallBackProc(void *param
)
86 wxMacFunctor
* f
= (wxMacFunctor
*) param
;
87 void *result
= (*f
)() ;
92 template<typename classtype
,typename param1type
>
93 class wxMacObjectFunctor1
: public wxMacFunctor
95 typedef void (classtype::*function
)( param1type p1
) ;
96 typedef void (classtype::*ref_function
)( const param1type
& p1
) ;
98 wxMacObjectFunctor1( classtype
*obj
, function f
, param1type p1
) :
106 wxMacObjectFunctor1( classtype
*obj
, ref_function f
, param1type p1
) :
114 ~wxMacObjectFunctor1() {}
116 virtual void* operator()()
118 (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
) ;
166 // common interface for all implementations
167 class wxMacTextControl
: public wxMacControl
170 wxMacTextControl( wxTextCtrl
*peer
) ;
171 ~wxMacTextControl() ;
173 virtual wxString
GetStringValue() const = 0 ;
174 virtual void SetStringValue( const wxString
&val
) = 0 ;
175 virtual void SetStyle(long start
, long end
, const wxTextAttr
& style
) ;
176 virtual void Copy() ;
178 virtual void Paste() ;
179 virtual bool CanPaste() const ;
180 virtual void SetEditable(bool editable
) ;
181 virtual wxTextPos
GetLastPosition() const ;
182 virtual void Replace( long from
, long to
, const wxString str
) ;
183 virtual void Remove( long from
, long to
) = 0 ;
184 virtual void SetSelection( long from
, long to
) = 0 ;
185 virtual void GetSelection( long* from
, long* to
) const = 0 ;
186 virtual void WriteText(const wxString
& str
) = 0 ;
188 virtual void Clear() ;
189 virtual bool CanUndo() const;
190 virtual void Undo() ;
191 virtual bool CanRedo() const;
192 virtual void Redo() ;
193 virtual int GetNumberOfLines() const ;
194 virtual long XYToPosition(long x
, long y
) const;
195 virtual bool PositionToXY(long pos
, long *x
, long *y
) const ;
196 virtual void ShowPosition( long WXUNUSED(pos
) ) ;
197 virtual int GetLineLength(long lineNo
) const ;
198 virtual wxString
GetLineText(long lineNo
) const ;
199 virtual bool SetupCursor( const wxPoint
& pt
) { return false ; }
201 #ifndef __WXMAC_OSX__
202 virtual void MacControlUserPaneDrawProc(wxInt16 part
) = 0 ;
203 virtual wxInt16
MacControlUserPaneHitTestProc(wxInt16 x
, wxInt16 y
) = 0 ;
204 virtual wxInt16
MacControlUserPaneTrackingProc(wxInt16 x
, wxInt16 y
, void* actionProc
) = 0 ;
205 virtual void MacControlUserPaneIdleProc() = 0 ;
206 virtual wxInt16
MacControlUserPaneKeyDownProc(wxInt16 keyCode
, wxInt16 charCode
, wxInt16 modifiers
) = 0 ;
207 virtual void MacControlUserPaneActivateProc(bool activating
) = 0 ;
208 virtual wxInt16
MacControlUserPaneFocusProc(wxInt16 action
) = 0 ;
209 virtual void MacControlUserPaneBackgroundProc(void* info
) = 0 ;
213 // common parts for implementations based on MLTE
215 class wxMacMLTEControl
: public wxMacTextControl
218 wxMacMLTEControl( wxTextCtrl
*peer
) ;
219 virtual wxString
GetStringValue() const ;
220 virtual void SetStringValue( const wxString
&str
) ;
222 static TXNFrameOptions
FrameOptionsFromWXStyle( long wxStyle
) ;
223 void AdjustCreationAttributes( const wxColour
& background
, bool visible
) ;
225 virtual void SetFont( const wxFont
& font
, const wxColour
& foreground
, long windowStyle
) ;
226 virtual void SetBackground( const wxBrush
&brush
) ;
227 virtual void SetStyle(long start
, long end
, const wxTextAttr
& style
) ;
228 virtual void Copy() ;
230 virtual void Paste() ;
231 virtual bool CanPaste() const ;
232 virtual void SetEditable(bool editable
) ;
233 virtual wxTextPos
GetLastPosition() const ;
234 virtual void Replace( long from
, long to
, const wxString str
) ;
235 virtual void Remove( long from
, long to
) ;
236 virtual void GetSelection( long* from
, long* to
) const ;
237 virtual void SetSelection( long from
, long to
) ;
239 virtual void WriteText(const wxString
& str
) ;
240 virtual void Clear() ;
242 virtual bool CanUndo() const ;
243 virtual void Undo() ;
244 virtual bool CanRedo() const;
245 virtual void Redo() ;
246 virtual int GetNumberOfLines() const ;
247 virtual long XYToPosition(long x
, long y
) const ;
248 virtual bool PositionToXY(long pos
, long *x
, long *y
) const ;
249 virtual void ShowPosition( long pos
) ;
250 virtual int GetLineLength(long lineNo
) const ;
251 virtual wxString
GetLineText(long lineNo
) const ;
253 void SetTXNData( const wxString
& st
, TXNOffset start
, TXNOffset end
) ;
256 void TXNSetAttribute( const wxTextAttr
& style
, long from
, long to
) ;
260 #if TARGET_API_MAC_OSX
262 // implementation available under OSX
264 #if MAC_OS_X_VERSION_MAX_ALLOWED > MAC_OS_X_VERSION_10_2
266 class wxMacMLTEHIViewControl
: public wxMacMLTEControl
269 wxMacMLTEHIViewControl( wxTextCtrl
*wxPeer
,
272 const wxSize
& size
, long style
) ;
273 virtual OSStatus
SetFocus( ControlFocusPart focusPart
) ;
274 virtual bool HasFocus() const ;
276 HIViewRef m_scrollView
;
277 HIViewRef m_textView
;
282 class wxMacUnicodeTextControl
: public wxMacTextControl
285 wxMacUnicodeTextControl( wxTextCtrl
*wxPeer
,
288 const wxSize
& size
, long style
) ;
289 ~wxMacUnicodeTextControl();
290 virtual void VisibilityChanged(bool shown
);
291 virtual wxString
GetStringValue() const ;
292 virtual void SetStringValue( const wxString
&str
) ;
295 virtual void Paste();
296 virtual bool CanPaste() const;
297 virtual void SetEditable(bool editable
) ;
298 virtual void Remove( long from
, long to
) ;
299 virtual void GetSelection( long* from
, long* to
) const ;
300 virtual void SetSelection( long from
, long to
) ;
301 virtual void WriteText(const wxString
& str
) ;
303 // contains the tag for the content (is different for password and non-password controls)
309 // 'classic' MLTE implementation
311 class wxMacMLTEClassicControl
: public wxMacMLTEControl
314 wxMacMLTEClassicControl( wxTextCtrl
*wxPeer
,
317 const wxSize
& size
, long style
) ;
318 ~wxMacMLTEClassicControl() ;
319 virtual void VisibilityChanged(bool shown
) ;
320 virtual void SuperChangedPosition() ;
322 virtual void MacControlUserPaneDrawProc(wxInt16 part
) ;
323 virtual wxInt16
MacControlUserPaneHitTestProc(wxInt16 x
, wxInt16 y
) ;
324 virtual wxInt16
MacControlUserPaneTrackingProc(wxInt16 x
, wxInt16 y
, void* actionProc
) ;
325 virtual void MacControlUserPaneIdleProc() ;
326 virtual wxInt16
MacControlUserPaneKeyDownProc(wxInt16 keyCode
, wxInt16 charCode
, wxInt16 modifiers
) ;
327 virtual void MacControlUserPaneActivateProc(bool activating
) ;
328 virtual wxInt16
MacControlUserPaneFocusProc(wxInt16 action
) ;
329 virtual void MacControlUserPaneBackgroundProc(void* info
) ;
331 virtual bool SetupCursor( const wxPoint
& WXUNUSED(pt
) ) { MacControlUserPaneIdleProc() ; return true ;}
333 virtual void SetRect( Rect
*r
) ;
338 void MacUpdatePosition() ;
339 void MacActivatePaneText(Boolean setActive
) ;
340 void MacFocusPaneText(Boolean setFocus
) ;
342 void MacSetObjectVisibility(Boolean vis
) ;
344 TXNFrameID m_txnFrameID
;
346 WindowRef m_txnWindow
;
347 // bounds of the control as we last did set the txn frames
348 Rect m_txnControlBounds
;
351 static pascal void TXNScrollInfoProc (SInt32 iValue
, SInt32 iMaximumValue
,
352 TXNScrollBarOrientation iScrollBarOrientation
, SInt32 iRefCon
) ;
353 static pascal void TXNScrollActionProc( ControlRef controlRef
, ControlPartCode partCode
) ;
354 ControlRef m_sbHorizontal
;
355 SInt32 m_lastHorizontalValue
;
356 ControlRef m_sbVertical
;
357 SInt32 m_lastVerticalValue
;
361 #define TE_UNLIMITED_LENGTH 0xFFFFFFFFUL
363 #if !USE_SHARED_LIBRARY
364 IMPLEMENT_DYNAMIC_CLASS(wxTextCtrl
, wxControl
)
366 BEGIN_EVENT_TABLE(wxTextCtrl
, wxControl
)
367 EVT_ERASE_BACKGROUND( wxTextCtrl::OnEraseBackground
)
368 EVT_DROP_FILES(wxTextCtrl::OnDropFiles
)
369 EVT_CHAR(wxTextCtrl::OnChar
)
370 EVT_MENU(wxID_CUT
, wxTextCtrl::OnCut
)
371 EVT_MENU(wxID_COPY
, wxTextCtrl::OnCopy
)
372 EVT_MENU(wxID_PASTE
, wxTextCtrl::OnPaste
)
373 EVT_MENU(wxID_UNDO
, wxTextCtrl::OnUndo
)
374 EVT_MENU(wxID_REDO
, wxTextCtrl::OnRedo
)
376 EVT_UPDATE_UI(wxID_CUT
, wxTextCtrl::OnUpdateCut
)
377 EVT_UPDATE_UI(wxID_COPY
, wxTextCtrl::OnUpdateCopy
)
378 EVT_UPDATE_UI(wxID_PASTE
, wxTextCtrl::OnUpdatePaste
)
379 EVT_UPDATE_UI(wxID_UNDO
, wxTextCtrl::OnUpdateUndo
)
380 EVT_UPDATE_UI(wxID_REDO
, wxTextCtrl::OnUpdateRedo
)
385 void wxTextCtrl::Init()
390 m_maxLength
= TE_UNLIMITED_LENGTH
;
393 wxTextCtrl::~wxTextCtrl()
398 bool wxTextCtrl::Create(wxWindow
*parent
, wxWindowID id
,
401 const wxSize
& size
, long style
,
402 const wxValidator
& validator
,
403 const wxString
& name
)
405 m_macIsUserPane
= false ;
408 if ( ! ( style
& wxNO_BORDER
) )
409 style
= ( style
& ~wxBORDER_MASK
) | wxSUNKEN_BORDER
;
411 if ( !wxTextCtrlBase::Create(parent
, id
, pos
, size
, style
& ~(wxHSCROLL
|wxVSCROLL
), validator
, name
) )
414 if ( m_windowStyle
& wxTE_MULTILINE
)
416 wxASSERT_MSG( !(m_windowStyle
& wxTE_PROCESS_ENTER
),
417 wxT("wxTE_PROCESS_ENTER style is ignored for multiline text controls (they always process it)") );
419 m_windowStyle
|= wxTE_PROCESS_ENTER
;
420 style
|= wxTE_PROCESS_ENTER
;
424 #if MAC_OS_X_VERSION_MAX_ALLOWED > MAC_OS_X_VERSION_10_2
425 if ( UMAGetSystemVersion() >= 0x1050 )
427 m_peer
= new wxMacMLTEHIViewControl( this , str
, pos
, size
, style
) ;
430 #if !wxMAC_AWAYS_USE_MLTE
433 m_peer
= new wxMacUnicodeTextControl( this , str
, pos
, size
, style
) ;
439 m_peer
= new wxMacMLTEClassicControl( this , str
, pos
, size
, style
) ;
442 MacPostControlCreate(pos
,size
) ;
444 if ( m_windowStyle
& wxTE_READONLY
)
446 SetEditable( false ) ;
449 SetCursor( wxCursor( wxCURSOR_IBEAM
) ) ;
454 void wxTextCtrl::MacSuperChangedPosition()
456 wxWindow::MacSuperChangedPosition() ;
457 GetPeer()->SuperChangedPosition() ;
460 void wxTextCtrl::MacVisibilityChanged()
462 GetPeer()->VisibilityChanged( MacIsReallyShown() ) ;
465 void wxTextCtrl::MacEnabledStateChanged()
469 wxString
wxTextCtrl::GetValue() const
471 return GetPeer()->GetStringValue() ;
474 void wxTextCtrl::GetSelection(long* from
, long* to
) const
476 GetPeer()->GetSelection( from
, to
) ;
479 void wxTextCtrl::SetValue(const wxString
& str
)
482 if ( GetValue() == str
)
485 GetPeer()->SetStringValue(str
) ;
487 wxCommandEvent
event(wxEVT_COMMAND_TEXT_UPDATED
, m_windowId
);
488 event
.SetString( GetValue() ) ;
489 event
.SetEventObject( this );
490 GetEventHandler()->ProcessEvent(event
);
493 void wxTextCtrl::SetMaxLength(unsigned long len
)
498 bool wxTextCtrl::SetFont( const wxFont
& font
)
500 if ( !wxTextCtrlBase::SetFont( font
) )
503 GetPeer()->SetFont( font
, GetForegroundColour() , GetWindowStyle() ) ;
507 bool wxTextCtrl::SetStyle(long start
, long end
, const wxTextAttr
& style
)
509 GetPeer()->SetStyle( start
, end
, style
) ;
513 bool wxTextCtrl::SetDefaultStyle(const wxTextAttr
& style
)
515 wxTextCtrlBase::SetDefaultStyle( style
) ;
516 SetStyle( kTXNUseCurrentSelection
, kTXNUseCurrentSelection
, GetDefaultStyle() ) ;
520 // Clipboard operations
521 void wxTextCtrl::Copy()
529 void wxTextCtrl::Cut()
535 wxCommandEvent
event(wxEVT_COMMAND_TEXT_UPDATED
, m_windowId
);
536 event
.SetEventObject( this );
537 GetEventHandler()->ProcessEvent(event
);
541 void wxTextCtrl::Paste()
546 // eventually we should add setting the default style again
548 wxCommandEvent
event(wxEVT_COMMAND_TEXT_UPDATED
, m_windowId
);
549 event
.SetEventObject( this );
550 GetEventHandler()->ProcessEvent(event
);
554 bool wxTextCtrl::CanCopy() const
556 // Can copy if there's a selection
558 GetSelection(& from
, & to
);
562 bool wxTextCtrl::CanCut() const
568 // Can cut if there's a selection
570 GetSelection(& from
, & to
);
574 bool wxTextCtrl::CanPaste() const
579 return GetPeer()->CanPaste() ;
582 void wxTextCtrl::SetEditable(bool editable
)
584 if ( editable
!= m_editable
)
586 m_editable
= editable
;
587 GetPeer()->SetEditable( editable
) ;
591 void wxTextCtrl::SetInsertionPoint(long pos
)
593 SetSelection( pos
, pos
) ;
596 void wxTextCtrl::SetInsertionPointEnd()
598 wxTextPos pos
= GetLastPosition();
599 SetInsertionPoint(pos
);
602 long wxTextCtrl::GetInsertionPoint() const
605 GetSelection( &begin
, &end
) ;
609 wxTextPos
wxTextCtrl::GetLastPosition() const
611 return GetPeer()->GetLastPosition( ) ;
614 void wxTextCtrl::Replace(long from
, long to
, const wxString
& str
)
616 GetPeer()->Replace( from
, to
, str
) ;
619 void wxTextCtrl::Remove(long from
, long to
)
621 GetPeer()->Remove( from
, to
) ;
624 void wxTextCtrl::SetSelection(long from
, long to
)
626 GetPeer()->SetSelection( from
, to
) ;
629 bool wxTextCtrl::LoadFile(const wxString
& file
)
631 if ( wxTextCtrlBase::LoadFile(file
) )
639 void wxTextCtrl::WriteText(const wxString
& str
)
641 // TODO this MPRemoting will be moved into a remoting peer proxy for any command
642 if ( !wxIsMainThread() )
644 // unfortunately CW 8 is not able to correctly deduce the template types, so we have
645 // to instantiate explicitely
646 wxMacMPRemoteGUICall
<wxTextCtrl
,wxString
>( this , &wxTextCtrl::WriteText
, str
) ;
651 GetPeer()->WriteText( str
) ;
655 void wxTextCtrl::AppendText(const wxString
& text
)
657 SetInsertionPointEnd();
661 void wxTextCtrl::Clear()
666 bool wxTextCtrl::IsModified() const
671 bool wxTextCtrl::IsEditable() const
673 return IsEnabled() && m_editable
;
676 bool wxTextCtrl::AcceptsFocus() const
678 // we don't want focus if we can't be edited
679 return /*IsEditable() && */ wxControl::AcceptsFocus();
682 wxSize
wxTextCtrl::DoGetBestSize() const
688 // these are the numbers from the HIG, we reduce them by the borders
691 switch( m_windowVariant
)
693 case wxWINDOW_VARIANT_NORMAL
:
696 case wxWINDOW_VARIANT_SMALL
:
699 case wxWINDOW_VARIANT_MINI
:
707 // as the above numbers have some free space around the text
708 // we get 5 lines like this anyway
709 if ( m_windowStyle
& wxTE_MULTILINE
)
714 if ( !HasFlag(wxNO_BORDER
) )
717 return wxSize(wText
, hText
);
720 // ----------------------------------------------------------------------------
722 // ----------------------------------------------------------------------------
724 void wxTextCtrl::Undo()
732 void wxTextCtrl::Redo()
740 bool wxTextCtrl::CanUndo() const
746 return GetPeer()->CanUndo() ;
749 bool wxTextCtrl::CanRedo() const
755 return GetPeer()->CanRedo() ;
758 void wxTextCtrl::MarkDirty()
763 void wxTextCtrl::DiscardEdits()
768 int wxTextCtrl::GetNumberOfLines() const
770 return GetPeer()->GetNumberOfLines() ;
773 long wxTextCtrl::XYToPosition(long x
, long y
) const
775 return GetPeer()->XYToPosition( x
, y
) ;
778 bool wxTextCtrl::PositionToXY(long pos
, long *x
, long *y
) const
780 return GetPeer()->PositionToXY(pos
, x
, y
) ;
783 void wxTextCtrl::ShowPosition(long pos
)
785 return GetPeer()->ShowPosition(pos
) ;
788 int wxTextCtrl::GetLineLength(long lineNo
) const
790 return GetPeer()->GetLineLength(lineNo
) ;
793 wxString
wxTextCtrl::GetLineText(long lineNo
) const
795 return GetPeer()->GetLineText(lineNo
) ;
802 void wxTextCtrl::Command(wxCommandEvent
& event
)
804 SetValue (event
.GetString());
805 ProcessCommand (event
);
808 void wxTextCtrl::OnDropFiles(wxDropFilesEvent
& event
)
810 // By default, load the first file into the text window.
811 if (event
.GetNumberOfFiles() > 0)
813 LoadFile(event
.GetFiles()[0]);
817 void wxTextCtrl::OnEraseBackground(wxEraseEvent
& event
)
819 // all erasing should be done by the real mac control implementation
820 // while this is true for MLTE under classic, the HITextView is somehow
821 // transparent but background erase is not working correctly, so intercept
822 // things while we can...
826 void wxTextCtrl::OnChar(wxKeyEvent
& event
)
828 int key
= event
.GetKeyCode() ;
829 bool eat_key
= false ;
831 if ( key
== 'c' && event
.MetaDown() )
838 if ( !IsEditable() && key
!= WXK_LEFT
&& key
!= WXK_RIGHT
&& key
!= WXK_DOWN
&& key
!= WXK_UP
&& key
!= WXK_TAB
&&
839 !( key
== WXK_RETURN
&& ( (m_windowStyle
& wxPROCESS_ENTER
) || (m_windowStyle
& wxTE_MULTILINE
) ) )
840 /* && key != WXK_PRIOR && key != WXK_NEXT && key != WXK_HOME && key != WXK_END */
847 // Check if we have reached the max # of chars, but still allow navigation and deletion
848 if ( !IsMultiLine() && GetValue().Length() >= m_maxLength
&&
849 key
!= WXK_LEFT
&& key
!= WXK_RIGHT
&& key
!= WXK_TAB
&&
850 key
!= WXK_BACK
&& !( key
== WXK_RETURN
&& (m_windowStyle
& wxPROCESS_ENTER
) )
853 // eat it, we don't want to add more than allowed # of characters
857 // assume that any key not processed yet is going to modify the control
860 if ( key
== 'v' && event
.MetaDown() )
866 if ( key
== 'x' && event
.MetaDown() )
875 if (m_windowStyle
& wxPROCESS_ENTER
)
877 wxCommandEvent
event(wxEVT_COMMAND_TEXT_ENTER
, m_windowId
);
878 event
.SetEventObject( this );
879 event
.SetString( GetValue() );
880 if ( GetEventHandler()->ProcessEvent(event
) )
883 if ( !(m_windowStyle
& wxTE_MULTILINE
) )
885 wxWindow
*parent
= GetParent();
886 while( parent
&& !parent
->IsTopLevel() && parent
->GetDefaultItem() == NULL
) {
887 parent
= parent
->GetParent() ;
889 if ( parent
&& parent
->GetDefaultItem() )
891 wxButton
*def
= wxDynamicCast(parent
->GetDefaultItem(),
893 if ( def
&& def
->IsEnabled() )
895 wxCommandEvent
event(wxEVT_COMMAND_BUTTON_CLICKED
, def
->GetId() );
896 event
.SetEventObject(def
);
902 // this will make wxWidgets eat the ENTER key so that
903 // we actually prevent line wrapping in a single line
911 if ( !(m_windowStyle
& wxTE_PROCESS_TAB
))
914 if (!event
.ShiftDown())
915 flags
|= wxNavigationKeyEvent::IsForward
;
916 if (event
.ControlDown())
917 flags
|= wxNavigationKeyEvent::WinChange
;
923 // This is necessary (don't know why) or the tab will not
925 WriteText(wxT("\t"));
933 // perform keystroke handling
934 if ( wxTheApp
->MacGetCurrentEvent() != NULL
&& wxTheApp
->MacGetCurrentEventHandlerCallRef() != NULL
)
935 CallNextEventHandler((EventHandlerCallRef
)wxTheApp
->MacGetCurrentEventHandlerCallRef() , (EventRef
) wxTheApp
->MacGetCurrentEvent() ) ;
939 if ( wxMacConvertEventToRecord( (EventRef
) wxTheApp
->MacGetCurrentEvent() , &rec
) )
941 EventRecord
*ev
= &rec
;
944 keychar
= short(ev
->message
& charCodeMask
);
945 keycode
= short(ev
->message
& keyCodeMask
) >> 8 ;
947 m_peer
->HandleKey( keycode
, keychar
, ev
->modifiers
) ;
951 if ( ( key
>= 0x20 && key
< WXK_START
) ||
956 wxCommandEvent
event1(wxEVT_COMMAND_TEXT_UPDATED
, m_windowId
);
957 event1
.SetEventObject( this );
958 wxPostEvent(GetEventHandler(),event1
);
962 // ----------------------------------------------------------------------------
963 // standard handlers for standard edit menu events
964 // ----------------------------------------------------------------------------
966 void wxTextCtrl::OnCut(wxCommandEvent
& WXUNUSED(event
))
971 void wxTextCtrl::OnCopy(wxCommandEvent
& WXUNUSED(event
))
976 void wxTextCtrl::OnPaste(wxCommandEvent
& WXUNUSED(event
))
981 void wxTextCtrl::OnUndo(wxCommandEvent
& WXUNUSED(event
))
986 void wxTextCtrl::OnRedo(wxCommandEvent
& WXUNUSED(event
))
991 void wxTextCtrl::OnUpdateCut(wxUpdateUIEvent
& event
)
993 event
.Enable( CanCut() );
996 void wxTextCtrl::OnUpdateCopy(wxUpdateUIEvent
& event
)
998 event
.Enable( CanCopy() );
1001 void wxTextCtrl::OnUpdatePaste(wxUpdateUIEvent
& event
)
1003 event
.Enable( CanPaste() );
1006 void wxTextCtrl::OnUpdateUndo(wxUpdateUIEvent
& event
)
1008 event
.Enable( CanUndo() );
1011 void wxTextCtrl::OnUpdateRedo(wxUpdateUIEvent
& event
)
1013 event
.Enable( CanRedo() );
1016 bool wxTextCtrl::MacSetupCursor( const wxPoint
& pt
)
1018 if ( !GetPeer()->SetupCursor(pt
) )
1019 return wxWindow::MacSetupCursor( pt
) ;
1023 #if !TARGET_API_MAC_OSX
1025 // user pane implementation
1027 void wxTextCtrl::MacControlUserPaneDrawProc(wxInt16 part
)
1029 GetPeer()->MacControlUserPaneDrawProc( part
) ;
1032 wxInt16
wxTextCtrl::MacControlUserPaneHitTestProc(wxInt16 x
, wxInt16 y
)
1034 return GetPeer()->MacControlUserPaneHitTestProc( x
, y
) ;
1037 wxInt16
wxTextCtrl::MacControlUserPaneTrackingProc(wxInt16 x
, wxInt16 y
, void* actionProc
)
1039 return GetPeer()->MacControlUserPaneTrackingProc( x
, y
, actionProc
) ;
1042 void wxTextCtrl::MacControlUserPaneIdleProc()
1044 GetPeer()->MacControlUserPaneIdleProc( ) ;
1047 wxInt16
wxTextCtrl::MacControlUserPaneKeyDownProc(wxInt16 keyCode
, wxInt16 charCode
, wxInt16 modifiers
)
1049 return GetPeer()->MacControlUserPaneKeyDownProc( keyCode
, charCode
, modifiers
) ;
1052 void wxTextCtrl::MacControlUserPaneActivateProc(bool activating
)
1054 GetPeer()->MacControlUserPaneActivateProc( activating
) ;
1057 wxInt16
wxTextCtrl::MacControlUserPaneFocusProc(wxInt16 action
)
1059 return GetPeer()->MacControlUserPaneFocusProc( action
) ;
1062 void wxTextCtrl::MacControlUserPaneBackgroundProc(void* info
)
1064 GetPeer()->MacControlUserPaneBackgroundProc( info
) ;
1068 // ----------------------------------------------------------------------------
1069 // implementation base class
1070 // ----------------------------------------------------------------------------
1072 wxMacTextControl::wxMacTextControl(wxTextCtrl
* peer
) :
1073 wxMacControl( peer
)
1077 wxMacTextControl::~wxMacTextControl()
1081 void wxMacTextControl::SetStyle(long start
, long end
, const wxTextAttr
& style
)
1085 void wxMacTextControl::Copy()
1089 void wxMacTextControl::Cut()
1093 void wxMacTextControl::Paste()
1097 bool wxMacTextControl::CanPaste() const
1102 void wxMacTextControl::SetEditable(bool editable
)
1106 wxTextPos
wxMacTextControl::GetLastPosition() const
1108 return GetStringValue().Length() ;
1111 void wxMacTextControl::Replace( long from
, long to
, const wxString str
)
1115 void wxMacTextControl::Clear()
1117 SetStringValue( wxEmptyString
) ;
1120 bool wxMacTextControl::CanUndo() const
1125 void wxMacTextControl::Undo() { }
1127 bool wxMacTextControl::CanRedo() const
1132 void wxMacTextControl::Redo()
1136 long wxMacTextControl::XYToPosition(long x
, long y
) const
1141 bool wxMacTextControl::PositionToXY(long pos
, long *x
, long *y
) const
1146 void wxMacTextControl::ShowPosition( long WXUNUSED(pos
) )
1150 int wxMacTextControl::GetNumberOfLines() const
1152 ItemCount lines
= 0 ;
1153 wxString content
= GetStringValue() ;
1155 for (size_t i
= 0; i
< content
.Length() ; i
++)
1157 if (content
[i
] == '\r') lines
++;
1162 wxString
wxMacTextControl::GetLineText(long lineNo
) const
1164 // TODO change this if possible to reflect real lines
1165 wxString content
= GetStringValue() ;
1169 for (size_t i
= 0; i
< content
.Length() ; i
++)
1171 if (count
== lineNo
)
1173 // Add chars in line then
1176 for (size_t j
= i
; j
< content
.Length(); j
++)
1178 if (content
[j
] == '\n')
1186 if (content
[i
] == '\n') count
++;
1188 return wxEmptyString
;
1191 int wxMacTextControl::GetLineLength(long lineNo
) const
1193 // TODO change this if possible to reflect real lines
1194 wxString content
= GetStringValue() ;
1198 for (size_t i
= 0; i
< content
.Length() ; i
++)
1200 if (count
== lineNo
)
1202 // Count chars in line then
1204 for (size_t j
= i
; j
< content
.Length(); j
++)
1207 if (content
[j
] == '\n') return count
;
1212 if (content
[i
] == '\n') count
++;
1217 // ----------------------------------------------------------------------------
1218 // standard unicode control implementation
1219 // ----------------------------------------------------------------------------
1221 #if TARGET_API_MAC_OSX
1223 wxMacUnicodeTextControl::wxMacUnicodeTextControl( wxTextCtrl
*wxPeer
,
1224 const wxString
& str
,
1226 const wxSize
& size
, long style
) : wxMacTextControl( wxPeer
)
1228 m_font
= wxPeer
->GetFont() ;
1229 m_windowStyle
= style
;
1230 Rect bounds
= wxMacGetBoundsForControl( wxPeer
, pos
, size
) ;
1232 wxMacConvertNewlines10To13( &st
) ;
1233 wxMacCFStringHolder
cf(st
, m_font
.GetEncoding()) ;
1234 CFStringRef cfr
= cf
;
1235 Boolean isPassword
= ( m_windowStyle
& wxTE_PASSWORD
) != 0 ;
1236 m_valueTag
= isPassword
? kControlEditTextPasswordCFStringTag
: kControlEditTextCFStringTag
;
1237 CreateEditUnicodeTextControl( MAC_WXHWND(wxPeer
->MacGetTopLevelWindowRef()), &bounds
, cfr
, isPassword
, NULL
, &m_controlRef
) ;
1239 if ( !(m_windowStyle
& wxTE_MULTILINE
) )
1241 SetData
<Boolean
>( kControlEditTextPart
, kControlEditTextSingleLineTag
, true ) ;
1245 wxMacUnicodeTextControl::~wxMacUnicodeTextControl()
1249 void wxMacUnicodeTextControl::VisibilityChanged(bool shown
)
1251 if ( !(m_windowStyle
& wxTE_MULTILINE
) && shown
)
1253 // work around a refresh issue insofar as not always the entire content is shown even if this would be possible
1254 ControlEditTextSelectionRec sel
;
1255 CFStringRef value
= NULL
;
1257 verify_noerr( GetData
<ControlEditTextSelectionRec
>( 0, kControlEditTextSelectionTag
, &sel
) );
1258 verify_noerr( GetData
<CFStringRef
>( 0, m_valueTag
, &value
) );
1259 verify_noerr( SetData
<CFStringRef
>( 0, m_valueTag
, &value
) );
1260 verify_noerr( SetData
<ControlEditTextSelectionRec
>( 0, kControlEditTextSelectionTag
, &sel
) );
1262 CFRelease( value
) ;
1265 wxString
wxMacUnicodeTextControl::GetStringValue() const
1268 CFStringRef value
= GetData
<CFStringRef
>(0,m_valueTag
) ;
1271 wxMacCFStringHolder
cf(value
) ;
1272 result
= cf
.AsString() ;
1275 wxMacConvertNewlines13To10( &result
) ;
1277 wxMacConvertNewlines10To13( &result
) ;
1281 void wxMacUnicodeTextControl::SetStringValue( const wxString
&str
)
1284 wxMacConvertNewlines10To13( &st
) ;
1285 wxMacCFStringHolder
cf(st
, m_font
.GetEncoding() ) ;
1286 verify_noerr( SetData
<CFStringRef
>( 0, m_valueTag
, cf
) ) ;
1288 void wxMacUnicodeTextControl::Copy()
1290 SendHICommand( kHICommandCopy
) ;
1292 void wxMacUnicodeTextControl::Cut()
1294 SendHICommand( kHICommandCut
) ;
1296 void wxMacUnicodeTextControl::Paste()
1298 SendHICommand( kHICommandPaste
) ;
1300 bool wxMacUnicodeTextControl::CanPaste() const
1304 void wxMacUnicodeTextControl::SetEditable(bool editable
)
1306 SetData
<Boolean
>( 0 , kControlEditTextLockedTag
, (Boolean
) !editable
) ;
1308 void wxMacUnicodeTextControl::Remove( long from
, long to
)
1312 void wxMacUnicodeTextControl::GetSelection( long* from
, long* to
) const
1314 ControlEditTextSelectionRec sel
;
1315 verify_noerr(GetData
<ControlEditTextSelectionRec
>( 0, kControlEditTextSelectionTag
, &sel
) ) ;
1316 if ( from
) *from
= sel
.selStart
;
1317 if ( to
) *to
= sel
.selEnd
;
1320 void wxMacUnicodeTextControl::SetSelection( long from
, long to
)
1322 ControlEditTextSelectionRec sel
;
1323 sel
.selStart
= from
;
1325 SetData
<ControlEditTextSelectionRec
>( 0 , kControlEditTextSelectionTag
, &sel
) ;
1328 void wxMacUnicodeTextControl::WriteText(const wxString
& str
)
1331 wxMacConvertNewlines10To13( &st
) ;
1332 #if MAC_OS_X_VERSION_MAX_ALLOWED > MAC_OS_X_VERSION_10_2
1333 wxMacCFStringHolder
cf(st
, m_font
.GetEncoding() ) ;
1334 CFStringRef value
= cf
;
1335 SetData
<CFStringRef
>( 0, kControlEditTextInsertCFStringRefTag
, &value
);
1337 wxString val
= GetStringValue() ;
1339 GetSelection( &start
, &end
) ;
1340 val
.Remove( start
, end
- start
) ;
1341 val
.insert( start
, str
) ;
1342 SetStringValue( val
) ;
1343 SetSelection( start
+ str
.Length() , start
+ str
.Length() ) ;
1349 // ----------------------------------------------------------------------------
1350 // MLTE control implementation (common part)
1351 // ----------------------------------------------------------------------------
1353 // if mlte is on read only , no changes at all are allowed, not even from
1354 // procedural API, in order to allow changes via API all the same we must undo
1355 // the readonly status while we are executing, this class helps to do so
1357 class wxMacEditHelper
1360 wxMacEditHelper( TXNObject txn
)
1362 TXNControlTag tag
[] = { kTXNIOPrivilegesTag
} ;
1364 TXNGetTXNObjectControls( m_txn
, 1 , tag
, m_data
) ;
1365 if ( m_data
[0].uValue
== kTXNReadOnly
)
1367 TXNControlData data
[] = { { kTXNReadWrite
} } ;
1368 TXNSetTXNObjectControls( m_txn
, false , 1 , tag
, data
) ;
1373 TXNControlTag tag
[] = { kTXNIOPrivilegesTag
} ;
1374 if ( m_data
[0].uValue
== kTXNReadOnly
)
1376 TXNSetTXNObjectControls( m_txn
, false , 1 , tag
, m_data
) ;
1381 TXNControlData m_data
[1] ;
1384 wxMacMLTEControl::wxMacMLTEControl( wxTextCtrl
*peer
) : wxMacTextControl( peer
)
1386 SetNeedsFocusRect( true ) ;
1389 wxString
wxMacMLTEControl::GetStringValue() const
1393 Size actualSize
= 0;
1397 err
= TXNGetDataEncoded( m_txn
, kTXNStartOffset
, kTXNEndOffset
, &theText
, kTXNUnicodeTextData
);
1405 actualSize
= GetHandleSize( theText
) / sizeof( UniChar
) ;
1406 if ( actualSize
> 0 )
1408 wxChar
*ptr
= NULL
;
1409 #if SIZEOF_WCHAR_T == 2
1410 ptr
= new wxChar
[actualSize
+ 1 ] ;
1411 wxStrncpy( ptr
, (wxChar
*) *theText
, actualSize
) ;
1413 SetHandleSize( theText
, ( actualSize
+ 1 ) * sizeof( UniChar
) ) ;
1415 (((UniChar
*)*theText
)[actualSize
]) = 0 ;
1416 wxMBConvUTF16BE converter
;
1417 size_t noChars
= converter
.MB2WC( NULL
, (const char*)*theText
, 0 ) ;
1418 ptr
= new wxChar
[noChars
+ 1] ;
1420 noChars
= converter
.MB2WC( ptr
, (const char*)*theText
, noChars
) ;
1422 HUnlock( theText
) ;
1424 ptr
[actualSize
] = 0 ;
1425 result
= wxString( ptr
) ;
1428 DisposeHandle( theText
) ;
1432 err
= TXNGetDataEncoded( m_txn
, kTXNStartOffset
, kTXNEndOffset
, &theText
, kTXNTextData
);
1440 actualSize
= GetHandleSize( theText
) ;
1441 if ( actualSize
> 0 )
1444 result
= wxString( *theText
, wxConvLocal
, actualSize
) ;
1445 HUnlock( theText
) ;
1447 DisposeHandle( theText
) ;
1452 wxMacConvertNewlines13To10( &result
) ;
1454 wxMacConvertNewlines10To13( &result
) ;
1459 void wxMacMLTEControl::SetStringValue( const wxString
&str
)
1463 wxMacConvertNewlines10To13( &st
) ;
1465 wxMacWindowClipper
c( m_peer
) ;
1467 wxMacEditHelper
help(m_txn
) ;
1468 SetTXNData( st
, kTXNStartOffset
, kTXNEndOffset
) ;
1470 TXNSetSelection( m_txn
, 0, 0);
1471 TXNShowSelection( m_txn
, kTXNShowStart
);
1475 TXNFrameOptions
wxMacMLTEControl::FrameOptionsFromWXStyle( long wxStyle
)
1477 TXNFrameOptions frameOptions
=
1478 kTXNDontDrawCaretWhenInactiveMask
;
1480 if ( ! ( wxStyle
& wxTE_NOHIDESEL
) )
1481 frameOptions
|= kTXNDontDrawSelectionWhenInactiveMask
;
1483 if ( wxStyle
& wxTE_MULTILINE
)
1485 if ( ! ( wxStyle
& wxTE_DONTWRAP
) )
1486 frameOptions
|= kTXNAlwaysWrapAtViewEdgeMask
;
1489 frameOptions
|= kTXNAlwaysWrapAtViewEdgeMask
;
1490 frameOptions
|= kTXNWantHScrollBarMask
;
1493 if ( !(wxStyle
& wxTE_NO_VSCROLL
) )
1495 frameOptions
|= kTXNWantVScrollBarMask
;
1496 if ( frameOptions
& kTXNWantHScrollBarMask
)
1497 frameOptions
|= kTXNDrawGrowIconMask
;
1501 frameOptions
|= kTXNSingleLineOnlyMask
;
1503 if ( wxStyle
& wxHSCROLL
)
1504 frameOptions
|= kTXNWantHScrollBarMask
;
1506 return frameOptions
;
1509 void wxMacMLTEControl::AdjustCreationAttributes( const wxColour
&background
, bool visible
)
1511 TXNControlTag iControlTags
[] =
1513 kTXNDoFontSubstitution
,
1514 kTXNWordWrapStateTag
,
1516 TXNControlData iControlData
[] =
1522 int toptag
= WXSIZEOF( iControlTags
) ;
1524 if ( m_windowStyle
& wxTE_MULTILINE
)
1526 if (m_windowStyle
& wxTE_DONTWRAP
)
1527 iControlData
[1].uValue
= kTXNNoAutoWrap
;
1529 iControlData
[1].uValue
= kTXNAutoWrap
;
1531 verify_noerr( TXNSetTXNObjectControls( m_txn
, false, toptag
,
1532 iControlTags
, iControlData
)) ;
1534 // setting the default font
1535 // under 10.2 this causes a visible caret, therefore we avoid it
1537 if ( UMAGetSystemVersion() >= 0x1030 )
1543 GetThemeFont(kThemeSystemFont
, GetApplicationScript() , fontName
, &fontSize
, &fontStyle
) ;
1545 TXNTypeAttributes typeAttr
[] =
1547 { kTXNQDFontNameAttribute
, kTXNQDFontNameAttributeSize
, { (void*) fontName
} } ,
1548 { kTXNQDFontSizeAttribute
, kTXNFontSizeAttributeSize
, { (void*) (fontSize
<< 16) } } ,
1549 { kTXNQDFontStyleAttribute
, kTXNQDFontStyleAttributeSize
, { (void*) normal
} } ,
1552 verify_noerr( TXNSetTypeAttributes (m_txn
, sizeof( typeAttr
) / sizeof(TXNTypeAttributes
) , typeAttr
,
1557 if ( m_windowStyle
& wxTE_PASSWORD
)
1560 verify_noerr(TXNEchoMode( m_txn
, c
, 0 , true )) ;
1563 TXNBackground tback
;
1564 tback
.bgType
= kTXNBackgroundTypeRGB
;
1565 tback
.bg
.color
= MAC_WXCOLORREF( background
.GetPixel() );
1566 TXNSetBackground( m_txn
, &tback
);
1569 void wxMacMLTEControl::SetBackground( const wxBrush
&brush
)
1571 // currently only solid background are supported
1572 TXNBackground tback
;
1573 tback
.bgType
= kTXNBackgroundTypeRGB
;
1574 tback
.bg
.color
= MAC_WXCOLORREF( brush
.GetColour().GetPixel() );
1575 TXNSetBackground( m_txn
, &tback
);
1578 void wxMacMLTEControl::TXNSetAttribute( const wxTextAttr
& style
, long from
, long to
)
1580 TXNTypeAttributes typeAttr
[4] ;
1581 Str255 fontName
= "\pMonaco" ;
1582 SInt16 fontSize
= 12 ;
1583 Style fontStyle
= normal
;
1585 int attrCounter
= 0 ;
1586 if ( style
.HasFont() )
1588 const wxFont
&font
= style
.GetFont() ;
1589 wxMacStringToPascal( font
.GetFaceName() , fontName
) ;
1590 fontSize
= font
.GetPointSize() ;
1591 if ( font
.GetUnderlined() )
1592 fontStyle
|= underline
;
1593 if ( font
.GetWeight() == wxBOLD
)
1595 if ( font
.GetStyle() == wxITALIC
)
1596 fontStyle
|= italic
;
1598 typeAttr
[attrCounter
].tag
= kTXNQDFontNameAttribute
;
1599 typeAttr
[attrCounter
].size
= kTXNQDFontNameAttributeSize
;
1600 typeAttr
[attrCounter
].data
.dataPtr
= (void*) fontName
;
1601 typeAttr
[attrCounter
+1].tag
= kTXNQDFontSizeAttribute
;
1602 typeAttr
[attrCounter
+1].size
= kTXNFontSizeAttributeSize
;
1603 typeAttr
[attrCounter
+1].data
.dataValue
= (fontSize
<< 16) ;
1604 typeAttr
[attrCounter
+2].tag
= kTXNQDFontStyleAttribute
;
1605 typeAttr
[attrCounter
+2].size
= kTXNQDFontStyleAttributeSize
;
1606 typeAttr
[attrCounter
+2].data
.dataValue
= fontStyle
;
1609 if ( style
.HasTextColour() )
1611 typeAttr
[attrCounter
].tag
= kTXNQDFontColorAttribute
;
1612 typeAttr
[attrCounter
].size
= kTXNQDFontColorAttributeSize
;
1613 typeAttr
[attrCounter
].data
.dataPtr
= (void*) &color
;
1614 color
= MAC_WXCOLORREF(style
.GetTextColour().GetPixel()) ;
1617 if ( attrCounter
> 0 )
1619 verify_noerr( TXNSetTypeAttributes ( m_txn
, attrCounter
, typeAttr
, from
, to
) );
1623 void wxMacMLTEControl::SetFont( const wxFont
& font
, const wxColour
& foreground
, long windowStyle
)
1625 wxMacEditHelper
help(m_txn
) ;
1626 TXNSetAttribute( wxTextAttr(foreground
,wxNullColour
,font
) , kTXNStartOffset
,kTXNEndOffset
) ;
1628 void wxMacMLTEControl::SetStyle(long start
, long end
, const wxTextAttr
& style
)
1630 wxMacEditHelper
help(m_txn
) ;
1631 TXNSetAttribute( style
, start
,end
) ;
1634 void wxMacMLTEControl::Copy()
1636 ClearCurrentScrap();
1638 TXNConvertToPublicScrap();
1641 void wxMacMLTEControl::Cut()
1643 ClearCurrentScrap();
1645 TXNConvertToPublicScrap();
1648 void wxMacMLTEControl::Paste()
1650 TXNConvertFromPublicScrap();
1654 bool wxMacMLTEControl::CanPaste() const
1656 return TXNIsScrapPastable() ;
1659 void wxMacMLTEControl::SetEditable(bool editable
)
1661 TXNControlTag tag
[] = { kTXNIOPrivilegesTag
} ;
1662 TXNControlData data
[] = { { editable
? kTXNReadWrite
: kTXNReadOnly
} } ;
1663 TXNSetTXNObjectControls( m_txn
, false , WXSIZEOF(tag
) , tag
, data
) ;
1666 wxTextPos
wxMacMLTEControl::GetLastPosition() const
1668 wxTextPos actualsize
= 0 ;
1671 OSErr err
= TXNGetDataEncoded( m_txn
, kTXNStartOffset
, kTXNEndOffset
, &theText
, kTXNTextData
);
1679 actualsize
= GetHandleSize( theText
) ;
1680 DisposeHandle( theText
) ;
1686 void wxMacMLTEControl::Replace( long from
, long to
, const wxString str
)
1688 wxString value
= str
;
1689 wxMacConvertNewlines10To13( &value
) ;
1691 wxMacEditHelper
help( m_txn
) ;
1692 wxMacWindowClipper
c( m_peer
) ;
1694 TXNSetSelection(m_txn
, from
, to
) ;
1696 SetTXNData( value
, kTXNUseCurrentSelection
, kTXNUseCurrentSelection
) ;
1699 void wxMacMLTEControl::Remove( long from
, long to
)
1701 wxMacWindowClipper
c( m_peer
) ;
1702 wxMacEditHelper
help( m_txn
) ;
1703 TXNSetSelection(m_txn
, from
, to
) ;
1707 void wxMacMLTEControl::GetSelection( long* from
, long* to
) const
1709 TXNGetSelection( m_txn
, (TXNOffset
*) from
, (TXNOffset
*) to
) ;
1712 void wxMacMLTEControl::SetSelection( long from
, long to
)
1714 wxMacWindowClipper
c( m_peer
) ;
1715 /* change the selection */
1716 if ((from
== -1) && (to
== -1))
1717 TXNSelectAll(m_txn
);
1719 TXNSetSelection( m_txn
, from
, to
);
1720 TXNShowSelection( m_txn
, kTXNShowStart
);
1723 void wxMacMLTEControl::WriteText(const wxString
& str
)
1726 wxMacConvertNewlines10To13( &st
) ;
1728 long start
, end
, dummy
;
1729 GetSelection( &start
, &dummy
) ;
1730 wxMacWindowClipper
c( m_peer
) ;
1732 wxMacEditHelper
helper( m_txn
) ;
1733 SetTXNData( st
, kTXNUseCurrentSelection
, kTXNUseCurrentSelection
) ;
1735 GetSelection( &dummy
, &end
) ;
1736 // TODO SetStyle( start , end , GetDefaultStyle() ) ;
1739 void wxMacMLTEControl::Clear()
1741 wxMacWindowClipper
c( m_peer
) ;
1742 wxMacEditHelper
st(m_txn
) ;
1743 TXNSetSelection( m_txn
, kTXNStartOffset
, kTXNEndOffset
) ;
1747 bool wxMacMLTEControl::CanUndo() const
1749 return TXNCanUndo( m_txn
, NULL
) ;
1752 void wxMacMLTEControl::Undo()
1757 bool wxMacMLTEControl::CanRedo() const
1759 return TXNCanRedo( m_txn
, NULL
) ;
1762 void wxMacMLTEControl::Redo()
1767 int wxMacMLTEControl::GetNumberOfLines() const
1769 ItemCount lines
= 0 ;
1770 TXNGetLineCount(m_txn
, &lines
) ;
1774 long wxMacMLTEControl::XYToPosition(long x
, long y
) const
1778 wxTextPos lastpos
= GetLastPosition() ;
1780 // TODO find a better implementation : while we can get the
1781 // line metrics of a certain line, we don't get its starting
1782 // position, so it would probably be rather a binary search
1783 // for the start position
1786 int lastHeight
= 0 ;
1789 for ( n
= 0 ; n
<= (ItemCount
) lastpos
; ++n
)
1791 if ( y
== ypos
&& x
== xpos
)
1794 TXNOffsetToPoint( m_txn
, n
, &curpt
);
1796 if ( curpt
.v
> lastHeight
)
1801 lastHeight
= curpt
.v
;
1809 bool wxMacMLTEControl::PositionToXY(long pos
, long *x
, long *y
) const
1813 wxTextPos lastpos
= GetLastPosition() ;
1818 if ( pos
<= lastpos
)
1820 // TODO find a better implementation : while we can get the
1821 // line metrics of a certain line, we don't get its starting
1822 // position, so it would probably be rather a binary search
1823 // for the start position
1826 int lastHeight
= 0 ;
1829 for ( n
= 0 ; n
<= (ItemCount
) pos
; ++n
)
1831 TXNOffsetToPoint(m_txn
, n
, &curpt
);
1833 if ( curpt
.v
> lastHeight
)
1838 lastHeight
= curpt
.v
;
1843 if ( y
) *y
= ypos
;
1844 if ( x
) *x
= xpos
;
1850 void wxMacMLTEControl::ShowPosition( long pos
)
1852 #if TARGET_RT_MAC_MACHO && defined(AVAILABLE_MAC_OS_X_VERSION_10_2_AND_LATER)
1856 TXNOffset selstart
, selend
;
1857 TXNGetSelection( m_txn
, &selstart
, &selend
) ;
1858 TXNOffsetToPoint( m_txn
, selstart
, ¤t
);
1859 TXNOffsetToPoint( m_txn
, pos
, &desired
);
1860 //TODO use HIPoints for 10.3 and above
1861 if ( (UInt32
) TXNScroll
!= (UInt32
) kUnresolvedCFragSymbolAddress
)
1863 OSErr theErr
= noErr
;
1864 SInt32 dv
= desired
.v
- current
.v
;
1865 SInt32 dh
= desired
.h
- current
.h
;
1866 TXNShowSelection( m_txn
, true ) ;
1867 theErr
= TXNScroll( m_txn
, kTXNScrollUnitsInPixels
, kTXNScrollUnitsInPixels
, &dv
, &dh
);
1868 wxASSERT_MSG( theErr
== noErr
, _T("TXNScroll returned an error!") );
1874 void wxMacMLTEControl::SetTXNData( const wxString
& st
, TXNOffset start
, TXNOffset end
)
1877 #if SIZEOF_WCHAR_T == 2
1878 size_t len
= st
.Len() ;
1879 TXNSetData( m_txn
, kTXNUnicodeTextData
, (void*)st
.wc_str(), len
* 2,
1882 wxMBConvUTF16BE converter
;
1883 ByteCount byteBufferLen
= converter
.WC2MB( NULL
, st
.wc_str() , 0 ) ;
1884 UniChar
*unibuf
= (UniChar
*) malloc(byteBufferLen
) ;
1885 converter
.WC2MB( (char*) unibuf
, st
.wc_str() , byteBufferLen
) ;
1886 TXNSetData( m_txn
, kTXNUnicodeTextData
, (void*)unibuf
, byteBufferLen
,
1891 wxCharBuffer text
= st
.mb_str(wxConvLocal
) ;
1892 TXNSetData( m_txn
, kTXNTextData
, (void*)text
.data(), strlen( text
) ,
1898 wxString
wxMacMLTEControl::GetLineText(long lineNo
) const
1902 if ( lineNo
< GetNumberOfLines() )
1910 // get the first possible position in the control
1912 TXNOffsetToPoint(m_txn
, 0, &firstPoint
);
1914 // Iterate through the lines until we reach the one we want,
1915 // adding to our current y pixel point position
1916 while (ypos
< lineNo
)
1918 TXNGetLineMetrics(m_txn
, ypos
++, &lineWidth
, &lineHeight
);
1919 currentHeight
+= lineHeight
;
1922 Point thePoint
= { firstPoint
.v
+ (currentHeight
>> 16), firstPoint
.h
+ (0) };
1923 TXNOffset theOffset
;
1924 TXNPointToOffset(m_txn
, thePoint
, &theOffset
);
1926 wxString content
= GetStringValue() ;
1927 Point currentPoint
= thePoint
;
1928 while(thePoint
.v
== currentPoint
.v
&& theOffset
< content
.length())
1930 line
+= content
[theOffset
];
1931 TXNOffsetToPoint(m_txn
, ++theOffset
, ¤tPoint
);
1937 int wxMacMLTEControl::GetLineLength(long lineNo
) const
1941 if ( lineNo
< GetNumberOfLines() )
1949 // get the first possible position in the control
1951 TXNOffsetToPoint(m_txn
, 0, &firstPoint
);
1953 // Iterate through the lines until we reach the one we want,
1954 // adding to our current y pixel point position
1955 while (ypos
< lineNo
)
1957 TXNGetLineMetrics(m_txn
, ypos
++, &lineWidth
, &lineHeight
);
1958 currentHeight
+= lineHeight
;
1961 Point thePoint
= { firstPoint
.v
+ (currentHeight
>> 16), firstPoint
.h
+ (0) };
1962 TXNOffset theOffset
;
1963 TXNPointToOffset(m_txn
, thePoint
, &theOffset
);
1965 wxString content
= GetStringValue() ;
1966 Point currentPoint
= thePoint
;
1967 while(thePoint
.v
== currentPoint
.v
&& theOffset
< content
.length())
1970 TXNOffsetToPoint(m_txn
, ++theOffset
, ¤tPoint
);
1977 // ----------------------------------------------------------------------------
1978 // MLTE control implementation (classic part)
1979 // ----------------------------------------------------------------------------
1981 // OS X Notes : We still don't have a full replacement for MLTE, so this implementation
1982 // has to live on. We have different problems coming from outdated implementations on the
1983 // various OS X versions. Most deal with the scrollbars: they are not correctly embedded
1984 // while this can be solved on 10.3 by reassigning them the correct place, on 10.2 there is
1985 // no way out, therefore we are using our own implementation and our own scrollbars ....
1987 #ifdef __WXMAC_OSX__
1989 TXNScrollInfoUPP gTXNScrollInfoProc
= NULL
;
1990 ControlActionUPP gTXNScrollActionProc
= NULL
;
1992 pascal void wxMacMLTEClassicControl::TXNScrollInfoProc (SInt32 iValue
, SInt32 iMaximumValue
, TXNScrollBarOrientation
1993 iScrollBarOrientation
, SInt32 iRefCon
)
1995 wxMacMLTEClassicControl
* mlte
= (wxMacMLTEClassicControl
*) iRefCon
;
1996 SInt32 value
= wxMax( iValue
, 0 ) ;
1997 SInt32 maximum
= wxMax( iMaximumValue
, 0 ) ;
1999 if ( iScrollBarOrientation
== kTXNHorizontal
)
2001 if ( mlte
->m_sbHorizontal
)
2003 SetControl32BitValue( mlte
->m_sbHorizontal
, value
) ;
2004 SetControl32BitMaximum( mlte
->m_sbHorizontal
, maximum
) ;
2005 mlte
->m_lastHorizontalValue
= value
;
2008 else if ( iScrollBarOrientation
== kTXNVertical
)
2010 if ( mlte
->m_sbVertical
)
2012 SetControl32BitValue( mlte
->m_sbVertical
, value
) ;
2013 SetControl32BitMaximum( mlte
->m_sbVertical
, maximum
) ;
2014 mlte
->m_lastVerticalValue
= value
;
2019 pascal void wxMacMLTEClassicControl::TXNScrollActionProc( ControlRef controlRef
, ControlPartCode partCode
)
2022 wxMacMLTEClassicControl
* mlte
= (wxMacMLTEClassicControl
*) GetControlReference( controlRef
) ;
2026 if ( controlRef
!= mlte
->m_sbVertical
&& controlRef
!= mlte
->m_sbHorizontal
)
2029 bool isHorizontal
= ( controlRef
== mlte
->m_sbHorizontal
) ;
2031 SInt32 minimum
= 0 ;
2032 SInt32 maximum
= GetControl32BitMaximum( controlRef
) ;
2033 SInt32 value
= GetControl32BitValue( controlRef
) ;
2037 case kControlDownButtonPart
:
2040 case kControlUpButtonPart
:
2043 case kControlPageDownPart
:
2044 delta
= GetControlViewSize( controlRef
) ;
2046 case kControlPageUpPart
:
2047 delta
= -GetControlViewSize( controlRef
) ;
2049 case kControlIndicatorPart
:
2051 ( isHorizontal
? mlte
->m_lastHorizontalValue
: mlte
->m_lastVerticalValue
) ;
2058 SInt32 newValue
= value
;
2060 if ( partCode
!= kControlIndicatorPart
)
2062 if( value
+ delta
< minimum
)
2063 delta
= minimum
- value
;
2064 if ( value
+ delta
> maximum
)
2065 delta
= maximum
- value
;
2067 SetControl32BitValue( controlRef
, value
+ delta
) ;
2068 newValue
= value
+ delta
;
2071 SInt32 verticalDelta
= isHorizontal
? 0 : delta
;
2072 SInt32 horizontalDelta
= isHorizontal
? delta
: 0 ;
2074 err
= TXNScroll( mlte
->m_txn
, kTXNScrollUnitsInPixels
, kTXNScrollUnitsInPixels
,
2075 &verticalDelta
, &horizontalDelta
);
2078 mlte
->m_lastHorizontalValue
= newValue
;
2080 mlte
->m_lastVerticalValue
= newValue
;
2085 // make correct activations
2086 void wxMacMLTEClassicControl::MacActivatePaneText(Boolean setActive
)
2088 wxTextCtrl
* textctrl
= (wxTextCtrl
*) GetControlReference(m_controlRef
);
2090 wxMacWindowClipper
clipper( textctrl
) ;
2091 TXNActivate(m_txn
, m_txnFrameID
, setActive
);
2093 ControlRef controlFocus
= 0 ;
2094 GetKeyboardFocus( m_txnWindow
, &controlFocus
) ;
2095 if ( controlFocus
== m_controlRef
)
2096 TXNFocus( m_txn
, setActive
);
2099 void wxMacMLTEClassicControl::MacFocusPaneText(Boolean setFocus
)
2101 TXNFocus( m_txn
, setFocus
);
2104 // guards against inappropriate redraw (hidden objects drawing onto window)
2106 void wxMacMLTEClassicControl::MacSetObjectVisibility(Boolean vis
)
2108 ControlRef controlFocus
= 0 ;
2109 GetKeyboardFocus( m_txnWindow
, &controlFocus
) ;
2111 if ( controlFocus
== m_controlRef
&& vis
== false )
2113 SetKeyboardFocus( m_txnWindow
, m_controlRef
, kControlFocusNoPart
) ;
2116 TXNControlTag iControlTags
[] =
2120 TXNControlData iControlData
[] =
2125 int toptag
= WXSIZEOF( iControlTags
) ;
2127 verify_noerr( TXNGetTXNObjectControls( m_txn
, toptag
,
2128 iControlTags
, iControlData
) ) ;
2130 if ( iControlData
[0].uValue
!= vis
)
2132 iControlData
[0].uValue
= vis
;
2133 verify_noerr( TXNSetTXNObjectControls( m_txn
, false , toptag
,
2134 iControlTags
, iControlData
)) ;
2136 // we right now are always clipping as partial visibility (overlapped) visibility
2137 // is also a problem, if we run into further problems we might set the FrameBounds to an empty
2141 // make sure that the TXNObject is at the right position
2143 void wxMacMLTEClassicControl::MacUpdatePosition()
2145 wxTextCtrl
* textctrl
= (wxTextCtrl
*) GetControlReference(m_controlRef
);
2146 if ( textctrl
== NULL
)
2150 UMAGetControlBoundsInWindowCoords(m_controlRef
, &bounds
);
2152 if ( !EqualRect( &bounds
, &m_txnControlBounds
) )
2155 Rect oldBounds
= m_txnControlBounds
;
2156 m_txnControlBounds
= bounds
;
2157 wxMacWindowClipper
cl(textctrl
) ;
2159 #ifdef __WXMAC_OSX__
2160 bool isCompositing
= textctrl
->MacGetTopLevelWindow()->MacUsesCompositing() ;
2161 if ( m_sbHorizontal
|| m_sbVertical
)
2163 int w
= bounds
.right
- bounds
.left
;
2164 int h
= bounds
.bottom
- bounds
.top
;
2166 if ( m_sbHorizontal
)
2170 sbBounds
.left
= -1 ;
2171 sbBounds
.top
= h
- 14 ;
2172 sbBounds
.right
= w
+ 1 ;
2173 sbBounds
.bottom
= h
+ 1 ;
2175 if ( !isCompositing
)
2176 OffsetRect( &sbBounds
, m_txnControlBounds
.left
, m_txnControlBounds
.top
) ;
2178 SetControlBounds( m_sbHorizontal
, &sbBounds
) ;
2179 SetControlViewSize( m_sbHorizontal
, w
) ;
2185 sbBounds
.left
= w
- 14 ;
2187 sbBounds
.right
= w
+ 1 ;
2188 sbBounds
.bottom
= m_sbHorizontal
? h
- 14 : h
+ 1 ;
2190 if ( !isCompositing
)
2191 OffsetRect( &sbBounds
, m_txnControlBounds
.left
, m_txnControlBounds
.top
) ;
2193 SetControlBounds( m_sbVertical
, &sbBounds
) ;
2194 SetControlViewSize( m_sbVertical
, h
) ;
2197 TXNSetFrameBounds( m_txn
, m_txnControlBounds
.top
, m_txnControlBounds
.left
,
2198 m_txnControlBounds
.bottom
- ( m_sbHorizontal
? 14 : 0 ) , m_txnControlBounds
.right
- ( m_sbVertical
? 14 : 0 ), m_txnFrameID
);
2201 TXNSetFrameBounds( m_txn
, m_txnControlBounds
.top
, m_txnControlBounds
.left
,
2202 wxMax( m_txnControlBounds
.bottom
, m_txnControlBounds
.top
) ,
2203 wxMax( m_txnControlBounds
.right
, m_txnControlBounds
.left
) , m_txnFrameID
);
2205 // the SetFrameBounds method unter classic sometimes does not correctly scroll a selection into sight after a
2206 // movement, therefore we have to force it
2208 TXNLongRect textRect
;
2209 TXNGetRectBounds( m_txn
, NULL
, NULL
, &textRect
) ;
2210 if ( textRect
.left
< m_txnControlBounds
.left
)
2212 TXNShowSelection( m_txn
, false ) ;
2218 void wxMacMLTEClassicControl::SetRect( Rect
*r
)
2220 wxMacControl::SetRect( r
) ;
2221 MacUpdatePosition() ;
2224 void wxMacMLTEClassicControl::MacControlUserPaneDrawProc(wxInt16 thePart
)
2226 wxTextCtrl
* textctrl
= (wxTextCtrl
*) GetControlReference(m_controlRef
);
2227 if ( textctrl
== NULL
)
2230 if ( textctrl
->MacIsReallyShown() )
2232 wxMacWindowClipper
clipper( textctrl
) ;
2233 TXNDraw( m_txn
, NULL
) ;
2237 wxInt16
wxMacMLTEClassicControl::MacControlUserPaneHitTestProc(wxInt16 x
, wxInt16 y
)
2239 Point where
= { y
, x
} ;
2240 ControlPartCode result
;
2243 wxTextCtrl
* textctrl
= (wxTextCtrl
*) GetControlReference(m_controlRef
);
2244 if ( textctrl
== NULL
)
2247 if (textctrl
->MacIsReallyShown() )
2249 if (PtInRect(where
, &m_txnControlBounds
))
2250 result
= kControlEditTextPart
;
2253 // sometimes we get the coords also in control local coordinates, therefore test again
2254 if ( textctrl
->MacGetTopLevelWindow()->MacUsesCompositing() )
2257 textctrl
->MacClientToRootWindow( &x
, &y
) ;
2261 if (PtInRect(where
, &m_txnControlBounds
))
2262 result
= kControlEditTextPart
;
2270 wxInt16
wxMacMLTEClassicControl::MacControlUserPaneTrackingProc( wxInt16 x
, wxInt16 y
, void* actionProc
)
2272 wxTextCtrl
* textctrl
= (wxTextCtrl
*) GetControlReference(m_controlRef
);
2273 if ( textctrl
== NULL
)
2276 ControlPartCode partCodeResult
= 0;
2278 if (textctrl
->MacIsReallyShown() )
2280 Point startPt
= { y
,x
} ;
2281 // for compositing, we must convert these into toplevel window coordinates, because hittesting expects them
2282 if ( textctrl
->MacGetTopLevelWindow()->MacUsesCompositing() )
2285 textctrl
->MacClientToRootWindow( &x
, &y
) ;
2290 switch (MacControlUserPaneHitTestProc( startPt
.h
, startPt
.v
))
2292 case kControlEditTextPart
:
2294 wxMacWindowClipper
clipper( textctrl
) ;
2297 ConvertEventRefToEventRecord( (EventRef
) wxTheApp
->MacGetCurrentEvent() , &rec
) ;
2298 TXNClick( m_txn
, &rec
);
2304 return partCodeResult
;
2307 void wxMacMLTEClassicControl::MacControlUserPaneIdleProc()
2309 wxTextCtrl
* textctrl
= (wxTextCtrl
*) GetControlReference(m_controlRef
);
2310 if ( textctrl
== NULL
)
2313 if (textctrl
->MacIsReallyShown())
2315 if (IsControlActive(m_controlRef
))
2319 wxMacWindowClipper
clipper( textctrl
) ;
2324 if (PtInRect(mousep
, &m_txnControlBounds
))
2327 RectRgn((theRgn
= NewRgn()), &m_txnControlBounds
);
2328 TXNAdjustCursor(m_txn
, theRgn
);
2335 wxInt16
wxMacMLTEClassicControl::MacControlUserPaneKeyDownProc (wxInt16 keyCode
, wxInt16 charCode
, wxInt16 modifiers
)
2337 wxTextCtrl
* textctrl
= (wxTextCtrl
*) GetControlReference(m_controlRef
);
2338 if ( textctrl
== NULL
)
2341 wxMacWindowClipper
clipper( textctrl
) ;
2344 memset( &ev
, 0 , sizeof( ev
) ) ;
2346 ev
.modifiers
= modifiers
;
2347 ev
.message
= (( keyCode
<< 8 ) & keyCodeMask
) + ( charCode
& charCodeMask
) ;
2348 TXNKeyDown( m_txn
, &ev
);
2350 return kControlEntireControl
;
2353 void wxMacMLTEClassicControl::MacControlUserPaneActivateProc( bool activating
)
2355 MacActivatePaneText( activating
);
2358 wxInt16
wxMacMLTEClassicControl::MacControlUserPaneFocusProc(wxInt16 action
)
2360 ControlPartCode focusResult
;
2362 focusResult
= kControlFocusNoPart
;
2363 wxTextCtrl
* textctrl
= (wxTextCtrl
*) GetControlReference(m_controlRef
);
2364 if ( textctrl
== NULL
)
2367 wxMacWindowClipper
clipper( textctrl
) ;
2369 ControlRef controlFocus
= 0 ;
2370 GetKeyboardFocus( m_txnWindow
, &controlFocus
) ;
2371 bool wasFocused
= ( controlFocus
== m_controlRef
) ;
2375 case kControlFocusPrevPart
:
2376 case kControlFocusNextPart
:
2377 MacFocusPaneText( ( !wasFocused
));
2378 focusResult
= (!wasFocused
) ? (ControlPartCode
) kControlEditTextPart
: (ControlPartCode
) kControlFocusNoPart
;
2381 case kControlFocusNoPart
:
2383 MacFocusPaneText( false);
2384 focusResult
= kControlFocusNoPart
;
2391 void wxMacMLTEClassicControl::MacControlUserPaneBackgroundProc( void *info
)
2395 wxMacMLTEClassicControl::wxMacMLTEClassicControl( wxTextCtrl
*wxPeer
,
2396 const wxString
& str
,
2398 const wxSize
& size
, long style
) : wxMacMLTEControl( wxPeer
)
2400 m_font
= wxPeer
->GetFont() ;
2401 m_windowStyle
= style
;
2402 Rect bounds
= wxMacGetBoundsForControl( wxPeer
, pos
, size
) ;
2404 wxMacConvertNewlines10To13( &st
) ;
2408 featurSet
= kControlSupportsEmbedding
| kControlSupportsFocus
| kControlWantsIdle
2409 | kControlWantsActivate
| kControlHandlesTracking
// | kControlHasSpecialBackground
2410 | kControlGetsFocusOnClick
| kControlSupportsLiveFeedback
;
2412 verify_noerr( ::CreateUserPaneControl( MAC_WXHWND(wxPeer
->GetParent()->MacGetTopLevelWindowRef()), &bounds
, featurSet
, &m_controlRef
) );
2416 AdjustCreationAttributes( *wxWHITE
, true) ;
2418 MacSetObjectVisibility( wxPeer
->MacIsReallyShown() ) ;
2420 wxMacWindowClipper
clipper( m_peer
) ;
2421 SetTXNData( st
, kTXNStartOffset
, kTXNEndOffset
) ;
2422 TXNSetSelection( m_txn
, 0, 0);
2425 wxMacMLTEClassicControl::~wxMacMLTEClassicControl()
2427 TXNDeleteObject(m_txn
);
2431 void wxMacMLTEClassicControl::VisibilityChanged(bool shown
)
2433 MacSetObjectVisibility( shown
) ;
2434 wxMacControl::VisibilityChanged( shown
) ;
2437 void wxMacMLTEClassicControl::SuperChangedPosition()
2439 MacUpdatePosition() ;
2440 wxMacControl::SuperChangedPosition() ;
2443 #ifdef __WXMAC_OSX__
2445 ControlUserPaneDrawUPP gTPDrawProc
= NULL
;
2446 ControlUserPaneHitTestUPP gTPHitProc
= NULL
;
2447 ControlUserPaneTrackingUPP gTPTrackProc
= NULL
;
2448 ControlUserPaneIdleUPP gTPIdleProc
= NULL
;
2449 ControlUserPaneKeyDownUPP gTPKeyProc
= NULL
;
2450 ControlUserPaneActivateUPP gTPActivateProc
= NULL
;
2451 ControlUserPaneFocusUPP gTPFocusProc
= NULL
;
2453 static pascal void wxMacControlUserPaneDrawProc(ControlRef control
, SInt16 part
)
2455 wxTextCtrl
*textCtrl
= wxDynamicCast( wxFindControlFromMacControl(control
) , wxTextCtrl
) ;
2456 wxMacMLTEClassicControl
* win
= textCtrl
? (wxMacMLTEClassicControl
*)(textCtrl
->GetPeer()) : NULL
;
2458 win
->MacControlUserPaneDrawProc(part
) ;
2461 static pascal ControlPartCode
wxMacControlUserPaneHitTestProc(ControlRef control
, Point where
)
2463 wxTextCtrl
*textCtrl
= wxDynamicCast( wxFindControlFromMacControl(control
) , wxTextCtrl
) ;
2464 wxMacMLTEClassicControl
* win
= textCtrl
? (wxMacMLTEClassicControl
*)(textCtrl
->GetPeer()) : NULL
;
2466 return win
->MacControlUserPaneHitTestProc(where
.h
, where
.v
) ;
2468 return kControlNoPart
;
2471 static pascal ControlPartCode
wxMacControlUserPaneTrackingProc(ControlRef control
, Point startPt
, ControlActionUPP actionProc
)
2473 wxTextCtrl
*textCtrl
= wxDynamicCast( wxFindControlFromMacControl(control
) , wxTextCtrl
) ;
2474 wxMacMLTEClassicControl
* win
= textCtrl
? (wxMacMLTEClassicControl
*)(textCtrl
->GetPeer()) : NULL
;
2476 return win
->MacControlUserPaneTrackingProc( startPt
.h
, startPt
.v
, (void*) actionProc
) ;
2478 return kControlNoPart
;
2481 static pascal void wxMacControlUserPaneIdleProc(ControlRef control
)
2483 wxTextCtrl
*textCtrl
= wxDynamicCast( wxFindControlFromMacControl(control
) , wxTextCtrl
) ;
2484 wxMacMLTEClassicControl
* win
= textCtrl
? (wxMacMLTEClassicControl
*)(textCtrl
->GetPeer()) : NULL
;
2486 win
->MacControlUserPaneIdleProc() ;
2489 static pascal ControlPartCode
wxMacControlUserPaneKeyDownProc(ControlRef control
, SInt16 keyCode
, SInt16 charCode
, SInt16 modifiers
)
2491 wxTextCtrl
*textCtrl
= wxDynamicCast( wxFindControlFromMacControl(control
) , wxTextCtrl
) ;
2492 wxMacMLTEClassicControl
* win
= textCtrl
? (wxMacMLTEClassicControl
*)(textCtrl
->GetPeer()) : NULL
;
2494 return win
->MacControlUserPaneKeyDownProc(keyCode
,charCode
,modifiers
) ;
2496 return kControlNoPart
;
2499 static pascal void wxMacControlUserPaneActivateProc(ControlRef control
, Boolean activating
)
2501 wxTextCtrl
*textCtrl
= wxDynamicCast( wxFindControlFromMacControl(control
) , wxTextCtrl
) ;
2502 wxMacMLTEClassicControl
* win
= textCtrl
? (wxMacMLTEClassicControl
*)(textCtrl
->GetPeer()) : NULL
;
2504 win
->MacControlUserPaneActivateProc(activating
) ;
2507 static pascal ControlPartCode
wxMacControlUserPaneFocusProc(ControlRef control
, ControlFocusPart action
)
2509 wxTextCtrl
*textCtrl
= wxDynamicCast( wxFindControlFromMacControl(control
) , wxTextCtrl
) ;
2510 wxMacMLTEClassicControl
* win
= textCtrl
? (wxMacMLTEClassicControl
*)(textCtrl
->GetPeer()) : NULL
;
2512 return win
->MacControlUserPaneFocusProc(action
) ;
2514 return kControlNoPart
;
2518 static pascal void wxMacControlUserPaneBackgroundProc(ControlRef control, ControlBackgroundPtr info)
2520 wxTextCtrl *textCtrl = wxDynamicCast( wxFindControlFromMacControl(control) , wxTextCtrl ) ;
2521 wxMacMLTEClassicControl * win = textCtrl ? (wxMacMLTEClassicControl*)(textCtrl->GetPeer()) : NULL ;
2523 win->MacControlUserPaneBackgroundProc(info) ;
2528 // TXNRegisterScrollInfoProc
2530 OSStatus
wxMacMLTEClassicControl::DoCreate()
2534 OSStatus err
= noErr
;
2536 /* set up our globals */
2537 #ifdef __WXMAC_OSX__
2538 if (gTPDrawProc
== NULL
) gTPDrawProc
= NewControlUserPaneDrawUPP(wxMacControlUserPaneDrawProc
);
2539 if (gTPHitProc
== NULL
) gTPHitProc
= NewControlUserPaneHitTestUPP(wxMacControlUserPaneHitTestProc
);
2540 if (gTPTrackProc
== NULL
) gTPTrackProc
= NewControlUserPaneTrackingUPP(wxMacControlUserPaneTrackingProc
);
2541 if (gTPIdleProc
== NULL
) gTPIdleProc
= NewControlUserPaneIdleUPP(wxMacControlUserPaneIdleProc
);
2542 if (gTPKeyProc
== NULL
) gTPKeyProc
= NewControlUserPaneKeyDownUPP(wxMacControlUserPaneKeyDownProc
);
2543 if (gTPActivateProc
== NULL
) gTPActivateProc
= NewControlUserPaneActivateUPP(wxMacControlUserPaneActivateProc
);
2544 if (gTPFocusProc
== NULL
) gTPFocusProc
= NewControlUserPaneFocusUPP(wxMacControlUserPaneFocusProc
);
2546 if (gTXNScrollInfoProc
== NULL
) gTXNScrollInfoProc
= NewTXNScrollInfoUPP(TXNScrollInfoProc
) ;
2547 if (gTXNScrollActionProc
== NULL
) gTXNScrollActionProc
= NewControlActionUPP(TXNScrollActionProc
) ;
2550 /* set the initial settings for our private data */
2552 m_txnWindow
=GetControlOwner(m_controlRef
);
2553 m_txnPort
= (GrafPtr
) GetWindowPort(m_txnWindow
);
2555 #ifdef __WXMAC_OSX__
2556 /* set up the user pane procedures */
2557 SetControlData(m_controlRef
, kControlEntireControl
, kControlUserPaneDrawProcTag
, sizeof(gTPDrawProc
), &gTPDrawProc
);
2558 SetControlData(m_controlRef
, kControlEntireControl
, kControlUserPaneHitTestProcTag
, sizeof(gTPHitProc
), &gTPHitProc
);
2559 SetControlData(m_controlRef
, kControlEntireControl
, kControlUserPaneTrackingProcTag
, sizeof(gTPTrackProc
), &gTPTrackProc
);
2560 SetControlData(m_controlRef
, kControlEntireControl
, kControlUserPaneIdleProcTag
, sizeof(gTPIdleProc
), &gTPIdleProc
);
2561 SetControlData(m_controlRef
, kControlEntireControl
, kControlUserPaneKeyDownProcTag
, sizeof(gTPKeyProc
), &gTPKeyProc
);
2562 SetControlData(m_controlRef
, kControlEntireControl
, kControlUserPaneActivateProcTag
, sizeof(gTPActivateProc
), &gTPActivateProc
);
2563 SetControlData(m_controlRef
, kControlEntireControl
, kControlUserPaneFocusProcTag
, sizeof(gTPFocusProc
), &gTPFocusProc
);
2565 /* calculate the rectangles used by the control */
2566 UMAGetControlBoundsInWindowCoords(m_controlRef
, &bounds
);
2568 m_txnControlBounds
= bounds
;
2570 CGrafPtr origPort
= NULL
;
2571 GDHandle origDev
= NULL
;
2572 GetGWorld( &origPort
, &origDev
) ;
2575 /* create the new edit field */
2577 TXNFrameOptions frameOptions
= FrameOptionsFromWXStyle( m_windowStyle
) ;
2579 #ifdef __WXMAC_OSX__
2581 // the scrollbars are not correctly embedded but are inserted at the root
2582 // this gives us problems as we have erratic redraws even over the structure
2585 m_sbHorizontal
= 0 ;
2587 m_lastHorizontalValue
= 0 ;
2588 m_lastVerticalValue
= 0 ;
2590 Rect sb
= { 0 , 0 , 0 , 0 } ;
2591 if ( frameOptions
& kTXNWantVScrollBarMask
)
2593 CreateScrollBarControl( m_txnWindow
, &sb
, 0 , 0 , 100 , 1 , true , gTXNScrollActionProc
, &m_sbVertical
) ;
2594 SetControlReference( m_sbVertical
, (SInt32
) this ) ;
2595 SetControlAction( m_sbVertical
, gTXNScrollActionProc
);
2596 ShowControl( m_sbVertical
) ;
2597 EmbedControl( m_sbVertical
, m_controlRef
) ;
2598 frameOptions
&= ~kTXNWantVScrollBarMask
;
2600 if ( frameOptions
& kTXNWantHScrollBarMask
)
2602 CreateScrollBarControl( m_txnWindow
, &sb
, 0 , 0 , 100 , 1 , true , gTXNScrollActionProc
, &m_sbHorizontal
) ;
2603 SetControlReference( m_sbHorizontal
, (SInt32
) this ) ;
2604 SetControlAction( m_sbHorizontal
, gTXNScrollActionProc
);
2605 ShowControl( m_sbHorizontal
) ;
2606 EmbedControl( m_sbHorizontal
, m_controlRef
) ;
2607 frameOptions
&= ~(kTXNWantHScrollBarMask
| kTXNDrawGrowIconMask
);
2612 verify_noerr(TXNNewObject(NULL
, m_txnWindow
, &bounds
,
2614 kTXNTextEditStyleFrameType
,
2616 kTXNSystemDefaultEncoding
,
2617 &m_txn
, &m_txnFrameID
, NULL
) );
2619 TXNCarbonEventInfo cInfo
;
2621 cInfo
.useCarbonEvents
= false ;
2624 cInfo
.fDictionary
= NULL
;
2626 TXNControlTag iControlTags
[] =
2628 kTXNUseCarbonEvents
,
2630 TXNControlData iControlData
[] =
2635 int toptag
= WXSIZEOF( iControlTags
) ;
2637 verify_noerr( TXNSetTXNObjectControls( m_txn
, false , toptag
,
2638 iControlTags
, iControlData
)) ;
2641 #ifdef __WXMAC_OSX__
2642 TXNRegisterScrollInfoProc( m_txn
, gTXNScrollInfoProc
, (SInt32
) this);
2645 SetGWorld( origPort
, origDev
) ;
2649 // ----------------------------------------------------------------------------
2650 // MLTE control implementation (OSX part)
2651 // ----------------------------------------------------------------------------
2653 #if TARGET_API_MAC_OSX
2655 #if MAC_OS_X_VERSION_MAX_ALLOWED > MAC_OS_X_VERSION_10_2
2657 wxMacMLTEHIViewControl::wxMacMLTEHIViewControl( wxTextCtrl
*wxPeer
,
2658 const wxString
& str
,
2660 const wxSize
& size
, long style
) : wxMacMLTEControl( wxPeer
)
2662 m_font
= wxPeer
->GetFont() ;
2663 m_windowStyle
= style
;
2664 Rect bounds
= wxMacGetBoundsForControl( wxPeer
, pos
, size
) ;
2666 wxMacConvertNewlines10To13( &st
) ;
2668 HIRect hr
= { bounds
.left
, bounds
.top
, bounds
.right
- bounds
.left
, bounds
.bottom
- bounds
.top
} ;
2670 m_scrollView
= NULL
;
2671 TXNFrameOptions frameOptions
= FrameOptionsFromWXStyle( style
) ;
2672 if ( frameOptions
& (kTXNWantVScrollBarMask
|kTXNWantHScrollBarMask
) )
2674 HIScrollViewCreate(( frameOptions
& kTXNWantHScrollBarMask
? kHIScrollViewOptionsHorizScroll
: 0) |
2675 ( frameOptions
& kTXNWantVScrollBarMask
? kHIScrollViewOptionsVertScroll
: 0 ) , &m_scrollView
) ;
2677 HIViewSetFrame( m_scrollView
, &hr
);
2678 HIViewSetVisible( m_scrollView
, true );
2682 HITextViewCreate( NULL
, 0, frameOptions
, &m_textView
) ;
2683 m_txn
= HITextViewGetTXNObject( m_textView
) ;
2684 HIViewSetVisible( m_textView
, true ) ;
2687 HIViewAddSubview( m_scrollView
, m_textView
) ;
2688 m_controlRef
= m_scrollView
;
2689 wxPeer
->MacInstallEventHandler( (WXWidget
) m_textView
) ;
2693 HIViewSetFrame( m_textView
, &hr
);
2694 m_controlRef
= m_textView
;
2697 AdjustCreationAttributes( *wxWHITE
, true ) ;
2699 wxMacWindowClipper
c( m_peer
) ;
2700 SetTXNData( st
, kTXNStartOffset
, kTXNEndOffset
) ;
2702 TXNSetSelection( m_txn
, 0, 0);
2703 TXNShowSelection( m_txn
, kTXNShowStart
);
2707 OSStatus
wxMacMLTEHIViewControl::SetFocus( ControlFocusPart focusPart
)
2709 return SetKeyboardFocus( GetControlOwner( m_textView
) ,
2710 m_textView
, focusPart
) ;
2713 bool wxMacMLTEHIViewControl::HasFocus() const
2715 ControlRef control
;
2716 GetKeyboardFocus( GetUserFocusWindow() , &control
) ;
2717 return control
== m_textView
;
2720 #endif // MAC_OS_X_VERSION_MAX_ALLOWED > MAC_OS_X_VERSION_10_2
2725 #endif // wxUSE_TEXTCTRL