X-Git-Url: https://git.saurik.com/wxWidgets.git/blobdiff_plain/005ac806ead92411ad4810d407df311e4a608302..4d8209b9070ea7120078e83a648f3627e57bc15a:/src/osx/textctrl_osx.cpp diff --git a/src/osx/textctrl_osx.cpp b/src/osx/textctrl_osx.cpp index 4021966024..aa500bce44 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() ; @@ -157,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 ) ) @@ -207,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: @@ -289,31 +281,11 @@ 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) -{ - wxTextEntry::WriteText( str ) ; - if ( m_triggerUpdateEvents ) - SendTextUpdatedEvent(); -} - -void wxTextCtrl::Clear() -{ - wxTextEntry::Clear() ; - SendTextUpdatedEvent(); -} - void wxTextCtrl::Copy() { if (CanCopy()) { - wxClipboardTextEvent evt(wxEVT_COMMAND_TEXT_COPY, GetId()); + wxClipboardTextEvent evt(wxEVT_COMMAND_TEXT_COPY, GetId()); evt.SetEventObject(this); if (!GetEventHandler()->ProcessEvent(evt)) { @@ -326,7 +298,7 @@ void wxTextCtrl::Cut() { if (CanCut()) { - wxClipboardTextEvent evt(wxEVT_COMMAND_TEXT_CUT, GetId()); + wxClipboardTextEvent evt(wxEVT_COMMAND_TEXT_CUT, GetId()); evt.SetEventObject(this); if (!GetEventHandler()->ProcessEvent(evt)) { @@ -341,7 +313,7 @@ void wxTextCtrl::Paste() { if (CanPaste()) { - wxClipboardTextEvent evt(wxEVT_COMMAND_TEXT_PASTE, GetId()); + wxClipboardTextEvent evt(wxEVT_COMMAND_TEXT_PASTE, GetId()); evt.SetEventObject(this); if (!GetEventHandler()->ProcessEvent(evt)) { @@ -362,7 +334,7 @@ void wxTextCtrl::OnDropFiles(wxDropFilesEvent& event) void wxTextCtrl::OnKeyDown(wxKeyEvent& event) { - if ( event.GetModifiers() == wxMOD_CMD ) + if ( event.GetModifiers() == wxMOD_CONTROL ) { switch( event.GetKeyCode() ) { @@ -404,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 @@ -625,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 // ---------------------------------------------------------------------------- @@ -783,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;