1 /////////////////////////////////////////////////////////////////////////////
4 // Author: Stefan Csomor
5 // Modified by: Ryan Norton (MLTE GetLineLength and GetLineText)
8 // Copyright: (c) Stefan Csomor
9 // Licence: wxWindows licence
10 /////////////////////////////////////////////////////////////////////////////
13 #pragma implementation "textctrl.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
65 #include <MacTextEditor.h>
66 #include <ATSUnicode.h>
67 #include <TextCommon.h>
68 #include <TextEncodingConverter.h>
69 #include "wx/mac/uma.h"
75 virtual ~wxMacFunctor() {}
76 virtual void* operator()() = 0 ;
77 static void* CallBackProc(void *param
)
79 wxMacFunctor
* f
= (wxMacFunctor
*) param
;
80 void *result
= (*f
)() ;
85 template<typename classtype
,typename param1type
>
86 class wxMacObjectFunctor1
: public wxMacFunctor
88 typedef void (classtype::*function
)( param1type p1
) ;
89 typedef void (classtype::*ref_function
)( const param1type
& p1
) ;
91 wxMacObjectFunctor1( classtype
*obj
, function f
, param1type p1
) :
99 wxMacObjectFunctor1( classtype
*obj
, ref_function f
, param1type p1
) :
107 ~wxMacObjectFunctor1() {}
109 virtual void* operator()()
111 (m_object
->*m_function
)(m_param1
) ;
115 classtype
* m_object
;
116 param1type m_param1
;
119 function m_function
;
120 ref_function m_refFunction
;
124 template<typename classtype
, typename param1type
>
125 void* wxMacMPRemoteCall( classtype
*object
, void (classtype::*function
)( param1type p1
) , param1type p1
)
127 wxMacObjectFunctor1
<classtype
,param1type
> params(object
,function
,p1
) ;
129 MPRemoteCall( wxMacFunctor::CallBackProc
, ¶ms
, kMPOwningProcessRemoteContext
) ;
133 template<typename classtype
, typename param1type
>
134 void* wxMacMPRemoteCall( classtype
*object
, void (classtype::*function
)( const param1type
& p1
) , param1type p1
)
136 wxMacObjectFunctor1
<classtype
,param1type
> params(object
,function
,p1
) ;
138 MPRemoteCall( wxMacFunctor::CallBackProc
, ¶ms
, kMPOwningProcessRemoteContext
) ;
142 template<typename classtype
, typename param1type
>
143 void* wxMacMPRemoteGUICall( classtype
*object
, void (classtype::*function
)( param1type p1
) , param1type p1
)
146 void *result
= wxMacMPRemoteCall( object
, function
, p1
) ;
151 template<typename classtype
, typename param1type
>
152 void* wxMacMPRemoteGUICall( classtype
*object
, void (classtype::*function
)( const param1type
& p1
) , param1type p1
)
155 void *result
= wxMacMPRemoteCall( object
, function
, p1
) ;
159 // common interface for all implementations
160 class wxMacTextControl
: public wxMacControl
164 ~wxMacTextControl() ;
166 virtual wxString
GetStringValue() const = 0 ;
167 virtual void SetStringValue( const wxString
&val
) = 0 ;
168 virtual void SetStyle(long start
, long end
, const wxTextAttr
& style
) ;
169 virtual void Copy() ;
171 virtual void Paste() ;
172 virtual bool CanPaste() const ;
173 virtual void SetEditable(bool editable
) ;
174 virtual long GetLastPosition() const ;
175 virtual void Replace( long from
, long to
, const wxString str
) ;
176 virtual void Remove( long from
, long to
) = 0 ;
177 virtual void SetSelection( long from
, long to
) = 0 ;
178 virtual void GetSelection( long* from
, long* to
) const = 0 ;
179 virtual void WriteText(const wxString
& str
) = 0 ;
181 virtual void Clear() ;
182 virtual bool CanUndo() const;
183 virtual void Undo() ;
184 virtual bool CanRedo() const;
185 virtual void Redo() ;
186 virtual int GetNumberOfLines() const ;
187 virtual long XYToPosition(long x
, long y
) const;
188 virtual bool PositionToXY(long pos
, long *x
, long *y
) const ;
189 virtual void ShowPosition( long WXUNUSED(pos
) ) ;
190 virtual int GetLineLength(long lineNo
) const ;
191 virtual wxString
GetLineText(long lineNo
) const ;
194 // common parts for implementations based on MLTE
196 class wxMacMLTEControl
: public wxMacTextControl
199 virtual wxString
GetStringValue() const ;
200 virtual void SetStringValue( const wxString
&str
) ;
202 static TXNFrameOptions
FrameOptionsFromWXStyle( long wxStyle
) ;
203 void AdjustCreationAttributes( const wxColour
& background
, bool visible
) ;
205 virtual void SetFont( const wxFont
& font
, const wxColour
& foreground
, long windowStyle
) ;
206 virtual void SetBackground( const wxBrush
&brush
) ;
207 virtual void SetStyle(long start
, long end
, const wxTextAttr
& style
) ;
208 virtual void Copy() ;
210 virtual void Paste() ;
211 virtual bool CanPaste() const ;
212 virtual void SetEditable(bool editable
) ;
213 virtual long GetLastPosition() const ;
214 virtual void Replace( long from
, long to
, const wxString str
) ;
215 virtual void Remove( long from
, long to
) ;
216 virtual void GetSelection( long* from
, long* to
) const ;
217 virtual void SetSelection( long from
, long to
) ;
219 virtual void WriteText(const wxString
& str
) ;
220 virtual void Clear() ;
222 virtual bool CanUndo() const ;
223 virtual void Undo() ;
224 virtual bool CanRedo() const;
225 virtual void Redo() ;
226 virtual int GetNumberOfLines() const ;
227 virtual long XYToPosition(long x
, long y
) const ;
228 virtual bool PositionToXY(long pos
, long *x
, long *y
) const ;
229 virtual void ShowPosition( long pos
) ;
230 virtual int GetLineLength(long lineNo
) const ;
231 virtual wxString
GetLineText(long lineNo
) const ;
233 void SetTXNData( const wxString
& st
, TXNOffset start
, TXNOffset end
) ;
236 void TXNSetAttribute( const wxTextAttr
& style
, long from
, long to
) ;
240 #if TARGET_API_MAC_OSX
242 // implementation available under OSX
244 #if MAC_OS_X_VERSION_MAX_ALLOWED > MAC_OS_X_VERSION_10_2
246 class wxMacMLTEHIViewControl
: public wxMacMLTEControl
249 wxMacMLTEHIViewControl( wxWindow
*wxPeer
,
252 const wxSize
& size
, long style
) ;
253 virtual OSStatus
SetFocus( ControlFocusPart focusPart
) ;
254 virtual bool HasFocus() const ;
255 virtual bool NeedsFocusRect() const;
257 HIViewRef m_scrollView
;
258 HIViewRef m_textView
;
263 class wxMacUnicodeTextControl
: public wxMacTextControl
266 wxMacUnicodeTextControl( wxWindow
*wxPeer
,
269 const wxSize
& size
, long style
) ;
270 ~wxMacUnicodeTextControl();
271 virtual void VisibilityChanged(bool shown
);
272 virtual wxString
GetStringValue() const ;
273 virtual void SetStringValue( const wxString
&str
) ;
276 virtual void Paste();
277 virtual bool CanPaste() const;
278 virtual void SetEditable(bool editable
) ;
279 virtual void Remove( long from
, long to
) ;
280 virtual void GetSelection( long* from
, long* to
) const ;
281 virtual void SetSelection( long from
, long to
) ;
282 virtual void WriteText(const wxString
& str
) ;
284 // contains the tag for the content (is different for password and non-password controls)
290 // implementation available under classic
292 class STPTextPaneVars
;
294 class wxMacMLTEClassicControl
: public wxMacMLTEControl
297 wxMacMLTEClassicControl( wxWindow
*wxPeer
,
300 const wxSize
& size
, long style
) ;
301 ~wxMacMLTEClassicControl() ;
302 virtual void VisibilityChanged(bool shown
) ;
303 virtual bool NeedsFocusRect() const;
307 // hack to make public until we have migrated all procs
308 STPTextPaneVars
* m_macTXNvars
;
311 #define TE_UNLIMITED_LENGTH 0xFFFFFFFFUL
313 #if !USE_SHARED_LIBRARY
314 IMPLEMENT_DYNAMIC_CLASS(wxTextCtrl
, wxControl
)
316 BEGIN_EVENT_TABLE(wxTextCtrl
, wxControl
)
317 EVT_ERASE_BACKGROUND( wxTextCtrl::OnEraseBackground
)
318 EVT_DROP_FILES(wxTextCtrl::OnDropFiles
)
319 EVT_CHAR(wxTextCtrl::OnChar
)
320 EVT_MENU(wxID_CUT
, wxTextCtrl::OnCut
)
321 EVT_MENU(wxID_COPY
, wxTextCtrl::OnCopy
)
322 EVT_MENU(wxID_PASTE
, wxTextCtrl::OnPaste
)
323 EVT_MENU(wxID_UNDO
, wxTextCtrl::OnUndo
)
324 EVT_MENU(wxID_REDO
, wxTextCtrl::OnRedo
)
326 EVT_UPDATE_UI(wxID_CUT
, wxTextCtrl::OnUpdateCut
)
327 EVT_UPDATE_UI(wxID_COPY
, wxTextCtrl::OnUpdateCopy
)
328 EVT_UPDATE_UI(wxID_PASTE
, wxTextCtrl::OnUpdatePaste
)
329 EVT_UPDATE_UI(wxID_UNDO
, wxTextCtrl::OnUpdateUndo
)
330 EVT_UPDATE_UI(wxID_REDO
, wxTextCtrl::OnUpdateRedo
)
335 void wxTextCtrl::Init()
340 m_maxLength
= TE_UNLIMITED_LENGTH
;
343 wxTextCtrl::~wxTextCtrl()
348 bool wxTextCtrl::Create(wxWindow
*parent
, wxWindowID id
,
351 const wxSize
& size
, long style
,
352 const wxValidator
& validator
,
353 const wxString
& name
)
355 m_macIsUserPane
= FALSE
;
358 if ( ! ( style
& wxNO_BORDER
) )
359 style
= ( style
& ~wxBORDER_MASK
) | wxSUNKEN_BORDER
;
361 if ( !wxTextCtrlBase::Create(parent
, id
, pos
, size
, style
& ~(wxHSCROLL
|wxVSCROLL
), validator
, name
) )
364 Rect bounds
= wxMacGetBoundsForControl( this , pos
, size
) ;
366 if ( m_windowStyle
& wxTE_MULTILINE
)
368 wxASSERT_MSG( !(m_windowStyle
& wxTE_PROCESS_ENTER
),
369 wxT("wxTE_PROCESS_ENTER style is ignored for multiline text controls (they always process it)") );
371 m_windowStyle
|= wxTE_PROCESS_ENTER
;
372 style
|= wxTE_PROCESS_ENTER
;
375 #if TARGET_API_MAC_OSX
376 #if MAC_OS_X_VERSION_MAX_ALLOWED > MAC_OS_X_VERSION_10_2
377 if ( UMAGetSystemVersion() >= 0x1030 )
379 m_peer
= new wxMacMLTEHIViewControl( this , str
, pos
, size
, style
) ;
382 #if !wxMAC_AWAYS_USE_MLTE
385 m_peer
= new wxMacUnicodeTextControl( this , str
, pos
, size
, style
) ;
391 // this control draws the border itself
392 if ( !HasFlag(wxNO_BORDER
) )
394 m_windowStyle
&= ~wxSUNKEN_BORDER
;
395 bounds
= wxMacGetBoundsForControl( this , pos
, size
) ;
397 m_peer
= new wxMacMLTEClassicControl( this , str
, pos
, size
, style
) ;
400 MacPostControlCreate(pos
,size
) ;
402 if ( m_windowStyle
& wxTE_READONLY
)
404 SetEditable( false ) ;
411 void wxTextCtrl::MacVisibilityChanged()
413 GetPeer()->VisibilityChanged( MacIsReallyShown() ) ;
416 void wxTextCtrl::MacEnabledStateChanged()
420 wxString
wxTextCtrl::GetValue() const
422 return GetPeer()->GetStringValue() ;
425 void wxTextCtrl::GetSelection(long* from
, long* to
) const
427 GetPeer()->GetSelection( from
, to
) ;
430 void wxTextCtrl::SetValue(const wxString
& str
)
433 if ( GetValue() == str
)
436 GetPeer()->SetStringValue(str
) ;
438 wxCommandEvent
event(wxEVT_COMMAND_TEXT_UPDATED
, m_windowId
);
439 event
.SetString( GetValue() ) ;
440 event
.SetEventObject( this );
441 GetEventHandler()->ProcessEvent(event
);
444 void wxTextCtrl::SetMaxLength(unsigned long len
)
449 bool wxTextCtrl::SetFont( const wxFont
& font
)
451 if ( !wxTextCtrlBase::SetFont( font
) )
454 GetPeer()->SetFont( font
, GetForegroundColour() , GetWindowStyle() ) ;
458 bool wxTextCtrl::SetStyle(long start
, long end
, const wxTextAttr
& style
)
460 GetPeer()->SetStyle( start
, end
, style
) ;
464 bool wxTextCtrl::SetDefaultStyle(const wxTextAttr
& style
)
466 wxTextCtrlBase::SetDefaultStyle( style
) ;
467 SetStyle( kTXNUseCurrentSelection
, kTXNUseCurrentSelection
, GetDefaultStyle() ) ;
471 // Clipboard operations
472 void wxTextCtrl::Copy()
480 void wxTextCtrl::Cut()
486 wxCommandEvent
event(wxEVT_COMMAND_TEXT_UPDATED
, m_windowId
);
487 event
.SetString( GetValue() ) ;
488 event
.SetEventObject( this );
489 GetEventHandler()->ProcessEvent(event
);
493 void wxTextCtrl::Paste()
498 // eventually we should add setting the default style again
500 wxCommandEvent
event(wxEVT_COMMAND_TEXT_UPDATED
, m_windowId
);
501 event
.SetString( GetValue() ) ;
502 event
.SetEventObject( this );
503 GetEventHandler()->ProcessEvent(event
);
507 bool wxTextCtrl::CanCopy() const
509 // Can copy if there's a selection
511 GetSelection(& from
, & to
);
515 bool wxTextCtrl::CanCut() const
521 // Can cut if there's a selection
523 GetSelection(& from
, & to
);
527 bool wxTextCtrl::CanPaste() const
532 return GetPeer()->CanPaste() ;
535 void wxTextCtrl::SetEditable(bool editable
)
537 if ( editable
!= m_editable
)
539 m_editable
= editable
;
540 GetPeer()->SetEditable( editable
) ;
544 void wxTextCtrl::SetInsertionPoint(long pos
)
546 SetSelection( pos
, pos
) ;
549 void wxTextCtrl::SetInsertionPointEnd()
551 long pos
= GetLastPosition();
552 SetInsertionPoint(pos
);
555 long wxTextCtrl::GetInsertionPoint() const
558 GetSelection( &begin
, &end
) ;
562 long wxTextCtrl::GetLastPosition() const
564 return GetPeer()->GetLastPosition( ) ;
567 void wxTextCtrl::Replace(long from
, long to
, const wxString
& str
)
569 GetPeer()->Replace( from
, to
, str
) ;
572 void wxTextCtrl::Remove(long from
, long to
)
574 GetPeer()->Remove( from
, to
) ;
577 void wxTextCtrl::SetSelection(long from
, long to
)
579 GetPeer()->SetSelection( from
, to
) ;
582 bool wxTextCtrl::LoadFile(const wxString
& file
)
584 if ( wxTextCtrlBase::LoadFile(file
) )
592 void wxTextCtrl::WriteText(const wxString
& str
)
594 // TODO this MPRemoting will be moved into a remoting peer proxy for any command
595 if ( !wxIsMainThread() )
597 // unfortunately CW 8 is not able to correctly deduce the template types, so we have
598 // to instantiate explicitely
599 wxMacMPRemoteGUICall
<wxTextCtrl
,wxString
>( this , &wxTextCtrl::WriteText
, str
) ;
604 GetPeer()->WriteText( str
) ;
608 void wxTextCtrl::AppendText(const wxString
& text
)
610 SetInsertionPointEnd();
614 void wxTextCtrl::Clear()
619 bool wxTextCtrl::IsModified() const
624 bool wxTextCtrl::IsEditable() const
626 return IsEnabled() && m_editable
;
629 bool wxTextCtrl::AcceptsFocus() const
631 // we don't want focus if we can't be edited
632 return /*IsEditable() && */ wxControl::AcceptsFocus();
635 wxSize
wxTextCtrl::DoGetBestSize() const
641 // these are the numbers from the HIG, we reduce them by the borders
644 switch( m_windowVariant
)
646 case wxWINDOW_VARIANT_NORMAL
:
649 case wxWINDOW_VARIANT_SMALL
:
652 case wxWINDOW_VARIANT_MINI
:
660 // as the above numbers have some free space around the text
661 // we get 5 lines like this anyway
662 if ( m_windowStyle
& wxTE_MULTILINE
)
667 if ( !HasFlag(wxNO_BORDER
) )
670 return wxSize(wText
, hText
);
673 // ----------------------------------------------------------------------------
675 // ----------------------------------------------------------------------------
677 void wxTextCtrl::Undo()
685 void wxTextCtrl::Redo()
693 bool wxTextCtrl::CanUndo() const
699 return GetPeer()->CanUndo() ;
702 bool wxTextCtrl::CanRedo() const
708 return GetPeer()->CanRedo() ;
711 void wxTextCtrl::MarkDirty()
716 void wxTextCtrl::DiscardEdits()
721 int wxTextCtrl::GetNumberOfLines() const
723 return GetPeer()->GetNumberOfLines() ;
726 long wxTextCtrl::XYToPosition(long x
, long y
) const
728 return GetPeer()->XYToPosition( x
, y
) ;
731 bool wxTextCtrl::PositionToXY(long pos
, long *x
, long *y
) const
733 return GetPeer()->PositionToXY(pos
, x
, y
) ;
736 void wxTextCtrl::ShowPosition(long pos
)
738 return GetPeer()->ShowPosition(pos
) ;
741 int wxTextCtrl::GetLineLength(long lineNo
) const
743 return GetPeer()->GetLineLength(lineNo
) ;
746 wxString
wxTextCtrl::GetLineText(long lineNo
) const
748 return GetPeer()->GetLineText(lineNo
) ;
755 void wxTextCtrl::Command(wxCommandEvent
& event
)
757 SetValue (event
.GetString());
758 ProcessCommand (event
);
761 void wxTextCtrl::OnDropFiles(wxDropFilesEvent
& event
)
763 // By default, load the first file into the text window.
764 if (event
.GetNumberOfFiles() > 0)
766 LoadFile(event
.GetFiles()[0]);
770 void wxTextCtrl::OnEraseBackground(wxEraseEvent
& event
)
772 // all erasing should be done by the real mac control implementation
773 // while this is true for MLTE under classic, the HITextView is somehow
774 // transparent but background erase is not working correctly, so intercept
775 // things while we can...
779 void wxTextCtrl::OnChar(wxKeyEvent
& event
)
781 int key
= event
.GetKeyCode() ;
782 bool eat_key
= false ;
784 if ( key
== 'c' && event
.MetaDown() )
791 if ( !IsEditable() && key
!= WXK_LEFT
&& key
!= WXK_RIGHT
&& key
!= WXK_DOWN
&& key
!= WXK_UP
&& key
!= WXK_TAB
&&
792 !( key
== WXK_RETURN
&& ( (m_windowStyle
& wxPROCESS_ENTER
) || (m_windowStyle
& wxTE_MULTILINE
) ) )
793 /* && key != WXK_PRIOR && key != WXK_NEXT && key != WXK_HOME && key != WXK_END */
800 // Check if we have reached the max # of chars, but still allow navigation and deletion
801 if ( !IsMultiLine() && GetValue().Length() >= m_maxLength
&&
802 key
!= WXK_LEFT
&& key
!= WXK_RIGHT
&& key
!= WXK_TAB
&&
803 key
!= WXK_BACK
&& !( key
== WXK_RETURN
&& (m_windowStyle
& wxPROCESS_ENTER
) )
806 // eat it, we don't want to add more than allowed # of characters
810 // assume that any key not processed yet is going to modify the control
813 if ( key
== 'v' && event
.MetaDown() )
819 if ( key
== 'x' && event
.MetaDown() )
828 if (m_windowStyle
& wxPROCESS_ENTER
)
830 wxCommandEvent
event(wxEVT_COMMAND_TEXT_ENTER
, m_windowId
);
831 event
.SetEventObject( this );
832 event
.SetString( GetValue() );
833 if ( GetEventHandler()->ProcessEvent(event
) )
836 if ( !(m_windowStyle
& wxTE_MULTILINE
) )
838 wxWindow
*parent
= GetParent();
839 while( parent
&& !parent
->IsTopLevel() && parent
->GetDefaultItem() == NULL
) {
840 parent
= parent
->GetParent() ;
842 if ( parent
&& parent
->GetDefaultItem() )
844 wxButton
*def
= wxDynamicCast(parent
->GetDefaultItem(),
846 if ( def
&& def
->IsEnabled() )
848 wxCommandEvent
event(wxEVT_COMMAND_BUTTON_CLICKED
, def
->GetId() );
849 event
.SetEventObject(def
);
855 // this will make wxWidgets eat the ENTER key so that
856 // we actually prevent line wrapping in a single line
864 if ( !(m_windowStyle
& wxTE_PROCESS_TAB
))
867 if (!event
.ShiftDown())
868 flags
|= wxNavigationKeyEvent::IsForward
;
869 if (event
.ControlDown())
870 flags
|= wxNavigationKeyEvent::WinChange
;
876 // This is necessary (don't know why) or the tab will not
878 WriteText(wxT("\t"));
886 // perform keystroke handling
887 if ( wxTheApp
->MacGetCurrentEvent() != NULL
&& wxTheApp
->MacGetCurrentEventHandlerCallRef() != NULL
)
888 CallNextEventHandler((EventHandlerCallRef
)wxTheApp
->MacGetCurrentEventHandlerCallRef() , (EventRef
) wxTheApp
->MacGetCurrentEvent() ) ;
892 if ( wxMacConvertEventToRecord( (EventRef
) wxTheApp
->MacGetCurrentEvent() , &rec
) )
894 EventRecord
*ev
= &rec
;
897 keychar
= short(ev
->message
& charCodeMask
);
898 keycode
= short(ev
->message
& keyCodeMask
) >> 8 ;
900 m_peer
->HandleKey( keycode
, keychar
, ev
->modifiers
) ;
904 if ( ( key
>= 0x20 && key
< WXK_START
) ||
909 wxCommandEvent
event1(wxEVT_COMMAND_TEXT_UPDATED
, m_windowId
);
910 event1
.SetString( GetValue() ) ;
911 event1
.SetEventObject( this );
912 wxPostEvent(GetEventHandler(),event1
);
916 // ----------------------------------------------------------------------------
917 // standard handlers for standard edit menu events
918 // ----------------------------------------------------------------------------
920 void wxTextCtrl::OnCut(wxCommandEvent
& WXUNUSED(event
))
925 void wxTextCtrl::OnCopy(wxCommandEvent
& WXUNUSED(event
))
930 void wxTextCtrl::OnPaste(wxCommandEvent
& WXUNUSED(event
))
935 void wxTextCtrl::OnUndo(wxCommandEvent
& WXUNUSED(event
))
940 void wxTextCtrl::OnRedo(wxCommandEvent
& WXUNUSED(event
))
945 void wxTextCtrl::OnUpdateCut(wxUpdateUIEvent
& event
)
947 event
.Enable( CanCut() );
950 void wxTextCtrl::OnUpdateCopy(wxUpdateUIEvent
& event
)
952 event
.Enable( CanCopy() );
955 void wxTextCtrl::OnUpdatePaste(wxUpdateUIEvent
& event
)
957 event
.Enable( CanPaste() );
960 void wxTextCtrl::OnUpdateUndo(wxUpdateUIEvent
& event
)
962 event
.Enable( CanUndo() );
965 void wxTextCtrl::OnUpdateRedo(wxUpdateUIEvent
& event
)
967 event
.Enable( CanRedo() );
970 bool wxTextCtrl::MacSetupCursor( const wxPoint
& pt
)
975 // user pane implementation
977 void wxTextCtrl::MacControlUserPaneDrawProc(wxInt16 part
)
981 wxInt16
wxTextCtrl::MacControlUserPaneHitTestProc(wxInt16 x
, wxInt16 y
)
983 return kControlNoPart
;
986 wxInt16
wxTextCtrl::MacControlUserPaneTrackingProc(wxInt16 x
, wxInt16 y
, void* actionProc
)
988 return kControlNoPart
;
991 void wxTextCtrl::MacControlUserPaneIdleProc()
995 wxInt16
wxTextCtrl::MacControlUserPaneKeyDownProc(wxInt16 keyCode
, wxInt16 charCode
, wxInt16 modifiers
)
997 return kControlNoPart
;
1000 void wxTextCtrl::MacControlUserPaneActivateProc(bool activating
)
1004 wxInt16
wxTextCtrl::MacControlUserPaneFocusProc(wxInt16 action
)
1006 return kControlNoPart
;
1009 void wxTextCtrl::MacControlUserPaneBackgroundProc(void* info
)
1013 // ----------------------------------------------------------------------------
1014 // implementation base class
1015 // ----------------------------------------------------------------------------
1017 wxMacTextControl::wxMacTextControl()
1021 wxMacTextControl::~wxMacTextControl()
1025 void wxMacTextControl::SetStyle(long start
, long end
, const wxTextAttr
& style
)
1029 void wxMacTextControl::Copy()
1033 void wxMacTextControl::Cut()
1037 void wxMacTextControl::Paste()
1041 bool wxMacTextControl::CanPaste() const
1046 void wxMacTextControl::SetEditable(bool editable
)
1050 long wxMacTextControl::GetLastPosition() const
1052 return GetStringValue().Length() ;
1055 void wxMacTextControl::Replace( long from
, long to
, const wxString str
)
1059 void wxMacTextControl::Clear()
1061 SetStringValue( wxEmptyString
) ;
1064 bool wxMacTextControl::CanUndo() const
1069 void wxMacTextControl::Undo() { }
1071 bool wxMacTextControl::CanRedo() const
1076 void wxMacTextControl::Redo()
1080 long wxMacTextControl::XYToPosition(long x
, long y
) const
1085 bool wxMacTextControl::PositionToXY(long pos
, long *x
, long *y
) const
1090 void wxMacTextControl::ShowPosition( long WXUNUSED(pos
) )
1094 int wxMacTextControl::GetNumberOfLines() const
1096 ItemCount lines
= 0 ;
1097 wxString content
= GetStringValue() ;
1099 for (size_t i
= 0; i
< content
.Length() ; i
++)
1101 if (content
[i
] == '\r') lines
++;
1106 wxString
wxMacTextControl::GetLineText(long lineNo
) const
1108 // TODO change this if possible to reflect real lines
1109 wxString content
= GetStringValue() ;
1113 for (size_t i
= 0; i
< content
.Length() ; i
++)
1115 if (count
== lineNo
)
1117 // Add chars in line then
1120 for (size_t j
= i
; j
< content
.Length(); j
++)
1122 if (content
[j
] == '\n')
1130 if (content
[i
] == '\n') count
++;
1132 return wxEmptyString
;
1135 int wxMacTextControl::GetLineLength(long lineNo
) const
1137 // TODO change this if possible to reflect real lines
1138 wxString content
= GetStringValue() ;
1142 for (size_t i
= 0; i
< content
.Length() ; i
++)
1144 if (count
== lineNo
)
1146 // Count chars in line then
1148 for (size_t j
= i
; j
< content
.Length(); j
++)
1151 if (content
[j
] == '\n') return count
;
1156 if (content
[i
] == '\n') count
++;
1161 // ----------------------------------------------------------------------------
1162 // standard unicode control implementation
1163 // ----------------------------------------------------------------------------
1165 #if TARGET_API_MAC_OSX
1167 wxMacUnicodeTextControl::wxMacUnicodeTextControl( wxWindow
*wxPeer
,
1168 const wxString
& str
,
1170 const wxSize
& size
, long style
)
1172 m_font
= wxPeer
->GetFont() ;
1173 m_windowStyle
= style
;
1174 Rect bounds
= wxMacGetBoundsForControl( wxPeer
, pos
, size
) ;
1176 wxMacConvertNewlines10To13( &st
) ;
1177 wxMacCFStringHolder
cf(st
, m_font
.GetEncoding()) ;
1178 CFStringRef cfr
= cf
;
1179 Boolean isPassword
= ( m_windowStyle
& wxTE_PASSWORD
) != 0 ;
1180 m_valueTag
= isPassword
? kControlEditTextPasswordCFStringTag
: kControlEditTextCFStringTag
;
1181 CreateEditUnicodeTextControl( MAC_WXHWND(wxPeer
->MacGetTopLevelWindowRef()), &bounds
, cfr
, isPassword
, NULL
, &m_controlRef
) ;
1183 if ( !(m_windowStyle
& wxTE_MULTILINE
) )
1185 SetData
<Boolean
>( kControlEditTextPart
, kControlEditTextSingleLineTag
, true ) ;
1189 wxMacUnicodeTextControl::~wxMacUnicodeTextControl()
1193 void wxMacUnicodeTextControl::VisibilityChanged(bool shown
)
1195 if ( !(m_windowStyle
& wxTE_MULTILINE
) && shown
)
1197 // work around a refresh issue insofar as not always the entire content is shown even if this would be possible
1198 ControlEditTextSelectionRec sel
;
1199 CFStringRef value
= NULL
;
1201 verify_noerr( GetData
<ControlEditTextSelectionRec
>( 0, kControlEditTextSelectionTag
, &sel
) );
1202 verify_noerr( GetData
<CFStringRef
>( 0, m_valueTag
, &value
) );
1203 verify_noerr( SetData
<CFStringRef
>( 0, m_valueTag
, &value
) );
1204 verify_noerr( SetData
<ControlEditTextSelectionRec
>( 0, kControlEditTextSelectionTag
, &sel
) );
1206 CFRelease( value
) ;
1209 wxString
wxMacUnicodeTextControl::GetStringValue() const
1212 CFStringRef value
= GetData
<CFStringRef
>(0,m_valueTag
) ;
1215 wxMacCFStringHolder
cf(value
) ;
1216 result
= cf
.AsString() ;
1219 wxMacConvertNewlines13To10( &result
) ;
1221 wxMacConvertNewlines10To13( &result
) ;
1225 void wxMacUnicodeTextControl::SetStringValue( const wxString
&str
)
1228 wxMacConvertNewlines10To13( &st
) ;
1229 wxMacCFStringHolder
cf(st
, m_font
.GetEncoding() ) ;
1230 verify_noerr( SetData
<CFStringRef
>( 0, m_valueTag
, cf
) ) ;
1232 void wxMacUnicodeTextControl::Copy()
1234 SendHICommand( kHICommandCopy
) ;
1236 void wxMacUnicodeTextControl::Cut()
1238 SendHICommand( kHICommandCut
) ;
1240 void wxMacUnicodeTextControl::Paste()
1242 SendHICommand( kHICommandPaste
) ;
1244 bool wxMacUnicodeTextControl::CanPaste() const
1248 void wxMacUnicodeTextControl::SetEditable(bool editable
)
1250 SetData
<Boolean
>( 0 , kControlEditTextLockedTag
, (Boolean
) !editable
) ;
1252 void wxMacUnicodeTextControl::Remove( long from
, long to
)
1256 void wxMacUnicodeTextControl::GetSelection( long* from
, long* to
) const
1258 ControlEditTextSelectionRec sel
;
1259 verify_noerr(GetData
<ControlEditTextSelectionRec
>( 0, kControlEditTextSelectionTag
, &sel
) ) ;
1260 if ( from
) *from
= sel
.selStart
;
1261 if ( to
) *to
= sel
.selEnd
;
1264 void wxMacUnicodeTextControl::SetSelection( long from
, long to
)
1266 ControlEditTextSelectionRec sel
;
1267 sel
.selStart
= from
;
1269 SetData
<ControlEditTextSelectionRec
>( 0 , kControlEditTextSelectionTag
, &sel
) ;
1272 void wxMacUnicodeTextControl::WriteText(const wxString
& str
)
1275 wxMacConvertNewlines10To13( &st
) ;
1276 #if MAC_OS_X_VERSION_MAX_ALLOWED > MAC_OS_X_VERSION_10_2
1277 wxMacCFStringHolder
cf(st
, m_font
.GetEncoding() ) ;
1278 CFStringRef value
= cf
;
1279 SetData
<CFStringRef
>( 0, kControlEditTextInsertCFStringRefTag
, &value
);
1281 wxString val
= GetStringValue() ;
1283 GetSelection( &start
, &end
) ;
1284 val
.Remove( start
, end
- start
) ;
1285 val
.insert( start
, str
) ;
1286 SetStringValue( val
) ;
1287 SetSelection( start
+ str
.Length() , start
+ str
.Length() ) ;
1293 // ----------------------------------------------------------------------------
1294 // MLTE control implementation (common part)
1295 // ----------------------------------------------------------------------------
1297 #if TARGET_API_MAC_OSX == 0
1298 // declaration needed because of one line in the code...
1299 static void TPUpdateVisibility(ControlRef theControl
) ;
1302 // if mlte is on read only , no changes at all are allowed, not even from
1303 // procedural API, in order to allow changes via API all the same we must undo
1304 // the readonly status while we are executing, this class helps to do so
1309 EditHelper( TXNObject txn
)
1311 TXNControlTag tag
[] = { kTXNIOPrivilegesTag
} ;
1313 TXNGetTXNObjectControls( m_txn
, 1 , tag
, m_data
) ;
1314 if ( m_data
[0].uValue
== kTXNReadOnly
)
1316 TXNControlData data
[] = { { kTXNReadWrite
} } ;
1317 TXNSetTXNObjectControls( m_txn
, false , 1 , tag
, data
) ;
1322 TXNControlTag tag
[] = { kTXNIOPrivilegesTag
} ;
1323 if ( m_data
[0].uValue
== kTXNReadOnly
)
1325 TXNSetTXNObjectControls( m_txn
, false , 1 , tag
, m_data
) ;
1330 TXNControlData m_data
[1] ;
1333 wxString
wxMacMLTEControl::GetStringValue() const
1337 Size actualSize
= 0;
1341 err
= TXNGetDataEncoded( m_txn
, kTXNStartOffset
, kTXNEndOffset
, &theText
, kTXNUnicodeTextData
);
1349 actualSize
= GetHandleSize( theText
) / sizeof( UniChar
) ;
1350 if ( actualSize
> 0 )
1352 wxChar
*ptr
= NULL
;
1353 #if SIZEOF_WCHAR_T == 2
1354 ptr
= new wxChar
[actualSize
+ 1 ] ;
1355 wxStrncpy( ptr
, (wxChar
*) *theText
, actualSize
) ;
1358 SetHandleSize( theText
, ( actualSize
+ 1 ) * sizeof( UniChar
) ) ;
1360 (((UniChar
*)*theText
)[actualSize
]) = 0 ;
1361 wxMBConvUTF16BE converter
;
1362 size_t noChars
= converter
.MB2WC( NULL
, (const char*)*theText
, 0 ) ;
1363 ptr
= new wxChar
[noChars
+ 1] ;
1365 noChars
= converter
.MB2WC( ptr
, (const char*)*theText
, noChars
) ;
1367 HUnlock( theText
) ;
1369 ptr
[actualSize
] = 0 ;
1370 result
= wxString( ptr
) ;
1373 DisposeHandle( theText
) ;
1377 err
= TXNGetDataEncoded( m_txn
, kTXNStartOffset
, kTXNEndOffset
, &theText
, kTXNTextData
);
1385 actualSize
= GetHandleSize( theText
) ;
1386 if ( actualSize
> 0 )
1389 result
= wxString( *theText
, wxConvLocal
, actualSize
) ;
1390 HUnlock( theText
) ;
1392 DisposeHandle( theText
) ;
1397 wxMacConvertNewlines13To10( &result
) ;
1399 wxMacConvertNewlines10To13( &result
) ;
1404 void wxMacMLTEControl::SetStringValue( const wxString
&str
)
1408 wxMacConvertNewlines10To13( &st
) ;
1409 EditHelper
help(m_txn
) ;
1411 // wxMacWindowClipper c( this ) ;
1412 #if !TARGET_API_MAC_OSX
1413 // otherwise scrolling might have problems ?
1414 TPUpdateVisibility( m_controlRef
) ;
1416 SetTXNData( st
, kTXNStartOffset
, kTXNEndOffset
) ;
1417 TXNSetSelection( m_txn
, 0, 0);
1418 TXNShowSelection( m_txn
, kTXNShowStart
);
1421 TXNFrameOptions
wxMacMLTEControl::FrameOptionsFromWXStyle( long wxStyle
)
1423 TXNFrameOptions frameOptions
=
1424 kTXNDontDrawCaretWhenInactiveMask
;
1425 if ( ! ( wxStyle
& wxTE_NOHIDESEL
) )
1426 frameOptions
|= kTXNDontDrawSelectionWhenInactiveMask
;
1428 if ( wxStyle
& wxTE_MULTILINE
)
1430 if ( ! ( wxStyle
& wxTE_DONTWRAP
) )
1431 frameOptions
|= kTXNAlwaysWrapAtViewEdgeMask
;
1434 frameOptions
|= kTXNAlwaysWrapAtViewEdgeMask
;
1435 frameOptions
|= kTXNWantHScrollBarMask
;
1438 if ( !(wxStyle
& wxTE_NO_VSCROLL
) )
1439 frameOptions
|= kTXNWantVScrollBarMask
;
1442 frameOptions
|= kTXNSingleLineOnlyMask
;
1444 if ( wxStyle
& wxHSCROLL
)
1445 frameOptions
|= kTXNWantHScrollBarMask
;
1447 return frameOptions
;
1450 void wxMacMLTEControl::AdjustCreationAttributes( const wxColour
&background
, bool visible
)
1452 TXNControlTag iControlTags
[3] = { kTXNDoFontSubstitution
, kTXNWordWrapStateTag
};
1453 TXNControlData iControlData
[3] = { {false}, {kTXNNoAutoWrap
} };
1455 #if TARGET_API_MAC_OSX
1456 iControlTags
[2] = kTXNVisibilityTag
;
1457 iControlData
[2].uValue
= visible
;
1461 if ( m_windowStyle
& wxTE_MULTILINE
)
1463 if (m_windowStyle
& wxTE_DONTWRAP
)
1464 iControlData
[1].uValue
= kTXNNoAutoWrap
;
1466 iControlData
[1].uValue
= kTXNAutoWrap
;
1469 verify_noerr( TXNSetTXNObjectControls( m_txn
, false, toptag
,
1470 iControlTags
, iControlData
)) ;
1472 // setting the default font
1478 GetThemeFont(kThemeSystemFont
, GetApplicationScript() , fontName
, &fontSize
, &fontStyle
) ;
1480 TXNTypeAttributes typeAttr
[] =
1482 { kTXNQDFontNameAttribute
, kTXNQDFontNameAttributeSize
, { (void*) fontName
} } ,
1483 { kTXNQDFontSizeAttribute
, kTXNFontSizeAttributeSize
, { (void*) (fontSize
<< 16) } } ,
1484 { kTXNQDFontStyleAttribute
, kTXNQDFontStyleAttributeSize
, { (void*) normal
} } ,
1487 verify_noerr( TXNSetTypeAttributes (m_txn
, sizeof( typeAttr
) / sizeof(TXNTypeAttributes
) , typeAttr
,
1491 if ( m_windowStyle
& wxTE_PASSWORD
)
1494 verify_noerr(TXNEchoMode( m_txn
, c
, 0 , true )) ;
1497 TXNBackground tback
;
1498 tback
.bgType
= kTXNBackgroundTypeRGB
;
1499 tback
.bg
.color
= MAC_WXCOLORREF( background
.GetPixel() );
1500 TXNSetBackground( m_txn
, &tback
);
1503 void wxMacMLTEControl::SetBackground( const wxBrush
&brush
)
1505 // currently only solid background are supported
1506 TXNBackground tback
;
1507 tback
.bgType
= kTXNBackgroundTypeRGB
;
1508 tback
.bg
.color
= MAC_WXCOLORREF( brush
.GetColour().GetPixel() );
1509 TXNSetBackground( m_txn
, &tback
);
1512 void wxMacMLTEControl::TXNSetAttribute( const wxTextAttr
& style
, long from
, long to
)
1514 TXNTypeAttributes typeAttr
[4] ;
1515 Str255 fontName
= "\pMonaco" ;
1516 SInt16 fontSize
= 12 ;
1517 Style fontStyle
= normal
;
1519 int attrCounter
= 0 ;
1520 if ( style
.HasFont() )
1522 const wxFont
&font
= style
.GetFont() ;
1523 wxMacStringToPascal( font
.GetFaceName() , fontName
) ;
1524 fontSize
= font
.GetPointSize() ;
1525 if ( font
.GetUnderlined() )
1526 fontStyle
|= underline
;
1527 if ( font
.GetWeight() == wxBOLD
)
1529 if ( font
.GetStyle() == wxITALIC
)
1530 fontStyle
|= italic
;
1532 typeAttr
[attrCounter
].tag
= kTXNQDFontNameAttribute
;
1533 typeAttr
[attrCounter
].size
= kTXNQDFontNameAttributeSize
;
1534 typeAttr
[attrCounter
].data
.dataPtr
= (void*) fontName
;
1535 typeAttr
[attrCounter
+1].tag
= kTXNQDFontSizeAttribute
;
1536 typeAttr
[attrCounter
+1].size
= kTXNFontSizeAttributeSize
;
1537 typeAttr
[attrCounter
+1].data
.dataValue
= (fontSize
<< 16) ;
1538 typeAttr
[attrCounter
+2].tag
= kTXNQDFontStyleAttribute
;
1539 typeAttr
[attrCounter
+2].size
= kTXNQDFontStyleAttributeSize
;
1540 typeAttr
[attrCounter
+2].data
.dataValue
= fontStyle
;
1543 if ( style
.HasTextColour() )
1545 typeAttr
[attrCounter
].tag
= kTXNQDFontColorAttribute
;
1546 typeAttr
[attrCounter
].size
= kTXNQDFontColorAttributeSize
;
1547 typeAttr
[attrCounter
].data
.dataPtr
= (void*) &color
;
1548 color
= MAC_WXCOLORREF(style
.GetTextColour().GetPixel()) ;
1551 if ( attrCounter
> 0 )
1553 verify_noerr( TXNSetTypeAttributes ( m_txn
, attrCounter
, typeAttr
, from
, to
) );
1557 void wxMacMLTEControl::SetFont( const wxFont
& font
, const wxColour
& foreground
, long windowStyle
)
1559 EditHelper
help(m_txn
) ;
1560 TXNSetAttribute( wxTextAttr(foreground
,wxNullColour
,font
) , kTXNStartOffset
,kTXNEndOffset
) ;
1562 void wxMacMLTEControl::SetStyle(long start
, long end
, const wxTextAttr
& style
)
1564 EditHelper
help(m_txn
) ;
1565 TXNSetAttribute( style
, start
,end
) ;
1568 void wxMacMLTEControl::Copy()
1570 ClearCurrentScrap();
1572 TXNConvertToPublicScrap();
1575 void wxMacMLTEControl::Cut()
1577 ClearCurrentScrap();
1579 TXNConvertToPublicScrap();
1582 void wxMacMLTEControl::Paste()
1584 TXNConvertFromPublicScrap();
1588 bool wxMacMLTEControl::CanPaste() const
1590 return TXNIsScrapPastable() ;
1593 void wxMacMLTEControl::SetEditable(bool editable
)
1595 TXNControlTag tag
[] = { kTXNIOPrivilegesTag
} ;
1596 TXNControlData data
[] = { { editable
? kTXNReadWrite
: kTXNReadOnly
} } ;
1597 TXNSetTXNObjectControls( m_txn
, false , sizeof(tag
) / sizeof (TXNControlTag
) , tag
, data
) ;
1600 long wxMacMLTEControl::GetLastPosition() const
1602 long actualsize
= 0 ;
1605 OSErr err
= TXNGetDataEncoded( m_txn
, kTXNStartOffset
, kTXNEndOffset
, &theText
, kTXNTextData
);
1613 actualsize
= GetHandleSize( theText
) ;
1614 DisposeHandle( theText
) ;
1620 void wxMacMLTEControl::Replace( long from
, long to
, const wxString str
)
1622 wxString value
= str
;
1623 wxMacConvertNewlines10To13( &value
) ;
1625 EditHelper
help( m_txn
) ;
1627 TXNSetSelection(m_txn
, from
, to
) ;
1629 SetTXNData( value
, kTXNUseCurrentSelection
, kTXNUseCurrentSelection
) ;
1632 void wxMacMLTEControl::Remove( long from
, long to
)
1634 EditHelper
help( m_txn
) ;
1636 TXNSetSelection(m_txn
, from
, to
) ;
1640 void wxMacMLTEControl::GetSelection( long* from
, long* to
) const
1642 TXNGetSelection( m_txn
, (TXNOffset
*) from
, (TXNOffset
*) to
) ;
1645 void wxMacMLTEControl::SetSelection( long from
, long to
)
1647 /* change the selection */
1648 if ((from
== -1) && (to
== -1))
1649 TXNSelectAll(m_txn
);
1651 TXNSetSelection( m_txn
, from
, to
);
1652 TXNShowSelection( m_txn
, kTXNShowStart
);
1655 void wxMacMLTEControl::WriteText(const wxString
& str
)
1657 EditHelper
helper( m_txn
) ;
1659 wxMacConvertNewlines10To13( &st
) ;
1661 long start
, end
, dummy
;
1662 GetSelection( &start
, &dummy
) ;
1663 SetTXNData( st
, kTXNUseCurrentSelection
, kTXNUseCurrentSelection
) ;
1664 GetSelection( &dummy
, &end
) ;
1665 // TODO SetStyle( start , end , GetDefaultStyle() ) ;
1668 void wxMacMLTEControl::Clear()
1670 EditHelper
st(m_txn
) ;
1671 TXNSetSelection( m_txn
, kTXNStartOffset
, kTXNEndOffset
) ;
1675 bool wxMacMLTEControl::CanUndo() const
1677 return TXNCanUndo( m_txn
, NULL
) ;
1680 void wxMacMLTEControl::Undo()
1685 bool wxMacMLTEControl::CanRedo() const
1687 return TXNCanRedo( m_txn
, NULL
) ;
1690 void wxMacMLTEControl::Redo()
1695 int wxMacMLTEControl::GetNumberOfLines() const
1697 ItemCount lines
= 0 ;
1698 TXNGetLineCount(m_txn
, &lines
) ;
1702 long wxMacMLTEControl::XYToPosition(long x
, long y
) const
1706 long lastpos
= GetLastPosition() ;
1708 // TODO find a better implementation : while we can get the
1709 // line metrics of a certain line, we don't get its starting
1710 // position, so it would probably be rather a binary search
1711 // for the start position
1714 int lastHeight
= 0 ;
1717 for ( n
= 0 ; n
<= (ItemCount
) lastpos
; ++n
)
1719 if ( y
== ypos
&& x
== xpos
)
1722 TXNOffsetToPoint( m_txn
, n
, &curpt
);
1724 if ( curpt
.v
> lastHeight
)
1729 lastHeight
= curpt
.v
;
1737 bool wxMacMLTEControl::PositionToXY(long pos
, long *x
, long *y
) const
1741 long lastpos
= GetLastPosition() ;
1746 if ( pos
<= lastpos
)
1748 // TODO find a better implementation : while we can get the
1749 // line metrics of a certain line, we don't get its starting
1750 // position, so it would probably be rather a binary search
1751 // for the start position
1754 int lastHeight
= 0 ;
1757 for ( n
= 0 ; n
<= (ItemCount
) pos
; ++n
)
1759 TXNOffsetToPoint(m_txn
, n
, &curpt
);
1761 if ( curpt
.v
> lastHeight
)
1766 lastHeight
= curpt
.v
;
1771 if ( y
) *y
= ypos
;
1772 if ( x
) *x
= xpos
;
1778 void wxMacMLTEControl::ShowPosition( long pos
)
1780 #if TARGET_RT_MAC_MACHO && defined(AVAILABLE_MAC_OS_X_VERSION_10_2_AND_LATER)
1784 TXNOffset selstart
, selend
;
1785 TXNGetSelection( m_txn
, &selstart
, &selend
) ;
1786 TXNOffsetToPoint( m_txn
, selstart
, ¤t
);
1787 TXNOffsetToPoint( m_txn
, pos
, &desired
);
1788 //TODO use HIPoints for 10.3 and above
1789 if ( (UInt32
) TXNScroll
!= (UInt32
) kUnresolvedCFragSymbolAddress
)
1791 OSErr theErr
= noErr
;
1792 SInt32 dv
= desired
.v
- current
.v
;
1793 SInt32 dh
= desired
.h
- current
.h
;
1794 TXNShowSelection( m_txn
, true ) ;
1795 theErr
= TXNScroll( m_txn
, kTXNScrollUnitsInPixels
, kTXNScrollUnitsInPixels
, &dv
, &dh
);
1796 wxASSERT_MSG( theErr
== noErr
, _T("TXNScroll returned an error!") );
1802 void wxMacMLTEControl::SetTXNData( const wxString
& st
, TXNOffset start
, TXNOffset end
)
1805 #if SIZEOF_WCHAR_T == 2
1806 size_t len
= st
.Len() ;
1807 TXNSetData( m_txn
, kTXNUnicodeTextData
, (void*)st
.wc_str(), len
* 2,
1810 wxMBConvUTF16BE converter
;
1811 ByteCount byteBufferLen
= converter
.WC2MB( NULL
, st
.wc_str() , 0 ) ;
1812 UniChar
*unibuf
= (UniChar
*) malloc(byteBufferLen
) ;
1813 converter
.WC2MB( (char*) unibuf
, st
.wc_str() , byteBufferLen
) ;
1814 TXNSetData( m_txn
, kTXNUnicodeTextData
, (void*)unibuf
, byteBufferLen
,
1819 wxCharBuffer text
= st
.mb_str(wxConvLocal
) ;
1820 TXNSetData( m_txn
, kTXNTextData
, (void*)text
.data(), strlen( text
) ,
1826 wxString
wxMacMLTEControl::GetLineText(long lineNo
) const
1830 if ( lineNo
< GetNumberOfLines() )
1838 // get the first possible position in the control
1840 TXNOffsetToPoint(m_txn
, 0, &firstPoint
);
1842 // Iterate through the lines until we reach the one we want,
1843 // adding to our current y pixel point position
1844 while (ypos
< lineNo
)
1846 TXNGetLineMetrics(m_txn
, ypos
++, &lineWidth
, &lineHeight
);
1847 currentHeight
+= lineHeight
;
1850 Point thePoint
= { firstPoint
.v
+ (currentHeight
>> 16), firstPoint
.h
+ (0) };
1851 TXNOffset theOffset
;
1852 TXNPointToOffset(m_txn
, thePoint
, &theOffset
);
1854 wxString content
= GetStringValue() ;
1855 Point currentPoint
= thePoint
;
1856 while(thePoint
.v
== currentPoint
.v
&& theOffset
< content
.length())
1858 line
+= content
[theOffset
];
1859 TXNOffsetToPoint(m_txn
, ++theOffset
, ¤tPoint
);
1865 int wxMacMLTEControl::GetLineLength(long lineNo
) const
1869 if ( lineNo
< GetNumberOfLines() )
1877 // get the first possible position in the control
1879 TXNOffsetToPoint(m_txn
, 0, &firstPoint
);
1881 // Iterate through the lines until we reach the one we want,
1882 // adding to our current y pixel point position
1883 while (ypos
< lineNo
)
1885 TXNGetLineMetrics(m_txn
, ypos
++, &lineWidth
, &lineHeight
);
1886 currentHeight
+= lineHeight
;
1889 Point thePoint
= { firstPoint
.v
+ (currentHeight
>> 16), firstPoint
.h
+ (0) };
1890 TXNOffset theOffset
;
1891 TXNPointToOffset(m_txn
, thePoint
, &theOffset
);
1893 wxString content
= GetStringValue() ;
1894 Point currentPoint
= thePoint
;
1895 while(thePoint
.v
== currentPoint
.v
&& theOffset
< content
.length())
1898 TXNOffsetToPoint(m_txn
, ++theOffset
, ¤tPoint
);
1905 // ----------------------------------------------------------------------------
1906 // MLTE control implementation (classic part)
1907 // ----------------------------------------------------------------------------
1909 // CS:TODO we still have a problem getting properly at the text events of a control because under Carbon
1910 // the MLTE engine registers itself for the key events thus the normal flow never occurs, the only measure for the
1911 // moment is to avoid setting the true focus on the control, the proper solution at the end would be to have
1912 // an alternate path for carbon key events that routes automatically into the same wx flow of events
1916 /* kmUPTextPart is the part code we return to indicate the user has clicked
1917 in the text area of our control */
1918 #define kmUPTextPart 1
1921 /* routines for using existing user pane controls.
1922 These routines are useful for cases where you would like to use an
1923 existing user pane control in, say, a dialog window as a scrolling
1926 /* Utility Routines */
1928 /* kUserClickedToFocusPart is a part code we pass to the SetKeyboardFocus
1929 routine. In our focus switching routine this part code is understood
1930 as meaning 'the user has clicked in the control and we need to switch
1931 the current focus to ourselves before we can continue'. */
1932 #define kUserClickedToFocusPart 100
1934 /* STPTextPaneVars is a structure used for storing the the mUP Control's
1935 internal variables and state information. A handle to this record is
1936 stored in the pane control's reference value field using the
1937 SetControlReference routine. */
1939 class STPTextPaneVars
{
1941 /* OS records referenced */
1942 TXNObject fTXNRec
; /* the txn record */
1943 TXNFrameID fTXNFrame
; /* the txn frame ID */
1944 ControlRef fUserPaneRec
; /* handle to the user pane control */
1945 WindowPtr fOwner
; /* window containing control */
1946 GrafPtr fDrawingEnvironment
; /* grafport where control is drawn */
1948 Boolean fInFocus
; /* true while the focus rect is drawn around the control */
1949 Boolean fIsActive
; /* true while the control is drawn in the active state */
1950 Boolean fTXNObjectActive
; /* reflects the activation state of the text edit record */
1951 Boolean fFocusDrawState
; /* true if focus is drawn (default: true) */
1952 /* calculated locations */
1953 Rect fRBounds
; /* control bounds */
1954 Rect fRTextArea
; /* area where the text is drawn */
1955 Rect fRFocusOutline
; /* rectangle used to draw the focus box */
1956 Rect fRTextOutline
; /* rectangle used to draw the border */
1957 RgnHandle fRTextOutlineRegion
; /* background region for the text, erased before calling TEUpdate */
1958 /* our focus advance override routine */
1959 EventHandlerUPP handlerUPP
;
1960 EventHandlerRef handlerRef
;
1966 /* Univerals Procedure Pointer variables used by the
1967 mUP Control. These variables are set up
1968 the first time that mUPOpenControl is called. */
1969 ControlUserPaneDrawUPP gTPDrawProc
= NULL
;
1970 ControlUserPaneHitTestUPP gTPHitProc
= NULL
;
1971 ControlUserPaneTrackingUPP gTPTrackProc
= NULL
;
1972 ControlUserPaneIdleUPP gTPIdleProc
= NULL
;
1973 ControlUserPaneKeyDownUPP gTPKeyProc
= NULL
;
1974 ControlUserPaneActivateUPP gTPActivateProc
= NULL
;
1975 ControlUserPaneFocusUPP gTPFocusProc
= NULL
;
1977 // one place for calculating all
1978 static void TPCalculateBounds(STPTextPaneVars
*varsp
, const Rect
& bounds
)
1980 SetRect(&varsp
->fRBounds
, bounds
.left
, bounds
.top
, bounds
.right
, bounds
.bottom
);
1981 SetRect(&varsp
->fRFocusOutline
, bounds
.left
, bounds
.top
, bounds
.right
, bounds
.bottom
);
1982 // eventually make TextOutline inset 1,1
1983 SetRect(&varsp
->fRTextOutline
, bounds
.left
, bounds
.top
, bounds
.right
, bounds
.bottom
);
1984 if ( !varsp
->fNoBorders
)
1986 SetRect(&varsp
->fRTextArea
, bounds
.left
+ 2 , bounds
.top
+ (varsp
->fMultiline
? 0 : 2) ,
1987 bounds
.right
- (varsp
->fMultiline
? 0 : 2), bounds
.bottom
- (varsp
->fMultiline
? 0 : 2));
1991 SetRect(&varsp
->fRTextArea
, bounds
.left
, bounds
.top
,
1992 bounds
.right
, bounds
.bottom
);
1996 OSStatus
MLTESetObjectVisibility( STPTextPaneVars
*varsp
, Boolean vis
, long wxStyle
)
1998 OSStatus err
= noErr
;
1999 wxTextCtrl
* textctrl
= (wxTextCtrl
*) GetControlReference(varsp
->fUserPaneRec
);
2002 #if TARGET_API_MAC_OSX
2003 TXNControlTag iControlTags
[1] = { kTXNVisibilityTag
};
2004 TXNControlData iControlData
[1] = {{ vis
}};
2005 err
= ::TXNSetTXNObjectControls( varsp
->fTXNRec
, false, 1, iControlTags
, iControlData
);
2008 UMAGetControlBoundsInWindowCoords( varsp
->fUserPaneRec
, &bounds
);
2009 TPCalculateBounds( varsp
, bounds
) ;
2012 wxMacWindowClipper
cl(textctrl
) ;
2013 TXNSetFrameBounds( varsp
->fTXNRec
, varsp
->fRTextArea
.top
, varsp
->fRTextArea
.left
,
2014 varsp
->fRTextArea
.bottom
, varsp
->fRTextArea
.right
, varsp
->fTXNFrame
);
2015 TXNShowSelection( varsp
->fTXNRec
, kTXNShowStart
);
2019 #if TARGET_API_MAC_OSX
2020 // in 10.2 the scrollbars are still actively redrawn when using only the code above
2021 if ( UMAGetSystemVersion() < 0x1030 )
2023 TXNSetFrameBounds( varsp
->fTXNRec
, varsp
->fRTextArea
.top
+ 20000 , varsp
->fRTextArea
.left
+ 20000 ,
2024 varsp
->fRTextArea
.bottom
+ 20000 , varsp
->fRTextArea
.right
+ 20000 , varsp
->fTXNFrame
);
2033 // make sure we don't miss changes as carbon events are not available for these under classic
2034 static void TPUpdateVisibility(ControlRef theControl
) {
2035 wxTextCtrl
* textctrl
= (wxTextCtrl
*) GetControlReference(theControl
);
2036 if ( textctrl
== NULL
)
2039 STPTextPaneVars
*varsp
= (STPTextPaneVars
*) ((wxMacMLTEClassicControl
*)textctrl
->GetPeer())->m_macTXNvars
;
2042 UMAGetControlBoundsInWindowCoords(theControl
, &bounds
);
2043 if ( textctrl
->MacIsReallyShown() != varsp
->fVisible
)
2045 // invalidate old position
2046 // InvalWindowRect( GetControlOwner( theControl ) , &varsp->fRBounds ) ;
2047 varsp
->fVisible
= textctrl
->MacIsReallyShown() ;
2049 if ( !EqualRect( &bounds
, &varsp
->fRBounds
) )
2052 Rect oldBounds
= varsp
->fRBounds
;
2053 TPCalculateBounds( varsp
, bounds
) ;
2054 // we only recalculate when visible, otherwise scrollbars get drawn at incorrect places
2055 if ( varsp
->fVisible
)
2057 wxMacWindowClipper
cl(textctrl
) ;
2058 TXNSetFrameBounds( varsp
->fTXNRec
, varsp
->fRTextArea
.top
, varsp
->fRTextArea
.left
,
2059 varsp
->fRTextArea
.bottom
, varsp
->fRTextArea
.right
, varsp
->fTXNFrame
);
2061 InvalWindowRect( GetControlOwner( theControl
) , &oldBounds
) ;
2062 InvalWindowRect( GetControlOwner( theControl
) , &varsp
->fRBounds
) ;
2066 // make correct activations
2067 static void TPActivatePaneText(STPTextPaneVars
*varsp
, Boolean setActive
) {
2069 wxTextCtrl
* textctrl
= (wxTextCtrl
*) GetControlReference(varsp
->fUserPaneRec
);
2070 if (varsp
->fTXNObjectActive
!= setActive
&& textctrl
->MacIsReallyShown() )
2072 varsp
->fTXNObjectActive
= setActive
;
2073 TXNActivate(varsp
->fTXNRec
, varsp
->fTXNFrame
, varsp
->fTXNObjectActive
);
2074 if (varsp
->fInFocus
)
2075 TXNFocus( varsp
->fTXNRec
, varsp
->fTXNObjectActive
);
2079 // update focus outlines
2080 static void TPRedrawFocusOutline(STPTextPaneVars
*varsp
) {
2083 if (varsp
->fFocusDrawState
!= (varsp
->fIsActive
&& varsp
->fInFocus
))
2085 varsp
->fFocusDrawState
= (varsp
->fIsActive
&& varsp
->fInFocus
);
2086 // DrawThemeFocusRect(&varsp->fRFocusOutline, varsp->fFocusDrawState);
2090 // update TXN focus state
2091 static void TPFocusPaneText(STPTextPaneVars
*varsp
, Boolean setFocus
) {
2092 wxTextCtrl
* textctrl
= (wxTextCtrl
*) GetControlReference(varsp
->fUserPaneRec
);
2094 if (varsp
->fInFocus
!= setFocus
&& textctrl
->MacIsReallyShown()) {
2095 varsp
->fInFocus
= setFocus
;
2096 TXNFocus( varsp
->fTXNRec
, varsp
->fInFocus
);
2101 static pascal void TPPaneDrawProc(ControlRef theControl
, ControlPartCode thePart
) {
2102 /* set up our globals */
2104 wxTextCtrl
* textctrl
= (wxTextCtrl
*) GetControlReference(theControl
);
2105 if ( textctrl
== NULL
)
2107 TPUpdateVisibility( theControl
) ;
2109 STPTextPaneVars
*varsp
= (STPTextPaneVars
*) ((wxMacMLTEClassicControl
*)textctrl
->GetPeer())->m_macTXNvars
;
2110 if ( textctrl
->MacIsReallyShown() )
2112 wxMacWindowClipper
clipper( textctrl
) ;
2113 TXNDraw(varsp
->fTXNRec
, NULL
);
2114 if ( !varsp
->fNoBorders
)
2115 DrawThemeEditTextFrame(&varsp
->fRTextOutline
, varsp
->fIsActive
? kThemeStateActive
: kThemeStateInactive
);
2116 TPRedrawFocusOutline( varsp
) ;
2122 /* TPPaneHitTestProc is called when the control manager would
2123 like to determine what part of the control the mouse resides over.
2124 We also call this routine from our tracking proc to determine how
2125 to handle mouse clicks. */
2126 static pascal ControlPartCode
TPPaneHitTestProc(ControlRef theControl
, Point where
) {
2127 ControlPartCode result
;
2128 /* set up our locals and lock down our globals*/
2130 wxTextCtrl
* textctrl
= (wxTextCtrl
*) GetControlReference(theControl
);
2131 if ( textctrl
== NULL
)
2133 TPUpdateVisibility( theControl
) ;
2134 STPTextPaneVars
*varsp
= (STPTextPaneVars
*) ((wxMacMLTEClassicControl
*)textctrl
->GetPeer())->m_macTXNvars
;
2135 if (textctrl
->MacIsReallyShown() )
2137 if (PtInRect(where
, &varsp
->fRBounds
))
2138 result
= kmUPTextPart
;
2141 // sometimes we get the coords also in control local coordinates, therefore test again
2142 if ( textctrl
->MacGetTopLevelWindow()->MacUsesCompositing() )
2145 textctrl
->MacClientToRootWindow( &x
, &y
) ;
2149 if (PtInRect(where
, &varsp
->fRBounds
))
2150 result
= kmUPTextPart
;
2162 /* TPPaneTrackingProc is called when the mouse is being held down
2163 over our control. This routine handles clicks in the text area
2164 and in the scroll bar. */
2165 static pascal ControlPartCode
TPPaneTrackingProc(ControlRef theControl
, Point startPt
, ControlActionUPP actionProc
) {
2167 ControlPartCode partCodeResult
;
2168 /* make sure we have some variables... */
2170 wxTextCtrl
* textctrl
= (wxTextCtrl
*) GetControlReference(theControl
);
2171 if ( textctrl
== NULL
)
2173 TPUpdateVisibility( theControl
) ;
2174 STPTextPaneVars
*varsp
= (STPTextPaneVars
*) ((wxMacMLTEClassicControl
*)textctrl
->GetPeer())->m_macTXNvars
;
2175 if (textctrl
->MacIsReallyShown() )
2177 /* we don't do any of these functions unless we're in focus */
2178 if ( ! varsp
->fInFocus
) {
2180 owner
= GetControlOwner(theControl
);
2181 ClearKeyboardFocus(owner
);
2182 SetKeyboardFocus(owner
, theControl
, kUserClickedToFocusPart
);
2184 /* find the location for the click */
2185 // for compositing, we must convert these into toplevel window coordinates, because hittesting expects them
2186 if ( textctrl
->MacGetTopLevelWindow()->MacUsesCompositing() )
2189 textctrl
->MacClientToRootWindow( &x
, &y
) ;
2194 switch (TPPaneHitTestProc(theControl
, startPt
))
2197 /* handle clicks in the text part */
2200 wxMacWindowClipper
clipper( textctrl
) ;
2203 ConvertEventRefToEventRecord( (EventRef
) wxTheApp
->MacGetCurrentEvent() , &rec
) ;
2204 TXNClick( varsp
->fTXNRec
, &rec
);
2211 return partCodeResult
;
2215 /* TPPaneIdleProc is our user pane idle routine. When our text field
2216 is active and in focus, we use this routine to set the cursor. */
2217 static pascal void TPPaneIdleProc(ControlRef theControl
) {
2219 wxTextCtrl
* textctrl
= (wxTextCtrl
*) GetControlReference(theControl
);
2220 if ( textctrl
== NULL
)
2222 TPUpdateVisibility( theControl
) ;
2223 STPTextPaneVars
*varsp
= (STPTextPaneVars
*) ((wxMacMLTEClassicControl
*)textctrl
->GetPeer())->m_macTXNvars
;
2224 if (textctrl
->MacIsReallyShown()) {
2225 /* if we're not active, then we have nothing to say about the cursor */
2226 if (varsp
->fIsActive
) {
2230 wxMacWindowClipper
clipper( textctrl
) ;
2232 /* there's a 'focus thing' and an 'unfocused thing' */
2233 if (varsp
->fInFocus
) {
2234 /* flash the cursor */
2235 SetPort(varsp
->fDrawingEnvironment
);
2236 TXNIdle(varsp
->fTXNRec
);
2237 /* set the cursor */
2238 if (PtInRect(mousep
, &varsp
->fRTextArea
)) {
2240 RectRgn((theRgn
= NewRgn()), &varsp
->fRTextArea
);
2241 TXNAdjustCursor(varsp
->fTXNRec
, theRgn
);
2246 // SetThemeCursor(kThemeArrowCursor);
2249 /* if it's in our bounds, set the cursor */
2250 UMAGetControlBoundsInWindowCoords(theControl
, &bounds
);
2251 if (PtInRect(mousep
, &bounds
))
2253 // SetThemeCursor(kThemeArrowCursor);
2261 /* TPPaneKeyDownProc is called whenever a keydown event is directed
2262 at our control. Here, we direct the keydown event to the text
2263 edit record and redraw the scroll bar and text field as appropriate. */
2264 static pascal ControlPartCode
TPPaneKeyDownProc(ControlRef theControl
,
2265 SInt16 keyCode
, SInt16 charCode
, SInt16 modifiers
) {
2267 wxTextCtrl
* textctrl
= (wxTextCtrl
*) GetControlReference(theControl
);
2268 if ( textctrl
== NULL
)
2270 TPUpdateVisibility( theControl
) ;
2272 STPTextPaneVars
*varsp
= (STPTextPaneVars
*) ((wxMacMLTEClassicControl
*)textctrl
->GetPeer())->m_macTXNvars
;
2273 if (varsp
->fInFocus
)
2275 /* turn autoscrolling on and send the key event to text edit */
2276 wxMacWindowClipper
clipper( textctrl
) ;
2278 memset( &ev
, 0 , sizeof( ev
) ) ;
2280 ev
.modifiers
= modifiers
;
2281 ev
.message
= (( keyCode
<< 8 ) & keyCodeMask
) + ( charCode
& charCodeMask
) ;
2282 TXNKeyDown( varsp
->fTXNRec
, &ev
);
2284 return kControlEntireControl
;
2288 /* TPPaneActivateProc is called when the window containing
2289 the user pane control receives activate events. Here, we redraw
2290 the control and it's text as necessary for the activation state. */
2291 static pascal void TPPaneActivateProc(ControlRef theControl
, Boolean activating
) {
2293 wxTextCtrl
* textctrl
= (wxTextCtrl
*) GetControlReference(theControl
);
2295 if ( textctrl
== NULL
)
2297 TPUpdateVisibility( theControl
) ;
2299 STPTextPaneVars
*varsp
= (STPTextPaneVars
*) ((wxMacMLTEClassicControl
*)textctrl
->GetPeer())->m_macTXNvars
;
2301 varsp
->fIsActive
= activating
;
2302 wxMacWindowClipper
clipper( textctrl
) ;
2303 TPActivatePaneText(varsp
, varsp
->fIsActive
&& varsp
->fInFocus
);
2304 /* redraw the frame */
2305 if ( textctrl
->MacIsReallyShown() )
2307 if ( !varsp
->fNoBorders
)
2308 DrawThemeEditTextFrame(&varsp
->fRTextOutline
, varsp
->fIsActive
? kThemeStateActive
: kThemeStateInactive
);
2309 TPRedrawFocusOutline( varsp
) ;
2314 /* TPPaneFocusProc is called when every the focus changes to or
2315 from our control. Herein, switch the focus appropriately
2316 according to the parameters and redraw the control as
2318 static pascal ControlPartCode
TPPaneFocusProc(ControlRef theControl
, ControlFocusPart action
) {
2319 ControlPartCode focusResult
;
2321 focusResult
= kControlFocusNoPart
;
2322 wxTextCtrl
* textctrl
= (wxTextCtrl
*) GetControlReference(theControl
);
2323 if ( textctrl
== NULL
)
2325 TPUpdateVisibility( theControl
) ;
2326 STPTextPaneVars
*varsp
= (STPTextPaneVars
*) ((wxMacMLTEClassicControl
*)textctrl
->GetPeer())->m_macTXNvars
;
2327 /* if kControlFocusPrevPart and kControlFocusNextPart are received when the user is
2328 tabbing forwards (or shift tabbing backwards) through the items in the dialog,
2329 and kControlFocusNextPart will be received. When the user clicks in our field
2330 and it is not the current focus, then the constant kUserClickedToFocusPart will
2331 be received. The constant kControlFocusNoPart will be received when our control
2332 is the current focus and the user clicks in another control. In your focus routine,
2333 you should respond to these codes as follows:
2335 kControlFocusNoPart - turn off focus and return kControlFocusNoPart. redraw
2336 the control and the focus rectangle as necessary.
2338 kControlFocusPrevPart or kControlFocusNextPart - toggle focus on or off
2339 depending on its current state. redraw the control and the focus rectangle
2340 as appropriate for the new focus state. If the focus state is 'off', return the constant
2341 kControlFocusNoPart, otherwise return a non-zero part code.
2342 kUserClickedToFocusPart - is a constant defined for this example. You should
2343 define your own value for handling click-to-focus type events. */
2344 /* calculate the next highlight state */
2347 case kControlFocusNoPart
:
2348 TPFocusPaneText(varsp
, false);
2349 focusResult
= kControlFocusNoPart
;
2351 case kUserClickedToFocusPart
:
2352 TPFocusPaneText(varsp
, true);
2355 case kControlFocusPrevPart
:
2356 case kControlFocusNextPart
:
2357 TPFocusPaneText(varsp
, ( ! varsp
->fInFocus
));
2358 focusResult
= varsp
->fInFocus
? 1 : kControlFocusNoPart
;
2361 TPActivatePaneText(varsp
, varsp
->fIsActive
&& varsp
->fInFocus
);
2362 /* redraw the text fram and focus rectangle to indicate the
2364 if ( textctrl
->MacIsReallyShown() )
2366 wxMacWindowClipper
c( textctrl
) ;
2367 if ( !varsp
->fNoBorders
)
2368 DrawThemeEditTextFrame(&varsp
->fRTextOutline
, varsp
->fIsActive
? kThemeStateActive
: kThemeStateInactive
);
2369 TPRedrawFocusOutline( varsp
) ;
2374 wxMacMLTEClassicControl::wxMacMLTEClassicControl( wxWindow
*wxPeer
,
2375 const wxString
& str
,
2377 const wxSize
& size
, long style
)
2379 m_font
= wxPeer
->GetFont() ;
2380 m_windowStyle
= style
;
2381 Rect bounds
= wxMacGetBoundsForControl( wxPeer
, pos
, size
) ;
2383 wxMacConvertNewlines10To13( &st
) ;
2387 featurSet
= kControlSupportsEmbedding
| kControlSupportsFocus
| kControlWantsIdle
2388 | kControlWantsActivate
| kControlHandlesTracking
| kControlHasSpecialBackground
2389 | kControlGetsFocusOnClick
| kControlSupportsLiveFeedback
;
2390 /* create the control */
2392 verify_noerr( ::CreateUserPaneControl( MAC_WXHWND(wxPeer
->GetParent()->MacGetTopLevelWindowRef()), &bounds
, featurSet
, &m_controlRef
) );
2395 // wxMacWindowClipper c(wxPeer) ;
2399 if ( wxPeer
->MacIsReallyShown() )
2400 MLTESetObjectVisibility( (STPTextPaneVars
*) m_macTXNvars
, true , style
) ;
2403 // wxMacWindowClipper clipper( wxPeer ) ;
2405 TPUpdateVisibility( m_controlRef
) ;
2407 SetTXNData( st
, kTXNStartOffset
, kTXNEndOffset
) ;
2409 TXNSetSelection( m_txn
, 0, 0);
2410 TXNShowSelection( m_txn
, kTXNShowStart
);
2413 AdjustCreationAttributes( *wxWHITE
, true ) ;
2416 wxMacMLTEClassicControl::~wxMacMLTEClassicControl()
2418 // SetControlReference(m_controlRef , 0) ;
2419 TXNDeleteObject(m_txn
);
2423 void wxMacMLTEClassicControl::VisibilityChanged(bool shown
)
2425 MLTESetObjectVisibility((STPTextPaneVars
*) m_macTXNvars
, shown
, m_windowStyle
) ;
2427 InvalWindowRect( GetControlOwner( m_controlRef
) , &((STPTextPaneVars
*)m_macTXNvars
)->fRBounds
) ;
2430 bool wxMacMLTEClassicControl::NeedsFocusRect() const
2435 OSStatus
wxMacMLTEClassicControl::DoCreate()
2438 WindowRef theWindow
;
2440 OSStatus err
= noErr
;
2442 /* set up our globals */
2443 if (gTPDrawProc
== NULL
) gTPDrawProc
= NewControlUserPaneDrawUPP(TPPaneDrawProc
);
2444 if (gTPHitProc
== NULL
) gTPHitProc
= NewControlUserPaneHitTestUPP(TPPaneHitTestProc
);
2445 if (gTPTrackProc
== NULL
) gTPTrackProc
= NewControlUserPaneTrackingUPP(TPPaneTrackingProc
);
2446 if (gTPIdleProc
== NULL
) gTPIdleProc
= NewControlUserPaneIdleUPP(TPPaneIdleProc
);
2447 if (gTPKeyProc
== NULL
) gTPKeyProc
= NewControlUserPaneKeyDownUPP(TPPaneKeyDownProc
);
2448 if (gTPActivateProc
== NULL
) gTPActivateProc
= NewControlUserPaneActivateUPP(TPPaneActivateProc
);
2449 if (gTPFocusProc
== NULL
) gTPFocusProc
= NewControlUserPaneFocusUPP(TPPaneFocusProc
);
2451 /* allocate our private storage */
2452 m_macTXNvars
= (STPTextPaneVars
*) malloc(sizeof(STPTextPaneVars
));
2454 /* set the initial settings for our private data */
2455 m_macTXNvars
->fMultiline
= m_windowStyle
& wxTE_MULTILINE
;
2456 m_macTXNvars
->fNoBorders
= m_windowStyle
& wxNO_BORDER
;
2457 m_macTXNvars
->fInFocus
= false;
2458 m_macTXNvars
->fIsActive
= true;
2459 m_macTXNvars
->fTXNObjectActive
= false;
2460 m_macTXNvars
->fFocusDrawState
= false ;
2461 m_macTXNvars
->fUserPaneRec
= m_controlRef
;
2462 m_macTXNvars
->fVisible
= true ;
2464 theWindow
= m_macTXNvars
->fOwner
= GetControlOwner(m_controlRef
);
2466 m_macTXNvars
->fDrawingEnvironment
= (GrafPtr
) GetWindowPort(theWindow
);
2468 /* set up the user pane procedures */
2469 SetControlData(m_controlRef
, kControlEntireControl
, kControlUserPaneDrawProcTag
, sizeof(gTPDrawProc
), &gTPDrawProc
);
2470 SetControlData(m_controlRef
, kControlEntireControl
, kControlUserPaneHitTestProcTag
, sizeof(gTPHitProc
), &gTPHitProc
);
2471 SetControlData(m_controlRef
, kControlEntireControl
, kControlUserPaneTrackingProcTag
, sizeof(gTPTrackProc
), &gTPTrackProc
);
2472 SetControlData(m_controlRef
, kControlEntireControl
, kControlUserPaneIdleProcTag
, sizeof(gTPIdleProc
), &gTPIdleProc
);
2473 SetControlData(m_controlRef
, kControlEntireControl
, kControlUserPaneKeyDownProcTag
, sizeof(gTPKeyProc
), &gTPKeyProc
);
2474 SetControlData(m_controlRef
, kControlEntireControl
, kControlUserPaneActivateProcTag
, sizeof(gTPActivateProc
), &gTPActivateProc
);
2475 SetControlData(m_controlRef
, kControlEntireControl
, kControlUserPaneFocusProcTag
, sizeof(gTPFocusProc
), &gTPFocusProc
);
2477 /* calculate the rectangles used by the control */
2478 UMAGetControlBoundsInWindowCoords(m_controlRef
, &bounds
);
2479 m_macTXNvars
->fRTextOutlineRegion
= NewRgn() ;
2480 TPCalculateBounds( m_macTXNvars
, bounds
) ;
2482 /* set up the drawing environment */
2483 SetPort(m_macTXNvars
->fDrawingEnvironment
);
2485 /* create the new edit field */
2487 TXNFrameOptions frameOptions
= FrameOptionsFromWXStyle( m_windowStyle
) ;
2489 verify_noerr(TXNNewObject(NULL
, m_macTXNvars
->fOwner
, &m_macTXNvars
->fRTextArea
,
2491 kTXNTextEditStyleFrameType
,
2493 kTXNSystemDefaultEncoding
,
2494 &m_macTXNvars
->fTXNRec
, &m_macTXNvars
->fTXNFrame
, (TXNObjectRefcon
) m_macTXNvars
));
2495 m_txn
= m_macTXNvars
->fTXNRec
;
2497 /* perform final activations and setup for our text field. Here,
2498 we assume that the window is going to be the 'active' window. */
2499 TPActivatePaneText(m_macTXNvars
, m_macTXNvars
->fIsActive
&& m_macTXNvars
->fInFocus
);
2504 // ----------------------------------------------------------------------------
2505 // MLTE control implementation (OSX part)
2506 // ----------------------------------------------------------------------------
2508 #if TARGET_API_MAC_OSX
2510 #if MAC_OS_X_VERSION_MAX_ALLOWED > MAC_OS_X_VERSION_10_2
2512 wxMacMLTEHIViewControl::wxMacMLTEHIViewControl( wxWindow
*wxPeer
,
2513 const wxString
& str
,
2515 const wxSize
& size
, long style
)
2517 m_font
= wxPeer
->GetFont() ;
2518 m_windowStyle
= style
;
2519 Rect bounds
= wxMacGetBoundsForControl( wxPeer
, pos
, size
) ;
2521 wxMacConvertNewlines10To13( &st
) ;
2523 HIRect hr
= { bounds
.left
, bounds
.top
, bounds
.right
- bounds
.left
, bounds
.bottom
- bounds
.top
} ;
2525 m_scrollView
= NULL
;
2526 TXNFrameOptions frameOptions
= FrameOptionsFromWXStyle( style
) ;
2527 if ( frameOptions
& (kTXNWantVScrollBarMask
|kTXNWantHScrollBarMask
) )
2529 HIScrollViewCreate(( frameOptions
& kTXNWantHScrollBarMask
? kHIScrollViewOptionsHorizScroll
: 0) |
2530 ( frameOptions
& kTXNWantVScrollBarMask
? kHIScrollViewOptionsVertScroll
: 0 ) , &m_scrollView
) ;
2532 HIViewSetFrame( m_scrollView
, &hr
);
2533 HIViewSetVisible( m_scrollView
, true );
2537 HITextViewCreate( NULL
, 0, frameOptions
, &m_textView
) ;
2538 m_txn
= HITextViewGetTXNObject( m_textView
) ;
2539 HIViewSetVisible( m_textView
, true ) ;
2542 HIViewAddSubview( m_scrollView
, m_textView
) ;
2543 m_controlRef
= m_scrollView
;
2544 wxPeer
->MacInstallEventHandler( (WXWidget
) m_textView
) ;
2548 HIViewSetFrame( m_textView
, &hr
);
2549 m_controlRef
= m_textView
;
2553 SetTXNData( st
, kTXNStartOffset
, kTXNEndOffset
) ;
2555 TXNSetSelection( m_txn
, 0, 0);
2556 TXNShowSelection( m_txn
, kTXNShowStart
);
2558 AdjustCreationAttributes( *wxWHITE
, true ) ;
2561 OSStatus
wxMacMLTEHIViewControl::SetFocus( ControlFocusPart focusPart
)
2563 return SetKeyboardFocus( GetControlOwner( m_textView
) ,
2564 m_textView
, focusPart
) ;
2567 bool wxMacMLTEHIViewControl::HasFocus() const
2569 ControlRef control
;
2570 GetKeyboardFocus( GetUserFocusWindow() , &control
) ;
2571 return control
== m_textView
;
2574 bool wxMacMLTEHIViewControl::NeedsFocusRect() const
2576 return m_windowStyle
& wxNO_BORDER
? false : true;
2579 #endif // MAC_OS_X_VERSION_MAX_ALLOWED > MAC_OS_X_VERSION_10_2
2584 #endif // wxUSE_TEXTCTRL