Ejemplo n.º 1
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.º 2
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;
}
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
Archivo: print.c Proyecto: gdt/viking
static void page_setup_cb (GtkWidget *widget, CustomWidgetInfo *info)
{
  PrintData *data = info->data;
  GtkPrintOperation *operation = data->operation;
  GtkPrintSettings  *settings;
  GtkPageSetup      *page_setup;
  GtkWidget         *toplevel;

  toplevel = gtk_widget_get_toplevel (widget);
#if GTK_CHECK_VERSION (2,18,0)
  if (! gtk_widget_is_toplevel (toplevel))
#else
  if (! GTK_WIDGET_TOPLEVEL (toplevel))
#endif
    toplevel = NULL;

  settings = gtk_print_operation_get_print_settings (operation);
  if (! settings)
    settings = gtk_print_settings_new ();

  page_setup = gtk_print_operation_get_default_page_setup (operation);

  page_setup = gtk_print_run_page_setup_dialog (GTK_WINDOW (toplevel),
                                                page_setup, settings);

  gtk_print_operation_set_default_page_setup (operation, page_setup);

  vik_print_preview_set_page_setup (VIK_PRINT_PREVIEW (info->preview),
                                     page_setup);

  update_page_setup (info);

}
Ejemplo n.º 5
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.º 6
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.º 7
0
void
gnc_print_operation_save_print_settings(GtkPrintOperation *op)
{
    g_return_if_fail(op);

    G_LOCK(print_settings);
    if (print_settings)
        g_object_unref(print_settings);
    print_settings = g_object_ref(gtk_print_operation_get_print_settings(op));
    G_UNLOCK(print_settings);
}
Ejemplo n.º 8
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.º 9
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.º 10
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.º 11
0
static void
print_done_cb (GtkPrintOperation *operation,
               GtkPrintOperationResult result,
               GKeyFile *key_file)
{
	GtkPrintSettings *settings;

	settings = gtk_print_operation_get_print_settings (operation);

	if (result == GTK_PRINT_OPERATION_RESULT_APPLY)
		save_settings (settings, key_file);
	if (result == GTK_PRINT_OPERATION_RESULT_ERROR)
		handle_error (operation);

	save_key_file (key_file);
	g_key_file_free (key_file);
}
Ejemplo n.º 12
0
static void
print_done (GtkPrintOperation *op,
	    GtkPrintOperationResult res,
	    PrintData *print_data)
{
  GError *error = NULL;

  if (res == GTK_PRINT_OPERATION_RESULT_ERROR)
    {

      GtkWidget *error_dialog;
      
      gtk_print_operation_get_error (op, &error);
      
      error_dialog = gtk_message_dialog_new (GTK_WINDOW (main_window),
					     GTK_DIALOG_DESTROY_WITH_PARENT,
					     GTK_MESSAGE_ERROR,
					     GTK_BUTTONS_CLOSE,
					     "Error printing file:\n%s",
					     error ? error->message : "no details");
      g_signal_connect (error_dialog, "response", G_CALLBACK (gtk_widget_destroy), NULL);
      gtk_widget_show (error_dialog);
    }
  else 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));
    }

  g_free (print_data->text);
  g_free (print_data->font);
  g_free (print_data);
  
  if (!gtk_print_operation_is_finished (op))
    {
      g_object_ref (op);
      active_prints = g_list_append (active_prints, op);
      update_statusbar ();
      
      /* This ref is unref:ed when we get the final state change */
      g_signal_connect (op, "status_changed",
			G_CALLBACK (status_changed_cb), NULL);
    }
}
Ejemplo n.º 13
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.º 14
0
/*
 * serialize print settings into a GKeyFile
 */
static GKeyFile *
print_settings_key_file_from_settings (PrintData *data)
{
  GtkPrintOperation *operation = data->operation;
  GtkPrintSettings  *settings;
  GKeyFile          *key_file  = g_key_file_new ();

  /* put version information into the file */
  g_key_file_set_integer (key_file, "meta", "major-version",
                          PRINT_SETTINGS_MAJOR_VERSION);
  g_key_file_set_integer (key_file, "meta", "minor-version",
                          PRINT_SETTINGS_MINOR_VERSION);

  /* save the contents of the GtkPrintSettings for the operation */
  settings = gtk_print_operation_get_print_settings (operation);

  if (settings)
    gtk_print_settings_foreach (settings,
                                print_settings_add_to_key_file, key_file);

  return key_file;
}
Ejemplo n.º 15
0
void XAP_UnixDialog_Print::cleanup(void)
{
	//
	// Get the filename we printed to
	//
	GtkPrintSettings *  pSettings = gtk_print_operation_get_print_settings(m_pPO);
	const gchar * szFname =  gtk_print_settings_get(pSettings,GTK_PRINT_SETTINGS_OUTPUT_URI);
	if((szFname != NULL) && (strcmp(szFname,"output.pdf") != 0))
	{
		m_pView->getDocument()->setPrintFilename(szFname);
	}
	g_object_unref(m_pPO);
	m_pPO= NULL;
	if(!m_bDidQuickPrint)
	{
		UT_DEBUGMSG(("Deleting PrintView %p \n",m_pPrintView));
		DELETEP(m_pPrintLayout);
		DELETEP(m_pPrintView);
	}
	else
	{
		if(m_pPrintLayout)
			m_pPrintLayout->setQuickPrint(NULL);
		m_pPrintLayout = NULL;
		m_pPrintView = NULL;

		if(m_bShowParagraphs)
			m_pView->setShowPara(true);
		m_pDL->incrementGraphicTick();
	}
	UT_DEBUGMSG(("Reset fontmap m_pView %p Graphics %p \n",m_pView,m_pView->getGraphics()));
	static_cast<GR_CairoGraphics *>(m_pView->getGraphics())->resetFontMapResolution();
	DELETEP(m_pPrintGraphics);
	//
	// Finish pending expose events.
	//
	m_pFrame->nullUpdate();
}
Ejemplo n.º 16
0
static void
cb_print_done(GtkPrintOperation* operation, GtkPrintOperationResult result,
              zathura_t* zathura)
{
  if (result == GTK_PRINT_OPERATION_RESULT_APPLY) {
    if (zathura->print.settings != NULL) {
      g_object_unref(zathura->print.settings);
    }
    if (zathura->print.page_setup != NULL) {
      g_object_unref(zathura->print.page_setup);
    }

    /* save previous settings */
    zathura->print.settings   = g_object_ref(gtk_print_operation_get_print_settings(operation));
    zathura->print.page_setup = g_object_ref(gtk_print_operation_get_default_page_setup(operation));
  } else if (result == GTK_PRINT_OPERATION_RESULT_ERROR) {
    GError* error = NULL;
    gtk_print_operation_get_error(operation, &error);
    girara_notify(zathura->ui.session, GIRARA_ERROR, _("Printing failed: %s"),
                  error->message);
    g_error_free(error);
  }
}
Ejemplo n.º 17
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.º 18
0
 static void print_done(GtkPrintOperation *prt, GtkPrintOperationResult result, gpointer user_data)
 {
	GKeyFile 				*conf		= GetConf();

	GtkPrintSettings		*settings	= gtk_print_operation_get_print_settings(prt);

#if GTK_CHECK_VERSION(2,12,0)
	GtkPageSetup			*setup		= gtk_print_operation_get_default_page_setup(prt);
#endif

	if(!conf)
		return;

#if GTK_CHECK_VERSION(2,12,0)
	Trace("Settings: %p Conf: %p page_setup: %p",settings,conf,setup);
	gtk_print_settings_to_key_file(settings,conf,NULL);
	gtk_page_setup_to_key_file(setup,conf,NULL);
#else
	gtk_print_settings_foreach(settings,(GtkPrintSettingsFunc) SavePrintSetting,conf);
#endif

	g_key_file_set_string(conf,"Print","Font",g_object_get_data(G_OBJECT(prt),"3270FontName"));

 }
Ejemplo n.º 19
0
void
CmOutputPrinter(int select_file, int show_dialog)
{
  GtkPrintOperation *print;
  GtkPrintOperationResult res;
  char buf[MESSAGE_BUF_SIZE];
  struct objlist *graobj, *g2wobj;
  int id, g2wid, g2woid, opt;
  N_VALUE *g2winst;
  GError *error;
  struct print_obj pobj;
  GtkPaperSize *paper_size;
  GtkPageSetup *page_setup;

  if (Menulock || Globallock)
    return;

  if (select_file && ! SetFileHidden())
    return;

  FileAutoScale();
  AdjustAxis();

  graobj = chkobject("gra");
  if (graobj == NULL)
    return;

  g2wobj = chkobject("gra2gtkprint");
  if (g2wobj == NULL)
    return;

  g2wid = newobj(g2wobj);
  if (g2wid < 0)
    return;

  putobj(g2wobj, "use_opacity", g2wid, &Menulocal.use_opacity);

  g2winst = chkobjinst(g2wobj, g2wid);
  _getobj(g2wobj, "oid", g2winst, &g2woid);
  id = newobj(graobj);
  init_graobj(graobj, id, "gra2gtkprint", g2woid);

  print = gtk_print_operation_new();
  gtk_print_operation_set_n_pages(print, 1);
#if GTK_CHECK_VERSION(2, 18, 0)
  gtk_print_operation_set_has_selection(print, FALSE);
  gtk_print_operation_set_support_selection(print, FALSE);
  gtk_print_operation_set_embed_page_setup(print, FALSE);
#endif
  gtk_print_operation_set_use_full_page(print, TRUE);

  if (PrintSettings == NULL)
    PrintSettings = gtk_print_settings_new();

  if (Menulocal.PaperId == PAPER_ID_CUSTOM) {
    paper_size = gtk_paper_size_new_custom(Menulocal.PaperName,
					   Menulocal.PaperName,
					   Menulocal.PaperWidth / 100.0,
					   Menulocal.PaperHeight / 100.0,
					   GTK_UNIT_MM);
  } else {
    paper_size = gtk_paper_size_new(Menulocal.PaperName);
  }

  page_setup = gtk_page_setup_new();
  gtk_page_setup_set_paper_size(page_setup, paper_size);
  if (Menulocal.PaperLandscape) {
    gtk_page_setup_set_orientation(page_setup, GTK_PAGE_ORIENTATION_LANDSCAPE);
  } else {
    gtk_page_setup_set_orientation(page_setup, GTK_PAGE_ORIENTATION_PORTRAIT);
  }

  gtk_print_operation_set_default_page_setup(print, page_setup);
  gtk_print_operation_set_print_settings(print, PrintSettings);

  pobj.graobj = graobj;
  pobj.id = id;
  pobj.g2wobj = g2wobj;
  pobj.g2winst = g2winst;
  g_signal_connect(print, "draw_page", G_CALLBACK(draw_page), &pobj);

  switch (show_dialog) {
  case PRINT_SHOW_DIALOG_NONE:
    opt = GTK_PRINT_OPERATION_ACTION_PRINT;
    break;
  case PRINT_SHOW_DIALOG_PREVIEW:
    opt = GTK_PRINT_OPERATION_ACTION_PREVIEW;
    break;
  case PRINT_SHOW_DIALOG_DIALOG:
    opt = GTK_PRINT_OPERATION_ACTION_PRINT_DIALOG;
    break;
  default:
    opt = GTK_PRINT_OPERATION_ACTION_PRINT_DIALOG;
  }

  res = gtk_print_operation_run(print, opt, GTK_WINDOW(TopLevel), &error);

  if (res == GTK_PRINT_OPERATION_RESULT_ERROR) {
    snprintf(buf, sizeof(buf), _("Printing error: %s"), error->message);
    message_box(NULL, buf, _("Print"), RESPONS_ERROR);
    g_error_free(error);
  } else if (res == GTK_PRINT_OPERATION_RESULT_APPLY) {
    if (PrintSettings)
      g_object_unref(PrintSettings);
    PrintSettings = g_object_ref(gtk_print_operation_get_print_settings(print));
  }
  g_object_unref(print);

  delobj(graobj, id);
  delobj(g2wobj, g2wid);

  if (select_file && NgraphApp.FileWin.data.data) {
    FileWinUpdate(NgraphApp.FileWin.data.data, TRUE);
  }
}
Ejemplo n.º 20
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
}
Ejemplo n.º 21
0
static gboolean 
preview_cb (GtkPrintOperation        *op,
	    GtkPrintOperationPreview *preview,
	    GtkPrintContext          *context,
	    GtkWindow                *parent,
	    gpointer                  data)
{
  GtkPrintSettings *settings;
  GtkWidget *window, *close, *page, *hbox, *vbox, *da;
  gdouble width, height;
  cairo_t *cr;
  PreviewOp *pop;
  PrintData *print_data = data;

  pop = g_new0 (PreviewOp, 1);

  pop->data = print_data;
  settings = gtk_print_operation_get_print_settings (op);

  width = 200;
  height = 300;
  window = gtk_window_new (GTK_WINDOW_TOPLEVEL);
  gtk_window_set_transient_for (GTK_WINDOW (window), 
				GTK_WINDOW (main_window));
  vbox = gtk_vbox_new (FALSE, 0);
  gtk_container_add (GTK_CONTAINER (window), vbox);
  hbox = gtk_hbox_new (FALSE, 0);
  gtk_box_pack_start (GTK_BOX (vbox), hbox,
		      FALSE, FALSE, 0);
  page = gtk_spin_button_new_with_range (1, 100, 1);
  gtk_box_pack_start (GTK_BOX (hbox), page, FALSE, FALSE, 0);
  
  close = gtk_button_new_from_stock (GTK_STOCK_CLOSE);
  gtk_box_pack_start (GTK_BOX (hbox), close, FALSE, FALSE, 0);

  da = gtk_drawing_area_new ();
  gtk_widget_set_size_request (GTK_WIDGET (da), width, height);
  gtk_box_pack_start (GTK_BOX (vbox), da, TRUE, TRUE, 0);

  gtk_widget_set_double_buffered (da, FALSE);

  gtk_widget_realize (da);
  
  cr = gdk_cairo_create (da->window);

  /* TODO: What dpi to use here? This will be used for pagination.. */
  gtk_print_context_set_cairo_context (context, cr, 72, 72);
  cairo_destroy (cr);
  
  pop->op = g_object_ref (op);
  pop->preview = preview;
  pop->spin = page;
  pop->area = da;
  pop->page = 1;

  g_signal_connect (page, "value-changed", 
		    G_CALLBACK (update_page), pop);
  g_signal_connect_swapped (close, "clicked", 
			    G_CALLBACK (gtk_widget_destroy), window);

  g_signal_connect (preview, "ready",
		    G_CALLBACK (preview_ready), pop);
  g_signal_connect (preview, "got-page-size",
		    G_CALLBACK (preview_got_page_size), pop);

  g_signal_connect (window, "destroy", 
                    G_CALLBACK (preview_destroy), pop);
                            
  gtk_widget_show_all (window);
  
  return TRUE;
}
Ejemplo n.º 22
0
static gboolean
print_settings_load_from_key_file (PrintData *data,
                                   GKeyFile  *key_file)
{
  GtkPrintOperation  *operation = data->operation;
  GtkPrintSettings   *settings;
  gchar             **keys;
  gsize               n_keys;
  gint                i;

  settings = gtk_print_operation_get_print_settings (operation);
  if (! settings)
    settings = gtk_print_settings_new ();

  keys = g_key_file_get_keys (key_file, PRINT_SETTINGS_NAME, &n_keys, NULL);

  if (! keys)
    return FALSE;

  for (i = 0; i < n_keys; i++)
    {
      gchar *value;

      value = g_key_file_get_value (key_file,
                                    PRINT_SETTINGS_NAME, keys[i], NULL);

      if (value)
        {
          gtk_print_settings_set (settings, keys[i], value);
          g_free (value);
        }
    }

  g_strfreev (keys);

  if (g_key_file_has_key (key_file, "image-setup", "unit", NULL))
    {
      data->unit = g_key_file_get_integer (key_file, "image-setup",
                                           "unit", NULL);
    }

  if (g_key_file_has_key (key_file, "image-setup", "x-resolution", NULL) &&
      g_key_file_has_key (key_file, "image-setup", "y-resolution", NULL))
    {
      data->xres = g_key_file_get_double (key_file, "image-setup",
                                          "x-resolution", NULL);
      data->yres = g_key_file_get_double (key_file, "image-setup",
                                          "y-resolution", NULL);
    }

  if (g_key_file_has_key (key_file, "image-setup", "x-offset", NULL) &&
      g_key_file_has_key (key_file, "image-setup", "y-offset", NULL))
    {
      data->offset_x = g_key_file_get_double (key_file, "image-setup",
                                              "x-offset", NULL);
      data->offset_y = g_key_file_get_double (key_file, "image-setup",
                                              "y-offset", NULL);
    }

  if (g_key_file_has_key (key_file, "image-setup", "center-mode", NULL))
    {
      data->center = g_key_file_get_integer (key_file, "image-setup",
                                             "center-mode", NULL);
    }

  if (g_key_file_has_key (key_file, "image-setup", "use-full-page", NULL))
    {
      data->use_full_page = g_key_file_get_boolean (key_file, "image-setup",
                                                    "use-full-page", NULL);
    }

  if (g_key_file_has_key (key_file, "image-setup", "crop-marks", NULL))
    {
      data->draw_crop_marks = g_key_file_get_boolean (key_file, "image-setup",
                                                      "crop-marks", NULL);
    }

  gtk_print_operation_set_print_settings (operation, settings);

  return TRUE;
}