xed-print-preview.c: Clean up code styling

This commit is contained in:
JosephMcc 2017-01-07 01:14:21 -08:00
parent c2eab264a3
commit 663511c1d1
1 changed files with 805 additions and 844 deletions

View File

@ -161,9 +161,7 @@ update_layout_size (XedPrintPreview *preview)
priv = preview->priv;
/* force size of the drawing area to make the scrolled window work */
gtk_layout_set_size (GTK_LAYOUT (priv->layout),
priv->tile_w * priv->cols,
priv->tile_h * priv->rows);
gtk_layout_set_size (GTK_LAYOUT (priv->layout), priv->tile_w * priv->cols, priv->tile_h * priv->rows);
gtk_widget_queue_draw (preview->priv->layout);
}
@ -254,12 +252,8 @@ set_zoom_fit_to_size (XedPrintPreview *preview)
priv = preview->priv;
g_object_get (gtk_layout_get_hadjustment (GTK_LAYOUT (priv->layout)),
"page-size", &width,
NULL);
g_object_get (gtk_layout_get_vadjustment (GTK_LAYOUT (priv->layout)),
"page-size", &height,
NULL);
g_object_get (gtk_layout_get_hadjustment (GTK_LAYOUT (priv->layout)), "page-size", &width, NULL);
g_object_get (gtk_layout_get_vadjustment (GTK_LAYOUT (priv->layout)), "page-size", &height, NULL);
width /= priv->cols;
height /= priv->rows;
@ -301,27 +295,25 @@ set_zoom_fit_to_size (XedPrintPreview *preview)
static void
zoom_in (XedPrintPreview *preview)
{
set_zoom_factor (preview,
preview->priv->scale * ZOOM_IN_FACTOR);
set_zoom_factor (preview, preview->priv->scale * ZOOM_IN_FACTOR);
}
static void
zoom_out (XedPrintPreview *preview)
{
set_zoom_factor (preview,
preview->priv->scale * ZOOM_OUT_FACTOR);
set_zoom_factor (preview, preview->priv->scale * ZOOM_OUT_FACTOR);
}
static void
goto_page (XedPrintPreview *preview, gint page)
goto_page (XedPrintPreview *preview,
gint page)
{
gchar c[32];
g_snprintf (c, 32, "%d", page + 1);
gtk_entry_set_text (GTK_ENTRY (preview->priv->page_entry), c);
gtk_widget_set_sensitive (GTK_WIDGET (preview->priv->prev),
(page > 0) && (preview->priv->n_pages > 1));
gtk_widget_set_sensitive (GTK_WIDGET (preview->priv->prev), (page > 0) && (preview->priv->n_pages > 1));
gtk_widget_set_sensitive (GTK_WIDGET (preview->priv->next),
(page != (preview->priv->n_pages - 1)) &&
(preview->priv->n_pages > 1));
@ -330,8 +322,10 @@ goto_page (XedPrintPreview *preview, gint page)
{
preview->priv->cur_page = page;
if (preview->priv->n_pages > 0)
{
gtk_widget_queue_draw (preview->priv->layout);
}
}
}
static void
@ -344,9 +338,13 @@ prev_button_clicked (GtkWidget *button,
event = gtk_get_current_event ();
if (event->button.state & GDK_SHIFT_MASK)
{
page = 0;
}
else
{
page = preview->priv->cur_page - preview->priv->rows * preview->priv->cols;
}
goto_page (preview, MAX (page, 0));
@ -363,9 +361,13 @@ next_button_clicked (GtkWidget *button,
event = gtk_get_current_event ();
if (event->button.state & GDK_SHIFT_MASK)
{
page = preview->priv->n_pages - 1;
}
else
{
page = preview->priv->cur_page + preview->priv->rows * preview->priv->cols;
}
goto_page (preview, MIN (page, preview->priv->n_pages - 1));
@ -442,25 +444,29 @@ page_entry_focus_out (GtkWidget *widget,
}
static void
on_1x1_clicked (GtkMenuItem *i, XedPrintPreview *preview)
on_1x1_clicked (GtkMenuItem *i,
XedPrintPreview *preview)
{
set_rows_and_cols (preview, 1, 1);
}
static void
on_1x2_clicked (GtkMenuItem *i, XedPrintPreview *preview)
on_1x2_clicked (GtkMenuItem *i,
XedPrintPreview *preview)
{
set_rows_and_cols (preview, 1, 2);
}
static void
on_2x1_clicked (GtkMenuItem *i, XedPrintPreview *preview)
on_2x1_clicked (GtkMenuItem *i,
XedPrintPreview *preview)
{
set_rows_and_cols (preview, 2, 1);
}
static void
on_2x2_clicked (GtkMenuItem *i, XedPrintPreview *preview)
on_2x2_clicked (GtkMenuItem *i,
XedPrintPreview *preview)
{
set_rows_and_cols (preview, 2, 2);
}
@ -473,10 +479,8 @@ multi_button_clicked (GtkWidget *button,
m = gtk_menu_new ();
gtk_widget_show (m);
g_signal_connect (m,
"selection_done",
G_CALLBACK (gtk_widget_destroy),
m);
g_signal_connect (m, "selection_done",
G_CALLBACK (gtk_widget_destroy), m);
i = gtk_menu_item_new_with_label ("1x1");
gtk_widget_show (i);
@ -498,9 +502,7 @@ multi_button_clicked (GtkWidget *button,
gtk_menu_attach (GTK_MENU (m), i, 1, 2, 1, 2);
g_signal_connect (i, "activate", G_CALLBACK (on_2x2_clicked), preview);
gtk_menu_popup (GTK_MENU (m),
NULL, NULL, NULL, preview, 0,
GDK_CURRENT_TIME);
gtk_menu_popup (GTK_MENU (m), NULL, NULL, NULL, preview, 0, GDK_CURRENT_TIME);
}
static void
@ -550,35 +552,26 @@ create_bar (XedPrintPreview *preview)
priv = preview->priv;
toolbar = gtk_toolbar_new ();
gtk_toolbar_set_style (GTK_TOOLBAR (toolbar),
GTK_TOOLBAR_BOTH_HORIZ);
gtk_toolbar_set_style (GTK_TOOLBAR (toolbar), GTK_TOOLBAR_BOTH_HORIZ);
gtk_widget_show (toolbar);
gtk_box_pack_start (GTK_BOX (preview),
toolbar,
FALSE, FALSE, 0);
gtk_box_pack_start (GTK_BOX (preview), toolbar, FALSE, FALSE, 0);
priv->prev = gtk_tool_button_new_from_stock (GTK_STOCK_GO_BACK);
gtk_tool_button_set_label (GTK_TOOL_BUTTON (priv->prev),
"P_revious Page");
gtk_tool_button_set_label (GTK_TOOL_BUTTON (priv->prev), "P_revious Page");
gtk_tool_button_set_use_underline (GTK_TOOL_BUTTON (priv->prev), TRUE);
gtk_tool_item_set_tooltip_text (priv->prev, _("Show the previous page"));
gtk_toolbar_insert (GTK_TOOLBAR (toolbar), priv->prev, -1);
g_signal_connect (priv->prev,
"clicked",
G_CALLBACK (prev_button_clicked),
preview);
g_signal_connect (priv->prev, "clicked",
G_CALLBACK (prev_button_clicked), preview);
gtk_widget_show (GTK_WIDGET (priv->prev));
priv->next = gtk_tool_button_new_from_stock (GTK_STOCK_GO_FORWARD);
gtk_tool_button_set_label (GTK_TOOL_BUTTON (priv->next),
"_Next Page");
gtk_tool_button_set_label (GTK_TOOL_BUTTON (priv->next), "_Next Page");
gtk_tool_button_set_use_underline (GTK_TOOL_BUTTON (priv->next), TRUE);
gtk_tool_item_set_tooltip_text (priv->next, _("Show the next page"));
gtk_toolbar_insert (GTK_TOOLBAR (toolbar), priv->next, -1);
g_signal_connect (priv->next,
"clicked",
G_CALLBACK (next_button_clicked),
preview);
g_signal_connect (priv->next, "clicked",
G_CALLBACK (next_button_clicked), preview);
gtk_widget_show (GTK_WIDGET (priv->next));
i = gtk_separator_tool_item_new ();
@ -591,34 +584,22 @@ create_bar (XedPrintPreview *preview)
gtk_entry_set_max_length (GTK_ENTRY (priv->page_entry), 6);
gtk_widget_set_tooltip_text (priv->page_entry, _("Current page (Alt+P)"));
g_signal_connect (priv->page_entry,
"activate",
G_CALLBACK (page_entry_activated),
preview);
g_signal_connect (priv->page_entry,
"insert-text",
G_CALLBACK (page_entry_insert_text),
NULL);
g_signal_connect (priv->page_entry,
"focus-out-event",
G_CALLBACK (page_entry_focus_out),
preview);
g_signal_connect (priv->page_entry, "activate",
G_CALLBACK (page_entry_activated), preview);
g_signal_connect (priv->page_entry, "insert-text",
G_CALLBACK (page_entry_insert_text), NULL);
g_signal_connect (priv->page_entry, "focus-out-event",
G_CALLBACK (page_entry_focus_out), preview);
gtk_box_pack_start (GTK_BOX (status),
priv->page_entry,
FALSE, FALSE, 0);
gtk_box_pack_start (GTK_BOX (status), priv->page_entry, FALSE, FALSE, 0);
/* gtk_label_set_mnemonic_widget ((GtkLabel *) l, mp->priv->page_entry); */
/* We are displaying 'XXX of XXX'. */
gtk_box_pack_start (GTK_BOX (status),
/* Translators: the "of" from "1 of 19" in print preview. */
gtk_label_new (_("of")),
FALSE, FALSE, 0);
gtk_box_pack_start (GTK_BOX (status), gtk_label_new (_("of")), FALSE, FALSE, 0);
priv->last = gtk_label_new ("");
gtk_box_pack_start (GTK_BOX (status),
priv->last,
FALSE, FALSE, 0);
gtk_box_pack_start (GTK_BOX (status), priv->last, FALSE, FALSE, 0);
atko = gtk_widget_get_accessible (priv->last);
atk_object_set_name (atko, _("Page total"));
atk_object_set_description (atko, _("The total number of pages in the document"));
@ -635,15 +616,12 @@ create_bar (XedPrintPreview *preview)
gtk_toolbar_insert (GTK_TOOLBAR (toolbar), i, -1);
priv->multi = gtk_tool_button_new_from_stock (GTK_STOCK_DND_MULTIPLE);
gtk_tool_button_set_label (GTK_TOOL_BUTTON (priv->multi),
"_Show Multiple Pages");
gtk_tool_button_set_label (GTK_TOOL_BUTTON (priv->multi), "_Show Multiple Pages");
gtk_tool_button_set_use_underline (GTK_TOOL_BUTTON (priv->multi), TRUE);
gtk_tool_item_set_tooltip_text (priv->multi, _("Show multiple pages"));
gtk_toolbar_insert (GTK_TOOLBAR (toolbar), priv->multi, -1);
g_signal_connect (priv->multi,
"clicked",
G_CALLBACK (multi_button_clicked),
preview);
g_signal_connect (priv->multi, "clicked",
G_CALLBACK (multi_button_clicked), preview);
gtk_widget_show (GTK_WIDGET (priv->multi));
i = gtk_separator_tool_item_new ();
@ -653,37 +631,29 @@ create_bar (XedPrintPreview *preview)
priv->zoom_one = gtk_tool_button_new_from_stock (GTK_STOCK_ZOOM_100);
gtk_tool_item_set_tooltip_text (priv->zoom_one, _("Zoom 1:1"));
gtk_toolbar_insert (GTK_TOOLBAR (toolbar), priv->zoom_one, -1);
g_signal_connect (priv->zoom_one,
"clicked",
G_CALLBACK (zoom_one_button_clicked),
preview);
g_signal_connect (priv->zoom_one, "clicked",
G_CALLBACK (zoom_one_button_clicked), preview);
gtk_widget_show (GTK_WIDGET (priv->zoom_one));
priv->zoom_fit = gtk_tool_button_new_from_stock (GTK_STOCK_ZOOM_FIT);
gtk_tool_item_set_tooltip_text (priv->zoom_fit, _("Zoom to fit the whole page"));
gtk_toolbar_insert (GTK_TOOLBAR (toolbar), priv->zoom_fit, -1);
g_signal_connect (priv->zoom_fit,
"clicked",
G_CALLBACK (zoom_fit_button_clicked),
preview);
g_signal_connect (priv->zoom_fit, "clicked",
G_CALLBACK (zoom_fit_button_clicked), preview);
gtk_widget_show (GTK_WIDGET (priv->zoom_fit));
priv->zoom_in = gtk_tool_button_new_from_stock (GTK_STOCK_ZOOM_IN);
gtk_tool_item_set_tooltip_text (priv->zoom_in, _("Zoom the page in"));
gtk_toolbar_insert (GTK_TOOLBAR (toolbar), priv->zoom_in, -1);
g_signal_connect (priv->zoom_in,
"clicked",
G_CALLBACK (zoom_in_button_clicked),
preview);
g_signal_connect (priv->zoom_in, "clicked",
G_CALLBACK (zoom_in_button_clicked), preview);
gtk_widget_show (GTK_WIDGET (priv->zoom_in));
priv->zoom_out = gtk_tool_button_new_from_stock (GTK_STOCK_ZOOM_OUT);
gtk_tool_item_set_tooltip_text (priv->zoom_out, _("Zoom the page out"));
gtk_toolbar_insert (GTK_TOOLBAR (toolbar), priv->zoom_out, -1);
g_signal_connect (priv->zoom_out,
"clicked",
G_CALLBACK (zoom_out_button_clicked),
preview);
g_signal_connect (priv->zoom_out, "clicked",
G_CALLBACK (zoom_out_button_clicked), preview);
gtk_widget_show (GTK_WIDGET (priv->zoom_out));
i = gtk_separator_tool_item_new ();
@ -723,7 +693,9 @@ get_page_at_coords (XedPrintPreview *preview,
priv = preview->priv;
if (priv->tile_h <= 0 || priv->tile_h <= 0)
{
return -1;
}
hadj = gtk_layout_get_hadjustment (GTK_LAYOUT (priv->layout));
vadj = gtk_layout_get_vadjustment (GTK_LAYOUT (priv->layout));
@ -735,13 +707,17 @@ get_page_at_coords (XedPrintPreview *preview,
c = 1 + x / (priv->tile_w);
if (c > priv->cols)
{
return -1;
}
pg = get_first_page_displayed (preview) - 1;
pg += (r - 1) * priv->cols + c;
if (pg >= priv->n_pages)
{
return -1;
}
/* FIXME: we could try to be picky and check
* if we actually are inside the page */
@ -761,7 +737,9 @@ preview_layout_query_tooltip (GtkWidget *widget,
pg = get_page_at_coords (preview, x, y);
if (pg < 0)
{
return FALSE;
}
tip = g_strdup_printf (_("Page %d of %d"), pg + 1, preview->priv->n_pages);
gtk_tooltip_set_text (tooltip, tip);
@ -809,7 +787,8 @@ preview_layout_key_press (GtkWidget *widget,
hstep = 10;
vstep = 10;
switch (event->keyval) {
switch (event->keyval)
{
case '1':
set_zoom_fit_to_size (preview);
break;
@ -957,16 +936,12 @@ create_preview_layout (XedPrintPreview *preview)
gtk_widget_set_can_focus (priv->layout, TRUE);
g_signal_connect (priv->layout,
"key-press-event",
G_CALLBACK (preview_layout_key_press),
preview);
g_signal_connect (priv->layout, "key-press-event",
G_CALLBACK (preview_layout_key_press), preview);
g_object_set (priv->layout, "has-tooltip", TRUE, NULL);
g_signal_connect (priv->layout,
"query-tooltip",
G_CALLBACK (preview_layout_query_tooltip),
preview);
g_signal_connect (priv->layout, "query-tooltip",
G_CALLBACK (preview_layout_query_tooltip), preview);
priv->scrolled_window = gtk_scrolled_window_new (NULL, NULL);
gtk_scrolled_window_set_policy (GTK_SCROLLED_WINDOW (priv->scrolled_window),
@ -974,9 +949,7 @@ create_preview_layout (XedPrintPreview *preview)
GTK_POLICY_AUTOMATIC);
gtk_container_add (GTK_CONTAINER (priv->scrolled_window), priv->layout);
gtk_box_pack_end (GTK_BOX (preview),
priv->scrolled_window,
TRUE, TRUE, 0);
gtk_box_pack_end (GTK_BOX (preview), priv->scrolled_window, TRUE, TRUE, 0);
gtk_widget_show_all (GTK_WIDGET (priv->scrolled_window));
gtk_widget_grab_focus (GTK_WIDGET (priv->layout));
@ -987,9 +960,7 @@ xed_print_preview_init (XedPrintPreview *preview)
{
XedPrintPreviewPrivate *priv;
priv = G_TYPE_INSTANCE_GET_PRIVATE (preview,
XED_TYPE_PRINT_PREVIEW,
XedPrintPreviewPrivate);
priv = G_TYPE_INSTANCE_GET_PRIVATE (preview, XED_TYPE_PRINT_PREVIEW, XedPrintPreviewPrivate);
preview->priv = priv;
@ -997,8 +968,7 @@ xed_print_preview_init (XedPrintPreview *preview)
priv->context = NULL;
priv->gtk_preview = NULL;
gtk_orientable_set_orientation (GTK_ORIENTABLE (preview),
GTK_ORIENTATION_VERTICAL);
gtk_orientable_set_orientation (GTK_ORIENTABLE (preview), GTK_ORIENTATION_VERTICAL);
create_bar (preview);
create_preview_layout (preview);
@ -1039,8 +1009,7 @@ draw_page_content (cairo_t *cr,
preview->priv->dpi,
preview->priv->dpi);
gtk_print_operation_preview_render_page (preview->priv->gtk_preview,
page_number);
gtk_print_operation_preview_render_page (preview->priv->gtk_preview, page_number);
}
/* For the frame, we scale and rotate manually, since
@ -1071,16 +1040,12 @@ draw_page_frame (cairo_t *cr,
/* drop shadow */
cairo_set_source_rgb (cr, 0, 0, 0);
cairo_rectangle (cr,
PAGE_SHADOW_OFFSET, PAGE_SHADOW_OFFSET,
w, h);
cairo_rectangle (cr, PAGE_SHADOW_OFFSET, PAGE_SHADOW_OFFSET, w, h);
cairo_fill (cr);
/* page frame */
cairo_set_source_rgb (cr, 1, 1, 1);
cairo_rectangle (cr,
0, 0,
w, h);
cairo_rectangle (cr, 0, 0, w, h);
cairo_fill_preserve (cr);
cairo_set_source_rgb (cr, 0, 0, 0);
cairo_set_line_width (cr, 1);
@ -1120,7 +1085,9 @@ preview_draw (GtkWidget *widget,
bin_window = gtk_layout_get_bin_window (GTK_LAYOUT (priv->layout));
if (!gtk_cairo_should_draw_window (cr, bin_window))
{
return TRUE;
}
cairo_save (cr);
@ -1133,20 +1100,17 @@ preview_draw (GtkWidget *widget,
{
for (j = 0; j < priv->rows; ++j)
{
if (!gtk_print_operation_preview_is_selected (priv->gtk_preview,
pg))
if (!gtk_print_operation_preview_is_selected (priv->gtk_preview, pg))
{
continue;
}
if (pg == priv->n_pages)
{
break;
}
draw_page (cr,
j * priv->tile_w,
i * priv->tile_h,
pg,
preview);
draw_page (cr, j * priv->tile_w, i * priv->tile_h, pg, preview);
++pg;
}
@ -1207,10 +1171,8 @@ preview_ready (GtkPrintOperationPreview *gtk_preview,
set_zoom_factor (preview, 1.0);
/* let the default gtklayout handler clear the background */
g_signal_connect_after (preview->priv->layout,
"draw",
G_CALLBACK (preview_draw),
preview);
g_signal_connect_after (preview->priv->layout, "draw",
G_CALLBACK (preview_draw), preview);
gtk_widget_queue_draw (preview->priv->layout);
}
@ -1263,8 +1225,7 @@ create_preview_surface_platform (GtkPaperSize *paper_size,
*dpi_x = *dpi_y = PRINTER_DPI;
sf = cairo_pdf_surface_create_for_stream (dummy_write_func, NULL,
width, height);
sf = cairo_pdf_surface_create_for_stream (dummy_write_func, NULL, width, height);
return sf;
}