X-Git-Url: https://git.saurik.com/wxWidgets.git/blobdiff_plain/200c18cc6c5c11353f42c0550651c18a8a4cd5b0..5778dedc92f6d31435aa1cda6846979a0e9ad35b:/src/gtk/dataview.cpp?ds=sidebyside diff --git a/src/gtk/dataview.cpp b/src/gtk/dataview.cpp index 9e316bb268..dc98b83b90 100644 --- a/src/gtk/dataview.cpp +++ b/src/gtk/dataview.cpp @@ -111,7 +111,7 @@ public: 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: @@ -623,7 +623,10 @@ wxgtk_tree_model_iter_children (GtkTreeModel *tree_model, { 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 ); } @@ -1416,7 +1419,7 @@ bool wxGtkDataViewModelNotifier::ItemDeleted( const wxDataViewItem &parent, cons 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); @@ -1695,6 +1698,7 @@ int wxDataViewRenderer::GetAlignment() const void wxDataViewRenderer::EnableEllipsize(wxEllipsizeMode mode) { +#ifdef __WXGTK26__ if ( gtk_check_version(2, 6, 0) != NULL ) return; @@ -1709,10 +1713,14 @@ void wxDataViewRenderer::EnableEllipsize(wxEllipsizeMode mode) g_value_set_enum( &gvalue, static_cast(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; @@ -1728,6 +1736,9 @@ wxEllipsizeMode wxDataViewRenderer::GetEllipsizeMode() const g_value_unset( &gvalue ); return mode; +#else // GTK < 2.6 + return wxELLIPSIZE_NONE; +#endif // GTK 2.6/before } void @@ -2396,7 +2407,9 @@ bool wxDataViewChoiceRenderer::SetValue( const wxVariant &value ) { 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 ); } @@ -2415,8 +2428,8 @@ bool wxDataViewChoiceRenderer::GetValue( wxVariant &value ) const 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(this)->GetOwner()->GetOwner()->GetFont() ); + wxString temp = wxGTK_CONV_BACK_FONT(g_value_get_string(&gvalue), + GetOwner()->GetOwner()->GetFont()); g_value_unset( &gvalue ); value = temp; @@ -2451,6 +2464,48 @@ void wxDataViewChoiceRenderer::SetAlignment( int align ) 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 // --------------------------------------------------------- @@ -2787,7 +2842,7 @@ void wxDataViewColumn::OnInternalIdle() { if (m_isConnected) return; - + if (GTK_WIDGET_REALIZED(GetOwner()->m_treeview)) { GtkTreeViewColumn *column = GTK_TREE_VIEW_COLUMN(m_column); @@ -2796,6 +2851,9 @@ void wxDataViewColumn::OnInternalIdle() 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; } } @@ -3518,6 +3576,10 @@ GtkTreePath *wxDataViewCtrlInternal::get_path( GtkTreeIter *iter ) 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); @@ -3611,7 +3673,10 @@ gboolean wxDataViewCtrlInternal::iter_children( GtkTreeIter *iter, GtkTreeIter * 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; @@ -3759,16 +3824,23 @@ gboolean wxDataViewCtrlInternal::iter_parent( GtkTreeIter *iter, GtkTreeIter *ch } } -// 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; } @@ -4277,11 +4349,7 @@ void wxDataViewCtrl::OnInternalIdle() bool wxDataViewCtrl::AssociateModel( wxDataViewModel *model ) { - if ( m_internal ) - { - delete m_internal; - m_internal = NULL; - } + wxDELETE(m_internal); if (!wxDataViewCtrlBase::AssociateModel( model )) return false;