X-Git-Url: https://git.saurik.com/wxWidgets.git/blobdiff_plain/cf5d4c76af8d7bea5b2dcb5755dc6efd1bffcd58..a39815bd30c62e13089f318028c9ee547940c4ad:/src/generic/datavgen.cpp?ds=sidebyside diff --git a/src/generic/datavgen.cpp b/src/generic/datavgen.cpp index 86bcadf928..5fd5797d8c 100644 --- a/src/generic/datavgen.cpp +++ b/src/generic/datavgen.cpp @@ -623,6 +623,9 @@ public: void ChangeCurrentRow( unsigned int row ); bool TryAdvanceCurrentColumn(wxDataViewTreeNode *node, bool forward); + wxDataViewColumn *GetCurrentColumn() const { return m_currentCol; } + void ClearCurrentColumn() { m_currentCol = NULL; } + bool IsSingleSel() const { return !GetParent()->HasFlag(wxDV_MULTIPLE); } bool IsEmpty() { return GetRowCount() == 0; } @@ -3524,6 +3527,7 @@ void wxDataViewMainWindow::OnChar( wxKeyEvent &event ) switch ( event.GetKeyCode() ) { case WXK_RETURN: + if ( !event.HasModifiers() ) { // Enter activates the item, i.e. sends wxEVT_COMMAND_DATAVIEW_ITEM_ACTIVATED to // it. Only if that event is not handled do we activate column renderer (which @@ -3543,6 +3547,7 @@ void wxDataViewMainWindow::OnChar( wxKeyEvent &event ) } case WXK_SPACE: + if ( !event.HasModifiers() ) { // Space toggles activatable items or -- if not activatable -- // starts inline editing (this is normally done using F2 on @@ -3572,6 +3577,7 @@ void wxDataViewMainWindow::OnChar( wxKeyEvent &event ) } case WXK_F2: + if ( !event.HasModifiers() ) { if( !m_selection.empty() ) { @@ -3593,7 +3599,7 @@ void wxDataViewMainWindow::OnChar( wxKeyEvent &event ) wxDataViewColumn *editableCol = FindColumnForEditing(item, wxDATAVIEW_CELL_EDITABLE); if ( editableCol ) - GetOwner()->StartEditor(item, GetOwner()->GetColumnIndex(editableCol)); + GetOwner()->EditItem(item, editableCol); } } break; @@ -4641,13 +4647,7 @@ unsigned int wxDataViewCtrl::GetBestColumnWidth(int idx) const m_clientArea->GetRowHeight()); if ( m_headerArea ) - { - int header_width = m_headerArea->GetTextExtent(column->GetTitle()).x; - // Labels on native MSW header are indented on both sides - header_width += - wxRendererNative::Get().GetHeaderButtonMargin(m_headerArea); - calculator.UpdateWithWidth(header_width); - } + calculator.UpdateWithWidth(m_headerArea->GetColumnTitleWidth(*column)); // The code below deserves some explanation. For very large controls, we // simply can't afford to calculate sizes for all items, it takes too @@ -4742,6 +4742,10 @@ bool wxDataViewCtrl::DeleteColumn( wxDataViewColumn *column ) m_colsBestWidths.erase(m_colsBestWidths.begin() + GetColumnIndex(column)); m_cols.Erase(ret); + + if ( m_clientArea->GetCurrentColumn() == column ) + m_clientArea->ClearCurrentColumn(); + OnColumnsCountChanged(); return true; @@ -4752,7 +4756,11 @@ bool wxDataViewCtrl::ClearColumns() SetExpanderColumn(NULL); m_cols.Clear(); m_colsBestWidths.clear(); + + m_clientArea->ClearCurrentColumn(); + OnColumnsCountChanged(); + return true; } @@ -4795,7 +4803,6 @@ void wxDataViewCtrl::OnInternalIdle() int wxDataViewCtrl::GetColumnPosition( const wxDataViewColumn *column ) const { -#if 1 unsigned int len = GetColumnCount(); for ( unsigned int i = 0; i < len; i++ ) { @@ -4805,25 +4812,6 @@ int wxDataViewCtrl::GetColumnPosition( const wxDataViewColumn *column ) const } return wxNOT_FOUND; -#else - // This returns the position in pixels which is not what we want. - int ret = 0, - dummy = 0; - unsigned int len = GetColumnCount(); - for ( unsigned int i = 0; i < len; i++ ) - { - wxDataViewColumn * col = GetColumnAt(i); - if (col->IsHidden()) - continue; - ret += col->GetWidth(); - if (column==col) - { - CalcScrolledPosition( ret, dummy, &ret, &dummy ); - break; - } - } - return ret; -#endif } wxDataViewColumn *wxDataViewCtrl::GetSortingColumn() const @@ -4850,6 +4838,11 @@ void wxDataViewCtrl::DoSetCurrentItem(const wxDataViewItem& item) } } +wxDataViewColumn *wxDataViewCtrl::GetCurrentColumn() const +{ + return m_clientArea->GetCurrentColumn(); +} + int wxDataViewCtrl::GetSelectedItemsCount() const { return m_clientArea->GetSelections().size(); @@ -5028,13 +5021,12 @@ bool wxDataViewCtrl::IsExpanded( const wxDataViewItem & item ) const return false; } -void wxDataViewCtrl::StartEditor( const wxDataViewItem & item, unsigned int column ) +void wxDataViewCtrl::EditItem(const wxDataViewItem& item, const wxDataViewColumn *column) { - wxDataViewColumn* col = GetColumn( column ); - if (!col) - return; + wxCHECK_RET( item.IsOk(), "invalid item" ); + wxCHECK_RET( column, "no column provided" ); - m_clientArea->StartEditing(item, col); + m_clientArea->StartEditing(item, column); } #endif // !wxUSE_GENERICDATAVIEWCTRL