X-Git-Url: https://git.saurik.com/wxWidgets.git/blobdiff_plain/95b20f41b6d66d00173633c48bee80d6aee64625..f7008bad873d18e389109f1e2c3af51323d16556:/src/common/datavcmn.cpp diff --git a/src/common/datavcmn.cpp b/src/common/datavcmn.cpp index 79ed168564..57c2aaecd0 100644 --- a/src/common/datavcmn.cpp +++ b/src/common/datavcmn.cpp @@ -18,20 +18,18 @@ #if wxUSE_DATAVIEWCTRL #include "wx/dataview.h" -#include "wx/spinctrl.h" -#include "wx/choice.h" - -#include "wx/weakref.h" -#include "wx/vector.h" #ifndef WX_PRECOMP #include "wx/dc.h" #include "wx/settings.h" #include "wx/log.h" - #include "wx/icon.h" #include "wx/crt.h" #endif +#include "wx/spinctrl.h" +#include "wx/choice.h" +#include "wx/imaglist.h" + const char wxDataViewCtrlNameStr[] = "dataviewCtrl"; @@ -40,13 +38,6 @@ bool operator == (const wxDataViewItem &left, const wxDataViewItem &right) return (left.GetID() == right.GetID() ); } -#ifdef __WXDEBUG__ -void wxDataViewItem::Print(const wxString& text) const -{ - wxPrintf(wxT("item %s: %lu\n"), text.GetData(), wxPtrToUInt(m_id)); -} -#endif - // --------------------------------------------------------- // wxDataViewModelNotifier // --------------------------------------------------------- @@ -235,7 +226,7 @@ void wxDataViewModel::RemoveNotifier( wxDataViewModelNotifier *notifier ) } int wxDataViewModel::Compare( const wxDataViewItem &item1, const wxDataViewItem &item2, - unsigned int column, bool ascending ) + unsigned int column, bool ascending ) const { // sort branches before leaves bool item1_is_container = IsContainer(item1); @@ -434,7 +425,7 @@ bool wxDataViewIndexListModel::HasDefaultCompare() const int wxDataViewIndexListModel::Compare(const wxDataViewItem& item1, const wxDataViewItem& item2, unsigned int WXUNUSED(column), - bool ascending) + bool ascending) const { if (m_ordered) { @@ -589,7 +580,7 @@ bool wxDataViewVirtualListModel::HasDefaultCompare() const int wxDataViewVirtualListModel::Compare(const wxDataViewItem& item1, const wxDataViewItem& item2, unsigned int WXUNUSED(column), - bool ascending) + bool ascending) const { unsigned int pos1 = wxPtrToUInt(item1.GetID()); unsigned int pos2 = wxPtrToUInt(item2.GetID()); @@ -704,6 +695,10 @@ bool wxDataViewRendererBase::StartEditing( const wxDataViewItem &item, wxRect la m_editorCtrl->PushEventHandler( handler ); + // there might be no editor control for the given item + if (!m_editorCtrl) + return false; + #if defined(__WXGTK20__) && !defined(wxUSE_GENERICDATAVIEWCTRL) handler->SetFocusOnIdle(); #else @@ -899,11 +894,11 @@ const wxDataViewModel* wxDataViewCtrlBase::GetModel() const void wxDataViewCtrlBase::ExpandAncestors( const wxDataViewItem & item ) { if (!m_model) return; - + if (!item.IsOk()) return; wxVector parentChain; - + // at first we get all the parents of the selected item wxDataViewItem parent = m_model->GetParent(item); while (parent.IsOk()) @@ -911,7 +906,7 @@ void wxDataViewCtrlBase::ExpandAncestors( const wxDataViewItem & item ) parentChain.push_back(parent); parent = m_model->GetParent(parent); } - + // then we expand the parents, starting at the root while (!parentChain.empty()) { @@ -1212,24 +1207,28 @@ wxDataViewCtrlBase::InsertColumn( unsigned int WXUNUSED(pos), wxDataViewColumn * IMPLEMENT_DYNAMIC_CLASS(wxDataViewEvent,wxNotifyEvent) -wxDEFINE_EVENT( wxEVT_COMMAND_DATAVIEW_SELECTION_CHANGED, wxDataViewEvent ) +wxDEFINE_EVENT( wxEVT_COMMAND_DATAVIEW_SELECTION_CHANGED, wxDataViewEvent ); -wxDEFINE_EVENT( wxEVT_COMMAND_DATAVIEW_ITEM_ACTIVATED, wxDataViewEvent ) -wxDEFINE_EVENT( wxEVT_COMMAND_DATAVIEW_ITEM_COLLAPSING, wxDataViewEvent ) -wxDEFINE_EVENT( wxEVT_COMMAND_DATAVIEW_ITEM_COLLAPSED, wxDataViewEvent ) -wxDEFINE_EVENT( wxEVT_COMMAND_DATAVIEW_ITEM_EXPANDING, wxDataViewEvent ) -wxDEFINE_EVENT( wxEVT_COMMAND_DATAVIEW_ITEM_EXPANDED, wxDataViewEvent ) -wxDEFINE_EVENT( wxEVT_COMMAND_DATAVIEW_ITEM_EDITING_STARTED, wxDataViewEvent ) -wxDEFINE_EVENT( wxEVT_COMMAND_DATAVIEW_ITEM_EDITING_DONE, wxDataViewEvent ) -wxDEFINE_EVENT( wxEVT_COMMAND_DATAVIEW_ITEM_VALUE_CHANGED, wxDataViewEvent ) +wxDEFINE_EVENT( wxEVT_COMMAND_DATAVIEW_ITEM_ACTIVATED, wxDataViewEvent ); +wxDEFINE_EVENT( wxEVT_COMMAND_DATAVIEW_ITEM_COLLAPSING, wxDataViewEvent ); +wxDEFINE_EVENT( wxEVT_COMMAND_DATAVIEW_ITEM_COLLAPSED, wxDataViewEvent ); +wxDEFINE_EVENT( wxEVT_COMMAND_DATAVIEW_ITEM_EXPANDING, wxDataViewEvent ); +wxDEFINE_EVENT( wxEVT_COMMAND_DATAVIEW_ITEM_EXPANDED, wxDataViewEvent ); +wxDEFINE_EVENT( wxEVT_COMMAND_DATAVIEW_ITEM_EDITING_STARTED, wxDataViewEvent ); +wxDEFINE_EVENT( wxEVT_COMMAND_DATAVIEW_ITEM_START_EDITING, wxDataViewEvent ); +wxDEFINE_EVENT( wxEVT_COMMAND_DATAVIEW_ITEM_EDITING_DONE, wxDataViewEvent ); +wxDEFINE_EVENT( wxEVT_COMMAND_DATAVIEW_ITEM_VALUE_CHANGED, wxDataViewEvent ); -wxDEFINE_EVENT( wxEVT_COMMAND_DATAVIEW_ITEM_CONTEXT_MENU, wxDataViewEvent ) +wxDEFINE_EVENT( wxEVT_COMMAND_DATAVIEW_ITEM_CONTEXT_MENU, wxDataViewEvent ); -wxDEFINE_EVENT( wxEVT_COMMAND_DATAVIEW_COLUMN_HEADER_CLICK, wxDataViewEvent ) -wxDEFINE_EVENT( wxEVT_COMMAND_DATAVIEW_COLUMN_HEADER_RIGHT_CLICK, wxDataViewEvent ) -wxDEFINE_EVENT( wxEVT_COMMAND_DATAVIEW_COLUMN_SORTED, wxDataViewEvent ) -wxDEFINE_EVENT( wxEVT_COMMAND_DATAVIEW_COLUMN_REORDERED, wxDataViewEvent ) +wxDEFINE_EVENT( wxEVT_COMMAND_DATAVIEW_COLUMN_HEADER_CLICK, wxDataViewEvent ); +wxDEFINE_EVENT( wxEVT_COMMAND_DATAVIEW_COLUMN_HEADER_RIGHT_CLICK, wxDataViewEvent ); +wxDEFINE_EVENT( wxEVT_COMMAND_DATAVIEW_COLUMN_SORTED, wxDataViewEvent ); +wxDEFINE_EVENT( wxEVT_COMMAND_DATAVIEW_COLUMN_REORDERED, wxDataViewEvent ); +wxDEFINE_EVENT( wxEVT_COMMAND_DATAVIEW_ITEM_BEGIN_DRAG, wxDataViewEvent ); +wxDEFINE_EVENT( wxEVT_COMMAND_DATAVIEW_ITEM_DROP_POSSIBLE, wxDataViewEvent ); +wxDEFINE_EVENT( wxEVT_COMMAND_DATAVIEW_ITEM_DROP, wxDataViewEvent ); // ------------------------------------- // wxDataViewSpinRenderer @@ -1395,13 +1394,13 @@ wxString wxDataViewListStore::GetColumnType( unsigned int pos ) const { return m_cols[pos]; } - + void wxDataViewListStore::AppendItem( const wxVector &values, wxClientData *data ) { wxDataViewListStoreLine *line = new wxDataViewListStoreLine( data ); line->m_values = values; m_data.push_back( line ); - + RowAppended(); } @@ -1410,24 +1409,25 @@ void wxDataViewListStore::PrependItem( const wxVector &values, wxClie wxDataViewListStoreLine *line = new wxDataViewListStoreLine( data ); line->m_values = values; m_data.insert( m_data.begin(), line ); - + RowPrepended(); } -void wxDataViewListStore::InsertItem( unsigned int row, const wxVector &values, wxClientData *data ) +void wxDataViewListStore::InsertItem( unsigned int row, const wxVector &values, + wxClientData *data ) { wxDataViewListStoreLine *line = new wxDataViewListStoreLine( data ); line->m_values = values; m_data.insert( m_data.begin()+row, line ); - + RowInserted( row ); } -void wxDataViewListStore::DeleteItem( unsigned row ) +void wxDataViewListStore::DeleteItem( unsigned int row ) { wxVector::iterator it = m_data.begin() + row; m_data.erase( it ); - + RowDeleted( row ); } @@ -1439,7 +1439,9 @@ void wxDataViewListStore::DeleteAllItems() wxDataViewListStoreLine* line = *it; delete line; } - + + m_data.clear(); + Reset( 0 ); } @@ -1453,7 +1455,7 @@ bool wxDataViewListStore::SetValueByRow( const wxVariant &value, unsigned int ro { wxDataViewListStoreLine *line = m_data[row]; line->m_values[col] = value; - + return true; } @@ -1526,18 +1528,18 @@ bool wxDataViewListCtrl::AppendColumn( wxDataViewColumn *col ) { return AppendColumn( col, "string" ); } - + wxDataViewColumn *wxDataViewListCtrl::AppendTextColumn( const wxString &label, wxDataViewCellMode mode, int width, wxAlignment align, int flags ) { GetStore()->AppendColumn( wxT("string") ); - + wxDataViewColumn *ret = new wxDataViewColumn( label, new wxDataViewTextRenderer( wxT("string"), mode ), GetStore()->GetColumnCount()-1, width, align, flags ); - + wxDataViewCtrl::AppendColumn( ret ); - + return ret; } @@ -1545,13 +1547,13 @@ wxDataViewColumn *wxDataViewListCtrl::AppendToggleColumn( const wxString &label, wxDataViewCellMode mode, int width, wxAlignment align, int flags ) { GetStore()->AppendColumn( wxT("bool") ); - + wxDataViewColumn *ret = new wxDataViewColumn( label, new wxDataViewToggleRenderer( wxT("bool"), mode ), GetStore()->GetColumnCount()-1, width, align, flags ); - + wxDataViewCtrl::AppendColumn( ret ); - + return ret; } @@ -1559,13 +1561,13 @@ wxDataViewColumn *wxDataViewListCtrl::AppendProgressColumn( const wxString &labe wxDataViewCellMode mode, int width, wxAlignment align, int flags ) { GetStore()->AppendColumn( wxT("long") ); - + wxDataViewColumn *ret = new wxDataViewColumn( label, new wxDataViewProgressRenderer( wxEmptyString, wxT("long"), mode ), GetStore()->GetColumnCount()-1, width, align, flags ); - + wxDataViewCtrl::AppendColumn( ret ); - + return ret; } @@ -1573,13 +1575,13 @@ wxDataViewColumn *wxDataViewListCtrl::AppendIconTextColumn( const wxString &labe wxDataViewCellMode mode, int width, wxAlignment align, int flags ) { GetStore()->AppendColumn( wxT("wxDataViewIconText") ); - + wxDataViewColumn *ret = new wxDataViewColumn( label, new wxDataViewIconTextRenderer( wxT("wxDataViewIconText"), mode ), GetStore()->GetColumnCount()-1, width, align, flags ); - + wxDataViewCtrl::AppendColumn( ret ); - + return ret; } @@ -1725,11 +1727,11 @@ wxDataViewTreeStore::InsertContainer(const wxDataViewItem& parent, { wxDataViewTreeStoreContainerNode *parent_node = FindContainerNode( parent ); if (!parent_node) return wxDataViewItem(0); - + wxDataViewTreeStoreNode *previous_node = FindNode( previous ); int pos = parent_node->GetChildren().IndexOf( previous_node ); if (pos == wxNOT_FOUND) return wxDataViewItem(0); - + wxDataViewTreeStoreContainerNode *node = new wxDataViewTreeStoreContainerNode( parent_node, text, icon, expanded, data ); parent_node->GetChildren().Insert( (size_t) pos, node ); @@ -1934,7 +1936,7 @@ unsigned int wxDataViewTreeStore::GetChildren( const wxDataViewItem &item, wxDat } int wxDataViewTreeStore::Compare( const wxDataViewItem &item1, const wxDataViewItem &item2, - unsigned int WXUNUSED(column), bool WXUNUSED(ascending) ) + unsigned int WXUNUSED(column), bool WXUNUSED(ascending) ) const { wxDataViewTreeStoreNode *node1 = FindNode( item1 ); wxDataViewTreeStoreNode *node2 = FindNode( item2 ); @@ -2041,9 +2043,9 @@ wxDataViewItem wxDataViewTreeCtrl::AppendItem( const wxDataViewItem& parent, icon = m_imageList->GetIcon( iconIndex ); wxDataViewItem res = GetStore()->AppendItem( parent, text, icon, data ); - + GetStore()->ItemAdded( parent, res ); - + return res; } @@ -2055,9 +2057,9 @@ wxDataViewItem wxDataViewTreeCtrl::PrependItem( const wxDataViewItem& parent, icon = m_imageList->GetIcon( iconIndex ); wxDataViewItem res = GetStore()->PrependItem( parent, text, icon, data ); - + GetStore()->ItemAdded( parent, res ); - + return res; } @@ -2069,9 +2071,9 @@ wxDataViewItem wxDataViewTreeCtrl::InsertItem( const wxDataViewItem& parent, con icon = m_imageList->GetIcon( iconIndex ); wxDataViewItem res = GetStore()->InsertItem( parent, previous, text, icon, data ); - + GetStore()->ItemAdded( parent, res ); - + return res; } @@ -2087,9 +2089,9 @@ wxDataViewItem wxDataViewTreeCtrl::PrependContainer( const wxDataViewItem& paren expanded = m_imageList->GetIcon( expandedIndex ); wxDataViewItem res = GetStore()->PrependContainer( parent, text, icon, expanded, data ); - + GetStore()->ItemAdded( parent, res ); - + return res; } @@ -2105,9 +2107,9 @@ wxDataViewItem wxDataViewTreeCtrl::AppendContainer( const wxDataViewItem& parent expanded = m_imageList->GetIcon( expandedIndex ); wxDataViewItem res = GetStore()->AppendContainer( parent, text, icon, expanded, data ); - + GetStore()->ItemAdded( parent, res ); - + return res; } @@ -2123,16 +2125,16 @@ wxDataViewItem wxDataViewTreeCtrl::InsertContainer( const wxDataViewItem& parent expanded = m_imageList->GetIcon( expandedIndex ); wxDataViewItem res = GetStore()->InsertContainer( parent, previous, text, icon, expanded, data ); - + GetStore()->ItemAdded( parent, res ); - + return res; } void wxDataViewTreeCtrl::SetItemText( const wxDataViewItem& item, const wxString &text ) { GetStore()->SetItemText(item,text); - + // notify control GetStore()->ValueChanged( item, 0 ); } @@ -2140,7 +2142,7 @@ void wxDataViewTreeCtrl::SetItemText( const wxDataViewItem& item, const wxString void wxDataViewTreeCtrl::SetItemIcon( const wxDataViewItem& item, const wxIcon &icon ) { GetStore()->SetItemIcon(item,icon); - + // notify control GetStore()->ValueChanged( item, 0 ); } @@ -2148,7 +2150,7 @@ void wxDataViewTreeCtrl::SetItemIcon( const wxDataViewItem& item, const wxIcon & void wxDataViewTreeCtrl::SetItemExpandedIcon( const wxDataViewItem& item, const wxIcon &icon ) { GetStore()->SetItemExpandedIcon(item,icon); - + // notify control GetStore()->ValueChanged( item, 0 ); } @@ -2158,7 +2160,7 @@ void wxDataViewTreeCtrl::DeleteItem( const wxDataViewItem& item ) wxDataViewItem parent_item = GetStore()->GetParent( item ); GetStore()->DeleteItem(item); - + // notify control GetStore()->ItemDeleted( parent_item, item ); } @@ -2185,7 +2187,7 @@ void wxDataViewTreeCtrl::DeleteChildren( const wxDataViewItem& item ) void wxDataViewTreeCtrl::DeleteAllItems() { GetStore()->DeleteAllItems(); - + GetStore()->Cleared(); } @@ -2197,7 +2199,7 @@ void wxDataViewTreeCtrl::OnExpanded( wxDataViewEvent &event ) if (!container) return; container->SetExpanded( true ); - + GetStore()->ItemChanged( event.GetItem() ); } @@ -2209,7 +2211,7 @@ void wxDataViewTreeCtrl::OnCollapsed( wxDataViewEvent &event ) if (!container) return; container->SetExpanded( false ); - + GetStore()->ItemChanged( event.GetItem() ); }