]> www.fi.muni.cz Git - evince.git/commitdiff
Show the popup menu also on keybindings
authorMarco Pesenti Gritti <mpg@redhat.com>
Mon, 16 May 2005 10:10:59 +0000 (10:10 +0000)
committerMarco Pesenti Gritti <marco@src.gnome.org>
Mon, 16 May 2005 10:10:59 +0000 (10:10 +0000)
2005-05-16  Marco Pesenti Gritti  <mpg@redhat.com>

        * lib/Makefile.am:
        * shell/ev-sidebar-links.c: (build_popup_menu), (popup_menu_cb),
        (button_press_cb), (ev_sidebar_links_construct):

        Show the popup menu also on keybindings

ChangeLog
lib/Makefile.am
lib/ev-gui.c [new file with mode: 0644]
lib/ev-gui.h [new file with mode: 0644]
shell/ev-sidebar-links.c

index 5055917acd555a8e918e4cef574021309c829c75..878b8ac75d9517f41a7b5b6b80f568d591210d02 100644 (file)
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,11 @@
+2005-05-16  Marco Pesenti Gritti  <mpg@redhat.com>
+
+       * lib/Makefile.am:
+       * shell/ev-sidebar-links.c: (build_popup_menu), (popup_menu_cb),
+       (button_press_cb), (ev_sidebar_links_construct):
+
+       Show the popup menu also on keybindings
+
 2005-05-16  Marco Pesenti Gritti  <mpg@redhat.com>
 
        * shell/ev-window.c: (ev_window_print), (ev_window_print_range):
index 6bcfc2e7e98b8222d473165cc466c0f05db89c74..adf16f11cdb145a1bde195895580bbd56e69b5c7 100644 (file)
@@ -14,4 +14,6 @@ libev_la_SOURCES=                             \
        ev-debug.h                              \
        ev-file-helpers.c                       \
        ev-file-helpers.h                       \
+       ev-gui.c                                \
+       ev-gui.h                                \
        $(NULL)
diff --git a/lib/ev-gui.c b/lib/ev-gui.c
new file mode 100644 (file)
index 0000000..595be67
--- /dev/null
@@ -0,0 +1,93 @@
+/*
+ *  Copyright (C) 2002 Marco Pesenti Gritti
+ *
+ *  This program is free software; you can redistribute it and/or modify
+ *  it under the terms of the GNU General Public License as published by
+ *  the Free Software Foundation; either version 2, or (at your option)
+ *  any later version.
+ *
+ *  This program is distributed in the hope that it will be useful,
+ *  but WITHOUT ANY WARRANTY; without even the implied warranty of
+ *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ *  GNU General Public License for more details.
+ *
+ *  You should have received a copy of the GNU General Public License
+ *  along with this program; if not, write to the Free Software
+ *  Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
+ *
+ *  $Id$
+ */
+
+#ifdef HAVE_CONFIG_H
+#include "config.h"
+#endif
+
+#include <gtk/gtktreeview.h>
+#include <gtk/gtktreeselection.h>
+
+#include "ev-gui.h"
+
+static void
+ev_gui_sanitise_popup_position (GtkMenu *menu,
+                               GtkWidget *widget,
+                               gint *x,
+                               gint *y)
+{
+       GdkScreen *screen = gtk_widget_get_screen (widget);
+       gint monitor_num;
+       GdkRectangle monitor;
+       GtkRequisition req;
+
+       g_return_if_fail (widget != NULL);
+
+       gtk_widget_size_request (GTK_WIDGET (menu), &req);
+
+       monitor_num = gdk_screen_get_monitor_at_point (screen, *x, *y);
+       gtk_menu_set_monitor (menu, monitor_num);
+       gdk_screen_get_monitor_geometry (screen, monitor_num, &monitor);
+
+       *x = CLAMP (*x, monitor.x, monitor.x + MAX (0, monitor.width - req.width));
+       *y = CLAMP (*y, monitor.y, monitor.y + MAX (0, monitor.height - req.height));
+}
+
+void
+ev_gui_menu_position_tree_selection (GtkMenu   *menu,
+                                    gint      *x,
+                                    gint      *y,
+                                    gboolean  *push_in,
+                                    gpointer  user_data)
+{
+       GtkTreeSelection *selection;
+       GList *selected_rows;
+       GtkTreeModel *model;
+       GtkTreeView *tree_view = GTK_TREE_VIEW (user_data);
+       GtkWidget *widget = GTK_WIDGET (user_data);
+       GtkRequisition req;
+       GdkRectangle visible;
+
+       gtk_widget_size_request (GTK_WIDGET (menu), &req);
+       gdk_window_get_origin (widget->window, x, y);
+
+       *x += (widget->allocation.width - req.width) / 2;
+
+       /* Add on height for the treeview title */
+       gtk_tree_view_get_visible_rect (tree_view, &visible);
+       *y += widget->allocation.height - visible.height;
+
+       selection = gtk_tree_view_get_selection (tree_view);
+       selected_rows = gtk_tree_selection_get_selected_rows (selection, &model);
+       if (selected_rows)
+       {
+               GdkRectangle cell_rect;
+
+               gtk_tree_view_get_cell_area (tree_view, selected_rows->data,
+                                            NULL, &cell_rect);
+
+               *y += CLAMP (cell_rect.y + cell_rect.height, 0, visible.height);
+
+               g_list_foreach (selected_rows, (GFunc)gtk_tree_path_free, NULL);
+               g_list_free (selected_rows);
+       }
+
+       ev_gui_sanitise_popup_position (menu, widget, x, y);
+}
diff --git a/lib/ev-gui.h b/lib/ev-gui.h
new file mode 100644 (file)
index 0000000..79323e6
--- /dev/null
@@ -0,0 +1,35 @@
+/*
+ *  Copyright (C) 2002 Marco Pesenti Gritti
+ *
+ *  This program is free software; you can redistribute it and/or modify
+ *  it under the terms of the GNU General Public License as published by
+ *  the Free Software Foundation; either version 2, or (at your option)
+ *  any later version.
+ *
+ *  This program is distributed in the hope that it will be useful,
+ *  but WITHOUT ANY WARRANTY; without even the implied warranty of
+ *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ *  GNU General Public License for more details.
+ *
+ *  You should have received a copy of the GNU General Public License
+ *  along with this program; if not, write to the Free Software
+ *  Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
+ *
+ *  $Id$
+ */
+
+#ifndef EPHY_GUI_H
+#define EPHY_GUI_H
+
+#include <gtk/gtkmenu.h>
+
+G_BEGIN_DECLS
+
+void ev_gui_menu_position_tree_selection (GtkMenu   *menu,
+                                         gint      *x,
+                                         gint      *y,
+                                         gboolean  *push_in,
+                                         gpointer   user_data);
+G_END_DECLS
+
+#endif
index 93959b37ab60444963ff94fd7520b7aabb50b7a3..e15e9ae291ad20165ff5b32e55825fb7dc2100c9 100644 (file)
@@ -33,6 +33,7 @@
 #include "ev-job-queue.h"
 #include "ev-document-links.h"
 #include "ev-window.h"
+#include "ev-gui.h"
 
 struct _EvSidebarLinksPrivate {
        GtkWidget *tree_view;
@@ -259,6 +260,32 @@ print_section_cb (GtkWidget *menuitem, EvSidebarLinks *sidebar)
        }
 }
 
+static GtkMenu *
+build_popup_menu (EvSidebarLinks *sidebar)
+{
+       GtkWidget *menu;
+       GtkWidget *item;
+
+       menu = gtk_menu_new ();
+       item = gtk_image_menu_item_new_from_stock (GTK_STOCK_PRINT, NULL);
+       gtk_label_set_label (GTK_LABEL (GTK_BIN (item)->child), _("Print..."));
+       gtk_widget_show (item);
+       gtk_menu_shell_append (GTK_MENU_SHELL (menu), item);
+       g_signal_connect (item, "activate",
+                         G_CALLBACK (print_section_cb), sidebar);
+
+       return GTK_MENU (menu);
+}
+
+static void
+popup_menu_cb (GtkWidget *treeview, EvSidebarLinks *sidebar)
+{
+       gtk_menu_popup (build_popup_menu (sidebar), NULL, NULL,
+                       ev_gui_menu_position_tree_selection,
+                       sidebar->priv->tree_view, 0,
+                       gtk_get_current_event_time ());
+}
+
 static gboolean
 button_press_cb (GtkWidget *treeview,
                  GdkEventButton *event,
@@ -272,25 +299,11 @@ button_press_cb (GtkWidget *treeview,
                                                   event->y,
                                                   &path,
                                                   NULL, NULL, NULL)) {
-                       GtkWidget *menu;
-                       GtkWidget *item;
-
                        gtk_tree_view_set_cursor (GTK_TREE_VIEW (treeview),
                                                  path, NULL, FALSE);
-
-                       menu = gtk_menu_new ();
-                       item = gtk_image_menu_item_new_from_stock
-                                                       (GTK_STOCK_PRINT, NULL);
-                       gtk_label_set_label (GTK_LABEL (GTK_BIN (item)->child),
-                                            _("Print..."));
-                       gtk_widget_show (item);
-                       gtk_menu_shell_append (GTK_MENU_SHELL (menu), item);
-                       g_signal_connect (item, "activate",
-                                         G_CALLBACK (print_section_cb), sidebar);
-
-                       gtk_menu_popup (GTK_MENU (menu), NULL, NULL, NULL, NULL, 2,
+                       gtk_menu_popup (build_popup_menu (sidebar), NULL,
+                                       NULL, NULL, NULL, event->button,
                                        gtk_get_current_event_time ());
-
                        gtk_tree_path_free (path);
 
                        return TRUE;
@@ -357,6 +370,10 @@ ev_sidebar_links_construct (EvSidebarLinks *ev_sidebar_links)
                          "button_press_event",
                          G_CALLBACK (button_press_cb),
                          ev_sidebar_links);
+       g_signal_connect (GTK_TREE_VIEW (priv->tree_view),
+                         "popup_menu",
+                         G_CALLBACK (popup_menu_cb),
+                         ev_sidebar_links);
 }
 
 static void