Implement wxDataViewCtrl::GetSortingColumn() and related code for GTK+

git-svn-id: https://svn.wxwidgets.org/svn/wx/wxWidgets/trunk@48692 c3d73ce0-8a6f-49c7-b76d-6d57e0e08775
This commit is contained in:
Robert Roebling 2007-09-14 21:02:18 +00:00
parent 7c77f33480
commit d32332aaf6
2 changed files with 63 additions and 24 deletions

View File

@ -197,6 +197,17 @@ public:
m_classicalMusicIsKnownToControl = false;
}
// helper method for wxLog
wxString GetTitle( const wxDataViewItem &item )
{
MyMusicModelNode *node = (MyMusicModelNode*) item.GetID();
if (!node)
return wxEmptyString;
return node->m_title;
}
// helper methods to change the model
void AddToClassical( const wxString &title, const wxString &artist, int year )
@ -754,7 +765,8 @@ void MyFrame::OnActivated( wxDataViewEvent &event )
if(!m_log)
return;
wxLogMessage("wxEVT_COMMAND_DATAVIEW_ITEM_ACTIVATED, Item Id: %d", event.GetItem().GetID() );
wxString title = m_music_model->GetTitle( event.GetItem() );
wxLogMessage("wxEVT_COMMAND_DATAVIEW_ITEM_ACTIVATED, Item: %s", title );
}
void MyFrame::OnSelectionChanged( wxDataViewEvent &event )
@ -762,7 +774,11 @@ void MyFrame::OnSelectionChanged( wxDataViewEvent &event )
if(!m_log)
return;
wxLogMessage("wxEVT_COMMAND_DATAVIEW_SELECTION_CHANGED, First selected Item: %d", event.GetItem().GetID() );
wxString title = m_music_model->GetTitle( event.GetItem() );
if (title.empty())
title = "None";
wxLogMessage("wxEVT_COMMAND_DATAVIEW_SELECTION_CHANGED, First selected Item: %s", title );
}
void MyFrame::OnExpanding( wxDataViewEvent &event )
@ -770,7 +786,8 @@ void MyFrame::OnExpanding( wxDataViewEvent &event )
if (!m_log)
return;
wxLogMessage("wxEVT_COMMAND_DATAVIEW_ITEM_EXPANDING, Item Id: %d", event.GetItem().GetID() );
wxString title = m_music_model->GetTitle( event.GetItem() );
wxLogMessage("wxEVT_COMMAND_DATAVIEW_ITEM_EXPANDING, Item: %s", title );
}
@ -779,7 +796,8 @@ void MyFrame::OnEditingStarted( wxDataViewEvent &event )
if (!m_log)
return;
wxLogMessage("wxEVT_COMMAND_DATAVIEW_ITEM_EDITING_STARTED, Item Id: %d", event.GetItem().GetID() );
wxString title = m_music_model->GetTitle( event.GetItem() );
wxLogMessage("wxEVT_COMMAND_DATAVIEW_ITEM_EDITING_STARTED, Item: %s", title );
}
void MyFrame::OnEditingDone( wxDataViewEvent &event )
@ -787,7 +805,8 @@ void MyFrame::OnEditingDone( wxDataViewEvent &event )
if (!m_log)
return;
wxLogMessage("wxEVT_COMMAND_DATAVIEW_ITEM_EDITING_DONE, Item Id: %d", event.GetItem().GetID() );
wxString title = m_music_model->GetTitle( event.GetItem() );
wxLogMessage("wxEVT_COMMAND_DATAVIEW_ITEM_EDITING_DONE, Item: %s", title );
}
void MyFrame::OnExpanded( wxDataViewEvent &event )
@ -795,7 +814,8 @@ void MyFrame::OnExpanded( wxDataViewEvent &event )
if (!m_log)
return;
wxLogMessage("wxEVT_COMMAND_DATAVIEW_ITEM_EXPANDED, Item Id: %d", event.GetItem().GetID() );
wxString title = m_music_model->GetTitle( event.GetItem() );
wxLogMessage("wxEVT_COMMAND_DATAVIEW_ITEM_EXPANDED, Item: %s", title );
}
void MyFrame::OnCollapsing( wxDataViewEvent &event )
@ -803,15 +823,17 @@ void MyFrame::OnCollapsing( wxDataViewEvent &event )
if (!m_log)
return;
wxLogMessage("wxEVT_COMMAND_DATAVIEW_ITEM_COLLAPSING, Item Id: %d", event.GetItem().GetID() );
wxString title = m_music_model->GetTitle( event.GetItem() );
wxLogMessage("wxEVT_COMMAND_DATAVIEW_ITEM_COLLAPSING, Item: %s", title );
}
void MyFrame::OnCollapsed( wxDataViewEvent &event )
{
if (!m_log)
return;
wxLogMessage("wxEVT_COMMAND_DATAVIEW_ITEM_COLLAPSED, Item Id: %d", event.GetItem().GetID() );
wxString title = m_music_model->GetTitle( event.GetItem() );
wxLogMessage("wxEVT_COMMAND_DATAVIEW_ITEM_COLLAPSED, Item: %s", title );
}
void MyFrame::OnHeaderClick( wxDataViewEvent &event )
@ -839,7 +861,9 @@ void MyFrame::OnSorted( wxDataViewEvent &event )
if(!m_log)
return;
wxLogMessage("wxEVT_COMMAND_DATAVIEW_COLUMN_SORTED, Column: %d", event.GetColumn());
int pos = m_musicCtrl->GetColumnPosition( event.GetDataViewColumn() );
wxLogMessage("wxEVT_COMMAND_DATAVIEW_COLUMN_SORTED, Column position: %d", pos );
}
void MyFrame::OnRightClick( wxMouseEvent &event )

View File

@ -92,6 +92,9 @@ public:
void SetSortColumn( int column ) { m_sort_column = column; }
int GetSortColumn() { return m_sort_column; }
void SetDataViewSortColumn( wxDataViewColumn *column ) { m_dataview_sort_column = column; }
wxDataViewColumn *GetDataViewSortColumn() { return m_dataview_sort_column; }
bool IsSorted() { return (m_sort_column >= 0); }
@ -109,6 +112,7 @@ private:
GtkWxTreeModel *m_gtk_model;
wxDataViewCtrl *m_owner;
GtkSortType m_sort_order;
wxDataViewColumn *m_dataview_sort_column;
int m_sort_column;
};
@ -614,6 +618,8 @@ gboolean wxgtk_tree_model_get_sort_column_id (GtkTreeSortable *sortabl
return TRUE;
}
wxDataViewColumn *gs_lastLeftClickHeader = NULL;
void wxgtk_tree_model_set_sort_column_id (GtkTreeSortable *sortable,
gint sort_column_id,
GtkSortType order)
@ -621,23 +627,29 @@ void wxgtk_tree_model_set_sort_column_id (GtkTreeSortable *sortable,
GtkWxTreeModel *tree_model = (GtkWxTreeModel *) sortable;
g_return_if_fail (GTK_IS_WX_TREE_MODEL (sortable) );
if ((sort_column_id == (gint) tree_model->internal->GetSortColumn()) &&
(order == tree_model->internal->GetSortOrder()))
return;
tree_model->internal->SetDataViewSortColumn( gs_lastLeftClickHeader );
tree_model->internal->SetSortColumn( sort_column_id );
if ((sort_column_id != (gint) tree_model->internal->GetSortColumn()) ||
(order != tree_model->internal->GetSortOrder()))
{
tree_model->internal->SetSortColumn( sort_column_id );
tree_model->internal->SetSortOrder( order );
tree_model->internal->SetSortOrder( order );
gtk_tree_sortable_sort_column_changed (sortable);
gtk_tree_sortable_sort_column_changed (sortable);
tree_model->internal->GetDataViewModel()->Resort();
tree_model->internal->GetDataViewModel()->Resort();
}
wxDataViewCtrl *dv = tree_model->internal->GetOwner();
wxDataViewEvent event( wxEVT_COMMAND_DATAVIEW_COLUMN_SORTED, dv->GetId() );
// TODO event.SetDataViewColumn( column );
event.SetModel( dv->GetModel() );
dv->GetEventHandler()->ProcessEvent( event );
if (gs_lastLeftClickHeader)
{
wxDataViewCtrl *dv = tree_model->internal->GetOwner();
wxDataViewEvent event( wxEVT_COMMAND_DATAVIEW_COLUMN_SORTED, dv->GetId() );
event.SetDataViewColumn( gs_lastLeftClickHeader );
event.SetModel( dv->GetModel() );
dv->GetEventHandler()->ProcessEvent( event );
}
gs_lastLeftClickHeader = NULL;
}
void wxgtk_tree_model_set_sort_func (GtkTreeSortable *sortable,
@ -1967,6 +1979,8 @@ gtk_dataview_header_button_press_callback( GtkWidget *widget,
if (gdk_event->button == 1)
{
gs_lastLeftClickHeader = column;
wxDataViewCtrl *dv = column->GetOwner();
wxDataViewEvent event( wxEVT_COMMAND_DATAVIEW_COLUMN_HEADER_CLICK, dv->GetId() );
event.SetDataViewColumn( column );
@ -2371,6 +2385,7 @@ wxDataViewCtrlInternal::wxDataViewCtrlInternal( wxDataViewCtrl *owner,
m_root = NULL;
m_sort_order = GTK_SORT_ASCENDING;
m_sort_column = -1;
m_dataview_sort_column = NULL;
InitTree();
}
@ -3137,7 +3152,7 @@ int wxDataViewCtrl::GetColumnPosition( const wxDataViewColumn *column ) const
wxDataViewColumn *wxDataViewCtrl::GetSortingColumn() const
{
return NULL;
return m_internal->GetDataViewSortColumn();
}
void wxDataViewCtrl::Expand( const wxDataViewItem & item )