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
) ;
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 ;
275 HIViewRef m_scrollView
;
276 HIViewRef m_textView
;
281 class wxMacUnicodeTextControl
: public wxMacTextControl
284 wxMacUnicodeTextControl( wxTextCtrl
*wxPeer
,
287 const wxSize
& size
, long style
) ;
288 ~wxMacUnicodeTextControl();
289 virtual void VisibilityChanged(bool shown
);
290 virtual wxString
GetStringValue() const ;
291 virtual void SetStringValue( const wxString
&str
) ;
294 virtual void Paste();
295 virtual bool CanPaste() const;
296 virtual void SetEditable(bool editable
) ;
297 virtual void Remove( long from
, long to
) ;
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 void SetRect( Rect
*r
) ;
335 void MacUpdatePosition() ;
336 void MacActivatePaneText(Boolean setActive
) ;
337 void MacFocusPaneText(Boolean setFocus
) ;
339 void MacSetObjectVisibility(Boolean vis
) ;
341 TXNFrameID m_txnFrameID
;
343 WindowRef m_txnWindow
;
344 // bounds of the control as we last did set the txn frames
345 Rect m_txnControlBounds
;
348 static pascal void TXNScrollInfoProc (SInt32 iValue
, SInt32 iMaximumValue
,
349 TXNScrollBarOrientation iScrollBarOrientation
, SInt32 iRefCon
) ;
350 static pascal void TXNScrollActionProc( ControlRef controlRef
, ControlPartCode partCode
) ;
351 ControlRef m_sbHorizontal
;
352 SInt32 m_lastHorizontalValue
;
353 ControlRef m_sbVertical
;
354 SInt32 m_lastVerticalValue
;
358 #define TE_UNLIMITED_LENGTH 0xFFFFFFFFUL
360 #if !USE_SHARED_LIBRARY
361 IMPLEMENT_DYNAMIC_CLASS(wxTextCtrl
, wxControl
)
363 BEGIN_EVENT_TABLE(wxTextCtrl
, wxControl
)
364 EVT_ERASE_BACKGROUND( wxTextCtrl::OnEraseBackground
)
365 EVT_DROP_FILES(wxTextCtrl::OnDropFiles
)
366 EVT_CHAR(wxTextCtrl::OnChar
)
367 EVT_MENU(wxID_CUT
, wxTextCtrl::OnCut
)
368 EVT_MENU(wxID_COPY
, wxTextCtrl::OnCopy
)
369 EVT_MENU(wxID_PASTE
, wxTextCtrl::OnPaste
)
370 EVT_MENU(wxID_UNDO
, wxTextCtrl::OnUndo
)
371 EVT_MENU(wxID_REDO
, wxTextCtrl::OnRedo
)
373 EVT_UPDATE_UI(wxID_CUT
, wxTextCtrl::OnUpdateCut
)
374 EVT_UPDATE_UI(wxID_COPY
, wxTextCtrl::OnUpdateCopy
)
375 EVT_UPDATE_UI(wxID_PASTE
, wxTextCtrl::OnUpdatePaste
)
376 EVT_UPDATE_UI(wxID_UNDO
, wxTextCtrl::OnUpdateUndo
)
377 EVT_UPDATE_UI(wxID_REDO
, wxTextCtrl::OnUpdateRedo
)
382 void wxTextCtrl::Init()
387 m_maxLength
= TE_UNLIMITED_LENGTH
;
390 wxTextCtrl::~wxTextCtrl()
395 bool wxTextCtrl::Create(wxWindow
*parent
, wxWindowID id
,
398 const wxSize
& size
, long style
,
399 const wxValidator
& validator
,
400 const wxString
& name
)
402 m_macIsUserPane
= false ;
405 if ( ! ( style
& wxNO_BORDER
) )
406 style
= ( style
& ~wxBORDER_MASK
) | wxSUNKEN_BORDER
;
408 if ( !wxTextCtrlBase::Create(parent
, id
, pos
, size
, style
& ~(wxHSCROLL
|wxVSCROLL
), validator
, name
) )
411 Rect bounds
= wxMacGetBoundsForControl( this , pos
, size
) ;
413 if ( m_windowStyle
& wxTE_MULTILINE
)
415 wxASSERT_MSG( !(m_windowStyle
& wxTE_PROCESS_ENTER
),
416 wxT("wxTE_PROCESS_ENTER style is ignored for multiline text controls (they always process it)") );
418 m_windowStyle
|= wxTE_PROCESS_ENTER
;
419 style
|= wxTE_PROCESS_ENTER
;
423 #if MAC_OS_X_VERSION_MAX_ALLOWED > MAC_OS_X_VERSION_10_2
424 if ( UMAGetSystemVersion() >= 0x1050 )
426 m_peer
= new wxMacMLTEHIViewControl( this , str
, pos
, size
, style
) ;
429 #if !wxMAC_AWAYS_USE_MLTE
432 m_peer
= new wxMacUnicodeTextControl( this , str
, pos
, size
, style
) ;
438 m_peer
= new wxMacMLTEClassicControl( this , str
, pos
, size
, style
) ;
441 MacPostControlCreate(pos
,size
) ;
443 if ( m_windowStyle
& wxTE_READONLY
)
445 SetEditable( false ) ;
451 void wxTextCtrl::MacSuperChangedPosition()
453 wxWindow::MacSuperChangedPosition() ;
454 GetPeer()->SuperChangedPosition() ;
457 void wxTextCtrl::MacVisibilityChanged()
459 GetPeer()->VisibilityChanged( MacIsReallyShown() ) ;
462 void wxTextCtrl::MacEnabledStateChanged()
466 wxString
wxTextCtrl::GetValue() const
468 return GetPeer()->GetStringValue() ;
471 void wxTextCtrl::GetSelection(long* from
, long* to
) const
473 GetPeer()->GetSelection( from
, to
) ;
476 void wxTextCtrl::SetValue(const wxString
& str
)
479 if ( GetValue() == str
)
482 GetPeer()->SetStringValue(str
) ;
484 wxCommandEvent
event(wxEVT_COMMAND_TEXT_UPDATED
, m_windowId
);
485 event
.SetString( GetValue() ) ;
486 event
.SetEventObject( this );
487 GetEventHandler()->ProcessEvent(event
);
490 void wxTextCtrl::SetMaxLength(unsigned long len
)
495 bool wxTextCtrl::SetFont( const wxFont
& font
)
497 if ( !wxTextCtrlBase::SetFont( font
) )
500 GetPeer()->SetFont( font
, GetForegroundColour() , GetWindowStyle() ) ;
504 bool wxTextCtrl::SetStyle(long start
, long end
, const wxTextAttr
& style
)
506 GetPeer()->SetStyle( start
, end
, style
) ;
510 bool wxTextCtrl::SetDefaultStyle(const wxTextAttr
& style
)
512 wxTextCtrlBase::SetDefaultStyle( style
) ;
513 SetStyle( kTXNUseCurrentSelection
, kTXNUseCurrentSelection
, GetDefaultStyle() ) ;
517 // Clipboard operations
518 void wxTextCtrl::Copy()
526 void wxTextCtrl::Cut()
532 wxCommandEvent
event(wxEVT_COMMAND_TEXT_UPDATED
, m_windowId
);
533 event
.SetEventObject( this );
534 GetEventHandler()->ProcessEvent(event
);
538 void wxTextCtrl::Paste()
543 // eventually we should add setting the default style again
545 wxCommandEvent
event(wxEVT_COMMAND_TEXT_UPDATED
, m_windowId
);
546 event
.SetEventObject( this );
547 GetEventHandler()->ProcessEvent(event
);
551 bool wxTextCtrl::CanCopy() const
553 // Can copy if there's a selection
555 GetSelection(& from
, & to
);
559 bool wxTextCtrl::CanCut() const
565 // Can cut if there's a selection
567 GetSelection(& from
, & to
);
571 bool wxTextCtrl::CanPaste() const
576 return GetPeer()->CanPaste() ;
579 void wxTextCtrl::SetEditable(bool editable
)
581 if ( editable
!= m_editable
)
583 m_editable
= editable
;
584 GetPeer()->SetEditable( editable
) ;
588 void wxTextCtrl::SetInsertionPoint(long pos
)
590 SetSelection( pos
, pos
) ;
593 void wxTextCtrl::SetInsertionPointEnd()
595 wxTextPos pos
= GetLastPosition();
596 SetInsertionPoint(pos
);
599 long wxTextCtrl::GetInsertionPoint() const
602 GetSelection( &begin
, &end
) ;
606 wxTextPos
wxTextCtrl::GetLastPosition() const
608 return GetPeer()->GetLastPosition( ) ;
611 void wxTextCtrl::Replace(long from
, long to
, const wxString
& str
)
613 GetPeer()->Replace( from
, to
, str
) ;
616 void wxTextCtrl::Remove(long from
, long to
)
618 GetPeer()->Remove( from
, to
) ;
621 void wxTextCtrl::SetSelection(long from
, long to
)
623 GetPeer()->SetSelection( from
, to
) ;
626 bool wxTextCtrl::LoadFile(const wxString
& file
)
628 if ( wxTextCtrlBase::LoadFile(file
) )
636 void wxTextCtrl::WriteText(const wxString
& str
)
638 // TODO this MPRemoting will be moved into a remoting peer proxy for any command
639 if ( !wxIsMainThread() )
641 // unfortunately CW 8 is not able to correctly deduce the template types, so we have
642 // to instantiate explicitely
643 wxMacMPRemoteGUICall
<wxTextCtrl
,wxString
>( this , &wxTextCtrl::WriteText
, str
) ;
648 GetPeer()->WriteText( str
) ;
652 void wxTextCtrl::AppendText(const wxString
& text
)
654 SetInsertionPointEnd();
658 void wxTextCtrl::Clear()
663 bool wxTextCtrl::IsModified() const
668 bool wxTextCtrl::IsEditable() const
670 return IsEnabled() && m_editable
;
673 bool wxTextCtrl::AcceptsFocus() const
675 // we don't want focus if we can't be edited
676 return /*IsEditable() && */ wxControl::AcceptsFocus();
679 wxSize
wxTextCtrl::DoGetBestSize() const
685 // these are the numbers from the HIG, we reduce them by the borders
688 switch( m_windowVariant
)
690 case wxWINDOW_VARIANT_NORMAL
:
693 case wxWINDOW_VARIANT_SMALL
:
696 case wxWINDOW_VARIANT_MINI
:
704 // as the above numbers have some free space around the text
705 // we get 5 lines like this anyway
706 if ( m_windowStyle
& wxTE_MULTILINE
)
711 if ( !HasFlag(wxNO_BORDER
) )
714 return wxSize(wText
, hText
);
717 // ----------------------------------------------------------------------------
719 // ----------------------------------------------------------------------------
721 void wxTextCtrl::Undo()
729 void wxTextCtrl::Redo()
737 bool wxTextCtrl::CanUndo() const
743 return GetPeer()->CanUndo() ;
746 bool wxTextCtrl::CanRedo() const
752 return GetPeer()->CanRedo() ;
755 void wxTextCtrl::MarkDirty()
760 void wxTextCtrl::DiscardEdits()
765 int wxTextCtrl::GetNumberOfLines() const
767 return GetPeer()->GetNumberOfLines() ;
770 long wxTextCtrl::XYToPosition(long x
, long y
) const
772 return GetPeer()->XYToPosition( x
, y
) ;
775 bool wxTextCtrl::PositionToXY(long pos
, long *x
, long *y
) const
777 return GetPeer()->PositionToXY(pos
, x
, y
) ;
780 void wxTextCtrl::ShowPosition(long pos
)
782 return GetPeer()->ShowPosition(pos
) ;
785 int wxTextCtrl::GetLineLength(long lineNo
) const
787 return GetPeer()->GetLineLength(lineNo
) ;
790 wxString
wxTextCtrl::GetLineText(long lineNo
) const
792 return GetPeer()->GetLineText(lineNo
) ;
799 void wxTextCtrl::Command(wxCommandEvent
& event
)
801 SetValue (event
.GetString());
802 ProcessCommand (event
);
805 void wxTextCtrl::OnDropFiles(wxDropFilesEvent
& event
)
807 // By default, load the first file into the text window.
808 if (event
.GetNumberOfFiles() > 0)
810 LoadFile(event
.GetFiles()[0]);
814 void wxTextCtrl::OnEraseBackground(wxEraseEvent
& event
)
816 // all erasing should be done by the real mac control implementation
817 // while this is true for MLTE under classic, the HITextView is somehow
818 // transparent but background erase is not working correctly, so intercept
819 // things while we can...
823 void wxTextCtrl::OnChar(wxKeyEvent
& event
)
825 int key
= event
.GetKeyCode() ;
826 bool eat_key
= false ;
828 if ( key
== 'c' && event
.MetaDown() )
835 if ( !IsEditable() && key
!= WXK_LEFT
&& key
!= WXK_RIGHT
&& key
!= WXK_DOWN
&& key
!= WXK_UP
&& key
!= WXK_TAB
&&
836 !( key
== WXK_RETURN
&& ( (m_windowStyle
& wxPROCESS_ENTER
) || (m_windowStyle
& wxTE_MULTILINE
) ) )
837 /* && key != WXK_PRIOR && key != WXK_NEXT && key != WXK_HOME && key != WXK_END */
844 // Check if we have reached the max # of chars, but still allow navigation and deletion
845 if ( !IsMultiLine() && GetValue().Length() >= m_maxLength
&&
846 key
!= WXK_LEFT
&& key
!= WXK_RIGHT
&& key
!= WXK_TAB
&&
847 key
!= WXK_BACK
&& !( key
== WXK_RETURN
&& (m_windowStyle
& wxPROCESS_ENTER
) )
850 // eat it, we don't want to add more than allowed # of characters
854 // assume that any key not processed yet is going to modify the control
857 if ( key
== 'v' && event
.MetaDown() )
863 if ( key
== 'x' && event
.MetaDown() )
872 if (m_windowStyle
& wxPROCESS_ENTER
)
874 wxCommandEvent
event(wxEVT_COMMAND_TEXT_ENTER
, m_windowId
);
875 event
.SetEventObject( this );
876 event
.SetString( GetValue() );
877 if ( GetEventHandler()->ProcessEvent(event
) )
880 if ( !(m_windowStyle
& wxTE_MULTILINE
) )
882 wxWindow
*parent
= GetParent();
883 while( parent
&& !parent
->IsTopLevel() && parent
->GetDefaultItem() == NULL
) {
884 parent
= parent
->GetParent() ;
886 if ( parent
&& parent
->GetDefaultItem() )
888 wxButton
*def
= wxDynamicCast(parent
->GetDefaultItem(),
890 if ( def
&& def
->IsEnabled() )
892 wxCommandEvent
event(wxEVT_COMMAND_BUTTON_CLICKED
, def
->GetId() );
893 event
.SetEventObject(def
);
899 // this will make wxWidgets eat the ENTER key so that
900 // we actually prevent line wrapping in a single line
908 if ( !(m_windowStyle
& wxTE_PROCESS_TAB
))
911 if (!event
.ShiftDown())
912 flags
|= wxNavigationKeyEvent::IsForward
;
913 if (event
.ControlDown())
914 flags
|= wxNavigationKeyEvent::WinChange
;
920 // This is necessary (don't know why) or the tab will not
922 WriteText(wxT("\t"));
930 // perform keystroke handling
931 if ( wxTheApp
->MacGetCurrentEvent() != NULL
&& wxTheApp
->MacGetCurrentEventHandlerCallRef() != NULL
)
932 CallNextEventHandler((EventHandlerCallRef
)wxTheApp
->MacGetCurrentEventHandlerCallRef() , (EventRef
) wxTheApp
->MacGetCurrentEvent() ) ;
936 if ( wxMacConvertEventToRecord( (EventRef
) wxTheApp
->MacGetCurrentEvent() , &rec
) )
938 EventRecord
*ev
= &rec
;
941 keychar
= short(ev
->message
& charCodeMask
);
942 keycode
= short(ev
->message
& keyCodeMask
) >> 8 ;
944 m_peer
->HandleKey( keycode
, keychar
, ev
->modifiers
) ;
948 if ( ( key
>= 0x20 && key
< WXK_START
) ||
953 wxCommandEvent
event1(wxEVT_COMMAND_TEXT_UPDATED
, m_windowId
);
954 event1
.SetEventObject( this );
955 wxPostEvent(GetEventHandler(),event1
);
959 // ----------------------------------------------------------------------------
960 // standard handlers for standard edit menu events
961 // ----------------------------------------------------------------------------
963 void wxTextCtrl::OnCut(wxCommandEvent
& WXUNUSED(event
))
968 void wxTextCtrl::OnCopy(wxCommandEvent
& WXUNUSED(event
))
973 void wxTextCtrl::OnPaste(wxCommandEvent
& WXUNUSED(event
))
978 void wxTextCtrl::OnUndo(wxCommandEvent
& WXUNUSED(event
))
983 void wxTextCtrl::OnRedo(wxCommandEvent
& WXUNUSED(event
))
988 void wxTextCtrl::OnUpdateCut(wxUpdateUIEvent
& event
)
990 event
.Enable( CanCut() );
993 void wxTextCtrl::OnUpdateCopy(wxUpdateUIEvent
& event
)
995 event
.Enable( CanCopy() );
998 void wxTextCtrl::OnUpdatePaste(wxUpdateUIEvent
& event
)
1000 event
.Enable( CanPaste() );
1003 void wxTextCtrl::OnUpdateUndo(wxUpdateUIEvent
& event
)
1005 event
.Enable( CanUndo() );
1008 void wxTextCtrl::OnUpdateRedo(wxUpdateUIEvent
& event
)
1010 event
.Enable( CanRedo() );
1013 bool wxTextCtrl::MacSetupCursor( const wxPoint
& pt
)
1017 #if !TARGET_API_MAC_OSX
1019 // user pane implementation
1021 void wxTextCtrl::MacControlUserPaneDrawProc(wxInt16 part
)
1023 GetPeer()->MacControlUserPaneDrawProc( part
) ;
1026 wxInt16
wxTextCtrl::MacControlUserPaneHitTestProc(wxInt16 x
, wxInt16 y
)
1028 return GetPeer()->MacControlUserPaneHitTestProc( x
, y
) ;
1031 wxInt16
wxTextCtrl::MacControlUserPaneTrackingProc(wxInt16 x
, wxInt16 y
, void* actionProc
)
1033 return GetPeer()->MacControlUserPaneTrackingProc( x
, y
, actionProc
) ;
1036 void wxTextCtrl::MacControlUserPaneIdleProc()
1038 GetPeer()->MacControlUserPaneIdleProc( ) ;
1041 wxInt16
wxTextCtrl::MacControlUserPaneKeyDownProc(wxInt16 keyCode
, wxInt16 charCode
, wxInt16 modifiers
)
1043 return GetPeer()->MacControlUserPaneKeyDownProc( keyCode
, charCode
, modifiers
) ;
1046 void wxTextCtrl::MacControlUserPaneActivateProc(bool activating
)
1048 GetPeer()->MacControlUserPaneActivateProc( activating
) ;
1051 wxInt16
wxTextCtrl::MacControlUserPaneFocusProc(wxInt16 action
)
1053 return GetPeer()->MacControlUserPaneFocusProc( action
) ;
1056 void wxTextCtrl::MacControlUserPaneBackgroundProc(void* info
)
1058 GetPeer()->MacControlUserPaneBackgroundProc( info
) ;
1062 // ----------------------------------------------------------------------------
1063 // implementation base class
1064 // ----------------------------------------------------------------------------
1066 wxMacTextControl::wxMacTextControl(wxTextCtrl
* peer
) :
1067 wxMacControl( peer
)
1071 wxMacTextControl::~wxMacTextControl()
1075 void wxMacTextControl::SetStyle(long start
, long end
, const wxTextAttr
& style
)
1079 void wxMacTextControl::Copy()
1083 void wxMacTextControl::Cut()
1087 void wxMacTextControl::Paste()
1091 bool wxMacTextControl::CanPaste() const
1096 void wxMacTextControl::SetEditable(bool editable
)
1100 wxTextPos
wxMacTextControl::GetLastPosition() const
1102 return GetStringValue().Length() ;
1105 void wxMacTextControl::Replace( long from
, long to
, const wxString str
)
1109 void wxMacTextControl::Clear()
1111 SetStringValue( wxEmptyString
) ;
1114 bool wxMacTextControl::CanUndo() const
1119 void wxMacTextControl::Undo() { }
1121 bool wxMacTextControl::CanRedo() const
1126 void wxMacTextControl::Redo()
1130 long wxMacTextControl::XYToPosition(long x
, long y
) const
1135 bool wxMacTextControl::PositionToXY(long pos
, long *x
, long *y
) const
1140 void wxMacTextControl::ShowPosition( long WXUNUSED(pos
) )
1144 int wxMacTextControl::GetNumberOfLines() const
1146 ItemCount lines
= 0 ;
1147 wxString content
= GetStringValue() ;
1149 for (size_t i
= 0; i
< content
.Length() ; i
++)
1151 if (content
[i
] == '\r') lines
++;
1156 wxString
wxMacTextControl::GetLineText(long lineNo
) const
1158 // TODO change this if possible to reflect real lines
1159 wxString content
= GetStringValue() ;
1163 for (size_t i
= 0; i
< content
.Length() ; i
++)
1165 if (count
== lineNo
)
1167 // Add chars in line then
1170 for (size_t j
= i
; j
< content
.Length(); j
++)
1172 if (content
[j
] == '\n')
1180 if (content
[i
] == '\n') count
++;
1182 return wxEmptyString
;
1185 int wxMacTextControl::GetLineLength(long lineNo
) const
1187 // TODO change this if possible to reflect real lines
1188 wxString content
= GetStringValue() ;
1192 for (size_t i
= 0; i
< content
.Length() ; i
++)
1194 if (count
== lineNo
)
1196 // Count chars in line then
1198 for (size_t j
= i
; j
< content
.Length(); j
++)
1201 if (content
[j
] == '\n') return count
;
1206 if (content
[i
] == '\n') count
++;
1211 // ----------------------------------------------------------------------------
1212 // standard unicode control implementation
1213 // ----------------------------------------------------------------------------
1215 #if TARGET_API_MAC_OSX
1217 wxMacUnicodeTextControl::wxMacUnicodeTextControl( wxTextCtrl
*wxPeer
,
1218 const wxString
& str
,
1220 const wxSize
& size
, long style
) : wxMacTextControl( wxPeer
)
1222 m_font
= wxPeer
->GetFont() ;
1223 m_windowStyle
= style
;
1224 Rect bounds
= wxMacGetBoundsForControl( wxPeer
, pos
, size
) ;
1226 wxMacConvertNewlines10To13( &st
) ;
1227 wxMacCFStringHolder
cf(st
, m_font
.GetEncoding()) ;
1228 CFStringRef cfr
= cf
;
1229 Boolean isPassword
= ( m_windowStyle
& wxTE_PASSWORD
) != 0 ;
1230 m_valueTag
= isPassword
? kControlEditTextPasswordCFStringTag
: kControlEditTextCFStringTag
;
1231 CreateEditUnicodeTextControl( MAC_WXHWND(wxPeer
->MacGetTopLevelWindowRef()), &bounds
, cfr
, isPassword
, NULL
, &m_controlRef
) ;
1233 if ( !(m_windowStyle
& wxTE_MULTILINE
) )
1235 SetData
<Boolean
>( kControlEditTextPart
, kControlEditTextSingleLineTag
, true ) ;
1239 wxMacUnicodeTextControl::~wxMacUnicodeTextControl()
1243 void wxMacUnicodeTextControl::VisibilityChanged(bool shown
)
1245 if ( !(m_windowStyle
& wxTE_MULTILINE
) && shown
)
1247 // work around a refresh issue insofar as not always the entire content is shown even if this would be possible
1248 ControlEditTextSelectionRec sel
;
1249 CFStringRef value
= NULL
;
1251 verify_noerr( GetData
<ControlEditTextSelectionRec
>( 0, kControlEditTextSelectionTag
, &sel
) );
1252 verify_noerr( GetData
<CFStringRef
>( 0, m_valueTag
, &value
) );
1253 verify_noerr( SetData
<CFStringRef
>( 0, m_valueTag
, &value
) );
1254 verify_noerr( SetData
<ControlEditTextSelectionRec
>( 0, kControlEditTextSelectionTag
, &sel
) );
1256 CFRelease( value
) ;
1259 wxString
wxMacUnicodeTextControl::GetStringValue() const
1262 CFStringRef value
= GetData
<CFStringRef
>(0,m_valueTag
) ;
1265 wxMacCFStringHolder
cf(value
) ;
1266 result
= cf
.AsString() ;
1269 wxMacConvertNewlines13To10( &result
) ;
1271 wxMacConvertNewlines10To13( &result
) ;
1275 void wxMacUnicodeTextControl::SetStringValue( const wxString
&str
)
1278 wxMacConvertNewlines10To13( &st
) ;
1279 wxMacCFStringHolder
cf(st
, m_font
.GetEncoding() ) ;
1280 verify_noerr( SetData
<CFStringRef
>( 0, m_valueTag
, cf
) ) ;
1282 void wxMacUnicodeTextControl::Copy()
1284 SendHICommand( kHICommandCopy
) ;
1286 void wxMacUnicodeTextControl::Cut()
1288 SendHICommand( kHICommandCut
) ;
1290 void wxMacUnicodeTextControl::Paste()
1292 SendHICommand( kHICommandPaste
) ;
1294 bool wxMacUnicodeTextControl::CanPaste() const
1298 void wxMacUnicodeTextControl::SetEditable(bool editable
)
1300 SetData
<Boolean
>( 0 , kControlEditTextLockedTag
, (Boolean
) !editable
) ;
1302 void wxMacUnicodeTextControl::Remove( long from
, long to
)
1306 void wxMacUnicodeTextControl::GetSelection( long* from
, long* to
) const
1308 ControlEditTextSelectionRec sel
;
1309 verify_noerr(GetData
<ControlEditTextSelectionRec
>( 0, kControlEditTextSelectionTag
, &sel
) ) ;
1310 if ( from
) *from
= sel
.selStart
;
1311 if ( to
) *to
= sel
.selEnd
;
1314 void wxMacUnicodeTextControl::SetSelection( long from
, long to
)
1316 ControlEditTextSelectionRec sel
;
1317 sel
.selStart
= from
;
1319 SetData
<ControlEditTextSelectionRec
>( 0 , kControlEditTextSelectionTag
, &sel
) ;
1322 void wxMacUnicodeTextControl::WriteText(const wxString
& str
)
1325 wxMacConvertNewlines10To13( &st
) ;
1326 #if MAC_OS_X_VERSION_MAX_ALLOWED > MAC_OS_X_VERSION_10_2
1327 wxMacCFStringHolder
cf(st
, m_font
.GetEncoding() ) ;
1328 CFStringRef value
= cf
;
1329 SetData
<CFStringRef
>( 0, kControlEditTextInsertCFStringRefTag
, &value
);
1331 wxString val
= GetStringValue() ;
1333 GetSelection( &start
, &end
) ;
1334 val
.Remove( start
, end
- start
) ;
1335 val
.insert( start
, str
) ;
1336 SetStringValue( val
) ;
1337 SetSelection( start
+ str
.Length() , start
+ str
.Length() ) ;
1343 // ----------------------------------------------------------------------------
1344 // MLTE control implementation (common part)
1345 // ----------------------------------------------------------------------------
1347 // if mlte is on read only , no changes at all are allowed, not even from
1348 // procedural API, in order to allow changes via API all the same we must undo
1349 // the readonly status while we are executing, this class helps to do so
1351 class wxMacEditHelper
1354 wxMacEditHelper( TXNObject txn
)
1356 TXNControlTag tag
[] = { kTXNIOPrivilegesTag
} ;
1358 TXNGetTXNObjectControls( m_txn
, 1 , tag
, m_data
) ;
1359 if ( m_data
[0].uValue
== kTXNReadOnly
)
1361 TXNControlData data
[] = { { kTXNReadWrite
} } ;
1362 TXNSetTXNObjectControls( m_txn
, false , 1 , tag
, data
) ;
1367 TXNControlTag tag
[] = { kTXNIOPrivilegesTag
} ;
1368 if ( m_data
[0].uValue
== kTXNReadOnly
)
1370 TXNSetTXNObjectControls( m_txn
, false , 1 , tag
, m_data
) ;
1375 TXNControlData m_data
[1] ;
1378 wxMacMLTEControl::wxMacMLTEControl( wxTextCtrl
*peer
) : wxMacTextControl( peer
)
1380 SetNeedsFocusRect( true ) ;
1383 wxString
wxMacMLTEControl::GetStringValue() const
1387 Size actualSize
= 0;
1391 err
= TXNGetDataEncoded( m_txn
, kTXNStartOffset
, kTXNEndOffset
, &theText
, kTXNUnicodeTextData
);
1399 actualSize
= GetHandleSize( theText
) / sizeof( UniChar
) ;
1400 if ( actualSize
> 0 )
1402 wxChar
*ptr
= NULL
;
1403 #if SIZEOF_WCHAR_T == 2
1404 ptr
= new wxChar
[actualSize
+ 1 ] ;
1405 wxStrncpy( ptr
, (wxChar
*) *theText
, actualSize
) ;
1407 SetHandleSize( theText
, ( actualSize
+ 1 ) * sizeof( UniChar
) ) ;
1409 (((UniChar
*)*theText
)[actualSize
]) = 0 ;
1410 wxMBConvUTF16BE converter
;
1411 size_t noChars
= converter
.MB2WC( NULL
, (const char*)*theText
, 0 ) ;
1412 ptr
= new wxChar
[noChars
+ 1] ;
1414 noChars
= converter
.MB2WC( ptr
, (const char*)*theText
, noChars
) ;
1416 HUnlock( theText
) ;
1418 ptr
[actualSize
] = 0 ;
1419 result
= wxString( ptr
) ;
1422 DisposeHandle( theText
) ;
1426 err
= TXNGetDataEncoded( m_txn
, kTXNStartOffset
, kTXNEndOffset
, &theText
, kTXNTextData
);
1434 actualSize
= GetHandleSize( theText
) ;
1435 if ( actualSize
> 0 )
1438 result
= wxString( *theText
, wxConvLocal
, actualSize
) ;
1439 HUnlock( theText
) ;
1441 DisposeHandle( theText
) ;
1446 wxMacConvertNewlines13To10( &result
) ;
1448 wxMacConvertNewlines10To13( &result
) ;
1453 void wxMacMLTEControl::SetStringValue( const wxString
&str
)
1457 wxMacConvertNewlines10To13( &st
) ;
1459 wxMacWindowClipper
c( m_peer
) ;
1461 wxMacEditHelper
help(m_txn
) ;
1462 SetTXNData( st
, kTXNStartOffset
, kTXNEndOffset
) ;
1464 TXNSetSelection( m_txn
, 0, 0);
1465 TXNShowSelection( m_txn
, kTXNShowStart
);
1469 TXNFrameOptions
wxMacMLTEControl::FrameOptionsFromWXStyle( long wxStyle
)
1471 TXNFrameOptions frameOptions
=
1472 kTXNDontDrawCaretWhenInactiveMask
;
1474 if ( ! ( wxStyle
& wxTE_NOHIDESEL
) )
1475 frameOptions
|= kTXNDontDrawSelectionWhenInactiveMask
;
1477 if ( wxStyle
& wxTE_MULTILINE
)
1479 if ( ! ( wxStyle
& wxTE_DONTWRAP
) )
1480 frameOptions
|= kTXNAlwaysWrapAtViewEdgeMask
;
1483 frameOptions
|= kTXNAlwaysWrapAtViewEdgeMask
;
1484 frameOptions
|= kTXNWantHScrollBarMask
;
1487 if ( !(wxStyle
& wxTE_NO_VSCROLL
) )
1489 frameOptions
|= kTXNWantVScrollBarMask
;
1490 if ( frameOptions
& kTXNWantHScrollBarMask
)
1491 frameOptions
|= kTXNDrawGrowIconMask
;
1495 frameOptions
|= kTXNSingleLineOnlyMask
;
1497 if ( wxStyle
& wxHSCROLL
)
1498 frameOptions
|= kTXNWantHScrollBarMask
;
1500 return frameOptions
;
1503 void wxMacMLTEControl::AdjustCreationAttributes( const wxColour
&background
, bool visible
)
1505 TXNControlTag iControlTags
[] =
1507 kTXNDoFontSubstitution
,
1508 kTXNWordWrapStateTag
,
1510 TXNControlData iControlData
[] =
1516 int toptag
= WXSIZEOF( iControlTags
) ;
1518 if ( m_windowStyle
& wxTE_MULTILINE
)
1520 if (m_windowStyle
& wxTE_DONTWRAP
)
1521 iControlData
[1].uValue
= kTXNNoAutoWrap
;
1523 iControlData
[1].uValue
= kTXNAutoWrap
;
1525 verify_noerr( TXNSetTXNObjectControls( m_txn
, false, toptag
,
1526 iControlTags
, iControlData
)) ;
1528 // setting the default font
1534 GetThemeFont(kThemeSystemFont
, GetApplicationScript() , fontName
, &fontSize
, &fontStyle
) ;
1536 TXNTypeAttributes typeAttr
[] =
1538 { kTXNQDFontNameAttribute
, kTXNQDFontNameAttributeSize
, { (void*) fontName
} } ,
1539 { kTXNQDFontSizeAttribute
, kTXNFontSizeAttributeSize
, { (void*) (fontSize
<< 16) } } ,
1540 { kTXNQDFontStyleAttribute
, kTXNQDFontStyleAttributeSize
, { (void*) normal
} } ,
1543 verify_noerr( TXNSetTypeAttributes (m_txn
, sizeof( typeAttr
) / sizeof(TXNTypeAttributes
) , typeAttr
,
1547 if ( m_windowStyle
& wxTE_PASSWORD
)
1550 verify_noerr(TXNEchoMode( m_txn
, c
, 0 , true )) ;
1553 TXNBackground tback
;
1554 tback
.bgType
= kTXNBackgroundTypeRGB
;
1555 tback
.bg
.color
= MAC_WXCOLORREF( background
.GetPixel() );
1556 TXNSetBackground( m_txn
, &tback
);
1559 void wxMacMLTEControl::SetBackground( const wxBrush
&brush
)
1561 // currently only solid background are supported
1562 TXNBackground tback
;
1563 tback
.bgType
= kTXNBackgroundTypeRGB
;
1564 tback
.bg
.color
= MAC_WXCOLORREF( brush
.GetColour().GetPixel() );
1565 TXNSetBackground( m_txn
, &tback
);
1568 void wxMacMLTEControl::TXNSetAttribute( const wxTextAttr
& style
, long from
, long to
)
1570 TXNTypeAttributes typeAttr
[4] ;
1571 Str255 fontName
= "\pMonaco" ;
1572 SInt16 fontSize
= 12 ;
1573 Style fontStyle
= normal
;
1575 int attrCounter
= 0 ;
1576 if ( style
.HasFont() )
1578 const wxFont
&font
= style
.GetFont() ;
1579 wxMacStringToPascal( font
.GetFaceName() , fontName
) ;
1580 fontSize
= font
.GetPointSize() ;
1581 if ( font
.GetUnderlined() )
1582 fontStyle
|= underline
;
1583 if ( font
.GetWeight() == wxBOLD
)
1585 if ( font
.GetStyle() == wxITALIC
)
1586 fontStyle
|= italic
;
1588 typeAttr
[attrCounter
].tag
= kTXNQDFontNameAttribute
;
1589 typeAttr
[attrCounter
].size
= kTXNQDFontNameAttributeSize
;
1590 typeAttr
[attrCounter
].data
.dataPtr
= (void*) fontName
;
1591 typeAttr
[attrCounter
+1].tag
= kTXNQDFontSizeAttribute
;
1592 typeAttr
[attrCounter
+1].size
= kTXNFontSizeAttributeSize
;
1593 typeAttr
[attrCounter
+1].data
.dataValue
= (fontSize
<< 16) ;
1594 typeAttr
[attrCounter
+2].tag
= kTXNQDFontStyleAttribute
;
1595 typeAttr
[attrCounter
+2].size
= kTXNQDFontStyleAttributeSize
;
1596 typeAttr
[attrCounter
+2].data
.dataValue
= fontStyle
;
1599 if ( style
.HasTextColour() )
1601 typeAttr
[attrCounter
].tag
= kTXNQDFontColorAttribute
;
1602 typeAttr
[attrCounter
].size
= kTXNQDFontColorAttributeSize
;
1603 typeAttr
[attrCounter
].data
.dataPtr
= (void*) &color
;
1604 color
= MAC_WXCOLORREF(style
.GetTextColour().GetPixel()) ;
1607 if ( attrCounter
> 0 )
1609 verify_noerr( TXNSetTypeAttributes ( m_txn
, attrCounter
, typeAttr
, from
, to
) );
1613 void wxMacMLTEControl::SetFont( const wxFont
& font
, const wxColour
& foreground
, long windowStyle
)
1615 wxMacEditHelper
help(m_txn
) ;
1616 TXNSetAttribute( wxTextAttr(foreground
,wxNullColour
,font
) , kTXNStartOffset
,kTXNEndOffset
) ;
1618 void wxMacMLTEControl::SetStyle(long start
, long end
, const wxTextAttr
& style
)
1620 wxMacEditHelper
help(m_txn
) ;
1621 TXNSetAttribute( style
, start
,end
) ;
1624 void wxMacMLTEControl::Copy()
1626 ClearCurrentScrap();
1628 TXNConvertToPublicScrap();
1631 void wxMacMLTEControl::Cut()
1633 ClearCurrentScrap();
1635 TXNConvertToPublicScrap();
1638 void wxMacMLTEControl::Paste()
1640 TXNConvertFromPublicScrap();
1644 bool wxMacMLTEControl::CanPaste() const
1646 return TXNIsScrapPastable() ;
1649 void wxMacMLTEControl::SetEditable(bool editable
)
1651 TXNControlTag tag
[] = { kTXNIOPrivilegesTag
} ;
1652 TXNControlData data
[] = { { editable
? kTXNReadWrite
: kTXNReadOnly
} } ;
1653 TXNSetTXNObjectControls( m_txn
, false , WXSIZEOF(tag
) , tag
, data
) ;
1656 wxTextPos
wxMacMLTEControl::GetLastPosition() const
1658 wxTextPos actualsize
= 0 ;
1661 OSErr err
= TXNGetDataEncoded( m_txn
, kTXNStartOffset
, kTXNEndOffset
, &theText
, kTXNTextData
);
1669 actualsize
= GetHandleSize( theText
) ;
1670 DisposeHandle( theText
) ;
1676 void wxMacMLTEControl::Replace( long from
, long to
, const wxString str
)
1678 wxString value
= str
;
1679 wxMacConvertNewlines10To13( &value
) ;
1681 wxMacEditHelper
help( m_txn
) ;
1682 wxMacWindowClipper
c( m_peer
) ;
1684 TXNSetSelection(m_txn
, from
, to
) ;
1686 SetTXNData( value
, kTXNUseCurrentSelection
, kTXNUseCurrentSelection
) ;
1689 void wxMacMLTEControl::Remove( long from
, long to
)
1691 wxMacWindowClipper
c( m_peer
) ;
1692 wxMacEditHelper
help( m_txn
) ;
1693 TXNSetSelection(m_txn
, from
, to
) ;
1697 void wxMacMLTEControl::GetSelection( long* from
, long* to
) const
1699 TXNGetSelection( m_txn
, (TXNOffset
*) from
, (TXNOffset
*) to
) ;
1702 void wxMacMLTEControl::SetSelection( long from
, long to
)
1704 wxMacWindowClipper
c( m_peer
) ;
1705 /* change the selection */
1706 if ((from
== -1) && (to
== -1))
1707 TXNSelectAll(m_txn
);
1709 TXNSetSelection( m_txn
, from
, to
);
1710 TXNShowSelection( m_txn
, kTXNShowStart
);
1713 void wxMacMLTEControl::WriteText(const wxString
& str
)
1716 wxMacConvertNewlines10To13( &st
) ;
1718 long start
, end
, dummy
;
1719 GetSelection( &start
, &dummy
) ;
1720 wxMacWindowClipper
c( m_peer
) ;
1722 wxMacEditHelper
helper( m_txn
) ;
1723 SetTXNData( st
, kTXNUseCurrentSelection
, kTXNUseCurrentSelection
) ;
1725 GetSelection( &dummy
, &end
) ;
1726 // TODO SetStyle( start , end , GetDefaultStyle() ) ;
1729 void wxMacMLTEControl::Clear()
1731 wxMacWindowClipper
c( m_peer
) ;
1732 wxMacEditHelper
st(m_txn
) ;
1733 TXNSetSelection( m_txn
, kTXNStartOffset
, kTXNEndOffset
) ;
1737 bool wxMacMLTEControl::CanUndo() const
1739 return TXNCanUndo( m_txn
, NULL
) ;
1742 void wxMacMLTEControl::Undo()
1747 bool wxMacMLTEControl::CanRedo() const
1749 return TXNCanRedo( m_txn
, NULL
) ;
1752 void wxMacMLTEControl::Redo()
1757 int wxMacMLTEControl::GetNumberOfLines() const
1759 ItemCount lines
= 0 ;
1760 TXNGetLineCount(m_txn
, &lines
) ;
1764 long wxMacMLTEControl::XYToPosition(long x
, long y
) const
1768 wxTextPos lastpos
= GetLastPosition() ;
1770 // TODO find a better implementation : while we can get the
1771 // line metrics of a certain line, we don't get its starting
1772 // position, so it would probably be rather a binary search
1773 // for the start position
1776 int lastHeight
= 0 ;
1779 for ( n
= 0 ; n
<= (ItemCount
) lastpos
; ++n
)
1781 if ( y
== ypos
&& x
== xpos
)
1784 TXNOffsetToPoint( m_txn
, n
, &curpt
);
1786 if ( curpt
.v
> lastHeight
)
1791 lastHeight
= curpt
.v
;
1799 bool wxMacMLTEControl::PositionToXY(long pos
, long *x
, long *y
) const
1803 wxTextPos lastpos
= GetLastPosition() ;
1808 if ( pos
<= lastpos
)
1810 // TODO find a better implementation : while we can get the
1811 // line metrics of a certain line, we don't get its starting
1812 // position, so it would probably be rather a binary search
1813 // for the start position
1816 int lastHeight
= 0 ;
1819 for ( n
= 0 ; n
<= (ItemCount
) pos
; ++n
)
1821 TXNOffsetToPoint(m_txn
, n
, &curpt
);
1823 if ( curpt
.v
> lastHeight
)
1828 lastHeight
= curpt
.v
;
1833 if ( y
) *y
= ypos
;
1834 if ( x
) *x
= xpos
;
1840 void wxMacMLTEControl::ShowPosition( long pos
)
1842 #if TARGET_RT_MAC_MACHO && defined(AVAILABLE_MAC_OS_X_VERSION_10_2_AND_LATER)
1846 TXNOffset selstart
, selend
;
1847 TXNGetSelection( m_txn
, &selstart
, &selend
) ;
1848 TXNOffsetToPoint( m_txn
, selstart
, ¤t
);
1849 TXNOffsetToPoint( m_txn
, pos
, &desired
);
1850 //TODO use HIPoints for 10.3 and above
1851 if ( (UInt32
) TXNScroll
!= (UInt32
) kUnresolvedCFragSymbolAddress
)
1853 OSErr theErr
= noErr
;
1854 SInt32 dv
= desired
.v
- current
.v
;
1855 SInt32 dh
= desired
.h
- current
.h
;
1856 TXNShowSelection( m_txn
, true ) ;
1857 theErr
= TXNScroll( m_txn
, kTXNScrollUnitsInPixels
, kTXNScrollUnitsInPixels
, &dv
, &dh
);
1858 wxASSERT_MSG( theErr
== noErr
, _T("TXNScroll returned an error!") );
1864 void wxMacMLTEControl::SetTXNData( const wxString
& st
, TXNOffset start
, TXNOffset end
)
1867 #if SIZEOF_WCHAR_T == 2
1868 size_t len
= st
.Len() ;
1869 TXNSetData( m_txn
, kTXNUnicodeTextData
, (void*)st
.wc_str(), len
* 2,
1872 wxMBConvUTF16BE converter
;
1873 ByteCount byteBufferLen
= converter
.WC2MB( NULL
, st
.wc_str() , 0 ) ;
1874 UniChar
*unibuf
= (UniChar
*) malloc(byteBufferLen
) ;
1875 converter
.WC2MB( (char*) unibuf
, st
.wc_str() , byteBufferLen
) ;
1876 TXNSetData( m_txn
, kTXNUnicodeTextData
, (void*)unibuf
, byteBufferLen
,
1881 wxCharBuffer text
= st
.mb_str(wxConvLocal
) ;
1882 TXNSetData( m_txn
, kTXNTextData
, (void*)text
.data(), strlen( text
) ,
1888 wxString
wxMacMLTEControl::GetLineText(long lineNo
) const
1892 if ( lineNo
< GetNumberOfLines() )
1900 // get the first possible position in the control
1902 TXNOffsetToPoint(m_txn
, 0, &firstPoint
);
1904 // Iterate through the lines until we reach the one we want,
1905 // adding to our current y pixel point position
1906 while (ypos
< lineNo
)
1908 TXNGetLineMetrics(m_txn
, ypos
++, &lineWidth
, &lineHeight
);
1909 currentHeight
+= lineHeight
;
1912 Point thePoint
= { firstPoint
.v
+ (currentHeight
>> 16), firstPoint
.h
+ (0) };
1913 TXNOffset theOffset
;
1914 TXNPointToOffset(m_txn
, thePoint
, &theOffset
);
1916 wxString content
= GetStringValue() ;
1917 Point currentPoint
= thePoint
;
1918 while(thePoint
.v
== currentPoint
.v
&& theOffset
< content
.length())
1920 line
+= content
[theOffset
];
1921 TXNOffsetToPoint(m_txn
, ++theOffset
, ¤tPoint
);
1927 int wxMacMLTEControl::GetLineLength(long lineNo
) const
1931 if ( lineNo
< GetNumberOfLines() )
1939 // get the first possible position in the control
1941 TXNOffsetToPoint(m_txn
, 0, &firstPoint
);
1943 // Iterate through the lines until we reach the one we want,
1944 // adding to our current y pixel point position
1945 while (ypos
< lineNo
)
1947 TXNGetLineMetrics(m_txn
, ypos
++, &lineWidth
, &lineHeight
);
1948 currentHeight
+= lineHeight
;
1951 Point thePoint
= { firstPoint
.v
+ (currentHeight
>> 16), firstPoint
.h
+ (0) };
1952 TXNOffset theOffset
;
1953 TXNPointToOffset(m_txn
, thePoint
, &theOffset
);
1955 wxString content
= GetStringValue() ;
1956 Point currentPoint
= thePoint
;
1957 while(thePoint
.v
== currentPoint
.v
&& theOffset
< content
.length())
1960 TXNOffsetToPoint(m_txn
, ++theOffset
, ¤tPoint
);
1967 // ----------------------------------------------------------------------------
1968 // MLTE control implementation (classic part)
1969 // ----------------------------------------------------------------------------
1971 // OS X Notes : We still don't have a full replacement for MLTE, so this implementation
1972 // has to live on. We have different problems coming from outdated implementations on the
1973 // various OS X versions. Most deal with the scrollbars: they are not correctly embedded
1974 // while this can be solved on 10.3 by reassigning them the correct place, on 10.2 there is
1975 // no way out, therefore we are using our own implementation and our own scrollbars ....
1977 #ifdef __WXMAC_OSX__
1979 TXNScrollInfoUPP gTXNScrollInfoProc
= NULL
;
1980 ControlActionUPP gTXNScrollActionProc
= NULL
;
1982 pascal void wxMacMLTEClassicControl::TXNScrollInfoProc (SInt32 iValue
, SInt32 iMaximumValue
, TXNScrollBarOrientation
1983 iScrollBarOrientation
, SInt32 iRefCon
)
1985 wxMacMLTEClassicControl
* mlte
= (wxMacMLTEClassicControl
*) iRefCon
;
1986 SInt32 value
= wxMax( iValue
, 0 ) ;
1987 SInt32 maximum
= wxMax( iMaximumValue
, 0 ) ;
1989 if ( iScrollBarOrientation
== kTXNHorizontal
)
1991 if ( mlte
->m_sbHorizontal
)
1993 SetControl32BitValue( mlte
->m_sbHorizontal
, value
) ;
1994 SetControl32BitMaximum( mlte
->m_sbHorizontal
, maximum
) ;
1995 mlte
->m_lastHorizontalValue
= value
;
1998 else if ( iScrollBarOrientation
== kTXNVertical
)
2000 if ( mlte
->m_sbVertical
)
2002 SetControl32BitValue( mlte
->m_sbVertical
, value
) ;
2003 SetControl32BitMaximum( mlte
->m_sbVertical
, maximum
) ;
2004 mlte
->m_lastVerticalValue
= value
;
2009 pascal void wxMacMLTEClassicControl::TXNScrollActionProc( ControlRef controlRef
, ControlPartCode partCode
)
2012 wxMacMLTEClassicControl
* mlte
= (wxMacMLTEClassicControl
*) GetControlReference( controlRef
) ;
2016 if ( controlRef
!= mlte
->m_sbVertical
&& controlRef
!= mlte
->m_sbHorizontal
)
2019 bool isHorizontal
= ( controlRef
== mlte
->m_sbHorizontal
) ;
2021 SInt32 minimum
= 0 ;
2022 SInt32 maximum
= GetControl32BitMaximum( controlRef
) ;
2023 SInt32 value
= GetControl32BitValue( controlRef
) ;
2027 case kControlDownButtonPart
:
2030 case kControlUpButtonPart
:
2033 case kControlPageDownPart
:
2034 delta
= GetControlViewSize( controlRef
) ;
2036 case kControlPageUpPart
:
2037 delta
= -GetControlViewSize( controlRef
) ;
2039 case kControlIndicatorPart
:
2041 ( isHorizontal
? mlte
->m_lastHorizontalValue
: mlte
->m_lastVerticalValue
) ;
2048 SInt32 newValue
= value
;
2050 if ( partCode
!= kControlIndicatorPart
)
2052 if( value
+ delta
< minimum
)
2053 delta
= minimum
- value
;
2054 if ( value
+ delta
> maximum
)
2055 delta
= maximum
- value
;
2057 SetControl32BitValue( controlRef
, value
+ delta
) ;
2058 newValue
= value
+ delta
;
2061 SInt32 verticalDelta
= isHorizontal
? 0 : delta
;
2062 SInt32 horizontalDelta
= isHorizontal
? delta
: 0 ;
2064 err
= TXNScroll( mlte
->m_txn
, kTXNScrollUnitsInPixels
, kTXNScrollUnitsInPixels
,
2065 &verticalDelta
, &horizontalDelta
);
2068 mlte
->m_lastHorizontalValue
= newValue
;
2070 mlte
->m_lastVerticalValue
= newValue
;
2075 // make correct activations
2076 void wxMacMLTEClassicControl::MacActivatePaneText(Boolean setActive
)
2078 wxTextCtrl
* textctrl
= (wxTextCtrl
*) GetControlReference(m_controlRef
);
2080 wxMacWindowClipper
clipper( textctrl
) ;
2081 TXNActivate(m_txn
, m_txnFrameID
, setActive
);
2083 ControlRef controlFocus
= 0 ;
2084 GetKeyboardFocus( m_txnWindow
, &controlFocus
) ;
2085 if ( controlFocus
== m_controlRef
)
2086 TXNFocus( m_txn
, setActive
);
2089 void wxMacMLTEClassicControl::MacFocusPaneText(Boolean setFocus
)
2091 TXNFocus( m_txn
, setFocus
);
2094 // guards against inappropriate redraw (hidden objects drawing onto window)
2096 void wxMacMLTEClassicControl::MacSetObjectVisibility(Boolean vis
)
2098 ControlRef controlFocus
= 0 ;
2099 GetKeyboardFocus( m_txnWindow
, &controlFocus
) ;
2101 if ( controlFocus
== m_controlRef
&& vis
== false )
2103 SetKeyboardFocus( m_txnWindow
, m_controlRef
, kControlFocusNoPart
) ;
2105 // we right now are always clipping as partial visibility (overlapped) visibility
2106 // is also a problem, if we run into further problems we might set the FrameBounds to an empty
2110 // make sure that the TXNObject is at the right position
2112 void wxMacMLTEClassicControl::MacUpdatePosition()
2114 wxTextCtrl
* textctrl
= (wxTextCtrl
*) GetControlReference(m_controlRef
);
2115 if ( textctrl
== NULL
)
2119 UMAGetControlBoundsInWindowCoords(m_controlRef
, &bounds
);
2121 if ( !EqualRect( &bounds
, &m_txnControlBounds
) )
2124 Rect oldBounds
= m_txnControlBounds
;
2125 m_txnControlBounds
= bounds
;
2126 wxMacWindowClipper
cl(textctrl
) ;
2128 #ifdef __WXMAC_OSX__
2129 bool isCompositing
= textctrl
->MacGetTopLevelWindow()->MacUsesCompositing() ;
2130 if ( m_sbHorizontal
|| m_sbVertical
)
2132 int w
= bounds
.right
- bounds
.left
;
2133 int h
= bounds
.bottom
- bounds
.top
;
2135 if ( m_sbHorizontal
)
2139 sbBounds
.left
= -1 ;
2140 sbBounds
.top
= h
- 14 ;
2141 sbBounds
.right
= w
+ 1 ;
2142 sbBounds
.bottom
= h
+ 1 ;
2144 if ( !isCompositing
)
2145 OffsetRect( &sbBounds
, m_txnControlBounds
.left
, m_txnControlBounds
.top
) ;
2147 SetControlBounds( m_sbHorizontal
, &sbBounds
) ;
2148 SetControlViewSize( m_sbHorizontal
, w
) ;
2154 sbBounds
.left
= w
- 14 ;
2156 sbBounds
.right
= w
+ 1 ;
2157 sbBounds
.bottom
= m_sbHorizontal
? h
- 14 : h
+ 1 ;
2159 if ( !isCompositing
)
2160 OffsetRect( &sbBounds
, m_txnControlBounds
.left
, m_txnControlBounds
.top
) ;
2162 SetControlBounds( m_sbVertical
, &sbBounds
) ;
2163 SetControlViewSize( m_sbVertical
, h
) ;
2166 TXNSetFrameBounds( m_txn
, m_txnControlBounds
.top
, m_txnControlBounds
.left
,
2167 m_txnControlBounds
.bottom
- ( m_sbHorizontal
? 14 : 0 ) , m_txnControlBounds
.right
- ( m_sbVertical
? 14 : 0 ), m_txnFrameID
);
2170 TXNSetFrameBounds( m_txn
, m_txnControlBounds
.top
, m_txnControlBounds
.left
,
2171 wxMax( m_txnControlBounds
.bottom
, m_txnControlBounds
.top
) ,
2172 wxMax( m_txnControlBounds
.right
, m_txnControlBounds
.left
) , m_txnFrameID
);
2174 // the SetFrameBounds method unter classic sometimes does not correctly scroll a selection into sight after a
2175 // movement, therefore we have to force it
2177 TXNLongRect textRect
;
2178 TXNGetRectBounds( m_txn
, NULL
, NULL
, &textRect
) ;
2179 if ( textRect
.left
< m_txnControlBounds
.left
)
2181 TXNShowSelection( m_txn
, false ) ;
2187 void wxMacMLTEClassicControl::SetRect( Rect
*r
)
2189 wxMacControl::SetRect( r
) ;
2190 MacUpdatePosition() ;
2193 void wxMacMLTEClassicControl::MacControlUserPaneDrawProc(wxInt16 thePart
)
2195 wxTextCtrl
* textctrl
= (wxTextCtrl
*) GetControlReference(m_controlRef
);
2196 if ( textctrl
== NULL
)
2199 if ( textctrl
->MacIsReallyShown() )
2201 wxMacWindowClipper
clipper( textctrl
) ;
2202 TXNDraw( m_txn
, NULL
) ;
2206 wxInt16
wxMacMLTEClassicControl::MacControlUserPaneHitTestProc(wxInt16 x
, wxInt16 y
)
2208 Point where
= { y
, x
} ;
2209 ControlPartCode result
;
2212 wxTextCtrl
* textctrl
= (wxTextCtrl
*) GetControlReference(m_controlRef
);
2213 if ( textctrl
== NULL
)
2216 if (textctrl
->MacIsReallyShown() )
2218 if (PtInRect(where
, &m_txnControlBounds
))
2219 result
= kControlEditTextPart
;
2222 // sometimes we get the coords also in control local coordinates, therefore test again
2223 if ( textctrl
->MacGetTopLevelWindow()->MacUsesCompositing() )
2226 textctrl
->MacClientToRootWindow( &x
, &y
) ;
2230 if (PtInRect(where
, &m_txnControlBounds
))
2231 result
= kControlEditTextPart
;
2239 wxInt16
wxMacMLTEClassicControl::MacControlUserPaneTrackingProc( wxInt16 x
, wxInt16 y
, void* actionProc
)
2241 wxTextCtrl
* textctrl
= (wxTextCtrl
*) GetControlReference(m_controlRef
);
2242 if ( textctrl
== NULL
)
2245 ControlPartCode partCodeResult
= 0;
2247 if (textctrl
->MacIsReallyShown() )
2249 Point startPt
= { y
,x
} ;
2250 // for compositing, we must convert these into toplevel window coordinates, because hittesting expects them
2251 if ( textctrl
->MacGetTopLevelWindow()->MacUsesCompositing() )
2254 textctrl
->MacClientToRootWindow( &x
, &y
) ;
2259 switch (MacControlUserPaneHitTestProc( startPt
.h
, startPt
.v
))
2261 case kControlEditTextPart
:
2263 wxMacWindowClipper
clipper( textctrl
) ;
2266 ConvertEventRefToEventRecord( (EventRef
) wxTheApp
->MacGetCurrentEvent() , &rec
) ;
2267 TXNClick( m_txn
, &rec
);
2273 return partCodeResult
;
2276 void wxMacMLTEClassicControl::MacControlUserPaneIdleProc()
2278 wxTextCtrl
* textctrl
= (wxTextCtrl
*) GetControlReference(m_controlRef
);
2279 if ( textctrl
== NULL
)
2282 if (textctrl
->MacIsReallyShown())
2284 if (IsControlActive(m_controlRef
))
2288 wxMacWindowClipper
clipper( textctrl
) ;
2293 if (PtInRect(mousep
, &m_txnControlBounds
))
2296 RectRgn((theRgn
= NewRgn()), &m_txnControlBounds
);
2297 TXNAdjustCursor(m_txn
, theRgn
);
2304 wxInt16
wxMacMLTEClassicControl::MacControlUserPaneKeyDownProc (wxInt16 keyCode
, wxInt16 charCode
, wxInt16 modifiers
)
2306 wxTextCtrl
* textctrl
= (wxTextCtrl
*) GetControlReference(m_controlRef
);
2307 if ( textctrl
== NULL
)
2310 wxMacWindowClipper
clipper( textctrl
) ;
2313 memset( &ev
, 0 , sizeof( ev
) ) ;
2315 ev
.modifiers
= modifiers
;
2316 ev
.message
= (( keyCode
<< 8 ) & keyCodeMask
) + ( charCode
& charCodeMask
) ;
2317 TXNKeyDown( m_txn
, &ev
);
2319 return kControlEntireControl
;
2322 void wxMacMLTEClassicControl::MacControlUserPaneActivateProc( bool activating
)
2324 MacActivatePaneText( activating
);
2327 wxInt16
wxMacMLTEClassicControl::MacControlUserPaneFocusProc(wxInt16 action
)
2329 ControlPartCode focusResult
;
2331 focusResult
= kControlFocusNoPart
;
2332 wxTextCtrl
* textctrl
= (wxTextCtrl
*) GetControlReference(m_controlRef
);
2333 if ( textctrl
== NULL
)
2336 wxMacWindowClipper
clipper( textctrl
) ;
2338 ControlRef controlFocus
= 0 ;
2339 GetKeyboardFocus( m_txnWindow
, &controlFocus
) ;
2340 bool wasFocused
= ( controlFocus
== m_controlRef
) ;
2344 case kControlFocusPrevPart
:
2345 case kControlFocusNextPart
:
2346 MacFocusPaneText( ( !wasFocused
));
2347 focusResult
= (!wasFocused
) ? kControlEditTextPart
: kControlFocusNoPart
;
2350 case kControlFocusNoPart
:
2352 MacFocusPaneText( false);
2353 focusResult
= kControlFocusNoPart
;
2360 void wxMacMLTEClassicControl::MacControlUserPaneBackgroundProc( void *info
)
2364 wxMacMLTEClassicControl::wxMacMLTEClassicControl( wxTextCtrl
*wxPeer
,
2365 const wxString
& str
,
2367 const wxSize
& size
, long style
) : wxMacMLTEControl( wxPeer
)
2369 m_font
= wxPeer
->GetFont() ;
2370 m_windowStyle
= style
;
2371 Rect bounds
= wxMacGetBoundsForControl( wxPeer
, pos
, size
) ;
2373 wxMacConvertNewlines10To13( &st
) ;
2377 featurSet
= kControlSupportsEmbedding
| kControlSupportsFocus
| kControlWantsIdle
2378 | kControlWantsActivate
| kControlHandlesTracking
| kControlHasSpecialBackground
2379 | kControlGetsFocusOnClick
| kControlSupportsLiveFeedback
;
2381 verify_noerr( ::CreateUserPaneControl( MAC_WXHWND(wxPeer
->GetParent()->MacGetTopLevelWindowRef()), &bounds
, featurSet
, &m_controlRef
) );
2385 MacSetObjectVisibility( wxPeer
->MacIsReallyShown() ) ;
2387 AdjustCreationAttributes( *wxWHITE
, true) ;
2389 wxMacWindowClipper
clipper( m_peer
) ;
2390 SetTXNData( st
, kTXNStartOffset
, kTXNEndOffset
) ;
2391 TXNSetSelection( m_txn
, 0, 0);
2394 wxMacMLTEClassicControl::~wxMacMLTEClassicControl()
2396 TXNDeleteObject(m_txn
);
2400 void wxMacMLTEClassicControl::VisibilityChanged(bool shown
)
2402 MacSetObjectVisibility( shown
) ;
2403 wxMacControl::VisibilityChanged( shown
) ;
2406 void wxMacMLTEClassicControl::SuperChangedPosition()
2408 MacUpdatePosition() ;
2409 wxMacControl::SuperChangedPosition() ;
2412 #ifdef __WXMAC_OSX__
2414 ControlUserPaneDrawUPP gTPDrawProc
= NULL
;
2415 ControlUserPaneHitTestUPP gTPHitProc
= NULL
;
2416 ControlUserPaneTrackingUPP gTPTrackProc
= NULL
;
2417 ControlUserPaneIdleUPP gTPIdleProc
= NULL
;
2418 ControlUserPaneKeyDownUPP gTPKeyProc
= NULL
;
2419 ControlUserPaneActivateUPP gTPActivateProc
= NULL
;
2420 ControlUserPaneFocusUPP gTPFocusProc
= NULL
;
2422 static pascal void wxMacControlUserPaneDrawProc(ControlRef control
, SInt16 part
)
2424 wxTextCtrl
*textCtrl
= wxDynamicCast( wxFindControlFromMacControl(control
) , wxTextCtrl
) ;
2425 wxMacMLTEClassicControl
* win
= textCtrl
? dynamic_cast<wxMacMLTEClassicControl
*>(textCtrl
->GetPeer()) : NULL
;
2427 win
->MacControlUserPaneDrawProc(part
) ;
2430 static pascal ControlPartCode
wxMacControlUserPaneHitTestProc(ControlRef control
, Point where
)
2432 wxTextCtrl
*textCtrl
= wxDynamicCast( wxFindControlFromMacControl(control
) , wxTextCtrl
) ;
2433 wxMacMLTEClassicControl
* win
= textCtrl
? dynamic_cast<wxMacMLTEClassicControl
*>(textCtrl
->GetPeer()) : NULL
;
2435 return win
->MacControlUserPaneHitTestProc(where
.h
, where
.v
) ;
2437 return kControlNoPart
;
2440 static pascal ControlPartCode
wxMacControlUserPaneTrackingProc(ControlRef control
, Point startPt
, ControlActionUPP actionProc
)
2442 wxTextCtrl
*textCtrl
= wxDynamicCast( wxFindControlFromMacControl(control
) , wxTextCtrl
) ;
2443 wxMacMLTEClassicControl
* win
= textCtrl
? dynamic_cast<wxMacMLTEClassicControl
*>(textCtrl
->GetPeer()) : NULL
;
2445 return win
->MacControlUserPaneTrackingProc( startPt
.h
, startPt
.v
, (void*) actionProc
) ;
2447 return kControlNoPart
;
2450 static pascal void wxMacControlUserPaneIdleProc(ControlRef control
)
2452 wxTextCtrl
*textCtrl
= wxDynamicCast( wxFindControlFromMacControl(control
) , wxTextCtrl
) ;
2453 wxMacMLTEClassicControl
* win
= textCtrl
? dynamic_cast<wxMacMLTEClassicControl
*>(textCtrl
->GetPeer()) : NULL
;
2455 win
->MacControlUserPaneIdleProc() ;
2458 static pascal ControlPartCode
wxMacControlUserPaneKeyDownProc(ControlRef control
, SInt16 keyCode
, SInt16 charCode
, SInt16 modifiers
)
2460 wxTextCtrl
*textCtrl
= wxDynamicCast( wxFindControlFromMacControl(control
) , wxTextCtrl
) ;
2461 wxMacMLTEClassicControl
* win
= textCtrl
? dynamic_cast<wxMacMLTEClassicControl
*>(textCtrl
->GetPeer()) : NULL
;
2463 return win
->MacControlUserPaneKeyDownProc(keyCode
,charCode
,modifiers
) ;
2465 return kControlNoPart
;
2468 static pascal void wxMacControlUserPaneActivateProc(ControlRef control
, Boolean activating
)
2470 wxTextCtrl
*textCtrl
= wxDynamicCast( wxFindControlFromMacControl(control
) , wxTextCtrl
) ;
2471 wxMacMLTEClassicControl
* win
= textCtrl
? dynamic_cast<wxMacMLTEClassicControl
*>(textCtrl
->GetPeer()) : NULL
;
2473 win
->MacControlUserPaneActivateProc(activating
) ;
2476 static pascal ControlPartCode
wxMacControlUserPaneFocusProc(ControlRef control
, ControlFocusPart action
)
2478 wxTextCtrl
*textCtrl
= wxDynamicCast( wxFindControlFromMacControl(control
) , wxTextCtrl
) ;
2479 wxMacMLTEClassicControl
* win
= textCtrl
? dynamic_cast<wxMacMLTEClassicControl
*>(textCtrl
->GetPeer()) : NULL
;
2481 return win
->MacControlUserPaneFocusProc(action
) ;
2483 return kControlNoPart
;
2486 static pascal void wxMacControlUserPaneBackgroundProc(ControlRef control
, ControlBackgroundPtr info
)
2488 wxTextCtrl
*textCtrl
= wxDynamicCast( wxFindControlFromMacControl(control
) , wxTextCtrl
) ;
2489 wxMacMLTEClassicControl
* win
= textCtrl
? dynamic_cast<wxMacMLTEClassicControl
*>(textCtrl
->GetPeer()) : NULL
;
2491 win
->MacControlUserPaneBackgroundProc(info
) ;
2495 // TXNRegisterScrollInfoProc
2497 OSStatus
wxMacMLTEClassicControl::DoCreate()
2501 OSStatus err
= noErr
;
2503 /* set up our globals */
2504 #ifdef __WXMAC_OSX__
2505 if (gTPDrawProc
== NULL
) gTPDrawProc
= NewControlUserPaneDrawUPP(wxMacControlUserPaneDrawProc
);
2506 if (gTPHitProc
== NULL
) gTPHitProc
= NewControlUserPaneHitTestUPP(wxMacControlUserPaneHitTestProc
);
2507 if (gTPTrackProc
== NULL
) gTPTrackProc
= NewControlUserPaneTrackingUPP(wxMacControlUserPaneTrackingProc
);
2508 if (gTPIdleProc
== NULL
) gTPIdleProc
= NewControlUserPaneIdleUPP(wxMacControlUserPaneIdleProc
);
2509 if (gTPKeyProc
== NULL
) gTPKeyProc
= NewControlUserPaneKeyDownUPP(wxMacControlUserPaneKeyDownProc
);
2510 if (gTPActivateProc
== NULL
) gTPActivateProc
= NewControlUserPaneActivateUPP(wxMacControlUserPaneActivateProc
);
2511 if (gTPFocusProc
== NULL
) gTPFocusProc
= NewControlUserPaneFocusUPP(wxMacControlUserPaneFocusProc
);
2513 if (gTXNScrollInfoProc
== NULL
) gTXNScrollInfoProc
= NewTXNScrollInfoUPP(TXNScrollInfoProc
) ;
2514 if (gTXNScrollActionProc
== NULL
) gTXNScrollActionProc
= NewControlActionUPP(TXNScrollActionProc
) ;
2517 /* set the initial settings for our private data */
2519 m_txnWindow
=GetControlOwner(m_controlRef
);
2520 m_txnPort
= (GrafPtr
) GetWindowPort(m_txnWindow
);
2522 #ifdef __WXMAC_OSX__
2523 /* set up the user pane procedures */
2524 SetControlData(m_controlRef
, kControlEntireControl
, kControlUserPaneDrawProcTag
, sizeof(gTPDrawProc
), &gTPDrawProc
);
2525 SetControlData(m_controlRef
, kControlEntireControl
, kControlUserPaneHitTestProcTag
, sizeof(gTPHitProc
), &gTPHitProc
);
2526 SetControlData(m_controlRef
, kControlEntireControl
, kControlUserPaneTrackingProcTag
, sizeof(gTPTrackProc
), &gTPTrackProc
);
2527 SetControlData(m_controlRef
, kControlEntireControl
, kControlUserPaneIdleProcTag
, sizeof(gTPIdleProc
), &gTPIdleProc
);
2528 SetControlData(m_controlRef
, kControlEntireControl
, kControlUserPaneKeyDownProcTag
, sizeof(gTPKeyProc
), &gTPKeyProc
);
2529 SetControlData(m_controlRef
, kControlEntireControl
, kControlUserPaneActivateProcTag
, sizeof(gTPActivateProc
), &gTPActivateProc
);
2530 SetControlData(m_controlRef
, kControlEntireControl
, kControlUserPaneFocusProcTag
, sizeof(gTPFocusProc
), &gTPFocusProc
);
2532 /* calculate the rectangles used by the control */
2533 UMAGetControlBoundsInWindowCoords(m_controlRef
, &bounds
);
2535 m_txnControlBounds
= bounds
;
2537 CGrafPtr origPort
= NULL
;
2538 GDHandle origDev
= NULL
;
2539 GetGWorld( &origPort
, &origDev
) ;
2542 /* create the new edit field */
2544 TXNFrameOptions frameOptions
= FrameOptionsFromWXStyle( m_windowStyle
) ;
2546 #ifdef __WXMAC_OSX__
2548 // the scrollbars are not correctly embedded but are inserted at the root
2549 // this gives us problems as we have erratic redraws even over the structure
2552 m_sbHorizontal
= 0 ;
2554 m_lastHorizontalValue
= 0 ;
2555 m_lastVerticalValue
= 0 ;
2557 Rect sb
= { 0 , 0 , 0 , 0 } ;
2558 if ( frameOptions
& kTXNWantVScrollBarMask
)
2560 CreateScrollBarControl( m_txnWindow
, &sb
, 0 , 0 , 100 , 1 , true , gTXNScrollActionProc
, &m_sbVertical
) ;
2561 SetControlReference( m_sbVertical
, (SInt32
) this ) ;
2562 SetControlAction( m_sbVertical
, gTXNScrollActionProc
);
2563 ShowControl( m_sbVertical
) ;
2564 EmbedControl( m_sbVertical
, m_controlRef
) ;
2565 frameOptions
&= ~kTXNWantVScrollBarMask
;
2567 if ( frameOptions
& kTXNWantHScrollBarMask
)
2569 CreateScrollBarControl( m_txnWindow
, &sb
, 0 , 0 , 100 , 1 , true , gTXNScrollActionProc
, &m_sbHorizontal
) ;
2570 SetControlReference( m_sbHorizontal
, (SInt32
) this ) ;
2571 SetControlAction( m_sbHorizontal
, gTXNScrollActionProc
);
2572 ShowControl( m_sbHorizontal
) ;
2573 EmbedControl( m_sbHorizontal
, m_controlRef
) ;
2574 frameOptions
&= ~(kTXNWantHScrollBarMask
| kTXNDrawGrowIconMask
);
2579 verify_noerr(TXNNewObject(NULL
, m_txnWindow
, &bounds
,
2581 kTXNTextEditStyleFrameType
,
2583 kTXNSystemDefaultEncoding
,
2584 &m_txn
, &m_txnFrameID
, NULL
) );
2586 #ifdef __WXMAC_OSX__
2587 TXNRegisterScrollInfoProc( m_txn
, gTXNScrollInfoProc
, (SInt32
) this);
2590 SetGWorld( origPort
, origDev
) ;
2594 // ----------------------------------------------------------------------------
2595 // MLTE control implementation (OSX part)
2596 // ----------------------------------------------------------------------------
2598 #if TARGET_API_MAC_OSX
2600 #if MAC_OS_X_VERSION_MAX_ALLOWED > MAC_OS_X_VERSION_10_2
2602 wxMacMLTEHIViewControl::wxMacMLTEHIViewControl( wxTextCtrl
*wxPeer
,
2603 const wxString
& str
,
2605 const wxSize
& size
, long style
) : wxMacMLTEControl( wxPeer
)
2607 m_font
= wxPeer
->GetFont() ;
2608 m_windowStyle
= style
;
2609 Rect bounds
= wxMacGetBoundsForControl( wxPeer
, pos
, size
) ;
2611 wxMacConvertNewlines10To13( &st
) ;
2613 HIRect hr
= { bounds
.left
, bounds
.top
, bounds
.right
- bounds
.left
, bounds
.bottom
- bounds
.top
} ;
2615 m_scrollView
= NULL
;
2616 TXNFrameOptions frameOptions
= FrameOptionsFromWXStyle( style
) ;
2617 if ( frameOptions
& (kTXNWantVScrollBarMask
|kTXNWantHScrollBarMask
) )
2619 HIScrollViewCreate(( frameOptions
& kTXNWantHScrollBarMask
? kHIScrollViewOptionsHorizScroll
: 0) |
2620 ( frameOptions
& kTXNWantVScrollBarMask
? kHIScrollViewOptionsVertScroll
: 0 ) , &m_scrollView
) ;
2622 HIViewSetFrame( m_scrollView
, &hr
);
2623 HIViewSetVisible( m_scrollView
, true );
2627 HITextViewCreate( NULL
, 0, frameOptions
, &m_textView
) ;
2628 m_txn
= HITextViewGetTXNObject( m_textView
) ;
2629 HIViewSetVisible( m_textView
, true ) ;
2632 HIViewAddSubview( m_scrollView
, m_textView
) ;
2633 m_controlRef
= m_scrollView
;
2634 wxPeer
->MacInstallEventHandler( (WXWidget
) m_textView
) ;
2638 HIViewSetFrame( m_textView
, &hr
);
2639 m_controlRef
= m_textView
;
2642 AdjustCreationAttributes( *wxWHITE
, true ) ;
2644 wxMacWindowClipper
c( m_peer
) ;
2645 SetTXNData( st
, kTXNStartOffset
, kTXNEndOffset
) ;
2647 TXNSetSelection( m_txn
, 0, 0);
2648 TXNShowSelection( m_txn
, kTXNShowStart
);
2652 OSStatus
wxMacMLTEHIViewControl::SetFocus( ControlFocusPart focusPart
)
2654 return SetKeyboardFocus( GetControlOwner( m_textView
) ,
2655 m_textView
, focusPart
) ;
2658 bool wxMacMLTEHIViewControl::HasFocus() const
2660 ControlRef control
;
2661 GetKeyboardFocus( GetUserFocusWindow() , &control
) ;
2662 return control
== m_textView
;
2665 #endif // MAC_OS_X_VERSION_MAX_ALLOWED > MAC_OS_X_VERSION_10_2
2670 #endif // wxUSE_TEXTCTRL