1 /////////////////////////////////////////////////////////////////////////////
4 // Author: Stefan Csomor
5 // Modified by: Ryan Norton (MLTE GetLineLength and GetLineText)
8 // Copyright: (c) Stefan Csomor
9 // Licence: wxWindows licence
10 /////////////////////////////////////////////////////////////////////////////
12 #if defined(__GNUG__) && !defined(NO_GCC_PRAGMA)
13 #pragma implementation "textctrl.h"
16 #include "wx/wxprec.h"
22 #include <sys/types.h>
28 #include "wx/msgdlg.h"
30 #if wxUSE_STD_IOSTREAM
40 #include "wx/button.h"
41 #include "wx/toplevel.h"
42 #include "wx/textctrl.h"
43 #include "wx/notebook.h"
44 #include "wx/tabctrl.h"
45 #include "wx/settings.h"
46 #include "wx/filefn.h"
49 #if defined(__BORLANDC__) && !defined(__WIN32__)
51 #elif !defined(__MWERKS__) && !defined(__GNUWIN32) && !defined(__DARWIN__)
59 // if this is set to 1 then under OSX 10.2 the 'classic' MLTE implementation will be used
60 // if set to 0 then the unicode textctrl will be used
61 #ifndef wxMAC_AWAYS_USE_MLTE
62 #define wxMAC_AWAYS_USE_MLTE 1
65 #include <MacTextEditor.h>
66 #include <ATSUnicode.h>
67 #include <TextCommon.h>
68 #include <TextEncodingConverter.h>
69 #include "wx/mac/uma.h"
75 virtual ~wxMacFunctor() {}
76 virtual void* operator()() = 0 ;
77 static void* CallBackProc(void *param
)
79 wxMacFunctor
* f
= (wxMacFunctor
*) param
;
80 void *result
= (*f
)() ;
85 template<typename classtype
,typename param1type
>
86 class wxMacObjectFunctor1
: public wxMacFunctor
88 typedef void (classtype::*function
)( param1type p1
) ;
89 typedef void (classtype::*ref_function
)( const param1type
& p1
) ;
91 wxMacObjectFunctor1( classtype
*obj
, function f
, param1type p1
) :
99 wxMacObjectFunctor1( classtype
*obj
, ref_function f
, param1type p1
) :
107 ~wxMacObjectFunctor1() {}
109 virtual void* operator()()
111 (m_object
->*m_function
)(m_param1
) ;
115 classtype
* m_object
;
116 param1type m_param1
;
119 function m_function
;
120 ref_function m_refFunction
;
124 template<typename classtype
, typename param1type
>
125 void* wxMacMPRemoteCall( classtype
*object
, void (classtype::*function
)( param1type p1
) , param1type p1
)
127 wxMacObjectFunctor1
<classtype
,param1type
> params(object
,function
,p1
) ;
129 MPRemoteCall( wxMacFunctor::CallBackProc
, ¶ms
, kMPOwningProcessRemoteContext
) ;
133 template<typename classtype
, typename param1type
>
134 void* wxMacMPRemoteCall( classtype
*object
, void (classtype::*function
)( const param1type
& p1
) , param1type p1
)
136 wxMacObjectFunctor1
<classtype
,param1type
> params(object
,function
,p1
) ;
138 MPRemoteCall( wxMacFunctor::CallBackProc
, ¶ms
, kMPOwningProcessRemoteContext
) ;
142 template<typename classtype
, typename param1type
>
143 void* wxMacMPRemoteGUICall( classtype
*object
, void (classtype::*function
)( param1type p1
) , param1type p1
)
146 void *result
= wxMacMPRemoteCall( object
, function
, p1
) ;
151 template<typename classtype
, typename param1type
>
152 void* wxMacMPRemoteGUICall( classtype
*object
, void (classtype::*function
)( const param1type
& p1
) , param1type p1
)
155 void *result
= wxMacMPRemoteCall( object
, function
, p1
) ;
159 // common interface for all implementations
160 class wxMacTextControl
: public wxMacControl
164 ~wxMacTextControl() ;
166 virtual wxString
GetStringValue() const = 0 ;
167 virtual void SetStringValue( const wxString
&val
) = 0 ;
168 virtual void SetStyle(long start
, long end
, const wxTextAttr
& style
) ;
169 virtual void Copy() ;
171 virtual void Paste() ;
172 virtual bool CanPaste() const ;
173 virtual void SetEditable(bool editable
) ;
174 virtual wxTextPos
GetLastPosition() const ;
175 virtual void Replace( long from
, long to
, const wxString str
) ;
176 virtual void Remove( long from
, long to
) = 0 ;
177 virtual void SetSelection( long from
, long to
) = 0 ;
178 virtual void GetSelection( long* from
, long* to
) const = 0 ;
179 virtual void WriteText(const wxString
& str
) = 0 ;
181 virtual void Clear() ;
182 virtual bool CanUndo() const;
183 virtual void Undo() ;
184 virtual bool CanRedo() const;
185 virtual void Redo() ;
186 virtual int GetNumberOfLines() const ;
187 virtual long XYToPosition(long x
, long y
) const;
188 virtual bool PositionToXY(long pos
, long *x
, long *y
) const ;
189 virtual void ShowPosition( long WXUNUSED(pos
) ) ;
190 virtual int GetLineLength(long lineNo
) const ;
191 virtual wxString
GetLineText(long lineNo
) const ;
193 #ifndef __WXMAC_OSX__
194 virtual void MacControlUserPaneDrawProc(wxInt16 part
) = 0 ;
195 virtual wxInt16
MacControlUserPaneHitTestProc(wxInt16 x
, wxInt16 y
) = 0 ;
196 virtual wxInt16
MacControlUserPaneTrackingProc(wxInt16 x
, wxInt16 y
, void* actionProc
) = 0 ;
197 virtual void MacControlUserPaneIdleProc() = 0 ;
198 virtual wxInt16
MacControlUserPaneKeyDownProc(wxInt16 keyCode
, wxInt16 charCode
, wxInt16 modifiers
) = 0 ;
199 virtual void MacControlUserPaneActivateProc(bool activating
) = 0 ;
200 virtual wxInt16
MacControlUserPaneFocusProc(wxInt16 action
) = 0 ;
201 virtual void MacControlUserPaneBackgroundProc(void* info
) = 0 ;
205 // common parts for implementations based on MLTE
207 class wxMacMLTEControl
: public wxMacTextControl
210 virtual wxString
GetStringValue() const ;
211 virtual void SetStringValue( const wxString
&str
) ;
213 static TXNFrameOptions
FrameOptionsFromWXStyle( long wxStyle
) ;
214 void AdjustCreationAttributes( const wxColour
& background
, bool visible
) ;
216 virtual void SetFont( const wxFont
& font
, const wxColour
& foreground
, long windowStyle
) ;
217 virtual void SetBackground( const wxBrush
&brush
) ;
218 virtual void SetStyle(long start
, long end
, const wxTextAttr
& style
) ;
219 virtual void Copy() ;
221 virtual void Paste() ;
222 virtual bool CanPaste() const ;
223 virtual void SetEditable(bool editable
) ;
224 virtual wxTextPos
GetLastPosition() const ;
225 virtual void Replace( long from
, long to
, const wxString str
) ;
226 virtual void Remove( long from
, long to
) ;
227 virtual void GetSelection( long* from
, long* to
) const ;
228 virtual void SetSelection( long from
, long to
) ;
230 virtual void WriteText(const wxString
& str
) ;
231 virtual void Clear() ;
233 virtual bool CanUndo() const ;
234 virtual void Undo() ;
235 virtual bool CanRedo() const;
236 virtual void Redo() ;
237 virtual int GetNumberOfLines() const ;
238 virtual long XYToPosition(long x
, long y
) const ;
239 virtual bool PositionToXY(long pos
, long *x
, long *y
) const ;
240 virtual void ShowPosition( long pos
) ;
241 virtual int GetLineLength(long lineNo
) const ;
242 virtual wxString
GetLineText(long lineNo
) const ;
244 void SetTXNData( const wxString
& st
, TXNOffset start
, TXNOffset end
) ;
247 void TXNSetAttribute( const wxTextAttr
& style
, long from
, long to
) ;
251 #if TARGET_API_MAC_OSX
253 // implementation available under OSX
255 #if MAC_OS_X_VERSION_MAX_ALLOWED > MAC_OS_X_VERSION_10_2
257 class wxMacMLTEHIViewControl
: public wxMacMLTEControl
260 wxMacMLTEHIViewControl( wxWindow
*wxPeer
,
263 const wxSize
& size
, long style
) ;
264 virtual OSStatus
SetFocus( ControlFocusPart focusPart
) ;
265 virtual bool HasFocus() const ;
266 virtual bool NeedsFocusRect() const;
268 HIViewRef m_scrollView
;
269 HIViewRef m_textView
;
274 class wxMacUnicodeTextControl
: public wxMacTextControl
277 wxMacUnicodeTextControl( wxWindow
*wxPeer
,
280 const wxSize
& size
, long style
) ;
281 ~wxMacUnicodeTextControl();
282 virtual void VisibilityChanged(bool shown
);
283 virtual wxString
GetStringValue() const ;
284 virtual void SetStringValue( const wxString
&str
) ;
287 virtual void Paste();
288 virtual bool CanPaste() const;
289 virtual void SetEditable(bool editable
) ;
290 virtual void Remove( long from
, long to
) ;
291 virtual void GetSelection( long* from
, long* to
) const ;
292 virtual void SetSelection( long from
, long to
) ;
293 virtual void WriteText(const wxString
& str
) ;
295 // contains the tag for the content (is different for password and non-password controls)
301 // 'classic' MLTE implementation
303 class STPTextPaneVars
;
305 class wxMacMLTEClassicControl
: public wxMacMLTEControl
308 wxMacMLTEClassicControl( wxWindow
*wxPeer
,
311 const wxSize
& size
, long style
) ;
312 ~wxMacMLTEClassicControl() ;
313 virtual void VisibilityChanged(bool shown
) ;
314 virtual bool NeedsFocusRect() const;
316 virtual void MacControlUserPaneDrawProc(wxInt16 part
) ;
317 virtual wxInt16
MacControlUserPaneHitTestProc(wxInt16 x
, wxInt16 y
) ;
318 virtual wxInt16
MacControlUserPaneTrackingProc(wxInt16 x
, wxInt16 y
, void* actionProc
) ;
319 virtual void MacControlUserPaneIdleProc() ;
320 virtual wxInt16
MacControlUserPaneKeyDownProc(wxInt16 keyCode
, wxInt16 charCode
, wxInt16 modifiers
) ;
321 virtual void MacControlUserPaneActivateProc(bool activating
) ;
322 virtual wxInt16
MacControlUserPaneFocusProc(wxInt16 action
) ;
323 virtual void MacControlUserPaneBackgroundProc(void* info
) ;
328 // hack to make public until we have migrated all procs
329 STPTextPaneVars
* m_macTXNvars
;
332 #define TE_UNLIMITED_LENGTH 0xFFFFFFFFUL
334 #if !USE_SHARED_LIBRARY
335 IMPLEMENT_DYNAMIC_CLASS(wxTextCtrl
, wxControl
)
337 BEGIN_EVENT_TABLE(wxTextCtrl
, wxControl
)
338 EVT_ERASE_BACKGROUND( wxTextCtrl::OnEraseBackground
)
339 EVT_DROP_FILES(wxTextCtrl::OnDropFiles
)
340 EVT_CHAR(wxTextCtrl::OnChar
)
341 EVT_MENU(wxID_CUT
, wxTextCtrl::OnCut
)
342 EVT_MENU(wxID_COPY
, wxTextCtrl::OnCopy
)
343 EVT_MENU(wxID_PASTE
, wxTextCtrl::OnPaste
)
344 EVT_MENU(wxID_UNDO
, wxTextCtrl::OnUndo
)
345 EVT_MENU(wxID_REDO
, wxTextCtrl::OnRedo
)
347 EVT_UPDATE_UI(wxID_CUT
, wxTextCtrl::OnUpdateCut
)
348 EVT_UPDATE_UI(wxID_COPY
, wxTextCtrl::OnUpdateCopy
)
349 EVT_UPDATE_UI(wxID_PASTE
, wxTextCtrl::OnUpdatePaste
)
350 EVT_UPDATE_UI(wxID_UNDO
, wxTextCtrl::OnUpdateUndo
)
351 EVT_UPDATE_UI(wxID_REDO
, wxTextCtrl::OnUpdateRedo
)
356 void wxTextCtrl::Init()
361 m_maxLength
= TE_UNLIMITED_LENGTH
;
364 wxTextCtrl::~wxTextCtrl()
369 bool wxTextCtrl::Create(wxWindow
*parent
, wxWindowID id
,
372 const wxSize
& size
, long style
,
373 const wxValidator
& validator
,
374 const wxString
& name
)
376 m_macIsUserPane
= false ;
379 if ( ! ( style
& wxNO_BORDER
) )
380 style
= ( style
& ~wxBORDER_MASK
) | wxSUNKEN_BORDER
;
382 if ( !wxTextCtrlBase::Create(parent
, id
, pos
, size
, style
& ~(wxHSCROLL
|wxVSCROLL
), validator
, name
) )
385 Rect bounds
= wxMacGetBoundsForControl( this , pos
, size
) ;
387 if ( m_windowStyle
& wxTE_MULTILINE
)
389 wxASSERT_MSG( !(m_windowStyle
& wxTE_PROCESS_ENTER
),
390 wxT("wxTE_PROCESS_ENTER style is ignored for multiline text controls (they always process it)") );
392 m_windowStyle
|= wxTE_PROCESS_ENTER
;
393 style
|= wxTE_PROCESS_ENTER
;
397 #if MAC_OS_X_VERSION_MAX_ALLOWED > MAC_OS_X_VERSION_10_2
398 if ( UMAGetSystemVersion() >= 0x1030 )
400 m_peer
= new wxMacMLTEHIViewControl( this , str
, pos
, size
, style
) ;
403 #if !wxMAC_AWAYS_USE_MLTE
406 m_peer
= new wxMacUnicodeTextControl( this , str
, pos
, size
, style
) ;
412 // this control draws the border itself
413 if ( !HasFlag(wxNO_BORDER
) )
415 m_windowStyle
&= ~wxSUNKEN_BORDER
;
416 bounds
= wxMacGetBoundsForControl( this , pos
, size
) ;
418 m_peer
= new wxMacMLTEClassicControl( this , str
, pos
, size
, style
) ;
421 MacPostControlCreate(pos
,size
) ;
423 if ( m_windowStyle
& wxTE_READONLY
)
425 SetEditable( false ) ;
431 void wxTextCtrl::MacVisibilityChanged()
433 GetPeer()->VisibilityChanged( MacIsReallyShown() ) ;
436 void wxTextCtrl::MacEnabledStateChanged()
440 wxString
wxTextCtrl::GetValue() const
442 return GetPeer()->GetStringValue() ;
445 void wxTextCtrl::GetSelection(long* from
, long* to
) const
447 GetPeer()->GetSelection( from
, to
) ;
450 void wxTextCtrl::SetValue(const wxString
& str
)
453 if ( GetValue() == str
)
456 GetPeer()->SetStringValue(str
) ;
458 wxCommandEvent
event(wxEVT_COMMAND_TEXT_UPDATED
, m_windowId
);
459 event
.SetString( GetValue() ) ;
460 event
.SetEventObject( this );
461 GetEventHandler()->ProcessEvent(event
);
464 void wxTextCtrl::SetMaxLength(unsigned long len
)
469 bool wxTextCtrl::SetFont( const wxFont
& font
)
471 if ( !wxTextCtrlBase::SetFont( font
) )
474 GetPeer()->SetFont( font
, GetForegroundColour() , GetWindowStyle() ) ;
478 bool wxTextCtrl::SetStyle(long start
, long end
, const wxTextAttr
& style
)
480 GetPeer()->SetStyle( start
, end
, style
) ;
484 bool wxTextCtrl::SetDefaultStyle(const wxTextAttr
& style
)
486 wxTextCtrlBase::SetDefaultStyle( style
) ;
487 SetStyle( kTXNUseCurrentSelection
, kTXNUseCurrentSelection
, GetDefaultStyle() ) ;
491 // Clipboard operations
492 void wxTextCtrl::Copy()
500 void wxTextCtrl::Cut()
506 wxCommandEvent
event(wxEVT_COMMAND_TEXT_UPDATED
, m_windowId
);
507 event
.SetEventObject( this );
508 GetEventHandler()->ProcessEvent(event
);
512 void wxTextCtrl::Paste()
517 // eventually we should add setting the default style again
519 wxCommandEvent
event(wxEVT_COMMAND_TEXT_UPDATED
, m_windowId
);
520 event
.SetEventObject( this );
521 GetEventHandler()->ProcessEvent(event
);
525 bool wxTextCtrl::CanCopy() const
527 // Can copy if there's a selection
529 GetSelection(& from
, & to
);
533 bool wxTextCtrl::CanCut() const
539 // Can cut if there's a selection
541 GetSelection(& from
, & to
);
545 bool wxTextCtrl::CanPaste() const
550 return GetPeer()->CanPaste() ;
553 void wxTextCtrl::SetEditable(bool editable
)
555 if ( editable
!= m_editable
)
557 m_editable
= editable
;
558 GetPeer()->SetEditable( editable
) ;
562 void wxTextCtrl::SetInsertionPoint(long pos
)
564 SetSelection( pos
, pos
) ;
567 void wxTextCtrl::SetInsertionPointEnd()
569 wxTextPos pos
= GetLastPosition();
570 SetInsertionPoint(pos
);
573 long wxTextCtrl::GetInsertionPoint() const
576 GetSelection( &begin
, &end
) ;
580 wxTextPos
wxTextCtrl::GetLastPosition() const
582 return GetPeer()->GetLastPosition( ) ;
585 void wxTextCtrl::Replace(long from
, long to
, const wxString
& str
)
587 GetPeer()->Replace( from
, to
, str
) ;
590 void wxTextCtrl::Remove(long from
, long to
)
592 GetPeer()->Remove( from
, to
) ;
595 void wxTextCtrl::SetSelection(long from
, long to
)
597 GetPeer()->SetSelection( from
, to
) ;
600 bool wxTextCtrl::LoadFile(const wxString
& file
)
602 if ( wxTextCtrlBase::LoadFile(file
) )
610 void wxTextCtrl::WriteText(const wxString
& str
)
612 // TODO this MPRemoting will be moved into a remoting peer proxy for any command
613 if ( !wxIsMainThread() )
615 // unfortunately CW 8 is not able to correctly deduce the template types, so we have
616 // to instantiate explicitely
617 wxMacMPRemoteGUICall
<wxTextCtrl
,wxString
>( this , &wxTextCtrl::WriteText
, str
) ;
622 GetPeer()->WriteText( str
) ;
626 void wxTextCtrl::AppendText(const wxString
& text
)
628 SetInsertionPointEnd();
632 void wxTextCtrl::Clear()
637 bool wxTextCtrl::IsModified() const
642 bool wxTextCtrl::IsEditable() const
644 return IsEnabled() && m_editable
;
647 bool wxTextCtrl::AcceptsFocus() const
649 // we don't want focus if we can't be edited
650 return /*IsEditable() && */ wxControl::AcceptsFocus();
653 wxSize
wxTextCtrl::DoGetBestSize() const
659 // these are the numbers from the HIG, we reduce them by the borders
662 switch( m_windowVariant
)
664 case wxWINDOW_VARIANT_NORMAL
:
667 case wxWINDOW_VARIANT_SMALL
:
670 case wxWINDOW_VARIANT_MINI
:
678 // as the above numbers have some free space around the text
679 // we get 5 lines like this anyway
680 if ( m_windowStyle
& wxTE_MULTILINE
)
685 if ( !HasFlag(wxNO_BORDER
) )
688 return wxSize(wText
, hText
);
691 // ----------------------------------------------------------------------------
693 // ----------------------------------------------------------------------------
695 void wxTextCtrl::Undo()
703 void wxTextCtrl::Redo()
711 bool wxTextCtrl::CanUndo() const
717 return GetPeer()->CanUndo() ;
720 bool wxTextCtrl::CanRedo() const
726 return GetPeer()->CanRedo() ;
729 void wxTextCtrl::MarkDirty()
734 void wxTextCtrl::DiscardEdits()
739 int wxTextCtrl::GetNumberOfLines() const
741 return GetPeer()->GetNumberOfLines() ;
744 long wxTextCtrl::XYToPosition(long x
, long y
) const
746 return GetPeer()->XYToPosition( x
, y
) ;
749 bool wxTextCtrl::PositionToXY(long pos
, long *x
, long *y
) const
751 return GetPeer()->PositionToXY(pos
, x
, y
) ;
754 void wxTextCtrl::ShowPosition(long pos
)
756 return GetPeer()->ShowPosition(pos
) ;
759 int wxTextCtrl::GetLineLength(long lineNo
) const
761 return GetPeer()->GetLineLength(lineNo
) ;
764 wxString
wxTextCtrl::GetLineText(long lineNo
) const
766 return GetPeer()->GetLineText(lineNo
) ;
773 void wxTextCtrl::Command(wxCommandEvent
& event
)
775 SetValue (event
.GetString());
776 ProcessCommand (event
);
779 void wxTextCtrl::OnDropFiles(wxDropFilesEvent
& event
)
781 // By default, load the first file into the text window.
782 if (event
.GetNumberOfFiles() > 0)
784 LoadFile(event
.GetFiles()[0]);
788 void wxTextCtrl::OnEraseBackground(wxEraseEvent
& event
)
790 // all erasing should be done by the real mac control implementation
791 // while this is true for MLTE under classic, the HITextView is somehow
792 // transparent but background erase is not working correctly, so intercept
793 // things while we can...
797 void wxTextCtrl::OnChar(wxKeyEvent
& event
)
799 int key
= event
.GetKeyCode() ;
800 bool eat_key
= false ;
802 if ( key
== 'c' && event
.MetaDown() )
809 if ( !IsEditable() && key
!= WXK_LEFT
&& key
!= WXK_RIGHT
&& key
!= WXK_DOWN
&& key
!= WXK_UP
&& key
!= WXK_TAB
&&
810 !( key
== WXK_RETURN
&& ( (m_windowStyle
& wxPROCESS_ENTER
) || (m_windowStyle
& wxTE_MULTILINE
) ) )
811 /* && key != WXK_PRIOR && key != WXK_NEXT && key != WXK_HOME && key != WXK_END */
818 // Check if we have reached the max # of chars, but still allow navigation and deletion
819 if ( !IsMultiLine() && GetValue().Length() >= m_maxLength
&&
820 key
!= WXK_LEFT
&& key
!= WXK_RIGHT
&& key
!= WXK_TAB
&&
821 key
!= WXK_BACK
&& !( key
== WXK_RETURN
&& (m_windowStyle
& wxPROCESS_ENTER
) )
824 // eat it, we don't want to add more than allowed # of characters
828 // assume that any key not processed yet is going to modify the control
831 if ( key
== 'v' && event
.MetaDown() )
837 if ( key
== 'x' && event
.MetaDown() )
846 if (m_windowStyle
& wxPROCESS_ENTER
)
848 wxCommandEvent
event(wxEVT_COMMAND_TEXT_ENTER
, m_windowId
);
849 event
.SetEventObject( this );
850 event
.SetString( GetValue() );
851 if ( GetEventHandler()->ProcessEvent(event
) )
854 if ( !(m_windowStyle
& wxTE_MULTILINE
) )
856 wxWindow
*parent
= GetParent();
857 while( parent
&& !parent
->IsTopLevel() && parent
->GetDefaultItem() == NULL
) {
858 parent
= parent
->GetParent() ;
860 if ( parent
&& parent
->GetDefaultItem() )
862 wxButton
*def
= wxDynamicCast(parent
->GetDefaultItem(),
864 if ( def
&& def
->IsEnabled() )
866 wxCommandEvent
event(wxEVT_COMMAND_BUTTON_CLICKED
, def
->GetId() );
867 event
.SetEventObject(def
);
873 // this will make wxWidgets eat the ENTER key so that
874 // we actually prevent line wrapping in a single line
882 if ( !(m_windowStyle
& wxTE_PROCESS_TAB
))
885 if (!event
.ShiftDown())
886 flags
|= wxNavigationKeyEvent::IsForward
;
887 if (event
.ControlDown())
888 flags
|= wxNavigationKeyEvent::WinChange
;
894 // This is necessary (don't know why) or the tab will not
896 WriteText(wxT("\t"));
904 // perform keystroke handling
905 if ( wxTheApp
->MacGetCurrentEvent() != NULL
&& wxTheApp
->MacGetCurrentEventHandlerCallRef() != NULL
)
906 CallNextEventHandler((EventHandlerCallRef
)wxTheApp
->MacGetCurrentEventHandlerCallRef() , (EventRef
) wxTheApp
->MacGetCurrentEvent() ) ;
910 if ( wxMacConvertEventToRecord( (EventRef
) wxTheApp
->MacGetCurrentEvent() , &rec
) )
912 EventRecord
*ev
= &rec
;
915 keychar
= short(ev
->message
& charCodeMask
);
916 keycode
= short(ev
->message
& keyCodeMask
) >> 8 ;
918 m_peer
->HandleKey( keycode
, keychar
, ev
->modifiers
) ;
922 if ( ( key
>= 0x20 && key
< WXK_START
) ||
927 wxCommandEvent
event1(wxEVT_COMMAND_TEXT_UPDATED
, m_windowId
);
928 event1
.SetEventObject( this );
929 wxPostEvent(GetEventHandler(),event1
);
933 // ----------------------------------------------------------------------------
934 // standard handlers for standard edit menu events
935 // ----------------------------------------------------------------------------
937 void wxTextCtrl::OnCut(wxCommandEvent
& WXUNUSED(event
))
942 void wxTextCtrl::OnCopy(wxCommandEvent
& WXUNUSED(event
))
947 void wxTextCtrl::OnPaste(wxCommandEvent
& WXUNUSED(event
))
952 void wxTextCtrl::OnUndo(wxCommandEvent
& WXUNUSED(event
))
957 void wxTextCtrl::OnRedo(wxCommandEvent
& WXUNUSED(event
))
962 void wxTextCtrl::OnUpdateCut(wxUpdateUIEvent
& event
)
964 event
.Enable( CanCut() );
967 void wxTextCtrl::OnUpdateCopy(wxUpdateUIEvent
& event
)
969 event
.Enable( CanCopy() );
972 void wxTextCtrl::OnUpdatePaste(wxUpdateUIEvent
& event
)
974 event
.Enable( CanPaste() );
977 void wxTextCtrl::OnUpdateUndo(wxUpdateUIEvent
& event
)
979 event
.Enable( CanUndo() );
982 void wxTextCtrl::OnUpdateRedo(wxUpdateUIEvent
& event
)
984 event
.Enable( CanRedo() );
987 bool wxTextCtrl::MacSetupCursor( const wxPoint
& pt
)
991 #if !TARGET_API_MAC_OSX
993 // user pane implementation
995 void wxTextCtrl::MacControlUserPaneDrawProc(wxInt16 part
)
997 GetPeer()->MacControlUserPaneDrawProc( part
) ;
1000 wxInt16
wxTextCtrl::MacControlUserPaneHitTestProc(wxInt16 x
, wxInt16 y
)
1002 return GetPeer()->MacControlUserPaneHitTestProc( x
, y
) ;
1005 wxInt16
wxTextCtrl::MacControlUserPaneTrackingProc(wxInt16 x
, wxInt16 y
, void* actionProc
)
1007 return GetPeer()->MacControlUserPaneTrackingProc( x
, y
, actionProc
) ;
1010 void wxTextCtrl::MacControlUserPaneIdleProc()
1012 GetPeer()->MacControlUserPaneIdleProc( ) ;
1015 wxInt16
wxTextCtrl::MacControlUserPaneKeyDownProc(wxInt16 keyCode
, wxInt16 charCode
, wxInt16 modifiers
)
1017 return GetPeer()->MacControlUserPaneKeyDownProc( keyCode
, charCode
, modifiers
) ;
1020 void wxTextCtrl::MacControlUserPaneActivateProc(bool activating
)
1022 GetPeer()->MacControlUserPaneActivateProc( activating
) ;
1025 wxInt16
wxTextCtrl::MacControlUserPaneFocusProc(wxInt16 action
)
1027 return GetPeer()->MacControlUserPaneFocusProc( action
) ;
1030 void wxTextCtrl::MacControlUserPaneBackgroundProc(void* info
)
1032 GetPeer()->MacControlUserPaneBackgroundProc( info
) ;
1036 // ----------------------------------------------------------------------------
1037 // implementation base class
1038 // ----------------------------------------------------------------------------
1040 wxMacTextControl::wxMacTextControl()
1044 wxMacTextControl::~wxMacTextControl()
1048 void wxMacTextControl::SetStyle(long start
, long end
, const wxTextAttr
& style
)
1052 void wxMacTextControl::Copy()
1056 void wxMacTextControl::Cut()
1060 void wxMacTextControl::Paste()
1064 bool wxMacTextControl::CanPaste() const
1069 void wxMacTextControl::SetEditable(bool editable
)
1073 wxTextPos
wxMacTextControl::GetLastPosition() const
1075 return GetStringValue().Length() ;
1078 void wxMacTextControl::Replace( long from
, long to
, const wxString str
)
1082 void wxMacTextControl::Clear()
1084 SetStringValue( wxEmptyString
) ;
1087 bool wxMacTextControl::CanUndo() const
1092 void wxMacTextControl::Undo() { }
1094 bool wxMacTextControl::CanRedo() const
1099 void wxMacTextControl::Redo()
1103 long wxMacTextControl::XYToPosition(long x
, long y
) const
1108 bool wxMacTextControl::PositionToXY(long pos
, long *x
, long *y
) const
1113 void wxMacTextControl::ShowPosition( long WXUNUSED(pos
) )
1117 int wxMacTextControl::GetNumberOfLines() const
1119 ItemCount lines
= 0 ;
1120 wxString content
= GetStringValue() ;
1122 for (size_t i
= 0; i
< content
.Length() ; i
++)
1124 if (content
[i
] == '\r') lines
++;
1129 wxString
wxMacTextControl::GetLineText(long lineNo
) const
1131 // TODO change this if possible to reflect real lines
1132 wxString content
= GetStringValue() ;
1136 for (size_t i
= 0; i
< content
.Length() ; i
++)
1138 if (count
== lineNo
)
1140 // Add chars in line then
1143 for (size_t j
= i
; j
< content
.Length(); j
++)
1145 if (content
[j
] == '\n')
1153 if (content
[i
] == '\n') count
++;
1155 return wxEmptyString
;
1158 int wxMacTextControl::GetLineLength(long lineNo
) const
1160 // TODO change this if possible to reflect real lines
1161 wxString content
= GetStringValue() ;
1165 for (size_t i
= 0; i
< content
.Length() ; i
++)
1167 if (count
== lineNo
)
1169 // Count chars in line then
1171 for (size_t j
= i
; j
< content
.Length(); j
++)
1174 if (content
[j
] == '\n') return count
;
1179 if (content
[i
] == '\n') count
++;
1184 // ----------------------------------------------------------------------------
1185 // standard unicode control implementation
1186 // ----------------------------------------------------------------------------
1188 #if TARGET_API_MAC_OSX
1190 wxMacUnicodeTextControl::wxMacUnicodeTextControl( wxWindow
*wxPeer
,
1191 const wxString
& str
,
1193 const wxSize
& size
, long style
)
1195 m_font
= wxPeer
->GetFont() ;
1196 m_windowStyle
= style
;
1197 Rect bounds
= wxMacGetBoundsForControl( wxPeer
, pos
, size
) ;
1199 wxMacConvertNewlines10To13( &st
) ;
1200 wxMacCFStringHolder
cf(st
, m_font
.GetEncoding()) ;
1201 CFStringRef cfr
= cf
;
1202 Boolean isPassword
= ( m_windowStyle
& wxTE_PASSWORD
) != 0 ;
1203 m_valueTag
= isPassword
? kControlEditTextPasswordCFStringTag
: kControlEditTextCFStringTag
;
1204 CreateEditUnicodeTextControl( MAC_WXHWND(wxPeer
->MacGetTopLevelWindowRef()), &bounds
, cfr
, isPassword
, NULL
, &m_controlRef
) ;
1206 if ( !(m_windowStyle
& wxTE_MULTILINE
) )
1208 SetData
<Boolean
>( kControlEditTextPart
, kControlEditTextSingleLineTag
, true ) ;
1212 wxMacUnicodeTextControl::~wxMacUnicodeTextControl()
1216 void wxMacUnicodeTextControl::VisibilityChanged(bool shown
)
1218 if ( !(m_windowStyle
& wxTE_MULTILINE
) && shown
)
1220 // work around a refresh issue insofar as not always the entire content is shown even if this would be possible
1221 ControlEditTextSelectionRec sel
;
1222 CFStringRef value
= NULL
;
1224 verify_noerr( GetData
<ControlEditTextSelectionRec
>( 0, kControlEditTextSelectionTag
, &sel
) );
1225 verify_noerr( GetData
<CFStringRef
>( 0, m_valueTag
, &value
) );
1226 verify_noerr( SetData
<CFStringRef
>( 0, m_valueTag
, &value
) );
1227 verify_noerr( SetData
<ControlEditTextSelectionRec
>( 0, kControlEditTextSelectionTag
, &sel
) );
1229 CFRelease( value
) ;
1232 wxString
wxMacUnicodeTextControl::GetStringValue() const
1235 CFStringRef value
= GetData
<CFStringRef
>(0,m_valueTag
) ;
1238 wxMacCFStringHolder
cf(value
) ;
1239 result
= cf
.AsString() ;
1242 wxMacConvertNewlines13To10( &result
) ;
1244 wxMacConvertNewlines10To13( &result
) ;
1248 void wxMacUnicodeTextControl::SetStringValue( const wxString
&str
)
1251 wxMacConvertNewlines10To13( &st
) ;
1252 wxMacCFStringHolder
cf(st
, m_font
.GetEncoding() ) ;
1253 verify_noerr( SetData
<CFStringRef
>( 0, m_valueTag
, cf
) ) ;
1255 void wxMacUnicodeTextControl::Copy()
1257 SendHICommand( kHICommandCopy
) ;
1259 void wxMacUnicodeTextControl::Cut()
1261 SendHICommand( kHICommandCut
) ;
1263 void wxMacUnicodeTextControl::Paste()
1265 SendHICommand( kHICommandPaste
) ;
1267 bool wxMacUnicodeTextControl::CanPaste() const
1271 void wxMacUnicodeTextControl::SetEditable(bool editable
)
1273 SetData
<Boolean
>( 0 , kControlEditTextLockedTag
, (Boolean
) !editable
) ;
1275 void wxMacUnicodeTextControl::Remove( long from
, long to
)
1279 void wxMacUnicodeTextControl::GetSelection( long* from
, long* to
) const
1281 ControlEditTextSelectionRec sel
;
1282 verify_noerr(GetData
<ControlEditTextSelectionRec
>( 0, kControlEditTextSelectionTag
, &sel
) ) ;
1283 if ( from
) *from
= sel
.selStart
;
1284 if ( to
) *to
= sel
.selEnd
;
1287 void wxMacUnicodeTextControl::SetSelection( long from
, long to
)
1289 ControlEditTextSelectionRec sel
;
1290 sel
.selStart
= from
;
1292 SetData
<ControlEditTextSelectionRec
>( 0 , kControlEditTextSelectionTag
, &sel
) ;
1295 void wxMacUnicodeTextControl::WriteText(const wxString
& str
)
1298 wxMacConvertNewlines10To13( &st
) ;
1299 #if MAC_OS_X_VERSION_MAX_ALLOWED > MAC_OS_X_VERSION_10_2
1300 wxMacCFStringHolder
cf(st
, m_font
.GetEncoding() ) ;
1301 CFStringRef value
= cf
;
1302 SetData
<CFStringRef
>( 0, kControlEditTextInsertCFStringRefTag
, &value
);
1304 wxString val
= GetStringValue() ;
1306 GetSelection( &start
, &end
) ;
1307 val
.Remove( start
, end
- start
) ;
1308 val
.insert( start
, str
) ;
1309 SetStringValue( val
) ;
1310 SetSelection( start
+ str
.Length() , start
+ str
.Length() ) ;
1316 // ----------------------------------------------------------------------------
1317 // MLTE control implementation (common part)
1318 // ----------------------------------------------------------------------------
1320 #if TARGET_API_MAC_OSX == 0
1321 // declaration needed because of one line in the code...
1322 static void TPUpdateVisibility(ControlRef theControl
) ;
1325 // if mlte is on read only , no changes at all are allowed, not even from
1326 // procedural API, in order to allow changes via API all the same we must undo
1327 // the readonly status while we are executing, this class helps to do so
1332 EditHelper( TXNObject txn
)
1334 TXNControlTag tag
[] = { kTXNIOPrivilegesTag
} ;
1336 TXNGetTXNObjectControls( m_txn
, 1 , tag
, m_data
) ;
1337 if ( m_data
[0].uValue
== kTXNReadOnly
)
1339 TXNControlData data
[] = { { kTXNReadWrite
} } ;
1340 TXNSetTXNObjectControls( m_txn
, false , 1 , tag
, data
) ;
1345 TXNControlTag tag
[] = { kTXNIOPrivilegesTag
} ;
1346 if ( m_data
[0].uValue
== kTXNReadOnly
)
1348 TXNSetTXNObjectControls( m_txn
, false , 1 , tag
, m_data
) ;
1353 TXNControlData m_data
[1] ;
1356 wxString
wxMacMLTEControl::GetStringValue() const
1360 Size actualSize
= 0;
1364 err
= TXNGetDataEncoded( m_txn
, kTXNStartOffset
, kTXNEndOffset
, &theText
, kTXNUnicodeTextData
);
1372 actualSize
= GetHandleSize( theText
) / sizeof( UniChar
) ;
1373 if ( actualSize
> 0 )
1375 wxChar
*ptr
= NULL
;
1376 #if SIZEOF_WCHAR_T == 2
1377 ptr
= new wxChar
[actualSize
+ 1 ] ;
1378 wxStrncpy( ptr
, (wxChar
*) *theText
, actualSize
) ;
1380 SetHandleSize( theText
, ( actualSize
+ 1 ) * sizeof( UniChar
) ) ;
1382 (((UniChar
*)*theText
)[actualSize
]) = 0 ;
1383 wxMBConvUTF16BE converter
;
1384 size_t noChars
= converter
.MB2WC( NULL
, (const char*)*theText
, 0 ) ;
1385 ptr
= new wxChar
[noChars
+ 1] ;
1387 noChars
= converter
.MB2WC( ptr
, (const char*)*theText
, noChars
) ;
1389 HUnlock( theText
) ;
1391 ptr
[actualSize
] = 0 ;
1392 result
= wxString( ptr
) ;
1395 DisposeHandle( theText
) ;
1399 err
= TXNGetDataEncoded( m_txn
, kTXNStartOffset
, kTXNEndOffset
, &theText
, kTXNTextData
);
1407 actualSize
= GetHandleSize( theText
) ;
1408 if ( actualSize
> 0 )
1411 result
= wxString( *theText
, wxConvLocal
, actualSize
) ;
1412 HUnlock( theText
) ;
1414 DisposeHandle( theText
) ;
1419 wxMacConvertNewlines13To10( &result
) ;
1421 wxMacConvertNewlines10To13( &result
) ;
1426 void wxMacMLTEControl::SetStringValue( const wxString
&str
)
1430 wxMacConvertNewlines10To13( &st
) ;
1431 EditHelper
help(m_txn
) ;
1433 // wxMacWindowClipper c( this ) ;
1434 #if !TARGET_API_MAC_OSX
1435 // otherwise scrolling might have problems ?
1436 TPUpdateVisibility( m_controlRef
) ;
1438 SetTXNData( st
, kTXNStartOffset
, kTXNEndOffset
) ;
1439 TXNSetSelection( m_txn
, 0, 0);
1440 TXNShowSelection( m_txn
, kTXNShowStart
);
1443 TXNFrameOptions
wxMacMLTEControl::FrameOptionsFromWXStyle( long wxStyle
)
1445 TXNFrameOptions frameOptions
=
1446 kTXNDontDrawCaretWhenInactiveMask
;
1447 if ( ! ( wxStyle
& wxTE_NOHIDESEL
) )
1448 frameOptions
|= kTXNDontDrawSelectionWhenInactiveMask
;
1450 if ( wxStyle
& wxTE_MULTILINE
)
1452 if ( ! ( wxStyle
& wxTE_DONTWRAP
) )
1453 frameOptions
|= kTXNAlwaysWrapAtViewEdgeMask
;
1456 frameOptions
|= kTXNAlwaysWrapAtViewEdgeMask
;
1457 frameOptions
|= kTXNWantHScrollBarMask
;
1460 if ( !(wxStyle
& wxTE_NO_VSCROLL
) )
1461 frameOptions
|= kTXNWantVScrollBarMask
;
1464 frameOptions
|= kTXNSingleLineOnlyMask
;
1466 if ( wxStyle
& wxHSCROLL
)
1467 frameOptions
|= kTXNWantHScrollBarMask
;
1469 return frameOptions
;
1472 void wxMacMLTEControl::AdjustCreationAttributes( const wxColour
&background
, bool visible
)
1474 TXNControlTag iControlTags
[3] = { kTXNDoFontSubstitution
, kTXNWordWrapStateTag
};
1475 TXNControlData iControlData
[3] = { {false}, {kTXNNoAutoWrap
} };
1477 #if TARGET_API_MAC_OSX
1478 iControlTags
[2] = kTXNVisibilityTag
;
1479 iControlData
[2].uValue
= visible
;
1483 if ( m_windowStyle
& wxTE_MULTILINE
)
1485 if (m_windowStyle
& wxTE_DONTWRAP
)
1486 iControlData
[1].uValue
= kTXNNoAutoWrap
;
1488 iControlData
[1].uValue
= kTXNAutoWrap
;
1490 verify_noerr( TXNSetTXNObjectControls( m_txn
, false, toptag
,
1491 iControlTags
, iControlData
)) ;
1493 // setting the default font
1499 GetThemeFont(kThemeSystemFont
, GetApplicationScript() , fontName
, &fontSize
, &fontStyle
) ;
1501 TXNTypeAttributes typeAttr
[] =
1503 { kTXNQDFontNameAttribute
, kTXNQDFontNameAttributeSize
, { (void*) fontName
} } ,
1504 { kTXNQDFontSizeAttribute
, kTXNFontSizeAttributeSize
, { (void*) (fontSize
<< 16) } } ,
1505 { kTXNQDFontStyleAttribute
, kTXNQDFontStyleAttributeSize
, { (void*) normal
} } ,
1508 verify_noerr( TXNSetTypeAttributes (m_txn
, sizeof( typeAttr
) / sizeof(TXNTypeAttributes
) , typeAttr
,
1512 if ( m_windowStyle
& wxTE_PASSWORD
)
1515 verify_noerr(TXNEchoMode( m_txn
, c
, 0 , true )) ;
1518 TXNBackground tback
;
1519 tback
.bgType
= kTXNBackgroundTypeRGB
;
1520 tback
.bg
.color
= MAC_WXCOLORREF( background
.GetPixel() );
1521 TXNSetBackground( m_txn
, &tback
);
1524 void wxMacMLTEControl::SetBackground( const wxBrush
&brush
)
1526 // currently only solid background are supported
1527 TXNBackground tback
;
1528 tback
.bgType
= kTXNBackgroundTypeRGB
;
1529 tback
.bg
.color
= MAC_WXCOLORREF( brush
.GetColour().GetPixel() );
1530 TXNSetBackground( m_txn
, &tback
);
1533 void wxMacMLTEControl::TXNSetAttribute( const wxTextAttr
& style
, long from
, long to
)
1535 TXNTypeAttributes typeAttr
[4] ;
1536 Str255 fontName
= "\pMonaco" ;
1537 SInt16 fontSize
= 12 ;
1538 Style fontStyle
= normal
;
1540 int attrCounter
= 0 ;
1541 if ( style
.HasFont() )
1543 const wxFont
&font
= style
.GetFont() ;
1544 wxMacStringToPascal( font
.GetFaceName() , fontName
) ;
1545 fontSize
= font
.GetPointSize() ;
1546 if ( font
.GetUnderlined() )
1547 fontStyle
|= underline
;
1548 if ( font
.GetWeight() == wxBOLD
)
1550 if ( font
.GetStyle() == wxITALIC
)
1551 fontStyle
|= italic
;
1553 typeAttr
[attrCounter
].tag
= kTXNQDFontNameAttribute
;
1554 typeAttr
[attrCounter
].size
= kTXNQDFontNameAttributeSize
;
1555 typeAttr
[attrCounter
].data
.dataPtr
= (void*) fontName
;
1556 typeAttr
[attrCounter
+1].tag
= kTXNQDFontSizeAttribute
;
1557 typeAttr
[attrCounter
+1].size
= kTXNFontSizeAttributeSize
;
1558 typeAttr
[attrCounter
+1].data
.dataValue
= (fontSize
<< 16) ;
1559 typeAttr
[attrCounter
+2].tag
= kTXNQDFontStyleAttribute
;
1560 typeAttr
[attrCounter
+2].size
= kTXNQDFontStyleAttributeSize
;
1561 typeAttr
[attrCounter
+2].data
.dataValue
= fontStyle
;
1564 if ( style
.HasTextColour() )
1566 typeAttr
[attrCounter
].tag
= kTXNQDFontColorAttribute
;
1567 typeAttr
[attrCounter
].size
= kTXNQDFontColorAttributeSize
;
1568 typeAttr
[attrCounter
].data
.dataPtr
= (void*) &color
;
1569 color
= MAC_WXCOLORREF(style
.GetTextColour().GetPixel()) ;
1572 if ( attrCounter
> 0 )
1574 verify_noerr( TXNSetTypeAttributes ( m_txn
, attrCounter
, typeAttr
, from
, to
) );
1578 void wxMacMLTEControl::SetFont( const wxFont
& font
, const wxColour
& foreground
, long windowStyle
)
1580 EditHelper
help(m_txn
) ;
1581 TXNSetAttribute( wxTextAttr(foreground
,wxNullColour
,font
) , kTXNStartOffset
,kTXNEndOffset
) ;
1583 void wxMacMLTEControl::SetStyle(long start
, long end
, const wxTextAttr
& style
)
1585 EditHelper
help(m_txn
) ;
1586 TXNSetAttribute( style
, start
,end
) ;
1589 void wxMacMLTEControl::Copy()
1591 ClearCurrentScrap();
1593 TXNConvertToPublicScrap();
1596 void wxMacMLTEControl::Cut()
1598 ClearCurrentScrap();
1600 TXNConvertToPublicScrap();
1603 void wxMacMLTEControl::Paste()
1605 TXNConvertFromPublicScrap();
1609 bool wxMacMLTEControl::CanPaste() const
1611 return TXNIsScrapPastable() ;
1614 void wxMacMLTEControl::SetEditable(bool editable
)
1616 TXNControlTag tag
[] = { kTXNIOPrivilegesTag
} ;
1617 TXNControlData data
[] = { { editable
? kTXNReadWrite
: kTXNReadOnly
} } ;
1618 TXNSetTXNObjectControls( m_txn
, false , sizeof(tag
) / sizeof (TXNControlTag
) , tag
, data
) ;
1621 wxTextPos
wxMacMLTEControl::GetLastPosition() const
1623 wxTextPos actualsize
= 0 ;
1626 OSErr err
= TXNGetDataEncoded( m_txn
, kTXNStartOffset
, kTXNEndOffset
, &theText
, kTXNTextData
);
1634 actualsize
= GetHandleSize( theText
) ;
1635 DisposeHandle( theText
) ;
1641 void wxMacMLTEControl::Replace( long from
, long to
, const wxString str
)
1643 wxString value
= str
;
1644 wxMacConvertNewlines10To13( &value
) ;
1646 EditHelper
help( m_txn
) ;
1648 TXNSetSelection(m_txn
, from
, to
) ;
1650 SetTXNData( value
, kTXNUseCurrentSelection
, kTXNUseCurrentSelection
) ;
1653 void wxMacMLTEControl::Remove( long from
, long to
)
1655 EditHelper
help( m_txn
) ;
1657 TXNSetSelection(m_txn
, from
, to
) ;
1661 void wxMacMLTEControl::GetSelection( long* from
, long* to
) const
1663 TXNGetSelection( m_txn
, (TXNOffset
*) from
, (TXNOffset
*) to
) ;
1666 void wxMacMLTEControl::SetSelection( long from
, long to
)
1668 /* change the selection */
1669 if ((from
== -1) && (to
== -1))
1670 TXNSelectAll(m_txn
);
1672 TXNSetSelection( m_txn
, from
, to
);
1673 TXNShowSelection( m_txn
, kTXNShowStart
);
1676 void wxMacMLTEControl::WriteText(const wxString
& str
)
1678 EditHelper
helper( m_txn
) ;
1680 wxMacConvertNewlines10To13( &st
) ;
1682 long start
, end
, dummy
;
1683 GetSelection( &start
, &dummy
) ;
1684 SetTXNData( st
, kTXNUseCurrentSelection
, kTXNUseCurrentSelection
) ;
1685 GetSelection( &dummy
, &end
) ;
1686 // TODO SetStyle( start , end , GetDefaultStyle() ) ;
1689 void wxMacMLTEControl::Clear()
1691 EditHelper
st(m_txn
) ;
1692 TXNSetSelection( m_txn
, kTXNStartOffset
, kTXNEndOffset
) ;
1696 bool wxMacMLTEControl::CanUndo() const
1698 return TXNCanUndo( m_txn
, NULL
) ;
1701 void wxMacMLTEControl::Undo()
1706 bool wxMacMLTEControl::CanRedo() const
1708 return TXNCanRedo( m_txn
, NULL
) ;
1711 void wxMacMLTEControl::Redo()
1716 int wxMacMLTEControl::GetNumberOfLines() const
1718 ItemCount lines
= 0 ;
1719 TXNGetLineCount(m_txn
, &lines
) ;
1723 long wxMacMLTEControl::XYToPosition(long x
, long y
) const
1727 wxTextPos lastpos
= GetLastPosition() ;
1729 // TODO find a better implementation : while we can get the
1730 // line metrics of a certain line, we don't get its starting
1731 // position, so it would probably be rather a binary search
1732 // for the start position
1735 int lastHeight
= 0 ;
1738 for ( n
= 0 ; n
<= (ItemCount
) lastpos
; ++n
)
1740 if ( y
== ypos
&& x
== xpos
)
1743 TXNOffsetToPoint( m_txn
, n
, &curpt
);
1745 if ( curpt
.v
> lastHeight
)
1750 lastHeight
= curpt
.v
;
1758 bool wxMacMLTEControl::PositionToXY(long pos
, long *x
, long *y
) const
1762 wxTextPos lastpos
= GetLastPosition() ;
1767 if ( pos
<= lastpos
)
1769 // TODO find a better implementation : while we can get the
1770 // line metrics of a certain line, we don't get its starting
1771 // position, so it would probably be rather a binary search
1772 // for the start position
1775 int lastHeight
= 0 ;
1778 for ( n
= 0 ; n
<= (ItemCount
) pos
; ++n
)
1780 TXNOffsetToPoint(m_txn
, n
, &curpt
);
1782 if ( curpt
.v
> lastHeight
)
1787 lastHeight
= curpt
.v
;
1792 if ( y
) *y
= ypos
;
1793 if ( x
) *x
= xpos
;
1799 void wxMacMLTEControl::ShowPosition( long pos
)
1801 #if TARGET_RT_MAC_MACHO && defined(AVAILABLE_MAC_OS_X_VERSION_10_2_AND_LATER)
1805 TXNOffset selstart
, selend
;
1806 TXNGetSelection( m_txn
, &selstart
, &selend
) ;
1807 TXNOffsetToPoint( m_txn
, selstart
, ¤t
);
1808 TXNOffsetToPoint( m_txn
, pos
, &desired
);
1809 //TODO use HIPoints for 10.3 and above
1810 if ( (UInt32
) TXNScroll
!= (UInt32
) kUnresolvedCFragSymbolAddress
)
1812 OSErr theErr
= noErr
;
1813 SInt32 dv
= desired
.v
- current
.v
;
1814 SInt32 dh
= desired
.h
- current
.h
;
1815 TXNShowSelection( m_txn
, true ) ;
1816 theErr
= TXNScroll( m_txn
, kTXNScrollUnitsInPixels
, kTXNScrollUnitsInPixels
, &dv
, &dh
);
1817 wxASSERT_MSG( theErr
== noErr
, _T("TXNScroll returned an error!") );
1823 void wxMacMLTEControl::SetTXNData( const wxString
& st
, TXNOffset start
, TXNOffset end
)
1826 #if SIZEOF_WCHAR_T == 2
1827 size_t len
= st
.Len() ;
1828 TXNSetData( m_txn
, kTXNUnicodeTextData
, (void*)st
.wc_str(), len
* 2,
1831 wxMBConvUTF16BE converter
;
1832 ByteCount byteBufferLen
= converter
.WC2MB( NULL
, st
.wc_str() , 0 ) ;
1833 UniChar
*unibuf
= (UniChar
*) malloc(byteBufferLen
) ;
1834 converter
.WC2MB( (char*) unibuf
, st
.wc_str() , byteBufferLen
) ;
1835 TXNSetData( m_txn
, kTXNUnicodeTextData
, (void*)unibuf
, byteBufferLen
,
1840 wxCharBuffer text
= st
.mb_str(wxConvLocal
) ;
1841 TXNSetData( m_txn
, kTXNTextData
, (void*)text
.data(), strlen( text
) ,
1847 wxString
wxMacMLTEControl::GetLineText(long lineNo
) const
1851 if ( lineNo
< GetNumberOfLines() )
1859 // get the first possible position in the control
1861 TXNOffsetToPoint(m_txn
, 0, &firstPoint
);
1863 // Iterate through the lines until we reach the one we want,
1864 // adding to our current y pixel point position
1865 while (ypos
< lineNo
)
1867 TXNGetLineMetrics(m_txn
, ypos
++, &lineWidth
, &lineHeight
);
1868 currentHeight
+= lineHeight
;
1871 Point thePoint
= { firstPoint
.v
+ (currentHeight
>> 16), firstPoint
.h
+ (0) };
1872 TXNOffset theOffset
;
1873 TXNPointToOffset(m_txn
, thePoint
, &theOffset
);
1875 wxString content
= GetStringValue() ;
1876 Point currentPoint
= thePoint
;
1877 while(thePoint
.v
== currentPoint
.v
&& theOffset
< content
.length())
1879 line
+= content
[theOffset
];
1880 TXNOffsetToPoint(m_txn
, ++theOffset
, ¤tPoint
);
1886 int wxMacMLTEControl::GetLineLength(long lineNo
) const
1890 if ( lineNo
< GetNumberOfLines() )
1898 // get the first possible position in the control
1900 TXNOffsetToPoint(m_txn
, 0, &firstPoint
);
1902 // Iterate through the lines until we reach the one we want,
1903 // adding to our current y pixel point position
1904 while (ypos
< lineNo
)
1906 TXNGetLineMetrics(m_txn
, ypos
++, &lineWidth
, &lineHeight
);
1907 currentHeight
+= lineHeight
;
1910 Point thePoint
= { firstPoint
.v
+ (currentHeight
>> 16), firstPoint
.h
+ (0) };
1911 TXNOffset theOffset
;
1912 TXNPointToOffset(m_txn
, thePoint
, &theOffset
);
1914 wxString content
= GetStringValue() ;
1915 Point currentPoint
= thePoint
;
1916 while(thePoint
.v
== currentPoint
.v
&& theOffset
< content
.length())
1919 TXNOffsetToPoint(m_txn
, ++theOffset
, ¤tPoint
);
1926 // ----------------------------------------------------------------------------
1927 // MLTE control implementation (classic part)
1928 // ----------------------------------------------------------------------------
1930 // CS:TODO we still have a problem getting properly at the text events of a control because under Carbon
1931 // the MLTE engine registers itself for the key events thus the normal flow never occurs, the only measure for the
1932 // moment is to avoid setting the true focus on the control, the proper solution at the end would be to have
1933 // an alternate path for carbon key events that routes automatically into the same wx flow of events
1937 /* kmUPTextPart is the part code we return to indicate the user has clicked
1938 in the text area of our control */
1939 #define kmUPTextPart 1
1942 /* routines for using existing user pane controls.
1943 These routines are useful for cases where you would like to use an
1944 existing user pane control in, say, a dialog window as a scrolling
1947 /* Utility Routines */
1949 /* kUserClickedToFocusPart is a part code we pass to the SetKeyboardFocus
1950 routine. In our focus switching routine this part code is understood
1951 as meaning 'the user has clicked in the control and we need to switch
1952 the current focus to ourselves before we can continue'. */
1953 #define kUserClickedToFocusPart 100
1955 /* STPTextPaneVars is a structure used for storing the the mUP Control's
1956 internal variables and state information. A handle to this record is
1957 stored in the pane control's reference value field using the
1958 SetControlReference routine. */
1960 class STPTextPaneVars
{
1962 /* OS records referenced */
1963 TXNObject fTXNRec
; /* the txn record */
1964 TXNFrameID fTXNFrame
; /* the txn frame ID */
1965 ControlRef fUserPaneRec
; /* handle to the user pane control */
1966 WindowPtr fOwner
; /* window containing control */
1967 GrafPtr fDrawingEnvironment
; /* grafport where control is drawn */
1969 Boolean fInFocus
; /* true while the focus rect is drawn around the control */
1970 Boolean fIsActive
; /* true while the control is drawn in the active state */
1971 Boolean fTXNObjectActive
; /* reflects the activation state of the text edit record */
1972 Boolean fFocusDrawState
; /* true if focus is drawn (default: true) */
1973 /* calculated locations */
1974 Rect fRBounds
; /* control bounds */
1975 Rect fRTextArea
; /* area where the text is drawn */
1976 Rect fRFocusOutline
; /* rectangle used to draw the focus box */
1977 Rect fRTextOutline
; /* rectangle used to draw the border */
1978 RgnHandle fRTextOutlineRegion
; /* background region for the text, erased before calling TEUpdate */
1979 /* our focus advance override routine */
1980 EventHandlerUPP handlerUPP
;
1981 EventHandlerRef handlerRef
;
1987 /* Univerals Procedure Pointer variables used by the
1988 mUP Control. These variables are set up
1989 the first time that mUPOpenControl is called. */
1990 ControlUserPaneDrawUPP gTPDrawProc
= NULL
;
1991 ControlUserPaneHitTestUPP gTPHitProc
= NULL
;
1992 ControlUserPaneTrackingUPP gTPTrackProc
= NULL
;
1993 ControlUserPaneIdleUPP gTPIdleProc
= NULL
;
1994 ControlUserPaneKeyDownUPP gTPKeyProc
= NULL
;
1995 ControlUserPaneActivateUPP gTPActivateProc
= NULL
;
1996 ControlUserPaneFocusUPP gTPFocusProc
= NULL
;
1998 // one place for calculating all
1999 static void TPCalculateBounds(STPTextPaneVars
*varsp
, const Rect
& bounds
)
2001 SetRect(&varsp
->fRBounds
, bounds
.left
, bounds
.top
, bounds
.right
, bounds
.bottom
);
2002 SetRect(&varsp
->fRFocusOutline
, bounds
.left
, bounds
.top
, bounds
.right
, bounds
.bottom
);
2003 // eventually make TextOutline inset 1,1
2004 SetRect(&varsp
->fRTextOutline
, bounds
.left
, bounds
.top
, bounds
.right
, bounds
.bottom
);
2005 if ( !varsp
->fNoBorders
)
2007 SetRect(&varsp
->fRTextArea
, bounds
.left
+ 2 , bounds
.top
+ (varsp
->fMultiline
? 0 : 2) ,
2008 bounds
.right
- (varsp
->fMultiline
? 0 : 2), bounds
.bottom
- (varsp
->fMultiline
? 0 : 2));
2012 SetRect(&varsp
->fRTextArea
, bounds
.left
, bounds
.top
,
2013 bounds
.right
, bounds
.bottom
);
2017 OSStatus
MLTESetObjectVisibility( STPTextPaneVars
*varsp
, Boolean vis
, long wxStyle
)
2019 OSStatus err
= noErr
;
2020 wxTextCtrl
* textctrl
= (wxTextCtrl
*) GetControlReference(varsp
->fUserPaneRec
);
2023 #if TARGET_API_MAC_OSX
2024 TXNControlTag iControlTags
[1] = { kTXNVisibilityTag
};
2025 TXNControlData iControlData
[1] = {{ vis
}};
2026 err
= ::TXNSetTXNObjectControls( varsp
->fTXNRec
, false, 1, iControlTags
, iControlData
);
2029 UMAGetControlBoundsInWindowCoords( varsp
->fUserPaneRec
, &bounds
);
2030 TPCalculateBounds( varsp
, bounds
) ;
2033 wxMacWindowClipper
cl(textctrl
) ;
2034 TXNSetFrameBounds( varsp
->fTXNRec
, varsp
->fRTextArea
.top
, varsp
->fRTextArea
.left
,
2035 varsp
->fRTextArea
.bottom
, varsp
->fRTextArea
.right
, varsp
->fTXNFrame
);
2036 TXNShowSelection( varsp
->fTXNRec
, kTXNShowStart
);
2040 #if TARGET_API_MAC_OSX
2041 // in 10.2 the scrollbars are still actively redrawn when using only the code above
2042 if ( UMAGetSystemVersion() < 0x1030 )
2044 TXNSetFrameBounds( varsp
->fTXNRec
, varsp
->fRTextArea
.top
+ 20000 , varsp
->fRTextArea
.left
+ 20000 ,
2045 varsp
->fRTextArea
.bottom
+ 20000 , varsp
->fRTextArea
.right
+ 20000 , varsp
->fTXNFrame
);
2053 // make sure we don't miss changes as carbon events are not available for these under classic
2054 static void TPUpdateVisibility(ControlRef theControl
)
2056 wxTextCtrl
* textctrl
= (wxTextCtrl
*) GetControlReference(theControl
);
2057 if ( textctrl
== NULL
)
2060 STPTextPaneVars
*varsp
= (STPTextPaneVars
*) ((wxMacMLTEClassicControl
*)textctrl
->GetPeer())->m_macTXNvars
;
2063 UMAGetControlBoundsInWindowCoords(theControl
, &bounds
);
2064 if ( textctrl
->MacIsReallyShown() != varsp
->fVisible
)
2066 // invalidate old position
2067 // InvalWindowRect( GetControlOwner( theControl ) , &varsp->fRBounds ) ;
2068 varsp
->fVisible
= textctrl
->MacIsReallyShown() ;
2070 if ( !EqualRect( &bounds
, &varsp
->fRBounds
) )
2073 Rect oldBounds
= varsp
->fRBounds
;
2074 TPCalculateBounds( varsp
, bounds
) ;
2075 // we only recalculate when visible, otherwise scrollbars get drawn at incorrect places
2076 if ( varsp
->fVisible
)
2078 wxMacWindowClipper
cl(textctrl
) ;
2079 TXNSetFrameBounds( varsp
->fTXNRec
, varsp
->fRTextArea
.top
, varsp
->fRTextArea
.left
,
2080 varsp
->fRTextArea
.bottom
, varsp
->fRTextArea
.right
, varsp
->fTXNFrame
);
2082 InvalWindowRect( GetControlOwner( theControl
) , &oldBounds
) ;
2083 InvalWindowRect( GetControlOwner( theControl
) , &varsp
->fRBounds
) ;
2087 // make correct activations
2088 static void TPActivatePaneText(STPTextPaneVars
*varsp
, Boolean setActive
) {
2089 wxTextCtrl
* textctrl
= (wxTextCtrl
*) GetControlReference(varsp
->fUserPaneRec
);
2090 if (varsp
->fTXNObjectActive
!= setActive
&& textctrl
->MacIsReallyShown() )
2092 varsp
->fTXNObjectActive
= setActive
;
2093 TXNActivate(varsp
->fTXNRec
, varsp
->fTXNFrame
, varsp
->fTXNObjectActive
);
2094 if (varsp
->fInFocus
)
2095 TXNFocus( varsp
->fTXNRec
, varsp
->fTXNObjectActive
);
2099 // update focus outlines
2100 static void TPRedrawFocusOutline(STPTextPaneVars
*varsp
) {
2102 if (varsp
->fFocusDrawState
!= (varsp
->fIsActive
&& varsp
->fInFocus
))
2104 varsp
->fFocusDrawState
= (varsp
->fIsActive
&& varsp
->fInFocus
);
2105 // DrawThemeFocusRect(&varsp->fRFocusOutline, varsp->fFocusDrawState);
2109 // update TXN focus state
2110 static void TPFocusPaneText(STPTextPaneVars
*varsp
, Boolean setFocus
) {
2111 wxTextCtrl
* textctrl
= (wxTextCtrl
*) GetControlReference(varsp
->fUserPaneRec
);
2113 if (varsp
->fInFocus
!= setFocus
/*&& textctrl->MacIsReallyShown() */ ) {
2114 varsp
->fInFocus
= setFocus
;
2115 TXNFocus( varsp
->fTXNRec
, varsp
->fInFocus
);
2120 void wxMacMLTEClassicControl::MacControlUserPaneDrawProc(wxInt16 thePart
)
2122 /* set up our globals */
2124 wxTextCtrl
* textctrl
= (wxTextCtrl
*) GetControlReference(m_controlRef
);
2125 if ( textctrl
== NULL
)
2127 TPUpdateVisibility( m_controlRef
) ;
2129 if ( textctrl
->MacIsReallyShown() )
2131 wxMacWindowClipper
clipper( textctrl
) ;
2132 TXNDraw(m_txn
, NULL
);
2133 if ( !m_macTXNvars
->fNoBorders
)
2134 DrawThemeEditTextFrame(&m_macTXNvars
->fRTextOutline
, m_macTXNvars
->fIsActive
? kThemeStateActive
: kThemeStateInactive
);
2135 TPRedrawFocusOutline( m_macTXNvars
) ;
2140 /* TPPaneHitTestProc is called when the control manager would
2141 like to determine what part of the control the mouse resides over.
2142 We also call this routine from our tracking proc to determine how
2143 to handle mouse clicks. */
2144 wxInt16
wxMacMLTEClassicControl::MacControlUserPaneHitTestProc(wxInt16 x
, wxInt16 y
)
2146 Point where
= { y
, x
} ;
2147 ControlPartCode result
;
2148 /* set up our locals and lock down our globals*/
2150 wxTextCtrl
* textctrl
= (wxTextCtrl
*) GetControlReference(m_controlRef
);
2151 if ( textctrl
== NULL
)
2154 TPUpdateVisibility( m_controlRef
) ;
2156 if (textctrl
->MacIsReallyShown() )
2158 if (PtInRect(where
, &m_macTXNvars
->fRBounds
))
2159 result
= kmUPTextPart
;
2162 // sometimes we get the coords also in control local coordinates, therefore test again
2163 if ( textctrl
->MacGetTopLevelWindow()->MacUsesCompositing() )
2166 textctrl
->MacClientToRootWindow( &x
, &y
) ;
2170 if (PtInRect(where
, &m_macTXNvars
->fRBounds
))
2171 result
= kmUPTextPart
;
2179 /* TPPaneTrackingProc is called when the mouse is being held down
2180 over our control. This routine handles clicks in the text area
2181 and in the scroll bar. */
2183 wxInt16
wxMacMLTEClassicControl::MacControlUserPaneTrackingProc( wxInt16 x
, wxInt16 y
, void* actionProc
)
2185 Point startPt
= { y
,x
} ;
2186 ControlPartCode partCodeResult
;
2187 /* make sure we have some variables... */
2189 wxTextCtrl
* textctrl
= (wxTextCtrl
*) GetControlReference(m_controlRef
);
2190 if ( textctrl
== NULL
)
2192 TPUpdateVisibility( m_controlRef
) ;
2194 if (textctrl
->MacIsReallyShown() )
2196 /* we don't do any of these functions unless we're in focus */
2197 if ( ! m_macTXNvars
->fInFocus
) {
2199 owner
= GetControlOwner(m_controlRef
);
2200 ClearKeyboardFocus(owner
);
2201 SetKeyboardFocus(owner
, m_controlRef
, kUserClickedToFocusPart
);
2203 /* find the location for the click */
2204 // for compositing, we must convert these into toplevel window coordinates, because hittesting expects them
2205 if ( textctrl
->MacGetTopLevelWindow()->MacUsesCompositing() )
2208 textctrl
->MacClientToRootWindow( &x
, &y
) ;
2213 switch (MacControlUserPaneHitTestProc( startPt
.h
, startPt
.v
))
2215 /* handle clicks in the text part */
2218 wxMacWindowClipper
clipper( textctrl
) ;
2221 ConvertEventRefToEventRecord( (EventRef
) wxTheApp
->MacGetCurrentEvent() , &rec
) ;
2222 TXNClick( m_txn
, &rec
);
2229 return partCodeResult
;
2233 /* TPPaneIdleProc is our user pane idle routine. When our text field
2234 is active and in focus, we use this routine to set the cursor. */
2235 void wxMacMLTEClassicControl::MacControlUserPaneIdleProc()
2238 wxTextCtrl
* textctrl
= (wxTextCtrl
*) GetControlReference(m_controlRef
);
2239 if ( textctrl
== NULL
)
2241 TPUpdateVisibility( m_controlRef
) ;
2243 if (textctrl
->MacIsReallyShown())
2245 /* if we're not active, then we have nothing to say about the cursor */
2246 if (m_macTXNvars
->fIsActive
)
2251 wxMacWindowClipper
clipper( textctrl
) ;
2253 /* there's a 'focus thing' and an 'unfocused thing' */
2254 if (m_macTXNvars
->fInFocus
)
2256 /* flash the cursor */
2257 SetPort(m_macTXNvars
->fDrawingEnvironment
);
2258 TXNIdle(m_macTXNvars
->fTXNRec
);
2259 /* set the cursor */
2260 if (PtInRect(mousep
, &m_macTXNvars
->fRTextArea
))
2263 RectRgn((theRgn
= NewRgn()), &m_macTXNvars
->fRTextArea
);
2264 TXNAdjustCursor(m_macTXNvars
->fTXNRec
, theRgn
);
2269 // SetThemeCursor(kThemeArrowCursor);
2274 /* if it's in our bounds, set the cursor */
2275 UMAGetControlBoundsInWindowCoords(m_controlRef
, &bounds
);
2276 if (PtInRect(mousep
, &bounds
))
2278 // SetThemeCursor(kThemeArrowCursor);
2286 /* TPPaneKeyDownProc is called whenever a keydown event is directed
2287 at our control. Here, we direct the keydown event to the text
2288 edit record and redraw the scroll bar and text field as appropriate. */
2289 wxInt16
wxMacMLTEClassicControl::MacControlUserPaneKeyDownProc (wxInt16 keyCode
, wxInt16 charCode
, wxInt16 modifiers
)
2291 wxTextCtrl
* textctrl
= (wxTextCtrl
*) GetControlReference(m_controlRef
);
2292 if ( textctrl
== NULL
)
2294 TPUpdateVisibility( m_controlRef
) ;
2296 if (m_macTXNvars
->fInFocus
)
2298 /* turn autoscrolling on and send the key event to text edit */
2299 wxMacWindowClipper
clipper( textctrl
) ;
2301 memset( &ev
, 0 , sizeof( ev
) ) ;
2303 ev
.modifiers
= modifiers
;
2304 ev
.message
= (( keyCode
<< 8 ) & keyCodeMask
) + ( charCode
& charCodeMask
) ;
2305 TXNKeyDown( m_txn
, &ev
);
2307 return kControlEntireControl
;
2311 /* TPPaneActivateProc is called when the window containing
2312 the user pane control receives activate events. Here, we redraw
2313 the control and it's text as necessary for the activation state. */
2315 void wxMacMLTEClassicControl::MacControlUserPaneActivateProc( bool activating
)
2318 wxTextCtrl
* textctrl
= (wxTextCtrl
*) GetControlReference(m_controlRef
);
2320 if ( textctrl
== NULL
)
2322 TPUpdateVisibility( m_controlRef
) ;
2324 m_macTXNvars
->fIsActive
= activating
;
2325 wxMacWindowClipper
clipper( textctrl
) ;
2326 TPActivatePaneText(m_macTXNvars
, m_macTXNvars
->fIsActive
&& m_macTXNvars
->fInFocus
);
2327 /* redraw the frame */
2328 if ( textctrl
->MacIsReallyShown() )
2330 if ( !m_macTXNvars
->fNoBorders
)
2331 DrawThemeEditTextFrame(&m_macTXNvars
->fRTextOutline
, m_macTXNvars
->fIsActive
? kThemeStateActive
: kThemeStateInactive
);
2332 TPRedrawFocusOutline( m_macTXNvars
) ;
2337 /* TPPaneFocusProc is called when every the focus changes to or
2338 from our control. Herein, switch the focus appropriately
2339 according to the parameters and redraw the control as
2341 wxInt16
wxMacMLTEClassicControl::MacControlUserPaneFocusProc(wxInt16 action
)
2343 ControlPartCode focusResult
;
2345 focusResult
= kControlFocusNoPart
;
2346 wxTextCtrl
* textctrl
= (wxTextCtrl
*) GetControlReference(m_controlRef
);
2347 if ( textctrl
== NULL
)
2349 TPUpdateVisibility( m_controlRef
) ;
2351 /* if kControlFocusPrevPart and kControlFocusNextPart are received when the user is
2352 tabbing forwards (or shift tabbing backwards) through the items in the dialog,
2353 and kControlFocusNextPart will be received. When the user clicks in our field
2354 and it is not the current focus, then the constant kUserClickedToFocusPart will
2355 be received. The constant kControlFocusNoPart will be received when our control
2356 is the current focus and the user clicks in another control. In your focus routine,
2357 you should respond to these codes as follows:
2359 kControlFocusNoPart - turn off focus and return kControlFocusNoPart. redraw
2360 the control and the focus rectangle as necessary.
2362 kControlFocusPrevPart or kControlFocusNextPart - toggle focus on or off
2363 depending on its current state. redraw the control and the focus rectangle
2364 as appropriate for the new focus state. If the focus state is 'off', return the constant
2365 kControlFocusNoPart, otherwise return a non-zero part code.
2366 kUserClickedToFocusPart - is a constant defined for this example. You should
2367 define your own value for handling click-to-focus type events. */
2368 /* calculate the next highlight state */
2372 case kControlFocusNoPart
:
2373 TPFocusPaneText(m_macTXNvars
, false);
2374 focusResult
= kControlFocusNoPart
;
2376 case kUserClickedToFocusPart
:
2377 TPFocusPaneText(m_macTXNvars
, true);
2380 case kControlFocusPrevPart
:
2381 case kControlFocusNextPart
:
2382 TPFocusPaneText(m_macTXNvars
, ( ! m_macTXNvars
->fInFocus
));
2383 focusResult
= m_macTXNvars
->fInFocus
? 1 : kControlFocusNoPart
;
2386 TPActivatePaneText(m_macTXNvars
, m_macTXNvars
->fIsActive
&& m_macTXNvars
->fInFocus
);
2387 /* redraw the text fram and focus rectangle to indicate the
2389 if ( textctrl
->MacIsReallyShown() )
2391 wxMacWindowClipper
c( textctrl
) ;
2392 if ( !m_macTXNvars
->fNoBorders
)
2393 DrawThemeEditTextFrame(&m_macTXNvars
->fRTextOutline
, m_macTXNvars
->fIsActive
? kThemeStateActive
: kThemeStateInactive
);
2394 TPRedrawFocusOutline( m_macTXNvars
) ;
2399 void wxMacMLTEClassicControl::MacControlUserPaneBackgroundProc( void *info
)
2403 wxMacMLTEClassicControl::wxMacMLTEClassicControl( wxWindow
*wxPeer
,
2404 const wxString
& str
,
2406 const wxSize
& size
, long style
)
2408 m_font
= wxPeer
->GetFont() ;
2409 m_windowStyle
= style
;
2410 Rect bounds
= wxMacGetBoundsForControl( wxPeer
, pos
, size
) ;
2412 wxMacConvertNewlines10To13( &st
) ;
2416 featurSet
= kControlSupportsEmbedding
| kControlSupportsFocus
| kControlWantsIdle
2417 | kControlWantsActivate
| kControlHandlesTracking
| kControlHasSpecialBackground
2418 | kControlGetsFocusOnClick
| kControlSupportsLiveFeedback
;
2419 /* create the control */
2421 verify_noerr( ::CreateUserPaneControl( MAC_WXHWND(wxPeer
->GetParent()->MacGetTopLevelWindowRef()), &bounds
, featurSet
, &m_controlRef
) );
2424 // wxMacWindowClipper c(wxPeer) ;
2428 if ( wxPeer
->MacIsReallyShown() )
2429 MLTESetObjectVisibility( (STPTextPaneVars
*) m_macTXNvars
, true , style
) ;
2432 // wxMacWindowClipper clipper( wxPeer ) ;
2434 TPUpdateVisibility( m_controlRef
) ;
2436 SetTXNData( st
, kTXNStartOffset
, kTXNEndOffset
) ;
2438 TXNSetSelection( m_txn
, 0, 0);
2439 TXNShowSelection( m_txn
, kTXNShowStart
);
2442 AdjustCreationAttributes( *wxWHITE
, true ) ;
2445 wxMacMLTEClassicControl::~wxMacMLTEClassicControl()
2447 // SetControlReference(m_controlRef , 0) ;
2448 TXNDeleteObject(m_txn
);
2452 void wxMacMLTEClassicControl::VisibilityChanged(bool shown
)
2454 MLTESetObjectVisibility((STPTextPaneVars
*) m_macTXNvars
, shown
, m_windowStyle
) ;
2456 InvalWindowRect( GetControlOwner( m_controlRef
) , &((STPTextPaneVars
*)m_macTXNvars
)->fRBounds
) ;
2459 bool wxMacMLTEClassicControl::NeedsFocusRect() const
2464 #ifdef __WXMAC_OSX__
2466 static pascal void wxMacControlUserPaneDrawProc(ControlRef control
, SInt16 part
)
2468 wxTextCtrl
*textCtrl
= wxDynamicCast( wxFindControlFromMacControl(control
) , wxTextCtrl
) ;
2469 wxMacMLTEClassicControl
* win
= textCtrl
? dynamic_cast<wxMacMLTEClassicControl
*>(textCtrl
->GetPeer()) : NULL
;
2471 win
->MacControlUserPaneDrawProc(part
) ;
2474 static pascal ControlPartCode
wxMacControlUserPaneHitTestProc(ControlRef control
, Point where
)
2476 wxTextCtrl
*textCtrl
= wxDynamicCast( wxFindControlFromMacControl(control
) , wxTextCtrl
) ;
2477 wxMacMLTEClassicControl
* win
= textCtrl
? dynamic_cast<wxMacMLTEClassicControl
*>(textCtrl
->GetPeer()) : NULL
;
2479 return win
->MacControlUserPaneHitTestProc(where
.h
, where
.v
) ;
2481 return kControlNoPart
;
2484 static pascal ControlPartCode
wxMacControlUserPaneTrackingProc(ControlRef control
, Point startPt
, ControlActionUPP actionProc
)
2486 wxTextCtrl
*textCtrl
= wxDynamicCast( wxFindControlFromMacControl(control
) , wxTextCtrl
) ;
2487 wxMacMLTEClassicControl
* win
= textCtrl
? dynamic_cast<wxMacMLTEClassicControl
*>(textCtrl
->GetPeer()) : NULL
;
2489 return win
->MacControlUserPaneTrackingProc( startPt
.h
, startPt
.v
, (void*) actionProc
) ;
2491 return kControlNoPart
;
2494 static pascal void wxMacControlUserPaneIdleProc(ControlRef control
)
2496 wxTextCtrl
*textCtrl
= wxDynamicCast( wxFindControlFromMacControl(control
) , wxTextCtrl
) ;
2497 wxMacMLTEClassicControl
* win
= textCtrl
? dynamic_cast<wxMacMLTEClassicControl
*>(textCtrl
->GetPeer()) : NULL
;
2499 win
->MacControlUserPaneIdleProc() ;
2502 static pascal ControlPartCode
wxMacControlUserPaneKeyDownProc(ControlRef control
, SInt16 keyCode
, SInt16 charCode
, SInt16 modifiers
)
2504 wxTextCtrl
*textCtrl
= wxDynamicCast( wxFindControlFromMacControl(control
) , wxTextCtrl
) ;
2505 wxMacMLTEClassicControl
* win
= textCtrl
? dynamic_cast<wxMacMLTEClassicControl
*>(textCtrl
->GetPeer()) : NULL
;
2507 return win
->MacControlUserPaneKeyDownProc(keyCode
,charCode
,modifiers
) ;
2509 return kControlNoPart
;
2512 static pascal void wxMacControlUserPaneActivateProc(ControlRef control
, Boolean activating
)
2514 wxTextCtrl
*textCtrl
= wxDynamicCast( wxFindControlFromMacControl(control
) , wxTextCtrl
) ;
2515 wxMacMLTEClassicControl
* win
= textCtrl
? dynamic_cast<wxMacMLTEClassicControl
*>(textCtrl
->GetPeer()) : NULL
;
2517 win
->MacControlUserPaneActivateProc(activating
) ;
2520 static pascal ControlPartCode
wxMacControlUserPaneFocusProc(ControlRef control
, ControlFocusPart action
)
2522 wxTextCtrl
*textCtrl
= wxDynamicCast( wxFindControlFromMacControl(control
) , wxTextCtrl
) ;
2523 wxMacMLTEClassicControl
* win
= textCtrl
? dynamic_cast<wxMacMLTEClassicControl
*>(textCtrl
->GetPeer()) : NULL
;
2525 return win
->MacControlUserPaneFocusProc(action
) ;
2527 return kControlNoPart
;
2530 static pascal void wxMacControlUserPaneBackgroundProc(ControlRef control
, ControlBackgroundPtr info
)
2532 wxTextCtrl
*textCtrl
= wxDynamicCast( wxFindControlFromMacControl(control
) , wxTextCtrl
) ;
2533 wxMacMLTEClassicControl
* win
= textCtrl
? dynamic_cast<wxMacMLTEClassicControl
*>(textCtrl
->GetPeer()) : NULL
;
2535 win
->MacControlUserPaneBackgroundProc(info
) ;
2539 OSStatus
wxMacMLTEClassicControl::DoCreate()
2542 WindowRef theWindow
;
2544 OSStatus err
= noErr
;
2546 /* set up our globals */
2547 #ifdef __WXMAC_OSX__
2548 if (gTPDrawProc
== NULL
) gTPDrawProc
= NewControlUserPaneDrawUPP(wxMacControlUserPaneDrawProc
);
2549 if (gTPHitProc
== NULL
) gTPHitProc
= NewControlUserPaneHitTestUPP(wxMacControlUserPaneHitTestProc
);
2550 if (gTPTrackProc
== NULL
) gTPTrackProc
= NewControlUserPaneTrackingUPP(wxMacControlUserPaneTrackingProc
);
2551 if (gTPIdleProc
== NULL
) gTPIdleProc
= NewControlUserPaneIdleUPP(wxMacControlUserPaneIdleProc
);
2552 if (gTPKeyProc
== NULL
) gTPKeyProc
= NewControlUserPaneKeyDownUPP(wxMacControlUserPaneKeyDownProc
);
2553 if (gTPActivateProc
== NULL
) gTPActivateProc
= NewControlUserPaneActivateUPP(wxMacControlUserPaneActivateProc
);
2554 if (gTPFocusProc
== NULL
) gTPFocusProc
= NewControlUserPaneFocusUPP(wxMacControlUserPaneFocusProc
);
2557 /* allocate our private storage */
2558 m_macTXNvars
= (STPTextPaneVars
*) malloc(sizeof(STPTextPaneVars
));
2560 /* set the initial settings for our private data */
2561 m_macTXNvars
->fMultiline
= m_windowStyle
& wxTE_MULTILINE
;
2562 m_macTXNvars
->fNoBorders
= m_windowStyle
& wxNO_BORDER
;
2563 m_macTXNvars
->fInFocus
= false;
2564 m_macTXNvars
->fIsActive
= true;
2565 m_macTXNvars
->fTXNObjectActive
= false;
2566 m_macTXNvars
->fFocusDrawState
= false ;
2567 m_macTXNvars
->fUserPaneRec
= m_controlRef
;
2568 m_macTXNvars
->fVisible
= true ;
2570 theWindow
= m_macTXNvars
->fOwner
= GetControlOwner(m_controlRef
);
2572 m_macTXNvars
->fDrawingEnvironment
= (GrafPtr
) GetWindowPort(theWindow
);
2574 #ifdef __WXMAC_OSX__
2575 /* set up the user pane procedures */
2576 SetControlData(m_controlRef
, kControlEntireControl
, kControlUserPaneDrawProcTag
, sizeof(gTPDrawProc
), &gTPDrawProc
);
2577 SetControlData(m_controlRef
, kControlEntireControl
, kControlUserPaneHitTestProcTag
, sizeof(gTPHitProc
), &gTPHitProc
);
2578 SetControlData(m_controlRef
, kControlEntireControl
, kControlUserPaneTrackingProcTag
, sizeof(gTPTrackProc
), &gTPTrackProc
);
2579 SetControlData(m_controlRef
, kControlEntireControl
, kControlUserPaneIdleProcTag
, sizeof(gTPIdleProc
), &gTPIdleProc
);
2580 SetControlData(m_controlRef
, kControlEntireControl
, kControlUserPaneKeyDownProcTag
, sizeof(gTPKeyProc
), &gTPKeyProc
);
2581 SetControlData(m_controlRef
, kControlEntireControl
, kControlUserPaneActivateProcTag
, sizeof(gTPActivateProc
), &gTPActivateProc
);
2582 SetControlData(m_controlRef
, kControlEntireControl
, kControlUserPaneFocusProcTag
, sizeof(gTPFocusProc
), &gTPFocusProc
);
2584 /* calculate the rectangles used by the control */
2585 UMAGetControlBoundsInWindowCoords(m_controlRef
, &bounds
);
2586 m_macTXNvars
->fRTextOutlineRegion
= NewRgn() ;
2587 TPCalculateBounds( m_macTXNvars
, bounds
) ;
2589 /* set up the drawing environment */
2590 SetPort(m_macTXNvars
->fDrawingEnvironment
);
2592 /* create the new edit field */
2594 TXNFrameOptions frameOptions
= FrameOptionsFromWXStyle( m_windowStyle
) ;
2596 verify_noerr(TXNNewObject(NULL
, m_macTXNvars
->fOwner
, &m_macTXNvars
->fRTextArea
,
2598 kTXNTextEditStyleFrameType
,
2600 kTXNSystemDefaultEncoding
,
2601 &m_macTXNvars
->fTXNRec
, &m_macTXNvars
->fTXNFrame
, (TXNObjectRefcon
) m_macTXNvars
));
2602 m_txn
= m_macTXNvars
->fTXNRec
;
2604 /* perform final activations and setup for our text field. Here,
2605 we assume that the window is going to be the 'active' window. */
2606 TPActivatePaneText(m_macTXNvars
, m_macTXNvars
->fIsActive
&& m_macTXNvars
->fInFocus
);
2611 // ----------------------------------------------------------------------------
2612 // MLTE control implementation (OSX part)
2613 // ----------------------------------------------------------------------------
2615 #if TARGET_API_MAC_OSX
2617 #if MAC_OS_X_VERSION_MAX_ALLOWED > MAC_OS_X_VERSION_10_2
2619 wxMacMLTEHIViewControl::wxMacMLTEHIViewControl( wxWindow
*wxPeer
,
2620 const wxString
& str
,
2622 const wxSize
& size
, long style
)
2624 m_font
= wxPeer
->GetFont() ;
2625 m_windowStyle
= style
;
2626 Rect bounds
= wxMacGetBoundsForControl( wxPeer
, pos
, size
) ;
2628 wxMacConvertNewlines10To13( &st
) ;
2630 HIRect hr
= { bounds
.left
, bounds
.top
, bounds
.right
- bounds
.left
, bounds
.bottom
- bounds
.top
} ;
2632 m_scrollView
= NULL
;
2633 TXNFrameOptions frameOptions
= FrameOptionsFromWXStyle( style
) ;
2634 if ( frameOptions
& (kTXNWantVScrollBarMask
|kTXNWantHScrollBarMask
) )
2636 HIScrollViewCreate(( frameOptions
& kTXNWantHScrollBarMask
? kHIScrollViewOptionsHorizScroll
: 0) |
2637 ( frameOptions
& kTXNWantVScrollBarMask
? kHIScrollViewOptionsVertScroll
: 0 ) , &m_scrollView
) ;
2639 HIViewSetFrame( m_scrollView
, &hr
);
2640 HIViewSetVisible( m_scrollView
, true );
2644 HITextViewCreate( NULL
, 0, frameOptions
, &m_textView
) ;
2645 m_txn
= HITextViewGetTXNObject( m_textView
) ;
2646 HIViewSetVisible( m_textView
, true ) ;
2649 HIViewAddSubview( m_scrollView
, m_textView
) ;
2650 m_controlRef
= m_scrollView
;
2651 wxPeer
->MacInstallEventHandler( (WXWidget
) m_textView
) ;
2655 HIViewSetFrame( m_textView
, &hr
);
2656 m_controlRef
= m_textView
;
2659 SetTXNData( st
, kTXNStartOffset
, kTXNEndOffset
) ;
2661 TXNSetSelection( m_txn
, 0, 0);
2662 TXNShowSelection( m_txn
, kTXNShowStart
);
2664 AdjustCreationAttributes( *wxWHITE
, true ) ;
2667 OSStatus
wxMacMLTEHIViewControl::SetFocus( ControlFocusPart focusPart
)
2669 return SetKeyboardFocus( GetControlOwner( m_textView
) ,
2670 m_textView
, focusPart
) ;
2673 bool wxMacMLTEHIViewControl::HasFocus() const
2675 ControlRef control
;
2676 GetKeyboardFocus( GetUserFocusWindow() , &control
) ;
2677 return control
== m_textView
;
2680 bool wxMacMLTEHIViewControl::NeedsFocusRect() const
2682 return m_windowStyle
& wxNO_BORDER
? false : true;
2685 #endif // MAC_OS_X_VERSION_MAX_ALLOWED > MAC_OS_X_VERSION_10_2
2690 #endif // wxUSE_TEXTCTRL