This repository has been archived by the owner on Nov 17, 2020. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
/
gtkprintoperation.c
3281 lines (2849 loc) · 94.5 KB
/
gtkprintoperation.c
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
/* GTK - The GIMP Toolkit
* gtkprintoperation.c: Print Operation
* Copyright (C) 2006, Red Hat, Inc.
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
* License as published by the Free Software Foundation; either
* version 2 of the License, or (at your option) any later version.
*
* This library is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
* License along with this library; if not, write to the
* Free Software Foundation, Inc., 59 Temple Place - Suite 330,
* Boston, MA 02111-1307, USA.
*/
#include "config.h"
#include <errno.h>
#include <stdlib.h>
#include <math.h>
#include <string.h>
#include "gtkprintoperation-private.h"
#include "gtkmarshalers.h"
#include <cairo-pdf.h>
#include "gtkintl.h"
#include "gtkprivate.h"
#include "gtkmessagedialog.h"
#include "gtkalias.h"
#define SHOW_PROGRESS_TIME 1200
#define GTK_PRINT_OPERATION_GET_PRIVATE(obj)(G_TYPE_INSTANCE_GET_PRIVATE ((obj), GTK_TYPE_PRINT_OPERATION, GtkPrintOperationPrivate))
enum
{
DONE,
BEGIN_PRINT,
PAGINATE,
REQUEST_PAGE_SETUP,
DRAW_PAGE,
END_PRINT,
STATUS_CHANGED,
CREATE_CUSTOM_WIDGET,
CUSTOM_WIDGET_APPLY,
PREVIEW,
UPDATE_CUSTOM_WIDGET,
LAST_SIGNAL
};
enum
{
PROP_0,
PROP_DEFAULT_PAGE_SETUP,
PROP_PRINT_SETTINGS,
PROP_JOB_NAME,
PROP_N_PAGES,
PROP_CURRENT_PAGE,
PROP_USE_FULL_PAGE,
PROP_TRACK_PRINT_STATUS,
PROP_UNIT,
PROP_SHOW_PROGRESS,
PROP_ALLOW_ASYNC,
PROP_EXPORT_FILENAME,
PROP_STATUS,
PROP_STATUS_STRING,
PROP_CUSTOM_TAB_LABEL,
PROP_EMBED_PAGE_SETUP,
PROP_HAS_SELECTION,
PROP_SUPPORT_SELECTION,
PROP_N_PAGES_TO_PRINT
};
static guint signals[LAST_SIGNAL] = { 0 };
static int job_nr = 0;
typedef struct _PrintPagesData PrintPagesData;
static void preview_iface_init (GtkPrintOperationPreviewIface *iface);
static GtkPageSetup *create_page_setup (GtkPrintOperation *op);
static void common_render_page (GtkPrintOperation *op,
gint page_nr);
static void increment_page_sequence (PrintPagesData *data);
static void prepare_data (PrintPagesData *data);
static void clamp_page_ranges (PrintPagesData *data);
G_DEFINE_TYPE_WITH_CODE (GtkPrintOperation, gtk_print_operation, G_TYPE_OBJECT,
G_IMPLEMENT_INTERFACE (GTK_TYPE_PRINT_OPERATION_PREVIEW,
preview_iface_init))
/**
* gtk_print_error_quark:
*
* Registers an error quark for #GtkPrintOperation if necessary.
*
* Return value: The error quark used for #GtkPrintOperation errors.
*
* Since: 2.10
**/
GQuark
gtk_print_error_quark (void)
{
static GQuark quark = 0;
if (quark == 0)
quark = g_quark_from_static_string ("gtk-print-error-quark");
return quark;
}
static void
gtk_print_operation_finalize (GObject *object)
{
GtkPrintOperation *print_operation = GTK_PRINT_OPERATION (object);
GtkPrintOperationPrivate *priv = print_operation->priv;
if (priv->free_platform_data &&
priv->platform_data)
{
priv->free_platform_data (priv->platform_data);
priv->free_platform_data = NULL;
}
if (priv->default_page_setup)
g_object_unref (priv->default_page_setup);
if (priv->print_settings)
g_object_unref (priv->print_settings);
if (priv->print_context)
g_object_unref (priv->print_context);
g_free (priv->export_filename);
g_free (priv->job_name);
g_free (priv->custom_tab_label);
g_free (priv->status_string);
if (priv->print_pages_idle_id > 0)
g_source_remove (priv->print_pages_idle_id);
if (priv->show_progress_timeout_id > 0)
g_source_remove (priv->show_progress_timeout_id);
if (priv->error)
g_error_free (priv->error);
G_OBJECT_CLASS (gtk_print_operation_parent_class)->finalize (object);
}
static void
gtk_print_operation_init (GtkPrintOperation *operation)
{
GtkPrintOperationPrivate *priv;
const char *appname;
priv = operation->priv = GTK_PRINT_OPERATION_GET_PRIVATE (operation);
priv->status = GTK_PRINT_STATUS_INITIAL;
priv->status_string = g_strdup ("");
priv->default_page_setup = NULL;
priv->print_settings = NULL;
priv->nr_of_pages = -1;
priv->nr_of_pages_to_print = -1;
priv->page_position = -1;
priv->current_page = -1;
priv->use_full_page = FALSE;
priv->show_progress = FALSE;
priv->export_filename = NULL;
priv->track_print_status = FALSE;
priv->is_sync = FALSE;
priv->support_selection = FALSE;
priv->has_selection = FALSE;
priv->embed_page_setup = FALSE;
priv->page_drawing_state = GTK_PAGE_DRAWING_STATE_READY;
priv->rloop = NULL;
priv->unit = GTK_UNIT_PIXEL;
appname = g_get_application_name ();
if (appname == NULL)
appname = "";
/* translators: this string is the default job title for print
* jobs. %s gets replaced by the application name, %d gets replaced
* by the job number.
*/
priv->job_name = g_strdup_printf (_("%s job #%d"), appname, ++job_nr);
}
static void
preview_iface_render_page (GtkPrintOperationPreview *preview,
gint page_nr)
{
GtkPrintOperation *op;
op = GTK_PRINT_OPERATION (preview);
common_render_page (op, page_nr);
}
static void
preview_iface_end_preview (GtkPrintOperationPreview *preview)
{
GtkPrintOperation *op;
op = GTK_PRINT_OPERATION (preview);
g_signal_emit (op, signals[END_PRINT], 0, op->priv->print_context);
if (op->priv->rloop)
g_main_loop_quit (op->priv->rloop);
if (op->priv->end_run)
op->priv->end_run (op, op->priv->is_sync, TRUE);
_gtk_print_operation_set_status (op, GTK_PRINT_STATUS_FINISHED, NULL);
g_signal_emit (op, signals[DONE], 0, GTK_PRINT_OPERATION_RESULT_APPLY);
}
static gboolean
preview_iface_is_selected (GtkPrintOperationPreview *preview,
gint page_nr)
{
GtkPrintOperation *op;
GtkPrintOperationPrivate *priv;
int i;
op = GTK_PRINT_OPERATION (preview);
priv = op->priv;
switch (priv->print_pages)
{
case GTK_PRINT_PAGES_SELECTION:
case GTK_PRINT_PAGES_ALL:
return (page_nr >= 0) && (page_nr < priv->nr_of_pages);
case GTK_PRINT_PAGES_CURRENT:
return page_nr == priv->current_page;
case GTK_PRINT_PAGES_RANGES:
for (i = 0; i < priv->num_page_ranges; i++)
{
if (page_nr >= priv->page_ranges[i].start &&
(page_nr <= priv->page_ranges[i].end || priv->page_ranges[i].end == -1))
return TRUE;
}
return FALSE;
}
return FALSE;
}
static void
preview_iface_init (GtkPrintOperationPreviewIface *iface)
{
iface->render_page = preview_iface_render_page;
iface->end_preview = preview_iface_end_preview;
iface->is_selected = preview_iface_is_selected;
}
static void
preview_start_page (GtkPrintOperation *op,
GtkPrintContext *print_context,
GtkPageSetup *page_setup)
{
if ((op->priv->manual_number_up < 2) ||
(op->priv->page_position % op->priv->manual_number_up == 0))
g_signal_emit_by_name (op, "got-page-size", print_context, page_setup);
}
static void
preview_end_page (GtkPrintOperation *op,
GtkPrintContext *print_context)
{
cairo_t *cr;
cr = gtk_print_context_get_cairo_context (print_context);
if ((op->priv->manual_number_up < 2) ||
((op->priv->page_position + 1) % op->priv->manual_number_up == 0) ||
(op->priv->page_position == op->priv->nr_of_pages_to_print - 1))
cairo_show_page (cr);
}
static void
preview_end_run (GtkPrintOperation *op,
gboolean wait,
gboolean cancelled)
{
g_free (op->priv->page_ranges);
op->priv->page_ranges = NULL;
}
static void
gtk_print_operation_set_property (GObject *object,
guint prop_id,
const GValue *value,
GParamSpec *pspec)
{
GtkPrintOperation *op = GTK_PRINT_OPERATION (object);
switch (prop_id)
{
case PROP_DEFAULT_PAGE_SETUP:
gtk_print_operation_set_default_page_setup (op, g_value_get_object (value));
break;
case PROP_PRINT_SETTINGS:
gtk_print_operation_set_print_settings (op, g_value_get_object (value));
break;
case PROP_JOB_NAME:
gtk_print_operation_set_job_name (op, g_value_get_string (value));
break;
case PROP_N_PAGES:
gtk_print_operation_set_n_pages (op, g_value_get_int (value));
break;
case PROP_CURRENT_PAGE:
gtk_print_operation_set_current_page (op, g_value_get_int (value));
break;
case PROP_USE_FULL_PAGE:
gtk_print_operation_set_use_full_page (op, g_value_get_boolean (value));
break;
case PROP_TRACK_PRINT_STATUS:
gtk_print_operation_set_track_print_status (op, g_value_get_boolean (value));
break;
case PROP_UNIT:
gtk_print_operation_set_unit (op, g_value_get_enum (value));
break;
case PROP_ALLOW_ASYNC:
gtk_print_operation_set_allow_async (op, g_value_get_boolean (value));
break;
case PROP_SHOW_PROGRESS:
gtk_print_operation_set_show_progress (op, g_value_get_boolean (value));
break;
case PROP_EXPORT_FILENAME:
gtk_print_operation_set_export_filename (op, g_value_get_string (value));
break;
case PROP_CUSTOM_TAB_LABEL:
gtk_print_operation_set_custom_tab_label (op, g_value_get_string (value));
break;
case PROP_EMBED_PAGE_SETUP:
gtk_print_operation_set_embed_page_setup (op, g_value_get_boolean (value));
break;
case PROP_HAS_SELECTION:
gtk_print_operation_set_has_selection (op, g_value_get_boolean (value));
break;
case PROP_SUPPORT_SELECTION:
gtk_print_operation_set_support_selection (op, g_value_get_boolean (value));
break;
default:
G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
break;
}
}
static void
gtk_print_operation_get_property (GObject *object,
guint prop_id,
GValue *value,
GParamSpec *pspec)
{
GtkPrintOperation *op = GTK_PRINT_OPERATION (object);
GtkPrintOperationPrivate *priv = op->priv;
switch (prop_id)
{
case PROP_DEFAULT_PAGE_SETUP:
g_value_set_object (value, priv->default_page_setup);
break;
case PROP_PRINT_SETTINGS:
g_value_set_object (value, priv->print_settings);
break;
case PROP_JOB_NAME:
g_value_set_string (value, priv->job_name);
break;
case PROP_N_PAGES:
g_value_set_int (value, priv->nr_of_pages);
break;
case PROP_CURRENT_PAGE:
g_value_set_int (value, priv->current_page);
break;
case PROP_USE_FULL_PAGE:
g_value_set_boolean (value, priv->use_full_page);
break;
case PROP_TRACK_PRINT_STATUS:
g_value_set_boolean (value, priv->track_print_status);
break;
case PROP_UNIT:
g_value_set_enum (value, priv->unit);
break;
case PROP_ALLOW_ASYNC:
g_value_set_boolean (value, priv->allow_async);
break;
case PROP_SHOW_PROGRESS:
g_value_set_boolean (value, priv->show_progress);
break;
case PROP_EXPORT_FILENAME:
g_value_set_string (value, priv->export_filename);
break;
case PROP_STATUS:
g_value_set_enum (value, priv->status);
break;
case PROP_STATUS_STRING:
g_value_set_string (value, priv->status_string);
break;
case PROP_CUSTOM_TAB_LABEL:
g_value_set_string (value, priv->custom_tab_label);
break;
case PROP_EMBED_PAGE_SETUP:
g_value_set_boolean (value, priv->embed_page_setup);
break;
case PROP_HAS_SELECTION:
g_value_set_boolean (value, priv->has_selection);
break;
case PROP_SUPPORT_SELECTION:
g_value_set_boolean (value, priv->support_selection);
break;
case PROP_N_PAGES_TO_PRINT:
g_value_set_int (value, priv->nr_of_pages_to_print);
break;
default:
G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
break;
}
}
struct _PrintPagesData
{
GtkPrintOperation *op;
gint uncollated_copies;
gint collated_copies;
gint uncollated, collated, total;
gint range, num_ranges;
GtkPageRange *ranges;
GtkPageRange one_range;
gint page;
gint sheet;
gint first_position, last_position;
gint first_sheet;
gint num_of_sheets;
gint *pages;
GtkWidget *progress;
gboolean initialized;
gboolean is_preview;
gboolean done;
};
typedef struct
{
GtkPrintOperationPreview *preview;
GtkPrintContext *print_context;
GtkWindow *parent;
cairo_surface_t *surface;
gchar *filename;
gboolean wait;
PrintPagesData *pages_data;
} PreviewOp;
static void
preview_print_idle_done (gpointer data)
{
GtkPrintOperation *op;
PreviewOp *pop = (PreviewOp *) data;
op = GTK_PRINT_OPERATION (pop->preview);
cairo_surface_finish (pop->surface);
/* Surface is destroyed in launch_preview */
_gtk_print_operation_platform_backend_launch_preview (op,
pop->surface,
pop->parent,
pop->filename);
g_free (pop->filename);
gtk_print_operation_preview_end_preview (pop->preview);
g_object_unref (pop->pages_data->op);
g_free (pop->pages_data->pages);
g_free (pop->pages_data);
g_object_unref (op);
g_free (pop);
}
static gboolean
preview_print_idle (gpointer data)
{
PreviewOp *pop;
GtkPrintOperation *op;
GtkPrintOperationPrivate *priv;
gboolean done = FALSE;
pop = (PreviewOp *) data;
op = GTK_PRINT_OPERATION (pop->preview);
priv = op->priv;
if (priv->page_drawing_state == GTK_PAGE_DRAWING_STATE_READY)
{
if (!pop->pages_data->initialized)
{
pop->pages_data->initialized = TRUE;
prepare_data (pop->pages_data);
}
else
{
increment_page_sequence (pop->pages_data);
if (!pop->pages_data->done)
gtk_print_operation_preview_render_page (pop->preview, pop->pages_data->page);
else
done = priv->page_drawing_state == GTK_PAGE_DRAWING_STATE_READY;
}
}
return !done;
}
static void
preview_got_page_size (GtkPrintOperationPreview *preview,
GtkPrintContext *context,
GtkPageSetup *page_setup,
PreviewOp *pop)
{
GtkPrintOperation *op = GTK_PRINT_OPERATION (preview);
cairo_t *cr;
_gtk_print_operation_platform_backend_resize_preview_surface (op, page_setup, pop->surface);
cr = gtk_print_context_get_cairo_context (pop->print_context);
_gtk_print_operation_platform_backend_preview_start_page (op, pop->surface, cr);
}
static void
preview_ready (GtkPrintOperationPreview *preview,
GtkPrintContext *context,
PreviewOp *pop)
{
pop->print_context = context;
g_object_ref (preview);
gdk_threads_add_idle_full (G_PRIORITY_DEFAULT_IDLE + 10,
preview_print_idle,
pop,
preview_print_idle_done);
}
static gboolean
gtk_print_operation_preview_handler (GtkPrintOperation *op,
GtkPrintOperationPreview *preview,
GtkPrintContext *context,
GtkWindow *parent)
{
gdouble dpi_x, dpi_y;
PreviewOp *pop;
GtkPageSetup *page_setup;
cairo_t *cr;
pop = g_new0 (PreviewOp, 1);
pop->filename = NULL;
pop->preview = preview;
pop->parent = parent;
pop->pages_data = g_new0 (PrintPagesData, 1);
pop->pages_data->op = g_object_ref (GTK_PRINT_OPERATION (preview));
pop->pages_data->is_preview = TRUE;
page_setup = gtk_print_context_get_page_setup (context);
pop->surface =
_gtk_print_operation_platform_backend_create_preview_surface (op,
page_setup,
&dpi_x, &dpi_y,
&pop->filename);
if (pop->surface == NULL)
{
g_free (pop);
return FALSE;
}
cr = cairo_create (pop->surface);
gtk_print_context_set_cairo_context (op->priv->print_context, cr,
dpi_x, dpi_y);
cairo_destroy (cr);
g_signal_connect (preview, "ready", (GCallback) preview_ready, pop);
g_signal_connect (preview, "got-page-size", (GCallback) preview_got_page_size, pop);
return TRUE;
}
static GtkWidget *
gtk_print_operation_create_custom_widget (GtkPrintOperation *operation)
{
return NULL;
}
static void
gtk_print_operation_done (GtkPrintOperation *operation,
GtkPrintOperationResult result)
{
GtkPrintOperationPrivate *priv = operation->priv;
if (priv->print_context)
{
g_object_unref (priv->print_context);
priv->print_context = NULL;
}
}
static gboolean
custom_widget_accumulator (GSignalInvocationHint *ihint,
GValue *return_accu,
const GValue *handler_return,
gpointer dummy)
{
gboolean continue_emission;
GtkWidget *widget;
widget = g_value_get_object (handler_return);
if (widget != NULL)
g_value_set_object (return_accu, widget);
continue_emission = (widget == NULL);
return continue_emission;
}
static void
gtk_print_operation_class_init (GtkPrintOperationClass *class)
{
GObjectClass *gobject_class = (GObjectClass *)class;
gobject_class->set_property = gtk_print_operation_set_property;
gobject_class->get_property = gtk_print_operation_get_property;
gobject_class->finalize = gtk_print_operation_finalize;
class->preview = gtk_print_operation_preview_handler;
class->create_custom_widget = gtk_print_operation_create_custom_widget;
class->done = gtk_print_operation_done;
g_type_class_add_private (gobject_class, sizeof (GtkPrintOperationPrivate));
/**
* GtkPrintOperation::done:
* @operation: the #GtkPrintOperation on which the signal was emitted
* @result: the result of the print operation
*
* Emitted when the print operation run has finished doing
* everything required for printing.
*
* @result gives you information about what happened during the run.
* If @result is %GTK_PRINT_OPERATION_RESULT_ERROR then you can call
* gtk_print_operation_get_error() for more information.
*
* If you enabled print status tracking then
* gtk_print_operation_is_finished() may still return %FALSE
* after #GtkPrintOperation::done was emitted.
*
* Since: 2.10
*/
signals[DONE] =
g_signal_new (I_("done"),
G_TYPE_FROM_CLASS (gobject_class),
G_SIGNAL_RUN_LAST,
G_STRUCT_OFFSET (GtkPrintOperationClass, done),
NULL, NULL,
g_cclosure_marshal_VOID__ENUM,
G_TYPE_NONE, 1, GTK_TYPE_PRINT_OPERATION_RESULT);
/**
* GtkPrintOperation::begin-print:
* @operation: the #GtkPrintOperation on which the signal was emitted
* @context: the #GtkPrintContext for the current operation
*
* Emitted after the user has finished changing print settings
* in the dialog, before the actual rendering starts.
*
* A typical use for ::begin-print is to use the parameters from the
* #GtkPrintContext and paginate the document accordingly, and then
* set the number of pages with gtk_print_operation_set_n_pages().
*
* Since: 2.10
*/
signals[BEGIN_PRINT] =
g_signal_new (I_("begin-print"),
G_TYPE_FROM_CLASS (gobject_class),
G_SIGNAL_RUN_LAST,
G_STRUCT_OFFSET (GtkPrintOperationClass, begin_print),
NULL, NULL,
g_cclosure_marshal_VOID__OBJECT,
G_TYPE_NONE, 1, GTK_TYPE_PRINT_CONTEXT);
/**
* GtkPrintOperation::paginate:
* @operation: the #GtkPrintOperation on which the signal was emitted
* @context: the #GtkPrintContext for the current operation
*
* Emitted after the #GtkPrintOperation::begin-print signal, but before
* the actual rendering starts. It keeps getting emitted until a connected
* signal handler returns %TRUE.
*
* The ::paginate signal is intended to be used for paginating a document
* in small chunks, to avoid blocking the user interface for a long
* time. The signal handler should update the number of pages using
* gtk_print_operation_set_n_pages(), and return %TRUE if the document
* has been completely paginated.
*
* If you don't need to do pagination in chunks, you can simply do
* it all in the ::begin-print handler, and set the number of pages
* from there.
*
* Return value: %TRUE if pagination is complete
*
* Since: 2.10
*/
signals[PAGINATE] =
g_signal_new (I_("paginate"),
G_TYPE_FROM_CLASS (gobject_class),
G_SIGNAL_RUN_LAST,
G_STRUCT_OFFSET (GtkPrintOperationClass, paginate),
_gtk_boolean_handled_accumulator, NULL,
_gtk_marshal_BOOLEAN__OBJECT,
G_TYPE_BOOLEAN, 1, GTK_TYPE_PRINT_CONTEXT);
/**
* GtkPrintOperation::request-page-setup:
* @operation: the #GtkPrintOperation on which the signal was emitted
* @context: the #GtkPrintContext for the current operation
* @page_nr: the number of the currently printed page (0-based)
* @setup: the #GtkPageSetup
*
* Emitted once for every page that is printed, to give
* the application a chance to modify the page setup. Any changes
* done to @setup will be in force only for printing this page.
*
* Since: 2.10
*/
signals[REQUEST_PAGE_SETUP] =
g_signal_new (I_("request-page-setup"),
G_TYPE_FROM_CLASS (gobject_class),
G_SIGNAL_RUN_LAST,
G_STRUCT_OFFSET (GtkPrintOperationClass, request_page_setup),
NULL, NULL,
_gtk_marshal_VOID__OBJECT_INT_OBJECT,
G_TYPE_NONE, 3,
GTK_TYPE_PRINT_CONTEXT,
G_TYPE_INT,
GTK_TYPE_PAGE_SETUP);
/**
* GtkPrintOperation::draw-page:
* @operation: the #GtkPrintOperation on which the signal was emitted
* @context: the #GtkPrintContext for the current operation
* @page_nr: the number of the currently printed page (0-based)
*
* Emitted for every page that is printed. The signal handler
* must render the @page_nr's page onto the cairo context obtained
* from @context using gtk_print_context_get_cairo_context().
* |[
* static void
* draw_page (GtkPrintOperation *operation,
* GtkPrintContext *context,
* gint page_nr,
* gpointer user_data)
* {
* cairo_t *cr;
* PangoLayout *layout;
* gdouble width, text_height;
* gint layout_height;
* PangoFontDescription *desc;
*
* cr = gtk_print_context_get_cairo_context (context);
* width = gtk_print_context_get_width (context);
*
* cairo_rectangle (cr, 0, 0, width, HEADER_HEIGHT);
*
* cairo_set_source_rgb (cr, 0.8, 0.8, 0.8);
* cairo_fill (cr);
*
* layout = gtk_print_context_create_pango_layout (context);
*
* desc = pango_font_description_from_string ("sans 14");
* pango_layout_set_font_description (layout, desc);
* pango_font_description_free (desc);
*
* pango_layout_set_text (layout, "some text", -1);
* pango_layout_set_width (layout, width * PANGO_SCALE);
* pango_layout_set_alignment (layout, PANGO_ALIGN_CENTER);
*
* pango_layout_get_size (layout, NULL, &layout_height);
* text_height = (gdouble)layout_height / PANGO_SCALE;
*
* cairo_move_to (cr, width / 2, (HEADER_HEIGHT - text_height) / 2);
* pango_cairo_show_layout (cr, layout);
*
* g_object_unref (layout);
* }
* ]|
*
* Use gtk_print_operation_set_use_full_page() and
* gtk_print_operation_set_unit() before starting the print operation
* to set up the transformation of the cairo context according to your
* needs.
*
* Since: 2.10
*/
signals[DRAW_PAGE] =
g_signal_new (I_("draw-page"),
G_TYPE_FROM_CLASS (gobject_class),
G_SIGNAL_RUN_LAST,
G_STRUCT_OFFSET (GtkPrintOperationClass, draw_page),
NULL, NULL,
_gtk_marshal_VOID__OBJECT_INT,
G_TYPE_NONE, 2,
GTK_TYPE_PRINT_CONTEXT,
G_TYPE_INT);
/**
* GtkPrintOperation::end-print:
* @operation: the #GtkPrintOperation on which the signal was emitted
* @context: the #GtkPrintContext for the current operation
*
* Emitted after all pages have been rendered.
* A handler for this signal can clean up any resources that have
* been allocated in the #GtkPrintOperation::begin-print handler.
*
* Since: 2.10
*/
signals[END_PRINT] =
g_signal_new (I_("end-print"),
G_TYPE_FROM_CLASS (gobject_class),
G_SIGNAL_RUN_LAST,
G_STRUCT_OFFSET (GtkPrintOperationClass, end_print),
NULL, NULL,
g_cclosure_marshal_VOID__OBJECT,
G_TYPE_NONE, 1, GTK_TYPE_PRINT_CONTEXT);
/**
* GtkPrintOperation::status-changed:
* @operation: the #GtkPrintOperation on which the signal was emitted
*
* Emitted at between the various phases of the print operation.
* See #GtkPrintStatus for the phases that are being discriminated.
* Use gtk_print_operation_get_status() to find out the current
* status.
*
* Since: 2.10
*/
signals[STATUS_CHANGED] =
g_signal_new (I_("status-changed"),
G_TYPE_FROM_CLASS (class),
G_SIGNAL_RUN_LAST,
G_STRUCT_OFFSET (GtkPrintOperationClass, status_changed),
NULL, NULL,
g_cclosure_marshal_VOID__VOID,
G_TYPE_NONE, 0);
/**
* GtkPrintOperation::create-custom-widget:
* @operation: the #GtkPrintOperation on which the signal was emitted
*
* Emitted when displaying the print dialog. If you return a
* widget in a handler for this signal it will be added to a custom
* tab in the print dialog. You typically return a container widget
* with multiple widgets in it.
*
* The print dialog owns the returned widget, and its lifetime is not
* controlled by the application. However, the widget is guaranteed
* to stay around until the #GtkPrintOperation::custom-widget-apply
* signal is emitted on the operation. Then you can read out any
* information you need from the widgets.
*
* Returns: (transfer none): A custom widget that gets embedded in
* the print dialog, or %NULL
*
* Since: 2.10
*/
signals[CREATE_CUSTOM_WIDGET] =
g_signal_new (I_("create-custom-widget"),
G_TYPE_FROM_CLASS (class),
G_SIGNAL_RUN_LAST,
G_STRUCT_OFFSET (GtkPrintOperationClass, create_custom_widget),
custom_widget_accumulator, NULL,
_gtk_marshal_OBJECT__VOID,
G_TYPE_OBJECT, 0);
/**
* GtkPrintOperation::update-custom-widget:
* @operation: the #GtkPrintOperation on which the signal was emitted
* @widget: the custom widget added in create-custom-widget
* @setup: actual page setup
* @settings: actual print settings
*
* Emitted after change of selected printer. The actual page setup and
* print settings are passed to the custom widget, which can actualize
* itself according to this change.
*
* Since: 2.18
*/
signals[UPDATE_CUSTOM_WIDGET] =
g_signal_new (I_("update-custom-widget"),
G_TYPE_FROM_CLASS (class),
G_SIGNAL_RUN_LAST,
G_STRUCT_OFFSET (GtkPrintOperationClass, update_custom_widget),
NULL, NULL,
_gtk_marshal_VOID__OBJECT_OBJECT_OBJECT,
G_TYPE_NONE, 3, GTK_TYPE_WIDGET, GTK_TYPE_PAGE_SETUP, GTK_TYPE_PRINT_SETTINGS);
/**
* GtkPrintOperation::custom-widget-apply:
* @operation: the #GtkPrintOperation on which the signal was emitted
* @widget: the custom widget added in create-custom-widget
*
* Emitted right before #GtkPrintOperation::begin-print if you added
* a custom widget in the #GtkPrintOperation::create-custom-widget handler.
* When you get this signal you should read the information from the
* custom widgets, as the widgets are not guaraneed to be around at a
* later time.
*
* Since: 2.10
*/
signals[CUSTOM_WIDGET_APPLY] =
g_signal_new (I_("custom-widget-apply"),
G_TYPE_FROM_CLASS (class),
G_SIGNAL_RUN_LAST,
G_STRUCT_OFFSET (GtkPrintOperationClass, custom_widget_apply),
NULL, NULL,
g_cclosure_marshal_VOID__OBJECT,
G_TYPE_NONE, 1, GTK_TYPE_WIDGET);
/**
* GtkPrintOperation::preview:
* @operation: the #GtkPrintOperation on which the signal was emitted
* @preview: the #GtkPrintPreviewOperation for the current operation
* @context: the #GtkPrintContext that will be used
* @parent: (allow-none): the #GtkWindow to use as window parent, or %NULL
*
* Gets emitted when a preview is requested from the native dialog.
*
* The default handler for this signal uses an external viewer
* application to preview.
*
* To implement a custom print preview, an application must return
* %TRUE from its handler for this signal. In order to use the
* provided @context for the preview implementation, it must be
* given a suitable cairo context with gtk_print_context_set_cairo_context().
*
* The custom preview implementation can use
* gtk_print_operation_preview_is_selected() and
* gtk_print_operation_preview_render_page() to find pages which
* are selected for print and render them. The preview must be
* finished by calling gtk_print_operation_preview_end_preview()
* (typically in response to the user clicking a close button).
*
* Returns: %TRUE if the listener wants to take over control of the preview
*
* Since: 2.10
*/
signals[PREVIEW] =
g_signal_new (I_("preview"),
G_TYPE_FROM_CLASS (gobject_class),
G_SIGNAL_RUN_LAST,
G_STRUCT_OFFSET (GtkPrintOperationClass, preview),
_gtk_boolean_handled_accumulator, NULL,
_gtk_marshal_BOOLEAN__OBJECT_OBJECT_OBJECT,
G_TYPE_BOOLEAN, 3,
GTK_TYPE_PRINT_OPERATION_PREVIEW,
GTK_TYPE_PRINT_CONTEXT,
GTK_TYPE_WINDOW);
/**
* GtkPrintOperation:default-page-setup:
*
* The #GtkPageSetup used by default.
*
* This page setup will be used by gtk_print_operation_run(),
* but it can be overridden on a per-page basis by connecting
* to the #GtkPrintOperation::request-page-setup signal.
*
* Since: 2.10
*/
g_object_class_install_property (gobject_class,
PROP_DEFAULT_PAGE_SETUP,
g_param_spec_object ("default-page-setup",
P_("Default Page Setup"),
P_("The GtkPageSetup used by default"),
GTK_TYPE_PAGE_SETUP,
GTK_PARAM_READWRITE));