After an evaluation, GNOME has moved from Bugzilla to GitLab. Learn more about GitLab.
No new issues can be reported in GNOME Bugzilla anymore.
To report an issue in a GNOME project, go to GNOME GitLab.
Do not go to GNOME Gitlab for: Bluefish, Doxygen, GnuCash, GStreamer, java-gnome, LDTP, NetworkManager, Tomboy.
Bug 344519 - custom print ranges
custom print ranges
Status: RESOLVED FIXED
Product: gtk+
Classification: Platform
Component: Printing
unspecified
Other Linux
: Normal enhancement
: Medium API
Assigned To: gtk-bugs
gtk-bugs
: 439157 540590 (view as bug list)
Depends on:
Blocks: 457052
 
 
Reported: 2006-06-10 21:51 UTC by Christian Persch
Modified: 2015-02-18 00:28 UTC
See Also:
GNOME target: ---
GNOME version: Unversioned Enhancement


Attachments
Add ability to print selected pages (22.98 KB, patch)
2009-05-22 12:44 UTC, Marek Kašík
needs-work Details | Review
modified patch (17.55 KB, patch)
2009-05-26 11:19 UTC, Marek Kašík
needs-work Details | Review
newly modified patch (23.59 KB, patch)
2009-06-05 14:00 UTC, Marek Kašík
none Details | Review
modified patch (24.02 KB, patch)
2009-06-08 11:24 UTC, Marek Kašík
committed Details | Review

Description Christian Persch 2006-06-10 21:51:56 UTC
I'd like to have a way to add new print ranges to the print dialogue in addition to the stock ones (All,  Current, Range), and a way to hide some.
For example, in Epiphany, I'd like to add "Selection" and "Current frame", and remove "Current" which makes no sense there.
Comment 1 Carolyn_MacLeod 2006-07-05 21:37:49 UTC
Actually, I would use 'selection' range also.
Would be nice if GTK_PRINT_PAGES_SELECTION was one of the GtkPrintPages choices.
Comment 2 Matthias Clasen 2007-05-17 17:05:36 UTC
*** Bug 439157 has been marked as a duplicate of this bug. ***
Comment 3 Pacho Ramos 2008-02-23 11:18:05 UTC
What about this? Print selection is very useful :-/

Thanks a lot
Comment 4 Peter de Kraker 2008-06-27 12:52:18 UTC
I am very surprised this feature doesn't exist... we live in 2008..!

Everybody who uses printing, has the use for print selection, or am I crazy?

Please prioritize!
Comment 5 Matthias Clasen 2009-04-12 23:20:51 UTC
*** Bug 540590 has been marked as a duplicate of this bug. ***
Comment 6 Matthias Clasen 2009-05-07 06:06:54 UTC
At least the 'print selection' option should be relatively straightforward to add:

- add GTK_PRINT_PAGES_SELECTION to GtkPrintPages

- add gtk_print_unix_dialog_set_has_selection and gtk_print_operation_set_has_selection

- treat GTK_PRINT_PAGES_SELECTION like GTK_PRINT_PAGES_ALL in the loop-over-pages-to-print logic in GtkPrintOperation

Doing things this way would require apps to figure out how many pages the selection will format to, and use gtk_print_operation_set_n_pages in ::begin-print
Comment 7 Marek Kašík 2009-05-22 12:44:10 UTC
Created attachment 135172 [details] [review]
Add ability to print selected pages

Hi,

this patch adds ability to print selected pages. There is a new radio button under the "Current Page" radio button. This button is activated by gtk_print_operation_set_has_selection(operation, TRUE) function and the selection itself is filled by gtk_print_operation_set_selection(operation, ranges, num_ranges) in ::begin-print.

Marek
Comment 8 Matthias Clasen 2009-05-23 04:38:34 UTC
some comments:

1) I think the 'selection' choice should only be shown if the application supports it. It should be sensitive depending on whether there is a selection right now.

2) gtk_print_operation_set_selection seems to be a misunderstanding. In most cases, what the user can select will be an arbitrary fragment of a document, not a range of pages. Think about selecting a few lines in gedit, or a few paragraphs in a web page in a browser. I outlined above how I imagine apps to handle this (by calling gtk_print_operation_set_n_pages in ::begin-print).
Comment 9 Marek Kašík 2009-05-26 11:19:16 UTC
Created attachment 135379 [details] [review]
modified patch

Hi,

this is modified version of the previous patch. It demands user to call gtk_print_operation_set_support_selection() to show "Selection" radio button and gtk_print_operation_set_has_selection() to control its sensitivity. Number of pages to which the selection will be drawn has to be set by the gtk_print_operation_set_n_pages() function in callback of ::begin-print.

Marek
Comment 10 Matthias Clasen 2009-05-30 05:19:12 UTC
Looks basically ok now.

Some pedantic comments:


@@ -485,6 +485,7 @@ typedef enum
 {
   GTK_PRINT_PAGES_ALL,
   GTK_PRINT_PAGES_CURRENT,
+  GTK_PRINT_PAGES_SELECTION,
   GTK_PRINT_PAGES_RANGES
 } GtkPrintPages;
 

Please add the new value at the end of the enum, to not change the numeric value of GTK_PRINT_PAGES_RANGES.


+    case GTK_PRINT_PAGES_SELECTION:
+      return (page_nr >= 0) && (page_nr < priv->nr_of_pages);

Could just as well just add 

  case GTK_PRINT_PAGES_SELECTION:

before

  case GTK_PRINT_PAGES_ALL:

since both cases are identical.


Same here:

+  else if (priv->print_pages == GTK_PRINT_PAGES_SELECTION)
+    {
+      data->ranges = &data->one_range;
+      data->num_ranges = 1;
+      data->ranges[0].start = 0;
+      data->ranges[0].end = priv->nr_of_pages - 1;
+    }


 * @support_selection: TRUE to support selection

Please add markup: %TRUE (some more occurrences of this further down)


+ * will draw by gtk_print_operation_set_n_pages() in a callback of
+ * ::begin-print.

What I am doing for signals in the docs nowadays is: 
#GtkPrintOperation::begin-print. Then gtk-doc creates a nice link


Please add the new functions to docs/reference/gtk/gtk-sections.txt too.


One more thing: The new fields in GtkPrintUnixDialog should also be available as properties, including getters:

gtk_print_unix_dialog_get_support_selection
gtk_print_unix_dialog_get_has_selection

and boolean properties 

GtkPrintUnixDialog::support-selection
GtkPrintUnixDialog::has-selection

When you add the properties, don't forget to add change notification to the setters.


The same goes for capabilities, btw: there should be gtk_print_unix_dialog_get_manual_capabilities, and a
GtkPrintUnixDialog::manual-capabilities property (of type GtkPrintCapabilities)

Comment 11 Marek Kašík 2009-06-05 14:00:04 UTC
Created attachment 136024 [details] [review]
newly modified patch

Hi Matthias,

thank you for your comments, this patch is modification of the previous patch  according to those comments.

Marek
Comment 12 Matthias Clasen 2009-06-05 15:12:50 UTC
Looks good now. Two small remaining comments.

The original patch had this:

@@ -2476,6 +2480,13 @@ prepare_data (PrintPagesData *data)
             data->ranges[i].end >= priv->nr_of_pages)
           data->ranges[i].end = priv->nr_of_pages - 1;
     }
+  else if (priv->print_pages == GTK_PRINT_PAGES_SELECTION)
+    {
+      data->ranges = &data->one_range;
+      data->num_ranges = 1;
+      data->ranges[0].start = 0;
+      data->ranges[0].end = priv->nr_of_pages - 1;
+    }
   else if (priv->print_pages == GTK_PRINT_PAGES_CURRENT &&
    priv->current_page != -1)
     {


Is that not needed anymore, or did it get lost ?



Now that we have properties, the setters should do change notification. e.g

+void
+gtk_print_operation_set_has_selection (GtkPrintOperation  *op,
+                                       gboolean            has_selection)
+{
+  GtkPrintOperationPrivate *priv;
+
+  g_return_if_fail (GTK_IS_PRINT_OPERATION (op));
+
+  priv = op->priv;
+
+  priv->has_selection = has_selection;
+}


Should now do something like:

  has_selection = has_selection != FALSE;
  if (priv->selection != has_selection)
    {
      priv->selection = has_selection;
      g_object_notify (G_OBJECT (op), "has-selection");
    }

Comment 13 Marek Kašík 2009-06-05 15:46:08 UTC
This is not needed any more:

+  else if (priv->print_pages == GTK_PRINT_PAGES_SELECTION)
+    {
+      data->ranges = &data->one_range;
+      data->num_ranges = 1;
+      data->ranges[0].start = 0;
+      data->ranges[0].end = priv->nr_of_pages - 1;
+    }

GTK_PRINT_PAGES_SELECTION is handled in the same way as GTK_PRINT_PAGES_ALL now, which means that it is caught in the last "else" together with GTK_PRINT_PAGES_ALL.

The setters in the GtkPrintOperation don't do change notification because there aren't new properties in GtkPrintOperation. I added new properties to GtkPrintUnixDialog only (according to comment #10).
I'll add those properties to GtkPrintOperation as well.

One question.
What exactly do this line:
has_selection = has_selection != FALSE; ?

(is it some kind of conversion of bad integer values to correct values of gboolean (n (where n > 0) -> TRUE (1), 0 -> FALSE (0)) ?)

Marek
Comment 14 Matthias Clasen 2009-06-05 15:50:53 UTC
>The setters in the GtkPrintOperation don't do change notification because there
>aren't new properties in GtkPrintOperation. 

Ah, I had missed that, sorry.

> One question.
> What exactly do this line:
> has_selection = has_selection != FALSE; ?

Yeah, just a safe-guard, since C isn't very good about ensuring that booleans are only TRUE/FALSE. So when comparing them with ==, better be careful.
Comment 15 Marek Kašík 2009-06-08 11:24:37 UTC
Created attachment 136137 [details] [review]
modified patch

This patch adds properties "support-selection" and "has-selection" to the GtkPrintOperation.

Marek
Comment 16 Matthias Clasen 2009-06-08 13:21:45 UTC
thanks, looks good now.
Comment 17 Marek Kašík 2009-06-08 13:51:29 UTC
The patch is committed. Should I close this bug or leave it opened?

  Marek
Comment 18 Matthias Clasen 2009-06-08 14:08:34 UTC
Leave open, I'd say, for the more radical ideas about custom selections.
Comment 19 Matthias Clasen 2015-02-18 00:28:49 UTC
time to close it now, though