2 * Copyright (C) 2002 Marco Pesenti Gritti
4 * This program is free software; you can redistribute it and/or modify
5 * it under the terms of the GNU General Public License as published by
6 * the Free Software Foundation; either version 2, or (at your option)
9 * This program is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 * GNU General Public License for more details.
14 * You should have received a copy of the GNU General Public License
15 * along with this program; if not, write to the Free Software
16 * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
25 #include <gtk/gtktreeview.h>
26 #include <gtk/gtktreeselection.h>
31 ev_gui_sanitise_popup_position (GtkMenu *menu,
36 GdkScreen *screen = gtk_widget_get_screen (widget);
41 g_return_if_fail (widget != NULL);
43 gtk_widget_size_request (GTK_WIDGET (menu), &req);
45 monitor_num = gdk_screen_get_monitor_at_point (screen, *x, *y);
46 gtk_menu_set_monitor (menu, monitor_num);
47 gdk_screen_get_monitor_geometry (screen, monitor_num, &monitor);
49 *x = CLAMP (*x, monitor.x, monitor.x + MAX (0, monitor.width - req.width));
50 *y = CLAMP (*y, monitor.y, monitor.y + MAX (0, monitor.height - req.height));
54 ev_gui_menu_position_tree_selection (GtkMenu *menu,
60 GtkTreeSelection *selection;
63 GtkTreeView *tree_view = GTK_TREE_VIEW (user_data);
64 GtkWidget *widget = GTK_WIDGET (user_data);
68 gtk_widget_size_request (GTK_WIDGET (menu), &req);
69 gdk_window_get_origin (widget->window, x, y);
71 *x += (widget->allocation.width - req.width) / 2;
73 /* Add on height for the treeview title */
74 gtk_tree_view_get_visible_rect (tree_view, &visible);
75 *y += widget->allocation.height - visible.height;
77 selection = gtk_tree_view_get_selection (tree_view);
78 selected_rows = gtk_tree_selection_get_selected_rows (selection, &model);
81 GdkRectangle cell_rect;
83 gtk_tree_view_get_cell_area (tree_view, selected_rows->data,
86 *y += CLAMP (cell_rect.y + cell_rect.height, 0, visible.height);
88 g_list_foreach (selected_rows, (GFunc)gtk_tree_path_free, NULL);
89 g_list_free (selected_rows);
92 ev_gui_sanitise_popup_position (menu, widget, x, y);