|
26 | 26 | #include <string.h> |
27 | 27 | #include <glib/gi18n.h> |
28 | 28 |
|
29 | | -static int |
30 | | -_gtk_get_monitor_num (GdkMonitor *monitor) |
31 | | -{ |
32 | | - GdkDisplay *display; |
33 | | - int n_monitors, i; |
34 | | - |
35 | | - display = gdk_monitor_get_display (monitor); |
36 | | - n_monitors = gdk_display_get_n_monitors (display); |
37 | | - |
38 | | - for(i = 0; i < n_monitors; i++) |
39 | | - { |
40 | | - if (gdk_display_get_monitor (display, i) == monitor) return i; |
41 | | - } |
42 | | - |
43 | | - return -1; |
44 | | -} |
45 | | - |
46 | | -static void |
47 | | -ev_gui_sanitise_popup_position (GtkMenu *menu, |
48 | | - GtkWidget *widget, |
49 | | - gint *x, |
50 | | - gint *y) |
51 | | -{ |
52 | | - GdkDisplay *display = gtk_widget_get_display (widget); |
53 | | - GdkMonitor *monitor_num; |
54 | | - GdkRectangle monitor; |
55 | | - GtkRequisition req; |
56 | | - |
57 | | - g_return_if_fail (widget != NULL); |
58 | | - |
59 | | - gtk_widget_get_preferred_size (GTK_WIDGET (menu), &req, NULL); |
60 | | - |
61 | | - monitor_num = gdk_display_get_monitor_at_point (display, *x, *y); |
62 | | - gtk_menu_set_monitor (menu, _gtk_get_monitor_num (monitor_num)); |
63 | | - gdk_monitor_get_geometry (monitor_num, &monitor); |
64 | | - |
65 | | - *x = CLAMP (*x, monitor.x, monitor.x + MAX (0, monitor.width - req.width)); |
66 | | - *y = CLAMP (*y, monitor.y, monitor.y + MAX (0, monitor.height - req.height)); |
67 | | -} |
68 | | - |
69 | | -void |
70 | | -ev_gui_menu_position_tree_selection (GtkMenu *menu, |
71 | | - gint *x, |
72 | | - gint *y, |
73 | | - gboolean *push_in, |
74 | | - gpointer user_data) |
75 | | -{ |
76 | | - GtkTreeSelection *selection; |
77 | | - GList *selected_rows; |
78 | | - GtkTreeModel *model; |
79 | | - GtkTreeView *tree_view = GTK_TREE_VIEW (user_data); |
80 | | - GtkWidget *widget = GTK_WIDGET (user_data); |
81 | | - GtkRequisition req; |
82 | | - GtkAllocation allocation; |
83 | | - GdkRectangle visible; |
84 | | - |
85 | | - gtk_widget_get_preferred_size (GTK_WIDGET (menu), &req, NULL); |
86 | | - gdk_window_get_origin (gtk_widget_get_window (widget), x, y); |
87 | | - gtk_widget_get_allocation (widget, &allocation); |
88 | | - |
89 | | - *x += (allocation.width - req.width) / 2; |
90 | | - |
91 | | - /* Add on height for the treeview title */ |
92 | | - gtk_tree_view_get_visible_rect (tree_view, &visible); |
93 | | - *y += allocation.height - visible.height; |
94 | | - |
95 | | - selection = gtk_tree_view_get_selection (tree_view); |
96 | | - selected_rows = gtk_tree_selection_get_selected_rows (selection, &model); |
97 | | - if (selected_rows) |
98 | | - { |
99 | | - GdkRectangle cell_rect; |
100 | | - |
101 | | - gtk_tree_view_get_cell_area (tree_view, selected_rows->data, |
102 | | - NULL, &cell_rect); |
103 | | - |
104 | | - *y += CLAMP (cell_rect.y + cell_rect.height, 0, visible.height); |
105 | | - |
106 | | - g_list_foreach (selected_rows, (GFunc)gtk_tree_path_free, NULL); |
107 | | - g_list_free (selected_rows); |
108 | | - } |
109 | | - |
110 | | - ev_gui_sanitise_popup_position (menu, widget, x, y); |
111 | | -} |
112 | | - |
113 | 29 | void |
114 | 30 | file_chooser_dialog_add_writable_pixbuf_formats (GtkFileChooser *chooser) |
115 | 31 | { |
|
0 commit comments