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 ;
200 #ifndef __WXMAC_OSX__
201 virtual void MacControlUserPaneDrawProc(wxInt16 part
) = 0 ;
202 virtual wxInt16
MacControlUserPaneHitTestProc(wxInt16 x
, wxInt16 y
) = 0 ;
203 virtual wxInt16
MacControlUserPaneTrackingProc(wxInt16 x
, wxInt16 y
, void* actionProc
) = 0 ;
204 virtual void MacControlUserPaneIdleProc() = 0 ;
205 virtual wxInt16
MacControlUserPaneKeyDownProc(wxInt16 keyCode
, wxInt16 charCode
, wxInt16 modifiers
) = 0 ;
206 virtual void MacControlUserPaneActivateProc(bool activating
) = 0 ;
207 virtual wxInt16
MacControlUserPaneFocusProc(wxInt16 action
) = 0 ;
208 virtual void MacControlUserPaneBackgroundProc(void* info
) = 0 ;
212 // common parts for implementations based on MLTE
214 class wxMacMLTEControl
: public wxMacTextControl
217 wxMacMLTEControl( wxTextCtrl
*peer
) ;
218 virtual wxString
GetStringValue() const ;
219 virtual void SetStringValue( const wxString
&str
) ;
221 static TXNFrameOptions
FrameOptionsFromWXStyle( long wxStyle
) ;
222 void AdjustCreationAttributes( const wxColour
& background
, bool visible
) ;
224 virtual void SetFont( const wxFont
& font
, const wxColour
& foreground
, long windowStyle
) ;
225 virtual void SetBackground( const wxBrush
&brush
) ;
226 virtual void SetStyle(long start
, long end
, const wxTextAttr
& style
) ;
227 virtual void Copy() ;
229 virtual void Paste() ;
230 virtual bool CanPaste() const ;
231 virtual void SetEditable(bool editable
) ;
232 virtual wxTextPos
GetLastPosition() const ;
233 virtual void Replace( long from
, long to
, const wxString str
) ;
234 virtual void Remove( long from
, long to
) ;
235 virtual void GetSelection( long* from
, long* to
) const ;
236 virtual void SetSelection( long from
, long to
) ;
238 virtual void WriteText(const wxString
& str
) ;
239 virtual void Clear() ;
241 virtual bool CanUndo() const ;
242 virtual void Undo() ;
243 virtual bool CanRedo() const;
244 virtual void Redo() ;
245 virtual int GetNumberOfLines() const ;
246 virtual long XYToPosition(long x
, long y
) const ;
247 virtual bool PositionToXY(long pos
, long *x
, long *y
) const ;
248 virtual void ShowPosition( long pos
) ;
249 virtual int GetLineLength(long lineNo
) const ;
250 virtual wxString
GetLineText(long lineNo
) const ;
252 void SetTXNData( const wxString
& st
, TXNOffset start
, TXNOffset end
) ;
255 void TXNSetAttribute( const wxTextAttr
& style
, long from
, long to
) ;
259 #if TARGET_API_MAC_OSX
261 // implementation available under OSX
263 #if MAC_OS_X_VERSION_MAX_ALLOWED > MAC_OS_X_VERSION_10_2
265 class wxMacMLTEHIViewControl
: public wxMacMLTEControl
268 wxMacMLTEHIViewControl( wxTextCtrl
*wxPeer
,
271 const wxSize
& size
, long style
) ;
272 virtual OSStatus
SetFocus( ControlFocusPart focusPart
) ;
273 virtual bool HasFocus() const ;
275 HIViewRef m_scrollView
;
276 HIViewRef m_textView
;
281 class wxMacUnicodeTextControl
: public wxMacTextControl
284 wxMacUnicodeTextControl( wxTextCtrl
*wxPeer
,
287 const wxSize
& size
, long style
) ;
288 ~wxMacUnicodeTextControl();
289 virtual void VisibilityChanged(bool shown
);
290 virtual wxString
GetStringValue() const ;
291 virtual void SetStringValue( const wxString
&str
) ;
294 virtual void Paste();
295 virtual bool CanPaste() const;
296 virtual void SetEditable(bool editable
) ;
297 virtual void Remove( long from
, long to
) ;
298 virtual void GetSelection( long* from
, long* to
) const ;
299 virtual void SetSelection( long from
, long to
) ;
300 virtual void WriteText(const wxString
& str
) ;
302 // contains the tag for the content (is different for password and non-password controls)
308 // 'classic' MLTE implementation
310 class wxMacMLTEClassicControl
: public wxMacMLTEControl
313 wxMacMLTEClassicControl( wxTextCtrl
*wxPeer
,
316 const wxSize
& size
, long style
) ;
317 ~wxMacMLTEClassicControl() ;
318 virtual void VisibilityChanged(bool shown
) ;
319 virtual void SuperChangedPosition() ;
321 virtual void MacControlUserPaneDrawProc(wxInt16 part
) ;
322 virtual wxInt16
MacControlUserPaneHitTestProc(wxInt16 x
, wxInt16 y
) ;
323 virtual wxInt16
MacControlUserPaneTrackingProc(wxInt16 x
, wxInt16 y
, void* actionProc
) ;
324 virtual void MacControlUserPaneIdleProc() ;
325 virtual wxInt16
MacControlUserPaneKeyDownProc(wxInt16 keyCode
, wxInt16 charCode
, wxInt16 modifiers
) ;
326 virtual void MacControlUserPaneActivateProc(bool activating
) ;
327 virtual wxInt16
MacControlUserPaneFocusProc(wxInt16 action
) ;
328 virtual void MacControlUserPaneBackgroundProc(void* info
) ;
330 virtual void SetRect( Rect
*r
) ;
335 void MacUpdatePosition() ;
336 void MacActivatePaneText(Boolean setActive
) ;
337 void MacFocusPaneText(Boolean setFocus
) ;
339 void MacSetObjectVisibility(Boolean vis
) ;
341 TXNFrameID m_txnFrameID
;
343 WindowRef m_txnWindow
;
344 // bounds of the control as we last did set the txn frames
345 Rect m_txnControlBounds
;
348 static pascal void TXNScrollInfoProc (SInt32 iValue
, SInt32 iMaximumValue
,
349 TXNScrollBarOrientation iScrollBarOrientation
, SInt32 iRefCon
) ;
350 static pascal void TXNScrollActionProc( ControlRef controlRef
, ControlPartCode partCode
) ;
351 ControlRef m_sbHorizontal
;
352 SInt32 m_lastHorizontalValue
;
353 ControlRef m_sbVertical
;
354 SInt32 m_lastVerticalValue
;
358 #define TE_UNLIMITED_LENGTH 0xFFFFFFFFUL
360 #if !USE_SHARED_LIBRARY
361 IMPLEMENT_DYNAMIC_CLASS(wxTextCtrl
, wxControl
)
363 BEGIN_EVENT_TABLE(wxTextCtrl
, wxControl
)
364 EVT_ERASE_BACKGROUND( wxTextCtrl::OnEraseBackground
)
365 EVT_DROP_FILES(wxTextCtrl::OnDropFiles
)
366 EVT_CHAR(wxTextCtrl::OnChar
)
367 EVT_MENU(wxID_CUT
, wxTextCtrl::OnCut
)
368 EVT_MENU(wxID_COPY
, wxTextCtrl::OnCopy
)
369 EVT_MENU(wxID_PASTE
, wxTextCtrl::OnPaste
)
370 EVT_MENU(wxID_UNDO
, wxTextCtrl::OnUndo
)
371 EVT_MENU(wxID_REDO
, wxTextCtrl::OnRedo
)
373 EVT_UPDATE_UI(wxID_CUT
, wxTextCtrl::OnUpdateCut
)
374 EVT_UPDATE_UI(wxID_COPY
, wxTextCtrl::OnUpdateCopy
)
375 EVT_UPDATE_UI(wxID_PASTE
, wxTextCtrl::OnUpdatePaste
)
376 EVT_UPDATE_UI(wxID_UNDO
, wxTextCtrl::OnUpdateUndo
)
377 EVT_UPDATE_UI(wxID_REDO
, wxTextCtrl::OnUpdateRedo
)
382 void wxTextCtrl::Init()
387 m_maxLength
= TE_UNLIMITED_LENGTH
;
390 wxTextCtrl::~wxTextCtrl()
395 bool wxTextCtrl::Create(wxWindow
*parent
, wxWindowID id
,
398 const wxSize
& size
, long style
,
399 const wxValidator
& validator
,
400 const wxString
& name
)
402 m_macIsUserPane
= false ;
405 if ( ! ( style
& wxNO_BORDER
) )
406 style
= ( style
& ~wxBORDER_MASK
) | wxSUNKEN_BORDER
;
408 if ( !wxTextCtrlBase::Create(parent
, id
, pos
, size
, style
& ~(wxHSCROLL
|wxVSCROLL
), validator
, name
) )
411 if ( m_windowStyle
& wxTE_MULTILINE
)
413 wxASSERT_MSG( !(m_windowStyle
& wxTE_PROCESS_ENTER
),
414 wxT("wxTE_PROCESS_ENTER style is ignored for multiline text controls (they always process it)") );
416 m_windowStyle
|= wxTE_PROCESS_ENTER
;
417 style
|= wxTE_PROCESS_ENTER
;
421 #if MAC_OS_X_VERSION_MAX_ALLOWED > MAC_OS_X_VERSION_10_2
422 if ( UMAGetSystemVersion() >= 0x1050 )
424 m_peer
= new wxMacMLTEHIViewControl( this , str
, pos
, size
, style
) ;
427 #if !wxMAC_AWAYS_USE_MLTE
430 m_peer
= new wxMacUnicodeTextControl( this , str
, pos
, size
, style
) ;
436 m_peer
= new wxMacMLTEClassicControl( this , str
, pos
, size
, style
) ;
439 MacPostControlCreate(pos
,size
) ;
441 if ( m_windowStyle
& wxTE_READONLY
)
443 SetEditable( false ) ;
449 void wxTextCtrl::MacSuperChangedPosition()
451 wxWindow::MacSuperChangedPosition() ;
452 GetPeer()->SuperChangedPosition() ;
455 void wxTextCtrl::MacVisibilityChanged()
457 GetPeer()->VisibilityChanged( MacIsReallyShown() ) ;
460 void wxTextCtrl::MacEnabledStateChanged()
464 wxString
wxTextCtrl::GetValue() const
466 return GetPeer()->GetStringValue() ;
469 void wxTextCtrl::GetSelection(long* from
, long* to
) const
471 GetPeer()->GetSelection( from
, to
) ;
474 void wxTextCtrl::SetValue(const wxString
& str
)
477 if ( GetValue() == str
)
480 GetPeer()->SetStringValue(str
) ;
482 wxCommandEvent
event(wxEVT_COMMAND_TEXT_UPDATED
, m_windowId
);
483 event
.SetString( GetValue() ) ;
484 event
.SetEventObject( this );
485 GetEventHandler()->ProcessEvent(event
);
488 void wxTextCtrl::SetMaxLength(unsigned long len
)
493 bool wxTextCtrl::SetFont( const wxFont
& font
)
495 if ( !wxTextCtrlBase::SetFont( font
) )
498 GetPeer()->SetFont( font
, GetForegroundColour() , GetWindowStyle() ) ;
502 bool wxTextCtrl::SetStyle(long start
, long end
, const wxTextAttr
& style
)
504 GetPeer()->SetStyle( start
, end
, style
) ;
508 bool wxTextCtrl::SetDefaultStyle(const wxTextAttr
& style
)
510 wxTextCtrlBase::SetDefaultStyle( style
) ;
511 SetStyle( kTXNUseCurrentSelection
, kTXNUseCurrentSelection
, GetDefaultStyle() ) ;
515 // Clipboard operations
516 void wxTextCtrl::Copy()
524 void wxTextCtrl::Cut()
530 wxCommandEvent
event(wxEVT_COMMAND_TEXT_UPDATED
, m_windowId
);
531 event
.SetEventObject( this );
532 GetEventHandler()->ProcessEvent(event
);
536 void wxTextCtrl::Paste()
541 // eventually we should add setting the default style again
543 wxCommandEvent
event(wxEVT_COMMAND_TEXT_UPDATED
, m_windowId
);
544 event
.SetEventObject( this );
545 GetEventHandler()->ProcessEvent(event
);
549 bool wxTextCtrl::CanCopy() const
551 // Can copy if there's a selection
553 GetSelection(& from
, & to
);
557 bool wxTextCtrl::CanCut() const
563 // Can cut if there's a selection
565 GetSelection(& from
, & to
);
569 bool wxTextCtrl::CanPaste() const
574 return GetPeer()->CanPaste() ;
577 void wxTextCtrl::SetEditable(bool editable
)
579 if ( editable
!= m_editable
)
581 m_editable
= editable
;
582 GetPeer()->SetEditable( editable
) ;
586 void wxTextCtrl::SetInsertionPoint(long pos
)
588 SetSelection( pos
, pos
) ;
591 void wxTextCtrl::SetInsertionPointEnd()
593 wxTextPos pos
= GetLastPosition();
594 SetInsertionPoint(pos
);
597 long wxTextCtrl::GetInsertionPoint() const
600 GetSelection( &begin
, &end
) ;
604 wxTextPos
wxTextCtrl::GetLastPosition() const
606 return GetPeer()->GetLastPosition( ) ;
609 void wxTextCtrl::Replace(long from
, long to
, const wxString
& str
)
611 GetPeer()->Replace( from
, to
, str
) ;
614 void wxTextCtrl::Remove(long from
, long to
)
616 GetPeer()->Remove( from
, to
) ;
619 void wxTextCtrl::SetSelection(long from
, long to
)
621 GetPeer()->SetSelection( from
, to
) ;
624 bool wxTextCtrl::LoadFile(const wxString
& file
)
626 if ( wxTextCtrlBase::LoadFile(file
) )
634 void wxTextCtrl::WriteText(const wxString
& str
)
636 // TODO this MPRemoting will be moved into a remoting peer proxy for any command
637 if ( !wxIsMainThread() )
639 // unfortunately CW 8 is not able to correctly deduce the template types, so we have
640 // to instantiate explicitely
641 wxMacMPRemoteGUICall
<wxTextCtrl
,wxString
>( this , &wxTextCtrl::WriteText
, str
) ;
646 GetPeer()->WriteText( str
) ;
650 void wxTextCtrl::AppendText(const wxString
& text
)
652 SetInsertionPointEnd();
656 void wxTextCtrl::Clear()
661 bool wxTextCtrl::IsModified() const
666 bool wxTextCtrl::IsEditable() const
668 return IsEnabled() && m_editable
;
671 bool wxTextCtrl::AcceptsFocus() const
673 // we don't want focus if we can't be edited
674 return /*IsEditable() && */ wxControl::AcceptsFocus();
677 wxSize
wxTextCtrl::DoGetBestSize() const
683 // these are the numbers from the HIG, we reduce them by the borders
686 switch( m_windowVariant
)
688 case wxWINDOW_VARIANT_NORMAL
:
691 case wxWINDOW_VARIANT_SMALL
:
694 case wxWINDOW_VARIANT_MINI
:
702 // as the above numbers have some free space around the text
703 // we get 5 lines like this anyway
704 if ( m_windowStyle
& wxTE_MULTILINE
)
709 if ( !HasFlag(wxNO_BORDER
) )
712 return wxSize(wText
, hText
);
715 // ----------------------------------------------------------------------------
717 // ----------------------------------------------------------------------------
719 void wxTextCtrl::Undo()
727 void wxTextCtrl::Redo()
735 bool wxTextCtrl::CanUndo() const
741 return GetPeer()->CanUndo() ;
744 bool wxTextCtrl::CanRedo() const
750 return GetPeer()->CanRedo() ;
753 void wxTextCtrl::MarkDirty()
758 void wxTextCtrl::DiscardEdits()
763 int wxTextCtrl::GetNumberOfLines() const
765 return GetPeer()->GetNumberOfLines() ;
768 long wxTextCtrl::XYToPosition(long x
, long y
) const
770 return GetPeer()->XYToPosition( x
, y
) ;
773 bool wxTextCtrl::PositionToXY(long pos
, long *x
, long *y
) const
775 return GetPeer()->PositionToXY(pos
, x
, y
) ;
778 void wxTextCtrl::ShowPosition(long pos
)
780 return GetPeer()->ShowPosition(pos
) ;
783 int wxTextCtrl::GetLineLength(long lineNo
) const
785 return GetPeer()->GetLineLength(lineNo
) ;
788 wxString
wxTextCtrl::GetLineText(long lineNo
) const
790 return GetPeer()->GetLineText(lineNo
) ;
797 void wxTextCtrl::Command(wxCommandEvent
& event
)
799 SetValue (event
.GetString());
800 ProcessCommand (event
);
803 void wxTextCtrl::OnDropFiles(wxDropFilesEvent
& event
)
805 // By default, load the first file into the text window.
806 if (event
.GetNumberOfFiles() > 0)
808 LoadFile(event
.GetFiles()[0]);
812 void wxTextCtrl::OnEraseBackground(wxEraseEvent
& event
)
814 // all erasing should be done by the real mac control implementation
815 // while this is true for MLTE under classic, the HITextView is somehow
816 // transparent but background erase is not working correctly, so intercept
817 // things while we can...
821 void wxTextCtrl::OnChar(wxKeyEvent
& event
)
823 int key
= event
.GetKeyCode() ;
824 bool eat_key
= false ;
826 if ( key
== 'c' && event
.MetaDown() )
833 if ( !IsEditable() && key
!= WXK_LEFT
&& key
!= WXK_RIGHT
&& key
!= WXK_DOWN
&& key
!= WXK_UP
&& key
!= WXK_TAB
&&
834 !( key
== WXK_RETURN
&& ( (m_windowStyle
& wxPROCESS_ENTER
) || (m_windowStyle
& wxTE_MULTILINE
) ) )
835 /* && key != WXK_PRIOR && key != WXK_NEXT && key != WXK_HOME && key != WXK_END */
842 // Check if we have reached the max # of chars, but still allow navigation and deletion
843 if ( !IsMultiLine() && GetValue().Length() >= m_maxLength
&&
844 key
!= WXK_LEFT
&& key
!= WXK_RIGHT
&& key
!= WXK_TAB
&&
845 key
!= WXK_BACK
&& !( key
== WXK_RETURN
&& (m_windowStyle
& wxPROCESS_ENTER
) )
848 // eat it, we don't want to add more than allowed # of characters
852 // assume that any key not processed yet is going to modify the control
855 if ( key
== 'v' && event
.MetaDown() )
861 if ( key
== 'x' && event
.MetaDown() )
870 if (m_windowStyle
& wxPROCESS_ENTER
)
872 wxCommandEvent
event(wxEVT_COMMAND_TEXT_ENTER
, m_windowId
);
873 event
.SetEventObject( this );
874 event
.SetString( GetValue() );
875 if ( GetEventHandler()->ProcessEvent(event
) )
878 if ( !(m_windowStyle
& wxTE_MULTILINE
) )
880 wxWindow
*parent
= GetParent();
881 while( parent
&& !parent
->IsTopLevel() && parent
->GetDefaultItem() == NULL
) {
882 parent
= parent
->GetParent() ;
884 if ( parent
&& parent
->GetDefaultItem() )
886 wxButton
*def
= wxDynamicCast(parent
->GetDefaultItem(),
888 if ( def
&& def
->IsEnabled() )
890 wxCommandEvent
event(wxEVT_COMMAND_BUTTON_CLICKED
, def
->GetId() );
891 event
.SetEventObject(def
);
897 // this will make wxWidgets eat the ENTER key so that
898 // we actually prevent line wrapping in a single line
906 if ( !(m_windowStyle
& wxTE_PROCESS_TAB
))
909 if (!event
.ShiftDown())
910 flags
|= wxNavigationKeyEvent::IsForward
;
911 if (event
.ControlDown())
912 flags
|= wxNavigationKeyEvent::WinChange
;
918 // This is necessary (don't know why) or the tab will not
920 WriteText(wxT("\t"));
928 // perform keystroke handling
929 if ( wxTheApp
->MacGetCurrentEvent() != NULL
&& wxTheApp
->MacGetCurrentEventHandlerCallRef() != NULL
)
930 CallNextEventHandler((EventHandlerCallRef
)wxTheApp
->MacGetCurrentEventHandlerCallRef() , (EventRef
) wxTheApp
->MacGetCurrentEvent() ) ;
934 if ( wxMacConvertEventToRecord( (EventRef
) wxTheApp
->MacGetCurrentEvent() , &rec
) )
936 EventRecord
*ev
= &rec
;
939 keychar
= short(ev
->message
& charCodeMask
);
940 keycode
= short(ev
->message
& keyCodeMask
) >> 8 ;
942 m_peer
->HandleKey( keycode
, keychar
, ev
->modifiers
) ;
946 if ( ( key
>= 0x20 && key
< WXK_START
) ||
951 wxCommandEvent
event1(wxEVT_COMMAND_TEXT_UPDATED
, m_windowId
);
952 event1
.SetEventObject( this );
953 wxPostEvent(GetEventHandler(),event1
);
957 // ----------------------------------------------------------------------------
958 // standard handlers for standard edit menu events
959 // ----------------------------------------------------------------------------
961 void wxTextCtrl::OnCut(wxCommandEvent
& WXUNUSED(event
))
966 void wxTextCtrl::OnCopy(wxCommandEvent
& WXUNUSED(event
))
971 void wxTextCtrl::OnPaste(wxCommandEvent
& WXUNUSED(event
))
976 void wxTextCtrl::OnUndo(wxCommandEvent
& WXUNUSED(event
))
981 void wxTextCtrl::OnRedo(wxCommandEvent
& WXUNUSED(event
))
986 void wxTextCtrl::OnUpdateCut(wxUpdateUIEvent
& event
)
988 event
.Enable( CanCut() );
991 void wxTextCtrl::OnUpdateCopy(wxUpdateUIEvent
& event
)
993 event
.Enable( CanCopy() );
996 void wxTextCtrl::OnUpdatePaste(wxUpdateUIEvent
& event
)
998 event
.Enable( CanPaste() );
1001 void wxTextCtrl::OnUpdateUndo(wxUpdateUIEvent
& event
)
1003 event
.Enable( CanUndo() );
1006 void wxTextCtrl::OnUpdateRedo(wxUpdateUIEvent
& event
)
1008 event
.Enable( CanRedo() );
1011 bool wxTextCtrl::MacSetupCursor( const wxPoint
& pt
)
1015 #if !TARGET_API_MAC_OSX
1017 // user pane implementation
1019 void wxTextCtrl::MacControlUserPaneDrawProc(wxInt16 part
)
1021 GetPeer()->MacControlUserPaneDrawProc( part
) ;
1024 wxInt16
wxTextCtrl::MacControlUserPaneHitTestProc(wxInt16 x
, wxInt16 y
)
1026 return GetPeer()->MacControlUserPaneHitTestProc( x
, y
) ;
1029 wxInt16
wxTextCtrl::MacControlUserPaneTrackingProc(wxInt16 x
, wxInt16 y
, void* actionProc
)
1031 return GetPeer()->MacControlUserPaneTrackingProc( x
, y
, actionProc
) ;
1034 void wxTextCtrl::MacControlUserPaneIdleProc()
1036 GetPeer()->MacControlUserPaneIdleProc( ) ;
1039 wxInt16
wxTextCtrl::MacControlUserPaneKeyDownProc(wxInt16 keyCode
, wxInt16 charCode
, wxInt16 modifiers
)
1041 return GetPeer()->MacControlUserPaneKeyDownProc( keyCode
, charCode
, modifiers
) ;
1044 void wxTextCtrl::MacControlUserPaneActivateProc(bool activating
)
1046 GetPeer()->MacControlUserPaneActivateProc( activating
) ;
1049 wxInt16
wxTextCtrl::MacControlUserPaneFocusProc(wxInt16 action
)
1051 return GetPeer()->MacControlUserPaneFocusProc( action
) ;
1054 void wxTextCtrl::MacControlUserPaneBackgroundProc(void* info
)
1056 GetPeer()->MacControlUserPaneBackgroundProc( info
) ;
1060 // ----------------------------------------------------------------------------
1061 // implementation base class
1062 // ----------------------------------------------------------------------------
1064 wxMacTextControl::wxMacTextControl(wxTextCtrl
* peer
) :
1065 wxMacControl( peer
)
1069 wxMacTextControl::~wxMacTextControl()
1073 void wxMacTextControl::SetStyle(long start
, long end
, const wxTextAttr
& style
)
1077 void wxMacTextControl::Copy()
1081 void wxMacTextControl::Cut()
1085 void wxMacTextControl::Paste()
1089 bool wxMacTextControl::CanPaste() const
1094 void wxMacTextControl::SetEditable(bool editable
)
1098 wxTextPos
wxMacTextControl::GetLastPosition() const
1100 return GetStringValue().Length() ;
1103 void wxMacTextControl::Replace( long from
, long to
, const wxString str
)
1107 void wxMacTextControl::Clear()
1109 SetStringValue( wxEmptyString
) ;
1112 bool wxMacTextControl::CanUndo() const
1117 void wxMacTextControl::Undo() { }
1119 bool wxMacTextControl::CanRedo() const
1124 void wxMacTextControl::Redo()
1128 long wxMacTextControl::XYToPosition(long x
, long y
) const
1133 bool wxMacTextControl::PositionToXY(long pos
, long *x
, long *y
) const
1138 void wxMacTextControl::ShowPosition( long WXUNUSED(pos
) )
1142 int wxMacTextControl::GetNumberOfLines() const
1144 ItemCount lines
= 0 ;
1145 wxString content
= GetStringValue() ;
1147 for (size_t i
= 0; i
< content
.Length() ; i
++)
1149 if (content
[i
] == '\r') lines
++;
1154 wxString
wxMacTextControl::GetLineText(long lineNo
) const
1156 // TODO change this if possible to reflect real lines
1157 wxString content
= GetStringValue() ;
1161 for (size_t i
= 0; i
< content
.Length() ; i
++)
1163 if (count
== lineNo
)
1165 // Add chars in line then
1168 for (size_t j
= i
; j
< content
.Length(); j
++)
1170 if (content
[j
] == '\n')
1178 if (content
[i
] == '\n') count
++;
1180 return wxEmptyString
;
1183 int wxMacTextControl::GetLineLength(long lineNo
) const
1185 // TODO change this if possible to reflect real lines
1186 wxString content
= GetStringValue() ;
1190 for (size_t i
= 0; i
< content
.Length() ; i
++)
1192 if (count
== lineNo
)
1194 // Count chars in line then
1196 for (size_t j
= i
; j
< content
.Length(); j
++)
1199 if (content
[j
] == '\n') return count
;
1204 if (content
[i
] == '\n') count
++;
1209 // ----------------------------------------------------------------------------
1210 // standard unicode control implementation
1211 // ----------------------------------------------------------------------------
1213 #if TARGET_API_MAC_OSX
1215 wxMacUnicodeTextControl::wxMacUnicodeTextControl( wxTextCtrl
*wxPeer
,
1216 const wxString
& str
,
1218 const wxSize
& size
, long style
) : wxMacTextControl( wxPeer
)
1220 m_font
= wxPeer
->GetFont() ;
1221 m_windowStyle
= style
;
1222 Rect bounds
= wxMacGetBoundsForControl( wxPeer
, pos
, size
) ;
1224 wxMacConvertNewlines10To13( &st
) ;
1225 wxMacCFStringHolder
cf(st
, m_font
.GetEncoding()) ;
1226 CFStringRef cfr
= cf
;
1227 Boolean isPassword
= ( m_windowStyle
& wxTE_PASSWORD
) != 0 ;
1228 m_valueTag
= isPassword
? kControlEditTextPasswordCFStringTag
: kControlEditTextCFStringTag
;
1229 CreateEditUnicodeTextControl( MAC_WXHWND(wxPeer
->MacGetTopLevelWindowRef()), &bounds
, cfr
, isPassword
, NULL
, &m_controlRef
) ;
1231 if ( !(m_windowStyle
& wxTE_MULTILINE
) )
1233 SetData
<Boolean
>( kControlEditTextPart
, kControlEditTextSingleLineTag
, true ) ;
1237 wxMacUnicodeTextControl::~wxMacUnicodeTextControl()
1241 void wxMacUnicodeTextControl::VisibilityChanged(bool shown
)
1243 if ( !(m_windowStyle
& wxTE_MULTILINE
) && shown
)
1245 // work around a refresh issue insofar as not always the entire content is shown even if this would be possible
1246 ControlEditTextSelectionRec sel
;
1247 CFStringRef value
= NULL
;
1249 verify_noerr( GetData
<ControlEditTextSelectionRec
>( 0, kControlEditTextSelectionTag
, &sel
) );
1250 verify_noerr( GetData
<CFStringRef
>( 0, m_valueTag
, &value
) );
1251 verify_noerr( SetData
<CFStringRef
>( 0, m_valueTag
, &value
) );
1252 verify_noerr( SetData
<ControlEditTextSelectionRec
>( 0, kControlEditTextSelectionTag
, &sel
) );
1254 CFRelease( value
) ;
1257 wxString
wxMacUnicodeTextControl::GetStringValue() const
1260 CFStringRef value
= GetData
<CFStringRef
>(0,m_valueTag
) ;
1263 wxMacCFStringHolder
cf(value
) ;
1264 result
= cf
.AsString() ;
1267 wxMacConvertNewlines13To10( &result
) ;
1269 wxMacConvertNewlines10To13( &result
) ;
1273 void wxMacUnicodeTextControl::SetStringValue( const wxString
&str
)
1276 wxMacConvertNewlines10To13( &st
) ;
1277 wxMacCFStringHolder
cf(st
, m_font
.GetEncoding() ) ;
1278 verify_noerr( SetData
<CFStringRef
>( 0, m_valueTag
, cf
) ) ;
1280 void wxMacUnicodeTextControl::Copy()
1282 SendHICommand( kHICommandCopy
) ;
1284 void wxMacUnicodeTextControl::Cut()
1286 SendHICommand( kHICommandCut
) ;
1288 void wxMacUnicodeTextControl::Paste()
1290 SendHICommand( kHICommandPaste
) ;
1292 bool wxMacUnicodeTextControl::CanPaste() const
1296 void wxMacUnicodeTextControl::SetEditable(bool editable
)
1298 SetData
<Boolean
>( 0 , kControlEditTextLockedTag
, (Boolean
) !editable
) ;
1300 void wxMacUnicodeTextControl::Remove( long from
, long to
)
1304 void wxMacUnicodeTextControl::GetSelection( long* from
, long* to
) const
1306 ControlEditTextSelectionRec sel
;
1307 verify_noerr(GetData
<ControlEditTextSelectionRec
>( 0, kControlEditTextSelectionTag
, &sel
) ) ;
1308 if ( from
) *from
= sel
.selStart
;
1309 if ( to
) *to
= sel
.selEnd
;
1312 void wxMacUnicodeTextControl::SetSelection( long from
, long to
)
1314 ControlEditTextSelectionRec sel
;
1315 sel
.selStart
= from
;
1317 SetData
<ControlEditTextSelectionRec
>( 0 , kControlEditTextSelectionTag
, &sel
) ;
1320 void wxMacUnicodeTextControl::WriteText(const wxString
& str
)
1323 wxMacConvertNewlines10To13( &st
) ;
1324 #if MAC_OS_X_VERSION_MAX_ALLOWED > MAC_OS_X_VERSION_10_2
1325 wxMacCFStringHolder
cf(st
, m_font
.GetEncoding() ) ;
1326 CFStringRef value
= cf
;
1327 SetData
<CFStringRef
>( 0, kControlEditTextInsertCFStringRefTag
, &value
);
1329 wxString val
= GetStringValue() ;
1331 GetSelection( &start
, &end
) ;
1332 val
.Remove( start
, end
- start
) ;
1333 val
.insert( start
, str
) ;
1334 SetStringValue( val
) ;
1335 SetSelection( start
+ str
.Length() , start
+ str
.Length() ) ;
1341 // ----------------------------------------------------------------------------
1342 // MLTE control implementation (common part)
1343 // ----------------------------------------------------------------------------
1345 // if mlte is on read only , no changes at all are allowed, not even from
1346 // procedural API, in order to allow changes via API all the same we must undo
1347 // the readonly status while we are executing, this class helps to do so
1349 class wxMacEditHelper
1352 wxMacEditHelper( TXNObject txn
)
1354 TXNControlTag tag
[] = { kTXNIOPrivilegesTag
} ;
1356 TXNGetTXNObjectControls( m_txn
, 1 , tag
, m_data
) ;
1357 if ( m_data
[0].uValue
== kTXNReadOnly
)
1359 TXNControlData data
[] = { { kTXNReadWrite
} } ;
1360 TXNSetTXNObjectControls( m_txn
, false , 1 , tag
, data
) ;
1365 TXNControlTag tag
[] = { kTXNIOPrivilegesTag
} ;
1366 if ( m_data
[0].uValue
== kTXNReadOnly
)
1368 TXNSetTXNObjectControls( m_txn
, false , 1 , tag
, m_data
) ;
1373 TXNControlData m_data
[1] ;
1376 wxMacMLTEControl::wxMacMLTEControl( wxTextCtrl
*peer
) : wxMacTextControl( peer
)
1378 SetNeedsFocusRect( true ) ;
1381 wxString
wxMacMLTEControl::GetStringValue() const
1385 Size actualSize
= 0;
1389 err
= TXNGetDataEncoded( m_txn
, kTXNStartOffset
, kTXNEndOffset
, &theText
, kTXNUnicodeTextData
);
1397 actualSize
= GetHandleSize( theText
) / sizeof( UniChar
) ;
1398 if ( actualSize
> 0 )
1400 wxChar
*ptr
= NULL
;
1401 #if SIZEOF_WCHAR_T == 2
1402 ptr
= new wxChar
[actualSize
+ 1 ] ;
1403 wxStrncpy( ptr
, (wxChar
*) *theText
, actualSize
) ;
1405 SetHandleSize( theText
, ( actualSize
+ 1 ) * sizeof( UniChar
) ) ;
1407 (((UniChar
*)*theText
)[actualSize
]) = 0 ;
1408 wxMBConvUTF16BE converter
;
1409 size_t noChars
= converter
.MB2WC( NULL
, (const char*)*theText
, 0 ) ;
1410 ptr
= new wxChar
[noChars
+ 1] ;
1412 noChars
= converter
.MB2WC( ptr
, (const char*)*theText
, noChars
) ;
1414 HUnlock( theText
) ;
1416 ptr
[actualSize
] = 0 ;
1417 result
= wxString( ptr
) ;
1420 DisposeHandle( theText
) ;
1424 err
= TXNGetDataEncoded( m_txn
, kTXNStartOffset
, kTXNEndOffset
, &theText
, kTXNTextData
);
1432 actualSize
= GetHandleSize( theText
) ;
1433 if ( actualSize
> 0 )
1436 result
= wxString( *theText
, wxConvLocal
, actualSize
) ;
1437 HUnlock( theText
) ;
1439 DisposeHandle( theText
) ;
1444 wxMacConvertNewlines13To10( &result
) ;
1446 wxMacConvertNewlines10To13( &result
) ;
1451 void wxMacMLTEControl::SetStringValue( const wxString
&str
)
1455 wxMacConvertNewlines10To13( &st
) ;
1457 wxMacWindowClipper
c( m_peer
) ;
1459 wxMacEditHelper
help(m_txn
) ;
1460 SetTXNData( st
, kTXNStartOffset
, kTXNEndOffset
) ;
1462 TXNSetSelection( m_txn
, 0, 0);
1463 TXNShowSelection( m_txn
, kTXNShowStart
);
1467 TXNFrameOptions
wxMacMLTEControl::FrameOptionsFromWXStyle( long wxStyle
)
1469 TXNFrameOptions frameOptions
=
1470 kTXNDontDrawCaretWhenInactiveMask
;
1472 if ( ! ( wxStyle
& wxTE_NOHIDESEL
) )
1473 frameOptions
|= kTXNDontDrawSelectionWhenInactiveMask
;
1475 if ( wxStyle
& wxTE_MULTILINE
)
1477 if ( ! ( wxStyle
& wxTE_DONTWRAP
) )
1478 frameOptions
|= kTXNAlwaysWrapAtViewEdgeMask
;
1481 frameOptions
|= kTXNAlwaysWrapAtViewEdgeMask
;
1482 frameOptions
|= kTXNWantHScrollBarMask
;
1485 if ( !(wxStyle
& wxTE_NO_VSCROLL
) )
1487 frameOptions
|= kTXNWantVScrollBarMask
;
1488 if ( frameOptions
& kTXNWantHScrollBarMask
)
1489 frameOptions
|= kTXNDrawGrowIconMask
;
1493 frameOptions
|= kTXNSingleLineOnlyMask
;
1495 if ( wxStyle
& wxHSCROLL
)
1496 frameOptions
|= kTXNWantHScrollBarMask
;
1498 return frameOptions
;
1501 void wxMacMLTEControl::AdjustCreationAttributes( const wxColour
&background
, bool visible
)
1503 TXNControlTag iControlTags
[] =
1505 kTXNDoFontSubstitution
,
1506 kTXNWordWrapStateTag
,
1508 TXNControlData iControlData
[] =
1514 int toptag
= WXSIZEOF( iControlTags
) ;
1516 if ( m_windowStyle
& wxTE_MULTILINE
)
1518 if (m_windowStyle
& wxTE_DONTWRAP
)
1519 iControlData
[1].uValue
= kTXNNoAutoWrap
;
1521 iControlData
[1].uValue
= kTXNAutoWrap
;
1523 verify_noerr( TXNSetTXNObjectControls( m_txn
, false, toptag
,
1524 iControlTags
, iControlData
)) ;
1526 // setting the default font
1532 GetThemeFont(kThemeSystemFont
, GetApplicationScript() , fontName
, &fontSize
, &fontStyle
) ;
1534 TXNTypeAttributes typeAttr
[] =
1536 { kTXNQDFontNameAttribute
, kTXNQDFontNameAttributeSize
, { (void*) fontName
} } ,
1537 { kTXNQDFontSizeAttribute
, kTXNFontSizeAttributeSize
, { (void*) (fontSize
<< 16) } } ,
1538 { kTXNQDFontStyleAttribute
, kTXNQDFontStyleAttributeSize
, { (void*) normal
} } ,
1541 verify_noerr( TXNSetTypeAttributes (m_txn
, sizeof( typeAttr
) / sizeof(TXNTypeAttributes
) , typeAttr
,
1545 if ( m_windowStyle
& wxTE_PASSWORD
)
1548 verify_noerr(TXNEchoMode( m_txn
, c
, 0 , true )) ;
1551 TXNBackground tback
;
1552 tback
.bgType
= kTXNBackgroundTypeRGB
;
1553 tback
.bg
.color
= MAC_WXCOLORREF( background
.GetPixel() );
1554 TXNSetBackground( m_txn
, &tback
);
1557 void wxMacMLTEControl::SetBackground( const wxBrush
&brush
)
1559 // currently only solid background are supported
1560 TXNBackground tback
;
1561 tback
.bgType
= kTXNBackgroundTypeRGB
;
1562 tback
.bg
.color
= MAC_WXCOLORREF( brush
.GetColour().GetPixel() );
1563 TXNSetBackground( m_txn
, &tback
);
1566 void wxMacMLTEControl::TXNSetAttribute( const wxTextAttr
& style
, long from
, long to
)
1568 TXNTypeAttributes typeAttr
[4] ;
1569 Str255 fontName
= "\pMonaco" ;
1570 SInt16 fontSize
= 12 ;
1571 Style fontStyle
= normal
;
1573 int attrCounter
= 0 ;
1574 if ( style
.HasFont() )
1576 const wxFont
&font
= style
.GetFont() ;
1577 wxMacStringToPascal( font
.GetFaceName() , fontName
) ;
1578 fontSize
= font
.GetPointSize() ;
1579 if ( font
.GetUnderlined() )
1580 fontStyle
|= underline
;
1581 if ( font
.GetWeight() == wxBOLD
)
1583 if ( font
.GetStyle() == wxITALIC
)
1584 fontStyle
|= italic
;
1586 typeAttr
[attrCounter
].tag
= kTXNQDFontNameAttribute
;
1587 typeAttr
[attrCounter
].size
= kTXNQDFontNameAttributeSize
;
1588 typeAttr
[attrCounter
].data
.dataPtr
= (void*) fontName
;
1589 typeAttr
[attrCounter
+1].tag
= kTXNQDFontSizeAttribute
;
1590 typeAttr
[attrCounter
+1].size
= kTXNFontSizeAttributeSize
;
1591 typeAttr
[attrCounter
+1].data
.dataValue
= (fontSize
<< 16) ;
1592 typeAttr
[attrCounter
+2].tag
= kTXNQDFontStyleAttribute
;
1593 typeAttr
[attrCounter
+2].size
= kTXNQDFontStyleAttributeSize
;
1594 typeAttr
[attrCounter
+2].data
.dataValue
= fontStyle
;
1597 if ( style
.HasTextColour() )
1599 typeAttr
[attrCounter
].tag
= kTXNQDFontColorAttribute
;
1600 typeAttr
[attrCounter
].size
= kTXNQDFontColorAttributeSize
;
1601 typeAttr
[attrCounter
].data
.dataPtr
= (void*) &color
;
1602 color
= MAC_WXCOLORREF(style
.GetTextColour().GetPixel()) ;
1605 if ( attrCounter
> 0 )
1607 verify_noerr( TXNSetTypeAttributes ( m_txn
, attrCounter
, typeAttr
, from
, to
) );
1611 void wxMacMLTEControl::SetFont( const wxFont
& font
, const wxColour
& foreground
, long windowStyle
)
1613 wxMacEditHelper
help(m_txn
) ;
1614 TXNSetAttribute( wxTextAttr(foreground
,wxNullColour
,font
) , kTXNStartOffset
,kTXNEndOffset
) ;
1616 void wxMacMLTEControl::SetStyle(long start
, long end
, const wxTextAttr
& style
)
1618 wxMacEditHelper
help(m_txn
) ;
1619 TXNSetAttribute( style
, start
,end
) ;
1622 void wxMacMLTEControl::Copy()
1624 ClearCurrentScrap();
1626 TXNConvertToPublicScrap();
1629 void wxMacMLTEControl::Cut()
1631 ClearCurrentScrap();
1633 TXNConvertToPublicScrap();
1636 void wxMacMLTEControl::Paste()
1638 TXNConvertFromPublicScrap();
1642 bool wxMacMLTEControl::CanPaste() const
1644 return TXNIsScrapPastable() ;
1647 void wxMacMLTEControl::SetEditable(bool editable
)
1649 TXNControlTag tag
[] = { kTXNIOPrivilegesTag
} ;
1650 TXNControlData data
[] = { { editable
? kTXNReadWrite
: kTXNReadOnly
} } ;
1651 TXNSetTXNObjectControls( m_txn
, false , WXSIZEOF(tag
) , tag
, data
) ;
1654 wxTextPos
wxMacMLTEControl::GetLastPosition() const
1656 wxTextPos actualsize
= 0 ;
1659 OSErr err
= TXNGetDataEncoded( m_txn
, kTXNStartOffset
, kTXNEndOffset
, &theText
, kTXNTextData
);
1667 actualsize
= GetHandleSize( theText
) ;
1668 DisposeHandle( theText
) ;
1674 void wxMacMLTEControl::Replace( long from
, long to
, const wxString str
)
1676 wxString value
= str
;
1677 wxMacConvertNewlines10To13( &value
) ;
1679 wxMacEditHelper
help( m_txn
) ;
1680 wxMacWindowClipper
c( m_peer
) ;
1682 TXNSetSelection(m_txn
, from
, to
) ;
1684 SetTXNData( value
, kTXNUseCurrentSelection
, kTXNUseCurrentSelection
) ;
1687 void wxMacMLTEControl::Remove( long from
, long to
)
1689 wxMacWindowClipper
c( m_peer
) ;
1690 wxMacEditHelper
help( m_txn
) ;
1691 TXNSetSelection(m_txn
, from
, to
) ;
1695 void wxMacMLTEControl::GetSelection( long* from
, long* to
) const
1697 TXNGetSelection( m_txn
, (TXNOffset
*) from
, (TXNOffset
*) to
) ;
1700 void wxMacMLTEControl::SetSelection( long from
, long to
)
1702 wxMacWindowClipper
c( m_peer
) ;
1703 /* change the selection */
1704 if ((from
== -1) && (to
== -1))
1705 TXNSelectAll(m_txn
);
1707 TXNSetSelection( m_txn
, from
, to
);
1708 TXNShowSelection( m_txn
, kTXNShowStart
);
1711 void wxMacMLTEControl::WriteText(const wxString
& str
)
1714 wxMacConvertNewlines10To13( &st
) ;
1716 long start
, end
, dummy
;
1717 GetSelection( &start
, &dummy
) ;
1718 wxMacWindowClipper
c( m_peer
) ;
1720 wxMacEditHelper
helper( m_txn
) ;
1721 SetTXNData( st
, kTXNUseCurrentSelection
, kTXNUseCurrentSelection
) ;
1723 GetSelection( &dummy
, &end
) ;
1724 // TODO SetStyle( start , end , GetDefaultStyle() ) ;
1727 void wxMacMLTEControl::Clear()
1729 wxMacWindowClipper
c( m_peer
) ;
1730 wxMacEditHelper
st(m_txn
) ;
1731 TXNSetSelection( m_txn
, kTXNStartOffset
, kTXNEndOffset
) ;
1735 bool wxMacMLTEControl::CanUndo() const
1737 return TXNCanUndo( m_txn
, NULL
) ;
1740 void wxMacMLTEControl::Undo()
1745 bool wxMacMLTEControl::CanRedo() const
1747 return TXNCanRedo( m_txn
, NULL
) ;
1750 void wxMacMLTEControl::Redo()
1755 int wxMacMLTEControl::GetNumberOfLines() const
1757 ItemCount lines
= 0 ;
1758 TXNGetLineCount(m_txn
, &lines
) ;
1762 long wxMacMLTEControl::XYToPosition(long x
, long y
) const
1766 wxTextPos lastpos
= GetLastPosition() ;
1768 // TODO find a better implementation : while we can get the
1769 // line metrics of a certain line, we don't get its starting
1770 // position, so it would probably be rather a binary search
1771 // for the start position
1774 int lastHeight
= 0 ;
1777 for ( n
= 0 ; n
<= (ItemCount
) lastpos
; ++n
)
1779 if ( y
== ypos
&& x
== xpos
)
1782 TXNOffsetToPoint( m_txn
, n
, &curpt
);
1784 if ( curpt
.v
> lastHeight
)
1789 lastHeight
= curpt
.v
;
1797 bool wxMacMLTEControl::PositionToXY(long pos
, long *x
, long *y
) const
1801 wxTextPos lastpos
= GetLastPosition() ;
1806 if ( pos
<= lastpos
)
1808 // TODO find a better implementation : while we can get the
1809 // line metrics of a certain line, we don't get its starting
1810 // position, so it would probably be rather a binary search
1811 // for the start position
1814 int lastHeight
= 0 ;
1817 for ( n
= 0 ; n
<= (ItemCount
) pos
; ++n
)
1819 TXNOffsetToPoint(m_txn
, n
, &curpt
);
1821 if ( curpt
.v
> lastHeight
)
1826 lastHeight
= curpt
.v
;
1831 if ( y
) *y
= ypos
;
1832 if ( x
) *x
= xpos
;
1838 void wxMacMLTEControl::ShowPosition( long pos
)
1840 #if TARGET_RT_MAC_MACHO && defined(AVAILABLE_MAC_OS_X_VERSION_10_2_AND_LATER)
1844 TXNOffset selstart
, selend
;
1845 TXNGetSelection( m_txn
, &selstart
, &selend
) ;
1846 TXNOffsetToPoint( m_txn
, selstart
, ¤t
);
1847 TXNOffsetToPoint( m_txn
, pos
, &desired
);
1848 //TODO use HIPoints for 10.3 and above
1849 if ( (UInt32
) TXNScroll
!= (UInt32
) kUnresolvedCFragSymbolAddress
)
1851 OSErr theErr
= noErr
;
1852 SInt32 dv
= desired
.v
- current
.v
;
1853 SInt32 dh
= desired
.h
- current
.h
;
1854 TXNShowSelection( m_txn
, true ) ;
1855 theErr
= TXNScroll( m_txn
, kTXNScrollUnitsInPixels
, kTXNScrollUnitsInPixels
, &dv
, &dh
);
1856 wxASSERT_MSG( theErr
== noErr
, _T("TXNScroll returned an error!") );
1862 void wxMacMLTEControl::SetTXNData( const wxString
& st
, TXNOffset start
, TXNOffset end
)
1865 #if SIZEOF_WCHAR_T == 2
1866 size_t len
= st
.Len() ;
1867 TXNSetData( m_txn
, kTXNUnicodeTextData
, (void*)st
.wc_str(), len
* 2,
1870 wxMBConvUTF16BE converter
;
1871 ByteCount byteBufferLen
= converter
.WC2MB( NULL
, st
.wc_str() , 0 ) ;
1872 UniChar
*unibuf
= (UniChar
*) malloc(byteBufferLen
) ;
1873 converter
.WC2MB( (char*) unibuf
, st
.wc_str() , byteBufferLen
) ;
1874 TXNSetData( m_txn
, kTXNUnicodeTextData
, (void*)unibuf
, byteBufferLen
,
1879 wxCharBuffer text
= st
.mb_str(wxConvLocal
) ;
1880 TXNSetData( m_txn
, kTXNTextData
, (void*)text
.data(), strlen( text
) ,
1886 wxString
wxMacMLTEControl::GetLineText(long lineNo
) const
1890 if ( lineNo
< GetNumberOfLines() )
1898 // get the first possible position in the control
1900 TXNOffsetToPoint(m_txn
, 0, &firstPoint
);
1902 // Iterate through the lines until we reach the one we want,
1903 // adding to our current y pixel point position
1904 while (ypos
< lineNo
)
1906 TXNGetLineMetrics(m_txn
, ypos
++, &lineWidth
, &lineHeight
);
1907 currentHeight
+= lineHeight
;
1910 Point thePoint
= { firstPoint
.v
+ (currentHeight
>> 16), firstPoint
.h
+ (0) };
1911 TXNOffset theOffset
;
1912 TXNPointToOffset(m_txn
, thePoint
, &theOffset
);
1914 wxString content
= GetStringValue() ;
1915 Point currentPoint
= thePoint
;
1916 while(thePoint
.v
== currentPoint
.v
&& theOffset
< content
.length())
1918 line
+= content
[theOffset
];
1919 TXNOffsetToPoint(m_txn
, ++theOffset
, ¤tPoint
);
1925 int wxMacMLTEControl::GetLineLength(long lineNo
) const
1929 if ( lineNo
< GetNumberOfLines() )
1937 // get the first possible position in the control
1939 TXNOffsetToPoint(m_txn
, 0, &firstPoint
);
1941 // Iterate through the lines until we reach the one we want,
1942 // adding to our current y pixel point position
1943 while (ypos
< lineNo
)
1945 TXNGetLineMetrics(m_txn
, ypos
++, &lineWidth
, &lineHeight
);
1946 currentHeight
+= lineHeight
;
1949 Point thePoint
= { firstPoint
.v
+ (currentHeight
>> 16), firstPoint
.h
+ (0) };
1950 TXNOffset theOffset
;
1951 TXNPointToOffset(m_txn
, thePoint
, &theOffset
);
1953 wxString content
= GetStringValue() ;
1954 Point currentPoint
= thePoint
;
1955 while(thePoint
.v
== currentPoint
.v
&& theOffset
< content
.length())
1958 TXNOffsetToPoint(m_txn
, ++theOffset
, ¤tPoint
);
1965 // ----------------------------------------------------------------------------
1966 // MLTE control implementation (classic part)
1967 // ----------------------------------------------------------------------------
1969 // OS X Notes : We still don't have a full replacement for MLTE, so this implementation
1970 // has to live on. We have different problems coming from outdated implementations on the
1971 // various OS X versions. Most deal with the scrollbars: they are not correctly embedded
1972 // while this can be solved on 10.3 by reassigning them the correct place, on 10.2 there is
1973 // no way out, therefore we are using our own implementation and our own scrollbars ....
1975 #ifdef __WXMAC_OSX__
1977 TXNScrollInfoUPP gTXNScrollInfoProc
= NULL
;
1978 ControlActionUPP gTXNScrollActionProc
= NULL
;
1980 pascal void wxMacMLTEClassicControl::TXNScrollInfoProc (SInt32 iValue
, SInt32 iMaximumValue
, TXNScrollBarOrientation
1981 iScrollBarOrientation
, SInt32 iRefCon
)
1983 wxMacMLTEClassicControl
* mlte
= (wxMacMLTEClassicControl
*) iRefCon
;
1984 SInt32 value
= wxMax( iValue
, 0 ) ;
1985 SInt32 maximum
= wxMax( iMaximumValue
, 0 ) ;
1987 if ( iScrollBarOrientation
== kTXNHorizontal
)
1989 if ( mlte
->m_sbHorizontal
)
1991 SetControl32BitValue( mlte
->m_sbHorizontal
, value
) ;
1992 SetControl32BitMaximum( mlte
->m_sbHorizontal
, maximum
) ;
1993 mlte
->m_lastHorizontalValue
= value
;
1996 else if ( iScrollBarOrientation
== kTXNVertical
)
1998 if ( mlte
->m_sbVertical
)
2000 SetControl32BitValue( mlte
->m_sbVertical
, value
) ;
2001 SetControl32BitMaximum( mlte
->m_sbVertical
, maximum
) ;
2002 mlte
->m_lastVerticalValue
= value
;
2007 pascal void wxMacMLTEClassicControl::TXNScrollActionProc( ControlRef controlRef
, ControlPartCode partCode
)
2010 wxMacMLTEClassicControl
* mlte
= (wxMacMLTEClassicControl
*) GetControlReference( controlRef
) ;
2014 if ( controlRef
!= mlte
->m_sbVertical
&& controlRef
!= mlte
->m_sbHorizontal
)
2017 bool isHorizontal
= ( controlRef
== mlte
->m_sbHorizontal
) ;
2019 SInt32 minimum
= 0 ;
2020 SInt32 maximum
= GetControl32BitMaximum( controlRef
) ;
2021 SInt32 value
= GetControl32BitValue( controlRef
) ;
2025 case kControlDownButtonPart
:
2028 case kControlUpButtonPart
:
2031 case kControlPageDownPart
:
2032 delta
= GetControlViewSize( controlRef
) ;
2034 case kControlPageUpPart
:
2035 delta
= -GetControlViewSize( controlRef
) ;
2037 case kControlIndicatorPart
:
2039 ( isHorizontal
? mlte
->m_lastHorizontalValue
: mlte
->m_lastVerticalValue
) ;
2046 SInt32 newValue
= value
;
2048 if ( partCode
!= kControlIndicatorPart
)
2050 if( value
+ delta
< minimum
)
2051 delta
= minimum
- value
;
2052 if ( value
+ delta
> maximum
)
2053 delta
= maximum
- value
;
2055 SetControl32BitValue( controlRef
, value
+ delta
) ;
2056 newValue
= value
+ delta
;
2059 SInt32 verticalDelta
= isHorizontal
? 0 : delta
;
2060 SInt32 horizontalDelta
= isHorizontal
? delta
: 0 ;
2062 err
= TXNScroll( mlte
->m_txn
, kTXNScrollUnitsInPixels
, kTXNScrollUnitsInPixels
,
2063 &verticalDelta
, &horizontalDelta
);
2066 mlte
->m_lastHorizontalValue
= newValue
;
2068 mlte
->m_lastVerticalValue
= newValue
;
2073 // make correct activations
2074 void wxMacMLTEClassicControl::MacActivatePaneText(Boolean setActive
)
2076 wxTextCtrl
* textctrl
= (wxTextCtrl
*) GetControlReference(m_controlRef
);
2078 wxMacWindowClipper
clipper( textctrl
) ;
2079 TXNActivate(m_txn
, m_txnFrameID
, setActive
);
2081 ControlRef controlFocus
= 0 ;
2082 GetKeyboardFocus( m_txnWindow
, &controlFocus
) ;
2083 if ( controlFocus
== m_controlRef
)
2084 TXNFocus( m_txn
, setActive
);
2087 void wxMacMLTEClassicControl::MacFocusPaneText(Boolean setFocus
)
2089 TXNFocus( m_txn
, setFocus
);
2092 // guards against inappropriate redraw (hidden objects drawing onto window)
2094 void wxMacMLTEClassicControl::MacSetObjectVisibility(Boolean vis
)
2096 ControlRef controlFocus
= 0 ;
2097 GetKeyboardFocus( m_txnWindow
, &controlFocus
) ;
2099 if ( controlFocus
== m_controlRef
&& vis
== false )
2101 SetKeyboardFocus( m_txnWindow
, m_controlRef
, kControlFocusNoPart
) ;
2103 // we right now are always clipping as partial visibility (overlapped) visibility
2104 // is also a problem, if we run into further problems we might set the FrameBounds to an empty
2108 // make sure that the TXNObject is at the right position
2110 void wxMacMLTEClassicControl::MacUpdatePosition()
2112 wxTextCtrl
* textctrl
= (wxTextCtrl
*) GetControlReference(m_controlRef
);
2113 if ( textctrl
== NULL
)
2117 UMAGetControlBoundsInWindowCoords(m_controlRef
, &bounds
);
2119 if ( !EqualRect( &bounds
, &m_txnControlBounds
) )
2122 Rect oldBounds
= m_txnControlBounds
;
2123 m_txnControlBounds
= bounds
;
2124 wxMacWindowClipper
cl(textctrl
) ;
2126 #ifdef __WXMAC_OSX__
2127 bool isCompositing
= textctrl
->MacGetTopLevelWindow()->MacUsesCompositing() ;
2128 if ( m_sbHorizontal
|| m_sbVertical
)
2130 int w
= bounds
.right
- bounds
.left
;
2131 int h
= bounds
.bottom
- bounds
.top
;
2133 if ( m_sbHorizontal
)
2137 sbBounds
.left
= -1 ;
2138 sbBounds
.top
= h
- 14 ;
2139 sbBounds
.right
= w
+ 1 ;
2140 sbBounds
.bottom
= h
+ 1 ;
2142 if ( !isCompositing
)
2143 OffsetRect( &sbBounds
, m_txnControlBounds
.left
, m_txnControlBounds
.top
) ;
2145 SetControlBounds( m_sbHorizontal
, &sbBounds
) ;
2146 SetControlViewSize( m_sbHorizontal
, w
) ;
2152 sbBounds
.left
= w
- 14 ;
2154 sbBounds
.right
= w
+ 1 ;
2155 sbBounds
.bottom
= m_sbHorizontal
? h
- 14 : h
+ 1 ;
2157 if ( !isCompositing
)
2158 OffsetRect( &sbBounds
, m_txnControlBounds
.left
, m_txnControlBounds
.top
) ;
2160 SetControlBounds( m_sbVertical
, &sbBounds
) ;
2161 SetControlViewSize( m_sbVertical
, h
) ;
2164 TXNSetFrameBounds( m_txn
, m_txnControlBounds
.top
, m_txnControlBounds
.left
,
2165 m_txnControlBounds
.bottom
- ( m_sbHorizontal
? 14 : 0 ) , m_txnControlBounds
.right
- ( m_sbVertical
? 14 : 0 ), m_txnFrameID
);
2168 TXNSetFrameBounds( m_txn
, m_txnControlBounds
.top
, m_txnControlBounds
.left
,
2169 wxMax( m_txnControlBounds
.bottom
, m_txnControlBounds
.top
) ,
2170 wxMax( m_txnControlBounds
.right
, m_txnControlBounds
.left
) , m_txnFrameID
);
2172 // the SetFrameBounds method unter classic sometimes does not correctly scroll a selection into sight after a
2173 // movement, therefore we have to force it
2175 TXNLongRect textRect
;
2176 TXNGetRectBounds( m_txn
, NULL
, NULL
, &textRect
) ;
2177 if ( textRect
.left
< m_txnControlBounds
.left
)
2179 TXNShowSelection( m_txn
, false ) ;
2185 void wxMacMLTEClassicControl::SetRect( Rect
*r
)
2187 wxMacControl::SetRect( r
) ;
2188 MacUpdatePosition() ;
2191 void wxMacMLTEClassicControl::MacControlUserPaneDrawProc(wxInt16 thePart
)
2193 wxTextCtrl
* textctrl
= (wxTextCtrl
*) GetControlReference(m_controlRef
);
2194 if ( textctrl
== NULL
)
2197 if ( textctrl
->MacIsReallyShown() )
2199 wxMacWindowClipper
clipper( textctrl
) ;
2200 TXNDraw( m_txn
, NULL
) ;
2204 wxInt16
wxMacMLTEClassicControl::MacControlUserPaneHitTestProc(wxInt16 x
, wxInt16 y
)
2206 Point where
= { y
, x
} ;
2207 ControlPartCode result
;
2210 wxTextCtrl
* textctrl
= (wxTextCtrl
*) GetControlReference(m_controlRef
);
2211 if ( textctrl
== NULL
)
2214 if (textctrl
->MacIsReallyShown() )
2216 if (PtInRect(where
, &m_txnControlBounds
))
2217 result
= kControlEditTextPart
;
2220 // sometimes we get the coords also in control local coordinates, therefore test again
2221 if ( textctrl
->MacGetTopLevelWindow()->MacUsesCompositing() )
2224 textctrl
->MacClientToRootWindow( &x
, &y
) ;
2228 if (PtInRect(where
, &m_txnControlBounds
))
2229 result
= kControlEditTextPart
;
2237 wxInt16
wxMacMLTEClassicControl::MacControlUserPaneTrackingProc( wxInt16 x
, wxInt16 y
, void* actionProc
)
2239 wxTextCtrl
* textctrl
= (wxTextCtrl
*) GetControlReference(m_controlRef
);
2240 if ( textctrl
== NULL
)
2243 ControlPartCode partCodeResult
= 0;
2245 if (textctrl
->MacIsReallyShown() )
2247 Point startPt
= { y
,x
} ;
2248 // for compositing, we must convert these into toplevel window coordinates, because hittesting expects them
2249 if ( textctrl
->MacGetTopLevelWindow()->MacUsesCompositing() )
2252 textctrl
->MacClientToRootWindow( &x
, &y
) ;
2257 switch (MacControlUserPaneHitTestProc( startPt
.h
, startPt
.v
))
2259 case kControlEditTextPart
:
2261 wxMacWindowClipper
clipper( textctrl
) ;
2264 ConvertEventRefToEventRecord( (EventRef
) wxTheApp
->MacGetCurrentEvent() , &rec
) ;
2265 TXNClick( m_txn
, &rec
);
2271 return partCodeResult
;
2274 void wxMacMLTEClassicControl::MacControlUserPaneIdleProc()
2276 wxTextCtrl
* textctrl
= (wxTextCtrl
*) GetControlReference(m_controlRef
);
2277 if ( textctrl
== NULL
)
2280 if (textctrl
->MacIsReallyShown())
2282 if (IsControlActive(m_controlRef
))
2286 wxMacWindowClipper
clipper( textctrl
) ;
2291 if (PtInRect(mousep
, &m_txnControlBounds
))
2294 RectRgn((theRgn
= NewRgn()), &m_txnControlBounds
);
2295 TXNAdjustCursor(m_txn
, theRgn
);
2302 wxInt16
wxMacMLTEClassicControl::MacControlUserPaneKeyDownProc (wxInt16 keyCode
, wxInt16 charCode
, wxInt16 modifiers
)
2304 wxTextCtrl
* textctrl
= (wxTextCtrl
*) GetControlReference(m_controlRef
);
2305 if ( textctrl
== NULL
)
2308 wxMacWindowClipper
clipper( textctrl
) ;
2311 memset( &ev
, 0 , sizeof( ev
) ) ;
2313 ev
.modifiers
= modifiers
;
2314 ev
.message
= (( keyCode
<< 8 ) & keyCodeMask
) + ( charCode
& charCodeMask
) ;
2315 TXNKeyDown( m_txn
, &ev
);
2317 return kControlEntireControl
;
2320 void wxMacMLTEClassicControl::MacControlUserPaneActivateProc( bool activating
)
2322 MacActivatePaneText( activating
);
2325 wxInt16
wxMacMLTEClassicControl::MacControlUserPaneFocusProc(wxInt16 action
)
2327 ControlPartCode focusResult
;
2329 focusResult
= kControlFocusNoPart
;
2330 wxTextCtrl
* textctrl
= (wxTextCtrl
*) GetControlReference(m_controlRef
);
2331 if ( textctrl
== NULL
)
2334 wxMacWindowClipper
clipper( textctrl
) ;
2336 ControlRef controlFocus
= 0 ;
2337 GetKeyboardFocus( m_txnWindow
, &controlFocus
) ;
2338 bool wasFocused
= ( controlFocus
== m_controlRef
) ;
2342 case kControlFocusPrevPart
:
2343 case kControlFocusNextPart
:
2344 MacFocusPaneText( ( !wasFocused
));
2345 focusResult
= (!wasFocused
) ? (ControlPartCode
) kControlEditTextPart
: (ControlPartCode
) kControlFocusNoPart
;
2348 case kControlFocusNoPart
:
2350 MacFocusPaneText( false);
2351 focusResult
= kControlFocusNoPart
;
2358 void wxMacMLTEClassicControl::MacControlUserPaneBackgroundProc( void *info
)
2362 wxMacMLTEClassicControl::wxMacMLTEClassicControl( wxTextCtrl
*wxPeer
,
2363 const wxString
& str
,
2365 const wxSize
& size
, long style
) : wxMacMLTEControl( wxPeer
)
2367 m_font
= wxPeer
->GetFont() ;
2368 m_windowStyle
= style
;
2369 Rect bounds
= wxMacGetBoundsForControl( wxPeer
, pos
, size
) ;
2371 wxMacConvertNewlines10To13( &st
) ;
2375 featurSet
= kControlSupportsEmbedding
| kControlSupportsFocus
| kControlWantsIdle
2376 | kControlWantsActivate
| kControlHandlesTracking
// | kControlHasSpecialBackground
2377 | kControlGetsFocusOnClick
| kControlSupportsLiveFeedback
;
2379 verify_noerr( ::CreateUserPaneControl( MAC_WXHWND(wxPeer
->GetParent()->MacGetTopLevelWindowRef()), &bounds
, featurSet
, &m_controlRef
) );
2383 MacSetObjectVisibility( wxPeer
->MacIsReallyShown() ) ;
2385 AdjustCreationAttributes( *wxWHITE
, true) ;
2387 wxMacWindowClipper
clipper( m_peer
) ;
2388 SetTXNData( st
, kTXNStartOffset
, kTXNEndOffset
) ;
2389 TXNSetSelection( m_txn
, 0, 0);
2392 wxMacMLTEClassicControl::~wxMacMLTEClassicControl()
2394 TXNDeleteObject(m_txn
);
2398 void wxMacMLTEClassicControl::VisibilityChanged(bool shown
)
2400 MacSetObjectVisibility( shown
) ;
2401 wxMacControl::VisibilityChanged( shown
) ;
2404 void wxMacMLTEClassicControl::SuperChangedPosition()
2406 MacUpdatePosition() ;
2407 wxMacControl::SuperChangedPosition() ;
2410 #ifdef __WXMAC_OSX__
2412 ControlUserPaneDrawUPP gTPDrawProc
= NULL
;
2413 ControlUserPaneHitTestUPP gTPHitProc
= NULL
;
2414 ControlUserPaneTrackingUPP gTPTrackProc
= NULL
;
2415 ControlUserPaneIdleUPP gTPIdleProc
= NULL
;
2416 ControlUserPaneKeyDownUPP gTPKeyProc
= NULL
;
2417 ControlUserPaneActivateUPP gTPActivateProc
= NULL
;
2418 ControlUserPaneFocusUPP gTPFocusProc
= NULL
;
2420 static pascal void wxMacControlUserPaneDrawProc(ControlRef control
, SInt16 part
)
2422 wxTextCtrl
*textCtrl
= wxDynamicCast( wxFindControlFromMacControl(control
) , wxTextCtrl
) ;
2423 wxMacMLTEClassicControl
* win
= textCtrl
? dynamic_cast<wxMacMLTEClassicControl
*>(textCtrl
->GetPeer()) : NULL
;
2425 win
->MacControlUserPaneDrawProc(part
) ;
2428 static pascal ControlPartCode
wxMacControlUserPaneHitTestProc(ControlRef control
, Point where
)
2430 wxTextCtrl
*textCtrl
= wxDynamicCast( wxFindControlFromMacControl(control
) , wxTextCtrl
) ;
2431 wxMacMLTEClassicControl
* win
= textCtrl
? dynamic_cast<wxMacMLTEClassicControl
*>(textCtrl
->GetPeer()) : NULL
;
2433 return win
->MacControlUserPaneHitTestProc(where
.h
, where
.v
) ;
2435 return kControlNoPart
;
2438 static pascal ControlPartCode
wxMacControlUserPaneTrackingProc(ControlRef control
, Point startPt
, ControlActionUPP actionProc
)
2440 wxTextCtrl
*textCtrl
= wxDynamicCast( wxFindControlFromMacControl(control
) , wxTextCtrl
) ;
2441 wxMacMLTEClassicControl
* win
= textCtrl
? dynamic_cast<wxMacMLTEClassicControl
*>(textCtrl
->GetPeer()) : NULL
;
2443 return win
->MacControlUserPaneTrackingProc( startPt
.h
, startPt
.v
, (void*) actionProc
) ;
2445 return kControlNoPart
;
2448 static pascal void wxMacControlUserPaneIdleProc(ControlRef control
)
2450 wxTextCtrl
*textCtrl
= wxDynamicCast( wxFindControlFromMacControl(control
) , wxTextCtrl
) ;
2451 wxMacMLTEClassicControl
* win
= textCtrl
? dynamic_cast<wxMacMLTEClassicControl
*>(textCtrl
->GetPeer()) : NULL
;
2453 win
->MacControlUserPaneIdleProc() ;
2456 static pascal ControlPartCode
wxMacControlUserPaneKeyDownProc(ControlRef control
, SInt16 keyCode
, SInt16 charCode
, SInt16 modifiers
)
2458 wxTextCtrl
*textCtrl
= wxDynamicCast( wxFindControlFromMacControl(control
) , wxTextCtrl
) ;
2459 wxMacMLTEClassicControl
* win
= textCtrl
? dynamic_cast<wxMacMLTEClassicControl
*>(textCtrl
->GetPeer()) : NULL
;
2461 return win
->MacControlUserPaneKeyDownProc(keyCode
,charCode
,modifiers
) ;
2463 return kControlNoPart
;
2466 static pascal void wxMacControlUserPaneActivateProc(ControlRef control
, Boolean activating
)
2468 wxTextCtrl
*textCtrl
= wxDynamicCast( wxFindControlFromMacControl(control
) , wxTextCtrl
) ;
2469 wxMacMLTEClassicControl
* win
= textCtrl
? dynamic_cast<wxMacMLTEClassicControl
*>(textCtrl
->GetPeer()) : NULL
;
2471 win
->MacControlUserPaneActivateProc(activating
) ;
2474 static pascal ControlPartCode
wxMacControlUserPaneFocusProc(ControlRef control
, ControlFocusPart action
)
2476 wxTextCtrl
*textCtrl
= wxDynamicCast( wxFindControlFromMacControl(control
) , wxTextCtrl
) ;
2477 wxMacMLTEClassicControl
* win
= textCtrl
? dynamic_cast<wxMacMLTEClassicControl
*>(textCtrl
->GetPeer()) : NULL
;
2479 return win
->MacControlUserPaneFocusProc(action
) ;
2481 return kControlNoPart
;
2485 static pascal void wxMacControlUserPaneBackgroundProc(ControlRef control, ControlBackgroundPtr info)
2487 wxTextCtrl *textCtrl = wxDynamicCast( wxFindControlFromMacControl(control) , wxTextCtrl ) ;
2488 wxMacMLTEClassicControl * win = textCtrl ? dynamic_cast<wxMacMLTEClassicControl*>(textCtrl->GetPeer()) : NULL ;
2490 win->MacControlUserPaneBackgroundProc(info) ;
2495 // TXNRegisterScrollInfoProc
2497 OSStatus
wxMacMLTEClassicControl::DoCreate()
2501 OSStatus err
= noErr
;
2503 /* set up our globals */
2504 #ifdef __WXMAC_OSX__
2505 if (gTPDrawProc
== NULL
) gTPDrawProc
= NewControlUserPaneDrawUPP(wxMacControlUserPaneDrawProc
);
2506 if (gTPHitProc
== NULL
) gTPHitProc
= NewControlUserPaneHitTestUPP(wxMacControlUserPaneHitTestProc
);
2507 if (gTPTrackProc
== NULL
) gTPTrackProc
= NewControlUserPaneTrackingUPP(wxMacControlUserPaneTrackingProc
);
2508 if (gTPIdleProc
== NULL
) gTPIdleProc
= NewControlUserPaneIdleUPP(wxMacControlUserPaneIdleProc
);
2509 if (gTPKeyProc
== NULL
) gTPKeyProc
= NewControlUserPaneKeyDownUPP(wxMacControlUserPaneKeyDownProc
);
2510 if (gTPActivateProc
== NULL
) gTPActivateProc
= NewControlUserPaneActivateUPP(wxMacControlUserPaneActivateProc
);
2511 if (gTPFocusProc
== NULL
) gTPFocusProc
= NewControlUserPaneFocusUPP(wxMacControlUserPaneFocusProc
);
2513 if (gTXNScrollInfoProc
== NULL
) gTXNScrollInfoProc
= NewTXNScrollInfoUPP(TXNScrollInfoProc
) ;
2514 if (gTXNScrollActionProc
== NULL
) gTXNScrollActionProc
= NewControlActionUPP(TXNScrollActionProc
) ;
2517 /* set the initial settings for our private data */
2519 m_txnWindow
=GetControlOwner(m_controlRef
);
2520 m_txnPort
= (GrafPtr
) GetWindowPort(m_txnWindow
);
2522 #ifdef __WXMAC_OSX__
2523 /* set up the user pane procedures */
2524 SetControlData(m_controlRef
, kControlEntireControl
, kControlUserPaneDrawProcTag
, sizeof(gTPDrawProc
), &gTPDrawProc
);
2525 SetControlData(m_controlRef
, kControlEntireControl
, kControlUserPaneHitTestProcTag
, sizeof(gTPHitProc
), &gTPHitProc
);
2526 SetControlData(m_controlRef
, kControlEntireControl
, kControlUserPaneTrackingProcTag
, sizeof(gTPTrackProc
), &gTPTrackProc
);
2527 SetControlData(m_controlRef
, kControlEntireControl
, kControlUserPaneIdleProcTag
, sizeof(gTPIdleProc
), &gTPIdleProc
);
2528 SetControlData(m_controlRef
, kControlEntireControl
, kControlUserPaneKeyDownProcTag
, sizeof(gTPKeyProc
), &gTPKeyProc
);
2529 SetControlData(m_controlRef
, kControlEntireControl
, kControlUserPaneActivateProcTag
, sizeof(gTPActivateProc
), &gTPActivateProc
);
2530 SetControlData(m_controlRef
, kControlEntireControl
, kControlUserPaneFocusProcTag
, sizeof(gTPFocusProc
), &gTPFocusProc
);
2532 /* calculate the rectangles used by the control */
2533 UMAGetControlBoundsInWindowCoords(m_controlRef
, &bounds
);
2535 m_txnControlBounds
= bounds
;
2537 CGrafPtr origPort
= NULL
;
2538 GDHandle origDev
= NULL
;
2539 GetGWorld( &origPort
, &origDev
) ;
2542 /* create the new edit field */
2544 TXNFrameOptions frameOptions
= FrameOptionsFromWXStyle( m_windowStyle
) ;
2546 #ifdef __WXMAC_OSX__
2548 // the scrollbars are not correctly embedded but are inserted at the root
2549 // this gives us problems as we have erratic redraws even over the structure
2552 m_sbHorizontal
= 0 ;
2554 m_lastHorizontalValue
= 0 ;
2555 m_lastVerticalValue
= 0 ;
2557 Rect sb
= { 0 , 0 , 0 , 0 } ;
2558 if ( frameOptions
& kTXNWantVScrollBarMask
)
2560 CreateScrollBarControl( m_txnWindow
, &sb
, 0 , 0 , 100 , 1 , true , gTXNScrollActionProc
, &m_sbVertical
) ;
2561 SetControlReference( m_sbVertical
, (SInt32
) this ) ;
2562 SetControlAction( m_sbVertical
, gTXNScrollActionProc
);
2563 ShowControl( m_sbVertical
) ;
2564 EmbedControl( m_sbVertical
, m_controlRef
) ;
2565 frameOptions
&= ~kTXNWantVScrollBarMask
;
2567 if ( frameOptions
& kTXNWantHScrollBarMask
)
2569 CreateScrollBarControl( m_txnWindow
, &sb
, 0 , 0 , 100 , 1 , true , gTXNScrollActionProc
, &m_sbHorizontal
) ;
2570 SetControlReference( m_sbHorizontal
, (SInt32
) this ) ;
2571 SetControlAction( m_sbHorizontal
, gTXNScrollActionProc
);
2572 ShowControl( m_sbHorizontal
) ;
2573 EmbedControl( m_sbHorizontal
, m_controlRef
) ;
2574 frameOptions
&= ~(kTXNWantHScrollBarMask
| kTXNDrawGrowIconMask
);
2579 verify_noerr(TXNNewObject(NULL
, m_txnWindow
, &bounds
,
2581 kTXNTextEditStyleFrameType
,
2583 kTXNSystemDefaultEncoding
,
2584 &m_txn
, &m_txnFrameID
, NULL
) );
2586 #ifdef __WXMAC_OSX__
2587 TXNRegisterScrollInfoProc( m_txn
, gTXNScrollInfoProc
, (SInt32
) this);
2590 SetGWorld( origPort
, origDev
) ;
2594 // ----------------------------------------------------------------------------
2595 // MLTE control implementation (OSX part)
2596 // ----------------------------------------------------------------------------
2598 #if TARGET_API_MAC_OSX
2600 #if MAC_OS_X_VERSION_MAX_ALLOWED > MAC_OS_X_VERSION_10_2
2602 wxMacMLTEHIViewControl::wxMacMLTEHIViewControl( wxTextCtrl
*wxPeer
,
2603 const wxString
& str
,
2605 const wxSize
& size
, long style
) : wxMacMLTEControl( wxPeer
)
2607 m_font
= wxPeer
->GetFont() ;
2608 m_windowStyle
= style
;
2609 Rect bounds
= wxMacGetBoundsForControl( wxPeer
, pos
, size
) ;
2611 wxMacConvertNewlines10To13( &st
) ;
2613 HIRect hr
= { bounds
.left
, bounds
.top
, bounds
.right
- bounds
.left
, bounds
.bottom
- bounds
.top
} ;
2615 m_scrollView
= NULL
;
2616 TXNFrameOptions frameOptions
= FrameOptionsFromWXStyle( style
) ;
2617 if ( frameOptions
& (kTXNWantVScrollBarMask
|kTXNWantHScrollBarMask
) )
2619 HIScrollViewCreate(( frameOptions
& kTXNWantHScrollBarMask
? kHIScrollViewOptionsHorizScroll
: 0) |
2620 ( frameOptions
& kTXNWantVScrollBarMask
? kHIScrollViewOptionsVertScroll
: 0 ) , &m_scrollView
) ;
2622 HIViewSetFrame( m_scrollView
, &hr
);
2623 HIViewSetVisible( m_scrollView
, true );
2627 HITextViewCreate( NULL
, 0, frameOptions
, &m_textView
) ;
2628 m_txn
= HITextViewGetTXNObject( m_textView
) ;
2629 HIViewSetVisible( m_textView
, true ) ;
2632 HIViewAddSubview( m_scrollView
, m_textView
) ;
2633 m_controlRef
= m_scrollView
;
2634 wxPeer
->MacInstallEventHandler( (WXWidget
) m_textView
) ;
2638 HIViewSetFrame( m_textView
, &hr
);
2639 m_controlRef
= m_textView
;
2642 AdjustCreationAttributes( *wxWHITE
, true ) ;
2644 wxMacWindowClipper
c( m_peer
) ;
2645 SetTXNData( st
, kTXNStartOffset
, kTXNEndOffset
) ;
2647 TXNSetSelection( m_txn
, 0, 0);
2648 TXNShowSelection( m_txn
, kTXNShowStart
);
2652 OSStatus
wxMacMLTEHIViewControl::SetFocus( ControlFocusPart focusPart
)
2654 return SetKeyboardFocus( GetControlOwner( m_textView
) ,
2655 m_textView
, focusPart
) ;
2658 bool wxMacMLTEHIViewControl::HasFocus() const
2660 ControlRef control
;
2661 GetKeyboardFocus( GetUserFocusWindow() , &control
) ;
2662 return control
== m_textView
;
2665 #endif // MAC_OS_X_VERSION_MAX_ALLOWED > MAC_OS_X_VERSION_10_2
2670 #endif // wxUSE_TEXTCTRL