[gtk+] printunixdialog: Use new drawing area API
- From: Benjamin Otte <otte src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [gtk+] printunixdialog: Use new drawing area API
- Date: Fri, 18 Nov 2016 05:42:22 +0000 (UTC)
commit dd6fb874436e028b55324c11a5be6e2b4398d748
Author: Benjamin Otte <otte redhat com>
Date: Fri Nov 18 06:32:27 2016 +0100
printunixdialog: Use new drawing area API
gtk/gtkprintunixdialog.c | 62 ++++++++++++++++++++++++-----------------
gtk/ui/gtkprintunixdialog.ui | 8 +++---
2 files changed, 40 insertions(+), 30 deletions(-)
---
diff --git a/gtk/gtkprintunixdialog.c b/gtk/gtkprintunixdialog.c
index f5f920e..3618e7b 100644
--- a/gtk/gtkprintunixdialog.c
+++ b/gtk/gtkprintunixdialog.c
@@ -164,9 +164,11 @@ static void update_print_at_entry_sensitivity (GtkWidget *button,
GtkPrintUnixDialog *dialog);
static void update_print_at_option (GtkPrintUnixDialog *dialog);
static void update_dialog_from_capabilities (GtkPrintUnixDialog *dialog);
-static gboolean draw_collate_cb (GtkWidget *widget,
+static void draw_collate (GtkDrawingArea *da,
cairo_t *cr,
- GtkPrintUnixDialog *dialog);
+ int width,
+ int height,
+ gpointer data);
static gboolean is_printer_active (GtkTreeModel *model,
GtkTreeIter *iter,
GtkPrintUnixDialog *dialog);
@@ -183,9 +185,11 @@ static void page_name_func (GtkCellLayout *cell_la
GtkTreeIter *iter,
gpointer data);
static void update_number_up_layout (GtkPrintUnixDialog *dialog);
-static gboolean draw_page_cb (GtkWidget *widget,
+static void draw_page (GtkDrawingArea *da,
cairo_t *cr,
- GtkPrintUnixDialog *dialog);
+ int width,
+ int height,
+ gpointer data);
static gboolean dialog_get_collate (GtkPrintUnixDialog *dialog);
@@ -552,11 +556,9 @@ gtk_print_unix_dialog_class_init (GtkPrintUnixDialogClass *class)
gtk_widget_class_bind_template_callback (widget_class, update_print_at_option);
gtk_widget_class_bind_template_callback (widget_class, update_dialog_from_capabilities);
gtk_widget_class_bind_template_callback (widget_class, update_collate_icon);
- gtk_widget_class_bind_template_callback (widget_class, draw_collate_cb);
gtk_widget_class_bind_template_callback (widget_class, redraw_page_layout_preview);
gtk_widget_class_bind_template_callback (widget_class, update_number_up_layout);
gtk_widget_class_bind_template_callback (widget_class, redraw_page_layout_preview);
- gtk_widget_class_bind_template_callback (widget_class, draw_page_cb);
gtk_widget_class_set_css_name (widget_class, "printdialog");
}
@@ -796,6 +798,13 @@ gtk_print_unix_dialog_init (GtkPrintUnixDialog *dialog)
/* Load custom papers */
_gtk_print_load_custom_papers (priv->custom_paper_list);
+ gtk_drawing_area_set_draw_func (GTK_DRAWING_AREA (priv->collate_image),
+ draw_collate,
+ dialog, NULL);
+ gtk_drawing_area_set_draw_func (GTK_DRAWING_AREA (priv->page_layout_preview),
+ draw_page,
+ dialog, NULL);
+
gtk_css_node_set_name (gtk_widget_get_css_node (priv->collate_image), I_("paper"));
gtk_css_node_set_name (gtk_widget_get_css_node (priv->page_layout_preview), I_("paper"));
}
@@ -2244,11 +2253,15 @@ paint_page (GtkWidget *widget,
cairo_show_text (cr, text);
}
-static gboolean
-draw_collate_cb (GtkWidget *widget,
- cairo_t *cr,
- GtkPrintUnixDialog *dialog)
-{
+static void
+draw_collate (GtkDrawingArea *da,
+ cairo_t *cr,
+ int width,
+ int height,
+ gpointer data)
+{
+ GtkPrintUnixDialog *dialog = GTK_PRINT_UNIX_DIALOG (data);
+ GtkWidget *widget = GTK_WIDGET (da);
gboolean collate, reverse, rtl;
gint copies;
gint text_x;
@@ -2258,10 +2271,10 @@ draw_collate_cb (GtkWidget *widget,
reverse = dialog_get_reverse (dialog);
copies = dialog_get_n_copies (dialog);
- rtl = (gtk_widget_get_direction (GTK_WIDGET (widget)) == GTK_TEXT_DIR_RTL);
+ rtl = (gtk_widget_get_direction (widget) == GTK_TEXT_DIR_RTL);
- x = (gtk_widget_get_allocated_width (widget) - 30) / 2;
- y = (gtk_widget_get_allocated_height (widget) - 36) / 2;
+ x = (width - 30) / 2;
+ y = (height - 36) / 2;
if (rtl)
{
x1 = x;
@@ -2292,8 +2305,6 @@ draw_collate_cb (GtkWidget *widget,
paint_page (widget, cr, x2 + p1, y, reverse ? "1" : "2", text_x);
paint_page (widget, cr, x2 + p2, y + 10, collate == reverse ? "2" : "1", text_x);
}
-
- return TRUE;
}
static void
@@ -2647,11 +2658,15 @@ dialog_get_number_up_layout (GtkPrintUnixDialog *dialog)
return layout;
}
-static gboolean
-draw_page_cb (GtkWidget *widget,
- cairo_t *cr,
- GtkPrintUnixDialog *dialog)
-{
+static void
+draw_page (GtkDrawingArea *da,
+ cairo_t *cr,
+ int width,
+ int height,
+ gpointer data)
+{
+ GtkWidget *widget = GTK_WIDGET (da);
+ GtkPrintUnixDialog *dialog = GTK_PRINT_UNIX_DIALOG (data);
GtkPrintUnixDialogPrivate *priv = dialog->priv;
GtkStyleContext *context;
gdouble ratio;
@@ -2667,7 +2682,6 @@ draw_page_cb (GtkWidget *widget,
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;
@@ -2681,8 +2695,6 @@ draw_page_cb (GtkWidget *widget,
(orientation == GTK_PAGE_ORIENTATION_REVERSE_LANDSCAPE);
number_up_layout = dialog_get_number_up_layout (dialog);
- width = gtk_widget_get_allocated_width (widget);
- height = gtk_widget_get_allocated_height (widget);
cairo_save (cr);
@@ -3050,8 +3062,6 @@ draw_page_cb (GtkWidget *widget,
cairo_line_to (cr, pos_x + w + 0.5, pos_y + h + shadow_offset + RULER_DISTANCE + RULER_RADIUS);
cairo_stroke (cr);
}
-
- return TRUE;
}
static void
diff --git a/gtk/ui/gtkprintunixdialog.ui b/gtk/ui/gtkprintunixdialog.ui
index a0e4235..091c187 100644
--- a/gtk/ui/gtkprintunixdialog.ui
+++ b/gtk/ui/gtkprintunixdialog.ui
@@ -383,8 +383,8 @@
</child>
<child>
<object class="GtkDrawingArea" id="collate_image">
- <property name="width-request">70</property>
- <property name="height-request">90</property>
+ <property name="content-width">70</property>
+ <property name="content-height">90</property>
<property name="visible">1</property>
<signal name="draw" handler="draw_collate_cb" swapped="no"/>
</object>
@@ -823,8 +823,8 @@
<property name="visible">1</property>
<child>
<object class="GtkDrawingArea" id="page_layout_preview">
- <property name="width-request">320</property>
- <property name="height-request">160</property>
+ <property name="content-width">320</property>
+ <property name="content-height">160</property>
<property name="visible">1</property>
<signal name="draw" handler="draw_page_cb" swapped="no"/>
</object>
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]