diff options
author | Linus Torvalds <torvalds@linux-foundation.org> | 2012-08-30 09:30:59 -0700 |
---|---|---|
committer | Linus Torvalds <torvalds@linux-foundation.org> | 2012-08-30 09:30:59 -0700 |
commit | 6a210e573d947d61172da0363cbd7832e5459323 (patch) | |
tree | cc63839a182a7f3a110387b64eadd2edb7d5da0f | |
parent | 348afc3f576f3ad3cf3ad78b2f037cd5d6c73445 (diff) | |
download | subsurface-6a210e573d947d61172da0363cbd7832e5459323.tar.gz |
Add support for printing only the selected dives
Right now we just implicitly decide "print only selected dives" when
there is more than one dive selected (and then print all dives if only
one dive is selected).
We probably should have an checkbutton in the dive details page for the
choice. But I wanted to avoid the pain that is gtk as far as possible
for the initial implementation. The code is ready to be changed to just
use a checkbutton instead.
Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
-rw-r--r-- | display.h | 1 | ||||
-rw-r--r-- | print.c | 52 |
2 files changed, 43 insertions, 10 deletions
@@ -28,6 +28,7 @@ extern void attach_tooltip(int x, int y, int w, int h, const char *text); struct options { enum { PRETTY, TABLE } type; + int print_selected; }; extern char zoomed_plot; @@ -13,6 +13,23 @@ static struct options print_options; +/* Return the 'i'th dive for printing, taking our dive selection into account */ +static struct dive *get_dive_for_printing(int idx) +{ + if (print_options.print_selected) { + int i; + struct dive *dive; + for_each_dive(i, dive) { + if (!dive->selected) + continue; + if (!idx) + return dive; + idx--; + } + return NULL; + } + return get_dive(idx); +} static void set_font(PangoLayout *layout, PangoFontDescription *font, double size, int align) @@ -21,7 +38,6 @@ static void set_font(PangoLayout *layout, PangoFontDescription *font, pango_layout_set_font_description(layout, font); pango_layout_set_ellipsize(layout, PANGO_ELLIPSIZE_END); pango_layout_set_alignment(layout, align); - } /* @@ -283,7 +299,7 @@ static void print(int divenr, cairo_t *cr, double x, double y, double w, { struct dive *dive; - dive = get_dive(divenr); + dive = get_dive_for_printing(divenr); if (!dive) return; cairo_save(cr); @@ -330,7 +346,7 @@ static void print_table(int divenr, cairo_t *cr, double x, double y, { struct dive *dive; - dive = get_dive(divenr); + dive = get_dive_for_printing(divenr); if (!dive) return; cairo_save(cr); @@ -380,7 +396,7 @@ static void draw_table(GtkPrintOperation *operation, gint page_nr, gpointer user_data) { - int nr; + int i, nr; int n_dive_per_page = 25; cairo_t *cr; double w, h; @@ -394,7 +410,6 @@ static void draw_table(GtkPrintOperation *operation, nr = page_nr*n_dive_per_page; print_table_header(cr, 0, 0+h, w, h, font); - int i; for (i = 0; i < n_dive_per_page; i++) { print_table(nr+i, cr, 0, h*1.5+h*i, w, h, font); } @@ -402,17 +417,34 @@ static void draw_table(GtkPrintOperation *operation, pango_font_description_free(font); } +static int nr_selected_dives(void) +{ + int i, dives; + struct dive *dive; + + dives = 0; + for_each_dive(i, dive) + dives += dive->selected; + return dives; +} + static void begin_print(GtkPrintOperation *operation, gpointer user_data) { - int dives_per_page = 1; + int pages, dives; + int dives_per_page; + + dives = nr_selected_dives(); + print_options.print_selected = dives > 1; + if (dives <= 1) + dives = dive_table.nr; + if (print_options.type == PRETTY) { - dives_per_page = 6; + dives_per_page = 6; } else { dives_per_page = 25; } - int pages; - pages = (dive_table.nr + dives_per_page - 1) / dives_per_page; - gtk_print_operation_set_n_pages(operation, pages); + pages = (dives + dives_per_page - 1) / dives_per_page; + gtk_print_operation_set_n_pages(operation, pages); } |