static void page_setup_cb (GtkWidget *widget, CustomWidgetInfo *info) { PrintData *data = info->data; GtkPrintOperation *operation = data->operation; GtkPrintSettings *settings; GtkPageSetup *page_setup; GtkWidget *toplevel; toplevel = gtk_widget_get_toplevel (widget); #if GTK_CHECK_VERSION (2,18,0) if (! gtk_widget_is_toplevel (toplevel)) #else if (! GTK_WIDGET_TOPLEVEL (toplevel)) #endif toplevel = NULL; settings = gtk_print_operation_get_print_settings (operation); if (! settings) settings = gtk_print_settings_new (); page_setup = gtk_print_operation_get_default_page_setup (operation); page_setup = gtk_print_run_page_setup_dialog (GTK_WINDOW (toplevel), page_setup, settings); gtk_print_operation_set_default_page_setup (operation, page_setup); vik_print_preview_set_page_setup (VIK_PRINT_PREVIEW (info->preview), page_setup); update_page_setup (info); }
static void print_page_setup_notify (GtkPrintOperation *operation) { GtkPageSetup *setup; setup = gtk_print_operation_get_default_page_setup (operation); print_size_info_set_page_setup (&info); print_preview_set_page_setup (PRINT_PREVIEW (info.preview), setup); }
static GtkWidget * photos_print_operation_create_custom_widget (GtkPrintOperation *operation) { PhotosPrintOperation *self = PHOTOS_PRINT_OPERATION (operation); GtkPageSetup *page_setup; GtkWidget *print_setup; page_setup = gtk_print_operation_get_default_page_setup (GTK_PRINT_OPERATION (self)); print_setup = photos_print_setup_new (self->node, page_setup); return print_setup; }
void print(zathura_t* zathura) { g_return_if_fail(zathura != NULL); g_return_if_fail(zathura->document != NULL); GtkPrintOperation* print_operation = gtk_print_operation_new(); /* print operation settings */ gtk_print_operation_set_job_name(print_operation, zathura_document_get_path(zathura->document)); gtk_print_operation_set_allow_async(print_operation, TRUE); gtk_print_operation_set_n_pages(print_operation, zathura_document_get_number_of_pages(zathura->document)); gtk_print_operation_set_current_page(print_operation, zathura_document_get_current_page_number(zathura->document)); gtk_print_operation_set_use_full_page(print_operation, TRUE); if (zathura->print.settings != NULL) { gtk_print_operation_set_print_settings(print_operation, zathura->print.settings); } if (zathura->print.page_setup != NULL) { gtk_print_operation_set_default_page_setup(print_operation, zathura->print.page_setup); } gtk_print_operation_set_embed_page_setup(print_operation, TRUE); /* print operation signals */ g_signal_connect(print_operation, "draw-page", G_CALLBACK(cb_print_draw_page), zathura); g_signal_connect(print_operation, "end-print", G_CALLBACK(cb_print_end), zathura); g_signal_connect(print_operation, "request-page-setup", G_CALLBACK(cb_print_request_page_setup), zathura); /* print */ GError* error = NULL; GtkPrintOperationResult result = gtk_print_operation_run(print_operation, GTK_PRINT_OPERATION_ACTION_PRINT_DIALOG, GTK_WINDOW(zathura->ui.session->gtk.window), &error); if (result == GTK_PRINT_OPERATION_RESULT_ERROR) { girara_notify(zathura->ui.session, GIRARA_ERROR, _("Printing failed: %s"), error->message); g_error_free(error); } else if (result == GTK_PRINT_OPERATION_RESULT_APPLY) { g_clear_object(&zathura->print.settings); g_clear_object(&zathura->print.page_setup); /* save previous settings */ zathura->print.settings = g_object_ref(gtk_print_operation_get_print_settings(print_operation)); zathura->print.page_setup = g_object_ref(gtk_print_operation_get_default_page_setup(print_operation)); } g_object_unref(print_operation); }
void print_page_setup_dialog (GtkPrintOperation *operation) { GtkPrintSettings *settings; GtkPageSetup *setup; g_return_if_fail (GTK_IS_PRINT_OPERATION (operation)); setup = gtk_print_operation_get_default_page_setup (operation); settings = gtk_print_settings_new (); setup = gtk_print_run_page_setup_dialog (NULL, setup, settings); g_object_unref (settings); gtk_print_operation_set_default_page_setup (operation, setup); }
static GObject * xviewer_print_create_custom_widget (GtkPrintOperation *operation, gpointer user_data) { GtkPageSetup *page_setup; XviewerPrintData *data; xviewer_debug (DEBUG_PRINTING); data = (XviewerPrintData *)user_data; page_setup = gtk_print_operation_get_default_page_setup (operation); if (page_setup == NULL) page_setup = gtk_page_setup_new (); return G_OBJECT (xviewer_print_image_setup_new (data->image, page_setup)); }
GtkPrintOperation * create_print_operation (DiagramData *data, const char *name) { PrintData *print_data; GtkPrintOperation *operation; GtkPageSetup * setup; int num_pages; /* gets deleted in end_print */ print_data = g_new0 (PrintData, 1); print_data->data = g_object_ref (data); print_data->renderer = g_object_new (DIA_TYPE_CAIRO_RENDERER, NULL); operation = gtk_print_operation_new (); gtk_print_operation_set_job_name (operation, name); setup = gtk_print_operation_get_default_page_setup (operation); if (!setup) setup = gtk_page_setup_new (); _dia_to_gtk_page_setup (print_data->data, setup); gtk_print_operation_set_default_page_setup (operation, setup); g_object_unref (setup); /* similar logic draw_page() but we need to set the total pages in advance */ if (data->paper.fitto) { num_pages = data->paper.fitwidth * data->paper.fitheight; } else { int nx = ceil((data->extents.right - data->extents.left) / data->paper.width); int ny = ceil((data->extents.bottom - data->extents.top) / data->paper.height); num_pages = nx * ny; } gtk_print_operation_set_n_pages (operation, num_pages); gtk_print_operation_set_unit (operation, GTK_UNIT_MM); g_signal_connect (operation, "draw_page", G_CALLBACK (draw_page), print_data); g_signal_connect (operation, "begin_print", G_CALLBACK (begin_print), print_data); g_signal_connect (operation, "end_print", G_CALLBACK (end_print), print_data); return operation; }
static void print_size_info_get_page_dimensions (PrintSizeInfo *info, gdouble *page_width, gdouble *page_height, GtkUnit unit) { GtkPageSetup *setup; setup = gtk_print_operation_get_default_page_setup (info->data->operation); if (info->data->use_full_page) { *page_width = gtk_page_setup_get_paper_width (setup, unit); *page_height = gtk_page_setup_get_paper_height (setup, unit); } else { *page_width = gtk_page_setup_get_page_width (setup, unit); *page_height = gtk_page_setup_get_page_height (setup, unit); } }
void print_page_setup_save (GtkPrintOperation *operation, gint32 image_ID) { GtkPageSetup *setup; GKeyFile *key_file; g_return_if_fail (GTK_IS_PRINT_OPERATION (operation)); key_file = g_key_file_new (); setup = gtk_print_operation_get_default_page_setup (operation); gtk_page_setup_to_key_file (setup, key_file, PRINT_PAGE_SETUP_NAME); print_utils_key_file_save_as_parasite (key_file, image_ID, PRINT_PAGE_SETUP_NAME); print_utils_key_file_save_as_rcfile (key_file, PRINT_PAGE_SETUP_NAME); g_key_file_free (key_file); }
static void get_page_dimensions (CustomWidgetInfo *info, gdouble *page_width, gdouble *page_height, GtkUnit unit) { GtkPageSetup *setup; setup = gtk_print_operation_get_default_page_setup (info->data->operation); *page_width = gtk_page_setup_get_paper_width (setup, unit); *page_height = gtk_page_setup_get_paper_height (setup, unit); if (!info->data->use_full_page) { gdouble left_margin = gtk_page_setup_get_left_margin (setup, unit); gdouble right_margin = gtk_page_setup_get_right_margin (setup, unit); gdouble top_margin = gtk_page_setup_get_top_margin (setup, unit); gdouble bottom_margin = gtk_page_setup_get_bottom_margin (setup, unit); *page_width -= left_margin + right_margin; *page_height -= top_margin + bottom_margin; } }
static void cb_print_done(GtkPrintOperation* operation, GtkPrintOperationResult result, zathura_t* zathura) { if (result == GTK_PRINT_OPERATION_RESULT_APPLY) { if (zathura->print.settings != NULL) { g_object_unref(zathura->print.settings); } if (zathura->print.page_setup != NULL) { g_object_unref(zathura->print.page_setup); } /* save previous settings */ zathura->print.settings = g_object_ref(gtk_print_operation_get_print_settings(operation)); zathura->print.page_setup = g_object_ref(gtk_print_operation_get_default_page_setup(operation)); } else if (result == GTK_PRINT_OPERATION_RESULT_ERROR) { GError* error = NULL; gtk_print_operation_get_error(operation, &error); girara_notify(zathura->ui.session, GIRARA_ERROR, _("Printing failed: %s"), error->message); g_error_free(error); } }
static void print_done(GtkPrintOperation *prt, GtkPrintOperationResult result, gpointer user_data) { GKeyFile *conf = GetConf(); GtkPrintSettings *settings = gtk_print_operation_get_print_settings(prt); #if GTK_CHECK_VERSION(2,12,0) GtkPageSetup *setup = gtk_print_operation_get_default_page_setup(prt); #endif if(!conf) return; #if GTK_CHECK_VERSION(2,12,0) Trace("Settings: %p Conf: %p page_setup: %p",settings,conf,setup); gtk_print_settings_to_key_file(settings,conf,NULL); gtk_page_setup_to_key_file(setup,conf,NULL); #else gtk_print_settings_foreach(settings,(GtkPrintSettingsFunc) SavePrintSetting,conf); #endif g_key_file_set_string(conf,"Print","Font",g_object_get_data(G_OBJECT(prt),"3270FontName")); }
static GtkWidget *create_custom_widget_cb(GtkPrintOperation *operation, PrintData *data) { GtkWidget *layout; GtkWidget *main_hbox; GtkWidget *main_vbox; GtkWidget *hbox; GtkWidget *vbox; GtkWidget *button; GtkWidget *label; GtkPageSetup *setup; CustomWidgetInfo *info = g_malloc0(sizeof(CustomWidgetInfo)); g_signal_connect_swapped (data->operation, _("done"), G_CALLBACK (custom_widgets_cleanup), info); info->data = data; setup = gtk_print_operation_get_default_page_setup (data->operation); if (! setup) { setup = gtk_page_setup_new (); gtk_print_operation_set_default_page_setup (data->operation, setup); } layout = gtk_vbox_new (FALSE, 6); gtk_container_set_border_width (GTK_CONTAINER (layout), 12); /* main hbox */ main_hbox = gtk_hbox_new (FALSE, 12); gtk_box_pack_start (GTK_BOX (layout), main_hbox, TRUE, TRUE, 0); gtk_widget_show (main_hbox); /* main vbox */ main_vbox = gtk_vbox_new (FALSE, 12); gtk_box_pack_start (GTK_BOX (main_hbox), main_vbox, FALSE, FALSE, 0); gtk_widget_show (main_vbox); vbox = gtk_vbox_new (FALSE, 6); gtk_box_pack_start (GTK_BOX (main_vbox), vbox, FALSE, FALSE, 0); gtk_widget_show (vbox); /* Page Size */ button = gtk_button_new_with_mnemonic (_("_Adjust Page Size " "and Orientation")); gtk_box_pack_start (GTK_BOX (main_vbox), button, FALSE, FALSE, 0); g_signal_connect (G_OBJECT (button), "clicked", G_CALLBACK (page_setup_cb), info); gtk_widget_show (button); /* Center */ GtkWidget *combo; const PrintCenterName *center; hbox = gtk_hbox_new (FALSE, 6); gtk_box_pack_start (GTK_BOX (main_vbox), hbox, FALSE, FALSE, 0); gtk_widget_show (hbox); label = gtk_label_new_with_mnemonic (_("C_enter:")); gtk_misc_set_alignment (GTK_MISC (label), 0.0, 0.5); gtk_box_pack_start (GTK_BOX (hbox), label, FALSE, FALSE, 0); gtk_widget_show (label); combo = vik_combo_box_text_new (); for (center = center_modes; center->name; center++) { vik_combo_box_text_append (combo, _(center->name)); } gtk_combo_box_set_active(GTK_COMBO_BOX(combo), VIK_PRINT_CENTER_BOTH); gtk_box_pack_start (GTK_BOX (hbox), combo, TRUE, TRUE, 0); gtk_widget_show (combo); gtk_label_set_mnemonic_widget (GTK_LABEL (label), combo); g_signal_connect(combo, "changed", G_CALLBACK(center_changed_cb), info); info->center_combo = combo; /* ignore page margins */ button = gtk_check_button_new_with_mnemonic (_("Ignore Page _Margins")); gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON (button), data->use_full_page); gtk_box_pack_start (GTK_BOX (main_vbox), button, FALSE, FALSE, 0); g_signal_connect (button, "toggled", G_CALLBACK (full_page_toggled_cb), info); gtk_widget_show (button); /* scale */ vbox = gtk_vbox_new (FALSE, 1); gtk_box_pack_start (GTK_BOX (main_vbox), vbox, FALSE, FALSE, 0); gtk_widget_show (vbox); hbox = gtk_hbox_new (FALSE, 6); gtk_box_pack_start (GTK_BOX (vbox), hbox, FALSE, FALSE, 0); gtk_widget_show (hbox); label = gtk_label_new_with_mnemonic (_("Image S_ize:")); gtk_misc_set_alignment (GTK_MISC (label), 0.0, 0.5); gtk_box_pack_start (GTK_BOX (hbox), label, FALSE, FALSE, 0); gtk_widget_show (label); label = gtk_label_new (NULL); gtk_misc_set_alignment (GTK_MISC (label), 0.0, 0.5); info->scale_label = label; gtk_box_pack_start (GTK_BOX (hbox), info->scale_label, TRUE, TRUE, 0); gtk_widget_show (info->scale_label); info->scale = gtk_hscale_new_with_range(1, 100, 1); gtk_box_pack_start (GTK_BOX (vbox), info->scale, TRUE, TRUE, 0); gtk_scale_set_draw_value(GTK_SCALE(info->scale), FALSE); gtk_widget_show (info->scale); gtk_label_set_mnemonic_widget (GTK_LABEL (label), info->scale); g_signal_connect(info->scale, "change_value", G_CALLBACK(scale_change_value_cb), info); info->preview = vik_print_preview_new (setup, GDK_DRAWABLE(vik_viewport_get_pixmap(data->vvp))); vik_print_preview_set_use_full_page (VIK_PRINT_PREVIEW(info->preview), data->use_full_page); gtk_box_pack_start (GTK_BOX (main_hbox), info->preview, TRUE, TRUE, 0); gtk_widget_show (info->preview); g_signal_connect (info->preview, "offsets-changed", G_CALLBACK (preview_offsets_changed_cb), info); update_page_setup (info); gdouble offset_x_max, offset_y_max; get_max_offsets (info, &offset_x_max, &offset_y_max); vik_print_preview_set_image_offsets_max (VIK_PRINT_PREVIEW (info->preview), offset_x_max, offset_y_max); set_scale_value(info); return layout; }
GtkWidget * print_page_layout_gui (PrintData *data, const gchar *help_id) { GtkWidget *main_hbox; GtkWidget *main_vbox; GtkWidget *button; GtkWidget *frame; GtkPageSetup *setup; GtkSizeGroup *label_group; GtkSizeGroup *entry_group; memset (&info, 0, sizeof (PrintSizeInfo)); info.data = data; info.image_width = gimp_drawable_width (data->drawable_id); info.image_height = gimp_drawable_height (data->drawable_id); setup = gtk_print_operation_get_default_page_setup (data->operation); if (! setup) { setup = gtk_page_setup_new (); gtk_print_operation_set_default_page_setup (data->operation, setup); } /* main hbox */ main_hbox = gtk_hbox_new (FALSE, 12); gtk_container_set_border_width (GTK_CONTAINER (main_hbox), 12); /* main vbox */ main_vbox = gtk_vbox_new (FALSE, 12); gtk_box_pack_start (GTK_BOX (main_hbox), main_vbox, FALSE, FALSE, 0); gtk_widget_show (main_vbox); label_group = gtk_size_group_new (GTK_SIZE_GROUP_HORIZONTAL); entry_group = gtk_size_group_new (GTK_SIZE_GROUP_HORIZONTAL); /* size entry area for the image's print size */ frame = print_size_frame (data, label_group, entry_group); gtk_box_pack_start (GTK_BOX (main_vbox), frame, FALSE, FALSE, 0); gtk_widget_show (frame); /* offset entry area for the image's offset position */ frame = print_offset_frame (data, label_group, entry_group); gtk_box_pack_start (GTK_BOX (main_vbox), frame, FALSE, FALSE, 0); gtk_widget_show (frame); g_object_unref (label_group); g_object_unref (entry_group); button = gtk_check_button_new_with_mnemonic (_("Ignore Page _Margins")); gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON (button), data->use_full_page); gtk_box_pack_start (GTK_BOX (main_vbox), button, FALSE, FALSE, 0); g_signal_connect (button, "toggled", G_CALLBACK (print_size_info_use_full_page_toggled), NULL); gtk_widget_show (button); /* preview */ frame = gimp_frame_new (_("Preview")); gtk_box_pack_start (GTK_BOX (main_hbox), frame, TRUE, TRUE, 0); gtk_widget_show (frame); info.preview = print_preview_new (setup, data->drawable_id); print_preview_set_use_full_page (PRINT_PREVIEW (info.preview), data->use_full_page); gtk_container_add (GTK_CONTAINER (frame), info.preview); gtk_widget_show (info.preview); g_signal_connect (info.preview, "offsets-changed", G_CALLBACK (print_size_info_preview_offset_changed), NULL); print_size_info_set_page_setup (&info); g_signal_connect_object (data->operation, "notify::default-page-setup", G_CALLBACK (print_page_setup_notify), main_hbox, 0); gimp_help_connect (main_hbox, gimp_standard_help_func, help_id, NULL); return main_hbox; }
static void print_size_info_set_page_setup (PrintSizeInfo *info) { GtkPageSetup *setup; PrintData *data = info->data; gdouble page_width; gdouble page_height; gdouble x; gdouble y; setup = gtk_print_operation_get_default_page_setup (data->operation); print_size_info_get_page_dimensions (info, &page_width, &page_height, GTK_UNIT_INCH); page_width *= gimp_unit_get_factor (data->unit); page_height *= gimp_unit_get_factor (data->unit); if (info->area_label) { gchar *format; gchar *text; format = g_strdup_printf ("%%.%df x %%.%df %s", gimp_unit_get_digits (data->unit), gimp_unit_get_digits (data->unit), gimp_unit_get_plural (data->unit)); text = g_strdup_printf (format, page_width, page_height); g_free (format); gtk_label_set_text (GTK_LABEL (info->area_label), text); g_free (text); } x = page_width; y = page_height; if (info->chain && gimp_chain_button_get_active (info->chain)) { gdouble ratio_x = page_width / (gdouble) info->image_width; gdouble ratio_y = page_height / (gdouble) info->image_height; if (ratio_x < ratio_y) y = (gdouble) info->image_height * ratio_x; else x = (gdouble) info->image_width * ratio_y; } gimp_size_entry_set_value_boundaries (info->size_entry, WIDTH, page_width / 100.0, x); gimp_size_entry_set_value_boundaries (info->size_entry, HEIGHT, page_height / 100.0, y); print_size_info_get_page_dimensions (info, &page_width, &page_height, GTK_UNIT_POINTS); x = (gdouble) info->image_width / page_width * 72.0; y = (gdouble) info->image_height / page_height * 72.0; if (info->chain && gimp_chain_button_get_active (info->chain)) { gdouble max = MAX (x, y); x = y = max; } gimp_size_entry_set_refval_boundaries (info->resolution_entry, 0, x, GIMP_MAX_RESOLUTION); gimp_size_entry_set_refval_boundaries (info->resolution_entry, 1, y, GIMP_MAX_RESOLUTION); }