Commit 67cfa075 authored by Michael Catanzaro's avatar Michael Catanzaro

Revert "Don't use deprecated gtk_menu_popup"

This reverts commit 8d4267a6.
parent 949bce19
......@@ -24,6 +24,74 @@
#include <glib/gi18n.h>
#include <gtk/gtk.h>
/**
* ephy_gui_menu_position_under_widget:
* @menu:
* @x:
* @y:
* @push_in:
* @user_data: a #GtkWidget
*
* Positions @menu under (or over, depending on space available) the widget
* @user_data.
*/
void
ephy_gui_menu_position_under_widget (GtkMenu *menu,
gint *x,
gint *y,
gboolean *push_in,
gpointer user_data)
{
/* Adapted from gtktoolbar.c */
GtkWidget *widget = GTK_WIDGET (user_data);
GtkWidget *container;
GtkRequisition req;
GtkRequisition menu_req;
GtkAllocation allocation;
GdkRectangle monitor;
GdkWindow *window;
int monitor_num;
GdkScreen *screen;
g_return_if_fail (GTK_IS_WIDGET (widget));
container = gtk_widget_get_ancestor (widget, GTK_TYPE_CONTAINER);
g_return_if_fail (container != NULL);
gtk_widget_get_preferred_size (widget, &req, NULL);
gtk_widget_get_preferred_size (GTK_WIDGET (menu), &menu_req, NULL);
screen = gtk_widget_get_screen (GTK_WIDGET (menu));
window = gtk_widget_get_window (widget);
monitor_num = gdk_screen_get_monitor_at_window (screen, window);
if (monitor_num < 0)
monitor_num = 0;
gdk_screen_get_monitor_geometry (screen, monitor_num, &monitor);
gtk_widget_get_allocation (widget, &allocation);
gdk_window_get_origin (window, x, y);
if (!gtk_widget_get_has_window (widget)) {
*x += allocation.x;
*y += allocation.y;
}
if (gtk_widget_get_direction (container) == GTK_TEXT_DIR_LTR)
*x += allocation.width - req.width;
else
*x += req.width - menu_req.width;
if ((*y + allocation.height + menu_req.height) <= monitor.y + monitor.height)
*y += allocation.height;
else if ((*y - menu_req.height) >= monitor.y)
*y -= menu_req.height;
else if (monitor.y + monitor.height - (*y + allocation.height) > *y)
*y += allocation.height;
else
*y -= menu_req.height;
*push_in = FALSE;
}
GtkWindowGroup *
ephy_gui_ensure_window_group (GtkWindow *window)
{
......
......@@ -24,6 +24,12 @@
G_BEGIN_DECLS
void ephy_gui_menu_position_under_widget (GtkMenu *menu,
gint *x,
gint *y,
gboolean *push_in,
gpointer user_data);
GtkWindowGroup *ephy_gui_ensure_window_group (GtkWindow *window);
void ephy_gui_get_current_event (GdkEventType *type,
......
......@@ -418,11 +418,10 @@ popup_history_menu (GtkWidget *widget,
GtkWidget *menu;
menu = build_dropdown_menu (window, direction);
gtk_menu_popup_at_widget (GTK_MENU (menu),
widget,
GDK_GRAVITY_SOUTH_WEST,
GDK_GRAVITY_NORTH_WEST,
(GdkEvent *)event);
gtk_menu_popup (GTK_MENU (menu),
NULL, NULL,
ephy_gui_menu_position_under_widget, widget,
event->button, event->time);
}
typedef struct {
......
......@@ -452,7 +452,7 @@ on_treeview_button_press_event (GtkWidget *widget,
menu = gtk_menu_new_from_model (self->treeview_popup_menu_model);
gtk_menu_attach_to_widget (GTK_MENU (menu), GTK_WIDGET (self), NULL);
gtk_menu_popup_at_pointer (GTK_MENU (menu), (GdkEvent *)event);
gtk_menu_popup (GTK_MENU (menu), NULL, NULL, NULL, NULL, event->button, event->time);
return TRUE;
}
......
......@@ -2360,17 +2360,16 @@ show_notebook_popup_menu (GtkNotebook *notebook,
"move-right");
g_simple_action_set_enabled (G_SIMPLE_ACTION (action), page_num < n_pages - 1);
gtk_menu_popup_at_pointer (GTK_MENU (menu), (GdkEvent *)event);
gtk_menu_popup (GTK_MENU (menu), NULL, NULL,
NULL, NULL,
event->button, event->time);
} else {
tab = GTK_WIDGET (window->active_embed);
tab_label = gtk_notebook_get_tab_label (notebook, tab);
/* Not tested, because I don't know how to trigger this code. */
gtk_menu_popup_at_widget (GTK_MENU (menu),
tab_label,
GDK_GRAVITY_SOUTH_WEST,
GDK_GRAVITY_NORTH_WEST,
NULL);
gtk_menu_popup (GTK_MENU (menu), NULL, NULL,
ephy_gui_menu_position_under_widget, tab_label,
0, gtk_get_current_event_time ());
gtk_menu_shell_select_first (GTK_MENU_SHELL (menu), FALSE);
}
......
......@@ -328,7 +328,7 @@ on_passwords_treeview_button_press_event (GtkWidget *widget,
menu = gtk_menu_new_from_model (dialog->treeview_popup_menu_model);
gtk_menu_attach_to_widget (GTK_MENU (menu), GTK_WIDGET (dialog), NULL);
gtk_menu_popup_at_pointer (GTK_MENU (menu), (GdkEvent *)event);
gtk_menu_popup (GTK_MENU (menu), NULL, NULL, NULL, NULL, event->button, event->time);
return TRUE;
}
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment