]> Pileus Git - ~andy/gtk/blobdiff - gtk/gtkprintunixdialog.c
Finish making the GtkSettings object identical on all backends so that it doesn't...
[~andy/gtk] / gtk / gtkprintunixdialog.c
index f4ce65620adc261c3a9cce25933d8ddc49be922f..d555c1b865034f8ad1a78cc5d2fd72c9d7c94759 100644 (file)
  */
 
 #include "config.h"
+
 #include <stdlib.h>
 #include <string.h>
 #include <ctype.h>
 #include <stdio.h>
 #include <math.h>
 
-#include "gtkintl.h"
-#include "gtkprivate.h"
+#include "gtkprintunixdialog.h"
+
+#include "gtkcustompaperunixdialog.h"
+#include "gtkprintbackend.h"
+#include "gtkprinter-private.h"
+#include "gtkprinteroptionwidget.h"
+#include "gtkprintutils.h"
 
 #include "gtkspinbutton.h"
 #include "gtkcellrendererpixbuf.h"
 #include "gtklabel.h"
 #include "gtkeventbox.h"
 #include "gtkbuildable.h"
-
-#include "gtkcustompaperunixdialog.h"
-#include "gtkprintbackend.h"
-#include "gtkprinter-private.h"
-#include "gtkprintunixdialog.h"
-#include "gtkprinteroptionwidget.h"
-#include "gtkprintutils.h"
-
 #include "gtkmessagedialog.h"
 #include "gtkbutton.h"
+#include "gtkintl.h"
+#include "gtkprivate.h"
+#include "gtktypebuiltins.h"
 
-#define EXAMPLE_PAGE_AREA_SIZE 140
+#define EXAMPLE_PAGE_AREA_SIZE 110
 #define RULER_DISTANCE 7.5
 #define RULER_RADIUS 2
 
@@ -75,8 +76,7 @@ static void     gtk_print_unix_dialog_get_property (GObject            *object,
                                                     guint               prop_id,
                                                     GValue             *value,
                                                     GParamSpec         *pspec);
-static void     gtk_print_unix_dialog_style_set    (GtkWidget          *widget,
-                                                    GtkStyle           *previous_style);
+static void     gtk_print_unix_dialog_style_updated (GtkWidget          *widget);
 static void     populate_dialog                    (GtkPrintUnixDialog *dialog);
 static void     unschedule_idle_mark_conflicts     (GtkPrintUnixDialog *dialog);
 static void     selected_printer_changed           (GtkTreeSelection   *selection,
@@ -248,7 +248,7 @@ struct GtkPrintUnixDialogPrivate
 
   GtkPrinter *current_printer;
   GtkPrinter *request_details_printer;
-  guint request_details_tag;
+  gulong request_details_tag;
   GtkPrinterOptionSet *options;
   gulong options_changed_handler;
   gulong mark_conflicts_id;
@@ -290,7 +290,7 @@ gtk_print_unix_dialog_class_init (GtkPrintUnixDialogClass *class)
   object_class->set_property = gtk_print_unix_dialog_set_property;
   object_class->get_property = gtk_print_unix_dialog_get_property;
 
-  widget_class->style_set = gtk_print_unix_dialog_style_set;
+  widget_class->style_updated = gtk_print_unix_dialog_style_updated;
 
   g_object_class_install_property (object_class,
                                    PROP_PAGE_SETUP,
@@ -402,7 +402,7 @@ set_busy_cursor (GtkPrintUnixDialog *dialog,
   gdk_display_flush (display);
 
   if (cursor)
-    gdk_cursor_unref (cursor);
+    g_object_unref (cursor);
 }
 
 static void
@@ -1140,7 +1140,7 @@ wrap_in_frame (const gchar *label,
   gtk_label_set_markup (GTK_LABEL (label_widget), bold_text);
   g_free (bold_text);
 
-  frame = gtk_vbox_new (FALSE, 6);
+  frame = gtk_box_new (GTK_ORIENTATION_VERTICAL, 6);
   gtk_box_pack_start (GTK_BOX (frame), label_widget, FALSE, FALSE, 0);
 
   alignment = gtk_alignment_new (0.0, 0.0, 1.0, 1.0);
@@ -1189,7 +1189,7 @@ add_option_to_extension_point (GtkPrinterOption *option,
       gtk_misc_set_alignment (GTK_MISC (label), 0.0, 0.5);
       gtk_label_set_mnemonic_widget (GTK_LABEL (label), widget);
 
-      hbox = gtk_hbox_new (FALSE, 12);
+      hbox = gtk_box_new (GTK_ORIENTATION_HORIZONTAL, 12);
       gtk_box_pack_start (GTK_BOX (hbox), label, FALSE, FALSE, 0);
       gtk_box_pack_start (GTK_BOX (hbox), widget, FALSE, FALSE, 0);
       gtk_widget_show (hbox);
@@ -1928,6 +1928,7 @@ selected_printer_changed (GtkTreeSelection   *selection,
 
       priv->options_changed_handler =
         g_signal_connect_swapped (priv->options, "changed", G_CALLBACK (options_changed_cb), dialog);
+      schedule_idle_mark_conflicts (dialog);
     }
 
   update_dialog_from_settings (dialog);
@@ -1958,9 +1959,10 @@ paint_page (GtkWidget *widget,
             gchar     *text,
             gint       text_x)
 {
-  GtkStyle *style;
+  GtkStyleContext *context;
   gint x, y, width, height;
   gint text_y, linewidth;
+  GdkRGBA color;
 
   x = x_offset * scale;
   y = y_offset * scale;
@@ -1970,13 +1972,18 @@ paint_page (GtkWidget *widget,
   linewidth = 2;
   text_y = 21;
 
-  style = gtk_widget_get_style (widget);
+  context = gtk_widget_get_style_context (widget);
+
+  gtk_style_context_save (context);
+  gtk_style_context_add_class (context, GTK_STYLE_CLASS_VIEW);
 
-  gdk_cairo_set_source_color (cr, &style->base[GTK_STATE_NORMAL]);
+  gtk_style_context_get_background_color (context, 0, &color);
+  gdk_cairo_set_source_rgba (cr, &color);
   cairo_rectangle (cr, x, y, width, height);
   cairo_fill (cr);
 
-  gdk_cairo_set_source_color (cr, &style->text[GTK_STATE_NORMAL]);
+  gtk_style_context_get_color (context, 0, &color);
+  gdk_cairo_set_source_rgba (cr, &color);
   cairo_set_line_width (cr, linewidth);
   cairo_rectangle (cr, x + linewidth/2.0, y + linewidth/2.0, width - linewidth, height - linewidth);
   cairo_stroke (cr);
@@ -1987,16 +1994,16 @@ paint_page (GtkWidget *widget,
   cairo_set_font_size (cr, (gint)(9 * scale));
   cairo_move_to (cr, x + (gint)(text_x * scale), y + (gint)(text_y * scale));
   cairo_show_text (cr, text);
+
+  gtk_style_context_restore (context);
 }
 
 static gboolean
 draw_collate_cb (GtkWidget          *widget,
-                 GdkEventExpose     *event,
+                 cairo_t            *cr,
                  GtkPrintUnixDialog *dialog)
 {
-  GtkAllocation allocation;
   GtkSettings *settings;
-  cairo_t *cr;
   gint size;
   gfloat scale;
   gboolean collate, reverse, rtl;
@@ -2017,12 +2024,6 @@ draw_collate_cb (GtkWidget          *widget,
   scale = size / 48.0;
   text_x = rtl ? 4 : 11;
 
-  cr = gdk_cairo_create (gtk_widget_get_window (widget));
-
-  gtk_widget_get_allocation (widget, &allocation);
-  cairo_translate (cr, allocation.x, allocation.y);
-  gtk_widget_set_allocation (widget, &allocation);
-
   if (copies == 1)
     {
       paint_page (widget, cr, scale, rtl ? 40: 15, 5, reverse ? "1" : "2", text_x);
@@ -2037,16 +2038,13 @@ draw_collate_cb (GtkWidget          *widget,
       paint_page (widget, cr, scale, rtl ? 15 : 40, 15, collate == reverse ? "2" : "1", text_x);
     }
 
-  cairo_destroy (cr);
-
   return TRUE;
 }
 
 static void
-gtk_print_unix_dialog_style_set (GtkWidget *widget,
-                                 GtkStyle  *previous_style)
+gtk_print_unix_dialog_style_updated (GtkWidget *widget)
 {
-  GTK_WIDGET_CLASS (gtk_print_unix_dialog_parent_class)->style_set (widget, previous_style);
+  GTK_WIDGET_CLASS (gtk_print_unix_dialog_parent_class)->style_updated (widget);
 
   if (gtk_widget_has_screen (widget))
     {
@@ -2110,11 +2108,11 @@ create_main_page (GtkPrintUnixDialog *dialog)
   GtkWidget *custom_input;
   const gchar *range_tooltip;
 
-  main_vbox = gtk_vbox_new (FALSE, 18);
+  main_vbox = gtk_box_new (GTK_ORIENTATION_VERTICAL, 18);
   gtk_container_set_border_width (GTK_CONTAINER (main_vbox), 12);
   gtk_widget_show (main_vbox);
 
-  vbox = gtk_vbox_new (FALSE, 6);
+  vbox = gtk_box_new (GTK_ORIENTATION_VERTICAL, 6);
   gtk_box_pack_start (GTK_BOX (main_vbox), vbox, TRUE, TRUE, 0);
   gtk_widget_show (vbox);
 
@@ -2180,12 +2178,12 @@ create_main_page (GtkPrintUnixDialog *dialog)
   gtk_widget_show (treeview);
   gtk_container_add (GTK_CONTAINER (scrolled), treeview);
 
-  custom_input = gtk_hbox_new (FALSE, 18);
+  custom_input = gtk_box_new (GTK_ORIENTATION_HORIZONTAL, 18);
   gtk_widget_show (custom_input);
   gtk_box_pack_start (GTK_BOX (vbox), custom_input, FALSE, FALSE, 0);
   priv->extension_point = custom_input;
 
-  hbox = gtk_hbox_new (FALSE, 18);
+  hbox = gtk_box_new (GTK_ORIENTATION_HORIZONTAL, 18);
   gtk_widget_show (hbox);
   gtk_box_pack_start (GTK_BOX (main_vbox), hbox, FALSE, FALSE, 0);
 
@@ -2295,7 +2293,7 @@ create_main_page (GtkPrintUnixDialog *dialog)
   gtk_table_attach (GTK_TABLE (table), image,
                     1, 2, 1, 3, GTK_FILL, 0,
                     0, 0);
-  g_signal_connect (image, "expose-event",
+  g_signal_connect (image, "draw",
                     G_CALLBACK (draw_collate_cb), dialog);
 
   label = gtk_label_new (_("General"));
@@ -2575,6 +2573,13 @@ dialog_get_number_up_layout (GtkPrintUnixDialog *dialog)
   if (val == NULL)
     return layout;
 
+  if (val[0] == '\0' && priv->options)
+    {
+      GtkPrinterOption *option = gtk_printer_option_set_lookup (priv->options, "gtk-n-up-layout");
+      if (option)
+        val = option->value;
+    }
+
   enum_class = g_type_class_ref (GTK_TYPE_NUMBER_UP_LAYOUT);
   enum_value = g_enum_get_value_by_nick (enum_class, val);
   if (enum_value)
@@ -2586,13 +2591,11 @@ dialog_get_number_up_layout (GtkPrintUnixDialog *dialog)
 
 static gboolean
 draw_page_cb (GtkWidget          *widget,
-              GdkEventExpose     *event,
+              cairo_t            *cr,
               GtkPrintUnixDialog *dialog)
 {
   GtkPrintUnixDialogPrivate *priv = dialog->priv;
-  GtkAllocation allocation;
-  GtkStyle *style;
-  cairo_t *cr;
+  GtkStyleContext *context;
   gdouble ratio;
   gint w, h, tmp, shadow_offset;
   gint pages_x, pages_y, i, x, y, layout_w, layout_h;
@@ -2602,10 +2605,11 @@ draw_page_cb (GtkWidget          *widget,
   PangoLayout *layout;
   PangoFontDescription *font;
   gchar *text;
-  GdkColor *color;
+  GdkRGBA color;
   GtkNumberUpLayout number_up_layout;
   gint start_x, end_x, start_y, end_y;
   gint dx, dy;
+  gint width, height;
   gboolean horizontal;
   GtkPageSetup *page_setup;
   gdouble paper_width, paper_height;
@@ -2619,8 +2623,8 @@ draw_page_cb (GtkWidget          *widget,
     (orientation == GTK_PAGE_ORIENTATION_REVERSE_LANDSCAPE);
 
   number_up_layout = dialog_get_number_up_layout (dialog);
-
-  cr = gdk_cairo_create (gtk_widget_get_window (widget));
+  width = gtk_widget_get_allocated_width (widget);
+  height = gtk_widget_get_allocated_height (widget);
 
   cairo_save (cr);
 
@@ -2700,27 +2704,31 @@ draw_page_cb (GtkWidget          *widget,
       pages_y = tmp;
     }
 
-  style = gtk_widget_get_style (widget);
+  context = gtk_widget_get_style_context (widget);
+
+  gtk_style_context_save (context);
+  gtk_style_context_add_class (context, GTK_STYLE_CLASS_VIEW);
 
-  gtk_widget_get_allocation (widget, &allocation);
-  pos_x = allocation.x + (allocation.width - w) / 2;
-  pos_y = allocation.y + (allocation.height - h) / 2 - 10;
+  pos_x = (width - w) / 2;
+  pos_y = (height - h) / 2 - 10;
   cairo_translate (cr, pos_x, pos_y);
 
   shadow_offset = 3;
 
-  color = &style->text[GTK_STATE_NORMAL];
-  cairo_set_source_rgba (cr, color->red / 65535., color->green / 65535., color->blue / 65535, 0.5);
+  gtk_style_context_get_color (context, 0, &color);
+  cairo_set_source_rgba (cr, color.red, color.green, color.blue, 0.5);
   cairo_rectangle (cr, shadow_offset + 1, shadow_offset + 1, w, h);
   cairo_fill (cr);
 
-  gdk_cairo_set_source_color (cr, &style->base[GTK_STATE_NORMAL]);
+  gtk_style_context_get_background_color (context, 0, &color);
+  gdk_cairo_set_source_rgba (cr, &color);
   cairo_rectangle (cr, 1, 1, w, h);
   cairo_fill (cr);
   cairo_set_line_width (cr, 1.0);
   cairo_rectangle (cr, 0.5, 0.5, w + 1, h + 1);
 
-  gdk_cairo_set_source_color (cr, &style->text[GTK_STATE_NORMAL]);
+  gtk_style_context_get_color (context, 0, &color);
+  gdk_cairo_set_source_rgba (cr, &color);
   cairo_stroke (cr);
 
   i = 1;
@@ -2914,13 +2922,12 @@ draw_page_cb (GtkWidget          *widget,
 
       ltr = gtk_widget_get_direction (GTK_WIDGET (dialog)) == GTK_TEXT_DIR_LTR;
 
-      gtk_widget_get_allocation (widget, &allocation);
       if (ltr)
         cairo_translate (cr, pos_x - layout_w / PANGO_SCALE - 2 * RULER_DISTANCE,
-                             allocation.y + (allocation.height - layout_h / PANGO_SCALE) / 2);
+                             (height - layout_h / PANGO_SCALE) / 2);
       else
         cairo_translate (cr, pos_x + w + shadow_offset + 2 * RULER_DISTANCE,
-                             allocation.y + (allocation.height - layout_h / PANGO_SCALE) / 2);
+                             (height - layout_h / PANGO_SCALE) / 2);
 
       pango_cairo_show_layout (cr, layout);
 
@@ -2936,7 +2943,7 @@ draw_page_cb (GtkWidget          *widget,
       g_free (text);
       pango_layout_get_size (layout, &layout_w, &layout_h);
 
-      cairo_translate (cr, allocation.x + (allocation.width - layout_w / PANGO_SCALE) / 2,
+      cairo_translate (cr, (width - layout_w / PANGO_SCALE) / 2,
                            pos_y + h + shadow_offset + 2 * RULER_DISTANCE);
 
       pango_cairo_show_layout (cr, layout);
@@ -2989,7 +2996,7 @@ draw_page_cb (GtkWidget          *widget,
       cairo_stroke (cr);
     }
 
-  cairo_destroy (cr);
+  gtk_style_context_restore (context);
 
   return TRUE;
 }
@@ -3308,11 +3315,11 @@ create_page_setup_page (GtkPrintUnixDialog *dialog)
   GtkWidget *combo, *spinbutton, *draw;
   GtkCellRenderer *cell;
 
-  main_vbox = gtk_vbox_new (FALSE, 18);
+  main_vbox = gtk_box_new (GTK_ORIENTATION_VERTICAL, 18);
   gtk_container_set_border_width (GTK_CONTAINER (main_vbox), 12);
   gtk_widget_show (main_vbox);
 
-  hbox = gtk_hbox_new (FALSE, 18);
+  hbox = gtk_box_new (GTK_ORIENTATION_HORIZONTAL, 18);
   gtk_widget_show (hbox);
   gtk_box_pack_start (GTK_BOX (main_vbox), hbox, FALSE, FALSE, 0);
 
@@ -3378,7 +3385,7 @@ create_page_setup_page (GtkPrintUnixDialog *dialog)
                     0, 1, 3, 4,  GTK_FILL, 0,
                     0, 0);
 
-  combo = gtk_combo_box_new_text ();
+  combo = gtk_combo_box_text_new ();
   priv->page_set_combo = combo;
   gtk_widget_show (combo);
   gtk_table_attach (GTK_TABLE (table), combo,
@@ -3386,9 +3393,9 @@ create_page_setup_page (GtkPrintUnixDialog *dialog)
                     0, 0);
   gtk_label_set_mnemonic_widget (GTK_LABEL (label), combo);
   /* In enum order */
-  gtk_combo_box_append_text (GTK_COMBO_BOX (combo), _("All sheets"));
-  gtk_combo_box_append_text (GTK_COMBO_BOX (combo), _("Even sheets"));
-  gtk_combo_box_append_text (GTK_COMBO_BOX (combo), _("Odd sheets"));
+  gtk_combo_box_text_append_text (GTK_COMBO_BOX_TEXT (combo), _("All sheets"));
+  gtk_combo_box_text_append_text (GTK_COMBO_BOX_TEXT (combo), _("Even sheets"));
+  gtk_combo_box_text_append_text (GTK_COMBO_BOX_TEXT (combo), _("Odd sheets"));
   gtk_combo_box_set_active (GTK_COMBO_BOX (combo), 0);
 
   label = gtk_label_new_with_mnemonic (_("Sc_ale:"));
@@ -3398,7 +3405,7 @@ create_page_setup_page (GtkPrintUnixDialog *dialog)
                     0, 1, 4, 5,  GTK_FILL, 0,
                     0, 0);
 
-  hbox2 = gtk_hbox_new (FALSE, 6);
+  hbox2 = gtk_box_new (GTK_ORIENTATION_HORIZONTAL, 6);
   gtk_widget_show (hbox2);
   gtk_table_attach (GTK_TABLE (table), hbox2,
                     1, 2, 4, 5,  GTK_FILL, 0,
@@ -3500,32 +3507,32 @@ create_page_setup_page (GtkPrintUnixDialog *dialog)
                    0, 1, 4, 5,
                    GTK_FILL, 0, 0, 0);
 
-  combo = gtk_combo_box_new_text ();
+  combo = gtk_combo_box_text_new ();
   priv->orientation_combo = GTK_WIDGET (combo);
   gtk_table_attach (GTK_TABLE (table), combo,
                    1, 2, 4, 5,  GTK_FILL, 0,
                    0, 0);
   gtk_label_set_mnemonic_widget (GTK_LABEL (label), combo);
   /* In enum order */
-  gtk_combo_box_append_text (GTK_COMBO_BOX (combo), _("Portrait"));
-  gtk_combo_box_append_text (GTK_COMBO_BOX (combo), _("Landscape"));
-  gtk_combo_box_append_text (GTK_COMBO_BOX (combo), _("Reverse portrait"));
-  gtk_combo_box_append_text (GTK_COMBO_BOX (combo), _("Reverse landscape"));
+  gtk_combo_box_text_append_text (GTK_COMBO_BOX_TEXT (combo), _("Portrait"));
+  gtk_combo_box_text_append_text (GTK_COMBO_BOX_TEXT (combo), _("Landscape"));
+  gtk_combo_box_text_append_text (GTK_COMBO_BOX_TEXT (combo), _("Reverse portrait"));
+  gtk_combo_box_text_append_text (GTK_COMBO_BOX_TEXT (combo), _("Reverse landscape"));
   gtk_combo_box_set_active (GTK_COMBO_BOX (combo), 0);
   gtk_widget_set_sensitive (combo, FALSE);
   gtk_widget_show (combo);
 
 
   /* Add the page layout preview */
-  hbox2 = gtk_hbox_new (FALSE, 0);
+  hbox2 = gtk_box_new (GTK_ORIENTATION_HORIZONTAL, 0);
   gtk_widget_show (hbox2);
   gtk_box_pack_start (GTK_BOX (main_vbox), hbox2, TRUE, TRUE, 0);
 
   draw = gtk_drawing_area_new ();
   gtk_widget_set_has_window (draw, FALSE);
   priv->page_layout_preview = draw;
-  gtk_widget_set_size_request (draw, 350, 200);
-  g_signal_connect (draw, "expose-event", G_CALLBACK (draw_page_cb), dialog);
+  gtk_widget_set_size_request (draw, 280, 160);
+  g_signal_connect (draw, "draw", G_CALLBACK (draw_page_cb), dialog);
   gtk_widget_show (draw);
 
   gtk_box_pack_start (GTK_BOX (hbox2), draw, TRUE, FALSE, 0);
@@ -3767,7 +3774,7 @@ create_advanced_page (GtkPrintUnixDialog *dialog)
                                   GTK_POLICY_NEVER,
                                   GTK_POLICY_AUTOMATIC);
 
-  main_vbox = gtk_vbox_new (FALSE, 18);
+  main_vbox = gtk_box_new (GTK_ORIENTATION_VERTICAL, 18);
   gtk_container_set_border_width (GTK_CONTAINER (main_vbox), 12);
   gtk_widget_show (main_vbox);
 
@@ -3796,13 +3803,12 @@ populate_dialog (GtkPrintUnixDialog *print_dialog)
   content_area = gtk_dialog_get_content_area (dialog);
   action_area = gtk_dialog_get_action_area (dialog);
 
-  gtk_dialog_set_has_separator (dialog, FALSE);
   gtk_container_set_border_width (GTK_CONTAINER (dialog), 5);
   gtk_box_set_spacing (GTK_BOX (content_area), 2); /* 2 * 5 + 2 = 12 */
   gtk_container_set_border_width (GTK_CONTAINER (action_area), 5);
   gtk_box_set_spacing (GTK_BOX (action_area), 6);
 
-  vbox = gtk_vbox_new (FALSE, 6);
+  vbox = gtk_box_new (GTK_ORIENTATION_VERTICAL, 6);
   gtk_container_set_border_width (GTK_CONTAINER (vbox), 5);
   gtk_box_pack_start (GTK_BOX (content_area), vbox, TRUE, TRUE, 0);
   gtk_widget_show (vbox);
@@ -3831,7 +3837,7 @@ populate_dialog (GtkPrintUnixDialog *print_dialog)
                         &priv->finishing_page);
   create_advanced_page (print_dialog);
 
-  priv->conflicts_widget = conflict_hbox = gtk_hbox_new (FALSE, 12);
+  priv->conflicts_widget = conflict_hbox = gtk_box_new (GTK_ORIENTATION_HORIZONTAL, 12);
   gtk_box_pack_end (GTK_BOX (vbox), conflict_hbox, FALSE, FALSE, 0);
   image = gtk_image_new_from_stock (GTK_STOCK_DIALOG_WARNING, GTK_ICON_SIZE_MENU);
   gtk_widget_show (image);
@@ -3867,7 +3873,6 @@ gtk_print_unix_dialog_new (const gchar *title,
   result = g_object_new (GTK_TYPE_PRINT_UNIX_DIALOG,
                          "transient-for", parent,
                          "title", _title,
-                         "has-separator", FALSE,
                          NULL);
 
   return result;
@@ -3879,7 +3884,7 @@ gtk_print_unix_dialog_new (const gchar *title,
  *
  * Gets the currently selected printer.
  *
- * Returns: the currently selected printer
+ * Returns: (transfer none): the currently selected printer
  *
  * Since: 2.10
  */
@@ -3928,7 +3933,7 @@ gtk_print_unix_dialog_set_page_setup (GtkPrintUnixDialog *dialog,
  *
  * Gets the page setup that is used by the #GtkPrintUnixDialog.
  *
- * Returns: the page setup of @dialog.
+ * Returns: (transfer none): the page setup of @dialog.
  *
  * Since: 2.10
  */