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
1540 GetThemeFont(kThemeSystemFont
, GetApplicationScript() , fontName
, &fontSize
, &fontStyle
) ;
1542 TXNTypeAttributes typeAttr
[] =
1544 { kTXNQDFontNameAttribute
, kTXNQDFontNameAttributeSize
, { (void*) fontName
} } ,
1545 { kTXNQDFontSizeAttribute
, kTXNFontSizeAttributeSize
, { (void*) (fontSize
<< 16) } } ,
1546 { kTXNQDFontStyleAttribute
, kTXNQDFontStyleAttributeSize
, { (void*) normal
} } ,
1549 verify_noerr( TXNSetTypeAttributes (m_txn
, sizeof( typeAttr
) / sizeof(TXNTypeAttributes
) , typeAttr
,
1553 if ( m_windowStyle
& wxTE_PASSWORD
)
1556 verify_noerr(TXNEchoMode( m_txn
, c
, 0 , true )) ;
1559 TXNBackground tback
;
1560 tback
.bgType
= kTXNBackgroundTypeRGB
;
1561 tback
.bg
.color
= MAC_WXCOLORREF( background
.GetPixel() );
1562 TXNSetBackground( m_txn
, &tback
);
1565 void wxMacMLTEControl::SetBackground( const wxBrush
&brush
)
1567 // currently only solid background are supported
1568 TXNBackground tback
;
1569 tback
.bgType
= kTXNBackgroundTypeRGB
;
1570 tback
.bg
.color
= MAC_WXCOLORREF( brush
.GetColour().GetPixel() );
1571 TXNSetBackground( m_txn
, &tback
);
1574 void wxMacMLTEControl::TXNSetAttribute( const wxTextAttr
& style
, long from
, long to
)
1576 TXNTypeAttributes typeAttr
[4] ;
1577 Str255 fontName
= "\pMonaco" ;
1578 SInt16 fontSize
= 12 ;
1579 Style fontStyle
= normal
;
1581 int attrCounter
= 0 ;
1582 if ( style
.HasFont() )
1584 const wxFont
&font
= style
.GetFont() ;
1585 wxMacStringToPascal( font
.GetFaceName() , fontName
) ;
1586 fontSize
= font
.GetPointSize() ;
1587 if ( font
.GetUnderlined() )
1588 fontStyle
|= underline
;
1589 if ( font
.GetWeight() == wxBOLD
)
1591 if ( font
.GetStyle() == wxITALIC
)
1592 fontStyle
|= italic
;
1594 typeAttr
[attrCounter
].tag
= kTXNQDFontNameAttribute
;
1595 typeAttr
[attrCounter
].size
= kTXNQDFontNameAttributeSize
;
1596 typeAttr
[attrCounter
].data
.dataPtr
= (void*) fontName
;
1597 typeAttr
[attrCounter
+1].tag
= kTXNQDFontSizeAttribute
;
1598 typeAttr
[attrCounter
+1].size
= kTXNFontSizeAttributeSize
;
1599 typeAttr
[attrCounter
+1].data
.dataValue
= (fontSize
<< 16) ;
1600 typeAttr
[attrCounter
+2].tag
= kTXNQDFontStyleAttribute
;
1601 typeAttr
[attrCounter
+2].size
= kTXNQDFontStyleAttributeSize
;
1602 typeAttr
[attrCounter
+2].data
.dataValue
= fontStyle
;
1605 if ( style
.HasTextColour() )
1607 typeAttr
[attrCounter
].tag
= kTXNQDFontColorAttribute
;
1608 typeAttr
[attrCounter
].size
= kTXNQDFontColorAttributeSize
;
1609 typeAttr
[attrCounter
].data
.dataPtr
= (void*) &color
;
1610 color
= MAC_WXCOLORREF(style
.GetTextColour().GetPixel()) ;
1613 if ( attrCounter
> 0 )
1615 verify_noerr( TXNSetTypeAttributes ( m_txn
, attrCounter
, typeAttr
, from
, to
) );
1619 void wxMacMLTEControl::SetFont( const wxFont
& font
, const wxColour
& foreground
, long windowStyle
)
1621 wxMacEditHelper
help(m_txn
) ;
1622 TXNSetAttribute( wxTextAttr(foreground
,wxNullColour
,font
) , kTXNStartOffset
,kTXNEndOffset
) ;
1624 void wxMacMLTEControl::SetStyle(long start
, long end
, const wxTextAttr
& style
)
1626 wxMacEditHelper
help(m_txn
) ;
1627 TXNSetAttribute( style
, start
,end
) ;
1630 void wxMacMLTEControl::Copy()
1632 ClearCurrentScrap();
1634 TXNConvertToPublicScrap();
1637 void wxMacMLTEControl::Cut()
1639 ClearCurrentScrap();
1641 TXNConvertToPublicScrap();
1644 void wxMacMLTEControl::Paste()
1646 TXNConvertFromPublicScrap();
1650 bool wxMacMLTEControl::CanPaste() const
1652 return TXNIsScrapPastable() ;
1655 void wxMacMLTEControl::SetEditable(bool editable
)
1657 TXNControlTag tag
[] = { kTXNIOPrivilegesTag
} ;
1658 TXNControlData data
[] = { { editable
? kTXNReadWrite
: kTXNReadOnly
} } ;
1659 TXNSetTXNObjectControls( m_txn
, false , WXSIZEOF(tag
) , tag
, data
) ;
1662 wxTextPos
wxMacMLTEControl::GetLastPosition() const
1664 wxTextPos actualsize
= 0 ;
1667 OSErr err
= TXNGetDataEncoded( m_txn
, kTXNStartOffset
, kTXNEndOffset
, &theText
, kTXNTextData
);
1675 actualsize
= GetHandleSize( theText
) ;
1676 DisposeHandle( theText
) ;
1682 void wxMacMLTEControl::Replace( long from
, long to
, const wxString str
)
1684 wxString value
= str
;
1685 wxMacConvertNewlines10To13( &value
) ;
1687 wxMacEditHelper
help( m_txn
) ;
1688 wxMacWindowClipper
c( m_peer
) ;
1690 TXNSetSelection(m_txn
, from
, to
) ;
1692 SetTXNData( value
, kTXNUseCurrentSelection
, kTXNUseCurrentSelection
) ;
1695 void wxMacMLTEControl::Remove( long from
, long to
)
1697 wxMacWindowClipper
c( m_peer
) ;
1698 wxMacEditHelper
help( m_txn
) ;
1699 TXNSetSelection(m_txn
, from
, to
) ;
1703 void wxMacMLTEControl::GetSelection( long* from
, long* to
) const
1705 TXNGetSelection( m_txn
, (TXNOffset
*) from
, (TXNOffset
*) to
) ;
1708 void wxMacMLTEControl::SetSelection( long from
, long to
)
1710 wxMacWindowClipper
c( m_peer
) ;
1711 /* change the selection */
1712 if ((from
== -1) && (to
== -1))
1713 TXNSelectAll(m_txn
);
1715 TXNSetSelection( m_txn
, from
, to
);
1716 TXNShowSelection( m_txn
, kTXNShowStart
);
1719 void wxMacMLTEControl::WriteText(const wxString
& str
)
1722 wxMacConvertNewlines10To13( &st
) ;
1724 long start
, end
, dummy
;
1725 GetSelection( &start
, &dummy
) ;
1726 wxMacWindowClipper
c( m_peer
) ;
1728 wxMacEditHelper
helper( m_txn
) ;
1729 SetTXNData( st
, kTXNUseCurrentSelection
, kTXNUseCurrentSelection
) ;
1731 GetSelection( &dummy
, &end
) ;
1732 // TODO SetStyle( start , end , GetDefaultStyle() ) ;
1735 void wxMacMLTEControl::Clear()
1737 wxMacWindowClipper
c( m_peer
) ;
1738 wxMacEditHelper
st(m_txn
) ;
1739 TXNSetSelection( m_txn
, kTXNStartOffset
, kTXNEndOffset
) ;
1743 bool wxMacMLTEControl::CanUndo() const
1745 return TXNCanUndo( m_txn
, NULL
) ;
1748 void wxMacMLTEControl::Undo()
1753 bool wxMacMLTEControl::CanRedo() const
1755 return TXNCanRedo( m_txn
, NULL
) ;
1758 void wxMacMLTEControl::Redo()
1763 int wxMacMLTEControl::GetNumberOfLines() const
1765 ItemCount lines
= 0 ;
1766 TXNGetLineCount(m_txn
, &lines
) ;
1770 long wxMacMLTEControl::XYToPosition(long x
, long y
) const
1774 wxTextPos lastpos
= GetLastPosition() ;
1776 // TODO find a better implementation : while we can get the
1777 // line metrics of a certain line, we don't get its starting
1778 // position, so it would probably be rather a binary search
1779 // for the start position
1782 int lastHeight
= 0 ;
1785 for ( n
= 0 ; n
<= (ItemCount
) lastpos
; ++n
)
1787 if ( y
== ypos
&& x
== xpos
)
1790 TXNOffsetToPoint( m_txn
, n
, &curpt
);
1792 if ( curpt
.v
> lastHeight
)
1797 lastHeight
= curpt
.v
;
1805 bool wxMacMLTEControl::PositionToXY(long pos
, long *x
, long *y
) const
1809 wxTextPos lastpos
= GetLastPosition() ;
1814 if ( pos
<= lastpos
)
1816 // TODO find a better implementation : while we can get the
1817 // line metrics of a certain line, we don't get its starting
1818 // position, so it would probably be rather a binary search
1819 // for the start position
1822 int lastHeight
= 0 ;
1825 for ( n
= 0 ; n
<= (ItemCount
) pos
; ++n
)
1827 TXNOffsetToPoint(m_txn
, n
, &curpt
);
1829 if ( curpt
.v
> lastHeight
)
1834 lastHeight
= curpt
.v
;
1839 if ( y
) *y
= ypos
;
1840 if ( x
) *x
= xpos
;
1846 void wxMacMLTEControl::ShowPosition( long pos
)
1848 #if TARGET_RT_MAC_MACHO && defined(AVAILABLE_MAC_OS_X_VERSION_10_2_AND_LATER)
1852 TXNOffset selstart
, selend
;
1853 TXNGetSelection( m_txn
, &selstart
, &selend
) ;
1854 TXNOffsetToPoint( m_txn
, selstart
, ¤t
);
1855 TXNOffsetToPoint( m_txn
, pos
, &desired
);
1856 //TODO use HIPoints for 10.3 and above
1857 if ( (UInt32
) TXNScroll
!= (UInt32
) kUnresolvedCFragSymbolAddress
)
1859 OSErr theErr
= noErr
;
1860 SInt32 dv
= desired
.v
- current
.v
;
1861 SInt32 dh
= desired
.h
- current
.h
;
1862 TXNShowSelection( m_txn
, true ) ;
1863 theErr
= TXNScroll( m_txn
, kTXNScrollUnitsInPixels
, kTXNScrollUnitsInPixels
, &dv
, &dh
);
1864 wxASSERT_MSG( theErr
== noErr
, _T("TXNScroll returned an error!") );
1870 void wxMacMLTEControl::SetTXNData( const wxString
& st
, TXNOffset start
, TXNOffset end
)
1873 #if SIZEOF_WCHAR_T == 2
1874 size_t len
= st
.Len() ;
1875 TXNSetData( m_txn
, kTXNUnicodeTextData
, (void*)st
.wc_str(), len
* 2,
1878 wxMBConvUTF16BE converter
;
1879 ByteCount byteBufferLen
= converter
.WC2MB( NULL
, st
.wc_str() , 0 ) ;
1880 UniChar
*unibuf
= (UniChar
*) malloc(byteBufferLen
) ;
1881 converter
.WC2MB( (char*) unibuf
, st
.wc_str() , byteBufferLen
) ;
1882 TXNSetData( m_txn
, kTXNUnicodeTextData
, (void*)unibuf
, byteBufferLen
,
1887 wxCharBuffer text
= st
.mb_str(wxConvLocal
) ;
1888 TXNSetData( m_txn
, kTXNTextData
, (void*)text
.data(), strlen( text
) ,
1894 wxString
wxMacMLTEControl::GetLineText(long lineNo
) const
1898 if ( lineNo
< GetNumberOfLines() )
1906 // get the first possible position in the control
1908 TXNOffsetToPoint(m_txn
, 0, &firstPoint
);
1910 // Iterate through the lines until we reach the one we want,
1911 // adding to our current y pixel point position
1912 while (ypos
< lineNo
)
1914 TXNGetLineMetrics(m_txn
, ypos
++, &lineWidth
, &lineHeight
);
1915 currentHeight
+= lineHeight
;
1918 Point thePoint
= { firstPoint
.v
+ (currentHeight
>> 16), firstPoint
.h
+ (0) };
1919 TXNOffset theOffset
;
1920 TXNPointToOffset(m_txn
, thePoint
, &theOffset
);
1922 wxString content
= GetStringValue() ;
1923 Point currentPoint
= thePoint
;
1924 while(thePoint
.v
== currentPoint
.v
&& theOffset
< content
.length())
1926 line
+= content
[theOffset
];
1927 TXNOffsetToPoint(m_txn
, ++theOffset
, ¤tPoint
);
1933 int wxMacMLTEControl::GetLineLength(long lineNo
) const
1937 if ( lineNo
< GetNumberOfLines() )
1945 // get the first possible position in the control
1947 TXNOffsetToPoint(m_txn
, 0, &firstPoint
);
1949 // Iterate through the lines until we reach the one we want,
1950 // adding to our current y pixel point position
1951 while (ypos
< lineNo
)
1953 TXNGetLineMetrics(m_txn
, ypos
++, &lineWidth
, &lineHeight
);
1954 currentHeight
+= lineHeight
;
1957 Point thePoint
= { firstPoint
.v
+ (currentHeight
>> 16), firstPoint
.h
+ (0) };
1958 TXNOffset theOffset
;
1959 TXNPointToOffset(m_txn
, thePoint
, &theOffset
);
1961 wxString content
= GetStringValue() ;
1962 Point currentPoint
= thePoint
;
1963 while(thePoint
.v
== currentPoint
.v
&& theOffset
< content
.length())
1966 TXNOffsetToPoint(m_txn
, ++theOffset
, ¤tPoint
);
1973 // ----------------------------------------------------------------------------
1974 // MLTE control implementation (classic part)
1975 // ----------------------------------------------------------------------------
1977 // OS X Notes : We still don't have a full replacement for MLTE, so this implementation
1978 // has to live on. We have different problems coming from outdated implementations on the
1979 // various OS X versions. Most deal with the scrollbars: they are not correctly embedded
1980 // while this can be solved on 10.3 by reassigning them the correct place, on 10.2 there is
1981 // no way out, therefore we are using our own implementation and our own scrollbars ....
1983 #ifdef __WXMAC_OSX__
1985 TXNScrollInfoUPP gTXNScrollInfoProc
= NULL
;
1986 ControlActionUPP gTXNScrollActionProc
= NULL
;
1988 pascal void wxMacMLTEClassicControl::TXNScrollInfoProc (SInt32 iValue
, SInt32 iMaximumValue
, TXNScrollBarOrientation
1989 iScrollBarOrientation
, SInt32 iRefCon
)
1991 wxMacMLTEClassicControl
* mlte
= (wxMacMLTEClassicControl
*) iRefCon
;
1992 SInt32 value
= wxMax( iValue
, 0 ) ;
1993 SInt32 maximum
= wxMax( iMaximumValue
, 0 ) ;
1995 if ( iScrollBarOrientation
== kTXNHorizontal
)
1997 if ( mlte
->m_sbHorizontal
)
1999 SetControl32BitValue( mlte
->m_sbHorizontal
, value
) ;
2000 SetControl32BitMaximum( mlte
->m_sbHorizontal
, maximum
) ;
2001 mlte
->m_lastHorizontalValue
= value
;
2004 else if ( iScrollBarOrientation
== kTXNVertical
)
2006 if ( mlte
->m_sbVertical
)
2008 SetControl32BitValue( mlte
->m_sbVertical
, value
) ;
2009 SetControl32BitMaximum( mlte
->m_sbVertical
, maximum
) ;
2010 mlte
->m_lastVerticalValue
= value
;
2015 pascal void wxMacMLTEClassicControl::TXNScrollActionProc( ControlRef controlRef
, ControlPartCode partCode
)
2018 wxMacMLTEClassicControl
* mlte
= (wxMacMLTEClassicControl
*) GetControlReference( controlRef
) ;
2022 if ( controlRef
!= mlte
->m_sbVertical
&& controlRef
!= mlte
->m_sbHorizontal
)
2025 bool isHorizontal
= ( controlRef
== mlte
->m_sbHorizontal
) ;
2027 SInt32 minimum
= 0 ;
2028 SInt32 maximum
= GetControl32BitMaximum( controlRef
) ;
2029 SInt32 value
= GetControl32BitValue( controlRef
) ;
2033 case kControlDownButtonPart
:
2036 case kControlUpButtonPart
:
2039 case kControlPageDownPart
:
2040 delta
= GetControlViewSize( controlRef
) ;
2042 case kControlPageUpPart
:
2043 delta
= -GetControlViewSize( controlRef
) ;
2045 case kControlIndicatorPart
:
2047 ( isHorizontal
? mlte
->m_lastHorizontalValue
: mlte
->m_lastVerticalValue
) ;
2054 SInt32 newValue
= value
;
2056 if ( partCode
!= kControlIndicatorPart
)
2058 if( value
+ delta
< minimum
)
2059 delta
= minimum
- value
;
2060 if ( value
+ delta
> maximum
)
2061 delta
= maximum
- value
;
2063 SetControl32BitValue( controlRef
, value
+ delta
) ;
2064 newValue
= value
+ delta
;
2067 SInt32 verticalDelta
= isHorizontal
? 0 : delta
;
2068 SInt32 horizontalDelta
= isHorizontal
? delta
: 0 ;
2070 err
= TXNScroll( mlte
->m_txn
, kTXNScrollUnitsInPixels
, kTXNScrollUnitsInPixels
,
2071 &verticalDelta
, &horizontalDelta
);
2074 mlte
->m_lastHorizontalValue
= newValue
;
2076 mlte
->m_lastVerticalValue
= newValue
;
2081 // make correct activations
2082 void wxMacMLTEClassicControl::MacActivatePaneText(Boolean setActive
)
2084 wxTextCtrl
* textctrl
= (wxTextCtrl
*) GetControlReference(m_controlRef
);
2086 wxMacWindowClipper
clipper( textctrl
) ;
2087 TXNActivate(m_txn
, m_txnFrameID
, setActive
);
2089 ControlRef controlFocus
= 0 ;
2090 GetKeyboardFocus( m_txnWindow
, &controlFocus
) ;
2091 if ( controlFocus
== m_controlRef
)
2092 TXNFocus( m_txn
, setActive
);
2095 void wxMacMLTEClassicControl::MacFocusPaneText(Boolean setFocus
)
2097 TXNFocus( m_txn
, setFocus
);
2100 // guards against inappropriate redraw (hidden objects drawing onto window)
2102 void wxMacMLTEClassicControl::MacSetObjectVisibility(Boolean vis
)
2104 ControlRef controlFocus
= 0 ;
2105 GetKeyboardFocus( m_txnWindow
, &controlFocus
) ;
2107 if ( controlFocus
== m_controlRef
&& vis
== false )
2109 SetKeyboardFocus( m_txnWindow
, m_controlRef
, kControlFocusNoPart
) ;
2111 // we right now are always clipping as partial visibility (overlapped) visibility
2112 // is also a problem, if we run into further problems we might set the FrameBounds to an empty
2116 // make sure that the TXNObject is at the right position
2118 void wxMacMLTEClassicControl::MacUpdatePosition()
2120 wxTextCtrl
* textctrl
= (wxTextCtrl
*) GetControlReference(m_controlRef
);
2121 if ( textctrl
== NULL
)
2125 UMAGetControlBoundsInWindowCoords(m_controlRef
, &bounds
);
2127 if ( !EqualRect( &bounds
, &m_txnControlBounds
) )
2130 Rect oldBounds
= m_txnControlBounds
;
2131 m_txnControlBounds
= bounds
;
2132 wxMacWindowClipper
cl(textctrl
) ;
2134 #ifdef __WXMAC_OSX__
2135 bool isCompositing
= textctrl
->MacGetTopLevelWindow()->MacUsesCompositing() ;
2136 if ( m_sbHorizontal
|| m_sbVertical
)
2138 int w
= bounds
.right
- bounds
.left
;
2139 int h
= bounds
.bottom
- bounds
.top
;
2141 if ( m_sbHorizontal
)
2145 sbBounds
.left
= -1 ;
2146 sbBounds
.top
= h
- 14 ;
2147 sbBounds
.right
= w
+ 1 ;
2148 sbBounds
.bottom
= h
+ 1 ;
2150 if ( !isCompositing
)
2151 OffsetRect( &sbBounds
, m_txnControlBounds
.left
, m_txnControlBounds
.top
) ;
2153 SetControlBounds( m_sbHorizontal
, &sbBounds
) ;
2154 SetControlViewSize( m_sbHorizontal
, w
) ;
2160 sbBounds
.left
= w
- 14 ;
2162 sbBounds
.right
= w
+ 1 ;
2163 sbBounds
.bottom
= m_sbHorizontal
? h
- 14 : h
+ 1 ;
2165 if ( !isCompositing
)
2166 OffsetRect( &sbBounds
, m_txnControlBounds
.left
, m_txnControlBounds
.top
) ;
2168 SetControlBounds( m_sbVertical
, &sbBounds
) ;
2169 SetControlViewSize( m_sbVertical
, h
) ;
2172 TXNSetFrameBounds( m_txn
, m_txnControlBounds
.top
, m_txnControlBounds
.left
,
2173 m_txnControlBounds
.bottom
- ( m_sbHorizontal
? 14 : 0 ) , m_txnControlBounds
.right
- ( m_sbVertical
? 14 : 0 ), m_txnFrameID
);
2176 TXNSetFrameBounds( m_txn
, m_txnControlBounds
.top
, m_txnControlBounds
.left
,
2177 wxMax( m_txnControlBounds
.bottom
, m_txnControlBounds
.top
) ,
2178 wxMax( m_txnControlBounds
.right
, m_txnControlBounds
.left
) , m_txnFrameID
);
2180 // the SetFrameBounds method unter classic sometimes does not correctly scroll a selection into sight after a
2181 // movement, therefore we have to force it
2183 TXNLongRect textRect
;
2184 TXNGetRectBounds( m_txn
, NULL
, NULL
, &textRect
) ;
2185 if ( textRect
.left
< m_txnControlBounds
.left
)
2187 TXNShowSelection( m_txn
, false ) ;
2193 void wxMacMLTEClassicControl::SetRect( Rect
*r
)
2195 wxMacControl::SetRect( r
) ;
2196 MacUpdatePosition() ;
2199 void wxMacMLTEClassicControl::MacControlUserPaneDrawProc(wxInt16 thePart
)
2201 wxTextCtrl
* textctrl
= (wxTextCtrl
*) GetControlReference(m_controlRef
);
2202 if ( textctrl
== NULL
)
2205 if ( textctrl
->MacIsReallyShown() )
2207 wxMacWindowClipper
clipper( textctrl
) ;
2208 TXNDraw( m_txn
, NULL
) ;
2212 wxInt16
wxMacMLTEClassicControl::MacControlUserPaneHitTestProc(wxInt16 x
, wxInt16 y
)
2214 Point where
= { y
, x
} ;
2215 ControlPartCode result
;
2218 wxTextCtrl
* textctrl
= (wxTextCtrl
*) GetControlReference(m_controlRef
);
2219 if ( textctrl
== NULL
)
2222 if (textctrl
->MacIsReallyShown() )
2224 if (PtInRect(where
, &m_txnControlBounds
))
2225 result
= kControlEditTextPart
;
2228 // sometimes we get the coords also in control local coordinates, therefore test again
2229 if ( textctrl
->MacGetTopLevelWindow()->MacUsesCompositing() )
2232 textctrl
->MacClientToRootWindow( &x
, &y
) ;
2236 if (PtInRect(where
, &m_txnControlBounds
))
2237 result
= kControlEditTextPart
;
2245 wxInt16
wxMacMLTEClassicControl::MacControlUserPaneTrackingProc( wxInt16 x
, wxInt16 y
, void* actionProc
)
2247 wxTextCtrl
* textctrl
= (wxTextCtrl
*) GetControlReference(m_controlRef
);
2248 if ( textctrl
== NULL
)
2251 ControlPartCode partCodeResult
= 0;
2253 if (textctrl
->MacIsReallyShown() )
2255 Point startPt
= { y
,x
} ;
2256 // for compositing, we must convert these into toplevel window coordinates, because hittesting expects them
2257 if ( textctrl
->MacGetTopLevelWindow()->MacUsesCompositing() )
2260 textctrl
->MacClientToRootWindow( &x
, &y
) ;
2265 switch (MacControlUserPaneHitTestProc( startPt
.h
, startPt
.v
))
2267 case kControlEditTextPart
:
2269 wxMacWindowClipper
clipper( textctrl
) ;
2272 ConvertEventRefToEventRecord( (EventRef
) wxTheApp
->MacGetCurrentEvent() , &rec
) ;
2273 TXNClick( m_txn
, &rec
);
2279 return partCodeResult
;
2282 void wxMacMLTEClassicControl::MacControlUserPaneIdleProc()
2284 wxTextCtrl
* textctrl
= (wxTextCtrl
*) GetControlReference(m_controlRef
);
2285 if ( textctrl
== NULL
)
2288 if (textctrl
->MacIsReallyShown())
2290 if (IsControlActive(m_controlRef
))
2294 wxMacWindowClipper
clipper( textctrl
) ;
2299 if (PtInRect(mousep
, &m_txnControlBounds
))
2302 RectRgn((theRgn
= NewRgn()), &m_txnControlBounds
);
2303 TXNAdjustCursor(m_txn
, theRgn
);
2310 wxInt16
wxMacMLTEClassicControl::MacControlUserPaneKeyDownProc (wxInt16 keyCode
, wxInt16 charCode
, wxInt16 modifiers
)
2312 wxTextCtrl
* textctrl
= (wxTextCtrl
*) GetControlReference(m_controlRef
);
2313 if ( textctrl
== NULL
)
2316 wxMacWindowClipper
clipper( textctrl
) ;
2319 memset( &ev
, 0 , sizeof( ev
) ) ;
2321 ev
.modifiers
= modifiers
;
2322 ev
.message
= (( keyCode
<< 8 ) & keyCodeMask
) + ( charCode
& charCodeMask
) ;
2323 TXNKeyDown( m_txn
, &ev
);
2325 return kControlEntireControl
;
2328 void wxMacMLTEClassicControl::MacControlUserPaneActivateProc( bool activating
)
2330 MacActivatePaneText( activating
);
2333 wxInt16
wxMacMLTEClassicControl::MacControlUserPaneFocusProc(wxInt16 action
)
2335 ControlPartCode focusResult
;
2337 focusResult
= kControlFocusNoPart
;
2338 wxTextCtrl
* textctrl
= (wxTextCtrl
*) GetControlReference(m_controlRef
);
2339 if ( textctrl
== NULL
)
2342 wxMacWindowClipper
clipper( textctrl
) ;
2344 ControlRef controlFocus
= 0 ;
2345 GetKeyboardFocus( m_txnWindow
, &controlFocus
) ;
2346 bool wasFocused
= ( controlFocus
== m_controlRef
) ;
2350 case kControlFocusPrevPart
:
2351 case kControlFocusNextPart
:
2352 MacFocusPaneText( ( !wasFocused
));
2353 focusResult
= (!wasFocused
) ? (ControlPartCode
) kControlEditTextPart
: (ControlPartCode
) kControlFocusNoPart
;
2356 case kControlFocusNoPart
:
2358 MacFocusPaneText( false);
2359 focusResult
= kControlFocusNoPart
;
2366 void wxMacMLTEClassicControl::MacControlUserPaneBackgroundProc( void *info
)
2370 wxMacMLTEClassicControl::wxMacMLTEClassicControl( wxTextCtrl
*wxPeer
,
2371 const wxString
& str
,
2373 const wxSize
& size
, long style
) : wxMacMLTEControl( wxPeer
)
2375 m_font
= wxPeer
->GetFont() ;
2376 m_windowStyle
= style
;
2377 Rect bounds
= wxMacGetBoundsForControl( wxPeer
, pos
, size
) ;
2379 wxMacConvertNewlines10To13( &st
) ;
2383 featurSet
= kControlSupportsEmbedding
| kControlSupportsFocus
| kControlWantsIdle
2384 | kControlWantsActivate
| kControlHandlesTracking
// | kControlHasSpecialBackground
2385 | kControlGetsFocusOnClick
| kControlSupportsLiveFeedback
;
2387 verify_noerr( ::CreateUserPaneControl( MAC_WXHWND(wxPeer
->GetParent()->MacGetTopLevelWindowRef()), &bounds
, featurSet
, &m_controlRef
) );
2391 MacSetObjectVisibility( wxPeer
->MacIsReallyShown() ) ;
2393 AdjustCreationAttributes( *wxWHITE
, true) ;
2395 wxMacWindowClipper
clipper( m_peer
) ;
2396 SetTXNData( st
, kTXNStartOffset
, kTXNEndOffset
) ;
2397 TXNSetSelection( m_txn
, 0, 0);
2400 wxMacMLTEClassicControl::~wxMacMLTEClassicControl()
2402 TXNDeleteObject(m_txn
);
2406 void wxMacMLTEClassicControl::VisibilityChanged(bool shown
)
2408 MacSetObjectVisibility( shown
) ;
2409 wxMacControl::VisibilityChanged( shown
) ;
2412 void wxMacMLTEClassicControl::SuperChangedPosition()
2414 MacUpdatePosition() ;
2415 wxMacControl::SuperChangedPosition() ;
2418 #ifdef __WXMAC_OSX__
2420 ControlUserPaneDrawUPP gTPDrawProc
= NULL
;
2421 ControlUserPaneHitTestUPP gTPHitProc
= NULL
;
2422 ControlUserPaneTrackingUPP gTPTrackProc
= NULL
;
2423 ControlUserPaneIdleUPP gTPIdleProc
= NULL
;
2424 ControlUserPaneKeyDownUPP gTPKeyProc
= NULL
;
2425 ControlUserPaneActivateUPP gTPActivateProc
= NULL
;
2426 ControlUserPaneFocusUPP gTPFocusProc
= NULL
;
2428 static pascal void wxMacControlUserPaneDrawProc(ControlRef control
, SInt16 part
)
2430 wxTextCtrl
*textCtrl
= wxDynamicCast( wxFindControlFromMacControl(control
) , wxTextCtrl
) ;
2431 wxMacMLTEClassicControl
* win
= textCtrl
? (wxMacMLTEClassicControl
*)(textCtrl
->GetPeer()) : NULL
;
2433 win
->MacControlUserPaneDrawProc(part
) ;
2436 static pascal ControlPartCode
wxMacControlUserPaneHitTestProc(ControlRef control
, Point where
)
2438 wxTextCtrl
*textCtrl
= wxDynamicCast( wxFindControlFromMacControl(control
) , wxTextCtrl
) ;
2439 wxMacMLTEClassicControl
* win
= textCtrl
? (wxMacMLTEClassicControl
*)(textCtrl
->GetPeer()) : NULL
;
2441 return win
->MacControlUserPaneHitTestProc(where
.h
, where
.v
) ;
2443 return kControlNoPart
;
2446 static pascal ControlPartCode
wxMacControlUserPaneTrackingProc(ControlRef control
, Point startPt
, ControlActionUPP actionProc
)
2448 wxTextCtrl
*textCtrl
= wxDynamicCast( wxFindControlFromMacControl(control
) , wxTextCtrl
) ;
2449 wxMacMLTEClassicControl
* win
= textCtrl
? (wxMacMLTEClassicControl
*)(textCtrl
->GetPeer()) : NULL
;
2451 return win
->MacControlUserPaneTrackingProc( startPt
.h
, startPt
.v
, (void*) actionProc
) ;
2453 return kControlNoPart
;
2456 static pascal void wxMacControlUserPaneIdleProc(ControlRef control
)
2458 wxTextCtrl
*textCtrl
= wxDynamicCast( wxFindControlFromMacControl(control
) , wxTextCtrl
) ;
2459 wxMacMLTEClassicControl
* win
= textCtrl
? (wxMacMLTEClassicControl
*)(textCtrl
->GetPeer()) : NULL
;
2461 win
->MacControlUserPaneIdleProc() ;
2464 static pascal ControlPartCode
wxMacControlUserPaneKeyDownProc(ControlRef control
, SInt16 keyCode
, SInt16 charCode
, SInt16 modifiers
)
2466 wxTextCtrl
*textCtrl
= wxDynamicCast( wxFindControlFromMacControl(control
) , wxTextCtrl
) ;
2467 wxMacMLTEClassicControl
* win
= textCtrl
? (wxMacMLTEClassicControl
*)(textCtrl
->GetPeer()) : NULL
;
2469 return win
->MacControlUserPaneKeyDownProc(keyCode
,charCode
,modifiers
) ;
2471 return kControlNoPart
;
2474 static pascal void wxMacControlUserPaneActivateProc(ControlRef control
, Boolean activating
)
2476 wxTextCtrl
*textCtrl
= wxDynamicCast( wxFindControlFromMacControl(control
) , wxTextCtrl
) ;
2477 wxMacMLTEClassicControl
* win
= textCtrl
? (wxMacMLTEClassicControl
*)(textCtrl
->GetPeer()) : NULL
;
2479 win
->MacControlUserPaneActivateProc(activating
) ;
2482 static pascal ControlPartCode
wxMacControlUserPaneFocusProc(ControlRef control
, ControlFocusPart action
)
2484 wxTextCtrl
*textCtrl
= wxDynamicCast( wxFindControlFromMacControl(control
) , wxTextCtrl
) ;
2485 wxMacMLTEClassicControl
* win
= textCtrl
? (wxMacMLTEClassicControl
*)(textCtrl
->GetPeer()) : NULL
;
2487 return win
->MacControlUserPaneFocusProc(action
) ;
2489 return kControlNoPart
;
2493 static pascal void wxMacControlUserPaneBackgroundProc(ControlRef control, ControlBackgroundPtr info)
2495 wxTextCtrl *textCtrl = wxDynamicCast( wxFindControlFromMacControl(control) , wxTextCtrl ) ;
2496 wxMacMLTEClassicControl * win = textCtrl ? (wxMacMLTEClassicControl*)(textCtrl->GetPeer()) : NULL ;
2498 win->MacControlUserPaneBackgroundProc(info) ;
2503 // TXNRegisterScrollInfoProc
2505 OSStatus
wxMacMLTEClassicControl::DoCreate()
2509 OSStatus err
= noErr
;
2511 /* set up our globals */
2512 #ifdef __WXMAC_OSX__
2513 if (gTPDrawProc
== NULL
) gTPDrawProc
= NewControlUserPaneDrawUPP(wxMacControlUserPaneDrawProc
);
2514 if (gTPHitProc
== NULL
) gTPHitProc
= NewControlUserPaneHitTestUPP(wxMacControlUserPaneHitTestProc
);
2515 if (gTPTrackProc
== NULL
) gTPTrackProc
= NewControlUserPaneTrackingUPP(wxMacControlUserPaneTrackingProc
);
2516 if (gTPIdleProc
== NULL
) gTPIdleProc
= NewControlUserPaneIdleUPP(wxMacControlUserPaneIdleProc
);
2517 if (gTPKeyProc
== NULL
) gTPKeyProc
= NewControlUserPaneKeyDownUPP(wxMacControlUserPaneKeyDownProc
);
2518 if (gTPActivateProc
== NULL
) gTPActivateProc
= NewControlUserPaneActivateUPP(wxMacControlUserPaneActivateProc
);
2519 if (gTPFocusProc
== NULL
) gTPFocusProc
= NewControlUserPaneFocusUPP(wxMacControlUserPaneFocusProc
);
2521 if (gTXNScrollInfoProc
== NULL
) gTXNScrollInfoProc
= NewTXNScrollInfoUPP(TXNScrollInfoProc
) ;
2522 if (gTXNScrollActionProc
== NULL
) gTXNScrollActionProc
= NewControlActionUPP(TXNScrollActionProc
) ;
2525 /* set the initial settings for our private data */
2527 m_txnWindow
=GetControlOwner(m_controlRef
);
2528 m_txnPort
= (GrafPtr
) GetWindowPort(m_txnWindow
);
2530 #ifdef __WXMAC_OSX__
2531 /* set up the user pane procedures */
2532 SetControlData(m_controlRef
, kControlEntireControl
, kControlUserPaneDrawProcTag
, sizeof(gTPDrawProc
), &gTPDrawProc
);
2533 SetControlData(m_controlRef
, kControlEntireControl
, kControlUserPaneHitTestProcTag
, sizeof(gTPHitProc
), &gTPHitProc
);
2534 SetControlData(m_controlRef
, kControlEntireControl
, kControlUserPaneTrackingProcTag
, sizeof(gTPTrackProc
), &gTPTrackProc
);
2535 SetControlData(m_controlRef
, kControlEntireControl
, kControlUserPaneIdleProcTag
, sizeof(gTPIdleProc
), &gTPIdleProc
);
2536 SetControlData(m_controlRef
, kControlEntireControl
, kControlUserPaneKeyDownProcTag
, sizeof(gTPKeyProc
), &gTPKeyProc
);
2537 SetControlData(m_controlRef
, kControlEntireControl
, kControlUserPaneActivateProcTag
, sizeof(gTPActivateProc
), &gTPActivateProc
);
2538 SetControlData(m_controlRef
, kControlEntireControl
, kControlUserPaneFocusProcTag
, sizeof(gTPFocusProc
), &gTPFocusProc
);
2540 /* calculate the rectangles used by the control */
2541 UMAGetControlBoundsInWindowCoords(m_controlRef
, &bounds
);
2543 m_txnControlBounds
= bounds
;
2545 CGrafPtr origPort
= NULL
;
2546 GDHandle origDev
= NULL
;
2547 GetGWorld( &origPort
, &origDev
) ;
2550 /* create the new edit field */
2552 TXNFrameOptions frameOptions
= FrameOptionsFromWXStyle( m_windowStyle
) ;
2554 #ifdef __WXMAC_OSX__
2556 // the scrollbars are not correctly embedded but are inserted at the root
2557 // this gives us problems as we have erratic redraws even over the structure
2560 m_sbHorizontal
= 0 ;
2562 m_lastHorizontalValue
= 0 ;
2563 m_lastVerticalValue
= 0 ;
2565 Rect sb
= { 0 , 0 , 0 , 0 } ;
2566 if ( frameOptions
& kTXNWantVScrollBarMask
)
2568 CreateScrollBarControl( m_txnWindow
, &sb
, 0 , 0 , 100 , 1 , true , gTXNScrollActionProc
, &m_sbVertical
) ;
2569 SetControlReference( m_sbVertical
, (SInt32
) this ) ;
2570 SetControlAction( m_sbVertical
, gTXNScrollActionProc
);
2571 ShowControl( m_sbVertical
) ;
2572 EmbedControl( m_sbVertical
, m_controlRef
) ;
2573 frameOptions
&= ~kTXNWantVScrollBarMask
;
2575 if ( frameOptions
& kTXNWantHScrollBarMask
)
2577 CreateScrollBarControl( m_txnWindow
, &sb
, 0 , 0 , 100 , 1 , true , gTXNScrollActionProc
, &m_sbHorizontal
) ;
2578 SetControlReference( m_sbHorizontal
, (SInt32
) this ) ;
2579 SetControlAction( m_sbHorizontal
, gTXNScrollActionProc
);
2580 ShowControl( m_sbHorizontal
) ;
2581 EmbedControl( m_sbHorizontal
, m_controlRef
) ;
2582 frameOptions
&= ~(kTXNWantHScrollBarMask
| kTXNDrawGrowIconMask
);
2587 verify_noerr(TXNNewObject(NULL
, m_txnWindow
, &bounds
,
2589 kTXNTextEditStyleFrameType
,
2591 kTXNSystemDefaultEncoding
,
2592 &m_txn
, &m_txnFrameID
, NULL
) );
2594 #ifdef __WXMAC_OSX__
2595 TXNRegisterScrollInfoProc( m_txn
, gTXNScrollInfoProc
, (SInt32
) this);
2598 SetGWorld( origPort
, origDev
) ;
2602 // ----------------------------------------------------------------------------
2603 // MLTE control implementation (OSX part)
2604 // ----------------------------------------------------------------------------
2606 #if TARGET_API_MAC_OSX
2608 #if MAC_OS_X_VERSION_MAX_ALLOWED > MAC_OS_X_VERSION_10_2
2610 wxMacMLTEHIViewControl::wxMacMLTEHIViewControl( wxTextCtrl
*wxPeer
,
2611 const wxString
& str
,
2613 const wxSize
& size
, long style
) : wxMacMLTEControl( wxPeer
)
2615 m_font
= wxPeer
->GetFont() ;
2616 m_windowStyle
= style
;
2617 Rect bounds
= wxMacGetBoundsForControl( wxPeer
, pos
, size
) ;
2619 wxMacConvertNewlines10To13( &st
) ;
2621 HIRect hr
= { bounds
.left
, bounds
.top
, bounds
.right
- bounds
.left
, bounds
.bottom
- bounds
.top
} ;
2623 m_scrollView
= NULL
;
2624 TXNFrameOptions frameOptions
= FrameOptionsFromWXStyle( style
) ;
2625 if ( frameOptions
& (kTXNWantVScrollBarMask
|kTXNWantHScrollBarMask
) )
2627 HIScrollViewCreate(( frameOptions
& kTXNWantHScrollBarMask
? kHIScrollViewOptionsHorizScroll
: 0) |
2628 ( frameOptions
& kTXNWantVScrollBarMask
? kHIScrollViewOptionsVertScroll
: 0 ) , &m_scrollView
) ;
2630 HIViewSetFrame( m_scrollView
, &hr
);
2631 HIViewSetVisible( m_scrollView
, true );
2635 HITextViewCreate( NULL
, 0, frameOptions
, &m_textView
) ;
2636 m_txn
= HITextViewGetTXNObject( m_textView
) ;
2637 HIViewSetVisible( m_textView
, true ) ;
2640 HIViewAddSubview( m_scrollView
, m_textView
) ;
2641 m_controlRef
= m_scrollView
;
2642 wxPeer
->MacInstallEventHandler( (WXWidget
) m_textView
) ;
2646 HIViewSetFrame( m_textView
, &hr
);
2647 m_controlRef
= m_textView
;
2650 AdjustCreationAttributes( *wxWHITE
, true ) ;
2652 wxMacWindowClipper
c( m_peer
) ;
2653 SetTXNData( st
, kTXNStartOffset
, kTXNEndOffset
) ;
2655 TXNSetSelection( m_txn
, 0, 0);
2656 TXNShowSelection( m_txn
, kTXNShowStart
);
2660 OSStatus
wxMacMLTEHIViewControl::SetFocus( ControlFocusPart focusPart
)
2662 return SetKeyboardFocus( GetControlOwner( m_textView
) ,
2663 m_textView
, focusPart
) ;
2666 bool wxMacMLTEHIViewControl::HasFocus() const
2668 ControlRef control
;
2669 GetKeyboardFocus( GetUserFocusWindow() , &control
) ;
2670 return control
== m_textView
;
2673 #endif // MAC_OS_X_VERSION_MAX_ALLOWED > MAC_OS_X_VERSION_10_2
2678 #endif // wxUSE_TEXTCTRL