+ wxString str;
+ str.Printf( wxT("%d"), (int) l );
+ wxSpinCtrl *sc = new wxSpinCtrl( parent, wxID_ANY, str,
+ labelRect.GetTopLeft(), size, wxSP_ARROW_KEYS|wxTE_PROCESS_ENTER, m_min, m_max, l );
+#ifdef __WXMAC__
+ size = sc->GetSize();
+ wxPoint pt = sc->GetPosition();
+ sc->SetSize( pt.x - 4, pt.y - 4, size.x, size.y );
+#endif
+
+ return sc;
+}
+
+bool wxDataViewSpinRenderer::GetValueFromEditorCtrl( wxWindow* editor, wxVariant &value )
+{
+ wxSpinCtrl *sc = (wxSpinCtrl*) editor;
+ long l = sc->GetValue();
+ value = l;
+ return true;
+}
+
+bool wxDataViewSpinRenderer::Render( wxRect rect, wxDC *dc, int state )
+{
+ wxString str;
+ str.Printf(wxT("%d"), (int) m_data );
+ RenderText( str, 0, rect, dc, state );
+ return true;
+}
+
+wxSize wxDataViewSpinRenderer::GetSize() const
+{
+ wxSize sz = GetTextExtent(wxString::Format("%d", (int)m_data));
+
+ // Allow some space for the spin buttons, which is approximately the size
+ // of a scrollbar (and getting pixel-exact value would be complicated).
+ // Also add some whitespace between the text and the button:
+ sz.x += wxSystemSettings::GetMetric(wxSYS_VSCROLL_X);
+ sz.x += GetTextExtent("M").x;
+
+ return sz;
+}
+
+bool wxDataViewSpinRenderer::SetValue( const wxVariant &value )
+{
+ m_data = value.GetLong();
+ return true;
+}
+
+bool wxDataViewSpinRenderer::GetValue( wxVariant &value ) const
+{
+ value = m_data;
+ return true;
+}
+
+// -------------------------------------
+// wxDataViewChoiceRenderer
+// -------------------------------------
+
+#if defined(wxHAS_GENERIC_DATAVIEWCTRL) || defined(__WXOSX_CARBON__)
+
+wxDataViewChoiceRenderer::wxDataViewChoiceRenderer( const wxArrayString& choices, wxDataViewCellMode mode, int alignment ) :
+ wxDataViewCustomRenderer(wxT("string"), mode, alignment )
+{
+ m_choices = choices;
+}
+
+wxWindow* wxDataViewChoiceRenderer::CreateEditorCtrl( wxWindow *parent, wxRect labelRect, const wxVariant &value )
+{
+ wxChoice* c = new wxChoice
+ (
+ parent,
+ wxID_ANY,
+ labelRect.GetTopLeft(),
+ wxSize(labelRect.GetWidth(), -1),
+ m_choices
+ );
+ c->Move(labelRect.GetRight() - c->GetRect().width, wxDefaultCoord);
+ c->SetStringSelection( value.GetString() );
+ return c;
+}
+
+bool wxDataViewChoiceRenderer::GetValueFromEditorCtrl( wxWindow* editor, wxVariant &value )
+{
+ wxChoice *c = (wxChoice*) editor;
+ wxString s = c->GetStringSelection();
+ value = s;
+ return true;
+}
+
+bool wxDataViewChoiceRenderer::Render( wxRect rect, wxDC *dc, int state )
+{
+ RenderText( m_data, 0, rect, dc, state );
+ return true;
+}
+
+wxSize wxDataViewChoiceRenderer::GetSize() const
+{
+ wxSize sz;
+
+ for ( wxArrayString::const_iterator i = m_choices.begin(); i != m_choices.end(); ++i )
+ sz.IncTo(GetTextExtent(*i));
+
+ // Allow some space for the right-side button, which is approximately the
+ // size of a scrollbar (and getting pixel-exact value would be complicated).
+ // Also add some whitespace between the text and the button:
+ sz.x += wxSystemSettings::GetMetric(wxSYS_VSCROLL_X);
+ sz.x += GetTextExtent("M").x;
+
+ return sz;
+}
+
+bool wxDataViewChoiceRenderer::SetValue( const wxVariant &value )
+{
+ m_data = value.GetString();
+ return true;
+}
+
+bool wxDataViewChoiceRenderer::GetValue( wxVariant &value ) const
+{
+ value = m_data;
+ return true;
+}
+
+// ----------------------------------------------------------------------------
+// wxDataViewChoiceByIndexRenderer
+// ----------------------------------------------------------------------------
+
+wxDataViewChoiceByIndexRenderer::wxDataViewChoiceByIndexRenderer( const wxArrayString &choices,
+ wxDataViewCellMode mode, int alignment ) :
+ wxDataViewChoiceRenderer( choices, mode, alignment )
+{
+}
+
+wxWindow* wxDataViewChoiceByIndexRenderer::CreateEditorCtrl( wxWindow *parent, wxRect labelRect, const wxVariant &value )
+{
+ wxVariant string_value = GetChoice( value.GetLong() );
+
+ return wxDataViewChoiceRenderer::CreateEditorCtrl( parent, labelRect, string_value );
+}
+
+bool wxDataViewChoiceByIndexRenderer::GetValueFromEditorCtrl( wxWindow* editor, wxVariant &value )
+{
+ wxVariant string_value;
+ if (!wxDataViewChoiceRenderer::GetValueFromEditorCtrl( editor, string_value ))
+ return false;
+
+ value = (long) GetChoices().Index( string_value.GetString() );
+ return true;
+}
+
+bool wxDataViewChoiceByIndexRenderer::SetValue( const wxVariant &value )
+{
+ wxVariant string_value = GetChoice( value.GetLong() );
+ return wxDataViewChoiceRenderer::SetValue( string_value );
+}
+
+bool wxDataViewChoiceByIndexRenderer::GetValue( wxVariant &value ) const
+{
+ wxVariant string_value;
+ if (!wxDataViewChoiceRenderer::GetValue( string_value ))
+ return false;
+
+ value = (long) GetChoices().Index( string_value.GetString() );
+ return true;
+}
+
+#endif
+
+// ---------------------------------------------------------
+// wxDataViewDateRenderer
+// ---------------------------------------------------------
+
+#if (defined(wxHAS_GENERIC_DATAVIEWCTRL) || defined(__WXGTK__)) && wxUSE_DATEPICKCTRL
+
+wxDataViewDateRenderer::wxDataViewDateRenderer(const wxString& varianttype,
+ wxDataViewCellMode mode, int align)
+ : wxDataViewCustomRenderer(varianttype, mode, align)
+{
+}
+
+wxWindow *
+wxDataViewDateRenderer::CreateEditorCtrl(wxWindow *parent, wxRect labelRect, const wxVariant& value)
+{
+ return new wxDatePickerCtrl
+ (
+ parent,
+ wxID_ANY,
+ value.GetDateTime(),
+ labelRect.GetTopLeft(),
+ labelRect.GetSize()
+ );
+}
+
+bool wxDataViewDateRenderer::GetValueFromEditorCtrl(wxWindow *editor, wxVariant& value)
+{
+ wxDatePickerCtrl *ctrl = static_cast<wxDatePickerCtrl*>(editor);
+ value = ctrl->GetValue();
+ return true;
+}
+
+bool wxDataViewDateRenderer::SetValue(const wxVariant& value)
+{
+ m_date = value.GetDateTime();
+ return true;
+}
+
+bool wxDataViewDateRenderer::GetValue(wxVariant& value) const
+{
+ value = m_date;
+ return true;
+}
+
+bool wxDataViewDateRenderer::Render(wxRect cell, wxDC* dc, int state)
+{
+ wxString tmp = m_date.FormatDate();
+ RenderText( tmp, 0, cell, dc, state );
+ return true;
+}
+
+wxSize wxDataViewDateRenderer::GetSize() const
+{
+ return GetTextExtent(m_date.FormatDate());
+}
+
+#endif // (defined(wxHAS_GENERIC_DATAVIEWCTRL) || defined(__WXGTK__)) && wxUSE_DATEPICKCTRL
+
+//-----------------------------------------------------------------------------
+// wxDataViewListStore
+//-----------------------------------------------------------------------------
+
+wxDataViewListStore::wxDataViewListStore()
+{
+}
+
+wxDataViewListStore::~wxDataViewListStore()
+{
+ wxVector<wxDataViewListStoreLine*>::iterator it;
+ for (it = m_data.begin(); it != m_data.end(); ++it)
+ {
+ wxDataViewListStoreLine* line = *it;
+ delete line;
+ }
+}
+
+void wxDataViewListStore::PrependColumn( const wxString &varianttype )
+{
+ m_cols.Insert( varianttype, 0 );
+}
+
+void wxDataViewListStore::InsertColumn( unsigned int pos, const wxString &varianttype )
+{
+ m_cols.Insert( varianttype, pos );
+}
+
+void wxDataViewListStore::AppendColumn( const wxString &varianttype )
+{
+ m_cols.Add( varianttype );
+}
+
+unsigned int wxDataViewListStore::GetColumnCount() const
+{
+ return m_cols.GetCount();
+}
+
+unsigned int wxDataViewListStore::GetItemCount() const
+{
+ return m_data.size();
+}
+
+wxString wxDataViewListStore::GetColumnType( unsigned int pos ) const
+{
+ return m_cols[pos];
+}
+
+void wxDataViewListStore::AppendItem( const wxVector<wxVariant> &values, wxUIntPtr data )
+{
+ wxDataViewListStoreLine *line = new wxDataViewListStoreLine( data );
+ line->m_values = values;
+ m_data.push_back( line );
+
+ RowAppended();
+}
+
+void wxDataViewListStore::PrependItem( const wxVector<wxVariant> &values, wxUIntPtr data )
+{
+ 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,
+ wxUIntPtr data )
+{
+ wxDataViewListStoreLine *line = new wxDataViewListStoreLine( data );
+ line->m_values = values;
+ m_data.insert( m_data.begin()+row, line );
+
+ RowInserted( row );
+}
+
+void wxDataViewListStore::DeleteItem( unsigned int row )
+{
+ wxVector<wxDataViewListStoreLine*>::iterator it = m_data.begin() + row;
+ delete *it;
+ m_data.erase( it );
+
+ RowDeleted( row );
+}
+
+void wxDataViewListStore::DeleteAllItems()
+{
+ wxVector<wxDataViewListStoreLine*>::iterator it;
+ for (it = m_data.begin(); it != m_data.end(); ++it)
+ {
+ wxDataViewListStoreLine* line = *it;
+ delete line;
+ }
+
+ m_data.clear();
+
+ Reset( 0 );
+}
+
+void wxDataViewListStore::SetItemData( const wxDataViewItem& item, wxUIntPtr data )
+{
+ wxDataViewListStoreLine* line = m_data[GetRow(item)];
+ if (!line) return;
+
+ line->SetData( data );
+}
+
+wxUIntPtr wxDataViewListStore::GetItemData( const wxDataViewItem& item ) const
+{
+ wxDataViewListStoreLine* line = m_data[GetRow(item)];
+ if (!line) return static_cast<wxUIntPtr>(NULL);
+
+ return line->GetData();
+}
+
+void wxDataViewListStore::GetValueByRow( wxVariant &value, unsigned int row, unsigned int col ) const
+{
+ wxDataViewListStoreLine *line = m_data[row];
+ value = line->m_values[col];
+}
+
+bool wxDataViewListStore::SetValueByRow( const wxVariant &value, unsigned int row, unsigned int col )
+{
+ wxDataViewListStoreLine *line = m_data[row];
+ line->m_values[col] = value;
+
+ return true;
+}
+
+//-----------------------------------------------------------------------------
+// wxDataViewListCtrl
+//-----------------------------------------------------------------------------
+
+IMPLEMENT_DYNAMIC_CLASS(wxDataViewListCtrl,wxDataViewCtrl)
+
+BEGIN_EVENT_TABLE(wxDataViewListCtrl,wxDataViewCtrl)
+ EVT_SIZE( wxDataViewListCtrl::OnSize )
+END_EVENT_TABLE()
+
+wxDataViewListCtrl::wxDataViewListCtrl()
+{
+}
+
+wxDataViewListCtrl::wxDataViewListCtrl( wxWindow *parent, wxWindowID id,
+ const wxPoint& pos, const wxSize& size, long style,
+ const wxValidator& validator )
+{
+ Create( parent, id, pos, size, style, validator );
+}
+
+wxDataViewListCtrl::~wxDataViewListCtrl()
+{
+}
+
+
+bool wxDataViewListCtrl::Create( wxWindow *parent, wxWindowID id,
+ const wxPoint& pos, const wxSize& size, long style,
+ const wxValidator& validator )
+{
+ if ( !wxDataViewCtrl::Create( parent, id, pos, size, style, validator ) )
+ return false;
+
+ wxDataViewListStore *store = new wxDataViewListStore;
+ AssociateModel( store );
+ store->DecRef();
+
+ return true;
+}
+
+bool wxDataViewListCtrl::AppendColumn( wxDataViewColumn *column, const wxString &varianttype )
+{
+ GetStore()->AppendColumn( varianttype );
+ return wxDataViewCtrl::AppendColumn( column );
+}
+
+bool wxDataViewListCtrl::PrependColumn( wxDataViewColumn *column, const wxString &varianttype )
+{
+ GetStore()->PrependColumn( varianttype );
+ return wxDataViewCtrl::PrependColumn( column );
+}
+
+bool wxDataViewListCtrl::InsertColumn( unsigned int pos, wxDataViewColumn *column, const wxString &varianttype )
+{
+ GetStore()->InsertColumn( pos, varianttype );
+ 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::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;
+}
+
+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;
+}
+
+wxDataViewColumn *wxDataViewListCtrl::AppendProgressColumn( const wxString &label,
+ 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;
+}
+
+wxDataViewColumn *wxDataViewListCtrl::AppendIconTextColumn( const wxString &label,
+ 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;
+}
+
+void wxDataViewListCtrl::OnSize( wxSizeEvent &event )
+{
+ event.Skip( true );
+}
+
+//-----------------------------------------------------------------------------
+// wxDataViewTreeStore
+//-----------------------------------------------------------------------------
+
+wxDataViewTreeStoreNode::wxDataViewTreeStoreNode(
+ wxDataViewTreeStoreNode *parent,
+ const wxString &text, const wxIcon &icon, wxClientData *data )
+{
+ m_parent = parent;
+ m_text = text;
+ m_icon = icon;
+ m_data = data;
+}
+
+wxDataViewTreeStoreNode::~wxDataViewTreeStoreNode()
+{
+ if (m_data)
+ delete m_data;
+}
+
+#include "wx/listimpl.cpp"
+WX_DEFINE_LIST(wxDataViewTreeStoreNodeList)
+
+wxDataViewTreeStoreContainerNode::wxDataViewTreeStoreContainerNode(
+ wxDataViewTreeStoreNode *parent, const wxString &text,
+ const wxIcon &icon, const wxIcon &expanded, wxClientData *data ) :
+ wxDataViewTreeStoreNode( parent, text, icon, data )
+{
+ m_iconExpanded = expanded;
+ m_isExpanded = false;
+ m_children.DeleteContents(true);
+}
+
+wxDataViewTreeStoreContainerNode::~wxDataViewTreeStoreContainerNode()
+{
+}
+
+//-----------------------------------------------------------------------------
+
+wxDataViewTreeStore::wxDataViewTreeStore()
+{
+ m_root = new wxDataViewTreeStoreContainerNode( NULL, wxEmptyString );
+}
+
+wxDataViewTreeStore::~wxDataViewTreeStore()
+{
+ delete m_root;
+}
+
+wxDataViewItem wxDataViewTreeStore::AppendItem( const wxDataViewItem& parent,
+ const wxString &text, const wxIcon &icon, wxClientData *data )
+{
+ wxDataViewTreeStoreContainerNode *parent_node = FindContainerNode( parent );
+ if (!parent_node) return wxDataViewItem(0);
+
+ wxDataViewTreeStoreNode *node =
+ new wxDataViewTreeStoreNode( parent_node, text, icon, data );
+ parent_node->GetChildren().Append( node );
+
+ return node->GetItem();
+}
+
+wxDataViewItem wxDataViewTreeStore::PrependItem( const wxDataViewItem& parent,
+ const wxString &text, const wxIcon &icon, wxClientData *data )
+{
+ wxDataViewTreeStoreContainerNode *parent_node = FindContainerNode( parent );
+ if (!parent_node) return wxDataViewItem(0);
+
+ wxDataViewTreeStoreNode *node =
+ new wxDataViewTreeStoreNode( parent_node, text, icon, data );
+ parent_node->GetChildren().Insert( node );
+
+ return node->GetItem();
+}
+
+wxDataViewItem
+wxDataViewTreeStore::InsertItem(const wxDataViewItem& parent,
+ const wxDataViewItem& previous,
+ const wxString& text,
+ const wxIcon& icon,
+ wxClientData *data)
+{
+ 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,
+ const wxString &text, const wxIcon &icon, const wxIcon &expanded,
+ wxClientData *data )
+{
+ wxDataViewTreeStoreContainerNode *parent_node = FindContainerNode( parent );
+ if (!parent_node) return wxDataViewItem(0);
+
+ wxDataViewTreeStoreContainerNode *node =
+ new wxDataViewTreeStoreContainerNode( parent_node, text, icon, expanded, data );
+ parent_node->GetChildren().Insert( node );
+
+ return node->GetItem();
+}
+
+wxDataViewItem
+wxDataViewTreeStore::AppendContainer(const wxDataViewItem& parent,
+ const wxString &text,
+ const wxIcon& icon,
+ const wxIcon& expanded,
+ wxClientData * data)
+{
+ wxDataViewTreeStoreContainerNode *parent_node = FindContainerNode( parent );
+ if (!parent_node) return wxDataViewItem(0);
+
+ wxDataViewTreeStoreContainerNode *node =
+ new wxDataViewTreeStoreContainerNode( parent_node, text, icon, expanded, data );
+ parent_node->GetChildren().Append( node );
+
+ return node->GetItem();
+}
+
+wxDataViewItem
+wxDataViewTreeStore::InsertContainer(const wxDataViewItem& parent,
+ const wxDataViewItem& previous,
+ const wxString& text,
+ const wxIcon& icon,
+ const wxIcon& expanded,
+ wxClientData * data)
+{
+ 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();
+}
+
+bool wxDataViewTreeStore::IsContainer( const wxDataViewItem& item ) const
+{
+ wxDataViewTreeStoreNode *node = FindNode( item );
+ if (!node) return false;
+
+ return node->IsContainer();
+}
+
+wxDataViewItem wxDataViewTreeStore::GetNthChild( const wxDataViewItem& parent, unsigned int pos ) const
+{
+ wxDataViewTreeStoreContainerNode *parent_node = FindContainerNode( parent );
+ if (!parent_node) return wxDataViewItem(0);
+
+ wxDataViewTreeStoreNodeList::compatibility_iterator node = parent_node->GetChildren().Item( pos );
+ if (node)
+ return wxDataViewItem(node->GetData());
+
+ return wxDataViewItem(0);
+}
+
+int wxDataViewTreeStore::GetChildCount( const wxDataViewItem& parent ) const
+{
+ wxDataViewTreeStoreNode *node = FindNode( parent );
+ if (!node) return -1;
+
+ if (!node->IsContainer())
+ return 0;
+
+ wxDataViewTreeStoreContainerNode *container_node = (wxDataViewTreeStoreContainerNode*) node;
+ return (int) container_node->GetChildren().GetCount();
+}
+
+void wxDataViewTreeStore::SetItemText( const wxDataViewItem& item, const wxString &text )
+{
+ wxDataViewTreeStoreNode *node = FindNode( item );
+ if (!node) return;
+
+ node->SetText( text );
+}
+
+wxString wxDataViewTreeStore::GetItemText( const wxDataViewItem& item ) const
+{
+ wxDataViewTreeStoreNode *node = FindNode( item );
+ if (!node) return wxEmptyString;
+
+ return node->GetText();
+}
+
+void wxDataViewTreeStore::SetItemIcon( const wxDataViewItem& item, const wxIcon &icon )
+{
+ wxDataViewTreeStoreNode *node = FindNode( item );
+ if (!node) return;
+
+ node->SetIcon( icon );
+}
+
+const wxIcon &wxDataViewTreeStore::GetItemIcon( const wxDataViewItem& item ) const
+{
+ wxDataViewTreeStoreNode *node = FindNode( item );
+ if (!node) return wxNullIcon;
+
+ return node->GetIcon();
+}
+
+void wxDataViewTreeStore::SetItemExpandedIcon( const wxDataViewItem& item, const wxIcon &icon )
+{
+ wxDataViewTreeStoreContainerNode *node = FindContainerNode( item );
+ if (!node) return;
+
+ node->SetExpandedIcon( icon );
+}
+
+const wxIcon &wxDataViewTreeStore::GetItemExpandedIcon( const wxDataViewItem& item ) const
+{
+ wxDataViewTreeStoreContainerNode *node = FindContainerNode( item );
+ if (!node) return wxNullIcon;
+
+ return node->GetExpandedIcon();
+}
+
+void wxDataViewTreeStore::SetItemData( const wxDataViewItem& item, wxClientData *data )
+{
+ wxDataViewTreeStoreNode *node = FindNode( item );
+ if (!node) return;
+
+ node->SetData( data );
+}
+
+wxClientData *wxDataViewTreeStore::GetItemData( const wxDataViewItem& item ) const
+{
+ wxDataViewTreeStoreNode *node = FindNode( item );
+ if (!node) return NULL;
+
+ return node->GetData();
+}
+
+void wxDataViewTreeStore::DeleteItem( const wxDataViewItem& item )
+{
+ if (!item.IsOk()) return;
+
+ wxDataViewItem parent_item = GetParent( item );
+
+ wxDataViewTreeStoreContainerNode *parent_node = FindContainerNode( parent_item );
+ if (!parent_node) return;
+
+ parent_node->GetChildren().DeleteObject( FindNode(item) );
+}
+
+void wxDataViewTreeStore::DeleteChildren( const wxDataViewItem& item )
+{
+ wxDataViewTreeStoreContainerNode *node = FindContainerNode( item );
+ if (!node) return;
+
+ node->GetChildren().clear();
+}
+
+void wxDataViewTreeStore::DeleteAllItems()
+{
+ DeleteChildren(wxDataViewItem(m_root));
+}
+
+void
+wxDataViewTreeStore::GetValue(wxVariant &variant,
+ const wxDataViewItem &item,
+ unsigned int WXUNUSED(col)) const
+{
+ // if (col != 0) return;
+
+ wxDataViewTreeStoreNode *node = FindNode( item );
+ if (!node) return;
+
+ wxIcon icon( node->GetIcon());
+ if (node->IsContainer())
+ {
+ wxDataViewTreeStoreContainerNode *container = (wxDataViewTreeStoreContainerNode*) node;
+ if (container->IsExpanded() && container->GetExpandedIcon().IsOk())
+ icon = container->GetExpandedIcon();
+ }
+
+ wxDataViewIconText data( node->GetText(), icon );
+
+ variant << data;
+}
+
+bool
+wxDataViewTreeStore::SetValue(const wxVariant& variant,
+ const wxDataViewItem& item,
+ unsigned int WXUNUSED(col))
+{
+ // if (col != 0) return false;
+
+ wxDataViewTreeStoreNode *node = FindNode( item );
+ if (!node) return false;
+
+ wxDataViewIconText data;
+
+ data << variant;
+
+ node->SetText( data.GetText() );
+ node->SetIcon( data.GetIcon() );
+
+ return true;
+}
+
+wxDataViewItem wxDataViewTreeStore::GetParent( const wxDataViewItem &item ) const
+{
+ wxDataViewTreeStoreNode *node = FindNode( item );
+ if (!node) return wxDataViewItem(0);
+
+ wxDataViewTreeStoreNode *parent = node->GetParent();
+ if (!parent) return wxDataViewItem(0);
+
+ if (parent == m_root)
+ return wxDataViewItem(0);
+
+ return parent->GetItem();
+}
+
+unsigned int wxDataViewTreeStore::GetChildren( const wxDataViewItem &item, wxDataViewItemArray &children ) const
+{
+ wxDataViewTreeStoreContainerNode *node = FindContainerNode( item );
+ if (!node) return 0;
+
+ wxDataViewTreeStoreNodeList::iterator iter;
+ for (iter = node->GetChildren().begin(); iter != node->GetChildren().end(); iter++)
+ {
+ wxDataViewTreeStoreNode* child = *iter;
+ children.Add( child->GetItem() );
+ }
+
+ return node->GetChildren().GetCount();
+}
+
+int wxDataViewTreeStore::Compare( const wxDataViewItem &item1, const wxDataViewItem &item2,
+ unsigned int WXUNUSED(column), bool WXUNUSED(ascending) ) const
+{
+ wxDataViewTreeStoreNode *node1 = FindNode( item1 );
+ wxDataViewTreeStoreNode *node2 = FindNode( item2 );
+
+ if (!node1 || !node2)
+ return 0;
+
+ wxDataViewTreeStoreContainerNode* parent1 =
+ (wxDataViewTreeStoreContainerNode*) node1->GetParent();
+ wxDataViewTreeStoreContainerNode* parent2 =
+ (wxDataViewTreeStoreContainerNode*) node2->GetParent();
+
+ if (parent1 != parent2)
+ {
+ wxLogError( wxT("Comparing items with different parent.") );
+ return 0;
+ }
+
+ if (node1->IsContainer() && !node2->IsContainer())
+ return -1;
+
+ if (node2->IsContainer() && !node1->IsContainer())
+ return 1;
+
+ return parent1->GetChildren().IndexOf( node1 ) - parent2->GetChildren().IndexOf( node2 );
+}
+
+wxDataViewTreeStoreNode *wxDataViewTreeStore::FindNode( const wxDataViewItem &item ) const
+{
+ if (!item.IsOk())
+ return m_root;
+
+ return (wxDataViewTreeStoreNode*) item.GetID();
+}
+
+wxDataViewTreeStoreContainerNode *wxDataViewTreeStore::FindContainerNode( const wxDataViewItem &item ) const
+{
+ if (!item.IsOk())
+ return (wxDataViewTreeStoreContainerNode*) m_root;
+
+ wxDataViewTreeStoreNode* node = (wxDataViewTreeStoreNode*) item.GetID();
+
+ if (!node->IsContainer())
+ return NULL;
+
+ return (wxDataViewTreeStoreContainerNode*) node;
+}
+
+//-----------------------------------------------------------------------------
+// wxDataViewTreeCtrl
+//-----------------------------------------------------------------------------
+
+IMPLEMENT_DYNAMIC_CLASS(wxDataViewTreeCtrl,wxDataViewCtrl)
+
+BEGIN_EVENT_TABLE(wxDataViewTreeCtrl,wxDataViewCtrl)
+ EVT_DATAVIEW_ITEM_EXPANDED(-1, wxDataViewTreeCtrl::OnExpanded)
+ EVT_DATAVIEW_ITEM_COLLAPSED(-1, wxDataViewTreeCtrl::OnCollapsed)
+ EVT_SIZE( wxDataViewTreeCtrl::OnSize )
+END_EVENT_TABLE()
+
+bool wxDataViewTreeCtrl::Create( wxWindow *parent, wxWindowID id,
+ const wxPoint& pos, const wxSize& size, long style, const wxValidator& validator )
+{
+ if ( !wxDataViewCtrl::Create( parent, id, pos, size, style, validator ) )
+ return false;
+
+ // create the standard model and a column in the tree
+ wxDataViewTreeStore *store = new wxDataViewTreeStore;
+ AssociateModel( store );
+ store->DecRef();
+
+ AppendIconTextColumn
+ (
+ wxString(), // no label (header is not shown anyhow)
+ 0, // the only model column
+ wxDATAVIEW_CELL_EDITABLE,
+ -1, // default width
+ wxALIGN_NOT, // and alignment
+ 0 // not resizable
+ );
+
+ return true;
+}
+
+wxDataViewItem wxDataViewTreeCtrl::AppendItem( const wxDataViewItem& parent,
+ const wxString &text, int iconIndex, wxClientData *data )
+{
+ wxDataViewItem res = GetStore()->
+ AppendItem( parent, text, GetImage(iconIndex), data );
+
+ GetStore()->ItemAdded( parent, res );
+
+ return res;
+}
+
+wxDataViewItem wxDataViewTreeCtrl::PrependItem( const wxDataViewItem& parent,
+ const wxString &text, int iconIndex, wxClientData *data )
+{
+ wxDataViewItem res = GetStore()->
+ PrependItem( parent, text, GetImage(iconIndex), data );
+
+ GetStore()->ItemAdded( parent, res );
+
+ return res;
+}
+
+wxDataViewItem wxDataViewTreeCtrl::InsertItem( const wxDataViewItem& parent, const wxDataViewItem& previous,
+ const wxString &text, int iconIndex, wxClientData *data )
+{
+ wxDataViewItem res = GetStore()->
+ InsertItem( parent, previous, text, GetImage(iconIndex), data );
+
+ GetStore()->ItemAdded( parent, res );
+
+ return res;
+}
+
+wxDataViewItem wxDataViewTreeCtrl::PrependContainer( const wxDataViewItem& parent,
+ const wxString &text, int iconIndex, int expandedIndex, wxClientData *data )
+{
+ wxDataViewItem res = GetStore()->
+ PrependContainer( parent, text,
+ GetImage(iconIndex), GetImage(expandedIndex), data );
+
+ GetStore()->ItemAdded( parent, res );
+
+ return res;
+}
+
+wxDataViewItem wxDataViewTreeCtrl::AppendContainer( const wxDataViewItem& parent,
+ const wxString &text, int iconIndex, int expandedIndex, wxClientData *data )
+{
+ wxDataViewItem res = GetStore()->
+ AppendContainer( parent, text,
+ GetImage(iconIndex), GetImage(expandedIndex), data );
+
+ GetStore()->ItemAdded( parent, res );
+
+ return res;
+}
+
+wxDataViewItem wxDataViewTreeCtrl::InsertContainer( const wxDataViewItem& parent, const wxDataViewItem& previous,
+ const wxString &text, int iconIndex, int expandedIndex, wxClientData *data )
+{
+ wxDataViewItem res = GetStore()->
+ InsertContainer( parent, previous, text,
+ GetImage(iconIndex), GetImage(expandedIndex), 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 (HasImageList()) return;
+
+ wxDataViewTreeStoreContainerNode* container = GetStore()->FindContainerNode( event.GetItem() );
+ if (!container) return;
+
+ container->SetExpanded( true );
+
+ GetStore()->ItemChanged( event.GetItem() );
+}
+
+void wxDataViewTreeCtrl::OnCollapsed( wxDataViewEvent &event )
+{
+ if (HasImageList()) return;
+
+ wxDataViewTreeStoreContainerNode* container = GetStore()->FindContainerNode( event.GetItem() );
+ if (!container) return;
+
+ container->SetExpanded( false );
+
+ GetStore()->ItemChanged( event.GetItem() );
+}
+
+void wxDataViewTreeCtrl::OnSize( wxSizeEvent &event )
+{
+#if defined(wxUSE_GENERICDATAVIEWCTRL)
+ // automatically resize our only column to take the entire control width
+ if ( GetColumnCount() )
+ {
+ wxSize size = GetClientSize();
+ GetColumn(0)->SetWidth(size.x);
+ }
+#endif
+ event.Skip( true );
+}
+
+#endif // wxUSE_DATAVIEWCTRL
+