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"
48 #include "wx/sysopt.h"
50 #if defined(__BORLANDC__) && !defined(__WIN32__)
52 #elif !defined(__MWERKS__) && !defined(__GNUWIN32) && !defined(__DARWIN__)
60 // if this is set to 1 then under OSX 10.2 the 'classic' MLTE implementation will be used
61 // if set to 0 then the unicode textctrl will be used
62 #ifndef wxMAC_AWAYS_USE_MLTE
63 #define wxMAC_AWAYS_USE_MLTE 1
69 kTXNVisibilityTag
= 'visb' /*set the visibility state of the object */
73 #include <MacTextEditor.h>
74 #include <ATSUnicode.h>
75 #include <TextCommon.h>
76 #include <TextEncodingConverter.h>
77 #include "wx/mac/uma.h"
83 virtual ~wxMacFunctor() {}
84 virtual void* operator()() = 0 ;
85 static void* CallBackProc(void *param
)
87 wxMacFunctor
* f
= (wxMacFunctor
*) param
;
88 void *result
= (*f
)() ;
93 template<typename classtype
,typename param1type
>
94 class wxMacObjectFunctor1
: public wxMacFunctor
96 typedef void (classtype::*function
)( param1type p1
) ;
97 typedef void (classtype::*ref_function
)( const param1type
& p1
) ;
99 wxMacObjectFunctor1( classtype
*obj
, function f
, param1type p1
) :
107 wxMacObjectFunctor1( classtype
*obj
, ref_function f
, param1type p1
) :
115 ~wxMacObjectFunctor1() {}
117 virtual void* operator()()
119 (m_object
->*m_function
)(m_param1
) ;
123 classtype
* m_object
;
124 param1type m_param1
;
127 function m_function
;
128 ref_function m_refFunction
;
132 template<typename classtype
, typename param1type
>
133 void* wxMacMPRemoteCall( classtype
*object
, void (classtype::*function
)( param1type p1
) , param1type p1
)
135 wxMacObjectFunctor1
<classtype
,param1type
> params(object
,function
,p1
) ;
137 MPRemoteCall( wxMacFunctor::CallBackProc
, ¶ms
, kMPOwningProcessRemoteContext
) ;
141 template<typename classtype
, typename param1type
>
142 void* wxMacMPRemoteCall( classtype
*object
, void (classtype::*function
)( const param1type
& p1
) , param1type p1
)
144 wxMacObjectFunctor1
<classtype
,param1type
> params(object
,function
,p1
) ;
146 MPRemoteCall( wxMacFunctor::CallBackProc
, ¶ms
, kMPOwningProcessRemoteContext
) ;
150 template<typename classtype
, typename param1type
>
151 void* wxMacMPRemoteGUICall( classtype
*object
, void (classtype::*function
)( param1type p1
) , param1type p1
)
154 void *result
= wxMacMPRemoteCall( object
, function
, p1
) ;
159 template<typename classtype
, typename param1type
>
160 void* wxMacMPRemoteGUICall( classtype
*object
, void (classtype::*function
)( const param1type
& p1
) , param1type p1
)
163 void *result
= wxMacMPRemoteCall( object
, function
, p1
) ;
167 // common interface for all implementations
168 class wxMacTextControl
: public wxMacControl
171 wxMacTextControl( wxTextCtrl
*peer
) ;
172 ~wxMacTextControl() ;
174 virtual wxString
GetStringValue() const = 0 ;
175 virtual void SetStringValue( const wxString
&val
) = 0 ;
176 virtual void SetStyle(long start
, long end
, const wxTextAttr
& style
) ;
177 virtual void Copy() ;
179 virtual void Paste() ;
180 virtual bool CanPaste() const ;
181 virtual void SetEditable(bool editable
) ;
182 virtual wxTextPos
GetLastPosition() const ;
183 virtual void Replace( long from
, long to
, const wxString str
) ;
184 virtual void Remove( long from
, long to
) = 0 ;
185 virtual void SetSelection( long from
, long to
) = 0 ;
186 virtual void GetSelection( long* from
, long* to
) const = 0 ;
187 virtual void WriteText(const wxString
& str
) = 0 ;
189 virtual void Clear() ;
190 virtual bool CanUndo() const;
191 virtual void Undo() ;
192 virtual bool CanRedo() const;
193 virtual void Redo() ;
194 virtual int GetNumberOfLines() const ;
195 virtual long XYToPosition(long x
, long y
) const;
196 virtual bool PositionToXY(long pos
, long *x
, long *y
) const ;
197 virtual void ShowPosition( long WXUNUSED(pos
) ) ;
198 virtual int GetLineLength(long lineNo
) const ;
199 virtual wxString
GetLineText(long lineNo
) const ;
200 virtual bool SetupCursor( const wxPoint
& pt
) { return false ; }
202 #ifndef __WXMAC_OSX__
203 virtual void MacControlUserPaneDrawProc(wxInt16 part
) = 0 ;
204 virtual wxInt16
MacControlUserPaneHitTestProc(wxInt16 x
, wxInt16 y
) = 0 ;
205 virtual wxInt16
MacControlUserPaneTrackingProc(wxInt16 x
, wxInt16 y
, void* actionProc
) = 0 ;
206 virtual void MacControlUserPaneIdleProc() = 0 ;
207 virtual wxInt16
MacControlUserPaneKeyDownProc(wxInt16 keyCode
, wxInt16 charCode
, wxInt16 modifiers
) = 0 ;
208 virtual void MacControlUserPaneActivateProc(bool activating
) = 0 ;
209 virtual wxInt16
MacControlUserPaneFocusProc(wxInt16 action
) = 0 ;
210 virtual void MacControlUserPaneBackgroundProc(void* info
) = 0 ;
214 // common parts for implementations based on MLTE
216 class wxMacMLTEControl
: public wxMacTextControl
219 wxMacMLTEControl( wxTextCtrl
*peer
) ;
220 virtual wxString
GetStringValue() const ;
221 virtual void SetStringValue( const wxString
&str
) ;
223 static TXNFrameOptions
FrameOptionsFromWXStyle( long wxStyle
) ;
224 void AdjustCreationAttributes( const wxColour
& background
, bool visible
) ;
226 virtual void SetFont( const wxFont
& font
, const wxColour
& foreground
, long windowStyle
) ;
227 virtual void SetBackground( const wxBrush
&brush
) ;
228 virtual void SetStyle(long start
, long end
, const wxTextAttr
& style
) ;
229 virtual void Copy() ;
231 virtual void Paste() ;
232 virtual bool CanPaste() const ;
233 virtual void SetEditable(bool editable
) ;
234 virtual wxTextPos
GetLastPosition() const ;
235 virtual void Replace( long from
, long to
, const wxString str
) ;
236 virtual void Remove( long from
, long to
) ;
237 virtual void GetSelection( long* from
, long* to
) const ;
238 virtual void SetSelection( long from
, long to
) ;
240 virtual void WriteText(const wxString
& str
) ;
241 virtual void Clear() ;
243 virtual bool CanUndo() const ;
244 virtual void Undo() ;
245 virtual bool CanRedo() const;
246 virtual void Redo() ;
247 virtual int GetNumberOfLines() const ;
248 virtual long XYToPosition(long x
, long y
) const ;
249 virtual bool PositionToXY(long pos
, long *x
, long *y
) const ;
250 virtual void ShowPosition( long pos
) ;
251 virtual int GetLineLength(long lineNo
) const ;
252 virtual wxString
GetLineText(long lineNo
) const ;
254 void SetTXNData( const wxString
& st
, TXNOffset start
, TXNOffset end
) ;
257 void TXNSetAttribute( const wxTextAttr
& style
, long from
, long to
) ;
261 #if TARGET_API_MAC_OSX
263 // implementation available under OSX
265 #if MAC_OS_X_VERSION_MAX_ALLOWED > MAC_OS_X_VERSION_10_2
267 class wxMacMLTEHIViewControl
: public wxMacMLTEControl
270 wxMacMLTEHIViewControl( wxTextCtrl
*wxPeer
,
273 const wxSize
& size
, long style
) ;
274 virtual OSStatus
SetFocus( ControlFocusPart focusPart
) ;
275 virtual bool HasFocus() const ;
277 HIViewRef m_scrollView
;
278 HIViewRef m_textView
;
283 class wxMacUnicodeTextControl
: public wxMacTextControl
286 wxMacUnicodeTextControl( wxTextCtrl
*wxPeer
,
289 const wxSize
& size
, long style
) ;
290 ~wxMacUnicodeTextControl();
291 virtual void VisibilityChanged(bool shown
);
292 virtual wxString
GetStringValue() const ;
293 virtual void SetStringValue( const wxString
&str
) ;
296 virtual void Paste();
297 virtual bool CanPaste() const;
298 virtual void SetEditable(bool editable
) ;
299 virtual void Remove( long from
, long to
) ;
300 virtual void GetSelection( long* from
, long* to
) const ;
301 virtual void SetSelection( long from
, long to
) ;
302 virtual void WriteText(const wxString
& str
) ;
304 // contains the tag for the content (is different for password and non-password controls)
310 // 'classic' MLTE implementation
312 class wxMacMLTEClassicControl
: public wxMacMLTEControl
315 wxMacMLTEClassicControl( wxTextCtrl
*wxPeer
,
318 const wxSize
& size
, long style
) ;
319 ~wxMacMLTEClassicControl() ;
320 virtual void VisibilityChanged(bool shown
) ;
321 virtual void SuperChangedPosition() ;
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 bool SetupCursor( const wxPoint
& WXUNUSED(pt
) ) { MacControlUserPaneIdleProc() ; return true ;}
334 virtual void SetRect( Rect
*r
) ;
339 void MacUpdatePosition() ;
340 void MacActivatePaneText(Boolean setActive
) ;
341 void MacFocusPaneText(Boolean setFocus
) ;
343 void MacSetObjectVisibility(Boolean vis
) ;
345 TXNFrameID m_txnFrameID
;
347 WindowRef m_txnWindow
;
348 // bounds of the control as we last did set the txn frames
349 Rect m_txnControlBounds
;
350 Rect m_txnVisBounds
;
352 static pascal void TXNScrollInfoProc (SInt32 iValue
, SInt32 iMaximumValue
,
353 TXNScrollBarOrientation iScrollBarOrientation
, SInt32 iRefCon
) ;
354 static pascal void TXNScrollActionProc( ControlRef controlRef
, ControlPartCode partCode
) ;
355 ControlRef m_sbHorizontal
;
356 SInt32 m_lastHorizontalValue
;
357 ControlRef m_sbVertical
;
358 SInt32 m_lastVerticalValue
;
362 #define TE_UNLIMITED_LENGTH 0xFFFFFFFFUL
364 #if !USE_SHARED_LIBRARY
365 IMPLEMENT_DYNAMIC_CLASS(wxTextCtrl
, wxControl
)
367 BEGIN_EVENT_TABLE(wxTextCtrl
, wxControl
)
368 EVT_ERASE_BACKGROUND( wxTextCtrl::OnEraseBackground
)
369 EVT_DROP_FILES(wxTextCtrl::OnDropFiles
)
370 EVT_CHAR(wxTextCtrl::OnChar
)
371 EVT_MENU(wxID_CUT
, wxTextCtrl::OnCut
)
372 EVT_MENU(wxID_COPY
, wxTextCtrl::OnCopy
)
373 EVT_MENU(wxID_PASTE
, wxTextCtrl::OnPaste
)
374 EVT_MENU(wxID_UNDO
, wxTextCtrl::OnUndo
)
375 EVT_MENU(wxID_REDO
, wxTextCtrl::OnRedo
)
377 EVT_UPDATE_UI(wxID_CUT
, wxTextCtrl::OnUpdateCut
)
378 EVT_UPDATE_UI(wxID_COPY
, wxTextCtrl::OnUpdateCopy
)
379 EVT_UPDATE_UI(wxID_PASTE
, wxTextCtrl::OnUpdatePaste
)
380 EVT_UPDATE_UI(wxID_UNDO
, wxTextCtrl::OnUpdateUndo
)
381 EVT_UPDATE_UI(wxID_REDO
, wxTextCtrl::OnUpdateRedo
)
386 void wxTextCtrl::Init()
391 m_maxLength
= TE_UNLIMITED_LENGTH
;
394 wxTextCtrl::~wxTextCtrl()
399 bool wxTextCtrl::Create(wxWindow
*parent
, wxWindowID id
,
402 const wxSize
& size
, long style
,
403 const wxValidator
& validator
,
404 const wxString
& name
)
406 m_macIsUserPane
= false ;
409 if ( ! ( style
& wxNO_BORDER
) )
410 style
= ( style
& ~wxBORDER_MASK
) | wxSUNKEN_BORDER
;
412 if ( !wxTextCtrlBase::Create(parent
, id
, pos
, size
, style
& ~(wxHSCROLL
|wxVSCROLL
), validator
, name
) )
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
;
424 bool forceMLTE
= false ;
425 #if wxUSE_SYSTEM_OPTIONS
426 if ( (wxSystemOptions::HasOption(wxMAC_TEXTCONTROL_USE_MLTE
) ) && ( wxSystemOptions::GetOptionInt( wxMAC_TEXTCONTROL_USE_MLTE
) == 1) )
433 #if MAC_OS_X_VERSION_MAX_ALLOWED > MAC_OS_X_VERSION_10_2
434 if ( UMAGetSystemVersion() >= 0x1030 && forceMLTE
== false )
436 if ( m_windowStyle
& wxTE_MULTILINE
)
437 m_peer
= new wxMacMLTEHIViewControl( this , str
, pos
, size
, style
) ;
442 if ( !(m_windowStyle
& wxTE_MULTILINE
) && forceMLTE
== false )
443 m_peer
= new wxMacUnicodeTextControl( this , str
, pos
, size
, style
) ;
448 m_peer
= new wxMacMLTEClassicControl( this , str
, pos
, size
, style
) ;
451 MacPostControlCreate(pos
,size
) ;
453 // only now the embedding is correct and we can do a positioning update
455 MacSuperChangedPosition() ;
457 if ( m_windowStyle
& wxTE_READONLY
)
459 SetEditable( false ) ;
462 SetCursor( wxCursor( wxCURSOR_IBEAM
) ) ;
467 void wxTextCtrl::MacSuperChangedPosition()
469 wxWindow::MacSuperChangedPosition() ;
470 GetPeer()->SuperChangedPosition() ;
473 void wxTextCtrl::MacVisibilityChanged()
475 GetPeer()->VisibilityChanged( MacIsReallyShown() ) ;
478 void wxTextCtrl::MacEnabledStateChanged()
482 wxString
wxTextCtrl::GetValue() const
484 return GetPeer()->GetStringValue() ;
487 void wxTextCtrl::GetSelection(long* from
, long* to
) const
489 GetPeer()->GetSelection( from
, to
) ;
492 void wxTextCtrl::SetValue(const wxString
& str
)
495 if ( GetValue() == str
)
498 GetPeer()->SetStringValue(str
) ;
500 wxCommandEvent
event(wxEVT_COMMAND_TEXT_UPDATED
, m_windowId
);
501 event
.SetString( GetValue() ) ;
502 event
.SetEventObject( this );
503 GetEventHandler()->ProcessEvent(event
);
506 void wxTextCtrl::SetMaxLength(unsigned long len
)
511 bool wxTextCtrl::SetFont( const wxFont
& font
)
513 if ( !wxTextCtrlBase::SetFont( font
) )
516 GetPeer()->SetFont( font
, GetForegroundColour() , GetWindowStyle() ) ;
520 bool wxTextCtrl::SetStyle(long start
, long end
, const wxTextAttr
& style
)
522 GetPeer()->SetStyle( start
, end
, style
) ;
526 bool wxTextCtrl::SetDefaultStyle(const wxTextAttr
& style
)
528 wxTextCtrlBase::SetDefaultStyle( style
) ;
529 SetStyle( kTXNUseCurrentSelection
, kTXNUseCurrentSelection
, GetDefaultStyle() ) ;
533 // Clipboard operations
534 void wxTextCtrl::Copy()
542 void wxTextCtrl::Cut()
548 wxCommandEvent
event(wxEVT_COMMAND_TEXT_UPDATED
, m_windowId
);
549 event
.SetEventObject( this );
550 GetEventHandler()->ProcessEvent(event
);
554 void wxTextCtrl::Paste()
559 // eventually we should add setting the default style again
561 wxCommandEvent
event(wxEVT_COMMAND_TEXT_UPDATED
, m_windowId
);
562 event
.SetEventObject( this );
563 GetEventHandler()->ProcessEvent(event
);
567 bool wxTextCtrl::CanCopy() const
569 // Can copy if there's a selection
571 GetSelection(& from
, & to
);
575 bool wxTextCtrl::CanCut() const
581 // Can cut if there's a selection
583 GetSelection(& from
, & to
);
587 bool wxTextCtrl::CanPaste() const
592 return GetPeer()->CanPaste() ;
595 void wxTextCtrl::SetEditable(bool editable
)
597 if ( editable
!= m_editable
)
599 m_editable
= editable
;
600 GetPeer()->SetEditable( editable
) ;
604 void wxTextCtrl::SetInsertionPoint(long pos
)
606 SetSelection( pos
, pos
) ;
609 void wxTextCtrl::SetInsertionPointEnd()
611 wxTextPos pos
= GetLastPosition();
612 SetInsertionPoint(pos
);
615 long wxTextCtrl::GetInsertionPoint() const
618 GetSelection( &begin
, &end
) ;
622 wxTextPos
wxTextCtrl::GetLastPosition() const
624 return GetPeer()->GetLastPosition( ) ;
627 void wxTextCtrl::Replace(long from
, long to
, const wxString
& str
)
629 GetPeer()->Replace( from
, to
, str
) ;
632 void wxTextCtrl::Remove(long from
, long to
)
634 GetPeer()->Remove( from
, to
) ;
637 void wxTextCtrl::SetSelection(long from
, long to
)
639 GetPeer()->SetSelection( from
, to
) ;
642 bool wxTextCtrl::LoadFile(const wxString
& file
)
644 if ( wxTextCtrlBase::LoadFile(file
) )
652 void wxTextCtrl::WriteText(const wxString
& str
)
654 // TODO this MPRemoting will be moved into a remoting peer proxy for any command
655 if ( !wxIsMainThread() )
657 // unfortunately CW 8 is not able to correctly deduce the template types, so we have
658 // to instantiate explicitely
659 wxMacMPRemoteGUICall
<wxTextCtrl
,wxString
>( this , &wxTextCtrl::WriteText
, str
) ;
664 GetPeer()->WriteText( str
) ;
668 void wxTextCtrl::AppendText(const wxString
& text
)
670 SetInsertionPointEnd();
674 void wxTextCtrl::Clear()
679 bool wxTextCtrl::IsModified() const
684 bool wxTextCtrl::IsEditable() const
686 return IsEnabled() && m_editable
;
689 bool wxTextCtrl::AcceptsFocus() const
691 // we don't want focus if we can't be edited
692 return /*IsEditable() && */ wxControl::AcceptsFocus();
695 wxSize
wxTextCtrl::DoGetBestSize() const
701 // these are the numbers from the HIG, we reduce them by the borders
704 switch( m_windowVariant
)
706 case wxWINDOW_VARIANT_NORMAL
:
709 case wxWINDOW_VARIANT_SMALL
:
712 case wxWINDOW_VARIANT_MINI
:
720 // as the above numbers have some free space around the text
721 // we get 5 lines like this anyway
722 if ( m_windowStyle
& wxTE_MULTILINE
)
727 if ( !HasFlag(wxNO_BORDER
) )
730 return wxSize(wText
, hText
);
733 // ----------------------------------------------------------------------------
735 // ----------------------------------------------------------------------------
737 void wxTextCtrl::Undo()
745 void wxTextCtrl::Redo()
753 bool wxTextCtrl::CanUndo() const
759 return GetPeer()->CanUndo() ;
762 bool wxTextCtrl::CanRedo() const
768 return GetPeer()->CanRedo() ;
771 void wxTextCtrl::MarkDirty()
776 void wxTextCtrl::DiscardEdits()
781 int wxTextCtrl::GetNumberOfLines() const
783 return GetPeer()->GetNumberOfLines() ;
786 long wxTextCtrl::XYToPosition(long x
, long y
) const
788 return GetPeer()->XYToPosition( x
, y
) ;
791 bool wxTextCtrl::PositionToXY(long pos
, long *x
, long *y
) const
793 return GetPeer()->PositionToXY(pos
, x
, y
) ;
796 void wxTextCtrl::ShowPosition(long pos
)
798 return GetPeer()->ShowPosition(pos
) ;
801 int wxTextCtrl::GetLineLength(long lineNo
) const
803 return GetPeer()->GetLineLength(lineNo
) ;
806 wxString
wxTextCtrl::GetLineText(long lineNo
) const
808 return GetPeer()->GetLineText(lineNo
) ;
815 void wxTextCtrl::Command(wxCommandEvent
& event
)
817 SetValue (event
.GetString());
818 ProcessCommand (event
);
821 void wxTextCtrl::OnDropFiles(wxDropFilesEvent
& event
)
823 // By default, load the first file into the text window.
824 if (event
.GetNumberOfFiles() > 0)
826 LoadFile(event
.GetFiles()[0]);
830 void wxTextCtrl::OnEraseBackground(wxEraseEvent
& event
)
832 // all erasing should be done by the real mac control implementation
833 // while this is true for MLTE under classic, the HITextView is somehow
834 // transparent but background erase is not working correctly, so intercept
835 // things while we can...
839 void wxTextCtrl::OnChar(wxKeyEvent
& event
)
841 int key
= event
.GetKeyCode() ;
842 bool eat_key
= false ;
844 if ( key
== 'c' && event
.MetaDown() )
851 if ( !IsEditable() && key
!= WXK_LEFT
&& key
!= WXK_RIGHT
&& key
!= WXK_DOWN
&& key
!= WXK_UP
&& key
!= WXK_TAB
&&
852 !( key
== WXK_RETURN
&& ( (m_windowStyle
& wxPROCESS_ENTER
) || (m_windowStyle
& wxTE_MULTILINE
) ) )
853 /* && key != WXK_PRIOR && key != WXK_NEXT && key != WXK_HOME && key != WXK_END */
860 // Check if we have reached the max # of chars, but still allow navigation and deletion
861 if ( !IsMultiLine() && GetValue().Length() >= m_maxLength
&&
862 key
!= WXK_LEFT
&& key
!= WXK_RIGHT
&& key
!= WXK_TAB
&&
863 key
!= WXK_BACK
&& !( key
== WXK_RETURN
&& (m_windowStyle
& wxPROCESS_ENTER
) )
866 // eat it, we don't want to add more than allowed # of characters
870 // assume that any key not processed yet is going to modify the control
873 if ( key
== 'v' && event
.MetaDown() )
879 if ( key
== 'x' && event
.MetaDown() )
888 if (m_windowStyle
& wxPROCESS_ENTER
)
890 wxCommandEvent
event(wxEVT_COMMAND_TEXT_ENTER
, m_windowId
);
891 event
.SetEventObject( this );
892 event
.SetString( GetValue() );
893 if ( GetEventHandler()->ProcessEvent(event
) )
896 if ( !(m_windowStyle
& wxTE_MULTILINE
) )
898 wxWindow
*parent
= GetParent();
899 while( parent
&& !parent
->IsTopLevel() && parent
->GetDefaultItem() == NULL
) {
900 parent
= parent
->GetParent() ;
902 if ( parent
&& parent
->GetDefaultItem() )
904 wxButton
*def
= wxDynamicCast(parent
->GetDefaultItem(),
906 if ( def
&& def
->IsEnabled() )
908 wxCommandEvent
event(wxEVT_COMMAND_BUTTON_CLICKED
, def
->GetId() );
909 event
.SetEventObject(def
);
915 // this will make wxWidgets eat the ENTER key so that
916 // we actually prevent line wrapping in a single line
924 if ( !(m_windowStyle
& wxTE_PROCESS_TAB
))
927 if (!event
.ShiftDown())
928 flags
|= wxNavigationKeyEvent::IsForward
;
929 if (event
.ControlDown())
930 flags
|= wxNavigationKeyEvent::WinChange
;
936 // This is necessary (don't know why) or the tab will not
938 WriteText(wxT("\t"));
946 // perform keystroke handling
947 if ( wxTheApp
->MacGetCurrentEvent() != NULL
&& wxTheApp
->MacGetCurrentEventHandlerCallRef() != NULL
)
948 CallNextEventHandler((EventHandlerCallRef
)wxTheApp
->MacGetCurrentEventHandlerCallRef() , (EventRef
) wxTheApp
->MacGetCurrentEvent() ) ;
952 if ( wxMacConvertEventToRecord( (EventRef
) wxTheApp
->MacGetCurrentEvent() , &rec
) )
954 EventRecord
*ev
= &rec
;
957 keychar
= short(ev
->message
& charCodeMask
);
958 keycode
= short(ev
->message
& keyCodeMask
) >> 8 ;
960 m_peer
->HandleKey( keycode
, keychar
, ev
->modifiers
) ;
964 if ( ( key
>= 0x20 && key
< WXK_START
) ||
969 wxCommandEvent
event1(wxEVT_COMMAND_TEXT_UPDATED
, m_windowId
);
970 event1
.SetEventObject( this );
971 wxPostEvent(GetEventHandler(),event1
);
975 // ----------------------------------------------------------------------------
976 // standard handlers for standard edit menu events
977 // ----------------------------------------------------------------------------
979 void wxTextCtrl::OnCut(wxCommandEvent
& WXUNUSED(event
))
984 void wxTextCtrl::OnCopy(wxCommandEvent
& WXUNUSED(event
))
989 void wxTextCtrl::OnPaste(wxCommandEvent
& WXUNUSED(event
))
994 void wxTextCtrl::OnUndo(wxCommandEvent
& WXUNUSED(event
))
999 void wxTextCtrl::OnRedo(wxCommandEvent
& WXUNUSED(event
))
1004 void wxTextCtrl::OnUpdateCut(wxUpdateUIEvent
& event
)
1006 event
.Enable( CanCut() );
1009 void wxTextCtrl::OnUpdateCopy(wxUpdateUIEvent
& event
)
1011 event
.Enable( CanCopy() );
1014 void wxTextCtrl::OnUpdatePaste(wxUpdateUIEvent
& event
)
1016 event
.Enable( CanPaste() );
1019 void wxTextCtrl::OnUpdateUndo(wxUpdateUIEvent
& event
)
1021 event
.Enable( CanUndo() );
1024 void wxTextCtrl::OnUpdateRedo(wxUpdateUIEvent
& event
)
1026 event
.Enable( CanRedo() );
1029 bool wxTextCtrl::MacSetupCursor( const wxPoint
& pt
)
1031 if ( !GetPeer()->SetupCursor(pt
) )
1032 return wxWindow::MacSetupCursor( pt
) ;
1036 #if !TARGET_API_MAC_OSX
1038 // user pane implementation
1040 void wxTextCtrl::MacControlUserPaneDrawProc(wxInt16 part
)
1042 GetPeer()->MacControlUserPaneDrawProc( part
) ;
1045 wxInt16
wxTextCtrl::MacControlUserPaneHitTestProc(wxInt16 x
, wxInt16 y
)
1047 return GetPeer()->MacControlUserPaneHitTestProc( x
, y
) ;
1050 wxInt16
wxTextCtrl::MacControlUserPaneTrackingProc(wxInt16 x
, wxInt16 y
, void* actionProc
)
1052 return GetPeer()->MacControlUserPaneTrackingProc( x
, y
, actionProc
) ;
1055 void wxTextCtrl::MacControlUserPaneIdleProc()
1057 GetPeer()->MacControlUserPaneIdleProc( ) ;
1060 wxInt16
wxTextCtrl::MacControlUserPaneKeyDownProc(wxInt16 keyCode
, wxInt16 charCode
, wxInt16 modifiers
)
1062 return GetPeer()->MacControlUserPaneKeyDownProc( keyCode
, charCode
, modifiers
) ;
1065 void wxTextCtrl::MacControlUserPaneActivateProc(bool activating
)
1067 GetPeer()->MacControlUserPaneActivateProc( activating
) ;
1070 wxInt16
wxTextCtrl::MacControlUserPaneFocusProc(wxInt16 action
)
1072 return GetPeer()->MacControlUserPaneFocusProc( action
) ;
1075 void wxTextCtrl::MacControlUserPaneBackgroundProc(void* info
)
1077 GetPeer()->MacControlUserPaneBackgroundProc( info
) ;
1081 // ----------------------------------------------------------------------------
1082 // implementation base class
1083 // ----------------------------------------------------------------------------
1085 wxMacTextControl::wxMacTextControl(wxTextCtrl
* peer
) :
1086 wxMacControl( peer
)
1090 wxMacTextControl::~wxMacTextControl()
1094 void wxMacTextControl::SetStyle(long start
, long end
, const wxTextAttr
& style
)
1098 void wxMacTextControl::Copy()
1102 void wxMacTextControl::Cut()
1106 void wxMacTextControl::Paste()
1110 bool wxMacTextControl::CanPaste() const
1115 void wxMacTextControl::SetEditable(bool editable
)
1119 wxTextPos
wxMacTextControl::GetLastPosition() const
1121 return GetStringValue().Length() ;
1124 void wxMacTextControl::Replace( long from
, long to
, const wxString str
)
1128 void wxMacTextControl::Clear()
1130 SetStringValue( wxEmptyString
) ;
1133 bool wxMacTextControl::CanUndo() const
1138 void wxMacTextControl::Undo() { }
1140 bool wxMacTextControl::CanRedo() const
1145 void wxMacTextControl::Redo()
1149 long wxMacTextControl::XYToPosition(long x
, long y
) const
1154 bool wxMacTextControl::PositionToXY(long pos
, long *x
, long *y
) const
1159 void wxMacTextControl::ShowPosition( long WXUNUSED(pos
) )
1163 int wxMacTextControl::GetNumberOfLines() const
1165 ItemCount lines
= 0 ;
1166 wxString content
= GetStringValue() ;
1168 for (size_t i
= 0; i
< content
.Length() ; i
++)
1170 if (content
[i
] == '\r') lines
++;
1175 wxString
wxMacTextControl::GetLineText(long lineNo
) const
1177 // TODO change this if possible to reflect real lines
1178 wxString content
= GetStringValue() ;
1182 for (size_t i
= 0; i
< content
.Length() ; i
++)
1184 if (count
== lineNo
)
1186 // Add chars in line then
1189 for (size_t j
= i
; j
< content
.Length(); j
++)
1191 if (content
[j
] == '\n')
1199 if (content
[i
] == '\n') count
++;
1201 return wxEmptyString
;
1204 int wxMacTextControl::GetLineLength(long lineNo
) const
1206 // TODO change this if possible to reflect real lines
1207 wxString content
= GetStringValue() ;
1211 for (size_t i
= 0; i
< content
.Length() ; i
++)
1213 if (count
== lineNo
)
1215 // Count chars in line then
1217 for (size_t j
= i
; j
< content
.Length(); j
++)
1220 if (content
[j
] == '\n') return count
;
1225 if (content
[i
] == '\n') count
++;
1230 // ----------------------------------------------------------------------------
1231 // standard unicode control implementation
1232 // ----------------------------------------------------------------------------
1234 #if TARGET_API_MAC_OSX
1236 wxMacUnicodeTextControl::wxMacUnicodeTextControl( wxTextCtrl
*wxPeer
,
1237 const wxString
& str
,
1239 const wxSize
& size
, long style
) : wxMacTextControl( wxPeer
)
1241 m_font
= wxPeer
->GetFont() ;
1242 m_windowStyle
= style
;
1243 Rect bounds
= wxMacGetBoundsForControl( wxPeer
, pos
, size
) ;
1245 wxMacConvertNewlines10To13( &st
) ;
1246 wxMacCFStringHolder
cf(st
, m_font
.GetEncoding()) ;
1247 CFStringRef cfr
= cf
;
1248 Boolean isPassword
= ( m_windowStyle
& wxTE_PASSWORD
) != 0 ;
1249 m_valueTag
= isPassword
? kControlEditTextPasswordCFStringTag
: kControlEditTextCFStringTag
;
1250 CreateEditUnicodeTextControl( MAC_WXHWND(wxPeer
->MacGetTopLevelWindowRef()), &bounds
, cfr
, isPassword
, NULL
, &m_controlRef
) ;
1252 if ( !(m_windowStyle
& wxTE_MULTILINE
) )
1254 SetData
<Boolean
>( kControlEditTextPart
, kControlEditTextSingleLineTag
, true ) ;
1258 wxMacUnicodeTextControl::~wxMacUnicodeTextControl()
1262 void wxMacUnicodeTextControl::VisibilityChanged(bool shown
)
1264 if ( !(m_windowStyle
& wxTE_MULTILINE
) && shown
)
1266 // work around a refresh issue insofar as not always the entire content is shown even if this would be possible
1267 ControlEditTextSelectionRec sel
;
1268 CFStringRef value
= NULL
;
1270 verify_noerr( GetData
<ControlEditTextSelectionRec
>( 0, kControlEditTextSelectionTag
, &sel
) );
1271 verify_noerr( GetData
<CFStringRef
>( 0, m_valueTag
, &value
) );
1272 verify_noerr( SetData
<CFStringRef
>( 0, m_valueTag
, &value
) );
1273 verify_noerr( SetData
<ControlEditTextSelectionRec
>( 0, kControlEditTextSelectionTag
, &sel
) );
1275 CFRelease( value
) ;
1278 wxString
wxMacUnicodeTextControl::GetStringValue() const
1281 CFStringRef value
= GetData
<CFStringRef
>(0,m_valueTag
) ;
1284 wxMacCFStringHolder
cf(value
) ;
1285 result
= cf
.AsString() ;
1288 wxMacConvertNewlines13To10( &result
) ;
1290 wxMacConvertNewlines10To13( &result
) ;
1294 void wxMacUnicodeTextControl::SetStringValue( const wxString
&str
)
1297 wxMacConvertNewlines10To13( &st
) ;
1298 wxMacCFStringHolder
cf(st
, m_font
.GetEncoding() ) ;
1299 verify_noerr( SetData
<CFStringRef
>( 0, m_valueTag
, cf
) ) ;
1301 void wxMacUnicodeTextControl::Copy()
1303 SendHICommand( kHICommandCopy
) ;
1305 void wxMacUnicodeTextControl::Cut()
1307 SendHICommand( kHICommandCut
) ;
1309 void wxMacUnicodeTextControl::Paste()
1311 SendHICommand( kHICommandPaste
) ;
1313 bool wxMacUnicodeTextControl::CanPaste() const
1317 void wxMacUnicodeTextControl::SetEditable(bool editable
)
1319 SetData
<Boolean
>( 0 , kControlEditTextLockedTag
, (Boolean
) !editable
) ;
1321 void wxMacUnicodeTextControl::Remove( long from
, long to
)
1325 void wxMacUnicodeTextControl::GetSelection( long* from
, long* to
) const
1327 ControlEditTextSelectionRec sel
;
1328 verify_noerr(GetData
<ControlEditTextSelectionRec
>( 0, kControlEditTextSelectionTag
, &sel
) ) ;
1329 if ( from
) *from
= sel
.selStart
;
1330 if ( to
) *to
= sel
.selEnd
;
1333 void wxMacUnicodeTextControl::SetSelection( long from
, long to
)
1335 ControlEditTextSelectionRec sel
;
1336 sel
.selStart
= from
;
1338 SetData
<ControlEditTextSelectionRec
>( 0 , kControlEditTextSelectionTag
, &sel
) ;
1341 void wxMacUnicodeTextControl::WriteText(const wxString
& str
)
1344 wxMacConvertNewlines10To13( &st
) ;
1345 #if MAC_OS_X_VERSION_MAX_ALLOWED > MAC_OS_X_VERSION_10_2
1346 wxMacCFStringHolder
cf(st
, m_font
.GetEncoding() ) ;
1347 CFStringRef value
= cf
;
1348 SetData
<CFStringRef
>( 0, kControlEditTextInsertCFStringRefTag
, &value
);
1350 wxString val
= GetStringValue() ;
1352 GetSelection( &start
, &end
) ;
1353 val
.Remove( start
, end
- start
) ;
1354 val
.insert( start
, str
) ;
1355 SetStringValue( val
) ;
1356 SetSelection( start
+ str
.Length() , start
+ str
.Length() ) ;
1362 // ----------------------------------------------------------------------------
1363 // MLTE control implementation (common part)
1364 // ----------------------------------------------------------------------------
1366 // if mlte is on read only , no changes at all are allowed, not even from
1367 // procedural API, in order to allow changes via API all the same we must undo
1368 // the readonly status while we are executing, this class helps to do so
1370 class wxMacEditHelper
1373 wxMacEditHelper( TXNObject txn
)
1375 TXNControlTag tag
[] = { kTXNIOPrivilegesTag
} ;
1377 TXNGetTXNObjectControls( m_txn
, 1 , tag
, m_data
) ;
1378 if ( m_data
[0].uValue
== kTXNReadOnly
)
1380 TXNControlData data
[] = { { kTXNReadWrite
} } ;
1381 TXNSetTXNObjectControls( m_txn
, false , 1 , tag
, data
) ;
1386 TXNControlTag tag
[] = { kTXNIOPrivilegesTag
} ;
1387 if ( m_data
[0].uValue
== kTXNReadOnly
)
1389 TXNSetTXNObjectControls( m_txn
, false , 1 , tag
, m_data
) ;
1394 TXNControlData m_data
[1] ;
1397 wxMacMLTEControl::wxMacMLTEControl( wxTextCtrl
*peer
) : wxMacTextControl( peer
)
1399 SetNeedsFocusRect( true ) ;
1402 wxString
wxMacMLTEControl::GetStringValue() const
1406 Size actualSize
= 0;
1410 err
= TXNGetDataEncoded( m_txn
, kTXNStartOffset
, kTXNEndOffset
, &theText
, kTXNUnicodeTextData
);
1418 actualSize
= GetHandleSize( theText
) / sizeof( UniChar
) ;
1419 if ( actualSize
> 0 )
1421 wxChar
*ptr
= NULL
;
1422 #if SIZEOF_WCHAR_T == 2
1423 ptr
= new wxChar
[actualSize
+ 1 ] ;
1424 wxStrncpy( ptr
, (wxChar
*) *theText
, actualSize
) ;
1426 SetHandleSize( theText
, ( actualSize
+ 1 ) * sizeof( UniChar
) ) ;
1428 (((UniChar
*)*theText
)[actualSize
]) = 0 ;
1429 wxMBConvUTF16BE converter
;
1430 size_t noChars
= converter
.MB2WC( NULL
, (const char*)*theText
, 0 ) ;
1431 ptr
= new wxChar
[noChars
+ 1] ;
1433 noChars
= converter
.MB2WC( ptr
, (const char*)*theText
, noChars
) ;
1435 HUnlock( theText
) ;
1437 ptr
[actualSize
] = 0 ;
1438 result
= wxString( ptr
) ;
1441 DisposeHandle( theText
) ;
1445 err
= TXNGetDataEncoded( m_txn
, kTXNStartOffset
, kTXNEndOffset
, &theText
, kTXNTextData
);
1453 actualSize
= GetHandleSize( theText
) ;
1454 if ( actualSize
> 0 )
1457 result
= wxString( *theText
, wxConvLocal
, actualSize
) ;
1458 HUnlock( theText
) ;
1460 DisposeHandle( theText
) ;
1465 wxMacConvertNewlines13To10( &result
) ;
1467 wxMacConvertNewlines10To13( &result
) ;
1472 void wxMacMLTEControl::SetStringValue( const wxString
&str
)
1476 wxMacConvertNewlines10To13( &st
) ;
1478 wxMacWindowClipper
c( m_peer
) ;
1480 wxMacEditHelper
help(m_txn
) ;
1481 SetTXNData( st
, kTXNStartOffset
, kTXNEndOffset
) ;
1483 TXNSetSelection( m_txn
, 0, 0);
1484 TXNShowSelection( m_txn
, kTXNShowStart
);
1488 TXNFrameOptions
wxMacMLTEControl::FrameOptionsFromWXStyle( long wxStyle
)
1490 TXNFrameOptions frameOptions
=
1491 kTXNDontDrawCaretWhenInactiveMask
1492 #if MAC_OS_X_VERSION_MAX_ALLOWED >= MAC_OS_X_VERSION_10_3
1493 | kTXNDoFontSubstitutionMask
1497 if ( ! ( wxStyle
& wxTE_NOHIDESEL
) )
1498 frameOptions
|= kTXNDontDrawSelectionWhenInactiveMask
;
1500 if ( wxStyle
& wxTE_MULTILINE
)
1502 if ( ! ( wxStyle
& wxTE_DONTWRAP
) )
1503 frameOptions
|= kTXNAlwaysWrapAtViewEdgeMask
;
1506 frameOptions
|= kTXNAlwaysWrapAtViewEdgeMask
;
1507 frameOptions
|= kTXNWantHScrollBarMask
;
1510 if ( !(wxStyle
& wxTE_NO_VSCROLL
) )
1512 frameOptions
|= kTXNWantVScrollBarMask
;
1513 if ( frameOptions
& kTXNWantHScrollBarMask
)
1514 frameOptions
|= kTXNDrawGrowIconMask
;
1518 frameOptions
|= kTXNSingleLineOnlyMask
;
1520 if ( wxStyle
& wxHSCROLL
)
1521 frameOptions
|= kTXNWantHScrollBarMask
;
1523 return frameOptions
;
1526 void wxMacMLTEControl::AdjustCreationAttributes( const wxColour
&background
, bool visible
)
1528 TXNControlTag iControlTags
[] =
1530 kTXNDoFontSubstitution
,
1531 kTXNWordWrapStateTag
,
1533 TXNControlData iControlData
[] =
1539 int toptag
= WXSIZEOF( iControlTags
) ;
1541 if ( m_windowStyle
& wxTE_MULTILINE
)
1543 if (m_windowStyle
& wxTE_DONTWRAP
)
1544 iControlData
[1].uValue
= kTXNNoAutoWrap
;
1546 iControlData
[1].uValue
= kTXNAutoWrap
;
1548 verify_noerr( TXNSetTXNObjectControls( m_txn
, false, toptag
,
1549 iControlTags
, iControlData
)) ;
1551 // setting the default font
1552 // under 10.2 this causes a visible caret, therefore we avoid it
1554 if ( UMAGetSystemVersion() >= 0x1030 )
1560 GetThemeFont(kThemeSystemFont
, GetApplicationScript() , fontName
, &fontSize
, &fontStyle
) ;
1562 TXNTypeAttributes typeAttr
[] =
1564 { kTXNQDFontNameAttribute
, kTXNQDFontNameAttributeSize
, { (void*) fontName
} } ,
1565 { kTXNQDFontSizeAttribute
, kTXNFontSizeAttributeSize
, { (void*) (fontSize
<< 16) } } ,
1566 { kTXNQDFontStyleAttribute
, kTXNQDFontStyleAttributeSize
, { (void*) normal
} } ,
1569 verify_noerr( TXNSetTypeAttributes (m_txn
, sizeof( typeAttr
) / sizeof(TXNTypeAttributes
) , typeAttr
,
1574 if ( m_windowStyle
& wxTE_PASSWORD
)
1577 verify_noerr(TXNEchoMode( m_txn
, c
, 0 , true )) ;
1580 TXNBackground tback
;
1581 tback
.bgType
= kTXNBackgroundTypeRGB
;
1582 tback
.bg
.color
= MAC_WXCOLORREF( background
.GetPixel() );
1583 TXNSetBackground( m_txn
, &tback
);
1586 void wxMacMLTEControl::SetBackground( const wxBrush
&brush
)
1588 // currently only solid background are supported
1589 TXNBackground tback
;
1590 tback
.bgType
= kTXNBackgroundTypeRGB
;
1591 tback
.bg
.color
= MAC_WXCOLORREF( brush
.GetColour().GetPixel() );
1592 TXNSetBackground( m_txn
, &tback
);
1595 void wxMacMLTEControl::TXNSetAttribute( const wxTextAttr
& style
, long from
, long to
)
1597 TXNTypeAttributes typeAttr
[4] ;
1598 Str255 fontName
= "\pMonaco" ;
1599 SInt16 fontSize
= 12 ;
1600 Style fontStyle
= normal
;
1602 int attrCounter
= 0 ;
1603 if ( style
.HasFont() )
1605 const wxFont
&font
= style
.GetFont() ;
1606 wxMacStringToPascal( font
.GetFaceName() , fontName
) ;
1607 fontSize
= font
.GetPointSize() ;
1608 if ( font
.GetUnderlined() )
1609 fontStyle
|= underline
;
1610 if ( font
.GetWeight() == wxBOLD
)
1612 if ( font
.GetStyle() == wxITALIC
)
1613 fontStyle
|= italic
;
1615 typeAttr
[attrCounter
].tag
= kTXNQDFontNameAttribute
;
1616 typeAttr
[attrCounter
].size
= kTXNQDFontNameAttributeSize
;
1617 typeAttr
[attrCounter
].data
.dataPtr
= (void*) fontName
;
1618 typeAttr
[attrCounter
+1].tag
= kTXNQDFontSizeAttribute
;
1619 typeAttr
[attrCounter
+1].size
= kTXNFontSizeAttributeSize
;
1620 typeAttr
[attrCounter
+1].data
.dataValue
= (fontSize
<< 16) ;
1621 typeAttr
[attrCounter
+2].tag
= kTXNQDFontStyleAttribute
;
1622 typeAttr
[attrCounter
+2].size
= kTXNQDFontStyleAttributeSize
;
1623 typeAttr
[attrCounter
+2].data
.dataValue
= fontStyle
;
1626 if ( style
.HasTextColour() )
1628 typeAttr
[attrCounter
].tag
= kTXNQDFontColorAttribute
;
1629 typeAttr
[attrCounter
].size
= kTXNQDFontColorAttributeSize
;
1630 typeAttr
[attrCounter
].data
.dataPtr
= (void*) &color
;
1631 color
= MAC_WXCOLORREF(style
.GetTextColour().GetPixel()) ;
1634 if ( attrCounter
> 0 )
1636 verify_noerr( TXNSetTypeAttributes ( m_txn
, attrCounter
, typeAttr
, from
, to
) );
1640 void wxMacMLTEControl::SetFont( const wxFont
& font
, const wxColour
& foreground
, long windowStyle
)
1642 wxMacEditHelper
help(m_txn
) ;
1643 TXNSetAttribute( wxTextAttr(foreground
,wxNullColour
,font
) , kTXNStartOffset
,kTXNEndOffset
) ;
1645 void wxMacMLTEControl::SetStyle(long start
, long end
, const wxTextAttr
& style
)
1647 wxMacEditHelper
help(m_txn
) ;
1648 TXNSetAttribute( style
, start
,end
) ;
1651 void wxMacMLTEControl::Copy()
1653 ClearCurrentScrap();
1655 TXNConvertToPublicScrap();
1658 void wxMacMLTEControl::Cut()
1660 ClearCurrentScrap();
1662 TXNConvertToPublicScrap();
1665 void wxMacMLTEControl::Paste()
1667 TXNConvertFromPublicScrap();
1671 bool wxMacMLTEControl::CanPaste() const
1673 return TXNIsScrapPastable() ;
1676 void wxMacMLTEControl::SetEditable(bool editable
)
1678 TXNControlTag tag
[] = { kTXNIOPrivilegesTag
} ;
1679 TXNControlData data
[] = { { editable
? kTXNReadWrite
: kTXNReadOnly
} } ;
1680 TXNSetTXNObjectControls( m_txn
, false , WXSIZEOF(tag
) , tag
, data
) ;
1683 wxTextPos
wxMacMLTEControl::GetLastPosition() const
1685 wxTextPos actualsize
= 0 ;
1688 OSErr err
= TXNGetDataEncoded( m_txn
, kTXNStartOffset
, kTXNEndOffset
, &theText
, kTXNTextData
);
1696 actualsize
= GetHandleSize( theText
) ;
1697 DisposeHandle( theText
) ;
1703 void wxMacMLTEControl::Replace( long from
, long to
, const wxString str
)
1705 wxString value
= str
;
1706 wxMacConvertNewlines10To13( &value
) ;
1708 wxMacEditHelper
help( m_txn
) ;
1709 wxMacWindowClipper
c( m_peer
) ;
1711 TXNSetSelection(m_txn
, from
, to
) ;
1713 SetTXNData( value
, kTXNUseCurrentSelection
, kTXNUseCurrentSelection
) ;
1716 void wxMacMLTEControl::Remove( long from
, long to
)
1718 wxMacWindowClipper
c( m_peer
) ;
1719 wxMacEditHelper
help( m_txn
) ;
1720 TXNSetSelection(m_txn
, from
, to
) ;
1724 void wxMacMLTEControl::GetSelection( long* from
, long* to
) const
1726 TXNGetSelection( m_txn
, (TXNOffset
*) from
, (TXNOffset
*) to
) ;
1729 void wxMacMLTEControl::SetSelection( long from
, long to
)
1731 wxMacWindowClipper
c( m_peer
) ;
1732 /* change the selection */
1733 if ((from
== -1) && (to
== -1))
1734 TXNSelectAll(m_txn
);
1736 TXNSetSelection( m_txn
, from
, to
);
1737 TXNShowSelection( m_txn
, kTXNShowStart
);
1740 void wxMacMLTEControl::WriteText(const wxString
& str
)
1743 wxMacConvertNewlines10To13( &st
) ;
1745 long start
, end
, dummy
;
1746 GetSelection( &start
, &dummy
) ;
1747 wxMacWindowClipper
c( m_peer
) ;
1749 wxMacEditHelper
helper( m_txn
) ;
1750 SetTXNData( st
, kTXNUseCurrentSelection
, kTXNUseCurrentSelection
) ;
1752 GetSelection( &dummy
, &end
) ;
1753 // TODO SetStyle( start , end , GetDefaultStyle() ) ;
1756 void wxMacMLTEControl::Clear()
1758 wxMacWindowClipper
c( m_peer
) ;
1759 wxMacEditHelper
st(m_txn
) ;
1760 TXNSetSelection( m_txn
, kTXNStartOffset
, kTXNEndOffset
) ;
1764 bool wxMacMLTEControl::CanUndo() const
1766 return TXNCanUndo( m_txn
, NULL
) ;
1769 void wxMacMLTEControl::Undo()
1774 bool wxMacMLTEControl::CanRedo() const
1776 return TXNCanRedo( m_txn
, NULL
) ;
1779 void wxMacMLTEControl::Redo()
1784 int wxMacMLTEControl::GetNumberOfLines() const
1786 ItemCount lines
= 0 ;
1787 TXNGetLineCount(m_txn
, &lines
) ;
1791 long wxMacMLTEControl::XYToPosition(long x
, long y
) const
1795 wxTextPos lastpos
= GetLastPosition() ;
1797 // TODO find a better implementation : while we can get the
1798 // line metrics of a certain line, we don't get its starting
1799 // position, so it would probably be rather a binary search
1800 // for the start position
1803 int lastHeight
= 0 ;
1806 for ( n
= 0 ; n
<= (ItemCount
) lastpos
; ++n
)
1808 if ( y
== ypos
&& x
== xpos
)
1811 TXNOffsetToPoint( m_txn
, n
, &curpt
);
1813 if ( curpt
.v
> lastHeight
)
1818 lastHeight
= curpt
.v
;
1826 bool wxMacMLTEControl::PositionToXY(long pos
, long *x
, long *y
) const
1830 wxTextPos lastpos
= GetLastPosition() ;
1835 if ( pos
<= lastpos
)
1837 // TODO find a better implementation : while we can get the
1838 // line metrics of a certain line, we don't get its starting
1839 // position, so it would probably be rather a binary search
1840 // for the start position
1843 int lastHeight
= 0 ;
1846 for ( n
= 0 ; n
<= (ItemCount
) pos
; ++n
)
1848 TXNOffsetToPoint(m_txn
, n
, &curpt
);
1850 if ( curpt
.v
> lastHeight
)
1855 lastHeight
= curpt
.v
;
1860 if ( y
) *y
= ypos
;
1861 if ( x
) *x
= xpos
;
1867 void wxMacMLTEControl::ShowPosition( long pos
)
1869 #if TARGET_RT_MAC_MACHO && defined(AVAILABLE_MAC_OS_X_VERSION_10_2_AND_LATER)
1873 TXNOffset selstart
, selend
;
1874 TXNGetSelection( m_txn
, &selstart
, &selend
) ;
1875 TXNOffsetToPoint( m_txn
, selstart
, ¤t
);
1876 TXNOffsetToPoint( m_txn
, pos
, &desired
);
1877 //TODO use HIPoints for 10.3 and above
1878 if ( (UInt32
) TXNScroll
!= (UInt32
) kUnresolvedCFragSymbolAddress
)
1880 OSErr theErr
= noErr
;
1881 SInt32 dv
= desired
.v
- current
.v
;
1882 SInt32 dh
= desired
.h
- current
.h
;
1883 TXNShowSelection( m_txn
, true ) ;
1884 theErr
= TXNScroll( m_txn
, kTXNScrollUnitsInPixels
, kTXNScrollUnitsInPixels
, &dv
, &dh
);
1885 // there will be an error returned for classic mlte implementation when the control is
1886 // invisible, but HITextView works correctly, so we don't assert that one
1887 // wxASSERT_MSG( theErr == noErr, _T("TXNScroll returned an error!") );
1893 void wxMacMLTEControl::SetTXNData( const wxString
& st
, TXNOffset start
, TXNOffset end
)
1896 #if SIZEOF_WCHAR_T == 2
1897 size_t len
= st
.Len() ;
1898 TXNSetData( m_txn
, kTXNUnicodeTextData
, (void*)st
.wc_str(), len
* 2,
1901 wxMBConvUTF16BE converter
;
1902 ByteCount byteBufferLen
= converter
.WC2MB( NULL
, st
.wc_str() , 0 ) ;
1903 UniChar
*unibuf
= (UniChar
*) malloc(byteBufferLen
) ;
1904 converter
.WC2MB( (char*) unibuf
, st
.wc_str() , byteBufferLen
) ;
1905 TXNSetData( m_txn
, kTXNUnicodeTextData
, (void*)unibuf
, byteBufferLen
,
1910 wxCharBuffer text
= st
.mb_str(wxConvLocal
) ;
1911 TXNSetData( m_txn
, kTXNTextData
, (void*)text
.data(), strlen( text
) ,
1917 wxString
wxMacMLTEControl::GetLineText(long lineNo
) const
1921 if ( lineNo
< GetNumberOfLines() )
1929 // get the first possible position in the control
1931 TXNOffsetToPoint(m_txn
, 0, &firstPoint
);
1933 // Iterate through the lines until we reach the one we want,
1934 // adding to our current y pixel point position
1935 while (ypos
< lineNo
)
1937 TXNGetLineMetrics(m_txn
, ypos
++, &lineWidth
, &lineHeight
);
1938 currentHeight
+= lineHeight
;
1941 Point thePoint
= { firstPoint
.v
+ (currentHeight
>> 16), firstPoint
.h
+ (0) };
1942 TXNOffset theOffset
;
1943 TXNPointToOffset(m_txn
, thePoint
, &theOffset
);
1945 wxString content
= GetStringValue() ;
1946 Point currentPoint
= thePoint
;
1947 while(thePoint
.v
== currentPoint
.v
&& theOffset
< content
.length())
1949 line
+= content
[theOffset
];
1950 TXNOffsetToPoint(m_txn
, ++theOffset
, ¤tPoint
);
1956 int wxMacMLTEControl::GetLineLength(long lineNo
) const
1960 if ( lineNo
< GetNumberOfLines() )
1968 // get the first possible position in the control
1970 TXNOffsetToPoint(m_txn
, 0, &firstPoint
);
1972 // Iterate through the lines until we reach the one we want,
1973 // adding to our current y pixel point position
1974 while (ypos
< lineNo
)
1976 TXNGetLineMetrics(m_txn
, ypos
++, &lineWidth
, &lineHeight
);
1977 currentHeight
+= lineHeight
;
1980 Point thePoint
= { firstPoint
.v
+ (currentHeight
>> 16), firstPoint
.h
+ (0) };
1981 TXNOffset theOffset
;
1982 TXNPointToOffset(m_txn
, thePoint
, &theOffset
);
1984 wxString content
= GetStringValue() ;
1985 Point currentPoint
= thePoint
;
1986 while(thePoint
.v
== currentPoint
.v
&& theOffset
< content
.length())
1989 TXNOffsetToPoint(m_txn
, ++theOffset
, ¤tPoint
);
1996 // ----------------------------------------------------------------------------
1997 // MLTE control implementation (classic part)
1998 // ----------------------------------------------------------------------------
2000 // OS X Notes : We still don't have a full replacement for MLTE, so this implementation
2001 // has to live on. We have different problems coming from outdated implementations on the
2002 // various OS X versions. Most deal with the scrollbars: they are not correctly embedded
2003 // while this can be solved on 10.3 by reassigning them the correct place, on 10.2 there is
2004 // no way out, therefore we are using our own implementation and our own scrollbars ....
2006 #ifdef __WXMAC_OSX__
2008 TXNScrollInfoUPP gTXNScrollInfoProc
= NULL
;
2009 ControlActionUPP gTXNScrollActionProc
= NULL
;
2011 pascal void wxMacMLTEClassicControl::TXNScrollInfoProc (SInt32 iValue
, SInt32 iMaximumValue
, TXNScrollBarOrientation
2012 iScrollBarOrientation
, SInt32 iRefCon
)
2014 wxMacMLTEClassicControl
* mlte
= (wxMacMLTEClassicControl
*) iRefCon
;
2015 SInt32 value
= wxMax( iValue
, 0 ) ;
2016 SInt32 maximum
= wxMax( iMaximumValue
, 0 ) ;
2018 if ( iScrollBarOrientation
== kTXNHorizontal
)
2020 if ( mlte
->m_sbHorizontal
)
2022 SetControl32BitValue( mlte
->m_sbHorizontal
, value
) ;
2023 SetControl32BitMaximum( mlte
->m_sbHorizontal
, maximum
) ;
2024 mlte
->m_lastHorizontalValue
= value
;
2027 else if ( iScrollBarOrientation
== kTXNVertical
)
2029 if ( mlte
->m_sbVertical
)
2031 SetControl32BitValue( mlte
->m_sbVertical
, value
) ;
2032 SetControl32BitMaximum( mlte
->m_sbVertical
, maximum
) ;
2033 mlte
->m_lastVerticalValue
= value
;
2038 pascal void wxMacMLTEClassicControl::TXNScrollActionProc( ControlRef controlRef
, ControlPartCode partCode
)
2041 wxMacMLTEClassicControl
* mlte
= (wxMacMLTEClassicControl
*) GetControlReference( controlRef
) ;
2045 if ( controlRef
!= mlte
->m_sbVertical
&& controlRef
!= mlte
->m_sbHorizontal
)
2048 bool isHorizontal
= ( controlRef
== mlte
->m_sbHorizontal
) ;
2050 SInt32 minimum
= 0 ;
2051 SInt32 maximum
= GetControl32BitMaximum( controlRef
) ;
2052 SInt32 value
= GetControl32BitValue( controlRef
) ;
2056 case kControlDownButtonPart
:
2059 case kControlUpButtonPart
:
2062 case kControlPageDownPart
:
2063 delta
= GetControlViewSize( controlRef
) ;
2065 case kControlPageUpPart
:
2066 delta
= -GetControlViewSize( controlRef
) ;
2068 case kControlIndicatorPart
:
2070 ( isHorizontal
? mlte
->m_lastHorizontalValue
: mlte
->m_lastVerticalValue
) ;
2077 SInt32 newValue
= value
;
2079 if ( partCode
!= kControlIndicatorPart
)
2081 if( value
+ delta
< minimum
)
2082 delta
= minimum
- value
;
2083 if ( value
+ delta
> maximum
)
2084 delta
= maximum
- value
;
2086 SetControl32BitValue( controlRef
, value
+ delta
) ;
2087 newValue
= value
+ delta
;
2090 SInt32 verticalDelta
= isHorizontal
? 0 : delta
;
2091 SInt32 horizontalDelta
= isHorizontal
? delta
: 0 ;
2093 err
= TXNScroll( mlte
->m_txn
, kTXNScrollUnitsInPixels
, kTXNScrollUnitsInPixels
,
2094 &verticalDelta
, &horizontalDelta
);
2097 mlte
->m_lastHorizontalValue
= newValue
;
2099 mlte
->m_lastVerticalValue
= newValue
;
2104 // make correct activations
2105 void wxMacMLTEClassicControl::MacActivatePaneText(Boolean setActive
)
2107 wxTextCtrl
* textctrl
= (wxTextCtrl
*) GetControlReference(m_controlRef
);
2109 wxMacWindowClipper
clipper( textctrl
) ;
2110 TXNActivate(m_txn
, m_txnFrameID
, setActive
);
2112 ControlRef controlFocus
= 0 ;
2113 GetKeyboardFocus( m_txnWindow
, &controlFocus
) ;
2114 if ( controlFocus
== m_controlRef
)
2115 TXNFocus( m_txn
, setActive
);
2118 void wxMacMLTEClassicControl::MacFocusPaneText(Boolean setFocus
)
2120 TXNFocus( m_txn
, setFocus
);
2123 // guards against inappropriate redraw (hidden objects drawing onto window)
2125 void wxMacMLTEClassicControl::MacSetObjectVisibility(Boolean vis
)
2127 ControlRef controlFocus
= 0 ;
2128 GetKeyboardFocus( m_txnWindow
, &controlFocus
) ;
2130 if ( controlFocus
== m_controlRef
&& vis
== false )
2132 SetKeyboardFocus( m_txnWindow
, m_controlRef
, kControlFocusNoPart
) ;
2135 TXNControlTag iControlTags
[1] = { kTXNVisibilityTag
};
2136 TXNControlData iControlData
[1] = { {(UInt32
) false } };
2138 verify_noerr( TXNGetTXNObjectControls( m_txn
, 1,
2139 iControlTags
, iControlData
) ) ;
2141 if ( iControlData
[0].uValue
!= vis
)
2143 iControlData
[0].uValue
= vis
;
2144 verify_noerr( TXNSetTXNObjectControls( m_txn
, false , 1,
2145 iControlTags
, iControlData
)) ;
2147 // we right now are always clipping as partial visibility (overlapped) visibility
2148 // is also a problem, if we run into further problems we might set the FrameBounds to an empty
2152 // make sure that the TXNObject is at the right position
2154 void wxMacMLTEClassicControl::MacUpdatePosition()
2156 wxTextCtrl
* textctrl
= (wxTextCtrl
*) GetControlReference(m_controlRef
);
2157 if ( textctrl
== NULL
)
2161 UMAGetControlBoundsInWindowCoords(m_controlRef
, &bounds
);
2163 wxRect visRect
= textctrl
->MacGetClippedClientRect() ;
2164 Rect visBounds
= { visRect
.y
, visRect
.x
, visRect
.y
+ visRect
.height
, visRect
.x
+ visRect
.width
} ;
2167 textctrl
->MacWindowToRootWindow( &x
, &y
) ;
2168 OffsetRect( &visBounds
, x
, y
) ;
2170 if ( !EqualRect( &bounds
, &m_txnControlBounds
) || !EqualRect( &visBounds
, &m_txnVisBounds
) )
2172 m_txnControlBounds
= bounds
;
2173 m_txnVisBounds
= visBounds
;
2174 wxMacWindowClipper
cl(textctrl
) ;
2176 #ifdef __WXMAC_OSX__
2177 bool isCompositing
= textctrl
->MacGetTopLevelWindow()->MacUsesCompositing() ;
2178 if ( m_sbHorizontal
|| m_sbVertical
)
2180 int w
= bounds
.right
- bounds
.left
;
2181 int h
= bounds
.bottom
- bounds
.top
;
2183 if ( m_sbHorizontal
)
2187 sbBounds
.left
= -1 ;
2188 sbBounds
.top
= h
- 14 ;
2189 sbBounds
.right
= w
+ 1 ;
2190 sbBounds
.bottom
= h
+ 1 ;
2192 if ( !isCompositing
)
2193 OffsetRect( &sbBounds
, m_txnControlBounds
.left
, m_txnControlBounds
.top
) ;
2195 SetControlBounds( m_sbHorizontal
, &sbBounds
) ;
2196 SetControlViewSize( m_sbHorizontal
, w
) ;
2202 sbBounds
.left
= w
- 14 ;
2204 sbBounds
.right
= w
+ 1 ;
2205 sbBounds
.bottom
= m_sbHorizontal
? h
- 14 : h
+ 1 ;
2207 if ( !isCompositing
)
2208 OffsetRect( &sbBounds
, m_txnControlBounds
.left
, m_txnControlBounds
.top
) ;
2210 SetControlBounds( m_sbVertical
, &sbBounds
) ;
2211 SetControlViewSize( m_sbVertical
, h
) ;
2216 TXNLongRect olddestRect
;
2217 TXNGetRectBounds( m_txn
, &oldviewRect
, &olddestRect
, NULL
) ;
2219 Rect viewRect
= { m_txnControlBounds
.top
, m_txnControlBounds
.left
,
2220 m_txnControlBounds
.bottom
- ( m_sbHorizontal
? 14 : 0 ) , m_txnControlBounds
.right
- ( m_sbVertical
? 14 : 0 ) } ;
2221 TXNLongRect destRect
= { m_txnControlBounds
.top
, m_txnControlBounds
.left
,
2222 m_txnControlBounds
.bottom
- ( m_sbHorizontal
? 14 : 0 ) , m_txnControlBounds
.right
- ( m_sbVertical
? 14 : 0 ) } ;
2224 if ( olddestRect
.right
>= 10000 )
2225 destRect
.right
= destRect
.left
+ 32000 ;
2227 if ( olddestRect
.bottom
>= 0x20000000 )
2228 destRect
.bottom
= destRect
.top
+ 0x40000000 ;
2230 SectRect( &viewRect
, &visBounds
, &viewRect
) ;
2231 TXNSetRectBounds( m_txn
, &viewRect
, &destRect
, true ) ;
2233 TXNSetFrameBounds( m_txn, m_txnControlBounds.top, m_txnControlBounds.left,
2234 m_txnControlBounds.bottom - ( m_sbHorizontal ? 14 : 0 ) , m_txnControlBounds.right - ( m_sbVertical ? 14 : 0 ), m_txnFrameID);
2238 TXNSetFrameBounds( m_txn
, m_txnControlBounds
.top
, m_txnControlBounds
.left
,
2239 wxMax( m_txnControlBounds
.bottom
, m_txnControlBounds
.top
) ,
2240 wxMax( m_txnControlBounds
.right
, m_txnControlBounds
.left
) , m_txnFrameID
);
2242 // the SetFrameBounds method unter classic sometimes does not correctly scroll a selection into sight after a
2243 // movement, therefore we have to force it
2245 TXNLongRect textRect
;
2246 TXNGetRectBounds( m_txn
, NULL
, NULL
, &textRect
) ;
2247 if ( textRect
.left
< m_txnControlBounds
.left
)
2249 TXNShowSelection( m_txn
, false ) ;
2255 void wxMacMLTEClassicControl::SetRect( Rect
*r
)
2257 wxMacControl::SetRect( r
) ;
2258 MacUpdatePosition() ;
2261 void wxMacMLTEClassicControl::MacControlUserPaneDrawProc(wxInt16 thePart
)
2263 wxTextCtrl
* textctrl
= (wxTextCtrl
*) GetControlReference(m_controlRef
);
2264 if ( textctrl
== NULL
)
2267 if ( textctrl
->MacIsReallyShown() )
2269 wxMacWindowClipper
clipper( textctrl
) ;
2270 TXNDraw( m_txn
, NULL
) ;
2274 wxInt16
wxMacMLTEClassicControl::MacControlUserPaneHitTestProc(wxInt16 x
, wxInt16 y
)
2276 Point where
= { y
, x
} ;
2277 ControlPartCode result
;
2280 wxTextCtrl
* textctrl
= (wxTextCtrl
*) GetControlReference(m_controlRef
);
2281 if ( textctrl
== NULL
)
2284 if (textctrl
->MacIsReallyShown() )
2286 if (PtInRect(where
, &m_txnControlBounds
))
2287 result
= kControlEditTextPart
;
2290 // sometimes we get the coords also in control local coordinates, therefore test again
2291 if ( textctrl
->MacGetTopLevelWindow()->MacUsesCompositing() )
2294 textctrl
->MacClientToRootWindow( &x
, &y
) ;
2298 if (PtInRect(where
, &m_txnControlBounds
))
2299 result
= kControlEditTextPart
;
2307 wxInt16
wxMacMLTEClassicControl::MacControlUserPaneTrackingProc( wxInt16 x
, wxInt16 y
, void* actionProc
)
2309 wxTextCtrl
* textctrl
= (wxTextCtrl
*) GetControlReference(m_controlRef
);
2310 if ( textctrl
== NULL
)
2313 ControlPartCode partCodeResult
= 0;
2315 if (textctrl
->MacIsReallyShown() )
2317 Point startPt
= { y
,x
} ;
2318 // for compositing, we must convert these into toplevel window coordinates, because hittesting expects them
2319 if ( textctrl
->MacGetTopLevelWindow()->MacUsesCompositing() )
2322 textctrl
->MacClientToRootWindow( &x
, &y
) ;
2327 switch (MacControlUserPaneHitTestProc( startPt
.h
, startPt
.v
))
2329 case kControlEditTextPart
:
2331 wxMacWindowClipper
clipper( textctrl
) ;
2334 ConvertEventRefToEventRecord( (EventRef
) wxTheApp
->MacGetCurrentEvent() , &rec
) ;
2335 TXNClick( m_txn
, &rec
);
2341 return partCodeResult
;
2344 void wxMacMLTEClassicControl::MacControlUserPaneIdleProc()
2346 wxTextCtrl
* textctrl
= (wxTextCtrl
*) GetControlReference(m_controlRef
);
2347 if ( textctrl
== NULL
)
2350 if (textctrl
->MacIsReallyShown())
2352 if (IsControlActive(m_controlRef
))
2356 wxMacWindowClipper
clipper( textctrl
) ;
2361 if (PtInRect(mousep
, &m_txnControlBounds
))
2364 RectRgn((theRgn
= NewRgn()), &m_txnControlBounds
);
2365 TXNAdjustCursor(m_txn
, theRgn
);
2372 wxInt16
wxMacMLTEClassicControl::MacControlUserPaneKeyDownProc (wxInt16 keyCode
, wxInt16 charCode
, wxInt16 modifiers
)
2374 wxTextCtrl
* textctrl
= (wxTextCtrl
*) GetControlReference(m_controlRef
);
2375 if ( textctrl
== NULL
)
2378 wxMacWindowClipper
clipper( textctrl
) ;
2381 memset( &ev
, 0 , sizeof( ev
) ) ;
2383 ev
.modifiers
= modifiers
;
2384 ev
.message
= (( keyCode
<< 8 ) & keyCodeMask
) + ( charCode
& charCodeMask
) ;
2385 TXNKeyDown( m_txn
, &ev
);
2387 return kControlEntireControl
;
2390 void wxMacMLTEClassicControl::MacControlUserPaneActivateProc( bool activating
)
2392 MacActivatePaneText( activating
);
2395 wxInt16
wxMacMLTEClassicControl::MacControlUserPaneFocusProc(wxInt16 action
)
2397 ControlPartCode focusResult
;
2399 focusResult
= kControlFocusNoPart
;
2400 wxTextCtrl
* textctrl
= (wxTextCtrl
*) GetControlReference(m_controlRef
);
2401 if ( textctrl
== NULL
)
2404 wxMacWindowClipper
clipper( textctrl
) ;
2406 ControlRef controlFocus
= 0 ;
2407 GetKeyboardFocus( m_txnWindow
, &controlFocus
) ;
2408 bool wasFocused
= ( controlFocus
== m_controlRef
) ;
2412 case kControlFocusPrevPart
:
2413 case kControlFocusNextPart
:
2414 MacFocusPaneText( ( !wasFocused
));
2415 focusResult
= (!wasFocused
) ? (ControlPartCode
) kControlEditTextPart
: (ControlPartCode
) kControlFocusNoPart
;
2418 case kControlFocusNoPart
:
2420 MacFocusPaneText( false);
2421 focusResult
= kControlFocusNoPart
;
2428 void wxMacMLTEClassicControl::MacControlUserPaneBackgroundProc( void *info
)
2432 wxMacMLTEClassicControl::wxMacMLTEClassicControl( wxTextCtrl
*wxPeer
,
2433 const wxString
& str
,
2435 const wxSize
& size
, long style
) : wxMacMLTEControl( wxPeer
)
2437 m_font
= wxPeer
->GetFont() ;
2438 m_windowStyle
= style
;
2439 Rect bounds
= wxMacGetBoundsForControl( wxPeer
, pos
, size
) ;
2441 wxMacConvertNewlines10To13( &st
) ;
2445 featurSet
= kControlSupportsEmbedding
| kControlSupportsFocus
| kControlWantsIdle
2446 | kControlWantsActivate
| kControlHandlesTracking
// | kControlHasSpecialBackground
2447 | kControlGetsFocusOnClick
| kControlSupportsLiveFeedback
;
2449 verify_noerr( ::CreateUserPaneControl( MAC_WXHWND(wxPeer
->GetParent()->MacGetTopLevelWindowRef()), &bounds
, featurSet
, &m_controlRef
) );
2453 AdjustCreationAttributes( *wxWHITE
, true) ;
2455 MacSetObjectVisibility( wxPeer
->MacIsReallyShown() ) ;
2457 wxMacWindowClipper
clipper( m_peer
) ;
2458 SetTXNData( st
, kTXNStartOffset
, kTXNEndOffset
) ;
2459 TXNSetSelection( m_txn
, 0, 0);
2462 wxMacMLTEClassicControl::~wxMacMLTEClassicControl()
2464 TXNDeleteObject(m_txn
);
2468 void wxMacMLTEClassicControl::VisibilityChanged(bool shown
)
2470 MacSetObjectVisibility( shown
) ;
2471 wxMacControl::VisibilityChanged( shown
) ;
2474 void wxMacMLTEClassicControl::SuperChangedPosition()
2476 MacUpdatePosition() ;
2477 wxMacControl::SuperChangedPosition() ;
2480 #ifdef __WXMAC_OSX__
2482 ControlUserPaneDrawUPP gTPDrawProc
= NULL
;
2483 ControlUserPaneHitTestUPP gTPHitProc
= NULL
;
2484 ControlUserPaneTrackingUPP gTPTrackProc
= NULL
;
2485 ControlUserPaneIdleUPP gTPIdleProc
= NULL
;
2486 ControlUserPaneKeyDownUPP gTPKeyProc
= NULL
;
2487 ControlUserPaneActivateUPP gTPActivateProc
= NULL
;
2488 ControlUserPaneFocusUPP gTPFocusProc
= NULL
;
2490 static pascal void wxMacControlUserPaneDrawProc(ControlRef control
, SInt16 part
)
2492 wxTextCtrl
*textCtrl
= wxDynamicCast( wxFindControlFromMacControl(control
) , wxTextCtrl
) ;
2493 wxMacMLTEClassicControl
* win
= textCtrl
? (wxMacMLTEClassicControl
*)(textCtrl
->GetPeer()) : NULL
;
2495 win
->MacControlUserPaneDrawProc(part
) ;
2498 static pascal ControlPartCode
wxMacControlUserPaneHitTestProc(ControlRef control
, Point where
)
2500 wxTextCtrl
*textCtrl
= wxDynamicCast( wxFindControlFromMacControl(control
) , wxTextCtrl
) ;
2501 wxMacMLTEClassicControl
* win
= textCtrl
? (wxMacMLTEClassicControl
*)(textCtrl
->GetPeer()) : NULL
;
2503 return win
->MacControlUserPaneHitTestProc(where
.h
, where
.v
) ;
2505 return kControlNoPart
;
2508 static pascal ControlPartCode
wxMacControlUserPaneTrackingProc(ControlRef control
, Point startPt
, ControlActionUPP actionProc
)
2510 wxTextCtrl
*textCtrl
= wxDynamicCast( wxFindControlFromMacControl(control
) , wxTextCtrl
) ;
2511 wxMacMLTEClassicControl
* win
= textCtrl
? (wxMacMLTEClassicControl
*)(textCtrl
->GetPeer()) : NULL
;
2513 return win
->MacControlUserPaneTrackingProc( startPt
.h
, startPt
.v
, (void*) actionProc
) ;
2515 return kControlNoPart
;
2518 static pascal void wxMacControlUserPaneIdleProc(ControlRef control
)
2520 wxTextCtrl
*textCtrl
= wxDynamicCast( wxFindControlFromMacControl(control
) , wxTextCtrl
) ;
2521 wxMacMLTEClassicControl
* win
= textCtrl
? (wxMacMLTEClassicControl
*)(textCtrl
->GetPeer()) : NULL
;
2523 win
->MacControlUserPaneIdleProc() ;
2526 static pascal ControlPartCode
wxMacControlUserPaneKeyDownProc(ControlRef control
, SInt16 keyCode
, SInt16 charCode
, SInt16 modifiers
)
2528 wxTextCtrl
*textCtrl
= wxDynamicCast( wxFindControlFromMacControl(control
) , wxTextCtrl
) ;
2529 wxMacMLTEClassicControl
* win
= textCtrl
? (wxMacMLTEClassicControl
*)(textCtrl
->GetPeer()) : NULL
;
2531 return win
->MacControlUserPaneKeyDownProc(keyCode
,charCode
,modifiers
) ;
2533 return kControlNoPart
;
2536 static pascal void wxMacControlUserPaneActivateProc(ControlRef control
, Boolean activating
)
2538 wxTextCtrl
*textCtrl
= wxDynamicCast( wxFindControlFromMacControl(control
) , wxTextCtrl
) ;
2539 wxMacMLTEClassicControl
* win
= textCtrl
? (wxMacMLTEClassicControl
*)(textCtrl
->GetPeer()) : NULL
;
2541 win
->MacControlUserPaneActivateProc(activating
) ;
2544 static pascal ControlPartCode
wxMacControlUserPaneFocusProc(ControlRef control
, ControlFocusPart action
)
2546 wxTextCtrl
*textCtrl
= wxDynamicCast( wxFindControlFromMacControl(control
) , wxTextCtrl
) ;
2547 wxMacMLTEClassicControl
* win
= textCtrl
? (wxMacMLTEClassicControl
*)(textCtrl
->GetPeer()) : NULL
;
2549 return win
->MacControlUserPaneFocusProc(action
) ;
2551 return kControlNoPart
;
2555 static pascal void wxMacControlUserPaneBackgroundProc(ControlRef control, ControlBackgroundPtr info)
2557 wxTextCtrl *textCtrl = wxDynamicCast( wxFindControlFromMacControl(control) , wxTextCtrl ) ;
2558 wxMacMLTEClassicControl * win = textCtrl ? (wxMacMLTEClassicControl*)(textCtrl->GetPeer()) : NULL ;
2560 win->MacControlUserPaneBackgroundProc(info) ;
2565 // TXNRegisterScrollInfoProc
2567 OSStatus
wxMacMLTEClassicControl::DoCreate()
2571 OSStatus err
= noErr
;
2573 /* set up our globals */
2574 #ifdef __WXMAC_OSX__
2575 if (gTPDrawProc
== NULL
) gTPDrawProc
= NewControlUserPaneDrawUPP(wxMacControlUserPaneDrawProc
);
2576 if (gTPHitProc
== NULL
) gTPHitProc
= NewControlUserPaneHitTestUPP(wxMacControlUserPaneHitTestProc
);
2577 if (gTPTrackProc
== NULL
) gTPTrackProc
= NewControlUserPaneTrackingUPP(wxMacControlUserPaneTrackingProc
);
2578 if (gTPIdleProc
== NULL
) gTPIdleProc
= NewControlUserPaneIdleUPP(wxMacControlUserPaneIdleProc
);
2579 if (gTPKeyProc
== NULL
) gTPKeyProc
= NewControlUserPaneKeyDownUPP(wxMacControlUserPaneKeyDownProc
);
2580 if (gTPActivateProc
== NULL
) gTPActivateProc
= NewControlUserPaneActivateUPP(wxMacControlUserPaneActivateProc
);
2581 if (gTPFocusProc
== NULL
) gTPFocusProc
= NewControlUserPaneFocusUPP(wxMacControlUserPaneFocusProc
);
2583 if (gTXNScrollInfoProc
== NULL
) gTXNScrollInfoProc
= NewTXNScrollInfoUPP(TXNScrollInfoProc
) ;
2584 if (gTXNScrollActionProc
== NULL
) gTXNScrollActionProc
= NewControlActionUPP(TXNScrollActionProc
) ;
2587 /* set the initial settings for our private data */
2589 m_txnWindow
=GetControlOwner(m_controlRef
);
2590 m_txnPort
= (GrafPtr
) GetWindowPort(m_txnWindow
);
2592 #ifdef __WXMAC_OSX__
2593 /* set up the user pane procedures */
2594 SetControlData(m_controlRef
, kControlEntireControl
, kControlUserPaneDrawProcTag
, sizeof(gTPDrawProc
), &gTPDrawProc
);
2595 SetControlData(m_controlRef
, kControlEntireControl
, kControlUserPaneHitTestProcTag
, sizeof(gTPHitProc
), &gTPHitProc
);
2596 SetControlData(m_controlRef
, kControlEntireControl
, kControlUserPaneTrackingProcTag
, sizeof(gTPTrackProc
), &gTPTrackProc
);
2597 SetControlData(m_controlRef
, kControlEntireControl
, kControlUserPaneIdleProcTag
, sizeof(gTPIdleProc
), &gTPIdleProc
);
2598 SetControlData(m_controlRef
, kControlEntireControl
, kControlUserPaneKeyDownProcTag
, sizeof(gTPKeyProc
), &gTPKeyProc
);
2599 SetControlData(m_controlRef
, kControlEntireControl
, kControlUserPaneActivateProcTag
, sizeof(gTPActivateProc
), &gTPActivateProc
);
2600 SetControlData(m_controlRef
, kControlEntireControl
, kControlUserPaneFocusProcTag
, sizeof(gTPFocusProc
), &gTPFocusProc
);
2602 /* calculate the rectangles used by the control */
2603 UMAGetControlBoundsInWindowCoords(m_controlRef
, &bounds
);
2605 m_txnControlBounds
= bounds
;
2606 m_txnVisBounds
= bounds
;
2608 CGrafPtr origPort
= NULL
;
2609 GDHandle origDev
= NULL
;
2610 GetGWorld( &origPort
, &origDev
) ;
2613 /* create the new edit field */
2615 TXNFrameOptions frameOptions
= FrameOptionsFromWXStyle( m_windowStyle
) ;
2617 #ifdef __WXMAC_OSX__
2619 // the scrollbars are not correctly embedded but are inserted at the root
2620 // this gives us problems as we have erratic redraws even over the structure
2623 m_sbHorizontal
= 0 ;
2625 m_lastHorizontalValue
= 0 ;
2626 m_lastVerticalValue
= 0 ;
2628 Rect sb
= { 0 , 0 , 0 , 0 } ;
2629 if ( frameOptions
& kTXNWantVScrollBarMask
)
2631 CreateScrollBarControl( m_txnWindow
, &sb
, 0 , 0 , 100 , 1 , true , gTXNScrollActionProc
, &m_sbVertical
) ;
2632 SetControlReference( m_sbVertical
, (SInt32
) this ) ;
2633 SetControlAction( m_sbVertical
, gTXNScrollActionProc
);
2634 ShowControl( m_sbVertical
) ;
2635 EmbedControl( m_sbVertical
, m_controlRef
) ;
2636 frameOptions
&= ~kTXNWantVScrollBarMask
;
2638 if ( frameOptions
& kTXNWantHScrollBarMask
)
2640 CreateScrollBarControl( m_txnWindow
, &sb
, 0 , 0 , 100 , 1 , true , gTXNScrollActionProc
, &m_sbHorizontal
) ;
2641 SetControlReference( m_sbHorizontal
, (SInt32
) this ) ;
2642 SetControlAction( m_sbHorizontal
, gTXNScrollActionProc
);
2643 ShowControl( m_sbHorizontal
) ;
2644 EmbedControl( m_sbHorizontal
, m_controlRef
) ;
2645 frameOptions
&= ~(kTXNWantHScrollBarMask
| kTXNDrawGrowIconMask
);
2650 verify_noerr(TXNNewObject(NULL
, m_txnWindow
, &bounds
,
2652 kTXNTextEditStyleFrameType
,
2654 kTXNSystemDefaultEncoding
,
2655 &m_txn
, &m_txnFrameID
, NULL
) );
2657 TXNCarbonEventInfo cInfo ;
2659 cInfo.useCarbonEvents = false ;
2662 cInfo.fDictionary = NULL ;
2664 TXNControlTag iControlTags[] =
2666 kTXNUseCarbonEvents ,
2668 TXNControlData iControlData[] =
2673 int toptag = WXSIZEOF( iControlTags ) ;
2675 verify_noerr( TXNSetTXNObjectControls( m_txn, false , toptag,
2676 iControlTags, iControlData )) ;
2679 #ifdef __WXMAC_OSX__
2680 TXNRegisterScrollInfoProc( m_txn
, gTXNScrollInfoProc
, (SInt32
) this);
2683 SetGWorld( origPort
, origDev
) ;
2687 // ----------------------------------------------------------------------------
2688 // MLTE control implementation (OSX part)
2689 // ----------------------------------------------------------------------------
2691 #if TARGET_API_MAC_OSX
2693 #if MAC_OS_X_VERSION_MAX_ALLOWED > MAC_OS_X_VERSION_10_2
2695 wxMacMLTEHIViewControl::wxMacMLTEHIViewControl( wxTextCtrl
*wxPeer
,
2696 const wxString
& str
,
2698 const wxSize
& size
, long style
) : wxMacMLTEControl( wxPeer
)
2700 m_font
= wxPeer
->GetFont() ;
2701 m_windowStyle
= style
;
2702 Rect bounds
= wxMacGetBoundsForControl( wxPeer
, pos
, size
) ;
2704 wxMacConvertNewlines10To13( &st
) ;
2706 HIRect hr
= { bounds
.left
, bounds
.top
, bounds
.right
- bounds
.left
, bounds
.bottom
- bounds
.top
} ;
2708 m_scrollView
= NULL
;
2709 TXNFrameOptions frameOptions
= FrameOptionsFromWXStyle( style
) ;
2710 if ( frameOptions
& (kTXNWantVScrollBarMask
|kTXNWantHScrollBarMask
) )
2712 HIScrollViewCreate(( frameOptions
& kTXNWantHScrollBarMask
? kHIScrollViewOptionsHorizScroll
: 0) |
2713 ( frameOptions
& kTXNWantVScrollBarMask
? kHIScrollViewOptionsVertScroll
: 0 ) , &m_scrollView
) ;
2715 HIViewSetFrame( m_scrollView
, &hr
);
2716 HIViewSetVisible( m_scrollView
, true );
2720 HITextViewCreate( NULL
, 0, frameOptions
, &m_textView
) ;
2721 m_txn
= HITextViewGetTXNObject( m_textView
) ;
2722 HIViewSetVisible( m_textView
, true ) ;
2725 HIViewAddSubview( m_scrollView
, m_textView
) ;
2726 m_controlRef
= m_scrollView
;
2727 wxPeer
->MacInstallEventHandler( (WXWidget
) m_textView
) ;
2731 HIViewSetFrame( m_textView
, &hr
);
2732 m_controlRef
= m_textView
;
2735 AdjustCreationAttributes( *wxWHITE
, true ) ;
2737 wxMacWindowClipper
c( m_peer
) ;
2738 SetTXNData( st
, kTXNStartOffset
, kTXNEndOffset
) ;
2740 TXNSetSelection( m_txn
, 0, 0);
2741 TXNShowSelection( m_txn
, kTXNShowStart
);
2745 OSStatus
wxMacMLTEHIViewControl::SetFocus( ControlFocusPart focusPart
)
2747 return SetKeyboardFocus( GetControlOwner( m_textView
) ,
2748 m_textView
, focusPart
) ;
2751 bool wxMacMLTEHIViewControl::HasFocus() const
2753 ControlRef control
;
2754 GetKeyboardFocus( GetUserFocusWindow() , &control
) ;
2755 return control
== m_textView
;
2758 #endif // MAC_OS_X_VERSION_MAX_ALLOWED > MAC_OS_X_VERSION_10_2
2763 #endif // wxUSE_TEXTCTRL