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 int ConvertAttribute( const wxTextAttr
& style
, TXNTypeAttributes attr
[] ) ;
203 static TXNFrameOptions
FrameOptionsFromWXStyle( long wxStyle
) ;
204 void AdjustCreationAttributes( const wxColour
& background
, bool visible
) ;
206 virtual void SetFont( const wxFont
& font
, const wxColour
& foreground
, long windowStyle
) ;
207 virtual void SetBackground( const wxBrush
&brush
) ;
208 virtual void SetStyle(long start
, long end
, const wxTextAttr
& style
) ;
209 virtual void Copy() ;
211 virtual void Paste() ;
212 virtual bool CanPaste() const ;
213 virtual void SetEditable(bool editable
) ;
214 virtual long GetLastPosition() const ;
215 virtual void Replace( long from
, long to
, const wxString str
) ;
216 virtual void Remove( long from
, long to
) ;
217 virtual void GetSelection( long* from
, long* to
) const ;
218 virtual void SetSelection( long from
, long to
) ;
220 virtual void WriteText(const wxString
& str
) ;
221 virtual void Clear() ;
223 virtual bool CanUndo() const ;
224 virtual void Undo() ;
225 virtual bool CanRedo() const;
226 virtual void Redo() ;
227 virtual int GetNumberOfLines() const ;
228 virtual long XYToPosition(long x
, long y
) const ;
229 virtual bool PositionToXY(long pos
, long *x
, long *y
) const ;
230 virtual void ShowPosition( long pos
) ;
231 virtual int GetLineLength(long lineNo
) const ;
232 virtual wxString
GetLineText(long lineNo
) const ;
234 void SetTXNData( const wxString
& st
, TXNOffset start
, TXNOffset end
) ;
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
) ;
439 void wxTextCtrl::SetMaxLength(unsigned long len
)
444 bool wxTextCtrl::SetFont( const wxFont
& font
)
446 if ( !wxTextCtrlBase::SetFont( font
) )
449 GetPeer()->SetFont( font
, GetForegroundColour() , GetWindowStyle() ) ;
453 bool wxTextCtrl::SetStyle(long start
, long end
, const wxTextAttr
& style
)
455 GetPeer()->SetStyle( start
, end
, style
) ;
459 bool wxTextCtrl::SetDefaultStyle(const wxTextAttr
& style
)
461 wxTextCtrlBase::SetDefaultStyle( style
) ;
462 SetStyle( kTXNUseCurrentSelection
, kTXNUseCurrentSelection
, GetDefaultStyle() ) ;
466 // Clipboard operations
467 void wxTextCtrl::Copy()
475 void wxTextCtrl::Cut()
481 wxCommandEvent
event(wxEVT_COMMAND_TEXT_UPDATED
, m_windowId
);
482 event
.SetString( GetValue() ) ;
483 event
.SetEventObject( this );
484 GetEventHandler()->ProcessEvent(event
);
488 void wxTextCtrl::Paste()
493 // eventually we should add setting the default style again
495 wxCommandEvent
event(wxEVT_COMMAND_TEXT_UPDATED
, m_windowId
);
496 event
.SetString( GetValue() ) ;
497 event
.SetEventObject( this );
498 GetEventHandler()->ProcessEvent(event
);
502 bool wxTextCtrl::CanCopy() const
504 // Can copy if there's a selection
506 GetSelection(& from
, & to
);
510 bool wxTextCtrl::CanCut() const
516 // Can cut if there's a selection
518 GetSelection(& from
, & to
);
522 bool wxTextCtrl::CanPaste() const
527 return GetPeer()->CanPaste() ;
530 void wxTextCtrl::SetEditable(bool editable
)
532 if ( editable
!= m_editable
)
534 m_editable
= editable
;
535 GetPeer()->SetEditable( editable
) ;
539 void wxTextCtrl::SetInsertionPoint(long pos
)
541 SetSelection( pos
, pos
) ;
544 void wxTextCtrl::SetInsertionPointEnd()
546 long pos
= GetLastPosition();
547 SetInsertionPoint(pos
);
550 long wxTextCtrl::GetInsertionPoint() const
553 GetSelection( &begin
, &end
) ;
557 long wxTextCtrl::GetLastPosition() const
559 return GetPeer()->GetLastPosition( ) ;
562 void wxTextCtrl::Replace(long from
, long to
, const wxString
& str
)
564 GetPeer()->Replace( from
, to
, str
) ;
567 void wxTextCtrl::Remove(long from
, long to
)
569 GetPeer()->Remove( from
, to
) ;
572 void wxTextCtrl::SetSelection(long from
, long to
)
574 GetPeer()->SetSelection( from
, to
) ;
577 bool wxTextCtrl::LoadFile(const wxString
& file
)
579 if ( wxTextCtrlBase::LoadFile(file
) )
587 void wxTextCtrl::WriteText(const wxString
& str
)
589 // TODO this MPRemoting will be moved into a remoting peer proxy for any command
590 if ( !wxIsMainThread() )
592 // unfortunately CW 8 is not able to correctly deduce the template types, so we have
593 // to instantiate explicitely
594 wxMacMPRemoteGUICall
<wxTextCtrl
,wxString
>( this , &wxTextCtrl::WriteText
, str
) ;
599 GetPeer()->WriteText( str
) ;
603 void wxTextCtrl::AppendText(const wxString
& text
)
605 SetInsertionPointEnd();
609 void wxTextCtrl::Clear()
614 bool wxTextCtrl::IsModified() const
619 bool wxTextCtrl::IsEditable() const
621 return IsEnabled() && m_editable
;
624 bool wxTextCtrl::AcceptsFocus() const
626 // we don't want focus if we can't be edited
627 return /*IsEditable() && */ wxControl::AcceptsFocus();
630 wxSize
wxTextCtrl::DoGetBestSize() const
636 // these are the numbers from the HIG, we reduce them by the borders
639 switch( m_windowVariant
)
641 case wxWINDOW_VARIANT_NORMAL
:
644 case wxWINDOW_VARIANT_SMALL
:
647 case wxWINDOW_VARIANT_MINI
:
655 // as the above numbers have some free space around the text
656 // we get 5 lines like this anyway
657 if ( m_windowStyle
& wxTE_MULTILINE
)
662 if ( !HasFlag(wxNO_BORDER
) )
665 return wxSize(wText
, hText
);
668 // ----------------------------------------------------------------------------
670 // ----------------------------------------------------------------------------
672 void wxTextCtrl::Undo()
680 void wxTextCtrl::Redo()
688 bool wxTextCtrl::CanUndo() const
694 return GetPeer()->CanUndo() ;
697 bool wxTextCtrl::CanRedo() const
703 return GetPeer()->CanRedo() ;
706 void wxTextCtrl::MarkDirty()
711 void wxTextCtrl::DiscardEdits()
716 int wxTextCtrl::GetNumberOfLines() const
718 return GetPeer()->GetNumberOfLines() ;
721 long wxTextCtrl::XYToPosition(long x
, long y
) const
723 return GetPeer()->XYToPosition( x
, y
) ;
726 bool wxTextCtrl::PositionToXY(long pos
, long *x
, long *y
) const
728 return GetPeer()->PositionToXY(pos
, x
, y
) ;
731 void wxTextCtrl::ShowPosition(long pos
)
733 return GetPeer()->ShowPosition(pos
) ;
736 int wxTextCtrl::GetLineLength(long lineNo
) const
738 return GetPeer()->GetLineLength(lineNo
) ;
741 wxString
wxTextCtrl::GetLineText(long lineNo
) const
743 return GetPeer()->GetLineText(lineNo
) ;
750 void wxTextCtrl::Command(wxCommandEvent
& event
)
752 SetValue (event
.GetString());
753 ProcessCommand (event
);
756 void wxTextCtrl::OnDropFiles(wxDropFilesEvent
& event
)
758 // By default, load the first file into the text window.
759 if (event
.GetNumberOfFiles() > 0)
761 LoadFile(event
.GetFiles()[0]);
765 void wxTextCtrl::OnEraseBackground(wxEraseEvent
& event
)
767 // all erasing should be done by the real mac control implementation
768 // while this is true for MLTE under classic, the HITextView is somehow
769 // transparent but background erase is not working correctly, so intercept
770 // things while we can...
774 void wxTextCtrl::OnChar(wxKeyEvent
& event
)
776 int key
= event
.GetKeyCode() ;
777 bool eat_key
= false ;
779 if ( key
== 'c' && event
.MetaDown() )
786 if ( !IsEditable() && key
!= WXK_LEFT
&& key
!= WXK_RIGHT
&& key
!= WXK_DOWN
&& key
!= WXK_UP
&& key
!= WXK_TAB
&&
787 !( key
== WXK_RETURN
&& ( (m_windowStyle
& wxPROCESS_ENTER
) || (m_windowStyle
& wxTE_MULTILINE
) ) )
788 /* && key != WXK_PRIOR && key != WXK_NEXT && key != WXK_HOME && key != WXK_END */
795 // assume that any key not processed yet is going to modify the control
798 if ( key
== 'v' && event
.MetaDown() )
804 if ( key
== 'x' && event
.MetaDown() )
813 if (m_windowStyle
& wxPROCESS_ENTER
)
815 wxCommandEvent
event(wxEVT_COMMAND_TEXT_ENTER
, m_windowId
);
816 event
.SetEventObject( this );
817 event
.SetString( GetValue() );
818 if ( GetEventHandler()->ProcessEvent(event
) )
821 if ( !(m_windowStyle
& wxTE_MULTILINE
) )
823 wxWindow
*parent
= GetParent();
824 while( parent
&& !parent
->IsTopLevel() && parent
->GetDefaultItem() == NULL
) {
825 parent
= parent
->GetParent() ;
827 if ( parent
&& parent
->GetDefaultItem() )
829 wxButton
*def
= wxDynamicCast(parent
->GetDefaultItem(),
831 if ( def
&& def
->IsEnabled() )
833 wxCommandEvent
event(wxEVT_COMMAND_BUTTON_CLICKED
, def
->GetId() );
834 event
.SetEventObject(def
);
840 // this will make wxWidgets eat the ENTER key so that
841 // we actually prevent line wrapping in a single line
849 if ( !(m_windowStyle
& wxTE_PROCESS_TAB
))
852 if (!event
.ShiftDown())
853 flags
|= wxNavigationKeyEvent::IsForward
;
854 if (event
.ControlDown())
855 flags
|= wxNavigationKeyEvent::WinChange
;
861 // This is necessary (don't know why) or the tab will not
863 WriteText(wxT("\t"));
871 // perform keystroke handling
872 if ( wxTheApp
->MacGetCurrentEvent() != NULL
&& wxTheApp
->MacGetCurrentEventHandlerCallRef() != NULL
)
873 CallNextEventHandler((EventHandlerCallRef
)wxTheApp
->MacGetCurrentEventHandlerCallRef() , (EventRef
) wxTheApp
->MacGetCurrentEvent() ) ;
877 if ( wxMacConvertEventToRecord( (EventRef
) wxTheApp
->MacGetCurrentEvent() , &rec
) )
879 EventRecord
*ev
= &rec
;
882 keychar
= short(ev
->message
& charCodeMask
);
883 keycode
= short(ev
->message
& keyCodeMask
) >> 8 ;
885 m_peer
->HandleKey( keycode
, keychar
, ev
->modifiers
) ;
889 if ( ( key
>= 0x20 && key
< WXK_START
) ||
894 wxCommandEvent
event1(wxEVT_COMMAND_TEXT_UPDATED
, m_windowId
);
895 event1
.SetString( GetValue() ) ;
896 event1
.SetEventObject( this );
897 wxPostEvent(GetEventHandler(),event1
);
901 // ----------------------------------------------------------------------------
902 // standard handlers for standard edit menu events
903 // ----------------------------------------------------------------------------
905 void wxTextCtrl::OnCut(wxCommandEvent
& WXUNUSED(event
))
910 void wxTextCtrl::OnCopy(wxCommandEvent
& WXUNUSED(event
))
915 void wxTextCtrl::OnPaste(wxCommandEvent
& WXUNUSED(event
))
920 void wxTextCtrl::OnUndo(wxCommandEvent
& WXUNUSED(event
))
925 void wxTextCtrl::OnRedo(wxCommandEvent
& WXUNUSED(event
))
930 void wxTextCtrl::OnUpdateCut(wxUpdateUIEvent
& event
)
932 event
.Enable( CanCut() );
935 void wxTextCtrl::OnUpdateCopy(wxUpdateUIEvent
& event
)
937 event
.Enable( CanCopy() );
940 void wxTextCtrl::OnUpdatePaste(wxUpdateUIEvent
& event
)
942 event
.Enable( CanPaste() );
945 void wxTextCtrl::OnUpdateUndo(wxUpdateUIEvent
& event
)
947 event
.Enable( CanUndo() );
950 void wxTextCtrl::OnUpdateRedo(wxUpdateUIEvent
& event
)
952 event
.Enable( CanRedo() );
955 bool wxTextCtrl::MacSetupCursor( const wxPoint
& pt
)
960 // user pane implementation
962 void wxTextCtrl::MacControlUserPaneDrawProc(wxInt16 part
)
966 wxInt16
wxTextCtrl::MacControlUserPaneHitTestProc(wxInt16 x
, wxInt16 y
)
968 return kControlNoPart
;
971 wxInt16
wxTextCtrl::MacControlUserPaneTrackingProc(wxInt16 x
, wxInt16 y
, void* actionProc
)
973 return kControlNoPart
;
976 void wxTextCtrl::MacControlUserPaneIdleProc()
980 wxInt16
wxTextCtrl::MacControlUserPaneKeyDownProc(wxInt16 keyCode
, wxInt16 charCode
, wxInt16 modifiers
)
982 return kControlNoPart
;
985 void wxTextCtrl::MacControlUserPaneActivateProc(bool activating
)
989 wxInt16
wxTextCtrl::MacControlUserPaneFocusProc(wxInt16 action
)
991 return kControlNoPart
;
994 void wxTextCtrl::MacControlUserPaneBackgroundProc(void* info
)
998 // ----------------------------------------------------------------------------
999 // implementation base class
1000 // ----------------------------------------------------------------------------
1002 wxMacTextControl::wxMacTextControl()
1006 wxMacTextControl::~wxMacTextControl()
1010 void wxMacTextControl::SetStyle(long start
, long end
, const wxTextAttr
& style
)
1014 void wxMacTextControl::Copy()
1018 void wxMacTextControl::Cut()
1022 void wxMacTextControl::Paste()
1026 bool wxMacTextControl::CanPaste() const
1031 void wxMacTextControl::SetEditable(bool editable
)
1035 long wxMacTextControl::GetLastPosition() const
1037 return GetStringValue().Length() ;
1040 void wxMacTextControl::Replace( long from
, long to
, const wxString str
)
1044 void wxMacTextControl::Clear()
1046 SetStringValue( wxEmptyString
) ;
1049 bool wxMacTextControl::CanUndo() const
1054 void wxMacTextControl::Undo() { }
1056 bool wxMacTextControl::CanRedo() const
1061 void wxMacTextControl::Redo()
1065 long wxMacTextControl::XYToPosition(long x
, long y
) const
1070 bool wxMacTextControl::PositionToXY(long pos
, long *x
, long *y
) const
1075 void wxMacTextControl::ShowPosition( long WXUNUSED(pos
) )
1079 int wxMacTextControl::GetNumberOfLines() const
1081 ItemCount lines
= 0 ;
1082 wxString content
= GetStringValue() ;
1084 for (size_t i
= 0; i
< content
.Length() ; i
++)
1086 if (content
[i
] == '\r') lines
++;
1091 wxString
wxMacTextControl::GetLineText(long lineNo
) const
1093 // TODO change this if possible to reflect real lines
1094 wxString content
= GetStringValue() ;
1098 for (size_t i
= 0; i
< content
.Length() ; i
++)
1100 if (count
== lineNo
)
1102 // Add chars in line then
1105 for (size_t j
= i
; j
< content
.Length(); j
++)
1107 if (content
[j
] == '\n')
1115 if (content
[i
] == '\n') count
++;
1117 return wxEmptyString
;
1120 int wxMacTextControl::GetLineLength(long lineNo
) const
1122 // TODO change this if possible to reflect real lines
1123 wxString content
= GetStringValue() ;
1127 for (size_t i
= 0; i
< content
.Length() ; i
++)
1129 if (count
== lineNo
)
1131 // Count chars in line then
1133 for (size_t j
= i
; j
< content
.Length(); j
++)
1136 if (content
[j
] == '\n') return count
;
1141 if (content
[i
] == '\n') count
++;
1146 // ----------------------------------------------------------------------------
1147 // standard unicode control implementation
1148 // ----------------------------------------------------------------------------
1150 #if TARGET_API_MAC_OSX
1152 wxMacUnicodeTextControl::wxMacUnicodeTextControl( wxWindow
*wxPeer
,
1153 const wxString
& str
,
1155 const wxSize
& size
, long style
)
1157 m_font
= wxPeer
->GetFont() ;
1158 m_windowStyle
= style
;
1159 Rect bounds
= wxMacGetBoundsForControl( wxPeer
, pos
, size
) ;
1161 wxMacConvertNewlines10To13( &st
) ;
1162 wxMacCFStringHolder
cf(st
, m_font
.GetEncoding()) ;
1163 CFStringRef cfr
= cf
;
1164 Boolean isPassword
= ( m_windowStyle
& wxTE_PASSWORD
) != 0 ;
1165 m_valueTag
= isPassword
? kControlEditTextPasswordCFStringTag
: kControlEditTextCFStringTag
;
1166 CreateEditUnicodeTextControl( MAC_WXHWND(wxPeer
->MacGetTopLevelWindowRef()), &bounds
, cfr
, isPassword
, NULL
, &m_controlRef
) ;
1168 if ( !(m_windowStyle
& wxTE_MULTILINE
) )
1170 SetData
<Boolean
>( kControlEditTextPart
, kControlEditTextSingleLineTag
, true ) ;
1174 wxMacUnicodeTextControl::~wxMacUnicodeTextControl()
1178 void wxMacUnicodeTextControl::VisibilityChanged(bool shown
)
1180 if ( !(m_windowStyle
& wxTE_MULTILINE
) && shown
)
1182 // work around a refresh issue insofar as not always the entire content is shown even if this would be possible
1183 ControlEditTextSelectionRec sel
;
1184 CFStringRef value
= NULL
;
1186 verify_noerr( GetData
<ControlEditTextSelectionRec
>( 0, kControlEditTextSelectionTag
, &sel
) );
1187 verify_noerr( GetData
<CFStringRef
>( 0, m_valueTag
, &value
) );
1188 verify_noerr( SetData
<CFStringRef
>( 0, m_valueTag
, &value
) );
1189 verify_noerr( SetData
<ControlEditTextSelectionRec
>( 0, kControlEditTextSelectionTag
, &sel
) );
1191 CFRelease( value
) ;
1194 wxString
wxMacUnicodeTextControl::GetStringValue() const
1197 CFStringRef value
= GetData
<CFStringRef
>(0,m_valueTag
) ;
1200 wxMacCFStringHolder
cf(value
) ;
1201 result
= cf
.AsString() ;
1204 wxMacConvertNewlines13To10( &result
) ;
1206 wxMacConvertNewlines10To13( &result
) ;
1210 void wxMacUnicodeTextControl::SetStringValue( const wxString
&str
)
1213 wxMacConvertNewlines10To13( &st
) ;
1214 wxMacCFStringHolder
cf(st
, m_font
.GetEncoding() ) ;
1215 verify_noerr( SetData
<CFStringRef
>( 0, m_valueTag
, cf
) ) ;
1217 void wxMacUnicodeTextControl::Copy()
1219 SendHICommand( kHICommandCopy
) ;
1221 void wxMacUnicodeTextControl::Cut()
1223 SendHICommand( kHICommandCut
) ;
1225 void wxMacUnicodeTextControl::Paste()
1227 SendHICommand( kHICommandPaste
) ;
1229 bool wxMacUnicodeTextControl::CanPaste() const
1233 void wxMacUnicodeTextControl::SetEditable(bool editable
)
1235 SetData
<Boolean
>( 0 , kControlEditTextLockedTag
, (Boolean
) !editable
) ;
1237 void wxMacUnicodeTextControl::Remove( long from
, long to
)
1241 void wxMacUnicodeTextControl::GetSelection( long* from
, long* to
) const
1243 ControlEditTextSelectionRec sel
;
1244 verify_noerr(GetData
<ControlEditTextSelectionRec
>( 0, kControlEditTextSelectionTag
, &sel
) ) ;
1245 if ( from
) *from
= sel
.selStart
;
1246 if ( to
) *to
= sel
.selEnd
;
1249 void wxMacUnicodeTextControl::SetSelection( long from
, long to
)
1251 ControlEditTextSelectionRec sel
;
1252 sel
.selStart
= from
;
1254 SetData
<ControlEditTextSelectionRec
>( 0 , kControlEditTextSelectionTag
, &sel
) ;
1257 void wxMacUnicodeTextControl::WriteText(const wxString
& str
)
1260 wxMacConvertNewlines10To13( &st
) ;
1261 #if MAC_OS_X_VERSION_MAX_ALLOWED > MAC_OS_X_VERSION_10_2
1262 wxMacCFStringHolder
cf(st
, m_font
.GetEncoding() ) ;
1263 CFStringRef value
= cf
;
1264 SetData
<CFStringRef
>( 0, kControlEditTextInsertCFStringRefTag
, &value
);
1266 wxString val
= GetStringValue() ;
1268 GetSelection( &start
, &end
) ;
1269 val
.Remove( start
, end
- start
) ;
1270 val
.insert( start
, str
) ;
1271 SetStringValue( val
) ;
1272 SetSelection( start
+ str
.Length() , start
+ str
.Length() ) ;
1278 // ----------------------------------------------------------------------------
1279 // MLTE control implementation (common part)
1280 // ----------------------------------------------------------------------------
1282 #if TARGET_API_MAC_OSX == 0
1283 // declaration needed because of one line in the code...
1284 static void TPUpdateVisibility(ControlRef theControl
) ;
1287 // if mlte is on read only , no changes at all are allowed, not even from
1288 // procedural API, in order to allow changes via API all the same we must undo
1289 // the readonly status while we are executing, this class helps to do so
1294 EditHelper( TXNObject txn
)
1296 TXNControlTag tag
[] = { kTXNIOPrivilegesTag
} ;
1298 TXNGetTXNObjectControls( m_txn
, 1 , tag
, m_data
) ;
1299 if ( m_data
[0].uValue
== kTXNReadOnly
)
1301 TXNControlData data
[] = { { kTXNReadWrite
} } ;
1302 TXNSetTXNObjectControls( m_txn
, false , 1 , tag
, data
) ;
1307 TXNControlTag tag
[] = { kTXNIOPrivilegesTag
} ;
1308 if ( m_data
[0].uValue
== kTXNReadOnly
)
1310 TXNSetTXNObjectControls( m_txn
, false , 1 , tag
, m_data
) ;
1315 TXNControlData m_data
[1] ;
1318 wxString
wxMacMLTEControl::GetStringValue() const
1322 Size actualSize
= 0;
1326 err
= TXNGetDataEncoded( m_txn
, kTXNStartOffset
, kTXNEndOffset
, &theText
, kTXNUnicodeTextData
);
1334 actualSize
= GetHandleSize( theText
) / sizeof( UniChar
) ;
1335 if ( actualSize
> 0 )
1337 wxChar
*ptr
= NULL
;
1338 #if SIZEOF_WCHAR_T == 2
1339 ptr
= new wxChar
[actualSize
+ 1 ] ;
1340 wxStrncpy( ptr
, (wxChar
*) *theText
, actualSize
) ;
1343 SetHandleSize( theText
, ( actualSize
+ 1 ) * sizeof( UniChar
) ) ;
1345 (((UniChar
*)*theText
)[actualSize
]) = 0 ;
1346 wxMBConvUTF16BE converter
;
1347 size_t noChars
= converter
.MB2WC( NULL
, (const char*)*theText
, 0 ) ;
1348 ptr
= new wxChar
[noChars
+ 1] ;
1350 noChars
= converter
.MB2WC( ptr
, (const char*)*theText
, noChars
) ;
1352 HUnlock( theText
) ;
1354 ptr
[actualSize
] = 0 ;
1355 result
= wxString( ptr
) ;
1358 DisposeHandle( theText
) ;
1362 err
= TXNGetDataEncoded( m_txn
, kTXNStartOffset
, kTXNEndOffset
, &theText
, kTXNTextData
);
1370 actualSize
= GetHandleSize( theText
) ;
1371 if ( actualSize
> 0 )
1374 result
= wxString( *theText
, wxConvLocal
, actualSize
) ;
1375 HUnlock( theText
) ;
1377 DisposeHandle( theText
) ;
1382 wxMacConvertNewlines13To10( &result
) ;
1384 wxMacConvertNewlines10To13( &result
) ;
1389 void wxMacMLTEControl::SetStringValue( const wxString
&str
)
1393 wxMacConvertNewlines10To13( &st
) ;
1394 EditHelper
help(m_txn
) ;
1396 // wxMacWindowClipper c( this ) ;
1397 #if !TARGET_API_MAC_OSX
1398 // otherwise scrolling might have problems ?
1399 TPUpdateVisibility( m_controlRef
) ;
1401 SetTXNData( st
, kTXNStartOffset
, kTXNEndOffset
) ;
1402 TXNSetSelection( m_txn
, 0, 0);
1403 TXNShowSelection( m_txn
, kTXNShowStart
);
1406 TXNFrameOptions
wxMacMLTEControl::FrameOptionsFromWXStyle( long wxStyle
)
1408 TXNFrameOptions frameOptions
=
1409 kTXNDontDrawCaretWhenInactiveMask
;
1410 if ( ! ( wxStyle
& wxTE_NOHIDESEL
) )
1411 frameOptions
|= kTXNDontDrawSelectionWhenInactiveMask
;
1413 if ( wxStyle
& wxTE_MULTILINE
)
1415 if ( ! ( wxStyle
& wxTE_DONTWRAP
) )
1416 frameOptions
|= kTXNAlwaysWrapAtViewEdgeMask
;
1419 frameOptions
|= kTXNAlwaysWrapAtViewEdgeMask
;
1420 frameOptions
|= kTXNWantHScrollBarMask
;
1423 if ( !(wxStyle
& wxTE_NO_VSCROLL
) )
1424 frameOptions
|= kTXNWantVScrollBarMask
;
1427 frameOptions
|= kTXNSingleLineOnlyMask
;
1429 if ( wxStyle
& wxHSCROLL
)
1430 frameOptions
|= kTXNWantHScrollBarMask
;
1432 return frameOptions
;
1435 void wxMacMLTEControl::AdjustCreationAttributes( const wxColour
&background
, bool visible
)
1437 TXNControlTag iControlTags
[3] = { kTXNDoFontSubstitution
, kTXNWordWrapStateTag
};
1438 TXNControlData iControlData
[3] = { {false}, {kTXNNoAutoWrap
} };
1440 #if TARGET_API_MAC_OSX
1441 iControlTags
[2] = kTXNVisibilityTag
;
1442 iControlData
[2].uValue
= visible
;
1446 if ( m_windowStyle
& wxTE_MULTILINE
)
1448 if (m_windowStyle
& wxTE_DONTWRAP
)
1449 iControlData
[1].uValue
= kTXNNoAutoWrap
;
1451 iControlData
[1].uValue
= kTXNAutoWrap
;
1454 verify_noerr( TXNSetTXNObjectControls( m_txn
, false, toptag
,
1455 iControlTags
, iControlData
)) ;
1457 // setting the default font
1463 GetThemeFont(kThemeSystemFont
, GetApplicationScript() , fontName
, &fontSize
, &fontStyle
) ;
1465 TXNTypeAttributes typeAttr
[] =
1467 { kTXNQDFontNameAttribute
, kTXNQDFontNameAttributeSize
, { (void*) fontName
} } ,
1468 { kTXNQDFontSizeAttribute
, kTXNFontSizeAttributeSize
, { (void*) (fontSize
<< 16) } } ,
1469 { kTXNQDFontStyleAttribute
, kTXNQDFontStyleAttributeSize
, { (void*) normal
} } ,
1472 verify_noerr( TXNSetTypeAttributes (m_txn
, sizeof( typeAttr
) / sizeof(TXNTypeAttributes
) , typeAttr
,
1476 if ( m_windowStyle
& wxTE_PASSWORD
)
1479 verify_noerr(TXNEchoMode( m_txn
, c
, 0 , true )) ;
1482 TXNBackground tback
;
1483 tback
.bgType
= kTXNBackgroundTypeRGB
;
1484 tback
.bg
.color
= MAC_WXCOLORREF( background
.GetPixel() );
1485 TXNSetBackground( m_txn
, &tback
);
1488 void wxMacMLTEControl::SetBackground( const wxBrush
&brush
)
1490 // currently only solid background are supported
1491 TXNBackground tback
;
1492 tback
.bgType
= kTXNBackgroundTypeRGB
;
1493 tback
.bg
.color
= MAC_WXCOLORREF( brush
.GetColour().GetPixel() );
1494 TXNSetBackground( m_txn
, &tback
);
1497 int wxMacMLTEControl::ConvertAttribute( const wxTextAttr
& style
, TXNTypeAttributes typeAttr
[] )
1499 Str255 fontName
= "\pMonaco" ;
1500 SInt16 fontSize
= 12 ;
1501 Style fontStyle
= normal
;
1503 int attrCounter
= 0 ;
1504 if ( style
.HasFont() )
1506 const wxFont
&font
= style
.GetFont() ;
1507 wxMacStringToPascal( font
.GetFaceName() , fontName
) ;
1508 fontSize
= font
.GetPointSize() ;
1509 if ( font
.GetUnderlined() )
1510 fontStyle
|= underline
;
1511 if ( font
.GetWeight() == wxBOLD
)
1513 if ( font
.GetStyle() == wxITALIC
)
1514 fontStyle
|= italic
;
1516 typeAttr
[attrCounter
].tag
= kTXNQDFontNameAttribute
;
1517 typeAttr
[attrCounter
].size
= kTXNQDFontNameAttributeSize
;
1518 typeAttr
[attrCounter
].data
.dataPtr
= (void*) fontName
;
1519 typeAttr
[attrCounter
+1].tag
= kTXNQDFontSizeAttribute
;
1520 typeAttr
[attrCounter
+1].size
= kTXNFontSizeAttributeSize
;
1521 typeAttr
[attrCounter
+1].data
.dataValue
= (fontSize
<< 16) ;
1522 typeAttr
[attrCounter
+2].tag
= kTXNQDFontStyleAttribute
;
1523 typeAttr
[attrCounter
+2].size
= kTXNQDFontStyleAttributeSize
;
1524 typeAttr
[attrCounter
+2].data
.dataValue
= fontStyle
;
1527 if ( style
.HasTextColour() )
1529 typeAttr
[attrCounter
].tag
= kTXNQDFontColorAttribute
;
1530 typeAttr
[attrCounter
].size
= kTXNQDFontColorAttributeSize
;
1531 typeAttr
[attrCounter
].data
.dataPtr
= (void*) &color
;
1532 color
= MAC_WXCOLORREF(style
.GetTextColour().GetPixel()) ;
1535 return attrCounter
;
1538 void wxMacMLTEControl::SetFont( const wxFont
& font
, const wxColour
& foreground
, long windowStyle
)
1540 EditHelper
help(m_txn
) ;
1541 wxTextAttr
style(foreground
,wxNullColour
,font
) ;
1542 TXNTypeAttributes typeAttr
[4] ;
1543 int attrCounter
= ConvertAttribute( style
, typeAttr
) ;
1544 if ( attrCounter
> 0 )
1546 verify_noerr( TXNSetTypeAttributes ( m_txn
, attrCounter
, typeAttr
, kTXNStartOffset
,kTXNEndOffset
) );
1549 void wxMacMLTEControl::SetStyle(long start
, long end
, const wxTextAttr
& style
)
1551 EditHelper
help(m_txn
) ;
1552 TXNTypeAttributes typeAttr
[4] ;
1553 int attrCounter
= ConvertAttribute( style
, typeAttr
) ;
1554 if ( attrCounter
> 0 )
1556 verify_noerr( TXNSetTypeAttributes ( m_txn
, attrCounter
, typeAttr
, start
,end
) );
1560 void wxMacMLTEControl::Copy()
1562 ClearCurrentScrap();
1564 TXNConvertToPublicScrap();
1567 void wxMacMLTEControl::Cut()
1569 ClearCurrentScrap();
1571 TXNConvertToPublicScrap();
1574 void wxMacMLTEControl::Paste()
1576 TXNConvertFromPublicScrap();
1580 bool wxMacMLTEControl::CanPaste() const
1582 return TXNIsScrapPastable() ;
1585 void wxMacMLTEControl::SetEditable(bool editable
)
1587 TXNControlTag tag
[] = { kTXNIOPrivilegesTag
} ;
1588 TXNControlData data
[] = { { editable
? kTXNReadWrite
: kTXNReadOnly
} } ;
1589 TXNSetTXNObjectControls( m_txn
, false , sizeof(tag
) / sizeof (TXNControlTag
) , tag
, data
) ;
1592 long wxMacMLTEControl::GetLastPosition() const
1594 long actualsize
= 0 ;
1597 OSErr err
= TXNGetDataEncoded( m_txn
, kTXNStartOffset
, kTXNEndOffset
, &theText
, kTXNTextData
);
1605 actualsize
= GetHandleSize( theText
) ;
1606 DisposeHandle( theText
) ;
1612 void wxMacMLTEControl::Replace( long from
, long to
, const wxString str
)
1614 wxString value
= str
;
1615 wxMacConvertNewlines10To13( &value
) ;
1617 EditHelper
help( m_txn
) ;
1619 TXNSetSelection(m_txn
, from
, to
) ;
1621 SetTXNData( value
, kTXNUseCurrentSelection
, kTXNUseCurrentSelection
) ;
1624 void wxMacMLTEControl::Remove( long from
, long to
)
1626 EditHelper
help( m_txn
) ;
1628 TXNSetSelection(m_txn
, from
, to
) ;
1632 void wxMacMLTEControl::GetSelection( long* from
, long* to
) const
1634 TXNGetSelection( m_txn
, (TXNOffset
*) from
, (TXNOffset
*) to
) ;
1637 void wxMacMLTEControl::SetSelection( long from
, long to
)
1639 /* change the selection */
1640 if ((from
== -1) && (to
== -1))
1641 TXNSelectAll(m_txn
);
1643 TXNSetSelection( m_txn
, from
, to
);
1644 TXNShowSelection( m_txn
, kTXNShowStart
);
1647 void wxMacMLTEControl::WriteText(const wxString
& str
)
1649 EditHelper
helper( m_txn
) ;
1651 wxMacConvertNewlines10To13( &st
) ;
1653 long start
, end
, dummy
;
1654 GetSelection( &start
, &dummy
) ;
1655 SetTXNData( st
, kTXNUseCurrentSelection
, kTXNUseCurrentSelection
) ;
1656 GetSelection( &dummy
, &end
) ;
1657 // TODO SetStyle( start , end , GetDefaultStyle() ) ;
1660 void wxMacMLTEControl::Clear()
1662 EditHelper
st(m_txn
) ;
1663 TXNSetSelection( m_txn
, kTXNStartOffset
, kTXNEndOffset
) ;
1667 bool wxMacMLTEControl::CanUndo() const
1669 return TXNCanUndo( m_txn
, NULL
) ;
1672 void wxMacMLTEControl::Undo()
1677 bool wxMacMLTEControl::CanRedo() const
1679 return TXNCanRedo( m_txn
, NULL
) ;
1682 void wxMacMLTEControl::Redo()
1687 int wxMacMLTEControl::GetNumberOfLines() const
1689 ItemCount lines
= 0 ;
1690 TXNGetLineCount(m_txn
, &lines
) ;
1694 long wxMacMLTEControl::XYToPosition(long x
, long y
) const
1698 long lastpos
= GetLastPosition() ;
1700 // TODO find a better implementation : while we can get the
1701 // line metrics of a certain line, we don't get its starting
1702 // position, so it would probably be rather a binary search
1703 // for the start position
1706 int lastHeight
= 0 ;
1709 for ( n
= 0 ; n
<= (ItemCount
) lastpos
; ++n
)
1711 if ( y
== ypos
&& x
== xpos
)
1714 TXNOffsetToPoint( m_txn
, n
, &curpt
);
1716 if ( curpt
.v
> lastHeight
)
1721 lastHeight
= curpt
.v
;
1729 bool wxMacMLTEControl::PositionToXY(long pos
, long *x
, long *y
) const
1733 long lastpos
= GetLastPosition() ;
1738 if ( pos
<= lastpos
)
1740 // TODO find a better implementation : while we can get the
1741 // line metrics of a certain line, we don't get its starting
1742 // position, so it would probably be rather a binary search
1743 // for the start position
1746 int lastHeight
= 0 ;
1749 for ( n
= 0 ; n
<= (ItemCount
) pos
; ++n
)
1751 TXNOffsetToPoint(m_txn
, n
, &curpt
);
1753 if ( curpt
.v
> lastHeight
)
1758 lastHeight
= curpt
.v
;
1763 if ( y
) *y
= ypos
;
1764 if ( x
) *x
= xpos
;
1770 void wxMacMLTEControl::ShowPosition( long pos
)
1772 #if TARGET_RT_MAC_MACHO && defined(AVAILABLE_MAC_OS_X_VERSION_10_2_AND_LATER)
1776 TXNOffset selstart
, selend
;
1777 TXNGetSelection( m_txn
, &selstart
, &selend
) ;
1778 TXNOffsetToPoint( m_txn
, selstart
, ¤t
);
1779 TXNOffsetToPoint( m_txn
, pos
, &desired
);
1780 //TODO use HIPoints for 10.3 and above
1781 if ( (UInt32
) TXNScroll
!= (UInt32
) kUnresolvedCFragSymbolAddress
)
1783 OSErr theErr
= noErr
;
1784 SInt32 dv
= desired
.v
- current
.v
;
1785 SInt32 dh
= desired
.h
- current
.h
;
1786 TXNShowSelection( m_txn
, true ) ;
1787 theErr
= TXNScroll( m_txn
, kTXNScrollUnitsInPixels
, kTXNScrollUnitsInPixels
, &dv
, &dh
);
1788 wxASSERT_MSG( theErr
== noErr
, _T("TXNScroll returned an error!") );
1794 void wxMacMLTEControl::SetTXNData( const wxString
& st
, TXNOffset start
, TXNOffset end
)
1797 #if SIZEOF_WCHAR_T == 2
1798 size_t len
= st
.Len() ;
1799 TXNSetData( m_txn
, kTXNUnicodeTextData
, (void*)st
.wc_str(), len
* 2,
1802 wxMBConvUTF16BE converter
;
1803 ByteCount byteBufferLen
= converter
.WC2MB( NULL
, st
.wc_str() , 0 ) ;
1804 UniChar
*unibuf
= (UniChar
*) malloc(byteBufferLen
) ;
1805 converter
.WC2MB( (char*) unibuf
, st
.wc_str() , byteBufferLen
) ;
1806 TXNSetData( m_txn
, kTXNUnicodeTextData
, (void*)unibuf
, byteBufferLen
,
1811 wxCharBuffer text
= st
.mb_str(wxConvLocal
) ;
1812 TXNSetData( m_txn
, kTXNTextData
, (void*)text
.data(), strlen( text
) ,
1818 wxString
wxMacMLTEControl::GetLineText(long lineNo
) const
1822 if ( lineNo
< GetNumberOfLines() )
1830 // get the first possible position in the control
1832 TXNOffsetToPoint(m_txn
, 0, &firstPoint
);
1834 // Iterate through the lines until we reach the one we want,
1835 // adding to our current y pixel point position
1836 while (ypos
< lineNo
)
1838 TXNGetLineMetrics(m_txn
, ypos
++, &lineWidth
, &lineHeight
);
1839 currentHeight
+= lineHeight
;
1842 Point thePoint
= { firstPoint
.v
+ (currentHeight
>> 16), firstPoint
.h
+ (0) };
1843 TXNOffset theOffset
;
1844 TXNPointToOffset(m_txn
, thePoint
, &theOffset
);
1846 wxString content
= GetStringValue() ;
1847 Point currentPoint
= thePoint
;
1848 while(thePoint
.v
== currentPoint
.v
&& theOffset
< content
.length())
1850 line
+= content
[theOffset
];
1851 TXNOffsetToPoint(m_txn
, ++theOffset
, ¤tPoint
);
1857 int wxMacMLTEControl::GetLineLength(long lineNo
) const
1861 if ( lineNo
< GetNumberOfLines() )
1869 // get the first possible position in the control
1871 TXNOffsetToPoint(m_txn
, 0, &firstPoint
);
1873 // Iterate through the lines until we reach the one we want,
1874 // adding to our current y pixel point position
1875 while (ypos
< lineNo
)
1877 TXNGetLineMetrics(m_txn
, ypos
++, &lineWidth
, &lineHeight
);
1878 currentHeight
+= lineHeight
;
1881 Point thePoint
= { firstPoint
.v
+ (currentHeight
>> 16), firstPoint
.h
+ (0) };
1882 TXNOffset theOffset
;
1883 TXNPointToOffset(m_txn
, thePoint
, &theOffset
);
1885 wxString content
= GetStringValue() ;
1886 Point currentPoint
= thePoint
;
1887 while(thePoint
.v
== currentPoint
.v
&& theOffset
< content
.length())
1890 TXNOffsetToPoint(m_txn
, ++theOffset
, ¤tPoint
);
1897 // ----------------------------------------------------------------------------
1898 // MLTE control implementation (classic part)
1899 // ----------------------------------------------------------------------------
1901 // CS:TODO we still have a problem getting properly at the text events of a control because under Carbon
1902 // the MLTE engine registers itself for the key events thus the normal flow never occurs, the only measure for the
1903 // moment is to avoid setting the true focus on the control, the proper solution at the end would be to have
1904 // an alternate path for carbon key events that routes automatically into the same wx flow of events
1908 /* kmUPTextPart is the part code we return to indicate the user has clicked
1909 in the text area of our control */
1910 #define kmUPTextPart 1
1913 /* routines for using existing user pane controls.
1914 These routines are useful for cases where you would like to use an
1915 existing user pane control in, say, a dialog window as a scrolling
1918 /* Utility Routines */
1920 /* kUserClickedToFocusPart is a part code we pass to the SetKeyboardFocus
1921 routine. In our focus switching routine this part code is understood
1922 as meaning 'the user has clicked in the control and we need to switch
1923 the current focus to ourselves before we can continue'. */
1924 #define kUserClickedToFocusPart 100
1926 /* STPTextPaneVars is a structure used for storing the the mUP Control's
1927 internal variables and state information. A handle to this record is
1928 stored in the pane control's reference value field using the
1929 SetControlReference routine. */
1931 class STPTextPaneVars
{
1933 /* OS records referenced */
1934 TXNObject fTXNRec
; /* the txn record */
1935 TXNFrameID fTXNFrame
; /* the txn frame ID */
1936 ControlRef fUserPaneRec
; /* handle to the user pane control */
1937 WindowPtr fOwner
; /* window containing control */
1938 GrafPtr fDrawingEnvironment
; /* grafport where control is drawn */
1940 Boolean fInFocus
; /* true while the focus rect is drawn around the control */
1941 Boolean fIsActive
; /* true while the control is drawn in the active state */
1942 Boolean fTXNObjectActive
; /* reflects the activation state of the text edit record */
1943 Boolean fFocusDrawState
; /* true if focus is drawn (default: true) */
1944 /* calculated locations */
1945 Rect fRBounds
; /* control bounds */
1946 Rect fRTextArea
; /* area where the text is drawn */
1947 Rect fRFocusOutline
; /* rectangle used to draw the focus box */
1948 Rect fRTextOutline
; /* rectangle used to draw the border */
1949 RgnHandle fRTextOutlineRegion
; /* background region for the text, erased before calling TEUpdate */
1950 /* our focus advance override routine */
1951 EventHandlerUPP handlerUPP
;
1952 EventHandlerRef handlerRef
;
1958 /* Univerals Procedure Pointer variables used by the
1959 mUP Control. These variables are set up
1960 the first time that mUPOpenControl is called. */
1961 ControlUserPaneDrawUPP gTPDrawProc
= NULL
;
1962 ControlUserPaneHitTestUPP gTPHitProc
= NULL
;
1963 ControlUserPaneTrackingUPP gTPTrackProc
= NULL
;
1964 ControlUserPaneIdleUPP gTPIdleProc
= NULL
;
1965 ControlUserPaneKeyDownUPP gTPKeyProc
= NULL
;
1966 ControlUserPaneActivateUPP gTPActivateProc
= NULL
;
1967 ControlUserPaneFocusUPP gTPFocusProc
= NULL
;
1969 // one place for calculating all
1970 static void TPCalculateBounds(STPTextPaneVars
*varsp
, const Rect
& bounds
)
1972 SetRect(&varsp
->fRBounds
, bounds
.left
, bounds
.top
, bounds
.right
, bounds
.bottom
);
1973 SetRect(&varsp
->fRFocusOutline
, bounds
.left
, bounds
.top
, bounds
.right
, bounds
.bottom
);
1974 // eventually make TextOutline inset 1,1
1975 SetRect(&varsp
->fRTextOutline
, bounds
.left
, bounds
.top
, bounds
.right
, bounds
.bottom
);
1976 if ( !varsp
->fNoBorders
)
1978 SetRect(&varsp
->fRTextArea
, bounds
.left
+ 2 , bounds
.top
+ (varsp
->fMultiline
? 0 : 2) ,
1979 bounds
.right
- (varsp
->fMultiline
? 0 : 2), bounds
.bottom
- (varsp
->fMultiline
? 0 : 2));
1983 SetRect(&varsp
->fRTextArea
, bounds
.left
, bounds
.top
,
1984 bounds
.right
, bounds
.bottom
);
1988 OSStatus
MLTESetObjectVisibility( STPTextPaneVars
*varsp
, Boolean vis
, long wxStyle
)
1990 OSStatus err
= noErr
;
1991 #if TARGET_API_MAC_OSX
1992 TXNControlTag iControlTags
[1] = { kTXNVisibilityTag
};
1993 TXNControlData iControlData
[1] = {{ vis
}};
1994 err
= ::TXNSetTXNObjectControls( varsp
->fTXNRec
, false, 1, iControlTags
, iControlData
);
1996 wxTextCtrl
* textctrl
= (wxTextCtrl
*) GetControlReference(varsp
->fUserPaneRec
);
1997 if ( vis
&& textctrl
)
2000 UMAGetControlBoundsInWindowCoords( varsp
->fUserPaneRec
, &bounds
);
2001 TPCalculateBounds( varsp
, bounds
) ;
2002 wxMacWindowClipper
cl(textctrl
) ;
2003 TXNSetFrameBounds( varsp
->fTXNRec
, varsp
->fRTextArea
.top
, varsp
->fRTextArea
.left
,
2004 varsp
->fRTextArea
.bottom
, varsp
->fRTextArea
.right
, varsp
->fTXNFrame
);
2005 TXNShowSelection( varsp
->fTXNRec
, kTXNShowStart
);
2010 // make sure we don't miss changes as carbon events are not available for these under classic
2011 static void TPUpdateVisibility(ControlRef theControl
) {
2012 wxTextCtrl
* textctrl
= (wxTextCtrl
*) GetControlReference(theControl
);
2013 if ( textctrl
== NULL
)
2016 STPTextPaneVars
*varsp
= (STPTextPaneVars
*) ((wxMacMLTEClassicControl
*)textctrl
->GetPeer())->m_macTXNvars
;
2019 UMAGetControlBoundsInWindowCoords(theControl
, &bounds
);
2020 if ( textctrl
->MacIsReallyShown() != varsp
->fVisible
)
2022 // invalidate old position
2023 // InvalWindowRect( GetControlOwner( theControl ) , &varsp->fRBounds ) ;
2024 varsp
->fVisible
= textctrl
->MacIsReallyShown() ;
2026 if ( !EqualRect( &bounds
, &varsp
->fRBounds
) )
2029 Rect oldBounds
= varsp
->fRBounds
;
2030 TPCalculateBounds( varsp
, bounds
) ;
2031 // we only recalculate when visible, otherwise scrollbars get drawn at incorrect places
2032 if ( varsp
->fVisible
)
2034 wxMacWindowClipper
cl(textctrl
) ;
2035 TXNSetFrameBounds( varsp
->fTXNRec
, varsp
->fRTextArea
.top
, varsp
->fRTextArea
.left
,
2036 varsp
->fRTextArea
.bottom
, varsp
->fRTextArea
.right
, varsp
->fTXNFrame
);
2038 InvalWindowRect( GetControlOwner( theControl
) , &oldBounds
) ;
2039 InvalWindowRect( GetControlOwner( theControl
) , &varsp
->fRBounds
) ;
2043 // make correct activations
2044 static void TPActivatePaneText(STPTextPaneVars
*varsp
, Boolean setActive
) {
2046 wxTextCtrl
* textctrl
= (wxTextCtrl
*) GetControlReference(varsp
->fUserPaneRec
);
2047 if (varsp
->fTXNObjectActive
!= setActive
&& textctrl
->MacIsReallyShown() )
2049 varsp
->fTXNObjectActive
= setActive
;
2050 TXNActivate(varsp
->fTXNRec
, varsp
->fTXNFrame
, varsp
->fTXNObjectActive
);
2051 if (varsp
->fInFocus
)
2052 TXNFocus( varsp
->fTXNRec
, varsp
->fTXNObjectActive
);
2056 // update focus outlines
2057 static void TPRedrawFocusOutline(STPTextPaneVars
*varsp
) {
2060 if (varsp
->fFocusDrawState
!= (varsp
->fIsActive
&& varsp
->fInFocus
))
2062 varsp
->fFocusDrawState
= (varsp
->fIsActive
&& varsp
->fInFocus
);
2063 DrawThemeFocusRect(&varsp
->fRFocusOutline
, varsp
->fFocusDrawState
);
2067 // update TXN focus state
2068 static void TPFocusPaneText(STPTextPaneVars
*varsp
, Boolean setFocus
) {
2069 wxTextCtrl
* textctrl
= (wxTextCtrl
*) GetControlReference(varsp
->fUserPaneRec
);
2071 if (varsp
->fInFocus
!= setFocus
&& textctrl
->MacIsReallyShown()) {
2072 varsp
->fInFocus
= setFocus
;
2073 TXNFocus( varsp
->fTXNRec
, varsp
->fInFocus
);
2078 static pascal void TPPaneDrawProc(ControlRef theControl
, ControlPartCode thePart
) {
2079 /* set up our globals */
2081 wxTextCtrl
* textctrl
= (wxTextCtrl
*) GetControlReference(theControl
);
2082 if ( textctrl
== NULL
)
2084 TPUpdateVisibility( theControl
) ;
2086 STPTextPaneVars
*varsp
= (STPTextPaneVars
*) ((wxMacMLTEClassicControl
*)textctrl
->GetPeer())->m_macTXNvars
;
2087 if ( textctrl
->MacIsReallyShown() )
2089 wxMacWindowClipper
clipper( textctrl
) ;
2090 TXNDraw(varsp
->fTXNRec
, NULL
);
2091 if ( !varsp
->fNoBorders
)
2092 DrawThemeEditTextFrame(&varsp
->fRTextOutline
, varsp
->fIsActive
? kThemeStateActive
: kThemeStateInactive
);
2093 TPRedrawFocusOutline( varsp
) ;
2099 /* TPPaneHitTestProc is called when the control manager would
2100 like to determine what part of the control the mouse resides over.
2101 We also call this routine from our tracking proc to determine how
2102 to handle mouse clicks. */
2103 static pascal ControlPartCode
TPPaneHitTestProc(ControlRef theControl
, Point where
) {
2104 ControlPartCode result
;
2105 /* set up our locals and lock down our globals*/
2107 wxTextCtrl
* textctrl
= (wxTextCtrl
*) GetControlReference(theControl
);
2108 if ( textctrl
== NULL
)
2110 TPUpdateVisibility( theControl
) ;
2111 STPTextPaneVars
*varsp
= (STPTextPaneVars
*) ((wxMacMLTEClassicControl
*)textctrl
->GetPeer())->m_macTXNvars
;
2112 if (textctrl
->MacIsReallyShown() )
2114 if (PtInRect(where
, &varsp
->fRBounds
))
2115 result
= kmUPTextPart
;
2118 // sometimes we get the coords also in control local coordinates, therefore test again
2119 if ( textctrl
->MacGetTopLevelWindow()->MacUsesCompositing() )
2122 textctrl
->MacClientToRootWindow( &x
, &y
) ;
2126 if (PtInRect(where
, &varsp
->fRBounds
))
2127 result
= kmUPTextPart
;
2139 /* TPPaneTrackingProc is called when the mouse is being held down
2140 over our control. This routine handles clicks in the text area
2141 and in the scroll bar. */
2142 static pascal ControlPartCode
TPPaneTrackingProc(ControlRef theControl
, Point startPt
, ControlActionUPP actionProc
) {
2144 ControlPartCode partCodeResult
;
2145 /* make sure we have some variables... */
2147 wxTextCtrl
* textctrl
= (wxTextCtrl
*) GetControlReference(theControl
);
2148 if ( textctrl
== NULL
)
2150 TPUpdateVisibility( theControl
) ;
2151 STPTextPaneVars
*varsp
= (STPTextPaneVars
*) ((wxMacMLTEClassicControl
*)textctrl
->GetPeer())->m_macTXNvars
;
2152 if (textctrl
->MacIsReallyShown() )
2154 /* we don't do any of these functions unless we're in focus */
2155 if ( ! varsp
->fInFocus
) {
2157 owner
= GetControlOwner(theControl
);
2158 ClearKeyboardFocus(owner
);
2159 SetKeyboardFocus(owner
, theControl
, kUserClickedToFocusPart
);
2161 /* find the location for the click */
2162 // for compositing, we must convert these into toplevel window coordinates, because hittesting expects them
2163 if ( textctrl
->MacGetTopLevelWindow()->MacUsesCompositing() )
2166 textctrl
->MacClientToRootWindow( &x
, &y
) ;
2171 switch (TPPaneHitTestProc(theControl
, startPt
))
2174 /* handle clicks in the text part */
2177 wxMacWindowClipper
clipper( textctrl
) ;
2180 ConvertEventRefToEventRecord( (EventRef
) wxTheApp
->MacGetCurrentEvent() , &rec
) ;
2181 TXNClick( varsp
->fTXNRec
, &rec
);
2188 return partCodeResult
;
2192 /* TPPaneIdleProc is our user pane idle routine. When our text field
2193 is active and in focus, we use this routine to set the cursor. */
2194 static pascal void TPPaneIdleProc(ControlRef theControl
) {
2196 wxTextCtrl
* textctrl
= (wxTextCtrl
*) GetControlReference(theControl
);
2197 if ( textctrl
== NULL
)
2199 TPUpdateVisibility( theControl
) ;
2200 STPTextPaneVars
*varsp
= (STPTextPaneVars
*) ((wxMacMLTEClassicControl
*)textctrl
->GetPeer())->m_macTXNvars
;
2201 if (textctrl
->MacIsReallyShown()) {
2202 /* if we're not active, then we have nothing to say about the cursor */
2203 if (varsp
->fIsActive
) {
2207 wxMacWindowClipper
clipper( textctrl
) ;
2209 /* there's a 'focus thing' and an 'unfocused thing' */
2210 if (varsp
->fInFocus
) {
2211 /* flash the cursor */
2212 SetPort(varsp
->fDrawingEnvironment
);
2213 TXNIdle(varsp
->fTXNRec
);
2214 /* set the cursor */
2215 if (PtInRect(mousep
, &varsp
->fRTextArea
)) {
2217 RectRgn((theRgn
= NewRgn()), &varsp
->fRTextArea
);
2218 TXNAdjustCursor(varsp
->fTXNRec
, theRgn
);
2223 // SetThemeCursor(kThemeArrowCursor);
2226 /* if it's in our bounds, set the cursor */
2227 UMAGetControlBoundsInWindowCoords(theControl
, &bounds
);
2228 if (PtInRect(mousep
, &bounds
))
2230 // SetThemeCursor(kThemeArrowCursor);
2238 /* TPPaneKeyDownProc is called whenever a keydown event is directed
2239 at our control. Here, we direct the keydown event to the text
2240 edit record and redraw the scroll bar and text field as appropriate. */
2241 static pascal ControlPartCode
TPPaneKeyDownProc(ControlRef theControl
,
2242 SInt16 keyCode
, SInt16 charCode
, SInt16 modifiers
) {
2244 wxTextCtrl
* textctrl
= (wxTextCtrl
*) GetControlReference(theControl
);
2245 if ( textctrl
== NULL
)
2247 TPUpdateVisibility( theControl
) ;
2249 STPTextPaneVars
*varsp
= (STPTextPaneVars
*) ((wxMacMLTEClassicControl
*)textctrl
->GetPeer())->m_macTXNvars
;
2250 if (varsp
->fInFocus
)
2252 /* turn autoscrolling on and send the key event to text edit */
2253 wxMacWindowClipper
clipper( textctrl
) ;
2255 memset( &ev
, 0 , sizeof( ev
) ) ;
2257 ev
.modifiers
= modifiers
;
2258 ev
.message
= (( keyCode
<< 8 ) & keyCodeMask
) + ( charCode
& charCodeMask
) ;
2259 TXNKeyDown( varsp
->fTXNRec
, &ev
);
2261 return kControlEntireControl
;
2265 /* TPPaneActivateProc is called when the window containing
2266 the user pane control receives activate events. Here, we redraw
2267 the control and it's text as necessary for the activation state. */
2268 static pascal void TPPaneActivateProc(ControlRef theControl
, Boolean activating
) {
2270 wxTextCtrl
* textctrl
= (wxTextCtrl
*) GetControlReference(theControl
);
2272 if ( textctrl
== NULL
)
2274 TPUpdateVisibility( theControl
) ;
2276 STPTextPaneVars
*varsp
= (STPTextPaneVars
*) ((wxMacMLTEClassicControl
*)textctrl
->GetPeer())->m_macTXNvars
;
2278 varsp
->fIsActive
= activating
;
2279 wxMacWindowClipper
clipper( textctrl
) ;
2280 TPActivatePaneText(varsp
, varsp
->fIsActive
&& varsp
->fInFocus
);
2281 /* redraw the frame */
2282 if ( textctrl
->MacIsReallyShown() )
2284 if ( !varsp
->fNoBorders
)
2285 DrawThemeEditTextFrame(&varsp
->fRTextOutline
, varsp
->fIsActive
? kThemeStateActive
: kThemeStateInactive
);
2286 TPRedrawFocusOutline( varsp
) ;
2291 /* TPPaneFocusProc is called when every the focus changes to or
2292 from our control. Herein, switch the focus appropriately
2293 according to the parameters and redraw the control as
2295 static pascal ControlPartCode
TPPaneFocusProc(ControlRef theControl
, ControlFocusPart action
) {
2296 ControlPartCode focusResult
;
2298 focusResult
= kControlFocusNoPart
;
2299 wxTextCtrl
* textctrl
= (wxTextCtrl
*) GetControlReference(theControl
);
2300 if ( textctrl
== NULL
)
2302 TPUpdateVisibility( theControl
) ;
2303 STPTextPaneVars
*varsp
= (STPTextPaneVars
*) ((wxMacMLTEClassicControl
*)textctrl
->GetPeer())->m_macTXNvars
;
2304 /* if kControlFocusPrevPart and kControlFocusNextPart are received when the user is
2305 tabbing forwards (or shift tabbing backwards) through the items in the dialog,
2306 and kControlFocusNextPart will be received. When the user clicks in our field
2307 and it is not the current focus, then the constant kUserClickedToFocusPart will
2308 be received. The constant kControlFocusNoPart will be received when our control
2309 is the current focus and the user clicks in another control. In your focus routine,
2310 you should respond to these codes as follows:
2312 kControlFocusNoPart - turn off focus and return kControlFocusNoPart. redraw
2313 the control and the focus rectangle as necessary.
2315 kControlFocusPrevPart or kControlFocusNextPart - toggle focus on or off
2316 depending on its current state. redraw the control and the focus rectangle
2317 as appropriate for the new focus state. If the focus state is 'off', return the constant
2318 kControlFocusNoPart, otherwise return a non-zero part code.
2319 kUserClickedToFocusPart - is a constant defined for this example. You should
2320 define your own value for handling click-to-focus type events. */
2321 /* calculate the next highlight state */
2324 case kControlFocusNoPart
:
2325 TPFocusPaneText(varsp
, false);
2326 focusResult
= kControlFocusNoPart
;
2328 case kUserClickedToFocusPart
:
2329 TPFocusPaneText(varsp
, true);
2332 case kControlFocusPrevPart
:
2333 case kControlFocusNextPart
:
2334 TPFocusPaneText(varsp
, ( ! varsp
->fInFocus
));
2335 focusResult
= varsp
->fInFocus
? 1 : kControlFocusNoPart
;
2338 TPActivatePaneText(varsp
, varsp
->fIsActive
&& varsp
->fInFocus
);
2339 /* redraw the text fram and focus rectangle to indicate the
2341 if ( textctrl
->MacIsReallyShown() )
2343 wxMacWindowClipper
c( textctrl
) ;
2344 if ( !varsp
->fNoBorders
)
2345 DrawThemeEditTextFrame(&varsp
->fRTextOutline
, varsp
->fIsActive
? kThemeStateActive
: kThemeStateInactive
);
2346 TPRedrawFocusOutline( varsp
) ;
2351 wxMacMLTEClassicControl::wxMacMLTEClassicControl( wxWindow
*wxPeer
,
2352 const wxString
& str
,
2354 const wxSize
& size
, long style
)
2356 m_font
= wxPeer
->GetFont() ;
2357 m_windowStyle
= style
;
2358 Rect bounds
= wxMacGetBoundsForControl( wxPeer
, pos
, size
) ;
2360 wxMacConvertNewlines10To13( &st
) ;
2364 featurSet
= kControlSupportsEmbedding
| kControlSupportsFocus
| kControlWantsIdle
2365 | kControlWantsActivate
| kControlHandlesTracking
| kControlHasSpecialBackground
2366 | kControlGetsFocusOnClick
| kControlSupportsLiveFeedback
;
2367 /* create the control */
2369 verify_noerr( ::CreateUserPaneControl( MAC_WXHWND(wxPeer
->GetParent()->MacGetTopLevelWindowRef()), &bounds
, featurSet
, &m_controlRef
) );
2372 // wxMacWindowClipper c(wxPeer) ;
2376 if ( wxPeer
->MacIsReallyShown() )
2377 MLTESetObjectVisibility( (STPTextPaneVars
*) m_macTXNvars
, true , style
) ;
2380 // wxMacWindowClipper clipper( wxPeer ) ;
2382 TPUpdateVisibility( m_controlRef
) ;
2384 SetTXNData( st
, kTXNStartOffset
, kTXNEndOffset
) ;
2386 TXNSetSelection( m_txn
, 0, 0);
2387 TXNShowSelection( m_txn
, kTXNShowStart
);
2390 AdjustCreationAttributes( *wxWHITE
, true ) ;
2393 wxMacMLTEClassicControl::~wxMacMLTEClassicControl()
2395 // SetControlReference(m_controlRef , 0) ;
2396 TXNDeleteObject(m_txn
);
2400 void wxMacMLTEClassicControl::VisibilityChanged(bool shown
)
2402 MLTESetObjectVisibility((STPTextPaneVars
*) m_macTXNvars
, shown
, m_windowStyle
) ;
2404 InvalWindowRect( GetControlOwner( m_controlRef
) , &((STPTextPaneVars
*)m_macTXNvars
)->fRBounds
) ;
2407 OSStatus
wxMacMLTEClassicControl::DoCreate()
2410 WindowRef theWindow
;
2412 OSStatus err
= noErr
;
2414 /* set up our globals */
2415 if (gTPDrawProc
== NULL
) gTPDrawProc
= NewControlUserPaneDrawUPP(TPPaneDrawProc
);
2416 if (gTPHitProc
== NULL
) gTPHitProc
= NewControlUserPaneHitTestUPP(TPPaneHitTestProc
);
2417 if (gTPTrackProc
== NULL
) gTPTrackProc
= NewControlUserPaneTrackingUPP(TPPaneTrackingProc
);
2418 if (gTPIdleProc
== NULL
) gTPIdleProc
= NewControlUserPaneIdleUPP(TPPaneIdleProc
);
2419 if (gTPKeyProc
== NULL
) gTPKeyProc
= NewControlUserPaneKeyDownUPP(TPPaneKeyDownProc
);
2420 if (gTPActivateProc
== NULL
) gTPActivateProc
= NewControlUserPaneActivateUPP(TPPaneActivateProc
);
2421 if (gTPFocusProc
== NULL
) gTPFocusProc
= NewControlUserPaneFocusUPP(TPPaneFocusProc
);
2423 /* allocate our private storage */
2424 m_macTXNvars
= (STPTextPaneVars
*) malloc(sizeof(STPTextPaneVars
));
2426 /* set the initial settings for our private data */
2427 m_macTXNvars
->fMultiline
= m_windowStyle
& wxTE_MULTILINE
;
2428 m_macTXNvars
->fNoBorders
= m_windowStyle
& wxNO_BORDER
;
2429 m_macTXNvars
->fInFocus
= false;
2430 m_macTXNvars
->fIsActive
= true;
2431 m_macTXNvars
->fTXNObjectActive
= false;
2432 m_macTXNvars
->fFocusDrawState
= false ;
2433 m_macTXNvars
->fUserPaneRec
= m_controlRef
;
2434 m_macTXNvars
->fVisible
= true ;
2436 theWindow
= m_macTXNvars
->fOwner
= GetControlOwner(m_controlRef
);
2438 m_macTXNvars
->fDrawingEnvironment
= (GrafPtr
) GetWindowPort(theWindow
);
2440 /* set up the user pane procedures */
2441 SetControlData(m_controlRef
, kControlEntireControl
, kControlUserPaneDrawProcTag
, sizeof(gTPDrawProc
), &gTPDrawProc
);
2442 SetControlData(m_controlRef
, kControlEntireControl
, kControlUserPaneHitTestProcTag
, sizeof(gTPHitProc
), &gTPHitProc
);
2443 SetControlData(m_controlRef
, kControlEntireControl
, kControlUserPaneTrackingProcTag
, sizeof(gTPTrackProc
), &gTPTrackProc
);
2444 SetControlData(m_controlRef
, kControlEntireControl
, kControlUserPaneIdleProcTag
, sizeof(gTPIdleProc
), &gTPIdleProc
);
2445 SetControlData(m_controlRef
, kControlEntireControl
, kControlUserPaneKeyDownProcTag
, sizeof(gTPKeyProc
), &gTPKeyProc
);
2446 SetControlData(m_controlRef
, kControlEntireControl
, kControlUserPaneActivateProcTag
, sizeof(gTPActivateProc
), &gTPActivateProc
);
2447 SetControlData(m_controlRef
, kControlEntireControl
, kControlUserPaneFocusProcTag
, sizeof(gTPFocusProc
), &gTPFocusProc
);
2449 /* calculate the rectangles used by the control */
2450 UMAGetControlBoundsInWindowCoords(m_controlRef
, &bounds
);
2451 m_macTXNvars
->fRTextOutlineRegion
= NewRgn() ;
2452 TPCalculateBounds( m_macTXNvars
, bounds
) ;
2454 /* set up the drawing environment */
2455 SetPort(m_macTXNvars
->fDrawingEnvironment
);
2457 /* create the new edit field */
2459 TXNFrameOptions frameOptions
= FrameOptionsFromWXStyle( m_windowStyle
) ;
2461 verify_noerr(TXNNewObject(NULL
, m_macTXNvars
->fOwner
, &m_macTXNvars
->fRTextArea
,
2463 kTXNTextEditStyleFrameType
,
2465 kTXNSystemDefaultEncoding
,
2466 &m_macTXNvars
->fTXNRec
, &m_macTXNvars
->fTXNFrame
, (TXNObjectRefcon
) m_macTXNvars
));
2467 m_txn
= m_macTXNvars
->fTXNRec
;
2469 /* perform final activations and setup for our text field. Here,
2470 we assume that the window is going to be the 'active' window. */
2471 TPActivatePaneText(m_macTXNvars
, m_macTXNvars
->fIsActive
&& m_macTXNvars
->fInFocus
);
2478 // Classic controls are not initially focused and
2479 // smaller ones are focused badly with the focus rect
2480 // this "fixes" the above issue - but there is probably a
2483 // Still, on smaller text controls the focus rect is off
2486 bool wxMacMLTEClassicControl::NeedsFocusRect() const
2488 return m_windowStyle
& wxNO_BORDER
? false : true;
2491 // ----------------------------------------------------------------------------
2492 // MLTE control implementation (OSX part)
2493 // ----------------------------------------------------------------------------
2495 #if TARGET_API_MAC_OSX
2497 #if MAC_OS_X_VERSION_MAX_ALLOWED > MAC_OS_X_VERSION_10_2
2499 wxMacMLTEHIViewControl::wxMacMLTEHIViewControl( wxWindow
*wxPeer
,
2500 const wxString
& str
,
2502 const wxSize
& size
, long style
)
2504 m_font
= wxPeer
->GetFont() ;
2505 m_windowStyle
= style
;
2506 Rect bounds
= wxMacGetBoundsForControl( wxPeer
, pos
, size
) ;
2508 wxMacConvertNewlines10To13( &st
) ;
2510 HIRect hr
= { bounds
.left
, bounds
.top
, bounds
.right
- bounds
.left
, bounds
.bottom
- bounds
.top
} ;
2512 m_scrollView
= NULL
;
2513 TXNFrameOptions frameOptions
= FrameOptionsFromWXStyle( style
) ;
2514 if ( frameOptions
& (kTXNWantVScrollBarMask
|kTXNWantHScrollBarMask
) )
2516 HIScrollViewCreate(( frameOptions
& kTXNWantHScrollBarMask
? kHIScrollViewOptionsHorizScroll
: 0) |
2517 ( frameOptions
& kTXNWantVScrollBarMask
? kHIScrollViewOptionsVertScroll
: 0 ) , &m_scrollView
) ;
2519 HIViewSetFrame( m_scrollView
, &hr
);
2520 HIViewSetVisible( m_scrollView
, true );
2524 HITextViewCreate( NULL
, 0, frameOptions
, &m_textView
) ;
2525 m_txn
= HITextViewGetTXNObject( m_textView
) ;
2526 HIViewSetVisible( m_textView
, true ) ;
2529 HIViewAddSubview( m_scrollView
, m_textView
) ;
2530 m_controlRef
= m_scrollView
;
2531 wxPeer
->MacInstallEventHandler( (WXWidget
) m_textView
) ;
2535 HIViewSetFrame( m_textView
, &hr
);
2536 m_controlRef
= m_textView
;
2540 SetTXNData( st
, kTXNStartOffset
, kTXNEndOffset
) ;
2542 TXNSetSelection( m_txn
, 0, 0);
2543 TXNShowSelection( m_txn
, kTXNShowStart
);
2545 AdjustCreationAttributes( *wxWHITE
, true ) ;
2548 OSStatus
wxMacMLTEHIViewControl::SetFocus( ControlFocusPart focusPart
)
2550 return SetKeyboardFocus( GetControlOwner( m_textView
) ,
2551 m_textView
, focusPart
) ;
2554 bool wxMacMLTEHIViewControl::HasFocus() const
2556 ControlRef control
;
2557 GetKeyboardFocus( GetUserFocusWindow() , &control
) ;
2558 return control
== m_textView
;
2561 bool wxMacMLTEHIViewControl::NeedsFocusRect() const
2563 return m_windowStyle
& wxNO_BORDER
? false : true;
2566 #endif // MAC_OS_X_VERSION_MAX_ALLOWED > MAC_OS_X_VERSION_10_2
2571 #endif // wxUSE_TEXTCTRL