X-Git-Url: https://git.saurik.com/wxWidgets.git/blobdiff_plain/e4a8d29c50d9cbb8dfce76af6c3f0e882a620217..a188ac2988b6fedeead7a809124b8eaa2290c020:/src/gtk/dataview.cpp diff --git a/src/gtk/dataview.cpp b/src/gtk/dataview.cpp index 71bb162ad4..0110325a42 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; @@ -3025,7 +3063,6 @@ void wxGtkTreeModelNode::Resort() // 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; @@ -3033,15 +3070,17 @@ void wxGtkTreeModelNode::Resort() } // 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++) { @@ -3368,18 +3407,19 @@ GtkTreeModelFlags wxDataViewCtrlInternal::get_flags() 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; } @@ -3430,8 +3470,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 @@ -3457,17 +3497,19 @@ gboolean wxDataViewCtrlInternal::iter_next( GtkTreeIter *iter ) { 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) return FALSE; - if (n >= (int) wx_model->GetLastIndex()) + if (n >= (int) wx_model->GetCount()) 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 { @@ -3496,7 +3538,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) 1; return TRUE; } @@ -3527,6 +3569,11 @@ gboolean wxDataViewCtrlInternal::iter_has_child( GtkTreeIter *iter ) { if (m_wx_model->IsVirtualListModel()) { + wxDataViewVirtualListModel *wx_model = (wxDataViewVirtualListModel*) m_wx_model; + + if (iter == NULL) + return (gint) wx_model->GetCount(); + // this is a list, nodes have no children return FALSE; } @@ -3553,10 +3600,10 @@ gint wxDataViewCtrlInternal::iter_n_children( GtkTreeIter *iter ) { 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; } @@ -3586,7 +3633,7 @@ gboolean wxDataViewCtrlInternal::iter_nth_child( GtkTreeIter *iter, GtkTreeIter { if (m_wx_model->IsVirtualListModel()) { - wxDataViewIndexListModel *wx_model = (wxDataViewIndexListModel*) m_wx_model; + wxDataViewVirtualListModel *wx_model = (wxDataViewVirtualListModel*) m_wx_model; if (parent) return FALSE; @@ -3594,11 +3641,12 @@ gboolean wxDataViewCtrlInternal::iter_nth_child( GtkTreeIter *iter, GtkTreeIter 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; }