wxDataViewCtrl* GetOwner() { return m_owner; }
GtkWxTreeModel* GetGtkModel() { return m_gtk_model; }
+ // item can be deleted already in the model
+ int GetIndexOf( const wxDataViewItem &parent, const wxDataViewItem &item );
+
protected:
void InitTree();
wxGtkTreeModelNode *FindNode( const wxDataViewItem &item );
gtype = G_TYPE_STRING;
else
{
- gtype = G_TYPE_STRING;
- // wxFAIL_MSG( wxT("non-string columns not supported yet") );
+ gtype = G_TYPE_POINTER;
+ // wxFAIL_MSG( wxT("non-string columns not supported for searching yet") );
}
return gtype;
bool wxGtkDataViewModelNotifier::ItemDeleted( const wxDataViewItem &parent, const wxDataViewItem &item )
{
+#if 0
+ // using _get_path for a deleted item cannot be
+ // a good idea
GtkTreeIter iter;
iter.stamp = m_wxgtk_model->stamp;
iter.user_data = (gpointer) item.GetID();
-
GtkTreePath *path = wxgtk_tree_model_get_path(
GTK_TREE_MODEL(m_wxgtk_model), &iter );
+#else
+ // so get the path from the parent
+ GtkTreeIter iter;
+ iter.stamp = m_wxgtk_model->stamp;
+ iter.user_data = (gpointer) parent.GetID();
+ GtkTreePath *path = wxgtk_tree_model_get_path(
+ GTK_TREE_MODEL(m_wxgtk_model), &iter );
+ // and add the final index ourselves
+ int index = m_owner->GtkGetInternal()->GetIndexOf( parent, item );
+ gtk_tree_path_append_index( path, index );
+#endif
+
gtk_tree_model_row_deleted(
GTK_TREE_MODEL(m_wxgtk_model), path );
gtk_tree_path_free (path);
void wxDataViewRenderer::EnableEllipsize(wxEllipsizeMode mode)
{
+#ifdef __WXGTK26__
if ( gtk_check_version(2, 6, 0) != NULL )
return;
+ GtkCellRendererText * const rend = GtkGetTextRenderer();
+ if ( !rend )
+ return;
+
// we use the same values in wxEllipsizeMode as PangoEllipsizeMode so we
// can just cast between them
GValue gvalue = { 0, };
g_value_init( &gvalue, PANGO_TYPE_ELLIPSIZE_MODE );
g_value_set_enum( &gvalue, static_cast<PangoEllipsizeMode>(mode) );
- g_object_set_property( G_OBJECT(m_renderer), "ellipsize", &gvalue );
+ g_object_set_property( G_OBJECT(rend), "ellipsize", &gvalue );
g_value_unset( &gvalue );
+#else // GTK < 2.6
+ wxUnusedVar(mode);
+#endif // GTK 2.6/before
}
wxEllipsizeMode wxDataViewRenderer::GetEllipsizeMode() const
{
+#ifdef __WXGTK26__
if ( gtk_check_version(2, 6, 0) != NULL )
return wxELLIPSIZE_NONE;
+ GtkCellRendererText * const rend = GtkGetTextRenderer();
+ if ( !rend )
+ return wxELLIPSIZE_NONE;
+
GValue gvalue = { 0, };
g_value_init( &gvalue, PANGO_TYPE_ELLIPSIZE_MODE );
- g_object_get_property( G_OBJECT(m_renderer), "ellipsize", &gvalue );
+ g_object_get_property( G_OBJECT(rend), "ellipsize", &gvalue );
wxEllipsizeMode
mode = static_cast<wxEllipsizeMode>(g_value_get_enum( &gvalue ));
g_value_unset( &gvalue );
return mode;
+#else // GTK < 2.6
+ return wxELLIPSIZE_NONE;
+#endif // GTK 2.6/before
}
void
bool wxDataViewTextRenderer::GtkSetAttr(const wxDataViewItemAttr& attr)
{
- return GtkApplyAttr(GTK_CELL_RENDERER_TEXT(m_renderer), attr);
+ return GtkApplyAttr(GtkGetTextRenderer(), attr);
+}
+
+GtkCellRendererText *wxDataViewTextRenderer::GtkGetTextRenderer() const
+{
+ return GTK_CELL_RENDERER_TEXT(m_renderer);
}
// ---------------------------------------------------------
Init(mode, align);
}
+GtkCellRendererText *wxDataViewCustomRenderer::GtkGetTextRenderer() const
+{
+ if ( !m_text_renderer )
+ {
+ // we create it on demand so need to do it even from a const function
+ const_cast<wxDataViewCustomRenderer *>(this)->
+ m_text_renderer = GTK_CELL_RENDERER_TEXT(gtk_cell_renderer_text_new());
+ }
+
+ return m_text_renderer;
+}
+
void wxDataViewCustomRenderer::RenderText( const wxString &text,
int xoffset,
wxRect cell,
wxDC *WXUNUSED(dc),
int WXUNUSED(state) )
{
- if (!m_text_renderer)
- m_text_renderer = GTK_CELL_RENDERER_TEXT(gtk_cell_renderer_text_new());
+
+ GtkCellRendererText * const textRenderer = GtkGetTextRenderer();
GValue gvalue = { 0, };
g_value_init( &gvalue, G_TYPE_STRING );
g_value_set_string( &gvalue, wxGTK_CONV_FONT( text, GetOwner()->GetOwner()->GetFont() ) );
- g_object_set_property( G_OBJECT(m_text_renderer), "text", &gvalue );
+ g_object_set_property( G_OBJECT(textRenderer), "text", &gvalue );
g_value_unset( &gvalue );
- GtkApplyAttr(m_text_renderer, GetAttr());
+ GtkApplyAttr(textRenderer, GetAttr());
GdkRectangle cell_area;
wxRectToGDKRect(cell, cell_area);
cell_area.x += xoffset;
cell_area.width -= xoffset;
- gtk_cell_renderer_render( GTK_CELL_RENDERER(m_text_renderer),
+ gtk_cell_renderer_render( GTK_CELL_RENDERER(textRenderer),
m_renderParams.window,
m_renderParams.widget,
m_renderParams.background_area,
GtkTreePath *wxDataViewCtrlInternal::get_path( GtkTreeIter *iter )
{
+ // When this is called from ItemDeleted(), the item is already
+ // deleted in the model.
+
GtkTreePath *retval = gtk_tree_path_new ();
if (m_wx_model->IsVirtualListModel())
}
}
+// item can be deleted already in the model
+int wxDataViewCtrlInternal::GetIndexOf( const wxDataViewItem &parent, const wxDataViewItem &item )
+{
+ wxGtkTreeModelNode *parent_node = FindNode( parent );
+ wxGtkTreeModelChildren &children = parent_node->GetChildren();
+ size_t j;
+ for (j = 0; j < children.GetCount(); j++)
+ {
+ if (children[j] == item.GetID())
+ return j;
+ }
+ return -1;
+}
+
+
static wxGtkTreeModelNode*
wxDataViewCtrlInternal_FindNode( wxDataViewModel * model, wxGtkTreeModelNode *treeNode, const wxDataViewItem &item )
{
if( node && node->GetNodes().GetCount() != 0 )
{
int len = node->GetNodes().GetCount();
- wxGtkTreeModelNodes nodes = node->GetNodes();
+ wxGtkTreeModelNodes &nodes = node->GetNodes();
int j = 0;
for( ; j < len; j ++)
{