removed Set/GetSortAscending from wxDataViewModel and move into wxDataViewCtrl
git-svn-id: https://svn.wxwidgets.org/svn/wx/wxWidgets/trunk@48139 c3d73ce0-8a6f-49c7-b76d-6d57e0e08775
This commit is contained in:
@@ -155,9 +155,6 @@ public:
|
|||||||
|
|
||||||
void SetSortingColumn( unsigned int col ) { m_sortingColumn = col; }
|
void SetSortingColumn( unsigned int col ) { m_sortingColumn = col; }
|
||||||
unsigned int GetSortingColumn() { return m_sortingColumn; }
|
unsigned int GetSortingColumn() { return m_sortingColumn; }
|
||||||
void SetSortOrderAscending( bool ascending ) { m_ascending = ascending; }
|
|
||||||
bool GetSortOrderAscending() { return m_ascending; }
|
|
||||||
|
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
// the user should not delete this class directly: he should use DecRef() instead!
|
// the user should not delete this class directly: he should use DecRef() instead!
|
||||||
@@ -165,7 +162,6 @@ protected:
|
|||||||
|
|
||||||
wxDataViewModelNotifiers m_notifiers;
|
wxDataViewModelNotifiers m_notifiers;
|
||||||
unsigned int m_sortingColumn;
|
unsigned int m_sortingColumn;
|
||||||
bool m_ascending;
|
|
||||||
};
|
};
|
||||||
|
|
||||||
// ---------------------------------------------------------
|
// ---------------------------------------------------------
|
||||||
|
@@ -43,7 +43,6 @@ wxDataViewModel::wxDataViewModel()
|
|||||||
{
|
{
|
||||||
m_notifiers.DeleteContents( true );
|
m_notifiers.DeleteContents( true );
|
||||||
m_sortingColumn = 0;
|
m_sortingColumn = 0;
|
||||||
m_ascending = true;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
bool wxDataViewModel::ItemAdded( const wxDataViewItem &parent, const wxDataViewItem &item )
|
bool wxDataViewModel::ItemAdded( const wxDataViewItem &parent, const wxDataViewItem &item )
|
||||||
@@ -157,13 +156,6 @@ int wxDataViewModel::Compare( const wxDataViewItem &item1, const wxDataViewItem
|
|||||||
GetValue( value1, item1, m_sortingColumn );
|
GetValue( value1, item1, m_sortingColumn );
|
||||||
GetValue( value2, item2, m_sortingColumn );
|
GetValue( value2, item2, m_sortingColumn );
|
||||||
|
|
||||||
if (!m_ascending)
|
|
||||||
{
|
|
||||||
wxVariant temp = value1;
|
|
||||||
value1 = value2;
|
|
||||||
value2 = temp;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (value1.GetType() == wxT("string"))
|
if (value1.GetType() == wxT("string"))
|
||||||
{
|
{
|
||||||
wxString str1 = value1.GetString();
|
wxString str1 = value1.GetString();
|
||||||
@@ -197,8 +189,6 @@ int wxDataViewModel::Compare( const wxDataViewItem &item1, const wxDataViewItem
|
|||||||
unsigned long litem1 = (unsigned long) item1.GetID();
|
unsigned long litem1 = (unsigned long) item1.GetID();
|
||||||
unsigned long litem2 = (unsigned long) item2.GetID();
|
unsigned long litem2 = (unsigned long) item2.GetID();
|
||||||
|
|
||||||
if (!m_ascending)
|
|
||||||
return litem2-litem1;
|
|
||||||
return litem1-litem2;
|
return litem1-litem2;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@@ -43,7 +43,9 @@
|
|||||||
//-----------------------------------------------------------------------------
|
//-----------------------------------------------------------------------------
|
||||||
//-----------------------------------------------------------------------------
|
//-----------------------------------------------------------------------------
|
||||||
|
|
||||||
wxDataViewModel *g_model = NULL;
|
class wxDataViewCtrlInternal;
|
||||||
|
|
||||||
|
wxDataViewCtrlInternal *g_internal = NULL;
|
||||||
|
|
||||||
class wxGtkTreeModelNode;
|
class wxGtkTreeModelNode;
|
||||||
|
|
||||||
@@ -85,6 +87,9 @@ public:
|
|||||||
bool Cleared();
|
bool Cleared();
|
||||||
void Resort();
|
void Resort();
|
||||||
|
|
||||||
|
void SetSortOrder( GtkSortType sort_order ) { m_sort_order = sort_order; }
|
||||||
|
GtkSortType GetSortOrder() { return m_sort_order; }
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
void InitTree();
|
void InitTree();
|
||||||
wxGtkTreeModelNode *FindNode( const wxDataViewItem &item );
|
wxGtkTreeModelNode *FindNode( const wxDataViewItem &item );
|
||||||
@@ -98,6 +103,7 @@ private:
|
|||||||
wxDataViewModel *m_wx_model;
|
wxDataViewModel *m_wx_model;
|
||||||
GtkWxTreeModel *m_gtk_model;
|
GtkWxTreeModel *m_gtk_model;
|
||||||
wxDataViewCtrl *m_owner;
|
wxDataViewCtrl *m_owner;
|
||||||
|
GtkSortType m_sort_order;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
@@ -119,13 +125,13 @@ public:
|
|||||||
m_parent = parent;
|
m_parent = parent;
|
||||||
m_item = item;
|
m_item = item;
|
||||||
m_internal = internal;
|
m_internal = internal;
|
||||||
g_model = internal->GetDataViewModel();
|
g_internal = internal;
|
||||||
m_children = new wxGtkTreeModelChildren( wxGtkTreeModelNodeCmp );
|
m_children = new wxGtkTreeModelChildren( wxGtkTreeModelNodeCmp );
|
||||||
}
|
}
|
||||||
|
|
||||||
~wxGtkTreeModelNode()
|
~wxGtkTreeModelNode()
|
||||||
{
|
{
|
||||||
g_model = m_internal->GetDataViewModel();
|
g_internal = m_internal;
|
||||||
size_t count = m_children->GetCount();
|
size_t count = m_children->GetCount();
|
||||||
size_t i;
|
size_t i;
|
||||||
for (i = 0; i < count; i++)
|
for (i = 0; i < count; i++)
|
||||||
@@ -138,20 +144,20 @@ public:
|
|||||||
|
|
||||||
unsigned int AddNode( wxGtkTreeModelNode* child )
|
unsigned int AddNode( wxGtkTreeModelNode* child )
|
||||||
{
|
{
|
||||||
g_model = m_internal->GetDataViewModel();
|
g_internal = m_internal;
|
||||||
m_nodes.Add( child );
|
m_nodes.Add( child );
|
||||||
return m_children->Add( child->GetItem().GetID() );
|
return m_children->Add( child->GetItem().GetID() );
|
||||||
}
|
}
|
||||||
|
|
||||||
unsigned int AddLeave( void* id )
|
unsigned int AddLeave( void* id )
|
||||||
{
|
{
|
||||||
g_model = m_internal->GetDataViewModel();
|
g_internal = m_internal;
|
||||||
return m_children->Add( id );
|
return m_children->Add( id );
|
||||||
}
|
}
|
||||||
|
|
||||||
void DeleteChild( void* id )
|
void DeleteChild( void* id )
|
||||||
{
|
{
|
||||||
g_model = m_internal->GetDataViewModel();
|
g_internal = m_internal;
|
||||||
size_t pos;
|
size_t pos;
|
||||||
size_t count = m_children->GetCount();
|
size_t count = m_children->GetCount();
|
||||||
for (pos = 0; pos < count; pos++)
|
for (pos = 0; pos < count; pos++)
|
||||||
@@ -202,7 +208,10 @@ private:
|
|||||||
|
|
||||||
int LINKAGEMODE wxGtkTreeModelNodeCmp( void* id1, void* id2 )
|
int LINKAGEMODE wxGtkTreeModelNodeCmp( void* id1, void* id2 )
|
||||||
{
|
{
|
||||||
return g_model->Compare( id1, id2 );
|
int ret = g_internal->GetDataViewModel()->Compare( id1, id2 );
|
||||||
|
if (g_internal->GetSortOrder() == GTK_SORT_DESCENDING)
|
||||||
|
return -ret;
|
||||||
|
return ret;
|
||||||
}
|
}
|
||||||
|
|
||||||
//-----------------------------------------------------------------------------
|
//-----------------------------------------------------------------------------
|
||||||
@@ -593,35 +602,25 @@ gboolean wxgtk_tree_model_get_sort_column_id (GtkTreeSortable *sortabl
|
|||||||
*sort_column_id = tree_model->internal->GetDataViewModel()->GetSortingColumn();
|
*sort_column_id = tree_model->internal->GetDataViewModel()->GetSortingColumn();
|
||||||
|
|
||||||
if (order)
|
if (order)
|
||||||
{
|
*order = tree_model->internal->GetSortOrder();
|
||||||
bool ascending = tree_model->internal->GetDataViewModel()->GetSortOrderAscending();
|
|
||||||
if (ascending)
|
|
||||||
*order = GTK_SORT_ASCENDING;
|
|
||||||
else
|
|
||||||
*order = GTK_SORT_DESCENDING;
|
|
||||||
}
|
|
||||||
|
|
||||||
return TRUE;
|
return TRUE;
|
||||||
}
|
}
|
||||||
|
|
||||||
void wxgtk_tree_model_set_sort_column_id (GtkTreeSortable *sortable,
|
void wxgtk_tree_model_set_sort_column_id (GtkTreeSortable *sortable,
|
||||||
gint sort_column_id,
|
gint sort_column_id,
|
||||||
GtkSortType order)
|
GtkSortType order)
|
||||||
{
|
{
|
||||||
GtkWxTreeModel *tree_model = (GtkWxTreeModel *) sortable;
|
GtkWxTreeModel *tree_model = (GtkWxTreeModel *) sortable;
|
||||||
g_return_if_fail (GTK_IS_WX_TREE_MODEL (sortable) );
|
g_return_if_fail (GTK_IS_WX_TREE_MODEL (sortable) );
|
||||||
|
|
||||||
bool ascending = TRUE;
|
|
||||||
if (order != GTK_SORT_ASCENDING)
|
|
||||||
ascending = FALSE;
|
|
||||||
|
|
||||||
if ((sort_column_id == (gint) tree_model->internal->GetDataViewModel()->GetSortingColumn()) &&
|
if ((sort_column_id == (gint) tree_model->internal->GetDataViewModel()->GetSortingColumn()) &&
|
||||||
(ascending == tree_model->internal->GetDataViewModel()->GetSortOrderAscending()))
|
(order == tree_model->internal->GetSortOrder()))
|
||||||
return;
|
return;
|
||||||
|
|
||||||
tree_model->internal->GetDataViewModel()->SetSortingColumn( sort_column_id );
|
tree_model->internal->GetDataViewModel()->SetSortingColumn( sort_column_id );
|
||||||
|
|
||||||
tree_model->internal->GetDataViewModel()->SetSortOrderAscending( ascending );
|
tree_model->internal->SetSortOrder( order );
|
||||||
|
|
||||||
gtk_tree_sortable_sort_column_changed (sortable);
|
gtk_tree_sortable_sort_column_changed (sortable);
|
||||||
|
|
||||||
@@ -2152,7 +2151,7 @@ void wxDataViewColumn::SetWidth( int width )
|
|||||||
|
|
||||||
void wxGtkTreeModelNode::Resort()
|
void wxGtkTreeModelNode::Resort()
|
||||||
{
|
{
|
||||||
g_model = m_internal->GetDataViewModel();
|
g_internal = m_internal;
|
||||||
|
|
||||||
size_t child_count = GetChildCount();
|
size_t child_count = GetChildCount();
|
||||||
if (child_count == 0)
|
if (child_count == 0)
|
||||||
@@ -2239,6 +2238,7 @@ wxDataViewCtrlInternal::wxDataViewCtrlInternal( wxDataViewCtrl *owner,
|
|||||||
m_wx_model = wx_model;
|
m_wx_model = wx_model;
|
||||||
m_gtk_model = gtk_model;
|
m_gtk_model = gtk_model;
|
||||||
m_root = NULL;
|
m_root = NULL;
|
||||||
|
m_sort_order = GTK_SORT_ASCENDING;
|
||||||
InitTree();
|
InitTree();
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -2345,7 +2345,7 @@ bool wxDataViewCtrlInternal::Cleared()
|
|||||||
|
|
||||||
gboolean wxDataViewCtrlInternal::get_iter( GtkTreeIter *iter, GtkTreePath *path )
|
gboolean wxDataViewCtrlInternal::get_iter( GtkTreeIter *iter, GtkTreePath *path )
|
||||||
{
|
{
|
||||||
g_model = m_wx_model;
|
g_internal = this;
|
||||||
|
|
||||||
int depth = gtk_tree_path_get_depth( path );
|
int depth = gtk_tree_path_get_depth( path );
|
||||||
|
|
||||||
@@ -2387,7 +2387,7 @@ gboolean wxDataViewCtrlInternal::get_iter( GtkTreeIter *iter, GtkTreePath *path
|
|||||||
|
|
||||||
GtkTreePath *wxDataViewCtrlInternal::get_path( GtkTreeIter *iter )
|
GtkTreePath *wxDataViewCtrlInternal::get_path( GtkTreeIter *iter )
|
||||||
{
|
{
|
||||||
g_model = m_wx_model;
|
g_internal = this;
|
||||||
|
|
||||||
GtkTreePath *retval = gtk_tree_path_new ();
|
GtkTreePath *retval = gtk_tree_path_new ();
|
||||||
void *id = iter->user_data;
|
void *id = iter->user_data;
|
||||||
@@ -2407,7 +2407,7 @@ GtkTreePath *wxDataViewCtrlInternal::get_path( GtkTreeIter *iter )
|
|||||||
|
|
||||||
GtkTreePath *wxDataViewCtrlInternal::get_path_safe( GtkTreeIter *iter )
|
GtkTreePath *wxDataViewCtrlInternal::get_path_safe( GtkTreeIter *iter )
|
||||||
{
|
{
|
||||||
g_model = m_wx_model;
|
g_internal = this;
|
||||||
|
|
||||||
GtkTreePath *retval = gtk_tree_path_new ();
|
GtkTreePath *retval = gtk_tree_path_new ();
|
||||||
void *id = iter->user_data;
|
void *id = iter->user_data;
|
||||||
@@ -2434,7 +2434,7 @@ GtkTreePath *wxDataViewCtrlInternal::get_path_safe( GtkTreeIter *iter )
|
|||||||
|
|
||||||
gboolean wxDataViewCtrlInternal::iter_next( GtkTreeIter *iter )
|
gboolean wxDataViewCtrlInternal::iter_next( GtkTreeIter *iter )
|
||||||
{
|
{
|
||||||
g_model = m_wx_model;
|
g_internal = this;
|
||||||
|
|
||||||
wxGtkTreeModelNode *parent = FindParentNode( iter );
|
wxGtkTreeModelNode *parent = FindParentNode( iter );
|
||||||
if( parent == NULL )
|
if( parent == NULL )
|
||||||
@@ -2453,7 +2453,7 @@ gboolean wxDataViewCtrlInternal::iter_next( GtkTreeIter *iter )
|
|||||||
|
|
||||||
gboolean wxDataViewCtrlInternal::iter_children( GtkTreeIter *iter, GtkTreeIter *parent )
|
gboolean wxDataViewCtrlInternal::iter_children( GtkTreeIter *iter, GtkTreeIter *parent )
|
||||||
{
|
{
|
||||||
g_model = m_wx_model;
|
g_internal = this;
|
||||||
|
|
||||||
wxDataViewItem item( (void*) parent->user_data );
|
wxDataViewItem item( (void*) parent->user_data );
|
||||||
|
|
||||||
@@ -2474,7 +2474,7 @@ gboolean wxDataViewCtrlInternal::iter_children( GtkTreeIter *iter, GtkTreeIter *
|
|||||||
|
|
||||||
gboolean wxDataViewCtrlInternal::iter_has_child( GtkTreeIter *iter )
|
gboolean wxDataViewCtrlInternal::iter_has_child( GtkTreeIter *iter )
|
||||||
{
|
{
|
||||||
g_model = m_wx_model;
|
g_internal = this;
|
||||||
|
|
||||||
wxDataViewItem item( (void*) iter->user_data );
|
wxDataViewItem item( (void*) iter->user_data );
|
||||||
bool is_container = m_wx_model->IsContainer( item );
|
bool is_container = m_wx_model->IsContainer( item );
|
||||||
@@ -2490,7 +2490,7 @@ gboolean wxDataViewCtrlInternal::iter_has_child( GtkTreeIter *iter )
|
|||||||
|
|
||||||
gint wxDataViewCtrlInternal::iter_n_children( GtkTreeIter *iter )
|
gint wxDataViewCtrlInternal::iter_n_children( GtkTreeIter *iter )
|
||||||
{
|
{
|
||||||
g_model = m_wx_model;
|
g_internal = this;
|
||||||
|
|
||||||
wxDataViewItem item( (void*) iter->user_data );
|
wxDataViewItem item( (void*) iter->user_data );
|
||||||
|
|
||||||
@@ -2507,7 +2507,7 @@ gint wxDataViewCtrlInternal::iter_n_children( GtkTreeIter *iter )
|
|||||||
|
|
||||||
gboolean wxDataViewCtrlInternal::iter_nth_child( GtkTreeIter *iter, GtkTreeIter *parent, gint n )
|
gboolean wxDataViewCtrlInternal::iter_nth_child( GtkTreeIter *iter, GtkTreeIter *parent, gint n )
|
||||||
{
|
{
|
||||||
g_model = m_wx_model;
|
g_internal = this;
|
||||||
|
|
||||||
void* id = NULL;
|
void* id = NULL;
|
||||||
if (parent) id = (void*) parent->user_data;
|
if (parent) id = (void*) parent->user_data;
|
||||||
@@ -2529,7 +2529,7 @@ gboolean wxDataViewCtrlInternal::iter_nth_child( GtkTreeIter *iter, GtkTreeIter
|
|||||||
|
|
||||||
gboolean wxDataViewCtrlInternal::iter_parent( GtkTreeIter *iter, GtkTreeIter *child )
|
gboolean wxDataViewCtrlInternal::iter_parent( GtkTreeIter *iter, GtkTreeIter *child )
|
||||||
{
|
{
|
||||||
g_model = m_wx_model;
|
g_internal = this;
|
||||||
|
|
||||||
wxGtkTreeModelNode *node = FindParentNode( child );
|
wxGtkTreeModelNode *node = FindParentNode( child );
|
||||||
if (!node)
|
if (!node)
|
||||||
|
Reference in New Issue
Block a user