X-Git-Url: https://git.saurik.com/wxWidgets.git/blobdiff_plain/1f226ad8a70e32951c684de7555b3e1ce6f1153c..f81bd28859d95c2a8f8b6ec71885f8770b5e5e1a:/src/gtk/dataview.cpp diff --git a/src/gtk/dataview.cpp b/src/gtk/dataview.cpp index ba50a455d4..040ddc6e61 100644 --- a/src/gtk/dataview.cpp +++ b/src/gtk/dataview.cpp @@ -640,9 +640,7 @@ wxgtk_tree_model_iter_n_children (GtkTreeModel *tree_model, { 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 ( !iter || wxtree_model->stamp == iter->stamp, 0); return wxtree_model->internal->iter_n_children( iter ); } @@ -2973,6 +2971,7 @@ bool wxDataViewColumn::IsReorderable() const // wxGtkTreeModelNode //----------------------------------------------------------------------------- +#if 0 class wxGtkTreeModelChildWithPos { public: @@ -2987,10 +2986,20 @@ int wxGtkTreeModelChildWithPosCmp( const void* data1, const void* data2, const v 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() { @@ -3010,7 +3019,36 @@ 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; @@ -3022,25 +3060,27 @@ void wxGtkTreeModelNode::Resort() // Sort array keeping original positions wxQsort( temp, child_count, sizeof(wxGtkTreeModelChildWithPos), &wxGtkTreeModelChildWithPosCmp, m_internal ); - // Transfer positions to new_order array - gint *new_order = new gint[child_count]; - for (i = 0; i < child_count; i++) - new_order[i] = temp[i].pos; - // Transfer IDs to m_children + // Transfer positions to new_order array and + // IDs to m_children m_children.Clear(); for (i = 0; i < child_count; i++) + { + new_order[i] = temp[i].pos; m_children.Add( temp[i].id ); + } // 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++) { @@ -3377,8 +3417,8 @@ gboolean wxDataViewCtrlInternal::get_iter( GtkTreeIter *iter, GtkTreePath *path 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; } @@ -3429,8 +3469,8 @@ GtkTreePath *wxDataViewCtrlInternal::get_path( GtkTreeIter *iter ) 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 @@ -3458,7 +3498,8 @@ gboolean wxDataViewCtrlInternal::iter_next( GtkTreeIter *iter ) { wxDataViewIndexListModel *wx_model = (wxDataViewIndexListModel*) 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) return FALSE; @@ -3466,7 +3507,8 @@ gboolean wxDataViewCtrlInternal::iter_next( GtkTreeIter *iter ) if (n >= (int) wx_model->GetLastIndex()) 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 { @@ -3495,7 +3537,7 @@ gboolean wxDataViewCtrlInternal::iter_children( GtkTreeIter *iter, GtkTreeIter * return FALSE; iter->stamp = m_gtk_model->stamp; - iter->user_data = (gpointer) -1; + iter->user_data = (gpointer) 0; return TRUE; } @@ -3597,7 +3639,8 @@ gboolean wxDataViewCtrlInternal::iter_nth_child( GtkTreeIter *iter, GtkTreeIter 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; }