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/settings.h"
44 #include "wx/filefn.h"
46 #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 */
74 #include <MacTextEditor.h>
75 #include <ATSUnicode.h>
76 #include <TextCommon.h>
77 #include <TextEncodingConverter.h>
79 #include "wx/mac/uma.h"
85 virtual ~wxMacFunctor() {}
86 virtual void* operator()() = 0 ;
87 static void* CallBackProc(void *param
)
89 wxMacFunctor
* f
= (wxMacFunctor
*) param
;
90 void *result
= (*f
)() ;
95 template<typename classtype
,typename param1type
>
96 class wxMacObjectFunctor1
: public wxMacFunctor
98 typedef void (classtype::*function
)( param1type p1
) ;
99 typedef void (classtype::*ref_function
)( const param1type
& p1
) ;
101 wxMacObjectFunctor1( classtype
*obj
, function f
, param1type p1
) :
109 wxMacObjectFunctor1( classtype
*obj
, ref_function f
, param1type p1
) :
117 ~wxMacObjectFunctor1() {}
119 virtual void* operator()()
121 (m_object
->*m_function
)(m_param1
) ;
125 classtype
* m_object
;
126 param1type m_param1
;
129 function m_function
;
130 ref_function m_refFunction
;
134 template<typename classtype
, typename param1type
>
135 void* wxMacMPRemoteCall( classtype
*object
, void (classtype::*function
)( param1type p1
) , param1type p1
)
137 wxMacObjectFunctor1
<classtype
,param1type
> params(object
,function
,p1
) ;
139 MPRemoteCall( wxMacFunctor::CallBackProc
, ¶ms
, kMPOwningProcessRemoteContext
) ;
143 template<typename classtype
, typename param1type
>
144 void* wxMacMPRemoteCall( classtype
*object
, void (classtype::*function
)( const param1type
& p1
) , param1type p1
)
146 wxMacObjectFunctor1
<classtype
,param1type
> params(object
,function
,p1
) ;
148 MPRemoteCall( wxMacFunctor::CallBackProc
, ¶ms
, kMPOwningProcessRemoteContext
) ;
152 template<typename classtype
, typename param1type
>
153 void* wxMacMPRemoteGUICall( classtype
*object
, void (classtype::*function
)( param1type p1
) , param1type p1
)
156 void *result
= wxMacMPRemoteCall( object
, function
, p1
) ;
161 template<typename classtype
, typename param1type
>
162 void* wxMacMPRemoteGUICall( classtype
*object
, void (classtype::*function
)( const param1type
& p1
) , param1type p1
)
165 void *result
= wxMacMPRemoteCall( object
, function
, p1
) ;
169 // common interface for all implementations
170 class wxMacTextControl
: public wxMacControl
173 wxMacTextControl( wxTextCtrl
*peer
) ;
174 ~wxMacTextControl() ;
176 virtual wxString
GetStringValue() const = 0 ;
177 virtual void SetStringValue( const wxString
&val
) = 0 ;
178 virtual void SetStyle(long start
, long end
, const wxTextAttr
& style
) ;
179 virtual void Copy() ;
181 virtual void Paste() ;
182 virtual bool CanPaste() const ;
183 virtual void SetEditable(bool editable
) ;
184 virtual wxTextPos
GetLastPosition() const ;
185 virtual void Replace( long from
, long to
, const wxString str
) ;
186 virtual void Remove( long from
, long to
) = 0 ;
187 virtual void SetSelection( long from
, long to
) = 0 ;
188 virtual void GetSelection( long* from
, long* to
) const = 0 ;
189 virtual void WriteText(const wxString
& str
) = 0 ;
191 virtual void Clear() ;
192 virtual bool CanUndo() const;
193 virtual void Undo() ;
194 virtual bool CanRedo() const;
195 virtual void Redo() ;
196 virtual int GetNumberOfLines() const ;
197 virtual long XYToPosition(long x
, long y
) const;
198 virtual bool PositionToXY(long pos
, long *x
, long *y
) const ;
199 virtual void ShowPosition( long WXUNUSED(pos
) ) ;
200 virtual int GetLineLength(long lineNo
) const ;
201 virtual wxString
GetLineText(long lineNo
) const ;
202 virtual bool SetupCursor( const wxPoint
& pt
) { return false ; }
204 #ifndef __WXMAC_OSX__
205 virtual void MacControlUserPaneDrawProc(wxInt16 part
) = 0 ;
206 virtual wxInt16
MacControlUserPaneHitTestProc(wxInt16 x
, wxInt16 y
) = 0 ;
207 virtual wxInt16
MacControlUserPaneTrackingProc(wxInt16 x
, wxInt16 y
, void* actionProc
) = 0 ;
208 virtual void MacControlUserPaneIdleProc() = 0 ;
209 virtual wxInt16
MacControlUserPaneKeyDownProc(wxInt16 keyCode
, wxInt16 charCode
, wxInt16 modifiers
) = 0 ;
210 virtual void MacControlUserPaneActivateProc(bool activating
) = 0 ;
211 virtual wxInt16
MacControlUserPaneFocusProc(wxInt16 action
) = 0 ;
212 virtual void MacControlUserPaneBackgroundProc(void* info
) = 0 ;
216 // common parts for implementations based on MLTE
218 class wxMacMLTEControl
: public wxMacTextControl
221 wxMacMLTEControl( wxTextCtrl
*peer
) ;
222 virtual wxString
GetStringValue() const ;
223 virtual void SetStringValue( const wxString
&str
) ;
225 static TXNFrameOptions
FrameOptionsFromWXStyle( long wxStyle
) ;
226 void AdjustCreationAttributes( const wxColour
& background
, bool visible
) ;
228 virtual void SetFont( const wxFont
& font
, const wxColour
& foreground
, long windowStyle
) ;
229 virtual void SetBackground( const wxBrush
&brush
) ;
230 virtual void SetStyle(long start
, long end
, const wxTextAttr
& style
) ;
231 virtual void Copy() ;
233 virtual void Paste() ;
234 virtual bool CanPaste() const ;
235 virtual void SetEditable(bool editable
) ;
236 virtual wxTextPos
GetLastPosition() const ;
237 virtual void Replace( long from
, long to
, const wxString str
) ;
238 virtual void Remove( long from
, long to
) ;
239 virtual void GetSelection( long* from
, long* to
) const ;
240 virtual void SetSelection( long from
, long to
) ;
242 virtual void WriteText(const wxString
& str
) ;
243 virtual void Clear() ;
245 virtual bool CanUndo() const ;
246 virtual void Undo() ;
247 virtual bool CanRedo() const;
248 virtual void Redo() ;
249 virtual int GetNumberOfLines() const ;
250 virtual long XYToPosition(long x
, long y
) const ;
251 virtual bool PositionToXY(long pos
, long *x
, long *y
) const ;
252 virtual void ShowPosition( long pos
) ;
253 virtual int GetLineLength(long lineNo
) const ;
254 virtual wxString
GetLineText(long lineNo
) const ;
256 void SetTXNData( const wxString
& st
, TXNOffset start
, TXNOffset end
) ;
259 void TXNSetAttribute( const wxTextAttr
& style
, long from
, long to
) ;
263 #if TARGET_API_MAC_OSX
265 // implementation available under OSX
267 #if MAC_OS_X_VERSION_MAX_ALLOWED > MAC_OS_X_VERSION_10_2
269 class wxMacMLTEHIViewControl
: public wxMacMLTEControl
272 wxMacMLTEHIViewControl( wxTextCtrl
*wxPeer
,
275 const wxSize
& size
, long style
) ;
276 virtual OSStatus
SetFocus( ControlFocusPart focusPart
) ;
277 virtual bool HasFocus() const ;
279 HIViewRef m_scrollView
;
280 HIViewRef m_textView
;
285 class wxMacUnicodeTextControl
: public wxMacTextControl
288 wxMacUnicodeTextControl( wxTextCtrl
*wxPeer
,
291 const wxSize
& size
, long style
) ;
292 ~wxMacUnicodeTextControl();
293 virtual void VisibilityChanged(bool shown
);
294 virtual wxString
GetStringValue() const ;
295 virtual void SetStringValue( const wxString
&str
) ;
298 virtual void Paste();
299 virtual bool CanPaste() const;
300 virtual void SetEditable(bool editable
) ;
301 virtual void Remove( long from
, long to
) ;
302 virtual void GetSelection( long* from
, long* to
) const ;
303 virtual void SetSelection( long from
, long to
) ;
304 virtual void WriteText(const wxString
& str
) ;
306 // contains the tag for the content (is different for password and non-password controls)
312 // 'classic' MLTE implementation
314 class wxMacMLTEClassicControl
: public wxMacMLTEControl
317 wxMacMLTEClassicControl( wxTextCtrl
*wxPeer
,
320 const wxSize
& size
, long style
) ;
321 ~wxMacMLTEClassicControl() ;
322 virtual void VisibilityChanged(bool shown
) ;
323 virtual void SuperChangedPosition() ;
325 virtual void MacControlUserPaneDrawProc(wxInt16 part
) ;
326 virtual wxInt16
MacControlUserPaneHitTestProc(wxInt16 x
, wxInt16 y
) ;
327 virtual wxInt16
MacControlUserPaneTrackingProc(wxInt16 x
, wxInt16 y
, void* actionProc
) ;
328 virtual void MacControlUserPaneIdleProc() ;
329 virtual wxInt16
MacControlUserPaneKeyDownProc(wxInt16 keyCode
, wxInt16 charCode
, wxInt16 modifiers
) ;
330 virtual void MacControlUserPaneActivateProc(bool activating
) ;
331 virtual wxInt16
MacControlUserPaneFocusProc(wxInt16 action
) ;
332 virtual void MacControlUserPaneBackgroundProc(void* info
) ;
334 virtual bool SetupCursor( const wxPoint
& WXUNUSED(pt
) ) { MacControlUserPaneIdleProc() ; return true ;}
336 virtual void SetRect( Rect
*r
) ;
341 void MacUpdatePosition() ;
342 void MacActivatePaneText(Boolean setActive
) ;
343 void MacFocusPaneText(Boolean setFocus
) ;
345 void MacSetObjectVisibility(Boolean vis
) ;
347 TXNFrameID m_txnFrameID
;
349 WindowRef m_txnWindow
;
350 // bounds of the control as we last did set the txn frames
351 Rect m_txnControlBounds
;
352 Rect m_txnVisBounds
;
354 static pascal void TXNScrollInfoProc (SInt32 iValue
, SInt32 iMaximumValue
,
355 TXNScrollBarOrientation iScrollBarOrientation
, SInt32 iRefCon
) ;
356 static pascal void TXNScrollActionProc( ControlRef controlRef
, ControlPartCode partCode
) ;
357 ControlRef m_sbHorizontal
;
358 SInt32 m_lastHorizontalValue
;
359 ControlRef m_sbVertical
;
360 SInt32 m_lastVerticalValue
;
364 #define TE_UNLIMITED_LENGTH 0xFFFFFFFFUL
366 IMPLEMENT_DYNAMIC_CLASS(wxTextCtrl
, wxControl
)
368 BEGIN_EVENT_TABLE(wxTextCtrl
, wxControl
)
369 EVT_ERASE_BACKGROUND( wxTextCtrl::OnEraseBackground
)
370 EVT_DROP_FILES(wxTextCtrl::OnDropFiles
)
371 EVT_CHAR(wxTextCtrl::OnChar
)
372 EVT_MENU(wxID_CUT
, wxTextCtrl::OnCut
)
373 EVT_MENU(wxID_COPY
, wxTextCtrl::OnCopy
)
374 EVT_MENU(wxID_PASTE
, wxTextCtrl::OnPaste
)
375 EVT_MENU(wxID_UNDO
, wxTextCtrl::OnUndo
)
376 EVT_MENU(wxID_REDO
, wxTextCtrl::OnRedo
)
377 EVT_MENU(wxID_CLEAR
, wxTextCtrl::OnDelete
)
378 EVT_MENU(wxID_SELECTALL
, wxTextCtrl::OnSelectAll
)
380 EVT_CONTEXT_MENU(wxTextCtrl::OnContextMenu
)
382 EVT_UPDATE_UI(wxID_CUT
, wxTextCtrl::OnUpdateCut
)
383 EVT_UPDATE_UI(wxID_COPY
, wxTextCtrl::OnUpdateCopy
)
384 EVT_UPDATE_UI(wxID_PASTE
, wxTextCtrl::OnUpdatePaste
)
385 EVT_UPDATE_UI(wxID_UNDO
, wxTextCtrl::OnUpdateUndo
)
386 EVT_UPDATE_UI(wxID_REDO
, wxTextCtrl::OnUpdateRedo
)
387 EVT_UPDATE_UI(wxID_CLEAR
, wxTextCtrl::OnUpdateDelete
)
388 EVT_UPDATE_UI(wxID_SELECTALL
, wxTextCtrl::OnUpdateSelectAll
)
392 void wxTextCtrl::Init()
397 m_privateContextMenu
= NULL
;
399 m_maxLength
= TE_UNLIMITED_LENGTH
;
402 wxTextCtrl::~wxTextCtrl()
404 delete m_privateContextMenu
;
408 bool wxTextCtrl::Create(wxWindow
*parent
, wxWindowID id
,
411 const wxSize
& size
, long style
,
412 const wxValidator
& validator
,
413 const wxString
& name
)
415 m_macIsUserPane
= false ;
418 if ( ! ( style
& wxNO_BORDER
) )
419 style
= ( style
& ~wxBORDER_MASK
) | wxSUNKEN_BORDER
;
421 if ( !wxTextCtrlBase::Create(parent
, id
, pos
, size
, style
& ~(wxHSCROLL
|wxVSCROLL
), validator
, name
) )
424 if ( m_windowStyle
& wxTE_MULTILINE
)
426 wxASSERT_MSG( !(m_windowStyle
& wxTE_PROCESS_ENTER
),
427 wxT("wxTE_PROCESS_ENTER style is ignored for multiline text controls (they always process it)") );
429 m_windowStyle
|= wxTE_PROCESS_ENTER
;
430 style
|= wxTE_PROCESS_ENTER
;
433 bool forceMLTE
= false ;
434 #if wxUSE_SYSTEM_OPTIONS
435 if ( (wxSystemOptions::HasOption(wxMAC_TEXTCONTROL_USE_MLTE
) ) && ( wxSystemOptions::GetOptionInt( wxMAC_TEXTCONTROL_USE_MLTE
) == 1) )
442 #if MAC_OS_X_VERSION_MAX_ALLOWED > MAC_OS_X_VERSION_10_2
443 if ( UMAGetSystemVersion() >= 0x1030 && forceMLTE
== false )
445 if ( m_windowStyle
& wxTE_MULTILINE
)
446 m_peer
= new wxMacMLTEHIViewControl( this , str
, pos
, size
, style
) ;
451 if ( !(m_windowStyle
& wxTE_MULTILINE
) && forceMLTE
== false )
452 m_peer
= new wxMacUnicodeTextControl( this , str
, pos
, size
, style
) ;
457 m_peer
= new wxMacMLTEClassicControl( this , str
, pos
, size
, style
) ;
460 MacPostControlCreate(pos
,size
) ;
462 // only now the embedding is correct and we can do a positioning update
464 MacSuperChangedPosition() ;
466 if ( m_windowStyle
& wxTE_READONLY
)
468 SetEditable( false ) ;
471 SetCursor( wxCursor( wxCURSOR_IBEAM
) ) ;
476 void wxTextCtrl::MacSuperChangedPosition()
478 wxWindow::MacSuperChangedPosition() ;
479 GetPeer()->SuperChangedPosition() ;
482 void wxTextCtrl::MacVisibilityChanged()
484 GetPeer()->VisibilityChanged( MacIsReallyShown() ) ;
487 void wxTextCtrl::MacEnabledStateChanged()
491 wxString
wxTextCtrl::GetValue() const
493 return GetPeer()->GetStringValue() ;
496 void wxTextCtrl::GetSelection(long* from
, long* to
) const
498 GetPeer()->GetSelection( from
, to
) ;
501 void wxTextCtrl::SetValue(const wxString
& str
)
504 if ( GetValue() == str
)
507 GetPeer()->SetStringValue(str
) ;
509 wxCommandEvent
event(wxEVT_COMMAND_TEXT_UPDATED
, m_windowId
);
510 event
.SetString( GetValue() ) ;
511 event
.SetEventObject( this );
512 GetEventHandler()->ProcessEvent(event
);
515 void wxTextCtrl::SetMaxLength(unsigned long len
)
520 bool wxTextCtrl::SetFont( const wxFont
& font
)
522 if ( !wxTextCtrlBase::SetFont( font
) )
525 GetPeer()->SetFont( font
, GetForegroundColour() , GetWindowStyle() ) ;
529 bool wxTextCtrl::SetStyle(long start
, long end
, const wxTextAttr
& style
)
531 GetPeer()->SetStyle( start
, end
, style
) ;
535 bool wxTextCtrl::SetDefaultStyle(const wxTextAttr
& style
)
537 wxTextCtrlBase::SetDefaultStyle( style
) ;
538 SetStyle( kTXNUseCurrentSelection
, kTXNUseCurrentSelection
, GetDefaultStyle() ) ;
542 // Clipboard operations
543 void wxTextCtrl::Copy()
551 void wxTextCtrl::Cut()
557 wxCommandEvent
event(wxEVT_COMMAND_TEXT_UPDATED
, m_windowId
);
558 event
.SetEventObject( this );
559 GetEventHandler()->ProcessEvent(event
);
563 void wxTextCtrl::Paste()
568 // eventually we should add setting the default style again
570 wxCommandEvent
event(wxEVT_COMMAND_TEXT_UPDATED
, m_windowId
);
571 event
.SetEventObject( this );
572 GetEventHandler()->ProcessEvent(event
);
576 bool wxTextCtrl::CanCopy() const
578 // Can copy if there's a selection
580 GetSelection(& from
, & to
);
584 bool wxTextCtrl::CanCut() const
590 // Can cut if there's a selection
592 GetSelection(& from
, & to
);
596 bool wxTextCtrl::CanPaste() const
601 return GetPeer()->CanPaste() ;
604 void wxTextCtrl::SetEditable(bool editable
)
606 if ( editable
!= m_editable
)
608 m_editable
= editable
;
609 GetPeer()->SetEditable( editable
) ;
613 void wxTextCtrl::SetInsertionPoint(long pos
)
615 SetSelection( pos
, pos
) ;
618 void wxTextCtrl::SetInsertionPointEnd()
620 wxTextPos pos
= GetLastPosition();
621 SetInsertionPoint(pos
);
624 long wxTextCtrl::GetInsertionPoint() const
627 GetSelection( &begin
, &end
) ;
631 wxTextPos
wxTextCtrl::GetLastPosition() const
633 return GetPeer()->GetLastPosition( ) ;
636 void wxTextCtrl::Replace(long from
, long to
, const wxString
& str
)
638 GetPeer()->Replace( from
, to
, str
) ;
641 void wxTextCtrl::Remove(long from
, long to
)
643 GetPeer()->Remove( from
, to
) ;
646 void wxTextCtrl::SetSelection(long from
, long to
)
648 GetPeer()->SetSelection( from
, to
) ;
651 bool wxTextCtrl::LoadFile(const wxString
& file
)
653 if ( wxTextCtrlBase::LoadFile(file
) )
661 void wxTextCtrl::WriteText(const wxString
& str
)
663 // TODO this MPRemoting will be moved into a remoting peer proxy for any command
664 if ( !wxIsMainThread() )
666 // unfortunately CW 8 is not able to correctly deduce the template types, so we have
667 // to instantiate explicitly
668 wxMacMPRemoteGUICall
<wxTextCtrl
,wxString
>( this , &wxTextCtrl::WriteText
, str
) ;
673 GetPeer()->WriteText( str
) ;
677 void wxTextCtrl::AppendText(const wxString
& text
)
679 SetInsertionPointEnd();
683 void wxTextCtrl::Clear()
688 bool wxTextCtrl::IsModified() const
693 bool wxTextCtrl::IsEditable() const
695 return IsEnabled() && m_editable
;
698 bool wxTextCtrl::AcceptsFocus() const
700 // we don't want focus if we can't be edited
701 return /*IsEditable() && */ wxControl::AcceptsFocus();
704 wxSize
wxTextCtrl::DoGetBestSize() const
710 // these are the numbers from the HIG, we reduce them by the borders
713 switch( m_windowVariant
)
715 case wxWINDOW_VARIANT_NORMAL
:
718 case wxWINDOW_VARIANT_SMALL
:
721 case wxWINDOW_VARIANT_MINI
:
729 // as the above numbers have some free space around the text
730 // we get 5 lines like this anyway
731 if ( m_windowStyle
& wxTE_MULTILINE
)
736 if ( !HasFlag(wxNO_BORDER
) )
739 return wxSize(wText
, hText
);
742 // ----------------------------------------------------------------------------
744 // ----------------------------------------------------------------------------
746 void wxTextCtrl::Undo()
754 void wxTextCtrl::Redo()
762 bool wxTextCtrl::CanUndo() const
768 return GetPeer()->CanUndo() ;
771 bool wxTextCtrl::CanRedo() const
777 return GetPeer()->CanRedo() ;
780 void wxTextCtrl::MarkDirty()
785 void wxTextCtrl::DiscardEdits()
790 int wxTextCtrl::GetNumberOfLines() const
792 return GetPeer()->GetNumberOfLines() ;
795 long wxTextCtrl::XYToPosition(long x
, long y
) const
797 return GetPeer()->XYToPosition( x
, y
) ;
800 bool wxTextCtrl::PositionToXY(long pos
, long *x
, long *y
) const
802 return GetPeer()->PositionToXY(pos
, x
, y
) ;
805 void wxTextCtrl::ShowPosition(long pos
)
807 return GetPeer()->ShowPosition(pos
) ;
810 int wxTextCtrl::GetLineLength(long lineNo
) const
812 return GetPeer()->GetLineLength(lineNo
) ;
815 wxString
wxTextCtrl::GetLineText(long lineNo
) const
817 return GetPeer()->GetLineText(lineNo
) ;
824 void wxTextCtrl::Command(wxCommandEvent
& event
)
826 SetValue (event
.GetString());
827 ProcessCommand (event
);
830 void wxTextCtrl::OnDropFiles(wxDropFilesEvent
& event
)
832 // By default, load the first file into the text window.
833 if (event
.GetNumberOfFiles() > 0)
835 LoadFile(event
.GetFiles()[0]);
839 void wxTextCtrl::OnEraseBackground(wxEraseEvent
& event
)
841 // all erasing should be done by the real mac control implementation
842 // while this is true for MLTE under classic, the HITextView is somehow
843 // transparent but background erase is not working correctly, so intercept
844 // things while we can...
848 void wxTextCtrl::OnChar(wxKeyEvent
& event
)
850 int key
= event
.GetKeyCode() ;
851 bool eat_key
= false ;
853 if ( key
== 'c' && event
.MetaDown() )
860 if ( !IsEditable() && key
!= WXK_LEFT
&& key
!= WXK_RIGHT
&& key
!= WXK_DOWN
&& key
!= WXK_UP
&& key
!= WXK_TAB
&&
861 !( key
== WXK_RETURN
&& ( (m_windowStyle
& wxPROCESS_ENTER
) || (m_windowStyle
& wxTE_MULTILINE
) ) )
862 /* && key != WXK_PRIOR && key != WXK_NEXT && key != WXK_HOME && key != WXK_END */
869 // Check if we have reached the max # of chars, but still allow navigation and deletion
870 if ( !IsMultiLine() && GetValue().Length() >= m_maxLength
&&
871 key
!= WXK_LEFT
&& key
!= WXK_RIGHT
&& key
!= WXK_TAB
&&
872 key
!= WXK_BACK
&& !( key
== WXK_RETURN
&& (m_windowStyle
& wxPROCESS_ENTER
) )
875 // eat it, we don't want to add more than allowed # of characters
879 // assume that any key not processed yet is going to modify the control
882 if ( key
== 'v' && event
.MetaDown() )
888 if ( key
== 'x' && event
.MetaDown() )
897 if (m_windowStyle
& wxPROCESS_ENTER
)
899 wxCommandEvent
event(wxEVT_COMMAND_TEXT_ENTER
, m_windowId
);
900 event
.SetEventObject( this );
901 event
.SetString( GetValue() );
902 if ( GetEventHandler()->ProcessEvent(event
) )
905 if ( !(m_windowStyle
& wxTE_MULTILINE
) )
907 wxWindow
*parent
= GetParent();
908 while( parent
&& !parent
->IsTopLevel() && parent
->GetDefaultItem() == NULL
) {
909 parent
= parent
->GetParent() ;
911 if ( parent
&& parent
->GetDefaultItem() )
913 wxButton
*def
= wxDynamicCast(parent
->GetDefaultItem(),
915 if ( def
&& def
->IsEnabled() )
917 wxCommandEvent
event(wxEVT_COMMAND_BUTTON_CLICKED
, def
->GetId() );
918 event
.SetEventObject(def
);
924 // this will make wxWidgets eat the ENTER key so that
925 // we actually prevent line wrapping in a single line
933 if ( !(m_windowStyle
& wxTE_PROCESS_TAB
))
936 if (!event
.ShiftDown())
937 flags
|= wxNavigationKeyEvent::IsForward
;
938 if (event
.ControlDown())
939 flags
|= wxNavigationKeyEvent::WinChange
;
945 // This is necessary (don't know why) or the tab will not
947 WriteText(wxT("\t"));
955 // perform keystroke handling
956 if ( wxTheApp
->MacGetCurrentEvent() != NULL
&& wxTheApp
->MacGetCurrentEventHandlerCallRef() != NULL
)
957 CallNextEventHandler((EventHandlerCallRef
)wxTheApp
->MacGetCurrentEventHandlerCallRef() , (EventRef
) wxTheApp
->MacGetCurrentEvent() ) ;
961 if ( wxMacConvertEventToRecord( (EventRef
) wxTheApp
->MacGetCurrentEvent() , &rec
) )
963 EventRecord
*ev
= &rec
;
966 keychar
= short(ev
->message
& charCodeMask
);
967 keycode
= short(ev
->message
& keyCodeMask
) >> 8 ;
969 m_peer
->HandleKey( keycode
, keychar
, ev
->modifiers
) ;
973 if ( ( key
>= 0x20 && key
< WXK_START
) ||
978 wxCommandEvent
event1(wxEVT_COMMAND_TEXT_UPDATED
, m_windowId
);
979 event1
.SetEventObject( this );
980 wxPostEvent(GetEventHandler(),event1
);
984 // ----------------------------------------------------------------------------
985 // standard handlers for standard edit menu events
986 // ----------------------------------------------------------------------------
988 void wxTextCtrl::OnCut(wxCommandEvent
& WXUNUSED(event
))
993 void wxTextCtrl::OnCopy(wxCommandEvent
& WXUNUSED(event
))
998 void wxTextCtrl::OnPaste(wxCommandEvent
& WXUNUSED(event
))
1003 void wxTextCtrl::OnUndo(wxCommandEvent
& WXUNUSED(event
))
1008 void wxTextCtrl::OnRedo(wxCommandEvent
& WXUNUSED(event
))
1013 void wxTextCtrl::OnDelete(wxCommandEvent
& WXUNUSED(event
))
1016 GetSelection(& from
, & to
);
1017 if (from
!= -1 && to
!= -1)
1021 void wxTextCtrl::OnSelectAll(wxCommandEvent
& WXUNUSED(event
))
1023 SetSelection(-1, -1);
1026 void wxTextCtrl::OnUpdateCut(wxUpdateUIEvent
& event
)
1028 event
.Enable( CanCut() );
1031 void wxTextCtrl::OnUpdateCopy(wxUpdateUIEvent
& event
)
1033 event
.Enable( CanCopy() );
1036 void wxTextCtrl::OnUpdatePaste(wxUpdateUIEvent
& event
)
1038 event
.Enable( CanPaste() );
1041 void wxTextCtrl::OnUpdateUndo(wxUpdateUIEvent
& event
)
1043 event
.Enable( CanUndo() );
1046 void wxTextCtrl::OnUpdateRedo(wxUpdateUIEvent
& event
)
1048 event
.Enable( CanRedo() );
1051 void wxTextCtrl::OnUpdateDelete(wxUpdateUIEvent
& event
)
1054 GetSelection(& from
, & to
);
1055 event
.Enable(from
!= -1 && to
!= -1 && from
!= to
&& IsEditable()) ;
1058 void wxTextCtrl::OnUpdateSelectAll(wxUpdateUIEvent
& event
)
1060 event
.Enable(GetLastPosition() > 0);
1063 // CS: Context Menus only work with mlte implementations or non-multiline HIViews at the moment
1065 void wxTextCtrl::OnContextMenu(wxContextMenuEvent
& event
)
1067 if (m_privateContextMenu
== NULL
)
1069 m_privateContextMenu
= new wxMenu
;
1070 m_privateContextMenu
->Append(wxID_UNDO
, _("&Undo"));
1071 m_privateContextMenu
->Append(wxID_REDO
, _("&Redo"));
1072 m_privateContextMenu
->AppendSeparator();
1073 m_privateContextMenu
->Append(wxID_CUT
, _("Cu&t"));
1074 m_privateContextMenu
->Append(wxID_COPY
, _("&Copy"));
1075 m_privateContextMenu
->Append(wxID_PASTE
, _("&Paste"));
1076 m_privateContextMenu
->Append(wxID_CLEAR
, _("&Delete"));
1077 m_privateContextMenu
->AppendSeparator();
1078 m_privateContextMenu
->Append(wxID_SELECTALL
, _("Select &All"));
1081 if (m_privateContextMenu
!= NULL
)
1082 PopupMenu(m_privateContextMenu
);
1085 bool wxTextCtrl::MacSetupCursor( const wxPoint
& pt
)
1087 if ( !GetPeer()->SetupCursor(pt
) )
1088 return wxWindow::MacSetupCursor( pt
) ;
1092 #if !TARGET_API_MAC_OSX
1094 // user pane implementation
1096 void wxTextCtrl::MacControlUserPaneDrawProc(wxInt16 part
)
1098 GetPeer()->MacControlUserPaneDrawProc( part
) ;
1101 wxInt16
wxTextCtrl::MacControlUserPaneHitTestProc(wxInt16 x
, wxInt16 y
)
1103 return GetPeer()->MacControlUserPaneHitTestProc( x
, y
) ;
1106 wxInt16
wxTextCtrl::MacControlUserPaneTrackingProc(wxInt16 x
, wxInt16 y
, void* actionProc
)
1108 return GetPeer()->MacControlUserPaneTrackingProc( x
, y
, actionProc
) ;
1111 void wxTextCtrl::MacControlUserPaneIdleProc()
1113 GetPeer()->MacControlUserPaneIdleProc( ) ;
1116 wxInt16
wxTextCtrl::MacControlUserPaneKeyDownProc(wxInt16 keyCode
, wxInt16 charCode
, wxInt16 modifiers
)
1118 return GetPeer()->MacControlUserPaneKeyDownProc( keyCode
, charCode
, modifiers
) ;
1121 void wxTextCtrl::MacControlUserPaneActivateProc(bool activating
)
1123 GetPeer()->MacControlUserPaneActivateProc( activating
) ;
1126 wxInt16
wxTextCtrl::MacControlUserPaneFocusProc(wxInt16 action
)
1128 return GetPeer()->MacControlUserPaneFocusProc( action
) ;
1131 void wxTextCtrl::MacControlUserPaneBackgroundProc(void* info
)
1133 GetPeer()->MacControlUserPaneBackgroundProc( info
) ;
1137 // ----------------------------------------------------------------------------
1138 // implementation base class
1139 // ----------------------------------------------------------------------------
1141 wxMacTextControl::wxMacTextControl(wxTextCtrl
* peer
) :
1142 wxMacControl( peer
)
1146 wxMacTextControl::~wxMacTextControl()
1150 void wxMacTextControl::SetStyle(long start
, long end
, const wxTextAttr
& style
)
1154 void wxMacTextControl::Copy()
1158 void wxMacTextControl::Cut()
1162 void wxMacTextControl::Paste()
1166 bool wxMacTextControl::CanPaste() const
1171 void wxMacTextControl::SetEditable(bool editable
)
1175 wxTextPos
wxMacTextControl::GetLastPosition() const
1177 return GetStringValue().Length() ;
1180 void wxMacTextControl::Replace( long from
, long to
, const wxString str
)
1184 void wxMacTextControl::Clear()
1186 SetStringValue( wxEmptyString
) ;
1189 bool wxMacTextControl::CanUndo() const
1194 void wxMacTextControl::Undo() { }
1196 bool wxMacTextControl::CanRedo() const
1201 void wxMacTextControl::Redo()
1205 long wxMacTextControl::XYToPosition(long x
, long y
) const
1210 bool wxMacTextControl::PositionToXY(long pos
, long *x
, long *y
) const
1215 void wxMacTextControl::ShowPosition( long WXUNUSED(pos
) )
1219 int wxMacTextControl::GetNumberOfLines() const
1221 ItemCount lines
= 0 ;
1222 wxString content
= GetStringValue() ;
1224 for (size_t i
= 0; i
< content
.Length() ; i
++)
1226 if (content
[i
] == '\r') lines
++;
1231 wxString
wxMacTextControl::GetLineText(long lineNo
) const
1233 // TODO change this if possible to reflect real lines
1234 wxString content
= GetStringValue() ;
1238 for (size_t i
= 0; i
< content
.Length() ; i
++)
1240 if (count
== lineNo
)
1242 // Add chars in line then
1245 for (size_t j
= i
; j
< content
.Length(); j
++)
1247 if (content
[j
] == '\n')
1255 if (content
[i
] == '\n') count
++;
1257 return wxEmptyString
;
1260 int wxMacTextControl::GetLineLength(long lineNo
) const
1262 // TODO change this if possible to reflect real lines
1263 wxString content
= GetStringValue() ;
1267 for (size_t i
= 0; i
< content
.Length() ; i
++)
1269 if (count
== lineNo
)
1271 // Count chars in line then
1273 for (size_t j
= i
; j
< content
.Length(); j
++)
1276 if (content
[j
] == '\n') return count
;
1281 if (content
[i
] == '\n') count
++;
1286 // ----------------------------------------------------------------------------
1287 // standard unicode control implementation
1288 // ----------------------------------------------------------------------------
1290 #if TARGET_API_MAC_OSX
1292 wxMacUnicodeTextControl::wxMacUnicodeTextControl( wxTextCtrl
*wxPeer
,
1293 const wxString
& str
,
1295 const wxSize
& size
, long style
) : wxMacTextControl( wxPeer
)
1297 m_font
= wxPeer
->GetFont() ;
1298 m_windowStyle
= style
;
1299 Rect bounds
= wxMacGetBoundsForControl( wxPeer
, pos
, size
) ;
1301 wxMacConvertNewlines10To13( &st
) ;
1302 wxMacCFStringHolder
cf(st
, m_font
.GetEncoding()) ;
1303 CFStringRef cfr
= cf
;
1304 Boolean isPassword
= ( m_windowStyle
& wxTE_PASSWORD
) != 0 ;
1305 m_valueTag
= isPassword
? kControlEditTextPasswordCFStringTag
: kControlEditTextCFStringTag
;
1306 CreateEditUnicodeTextControl( MAC_WXHWND(wxPeer
->MacGetTopLevelWindowRef()), &bounds
, cfr
, isPassword
, NULL
, &m_controlRef
) ;
1308 if ( !(m_windowStyle
& wxTE_MULTILINE
) )
1310 SetData
<Boolean
>( kControlEditTextPart
, kControlEditTextSingleLineTag
, true ) ;
1314 wxMacUnicodeTextControl::~wxMacUnicodeTextControl()
1318 void wxMacUnicodeTextControl::VisibilityChanged(bool shown
)
1320 if ( !(m_windowStyle
& wxTE_MULTILINE
) && shown
)
1322 // work around a refresh issue insofar as not always the entire content is shown even if this would be possible
1323 ControlEditTextSelectionRec sel
;
1324 CFStringRef value
= NULL
;
1326 verify_noerr( GetData
<ControlEditTextSelectionRec
>( 0, kControlEditTextSelectionTag
, &sel
) );
1327 verify_noerr( GetData
<CFStringRef
>( 0, m_valueTag
, &value
) );
1328 verify_noerr( SetData
<CFStringRef
>( 0, m_valueTag
, &value
) );
1329 verify_noerr( SetData
<ControlEditTextSelectionRec
>( 0, kControlEditTextSelectionTag
, &sel
) );
1331 CFRelease( value
) ;
1334 wxString
wxMacUnicodeTextControl::GetStringValue() const
1337 CFStringRef value
= GetData
<CFStringRef
>(0,m_valueTag
) ;
1340 wxMacCFStringHolder
cf(value
) ;
1341 result
= cf
.AsString() ;
1344 wxMacConvertNewlines13To10( &result
) ;
1346 wxMacConvertNewlines10To13( &result
) ;
1350 void wxMacUnicodeTextControl::SetStringValue( const wxString
&str
)
1353 wxMacConvertNewlines10To13( &st
) ;
1354 wxMacCFStringHolder
cf(st
, m_font
.GetEncoding() ) ;
1355 verify_noerr( SetData
<CFStringRef
>( 0, m_valueTag
, cf
) ) ;
1357 void wxMacUnicodeTextControl::Copy()
1359 SendHICommand( kHICommandCopy
) ;
1361 void wxMacUnicodeTextControl::Cut()
1363 SendHICommand( kHICommandCut
) ;
1365 void wxMacUnicodeTextControl::Paste()
1367 SendHICommand( kHICommandPaste
) ;
1369 bool wxMacUnicodeTextControl::CanPaste() const
1373 void wxMacUnicodeTextControl::SetEditable(bool editable
)
1375 SetData
<Boolean
>( 0 , kControlEditTextLockedTag
, (Boolean
) !editable
) ;
1377 void wxMacUnicodeTextControl::Remove( long from
, long to
)
1381 void wxMacUnicodeTextControl::GetSelection( long* from
, long* to
) const
1383 ControlEditTextSelectionRec sel
;
1384 verify_noerr(GetData
<ControlEditTextSelectionRec
>( 0, kControlEditTextSelectionTag
, &sel
) ) ;
1385 if ( from
) *from
= sel
.selStart
;
1386 if ( to
) *to
= sel
.selEnd
;
1389 void wxMacUnicodeTextControl::SetSelection( long from
, long to
)
1391 ControlEditTextSelectionRec sel
;
1392 if ((from
== -1) && (to
== -1))
1395 to
= 32767 ; // sel has 16 bit signed values, max is 32767
1397 sel
.selStart
= from
;
1399 SetData
<ControlEditTextSelectionRec
>( 0 , kControlEditTextSelectionTag
, &sel
) ;
1402 void wxMacUnicodeTextControl::WriteText(const wxString
& str
)
1405 wxMacConvertNewlines10To13( &st
) ;
1406 #if MAC_OS_X_VERSION_MAX_ALLOWED > MAC_OS_X_VERSION_10_2
1407 wxMacCFStringHolder
cf(st
, m_font
.GetEncoding() ) ;
1408 CFStringRef value
= cf
;
1409 SetData
<CFStringRef
>( 0, kControlEditTextInsertCFStringRefTag
, &value
);
1411 wxString val
= GetStringValue() ;
1413 GetSelection( &start
, &end
) ;
1414 val
.Remove( start
, end
- start
) ;
1415 val
.insert( start
, str
) ;
1416 SetStringValue( val
) ;
1417 SetSelection( start
+ str
.Length() , start
+ str
.Length() ) ;
1423 // ----------------------------------------------------------------------------
1424 // MLTE control implementation (common part)
1425 // ----------------------------------------------------------------------------
1427 // if mlte is on read only , no changes at all are allowed, not even from
1428 // procedural API, in order to allow changes via API all the same we must undo
1429 // the readonly status while we are executing, this class helps to do so
1431 class wxMacEditHelper
1434 wxMacEditHelper( TXNObject txn
)
1436 TXNControlTag tag
[] = { kTXNIOPrivilegesTag
} ;
1438 TXNGetTXNObjectControls( m_txn
, 1 , tag
, m_data
) ;
1439 if ( m_data
[0].uValue
== kTXNReadOnly
)
1441 TXNControlData data
[] = { { kTXNReadWrite
} } ;
1442 TXNSetTXNObjectControls( m_txn
, false , 1 , tag
, data
) ;
1447 TXNControlTag tag
[] = { kTXNIOPrivilegesTag
} ;
1448 if ( m_data
[0].uValue
== kTXNReadOnly
)
1450 TXNSetTXNObjectControls( m_txn
, false , 1 , tag
, m_data
) ;
1455 TXNControlData m_data
[1] ;
1458 wxMacMLTEControl::wxMacMLTEControl( wxTextCtrl
*peer
) : wxMacTextControl( peer
)
1460 SetNeedsFocusRect( true ) ;
1463 wxString
wxMacMLTEControl::GetStringValue() const
1467 Size actualSize
= 0;
1471 err
= TXNGetDataEncoded( m_txn
, kTXNStartOffset
, kTXNEndOffset
, &theText
, kTXNUnicodeTextData
);
1479 actualSize
= GetHandleSize( theText
) / sizeof( UniChar
) ;
1480 if ( actualSize
> 0 )
1482 wxChar
*ptr
= NULL
;
1483 #if SIZEOF_WCHAR_T == 2
1484 ptr
= new wxChar
[actualSize
+ 1 ] ;
1485 wxStrncpy( ptr
, (wxChar
*) *theText
, actualSize
) ;
1487 SetHandleSize( theText
, ( actualSize
+ 1 ) * sizeof( UniChar
) ) ;
1489 (((UniChar
*)*theText
)[actualSize
]) = 0 ;
1490 wxMBConvUTF16 converter
;
1491 size_t noChars
= converter
.MB2WC( NULL
, (const char*)*theText
, 0 ) ;
1492 ptr
= new wxChar
[noChars
+ 1] ;
1494 noChars
= converter
.MB2WC( ptr
, (const char*)*theText
, noChars
) ;
1496 HUnlock( theText
) ;
1498 ptr
[actualSize
] = 0 ;
1499 result
= wxString( ptr
) ;
1502 DisposeHandle( theText
) ;
1506 err
= TXNGetDataEncoded( m_txn
, kTXNStartOffset
, kTXNEndOffset
, &theText
, kTXNTextData
);
1514 actualSize
= GetHandleSize( theText
) ;
1515 if ( actualSize
> 0 )
1518 result
= wxString( *theText
, wxConvLocal
, actualSize
) ;
1519 HUnlock( theText
) ;
1521 DisposeHandle( theText
) ;
1526 wxMacConvertNewlines13To10( &result
) ;
1528 wxMacConvertNewlines10To13( &result
) ;
1533 void wxMacMLTEControl::SetStringValue( const wxString
&str
)
1537 wxMacConvertNewlines10To13( &st
) ;
1539 wxMacWindowClipper
c( m_peer
) ;
1541 wxMacEditHelper
help(m_txn
) ;
1542 SetTXNData( st
, kTXNStartOffset
, kTXNEndOffset
) ;
1544 TXNSetSelection( m_txn
, 0, 0);
1545 TXNShowSelection( m_txn
, kTXNShowStart
);
1549 TXNFrameOptions
wxMacMLTEControl::FrameOptionsFromWXStyle( long wxStyle
)
1551 TXNFrameOptions frameOptions
=
1552 kTXNDontDrawCaretWhenInactiveMask
1553 #if MAC_OS_X_VERSION_MAX_ALLOWED >= MAC_OS_X_VERSION_10_3
1554 | kTXNDoFontSubstitutionMask
1558 if ( ! ( wxStyle
& wxTE_NOHIDESEL
) )
1559 frameOptions
|= kTXNDontDrawSelectionWhenInactiveMask
;
1561 if ( wxStyle
& wxTE_MULTILINE
)
1563 if ( ! ( wxStyle
& wxTE_DONTWRAP
) )
1564 frameOptions
|= kTXNAlwaysWrapAtViewEdgeMask
;
1567 frameOptions
|= kTXNAlwaysWrapAtViewEdgeMask
;
1568 frameOptions
|= kTXNWantHScrollBarMask
;
1571 if ( !(wxStyle
& wxTE_NO_VSCROLL
) )
1573 frameOptions
|= kTXNWantVScrollBarMask
;
1574 if ( frameOptions
& kTXNWantHScrollBarMask
)
1575 frameOptions
|= kTXNDrawGrowIconMask
;
1579 frameOptions
|= kTXNSingleLineOnlyMask
;
1581 if ( wxStyle
& wxHSCROLL
)
1582 frameOptions
|= kTXNWantHScrollBarMask
;
1584 return frameOptions
;
1587 void wxMacMLTEControl::AdjustCreationAttributes( const wxColour
&background
, bool visible
)
1589 TXNControlTag iControlTags
[] =
1591 kTXNDoFontSubstitution
,
1592 kTXNWordWrapStateTag
,
1594 TXNControlData iControlData
[] =
1600 int toptag
= WXSIZEOF( iControlTags
) ;
1602 if ( m_windowStyle
& wxTE_MULTILINE
)
1604 if (m_windowStyle
& wxTE_DONTWRAP
)
1605 iControlData
[1].uValue
= kTXNNoAutoWrap
;
1607 iControlData
[1].uValue
= kTXNAutoWrap
;
1609 verify_noerr( TXNSetTXNObjectControls( m_txn
, false, toptag
,
1610 iControlTags
, iControlData
)) ;
1612 // setting the default font
1613 // under 10.2 this causes a visible caret, therefore we avoid it
1615 if ( UMAGetSystemVersion() >= 0x1030 )
1621 GetThemeFont(kThemeSystemFont
, GetApplicationScript() , fontName
, &fontSize
, &fontStyle
) ;
1623 TXNTypeAttributes typeAttr
[] =
1625 { kTXNQDFontNameAttribute
, kTXNQDFontNameAttributeSize
, { (void*) fontName
} } ,
1626 { kTXNQDFontSizeAttribute
, kTXNFontSizeAttributeSize
, { (void*) (fontSize
<< 16) } } ,
1627 { kTXNQDFontStyleAttribute
, kTXNQDFontStyleAttributeSize
, { (void*) normal
} } ,
1630 verify_noerr( TXNSetTypeAttributes (m_txn
, sizeof( typeAttr
) / sizeof(TXNTypeAttributes
) , typeAttr
,
1635 if ( m_windowStyle
& wxTE_PASSWORD
)
1638 verify_noerr(TXNEchoMode( m_txn
, c
, 0 , true )) ;
1641 TXNBackground tback
;
1642 tback
.bgType
= kTXNBackgroundTypeRGB
;
1643 tback
.bg
.color
= MAC_WXCOLORREF( background
.GetPixel() );
1644 TXNSetBackground( m_txn
, &tback
);
1647 void wxMacMLTEControl::SetBackground( const wxBrush
&brush
)
1649 // currently only solid background are supported
1650 TXNBackground tback
;
1651 tback
.bgType
= kTXNBackgroundTypeRGB
;
1652 tback
.bg
.color
= MAC_WXCOLORREF( brush
.GetColour().GetPixel() );
1653 TXNSetBackground( m_txn
, &tback
);
1656 void wxMacMLTEControl::TXNSetAttribute( const wxTextAttr
& style
, long from
, long to
)
1658 TXNTypeAttributes typeAttr
[4] ;
1659 Str255 fontName
= "\pMonaco" ;
1660 SInt16 fontSize
= 12 ;
1661 Style fontStyle
= normal
;
1663 int attrCounter
= 0 ;
1664 if ( style
.HasFont() )
1666 const wxFont
&font
= style
.GetFont() ;
1667 wxMacStringToPascal( font
.GetFaceName() , fontName
) ;
1668 fontSize
= font
.GetPointSize() ;
1669 if ( font
.GetUnderlined() )
1670 fontStyle
|= underline
;
1671 if ( font
.GetWeight() == wxBOLD
)
1673 if ( font
.GetStyle() == wxITALIC
)
1674 fontStyle
|= italic
;
1676 typeAttr
[attrCounter
].tag
= kTXNQDFontNameAttribute
;
1677 typeAttr
[attrCounter
].size
= kTXNQDFontNameAttributeSize
;
1678 typeAttr
[attrCounter
].data
.dataPtr
= (void*) fontName
;
1679 typeAttr
[attrCounter
+1].tag
= kTXNQDFontSizeAttribute
;
1680 typeAttr
[attrCounter
+1].size
= kTXNFontSizeAttributeSize
;
1681 typeAttr
[attrCounter
+1].data
.dataValue
= (fontSize
<< 16) ;
1682 typeAttr
[attrCounter
+2].tag
= kTXNQDFontStyleAttribute
;
1683 typeAttr
[attrCounter
+2].size
= kTXNQDFontStyleAttributeSize
;
1684 typeAttr
[attrCounter
+2].data
.dataValue
= fontStyle
;
1687 if ( style
.HasTextColour() )
1689 typeAttr
[attrCounter
].tag
= kTXNQDFontColorAttribute
;
1690 typeAttr
[attrCounter
].size
= kTXNQDFontColorAttributeSize
;
1691 typeAttr
[attrCounter
].data
.dataPtr
= (void*) &color
;
1692 color
= MAC_WXCOLORREF(style
.GetTextColour().GetPixel()) ;
1695 if ( attrCounter
> 0 )
1697 verify_noerr( TXNSetTypeAttributes ( m_txn
, attrCounter
, typeAttr
, from
, to
) );
1701 void wxMacMLTEControl::SetFont( const wxFont
& font
, const wxColour
& foreground
, long windowStyle
)
1703 wxMacEditHelper
help(m_txn
) ;
1704 TXNSetAttribute( wxTextAttr(foreground
,wxNullColour
,font
) , kTXNStartOffset
,kTXNEndOffset
) ;
1706 void wxMacMLTEControl::SetStyle(long start
, long end
, const wxTextAttr
& style
)
1708 wxMacEditHelper
help(m_txn
) ;
1709 TXNSetAttribute( style
, start
,end
) ;
1712 void wxMacMLTEControl::Copy()
1714 ClearCurrentScrap();
1716 TXNConvertToPublicScrap();
1719 void wxMacMLTEControl::Cut()
1721 ClearCurrentScrap();
1723 TXNConvertToPublicScrap();
1726 void wxMacMLTEControl::Paste()
1728 TXNConvertFromPublicScrap();
1732 bool wxMacMLTEControl::CanPaste() const
1734 return TXNIsScrapPastable() ;
1737 void wxMacMLTEControl::SetEditable(bool editable
)
1739 TXNControlTag tag
[] = { kTXNIOPrivilegesTag
} ;
1740 TXNControlData data
[] = { { editable
? kTXNReadWrite
: kTXNReadOnly
} } ;
1741 TXNSetTXNObjectControls( m_txn
, false , WXSIZEOF(tag
) , tag
, data
) ;
1744 wxTextPos
wxMacMLTEControl::GetLastPosition() const
1746 wxTextPos actualsize
= 0 ;
1749 OSErr err
= TXNGetDataEncoded( m_txn
, kTXNStartOffset
, kTXNEndOffset
, &theText
, kTXNTextData
);
1757 actualsize
= GetHandleSize( theText
) ;
1758 DisposeHandle( theText
) ;
1764 void wxMacMLTEControl::Replace( long from
, long to
, const wxString str
)
1766 wxString value
= str
;
1767 wxMacConvertNewlines10To13( &value
) ;
1769 wxMacEditHelper
help( m_txn
) ;
1770 wxMacWindowClipper
c( m_peer
) ;
1772 TXNSetSelection(m_txn
, from
, to
) ;
1774 SetTXNData( value
, kTXNUseCurrentSelection
, kTXNUseCurrentSelection
) ;
1777 void wxMacMLTEControl::Remove( long from
, long to
)
1779 wxMacWindowClipper
c( m_peer
) ;
1780 wxMacEditHelper
help( m_txn
) ;
1781 TXNSetSelection(m_txn
, from
, to
) ;
1785 void wxMacMLTEControl::GetSelection( long* from
, long* to
) const
1787 TXNGetSelection( m_txn
, (TXNOffset
*) from
, (TXNOffset
*) to
) ;
1790 void wxMacMLTEControl::SetSelection( long from
, long to
)
1792 wxMacWindowClipper
c( m_peer
) ;
1793 /* change the selection */
1794 if ((from
== -1) && (to
== -1))
1795 TXNSelectAll(m_txn
);
1797 TXNSetSelection( m_txn
, from
, to
);
1798 TXNShowSelection( m_txn
, kTXNShowStart
);
1801 void wxMacMLTEControl::WriteText(const wxString
& str
)
1804 wxMacConvertNewlines10To13( &st
) ;
1806 long start
, end
, dummy
;
1807 GetSelection( &start
, &dummy
) ;
1808 wxMacWindowClipper
c( m_peer
) ;
1810 wxMacEditHelper
helper( m_txn
) ;
1811 SetTXNData( st
, kTXNUseCurrentSelection
, kTXNUseCurrentSelection
) ;
1813 GetSelection( &dummy
, &end
) ;
1814 // TODO SetStyle( start , end , GetDefaultStyle() ) ;
1817 void wxMacMLTEControl::Clear()
1819 wxMacWindowClipper
c( m_peer
) ;
1820 wxMacEditHelper
st(m_txn
) ;
1821 TXNSetSelection( m_txn
, kTXNStartOffset
, kTXNEndOffset
) ;
1825 bool wxMacMLTEControl::CanUndo() const
1827 return TXNCanUndo( m_txn
, NULL
) ;
1830 void wxMacMLTEControl::Undo()
1835 bool wxMacMLTEControl::CanRedo() const
1837 return TXNCanRedo( m_txn
, NULL
) ;
1840 void wxMacMLTEControl::Redo()
1845 int wxMacMLTEControl::GetNumberOfLines() const
1847 ItemCount lines
= 0 ;
1848 TXNGetLineCount(m_txn
, &lines
) ;
1852 long wxMacMLTEControl::XYToPosition(long x
, long y
) const
1856 wxTextPos lastpos
= GetLastPosition() ;
1858 // TODO find a better implementation : while we can get the
1859 // line metrics of a certain line, we don't get its starting
1860 // position, so it would probably be rather a binary search
1861 // for the start position
1864 int lastHeight
= 0 ;
1867 for ( n
= 0 ; n
<= (ItemCount
) lastpos
; ++n
)
1869 if ( y
== ypos
&& x
== xpos
)
1872 TXNOffsetToPoint( m_txn
, n
, &curpt
);
1874 if ( curpt
.v
> lastHeight
)
1879 lastHeight
= curpt
.v
;
1887 bool wxMacMLTEControl::PositionToXY(long pos
, long *x
, long *y
) const
1891 wxTextPos lastpos
= GetLastPosition() ;
1896 if ( pos
<= lastpos
)
1898 // TODO find a better implementation : while we can get the
1899 // line metrics of a certain line, we don't get its starting
1900 // position, so it would probably be rather a binary search
1901 // for the start position
1904 int lastHeight
= 0 ;
1907 for ( n
= 0 ; n
<= (ItemCount
) pos
; ++n
)
1909 TXNOffsetToPoint(m_txn
, n
, &curpt
);
1911 if ( curpt
.v
> lastHeight
)
1916 lastHeight
= curpt
.v
;
1921 if ( y
) *y
= ypos
;
1922 if ( x
) *x
= xpos
;
1928 void wxMacMLTEControl::ShowPosition( long pos
)
1930 #if TARGET_RT_MAC_MACHO && defined(AVAILABLE_MAC_OS_X_VERSION_10_2_AND_LATER)
1934 TXNOffset selstart
, selend
;
1935 TXNGetSelection( m_txn
, &selstart
, &selend
) ;
1936 TXNOffsetToPoint( m_txn
, selstart
, ¤t
);
1937 TXNOffsetToPoint( m_txn
, pos
, &desired
);
1938 //TODO use HIPoints for 10.3 and above
1939 if ( (UInt32
) TXNScroll
!= (UInt32
) kUnresolvedCFragSymbolAddress
)
1941 OSErr theErr
= noErr
;
1942 SInt32 dv
= desired
.v
- current
.v
;
1943 SInt32 dh
= desired
.h
- current
.h
;
1944 TXNShowSelection( m_txn
, true ) ;
1945 theErr
= TXNScroll( m_txn
, kTXNScrollUnitsInPixels
, kTXNScrollUnitsInPixels
, &dv
, &dh
);
1946 // there will be an error returned for classic mlte implementation when the control is
1947 // invisible, but HITextView works correctly, so we don't assert that one
1948 // wxASSERT_MSG( theErr == noErr, _T("TXNScroll returned an error!") );
1954 void wxMacMLTEControl::SetTXNData( const wxString
& st
, TXNOffset start
, TXNOffset end
)
1957 #if SIZEOF_WCHAR_T == 2
1958 size_t len
= st
.Len() ;
1959 TXNSetData( m_txn
, kTXNUnicodeTextData
, (void*)st
.wc_str(), len
* 2,
1962 wxMBConvUTF16 converter
;
1963 ByteCount byteBufferLen
= converter
.WC2MB( NULL
, st
.wc_str() , 0 ) ;
1964 UniChar
*unibuf
= (UniChar
*) malloc(byteBufferLen
) ;
1965 converter
.WC2MB( (char*) unibuf
, st
.wc_str() , byteBufferLen
) ;
1966 TXNSetData( m_txn
, kTXNUnicodeTextData
, (void*)unibuf
, byteBufferLen
,
1971 wxCharBuffer text
= st
.mb_str(wxConvLocal
) ;
1972 TXNSetData( m_txn
, kTXNTextData
, (void*)text
.data(), strlen( text
) ,
1978 wxString
wxMacMLTEControl::GetLineText(long lineNo
) const
1982 if ( lineNo
< GetNumberOfLines() )
1990 // get the first possible position in the control
1992 TXNOffsetToPoint(m_txn
, 0, &firstPoint
);
1994 // Iterate through the lines until we reach the one we want,
1995 // adding to our current y pixel point position
1996 while (ypos
< lineNo
)
1998 TXNGetLineMetrics(m_txn
, ypos
++, &lineWidth
, &lineHeight
);
1999 currentHeight
+= lineHeight
;
2002 Point thePoint
= { firstPoint
.v
+ (currentHeight
>> 16), firstPoint
.h
+ (0) };
2003 TXNOffset theOffset
;
2004 TXNPointToOffset(m_txn
, thePoint
, &theOffset
);
2006 wxString content
= GetStringValue() ;
2007 Point currentPoint
= thePoint
;
2008 while(thePoint
.v
== currentPoint
.v
&& theOffset
< content
.length())
2010 line
+= content
[theOffset
];
2011 TXNOffsetToPoint(m_txn
, ++theOffset
, ¤tPoint
);
2017 int wxMacMLTEControl::GetLineLength(long lineNo
) const
2021 if ( lineNo
< GetNumberOfLines() )
2029 // get the first possible position in the control
2031 TXNOffsetToPoint(m_txn
, 0, &firstPoint
);
2033 // Iterate through the lines until we reach the one we want,
2034 // adding to our current y pixel point position
2035 while (ypos
< lineNo
)
2037 TXNGetLineMetrics(m_txn
, ypos
++, &lineWidth
, &lineHeight
);
2038 currentHeight
+= lineHeight
;
2041 Point thePoint
= { firstPoint
.v
+ (currentHeight
>> 16), firstPoint
.h
+ (0) };
2042 TXNOffset theOffset
;
2043 TXNPointToOffset(m_txn
, thePoint
, &theOffset
);
2045 wxString content
= GetStringValue() ;
2046 Point currentPoint
= thePoint
;
2047 while(thePoint
.v
== currentPoint
.v
&& theOffset
< content
.length())
2050 TXNOffsetToPoint(m_txn
, ++theOffset
, ¤tPoint
);
2057 // ----------------------------------------------------------------------------
2058 // MLTE control implementation (classic part)
2059 // ----------------------------------------------------------------------------
2061 // OS X Notes : We still don't have a full replacement for MLTE, so this implementation
2062 // has to live on. We have different problems coming from outdated implementations on the
2063 // various OS X versions. Most deal with the scrollbars: they are not correctly embedded
2064 // while this can be solved on 10.3 by reassigning them the correct place, on 10.2 there is
2065 // no way out, therefore we are using our own implementation and our own scrollbars ....
2067 #ifdef __WXMAC_OSX__
2069 TXNScrollInfoUPP gTXNScrollInfoProc
= NULL
;
2070 ControlActionUPP gTXNScrollActionProc
= NULL
;
2072 pascal void wxMacMLTEClassicControl::TXNScrollInfoProc (SInt32 iValue
, SInt32 iMaximumValue
, TXNScrollBarOrientation
2073 iScrollBarOrientation
, SInt32 iRefCon
)
2075 wxMacMLTEClassicControl
* mlte
= (wxMacMLTEClassicControl
*) iRefCon
;
2076 SInt32 value
= wxMax( iValue
, 0 ) ;
2077 SInt32 maximum
= wxMax( iMaximumValue
, 0 ) ;
2079 if ( iScrollBarOrientation
== kTXNHorizontal
)
2081 if ( mlte
->m_sbHorizontal
)
2083 SetControl32BitValue( mlte
->m_sbHorizontal
, value
) ;
2084 SetControl32BitMaximum( mlte
->m_sbHorizontal
, maximum
) ;
2085 mlte
->m_lastHorizontalValue
= value
;
2088 else if ( iScrollBarOrientation
== kTXNVertical
)
2090 if ( mlte
->m_sbVertical
)
2092 SetControl32BitValue( mlte
->m_sbVertical
, value
) ;
2093 SetControl32BitMaximum( mlte
->m_sbVertical
, maximum
) ;
2094 mlte
->m_lastVerticalValue
= value
;
2099 pascal void wxMacMLTEClassicControl::TXNScrollActionProc( ControlRef controlRef
, ControlPartCode partCode
)
2102 wxMacMLTEClassicControl
* mlte
= (wxMacMLTEClassicControl
*) GetControlReference( controlRef
) ;
2106 if ( controlRef
!= mlte
->m_sbVertical
&& controlRef
!= mlte
->m_sbHorizontal
)
2109 bool isHorizontal
= ( controlRef
== mlte
->m_sbHorizontal
) ;
2111 SInt32 minimum
= 0 ;
2112 SInt32 maximum
= GetControl32BitMaximum( controlRef
) ;
2113 SInt32 value
= GetControl32BitValue( controlRef
) ;
2117 case kControlDownButtonPart
:
2120 case kControlUpButtonPart
:
2123 case kControlPageDownPart
:
2124 delta
= GetControlViewSize( controlRef
) ;
2126 case kControlPageUpPart
:
2127 delta
= -GetControlViewSize( controlRef
) ;
2129 case kControlIndicatorPart
:
2131 ( isHorizontal
? mlte
->m_lastHorizontalValue
: mlte
->m_lastVerticalValue
) ;
2138 SInt32 newValue
= value
;
2140 if ( partCode
!= kControlIndicatorPart
)
2142 if( value
+ delta
< minimum
)
2143 delta
= minimum
- value
;
2144 if ( value
+ delta
> maximum
)
2145 delta
= maximum
- value
;
2147 SetControl32BitValue( controlRef
, value
+ delta
) ;
2148 newValue
= value
+ delta
;
2151 SInt32 verticalDelta
= isHorizontal
? 0 : delta
;
2152 SInt32 horizontalDelta
= isHorizontal
? delta
: 0 ;
2154 err
= TXNScroll( mlte
->m_txn
, kTXNScrollUnitsInPixels
, kTXNScrollUnitsInPixels
,
2155 &verticalDelta
, &horizontalDelta
);
2158 mlte
->m_lastHorizontalValue
= newValue
;
2160 mlte
->m_lastVerticalValue
= newValue
;
2165 // make correct activations
2166 void wxMacMLTEClassicControl::MacActivatePaneText(Boolean setActive
)
2168 wxTextCtrl
* textctrl
= (wxTextCtrl
*) GetControlReference(m_controlRef
);
2170 wxMacWindowClipper
clipper( textctrl
) ;
2171 TXNActivate(m_txn
, m_txnFrameID
, setActive
);
2173 ControlRef controlFocus
= 0 ;
2174 GetKeyboardFocus( m_txnWindow
, &controlFocus
) ;
2175 if ( controlFocus
== m_controlRef
)
2176 TXNFocus( m_txn
, setActive
);
2179 void wxMacMLTEClassicControl::MacFocusPaneText(Boolean setFocus
)
2181 TXNFocus( m_txn
, setFocus
);
2184 // guards against inappropriate redraw (hidden objects drawing onto window)
2186 void wxMacMLTEClassicControl::MacSetObjectVisibility(Boolean vis
)
2188 ControlRef controlFocus
= 0 ;
2189 GetKeyboardFocus( m_txnWindow
, &controlFocus
) ;
2191 if ( controlFocus
== m_controlRef
&& vis
== false )
2193 SetKeyboardFocus( m_txnWindow
, m_controlRef
, kControlFocusNoPart
) ;
2196 TXNControlTag iControlTags
[1] = { kTXNVisibilityTag
};
2197 TXNControlData iControlData
[1] = { {(UInt32
) false } };
2199 verify_noerr( TXNGetTXNObjectControls( m_txn
, 1,
2200 iControlTags
, iControlData
) ) ;
2202 if ( iControlData
[0].uValue
!= vis
)
2204 iControlData
[0].uValue
= vis
;
2205 verify_noerr( TXNSetTXNObjectControls( m_txn
, false , 1,
2206 iControlTags
, iControlData
)) ;
2208 // we right now are always clipping as partial visibility (overlapped) visibility
2209 // is also a problem, if we run into further problems we might set the FrameBounds to an empty
2213 // make sure that the TXNObject is at the right position
2215 void wxMacMLTEClassicControl::MacUpdatePosition()
2217 wxTextCtrl
* textctrl
= (wxTextCtrl
*) GetControlReference(m_controlRef
);
2218 if ( textctrl
== NULL
)
2222 UMAGetControlBoundsInWindowCoords(m_controlRef
, &bounds
);
2224 wxRect visRect
= textctrl
->MacGetClippedClientRect() ;
2225 Rect visBounds
= { visRect
.y
, visRect
.x
, visRect
.y
+ visRect
.height
, visRect
.x
+ visRect
.width
} ;
2228 textctrl
->MacWindowToRootWindow( &x
, &y
) ;
2229 OffsetRect( &visBounds
, x
, y
) ;
2231 if ( !EqualRect( &bounds
, &m_txnControlBounds
) || !EqualRect( &visBounds
, &m_txnVisBounds
) )
2233 m_txnControlBounds
= bounds
;
2234 m_txnVisBounds
= visBounds
;
2235 wxMacWindowClipper
cl(textctrl
) ;
2237 #ifdef __WXMAC_OSX__
2238 bool isCompositing
= textctrl
->MacGetTopLevelWindow()->MacUsesCompositing() ;
2239 if ( m_sbHorizontal
|| m_sbVertical
)
2241 int w
= bounds
.right
- bounds
.left
;
2242 int h
= bounds
.bottom
- bounds
.top
;
2244 if ( m_sbHorizontal
)
2248 sbBounds
.left
= -1 ;
2249 sbBounds
.top
= h
- 14 ;
2250 sbBounds
.right
= w
+ 1 ;
2251 sbBounds
.bottom
= h
+ 1 ;
2253 if ( !isCompositing
)
2254 OffsetRect( &sbBounds
, m_txnControlBounds
.left
, m_txnControlBounds
.top
) ;
2256 SetControlBounds( m_sbHorizontal
, &sbBounds
) ;
2257 SetControlViewSize( m_sbHorizontal
, w
) ;
2263 sbBounds
.left
= w
- 14 ;
2265 sbBounds
.right
= w
+ 1 ;
2266 sbBounds
.bottom
= m_sbHorizontal
? h
- 14 : h
+ 1 ;
2268 if ( !isCompositing
)
2269 OffsetRect( &sbBounds
, m_txnControlBounds
.left
, m_txnControlBounds
.top
) ;
2271 SetControlBounds( m_sbVertical
, &sbBounds
) ;
2272 SetControlViewSize( m_sbVertical
, h
) ;
2277 TXNLongRect olddestRect
;
2278 TXNGetRectBounds( m_txn
, &oldviewRect
, &olddestRect
, NULL
) ;
2280 Rect viewRect
= { m_txnControlBounds
.top
, m_txnControlBounds
.left
,
2281 m_txnControlBounds
.bottom
- ( m_sbHorizontal
? 14 : 0 ) , m_txnControlBounds
.right
- ( m_sbVertical
? 14 : 0 ) } ;
2282 TXNLongRect destRect
= { m_txnControlBounds
.top
, m_txnControlBounds
.left
,
2283 m_txnControlBounds
.bottom
- ( m_sbHorizontal
? 14 : 0 ) , m_txnControlBounds
.right
- ( m_sbVertical
? 14 : 0 ) } ;
2285 if ( olddestRect
.right
>= 10000 )
2286 destRect
.right
= destRect
.left
+ 32000 ;
2288 if ( olddestRect
.bottom
>= 0x20000000 )
2289 destRect
.bottom
= destRect
.top
+ 0x40000000 ;
2291 SectRect( &viewRect
, &visBounds
, &viewRect
) ;
2292 TXNSetRectBounds( m_txn
, &viewRect
, &destRect
, true ) ;
2294 TXNSetFrameBounds( m_txn, m_txnControlBounds.top, m_txnControlBounds.left,
2295 m_txnControlBounds.bottom - ( m_sbHorizontal ? 14 : 0 ) , m_txnControlBounds.right - ( m_sbVertical ? 14 : 0 ), m_txnFrameID);
2299 TXNSetFrameBounds( m_txn
, m_txnControlBounds
.top
, m_txnControlBounds
.left
,
2300 wxMax( m_txnControlBounds
.bottom
, m_txnControlBounds
.top
) ,
2301 wxMax( m_txnControlBounds
.right
, m_txnControlBounds
.left
) , m_txnFrameID
);
2303 // the SetFrameBounds method unter classic sometimes does not correctly scroll a selection into sight after a
2304 // movement, therefore we have to force it
2306 // according to David Surovell this problem also sometimes occurs under OSX, so we use this as well
2308 TXNLongRect textRect
;
2309 TXNGetRectBounds( m_txn
, NULL
, NULL
, &textRect
) ;
2310 if ( textRect
.left
< m_txnControlBounds
.left
)
2312 TXNShowSelection( m_txn
, false ) ;
2317 void wxMacMLTEClassicControl::SetRect( Rect
*r
)
2319 wxMacControl::SetRect( r
) ;
2320 MacUpdatePosition() ;
2323 void wxMacMLTEClassicControl::MacControlUserPaneDrawProc(wxInt16 thePart
)
2325 wxTextCtrl
* textctrl
= (wxTextCtrl
*) GetControlReference(m_controlRef
);
2326 if ( textctrl
== NULL
)
2329 if ( textctrl
->MacIsReallyShown() )
2331 wxMacWindowClipper
clipper( textctrl
) ;
2332 TXNDraw( m_txn
, NULL
) ;
2336 wxInt16
wxMacMLTEClassicControl::MacControlUserPaneHitTestProc(wxInt16 x
, wxInt16 y
)
2338 Point where
= { y
, x
} ;
2339 ControlPartCode result
;
2342 wxTextCtrl
* textctrl
= (wxTextCtrl
*) GetControlReference(m_controlRef
);
2343 if ( textctrl
== NULL
)
2346 if (textctrl
->MacIsReallyShown() )
2348 if (PtInRect(where
, &m_txnControlBounds
))
2349 result
= kControlEditTextPart
;
2352 // sometimes we get the coords also in control local coordinates, therefore test again
2353 if ( textctrl
->MacGetTopLevelWindow()->MacUsesCompositing() )
2356 textctrl
->MacClientToRootWindow( &x
, &y
) ;
2360 if (PtInRect(where
, &m_txnControlBounds
))
2361 result
= kControlEditTextPart
;
2369 wxInt16
wxMacMLTEClassicControl::MacControlUserPaneTrackingProc( wxInt16 x
, wxInt16 y
, void* actionProc
)
2371 wxTextCtrl
* textctrl
= (wxTextCtrl
*) GetControlReference(m_controlRef
);
2372 if ( textctrl
== NULL
)
2375 ControlPartCode partCodeResult
= 0;
2377 if (textctrl
->MacIsReallyShown() )
2379 Point startPt
= { y
,x
} ;
2380 // for compositing, we must convert these into toplevel window coordinates, because hittesting expects them
2381 if ( textctrl
->MacGetTopLevelWindow()->MacUsesCompositing() )
2384 textctrl
->MacClientToRootWindow( &x
, &y
) ;
2389 switch (MacControlUserPaneHitTestProc( startPt
.h
, startPt
.v
))
2391 case kControlEditTextPart
:
2393 wxMacWindowClipper
clipper( textctrl
) ;
2396 ConvertEventRefToEventRecord( (EventRef
) wxTheApp
->MacGetCurrentEvent() , &rec
) ;
2397 TXNClick( m_txn
, &rec
);
2403 return partCodeResult
;
2406 void wxMacMLTEClassicControl::MacControlUserPaneIdleProc()
2408 wxTextCtrl
* textctrl
= (wxTextCtrl
*) GetControlReference(m_controlRef
);
2409 if ( textctrl
== NULL
)
2412 if (textctrl
->MacIsReallyShown())
2414 if (IsControlActive(m_controlRef
))
2418 wxMacWindowClipper
clipper( textctrl
) ;
2423 if (PtInRect(mousep
, &m_txnControlBounds
))
2426 RectRgn((theRgn
= NewRgn()), &m_txnControlBounds
);
2427 TXNAdjustCursor(m_txn
, theRgn
);
2434 wxInt16
wxMacMLTEClassicControl::MacControlUserPaneKeyDownProc (wxInt16 keyCode
, wxInt16 charCode
, wxInt16 modifiers
)
2436 wxTextCtrl
* textctrl
= (wxTextCtrl
*) GetControlReference(m_controlRef
);
2437 if ( textctrl
== NULL
)
2440 wxMacWindowClipper
clipper( textctrl
) ;
2443 memset( &ev
, 0 , sizeof( ev
) ) ;
2445 ev
.modifiers
= modifiers
;
2446 ev
.message
= (( keyCode
<< 8 ) & keyCodeMask
) + ( charCode
& charCodeMask
) ;
2447 TXNKeyDown( m_txn
, &ev
);
2449 return kControlEntireControl
;
2452 void wxMacMLTEClassicControl::MacControlUserPaneActivateProc( bool activating
)
2454 MacActivatePaneText( activating
);
2457 wxInt16
wxMacMLTEClassicControl::MacControlUserPaneFocusProc(wxInt16 action
)
2459 ControlPartCode focusResult
;
2461 focusResult
= kControlFocusNoPart
;
2462 wxTextCtrl
* textctrl
= (wxTextCtrl
*) GetControlReference(m_controlRef
);
2463 if ( textctrl
== NULL
)
2466 wxMacWindowClipper
clipper( textctrl
) ;
2468 ControlRef controlFocus
= 0 ;
2469 GetKeyboardFocus( m_txnWindow
, &controlFocus
) ;
2470 bool wasFocused
= ( controlFocus
== m_controlRef
) ;
2474 case kControlFocusPrevPart
:
2475 case kControlFocusNextPart
:
2476 MacFocusPaneText( ( !wasFocused
));
2477 focusResult
= (!wasFocused
) ? (ControlPartCode
) kControlEditTextPart
: (ControlPartCode
) kControlFocusNoPart
;
2480 case kControlFocusNoPart
:
2482 MacFocusPaneText( false);
2483 focusResult
= kControlFocusNoPart
;
2490 void wxMacMLTEClassicControl::MacControlUserPaneBackgroundProc( void *info
)
2494 wxMacMLTEClassicControl::wxMacMLTEClassicControl( wxTextCtrl
*wxPeer
,
2495 const wxString
& str
,
2497 const wxSize
& size
, long style
) : wxMacMLTEControl( wxPeer
)
2499 m_font
= wxPeer
->GetFont() ;
2500 m_windowStyle
= style
;
2501 Rect bounds
= wxMacGetBoundsForControl( wxPeer
, pos
, size
) ;
2505 featurSet
= kControlSupportsEmbedding
| kControlSupportsFocus
| kControlWantsIdle
2506 | kControlWantsActivate
| kControlHandlesTracking
// | kControlHasSpecialBackground
2507 | kControlGetsFocusOnClick
| kControlSupportsLiveFeedback
;
2509 verify_noerr( ::CreateUserPaneControl( MAC_WXHWND(wxPeer
->GetParent()->MacGetTopLevelWindowRef()), &bounds
, featurSet
, &m_controlRef
) );
2513 AdjustCreationAttributes( *wxWHITE
, true) ;
2515 MacSetObjectVisibility( wxPeer
->MacIsReallyShown() ) ;
2519 wxMacConvertNewlines10To13( &st
) ;
2520 wxMacWindowClipper
clipper( m_peer
) ;
2521 SetTXNData( st
, kTXNStartOffset
, kTXNEndOffset
) ;
2522 TXNSetSelection( m_txn
, 0, 0);
2526 wxMacMLTEClassicControl::~wxMacMLTEClassicControl()
2528 TXNDeleteObject(m_txn
);
2532 void wxMacMLTEClassicControl::VisibilityChanged(bool shown
)
2534 MacSetObjectVisibility( shown
) ;
2535 wxMacControl::VisibilityChanged( shown
) ;
2538 void wxMacMLTEClassicControl::SuperChangedPosition()
2540 MacUpdatePosition() ;
2541 wxMacControl::SuperChangedPosition() ;
2544 #ifdef __WXMAC_OSX__
2546 ControlUserPaneDrawUPP gTPDrawProc
= NULL
;
2547 ControlUserPaneHitTestUPP gTPHitProc
= NULL
;
2548 ControlUserPaneTrackingUPP gTPTrackProc
= NULL
;
2549 ControlUserPaneIdleUPP gTPIdleProc
= NULL
;
2550 ControlUserPaneKeyDownUPP gTPKeyProc
= NULL
;
2551 ControlUserPaneActivateUPP gTPActivateProc
= NULL
;
2552 ControlUserPaneFocusUPP gTPFocusProc
= NULL
;
2554 static pascal void wxMacControlUserPaneDrawProc(ControlRef control
, SInt16 part
)
2556 wxTextCtrl
*textCtrl
= wxDynamicCast( wxFindControlFromMacControl(control
) , wxTextCtrl
) ;
2557 wxMacMLTEClassicControl
* win
= textCtrl
? (wxMacMLTEClassicControl
*)(textCtrl
->GetPeer()) : NULL
;
2559 win
->MacControlUserPaneDrawProc(part
) ;
2562 static pascal ControlPartCode
wxMacControlUserPaneHitTestProc(ControlRef control
, Point where
)
2564 wxTextCtrl
*textCtrl
= wxDynamicCast( wxFindControlFromMacControl(control
) , wxTextCtrl
) ;
2565 wxMacMLTEClassicControl
* win
= textCtrl
? (wxMacMLTEClassicControl
*)(textCtrl
->GetPeer()) : NULL
;
2567 return win
->MacControlUserPaneHitTestProc(where
.h
, where
.v
) ;
2569 return kControlNoPart
;
2572 static pascal ControlPartCode
wxMacControlUserPaneTrackingProc(ControlRef control
, Point startPt
, ControlActionUPP actionProc
)
2574 wxTextCtrl
*textCtrl
= wxDynamicCast( wxFindControlFromMacControl(control
) , wxTextCtrl
) ;
2575 wxMacMLTEClassicControl
* win
= textCtrl
? (wxMacMLTEClassicControl
*)(textCtrl
->GetPeer()) : NULL
;
2577 return win
->MacControlUserPaneTrackingProc( startPt
.h
, startPt
.v
, (void*) actionProc
) ;
2579 return kControlNoPart
;
2582 static pascal void wxMacControlUserPaneIdleProc(ControlRef control
)
2584 wxTextCtrl
*textCtrl
= wxDynamicCast( wxFindControlFromMacControl(control
) , wxTextCtrl
) ;
2585 wxMacMLTEClassicControl
* win
= textCtrl
? (wxMacMLTEClassicControl
*)(textCtrl
->GetPeer()) : NULL
;
2587 win
->MacControlUserPaneIdleProc() ;
2590 static pascal ControlPartCode
wxMacControlUserPaneKeyDownProc(ControlRef control
, SInt16 keyCode
, SInt16 charCode
, SInt16 modifiers
)
2592 wxTextCtrl
*textCtrl
= wxDynamicCast( wxFindControlFromMacControl(control
) , wxTextCtrl
) ;
2593 wxMacMLTEClassicControl
* win
= textCtrl
? (wxMacMLTEClassicControl
*)(textCtrl
->GetPeer()) : NULL
;
2595 return win
->MacControlUserPaneKeyDownProc(keyCode
,charCode
,modifiers
) ;
2597 return kControlNoPart
;
2600 static pascal void wxMacControlUserPaneActivateProc(ControlRef control
, Boolean activating
)
2602 wxTextCtrl
*textCtrl
= wxDynamicCast( wxFindControlFromMacControl(control
) , wxTextCtrl
) ;
2603 wxMacMLTEClassicControl
* win
= textCtrl
? (wxMacMLTEClassicControl
*)(textCtrl
->GetPeer()) : NULL
;
2605 win
->MacControlUserPaneActivateProc(activating
) ;
2608 static pascal ControlPartCode
wxMacControlUserPaneFocusProc(ControlRef control
, ControlFocusPart action
)
2610 wxTextCtrl
*textCtrl
= wxDynamicCast( wxFindControlFromMacControl(control
) , wxTextCtrl
) ;
2611 wxMacMLTEClassicControl
* win
= textCtrl
? (wxMacMLTEClassicControl
*)(textCtrl
->GetPeer()) : NULL
;
2613 return win
->MacControlUserPaneFocusProc(action
) ;
2615 return kControlNoPart
;
2619 static pascal void wxMacControlUserPaneBackgroundProc(ControlRef control, ControlBackgroundPtr info)
2621 wxTextCtrl *textCtrl = wxDynamicCast( wxFindControlFromMacControl(control) , wxTextCtrl ) ;
2622 wxMacMLTEClassicControl * win = textCtrl ? (wxMacMLTEClassicControl*)(textCtrl->GetPeer()) : NULL ;
2624 win->MacControlUserPaneBackgroundProc(info) ;
2629 // TXNRegisterScrollInfoProc
2631 OSStatus
wxMacMLTEClassicControl::DoCreate()
2635 OSStatus err
= noErr
;
2637 /* set up our globals */
2638 #ifdef __WXMAC_OSX__
2639 if (gTPDrawProc
== NULL
) gTPDrawProc
= NewControlUserPaneDrawUPP(wxMacControlUserPaneDrawProc
);
2640 if (gTPHitProc
== NULL
) gTPHitProc
= NewControlUserPaneHitTestUPP(wxMacControlUserPaneHitTestProc
);
2641 if (gTPTrackProc
== NULL
) gTPTrackProc
= NewControlUserPaneTrackingUPP(wxMacControlUserPaneTrackingProc
);
2642 if (gTPIdleProc
== NULL
) gTPIdleProc
= NewControlUserPaneIdleUPP(wxMacControlUserPaneIdleProc
);
2643 if (gTPKeyProc
== NULL
) gTPKeyProc
= NewControlUserPaneKeyDownUPP(wxMacControlUserPaneKeyDownProc
);
2644 if (gTPActivateProc
== NULL
) gTPActivateProc
= NewControlUserPaneActivateUPP(wxMacControlUserPaneActivateProc
);
2645 if (gTPFocusProc
== NULL
) gTPFocusProc
= NewControlUserPaneFocusUPP(wxMacControlUserPaneFocusProc
);
2647 if (gTXNScrollInfoProc
== NULL
) gTXNScrollInfoProc
= NewTXNScrollInfoUPP(TXNScrollInfoProc
) ;
2648 if (gTXNScrollActionProc
== NULL
) gTXNScrollActionProc
= NewControlActionUPP(TXNScrollActionProc
) ;
2651 /* set the initial settings for our private data */
2653 m_txnWindow
=GetControlOwner(m_controlRef
);
2654 m_txnPort
= (GrafPtr
) GetWindowPort(m_txnWindow
);
2656 #ifdef __WXMAC_OSX__
2657 /* set up the user pane procedures */
2658 SetControlData(m_controlRef
, kControlEntireControl
, kControlUserPaneDrawProcTag
, sizeof(gTPDrawProc
), &gTPDrawProc
);
2659 SetControlData(m_controlRef
, kControlEntireControl
, kControlUserPaneHitTestProcTag
, sizeof(gTPHitProc
), &gTPHitProc
);
2660 SetControlData(m_controlRef
, kControlEntireControl
, kControlUserPaneTrackingProcTag
, sizeof(gTPTrackProc
), &gTPTrackProc
);
2661 SetControlData(m_controlRef
, kControlEntireControl
, kControlUserPaneIdleProcTag
, sizeof(gTPIdleProc
), &gTPIdleProc
);
2662 SetControlData(m_controlRef
, kControlEntireControl
, kControlUserPaneKeyDownProcTag
, sizeof(gTPKeyProc
), &gTPKeyProc
);
2663 SetControlData(m_controlRef
, kControlEntireControl
, kControlUserPaneActivateProcTag
, sizeof(gTPActivateProc
), &gTPActivateProc
);
2664 SetControlData(m_controlRef
, kControlEntireControl
, kControlUserPaneFocusProcTag
, sizeof(gTPFocusProc
), &gTPFocusProc
);
2666 /* calculate the rectangles used by the control */
2667 UMAGetControlBoundsInWindowCoords(m_controlRef
, &bounds
);
2669 m_txnControlBounds
= bounds
;
2670 m_txnVisBounds
= bounds
;
2672 CGrafPtr origPort
= NULL
;
2673 GDHandle origDev
= NULL
;
2674 GetGWorld( &origPort
, &origDev
) ;
2677 /* create the new edit field */
2679 TXNFrameOptions frameOptions
= FrameOptionsFromWXStyle( m_windowStyle
) ;
2681 #ifdef __WXMAC_OSX__
2683 // the scrollbars are not correctly embedded but are inserted at the root
2684 // this gives us problems as we have erratic redraws even over the structure
2687 m_sbHorizontal
= 0 ;
2689 m_lastHorizontalValue
= 0 ;
2690 m_lastVerticalValue
= 0 ;
2692 Rect sb
= { 0 , 0 , 0 , 0 } ;
2693 if ( frameOptions
& kTXNWantVScrollBarMask
)
2695 CreateScrollBarControl( m_txnWindow
, &sb
, 0 , 0 , 100 , 1 , true , gTXNScrollActionProc
, &m_sbVertical
) ;
2696 SetControlReference( m_sbVertical
, (SInt32
) this ) ;
2697 SetControlAction( m_sbVertical
, gTXNScrollActionProc
);
2698 ShowControl( m_sbVertical
) ;
2699 EmbedControl( m_sbVertical
, m_controlRef
) ;
2700 frameOptions
&= ~kTXNWantVScrollBarMask
;
2702 if ( frameOptions
& kTXNWantHScrollBarMask
)
2704 CreateScrollBarControl( m_txnWindow
, &sb
, 0 , 0 , 100 , 1 , true , gTXNScrollActionProc
, &m_sbHorizontal
) ;
2705 SetControlReference( m_sbHorizontal
, (SInt32
) this ) ;
2706 SetControlAction( m_sbHorizontal
, gTXNScrollActionProc
);
2707 ShowControl( m_sbHorizontal
) ;
2708 EmbedControl( m_sbHorizontal
, m_controlRef
) ;
2709 frameOptions
&= ~(kTXNWantHScrollBarMask
| kTXNDrawGrowIconMask
);
2714 verify_noerr(TXNNewObject(NULL
, m_txnWindow
, &bounds
,
2716 kTXNTextEditStyleFrameType
,
2718 kTXNSystemDefaultEncoding
,
2719 &m_txn
, &m_txnFrameID
, NULL
) );
2721 TXNCarbonEventInfo cInfo ;
2723 cInfo.useCarbonEvents = false ;
2726 cInfo.fDictionary = NULL ;
2728 TXNControlTag iControlTags[] =
2730 kTXNUseCarbonEvents ,
2732 TXNControlData iControlData[] =
2737 int toptag = WXSIZEOF( iControlTags ) ;
2739 verify_noerr( TXNSetTXNObjectControls( m_txn, false , toptag,
2740 iControlTags, iControlData )) ;
2743 #ifdef __WXMAC_OSX__
2744 TXNRegisterScrollInfoProc( m_txn
, gTXNScrollInfoProc
, (SInt32
) this);
2747 SetGWorld( origPort
, origDev
) ;
2751 // ----------------------------------------------------------------------------
2752 // MLTE control implementation (OSX part)
2753 // ----------------------------------------------------------------------------
2755 #if TARGET_API_MAC_OSX
2757 #if MAC_OS_X_VERSION_MAX_ALLOWED > MAC_OS_X_VERSION_10_2
2759 wxMacMLTEHIViewControl::wxMacMLTEHIViewControl( wxTextCtrl
*wxPeer
,
2760 const wxString
& str
,
2762 const wxSize
& size
, long style
) : wxMacMLTEControl( wxPeer
)
2764 m_font
= wxPeer
->GetFont() ;
2765 m_windowStyle
= style
;
2766 Rect bounds
= wxMacGetBoundsForControl( wxPeer
, pos
, size
) ;
2768 wxMacConvertNewlines10To13( &st
) ;
2770 HIRect hr
= { bounds
.left
, bounds
.top
, bounds
.right
- bounds
.left
, bounds
.bottom
- bounds
.top
} ;
2772 m_scrollView
= NULL
;
2773 TXNFrameOptions frameOptions
= FrameOptionsFromWXStyle( style
) ;
2774 if ( frameOptions
& (kTXNWantVScrollBarMask
|kTXNWantHScrollBarMask
) )
2776 HIScrollViewCreate(( frameOptions
& kTXNWantHScrollBarMask
? kHIScrollViewOptionsHorizScroll
: 0) |
2777 ( frameOptions
& kTXNWantVScrollBarMask
? kHIScrollViewOptionsVertScroll
: 0 ) , &m_scrollView
) ;
2779 HIViewSetFrame( m_scrollView
, &hr
);
2780 HIViewSetVisible( m_scrollView
, true );
2784 HITextViewCreate( NULL
, 0, frameOptions
, &m_textView
) ;
2785 m_txn
= HITextViewGetTXNObject( m_textView
) ;
2786 HIViewSetVisible( m_textView
, true ) ;
2789 HIViewAddSubview( m_scrollView
, m_textView
) ;
2790 m_controlRef
= m_scrollView
;
2791 wxPeer
->MacInstallEventHandler( (WXWidget
) m_textView
) ;
2795 HIViewSetFrame( m_textView
, &hr
);
2796 m_controlRef
= m_textView
;
2799 AdjustCreationAttributes( *wxWHITE
, true ) ;
2801 wxMacWindowClipper
c( m_peer
) ;
2802 SetTXNData( st
, kTXNStartOffset
, kTXNEndOffset
) ;
2804 TXNSetSelection( m_txn
, 0, 0);
2805 TXNShowSelection( m_txn
, kTXNShowStart
);
2809 OSStatus
wxMacMLTEHIViewControl::SetFocus( ControlFocusPart focusPart
)
2811 return SetKeyboardFocus( GetControlOwner( m_textView
) ,
2812 m_textView
, focusPart
) ;
2815 bool wxMacMLTEHIViewControl::HasFocus() const
2817 ControlRef control
;
2818 GetKeyboardFocus( GetUserFocusWindow() , &control
) ;
2819 return control
== m_textView
;
2822 #endif // MAC_OS_X_VERSION_MAX_ALLOWED > MAC_OS_X_VERSION_10_2
2827 #endif // wxUSE_TEXTCTRL