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 IMPLEMENT_DYNAMIC_CLASS(wxTextCtrl
, wxControl
)
366 BEGIN_EVENT_TABLE(wxTextCtrl
, wxControl
)
367 EVT_ERASE_BACKGROUND( wxTextCtrl::OnEraseBackground
)
368 EVT_DROP_FILES(wxTextCtrl::OnDropFiles
)
369 EVT_CHAR(wxTextCtrl::OnChar
)
370 EVT_MENU(wxID_CUT
, wxTextCtrl::OnCut
)
371 EVT_MENU(wxID_COPY
, wxTextCtrl::OnCopy
)
372 EVT_MENU(wxID_PASTE
, wxTextCtrl::OnPaste
)
373 EVT_MENU(wxID_UNDO
, wxTextCtrl::OnUndo
)
374 EVT_MENU(wxID_REDO
, wxTextCtrl::OnRedo
)
376 EVT_UPDATE_UI(wxID_CUT
, wxTextCtrl::OnUpdateCut
)
377 EVT_UPDATE_UI(wxID_COPY
, wxTextCtrl::OnUpdateCopy
)
378 EVT_UPDATE_UI(wxID_PASTE
, wxTextCtrl::OnUpdatePaste
)
379 EVT_UPDATE_UI(wxID_UNDO
, wxTextCtrl::OnUpdateUndo
)
380 EVT_UPDATE_UI(wxID_REDO
, wxTextCtrl::OnUpdateRedo
)
384 void wxTextCtrl::Init()
389 m_maxLength
= TE_UNLIMITED_LENGTH
;
392 wxTextCtrl::~wxTextCtrl()
397 bool wxTextCtrl::Create(wxWindow
*parent
, wxWindowID id
,
400 const wxSize
& size
, long style
,
401 const wxValidator
& validator
,
402 const wxString
& name
)
404 m_macIsUserPane
= false ;
407 if ( ! ( style
& wxNO_BORDER
) )
408 style
= ( style
& ~wxBORDER_MASK
) | wxSUNKEN_BORDER
;
410 if ( !wxTextCtrlBase::Create(parent
, id
, pos
, size
, style
& ~(wxHSCROLL
|wxVSCROLL
), validator
, name
) )
413 if ( m_windowStyle
& wxTE_MULTILINE
)
415 wxASSERT_MSG( !(m_windowStyle
& wxTE_PROCESS_ENTER
),
416 wxT("wxTE_PROCESS_ENTER style is ignored for multiline text controls (they always process it)") );
418 m_windowStyle
|= wxTE_PROCESS_ENTER
;
419 style
|= wxTE_PROCESS_ENTER
;
422 bool forceMLTE
= false ;
423 #if wxUSE_SYSTEM_OPTIONS
424 if ( (wxSystemOptions::HasOption(wxMAC_TEXTCONTROL_USE_MLTE
) ) && ( wxSystemOptions::GetOptionInt( wxMAC_TEXTCONTROL_USE_MLTE
) == 1) )
431 #if MAC_OS_X_VERSION_MAX_ALLOWED > MAC_OS_X_VERSION_10_2
432 if ( UMAGetSystemVersion() >= 0x1030 && forceMLTE
== false )
434 if ( m_windowStyle
& wxTE_MULTILINE
)
435 m_peer
= new wxMacMLTEHIViewControl( this , str
, pos
, size
, style
) ;
440 if ( !(m_windowStyle
& wxTE_MULTILINE
) && forceMLTE
== false )
441 m_peer
= new wxMacUnicodeTextControl( this , str
, pos
, size
, style
) ;
446 m_peer
= new wxMacMLTEClassicControl( this , str
, pos
, size
, style
) ;
449 MacPostControlCreate(pos
,size
) ;
451 // only now the embedding is correct and we can do a positioning update
453 MacSuperChangedPosition() ;
455 if ( m_windowStyle
& wxTE_READONLY
)
457 SetEditable( false ) ;
460 SetCursor( wxCursor( wxCURSOR_IBEAM
) ) ;
465 void wxTextCtrl::MacSuperChangedPosition()
467 wxWindow::MacSuperChangedPosition() ;
468 GetPeer()->SuperChangedPosition() ;
471 void wxTextCtrl::MacVisibilityChanged()
473 GetPeer()->VisibilityChanged( MacIsReallyShown() ) ;
476 void wxTextCtrl::MacEnabledStateChanged()
480 wxString
wxTextCtrl::GetValue() const
482 return GetPeer()->GetStringValue() ;
485 void wxTextCtrl::GetSelection(long* from
, long* to
) const
487 GetPeer()->GetSelection( from
, to
) ;
490 void wxTextCtrl::SetValue(const wxString
& str
)
493 if ( GetValue() == str
)
496 GetPeer()->SetStringValue(str
) ;
498 wxCommandEvent
event(wxEVT_COMMAND_TEXT_UPDATED
, m_windowId
);
499 event
.SetString( GetValue() ) ;
500 event
.SetEventObject( this );
501 GetEventHandler()->ProcessEvent(event
);
504 void wxTextCtrl::SetMaxLength(unsigned long len
)
509 bool wxTextCtrl::SetFont( const wxFont
& font
)
511 if ( !wxTextCtrlBase::SetFont( font
) )
514 GetPeer()->SetFont( font
, GetForegroundColour() , GetWindowStyle() ) ;
518 bool wxTextCtrl::SetStyle(long start
, long end
, const wxTextAttr
& style
)
520 GetPeer()->SetStyle( start
, end
, style
) ;
524 bool wxTextCtrl::SetDefaultStyle(const wxTextAttr
& style
)
526 wxTextCtrlBase::SetDefaultStyle( style
) ;
527 SetStyle( kTXNUseCurrentSelection
, kTXNUseCurrentSelection
, GetDefaultStyle() ) ;
531 // Clipboard operations
532 void wxTextCtrl::Copy()
540 void wxTextCtrl::Cut()
546 wxCommandEvent
event(wxEVT_COMMAND_TEXT_UPDATED
, m_windowId
);
547 event
.SetEventObject( this );
548 GetEventHandler()->ProcessEvent(event
);
552 void wxTextCtrl::Paste()
557 // eventually we should add setting the default style again
559 wxCommandEvent
event(wxEVT_COMMAND_TEXT_UPDATED
, m_windowId
);
560 event
.SetEventObject( this );
561 GetEventHandler()->ProcessEvent(event
);
565 bool wxTextCtrl::CanCopy() const
567 // Can copy if there's a selection
569 GetSelection(& from
, & to
);
573 bool wxTextCtrl::CanCut() const
579 // Can cut if there's a selection
581 GetSelection(& from
, & to
);
585 bool wxTextCtrl::CanPaste() const
590 return GetPeer()->CanPaste() ;
593 void wxTextCtrl::SetEditable(bool editable
)
595 if ( editable
!= m_editable
)
597 m_editable
= editable
;
598 GetPeer()->SetEditable( editable
) ;
602 void wxTextCtrl::SetInsertionPoint(long pos
)
604 SetSelection( pos
, pos
) ;
607 void wxTextCtrl::SetInsertionPointEnd()
609 wxTextPos pos
= GetLastPosition();
610 SetInsertionPoint(pos
);
613 long wxTextCtrl::GetInsertionPoint() const
616 GetSelection( &begin
, &end
) ;
620 wxTextPos
wxTextCtrl::GetLastPosition() const
622 return GetPeer()->GetLastPosition( ) ;
625 void wxTextCtrl::Replace(long from
, long to
, const wxString
& str
)
627 GetPeer()->Replace( from
, to
, str
) ;
630 void wxTextCtrl::Remove(long from
, long to
)
632 GetPeer()->Remove( from
, to
) ;
635 void wxTextCtrl::SetSelection(long from
, long to
)
637 GetPeer()->SetSelection( from
, to
) ;
640 bool wxTextCtrl::LoadFile(const wxString
& file
)
642 if ( wxTextCtrlBase::LoadFile(file
) )
650 void wxTextCtrl::WriteText(const wxString
& str
)
652 // TODO this MPRemoting will be moved into a remoting peer proxy for any command
653 if ( !wxIsMainThread() )
655 // unfortunately CW 8 is not able to correctly deduce the template types, so we have
656 // to instantiate explicitly
657 wxMacMPRemoteGUICall
<wxTextCtrl
,wxString
>( this , &wxTextCtrl::WriteText
, str
) ;
662 GetPeer()->WriteText( str
) ;
666 void wxTextCtrl::AppendText(const wxString
& text
)
668 SetInsertionPointEnd();
672 void wxTextCtrl::Clear()
677 bool wxTextCtrl::IsModified() const
682 bool wxTextCtrl::IsEditable() const
684 return IsEnabled() && m_editable
;
687 bool wxTextCtrl::AcceptsFocus() const
689 // we don't want focus if we can't be edited
690 return /*IsEditable() && */ wxControl::AcceptsFocus();
693 wxSize
wxTextCtrl::DoGetBestSize() const
699 // these are the numbers from the HIG, we reduce them by the borders
702 switch( m_windowVariant
)
704 case wxWINDOW_VARIANT_NORMAL
:
707 case wxWINDOW_VARIANT_SMALL
:
710 case wxWINDOW_VARIANT_MINI
:
718 // as the above numbers have some free space around the text
719 // we get 5 lines like this anyway
720 if ( m_windowStyle
& wxTE_MULTILINE
)
725 if ( !HasFlag(wxNO_BORDER
) )
728 return wxSize(wText
, hText
);
731 // ----------------------------------------------------------------------------
733 // ----------------------------------------------------------------------------
735 void wxTextCtrl::Undo()
743 void wxTextCtrl::Redo()
751 bool wxTextCtrl::CanUndo() const
757 return GetPeer()->CanUndo() ;
760 bool wxTextCtrl::CanRedo() const
766 return GetPeer()->CanRedo() ;
769 void wxTextCtrl::MarkDirty()
774 void wxTextCtrl::DiscardEdits()
779 int wxTextCtrl::GetNumberOfLines() const
781 return GetPeer()->GetNumberOfLines() ;
784 long wxTextCtrl::XYToPosition(long x
, long y
) const
786 return GetPeer()->XYToPosition( x
, y
) ;
789 bool wxTextCtrl::PositionToXY(long pos
, long *x
, long *y
) const
791 return GetPeer()->PositionToXY(pos
, x
, y
) ;
794 void wxTextCtrl::ShowPosition(long pos
)
796 return GetPeer()->ShowPosition(pos
) ;
799 int wxTextCtrl::GetLineLength(long lineNo
) const
801 return GetPeer()->GetLineLength(lineNo
) ;
804 wxString
wxTextCtrl::GetLineText(long lineNo
) const
806 return GetPeer()->GetLineText(lineNo
) ;
813 void wxTextCtrl::Command(wxCommandEvent
& event
)
815 SetValue (event
.GetString());
816 ProcessCommand (event
);
819 void wxTextCtrl::OnDropFiles(wxDropFilesEvent
& event
)
821 // By default, load the first file into the text window.
822 if (event
.GetNumberOfFiles() > 0)
824 LoadFile(event
.GetFiles()[0]);
828 void wxTextCtrl::OnEraseBackground(wxEraseEvent
& event
)
830 // all erasing should be done by the real mac control implementation
831 // while this is true for MLTE under classic, the HITextView is somehow
832 // transparent but background erase is not working correctly, so intercept
833 // things while we can...
837 void wxTextCtrl::OnChar(wxKeyEvent
& event
)
839 int key
= event
.GetKeyCode() ;
840 bool eat_key
= false ;
842 if ( key
== 'c' && event
.MetaDown() )
849 if ( !IsEditable() && key
!= WXK_LEFT
&& key
!= WXK_RIGHT
&& key
!= WXK_DOWN
&& key
!= WXK_UP
&& key
!= WXK_TAB
&&
850 !( key
== WXK_RETURN
&& ( (m_windowStyle
& wxPROCESS_ENTER
) || (m_windowStyle
& wxTE_MULTILINE
) ) )
851 /* && key != WXK_PRIOR && key != WXK_NEXT && key != WXK_HOME && key != WXK_END */
858 // Check if we have reached the max # of chars, but still allow navigation and deletion
859 if ( !IsMultiLine() && GetValue().Length() >= m_maxLength
&&
860 key
!= WXK_LEFT
&& key
!= WXK_RIGHT
&& key
!= WXK_TAB
&&
861 key
!= WXK_BACK
&& !( key
== WXK_RETURN
&& (m_windowStyle
& wxPROCESS_ENTER
) )
864 // eat it, we don't want to add more than allowed # of characters
868 // assume that any key not processed yet is going to modify the control
871 if ( key
== 'v' && event
.MetaDown() )
877 if ( key
== 'x' && event
.MetaDown() )
886 if (m_windowStyle
& wxPROCESS_ENTER
)
888 wxCommandEvent
event(wxEVT_COMMAND_TEXT_ENTER
, m_windowId
);
889 event
.SetEventObject( this );
890 event
.SetString( GetValue() );
891 if ( GetEventHandler()->ProcessEvent(event
) )
894 if ( !(m_windowStyle
& wxTE_MULTILINE
) )
896 wxWindow
*parent
= GetParent();
897 while( parent
&& !parent
->IsTopLevel() && parent
->GetDefaultItem() == NULL
) {
898 parent
= parent
->GetParent() ;
900 if ( parent
&& parent
->GetDefaultItem() )
902 wxButton
*def
= wxDynamicCast(parent
->GetDefaultItem(),
904 if ( def
&& def
->IsEnabled() )
906 wxCommandEvent
event(wxEVT_COMMAND_BUTTON_CLICKED
, def
->GetId() );
907 event
.SetEventObject(def
);
913 // this will make wxWidgets eat the ENTER key so that
914 // we actually prevent line wrapping in a single line
922 if ( !(m_windowStyle
& wxTE_PROCESS_TAB
))
925 if (!event
.ShiftDown())
926 flags
|= wxNavigationKeyEvent::IsForward
;
927 if (event
.ControlDown())
928 flags
|= wxNavigationKeyEvent::WinChange
;
934 // This is necessary (don't know why) or the tab will not
936 WriteText(wxT("\t"));
944 // perform keystroke handling
945 if ( wxTheApp
->MacGetCurrentEvent() != NULL
&& wxTheApp
->MacGetCurrentEventHandlerCallRef() != NULL
)
946 CallNextEventHandler((EventHandlerCallRef
)wxTheApp
->MacGetCurrentEventHandlerCallRef() , (EventRef
) wxTheApp
->MacGetCurrentEvent() ) ;
950 if ( wxMacConvertEventToRecord( (EventRef
) wxTheApp
->MacGetCurrentEvent() , &rec
) )
952 EventRecord
*ev
= &rec
;
955 keychar
= short(ev
->message
& charCodeMask
);
956 keycode
= short(ev
->message
& keyCodeMask
) >> 8 ;
958 m_peer
->HandleKey( keycode
, keychar
, ev
->modifiers
) ;
962 if ( ( key
>= 0x20 && key
< WXK_START
) ||
967 wxCommandEvent
event1(wxEVT_COMMAND_TEXT_UPDATED
, m_windowId
);
968 event1
.SetEventObject( this );
969 wxPostEvent(GetEventHandler(),event1
);
973 // ----------------------------------------------------------------------------
974 // standard handlers for standard edit menu events
975 // ----------------------------------------------------------------------------
977 void wxTextCtrl::OnCut(wxCommandEvent
& WXUNUSED(event
))
982 void wxTextCtrl::OnCopy(wxCommandEvent
& WXUNUSED(event
))
987 void wxTextCtrl::OnPaste(wxCommandEvent
& WXUNUSED(event
))
992 void wxTextCtrl::OnUndo(wxCommandEvent
& WXUNUSED(event
))
997 void wxTextCtrl::OnRedo(wxCommandEvent
& WXUNUSED(event
))
1002 void wxTextCtrl::OnUpdateCut(wxUpdateUIEvent
& event
)
1004 event
.Enable( CanCut() );
1007 void wxTextCtrl::OnUpdateCopy(wxUpdateUIEvent
& event
)
1009 event
.Enable( CanCopy() );
1012 void wxTextCtrl::OnUpdatePaste(wxUpdateUIEvent
& event
)
1014 event
.Enable( CanPaste() );
1017 void wxTextCtrl::OnUpdateUndo(wxUpdateUIEvent
& event
)
1019 event
.Enable( CanUndo() );
1022 void wxTextCtrl::OnUpdateRedo(wxUpdateUIEvent
& event
)
1024 event
.Enable( CanRedo() );
1027 bool wxTextCtrl::MacSetupCursor( const wxPoint
& pt
)
1029 if ( !GetPeer()->SetupCursor(pt
) )
1030 return wxWindow::MacSetupCursor( pt
) ;
1034 #if !TARGET_API_MAC_OSX
1036 // user pane implementation
1038 void wxTextCtrl::MacControlUserPaneDrawProc(wxInt16 part
)
1040 GetPeer()->MacControlUserPaneDrawProc( part
) ;
1043 wxInt16
wxTextCtrl::MacControlUserPaneHitTestProc(wxInt16 x
, wxInt16 y
)
1045 return GetPeer()->MacControlUserPaneHitTestProc( x
, y
) ;
1048 wxInt16
wxTextCtrl::MacControlUserPaneTrackingProc(wxInt16 x
, wxInt16 y
, void* actionProc
)
1050 return GetPeer()->MacControlUserPaneTrackingProc( x
, y
, actionProc
) ;
1053 void wxTextCtrl::MacControlUserPaneIdleProc()
1055 GetPeer()->MacControlUserPaneIdleProc( ) ;
1058 wxInt16
wxTextCtrl::MacControlUserPaneKeyDownProc(wxInt16 keyCode
, wxInt16 charCode
, wxInt16 modifiers
)
1060 return GetPeer()->MacControlUserPaneKeyDownProc( keyCode
, charCode
, modifiers
) ;
1063 void wxTextCtrl::MacControlUserPaneActivateProc(bool activating
)
1065 GetPeer()->MacControlUserPaneActivateProc( activating
) ;
1068 wxInt16
wxTextCtrl::MacControlUserPaneFocusProc(wxInt16 action
)
1070 return GetPeer()->MacControlUserPaneFocusProc( action
) ;
1073 void wxTextCtrl::MacControlUserPaneBackgroundProc(void* info
)
1075 GetPeer()->MacControlUserPaneBackgroundProc( info
) ;
1079 // ----------------------------------------------------------------------------
1080 // implementation base class
1081 // ----------------------------------------------------------------------------
1083 wxMacTextControl::wxMacTextControl(wxTextCtrl
* peer
) :
1084 wxMacControl( peer
)
1088 wxMacTextControl::~wxMacTextControl()
1092 void wxMacTextControl::SetStyle(long start
, long end
, const wxTextAttr
& style
)
1096 void wxMacTextControl::Copy()
1100 void wxMacTextControl::Cut()
1104 void wxMacTextControl::Paste()
1108 bool wxMacTextControl::CanPaste() const
1113 void wxMacTextControl::SetEditable(bool editable
)
1117 wxTextPos
wxMacTextControl::GetLastPosition() const
1119 return GetStringValue().Length() ;
1122 void wxMacTextControl::Replace( long from
, long to
, const wxString str
)
1126 void wxMacTextControl::Clear()
1128 SetStringValue( wxEmptyString
) ;
1131 bool wxMacTextControl::CanUndo() const
1136 void wxMacTextControl::Undo() { }
1138 bool wxMacTextControl::CanRedo() const
1143 void wxMacTextControl::Redo()
1147 long wxMacTextControl::XYToPosition(long x
, long y
) const
1152 bool wxMacTextControl::PositionToXY(long pos
, long *x
, long *y
) const
1157 void wxMacTextControl::ShowPosition( long WXUNUSED(pos
) )
1161 int wxMacTextControl::GetNumberOfLines() const
1163 ItemCount lines
= 0 ;
1164 wxString content
= GetStringValue() ;
1166 for (size_t i
= 0; i
< content
.Length() ; i
++)
1168 if (content
[i
] == '\r') lines
++;
1173 wxString
wxMacTextControl::GetLineText(long lineNo
) const
1175 // TODO change this if possible to reflect real lines
1176 wxString content
= GetStringValue() ;
1180 for (size_t i
= 0; i
< content
.Length() ; i
++)
1182 if (count
== lineNo
)
1184 // Add chars in line then
1187 for (size_t j
= i
; j
< content
.Length(); j
++)
1189 if (content
[j
] == '\n')
1197 if (content
[i
] == '\n') count
++;
1199 return wxEmptyString
;
1202 int wxMacTextControl::GetLineLength(long lineNo
) const
1204 // TODO change this if possible to reflect real lines
1205 wxString content
= GetStringValue() ;
1209 for (size_t i
= 0; i
< content
.Length() ; i
++)
1211 if (count
== lineNo
)
1213 // Count chars in line then
1215 for (size_t j
= i
; j
< content
.Length(); j
++)
1218 if (content
[j
] == '\n') return count
;
1223 if (content
[i
] == '\n') count
++;
1228 // ----------------------------------------------------------------------------
1229 // standard unicode control implementation
1230 // ----------------------------------------------------------------------------
1232 #if TARGET_API_MAC_OSX
1234 wxMacUnicodeTextControl::wxMacUnicodeTextControl( wxTextCtrl
*wxPeer
,
1235 const wxString
& str
,
1237 const wxSize
& size
, long style
) : wxMacTextControl( wxPeer
)
1239 m_font
= wxPeer
->GetFont() ;
1240 m_windowStyle
= style
;
1241 Rect bounds
= wxMacGetBoundsForControl( wxPeer
, pos
, size
) ;
1243 wxMacConvertNewlines10To13( &st
) ;
1244 wxMacCFStringHolder
cf(st
, m_font
.GetEncoding()) ;
1245 CFStringRef cfr
= cf
;
1246 Boolean isPassword
= ( m_windowStyle
& wxTE_PASSWORD
) != 0 ;
1247 m_valueTag
= isPassword
? kControlEditTextPasswordCFStringTag
: kControlEditTextCFStringTag
;
1248 CreateEditUnicodeTextControl( MAC_WXHWND(wxPeer
->MacGetTopLevelWindowRef()), &bounds
, cfr
, isPassword
, NULL
, &m_controlRef
) ;
1250 if ( !(m_windowStyle
& wxTE_MULTILINE
) )
1252 SetData
<Boolean
>( kControlEditTextPart
, kControlEditTextSingleLineTag
, true ) ;
1256 wxMacUnicodeTextControl::~wxMacUnicodeTextControl()
1260 void wxMacUnicodeTextControl::VisibilityChanged(bool shown
)
1262 if ( !(m_windowStyle
& wxTE_MULTILINE
) && shown
)
1264 // work around a refresh issue insofar as not always the entire content is shown even if this would be possible
1265 ControlEditTextSelectionRec sel
;
1266 CFStringRef value
= NULL
;
1268 verify_noerr( GetData
<ControlEditTextSelectionRec
>( 0, kControlEditTextSelectionTag
, &sel
) );
1269 verify_noerr( GetData
<CFStringRef
>( 0, m_valueTag
, &value
) );
1270 verify_noerr( SetData
<CFStringRef
>( 0, m_valueTag
, &value
) );
1271 verify_noerr( SetData
<ControlEditTextSelectionRec
>( 0, kControlEditTextSelectionTag
, &sel
) );
1273 CFRelease( value
) ;
1276 wxString
wxMacUnicodeTextControl::GetStringValue() const
1279 CFStringRef value
= GetData
<CFStringRef
>(0,m_valueTag
) ;
1282 wxMacCFStringHolder
cf(value
) ;
1283 result
= cf
.AsString() ;
1286 wxMacConvertNewlines13To10( &result
) ;
1288 wxMacConvertNewlines10To13( &result
) ;
1292 void wxMacUnicodeTextControl::SetStringValue( const wxString
&str
)
1295 wxMacConvertNewlines10To13( &st
) ;
1296 wxMacCFStringHolder
cf(st
, m_font
.GetEncoding() ) ;
1297 verify_noerr( SetData
<CFStringRef
>( 0, m_valueTag
, cf
) ) ;
1299 void wxMacUnicodeTextControl::Copy()
1301 SendHICommand( kHICommandCopy
) ;
1303 void wxMacUnicodeTextControl::Cut()
1305 SendHICommand( kHICommandCut
) ;
1307 void wxMacUnicodeTextControl::Paste()
1309 SendHICommand( kHICommandPaste
) ;
1311 bool wxMacUnicodeTextControl::CanPaste() const
1315 void wxMacUnicodeTextControl::SetEditable(bool editable
)
1317 SetData
<Boolean
>( 0 , kControlEditTextLockedTag
, (Boolean
) !editable
) ;
1319 void wxMacUnicodeTextControl::Remove( long from
, long to
)
1323 void wxMacUnicodeTextControl::GetSelection( long* from
, long* to
) const
1325 ControlEditTextSelectionRec sel
;
1326 verify_noerr(GetData
<ControlEditTextSelectionRec
>( 0, kControlEditTextSelectionTag
, &sel
) ) ;
1327 if ( from
) *from
= sel
.selStart
;
1328 if ( to
) *to
= sel
.selEnd
;
1331 void wxMacUnicodeTextControl::SetSelection( long from
, long to
)
1333 ControlEditTextSelectionRec sel
;
1334 sel
.selStart
= from
;
1336 SetData
<ControlEditTextSelectionRec
>( 0 , kControlEditTextSelectionTag
, &sel
) ;
1339 void wxMacUnicodeTextControl::WriteText(const wxString
& str
)
1342 wxMacConvertNewlines10To13( &st
) ;
1343 #if MAC_OS_X_VERSION_MAX_ALLOWED > MAC_OS_X_VERSION_10_2
1344 wxMacCFStringHolder
cf(st
, m_font
.GetEncoding() ) ;
1345 CFStringRef value
= cf
;
1346 SetData
<CFStringRef
>( 0, kControlEditTextInsertCFStringRefTag
, &value
);
1348 wxString val
= GetStringValue() ;
1350 GetSelection( &start
, &end
) ;
1351 val
.Remove( start
, end
- start
) ;
1352 val
.insert( start
, str
) ;
1353 SetStringValue( val
) ;
1354 SetSelection( start
+ str
.Length() , start
+ str
.Length() ) ;
1360 // ----------------------------------------------------------------------------
1361 // MLTE control implementation (common part)
1362 // ----------------------------------------------------------------------------
1364 // if mlte is on read only , no changes at all are allowed, not even from
1365 // procedural API, in order to allow changes via API all the same we must undo
1366 // the readonly status while we are executing, this class helps to do so
1368 class wxMacEditHelper
1371 wxMacEditHelper( TXNObject txn
)
1373 TXNControlTag tag
[] = { kTXNIOPrivilegesTag
} ;
1375 TXNGetTXNObjectControls( m_txn
, 1 , tag
, m_data
) ;
1376 if ( m_data
[0].uValue
== kTXNReadOnly
)
1378 TXNControlData data
[] = { { kTXNReadWrite
} } ;
1379 TXNSetTXNObjectControls( m_txn
, false , 1 , tag
, data
) ;
1384 TXNControlTag tag
[] = { kTXNIOPrivilegesTag
} ;
1385 if ( m_data
[0].uValue
== kTXNReadOnly
)
1387 TXNSetTXNObjectControls( m_txn
, false , 1 , tag
, m_data
) ;
1392 TXNControlData m_data
[1] ;
1395 wxMacMLTEControl::wxMacMLTEControl( wxTextCtrl
*peer
) : wxMacTextControl( peer
)
1397 SetNeedsFocusRect( true ) ;
1400 wxString
wxMacMLTEControl::GetStringValue() const
1404 Size actualSize
= 0;
1408 err
= TXNGetDataEncoded( m_txn
, kTXNStartOffset
, kTXNEndOffset
, &theText
, kTXNUnicodeTextData
);
1416 actualSize
= GetHandleSize( theText
) / sizeof( UniChar
) ;
1417 if ( actualSize
> 0 )
1419 wxChar
*ptr
= NULL
;
1420 #if SIZEOF_WCHAR_T == 2
1421 ptr
= new wxChar
[actualSize
+ 1 ] ;
1422 wxStrncpy( ptr
, (wxChar
*) *theText
, actualSize
) ;
1424 SetHandleSize( theText
, ( actualSize
+ 1 ) * sizeof( UniChar
) ) ;
1426 (((UniChar
*)*theText
)[actualSize
]) = 0 ;
1427 wxMBConvUTF16 converter
;
1428 size_t noChars
= converter
.MB2WC( NULL
, (const char*)*theText
, 0 ) ;
1429 ptr
= new wxChar
[noChars
+ 1] ;
1431 noChars
= converter
.MB2WC( ptr
, (const char*)*theText
, noChars
) ;
1433 HUnlock( theText
) ;
1435 ptr
[actualSize
] = 0 ;
1436 result
= wxString( ptr
) ;
1439 DisposeHandle( theText
) ;
1443 err
= TXNGetDataEncoded( m_txn
, kTXNStartOffset
, kTXNEndOffset
, &theText
, kTXNTextData
);
1451 actualSize
= GetHandleSize( theText
) ;
1452 if ( actualSize
> 0 )
1455 result
= wxString( *theText
, wxConvLocal
, actualSize
) ;
1456 HUnlock( theText
) ;
1458 DisposeHandle( theText
) ;
1463 wxMacConvertNewlines13To10( &result
) ;
1465 wxMacConvertNewlines10To13( &result
) ;
1470 void wxMacMLTEControl::SetStringValue( const wxString
&str
)
1474 wxMacConvertNewlines10To13( &st
) ;
1476 wxMacWindowClipper
c( m_peer
) ;
1478 wxMacEditHelper
help(m_txn
) ;
1479 SetTXNData( st
, kTXNStartOffset
, kTXNEndOffset
) ;
1481 TXNSetSelection( m_txn
, 0, 0);
1482 TXNShowSelection( m_txn
, kTXNShowStart
);
1486 TXNFrameOptions
wxMacMLTEControl::FrameOptionsFromWXStyle( long wxStyle
)
1488 TXNFrameOptions frameOptions
=
1489 kTXNDontDrawCaretWhenInactiveMask
1490 #if MAC_OS_X_VERSION_MAX_ALLOWED >= MAC_OS_X_VERSION_10_3
1491 | kTXNDoFontSubstitutionMask
1495 if ( ! ( wxStyle
& wxTE_NOHIDESEL
) )
1496 frameOptions
|= kTXNDontDrawSelectionWhenInactiveMask
;
1498 if ( wxStyle
& wxTE_MULTILINE
)
1500 if ( ! ( wxStyle
& wxTE_DONTWRAP
) )
1501 frameOptions
|= kTXNAlwaysWrapAtViewEdgeMask
;
1504 frameOptions
|= kTXNAlwaysWrapAtViewEdgeMask
;
1505 frameOptions
|= kTXNWantHScrollBarMask
;
1508 if ( !(wxStyle
& wxTE_NO_VSCROLL
) )
1510 frameOptions
|= kTXNWantVScrollBarMask
;
1511 if ( frameOptions
& kTXNWantHScrollBarMask
)
1512 frameOptions
|= kTXNDrawGrowIconMask
;
1516 frameOptions
|= kTXNSingleLineOnlyMask
;
1518 if ( wxStyle
& wxHSCROLL
)
1519 frameOptions
|= kTXNWantHScrollBarMask
;
1521 return frameOptions
;
1524 void wxMacMLTEControl::AdjustCreationAttributes( const wxColour
&background
, bool visible
)
1526 TXNControlTag iControlTags
[] =
1528 kTXNDoFontSubstitution
,
1529 kTXNWordWrapStateTag
,
1531 TXNControlData iControlData
[] =
1537 int toptag
= WXSIZEOF( iControlTags
) ;
1539 if ( m_windowStyle
& wxTE_MULTILINE
)
1541 if (m_windowStyle
& wxTE_DONTWRAP
)
1542 iControlData
[1].uValue
= kTXNNoAutoWrap
;
1544 iControlData
[1].uValue
= kTXNAutoWrap
;
1546 verify_noerr( TXNSetTXNObjectControls( m_txn
, false, toptag
,
1547 iControlTags
, iControlData
)) ;
1549 // setting the default font
1550 // under 10.2 this causes a visible caret, therefore we avoid it
1552 if ( UMAGetSystemVersion() >= 0x1030 )
1558 GetThemeFont(kThemeSystemFont
, GetApplicationScript() , fontName
, &fontSize
, &fontStyle
) ;
1560 TXNTypeAttributes typeAttr
[] =
1562 { kTXNQDFontNameAttribute
, kTXNQDFontNameAttributeSize
, { (void*) fontName
} } ,
1563 { kTXNQDFontSizeAttribute
, kTXNFontSizeAttributeSize
, { (void*) (fontSize
<< 16) } } ,
1564 { kTXNQDFontStyleAttribute
, kTXNQDFontStyleAttributeSize
, { (void*) normal
} } ,
1567 verify_noerr( TXNSetTypeAttributes (m_txn
, sizeof( typeAttr
) / sizeof(TXNTypeAttributes
) , typeAttr
,
1572 if ( m_windowStyle
& wxTE_PASSWORD
)
1575 verify_noerr(TXNEchoMode( m_txn
, c
, 0 , true )) ;
1578 TXNBackground tback
;
1579 tback
.bgType
= kTXNBackgroundTypeRGB
;
1580 tback
.bg
.color
= MAC_WXCOLORREF( background
.GetPixel() );
1581 TXNSetBackground( m_txn
, &tback
);
1584 void wxMacMLTEControl::SetBackground( const wxBrush
&brush
)
1586 // currently only solid background are supported
1587 TXNBackground tback
;
1588 tback
.bgType
= kTXNBackgroundTypeRGB
;
1589 tback
.bg
.color
= MAC_WXCOLORREF( brush
.GetColour().GetPixel() );
1590 TXNSetBackground( m_txn
, &tback
);
1593 void wxMacMLTEControl::TXNSetAttribute( const wxTextAttr
& style
, long from
, long to
)
1595 TXNTypeAttributes typeAttr
[4] ;
1596 Str255 fontName
= "\pMonaco" ;
1597 SInt16 fontSize
= 12 ;
1598 Style fontStyle
= normal
;
1600 int attrCounter
= 0 ;
1601 if ( style
.HasFont() )
1603 const wxFont
&font
= style
.GetFont() ;
1604 wxMacStringToPascal( font
.GetFaceName() , fontName
) ;
1605 fontSize
= font
.GetPointSize() ;
1606 if ( font
.GetUnderlined() )
1607 fontStyle
|= underline
;
1608 if ( font
.GetWeight() == wxBOLD
)
1610 if ( font
.GetStyle() == wxITALIC
)
1611 fontStyle
|= italic
;
1613 typeAttr
[attrCounter
].tag
= kTXNQDFontNameAttribute
;
1614 typeAttr
[attrCounter
].size
= kTXNQDFontNameAttributeSize
;
1615 typeAttr
[attrCounter
].data
.dataPtr
= (void*) fontName
;
1616 typeAttr
[attrCounter
+1].tag
= kTXNQDFontSizeAttribute
;
1617 typeAttr
[attrCounter
+1].size
= kTXNFontSizeAttributeSize
;
1618 typeAttr
[attrCounter
+1].data
.dataValue
= (fontSize
<< 16) ;
1619 typeAttr
[attrCounter
+2].tag
= kTXNQDFontStyleAttribute
;
1620 typeAttr
[attrCounter
+2].size
= kTXNQDFontStyleAttributeSize
;
1621 typeAttr
[attrCounter
+2].data
.dataValue
= fontStyle
;
1624 if ( style
.HasTextColour() )
1626 typeAttr
[attrCounter
].tag
= kTXNQDFontColorAttribute
;
1627 typeAttr
[attrCounter
].size
= kTXNQDFontColorAttributeSize
;
1628 typeAttr
[attrCounter
].data
.dataPtr
= (void*) &color
;
1629 color
= MAC_WXCOLORREF(style
.GetTextColour().GetPixel()) ;
1632 if ( attrCounter
> 0 )
1634 verify_noerr( TXNSetTypeAttributes ( m_txn
, attrCounter
, typeAttr
, from
, to
) );
1638 void wxMacMLTEControl::SetFont( const wxFont
& font
, const wxColour
& foreground
, long windowStyle
)
1640 wxMacEditHelper
help(m_txn
) ;
1641 TXNSetAttribute( wxTextAttr(foreground
,wxNullColour
,font
) , kTXNStartOffset
,kTXNEndOffset
) ;
1643 void wxMacMLTEControl::SetStyle(long start
, long end
, const wxTextAttr
& style
)
1645 wxMacEditHelper
help(m_txn
) ;
1646 TXNSetAttribute( style
, start
,end
) ;
1649 void wxMacMLTEControl::Copy()
1651 ClearCurrentScrap();
1653 TXNConvertToPublicScrap();
1656 void wxMacMLTEControl::Cut()
1658 ClearCurrentScrap();
1660 TXNConvertToPublicScrap();
1663 void wxMacMLTEControl::Paste()
1665 TXNConvertFromPublicScrap();
1669 bool wxMacMLTEControl::CanPaste() const
1671 return TXNIsScrapPastable() ;
1674 void wxMacMLTEControl::SetEditable(bool editable
)
1676 TXNControlTag tag
[] = { kTXNIOPrivilegesTag
} ;
1677 TXNControlData data
[] = { { editable
? kTXNReadWrite
: kTXNReadOnly
} } ;
1678 TXNSetTXNObjectControls( m_txn
, false , WXSIZEOF(tag
) , tag
, data
) ;
1681 wxTextPos
wxMacMLTEControl::GetLastPosition() const
1683 wxTextPos actualsize
= 0 ;
1686 OSErr err
= TXNGetDataEncoded( m_txn
, kTXNStartOffset
, kTXNEndOffset
, &theText
, kTXNTextData
);
1694 actualsize
= GetHandleSize( theText
) ;
1695 DisposeHandle( theText
) ;
1701 void wxMacMLTEControl::Replace( long from
, long to
, const wxString str
)
1703 wxString value
= str
;
1704 wxMacConvertNewlines10To13( &value
) ;
1706 wxMacEditHelper
help( m_txn
) ;
1707 wxMacWindowClipper
c( m_peer
) ;
1709 TXNSetSelection(m_txn
, from
, to
) ;
1711 SetTXNData( value
, kTXNUseCurrentSelection
, kTXNUseCurrentSelection
) ;
1714 void wxMacMLTEControl::Remove( long from
, long to
)
1716 wxMacWindowClipper
c( m_peer
) ;
1717 wxMacEditHelper
help( m_txn
) ;
1718 TXNSetSelection(m_txn
, from
, to
) ;
1722 void wxMacMLTEControl::GetSelection( long* from
, long* to
) const
1724 TXNGetSelection( m_txn
, (TXNOffset
*) from
, (TXNOffset
*) to
) ;
1727 void wxMacMLTEControl::SetSelection( long from
, long to
)
1729 wxMacWindowClipper
c( m_peer
) ;
1730 /* change the selection */
1731 if ((from
== -1) && (to
== -1))
1732 TXNSelectAll(m_txn
);
1734 TXNSetSelection( m_txn
, from
, to
);
1735 TXNShowSelection( m_txn
, kTXNShowStart
);
1738 void wxMacMLTEControl::WriteText(const wxString
& str
)
1741 wxMacConvertNewlines10To13( &st
) ;
1743 long start
, end
, dummy
;
1744 GetSelection( &start
, &dummy
) ;
1745 wxMacWindowClipper
c( m_peer
) ;
1747 wxMacEditHelper
helper( m_txn
) ;
1748 SetTXNData( st
, kTXNUseCurrentSelection
, kTXNUseCurrentSelection
) ;
1750 GetSelection( &dummy
, &end
) ;
1751 // TODO SetStyle( start , end , GetDefaultStyle() ) ;
1754 void wxMacMLTEControl::Clear()
1756 wxMacWindowClipper
c( m_peer
) ;
1757 wxMacEditHelper
st(m_txn
) ;
1758 TXNSetSelection( m_txn
, kTXNStartOffset
, kTXNEndOffset
) ;
1762 bool wxMacMLTEControl::CanUndo() const
1764 return TXNCanUndo( m_txn
, NULL
) ;
1767 void wxMacMLTEControl::Undo()
1772 bool wxMacMLTEControl::CanRedo() const
1774 return TXNCanRedo( m_txn
, NULL
) ;
1777 void wxMacMLTEControl::Redo()
1782 int wxMacMLTEControl::GetNumberOfLines() const
1784 ItemCount lines
= 0 ;
1785 TXNGetLineCount(m_txn
, &lines
) ;
1789 long wxMacMLTEControl::XYToPosition(long x
, long y
) const
1793 wxTextPos lastpos
= GetLastPosition() ;
1795 // TODO find a better implementation : while we can get the
1796 // line metrics of a certain line, we don't get its starting
1797 // position, so it would probably be rather a binary search
1798 // for the start position
1801 int lastHeight
= 0 ;
1804 for ( n
= 0 ; n
<= (ItemCount
) lastpos
; ++n
)
1806 if ( y
== ypos
&& x
== xpos
)
1809 TXNOffsetToPoint( m_txn
, n
, &curpt
);
1811 if ( curpt
.v
> lastHeight
)
1816 lastHeight
= curpt
.v
;
1824 bool wxMacMLTEControl::PositionToXY(long pos
, long *x
, long *y
) const
1828 wxTextPos lastpos
= GetLastPosition() ;
1833 if ( pos
<= lastpos
)
1835 // TODO find a better implementation : while we can get the
1836 // line metrics of a certain line, we don't get its starting
1837 // position, so it would probably be rather a binary search
1838 // for the start position
1841 int lastHeight
= 0 ;
1844 for ( n
= 0 ; n
<= (ItemCount
) pos
; ++n
)
1846 TXNOffsetToPoint(m_txn
, n
, &curpt
);
1848 if ( curpt
.v
> lastHeight
)
1853 lastHeight
= curpt
.v
;
1858 if ( y
) *y
= ypos
;
1859 if ( x
) *x
= xpos
;
1865 void wxMacMLTEControl::ShowPosition( long pos
)
1867 #if TARGET_RT_MAC_MACHO && defined(AVAILABLE_MAC_OS_X_VERSION_10_2_AND_LATER)
1871 TXNOffset selstart
, selend
;
1872 TXNGetSelection( m_txn
, &selstart
, &selend
) ;
1873 TXNOffsetToPoint( m_txn
, selstart
, ¤t
);
1874 TXNOffsetToPoint( m_txn
, pos
, &desired
);
1875 //TODO use HIPoints for 10.3 and above
1876 if ( (UInt32
) TXNScroll
!= (UInt32
) kUnresolvedCFragSymbolAddress
)
1878 OSErr theErr
= noErr
;
1879 SInt32 dv
= desired
.v
- current
.v
;
1880 SInt32 dh
= desired
.h
- current
.h
;
1881 TXNShowSelection( m_txn
, true ) ;
1882 theErr
= TXNScroll( m_txn
, kTXNScrollUnitsInPixels
, kTXNScrollUnitsInPixels
, &dv
, &dh
);
1883 // there will be an error returned for classic mlte implementation when the control is
1884 // invisible, but HITextView works correctly, so we don't assert that one
1885 // wxASSERT_MSG( theErr == noErr, _T("TXNScroll returned an error!") );
1891 void wxMacMLTEControl::SetTXNData( const wxString
& st
, TXNOffset start
, TXNOffset end
)
1894 #if SIZEOF_WCHAR_T == 2
1895 size_t len
= st
.Len() ;
1896 TXNSetData( m_txn
, kTXNUnicodeTextData
, (void*)st
.wc_str(), len
* 2,
1899 wxMBConvUTF16 converter
;
1900 ByteCount byteBufferLen
= converter
.WC2MB( NULL
, st
.wc_str() , 0 ) ;
1901 UniChar
*unibuf
= (UniChar
*) malloc(byteBufferLen
) ;
1902 converter
.WC2MB( (char*) unibuf
, st
.wc_str() , byteBufferLen
) ;
1903 TXNSetData( m_txn
, kTXNUnicodeTextData
, (void*)unibuf
, byteBufferLen
,
1908 wxCharBuffer text
= st
.mb_str(wxConvLocal
) ;
1909 TXNSetData( m_txn
, kTXNTextData
, (void*)text
.data(), strlen( text
) ,
1915 wxString
wxMacMLTEControl::GetLineText(long lineNo
) const
1919 if ( lineNo
< GetNumberOfLines() )
1927 // get the first possible position in the control
1929 TXNOffsetToPoint(m_txn
, 0, &firstPoint
);
1931 // Iterate through the lines until we reach the one we want,
1932 // adding to our current y pixel point position
1933 while (ypos
< lineNo
)
1935 TXNGetLineMetrics(m_txn
, ypos
++, &lineWidth
, &lineHeight
);
1936 currentHeight
+= lineHeight
;
1939 Point thePoint
= { firstPoint
.v
+ (currentHeight
>> 16), firstPoint
.h
+ (0) };
1940 TXNOffset theOffset
;
1941 TXNPointToOffset(m_txn
, thePoint
, &theOffset
);
1943 wxString content
= GetStringValue() ;
1944 Point currentPoint
= thePoint
;
1945 while(thePoint
.v
== currentPoint
.v
&& theOffset
< content
.length())
1947 line
+= content
[theOffset
];
1948 TXNOffsetToPoint(m_txn
, ++theOffset
, ¤tPoint
);
1954 int wxMacMLTEControl::GetLineLength(long lineNo
) const
1958 if ( lineNo
< GetNumberOfLines() )
1966 // get the first possible position in the control
1968 TXNOffsetToPoint(m_txn
, 0, &firstPoint
);
1970 // Iterate through the lines until we reach the one we want,
1971 // adding to our current y pixel point position
1972 while (ypos
< lineNo
)
1974 TXNGetLineMetrics(m_txn
, ypos
++, &lineWidth
, &lineHeight
);
1975 currentHeight
+= lineHeight
;
1978 Point thePoint
= { firstPoint
.v
+ (currentHeight
>> 16), firstPoint
.h
+ (0) };
1979 TXNOffset theOffset
;
1980 TXNPointToOffset(m_txn
, thePoint
, &theOffset
);
1982 wxString content
= GetStringValue() ;
1983 Point currentPoint
= thePoint
;
1984 while(thePoint
.v
== currentPoint
.v
&& theOffset
< content
.length())
1987 TXNOffsetToPoint(m_txn
, ++theOffset
, ¤tPoint
);
1994 // ----------------------------------------------------------------------------
1995 // MLTE control implementation (classic part)
1996 // ----------------------------------------------------------------------------
1998 // OS X Notes : We still don't have a full replacement for MLTE, so this implementation
1999 // has to live on. We have different problems coming from outdated implementations on the
2000 // various OS X versions. Most deal with the scrollbars: they are not correctly embedded
2001 // while this can be solved on 10.3 by reassigning them the correct place, on 10.2 there is
2002 // no way out, therefore we are using our own implementation and our own scrollbars ....
2004 #ifdef __WXMAC_OSX__
2006 TXNScrollInfoUPP gTXNScrollInfoProc
= NULL
;
2007 ControlActionUPP gTXNScrollActionProc
= NULL
;
2009 pascal void wxMacMLTEClassicControl::TXNScrollInfoProc (SInt32 iValue
, SInt32 iMaximumValue
, TXNScrollBarOrientation
2010 iScrollBarOrientation
, SInt32 iRefCon
)
2012 wxMacMLTEClassicControl
* mlte
= (wxMacMLTEClassicControl
*) iRefCon
;
2013 SInt32 value
= wxMax( iValue
, 0 ) ;
2014 SInt32 maximum
= wxMax( iMaximumValue
, 0 ) ;
2016 if ( iScrollBarOrientation
== kTXNHorizontal
)
2018 if ( mlte
->m_sbHorizontal
)
2020 SetControl32BitValue( mlte
->m_sbHorizontal
, value
) ;
2021 SetControl32BitMaximum( mlte
->m_sbHorizontal
, maximum
) ;
2022 mlte
->m_lastHorizontalValue
= value
;
2025 else if ( iScrollBarOrientation
== kTXNVertical
)
2027 if ( mlte
->m_sbVertical
)
2029 SetControl32BitValue( mlte
->m_sbVertical
, value
) ;
2030 SetControl32BitMaximum( mlte
->m_sbVertical
, maximum
) ;
2031 mlte
->m_lastVerticalValue
= value
;
2036 pascal void wxMacMLTEClassicControl::TXNScrollActionProc( ControlRef controlRef
, ControlPartCode partCode
)
2039 wxMacMLTEClassicControl
* mlte
= (wxMacMLTEClassicControl
*) GetControlReference( controlRef
) ;
2043 if ( controlRef
!= mlte
->m_sbVertical
&& controlRef
!= mlte
->m_sbHorizontal
)
2046 bool isHorizontal
= ( controlRef
== mlte
->m_sbHorizontal
) ;
2048 SInt32 minimum
= 0 ;
2049 SInt32 maximum
= GetControl32BitMaximum( controlRef
) ;
2050 SInt32 value
= GetControl32BitValue( controlRef
) ;
2054 case kControlDownButtonPart
:
2057 case kControlUpButtonPart
:
2060 case kControlPageDownPart
:
2061 delta
= GetControlViewSize( controlRef
) ;
2063 case kControlPageUpPart
:
2064 delta
= -GetControlViewSize( controlRef
) ;
2066 case kControlIndicatorPart
:
2068 ( isHorizontal
? mlte
->m_lastHorizontalValue
: mlte
->m_lastVerticalValue
) ;
2075 SInt32 newValue
= value
;
2077 if ( partCode
!= kControlIndicatorPart
)
2079 if( value
+ delta
< minimum
)
2080 delta
= minimum
- value
;
2081 if ( value
+ delta
> maximum
)
2082 delta
= maximum
- value
;
2084 SetControl32BitValue( controlRef
, value
+ delta
) ;
2085 newValue
= value
+ delta
;
2088 SInt32 verticalDelta
= isHorizontal
? 0 : delta
;
2089 SInt32 horizontalDelta
= isHorizontal
? delta
: 0 ;
2091 err
= TXNScroll( mlte
->m_txn
, kTXNScrollUnitsInPixels
, kTXNScrollUnitsInPixels
,
2092 &verticalDelta
, &horizontalDelta
);
2095 mlte
->m_lastHorizontalValue
= newValue
;
2097 mlte
->m_lastVerticalValue
= newValue
;
2102 // make correct activations
2103 void wxMacMLTEClassicControl::MacActivatePaneText(Boolean setActive
)
2105 wxTextCtrl
* textctrl
= (wxTextCtrl
*) GetControlReference(m_controlRef
);
2107 wxMacWindowClipper
clipper( textctrl
) ;
2108 TXNActivate(m_txn
, m_txnFrameID
, setActive
);
2110 ControlRef controlFocus
= 0 ;
2111 GetKeyboardFocus( m_txnWindow
, &controlFocus
) ;
2112 if ( controlFocus
== m_controlRef
)
2113 TXNFocus( m_txn
, setActive
);
2116 void wxMacMLTEClassicControl::MacFocusPaneText(Boolean setFocus
)
2118 TXNFocus( m_txn
, setFocus
);
2121 // guards against inappropriate redraw (hidden objects drawing onto window)
2123 void wxMacMLTEClassicControl::MacSetObjectVisibility(Boolean vis
)
2125 ControlRef controlFocus
= 0 ;
2126 GetKeyboardFocus( m_txnWindow
, &controlFocus
) ;
2128 if ( controlFocus
== m_controlRef
&& vis
== false )
2130 SetKeyboardFocus( m_txnWindow
, m_controlRef
, kControlFocusNoPart
) ;
2133 TXNControlTag iControlTags
[1] = { kTXNVisibilityTag
};
2134 TXNControlData iControlData
[1] = { {(UInt32
) false } };
2136 verify_noerr( TXNGetTXNObjectControls( m_txn
, 1,
2137 iControlTags
, iControlData
) ) ;
2139 if ( iControlData
[0].uValue
!= vis
)
2141 iControlData
[0].uValue
= vis
;
2142 verify_noerr( TXNSetTXNObjectControls( m_txn
, false , 1,
2143 iControlTags
, iControlData
)) ;
2145 // we right now are always clipping as partial visibility (overlapped) visibility
2146 // is also a problem, if we run into further problems we might set the FrameBounds to an empty
2150 // make sure that the TXNObject is at the right position
2152 void wxMacMLTEClassicControl::MacUpdatePosition()
2154 wxTextCtrl
* textctrl
= (wxTextCtrl
*) GetControlReference(m_controlRef
);
2155 if ( textctrl
== NULL
)
2159 UMAGetControlBoundsInWindowCoords(m_controlRef
, &bounds
);
2161 wxRect visRect
= textctrl
->MacGetClippedClientRect() ;
2162 Rect visBounds
= { visRect
.y
, visRect
.x
, visRect
.y
+ visRect
.height
, visRect
.x
+ visRect
.width
} ;
2165 textctrl
->MacWindowToRootWindow( &x
, &y
) ;
2166 OffsetRect( &visBounds
, x
, y
) ;
2168 if ( !EqualRect( &bounds
, &m_txnControlBounds
) || !EqualRect( &visBounds
, &m_txnVisBounds
) )
2170 m_txnControlBounds
= bounds
;
2171 m_txnVisBounds
= visBounds
;
2172 wxMacWindowClipper
cl(textctrl
) ;
2174 #ifdef __WXMAC_OSX__
2175 bool isCompositing
= textctrl
->MacGetTopLevelWindow()->MacUsesCompositing() ;
2176 if ( m_sbHorizontal
|| m_sbVertical
)
2178 int w
= bounds
.right
- bounds
.left
;
2179 int h
= bounds
.bottom
- bounds
.top
;
2181 if ( m_sbHorizontal
)
2185 sbBounds
.left
= -1 ;
2186 sbBounds
.top
= h
- 14 ;
2187 sbBounds
.right
= w
+ 1 ;
2188 sbBounds
.bottom
= h
+ 1 ;
2190 if ( !isCompositing
)
2191 OffsetRect( &sbBounds
, m_txnControlBounds
.left
, m_txnControlBounds
.top
) ;
2193 SetControlBounds( m_sbHorizontal
, &sbBounds
) ;
2194 SetControlViewSize( m_sbHorizontal
, w
) ;
2200 sbBounds
.left
= w
- 14 ;
2202 sbBounds
.right
= w
+ 1 ;
2203 sbBounds
.bottom
= m_sbHorizontal
? h
- 14 : h
+ 1 ;
2205 if ( !isCompositing
)
2206 OffsetRect( &sbBounds
, m_txnControlBounds
.left
, m_txnControlBounds
.top
) ;
2208 SetControlBounds( m_sbVertical
, &sbBounds
) ;
2209 SetControlViewSize( m_sbVertical
, h
) ;
2214 TXNLongRect olddestRect
;
2215 TXNGetRectBounds( m_txn
, &oldviewRect
, &olddestRect
, NULL
) ;
2217 Rect viewRect
= { m_txnControlBounds
.top
, m_txnControlBounds
.left
,
2218 m_txnControlBounds
.bottom
- ( m_sbHorizontal
? 14 : 0 ) , m_txnControlBounds
.right
- ( m_sbVertical
? 14 : 0 ) } ;
2219 TXNLongRect destRect
= { m_txnControlBounds
.top
, m_txnControlBounds
.left
,
2220 m_txnControlBounds
.bottom
- ( m_sbHorizontal
? 14 : 0 ) , m_txnControlBounds
.right
- ( m_sbVertical
? 14 : 0 ) } ;
2222 if ( olddestRect
.right
>= 10000 )
2223 destRect
.right
= destRect
.left
+ 32000 ;
2225 if ( olddestRect
.bottom
>= 0x20000000 )
2226 destRect
.bottom
= destRect
.top
+ 0x40000000 ;
2228 SectRect( &viewRect
, &visBounds
, &viewRect
) ;
2229 TXNSetRectBounds( m_txn
, &viewRect
, &destRect
, true ) ;
2231 TXNSetFrameBounds( m_txn, m_txnControlBounds.top, m_txnControlBounds.left,
2232 m_txnControlBounds.bottom - ( m_sbHorizontal ? 14 : 0 ) , m_txnControlBounds.right - ( m_sbVertical ? 14 : 0 ), m_txnFrameID);
2236 TXNSetFrameBounds( m_txn
, m_txnControlBounds
.top
, m_txnControlBounds
.left
,
2237 wxMax( m_txnControlBounds
.bottom
, m_txnControlBounds
.top
) ,
2238 wxMax( m_txnControlBounds
.right
, m_txnControlBounds
.left
) , m_txnFrameID
);
2240 // the SetFrameBounds method unter classic sometimes does not correctly scroll a selection into sight after a
2241 // movement, therefore we have to force it
2243 TXNLongRect textRect
;
2244 TXNGetRectBounds( m_txn
, NULL
, NULL
, &textRect
) ;
2245 if ( textRect
.left
< m_txnControlBounds
.left
)
2247 TXNShowSelection( m_txn
, false ) ;
2253 void wxMacMLTEClassicControl::SetRect( Rect
*r
)
2255 wxMacControl::SetRect( r
) ;
2256 MacUpdatePosition() ;
2259 void wxMacMLTEClassicControl::MacControlUserPaneDrawProc(wxInt16 thePart
)
2261 wxTextCtrl
* textctrl
= (wxTextCtrl
*) GetControlReference(m_controlRef
);
2262 if ( textctrl
== NULL
)
2265 if ( textctrl
->MacIsReallyShown() )
2267 wxMacWindowClipper
clipper( textctrl
) ;
2268 TXNDraw( m_txn
, NULL
) ;
2272 wxInt16
wxMacMLTEClassicControl::MacControlUserPaneHitTestProc(wxInt16 x
, wxInt16 y
)
2274 Point where
= { y
, x
} ;
2275 ControlPartCode result
;
2278 wxTextCtrl
* textctrl
= (wxTextCtrl
*) GetControlReference(m_controlRef
);
2279 if ( textctrl
== NULL
)
2282 if (textctrl
->MacIsReallyShown() )
2284 if (PtInRect(where
, &m_txnControlBounds
))
2285 result
= kControlEditTextPart
;
2288 // sometimes we get the coords also in control local coordinates, therefore test again
2289 if ( textctrl
->MacGetTopLevelWindow()->MacUsesCompositing() )
2292 textctrl
->MacClientToRootWindow( &x
, &y
) ;
2296 if (PtInRect(where
, &m_txnControlBounds
))
2297 result
= kControlEditTextPart
;
2305 wxInt16
wxMacMLTEClassicControl::MacControlUserPaneTrackingProc( wxInt16 x
, wxInt16 y
, void* actionProc
)
2307 wxTextCtrl
* textctrl
= (wxTextCtrl
*) GetControlReference(m_controlRef
);
2308 if ( textctrl
== NULL
)
2311 ControlPartCode partCodeResult
= 0;
2313 if (textctrl
->MacIsReallyShown() )
2315 Point startPt
= { y
,x
} ;
2316 // for compositing, we must convert these into toplevel window coordinates, because hittesting expects them
2317 if ( textctrl
->MacGetTopLevelWindow()->MacUsesCompositing() )
2320 textctrl
->MacClientToRootWindow( &x
, &y
) ;
2325 switch (MacControlUserPaneHitTestProc( startPt
.h
, startPt
.v
))
2327 case kControlEditTextPart
:
2329 wxMacWindowClipper
clipper( textctrl
) ;
2332 ConvertEventRefToEventRecord( (EventRef
) wxTheApp
->MacGetCurrentEvent() , &rec
) ;
2333 TXNClick( m_txn
, &rec
);
2339 return partCodeResult
;
2342 void wxMacMLTEClassicControl::MacControlUserPaneIdleProc()
2344 wxTextCtrl
* textctrl
= (wxTextCtrl
*) GetControlReference(m_controlRef
);
2345 if ( textctrl
== NULL
)
2348 if (textctrl
->MacIsReallyShown())
2350 if (IsControlActive(m_controlRef
))
2354 wxMacWindowClipper
clipper( textctrl
) ;
2359 if (PtInRect(mousep
, &m_txnControlBounds
))
2362 RectRgn((theRgn
= NewRgn()), &m_txnControlBounds
);
2363 TXNAdjustCursor(m_txn
, theRgn
);
2370 wxInt16
wxMacMLTEClassicControl::MacControlUserPaneKeyDownProc (wxInt16 keyCode
, wxInt16 charCode
, wxInt16 modifiers
)
2372 wxTextCtrl
* textctrl
= (wxTextCtrl
*) GetControlReference(m_controlRef
);
2373 if ( textctrl
== NULL
)
2376 wxMacWindowClipper
clipper( textctrl
) ;
2379 memset( &ev
, 0 , sizeof( ev
) ) ;
2381 ev
.modifiers
= modifiers
;
2382 ev
.message
= (( keyCode
<< 8 ) & keyCodeMask
) + ( charCode
& charCodeMask
) ;
2383 TXNKeyDown( m_txn
, &ev
);
2385 return kControlEntireControl
;
2388 void wxMacMLTEClassicControl::MacControlUserPaneActivateProc( bool activating
)
2390 MacActivatePaneText( activating
);
2393 wxInt16
wxMacMLTEClassicControl::MacControlUserPaneFocusProc(wxInt16 action
)
2395 ControlPartCode focusResult
;
2397 focusResult
= kControlFocusNoPart
;
2398 wxTextCtrl
* textctrl
= (wxTextCtrl
*) GetControlReference(m_controlRef
);
2399 if ( textctrl
== NULL
)
2402 wxMacWindowClipper
clipper( textctrl
) ;
2404 ControlRef controlFocus
= 0 ;
2405 GetKeyboardFocus( m_txnWindow
, &controlFocus
) ;
2406 bool wasFocused
= ( controlFocus
== m_controlRef
) ;
2410 case kControlFocusPrevPart
:
2411 case kControlFocusNextPart
:
2412 MacFocusPaneText( ( !wasFocused
));
2413 focusResult
= (!wasFocused
) ? (ControlPartCode
) kControlEditTextPart
: (ControlPartCode
) kControlFocusNoPart
;
2416 case kControlFocusNoPart
:
2418 MacFocusPaneText( false);
2419 focusResult
= kControlFocusNoPart
;
2426 void wxMacMLTEClassicControl::MacControlUserPaneBackgroundProc( void *info
)
2430 wxMacMLTEClassicControl::wxMacMLTEClassicControl( wxTextCtrl
*wxPeer
,
2431 const wxString
& str
,
2433 const wxSize
& size
, long style
) : wxMacMLTEControl( wxPeer
)
2435 m_font
= wxPeer
->GetFont() ;
2436 m_windowStyle
= style
;
2437 Rect bounds
= wxMacGetBoundsForControl( wxPeer
, pos
, size
) ;
2439 wxMacConvertNewlines10To13( &st
) ;
2443 featurSet
= kControlSupportsEmbedding
| kControlSupportsFocus
| kControlWantsIdle
2444 | kControlWantsActivate
| kControlHandlesTracking
// | kControlHasSpecialBackground
2445 | kControlGetsFocusOnClick
| kControlSupportsLiveFeedback
;
2447 verify_noerr( ::CreateUserPaneControl( MAC_WXHWND(wxPeer
->GetParent()->MacGetTopLevelWindowRef()), &bounds
, featurSet
, &m_controlRef
) );
2451 AdjustCreationAttributes( *wxWHITE
, true) ;
2453 MacSetObjectVisibility( wxPeer
->MacIsReallyShown() ) ;
2455 wxMacWindowClipper
clipper( m_peer
) ;
2456 SetTXNData( st
, kTXNStartOffset
, kTXNEndOffset
) ;
2457 TXNSetSelection( m_txn
, 0, 0);
2460 wxMacMLTEClassicControl::~wxMacMLTEClassicControl()
2462 TXNDeleteObject(m_txn
);
2466 void wxMacMLTEClassicControl::VisibilityChanged(bool shown
)
2468 MacSetObjectVisibility( shown
) ;
2469 wxMacControl::VisibilityChanged( shown
) ;
2472 void wxMacMLTEClassicControl::SuperChangedPosition()
2474 MacUpdatePosition() ;
2475 wxMacControl::SuperChangedPosition() ;
2478 #ifdef __WXMAC_OSX__
2480 ControlUserPaneDrawUPP gTPDrawProc
= NULL
;
2481 ControlUserPaneHitTestUPP gTPHitProc
= NULL
;
2482 ControlUserPaneTrackingUPP gTPTrackProc
= NULL
;
2483 ControlUserPaneIdleUPP gTPIdleProc
= NULL
;
2484 ControlUserPaneKeyDownUPP gTPKeyProc
= NULL
;
2485 ControlUserPaneActivateUPP gTPActivateProc
= NULL
;
2486 ControlUserPaneFocusUPP gTPFocusProc
= NULL
;
2488 static pascal void wxMacControlUserPaneDrawProc(ControlRef control
, SInt16 part
)
2490 wxTextCtrl
*textCtrl
= wxDynamicCast( wxFindControlFromMacControl(control
) , wxTextCtrl
) ;
2491 wxMacMLTEClassicControl
* win
= textCtrl
? (wxMacMLTEClassicControl
*)(textCtrl
->GetPeer()) : NULL
;
2493 win
->MacControlUserPaneDrawProc(part
) ;
2496 static pascal ControlPartCode
wxMacControlUserPaneHitTestProc(ControlRef control
, Point where
)
2498 wxTextCtrl
*textCtrl
= wxDynamicCast( wxFindControlFromMacControl(control
) , wxTextCtrl
) ;
2499 wxMacMLTEClassicControl
* win
= textCtrl
? (wxMacMLTEClassicControl
*)(textCtrl
->GetPeer()) : NULL
;
2501 return win
->MacControlUserPaneHitTestProc(where
.h
, where
.v
) ;
2503 return kControlNoPart
;
2506 static pascal ControlPartCode
wxMacControlUserPaneTrackingProc(ControlRef control
, Point startPt
, ControlActionUPP actionProc
)
2508 wxTextCtrl
*textCtrl
= wxDynamicCast( wxFindControlFromMacControl(control
) , wxTextCtrl
) ;
2509 wxMacMLTEClassicControl
* win
= textCtrl
? (wxMacMLTEClassicControl
*)(textCtrl
->GetPeer()) : NULL
;
2511 return win
->MacControlUserPaneTrackingProc( startPt
.h
, startPt
.v
, (void*) actionProc
) ;
2513 return kControlNoPart
;
2516 static pascal void wxMacControlUserPaneIdleProc(ControlRef control
)
2518 wxTextCtrl
*textCtrl
= wxDynamicCast( wxFindControlFromMacControl(control
) , wxTextCtrl
) ;
2519 wxMacMLTEClassicControl
* win
= textCtrl
? (wxMacMLTEClassicControl
*)(textCtrl
->GetPeer()) : NULL
;
2521 win
->MacControlUserPaneIdleProc() ;
2524 static pascal ControlPartCode
wxMacControlUserPaneKeyDownProc(ControlRef control
, SInt16 keyCode
, SInt16 charCode
, SInt16 modifiers
)
2526 wxTextCtrl
*textCtrl
= wxDynamicCast( wxFindControlFromMacControl(control
) , wxTextCtrl
) ;
2527 wxMacMLTEClassicControl
* win
= textCtrl
? (wxMacMLTEClassicControl
*)(textCtrl
->GetPeer()) : NULL
;
2529 return win
->MacControlUserPaneKeyDownProc(keyCode
,charCode
,modifiers
) ;
2531 return kControlNoPart
;
2534 static pascal void wxMacControlUserPaneActivateProc(ControlRef control
, Boolean activating
)
2536 wxTextCtrl
*textCtrl
= wxDynamicCast( wxFindControlFromMacControl(control
) , wxTextCtrl
) ;
2537 wxMacMLTEClassicControl
* win
= textCtrl
? (wxMacMLTEClassicControl
*)(textCtrl
->GetPeer()) : NULL
;
2539 win
->MacControlUserPaneActivateProc(activating
) ;
2542 static pascal ControlPartCode
wxMacControlUserPaneFocusProc(ControlRef control
, ControlFocusPart action
)
2544 wxTextCtrl
*textCtrl
= wxDynamicCast( wxFindControlFromMacControl(control
) , wxTextCtrl
) ;
2545 wxMacMLTEClassicControl
* win
= textCtrl
? (wxMacMLTEClassicControl
*)(textCtrl
->GetPeer()) : NULL
;
2547 return win
->MacControlUserPaneFocusProc(action
) ;
2549 return kControlNoPart
;
2553 static pascal void wxMacControlUserPaneBackgroundProc(ControlRef control, ControlBackgroundPtr info)
2555 wxTextCtrl *textCtrl = wxDynamicCast( wxFindControlFromMacControl(control) , wxTextCtrl ) ;
2556 wxMacMLTEClassicControl * win = textCtrl ? (wxMacMLTEClassicControl*)(textCtrl->GetPeer()) : NULL ;
2558 win->MacControlUserPaneBackgroundProc(info) ;
2563 // TXNRegisterScrollInfoProc
2565 OSStatus
wxMacMLTEClassicControl::DoCreate()
2569 OSStatus err
= noErr
;
2571 /* set up our globals */
2572 #ifdef __WXMAC_OSX__
2573 if (gTPDrawProc
== NULL
) gTPDrawProc
= NewControlUserPaneDrawUPP(wxMacControlUserPaneDrawProc
);
2574 if (gTPHitProc
== NULL
) gTPHitProc
= NewControlUserPaneHitTestUPP(wxMacControlUserPaneHitTestProc
);
2575 if (gTPTrackProc
== NULL
) gTPTrackProc
= NewControlUserPaneTrackingUPP(wxMacControlUserPaneTrackingProc
);
2576 if (gTPIdleProc
== NULL
) gTPIdleProc
= NewControlUserPaneIdleUPP(wxMacControlUserPaneIdleProc
);
2577 if (gTPKeyProc
== NULL
) gTPKeyProc
= NewControlUserPaneKeyDownUPP(wxMacControlUserPaneKeyDownProc
);
2578 if (gTPActivateProc
== NULL
) gTPActivateProc
= NewControlUserPaneActivateUPP(wxMacControlUserPaneActivateProc
);
2579 if (gTPFocusProc
== NULL
) gTPFocusProc
= NewControlUserPaneFocusUPP(wxMacControlUserPaneFocusProc
);
2581 if (gTXNScrollInfoProc
== NULL
) gTXNScrollInfoProc
= NewTXNScrollInfoUPP(TXNScrollInfoProc
) ;
2582 if (gTXNScrollActionProc
== NULL
) gTXNScrollActionProc
= NewControlActionUPP(TXNScrollActionProc
) ;
2585 /* set the initial settings for our private data */
2587 m_txnWindow
=GetControlOwner(m_controlRef
);
2588 m_txnPort
= (GrafPtr
) GetWindowPort(m_txnWindow
);
2590 #ifdef __WXMAC_OSX__
2591 /* set up the user pane procedures */
2592 SetControlData(m_controlRef
, kControlEntireControl
, kControlUserPaneDrawProcTag
, sizeof(gTPDrawProc
), &gTPDrawProc
);
2593 SetControlData(m_controlRef
, kControlEntireControl
, kControlUserPaneHitTestProcTag
, sizeof(gTPHitProc
), &gTPHitProc
);
2594 SetControlData(m_controlRef
, kControlEntireControl
, kControlUserPaneTrackingProcTag
, sizeof(gTPTrackProc
), &gTPTrackProc
);
2595 SetControlData(m_controlRef
, kControlEntireControl
, kControlUserPaneIdleProcTag
, sizeof(gTPIdleProc
), &gTPIdleProc
);
2596 SetControlData(m_controlRef
, kControlEntireControl
, kControlUserPaneKeyDownProcTag
, sizeof(gTPKeyProc
), &gTPKeyProc
);
2597 SetControlData(m_controlRef
, kControlEntireControl
, kControlUserPaneActivateProcTag
, sizeof(gTPActivateProc
), &gTPActivateProc
);
2598 SetControlData(m_controlRef
, kControlEntireControl
, kControlUserPaneFocusProcTag
, sizeof(gTPFocusProc
), &gTPFocusProc
);
2600 /* calculate the rectangles used by the control */
2601 UMAGetControlBoundsInWindowCoords(m_controlRef
, &bounds
);
2603 m_txnControlBounds
= bounds
;
2604 m_txnVisBounds
= bounds
;
2606 CGrafPtr origPort
= NULL
;
2607 GDHandle origDev
= NULL
;
2608 GetGWorld( &origPort
, &origDev
) ;
2611 /* create the new edit field */
2613 TXNFrameOptions frameOptions
= FrameOptionsFromWXStyle( m_windowStyle
) ;
2615 #ifdef __WXMAC_OSX__
2617 // the scrollbars are not correctly embedded but are inserted at the root
2618 // this gives us problems as we have erratic redraws even over the structure
2621 m_sbHorizontal
= 0 ;
2623 m_lastHorizontalValue
= 0 ;
2624 m_lastVerticalValue
= 0 ;
2626 Rect sb
= { 0 , 0 , 0 , 0 } ;
2627 if ( frameOptions
& kTXNWantVScrollBarMask
)
2629 CreateScrollBarControl( m_txnWindow
, &sb
, 0 , 0 , 100 , 1 , true , gTXNScrollActionProc
, &m_sbVertical
) ;
2630 SetControlReference( m_sbVertical
, (SInt32
) this ) ;
2631 SetControlAction( m_sbVertical
, gTXNScrollActionProc
);
2632 ShowControl( m_sbVertical
) ;
2633 EmbedControl( m_sbVertical
, m_controlRef
) ;
2634 frameOptions
&= ~kTXNWantVScrollBarMask
;
2636 if ( frameOptions
& kTXNWantHScrollBarMask
)
2638 CreateScrollBarControl( m_txnWindow
, &sb
, 0 , 0 , 100 , 1 , true , gTXNScrollActionProc
, &m_sbHorizontal
) ;
2639 SetControlReference( m_sbHorizontal
, (SInt32
) this ) ;
2640 SetControlAction( m_sbHorizontal
, gTXNScrollActionProc
);
2641 ShowControl( m_sbHorizontal
) ;
2642 EmbedControl( m_sbHorizontal
, m_controlRef
) ;
2643 frameOptions
&= ~(kTXNWantHScrollBarMask
| kTXNDrawGrowIconMask
);
2648 verify_noerr(TXNNewObject(NULL
, m_txnWindow
, &bounds
,
2650 kTXNTextEditStyleFrameType
,
2652 kTXNSystemDefaultEncoding
,
2653 &m_txn
, &m_txnFrameID
, NULL
) );
2655 TXNCarbonEventInfo cInfo ;
2657 cInfo.useCarbonEvents = false ;
2660 cInfo.fDictionary = NULL ;
2662 TXNControlTag iControlTags[] =
2664 kTXNUseCarbonEvents ,
2666 TXNControlData iControlData[] =
2671 int toptag = WXSIZEOF( iControlTags ) ;
2673 verify_noerr( TXNSetTXNObjectControls( m_txn, false , toptag,
2674 iControlTags, iControlData )) ;
2677 #ifdef __WXMAC_OSX__
2678 TXNRegisterScrollInfoProc( m_txn
, gTXNScrollInfoProc
, (SInt32
) this);
2681 SetGWorld( origPort
, origDev
) ;
2685 // ----------------------------------------------------------------------------
2686 // MLTE control implementation (OSX part)
2687 // ----------------------------------------------------------------------------
2689 #if TARGET_API_MAC_OSX
2691 #if MAC_OS_X_VERSION_MAX_ALLOWED > MAC_OS_X_VERSION_10_2
2693 wxMacMLTEHIViewControl::wxMacMLTEHIViewControl( wxTextCtrl
*wxPeer
,
2694 const wxString
& str
,
2696 const wxSize
& size
, long style
) : wxMacMLTEControl( wxPeer
)
2698 m_font
= wxPeer
->GetFont() ;
2699 m_windowStyle
= style
;
2700 Rect bounds
= wxMacGetBoundsForControl( wxPeer
, pos
, size
) ;
2702 wxMacConvertNewlines10To13( &st
) ;
2704 HIRect hr
= { bounds
.left
, bounds
.top
, bounds
.right
- bounds
.left
, bounds
.bottom
- bounds
.top
} ;
2706 m_scrollView
= NULL
;
2707 TXNFrameOptions frameOptions
= FrameOptionsFromWXStyle( style
) ;
2708 if ( frameOptions
& (kTXNWantVScrollBarMask
|kTXNWantHScrollBarMask
) )
2710 HIScrollViewCreate(( frameOptions
& kTXNWantHScrollBarMask
? kHIScrollViewOptionsHorizScroll
: 0) |
2711 ( frameOptions
& kTXNWantVScrollBarMask
? kHIScrollViewOptionsVertScroll
: 0 ) , &m_scrollView
) ;
2713 HIViewSetFrame( m_scrollView
, &hr
);
2714 HIViewSetVisible( m_scrollView
, true );
2718 HITextViewCreate( NULL
, 0, frameOptions
, &m_textView
) ;
2719 m_txn
= HITextViewGetTXNObject( m_textView
) ;
2720 HIViewSetVisible( m_textView
, true ) ;
2723 HIViewAddSubview( m_scrollView
, m_textView
) ;
2724 m_controlRef
= m_scrollView
;
2725 wxPeer
->MacInstallEventHandler( (WXWidget
) m_textView
) ;
2729 HIViewSetFrame( m_textView
, &hr
);
2730 m_controlRef
= m_textView
;
2733 AdjustCreationAttributes( *wxWHITE
, true ) ;
2735 wxMacWindowClipper
c( m_peer
) ;
2736 SetTXNData( st
, kTXNStartOffset
, kTXNEndOffset
) ;
2738 TXNSetSelection( m_txn
, 0, 0);
2739 TXNShowSelection( m_txn
, kTXNShowStart
);
2743 OSStatus
wxMacMLTEHIViewControl::SetFocus( ControlFocusPart focusPart
)
2745 return SetKeyboardFocus( GetControlOwner( m_textView
) ,
2746 m_textView
, focusPart
) ;
2749 bool wxMacMLTEHIViewControl::HasFocus() const
2751 ControlRef control
;
2752 GetKeyboardFocus( GetUserFocusWindow() , &control
) ;
2753 return control
== m_textView
;
2756 #endif // MAC_OS_X_VERSION_MAX_ALLOWED > MAC_OS_X_VERSION_10_2
2761 #endif // wxUSE_TEXTCTRL