X-Git-Url: https://www.fi.muni.cz/~kas/git//home/kas/public_html/git/?a=blobdiff_plain;f=shell%2Fev-utils.c;h=90217262f3dbc2a16041d07346affbfd4fa5ee21;hb=64153d3fe6c59d09f13131db5f376df550f966ac;hp=cf8a67c85bd8189dd1a9e81548379e502dacaf92;hpb=ca0836cb912f3b88834cae97774079314727c6e2;p=evince.git diff --git a/shell/ev-utils.c b/shell/ev-utils.c index cf8a67c8..90217262 100644 --- a/shell/ev-utils.c +++ b/shell/ev-utils.c @@ -18,9 +18,16 @@ * */ +#include + #include "ev-utils.h" +#include "ev-file-helpers.h" + +#include #include +#define PRINT_CONFIG_FILENAME "ev-print-config.xml" + typedef struct { int size; @@ -177,3 +184,188 @@ ev_pixbuf_add_shadow (GdkPixbuf *src, int size, } +/* Simple function to output the contents of a region. Used solely for testing + * the region code. + */ +void +ev_print_region_contents (GdkRegion *region) +{ + GdkRectangle *rectangles = NULL; + gint n_rectangles, i; + + if (region == NULL) { + g_print ("\n"); + return; + } + + g_print ("\n", region); + gdk_region_get_rectangles (region, &rectangles, &n_rectangles); + for (i = 0; i < n_rectangles; i++) { + g_print ("\t(%d %d, %d %d) [%dx%d]\n", + rectangles[i].x, + rectangles[i].y, + rectangles[i].x + rectangles[i].width, + rectangles[i].y + rectangles[i].height, + rectangles[i].width, + rectangles[i].height); + } + g_free (rectangles); +} + +#ifdef WITH_GNOME_PRINT +gboolean +using_pdf_printer (GnomePrintConfig *config) +{ + const guchar *driver; + + driver = gnome_print_config_get ( + config, (const guchar *)"Settings.Engine.Backend.Driver"); + + if (driver) { + if (!strcmp ((const gchar *)driver, "gnome-print-pdf")) + return TRUE; + else + return FALSE; + } + + return FALSE; +} + +gboolean +using_postscript_printer (GnomePrintConfig *config) +{ + const guchar *driver; + const guchar *transport; + + driver = gnome_print_config_get ( + config, (const guchar *)"Settings.Engine.Backend.Driver"); + + transport = gnome_print_config_get ( + config, (const guchar *)"Settings.Transport.Backend"); + + if (driver) { + if (!strcmp ((const gchar *)driver, "gnome-print-ps")) + return TRUE; + else + return FALSE; + } else if (transport) { /* these transports default to PostScript */ + if (!strcmp ((const gchar *)transport, "CUPS")) + return TRUE; + else if (!strcmp ((const gchar *)transport, "LPD")) + return TRUE; + else if (!strcmp ((const gchar *)transport, "PAPI")) + return TRUE; + } + + return FALSE; +} + +GnomePrintConfig * +load_print_config_from_file (void) +{ + GnomePrintConfig *print_config = NULL; + char *file_name, *contents = NULL; + + file_name = g_build_filename (ev_dot_dir (), PRINT_CONFIG_FILENAME, + NULL); + + if (g_file_get_contents (file_name, &contents, NULL, NULL)) { + print_config = gnome_print_config_from_string (contents, 0); + g_free (contents); + } + + if (print_config == NULL) { + print_config = gnome_print_config_default (); + } + + g_free (file_name); + + return print_config; +} + +void +save_print_config_to_file (GnomePrintConfig *config) +{ + char *file_name, *str; + + g_return_if_fail (config != NULL); + + str = gnome_print_config_to_string (config, 0); + if (str == NULL) return; + + file_name = g_build_filename (ev_dot_dir (), + PRINT_CONFIG_FILENAME, + NULL); + + g_file_set_contents (file_name, str, -1, NULL); + + g_free (file_name); + g_free (str); +} +#endif /* WITH_GNOME_PRINT */ + +static void +ev_gui_sanitise_popup_position (GtkMenu *menu, + GtkWidget *widget, + gint *x, + gint *y) +{ + GdkScreen *screen = gtk_widget_get_screen (widget); + gint monitor_num; + GdkRectangle monitor; + GtkRequisition req; + + g_return_if_fail (widget != NULL); + + gtk_widget_size_request (GTK_WIDGET (menu), &req); + + monitor_num = gdk_screen_get_monitor_at_point (screen, *x, *y); + gtk_menu_set_monitor (menu, monitor_num); + gdk_screen_get_monitor_geometry (screen, monitor_num, &monitor); + + *x = CLAMP (*x, monitor.x, monitor.x + MAX (0, monitor.width - req.width)); + *y = CLAMP (*y, monitor.y, monitor.y + MAX (0, monitor.height - req.height)); +} + +void +ev_gui_menu_position_tree_selection (GtkMenu *menu, + gint *x, + gint *y, + gboolean *push_in, + gpointer user_data) +{ + GtkTreeSelection *selection; + GList *selected_rows; + GtkTreeModel *model; + GtkTreeView *tree_view = GTK_TREE_VIEW (user_data); + GtkWidget *widget = GTK_WIDGET (user_data); + GtkRequisition req; + GdkRectangle visible; + + gtk_widget_size_request (GTK_WIDGET (menu), &req); + gdk_window_get_origin (widget->window, x, y); + + *x += (widget->allocation.width - req.width) / 2; + + /* Add on height for the treeview title */ + gtk_tree_view_get_visible_rect (tree_view, &visible); + *y += widget->allocation.height - visible.height; + + selection = gtk_tree_view_get_selection (tree_view); + selected_rows = gtk_tree_selection_get_selected_rows (selection, &model); + if (selected_rows) + { + GdkRectangle cell_rect; + + gtk_tree_view_get_cell_area (tree_view, selected_rows->data, + NULL, &cell_rect); + + *y += CLAMP (cell_rect.y + cell_rect.height, 0, visible.height); + + g_list_foreach (selected_rows, (GFunc)gtk_tree_path_free, NULL); + g_list_free (selected_rows); + } + + ev_gui_sanitise_popup_position (menu, widget, x, y); +} +