2 * This program is free software; you can redistribute it and/or modify
3 * it under the terms of the GNU General Public License as published by
4 * the Free Software Foundation; either version 2 of the License, or
5 * (at your option) any later version.
7 * This program is distributed in the hope that it will be useful,
8 * but WITHOUT ANY WARRANTY; without even the implied warranty of
9 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
10 * GNU Library General Public License for more details.
12 * You should have received a copy of the GNU General Public License
13 * along with this program; if not, write to the Free Software
14 * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
17 #include "sourceview-print.h"
18 #include "sourceview-private.h"
20 #include <libanjuta/anjuta-debug.h>
22 #include <libgnomeprintui/gnome-print-job-preview.h>
23 #include <libgnomeprintui/gnome-print-dialog.h>
25 #include <gtksourceview/gtksourceview.h>
26 #include <gtksourceview/gtksourcelanguage.h>
27 #include <gtksourceview/gtksourcelanguagesmanager.h>
28 #include <gtksourceview/gtksourceprintjob.h>
30 #include <libanjuta/interfaces/ianjuta-editor.h>
32 static GtkSourcePrintJob
*
33 create_print_job(Sourceview
* sv
)
35 GtkSourcePrintJob
*job
;
37 GtkSourceBuffer
*buffer
;
38 const gchar
*filename
;
40 g_return_val_if_fail (sv
!= NULL
, NULL
);
42 view
= GTK_SOURCE_VIEW(sv
->priv
->view
);
43 buffer
= GTK_SOURCE_BUFFER (sv
->priv
->document
);
45 job
= gtk_source_print_job_new (NULL
);
46 gtk_source_print_job_setup_from_view (job
, view
);
47 gtk_source_print_job_set_wrap_mode (job
, GTK_WRAP_CHAR
);
48 gtk_source_print_job_set_highlight (job
, TRUE
);
49 gtk_source_print_job_set_print_numbers (job
, 1);
51 gtk_source_print_job_set_header_format (job
,
57 filename
= ianjuta_editor_get_filename(IANJUTA_EDITOR(sv
), NULL
);
59 gtk_source_print_job_set_footer_format (job
,
65 gtk_source_print_job_set_print_header (job
, TRUE
);
66 gtk_source_print_job_set_print_footer (job
, TRUE
);
72 sourceview_print_dialog_new (GtkSourcePrintJob
*job
, GtkSourceBuffer
* buffer
)
77 GnomePrintConfig
*config
;
79 if (!gtk_text_buffer_get_selection_bounds (GTK_TEXT_BUFFER (buffer
), NULL
, NULL
))
80 selection_flag
= GNOME_PRINT_RANGE_SELECTION_UNSENSITIVE
;
82 selection_flag
= GNOME_PRINT_RANGE_SELECTION
;
84 config
= gtk_source_print_job_get_config (GTK_SOURCE_PRINT_JOB (job
));
86 dialog
= g_object_new (GNOME_TYPE_PRINT_DIALOG
, "print_config", config
, NULL
);
88 gnome_print_dialog_construct (GNOME_PRINT_DIALOG (dialog
),
89 (const unsigned char *)_("Print"),
90 GNOME_PRINT_DIALOG_RANGE
| GNOME_PRINT_DIALOG_COPIES
);
92 lines
= gtk_text_buffer_get_line_count (GTK_TEXT_BUFFER (buffer
));
94 gnome_print_dialog_construct_range_page (GNOME_PRINT_DIALOG (dialog
),
95 GNOME_PRINT_RANGE_ALL
|
96 GNOME_PRINT_RANGE_RANGE
|
98 1, lines
, (const unsigned char *)"A",
99 (const unsigned char *)_("Lines"));
105 sourceview_print(Sourceview
* sv
)
107 GtkSourcePrintJob
* job
= create_print_job(sv
);
108 GtkWidget
* print
= sourceview_print_dialog_new(job
,
109 GTK_SOURCE_BUFFER(sv
->priv
->document
));
110 GnomePrintButtons result
= gtk_dialog_run(GTK_DIALOG(print
));
114 case GNOME_PRINT_DIALOG_RESPONSE_PREVIEW
:
115 sourceview_print_preview(sv
);
117 case GNOME_PRINT_DIALOG_RESPONSE_PRINT
:
119 GnomePrintJob
* gjob
= gtk_source_print_job_print (job
);
120 gnome_print_job_print(gjob
);
121 g_object_unref(gjob
);
124 case GNOME_PRINT_DIALOG_RESPONSE_CANCEL
:
127 DEBUG_PRINT("Unknown print response");
129 gtk_widget_destroy(print
);
134 sourceview_print_preview(Sourceview
* sv
)
136 GtkSourcePrintJob
* job
;
140 job
= create_print_job(sv
);
142 gjob
= gtk_source_print_job_print (job
);
143 preview
= gnome_print_job_preview_new (gjob
,
144 (const guchar
*)_("Print preview"));
146 gtk_widget_show(preview
);
149 g_object_unref(gjob
);