Skip to content
Permalink
Browse files

avoid deprecated 'gtk_menu_popup'

  • Loading branch information...
sc0w committed May 19, 2018
1 parent 4d80780 commit 49f8520391f2e9a06c4ea234434bfa8a9b5f85ee
@@ -1375,13 +1375,9 @@ popup_menu (PlumaFileBrowserWidget * obj, GdkEventButton * event, GtkTreeModel *
}
}

gtk_menu_popup (GTK_MENU (menu), NULL, NULL, NULL, NULL,
event->button, event->time);
gtk_menu_popup_at_pointer (GTK_MENU (menu), NULL);
} else {
gtk_menu_popup (GTK_MENU (menu), NULL, NULL,
pluma_utils_menu_position_under_tree_view,
obj->priv->treeview, 0,
gtk_get_current_event_time ());
menu_popup_at_treeview_selection (menu, GTK_WIDGET (obj->priv->treeview));
gtk_menu_shell_select_first (GTK_MENU_SHELL (menu), FALSE);
}

@@ -491,69 +491,6 @@ pluma_documents_panel_class_init (PlumaDocumentsPanelClass *klass)
g_type_class_add_private (object_class, sizeof (PlumaDocumentsPanelPrivate));
}

static GtkTreePath *
get_current_path (PlumaDocumentsPanel *panel)
{
gint num;
GtkWidget *nb;
GtkTreePath *path;

nb = _pluma_window_get_notebook (panel->priv->window);
num = gtk_notebook_get_current_page (GTK_NOTEBOOK (nb));

path = gtk_tree_path_new_from_indices (num, -1);

return path;
}

static void
menu_position (GtkMenu *menu,
gint *x,
gint *y,
gboolean *push_in,
PlumaDocumentsPanel *panel)
{
GtkTreePath *path;
GdkRectangle rect;
gint wy;
GtkAllocation allocation;
GtkRequisition requisition;
GtkWidget *w;

w = panel->priv->treeview;

gtk_widget_get_allocation(w, &allocation);

path = get_current_path (panel);

gtk_tree_view_get_cell_area (GTK_TREE_VIEW (w),
path,
NULL,
&rect);

wy = rect.y;

gdk_window_get_origin (gtk_widget_get_window (w), x, y);

gtk_widget_get_preferred_size (GTK_WIDGET (menu), NULL, &requisition);

if (gtk_widget_get_direction (w) == GTK_TEXT_DIR_RTL)
{
*x += allocation.x + allocation.width - requisition.width - 10;
}
else
{
*x += allocation.x + 10;
}

wy = MAX (*y + 5, *y + wy + 5);
wy = MIN (wy, *y + allocation.height - requisition.height - 5);

*y = wy;

*push_in = TRUE;
}

static gboolean
show_popup_menu (PlumaDocumentsPanel *panel,
GdkEventButton *event)
@@ -566,24 +503,11 @@ show_popup_menu (PlumaDocumentsPanel *panel,

if (event != NULL)
{
gtk_menu_popup (GTK_MENU (menu),
NULL,
NULL,
NULL,
NULL,
event->button,
event->time);
gtk_menu_popup_at_pointer (GTK_MENU (menu), NULL);
}
else
{
gtk_menu_popup (GTK_MENU (menu),
NULL,
NULL,
(GtkMenuPositionFunc) menu_position,
panel,
0,
gtk_get_current_event_time ());

menu_popup_at_treeview_selection (menu, panel->priv->treeview);
gtk_menu_shell_select_first (GTK_MENU_SHELL (menu), FALSE);
}

@@ -498,9 +498,7 @@ multi_button_clicked (GtkWidget *button,
gtk_menu_attach (GTK_MENU (m), i, 1, 2, 1, 2);
g_signal_connect (i, "activate", G_CALLBACK (on_2x2_clicked), preview);

gtk_menu_popup (GTK_MENU (m),
NULL, NULL, NULL, preview, 0,
GDK_CURRENT_TIME);
gtk_menu_popup_at_pointer (GTK_MENU (m), NULL);
}

static void
@@ -182,34 +182,6 @@ menu_deactivate (GtkMenu *menu,
gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON (combo->priv->button), FALSE);
}

static void
menu_position_func (GtkMenu *menu,
gint *x,
gint *y,
gboolean *push_in,
PlumaStatusComboBox *combo)
{
GtkRequisition request;
GtkAllocation allocation;

*push_in = FALSE;

gtk_widget_get_preferred_size (gtk_widget_get_toplevel (GTK_WIDGET (menu)), NULL, &request);

/* get the origin... */
gdk_window_get_origin (gtk_widget_get_window (GTK_WIDGET (combo)), x, y);
gtk_widget_get_allocation (GTK_WIDGET (combo), &allocation);

/* make the menu as wide as the widget */
if (request.width < allocation.width)
{
gtk_widget_set_size_request (GTK_WIDGET (menu), allocation.width, -1);
}

/* position it above the widget */
*y -= request.height;
}

static void
button_press_event (GtkWidget *widget,
GdkEventButton *event,
@@ -231,13 +203,11 @@ button_press_event (GtkWidget *widget,
gtk_widget_set_size_request (gtk_widget_get_toplevel (combo->priv->menu), -1, max_height);
}

gtk_menu_popup (GTK_MENU (combo->priv->menu),
NULL,
NULL,
(GtkMenuPositionFunc)menu_position_func,
combo,
event->button,
event->time);
gtk_menu_popup_at_widget (GTK_MENU (combo->priv->menu),
gtk_widget_get_parent (widget),
GDK_GRAVITY_NORTH_WEST,
GDK_GRAVITY_SOUTH_WEST,
(const GdkEvent*) event);

gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON (combo->priv->button), TRUE);

@@ -202,6 +202,31 @@ pluma_utils_menu_position_under_tree_view (GtkMenu *menu,
}
}

void
menu_popup_at_treeview_selection (GtkWidget *menu,
GtkWidget *treeview)
{
GtkTreePath *path;
GtkTreeViewColumn *column;
GdkWindow *bin_window;
GdkRectangle rect;

gtk_tree_view_get_cursor (GTK_TREE_VIEW (treeview), &path, &column);
g_return_if_fail (path != NULL);

if (column == NULL)
column = gtk_tree_view_get_column (GTK_TREE_VIEW (treeview), 0);

bin_window = gtk_tree_view_get_bin_window (GTK_TREE_VIEW (treeview));
gtk_tree_view_get_cell_area (GTK_TREE_VIEW (treeview), path, column, &rect);

gtk_menu_popup_at_rect (GTK_MENU (menu), bin_window, &rect,
GDK_GRAVITY_SOUTH_WEST, GDK_GRAVITY_NORTH_WEST,
NULL);

gtk_tree_path_free(path);
}

/**
* pluma_gtk_button_new_with_icon:
* @label:
@@ -64,6 +64,9 @@ void pluma_utils_menu_position_under_tree_view
gboolean *push_in,
gpointer user_data);

void menu_popup_at_treeview_selection (GtkWidget *menu,
GtkWidget *treeview);

GtkWidget *pluma_gtk_button_new_with_icon (const gchar *label,
const gchar *icon_name);

@@ -2014,13 +2014,7 @@ show_line_numbers_menu (GtkWidget *view,

menu = create_line_numbers_menu (view);

gtk_menu_popup (GTK_MENU (menu),
NULL,
NULL,
NULL,
NULL,
event->button,
event->time);
gtk_menu_popup_at_pointer (GTK_MENU (menu), NULL);
}

static gboolean
@@ -3442,9 +3442,7 @@ show_notebook_popup_menu (GtkNotebook *notebook,
#endif
if (event != NULL)
{
gtk_menu_popup (GTK_MENU (menu), NULL, NULL,
NULL, NULL,
event->button, event->time);
gtk_menu_popup_at_pointer (GTK_MENU (menu), NULL);
}
else
{
@@ -3456,9 +3454,11 @@ show_notebook_popup_menu (GtkNotebook *notebook,

tab_label = gtk_notebook_get_tab_label (notebook, tab);

gtk_menu_popup (GTK_MENU (menu), NULL, NULL,
pluma_utils_menu_position_under_widget, tab_label,
0, gtk_get_current_event_time ());
gtk_menu_popup_at_widget (GTK_MENU (menu),
tab_label,
GDK_GRAVITY_SOUTH_WEST,
GDK_GRAVITY_NORTH_WEST,
(const GdkEvent*) event);

gtk_menu_shell_select_first (GTK_MENU_SHELL (menu), FALSE);
}

0 comments on commit 49f8520

Please sign in to comment.
You can’t perform that action at this time.