X-Git-Url: https://git.saurik.com/wxWidgets.git/blobdiff_plain/8af28fabffca3144a38602fa801205cd1183533c..143712733086515ee6ed40bbd9b7f11ce7f9d2e8:/src/common/datavcmn.cpp diff --git a/src/common/datavcmn.cpp b/src/common/datavcmn.cpp index 17f3e911d3..66982abf7a 100644 --- a/src/common/datavcmn.cpp +++ b/src/common/datavcmn.cpp @@ -38,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 // --------------------------------------------------------- @@ -233,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); @@ -316,7 +309,7 @@ wxDataViewIndexListModel::wxDataViewIndexListModel( unsigned int initial_size ) unsigned int i; for (i = 1; i < initial_size+1; i++) m_hash.Add( wxUIntToPtr(i) ); - m_lastIndex = initial_size + 1; + m_nextFreeID = initial_size + 1; } wxDataViewIndexListModel::~wxDataViewIndexListModel() @@ -334,7 +327,8 @@ void wxDataViewIndexListModel::Reset( unsigned int new_size ) unsigned int i; for (i = 1; i < new_size+1; i++) m_hash.Add( wxUIntToPtr(i) ); - m_lastIndex = new_size + 1; + + m_nextFreeID = new_size + 1; wxDataViewModel::Cleared(); } @@ -343,17 +337,22 @@ void wxDataViewIndexListModel::RowPrepended() { m_ordered = false; - unsigned int id = m_lastIndex++; + unsigned int id = m_nextFreeID; + m_nextFreeID++; + m_hash.Insert( wxUIntToPtr(id), 0 ); wxDataViewItem item( wxUIntToPtr(id) ); ItemAdded( wxDataViewItem(0), item ); + } void wxDataViewIndexListModel::RowInserted( unsigned int before ) { m_ordered = false; - unsigned int id = m_lastIndex++; + unsigned int id = m_nextFreeID; + m_nextFreeID++; + m_hash.Insert( wxUIntToPtr(id), before ); wxDataViewItem item( wxUIntToPtr(id) ); ItemAdded( wxDataViewItem(0), item ); @@ -361,7 +360,9 @@ void wxDataViewIndexListModel::RowInserted( unsigned int before ) void wxDataViewIndexListModel::RowAppended() { - unsigned int id = m_lastIndex++; + unsigned int id = m_nextFreeID; + m_nextFreeID++; + m_hash.Add( wxUIntToPtr(id) ); wxDataViewItem item( wxUIntToPtr(id) ); ItemAdded( wxDataViewItem(0), item ); @@ -409,10 +410,7 @@ void wxDataViewIndexListModel::RowValueChanged( unsigned int row, unsigned int c unsigned int wxDataViewIndexListModel::GetRow( const wxDataViewItem &item ) const { if (m_ordered) - { - unsigned int pos = wxPtrToUInt( item.GetID() ); - return pos-1; - } + return wxPtrToUInt(item.GetID())-1; // assert for not found return (unsigned int) m_hash.Index( item.GetID() ); @@ -432,12 +430,12 @@ 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) { - unsigned int pos1 = wxPtrToUInt(item1.GetID()); - unsigned int pos2 = wxPtrToUInt(item2.GetID()); + unsigned int pos1 = wxPtrToUInt(item1.GetID()); // -1 not needed here + unsigned int pos2 = wxPtrToUInt(item2.GetID()); // -1 not needed here if (ascending) return pos1 - pos2; @@ -500,7 +498,7 @@ unsigned int wxDataViewIndexListModel::GetChildren( const wxDataViewItem &item, wxDataViewVirtualListModel::wxDataViewVirtualListModel( unsigned int initial_size ) { - m_lastIndex = initial_size-1; + m_size = initial_size; } wxDataViewVirtualListModel::~wxDataViewVirtualListModel() @@ -509,41 +507,43 @@ wxDataViewVirtualListModel::~wxDataViewVirtualListModel() void wxDataViewVirtualListModel::Reset( unsigned int new_size ) { - m_lastIndex = new_size-1; + m_size = new_size; wxDataViewModel::Cleared(); } void wxDataViewVirtualListModel::RowPrepended() { - m_lastIndex++; - wxDataViewItem item( NULL ); + m_size++; + wxDataViewItem item( wxUIntToPtr(1) ); ItemAdded( wxDataViewItem(0), item ); } void wxDataViewVirtualListModel::RowInserted( unsigned int before ) { - m_lastIndex++; - wxDataViewItem item( wxUIntToPtr(before) ); + m_size++; + wxDataViewItem item( wxUIntToPtr(before+1) ); ItemAdded( wxDataViewItem(0), item ); } void wxDataViewVirtualListModel::RowAppended() { - m_lastIndex++; - wxDataViewItem item( wxUIntToPtr(m_lastIndex) ); + m_size++; + wxDataViewItem item( wxUIntToPtr(m_size) ); ItemAdded( wxDataViewItem(0), item ); } void wxDataViewVirtualListModel::RowDeleted( unsigned int row ) { - wxDataViewItem item( wxUIntToPtr(row) ); + m_size--; + wxDataViewItem item( wxUIntToPtr(row+1) ); wxDataViewModel::ItemDeleted( wxDataViewItem(0), item ); - m_lastIndex++; } void wxDataViewVirtualListModel::RowsDeleted( const wxArrayInt &rows ) { + m_size -= rows.GetCount(); + wxArrayInt sorted = rows; sorted.Sort( my_sort ); @@ -551,12 +551,10 @@ void wxDataViewVirtualListModel::RowsDeleted( const wxArrayInt &rows ) unsigned int i; for (i = 0; i < sorted.GetCount(); i++) { - wxDataViewItem item( wxUIntToPtr(sorted[i]) ); + wxDataViewItem item( wxUIntToPtr(sorted[i]+1) ); array.Add( item ); } wxDataViewModel::ItemsDeleted( wxDataViewItem(0), array ); - - m_lastIndex -= rows.GetCount(); } void wxDataViewVirtualListModel::RowChanged( unsigned int row ) @@ -571,12 +569,12 @@ void wxDataViewVirtualListModel::RowValueChanged( unsigned int row, unsigned int unsigned int wxDataViewVirtualListModel::GetRow( const wxDataViewItem &item ) const { - return wxPtrToUInt( item.GetID() ); + return wxPtrToUInt( item.GetID() ) -1; } wxDataViewItem wxDataViewVirtualListModel::GetItem( unsigned int row ) const { - return wxDataViewItem( wxUIntToPtr(row) ); + return wxDataViewItem( wxUIntToPtr(row+1) ); } bool wxDataViewVirtualListModel::HasDefaultCompare() const @@ -587,10 +585,10 @@ 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()); + unsigned int pos1 = wxPtrToUInt(item1.GetID()); // -1 not needed here + unsigned int pos2 = wxPtrToUInt(item2.GetID()); // -1 not needed here if (ascending) return pos1 - pos2; @@ -688,13 +686,30 @@ public: bool wxDataViewRendererBase::StartEditing( const wxDataViewItem &item, wxRect labelRect ) { + wxDataViewCtrl* dv_ctrl = GetOwner()->GetOwner(); + + // Before doing anything we send an event asking if editing of this item is really wanted. + wxDataViewEvent start_event( wxEVT_COMMAND_DATAVIEW_ITEM_START_EDITING, dv_ctrl->GetId() ); + start_event.SetDataViewColumn( GetOwner() ); + start_event.SetModel( dv_ctrl->GetModel() ); + start_event.SetItem( item ); + start_event.SetEventObject( dv_ctrl ); + dv_ctrl->GetEventHandler()->ProcessEvent( start_event ); + if( !start_event.IsAllowed() ) + return false; + m_item = item; // remember for later unsigned int col = GetOwner()->GetModelColumn(); wxVariant value; - GetOwner()->GetOwner()->GetModel()->GetValue( value, item, col ); + dv_ctrl->GetModel()->GetValue( value, item, col ); + + m_editorCtrl = CreateEditorCtrl( dv_ctrl->GetMainWindow(), labelRect, value ); + + // there might be no editor control for the given item + if(!m_editorCtrl) + return false; - m_editorCtrl = CreateEditorCtrl( GetOwner()->GetOwner()->GetMainWindow(), labelRect, value ); (void) new wxKillRef( m_editorCtrl.get() ); wxDataViewEditorCtrlEvtHandler *handler = @@ -709,18 +724,20 @@ bool wxDataViewRendererBase::StartEditing( const wxDataViewItem &item, wxRect la #endif // Now we should send Editing Started event - wxDataViewEvent event( wxEVT_COMMAND_DATAVIEW_ITEM_EDITING_STARTED, GetOwner()->GetOwner()->GetId() ); + wxDataViewEvent event( wxEVT_COMMAND_DATAVIEW_ITEM_EDITING_STARTED, dv_ctrl->GetId() ); event.SetDataViewColumn( GetOwner() ); - event.SetModel( GetOwner()->GetOwner()->GetModel() ); + event.SetModel( dv_ctrl->GetModel() ); event.SetItem( item ); - GetOwner()->GetOwner()->GetEventHandler()->ProcessEvent( event ); + event.SetEventObject( dv_ctrl ); + dv_ctrl->GetEventHandler()->ProcessEvent( event ); return true; } void wxDataViewRendererBase::CancelEditing() { - if (!m_editorCtrl) return; + if (!m_editorCtrl) + return; GetOwner()->GetOwner()->GetMainWindow()->SetFocus(); @@ -730,12 +747,15 @@ void wxDataViewRendererBase::CancelEditing() bool wxDataViewRendererBase::FinishEditing() { - if (!m_editorCtrl) return true; + if (!m_editorCtrl) + return true; wxVariant value; GetValueFromEditorCtrl( m_editorCtrl, value ); - GetOwner()->GetOwner()->GetMainWindow()->SetFocus(); + wxDataViewCtrl* dv_ctrl = GetOwner()->GetOwner(); + + dv_ctrl->GetMainWindow()->SetFocus(); m_editorCtrl->Hide(); wxPendingDelete.Append( m_editorCtrl ); @@ -744,15 +764,16 @@ bool wxDataViewRendererBase::FinishEditing() return false; unsigned int col = GetOwner()->GetModelColumn(); - GetOwner()->GetOwner()->GetModel()->SetValue( value, m_item, col ); - GetOwner()->GetOwner()->GetModel()->ValueChanged( m_item, col ); + dv_ctrl->GetModel()->SetValue( value, m_item, col ); + dv_ctrl->GetModel()->ValueChanged( m_item, col ); // Now we should send Editing Done event - wxDataViewEvent event( wxEVT_COMMAND_DATAVIEW_ITEM_EDITING_DONE, GetOwner()->GetOwner()->GetId() ); + wxDataViewEvent event( wxEVT_COMMAND_DATAVIEW_ITEM_EDITING_DONE, dv_ctrl->GetId() ); event.SetDataViewColumn( GetOwner() ); - event.SetModel( GetOwner()->GetOwner()->GetModel() ); + event.SetModel( dv_ctrl->GetModel() ); event.SetItem( m_item ); - GetOwner()->GetOwner()->GetEventHandler()->ProcessEvent( event ); + event.SetEventObject( dv_ctrl ); + dv_ctrl->GetEventHandler()->ProcessEvent( event ); return true; } @@ -1218,6 +1239,7 @@ 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 ); @@ -1228,10 +1250,14 @@ 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_CACHE_HINT, 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 // ------------------------------------- @@ -1300,7 +1326,7 @@ bool wxDataViewSpinRenderer::GetValue( wxVariant &value ) const // wxDataViewChoiceRenderer // ------------------------------------- -#if defined(wxHAS_GENERIC_DATAVIEWCTRL) || defined(__WXMAC__) +#if defined(wxHAS_GENERIC_DATAVIEWCTRL) || defined(__WXOSX_CARBON__) wxDataViewChoiceRenderer::wxDataViewChoiceRenderer( const wxArrayString& choices, wxDataViewCellMode mode, int alignment ) : wxDataViewCustomRenderer(wxT("string"), mode, alignment ) @@ -1415,7 +1441,7 @@ void wxDataViewListStore::PrependItem( const wxVector &values, wxClie RowPrepended(); } -void wxDataViewListStore::InsertItem( unsigned int row, const wxVector &values, +void wxDataViewListStore::InsertItem( unsigned int row, const wxVector &values, wxClientData *data ) { wxDataViewListStoreLine *line = new wxDataViewListStoreLine( data ); @@ -1531,7 +1557,7 @@ bool wxDataViewListCtrl::AppendColumn( wxDataViewColumn *col ) return AppendColumn( col, "string" ); } -wxDataViewColumn *wxDataViewListCtrl::AppendTextColumn( const wxString &label, +wxDataViewColumn *wxDataViewListCtrl::AppendTextColumn( const wxString &label, wxDataViewCellMode mode, int width, wxAlignment align, int flags ) { GetStore()->AppendColumn( wxT("string") ); @@ -1545,7 +1571,7 @@ wxDataViewColumn *wxDataViewListCtrl::AppendTextColumn( const wxString &label, return ret; } -wxDataViewColumn *wxDataViewListCtrl::AppendToggleColumn( const wxString &label, +wxDataViewColumn *wxDataViewListCtrl::AppendToggleColumn( const wxString &label, wxDataViewCellMode mode, int width, wxAlignment align, int flags ) { GetStore()->AppendColumn( wxT("bool") ); @@ -1559,7 +1585,7 @@ wxDataViewColumn *wxDataViewListCtrl::AppendToggleColumn( const wxString &label, return ret; } -wxDataViewColumn *wxDataViewListCtrl::AppendProgressColumn( const wxString &label, +wxDataViewColumn *wxDataViewListCtrl::AppendProgressColumn( const wxString &label, wxDataViewCellMode mode, int width, wxAlignment align, int flags ) { GetStore()->AppendColumn( wxT("long") ); @@ -1573,7 +1599,7 @@ wxDataViewColumn *wxDataViewListCtrl::AppendProgressColumn( const wxString &labe return ret; } -wxDataViewColumn *wxDataViewListCtrl::AppendIconTextColumn( const wxString &label, +wxDataViewColumn *wxDataViewListCtrl::AppendIconTextColumn( const wxString &label, wxDataViewCellMode mode, int width, wxAlignment align, int flags ) { GetStore()->AppendColumn( wxT("wxDataViewIconText") ); @@ -1854,7 +1880,7 @@ void wxDataViewTreeStore::DeleteChildren( const wxDataViewItem& item ) void wxDataViewTreeStore::DeleteAllItems() { - // TODO + DeleteChildren(m_root); } void @@ -1938,7 +1964,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 ); @@ -2134,7 +2160,7 @@ wxDataViewItem wxDataViewTreeCtrl::InsertContainer( const wxDataViewItem& parent } void wxDataViewTreeCtrl::SetItemText( const wxDataViewItem& item, const wxString &text ) -{ +{ GetStore()->SetItemText(item,text); // notify control @@ -2142,7 +2168,7 @@ void wxDataViewTreeCtrl::SetItemText( const wxDataViewItem& item, const wxString } void wxDataViewTreeCtrl::SetItemIcon( const wxDataViewItem& item, const wxIcon &icon ) -{ +{ GetStore()->SetItemIcon(item,icon); // notify control @@ -2150,7 +2176,7 @@ void wxDataViewTreeCtrl::SetItemIcon( const wxDataViewItem& item, const wxIcon & } void wxDataViewTreeCtrl::SetItemExpandedIcon( const wxDataViewItem& item, const wxIcon &icon ) -{ +{ GetStore()->SetItemExpandedIcon(item,icon); // notify control @@ -2158,7 +2184,7 @@ void wxDataViewTreeCtrl::SetItemExpandedIcon( const wxDataViewItem& item, const } void wxDataViewTreeCtrl::DeleteItem( const wxDataViewItem& item ) -{ +{ wxDataViewItem parent_item = GetStore()->GetParent( item ); GetStore()->DeleteItem(item); @@ -2168,7 +2194,7 @@ void wxDataViewTreeCtrl::DeleteItem( const wxDataViewItem& item ) } void wxDataViewTreeCtrl::DeleteChildren( const wxDataViewItem& item ) -{ +{ wxDataViewTreeStoreContainerNode *node = GetStore()->FindContainerNode( item ); if (!node) return; @@ -2187,7 +2213,7 @@ void wxDataViewTreeCtrl::DeleteChildren( const wxDataViewItem& item ) } void wxDataViewTreeCtrl::DeleteAllItems() -{ +{ GetStore()->DeleteAllItems(); GetStore()->Cleared();