X-Git-Url: https://git.saurik.com/wxWidgets.git/blobdiff_plain/489468feaa08b8f504735eecca522fb8d0f825d2..c9ed413ab4f5673ffff00198dc6ce1397398bda4:/src/osx/carbon/textctrl.cpp?ds=inline diff --git a/src/osx/carbon/textctrl.cpp b/src/osx/carbon/textctrl.cpp index b162a58860..267680fca8 100644 --- a/src/osx/carbon/textctrl.cpp +++ b/src/osx/carbon/textctrl.cpp @@ -1,5 +1,5 @@ ///////////////////////////////////////////////////////////////////////////// -// Name: src/mac/carbon/textctrl.cpp +// Name: src/osx/carbon/textctrl.cpp // Purpose: wxTextCtrl // Author: Stefan Csomor // Modified by: Ryan Norton (MLTE GetLineLength and GetLineText) @@ -46,8 +46,8 @@ #include "wx/sysopt.h" #include "wx/thread.h" -#include "wx/mac/uma.h" -#include "wx/mac/carbon/private/mactext.h" +#include "wx/osx/private.h" +#include "wx/osx/carbon/private/mactext.h" class wxMacFunctor { @@ -144,7 +144,7 @@ void* wxMacMPRemoteGUICall( classtype *object , void (classtype::*function)( con class WXDLLEXPORT wxMacPortSaver { - DECLARE_NO_COPY_CLASS(wxMacPortSaver) + wxDECLARE_NO_COPY_CLASS(wxMacPortSaver); public: wxMacPortSaver( GrafPtr port ); @@ -160,7 +160,7 @@ private : class WXDLLEXPORT wxMacWindowClipper : public wxMacPortSaver { - DECLARE_NO_COPY_CLASS(wxMacWindowClipper) + wxDECLARE_NO_COPY_CLASS(wxMacWindowClipper); public: wxMacWindowClipper( const wxWindow* win ); @@ -218,1058 +218,193 @@ wxMacWindowClipper::~wxMacWindowClipper() // common parts for implementations based on MLTE -class wxMacMLTEControl : public wxMacTextControl +class wxMacMLTEControl : public wxMacControl, public wxTextWidgetImpl { public : wxMacMLTEControl( wxTextCtrl *peer ) ; + ~wxMacMLTEControl() {} + + virtual bool CanFocus() const + { return true; } virtual wxString GetStringValue() const ; virtual void SetStringValue( const wxString &str ) ; - static TXNFrameOptions FrameOptionsFromWXStyle( long wxStyle ) ; - - void AdjustCreationAttributes( const wxColour& background, bool visible ) ; - - virtual void SetFont( const wxFont & font, const wxColour& foreground, long windowStyle ) ; - virtual void SetBackgroundColour(const wxColour& col ); - virtual void SetStyle( long start, long end, const wxTextAttr& style ) ; - virtual void Copy() ; - virtual void Cut() ; - virtual void Paste() ; - virtual bool CanPaste() const ; - virtual void SetEditable( bool editable ) ; - virtual wxTextPos GetLastPosition() const ; - virtual void Replace( long from, long to, const wxString &str ) ; - virtual void Remove( long from, long to ) ; - virtual void GetSelection( long* from, long* to ) const ; - virtual void SetSelection( long from, long to ) ; - - virtual void WriteText( const wxString& str ) ; - - virtual bool HasOwnContextMenu() const - { - TXNCommandEventSupportOptions options ; - TXNGetCommandEventSupport( m_txn , & options ) ; - return options & kTXNSupportEditCommandProcessing ; - } - - virtual void CheckSpelling(bool check) - { - TXNSetSpellCheckAsYouType( m_txn, (Boolean) check ); - } - virtual void Clear() ; - - virtual bool CanUndo() const ; - virtual void Undo() ; - virtual bool CanRedo() const; - virtual void Redo() ; - virtual int GetNumberOfLines() const ; - virtual long XYToPosition(long x, long y) const ; - virtual bool PositionToXY(long pos, long *x, long *y) const ; - virtual void ShowPosition( long pos ) ; - virtual int GetLineLength(long lineNo) const ; - virtual wxString GetLineText(long lineNo) const ; - - void SetTXNData( const wxString& st , TXNOffset start , TXNOffset end ) ; - TXNObject GetTXNObject() { return m_txn ; } - -protected : - void TXNSetAttribute( const wxTextAttr& style , long from , long to ) ; - - TXNObject m_txn ; -} ; - -// implementation available under OSX - -class wxMacMLTEHIViewControl : public wxMacMLTEControl -{ -public : - wxMacMLTEHIViewControl( wxTextCtrl *wxPeer, - const wxString& str, - const wxPoint& pos, - const wxSize& size, long style ) ; - virtual ~wxMacMLTEHIViewControl() ; - - virtual OSStatus SetFocus( ControlFocusPart focusPart ) ; - virtual bool HasFocus() const ; - virtual void SetBackgroundColour(const wxColour& col ) ; - -protected : - HIViewRef m_scrollView ; - HIViewRef m_textView ; -}; - -// 'classic' MLTE implementation - -class wxMacMLTEClassicControl : public wxMacMLTEControl -{ -public : - wxMacMLTEClassicControl( wxTextCtrl *wxPeer, - const wxString& str, - const wxPoint& pos, - const wxSize& size, long style ) ; - virtual ~wxMacMLTEClassicControl() ; - - virtual void VisibilityChanged(bool shown) ; - virtual void SuperChangedPosition() ; - - virtual void MacControlUserPaneDrawProc(wxInt16 part) ; - virtual wxInt16 MacControlUserPaneHitTestProc(wxInt16 x, wxInt16 y) ; - virtual wxInt16 MacControlUserPaneTrackingProc(wxInt16 x, wxInt16 y, void* actionProc) ; - virtual void MacControlUserPaneIdleProc() ; - virtual wxInt16 MacControlUserPaneKeyDownProc(wxInt16 keyCode, wxInt16 charCode, wxInt16 modifiers) ; - virtual void MacControlUserPaneActivateProc(bool activating) ; - virtual wxInt16 MacControlUserPaneFocusProc(wxInt16 action) ; - virtual void MacControlUserPaneBackgroundProc(void* info) ; - - virtual bool SetupCursor( const wxPoint& WXUNUSED(pt) ) - { - MacControlUserPaneIdleProc(); - return true; - } - - virtual void SetRect( Rect *r ) ; - -protected : - OSStatus DoCreate(); - - void MacUpdatePosition() ; - void MacActivatePaneText(bool setActive) ; - void MacFocusPaneText(bool setFocus) ; - void MacSetObjectVisibility(bool vis) ; - -private : - TXNFrameID m_txnFrameID ; - GrafPtr m_txnPort ; - WindowRef m_txnWindow ; - // bounds of the control as we last did set the txn frames - Rect m_txnControlBounds ; - Rect m_txnVisBounds ; - - static pascal void TXNScrollActionProc( ControlRef controlRef , ControlPartCode partCode ) ; - static pascal void TXNScrollInfoProc( - SInt32 iValue, SInt32 iMaximumValue, - TXNScrollBarOrientation iScrollBarOrientation, SInt32 iRefCon ) ; - - ControlRef m_sbHorizontal ; - SInt32 m_lastHorizontalValue ; - ControlRef m_sbVertical ; - SInt32 m_lastVerticalValue ; -}; - - -IMPLEMENT_DYNAMIC_CLASS(wxTextCtrl, wxTextCtrlBase) - -BEGIN_EVENT_TABLE(wxTextCtrl, wxTextCtrlBase) - EVT_DROP_FILES(wxTextCtrl::OnDropFiles) - EVT_CHAR(wxTextCtrl::OnChar) - EVT_MENU(wxID_CUT, wxTextCtrl::OnCut) - EVT_MENU(wxID_COPY, wxTextCtrl::OnCopy) - EVT_MENU(wxID_PASTE, wxTextCtrl::OnPaste) - EVT_MENU(wxID_UNDO, wxTextCtrl::OnUndo) - EVT_MENU(wxID_REDO, wxTextCtrl::OnRedo) - EVT_MENU(wxID_CLEAR, wxTextCtrl::OnDelete) - EVT_MENU(wxID_SELECTALL, wxTextCtrl::OnSelectAll) - - EVT_CONTEXT_MENU(wxTextCtrl::OnContextMenu) - - EVT_UPDATE_UI(wxID_CUT, wxTextCtrl::OnUpdateCut) - EVT_UPDATE_UI(wxID_COPY, wxTextCtrl::OnUpdateCopy) - EVT_UPDATE_UI(wxID_PASTE, wxTextCtrl::OnUpdatePaste) - EVT_UPDATE_UI(wxID_UNDO, wxTextCtrl::OnUpdateUndo) - EVT_UPDATE_UI(wxID_REDO, wxTextCtrl::OnUpdateRedo) - EVT_UPDATE_UI(wxID_CLEAR, wxTextCtrl::OnUpdateDelete) - EVT_UPDATE_UI(wxID_SELECTALL, wxTextCtrl::OnUpdateSelectAll) -END_EVENT_TABLE() - - -void wxTextCtrl::Init() -{ - m_editable = true ; - m_dirty = false; - - m_maxLength = 0; - m_privateContextMenu = NULL; - m_triggerOnSetValue = true ; -} - -wxTextCtrl::~wxTextCtrl() -{ - delete m_privateContextMenu; -} - -bool wxTextCtrl::Create( wxWindow *parent, - wxWindowID id, - const wxString& str, - const wxPoint& pos, - const wxSize& size, - long style, - const wxValidator& validator, - const wxString& name ) -{ - m_macIsUserPane = false ; - m_editable = true ; - - if ( ! (style & wxNO_BORDER) ) - style = (style & ~wxBORDER_MASK) | wxSUNKEN_BORDER ; - - if ( !wxTextCtrlBase::Create( parent, id, pos, size, style & ~(wxHSCROLL | wxVSCROLL), validator, name ) ) - return false; - - if ( m_windowStyle & wxTE_MULTILINE ) - { - // always turn on this style for multi-line controls - m_windowStyle |= wxTE_PROCESS_ENTER; - style |= wxTE_PROCESS_ENTER ; - } - - CreatePeer( str, pos, size, style ); - - MacPostControlCreate(pos, size) ; - - // only now the embedding is correct and we can do a positioning update - - MacSuperChangedPosition() ; - - if ( m_windowStyle & wxTE_READONLY) - SetEditable( false ) ; - - SetCursor( wxCursor( wxCURSOR_IBEAM ) ) ; - - return true; -} - -void wxTextCtrl::CreatePeer( - const wxString& str, - const wxPoint& pos, - const wxSize& size, long style ) -{ - bool forceMLTE = false ; - -#if wxUSE_SYSTEM_OPTIONS - if (wxSystemOptions::HasOption( wxMAC_TEXTCONTROL_USE_MLTE ) && (wxSystemOptions::GetOptionInt( wxMAC_TEXTCONTROL_USE_MLTE ) == 1)) - { - forceMLTE = true ; - } -#endif - - if ( UMAGetSystemVersion() >= 0x1050 ) - forceMLTE = false; - - if ( !forceMLTE ) - { - if ( m_windowStyle & wxTE_MULTILINE || ( UMAGetSystemVersion() >= 0x1050 ) ) - m_peer = new wxMacMLTEHIViewControl( this , str , pos , size , style ) ; - } - - if ( !m_peer ) - { - if ( !(m_windowStyle & wxTE_MULTILINE) && !forceMLTE ) - { - m_peer = new wxMacUnicodeTextControl( this , str , pos , size , style ) ; - } - } - - // the horizontal single line scrolling bug that made us keep the classic implementation - // is fixed in 10.5 -#if MAC_OS_X_VERSION_MIN_REQUIRED < MAC_OS_X_VERSION_10_5 - if ( !m_peer ) - m_peer = new wxMacMLTEClassicControl( this , str , pos , size , style ) ; -#endif -} - -void wxTextCtrl::MacSuperChangedPosition() -{ - wxWindow::MacSuperChangedPosition() ; - GetPeer()->SuperChangedPosition() ; -} - -void wxTextCtrl::MacVisibilityChanged() -{ - GetPeer()->VisibilityChanged( GetPeer()->IsVisible() ); -} - -void wxTextCtrl::MacCheckSpelling(bool check) -{ - GetPeer()->CheckSpelling(check); -} - -wxString wxTextCtrl::GetValue() const -{ - return GetPeer()->GetStringValue() ; -} - -void wxTextCtrl::GetSelection(long* from, long* to) const -{ - GetPeer()->GetSelection( from , to ) ; -} - -void wxTextCtrl::DoSetValue(const wxString& str, int flags) -{ - // optimize redraws - if ( GetValue() == str ) - return; - - GetPeer()->SetStringValue( str ) ; - - if ( (flags & SetValue_SendEvent) && m_triggerOnSetValue ) - { - SendTextUpdatedEvent(); - } -} - -void wxTextCtrl::SetMaxLength(unsigned long len) -{ - m_maxLength = len ; -} - -bool wxTextCtrl::SetFont( const wxFont& font ) -{ - if ( !wxTextCtrlBase::SetFont( font ) ) - return false ; - - GetPeer()->SetFont( font , GetForegroundColour() , GetWindowStyle() ) ; - - return true ; -} - -bool wxTextCtrl::SetStyle(long start, long end, const wxTextAttr& style) -{ - GetPeer()->SetStyle( start , end , style ) ; - - return true ; -} - -bool wxTextCtrl::SetDefaultStyle(const wxTextAttr& style) -{ - wxTextCtrlBase::SetDefaultStyle( style ) ; - SetStyle( kTXNUseCurrentSelection , kTXNUseCurrentSelection , GetDefaultStyle() ) ; - - return true ; -} - -// Clipboard operations - -void wxTextCtrl::Copy() -{ - if (CanCopy()) - GetPeer()->Copy() ; -} - -void wxTextCtrl::Cut() -{ - if (CanCut()) - { - GetPeer()->Cut() ; - - wxCommandEvent event( wxEVT_COMMAND_TEXT_UPDATED, m_windowId ); - event.SetEventObject( this ); - HandleWindowEvent( event ); - } -} - -void wxTextCtrl::Paste() -{ - if (CanPaste()) - { - GetPeer()->Paste() ; - - // TODO: eventually we should add setting the default style again - - wxCommandEvent event( wxEVT_COMMAND_TEXT_UPDATED, m_windowId ); - event.SetEventObject( this ); - HandleWindowEvent( event ); - } -} - -bool wxTextCtrl::CanCopy() const -{ - // Can copy if there's a selection - long from, to; - GetSelection( &from, &to ); - - return (from != to); -} - -bool wxTextCtrl::CanCut() const -{ - if ( !IsEditable() ) - return false; - - // Can cut if there's a selection - long from, to; - GetSelection( &from, &to ); - - return (from != to); -} - -bool wxTextCtrl::CanPaste() const -{ - if (!IsEditable()) - return false; - - return GetPeer()->CanPaste() ; -} - -void wxTextCtrl::SetEditable(bool editable) -{ - if ( editable != m_editable ) - { - m_editable = editable ; - GetPeer()->SetEditable( editable ) ; - } -} - -void wxTextCtrl::SetInsertionPoint(long pos) -{ - SetSelection( pos , pos ) ; -} - -void wxTextCtrl::SetInsertionPointEnd() -{ - wxTextPos pos = GetLastPosition(); - SetInsertionPoint( pos ); -} - -long wxTextCtrl::GetInsertionPoint() const -{ - long begin, end ; - GetSelection( &begin , &end ) ; - - return begin ; -} - -wxTextPos wxTextCtrl::GetLastPosition() const -{ - return GetPeer()->GetLastPosition() ; -} - -void wxTextCtrl::Replace(long from, long to, const wxString& str) -{ - GetPeer()->Replace( from , to , str ) ; -} - -void wxTextCtrl::Remove(long from, long to) -{ - GetPeer()->Remove( from , to ) ; -} - -void wxTextCtrl::SetSelection(long from, long to) -{ - GetPeer()->SetSelection( from , to ) ; -} - -void wxTextCtrl::WriteText(const wxString& str) -{ - // TODO: this MPRemoting will be moved into a remoting peer proxy for any command - if ( !wxIsMainThread() ) - { - // unfortunately CW 8 is not able to correctly deduce the template types, - // so we have to instantiate explicitly - wxMacMPRemoteGUICall( this , &wxTextCtrl::WriteText , str ) ; - - return ; - } - - GetPeer()->WriteText( str ) ; -} - -void wxTextCtrl::AppendText(const wxString& text) -{ - SetInsertionPointEnd(); - WriteText( text ); -} - -void wxTextCtrl::Clear() -{ - GetPeer()->Clear() ; -} - -bool wxTextCtrl::IsModified() const -{ - return m_dirty; -} - -bool wxTextCtrl::IsEditable() const -{ - return IsEnabled() && m_editable ; -} - -bool wxTextCtrl::AcceptsFocus() const -{ - // we don't want focus if we can't be edited - return /*IsEditable() && */ wxControl::AcceptsFocus(); -} - -wxSize wxTextCtrl::DoGetBestSize() const -{ - int wText, hText; - - // these are the numbers from the HIG: - // we reduce them by the borders first - wText = 100 ; - - switch ( m_windowVariant ) - { - case wxWINDOW_VARIANT_NORMAL : - hText = 22 - 6 ; - break ; - - case wxWINDOW_VARIANT_SMALL : - hText = 19 - 6 ; - break ; - - case wxWINDOW_VARIANT_MINI : - hText = 15 - 6 ; - break ; - - default : - hText = 22 - 6; - break ; - } - - // as the above numbers have some free space around the text - // we get 5 lines like this anyway - if ( m_windowStyle & wxTE_MULTILINE ) - hText *= 5 ; - - if ( !HasFlag(wxNO_BORDER) ) - hText += 6 ; - - return wxSize(wText, hText); -} - -// ---------------------------------------------------------------------------- -// Undo/redo -// ---------------------------------------------------------------------------- - -void wxTextCtrl::Undo() -{ - if (CanUndo()) - GetPeer()->Undo() ; -} - -void wxTextCtrl::Redo() -{ - if (CanRedo()) - GetPeer()->Redo() ; -} - -bool wxTextCtrl::CanUndo() const -{ - if ( !IsEditable() ) - return false ; - - return GetPeer()->CanUndo() ; -} - -bool wxTextCtrl::CanRedo() const -{ - if ( !IsEditable() ) - return false ; - - return GetPeer()->CanRedo() ; -} - -void wxTextCtrl::MarkDirty() -{ - m_dirty = true; -} - -void wxTextCtrl::DiscardEdits() -{ - m_dirty = false; -} - -int wxTextCtrl::GetNumberOfLines() const -{ - return GetPeer()->GetNumberOfLines() ; -} - -long wxTextCtrl::XYToPosition(long x, long y) const -{ - return GetPeer()->XYToPosition( x , y ) ; -} - -bool wxTextCtrl::PositionToXY(long pos, long *x, long *y) const -{ - return GetPeer()->PositionToXY( pos , x , y ) ; -} - -void wxTextCtrl::ShowPosition(long pos) -{ - return GetPeer()->ShowPosition(pos) ; -} - -int wxTextCtrl::GetLineLength(long lineNo) const -{ - return GetPeer()->GetLineLength(lineNo) ; -} - -wxString wxTextCtrl::GetLineText(long lineNo) const -{ - return GetPeer()->GetLineText(lineNo) ; -} - -void wxTextCtrl::Command(wxCommandEvent & event) -{ - SetValue(event.GetString()); - ProcessCommand(event); -} - -void wxTextCtrl::OnDropFiles(wxDropFilesEvent& event) -{ - // By default, load the first file into the text window. - if (event.GetNumberOfFiles() > 0) - LoadFile( event.GetFiles()[0] ); -} - -void wxTextCtrl::OnChar(wxKeyEvent& event) -{ - int key = event.GetKeyCode() ; - bool eat_key = false ; - long from, to; - - if ( key == 'a' && event.MetaDown() ) - { - SelectAll() ; - - return ; - } - - if ( key == 'c' && event.MetaDown() ) - { - if ( CanCopy() ) - Copy() ; - - return ; - } - - if ( !IsEditable() && key != WXK_LEFT && key != WXK_RIGHT && key != WXK_DOWN && key != WXK_UP && key != WXK_TAB && - !( key == WXK_RETURN && ( (m_windowStyle & wxTE_PROCESS_ENTER) || (m_windowStyle & wxTE_MULTILINE) ) ) -// && key != WXK_PAGEUP && key != WXK_PAGEDOWN && key != WXK_HOME && key != WXK_END - ) - { - // eat it - return ; - } - - // Check if we have reached the max # of chars (if it is set), but still - // allow navigation and deletion - GetSelection( &from, &to ); - if ( !IsMultiLine() && m_maxLength && GetValue().length() >= m_maxLength && - key != WXK_LEFT && key != WXK_RIGHT && key != WXK_TAB && key != WXK_UP && key != WXK_DOWN && - key != WXK_BACK && key != WXK_DELETE && !( key == WXK_RETURN && (m_windowStyle & wxTE_PROCESS_ENTER) ) && - from == to ) - { - // eat it, we don't want to add more than allowed # of characters - - // TODO: generate EVT_TEXT_MAXLEN() - return; - } - - // assume that any key not processed yet is going to modify the control - m_dirty = true; - - if ( key == 'v' && event.MetaDown() ) - { - if ( CanPaste() ) - Paste() ; - - return ; - } - - if ( key == 'x' && event.MetaDown() ) - { - if ( CanCut() ) - Cut() ; - - return ; - } - - switch ( key ) - { - case WXK_RETURN: - if (m_windowStyle & wxTE_PROCESS_ENTER) - { - wxCommandEvent event(wxEVT_COMMAND_TEXT_ENTER, m_windowId); - event.SetEventObject( this ); - event.SetString( GetValue() ); - if ( HandleWindowEvent(event) ) - return; - } - - if ( !(m_windowStyle & wxTE_MULTILINE) ) - { - wxTopLevelWindow *tlw = wxDynamicCast(wxGetTopLevelParent(this), wxTopLevelWindow); - if ( tlw && tlw->GetDefaultItem() ) - { - wxButton *def = wxDynamicCast(tlw->GetDefaultItem(), wxButton); - if ( def && def->IsEnabled() ) - { - wxCommandEvent event(wxEVT_COMMAND_BUTTON_CLICKED, def->GetId() ); - event.SetEventObject(def); - def->Command(event); - - return ; - } - } - - // this will make wxWidgets eat the ENTER key so that - // we actually prevent line wrapping in a single line text control - eat_key = true; - } - break; - - case WXK_TAB: - if ( !(m_windowStyle & wxTE_PROCESS_TAB)) - { - int flags = 0; - if (!event.ShiftDown()) - flags |= wxNavigationKeyEvent::IsForward ; - if (event.ControlDown()) - flags |= wxNavigationKeyEvent::WinChange ; - Navigate(flags); - - return; - } - else - { - // This is necessary (don't know why); - // otherwise the tab will not be inserted. - WriteText(wxT("\t")); - eat_key = true; - } - break; - - default: - break; - } - - if (!eat_key) - { - // perform keystroke handling - event.Skip(true) ; - } - - if ( ( key >= 0x20 && key < WXK_START ) || - ( key >= WXK_NUMPAD0 && key <= WXK_DIVIDE ) || - key == WXK_RETURN || - key == WXK_DELETE || - key == WXK_BACK) - { - wxCommandEvent event1(wxEVT_COMMAND_TEXT_UPDATED, m_windowId); - event1.SetEventObject( this ); - wxPostEvent( GetEventHandler(), event1 ); - } -} - -// ---------------------------------------------------------------------------- -// standard handlers for standard edit menu events -// ---------------------------------------------------------------------------- - -void wxTextCtrl::OnCut(wxCommandEvent& WXUNUSED(event)) -{ - Cut(); -} - -void wxTextCtrl::OnCopy(wxCommandEvent& WXUNUSED(event)) -{ - Copy(); -} - -void wxTextCtrl::OnPaste(wxCommandEvent& WXUNUSED(event)) -{ - Paste(); -} - -void wxTextCtrl::OnUndo(wxCommandEvent& WXUNUSED(event)) -{ - Undo(); -} - -void wxTextCtrl::OnRedo(wxCommandEvent& WXUNUSED(event)) -{ - Redo(); -} - -void wxTextCtrl::OnDelete(wxCommandEvent& WXUNUSED(event)) -{ - long from, to; - - GetSelection( &from, &to ); - if (from != -1 && to != -1) - Remove( from, to ); -} - -void wxTextCtrl::OnSelectAll(wxCommandEvent& WXUNUSED(event)) -{ - SetSelection(-1, -1); -} - -void wxTextCtrl::OnUpdateCut(wxUpdateUIEvent& event) -{ - event.Enable( CanCut() ); -} - -void wxTextCtrl::OnUpdateCopy(wxUpdateUIEvent& event) -{ - event.Enable( CanCopy() ); -} - -void wxTextCtrl::OnUpdatePaste(wxUpdateUIEvent& event) -{ - event.Enable( CanPaste() ); -} - -void wxTextCtrl::OnUpdateUndo(wxUpdateUIEvent& event) -{ - event.Enable( CanUndo() ); -} - -void wxTextCtrl::OnUpdateRedo(wxUpdateUIEvent& event) -{ - event.Enable( CanRedo() ); -} - -void wxTextCtrl::OnUpdateDelete(wxUpdateUIEvent& event) -{ - long from, to; + static TXNFrameOptions FrameOptionsFromWXStyle( long wxStyle ) ; - GetSelection( &from, &to ); - event.Enable( from != -1 && to != -1 && from != to && IsEditable() ) ; -} + void AdjustCreationAttributes( const wxColour& background, bool visible ) ; -void wxTextCtrl::OnUpdateSelectAll(wxUpdateUIEvent& event) -{ - event.Enable(GetLastPosition() > 0); -} + virtual void SetFont( const wxFont & font, const wxColour& foreground, long windowStyle, bool ignoreBlack ) ; + virtual void SetBackgroundColour(const wxColour& col ); + virtual void SetStyle( long start, long end, const wxTextAttr& style ) ; + virtual void Copy() ; + virtual void Cut() ; + virtual void Paste() ; + virtual bool CanPaste() const ; + virtual void SetEditable( bool editable ) ; + virtual long GetLastPosition() const ; + virtual void Replace( long from, long to, const wxString &str ) ; + virtual void Remove( long from, long to ) ; + virtual void GetSelection( long* from, long* to ) const ; + virtual void SetSelection( long from, long to ) ; -// CS: Context Menus only work with MLTE implementations or non-multiline HIViews at the moment + virtual void WriteText( const wxString& str ) ; -void wxTextCtrl::OnContextMenu(wxContextMenuEvent& event) -{ - if ( GetPeer()->HasOwnContextMenu() ) + virtual bool HasOwnContextMenu() const { - event.Skip() ; - return ; + TXNCommandEventSupportOptions options ; + TXNGetCommandEventSupport( m_txn , & options ) ; + return options & kTXNSupportEditCommandProcessing ; } - if (m_privateContextMenu == NULL) + virtual void CheckSpelling(bool check) { - m_privateContextMenu = new wxMenu; - m_privateContextMenu->Append(wxID_UNDO, _("&Undo")); - m_privateContextMenu->Append(wxID_REDO, _("&Redo")); - m_privateContextMenu->AppendSeparator(); - m_privateContextMenu->Append(wxID_CUT, _("Cu&t")); - m_privateContextMenu->Append(wxID_COPY, _("&Copy")); - m_privateContextMenu->Append(wxID_PASTE, _("&Paste")); - m_privateContextMenu->Append(wxID_CLEAR, _("&Delete")); - m_privateContextMenu->AppendSeparator(); - m_privateContextMenu->Append(wxID_SELECTALL, _("Select &All")); + TXNSetSpellCheckAsYouType( m_txn, (Boolean) check ); } + virtual void Clear() ; - if (m_privateContextMenu != NULL) - PopupMenu(m_privateContextMenu); -} - -bool wxTextCtrl::MacSetupCursor( const wxPoint& pt ) -{ - if ( !GetPeer()->SetupCursor( pt ) ) - return wxWindow::MacSetupCursor( pt ) ; - else - return true ; -} - -// ---------------------------------------------------------------------------- -// implementation base class -// ---------------------------------------------------------------------------- - -wxMacTextControl::wxMacTextControl(wxTextCtrl* peer) : - wxMacControl( peer ) -{ -} + virtual bool CanUndo() const ; + virtual void Undo() ; + virtual bool CanRedo() const; + virtual void Redo() ; + virtual int GetNumberOfLines() const ; + virtual long XYToPosition(long x, long y) const ; + virtual bool PositionToXY(long pos, long *x, long *y) const ; + virtual void ShowPosition( long pos ) ; + virtual int GetLineLength(long lineNo) const ; + virtual wxString GetLineText(long lineNo) const ; -wxMacTextControl::~wxMacTextControl() -{ -} + void SetTXNData( const wxString& st , TXNOffset start , TXNOffset end ) ; + TXNObject GetTXNObject() { return m_txn ; } -void wxMacTextControl::SetStyle(long WXUNUSED(start), - long WXUNUSED(end), - const wxTextAttr& WXUNUSED(style)) -{ -} +protected : + void TXNSetAttribute( const wxTextAttr& style , long from , long to ) ; -void wxMacTextControl::Copy() -{ -} + TXNObject m_txn ; +} ; -void wxMacTextControl::Cut() -{ -} +// implementation available under OSX -void wxMacTextControl::Paste() +class wxMacMLTEHIViewControl : public wxMacMLTEControl { -} +public : + wxMacMLTEHIViewControl( wxTextCtrl *wxPeer, + const wxString& str, + const wxPoint& pos, + const wxSize& size, long style ) ; + virtual ~wxMacMLTEHIViewControl() ; -bool wxMacTextControl::CanPaste() const -{ - return false ; -} + virtual bool SetFocus() ; + virtual bool HasFocus() const ; + virtual void SetBackgroundColour(const wxColour& col ) ; -void wxMacTextControl::SetEditable(bool WXUNUSED(editable)) -{ -} +protected : + HIViewRef m_scrollView ; + HIViewRef m_textView ; +}; -wxTextPos wxMacTextControl::GetLastPosition() const -{ - return GetStringValue().length() ; -} +// 'classic' MLTE implementation -void wxMacTextControl::Replace( long from , long to , const wxString &val ) +class wxMacMLTEClassicControl : public wxMacMLTEControl { - SetSelection( from , to ) ; - WriteText( val ) ; -} +public : + wxMacMLTEClassicControl( wxTextCtrl *wxPeer, + const wxString& str, + const wxPoint& pos, + const wxSize& size, long style ) ; + virtual ~wxMacMLTEClassicControl() ; -void wxMacTextControl::Remove( long from , long to ) -{ - SetSelection( from , to ) ; - WriteText( wxEmptyString) ; -} + virtual void VisibilityChanged(bool shown) ; + virtual void SuperChangedPosition() ; -void wxMacTextControl::Clear() -{ - SetStringValue( wxEmptyString ) ; -} + virtual void MacControlUserPaneDrawProc(wxInt16 part) ; + virtual wxInt16 MacControlUserPaneHitTestProc(wxInt16 x, wxInt16 y) ; + virtual wxInt16 MacControlUserPaneTrackingProc(wxInt16 x, wxInt16 y, void* actionProc) ; + virtual void MacControlUserPaneIdleProc() ; + virtual wxInt16 MacControlUserPaneKeyDownProc(wxInt16 keyCode, wxInt16 charCode, wxInt16 modifiers) ; + virtual void MacControlUserPaneActivateProc(bool activating) ; + virtual wxInt16 MacControlUserPaneFocusProc(wxInt16 action) ; + virtual void MacControlUserPaneBackgroundProc(void* info) ; -bool wxMacTextControl::CanUndo() const -{ - return false ; -} + virtual bool SetupCursor( const wxPoint& WXUNUSED(pt) ) + { + MacControlUserPaneIdleProc(); + return true; + } -void wxMacTextControl::Undo() -{ -} + virtual void Move(int x, int y, int width, int height); -bool wxMacTextControl::CanRedo() const -{ - return false ; -} +protected : + OSStatus DoCreate(); -void wxMacTextControl::Redo() -{ -} + void MacUpdatePosition() ; + void MacActivatePaneText(bool setActive) ; + void MacFocusPaneText(bool setFocus) ; + void MacSetObjectVisibility(bool vis) ; -long wxMacTextControl::XYToPosition(long WXUNUSED(x), long WXUNUSED(y)) const -{ - return 0 ; -} +private : + TXNFrameID m_txnFrameID ; + GrafPtr m_txnPort ; + WindowRef m_txnWindow ; + // bounds of the control as we last did set the txn frames + Rect m_txnControlBounds ; + Rect m_txnVisBounds ; -bool wxMacTextControl::PositionToXY(long WXUNUSED(pos), - long *WXUNUSED(x), - long *WXUNUSED(y)) const -{ - return false ; -} + static pascal void TXNScrollActionProc( ControlRef controlRef , ControlPartCode partCode ) ; + static pascal void TXNScrollInfoProc( + SInt32 iValue, SInt32 iMaximumValue, + TXNScrollBarOrientation iScrollBarOrientation, SInt32 iRefCon ) ; -void wxMacTextControl::ShowPosition( long WXUNUSED(pos) ) -{ -} + ControlRef m_sbHorizontal ; + SInt32 m_lastHorizontalValue ; + ControlRef m_sbVertical ; + SInt32 m_lastVerticalValue ; +}; -int wxMacTextControl::GetNumberOfLines() const +wxWidgetImplType* wxWidgetImpl::CreateTextControl( wxTextCtrl* wxpeer, + wxWindowMac* WXUNUSED(parent), + wxWindowID WXUNUSED(id), + const wxString& str, + const wxPoint& pos, + const wxSize& size, + long style, + long WXUNUSED(extraStyle)) { - ItemCount lines = 0 ; - wxString content = GetStringValue() ; - lines = 1; + bool forceMLTE = false ; - for (size_t i = 0; i < content.length() ; i++) +#if wxUSE_SYSTEM_OPTIONS + if (wxSystemOptions::HasOption( wxMAC_TEXTCONTROL_USE_MLTE ) && (wxSystemOptions::GetOptionInt( wxMAC_TEXTCONTROL_USE_MLTE ) == 1)) { - if (content[i] == '\r') - lines++; + forceMLTE = true ; } +#endif - return lines ; -} + if ( UMAGetSystemVersion() >= 0x1050 ) + forceMLTE = false; -wxString wxMacTextControl::GetLineText(long lineNo) const -{ - // TODO: change this if possible to reflect real lines - wxString content = GetStringValue() ; + wxMacControl* peer = NULL; - // Find line first - int count = 0; - for (size_t i = 0; i < content.length() ; i++) + if ( !forceMLTE ) { - if (count == lineNo) - { - // Add chars in line then - wxString tmp; - - for (size_t j = i; j < content.length(); j++) - { - if (content[j] == '\n') - return tmp; - - tmp += content[j]; - } - - return tmp; - } - - if (content[i] == '\n') - count++; + if ( style & wxTE_MULTILINE || ( UMAGetSystemVersion() >= 0x1050 ) ) + peer = new wxMacMLTEHIViewControl( wxpeer , str , pos , size , style ) ; } - return wxEmptyString ; -} - -int wxMacTextControl::GetLineLength(long lineNo) const -{ - // TODO: change this if possible to reflect real lines - wxString content = GetStringValue() ; - - // Find line first - int count = 0; - for (size_t i = 0; i < content.length() ; i++) + if ( !peer ) { - if (count == lineNo) + if ( !(style & wxTE_MULTILINE) && !forceMLTE ) { - // Count chars in line then - count = 0; - for (size_t j = i; j < content.length(); j++) - { - count++; - if (content[j] == '\n') - return count; - } - - return count; + peer = new wxMacUnicodeTextControl( wxpeer , str , pos , size , style ) ; } - - if (content[i] == '\n') - count++; } - return 0 ; -} - -void wxMacTextControl::SetFont( const wxFont & font , const wxColour& foreground , long windowStyle ) -{ - wxMacControl::SetFont(font, foreground, windowStyle ); -#ifndef __LP64__ - - // overrule the barrier in wxMacControl for supporting disabled controls, in order to support - // setting the color to eg red and back to black by controllers - - if ( foreground == *wxBLACK ) - { - ControlFontStyleRec fontStyle; - fontStyle.foreColor.red = fontStyle.foreColor.green = fontStyle.foreColor.blue = 0; - fontStyle.flags = kControlUseForeColorMask; - ::SetControlFontStyle( m_controlRef , &fontStyle ); - } + // the horizontal single line scrolling bug that made us keep the classic implementation + // is fixed in 10.5 +#if MAC_OS_X_VERSION_MIN_REQUIRED < MAC_OS_X_VERSION_10_5 + if ( !peer ) + peer = new wxMacMLTEClassicControl( wxpeer , str , pos , size , style ) ; #endif + return peer; } // ---------------------------------------------------------------------------- @@ -1335,7 +470,9 @@ static pascal OSStatus wxMacUnicodeTextControlEventHandler( EventHandlerCallRef DEFINE_ONE_SHOT_HANDLER_GETTER( wxMacUnicodeTextControlEventHandler ) -wxMacUnicodeTextControl::wxMacUnicodeTextControl( wxTextCtrl *wxPeer ) : wxMacTextControl( wxPeer ) +wxMacUnicodeTextControl::wxMacUnicodeTextControl( wxTextCtrl *wxPeer ) + : wxMacControl( wxPeer ), + wxTextWidgetImpl( wxPeer ) { } @@ -1343,15 +480,8 @@ wxMacUnicodeTextControl::wxMacUnicodeTextControl( wxTextCtrl *wxPeer, const wxString& str, const wxPoint& pos, const wxSize& size, long style ) - : wxMacTextControl( wxPeer ) -{ - Create( wxPeer, str, pos, size, style ); -} - -bool wxMacUnicodeTextControl::Create( wxTextCtrl *wxPeer, - const wxString& str, - const wxPoint& pos, - const wxSize& size, long style ) + : wxMacControl( wxPeer ), + wxTextWidgetImpl( wxPeer ) { m_font = wxPeer->GetFont() ; m_windowStyle = style ; @@ -1360,23 +490,34 @@ bool wxMacUnicodeTextControl::Create( wxTextCtrl *wxPeer, wxString st = str ; wxMacConvertNewlines10To13( &st ) ; wxCFStringRef cf(st , m_font.GetEncoding()) ; - CFStringRef cfr = cf ; m_valueTag = kControlEditTextCFStringTag ; - CreateControl( wxPeer, &bounds, cfr ); + Boolean isPassword = ( m_windowStyle & wxTE_PASSWORD ) != 0 ; + if ( isPassword ) + { + m_valueTag = kControlEditTextPasswordCFStringTag ; + } + OSStatus err = CreateEditUnicodeTextControl( + MAC_WXHWND(wxPeer->MacGetTopLevelWindowRef()), &bounds , cf , + isPassword , NULL , &m_controlRef ) ; + verify_noerr( err ); if ( !(m_windowStyle & wxTE_MULTILINE) ) SetData( kControlEditTextPart , kControlEditTextSingleLineTag , true ) ; - InstallControlEventHandler( m_controlRef , GetwxMacUnicodeTextControlEventHandlerUPP(), - GetEventTypeCount(unicodeTextControlEventList), unicodeTextControlEventList, this, - NULL); + InstallEventHandlers(); +} - return true; +void wxMacUnicodeTextControl::InstallEventHandlers() +{ + ::InstallControlEventHandler( m_controlRef , GetwxMacUnicodeTextControlEventHandlerUPP(), + GetEventTypeCount(unicodeTextControlEventList), unicodeTextControlEventList, this, + (EventHandlerRef*) &m_macTextCtrlEventHandler); } wxMacUnicodeTextControl::~wxMacUnicodeTextControl() { + ::RemoveEventHandler((EventHandlerRef) m_macTextCtrlEventHandler); } void wxMacUnicodeTextControl::VisibilityChanged(bool shown) @@ -1424,19 +565,6 @@ void wxMacUnicodeTextControl::SetStringValue( const wxString &str ) verify_noerr( SetData( 0, m_valueTag , cf ) ) ; } -void wxMacUnicodeTextControl::CreateControl( wxTextCtrl* peer, const Rect* bounds, CFStringRef cfr ) -{ - Boolean isPassword = ( m_windowStyle & wxTE_PASSWORD ) != 0 ; - if ( isPassword ) - { - m_valueTag = kControlEditTextPasswordCFStringTag ; - } - OSStatus err = CreateEditUnicodeTextControl( - MAC_WXHWND(peer->MacGetTopLevelWindowRef()), bounds , cfr , - isPassword , NULL , &m_controlRef ) ; - verify_noerr( err ); -} - void wxMacUnicodeTextControl::Copy() { SendHICommand( kHICommandCopy ) ; @@ -1514,6 +642,17 @@ void wxMacUnicodeTextControl::SetSelection( long from , long to ) void wxMacUnicodeTextControl::WriteText( const wxString& str ) { + // TODO: this MPRemoting will be moved into a remoting peer proxy for any command + if ( !wxIsMainThread() ) + { +#if wxOSX_USE_CARBON + // unfortunately CW 8 is not able to correctly deduce the template types, + // so we have to instantiate explicitly + wxMacMPRemoteGUICall( (wxTextCtrl*) GetWXPeer() , &wxTextCtrl::WriteText , str ) ; +#endif + return ; + } + wxString st = str ; wxMacConvertNewlines10To13( &st ) ; @@ -1571,7 +710,8 @@ protected : } ; wxMacMLTEControl::wxMacMLTEControl( wxTextCtrl *peer ) - : wxMacTextControl( peer ) + : wxMacControl( peer ), + wxTextWidgetImpl( peer ) { SetNeedsFocusRect( true ) ; } @@ -1599,23 +739,18 @@ wxString wxMacMLTEControl::GetStringValue() const { wxChar *ptr = NULL ; -#if SIZEOF_WCHAR_T == 2 - ptr = new wxChar[actualSize + 1] ; - wxStrncpy( ptr , (wxChar*)(*theText) , actualSize ) ; -#else SetHandleSize( theText, (actualSize + 1) * sizeof(UniChar) ) ; HLock( theText ) ; (((UniChar*)*theText)[actualSize]) = 0 ; wxMBConvUTF16 converter ; size_t noChars = converter.MB2WC( NULL , (const char*)*theText , 0 ) ; - wxASSERT_MSG( noChars != wxCONV_FAILED, _T("Unable to count the number of characters in this string!") ); + wxASSERT_MSG( noChars != wxCONV_FAILED, wxT("Unable to count the number of characters in this string!") ); ptr = new wxChar[noChars + 1] ; noChars = converter.MB2WC( ptr , (const char*)*theText , noChars + 1 ) ; - wxASSERT_MSG( noChars != wxCONV_FAILED, _T("Conversion of string failed!") ); + wxASSERT_MSG( noChars != wxCONV_FAILED, wxT("Conversion of string failed!") ); ptr[noChars] = 0 ; HUnlock( theText ) ; -#endif ptr[actualSize] = 0 ; result = wxString( ptr ) ; @@ -1624,7 +759,7 @@ wxString wxMacMLTEControl::GetStringValue() const DisposeHandle( theText ) ; } -#else +#else // !wxUSE_UNICODE Handle theText ; err = TXNGetDataEncoded( m_txn , kTXNStartOffset, kTXNEndOffset, &theText, kTXNTextData ); @@ -1645,7 +780,7 @@ wxString wxMacMLTEControl::GetStringValue() const DisposeHandle( theText ) ; } -#endif +#endif // wxUSE_UNICODE/!wxUSE_UNICODE } #if '\n' == 10 @@ -1664,7 +799,7 @@ void wxMacMLTEControl::SetStringValue( const wxString &str ) { #ifndef __LP64__ - wxMacWindowClipper c( m_peer ) ; + wxMacWindowClipper c( GetWXPeer() ) ; #endif { @@ -1757,7 +892,7 @@ void wxMacMLTEControl::AdjustCreationAttributes(const wxColour &background, } ; err = TXNSetTypeAttributes( - m_txn, sizeof(typeAttr) / sizeof(TXNTypeAttributes), + m_txn, WXSIZEOF(typeAttr), typeAttr, kTXNStartOffset, kTXNEndOffset ); verify_noerr( err ); @@ -1815,7 +950,7 @@ void wxMacMLTEControl::SetBackgroundColour(const wxColour& col ) static inline int wxConvertToTXN(int x) { - return wx_static_cast(int, x / 254.0 * 72 + 0.5); + return static_cast(x / 254.0 * 72 + 0.5); } void wxMacMLTEControl::TXNSetAttribute( const wxTextAttr& style , long from , long to ) @@ -1927,7 +1062,8 @@ void wxMacMLTEControl::TXNSetAttribute( const wxTextAttr& style , long from , lo if ( typeAttrCount > 0 ) { verify_noerr( TXNSetTypeAttributes( m_txn , typeAttrCount, typeAttr, from , to ) ); - relayout = true; + if (from != to) + relayout = true; } if ( tabs != NULL ) @@ -1943,7 +1079,8 @@ void wxMacMLTEControl::TXNSetAttribute( const wxTextAttr& style , long from , lo void wxMacMLTEControl::SetFont(const wxFont & font, const wxColour& foreground, - long WXUNUSED(windowStyle)) + long WXUNUSED(windowStyle), + bool WXUNUSED(ignoreBlack)) { wxMacEditHelper help( m_txn ) ; TXNSetAttribute( wxTextAttr( foreground, wxNullColour, font ), kTXNStartOffset, kTXNEndOffset ) ; @@ -1982,11 +1119,20 @@ void wxMacMLTEControl::SetEditable(bool editable) TXNSetTXNObjectControls( m_txn, false, WXSIZEOF(tag), tag, data ) ; } -wxTextPos wxMacMLTEControl::GetLastPosition() const +long wxMacMLTEControl::GetLastPosition() const { wxTextPos actualsize = 0 ; Handle theText ; +#if wxUSE_UNICODE + OSErr err = TXNGetDataEncoded( m_txn, kTXNStartOffset, kTXNEndOffset, &theText, kTXNUnicodeTextData ); + // all done + if ( err == noErr ) + { + actualsize = GetHandleSize( theText )/sizeof(UniChar); + DisposeHandle( theText ) ; + } +#else OSErr err = TXNGetDataEncoded( m_txn, kTXNStartOffset, kTXNEndOffset, &theText, kTXNTextData ); // all done @@ -1995,6 +1141,7 @@ wxTextPos wxMacMLTEControl::GetLastPosition() const actualsize = GetHandleSize( theText ) ; DisposeHandle( theText ) ; } +#endif else { actualsize = 0 ; @@ -2010,7 +1157,7 @@ void wxMacMLTEControl::Replace( long from , long to , const wxString &str ) wxMacEditHelper help( m_txn ) ; #ifndef __LP64__ - wxMacWindowClipper c( m_peer ) ; + wxMacWindowClipper c( GetWXPeer() ) ; #endif TXNSetSelection( m_txn, from, to == -1 ? kTXNEndOffset : to ) ; @@ -2021,7 +1168,7 @@ void wxMacMLTEControl::Replace( long from , long to , const wxString &str ) void wxMacMLTEControl::Remove( long from , long to ) { #ifndef __LP64__ - wxMacWindowClipper c( m_peer ) ; + wxMacWindowClipper c( GetWXPeer() ) ; #endif wxMacEditHelper help( m_txn ) ; TXNSetSelection( m_txn , from , to ) ; @@ -2039,7 +1186,7 @@ void wxMacMLTEControl::GetSelection( long* from, long* to) const void wxMacMLTEControl::SetSelection( long from , long to ) { #ifndef __LP64__ - wxMacWindowClipper c( m_peer ) ; + wxMacWindowClipper c( GetWXPeer() ) ; #endif // change the selection @@ -2053,6 +1200,17 @@ void wxMacMLTEControl::SetSelection( long from , long to ) void wxMacMLTEControl::WriteText( const wxString& str ) { + // TODO: this MPRemoting will be moved into a remoting peer proxy for any command + if ( !wxIsMainThread() ) + { +#if wxOSX_USE_CARBON + // unfortunately CW 8 is not able to correctly deduce the template types, + // so we have to instantiate explicitly + wxMacMPRemoteGUICall( (wxTextCtrl*) GetWXPeer() , &wxTextCtrl::WriteText , str ) ; +#endif + return ; + } + wxString st = str ; wxMacConvertNewlines10To13( &st ) ; @@ -2060,7 +1218,7 @@ void wxMacMLTEControl::WriteText( const wxString& str ) GetSelection( &start , &dummy ) ; #ifndef __LP64__ - wxMacWindowClipper c( m_peer ) ; + wxMacWindowClipper c( GetWXPeer() ) ; #endif { @@ -2076,7 +1234,7 @@ void wxMacMLTEControl::WriteText( const wxString& str ) void wxMacMLTEControl::Clear() { #ifndef __LP64__ - wxMacWindowClipper c( m_peer ) ; + wxMacWindowClipper c( GetWXPeer() ) ; #endif wxMacEditHelper st( m_txn ) ; TXNSetSelection( m_txn , kTXNStartOffset , kTXNEndOffset ) ; @@ -2212,27 +1370,24 @@ void wxMacMLTEControl::ShowPosition( long pos ) // there will be an error returned for classic MLTE implementation when the control is // invisible, but HITextView works correctly, so we don't assert that one - // wxASSERT_MSG( theErr == noErr, _T("TXNScroll returned an error!") ); + // wxASSERT_MSG( theErr == noErr, wxT("TXNScroll returned an error!") ); } void wxMacMLTEControl::SetTXNData( const wxString& st, TXNOffset start, TXNOffset end ) { #if wxUSE_UNICODE -#if SIZEOF_WCHAR_T == 2 - size_t len = st.length() ; - TXNSetData( m_txn, kTXNUnicodeTextData, (void*)st.wc_str(), len * 2, start, end ); -#else wxMBConvUTF16 converter ; ByteCount byteBufferLen = converter.WC2MB( NULL, st.wc_str(), 0 ) ; - UniChar *unibuf = (UniChar*)malloc( byteBufferLen ) ; - converter.WC2MB( (char*)unibuf, st.wc_str(), byteBufferLen ) ; + wxASSERT_MSG( byteBufferLen != wxCONV_FAILED, + wxT("Conversion to UTF-16 unexpectedly failed") ); + UniChar *unibuf = (UniChar*)malloc( byteBufferLen + 2 ) ; // 2 for NUL in UTF-16 + converter.WC2MB( (char*)unibuf, st.wc_str(), byteBufferLen + 2 ) ; TXNSetData( m_txn, kTXNUnicodeTextData, (void*)unibuf, byteBufferLen, start, end ) ; free( unibuf ) ; -#endif -#else +#else // !wxUSE_UNICODE wxCharBuffer text = st.mb_str( wxConvLocal ) ; TXNSetData( m_txn, kTXNTextData, (void*)text.data(), strlen( text ), start, end ) ; -#endif +#endif // wxUSE_UNICODE/!wxUSE_UNICODE } wxString wxMacMLTEControl::GetLineText(long lineNo) const @@ -2571,9 +1726,9 @@ void wxMacMLTEClassicControl::MacUpdatePosition() } } -void wxMacMLTEClassicControl::SetRect( Rect *r ) +void wxMacMLTEClassicControl::Move(int x, int y, int width, int height) { - wxMacControl::SetRect( r ) ; + wxMacControl::Move(x,y,width,height) ; MacUpdatePosition() ; } @@ -2760,6 +1915,7 @@ wxMacMLTEClassicControl::wxMacMLTEClassicControl( wxTextCtrl *wxPeer, MAC_WXHWND(wxPeer->GetParent()->MacGetTopLevelWindowRef()), &bounds, featureSet, &m_controlRef ); verify_noerr( err ); + SetControlReference( m_controlRef , (URefCon) wxPeer ); DoCreate(); @@ -2770,7 +1926,7 @@ wxMacMLTEClassicControl::wxMacMLTEClassicControl( wxTextCtrl *wxPeer, { wxString st = str ; wxMacConvertNewlines10To13( &st ) ; - wxMacWindowClipper clipper( m_peer ) ; + wxMacWindowClipper clipper( GetWXPeer() ) ; SetTXNData( st , kTXNStartOffset, kTXNEndOffset ) ; TXNSetSelection( m_txn, 0, 0 ) ; } @@ -2804,7 +1960,7 @@ ControlUserPaneFocusUPP gTPFocusProc = NULL; static pascal void wxMacControlUserPaneDrawProc(ControlRef control, SInt16 part) { - wxTextCtrl *textCtrl = wxDynamicCast( wxFindControlFromMacControl(control) , wxTextCtrl ) ; + wxTextCtrl *textCtrl = wxDynamicCast( wxFindWindowFromWXWidget( (WXWidget) control) , wxTextCtrl ) ; wxMacMLTEClassicControl * win = textCtrl ? (wxMacMLTEClassicControl*)(textCtrl->GetPeer()) : NULL ; if ( win ) win->MacControlUserPaneDrawProc( part ) ; @@ -2812,7 +1968,7 @@ static pascal void wxMacControlUserPaneDrawProc(ControlRef control, SInt16 part) static pascal ControlPartCode wxMacControlUserPaneHitTestProc(ControlRef control, Point where) { - wxTextCtrl *textCtrl = wxDynamicCast( wxFindControlFromMacControl(control) , wxTextCtrl ) ; + wxTextCtrl *textCtrl = wxDynamicCast( wxFindWindowFromWXWidget( (WXWidget) control) , wxTextCtrl ) ; wxMacMLTEClassicControl * win = textCtrl ? (wxMacMLTEClassicControl*)(textCtrl->GetPeer()) : NULL ; if ( win ) return win->MacControlUserPaneHitTestProc( where.h , where.v ) ; @@ -2822,7 +1978,7 @@ static pascal ControlPartCode wxMacControlUserPaneHitTestProc(ControlRef control static pascal ControlPartCode wxMacControlUserPaneTrackingProc(ControlRef control, Point startPt, ControlActionUPP actionProc) { - wxTextCtrl *textCtrl = wxDynamicCast( wxFindControlFromMacControl(control) , wxTextCtrl ) ; + wxTextCtrl *textCtrl = wxDynamicCast( wxFindWindowFromWXWidget( (WXWidget) control) , wxTextCtrl ) ; wxMacMLTEClassicControl * win = textCtrl ? (wxMacMLTEClassicControl*)(textCtrl->GetPeer()) : NULL ; if ( win ) return win->MacControlUserPaneTrackingProc( startPt.h , startPt.v , (void*) actionProc ) ; @@ -2832,7 +1988,7 @@ static pascal ControlPartCode wxMacControlUserPaneTrackingProc(ControlRef contro static pascal void wxMacControlUserPaneIdleProc(ControlRef control) { - wxTextCtrl *textCtrl = wxDynamicCast( wxFindControlFromMacControl(control) , wxTextCtrl ) ; + wxTextCtrl *textCtrl = wxDynamicCast( wxFindWindowFromWXWidget((WXWidget) control) , wxTextCtrl ) ; wxMacMLTEClassicControl * win = textCtrl ? (wxMacMLTEClassicControl*)(textCtrl->GetPeer()) : NULL ; if ( win ) win->MacControlUserPaneIdleProc() ; @@ -2840,7 +1996,7 @@ static pascal void wxMacControlUserPaneIdleProc(ControlRef control) static pascal ControlPartCode wxMacControlUserPaneKeyDownProc(ControlRef control, SInt16 keyCode, SInt16 charCode, SInt16 modifiers) { - wxTextCtrl *textCtrl = wxDynamicCast( wxFindControlFromMacControl(control) , wxTextCtrl ) ; + wxTextCtrl *textCtrl = wxDynamicCast( wxFindWindowFromWXWidget((WXWidget) control) , wxTextCtrl ) ; wxMacMLTEClassicControl * win = textCtrl ? (wxMacMLTEClassicControl*)(textCtrl->GetPeer()) : NULL ; if ( win ) return win->MacControlUserPaneKeyDownProc( keyCode, charCode, modifiers ) ; @@ -2850,7 +2006,7 @@ static pascal ControlPartCode wxMacControlUserPaneKeyDownProc(ControlRef control static pascal void wxMacControlUserPaneActivateProc(ControlRef control, Boolean activating) { - wxTextCtrl *textCtrl = wxDynamicCast( wxFindControlFromMacControl(control) , wxTextCtrl ) ; + wxTextCtrl *textCtrl = wxDynamicCast( wxFindWindowFromWXWidget( (WXWidget)control) , wxTextCtrl ) ; wxMacMLTEClassicControl * win = textCtrl ? (wxMacMLTEClassicControl*)(textCtrl->GetPeer()) : NULL ; if ( win ) win->MacControlUserPaneActivateProc( activating ) ; @@ -2858,7 +2014,7 @@ static pascal void wxMacControlUserPaneActivateProc(ControlRef control, Boolean static pascal ControlPartCode wxMacControlUserPaneFocusProc(ControlRef control, ControlFocusPart action) { - wxTextCtrl *textCtrl = wxDynamicCast( wxFindControlFromMacControl(control) , wxTextCtrl ) ; + wxTextCtrl *textCtrl = wxDynamicCast( wxFindWindowFromWXWidget((WXWidget) control) , wxTextCtrl ) ; wxMacMLTEClassicControl * win = textCtrl ? (wxMacMLTEClassicControl*)(textCtrl->GetPeer()) : NULL ; if ( win ) return win->MacControlUserPaneFocusProc( action ) ; @@ -2869,7 +2025,7 @@ static pascal ControlPartCode wxMacControlUserPaneFocusProc(ControlRef control, #if 0 static pascal void wxMacControlUserPaneBackgroundProc(ControlRef control, ControlBackgroundPtr info) { - wxTextCtrl *textCtrl = wxDynamicCast( wxFindControlFromMacControl(control) , wxTextCtrl ) ; + wxTextCtrl *textCtrl = wxDynamicCast( wxFindWindowFromWXWidget(control) , wxTextCtrl ) ; wxMacMLTEClassicControl * win = textCtrl ? (wxMacMLTEClassicControl*)(textCtrl->GetPeer()) : NULL ; if ( win ) win->MacControlUserPaneBackgroundProc(info) ; @@ -3080,7 +2236,7 @@ wxMacMLTEHIViewControl::wxMacMLTEHIViewControl( wxTextCtrl *wxPeer, { HIViewAddSubview( m_scrollView , m_textView ) ; m_controlRef = m_scrollView ; - wxPeer->MacInstallEventHandler( (WXWidget) m_textView ) ; + InstallEventHandler( (WXWidget) m_textView ) ; } else { @@ -3090,14 +2246,14 @@ wxMacMLTEHIViewControl::wxMacMLTEHIViewControl( wxTextCtrl *wxPeer, AdjustCreationAttributes( *wxWHITE , true ) ; #ifndef __LP64__ - wxMacWindowClipper c( m_peer ) ; + wxMacWindowClipper c( GetWXPeer() ) ; #endif SetTXNData( st , kTXNStartOffset, kTXNEndOffset ) ; TXNSetSelection( m_txn, 0, 0 ); TXNShowSelection( m_txn, kTXNShowStart ); - InstallControlEventHandler( m_textView , GetwxMacTextControlEventHandlerUPP(), + ::InstallControlEventHandler( m_textView , GetwxMacTextControlEventHandlerUPP(), GetEventTypeCount(eventList), eventList, this, NULL); } @@ -3106,9 +2262,9 @@ wxMacMLTEHIViewControl::~wxMacMLTEHIViewControl() { } -OSStatus wxMacMLTEHIViewControl::SetFocus( ControlFocusPart focusPart ) +bool wxMacMLTEHIViewControl::SetFocus() { - return SetKeyboardFocus( GetControlOwner( m_textView ), m_textView, focusPart ) ; + return SetKeyboardFocus( GetControlOwner( m_textView ), m_textView, kControlFocusNextPart ) == noErr ; } bool wxMacMLTEHIViewControl::HasFocus() const