1 /////////////////////////////////////////////////////////////////////////////
4 // Author: Stefan Csomor
5 // Modified by: Ryan Norton (MLTE GetLineLength and GetLineText)
8 // Copyright: (c) Stefan Csomor
9 // Licence: wxWindows licence
10 /////////////////////////////////////////////////////////////////////////////
13 #pragma implementation "textctrl.h"
22 #include <sys/types.h>
28 #include "wx/msgdlg.h"
30 #if wxUSE_STD_IOSTREAM
40 #include "wx/button.h"
41 #include "wx/toplevel.h"
42 #include "wx/textctrl.h"
43 #include "wx/notebook.h"
44 #include "wx/tabctrl.h"
45 #include "wx/settings.h"
46 #include "wx/filefn.h"
49 #if defined(__BORLANDC__) && !defined(__WIN32__)
51 #elif !defined(__MWERKS__) && !defined(__GNUWIN32) && !defined(__DARWIN__)
59 // if this is set to 1 then under OSX 10.2 the 'classic' MLTE implementation will be used
60 // if set to 0 then the unicode textctrl will be used
61 #ifndef wxMAC_AWAYS_USE_MLTE
62 #define wxMAC_AWAYS_USE_MLTE 1
65 #include <MacTextEditor.h>
66 #include <ATSUnicode.h>
67 #include <TextCommon.h>
68 #include <TextEncodingConverter.h>
69 #include "wx/mac/uma.h"
75 virtual ~wxMacFunctor() {}
76 virtual void* operator()() = 0 ;
77 static void* CallBackProc(void *param
)
79 wxMacFunctor
* f
= (wxMacFunctor
*) param
;
80 void *result
= (*f
)() ;
85 template<typename classtype
,typename param1type
>
86 class wxMacObjectFunctor1
: public wxMacFunctor
88 typedef void (classtype::*function
)( param1type p1
) ;
89 typedef void (classtype::*ref_function
)( const param1type
& p1
) ;
91 wxMacObjectFunctor1( classtype
*obj
, function f
, param1type p1
) :
99 wxMacObjectFunctor1( classtype
*obj
, ref_function f
, param1type p1
) :
107 ~wxMacObjectFunctor1() {}
109 virtual void* operator()()
111 (m_object
->*m_function
)(m_param1
) ;
115 classtype
* m_object
;
116 param1type m_param1
;
119 function m_function
;
120 ref_function m_refFunction
;
124 template<typename classtype
, typename param1type
>
125 void* wxMacMPRemoteCall( classtype
*object
, void (classtype::*function
)( param1type p1
) , param1type p1
)
127 wxMacObjectFunctor1
<classtype
,param1type
> params(object
,function
,p1
) ;
129 MPRemoteCall( wxMacFunctor::CallBackProc
, ¶ms
, kMPOwningProcessRemoteContext
) ;
133 template<typename classtype
, typename param1type
>
134 void* wxMacMPRemoteCall( classtype
*object
, void (classtype::*function
)( const param1type
& p1
) , param1type p1
)
136 wxMacObjectFunctor1
<classtype
,param1type
> params(object
,function
,p1
) ;
138 MPRemoteCall( wxMacFunctor::CallBackProc
, ¶ms
, kMPOwningProcessRemoteContext
) ;
142 template<typename classtype
, typename param1type
>
143 void* wxMacMPRemoteGUICall( classtype
*object
, void (classtype::*function
)( param1type p1
) , param1type p1
)
146 void *result
= wxMacMPRemoteCall( object
, function
, p1
) ;
151 template<typename classtype
, typename param1type
>
152 void* wxMacMPRemoteGUICall( classtype
*object
, void (classtype::*function
)( const param1type
& p1
) , param1type p1
)
155 void *result
= wxMacMPRemoteCall( object
, function
, p1
) ;
159 // common interface for all implementations
160 class wxMacTextControl
: public wxMacControl
164 ~wxMacTextControl() ;
166 virtual wxString
GetStringValue() const = 0 ;
167 virtual void SetStringValue( const wxString
&val
) = 0 ;
168 virtual void SetStyle(long start
, long end
, const wxTextAttr
& style
) ;
169 virtual void Copy() ;
171 virtual void Paste() ;
172 virtual bool CanPaste() const ;
173 virtual void SetEditable(bool editable
) ;
174 virtual long GetLastPosition() const ;
175 virtual void Replace( long from
, long to
, const wxString str
) ;
176 virtual void Remove( long from
, long to
) = 0 ;
177 virtual void SetSelection( long from
, long to
) = 0 ;
178 virtual void GetSelection( long* from
, long* to
) const = 0 ;
179 virtual void WriteText(const wxString
& str
) = 0 ;
181 virtual void Clear() ;
182 virtual bool CanUndo() const;
183 virtual void Undo() ;
184 virtual bool CanRedo() const;
185 virtual void Redo() ;
186 virtual int GetNumberOfLines() const ;
187 virtual long XYToPosition(long x
, long y
) const;
188 virtual bool PositionToXY(long pos
, long *x
, long *y
) const ;
189 virtual void ShowPosition( long WXUNUSED(pos
) ) ;
190 virtual int GetLineLength(long lineNo
) const ;
191 virtual wxString
GetLineText(long lineNo
) const ;
194 // common parts for implementations based on MLTE
196 class wxMacMLTEControl
: public wxMacTextControl
199 virtual wxString
GetStringValue() const ;
200 virtual void SetStringValue( const wxString
&str
) ;
202 static TXNFrameOptions
FrameOptionsFromWXStyle( long wxStyle
) ;
203 void AdjustCreationAttributes( const wxColour
& background
, bool visible
) ;
205 virtual void SetFont( const wxFont
& font
, const wxColour
& foreground
, long windowStyle
) ;
206 virtual void SetBackground( const wxBrush
&brush
) ;
207 virtual void SetStyle(long start
, long end
, const wxTextAttr
& style
) ;
208 virtual void Copy() ;
210 virtual void Paste() ;
211 virtual bool CanPaste() const ;
212 virtual void SetEditable(bool editable
) ;
213 virtual long GetLastPosition() const ;
214 virtual void Replace( long from
, long to
, const wxString str
) ;
215 virtual void Remove( long from
, long to
) ;
216 virtual void GetSelection( long* from
, long* to
) const ;
217 virtual void SetSelection( long from
, long to
) ;
219 virtual void WriteText(const wxString
& str
) ;
220 virtual void Clear() ;
222 virtual bool CanUndo() const ;
223 virtual void Undo() ;
224 virtual bool CanRedo() const;
225 virtual void Redo() ;
226 virtual int GetNumberOfLines() const ;
227 virtual long XYToPosition(long x
, long y
) const ;
228 virtual bool PositionToXY(long pos
, long *x
, long *y
) const ;
229 virtual void ShowPosition( long pos
) ;
230 virtual int GetLineLength(long lineNo
) const ;
231 virtual wxString
GetLineText(long lineNo
) const ;
233 void SetTXNData( const wxString
& st
, TXNOffset start
, TXNOffset end
) ;
236 void TXNSetAttribute( const wxTextAttr
& style
, long from
, long to
) ;
240 #if TARGET_API_MAC_OSX
242 // implementation available under OSX
244 #if MAC_OS_X_VERSION_MAX_ALLOWED > MAC_OS_X_VERSION_10_2
246 class wxMacMLTEHIViewControl
: public wxMacMLTEControl
249 wxMacMLTEHIViewControl( wxWindow
*wxPeer
,
252 const wxSize
& size
, long style
) ;
253 virtual OSStatus
SetFocus( ControlFocusPart focusPart
) ;
254 virtual bool HasFocus() const ;
255 virtual bool NeedsFocusRect() const;
257 HIViewRef m_scrollView
;
258 HIViewRef m_textView
;
263 class wxMacUnicodeTextControl
: public wxMacTextControl
266 wxMacUnicodeTextControl( wxWindow
*wxPeer
,
269 const wxSize
& size
, long style
) ;
270 ~wxMacUnicodeTextControl();
271 virtual void VisibilityChanged(bool shown
);
272 virtual wxString
GetStringValue() const ;
273 virtual void SetStringValue( const wxString
&str
) ;
276 virtual void Paste();
277 virtual bool CanPaste() const;
278 virtual void SetEditable(bool editable
) ;
279 virtual void Remove( long from
, long to
) ;
280 virtual void GetSelection( long* from
, long* to
) const ;
281 virtual void SetSelection( long from
, long to
) ;
282 virtual void WriteText(const wxString
& str
) ;
284 // contains the tag for the content (is different for password and non-password controls)
290 // implementation available under classic
292 class STPTextPaneVars
;
294 class wxMacMLTEClassicControl
: public wxMacMLTEControl
297 wxMacMLTEClassicControl( wxWindow
*wxPeer
,
300 const wxSize
& size
, long style
) ;
301 ~wxMacMLTEClassicControl() ;
302 virtual void VisibilityChanged(bool shown
) ;
306 // hack to make public until we have migrated all procs
307 STPTextPaneVars
* m_macTXNvars
;
310 #define TE_UNLIMITED_LENGTH 0xFFFFFFFFUL
312 #if !USE_SHARED_LIBRARY
313 IMPLEMENT_DYNAMIC_CLASS(wxTextCtrl
, wxControl
)
315 BEGIN_EVENT_TABLE(wxTextCtrl
, wxControl
)
316 EVT_ERASE_BACKGROUND( wxTextCtrl::OnEraseBackground
)
317 EVT_DROP_FILES(wxTextCtrl::OnDropFiles
)
318 EVT_CHAR(wxTextCtrl::OnChar
)
319 EVT_MENU(wxID_CUT
, wxTextCtrl::OnCut
)
320 EVT_MENU(wxID_COPY
, wxTextCtrl::OnCopy
)
321 EVT_MENU(wxID_PASTE
, wxTextCtrl::OnPaste
)
322 EVT_MENU(wxID_UNDO
, wxTextCtrl::OnUndo
)
323 EVT_MENU(wxID_REDO
, wxTextCtrl::OnRedo
)
325 EVT_UPDATE_UI(wxID_CUT
, wxTextCtrl::OnUpdateCut
)
326 EVT_UPDATE_UI(wxID_COPY
, wxTextCtrl::OnUpdateCopy
)
327 EVT_UPDATE_UI(wxID_PASTE
, wxTextCtrl::OnUpdatePaste
)
328 EVT_UPDATE_UI(wxID_UNDO
, wxTextCtrl::OnUpdateUndo
)
329 EVT_UPDATE_UI(wxID_REDO
, wxTextCtrl::OnUpdateRedo
)
334 void wxTextCtrl::Init()
339 m_maxLength
= TE_UNLIMITED_LENGTH
;
342 wxTextCtrl::~wxTextCtrl()
347 bool wxTextCtrl::Create(wxWindow
*parent
, wxWindowID id
,
350 const wxSize
& size
, long style
,
351 const wxValidator
& validator
,
352 const wxString
& name
)
354 m_macIsUserPane
= FALSE
;
357 if ( ! ( style
& wxNO_BORDER
) )
358 style
= ( style
& ~wxBORDER_MASK
) | wxSUNKEN_BORDER
;
360 if ( !wxTextCtrlBase::Create(parent
, id
, pos
, size
, style
& ~(wxHSCROLL
|wxVSCROLL
), validator
, name
) )
363 Rect bounds
= wxMacGetBoundsForControl( this , pos
, size
) ;
365 if ( m_windowStyle
& wxTE_MULTILINE
)
367 wxASSERT_MSG( !(m_windowStyle
& wxTE_PROCESS_ENTER
),
368 wxT("wxTE_PROCESS_ENTER style is ignored for multiline text controls (they always process it)") );
370 m_windowStyle
|= wxTE_PROCESS_ENTER
;
371 style
|= wxTE_PROCESS_ENTER
;
374 #if TARGET_API_MAC_OSX
375 #if MAC_OS_X_VERSION_MAX_ALLOWED > MAC_OS_X_VERSION_10_2
376 if ( UMAGetSystemVersion() >= 0x1030 )
378 m_peer
= new wxMacMLTEHIViewControl( this , str
, pos
, size
, style
) ;
381 #if !wxMAC_AWAYS_USE_MLTE
384 m_peer
= new wxMacUnicodeTextControl( this , str
, pos
, size
, style
) ;
390 // this control draws the border itself
391 if ( !HasFlag(wxNO_BORDER
) )
393 m_windowStyle
&= ~wxSUNKEN_BORDER
;
394 bounds
= wxMacGetBoundsForControl( this , pos
, size
) ;
396 m_peer
= new wxMacMLTEClassicControl( this , str
, pos
, size
, style
) ;
399 MacPostControlCreate(pos
,size
) ;
401 if ( m_windowStyle
& wxTE_READONLY
)
403 SetEditable( false ) ;
410 void wxTextCtrl::MacVisibilityChanged()
412 GetPeer()->VisibilityChanged( MacIsReallyShown() ) ;
415 void wxTextCtrl::MacEnabledStateChanged()
419 wxString
wxTextCtrl::GetValue() const
421 return GetPeer()->GetStringValue() ;
424 void wxTextCtrl::GetSelection(long* from
, long* to
) const
426 GetPeer()->GetSelection( from
, to
) ;
429 void wxTextCtrl::SetValue(const wxString
& str
)
432 if ( GetValue() == str
)
435 GetPeer()->SetStringValue(str
) ;
438 void wxTextCtrl::SetMaxLength(unsigned long len
)
443 bool wxTextCtrl::SetFont( const wxFont
& font
)
445 if ( !wxTextCtrlBase::SetFont( font
) )
448 GetPeer()->SetFont( font
, GetForegroundColour() , GetWindowStyle() ) ;
452 bool wxTextCtrl::SetStyle(long start
, long end
, const wxTextAttr
& style
)
454 GetPeer()->SetStyle( start
, end
, style
) ;
458 bool wxTextCtrl::SetDefaultStyle(const wxTextAttr
& style
)
460 wxTextCtrlBase::SetDefaultStyle( style
) ;
461 SetStyle( kTXNUseCurrentSelection
, kTXNUseCurrentSelection
, GetDefaultStyle() ) ;
465 // Clipboard operations
466 void wxTextCtrl::Copy()
474 void wxTextCtrl::Cut()
480 wxCommandEvent
event(wxEVT_COMMAND_TEXT_UPDATED
, m_windowId
);
481 event
.SetString( GetValue() ) ;
482 event
.SetEventObject( this );
483 GetEventHandler()->ProcessEvent(event
);
487 void wxTextCtrl::Paste()
492 // eventually we should add setting the default style again
494 wxCommandEvent
event(wxEVT_COMMAND_TEXT_UPDATED
, m_windowId
);
495 event
.SetString( GetValue() ) ;
496 event
.SetEventObject( this );
497 GetEventHandler()->ProcessEvent(event
);
501 bool wxTextCtrl::CanCopy() const
503 // Can copy if there's a selection
505 GetSelection(& from
, & to
);
509 bool wxTextCtrl::CanCut() const
515 // Can cut if there's a selection
517 GetSelection(& from
, & to
);
521 bool wxTextCtrl::CanPaste() const
526 return GetPeer()->CanPaste() ;
529 void wxTextCtrl::SetEditable(bool editable
)
531 if ( editable
!= m_editable
)
533 m_editable
= editable
;
534 GetPeer()->SetEditable( editable
) ;
538 void wxTextCtrl::SetInsertionPoint(long pos
)
540 SetSelection( pos
, pos
) ;
543 void wxTextCtrl::SetInsertionPointEnd()
545 long pos
= GetLastPosition();
546 SetInsertionPoint(pos
);
549 long wxTextCtrl::GetInsertionPoint() const
552 GetSelection( &begin
, &end
) ;
556 long wxTextCtrl::GetLastPosition() const
558 return GetPeer()->GetLastPosition( ) ;
561 void wxTextCtrl::Replace(long from
, long to
, const wxString
& str
)
563 GetPeer()->Replace( from
, to
, str
) ;
566 void wxTextCtrl::Remove(long from
, long to
)
568 GetPeer()->Remove( from
, to
) ;
571 void wxTextCtrl::SetSelection(long from
, long to
)
573 GetPeer()->SetSelection( from
, to
) ;
576 bool wxTextCtrl::LoadFile(const wxString
& file
)
578 if ( wxTextCtrlBase::LoadFile(file
) )
586 void wxTextCtrl::WriteText(const wxString
& str
)
588 // TODO this MPRemoting will be moved into a remoting peer proxy for any command
589 if ( !wxIsMainThread() )
591 // unfortunately CW 8 is not able to correctly deduce the template types, so we have
592 // to instantiate explicitely
593 wxMacMPRemoteGUICall
<wxTextCtrl
,wxString
>( this , &wxTextCtrl::WriteText
, str
) ;
598 GetPeer()->WriteText( str
) ;
602 void wxTextCtrl::AppendText(const wxString
& text
)
604 SetInsertionPointEnd();
608 void wxTextCtrl::Clear()
613 bool wxTextCtrl::IsModified() const
618 bool wxTextCtrl::IsEditable() const
620 return IsEnabled() && m_editable
;
623 bool wxTextCtrl::AcceptsFocus() const
625 // we don't want focus if we can't be edited
626 return /*IsEditable() && */ wxControl::AcceptsFocus();
629 wxSize
wxTextCtrl::DoGetBestSize() const
635 // these are the numbers from the HIG, we reduce them by the borders
638 switch( m_windowVariant
)
640 case wxWINDOW_VARIANT_NORMAL
:
643 case wxWINDOW_VARIANT_SMALL
:
646 case wxWINDOW_VARIANT_MINI
:
654 // as the above numbers have some free space around the text
655 // we get 5 lines like this anyway
656 if ( m_windowStyle
& wxTE_MULTILINE
)
661 if ( !HasFlag(wxNO_BORDER
) )
664 return wxSize(wText
, hText
);
667 // ----------------------------------------------------------------------------
669 // ----------------------------------------------------------------------------
671 void wxTextCtrl::Undo()
679 void wxTextCtrl::Redo()
687 bool wxTextCtrl::CanUndo() const
693 return GetPeer()->CanUndo() ;
696 bool wxTextCtrl::CanRedo() const
702 return GetPeer()->CanRedo() ;
705 void wxTextCtrl::MarkDirty()
710 void wxTextCtrl::DiscardEdits()
715 int wxTextCtrl::GetNumberOfLines() const
717 return GetPeer()->GetNumberOfLines() ;
720 long wxTextCtrl::XYToPosition(long x
, long y
) const
722 return GetPeer()->XYToPosition( x
, y
) ;
725 bool wxTextCtrl::PositionToXY(long pos
, long *x
, long *y
) const
727 return GetPeer()->PositionToXY(pos
, x
, y
) ;
730 void wxTextCtrl::ShowPosition(long pos
)
732 return GetPeer()->ShowPosition(pos
) ;
735 int wxTextCtrl::GetLineLength(long lineNo
) const
737 return GetPeer()->GetLineLength(lineNo
) ;
740 wxString
wxTextCtrl::GetLineText(long lineNo
) const
742 return GetPeer()->GetLineText(lineNo
) ;
749 void wxTextCtrl::Command(wxCommandEvent
& event
)
751 SetValue (event
.GetString());
752 ProcessCommand (event
);
755 void wxTextCtrl::OnDropFiles(wxDropFilesEvent
& event
)
757 // By default, load the first file into the text window.
758 if (event
.GetNumberOfFiles() > 0)
760 LoadFile(event
.GetFiles()[0]);
764 void wxTextCtrl::OnEraseBackground(wxEraseEvent
& event
)
766 // all erasing should be done by the real mac control implementation
767 // while this is true for MLTE under classic, the HITextView is somehow
768 // transparent but background erase is not working correctly, so intercept
769 // things while we can...
773 void wxTextCtrl::OnChar(wxKeyEvent
& event
)
775 int key
= event
.GetKeyCode() ;
776 bool eat_key
= false ;
778 if ( key
== 'c' && event
.MetaDown() )
785 if ( !IsEditable() && key
!= WXK_LEFT
&& key
!= WXK_RIGHT
&& key
!= WXK_DOWN
&& key
!= WXK_UP
&& key
!= WXK_TAB
&&
786 !( key
== WXK_RETURN
&& ( (m_windowStyle
& wxPROCESS_ENTER
) || (m_windowStyle
& wxTE_MULTILINE
) ) )
787 /* && key != WXK_PRIOR && key != WXK_NEXT && key != WXK_HOME && key != WXK_END */
794 // Check if we have reached the max # of chars, but still allow navigation and deletion
795 if ( !IsMultiLine() && GetValue().Length() >= m_maxLength
&&
796 key
!= WXK_LEFT
&& key
!= WXK_RIGHT
&& key
!= WXK_TAB
&&
797 key
!= WXK_BACK
&& !( key
== WXK_RETURN
&& (m_windowStyle
& wxPROCESS_ENTER
) )
800 // eat it, we don't want to add more than allowed # of characters
804 // assume that any key not processed yet is going to modify the control
807 if ( key
== 'v' && event
.MetaDown() )
813 if ( key
== 'x' && event
.MetaDown() )
822 if (m_windowStyle
& wxPROCESS_ENTER
)
824 wxCommandEvent
event(wxEVT_COMMAND_TEXT_ENTER
, m_windowId
);
825 event
.SetEventObject( this );
826 event
.SetString( GetValue() );
827 if ( GetEventHandler()->ProcessEvent(event
) )
830 if ( !(m_windowStyle
& wxTE_MULTILINE
) )
832 wxWindow
*parent
= GetParent();
833 while( parent
&& !parent
->IsTopLevel() && parent
->GetDefaultItem() == NULL
) {
834 parent
= parent
->GetParent() ;
836 if ( parent
&& parent
->GetDefaultItem() )
838 wxButton
*def
= wxDynamicCast(parent
->GetDefaultItem(),
840 if ( def
&& def
->IsEnabled() )
842 wxCommandEvent
event(wxEVT_COMMAND_BUTTON_CLICKED
, def
->GetId() );
843 event
.SetEventObject(def
);
849 // this will make wxWidgets eat the ENTER key so that
850 // we actually prevent line wrapping in a single line
858 if ( !(m_windowStyle
& wxTE_PROCESS_TAB
))
861 if (!event
.ShiftDown())
862 flags
|= wxNavigationKeyEvent::IsForward
;
863 if (event
.ControlDown())
864 flags
|= wxNavigationKeyEvent::WinChange
;
870 // This is necessary (don't know why) or the tab will not
872 WriteText(wxT("\t"));
880 // perform keystroke handling
881 if ( wxTheApp
->MacGetCurrentEvent() != NULL
&& wxTheApp
->MacGetCurrentEventHandlerCallRef() != NULL
)
882 CallNextEventHandler((EventHandlerCallRef
)wxTheApp
->MacGetCurrentEventHandlerCallRef() , (EventRef
) wxTheApp
->MacGetCurrentEvent() ) ;
886 if ( wxMacConvertEventToRecord( (EventRef
) wxTheApp
->MacGetCurrentEvent() , &rec
) )
888 EventRecord
*ev
= &rec
;
891 keychar
= short(ev
->message
& charCodeMask
);
892 keycode
= short(ev
->message
& keyCodeMask
) >> 8 ;
894 m_peer
->HandleKey( keycode
, keychar
, ev
->modifiers
) ;
898 if ( ( key
>= 0x20 && key
< WXK_START
) ||
903 wxCommandEvent
event1(wxEVT_COMMAND_TEXT_UPDATED
, m_windowId
);
904 event1
.SetString( GetValue() ) ;
905 event1
.SetEventObject( this );
906 wxPostEvent(GetEventHandler(),event1
);
910 // ----------------------------------------------------------------------------
911 // standard handlers for standard edit menu events
912 // ----------------------------------------------------------------------------
914 void wxTextCtrl::OnCut(wxCommandEvent
& WXUNUSED(event
))
919 void wxTextCtrl::OnCopy(wxCommandEvent
& WXUNUSED(event
))
924 void wxTextCtrl::OnPaste(wxCommandEvent
& WXUNUSED(event
))
929 void wxTextCtrl::OnUndo(wxCommandEvent
& WXUNUSED(event
))
934 void wxTextCtrl::OnRedo(wxCommandEvent
& WXUNUSED(event
))
939 void wxTextCtrl::OnUpdateCut(wxUpdateUIEvent
& event
)
941 event
.Enable( CanCut() );
944 void wxTextCtrl::OnUpdateCopy(wxUpdateUIEvent
& event
)
946 event
.Enable( CanCopy() );
949 void wxTextCtrl::OnUpdatePaste(wxUpdateUIEvent
& event
)
951 event
.Enable( CanPaste() );
954 void wxTextCtrl::OnUpdateUndo(wxUpdateUIEvent
& event
)
956 event
.Enable( CanUndo() );
959 void wxTextCtrl::OnUpdateRedo(wxUpdateUIEvent
& event
)
961 event
.Enable( CanRedo() );
964 bool wxTextCtrl::MacSetupCursor( const wxPoint
& pt
)
969 // user pane implementation
971 void wxTextCtrl::MacControlUserPaneDrawProc(wxInt16 part
)
975 wxInt16
wxTextCtrl::MacControlUserPaneHitTestProc(wxInt16 x
, wxInt16 y
)
977 return kControlNoPart
;
980 wxInt16
wxTextCtrl::MacControlUserPaneTrackingProc(wxInt16 x
, wxInt16 y
, void* actionProc
)
982 return kControlNoPart
;
985 void wxTextCtrl::MacControlUserPaneIdleProc()
989 wxInt16
wxTextCtrl::MacControlUserPaneKeyDownProc(wxInt16 keyCode
, wxInt16 charCode
, wxInt16 modifiers
)
991 return kControlNoPart
;
994 void wxTextCtrl::MacControlUserPaneActivateProc(bool activating
)
998 wxInt16
wxTextCtrl::MacControlUserPaneFocusProc(wxInt16 action
)
1000 return kControlNoPart
;
1003 void wxTextCtrl::MacControlUserPaneBackgroundProc(void* info
)
1007 // ----------------------------------------------------------------------------
1008 // implementation base class
1009 // ----------------------------------------------------------------------------
1011 wxMacTextControl::wxMacTextControl()
1015 wxMacTextControl::~wxMacTextControl()
1019 void wxMacTextControl::SetStyle(long start
, long end
, const wxTextAttr
& style
)
1023 void wxMacTextControl::Copy()
1027 void wxMacTextControl::Cut()
1031 void wxMacTextControl::Paste()
1035 bool wxMacTextControl::CanPaste() const
1040 void wxMacTextControl::SetEditable(bool editable
)
1044 long wxMacTextControl::GetLastPosition() const
1046 return GetStringValue().Length() ;
1049 void wxMacTextControl::Replace( long from
, long to
, const wxString str
)
1053 void wxMacTextControl::Clear()
1055 SetStringValue( wxEmptyString
) ;
1058 bool wxMacTextControl::CanUndo() const
1063 void wxMacTextControl::Undo() { }
1065 bool wxMacTextControl::CanRedo() const
1070 void wxMacTextControl::Redo()
1074 long wxMacTextControl::XYToPosition(long x
, long y
) const
1079 bool wxMacTextControl::PositionToXY(long pos
, long *x
, long *y
) const
1084 void wxMacTextControl::ShowPosition( long WXUNUSED(pos
) )
1088 int wxMacTextControl::GetNumberOfLines() const
1090 ItemCount lines
= 0 ;
1091 wxString content
= GetStringValue() ;
1093 for (size_t i
= 0; i
< content
.Length() ; i
++)
1095 if (content
[i
] == '\r') lines
++;
1100 wxString
wxMacTextControl::GetLineText(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 // Add chars in line then
1114 for (size_t j
= i
; j
< content
.Length(); j
++)
1116 if (content
[j
] == '\n')
1124 if (content
[i
] == '\n') count
++;
1126 return wxEmptyString
;
1129 int wxMacTextControl::GetLineLength(long lineNo
) const
1131 // TODO change this if possible to reflect real lines
1132 wxString content
= GetStringValue() ;
1136 for (size_t i
= 0; i
< content
.Length() ; i
++)
1138 if (count
== lineNo
)
1140 // Count chars in line then
1142 for (size_t j
= i
; j
< content
.Length(); j
++)
1145 if (content
[j
] == '\n') return count
;
1150 if (content
[i
] == '\n') count
++;
1155 // ----------------------------------------------------------------------------
1156 // standard unicode control implementation
1157 // ----------------------------------------------------------------------------
1159 #if TARGET_API_MAC_OSX
1161 wxMacUnicodeTextControl::wxMacUnicodeTextControl( wxWindow
*wxPeer
,
1162 const wxString
& str
,
1164 const wxSize
& size
, long style
)
1166 m_font
= wxPeer
->GetFont() ;
1167 m_windowStyle
= style
;
1168 Rect bounds
= wxMacGetBoundsForControl( wxPeer
, pos
, size
) ;
1170 wxMacConvertNewlines10To13( &st
) ;
1171 wxMacCFStringHolder
cf(st
, m_font
.GetEncoding()) ;
1172 CFStringRef cfr
= cf
;
1173 Boolean isPassword
= ( m_windowStyle
& wxTE_PASSWORD
) != 0 ;
1174 m_valueTag
= isPassword
? kControlEditTextPasswordCFStringTag
: kControlEditTextCFStringTag
;
1175 CreateEditUnicodeTextControl( MAC_WXHWND(wxPeer
->MacGetTopLevelWindowRef()), &bounds
, cfr
, isPassword
, NULL
, &m_controlRef
) ;
1177 if ( !(m_windowStyle
& wxTE_MULTILINE
) )
1179 SetData
<Boolean
>( kControlEditTextPart
, kControlEditTextSingleLineTag
, true ) ;
1183 wxMacUnicodeTextControl::~wxMacUnicodeTextControl()
1187 void wxMacUnicodeTextControl::VisibilityChanged(bool shown
)
1189 if ( !(m_windowStyle
& wxTE_MULTILINE
) && shown
)
1191 // work around a refresh issue insofar as not always the entire content is shown even if this would be possible
1192 ControlEditTextSelectionRec sel
;
1193 CFStringRef value
= NULL
;
1195 verify_noerr( GetData
<ControlEditTextSelectionRec
>( 0, kControlEditTextSelectionTag
, &sel
) );
1196 verify_noerr( GetData
<CFStringRef
>( 0, m_valueTag
, &value
) );
1197 verify_noerr( SetData
<CFStringRef
>( 0, m_valueTag
, &value
) );
1198 verify_noerr( SetData
<ControlEditTextSelectionRec
>( 0, kControlEditTextSelectionTag
, &sel
) );
1200 CFRelease( value
) ;
1203 wxString
wxMacUnicodeTextControl::GetStringValue() const
1206 CFStringRef value
= GetData
<CFStringRef
>(0,m_valueTag
) ;
1209 wxMacCFStringHolder
cf(value
) ;
1210 result
= cf
.AsString() ;
1213 wxMacConvertNewlines13To10( &result
) ;
1215 wxMacConvertNewlines10To13( &result
) ;
1219 void wxMacUnicodeTextControl::SetStringValue( const wxString
&str
)
1222 wxMacConvertNewlines10To13( &st
) ;
1223 wxMacCFStringHolder
cf(st
, m_font
.GetEncoding() ) ;
1224 verify_noerr( SetData
<CFStringRef
>( 0, m_valueTag
, cf
) ) ;
1226 void wxMacUnicodeTextControl::Copy()
1228 SendHICommand( kHICommandCopy
) ;
1230 void wxMacUnicodeTextControl::Cut()
1232 SendHICommand( kHICommandCut
) ;
1234 void wxMacUnicodeTextControl::Paste()
1236 SendHICommand( kHICommandPaste
) ;
1238 bool wxMacUnicodeTextControl::CanPaste() const
1242 void wxMacUnicodeTextControl::SetEditable(bool editable
)
1244 SetData
<Boolean
>( 0 , kControlEditTextLockedTag
, (Boolean
) !editable
) ;
1246 void wxMacUnicodeTextControl::Remove( long from
, long to
)
1250 void wxMacUnicodeTextControl::GetSelection( long* from
, long* to
) const
1252 ControlEditTextSelectionRec sel
;
1253 verify_noerr(GetData
<ControlEditTextSelectionRec
>( 0, kControlEditTextSelectionTag
, &sel
) ) ;
1254 if ( from
) *from
= sel
.selStart
;
1255 if ( to
) *to
= sel
.selEnd
;
1258 void wxMacUnicodeTextControl::SetSelection( long from
, long to
)
1260 ControlEditTextSelectionRec sel
;
1261 sel
.selStart
= from
;
1263 SetData
<ControlEditTextSelectionRec
>( 0 , kControlEditTextSelectionTag
, &sel
) ;
1266 void wxMacUnicodeTextControl::WriteText(const wxString
& str
)
1269 wxMacConvertNewlines10To13( &st
) ;
1270 #if MAC_OS_X_VERSION_MAX_ALLOWED > MAC_OS_X_VERSION_10_2
1271 wxMacCFStringHolder
cf(st
, m_font
.GetEncoding() ) ;
1272 CFStringRef value
= cf
;
1273 SetData
<CFStringRef
>( 0, kControlEditTextInsertCFStringRefTag
, &value
);
1275 wxString val
= GetStringValue() ;
1277 GetSelection( &start
, &end
) ;
1278 val
.Remove( start
, end
- start
) ;
1279 val
.insert( start
, str
) ;
1280 SetStringValue( val
) ;
1281 SetSelection( start
+ str
.Length() , start
+ str
.Length() ) ;
1287 // ----------------------------------------------------------------------------
1288 // MLTE control implementation (common part)
1289 // ----------------------------------------------------------------------------
1291 #if TARGET_API_MAC_OSX == 0
1292 // declaration needed because of one line in the code...
1293 static void TPUpdateVisibility(ControlRef theControl
) ;
1296 // if mlte is on read only , no changes at all are allowed, not even from
1297 // procedural API, in order to allow changes via API all the same we must undo
1298 // the readonly status while we are executing, this class helps to do so
1303 EditHelper( TXNObject txn
)
1305 TXNControlTag tag
[] = { kTXNIOPrivilegesTag
} ;
1307 TXNGetTXNObjectControls( m_txn
, 1 , tag
, m_data
) ;
1308 if ( m_data
[0].uValue
== kTXNReadOnly
)
1310 TXNControlData data
[] = { { kTXNReadWrite
} } ;
1311 TXNSetTXNObjectControls( m_txn
, false , 1 , tag
, data
) ;
1316 TXNControlTag tag
[] = { kTXNIOPrivilegesTag
} ;
1317 if ( m_data
[0].uValue
== kTXNReadOnly
)
1319 TXNSetTXNObjectControls( m_txn
, false , 1 , tag
, m_data
) ;
1324 TXNControlData m_data
[1] ;
1327 wxString
wxMacMLTEControl::GetStringValue() const
1331 Size actualSize
= 0;
1335 err
= TXNGetDataEncoded( m_txn
, kTXNStartOffset
, kTXNEndOffset
, &theText
, kTXNUnicodeTextData
);
1343 actualSize
= GetHandleSize( theText
) / sizeof( UniChar
) ;
1344 if ( actualSize
> 0 )
1346 wxChar
*ptr
= NULL
;
1347 #if SIZEOF_WCHAR_T == 2
1348 ptr
= new wxChar
[actualSize
+ 1 ] ;
1349 wxStrncpy( ptr
, (wxChar
*) *theText
, actualSize
) ;
1352 SetHandleSize( theText
, ( actualSize
+ 1 ) * sizeof( UniChar
) ) ;
1354 (((UniChar
*)*theText
)[actualSize
]) = 0 ;
1355 wxMBConvUTF16BE converter
;
1356 size_t noChars
= converter
.MB2WC( NULL
, (const char*)*theText
, 0 ) ;
1357 ptr
= new wxChar
[noChars
+ 1] ;
1359 noChars
= converter
.MB2WC( ptr
, (const char*)*theText
, noChars
) ;
1361 HUnlock( theText
) ;
1363 ptr
[actualSize
] = 0 ;
1364 result
= wxString( ptr
) ;
1367 DisposeHandle( theText
) ;
1371 err
= TXNGetDataEncoded( m_txn
, kTXNStartOffset
, kTXNEndOffset
, &theText
, kTXNTextData
);
1379 actualSize
= GetHandleSize( theText
) ;
1380 if ( actualSize
> 0 )
1383 result
= wxString( *theText
, wxConvLocal
, actualSize
) ;
1384 HUnlock( theText
) ;
1386 DisposeHandle( theText
) ;
1391 wxMacConvertNewlines13To10( &result
) ;
1393 wxMacConvertNewlines10To13( &result
) ;
1398 void wxMacMLTEControl::SetStringValue( const wxString
&str
)
1402 wxMacConvertNewlines10To13( &st
) ;
1403 EditHelper
help(m_txn
) ;
1405 // wxMacWindowClipper c( this ) ;
1406 #if !TARGET_API_MAC_OSX
1407 // otherwise scrolling might have problems ?
1408 TPUpdateVisibility( m_controlRef
) ;
1410 SetTXNData( st
, kTXNStartOffset
, kTXNEndOffset
) ;
1411 TXNSetSelection( m_txn
, 0, 0);
1412 TXNShowSelection( m_txn
, kTXNShowStart
);
1415 TXNFrameOptions
wxMacMLTEControl::FrameOptionsFromWXStyle( long wxStyle
)
1417 TXNFrameOptions frameOptions
=
1418 kTXNDontDrawCaretWhenInactiveMask
;
1419 if ( ! ( wxStyle
& wxTE_NOHIDESEL
) )
1420 frameOptions
|= kTXNDontDrawSelectionWhenInactiveMask
;
1422 if ( wxStyle
& wxTE_MULTILINE
)
1424 if ( ! ( wxStyle
& wxTE_DONTWRAP
) )
1425 frameOptions
|= kTXNAlwaysWrapAtViewEdgeMask
;
1428 frameOptions
|= kTXNAlwaysWrapAtViewEdgeMask
;
1429 frameOptions
|= kTXNWantHScrollBarMask
;
1432 if ( !(wxStyle
& wxTE_NO_VSCROLL
) )
1433 frameOptions
|= kTXNWantVScrollBarMask
;
1436 frameOptions
|= kTXNSingleLineOnlyMask
;
1438 if ( wxStyle
& wxHSCROLL
)
1439 frameOptions
|= kTXNWantHScrollBarMask
;
1441 return frameOptions
;
1444 void wxMacMLTEControl::AdjustCreationAttributes( const wxColour
&background
, bool visible
)
1446 TXNControlTag iControlTags
[3] = { kTXNDoFontSubstitution
, kTXNWordWrapStateTag
};
1447 TXNControlData iControlData
[3] = { {false}, {kTXNNoAutoWrap
} };
1449 #if TARGET_API_MAC_OSX
1450 iControlTags
[2] = kTXNVisibilityTag
;
1451 iControlData
[2].uValue
= visible
;
1455 if ( m_windowStyle
& wxTE_MULTILINE
)
1457 if (m_windowStyle
& wxTE_DONTWRAP
)
1458 iControlData
[1].uValue
= kTXNNoAutoWrap
;
1460 iControlData
[1].uValue
= kTXNAutoWrap
;
1463 verify_noerr( TXNSetTXNObjectControls( m_txn
, false, toptag
,
1464 iControlTags
, iControlData
)) ;
1466 // setting the default font
1472 GetThemeFont(kThemeSystemFont
, GetApplicationScript() , fontName
, &fontSize
, &fontStyle
) ;
1474 TXNTypeAttributes typeAttr
[] =
1476 { kTXNQDFontNameAttribute
, kTXNQDFontNameAttributeSize
, { (void*) fontName
} } ,
1477 { kTXNQDFontSizeAttribute
, kTXNFontSizeAttributeSize
, { (void*) (fontSize
<< 16) } } ,
1478 { kTXNQDFontStyleAttribute
, kTXNQDFontStyleAttributeSize
, { (void*) normal
} } ,
1481 verify_noerr( TXNSetTypeAttributes (m_txn
, sizeof( typeAttr
) / sizeof(TXNTypeAttributes
) , typeAttr
,
1485 if ( m_windowStyle
& wxTE_PASSWORD
)
1488 verify_noerr(TXNEchoMode( m_txn
, c
, 0 , true )) ;
1491 TXNBackground tback
;
1492 tback
.bgType
= kTXNBackgroundTypeRGB
;
1493 tback
.bg
.color
= MAC_WXCOLORREF( background
.GetPixel() );
1494 TXNSetBackground( m_txn
, &tback
);
1497 void wxMacMLTEControl::SetBackground( const wxBrush
&brush
)
1499 // currently only solid background are supported
1500 TXNBackground tback
;
1501 tback
.bgType
= kTXNBackgroundTypeRGB
;
1502 tback
.bg
.color
= MAC_WXCOLORREF( brush
.GetColour().GetPixel() );
1503 TXNSetBackground( m_txn
, &tback
);
1506 void wxMacMLTEControl::TXNSetAttribute( const wxTextAttr
& style
, long from
, long to
)
1508 TXNTypeAttributes typeAttr
[4] ;
1509 Str255 fontName
= "\pMonaco" ;
1510 SInt16 fontSize
= 12 ;
1511 Style fontStyle
= normal
;
1513 int attrCounter
= 0 ;
1514 if ( style
.HasFont() )
1516 const wxFont
&font
= style
.GetFont() ;
1517 wxMacStringToPascal( font
.GetFaceName() , fontName
) ;
1518 fontSize
= font
.GetPointSize() ;
1519 if ( font
.GetUnderlined() )
1520 fontStyle
|= underline
;
1521 if ( font
.GetWeight() == wxBOLD
)
1523 if ( font
.GetStyle() == wxITALIC
)
1524 fontStyle
|= italic
;
1526 typeAttr
[attrCounter
].tag
= kTXNQDFontNameAttribute
;
1527 typeAttr
[attrCounter
].size
= kTXNQDFontNameAttributeSize
;
1528 typeAttr
[attrCounter
].data
.dataPtr
= (void*) fontName
;
1529 typeAttr
[attrCounter
+1].tag
= kTXNQDFontSizeAttribute
;
1530 typeAttr
[attrCounter
+1].size
= kTXNFontSizeAttributeSize
;
1531 typeAttr
[attrCounter
+1].data
.dataValue
= (fontSize
<< 16) ;
1532 typeAttr
[attrCounter
+2].tag
= kTXNQDFontStyleAttribute
;
1533 typeAttr
[attrCounter
+2].size
= kTXNQDFontStyleAttributeSize
;
1534 typeAttr
[attrCounter
+2].data
.dataValue
= fontStyle
;
1537 if ( style
.HasTextColour() )
1539 typeAttr
[attrCounter
].tag
= kTXNQDFontColorAttribute
;
1540 typeAttr
[attrCounter
].size
= kTXNQDFontColorAttributeSize
;
1541 typeAttr
[attrCounter
].data
.dataPtr
= (void*) &color
;
1542 color
= MAC_WXCOLORREF(style
.GetTextColour().GetPixel()) ;
1545 if ( attrCounter
> 0 )
1547 verify_noerr( TXNSetTypeAttributes ( m_txn
, attrCounter
, typeAttr
, from
, to
) );
1551 void wxMacMLTEControl::SetFont( const wxFont
& font
, const wxColour
& foreground
, long windowStyle
)
1553 EditHelper
help(m_txn
) ;
1554 TXNSetAttribute( wxTextAttr(foreground
,wxNullColour
,font
) , kTXNStartOffset
,kTXNEndOffset
) ;
1556 void wxMacMLTEControl::SetStyle(long start
, long end
, const wxTextAttr
& style
)
1558 EditHelper
help(m_txn
) ;
1559 TXNSetAttribute( style
, start
,end
) ;
1562 void wxMacMLTEControl::Copy()
1564 ClearCurrentScrap();
1566 TXNConvertToPublicScrap();
1569 void wxMacMLTEControl::Cut()
1571 ClearCurrentScrap();
1573 TXNConvertToPublicScrap();
1576 void wxMacMLTEControl::Paste()
1578 TXNConvertFromPublicScrap();
1582 bool wxMacMLTEControl::CanPaste() const
1584 return TXNIsScrapPastable() ;
1587 void wxMacMLTEControl::SetEditable(bool editable
)
1589 TXNControlTag tag
[] = { kTXNIOPrivilegesTag
} ;
1590 TXNControlData data
[] = { { editable
? kTXNReadWrite
: kTXNReadOnly
} } ;
1591 TXNSetTXNObjectControls( m_txn
, false , sizeof(tag
) / sizeof (TXNControlTag
) , tag
, data
) ;
1594 long wxMacMLTEControl::GetLastPosition() const
1596 long actualsize
= 0 ;
1599 OSErr err
= TXNGetDataEncoded( m_txn
, kTXNStartOffset
, kTXNEndOffset
, &theText
, kTXNTextData
);
1607 actualsize
= GetHandleSize( theText
) ;
1608 DisposeHandle( theText
) ;
1614 void wxMacMLTEControl::Replace( long from
, long to
, const wxString str
)
1616 wxString value
= str
;
1617 wxMacConvertNewlines10To13( &value
) ;
1619 EditHelper
help( m_txn
) ;
1621 TXNSetSelection(m_txn
, from
, to
) ;
1623 SetTXNData( value
, kTXNUseCurrentSelection
, kTXNUseCurrentSelection
) ;
1626 void wxMacMLTEControl::Remove( long from
, long to
)
1628 EditHelper
help( m_txn
) ;
1630 TXNSetSelection(m_txn
, from
, to
) ;
1634 void wxMacMLTEControl::GetSelection( long* from
, long* to
) const
1636 TXNGetSelection( m_txn
, (TXNOffset
*) from
, (TXNOffset
*) to
) ;
1639 void wxMacMLTEControl::SetSelection( long from
, long to
)
1641 /* change the selection */
1642 if ((from
== -1) && (to
== -1))
1643 TXNSelectAll(m_txn
);
1645 TXNSetSelection( m_txn
, from
, to
);
1646 TXNShowSelection( m_txn
, kTXNShowStart
);
1649 void wxMacMLTEControl::WriteText(const wxString
& str
)
1651 EditHelper
helper( m_txn
) ;
1653 wxMacConvertNewlines10To13( &st
) ;
1655 long start
, end
, dummy
;
1656 GetSelection( &start
, &dummy
) ;
1657 SetTXNData( st
, kTXNUseCurrentSelection
, kTXNUseCurrentSelection
) ;
1658 GetSelection( &dummy
, &end
) ;
1659 // TODO SetStyle( start , end , GetDefaultStyle() ) ;
1662 void wxMacMLTEControl::Clear()
1664 EditHelper
st(m_txn
) ;
1665 TXNSetSelection( m_txn
, kTXNStartOffset
, kTXNEndOffset
) ;
1669 bool wxMacMLTEControl::CanUndo() const
1671 return TXNCanUndo( m_txn
, NULL
) ;
1674 void wxMacMLTEControl::Undo()
1679 bool wxMacMLTEControl::CanRedo() const
1681 return TXNCanRedo( m_txn
, NULL
) ;
1684 void wxMacMLTEControl::Redo()
1689 int wxMacMLTEControl::GetNumberOfLines() const
1691 ItemCount lines
= 0 ;
1692 TXNGetLineCount(m_txn
, &lines
) ;
1696 long wxMacMLTEControl::XYToPosition(long x
, long y
) const
1700 long lastpos
= GetLastPosition() ;
1702 // TODO find a better implementation : while we can get the
1703 // line metrics of a certain line, we don't get its starting
1704 // position, so it would probably be rather a binary search
1705 // for the start position
1708 int lastHeight
= 0 ;
1711 for ( n
= 0 ; n
<= (ItemCount
) lastpos
; ++n
)
1713 if ( y
== ypos
&& x
== xpos
)
1716 TXNOffsetToPoint( m_txn
, n
, &curpt
);
1718 if ( curpt
.v
> lastHeight
)
1723 lastHeight
= curpt
.v
;
1731 bool wxMacMLTEControl::PositionToXY(long pos
, long *x
, long *y
) const
1735 long lastpos
= GetLastPosition() ;
1740 if ( pos
<= lastpos
)
1742 // TODO find a better implementation : while we can get the
1743 // line metrics of a certain line, we don't get its starting
1744 // position, so it would probably be rather a binary search
1745 // for the start position
1748 int lastHeight
= 0 ;
1751 for ( n
= 0 ; n
<= (ItemCount
) pos
; ++n
)
1753 TXNOffsetToPoint(m_txn
, n
, &curpt
);
1755 if ( curpt
.v
> lastHeight
)
1760 lastHeight
= curpt
.v
;
1765 if ( y
) *y
= ypos
;
1766 if ( x
) *x
= xpos
;
1772 void wxMacMLTEControl::ShowPosition( long pos
)
1774 #if TARGET_RT_MAC_MACHO && defined(AVAILABLE_MAC_OS_X_VERSION_10_2_AND_LATER)
1778 TXNOffset selstart
, selend
;
1779 TXNGetSelection( m_txn
, &selstart
, &selend
) ;
1780 TXNOffsetToPoint( m_txn
, selstart
, ¤t
);
1781 TXNOffsetToPoint( m_txn
, pos
, &desired
);
1782 //TODO use HIPoints for 10.3 and above
1783 if ( (UInt32
) TXNScroll
!= (UInt32
) kUnresolvedCFragSymbolAddress
)
1785 OSErr theErr
= noErr
;
1786 SInt32 dv
= desired
.v
- current
.v
;
1787 SInt32 dh
= desired
.h
- current
.h
;
1788 TXNShowSelection( m_txn
, true ) ;
1789 theErr
= TXNScroll( m_txn
, kTXNScrollUnitsInPixels
, kTXNScrollUnitsInPixels
, &dv
, &dh
);
1790 wxASSERT_MSG( theErr
== noErr
, _T("TXNScroll returned an error!") );
1796 void wxMacMLTEControl::SetTXNData( const wxString
& st
, TXNOffset start
, TXNOffset end
)
1799 #if SIZEOF_WCHAR_T == 2
1800 size_t len
= st
.Len() ;
1801 TXNSetData( m_txn
, kTXNUnicodeTextData
, (void*)st
.wc_str(), len
* 2,
1804 wxMBConvUTF16BE converter
;
1805 ByteCount byteBufferLen
= converter
.WC2MB( NULL
, st
.wc_str() , 0 ) ;
1806 UniChar
*unibuf
= (UniChar
*) malloc(byteBufferLen
) ;
1807 converter
.WC2MB( (char*) unibuf
, st
.wc_str() , byteBufferLen
) ;
1808 TXNSetData( m_txn
, kTXNUnicodeTextData
, (void*)unibuf
, byteBufferLen
,
1813 wxCharBuffer text
= st
.mb_str(wxConvLocal
) ;
1814 TXNSetData( m_txn
, kTXNTextData
, (void*)text
.data(), strlen( text
) ,
1820 wxString
wxMacMLTEControl::GetLineText(long lineNo
) const
1824 if ( lineNo
< GetNumberOfLines() )
1832 // get the first possible position in the control
1834 TXNOffsetToPoint(m_txn
, 0, &firstPoint
);
1836 // Iterate through the lines until we reach the one we want,
1837 // adding to our current y pixel point position
1838 while (ypos
< lineNo
)
1840 TXNGetLineMetrics(m_txn
, ypos
++, &lineWidth
, &lineHeight
);
1841 currentHeight
+= lineHeight
;
1844 Point thePoint
= { firstPoint
.v
+ (currentHeight
>> 16), firstPoint
.h
+ (0) };
1845 TXNOffset theOffset
;
1846 TXNPointToOffset(m_txn
, thePoint
, &theOffset
);
1848 wxString content
= GetStringValue() ;
1849 Point currentPoint
= thePoint
;
1850 while(thePoint
.v
== currentPoint
.v
&& theOffset
< content
.length())
1852 line
+= content
[theOffset
];
1853 TXNOffsetToPoint(m_txn
, ++theOffset
, ¤tPoint
);
1859 int wxMacMLTEControl::GetLineLength(long lineNo
) const
1863 if ( lineNo
< GetNumberOfLines() )
1871 // get the first possible position in the control
1873 TXNOffsetToPoint(m_txn
, 0, &firstPoint
);
1875 // Iterate through the lines until we reach the one we want,
1876 // adding to our current y pixel point position
1877 while (ypos
< lineNo
)
1879 TXNGetLineMetrics(m_txn
, ypos
++, &lineWidth
, &lineHeight
);
1880 currentHeight
+= lineHeight
;
1883 Point thePoint
= { firstPoint
.v
+ (currentHeight
>> 16), firstPoint
.h
+ (0) };
1884 TXNOffset theOffset
;
1885 TXNPointToOffset(m_txn
, thePoint
, &theOffset
);
1887 wxString content
= GetStringValue() ;
1888 Point currentPoint
= thePoint
;
1889 while(thePoint
.v
== currentPoint
.v
&& theOffset
< content
.length())
1892 TXNOffsetToPoint(m_txn
, ++theOffset
, ¤tPoint
);
1899 // ----------------------------------------------------------------------------
1900 // MLTE control implementation (classic part)
1901 // ----------------------------------------------------------------------------
1903 // CS:TODO we still have a problem getting properly at the text events of a control because under Carbon
1904 // the MLTE engine registers itself for the key events thus the normal flow never occurs, the only measure for the
1905 // moment is to avoid setting the true focus on the control, the proper solution at the end would be to have
1906 // an alternate path for carbon key events that routes automatically into the same wx flow of events
1910 /* kmUPTextPart is the part code we return to indicate the user has clicked
1911 in the text area of our control */
1912 #define kmUPTextPart 1
1915 /* routines for using existing user pane controls.
1916 These routines are useful for cases where you would like to use an
1917 existing user pane control in, say, a dialog window as a scrolling
1920 /* Utility Routines */
1922 /* kUserClickedToFocusPart is a part code we pass to the SetKeyboardFocus
1923 routine. In our focus switching routine this part code is understood
1924 as meaning 'the user has clicked in the control and we need to switch
1925 the current focus to ourselves before we can continue'. */
1926 #define kUserClickedToFocusPart 100
1928 /* STPTextPaneVars is a structure used for storing the the mUP Control's
1929 internal variables and state information. A handle to this record is
1930 stored in the pane control's reference value field using the
1931 SetControlReference routine. */
1933 class STPTextPaneVars
{
1935 /* OS records referenced */
1936 TXNObject fTXNRec
; /* the txn record */
1937 TXNFrameID fTXNFrame
; /* the txn frame ID */
1938 ControlRef fUserPaneRec
; /* handle to the user pane control */
1939 WindowPtr fOwner
; /* window containing control */
1940 GrafPtr fDrawingEnvironment
; /* grafport where control is drawn */
1942 Boolean fInFocus
; /* true while the focus rect is drawn around the control */
1943 Boolean fIsActive
; /* true while the control is drawn in the active state */
1944 Boolean fTXNObjectActive
; /* reflects the activation state of the text edit record */
1945 Boolean fFocusDrawState
; /* true if focus is drawn (default: true) */
1946 /* calculated locations */
1947 Rect fRBounds
; /* control bounds */
1948 Rect fRTextArea
; /* area where the text is drawn */
1949 Rect fRFocusOutline
; /* rectangle used to draw the focus box */
1950 Rect fRTextOutline
; /* rectangle used to draw the border */
1951 RgnHandle fRTextOutlineRegion
; /* background region for the text, erased before calling TEUpdate */
1952 /* our focus advance override routine */
1953 EventHandlerUPP handlerUPP
;
1954 EventHandlerRef handlerRef
;
1960 /* Univerals Procedure Pointer variables used by the
1961 mUP Control. These variables are set up
1962 the first time that mUPOpenControl is called. */
1963 ControlUserPaneDrawUPP gTPDrawProc
= NULL
;
1964 ControlUserPaneHitTestUPP gTPHitProc
= NULL
;
1965 ControlUserPaneTrackingUPP gTPTrackProc
= NULL
;
1966 ControlUserPaneIdleUPP gTPIdleProc
= NULL
;
1967 ControlUserPaneKeyDownUPP gTPKeyProc
= NULL
;
1968 ControlUserPaneActivateUPP gTPActivateProc
= NULL
;
1969 ControlUserPaneFocusUPP gTPFocusProc
= NULL
;
1971 // one place for calculating all
1972 static void TPCalculateBounds(STPTextPaneVars
*varsp
, const Rect
& bounds
)
1974 SetRect(&varsp
->fRBounds
, bounds
.left
, bounds
.top
, bounds
.right
, bounds
.bottom
);
1975 SetRect(&varsp
->fRFocusOutline
, bounds
.left
, bounds
.top
, bounds
.right
, bounds
.bottom
);
1976 // eventually make TextOutline inset 1,1
1977 SetRect(&varsp
->fRTextOutline
, bounds
.left
, bounds
.top
, bounds
.right
, bounds
.bottom
);
1978 if ( !varsp
->fNoBorders
)
1980 SetRect(&varsp
->fRTextArea
, bounds
.left
+ 2 , bounds
.top
+ (varsp
->fMultiline
? 0 : 2) ,
1981 bounds
.right
- (varsp
->fMultiline
? 0 : 2), bounds
.bottom
- (varsp
->fMultiline
? 0 : 2));
1985 SetRect(&varsp
->fRTextArea
, bounds
.left
, bounds
.top
,
1986 bounds
.right
, bounds
.bottom
);
1990 OSStatus
MLTESetObjectVisibility( STPTextPaneVars
*varsp
, Boolean vis
, long wxStyle
)
1992 OSStatus err
= noErr
;
1993 #if TARGET_API_MAC_OSX
1994 TXNControlTag iControlTags
[1] = { kTXNVisibilityTag
};
1995 TXNControlData iControlData
[1] = {{ vis
}};
1996 err
= ::TXNSetTXNObjectControls( varsp
->fTXNRec
, false, 1, iControlTags
, iControlData
);
1998 wxTextCtrl
* textctrl
= (wxTextCtrl
*) GetControlReference(varsp
->fUserPaneRec
);
1999 if ( vis
&& textctrl
)
2002 UMAGetControlBoundsInWindowCoords( varsp
->fUserPaneRec
, &bounds
);
2003 TPCalculateBounds( varsp
, bounds
) ;
2004 wxMacWindowClipper
cl(textctrl
) ;
2005 TXNSetFrameBounds( varsp
->fTXNRec
, varsp
->fRTextArea
.top
, varsp
->fRTextArea
.left
,
2006 varsp
->fRTextArea
.bottom
, varsp
->fRTextArea
.right
, varsp
->fTXNFrame
);
2007 TXNShowSelection( varsp
->fTXNRec
, kTXNShowStart
);
2012 // make sure we don't miss changes as carbon events are not available for these under classic
2013 static void TPUpdateVisibility(ControlRef theControl
) {
2014 wxTextCtrl
* textctrl
= (wxTextCtrl
*) GetControlReference(theControl
);
2015 if ( textctrl
== NULL
)
2018 STPTextPaneVars
*varsp
= (STPTextPaneVars
*) ((wxMacMLTEClassicControl
*)textctrl
->GetPeer())->m_macTXNvars
;
2021 UMAGetControlBoundsInWindowCoords(theControl
, &bounds
);
2022 if ( textctrl
->MacIsReallyShown() != varsp
->fVisible
)
2024 // invalidate old position
2025 // InvalWindowRect( GetControlOwner( theControl ) , &varsp->fRBounds ) ;
2026 varsp
->fVisible
= textctrl
->MacIsReallyShown() ;
2028 if ( !EqualRect( &bounds
, &varsp
->fRBounds
) )
2031 Rect oldBounds
= varsp
->fRBounds
;
2032 TPCalculateBounds( varsp
, bounds
) ;
2033 // we only recalculate when visible, otherwise scrollbars get drawn at incorrect places
2034 if ( varsp
->fVisible
)
2036 wxMacWindowClipper
cl(textctrl
) ;
2037 TXNSetFrameBounds( varsp
->fTXNRec
, varsp
->fRTextArea
.top
, varsp
->fRTextArea
.left
,
2038 varsp
->fRTextArea
.bottom
, varsp
->fRTextArea
.right
, varsp
->fTXNFrame
);
2040 InvalWindowRect( GetControlOwner( theControl
) , &oldBounds
) ;
2041 InvalWindowRect( GetControlOwner( theControl
) , &varsp
->fRBounds
) ;
2045 // make correct activations
2046 static void TPActivatePaneText(STPTextPaneVars
*varsp
, Boolean setActive
) {
2048 wxTextCtrl
* textctrl
= (wxTextCtrl
*) GetControlReference(varsp
->fUserPaneRec
);
2049 if (varsp
->fTXNObjectActive
!= setActive
&& textctrl
->MacIsReallyShown() )
2051 varsp
->fTXNObjectActive
= setActive
;
2052 TXNActivate(varsp
->fTXNRec
, varsp
->fTXNFrame
, varsp
->fTXNObjectActive
);
2053 if (varsp
->fInFocus
)
2054 TXNFocus( varsp
->fTXNRec
, varsp
->fTXNObjectActive
);
2058 // update focus outlines
2059 static void TPRedrawFocusOutline(STPTextPaneVars
*varsp
) {
2062 if (varsp
->fFocusDrawState
!= (varsp
->fIsActive
&& varsp
->fInFocus
))
2064 varsp
->fFocusDrawState
= (varsp
->fIsActive
&& varsp
->fInFocus
);
2065 DrawThemeFocusRect(&varsp
->fRFocusOutline
, varsp
->fFocusDrawState
);
2069 // update TXN focus state
2070 static void TPFocusPaneText(STPTextPaneVars
*varsp
, Boolean setFocus
) {
2071 wxTextCtrl
* textctrl
= (wxTextCtrl
*) GetControlReference(varsp
->fUserPaneRec
);
2073 if (varsp
->fInFocus
!= setFocus
&& textctrl
->MacIsReallyShown()) {
2074 varsp
->fInFocus
= setFocus
;
2075 TXNFocus( varsp
->fTXNRec
, varsp
->fInFocus
);
2080 static pascal void TPPaneDrawProc(ControlRef theControl
, ControlPartCode thePart
) {
2081 /* set up our globals */
2083 wxTextCtrl
* textctrl
= (wxTextCtrl
*) GetControlReference(theControl
);
2084 if ( textctrl
== NULL
)
2086 TPUpdateVisibility( theControl
) ;
2088 STPTextPaneVars
*varsp
= (STPTextPaneVars
*) ((wxMacMLTEClassicControl
*)textctrl
->GetPeer())->m_macTXNvars
;
2089 if ( textctrl
->MacIsReallyShown() )
2091 wxMacWindowClipper
clipper( textctrl
) ;
2092 TXNDraw(varsp
->fTXNRec
, NULL
);
2093 if ( !varsp
->fNoBorders
)
2094 DrawThemeEditTextFrame(&varsp
->fRTextOutline
, varsp
->fIsActive
? kThemeStateActive
: kThemeStateInactive
);
2095 TPRedrawFocusOutline( varsp
) ;
2101 /* TPPaneHitTestProc is called when the control manager would
2102 like to determine what part of the control the mouse resides over.
2103 We also call this routine from our tracking proc to determine how
2104 to handle mouse clicks. */
2105 static pascal ControlPartCode
TPPaneHitTestProc(ControlRef theControl
, Point where
) {
2106 ControlPartCode result
;
2107 /* set up our locals and lock down our globals*/
2109 wxTextCtrl
* textctrl
= (wxTextCtrl
*) GetControlReference(theControl
);
2110 if ( textctrl
== NULL
)
2112 TPUpdateVisibility( theControl
) ;
2113 STPTextPaneVars
*varsp
= (STPTextPaneVars
*) ((wxMacMLTEClassicControl
*)textctrl
->GetPeer())->m_macTXNvars
;
2114 if (textctrl
->MacIsReallyShown() )
2116 if (PtInRect(where
, &varsp
->fRBounds
))
2117 result
= kmUPTextPart
;
2120 // sometimes we get the coords also in control local coordinates, therefore test again
2121 if ( textctrl
->MacGetTopLevelWindow()->MacUsesCompositing() )
2124 textctrl
->MacClientToRootWindow( &x
, &y
) ;
2128 if (PtInRect(where
, &varsp
->fRBounds
))
2129 result
= kmUPTextPart
;
2141 /* TPPaneTrackingProc is called when the mouse is being held down
2142 over our control. This routine handles clicks in the text area
2143 and in the scroll bar. */
2144 static pascal ControlPartCode
TPPaneTrackingProc(ControlRef theControl
, Point startPt
, ControlActionUPP actionProc
) {
2146 ControlPartCode partCodeResult
;
2147 /* make sure we have some variables... */
2149 wxTextCtrl
* textctrl
= (wxTextCtrl
*) GetControlReference(theControl
);
2150 if ( textctrl
== NULL
)
2152 TPUpdateVisibility( theControl
) ;
2153 STPTextPaneVars
*varsp
= (STPTextPaneVars
*) ((wxMacMLTEClassicControl
*)textctrl
->GetPeer())->m_macTXNvars
;
2154 if (textctrl
->MacIsReallyShown() )
2156 /* we don't do any of these functions unless we're in focus */
2157 if ( ! varsp
->fInFocus
) {
2159 owner
= GetControlOwner(theControl
);
2160 ClearKeyboardFocus(owner
);
2161 SetKeyboardFocus(owner
, theControl
, kUserClickedToFocusPart
);
2163 /* find the location for the click */
2164 // for compositing, we must convert these into toplevel window coordinates, because hittesting expects them
2165 if ( textctrl
->MacGetTopLevelWindow()->MacUsesCompositing() )
2168 textctrl
->MacClientToRootWindow( &x
, &y
) ;
2173 switch (TPPaneHitTestProc(theControl
, startPt
))
2176 /* handle clicks in the text part */
2179 wxMacWindowClipper
clipper( textctrl
) ;
2182 ConvertEventRefToEventRecord( (EventRef
) wxTheApp
->MacGetCurrentEvent() , &rec
) ;
2183 TXNClick( varsp
->fTXNRec
, &rec
);
2190 return partCodeResult
;
2194 /* TPPaneIdleProc is our user pane idle routine. When our text field
2195 is active and in focus, we use this routine to set the cursor. */
2196 static pascal void TPPaneIdleProc(ControlRef theControl
) {
2198 wxTextCtrl
* textctrl
= (wxTextCtrl
*) GetControlReference(theControl
);
2199 if ( textctrl
== NULL
)
2201 TPUpdateVisibility( theControl
) ;
2202 STPTextPaneVars
*varsp
= (STPTextPaneVars
*) ((wxMacMLTEClassicControl
*)textctrl
->GetPeer())->m_macTXNvars
;
2203 if (textctrl
->MacIsReallyShown()) {
2204 /* if we're not active, then we have nothing to say about the cursor */
2205 if (varsp
->fIsActive
) {
2209 wxMacWindowClipper
clipper( textctrl
) ;
2211 /* there's a 'focus thing' and an 'unfocused thing' */
2212 if (varsp
->fInFocus
) {
2213 /* flash the cursor */
2214 SetPort(varsp
->fDrawingEnvironment
);
2215 TXNIdle(varsp
->fTXNRec
);
2216 /* set the cursor */
2217 if (PtInRect(mousep
, &varsp
->fRTextArea
)) {
2219 RectRgn((theRgn
= NewRgn()), &varsp
->fRTextArea
);
2220 TXNAdjustCursor(varsp
->fTXNRec
, theRgn
);
2225 // SetThemeCursor(kThemeArrowCursor);
2228 /* if it's in our bounds, set the cursor */
2229 UMAGetControlBoundsInWindowCoords(theControl
, &bounds
);
2230 if (PtInRect(mousep
, &bounds
))
2232 // SetThemeCursor(kThemeArrowCursor);
2240 /* TPPaneKeyDownProc is called whenever a keydown event is directed
2241 at our control. Here, we direct the keydown event to the text
2242 edit record and redraw the scroll bar and text field as appropriate. */
2243 static pascal ControlPartCode
TPPaneKeyDownProc(ControlRef theControl
,
2244 SInt16 keyCode
, SInt16 charCode
, SInt16 modifiers
) {
2246 wxTextCtrl
* textctrl
= (wxTextCtrl
*) GetControlReference(theControl
);
2247 if ( textctrl
== NULL
)
2249 TPUpdateVisibility( theControl
) ;
2251 STPTextPaneVars
*varsp
= (STPTextPaneVars
*) ((wxMacMLTEClassicControl
*)textctrl
->GetPeer())->m_macTXNvars
;
2252 if (varsp
->fInFocus
)
2254 /* turn autoscrolling on and send the key event to text edit */
2255 wxMacWindowClipper
clipper( textctrl
) ;
2257 memset( &ev
, 0 , sizeof( ev
) ) ;
2259 ev
.modifiers
= modifiers
;
2260 ev
.message
= (( keyCode
<< 8 ) & keyCodeMask
) + ( charCode
& charCodeMask
) ;
2261 TXNKeyDown( varsp
->fTXNRec
, &ev
);
2263 return kControlEntireControl
;
2267 /* TPPaneActivateProc is called when the window containing
2268 the user pane control receives activate events. Here, we redraw
2269 the control and it's text as necessary for the activation state. */
2270 static pascal void TPPaneActivateProc(ControlRef theControl
, Boolean activating
) {
2272 wxTextCtrl
* textctrl
= (wxTextCtrl
*) GetControlReference(theControl
);
2274 if ( textctrl
== NULL
)
2276 TPUpdateVisibility( theControl
) ;
2278 STPTextPaneVars
*varsp
= (STPTextPaneVars
*) ((wxMacMLTEClassicControl
*)textctrl
->GetPeer())->m_macTXNvars
;
2280 varsp
->fIsActive
= activating
;
2281 wxMacWindowClipper
clipper( textctrl
) ;
2282 TPActivatePaneText(varsp
, varsp
->fIsActive
&& varsp
->fInFocus
);
2283 /* redraw the frame */
2284 if ( textctrl
->MacIsReallyShown() )
2286 if ( !varsp
->fNoBorders
)
2287 DrawThemeEditTextFrame(&varsp
->fRTextOutline
, varsp
->fIsActive
? kThemeStateActive
: kThemeStateInactive
);
2288 TPRedrawFocusOutline( varsp
) ;
2293 /* TPPaneFocusProc is called when every the focus changes to or
2294 from our control. Herein, switch the focus appropriately
2295 according to the parameters and redraw the control as
2297 static pascal ControlPartCode
TPPaneFocusProc(ControlRef theControl
, ControlFocusPart action
) {
2298 ControlPartCode focusResult
;
2300 focusResult
= kControlFocusNoPart
;
2301 wxTextCtrl
* textctrl
= (wxTextCtrl
*) GetControlReference(theControl
);
2302 if ( textctrl
== NULL
)
2304 TPUpdateVisibility( theControl
) ;
2305 STPTextPaneVars
*varsp
= (STPTextPaneVars
*) ((wxMacMLTEClassicControl
*)textctrl
->GetPeer())->m_macTXNvars
;
2306 /* if kControlFocusPrevPart and kControlFocusNextPart are received when the user is
2307 tabbing forwards (or shift tabbing backwards) through the items in the dialog,
2308 and kControlFocusNextPart will be received. When the user clicks in our field
2309 and it is not the current focus, then the constant kUserClickedToFocusPart will
2310 be received. The constant kControlFocusNoPart will be received when our control
2311 is the current focus and the user clicks in another control. In your focus routine,
2312 you should respond to these codes as follows:
2314 kControlFocusNoPart - turn off focus and return kControlFocusNoPart. redraw
2315 the control and the focus rectangle as necessary.
2317 kControlFocusPrevPart or kControlFocusNextPart - toggle focus on or off
2318 depending on its current state. redraw the control and the focus rectangle
2319 as appropriate for the new focus state. If the focus state is 'off', return the constant
2320 kControlFocusNoPart, otherwise return a non-zero part code.
2321 kUserClickedToFocusPart - is a constant defined for this example. You should
2322 define your own value for handling click-to-focus type events. */
2323 /* calculate the next highlight state */
2326 case kControlFocusNoPart
:
2327 TPFocusPaneText(varsp
, false);
2328 focusResult
= kControlFocusNoPart
;
2330 case kUserClickedToFocusPart
:
2331 TPFocusPaneText(varsp
, true);
2334 case kControlFocusPrevPart
:
2335 case kControlFocusNextPart
:
2336 TPFocusPaneText(varsp
, ( ! varsp
->fInFocus
));
2337 focusResult
= varsp
->fInFocus
? 1 : kControlFocusNoPart
;
2340 TPActivatePaneText(varsp
, varsp
->fIsActive
&& varsp
->fInFocus
);
2341 /* redraw the text fram and focus rectangle to indicate the
2343 if ( textctrl
->MacIsReallyShown() )
2345 wxMacWindowClipper
c( textctrl
) ;
2346 if ( !varsp
->fNoBorders
)
2347 DrawThemeEditTextFrame(&varsp
->fRTextOutline
, varsp
->fIsActive
? kThemeStateActive
: kThemeStateInactive
);
2348 TPRedrawFocusOutline( varsp
) ;
2353 wxMacMLTEClassicControl::wxMacMLTEClassicControl( wxWindow
*wxPeer
,
2354 const wxString
& str
,
2356 const wxSize
& size
, long style
)
2358 m_font
= wxPeer
->GetFont() ;
2359 m_windowStyle
= style
;
2360 Rect bounds
= wxMacGetBoundsForControl( wxPeer
, pos
, size
) ;
2362 wxMacConvertNewlines10To13( &st
) ;
2366 featurSet
= kControlSupportsEmbedding
| kControlSupportsFocus
| kControlWantsIdle
2367 | kControlWantsActivate
| kControlHandlesTracking
| kControlHasSpecialBackground
2368 | kControlGetsFocusOnClick
| kControlSupportsLiveFeedback
;
2369 /* create the control */
2371 verify_noerr( ::CreateUserPaneControl( MAC_WXHWND(wxPeer
->GetParent()->MacGetTopLevelWindowRef()), &bounds
, featurSet
, &m_controlRef
) );
2374 // wxMacWindowClipper c(wxPeer) ;
2378 if ( wxPeer
->MacIsReallyShown() )
2379 MLTESetObjectVisibility( (STPTextPaneVars
*) m_macTXNvars
, true , style
) ;
2382 // wxMacWindowClipper clipper( wxPeer ) ;
2384 TPUpdateVisibility( m_controlRef
) ;
2386 SetTXNData( st
, kTXNStartOffset
, kTXNEndOffset
) ;
2388 TXNSetSelection( m_txn
, 0, 0);
2389 TXNShowSelection( m_txn
, kTXNShowStart
);
2392 AdjustCreationAttributes( *wxWHITE
, true ) ;
2395 wxMacMLTEClassicControl::~wxMacMLTEClassicControl()
2397 // SetControlReference(m_controlRef , 0) ;
2398 TXNDeleteObject(m_txn
);
2402 void wxMacMLTEClassicControl::VisibilityChanged(bool shown
)
2404 MLTESetObjectVisibility((STPTextPaneVars
*) m_macTXNvars
, shown
, m_windowStyle
) ;
2406 InvalWindowRect( GetControlOwner( m_controlRef
) , &((STPTextPaneVars
*)m_macTXNvars
)->fRBounds
) ;
2409 OSStatus
wxMacMLTEClassicControl::DoCreate()
2412 WindowRef theWindow
;
2414 OSStatus err
= noErr
;
2416 /* set up our globals */
2417 if (gTPDrawProc
== NULL
) gTPDrawProc
= NewControlUserPaneDrawUPP(TPPaneDrawProc
);
2418 if (gTPHitProc
== NULL
) gTPHitProc
= NewControlUserPaneHitTestUPP(TPPaneHitTestProc
);
2419 if (gTPTrackProc
== NULL
) gTPTrackProc
= NewControlUserPaneTrackingUPP(TPPaneTrackingProc
);
2420 if (gTPIdleProc
== NULL
) gTPIdleProc
= NewControlUserPaneIdleUPP(TPPaneIdleProc
);
2421 if (gTPKeyProc
== NULL
) gTPKeyProc
= NewControlUserPaneKeyDownUPP(TPPaneKeyDownProc
);
2422 if (gTPActivateProc
== NULL
) gTPActivateProc
= NewControlUserPaneActivateUPP(TPPaneActivateProc
);
2423 if (gTPFocusProc
== NULL
) gTPFocusProc
= NewControlUserPaneFocusUPP(TPPaneFocusProc
);
2425 /* allocate our private storage */
2426 m_macTXNvars
= (STPTextPaneVars
*) malloc(sizeof(STPTextPaneVars
));
2428 /* set the initial settings for our private data */
2429 m_macTXNvars
->fMultiline
= m_windowStyle
& wxTE_MULTILINE
;
2430 m_macTXNvars
->fNoBorders
= m_windowStyle
& wxNO_BORDER
;
2431 m_macTXNvars
->fInFocus
= false;
2432 m_macTXNvars
->fIsActive
= true;
2433 m_macTXNvars
->fTXNObjectActive
= false;
2434 m_macTXNvars
->fFocusDrawState
= false ;
2435 m_macTXNvars
->fUserPaneRec
= m_controlRef
;
2436 m_macTXNvars
->fVisible
= true ;
2438 theWindow
= m_macTXNvars
->fOwner
= GetControlOwner(m_controlRef
);
2440 m_macTXNvars
->fDrawingEnvironment
= (GrafPtr
) GetWindowPort(theWindow
);
2442 /* set up the user pane procedures */
2443 SetControlData(m_controlRef
, kControlEntireControl
, kControlUserPaneDrawProcTag
, sizeof(gTPDrawProc
), &gTPDrawProc
);
2444 SetControlData(m_controlRef
, kControlEntireControl
, kControlUserPaneHitTestProcTag
, sizeof(gTPHitProc
), &gTPHitProc
);
2445 SetControlData(m_controlRef
, kControlEntireControl
, kControlUserPaneTrackingProcTag
, sizeof(gTPTrackProc
), &gTPTrackProc
);
2446 SetControlData(m_controlRef
, kControlEntireControl
, kControlUserPaneIdleProcTag
, sizeof(gTPIdleProc
), &gTPIdleProc
);
2447 SetControlData(m_controlRef
, kControlEntireControl
, kControlUserPaneKeyDownProcTag
, sizeof(gTPKeyProc
), &gTPKeyProc
);
2448 SetControlData(m_controlRef
, kControlEntireControl
, kControlUserPaneActivateProcTag
, sizeof(gTPActivateProc
), &gTPActivateProc
);
2449 SetControlData(m_controlRef
, kControlEntireControl
, kControlUserPaneFocusProcTag
, sizeof(gTPFocusProc
), &gTPFocusProc
);
2451 /* calculate the rectangles used by the control */
2452 UMAGetControlBoundsInWindowCoords(m_controlRef
, &bounds
);
2453 m_macTXNvars
->fRTextOutlineRegion
= NewRgn() ;
2454 TPCalculateBounds( m_macTXNvars
, bounds
) ;
2456 /* set up the drawing environment */
2457 SetPort(m_macTXNvars
->fDrawingEnvironment
);
2459 /* create the new edit field */
2461 TXNFrameOptions frameOptions
= FrameOptionsFromWXStyle( m_windowStyle
) ;
2463 verify_noerr(TXNNewObject(NULL
, m_macTXNvars
->fOwner
, &m_macTXNvars
->fRTextArea
,
2465 kTXNTextEditStyleFrameType
,
2467 kTXNSystemDefaultEncoding
,
2468 &m_macTXNvars
->fTXNRec
, &m_macTXNvars
->fTXNFrame
, (TXNObjectRefcon
) m_macTXNvars
));
2469 m_txn
= m_macTXNvars
->fTXNRec
;
2471 /* perform final activations and setup for our text field. Here,
2472 we assume that the window is going to be the 'active' window. */
2473 TPActivatePaneText(m_macTXNvars
, m_macTXNvars
->fIsActive
&& m_macTXNvars
->fInFocus
);
2478 // ----------------------------------------------------------------------------
2479 // MLTE control implementation (OSX part)
2480 // ----------------------------------------------------------------------------
2482 #if TARGET_API_MAC_OSX
2484 #if MAC_OS_X_VERSION_MAX_ALLOWED > MAC_OS_X_VERSION_10_2
2486 wxMacMLTEHIViewControl::wxMacMLTEHIViewControl( wxWindow
*wxPeer
,
2487 const wxString
& str
,
2489 const wxSize
& size
, long style
)
2491 m_font
= wxPeer
->GetFont() ;
2492 m_windowStyle
= style
;
2493 Rect bounds
= wxMacGetBoundsForControl( wxPeer
, pos
, size
) ;
2495 wxMacConvertNewlines10To13( &st
) ;
2497 HIRect hr
= { bounds
.left
, bounds
.top
, bounds
.right
- bounds
.left
, bounds
.bottom
- bounds
.top
} ;
2499 m_scrollView
= NULL
;
2500 TXNFrameOptions frameOptions
= FrameOptionsFromWXStyle( style
) ;
2501 if ( frameOptions
& (kTXNWantVScrollBarMask
|kTXNWantHScrollBarMask
) )
2503 HIScrollViewCreate(( frameOptions
& kTXNWantHScrollBarMask
? kHIScrollViewOptionsHorizScroll
: 0) |
2504 ( frameOptions
& kTXNWantVScrollBarMask
? kHIScrollViewOptionsVertScroll
: 0 ) , &m_scrollView
) ;
2506 HIViewSetFrame( m_scrollView
, &hr
);
2507 HIViewSetVisible( m_scrollView
, true );
2511 HITextViewCreate( NULL
, 0, frameOptions
, &m_textView
) ;
2512 m_txn
= HITextViewGetTXNObject( m_textView
) ;
2513 HIViewSetVisible( m_textView
, true ) ;
2516 HIViewAddSubview( m_scrollView
, m_textView
) ;
2517 m_controlRef
= m_scrollView
;
2518 wxPeer
->MacInstallEventHandler( (WXWidget
) m_textView
) ;
2522 HIViewSetFrame( m_textView
, &hr
);
2523 m_controlRef
= m_textView
;
2527 SetTXNData( st
, kTXNStartOffset
, kTXNEndOffset
) ;
2529 TXNSetSelection( m_txn
, 0, 0);
2530 TXNShowSelection( m_txn
, kTXNShowStart
);
2532 AdjustCreationAttributes( *wxWHITE
, true ) ;
2535 OSStatus
wxMacMLTEHIViewControl::SetFocus( ControlFocusPart focusPart
)
2537 return SetKeyboardFocus( GetControlOwner( m_textView
) ,
2538 m_textView
, focusPart
) ;
2541 bool wxMacMLTEHIViewControl::HasFocus() const
2543 ControlRef control
;
2544 GetKeyboardFocus( GetUserFocusWindow() , &control
) ;
2545 return control
== m_textView
;
2548 bool wxMacMLTEHIViewControl::NeedsFocusRect() const
2550 return m_windowStyle
& wxNO_BORDER
? false : true;
2553 #endif // MAC_OS_X_VERSION_MAX_ALLOWED > MAC_OS_X_VERSION_10_2
2558 #endif // wxUSE_TEXTCTRL