Ejemplo n.º 1
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;
}
Ejemplo n.º 2
0
void XAP_UnixDialog_Print::PrintDirectly(XAP_Frame * pFrame, const char * szFilename, const char * szPrinter)
{
	m_pFrame = pFrame;
	setupPrint();
	if(szFilename)
    {
		 gtk_print_operation_set_export_filename(m_pPO, szFilename);
		 gtk_print_operation_run (m_pPO,GTK_PRINT_OPERATION_ACTION_EXPORT,
								  NULL,NULL);
	}
	else
	{
		GtkPrintSettings *  pSettings = gtk_print_operation_get_print_settings(m_pPO);
		if(szPrinter)
		{
			gtk_print_settings_set_printer(pSettings, szPrinter);
		}
		else
		{
			gtk_print_settings_set_printer(pSettings, GTK_PRINT_SETTINGS_PRINTER);
		}
		gtk_print_operation_set_print_settings(m_pPO,pSettings);
		gtk_print_operation_run (m_pPO,GTK_PRINT_OPERATION_ACTION_PRINT,
								 NULL,NULL);
	}
	cleanup();
}
Ejemplo n.º 3
0
void create_gtkprint_session(GtkTextView *text_view, const gchar *title)
{
	GtkPrintOperation *op;
	GtkPrintOperationResult res;
	GError *err = NULL;
	
	page_title = title;
	op = create_print_operation(text_view);
	
	res = gtk_print_operation_run(op, GTK_PRINT_OPERATION_ACTION_PRINT_DIALOG,
		GTK_WINDOW(gtk_widget_get_toplevel(GTK_WIDGET(text_view))), &err);
	switch (res) {
	case GTK_PRINT_OPERATION_RESULT_ERROR:
		create_error_dialog(text_view, err->message);
		g_error_free(err);
	case GTK_PRINT_OPERATION_RESULT_APPLY:
		if (settings)
			g_object_unref(settings);
		settings = g_object_ref(gtk_print_operation_get_print_settings(op));
	default:
		break;
	}
	
	g_object_unref(op);
}
Ejemplo n.º 4
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");
}
Ejemplo n.º 5
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);
}
Ejemplo n.º 6
0
static void
photos_base_item_print_load (GObject *source_object, GAsyncResult *res, gpointer user_data)
{
  PhotosBaseItem *self = PHOTOS_BASE_ITEM (source_object);
  GtkWindow *toplevel = GTK_WINDOW (user_data);
  GeglNode *node;
  GtkPrintOperation *print_op;

  node = photos_base_item_load_finish (self, res, NULL);
  if (node == NULL)
    goto out;

  print_op = photos_print_operation_new (self, node);
  g_signal_connect_data (print_op,
                         "done",
                         G_CALLBACK (photos_base_item_print_operation_done),
                         g_object_ref (self),
                         (GClosureNotify) g_object_unref,
                         G_CONNECT_SWAPPED);


  /* It is self managing. */
  photos_print_notification_new (print_op);

  gtk_print_operation_run (print_op, GTK_PRINT_OPERATION_ACTION_PRINT_DIALOG, toplevel, NULL);

 out:
  g_clear_object (&node);
  g_object_unref (toplevel);
}
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);
}
Ejemplo n.º 8
0
static void
get_view_ready_cb (GObject *source_object,
                   GAsyncResult *result,
                   gpointer user_data)
{
	GtkPrintOperation *operation = user_data;
	EBookClient *book_client = E_BOOK_CLIENT (source_object);
	EBookClientView *client_view = NULL;
	EContactPrintContext *ctxt;
	GError *error = NULL;

	e_book_client_get_view_finish (book_client, result, &client_view, &error);

	ctxt = g_object_get_data (G_OBJECT (operation), "contact-print-ctx");
	g_return_if_fail (ctxt != NULL);

	if (error != NULL) {
		g_warning (
			"%s: Failed to get view: %s",
			G_STRFUNC, error->message);
		g_error_free (error);

		gtk_print_operation_run (operation, ctxt->action, NULL, NULL);
		g_object_unref (operation);
	} else {
		g_signal_connect (
			client_view, "objects-added",
			G_CALLBACK (contacts_added), ctxt);
		g_signal_connect (
			client_view, "complete",
			G_CALLBACK (view_complete), operation);

		e_book_client_view_start (client_view, &error);

		if (error != NULL) {
			g_warning (
				"%s: Failed to start view: %s",
				G_STRFUNC, error->message);
			g_error_free (error);

			gtk_print_operation_run (operation, ctxt->action, NULL, NULL);
			g_object_unref (operation);
		}
	}
}
Ejemplo n.º 9
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);
}
Ejemplo n.º 10
0
void
calendar_print_start_cb (GtkWidget *widget, gpointer user_data)
{
	GUI *appGUI = (GUI *) user_data;

	GtkPrintOperation *print;
	GtkPrintOperationResult result;
	GError *error = NULL;
	gchar buffer[BUFFER_SIZE];

	g_strlcpy (config.cal_print_month_name_font, gtk_entry_get_text
	    (GTK_ENTRY (appGUI->cal->print_month_name_font_entry)), MAXFONTNAME);
	g_strlcpy (config.cal_print_day_name_font, gtk_entry_get_text
	    (GTK_ENTRY (appGUI->cal->print_day_name_font_entry)), MAXFONTNAME);
	g_strlcpy (config.cal_print_day_num_font, gtk_entry_get_text
	    (GTK_ENTRY (appGUI->cal->print_day_num_font_entry)), MAXFONTNAME);
	g_strlcpy (config.cal_print_event_font, gtk_entry_get_text
	    (GTK_ENTRY (appGUI->cal->print_event_font_entry)), MAXFONTNAME);
	config.cal_print_event_length = gtk_spin_button_get_value
	    (GTK_SPIN_BUTTON (appGUI->cal->print_event_length_spinbutton));
	config.cal_print_padding = gtk_spin_button_get_value
	    (GTK_SPIN_BUTTON (appGUI->cal->print_padding_spinbutton));
	config.cal_print_page_orientation = gtk_toggle_button_get_active
	    (GTK_TOGGLE_BUTTON (appGUI->cal->print_portrait_radiobutton)) ? PORTRAIT : LANDSCAPE;
	config.cal_print_tasks = gtk_toggle_button_get_active
	    (GTK_TOGGLE_BUTTON (appGUI->cal->print_tasks_checkbutton));
	config.cal_print_birthdays = gtk_toggle_button_get_active
	    (GTK_TOGGLE_BUTTON (appGUI->cal->print_birthdays_checkbutton));
	config.cal_print_namedays = gtk_toggle_button_get_active
	    (GTK_TOGGLE_BUTTON (appGUI->cal->print_namedays_checkbutton));
	config.cal_print_day_notes = gtk_toggle_button_get_active
	    (GTK_TOGGLE_BUTTON (appGUI->cal->print_day_notes_checkbutton));
	config.cal_print_ical = gtk_toggle_button_get_active
	    (GTK_TOGGLE_BUTTON (appGUI->cal->print_ical_checkbutton));

	gtk_widget_destroy (appGUI->cal->window_print_options);

    print = gtk_print_operation_new ();

    appGUI->print_lines_per_page = 0;
    appGUI->print_nlines = 0;
    appGUI->print_npages = 0;

    g_signal_connect (print, "begin_print", G_CALLBACK (calendar_begin_print), appGUI);
    g_signal_connect (print, "draw_page", G_CALLBACK (calendar_draw_page), appGUI);

    result = gtk_print_operation_run (print, GTK_PRINT_OPERATION_ACTION_PRINT_DIALOG,
                                      GTK_WINDOW (appGUI->main_window), &error);

    if (result == GTK_PRINT_OPERATION_RESULT_ERROR) {
	    g_snprintf (buffer, BUFFER_SIZE, "%s: %s", _("Error printing"), error->message);
        utl_gui_create_dialog (GTK_MESSAGE_ERROR, buffer, GTK_WINDOW (appGUI->main_window));
        g_error_free (error);
    }

    g_object_unref (print);
}
Ejemplo n.º 11
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);
}
Ejemplo n.º 12
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;
}
Ejemplo n.º 13
0
Archivo: print.c Proyecto: gdt/viking
void a_print(VikWindow *vw, VikViewport *vvp)
{
  /* TODO: make print_settings non-static when saving_settings_to_file is
   * implemented. Keep it static for now to retain settings for each
   * viking session
   */
  static GtkPrintSettings *print_settings = NULL;

  GtkPrintOperation *print_oper;
  GtkPrintOperationResult res;
  PrintData data;

  print_oper = gtk_print_operation_new ();

  data.num_pages     = 1;
  data.vw            = vw;
  data.vvp           = vvp;
  data.offset_x      = 0;
  data.offset_y      = 0;
  data.center        = VIK_PRINT_CENTER_BOTH;
  data.use_full_page = FALSE;
  data.operation     = print_oper;

  data.xmpp          = vik_viewport_get_xmpp(vvp);
  data.ympp          = vik_viewport_get_ympp(vvp);
  data.width         = vik_viewport_get_width(vvp);
  data.height        = vik_viewport_get_height(vvp);

  data.xres = data.yres = 230;   /* FIXME */

  if (print_settings != NULL) 
    gtk_print_operation_set_print_settings (print_oper, print_settings);

  g_signal_connect (print_oper, "begin_print", G_CALLBACK (begin_print), &data);
  g_signal_connect (print_oper, "draw_page", G_CALLBACK (draw_page), &data);
  g_signal_connect (print_oper, "end-print", G_CALLBACK (end_print), &data);
  g_signal_connect (print_oper, "create-custom-widget", G_CALLBACK (create_custom_widget_cb), &data);

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

  res = gtk_print_operation_run (print_oper,
                                 GTK_PRINT_OPERATION_ACTION_PRINT_DIALOG,
                                 GTK_WINDOW (vw), NULL);

  if (res == GTK_PRINT_OPERATION_RESULT_APPLY) {
    if (print_settings != NULL)
      g_object_unref (print_settings);
    print_settings = g_object_ref (gtk_print_operation_get_print_settings (print_oper));
  }

  g_object_unref (print_oper);
}
Ejemplo n.º 14
0
Archivo: print.c Proyecto: pwmt/zathura
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);
}
Ejemplo n.º 15
0
static void draw_page(GtkPrintOperation *operation,
			GtkPrintContext *context,
			gint page_nr,
			gpointer user_data)
{
	cairo_t *cr;
	PangoLayout *layout;
	double w, h;
	struct graphics_context gc = { .printer = 1 };

	cr = gtk_print_context_get_cairo_context(context);
	gc.cr = cr;

	layout=gtk_print_context_create_pango_layout(context);

	w = gtk_print_context_get_width(context);
	h = gtk_print_context_get_height(context);

	/* Do the profile on the top half of the page.. */
	plot(&gc, w, h/2, current_dive);

	pango_cairo_show_layout(cr,layout);
	g_object_unref(layout);
}

static void begin_print(GtkPrintOperation *operation, gpointer user_data)
{
}

static GtkPrintSettings *settings = NULL;

void do_print(void)
{
	GtkPrintOperation *print;
	GtkPrintOperationResult res;

	print = gtk_print_operation_new();
	if (settings != NULL)
		gtk_print_operation_set_print_settings(print, settings);
	gtk_print_operation_set_n_pages(print, 1);
	g_signal_connect(print, "begin_print", G_CALLBACK(begin_print), NULL);
	g_signal_connect(print, "draw_page", G_CALLBACK(draw_page), NULL);
	res = gtk_print_operation_run(print, GTK_PRINT_OPERATION_ACTION_PRINT_DIALOG,
					 GTK_WINDOW(main_window), 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(print));
	}
	g_object_unref(print);
}
Ejemplo n.º 16
0
void
cairo_print_callback (DiagramData *data,
                      const gchar *filename,
                      guint flags, /* further additions */
                      void *user_data)
{
  GtkPrintOperation *op = create_print_operation (data, filename ? filename : "diagram");
  GtkPrintOperationResult res;
  GError *error = NULL;
  
  res = gtk_print_operation_run (op, GTK_PRINT_OPERATION_ACTION_PRINT_DIALOG, NULL, &error);
  if (GTK_PRINT_OPERATION_RESULT_ERROR == res) {
    message_error (error->message);
    g_error_free (error);
  }
}
Ejemplo n.º 17
0
void
e_contact_print (EBookClient *book_client,
                 EBookQuery *query,
                 const GSList *contact_list,
                 GtkPrintOperationAction action)
{
	GtkPrintOperation *operation;
	EContactPrintContext *ctxt;

	ctxt = g_new0 (EContactPrintContext, 1);
	ctxt->action = action;
	ctxt->contact_list = e_client_util_copy_object_slist (NULL, contact_list);
	ctxt->style = g_new0 (EContactPrintStyle, 1);
	ctxt->page_nr = 0;
	ctxt->pages = 0;

	operation = e_print_operation_new ();
	gtk_print_operation_set_n_pages (operation, 1);

	g_object_set_data_full (
		G_OBJECT (operation), "contact-print-ctx", ctxt, g_free);

	g_signal_connect (
		operation, "begin-print",
		G_CALLBACK (contact_begin_print), ctxt);
	g_signal_connect (
		operation, "draw_page",
		G_CALLBACK (contact_draw_page), ctxt);
	g_signal_connect (
		operation, "end-print",
		G_CALLBACK (contact_end_print), ctxt);

	if (book_client) {
		gchar *query_str = e_book_query_to_string (query);

		e_book_client_get_view (
			book_client, query_str, NULL,
			get_view_ready_cb, operation);

		g_free (query_str);
	} else {
		gtk_print_operation_run (operation, action, NULL, NULL);

		g_object_unref (operation);
	}
}
Ejemplo n.º 18
0
static void
print_pixbuf (GObject * ignored, gpointer user_data)
{
  GtkPrintOperation *print;
  GtkPrintOperationResult res;
  ViewerCbInfo *info = (ViewerCbInfo *) user_data;

  print = gtk_print_operation_new ();

  g_signal_connect (print, "begin_print", G_CALLBACK (begin_print), info);
  g_signal_connect (print, "draw_page", G_CALLBACK (draw_page), info);

  res = gtk_print_operation_run (print, GTK_PRINT_OPERATION_ACTION_PRINT_DIALOG,
                                 GTK_WINDOW (info->window), NULL);

  g_object_unref (print);
}
Ejemplo n.º 19
0
void create_gtkprint_preview_session(GtkTextView *text_view, const gchar *title)
{
	GtkPrintOperation *op;
	GtkPrintOperationResult res;
	GError *err = NULL;
	
	page_title = title;
	op = create_print_operation(text_view);
	
	res = gtk_print_operation_run(op, GTK_PRINT_OPERATION_ACTION_PREVIEW,
		GTK_WINDOW(gtk_widget_get_toplevel(GTK_WIDGET(text_view))), &err);
	if (res == GTK_PRINT_OPERATION_RESULT_ERROR) {
		create_error_dialog(text_view, err->message);
		g_error_free(err);
	}
	
	g_object_unref(op);
}
Ejemplo n.º 20
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;
}
Ejemplo n.º 21
0
/* File->Print... */
void
action_print(GtkAction *action, I7Document *document)
{
	GError *error = NULL;
	I7App *theapp = i7_app_get();
	GtkPrintOperation *print = gtk_print_operation_new();
	GtkPrintSettings *settings = i7_app_get_print_settings(theapp);

	if(settings)
		gtk_print_operation_set_print_settings(print, settings);

	g_signal_connect(print, "begin-print", G_CALLBACK(on_begin_print), document);

	GtkPrintOperationResult result = gtk_print_operation_run(print, GTK_PRINT_OPERATION_ACTION_PRINT_DIALOG, GTK_WINDOW(document), &error);
	if(result == GTK_PRINT_OPERATION_RESULT_APPLY)
		i7_app_set_print_settings(theapp, g_object_ref(gtk_print_operation_get_print_settings(print)));
	else if(result == GTK_PRINT_OPERATION_RESULT_ERROR) /* TRANSLATORS: File->Print... */
		error_dialog(GTK_WINDOW(document), error, _("There was an error printing: "));
	g_object_unref(print);
}
Ejemplo n.º 22
0
void XAP_UnixDialog_Print::runModal(XAP_Frame * pFrame) 
{
	m_pFrame = pFrame;
	setupPrint();
    gtk_print_operation_set_show_progress(m_pPO, TRUE);

	XAP_UnixFrameImpl * pUnixFrameImpl = static_cast<XAP_UnixFrameImpl *>(m_pFrame->getFrameImpl());
	
	// Get the GtkWindow of the parent frame
	GtkWidget * parent = pUnixFrameImpl->getTopLevelWindow();
	GtkWindow * pPWindow = GTK_WINDOW(parent);
	//	const XAP_StringSet * pSS = XAP_App::getApp()->getStringSet();
	//	const gchar * szDialogName = einterpret_cast<const gchar *>(pSS->getValue(XAP_STRING_ID_DLG_UP_PrintTitle);

	gtk_print_operation_run (m_pPO,
							 (m_bIsPreview)? GTK_PRINT_OPERATION_ACTION_PREVIEW:
							 GTK_PRINT_OPERATION_ACTION_PRINT_DIALOG,
							 pPWindow, NULL);

	cleanup();
}
Ejemplo n.º 23
0
static VALUE
po_run(int argc, VALUE *argv, VALUE self)
{
    VALUE action, parent, rb_result;
    GtkPrintOperationResult result;
    GError *error = NULL;

    rb_scan_args(argc, argv, "11", &action, &parent);

    result = gtk_print_operation_run(_SELF(self), 
                                     RVAL2GENUM(action, GTK_TYPE_PRINT_OPERATION_ACTION),
                                     RVAL2GOBJ(parent), &error);

    rb_result = GENUM2RVAL(result, GTK_TYPE_PRINT_OPERATION_RESULT);
    if (rb_block_given_p()) {
        return rb_yield(rb_result);
    } else {
        if (result == GTK_PRINT_OPERATION_RESULT_ERROR)
            RAISE_GERROR(error);
        return rb_result;
    }
}
Ejemplo n.º 24
0
static void
print_or_preview (GSimpleAction *action, GtkPrintOperationAction print_action)
{
  GtkPrintOperation *print;
  PrintData *print_data;

  print_data = g_new0 (PrintData, 1);

  print_data->text = get_text ();
  print_data->font = g_strdup ("Sans 12");

  print = gtk_print_operation_new ();

  gtk_print_operation_set_track_print_status (print, TRUE);

  if (settings != NULL)
    gtk_print_operation_set_print_settings (print, settings);

  if (page_setup != NULL)
    gtk_print_operation_set_default_page_setup (print, page_setup);

  g_signal_connect (print, "begin_print", G_CALLBACK (begin_print), print_data);
  g_signal_connect (print, "end-print", G_CALLBACK (end_print), print_data);
  g_signal_connect (print, "draw_page", G_CALLBACK (draw_page), print_data);
  g_signal_connect (print, "create_custom_widget", G_CALLBACK (create_custom_widget), print_data);
  g_signal_connect (print, "custom_widget_apply", G_CALLBACK (custom_widget_apply), print_data);
  g_signal_connect (print, "preview", G_CALLBACK (preview_cb), print_data);

  g_signal_connect (print, "done", G_CALLBACK (print_done), print_data);

  gtk_print_operation_set_export_filename (print, "test.pdf");

#if 0
  gtk_print_operation_set_allow_async (print, TRUE);
#endif
  gtk_print_operation_run (print, print_action, GTK_WINDOW (main_window), NULL);

  g_object_unref (print);
}
Ejemplo n.º 25
0
static void
view_complete (EBookClientView *client_view,
               const GError *error,
               GtkPrintOperation *operation)
{
	EContactPrintContext *ctxt;

	g_return_if_fail (operation != NULL);

	ctxt = g_object_get_data (G_OBJECT (operation), "contact-print-ctx");
	g_return_if_fail (ctxt != NULL);

	e_book_client_view_stop (client_view, NULL);
	g_signal_handlers_disconnect_by_func (
		client_view, G_CALLBACK (contacts_added), ctxt);
	g_signal_handlers_disconnect_by_func (
		client_view, G_CALLBACK (view_complete), operation);

	g_object_unref (client_view);

	gtk_print_operation_run (operation, ctxt->action, NULL, NULL);
	g_object_unref (operation);
}
Ejemplo n.º 26
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);
}
Ejemplo n.º 27
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;
}
Ejemplo n.º 28
0
void
gdict_show_print_dialog (GtkWindow   *parent,
			 GdictDefbox *defbox)
{
  GtkPrintOperation *operation;
  GdictPrintData *data;
  gchar *print_font;
  gchar *word;
  GError *error;
  
  g_return_if_fail (parent == NULL || GTK_IS_WINDOW (parent));
  g_return_if_fail (GDICT_IS_DEFBOX (defbox));

  g_object_get (defbox, "word", &word, NULL);
  if (!word)
    {
      g_warning ("Print should be disabled.");
      return;
    }

  data = g_new0 (GdictPrintData, 1);
  data->defbox = defbox;
  data->word = word;

  operation = gtk_print_operation_new ();
  print_font = get_print_font ();
  data->font_desc = pango_font_description_from_string (print_font);
  data->font_size = pango_font_description_get_size (data->font_desc)
                    / PANGO_SCALE;
  g_free (print_font);

  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), data);

  error = NULL;
  gtk_print_operation_run (operation,
                           GTK_PRINT_OPERATION_ACTION_PRINT_DIALOG,
                           parent,
                           &error);
  g_object_unref (operation);

  if (error)
    {
      GtkWidget *dialog;

      dialog = gtk_message_dialog_new (parent,
                                       GTK_DIALOG_DESTROY_WITH_PARENT,
                                       GTK_MESSAGE_ERROR,
                                       GTK_BUTTONS_CLOSE,
				       _("Unable to display the preview: %s"),
                                       error->message);
      g_error_free (error);

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

      gtk_widget_show (dialog);
    }
}
Ejemplo n.º 29
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;
}
Ejemplo n.º 30
0
 int PrintText(const char *name, gchar *text)
 {
	GKeyFile			*conf	= GetConf();
 	GtkPrintOperation	*prt;
 	const gchar		*font;
	GtkPageSetup 		*page_setup = NULL;
	GtkPrintSettings 	*print_settings = NULL;

 	if(!text)
		return -EINVAL;

 	prt = gtk_print_operation_new();

 	if(!prt)
 		return -1;

	// Set job parameters
	g_object_set_data_full(G_OBJECT(prt),"3270Text",g_strsplit(g_strchomp(text),"\n",-1),(void (*)(gpointer)) g_strfreev);

	// Set print
	font = GetString("Print","Font","");
	if(!*font)
		font = GetString("Terminal","Font","Courier");

	g_object_set_data_full(G_OBJECT(prt),"3270FontName",g_strdup(font),g_free);

	// Configure print operation
	gtk_print_operation_set_job_name(prt,name);
	gtk_print_operation_set_allow_async(prt,0);
	gtk_print_operation_set_show_progress(prt,1);

	gtk_print_operation_set_custom_tab_label(prt,_( "Font" ));
	g_signal_connect(prt, "begin-print",    		G_CALLBACK(begin_print), 			0);
    g_signal_connect(prt, "draw-page",      		G_CALLBACK(draw_page),   			0);
#ifdef HAVE_PRINT_FONT_DIALOG
	g_signal_connect(prt, "create-custom-widget",   G_CALLBACK(create_custom_widget),	0);
	g_signal_connect(prt, "custom-widget-apply",   	G_CALLBACK(custom_widget_apply),	0);
#endif
    g_signal_connect(prt, "done",      				G_CALLBACK(print_done),	 			0);

	if(conf)
	{
#if GTK_CHECK_VERSION(2,12,0)
		gchar *ptr = g_key_file_get_string(conf,"Print Settings","output-uri",NULL);
		if(ptr)
		{
			gchar *uri = NULL;

			switch(*(ptr++))
			{
			case '$':
				if(g_str_has_prefix(ptr,"home/"))
					uri = g_strdup_printf("file:///%s/%s",g_get_home_dir(),ptr+5);
#if GTK_CHECK_VERSION(2,14,0)
				else if(g_str_has_prefix(ptr,"documents/"))
					uri = g_strdup_printf("file:///%s/%s",g_get_user_special_dir(G_USER_DIRECTORY_DOCUMENTS),ptr+10);
				else if(g_str_has_prefix(ptr,"desktop/"))
					uri = g_strdup_printf("file:///%s/%s",g_get_user_special_dir(G_USER_DIRECTORY_DESKTOP),ptr+8);
#endif
				break;

			case '~':
				uri = g_strdup_printf("file:///%s/%s",g_get_home_dir(),ptr);
				break;

			}

			if(uri)
			{
				g_key_file_set_string(conf,"Print Settings","output-uri",uri);
				g_free(uri);
			}
		}

		print_settings = gtk_print_settings_new_from_key_file(conf,NULL,NULL);
		page_setup = gtk_page_setup_new_from_key_file(conf,NULL,NULL);

		if(!page_setup)
			page_setup = gtk_page_setup_new();

#else // GTK_CHECK_VERSION(2,12,0)
		print_settings = gtk_print_settings_new();
		if(print_settings)
		{
			gchar 				**list;
			int 				f;

			list = g_key_file_get_keys(conf,"PrintSettings",NULL,NULL);
			if(list)
			{
				for(f=0;list[f];f++)
					gtk_print_settings_set(print_settings,list[f],g_key_file_get_string(conf,"PrintSettings",list[f],NULL));
				g_strfreev(list);
			}
		}
		page_setup = gtk_page_setup_new();
#endif
	}
	else
	{
		page_setup = gtk_page_setup_new();
		gtk_print_operation_set_print_settings(prt,gtk_print_settings_new());
	}

	Trace("page_setup: %p print_settings: %p",page_setup,print_settings);
	gtk_print_operation_set_print_settings(prt,print_settings);
	gtk_print_operation_set_default_page_setup(prt,page_setup);


	// Run Print dialog
	gtk_print_operation_run(prt,GTK_PRINT_OPERATION_ACTION_PRINT_DIALOG,GTK_WINDOW(topwindow),NULL);

    g_object_unref(prt);

    return 0;
 }