2
* This program is free software; you can redistribute it and/or modify it
3
* under the terms of the GNU General Public License as published by the Free
4
* Software Foundation; either version 2 of the License, or (at your option)
7
* This program is distributed in the hope that it will be useful, but WITHOUT
8
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
9
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
12
* You should have received a copy of the GNU General Public License along with
13
* this program; if not, write to the Free Software Foundation, Inc., 59 Temple
14
* Place, Suite 330, Boston, MA 02111-1307 USA
21
#include <pango/pango.h>
24
#include <mousepad/mousepad-private.h>
25
#include <mousepad/mousepad-preferences.h>
26
#include <mousepad/mousepad-document.h>
27
#include <mousepad/mousepad-util.h>
28
#include <mousepad/mousepad-print.h>
30
#define DOCUMENT_SPACING (10)
34
static void mousepad_print_finalize (GObject *object);
35
static void mousepad_print_settings_load (GtkPrintOperation *operation);
36
static void mousepad_print_settings_save_foreach (const gchar *key,
39
static void mousepad_print_settings_save (GtkPrintOperation *operation);
40
static void mousepad_print_begin_print (GtkPrintOperation *operation,
41
GtkPrintContext *context);
42
static void mousepad_print_draw_page (GtkPrintOperation *operation,
43
GtkPrintContext *context,
45
static void mousepad_print_page_setup_dialog (GtkWidget *button,
46
GtkPrintOperation *operation);
47
static void mousepad_print_button_toggled (GtkWidget *button,
48
MousepadPrint *print);
49
static void mousepad_print_button_font_set (GtkFontButton *button,
50
MousepadPrint *print);
51
static PangoAttrList *mousepad_print_attr_list_bold (void);
52
static GtkWidget *mousepad_print_create_custom_widget (GtkPrintOperation *operation);
53
static void mousepad_print_status_changed (GtkPrintOperation *operation);
54
static void mousepad_print_done (GtkPrintOperation *operation,
55
GtkPrintOperationResult result);
59
struct _MousepadPrintClass
61
GtkPrintOperationClass __parent__;
66
GtkPrintOperation __parent__;
68
/* the document we're going to print */
69
MousepadDocument *document;
71
/* print dialog widgets */
72
GtkWidget *widget_page_headers;
73
GtkWidget *widget_page_footers;
74
GtkWidget *widget_line_numbers;
75
GtkWidget *widget_text_wrapping;
76
GtkWidget *widget_syntax_highlighting;
77
GtkWidget *widget_header_font;
78
GtkWidget *widget_line_numbers_font;
79
GtkWidget *widget_body_font;
80
GtkWidget *widget_line_numbers_spin;
81
GtkWidget *widget_line_numbers_hbox;
84
gboolean print_line_numbers;
85
gint line_number_increment;
87
/* source view print compositor */
88
GtkSourcePrintCompositor *compositor;
93
G_DEFINE_TYPE (MousepadPrint, mousepad_print, GTK_TYPE_PRINT_OPERATION);
98
mousepad_print_class_init (MousepadPrintClass *klass)
100
GObjectClass *gobject_class;
101
GtkPrintOperationClass *gtkprintoperation_class;
103
gobject_class = G_OBJECT_CLASS (klass);
104
gobject_class->finalize = mousepad_print_finalize;
106
gtkprintoperation_class = GTK_PRINT_OPERATION_CLASS (klass);
107
gtkprintoperation_class->begin_print = mousepad_print_begin_print;
108
gtkprintoperation_class->draw_page = mousepad_print_draw_page;
109
gtkprintoperation_class->create_custom_widget = mousepad_print_create_custom_widget;
110
gtkprintoperation_class->status_changed = mousepad_print_status_changed;
111
gtkprintoperation_class->done = mousepad_print_done;
117
mousepad_print_init (MousepadPrint *print)
120
print->print_line_numbers = FALSE;
121
print->line_number_increment = 1;
122
print->compositor = NULL;
124
/* set a custom tab label */
125
gtk_print_operation_set_custom_tab_label (GTK_PRINT_OPERATION (print), _("Document Settings"));
131
mousepad_print_finalize (GObject *object)
133
MousepadPrint *print = MOUSEPAD_PRINT (object);
136
g_object_unref (print->compositor);
138
(*G_OBJECT_CLASS (mousepad_print_parent_class)->finalize) (object);
144
mousepad_print_settings_load (GtkPrintOperation *operation)
146
MousepadPrint *print = MOUSEPAD_PRINT (operation);
149
GtkPrintSettings *settings = NULL;
154
gchar *body_font = NULL;
155
gchar *header_font = NULL;
156
gchar *line_numbers_font = NULL;
157
GtkPageSetup *page_setup;
158
GtkPaperSize *paper_size;
159
PangoContext *context;
160
PangoFontDescription *font_desc;
162
mousepad_return_if_fail (MOUSEPAD_IS_DOCUMENT (print->document));
163
mousepad_return_if_fail (GTK_IS_WIDGET (print->document->textview));
165
/* get the config file filename */
166
filename = mousepad_util_get_save_location (MOUSEPAD_RC_RELPATH, FALSE);
167
if (G_UNLIKELY (filename == NULL))
170
/* create a new keyfile */
171
keyfile = g_key_file_new ();
173
if (G_LIKELY (g_key_file_load_from_file (keyfile, filename, G_KEY_FILE_NONE, NULL)))
175
/* get all the keys from the config file */
176
keys = g_key_file_get_keys (keyfile, "Print Settings", NULL, NULL);
180
/* create new settings object */
181
settings = gtk_print_settings_new ();
183
/* set all the keys */
184
for (i = 0; keys[i] != NULL; i++)
186
/* read the value from the config file */
187
value = g_key_file_get_value (keyfile, "Print Settings", keys[i], NULL);
190
if (G_LIKELY (value))
192
key = mousepad_util_key_name (keys[i]);
193
gtk_print_settings_set (settings, key, value);
204
/* free the key file */
205
g_key_file_free (keyfile);
210
if (G_LIKELY (settings))
212
/* apply the settings */
213
gtk_print_operation_set_print_settings (operation, settings);
215
if (gtk_print_settings_get_bool (settings, "page-setup-saved") == TRUE)
217
/* create new page setup */
218
page_setup = gtk_page_setup_new ();
220
/* set orientation */
221
gtk_page_setup_set_orientation (page_setup, gtk_print_settings_get_orientation (settings));
223
/* restore margins */
224
gtk_page_setup_set_top_margin (page_setup, gtk_print_settings_get_double (settings, "top-margin"), GTK_UNIT_MM);
225
gtk_page_setup_set_bottom_margin (page_setup, gtk_print_settings_get_double (settings, "bottom-margin"), GTK_UNIT_MM);
226
gtk_page_setup_set_right_margin (page_setup, gtk_print_settings_get_double (settings, "right-margin"), GTK_UNIT_MM);
227
gtk_page_setup_set_left_margin (page_setup, gtk_print_settings_get_double (settings, "left-margin"), GTK_UNIT_MM);
230
paper_size = gtk_print_settings_get_paper_size (settings);
231
if (G_LIKELY (paper_size))
232
gtk_page_setup_set_paper_size (page_setup, paper_size);
234
/* set the default page setup */
235
gtk_print_operation_set_default_page_setup (operation, page_setup);
237
/* release reference */
238
g_object_unref (G_OBJECT (page_setup));
241
/* restore print settings */
242
g_object_set (print->compositor,
244
gtk_print_settings_get_bool (settings, "print-header"),
245
"print-line-numbers",
246
gtk_print_settings_get_int (settings, "line-numbers-increment"),
248
gtk_print_settings_get_bool (settings, "text-wrapping") ? GTK_WRAP_WORD : GTK_WRAP_NONE,
250
gtk_print_settings_get_bool (settings, "highlight-syntax"),
253
print->print_line_numbers = gtk_print_settings_get_bool (settings, "print-line-numbers");
254
print->line_number_increment = gtk_print_settings_get_int (settings, "line-numbers-increment");
256
/* get the saved fonts, if set */
257
body_font = g_strdup (gtk_print_settings_get (settings, "body-font-name"));
258
header_font = g_strdup (gtk_print_settings_get (settings, "header-font-name"));
259
line_numbers_font = g_strdup (gtk_print_settings_get (settings, "line-numbers-font-name"));
261
/* release reference */
262
g_object_unref (G_OBJECT (settings));
265
/* if no font name is set, get the one used in the widget */
266
if (G_UNLIKELY (body_font == NULL))
268
/* get the font description from the context and convert it into a string */
269
context = gtk_widget_get_pango_context (GTK_WIDGET (print->document->textview));
270
font_desc = pango_context_get_font_description (context);
271
body_font = pango_font_description_to_string (font_desc);
274
/* set the restored body font or the one from the textview */
275
gtk_source_print_compositor_set_body_font_name (print->compositor, body_font);
277
/* if header font restored use it, otherwise use body font */
279
gtk_source_print_compositor_set_header_font_name (print->compositor, header_font);
281
gtk_source_print_compositor_set_header_font_name (print->compositor, body_font);
283
/* if line numbers font restored use it, otherwise use body font */
284
if (line_numbers_font)
285
gtk_source_print_compositor_set_line_numbers_font_name (print->compositor, line_numbers_font);
287
gtk_source_print_compositor_set_line_numbers_font_name (print->compositor, body_font);
291
g_free (header_font);
292
g_free (line_numbers_font);
298
mousepad_print_settings_save_foreach (const gchar *key,
302
GKeyFile *keyfile = user_data;
305
/* save the setting */
306
if (G_LIKELY (key && value))
308
config = mousepad_util_config_name (key);
309
g_key_file_set_value (keyfile, "Print Settings", config, value);
317
mousepad_print_settings_save (GtkPrintOperation *operation)
319
MousepadPrint *print = MOUSEPAD_PRINT (operation);
322
GtkPrintSettings *settings;
323
GtkPageSetup *page_setup;
324
GtkPaperSize *paper_size;
326
/* get the save location */
327
filename = mousepad_util_get_save_location (MOUSEPAD_RC_RELPATH, TRUE);
329
/* create a new keyfile */
330
keyfile = g_key_file_new ();
332
/* load the existing settings */
333
if (G_LIKELY (g_key_file_load_from_file (keyfile, filename, G_KEY_FILE_NONE, NULL)))
335
/* get the print settings */
336
settings = gtk_print_operation_get_print_settings (operation);
338
if (G_LIKELY (settings != NULL))
340
/* get the page setup */
341
page_setup = gtk_print_operation_get_default_page_setup (operation);
343
/* restore the page setup */
344
if (G_LIKELY (page_setup != NULL))
346
/* the the settings page orienation */
347
gtk_print_settings_set_orientation (settings, gtk_page_setup_get_orientation (page_setup));
350
gtk_print_settings_set_double (settings, "top-margin", gtk_page_setup_get_top_margin (page_setup, GTK_UNIT_MM));
351
gtk_print_settings_set_double (settings, "bottom-margin", gtk_page_setup_get_bottom_margin (page_setup, GTK_UNIT_MM));
352
gtk_print_settings_set_double (settings, "right-margin", gtk_page_setup_get_right_margin (page_setup, GTK_UNIT_MM));
353
gtk_print_settings_set_double (settings, "left-margin", gtk_page_setup_get_left_margin (page_setup, GTK_UNIT_MM));
355
/* get the paper size */
356
paper_size = gtk_page_setup_get_paper_size (page_setup);
358
/* set settings page size */
359
if (G_LIKELY (paper_size))
360
gtk_print_settings_set_paper_size (settings, paper_size);
363
/* a bool we use for loading */
364
gtk_print_settings_set_bool (settings, "page-setup-saved", page_setup != NULL);
366
/* set print settings */
367
gtk_print_settings_set_bool (settings,
369
gtk_source_print_compositor_get_print_header (print->compositor));
371
gtk_print_settings_set_bool (settings,
372
"print-line-numbers",
373
print->print_line_numbers);
375
gtk_print_settings_set_int (settings,
376
"line-numbers-increment",
377
print->line_number_increment);
379
gtk_print_settings_set_bool (settings,
381
gtk_source_print_compositor_get_wrap_mode (print->compositor) == GTK_WRAP_NONE ? FALSE : TRUE);
383
gtk_print_settings_set_bool (settings,
385
gtk_source_print_compositor_get_highlight_syntax (print->compositor));
387
gtk_print_settings_set (settings,
389
gtk_source_print_compositor_get_body_font_name (print->compositor));
391
gtk_print_settings_set (settings,
393
gtk_source_print_compositor_get_header_font_name (print->compositor));
395
gtk_print_settings_set (settings,
396
"line-numbers-font-name",
397
gtk_source_print_compositor_get_line_numbers_font_name (print->compositor));
399
/* store all the print settings */
400
gtk_print_settings_foreach (settings, mousepad_print_settings_save_foreach, keyfile);
402
/* save the contents */
403
mousepad_util_save_key_file (keyfile, filename);
408
g_key_file_free (keyfile);
415
mousepad_print_begin_print (GtkPrintOperation *operation,
416
GtkPrintContext *context)
418
MousepadPrint *print = MOUSEPAD_PRINT (operation);
419
MousepadDocument *document = print->document;
421
const gchar *file_name;
424
if (gtk_source_print_compositor_get_print_header (print->compositor))
426
if (mousepad_document_get_filename (document))
427
file_name = mousepad_document_get_filename (document);
429
file_name = mousepad_document_get_basename (document);
431
gtk_source_print_compositor_set_header_format (print->compositor,
438
/* paginate all of the pages at once */
439
while (!gtk_source_print_compositor_paginate (print->compositor, context))
442
n_pages = gtk_source_print_compositor_get_n_pages (print->compositor);
444
/* set the number of pages we're going to draw */
445
gtk_print_operation_set_n_pages (operation, n_pages);
451
mousepad_print_draw_page (GtkPrintOperation *operation,
452
GtkPrintContext *context,
455
MousepadPrint *print = MOUSEPAD_PRINT (operation);
457
gtk_source_print_compositor_draw_page (print->compositor, context, page_nr);
463
mousepad_print_page_setup_dialog (GtkWidget *button,
464
GtkPrintOperation *operation)
467
GtkPrintSettings *settings;
468
GtkPageSetup *page_setup;
470
/* get the toplevel of the button */
471
toplevel = gtk_widget_get_toplevel (button);
472
if (G_UNLIKELY (!gtk_widget_is_toplevel (toplevel)))
475
/* get the print settings */
476
settings = gtk_print_operation_get_print_settings (operation);
477
if (G_UNLIKELY (settings == NULL))
478
settings = gtk_print_settings_new ();
480
/* get the page setup */
481
page_setup = gtk_print_operation_get_default_page_setup (operation);
484
page_setup = gtk_print_run_page_setup_dialog (GTK_WINDOW (toplevel), page_setup, settings);
486
/* set the new page setup */
487
gtk_print_operation_set_default_page_setup (operation, page_setup);
493
mousepad_print_button_toggled (GtkWidget *button,
494
MousepadPrint *print)
496
gboolean active = gtk_toggle_button_get_active (GTK_TOGGLE_BUTTON (button));
498
/* save the correct setting */
499
if (button == print->widget_page_headers)
500
gtk_source_print_compositor_set_print_header (print->compositor, active);
501
else if (button == print->widget_line_numbers)
503
print->print_line_numbers = active;
504
gtk_widget_set_sensitive (print->widget_line_numbers_hbox, active);
506
else if (button == print->widget_text_wrapping)
507
gtk_source_print_compositor_set_wrap_mode (print->compositor, active ? GTK_WRAP_WORD : GTK_WRAP_NONE);
508
else if (button == print->widget_syntax_highlighting)
509
gtk_source_print_compositor_set_highlight_syntax (print->compositor, active);
515
mousepad_print_button_font_set (GtkFontButton *button,
516
MousepadPrint *print)
519
GtkWidget *widget = GTK_WIDGET (button);
521
font = gtk_font_button_get_font_name (button);
523
if (widget == print->widget_body_font)
524
gtk_source_print_compositor_set_body_font_name (print->compositor, font);
525
else if (widget == print->widget_header_font)
526
gtk_source_print_compositor_set_header_font_name (print->compositor, font);
527
else if (widget == print->widget_line_numbers_font)
528
gtk_source_print_compositor_set_line_numbers_font_name (print->compositor, font);
534
mousepad_print_spin_value_changed (GtkSpinButton *button,
535
MousepadPrint *print)
537
print->line_number_increment = gtk_spin_button_get_value_as_int (button);
539
if (print->line_number_increment > 0 && print->print_line_numbers)
541
gtk_source_print_compositor_set_print_line_numbers (print->compositor,
542
print->line_number_increment);
545
gtk_source_print_compositor_set_print_line_numbers (print->compositor, 0);
550
static PangoAttrList *
551
mousepad_print_attr_list_bold (void)
553
static PangoAttrList *attr_list = NULL;
554
PangoAttribute *attr;
556
if (G_UNLIKELY (attr_list == NULL))
558
/* create new attributes list */
559
attr_list = pango_attr_list_new ();
561
/* create attribute */
562
attr = pango_attr_weight_new (PANGO_WEIGHT_BOLD);
563
attr->start_index = 0;
564
attr->end_index = -1;
566
/* insert bold element */
567
pango_attr_list_insert (attr_list, attr);
576
mousepad_print_create_custom_widget (GtkPrintOperation *operation)
578
MousepadPrint *print = MOUSEPAD_PRINT (operation);
580
GtkWidget *vbox, *vbox2;
582
GtkWidget *alignment;
585
GtkAdjustment *adjustment;
587
vbox = gtk_vbox_new (FALSE, 6);
588
gtk_container_set_border_width (GTK_CONTAINER (vbox), 8);
590
frame = gtk_frame_new (NULL);
591
gtk_frame_set_shadow_type (GTK_FRAME (frame), GTK_SHADOW_NONE);
592
gtk_box_pack_start (GTK_BOX (vbox), frame, FALSE, FALSE, 0);
593
gtk_widget_show (frame);
595
label = gtk_label_new (_("Page Setup"));
596
gtk_label_set_attributes (GTK_LABEL (label), mousepad_print_attr_list_bold ());
597
gtk_frame_set_label_widget (GTK_FRAME (frame), label);
598
gtk_widget_show (label);
600
alignment = gtk_alignment_new (0.0, 0.5, 0.0, 1.0);
601
gtk_alignment_set_padding (GTK_ALIGNMENT (alignment), 6, 6, 12, 6);
602
gtk_container_add (GTK_CONTAINER (frame), alignment);
603
gtk_widget_show (alignment);
605
button = mousepad_util_image_button (GTK_STOCK_PROPERTIES, _("_Adjust page size and orientation"));
606
g_signal_connect (G_OBJECT (button), "clicked", G_CALLBACK (mousepad_print_page_setup_dialog), operation);
607
gtk_container_add (GTK_CONTAINER (alignment), button);
608
gtk_widget_show (button);
610
frame = gtk_frame_new (NULL);
611
gtk_frame_set_shadow_type (GTK_FRAME (frame), GTK_SHADOW_NONE);
612
gtk_box_pack_start (GTK_BOX (vbox), frame, FALSE, FALSE, 0);
613
gtk_widget_show (frame);
615
label = gtk_label_new (_("Appearance"));
616
gtk_label_set_attributes (GTK_LABEL (label), mousepad_print_attr_list_bold ());
617
gtk_frame_set_label_widget (GTK_FRAME (frame), label);
618
gtk_widget_show (label);
620
alignment = gtk_alignment_new (0.5, 0.5, 1.0, 1.0);
621
gtk_alignment_set_padding (GTK_ALIGNMENT (alignment), 6, 6, 12, 6);
622
gtk_container_add (GTK_CONTAINER (frame), alignment);
623
gtk_widget_show (alignment);
625
vbox2 = gtk_vbox_new (FALSE, 6);
626
gtk_container_add (GTK_CONTAINER (alignment), vbox2);
627
gtk_widget_show (vbox2);
629
button = print->widget_page_headers = gtk_check_button_new_with_mnemonic (_("Print page _headers"));
630
gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON (button),
631
gtk_source_print_compositor_get_print_header (print->compositor));
632
g_signal_connect (G_OBJECT (button), "toggled", G_CALLBACK (mousepad_print_button_toggled), print);
633
gtk_box_pack_start (GTK_BOX (vbox2), button, FALSE, FALSE, 0);
634
gtk_widget_show (button);
636
button = print->widget_line_numbers = gtk_check_button_new_with_mnemonic (_("Print _line numbers"));
637
gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON (button),
638
print->print_line_numbers);
639
g_signal_connect (G_OBJECT (button), "toggled", G_CALLBACK (mousepad_print_button_toggled), print);
640
gtk_box_pack_start (GTK_BOX (vbox2), button, FALSE, FALSE, 0);
641
gtk_widget_show (button);
643
alignment = gtk_alignment_new (0.0, 0.5, 0.0, 1.0);
644
gtk_alignment_set_padding (GTK_ALIGNMENT (alignment), 0, 0, 24, 0);
645
gtk_box_pack_start (GTK_BOX (vbox2), alignment, FALSE, FALSE, 0);
646
gtk_widget_show (alignment);
648
print->widget_line_numbers_hbox = gtk_hbox_new (FALSE, 6);
649
gtk_widget_set_sensitive (print->widget_line_numbers_hbox, print->print_line_numbers);
650
gtk_container_add (GTK_CONTAINER (alignment), print->widget_line_numbers_hbox);
651
gtk_widget_show (print->widget_line_numbers_hbox);
653
label = gtk_label_new (_("Number every"));
654
gtk_misc_set_alignment (GTK_MISC (label), 0.0, 0.5);
655
gtk_box_pack_start (GTK_BOX (print->widget_line_numbers_hbox), label, FALSE, TRUE, 0);
656
gtk_widget_show (label);
658
adjustment = GTK_ADJUSTMENT (gtk_adjustment_new (1.0, 1.0, 100.0, 1.0, 0.0, 0.0));
659
print->widget_line_numbers_spin = gtk_spin_button_new (adjustment, 1.0, 0);
660
gtk_spin_button_set_value (GTK_SPIN_BUTTON (print->widget_line_numbers_spin),
661
(gdouble) print->line_number_increment);
662
g_signal_connect (G_OBJECT (print->widget_line_numbers_spin),
664
G_CALLBACK (mousepad_print_spin_value_changed),
666
gtk_box_pack_start (GTK_BOX (print->widget_line_numbers_hbox), print->widget_line_numbers_spin, FALSE, TRUE, 0);
667
gtk_widget_show (print->widget_line_numbers_spin);
669
label = gtk_label_new (_("line(s)"));
670
gtk_misc_set_alignment (GTK_MISC (label), 0.0, 0.5);
671
gtk_box_pack_start (GTK_BOX (print->widget_line_numbers_hbox), label, FALSE, TRUE, 0);
672
gtk_widget_show (label);
674
button = print->widget_text_wrapping = gtk_check_button_new_with_mnemonic (_("Enable text _wrapping"));
675
gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON (button),
676
gtk_source_print_compositor_get_wrap_mode (print->compositor) == GTK_WRAP_NONE ? FALSE : TRUE);
677
g_signal_connect (G_OBJECT (button), "toggled", G_CALLBACK (mousepad_print_button_toggled), print);
678
gtk_box_pack_start (GTK_BOX (vbox2), button, FALSE, FALSE, 0);
679
gtk_widget_show (button);
681
button = print->widget_syntax_highlighting = gtk_check_button_new_with_mnemonic (_("Enable _syntax highlighting"));
682
gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON (button),
683
gtk_source_print_compositor_get_highlight_syntax (print->compositor));
684
g_signal_connect (G_OBJECT (button), "toggled", G_CALLBACK (mousepad_print_button_toggled), print);
685
gtk_box_pack_start (GTK_BOX (vbox2), button, FALSE, FALSE, 0);
686
gtk_widget_show (button);
688
frame = gtk_frame_new (NULL);
689
gtk_frame_set_shadow_type (GTK_FRAME (frame), GTK_SHADOW_NONE);
690
gtk_box_pack_start (GTK_BOX (vbox), frame, FALSE, FALSE, 0);
691
gtk_widget_show (frame);
693
label = gtk_label_new (_("Fonts"));
694
gtk_label_set_attributes (GTK_LABEL (label), mousepad_print_attr_list_bold ());
695
gtk_frame_set_label_widget (GTK_FRAME (frame), label);
696
gtk_widget_show (label);
698
alignment = gtk_alignment_new (0.0, 0.5, 0.0, 1.0);
699
gtk_alignment_set_padding (GTK_ALIGNMENT (alignment), 6, 6, 12, 6);
700
gtk_container_add (GTK_CONTAINER (frame), alignment);
701
gtk_widget_show (alignment);
703
table = gtk_table_new (3, 2, FALSE);
704
gtk_table_set_col_spacings (GTK_TABLE (table), 6);
705
gtk_table_set_row_spacings (GTK_TABLE (table), 6);
706
gtk_container_add (GTK_CONTAINER (alignment), table);
707
gtk_widget_show (table);
709
label = gtk_label_new (_("Header:"));
710
gtk_misc_set_alignment (GTK_MISC (label), 0.0, 0.5);
711
gtk_table_attach_defaults (GTK_TABLE (table), label, 0, 1, 0, 1);
712
gtk_widget_show (label);
714
print->widget_header_font = gtk_font_button_new_with_font (gtk_source_print_compositor_get_header_font_name (print->compositor));
715
gtk_table_attach_defaults (GTK_TABLE (table), print->widget_header_font, 1, 2, 0, 1);
716
g_signal_connect (G_OBJECT (print->widget_header_font), "font-set", G_CALLBACK (mousepad_print_button_font_set), print);
717
gtk_widget_show (print->widget_header_font);
719
label = gtk_label_new (_("Body:"));
720
gtk_misc_set_alignment (GTK_MISC (label), 0.0, 0.5);
721
gtk_table_attach_defaults (GTK_TABLE (table), label, 0, 1, 1, 2);
722
gtk_widget_show (label);
724
print->widget_body_font = gtk_font_button_new_with_font (gtk_source_print_compositor_get_body_font_name (print->compositor));
725
gtk_table_attach_defaults (GTK_TABLE (table), print->widget_body_font, 1, 2, 1, 2);
726
g_signal_connect (G_OBJECT (print->widget_body_font), "font-set", G_CALLBACK (mousepad_print_button_font_set), print);
727
gtk_widget_show (print->widget_body_font);
729
label = gtk_label_new (_("Line numbers:"));
730
gtk_misc_set_alignment (GTK_MISC (label), 0.0, 0.5);
731
gtk_table_attach_defaults (GTK_TABLE (table), label, 0, 1, 2, 3);
732
gtk_widget_show (label);
734
print->widget_line_numbers_font = gtk_font_button_new_with_font (gtk_source_print_compositor_get_line_numbers_font_name (print->compositor));
735
gtk_table_attach_defaults (GTK_TABLE (table), print->widget_line_numbers_font, 1, 2, 2, 3);
736
g_signal_connect (G_OBJECT (print->widget_line_numbers_font), "font-set", G_CALLBACK (mousepad_print_button_font_set), print);
737
gtk_widget_show (print->widget_line_numbers_font);
745
mousepad_print_status_changed (GtkPrintOperation *operation)
747
/* nothing usefull for now, we could set a statusbar text or something */
753
mousepad_print_done (GtkPrintOperation *operation,
754
GtkPrintOperationResult result)
756
/* check if the print succeeded */
757
if (result == GTK_PRINT_OPERATION_RESULT_APPLY)
759
/* save the settings */
760
mousepad_print_settings_save (operation);
767
mousepad_print_new (void)
769
return g_object_new (MOUSEPAD_TYPE_PRINT, NULL);
775
mousepad_print_document_interactive (MousepadPrint *print,
776
MousepadDocument *document,
780
GtkPrintOperationResult result;
782
mousepad_return_val_if_fail (MOUSEPAD_IS_PRINT (print), FALSE);
783
mousepad_return_val_if_fail (GTK_IS_PRINT_OPERATION (print), FALSE);
784
mousepad_return_val_if_fail (MOUSEPAD_IS_DOCUMENT (document), FALSE);
785
mousepad_return_val_if_fail (GTK_IS_SOURCE_BUFFER (document->buffer), FALSE);
786
mousepad_return_val_if_fail (GTK_IS_WINDOW (parent), FALSE);
787
mousepad_return_val_if_fail (error == NULL || *error == NULL, FALSE);
789
/* set the document */
790
print->document = document;
791
print->compositor = gtk_source_print_compositor_new (GTK_SOURCE_BUFFER (document->buffer));
794
mousepad_print_settings_load (GTK_PRINT_OPERATION (print));
796
/* allow async printing is support by the platform */
797
gtk_print_operation_set_allow_async (GTK_PRINT_OPERATION (print), TRUE);
799
/* run the operation */
800
result = gtk_print_operation_run (GTK_PRINT_OPERATION (print),
801
GTK_PRINT_OPERATION_ACTION_PRINT_DIALOG,
804
return (result != GTK_PRINT_OPERATION_RESULT_ERROR);