1 /////////////////////////////////////////////////////////////////////////////
4 // Author: Stefan Csomor
5 // Modified by: Ryan Norton (MLTE GetLineLength and GetLineText)
8 // Copyright: (c) Stefan Csomor
9 // Licence: wxWindows licence
10 /////////////////////////////////////////////////////////////////////////////
13 #pragma implementation "textctrl.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 long 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 ;
194 // common parts for implementations based on MLTE
196 class wxMacMLTEControl
: public wxMacTextControl
199 virtual wxString
GetStringValue() const ;
200 virtual void SetStringValue( const wxString
&str
) ;
202 static int ConvertAttribute( const wxTextAttr
& style
, TXNTypeAttributes attr
[] ) ;
203 static TXNFrameOptions
FrameOptionsFromWXStyle( long wxStyle
) ;
204 void AdjustCreationAttributes( const wxColour
& background
, bool visible
) ;
206 virtual void SetFont( const wxFont
& font
, const wxColour
& foreground
, long windowStyle
) ;
207 virtual void SetBackground( const wxBrush
&brush
) ;
208 virtual void SetStyle(long start
, long end
, const wxTextAttr
& style
) ;
209 virtual void Copy() ;
211 virtual void Paste() ;
212 virtual bool CanPaste() const ;
213 virtual void SetEditable(bool editable
) ;
214 virtual long GetLastPosition() const ;
215 virtual void Replace( long from
, long to
, const wxString str
) ;
216 virtual void Remove( long from
, long to
) ;
217 virtual void GetSelection( long* from
, long* to
) const ;
218 virtual void SetSelection( long from
, long to
) ;
220 virtual void WriteText(const wxString
& str
) ;
221 virtual void Clear() ;
223 virtual bool CanUndo() const ;
224 virtual void Undo() ;
225 virtual bool CanRedo() const;
226 virtual void Redo() ;
227 virtual int GetNumberOfLines() const ;
228 virtual long XYToPosition(long x
, long y
) const ;
229 virtual bool PositionToXY(long pos
, long *x
, long *y
) const ;
230 virtual void ShowPosition( long pos
) ;
231 virtual int GetLineLength(long lineNo
) const ;
232 virtual wxString
GetLineText(long lineNo
) const ;
234 void SetTXNData( const wxString
& st
, TXNOffset start
, TXNOffset end
) ;
240 #if TARGET_API_MAC_OSX
242 // implementation available under OSX
244 #if MAC_OS_X_VERSION_MAX_ALLOWED > MAC_OS_X_VERSION_10_2
246 class wxMacMLTEHIViewControl
: public wxMacMLTEControl
249 wxMacMLTEHIViewControl( wxWindow
*wxPeer
,
252 const wxSize
& size
, long style
) ;
253 virtual OSStatus
SetFocus( ControlFocusPart focusPart
) ;
254 virtual bool HasFocus() const ;
255 virtual bool NeedsFocusRect() const ;
257 HIViewRef m_scrollView
;
258 HIViewRef m_textView
;
263 class wxMacUnicodeTextControl
: public wxMacTextControl
266 wxMacUnicodeTextControl( wxWindow
*wxPeer
,
269 const wxSize
& size
, long style
) ;
270 ~wxMacUnicodeTextControl();
271 virtual void VisibilityChanged(bool shown
);
272 virtual wxString
GetStringValue() const ;
273 virtual void SetStringValue( const wxString
&str
) ;
276 virtual void Paste();
277 virtual bool CanPaste() const;
278 virtual void SetEditable(bool editable
) ;
279 virtual void Remove( long from
, long to
) ;
280 virtual void GetSelection( long* from
, long* to
) const ;
281 virtual void SetSelection( long from
, long to
) ;
282 virtual void WriteText(const wxString
& str
) ;
284 // contains the tag for the content (is different for password and non-password controls)
290 // implementation available under classic
292 class STPTextPaneVars
;
294 class wxMacMLTEClassicControl
: public wxMacMLTEControl
297 wxMacMLTEClassicControl( wxWindow
*wxPeer
,
300 const wxSize
& size
, long style
) ;
301 ~wxMacMLTEClassicControl() ;
302 virtual void VisibilityChanged(bool shown
) ;
306 // hack to make public until we have migrated all procs
307 STPTextPaneVars
* m_macTXNvars
;
310 #define TE_UNLIMITED_LENGTH 0xFFFFFFFFUL
312 #if !USE_SHARED_LIBRARY
313 IMPLEMENT_DYNAMIC_CLASS(wxTextCtrl
, wxControl
)
315 BEGIN_EVENT_TABLE(wxTextCtrl
, wxControl
)
316 EVT_ERASE_BACKGROUND( wxTextCtrl::OnEraseBackground
)
317 EVT_DROP_FILES(wxTextCtrl::OnDropFiles
)
318 EVT_CHAR(wxTextCtrl::OnChar
)
319 EVT_MENU(wxID_CUT
, wxTextCtrl::OnCut
)
320 EVT_MENU(wxID_COPY
, wxTextCtrl::OnCopy
)
321 EVT_MENU(wxID_PASTE
, wxTextCtrl::OnPaste
)
322 EVT_MENU(wxID_UNDO
, wxTextCtrl::OnUndo
)
323 EVT_MENU(wxID_REDO
, wxTextCtrl::OnRedo
)
325 EVT_UPDATE_UI(wxID_CUT
, wxTextCtrl::OnUpdateCut
)
326 EVT_UPDATE_UI(wxID_COPY
, wxTextCtrl::OnUpdateCopy
)
327 EVT_UPDATE_UI(wxID_PASTE
, wxTextCtrl::OnUpdatePaste
)
328 EVT_UPDATE_UI(wxID_UNDO
, wxTextCtrl::OnUpdateUndo
)
329 EVT_UPDATE_UI(wxID_REDO
, wxTextCtrl::OnUpdateRedo
)
334 void wxTextCtrl::Init()
339 m_maxLength
= TE_UNLIMITED_LENGTH
;
342 wxTextCtrl::~wxTextCtrl()
347 bool wxTextCtrl::Create(wxWindow
*parent
, wxWindowID id
,
350 const wxSize
& size
, long style
,
351 const wxValidator
& validator
,
352 const wxString
& name
)
354 m_macIsUserPane
= FALSE
;
357 if ( ! ( style
& wxNO_BORDER
) )
358 style
= ( style
& ~wxBORDER_MASK
) | wxSUNKEN_BORDER
;
360 if ( !wxTextCtrlBase::Create(parent
, id
, pos
, size
, style
& ~(wxHSCROLL
|wxVSCROLL
), validator
, name
) )
363 Rect bounds
= wxMacGetBoundsForControl( this , pos
, size
) ;
365 if ( m_windowStyle
& wxTE_MULTILINE
)
367 wxASSERT_MSG( !(m_windowStyle
& wxTE_PROCESS_ENTER
),
368 wxT("wxTE_PROCESS_ENTER style is ignored for multiline text controls (they always process it)") );
370 m_windowStyle
|= wxTE_PROCESS_ENTER
;
371 style
|= wxTE_PROCESS_ENTER
;
374 #if TARGET_API_MAC_OSX
375 #if MAC_OS_X_VERSION_MAX_ALLOWED > MAC_OS_X_VERSION_10_2
376 if ( UMAGetSystemVersion() >= 0x1030 )
378 m_peer
= new wxMacMLTEHIViewControl( this , str
, pos
, size
, style
) ;
381 #if !wxMAC_AWAYS_USE_MLTE
384 m_peer
= new wxMacUnicodeTextControl( this , str
, pos
, size
, style
) ;
390 // this control draws the border itself
391 if ( !HasFlag(wxNO_BORDER
) )
393 m_windowStyle
&= ~wxSUNKEN_BORDER
;
394 bounds
= wxMacGetBoundsForControl( this , pos
, size
) ;
396 m_peer
= new wxMacMLTEClassicControl( this , str
, pos
, size
, style
) ;
399 MacPostControlCreate(pos
,size
) ;
401 if ( m_windowStyle
& wxTE_READONLY
)
403 SetEditable( false ) ;
410 void wxTextCtrl::MacVisibilityChanged()
412 GetPeer()->VisibilityChanged( MacIsReallyShown() ) ;
415 void wxTextCtrl::MacEnabledStateChanged()
419 wxString
wxTextCtrl::GetValue() const
421 return GetPeer()->GetStringValue() ;
424 void wxTextCtrl::GetSelection(long* from
, long* to
) const
426 GetPeer()->GetSelection( from
, to
) ;
429 void wxTextCtrl::SetValue(const wxString
& str
)
432 if ( GetValue() == str
)
435 GetPeer()->SetStringValue(str
) ;
438 void wxTextCtrl::SetMaxLength(unsigned long len
)
443 bool wxTextCtrl::SetFont( const wxFont
& font
)
445 if ( !wxTextCtrlBase::SetFont( font
) )
448 GetPeer()->SetFont( font
, GetForegroundColour() , GetWindowStyle() ) ;
452 bool wxTextCtrl::SetStyle(long start
, long end
, const wxTextAttr
& style
)
454 GetPeer()->SetStyle( start
, end
, style
) ;
458 bool wxTextCtrl::SetDefaultStyle(const wxTextAttr
& style
)
460 wxTextCtrlBase::SetDefaultStyle( style
) ;
461 SetStyle( kTXNUseCurrentSelection
, kTXNUseCurrentSelection
, GetDefaultStyle() ) ;
465 // Clipboard operations
466 void wxTextCtrl::Copy()
474 void wxTextCtrl::Cut()
480 wxCommandEvent
event(wxEVT_COMMAND_TEXT_UPDATED
, m_windowId
);
481 event
.SetString( GetValue() ) ;
482 event
.SetEventObject( this );
483 GetEventHandler()->ProcessEvent(event
);
487 void wxTextCtrl::Paste()
492 // eventually we should add setting the default style again
494 wxCommandEvent
event(wxEVT_COMMAND_TEXT_UPDATED
, m_windowId
);
495 event
.SetString( GetValue() ) ;
496 event
.SetEventObject( this );
497 GetEventHandler()->ProcessEvent(event
);
501 bool wxTextCtrl::CanCopy() const
503 // Can copy if there's a selection
505 GetSelection(& from
, & to
);
509 bool wxTextCtrl::CanCut() const
515 // Can cut if there's a selection
517 GetSelection(& from
, & to
);
521 bool wxTextCtrl::CanPaste() const
526 return GetPeer()->CanPaste() ;
529 void wxTextCtrl::SetEditable(bool editable
)
531 if ( editable
!= m_editable
)
533 m_editable
= editable
;
534 GetPeer()->SetEditable( editable
) ;
538 void wxTextCtrl::SetInsertionPoint(long pos
)
540 SetSelection( pos
, pos
) ;
543 void wxTextCtrl::SetInsertionPointEnd()
545 long pos
= GetLastPosition();
546 SetInsertionPoint(pos
);
549 long wxTextCtrl::GetInsertionPoint() const
552 GetSelection( &begin
, &end
) ;
556 long wxTextCtrl::GetLastPosition() const
558 return GetPeer()->GetLastPosition( ) ;
561 void wxTextCtrl::Replace(long from
, long to
, const wxString
& str
)
563 GetPeer()->Replace( from
, to
, str
) ;
566 void wxTextCtrl::Remove(long from
, long to
)
568 GetPeer()->Remove( from
, to
) ;
571 void wxTextCtrl::SetSelection(long from
, long to
)
573 GetPeer()->SetSelection( from
, to
) ;
576 bool wxTextCtrl::LoadFile(const wxString
& file
)
578 if ( wxTextCtrlBase::LoadFile(file
) )
586 void wxTextCtrl::WriteText(const wxString
& str
)
588 // TODO this MPRemoting will be moved into a remoting peer proxy for any command
589 if ( !wxIsMainThread() )
591 // unfortunately CW 8 is not able to correctly deduce the template types, so we have
592 // to instantiate explicitely
593 wxMacMPRemoteGUICall
<wxTextCtrl
,wxString
>( this , &wxTextCtrl::WriteText
, str
) ;
598 GetPeer()->WriteText( str
) ;
602 void wxTextCtrl::AppendText(const wxString
& text
)
604 SetInsertionPointEnd();
608 void wxTextCtrl::Clear()
613 bool wxTextCtrl::IsModified() const
618 bool wxTextCtrl::IsEditable() const
620 return IsEnabled() && m_editable
;
623 bool wxTextCtrl::AcceptsFocus() const
625 // we don't want focus if we can't be edited
626 return /*IsEditable() && */ wxControl::AcceptsFocus();
629 wxSize
wxTextCtrl::DoGetBestSize() const
635 // these are the numbers from the HIG, we reduce them by the borders
638 switch( m_windowVariant
)
640 case wxWINDOW_VARIANT_NORMAL
:
643 case wxWINDOW_VARIANT_SMALL
:
646 case wxWINDOW_VARIANT_MINI
:
654 // as the above numbers have some free space around the text
655 // we get 5 lines like this anyway
656 if ( m_windowStyle
& wxTE_MULTILINE
)
661 if ( !HasFlag(wxNO_BORDER
) )
664 return wxSize(wText
, hText
);
667 // ----------------------------------------------------------------------------
669 // ----------------------------------------------------------------------------
671 void wxTextCtrl::Undo()
679 void wxTextCtrl::Redo()
687 bool wxTextCtrl::CanUndo() const
693 return GetPeer()->CanUndo() ;
696 bool wxTextCtrl::CanRedo() const
702 return GetPeer()->CanRedo() ;
705 void wxTextCtrl::MarkDirty()
710 void wxTextCtrl::DiscardEdits()
715 int wxTextCtrl::GetNumberOfLines() const
717 return GetPeer()->GetNumberOfLines() ;
720 long wxTextCtrl::XYToPosition(long x
, long y
) const
722 return GetPeer()->XYToPosition( x
, y
) ;
725 bool wxTextCtrl::PositionToXY(long pos
, long *x
, long *y
) const
727 return GetPeer()->PositionToXY(pos
, x
, y
) ;
730 void wxTextCtrl::ShowPosition(long pos
)
732 return GetPeer()->ShowPosition(pos
) ;
735 int wxTextCtrl::GetLineLength(long lineNo
) const
737 return GetPeer()->GetLineLength(lineNo
) ;
740 wxString
wxTextCtrl::GetLineText(long lineNo
) const
742 return GetPeer()->GetLineText(lineNo
) ;
749 void wxTextCtrl::Command(wxCommandEvent
& event
)
751 SetValue (event
.GetString());
752 ProcessCommand (event
);
755 void wxTextCtrl::OnDropFiles(wxDropFilesEvent
& event
)
757 // By default, load the first file into the text window.
758 if (event
.GetNumberOfFiles() > 0)
760 LoadFile(event
.GetFiles()[0]);
764 void wxTextCtrl::OnEraseBackground(wxEraseEvent
& event
)
766 // all erasing should be done by the real mac control implementation
767 // while this is true for MLTE under classic, the HITextView is somehow
768 // transparent but background erase is not working correctly, so intercept
769 // things while we can...
773 void wxTextCtrl::OnChar(wxKeyEvent
& event
)
775 int key
= event
.GetKeyCode() ;
776 bool eat_key
= false ;
778 if ( key
== 'c' && event
.MetaDown() )
785 if ( !IsEditable() && key
!= WXK_LEFT
&& key
!= WXK_RIGHT
&& key
!= WXK_DOWN
&& key
!= WXK_UP
&& key
!= WXK_TAB
&&
786 !( key
== WXK_RETURN
&& ( (m_windowStyle
& wxPROCESS_ENTER
) || (m_windowStyle
& wxTE_MULTILINE
) ) )
787 /* && key != WXK_PRIOR && key != WXK_NEXT && key != WXK_HOME && key != WXK_END */
794 // assume that any key not processed yet is going to modify the control
797 if ( key
== 'v' && event
.MetaDown() )
803 if ( key
== 'x' && event
.MetaDown() )
812 if (m_windowStyle
& wxPROCESS_ENTER
)
814 wxCommandEvent
event(wxEVT_COMMAND_TEXT_ENTER
, m_windowId
);
815 event
.SetEventObject( this );
816 event
.SetString( GetValue() );
817 if ( GetEventHandler()->ProcessEvent(event
) )
820 if ( !(m_windowStyle
& wxTE_MULTILINE
) )
822 wxWindow
*parent
= GetParent();
823 while( parent
&& !parent
->IsTopLevel() && parent
->GetDefaultItem() == NULL
) {
824 parent
= parent
->GetParent() ;
826 if ( parent
&& parent
->GetDefaultItem() )
828 wxButton
*def
= wxDynamicCast(parent
->GetDefaultItem(),
830 if ( def
&& def
->IsEnabled() )
832 wxCommandEvent
event(wxEVT_COMMAND_BUTTON_CLICKED
, def
->GetId() );
833 event
.SetEventObject(def
);
839 // this will make wxWidgets eat the ENTER key so that
840 // we actually prevent line wrapping in a single line
848 if ( !(m_windowStyle
& wxTE_PROCESS_TAB
))
851 if (!event
.ShiftDown())
852 flags
|= wxNavigationKeyEvent::IsForward
;
853 if (event
.ControlDown())
854 flags
|= wxNavigationKeyEvent::WinChange
;
860 // This is necessary (don't know why) or the tab will not
862 WriteText(wxT("\t"));
870 // perform keystroke handling
871 if ( wxTheApp
->MacGetCurrentEvent() != NULL
&& wxTheApp
->MacGetCurrentEventHandlerCallRef() != NULL
)
872 CallNextEventHandler((EventHandlerCallRef
)wxTheApp
->MacGetCurrentEventHandlerCallRef() , (EventRef
) wxTheApp
->MacGetCurrentEvent() ) ;
876 if ( wxMacConvertEventToRecord( (EventRef
) wxTheApp
->MacGetCurrentEvent() , &rec
) )
878 EventRecord
*ev
= &rec
;
881 keychar
= short(ev
->message
& charCodeMask
);
882 keycode
= short(ev
->message
& keyCodeMask
) >> 8 ;
884 m_peer
->HandleKey( keycode
, keychar
, ev
->modifiers
) ;
888 if ( ( key
>= 0x20 && key
< WXK_START
) ||
893 wxCommandEvent
event1(wxEVT_COMMAND_TEXT_UPDATED
, m_windowId
);
894 event1
.SetString( GetValue() ) ;
895 event1
.SetEventObject( this );
896 wxPostEvent(GetEventHandler(),event1
);
900 // ----------------------------------------------------------------------------
901 // standard handlers for standard edit menu events
902 // ----------------------------------------------------------------------------
904 void wxTextCtrl::OnCut(wxCommandEvent
& WXUNUSED(event
))
909 void wxTextCtrl::OnCopy(wxCommandEvent
& WXUNUSED(event
))
914 void wxTextCtrl::OnPaste(wxCommandEvent
& WXUNUSED(event
))
919 void wxTextCtrl::OnUndo(wxCommandEvent
& WXUNUSED(event
))
924 void wxTextCtrl::OnRedo(wxCommandEvent
& WXUNUSED(event
))
929 void wxTextCtrl::OnUpdateCut(wxUpdateUIEvent
& event
)
931 event
.Enable( CanCut() );
934 void wxTextCtrl::OnUpdateCopy(wxUpdateUIEvent
& event
)
936 event
.Enable( CanCopy() );
939 void wxTextCtrl::OnUpdatePaste(wxUpdateUIEvent
& event
)
941 event
.Enable( CanPaste() );
944 void wxTextCtrl::OnUpdateUndo(wxUpdateUIEvent
& event
)
946 event
.Enable( CanUndo() );
949 void wxTextCtrl::OnUpdateRedo(wxUpdateUIEvent
& event
)
951 event
.Enable( CanRedo() );
954 bool wxTextCtrl::MacSetupCursor( const wxPoint
& pt
)
959 // user pane implementation
961 void wxTextCtrl::MacControlUserPaneDrawProc(wxInt16 part
)
965 wxInt16
wxTextCtrl::MacControlUserPaneHitTestProc(wxInt16 x
, wxInt16 y
)
967 return kControlNoPart
;
970 wxInt16
wxTextCtrl::MacControlUserPaneTrackingProc(wxInt16 x
, wxInt16 y
, void* actionProc
)
972 return kControlNoPart
;
975 void wxTextCtrl::MacControlUserPaneIdleProc()
979 wxInt16
wxTextCtrl::MacControlUserPaneKeyDownProc(wxInt16 keyCode
, wxInt16 charCode
, wxInt16 modifiers
)
981 return kControlNoPart
;
984 void wxTextCtrl::MacControlUserPaneActivateProc(bool activating
)
988 wxInt16
wxTextCtrl::MacControlUserPaneFocusProc(wxInt16 action
)
990 return kControlNoPart
;
993 void wxTextCtrl::MacControlUserPaneBackgroundProc(void* info
)
997 // ----------------------------------------------------------------------------
998 // implementation base class
999 // ----------------------------------------------------------------------------
1001 wxMacTextControl::wxMacTextControl()
1005 wxMacTextControl::~wxMacTextControl()
1009 void wxMacTextControl::SetStyle(long start
, long end
, const wxTextAttr
& style
)
1013 void wxMacTextControl::Copy()
1017 void wxMacTextControl::Cut()
1021 void wxMacTextControl::Paste()
1025 bool wxMacTextControl::CanPaste() const
1030 void wxMacTextControl::SetEditable(bool editable
)
1034 long wxMacTextControl::GetLastPosition() const
1036 return GetStringValue().Length() ;
1039 void wxMacTextControl::Replace( long from
, long to
, const wxString str
)
1043 void wxMacTextControl::Clear()
1045 SetStringValue( wxEmptyString
) ;
1048 bool wxMacTextControl::CanUndo() const
1053 void wxMacTextControl::Undo() { }
1055 bool wxMacTextControl::CanRedo() const
1060 void wxMacTextControl::Redo()
1064 long wxMacTextControl::XYToPosition(long x
, long y
) const
1069 bool wxMacTextControl::PositionToXY(long pos
, long *x
, long *y
) const
1074 void wxMacTextControl::ShowPosition( long WXUNUSED(pos
) )
1078 int wxMacTextControl::GetNumberOfLines() const
1080 ItemCount lines
= 0 ;
1081 wxString content
= GetStringValue() ;
1083 for (size_t i
= 0; i
< content
.Length() ; i
++)
1085 if (content
[i
] == '\r') lines
++;
1090 wxString
wxMacTextControl::GetLineText(long lineNo
) const
1092 // TODO change this if possible to reflect real lines
1093 wxString content
= GetStringValue() ;
1097 for (size_t i
= 0; i
< content
.Length() ; i
++)
1099 if (count
== lineNo
)
1101 // Add chars in line then
1104 for (size_t j
= i
; j
< content
.Length(); j
++)
1106 if (content
[j
] == '\n')
1114 if (content
[i
] == '\n') count
++;
1116 return wxEmptyString
;
1119 int wxMacTextControl::GetLineLength(long lineNo
) const
1121 // TODO change this if possible to reflect real lines
1122 wxString content
= GetStringValue() ;
1126 for (size_t i
= 0; i
< content
.Length() ; i
++)
1128 if (count
== lineNo
)
1130 // Count chars in line then
1132 for (size_t j
= i
; j
< content
.Length(); j
++)
1135 if (content
[j
] == '\n') return count
;
1140 if (content
[i
] == '\n') count
++;
1145 // ----------------------------------------------------------------------------
1146 // standard unicode control implementation
1147 // ----------------------------------------------------------------------------
1149 #if TARGET_API_MAC_OSX
1151 wxMacUnicodeTextControl::wxMacUnicodeTextControl( wxWindow
*wxPeer
,
1152 const wxString
& str
,
1154 const wxSize
& size
, long style
)
1156 m_font
= wxPeer
->GetFont() ;
1157 m_windowStyle
= style
;
1158 Rect bounds
= wxMacGetBoundsForControl( wxPeer
, pos
, size
) ;
1160 wxMacConvertNewlines10To13( &st
) ;
1161 wxMacCFStringHolder
cf(st
, m_font
.GetEncoding()) ;
1162 CFStringRef cfr
= cf
;
1163 Boolean isPassword
= ( m_windowStyle
& wxTE_PASSWORD
) != 0 ;
1164 m_valueTag
= isPassword
? kControlEditTextPasswordCFStringTag
: kControlEditTextCFStringTag
;
1165 CreateEditUnicodeTextControl( MAC_WXHWND(wxPeer
->MacGetTopLevelWindowRef()), &bounds
, cfr
, isPassword
, NULL
, &m_controlRef
) ;
1167 if ( !(m_windowStyle
& wxTE_MULTILINE
) )
1169 SetData
<Boolean
>( kControlEditTextPart
, kControlEditTextSingleLineTag
, true ) ;
1173 wxMacUnicodeTextControl::~wxMacUnicodeTextControl()
1177 void wxMacUnicodeTextControl::VisibilityChanged(bool shown
)
1179 if ( !(m_windowStyle
& wxTE_MULTILINE
) && shown
)
1181 // work around a refresh issue insofar as not always the entire content is shown even if this would be possible
1182 ControlEditTextSelectionRec sel
;
1183 CFStringRef value
= NULL
;
1185 verify_noerr( GetData
<ControlEditTextSelectionRec
>( 0, kControlEditTextSelectionTag
, &sel
) );
1186 verify_noerr( GetData
<CFStringRef
>( 0, m_valueTag
, &value
) );
1187 verify_noerr( SetData
<CFStringRef
>( 0, m_valueTag
, &value
) );
1188 verify_noerr( SetData
<ControlEditTextSelectionRec
>( 0, kControlEditTextSelectionTag
, &sel
) );
1190 CFRelease( value
) ;
1193 wxString
wxMacUnicodeTextControl::GetStringValue() const
1196 CFStringRef value
= GetData
<CFStringRef
>(0,m_valueTag
) ;
1199 wxMacCFStringHolder
cf(value
) ;
1200 result
= cf
.AsString() ;
1202 #if TARGET_API_MAC_OSX
1203 wxMacConvertNewlines13To10( &result
) ;
1205 wxMacConvertNewlines10To13( &result
) ;
1209 void wxMacUnicodeTextControl::SetStringValue( const wxString
&str
)
1212 wxMacConvertNewlines10To13( &st
) ;
1213 wxMacCFStringHolder
cf(st
, m_font
.GetEncoding() ) ;
1214 verify_noerr( SetData
<CFStringRef
>( 0, m_valueTag
, cf
) ) ;
1216 void wxMacUnicodeTextControl::Copy()
1218 SendHICommand( kHICommandCopy
) ;
1220 void wxMacUnicodeTextControl::Cut()
1222 SendHICommand( kHICommandCut
) ;
1224 void wxMacUnicodeTextControl::Paste()
1226 SendHICommand( kHICommandPaste
) ;
1228 bool wxMacUnicodeTextControl::CanPaste() const
1232 void wxMacUnicodeTextControl::SetEditable(bool editable
)
1234 SetData
<Boolean
>( 0 , kControlEditTextLockedTag
, (Boolean
) !editable
) ;
1236 void wxMacUnicodeTextControl::Remove( long from
, long to
)
1240 void wxMacUnicodeTextControl::GetSelection( long* from
, long* to
) const
1242 ControlEditTextSelectionRec sel
;
1243 verify_noerr(GetData
<ControlEditTextSelectionRec
>( 0, kControlEditTextSelectionTag
, &sel
) ) ;
1244 if ( from
) *from
= sel
.selStart
;
1245 if ( to
) *to
= sel
.selEnd
;
1248 void wxMacUnicodeTextControl::SetSelection( long from
, long to
)
1250 ControlEditTextSelectionRec sel
;
1251 sel
.selStart
= from
;
1253 SetData
<ControlEditTextSelectionRec
>( 0 , kControlEditTextSelectionTag
, &sel
) ;
1256 void wxMacUnicodeTextControl::WriteText(const wxString
& str
)
1259 wxMacConvertNewlines10To13( &st
) ;
1260 #if MAC_OS_X_VERSION_MAX_ALLOWED > MAC_OS_X_VERSION_10_2
1261 wxMacCFStringHolder
cf(st
, m_font
.GetEncoding() ) ;
1262 CFStringRef value
= cf
;
1263 SetData
<CFStringRef
>( 0, kControlEditTextInsertCFStringRefTag
, &value
);
1265 wxString val
= GetStringValue() ;
1267 GetSelection( &start
, &end
) ;
1268 val
.Remove( start
, end
- start
) ;
1269 val
.insert( start
, str
) ;
1270 SetStringValue( val
) ;
1271 SetSelection( start
+ str
.Length() , start
+ str
.Length() ) ;
1277 // ----------------------------------------------------------------------------
1278 // MLTE control implementation (common part)
1279 // ----------------------------------------------------------------------------
1281 #if TARGET_API_MAC_OSX == 0
1282 // declaration needed because of one line in the code...
1283 static void TPUpdateVisibility(ControlRef theControl
) ;
1286 // if mlte is on read only , no changes at all are allowed, not even from
1287 // procedural API, in order to allow changes via API all the same we must undo
1288 // the readonly status while we are executing, this class helps to do so
1293 EditHelper( TXNObject txn
)
1295 TXNControlTag tag
[] = { kTXNIOPrivilegesTag
} ;
1297 TXNGetTXNObjectControls( m_txn
, 1 , tag
, m_data
) ;
1298 if ( m_data
[0].uValue
== kTXNReadOnly
)
1300 TXNControlData data
[] = { { kTXNReadWrite
} } ;
1301 TXNSetTXNObjectControls( m_txn
, false , 1 , tag
, data
) ;
1306 TXNControlTag tag
[] = { kTXNIOPrivilegesTag
} ;
1307 if ( m_data
[0].uValue
== kTXNReadOnly
)
1309 TXNSetTXNObjectControls( m_txn
, false , 1 , tag
, m_data
) ;
1314 TXNControlData m_data
[1] ;
1317 wxString
wxMacMLTEControl::GetStringValue() const
1321 Size actualSize
= 0;
1325 err
= TXNGetDataEncoded( m_txn
, kTXNStartOffset
, kTXNEndOffset
, &theText
, kTXNUnicodeTextData
);
1333 actualSize
= GetHandleSize( theText
) / sizeof( UniChar
) ;
1334 if ( actualSize
> 0 )
1336 wxChar
*ptr
= NULL
;
1337 #if SIZEOF_WCHAR_T == 2
1338 ptr
= new wxChar
[actualSize
+ 1 ] ;
1339 wxStrncpy( ptr
, (wxChar
*) *theText
, actualSize
) ;
1342 SetHandleSize( theText
, ( actualSize
+ 1 ) * sizeof( UniChar
) ) ;
1344 (((UniChar
*)*theText
)[actualSize
]) = 0 ;
1345 wxMBConvUTF16BE converter
;
1346 size_t noChars
= converter
.MB2WC( NULL
, (const char*)*theText
, 0 ) ;
1347 ptr
= new wxChar
[noChars
+ 1] ;
1349 noChars
= converter
.MB2WC( ptr
, (const char*)*theText
, noChars
) ;
1351 HUnlock( theText
) ;
1353 ptr
[actualSize
] = 0 ;
1354 result
= wxString( ptr
) ;
1357 DisposeHandle( theText
) ;
1361 err
= TXNGetDataEncoded( m_txn
, kTXNStartOffset
, kTXNEndOffset
, &theText
, kTXNTextData
);
1369 actualSize
= GetHandleSize( theText
) ;
1370 if ( actualSize
> 0 )
1373 result
= wxString( *theText
, wxConvLocal
, actualSize
) ;
1374 HUnlock( theText
) ;
1376 DisposeHandle( theText
) ;
1380 #if TARGET_API_MAC_OSX
1381 wxMacConvertNewlines13To10( &result
) ;
1383 wxMacConvertNewlines10To13( &result
) ;
1388 void wxMacMLTEControl::SetStringValue( const wxString
&str
)
1392 wxMacConvertNewlines10To13( &st
) ;
1393 EditHelper
help(m_txn
) ;
1395 // wxMacWindowClipper c( this ) ;
1396 #if !TARGET_API_MAC_OSX
1397 // otherwise scrolling might have problems ?
1398 TPUpdateVisibility( m_controlRef
) ;
1400 SetTXNData( st
, kTXNStartOffset
, kTXNEndOffset
) ;
1401 TXNSetSelection( m_txn
, 0, 0);
1402 TXNShowSelection( m_txn
, kTXNShowStart
);
1405 TXNFrameOptions
wxMacMLTEControl::FrameOptionsFromWXStyle( long wxStyle
)
1407 TXNFrameOptions frameOptions
=
1408 kTXNDontDrawCaretWhenInactiveMask
;
1409 if ( ! ( wxStyle
& wxTE_NOHIDESEL
) )
1410 frameOptions
|= kTXNDontDrawSelectionWhenInactiveMask
;
1412 if ( wxStyle
& wxTE_MULTILINE
)
1414 if ( ! ( wxStyle
& wxTE_DONTWRAP
) )
1415 frameOptions
|= kTXNAlwaysWrapAtViewEdgeMask
;
1418 frameOptions
|= kTXNAlwaysWrapAtViewEdgeMask
;
1419 frameOptions
|= kTXNWantHScrollBarMask
;
1422 if ( !(wxStyle
& wxTE_NO_VSCROLL
) )
1423 frameOptions
|= kTXNWantVScrollBarMask
;
1426 frameOptions
|= kTXNSingleLineOnlyMask
;
1428 if ( wxStyle
& wxHSCROLL
)
1429 frameOptions
|= kTXNWantHScrollBarMask
;
1431 return frameOptions
;
1434 void wxMacMLTEControl::AdjustCreationAttributes( const wxColour
&background
, bool visible
)
1436 TXNControlTag iControlTags
[3] = { kTXNDoFontSubstitution
, kTXNWordWrapStateTag
};
1437 TXNControlData iControlData
[3] = { {false}, {kTXNNoAutoWrap
} };
1439 #if TARGET_API_MAC_OSX
1440 iControlTags
[2] = kTXNVisibilityTag
;
1441 iControlData
[2].uValue
= visible
;
1445 if ( m_windowStyle
& wxTE_MULTILINE
)
1447 if (m_windowStyle
& wxTE_DONTWRAP
)
1448 iControlData
[1].uValue
= kTXNNoAutoWrap
;
1450 iControlData
[1].uValue
= kTXNAutoWrap
;
1453 verify_noerr( TXNSetTXNObjectControls( m_txn
, false, toptag
,
1454 iControlTags
, iControlData
)) ;
1456 // setting the default font
1462 GetThemeFont(kThemeSystemFont
, GetApplicationScript() , fontName
, &fontSize
, &fontStyle
) ;
1464 TXNTypeAttributes typeAttr
[] =
1466 { kTXNQDFontNameAttribute
, kTXNQDFontNameAttributeSize
, { (void*) fontName
} } ,
1467 { kTXNQDFontSizeAttribute
, kTXNFontSizeAttributeSize
, { (void*) (fontSize
<< 16) } } ,
1468 { kTXNQDFontStyleAttribute
, kTXNQDFontStyleAttributeSize
, { (void*) normal
} } ,
1471 verify_noerr( TXNSetTypeAttributes (m_txn
, sizeof( typeAttr
) / sizeof(TXNTypeAttributes
) , typeAttr
,
1475 if ( m_windowStyle
& wxTE_PASSWORD
)
1478 verify_noerr(TXNEchoMode( m_txn
, c
, 0 , true )) ;
1481 TXNBackground tback
;
1482 tback
.bgType
= kTXNBackgroundTypeRGB
;
1483 tback
.bg
.color
= MAC_WXCOLORREF( background
.GetPixel() );
1484 TXNSetBackground( m_txn
, &tback
);
1487 void wxMacMLTEControl::SetBackground( const wxBrush
&brush
)
1489 // currently only solid background are supported
1490 TXNBackground tback
;
1491 tback
.bgType
= kTXNBackgroundTypeRGB
;
1492 tback
.bg
.color
= MAC_WXCOLORREF( brush
.GetColour().GetPixel() );
1493 TXNSetBackground( m_txn
, &tback
);
1496 int wxMacMLTEControl::ConvertAttribute( const wxTextAttr
& style
, TXNTypeAttributes typeAttr
[] )
1498 Str255 fontName
= "\pMonaco" ;
1499 SInt16 fontSize
= 12 ;
1500 Style fontStyle
= normal
;
1502 int attrCounter
= 0 ;
1503 if ( style
.HasFont() )
1505 const wxFont
&font
= style
.GetFont() ;
1506 wxMacStringToPascal( font
.GetFaceName() , fontName
) ;
1507 fontSize
= font
.GetPointSize() ;
1508 if ( font
.GetUnderlined() )
1509 fontStyle
|= underline
;
1510 if ( font
.GetWeight() == wxBOLD
)
1512 if ( font
.GetStyle() == wxITALIC
)
1513 fontStyle
|= italic
;
1515 typeAttr
[attrCounter
].tag
= kTXNQDFontNameAttribute
;
1516 typeAttr
[attrCounter
].size
= kTXNQDFontNameAttributeSize
;
1517 typeAttr
[attrCounter
].data
.dataPtr
= (void*) fontName
;
1518 typeAttr
[attrCounter
+1].tag
= kTXNQDFontSizeAttribute
;
1519 typeAttr
[attrCounter
+1].size
= kTXNFontSizeAttributeSize
;
1520 typeAttr
[attrCounter
+1].data
.dataValue
= (fontSize
<< 16) ;
1521 typeAttr
[attrCounter
+2].tag
= kTXNQDFontStyleAttribute
;
1522 typeAttr
[attrCounter
+2].size
= kTXNQDFontStyleAttributeSize
;
1523 typeAttr
[attrCounter
+2].data
.dataValue
= fontStyle
;
1526 if ( style
.HasTextColour() )
1528 typeAttr
[attrCounter
].tag
= kTXNQDFontColorAttribute
;
1529 typeAttr
[attrCounter
].size
= kTXNQDFontColorAttributeSize
;
1530 typeAttr
[attrCounter
].data
.dataPtr
= (void*) &color
;
1531 color
= MAC_WXCOLORREF(style
.GetTextColour().GetPixel()) ;
1534 return attrCounter
;
1537 void wxMacMLTEControl::SetFont( const wxFont
& font
, const wxColour
& foreground
, long windowStyle
)
1539 EditHelper
help(m_txn
) ;
1540 wxTextAttr
style(foreground
,wxNullColour
,font
) ;
1541 TXNTypeAttributes typeAttr
[4] ;
1542 int attrCounter
= ConvertAttribute( style
, typeAttr
) ;
1543 if ( attrCounter
> 0 )
1545 verify_noerr( TXNSetTypeAttributes ( m_txn
, attrCounter
, typeAttr
, kTXNStartOffset
,kTXNEndOffset
) );
1548 void wxMacMLTEControl::SetStyle(long start
, long end
, const wxTextAttr
& style
)
1550 EditHelper
help(m_txn
) ;
1551 TXNTypeAttributes typeAttr
[4] ;
1552 int attrCounter
= ConvertAttribute( style
, typeAttr
) ;
1553 if ( attrCounter
> 0 )
1555 verify_noerr( TXNSetTypeAttributes ( m_txn
, attrCounter
, typeAttr
, start
,end
) );
1559 void wxMacMLTEControl::Copy()
1561 ClearCurrentScrap();
1563 TXNConvertToPublicScrap();
1566 void wxMacMLTEControl::Cut()
1568 ClearCurrentScrap();
1570 TXNConvertToPublicScrap();
1573 void wxMacMLTEControl::Paste()
1575 TXNConvertFromPublicScrap();
1579 bool wxMacMLTEControl::CanPaste() const
1581 return TXNIsScrapPastable() ;
1584 void wxMacMLTEControl::SetEditable(bool editable
)
1586 TXNControlTag tag
[] = { kTXNIOPrivilegesTag
} ;
1587 TXNControlData data
[] = { { editable
? kTXNReadWrite
: kTXNReadOnly
} } ;
1588 TXNSetTXNObjectControls( m_txn
, false , sizeof(tag
) / sizeof (TXNControlTag
) , tag
, data
) ;
1591 long wxMacMLTEControl::GetLastPosition() const
1593 long actualsize
= 0 ;
1596 OSErr err
= TXNGetDataEncoded( m_txn
, kTXNStartOffset
, kTXNEndOffset
, &theText
, kTXNTextData
);
1604 actualsize
= GetHandleSize( theText
) ;
1605 DisposeHandle( theText
) ;
1611 void wxMacMLTEControl::Replace( long from
, long to
, const wxString str
)
1613 wxString value
= str
;
1614 wxMacConvertNewlines10To13( &value
) ;
1616 EditHelper
help( m_txn
) ;
1618 TXNSetSelection(m_txn
, from
, to
) ;
1620 SetTXNData( value
, kTXNUseCurrentSelection
, kTXNUseCurrentSelection
) ;
1623 void wxMacMLTEControl::Remove( long from
, long to
)
1625 EditHelper
help( m_txn
) ;
1627 TXNSetSelection(m_txn
, from
, to
) ;
1631 void wxMacMLTEControl::GetSelection( long* from
, long* to
) const
1633 TXNGetSelection( m_txn
, (TXNOffset
*) from
, (TXNOffset
*) to
) ;
1636 void wxMacMLTEControl::SetSelection( long from
, long to
)
1638 /* change the selection */
1639 if ((from
== -1) && (to
== -1))
1640 TXNSelectAll(m_txn
);
1642 TXNSetSelection( m_txn
, from
, to
);
1643 TXNShowSelection( m_txn
, kTXNShowStart
);
1646 void wxMacMLTEControl::WriteText(const wxString
& str
)
1648 EditHelper
helper( m_txn
) ;
1650 wxMacConvertNewlines10To13( &st
) ;
1652 long start
, end
, dummy
;
1653 GetSelection( &start
, &dummy
) ;
1654 SetTXNData( st
, kTXNUseCurrentSelection
, kTXNUseCurrentSelection
) ;
1655 GetSelection( &dummy
, &end
) ;
1656 // TODO SetStyle( start , end , GetDefaultStyle() ) ;
1659 void wxMacMLTEControl::Clear()
1661 EditHelper
st(m_txn
) ;
1662 TXNSetSelection( m_txn
, kTXNStartOffset
, kTXNEndOffset
) ;
1666 bool wxMacMLTEControl::CanUndo() const
1668 return TXNCanUndo( m_txn
, NULL
) ;
1671 void wxMacMLTEControl::Undo()
1676 bool wxMacMLTEControl::CanRedo() const
1678 return TXNCanRedo( m_txn
, NULL
) ;
1681 void wxMacMLTEControl::Redo()
1686 int wxMacMLTEControl::GetNumberOfLines() const
1688 ItemCount lines
= 0 ;
1689 TXNGetLineCount(m_txn
, &lines
) ;
1693 long wxMacMLTEControl::XYToPosition(long x
, long y
) const
1697 long lastpos
= GetLastPosition() ;
1699 // TODO find a better implementation : while we can get the
1700 // line metrics of a certain line, we don't get its starting
1701 // position, so it would probably be rather a binary search
1702 // for the start position
1705 int lastHeight
= 0 ;
1708 for ( n
= 0 ; n
<= (ItemCount
) lastpos
; ++n
)
1710 if ( y
== ypos
&& x
== xpos
)
1713 TXNOffsetToPoint( m_txn
, n
, &curpt
);
1715 if ( curpt
.v
> lastHeight
)
1720 lastHeight
= curpt
.v
;
1728 bool wxMacMLTEControl::PositionToXY(long pos
, long *x
, long *y
) const
1732 long lastpos
= GetLastPosition() ;
1737 if ( pos
<= lastpos
)
1739 // TODO find a better implementation : while we can get the
1740 // line metrics of a certain line, we don't get its starting
1741 // position, so it would probably be rather a binary search
1742 // for the start position
1745 int lastHeight
= 0 ;
1748 for ( n
= 0 ; n
<= (ItemCount
) pos
; ++n
)
1750 TXNOffsetToPoint(m_txn
, n
, &curpt
);
1752 if ( curpt
.v
> lastHeight
)
1757 lastHeight
= curpt
.v
;
1762 if ( y
) *y
= ypos
;
1763 if ( x
) *x
= xpos
;
1769 void wxMacMLTEControl::ShowPosition( long pos
)
1771 #if TARGET_RT_MAC_MACHO && defined(AVAILABLE_MAC_OS_X_VERSION_10_2_AND_LATER)
1775 TXNOffset selstart
, selend
;
1776 TXNGetSelection( m_txn
, &selstart
, &selend
) ;
1777 TXNOffsetToPoint( m_txn
, selstart
, ¤t
);
1778 TXNOffsetToPoint( m_txn
, pos
, &desired
);
1779 //TODO use HIPoints for 10.3 and above
1780 if ( (UInt32
) TXNScroll
!= (UInt32
) kUnresolvedCFragSymbolAddress
)
1782 OSErr theErr
= noErr
;
1783 SInt32 dv
= desired
.v
- current
.v
;
1784 SInt32 dh
= desired
.h
- current
.h
;
1785 TXNShowSelection( m_txn
, true ) ;
1786 theErr
= TXNScroll( m_txn
, kTXNScrollUnitsInPixels
, kTXNScrollUnitsInPixels
, &dv
, &dh
);
1787 wxASSERT_MSG( theErr
== noErr
, _T("TXNScroll returned an error!") );
1793 void wxMacMLTEControl::SetTXNData( const wxString
& st
, TXNOffset start
, TXNOffset end
)
1796 #if SIZEOF_WCHAR_T == 2
1797 size_t len
= st
.Len() ;
1798 TXNSetData( m_txn
, kTXNUnicodeTextData
, (void*)st
.wc_str(), len
* 2,
1801 wxMBConvUTF16BE converter
;
1802 ByteCount byteBufferLen
= converter
.WC2MB( NULL
, st
.wc_str() , 0 ) ;
1803 UniChar
*unibuf
= (UniChar
*) malloc(byteBufferLen
) ;
1804 converter
.WC2MB( (char*) unibuf
, st
.wc_str() , byteBufferLen
) ;
1805 TXNSetData( m_txn
, kTXNUnicodeTextData
, (void*)unibuf
, byteBufferLen
,
1810 wxCharBuffer text
= st
.mb_str(wxConvLocal
) ;
1811 TXNSetData( m_txn
, kTXNTextData
, (void*)text
.data(), strlen( text
) ,
1817 wxString
wxMacMLTEControl::GetLineText(long lineNo
) const
1821 if ( lineNo
< GetNumberOfLines() )
1829 // get the first possible position in the control
1831 TXNOffsetToPoint(m_txn
, 0, &firstPoint
);
1833 // Iterate through the lines until we reach the one we want,
1834 // adding to our current y pixel point position
1835 while (ypos
< lineNo
)
1837 TXNGetLineMetrics(m_txn
, ypos
++, &lineWidth
, &lineHeight
);
1838 currentHeight
+= lineHeight
;
1841 Point thePoint
= { firstPoint
.v
+ Fix2Long(currentHeight
), firstPoint
.h
+ Fix2Long(0) };
1842 TXNOffset theOffset
;
1843 TXNPointToOffset(m_txn
, thePoint
, &theOffset
);
1845 wxString content
= GetStringValue() ;
1846 Point currentPoint
= thePoint
;
1847 while(thePoint
.v
== currentPoint
.v
&& theOffset
< content
.length())
1849 line
+= content
[theOffset
];
1850 TXNOffsetToPoint(m_txn
, ++theOffset
, ¤tPoint
);
1856 int wxMacMLTEControl::GetLineLength(long lineNo
) const
1860 if ( lineNo
< GetNumberOfLines() )
1868 // get the first possible position in the control
1870 TXNOffsetToPoint(m_txn
, 0, &firstPoint
);
1872 // Iterate through the lines until we reach the one we want,
1873 // adding to our current y pixel point position
1874 while (ypos
< lineNo
)
1876 TXNGetLineMetrics(m_txn
, ypos
++, &lineWidth
, &lineHeight
);
1877 currentHeight
+= lineHeight
;
1880 Point thePoint
= { firstPoint
.v
+ Fix2Long(currentHeight
), firstPoint
.h
+ Fix2Long(0) };
1881 TXNOffset theOffset
;
1882 TXNPointToOffset(m_txn
, thePoint
, &theOffset
);
1884 wxString content
= GetStringValue() ;
1885 Point currentPoint
= thePoint
;
1886 while(thePoint
.v
== currentPoint
.v
&& theOffset
< content
.length())
1889 TXNOffsetToPoint(m_txn
, ++theOffset
, ¤tPoint
);
1896 // ----------------------------------------------------------------------------
1897 // MLTE control implementation (classic part)
1898 // ----------------------------------------------------------------------------
1900 // CS:TODO we still have a problem getting properly at the text events of a control because under Carbon
1901 // the MLTE engine registers itself for the key events thus the normal flow never occurs, the only measure for the
1902 // moment is to avoid setting the true focus on the control, the proper solution at the end would be to have
1903 // an alternate path for carbon key events that routes automatically into the same wx flow of events
1907 /* kmUPTextPart is the part code we return to indicate the user has clicked
1908 in the text area of our control */
1909 #define kmUPTextPart 1
1912 /* routines for using existing user pane controls.
1913 These routines are useful for cases where you would like to use an
1914 existing user pane control in, say, a dialog window as a scrolling
1917 /* Utility Routines */
1919 /* kUserClickedToFocusPart is a part code we pass to the SetKeyboardFocus
1920 routine. In our focus switching routine this part code is understood
1921 as meaning 'the user has clicked in the control and we need to switch
1922 the current focus to ourselves before we can continue'. */
1923 #define kUserClickedToFocusPart 100
1925 /* STPTextPaneVars is a structure used for storing the the mUP Control's
1926 internal variables and state information. A handle to this record is
1927 stored in the pane control's reference value field using the
1928 SetControlReference routine. */
1930 class STPTextPaneVars
{
1932 /* OS records referenced */
1933 TXNObject fTXNRec
; /* the txn record */
1934 TXNFrameID fTXNFrame
; /* the txn frame ID */
1935 ControlRef fUserPaneRec
; /* handle to the user pane control */
1936 WindowPtr fOwner
; /* window containing control */
1937 GrafPtr fDrawingEnvironment
; /* grafport where control is drawn */
1939 Boolean fInFocus
; /* true while the focus rect is drawn around the control */
1940 Boolean fIsActive
; /* true while the control is drawn in the active state */
1941 Boolean fTXNObjectActive
; /* reflects the activation state of the text edit record */
1942 Boolean fFocusDrawState
; /* true if focus is drawn (default: true) */
1943 /* calculated locations */
1944 Rect fRBounds
; /* control bounds */
1945 Rect fRTextArea
; /* area where the text is drawn */
1946 Rect fRFocusOutline
; /* rectangle used to draw the focus box */
1947 Rect fRTextOutline
; /* rectangle used to draw the border */
1948 RgnHandle fRTextOutlineRegion
; /* background region for the text, erased before calling TEUpdate */
1949 /* our focus advance override routine */
1950 EventHandlerUPP handlerUPP
;
1951 EventHandlerRef handlerRef
;
1957 /* Univerals Procedure Pointer variables used by the
1958 mUP Control. These variables are set up
1959 the first time that mUPOpenControl is called. */
1960 ControlUserPaneDrawUPP gTPDrawProc
= NULL
;
1961 ControlUserPaneHitTestUPP gTPHitProc
= NULL
;
1962 ControlUserPaneTrackingUPP gTPTrackProc
= NULL
;
1963 ControlUserPaneIdleUPP gTPIdleProc
= NULL
;
1964 ControlUserPaneKeyDownUPP gTPKeyProc
= NULL
;
1965 ControlUserPaneActivateUPP gTPActivateProc
= NULL
;
1966 ControlUserPaneFocusUPP gTPFocusProc
= NULL
;
1968 // one place for calculating all
1969 static void TPCalculateBounds(STPTextPaneVars
*varsp
, const Rect
& bounds
)
1971 SetRect(&varsp
->fRBounds
, bounds
.left
, bounds
.top
, bounds
.right
, bounds
.bottom
);
1972 SetRect(&varsp
->fRFocusOutline
, bounds
.left
, bounds
.top
, bounds
.right
, bounds
.bottom
);
1973 // eventually make TextOutline inset 1,1
1974 SetRect(&varsp
->fRTextOutline
, bounds
.left
, bounds
.top
, bounds
.right
, bounds
.bottom
);
1975 if ( !varsp
->fNoBorders
)
1977 SetRect(&varsp
->fRTextArea
, bounds
.left
+ 2 , bounds
.top
+ (varsp
->fMultiline
? 0 : 2) ,
1978 bounds
.right
- (varsp
->fMultiline
? 0 : 2), bounds
.bottom
- (varsp
->fMultiline
? 0 : 2));
1982 SetRect(&varsp
->fRTextArea
, bounds
.left
, bounds
.top
,
1983 bounds
.right
, bounds
.bottom
);
1987 OSStatus
MLTESetObjectVisibility( STPTextPaneVars
*varsp
, Boolean vis
, long wxStyle
)
1989 OSStatus err
= noErr
;
1990 #if TARGET_API_MAC_OSX
1991 TXNControlTag iControlTags
[1] = { kTXNVisibilityTag
};
1992 TXNControlData iControlData
[1] = {{ vis
}};
1993 err
= ::TXNSetTXNObjectControls( varsp
->fTXNRec
, false, 1, iControlTags
, iControlData
);
1995 wxTextCtrl
* textctrl
= (wxTextCtrl
*) GetControlReference(varsp
->fUserPaneRec
);
1996 if ( vis
&& textctrl
)
1999 UMAGetControlBoundsInWindowCoords( varsp
->fUserPaneRec
, &bounds
);
2000 TPCalculateBounds( varsp
, bounds
) ;
2001 wxMacWindowClipper
cl(textctrl
) ;
2002 TXNSetFrameBounds( varsp
->fTXNRec
, varsp
->fRTextArea
.top
, varsp
->fRTextArea
.left
,
2003 varsp
->fRTextArea
.bottom
, varsp
->fRTextArea
.right
, varsp
->fTXNFrame
);
2004 TXNShowSelection( varsp
->fTXNRec
, kTXNShowStart
);
2009 // make sure we don't miss changes as carbon events are not available for these under classic
2010 static void TPUpdateVisibility(ControlRef theControl
) {
2011 wxTextCtrl
* textctrl
= (wxTextCtrl
*) GetControlReference(theControl
);
2012 if ( textctrl
== NULL
)
2015 STPTextPaneVars
*varsp
= (STPTextPaneVars
*) ((wxMacMLTEClassicControl
*)textctrl
->GetPeer())->m_macTXNvars
;
2018 UMAGetControlBoundsInWindowCoords(theControl
, &bounds
);
2019 if ( textctrl
->MacIsReallyShown() != varsp
->fVisible
)
2021 // invalidate old position
2022 // InvalWindowRect( GetControlOwner( theControl ) , &varsp->fRBounds ) ;
2023 varsp
->fVisible
= textctrl
->MacIsReallyShown() ;
2025 if ( !EqualRect( &bounds
, &varsp
->fRBounds
) )
2028 Rect oldBounds
= varsp
->fRBounds
;
2029 TPCalculateBounds( varsp
, bounds
) ;
2030 // we only recalculate when visible, otherwise scrollbars get drawn at incorrect places
2031 if ( varsp
->fVisible
)
2033 wxMacWindowClipper
cl(textctrl
) ;
2034 TXNSetFrameBounds( varsp
->fTXNRec
, varsp
->fRTextArea
.top
, varsp
->fRTextArea
.left
,
2035 varsp
->fRTextArea
.bottom
, varsp
->fRTextArea
.right
, varsp
->fTXNFrame
);
2037 InvalWindowRect( GetControlOwner( theControl
) , &oldBounds
) ;
2038 InvalWindowRect( GetControlOwner( theControl
) , &varsp
->fRBounds
) ;
2042 // make correct activations
2043 static void TPActivatePaneText(STPTextPaneVars
*varsp
, Boolean setActive
) {
2045 wxTextCtrl
* textctrl
= (wxTextCtrl
*) GetControlReference(varsp
->fUserPaneRec
);
2046 if (varsp
->fTXNObjectActive
!= setActive
&& textctrl
->MacIsReallyShown() )
2048 varsp
->fTXNObjectActive
= setActive
;
2049 TXNActivate(varsp
->fTXNRec
, varsp
->fTXNFrame
, varsp
->fTXNObjectActive
);
2050 if (varsp
->fInFocus
)
2051 TXNFocus( varsp
->fTXNRec
, varsp
->fTXNObjectActive
);
2055 // update focus outlines
2056 static void TPRedrawFocusOutline(STPTextPaneVars
*varsp
) {
2059 if (varsp
->fFocusDrawState
!= (varsp
->fIsActive
&& varsp
->fInFocus
))
2061 varsp
->fFocusDrawState
= (varsp
->fIsActive
&& varsp
->fInFocus
);
2062 DrawThemeFocusRect(&varsp
->fRFocusOutline
, varsp
->fFocusDrawState
);
2066 // update TXN focus state
2067 static void TPFocusPaneText(STPTextPaneVars
*varsp
, Boolean setFocus
) {
2068 wxTextCtrl
* textctrl
= (wxTextCtrl
*) GetControlReference(varsp
->fUserPaneRec
);
2070 if (varsp
->fInFocus
!= setFocus
&& textctrl
->MacIsReallyShown()) {
2071 varsp
->fInFocus
= setFocus
;
2072 TXNFocus( varsp
->fTXNRec
, varsp
->fInFocus
);
2077 static pascal void TPPaneDrawProc(ControlRef theControl
, ControlPartCode thePart
) {
2078 /* set up our globals */
2080 wxTextCtrl
* textctrl
= (wxTextCtrl
*) GetControlReference(theControl
);
2081 if ( textctrl
== NULL
)
2083 TPUpdateVisibility( theControl
) ;
2085 STPTextPaneVars
*varsp
= (STPTextPaneVars
*) ((wxMacMLTEClassicControl
*)textctrl
->GetPeer())->m_macTXNvars
;
2086 if ( textctrl
->MacIsReallyShown() )
2088 wxMacWindowClipper
clipper( textctrl
) ;
2089 TXNDraw(varsp
->fTXNRec
, NULL
);
2090 if ( !varsp
->fNoBorders
)
2091 DrawThemeEditTextFrame(&varsp
->fRTextOutline
, varsp
->fIsActive
? kThemeStateActive
: kThemeStateInactive
);
2092 TPRedrawFocusOutline( varsp
) ;
2098 /* TPPaneHitTestProc is called when the control manager would
2099 like to determine what part of the control the mouse resides over.
2100 We also call this routine from our tracking proc to determine how
2101 to handle mouse clicks. */
2102 static pascal ControlPartCode
TPPaneHitTestProc(ControlRef theControl
, Point where
) {
2103 ControlPartCode result
;
2104 /* set up our locals and lock down our globals*/
2106 wxTextCtrl
* textctrl
= (wxTextCtrl
*) GetControlReference(theControl
);
2107 if ( textctrl
== NULL
)
2109 TPUpdateVisibility( theControl
) ;
2110 STPTextPaneVars
*varsp
= (STPTextPaneVars
*) ((wxMacMLTEClassicControl
*)textctrl
->GetPeer())->m_macTXNvars
;
2111 if (textctrl
->MacIsReallyShown() )
2113 if (PtInRect(where
, &varsp
->fRBounds
))
2114 result
= kmUPTextPart
;
2117 // sometimes we get the coords also in control local coordinates, therefore test again
2118 if ( textctrl
->MacGetTopLevelWindow()->MacUsesCompositing() )
2121 textctrl
->MacClientToRootWindow( &x
, &y
) ;
2125 if (PtInRect(where
, &varsp
->fRBounds
))
2126 result
= kmUPTextPart
;
2138 /* TPPaneTrackingProc is called when the mouse is being held down
2139 over our control. This routine handles clicks in the text area
2140 and in the scroll bar. */
2141 static pascal ControlPartCode
TPPaneTrackingProc(ControlRef theControl
, Point startPt
, ControlActionUPP actionProc
) {
2143 ControlPartCode partCodeResult
;
2144 /* make sure we have some variables... */
2146 wxTextCtrl
* textctrl
= (wxTextCtrl
*) GetControlReference(theControl
);
2147 if ( textctrl
== NULL
)
2149 TPUpdateVisibility( theControl
) ;
2150 STPTextPaneVars
*varsp
= (STPTextPaneVars
*) ((wxMacMLTEClassicControl
*)textctrl
->GetPeer())->m_macTXNvars
;
2151 if (textctrl
->MacIsReallyShown() )
2153 /* we don't do any of these functions unless we're in focus */
2154 if ( ! varsp
->fInFocus
) {
2156 owner
= GetControlOwner(theControl
);
2157 ClearKeyboardFocus(owner
);
2158 SetKeyboardFocus(owner
, theControl
, kUserClickedToFocusPart
);
2160 /* find the location for the click */
2161 // for compositing, we must convert these into toplevel window coordinates, because hittesting expects them
2162 if ( textctrl
->MacGetTopLevelWindow()->MacUsesCompositing() )
2165 textctrl
->MacClientToRootWindow( &x
, &y
) ;
2170 switch (TPPaneHitTestProc(theControl
, startPt
))
2173 /* handle clicks in the text part */
2176 wxMacWindowClipper
clipper( textctrl
) ;
2179 ConvertEventRefToEventRecord( (EventRef
) wxTheApp
->MacGetCurrentEvent() , &rec
) ;
2180 TXNClick( varsp
->fTXNRec
, &rec
);
2187 return partCodeResult
;
2191 /* TPPaneIdleProc is our user pane idle routine. When our text field
2192 is active and in focus, we use this routine to set the cursor. */
2193 static pascal void TPPaneIdleProc(ControlRef theControl
) {
2195 wxTextCtrl
* textctrl
= (wxTextCtrl
*) GetControlReference(theControl
);
2196 if ( textctrl
== NULL
)
2198 TPUpdateVisibility( theControl
) ;
2199 STPTextPaneVars
*varsp
= (STPTextPaneVars
*) ((wxMacMLTEClassicControl
*)textctrl
->GetPeer())->m_macTXNvars
;
2200 if (textctrl
->MacIsReallyShown()) {
2201 /* if we're not active, then we have nothing to say about the cursor */
2202 if (varsp
->fIsActive
) {
2206 wxMacWindowClipper
clipper( textctrl
) ;
2208 /* there's a 'focus thing' and an 'unfocused thing' */
2209 if (varsp
->fInFocus
) {
2210 /* flash the cursor */
2211 SetPort(varsp
->fDrawingEnvironment
);
2212 TXNIdle(varsp
->fTXNRec
);
2213 /* set the cursor */
2214 if (PtInRect(mousep
, &varsp
->fRTextArea
)) {
2216 RectRgn((theRgn
= NewRgn()), &varsp
->fRTextArea
);
2217 TXNAdjustCursor(varsp
->fTXNRec
, theRgn
);
2222 // SetThemeCursor(kThemeArrowCursor);
2225 /* if it's in our bounds, set the cursor */
2226 UMAGetControlBoundsInWindowCoords(theControl
, &bounds
);
2227 if (PtInRect(mousep
, &bounds
))
2229 // SetThemeCursor(kThemeArrowCursor);
2237 /* TPPaneKeyDownProc is called whenever a keydown event is directed
2238 at our control. Here, we direct the keydown event to the text
2239 edit record and redraw the scroll bar and text field as appropriate. */
2240 static pascal ControlPartCode
TPPaneKeyDownProc(ControlRef theControl
,
2241 SInt16 keyCode
, SInt16 charCode
, SInt16 modifiers
) {
2243 wxTextCtrl
* textctrl
= (wxTextCtrl
*) GetControlReference(theControl
);
2244 if ( textctrl
== NULL
)
2246 TPUpdateVisibility( theControl
) ;
2248 STPTextPaneVars
*varsp
= (STPTextPaneVars
*) ((wxMacMLTEClassicControl
*)textctrl
->GetPeer())->m_macTXNvars
;
2249 if (varsp
->fInFocus
)
2251 /* turn autoscrolling on and send the key event to text edit */
2252 wxMacWindowClipper
clipper( textctrl
) ;
2254 memset( &ev
, 0 , sizeof( ev
) ) ;
2256 ev
.modifiers
= modifiers
;
2257 ev
.message
= (( keyCode
<< 8 ) & keyCodeMask
) + ( charCode
& charCodeMask
) ;
2258 TXNKeyDown( varsp
->fTXNRec
, &ev
);
2260 return kControlEntireControl
;
2264 /* TPPaneActivateProc is called when the window containing
2265 the user pane control receives activate events. Here, we redraw
2266 the control and it's text as necessary for the activation state. */
2267 static pascal void TPPaneActivateProc(ControlRef theControl
, Boolean activating
) {
2269 wxTextCtrl
* textctrl
= (wxTextCtrl
*) GetControlReference(theControl
);
2271 if ( textctrl
== NULL
)
2273 TPUpdateVisibility( theControl
) ;
2275 STPTextPaneVars
*varsp
= (STPTextPaneVars
*) ((wxMacMLTEClassicControl
*)textctrl
->GetPeer())->m_macTXNvars
;
2277 varsp
->fIsActive
= activating
;
2278 wxMacWindowClipper
clipper( textctrl
) ;
2279 TPActivatePaneText(varsp
, varsp
->fIsActive
&& varsp
->fInFocus
);
2280 /* redraw the frame */
2281 if ( textctrl
->MacIsReallyShown() )
2283 if ( !varsp
->fNoBorders
)
2284 DrawThemeEditTextFrame(&varsp
->fRTextOutline
, varsp
->fIsActive
? kThemeStateActive
: kThemeStateInactive
);
2285 TPRedrawFocusOutline( varsp
) ;
2290 /* TPPaneFocusProc is called when every the focus changes to or
2291 from our control. Herein, switch the focus appropriately
2292 according to the parameters and redraw the control as
2294 static pascal ControlPartCode
TPPaneFocusProc(ControlRef theControl
, ControlFocusPart action
) {
2295 ControlPartCode focusResult
;
2297 focusResult
= kControlFocusNoPart
;
2298 wxTextCtrl
* textctrl
= (wxTextCtrl
*) GetControlReference(theControl
);
2299 if ( textctrl
== NULL
)
2301 TPUpdateVisibility( theControl
) ;
2302 STPTextPaneVars
*varsp
= (STPTextPaneVars
*) ((wxMacMLTEClassicControl
*)textctrl
->GetPeer())->m_macTXNvars
;
2303 /* if kControlFocusPrevPart and kControlFocusNextPart are received when the user is
2304 tabbing forwards (or shift tabbing backwards) through the items in the dialog,
2305 and kControlFocusNextPart will be received. When the user clicks in our field
2306 and it is not the current focus, then the constant kUserClickedToFocusPart will
2307 be received. The constant kControlFocusNoPart will be received when our control
2308 is the current focus and the user clicks in another control. In your focus routine,
2309 you should respond to these codes as follows:
2311 kControlFocusNoPart - turn off focus and return kControlFocusNoPart. redraw
2312 the control and the focus rectangle as necessary.
2314 kControlFocusPrevPart or kControlFocusNextPart - toggle focus on or off
2315 depending on its current state. redraw the control and the focus rectangle
2316 as appropriate for the new focus state. If the focus state is 'off', return the constant
2317 kControlFocusNoPart, otherwise return a non-zero part code.
2318 kUserClickedToFocusPart - is a constant defined for this example. You should
2319 define your own value for handling click-to-focus type events. */
2320 /* calculate the next highlight state */
2323 case kControlFocusNoPart
:
2324 TPFocusPaneText(varsp
, false);
2325 focusResult
= kControlFocusNoPart
;
2327 case kUserClickedToFocusPart
:
2328 TPFocusPaneText(varsp
, true);
2331 case kControlFocusPrevPart
:
2332 case kControlFocusNextPart
:
2333 TPFocusPaneText(varsp
, ( ! varsp
->fInFocus
));
2334 focusResult
= varsp
->fInFocus
? 1 : kControlFocusNoPart
;
2337 TPActivatePaneText(varsp
, varsp
->fIsActive
&& varsp
->fInFocus
);
2338 /* redraw the text fram and focus rectangle to indicate the
2340 if ( textctrl
->MacIsReallyShown() )
2342 wxMacWindowClipper
c( textctrl
) ;
2343 if ( !varsp
->fNoBorders
)
2344 DrawThemeEditTextFrame(&varsp
->fRTextOutline
, varsp
->fIsActive
? kThemeStateActive
: kThemeStateInactive
);
2345 TPRedrawFocusOutline( varsp
) ;
2350 wxMacMLTEClassicControl::wxMacMLTEClassicControl( wxWindow
*wxPeer
,
2351 const wxString
& str
,
2353 const wxSize
& size
, long style
)
2355 m_font
= wxPeer
->GetFont() ;
2356 m_windowStyle
= style
;
2357 Rect bounds
= wxMacGetBoundsForControl( wxPeer
, pos
, size
) ;
2359 wxMacConvertNewlines10To13( &st
) ;
2363 featurSet
= kControlSupportsEmbedding
| kControlSupportsFocus
| kControlWantsIdle
2364 | kControlWantsActivate
| kControlHandlesTracking
| kControlHasSpecialBackground
2365 | kControlGetsFocusOnClick
| kControlSupportsLiveFeedback
;
2366 /* create the control */
2368 verify_noerr( ::CreateUserPaneControl( MAC_WXHWND(wxPeer
->GetParent()->MacGetTopLevelWindowRef()), &bounds
, featurSet
, &m_controlRef
) );
2371 // wxMacWindowClipper c(wxPeer) ;
2375 if ( wxPeer
->MacIsReallyShown() )
2376 MLTESetObjectVisibility( (STPTextPaneVars
*) m_macTXNvars
, true , style
) ;
2379 // wxMacWindowClipper clipper( wxPeer ) ;
2381 TPUpdateVisibility( m_controlRef
) ;
2383 SetTXNData( st
, kTXNStartOffset
, kTXNEndOffset
) ;
2385 TXNSetSelection( m_txn
, 0, 0);
2386 TXNShowSelection( m_txn
, kTXNShowStart
);
2389 AdjustCreationAttributes( *wxWHITE
, true ) ;
2392 wxMacMLTEClassicControl::~wxMacMLTEClassicControl()
2394 // SetControlReference(m_controlRef , 0) ;
2395 TXNDeleteObject(m_txn
);
2399 void wxMacMLTEClassicControl::VisibilityChanged(bool shown
)
2401 MLTESetObjectVisibility((STPTextPaneVars
*) m_macTXNvars
, shown
, m_windowStyle
) ;
2403 InvalWindowRect( GetControlOwner( m_controlRef
) , &((STPTextPaneVars
*)m_macTXNvars
)->fRBounds
) ;
2406 OSStatus
wxMacMLTEClassicControl::DoCreate()
2409 WindowRef theWindow
;
2411 OSStatus err
= noErr
;
2413 /* set up our globals */
2414 if (gTPDrawProc
== NULL
) gTPDrawProc
= NewControlUserPaneDrawUPP(TPPaneDrawProc
);
2415 if (gTPHitProc
== NULL
) gTPHitProc
= NewControlUserPaneHitTestUPP(TPPaneHitTestProc
);
2416 if (gTPTrackProc
== NULL
) gTPTrackProc
= NewControlUserPaneTrackingUPP(TPPaneTrackingProc
);
2417 if (gTPIdleProc
== NULL
) gTPIdleProc
= NewControlUserPaneIdleUPP(TPPaneIdleProc
);
2418 if (gTPKeyProc
== NULL
) gTPKeyProc
= NewControlUserPaneKeyDownUPP(TPPaneKeyDownProc
);
2419 if (gTPActivateProc
== NULL
) gTPActivateProc
= NewControlUserPaneActivateUPP(TPPaneActivateProc
);
2420 if (gTPFocusProc
== NULL
) gTPFocusProc
= NewControlUserPaneFocusUPP(TPPaneFocusProc
);
2422 /* allocate our private storage */
2423 m_macTXNvars
= (STPTextPaneVars
*) malloc(sizeof(STPTextPaneVars
));
2425 /* set the initial settings for our private data */
2426 m_macTXNvars
->fMultiline
= m_windowStyle
& wxTE_MULTILINE
;
2427 m_macTXNvars
->fNoBorders
= m_windowStyle
& wxNO_BORDER
;
2428 m_macTXNvars
->fInFocus
= false;
2429 m_macTXNvars
->fIsActive
= true;
2430 m_macTXNvars
->fTXNObjectActive
= false;
2431 m_macTXNvars
->fFocusDrawState
= false ;
2432 m_macTXNvars
->fUserPaneRec
= m_controlRef
;
2433 m_macTXNvars
->fVisible
= true ;
2435 theWindow
= m_macTXNvars
->fOwner
= GetControlOwner(m_controlRef
);
2437 m_macTXNvars
->fDrawingEnvironment
= (GrafPtr
) GetWindowPort(theWindow
);
2439 /* set up the user pane procedures */
2440 SetControlData(m_controlRef
, kControlEntireControl
, kControlUserPaneDrawProcTag
, sizeof(gTPDrawProc
), &gTPDrawProc
);
2441 SetControlData(m_controlRef
, kControlEntireControl
, kControlUserPaneHitTestProcTag
, sizeof(gTPHitProc
), &gTPHitProc
);
2442 SetControlData(m_controlRef
, kControlEntireControl
, kControlUserPaneTrackingProcTag
, sizeof(gTPTrackProc
), &gTPTrackProc
);
2443 SetControlData(m_controlRef
, kControlEntireControl
, kControlUserPaneIdleProcTag
, sizeof(gTPIdleProc
), &gTPIdleProc
);
2444 SetControlData(m_controlRef
, kControlEntireControl
, kControlUserPaneKeyDownProcTag
, sizeof(gTPKeyProc
), &gTPKeyProc
);
2445 SetControlData(m_controlRef
, kControlEntireControl
, kControlUserPaneActivateProcTag
, sizeof(gTPActivateProc
), &gTPActivateProc
);
2446 SetControlData(m_controlRef
, kControlEntireControl
, kControlUserPaneFocusProcTag
, sizeof(gTPFocusProc
), &gTPFocusProc
);
2448 /* calculate the rectangles used by the control */
2449 UMAGetControlBoundsInWindowCoords(m_controlRef
, &bounds
);
2450 m_macTXNvars
->fRTextOutlineRegion
= NewRgn() ;
2451 TPCalculateBounds( m_macTXNvars
, bounds
) ;
2453 /* set up the drawing environment */
2454 SetPort(m_macTXNvars
->fDrawingEnvironment
);
2456 /* create the new edit field */
2458 TXNFrameOptions frameOptions
= FrameOptionsFromWXStyle( m_windowStyle
) ;
2460 verify_noerr(TXNNewObject(NULL
, m_macTXNvars
->fOwner
, &m_macTXNvars
->fRTextArea
,
2462 kTXNTextEditStyleFrameType
,
2464 kTXNSystemDefaultEncoding
,
2465 &m_macTXNvars
->fTXNRec
, &m_macTXNvars
->fTXNFrame
, (TXNObjectRefcon
) m_macTXNvars
));
2466 m_txn
= m_macTXNvars
->fTXNRec
;
2468 /* perform final activations and setup for our text field. Here,
2469 we assume that the window is going to be the 'active' window. */
2470 TPActivatePaneText(m_macTXNvars
, m_macTXNvars
->fIsActive
&& m_macTXNvars
->fInFocus
);
2475 // ----------------------------------------------------------------------------
2476 // MLTE control implementation (OSX part)
2477 // ----------------------------------------------------------------------------
2479 #if TARGET_API_MAC_OSX
2481 #if MAC_OS_X_VERSION_MAX_ALLOWED > MAC_OS_X_VERSION_10_2
2483 wxMacMLTEHIViewControl::wxMacMLTEHIViewControl( wxWindow
*wxPeer
,
2484 const wxString
& str
,
2486 const wxSize
& size
, long style
)
2488 m_font
= wxPeer
->GetFont() ;
2489 m_windowStyle
= style
;
2490 Rect bounds
= wxMacGetBoundsForControl( wxPeer
, pos
, size
) ;
2492 wxMacConvertNewlines10To13( &st
) ;
2494 HIRect hr
= { bounds
.left
, bounds
.top
, bounds
.right
- bounds
.left
, bounds
.bottom
- bounds
.top
} ;
2496 m_scrollView
= NULL
;
2497 TXNFrameOptions frameOptions
= FrameOptionsFromWXStyle( style
) ;
2498 if ( frameOptions
& (kTXNWantVScrollBarMask
|kTXNWantHScrollBarMask
) )
2500 HIScrollViewCreate(( frameOptions
& kTXNWantHScrollBarMask
? kHIScrollViewOptionsHorizScroll
: 0) |
2501 ( frameOptions
& kTXNWantVScrollBarMask
? kHIScrollViewOptionsVertScroll
: 0 ) , &m_scrollView
) ;
2503 HIViewSetFrame( m_scrollView
, &hr
);
2504 HIViewSetVisible( m_scrollView
, true );
2508 HITextViewCreate( NULL
, 0, frameOptions
, &m_textView
) ;
2509 m_txn
= HITextViewGetTXNObject( m_textView
) ;
2510 HIViewSetVisible( m_textView
, true ) ;
2513 HIViewAddSubview( m_scrollView
, m_textView
) ;
2514 m_controlRef
= m_scrollView
;
2515 wxPeer
->MacInstallEventHandler( (WXWidget
) m_textView
) ;
2519 HIViewSetFrame( m_textView
, &hr
);
2520 m_controlRef
= m_textView
;
2524 SetTXNData( st
, kTXNStartOffset
, kTXNEndOffset
) ;
2526 TXNSetSelection( m_txn
, 0, 0);
2527 TXNShowSelection( m_txn
, kTXNShowStart
);
2529 AdjustCreationAttributes( *wxWHITE
, true ) ;
2532 OSStatus
wxMacMLTEHIViewControl::SetFocus( ControlFocusPart focusPart
)
2534 return SetKeyboardFocus( GetControlOwner( m_textView
) ,
2535 m_textView
, focusPart
) ;
2538 bool wxMacMLTEHIViewControl::HasFocus() const
2540 ControlRef control
;
2541 GetKeyboardFocus( GetUserFocusWindow() , &control
) ;
2542 return control
== m_textView
;
2545 bool wxMacMLTEHIViewControl::NeedsFocusRect() const
2547 return m_windowStyle
& wxNO_BORDER
? false : true;
2550 #endif // MAC_OS_X_VERSION_MAX_ALLOWED > MAC_OS_X_VERSION_10_2
2555 #endif // wxUSE_TEXTCTRL