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 // if this is set to 1 then under OSX 10.2 the 'classic' MLTE implementation will be used
60 // if set to 0 then the unicode textctrl will be used
61 #ifndef wxMAC_AWAYS_USE_MLTE
62 #define wxMAC_AWAYS_USE_MLTE 1
65 #include <MacTextEditor.h>
66 #include <ATSUnicode.h>
67 #include <TextCommon.h>
68 #include <TextEncodingConverter.h>
69 #include "wx/mac/uma.h"
75 virtual ~wxMacFunctor() {}
76 virtual void* operator()() = 0 ;
77 static void* CallBackProc(void *param
)
79 wxMacFunctor
* f
= (wxMacFunctor
*) param
;
80 void *result
= (*f
)() ;
85 template<typename classtype
,typename param1type
>
86 class wxMacObjectFunctor1
: public wxMacFunctor
88 typedef void (classtype::*function
)( param1type p1
) ;
89 typedef void (classtype::*ref_function
)( const param1type
& p1
) ;
91 wxMacObjectFunctor1( classtype
*obj
, function f
, param1type p1
) :
99 wxMacObjectFunctor1( classtype
*obj
, ref_function f
, param1type p1
) :
107 ~wxMacObjectFunctor1() {}
109 virtual void* operator()()
111 (m_object
->*m_function
)(m_param1
) ;
115 classtype
* m_object
;
116 param1type m_param1
;
119 function m_function
;
120 ref_function m_refFunction
;
124 template<typename classtype
, typename param1type
>
125 void* wxMacMPRemoteCall( classtype
*object
, void (classtype::*function
)( param1type p1
) , param1type p1
)
127 wxMacObjectFunctor1
<classtype
,param1type
> params(object
,function
,p1
) ;
129 MPRemoteCall( wxMacFunctor::CallBackProc
, ¶ms
, kMPOwningProcessRemoteContext
) ;
133 template<typename classtype
, typename param1type
>
134 void* wxMacMPRemoteCall( classtype
*object
, void (classtype::*function
)( const param1type
& p1
) , param1type p1
)
136 wxMacObjectFunctor1
<classtype
,param1type
> params(object
,function
,p1
) ;
138 MPRemoteCall( wxMacFunctor::CallBackProc
, ¶ms
, kMPOwningProcessRemoteContext
) ;
142 template<typename classtype
, typename param1type
>
143 void* wxMacMPRemoteGUICall( classtype
*object
, void (classtype::*function
)( param1type p1
) , param1type p1
)
146 void *result
= wxMacMPRemoteCall( object
, function
, p1
) ;
151 template<typename classtype
, typename param1type
>
152 void* wxMacMPRemoteGUICall( classtype
*object
, void (classtype::*function
)( const param1type
& p1
) , param1type p1
)
155 void *result
= wxMacMPRemoteCall( object
, function
, p1
) ;
159 // common interface for all implementations
160 class wxMacTextControl
: public wxMacControl
164 ~wxMacTextControl() ;
166 virtual wxString
GetStringValue() const = 0 ;
167 virtual void SetStringValue( const wxString
&val
) = 0 ;
168 virtual void SetStyle(long start
, long end
, const wxTextAttr
& style
) ;
169 virtual void Copy() ;
171 virtual void Paste() ;
172 virtual bool CanPaste() const ;
173 virtual void SetEditable(bool editable
) ;
174 virtual long GetLastPosition() const ;
175 virtual void Replace( long from
, long to
, const wxString str
) ;
176 virtual void Remove( long from
, long to
) = 0 ;
177 virtual void SetSelection( long from
, long to
) = 0 ;
178 virtual void GetSelection( long* from
, long* to
) const = 0 ;
179 virtual void WriteText(const wxString
& str
) = 0 ;
181 virtual void Clear() ;
182 virtual bool CanUndo() const;
183 virtual void Undo() ;
184 virtual bool CanRedo() const;
185 virtual void Redo() ;
186 virtual int GetNumberOfLines() const ;
187 virtual long XYToPosition(long x
, long y
) const;
188 virtual bool PositionToXY(long pos
, long *x
, long *y
) const ;
189 virtual void ShowPosition( long WXUNUSED(pos
) ) ;
190 virtual int GetLineLength(long lineNo
) const ;
191 virtual wxString
GetLineText(long lineNo
) const ;
194 // common parts for implementations based on MLTE
196 class wxMacMLTEControl
: public wxMacTextControl
199 virtual wxString
GetStringValue() const ;
200 virtual void SetStringValue( const wxString
&str
) ;
202 static int ConvertAttribute( const wxTextAttr
& style
, TXNTypeAttributes attr
[] ) ;
203 static TXNFrameOptions
FrameOptionsFromWXStyle( long wxStyle
) ;
204 void AdjustCreationAttributes( const wxColour
& background
, bool visible
) ;
206 virtual void SetFont( const wxFont
& font
, const wxColour
& foreground
, long windowStyle
) ;
207 virtual void SetBackground( const wxBrush
&brush
) ;
208 virtual void SetStyle(long start
, long end
, const wxTextAttr
& style
) ;
209 virtual void Copy() ;
211 virtual void Paste() ;
212 virtual bool CanPaste() const ;
213 virtual void SetEditable(bool editable
) ;
214 virtual long GetLastPosition() const ;
215 virtual void Replace( long from
, long to
, const wxString str
) ;
216 virtual void Remove( long from
, long to
) ;
217 virtual void GetSelection( long* from
, long* to
) const ;
218 virtual void SetSelection( long from
, long to
) ;
220 virtual void WriteText(const wxString
& str
) ;
221 virtual void Clear() ;
223 virtual bool CanUndo() const ;
224 virtual void Undo() ;
225 virtual bool CanRedo() const;
226 virtual void Redo() ;
227 virtual int GetNumberOfLines() const ;
228 virtual long XYToPosition(long x
, long y
) const ;
229 virtual bool PositionToXY(long pos
, long *x
, long *y
) const ;
230 virtual void ShowPosition( long pos
) ;
231 virtual int GetLineLength(long lineNo
) const ;
232 virtual wxString
GetLineText(long lineNo
) const ;
234 void SetTXNData( const wxString
& st
, TXNOffset start
, TXNOffset end
) ;
240 #if TARGET_API_MAC_OSX
242 // implementation available under OSX
244 #if MAC_OS_X_VERSION_MAX_ALLOWED > MAC_OS_X_VERSION_10_2
246 class wxMacMLTEHIViewControl
: public wxMacMLTEControl
249 wxMacMLTEHIViewControl( wxWindow
*wxPeer
,
252 const wxSize
& size
, long style
) ;
253 virtual OSStatus
SetFocus( ControlFocusPart focusPart
) ;
254 virtual bool HasFocus() const ;
255 virtual bool NeedsFocusRect() const ;
257 HIViewRef m_scrollView
;
258 HIViewRef m_textView
;
263 class wxMacUnicodeTextControl
: public wxMacTextControl
266 wxMacUnicodeTextControl( wxWindow
*wxPeer
,
269 const wxSize
& size
, long style
) ;
270 ~wxMacUnicodeTextControl();
271 virtual void VisibilityChanged(bool shown
);
272 virtual wxString
GetStringValue() const ;
273 virtual void SetStringValue( const wxString
&str
) ;
276 virtual void Paste();
277 virtual bool CanPaste() const;
278 virtual void SetEditable(bool editable
) ;
279 virtual void Remove( long from
, long to
) ;
280 virtual void GetSelection( long* from
, long* to
) const ;
281 virtual void SetSelection( long from
, long to
) ;
282 virtual void WriteText(const wxString
& str
) ;
284 // contains the tag for the content (is different for password and non-password controls)
290 // implementation available under classic
292 class STPTextPaneVars
;
294 class wxMacMLTEClassicControl
: public wxMacMLTEControl
297 wxMacMLTEClassicControl( wxWindow
*wxPeer
,
300 const wxSize
& size
, long style
) ;
301 ~wxMacMLTEClassicControl() ;
302 virtual void VisibilityChanged(bool shown
) ;
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
) )
392 m_windowStyle
&= ~wxSUNKEN_BORDER
;
393 m_peer
= new wxMacMLTEClassicControl( this , str
, pos
, size
, style
) ;
396 MacPostControlCreate(pos
,size
) ;
398 if ( m_windowStyle
& wxTE_READONLY
)
400 SetEditable( false ) ;
407 void wxTextCtrl::MacVisibilityChanged()
409 GetPeer()->VisibilityChanged( MacIsReallyShown() ) ;
412 void wxTextCtrl::MacEnabledStateChanged()
416 wxString
wxTextCtrl::GetValue() const
418 return GetPeer()->GetStringValue() ;
421 void wxTextCtrl::GetSelection(long* from
, long* to
) const
423 GetPeer()->GetSelection( from
, to
) ;
426 void wxTextCtrl::SetValue(const wxString
& str
)
429 if ( GetValue() == str
)
432 GetPeer()->SetStringValue(str
) ;
435 void wxTextCtrl::SetMaxLength(unsigned long len
)
440 bool wxTextCtrl::SetFont( const wxFont
& font
)
442 if ( !wxTextCtrlBase::SetFont( font
) )
445 GetPeer()->SetFont( font
, GetForegroundColour() , GetWindowStyle() ) ;
449 bool wxTextCtrl::SetStyle(long start
, long end
, const wxTextAttr
& style
)
451 GetPeer()->SetStyle( start
, end
, style
) ;
455 bool wxTextCtrl::SetDefaultStyle(const wxTextAttr
& style
)
457 wxTextCtrlBase::SetDefaultStyle( style
) ;
458 SetStyle( kTXNUseCurrentSelection
, kTXNUseCurrentSelection
, GetDefaultStyle() ) ;
462 // Clipboard operations
463 void wxTextCtrl::Copy()
471 void wxTextCtrl::Cut()
477 wxCommandEvent
event(wxEVT_COMMAND_TEXT_UPDATED
, m_windowId
);
478 event
.SetString( GetValue() ) ;
479 event
.SetEventObject( this );
480 GetEventHandler()->ProcessEvent(event
);
484 void wxTextCtrl::Paste()
489 // eventually we should add setting the default style again
491 wxCommandEvent
event(wxEVT_COMMAND_TEXT_UPDATED
, m_windowId
);
492 event
.SetString( GetValue() ) ;
493 event
.SetEventObject( this );
494 GetEventHandler()->ProcessEvent(event
);
498 bool wxTextCtrl::CanCopy() const
500 // Can copy if there's a selection
502 GetSelection(& from
, & to
);
506 bool wxTextCtrl::CanCut() const
512 // Can cut if there's a selection
514 GetSelection(& from
, & to
);
518 bool wxTextCtrl::CanPaste() const
523 return GetPeer()->CanPaste() ;
526 void wxTextCtrl::SetEditable(bool editable
)
528 if ( editable
!= m_editable
)
530 m_editable
= editable
;
531 GetPeer()->SetEditable( editable
) ;
535 void wxTextCtrl::SetInsertionPoint(long pos
)
537 SetSelection( pos
, pos
) ;
540 void wxTextCtrl::SetInsertionPointEnd()
542 long pos
= GetLastPosition();
543 SetInsertionPoint(pos
);
546 long wxTextCtrl::GetInsertionPoint() const
549 GetSelection( &begin
, &end
) ;
553 long wxTextCtrl::GetLastPosition() const
555 return GetPeer()->GetLastPosition( ) ;
558 void wxTextCtrl::Replace(long from
, long to
, const wxString
& str
)
560 GetPeer()->Replace( from
, to
, str
) ;
563 void wxTextCtrl::Remove(long from
, long to
)
565 GetPeer()->Remove( from
, to
) ;
568 void wxTextCtrl::SetSelection(long from
, long to
)
570 GetPeer()->SetSelection( from
, to
) ;
573 bool wxTextCtrl::LoadFile(const wxString
& file
)
575 if ( wxTextCtrlBase::LoadFile(file
) )
583 void wxTextCtrl::WriteText(const wxString
& str
)
585 // TODO this MPRemoting will be moved into a remoting peer proxy for any command
586 if ( !wxIsMainThread() )
588 // unfortunately CW 8 is not able to correctly deduce the template types, so we have
589 // to instantiate explicitely
590 wxMacMPRemoteGUICall
<wxTextCtrl
,wxString
>( this , &wxTextCtrl::WriteText
, str
) ;
595 GetPeer()->WriteText( str
) ;
599 void wxTextCtrl::AppendText(const wxString
& text
)
601 SetInsertionPointEnd();
605 void wxTextCtrl::Clear()
610 bool wxTextCtrl::IsModified() const
615 bool wxTextCtrl::IsEditable() const
617 return IsEnabled() && m_editable
;
620 bool wxTextCtrl::AcceptsFocus() const
622 // we don't want focus if we can't be edited
623 return /*IsEditable() && */ wxControl::AcceptsFocus();
626 wxSize
wxTextCtrl::DoGetBestSize() const
632 // these are the numbers from the HIG, we reduce them by the borders
635 switch( m_windowVariant
)
637 case wxWINDOW_VARIANT_NORMAL
:
640 case wxWINDOW_VARIANT_SMALL
:
643 case wxWINDOW_VARIANT_MINI
:
651 // as the above numbers have some free space around the text
652 // we get 5 lines like this anyway
653 if ( m_windowStyle
& wxTE_MULTILINE
)
658 if ( !HasFlag(wxNO_BORDER
) )
661 return wxSize(wText
, hText
);
664 // ----------------------------------------------------------------------------
666 // ----------------------------------------------------------------------------
668 void wxTextCtrl::Undo()
676 void wxTextCtrl::Redo()
684 bool wxTextCtrl::CanUndo() const
690 return GetPeer()->CanUndo() ;
693 bool wxTextCtrl::CanRedo() const
699 return GetPeer()->CanRedo() ;
702 void wxTextCtrl::MarkDirty()
707 void wxTextCtrl::DiscardEdits()
712 int wxTextCtrl::GetNumberOfLines() const
714 return GetPeer()->GetNumberOfLines() ;
717 long wxTextCtrl::XYToPosition(long x
, long y
) const
719 return GetPeer()->XYToPosition( x
, y
) ;
722 bool wxTextCtrl::PositionToXY(long pos
, long *x
, long *y
) const
724 return GetPeer()->PositionToXY(pos
, x
, y
) ;
727 void wxTextCtrl::ShowPosition(long pos
)
729 return GetPeer()->ShowPosition(pos
) ;
732 int wxTextCtrl::GetLineLength(long lineNo
) const
734 return GetPeer()->GetLineLength(lineNo
) ;
737 wxString
wxTextCtrl::GetLineText(long lineNo
) const
739 return GetPeer()->GetLineText(lineNo
) ;
746 void wxTextCtrl::Command(wxCommandEvent
& event
)
748 SetValue (event
.GetString());
749 ProcessCommand (event
);
752 void wxTextCtrl::OnDropFiles(wxDropFilesEvent
& event
)
754 // By default, load the first file into the text window.
755 if (event
.GetNumberOfFiles() > 0)
757 LoadFile(event
.GetFiles()[0]);
761 void wxTextCtrl::OnEraseBackground(wxEraseEvent
& event
)
763 // all erasing should be done by the real mac control implementation
764 // while this is true for MLTE under classic, the HITextView is somehow
765 // transparent but background erase is not working correctly, so intercept
766 // things while we can...
769 void wxTextCtrl::OnChar(wxKeyEvent
& event
)
771 int key
= event
.GetKeyCode() ;
772 bool eat_key
= false ;
774 if ( key
== 'c' && event
.MetaDown() )
781 if ( !IsEditable() && key
!= WXK_LEFT
&& key
!= WXK_RIGHT
&& key
!= WXK_DOWN
&& key
!= WXK_UP
&& key
!= WXK_TAB
&&
782 !( key
== WXK_RETURN
&& ( (m_windowStyle
& wxPROCESS_ENTER
) || (m_windowStyle
& wxTE_MULTILINE
) ) )
783 /* && key != WXK_PRIOR && key != WXK_NEXT && key != WXK_HOME && key != WXK_END */
790 // assume that any key not processed yet is going to modify the control
793 if ( key
== 'v' && event
.MetaDown() )
799 if ( key
== 'x' && event
.MetaDown() )
808 if (m_windowStyle
& wxPROCESS_ENTER
)
810 wxCommandEvent
event(wxEVT_COMMAND_TEXT_ENTER
, m_windowId
);
811 event
.SetEventObject( this );
812 event
.SetString( GetValue() );
813 if ( GetEventHandler()->ProcessEvent(event
) )
816 if ( !(m_windowStyle
& wxTE_MULTILINE
) )
818 wxWindow
*parent
= GetParent();
819 while( parent
&& !parent
->IsTopLevel() && parent
->GetDefaultItem() == NULL
) {
820 parent
= parent
->GetParent() ;
822 if ( parent
&& parent
->GetDefaultItem() )
824 wxButton
*def
= wxDynamicCast(parent
->GetDefaultItem(),
826 if ( def
&& def
->IsEnabled() )
828 wxCommandEvent
event(wxEVT_COMMAND_BUTTON_CLICKED
, def
->GetId() );
829 event
.SetEventObject(def
);
835 // this will make wxWidgets eat the ENTER key so that
836 // we actually prevent line wrapping in a single line
844 if ( !(m_windowStyle
& wxTE_PROCESS_TAB
))
847 if (!event
.ShiftDown())
848 flags
|= wxNavigationKeyEvent::IsForward
;
849 if (event
.ControlDown())
850 flags
|= wxNavigationKeyEvent::WinChange
;
856 // This is necessary (don't know why) or the tab will not
858 WriteText(wxT("\t"));
866 // perform keystroke handling
867 if ( wxTheApp
->MacGetCurrentEvent() != NULL
&& wxTheApp
->MacGetCurrentEventHandlerCallRef() != NULL
)
868 CallNextEventHandler((EventHandlerCallRef
)wxTheApp
->MacGetCurrentEventHandlerCallRef() , (EventRef
) wxTheApp
->MacGetCurrentEvent() ) ;
872 if ( wxMacConvertEventToRecord( (EventRef
) wxTheApp
->MacGetCurrentEvent() , &rec
) )
874 EventRecord
*ev
= &rec
;
877 keychar
= short(ev
->message
& charCodeMask
);
878 keycode
= short(ev
->message
& keyCodeMask
) >> 8 ;
880 m_peer
->HandleKey( keycode
, keychar
, ev
->modifiers
) ;
884 if ( ( key
>= 0x20 && key
< WXK_START
) ||
889 wxCommandEvent
event1(wxEVT_COMMAND_TEXT_UPDATED
, m_windowId
);
890 event1
.SetString( GetValue() ) ;
891 event1
.SetEventObject( this );
892 wxPostEvent(GetEventHandler(),event1
);
896 // ----------------------------------------------------------------------------
897 // standard handlers for standard edit menu events
898 // ----------------------------------------------------------------------------
900 void wxTextCtrl::OnCut(wxCommandEvent
& WXUNUSED(event
))
905 void wxTextCtrl::OnCopy(wxCommandEvent
& WXUNUSED(event
))
910 void wxTextCtrl::OnPaste(wxCommandEvent
& WXUNUSED(event
))
915 void wxTextCtrl::OnUndo(wxCommandEvent
& WXUNUSED(event
))
920 void wxTextCtrl::OnRedo(wxCommandEvent
& WXUNUSED(event
))
925 void wxTextCtrl::OnUpdateCut(wxUpdateUIEvent
& event
)
927 event
.Enable( CanCut() );
930 void wxTextCtrl::OnUpdateCopy(wxUpdateUIEvent
& event
)
932 event
.Enable( CanCopy() );
935 void wxTextCtrl::OnUpdatePaste(wxUpdateUIEvent
& event
)
937 event
.Enable( CanPaste() );
940 void wxTextCtrl::OnUpdateUndo(wxUpdateUIEvent
& event
)
942 event
.Enable( CanUndo() );
945 void wxTextCtrl::OnUpdateRedo(wxUpdateUIEvent
& event
)
947 event
.Enable( CanRedo() );
950 bool wxTextCtrl::MacSetupCursor( const wxPoint
& pt
)
955 // user pane implementation
957 void wxTextCtrl::MacControlUserPaneDrawProc(wxInt16 part
)
961 wxInt16
wxTextCtrl::MacControlUserPaneHitTestProc(wxInt16 x
, wxInt16 y
)
963 return kControlNoPart
;
966 wxInt16
wxTextCtrl::MacControlUserPaneTrackingProc(wxInt16 x
, wxInt16 y
, void* actionProc
)
968 return kControlNoPart
;
971 void wxTextCtrl::MacControlUserPaneIdleProc()
975 wxInt16
wxTextCtrl::MacControlUserPaneKeyDownProc(wxInt16 keyCode
, wxInt16 charCode
, wxInt16 modifiers
)
977 return kControlNoPart
;
980 void wxTextCtrl::MacControlUserPaneActivateProc(bool activating
)
984 wxInt16
wxTextCtrl::MacControlUserPaneFocusProc(wxInt16 action
)
986 return kControlNoPart
;
989 void wxTextCtrl::MacControlUserPaneBackgroundProc(void* info
)
993 // ----------------------------------------------------------------------------
994 // implementation base class
995 // ----------------------------------------------------------------------------
997 wxMacTextControl::wxMacTextControl()
1001 wxMacTextControl::~wxMacTextControl()
1005 void wxMacTextControl::SetStyle(long start
, long end
, const wxTextAttr
& style
)
1009 void wxMacTextControl::Copy()
1013 void wxMacTextControl::Cut()
1017 void wxMacTextControl::Paste()
1021 bool wxMacTextControl::CanPaste() const
1026 void wxMacTextControl::SetEditable(bool editable
)
1030 long wxMacTextControl::GetLastPosition() const
1032 return GetStringValue().Length() ;
1035 void wxMacTextControl::Replace( long from
, long to
, const wxString str
)
1039 void wxMacTextControl::Clear()
1041 SetStringValue( wxEmptyString
) ;
1044 bool wxMacTextControl::CanUndo() const
1049 void wxMacTextControl::Undo() { }
1051 bool wxMacTextControl::CanRedo() const
1056 void wxMacTextControl::Redo()
1060 long wxMacTextControl::XYToPosition(long x
, long y
) const
1065 bool wxMacTextControl::PositionToXY(long pos
, long *x
, long *y
) const
1070 void wxMacTextControl::ShowPosition( long WXUNUSED(pos
) )
1074 int wxMacTextControl::GetNumberOfLines() const
1076 ItemCount lines
= 0 ;
1077 wxString content
= GetStringValue() ;
1079 for (size_t i
= 0; i
< content
.Length() ; i
++)
1081 if (content
[i
] == '\r') lines
++;
1086 wxString
wxMacTextControl::GetLineText(long lineNo
) const
1088 // TODO change this if possible to reflect real lines
1089 wxString content
= GetStringValue() ;
1093 for (size_t i
= 0; i
< content
.Length() ; i
++)
1095 if (count
== lineNo
)
1097 // Add chars in line then
1100 for (size_t j
= i
; j
< content
.Length(); j
++)
1102 if (content
[j
] == '\n')
1110 if (content
[i
] == '\n') count
++;
1112 return wxEmptyString
;
1115 int wxMacTextControl::GetLineLength(long lineNo
) const
1117 // TODO change this if possible to reflect real lines
1118 wxString content
= GetStringValue() ;
1122 for (size_t i
= 0; i
< content
.Length() ; i
++)
1124 if (count
== lineNo
)
1126 // Count chars in line then
1128 for (size_t j
= i
; j
< content
.Length(); j
++)
1131 if (content
[j
] == '\n') return count
;
1136 if (content
[i
] == '\n') count
++;
1141 // ----------------------------------------------------------------------------
1142 // standard unicode control implementation
1143 // ----------------------------------------------------------------------------
1145 #if TARGET_API_MAC_OSX
1147 wxMacUnicodeTextControl::wxMacUnicodeTextControl( wxWindow
*wxPeer
,
1148 const wxString
& str
,
1150 const wxSize
& size
, long style
)
1152 m_font
= wxPeer
->GetFont() ;
1153 m_windowStyle
= style
;
1154 Rect bounds
= wxMacGetBoundsForControl( wxPeer
, pos
, size
) ;
1156 wxMacConvertNewlines13To10( &st
) ;
1157 wxMacCFStringHolder
cf(st
, m_font
.GetEncoding()) ;
1158 CFStringRef cfr
= cf
;
1159 Boolean isPassword
= ( m_windowStyle
& wxTE_PASSWORD
) != 0 ;
1160 m_valueTag
= isPassword
? kControlEditTextPasswordCFStringTag
: kControlEditTextCFStringTag
;
1161 CreateEditUnicodeTextControl( MAC_WXHWND(wxPeer
->MacGetTopLevelWindowRef()), &bounds
, cfr
, isPassword
, NULL
, &m_controlRef
) ;
1163 if ( !(m_windowStyle
& wxTE_MULTILINE
) )
1165 SetData
<Boolean
>( kControlEditTextPart
, kControlEditTextSingleLineTag
, true ) ;
1169 wxMacUnicodeTextControl::~wxMacUnicodeTextControl()
1173 void wxMacUnicodeTextControl::VisibilityChanged(bool shown
)
1175 if ( !(m_windowStyle
& wxTE_MULTILINE
) && shown
)
1177 // work around a refresh issue insofar as not always the entire content is shown even if this would be possible
1178 ControlEditTextSelectionRec sel
;
1179 CFStringRef value
= NULL
;
1181 verify_noerr( GetData
<ControlEditTextSelectionRec
>( 0, kControlEditTextSelectionTag
, &sel
) );
1182 verify_noerr( GetData
<CFStringRef
>( 0, m_valueTag
, &value
) );
1183 verify_noerr( SetData
<CFStringRef
>( 0, m_valueTag
, &value
) );
1184 verify_noerr( SetData
<ControlEditTextSelectionRec
>( 0, kControlEditTextSelectionTag
, &sel
) );
1186 CFRelease( value
) ;
1189 wxString
wxMacUnicodeTextControl::GetStringValue() const
1192 CFStringRef value
= GetData
<CFStringRef
>(0,m_valueTag
) ;
1195 wxMacCFStringHolder
cf(value
) ;
1196 result
= cf
.AsString() ;
1198 wxMacConvertNewlines10To13( &result
) ;
1201 void wxMacUnicodeTextControl::SetStringValue( const wxString
&str
)
1204 wxMacConvertNewlines13To10( &st
) ;
1205 wxMacCFStringHolder
cf(st
, m_font
.GetEncoding() ) ;
1206 verify_noerr( SetData
<CFStringRef
>( 0, m_valueTag
, cf
) ) ;
1208 void wxMacUnicodeTextControl::Copy()
1210 SendHICommand( kHICommandCopy
) ;
1212 void wxMacUnicodeTextControl::Cut()
1214 SendHICommand( kHICommandCut
) ;
1216 void wxMacUnicodeTextControl::Paste()
1218 SendHICommand( kHICommandPaste
) ;
1220 bool wxMacUnicodeTextControl::CanPaste() const
1224 void wxMacUnicodeTextControl::SetEditable(bool editable
)
1226 SetData
<Boolean
>( 0 , kControlEditTextLockedTag
, (Boolean
) !editable
) ;
1228 void wxMacUnicodeTextControl::Remove( long from
, long to
)
1232 void wxMacUnicodeTextControl::GetSelection( long* from
, long* to
) const
1234 ControlEditTextSelectionRec sel
;
1235 verify_noerr(GetData
<ControlEditTextSelectionRec
>( 0, kControlEditTextSelectionTag
, &sel
) ) ;
1236 if ( from
) *from
= sel
.selStart
;
1237 if ( to
) *to
= sel
.selEnd
;
1240 void wxMacUnicodeTextControl::SetSelection( long from
, long to
)
1242 ControlEditTextSelectionRec sel
;
1243 sel
.selStart
= from
;
1245 SetData
<ControlEditTextSelectionRec
>( 0 , kControlEditTextSelectionTag
, &sel
) ;
1248 void wxMacUnicodeTextControl::WriteText(const wxString
& str
)
1251 wxMacConvertNewlines13To10( &st
) ;
1252 #if MAC_OS_X_VERSION_MAX_ALLOWED > MAC_OS_X_VERSION_10_2
1253 wxMacCFStringHolder
cf(st
, m_font
.GetEncoding() ) ;
1254 CFStringRef value
= cf
;
1255 SetData
<CFStringRef
>( 0, kControlEditTextInsertCFStringRefTag
, &value
);
1257 wxString val
= GetStringValue() ;
1259 GetSelection( &start
, &end
) ;
1260 val
.Remove( start
, end
- start
) ;
1261 val
.insert( start
, str
) ;
1262 SetStringValue( val
) ;
1263 SetSelection( start
+ str
.Length() , start
+ str
.Length() ) ;
1269 // ----------------------------------------------------------------------------
1270 // MLTE control implementation (common part)
1271 // ----------------------------------------------------------------------------
1273 #if TARGET_API_MAC_OSX == 0
1274 // declaration needed because of one line in the code...
1275 static void TPUpdateVisibility(ControlRef theControl
) ;
1278 // if mlte is on read only , no changes at all are allowed, not even from
1279 // procedural API, in order to allow changes via API all the same we must undo
1280 // the readonly status while we are executing, this class helps to do so
1285 EditHelper( TXNObject txn
)
1287 TXNControlTag tag
[] = { kTXNIOPrivilegesTag
} ;
1289 TXNGetTXNObjectControls( m_txn
, 1 , tag
, m_data
) ;
1290 if ( m_data
[0].uValue
== kTXNReadOnly
)
1292 TXNControlData data
[] = { { kTXNReadWrite
} } ;
1293 TXNSetTXNObjectControls( m_txn
, false , 1 , tag
, data
) ;
1298 TXNControlTag tag
[] = { kTXNIOPrivilegesTag
} ;
1299 if ( m_data
[0].uValue
== kTXNReadOnly
)
1301 TXNSetTXNObjectControls( m_txn
, false , 1 , tag
, m_data
) ;
1306 TXNControlData m_data
[1] ;
1309 wxString
wxMacMLTEControl::GetStringValue() const
1313 Size actualSize
= 0;
1317 err
= TXNGetDataEncoded( m_txn
, kTXNStartOffset
, kTXNEndOffset
, &theText
, kTXNUnicodeTextData
);
1325 actualSize
= GetHandleSize( theText
) / sizeof( UniChar
) ;
1326 if ( actualSize
> 0 )
1328 wxChar
*ptr
= NULL
;
1329 #if SIZEOF_WCHAR_T == 2
1330 ptr
= new wxChar
[actualSize
+ 1 ] ;
1331 wxStrncpy( ptr
, (wxChar
*) *theText
, actualSize
) ;
1334 SetHandleSize( theText
, ( actualSize
+ 1 ) * sizeof( UniChar
) ) ;
1336 (((UniChar
*)*theText
)[actualSize
]) = 0 ;
1337 wxMBConvUTF16BE converter
;
1338 size_t noChars
= converter
.MB2WC( NULL
, (const char*)*theText
, 0 ) ;
1339 ptr
= new wxChar
[noChars
+ 1] ;
1341 noChars
= converter
.MB2WC( ptr
, (const char*)*theText
, noChars
) ;
1343 HUnlock( theText
) ;
1345 ptr
[actualSize
] = 0 ;
1346 result
= wxString( ptr
) ;
1349 DisposeHandle( theText
) ;
1353 err
= TXNGetDataEncoded( m_txn
, kTXNStartOffset
, kTXNEndOffset
, &theText
, kTXNTextData
);
1361 actualSize
= GetHandleSize( theText
) ;
1362 if ( actualSize
> 0 )
1365 result
= wxString( *theText
, wxConvLocal
, actualSize
) ;
1366 HUnlock( theText
) ;
1368 DisposeHandle( theText
) ;
1372 wxMacConvertNewlines10To13( &result
) ;
1376 void wxMacMLTEControl::SetStringValue( const wxString
&str
)
1379 wxMacConvertNewlines13To10( &st
) ;
1380 EditHelper
help(m_txn
) ;
1382 // wxMacWindowClipper c( this ) ;
1383 #if !TARGET_API_MAC_OSX
1384 // otherwise scrolling might have problems ?
1385 TPUpdateVisibility( m_controlRef
) ;
1387 SetTXNData( st
, kTXNStartOffset
, kTXNEndOffset
) ;
1388 TXNSetSelection( m_txn
, 0, 0);
1389 TXNShowSelection( m_txn
, kTXNShowStart
);
1392 TXNFrameOptions
wxMacMLTEControl::FrameOptionsFromWXStyle( long wxStyle
)
1394 TXNFrameOptions frameOptions
=
1395 kTXNDontDrawCaretWhenInactiveMask
;
1396 if ( ! ( wxStyle
& wxTE_NOHIDESEL
) )
1397 frameOptions
|= kTXNDontDrawSelectionWhenInactiveMask
;
1399 if ( wxStyle
& wxTE_MULTILINE
)
1401 if ( ! ( wxStyle
& wxTE_DONTWRAP
) )
1402 frameOptions
|= kTXNAlwaysWrapAtViewEdgeMask
;
1405 frameOptions
|= kTXNAlwaysWrapAtViewEdgeMask
;
1406 frameOptions
|= kTXNWantHScrollBarMask
;
1409 if ( !(wxStyle
& wxTE_NO_VSCROLL
) )
1410 frameOptions
|= kTXNWantVScrollBarMask
;
1413 frameOptions
|= kTXNSingleLineOnlyMask
;
1415 if ( wxStyle
& wxHSCROLL
)
1416 frameOptions
|= kTXNWantHScrollBarMask
;
1418 return frameOptions
;
1421 void wxMacMLTEControl::AdjustCreationAttributes( const wxColour
&background
, bool visible
)
1423 TXNControlTag iControlTags
[3] = { kTXNDoFontSubstitution
, kTXNWordWrapStateTag
};
1424 TXNControlData iControlData
[3] = { {false}, {kTXNNoAutoWrap
} };
1426 #if TARGET_API_MAC_OSX
1427 iControlTags
[2] = kTXNVisibilityTag
;
1428 iControlData
[2].uValue
= visible
;
1432 if ( m_windowStyle
& wxTE_MULTILINE
)
1434 if (m_windowStyle
& wxTE_DONTWRAP
)
1435 iControlData
[1].uValue
= kTXNNoAutoWrap
;
1437 iControlData
[1].uValue
= kTXNAutoWrap
;
1440 verify_noerr( TXNSetTXNObjectControls( m_txn
, false, toptag
,
1441 iControlTags
, iControlData
)) ;
1443 // setting the default font
1449 GetThemeFont(kThemeSystemFont
, GetApplicationScript() , fontName
, &fontSize
, &fontStyle
) ;
1451 TXNTypeAttributes typeAttr
[] =
1453 { kTXNQDFontNameAttribute
, kTXNQDFontNameAttributeSize
, { (void*) fontName
} } ,
1454 { kTXNQDFontSizeAttribute
, kTXNFontSizeAttributeSize
, { (void*) (fontSize
<< 16) } } ,
1455 { kTXNQDFontStyleAttribute
, kTXNQDFontStyleAttributeSize
, { (void*) normal
} } ,
1458 verify_noerr( TXNSetTypeAttributes (m_txn
, sizeof( typeAttr
) / sizeof(TXNTypeAttributes
) , typeAttr
,
1462 if ( m_windowStyle
& wxTE_PASSWORD
)
1465 verify_noerr(TXNEchoMode( m_txn
, c
, 0 , true )) ;
1468 TXNBackground tback
;
1469 tback
.bgType
= kTXNBackgroundTypeRGB
;
1470 tback
.bg
.color
= MAC_WXCOLORREF( background
.GetPixel() );
1471 TXNSetBackground( m_txn
, &tback
);
1474 void wxMacMLTEControl::SetBackground( const wxBrush
&brush
)
1476 // currently only solid background are supported
1477 TXNBackground tback
;
1478 tback
.bgType
= kTXNBackgroundTypeRGB
;
1479 tback
.bg
.color
= MAC_WXCOLORREF( brush
.GetColour().GetPixel() );
1480 TXNSetBackground( m_txn
, &tback
);
1483 int wxMacMLTEControl::ConvertAttribute( const wxTextAttr
& style
, TXNTypeAttributes typeAttr
[] )
1485 Str255 fontName
= "\pMonaco" ;
1486 SInt16 fontSize
= 12 ;
1487 Style fontStyle
= normal
;
1489 int attrCounter
= 0 ;
1490 if ( style
.HasFont() )
1492 const wxFont
&font
= style
.GetFont() ;
1493 wxMacStringToPascal( font
.GetFaceName() , fontName
) ;
1494 fontSize
= font
.GetPointSize() ;
1495 if ( font
.GetUnderlined() )
1496 fontStyle
|= underline
;
1497 if ( font
.GetWeight() == wxBOLD
)
1499 if ( font
.GetStyle() == wxITALIC
)
1500 fontStyle
|= italic
;
1502 typeAttr
[attrCounter
].tag
= kTXNQDFontNameAttribute
;
1503 typeAttr
[attrCounter
].size
= kTXNQDFontNameAttributeSize
;
1504 typeAttr
[attrCounter
].data
.dataPtr
= (void*) fontName
;
1505 typeAttr
[attrCounter
+1].tag
= kTXNQDFontSizeAttribute
;
1506 typeAttr
[attrCounter
+1].size
= kTXNFontSizeAttributeSize
;
1507 typeAttr
[attrCounter
+1].data
.dataValue
= (fontSize
<< 16) ;
1508 typeAttr
[attrCounter
+2].tag
= kTXNQDFontStyleAttribute
;
1509 typeAttr
[attrCounter
+2].size
= kTXNQDFontStyleAttributeSize
;
1510 typeAttr
[attrCounter
+2].data
.dataValue
= fontStyle
;
1513 if ( style
.HasTextColour() )
1515 typeAttr
[attrCounter
].tag
= kTXNQDFontColorAttribute
;
1516 typeAttr
[attrCounter
].size
= kTXNQDFontColorAttributeSize
;
1517 typeAttr
[attrCounter
].data
.dataPtr
= (void*) &color
;
1518 color
= MAC_WXCOLORREF(style
.GetTextColour().GetPixel()) ;
1521 return attrCounter
;
1524 void wxMacMLTEControl::SetFont( const wxFont
& font
, const wxColour
& foreground
, long windowStyle
)
1526 EditHelper
help(m_txn
) ;
1527 wxTextAttr
style(foreground
,wxNullColour
,font
) ;
1528 TXNTypeAttributes typeAttr
[4] ;
1529 int attrCounter
= ConvertAttribute( style
, typeAttr
) ;
1530 if ( attrCounter
> 0 )
1532 verify_noerr( TXNSetTypeAttributes ( m_txn
, attrCounter
, typeAttr
, kTXNStartOffset
,kTXNEndOffset
) );
1535 void wxMacMLTEControl::SetStyle(long start
, long end
, const wxTextAttr
& style
)
1537 EditHelper
help(m_txn
) ;
1538 TXNTypeAttributes typeAttr
[4] ;
1539 int attrCounter
= ConvertAttribute( style
, typeAttr
) ;
1540 if ( attrCounter
> 0 )
1542 verify_noerr( TXNSetTypeAttributes ( m_txn
, attrCounter
, typeAttr
, start
,end
) );
1546 void wxMacMLTEControl::Copy()
1548 ClearCurrentScrap();
1550 TXNConvertToPublicScrap();
1553 void wxMacMLTEControl::Cut()
1555 ClearCurrentScrap();
1557 TXNConvertToPublicScrap();
1560 void wxMacMLTEControl::Paste()
1562 TXNConvertFromPublicScrap();
1566 bool wxMacMLTEControl::CanPaste() const
1568 return TXNIsScrapPastable() ;
1571 void wxMacMLTEControl::SetEditable(bool editable
)
1573 TXNControlTag tag
[] = { kTXNIOPrivilegesTag
} ;
1574 TXNControlData data
[] = { { editable
? kTXNReadWrite
: kTXNReadOnly
} } ;
1575 TXNSetTXNObjectControls( m_txn
, false , sizeof(tag
) / sizeof (TXNControlTag
) , tag
, data
) ;
1578 long wxMacMLTEControl::GetLastPosition() const
1580 long actualsize
= 0 ;
1583 OSErr err
= TXNGetDataEncoded( m_txn
, kTXNStartOffset
, kTXNEndOffset
, &theText
, kTXNTextData
);
1591 actualsize
= GetHandleSize( theText
) ;
1592 DisposeHandle( theText
) ;
1598 void wxMacMLTEControl::Replace( long from
, long to
, const wxString str
)
1600 wxString value
= str
;
1601 wxMacConvertNewlines13To10( &value
) ;
1603 EditHelper
help( m_txn
) ;
1605 TXNSetSelection(m_txn
, from
, to
) ;
1607 SetTXNData( str
, kTXNUseCurrentSelection
, kTXNUseCurrentSelection
) ;
1610 void wxMacMLTEControl::Remove( long from
, long to
)
1612 EditHelper
help( m_txn
) ;
1614 TXNSetSelection(m_txn
, from
, to
) ;
1618 void wxMacMLTEControl::GetSelection( long* from
, long* to
) const
1620 TXNGetSelection( m_txn
, (TXNOffset
*) from
, (TXNOffset
*) to
) ;
1623 void wxMacMLTEControl::SetSelection( long from
, long to
)
1625 /* change the selection */
1626 if ((from
== -1) && (to
== -1))
1627 TXNSelectAll(m_txn
);
1629 TXNSetSelection( m_txn
, from
, to
);
1630 TXNShowSelection( m_txn
, kTXNShowStart
);
1633 void wxMacMLTEControl::WriteText(const wxString
& str
)
1635 EditHelper
helper( m_txn
) ;
1637 wxMacConvertNewlines13To10( &st
) ;
1639 long start
, end
, dummy
;
1640 GetSelection( &start
, &dummy
) ;
1641 SetTXNData( st
, kTXNUseCurrentSelection
, kTXNUseCurrentSelection
) ;
1642 GetSelection( &dummy
, &end
) ;
1643 // TODO SetStyle( start , end , GetDefaultStyle() ) ;
1646 void wxMacMLTEControl::Clear()
1648 EditHelper
st(m_txn
) ;
1649 TXNSetSelection( m_txn
, kTXNStartOffset
, kTXNEndOffset
) ;
1653 bool wxMacMLTEControl::CanUndo() const
1655 return TXNCanUndo( m_txn
, NULL
) ;
1658 void wxMacMLTEControl::Undo()
1663 bool wxMacMLTEControl::CanRedo() const
1665 return TXNCanRedo( m_txn
, NULL
) ;
1668 void wxMacMLTEControl::Redo()
1673 int wxMacMLTEControl::GetNumberOfLines() const
1675 ItemCount lines
= 0 ;
1676 TXNGetLineCount(m_txn
, &lines
) ;
1680 long wxMacMLTEControl::XYToPosition(long x
, long y
) const
1684 long lastpos
= GetLastPosition() ;
1686 // TODO find a better implementation : while we can get the
1687 // line metrics of a certain line, we don't get its starting
1688 // position, so it would probably be rather a binary search
1689 // for the start position
1692 int lastHeight
= 0 ;
1695 for ( n
= 0 ; n
<= (ItemCount
) lastpos
; ++n
)
1697 if ( y
== ypos
&& x
== xpos
)
1700 TXNOffsetToPoint( m_txn
, n
, &curpt
);
1702 if ( curpt
.v
> lastHeight
)
1707 lastHeight
= curpt
.v
;
1715 bool wxMacMLTEControl::PositionToXY(long pos
, long *x
, long *y
) const
1719 long lastpos
= GetLastPosition() ;
1724 if ( pos
<= lastpos
)
1726 // TODO find a better implementation : while we can get the
1727 // line metrics of a certain line, we don't get its starting
1728 // position, so it would probably be rather a binary search
1729 // for the start position
1732 int lastHeight
= 0 ;
1735 for ( n
= 0 ; n
<= (ItemCount
) pos
; ++n
)
1737 TXNOffsetToPoint(m_txn
, n
, &curpt
);
1739 if ( curpt
.v
> lastHeight
)
1744 lastHeight
= curpt
.v
;
1749 if ( y
) *y
= ypos
;
1750 if ( x
) *x
= xpos
;
1756 void wxMacMLTEControl::ShowPosition( long pos
)
1758 #if TARGET_RT_MAC_MACHO && defined(AVAILABLE_MAC_OS_X_VERSION_10_2_AND_LATER)
1762 TXNOffset selstart
, selend
;
1763 TXNGetSelection( m_txn
, &selstart
, &selend
) ;
1764 TXNOffsetToPoint( m_txn
, selstart
, ¤t
);
1765 TXNOffsetToPoint( m_txn
, pos
, &desired
);
1766 //TODO use HIPoints for 10.3 and above
1767 if ( (UInt32
) TXNScroll
!= (UInt32
) kUnresolvedCFragSymbolAddress
)
1769 OSErr theErr
= noErr
;
1770 SInt32 dv
= desired
.v
- current
.v
;
1771 SInt32 dh
= desired
.h
- current
.h
;
1772 TXNShowSelection( m_txn
, true ) ;
1773 theErr
= TXNScroll( m_txn
, kTXNScrollUnitsInPixels
, kTXNScrollUnitsInPixels
, &dv
, &dh
);
1774 wxASSERT_MSG( theErr
== noErr
, _T("TXNScroll returned an error!") );
1780 void wxMacMLTEControl::SetTXNData( const wxString
& st
, TXNOffset start
, TXNOffset end
)
1783 #if SIZEOF_WCHAR_T == 2
1784 size_t len
= st
.Len() ;
1785 TXNSetData( m_txn
, kTXNUnicodeTextData
, (void*)st
.wc_str(), len
* 2,
1788 wxMBConvUTF16BE converter
;
1789 ByteCount byteBufferLen
= converter
.WC2MB( NULL
, st
.wc_str() , 0 ) ;
1790 UniChar
*unibuf
= (UniChar
*) malloc(byteBufferLen
) ;
1791 converter
.WC2MB( (char*) unibuf
, st
.wc_str() , byteBufferLen
) ;
1792 TXNSetData( m_txn
, kTXNUnicodeTextData
, (void*)unibuf
, byteBufferLen
,
1797 wxCharBuffer text
= st
.mb_str(wxConvLocal
) ;
1798 TXNSetData( m_txn
, kTXNTextData
, (void*)text
.data(), strlen( text
) ,
1804 wxString
wxMacMLTEControl::GetLineText(long lineNo
) const
1808 wxString content
= GetStringValue() ;
1810 if ( lineNo
< GetNumberOfLines() )
1812 // TODO find a better implementation : while we can get the
1813 // line metrics of a certain line, we don't get its starting
1814 // position, so it would probably be rather a binary search
1815 // for the start position
1818 int lastHeight
= 0 ;
1819 long lastpos
= GetLastPosition() ;
1822 for ( n
= 0 ; n
<= (ItemCount
)lastpos
; ++n
)
1824 TXNOffsetToPoint( m_txn
, n
, &curpt
);
1826 if ( curpt
.v
> lastHeight
)
1828 if ( ypos
== lineNo
)
1834 lastHeight
= curpt
.v
;
1838 if ( ypos
== lineNo
)
1839 line
+= content
[n
] ;
1847 int wxMacMLTEControl::GetLineLength(long lineNo
) const
1850 if ( lineNo
< GetNumberOfLines() )
1852 // TODO find a better implementation : while we can get the
1853 // line metrics of a certain line, we don't get its starting
1854 // position, so it would probably be rather a binary search
1855 // for the start position
1858 int lastHeight
= 0 ;
1859 long lastpos
= GetLastPosition() ;
1862 for ( n
= 0 ; n
<= (ItemCount
) lastpos
; ++n
)
1864 TXNOffsetToPoint( m_txn
, n
, &curpt
);
1866 if ( curpt
.v
> lastHeight
)
1868 if ( ypos
== lineNo
)
1874 lastHeight
= curpt
.v
;
1884 // ----------------------------------------------------------------------------
1885 // MLTE control implementation (classic part)
1886 // ----------------------------------------------------------------------------
1888 // CS:TODO we still have a problem getting properly at the text events of a control because under Carbon
1889 // the MLTE engine registers itself for the key events thus the normal flow never occurs, the only measure for the
1890 // moment is to avoid setting the true focus on the control, the proper solution at the end would be to have
1891 // an alternate path for carbon key events that routes automatically into the same wx flow of events
1895 /* kmUPTextPart is the part code we return to indicate the user has clicked
1896 in the text area of our control */
1897 #define kmUPTextPart 1
1900 /* routines for using existing user pane controls.
1901 These routines are useful for cases where you would like to use an
1902 existing user pane control in, say, a dialog window as a scrolling
1905 /* Utility Routines */
1907 /* kUserClickedToFocusPart is a part code we pass to the SetKeyboardFocus
1908 routine. In our focus switching routine this part code is understood
1909 as meaning 'the user has clicked in the control and we need to switch
1910 the current focus to ourselves before we can continue'. */
1911 #define kUserClickedToFocusPart 100
1913 /* STPTextPaneVars is a structure used for storing the the mUP Control's
1914 internal variables and state information. A handle to this record is
1915 stored in the pane control's reference value field using the
1916 SetControlReference routine. */
1918 class STPTextPaneVars
{
1920 /* OS records referenced */
1921 TXNObject fTXNRec
; /* the txn record */
1922 TXNFrameID fTXNFrame
; /* the txn frame ID */
1923 ControlRef fUserPaneRec
; /* handle to the user pane control */
1924 WindowPtr fOwner
; /* window containing control */
1925 GrafPtr fDrawingEnvironment
; /* grafport where control is drawn */
1927 Boolean fInFocus
; /* true while the focus rect is drawn around the control */
1928 Boolean fIsActive
; /* true while the control is drawn in the active state */
1929 Boolean fTXNObjectActive
; /* reflects the activation state of the text edit record */
1930 Boolean fFocusDrawState
; /* true if focus is drawn (default: true) */
1931 /* calculated locations */
1932 Rect fRBounds
; /* control bounds */
1933 Rect fRTextArea
; /* area where the text is drawn */
1934 Rect fRFocusOutline
; /* rectangle used to draw the focus box */
1935 Rect fRTextOutline
; /* rectangle used to draw the border */
1936 RgnHandle fRTextOutlineRegion
; /* background region for the text, erased before calling TEUpdate */
1937 /* our focus advance override routine */
1938 EventHandlerUPP handlerUPP
;
1939 EventHandlerRef handlerRef
;
1945 /* Univerals Procedure Pointer variables used by the
1946 mUP Control. These variables are set up
1947 the first time that mUPOpenControl is called. */
1948 ControlUserPaneDrawUPP gTPDrawProc
= NULL
;
1949 ControlUserPaneHitTestUPP gTPHitProc
= NULL
;
1950 ControlUserPaneTrackingUPP gTPTrackProc
= NULL
;
1951 ControlUserPaneIdleUPP gTPIdleProc
= NULL
;
1952 ControlUserPaneKeyDownUPP gTPKeyProc
= NULL
;
1953 ControlUserPaneActivateUPP gTPActivateProc
= NULL
;
1954 ControlUserPaneFocusUPP gTPFocusProc
= NULL
;
1956 // one place for calculating all
1957 static void TPCalculateBounds(STPTextPaneVars
*varsp
, const Rect
& bounds
)
1959 SetRect(&varsp
->fRBounds
, bounds
.left
, bounds
.top
, bounds
.right
, bounds
.bottom
);
1960 SetRect(&varsp
->fRFocusOutline
, bounds
.left
, bounds
.top
, bounds
.right
, bounds
.bottom
);
1961 // eventually make TextOutline inset 1,1
1962 SetRect(&varsp
->fRTextOutline
, bounds
.left
, bounds
.top
, bounds
.right
, bounds
.bottom
);
1963 if ( !varsp
->fNoBorders
)
1965 SetRect(&varsp
->fRTextArea
, bounds
.left
+ 2 , bounds
.top
+ (varsp
->fMultiline
? 0 : 2) ,
1966 bounds
.right
- (varsp
->fMultiline
? 0 : 2), bounds
.bottom
- (varsp
->fMultiline
? 0 : 2));
1970 SetRect(&varsp
->fRTextArea
, bounds
.left
, bounds
.top
,
1971 bounds
.right
, bounds
.bottom
);
1975 OSStatus
MLTESetObjectVisibility( STPTextPaneVars
*varsp
, Boolean vis
, long wxStyle
)
1977 OSStatus err
= noErr
;
1978 #if TARGET_API_MAC_OSX
1979 TXNControlTag iControlTags
[1] = { kTXNVisibilityTag
};
1980 TXNControlData iControlData
[1] = {{ vis
}};
1981 err
= ::TXNSetTXNObjectControls( varsp
->fTXNRec
, false, 1, iControlTags
, iControlData
);
1983 wxTextCtrl
* textctrl
= (wxTextCtrl
*) GetControlReference(varsp
->fUserPaneRec
);
1984 if ( vis
&& textctrl
)
1987 UMAGetControlBoundsInWindowCoords( varsp
->fUserPaneRec
, &bounds
);
1988 TPCalculateBounds( varsp
, bounds
) ;
1989 wxMacWindowClipper
cl(textctrl
) ;
1990 TXNSetFrameBounds( varsp
->fTXNRec
, varsp
->fRTextArea
.top
, varsp
->fRTextArea
.left
,
1991 varsp
->fRTextArea
.bottom
, varsp
->fRTextArea
.right
, varsp
->fTXNFrame
);
1992 TXNShowSelection( varsp
->fTXNRec
, kTXNShowStart
);
1997 // make sure we don't miss changes as carbon events are not available for these under classic
1998 static void TPUpdateVisibility(ControlRef theControl
) {
1999 wxTextCtrl
* textctrl
= (wxTextCtrl
*) GetControlReference(theControl
);
2000 if ( textctrl
== NULL
)
2003 STPTextPaneVars
*varsp
= (STPTextPaneVars
*) ((wxMacMLTEClassicControl
*)textctrl
->GetPeer())->m_macTXNvars
;
2006 UMAGetControlBoundsInWindowCoords(theControl
, &bounds
);
2007 if ( textctrl
->MacIsReallyShown() != varsp
->fVisible
)
2009 // invalidate old position
2010 // InvalWindowRect( GetControlOwner( theControl ) , &varsp->fRBounds ) ;
2011 varsp
->fVisible
= textctrl
->MacIsReallyShown() ;
2013 if ( !EqualRect( &bounds
, &varsp
->fRBounds
) )
2016 Rect oldBounds
= varsp
->fRBounds
;
2017 TPCalculateBounds( varsp
, bounds
) ;
2018 // we only recalculate when visible, otherwise scrollbars get drawn at incorrect places
2019 if ( varsp
->fVisible
)
2021 wxMacWindowClipper
cl(textctrl
) ;
2022 TXNSetFrameBounds( varsp
->fTXNRec
, varsp
->fRTextArea
.top
, varsp
->fRTextArea
.left
,
2023 varsp
->fRTextArea
.bottom
, varsp
->fRTextArea
.right
, varsp
->fTXNFrame
);
2025 InvalWindowRect( GetControlOwner( theControl
) , &oldBounds
) ;
2026 InvalWindowRect( GetControlOwner( theControl
) , &varsp
->fRBounds
) ;
2030 // make correct activations
2031 static void TPActivatePaneText(STPTextPaneVars
*varsp
, Boolean setActive
) {
2033 wxTextCtrl
* textctrl
= (wxTextCtrl
*) GetControlReference(varsp
->fUserPaneRec
);
2034 if (varsp
->fTXNObjectActive
!= setActive
&& textctrl
->MacIsReallyShown() )
2036 varsp
->fTXNObjectActive
= setActive
;
2037 TXNActivate(varsp
->fTXNRec
, varsp
->fTXNFrame
, varsp
->fTXNObjectActive
);
2038 if (varsp
->fInFocus
)
2039 TXNFocus( varsp
->fTXNRec
, varsp
->fTXNObjectActive
);
2043 // update focus outlines
2044 static void TPRedrawFocusOutline(STPTextPaneVars
*varsp
) {
2047 if (varsp
->fFocusDrawState
!= (varsp
->fIsActive
&& varsp
->fInFocus
))
2049 varsp
->fFocusDrawState
= (varsp
->fIsActive
&& varsp
->fInFocus
);
2050 DrawThemeFocusRect(&varsp
->fRFocusOutline
, varsp
->fFocusDrawState
);
2054 // update TXN focus state
2055 static void TPFocusPaneText(STPTextPaneVars
*varsp
, Boolean setFocus
) {
2056 wxTextCtrl
* textctrl
= (wxTextCtrl
*) GetControlReference(varsp
->fUserPaneRec
);
2058 if (varsp
->fInFocus
!= setFocus
&& textctrl
->MacIsReallyShown()) {
2059 varsp
->fInFocus
= setFocus
;
2060 TXNFocus( varsp
->fTXNRec
, varsp
->fInFocus
);
2065 static pascal void TPPaneDrawProc(ControlRef theControl
, ControlPartCode thePart
) {
2066 /* set up our globals */
2068 wxTextCtrl
* textctrl
= (wxTextCtrl
*) GetControlReference(theControl
);
2069 if ( textctrl
== NULL
)
2071 TPUpdateVisibility( theControl
) ;
2073 STPTextPaneVars
*varsp
= (STPTextPaneVars
*) ((wxMacMLTEClassicControl
*)textctrl
->GetPeer())->m_macTXNvars
;
2074 if ( textctrl
->MacIsReallyShown() )
2076 wxMacWindowClipper
clipper( textctrl
) ;
2077 TXNDraw(varsp
->fTXNRec
, NULL
);
2078 if ( !varsp
->fNoBorders
)
2079 DrawThemeEditTextFrame(&varsp
->fRTextOutline
, varsp
->fIsActive
? kThemeStateActive
: kThemeStateInactive
);
2080 TPRedrawFocusOutline( varsp
) ;
2086 /* TPPaneHitTestProc is called when the control manager would
2087 like to determine what part of the control the mouse resides over.
2088 We also call this routine from our tracking proc to determine how
2089 to handle mouse clicks. */
2090 static pascal ControlPartCode
TPPaneHitTestProc(ControlRef theControl
, Point where
) {
2091 ControlPartCode result
;
2092 /* set up our locals and lock down our globals*/
2094 wxTextCtrl
* textctrl
= (wxTextCtrl
*) GetControlReference(theControl
);
2095 if ( textctrl
== NULL
)
2097 TPUpdateVisibility( theControl
) ;
2098 STPTextPaneVars
*varsp
= (STPTextPaneVars
*) ((wxMacMLTEClassicControl
*)textctrl
->GetPeer())->m_macTXNvars
;
2099 if (textctrl
->MacIsReallyShown() )
2101 if (PtInRect(where
, &varsp
->fRBounds
))
2102 result
= kmUPTextPart
;
2105 // sometimes we get the coords also in control local coordinates, therefore test again
2106 if ( textctrl
->MacGetTopLevelWindow()->MacUsesCompositing() )
2109 textctrl
->MacClientToRootWindow( &x
, &y
) ;
2113 if (PtInRect(where
, &varsp
->fRBounds
))
2114 result
= kmUPTextPart
;
2126 /* TPPaneTrackingProc is called when the mouse is being held down
2127 over our control. This routine handles clicks in the text area
2128 and in the scroll bar. */
2129 static pascal ControlPartCode
TPPaneTrackingProc(ControlRef theControl
, Point startPt
, ControlActionUPP actionProc
) {
2131 ControlPartCode partCodeResult
;
2132 /* make sure we have some variables... */
2134 wxTextCtrl
* textctrl
= (wxTextCtrl
*) GetControlReference(theControl
);
2135 if ( textctrl
== NULL
)
2137 TPUpdateVisibility( theControl
) ;
2138 STPTextPaneVars
*varsp
= (STPTextPaneVars
*) ((wxMacMLTEClassicControl
*)textctrl
->GetPeer())->m_macTXNvars
;
2139 if (textctrl
->MacIsReallyShown() )
2141 /* we don't do any of these functions unless we're in focus */
2142 if ( ! varsp
->fInFocus
) {
2144 owner
= GetControlOwner(theControl
);
2145 ClearKeyboardFocus(owner
);
2146 SetKeyboardFocus(owner
, theControl
, kUserClickedToFocusPart
);
2148 /* find the location for the click */
2149 // for compositing, we must convert these into toplevel window coordinates, because hittesting expects them
2150 if ( textctrl
->MacGetTopLevelWindow()->MacUsesCompositing() )
2153 textctrl
->MacClientToRootWindow( &x
, &y
) ;
2158 switch (TPPaneHitTestProc(theControl
, startPt
))
2161 /* handle clicks in the text part */
2164 wxMacWindowClipper
clipper( textctrl
) ;
2167 ConvertEventRefToEventRecord( (EventRef
) wxTheApp
->MacGetCurrentEvent() , &rec
) ;
2168 TXNClick( varsp
->fTXNRec
, &rec
);
2175 return partCodeResult
;
2179 /* TPPaneIdleProc is our user pane idle routine. When our text field
2180 is active and in focus, we use this routine to set the cursor. */
2181 static pascal void TPPaneIdleProc(ControlRef theControl
) {
2183 wxTextCtrl
* textctrl
= (wxTextCtrl
*) GetControlReference(theControl
);
2184 if ( textctrl
== NULL
)
2186 TPUpdateVisibility( theControl
) ;
2187 STPTextPaneVars
*varsp
= (STPTextPaneVars
*) ((wxMacMLTEClassicControl
*)textctrl
->GetPeer())->m_macTXNvars
;
2188 if (textctrl
->MacIsReallyShown()) {
2189 /* if we're not active, then we have nothing to say about the cursor */
2190 if (varsp
->fIsActive
) {
2194 wxMacWindowClipper
clipper( textctrl
) ;
2196 /* there's a 'focus thing' and an 'unfocused thing' */
2197 if (varsp
->fInFocus
) {
2198 /* flash the cursor */
2199 SetPort(varsp
->fDrawingEnvironment
);
2200 TXNIdle(varsp
->fTXNRec
);
2201 /* set the cursor */
2202 if (PtInRect(mousep
, &varsp
->fRTextArea
)) {
2204 RectRgn((theRgn
= NewRgn()), &varsp
->fRTextArea
);
2205 TXNAdjustCursor(varsp
->fTXNRec
, theRgn
);
2210 // SetThemeCursor(kThemeArrowCursor);
2213 /* if it's in our bounds, set the cursor */
2214 UMAGetControlBoundsInWindowCoords(theControl
, &bounds
);
2215 if (PtInRect(mousep
, &bounds
))
2217 // SetThemeCursor(kThemeArrowCursor);
2225 /* TPPaneKeyDownProc is called whenever a keydown event is directed
2226 at our control. Here, we direct the keydown event to the text
2227 edit record and redraw the scroll bar and text field as appropriate. */
2228 static pascal ControlPartCode
TPPaneKeyDownProc(ControlRef theControl
,
2229 SInt16 keyCode
, SInt16 charCode
, SInt16 modifiers
) {
2231 wxTextCtrl
* textctrl
= (wxTextCtrl
*) GetControlReference(theControl
);
2232 if ( textctrl
== NULL
)
2234 TPUpdateVisibility( theControl
) ;
2236 STPTextPaneVars
*varsp
= (STPTextPaneVars
*) ((wxMacMLTEClassicControl
*)textctrl
->GetPeer())->m_macTXNvars
;
2237 if (varsp
->fInFocus
)
2239 /* turn autoscrolling on and send the key event to text edit */
2240 wxMacWindowClipper
clipper( textctrl
) ;
2242 memset( &ev
, 0 , sizeof( ev
) ) ;
2244 ev
.modifiers
= modifiers
;
2245 ev
.message
= (( keyCode
<< 8 ) & keyCodeMask
) + ( charCode
& charCodeMask
) ;
2246 TXNKeyDown( varsp
->fTXNRec
, &ev
);
2248 return kControlEntireControl
;
2252 /* TPPaneActivateProc is called when the window containing
2253 the user pane control receives activate events. Here, we redraw
2254 the control and it's text as necessary for the activation state. */
2255 static pascal void TPPaneActivateProc(ControlRef theControl
, Boolean activating
) {
2257 wxTextCtrl
* textctrl
= (wxTextCtrl
*) GetControlReference(theControl
);
2259 if ( textctrl
== NULL
)
2261 TPUpdateVisibility( theControl
) ;
2263 STPTextPaneVars
*varsp
= (STPTextPaneVars
*) ((wxMacMLTEClassicControl
*)textctrl
->GetPeer())->m_macTXNvars
;
2265 varsp
->fIsActive
= activating
;
2266 wxMacWindowClipper
clipper( textctrl
) ;
2267 TPActivatePaneText(varsp
, varsp
->fIsActive
&& varsp
->fInFocus
);
2268 /* redraw the frame */
2269 if ( textctrl
->MacIsReallyShown() )
2271 if ( !varsp
->fNoBorders
)
2272 DrawThemeEditTextFrame(&varsp
->fRTextOutline
, varsp
->fIsActive
? kThemeStateActive
: kThemeStateInactive
);
2273 TPRedrawFocusOutline( varsp
) ;
2278 /* TPPaneFocusProc is called when every the focus changes to or
2279 from our control. Herein, switch the focus appropriately
2280 according to the parameters and redraw the control as
2282 static pascal ControlPartCode
TPPaneFocusProc(ControlRef theControl
, ControlFocusPart action
) {
2283 ControlPartCode focusResult
;
2285 focusResult
= kControlFocusNoPart
;
2286 wxTextCtrl
* textctrl
= (wxTextCtrl
*) GetControlReference(theControl
);
2287 if ( textctrl
== NULL
)
2289 TPUpdateVisibility( theControl
) ;
2290 STPTextPaneVars
*varsp
= (STPTextPaneVars
*) ((wxMacMLTEClassicControl
*)textctrl
->GetPeer())->m_macTXNvars
;
2291 /* if kControlFocusPrevPart and kControlFocusNextPart are received when the user is
2292 tabbing forwards (or shift tabbing backwards) through the items in the dialog,
2293 and kControlFocusNextPart will be received. When the user clicks in our field
2294 and it is not the current focus, then the constant kUserClickedToFocusPart will
2295 be received. The constant kControlFocusNoPart will be received when our control
2296 is the current focus and the user clicks in another control. In your focus routine,
2297 you should respond to these codes as follows:
2299 kControlFocusNoPart - turn off focus and return kControlFocusNoPart. redraw
2300 the control and the focus rectangle as necessary.
2302 kControlFocusPrevPart or kControlFocusNextPart - toggle focus on or off
2303 depending on its current state. redraw the control and the focus rectangle
2304 as appropriate for the new focus state. If the focus state is 'off', return the constant
2305 kControlFocusNoPart, otherwise return a non-zero part code.
2306 kUserClickedToFocusPart - is a constant defined for this example. You should
2307 define your own value for handling click-to-focus type events. */
2308 /* calculate the next highlight state */
2311 case kControlFocusNoPart
:
2312 TPFocusPaneText(varsp
, false);
2313 focusResult
= kControlFocusNoPart
;
2315 case kUserClickedToFocusPart
:
2316 TPFocusPaneText(varsp
, true);
2319 case kControlFocusPrevPart
:
2320 case kControlFocusNextPart
:
2321 TPFocusPaneText(varsp
, ( ! varsp
->fInFocus
));
2322 focusResult
= varsp
->fInFocus
? 1 : kControlFocusNoPart
;
2325 TPActivatePaneText(varsp
, varsp
->fIsActive
&& varsp
->fInFocus
);
2326 /* redraw the text fram and focus rectangle to indicate the
2328 if ( textctrl
->MacIsReallyShown() )
2330 wxMacWindowClipper
c( textctrl
) ;
2331 if ( !varsp
->fNoBorders
)
2332 DrawThemeEditTextFrame(&varsp
->fRTextOutline
, varsp
->fIsActive
? kThemeStateActive
: kThemeStateInactive
);
2333 TPRedrawFocusOutline( varsp
) ;
2338 wxMacMLTEClassicControl::wxMacMLTEClassicControl( wxWindow
*wxPeer
,
2339 const wxString
& str
,
2341 const wxSize
& size
, long style
)
2343 m_font
= wxPeer
->GetFont() ;
2344 m_windowStyle
= style
;
2345 Rect bounds
= wxMacGetBoundsForControl( wxPeer
, pos
, size
) ;
2347 wxMacConvertNewlines13To10( &st
) ;
2349 wxMacConvertNewlines13To10( &st
) ;
2353 featurSet
= kControlSupportsEmbedding
| kControlSupportsFocus
| kControlWantsIdle
2354 | kControlWantsActivate
| kControlHandlesTracking
| kControlHasSpecialBackground
2355 | kControlGetsFocusOnClick
| kControlSupportsLiveFeedback
;
2356 /* create the control */
2358 verify_noerr( ::CreateUserPaneControl( MAC_WXHWND(wxPeer
->GetParent()->MacGetTopLevelWindowRef()), &bounds
, featurSet
, &m_controlRef
) );
2361 // wxMacWindowClipper c(wxPeer) ;
2365 if ( wxPeer
->MacIsReallyShown() )
2366 MLTESetObjectVisibility( (STPTextPaneVars
*) m_macTXNvars
, true , style
) ;
2369 // wxMacWindowClipper clipper( wxPeer ) ;
2371 TPUpdateVisibility( m_controlRef
) ;
2373 SetTXNData( st
, kTXNStartOffset
, kTXNEndOffset
) ;
2375 TXNSetSelection( m_txn
, 0, 0);
2376 TXNShowSelection( m_txn
, kTXNShowStart
);
2379 AdjustCreationAttributes( *wxWHITE
, true ) ;
2382 wxMacMLTEClassicControl::~wxMacMLTEClassicControl()
2384 // SetControlReference(m_controlRef , 0) ;
2385 TXNDeleteObject(m_txn
);
2389 void wxMacMLTEClassicControl::VisibilityChanged(bool shown
)
2391 MLTESetObjectVisibility((STPTextPaneVars
*) m_macTXNvars
, shown
, m_windowStyle
) ;
2393 InvalWindowRect( GetControlOwner( m_controlRef
) , &((STPTextPaneVars
*)m_macTXNvars
)->fRBounds
) ;
2396 OSStatus
wxMacMLTEClassicControl::DoCreate()
2399 WindowRef theWindow
;
2401 OSStatus err
= noErr
;
2403 /* set up our globals */
2404 if (gTPDrawProc
== NULL
) gTPDrawProc
= NewControlUserPaneDrawUPP(TPPaneDrawProc
);
2405 if (gTPHitProc
== NULL
) gTPHitProc
= NewControlUserPaneHitTestUPP(TPPaneHitTestProc
);
2406 if (gTPTrackProc
== NULL
) gTPTrackProc
= NewControlUserPaneTrackingUPP(TPPaneTrackingProc
);
2407 if (gTPIdleProc
== NULL
) gTPIdleProc
= NewControlUserPaneIdleUPP(TPPaneIdleProc
);
2408 if (gTPKeyProc
== NULL
) gTPKeyProc
= NewControlUserPaneKeyDownUPP(TPPaneKeyDownProc
);
2409 if (gTPActivateProc
== NULL
) gTPActivateProc
= NewControlUserPaneActivateUPP(TPPaneActivateProc
);
2410 if (gTPFocusProc
== NULL
) gTPFocusProc
= NewControlUserPaneFocusUPP(TPPaneFocusProc
);
2412 /* allocate our private storage */
2413 m_macTXNvars
= (STPTextPaneVars
*) malloc(sizeof(STPTextPaneVars
));
2415 /* set the initial settings for our private data */
2416 m_macTXNvars
->fMultiline
= m_windowStyle
& wxTE_MULTILINE
;
2417 m_macTXNvars
->fNoBorders
= m_windowStyle
& wxNO_BORDER
;
2418 m_macTXNvars
->fInFocus
= false;
2419 m_macTXNvars
->fIsActive
= true;
2420 m_macTXNvars
->fTXNObjectActive
= false;
2421 m_macTXNvars
->fFocusDrawState
= false ;
2422 m_macTXNvars
->fUserPaneRec
= m_controlRef
;
2423 m_macTXNvars
->fVisible
= true ;
2425 theWindow
= m_macTXNvars
->fOwner
= GetControlOwner(m_controlRef
);
2427 m_macTXNvars
->fDrawingEnvironment
= (GrafPtr
) GetWindowPort(theWindow
);
2429 /* set up the user pane procedures */
2430 SetControlData(m_controlRef
, kControlEntireControl
, kControlUserPaneDrawProcTag
, sizeof(gTPDrawProc
), &gTPDrawProc
);
2431 SetControlData(m_controlRef
, kControlEntireControl
, kControlUserPaneHitTestProcTag
, sizeof(gTPHitProc
), &gTPHitProc
);
2432 SetControlData(m_controlRef
, kControlEntireControl
, kControlUserPaneTrackingProcTag
, sizeof(gTPTrackProc
), &gTPTrackProc
);
2433 SetControlData(m_controlRef
, kControlEntireControl
, kControlUserPaneIdleProcTag
, sizeof(gTPIdleProc
), &gTPIdleProc
);
2434 SetControlData(m_controlRef
, kControlEntireControl
, kControlUserPaneKeyDownProcTag
, sizeof(gTPKeyProc
), &gTPKeyProc
);
2435 SetControlData(m_controlRef
, kControlEntireControl
, kControlUserPaneActivateProcTag
, sizeof(gTPActivateProc
), &gTPActivateProc
);
2436 SetControlData(m_controlRef
, kControlEntireControl
, kControlUserPaneFocusProcTag
, sizeof(gTPFocusProc
), &gTPFocusProc
);
2438 /* calculate the rectangles used by the control */
2439 UMAGetControlBoundsInWindowCoords(m_controlRef
, &bounds
);
2440 m_macTXNvars
->fRTextOutlineRegion
= NewRgn() ;
2441 TPCalculateBounds( m_macTXNvars
, bounds
) ;
2443 /* set up the drawing environment */
2444 SetPort(m_macTXNvars
->fDrawingEnvironment
);
2446 /* create the new edit field */
2448 TXNFrameOptions frameOptions
= FrameOptionsFromWXStyle( m_windowStyle
) ;
2450 verify_noerr(TXNNewObject(NULL
, m_macTXNvars
->fOwner
, &m_macTXNvars
->fRTextArea
,
2452 kTXNTextEditStyleFrameType
,
2454 kTXNSystemDefaultEncoding
,
2455 &m_macTXNvars
->fTXNRec
, &m_macTXNvars
->fTXNFrame
, (TXNObjectRefcon
) m_macTXNvars
));
2456 m_txn
= m_macTXNvars
->fTXNRec
;
2458 /* perform final activations and setup for our text field. Here,
2459 we assume that the window is going to be the 'active' window. */
2460 TPActivatePaneText(m_macTXNvars
, m_macTXNvars
->fIsActive
&& m_macTXNvars
->fInFocus
);
2465 // ----------------------------------------------------------------------------
2466 // MLTE control implementation (OSX part)
2467 // ----------------------------------------------------------------------------
2469 #if TARGET_API_MAC_OSX
2471 #if MAC_OS_X_VERSION_MAX_ALLOWED > MAC_OS_X_VERSION_10_2
2473 wxMacMLTEHIViewControl::wxMacMLTEHIViewControl( wxWindow
*wxPeer
,
2474 const wxString
& str
,
2476 const wxSize
& size
, long style
)
2478 m_font
= wxPeer
->GetFont() ;
2479 m_windowStyle
= style
;
2480 Rect bounds
= wxMacGetBoundsForControl( wxPeer
, pos
, size
) ;
2482 wxMacConvertNewlines13To10( &st
) ;
2484 HIRect hr
= { bounds
.left
, bounds
.top
, bounds
.right
- bounds
.left
, bounds
.bottom
- bounds
.top
} ;
2486 m_scrollView
= NULL
;
2487 TXNFrameOptions frameOptions
= FrameOptionsFromWXStyle( style
) ;
2488 if ( frameOptions
& (kTXNWantVScrollBarMask
|kTXNWantHScrollBarMask
) )
2490 HIScrollViewCreate(( frameOptions
& kTXNWantHScrollBarMask
? kHIScrollViewOptionsHorizScroll
: 0) |
2491 ( frameOptions
& kTXNWantVScrollBarMask
? kHIScrollViewOptionsVertScroll
: 0 ) , &m_scrollView
) ;
2493 HIViewSetFrame( m_scrollView
, &hr
);
2494 HIViewSetVisible( m_scrollView
, true );
2498 HITextViewCreate( NULL
, 0, frameOptions
, &m_textView
) ;
2499 m_txn
= HITextViewGetTXNObject( m_textView
) ;
2500 HIViewSetVisible( m_textView
, true ) ;
2503 HIViewAddSubview( m_scrollView
, m_textView
) ;
2504 m_controlRef
= m_scrollView
;
2505 wxPeer
->MacInstallEventHandler( (WXWidget
) m_textView
) ;
2509 HIViewSetFrame( m_textView
, &hr
);
2510 m_controlRef
= m_textView
;
2514 SetTXNData( st
, kTXNStartOffset
, kTXNEndOffset
) ;
2516 TXNSetSelection( m_txn
, 0, 0);
2517 TXNShowSelection( m_txn
, kTXNShowStart
);
2519 AdjustCreationAttributes( *wxWHITE
, true ) ;
2522 OSStatus
wxMacMLTEHIViewControl::SetFocus( ControlFocusPart focusPart
)
2524 return SetKeyboardFocus( GetControlOwner( m_textView
) ,
2525 m_textView
, focusPart
) ;
2528 bool wxMacMLTEHIViewControl::HasFocus() const
2530 ControlRef control
;
2531 GetKeyboardFocus( GetUserFocusWindow() , &control
) ;
2532 return control
== m_textView
;
2535 bool wxMacMLTEHIViewControl::NeedsFocusRect() const
2537 return m_windowStyle
& wxNO_BORDER
? false : true;
2540 #endif // MAC_OS_X_VERSION_MAX_ALLOWED > MAC_OS_X_VERSION_10_2
2545 #endif // wxUSE_TEXTCTRL