Implement selection API and events
git-svn-id: https://svn.wxwidgets.org/svn/wx/wxWidgets/trunk@48209 c3d73ce0-8a6f-49c7-b76d-6d57e0e08775
This commit is contained in:
@@ -429,6 +429,7 @@ public:
|
||||
void OnExpanded( wxDataViewEvent &event );
|
||||
void OnCollapsing( wxDataViewEvent &event );
|
||||
void OnCollapsed( wxDataViewEvent &event );
|
||||
void OnSelected( wxDataViewEvent &event );
|
||||
|
||||
void OnHeaderClick( wxDataViewEvent &event );
|
||||
void OnHeaderRightClick( wxDataViewEvent &event );
|
||||
@@ -464,7 +465,7 @@ bool MyApp::OnInit(void)
|
||||
|
||||
// build the first frame
|
||||
MyFrame *frame =
|
||||
new MyFrame(NULL, wxT("wxDataViewCtrl feature test"), 10, 10, 700, 440);
|
||||
new MyFrame(NULL, wxT("wxDataViewCtrl feature test"), 40, 40, 700, 440);
|
||||
frame->Show(true);
|
||||
|
||||
SetTopWindow(frame);
|
||||
@@ -516,6 +517,7 @@ BEGIN_EVENT_TABLE(MyFrame, wxFrame)
|
||||
EVT_DATAVIEW_ITEM_EXPANDED(ID_MUSIC_CTRL, MyFrame::OnExpanded)
|
||||
EVT_DATAVIEW_ITEM_COLLAPSING(ID_MUSIC_CTRL, MyFrame::OnCollapsing)
|
||||
EVT_DATAVIEW_ITEM_COLLAPSED(ID_MUSIC_CTRL, MyFrame::OnCollapsed)
|
||||
EVT_DATAVIEW_ITEM_SELECTED(ID_MUSIC_CTRL, MyFrame::OnSelected)
|
||||
|
||||
EVT_DATAVIEW_COLUMN_HEADER_CLICK(ID_MUSIC_CTRL, MyFrame::OnHeaderClick)
|
||||
EVT_DATAVIEW_COLUMN_HEADER_RIGHT_CLICKED(ID_MUSIC_CTRL, MyFrame::OnHeaderRightClick)
|
||||
@@ -669,6 +671,14 @@ void MyFrame::OnActivated( wxDataViewEvent &event )
|
||||
wxLogMessage("wxEVT_COMMAND_DATAVIEW_ITEM_ACTIVATED, Item Id: %d; Column: %d", event.GetItem().GetID(), event.GetColumn());
|
||||
}
|
||||
|
||||
void MyFrame::OnSelected( wxDataViewEvent &event )
|
||||
{
|
||||
if(!m_log)
|
||||
return;
|
||||
|
||||
wxLogMessage("wxEVT_COMMAND_DATAVIEW_ITEM_SELECTED, Item Id: %d", event.GetItem().GetID() );
|
||||
}
|
||||
|
||||
void MyFrame::OnExpanding( wxDataViewEvent &event )
|
||||
{
|
||||
if (!m_log)
|
||||
|
@@ -632,7 +632,7 @@ void wxgtk_tree_model_set_sort_column_id (GtkTreeSortable *sortable,
|
||||
|
||||
wxDataViewCtrl *dv = tree_model->internal->GetOwner();
|
||||
wxDataViewEvent event( wxEVT_COMMAND_DATAVIEW_COLUMN_SORTED, dv->GetId() );
|
||||
// event.SetDataViewColumn( column );
|
||||
// TODO event.SetDataViewColumn( column );
|
||||
event.SetModel( dv->GetModel() );
|
||||
dv->GetEventHandler()->ProcessEvent( event );
|
||||
}
|
||||
@@ -2720,7 +2720,7 @@ wxdataview_selection_changed_callback( GtkTreeSelection* selection, wxDataViewCt
|
||||
return;
|
||||
|
||||
wxDataViewEvent event( wxEVT_COMMAND_DATAVIEW_ITEM_SELECTED, dv->GetId() );
|
||||
// TODO: item
|
||||
event.SetItem( dv->GetSelection() );
|
||||
event.SetModel( dv->GetModel() );
|
||||
dv->GetEventHandler()->ProcessEvent( event );
|
||||
}
|
||||
@@ -2995,6 +2995,22 @@ wxDataViewItem wxDataViewCtrl::GetSelection()
|
||||
|
||||
if (m_windowStyle & wxDV_MULTIPLE)
|
||||
{
|
||||
// Report the first one
|
||||
GtkTreeModel *model;
|
||||
GList *list = gtk_tree_selection_get_selected_rows( selection, &model );
|
||||
|
||||
if (list)
|
||||
{
|
||||
GtkTreePath *path = (GtkTreePath*) list->data;
|
||||
GtkTreeIter iter;
|
||||
m_internal->get_iter( &iter, path );
|
||||
|
||||
// delete list
|
||||
g_list_foreach( list, (GFunc) gtk_tree_path_free, NULL );
|
||||
g_list_free( list );
|
||||
|
||||
return wxDataViewItem( (void*) iter.user_data );
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
@@ -3011,32 +3027,124 @@ wxDataViewItem wxDataViewCtrl::GetSelection()
|
||||
|
||||
int wxDataViewCtrl::GetSelections( wxDataViewItemArray & sel ) const
|
||||
{
|
||||
sel.Clear();
|
||||
|
||||
GtkTreeSelection *selection = gtk_tree_view_get_selection( GTK_TREE_VIEW(m_treeview) );
|
||||
if (HasFlag(wxDV_MULTIPLE))
|
||||
{
|
||||
GtkTreeModel *model;
|
||||
GList *list = gtk_tree_selection_get_selected_rows( selection, &model );
|
||||
|
||||
int count = 0;
|
||||
while (list)
|
||||
{
|
||||
GtkTreePath *path = (GtkTreePath*) list->data;
|
||||
|
||||
GtkTreeIter iter;
|
||||
m_internal->get_iter( &iter, path );
|
||||
|
||||
sel.Add( wxDataViewItem( (void*) iter.user_data ) );
|
||||
|
||||
list = g_list_next( list );
|
||||
count++;
|
||||
}
|
||||
|
||||
// delete list
|
||||
g_list_foreach( list, (GFunc) gtk_tree_path_free, NULL );
|
||||
g_list_free( list );
|
||||
|
||||
return count;
|
||||
}
|
||||
else
|
||||
{
|
||||
GtkTreeModel *model;
|
||||
GtkTreeIter iter;
|
||||
gboolean has_selection = gtk_tree_selection_get_selected( selection, &model, &iter );
|
||||
if (has_selection)
|
||||
{
|
||||
sel.Add( wxDataViewItem( (void*) iter.user_data) );
|
||||
return 1;
|
||||
}
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
void wxDataViewCtrl::SetSelections( const wxDataViewItemArray & sel )
|
||||
{
|
||||
GtkDisableSelectionEvents();
|
||||
|
||||
GtkTreeSelection *selection = gtk_tree_view_get_selection( GTK_TREE_VIEW(m_treeview) );
|
||||
|
||||
gtk_tree_selection_unselect_all( selection );
|
||||
|
||||
size_t i;
|
||||
for (i = 0; i < sel.GetCount(); i++)
|
||||
{
|
||||
GtkTreeIter iter;
|
||||
iter.user_data = (gpointer) sel[i].GetID();
|
||||
gtk_tree_selection_select_iter( selection, &iter );
|
||||
}
|
||||
|
||||
GtkEnableSelectionEvents();
|
||||
}
|
||||
|
||||
void wxDataViewCtrl::Select( const wxDataViewItem & item )
|
||||
{
|
||||
GtkDisableSelectionEvents();
|
||||
|
||||
GtkTreeSelection *selection = gtk_tree_view_get_selection( GTK_TREE_VIEW(m_treeview) );
|
||||
|
||||
GtkTreeIter iter;
|
||||
iter.user_data = (gpointer) item.GetID();
|
||||
gtk_tree_selection_select_iter( selection, &iter );
|
||||
|
||||
GtkEnableSelectionEvents();
|
||||
}
|
||||
|
||||
void wxDataViewCtrl::Unselect( const wxDataViewItem & item )
|
||||
{
|
||||
GtkDisableSelectionEvents();
|
||||
|
||||
GtkTreeSelection *selection = gtk_tree_view_get_selection( GTK_TREE_VIEW(m_treeview) );
|
||||
|
||||
GtkTreeIter iter;
|
||||
iter.user_data = (gpointer) item.GetID();
|
||||
gtk_tree_selection_unselect_iter( selection, &iter );
|
||||
|
||||
GtkEnableSelectionEvents();
|
||||
}
|
||||
|
||||
bool wxDataViewCtrl::IsSelected( const wxDataViewItem & item ) const
|
||||
{
|
||||
return false;
|
||||
GtkTreeSelection *selection = gtk_tree_view_get_selection( GTK_TREE_VIEW(m_treeview) );
|
||||
|
||||
GtkTreeIter iter;
|
||||
iter.user_data = (gpointer) item.GetID();
|
||||
|
||||
return gtk_tree_selection_iter_is_selected( selection, &iter );
|
||||
}
|
||||
|
||||
void wxDataViewCtrl::SelectAll()
|
||||
{
|
||||
GtkDisableSelectionEvents();
|
||||
|
||||
GtkTreeSelection *selection = gtk_tree_view_get_selection( GTK_TREE_VIEW(m_treeview) );
|
||||
|
||||
gtk_tree_selection_select_all( selection );
|
||||
|
||||
GtkEnableSelectionEvents();
|
||||
}
|
||||
|
||||
void wxDataViewCtrl::UnselectAll()
|
||||
{
|
||||
GtkDisableSelectionEvents();
|
||||
|
||||
GtkTreeSelection *selection = gtk_tree_view_get_selection( GTK_TREE_VIEW(m_treeview) );
|
||||
|
||||
gtk_tree_selection_unselect_all( selection );
|
||||
|
||||
GtkEnableSelectionEvents();
|
||||
}
|
||||
|
||||
void wxDataViewCtrl::EnsureVisible( const wxDataViewItem & item, wxDataViewColumn *column )
|
||||
@@ -3059,15 +3167,15 @@ void wxDataViewCtrl::DoSetIndent()
|
||||
void wxDataViewCtrl::GtkDisableSelectionEvents()
|
||||
{
|
||||
GtkTreeSelection *selection = gtk_tree_view_get_selection( GTK_TREE_VIEW(m_treeview) );
|
||||
g_signal_connect_after (selection, "changed",
|
||||
G_CALLBACK (wxdataview_selection_changed_callback), this);
|
||||
g_signal_handlers_disconnect_by_func( selection,
|
||||
(gpointer) (wxdataview_selection_changed_callback), this);
|
||||
}
|
||||
|
||||
void wxDataViewCtrl::GtkEnableSelectionEvents()
|
||||
{
|
||||
GtkTreeSelection *selection = gtk_tree_view_get_selection( GTK_TREE_VIEW(m_treeview) );
|
||||
g_signal_handlers_disconnect_by_func( selection,
|
||||
(gpointer) (wxdataview_selection_changed_callback), this);
|
||||
g_signal_connect_after (selection, "changed",
|
||||
G_CALLBACK (wxdataview_selection_changed_callback), this);
|
||||
}
|
||||
|
||||
// static
|
||||
|
Reference in New Issue
Block a user