diff --git a/common/grid_tricks.cpp b/common/grid_tricks.cpp index a3858e5528..2affa071ae 100644 --- a/common/grid_tricks.cpp +++ b/common/grid_tricks.cpp @@ -30,6 +30,8 @@ #include #include #include +#include +#include #include #include @@ -105,6 +107,18 @@ bool GRID_TRICKS::isTextEntry( int aRow, int aCol ) } +bool GRID_TRICKS::isChoiceEditor( int aRow, int aCol ) +{ + wxGridCellEditor* editor = m_grid->GetCellEditor( aRow, aCol ); + bool retval = ( dynamic_cast( editor ) + || dynamic_cast( editor ) + || dynamic_cast( editor ) ); + + editor->DecRef(); + return retval; +} + + bool GRID_TRICKS::isCheckbox( int aRow, int aCol ) { wxGridCellRenderer* renderer = m_grid->GetCellRenderer( aRow, aCol ); @@ -329,6 +343,8 @@ void GRID_TRICKS::getSelectedArea() void GRID_TRICKS::onGridCellRightClick( wxGridEvent& aEvent ) { + m_grid->CommitPendingChanges( true ); + wxMenu menu; showPopupMenu( menu, aEvent ); @@ -389,8 +405,11 @@ void GRID_TRICKS::showPopupMenu( wxMenu& menu, wxGridEvent& aEvent ) { for( int col = m_sel_col_start; col < m_sel_col_start + m_sel_col_count; ++col ) { - if( !isReadOnly( row, col ) && isTextEntry( row, col ) ) + if( !isReadOnly( row, col ) + && ( isTextEntry( row, col ) || isChoiceEditor( row, col ) ) ) + { return true; + } } } @@ -492,37 +511,82 @@ void GRID_TRICKS::onCharHook( wxKeyEvent& ev ) handled = true; } } - else if( ev.GetModifiers() == wxMOD_CONTROL && ev.GetKeyCode() == 'V' ) + else if( ev.GetModifiers() == wxMOD_CONTROL && ev.GetKeyCode() == 'C' ) { - if( m_grid->IsCellEditControlShown() && wxTheClipboard->Open() ) + if( m_grid->IsCellEditControlShown() ) { - if( wxTheClipboard->IsSupported( wxDF_TEXT ) - || wxTheClipboard->IsSupported( wxDF_UNICODETEXT ) ) + wxTextEntry* te = dynamic_cast( ev.GetEventObject() ); + + if( te ) { - wxTextDataObject data; - wxTheClipboard->GetData( data ); + wxString selectedText = te->GetStringSelection(); - if( data.GetText().Contains( COL_SEP ) || data.GetText().Contains( ROW_SEP ) ) + if( !selectedText.IsEmpty() ) { - wxString stripped( data.GetText() ); - stripped.Replace( ROW_SEP, " " ); - stripped.Replace( ROW_SEP_R, " " ); - stripped.Replace( COL_SEP, " " ); + wxLogNull doNotLog; - // Write to the CellEditControl if we can - wxTextEntry* te = dynamic_cast( ev.GetEventObject() ); - - if( te && te->IsEditable() ) - te->WriteText( stripped ); - else - paste_text( stripped ); - - handled = true; + if( wxTheClipboard->Open() ) + { + wxTheClipboard->SetData( new wxTextDataObject( selectedText ) ); + wxTheClipboard->Flush(); + wxTheClipboard->Close(); + handled = true; + } } } - wxTheClipboard->Close(); - m_grid->ForceRefresh(); + if( !handled ) + { + m_grid->CancelPendingChanges(); + getSelectedArea(); + cutcopy( true, false ); + handled = true; + } + } + } + else if( ev.GetModifiers() == wxMOD_CONTROL && ev.GetKeyCode() == 'V' ) + { + if( m_grid->IsCellEditControlShown() ) + { + wxLogNull doNotLog; + + if( wxTheClipboard->Open() ) + { + if( wxTheClipboard->IsSupported( wxDF_TEXT ) + || wxTheClipboard->IsSupported( wxDF_UNICODETEXT ) ) + { + wxTextDataObject data; + wxTheClipboard->GetData( data ); + wxString text = data.GetText(); + + bool hasMultipleCells = text.Contains( COL_SEP ) || text.Contains( ROW_SEP ); + + if( hasMultipleCells ) + { + text.Replace( ROW_SEP, wxS( " " ) ); + text.Replace( ROW_SEP_R, wxS( " " ) ); + text.Replace( COL_SEP, wxS( " " ) ); + } + + wxTextEntry* te = dynamic_cast( ev.GetEventObject() ); + + if( te && te->IsEditable() ) + { + te->WriteText( text ); + handled = true; + } + else + { + m_grid->CancelPendingChanges(); + getSelectedArea(); + paste_text( text ); + handled = true; + } + } + + wxTheClipboard->Close(); + m_grid->ForceRefresh(); + } } } else if( ev.GetKeyCode() == WXK_ESCAPE ) diff --git a/include/grid_tricks.h b/include/grid_tricks.h index b87410d54a..2d858e3c24 100644 --- a/include/grid_tricks.h +++ b/include/grid_tricks.h @@ -114,6 +114,7 @@ protected: virtual void doPopupSelection( wxCommandEvent& event ); bool isTextEntry( int aRow, int aCol ); + bool isChoiceEditor( int aRow, int aCol ); bool isCheckbox( int aRow, int aCol ); bool isReadOnly( int aRow, int aCol );