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., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, 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>
31 #include <libanjuta/interfaces/ianjuta-document.h>
33 static GtkSourcePrintJob
*
34 create_print_job(Sourceview
* sv
)
36 GtkSourcePrintJob
*job
;
38 GtkSourceBuffer
*buffer
;
39 const gchar
*filename
;
41 g_return_val_if_fail (sv
!= NULL
, NULL
);
43 view
= GTK_SOURCE_VIEW(sv
->priv
->view
);
44 buffer
= GTK_SOURCE_BUFFER (sv
->priv
->document
);
46 job
= gtk_source_print_job_new (NULL
);
47 gtk_source_print_job_setup_from_view (job
, view
);
48 gtk_source_print_job_set_wrap_mode (job
, GTK_WRAP_CHAR
);
49 gtk_source_print_job_set_highlight (job
, TRUE
);
50 gtk_source_print_job_set_print_numbers (job
, 1);
52 gtk_source_print_job_set_header_format (job
,
58 filename
= ianjuta_document_get_filename(IANJUTA_DOCUMENT(sv
), NULL
);
60 gtk_source_print_job_set_footer_format (job
,
66 gtk_source_print_job_set_print_header (job
, TRUE
);
67 gtk_source_print_job_set_print_footer (job
, TRUE
);
73 sourceview_print_dialog_new (GtkSourcePrintJob
*job
, GtkSourceBuffer
* buffer
)
78 GnomePrintConfig
*config
;
80 if (!gtk_text_buffer_get_selection_bounds (GTK_TEXT_BUFFER (buffer
), NULL
, NULL
))
81 selection_flag
= GNOME_PRINT_RANGE_SELECTION_UNSENSITIVE
;
83 selection_flag
= GNOME_PRINT_RANGE_SELECTION
;
85 config
= gtk_source_print_job_get_config (GTK_SOURCE_PRINT_JOB (job
));
87 dialog
= g_object_new (GNOME_TYPE_PRINT_DIALOG
, "print_config", config
, NULL
);
89 gnome_print_dialog_construct (GNOME_PRINT_DIALOG (dialog
),
90 (const unsigned char *)_("Print"),
91 GNOME_PRINT_DIALOG_RANGE
| GNOME_PRINT_DIALOG_COPIES
);
93 lines
= gtk_text_buffer_get_line_count (GTK_TEXT_BUFFER (buffer
));
95 gnome_print_dialog_construct_range_page (GNOME_PRINT_DIALOG (dialog
),
96 GNOME_PRINT_RANGE_ALL
|
97 GNOME_PRINT_RANGE_RANGE
|
99 1, lines
, (const unsigned char *)"A",
100 (const unsigned char *)_("Lines"));
106 sourceview_print(Sourceview
* sv
)
108 GtkSourcePrintJob
* job
= create_print_job(sv
);
109 GtkWidget
* print
= sourceview_print_dialog_new(job
,
110 GTK_SOURCE_BUFFER(sv
->priv
->document
));
111 GnomePrintButtons result
= gtk_dialog_run(GTK_DIALOG(print
));
115 case GNOME_PRINT_DIALOG_RESPONSE_PREVIEW
:
116 sourceview_print_preview(sv
);
118 case GNOME_PRINT_DIALOG_RESPONSE_PRINT
:
120 GnomePrintJob
* gjob
= gtk_source_print_job_print (job
);
121 gnome_print_job_print(gjob
);
122 g_object_unref(gjob
);
125 case GNOME_PRINT_DIALOG_RESPONSE_CANCEL
:
128 DEBUG_PRINT("Unknown print response");
130 gtk_widget_destroy(print
);
135 sourceview_print_preview(Sourceview
* sv
)
137 GtkSourcePrintJob
* job
;
141 job
= create_print_job(sv
);
143 gjob
= gtk_source_print_job_print (job
);
144 preview
= gnome_print_job_preview_new (gjob
,
145 (const guchar
*)_("Print preview"));
147 gtk_widget_show(preview
);
150 g_object_unref(gjob
);