1 /////////////////////////////////////////////////////////////////////////////
4 // Author: Stefan Csomor
5 // Modified by: Ryan Norton (MLTE GetLineLength and GetLineText)
8 // Copyright: (c) Stefan Csomor
9 // Licence: wxWindows licence
10 /////////////////////////////////////////////////////////////////////////////
12 #include "wx/wxprec.h"
18 #include <sys/types.h>
24 #include "wx/msgdlg.h"
26 #if wxUSE_STD_IOSTREAM
36 #include "wx/button.h"
37 #include "wx/toplevel.h"
38 #include "wx/textctrl.h"
39 #include "wx/settings.h"
40 #include "wx/filefn.h"
42 #include "wx/sysopt.h"
46 #if defined(__BORLANDC__) && !defined(__WIN32__)
48 #elif !defined(__MWERKS__) && !defined(__GNUWIN32) && !defined(__DARWIN__)
56 // if this is set to 1 then under OSX 10.2 the 'classic' MLTE implementation will be used
57 // if set to 0 then the unicode textctrl will be used
58 #ifndef wxMAC_AWAYS_USE_MLTE
59 #define wxMAC_AWAYS_USE_MLTE 1
65 kTXNVisibilityTag
= 'visb' /*set the visibility state of the object */
70 #include <MacTextEditor.h>
71 #include <ATSUnicode.h>
72 #include <TextCommon.h>
73 #include <TextEncodingConverter.h>
75 #include "wx/mac/uma.h"
81 virtual ~wxMacFunctor() {}
82 virtual void* operator()() = 0 ;
83 static void* CallBackProc(void *param
)
85 wxMacFunctor
* f
= (wxMacFunctor
*) param
;
86 void *result
= (*f
)() ;
91 template<typename classtype
,typename param1type
>
92 class wxMacObjectFunctor1
: public wxMacFunctor
94 typedef void (classtype::*function
)( param1type p1
) ;
95 typedef void (classtype::*ref_function
)( const param1type
& p1
) ;
97 wxMacObjectFunctor1( classtype
*obj
, function f
, param1type p1
) :
105 wxMacObjectFunctor1( classtype
*obj
, ref_function f
, param1type p1
) :
113 ~wxMacObjectFunctor1() {}
115 virtual void* operator()()
117 (m_object
->*m_function
)(m_param1
) ;
121 classtype
* m_object
;
122 param1type m_param1
;
125 function m_function
;
126 ref_function m_refFunction
;
130 template<typename classtype
, typename param1type
>
131 void* wxMacMPRemoteCall( classtype
*object
, void (classtype::*function
)( param1type p1
) , param1type p1
)
133 wxMacObjectFunctor1
<classtype
,param1type
> params(object
,function
,p1
) ;
135 MPRemoteCall( wxMacFunctor::CallBackProc
, ¶ms
, kMPOwningProcessRemoteContext
) ;
139 template<typename classtype
, typename param1type
>
140 void* wxMacMPRemoteCall( classtype
*object
, void (classtype::*function
)( const param1type
& p1
) , param1type p1
)
142 wxMacObjectFunctor1
<classtype
,param1type
> params(object
,function
,p1
) ;
144 MPRemoteCall( wxMacFunctor::CallBackProc
, ¶ms
, kMPOwningProcessRemoteContext
) ;
148 template<typename classtype
, typename param1type
>
149 void* wxMacMPRemoteGUICall( classtype
*object
, void (classtype::*function
)( param1type p1
) , param1type p1
)
152 void *result
= wxMacMPRemoteCall( object
, function
, p1
) ;
157 template<typename classtype
, typename param1type
>
158 void* wxMacMPRemoteGUICall( classtype
*object
, void (classtype::*function
)( const param1type
& p1
) , param1type p1
)
161 void *result
= wxMacMPRemoteCall( object
, function
, p1
) ;
165 // common interface for all implementations
166 class wxMacTextControl
: public wxMacControl
169 wxMacTextControl( wxTextCtrl
*peer
) ;
170 ~wxMacTextControl() ;
172 virtual wxString
GetStringValue() const = 0 ;
173 virtual void SetStringValue( const wxString
&val
) = 0 ;
174 virtual void SetStyle(long start
, long end
, const wxTextAttr
& style
) ;
175 virtual void Copy() ;
177 virtual void Paste() ;
178 virtual bool CanPaste() const ;
179 virtual void SetEditable(bool editable
) ;
180 virtual wxTextPos
GetLastPosition() const ;
181 virtual void Replace( long from
, long to
, const wxString
&str
) ;
182 virtual void Remove( long from
, long to
) ;
183 virtual void SetSelection( long from
, long to
) = 0 ;
184 virtual void GetSelection( long* from
, long* to
) const = 0 ;
185 virtual void WriteText(const wxString
& str
) = 0 ;
187 virtual void Clear() ;
188 virtual bool CanUndo() const;
189 virtual void Undo() ;
190 virtual bool CanRedo() const;
191 virtual void Redo() ;
192 virtual int GetNumberOfLines() const ;
193 virtual long XYToPosition(long x
, long y
) const;
194 virtual bool PositionToXY(long pos
, long *x
, long *y
) const ;
195 virtual void ShowPosition( long WXUNUSED(pos
) ) ;
196 virtual int GetLineLength(long lineNo
) const ;
197 virtual wxString
GetLineText(long lineNo
) const ;
198 virtual bool SetupCursor( const wxPoint
& pt
) { return false ; }
200 #ifndef __WXMAC_OSX__
201 virtual void MacControlUserPaneDrawProc(wxInt16 part
) = 0 ;
202 virtual wxInt16
MacControlUserPaneHitTestProc(wxInt16 x
, wxInt16 y
) = 0 ;
203 virtual wxInt16
MacControlUserPaneTrackingProc(wxInt16 x
, wxInt16 y
, void* actionProc
) = 0 ;
204 virtual void MacControlUserPaneIdleProc() = 0 ;
205 virtual wxInt16
MacControlUserPaneKeyDownProc(wxInt16 keyCode
, wxInt16 charCode
, wxInt16 modifiers
) = 0 ;
206 virtual void MacControlUserPaneActivateProc(bool activating
) = 0 ;
207 virtual wxInt16
MacControlUserPaneFocusProc(wxInt16 action
) = 0 ;
208 virtual void MacControlUserPaneBackgroundProc(void* info
) = 0 ;
212 // common parts for implementations based on MLTE
214 class wxMacMLTEControl
: public wxMacTextControl
217 wxMacMLTEControl( wxTextCtrl
*peer
) ;
218 virtual wxString
GetStringValue() const ;
219 virtual void SetStringValue( const wxString
&str
) ;
221 static TXNFrameOptions
FrameOptionsFromWXStyle( long wxStyle
) ;
222 void AdjustCreationAttributes( const wxColour
& background
, bool visible
) ;
224 virtual void SetFont( const wxFont
& font
, const wxColour
& foreground
, long windowStyle
) ;
225 virtual void SetBackground( const wxBrush
&brush
) ;
226 virtual void SetStyle(long start
, long end
, const wxTextAttr
& style
) ;
227 virtual void Copy() ;
229 virtual void Paste() ;
230 virtual bool CanPaste() const ;
231 virtual void SetEditable(bool editable
) ;
232 virtual wxTextPos
GetLastPosition() const ;
233 virtual void Replace( long from
, long to
, const wxString
&str
) ;
234 virtual void Remove( long from
, long to
) ;
235 virtual void GetSelection( long* from
, long* to
) const ;
236 virtual void SetSelection( long from
, long to
) ;
238 virtual void WriteText(const wxString
& str
) ;
239 virtual void Clear() ;
241 virtual bool CanUndo() const ;
242 virtual void Undo() ;
243 virtual bool CanRedo() const;
244 virtual void Redo() ;
245 virtual int GetNumberOfLines() const ;
246 virtual long XYToPosition(long x
, long y
) const ;
247 virtual bool PositionToXY(long pos
, long *x
, long *y
) const ;
248 virtual void ShowPosition( long pos
) ;
249 virtual int GetLineLength(long lineNo
) const ;
250 virtual wxString
GetLineText(long lineNo
) const ;
252 void SetTXNData( const wxString
& st
, TXNOffset start
, TXNOffset end
) ;
255 void TXNSetAttribute( const wxTextAttr
& style
, long from
, long to
) ;
259 #if TARGET_API_MAC_OSX
261 // implementation available under OSX
263 #if MAC_OS_X_VERSION_MAX_ALLOWED > MAC_OS_X_VERSION_10_2
265 class wxMacMLTEHIViewControl
: public wxMacMLTEControl
268 wxMacMLTEHIViewControl( wxTextCtrl
*wxPeer
,
271 const wxSize
& size
, long style
) ;
272 virtual OSStatus
SetFocus( ControlFocusPart focusPart
) ;
273 virtual bool HasFocus() const ;
274 virtual void SetBackground( const wxBrush
&brush
) ;
276 HIViewRef m_scrollView
;
277 HIViewRef m_textView
;
282 class wxMacUnicodeTextControl
: public wxMacTextControl
285 wxMacUnicodeTextControl( wxTextCtrl
*wxPeer
,
288 const wxSize
& size
, long style
) ;
289 ~wxMacUnicodeTextControl();
290 virtual void VisibilityChanged(bool shown
);
291 virtual wxString
GetStringValue() const ;
292 virtual void SetStringValue( const wxString
&str
) ;
295 virtual void Paste();
296 virtual bool CanPaste() const;
297 virtual void SetEditable(bool editable
) ;
298 virtual void GetSelection( long* from
, long* to
) const ;
299 virtual void SetSelection( long from
, long to
) ;
300 virtual void WriteText(const wxString
& str
) ;
302 // contains the tag for the content (is different for password and non-password controls)
308 // 'classic' MLTE implementation
310 class wxMacMLTEClassicControl
: public wxMacMLTEControl
313 wxMacMLTEClassicControl( wxTextCtrl
*wxPeer
,
316 const wxSize
& size
, long style
) ;
317 ~wxMacMLTEClassicControl() ;
318 virtual void VisibilityChanged(bool shown
) ;
319 virtual void SuperChangedPosition() ;
321 virtual void MacControlUserPaneDrawProc(wxInt16 part
) ;
322 virtual wxInt16
MacControlUserPaneHitTestProc(wxInt16 x
, wxInt16 y
) ;
323 virtual wxInt16
MacControlUserPaneTrackingProc(wxInt16 x
, wxInt16 y
, void* actionProc
) ;
324 virtual void MacControlUserPaneIdleProc() ;
325 virtual wxInt16
MacControlUserPaneKeyDownProc(wxInt16 keyCode
, wxInt16 charCode
, wxInt16 modifiers
) ;
326 virtual void MacControlUserPaneActivateProc(bool activating
) ;
327 virtual wxInt16
MacControlUserPaneFocusProc(wxInt16 action
) ;
328 virtual void MacControlUserPaneBackgroundProc(void* info
) ;
330 virtual bool SetupCursor( const wxPoint
& WXUNUSED(pt
) ) { MacControlUserPaneIdleProc() ; return true ;}
332 virtual void SetRect( Rect
*r
) ;
337 void MacUpdatePosition() ;
338 void MacActivatePaneText(Boolean setActive
) ;
339 void MacFocusPaneText(Boolean setFocus
) ;
341 void MacSetObjectVisibility(Boolean vis
) ;
343 TXNFrameID m_txnFrameID
;
345 WindowRef m_txnWindow
;
346 // bounds of the control as we last did set the txn frames
347 Rect m_txnControlBounds
;
348 Rect m_txnVisBounds
;
350 static pascal void TXNScrollInfoProc (SInt32 iValue
, SInt32 iMaximumValue
,
351 TXNScrollBarOrientation iScrollBarOrientation
, SInt32 iRefCon
) ;
352 static pascal void TXNScrollActionProc( ControlRef controlRef
, ControlPartCode partCode
) ;
353 ControlRef m_sbHorizontal
;
354 SInt32 m_lastHorizontalValue
;
355 ControlRef m_sbVertical
;
356 SInt32 m_lastVerticalValue
;
360 #define TE_UNLIMITED_LENGTH 0xFFFFFFFFUL
362 IMPLEMENT_DYNAMIC_CLASS(wxTextCtrl
, wxControl
)
364 BEGIN_EVENT_TABLE(wxTextCtrl
, wxControl
)
365 EVT_ERASE_BACKGROUND( wxTextCtrl::OnEraseBackground
)
366 EVT_DROP_FILES(wxTextCtrl::OnDropFiles
)
367 EVT_CHAR(wxTextCtrl::OnChar
)
368 EVT_MENU(wxID_CUT
, wxTextCtrl::OnCut
)
369 EVT_MENU(wxID_COPY
, wxTextCtrl::OnCopy
)
370 EVT_MENU(wxID_PASTE
, wxTextCtrl::OnPaste
)
371 EVT_MENU(wxID_UNDO
, wxTextCtrl::OnUndo
)
372 EVT_MENU(wxID_REDO
, wxTextCtrl::OnRedo
)
373 EVT_MENU(wxID_CLEAR
, wxTextCtrl::OnDelete
)
374 EVT_MENU(wxID_SELECTALL
, wxTextCtrl::OnSelectAll
)
376 EVT_CONTEXT_MENU(wxTextCtrl::OnContextMenu
)
378 EVT_UPDATE_UI(wxID_CUT
, wxTextCtrl::OnUpdateCut
)
379 EVT_UPDATE_UI(wxID_COPY
, wxTextCtrl::OnUpdateCopy
)
380 EVT_UPDATE_UI(wxID_PASTE
, wxTextCtrl::OnUpdatePaste
)
381 EVT_UPDATE_UI(wxID_UNDO
, wxTextCtrl::OnUpdateUndo
)
382 EVT_UPDATE_UI(wxID_REDO
, wxTextCtrl::OnUpdateRedo
)
383 EVT_UPDATE_UI(wxID_CLEAR
, wxTextCtrl::OnUpdateDelete
)
384 EVT_UPDATE_UI(wxID_SELECTALL
, wxTextCtrl::OnUpdateSelectAll
)
388 void wxTextCtrl::Init()
393 m_privateContextMenu
= NULL
;
395 m_maxLength
= TE_UNLIMITED_LENGTH
;
398 wxTextCtrl::~wxTextCtrl()
400 delete m_privateContextMenu
;
404 bool wxTextCtrl::Create(wxWindow
*parent
, wxWindowID id
,
407 const wxSize
& size
, long style
,
408 const wxValidator
& validator
,
409 const wxString
& name
)
411 m_macIsUserPane
= false ;
414 if ( ! ( style
& wxNO_BORDER
) )
415 style
= ( style
& ~wxBORDER_MASK
) | wxSUNKEN_BORDER
;
417 if ( !wxTextCtrlBase::Create(parent
, id
, pos
, size
, style
& ~(wxHSCROLL
|wxVSCROLL
), validator
, name
) )
420 if ( m_windowStyle
& wxTE_MULTILINE
)
422 wxASSERT_MSG( !(m_windowStyle
& wxTE_PROCESS_ENTER
),
423 wxT("wxTE_PROCESS_ENTER style is ignored for multiline text controls (they always process it)") );
425 m_windowStyle
|= wxTE_PROCESS_ENTER
;
426 style
|= wxTE_PROCESS_ENTER
;
429 bool forceMLTE
= false ;
430 #if wxUSE_SYSTEM_OPTIONS
431 if ( (wxSystemOptions::HasOption(wxMAC_TEXTCONTROL_USE_MLTE
) ) && ( wxSystemOptions::GetOptionInt( wxMAC_TEXTCONTROL_USE_MLTE
) == 1) )
438 #if MAC_OS_X_VERSION_MAX_ALLOWED > MAC_OS_X_VERSION_10_2
439 if ( UMAGetSystemVersion() >= 0x1030 && forceMLTE
== false )
441 if ( m_windowStyle
& wxTE_MULTILINE
)
442 m_peer
= new wxMacMLTEHIViewControl( this , str
, pos
, size
, style
) ;
447 if ( !(m_windowStyle
& wxTE_MULTILINE
) && forceMLTE
== false )
448 m_peer
= new wxMacUnicodeTextControl( this , str
, pos
, size
, style
) ;
453 m_peer
= new wxMacMLTEClassicControl( this , str
, pos
, size
, style
) ;
456 MacPostControlCreate(pos
,size
) ;
458 // only now the embedding is correct and we can do a positioning update
460 MacSuperChangedPosition() ;
462 if ( m_windowStyle
& wxTE_READONLY
)
464 SetEditable( false ) ;
467 SetCursor( wxCursor( wxCURSOR_IBEAM
) ) ;
472 void wxTextCtrl::MacSuperChangedPosition()
474 wxWindow::MacSuperChangedPosition() ;
475 GetPeer()->SuperChangedPosition() ;
478 void wxTextCtrl::MacVisibilityChanged()
480 GetPeer()->VisibilityChanged( MacIsReallyShown() ) ;
483 void wxTextCtrl::MacEnabledStateChanged()
487 wxString
wxTextCtrl::GetValue() const
489 return GetPeer()->GetStringValue() ;
492 void wxTextCtrl::GetSelection(long* from
, long* to
) const
494 GetPeer()->GetSelection( from
, to
) ;
497 void wxTextCtrl::SetValue(const wxString
& str
)
500 if ( GetValue() == str
)
503 GetPeer()->SetStringValue(str
) ;
505 wxCommandEvent
event(wxEVT_COMMAND_TEXT_UPDATED
, m_windowId
);
506 event
.SetString( GetValue() ) ;
507 event
.SetEventObject( this );
508 GetEventHandler()->ProcessEvent(event
);
511 void wxTextCtrl::SetMaxLength(unsigned long len
)
516 bool wxTextCtrl::SetFont( const wxFont
& font
)
518 if ( !wxTextCtrlBase::SetFont( font
) )
521 GetPeer()->SetFont( font
, GetForegroundColour() , GetWindowStyle() ) ;
525 bool wxTextCtrl::SetStyle(long start
, long end
, const wxTextAttr
& style
)
527 GetPeer()->SetStyle( start
, end
, style
) ;
531 bool wxTextCtrl::SetDefaultStyle(const wxTextAttr
& style
)
533 wxTextCtrlBase::SetDefaultStyle( style
) ;
534 SetStyle( kTXNUseCurrentSelection
, kTXNUseCurrentSelection
, GetDefaultStyle() ) ;
538 // Clipboard operations
539 void wxTextCtrl::Copy()
547 void wxTextCtrl::Cut()
553 wxCommandEvent
event(wxEVT_COMMAND_TEXT_UPDATED
, m_windowId
);
554 event
.SetEventObject( this );
555 GetEventHandler()->ProcessEvent(event
);
559 void wxTextCtrl::Paste()
564 // eventually we should add setting the default style again
566 wxCommandEvent
event(wxEVT_COMMAND_TEXT_UPDATED
, m_windowId
);
567 event
.SetEventObject( this );
568 GetEventHandler()->ProcessEvent(event
);
572 bool wxTextCtrl::CanCopy() const
574 // Can copy if there's a selection
576 GetSelection(& from
, & to
);
580 bool wxTextCtrl::CanCut() const
586 // Can cut if there's a selection
588 GetSelection(& from
, & to
);
592 bool wxTextCtrl::CanPaste() const
597 return GetPeer()->CanPaste() ;
600 void wxTextCtrl::SetEditable(bool editable
)
602 if ( editable
!= m_editable
)
604 m_editable
= editable
;
605 GetPeer()->SetEditable( editable
) ;
609 void wxTextCtrl::SetInsertionPoint(long pos
)
611 SetSelection( pos
, pos
) ;
614 void wxTextCtrl::SetInsertionPointEnd()
616 wxTextPos pos
= GetLastPosition();
617 SetInsertionPoint(pos
);
620 long wxTextCtrl::GetInsertionPoint() const
623 GetSelection( &begin
, &end
) ;
627 wxTextPos
wxTextCtrl::GetLastPosition() const
629 return GetPeer()->GetLastPosition( ) ;
632 void wxTextCtrl::Replace(long from
, long to
, const wxString
& str
)
634 GetPeer()->Replace( from
, to
, str
) ;
637 void wxTextCtrl::Remove(long from
, long to
)
639 GetPeer()->Remove( from
, to
) ;
642 void wxTextCtrl::SetSelection(long from
, long to
)
644 GetPeer()->SetSelection( from
, to
) ;
647 bool wxTextCtrl::LoadFile(const wxString
& file
)
649 if ( wxTextCtrlBase::LoadFile(file
) )
657 void wxTextCtrl::WriteText(const wxString
& str
)
659 // TODO this MPRemoting will be moved into a remoting peer proxy for any command
660 if ( !wxIsMainThread() )
662 // unfortunately CW 8 is not able to correctly deduce the template types, so we have
663 // to instantiate explicitly
664 wxMacMPRemoteGUICall
<wxTextCtrl
,wxString
>( this , &wxTextCtrl::WriteText
, str
) ;
669 GetPeer()->WriteText( str
) ;
673 void wxTextCtrl::AppendText(const wxString
& text
)
675 SetInsertionPointEnd();
679 void wxTextCtrl::Clear()
684 bool wxTextCtrl::IsModified() const
689 bool wxTextCtrl::IsEditable() const
691 return IsEnabled() && m_editable
;
694 bool wxTextCtrl::AcceptsFocus() const
696 // we don't want focus if we can't be edited
697 return /*IsEditable() && */ wxControl::AcceptsFocus();
700 wxSize
wxTextCtrl::DoGetBestSize() const
706 // these are the numbers from the HIG, we reduce them by the borders
709 switch( m_windowVariant
)
711 case wxWINDOW_VARIANT_NORMAL
:
714 case wxWINDOW_VARIANT_SMALL
:
717 case wxWINDOW_VARIANT_MINI
:
725 // as the above numbers have some free space around the text
726 // we get 5 lines like this anyway
727 if ( m_windowStyle
& wxTE_MULTILINE
)
732 if ( !HasFlag(wxNO_BORDER
) )
735 return wxSize(wText
, hText
);
738 // ----------------------------------------------------------------------------
740 // ----------------------------------------------------------------------------
742 void wxTextCtrl::Undo()
750 void wxTextCtrl::Redo()
758 bool wxTextCtrl::CanUndo() const
764 return GetPeer()->CanUndo() ;
767 bool wxTextCtrl::CanRedo() const
773 return GetPeer()->CanRedo() ;
776 void wxTextCtrl::MarkDirty()
781 void wxTextCtrl::DiscardEdits()
786 int wxTextCtrl::GetNumberOfLines() const
788 return GetPeer()->GetNumberOfLines() ;
791 long wxTextCtrl::XYToPosition(long x
, long y
) const
793 return GetPeer()->XYToPosition( x
, y
) ;
796 bool wxTextCtrl::PositionToXY(long pos
, long *x
, long *y
) const
798 return GetPeer()->PositionToXY(pos
, x
, y
) ;
801 void wxTextCtrl::ShowPosition(long pos
)
803 return GetPeer()->ShowPosition(pos
) ;
806 int wxTextCtrl::GetLineLength(long lineNo
) const
808 return GetPeer()->GetLineLength(lineNo
) ;
811 wxString
wxTextCtrl::GetLineText(long lineNo
) const
813 return GetPeer()->GetLineText(lineNo
) ;
820 void wxTextCtrl::Command(wxCommandEvent
& event
)
822 SetValue (event
.GetString());
823 ProcessCommand (event
);
826 void wxTextCtrl::OnDropFiles(wxDropFilesEvent
& event
)
828 // By default, load the first file into the text window.
829 if (event
.GetNumberOfFiles() > 0)
831 LoadFile(event
.GetFiles()[0]);
835 void wxTextCtrl::OnEraseBackground(wxEraseEvent
& event
)
837 // all erasing should be done by the real mac control implementation
838 // while this is true for MLTE under classic, the HITextView is somehow
839 // transparent but background erase is not working correctly, so intercept
840 // things while we can...
844 void wxTextCtrl::OnChar(wxKeyEvent
& event
)
846 int key
= event
.GetKeyCode() ;
847 bool eat_key
= false ;
849 if ( key
== 'c' && event
.MetaDown() )
856 if ( !IsEditable() && key
!= WXK_LEFT
&& key
!= WXK_RIGHT
&& key
!= WXK_DOWN
&& key
!= WXK_UP
&& key
!= WXK_TAB
&&
857 !( key
== WXK_RETURN
&& ( (m_windowStyle
& wxPROCESS_ENTER
) || (m_windowStyle
& wxTE_MULTILINE
) ) )
858 /* && key != WXK_PRIOR && key != WXK_NEXT && key != WXK_HOME && key != WXK_END */
865 // Check if we have reached the max # of chars, but still allow navigation and deletion
866 if ( !IsMultiLine() && GetValue().Length() >= m_maxLength
&&
867 key
!= WXK_LEFT
&& key
!= WXK_RIGHT
&& key
!= WXK_TAB
&&
868 key
!= WXK_BACK
&& !( key
== WXK_RETURN
&& (m_windowStyle
& wxPROCESS_ENTER
) )
871 // eat it, we don't want to add more than allowed # of characters
875 // assume that any key not processed yet is going to modify the control
878 if ( key
== 'v' && event
.MetaDown() )
884 if ( key
== 'x' && event
.MetaDown() )
893 if (m_windowStyle
& wxPROCESS_ENTER
)
895 wxCommandEvent
event(wxEVT_COMMAND_TEXT_ENTER
, m_windowId
);
896 event
.SetEventObject( this );
897 event
.SetString( GetValue() );
898 if ( GetEventHandler()->ProcessEvent(event
) )
901 if ( !(m_windowStyle
& wxTE_MULTILINE
) )
903 wxWindow
*parent
= GetParent();
904 while( parent
&& !parent
->IsTopLevel() && parent
->GetDefaultItem() == NULL
) {
905 parent
= parent
->GetParent() ;
907 if ( parent
&& parent
->GetDefaultItem() )
909 wxButton
*def
= wxDynamicCast(parent
->GetDefaultItem(),
911 if ( def
&& def
->IsEnabled() )
913 wxCommandEvent
event(wxEVT_COMMAND_BUTTON_CLICKED
, def
->GetId() );
914 event
.SetEventObject(def
);
920 // this will make wxWidgets eat the ENTER key so that
921 // we actually prevent line wrapping in a single line
929 if ( !(m_windowStyle
& wxTE_PROCESS_TAB
))
932 if (!event
.ShiftDown())
933 flags
|= wxNavigationKeyEvent::IsForward
;
934 if (event
.ControlDown())
935 flags
|= wxNavigationKeyEvent::WinChange
;
941 // This is necessary (don't know why) or the tab will not
943 WriteText(wxT("\t"));
951 // perform keystroke handling
952 if ( wxTheApp
->MacGetCurrentEvent() != NULL
&& wxTheApp
->MacGetCurrentEventHandlerCallRef() != NULL
)
953 CallNextEventHandler((EventHandlerCallRef
)wxTheApp
->MacGetCurrentEventHandlerCallRef() , (EventRef
) wxTheApp
->MacGetCurrentEvent() ) ;
957 if ( wxMacConvertEventToRecord( (EventRef
) wxTheApp
->MacGetCurrentEvent() , &rec
) )
959 EventRecord
*ev
= &rec
;
962 keychar
= short(ev
->message
& charCodeMask
);
963 keycode
= short(ev
->message
& keyCodeMask
) >> 8 ;
965 m_peer
->HandleKey( keycode
, keychar
, ev
->modifiers
) ;
969 if ( ( key
>= 0x20 && key
< WXK_START
) ||
974 wxCommandEvent
event1(wxEVT_COMMAND_TEXT_UPDATED
, m_windowId
);
975 event1
.SetEventObject( this );
976 wxPostEvent(GetEventHandler(),event1
);
980 // ----------------------------------------------------------------------------
981 // standard handlers for standard edit menu events
982 // ----------------------------------------------------------------------------
984 void wxTextCtrl::OnCut(wxCommandEvent
& WXUNUSED(event
))
989 void wxTextCtrl::OnCopy(wxCommandEvent
& WXUNUSED(event
))
994 void wxTextCtrl::OnPaste(wxCommandEvent
& WXUNUSED(event
))
999 void wxTextCtrl::OnUndo(wxCommandEvent
& WXUNUSED(event
))
1004 void wxTextCtrl::OnRedo(wxCommandEvent
& WXUNUSED(event
))
1009 void wxTextCtrl::OnDelete(wxCommandEvent
& WXUNUSED(event
))
1012 GetSelection(& from
, & to
);
1013 if (from
!= -1 && to
!= -1)
1017 void wxTextCtrl::OnSelectAll(wxCommandEvent
& WXUNUSED(event
))
1019 SetSelection(-1, -1);
1022 void wxTextCtrl::OnUpdateCut(wxUpdateUIEvent
& event
)
1024 event
.Enable( CanCut() );
1027 void wxTextCtrl::OnUpdateCopy(wxUpdateUIEvent
& event
)
1029 event
.Enable( CanCopy() );
1032 void wxTextCtrl::OnUpdatePaste(wxUpdateUIEvent
& event
)
1034 event
.Enable( CanPaste() );
1037 void wxTextCtrl::OnUpdateUndo(wxUpdateUIEvent
& event
)
1039 event
.Enable( CanUndo() );
1042 void wxTextCtrl::OnUpdateRedo(wxUpdateUIEvent
& event
)
1044 event
.Enable( CanRedo() );
1047 void wxTextCtrl::OnUpdateDelete(wxUpdateUIEvent
& event
)
1050 GetSelection(& from
, & to
);
1051 event
.Enable(from
!= -1 && to
!= -1 && from
!= to
&& IsEditable()) ;
1054 void wxTextCtrl::OnUpdateSelectAll(wxUpdateUIEvent
& event
)
1056 event
.Enable(GetLastPosition() > 0);
1059 // CS: Context Menus only work with mlte implementations or non-multiline HIViews at the moment
1061 void wxTextCtrl::OnContextMenu(wxContextMenuEvent
& event
)
1063 if (m_privateContextMenu
== NULL
)
1065 m_privateContextMenu
= new wxMenu
;
1066 m_privateContextMenu
->Append(wxID_UNDO
, _("&Undo"));
1067 m_privateContextMenu
->Append(wxID_REDO
, _("&Redo"));
1068 m_privateContextMenu
->AppendSeparator();
1069 m_privateContextMenu
->Append(wxID_CUT
, _("Cu&t"));
1070 m_privateContextMenu
->Append(wxID_COPY
, _("&Copy"));
1071 m_privateContextMenu
->Append(wxID_PASTE
, _("&Paste"));
1072 m_privateContextMenu
->Append(wxID_CLEAR
, _("&Delete"));
1073 m_privateContextMenu
->AppendSeparator();
1074 m_privateContextMenu
->Append(wxID_SELECTALL
, _("Select &All"));
1077 if (m_privateContextMenu
!= NULL
)
1078 PopupMenu(m_privateContextMenu
);
1081 bool wxTextCtrl::MacSetupCursor( const wxPoint
& pt
)
1083 if ( !GetPeer()->SetupCursor(pt
) )
1084 return wxWindow::MacSetupCursor( pt
) ;
1088 #if !TARGET_API_MAC_OSX
1090 // user pane implementation
1092 void wxTextCtrl::MacControlUserPaneDrawProc(wxInt16 part
)
1094 GetPeer()->MacControlUserPaneDrawProc( part
) ;
1097 wxInt16
wxTextCtrl::MacControlUserPaneHitTestProc(wxInt16 x
, wxInt16 y
)
1099 return GetPeer()->MacControlUserPaneHitTestProc( x
, y
) ;
1102 wxInt16
wxTextCtrl::MacControlUserPaneTrackingProc(wxInt16 x
, wxInt16 y
, void* actionProc
)
1104 return GetPeer()->MacControlUserPaneTrackingProc( x
, y
, actionProc
) ;
1107 void wxTextCtrl::MacControlUserPaneIdleProc()
1109 GetPeer()->MacControlUserPaneIdleProc( ) ;
1112 wxInt16
wxTextCtrl::MacControlUserPaneKeyDownProc(wxInt16 keyCode
, wxInt16 charCode
, wxInt16 modifiers
)
1114 return GetPeer()->MacControlUserPaneKeyDownProc( keyCode
, charCode
, modifiers
) ;
1117 void wxTextCtrl::MacControlUserPaneActivateProc(bool activating
)
1119 GetPeer()->MacControlUserPaneActivateProc( activating
) ;
1122 wxInt16
wxTextCtrl::MacControlUserPaneFocusProc(wxInt16 action
)
1124 return GetPeer()->MacControlUserPaneFocusProc( action
) ;
1127 void wxTextCtrl::MacControlUserPaneBackgroundProc(void* info
)
1129 GetPeer()->MacControlUserPaneBackgroundProc( info
) ;
1133 // ----------------------------------------------------------------------------
1134 // implementation base class
1135 // ----------------------------------------------------------------------------
1137 wxMacTextControl::wxMacTextControl(wxTextCtrl
* peer
) :
1138 wxMacControl( peer
)
1142 wxMacTextControl::~wxMacTextControl()
1146 void wxMacTextControl::SetStyle(long start
, long end
, const wxTextAttr
& style
)
1150 void wxMacTextControl::Copy()
1154 void wxMacTextControl::Cut()
1158 void wxMacTextControl::Paste()
1162 bool wxMacTextControl::CanPaste() const
1167 void wxMacTextControl::SetEditable(bool editable
)
1171 wxTextPos
wxMacTextControl::GetLastPosition() const
1173 return GetStringValue().Length() ;
1176 void wxMacTextControl::Replace( long from
, long to
, const wxString
&val
)
1178 SetSelection( from
, to
) ;
1182 void wxMacTextControl::Remove( long from
, long to
)
1184 SetSelection( from
, to
) ;
1185 WriteText( wxEmptyString
) ;
1188 void wxMacTextControl::Clear()
1190 SetStringValue( wxEmptyString
) ;
1193 bool wxMacTextControl::CanUndo() const
1198 void wxMacTextControl::Undo() { }
1200 bool wxMacTextControl::CanRedo() const
1205 void wxMacTextControl::Redo()
1209 long wxMacTextControl::XYToPosition(long x
, long y
) const
1214 bool wxMacTextControl::PositionToXY(long pos
, long *x
, long *y
) const
1219 void wxMacTextControl::ShowPosition( long WXUNUSED(pos
) )
1223 int wxMacTextControl::GetNumberOfLines() const
1225 ItemCount lines
= 0 ;
1226 wxString content
= GetStringValue() ;
1228 for (size_t i
= 0; i
< content
.Length() ; i
++)
1230 if (content
[i
] == '\r') lines
++;
1235 wxString
wxMacTextControl::GetLineText(long lineNo
) const
1237 // TODO change this if possible to reflect real lines
1238 wxString content
= GetStringValue() ;
1242 for (size_t i
= 0; i
< content
.Length() ; i
++)
1244 if (count
== lineNo
)
1246 // Add chars in line then
1249 for (size_t j
= i
; j
< content
.Length(); j
++)
1251 if (content
[j
] == '\n')
1259 if (content
[i
] == '\n') count
++;
1261 return wxEmptyString
;
1264 int wxMacTextControl::GetLineLength(long lineNo
) const
1266 // TODO change this if possible to reflect real lines
1267 wxString content
= GetStringValue() ;
1271 for (size_t i
= 0; i
< content
.Length() ; i
++)
1273 if (count
== lineNo
)
1275 // Count chars in line then
1277 for (size_t j
= i
; j
< content
.Length(); j
++)
1280 if (content
[j
] == '\n') return count
;
1285 if (content
[i
] == '\n') count
++;
1290 // ----------------------------------------------------------------------------
1291 // standard unicode control implementation
1292 // ----------------------------------------------------------------------------
1294 #if TARGET_API_MAC_OSX
1296 wxMacUnicodeTextControl::wxMacUnicodeTextControl( wxTextCtrl
*wxPeer
,
1297 const wxString
& str
,
1299 const wxSize
& size
, long style
) : wxMacTextControl( wxPeer
)
1301 m_font
= wxPeer
->GetFont() ;
1302 m_windowStyle
= style
;
1303 Rect bounds
= wxMacGetBoundsForControl( wxPeer
, pos
, size
) ;
1305 wxMacConvertNewlines10To13( &st
) ;
1306 wxMacCFStringHolder
cf(st
, m_font
.GetEncoding()) ;
1307 CFStringRef cfr
= cf
;
1308 Boolean isPassword
= ( m_windowStyle
& wxTE_PASSWORD
) != 0 ;
1309 m_valueTag
= isPassword
? kControlEditTextPasswordCFStringTag
: kControlEditTextCFStringTag
;
1310 CreateEditUnicodeTextControl( MAC_WXHWND(wxPeer
->MacGetTopLevelWindowRef()), &bounds
, cfr
, isPassword
, NULL
, &m_controlRef
) ;
1312 if ( !(m_windowStyle
& wxTE_MULTILINE
) )
1314 SetData
<Boolean
>( kControlEditTextPart
, kControlEditTextSingleLineTag
, true ) ;
1318 wxMacUnicodeTextControl::~wxMacUnicodeTextControl()
1322 void wxMacUnicodeTextControl::VisibilityChanged(bool shown
)
1324 if ( !(m_windowStyle
& wxTE_MULTILINE
) && shown
)
1326 // work around a refresh issue insofar as not always the entire content is shown even if this would be possible
1327 ControlEditTextSelectionRec sel
;
1328 CFStringRef value
= NULL
;
1330 verify_noerr( GetData
<ControlEditTextSelectionRec
>( 0, kControlEditTextSelectionTag
, &sel
) );
1331 verify_noerr( GetData
<CFStringRef
>( 0, m_valueTag
, &value
) );
1332 verify_noerr( SetData
<CFStringRef
>( 0, m_valueTag
, &value
) );
1333 verify_noerr( SetData
<ControlEditTextSelectionRec
>( 0, kControlEditTextSelectionTag
, &sel
) );
1335 CFRelease( value
) ;
1338 wxString
wxMacUnicodeTextControl::GetStringValue() const
1341 CFStringRef value
= GetData
<CFStringRef
>(0,m_valueTag
) ;
1344 wxMacCFStringHolder
cf(value
) ;
1345 result
= cf
.AsString() ;
1348 wxMacConvertNewlines13To10( &result
) ;
1350 wxMacConvertNewlines10To13( &result
) ;
1354 void wxMacUnicodeTextControl::SetStringValue( const wxString
&str
)
1357 wxMacConvertNewlines10To13( &st
) ;
1358 wxMacCFStringHolder
cf(st
, m_font
.GetEncoding() ) ;
1359 verify_noerr( SetData
<CFStringRef
>( 0, m_valueTag
, cf
) ) ;
1361 void wxMacUnicodeTextControl::Copy()
1363 SendHICommand( kHICommandCopy
) ;
1365 void wxMacUnicodeTextControl::Cut()
1367 SendHICommand( kHICommandCut
) ;
1369 void wxMacUnicodeTextControl::Paste()
1371 SendHICommand( kHICommandPaste
) ;
1373 bool wxMacUnicodeTextControl::CanPaste() const
1377 void wxMacUnicodeTextControl::SetEditable(bool editable
)
1379 SetData
<Boolean
>( 0 , kControlEditTextLockedTag
, (Boolean
) !editable
) ;
1382 void wxMacUnicodeTextControl::GetSelection( long* from
, long* to
) const
1384 ControlEditTextSelectionRec sel
;
1385 verify_noerr(GetData
<ControlEditTextSelectionRec
>( 0, kControlEditTextSelectionTag
, &sel
) ) ;
1386 if ( from
) *from
= sel
.selStart
;
1387 if ( to
) *to
= sel
.selEnd
;
1390 void wxMacUnicodeTextControl::SetSelection( long from
, long to
)
1392 ControlEditTextSelectionRec sel
;
1393 if ((from
== -1) && (to
== -1))
1396 to
= 32767 ; // sel has 16 bit signed values, max is 32767
1398 sel
.selStart
= from
;
1400 SetData
<ControlEditTextSelectionRec
>( 0 , kControlEditTextSelectionTag
, &sel
) ;
1403 void wxMacUnicodeTextControl::WriteText(const wxString
& str
)
1406 wxMacConvertNewlines10To13( &st
) ;
1407 #if MAC_OS_X_VERSION_MAX_ALLOWED > MAC_OS_X_VERSION_10_2
1408 wxMacCFStringHolder
cf(st
, m_font
.GetEncoding() ) ;
1409 CFStringRef value
= cf
;
1410 SetData
<CFStringRef
>( 0, kControlEditTextInsertCFStringRefTag
, &value
);
1412 wxString val
= GetStringValue() ;
1414 GetSelection( &start
, &end
) ;
1415 val
.Remove( start
, end
- start
) ;
1416 val
.insert( start
, str
) ;
1417 SetStringValue( val
) ;
1418 SetSelection( start
+ str
.Length() , start
+ str
.Length() ) ;
1424 // ----------------------------------------------------------------------------
1425 // MLTE control implementation (common part)
1426 // ----------------------------------------------------------------------------
1428 // if mlte is on read only , no changes at all are allowed, not even from
1429 // procedural API, in order to allow changes via API all the same we must undo
1430 // the readonly status while we are executing, this class helps to do so
1432 class wxMacEditHelper
1435 wxMacEditHelper( TXNObject txn
)
1437 TXNControlTag tag
[] = { kTXNIOPrivilegesTag
} ;
1439 TXNGetTXNObjectControls( m_txn
, 1 , tag
, m_data
) ;
1440 if ( m_data
[0].uValue
== kTXNReadOnly
)
1442 TXNControlData data
[] = { { kTXNReadWrite
} } ;
1443 TXNSetTXNObjectControls( m_txn
, false , 1 , tag
, data
) ;
1448 TXNControlTag tag
[] = { kTXNIOPrivilegesTag
} ;
1449 if ( m_data
[0].uValue
== kTXNReadOnly
)
1451 TXNSetTXNObjectControls( m_txn
, false , 1 , tag
, m_data
) ;
1456 TXNControlData m_data
[1] ;
1459 wxMacMLTEControl::wxMacMLTEControl( wxTextCtrl
*peer
) : wxMacTextControl( peer
)
1461 SetNeedsFocusRect( true ) ;
1464 wxString
wxMacMLTEControl::GetStringValue() const
1468 Size actualSize
= 0;
1472 err
= TXNGetDataEncoded( m_txn
, kTXNStartOffset
, kTXNEndOffset
, &theText
, kTXNUnicodeTextData
);
1480 actualSize
= GetHandleSize( theText
) / sizeof( UniChar
) ;
1481 if ( actualSize
> 0 )
1483 wxChar
*ptr
= NULL
;
1484 #if SIZEOF_WCHAR_T == 2
1485 ptr
= new wxChar
[actualSize
+ 1 ] ;
1486 wxStrncpy( ptr
, (wxChar
*) *theText
, actualSize
) ;
1488 SetHandleSize( theText
, ( actualSize
+ 1 ) * sizeof( UniChar
) ) ;
1490 (((UniChar
*)*theText
)[actualSize
]) = 0 ;
1491 wxMBConvUTF16 converter
;
1492 size_t noChars
= converter
.MB2WC( NULL
, (const char*)*theText
, 0 ) ;
1493 ptr
= new wxChar
[noChars
+ 1] ;
1495 noChars
= converter
.MB2WC( ptr
, (const char*)*theText
, noChars
) ;
1497 HUnlock( theText
) ;
1499 ptr
[actualSize
] = 0 ;
1500 result
= wxString( ptr
) ;
1503 DisposeHandle( theText
) ;
1507 err
= TXNGetDataEncoded( m_txn
, kTXNStartOffset
, kTXNEndOffset
, &theText
, kTXNTextData
);
1515 actualSize
= GetHandleSize( theText
) ;
1516 if ( actualSize
> 0 )
1519 result
= wxString( *theText
, wxConvLocal
, actualSize
) ;
1520 HUnlock( theText
) ;
1522 DisposeHandle( theText
) ;
1527 wxMacConvertNewlines13To10( &result
) ;
1529 wxMacConvertNewlines10To13( &result
) ;
1534 void wxMacMLTEControl::SetStringValue( const wxString
&str
)
1538 wxMacConvertNewlines10To13( &st
) ;
1540 wxMacWindowClipper
c( m_peer
) ;
1542 wxMacEditHelper
help(m_txn
) ;
1543 SetTXNData( st
, kTXNStartOffset
, kTXNEndOffset
) ;
1545 TXNSetSelection( m_txn
, 0, 0);
1546 TXNShowSelection( m_txn
, kTXNShowStart
);
1550 TXNFrameOptions
wxMacMLTEControl::FrameOptionsFromWXStyle( long wxStyle
)
1552 TXNFrameOptions frameOptions
=
1553 kTXNDontDrawCaretWhenInactiveMask
1554 #if MAC_OS_X_VERSION_MAX_ALLOWED >= MAC_OS_X_VERSION_10_3
1555 | kTXNDoFontSubstitutionMask
1559 if ( ! ( wxStyle
& wxTE_NOHIDESEL
) )
1560 frameOptions
|= kTXNDontDrawSelectionWhenInactiveMask
;
1562 if ( wxStyle
& wxTE_MULTILINE
)
1564 if ( ! ( wxStyle
& wxTE_DONTWRAP
) )
1565 frameOptions
|= kTXNAlwaysWrapAtViewEdgeMask
;
1568 frameOptions
|= kTXNAlwaysWrapAtViewEdgeMask
;
1569 frameOptions
|= kTXNWantHScrollBarMask
;
1572 if ( !(wxStyle
& wxTE_NO_VSCROLL
) )
1574 frameOptions
|= kTXNWantVScrollBarMask
;
1575 if ( frameOptions
& kTXNWantHScrollBarMask
)
1576 frameOptions
|= kTXNDrawGrowIconMask
;
1580 frameOptions
|= kTXNSingleLineOnlyMask
;
1582 if ( wxStyle
& wxHSCROLL
)
1583 frameOptions
|= kTXNWantHScrollBarMask
;
1585 return frameOptions
;
1588 void wxMacMLTEControl::AdjustCreationAttributes( const wxColour
&background
, bool visible
)
1590 TXNControlTag iControlTags
[] =
1592 kTXNDoFontSubstitution
,
1593 kTXNWordWrapStateTag
,
1595 TXNControlData iControlData
[] =
1601 int toptag
= WXSIZEOF( iControlTags
) ;
1603 if ( m_windowStyle
& wxTE_MULTILINE
)
1605 if (m_windowStyle
& wxTE_DONTWRAP
)
1606 iControlData
[1].uValue
= kTXNNoAutoWrap
;
1608 iControlData
[1].uValue
= kTXNAutoWrap
;
1610 verify_noerr( TXNSetTXNObjectControls( m_txn
, false, toptag
,
1611 iControlTags
, iControlData
)) ;
1613 // setting the default font
1614 // under 10.2 this causes a visible caret, therefore we avoid it
1616 if ( UMAGetSystemVersion() >= 0x1030 )
1622 GetThemeFont(kThemeSystemFont
, GetApplicationScript() , fontName
, &fontSize
, &fontStyle
) ;
1624 TXNTypeAttributes typeAttr
[] =
1626 { kTXNQDFontNameAttribute
, kTXNQDFontNameAttributeSize
, { (void*) fontName
} } ,
1627 { kTXNQDFontSizeAttribute
, kTXNFontSizeAttributeSize
, { (void*) (fontSize
<< 16) } } ,
1628 { kTXNQDFontStyleAttribute
, kTXNQDFontStyleAttributeSize
, { (void*) normal
} } ,
1631 verify_noerr( TXNSetTypeAttributes (m_txn
, sizeof( typeAttr
) / sizeof(TXNTypeAttributes
) , typeAttr
,
1636 if ( m_windowStyle
& wxTE_PASSWORD
)
1639 verify_noerr(TXNEchoMode( m_txn
, c
, 0 , true )) ;
1642 TXNBackground tback
;
1643 tback
.bgType
= kTXNBackgroundTypeRGB
;
1644 tback
.bg
.color
= MAC_WXCOLORREF( background
.GetPixel() );
1645 TXNSetBackground( m_txn
, &tback
);
1648 void wxMacMLTEControl::SetBackground( const wxBrush
&brush
)
1650 // currently only solid background are supported
1651 TXNBackground tback
;
1652 tback
.bgType
= kTXNBackgroundTypeRGB
;
1653 tback
.bg
.color
= MAC_WXCOLORREF( brush
.GetColour().GetPixel() );
1654 TXNSetBackground( m_txn
, &tback
);
1657 void wxMacMLTEControl::TXNSetAttribute( const wxTextAttr
& style
, long from
, long to
)
1659 TXNTypeAttributes typeAttr
[4] ;
1660 Str255 fontName
= "\pMonaco" ;
1661 SInt16 fontSize
= 12 ;
1662 Style fontStyle
= normal
;
1664 int attrCounter
= 0 ;
1665 if ( style
.HasFont() )
1667 const wxFont
&font
= style
.GetFont() ;
1668 wxMacStringToPascal( font
.GetFaceName() , fontName
) ;
1669 fontSize
= font
.GetPointSize() ;
1670 if ( font
.GetUnderlined() )
1671 fontStyle
|= underline
;
1672 if ( font
.GetWeight() == wxBOLD
)
1674 if ( font
.GetStyle() == wxITALIC
)
1675 fontStyle
|= italic
;
1677 typeAttr
[attrCounter
].tag
= kTXNQDFontNameAttribute
;
1678 typeAttr
[attrCounter
].size
= kTXNQDFontNameAttributeSize
;
1679 typeAttr
[attrCounter
].data
.dataPtr
= (void*) fontName
;
1680 typeAttr
[attrCounter
+1].tag
= kTXNQDFontSizeAttribute
;
1681 typeAttr
[attrCounter
+1].size
= kTXNFontSizeAttributeSize
;
1682 typeAttr
[attrCounter
+1].data
.dataValue
= (fontSize
<< 16) ;
1683 typeAttr
[attrCounter
+2].tag
= kTXNQDFontStyleAttribute
;
1684 typeAttr
[attrCounter
+2].size
= kTXNQDFontStyleAttributeSize
;
1685 typeAttr
[attrCounter
+2].data
.dataValue
= fontStyle
;
1688 if ( style
.HasTextColour() )
1690 typeAttr
[attrCounter
].tag
= kTXNQDFontColorAttribute
;
1691 typeAttr
[attrCounter
].size
= kTXNQDFontColorAttributeSize
;
1692 typeAttr
[attrCounter
].data
.dataPtr
= (void*) &color
;
1693 color
= MAC_WXCOLORREF(style
.GetTextColour().GetPixel()) ;
1696 if ( attrCounter
> 0 )
1698 verify_noerr( TXNSetTypeAttributes ( m_txn
, attrCounter
, typeAttr
, from
, to
) );
1702 void wxMacMLTEControl::SetFont( const wxFont
& font
, const wxColour
& foreground
, long windowStyle
)
1704 wxMacEditHelper
help(m_txn
) ;
1705 TXNSetAttribute( wxTextAttr(foreground
,wxNullColour
,font
) , kTXNStartOffset
,kTXNEndOffset
) ;
1707 void wxMacMLTEControl::SetStyle(long start
, long end
, const wxTextAttr
& style
)
1709 wxMacEditHelper
help(m_txn
) ;
1710 TXNSetAttribute( style
, start
,end
) ;
1713 void wxMacMLTEControl::Copy()
1715 ClearCurrentScrap();
1717 TXNConvertToPublicScrap();
1720 void wxMacMLTEControl::Cut()
1722 ClearCurrentScrap();
1724 TXNConvertToPublicScrap();
1727 void wxMacMLTEControl::Paste()
1729 TXNConvertFromPublicScrap();
1733 bool wxMacMLTEControl::CanPaste() const
1735 return TXNIsScrapPastable() ;
1738 void wxMacMLTEControl::SetEditable(bool editable
)
1740 TXNControlTag tag
[] = { kTXNIOPrivilegesTag
} ;
1741 TXNControlData data
[] = { { editable
? kTXNReadWrite
: kTXNReadOnly
} } ;
1742 TXNSetTXNObjectControls( m_txn
, false , WXSIZEOF(tag
) , tag
, data
) ;
1745 wxTextPos
wxMacMLTEControl::GetLastPosition() const
1747 wxTextPos actualsize
= 0 ;
1750 OSErr err
= TXNGetDataEncoded( m_txn
, kTXNStartOffset
, kTXNEndOffset
, &theText
, kTXNTextData
);
1758 actualsize
= GetHandleSize( theText
) ;
1759 DisposeHandle( theText
) ;
1765 void wxMacMLTEControl::Replace( long from
, long to
, const wxString
&str
)
1767 wxString value
= str
;
1768 wxMacConvertNewlines10To13( &value
) ;
1770 wxMacEditHelper
help( m_txn
) ;
1771 wxMacWindowClipper
c( m_peer
) ;
1773 TXNSetSelection(m_txn
, from
, to
) ;
1775 SetTXNData( value
, kTXNUseCurrentSelection
, kTXNUseCurrentSelection
) ;
1778 void wxMacMLTEControl::Remove( long from
, long to
)
1780 wxMacWindowClipper
c( m_peer
) ;
1781 wxMacEditHelper
help( m_txn
) ;
1782 TXNSetSelection(m_txn
, from
, to
) ;
1786 void wxMacMLTEControl::GetSelection( long* from
, long* to
) const
1788 TXNGetSelection( m_txn
, (TXNOffset
*) from
, (TXNOffset
*) to
) ;
1791 void wxMacMLTEControl::SetSelection( long from
, long to
)
1793 wxMacWindowClipper
c( m_peer
) ;
1794 /* change the selection */
1795 if ((from
== -1) && (to
== -1))
1796 TXNSelectAll(m_txn
);
1798 TXNSetSelection( m_txn
, from
, to
);
1799 TXNShowSelection( m_txn
, kTXNShowStart
);
1802 void wxMacMLTEControl::WriteText(const wxString
& str
)
1805 wxMacConvertNewlines10To13( &st
) ;
1807 long start
, end
, dummy
;
1808 GetSelection( &start
, &dummy
) ;
1809 wxMacWindowClipper
c( m_peer
) ;
1811 wxMacEditHelper
helper( m_txn
) ;
1812 SetTXNData( st
, kTXNUseCurrentSelection
, kTXNUseCurrentSelection
) ;
1814 GetSelection( &dummy
, &end
) ;
1815 // TODO SetStyle( start , end , GetDefaultStyle() ) ;
1818 void wxMacMLTEControl::Clear()
1820 wxMacWindowClipper
c( m_peer
) ;
1821 wxMacEditHelper
st(m_txn
) ;
1822 TXNSetSelection( m_txn
, kTXNStartOffset
, kTXNEndOffset
) ;
1826 bool wxMacMLTEControl::CanUndo() const
1828 return TXNCanUndo( m_txn
, NULL
) ;
1831 void wxMacMLTEControl::Undo()
1836 bool wxMacMLTEControl::CanRedo() const
1838 return TXNCanRedo( m_txn
, NULL
) ;
1841 void wxMacMLTEControl::Redo()
1846 int wxMacMLTEControl::GetNumberOfLines() const
1848 ItemCount lines
= 0 ;
1849 TXNGetLineCount(m_txn
, &lines
) ;
1853 long wxMacMLTEControl::XYToPosition(long x
, long y
) const
1857 wxTextPos lastpos
= GetLastPosition() ;
1859 // TODO find a better implementation : while we can get the
1860 // line metrics of a certain line, we don't get its starting
1861 // position, so it would probably be rather a binary search
1862 // for the start position
1865 int lastHeight
= 0 ;
1868 for ( n
= 0 ; n
<= (ItemCount
) lastpos
; ++n
)
1870 if ( y
== ypos
&& x
== xpos
)
1873 TXNOffsetToPoint( m_txn
, n
, &curpt
);
1875 if ( curpt
.v
> lastHeight
)
1880 lastHeight
= curpt
.v
;
1888 bool wxMacMLTEControl::PositionToXY(long pos
, long *x
, long *y
) const
1892 wxTextPos lastpos
= GetLastPosition() ;
1897 if ( pos
<= lastpos
)
1899 // TODO find a better implementation : while we can get the
1900 // line metrics of a certain line, we don't get its starting
1901 // position, so it would probably be rather a binary search
1902 // for the start position
1905 int lastHeight
= 0 ;
1908 for ( n
= 0 ; n
<= (ItemCount
) pos
; ++n
)
1910 TXNOffsetToPoint(m_txn
, n
, &curpt
);
1912 if ( curpt
.v
> lastHeight
)
1917 lastHeight
= curpt
.v
;
1922 if ( y
) *y
= ypos
;
1923 if ( x
) *x
= xpos
;
1929 void wxMacMLTEControl::ShowPosition( long pos
)
1931 #if TARGET_RT_MAC_MACHO && defined(AVAILABLE_MAC_OS_X_VERSION_10_2_AND_LATER)
1935 TXNOffset selstart
, selend
;
1936 TXNGetSelection( m_txn
, &selstart
, &selend
) ;
1937 TXNOffsetToPoint( m_txn
, selstart
, ¤t
);
1938 TXNOffsetToPoint( m_txn
, pos
, &desired
);
1939 //TODO use HIPoints for 10.3 and above
1940 if ( (UInt32
) TXNScroll
!= (UInt32
) kUnresolvedCFragSymbolAddress
)
1942 OSErr theErr
= noErr
;
1943 SInt32 dv
= desired
.v
- current
.v
;
1944 SInt32 dh
= desired
.h
- current
.h
;
1945 TXNShowSelection( m_txn
, true ) ;
1946 theErr
= TXNScroll( m_txn
, kTXNScrollUnitsInPixels
, kTXNScrollUnitsInPixels
, &dv
, &dh
);
1947 // there will be an error returned for classic mlte implementation when the control is
1948 // invisible, but HITextView works correctly, so we don't assert that one
1949 // wxASSERT_MSG( theErr == noErr, _T("TXNScroll returned an error!") );
1955 void wxMacMLTEControl::SetTXNData( const wxString
& st
, TXNOffset start
, TXNOffset end
)
1958 #if SIZEOF_WCHAR_T == 2
1959 size_t len
= st
.Len() ;
1960 TXNSetData( m_txn
, kTXNUnicodeTextData
, (void*)st
.wc_str(), len
* 2,
1963 wxMBConvUTF16 converter
;
1964 ByteCount byteBufferLen
= converter
.WC2MB( NULL
, st
.wc_str() , 0 ) ;
1965 UniChar
*unibuf
= (UniChar
*) malloc(byteBufferLen
) ;
1966 converter
.WC2MB( (char*) unibuf
, st
.wc_str() , byteBufferLen
) ;
1967 TXNSetData( m_txn
, kTXNUnicodeTextData
, (void*)unibuf
, byteBufferLen
,
1972 wxCharBuffer text
= st
.mb_str(wxConvLocal
) ;
1973 TXNSetData( m_txn
, kTXNTextData
, (void*)text
.data(), strlen( text
) ,
1979 wxString
wxMacMLTEControl::GetLineText(long lineNo
) const
1983 if ( lineNo
< GetNumberOfLines() )
1991 // get the first possible position in the control
1993 TXNOffsetToPoint(m_txn
, 0, &firstPoint
);
1995 // Iterate through the lines until we reach the one we want,
1996 // adding to our current y pixel point position
1997 while (ypos
< lineNo
)
1999 TXNGetLineMetrics(m_txn
, ypos
++, &lineWidth
, &lineHeight
);
2000 currentHeight
+= lineHeight
;
2003 Point thePoint
= { firstPoint
.v
+ (currentHeight
>> 16), firstPoint
.h
+ (0) };
2004 TXNOffset theOffset
;
2005 TXNPointToOffset(m_txn
, thePoint
, &theOffset
);
2007 wxString content
= GetStringValue() ;
2008 Point currentPoint
= thePoint
;
2009 while(thePoint
.v
== currentPoint
.v
&& theOffset
< content
.length())
2011 line
+= content
[theOffset
];
2012 TXNOffsetToPoint(m_txn
, ++theOffset
, ¤tPoint
);
2018 int wxMacMLTEControl::GetLineLength(long lineNo
) const
2022 if ( lineNo
< GetNumberOfLines() )
2030 // get the first possible position in the control
2032 TXNOffsetToPoint(m_txn
, 0, &firstPoint
);
2034 // Iterate through the lines until we reach the one we want,
2035 // adding to our current y pixel point position
2036 while (ypos
< lineNo
)
2038 TXNGetLineMetrics(m_txn
, ypos
++, &lineWidth
, &lineHeight
);
2039 currentHeight
+= lineHeight
;
2042 Point thePoint
= { firstPoint
.v
+ (currentHeight
>> 16), firstPoint
.h
+ (0) };
2043 TXNOffset theOffset
;
2044 TXNPointToOffset(m_txn
, thePoint
, &theOffset
);
2046 wxString content
= GetStringValue() ;
2047 Point currentPoint
= thePoint
;
2048 while(thePoint
.v
== currentPoint
.v
&& theOffset
< content
.length())
2051 TXNOffsetToPoint(m_txn
, ++theOffset
, ¤tPoint
);
2058 // ----------------------------------------------------------------------------
2059 // MLTE control implementation (classic part)
2060 // ----------------------------------------------------------------------------
2062 // OS X Notes : We still don't have a full replacement for MLTE, so this implementation
2063 // has to live on. We have different problems coming from outdated implementations on the
2064 // various OS X versions. Most deal with the scrollbars: they are not correctly embedded
2065 // while this can be solved on 10.3 by reassigning them the correct place, on 10.2 there is
2066 // no way out, therefore we are using our own implementation and our own scrollbars ....
2068 #ifdef __WXMAC_OSX__
2070 TXNScrollInfoUPP gTXNScrollInfoProc
= NULL
;
2071 ControlActionUPP gTXNScrollActionProc
= NULL
;
2073 pascal void wxMacMLTEClassicControl::TXNScrollInfoProc (SInt32 iValue
, SInt32 iMaximumValue
, TXNScrollBarOrientation
2074 iScrollBarOrientation
, SInt32 iRefCon
)
2076 wxMacMLTEClassicControl
* mlte
= (wxMacMLTEClassicControl
*) iRefCon
;
2077 SInt32 value
= wxMax( iValue
, 0 ) ;
2078 SInt32 maximum
= wxMax( iMaximumValue
, 0 ) ;
2080 if ( iScrollBarOrientation
== kTXNHorizontal
)
2082 if ( mlte
->m_sbHorizontal
)
2084 SetControl32BitValue( mlte
->m_sbHorizontal
, value
) ;
2085 SetControl32BitMaximum( mlte
->m_sbHorizontal
, maximum
) ;
2086 mlte
->m_lastHorizontalValue
= value
;
2089 else if ( iScrollBarOrientation
== kTXNVertical
)
2091 if ( mlte
->m_sbVertical
)
2093 SetControl32BitValue( mlte
->m_sbVertical
, value
) ;
2094 SetControl32BitMaximum( mlte
->m_sbVertical
, maximum
) ;
2095 mlte
->m_lastVerticalValue
= value
;
2100 pascal void wxMacMLTEClassicControl::TXNScrollActionProc( ControlRef controlRef
, ControlPartCode partCode
)
2103 wxMacMLTEClassicControl
* mlte
= (wxMacMLTEClassicControl
*) GetControlReference( controlRef
) ;
2107 if ( controlRef
!= mlte
->m_sbVertical
&& controlRef
!= mlte
->m_sbHorizontal
)
2110 bool isHorizontal
= ( controlRef
== mlte
->m_sbHorizontal
) ;
2112 SInt32 minimum
= 0 ;
2113 SInt32 maximum
= GetControl32BitMaximum( controlRef
) ;
2114 SInt32 value
= GetControl32BitValue( controlRef
) ;
2118 case kControlDownButtonPart
:
2121 case kControlUpButtonPart
:
2124 case kControlPageDownPart
:
2125 delta
= GetControlViewSize( controlRef
) ;
2127 case kControlPageUpPart
:
2128 delta
= -GetControlViewSize( controlRef
) ;
2130 case kControlIndicatorPart
:
2132 ( isHorizontal
? mlte
->m_lastHorizontalValue
: mlte
->m_lastVerticalValue
) ;
2139 SInt32 newValue
= value
;
2141 if ( partCode
!= kControlIndicatorPart
)
2143 if( value
+ delta
< minimum
)
2144 delta
= minimum
- value
;
2145 if ( value
+ delta
> maximum
)
2146 delta
= maximum
- value
;
2148 SetControl32BitValue( controlRef
, value
+ delta
) ;
2149 newValue
= value
+ delta
;
2152 SInt32 verticalDelta
= isHorizontal
? 0 : delta
;
2153 SInt32 horizontalDelta
= isHorizontal
? delta
: 0 ;
2155 err
= TXNScroll( mlte
->m_txn
, kTXNScrollUnitsInPixels
, kTXNScrollUnitsInPixels
,
2156 &verticalDelta
, &horizontalDelta
);
2159 mlte
->m_lastHorizontalValue
= newValue
;
2161 mlte
->m_lastVerticalValue
= newValue
;
2166 // make correct activations
2167 void wxMacMLTEClassicControl::MacActivatePaneText(Boolean setActive
)
2169 wxTextCtrl
* textctrl
= (wxTextCtrl
*) GetControlReference(m_controlRef
);
2171 wxMacWindowClipper
clipper( textctrl
) ;
2172 TXNActivate(m_txn
, m_txnFrameID
, setActive
);
2174 ControlRef controlFocus
= 0 ;
2175 GetKeyboardFocus( m_txnWindow
, &controlFocus
) ;
2176 if ( controlFocus
== m_controlRef
)
2177 TXNFocus( m_txn
, setActive
);
2180 void wxMacMLTEClassicControl::MacFocusPaneText(Boolean setFocus
)
2182 TXNFocus( m_txn
, setFocus
);
2185 // guards against inappropriate redraw (hidden objects drawing onto window)
2187 void wxMacMLTEClassicControl::MacSetObjectVisibility(Boolean vis
)
2189 ControlRef controlFocus
= 0 ;
2190 GetKeyboardFocus( m_txnWindow
, &controlFocus
) ;
2192 if ( controlFocus
== m_controlRef
&& vis
== false )
2194 SetKeyboardFocus( m_txnWindow
, m_controlRef
, kControlFocusNoPart
) ;
2197 TXNControlTag iControlTags
[1] = { kTXNVisibilityTag
};
2198 TXNControlData iControlData
[1] = { {(UInt32
) false } };
2200 verify_noerr( TXNGetTXNObjectControls( m_txn
, 1,
2201 iControlTags
, iControlData
) ) ;
2203 if ( iControlData
[0].uValue
!= vis
)
2205 iControlData
[0].uValue
= vis
;
2206 verify_noerr( TXNSetTXNObjectControls( m_txn
, false , 1,
2207 iControlTags
, iControlData
)) ;
2209 // we right now are always clipping as partial visibility (overlapped) visibility
2210 // is also a problem, if we run into further problems we might set the FrameBounds to an empty
2214 // make sure that the TXNObject is at the right position
2216 void wxMacMLTEClassicControl::MacUpdatePosition()
2218 wxTextCtrl
* textctrl
= (wxTextCtrl
*) GetControlReference(m_controlRef
);
2219 if ( textctrl
== NULL
)
2223 UMAGetControlBoundsInWindowCoords(m_controlRef
, &bounds
);
2225 wxRect visRect
= textctrl
->MacGetClippedClientRect() ;
2226 Rect visBounds
= { visRect
.y
, visRect
.x
, visRect
.y
+ visRect
.height
, visRect
.x
+ visRect
.width
} ;
2229 textctrl
->MacWindowToRootWindow( &x
, &y
) ;
2230 OffsetRect( &visBounds
, x
, y
) ;
2232 if ( !EqualRect( &bounds
, &m_txnControlBounds
) || !EqualRect( &visBounds
, &m_txnVisBounds
) )
2234 m_txnControlBounds
= bounds
;
2235 m_txnVisBounds
= visBounds
;
2236 wxMacWindowClipper
cl(textctrl
) ;
2238 #ifdef __WXMAC_OSX__
2239 bool isCompositing
= textctrl
->MacGetTopLevelWindow()->MacUsesCompositing() ;
2240 if ( m_sbHorizontal
|| m_sbVertical
)
2242 int w
= bounds
.right
- bounds
.left
;
2243 int h
= bounds
.bottom
- bounds
.top
;
2245 if ( m_sbHorizontal
)
2249 sbBounds
.left
= -1 ;
2250 sbBounds
.top
= h
- 14 ;
2251 sbBounds
.right
= w
+ 1 ;
2252 sbBounds
.bottom
= h
+ 1 ;
2254 if ( !isCompositing
)
2255 OffsetRect( &sbBounds
, m_txnControlBounds
.left
, m_txnControlBounds
.top
) ;
2257 SetControlBounds( m_sbHorizontal
, &sbBounds
) ;
2258 SetControlViewSize( m_sbHorizontal
, w
) ;
2264 sbBounds
.left
= w
- 14 ;
2266 sbBounds
.right
= w
+ 1 ;
2267 sbBounds
.bottom
= m_sbHorizontal
? h
- 14 : h
+ 1 ;
2269 if ( !isCompositing
)
2270 OffsetRect( &sbBounds
, m_txnControlBounds
.left
, m_txnControlBounds
.top
) ;
2272 SetControlBounds( m_sbVertical
, &sbBounds
) ;
2273 SetControlViewSize( m_sbVertical
, h
) ;
2278 TXNLongRect olddestRect
;
2279 TXNGetRectBounds( m_txn
, &oldviewRect
, &olddestRect
, NULL
) ;
2281 Rect viewRect
= { m_txnControlBounds
.top
, m_txnControlBounds
.left
,
2282 m_txnControlBounds
.bottom
- ( m_sbHorizontal
? 14 : 0 ) , m_txnControlBounds
.right
- ( m_sbVertical
? 14 : 0 ) } ;
2283 TXNLongRect destRect
= { m_txnControlBounds
.top
, m_txnControlBounds
.left
,
2284 m_txnControlBounds
.bottom
- ( m_sbHorizontal
? 14 : 0 ) , m_txnControlBounds
.right
- ( m_sbVertical
? 14 : 0 ) } ;
2286 if ( olddestRect
.right
>= 10000 )
2287 destRect
.right
= destRect
.left
+ 32000 ;
2289 if ( olddestRect
.bottom
>= 0x20000000 )
2290 destRect
.bottom
= destRect
.top
+ 0x40000000 ;
2292 SectRect( &viewRect
, &visBounds
, &viewRect
) ;
2293 TXNSetRectBounds( m_txn
, &viewRect
, &destRect
, true ) ;
2295 TXNSetFrameBounds( m_txn, m_txnControlBounds.top, m_txnControlBounds.left,
2296 m_txnControlBounds.bottom - ( m_sbHorizontal ? 14 : 0 ) , m_txnControlBounds.right - ( m_sbVertical ? 14 : 0 ), m_txnFrameID);
2300 TXNSetFrameBounds( m_txn
, m_txnControlBounds
.top
, m_txnControlBounds
.left
,
2301 wxMax( m_txnControlBounds
.bottom
, m_txnControlBounds
.top
) ,
2302 wxMax( m_txnControlBounds
.right
, m_txnControlBounds
.left
) , m_txnFrameID
);
2304 // the SetFrameBounds method unter classic sometimes does not correctly scroll a selection into sight after a
2305 // movement, therefore we have to force it
2307 // according to David Surovell this problem also sometimes occurs under OSX, so we use this as well
2309 TXNLongRect textRect
;
2310 TXNGetRectBounds( m_txn
, NULL
, NULL
, &textRect
) ;
2311 if ( textRect
.left
< m_txnControlBounds
.left
)
2313 TXNShowSelection( m_txn
, false ) ;
2318 void wxMacMLTEClassicControl::SetRect( Rect
*r
)
2320 wxMacControl::SetRect( r
) ;
2321 MacUpdatePosition() ;
2324 void wxMacMLTEClassicControl::MacControlUserPaneDrawProc(wxInt16 thePart
)
2326 wxTextCtrl
* textctrl
= (wxTextCtrl
*) GetControlReference(m_controlRef
);
2327 if ( textctrl
== NULL
)
2330 if ( textctrl
->MacIsReallyShown() )
2332 wxMacWindowClipper
clipper( textctrl
) ;
2333 TXNDraw( m_txn
, NULL
) ;
2337 wxInt16
wxMacMLTEClassicControl::MacControlUserPaneHitTestProc(wxInt16 x
, wxInt16 y
)
2339 Point where
= { y
, x
} ;
2340 ControlPartCode result
;
2343 wxTextCtrl
* textctrl
= (wxTextCtrl
*) GetControlReference(m_controlRef
);
2344 if ( textctrl
== NULL
)
2347 if (textctrl
->MacIsReallyShown() )
2349 if (PtInRect(where
, &m_txnControlBounds
))
2350 result
= kControlEditTextPart
;
2353 // sometimes we get the coords also in control local coordinates, therefore test again
2354 if ( textctrl
->MacGetTopLevelWindow()->MacUsesCompositing() )
2357 textctrl
->MacClientToRootWindow( &x
, &y
) ;
2361 if (PtInRect(where
, &m_txnControlBounds
))
2362 result
= kControlEditTextPart
;
2370 wxInt16
wxMacMLTEClassicControl::MacControlUserPaneTrackingProc( wxInt16 x
, wxInt16 y
, void* actionProc
)
2372 wxTextCtrl
* textctrl
= (wxTextCtrl
*) GetControlReference(m_controlRef
);
2373 if ( textctrl
== NULL
)
2376 ControlPartCode partCodeResult
= 0;
2378 if (textctrl
->MacIsReallyShown() )
2380 Point startPt
= { y
,x
} ;
2381 // for compositing, we must convert these into toplevel window coordinates, because hittesting expects them
2382 if ( textctrl
->MacGetTopLevelWindow()->MacUsesCompositing() )
2385 textctrl
->MacClientToRootWindow( &x
, &y
) ;
2390 switch (MacControlUserPaneHitTestProc( startPt
.h
, startPt
.v
))
2392 case kControlEditTextPart
:
2394 wxMacWindowClipper
clipper( textctrl
) ;
2397 ConvertEventRefToEventRecord( (EventRef
) wxTheApp
->MacGetCurrentEvent() , &rec
) ;
2398 TXNClick( m_txn
, &rec
);
2404 return partCodeResult
;
2407 void wxMacMLTEClassicControl::MacControlUserPaneIdleProc()
2409 wxTextCtrl
* textctrl
= (wxTextCtrl
*) GetControlReference(m_controlRef
);
2410 if ( textctrl
== NULL
)
2413 if (textctrl
->MacIsReallyShown())
2415 if (IsControlActive(m_controlRef
))
2419 wxMacWindowClipper
clipper( textctrl
) ;
2424 if (PtInRect(mousep
, &m_txnControlBounds
))
2427 RectRgn((theRgn
= NewRgn()), &m_txnControlBounds
);
2428 TXNAdjustCursor(m_txn
, theRgn
);
2435 wxInt16
wxMacMLTEClassicControl::MacControlUserPaneKeyDownProc (wxInt16 keyCode
, wxInt16 charCode
, wxInt16 modifiers
)
2437 wxTextCtrl
* textctrl
= (wxTextCtrl
*) GetControlReference(m_controlRef
);
2438 if ( textctrl
== NULL
)
2441 wxMacWindowClipper
clipper( textctrl
) ;
2444 memset( &ev
, 0 , sizeof( ev
) ) ;
2446 ev
.modifiers
= modifiers
;
2447 ev
.message
= (( keyCode
<< 8 ) & keyCodeMask
) + ( charCode
& charCodeMask
) ;
2448 TXNKeyDown( m_txn
, &ev
);
2450 return kControlEntireControl
;
2453 void wxMacMLTEClassicControl::MacControlUserPaneActivateProc( bool activating
)
2455 MacActivatePaneText( activating
);
2458 wxInt16
wxMacMLTEClassicControl::MacControlUserPaneFocusProc(wxInt16 action
)
2460 ControlPartCode focusResult
;
2462 focusResult
= kControlFocusNoPart
;
2463 wxTextCtrl
* textctrl
= (wxTextCtrl
*) GetControlReference(m_controlRef
);
2464 if ( textctrl
== NULL
)
2467 wxMacWindowClipper
clipper( textctrl
) ;
2469 ControlRef controlFocus
= 0 ;
2470 GetKeyboardFocus( m_txnWindow
, &controlFocus
) ;
2471 bool wasFocused
= ( controlFocus
== m_controlRef
) ;
2475 case kControlFocusPrevPart
:
2476 case kControlFocusNextPart
:
2477 MacFocusPaneText( ( !wasFocused
));
2478 focusResult
= (!wasFocused
) ? (ControlPartCode
) kControlEditTextPart
: (ControlPartCode
) kControlFocusNoPart
;
2481 case kControlFocusNoPart
:
2483 MacFocusPaneText( false);
2484 focusResult
= kControlFocusNoPart
;
2491 void wxMacMLTEClassicControl::MacControlUserPaneBackgroundProc( void *info
)
2495 wxMacMLTEClassicControl::wxMacMLTEClassicControl( wxTextCtrl
*wxPeer
,
2496 const wxString
& str
,
2498 const wxSize
& size
, long style
) : wxMacMLTEControl( wxPeer
)
2500 m_font
= wxPeer
->GetFont() ;
2501 m_windowStyle
= style
;
2502 Rect bounds
= wxMacGetBoundsForControl( wxPeer
, pos
, size
) ;
2506 featurSet
= kControlSupportsEmbedding
| kControlSupportsFocus
| kControlWantsIdle
2507 | kControlWantsActivate
| kControlHandlesTracking
// | kControlHasSpecialBackground
2508 | kControlGetsFocusOnClick
| kControlSupportsLiveFeedback
;
2510 verify_noerr( ::CreateUserPaneControl( MAC_WXHWND(wxPeer
->GetParent()->MacGetTopLevelWindowRef()), &bounds
, featurSet
, &m_controlRef
) );
2514 AdjustCreationAttributes( *wxWHITE
, true) ;
2516 MacSetObjectVisibility( wxPeer
->MacIsReallyShown() ) ;
2520 wxMacConvertNewlines10To13( &st
) ;
2521 wxMacWindowClipper
clipper( m_peer
) ;
2522 SetTXNData( st
, kTXNStartOffset
, kTXNEndOffset
) ;
2523 TXNSetSelection( m_txn
, 0, 0);
2527 wxMacMLTEClassicControl::~wxMacMLTEClassicControl()
2529 TXNDeleteObject(m_txn
);
2533 void wxMacMLTEClassicControl::VisibilityChanged(bool shown
)
2535 MacSetObjectVisibility( shown
) ;
2536 wxMacControl::VisibilityChanged( shown
) ;
2539 void wxMacMLTEClassicControl::SuperChangedPosition()
2541 MacUpdatePosition() ;
2542 wxMacControl::SuperChangedPosition() ;
2545 #ifdef __WXMAC_OSX__
2547 ControlUserPaneDrawUPP gTPDrawProc
= NULL
;
2548 ControlUserPaneHitTestUPP gTPHitProc
= NULL
;
2549 ControlUserPaneTrackingUPP gTPTrackProc
= NULL
;
2550 ControlUserPaneIdleUPP gTPIdleProc
= NULL
;
2551 ControlUserPaneKeyDownUPP gTPKeyProc
= NULL
;
2552 ControlUserPaneActivateUPP gTPActivateProc
= NULL
;
2553 ControlUserPaneFocusUPP gTPFocusProc
= NULL
;
2555 static pascal void wxMacControlUserPaneDrawProc(ControlRef control
, SInt16 part
)
2557 wxTextCtrl
*textCtrl
= wxDynamicCast( wxFindControlFromMacControl(control
) , wxTextCtrl
) ;
2558 wxMacMLTEClassicControl
* win
= textCtrl
? (wxMacMLTEClassicControl
*)(textCtrl
->GetPeer()) : NULL
;
2560 win
->MacControlUserPaneDrawProc(part
) ;
2563 static pascal ControlPartCode
wxMacControlUserPaneHitTestProc(ControlRef control
, Point where
)
2565 wxTextCtrl
*textCtrl
= wxDynamicCast( wxFindControlFromMacControl(control
) , wxTextCtrl
) ;
2566 wxMacMLTEClassicControl
* win
= textCtrl
? (wxMacMLTEClassicControl
*)(textCtrl
->GetPeer()) : NULL
;
2568 return win
->MacControlUserPaneHitTestProc(where
.h
, where
.v
) ;
2570 return kControlNoPart
;
2573 static pascal ControlPartCode
wxMacControlUserPaneTrackingProc(ControlRef control
, Point startPt
, ControlActionUPP actionProc
)
2575 wxTextCtrl
*textCtrl
= wxDynamicCast( wxFindControlFromMacControl(control
) , wxTextCtrl
) ;
2576 wxMacMLTEClassicControl
* win
= textCtrl
? (wxMacMLTEClassicControl
*)(textCtrl
->GetPeer()) : NULL
;
2578 return win
->MacControlUserPaneTrackingProc( startPt
.h
, startPt
.v
, (void*) actionProc
) ;
2580 return kControlNoPart
;
2583 static pascal void wxMacControlUserPaneIdleProc(ControlRef control
)
2585 wxTextCtrl
*textCtrl
= wxDynamicCast( wxFindControlFromMacControl(control
) , wxTextCtrl
) ;
2586 wxMacMLTEClassicControl
* win
= textCtrl
? (wxMacMLTEClassicControl
*)(textCtrl
->GetPeer()) : NULL
;
2588 win
->MacControlUserPaneIdleProc() ;
2591 static pascal ControlPartCode
wxMacControlUserPaneKeyDownProc(ControlRef control
, SInt16 keyCode
, SInt16 charCode
, SInt16 modifiers
)
2593 wxTextCtrl
*textCtrl
= wxDynamicCast( wxFindControlFromMacControl(control
) , wxTextCtrl
) ;
2594 wxMacMLTEClassicControl
* win
= textCtrl
? (wxMacMLTEClassicControl
*)(textCtrl
->GetPeer()) : NULL
;
2596 return win
->MacControlUserPaneKeyDownProc(keyCode
,charCode
,modifiers
) ;
2598 return kControlNoPart
;
2601 static pascal void wxMacControlUserPaneActivateProc(ControlRef control
, Boolean activating
)
2603 wxTextCtrl
*textCtrl
= wxDynamicCast( wxFindControlFromMacControl(control
) , wxTextCtrl
) ;
2604 wxMacMLTEClassicControl
* win
= textCtrl
? (wxMacMLTEClassicControl
*)(textCtrl
->GetPeer()) : NULL
;
2606 win
->MacControlUserPaneActivateProc(activating
) ;
2609 static pascal ControlPartCode
wxMacControlUserPaneFocusProc(ControlRef control
, ControlFocusPart action
)
2611 wxTextCtrl
*textCtrl
= wxDynamicCast( wxFindControlFromMacControl(control
) , wxTextCtrl
) ;
2612 wxMacMLTEClassicControl
* win
= textCtrl
? (wxMacMLTEClassicControl
*)(textCtrl
->GetPeer()) : NULL
;
2614 return win
->MacControlUserPaneFocusProc(action
) ;
2616 return kControlNoPart
;
2620 static pascal void wxMacControlUserPaneBackgroundProc(ControlRef control, ControlBackgroundPtr info)
2622 wxTextCtrl *textCtrl = wxDynamicCast( wxFindControlFromMacControl(control) , wxTextCtrl ) ;
2623 wxMacMLTEClassicControl * win = textCtrl ? (wxMacMLTEClassicControl*)(textCtrl->GetPeer()) : NULL ;
2625 win->MacControlUserPaneBackgroundProc(info) ;
2630 // TXNRegisterScrollInfoProc
2632 OSStatus
wxMacMLTEClassicControl::DoCreate()
2636 OSStatus err
= noErr
;
2638 /* set up our globals */
2639 #ifdef __WXMAC_OSX__
2640 if (gTPDrawProc
== NULL
) gTPDrawProc
= NewControlUserPaneDrawUPP(wxMacControlUserPaneDrawProc
);
2641 if (gTPHitProc
== NULL
) gTPHitProc
= NewControlUserPaneHitTestUPP(wxMacControlUserPaneHitTestProc
);
2642 if (gTPTrackProc
== NULL
) gTPTrackProc
= NewControlUserPaneTrackingUPP(wxMacControlUserPaneTrackingProc
);
2643 if (gTPIdleProc
== NULL
) gTPIdleProc
= NewControlUserPaneIdleUPP(wxMacControlUserPaneIdleProc
);
2644 if (gTPKeyProc
== NULL
) gTPKeyProc
= NewControlUserPaneKeyDownUPP(wxMacControlUserPaneKeyDownProc
);
2645 if (gTPActivateProc
== NULL
) gTPActivateProc
= NewControlUserPaneActivateUPP(wxMacControlUserPaneActivateProc
);
2646 if (gTPFocusProc
== NULL
) gTPFocusProc
= NewControlUserPaneFocusUPP(wxMacControlUserPaneFocusProc
);
2648 if (gTXNScrollInfoProc
== NULL
) gTXNScrollInfoProc
= NewTXNScrollInfoUPP(TXNScrollInfoProc
) ;
2649 if (gTXNScrollActionProc
== NULL
) gTXNScrollActionProc
= NewControlActionUPP(TXNScrollActionProc
) ;
2652 /* set the initial settings for our private data */
2654 m_txnWindow
=GetControlOwner(m_controlRef
);
2655 m_txnPort
= (GrafPtr
) GetWindowPort(m_txnWindow
);
2657 #ifdef __WXMAC_OSX__
2658 /* set up the user pane procedures */
2659 SetControlData(m_controlRef
, kControlEntireControl
, kControlUserPaneDrawProcTag
, sizeof(gTPDrawProc
), &gTPDrawProc
);
2660 SetControlData(m_controlRef
, kControlEntireControl
, kControlUserPaneHitTestProcTag
, sizeof(gTPHitProc
), &gTPHitProc
);
2661 SetControlData(m_controlRef
, kControlEntireControl
, kControlUserPaneTrackingProcTag
, sizeof(gTPTrackProc
), &gTPTrackProc
);
2662 SetControlData(m_controlRef
, kControlEntireControl
, kControlUserPaneIdleProcTag
, sizeof(gTPIdleProc
), &gTPIdleProc
);
2663 SetControlData(m_controlRef
, kControlEntireControl
, kControlUserPaneKeyDownProcTag
, sizeof(gTPKeyProc
), &gTPKeyProc
);
2664 SetControlData(m_controlRef
, kControlEntireControl
, kControlUserPaneActivateProcTag
, sizeof(gTPActivateProc
), &gTPActivateProc
);
2665 SetControlData(m_controlRef
, kControlEntireControl
, kControlUserPaneFocusProcTag
, sizeof(gTPFocusProc
), &gTPFocusProc
);
2667 /* calculate the rectangles used by the control */
2668 UMAGetControlBoundsInWindowCoords(m_controlRef
, &bounds
);
2670 m_txnControlBounds
= bounds
;
2671 m_txnVisBounds
= bounds
;
2673 CGrafPtr origPort
= NULL
;
2674 GDHandle origDev
= NULL
;
2675 GetGWorld( &origPort
, &origDev
) ;
2678 /* create the new edit field */
2680 TXNFrameOptions frameOptions
= FrameOptionsFromWXStyle( m_windowStyle
) ;
2682 #ifdef __WXMAC_OSX__
2684 // the scrollbars are not correctly embedded but are inserted at the root
2685 // this gives us problems as we have erratic redraws even over the structure
2688 m_sbHorizontal
= 0 ;
2690 m_lastHorizontalValue
= 0 ;
2691 m_lastVerticalValue
= 0 ;
2693 Rect sb
= { 0 , 0 , 0 , 0 } ;
2694 if ( frameOptions
& kTXNWantVScrollBarMask
)
2696 CreateScrollBarControl( m_txnWindow
, &sb
, 0 , 0 , 100 , 1 , true , gTXNScrollActionProc
, &m_sbVertical
) ;
2697 SetControlReference( m_sbVertical
, (SInt32
) this ) ;
2698 SetControlAction( m_sbVertical
, gTXNScrollActionProc
);
2699 ShowControl( m_sbVertical
) ;
2700 EmbedControl( m_sbVertical
, m_controlRef
) ;
2701 frameOptions
&= ~kTXNWantVScrollBarMask
;
2703 if ( frameOptions
& kTXNWantHScrollBarMask
)
2705 CreateScrollBarControl( m_txnWindow
, &sb
, 0 , 0 , 100 , 1 , true , gTXNScrollActionProc
, &m_sbHorizontal
) ;
2706 SetControlReference( m_sbHorizontal
, (SInt32
) this ) ;
2707 SetControlAction( m_sbHorizontal
, gTXNScrollActionProc
);
2708 ShowControl( m_sbHorizontal
) ;
2709 EmbedControl( m_sbHorizontal
, m_controlRef
) ;
2710 frameOptions
&= ~(kTXNWantHScrollBarMask
| kTXNDrawGrowIconMask
);
2715 verify_noerr(TXNNewObject(NULL
, m_txnWindow
, &bounds
,
2717 kTXNTextEditStyleFrameType
,
2719 kTXNSystemDefaultEncoding
,
2720 &m_txn
, &m_txnFrameID
, NULL
) );
2722 TXNCarbonEventInfo cInfo ;
2724 cInfo.useCarbonEvents = false ;
2727 cInfo.fDictionary = NULL ;
2729 TXNControlTag iControlTags[] =
2731 kTXNUseCarbonEvents ,
2733 TXNControlData iControlData[] =
2738 int toptag = WXSIZEOF( iControlTags ) ;
2740 verify_noerr( TXNSetTXNObjectControls( m_txn, false , toptag,
2741 iControlTags, iControlData )) ;
2744 #ifdef __WXMAC_OSX__
2745 TXNRegisterScrollInfoProc( m_txn
, gTXNScrollInfoProc
, (SInt32
) this);
2748 SetGWorld( origPort
, origDev
) ;
2752 // ----------------------------------------------------------------------------
2753 // MLTE control implementation (OSX part)
2754 // ----------------------------------------------------------------------------
2756 #if TARGET_API_MAC_OSX
2758 #if MAC_OS_X_VERSION_MAX_ALLOWED > MAC_OS_X_VERSION_10_2
2760 wxMacMLTEHIViewControl::wxMacMLTEHIViewControl( wxTextCtrl
*wxPeer
,
2761 const wxString
& str
,
2763 const wxSize
& size
, long style
) : wxMacMLTEControl( wxPeer
)
2765 m_font
= wxPeer
->GetFont() ;
2766 m_windowStyle
= style
;
2767 Rect bounds
= wxMacGetBoundsForControl( wxPeer
, pos
, size
) ;
2769 wxMacConvertNewlines10To13( &st
) ;
2771 HIRect hr
= { { bounds
.left
, bounds
.top
} ,
2772 { bounds
.right
- bounds
.left
, bounds
.bottom
- bounds
.top
} } ;
2774 m_scrollView
= NULL
;
2775 TXNFrameOptions frameOptions
= FrameOptionsFromWXStyle( style
) ;
2776 if ( frameOptions
& (kTXNWantVScrollBarMask
|kTXNWantHScrollBarMask
) )
2778 HIScrollViewCreate(( frameOptions
& kTXNWantHScrollBarMask
? kHIScrollViewOptionsHorizScroll
: 0) |
2779 ( frameOptions
& kTXNWantVScrollBarMask
? kHIScrollViewOptionsVertScroll
: 0 ) , &m_scrollView
) ;
2781 HIViewSetFrame( m_scrollView
, &hr
);
2782 HIViewSetVisible( m_scrollView
, true );
2786 HITextViewCreate( NULL
, 0, frameOptions
, &m_textView
) ;
2787 m_txn
= HITextViewGetTXNObject( m_textView
) ;
2788 HIViewSetVisible( m_textView
, true ) ;
2791 HIViewAddSubview( m_scrollView
, m_textView
) ;
2792 m_controlRef
= m_scrollView
;
2793 wxPeer
->MacInstallEventHandler( (WXWidget
) m_textView
) ;
2797 HIViewSetFrame( m_textView
, &hr
);
2798 m_controlRef
= m_textView
;
2801 AdjustCreationAttributes( *wxWHITE
, true ) ;
2803 wxMacWindowClipper
c( m_peer
) ;
2804 SetTXNData( st
, kTXNStartOffset
, kTXNEndOffset
) ;
2806 TXNSetSelection( m_txn
, 0, 0);
2807 TXNShowSelection( m_txn
, kTXNShowStart
);
2811 OSStatus
wxMacMLTEHIViewControl::SetFocus( ControlFocusPart focusPart
)
2813 return SetKeyboardFocus( GetControlOwner( m_textView
) ,
2814 m_textView
, focusPart
) ;
2817 bool wxMacMLTEHIViewControl::HasFocus() const
2819 ControlRef control
;
2820 GetKeyboardFocus( GetUserFocusWindow() , &control
) ;
2821 return control
== m_textView
;
2824 #if MAC_OS_X_VERSION_MAX_ALLOWED < MAC_OS_X_VERSION_10_4
2825 #define kCGColorSpaceGenericRGB CFSTR("kCGColorSpaceGenericRGB")
2828 void wxMacMLTEHIViewControl::SetBackground( const wxBrush
&brush
)
2830 wxMacMLTEControl::SetBackground( brush
) ;
2832 CGColorSpaceRef rgbSpace = CGColorSpaceCreateDeviceRGB();
2833 RGBColor col = MAC_WXCOLORREF(brush.GetColour().GetPixel()) ;
2835 float component[4] ;
2836 component[0] = col.red / 65536.0 ;
2837 component[1] = col.green / 65536.0 ;
2838 component[2] = col.blue / 65536.0 ;
2839 component[3] = 1.0 ; // alpha
2841 CGColorRef color = CGColorCreate (rgbSpace , component );
2842 HITextViewSetBackgroundColor( m_textView , color ) ;
2843 CGColorSpaceRelease( rgbSpace );
2847 #endif // MAC_OS_X_VERSION_MAX_ALLOWED > MAC_OS_X_VERSION_10_2
2852 #endif // wxUSE_TEXTCTRL