Beispiel #1
0
static GtkPrintOperationResult
_do_print(EDITOR * e, GtkPrintOperationAction action)
{
	GtkPrintOperation *operation;
	GtkPrintSettings *psettings;
	GtkPageSetup *setup;
	GtkPrintOperationResult result;
	GError *error = NULL;

	operation = gtk_print_operation_new();
	psettings = gtk_print_settings_new();

	psettings = gtk_print_operation_get_print_settings(operation);

	setup = gtk_page_setup_new();
	gtk_page_setup_set_top_margin(setup, 30, GTK_UNIT_PIXEL);
	gtk_page_setup_set_left_margin(setup, 50, GTK_UNIT_PIXEL);

#ifdef WIN32
	gtk_print_operation_set_unit(operation, GTK_UNIT_POINTS);
#endif
	gtk_print_operation_set_default_page_setup(operation, setup);

	result = gtk_html_print_operation_run(GTK_HTML(e->html_widget), operation, action, GTK_WINDOW(e->window), (GtkHTMLPrintCalcHeight) _calc_header_height,	/* GtkHTMLPrintCalcHeight  calc_header_height */
					      (GtkHTMLPrintCalcHeight) _calc_footer_height,	/* GtkHTMLPrintCalcHeight  calc_footer_height */
					      (GtkHTMLPrintDrawFunc) _draw_header,	/* GtkHTMLPrintDrawFunc draw_header */
					      (GtkHTMLPrintDrawFunc) _draw_footer,	/* GtkHTMLPrintDrawFunc draw_footer */
					      e,	/* gpointer user_data */
					      &error);

	g_object_unref(operation);
	handle_error(&error);

	return result;
}
Beispiel #2
0
void
gui_editor_print (GUIEditor *editor)
{
  editor->print_operation = gtk_print_operation_new ();
#ifdef G_OS_WIN32
  gtk_print_operation_set_unit (editor->print_operation, GTK_UNIT_POINTS);
#endif
  GtkPrintOperationResult res;
  GError *error;
  GtkWidget *error_dialog;

  g_signal_connect (editor->print_operation, "begin-print", G_CALLBACK (gui_editor_begin_print), editor);
  g_signal_connect (editor->print_operation, "draw-page", G_CALLBACK (gui_editor_draw_page), editor);
  gtk_print_operation_set_show_progress (editor->print_operation, TRUE);
  res = gtk_print_operation_run (editor->print_operation, GTK_PRINT_OPERATION_ACTION_PRINT_DIALOG, NULL, &error);
  if (res == GTK_PRINT_OPERATION_RESULT_ERROR )
  {
    error_dialog = gtk_message_dialog_new (GTK_WINDOW (editor->scroll),
						GTK_DIALOG_DESTROY_WITH_PARENT,
						GTK_MESSAGE_ERROR,
						GTK_BUTTONS_CLOSE,
						"Error printing file:\n%s",
						error->message);
    gtk_widget_show (error_dialog);
    g_error_free (error);
  }

  g_object_unref (editor->print_operation);
}
Beispiel #3
0
int
main (int argc, char **argv)
{
  GtkPrintOperation *print;
  TestPrintFileOperation *print_file;

  gtk_init (&argc, &argv);

  /* Test some random drawing, with per-page paper settings */
  print = gtk_print_operation_new ();
  gtk_print_operation_set_n_pages (print, 2);
  gtk_print_operation_set_unit (print, GTK_UNIT_MM);
  gtk_print_operation_set_export_filename (print, "test.pdf");
  g_signal_connect (print, "draw_page", G_CALLBACK (draw_page), NULL);
  g_signal_connect (print, "request_page_setup", G_CALLBACK (request_page_setup), NULL);
  gtk_print_operation_run (print, GTK_PRINT_OPERATION_ACTION_EXPORT, NULL, NULL);

  /* Test subclassing of GtkPrintOperation */
  print_file = test_print_file_operation_new ("testprint.c");
  test_print_file_operation_set_font_size (print_file, 12.0);
  gtk_print_operation_set_export_filename (GTK_PRINT_OPERATION (print_file), "test2.pdf");
  gtk_print_operation_run (GTK_PRINT_OPERATION (print_file), GTK_PRINT_OPERATION_ACTION_EXPORT, NULL, NULL);
  
  return 0;
}
Beispiel #4
0
static void printing_print_gtk(GeanyDocument *doc)
{
	GtkPrintOperation *op;
	GtkPrintOperationResult res = GTK_PRINT_OPERATION_RESULT_ERROR;
	GError *error = NULL;
	DocInfo *dinfo;
	PrintWidgets *widgets;

	/** TODO check for monospace font, detect the widest character in the font and
	  * use it at font_width */

	widgets = g_new0(PrintWidgets, 1);
	dinfo = g_new0(DocInfo, 1);
	/* all other fields are initialised in begin_print() */
	dinfo->doc = doc;

	op = gtk_print_operation_new();

	gtk_print_operation_set_unit(op, GTK_UNIT_POINTS);
	gtk_print_operation_set_show_progress(op, TRUE);
#if GTK_CHECK_VERSION(2, 18, 0)
	gtk_print_operation_set_embed_page_setup(op, TRUE);
#endif

	g_signal_connect(op, "begin-print", G_CALLBACK(begin_print), dinfo);
	g_signal_connect(op, "end-print", G_CALLBACK(end_print), dinfo);
	g_signal_connect(op, "draw-page", G_CALLBACK(draw_page), dinfo);
	g_signal_connect(op, "status-changed", G_CALLBACK(status_changed), doc->file_name);
	g_signal_connect(op, "create-custom-widget", G_CALLBACK(create_custom_widget), widgets);
	g_signal_connect(op, "custom-widget-apply", G_CALLBACK(custom_widget_apply), widgets);

	if (settings != NULL)
		gtk_print_operation_set_print_settings(op, settings);
	if (page_setup != NULL)
		gtk_print_operation_set_default_page_setup(op, page_setup);

	res = gtk_print_operation_run(
		op, GTK_PRINT_OPERATION_ACTION_PRINT_DIALOG, GTK_WINDOW(main_widgets.window), &error);

	if (res == GTK_PRINT_OPERATION_RESULT_APPLY)
	{
		if (settings != NULL)
			g_object_unref(settings);
		settings = g_object_ref(gtk_print_operation_get_print_settings(op));
		/* status message is printed in the status-changed handler */
	}
	else if (res == GTK_PRINT_OPERATION_RESULT_ERROR)
	{
		dialogs_show_msgbox(GTK_MESSAGE_ERROR, _("Printing of %s failed (%s)."),
							doc->file_name, error->message);
		g_error_free(error);
	}

	g_object_unref(op);
	g_free(dinfo);
	g_free(widgets);
}
Beispiel #5
0
GtkWidget *
do_printing (GtkWidget *do_widget)
{
  GtkPrintOperation *operation;
  GtkPrintSettings *settings;
  PrintData *data;
  GError *error = NULL;

  operation = gtk_print_operation_new ();
  data = g_new0 (PrintData, 1);
  data->resourcename = g_strdup ("/sources/printing.c");
  data->font_size = 12.0;

  g_signal_connect (G_OBJECT (operation), "begin-print",
                    G_CALLBACK (begin_print), data);
  g_signal_connect (G_OBJECT (operation), "draw-page",
                    G_CALLBACK (draw_page), data);
  g_signal_connect (G_OBJECT (operation), "end-print",
                    G_CALLBACK (end_print), data);

  gtk_print_operation_set_use_full_page (operation, FALSE);
  gtk_print_operation_set_unit (operation, GTK_UNIT_POINTS);
  gtk_print_operation_set_embed_page_setup (operation, TRUE);

  settings = gtk_print_settings_new ();

  gtk_print_settings_set (settings, GTK_PRINT_SETTINGS_OUTPUT_BASENAME, "gtk-demo");
  gtk_print_operation_set_print_settings (operation, settings);

  gtk_print_operation_run (operation, GTK_PRINT_OPERATION_ACTION_PRINT_DIALOG, GTK_WINDOW (do_widget), &error);

  g_object_unref (operation);
  g_object_unref (settings);

  if (error)
    {
      GtkWidget *dialog;

      dialog = gtk_message_dialog_new (GTK_WINDOW (do_widget),
                                       GTK_DIALOG_DESTROY_WITH_PARENT,
                                       GTK_MESSAGE_ERROR,
                                       GTK_BUTTONS_CLOSE,
                                       "%s", error->message);
      g_error_free (error);

      g_signal_connect (dialog, "response",
                        G_CALLBACK (gtk_widget_destroy), NULL);

      gtk_widget_show (dialog);
    }


  return NULL;
}
Beispiel #6
0
int
main (int argc, char **argv)
{
  GtkPrintOperation *print;
  GtkPrintSettings *settings;

  settings = gtk_print_settings_new ();
  /* gtk_print_settings_set_printer (settings, "printer"); */

  print = gtk_print_operation_new ();
  gtk_print_operation_set_print_settings (print, settings);
  gtk_print_operation_set_n_pages (print, 1);
  gtk_print_operation_set_unit (print, GTK_UNIT_MM);
  g_signal_connect (print, "draw_page", G_CALLBACK (draw_page), NULL);
  gtk_print_operation_run (print, GTK_PRINT_OPERATION_ACTION_PRINT, NULL, NULL);

  return 0;
}
Beispiel #7
0
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;
}
Beispiel #8
0
GtkWidget *
soli_print_preview_new (GtkPrintOperation        *operation,
			 GtkPrintOperationPreview *gtk_preview,
			 GtkPrintContext          *context)
{
	SoliPrintPreview *preview;
	cairo_surface_t *surface;
	cairo_t *cr;
	gdouble dpi_x, dpi_y;

	g_return_val_if_fail (GTK_IS_PRINT_OPERATION (operation), NULL);
	g_return_val_if_fail (GTK_IS_PRINT_OPERATION_PREVIEW (gtk_preview), NULL);

	preview = g_object_new (SOLI_TYPE_PRINT_PREVIEW, NULL);

	preview->operation = g_object_ref (operation);
	preview->gtk_preview = g_object_ref (gtk_preview);
	preview->context = g_object_ref (context);

	/* FIXME: is this legal?? */
	gtk_print_operation_set_unit (operation, GTK_UNIT_POINTS);

	g_signal_connect_object (gtk_preview,
				 "ready",
				 G_CALLBACK (preview_ready),
				 preview,
				 0);

	/* FIXME: we need a cr to paginate... but we can't get the drawing
	 * area surface because it's not there yet... for now I create
	 * a dummy pdf surface.
	 * gtk_print_context_set_cairo_context() should be called in the
	 * got-page-size handler.
	 */
	surface = create_preview_surface (preview, &dpi_x, &dpi_y);
	cr = cairo_create (surface);
	gtk_print_context_set_cairo_context (context, cr, dpi_x, dpi_y);
	cairo_destroy (cr);
	cairo_surface_destroy (surface);

	return GTK_WIDGET (preview);
}
Beispiel #9
0
Print::Print(SPDocument *doc, SPItem *base) :
    _doc (doc),
    _base (base)
{
    g_assert (_doc);
    g_assert (_base);

    _printop = gtk_print_operation_new ();

    // set up dialog title, based on document name
    gchar *jobname = _doc->name ? _doc->name : _("SVG Document");
    Glib::ustring title = _("Print");
    title += " ";
    title += jobname;
    gtk_print_operation_set_job_name (_printop, title.c_str());

    // set up paper size to match the document size
    gtk_print_operation_set_unit (_printop, GTK_UNIT_POINTS);
    GtkPageSetup *page_setup = gtk_page_setup_new();
    gdouble doc_width = sp_document_width(_doc) * PT_PER_PX;
    gdouble doc_height = sp_document_height(_doc) * PT_PER_PX;
    GtkPaperSize *paper_size = gtk_paper_size_new_custom("custom", "custom",
                                doc_width, doc_height, GTK_UNIT_POINTS);
    gtk_page_setup_set_paper_size (page_setup, paper_size);
#ifndef WIN32
    gtk_print_operation_set_default_page_setup (_printop, page_setup);
#endif
    gtk_print_operation_set_use_full_page (_printop, TRUE);

    // set up signals
    _workaround._doc = _doc;
    _workaround._base = _base;
    _workaround._tab = &_tab;
    g_signal_connect (_printop, "create-custom-widget", G_CALLBACK (create_custom_widget), _tab.gobj());
    g_signal_connect (_printop, "begin-print", G_CALLBACK (begin_print), NULL);
    g_signal_connect (_printop, "draw-page", G_CALLBACK (draw_page), &_workaround);

    // build custom preferences tab
    gtk_print_operation_set_custom_tab_label (_printop, _("Rendering"));
}
Beispiel #10
0
PlannerPrintJob *
planner_print_job_new (GtkPrintOperation *gpo, GList *views)
{
        PlannerPrintJob     *job;
	PlannerPrintJobPriv *priv;

        job = g_object_new (PLANNER_TYPE_PRINT_JOB, NULL);

	priv = job->priv;

	job->operation = g_object_ref (gpo);
	gtk_print_operation_set_unit (gpo, GTK_UNIT_POINTS);

	priv->header = NULL;
	priv->footer = NULL;

	priv->font = pango_font_description_from_string ("Sans Regular 6");
	priv->font_height = pango_font_description_get_size (priv->font) / PANGO_SCALE;

	priv->bold_font = pango_font_description_from_string ("Sans Bold 6");

	priv->header_height = 0;
	priv->footer_height = 0;
	priv->views = views;

	g_signal_connect (G_OBJECT (gpo), "create-custom-widget",
			  G_CALLBACK (print_job_create_custom_widget), job);
	g_signal_connect (G_OBJECT (gpo), "custom-widget-apply",
			  G_CALLBACK (print_job_custom_widget_apply), job);
	g_signal_connect (G_OBJECT (gpo), "begin-print",
			  G_CALLBACK (print_job_begin_print), job);
	g_signal_connect (G_OBJECT (gpo), "draw-page",
			  G_CALLBACK (print_job_draw_page), job);
	g_signal_connect (G_OBJECT (gpo), "end-print",
			  G_CALLBACK (print_job_end_print), job);

        return job;
}
Beispiel #11
0
//!
//! @brief Sets up a print operation for the current results
//!
//! The function checks the results of the results text buffer, and then attempts
//! to set up a print operation.  If a section of the search results are highlighted
//! only those results are printed.
//!
void gw_print (const GtkPrintOperationAction ACTION, GwSearchWindow *window)
{
    //Declarations
    GwPrintData *data;
    GtkPrintOperation *operation;
    GtkPrintOperationResult res;
    
    //Initializations
    data = gw_printdata_new (window);
    operation = gtk_print_operation_new ();

    //Force at least some minimal margins on the pages that print
    gtk_print_operation_set_default_page_setup (operation, NULL);
    gtk_print_operation_set_use_full_page (operation, FALSE);
    gtk_print_operation_set_unit (operation, GTK_UNIT_MM);

    if (_settings != NULL)
      gtk_print_operation_set_print_settings (operation, _settings);

    g_signal_connect (operation, "begin_print", G_CALLBACK (_begin_print), data);
    g_signal_connect (operation, "draw_page", G_CALLBACK (_draw_page), data);
    g_signal_connect (operation, "paginate", G_CALLBACK (_paginate), data);
    g_signal_connect (operation, "done", G_CALLBACK (_done), data);

    res = gtk_print_operation_run (operation, ACTION, NULL, NULL);

    if (res == GTK_PRINT_OPERATION_RESULT_APPLY)
    {
        if (_settings != NULL) g_object_unref (_settings);
        _settings = g_object_ref (gtk_print_operation_get_print_settings (operation));
    }

    //Cleanup
    gw_printdata_free (data);
    g_object_unref (operation);
}
Beispiel #12
0
/**
 * Prints the current page.
 *
 * If printing on WIN32, in order to prevent the font from being tiny, (see bug #591177),
 * A GtkPrintOperation object needs to be created so that the unit can be set, and then
 * webkit_web_frame_print_full() needs to be called to use that GtkPrintOperation.  On
 * other platforms (specifically linux - not sure about MacOSX), the version of webkit may
 * not contain the function webkit_web_frame_print_full(), so webkit_web_frame_print() is
 * called instead (the font size problem doesn't show up on linux).
 *
 * @param self HTML renderer object
 */
static void
impl_webkit_print( GncHtml* self, const gchar* jobname, gboolean export_pdf )
{
#if !HAVE(WEBKIT_WEB_FRAME_PRINT_FULL)
    extern void webkit_web_frame_print( WebKitWebFrame * frame );
#endif

    gchar *export_filename = NULL;
    GncHtmlWebkitPrivate* priv;
    WebKitWebFrame* frame;
#if HAVE(WEBKIT_WEB_FRAME_PRINT_FULL)
    GtkPrintOperation* op = gtk_print_operation_new();
    GError* error = NULL;
    GtkPrintSettings *print_settings;
#endif

    priv = GNC_HTML_WEBKIT_GET_PRIVATE(self);
    frame = webkit_web_view_get_main_frame( priv->web_view );

#if HAVE(WEBKIT_WEB_FRAME_PRINT_FULL)
    gnc_print_operation_init( op, jobname );
    print_settings = gtk_print_operation_get_print_settings (op);
    if (!print_settings)
    {
        print_settings = gtk_print_settings_new();
        gtk_print_operation_set_print_settings(op, print_settings);
    }
#ifdef G_OS_WIN32
    gtk_print_operation_set_unit( op, GTK_UNIT_POINTS );
#endif

    // Make sure to generate a full export filename
    if (g_str_has_suffix(jobname, ".pdf"))
    {
        export_filename = g_strdup(jobname);
    }
    else
    {
        export_filename = g_strconcat(jobname, ".pdf", NULL);
    }

    // Two different modes of operation. Either export to PDF, or run the
    // normal print dialog
    if (export_pdf)
    {
        GtkWidget *dialog;
        gint result;
        gchar *export_dirname = NULL;
        gchar* basename;

        // Before we save the PDF file, we always as the user for the export
        // file name. We will store the chosen directory in the gtk print settings
        // as well.
        dialog = gtk_file_chooser_dialog_new (_("Export to PDF File"),
                                              NULL,
                                              GTK_FILE_CHOOSER_ACTION_SAVE,
                                              GTK_STOCK_CANCEL, GTK_RESPONSE_CANCEL,
                                              GTK_STOCK_SAVE, GTK_RESPONSE_ACCEPT,
                                              NULL);
        gtk_file_chooser_set_do_overwrite_confirmation (GTK_FILE_CHOOSER (dialog), TRUE);

        // Does the jobname look like a valid full file path?
        basename = g_path_get_basename(jobname);
        if (strcmp(basename, jobname) != 0)
        {
            gchar *tmp_basename;
            gchar *tmp_dirname = g_path_get_dirname(jobname);

            if (g_file_test(tmp_dirname, G_FILE_TEST_EXISTS | G_FILE_TEST_IS_DIR))
            {
                // Yes, the jobname starts with a directory name that actually
                // exists. Hence we use this as output directory.
                export_dirname = tmp_dirname;
                tmp_dirname = NULL;

                // As the prefix part of the "jobname" is the directory path, we
                // need to extract the suffix part for the filename.
                tmp_basename = g_path_get_basename(export_filename);
                g_free(export_filename);
                export_filename = tmp_basename;
            }
            g_free(tmp_dirname);
        }
        g_free(basename);

        // Set the output file name from the given jobname
        gtk_file_chooser_set_current_name (GTK_FILE_CHOOSER(dialog), export_filename);

        // Do we have a stored output directory?
        if (!export_dirname && gtk_print_settings_has_key(print_settings, GNC_GTK_PRINT_SETTINGS_EXPORT_DIR))
        {
            const char* tmp_dirname = gtk_print_settings_get(print_settings,
                                      GNC_GTK_PRINT_SETTINGS_EXPORT_DIR);
            // Only use the directory subsequently if it exists.
            if (g_file_test(tmp_dirname, G_FILE_TEST_EXISTS | G_FILE_TEST_IS_DIR))
            {
                export_dirname = g_strdup(tmp_dirname);
            }
        }

        // If we have an already existing directory, propose it now.
        if (export_dirname)
        {
            gtk_file_chooser_set_current_folder(GTK_FILE_CHOOSER(dialog), export_dirname);
        }
        g_free(export_dirname);

        result = gtk_dialog_run (GTK_DIALOG (dialog));
        // Weird. In gtk_dialog_run, the gtk code will run a fstat() on the
        // proposed new output filename, which of course fails with "file not
        // found" as this file doesn't exist. It will still show a warning output
        // in the trace file, though.

        if (result == GTK_RESPONSE_ACCEPT)
        {
            // The user pressed "Ok", so use the file name for the actual file output.
            gchar *dirname;
            char *tmp = gtk_file_chooser_get_filename (GTK_FILE_CHOOSER (dialog));
            g_free(export_filename);
            export_filename = tmp;

            // Store the directory part of the file for later
            dirname = g_path_get_dirname(export_filename);
            if (g_file_test(dirname, G_FILE_TEST_EXISTS | G_FILE_TEST_IS_DIR))
            {
                gtk_print_settings_set(print_settings, GNC_GTK_PRINT_SETTINGS_EXPORT_DIR, dirname);
            }
            g_free(dirname);
        }
        gtk_widget_destroy (dialog);

        if (result != GTK_RESPONSE_ACCEPT)
        {
            // User pressed cancel - no saving of the PDF file here.
            g_free(export_filename);
            g_object_unref( op );
            return;
        }

        // This function expects the full filename including (absolute?) path
        gtk_print_operation_set_export_filename(op, export_filename);

        // Run the "Export to PDF" print operation
        webkit_web_frame_print_full( frame, op, GTK_PRINT_OPERATION_ACTION_EXPORT, &error );
    }
    else
    {

        // Also store this export file name as output URI in the settings
        if (gtk_print_settings_has_key(print_settings, GTK_PRINT_SETTINGS_OUTPUT_URI))
        {
            // Get the previous output URI, extract the directory part, and
            // append the current filename.
            const gchar *olduri = gtk_print_settings_get(print_settings, GTK_PRINT_SETTINGS_OUTPUT_URI);
            gchar *dirname = g_path_get_dirname(olduri);
            gchar *newuri = (g_strcmp0(dirname, ".") == 0)
                            ? g_strdup(export_filename)
                            : g_build_filename(dirname, export_filename, NULL);
            //g_warning("olduri=%s newuri=%s", olduri, newuri);

            // This function expects the full filename including protocol, path, and name
            gtk_print_settings_set(print_settings, GTK_PRINT_SETTINGS_OUTPUT_URI, newuri);

            g_free(newuri);
            g_free(dirname);
        }
        else
        {
            // No stored output URI from the print settings, so just set our export filename
            gtk_print_settings_set(print_settings, GTK_PRINT_SETTINGS_OUTPUT_URI, export_filename);
        }

        // Run the normal printing dialog
        webkit_web_frame_print_full( frame, op, GTK_PRINT_OPERATION_ACTION_PRINT_DIALOG, &error );
    }

    if ( error != NULL )
    {
        GtkWidget* window = gtk_widget_get_toplevel( GTK_WIDGET(priv->web_view) );
        GtkWidget* dialog = gtk_message_dialog_new( gtk_widget_is_toplevel(window) ? GTK_WINDOW(window) : NULL,
                            GTK_DIALOG_DESTROY_WITH_PARENT,
                            GTK_MESSAGE_ERROR,
                            GTK_BUTTONS_CLOSE,
                            "%s", error->message );
        g_error_free( error );

        g_signal_connect( dialog, "response", G_CALLBACK(gtk_widget_destroy), NULL);
        gtk_widget_show( dialog );
    }

    // Remember to save the printing settings after this print job
    gnc_print_operation_save_print_settings(op);
    g_object_unref( op );
    g_free(export_filename);

#else
    webkit_web_frame_print( frame );
#endif
}
Beispiel #13
0
static GimpPDBStatusType
print_image (gint32     image_ID,
             gboolean   interactive,
             GError   **error)
{
  GtkPrintOperation       *operation;
  GtkPrintOperationResult  result;
  gchar                   *temp_proc;
  gint32                   layer;
  PrintData                data;

  /*  create a print layer from the projection  */
  layer = gimp_layer_new_from_visible (image_ID, image_ID, PRINT_PROC_NAME);

  operation = gtk_print_operation_new ();

  gtk_print_operation_set_n_pages (operation, 1);
  print_operation_set_name (operation, image_ID);

  print_page_setup_load (operation, image_ID);

  /* fill in the PrintData struct */
  data.image_id      = image_ID;
  data.drawable_id   = layer;
  data.unit          = gimp_get_default_unit ();
  data.image_unit    = gimp_image_get_unit (image_ID);
  data.offset_x      = 0;
  data.offset_y      = 0;
  data.center        = CENTER_BOTH;
  data.use_full_page = FALSE;
  data.operation     = operation;

  gimp_image_get_resolution (image_ID, &data.xres, &data.yres);

  print_settings_load (&data);

  gtk_print_operation_set_unit (operation, GTK_UNIT_PIXEL);

  g_signal_connect (operation, "begin-print",
                    G_CALLBACK (begin_print),
                    &data);
  g_signal_connect (operation, "draw-page",
                    G_CALLBACK (draw_page),
                    &data);
  g_signal_connect (operation, "end-print",
                    G_CALLBACK (end_print),
                    &image_ID);

  print_operation = operation;
  temp_proc = print_temp_proc_install (image_ID);
  gimp_extension_enable ();

  if (interactive)
    {
      gimp_ui_init (PLUG_IN_BINARY, FALSE);

      g_signal_connect_swapped (operation, "end-print",
                                G_CALLBACK (print_settings_save),
                                &data);

      g_signal_connect (operation, "create-custom-widget",
                        G_CALLBACK (create_custom_widget),
                        &data);

      gtk_print_operation_set_custom_tab_label (operation, _("Image Settings"));

      result = gtk_print_operation_run (operation,
                                        GTK_PRINT_OPERATION_ACTION_PRINT_DIALOG,
                                        NULL, error);
    }
  else
    {
      result = gtk_print_operation_run (operation,
                                        GTK_PRINT_OPERATION_ACTION_PRINT,
                                        NULL, error);
    }

  gimp_uninstall_temp_proc (temp_proc);
  g_free (temp_proc);
  print_operation = NULL;

  g_object_unref (operation);

  if (gimp_drawable_is_valid (layer))
    gimp_drawable_delete (layer);

  switch (result)
    {
    case GTK_PRINT_OPERATION_RESULT_APPLY:
    case GTK_PRINT_OPERATION_RESULT_IN_PROGRESS:
      return GIMP_PDB_SUCCESS;

    case GTK_PRINT_OPERATION_RESULT_CANCEL:
      return GIMP_PDB_CANCEL;

    case GTK_PRINT_OPERATION_RESULT_ERROR:
      return GIMP_PDB_EXECUTION_ERROR;
    }

  return GIMP_PDB_EXECUTION_ERROR;
}
Beispiel #14
0
/** \brief Print a satellite pass.
  * \param pass Pointer to the pass_t data
  * \param qth Pointer to the qth_t structure
  * \param parent Transient parent of the dialog, or NULL
  *
  * This function prints a satellite pass to the printer (or a file) using the
  * Gtk+ printing API. The function takes the user configuration into account
  * and only prints the selected columns. The font size will be adjusted so that
  * one row can fit on one line. The function will also try to reduce the number
  * of rows so that the whole pass can fit on one page:
  *
  *    +-------------------------+
  *    |         header          |
  *    |------------+------------|
  *    |            |            |
  *    |            |            |
  *    |  polar     |   az/el    |
  *    |            |            |
  *    |------------+------------|
  *    |                         |
  *    |    Table with data      |
  *    |                         |
  *    |  - - - - - - - - - - -  |
  *    |  - - - - - - - - - - -  |
  *    |  - - - - - - - - - - -  |
  *    |  - - - - - - - - - - -  |
  *    |  - - - - - - - - - - -  |
  *    |  - - - - - - - - - - -  |
  *    |  - - - - - - - - - - -  |
  *    |                         |
  *    +-------------------------+
  *
  */
void print_pass   (pass_t *pass, qth_t *qth, GtkWindow *parent)
{
    gchar *text,*header,*buff;

    GtkPrintOperation *operation;
    PrintData *data;
    GError *error = NULL;


    /* TODO check pass and qth */


    operation = gtk_print_operation_new ();
    data = g_new0 (PrintData, 1);
    data->font_size = 12.0;  // FIXME

    /* page header */
    data->pgheader = g_strdup_printf (_("Pass details for %s (orbit %d)"), pass->satname, pass->orbit);

    /* convert data to printable strings; we use existing pass_to_txt functions */
    data->fields = sat_cfg_get_int (SAT_CFG_INT_PRED_SINGLE_COL);
    header = pass_to_txt_tblheader (pass, qth, data->fields);
    text = pass_to_txt_tblcontents (pass, qth, data->fields);
    buff = g_strconcat (header, text, NULL);
    data->lines = g_strsplit (buff, "\n", 0);
    g_free (text);
    g_free (header);
    g_free (buff);

    g_signal_connect (G_OBJECT (operation), "begin-print", G_CALLBACK (begin_print), data);
    g_signal_connect (G_OBJECT (operation), "draw-page", G_CALLBACK (draw_page), data);
    g_signal_connect (G_OBJECT (operation), "end-print", G_CALLBACK (end_print), data);

    gtk_print_operation_set_use_full_page (operation, FALSE);
    gtk_print_operation_set_unit (operation, GTK_UNIT_POINTS);

    gtk_print_operation_run (operation, GTK_PRINT_OPERATION_ACTION_PRINT_DIALOG,
                             parent, &error);

    g_object_unref (operation);


    if (error) {
        sat_log_log (SAT_LOG_LEVEL_ERROR,
                     "%s: %s", __func__, error->message);

        GtkWidget *dialog;

        dialog = gtk_message_dialog_new (parent,
                                         GTK_DIALOG_DESTROY_WITH_PARENT,
                                         GTK_MESSAGE_ERROR,
                                         GTK_BUTTONS_CLOSE,
                                         "%s", error->message);
        g_error_free (error);

        g_signal_connect (dialog, "response",
                          G_CALLBACK (gtk_widget_destroy), NULL);

        gtk_widget_show (dialog);
    }


}
Beispiel #15
0
GtkWidget *
do_printing (GtkWidget *do_widget)
{
  GtkPrintOperation *operation;
  GtkPrintSettings *settings;
  PrintData *data;
  gchar *uri, *ext;
  const gchar *dir;
  GError *error = NULL;

  operation = gtk_print_operation_new ();
  data = g_new0 (PrintData, 1);
  data->filename = demo_find_file ("printing.c", NULL);
  data->font_size = 12.0;

  g_signal_connect (G_OBJECT (operation), "begin-print",
                    G_CALLBACK (begin_print), data);
  g_signal_connect (G_OBJECT (operation), "draw-page",
                    G_CALLBACK (draw_page), data);
  g_signal_connect (G_OBJECT (operation), "end-print",
                    G_CALLBACK (end_print), data);

  gtk_print_operation_set_use_full_page (operation, FALSE);
  gtk_print_operation_set_unit (operation, GTK_UNIT_POINTS);
  gtk_print_operation_set_embed_page_setup (operation, TRUE);

  settings = gtk_print_settings_new ();
  dir = g_get_user_special_dir (G_USER_DIRECTORY_DOCUMENTS);
  if (dir == NULL)
    dir = g_get_home_dir ();
  if (g_strcmp0 (gtk_print_settings_get (settings, GTK_PRINT_SETTINGS_OUTPUT_FILE_FORMAT), "ps") == 0)
    ext = ".ps";
  else if (g_strcmp0 (gtk_print_settings_get (settings, GTK_PRINT_SETTINGS_OUTPUT_FILE_FORMAT), "svg") == 0)
    ext = ".svg";
  else
    ext = ".pdf";

  uri = g_strconcat ("file://", dir, "/", "gtk-demo", ext, NULL);
  gtk_print_settings_set (settings, GTK_PRINT_SETTINGS_OUTPUT_URI, uri);
  gtk_print_operation_set_print_settings (operation, settings);

  gtk_print_operation_run (operation, GTK_PRINT_OPERATION_ACTION_PRINT_DIALOG, GTK_WINDOW (do_widget), &error);

  g_object_unref (operation);
  g_object_unref (settings);
  g_free (uri);

  if (error)
    {
      GtkWidget *dialog;

      dialog = gtk_message_dialog_new (GTK_WINDOW (do_widget),
                                       GTK_DIALOG_DESTROY_WITH_PARENT,
                                       GTK_MESSAGE_ERROR,
                                       GTK_BUTTONS_CLOSE,
                                       "%s", error->message);
      g_error_free (error);

      g_signal_connect (dialog, "response",
                        G_CALLBACK (gtk_widget_destroy), NULL);

      gtk_widget_show (dialog);
    }


  return NULL;
}
Beispiel #16
0
gint
yad_print_run (void)
{
  GtkWidget *dlg;
  GtkWidget *box, *img, *lbl;
  gchar *uri, *job_name = NULL;
  GtkPrintCapabilities pcap;
  GtkPrintOperationAction act = GTK_PRINT_OPERATION_ACTION_PRINT;
  gint resp, ret = 0;
  GError *err = NULL;

  /* check if file is exists */
  if (options.common_data.uri && options.common_data.uri[0])
    {
      if (!g_file_test (options.common_data.uri, G_FILE_TEST_EXISTS))
        {
          g_printerr (_("File %s not found.\n"), options.common_data.uri);
          return 1;
        }
    }
  else
    {
      g_printerr (_("Filename is not specified.\n"));
      return 1;
    }

  /* create print dialog */
  dlg = gtk_print_unix_dialog_new (options.data.dialog_title, NULL);
  gtk_window_set_type_hint (GTK_WINDOW (dlg), GDK_WINDOW_TYPE_HINT_NORMAL);
  gtk_print_unix_dialog_set_embed_page_setup (GTK_PRINT_UNIX_DIALOG (dlg), TRUE);
  pcap = GTK_PRINT_CAPABILITY_PAGE_SET | GTK_PRINT_CAPABILITY_COPIES |
    GTK_PRINT_CAPABILITY_COLLATE | GTK_PRINT_CAPABILITY_REVERSE |
    GTK_PRINT_CAPABILITY_NUMBER_UP | GTK_PRINT_CAPABILITY_NUMBER_UP_LAYOUT;
  if (options.common_data.preview && options.print_data.type != YAD_PRINT_RAW)
    pcap |= GTK_PRINT_CAPABILITY_PREVIEW;
  gtk_print_unix_dialog_set_manual_capabilities (GTK_PRINT_UNIX_DIALOG (dlg), pcap);

  if (!settings.print_settings)
    settings.print_settings = gtk_print_unix_dialog_get_settings (GTK_PRINT_UNIX_DIALOG (dlg));

  uri = g_build_filename (g_get_current_dir (), "yad.pdf", NULL);
  gtk_print_settings_set (settings.print_settings, "output-uri", g_filename_to_uri (uri, NULL, NULL));
  g_free (uri);

  gtk_print_unix_dialog_set_settings (GTK_PRINT_UNIX_DIALOG (dlg), settings.print_settings);

  if (settings.page_setup)
    gtk_print_unix_dialog_set_page_setup (GTK_PRINT_UNIX_DIALOG (dlg), settings.page_setup);

  /* set window behavior */
  gtk_widget_set_name (dlg, "yad-dialog-window");
  if (options.data.sticky)
    gtk_window_stick (GTK_WINDOW (dlg));
  gtk_window_set_resizable (GTK_WINDOW (dlg), !options.data.fixed);
  gtk_window_set_keep_above (GTK_WINDOW (dlg), options.data.ontop);
  gtk_window_set_decorated (GTK_WINDOW (dlg), !options.data.undecorated);
  gtk_window_set_skip_taskbar_hint (GTK_WINDOW (dlg), options.data.skip_taskbar);
  gtk_window_set_skip_pager_hint (GTK_WINDOW (dlg), options.data.skip_taskbar);

  /* set window size and position */
  if (!options.data.geometry)
    {
      gtk_window_set_default_size (GTK_WINDOW (dlg), options.data.width, options.data.height);
      if (options.data.center)
        gtk_window_set_position (GTK_WINDOW (dlg), GTK_WIN_POS_CENTER);
      else if (options.data.mouse)
        gtk_window_set_position (GTK_WINDOW (dlg), GTK_WIN_POS_MOUSE);
    }
  else
    {
      /* parse geometry, if given. must be after showing widget */
      gtk_widget_realize (dlg);
      gtk_window_parse_geometry (GTK_WINDOW (dlg), options.data.geometry);
    }

  /* create yad's top box */
  if (options.data.dialog_text || options.data.dialog_image)
    {
#if !GTK_CHECK_VERSION(3,0,0)
      box = gtk_hbox_new (FALSE, 0);
#else
      box = gtk_box_new (GTK_ORIENTATION_HORIZONTAL, 0);
#endif

      if (options.data.dialog_image)
        {
          GdkPixbuf *pb = NULL;

          pb = get_pixbuf (options.data.dialog_image, YAD_BIG_ICON);
          img = gtk_image_new_from_pixbuf (pb);
          if (pb)
            g_object_unref (pb);

          gtk_widget_set_name (img, "yad-dialog-image");
          gtk_box_pack_start (GTK_BOX (box), img, FALSE, FALSE, 2);
        }
      if (options.data.dialog_text)
        {
          gchar *buf = g_strcompress (options.data.dialog_text);

          lbl = gtk_label_new (NULL);
          if (!options.data.no_markup)
            gtk_label_set_markup (GTK_LABEL (lbl), buf);
          else
            gtk_label_set_text (GTK_LABEL (lbl), buf);
          gtk_widget_set_name (lbl, "yad-dialog-label");
          gtk_label_set_selectable (GTK_LABEL (lbl), options.data.selectable_labels);
          gtk_misc_set_alignment (GTK_MISC (lbl), options.data.text_align, 0.5);
          if (options.data.geometry || options.data.width != -1)
            gtk_label_set_line_wrap (GTK_LABEL (lbl), TRUE);
          gtk_box_pack_start (GTK_BOX (box), lbl, TRUE, TRUE, 2);
          g_signal_connect (G_OBJECT (lbl), "size-allocate", G_CALLBACK (size_allocate_cb), NULL);
          g_free (buf);
        }

      /* add tob box to dialog */
      gtk_widget_show_all (box);
      gtk_box_pack_start (GTK_BOX (gtk_dialog_get_content_area (GTK_DIALOG (dlg))), box, TRUE, TRUE, 5);
      gtk_box_reorder_child (GTK_BOX (gtk_dialog_get_content_area (GTK_DIALOG (dlg))), box, 0);
    }

  do
    {
      resp = gtk_dialog_run (GTK_DIALOG (dlg));
      switch (resp)
        {
        case GTK_RESPONSE_APPLY:   /* ask for preview */
          act = GTK_PRINT_OPERATION_ACTION_PREVIEW;
        case GTK_RESPONSE_OK:      /* run print */
          settings.print_settings = gtk_print_unix_dialog_get_settings (GTK_PRINT_UNIX_DIALOG (dlg));
          settings.page_setup = gtk_print_unix_dialog_get_page_setup (GTK_PRINT_UNIX_DIALOG (dlg));
          job_name = g_strdup_printf ("yad-%s-%d", g_path_get_basename (options.common_data.uri), getpid ());
          if (options.print_data.type != YAD_PRINT_RAW)
            {
              /* print text or image */
              GtkPrintOperation *op = gtk_print_operation_new ();
              gtk_print_operation_set_unit (op, GTK_UNIT_POINTS);
              gtk_print_operation_set_print_settings (op, settings.print_settings);
              gtk_print_operation_set_default_page_setup (op, settings.page_setup);
              gtk_print_operation_set_job_name (op, job_name);

              switch (options.print_data.type)
                {
                case YAD_PRINT_TEXT:
                  g_signal_connect (G_OBJECT (op), "begin-print", G_CALLBACK (begin_print_text), NULL);
                  g_signal_connect (G_OBJECT (op), "draw-page", G_CALLBACK (draw_page_text), NULL);
                  break;
                case YAD_PRINT_IMAGE:
                  gtk_print_operation_set_n_pages (op, 1);
                  g_signal_connect (G_OBJECT (op), "draw-page", G_CALLBACK (draw_page_image), NULL);
                  break;
                default:;
                }

              if (gtk_print_operation_run (op, act, NULL, &err) == GTK_PRINT_OPERATION_RESULT_ERROR)
                {
                  g_printerr (_("Printing failed: %s\n"), err->message);
                  ret = 1;
                }
            }
          else
            {
              /* print raw ps or pdf data */
              GtkPrinter *prnt;
              GtkPrintJob *job;

              prnt = gtk_print_unix_dialog_get_selected_printer (GTK_PRINT_UNIX_DIALOG (dlg));

              if (g_str_has_suffix (options.common_data.uri, ".ps"))
                {
                  if (!gtk_printer_accepts_ps (prnt))
                    {
                      g_printerr (_("Printer doesn't support ps format.\n"));
                      ret = 1;
                    }
                }
              else if (g_str_has_suffix (options.common_data.uri, ".pdf"))
                {
                  if (!gtk_printer_accepts_pdf (prnt))
                    {
                      g_printerr (_("Printer doesn't support pdf format.\n"));
                      ret = 1;
                    }
                }
              else
                {
                  g_printerr (_("This file type is not supported for raw printing.\n"));
                  ret = 1;
                }
              if (ret == 1)
                break;

              job = gtk_print_job_new (job_name, prnt, settings.print_settings, settings.page_setup);
              if (gtk_print_job_set_source_file (job, options.common_data.uri, &err))
                {
                  gtk_print_job_send (job, (GtkPrintJobCompleteFunc) raw_print_done, &ret, NULL);
                  gtk_main ();
                }
              else
                {
                  g_printerr (_("Load source file failed: %s\n"), err->message);
                  ret = 1;
                }
            }
          break;
        default:
          ret = 1;
          break;
        }
    }
  while (resp == GTK_RESPONSE_APPLY);

  gtk_widget_destroy (dlg);
  write_settings ();
  return ret;
}
Beispiel #17
0
static gboolean
mail_printer_print_timeout_cb (gpointer user_data)
{
    GSimpleAsyncResult *simple;
    AsyncContext *async_context;
    GCancellable *cancellable;
    GtkPrintOperation *print_operation;
    GtkPrintOperationAction print_action;
    EMailPrinter *printer;
    WebKitWebFrame *web_frame;
    gulong create_custom_widget_handler_id;
    gulong custom_widget_apply_handler_id;
    gulong draw_page_handler_id;
    GError *error = NULL;

    simple = G_SIMPLE_ASYNC_RESULT (user_data);
    async_context = g_simple_async_result_get_op_res_gpointer (simple);

    cancellable = async_context->cancellable;
    print_action = async_context->print_action;

    /* Check for cancellation one last time before printing. */
    if (g_cancellable_set_error_if_cancelled (cancellable, &error))
        goto exit;

    /* This returns a new reference. */
    printer = (EMailPrinter *) g_async_result_get_source_object (
                  G_ASYNC_RESULT (simple));

    print_operation = e_print_operation_new ();

    gtk_print_operation_set_show_progress (print_operation, TRUE);
    gtk_print_operation_set_unit (print_operation, GTK_UNIT_PIXEL);

    if (async_context->print_action == GTK_PRINT_OPERATION_ACTION_EXPORT) {
        const gchar *export_filename;

        export_filename =
            e_mail_printer_get_export_filename (printer);
        gtk_print_operation_set_export_filename (
            print_operation, export_filename);
    }

    create_custom_widget_handler_id = g_signal_connect (
                                          print_operation, "create-custom-widget",
                                          G_CALLBACK (mail_printer_create_custom_widget_cb),
                                          async_context);

    custom_widget_apply_handler_id = g_signal_connect (
                                         print_operation, "custom-widget-apply",
                                         G_CALLBACK (mail_printer_custom_widget_apply_cb),
                                         async_context);

    draw_page_handler_id = g_signal_connect (
                               print_operation, "draw-page",
                               G_CALLBACK (mail_printer_draw_footer_cb),
                               async_context->cancellable);

    web_frame = webkit_web_view_get_main_frame (async_context->web_view);

    async_context->print_result = webkit_web_frame_print_full (
                                      web_frame, print_operation, print_action, &error);

    /* Sanity check. */
    switch (async_context->print_result) {
    case GTK_PRINT_OPERATION_RESULT_ERROR:
        if (error == NULL)
            g_warning (
                "WebKit print operation returned "
                "ERROR result without setting a "
                "GError");
        break;
    case GTK_PRINT_OPERATION_RESULT_APPLY:
        if (error != NULL)
            g_warning (
                "WebKit print operation returned "
                "APPLY result but also set a GError");
        break;
    case GTK_PRINT_OPERATION_RESULT_CANCEL:
        if (error != NULL)
            g_warning (
                "WebKit print operation returned "
                "CANCEL result but also set a GError");
        break;
    default:
        g_warn_if_reached ();
    }

    g_signal_handler_disconnect (
        print_operation, create_custom_widget_handler_id);

    g_signal_handler_disconnect (
        print_operation, custom_widget_apply_handler_id);

    g_signal_handler_disconnect (
        print_operation, draw_page_handler_id);

    g_object_unref (print_operation);

    g_object_unref (printer);

exit:
    if (error != NULL)
        g_simple_async_result_take_error (simple, error);

    g_simple_async_result_complete_in_idle (simple);

    return FALSE;
}