Skip to content

Commit 49f8520

Browse files
committed
avoid deprecated 'gtk_menu_popup'
1 parent 4d80780 commit 49f8520

File tree

8 files changed

+45
-135
lines changed

8 files changed

+45
-135
lines changed

plugins/filebrowser/pluma-file-browser-widget.c

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1375,13 +1375,9 @@ popup_menu (PlumaFileBrowserWidget * obj, GdkEventButton * event, GtkTreeModel *
13751375
}
13761376
}
13771377

1378-
gtk_menu_popup (GTK_MENU (menu), NULL, NULL, NULL, NULL,
1379-
event->button, event->time);
1378+
gtk_menu_popup_at_pointer (GTK_MENU (menu), NULL);
13801379
} else {
1381-
gtk_menu_popup (GTK_MENU (menu), NULL, NULL,
1382-
pluma_utils_menu_position_under_tree_view,
1383-
obj->priv->treeview, 0,
1384-
gtk_get_current_event_time ());
1380+
menu_popup_at_treeview_selection (menu, GTK_WIDGET (obj->priv->treeview));
13851381
gtk_menu_shell_select_first (GTK_MENU_SHELL (menu), FALSE);
13861382
}
13871383

pluma/pluma-documents-panel.c

Lines changed: 2 additions & 78 deletions
Original file line numberDiff line numberDiff line change
@@ -491,69 +491,6 @@ pluma_documents_panel_class_init (PlumaDocumentsPanelClass *klass)
491491
g_type_class_add_private (object_class, sizeof (PlumaDocumentsPanelPrivate));
492492
}
493493

494-
static GtkTreePath *
495-
get_current_path (PlumaDocumentsPanel *panel)
496-
{
497-
gint num;
498-
GtkWidget *nb;
499-
GtkTreePath *path;
500-
501-
nb = _pluma_window_get_notebook (panel->priv->window);
502-
num = gtk_notebook_get_current_page (GTK_NOTEBOOK (nb));
503-
504-
path = gtk_tree_path_new_from_indices (num, -1);
505-
506-
return path;
507-
}
508-
509-
static void
510-
menu_position (GtkMenu *menu,
511-
gint *x,
512-
gint *y,
513-
gboolean *push_in,
514-
PlumaDocumentsPanel *panel)
515-
{
516-
GtkTreePath *path;
517-
GdkRectangle rect;
518-
gint wy;
519-
GtkAllocation allocation;
520-
GtkRequisition requisition;
521-
GtkWidget *w;
522-
523-
w = panel->priv->treeview;
524-
525-
gtk_widget_get_allocation(w, &allocation);
526-
527-
path = get_current_path (panel);
528-
529-
gtk_tree_view_get_cell_area (GTK_TREE_VIEW (w),
530-
path,
531-
NULL,
532-
&rect);
533-
534-
wy = rect.y;
535-
536-
gdk_window_get_origin (gtk_widget_get_window (w), x, y);
537-
538-
gtk_widget_get_preferred_size (GTK_WIDGET (menu), NULL, &requisition);
539-
540-
if (gtk_widget_get_direction (w) == GTK_TEXT_DIR_RTL)
541-
{
542-
*x += allocation.x + allocation.width - requisition.width - 10;
543-
}
544-
else
545-
{
546-
*x += allocation.x + 10;
547-
}
548-
549-
wy = MAX (*y + 5, *y + wy + 5);
550-
wy = MIN (wy, *y + allocation.height - requisition.height - 5);
551-
552-
*y = wy;
553-
554-
*push_in = TRUE;
555-
}
556-
557494
static gboolean
558495
show_popup_menu (PlumaDocumentsPanel *panel,
559496
GdkEventButton *event)
@@ -566,24 +503,11 @@ show_popup_menu (PlumaDocumentsPanel *panel,
566503

567504
if (event != NULL)
568505
{
569-
gtk_menu_popup (GTK_MENU (menu),
570-
NULL,
571-
NULL,
572-
NULL,
573-
NULL,
574-
event->button,
575-
event->time);
506+
gtk_menu_popup_at_pointer (GTK_MENU (menu), NULL);
576507
}
577508
else
578509
{
579-
gtk_menu_popup (GTK_MENU (menu),
580-
NULL,
581-
NULL,
582-
(GtkMenuPositionFunc) menu_position,
583-
panel,
584-
0,
585-
gtk_get_current_event_time ());
586-
510+
menu_popup_at_treeview_selection (menu, panel->priv->treeview);
587511
gtk_menu_shell_select_first (GTK_MENU_SHELL (menu), FALSE);
588512
}
589513

pluma/pluma-print-preview.c

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -498,9 +498,7 @@ multi_button_clicked (GtkWidget *button,
498498
gtk_menu_attach (GTK_MENU (m), i, 1, 2, 1, 2);
499499
g_signal_connect (i, "activate", G_CALLBACK (on_2x2_clicked), preview);
500500

501-
gtk_menu_popup (GTK_MENU (m),
502-
NULL, NULL, NULL, preview, 0,
503-
GDK_CURRENT_TIME);
501+
gtk_menu_popup_at_pointer (GTK_MENU (m), NULL);
504502
}
505503

506504
static void

pluma/pluma-status-combo-box.c

Lines changed: 5 additions & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -182,34 +182,6 @@ menu_deactivate (GtkMenu *menu,
182182
gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON (combo->priv->button), FALSE);
183183
}
184184

185-
static void
186-
menu_position_func (GtkMenu *menu,
187-
gint *x,
188-
gint *y,
189-
gboolean *push_in,
190-
PlumaStatusComboBox *combo)
191-
{
192-
GtkRequisition request;
193-
GtkAllocation allocation;
194-
195-
*push_in = FALSE;
196-
197-
gtk_widget_get_preferred_size (gtk_widget_get_toplevel (GTK_WIDGET (menu)), NULL, &request);
198-
199-
/* get the origin... */
200-
gdk_window_get_origin (gtk_widget_get_window (GTK_WIDGET (combo)), x, y);
201-
gtk_widget_get_allocation (GTK_WIDGET (combo), &allocation);
202-
203-
/* make the menu as wide as the widget */
204-
if (request.width < allocation.width)
205-
{
206-
gtk_widget_set_size_request (GTK_WIDGET (menu), allocation.width, -1);
207-
}
208-
209-
/* position it above the widget */
210-
*y -= request.height;
211-
}
212-
213185
static void
214186
button_press_event (GtkWidget *widget,
215187
GdkEventButton *event,
@@ -231,13 +203,11 @@ button_press_event (GtkWidget *widget,
231203
gtk_widget_set_size_request (gtk_widget_get_toplevel (combo->priv->menu), -1, max_height);
232204
}
233205

234-
gtk_menu_popup (GTK_MENU (combo->priv->menu),
235-
NULL,
236-
NULL,
237-
(GtkMenuPositionFunc)menu_position_func,
238-
combo,
239-
event->button,
240-
event->time);
206+
gtk_menu_popup_at_widget (GTK_MENU (combo->priv->menu),
207+
gtk_widget_get_parent (widget),
208+
GDK_GRAVITY_NORTH_WEST,
209+
GDK_GRAVITY_SOUTH_WEST,
210+
(const GdkEvent*) event);
241211

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

pluma/pluma-utils.c

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -202,6 +202,31 @@ pluma_utils_menu_position_under_tree_view (GtkMenu *menu,
202202
}
203203
}
204204

205+
void
206+
menu_popup_at_treeview_selection (GtkWidget *menu,
207+
GtkWidget *treeview)
208+
{
209+
GtkTreePath *path;
210+
GtkTreeViewColumn *column;
211+
GdkWindow *bin_window;
212+
GdkRectangle rect;
213+
214+
gtk_tree_view_get_cursor (GTK_TREE_VIEW (treeview), &path, &column);
215+
g_return_if_fail (path != NULL);
216+
217+
if (column == NULL)
218+
column = gtk_tree_view_get_column (GTK_TREE_VIEW (treeview), 0);
219+
220+
bin_window = gtk_tree_view_get_bin_window (GTK_TREE_VIEW (treeview));
221+
gtk_tree_view_get_cell_area (GTK_TREE_VIEW (treeview), path, column, &rect);
222+
223+
gtk_menu_popup_at_rect (GTK_MENU (menu), bin_window, &rect,
224+
GDK_GRAVITY_SOUTH_WEST, GDK_GRAVITY_NORTH_WEST,
225+
NULL);
226+
227+
gtk_tree_path_free(path);
228+
}
229+
205230
/**
206231
* pluma_gtk_button_new_with_icon:
207232
* @label:

pluma/pluma-utils.h

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -64,6 +64,9 @@ void pluma_utils_menu_position_under_tree_view
6464
gboolean *push_in,
6565
gpointer user_data);
6666

67+
void menu_popup_at_treeview_selection (GtkWidget *menu,
68+
GtkWidget *treeview);
69+
6770
GtkWidget *pluma_gtk_button_new_with_icon (const gchar *label,
6871
const gchar *icon_name);
6972

pluma/pluma-view.c

Lines changed: 1 addition & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -2014,13 +2014,7 @@ show_line_numbers_menu (GtkWidget *view,
20142014

20152015
menu = create_line_numbers_menu (view);
20162016

2017-
gtk_menu_popup (GTK_MENU (menu),
2018-
NULL,
2019-
NULL,
2020-
NULL,
2021-
NULL,
2022-
event->button,
2023-
event->time);
2017+
gtk_menu_popup_at_pointer (GTK_MENU (menu), NULL);
20242018
}
20252019

20262020
static gboolean

pluma/pluma-window.c

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -3442,9 +3442,7 @@ show_notebook_popup_menu (GtkNotebook *notebook,
34423442
#endif
34433443
if (event != NULL)
34443444
{
3445-
gtk_menu_popup (GTK_MENU (menu), NULL, NULL,
3446-
NULL, NULL,
3447-
event->button, event->time);
3445+
gtk_menu_popup_at_pointer (GTK_MENU (menu), NULL);
34483446
}
34493447
else
34503448
{
@@ -3456,9 +3454,11 @@ show_notebook_popup_menu (GtkNotebook *notebook,
34563454

34573455
tab_label = gtk_notebook_get_tab_label (notebook, tab);
34583456

3459-
gtk_menu_popup (GTK_MENU (menu), NULL, NULL,
3460-
pluma_utils_menu_position_under_widget, tab_label,
3461-
0, gtk_get_current_event_time ());
3457+
gtk_menu_popup_at_widget (GTK_MENU (menu),
3458+
tab_label,
3459+
GDK_GRAVITY_SOUTH_WEST,
3460+
GDK_GRAVITY_NORTH_WEST,
3461+
(const GdkEvent*) event);
34623462

34633463
gtk_menu_shell_select_first (GTK_MENU_SHELL (menu), FALSE);
34643464
}

0 commit comments

Comments
 (0)