]> git.saurik.com Git - wxWidgets.git/commitdiff
Implemented (for GTK+) and tested dataview_context_menu event
authorRobert Roebling <robert@roebling.de>
Sun, 16 Dec 2007 15:16:52 +0000 (15:16 +0000)
committerRobert Roebling <robert@roebling.de>
Sun, 16 Dec 2007 15:16:52 +0000 (15:16 +0000)
git-svn-id: https://svn.wxwidgets.org/svn/wx/wxWidgets/trunk@50746 c3d73ce0-8a6f-49c7-b76d-6d57e0e08775

samples/dataview/dataview.cpp
src/gtk/dataview.cpp

index c50fa4aa10995297aefc62b16d129069552ed414..c852284476cf10a2a06f7db71e3779ef9723dccf 100644 (file)
@@ -518,6 +518,8 @@ public:
     void OnHeaderRightClick( wxDataViewEvent &event );
     void OnSorted( wxDataViewEvent &event );
 
+    void OnContextMenu( wxDataViewEvent &event );
+
     void OnRightClick( wxMouseEvent &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_RIGHT_CLICKED(ID_MUSIC_CTRL, MyFrame::OnHeaderRightClick)
     EVT_DATAVIEW_COLUMN_SORTED(ID_MUSIC_CTRL, MyFrame::OnSorted)
+
+    EVT_DATAVIEW_ITEM_CONTEXT_MENU(ID_MUSIC_CTRL, MyFrame::OnContextMenu)
     
     EVT_RIGHT_UP(MyFrame::OnRightClick)
 END_EVENT_TABLE()
@@ -868,6 +872,15 @@ void MyFrame::OnCollapsed( wxDataViewEvent &event )
     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 )
 {
     if(!m_log)
index 929fa97c4d86acafa16438d81ccd129a310958d5..978ddd716aa9d0f9accbb9f8e78daf9a7be3ad57 100644 (file)
@@ -3233,8 +3233,8 @@ void gtk_dataviewctrl_size_callback( GtkWidget *WXUNUSED(widget),
 
 static gboolean
 gtk_dataview_motion_notify_callback( GtkWidget *widget,
-                                   GdkEventMotion *gdk_event,
-                                   wxDataViewCtrl *dv )
+                                     GdkEventMotion *gdk_event,
+                                     wxDataViewCtrl *dv )
 {
     if (gdk_event->is_hint)
     {
@@ -3273,6 +3273,47 @@ gtk_dataview_motion_notify_callback( GtkWidget *widget,
     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)
 
@@ -3379,6 +3420,9 @@ bool wxDataViewCtrl::Create(wxWindow *parent, wxWindowID id,
     g_signal_connect (m_treeview, "motion_notify_event",
                       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;
 }