X-Git-Url: https://git.saurik.com/wxWidgets.git/blobdiff_plain/e700e2964b33a7c510edf8b726b90207ed66f6b7..12b5f4b4d2d8a07962da7ba3b78c8c1ec2634a67:/src/common/datavcmn.cpp diff --git a/src/common/datavcmn.cpp b/src/common/datavcmn.cpp index 2ef7b821fd..6628437655 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"; @@ -896,14 +894,24 @@ const wxDataViewModel* wxDataViewCtrlBase::GetModel() const return m_model; } +bool wxDataViewCtrlBase::EnableDragSource( const wxDataFormat &WXUNUSED(format) ) +{ + return false; +} + +bool wxDataViewCtrlBase::EnableDropTarget( const wxDataFormat &WXUNUSED(format) ) +{ + return false; +} + 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 +919,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()) { @@ -946,7 +954,6 @@ wxDataViewColumn * wxDataViewCtrlBase::AppendToggleColumn( const wxString &label, unsigned int model_column, wxDataViewCellMode mode, int width, wxAlignment align, int flags ) { - wxDataViewColumn *ret = new wxDataViewColumn( label, new wxDataViewToggleRenderer( wxT("bool"), mode ), model_column, width, align, flags ); @@ -1231,6 +1238,9 @@ wxDEFINE_EVENT( wxEVT_COMMAND_DATAVIEW_COLUMN_HEADER_RIGHT_CLICK, wxDataViewEven 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 @@ -1396,13 +1406,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(); } @@ -1411,7 +1421,7 @@ void wxDataViewListStore::PrependItem( const wxVector &values, wxClie wxDataViewListStoreLine *line = new wxDataViewListStoreLine( data ); line->m_values = values; m_data.insert( m_data.begin(), line ); - + RowPrepended(); } @@ -1420,7 +1430,7 @@ void wxDataViewListStore::InsertItem( unsigned int row, const wxVectorm_values = values; m_data.insert( m_data.begin()+row, line ); - + RowInserted( row ); } @@ -1428,7 +1438,7 @@ void wxDataViewListStore::DeleteItem( unsigned row ) { wxVector::iterator it = m_data.begin() + row; m_data.erase( it ); - + RowDeleted( row ); } @@ -1440,7 +1450,7 @@ void wxDataViewListStore::DeleteAllItems() wxDataViewListStoreLine* line = *it; delete line; } - + Reset( 0 ); } @@ -1454,7 +1464,7 @@ bool wxDataViewListStore::SetValueByRow( const wxVariant &value, unsigned int ro { wxDataViewListStoreLine *line = m_data[row]; line->m_values[col] = value; - + return true; } @@ -1495,50 +1505,93 @@ bool wxDataViewListCtrl::Create( wxWindow *parent, wxWindowID id, return wxDataViewCtrl::Create( parent, id, pos, size, style, validator ); } -void wxDataViewListCtrl::AppendCol( wxDataViewColumn *column, const wxString &varianttype ) +bool wxDataViewListCtrl::AppendColumn( wxDataViewColumn *column, const wxString &varianttype ) { GetStore()->AppendColumn( varianttype ); - AppendColumn( column ); + return wxDataViewCtrl::AppendColumn( column ); } -void wxDataViewListCtrl::PrependCol( wxDataViewColumn *column, const wxString &varianttype ) +bool wxDataViewListCtrl::PrependColumn( wxDataViewColumn *column, const wxString &varianttype ) { GetStore()->PrependColumn( varianttype ); - PrependColumn( column ); + return wxDataViewCtrl::PrependColumn( column ); } -void wxDataViewListCtrl::InsertCol( unsigned int pos, wxDataViewColumn *column, const wxString &varianttype ) +bool wxDataViewListCtrl::InsertColumn( unsigned int pos, wxDataViewColumn *column, const wxString &varianttype ) { GetStore()->InsertColumn( pos, varianttype ); - InsertColumn( pos, column ); + return wxDataViewCtrl::InsertColumn( pos, column ); } - -wxDataViewColumn *wxDataViewListCtrl::AppendTextCol( const wxString &label, + +bool wxDataViewListCtrl::PrependColumn( wxDataViewColumn *col ) +{ + return PrependColumn( col, "string" ); +} + +bool wxDataViewListCtrl::InsertColumn( unsigned int pos, wxDataViewColumn *col ) +{ + return InsertColumn( pos, col, "string" ); +} + +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") ); - return AppendTextColumn( label, GetStore()->GetColumnCount()-1, mode, width, align, flags ); + + wxDataViewColumn *ret = new wxDataViewColumn( label, + new wxDataViewTextRenderer( wxT("string"), mode ), + GetStore()->GetColumnCount()-1, width, align, flags ); + + wxDataViewCtrl::AppendColumn( ret ); + + return ret; } -wxDataViewColumn *wxDataViewListCtrl::AppendToggleCol( const wxString &label, +wxDataViewColumn *wxDataViewListCtrl::AppendToggleColumn( const wxString &label, wxDataViewCellMode mode, int width, wxAlignment align, int flags ) { GetStore()->AppendColumn( wxT("bool") ); - return AppendToggleColumn( label, GetStore()->GetColumnCount()-1, mode, width, align, flags ); + + wxDataViewColumn *ret = new wxDataViewColumn( label, + new wxDataViewToggleRenderer( wxT("bool"), mode ), + GetStore()->GetColumnCount()-1, width, align, flags ); + + wxDataViewCtrl::AppendColumn( ret ); + + return ret; } -wxDataViewColumn *wxDataViewListCtrl::AppendProgressCol( const wxString &label, +wxDataViewColumn *wxDataViewListCtrl::AppendProgressColumn( const wxString &label, wxDataViewCellMode mode, int width, wxAlignment align, int flags ) { GetStore()->AppendColumn( wxT("long") ); - return AppendProgressColumn( label, GetStore()->GetColumnCount()-1, mode, width, align, flags ); + + wxDataViewColumn *ret = new wxDataViewColumn( label, + new wxDataViewProgressRenderer( wxEmptyString, wxT("long"), mode ), + GetStore()->GetColumnCount()-1, width, align, flags ); + + wxDataViewCtrl::AppendColumn( ret ); + + return ret; } -wxDataViewColumn *wxDataViewListCtrl::AppendIconTextCol( const wxString &label, +wxDataViewColumn *wxDataViewListCtrl::AppendIconTextColumn( const wxString &label, wxDataViewCellMode mode, int width, wxAlignment align, int flags ) { GetStore()->AppendColumn( wxT("wxDataViewIconText") ); - return AppendIconTextColumn( label, GetStore()->GetColumnCount()-1, mode, width, align, flags ); + + wxDataViewColumn *ret = new wxDataViewColumn( label, + new wxDataViewIconTextRenderer( wxT("wxDataViewIconText"), mode ), + GetStore()->GetColumnCount()-1, width, align, flags ); + + wxDataViewCtrl::AppendColumn( ret ); + + return ret; } void wxDataViewListCtrl::OnSize( wxSizeEvent &event ) @@ -1683,11 +1736,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 ); @@ -1803,18 +1856,7 @@ void wxDataViewTreeStore::DeleteChildren( const wxDataViewItem& item ) wxDataViewTreeStoreContainerNode *node = FindContainerNode( item ); if (!node) return; - wxDataViewItemArray array; - wxDataViewTreeStoreNodeList::iterator iter; - for (iter = node->GetChildren().begin(); iter != node->GetChildren().end(); iter++) - { - wxDataViewTreeStoreNode* child = *iter; - array.Add( child->GetItem() ); - } - node->GetChildren().clear(); - - // notify control - ItemsDeleted( item, array ); } void wxDataViewTreeStore::DeleteAllItems() @@ -2010,9 +2052,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; } @@ -2024,9 +2066,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; } @@ -2038,9 +2080,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; } @@ -2056,9 +2098,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; } @@ -2074,9 +2116,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; } @@ -2092,16 +2134,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 ); } @@ -2109,7 +2151,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 ); } @@ -2117,7 +2159,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 ); } @@ -2127,20 +2169,34 @@ void wxDataViewTreeCtrl::DeleteItem( const wxDataViewItem& item ) wxDataViewItem parent_item = GetStore()->GetParent( item ); GetStore()->DeleteItem(item); - + // notify control GetStore()->ItemDeleted( parent_item, item ); } void wxDataViewTreeCtrl::DeleteChildren( const wxDataViewItem& item ) { - GetStore()->DeleteChildren(item); + wxDataViewTreeStoreContainerNode *node = GetStore()->FindContainerNode( item ); + if (!node) return; + + wxDataViewItemArray array; + wxDataViewTreeStoreNodeList::iterator iter; + for (iter = node->GetChildren().begin(); iter != node->GetChildren().end(); iter++) + { + wxDataViewTreeStoreNode* child = *iter; + array.Add( child->GetItem() ); + } + + GetStore()->DeleteChildren( item ); + + // notify control + GetStore()->ItemsDeleted( item, array ); } void wxDataViewTreeCtrl::DeleteAllItems() { GetStore()->DeleteAllItems(); - + GetStore()->Cleared(); } @@ -2152,7 +2208,7 @@ void wxDataViewTreeCtrl::OnExpanded( wxDataViewEvent &event ) if (!container) return; container->SetExpanded( true ); - + GetStore()->ItemChanged( event.GetItem() ); } @@ -2164,7 +2220,7 @@ void wxDataViewTreeCtrl::OnCollapsed( wxDataViewEvent &event ) if (!container) return; container->SetExpanded( false ); - + GetStore()->ItemChanged( event.GetItem() ); }