static void
ide_editor_view_actions_print (GSimpleAction *action,
                               GVariant      *param,
                               gpointer       user_data)
{
  IdeEditorView *self = user_data;
  GtkWidget *toplevel;
  g_autoptr(IdeEditorPrintOperation) operation;
  GtkPrintOperationResult result;

  g_assert (IDE_IS_EDITOR_VIEW (self));

  toplevel = gtk_widget_get_toplevel (GTK_WIDGET (self));

  operation = ide_editor_print_operation_new (self->frame1->source_view);

  /* keep a ref until "done" is emitted */
  g_object_ref (operation);

  g_signal_connect_after (operation, "done", G_CALLBACK (print_done), g_object_ref (self));

  result = gtk_print_operation_run (GTK_PRINT_OPERATION (operation),
                                    GTK_PRINT_OPERATION_ACTION_PRINT_DIALOG,
                                    GTK_WINDOW (toplevel),
                                    NULL);

  handle_print_result (self, GTK_PRINT_OPERATION (operation), result);
}
Example #2
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;
}
Example #3
0
void
gl_ui_cmd_file_print (GtkAction *action,
                      glWindow  *window)
{
        glPrintOpDialog         *op;
        GtkPrintOperationResult  result;

        gl_debug (DEBUG_COMMANDS, "START");

        g_return_if_fail (action && GTK_IS_ACTION(action));
        g_return_if_fail (window && GL_IS_WINDOW(window));

        op = gl_print_op_dialog_new (GL_VIEW(window->view)->label);

        if (window->print_settings)
        {
                gl_print_op_set_settings (GL_PRINT_OP (op), window->print_settings);
        }

        result = gtk_print_operation_run (GTK_PRINT_OPERATION (op),
                                          GTK_PRINT_OPERATION_ACTION_PRINT_DIALOG,
                                          GTK_WINDOW (window),
                                          NULL);

        if ( result == GTK_PRINT_OPERATION_RESULT_APPLY )
        {
                gl_print_op_free_settings (window->print_settings);
                window->print_settings = gl_print_op_get_settings (GL_PRINT_OP (op));
        }

        gl_debug (DEBUG_COMMANDS, "END");
}
Example #4
0
File: msg2pdf.c Project: Popsch/mu
static gboolean
print_to_pdf (WebKitWebFrame *frame, GError **err)
{
	GtkPrintOperation *op;
	GtkPrintOperationResult res;
	char *path;
	gboolean rv;

	path = g_strdup_printf ("%s%c%x.pdf",mu_util_cache_dir(),
				G_DIR_SEPARATOR, (unsigned)random());
	if (!mu_util_create_dir_maybe (mu_util_cache_dir(),0700,FALSE)) {
		g_warning ("Couldn't create tempdir");
		return FALSE;
	}


	op = gtk_print_operation_new ();
	gtk_print_operation_set_export_filename
		(GTK_PRINT_OPERATION(op), path);

	res = webkit_web_frame_print_full (frame, op,
					   GTK_PRINT_OPERATION_ACTION_EXPORT,
					   err);
	g_object_unref (op);
	rv = (res != GTK_PRINT_OPERATION_RESULT_ERROR);
	if (rv)
		g_print ("%s\n", path);

	g_free (path);
	return rv;

}
static void
photos_print_operation_init (PhotosPrintOperation *self)
{
  GtkPrintSettings *settings;

  self->unit = GTK_UNIT_INCH;
  self->left_margin = 0.0;
  self->top_margin = 0.0;
  self->scale_factor = 100.0;

  settings = gtk_print_settings_new ();
  gtk_print_operation_set_print_settings (GTK_PRINT_OPERATION (self), settings);
  g_object_unref (settings);

  gtk_print_operation_set_custom_tab_label (GTK_PRINT_OPERATION (self), _("Image Settings"));
  gtk_print_operation_set_embed_page_setup (GTK_PRINT_OPERATION (self), TRUE);
  gtk_print_operation_set_n_pages (GTK_PRINT_OPERATION (self), 1);
}
static void
photos_print_operation_constructed (GObject *object)
{
  PhotosPrintOperation *self = PHOTOS_PRINT_OPERATION (object);
  GeglRectangle bbox;
  GtkPageSetup *page_setup;
  gchar *name;

  G_OBJECT_CLASS (photos_print_operation_parent_class)->constructed (object);

  page_setup = gtk_page_setup_new ();
  gtk_print_operation_set_default_page_setup (GTK_PRINT_OPERATION (self), page_setup);

  bbox = gegl_node_get_bounding_box (self->node);
  if (bbox.height >= bbox.width)
    gtk_page_setup_set_orientation (page_setup, GTK_PAGE_ORIENTATION_PORTRAIT);
  else
    gtk_page_setup_set_orientation (page_setup, GTK_PAGE_ORIENTATION_LANDSCAPE);

  g_object_unref (page_setup);

  name = g_strdup (photos_base_item_get_name (self->item));
  if (name == NULL || name[0] == '\0')
    {
      GFile *file;
      const gchar *uri;
      gchar *basename;

      uri = photos_base_item_get_uri (self->item);
      file = g_file_new_for_uri (uri);
      basename = g_file_get_basename (file);

      if (g_utf8_validate (basename, -1, NULL))
        name = g_strdup (basename);
      else
        name = g_filename_to_utf8 (basename, -1, NULL, NULL, NULL);

      g_free (basename);
      g_object_unref (file);
    }

  gtk_print_operation_set_job_name (GTK_PRINT_OPERATION (self), name);
  g_free (name);
}
Example #7
0
void
x_print (GschemToplevel *w_current)
{
  static GtkPrintSettings *settings = NULL;
  GtkPageSetup *setup;
  GtkPrintOperation *print;
  GtkPrintOperationResult res;
  GError *err = NULL;
  int num_pages = 1;

  /* Create the print operation and set it up */
  print = GTK_PRINT_OPERATION (g_object_new (GTK_TYPE_PRINT_OPERATION,
                                             "n-pages", num_pages,
                                             "use-full-page", FALSE,
                                             "unit", GTK_UNIT_POINTS,
                                             NULL));

  if (settings != NULL) {
    gtk_print_operation_set_print_settings (print, settings);
  }
  setup = x_print_default_page_setup (w_current->toplevel,
                                      w_current->toplevel->page_current);
  gtk_print_operation_set_default_page_setup (print, setup);

  g_signal_connect (print, "draw_page", G_CALLBACK (draw_page__print_operation),
                    w_current);

  res = gtk_print_operation_run (print, GTK_PRINT_OPERATION_ACTION_PRINT_DIALOG,
                                 GTK_WINDOW (w_current->main_window), &err);

  if (res == GTK_PRINT_OPERATION_RESULT_ERROR) {
    /* If printing failed due to an error, show an error dialog */
    GtkWidget *error_dialog =
      gtk_message_dialog_new (GTK_WINDOW (w_current->main_window),
                              GTK_DIALOG_DESTROY_WITH_PARENT,
                              GTK_MESSAGE_ERROR,
                              GTK_BUTTONS_CLOSE,
                              _("Error printing file:\n%1$s"),
                              err->message);
    g_signal_connect (error_dialog, "response",
                      G_CALLBACK (gtk_widget_destroy), NULL);
    gtk_widget_show (error_dialog);
    g_error_free (err);

  } else if (res == GTK_PRINT_OPERATION_RESULT_APPLY) {
    /* We're supposed to store the print settings, so do that */
    if (settings != NULL) {
      g_object_unref (settings);
    }
    settings = GTK_PRINT_SETTINGS (g_object_ref (gtk_print_operation_get_print_settings (print)));
  }

  /* Clean up */
  g_object_unref (print);
}
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;
}
static void
photos_print_notification_set_property (GObject *object, guint prop_id, const GValue *value, GParamSpec *pspec)
{
  PhotosPrintNotification *self = PHOTOS_PRINT_NOTIFICATION (object);

  switch (prop_id)
    {
    case PROP_PRINT_OP:
      self->priv->print_op = GTK_PRINT_OPERATION (g_value_dup_object (value));
      break;

    default:
      G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
      break;
    }
}
/**
 * Function called first when try to print the transaction list
 * initialize the variables and calculate the number of pages
 *
 * \param operation	GtkPrintOperation
 * \param context	GtkPrintContext
 * \param null
 *
 * \return FALSE
 * */
gboolean print_transactions_list_begin ( GtkPrintOperation *operation,
					 GtkPrintContext *context,
					 gpointer null )
{
    CustomList *custom_list;
    gint size_transaction;
    gint size_title = 0;
    gint size_archive = 0;
    gdouble transactions_per_page_double;
    gint nb_pages;
    gint number_of_archives = 0;

    devel_debug (NULL);

    /* we need to calculate the number of pages */
    cr = gtk_print_context_get_cairo_context (context);
    custom_list = transaction_model_get_model ();

    /* get the size of the title */
    if (gsb_data_print_config_get_draw_title () && title_string && strlen (title_string))
	size_title = pango_font_description_get_size (gsb_data_print_config_get_font_title ())/PANGO_SCALE;

    /* we need the number of archives and of transactions to print
     * number_of_archives will be set to 0 if no draw archives */
    print_transactions_list_get_visibles_lines (&number_of_archives,
						&total_transactions_to_print );

/*  xxx   mk_include 2 fois de suite modifie qd même des fichiers */

    /* get the size of a complete transaction and an archive */
    size_row = pango_font_description_get_size (gsb_data_print_config_get_font_transactions ())/PANGO_SCALE;
    size_transaction = size_row * custom_list -> nb_rows_by_transaction + 2*gsb_data_print_config_get_draw_lines ();
    size_archive = size_row + 2*gsb_data_print_config_get_draw_lines ();

    /* the heigh of a page decrease of 1 line if we use the columns titles */
    page_height = gtk_print_context_get_height (context) - gsb_data_print_config_get_draw_columns_name ()*size_transaction;

    /* how much transactions we can show in a page : */
    transactions_per_page_double = page_height / size_transaction;

    if (!size_title && !gsb_data_print_config_get_draw_archives ())
    {
	/* simple way : no archives and no title */
	nb_pages = ceil ( total_transactions_to_print / transactions_per_page_double );
	transactions_in_first_page = floor (transactions_per_page_double);
    }
    else
    {
	/* there are title or archives, it's more complex because it will have less transactions
	 * on the first page */
	gint first_page_height = page_height - size_title - size_archive*number_of_archives;

	transactions_in_first_page = floor (first_page_height / size_transaction);
	nb_pages = 1 + ceil (  (total_transactions_to_print - transactions_in_first_page)/ transactions_per_page_double );
    }

    /* set the number of page */
    gtk_print_operation_set_n_pages ( GTK_PRINT_OPERATION (operation),
				      nb_pages );
    /* save the nb of transactions per page */
    transactions_per_page = floor (transactions_per_page_double);

    /* calculate the size and position of the columns */
    page_width = gtk_print_context_get_width (context);
    print_transactions_list_calculate_columns (page_width);

    total_transactions_printed = 0;
    current_row_to_print = 0;
    return FALSE;
}
Example #11
0
/**
 * Function called first when try to print the  list
 * initialize the variables and calculate the number of pages
 *
 * \param operation	GtkPrintOperation
 * \param context	GtkPrintContext
 * \param null
 *
 * \return FALSE
 * */
gboolean print_tree_view_list_begin ( GtkPrintOperation *operation,
                        GtkPrintContext *context,
                        gpointer data )
{
    GtkTreeView *tree_view = ( GtkTreeView * ) data;
    gint size_line;
    gdouble lines_per_page_double;
    gint nbre_pages;

    devel_debug (NULL);

    /* we need to calculate the number of pages */
    cr = gtk_print_context_get_cairo_context ( context );

    /* get the size of the title */
    if ( title_string && strlen ( title_string ) )
        size_title = print_tree_view_list_get_title_size ( );
    else
        size_title = 0;

    /* get the size of a row */
    size_row = pango_font_description_get_size ( gsb_data_print_config_get_font_transactions () ) / PANGO_SCALE;
    size_line = size_row + gsb_data_print_config_get_draw_lines ( );

    /* get the size of the titles of columns */
    if ( gsb_data_print_config_get_draw_columns_name () )
    {
        nbre_lines_col_title = print_tree_view_list_get_columns_title_nbre_lines ( tree_view );
        size_columns_title = print_tree_view_list_get_columns_title_size ( nbre_lines_col_title );
    }
    else
        size_columns_title = 0;

    /* the heigh of a page decrease size_columns_title */
    page_height = gtk_print_context_get_height ( context );

    /* get total lines to print */
    total_lines_to_print = 0;
    total_lines_to_print = print_tree_view_list_set_rows_to_print ( tree_view );

    /* how much transactions we can show in a page : */
    lines_per_page_double = page_height / size_line;
    /* on enlève les lignes des titres des colonnes */
    lines_per_page_double -= nbre_lines_col_title;

    if ( !size_title ) /* no title */
    {
        nbre_pages = ceil ( total_lines_to_print / lines_per_page_double );
        lines_in_first_page = floor ( lines_per_page_double );
    }
    else
    {
        gint first_page_height;

        first_page_height = page_height - size_title;

        lines_in_first_page = floor ( first_page_height / size_line ) - nbre_lines_col_title;
        nbre_pages = 1 + ceil (  ( total_lines_to_print - lines_in_first_page ) /
                                    lines_per_page_double );
    }

    /* set the number of page */
    gtk_print_operation_set_n_pages ( GTK_PRINT_OPERATION ( operation ), nbre_pages );
    /* save the nb of rows per page */
    lines_per_page = floor ( lines_per_page_double );

    /* calculate the size and position of the columns */
    page_width = gtk_print_context_get_width ( context );
    print_tree_view_list_calculate_columns_width ( tree_view, page_width );

    if ( tree_path_to_print )
        gtk_tree_path_free ( tree_path_to_print );
    tree_path_to_print = gtk_tree_path_new_first ( );
    total_lines_printed = 0;
    current_row_to_print = 0;

    return FALSE;
}