void *id = child->GetItem().GetID();
m_children.Add( id );
-#if 0
- if (m_internal->IsSorted())
+
+ if (m_internal->IsSorted() || m_internal->GetDataViewModel()->HasDefaultCompare())
{
g_internal = m_internal;
m_children.Sort( &wxGtkTreeModelChildCmp );
return m_children.Index( id );
}
-#endif
+
return m_children.GetCount()-1;
}
unsigned int AddLeave( void* id )
{
m_children.Add( id );
-#if 0
- if (m_internal->IsSorted())
+
+ if (m_internal->IsSorted() || m_internal->GetDataViewModel()->HasDefaultCompare())
{
g_internal = m_internal;
m_children.Sort( &wxGtkTreeModelChildCmp );
return m_children.Index( id );
}
-#endif
+
return m_children.GetCount()-1;
}
// wxDataViewRenderer
// ---------------------------------------------------------
+static gpointer s_user_data = NULL;
+
+static void
+wxgtk_cell_editable_editing_done( GtkCellEditable *editable,
+ wxDataViewRenderer *wxrenderer )
+{
+ wxDataViewColumn *column = wxrenderer->GetOwner();
+ wxDataViewCtrl *dv = column->GetOwner();
+ wxDataViewEvent event( wxEVT_COMMAND_DATAVIEW_ITEM_EDITING_DONE, dv->GetId() );
+ event.SetDataViewColumn( column );
+ event.SetModel( dv->GetModel() );
+ wxDataViewItem item( s_user_data );
+ event.SetItem( item );
+ dv->GetEventHandler()->ProcessEvent( event );
+}
+
+static void
+wxgtk_renderer_editing_started( GtkCellRenderer *cell, GtkCellEditable *editable,
+ gchar *path, wxDataViewRenderer *wxrenderer )
+{
+ wxDataViewColumn *column = wxrenderer->GetOwner();
+ wxDataViewCtrl *dv = column->GetOwner();
+ wxDataViewEvent event( wxEVT_COMMAND_DATAVIEW_ITEM_EDITING_STARTED, dv->GetId() );
+ event.SetDataViewColumn( column );
+ event.SetModel( dv->GetModel() );
+ GtkTreePath *tree_path = gtk_tree_path_new_from_string( path );
+ GtkTreeIter iter;
+ dv->GtkGetInternal()->get_iter( &iter, tree_path );
+ gtk_tree_path_free( tree_path );
+ wxDataViewItem item( iter.user_data );
+ event.SetItem( item );
+ dv->GetEventHandler()->ProcessEvent( event );
+
+ if (GTK_IS_CELL_EDITABLE(editable))
+ {
+ s_user_data = iter.user_data;
+
+ g_signal_connect (GTK_CELL_EDITABLE (editable), "editing_done",
+ G_CALLBACK (wxgtk_cell_editable_editing_done),
+ (gpointer) wxrenderer );
+
+ }
+}
+
+
IMPLEMENT_ABSTRACT_CLASS(wxDataViewRenderer, wxDataViewRendererBase)
wxDataViewRenderer::wxDataViewRenderer( const wxString &varianttype, wxDataViewCellMode mode,
// after the m_renderer pointer has been initialized
}
+void wxDataViewRenderer::GtkInitHandlers()
+{
+ if (!gtk_check_version(2,6,0))
+ {
+ g_signal_connect (GTK_CELL_RENDERER(m_renderer), "editing_started",
+ G_CALLBACK (wxgtk_renderer_editing_started),
+ this);
+ }
+}
+
void wxDataViewRenderer::SetMode( wxDataViewCellMode mode )
{
GtkCellRendererMode gtkMode;
g_value_unset( &gvalue );
g_signal_connect_after( m_renderer, "edited", G_CALLBACK(wxGtkTextRendererEditedCallback), this );
+
+ GtkInitHandlers();
}
SetMode(mode);
SetMode(mode);
SetAlignment(align);
+ GtkInitHandlers();
+
return true;
}
return true;
}
+
+// ---------------------------------------------------------
+// wxDataViewIconTextRenderer
+// ---------------------------------------------------------
+
+IMPLEMENT_CLASS(wxDataViewIconTextRenderer, wxDataViewCustomRenderer)
+
+wxDataViewIconTextRenderer::wxDataViewIconTextRenderer(
+ const wxString &varianttype, wxDataViewCellMode mode, int align ) :
+ wxDataViewCustomRenderer( varianttype, mode, align )
+{
+ SetMode(mode);
+ SetAlignment(align);
+}
+
+wxDataViewIconTextRenderer::~wxDataViewIconTextRenderer()
+{
+}
+
+bool wxDataViewIconTextRenderer::SetValue( const wxVariant &value )
+{
+ m_value << value;
+ return true;
+}
+
+bool wxDataViewIconTextRenderer::GetValue( wxVariant &value ) const
+{
+ return false;
+}
+
+bool wxDataViewIconTextRenderer::Render( wxRect cell, wxDC *dc, int state )
+{
+ dc->SetFont( GetOwner()->GetOwner()->GetFont() );
+
+ const wxIcon &icon = m_value.GetIcon();
+ if (icon.IsOk())
+ {
+ dc->DrawIcon( icon, cell.x, cell.y ); // TODO centre
+ cell.x += icon.GetWidth()+4;
+ }
+
+ dc->DrawText( m_value.GetText(), cell.x, cell.y );
+
+ return true;
+}
+
+wxSize wxDataViewIconTextRenderer::GetSize() const
+{
+ return wxSize(80,16); // TODO
+}
+
+wxControl* wxDataViewIconTextRenderer::CreateEditorCtrl( wxWindow *parent, wxRect labelRect, const wxVariant &value )
+{
+ return NULL;
+}
+
+bool wxDataViewIconTextRenderer::GetValueFromEditorCtrl( wxControl* editor, wxVariant &value )
+{
+ return false;
+}
+
// ---------------------------------------------------------
// wxDataViewColumn
// ---------------------------------------------------------
IMPLEMENT_CLASS(wxDataViewColumn, wxDataViewColumnBase)
+#include <wx/listimpl.cpp>
+WX_DEFINE_LIST(wxDataViewColumnList);
+
wxDataViewColumn::wxDataViewColumn( const wxString &title, wxDataViewRenderer *cell,
unsigned int model_column, int width,
wxAlignment align, int flags ) :
GtkTreeViewColumn *column = GTK_TREE_VIEW_COLUMN(m_column);
if (sortable)
+ {
gtk_tree_view_column_set_sort_column_id( column, GetModelColumn() );
+ }
else
+ {
gtk_tree_view_column_set_sort_column_id( column, -1 );
+ gtk_tree_view_column_set_sort_indicator( column, FALSE );
+ }
}
bool wxDataViewColumn::IsSortable() const
gtk_tree_view_column_set_sort_order( column, GTK_SORT_ASCENDING );
else
gtk_tree_view_column_set_sort_order( column, GTK_SORT_DESCENDING );
+
+ gtk_tree_view_column_set_sort_indicator( column, TRUE );
}
bool wxDataViewColumn::IsSortOrderAscending() const
{
if (node->GetChildCount() == 0)
{
- wxDataViewItem child = m_wx_model->GetFirstChild( node->GetItem() );
- while (child.IsOk())
+ wxDataViewItemArray children;
+ unsigned int count = m_wx_model->GetChildren( node->GetItem(), children );
+ unsigned int pos;
+ for (pos = 0; pos < count; pos++)
{
+ wxDataViewItem child = children[pos];
+
if (m_wx_model->IsContainer( child ))
node->AddNode( new wxGtkTreeModelNode( node, child, this ) );
else
node->AddLeave( child.GetID() );
// Don't send any events here
-
- child = m_wx_model->GetNextSibling( child );
}
}
}
if (!wxDataViewCtrlBase::AppendColumn(col))
return false;
- GtkTreeViewColumn *column = (GtkTreeViewColumn *)col->GetGtkHandle();
+ m_cols.Append( col );
+
+ gtk_tree_view_append_column( GTK_TREE_VIEW(m_treeview),
+ GTK_TREE_VIEW_COLUMN(col->GetGtkHandle()) );
+
+ return true;
+}
+
+unsigned int wxDataViewCtrl::GetColumnCount() const
+{
+ return m_cols.GetCount();
+}
+
+wxDataViewColumn* wxDataViewCtrl::GetColumn( unsigned int pos ) const
+{
+ GtkTreeViewColumn *gtk_col = gtk_tree_view_get_column( GTK_TREE_VIEW(m_treeview), pos );
+ if (!gtk_col)
+ return NULL;
+
+ wxDataViewColumnList::const_iterator iter;
+ for (iter = m_cols.begin(); iter != m_cols.end(); iter++)
+ {
+ wxDataViewColumn *col = *iter;
+ if (GTK_TREE_VIEW_COLUMN(col->GetGtkHandle()) == gtk_col)
+ {
+ return col;
+ }
+ }
+
+ return NULL;
+}
+
+bool wxDataViewCtrl::DeleteColumn( wxDataViewColumn *column )
+{
+ gtk_tree_view_remove_column( GTK_TREE_VIEW(m_treeview),
+ GTK_TREE_VIEW_COLUMN(column->GetGtkHandle()) );
+
+ m_cols.remove( column );
- gtk_tree_view_append_column( GTK_TREE_VIEW(m_treeview), column );
+ delete column;
return true;
}
-wxDataViewItem wxDataViewCtrl::GetSelection()
+bool wxDataViewCtrl::ClearColumns()
+{
+ wxDataViewColumnList::iterator iter;
+ for (iter = m_cols.begin(); iter != m_cols.end(); iter++)
+ {
+ wxDataViewColumn *col = *iter;
+ gtk_tree_view_remove_column( GTK_TREE_VIEW(m_treeview),
+ GTK_TREE_VIEW_COLUMN(col->GetGtkHandle()) );
+ }
+
+ m_cols.clear();
+
+ return true;
+}
+
+void wxDataViewCtrl::Expand( const wxDataViewItem & item )
+{
+ GtkTreeIter iter;
+ iter.user_data = item.GetID();
+ GtkTreePath *path = m_internal->get_path( &iter );
+ gtk_tree_view_expand_row( GTK_TREE_VIEW(m_treeview), path, false );
+ gtk_tree_path_free( path );
+}
+
+void wxDataViewCtrl::Collapse( const wxDataViewItem & item )
+{
+ GtkTreeIter iter;
+ iter.user_data = item.GetID();
+ GtkTreePath *path = m_internal->get_path( &iter );
+ gtk_tree_view_collapse_row( GTK_TREE_VIEW(m_treeview), path );
+ gtk_tree_path_free( path );
+}
+
+wxDataViewItem wxDataViewCtrl::GetSelection() const
{
GtkTreeSelection *selection = gtk_tree_view_get_selection( GTK_TREE_VIEW(m_treeview) );
GtkEnableSelectionEvents();
}
-void wxDataViewCtrl::EnsureVisible( const wxDataViewItem & item, wxDataViewColumn *column )
+void wxDataViewCtrl::EnsureVisible( const wxDataViewItem & item, const wxDataViewColumn *column )
{
GtkTreeIter iter;
iter.user_data = (gpointer) item.GetID();
}
void wxDataViewCtrl::HitTest( const wxPoint &point,
- wxDataViewItem &item, unsigned int &column ) const
+ wxDataViewItem &item, wxDataViewColumn *&column ) const
{
item = wxDataViewItem(0);
- column = 0;
+ column = NULL;
}
wxRect wxDataViewCtrl::GetItemRect( const wxDataViewItem &item,
- unsigned int column ) const
+ const wxDataViewColumn *column ) const
{
return wxRect();
}
void wxDataViewCtrl::DoSetExpanderColumn()
{
+ gtk_tree_view_set_expander_column( GTK_TREE_VIEW(m_treeview),
+ GTK_TREE_VIEW_COLUMN( GetExpanderColumn()->GetGtkHandle() ) );
}
void wxDataViewCtrl::DoSetIndent()