else
{
gtype = G_TYPE_STRING;
- // wxFAIL_MSG( _T("non-string columns not supported yet") );
+ // wxFAIL_MSG( wxT("non-string columns not supported yet") );
}
return gtype;
}
else
{
- wxFAIL_MSG( _T("non-string columns not supported yet") );
+ wxFAIL_MSG( wxT("non-string columns not supported yet") );
}
}
{
GtkWxTreeModel *wxtree_model = (GtkWxTreeModel *) tree_model;
- //if (wxtree_model->stamp != iter->stamp)
- // wxPrintf( "crash\n" );
- // TODO: remove this code
+ // This happens when clearing the view by calling .._set_model( NULL );
+ if (iter->stamp == 0) return FALSE;
g_return_val_if_fail (GTK_IS_WX_TREE_MODEL (wxtree_model), FALSE);
g_return_val_if_fail (wxtree_model->stamp == iter->stamp, FALSE);
GtkTreeIter *iter)
{
GtkWxTreeModel *wxtree_model = (GtkWxTreeModel *) tree_model;
- g_return_val_if_fail (GTK_IS_WX_TREE_MODEL (wxtree_model), FALSE);
-
- if (iter != NULL)
- g_return_val_if_fail (wxtree_model->stamp == iter->stamp, 0);
+ g_return_val_if_fail (GTK_IS_WX_TREE_MODEL (wxtree_model), 0);
+ g_return_val_if_fail ( !iter || wxtree_model->stamp == iter->stamp, 0);
return wxtree_model->internal->iter_n_children( iter );
}
struct _GtkWxCellRendererText
{
GtkCellRendererText parent;
-
+
wxDataViewRenderer *wx_renderer;
};
event.SetColumn( wx_renderer->GetOwner()->GetModelColumn() );
event.SetItem( item );
dv->HandleWindowEvent( event );
-
+
if (event.IsAllowed())
return GTK_CELL_RENDERER_CLASS(text_cell_parent_class)->
start_editing( gtk_renderer, gdk_event, widget, path, background_area, cell_area, flags );
bool wxGtkDataViewModelNotifier::Cleared()
{
- gtk_tree_view_set_model( GTK_TREE_VIEW(m_owner->m_treeview), NULL );
-
- // this will create a new GTK model
m_owner->GtkGetInternal()->Cleared();
- SetGtkModel( m_owner->GtkGetInternal()->GetGtkModel() );
-
- gtk_tree_view_set_model( GTK_TREE_VIEW(m_owner->m_treeview), GTK_TREE_MODEL(m_wxgtk_model) );
-
- return false;
+ return true;
}
// ---------------------------------------------------------
{
m_renderer = NULL;
+ // we haven't changed them yet
+ m_usingDefaultAttrs = true;
+
// NOTE: SetMode() and SetAlignment() needs to be called in the renderer's ctor,
// after the m_renderer pointer has been initialized
}
if (!gtk_check_version(2,6,0))
{
g_signal_connect (GTK_CELL_RENDERER(m_renderer), "editing_started",
- G_CALLBACK (wxgtk_renderer_editing_started),
- this);
+ G_CALLBACK (wxgtk_renderer_editing_started),
+ this);
}
}
g_value_unset( &gvalue );
}
-// ---------------------------------------------------------
-// wxDataViewTextRendererAttr
-// ---------------------------------------------------------
-
-IMPLEMENT_CLASS(wxDataViewTextRendererAttr,wxDataViewTextRenderer)
-
-wxDataViewTextRendererAttr::wxDataViewTextRendererAttr( const wxString &varianttype,
- wxDataViewCellMode mode, int align ) :
- wxDataViewTextRenderer( varianttype, mode, align )
-{
-}
-
// ---------------------------------------------------------
// wxDataViewBitmapRenderer
// ---------------------------------------------------------
return FALSE;
}
-extern "C" {
-static void wxGtkTreeCellDataFunc( GtkTreeViewColumn *column,
- GtkCellRenderer *cell,
- GtkTreeModel *model,
- GtkTreeIter *iter,
- gpointer data );
-}
-
+extern "C"
+{
static void wxGtkTreeCellDataFunc( GtkTreeViewColumn *WXUNUSED(column),
GtkCellRenderer *renderer,
if (!wx_model->IsVirtualListModel())
{
-
- if (wx_model->IsContainer( item ))
- {
- if (wx_model->HasContainerColumns( item ) || (cell->GetOwner()->GetModelColumn() == 0))
+ gboolean visible;
+ if (wx_model->IsContainer( item ))
{
- GValue gvalue = { 0, };
- g_value_init( &gvalue, G_TYPE_BOOLEAN );
- g_value_set_boolean( &gvalue, TRUE );
- g_object_set_property( G_OBJECT(renderer), "visible", &gvalue );
- g_value_unset( &gvalue );
+ visible = wx_model->HasContainerColumns( item ) ||
+ (cell->GetOwner()->GetModelColumn() == 0);
}
else
{
- GValue gvalue = { 0, };
- g_value_init( &gvalue, G_TYPE_BOOLEAN );
- g_value_set_boolean( &gvalue, FALSE );
- g_object_set_property( G_OBJECT(renderer), "visible", &gvalue );
- g_value_unset( &gvalue );
-
- return;
+ visible = true;
}
- }
- else
- {
+
GValue gvalue = { 0, };
g_value_init( &gvalue, G_TYPE_BOOLEAN );
- g_value_set_boolean( &gvalue, TRUE );
+ g_value_set_boolean( &gvalue, visible );
g_object_set_property( G_OBJECT(renderer), "visible", &gvalue );
g_value_unset( &gvalue );
- }
+ if ( !visible )
+ return;
}
wxVariant value;
wx_model->GetValue( value, item, cell->GetOwner()->GetModelColumn() );
if (value.GetType() != cell->GetVariantType())
+ {
wxLogError( wxT("Wrong type, required: %s but: %s"),
value.GetType().c_str(),
cell->GetVariantType().c_str() );
+ }
cell->SetValue( value );
- if (cell->GtkHasAttributes())
- {
- wxDataViewItemAttr attr;
- bool colour_set = false;
- bool style_set = false;
- bool weight_set = false;
-
- if (wx_model->GetAttr( item, cell->GetOwner()->GetModelColumn(), attr ))
- {
- // this must be a GtkCellRendererText
- wxColour colour = attr.GetColour();
- if (colour.IsOk())
- {
- const GdkColor * const gcol = colour.GetColor();
- GValue gvalue = { 0, };
- g_value_init( &gvalue, GDK_TYPE_COLOR );
- g_value_set_boxed( &gvalue, gcol );
- g_object_set_property( G_OBJECT(renderer), "foreground_gdk", &gvalue );
- g_value_unset( &gvalue );
+ // deal with attributes
+ wxDataViewItemAttr attr;
+ if ( !wx_model->GetAttr( item, cell->GetOwner()->GetModelColumn(), attr )
+ && cell->GtkIsUsingDefaultAttrs() )
+ {
+ // no custom attributes specified and we're already using the default
+ // ones -- nothing to do
+ return;
+ }
- colour_set = true;
- }
+ bool usingDefaultAttrs = true;
+ if (attr.HasColour())
+ {
+ const GdkColor * const gcol = attr.GetColour().GetColor();
- if (attr.GetItalic())
- {
- GValue gvalue = { 0, };
- g_value_init( &gvalue, PANGO_TYPE_STYLE );
- g_value_set_enum( &gvalue, PANGO_STYLE_ITALIC );
- g_object_set_property( G_OBJECT(renderer), "style", &gvalue );
- g_value_unset( &gvalue );
+ GValue gvalue = { 0, };
+ g_value_init( &gvalue, GDK_TYPE_COLOR );
+ g_value_set_boxed( &gvalue, gcol );
+ g_object_set_property( G_OBJECT(renderer), "foreground_gdk", &gvalue );
+ g_value_unset( &gvalue );
- style_set = true;
- }
+ usingDefaultAttrs = false;
+ }
+ else
+ {
+ GValue gvalue = { 0, };
+ g_value_init( &gvalue, G_TYPE_BOOLEAN );
+ g_value_set_boolean( &gvalue, FALSE );
+ g_object_set_property( G_OBJECT(renderer), "foreground-set", &gvalue );
+ g_value_unset( &gvalue );
+ }
- if (attr.GetBold())
- {
- GValue gvalue = { 0, };
- g_value_init( &gvalue, PANGO_TYPE_WEIGHT );
- g_value_set_enum( &gvalue, PANGO_WEIGHT_BOLD );
- g_object_set_property( G_OBJECT(renderer), "weight", &gvalue );
- g_value_unset( &gvalue );
+ if (attr.GetItalic())
+ {
+ GValue gvalue = { 0, };
+ g_value_init( &gvalue, PANGO_TYPE_STYLE );
+ g_value_set_enum( &gvalue, PANGO_STYLE_ITALIC );
+ g_object_set_property( G_OBJECT(renderer), "style", &gvalue );
+ g_value_unset( &gvalue );
- weight_set = true;
- }
- }
+ usingDefaultAttrs = false;
+ }
+ else
+ {
+ GValue gvalue = { 0, };
+ g_value_init( &gvalue, G_TYPE_BOOLEAN );
+ g_value_set_boolean( &gvalue, FALSE );
+ g_object_set_property( G_OBJECT(renderer), "style-set", &gvalue );
+ g_value_unset( &gvalue );
+ }
- if (!style_set)
- {
- GValue gvalue = { 0, };
- g_value_init( &gvalue, G_TYPE_BOOLEAN );
- g_value_set_boolean( &gvalue, FALSE );
- g_object_set_property( G_OBJECT(renderer), "style-set", &gvalue );
- g_value_unset( &gvalue );
- }
- if (!weight_set)
- {
- GValue gvalue = { 0, };
- g_value_init( &gvalue, G_TYPE_BOOLEAN );
- g_value_set_boolean( &gvalue, FALSE );
- g_object_set_property( G_OBJECT(renderer), "weight-set", &gvalue );
- g_value_unset( &gvalue );
- }
+ if (attr.GetBold())
+ {
+ GValue gvalue = { 0, };
+ g_value_init( &gvalue, PANGO_TYPE_WEIGHT );
+ g_value_set_enum( &gvalue, PANGO_WEIGHT_BOLD );
+ g_object_set_property( G_OBJECT(renderer), "weight", &gvalue );
+ g_value_unset( &gvalue );
- if (!colour_set)
- {
- GValue gvalue = { 0, };
- g_value_init( &gvalue, G_TYPE_BOOLEAN );
- g_value_set_boolean( &gvalue, FALSE );
- g_object_set_property( G_OBJECT(renderer), "foreground-set", &gvalue );
- g_value_unset( &gvalue );
- }
+ usingDefaultAttrs = false;
+ }
+ else
+ {
+ GValue gvalue = { 0, };
+ g_value_init( &gvalue, G_TYPE_BOOLEAN );
+ g_value_set_boolean( &gvalue, FALSE );
+ g_object_set_property( G_OBJECT(renderer), "weight-set", &gvalue );
+ g_value_unset( &gvalue );
}
#if 0
}
#endif
+ cell->GtkSetUsingDefaultAttrs(usingDefaultAttrs);
}
+} // extern "C"
+
#include <wx/listimpl.cpp>
WX_DEFINE_LIST(wxDataViewColumnList)
// wxGtkTreeModelNode
//-----------------------------------------------------------------------------
+#if 0
class wxGtkTreeModelChildWithPos
{
public:
const wxGtkTreeModelChildWithPos* child2 = (const wxGtkTreeModelChildWithPos*) data2;
const wxDataViewCtrlInternal *internal = (const wxDataViewCtrlInternal *) user_data;
int ret = internal->GetDataViewModel()->Compare( child1->id, child2->id,
- internal->GetSortColumn(), (internal->GetSortOrder() == GTK_SORT_ASCENDING) );
+ internal->GetSortColumn(), (internal->GetSortOrder() == GTK_SORT_DESCENDING) );
return ret;
}
+#else
+static
+int LINKAGEMODE wxGtkTreeModelChildPtrCmp( void*** data1, void*** data2 )
+{
+ return gs_internal->GetDataViewModel()->Compare( **data1, **data2,
+ gs_internal->GetSortColumn(), (gs_internal->GetSortOrder() == GTK_SORT_ASCENDING) );
+}
+
+WX_DEFINE_ARRAY_PTR( void**, wxGtkTreeModelChildrenPtr );
+#endif
void wxGtkTreeModelNode::Resort()
{
return;
}
+ gint *new_order = new gint[child_count];
+
#if 1
+ // m_children has the original *void
+ // ptrs points to these
+ wxGtkTreeModelChildrenPtr ptrs;
+ size_t i;
+ for (i = 0; i < child_count; i++)
+ ptrs.Add( &(m_children[i]) );
+ // Sort the ptrs
+ gs_internal = m_internal;
+ ptrs.Sort( &wxGtkTreeModelChildPtrCmp );
+
+ wxGtkTreeModelChildren temp;
+ void** base_ptr = &(m_children[0]);
+ // Transfer positions to new_order array and
+ // IDs to temp
+ for (i = 0; i < child_count; i++)
+ {
+ new_order[i] = ptrs[i] - base_ptr;
+ temp.Add( *ptrs[i] );
+ }
+
+ // Transfer IDs back to m_children
+ m_children.Clear();
+ WX_APPEND_ARRAY( temp, m_children );
+#endif
+#if 0
+ // Too slow
+
// Build up array with IDs and original positions
wxGtkTreeModelChildWithPos* temp = new wxGtkTreeModelChildWithPos[child_count];
size_t i;
// Transfer positions to new_order array and
// IDs to m_children
m_children.Clear();
- gint *new_order = new gint[child_count];
for (i = 0; i < child_count; i++)
{
new_order[i] = temp[i].pos;
}
// Delete array
delete [] temp;
-#else
+#endif
+
+#if 0
+ // Too slow
+
wxGtkTreeModelChildren temp;
WX_APPEND_ARRAY( temp, m_children );
gs_internal = m_internal;
m_children.Sort( &wxGtkTreeModelChildCmp );
-
- gint *new_order = new gint[child_count];
unsigned int pos;
for (pos = 0; pos < child_count; pos++)
gtk_tree_path_free (path);
delete [] new_order;
-
+
unsigned int pos;
for (pos = 0; pos < node_count; pos++)
{
bool wxDataViewCtrlInternal::Cleared()
{
+ GtkWidget* tree_widget = GetOwner()->GtkGetTreeView();
+ gtk_tree_view_set_model( GTK_TREE_VIEW(tree_widget), NULL );
+ gtk_tree_view_set_model( GTK_TREE_VIEW(tree_widget), GTK_TREE_MODEL(m_gtk_model) );
+
if (m_root)
{
delete m_root;
InitTree();
}
- // Create new GTK model
- g_object_unref( m_gtk_model );
- m_gtk_model = wxgtk_tree_model_new();
- m_gtk_model->internal = this;
-
return true;
}
gboolean wxDataViewCtrlInternal::get_iter( GtkTreeIter *iter, GtkTreePath *path )
{
+
if (m_wx_model->IsVirtualListModel())
{
- wxDataViewIndexListModel *wx_model = (wxDataViewIndexListModel*) m_wx_model;
+ wxDataViewVirtualListModel *wx_model = (wxDataViewVirtualListModel*) m_wx_model;
unsigned int i = (unsigned int)gtk_tree_path_get_indices (path)[0];
- if (i >= wx_model->GetLastIndex() + 1)
+ if (i >= wx_model->GetCount())
return FALSE;
iter->stamp = m_gtk_model->stamp;
- // user_data is just the index
- iter->user_data = (gpointer) i;
+ // user_data is just the index +1
+ iter->user_data = (gpointer) (i+1);
return TRUE;
}
if (m_wx_model->IsVirtualListModel())
{
- // user_data is just the index
- int i = (wxUIntPtr) iter->user_data;
+ // user_data is just the index +1
+ int i = ( (wxUIntPtr) iter->user_data ) -1;
gtk_tree_path_append_index (retval, i);
}
else
{
if (m_wx_model->IsVirtualListModel())
{
- wxDataViewIndexListModel *wx_model = (wxDataViewIndexListModel*) m_wx_model;
+ wxDataViewVirtualListModel *wx_model = (wxDataViewVirtualListModel*) m_wx_model;
- int n = (wxUIntPtr) iter->user_data;
+ // user_data is just the index +1
+ int n = ( (wxUIntPtr) iter->user_data ) -1;
if (n == -1)
+ {
+ iter->user_data = NULL;
return FALSE;
+ }
- if (n >= (int) wx_model->GetLastIndex())
+ if (n >= (int) wx_model->GetCount()-1)
+ {
+ iter->user_data = NULL;
return FALSE;
+ }
- iter->user_data = (gpointer) ++n;
+ // user_data is just the index +1 (+2 because we need the next)
+ iter->user_data = (gpointer) (n+2);
}
else
{
wxGtkTreeModelNode *parent = FindParentNode( iter );
if( parent == NULL )
+ {
+ iter->user_data = NULL;
return FALSE;
+ }
int pos = parent->GetChildren().Index( iter->user_data );
if (pos == (int) parent->GetChildCount()-1)
+ {
+ iter->user_data = NULL;
return FALSE;
+ }
- iter->stamp = m_gtk_model->stamp;
iter->user_data = parent->GetChildren().Item( pos+1 );
}
return FALSE;
iter->stamp = m_gtk_model->stamp;
- iter->user_data = (gpointer) -1;
+ iter->user_data = (gpointer) 1;
return TRUE;
}
else
{
+ if (iter == NULL)
+ {
+ if (m_root->GetChildCount() == 0) return FALSE;
+ iter->stamp = m_gtk_model->stamp;
+ iter->user_data = (gpointer) m_root->GetChildren().Item( 0 );
+ return TRUE;
+ }
+
wxDataViewItem item( (void*) parent->user_data );
if (!m_wx_model->IsContainer( item ))
{
if (m_wx_model->IsVirtualListModel())
{
+ wxDataViewVirtualListModel *wx_model = (wxDataViewVirtualListModel*) m_wx_model;
+
+ if (iter == NULL)
+ return (wx_model->GetCount() > 0);
+
// this is a list, nodes have no children
return FALSE;
}
else
{
+ if (iter == NULL)
+ return (m_root->GetChildCount() > 0);
+
wxDataViewItem item( (void*) iter->user_data );
bool is_container = m_wx_model->IsContainer( item );
{
if (m_wx_model->IsVirtualListModel())
{
- wxDataViewIndexListModel *wx_model = (wxDataViewIndexListModel*) m_wx_model;
+ wxDataViewVirtualListModel *wx_model = (wxDataViewVirtualListModel*) m_wx_model;
if (iter == NULL)
- return (gint) wx_model->GetLastIndex() + 1;
+ return (gint) wx_model->GetCount();
return 0;
}
BuildBranch( parent_node );
- // wxPrintf( "iter_n_children %d\n", parent_node->GetChildCount() );
-
return parent_node->GetChildCount();
}
}
{
if (m_wx_model->IsVirtualListModel())
{
- wxDataViewIndexListModel *wx_model = (wxDataViewIndexListModel*) m_wx_model;
+ wxDataViewVirtualListModel *wx_model = (wxDataViewVirtualListModel*) m_wx_model;
if (parent)
return FALSE;
if (n < 0)
return FALSE;
- if (n >= (gint) wx_model->GetLastIndex() + 1)
+ if (n >= (gint) wx_model->GetCount())
return FALSE;
iter->stamp = m_gtk_model->stamp;
- iter->user_data = (gpointer) n;
+ // user_data is just the index +1
+ iter->user_data = (gpointer) (n+1);
return TRUE;
}
BuildBranch( parent_node );
- // wxPrintf( "iter_nth_child %d\n", n );
-
iter->stamp = m_gtk_model->stamp;
iter->user_data = parent_node->GetChildren().Item( n );
GtkTreeIter iter;
dv->GtkGetInternal()->get_iter( &iter, path );
- // wxPrintf( "mouse %d %d\n", (int) gdk_event->x, (int) gdk_event->y );
-
gtk_tree_path_free( path );
}
}
G_CALLBACK (wxdataview_selection_changed_callback), this);
}
+// ----------------------------------------------------------------------------
+// visual attributes stuff
+// ----------------------------------------------------------------------------
+
// static
wxVisualAttributes
wxDataViewCtrl::GetClassDefaultAttributes(wxWindowVariant WXUNUSED(variant))
return GetDefaultAttributesFromGTKWidget(gtk_tree_view_new);
}
+void wxDataViewCtrl::DoApplyWidgetStyle(GtkRcStyle *style)
+{
+ wxDataViewCtrlBase::DoApplyWidgetStyle(style);
+ gtk_widget_modify_style(m_treeview, style);
+}
-#endif
- // !wxUSE_GENERICDATAVIEWCTRL
+#endif // !wxUSE_GENERICDATAVIEWCTRL
-#endif
- // wxUSE_DATAVIEWCTRL
+#endif // wxUSE_DATAVIEWCTRL