X-Git-Url: https://git.saurik.com/wxWidgets.git/blobdiff_plain/5aa6ea933f515a1afa9b97b23e353f2eae54764c..f86a4930f2c69058684496a1882343fe8e709bf2:/src/osx/textctrl_osx.cpp diff --git a/src/osx/textctrl_osx.cpp b/src/osx/textctrl_osx.cpp index af08390bfa..e513b16b7e 100644 --- a/src/osx/textctrl_osx.cpp +++ b/src/osx/textctrl_osx.cpp @@ -4,7 +4,7 @@ // Author: Stefan Csomor // Modified by: Ryan Norton (MLTE GetLineLength and GetLineText) // Created: 1998-01-01 -// RCS-ID: $Id: textctrl.cpp 54820 2008-07-29 20:04:11Z SC $ +// RCS-ID: $Id$ // Copyright: (c) Stefan Csomor // Licence: wxWindows licence ///////////////////////////////////////////////////////////////////////////// @@ -48,8 +48,6 @@ #include "wx/osx/private.h" -IMPLEMENT_DYNAMIC_CLASS(wxTextCtrl, wxTextCtrlBase) - BEGIN_EVENT_TABLE(wxTextCtrl, wxTextCtrlBase) EVT_DROP_FILES(wxTextCtrl::OnDropFiles) EVT_CHAR(wxTextCtrl::OnChar) @@ -79,7 +77,6 @@ void wxTextCtrl::Init() m_dirty = false; m_privateContextMenu = NULL; - m_triggerUpdateEvents = true ; } wxTextCtrl::~wxTextCtrl() @@ -98,7 +95,7 @@ bool wxTextCtrl::Create( wxWindow *parent, const wxValidator& validator, const wxString& name ) { - m_macIsUserPane = false ; + DontCreatePeer(); m_editable = true ; if ( ! (style & wxNO_BORDER) ) @@ -115,16 +112,16 @@ bool wxTextCtrl::Create( wxWindow *parent, } - m_peer = wxWidgetImpl::CreateTextControl( this, GetParent(), GetId(), str, pos, size, style, GetExtraStyle() ); + SetPeer(wxWidgetImpl::CreateTextControl( this, GetParent(), GetId(), str, pos, size, style, GetExtraStyle() )); MacPostControlCreate(pos, size) ; - + #if wxOSX_USE_COCOA // under carbon everything can already be set before the MacPostControlCreate embedding takes place // but under cocoa for single line textfields this only works after everything has been set up GetTextPeer()->SetStringValue(str); #endif - + // only now the embedding is correct and we can do a positioning update MacSuperChangedPosition() ; @@ -137,11 +134,6 @@ bool wxTextCtrl::Create( wxWindow *parent, return true; } -wxTextWidgetImpl* wxTextCtrl::GetTextPeer() const -{ - return dynamic_cast (m_peer); -} - void wxTextCtrl::MacSuperChangedPosition() { wxWindow::MacSuperChangedPosition() ; @@ -162,11 +154,6 @@ void wxTextCtrl::MacCheckSpelling(bool check) GetTextPeer()->CheckSpelling(check); } -void wxTextCtrl::SetMaxLength(unsigned long len) -{ - m_maxLength = len ; -} - bool wxTextCtrl::SetFont( const wxFont& font ) { if ( !wxTextCtrlBase::SetFont( font ) ) @@ -212,7 +199,7 @@ wxSize wxTextCtrl::DoGetBestSize() const if (size.x > 0 && size.y > 0) return size; } - + int wText, hText; // these are the numbers from the HIG: @@ -294,33 +281,31 @@ wxString wxTextCtrl::GetLineText(long lineNo) const return GetTextPeer()->GetLineText(lineNo) ; } -void wxTextCtrl::Remove(long from, long to) -{ - wxTextEntry::Remove(from, to); - if ( m_triggerUpdateEvents ) - SendTextUpdatedEvent(); -} - -void wxTextCtrl::WriteText(const wxString& str) +void wxTextCtrl::Copy() { - wxTextEntry::WriteText( str ) ; - if ( m_triggerUpdateEvents ) - SendTextUpdatedEvent(); -} - -void wxTextCtrl::Clear() -{ - wxTextEntry::Clear() ; - SendTextUpdatedEvent(); + if (CanCopy()) + { + wxClipboardTextEvent evt(wxEVT_TEXT_COPY, GetId()); + evt.SetEventObject(this); + if (!GetEventHandler()->ProcessEvent(evt)) + { + wxTextEntry::Copy(); + } + } } void wxTextCtrl::Cut() { if (CanCut()) { - wxTextEntry::Cut() ; + wxClipboardTextEvent evt(wxEVT_TEXT_CUT, GetId()); + evt.SetEventObject(this); + if (!GetEventHandler()->ProcessEvent(evt)) + { + wxTextEntry::Cut(); - SendTextUpdatedEvent(); + SendTextUpdatedEvent(); + } } } @@ -328,10 +313,15 @@ void wxTextCtrl::Paste() { if (CanPaste()) { - wxTextEntry::Paste(); + wxClipboardTextEvent evt(wxEVT_TEXT_PASTE, GetId()); + evt.SetEventObject(this); + if (!GetEventHandler()->ProcessEvent(evt)) + { + wxTextEntry::Paste(); - // TODO: eventually we should add setting the default style again - SendTextUpdatedEvent(); + // TODO: eventually we should add setting the default style again + SendTextUpdatedEvent(); + } } } @@ -344,7 +334,7 @@ void wxTextCtrl::OnDropFiles(wxDropFilesEvent& event) void wxTextCtrl::OnKeyDown(wxKeyEvent& event) { - if ( event.MetaDown() ) + if ( event.GetModifiers() == wxMOD_CONTROL ) { switch( event.GetKeyCode() ) { @@ -386,18 +376,21 @@ void wxTextCtrl::OnChar(wxKeyEvent& event) 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 && - !event.IsKeyInCategory(WXK_CATEGORY_ARROW | WXK_CATEGORY_TAB | WXK_CATEGORY_CUT) && - !( key == WXK_RETURN && (m_windowStyle & wxTE_PROCESS_ENTER) ) && - from == to ) + if ( !GetTextPeer()->CanClipMaxLength() ) { - // eat it, we don't want to add more than allowed # of characters + // 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 && + !event.IsKeyInCategory(WXK_CATEGORY_ARROW | WXK_CATEGORY_TAB | WXK_CATEGORY_CUT) && + !( 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; + // TODO: generate EVT_TEXT_MAXLEN() + return; + } } // assume that any key not processed yet is going to modify the control @@ -408,7 +401,7 @@ void wxTextCtrl::OnChar(wxKeyEvent& event) case WXK_RETURN: if (m_windowStyle & wxTE_PROCESS_ENTER) { - wxCommandEvent event(wxEVT_COMMAND_TEXT_ENTER, m_windowId); + wxCommandEvent event(wxEVT_TEXT_ENTER, m_windowId); event.SetEventObject( this ); event.SetString( GetValue() ); if ( HandleWindowEvent(event) ) @@ -423,7 +416,7 @@ void wxTextCtrl::OnChar(wxKeyEvent& event) wxButton *def = wxDynamicCast(tlw->GetDefaultItem(), wxButton); if ( def && def->IsEnabled() ) { - wxCommandEvent event(wxEVT_COMMAND_BUTTON_CLICKED, def->GetId() ); + wxCommandEvent event(wxEVT_BUTTON, def->GetId() ); event.SetEventObject(def); def->Command(event); @@ -476,7 +469,7 @@ void wxTextCtrl::OnChar(wxKeyEvent& event) key == WXK_DELETE || key == WXK_BACK) { - wxCommandEvent event1(wxEVT_COMMAND_TEXT_UPDATED, m_windowId); + wxCommandEvent event1(wxEVT_TEXT, m_windowId); event1.SetEventObject( this ); wxPostEvent( GetEventHandler(), event1 ); } @@ -607,6 +600,21 @@ bool wxTextCtrl::MacSetupCursor( const wxPoint& pt ) return true ; } +bool wxTextCtrl::SetHint(const wxString& hint) +{ + m_hintString = hint; + + if ( GetTextPeer() && GetTextPeer()->SetHint(hint) ) + return true; + + return false; +} + +wxString wxTextCtrl::GetHint() const +{ + return m_hintString; +} + // ---------------------------------------------------------------------------- // implementation base class // ---------------------------------------------------------------------------- @@ -765,9 +773,10 @@ int wxTextWidgetImpl::GetLineLength(long lineNo) const count = 0; for (size_t j = i; j < content.length(); j++) { - count++; if (content[j] == '\n') return count; + + count++; } return count;