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 #if defined(__GNUG__) && !defined(NO_GCC_PRAGMA)
13 #pragma implementation "textctrl.h"
16 #include "wx/wxprec.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
68 kTXNVisibilityTag
= 'visb' /*set the visibility state of the object */
72 #include <MacTextEditor.h>
73 #include <ATSUnicode.h>
74 #include <TextCommon.h>
75 #include <TextEncodingConverter.h>
76 #include "wx/mac/uma.h"
82 virtual ~wxMacFunctor() {}
83 virtual void* operator()() = 0 ;
84 static void* CallBackProc(void *param
)
86 wxMacFunctor
* f
= (wxMacFunctor
*) param
;
87 void *result
= (*f
)() ;
92 template<typename classtype
,typename param1type
>
93 class wxMacObjectFunctor1
: public wxMacFunctor
95 typedef void (classtype::*function
)( param1type p1
) ;
96 typedef void (classtype::*ref_function
)( const param1type
& p1
) ;
98 wxMacObjectFunctor1( classtype
*obj
, function f
, param1type p1
) :
106 wxMacObjectFunctor1( classtype
*obj
, ref_function f
, param1type p1
) :
114 ~wxMacObjectFunctor1() {}
116 virtual void* operator()()
118 (m_object
->*m_function
)(m_param1
) ;
122 classtype
* m_object
;
123 param1type m_param1
;
126 function m_function
;
127 ref_function m_refFunction
;
131 template<typename classtype
, typename param1type
>
132 void* wxMacMPRemoteCall( classtype
*object
, void (classtype::*function
)( param1type p1
) , param1type p1
)
134 wxMacObjectFunctor1
<classtype
,param1type
> params(object
,function
,p1
) ;
136 MPRemoteCall( wxMacFunctor::CallBackProc
, ¶ms
, kMPOwningProcessRemoteContext
) ;
140 template<typename classtype
, typename param1type
>
141 void* wxMacMPRemoteCall( classtype
*object
, void (classtype::*function
)( const param1type
& p1
) , param1type p1
)
143 wxMacObjectFunctor1
<classtype
,param1type
> params(object
,function
,p1
) ;
145 MPRemoteCall( wxMacFunctor::CallBackProc
, ¶ms
, kMPOwningProcessRemoteContext
) ;
149 template<typename classtype
, typename param1type
>
150 void* wxMacMPRemoteGUICall( classtype
*object
, void (classtype::*function
)( param1type p1
) , param1type p1
)
153 void *result
= wxMacMPRemoteCall( object
, function
, p1
) ;
158 template<typename classtype
, typename param1type
>
159 void* wxMacMPRemoteGUICall( classtype
*object
, void (classtype::*function
)( const param1type
& p1
) , param1type p1
)
162 void *result
= wxMacMPRemoteCall( object
, function
, p1
) ;
166 // common interface for all implementations
167 class wxMacTextControl
: public wxMacControl
170 wxMacTextControl( wxTextCtrl
*peer
) ;
171 ~wxMacTextControl() ;
173 virtual wxString
GetStringValue() const = 0 ;
174 virtual void SetStringValue( const wxString
&val
) = 0 ;
175 virtual void SetStyle(long start
, long end
, const wxTextAttr
& style
) ;
176 virtual void Copy() ;
178 virtual void Paste() ;
179 virtual bool CanPaste() const ;
180 virtual void SetEditable(bool editable
) ;
181 virtual wxTextPos
GetLastPosition() const ;
182 virtual void Replace( long from
, long to
, const wxString str
) ;
183 virtual void Remove( long from
, long to
) = 0 ;
184 virtual void SetSelection( long from
, long to
) = 0 ;
185 virtual void GetSelection( long* from
, long* to
) const = 0 ;
186 virtual void WriteText(const wxString
& str
) = 0 ;
188 virtual void Clear() ;
189 virtual bool CanUndo() const;
190 virtual void Undo() ;
191 virtual bool CanRedo() const;
192 virtual void Redo() ;
193 virtual int GetNumberOfLines() const ;
194 virtual long XYToPosition(long x
, long y
) const;
195 virtual bool PositionToXY(long pos
, long *x
, long *y
) const ;
196 virtual void ShowPosition( long WXUNUSED(pos
) ) ;
197 virtual int GetLineLength(long lineNo
) const ;
198 virtual wxString
GetLineText(long lineNo
) const ;
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
) : wxMacTextControl( 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 bool NeedsFocusRect() const;
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 Remove( long from
, long to
) ;
299 virtual void GetSelection( long* from
, long* to
) const ;
300 virtual void SetSelection( long from
, long to
) ;
301 virtual void WriteText(const wxString
& str
) ;
303 // contains the tag for the content (is different for password and non-password controls)
309 // 'classic' MLTE implementation
311 class wxMacMLTEClassicControl
: public wxMacMLTEControl
314 wxMacMLTEClassicControl( wxTextCtrl
*wxPeer
,
317 const wxSize
& size
, long style
) ;
318 ~wxMacMLTEClassicControl() ;
319 virtual void VisibilityChanged(bool shown
) ;
320 virtual void SuperChangedPosition() ;
321 virtual bool NeedsFocusRect() const;
323 virtual void MacControlUserPaneDrawProc(wxInt16 part
) ;
324 virtual wxInt16
MacControlUserPaneHitTestProc(wxInt16 x
, wxInt16 y
) ;
325 virtual wxInt16
MacControlUserPaneTrackingProc(wxInt16 x
, wxInt16 y
, void* actionProc
) ;
326 virtual void MacControlUserPaneIdleProc() ;
327 virtual wxInt16
MacControlUserPaneKeyDownProc(wxInt16 keyCode
, wxInt16 charCode
, wxInt16 modifiers
) ;
328 virtual void MacControlUserPaneActivateProc(bool activating
) ;
329 virtual wxInt16
MacControlUserPaneFocusProc(wxInt16 action
) ;
330 virtual void MacControlUserPaneBackgroundProc(void* info
) ;
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
;
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 #if !USE_SHARED_LIBRARY
363 IMPLEMENT_DYNAMIC_CLASS(wxTextCtrl
, wxControl
)
365 BEGIN_EVENT_TABLE(wxTextCtrl
, wxControl
)
366 EVT_ERASE_BACKGROUND( wxTextCtrl::OnEraseBackground
)
367 EVT_DROP_FILES(wxTextCtrl::OnDropFiles
)
368 EVT_CHAR(wxTextCtrl::OnChar
)
369 EVT_MENU(wxID_CUT
, wxTextCtrl::OnCut
)
370 EVT_MENU(wxID_COPY
, wxTextCtrl::OnCopy
)
371 EVT_MENU(wxID_PASTE
, wxTextCtrl::OnPaste
)
372 EVT_MENU(wxID_UNDO
, wxTextCtrl::OnUndo
)
373 EVT_MENU(wxID_REDO
, wxTextCtrl::OnRedo
)
375 EVT_UPDATE_UI(wxID_CUT
, wxTextCtrl::OnUpdateCut
)
376 EVT_UPDATE_UI(wxID_COPY
, wxTextCtrl::OnUpdateCopy
)
377 EVT_UPDATE_UI(wxID_PASTE
, wxTextCtrl::OnUpdatePaste
)
378 EVT_UPDATE_UI(wxID_UNDO
, wxTextCtrl::OnUpdateUndo
)
379 EVT_UPDATE_UI(wxID_REDO
, wxTextCtrl::OnUpdateRedo
)
384 void wxTextCtrl::Init()
389 m_maxLength
= TE_UNLIMITED_LENGTH
;
392 wxTextCtrl::~wxTextCtrl()
397 bool wxTextCtrl::Create(wxWindow
*parent
, wxWindowID id
,
400 const wxSize
& size
, long style
,
401 const wxValidator
& validator
,
402 const wxString
& name
)
404 m_macIsUserPane
= false ;
407 if ( ! ( style
& wxNO_BORDER
) )
408 style
= ( style
& ~wxBORDER_MASK
) | wxSUNKEN_BORDER
;
410 if ( !wxTextCtrlBase::Create(parent
, id
, pos
, size
, style
& ~(wxHSCROLL
|wxVSCROLL
), validator
, name
) )
413 Rect bounds
= wxMacGetBoundsForControl( this , pos
, size
) ;
415 if ( m_windowStyle
& wxTE_MULTILINE
)
417 wxASSERT_MSG( !(m_windowStyle
& wxTE_PROCESS_ENTER
),
418 wxT("wxTE_PROCESS_ENTER style is ignored for multiline text controls (they always process it)") );
420 m_windowStyle
|= wxTE_PROCESS_ENTER
;
421 style
|= wxTE_PROCESS_ENTER
;
425 #if MAC_OS_X_VERSION_MAX_ALLOWED > MAC_OS_X_VERSION_10_2
426 if ( UMAGetSystemVersion() >= 0x1050 )
428 m_peer
= new wxMacMLTEHIViewControl( this , str
, pos
, size
, style
) ;
431 #if !wxMAC_AWAYS_USE_MLTE
434 m_peer
= new wxMacUnicodeTextControl( this , str
, pos
, size
, style
) ;
440 m_peer
= new wxMacMLTEClassicControl( this , str
, pos
, size
, style
) ;
443 MacPostControlCreate(pos
,size
) ;
445 if ( m_windowStyle
& wxTE_READONLY
)
447 SetEditable( false ) ;
453 void wxTextCtrl::MacSuperChangedPosition()
455 wxWindow::MacSuperChangedPosition() ;
456 GetPeer()->SuperChangedPosition() ;
459 void wxTextCtrl::MacVisibilityChanged()
461 GetPeer()->VisibilityChanged( MacIsReallyShown() ) ;
464 void wxTextCtrl::MacEnabledStateChanged()
468 wxString
wxTextCtrl::GetValue() const
470 return GetPeer()->GetStringValue() ;
473 void wxTextCtrl::GetSelection(long* from
, long* to
) const
475 GetPeer()->GetSelection( from
, to
) ;
478 void wxTextCtrl::SetValue(const wxString
& str
)
481 if ( GetValue() == str
)
484 GetPeer()->SetStringValue(str
) ;
486 wxCommandEvent
event(wxEVT_COMMAND_TEXT_UPDATED
, m_windowId
);
487 event
.SetString( GetValue() ) ;
488 event
.SetEventObject( this );
489 GetEventHandler()->ProcessEvent(event
);
492 void wxTextCtrl::SetMaxLength(unsigned long len
)
497 bool wxTextCtrl::SetFont( const wxFont
& font
)
499 if ( !wxTextCtrlBase::SetFont( font
) )
502 GetPeer()->SetFont( font
, GetForegroundColour() , GetWindowStyle() ) ;
506 bool wxTextCtrl::SetStyle(long start
, long end
, const wxTextAttr
& style
)
508 GetPeer()->SetStyle( start
, end
, style
) ;
512 bool wxTextCtrl::SetDefaultStyle(const wxTextAttr
& style
)
514 wxTextCtrlBase::SetDefaultStyle( style
) ;
515 SetStyle( kTXNUseCurrentSelection
, kTXNUseCurrentSelection
, GetDefaultStyle() ) ;
519 // Clipboard operations
520 void wxTextCtrl::Copy()
528 void wxTextCtrl::Cut()
534 wxCommandEvent
event(wxEVT_COMMAND_TEXT_UPDATED
, m_windowId
);
535 event
.SetEventObject( this );
536 GetEventHandler()->ProcessEvent(event
);
540 void wxTextCtrl::Paste()
545 // eventually we should add setting the default style again
547 wxCommandEvent
event(wxEVT_COMMAND_TEXT_UPDATED
, m_windowId
);
548 event
.SetEventObject( this );
549 GetEventHandler()->ProcessEvent(event
);
553 bool wxTextCtrl::CanCopy() const
555 // Can copy if there's a selection
557 GetSelection(& from
, & to
);
561 bool wxTextCtrl::CanCut() const
567 // Can cut if there's a selection
569 GetSelection(& from
, & to
);
573 bool wxTextCtrl::CanPaste() const
578 return GetPeer()->CanPaste() ;
581 void wxTextCtrl::SetEditable(bool editable
)
583 if ( editable
!= m_editable
)
585 m_editable
= editable
;
586 GetPeer()->SetEditable( editable
) ;
590 void wxTextCtrl::SetInsertionPoint(long pos
)
592 SetSelection( pos
, pos
) ;
595 void wxTextCtrl::SetInsertionPointEnd()
597 wxTextPos pos
= GetLastPosition();
598 SetInsertionPoint(pos
);
601 long wxTextCtrl::GetInsertionPoint() const
604 GetSelection( &begin
, &end
) ;
608 wxTextPos
wxTextCtrl::GetLastPosition() const
610 return GetPeer()->GetLastPosition( ) ;
613 void wxTextCtrl::Replace(long from
, long to
, const wxString
& str
)
615 GetPeer()->Replace( from
, to
, str
) ;
618 void wxTextCtrl::Remove(long from
, long to
)
620 GetPeer()->Remove( from
, to
) ;
623 void wxTextCtrl::SetSelection(long from
, long to
)
625 GetPeer()->SetSelection( from
, to
) ;
628 bool wxTextCtrl::LoadFile(const wxString
& file
)
630 if ( wxTextCtrlBase::LoadFile(file
) )
638 void wxTextCtrl::WriteText(const wxString
& str
)
640 // TODO this MPRemoting will be moved into a remoting peer proxy for any command
641 if ( !wxIsMainThread() )
643 // unfortunately CW 8 is not able to correctly deduce the template types, so we have
644 // to instantiate explicitely
645 wxMacMPRemoteGUICall
<wxTextCtrl
,wxString
>( this , &wxTextCtrl::WriteText
, str
) ;
650 GetPeer()->WriteText( str
) ;
654 void wxTextCtrl::AppendText(const wxString
& text
)
656 SetInsertionPointEnd();
660 void wxTextCtrl::Clear()
665 bool wxTextCtrl::IsModified() const
670 bool wxTextCtrl::IsEditable() const
672 return IsEnabled() && m_editable
;
675 bool wxTextCtrl::AcceptsFocus() const
677 // we don't want focus if we can't be edited
678 return /*IsEditable() && */ wxControl::AcceptsFocus();
681 wxSize
wxTextCtrl::DoGetBestSize() const
687 // these are the numbers from the HIG, we reduce them by the borders
690 switch( m_windowVariant
)
692 case wxWINDOW_VARIANT_NORMAL
:
695 case wxWINDOW_VARIANT_SMALL
:
698 case wxWINDOW_VARIANT_MINI
:
706 // as the above numbers have some free space around the text
707 // we get 5 lines like this anyway
708 if ( m_windowStyle
& wxTE_MULTILINE
)
713 if ( !HasFlag(wxNO_BORDER
) )
716 return wxSize(wText
, hText
);
719 // ----------------------------------------------------------------------------
721 // ----------------------------------------------------------------------------
723 void wxTextCtrl::Undo()
731 void wxTextCtrl::Redo()
739 bool wxTextCtrl::CanUndo() const
745 return GetPeer()->CanUndo() ;
748 bool wxTextCtrl::CanRedo() const
754 return GetPeer()->CanRedo() ;
757 void wxTextCtrl::MarkDirty()
762 void wxTextCtrl::DiscardEdits()
767 int wxTextCtrl::GetNumberOfLines() const
769 return GetPeer()->GetNumberOfLines() ;
772 long wxTextCtrl::XYToPosition(long x
, long y
) const
774 return GetPeer()->XYToPosition( x
, y
) ;
777 bool wxTextCtrl::PositionToXY(long pos
, long *x
, long *y
) const
779 return GetPeer()->PositionToXY(pos
, x
, y
) ;
782 void wxTextCtrl::ShowPosition(long pos
)
784 return GetPeer()->ShowPosition(pos
) ;
787 int wxTextCtrl::GetLineLength(long lineNo
) const
789 return GetPeer()->GetLineLength(lineNo
) ;
792 wxString
wxTextCtrl::GetLineText(long lineNo
) const
794 return GetPeer()->GetLineText(lineNo
) ;
801 void wxTextCtrl::Command(wxCommandEvent
& event
)
803 SetValue (event
.GetString());
804 ProcessCommand (event
);
807 void wxTextCtrl::OnDropFiles(wxDropFilesEvent
& event
)
809 // By default, load the first file into the text window.
810 if (event
.GetNumberOfFiles() > 0)
812 LoadFile(event
.GetFiles()[0]);
816 void wxTextCtrl::OnEraseBackground(wxEraseEvent
& event
)
818 // all erasing should be done by the real mac control implementation
819 // while this is true for MLTE under classic, the HITextView is somehow
820 // transparent but background erase is not working correctly, so intercept
821 // things while we can...
825 void wxTextCtrl::OnChar(wxKeyEvent
& event
)
827 int key
= event
.GetKeyCode() ;
828 bool eat_key
= false ;
830 if ( key
== 'c' && event
.MetaDown() )
837 if ( !IsEditable() && key
!= WXK_LEFT
&& key
!= WXK_RIGHT
&& key
!= WXK_DOWN
&& key
!= WXK_UP
&& key
!= WXK_TAB
&&
838 !( key
== WXK_RETURN
&& ( (m_windowStyle
& wxPROCESS_ENTER
) || (m_windowStyle
& wxTE_MULTILINE
) ) )
839 /* && key != WXK_PRIOR && key != WXK_NEXT && key != WXK_HOME && key != WXK_END */
846 // Check if we have reached the max # of chars, but still allow navigation and deletion
847 if ( !IsMultiLine() && GetValue().Length() >= m_maxLength
&&
848 key
!= WXK_LEFT
&& key
!= WXK_RIGHT
&& key
!= WXK_TAB
&&
849 key
!= WXK_BACK
&& !( key
== WXK_RETURN
&& (m_windowStyle
& wxPROCESS_ENTER
) )
852 // eat it, we don't want to add more than allowed # of characters
856 // assume that any key not processed yet is going to modify the control
859 if ( key
== 'v' && event
.MetaDown() )
865 if ( key
== 'x' && event
.MetaDown() )
874 if (m_windowStyle
& wxPROCESS_ENTER
)
876 wxCommandEvent
event(wxEVT_COMMAND_TEXT_ENTER
, m_windowId
);
877 event
.SetEventObject( this );
878 event
.SetString( GetValue() );
879 if ( GetEventHandler()->ProcessEvent(event
) )
882 if ( !(m_windowStyle
& wxTE_MULTILINE
) )
884 wxWindow
*parent
= GetParent();
885 while( parent
&& !parent
->IsTopLevel() && parent
->GetDefaultItem() == NULL
) {
886 parent
= parent
->GetParent() ;
888 if ( parent
&& parent
->GetDefaultItem() )
890 wxButton
*def
= wxDynamicCast(parent
->GetDefaultItem(),
892 if ( def
&& def
->IsEnabled() )
894 wxCommandEvent
event(wxEVT_COMMAND_BUTTON_CLICKED
, def
->GetId() );
895 event
.SetEventObject(def
);
901 // this will make wxWidgets eat the ENTER key so that
902 // we actually prevent line wrapping in a single line
910 if ( !(m_windowStyle
& wxTE_PROCESS_TAB
))
913 if (!event
.ShiftDown())
914 flags
|= wxNavigationKeyEvent::IsForward
;
915 if (event
.ControlDown())
916 flags
|= wxNavigationKeyEvent::WinChange
;
922 // This is necessary (don't know why) or the tab will not
924 WriteText(wxT("\t"));
932 // perform keystroke handling
933 if ( wxTheApp
->MacGetCurrentEvent() != NULL
&& wxTheApp
->MacGetCurrentEventHandlerCallRef() != NULL
)
934 CallNextEventHandler((EventHandlerCallRef
)wxTheApp
->MacGetCurrentEventHandlerCallRef() , (EventRef
) wxTheApp
->MacGetCurrentEvent() ) ;
938 if ( wxMacConvertEventToRecord( (EventRef
) wxTheApp
->MacGetCurrentEvent() , &rec
) )
940 EventRecord
*ev
= &rec
;
943 keychar
= short(ev
->message
& charCodeMask
);
944 keycode
= short(ev
->message
& keyCodeMask
) >> 8 ;
946 m_peer
->HandleKey( keycode
, keychar
, ev
->modifiers
) ;
950 if ( ( key
>= 0x20 && key
< WXK_START
) ||
955 wxCommandEvent
event1(wxEVT_COMMAND_TEXT_UPDATED
, m_windowId
);
956 event1
.SetEventObject( this );
957 wxPostEvent(GetEventHandler(),event1
);
961 // ----------------------------------------------------------------------------
962 // standard handlers for standard edit menu events
963 // ----------------------------------------------------------------------------
965 void wxTextCtrl::OnCut(wxCommandEvent
& WXUNUSED(event
))
970 void wxTextCtrl::OnCopy(wxCommandEvent
& WXUNUSED(event
))
975 void wxTextCtrl::OnPaste(wxCommandEvent
& WXUNUSED(event
))
980 void wxTextCtrl::OnUndo(wxCommandEvent
& WXUNUSED(event
))
985 void wxTextCtrl::OnRedo(wxCommandEvent
& WXUNUSED(event
))
990 void wxTextCtrl::OnUpdateCut(wxUpdateUIEvent
& event
)
992 event
.Enable( CanCut() );
995 void wxTextCtrl::OnUpdateCopy(wxUpdateUIEvent
& event
)
997 event
.Enable( CanCopy() );
1000 void wxTextCtrl::OnUpdatePaste(wxUpdateUIEvent
& event
)
1002 event
.Enable( CanPaste() );
1005 void wxTextCtrl::OnUpdateUndo(wxUpdateUIEvent
& event
)
1007 event
.Enable( CanUndo() );
1010 void wxTextCtrl::OnUpdateRedo(wxUpdateUIEvent
& event
)
1012 event
.Enable( CanRedo() );
1015 bool wxTextCtrl::MacSetupCursor( const wxPoint
& pt
)
1019 #if !TARGET_API_MAC_OSX
1021 // user pane implementation
1023 void wxTextCtrl::MacControlUserPaneDrawProc(wxInt16 part
)
1025 GetPeer()->MacControlUserPaneDrawProc( part
) ;
1028 wxInt16
wxTextCtrl::MacControlUserPaneHitTestProc(wxInt16 x
, wxInt16 y
)
1030 return GetPeer()->MacControlUserPaneHitTestProc( x
, y
) ;
1033 wxInt16
wxTextCtrl::MacControlUserPaneTrackingProc(wxInt16 x
, wxInt16 y
, void* actionProc
)
1035 return GetPeer()->MacControlUserPaneTrackingProc( x
, y
, actionProc
) ;
1038 void wxTextCtrl::MacControlUserPaneIdleProc()
1040 GetPeer()->MacControlUserPaneIdleProc( ) ;
1043 wxInt16
wxTextCtrl::MacControlUserPaneKeyDownProc(wxInt16 keyCode
, wxInt16 charCode
, wxInt16 modifiers
)
1045 return GetPeer()->MacControlUserPaneKeyDownProc( keyCode
, charCode
, modifiers
) ;
1048 void wxTextCtrl::MacControlUserPaneActivateProc(bool activating
)
1050 GetPeer()->MacControlUserPaneActivateProc( activating
) ;
1053 wxInt16
wxTextCtrl::MacControlUserPaneFocusProc(wxInt16 action
)
1055 return GetPeer()->MacControlUserPaneFocusProc( action
) ;
1058 void wxTextCtrl::MacControlUserPaneBackgroundProc(void* info
)
1060 GetPeer()->MacControlUserPaneBackgroundProc( info
) ;
1064 // ----------------------------------------------------------------------------
1065 // implementation base class
1066 // ----------------------------------------------------------------------------
1068 wxMacTextControl::wxMacTextControl(wxTextCtrl
* peer
) :
1069 wxMacControl( peer
)
1073 wxMacTextControl::~wxMacTextControl()
1077 void wxMacTextControl::SetStyle(long start
, long end
, const wxTextAttr
& style
)
1081 void wxMacTextControl::Copy()
1085 void wxMacTextControl::Cut()
1089 void wxMacTextControl::Paste()
1093 bool wxMacTextControl::CanPaste() const
1098 void wxMacTextControl::SetEditable(bool editable
)
1102 wxTextPos
wxMacTextControl::GetLastPosition() const
1104 return GetStringValue().Length() ;
1107 void wxMacTextControl::Replace( long from
, long to
, const wxString str
)
1111 void wxMacTextControl::Clear()
1113 SetStringValue( wxEmptyString
) ;
1116 bool wxMacTextControl::CanUndo() const
1121 void wxMacTextControl::Undo() { }
1123 bool wxMacTextControl::CanRedo() const
1128 void wxMacTextControl::Redo()
1132 long wxMacTextControl::XYToPosition(long x
, long y
) const
1137 bool wxMacTextControl::PositionToXY(long pos
, long *x
, long *y
) const
1142 void wxMacTextControl::ShowPosition( long WXUNUSED(pos
) )
1146 int wxMacTextControl::GetNumberOfLines() const
1148 ItemCount lines
= 0 ;
1149 wxString content
= GetStringValue() ;
1151 for (size_t i
= 0; i
< content
.Length() ; i
++)
1153 if (content
[i
] == '\r') lines
++;
1158 wxString
wxMacTextControl::GetLineText(long lineNo
) const
1160 // TODO change this if possible to reflect real lines
1161 wxString content
= GetStringValue() ;
1165 for (size_t i
= 0; i
< content
.Length() ; i
++)
1167 if (count
== lineNo
)
1169 // Add chars in line then
1172 for (size_t j
= i
; j
< content
.Length(); j
++)
1174 if (content
[j
] == '\n')
1182 if (content
[i
] == '\n') count
++;
1184 return wxEmptyString
;
1187 int wxMacTextControl::GetLineLength(long lineNo
) const
1189 // TODO change this if possible to reflect real lines
1190 wxString content
= GetStringValue() ;
1194 for (size_t i
= 0; i
< content
.Length() ; i
++)
1196 if (count
== lineNo
)
1198 // Count chars in line then
1200 for (size_t j
= i
; j
< content
.Length(); j
++)
1203 if (content
[j
] == '\n') return count
;
1208 if (content
[i
] == '\n') count
++;
1213 // ----------------------------------------------------------------------------
1214 // standard unicode control implementation
1215 // ----------------------------------------------------------------------------
1217 #if TARGET_API_MAC_OSX
1219 wxMacUnicodeTextControl::wxMacUnicodeTextControl( wxTextCtrl
*wxPeer
,
1220 const wxString
& str
,
1222 const wxSize
& size
, long style
) : wxMacTextControl( wxPeer
)
1224 m_font
= wxPeer
->GetFont() ;
1225 m_windowStyle
= style
;
1226 Rect bounds
= wxMacGetBoundsForControl( wxPeer
, pos
, size
) ;
1228 wxMacConvertNewlines10To13( &st
) ;
1229 wxMacCFStringHolder
cf(st
, m_font
.GetEncoding()) ;
1230 CFStringRef cfr
= cf
;
1231 Boolean isPassword
= ( m_windowStyle
& wxTE_PASSWORD
) != 0 ;
1232 m_valueTag
= isPassword
? kControlEditTextPasswordCFStringTag
: kControlEditTextCFStringTag
;
1233 CreateEditUnicodeTextControl( MAC_WXHWND(wxPeer
->MacGetTopLevelWindowRef()), &bounds
, cfr
, isPassword
, NULL
, &m_controlRef
) ;
1235 if ( !(m_windowStyle
& wxTE_MULTILINE
) )
1237 SetData
<Boolean
>( kControlEditTextPart
, kControlEditTextSingleLineTag
, true ) ;
1241 wxMacUnicodeTextControl::~wxMacUnicodeTextControl()
1245 void wxMacUnicodeTextControl::VisibilityChanged(bool shown
)
1247 if ( !(m_windowStyle
& wxTE_MULTILINE
) && shown
)
1249 // work around a refresh issue insofar as not always the entire content is shown even if this would be possible
1250 ControlEditTextSelectionRec sel
;
1251 CFStringRef value
= NULL
;
1253 verify_noerr( GetData
<ControlEditTextSelectionRec
>( 0, kControlEditTextSelectionTag
, &sel
) );
1254 verify_noerr( GetData
<CFStringRef
>( 0, m_valueTag
, &value
) );
1255 verify_noerr( SetData
<CFStringRef
>( 0, m_valueTag
, &value
) );
1256 verify_noerr( SetData
<ControlEditTextSelectionRec
>( 0, kControlEditTextSelectionTag
, &sel
) );
1258 CFRelease( value
) ;
1261 wxString
wxMacUnicodeTextControl::GetStringValue() const
1264 CFStringRef value
= GetData
<CFStringRef
>(0,m_valueTag
) ;
1267 wxMacCFStringHolder
cf(value
) ;
1268 result
= cf
.AsString() ;
1271 wxMacConvertNewlines13To10( &result
) ;
1273 wxMacConvertNewlines10To13( &result
) ;
1277 void wxMacUnicodeTextControl::SetStringValue( const wxString
&str
)
1280 wxMacConvertNewlines10To13( &st
) ;
1281 wxMacCFStringHolder
cf(st
, m_font
.GetEncoding() ) ;
1282 verify_noerr( SetData
<CFStringRef
>( 0, m_valueTag
, cf
) ) ;
1284 void wxMacUnicodeTextControl::Copy()
1286 SendHICommand( kHICommandCopy
) ;
1288 void wxMacUnicodeTextControl::Cut()
1290 SendHICommand( kHICommandCut
) ;
1292 void wxMacUnicodeTextControl::Paste()
1294 SendHICommand( kHICommandPaste
) ;
1296 bool wxMacUnicodeTextControl::CanPaste() const
1300 void wxMacUnicodeTextControl::SetEditable(bool editable
)
1302 SetData
<Boolean
>( 0 , kControlEditTextLockedTag
, (Boolean
) !editable
) ;
1304 void wxMacUnicodeTextControl::Remove( long from
, long to
)
1308 void wxMacUnicodeTextControl::GetSelection( long* from
, long* to
) const
1310 ControlEditTextSelectionRec sel
;
1311 verify_noerr(GetData
<ControlEditTextSelectionRec
>( 0, kControlEditTextSelectionTag
, &sel
) ) ;
1312 if ( from
) *from
= sel
.selStart
;
1313 if ( to
) *to
= sel
.selEnd
;
1316 void wxMacUnicodeTextControl::SetSelection( long from
, long to
)
1318 ControlEditTextSelectionRec sel
;
1319 sel
.selStart
= from
;
1321 SetData
<ControlEditTextSelectionRec
>( 0 , kControlEditTextSelectionTag
, &sel
) ;
1324 void wxMacUnicodeTextControl::WriteText(const wxString
& str
)
1327 wxMacConvertNewlines10To13( &st
) ;
1328 #if MAC_OS_X_VERSION_MAX_ALLOWED > MAC_OS_X_VERSION_10_2
1329 wxMacCFStringHolder
cf(st
, m_font
.GetEncoding() ) ;
1330 CFStringRef value
= cf
;
1331 SetData
<CFStringRef
>( 0, kControlEditTextInsertCFStringRefTag
, &value
);
1333 wxString val
= GetStringValue() ;
1335 GetSelection( &start
, &end
) ;
1336 val
.Remove( start
, end
- start
) ;
1337 val
.insert( start
, str
) ;
1338 SetStringValue( val
) ;
1339 SetSelection( start
+ str
.Length() , start
+ str
.Length() ) ;
1345 // ----------------------------------------------------------------------------
1346 // MLTE control implementation (common part)
1347 // ----------------------------------------------------------------------------
1349 // if mlte is on read only , no changes at all are allowed, not even from
1350 // procedural API, in order to allow changes via API all the same we must undo
1351 // the readonly status while we are executing, this class helps to do so
1353 class wxMacEditHelper
1356 wxMacEditHelper( TXNObject txn
)
1358 TXNControlTag tag
[] = { kTXNIOPrivilegesTag
} ;
1360 TXNGetTXNObjectControls( m_txn
, 1 , tag
, m_data
) ;
1361 if ( m_data
[0].uValue
== kTXNReadOnly
)
1363 TXNControlData data
[] = { { kTXNReadWrite
} } ;
1364 TXNSetTXNObjectControls( m_txn
, false , 1 , tag
, data
) ;
1369 TXNControlTag tag
[] = { kTXNIOPrivilegesTag
} ;
1370 if ( m_data
[0].uValue
== kTXNReadOnly
)
1372 TXNSetTXNObjectControls( m_txn
, false , 1 , tag
, m_data
) ;
1377 TXNControlData m_data
[1] ;
1380 wxString
wxMacMLTEControl::GetStringValue() const
1384 Size actualSize
= 0;
1388 err
= TXNGetDataEncoded( m_txn
, kTXNStartOffset
, kTXNEndOffset
, &theText
, kTXNUnicodeTextData
);
1396 actualSize
= GetHandleSize( theText
) / sizeof( UniChar
) ;
1397 if ( actualSize
> 0 )
1399 wxChar
*ptr
= NULL
;
1400 #if SIZEOF_WCHAR_T == 2
1401 ptr
= new wxChar
[actualSize
+ 1 ] ;
1402 wxStrncpy( ptr
, (wxChar
*) *theText
, actualSize
) ;
1404 SetHandleSize( theText
, ( actualSize
+ 1 ) * sizeof( UniChar
) ) ;
1406 (((UniChar
*)*theText
)[actualSize
]) = 0 ;
1407 wxMBConvUTF16BE converter
;
1408 size_t noChars
= converter
.MB2WC( NULL
, (const char*)*theText
, 0 ) ;
1409 ptr
= new wxChar
[noChars
+ 1] ;
1411 noChars
= converter
.MB2WC( ptr
, (const char*)*theText
, noChars
) ;
1413 HUnlock( theText
) ;
1415 ptr
[actualSize
] = 0 ;
1416 result
= wxString( ptr
) ;
1419 DisposeHandle( theText
) ;
1423 err
= TXNGetDataEncoded( m_txn
, kTXNStartOffset
, kTXNEndOffset
, &theText
, kTXNTextData
);
1431 actualSize
= GetHandleSize( theText
) ;
1432 if ( actualSize
> 0 )
1435 result
= wxString( *theText
, wxConvLocal
, actualSize
) ;
1436 HUnlock( theText
) ;
1438 DisposeHandle( theText
) ;
1443 wxMacConvertNewlines13To10( &result
) ;
1445 wxMacConvertNewlines10To13( &result
) ;
1450 void wxMacMLTEControl::SetStringValue( const wxString
&str
)
1454 wxMacConvertNewlines10To13( &st
) ;
1456 wxMacWindowClipper
c( m_peer
) ;
1458 wxMacEditHelper
help(m_txn
) ;
1459 SetTXNData( st
, kTXNStartOffset
, kTXNEndOffset
) ;
1461 TXNSetSelection( m_txn
, 0, 0);
1462 TXNShowSelection( m_txn
, kTXNShowStart
);
1466 TXNFrameOptions
wxMacMLTEControl::FrameOptionsFromWXStyle( long wxStyle
)
1468 TXNFrameOptions frameOptions
=
1469 kTXNDontDrawCaretWhenInactiveMask
;
1471 if ( ! ( wxStyle
& wxTE_NOHIDESEL
) )
1472 frameOptions
|= kTXNDontDrawSelectionWhenInactiveMask
;
1474 if ( wxStyle
& wxTE_MULTILINE
)
1476 if ( ! ( wxStyle
& wxTE_DONTWRAP
) )
1477 frameOptions
|= kTXNAlwaysWrapAtViewEdgeMask
;
1480 frameOptions
|= kTXNAlwaysWrapAtViewEdgeMask
;
1481 frameOptions
|= kTXNWantHScrollBarMask
;
1484 if ( !(wxStyle
& wxTE_NO_VSCROLL
) )
1486 frameOptions
|= kTXNWantVScrollBarMask
;
1487 if ( frameOptions
& kTXNWantHScrollBarMask
)
1488 frameOptions
|= kTXNDrawGrowIconMask
;
1492 frameOptions
|= kTXNSingleLineOnlyMask
;
1494 if ( wxStyle
& wxHSCROLL
)
1495 frameOptions
|= kTXNWantHScrollBarMask
;
1497 return frameOptions
;
1500 void wxMacMLTEControl::AdjustCreationAttributes( const wxColour
&background
, bool visible
)
1502 TXNControlTag iControlTags
[] =
1504 kTXNDoFontSubstitution
,
1505 kTXNWordWrapStateTag
,
1507 TXNControlData iControlData
[] =
1513 int toptag
= WXSIZEOF( iControlTags
) ;
1515 if ( m_windowStyle
& wxTE_MULTILINE
)
1517 if (m_windowStyle
& wxTE_DONTWRAP
)
1518 iControlData
[1].uValue
= kTXNNoAutoWrap
;
1520 iControlData
[1].uValue
= kTXNAutoWrap
;
1522 verify_noerr( TXNSetTXNObjectControls( m_txn
, false, toptag
,
1523 iControlTags
, iControlData
)) ;
1525 // setting the default font
1531 GetThemeFont(kThemeSystemFont
, GetApplicationScript() , fontName
, &fontSize
, &fontStyle
) ;
1533 TXNTypeAttributes typeAttr
[] =
1535 { kTXNQDFontNameAttribute
, kTXNQDFontNameAttributeSize
, { (void*) fontName
} } ,
1536 { kTXNQDFontSizeAttribute
, kTXNFontSizeAttributeSize
, { (void*) (fontSize
<< 16) } } ,
1537 { kTXNQDFontStyleAttribute
, kTXNQDFontStyleAttributeSize
, { (void*) normal
} } ,
1540 verify_noerr( TXNSetTypeAttributes (m_txn
, sizeof( typeAttr
) / sizeof(TXNTypeAttributes
) , typeAttr
,
1544 if ( m_windowStyle
& wxTE_PASSWORD
)
1547 verify_noerr(TXNEchoMode( m_txn
, c
, 0 , true )) ;
1550 TXNBackground tback
;
1551 tback
.bgType
= kTXNBackgroundTypeRGB
;
1552 tback
.bg
.color
= MAC_WXCOLORREF( background
.GetPixel() );
1553 TXNSetBackground( m_txn
, &tback
);
1556 void wxMacMLTEControl::SetBackground( const wxBrush
&brush
)
1558 // currently only solid background are supported
1559 TXNBackground tback
;
1560 tback
.bgType
= kTXNBackgroundTypeRGB
;
1561 tback
.bg
.color
= MAC_WXCOLORREF( brush
.GetColour().GetPixel() );
1562 TXNSetBackground( m_txn
, &tback
);
1565 void wxMacMLTEControl::TXNSetAttribute( const wxTextAttr
& style
, long from
, long to
)
1567 TXNTypeAttributes typeAttr
[4] ;
1568 Str255 fontName
= "\pMonaco" ;
1569 SInt16 fontSize
= 12 ;
1570 Style fontStyle
= normal
;
1572 int attrCounter
= 0 ;
1573 if ( style
.HasFont() )
1575 const wxFont
&font
= style
.GetFont() ;
1576 wxMacStringToPascal( font
.GetFaceName() , fontName
) ;
1577 fontSize
= font
.GetPointSize() ;
1578 if ( font
.GetUnderlined() )
1579 fontStyle
|= underline
;
1580 if ( font
.GetWeight() == wxBOLD
)
1582 if ( font
.GetStyle() == wxITALIC
)
1583 fontStyle
|= italic
;
1585 typeAttr
[attrCounter
].tag
= kTXNQDFontNameAttribute
;
1586 typeAttr
[attrCounter
].size
= kTXNQDFontNameAttributeSize
;
1587 typeAttr
[attrCounter
].data
.dataPtr
= (void*) fontName
;
1588 typeAttr
[attrCounter
+1].tag
= kTXNQDFontSizeAttribute
;
1589 typeAttr
[attrCounter
+1].size
= kTXNFontSizeAttributeSize
;
1590 typeAttr
[attrCounter
+1].data
.dataValue
= (fontSize
<< 16) ;
1591 typeAttr
[attrCounter
+2].tag
= kTXNQDFontStyleAttribute
;
1592 typeAttr
[attrCounter
+2].size
= kTXNQDFontStyleAttributeSize
;
1593 typeAttr
[attrCounter
+2].data
.dataValue
= fontStyle
;
1596 if ( style
.HasTextColour() )
1598 typeAttr
[attrCounter
].tag
= kTXNQDFontColorAttribute
;
1599 typeAttr
[attrCounter
].size
= kTXNQDFontColorAttributeSize
;
1600 typeAttr
[attrCounter
].data
.dataPtr
= (void*) &color
;
1601 color
= MAC_WXCOLORREF(style
.GetTextColour().GetPixel()) ;
1604 if ( attrCounter
> 0 )
1606 verify_noerr( TXNSetTypeAttributes ( m_txn
, attrCounter
, typeAttr
, from
, to
) );
1610 void wxMacMLTEControl::SetFont( const wxFont
& font
, const wxColour
& foreground
, long windowStyle
)
1612 wxMacEditHelper
help(m_txn
) ;
1613 TXNSetAttribute( wxTextAttr(foreground
,wxNullColour
,font
) , kTXNStartOffset
,kTXNEndOffset
) ;
1615 void wxMacMLTEControl::SetStyle(long start
, long end
, const wxTextAttr
& style
)
1617 wxMacEditHelper
help(m_txn
) ;
1618 TXNSetAttribute( style
, start
,end
) ;
1621 void wxMacMLTEControl::Copy()
1623 ClearCurrentScrap();
1625 TXNConvertToPublicScrap();
1628 void wxMacMLTEControl::Cut()
1630 ClearCurrentScrap();
1632 TXNConvertToPublicScrap();
1635 void wxMacMLTEControl::Paste()
1637 TXNConvertFromPublicScrap();
1641 bool wxMacMLTEControl::CanPaste() const
1643 return TXNIsScrapPastable() ;
1646 void wxMacMLTEControl::SetEditable(bool editable
)
1648 TXNControlTag tag
[] = { kTXNIOPrivilegesTag
} ;
1649 TXNControlData data
[] = { { editable
? kTXNReadWrite
: kTXNReadOnly
} } ;
1650 TXNSetTXNObjectControls( m_txn
, false , WXSIZEOF(tag
) , tag
, data
) ;
1653 wxTextPos
wxMacMLTEControl::GetLastPosition() const
1655 wxTextPos actualsize
= 0 ;
1658 OSErr err
= TXNGetDataEncoded( m_txn
, kTXNStartOffset
, kTXNEndOffset
, &theText
, kTXNTextData
);
1666 actualsize
= GetHandleSize( theText
) ;
1667 DisposeHandle( theText
) ;
1673 void wxMacMLTEControl::Replace( long from
, long to
, const wxString str
)
1675 wxString value
= str
;
1676 wxMacConvertNewlines10To13( &value
) ;
1678 wxMacEditHelper
help( m_txn
) ;
1679 wxMacWindowClipper
c( m_peer
) ;
1681 TXNSetSelection(m_txn
, from
, to
) ;
1683 SetTXNData( value
, kTXNUseCurrentSelection
, kTXNUseCurrentSelection
) ;
1686 void wxMacMLTEControl::Remove( long from
, long to
)
1688 wxMacWindowClipper
c( m_peer
) ;
1689 wxMacEditHelper
help( m_txn
) ;
1690 TXNSetSelection(m_txn
, from
, to
) ;
1694 void wxMacMLTEControl::GetSelection( long* from
, long* to
) const
1696 TXNGetSelection( m_txn
, (TXNOffset
*) from
, (TXNOffset
*) to
) ;
1699 void wxMacMLTEControl::SetSelection( long from
, long to
)
1701 wxMacWindowClipper
c( m_peer
) ;
1702 /* change the selection */
1703 if ((from
== -1) && (to
== -1))
1704 TXNSelectAll(m_txn
);
1706 TXNSetSelection( m_txn
, from
, to
);
1707 TXNShowSelection( m_txn
, kTXNShowStart
);
1710 void wxMacMLTEControl::WriteText(const wxString
& str
)
1713 wxMacConvertNewlines10To13( &st
) ;
1715 long start
, end
, dummy
;
1716 GetSelection( &start
, &dummy
) ;
1717 wxMacWindowClipper
c( m_peer
) ;
1719 wxMacEditHelper
helper( m_txn
) ;
1720 SetTXNData( st
, kTXNUseCurrentSelection
, kTXNUseCurrentSelection
) ;
1722 GetSelection( &dummy
, &end
) ;
1723 // TODO SetStyle( start , end , GetDefaultStyle() ) ;
1726 void wxMacMLTEControl::Clear()
1728 wxMacWindowClipper
c( m_peer
) ;
1729 wxMacEditHelper
st(m_txn
) ;
1730 TXNSetSelection( m_txn
, kTXNStartOffset
, kTXNEndOffset
) ;
1734 bool wxMacMLTEControl::CanUndo() const
1736 return TXNCanUndo( m_txn
, NULL
) ;
1739 void wxMacMLTEControl::Undo()
1744 bool wxMacMLTEControl::CanRedo() const
1746 return TXNCanRedo( m_txn
, NULL
) ;
1749 void wxMacMLTEControl::Redo()
1754 int wxMacMLTEControl::GetNumberOfLines() const
1756 ItemCount lines
= 0 ;
1757 TXNGetLineCount(m_txn
, &lines
) ;
1761 long wxMacMLTEControl::XYToPosition(long x
, long y
) const
1765 wxTextPos lastpos
= GetLastPosition() ;
1767 // TODO find a better implementation : while we can get the
1768 // line metrics of a certain line, we don't get its starting
1769 // position, so it would probably be rather a binary search
1770 // for the start position
1773 int lastHeight
= 0 ;
1776 for ( n
= 0 ; n
<= (ItemCount
) lastpos
; ++n
)
1778 if ( y
== ypos
&& x
== xpos
)
1781 TXNOffsetToPoint( m_txn
, n
, &curpt
);
1783 if ( curpt
.v
> lastHeight
)
1788 lastHeight
= curpt
.v
;
1796 bool wxMacMLTEControl::PositionToXY(long pos
, long *x
, long *y
) const
1800 wxTextPos lastpos
= GetLastPosition() ;
1805 if ( pos
<= lastpos
)
1807 // TODO find a better implementation : while we can get the
1808 // line metrics of a certain line, we don't get its starting
1809 // position, so it would probably be rather a binary search
1810 // for the start position
1813 int lastHeight
= 0 ;
1816 for ( n
= 0 ; n
<= (ItemCount
) pos
; ++n
)
1818 TXNOffsetToPoint(m_txn
, n
, &curpt
);
1820 if ( curpt
.v
> lastHeight
)
1825 lastHeight
= curpt
.v
;
1830 if ( y
) *y
= ypos
;
1831 if ( x
) *x
= xpos
;
1837 void wxMacMLTEControl::ShowPosition( long pos
)
1839 #if TARGET_RT_MAC_MACHO && defined(AVAILABLE_MAC_OS_X_VERSION_10_2_AND_LATER)
1843 TXNOffset selstart
, selend
;
1844 TXNGetSelection( m_txn
, &selstart
, &selend
) ;
1845 TXNOffsetToPoint( m_txn
, selstart
, ¤t
);
1846 TXNOffsetToPoint( m_txn
, pos
, &desired
);
1847 //TODO use HIPoints for 10.3 and above
1848 if ( (UInt32
) TXNScroll
!= (UInt32
) kUnresolvedCFragSymbolAddress
)
1850 OSErr theErr
= noErr
;
1851 SInt32 dv
= desired
.v
- current
.v
;
1852 SInt32 dh
= desired
.h
- current
.h
;
1853 TXNShowSelection( m_txn
, true ) ;
1854 theErr
= TXNScroll( m_txn
, kTXNScrollUnitsInPixels
, kTXNScrollUnitsInPixels
, &dv
, &dh
);
1855 wxASSERT_MSG( theErr
== noErr
, _T("TXNScroll returned an error!") );
1861 void wxMacMLTEControl::SetTXNData( const wxString
& st
, TXNOffset start
, TXNOffset end
)
1864 #if SIZEOF_WCHAR_T == 2
1865 size_t len
= st
.Len() ;
1866 TXNSetData( m_txn
, kTXNUnicodeTextData
, (void*)st
.wc_str(), len
* 2,
1869 wxMBConvUTF16BE converter
;
1870 ByteCount byteBufferLen
= converter
.WC2MB( NULL
, st
.wc_str() , 0 ) ;
1871 UniChar
*unibuf
= (UniChar
*) malloc(byteBufferLen
) ;
1872 converter
.WC2MB( (char*) unibuf
, st
.wc_str() , byteBufferLen
) ;
1873 TXNSetData( m_txn
, kTXNUnicodeTextData
, (void*)unibuf
, byteBufferLen
,
1878 wxCharBuffer text
= st
.mb_str(wxConvLocal
) ;
1879 TXNSetData( m_txn
, kTXNTextData
, (void*)text
.data(), strlen( text
) ,
1885 wxString
wxMacMLTEControl::GetLineText(long lineNo
) const
1889 if ( lineNo
< GetNumberOfLines() )
1897 // get the first possible position in the control
1899 TXNOffsetToPoint(m_txn
, 0, &firstPoint
);
1901 // Iterate through the lines until we reach the one we want,
1902 // adding to our current y pixel point position
1903 while (ypos
< lineNo
)
1905 TXNGetLineMetrics(m_txn
, ypos
++, &lineWidth
, &lineHeight
);
1906 currentHeight
+= lineHeight
;
1909 Point thePoint
= { firstPoint
.v
+ (currentHeight
>> 16), firstPoint
.h
+ (0) };
1910 TXNOffset theOffset
;
1911 TXNPointToOffset(m_txn
, thePoint
, &theOffset
);
1913 wxString content
= GetStringValue() ;
1914 Point currentPoint
= thePoint
;
1915 while(thePoint
.v
== currentPoint
.v
&& theOffset
< content
.length())
1917 line
+= content
[theOffset
];
1918 TXNOffsetToPoint(m_txn
, ++theOffset
, ¤tPoint
);
1924 int wxMacMLTEControl::GetLineLength(long lineNo
) const
1928 if ( lineNo
< GetNumberOfLines() )
1936 // get the first possible position in the control
1938 TXNOffsetToPoint(m_txn
, 0, &firstPoint
);
1940 // Iterate through the lines until we reach the one we want,
1941 // adding to our current y pixel point position
1942 while (ypos
< lineNo
)
1944 TXNGetLineMetrics(m_txn
, ypos
++, &lineWidth
, &lineHeight
);
1945 currentHeight
+= lineHeight
;
1948 Point thePoint
= { firstPoint
.v
+ (currentHeight
>> 16), firstPoint
.h
+ (0) };
1949 TXNOffset theOffset
;
1950 TXNPointToOffset(m_txn
, thePoint
, &theOffset
);
1952 wxString content
= GetStringValue() ;
1953 Point currentPoint
= thePoint
;
1954 while(thePoint
.v
== currentPoint
.v
&& theOffset
< content
.length())
1957 TXNOffsetToPoint(m_txn
, ++theOffset
, ¤tPoint
);
1964 // ----------------------------------------------------------------------------
1965 // MLTE control implementation (classic part)
1966 // ----------------------------------------------------------------------------
1968 // OS X Notes : We still don't have a full replacement for MLTE, so this implementation
1969 // has to live on. We have different problems coming from outdated implementations on the
1970 // various OS X versions. Most deal with the scrollbars: they are not correctly embedded
1971 // while this can be solved on 10.3 by reassigning them the correct place, on 10.2 there is
1972 // no way out, therefore we are using our own implementation and our own scrollbars ....
1974 #ifdef __WXMAC_OSX__
1976 TXNScrollInfoUPP gTXNScrollInfoProc
= NULL
;
1977 ControlActionUPP gTXNScrollActionProc
= NULL
;
1979 pascal void wxMacMLTEClassicControl::TXNScrollInfoProc (SInt32 iValue
, SInt32 iMaximumValue
, TXNScrollBarOrientation
1980 iScrollBarOrientation
, SInt32 iRefCon
)
1982 wxMacMLTEClassicControl
* mlte
= (wxMacMLTEClassicControl
*) iRefCon
;
1983 SInt32 value
= wxMax( iValue
, 0 ) ;
1984 SInt32 maximum
= wxMax( iMaximumValue
, 0 ) ;
1986 if ( iScrollBarOrientation
== kTXNHorizontal
)
1988 if ( mlte
->m_sbHorizontal
)
1990 SetControl32BitValue( mlte
->m_sbHorizontal
, value
) ;
1991 SetControl32BitMaximum( mlte
->m_sbHorizontal
, maximum
) ;
1992 mlte
->m_lastHorizontalValue
= value
;
1995 else if ( iScrollBarOrientation
== kTXNVertical
)
1997 if ( mlte
->m_sbVertical
)
1999 SetControl32BitValue( mlte
->m_sbVertical
, value
) ;
2000 SetControl32BitMaximum( mlte
->m_sbVertical
, maximum
) ;
2001 mlte
->m_lastVerticalValue
= value
;
2006 pascal void wxMacMLTEClassicControl::TXNScrollActionProc( ControlRef controlRef
, ControlPartCode partCode
)
2009 wxMacMLTEClassicControl
* mlte
= (wxMacMLTEClassicControl
*) GetControlReference( controlRef
) ;
2013 if ( controlRef
!= mlte
->m_sbVertical
&& controlRef
!= mlte
->m_sbHorizontal
)
2016 bool isHorizontal
= ( controlRef
== mlte
->m_sbHorizontal
) ;
2018 SInt32 minimum
= 0 ;
2019 SInt32 maximum
= GetControl32BitMaximum( controlRef
) ;
2020 SInt32 value
= GetControl32BitValue( controlRef
) ;
2024 case kControlDownButtonPart
:
2027 case kControlUpButtonPart
:
2030 case kControlPageDownPart
:
2031 delta
= GetControlViewSize( controlRef
) ;
2033 case kControlPageUpPart
:
2034 delta
= -GetControlViewSize( controlRef
) ;
2036 case kControlIndicatorPart
:
2038 ( isHorizontal
? mlte
->m_lastHorizontalValue
: mlte
->m_lastVerticalValue
) ;
2045 SInt32 newValue
= value
;
2047 if ( partCode
!= kControlIndicatorPart
)
2049 if( value
+ delta
< minimum
)
2050 delta
= minimum
- value
;
2051 if ( value
+ delta
> maximum
)
2052 delta
= maximum
- value
;
2054 SetControl32BitValue( controlRef
, value
+ delta
) ;
2055 newValue
= value
+ delta
;
2058 SInt32 verticalDelta
= isHorizontal
? 0 : delta
;
2059 SInt32 horizontalDelta
= isHorizontal
? delta
: 0 ;
2061 err
= TXNScroll( mlte
->m_txn
, kTXNScrollUnitsInPixels
, kTXNScrollUnitsInPixels
,
2062 &verticalDelta
, &horizontalDelta
);
2065 mlte
->m_lastHorizontalValue
= newValue
;
2067 mlte
->m_lastVerticalValue
= newValue
;
2072 // make correct activations
2073 void wxMacMLTEClassicControl::MacActivatePaneText(Boolean setActive
)
2075 wxTextCtrl
* textctrl
= (wxTextCtrl
*) GetControlReference(m_controlRef
);
2077 wxMacWindowClipper
clipper( textctrl
) ;
2078 TXNActivate(m_txn
, m_txnFrameID
, setActive
);
2080 ControlRef controlFocus
= 0 ;
2081 GetKeyboardFocus( m_txnWindow
, &controlFocus
) ;
2082 if ( controlFocus
== m_controlRef
)
2083 TXNFocus( m_txn
, setActive
);
2086 void wxMacMLTEClassicControl::MacFocusPaneText(Boolean setFocus
)
2088 TXNFocus( m_txn
, setFocus
);
2091 // guards against inappropriate redraw (hidden objects drawing onto window)
2093 void wxMacMLTEClassicControl::MacSetObjectVisibility(Boolean vis
)
2096 // we right now are always clipping as partial visibility (overlapped) visibility
2097 // is also a problem, if we run into further problems we might set the FrameBounds to an empty
2101 // make sure that the TXNObject is at the right position
2103 void wxMacMLTEClassicControl::MacUpdatePosition()
2105 wxTextCtrl
* textctrl
= (wxTextCtrl
*) GetControlReference(m_controlRef
);
2106 if ( textctrl
== NULL
)
2110 UMAGetControlBoundsInWindowCoords(m_controlRef
, &bounds
);
2112 if ( !EqualRect( &bounds
, &m_txnControlBounds
) )
2115 Rect oldBounds
= m_txnControlBounds
;
2116 m_txnControlBounds
= bounds
;
2117 wxMacWindowClipper
cl(textctrl
) ;
2119 #ifdef __WXMAC_OSX__
2120 if ( m_sbHorizontal
|| m_sbVertical
)
2122 int w
= bounds
.right
- bounds
.left
;
2123 int h
= bounds
.bottom
- bounds
.top
;
2125 if ( m_sbHorizontal
)
2129 sbBounds
.left
= -1 ;
2130 sbBounds
.top
= h
- 14 ;
2131 sbBounds
.right
= w
+ 1 ;
2132 sbBounds
.bottom
= h
+ 1 ;
2133 SetControlBounds( m_sbHorizontal
, &sbBounds
) ;
2134 SetControlViewSize( m_sbHorizontal
, w
) ;
2140 sbBounds
.left
= w
- 14 ;
2142 sbBounds
.right
= w
+ 1 ;
2143 sbBounds
.bottom
= m_sbHorizontal
? h
- 14 : h
+ 1 ;
2145 SetControlBounds( m_sbVertical
, &sbBounds
) ;
2146 SetControlViewSize( m_sbVertical
, h
) ;
2149 TXNSetFrameBounds( m_txn
, m_txnControlBounds
.top
, m_txnControlBounds
.left
,
2150 m_txnControlBounds
.bottom
- ( m_sbHorizontal
? 14 : 0 ) , m_txnControlBounds
.right
- ( m_sbVertical
? 14 : 0 ), m_txnFrameID
);
2153 TXNSetFrameBounds( m_txn
, m_txnControlBounds
.top
, m_txnControlBounds
.left
,
2154 wxMax( m_txnControlBounds
.bottom
, m_txnControlBounds
.top
) ,
2155 wxMax( m_txnControlBounds
.right
, m_txnControlBounds
.left
) , m_txnFrameID
);
2157 // the SetFrameBounds method unter classic sometimes does not correctly scroll a selection into sight after a
2158 // movement, therefore we have to force it
2160 TXNLongRect textRect
;
2161 TXNGetRectBounds( m_txn
, NULL
, NULL
, &textRect
) ;
2162 if ( textRect
.left
< m_txnControlBounds
.left
)
2164 TXNShowSelection( m_txn
, false ) ;
2170 void wxMacMLTEClassicControl::SetRect( Rect
*r
)
2172 wxMacControl::SetRect( r
) ;
2173 MacUpdatePosition() ;
2176 void wxMacMLTEClassicControl::MacControlUserPaneDrawProc(wxInt16 thePart
)
2178 wxTextCtrl
* textctrl
= (wxTextCtrl
*) GetControlReference(m_controlRef
);
2179 if ( textctrl
== NULL
)
2182 if ( textctrl
->MacIsReallyShown() )
2184 wxMacWindowClipper
clipper( textctrl
) ;
2185 TXNDraw( m_txn
, NULL
) ;
2189 wxInt16
wxMacMLTEClassicControl::MacControlUserPaneHitTestProc(wxInt16 x
, wxInt16 y
)
2191 Point where
= { y
, x
} ;
2192 ControlPartCode result
;
2195 wxTextCtrl
* textctrl
= (wxTextCtrl
*) GetControlReference(m_controlRef
);
2196 if ( textctrl
== NULL
)
2199 if (textctrl
->MacIsReallyShown() )
2201 if (PtInRect(where
, &m_txnControlBounds
))
2202 result
= kControlEditTextPart
;
2205 // sometimes we get the coords also in control local coordinates, therefore test again
2206 if ( textctrl
->MacGetTopLevelWindow()->MacUsesCompositing() )
2209 textctrl
->MacClientToRootWindow( &x
, &y
) ;
2213 if (PtInRect(where
, &m_txnControlBounds
))
2214 result
= kControlEditTextPart
;
2222 wxInt16
wxMacMLTEClassicControl::MacControlUserPaneTrackingProc( wxInt16 x
, wxInt16 y
, void* actionProc
)
2224 wxTextCtrl
* textctrl
= (wxTextCtrl
*) GetControlReference(m_controlRef
);
2225 if ( textctrl
== NULL
)
2228 ControlPartCode partCodeResult
= 0;
2230 if (textctrl
->MacIsReallyShown() )
2232 Point startPt
= { y
,x
} ;
2233 // for compositing, we must convert these into toplevel window coordinates, because hittesting expects them
2234 if ( textctrl
->MacGetTopLevelWindow()->MacUsesCompositing() )
2237 textctrl
->MacClientToRootWindow( &x
, &y
) ;
2242 switch (MacControlUserPaneHitTestProc( startPt
.h
, startPt
.v
))
2244 case kControlEditTextPart
:
2246 wxMacWindowClipper
clipper( textctrl
) ;
2249 ConvertEventRefToEventRecord( (EventRef
) wxTheApp
->MacGetCurrentEvent() , &rec
) ;
2250 TXNClick( m_txn
, &rec
);
2256 return partCodeResult
;
2259 void wxMacMLTEClassicControl::MacControlUserPaneIdleProc()
2261 wxTextCtrl
* textctrl
= (wxTextCtrl
*) GetControlReference(m_controlRef
);
2262 if ( textctrl
== NULL
)
2265 if (textctrl
->MacIsReallyShown())
2267 if (IsControlActive(m_controlRef
))
2271 wxMacWindowClipper
clipper( textctrl
) ;
2276 if (PtInRect(mousep
, &m_txnControlBounds
))
2279 RectRgn((theRgn
= NewRgn()), &m_txnControlBounds
);
2280 TXNAdjustCursor(m_txn
, theRgn
);
2287 wxInt16
wxMacMLTEClassicControl::MacControlUserPaneKeyDownProc (wxInt16 keyCode
, wxInt16 charCode
, wxInt16 modifiers
)
2289 wxTextCtrl
* textctrl
= (wxTextCtrl
*) GetControlReference(m_controlRef
);
2290 if ( textctrl
== NULL
)
2293 wxMacWindowClipper
clipper( textctrl
) ;
2296 memset( &ev
, 0 , sizeof( ev
) ) ;
2298 ev
.modifiers
= modifiers
;
2299 ev
.message
= (( keyCode
<< 8 ) & keyCodeMask
) + ( charCode
& charCodeMask
) ;
2300 TXNKeyDown( m_txn
, &ev
);
2302 return kControlEntireControl
;
2305 void wxMacMLTEClassicControl::MacControlUserPaneActivateProc( bool activating
)
2307 MacActivatePaneText( activating
);
2310 wxInt16
wxMacMLTEClassicControl::MacControlUserPaneFocusProc(wxInt16 action
)
2312 ControlPartCode focusResult
;
2314 focusResult
= kControlFocusNoPart
;
2315 wxTextCtrl
* textctrl
= (wxTextCtrl
*) GetControlReference(m_controlRef
);
2316 if ( textctrl
== NULL
)
2319 wxMacWindowClipper
clipper( textctrl
) ;
2321 ControlRef controlFocus
= 0 ;
2322 GetKeyboardFocus( m_txnWindow
, &controlFocus
) ;
2323 bool wasFocused
= ( controlFocus
== m_controlRef
) ;
2327 case kControlFocusPrevPart
:
2328 case kControlFocusNextPart
:
2329 MacFocusPaneText( ( !wasFocused
));
2330 focusResult
= (!wasFocused
) ? kControlEditTextPart
: kControlFocusNoPart
;
2333 case kControlFocusNoPart
:
2335 MacFocusPaneText( false);
2336 focusResult
= kControlFocusNoPart
;
2343 void wxMacMLTEClassicControl::MacControlUserPaneBackgroundProc( void *info
)
2347 wxMacMLTEClassicControl::wxMacMLTEClassicControl( wxTextCtrl
*wxPeer
,
2348 const wxString
& str
,
2350 const wxSize
& size
, long style
) : wxMacMLTEControl( wxPeer
)
2352 m_font
= wxPeer
->GetFont() ;
2353 m_windowStyle
= style
;
2354 Rect bounds
= wxMacGetBoundsForControl( wxPeer
, pos
, size
) ;
2356 wxMacConvertNewlines10To13( &st
) ;
2360 featurSet
= kControlSupportsEmbedding
| kControlSupportsFocus
| kControlWantsIdle
2361 | kControlWantsActivate
| kControlHandlesTracking
| kControlHasSpecialBackground
2362 | kControlGetsFocusOnClick
| kControlSupportsLiveFeedback
;
2364 verify_noerr( ::CreateUserPaneControl( MAC_WXHWND(wxPeer
->GetParent()->MacGetTopLevelWindowRef()), &bounds
, featurSet
, &m_controlRef
) );
2368 MacSetObjectVisibility( wxPeer
->MacIsReallyShown() ) ;
2370 AdjustCreationAttributes( *wxWHITE
, true) ;
2372 wxMacWindowClipper
clipper( m_peer
) ;
2373 SetTXNData( st
, kTXNStartOffset
, kTXNEndOffset
) ;
2374 TXNSetSelection( m_txn
, 0, 0);
2377 wxMacMLTEClassicControl::~wxMacMLTEClassicControl()
2379 TXNDeleteObject(m_txn
);
2383 void wxMacMLTEClassicControl::VisibilityChanged(bool shown
)
2385 MacSetObjectVisibility( shown
) ;
2386 wxMacControl::VisibilityChanged( shown
) ;
2389 void wxMacMLTEClassicControl::SuperChangedPosition()
2391 MacUpdatePosition() ;
2392 wxMacControl::SuperChangedPosition() ;
2395 bool wxMacMLTEClassicControl::NeedsFocusRect() const
2400 #ifdef __WXMAC_OSX__
2402 ControlUserPaneDrawUPP gTPDrawProc
= NULL
;
2403 ControlUserPaneHitTestUPP gTPHitProc
= NULL
;
2404 ControlUserPaneTrackingUPP gTPTrackProc
= NULL
;
2405 ControlUserPaneIdleUPP gTPIdleProc
= NULL
;
2406 ControlUserPaneKeyDownUPP gTPKeyProc
= NULL
;
2407 ControlUserPaneActivateUPP gTPActivateProc
= NULL
;
2408 ControlUserPaneFocusUPP gTPFocusProc
= NULL
;
2410 static pascal void wxMacControlUserPaneDrawProc(ControlRef control
, SInt16 part
)
2412 wxTextCtrl
*textCtrl
= wxDynamicCast( wxFindControlFromMacControl(control
) , wxTextCtrl
) ;
2413 wxMacMLTEClassicControl
* win
= textCtrl
? dynamic_cast<wxMacMLTEClassicControl
*>(textCtrl
->GetPeer()) : NULL
;
2415 win
->MacControlUserPaneDrawProc(part
) ;
2418 static pascal ControlPartCode
wxMacControlUserPaneHitTestProc(ControlRef control
, Point where
)
2420 wxTextCtrl
*textCtrl
= wxDynamicCast( wxFindControlFromMacControl(control
) , wxTextCtrl
) ;
2421 wxMacMLTEClassicControl
* win
= textCtrl
? dynamic_cast<wxMacMLTEClassicControl
*>(textCtrl
->GetPeer()) : NULL
;
2423 return win
->MacControlUserPaneHitTestProc(where
.h
, where
.v
) ;
2425 return kControlNoPart
;
2428 static pascal ControlPartCode
wxMacControlUserPaneTrackingProc(ControlRef control
, Point startPt
, ControlActionUPP actionProc
)
2430 wxTextCtrl
*textCtrl
= wxDynamicCast( wxFindControlFromMacControl(control
) , wxTextCtrl
) ;
2431 wxMacMLTEClassicControl
* win
= textCtrl
? dynamic_cast<wxMacMLTEClassicControl
*>(textCtrl
->GetPeer()) : NULL
;
2433 return win
->MacControlUserPaneTrackingProc( startPt
.h
, startPt
.v
, (void*) actionProc
) ;
2435 return kControlNoPart
;
2438 static pascal void wxMacControlUserPaneIdleProc(ControlRef control
)
2440 wxTextCtrl
*textCtrl
= wxDynamicCast( wxFindControlFromMacControl(control
) , wxTextCtrl
) ;
2441 wxMacMLTEClassicControl
* win
= textCtrl
? dynamic_cast<wxMacMLTEClassicControl
*>(textCtrl
->GetPeer()) : NULL
;
2443 win
->MacControlUserPaneIdleProc() ;
2446 static pascal ControlPartCode
wxMacControlUserPaneKeyDownProc(ControlRef control
, SInt16 keyCode
, SInt16 charCode
, SInt16 modifiers
)
2448 wxTextCtrl
*textCtrl
= wxDynamicCast( wxFindControlFromMacControl(control
) , wxTextCtrl
) ;
2449 wxMacMLTEClassicControl
* win
= textCtrl
? dynamic_cast<wxMacMLTEClassicControl
*>(textCtrl
->GetPeer()) : NULL
;
2451 return win
->MacControlUserPaneKeyDownProc(keyCode
,charCode
,modifiers
) ;
2453 return kControlNoPart
;
2456 static pascal void wxMacControlUserPaneActivateProc(ControlRef control
, Boolean activating
)
2458 wxTextCtrl
*textCtrl
= wxDynamicCast( wxFindControlFromMacControl(control
) , wxTextCtrl
) ;
2459 wxMacMLTEClassicControl
* win
= textCtrl
? dynamic_cast<wxMacMLTEClassicControl
*>(textCtrl
->GetPeer()) : NULL
;
2461 win
->MacControlUserPaneActivateProc(activating
) ;
2464 static pascal ControlPartCode
wxMacControlUserPaneFocusProc(ControlRef control
, ControlFocusPart action
)
2466 wxTextCtrl
*textCtrl
= wxDynamicCast( wxFindControlFromMacControl(control
) , wxTextCtrl
) ;
2467 wxMacMLTEClassicControl
* win
= textCtrl
? dynamic_cast<wxMacMLTEClassicControl
*>(textCtrl
->GetPeer()) : NULL
;
2469 return win
->MacControlUserPaneFocusProc(action
) ;
2471 return kControlNoPart
;
2474 static pascal void wxMacControlUserPaneBackgroundProc(ControlRef control
, ControlBackgroundPtr info
)
2476 wxTextCtrl
*textCtrl
= wxDynamicCast( wxFindControlFromMacControl(control
) , wxTextCtrl
) ;
2477 wxMacMLTEClassicControl
* win
= textCtrl
? dynamic_cast<wxMacMLTEClassicControl
*>(textCtrl
->GetPeer()) : NULL
;
2479 win
->MacControlUserPaneBackgroundProc(info
) ;
2483 // TXNRegisterScrollInfoProc
2485 OSStatus
wxMacMLTEClassicControl::DoCreate()
2489 OSStatus err
= noErr
;
2491 /* set up our globals */
2492 #ifdef __WXMAC_OSX__
2493 if (gTPDrawProc
== NULL
) gTPDrawProc
= NewControlUserPaneDrawUPP(wxMacControlUserPaneDrawProc
);
2494 if (gTPHitProc
== NULL
) gTPHitProc
= NewControlUserPaneHitTestUPP(wxMacControlUserPaneHitTestProc
);
2495 if (gTPTrackProc
== NULL
) gTPTrackProc
= NewControlUserPaneTrackingUPP(wxMacControlUserPaneTrackingProc
);
2496 if (gTPIdleProc
== NULL
) gTPIdleProc
= NewControlUserPaneIdleUPP(wxMacControlUserPaneIdleProc
);
2497 if (gTPKeyProc
== NULL
) gTPKeyProc
= NewControlUserPaneKeyDownUPP(wxMacControlUserPaneKeyDownProc
);
2498 if (gTPActivateProc
== NULL
) gTPActivateProc
= NewControlUserPaneActivateUPP(wxMacControlUserPaneActivateProc
);
2499 if (gTPFocusProc
== NULL
) gTPFocusProc
= NewControlUserPaneFocusUPP(wxMacControlUserPaneFocusProc
);
2501 if (gTXNScrollInfoProc
== NULL
) gTXNScrollInfoProc
= NewTXNScrollInfoUPP(TXNScrollInfoProc
) ;
2502 if (gTXNScrollActionProc
== NULL
) gTXNScrollActionProc
= NewControlActionUPP(TXNScrollActionProc
) ;
2505 /* set the initial settings for our private data */
2507 m_txnWindow
=GetControlOwner(m_controlRef
);
2508 m_txnPort
= (GrafPtr
) GetWindowPort(m_txnWindow
);
2510 #ifdef __WXMAC_OSX__
2511 /* set up the user pane procedures */
2512 SetControlData(m_controlRef
, kControlEntireControl
, kControlUserPaneDrawProcTag
, sizeof(gTPDrawProc
), &gTPDrawProc
);
2513 SetControlData(m_controlRef
, kControlEntireControl
, kControlUserPaneHitTestProcTag
, sizeof(gTPHitProc
), &gTPHitProc
);
2514 SetControlData(m_controlRef
, kControlEntireControl
, kControlUserPaneTrackingProcTag
, sizeof(gTPTrackProc
), &gTPTrackProc
);
2515 SetControlData(m_controlRef
, kControlEntireControl
, kControlUserPaneIdleProcTag
, sizeof(gTPIdleProc
), &gTPIdleProc
);
2516 SetControlData(m_controlRef
, kControlEntireControl
, kControlUserPaneKeyDownProcTag
, sizeof(gTPKeyProc
), &gTPKeyProc
);
2517 SetControlData(m_controlRef
, kControlEntireControl
, kControlUserPaneActivateProcTag
, sizeof(gTPActivateProc
), &gTPActivateProc
);
2518 SetControlData(m_controlRef
, kControlEntireControl
, kControlUserPaneFocusProcTag
, sizeof(gTPFocusProc
), &gTPFocusProc
);
2520 /* calculate the rectangles used by the control */
2521 UMAGetControlBoundsInWindowCoords(m_controlRef
, &bounds
);
2523 m_txnControlBounds
= bounds
;
2525 CGrafPtr origPort
= NULL
;
2526 GDHandle origDev
= NULL
;
2527 GetGWorld( &origPort
, &origDev
) ;
2530 /* create the new edit field */
2532 TXNFrameOptions frameOptions
= FrameOptionsFromWXStyle( m_windowStyle
) ;
2534 #ifdef __WXMAC_OSX__
2536 // the scrollbars are not correctly embedded but are inserted at the root
2537 // this gives us problems as we have erratic redraws even over the structure
2540 m_sbHorizontal
= 0 ;
2542 m_lastHorizontalValue
= 0 ;
2543 m_lastVerticalValue
= 0 ;
2545 Rect sb
= { 0 , 0 , 0 , 0 } ;
2546 if ( frameOptions
& kTXNWantVScrollBarMask
)
2548 CreateScrollBarControl( m_txnWindow
, &sb
, 0 , 0 , 100 , 1 , true , gTXNScrollActionProc
, &m_sbVertical
) ;
2549 SetControlReference( m_sbVertical
, (SInt32
) this ) ;
2550 SetControlAction( m_sbVertical
, gTXNScrollActionProc
);
2551 ShowControl( m_sbVertical
) ;
2552 EmbedControl( m_sbVertical
, m_controlRef
) ;
2553 frameOptions
&= ~kTXNWantVScrollBarMask
;
2555 if ( frameOptions
& kTXNWantHScrollBarMask
)
2557 CreateScrollBarControl( m_txnWindow
, &sb
, 0 , 0 , 100 , 1 , true , gTXNScrollActionProc
, &m_sbHorizontal
) ;
2558 SetControlReference( m_sbHorizontal
, (SInt32
) this ) ;
2559 SetControlAction( m_sbHorizontal
, gTXNScrollActionProc
);
2560 ShowControl( m_sbHorizontal
) ;
2561 EmbedControl( m_sbHorizontal
, m_controlRef
) ;
2562 frameOptions
&= ~(kTXNWantHScrollBarMask
| kTXNDrawGrowIconMask
);
2567 verify_noerr(TXNNewObject(NULL
, m_txnWindow
, &bounds
,
2569 kTXNTextEditStyleFrameType
,
2571 kTXNSystemDefaultEncoding
,
2572 &m_txn
, &m_txnFrameID
, NULL
) );
2574 #ifdef __WXMAC_OSX__
2575 TXNRegisterScrollInfoProc( m_txn
, gTXNScrollInfoProc
, (SInt32
) this);
2578 SetGWorld( origPort
, origDev
) ;
2582 // ----------------------------------------------------------------------------
2583 // MLTE control implementation (OSX part)
2584 // ----------------------------------------------------------------------------
2586 #if TARGET_API_MAC_OSX
2588 #if MAC_OS_X_VERSION_MAX_ALLOWED > MAC_OS_X_VERSION_10_2
2590 wxMacMLTEHIViewControl::wxMacMLTEHIViewControl( wxTextCtrl
*wxPeer
,
2591 const wxString
& str
,
2593 const wxSize
& size
, long style
) : wxMacMLTEControl( wxPeer
)
2595 m_font
= wxPeer
->GetFont() ;
2596 m_windowStyle
= style
;
2597 Rect bounds
= wxMacGetBoundsForControl( wxPeer
, pos
, size
) ;
2599 wxMacConvertNewlines10To13( &st
) ;
2601 HIRect hr
= { bounds
.left
, bounds
.top
, bounds
.right
- bounds
.left
, bounds
.bottom
- bounds
.top
} ;
2603 m_scrollView
= NULL
;
2604 TXNFrameOptions frameOptions
= FrameOptionsFromWXStyle( style
) ;
2605 if ( frameOptions
& (kTXNWantVScrollBarMask
|kTXNWantHScrollBarMask
) )
2607 HIScrollViewCreate(( frameOptions
& kTXNWantHScrollBarMask
? kHIScrollViewOptionsHorizScroll
: 0) |
2608 ( frameOptions
& kTXNWantVScrollBarMask
? kHIScrollViewOptionsVertScroll
: 0 ) , &m_scrollView
) ;
2610 HIViewSetFrame( m_scrollView
, &hr
);
2611 HIViewSetVisible( m_scrollView
, true );
2615 HITextViewCreate( NULL
, 0, frameOptions
, &m_textView
) ;
2616 m_txn
= HITextViewGetTXNObject( m_textView
) ;
2617 HIViewSetVisible( m_textView
, true ) ;
2620 HIViewAddSubview( m_scrollView
, m_textView
) ;
2621 m_controlRef
= m_scrollView
;
2622 wxPeer
->MacInstallEventHandler( (WXWidget
) m_textView
) ;
2626 HIViewSetFrame( m_textView
, &hr
);
2627 m_controlRef
= m_textView
;
2630 AdjustCreationAttributes( *wxWHITE
, true ) ;
2632 wxMacWindowClipper
c( m_peer
) ;
2633 SetTXNData( st
, kTXNStartOffset
, kTXNEndOffset
) ;
2635 TXNSetSelection( m_txn
, 0, 0);
2636 TXNShowSelection( m_txn
, kTXNShowStart
);
2640 OSStatus
wxMacMLTEHIViewControl::SetFocus( ControlFocusPart focusPart
)
2642 return SetKeyboardFocus( GetControlOwner( m_textView
) ,
2643 m_textView
, focusPart
) ;
2646 bool wxMacMLTEHIViewControl::HasFocus() const
2648 ControlRef control
;
2649 GetKeyboardFocus( GetUserFocusWindow() , &control
) ;
2650 return control
== m_textView
;
2653 bool wxMacMLTEHIViewControl::NeedsFocusRect() const
2655 return m_windowStyle
& wxNO_BORDER
? false : true;
2658 #endif // MAC_OS_X_VERSION_MAX_ALLOWED > MAC_OS_X_VERSION_10_2
2663 #endif // wxUSE_TEXTCTRL