X-Git-Url: https://git.saurik.com/wxWidgets.git/blobdiff_plain/5d2ebe49dfc05b38d83cace85f927baf04d3b6a1..07aaf32633ecf18ec3edfbb41793a112914792d0:/src/generic/datavgen.cpp?ds=sidebyside diff --git a/src/generic/datavgen.cpp b/src/generic/datavgen.cpp index 89bc7ebfc0..def4fb5877 100644 --- a/src/generic/datavgen.cpp +++ b/src/generic/datavgen.cpp @@ -80,7 +80,22 @@ static const int EXPANDER_OFFSET = 1; // For the generic implementation, both the leaf nodes and the nodes are sorted for // fast search when needed static wxDataViewModel* g_model; -static int g_column = -2; + +// The column is either the index of the column to be used for sorting or one +// of the special values in this enum: +enum +{ + // Sort when we're thawed later. + SortColumn_OnThaw = -3, + + // Don't sort at all. + SortColumn_None = -2, + + // Sort using the model default sort order. + SortColumn_Default = -1 +}; + +static int g_column = SortColumn_None; static bool g_asending = true; // ---------------------------------------------------------------------------- @@ -581,16 +596,39 @@ public: UpdateDisplay(); } + // Override the base class method to resort if needed, i.e. if + // SortPrepare() was called -- and ignored -- while we were frozen. + virtual void DoThaw() + { + if ( g_column == SortColumn_OnThaw ) + { + Resort(); + g_column = SortColumn_None; + } + + wxWindow::DoThaw(); + } + void SortPrepare() { g_model = GetModel(); + + // Avoid sorting while the window is frozen, this allows to quickly add + // many items without resorting after each addition and only resort + // them all at once when the window is finally thawed, see above. + if ( IsFrozen() ) + { + g_column = SortColumn_OnThaw; + return; + } + wxDataViewColumn* col = GetOwner()->GetSortingColumn(); if( !col ) { if (g_model->HasDefaultCompare()) - g_column = -1; + g_column = SortColumn_Default; else - g_column = -2; + g_column = SortColumn_None; g_asending = true; return; @@ -678,6 +716,7 @@ public: void SetRowHeight( int lineHeight ) { m_lineHeight = lineHeight; } int GetRowHeight() const { return m_lineHeight; } + int GetDefaultRowHeight() const; // Some useful functions for row and item mapping wxDataViewItem GetItemByRow( unsigned int row ) const; @@ -1398,15 +1437,7 @@ wxDataViewMainWindow::wxDataViewMainWindow( wxDataViewCtrl *parent, wxWindowID i m_currentColSetByKeyboard = false; m_useCellFocus = false; m_currentRow = (unsigned)-1; - -#ifdef __WXMSW__ - // We would like to use the same line height that Explorer uses. This is - // different from standard ListView control since Vista. - if ( wxGetWinVersion() >= wxWinVersion_Vista ) - m_lineHeight = wxMax(16, GetCharHeight()) + 6; // 16 = mini icon height - else -#endif // __WXMSW__ - m_lineHeight = wxMax(16, GetCharHeight()) + 1; // 16 = mini icon height + m_lineHeight = GetDefaultRowHeight(); #if wxUSE_DRAG_AND_DROP m_dragCount = 0; @@ -1449,6 +1480,20 @@ wxDataViewMainWindow::~wxDataViewMainWindow() } +int wxDataViewMainWindow::GetDefaultRowHeight() const +{ +#ifdef __WXMSW__ + // We would like to use the same line height that Explorer uses. This is + // different from standard ListView control since Vista. + if ( wxGetWinVersion() >= wxWinVersion_Vista ) + return wxMax(16, GetCharHeight()) + 6; // 16 = mini icon height + else +#endif // __WXMSW__ + return wxMax(16, GetCharHeight()) + 1; // 16 = mini icon height +} + + + #if wxUSE_DRAG_AND_DROP bool wxDataViewMainWindow::EnableDragSource( const wxDataFormat &format ) { @@ -3943,10 +3988,11 @@ void wxDataViewMainWindow::OnMouse( wxMouseEvent &event ) return; } - if(event.LeftDown()) + if(event.ButtonDown()) { - // Not skipping this event would prevent the system from setting focus - // to this window. + // Not skipping button down events would prevent the system from + // setting focus to this window as most (all?) of them do by default, + // so skip it to enable default handling. event.Skip(); } @@ -3992,30 +4038,30 @@ void wxDataViewMainWindow::OnMouse( wxMouseEvent &event ) le.SetItem( item ); le.SetColumn( col->GetModelColumn() ); le.SetDataViewColumn( col ); - - wxVariant value; - model->GetValue( value, item, col->GetModelColumn() ); - le.SetValue(value); } parent->ProcessWindowEvent(le); return; } - if (!col) + // Check if we clicked outside the item area. + if ((current >= GetRowCount()) || !col) { + // Follow Windows convention here: clicking either left or right (but + // not middle) button clears the existing selection. + if (m_owner && (event.LeftDown() || event.RightDown())) + { + if (!GetSelections().empty()) + { + m_owner->UnselectAll(); + SendSelectionChangedEvent(wxDataViewItem()); + } + } event.Skip(); return; } wxDataViewRenderer *cell = col->GetRenderer(); - if ((current >= GetRowCount()) || (x > GetEndOfLastCol())) - { - // Unselect all if below the last row ? - event.Skip(); - return; - } - wxDataViewColumn* const expander = GetExpanderColumnOrFirstOne(GetOwner()); @@ -4429,6 +4475,7 @@ void wxDataViewCtrl::Init() m_sortingColumnIdx = wxNOT_FOUND; m_headerArea = NULL; + m_clientArea = NULL; m_colsDirty = false; } @@ -4542,6 +4589,31 @@ void wxDataViewCtrl::SetFocus() m_clientArea->SetFocus(); } +bool wxDataViewCtrl::SetFont(const wxFont & font) +{ + if (!wxControl::SetFont(font)) + return false; + + if (m_headerArea) + m_headerArea->SetFont(font); + + if (m_clientArea) + { + m_clientArea->SetFont(font); + m_clientArea->SetRowHeight(m_clientArea->GetDefaultRowHeight()); + } + + if (m_headerArea || m_clientArea) + { + InvalidateColBestWidths(); + Layout(); + } + + return true; +} + + + bool wxDataViewCtrl::AssociateModel( wxDataViewModel *model ) { if (!wxDataViewCtrlBase::AssociateModel( model ))