X-Git-Url: https://git.saurik.com/wxWidgets.git/blobdiff_plain/da2e758f83f62cf9ff3bed69aecb8fc00f2583df..6a3f00bd6660d0326904d774d6e7a48a13af1f6f:/src/generic/treelist.cpp?ds=sidebyside diff --git a/src/generic/treelist.cpp b/src/generic/treelist.cpp index 68ee06f333..18cb193d18 100644 --- a/src/generic/treelist.cpp +++ b/src/generic/treelist.cpp @@ -549,23 +549,17 @@ public: } // Event handlers toggling the items checkbox if it was clicked. - virtual bool Activate(const wxRect& WXUNUSED(cell), - wxDataViewModel* model, - const wxDataViewItem& item, - unsigned int WXUNUSED(col)) + virtual bool ActivateCell(const wxRect& WXUNUSED(cell), + wxDataViewModel *model, + const wxDataViewItem & item, + unsigned int WXUNUSED(col), + const wxMouseEvent *mouseEvent) { - static_cast(model)->ToggleItem(item); - return true; - } - - virtual bool LeftClick(const wxPoint& pos, - const wxRect& WXUNUSED(cell), - wxDataViewModel* model, - const wxDataViewItem& item, - unsigned int WXUNUSED(col)) - { - if ( !wxRect(GetCheckSize()).Contains(pos) ) - return false; + if ( mouseEvent ) + { + if ( !wxRect(GetCheckSize()).Contains(mouseEvent->GetPosition()) ) + return false; + } static_cast(model)->ToggleItem(item); return true; @@ -671,16 +665,20 @@ wxTreeListModel::InsertItem(Node* parent, wxScopedPtr newItem(new Node(parent, text, imageClosed, imageOpened, data)); + // FIXME-VC6: This compiler refuses to compare "Node* previous" with + // wxTLI_XXX without some help. + const wxTreeListItem previousItem(previous); + // If we have no children at all, then inserting as last child is the same // as inserting as the first one so check for it here too. - if ( previous == wxTLI_FIRST || - (previous == wxTLI_LAST && !parent->GetChild()) ) + if ( previousItem == wxTLI_FIRST || + (previousItem == wxTLI_LAST && !parent->GetChild()) ) { parent->InsertChild(newItem.get()); } else // Not the first item, find the previous one. { - if ( previous == wxTLI_LAST ) + if ( previousItem == wxTLI_LAST ) { previous = parent->GetChild(); @@ -760,7 +758,12 @@ const wxString& wxTreeListModel::GetItemText(Node* item, unsigned col) const // empty string we can return reference to. wxCHECK_MSG( item, m_root->m_text, "Invalid item" ); - return col == 0 ? item->m_text : item->GetColumnText(col); + // Notice that asking for the text of a column of an item that doesn't have + // any column texts is not an error so we simply return an empty string in + // this case. + return col == 0 ? item->m_text + : item->HasColumnsTexts() ? item->GetColumnText(col) + : m_root->m_text; } void wxTreeListModel::SetItemText(Node* item, unsigned col, const wxString& text) @@ -1148,7 +1151,7 @@ void wxTreeListCtrl::SetColumnWidth(unsigned col, int width) wxDataViewColumn* const column = m_view->GetColumn(col); wxCHECK_RET( column, "No such column?" ); - return column->SetWidth(width); + column->SetWidth(width); } int wxTreeListCtrl::GetColumnWidth(unsigned col) const @@ -1608,29 +1611,38 @@ void wxTreeListCtrl::OnSize(wxSizeEvent& event) const wxRect rect = GetClientRect(); m_view->SetSize(rect); - // Resize the first column to take the remaining available space, if - // any. +#ifdef wxHAS_GENERIC_DATAVIEWCTRL + // The generic implementation doesn't refresh itself immediately which + // is annoying during "live resizing", so do it forcefully here to + // ensure that the items are re-laid out and the focus rectangle is + // redrawn correctly (instead of leaving traces) while our size is + // being changed. + wxWindow* const view = GetView(); + view->Refresh(); + view->Update(); +#endif // wxHAS_GENERIC_DATAVIEWCTRL + + // Resize the first column to take the remaining available space. const unsigned numColumns = GetColumnCount(); if ( !numColumns ) return; // There is a bug in generic wxDataViewCtrl: if the column width sums // up to the total size, horizontal scrollbar (unnecessarily) appears, - // so subtract 10 pixels to ensure this doesn't happen. - int remainingWidth = rect.width - 10; + // so subtract a bit to ensure this doesn't happen. + int remainingWidth = rect.width - 5; for ( unsigned n = 1; n < GetColumnCount(); n++ ) { remainingWidth -= GetColumnWidth(n); - if ( remainingWidth < 0 ) - break; + if ( remainingWidth <= 0 ) + { + // There is not enough space, as we're not going to give the + // first column negative width anyhow, just don't do anything. + return; + } } - // We don't decrease the width of the first column, even if we had - // increased it ourselves, because we want to avoid changing its size - // if the user resized it. We might want to remember if this was the - // case or if we only ever adjusted it automatically in the future. - if ( remainingWidth > GetColumnWidth(0) ) - SetColumnWidth(0, remainingWidth); + SetColumnWidth(0, remainingWidth); } } @@ -1647,7 +1659,7 @@ wxWindow* wxTreeListCtrl::GetView() const // wxTreeListEvent implementation // ============================================================================ -wxIMPLEMENT_ABSTRACT_CLASS(wxTreeListEvent, wxNotifyEvent) +wxIMPLEMENT_DYNAMIC_CLASS(wxTreeListEvent, wxNotifyEvent) #define wxDEFINE_TREELIST_EVENT(name) \ wxDEFINE_EVENT(wxEVT_COMMAND_TREELIST_##name, wxTreeListEvent)