X-Git-Url: https://git.saurik.com/wxWidgets.git/blobdiff_plain/0b6a49c21fb59ab3b03480a299ce2beab5fa6811..267ba369d605996cf6f9673aad528bfcf662f942:/src/osx/textctrl_osx.cpp diff --git a/src/osx/textctrl_osx.cpp b/src/osx/textctrl_osx.cpp index 9ace17a932..1ff3094dbc 100644 --- a/src/osx/textctrl_osx.cpp +++ b/src/osx/textctrl_osx.cpp @@ -80,7 +80,7 @@ void wxTextCtrl::Init() m_maxLength = 0; m_privateContextMenu = NULL; - m_triggerOnSetValue = true ; + m_triggerUpdateEvents = true ; } wxTextCtrl::~wxTextCtrl() @@ -119,7 +119,13 @@ bool wxTextCtrl::Create( wxWindow *parent, m_peer = 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() ; @@ -134,7 +140,7 @@ bool wxTextCtrl::Create( wxWindow *parent, wxTextWidgetImpl* wxTextCtrl::GetTextPeer() const { - return dynamic_cast (m_peer); + return dynamic_cast (m_peer); } void wxTextCtrl::MacSuperChangedPosition() @@ -157,7 +163,7 @@ void wxTextCtrl::MacCheckSpelling(bool check) GetTextPeer()->CheckSpelling(check); } -wxString wxTextCtrl::GetValue() const +wxString wxTextCtrl::DoGetValue() const { return GetTextPeer()->GetStringValue() ; } @@ -167,20 +173,6 @@ void wxTextCtrl::GetSelection(long* from, long* to) const GetTextPeer()->GetSelection( from , to ) ; } -void wxTextCtrl::DoSetValue(const wxString& str, int flags) -{ - // optimize redraws - if ( GetValue() == str ) - return; - - GetTextPeer()->SetStringValue( str ) ; - - if ( (flags & SetValue_SendEvent) && m_triggerOnSetValue ) - { - SendTextUpdatedEvent(); - } -} - void wxTextCtrl::SetMaxLength(unsigned long len) { m_maxLength = len ; @@ -225,10 +217,8 @@ void wxTextCtrl::Cut() { GetTextPeer()->Cut() ; - wxCommandEvent event( wxEVT_COMMAND_TEXT_UPDATED, m_windowId ); - event.SetEventObject( this ); - HandleWindowEvent( event ); - } + SendTextUpdatedEvent(); + } } void wxTextCtrl::Paste() @@ -238,10 +228,7 @@ void wxTextCtrl::Paste() GetTextPeer()->Paste() ; // TODO: eventually we should add setting the default style again - - wxCommandEvent event( wxEVT_COMMAND_TEXT_UPDATED, m_windowId ); - event.SetEventObject( this ); - HandleWindowEvent( event ); + SendTextUpdatedEvent(); } } @@ -307,14 +294,11 @@ wxTextPos wxTextCtrl::GetLastPosition() const return GetTextPeer()->GetLastPosition() ; } -void wxTextCtrl::Replace(long from, long to, const wxString& str) -{ - GetTextPeer()->Replace( from , to , str ) ; -} - void wxTextCtrl::Remove(long from, long to) { GetTextPeer()->Remove( from , to ) ; + if ( m_triggerUpdateEvents ) + SendTextUpdatedEvent(); } void wxTextCtrl::SetSelection(long from, long to) @@ -325,17 +309,14 @@ void wxTextCtrl::SetSelection(long from, long to) void wxTextCtrl::WriteText(const wxString& str) { GetTextPeer()->WriteText( str ) ; -} - -void wxTextCtrl::AppendText(const wxString& text) -{ - SetInsertionPointEnd(); - WriteText( text ); + if ( m_triggerUpdateEvents ) + SendTextUpdatedEvent(); } void wxTextCtrl::Clear() { GetTextPeer()->Clear() ; + SendTextUpdatedEvent(); } bool wxTextCtrl::IsModified() const @@ -498,7 +479,7 @@ void wxTextCtrl::OnChar(wxKeyEvent& event) return ; } - if ( !IsEditable() && key != WXK_LEFT && key != WXK_RIGHT && key != WXK_DOWN && key != WXK_UP && key != WXK_TAB && + if ( !IsEditable() && !event.IsKeyInCategory(WXK_CATEGORY_ARROW | WXK_CATEGORY_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 ) @@ -511,8 +492,8 @@ void wxTextCtrl::OnChar(wxKeyEvent& event) // 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) ) && + !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 @@ -605,6 +586,8 @@ void wxTextCtrl::OnChar(wxKeyEvent& event) event.Skip(true) ; } + // osx_cocoa sends its event upon insertText +#if wxOSX_USE_CARBON if ( ( key >= 0x20 && key < WXK_START ) || ( key >= WXK_NUMPAD0 && key <= WXK_DIVIDE ) || key == WXK_RETURN || @@ -615,6 +598,7 @@ void wxTextCtrl::OnChar(wxKeyEvent& event) event1.SetEventObject( this ); wxPostEvent( GetEventHandler(), event1 ); } +#endif } // ----------------------------------------------------------------------------