Implemented (for GTK+) and tested dataview_context_menu event

git-svn-id: https://svn.wxwidgets.org/svn/wx/wxWidgets/trunk@50746 c3d73ce0-8a6f-49c7-b76d-6d57e0e08775
This commit is contained in:
Robert Roebling
2007-12-16 15:16:52 +00:00
parent 6af3eec222
commit 74dea0decf
2 changed files with 59 additions and 2 deletions

View File

@@ -518,6 +518,8 @@ public:
void OnHeaderRightClick( wxDataViewEvent &event ); void OnHeaderRightClick( wxDataViewEvent &event );
void OnSorted( wxDataViewEvent &event ); void OnSorted( wxDataViewEvent &event );
void OnContextMenu( wxDataViewEvent &event );
void OnRightClick( wxMouseEvent &event ); void OnRightClick( wxMouseEvent &event );
void OnGoto( wxCommandEvent &event); void OnGoto( wxCommandEvent &event);
@@ -609,6 +611,8 @@ BEGIN_EVENT_TABLE(MyFrame, wxFrame)
EVT_DATAVIEW_COLUMN_HEADER_CLICK(ID_MUSIC_CTRL, MyFrame::OnHeaderClick) EVT_DATAVIEW_COLUMN_HEADER_CLICK(ID_MUSIC_CTRL, MyFrame::OnHeaderClick)
EVT_DATAVIEW_COLUMN_HEADER_RIGHT_CLICKED(ID_MUSIC_CTRL, MyFrame::OnHeaderRightClick) EVT_DATAVIEW_COLUMN_HEADER_RIGHT_CLICKED(ID_MUSIC_CTRL, MyFrame::OnHeaderRightClick)
EVT_DATAVIEW_COLUMN_SORTED(ID_MUSIC_CTRL, MyFrame::OnSorted) EVT_DATAVIEW_COLUMN_SORTED(ID_MUSIC_CTRL, MyFrame::OnSorted)
EVT_DATAVIEW_ITEM_CONTEXT_MENU(ID_MUSIC_CTRL, MyFrame::OnContextMenu)
EVT_RIGHT_UP(MyFrame::OnRightClick) EVT_RIGHT_UP(MyFrame::OnRightClick)
END_EVENT_TABLE() END_EVENT_TABLE()
@@ -868,6 +872,15 @@ void MyFrame::OnCollapsed( wxDataViewEvent &event )
wxLogMessage("wxEVT_COMMAND_DATAVIEW_ITEM_COLLAPSED, Item: %s", title ); wxLogMessage("wxEVT_COMMAND_DATAVIEW_ITEM_COLLAPSED, Item: %s", title );
} }
void MyFrame::OnContextMenu( wxDataViewEvent &event )
{
if (!m_log)
return;
wxString title = m_music_model->GetTitle( event.GetItem() );
wxLogMessage("wxEVT_COMMAND_DATAVIEW_ITEM_CONTEXT_MENU, Item: %s", title );
}
void MyFrame::OnHeaderClick( wxDataViewEvent &event ) void MyFrame::OnHeaderClick( wxDataViewEvent &event )
{ {
if(!m_log) if(!m_log)

View File

@@ -3233,8 +3233,8 @@ void gtk_dataviewctrl_size_callback( GtkWidget *WXUNUSED(widget),
static gboolean static gboolean
gtk_dataview_motion_notify_callback( GtkWidget *widget, gtk_dataview_motion_notify_callback( GtkWidget *widget,
GdkEventMotion *gdk_event, GdkEventMotion *gdk_event,
wxDataViewCtrl *dv ) wxDataViewCtrl *dv )
{ {
if (gdk_event->is_hint) if (gdk_event->is_hint)
{ {
@@ -3273,6 +3273,47 @@ gtk_dataview_motion_notify_callback( GtkWidget *widget,
return FALSE; return FALSE;
} }
//-----------------------------------------------------------------------------
// "button_press_event"
//-----------------------------------------------------------------------------
static gboolean
gtk_dataview_button_press_callback( GtkWidget *WXUNUSED(widget),
GdkEventButton *gdk_event,
wxDataViewCtrl *dv )
{
if ((gdk_event->button == 3) && (gdk_event->type == GDK_BUTTON_PRESS))
{
GtkTreePath *path = NULL;
GtkTreeViewColumn *column = NULL;
gint cell_x = 0;
gint cell_y = 0;
if (gtk_tree_view_get_path_at_pos(
GTK_TREE_VIEW(dv->GtkGetTreeView()),
(int) gdk_event->x, (int) gdk_event->y,
&path,
&column,
&cell_x,
&cell_y))
{
if (path)
{
GtkTreeIter iter;
dv->GtkGetInternal()->get_iter( &iter, path );
wxDataViewEvent event( wxEVT_COMMAND_DATAVIEW_ITEM_CONTEXT_MENU, dv->GetId() );
wxDataViewItem item( (void*) iter.user_data );;
event.SetItem( item );
event.SetModel( dv->GetModel() );
bool ret = dv->HandleWindowEvent( event );
gtk_tree_path_free( path );
return ret;
}
}
}
return FALSE;
}
IMPLEMENT_DYNAMIC_CLASS(wxDataViewCtrl, wxDataViewCtrlBase) IMPLEMENT_DYNAMIC_CLASS(wxDataViewCtrl, wxDataViewCtrlBase)
@@ -3379,6 +3420,9 @@ bool wxDataViewCtrl::Create(wxWindow *parent, wxWindowID id,
g_signal_connect (m_treeview, "motion_notify_event", g_signal_connect (m_treeview, "motion_notify_event",
G_CALLBACK (gtk_dataview_motion_notify_callback), this); G_CALLBACK (gtk_dataview_motion_notify_callback), this);
g_signal_connect (m_treeview, "button_press_event",
G_CALLBACK (gtk_dataview_button_press_callback), this);
return true; return true;
} }