wxDataViewCtrl* GetOwner() { return m_owner; }
GtkWxTreeModel* GetGtkModel() { return m_gtk_model; }
- // item can be deleted already in the model
+ // item can be deleted already in the model
int GetIndexOf( const wxDataViewItem &parent, const wxDataViewItem &item );
protected:
{
GtkWxTreeModel *wxtree_model = (GtkWxTreeModel *) tree_model;
g_return_val_if_fail (GTK_IS_WX_TREE_MODEL (wxtree_model), FALSE);
- g_return_val_if_fail (wxtree_model->stamp == parent->stamp, FALSE);
+ if (parent)
+ {
+ g_return_val_if_fail (wxtree_model->stamp == parent->stamp, FALSE);
+ }
return wxtree_model->internal->iter_children( iter, parent );
}
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;
g_value_set_enum( &gvalue, static_cast<PangoEllipsizeMode>(mode) );
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;
g_value_unset( &gvalue );
return mode;
+#else // GTK < 2.6
+ return wxELLIPSIZE_NONE;
+#endif // GTK 2.6/before
}
void
{
GValue gvalue = { 0, };
g_value_init( &gvalue, G_TYPE_STRING );
- g_value_set_string( &gvalue, wxGTK_CONV_FONT( value.GetString(), GetOwner()->GetOwner()->GetFont() ) );
+ g_value_set_string(&gvalue,
+ wxGTK_CONV_FONT(value.GetString(),
+ GetOwner()->GetOwner()->GetFont()));
g_object_set_property( G_OBJECT(m_renderer), "text", &gvalue );
g_value_unset( &gvalue );
}
GValue gvalue = { 0, };
g_value_init( &gvalue, G_TYPE_STRING );
g_object_get_property( G_OBJECT(m_renderer), "text", &gvalue );
- wxString temp = wxGTK_CONV_BACK_FONT( g_value_get_string( &gvalue ),
- const_cast<wxDataViewChoiceRenderer*>(this)->GetOwner()->GetOwner()->GetFont() );
+ wxString temp = wxGTK_CONV_BACK_FONT(g_value_get_string(&gvalue),
+ GetOwner()->GetOwner()->GetFont());
g_value_unset( &gvalue );
value = temp;
g_value_unset( &gvalue );
}
+// ----------------------------------------------------------------------------
+// wxDataViewChoiceByIndexRenderer
+// ----------------------------------------------------------------------------
+
+wxDataViewChoiceByIndexRenderer::wxDataViewChoiceByIndexRenderer( const wxArrayString &choices,
+ wxDataViewCellMode mode, int alignment ) :
+ wxDataViewChoiceRenderer( choices, mode, alignment )
+{
+}
+
+void wxDataViewChoiceByIndexRenderer::GtkOnTextEdited(const gchar *itempath, const wxString& str)
+{
+ wxVariant value( (long) GetChoices().Index( str ) );
+
+ if (!Validate( value ))
+ return;
+
+ GtkTreePath *path = gtk_tree_path_new_from_string( itempath );
+ GtkTreeIter iter;
+ GetOwner()->GetOwner()->GtkGetInternal()->get_iter( &iter, path );
+ wxDataViewItem item( (void*) iter.user_data );;
+ gtk_tree_path_free( path );
+
+ GtkOnCellChanged(value, item, GetOwner()->GetModelColumn());
+}
+
+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;
+}
+
// ---------------------------------------------------------
// wxDataViewDateRenderer
// ---------------------------------------------------------
{
if (m_isConnected)
return;
-
+
if (GTK_WIDGET_REALIZED(GetOwner()->m_treeview))
{
GtkTreeViewColumn *column = GTK_TREE_VIEW_COLUMN(m_column);
g_signal_connect(column->button, "button_press_event",
G_CALLBACK (gtk_dataview_header_button_press_callback), this);
+ // otherwise the event will be blocked by GTK+
+ gtk_tree_view_column_set_clickable( column, TRUE );
+
m_isConnected = true;
}
}
if (m_wx_model->IsVirtualListModel())
{
+ // iter is root, add nothing
+ if (!iter->user_data)
+ return retval;
+
// user_data is just the index +1
int i = ( (wxUIntPtr) iter->user_data ) -1;
gtk_tree_path_append_index (retval, i);
return TRUE;
}
- wxDataViewItem item( (void*) parent->user_data );
+
+ wxDataViewItem item;
+ if (parent)
+ item = wxDataViewItem( (void*) parent->user_data );
if (!m_wx_model->IsContainer( item ))
return FALSE;
}
}
-// item can be deleted already in the model
+// 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 (m_wx_model->IsVirtualListModel())
+ {
+ return wxPtrToUInt(item.GetID()) - 1;
+ }
+ else
{
- if (children[j] == item.GetID())
- return j;
+ 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;
}
bool wxDataViewCtrl::AssociateModel( wxDataViewModel *model )
{
- if ( m_internal )
- {
- delete m_internal;
- m_internal = NULL;
- }
+ wxDELETE(m_internal);
if (!wxDataViewCtrlBase::AssociateModel( model ))
return false;