#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";
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
// ---------------------------------------------------------
}
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);
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()
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();
}
{
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 );
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 );
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() );
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;
wxDataViewVirtualListModel::wxDataViewVirtualListModel( unsigned int initial_size )
{
- m_lastIndex = initial_size-1;
+ m_size = initial_size;
}
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) );
+ wxDataViewItem item( wxUIntToPtr(row+1) );
wxDataViewModel::ItemDeleted( wxDataViewItem(0), item );
- m_lastIndex++;
+ m_size--;
}
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();
+ m_size -= rows.GetCount();
}
void wxDataViewVirtualListModel::RowChanged( unsigned int row )
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
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;
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 =
#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();
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 );
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;
}
void wxDataViewCtrlBase::ExpandAncestors( const wxDataViewItem & item )
{
if (!m_model) return;
-
+
if (!item.IsOk()) return;
wxVector<wxDataViewItem> parentChain;
-
+
// at first we get all the parents of the selected item
wxDataViewItem parent = m_model->GetParent(item);
while (parent.IsOk())
parentChain.push_back(parent);
parent = m_model->GetParent(parent);
}
-
+
// then we expand the parents, starting at the root
while (!parentChain.empty())
{
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 );
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
// 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 )
{
return m_cols[pos];
}
-
+
void wxDataViewListStore::AppendItem( const wxVector<wxVariant> &values, wxClientData *data )
{
wxDataViewListStoreLine *line = new wxDataViewListStoreLine( data );
line->m_values = values;
m_data.push_back( line );
-
+
RowAppended();
}
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<wxVariant> &values, wxClientData *data )
+void wxDataViewListStore::InsertItem( unsigned int row, const wxVector<wxVariant> &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<wxDataViewListStoreLine*>::iterator it = m_data.begin() + row;
m_data.erase( it );
-
+
RowDeleted( row );
}
wxDataViewListStoreLine* line = *it;
delete line;
}
-
+
+ m_data.clear();
+
Reset( 0 );
}
{
wxDataViewListStoreLine *line = m_data[row];
line->m_values[col] = value;
-
+
return true;
}
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 );
+}
+
+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::AppendTextCol( const wxString &label,
+
+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 )
new wxDataViewTreeStoreNode( parent_node, text, icon, data );
parent_node->GetChildren().Append( node );
- // notify control
- ItemAdded( parent, node->GetItem() );
-
return node->GetItem();
}
new wxDataViewTreeStoreNode( parent_node, text, icon, data );
parent_node->GetChildren().Insert( node );
- // notify control
- ItemAdded( parent, node->GetItem() );
-
return node->GetItem();
}
wxDataViewItem
-wxDataViewTreeStore::InsertItem(const wxDataViewItem& WXUNUSED(parent),
- const wxDataViewItem& WXUNUSED(previous),
- const wxString& WXUNUSED(text),
- const wxIcon& WXUNUSED(icon),
- wxClientData * WXUNUSED(data))
+wxDataViewTreeStore::InsertItem(const wxDataViewItem& parent,
+ const wxDataViewItem& previous,
+ const wxString& text,
+ const wxIcon& icon,
+ wxClientData *data)
{
- return wxDataViewItem(0);
+ 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);
+
+ wxDataViewTreeStoreNode *node =
+ new wxDataViewTreeStoreNode( parent_node, text, icon, data );
+ parent_node->GetChildren().Insert( (size_t) pos, node );
+
+ return node->GetItem();
}
wxDataViewItem wxDataViewTreeStore::PrependContainer( const wxDataViewItem& parent,
new wxDataViewTreeStoreContainerNode( parent_node, text, icon, expanded, data );
parent_node->GetChildren().Insert( node );
- // notify control
- ItemAdded( parent, node->GetItem() );
-
return node->GetItem();
}
new wxDataViewTreeStoreContainerNode( parent_node, text, icon, expanded, data );
parent_node->GetChildren().Append( node );
- // notify control
- ItemAdded( parent, node->GetItem() );
-
return node->GetItem();
}
wxDataViewItem
-wxDataViewTreeStore::InsertContainer(const wxDataViewItem& WXUNUSED(parent),
- const wxDataViewItem& WXUNUSED(previous),
- const wxString& WXUNUSED(text),
- const wxIcon& WXUNUSED(icon),
- const wxIcon& WXUNUSED(expanded),
- wxClientData * WXUNUSED(data))
+wxDataViewTreeStore::InsertContainer(const wxDataViewItem& parent,
+ const wxDataViewItem& previous,
+ const wxString& text,
+ const wxIcon& icon,
+ const wxIcon& expanded,
+ wxClientData * data)
{
- return wxDataViewItem(0);
+ 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 );
+
+ return node->GetItem();
}
wxDataViewItem wxDataViewTreeStore::GetNthChild( const wxDataViewItem& parent, unsigned int pos ) const
if (!node) return;
node->SetText( text );
-
- // notify control
- ValueChanged( item, 0 );
}
wxString wxDataViewTreeStore::GetItemText( const wxDataViewItem& item ) const
if (!node) return;
node->SetIcon( icon );
-
- // notify control
- ValueChanged( item, 0 );
}
const wxIcon &wxDataViewTreeStore::GetItemIcon( const wxDataViewItem& item ) const
if (!node) return;
node->SetExpandedIcon( icon );
-
- // notify control
- ValueChanged( item, 0 );
}
const wxIcon &wxDataViewTreeStore::GetItemExpandedIcon( const wxDataViewItem& item ) const
if (!node) return;
node->SetData( data );
-
- // notify control? only sensible when sorting on client data
- // ValueChanged( item, 0 );
}
wxClientData *wxDataViewTreeStore::GetItemData( const wxDataViewItem& item ) const
if (!node) return;
parent_node->GetChildren().DeleteObject( node );
-
- // notify control
- ItemDeleted( parent_item, item );
}
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()
}
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 );
if (m_imageList && (iconIndex != -1))
icon = m_imageList->GetIcon( iconIndex );
- return GetStore()->AppendItem( parent, text, icon, data );
+ wxDataViewItem res = GetStore()->AppendItem( parent, text, icon, data );
+
+ GetStore()->ItemAdded( parent, res );
+
+ return res;
}
wxDataViewItem wxDataViewTreeCtrl::PrependItem( const wxDataViewItem& parent,
if (m_imageList && (iconIndex != -1))
icon = m_imageList->GetIcon( iconIndex );
- return GetStore()->PrependItem( parent, text, icon, data );
+ wxDataViewItem res = GetStore()->PrependItem( parent, text, icon, data );
+
+ GetStore()->ItemAdded( parent, res );
+
+ return res;
}
wxDataViewItem wxDataViewTreeCtrl::InsertItem( const wxDataViewItem& parent, const wxDataViewItem& previous,
if (m_imageList && (iconIndex != -1))
icon = m_imageList->GetIcon( iconIndex );
- return GetStore()->InsertItem( parent, previous, text, icon, data );
+ wxDataViewItem res = GetStore()->InsertItem( parent, previous, text, icon, data );
+
+ GetStore()->ItemAdded( parent, res );
+
+ return res;
}
wxDataViewItem wxDataViewTreeCtrl::PrependContainer( const wxDataViewItem& parent,
if (m_imageList && (expandedIndex != -1))
expanded = m_imageList->GetIcon( expandedIndex );
- return GetStore()->PrependContainer( parent, text, icon, expanded, data );
+ wxDataViewItem res = GetStore()->PrependContainer( parent, text, icon, expanded, data );
+
+ GetStore()->ItemAdded( parent, res );
+
+ return res;
}
wxDataViewItem wxDataViewTreeCtrl::AppendContainer( const wxDataViewItem& parent,
if (m_imageList && (expandedIndex != -1))
expanded = m_imageList->GetIcon( expandedIndex );
- return GetStore()->AppendContainer( parent, text, icon, expanded, data );
+ wxDataViewItem res = GetStore()->AppendContainer( parent, text, icon, expanded, data );
+
+ GetStore()->ItemAdded( parent, res );
+
+ return res;
}
wxDataViewItem wxDataViewTreeCtrl::InsertContainer( const wxDataViewItem& parent, const wxDataViewItem& previous,
if (m_imageList && (expandedIndex != -1))
expanded = m_imageList->GetIcon( expandedIndex );
- return GetStore()->InsertContainer( parent, previous, text, icon, expanded, data );
+ 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 );
+}
+
+void wxDataViewTreeCtrl::SetItemIcon( const wxDataViewItem& item, const wxIcon &icon )
+{
+ GetStore()->SetItemIcon(item,icon);
+
+ // notify control
+ GetStore()->ValueChanged( item, 0 );
+}
+
+void wxDataViewTreeCtrl::SetItemExpandedIcon( const wxDataViewItem& item, const wxIcon &icon )
+{
+ GetStore()->SetItemExpandedIcon(item,icon);
+
+ // notify control
+ GetStore()->ValueChanged( item, 0 );
+}
+
+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 )
+{
+ 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();
}
void wxDataViewTreeCtrl::OnExpanded( wxDataViewEvent &event )
if (!container) return;
container->SetExpanded( true );
+
GetStore()->ItemChanged( event.GetItem() );
}
if (!container) return;
container->SetExpanded( false );
+
GetStore()->ItemChanged( event.GetItem() );
}