1 /////////////////////////////////////////////////////////////////////////////
4 // Author: Stefan Csomor
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 #ifndef wxMAC_AWAYS_USE_MLTE
60 #define wxMAC_AWAYS_USE_MLTE 1
63 #include <MacTextEditor.h>
64 #include <ATSUnicode.h>
65 #include <TextCommon.h>
66 #include <TextEncodingConverter.h>
67 #include "wx/mac/uma.h"
73 virtual ~wxMacFunctor() {}
74 virtual void* operator()() = 0 ;
75 static void* CallBackProc(void *param
)
77 wxMacFunctor
* f
= (wxMacFunctor
*) param
;
78 void *result
= (*f
)() ;
83 template<typename classtype
,typename param1type
>
84 class wxMacObjectFunctor1
: public wxMacFunctor
86 typedef void (classtype::*function
)( param1type p1
) ;
87 typedef void (classtype::*ref_function
)( const param1type
& p1
) ;
89 wxMacObjectFunctor1( classtype
*obj
, function f
, param1type p1
) :
97 wxMacObjectFunctor1( classtype
*obj
, ref_function f
, param1type p1
) :
105 ~wxMacObjectFunctor1() {}
107 virtual void* operator()()
109 (m_object
->*m_function
)(m_param1
) ;
113 classtype
* m_object
;
114 param1type m_param1
;
117 function m_function
;
118 ref_function m_refFunction
;
122 template<typename classtype
, typename param1type
>
123 void* wxMacMPRemoteCall( classtype
*object
, void (classtype::*function
)( param1type p1
) , param1type p1
)
125 wxMacObjectFunctor1
<classtype
,param1type
> params(object
,function
,p1
) ;
127 MPRemoteCall( wxMacFunctor::CallBackProc
, ¶ms
, kMPOwningProcessRemoteContext
) ;
131 template<typename classtype
, typename param1type
>
132 void* wxMacMPRemoteCall( classtype
*object
, void (classtype::*function
)( const param1type
& p1
) , param1type p1
)
134 wxMacObjectFunctor1
<classtype
,param1type
> params(object
,function
,p1
) ;
136 MPRemoteCall( wxMacFunctor::CallBackProc
, ¶ms
, kMPOwningProcessRemoteContext
) ;
140 template<typename classtype
, typename param1type
>
141 void* wxMacMPRemoteGUICall( classtype
*object
, void (classtype::*function
)( param1type p1
) , param1type p1
)
144 void *result
= wxMacMPRemoteCall( object
, function
, p1
) ;
149 template<typename classtype
, typename param1type
>
150 void* wxMacMPRemoteGUICall( classtype
*object
, void (classtype::*function
)( const param1type
& p1
) , param1type p1
)
153 void *result
= wxMacMPRemoteCall( object
, function
, p1
) ;
157 // common interface for all implementations
158 class wxMacTextControl
: public wxMacControl
162 ~wxMacTextControl() ;
164 virtual wxString
GetStringValue() const = 0 ;
165 virtual void SetStringValue( const wxString
&val
) = 0 ;
166 virtual void SetStyle(long start
, long end
, const wxTextAttr
& style
) ;
167 virtual void Copy() ;
169 virtual void Paste() ;
170 virtual bool CanPaste() const ;
171 virtual void SetEditable(bool editable
) ;
172 virtual long GetLastPosition() const ;
173 virtual void Replace( long from
, long to
, const wxString str
) ;
174 virtual void Remove( long from
, long to
) = 0 ;
175 virtual void SetSelection( long from
, long to
) = 0 ;
176 virtual void GetSelection( long* from
, long* to
) const = 0 ;
177 virtual void WriteText(const wxString
& str
) = 0 ;
179 virtual void Clear() ;
180 virtual bool CanUndo() const;
181 virtual void Undo() ;
182 virtual bool CanRedo() const;
183 virtual void Redo() ;
184 virtual int GetNumberOfLines() const ;
185 virtual long XYToPosition(long x
, long y
) const;
186 virtual bool PositionToXY(long pos
, long *x
, long *y
) const ;
187 virtual void ShowPosition( long WXUNUSED(pos
) ) ;
188 virtual int GetLineLength(long lineNo
) const ;
189 virtual wxString
GetLineText(long lineNo
) const ;
192 // common parts for implementations based on MLTE
194 class wxMacMLTEControl
: public wxMacTextControl
197 virtual wxString
GetStringValue() const ;
198 virtual void SetStringValue( const wxString
&str
) ;
200 static int ConvertAttribute( const wxTextAttr
& style
, TXNTypeAttributes attr
[] ) ;
201 static TXNFrameOptions
FrameOptionsFromWXStyle( long wxStyle
) ;
202 void AdjustCreationAttributes( const wxColour
& background
, bool visible
) ;
204 virtual void SetFont( const wxFont
& font
, const wxColour
& foreground
, long windowStyle
) ;
205 virtual void SetStyle(long start
, long end
, const wxTextAttr
& style
) ;
206 virtual void Copy() ;
208 virtual void Paste() ;
209 virtual bool CanPaste() const ;
210 virtual void SetEditable(bool editable
) ;
211 virtual long GetLastPosition() const ;
212 virtual void Replace( long from
, long to
, const wxString str
) ;
213 virtual void Remove( long from
, long to
) ;
214 virtual void GetSelection( long* from
, long* to
) const ;
215 virtual void SetSelection( long from
, long to
) ;
217 virtual void WriteText(const wxString
& str
) ;
218 virtual void Clear() ;
220 virtual bool CanUndo() const ;
221 virtual void Undo() ;
222 virtual bool CanRedo() const;
223 virtual void Redo() ;
224 virtual int GetNumberOfLines() const ;
225 virtual long XYToPosition(long x
, long y
) const ;
226 virtual bool PositionToXY(long pos
, long *x
, long *y
) const ;
227 virtual void ShowPosition( long pos
) ;
228 virtual int GetLineLength(long lineNo
) const ;
229 virtual wxString
GetLineText(long lineNo
) const ;
231 void SetTXNData( const wxString
& st
, TXNOffset start
, TXNOffset end
) ;
237 #if TARGET_API_MAC_OSX
239 // implementation available under OSX
241 #if MAC_OS_X_VERSION_MAX_ALLOWED > MAC_OS_X_VERSION_10_2
243 class wxMacMLTEHIViewControl
: public wxMacMLTEControl
246 wxMacMLTEHIViewControl( wxWindow
*wxPeer
,
249 const wxSize
& size
, long style
) ;
250 virtual OSStatus
SetFocus( ControlFocusPart focusPart
) ;
251 virtual bool HasFocus() const ;
252 virtual bool NeedsFocusRect() const ;
254 HIViewRef m_scrollView
;
255 HIViewRef m_textView
;
260 class wxMacUnicodeTextControl
: public wxMacTextControl
263 wxMacUnicodeTextControl( wxWindow
*wxPeer
,
266 const wxSize
& size
, long style
) ;
267 ~wxMacUnicodeTextControl();
268 virtual void VisibilityChanged(bool shown
);
269 virtual wxString
GetStringValue() const ;
270 virtual void SetStringValue( const wxString
&str
) ;
273 virtual void Paste();
274 virtual bool CanPaste() const;
275 virtual void SetEditable(bool editable
) ;
276 virtual void Remove( long from
, long to
) ;
277 virtual void GetSelection( long* from
, long* to
) const ;
278 virtual void SetSelection( long from
, long to
) ;
279 virtual void WriteText(const wxString
& str
) ;
281 // contains the tag for the content (is different for password and non-password controls)
287 // implementation available under classic
289 class STPTextPaneVars
;
291 class wxMacMLTEClassicControl
: public wxMacMLTEControl
294 wxMacMLTEClassicControl( wxWindow
*wxPeer
,
297 const wxSize
& size
, long style
) ;
298 ~wxMacMLTEClassicControl() ;
299 virtual void VisibilityChanged(bool shown
) ;
303 // hack to make public until we have migrated all procs
304 STPTextPaneVars
* m_macTXNvars
;
307 #define TE_UNLIMITED_LENGTH 0xFFFFFFFFUL
309 #if !USE_SHARED_LIBRARY
310 IMPLEMENT_DYNAMIC_CLASS(wxTextCtrl
, wxControl
)
312 BEGIN_EVENT_TABLE(wxTextCtrl
, wxControl
)
313 EVT_DROP_FILES(wxTextCtrl::OnDropFiles
)
314 EVT_CHAR(wxTextCtrl::OnChar
)
315 EVT_MENU(wxID_CUT
, wxTextCtrl::OnCut
)
316 EVT_MENU(wxID_COPY
, wxTextCtrl::OnCopy
)
317 EVT_MENU(wxID_PASTE
, wxTextCtrl::OnPaste
)
318 EVT_MENU(wxID_UNDO
, wxTextCtrl::OnUndo
)
319 EVT_MENU(wxID_REDO
, wxTextCtrl::OnRedo
)
321 EVT_UPDATE_UI(wxID_CUT
, wxTextCtrl::OnUpdateCut
)
322 EVT_UPDATE_UI(wxID_COPY
, wxTextCtrl::OnUpdateCopy
)
323 EVT_UPDATE_UI(wxID_PASTE
, wxTextCtrl::OnUpdatePaste
)
324 EVT_UPDATE_UI(wxID_UNDO
, wxTextCtrl::OnUpdateUndo
)
325 EVT_UPDATE_UI(wxID_REDO
, wxTextCtrl::OnUpdateRedo
)
330 void wxTextCtrl::Init()
335 m_maxLength
= TE_UNLIMITED_LENGTH
;
338 wxTextCtrl::~wxTextCtrl()
343 bool wxTextCtrl::Create(wxWindow
*parent
, wxWindowID id
,
346 const wxSize
& size
, long style
,
347 const wxValidator
& validator
,
348 const wxString
& name
)
350 m_macIsUserPane
= FALSE
;
353 if ( !HasFlag(wxNO_BORDER
) )
354 style
|= wxSUNKEN_BORDER
;
356 if ( !wxTextCtrlBase::Create(parent
, id
, pos
, size
, style
& ~(wxHSCROLL
|wxVSCROLL
), validator
, name
) )
359 wxSize mySize
= size
;
361 Rect bounds
= wxMacGetBoundsForControl( this , pos
, size
) ;
363 if ( m_windowStyle
& wxTE_MULTILINE
)
365 wxASSERT_MSG( !(m_windowStyle
& wxTE_PROCESS_ENTER
),
366 wxT("wxTE_PROCESS_ENTER style is ignored for multiline text controls (they always process it)") );
368 m_windowStyle
|= wxTE_PROCESS_ENTER
;
369 style
|= wxTE_PROCESS_ENTER
;
372 #if TARGET_API_MAC_OSX
373 #if MAC_OS_X_VERSION_MAX_ALLOWED > MAC_OS_X_VERSION_10_2
374 if ( UMAGetSystemVersion() >= 0x1030 )
376 m_peer
= new wxMacMLTEHIViewControl( this , str
, pos
, size
, style
) ;
379 #if !wxMAC_AWAYS_USE_MLTE
382 m_peer
= new wxMacUnicodeTextControl( this , str
, pos
, size
, style
) ;
388 // this control draws the border itself
389 if ( !HasFlag(wxNO_BORDER
) )
390 m_windowStyle
&= ~wxSUNKEN_BORDER
;
391 m_peer
= new wxMacMLTEClassicControl( this , str
, pos
, size
, style
) ;
394 MacPostControlCreate(pos
,size
) ;
396 if ( m_windowStyle
& wxTE_READONLY
)
398 SetEditable( false ) ;
405 void wxTextCtrl::MacVisibilityChanged()
407 GetPeer()->VisibilityChanged( MacIsReallyShown() ) ;
410 void wxTextCtrl::MacEnabledStateChanged()
414 wxString
wxTextCtrl::GetValue() const
416 return GetPeer()->GetStringValue() ;
419 void wxTextCtrl::GetSelection(long* from
, long* to
) const
421 GetPeer()->GetSelection( from
, to
) ;
424 void wxTextCtrl::SetValue(const wxString
& str
)
427 if ( GetValue() == str
)
430 GetPeer()->SetStringValue(str
) ;
433 void wxTextCtrl::SetMaxLength(unsigned long len
)
438 bool wxTextCtrl::SetFont( const wxFont
& font
)
440 if ( !wxTextCtrlBase::SetFont( font
) )
443 GetPeer()->SetFont( font
, GetForegroundColour() , GetWindowStyle() ) ;
447 bool wxTextCtrl::SetStyle(long start
, long end
, const wxTextAttr
& style
)
449 GetPeer()->SetStyle( start
, end
, style
) ;
453 bool wxTextCtrl::SetDefaultStyle(const wxTextAttr
& style
)
455 wxTextCtrlBase::SetDefaultStyle( style
) ;
456 SetStyle( kTXNUseCurrentSelection
, kTXNUseCurrentSelection
, GetDefaultStyle() ) ;
460 // Clipboard operations
461 void wxTextCtrl::Copy()
469 void wxTextCtrl::Cut()
475 wxCommandEvent
event(wxEVT_COMMAND_TEXT_UPDATED
, m_windowId
);
476 event
.SetString( GetValue() ) ;
477 event
.SetEventObject( this );
478 GetEventHandler()->ProcessEvent(event
);
482 void wxTextCtrl::Paste()
487 // eventually we should add setting the default style again
489 wxCommandEvent
event(wxEVT_COMMAND_TEXT_UPDATED
, m_windowId
);
490 event
.SetString( GetValue() ) ;
491 event
.SetEventObject( this );
492 GetEventHandler()->ProcessEvent(event
);
496 bool wxTextCtrl::CanCopy() const
498 // Can copy if there's a selection
500 GetSelection(& from
, & to
);
504 bool wxTextCtrl::CanCut() const
510 // Can cut if there's a selection
512 GetSelection(& from
, & to
);
516 bool wxTextCtrl::CanPaste() const
521 return GetPeer()->CanPaste() ;
524 void wxTextCtrl::SetEditable(bool editable
)
526 if ( editable
!= m_editable
)
528 m_editable
= editable
;
529 GetPeer()->SetEditable( editable
) ;
533 void wxTextCtrl::SetInsertionPoint(long pos
)
535 SetSelection( pos
, pos
) ;
538 void wxTextCtrl::SetInsertionPointEnd()
540 long pos
= GetLastPosition();
541 SetInsertionPoint(pos
);
544 long wxTextCtrl::GetInsertionPoint() const
547 GetSelection( &begin
, &end
) ;
551 long wxTextCtrl::GetLastPosition() const
553 return GetPeer()->GetLastPosition( ) ;
556 void wxTextCtrl::Replace(long from
, long to
, const wxString
& str
)
558 GetPeer()->Replace( from
, to
, str
) ;
561 void wxTextCtrl::Remove(long from
, long to
)
563 GetPeer()->Remove( from
, to
) ;
566 void wxTextCtrl::SetSelection(long from
, long to
)
568 GetPeer()->SetSelection( from
, to
) ;
571 bool wxTextCtrl::LoadFile(const wxString
& file
)
573 if ( wxTextCtrlBase::LoadFile(file
) )
581 void wxTextCtrl::WriteText(const wxString
& str
)
583 // TODO this MPRemoting will be moved into a remoting peer proxy for any command
584 if ( !wxIsMainThread() )
586 // unfortunately CW 8 is not able to correctly deduce the template types, so we have
587 // to instantiate explicitely
588 wxMacMPRemoteGUICall
<wxTextCtrl
,wxString
>( this , &wxTextCtrl::WriteText
, str
) ;
593 GetPeer()->WriteText( str
) ;
597 void wxTextCtrl::AppendText(const wxString
& text
)
599 SetInsertionPointEnd();
603 void wxTextCtrl::Clear()
608 bool wxTextCtrl::IsModified() const
613 bool wxTextCtrl::IsEditable() const
615 return IsEnabled() && m_editable
;
618 bool wxTextCtrl::AcceptsFocus() const
620 // we don't want focus if we can't be edited
621 return /*IsEditable() && */ wxControl::AcceptsFocus();
624 wxSize
wxTextCtrl::DoGetBestSize() const
630 switch( m_windowVariant
)
632 case wxWINDOW_VARIANT_NORMAL
:
635 case wxWINDOW_VARIANT_SMALL
:
638 case wxWINDOW_VARIANT_MINI
:
646 if ( HasFlag(wxNO_BORDER
) )
649 if ( m_windowStyle
& wxTE_MULTILINE
)
654 return wxSize(wText
, hText
);
657 // ----------------------------------------------------------------------------
659 // ----------------------------------------------------------------------------
661 void wxTextCtrl::Undo()
669 void wxTextCtrl::Redo()
677 bool wxTextCtrl::CanUndo() const
683 return GetPeer()->CanUndo() ;
686 bool wxTextCtrl::CanRedo() const
692 return GetPeer()->CanRedo() ;
695 void wxTextCtrl::MarkDirty()
700 void wxTextCtrl::DiscardEdits()
705 int wxTextCtrl::GetNumberOfLines() const
707 return GetPeer()->GetNumberOfLines() ;
710 long wxTextCtrl::XYToPosition(long x
, long y
) const
712 return GetPeer()->XYToPosition( x
, y
) ;
715 bool wxTextCtrl::PositionToXY(long pos
, long *x
, long *y
) const
717 return GetPeer()->PositionToXY(pos
, x
, y
) ;
720 void wxTextCtrl::ShowPosition(long pos
)
722 return GetPeer()->ShowPosition(pos
) ;
725 int wxTextCtrl::GetLineLength(long lineNo
) const
727 return GetPeer()->GetLineLength(lineNo
) ;
730 wxString
wxTextCtrl::GetLineText(long lineNo
) const
732 return GetPeer()->GetLineText(lineNo
) ;
739 void wxTextCtrl::Command(wxCommandEvent
& event
)
741 SetValue (event
.GetString());
742 ProcessCommand (event
);
745 void wxTextCtrl::OnDropFiles(wxDropFilesEvent
& event
)
747 // By default, load the first file into the text window.
748 if (event
.GetNumberOfFiles() > 0)
750 LoadFile(event
.GetFiles()[0]);
754 void wxTextCtrl::OnChar(wxKeyEvent
& event
)
756 int key
= event
.GetKeyCode() ;
757 bool eat_key
= false ;
759 if ( key
== 'c' && event
.MetaDown() )
766 if ( !IsEditable() && key
!= WXK_LEFT
&& key
!= WXK_RIGHT
&& key
!= WXK_DOWN
&& key
!= WXK_UP
&& key
!= WXK_TAB
&&
767 !( key
== WXK_RETURN
&& ( (m_windowStyle
& wxPROCESS_ENTER
) || (m_windowStyle
& wxTE_MULTILINE
) ) )
768 /* && key != WXK_PRIOR && key != WXK_NEXT && key != WXK_HOME && key != WXK_END */
775 // assume that any key not processed yet is going to modify the control
778 if ( key
== 'v' && event
.MetaDown() )
784 if ( key
== 'x' && event
.MetaDown() )
793 if (m_windowStyle
& wxPROCESS_ENTER
)
795 wxCommandEvent
event(wxEVT_COMMAND_TEXT_ENTER
, m_windowId
);
796 event
.SetEventObject( this );
797 event
.SetString( GetValue() );
798 if ( GetEventHandler()->ProcessEvent(event
) )
801 if ( !(m_windowStyle
& wxTE_MULTILINE
) )
803 wxWindow
*parent
= GetParent();
804 while( parent
&& !parent
->IsTopLevel() && parent
->GetDefaultItem() == NULL
) {
805 parent
= parent
->GetParent() ;
807 if ( parent
&& parent
->GetDefaultItem() )
809 wxButton
*def
= wxDynamicCast(parent
->GetDefaultItem(),
811 if ( def
&& def
->IsEnabled() )
813 wxCommandEvent
event(wxEVT_COMMAND_BUTTON_CLICKED
, def
->GetId() );
814 event
.SetEventObject(def
);
820 // this will make wxWidgets eat the ENTER key so that
821 // we actually prevent line wrapping in a single line
829 if ( !(m_windowStyle
& wxTE_PROCESS_TAB
))
832 if (!event
.ShiftDown())
833 flags
|= wxNavigationKeyEvent::IsForward
;
834 if (event
.ControlDown())
835 flags
|= wxNavigationKeyEvent::WinChange
;
841 // This is necessary (don't know why) or the tab will not
843 WriteText(wxT("\t"));
851 // perform keystroke handling
852 if ( wxTheApp
->MacGetCurrentEvent() != NULL
&& wxTheApp
->MacGetCurrentEventHandlerCallRef() != NULL
)
853 CallNextEventHandler((EventHandlerCallRef
)wxTheApp
->MacGetCurrentEventHandlerCallRef() , (EventRef
) wxTheApp
->MacGetCurrentEvent() ) ;
857 if ( wxMacConvertEventToRecord( (EventRef
) wxTheApp
->MacGetCurrentEvent() , &rec
) )
859 EventRecord
*ev
= &rec
;
862 keychar
= short(ev
->message
& charCodeMask
);
863 keycode
= short(ev
->message
& keyCodeMask
) >> 8 ;
865 m_peer
->HandleKey( keycode
, keychar
, ev
->modifiers
) ;
869 if ( ( key
>= 0x20 && key
< WXK_START
) ||
874 wxCommandEvent
event1(wxEVT_COMMAND_TEXT_UPDATED
, m_windowId
);
875 event1
.SetString( GetValue() ) ;
876 event1
.SetEventObject( this );
877 wxPostEvent(GetEventHandler(),event1
);
881 // ----------------------------------------------------------------------------
882 // standard handlers for standard edit menu events
883 // ----------------------------------------------------------------------------
885 void wxTextCtrl::OnCut(wxCommandEvent
& WXUNUSED(event
))
890 void wxTextCtrl::OnCopy(wxCommandEvent
& WXUNUSED(event
))
895 void wxTextCtrl::OnPaste(wxCommandEvent
& WXUNUSED(event
))
900 void wxTextCtrl::OnUndo(wxCommandEvent
& WXUNUSED(event
))
905 void wxTextCtrl::OnRedo(wxCommandEvent
& WXUNUSED(event
))
910 void wxTextCtrl::OnUpdateCut(wxUpdateUIEvent
& event
)
912 event
.Enable( CanCut() );
915 void wxTextCtrl::OnUpdateCopy(wxUpdateUIEvent
& event
)
917 event
.Enable( CanCopy() );
920 void wxTextCtrl::OnUpdatePaste(wxUpdateUIEvent
& event
)
922 event
.Enable( CanPaste() );
925 void wxTextCtrl::OnUpdateUndo(wxUpdateUIEvent
& event
)
927 event
.Enable( CanUndo() );
930 void wxTextCtrl::OnUpdateRedo(wxUpdateUIEvent
& event
)
932 event
.Enable( CanRedo() );
935 bool wxTextCtrl::MacSetupCursor( const wxPoint
& pt
)
940 // user pane implementation
942 void wxTextCtrl::MacControlUserPaneDrawProc(wxInt16 part
)
946 wxInt16
wxTextCtrl::MacControlUserPaneHitTestProc(wxInt16 x
, wxInt16 y
)
948 return kControlNoPart
;
951 wxInt16
wxTextCtrl::MacControlUserPaneTrackingProc(wxInt16 x
, wxInt16 y
, void* actionProc
)
953 return kControlNoPart
;
956 void wxTextCtrl::MacControlUserPaneIdleProc()
960 wxInt16
wxTextCtrl::MacControlUserPaneKeyDownProc(wxInt16 keyCode
, wxInt16 charCode
, wxInt16 modifiers
)
962 return kControlNoPart
;
965 void wxTextCtrl::MacControlUserPaneActivateProc(bool activating
)
969 wxInt16
wxTextCtrl::MacControlUserPaneFocusProc(wxInt16 action
)
971 return kControlNoPart
;
974 void wxTextCtrl::MacControlUserPaneBackgroundProc(void* info
)
978 // ----------------------------------------------------------------------------
979 // implementation base class
980 // ----------------------------------------------------------------------------
982 wxMacTextControl::wxMacTextControl()
986 wxMacTextControl::~wxMacTextControl()
990 void wxMacTextControl::SetStyle(long start
, long end
, const wxTextAttr
& style
)
994 void wxMacTextControl::Copy()
998 void wxMacTextControl::Cut()
1002 void wxMacTextControl::Paste()
1006 bool wxMacTextControl::CanPaste() const
1011 void wxMacTextControl::SetEditable(bool editable
)
1015 long wxMacTextControl::GetLastPosition() const
1017 return GetStringValue().Length() ;
1020 void wxMacTextControl::Replace( long from
, long to
, const wxString str
)
1024 void wxMacTextControl::Clear()
1026 SetStringValue( wxEmptyString
) ;
1029 bool wxMacTextControl::CanUndo() const
1034 void wxMacTextControl::Undo() { }
1036 bool wxMacTextControl::CanRedo() const
1041 void wxMacTextControl::Redo()
1045 long wxMacTextControl::XYToPosition(long x
, long y
) const
1050 bool wxMacTextControl::PositionToXY(long pos
, long *x
, long *y
) const
1055 void wxMacTextControl::ShowPosition( long WXUNUSED(pos
) )
1059 int wxMacTextControl::GetNumberOfLines() const
1061 ItemCount lines
= 0 ;
1062 wxString content
= GetStringValue() ;
1064 for (size_t i
= 0; i
< content
.Length() ; i
++)
1066 if (content
[i
] == '\r') lines
++;
1071 wxString
wxMacTextControl::GetLineText(long lineNo
) const
1073 // TODO change this if possible to reflect real lines
1074 wxString content
= GetStringValue() ;
1078 for (size_t i
= 0; i
< content
.Length() ; i
++)
1080 if (count
== lineNo
)
1082 // Add chars in line then
1085 for (size_t j
= i
; j
< content
.Length(); j
++)
1087 if (content
[j
] == '\n')
1095 if (content
[i
] == '\n') count
++;
1097 return wxEmptyString
;
1100 int wxMacTextControl::GetLineLength(long lineNo
) const
1102 // TODO change this if possible to reflect real lines
1103 wxString content
= GetStringValue() ;
1107 for (size_t i
= 0; i
< content
.Length() ; i
++)
1109 if (count
== lineNo
)
1111 // Count chars in line then
1113 for (size_t j
= i
; j
< content
.Length(); j
++)
1116 if (content
[j
] == '\n') return count
;
1121 if (content
[i
] == '\n') count
++;
1126 // ----------------------------------------------------------------------------
1127 // standard unicode control implementation
1128 // ----------------------------------------------------------------------------
1130 #if TARGET_API_MAC_OSX
1132 wxMacUnicodeTextControl::wxMacUnicodeTextControl( wxWindow
*wxPeer
,
1133 const wxString
& str
,
1135 const wxSize
& size
, long style
)
1137 m_font
= wxPeer
->GetFont() ;
1138 m_windowStyle
= style
;
1139 Rect bounds
= wxMacGetBoundsForControl( wxPeer
, pos
, size
) ;
1141 wxMacConvertNewlines13To10( &st
) ;
1142 wxMacCFStringHolder
cf(st
, m_font
.GetEncoding()) ;
1143 CFStringRef cfr
= cf
;
1144 Boolean isPassword
= ( m_windowStyle
& wxTE_PASSWORD
) != 0 ;
1145 m_valueTag
= isPassword
? kControlEditTextPasswordCFStringTag
: kControlEditTextCFStringTag
;
1146 CreateEditUnicodeTextControl( MAC_WXHWND(wxPeer
->MacGetTopLevelWindowRef()), &bounds
, cfr
, isPassword
, NULL
, &m_controlRef
) ;
1148 if ( !(m_windowStyle
& wxTE_MULTILINE
) )
1150 SetData
<Boolean
>( kControlEditTextPart
, kControlEditTextSingleLineTag
, true ) ;
1154 wxMacUnicodeTextControl::~wxMacUnicodeTextControl()
1158 void wxMacUnicodeTextControl::VisibilityChanged(bool shown
)
1160 if ( !(m_windowStyle
& wxTE_MULTILINE
) && shown
)
1162 // work around a refresh issue insofar as not always the entire content is shown even if this would be possible
1163 ControlEditTextSelectionRec sel
;
1164 CFStringRef value
= NULL
;
1166 verify_noerr( GetData
<ControlEditTextSelectionRec
>( 0, kControlEditTextSelectionTag
, &sel
) );
1167 verify_noerr( GetData
<CFStringRef
>( 0, m_valueTag
, &value
) );
1168 verify_noerr( SetData
<CFStringRef
>( 0, m_valueTag
, &value
) );
1169 verify_noerr( SetData
<ControlEditTextSelectionRec
>( 0, kControlEditTextSelectionTag
, &sel
) );
1171 CFRelease( value
) ;
1174 wxString
wxMacUnicodeTextControl::GetStringValue() const
1177 CFStringRef value
= GetData
<CFStringRef
>(0,m_valueTag
) ;
1180 wxMacCFStringHolder
cf(value
) ;
1181 result
= cf
.AsString() ;
1183 wxMacConvertNewlines10To13( &result
) ;
1186 void wxMacUnicodeTextControl::SetStringValue( const wxString
&str
)
1189 wxMacConvertNewlines13To10( &st
) ;
1190 wxMacCFStringHolder
cf(st
, m_font
.GetEncoding() ) ;
1191 verify_noerr( SetData
<CFStringRef
>( 0, m_valueTag
, cf
) ) ;
1193 void wxMacUnicodeTextControl::Copy()
1195 SendHICommand( kHICommandCopy
) ;
1197 void wxMacUnicodeTextControl::Cut()
1199 SendHICommand( kHICommandCut
) ;
1201 void wxMacUnicodeTextControl::Paste()
1203 SendHICommand( kHICommandPaste
) ;
1205 bool wxMacUnicodeTextControl::CanPaste() const
1209 void wxMacUnicodeTextControl::SetEditable(bool editable
)
1211 SetData
<Boolean
>( 0 , kControlEditTextLockedTag
, (Boolean
) !editable
) ;
1213 void wxMacUnicodeTextControl::Remove( long from
, long to
)
1217 void wxMacUnicodeTextControl::GetSelection( long* from
, long* to
) const
1219 ControlEditTextSelectionRec sel
;
1220 verify_noerr(GetData
<ControlEditTextSelectionRec
>( 0, kControlEditTextSelectionTag
, &sel
) ) ;
1221 if ( from
) *from
= sel
.selStart
;
1222 if ( to
) *to
= sel
.selEnd
;
1225 void wxMacUnicodeTextControl::SetSelection( long from
, long to
)
1227 ControlEditTextSelectionRec sel
;
1228 sel
.selStart
= from
;
1230 SetData
<ControlEditTextSelectionRec
>( 0 , kControlEditTextSelectionTag
, &sel
) ;
1233 void wxMacUnicodeTextControl::WriteText(const wxString
& str
)
1236 wxMacConvertNewlines13To10( &st
) ;
1237 #if MAC_OS_X_VERSION_MAX_ALLOWED > MAC_OS_X_VERSION_10_2
1238 wxMacCFStringHolder
cf(st
, m_font
.GetEncoding() ) ;
1239 CFStringRef value
= cf
;
1240 SetData
<CFStringRef
>( 0, kControlEditTextInsertCFStringRefTag
, &value
);
1242 wxString val
= GetStringValue() ;
1244 GetSelection( &start
, &end
) ;
1245 val
.Remove( start
, end
- start
) ;
1246 val
.insert( start
, str
) ;
1247 SetStringValue( val
) ;
1248 SetInsertionPoint( start
+ str
.Length() ) ;
1254 // ----------------------------------------------------------------------------
1255 // MLTE control implementation (common part)
1256 // ----------------------------------------------------------------------------
1258 #if TARGET_API_MAC_OSX == 0
1259 // declaration needed because of one line in the code...
1260 static void TPUpdateVisibility(ControlRef theControl
) ;
1263 // if mlte is on read only , no changes at all are allowed, not even from
1264 // procedural API, in order to allow changes via API all the same we must undo
1265 // the readonly status while we are executing, this class helps to do so
1270 EditHelper( TXNObject txn
)
1272 TXNControlTag tag
[] = { kTXNIOPrivilegesTag
} ;
1274 TXNGetTXNObjectControls( m_txn
, 1 , tag
, m_data
) ;
1275 if ( m_data
[0].uValue
== kTXNReadOnly
)
1277 TXNControlData data
[] = { { kTXNReadWrite
} } ;
1278 TXNSetTXNObjectControls( m_txn
, false , 1 , tag
, data
) ;
1283 TXNControlTag tag
[] = { kTXNIOPrivilegesTag
} ;
1284 if ( m_data
[0].uValue
== kTXNReadOnly
)
1286 TXNSetTXNObjectControls( m_txn
, false , 1 , tag
, m_data
) ;
1291 TXNControlData m_data
[1] ;
1294 wxString
wxMacMLTEControl::GetStringValue() const
1298 Size actualSize
= 0;
1302 err
= TXNGetDataEncoded( m_txn
, kTXNStartOffset
, kTXNEndOffset
, &theText
, kTXNUnicodeTextData
);
1310 actualSize
= GetHandleSize( theText
) / sizeof( UniChar
) ;
1311 if ( actualSize
> 0 )
1313 wxChar
*ptr
= NULL
;
1314 #if SIZEOF_WCHAR_T == 2
1315 ptr
= new wxChar
[actualSize
+ 1 ] ;
1316 wxStrncpy( ptr
, (wxChar
*) *theText
, actualSize
) ;
1319 SetHandleSize( theText
, ( actualSize
+ 1 ) * sizeof( UniChar
) ) ;
1321 (((UniChar
*)*theText
)[actualSize
]) = 0 ;
1322 wxMBConvUTF16BE converter
;
1323 size_t noChars
= converter
.MB2WC( NULL
, (const char*)*theText
, 0 ) ;
1324 ptr
= new wxChar
[noChars
+ 1] ;
1326 noChars
= converter
.MB2WC( ptr
, (const char*)*theText
, noChars
) ;
1328 HUnlock( theText
) ;
1330 ptr
[actualSize
] = 0 ;
1331 result
= wxString( ptr
) ;
1334 DisposeHandle( theText
) ;
1338 err
= TXNGetDataEncoded( m_txn
, kTXNStartOffset
, kTXNEndOffset
, &theText
, kTXNTextData
);
1346 actualSize
= GetHandleSize( theText
) ;
1347 if ( actualSize
> 0 )
1350 result
= wxString( *theText
, wxConvLocal
, actualSize
) ;
1351 HUnlock( theText
) ;
1353 DisposeHandle( theText
) ;
1357 wxMacConvertNewlines10To13( &result
) ;
1361 void wxMacMLTEControl::SetStringValue( const wxString
&str
)
1364 wxMacConvertNewlines13To10( &st
) ;
1365 EditHelper
help(m_txn
) ;
1367 // wxMacWindowClipper c( this ) ;
1368 #if !TARGET_API_MAC_OSX
1369 // otherwise scrolling might have problems ?
1370 TPUpdateVisibility( m_controlRef
) ;
1372 SetTXNData( st
, kTXNStartOffset
, kTXNEndOffset
) ;
1373 TXNSetSelection( m_txn
, 0, 0);
1374 TXNShowSelection( m_txn
, kTXNShowStart
);
1377 TXNFrameOptions
wxMacMLTEControl::FrameOptionsFromWXStyle( long wxStyle
)
1379 TXNFrameOptions frameOptions
=
1380 kTXNDontDrawCaretWhenInactiveMask
;
1381 if ( ! ( wxStyle
& wxTE_NOHIDESEL
) )
1382 frameOptions
|= kTXNDontDrawSelectionWhenInactiveMask
;
1384 if ( wxStyle
& wxTE_MULTILINE
)
1386 if ( ! ( wxStyle
& wxTE_DONTWRAP
) )
1387 frameOptions
|= kTXNAlwaysWrapAtViewEdgeMask
;
1390 frameOptions
|= kTXNAlwaysWrapAtViewEdgeMask
;
1391 frameOptions
|= kTXNWantHScrollBarMask
;
1394 if ( !(wxStyle
& wxTE_NO_VSCROLL
) )
1395 frameOptions
|= kTXNWantVScrollBarMask
;
1398 frameOptions
|= kTXNSingleLineOnlyMask
;
1400 if ( wxStyle
& wxHSCROLL
)
1401 frameOptions
|= kTXNWantHScrollBarMask
;
1403 return frameOptions
;
1406 void wxMacMLTEControl::AdjustCreationAttributes( const wxColour
&background
, bool visible
)
1408 TXNControlTag iControlTags
[3] = { kTXNDoFontSubstitution
, kTXNWordWrapStateTag
};
1409 TXNControlData iControlData
[3] = { {false}, {kTXNNoAutoWrap
} };
1411 #if TARGET_API_MAC_OSX
1412 iControlTags
[2] = kTXNVisibilityTag
;
1413 iControlData
[2].uValue
= visible
;
1417 if ( m_windowStyle
& wxTE_MULTILINE
)
1419 if (m_windowStyle
& wxTE_DONTWRAP
)
1420 iControlData
[1].uValue
= kTXNNoAutoWrap
;
1422 iControlData
[1].uValue
= kTXNAutoWrap
;
1425 verify_noerr( TXNSetTXNObjectControls( m_txn
, false, toptag
,
1426 iControlTags
, iControlData
)) ;
1428 // setting the default font
1434 GetThemeFont(kThemeSystemFont
, GetApplicationScript() , fontName
, &fontSize
, &fontStyle
) ;
1436 TXNTypeAttributes typeAttr
[] =
1438 { kTXNQDFontNameAttribute
, kTXNQDFontNameAttributeSize
, { (void*) fontName
} } ,
1439 { kTXNQDFontSizeAttribute
, kTXNFontSizeAttributeSize
, { (void*) (fontSize
<< 16) } } ,
1440 { kTXNQDFontStyleAttribute
, kTXNQDFontStyleAttributeSize
, { (void*) normal
} } ,
1443 verify_noerr( TXNSetTypeAttributes (m_txn
, sizeof( typeAttr
) / sizeof(TXNTypeAttributes
) , typeAttr
,
1447 if ( m_windowStyle
& wxTE_PASSWORD
)
1450 verify_noerr(TXNEchoMode( m_txn
, c
, 0 , true )) ;
1453 TXNBackground tback
;
1454 tback
.bgType
= kTXNBackgroundTypeRGB
;
1455 tback
.bg
.color
= MAC_WXCOLORREF( background
.GetPixel() );
1456 TXNSetBackground( m_txn
, &tback
);
1459 int wxMacMLTEControl::ConvertAttribute( const wxTextAttr
& style
, TXNTypeAttributes typeAttr
[] )
1461 Str255 fontName
= "\pMonaco" ;
1462 SInt16 fontSize
= 12 ;
1463 Style fontStyle
= normal
;
1465 int attrCounter
= 0 ;
1466 if ( style
.HasFont() )
1468 const wxFont
&font
= style
.GetFont() ;
1469 wxMacStringToPascal( font
.GetFaceName() , fontName
) ;
1470 fontSize
= font
.GetPointSize() ;
1471 if ( font
.GetUnderlined() )
1472 fontStyle
|= underline
;
1473 if ( font
.GetWeight() == wxBOLD
)
1475 if ( font
.GetStyle() == wxITALIC
)
1476 fontStyle
|= italic
;
1478 typeAttr
[attrCounter
].tag
= kTXNQDFontNameAttribute
;
1479 typeAttr
[attrCounter
].size
= kTXNQDFontNameAttributeSize
;
1480 typeAttr
[attrCounter
].data
.dataPtr
= (void*) fontName
;
1481 typeAttr
[attrCounter
+1].tag
= kTXNQDFontSizeAttribute
;
1482 typeAttr
[attrCounter
+1].size
= kTXNFontSizeAttributeSize
;
1483 typeAttr
[attrCounter
+1].data
.dataValue
= (fontSize
<< 16) ;
1484 typeAttr
[attrCounter
+2].tag
= kTXNQDFontStyleAttribute
;
1485 typeAttr
[attrCounter
+2].size
= kTXNQDFontStyleAttributeSize
;
1486 typeAttr
[attrCounter
+2].data
.dataValue
= fontStyle
;
1490 if ( style
.HasTextColour() )
1492 typeAttr
[attrCounter
].tag
= kTXNQDFontColorAttribute
;
1493 typeAttr
[attrCounter
].size
= kTXNQDFontColorAttributeSize
;
1494 typeAttr
[attrCounter
].data
.dataPtr
= (void*) &color
;
1495 color
= MAC_WXCOLORREF(style
.GetTextColour().GetPixel()) ;
1498 return attrCounter
;
1501 void wxMacMLTEControl::SetFont( const wxFont
& font
, const wxColour
& foreground
, long windowStyle
)
1503 EditHelper
help(m_txn
) ;
1504 wxTextAttr
style(wxNullColour
,wxNullColour
,font
) ;
1505 TXNTypeAttributes typeAttr
[4] ;
1506 int attrCounter
= ConvertAttribute( style
, typeAttr
) ;
1507 if ( attrCounter
> 0 )
1509 verify_noerr( TXNSetTypeAttributes ( m_txn
, attrCounter
, typeAttr
, kTXNStartOffset
,kTXNEndOffset
) );
1512 void wxMacMLTEControl::SetStyle(long start
, long end
, const wxTextAttr
& style
)
1514 EditHelper
help(m_txn
) ;
1515 TXNTypeAttributes typeAttr
[4] ;
1516 int attrCounter
= ConvertAttribute( style
, typeAttr
) ;
1517 if ( attrCounter
> 0 )
1519 verify_noerr( TXNSetTypeAttributes ( m_txn
, attrCounter
, typeAttr
, start
,end
) );
1523 void wxMacMLTEControl::Copy()
1525 ClearCurrentScrap();
1527 TXNConvertToPublicScrap();
1530 void wxMacMLTEControl::Cut()
1532 ClearCurrentScrap();
1534 TXNConvertToPublicScrap();
1537 void wxMacMLTEControl::Paste()
1539 TXNConvertFromPublicScrap();
1543 bool wxMacMLTEControl::CanPaste() const
1545 return TXNIsScrapPastable() ;
1548 void wxMacMLTEControl::SetEditable(bool editable
)
1550 TXNControlTag tag
[] = { kTXNIOPrivilegesTag
} ;
1551 TXNControlData data
[] = { { editable
? kTXNReadWrite
: kTXNReadOnly
} } ;
1552 TXNSetTXNObjectControls( m_txn
, false , sizeof(tag
) / sizeof (TXNControlTag
) , tag
, data
) ;
1555 long wxMacMLTEControl::GetLastPosition() const
1557 long actualsize
= 0 ;
1560 OSErr err
= TXNGetDataEncoded( m_txn
, kTXNStartOffset
, kTXNEndOffset
, &theText
, kTXNTextData
);
1568 actualsize
= GetHandleSize( theText
) ;
1569 DisposeHandle( theText
) ;
1575 void wxMacMLTEControl::Replace( long from
, long to
, const wxString str
)
1577 wxString value
= str
;
1578 wxMacConvertNewlines13To10( &value
) ;
1580 EditHelper
help( m_txn
) ;
1582 TXNSetSelection(m_txn
, from
, to
) ;
1584 SetTXNData( str
, kTXNUseCurrentSelection
, kTXNUseCurrentSelection
) ;
1587 void wxMacMLTEControl::Remove( long from
, long to
)
1589 EditHelper
help( m_txn
) ;
1591 TXNSetSelection(m_txn
, from
, to
) ;
1595 void wxMacMLTEControl::GetSelection( long* from
, long* to
) const
1597 TXNGetSelection( m_txn
, (TXNOffset
*) from
, (TXNOffset
*) to
) ;
1600 void wxMacMLTEControl::SetSelection( long from
, long to
)
1602 /* change the selection */
1603 if ((from
== -1) && (to
== -1))
1604 TXNSelectAll(m_txn
);
1606 TXNSetSelection( m_txn
, from
, to
);
1607 TXNShowSelection( m_txn
, kTXNShowStart
);
1610 void wxMacMLTEControl::WriteText(const wxString
& str
)
1612 EditHelper
helper( m_txn
) ;
1614 wxMacConvertNewlines13To10( &st
) ;
1616 long start
, end
, dummy
;
1617 GetSelection( &start
, &dummy
) ;
1618 SetTXNData( st
, kTXNUseCurrentSelection
, kTXNUseCurrentSelection
) ;
1619 GetSelection( &dummy
, &end
) ;
1620 // TODO SetStyle( start , end , GetDefaultStyle() ) ;
1623 void wxMacMLTEControl::Clear()
1625 EditHelper
st(m_txn
) ;
1626 TXNSetSelection( m_txn
, kTXNStartOffset
, kTXNEndOffset
) ;
1630 bool wxMacMLTEControl::CanUndo() const
1632 return TXNCanUndo( m_txn
, NULL
) ;
1635 void wxMacMLTEControl::Undo()
1640 bool wxMacMLTEControl::CanRedo() const
1642 return TXNCanRedo( m_txn
, NULL
) ;
1645 void wxMacMLTEControl::Redo()
1650 int wxMacMLTEControl::GetNumberOfLines() const
1652 ItemCount lines
= 0 ;
1653 TXNGetLineCount(m_txn
, &lines
) ;
1657 long wxMacMLTEControl::XYToPosition(long x
, long y
) const
1661 long lastpos
= GetLastPosition() ;
1663 // TODO find a better implementation : while we can get the
1664 // line metrics of a certain line, we don't get its starting
1665 // position, so it would probably be rather a binary search
1666 // for the start position
1669 int lastHeight
= 0 ;
1672 for ( n
= 0 ; n
<= (ItemCount
) lastpos
; ++n
)
1674 if ( y
== ypos
&& x
== xpos
)
1677 TXNOffsetToPoint( m_txn
, n
, &curpt
);
1679 if ( curpt
.v
> lastHeight
)
1684 lastHeight
= curpt
.v
;
1692 bool wxMacMLTEControl::PositionToXY(long pos
, long *x
, long *y
) const
1696 long lastpos
= GetLastPosition() ;
1701 if ( pos
<= lastpos
)
1703 // TODO find a better implementation : while we can get the
1704 // line metrics of a certain line, we don't get its starting
1705 // position, so it would probably be rather a binary search
1706 // for the start position
1709 int lastHeight
= 0 ;
1712 for ( n
= 0 ; n
<= (ItemCount
) pos
; ++n
)
1714 TXNOffsetToPoint(m_txn
, n
, &curpt
);
1716 if ( curpt
.v
> lastHeight
)
1721 lastHeight
= curpt
.v
;
1726 if ( y
) *y
= ypos
;
1727 if ( x
) *x
= xpos
;
1733 void wxMacMLTEControl::ShowPosition( long pos
)
1735 #if TARGET_RT_MAC_MACHO && defined(AVAILABLE_MAC_OS_X_VERSION_10_2_AND_LATER)
1739 TXNOffset selstart
, selend
;
1740 TXNGetSelection( m_txn
, &selstart
, &selend
) ;
1741 TXNOffsetToPoint( m_txn
, selstart
, ¤t
);
1742 TXNOffsetToPoint( m_txn
, pos
, &desired
);
1743 //TODO use HIPoints for 10.3 and above
1744 if ( (UInt32
) TXNScroll
!= (UInt32
) kUnresolvedCFragSymbolAddress
)
1746 OSErr theErr
= noErr
;
1747 SInt32 dv
= desired
.v
- current
.v
;
1748 SInt32 dh
= desired
.h
- current
.h
;
1749 TXNShowSelection( m_txn
, true ) ;
1750 theErr
= TXNScroll( m_txn
, kTXNScrollUnitsInPixels
, kTXNScrollUnitsInPixels
, &dv
, &dh
);
1751 wxASSERT_MSG( theErr
== noErr
, _T("TXNScroll returned an error!") );
1757 void wxMacMLTEControl::SetTXNData( const wxString
& st
, TXNOffset start
, TXNOffset end
)
1760 #if SIZEOF_WCHAR_T == 2
1761 size_t len
= st
.Len() ;
1762 TXNSetData( m_txn
, kTXNUnicodeTextData
, (void*)st
.wc_str(), len
* 2,
1765 wxMBConvUTF16BE converter
;
1766 ByteCount byteBufferLen
= converter
.WC2MB( NULL
, st
.wc_str() , 0 ) ;
1767 UniChar
*unibuf
= (UniChar
*) malloc(byteBufferLen
) ;
1768 converter
.WC2MB( (char*) unibuf
, st
.wc_str() , byteBufferLen
) ;
1769 TXNSetData( m_txn
, kTXNUnicodeTextData
, (void*)unibuf
, byteBufferLen
,
1774 wxCharBuffer text
= st
.mb_str(wxConvLocal
) ;
1775 TXNSetData( m_txn
, kTXNTextData
, (void*)text
.data(), strlen( text
) ,
1781 wxString
wxMacMLTEControl::GetLineText(long lineNo
) const
1785 wxString content
= GetStringValue() ;
1787 if ( lineNo
< GetNumberOfLines() )
1789 // TODO find a better implementation : while we can get the
1790 // line metrics of a certain line, we don't get its starting
1791 // position, so it would probably be rather a binary search
1792 // for the start position
1795 int lastHeight
= 0 ;
1796 long lastpos
= GetLastPosition() ;
1799 for ( n
= 0 ; n
<= (ItemCount
)lastpos
; ++n
)
1801 TXNOffsetToPoint( m_txn
, n
, &curpt
);
1803 if ( curpt
.v
> lastHeight
)
1805 if ( ypos
== lineNo
)
1811 lastHeight
= curpt
.v
;
1815 if ( ypos
== lineNo
)
1816 line
+= content
[n
] ;
1824 int wxMacMLTEControl::GetLineLength(long lineNo
) const
1827 if ( lineNo
< GetNumberOfLines() )
1829 // TODO find a better implementation : while we can get the
1830 // line metrics of a certain line, we don't get its starting
1831 // position, so it would probably be rather a binary search
1832 // for the start position
1835 int lastHeight
= 0 ;
1836 long lastpos
= GetLastPosition() ;
1839 for ( n
= 0 ; n
<= (ItemCount
) lastpos
; ++n
)
1841 TXNOffsetToPoint( m_txn
, n
, &curpt
);
1843 if ( curpt
.v
> lastHeight
)
1845 if ( ypos
== lineNo
)
1851 lastHeight
= curpt
.v
;
1861 // ----------------------------------------------------------------------------
1862 // MLTE control implementation (classic part)
1863 // ----------------------------------------------------------------------------
1865 // CS:TODO we still have a problem getting properly at the text events of a control because under Carbon
1866 // the MLTE engine registers itself for the key events thus the normal flow never occurs, the only measure for the
1867 // moment is to avoid setting the true focus on the control, the proper solution at the end would be to have
1868 // an alternate path for carbon key events that routes automatically into the same wx flow of events
1872 /* kmUPTextPart is the part code we return to indicate the user has clicked
1873 in the text area of our control */
1874 #define kmUPTextPart 1
1877 /* routines for using existing user pane controls.
1878 These routines are useful for cases where you would like to use an
1879 existing user pane control in, say, a dialog window as a scrolling
1882 /* Utility Routines */
1884 /* kUserClickedToFocusPart is a part code we pass to the SetKeyboardFocus
1885 routine. In our focus switching routine this part code is understood
1886 as meaning 'the user has clicked in the control and we need to switch
1887 the current focus to ourselves before we can continue'. */
1888 #define kUserClickedToFocusPart 100
1890 /* STPTextPaneVars is a structure used for storing the the mUP Control's
1891 internal variables and state information. A handle to this record is
1892 stored in the pane control's reference value field using the
1893 SetControlReference routine. */
1895 class STPTextPaneVars
{
1897 /* OS records referenced */
1898 TXNObject fTXNRec
; /* the txn record */
1899 TXNFrameID fTXNFrame
; /* the txn frame ID */
1900 ControlRef fUserPaneRec
; /* handle to the user pane control */
1901 WindowPtr fOwner
; /* window containing control */
1902 GrafPtr fDrawingEnvironment
; /* grafport where control is drawn */
1904 Boolean fInFocus
; /* true while the focus rect is drawn around the control */
1905 Boolean fIsActive
; /* true while the control is drawn in the active state */
1906 Boolean fTXNObjectActive
; /* reflects the activation state of the text edit record */
1907 Boolean fFocusDrawState
; /* true if focus is drawn (default: true) */
1908 /* calculated locations */
1909 Rect fRBounds
; /* control bounds */
1910 Rect fRTextArea
; /* area where the text is drawn */
1911 Rect fRFocusOutline
; /* rectangle used to draw the focus box */
1912 Rect fRTextOutline
; /* rectangle used to draw the border */
1913 RgnHandle fRTextOutlineRegion
; /* background region for the text, erased before calling TEUpdate */
1914 /* our focus advance override routine */
1915 EventHandlerUPP handlerUPP
;
1916 EventHandlerRef handlerRef
;
1922 /* Univerals Procedure Pointer variables used by the
1923 mUP Control. These variables are set up
1924 the first time that mUPOpenControl is called. */
1925 ControlUserPaneDrawUPP gTPDrawProc
= NULL
;
1926 ControlUserPaneHitTestUPP gTPHitProc
= NULL
;
1927 ControlUserPaneTrackingUPP gTPTrackProc
= NULL
;
1928 ControlUserPaneIdleUPP gTPIdleProc
= NULL
;
1929 ControlUserPaneKeyDownUPP gTPKeyProc
= NULL
;
1930 ControlUserPaneActivateUPP gTPActivateProc
= NULL
;
1931 ControlUserPaneFocusUPP gTPFocusProc
= NULL
;
1933 // one place for calculating all
1934 static void TPCalculateBounds(STPTextPaneVars
*varsp
, const Rect
& bounds
)
1936 SetRect(&varsp
->fRBounds
, bounds
.left
, bounds
.top
, bounds
.right
, bounds
.bottom
);
1937 SetRect(&varsp
->fRFocusOutline
, bounds
.left
, bounds
.top
, bounds
.right
, bounds
.bottom
);
1938 // eventually make TextOutline inset 1,1
1939 SetRect(&varsp
->fRTextOutline
, bounds
.left
, bounds
.top
, bounds
.right
, bounds
.bottom
);
1940 if ( !varsp
->fNoBorders
)
1942 SetRect(&varsp
->fRTextArea
, bounds
.left
+ 2 , bounds
.top
+ (varsp
->fMultiline
? 0 : 2) ,
1943 bounds
.right
- (varsp
->fMultiline
? 0 : 2), bounds
.bottom
- (varsp
->fMultiline
? 0 : 2));
1947 SetRect(&varsp
->fRTextArea
, bounds
.left
, bounds
.top
,
1948 bounds
.right
, bounds
.bottom
);
1952 OSStatus
MLTESetObjectVisibility( STPTextPaneVars
*varsp
, Boolean vis
, long wxStyle
)
1954 OSStatus err
= noErr
;
1955 #if TARGET_API_MAC_OSX
1956 TXNControlTag iControlTags
[1] = { kTXNVisibilityTag
};
1957 TXNControlData iControlData
[1] = {{ vis
}};
1958 err
= ::TXNSetTXNObjectControls( varsp
->fTXNRec
, false, 1, iControlTags
, iControlData
);
1960 wxTextCtrl
* textctrl
= (wxTextCtrl
*) GetControlReference(varsp
->fUserPaneRec
);
1961 if ( vis
&& textctrl
)
1964 UMAGetControlBoundsInWindowCoords( varsp
->fUserPaneRec
, &bounds
);
1965 TPCalculateBounds( varsp
, bounds
) ;
1966 wxMacWindowClipper
cl(textctrl
) ;
1967 TXNSetFrameBounds( varsp
->fTXNRec
, varsp
->fRTextArea
.top
, varsp
->fRTextArea
.left
,
1968 varsp
->fRTextArea
.bottom
, varsp
->fRTextArea
.right
, varsp
->fTXNFrame
);
1969 TXNShowSelection( varsp
->fTXNRec
, kTXNShowStart
);
1974 // make sure we don't miss changes as carbon events are not available for these under classic
1975 static void TPUpdateVisibility(ControlRef theControl
) {
1976 wxTextCtrl
* textctrl
= (wxTextCtrl
*) GetControlReference(theControl
);
1977 if ( textctrl
== NULL
)
1980 STPTextPaneVars
*varsp
= (STPTextPaneVars
*) ((wxMacMLTEClassicControl
*)textctrl
->GetPeer())->m_macTXNvars
;
1983 UMAGetControlBoundsInWindowCoords(theControl
, &bounds
);
1984 if ( textctrl
->MacIsReallyShown() != varsp
->fVisible
)
1986 // invalidate old position
1987 // InvalWindowRect( GetControlOwner( theControl ) , &varsp->fRBounds ) ;
1988 varsp
->fVisible
= textctrl
->MacIsReallyShown() ;
1990 if ( !EqualRect( &bounds
, &varsp
->fRBounds
) )
1993 Rect oldBounds
= varsp
->fRBounds
;
1994 TPCalculateBounds( varsp
, bounds
) ;
1995 // we only recalculate when visible, otherwise scrollbars get drawn at incorrect places
1996 if ( varsp
->fVisible
)
1998 wxMacWindowClipper
cl(textctrl
) ;
1999 TXNSetFrameBounds( varsp
->fTXNRec
, varsp
->fRTextArea
.top
, varsp
->fRTextArea
.left
,
2000 varsp
->fRTextArea
.bottom
, varsp
->fRTextArea
.right
, varsp
->fTXNFrame
);
2002 InvalWindowRect( GetControlOwner( theControl
) , &oldBounds
) ;
2003 InvalWindowRect( GetControlOwner( theControl
) , &varsp
->fRBounds
) ;
2007 // make correct activations
2008 static void TPActivatePaneText(STPTextPaneVars
*varsp
, Boolean setActive
) {
2010 wxTextCtrl
* textctrl
= (wxTextCtrl
*) GetControlReference(varsp
->fUserPaneRec
);
2011 if (varsp
->fTXNObjectActive
!= setActive
&& textctrl
->MacIsReallyShown() )
2013 varsp
->fTXNObjectActive
= setActive
;
2014 TXNActivate(varsp
->fTXNRec
, varsp
->fTXNFrame
, varsp
->fTXNObjectActive
);
2015 if (varsp
->fInFocus
)
2016 TXNFocus( varsp
->fTXNRec
, varsp
->fTXNObjectActive
);
2020 // update focus outlines
2021 static void TPRedrawFocusOutline(STPTextPaneVars
*varsp
) {
2024 if (varsp
->fFocusDrawState
!= (varsp
->fIsActive
&& varsp
->fInFocus
))
2026 varsp
->fFocusDrawState
= (varsp
->fIsActive
&& varsp
->fInFocus
);
2027 DrawThemeFocusRect(&varsp
->fRFocusOutline
, varsp
->fFocusDrawState
);
2031 // update TXN focus state
2032 static void TPFocusPaneText(STPTextPaneVars
*varsp
, Boolean setFocus
) {
2033 wxTextCtrl
* textctrl
= (wxTextCtrl
*) GetControlReference(varsp
->fUserPaneRec
);
2035 if (varsp
->fInFocus
!= setFocus
&& textctrl
->MacIsReallyShown()) {
2036 varsp
->fInFocus
= setFocus
;
2037 TXNFocus( varsp
->fTXNRec
, varsp
->fInFocus
);
2042 static pascal void TPPaneDrawProc(ControlRef theControl
, ControlPartCode thePart
) {
2043 /* set up our globals */
2045 wxTextCtrl
* textctrl
= (wxTextCtrl
*) GetControlReference(theControl
);
2046 if ( textctrl
== NULL
)
2048 TPUpdateVisibility( theControl
) ;
2050 STPTextPaneVars
*varsp
= (STPTextPaneVars
*) ((wxMacMLTEClassicControl
*)textctrl
->GetPeer())->m_macTXNvars
;
2051 if ( textctrl
->MacIsReallyShown() )
2053 wxMacWindowClipper
clipper( textctrl
) ;
2054 TXNDraw(varsp
->fTXNRec
, NULL
);
2055 if ( !varsp
->fNoBorders
)
2056 DrawThemeEditTextFrame(&varsp
->fRTextOutline
, varsp
->fIsActive
? kThemeStateActive
: kThemeStateInactive
);
2057 TPRedrawFocusOutline( varsp
) ;
2063 /* TPPaneHitTestProc is called when the control manager would
2064 like to determine what part of the control the mouse resides over.
2065 We also call this routine from our tracking proc to determine how
2066 to handle mouse clicks. */
2067 static pascal ControlPartCode
TPPaneHitTestProc(ControlRef theControl
, Point where
) {
2068 ControlPartCode result
;
2069 /* set up our locals and lock down our globals*/
2071 wxTextCtrl
* textctrl
= (wxTextCtrl
*) GetControlReference(theControl
);
2072 if ( textctrl
== NULL
)
2074 TPUpdateVisibility( theControl
) ;
2075 STPTextPaneVars
*varsp
= (STPTextPaneVars
*) ((wxMacMLTEClassicControl
*)textctrl
->GetPeer())->m_macTXNvars
;
2076 if (textctrl
->MacIsReallyShown() )
2078 if (PtInRect(where
, &varsp
->fRBounds
))
2079 result
= kmUPTextPart
;
2082 // sometimes we get the coords also in control local coordinates, therefore test again
2083 if ( textctrl
->MacGetTopLevelWindow()->MacUsesCompositing() )
2086 textctrl
->MacClientToRootWindow( &x
, &y
) ;
2090 if (PtInRect(where
, &varsp
->fRBounds
))
2091 result
= kmUPTextPart
;
2103 /* TPPaneTrackingProc is called when the mouse is being held down
2104 over our control. This routine handles clicks in the text area
2105 and in the scroll bar. */
2106 static pascal ControlPartCode
TPPaneTrackingProc(ControlRef theControl
, Point startPt
, ControlActionUPP actionProc
) {
2108 ControlPartCode partCodeResult
;
2109 /* make sure we have some variables... */
2111 wxTextCtrl
* textctrl
= (wxTextCtrl
*) GetControlReference(theControl
);
2112 if ( textctrl
== NULL
)
2114 TPUpdateVisibility( theControl
) ;
2115 STPTextPaneVars
*varsp
= (STPTextPaneVars
*) ((wxMacMLTEClassicControl
*)textctrl
->GetPeer())->m_macTXNvars
;
2116 if (textctrl
->MacIsReallyShown() )
2118 /* we don't do any of these functions unless we're in focus */
2119 if ( ! varsp
->fInFocus
) {
2121 owner
= GetControlOwner(theControl
);
2122 ClearKeyboardFocus(owner
);
2123 SetKeyboardFocus(owner
, theControl
, kUserClickedToFocusPart
);
2125 /* find the location for the click */
2126 // for compositing, we must convert these into toplevel window coordinates, because hittesting expects them
2127 if ( textctrl
->MacGetTopLevelWindow()->MacUsesCompositing() )
2130 textctrl
->MacClientToRootWindow( &x
, &y
) ;
2135 switch (TPPaneHitTestProc(theControl
, startPt
))
2138 /* handle clicks in the text part */
2141 wxMacWindowClipper
clipper( textctrl
) ;
2144 ConvertEventRefToEventRecord( (EventRef
) wxTheApp
->MacGetCurrentEvent() , &rec
) ;
2145 TXNClick( varsp
->fTXNRec
, &rec
);
2152 return partCodeResult
;
2156 /* TPPaneIdleProc is our user pane idle routine. When our text field
2157 is active and in focus, we use this routine to set the cursor. */
2158 static pascal void TPPaneIdleProc(ControlRef theControl
) {
2160 wxTextCtrl
* textctrl
= (wxTextCtrl
*) GetControlReference(theControl
);
2161 if ( textctrl
== NULL
)
2163 TPUpdateVisibility( theControl
) ;
2164 STPTextPaneVars
*varsp
= (STPTextPaneVars
*) ((wxMacMLTEClassicControl
*)textctrl
->GetPeer())->m_macTXNvars
;
2165 if (textctrl
->MacIsReallyShown()) {
2166 /* if we're not active, then we have nothing to say about the cursor */
2167 if (varsp
->fIsActive
) {
2171 wxMacWindowClipper
clipper( textctrl
) ;
2173 /* there's a 'focus thing' and an 'unfocused thing' */
2174 if (varsp
->fInFocus
) {
2175 /* flash the cursor */
2176 SetPort(varsp
->fDrawingEnvironment
);
2177 TXNIdle(varsp
->fTXNRec
);
2178 /* set the cursor */
2179 if (PtInRect(mousep
, &varsp
->fRTextArea
)) {
2181 RectRgn((theRgn
= NewRgn()), &varsp
->fRTextArea
);
2182 TXNAdjustCursor(varsp
->fTXNRec
, theRgn
);
2187 // SetThemeCursor(kThemeArrowCursor);
2190 /* if it's in our bounds, set the cursor */
2191 UMAGetControlBoundsInWindowCoords(theControl
, &bounds
);
2192 if (PtInRect(mousep
, &bounds
))
2194 // SetThemeCursor(kThemeArrowCursor);
2202 /* TPPaneKeyDownProc is called whenever a keydown event is directed
2203 at our control. Here, we direct the keydown event to the text
2204 edit record and redraw the scroll bar and text field as appropriate. */
2205 static pascal ControlPartCode
TPPaneKeyDownProc(ControlRef theControl
,
2206 SInt16 keyCode
, SInt16 charCode
, SInt16 modifiers
) {
2208 wxTextCtrl
* textctrl
= (wxTextCtrl
*) GetControlReference(theControl
);
2209 if ( textctrl
== NULL
)
2211 TPUpdateVisibility( theControl
) ;
2213 STPTextPaneVars
*varsp
= (STPTextPaneVars
*) ((wxMacMLTEClassicControl
*)textctrl
->GetPeer())->m_macTXNvars
;
2214 if (varsp
->fInFocus
)
2216 /* turn autoscrolling on and send the key event to text edit */
2217 wxMacWindowClipper
clipper( textctrl
) ;
2219 memset( &ev
, 0 , sizeof( ev
) ) ;
2221 ev
.modifiers
= modifiers
;
2222 ev
.message
= (( keyCode
<< 8 ) & keyCodeMask
) + ( charCode
& charCodeMask
) ;
2223 TXNKeyDown( varsp
->fTXNRec
, &ev
);
2225 return kControlEntireControl
;
2229 /* TPPaneActivateProc is called when the window containing
2230 the user pane control receives activate events. Here, we redraw
2231 the control and it's text as necessary for the activation state. */
2232 static pascal void TPPaneActivateProc(ControlRef theControl
, Boolean activating
) {
2234 wxTextCtrl
* textctrl
= (wxTextCtrl
*) GetControlReference(theControl
);
2236 if ( textctrl
== NULL
)
2238 TPUpdateVisibility( theControl
) ;
2240 STPTextPaneVars
*varsp
= (STPTextPaneVars
*) ((wxMacMLTEClassicControl
*)textctrl
->GetPeer())->m_macTXNvars
;
2242 varsp
->fIsActive
= activating
;
2243 wxMacWindowClipper
clipper( textctrl
) ;
2244 TPActivatePaneText(varsp
, varsp
->fIsActive
&& varsp
->fInFocus
);
2245 /* redraw the frame */
2246 if ( textctrl
->MacIsReallyShown() )
2248 if ( !varsp
->fNoBorders
)
2249 DrawThemeEditTextFrame(&varsp
->fRTextOutline
, varsp
->fIsActive
? kThemeStateActive
: kThemeStateInactive
);
2250 TPRedrawFocusOutline( varsp
) ;
2255 /* TPPaneFocusProc is called when every the focus changes to or
2256 from our control. Herein, switch the focus appropriately
2257 according to the parameters and redraw the control as
2259 static pascal ControlPartCode
TPPaneFocusProc(ControlRef theControl
, ControlFocusPart action
) {
2260 ControlPartCode focusResult
;
2262 focusResult
= kControlFocusNoPart
;
2263 wxTextCtrl
* textctrl
= (wxTextCtrl
*) GetControlReference(theControl
);
2264 if ( textctrl
== NULL
)
2266 TPUpdateVisibility( theControl
) ;
2267 STPTextPaneVars
*varsp
= (STPTextPaneVars
*) ((wxMacMLTEClassicControl
*)textctrl
->GetPeer())->m_macTXNvars
;
2268 /* if kControlFocusPrevPart and kControlFocusNextPart are received when the user is
2269 tabbing forwards (or shift tabbing backwards) through the items in the dialog,
2270 and kControlFocusNextPart will be received. When the user clicks in our field
2271 and it is not the current focus, then the constant kUserClickedToFocusPart will
2272 be received. The constant kControlFocusNoPart will be received when our control
2273 is the current focus and the user clicks in another control. In your focus routine,
2274 you should respond to these codes as follows:
2276 kControlFocusNoPart - turn off focus and return kControlFocusNoPart. redraw
2277 the control and the focus rectangle as necessary.
2279 kControlFocusPrevPart or kControlFocusNextPart - toggle focus on or off
2280 depending on its current state. redraw the control and the focus rectangle
2281 as appropriate for the new focus state. If the focus state is 'off', return the constant
2282 kControlFocusNoPart, otherwise return a non-zero part code.
2283 kUserClickedToFocusPart - is a constant defined for this example. You should
2284 define your own value for handling click-to-focus type events. */
2285 /* calculate the next highlight state */
2288 case kControlFocusNoPart
:
2289 TPFocusPaneText(varsp
, false);
2290 focusResult
= kControlFocusNoPart
;
2292 case kUserClickedToFocusPart
:
2293 TPFocusPaneText(varsp
, true);
2296 case kControlFocusPrevPart
:
2297 case kControlFocusNextPart
:
2298 TPFocusPaneText(varsp
, ( ! varsp
->fInFocus
));
2299 focusResult
= varsp
->fInFocus
? 1 : kControlFocusNoPart
;
2302 TPActivatePaneText(varsp
, varsp
->fIsActive
&& varsp
->fInFocus
);
2303 /* redraw the text fram and focus rectangle to indicate the
2305 if ( textctrl
->MacIsReallyShown() )
2307 wxMacWindowClipper
c( textctrl
) ;
2308 if ( !varsp
->fNoBorders
)
2309 DrawThemeEditTextFrame(&varsp
->fRTextOutline
, varsp
->fIsActive
? kThemeStateActive
: kThemeStateInactive
);
2310 TPRedrawFocusOutline( varsp
) ;
2315 wxMacMLTEClassicControl::wxMacMLTEClassicControl( wxWindow
*wxPeer
,
2316 const wxString
& str
,
2318 const wxSize
& size
, long style
)
2320 m_font
= wxPeer
->GetFont() ;
2321 m_windowStyle
= style
;
2322 Rect bounds
= wxMacGetBoundsForControl( wxPeer
, pos
, size
) ;
2324 wxMacConvertNewlines13To10( &st
) ;
2326 wxMacConvertNewlines13To10( &st
) ;
2330 featurSet
= kControlSupportsEmbedding
| kControlSupportsFocus
| kControlWantsIdle
2331 | kControlWantsActivate
| kControlHandlesTracking
| kControlHasSpecialBackground
2332 | kControlGetsFocusOnClick
| kControlSupportsLiveFeedback
;
2333 /* create the control */
2335 verify_noerr( ::CreateUserPaneControl( MAC_WXHWND(wxPeer
->GetParent()->MacGetTopLevelWindowRef()), &bounds
, featurSet
, &m_controlRef
) );
2338 // wxMacWindowClipper c(wxPeer) ;
2342 if ( wxPeer
->MacIsReallyShown() )
2343 MLTESetObjectVisibility( (STPTextPaneVars
*) m_macTXNvars
, true , style
) ;
2346 // wxMacWindowClipper clipper( wxPeer ) ;
2348 TPUpdateVisibility( m_controlRef
) ;
2350 SetTXNData( st
, kTXNStartOffset
, kTXNEndOffset
) ;
2352 TXNSetSelection( m_txn
, 0, 0);
2353 TXNShowSelection( m_txn
, kTXNShowStart
);
2356 AdjustCreationAttributes( *wxWHITE
, true ) ;
2359 wxMacMLTEClassicControl::~wxMacMLTEClassicControl()
2361 // SetControlReference(m_controlRef , 0) ;
2362 TXNDeleteObject(m_txn
);
2366 void wxMacMLTEClassicControl::VisibilityChanged(bool shown
)
2368 MLTESetObjectVisibility((STPTextPaneVars
*) m_macTXNvars
, shown
, m_windowStyle
) ;
2370 InvalWindowRect( GetControlOwner( m_controlRef
) , &((STPTextPaneVars
*)m_macTXNvars
)->fRBounds
) ;
2373 OSStatus
wxMacMLTEClassicControl::DoCreate()
2376 WindowRef theWindow
;
2378 OSStatus err
= noErr
;
2380 /* set up our globals */
2381 if (gTPDrawProc
== NULL
) gTPDrawProc
= NewControlUserPaneDrawUPP(TPPaneDrawProc
);
2382 if (gTPHitProc
== NULL
) gTPHitProc
= NewControlUserPaneHitTestUPP(TPPaneHitTestProc
);
2383 if (gTPTrackProc
== NULL
) gTPTrackProc
= NewControlUserPaneTrackingUPP(TPPaneTrackingProc
);
2384 if (gTPIdleProc
== NULL
) gTPIdleProc
= NewControlUserPaneIdleUPP(TPPaneIdleProc
);
2385 if (gTPKeyProc
== NULL
) gTPKeyProc
= NewControlUserPaneKeyDownUPP(TPPaneKeyDownProc
);
2386 if (gTPActivateProc
== NULL
) gTPActivateProc
= NewControlUserPaneActivateUPP(TPPaneActivateProc
);
2387 if (gTPFocusProc
== NULL
) gTPFocusProc
= NewControlUserPaneFocusUPP(TPPaneFocusProc
);
2389 /* allocate our private storage */
2390 m_macTXNvars
= (STPTextPaneVars
*) malloc(sizeof(STPTextPaneVars
));
2392 /* set the initial settings for our private data */
2393 m_macTXNvars
->fMultiline
= m_windowStyle
& wxTE_MULTILINE
;
2394 m_macTXNvars
->fNoBorders
= m_windowStyle
& wxNO_BORDER
;
2395 m_macTXNvars
->fInFocus
= false;
2396 m_macTXNvars
->fIsActive
= true;
2397 m_macTXNvars
->fTXNObjectActive
= false;
2398 m_macTXNvars
->fFocusDrawState
= false ;
2399 m_macTXNvars
->fUserPaneRec
= m_controlRef
;
2400 m_macTXNvars
->fVisible
= true ;
2402 theWindow
= m_macTXNvars
->fOwner
= GetControlOwner(m_controlRef
);
2404 m_macTXNvars
->fDrawingEnvironment
= (GrafPtr
) GetWindowPort(theWindow
);
2406 /* set up the user pane procedures */
2407 SetControlData(m_controlRef
, kControlEntireControl
, kControlUserPaneDrawProcTag
, sizeof(gTPDrawProc
), &gTPDrawProc
);
2408 SetControlData(m_controlRef
, kControlEntireControl
, kControlUserPaneHitTestProcTag
, sizeof(gTPHitProc
), &gTPHitProc
);
2409 SetControlData(m_controlRef
, kControlEntireControl
, kControlUserPaneTrackingProcTag
, sizeof(gTPTrackProc
), &gTPTrackProc
);
2410 SetControlData(m_controlRef
, kControlEntireControl
, kControlUserPaneIdleProcTag
, sizeof(gTPIdleProc
), &gTPIdleProc
);
2411 SetControlData(m_controlRef
, kControlEntireControl
, kControlUserPaneKeyDownProcTag
, sizeof(gTPKeyProc
), &gTPKeyProc
);
2412 SetControlData(m_controlRef
, kControlEntireControl
, kControlUserPaneActivateProcTag
, sizeof(gTPActivateProc
), &gTPActivateProc
);
2413 SetControlData(m_controlRef
, kControlEntireControl
, kControlUserPaneFocusProcTag
, sizeof(gTPFocusProc
), &gTPFocusProc
);
2415 /* calculate the rectangles used by the control */
2416 UMAGetControlBoundsInWindowCoords(m_controlRef
, &bounds
);
2417 m_macTXNvars
->fRTextOutlineRegion
= NewRgn() ;
2418 TPCalculateBounds( m_macTXNvars
, bounds
) ;
2420 /* set up the drawing environment */
2421 SetPort(m_macTXNvars
->fDrawingEnvironment
);
2423 /* create the new edit field */
2425 TXNFrameOptions frameOptions
= FrameOptionsFromWXStyle( m_windowStyle
) ;
2427 verify_noerr(TXNNewObject(NULL
, m_macTXNvars
->fOwner
, &m_macTXNvars
->fRTextArea
,
2429 kTXNTextEditStyleFrameType
,
2431 kTXNSystemDefaultEncoding
,
2432 &m_macTXNvars
->fTXNRec
, &m_macTXNvars
->fTXNFrame
, (TXNObjectRefcon
) m_macTXNvars
));
2433 m_txn
= m_macTXNvars
->fTXNRec
;
2435 /* perform final activations and setup for our text field. Here,
2436 we assume that the window is going to be the 'active' window. */
2437 TPActivatePaneText(m_macTXNvars
, m_macTXNvars
->fIsActive
&& m_macTXNvars
->fInFocus
);
2442 // ----------------------------------------------------------------------------
2443 // MLTE control implementation (OSX part)
2444 // ----------------------------------------------------------------------------
2446 #if TARGET_API_MAC_OSX
2448 wxMacMLTEHIViewControl::wxMacMLTEHIViewControl( wxWindow
*wxPeer
,
2449 const wxString
& str
,
2451 const wxSize
& size
, long style
)
2453 m_font
= wxPeer
->GetFont() ;
2454 m_windowStyle
= style
;
2455 Rect bounds
= wxMacGetBoundsForControl( wxPeer
, pos
, size
) ;
2457 wxMacConvertNewlines13To10( &st
) ;
2459 HIRect hr
= { bounds
.left
, bounds
.top
, bounds
.right
- bounds
.left
, bounds
.bottom
- bounds
.top
} ;
2461 m_scrollView
= NULL
;
2462 TXNFrameOptions frameOptions
= FrameOptionsFromWXStyle( style
) ;
2463 if ( frameOptions
& (kTXNWantVScrollBarMask
|kTXNWantHScrollBarMask
) )
2465 HIScrollViewCreate(( frameOptions
& kTXNWantHScrollBarMask
? kHIScrollViewOptionsHorizScroll
: 0) |
2466 ( frameOptions
& kTXNWantVScrollBarMask
? kHIScrollViewOptionsVertScroll
: 0 ) , &m_scrollView
) ;
2468 HIViewSetFrame( m_scrollView
, &hr
);
2469 HIViewSetVisible( m_scrollView
, true );
2473 HITextViewCreate( NULL
, 0, frameOptions
, &m_textView
) ;
2474 m_txn
= HITextViewGetTXNObject( m_textView
) ;
2475 HIViewSetVisible( m_textView
, true ) ;
2478 HIViewAddSubview( m_scrollView
, m_textView
) ;
2479 m_controlRef
= m_scrollView
;
2480 wxPeer
->MacInstallEventHandler( (WXWidget
) m_textView
) ;
2484 HIViewSetFrame( m_textView
, &hr
);
2485 m_controlRef
= m_textView
;
2489 SetTXNData( st
, kTXNStartOffset
, kTXNEndOffset
) ;
2491 TXNSetSelection( m_txn
, 0, 0);
2492 TXNShowSelection( m_txn
, kTXNShowStart
);
2494 AdjustCreationAttributes( *wxWHITE
, true ) ;
2497 OSStatus
wxMacMLTEHIViewControl::SetFocus( ControlFocusPart focusPart
)
2499 return SetKeyboardFocus( GetControlOwner( m_textView
) ,
2500 m_textView
, focusPart
) ;
2503 bool wxMacMLTEHIViewControl::HasFocus() const
2505 ControlRef control
;
2506 GetKeyboardFocus( GetUserFocusWindow() , &control
) ;
2507 return control
== m_textView
;
2510 bool wxMacMLTEHIViewControl::NeedsFocusRect() const
2517 #endif // wxUSE_TEXTCTRL