93 layout = gtk_print_context_create_pango_layout(context);
94 pango_layout_set_wrap(layout, PANGO_WRAP_WORD_CHAR);
95 pango_layout_set_spacing(layout, 0);
96 pango_layout_set_attributes(layout,
NULL);
97 pango_layout_set_font_description(layout, desc);
105 gint layout_w, layout_h;
107 pango_layout_set_text(layout,
text, -1);
108 pango_layout_get_size(layout, &layout_w, &layout_h);
111 gint default_w = 50 * strlen(
text) * PANGO_SCALE;
113 geany_debug(
"Invalid layout_w (%d). Falling back to default width (%d)",
114 layout_w, default_w);
115 layout_w = default_w;
119 gint default_h = 100 * PANGO_SCALE;
121 geany_debug(
"Invalid layout_h (%d). Falling back to default height (%d)",
122 layout_h, default_h);
123 layout_h = default_h;
127 *width = (gdouble)layout_w / PANGO_SCALE;
129 *height = (gdouble)layout_h / PANGO_SCALE;
140 g_path_get_basename(tmp_file_name) : g_strdup(tmp_file_name);
141 PangoLayout *layout = dinfo->
layout;
144 cairo_set_line_width(cr, 0.3);
145 cairo_set_source_rgb(cr, 0, 0, 0);
146 cairo_rectangle(cr, 2, 2, width - 4, ph_height - 4);
151 pango_layout_set_width(layout, (width - 8) * PANGO_SCALE);
152 pango_layout_set_ellipsize(layout, PANGO_ELLIPSIZE_MIDDLE);
154 data = g_strdup_printf(
"<b>%s</b>", file_name);
155 pango_layout_set_markup(layout, data, -1);
156 pango_layout_set_alignment(layout, PANGO_ALIGN_LEFT);
158 pango_cairo_show_layout(cr, layout);
162 data = g_strdup_printf(
_(
"<b>Page %d of %d</b>"), page_nr + 1, dinfo->
pages->len);
163 pango_layout_set_markup(layout, data, -1);
164 pango_layout_set_alignment(layout, PANGO_ALIGN_LEFT);
166 pango_cairo_show_layout(cr, layout);
170 if (G_LIKELY(!
EMPTY(datetime)))
172 data = g_strdup_printf(
"<b>%s</b>", datetime);
173 pango_layout_set_markup(layout, data, -1);
174 pango_layout_set_alignment(layout, PANGO_ALIGN_RIGHT);
176 pango_cairo_show_layout(cr, layout);
182 pango_layout_set_alignment(layout, PANGO_ALIGN_LEFT);
183 pango_layout_set_ellipsize(layout, PANGO_ELLIPSIZE_NONE);
184 pango_layout_set_justify(layout, FALSE);
185 pango_layout_set_width(layout, width * PANGO_SCALE);
214 gboolean sens = gtk_toggle_button_get_active(togglebutton);
226 GtkWidget *alignment36;
232 gtk_print_operation_set_custom_tab_label(operation,
_(
"Document Setup"));
234 page = gtk_box_new(GTK_ORIENTATION_VERTICAL, 0);
235 gtk_container_set_border_width(GTK_CONTAINER(page), 5);
244 gtk_widget_set_tooltip_text(w->
check_print_pagenumbers,
_(
"Add page numbers at the bottom of each page. It takes 2 lines of the page."));
249 gtk_widget_set_tooltip_text(w->
check_print_pageheader,
_(
"Add a little header to every page containing the page number, the filename and the current date (see below). It takes 3 lines of the page."));
253 frame33 = gtk_frame_new(
NULL);
254 gtk_box_pack_start(GTK_BOX(page), frame33, FALSE, FALSE, 0);
255 gtk_frame_set_label_align(GTK_FRAME(frame33), 0, 0);
256 gtk_frame_set_shadow_type(GTK_FRAME(frame33), GTK_SHADOW_NONE);
258 alignment36 = gtk_alignment_new(0, 0.5, 1, 1);
260 gtk_alignment_set_padding(GTK_ALIGNMENT(alignment36), 0, 0, 12, 0);
262 vbox30 = gtk_box_new(GTK_ORIENTATION_VERTICAL, 1);
265 w->
check_print_basename = gtk_check_button_new_with_mnemonic(
_(
"Use the basename of the printed file"));
267 gtk_widget_set_tooltip_text(w->
check_print_basename,
_(
"Print only the basename(without the path) of the printed file"));
270 hbox10 = gtk_box_new(GTK_ORIENTATION_HORIZONTAL, 5);
271 gtk_box_pack_start(GTK_BOX(vbox30), hbox10, TRUE, TRUE, 0);
273 label203 = gtk_label_new(
_(
"Date format:"));
274 gtk_box_pack_start(GTK_BOX(hbox10), label203, FALSE, FALSE, 0);
279 gtk_widget_set_tooltip_text(w->
entry_print_dateformat,
_(
"Specify a format for the date and time stamp which is added to the page header on each page. You can use any conversion specifiers which can be used with the ANSI C strftime function."));
288static void end_print(GtkPrintOperation *operation, GtkPrintContext *context, gpointer user_data)
296 g_object_unref(dinfo->
sci);
297 g_object_unref(dinfo->
layout);
298 g_array_free(dinfo->
pages, TRUE);
304 dinfo->
fr.
hdc = dinfo->
fr.
hdcTarget = gtk_print_context_get_cairo_context(ctx);
335static void begin_print(GtkPrintOperation *operation, GtkPrintContext *context, gpointer user_data)
338 PangoContext *pango_ctx, *widget_pango_ctx;
339 PangoFontDescription *desc;
340 gdouble pango_res, widget_res;
352 g_object_ref_sink(dinfo->
sci);
366 pango_ctx = gtk_print_context_create_pango_context(context);
367 pango_res = pango_cairo_context_get_resolution(pango_ctx);
368 g_object_unref(pango_ctx);
369 widget_pango_ctx = gtk_widget_get_pango_context(GTK_WIDGET(dinfo->
sci));
370 widget_res = pango_cairo_context_get_resolution(widget_pango_ctx);
375 widget_res = pango_cairo_font_map_get_resolution(
376 (PangoCairoFontMap*) pango_context_get_font_map(widget_pango_ctx));
378 dinfo->
sci_scale = pango_res / widget_res;
380 dinfo->
pages = g_array_new(FALSE, FALSE,
sizeof(gint));
386 pango_font_description_free(desc);
400 cairo_save(dinfo->
fr.
hdc);
403 cairo_restore(dinfo->
fr.
hdc);
409static gboolean
paginate(GtkPrintOperation *operation, GtkPrintContext *context, gpointer user_data)
424 gtk_print_operation_set_n_pages(operation, dinfo->
pages->len);
430static void draw_page(GtkPrintOperation *operation, GtkPrintContext *context,
431 gint page_nr, gpointer user_data)
435 gdouble width, height;
437 g_return_if_fail(dinfo !=
NULL);
438 g_return_if_fail((guint)page_nr < dinfo->pages->len);
440 if (dinfo->
pages->len > 0)
442 gdouble fraction = (page_nr + 1) / (gdouble) dinfo->
pages->len;
443 gchar *
text = g_strdup_printf(
_(
"Page %d of %d"), page_nr + 1, dinfo->
pages->len);
449 cr = gtk_print_context_get_cairo_context(context);
450 width = gtk_print_context_get_width(context);
451 height = gtk_print_context_get_height(context);
457 if ((guint)page_nr + 1 < dinfo->
pages->len)
465 cairo_set_source_rgb(cr, 0, 0, 0);
477 cairo_set_line_width(cr, 0.3);
478 cairo_move_to(cr, x, y1);
479 cairo_line_to(cr, x, y2);
485 gchar *
line = g_strdup_printf(
"<small>- %d -</small>", page_nr + 1);
486 pango_layout_set_markup(dinfo->
layout,
line, -1);
487 pango_layout_set_alignment(dinfo->
layout, PANGO_ALIGN_CENTER);
489 pango_cairo_show_layout(cr, dinfo->
layout);
498 if (gtk_print_operation_get_status(op) == GTK_PRINT_STATUS_FINISHED_ABORTED)
500 else if (gtk_print_operation_get_status(op) == GTK_PRINT_STATUS_FINISHED)
507 GtkPrintOperation *op;
508 GtkPrintOperationResult res = GTK_PRINT_OPERATION_RESULT_ERROR;
521 op = gtk_print_operation_new();
523 gtk_print_operation_set_unit(op, GTK_UNIT_POINTS);
524 gtk_print_operation_set_show_progress(op, TRUE);
525 gtk_print_operation_set_embed_page_setup(op, TRUE);
527 g_signal_connect(op,
"begin-print", G_CALLBACK(
begin_print), &dinfo);
528 g_signal_connect(op,
"end-print", G_CALLBACK(
end_print), &dinfo);
529 g_signal_connect(op,
"paginate", G_CALLBACK(
paginate), &dinfo);
530 g_signal_connect(op,
"draw-page", G_CALLBACK(
draw_page), &dinfo);
536 gtk_print_operation_set_print_settings(op,
settings);
538 gtk_print_operation_set_default_page_setup(op,
page_setup);
540 res = gtk_print_operation_run(
543 if (res == GTK_PRINT_OPERATION_RESULT_APPLY)
547 settings = g_object_ref(gtk_print_operation_get_print_settings(op));
550 else if (res == GTK_PRINT_OPERATION_RESULT_ERROR)
564 GtkPageSetup *new_page_setup;
567 settings = gtk_print_settings_new();
569 new_page_setup = gtk_print_run_page_setup_dialog(
590 _(
"Please set a print command in the preferences dialog first."));
598 _(
"The file \"%s\" will be printed with the following command:\n\n%s"),
605 gchar *argv[] = {
"/bin/sh",
"-c", cmdline,
NULL };
613 _(
"Cannot execute print command \"%s\": %s. "
614 "Check the path setting in Preferences."),
#define SC_PRINT_COLOURONWHITE
#define SCI_SETDOCPOINTER
#define SCI_GETDOCPOINTER
#define SCI_SETPRINTCOLOURMODE
static struct @80 widgets
gboolean dialogs_show_question(const gchar *text,...)
Shows a question message box with text and Yes/No buttons.
void dialogs_show_msgbox(GtkMessageType type, const gchar *text,...)
Shows a message box of the type type with text.
File related dialogs, miscellaneous dialogs, font dialog.
Document related actions: new, save, open, etc.
#define DOC_VALID(doc_ptr)
Null-safe way to check GeanyDocument::is_valid.
#define DOC_FILENAME(doc)
Returns the filename of the document passed or GEANY_STRING_UNTITLED (e.g.
ScintillaObject * editor_create_widget(GeanyEditor *editor)
Creates a new Scintilla GtkWidget based on the settings for editor.
void error(const errorSelection selection, const char *const format,...)
#define GEANY_STRING_UNTITLED
void highlighting_set_styles(ScintillaObject *sci, GeanyFiletype *ft)
Sets up highlighting and other visual settings.
Syntax highlighting for the different filetypes, using the Scintilla lexers.
void geany_debug(gchar const *format,...)
void msgwin_status_add(const gchar *format,...)
Logs a formatted status message without setting the status bar.
Message window functions (status, compiler, messages windows).
static GtkWidget * create_custom_widget(GtkPrintOperation *operation, gpointer user_data)
static void status_changed(GtkPrintOperation *op, gpointer data)
void printing_page_setup_gtk(void)
static void add_page_header(DocInfo *dinfo, cairo_t *cr, gint width, gint page_nr)
PrintingPrefs printing_prefs
static void draw_page(GtkPrintOperation *operation, GtkPrintContext *context, gint page_nr, gpointer user_data)
static void setup_range(DocInfo *dinfo, GtkPrintContext *ctx)
void printing_print_doc(GeanyDocument *doc)
static GtkPrintSettings * settings
static void end_print(GtkPrintOperation *operation, GtkPrintContext *context, gpointer user_data)
static void begin_print(GtkPrintOperation *operation, GtkPrintContext *context, gpointer user_data)
static void printing_print_gtk(GeanyDocument *doc)
static void print_external(GeanyDocument *doc)
static void on_page_header_toggled(GtkToggleButton *togglebutton, gpointer user_data)
static GtkPageSetup * page_setup
static void custom_widget_apply(GtkPrintOperation *operation, GtkWidget *widget, gpointer user_data)
static void get_text_dimensions(PangoLayout *layout, const gchar *text, gdouble *width, gdouble *height)
static gboolean paginate(GtkPrintOperation *operation, GtkPrintContext *context, gpointer user_data)
static gint format_range(DocInfo *dinfo, gboolean draw)
static PangoLayout * setup_pango_layout(GtkPrintContext *context, PangoFontDescription *desc)
gint sci_get_length(ScintillaObject *sci)
Gets the length of all text.
void sci_set_line_numbers(ScintillaObject *sci, gboolean set)
Wrapper functions for the Scintilla editor widget SCI_* messages.
gboolean spawn_async(const gchar *working_directory, const gchar *command_line, gchar **argv, gchar **envp, GPid *child_pid, GError **error)
Executes a child asynchronously.
Portable and convenient process spawning and communication.
gtk_container_add(GTK_CONTAINER(dialog->vbox), check_button)
gtk_widget_show_all(dialog)
struct Sci_RangeToFormat fr
Structure for representing an open tab with all its properties.
gchar * file_name
The UTF-8 encoded file name.
GeanyFiletype * file_type
The filetype for this document, it's only a reference to one of the elements of the global filetypes ...
GeanyEditor * editor
The editor associated with the document.
ScintillaObject * sci
The Scintilla editor GtkWidget.
gchar * editor_font
editor font
GtkWidget * window
Main window.
GtkWidget * progressbar
Progress bar widget in the status bar to show progress of various actions.
gchar * external_print_cmd
gboolean use_gtk_printing
gboolean print_page_header
gboolean page_header_basename
gchar * page_header_datefmt
gboolean print_page_numbers
gboolean print_line_numbers
Defines internationalization macros.
GeanyMainWidgets main_widgets
void ui_entry_add_clear_icon(GtkEntry *entry)
Adds a small clear icon to the right end of the passed entry.
GeanyInterfacePrefs interface_prefs
User Interface general utility functions.
gchar * utils_get_date_time(const gchar *format, time_t *time_to_use)
Retrieves a formatted date/time string from strftime().
void utils_str_replace_all(gchar **haystack, const gchar *needle, const gchar *replacement)
General utility functions, non-GTK related.
#define EMPTY(ptr)
Returns TRUE if ptr is NULL or *ptr is FALSE.