X-Git-Url: https://git.saurik.com/wxWidgets.git/blobdiff_plain/16671f229af4d3ff3ca2a6612a8ebc6c89f45c24..808cbd174a5c7d0946df7dcaf1891e881a94f64f:/src/osx/textctrl_osx.cpp?ds=sidebyside diff --git a/src/osx/textctrl_osx.cpp b/src/osx/textctrl_osx.cpp index 6edd282e97..4262ff2301 100644 --- a/src/osx/textctrl_osx.cpp +++ b/src/osx/textctrl_osx.cpp @@ -53,6 +53,7 @@ IMPLEMENT_DYNAMIC_CLASS(wxTextCtrl, wxTextCtrlBase) BEGIN_EVENT_TABLE(wxTextCtrl, wxTextCtrlBase) EVT_DROP_FILES(wxTextCtrl::OnDropFiles) EVT_CHAR(wxTextCtrl::OnChar) + EVT_KEY_DOWN(wxTextCtrl::OnKeyDown) EVT_MENU(wxID_CUT, wxTextCtrl::OnCut) EVT_MENU(wxID_COPY, wxTextCtrl::OnCopy) EVT_MENU(wxID_PASTE, wxTextCtrl::OnPaste) @@ -75,10 +76,8 @@ END_EVENT_TABLE() void wxTextCtrl::Init() { - m_editable = true ; m_dirty = false; - m_maxLength = 0; m_privateContextMenu = NULL; m_triggerUpdateEvents = true ; } @@ -163,16 +162,6 @@ void wxTextCtrl::MacCheckSpelling(bool check) GetTextPeer()->CheckSpelling(check); } -wxString wxTextCtrl::DoGetValue() const -{ - return GetTextPeer()->GetStringValue() ; -} - -void wxTextCtrl::GetSelection(long* from, long* to) const -{ - GetTextPeer()->GetSelection( from , to ) ; -} - void wxTextCtrl::SetMaxLength(unsigned long len) { m_maxLength = len ; @@ -190,7 +179,8 @@ bool wxTextCtrl::SetFont( const wxFont& font ) bool wxTextCtrl::SetStyle(long start, long end, const wxTextAttr& style) { - GetTextPeer()->SetStyle( start , end , style ) ; + if (GetTextPeer()) + GetTextPeer()->SetStyle( start , end , style ) ; return true ; } @@ -203,132 +193,11 @@ bool wxTextCtrl::SetDefaultStyle(const wxTextAttr& style) return true ; } -// Clipboard operations - -void wxTextCtrl::Copy() -{ - if (CanCopy()) - GetTextPeer()->Copy() ; -} - -void wxTextCtrl::Cut() -{ - if (CanCut()) - { - GetTextPeer()->Cut() ; - - SendTextUpdatedEvent(); - } -} - -void wxTextCtrl::Paste() -{ - if (CanPaste()) - { - GetTextPeer()->Paste() ; - - // TODO: eventually we should add setting the default style again - SendTextUpdatedEvent(); - } -} - -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 GetTextPeer()->CanPaste() ; -} - -void wxTextCtrl::SetEditable(bool editable) -{ - if ( editable != m_editable ) - { - m_editable = editable ; - GetTextPeer()->SetEditable( editable ) ; - } -} - -void wxTextCtrl::SetInsertionPoint(long pos) -{ - SetSelection( pos , pos ) ; -} - -void wxTextCtrl::SetInsertionPointEnd() -{ - long pos = GetLastPosition(); - SetInsertionPoint( pos ); -} - -long wxTextCtrl::GetInsertionPoint() const -{ - long begin, end ; - GetSelection( &begin , &end ) ; - - return begin ; -} - -wxTextPos wxTextCtrl::GetLastPosition() const -{ - return GetTextPeer()->GetLastPosition() ; -} - -void wxTextCtrl::Remove(long from, long to) -{ - GetTextPeer()->Remove( from , to ) ; - if ( m_triggerUpdateEvents ) - SendTextUpdatedEvent(); -} - -void wxTextCtrl::SetSelection(long from, long to) -{ - GetTextPeer()->SetSelection( from , to ) ; -} - -void wxTextCtrl::WriteText(const wxString& str) -{ - GetTextPeer()->WriteText( str ) ; - if ( m_triggerUpdateEvents ) - SendTextUpdatedEvent(); -} - -void wxTextCtrl::Clear() -{ - GetTextPeer()->Clear() ; - SendTextUpdatedEvent(); -} - 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 @@ -337,6 +206,13 @@ bool wxTextCtrl::AcceptsFocus() const wxSize wxTextCtrl::DoGetBestSize() const { + if (GetTextPeer()) + { + wxSize size = GetTextPeer()->GetBestSize(); + if (size.x > 0 && size.y > 0) + return size; + } + int wText, hText; // these are the numbers from the HIG: @@ -378,38 +254,6 @@ bool wxTextCtrl::GetStyle(long position, wxTextAttr& style) return GetTextPeer()->GetStyle(position, style); } -// ---------------------------------------------------------------------------- -// Undo/redo -// ---------------------------------------------------------------------------- - -void wxTextCtrl::Undo() -{ - if (CanUndo()) - GetTextPeer()->Undo() ; -} - -void wxTextCtrl::Redo() -{ - if (CanRedo()) - GetTextPeer()->Redo() ; -} - -bool wxTextCtrl::CanUndo() const -{ - if ( !IsEditable() ) - return false ; - - return GetTextPeer()->CanUndo() ; -} - -bool wxTextCtrl::CanRedo() const -{ - if ( !IsEditable() ) - return false ; - - return GetTextPeer()->CanRedo() ; -} - void wxTextCtrl::MarkDirty() { m_dirty = true; @@ -450,39 +294,88 @@ wxString wxTextCtrl::GetLineText(long lineNo) const return GetTextPeer()->GetLineText(lineNo) ; } -void wxTextCtrl::Command(wxCommandEvent & event) +void wxTextCtrl::Remove(long from, long to) { - SetValue(event.GetString()); - ProcessCommand(event); + wxTextEntry::Remove(from, to); + if ( m_triggerUpdateEvents ) + SendTextUpdatedEvent(); } -void wxTextCtrl::OnDropFiles(wxDropFilesEvent& event) +void wxTextCtrl::WriteText(const wxString& str) { - // By default, load the first file into the text window. - if (event.GetNumberOfFiles() > 0) - LoadFile( event.GetFiles()[0] ); + wxTextEntry::WriteText( str ) ; + if ( m_triggerUpdateEvents ) + SendTextUpdatedEvent(); } -void wxTextCtrl::OnChar(wxKeyEvent& event) +void wxTextCtrl::Clear() { - int key = event.GetKeyCode() ; - bool eat_key = false ; - long from, to; + wxTextEntry::Clear() ; + SendTextUpdatedEvent(); +} - if ( key == 'a' && event.MetaDown() ) +void wxTextCtrl::Cut() +{ + if (CanCut()) { - SelectAll() ; + wxTextEntry::Cut() ; - return ; + SendTextUpdatedEvent(); } +} - if ( key == 'c' && event.MetaDown() ) +void wxTextCtrl::Paste() +{ + if (CanPaste()) { - if ( CanCopy() ) - Copy() ; + wxTextEntry::Paste(); - return ; + // TODO: eventually we should add setting the default style again + SendTextUpdatedEvent(); + } +} + +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::OnKeyDown(wxKeyEvent& event) +{ + if ( event.GetModifiers() == wxMOD_CMD ) + { + switch( event.GetKeyCode() ) + { + case 'A': + SelectAll(); + return; + case 'C': + if ( CanCopy() ) + Copy() ; + return; + case 'V': + if ( CanPaste() ) + Paste() ; + return; + case 'X': + if ( CanCut() ) + Cut() ; + return; + default: + break; + } } + // no, we didn't process it + event.Skip(); +} + +void wxTextCtrl::OnChar(wxKeyEvent& event) +{ + int key = event.GetKeyCode() ; + bool eat_key = false ; + long from, to; if ( !IsEditable() && !event.IsKeyInCategory(WXK_CATEGORY_ARROW | WXK_CATEGORY_TAB) && !( key == WXK_RETURN && ( (m_windowStyle & wxTE_PROCESS_ENTER) || (m_windowStyle & wxTE_MULTILINE) ) ) @@ -510,22 +403,6 @@ void wxTextCtrl::OnChar(wxKeyEvent& event) // 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: @@ -606,10 +483,18 @@ void wxTextCtrl::OnChar(wxKeyEvent& event) #endif } +void wxTextCtrl::Command(wxCommandEvent & event) +{ + SetValue(event.GetString()); + ProcessCommand(event); +} + // ---------------------------------------------------------------------------- // standard handlers for standard edit menu events // ---------------------------------------------------------------------------- +// CS: Context Menus only work with MLTE implementations or non-multiline HIViews at the moment + void wxTextCtrl::OnCut(wxCommandEvent& WXUNUSED(event)) { Cut(); @@ -687,8 +572,6 @@ void wxTextCtrl::OnUpdateSelectAll(wxUpdateUIEvent& event) event.Enable(GetLastPosition() > 0); } -// CS: Context Menus only work with MLTE implementations or non-multiline HIViews at the moment - void wxTextCtrl::OnContextMenu(wxContextMenuEvent& event) { if ( GetTextPeer()->HasOwnContextMenu() ) @@ -712,8 +595,7 @@ void wxTextCtrl::OnContextMenu(wxContextMenuEvent& event) m_privateContextMenu->Append(wxID_SELECTALL, _("Select &All")); } - if (m_privateContextMenu != NULL) - PopupMenu(m_privateContextMenu); + PopupMenu(m_privateContextMenu); #endif } @@ -820,13 +702,16 @@ void wxTextWidgetImpl::ShowPosition( long WXUNUSED(pos) ) int wxTextWidgetImpl::GetNumberOfLines() const { - ItemCount lines = 0 ; wxString content = GetStringValue() ; - lines = 1; + ItemCount lines = 1; for (size_t i = 0; i < content.length() ; i++) { +#if wxOSX_USE_COCOA + if (content[i] == '\n') +#else if (content[i] == '\r') +#endif lines++; }