Commit 998078ba authored by Sébastien Lafargue's avatar Sébastien Lafargue

gedit: remove usage of deprecated gtk_menu_popup_* functions

The position of the file browser contextual menu
when activated by shortcut is also fixed.
parent 9913f5ae
......@@ -1506,12 +1506,7 @@ row_on_button_pressed (GtkWidget *row_event_box,
G_CALLBACK (gtk_widget_destroy),
NULL);
gtk_menu_popup_for_device (GTK_MENU (menu),
gdk_event_get_device ((GdkEvent *)event),
NULL, NULL,
NULL, NULL, NULL,
event->button,
event->time);
gtk_menu_popup_at_pointer (GTK_MENU (menu), (GdkEvent *)event);
return TRUE;
}
......
......@@ -484,9 +484,7 @@ multi_pages_button_clicked (GtkWidget *button,
gtk_menu_attach (GTK_MENU (menu), item, 1, 2, 0, 1);
g_signal_connect (item, "activate", G_CALLBACK (on_1x2_clicked), preview);
gtk_menu_popup (GTK_MENU (menu),
NULL, NULL, NULL, preview, 0,
GDK_CURRENT_TIME);
gtk_menu_popup_at_pointer (GTK_MENU (menu), NULL);
}
static void
......
......@@ -78,55 +78,37 @@ gedit_utils_menu_position_under_widget (GtkMenu *menu,
*push_in = TRUE;
}
void
gedit_utils_menu_position_under_tree_view (GtkMenu *menu,
gint *x,
gint *y,
gboolean *push_in,
gpointer user_data)
gboolean
gedit_utils_menu_position_under_tree_view (GtkTreeView *tree_view,
GdkRectangle *rect)
{
GtkTreeView *tree = GTK_TREE_VIEW (user_data);
GtkTreeModel *model;
GtkTreeSelection *selection;
GtkTreeIter iter;
model = gtk_tree_view_get_model (tree);
g_return_if_fail (model != NULL);
GtkTreeModel *model;
gint count_rows;
GList *rows;
gint widget_x, widget_y;
selection = gtk_tree_view_get_selection (tree);
g_return_if_fail (selection != NULL);
model = gtk_tree_view_get_model (tree_view);
g_return_val_if_fail (model != NULL, FALSE);
if (gtk_tree_selection_get_selected (selection, NULL, &iter))
{
GtkTreePath *path;
GdkRectangle rect;
selection = gtk_tree_view_get_selection (tree_view);
g_return_val_if_fail (selection != NULL, FALSE);
widget_get_origin (GTK_WIDGET (tree), x, y);
count_rows = gtk_tree_selection_count_selected_rows (selection);
if (count_rows != 1)
return FALSE;
path = gtk_tree_model_get_path (model, &iter);
gtk_tree_view_get_cell_area (tree, path,
gtk_tree_view_get_column (tree, 0), /* FIXME 0 for RTL ? */
&rect);
gtk_tree_path_free (path);
rows = gtk_tree_selection_get_selected_rows (selection, &model);
gtk_tree_view_get_cell_area (tree_view, (GtkTreePath *)(rows->data),
gtk_tree_view_get_column (tree_view, 0),
rect);
*x += rect.x;
*y += rect.y + rect.height;
gtk_tree_view_convert_bin_window_to_widget_coords (tree_view, rect->x, rect->y, &widget_x, &widget_y);
rect->x = widget_x;
rect->y = widget_y;
if (gtk_widget_get_direction (GTK_WIDGET (tree)) == GTK_TEXT_DIR_RTL)
{
GtkRequisition requisition;
gtk_widget_get_preferred_size (GTK_WIDGET (menu),
&requisition, NULL);
*x += rect.width - requisition.width;
}
}
else
{
/* no selection -> regular "under widget" positioning */
gedit_utils_menu_position_under_widget (menu,
x, y, push_in,
tree);
}
g_list_free_full (rows, (GDestroyNotify) gtk_tree_path_free);
return TRUE;
}
/**
......
......@@ -43,101 +43,80 @@ G_BEGIN_DECLS
enum { GEDIT_ALL_WORKSPACES = 0xffffffff };
void gedit_utils_menu_position_under_widget (GtkMenu *menu,
gint *x,
gint *y,
gboolean *push_in,
gpointer user_data);
void gedit_utils_menu_position_under_tree_view
(GtkMenu *menu,
gint *x,
gint *y,
gboolean *push_in,
gpointer user_data);
void gedit_utils_menu_position_under_widget (GtkMenu *menu,
gint *x,
gint *y,
gboolean *push_in,
gpointer user_data);
gboolean gedit_utils_menu_position_under_tree_view (GtkTreeView *tree_view,
GdkRectangle *rect);
G_DEPRECATED
gchar *gedit_utils_escape_underscores (const gchar *text,
gssize length);
gchar *gedit_utils_escape_underscores (const gchar *text,
gssize length);
gchar *gedit_utils_str_middle_truncate (const gchar *string,
guint truncate_length);
gchar *gedit_utils_str_end_truncate (const gchar *string,
guint truncate_length);
void gedit_utils_set_atk_name_description (GtkWidget *widget,
const gchar *name,
const gchar *description);
void gedit_utils_set_atk_relation (GtkWidget *obj1,
GtkWidget *obj2,
AtkRelationType rel_type);
void gedit_warning (GtkWindow *parent,
const gchar *format,
...) G_GNUC_PRINTF(2, 3);
gchar *gedit_utils_make_valid_utf8 (const char *name);
gchar *gedit_utils_str_middle_truncate (const gchar *string,
guint truncate_length);
gchar *gedit_utils_str_end_truncate (const gchar *string,
guint truncate_length);
void gedit_utils_set_atk_name_description (GtkWidget *widget,
const gchar *name,
const gchar *description);
void gedit_utils_set_atk_relation (GtkWidget *obj1,
GtkWidget *obj2,
AtkRelationType rel_type);
void gedit_warning (GtkWindow *parent,
const gchar *format,
...) G_GNUC_PRINTF(2, 3);
gchar *gedit_utils_make_valid_utf8 (const char *name);
/* Note that this function replace home dir with ~ */
G_DEPRECATED
gchar *gedit_utils_uri_get_dirname (const char *uri);
gchar *gedit_utils_location_get_dirname_for_display
(GFile *location);
gchar *gedit_utils_replace_home_dir_with_tilde(const gchar *uri);
gchar *gedit_utils_uri_get_dirname (const char *uri);
gchar *gedit_utils_location_get_dirname_for_display (GFile *location);
gchar *gedit_utils_replace_home_dir_with_tilde (const gchar *uri);
guint gedit_utils_get_current_workspace (GdkScreen *screen);
guint gedit_utils_get_window_workspace (GtkWindow *gtkwindow);
void gedit_utils_get_current_viewport (GdkScreen *screen,
gint *x,
gint *y);
gboolean gedit_utils_is_valid_location (GFile *location);
guint gedit_utils_get_current_workspace (GdkScreen *screen);
guint gedit_utils_get_window_workspace (GtkWindow *gtkwindow);
void gedit_utils_get_current_viewport (GdkScreen *screen,
gint *x,
gint *y);
gboolean gedit_utils_is_valid_location (GFile *location);
G_DEPRECATED
gboolean gedit_utils_get_ui_objects (const gchar *filename,
gchar **root_objects,
GtkWidget **error_widget,
const gchar *object_name,
...) G_GNUC_NULL_TERMINATED;
gboolean gedit_utils_get_ui_objects (const gchar *filename,
gchar **root_objects,
GtkWidget **error_widget,
const gchar *object_name,
...) G_GNUC_NULL_TERMINATED;
G_DEPRECATED
gboolean gedit_utils_get_ui_objects_with_translation_domain
(const gchar *filename,
const gchar *translation_domain,
gchar **root_objects,
GtkWidget **error_widget,
const gchar *object_name,
...) G_GNUC_NULL_TERMINATED;
gboolean gedit_utils_get_ui_objects_with_translation_domain (const gchar *filename,
const gchar *translation_domain,
gchar **root_objects,
GtkWidget **error_widget,
const gchar *object_name,
...) G_GNUC_NULL_TERMINATED;
G_DEPRECATED
gchar *gedit_utils_make_canonical_uri_from_shell_arg
(const gchar *str);
gchar *gedit_utils_make_canonical_uri_from_shell_arg (const gchar *str);
gchar *gedit_utils_basename_for_display (GFile *location);
gboolean gedit_utils_decode_uri (const gchar *uri,
gchar **scheme,
gchar **user,
gchar **port,
gchar **host,
gchar **path);
gchar *gedit_utils_basename_for_display (GFile *location);
gboolean gedit_utils_decode_uri (const gchar *uri,
gchar **scheme,
gchar **user,
gchar **port,
gchar **host,
gchar **path);
/* Turns data from a drop into a list of well formatted uris */
gchar **gedit_utils_drop_get_uris (GtkSelectionData *selection_data);
GtkSourceCompressionType
gedit_utils_get_compression_type_from_content_type
(const gchar *content_type);
gchar *gedit_utils_set_direct_save_filename (GdkDragContext *context);
gchar **gedit_utils_drop_get_uris (GtkSelectionData *selection_data);
GtkSourceCompressionType gedit_utils_get_compression_type_from_content_type (const gchar *content_type);
gchar *gedit_utils_set_direct_save_filename (GdkDragContext *context);
const gchar *gedit_utils_newline_type_to_string (GtkSourceNewlineType newline_type);
const gchar *gedit_utils_newline_type_to_string (GtkSourceNewlineType newline_type);
G_END_DECLS
......
......@@ -938,10 +938,7 @@ search_entry_icon_release (GtkEntry *entry,
G_CALLBACK (gtk_widget_destroy),
NULL);
gtk_menu_popup (GTK_MENU (menu),
NULL, NULL,
gedit_utils_menu_position_under_widget, entry,
event->button, event->time);
gtk_menu_popup_at_widget (GTK_MENU (menu), GTK_WIDGET (entry), GDK_GRAVITY_SOUTH_WEST, GDK_GRAVITY_NORTH_WEST, NULL);
}
static void
......
......@@ -483,13 +483,7 @@ show_line_numbers_menu (GeditView *view,
NULL);
gtk_widget_show_all (menu);
gtk_menu_popup (GTK_MENU (menu),
NULL,
NULL,
NULL,
NULL,
event->button,
event->time);
gtk_menu_popup_at_pointer (GTK_MENU (menu), (GdkEvent *)event);
}
static gboolean
......
......@@ -2220,9 +2220,7 @@ on_show_popup_menu (GeditMultiNotebook *multi,
NULL);
gtk_widget_show (menu);
gtk_menu_popup (GTK_MENU (menu), NULL, NULL,
NULL, NULL,
event->button, event->time);
gtk_menu_popup_at_pointer (GTK_MENU (menu), (GdkEvent *)event);
}
static void
......
......@@ -1178,6 +1178,7 @@ gedit_file_browser_widget_get_first_selected (GeditFileBrowserWidget *obj,
static gboolean
popup_menu (GeditFileBrowserWidget *obj,
GtkTreeView *treeview,
GdkEventButton *event,
GtkTreeModel *model)
{
......@@ -1197,13 +1198,13 @@ popup_menu (GeditFileBrowserWidget *obj,
if (event != NULL)
{
GtkTreeSelection *selection;
selection = gtk_tree_view_get_selection (GTK_TREE_VIEW (obj->priv->treeview));
selection = gtk_tree_view_get_selection (treeview);
if (gtk_tree_selection_count_selected_rows (selection) <= 1)
{
GtkTreePath *path;
if (gtk_tree_view_get_path_at_pos (GTK_TREE_VIEW (obj->priv->treeview),
if (gtk_tree_view_get_path_at_pos (treeview,
(gint)event->x, (gint)event->y,
&path, NULL, NULL, NULL))
{
......@@ -1213,16 +1214,26 @@ popup_menu (GeditFileBrowserWidget *obj,
}
}
gtk_menu_popup (GTK_MENU (menu), NULL, NULL, NULL, NULL,
event->button, event->time);
gtk_menu_popup_at_pointer (GTK_MENU (menu), (GdkEvent *)event);
}
else
{
gtk_menu_popup (GTK_MENU (menu), NULL, NULL,
gedit_utils_menu_position_under_tree_view,
obj->priv->treeview, 0,
gtk_get_current_event_time ());
gtk_menu_shell_select_first (GTK_MENU_SHELL (menu), FALSE);
GdkWindow *window = gtk_widget_get_window (GTK_WIDGET (treeview));
GdkGravity rect_gravity = GDK_GRAVITY_EAST;
GdkGravity menu_gravity = GDK_GRAVITY_NORTH_WEST;
GdkRectangle rect;
if (gedit_utils_menu_position_under_tree_view (treeview, &rect))
{
if (gtk_widget_get_direction (GTK_WIDGET (treeview)) == GTK_TEXT_DIR_RTL)
{
rect_gravity = GDK_GRAVITY_WEST;
menu_gravity = GDK_GRAVITY_NORTH_EAST;
}
gtk_menu_popup_at_rect (GTK_MENU (menu), window, &rect, rect_gravity, menu_gravity, NULL);
gtk_menu_shell_select_first (GTK_MENU_SHELL (menu), FALSE);
}
}
return TRUE;
......@@ -2501,82 +2512,6 @@ on_treeview_error (GeditFileBrowserView *tree_view,
g_signal_emit (obj, signals[ERROR], 0, code, message);
}
/* Copied from GTK+'s gtkmenubutton.c and modified */
static void
menu_position_func (GtkMenu *menu,
gint *x,
gint *y,
gboolean *push_in,
GtkWidget *widget)
{
GtkWidget *popup = GTK_WIDGET (menu);
GtkWidget *toplevel;
GtkRequisition menu_req;
GtkTextDirection direction;
GdkRectangle monitor;
gint monitor_num;
GdkScreen *screen;
GdkWindow *window;
GtkAllocation allocation, arrow_allocation;
GtkAlign align;
/* Set the corresponding type hint on the toplevel,
* so the WM can omit the top side of the shadows.
*/
toplevel = gtk_widget_get_toplevel (popup);
gtk_window_set_type_hint (GTK_WINDOW (toplevel), GDK_WINDOW_TYPE_HINT_DROPDOWN_MENU);
gtk_widget_get_preferred_size (popup, &menu_req, NULL);
align = gtk_widget_get_halign (popup);
direction = gtk_widget_get_direction (widget);
window = gtk_widget_get_window (widget);
screen = gtk_widget_get_screen (GTK_WIDGET (menu));
monitor_num = gdk_screen_get_monitor_at_window (screen, window);
if (monitor_num < 0)
monitor_num = 0;
gdk_screen_get_monitor_workarea (screen, monitor_num, &monitor);
gtk_widget_get_allocation (widget, &allocation);
gtk_widget_get_allocation (widget, &arrow_allocation);
gdk_window_get_origin (window, x, y);
*x += allocation.x;
*y += allocation.y;
/* treat the default align value like START */
if (align == GTK_ALIGN_FILL)
align = GTK_ALIGN_START;
if (align == GTK_ALIGN_CENTER)
{
*x -= (menu_req.width - allocation.width) / 2;
}
else if ((align == GTK_ALIGN_START && direction == GTK_TEXT_DIR_LTR) ||
(align == GTK_ALIGN_END && direction == GTK_TEXT_DIR_RTL))
{
*x += MAX (allocation.width - menu_req.width, 0);
}
else if (menu_req.width > allocation.width)
{
*x -= menu_req.width - allocation.width;
}
if ((*y + arrow_allocation.height + menu_req.height) <= monitor.y + monitor.height)
*y += arrow_allocation.height;
else if ((*y - menu_req.height) >= monitor.y)
*y -= menu_req.height;
else if (monitor.y + monitor.height - (*y + arrow_allocation.height) > *y)
*y += arrow_allocation.height;
else
*y -= menu_req.height;
*push_in = FALSE;
}
static gboolean
on_location_button_press_event (GtkWidget *button,
GdkEventButton *event,
......@@ -2592,9 +2527,7 @@ on_location_button_press_event (GtkWidget *button,
else
menu = obj->priv->location_next_menu;
gtk_menu_popup_for_device (GTK_MENU (menu), event->device, NULL, NULL,
(GtkMenuPositionFunc) menu_position_func,
button, NULL, event->button, event->time);
gtk_menu_popup_at_pointer (GTK_MENU (menu), (GdkEvent *)event);
return TRUE;
}
......@@ -2697,7 +2630,7 @@ static gboolean
on_treeview_popup_menu (GeditFileBrowserView *treeview,
GeditFileBrowserWidget *obj)
{
return popup_menu (obj, NULL, gtk_tree_view_get_model (GTK_TREE_VIEW (treeview)));
return popup_menu (obj, treeview, NULL, gtk_tree_view_get_model (GTK_TREE_VIEW (treeview)));
}
static gboolean
......@@ -2707,6 +2640,7 @@ on_treeview_button_press_event (GeditFileBrowserView *treeview,
{
if (event->type == GDK_BUTTON_PRESS && event->button == GDK_BUTTON_SECONDARY)
return popup_menu (obj,
treeview,
event,
gtk_tree_view_get_model (GTK_TREE_VIEW (treeview)));
......
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