export.cpp revision a4f5285714e41e9b1a29422b6fa5b520c3d5624a
b7f07692f95074fdcf74c7350fbf5f3099ffc1b6miklosh/* Authors:
b7f07692f95074fdcf74c7350fbf5f3099ffc1b6miklosh * Lauris Kaplinski <lauris@kaplinski.com>
b7f07692f95074fdcf74c7350fbf5f3099ffc1b6miklosh * bulia byak <buliabyak@users.sf.net>
b7f07692f95074fdcf74c7350fbf5f3099ffc1b6miklosh * Johan Engelen <j.b.c.engelen@ewi.utwente.nl>
b7f07692f95074fdcf74c7350fbf5f3099ffc1b6miklosh * Peter Bostrom
b7f07692f95074fdcf74c7350fbf5f3099ffc1b6miklosh * Jon A. Cruz <jon@joncruz.org>
b7f07692f95074fdcf74c7350fbf5f3099ffc1b6miklosh * Abhishek Sharma
b7f07692f95074fdcf74c7350fbf5f3099ffc1b6miklosh * Kris De Gussem <Kris.DeGussem@gmail.com>
b7f07692f95074fdcf74c7350fbf5f3099ffc1b6miklosh *
b7f07692f95074fdcf74c7350fbf5f3099ffc1b6miklosh * Copyright (C) 1999-2007, 2012 Authors
4b1c2be41ce8c1a88502c1b1885ad1468646fbfftheadib * Copyright (C) 2001-2002 Ximian, Inc.
b7f07692f95074fdcf74c7350fbf5f3099ffc1b6miklosh *
b7f07692f95074fdcf74c7350fbf5f3099ffc1b6miklosh * Released under GNU GPL, read the file 'COPYING' for more information
b7f07692f95074fdcf74c7350fbf5f3099ffc1b6miklosh */
b7f07692f95074fdcf74c7350fbf5f3099ffc1b6miklosh
b7f07692f95074fdcf74c7350fbf5f3099ffc1b6miklosh#ifdef HAVE_CONFIG_H
b7f07692f95074fdcf74c7350fbf5f3099ffc1b6miklosh# include "config.h"
b7f07692f95074fdcf74c7350fbf5f3099ffc1b6miklosh#endif
b7f07692f95074fdcf74c7350fbf5f3099ffc1b6miklosh
b7f07692f95074fdcf74c7350fbf5f3099ffc1b6miklosh// This has to be included prior to anything that includes setjmp.h, it croaks otherwise
b7f07692f95074fdcf74c7350fbf5f3099ffc1b6miklosh#include <png.h>
b7f07692f95074fdcf74c7350fbf5f3099ffc1b6miklosh
b7f07692f95074fdcf74c7350fbf5f3099ffc1b6miklosh#if GLIBMM_DISABLE_DEPRECATED && HAVE_GLIBMM_THREADS_H
b7f07692f95074fdcf74c7350fbf5f3099ffc1b6miklosh#include <glibmm/threads.h>
b7f07692f95074fdcf74c7350fbf5f3099ffc1b6miklosh#endif
b7f07692f95074fdcf74c7350fbf5f3099ffc1b6miklosh
b7f07692f95074fdcf74c7350fbf5f3099ffc1b6miklosh#include <gtkmm/box.h>
b7f07692f95074fdcf74c7350fbf5f3099ffc1b6miklosh#include <gtkmm/buttonbox.h>
b7f07692f95074fdcf74c7350fbf5f3099ffc1b6miklosh#include <gtkmm/dialog.h>
b7f07692f95074fdcf74c7350fbf5f3099ffc1b6miklosh#include <gtkmm/entry.h>
b7f07692f95074fdcf74c7350fbf5f3099ffc1b6miklosh#include <gtkmm/image.h>
b7f07692f95074fdcf74c7350fbf5f3099ffc1b6miklosh#include <gtkmm/label.h>
b7f07692f95074fdcf74c7350fbf5f3099ffc1b6miklosh#include <gtkmm/spinbutton.h>
b7f07692f95074fdcf74c7350fbf5f3099ffc1b6miklosh#include <gtkmm/stock.h>
b7f07692f95074fdcf74c7350fbf5f3099ffc1b6miklosh#include <gtkmm/stockid.h>
5c45c5153b0415f7573f69f4ee3e946b5872a8d1theadib#if WITH_GTKMM_3_0
5c45c5153b0415f7573f69f4ee3e946b5872a8d1theadib# include <gtkmm/grid.h>
5c45c5153b0415f7573f69f4ee3e946b5872a8d1theadib#else
5c45c5153b0415f7573f69f4ee3e946b5872a8d1theadib# include <gtkmm/table.h>
5c45c5153b0415f7573f69f4ee3e946b5872a8d1theadib#endif
5c45c5153b0415f7573f69f4ee3e946b5872a8d1theadib#include <gtkmm/togglebutton.h>
5c45c5153b0415f7573f69f4ee3e946b5872a8d1theadib#include <gtkmm/widget.h>
54e660c4de9d37185e3953165d053526632ef4f0johanengelen
54e660c4de9d37185e3953165d053526632ef4f0johanengelen#ifdef WITH_GNOME_VFS
54e660c4de9d37185e3953165d053526632ef4f0johanengelen# include <libgnomevfs/gnome-vfs-init.h> // gnome_vfs_initialized
5c45c5153b0415f7573f69f4ee3e946b5872a8d1theadib#endif
b7f07692f95074fdcf74c7350fbf5f3099ffc1b6miklosh
b7f07692f95074fdcf74c7350fbf5f3099ffc1b6miklosh#include <glibmm/i18n.h>
b7f07692f95074fdcf74c7350fbf5f3099ffc1b6miklosh#include <glibmm/miscutils.h>
b7f07692f95074fdcf74c7350fbf5f3099ffc1b6miklosh
b7f07692f95074fdcf74c7350fbf5f3099ffc1b6miklosh#include "ui/widget/unit-menu.h"
b7f07692f95074fdcf74c7350fbf5f3099ffc1b6miklosh#include "util/units.h"
b7f07692f95074fdcf74c7350fbf5f3099ffc1b6miklosh#include "helper/window.h"
b7f07692f95074fdcf74c7350fbf5f3099ffc1b6miklosh#include "inkscape-private.h"
b7f07692f95074fdcf74c7350fbf5f3099ffc1b6miklosh#include "document.h"
b7f07692f95074fdcf74c7350fbf5f3099ffc1b6miklosh#include "document-undo.h"
b7f07692f95074fdcf74c7350fbf5f3099ffc1b6miklosh#include "desktop-handles.h"
dd69425007680aafc47fdd994e1985625571d252bryce#include "sp-item.h"
b7f07692f95074fdcf74c7350fbf5f3099ffc1b6miklosh#include "selection.h"
b7f07692f95074fdcf74c7350fbf5f3099ffc1b6miklosh#include "file.h"
b7f07692f95074fdcf74c7350fbf5f3099ffc1b6miklosh#include "macros.h"
b7f07692f95074fdcf74c7350fbf5f3099ffc1b6miklosh#include "sp-namedview.h"
b7f07692f95074fdcf74c7350fbf5f3099ffc1b6miklosh#include "selection-chemistry.h"
b7f07692f95074fdcf74c7350fbf5f3099ffc1b6miklosh
b7f07692f95074fdcf74c7350fbf5f3099ffc1b6miklosh#include "dialogs/dialog-events.h"
b7f07692f95074fdcf74c7350fbf5f3099ffc1b6miklosh#include "preferences.h"
b7f07692f95074fdcf74c7350fbf5f3099ffc1b6miklosh#include "verbs.h"
b7f07692f95074fdcf74c7350fbf5f3099ffc1b6miklosh#include "interface.h"
b7f07692f95074fdcf74c7350fbf5f3099ffc1b6miklosh#include "sp-root.h"
b7f07692f95074fdcf74c7350fbf5f3099ffc1b6miklosh
b7f07692f95074fdcf74c7350fbf5f3099ffc1b6miklosh#include "extension/output.h"
b7f07692f95074fdcf74c7350fbf5f3099ffc1b6miklosh#include "extension/db.h"
5c45c5153b0415f7573f69f4ee3e946b5872a8d1theadib
5c45c5153b0415f7573f69f4ee3e946b5872a8d1theadib#include "io/sys.h"
b7f07692f95074fdcf74c7350fbf5f3099ffc1b6miklosh
b7f07692f95074fdcf74c7350fbf5f3099ffc1b6miklosh#include "helper/png-write.h"
b7f07692f95074fdcf74c7350fbf5f3099ffc1b6miklosh
b7f07692f95074fdcf74c7350fbf5f3099ffc1b6miklosh#if WITH_EXT_GDL
b7f07692f95074fdcf74c7350fbf5f3099ffc1b6miklosh#include <gdl/gdl-dock-item.h>
b7f07692f95074fdcf74c7350fbf5f3099ffc1b6miklosh#else
b7f07692f95074fdcf74c7350fbf5f3099ffc1b6miklosh#include "libgdl/gdl-dock-item.h"
b7f07692f95074fdcf74c7350fbf5f3099ffc1b6miklosh#endif
b7f07692f95074fdcf74c7350fbf5f3099ffc1b6miklosh
b7f07692f95074fdcf74c7350fbf5f3099ffc1b6miklosh
b7f07692f95074fdcf74c7350fbf5f3099ffc1b6miklosh// required to set status message after export
b7f07692f95074fdcf74c7350fbf5f3099ffc1b6miklosh#include "desktop.h"
b7f07692f95074fdcf74c7350fbf5f3099ffc1b6miklosh#include "message-stack.h"
b7f07692f95074fdcf74c7350fbf5f3099ffc1b6miklosh
b7f07692f95074fdcf74c7350fbf5f3099ffc1b6miklosh#ifdef WIN32
b7f07692f95074fdcf74c7350fbf5f3099ffc1b6miklosh#include <windows.h>
b7f07692f95074fdcf74c7350fbf5f3099ffc1b6miklosh#include <commdlg.h>
b7f07692f95074fdcf74c7350fbf5f3099ffc1b6miklosh#include <gdk/gdkwin32.h>
d444ed610362dab3c3e727d1b110312318b84cb8miklosh#include <glibmm/fileutils.h>
b7f07692f95074fdcf74c7350fbf5f3099ffc1b6miklosh#endif
b7f07692f95074fdcf74c7350fbf5f3099ffc1b6miklosh
b7f07692f95074fdcf74c7350fbf5f3099ffc1b6miklosh#include <gtk/gtk.h>
b7f07692f95074fdcf74c7350fbf5f3099ffc1b6miklosh
b7f07692f95074fdcf74c7350fbf5f3099ffc1b6miklosh#define SP_EXPORT_MIN_SIZE 1.0
b7f07692f95074fdcf74c7350fbf5f3099ffc1b6miklosh
b7f07692f95074fdcf74c7350fbf5f3099ffc1b6miklosh#define DPI_BASE Inkscape::Util::Quantity::convert(1, "in", "px")
b7f07692f95074fdcf74c7350fbf5f3099ffc1b6miklosh
b7f07692f95074fdcf74c7350fbf5f3099ffc1b6miklosh#define EXPORT_COORD_PRECISION 3
b7f07692f95074fdcf74c7350fbf5f3099ffc1b6miklosh
b7f07692f95074fdcf74c7350fbf5f3099ffc1b6miklosh#include "../../desktop-handles.h"
b7f07692f95074fdcf74c7350fbf5f3099ffc1b6miklosh#include "../../document.h"
b7f07692f95074fdcf74c7350fbf5f3099ffc1b6miklosh#include "../../document-undo.h"
b7f07692f95074fdcf74c7350fbf5f3099ffc1b6miklosh#include "verbs.h"
b7f07692f95074fdcf74c7350fbf5f3099ffc1b6miklosh#include "export.h"
b7f07692f95074fdcf74c7350fbf5f3099ffc1b6miklosh
b7f07692f95074fdcf74c7350fbf5f3099ffc1b6mikloshusing Inkscape::Util::unit_table;
b7f07692f95074fdcf74c7350fbf5f3099ffc1b6miklosh
b7f07692f95074fdcf74c7350fbf5f3099ffc1b6mikloshnamespace {
b7f07692f95074fdcf74c7350fbf5f3099ffc1b6miklosh
b7f07692f95074fdcf74c7350fbf5f3099ffc1b6mikloshclass MessageCleaner
b7f07692f95074fdcf74c7350fbf5f3099ffc1b6miklosh{
b7f07692f95074fdcf74c7350fbf5f3099ffc1b6mikloshpublic:
b7f07692f95074fdcf74c7350fbf5f3099ffc1b6miklosh MessageCleaner(Inkscape::MessageId messageId, SPDesktop *desktop) :
b7f07692f95074fdcf74c7350fbf5f3099ffc1b6miklosh _desktop(desktop),
b7f07692f95074fdcf74c7350fbf5f3099ffc1b6miklosh _messageId(messageId)
b7f07692f95074fdcf74c7350fbf5f3099ffc1b6miklosh {
b7f07692f95074fdcf74c7350fbf5f3099ffc1b6miklosh }
b7f07692f95074fdcf74c7350fbf5f3099ffc1b6miklosh
b7f07692f95074fdcf74c7350fbf5f3099ffc1b6miklosh ~MessageCleaner()
b7f07692f95074fdcf74c7350fbf5f3099ffc1b6miklosh {
b7f07692f95074fdcf74c7350fbf5f3099ffc1b6miklosh if (_messageId && _desktop) {
b7f07692f95074fdcf74c7350fbf5f3099ffc1b6miklosh _desktop->messageStack()->cancel(_messageId);
b7f07692f95074fdcf74c7350fbf5f3099ffc1b6miklosh }
b7f07692f95074fdcf74c7350fbf5f3099ffc1b6miklosh }
b7f07692f95074fdcf74c7350fbf5f3099ffc1b6miklosh
b7f07692f95074fdcf74c7350fbf5f3099ffc1b6mikloshprivate:
b7f07692f95074fdcf74c7350fbf5f3099ffc1b6miklosh MessageCleaner(MessageCleaner const &other);
b7f07692f95074fdcf74c7350fbf5f3099ffc1b6miklosh MessageCleaner &operator=(MessageCleaner const &other);
b7f07692f95074fdcf74c7350fbf5f3099ffc1b6miklosh
b7f07692f95074fdcf74c7350fbf5f3099ffc1b6miklosh SPDesktop *_desktop;
b7f07692f95074fdcf74c7350fbf5f3099ffc1b6miklosh Inkscape::MessageId _messageId;
b7f07692f95074fdcf74c7350fbf5f3099ffc1b6miklosh};
b7f07692f95074fdcf74c7350fbf5f3099ffc1b6miklosh
17d87f5698f5c2958d38c6a6207c7b322a7adaf9johanengelen} // namespace
b7f07692f95074fdcf74c7350fbf5f3099ffc1b6miklosh
b7f07692f95074fdcf74c7350fbf5f3099ffc1b6mikloshnamespace Inkscape {
b7f07692f95074fdcf74c7350fbf5f3099ffc1b6mikloshnamespace UI {
b7f07692f95074fdcf74c7350fbf5f3099ffc1b6mikloshnamespace Dialog {
b7f07692f95074fdcf74c7350fbf5f3099ffc1b6miklosh
b7f07692f95074fdcf74c7350fbf5f3099ffc1b6miklosh/** A list of strings that is used both in the preferences, and in the
b7f07692f95074fdcf74c7350fbf5f3099ffc1b6miklosh data fields to describe the various values of \c selection_type. */
b7f07692f95074fdcf74c7350fbf5f3099ffc1b6mikloshstatic const char * selection_names[SELECTION_NUMBER_OF] = {
b7f07692f95074fdcf74c7350fbf5f3099ffc1b6miklosh "page", "drawing", "selection", "custom"
4b1c2be41ce8c1a88502c1b1885ad1468646fbfftheadib};
b7f07692f95074fdcf74c7350fbf5f3099ffc1b6miklosh
b7f07692f95074fdcf74c7350fbf5f3099ffc1b6miklosh/** The names on the buttons for the various selection types. */
b7f07692f95074fdcf74c7350fbf5f3099ffc1b6mikloshstatic const char * selection_labels[SELECTION_NUMBER_OF] = {
b7f07692f95074fdcf74c7350fbf5f3099ffc1b6miklosh N_("_Page"), N_("_Drawing"), N_("_Selection"), N_("_Custom")
b7f07692f95074fdcf74c7350fbf5f3099ffc1b6miklosh};
b7f07692f95074fdcf74c7350fbf5f3099ffc1b6miklosh
b7f07692f95074fdcf74c7350fbf5f3099ffc1b6mikloshExport::Export (void) :
b7f07692f95074fdcf74c7350fbf5f3099ffc1b6miklosh UI::Widget::Panel ("", "/dialogs/export/", SP_VERB_DIALOG_EXPORT),
b7f07692f95074fdcf74c7350fbf5f3099ffc1b6miklosh current_key(SELECTION_PAGE),
b7f07692f95074fdcf74c7350fbf5f3099ffc1b6miklosh original_name(),
b7f07692f95074fdcf74c7350fbf5f3099ffc1b6miklosh doc_export_name(),
b7f07692f95074fdcf74c7350fbf5f3099ffc1b6miklosh filename_modified(false),
b7f07692f95074fdcf74c7350fbf5f3099ffc1b6miklosh was_empty(true),
b7f07692f95074fdcf74c7350fbf5f3099ffc1b6miklosh update(false),
b7f07692f95074fdcf74c7350fbf5f3099ffc1b6miklosh togglebox(true, 0),
b7f07692f95074fdcf74c7350fbf5f3099ffc1b6miklosh area_box(false, 3),
b7f07692f95074fdcf74c7350fbf5f3099ffc1b6miklosh singleexport_box(false, 0),
5c45c5153b0415f7573f69f4ee3e946b5872a8d1theadib size_box(false, 3),
b7f07692f95074fdcf74c7350fbf5f3099ffc1b6miklosh file_box(false, 3),
54e660c4de9d37185e3953165d053526632ef4f0johanengelen unitbox(false, 0),
b7f07692f95074fdcf74c7350fbf5f3099ffc1b6miklosh unit_selector(),
b7f07692f95074fdcf74c7350fbf5f3099ffc1b6miklosh units_label(_("Units:")),
b7f07692f95074fdcf74c7350fbf5f3099ffc1b6miklosh filename_box(false, 5),
b7f07692f95074fdcf74c7350fbf5f3099ffc1b6miklosh browse_label(_("_Export As..."), 1),
b7f07692f95074fdcf74c7350fbf5f3099ffc1b6miklosh browse_image(Gtk::StockID(Gtk::Stock::INDEX), Gtk::ICON_SIZE_BUTTON),
b7f07692f95074fdcf74c7350fbf5f3099ffc1b6miklosh batch_box(false, 5),
b7f07692f95074fdcf74c7350fbf5f3099ffc1b6miklosh batch_export(_("B_atch export all selected objects"), _("Export each selected object into its own PNG file, using export hints if any (caution, overwrites without asking!)")),
b7f07692f95074fdcf74c7350fbf5f3099ffc1b6miklosh hide_box(false, 5),
b7f07692f95074fdcf74c7350fbf5f3099ffc1b6miklosh hide_export(_("Hide a_ll except selected"), _("In the exported image, hide all objects except those that are selected")),
17d87f5698f5c2958d38c6a6207c7b322a7adaf9johanengelen closeWhenDone(_("Close when complete"), _("Once the export completes, close this dialog")),
b7f07692f95074fdcf74c7350fbf5f3099ffc1b6miklosh button_box(false, 3),
b7f07692f95074fdcf74c7350fbf5f3099ffc1b6miklosh export_label(_("_Export"), 1),
b7f07692f95074fdcf74c7350fbf5f3099ffc1b6miklosh export_image(Gtk::StockID(Gtk::Stock::APPLY), Gtk::ICON_SIZE_BUTTON),
b7f07692f95074fdcf74c7350fbf5f3099ffc1b6miklosh _prog(),
7cc06cc17ffc875601993118f9533dfe36bd2dd5johanengelen prog_dlg(NULL),
b7f07692f95074fdcf74c7350fbf5f3099ffc1b6miklosh interrupted(false),
7cc06cc17ffc875601993118f9533dfe36bd2dd5johanengelen prefs(NULL),
b7f07692f95074fdcf74c7350fbf5f3099ffc1b6miklosh desktop(NULL),
c87a66337fedd13cf951d99e604362432220deb5johanengelen deskTrack(),
54e660c4de9d37185e3953165d053526632ef4f0johanengelen selectChangedConn(),
54e660c4de9d37185e3953165d053526632ef4f0johanengelen subselChangedConn(),
54e660c4de9d37185e3953165d053526632ef4f0johanengelen selectModifiedConn()
54e660c4de9d37185e3953165d053526632ef4f0johanengelen{
b7f07692f95074fdcf74c7350fbf5f3099ffc1b6miklosh prefs = Inkscape::Preferences::get();
17d87f5698f5c2958d38c6a6207c7b322a7adaf9johanengelen
b7f07692f95074fdcf74c7350fbf5f3099ffc1b6miklosh singleexport_box.set_border_width(0);
54e660c4de9d37185e3953165d053526632ef4f0johanengelen
17d87f5698f5c2958d38c6a6207c7b322a7adaf9johanengelen /* Export area frame */
54e660c4de9d37185e3953165d053526632ef4f0johanengelen {
54e660c4de9d37185e3953165d053526632ef4f0johanengelen Gtk::Label* lbl = new Gtk::Label(_("<b>Export area</b>"), Gtk::ALIGN_START);
17d87f5698f5c2958d38c6a6207c7b322a7adaf9johanengelen lbl->set_use_markup(true);
54e660c4de9d37185e3953165d053526632ef4f0johanengelen area_box.pack_start(*lbl);
17d87f5698f5c2958d38c6a6207c7b322a7adaf9johanengelen
54e660c4de9d37185e3953165d053526632ef4f0johanengelen /* Units box */
54e660c4de9d37185e3953165d053526632ef4f0johanengelen /* gets added to the vbox later, but the unit selector is needed
54e660c4de9d37185e3953165d053526632ef4f0johanengelen earlier than that */
54e660c4de9d37185e3953165d053526632ef4f0johanengelen unit_selector.setUnitType(Inkscape::Util::UNIT_TYPE_LINEAR);
54e660c4de9d37185e3953165d053526632ef4f0johanengelen
e21d4ac16bee82a55fd227660aa14af10ecac9b1johanengelen SPDesktop *desktop = SP_ACTIVE_DESKTOP;
54e660c4de9d37185e3953165d053526632ef4f0johanengelen if (desktop) {
54e660c4de9d37185e3953165d053526632ef4f0johanengelen unit_selector.setUnit(sp_desktop_namedview(desktop)->doc_units->abbr);
54e660c4de9d37185e3953165d053526632ef4f0johanengelen }
54e660c4de9d37185e3953165d053526632ef4f0johanengelen unitChangedConn = unit_selector.signal_changed().connect(sigc::mem_fun(*this, &Export::onUnitChanged));
54e660c4de9d37185e3953165d053526632ef4f0johanengelen unitbox.pack_end(unit_selector, false, false, 0);
54e660c4de9d37185e3953165d053526632ef4f0johanengelen unitbox.pack_end(units_label, false, false, 3);
54e660c4de9d37185e3953165d053526632ef4f0johanengelen
54e660c4de9d37185e3953165d053526632ef4f0johanengelen for (int i = 0; i < SELECTION_NUMBER_OF; i++) {
54e660c4de9d37185e3953165d053526632ef4f0johanengelen selectiontype_buttons[i] = new Gtk::RadioButton(_(selection_labels[i]), true);
54e660c4de9d37185e3953165d053526632ef4f0johanengelen if (i > 0) {
54e660c4de9d37185e3953165d053526632ef4f0johanengelen Gtk::RadioButton::Group group = selectiontype_buttons[0]->get_group();
17d87f5698f5c2958d38c6a6207c7b322a7adaf9johanengelen selectiontype_buttons[i]->set_group(group);
b7f07692f95074fdcf74c7350fbf5f3099ffc1b6miklosh }
b7f07692f95074fdcf74c7350fbf5f3099ffc1b6miklosh selectiontype_buttons[i]->set_mode(false);
17d87f5698f5c2958d38c6a6207c7b322a7adaf9johanengelen togglebox.pack_start(*selectiontype_buttons[i], false, true, 0);
b7f07692f95074fdcf74c7350fbf5f3099ffc1b6miklosh selectiontype_buttons[i]->signal_clicked().connect(sigc::mem_fun(*this, &Export::onAreaToggled));
b7f07692f95074fdcf74c7350fbf5f3099ffc1b6miklosh }
17d87f5698f5c2958d38c6a6207c7b322a7adaf9johanengelen
b7f07692f95074fdcf74c7350fbf5f3099ffc1b6miklosh#if WITH_GTKMM_3_0
17d87f5698f5c2958d38c6a6207c7b322a7adaf9johanengelen Gtk::Grid* t = new Gtk::Grid();
b7f07692f95074fdcf74c7350fbf5f3099ffc1b6miklosh t->set_row_spacing(4);
b7f07692f95074fdcf74c7350fbf5f3099ffc1b6miklosh t->set_column_spacing(4);
b7f07692f95074fdcf74c7350fbf5f3099ffc1b6miklosh#else
54e660c4de9d37185e3953165d053526632ef4f0johanengelen Gtk::Table* t = new Gtk::Table(3, 4, false);
54e660c4de9d37185e3953165d053526632ef4f0johanengelen t->set_row_spacings (4);
54e660c4de9d37185e3953165d053526632ef4f0johanengelen t->set_col_spacings (4);
b7f07692f95074fdcf74c7350fbf5f3099ffc1b6miklosh#endif
b7f07692f95074fdcf74c7350fbf5f3099ffc1b6miklosh
54e660c4de9d37185e3953165d053526632ef4f0johanengelen x0_adj = createSpinbutton ( "x0", 0.0, -1000000.0, 1000000.0, 0.1, 1.0,
54e660c4de9d37185e3953165d053526632ef4f0johanengelen t, 0, 0, _("_x0:"), "", EXPORT_COORD_PRECISION, 1,
54e660c4de9d37185e3953165d053526632ef4f0johanengelen &Export::onAreaX0Change);
54e660c4de9d37185e3953165d053526632ef4f0johanengelen
54e660c4de9d37185e3953165d053526632ef4f0johanengelen x1_adj = createSpinbutton ( "x1", 0.0, -1000000.0, 1000000.0, 0.1, 1.0,
e21d4ac16bee82a55fd227660aa14af10ecac9b1johanengelen t, 0, 1, _("x_1:"), "", EXPORT_COORD_PRECISION, 1,
e21d4ac16bee82a55fd227660aa14af10ecac9b1johanengelen &Export::onAreaX1Change);
e21d4ac16bee82a55fd227660aa14af10ecac9b1johanengelen
e21d4ac16bee82a55fd227660aa14af10ecac9b1johanengelen width_adj = createSpinbutton ( "width", 0.0, 0.0, PNG_UINT_31_MAX, 0.1, 1.0,
e21d4ac16bee82a55fd227660aa14af10ecac9b1johanengelen t, 0, 2, _("Wid_th:"), "", EXPORT_COORD_PRECISION, 1,
e21d4ac16bee82a55fd227660aa14af10ecac9b1johanengelen &Export::onAreaWidthChange);
e21d4ac16bee82a55fd227660aa14af10ecac9b1johanengelen
e21d4ac16bee82a55fd227660aa14af10ecac9b1johanengelen y0_adj = createSpinbutton ( "y0", 0.0, -1000000.0, 1000000.0, 0.1, 1.0,
17d87f5698f5c2958d38c6a6207c7b322a7adaf9johanengelen t, 2, 0, _("_y0:"), "", EXPORT_COORD_PRECISION, 1,
54e660c4de9d37185e3953165d053526632ef4f0johanengelen &Export::onAreaY0Change);
54e660c4de9d37185e3953165d053526632ef4f0johanengelen
17d87f5698f5c2958d38c6a6207c7b322a7adaf9johanengelen y1_adj = createSpinbutton ( "y1", 0.0, -1000000.0, 1000000.0, 0.1, 1.0,
54e660c4de9d37185e3953165d053526632ef4f0johanengelen t, 2, 1, _("y_1:"), "", EXPORT_COORD_PRECISION, 1,
54e660c4de9d37185e3953165d053526632ef4f0johanengelen &Export::onAreaY1Change);
17d87f5698f5c2958d38c6a6207c7b322a7adaf9johanengelen
54e660c4de9d37185e3953165d053526632ef4f0johanengelen height_adj = createSpinbutton ( "height", 0.0, 0.0, PNG_UINT_31_MAX, 0.1, 1.0,
17d87f5698f5c2958d38c6a6207c7b322a7adaf9johanengelen t, 2, 2, _("Hei_ght:"), "", EXPORT_COORD_PRECISION, 1,
54e660c4de9d37185e3953165d053526632ef4f0johanengelen &Export::onAreaHeightChange);
54e660c4de9d37185e3953165d053526632ef4f0johanengelen
54e660c4de9d37185e3953165d053526632ef4f0johanengelen area_box.pack_start(togglebox, false, false, 3);
54e660c4de9d37185e3953165d053526632ef4f0johanengelen area_box.pack_start(*t, false, false, 0);
b7f07692f95074fdcf74c7350fbf5f3099ffc1b6miklosh area_box.pack_start(unitbox, false, false, 0);
b7f07692f95074fdcf74c7350fbf5f3099ffc1b6miklosh
b7f07692f95074fdcf74c7350fbf5f3099ffc1b6miklosh area_box.set_border_width(3);
b7f07692f95074fdcf74c7350fbf5f3099ffc1b6miklosh singleexport_box.pack_start(area_box, false, false, 0);
b7f07692f95074fdcf74c7350fbf5f3099ffc1b6miklosh
b7f07692f95074fdcf74c7350fbf5f3099ffc1b6miklosh } // end of area box
b7f07692f95074fdcf74c7350fbf5f3099ffc1b6miklosh
b7f07692f95074fdcf74c7350fbf5f3099ffc1b6miklosh /* Bitmap size frame */
4b1c2be41ce8c1a88502c1b1885ad1468646fbfftheadib {
b7f07692f95074fdcf74c7350fbf5f3099ffc1b6miklosh size_box.set_border_width(3);
b7f07692f95074fdcf74c7350fbf5f3099ffc1b6miklosh bm_label = new Gtk::Label(_("<b>Image size</b>"), Gtk::ALIGN_START);
b7f07692f95074fdcf74c7350fbf5f3099ffc1b6miklosh bm_label->set_use_markup(true);
b7f07692f95074fdcf74c7350fbf5f3099ffc1b6miklosh size_box.pack_start(*bm_label, false, false, 0);
b7f07692f95074fdcf74c7350fbf5f3099ffc1b6miklosh
4b1c2be41ce8c1a88502c1b1885ad1468646fbfftheadib#if WITH_GTKMM_3_0
b7f07692f95074fdcf74c7350fbf5f3099ffc1b6miklosh Gtk::Grid *t = new Gtk::Grid();
b7f07692f95074fdcf74c7350fbf5f3099ffc1b6miklosh t->set_row_spacing(4);
b7f07692f95074fdcf74c7350fbf5f3099ffc1b6miklosh t->set_column_spacing(4);
b7f07692f95074fdcf74c7350fbf5f3099ffc1b6miklosh#else
b7f07692f95074fdcf74c7350fbf5f3099ffc1b6miklosh Gtk::Table *t = new Gtk::Table(2, 5, false);
b7f07692f95074fdcf74c7350fbf5f3099ffc1b6miklosh t->set_row_spacings (4);
b7f07692f95074fdcf74c7350fbf5f3099ffc1b6miklosh t->set_col_spacings (4);
b7f07692f95074fdcf74c7350fbf5f3099ffc1b6miklosh#endif
b7f07692f95074fdcf74c7350fbf5f3099ffc1b6miklosh
b7f07692f95074fdcf74c7350fbf5f3099ffc1b6miklosh size_box.pack_start(*t);
b7f07692f95074fdcf74c7350fbf5f3099ffc1b6miklosh
17d87f5698f5c2958d38c6a6207c7b322a7adaf9johanengelen bmwidth_adj = createSpinbutton ( "bmwidth", 16.0, 1.0, 1000000.0, 1.0, 10.0,
b7f07692f95074fdcf74c7350fbf5f3099ffc1b6miklosh t, 0, 0,
b7f07692f95074fdcf74c7350fbf5f3099ffc1b6miklosh _("_Width:"), _("pixels at"), 0, 1,
b7f07692f95074fdcf74c7350fbf5f3099ffc1b6miklosh &Export::onBitmapWidthChange);
b7f07692f95074fdcf74c7350fbf5f3099ffc1b6miklosh
b7f07692f95074fdcf74c7350fbf5f3099ffc1b6miklosh xdpi_adj = createSpinbutton ( "xdpi",
b7f07692f95074fdcf74c7350fbf5f3099ffc1b6miklosh prefs->getDouble("/dialogs/export/defaultxdpi/value", DPI_BASE),
b7f07692f95074fdcf74c7350fbf5f3099ffc1b6miklosh 0.01, 100000.0, 0.1, 1.0, t, 3, 0,
b7f07692f95074fdcf74c7350fbf5f3099ffc1b6miklosh "", _("dp_i"), 2, 1,
b7f07692f95074fdcf74c7350fbf5f3099ffc1b6miklosh &Export::onExportXdpiChange);
b7f07692f95074fdcf74c7350fbf5f3099ffc1b6miklosh
b7f07692f95074fdcf74c7350fbf5f3099ffc1b6miklosh bmheight_adj = createSpinbutton ( "bmheight", 16.0, 1.0, 1000000.0, 1.0, 10.0,
b7f07692f95074fdcf74c7350fbf5f3099ffc1b6miklosh t, 0, 1,
b7f07692f95074fdcf74c7350fbf5f3099ffc1b6miklosh _("_Height:"), _("pixels at"), 0, 1,
b7f07692f95074fdcf74c7350fbf5f3099ffc1b6miklosh &Export::onBitmapHeightChange);
b7f07692f95074fdcf74c7350fbf5f3099ffc1b6miklosh
b7f07692f95074fdcf74c7350fbf5f3099ffc1b6miklosh /** TODO
b7f07692f95074fdcf74c7350fbf5f3099ffc1b6miklosh * There's no way to set ydpi currently, so we use the defaultxdpi value here, too...
b7f07692f95074fdcf74c7350fbf5f3099ffc1b6miklosh */
b7f07692f95074fdcf74c7350fbf5f3099ffc1b6miklosh ydpi_adj = createSpinbutton ( "ydpi", prefs->getDouble("/dialogs/export/defaultxdpi/value", DPI_BASE),
b7f07692f95074fdcf74c7350fbf5f3099ffc1b6miklosh 0.01, 100000.0, 0.1, 1.0, t, 3, 1,
b7f07692f95074fdcf74c7350fbf5f3099ffc1b6miklosh "", _("dpi"), 2, 0, NULL );
b7f07692f95074fdcf74c7350fbf5f3099ffc1b6miklosh
b7f07692f95074fdcf74c7350fbf5f3099ffc1b6miklosh singleexport_box.pack_start(size_box);
b7f07692f95074fdcf74c7350fbf5f3099ffc1b6miklosh }
b7f07692f95074fdcf74c7350fbf5f3099ffc1b6miklosh
b7f07692f95074fdcf74c7350fbf5f3099ffc1b6miklosh /* File entry */
b7f07692f95074fdcf74c7350fbf5f3099ffc1b6miklosh {
b7f07692f95074fdcf74c7350fbf5f3099ffc1b6miklosh file_box.set_border_width(3);
b7f07692f95074fdcf74c7350fbf5f3099ffc1b6miklosh flabel = new Gtk::Label(_("<b>_Filename</b>"), Gtk::ALIGN_START, Gtk::ALIGN_CENTER, true);
b7f07692f95074fdcf74c7350fbf5f3099ffc1b6miklosh flabel->set_use_markup(true);
b7f07692f95074fdcf74c7350fbf5f3099ffc1b6miklosh file_box.pack_start(*flabel, false, false, 0);
b7f07692f95074fdcf74c7350fbf5f3099ffc1b6miklosh
b7f07692f95074fdcf74c7350fbf5f3099ffc1b6miklosh set_default_filename();
b7f07692f95074fdcf74c7350fbf5f3099ffc1b6miklosh
b7f07692f95074fdcf74c7350fbf5f3099ffc1b6miklosh filename_box.pack_start (filename_entry, true, true, 0);
b7f07692f95074fdcf74c7350fbf5f3099ffc1b6miklosh
b7f07692f95074fdcf74c7350fbf5f3099ffc1b6miklosh Gtk::HBox* browser_im_label = new Gtk::HBox(false, 3);
b7f07692f95074fdcf74c7350fbf5f3099ffc1b6miklosh browser_im_label->pack_start(browse_image);
b7f07692f95074fdcf74c7350fbf5f3099ffc1b6miklosh browser_im_label->pack_start(browse_label);
b7f07692f95074fdcf74c7350fbf5f3099ffc1b6miklosh browse_button.add(*browser_im_label);
b7f07692f95074fdcf74c7350fbf5f3099ffc1b6miklosh filename_box.pack_end (browse_button, false, false, 4);
b7f07692f95074fdcf74c7350fbf5f3099ffc1b6miklosh
b7f07692f95074fdcf74c7350fbf5f3099ffc1b6miklosh file_box.add(filename_box);
b7f07692f95074fdcf74c7350fbf5f3099ffc1b6miklosh
b7f07692f95074fdcf74c7350fbf5f3099ffc1b6miklosh original_name = filename_entry.get_text();
b7f07692f95074fdcf74c7350fbf5f3099ffc1b6miklosh
b7f07692f95074fdcf74c7350fbf5f3099ffc1b6miklosh // focus is in the filename initially:
b7f07692f95074fdcf74c7350fbf5f3099ffc1b6miklosh filename_entry.grab_focus();
b7f07692f95074fdcf74c7350fbf5f3099ffc1b6miklosh
b7f07692f95074fdcf74c7350fbf5f3099ffc1b6miklosh // mnemonic in frame label moves focus to filename:
b7f07692f95074fdcf74c7350fbf5f3099ffc1b6miklosh flabel->set_mnemonic_widget(filename_entry);
4b1c2be41ce8c1a88502c1b1885ad1468646fbfftheadib
b7f07692f95074fdcf74c7350fbf5f3099ffc1b6miklosh singleexport_box.pack_start(file_box);
b7f07692f95074fdcf74c7350fbf5f3099ffc1b6miklosh }
b7f07692f95074fdcf74c7350fbf5f3099ffc1b6miklosh
b7f07692f95074fdcf74c7350fbf5f3099ffc1b6miklosh batch_export.set_sensitive(true);
17d87f5698f5c2958d38c6a6207c7b322a7adaf9johanengelen batch_box.pack_start(batch_export, false, false);
17d87f5698f5c2958d38c6a6207c7b322a7adaf9johanengelen
17d87f5698f5c2958d38c6a6207c7b322a7adaf9johanengelen hide_export.set_sensitive(true);
b7f07692f95074fdcf74c7350fbf5f3099ffc1b6miklosh hide_export.set_active (prefs->getBool("/dialogs/export/hideexceptselected/value", false));
b7f07692f95074fdcf74c7350fbf5f3099ffc1b6miklosh hide_box.pack_start(hide_export, false, false);
b7f07692f95074fdcf74c7350fbf5f3099ffc1b6miklosh
b7f07692f95074fdcf74c7350fbf5f3099ffc1b6miklosh
b7f07692f95074fdcf74c7350fbf5f3099ffc1b6miklosh /* Export Button row */
b7f07692f95074fdcf74c7350fbf5f3099ffc1b6miklosh button_box.set_border_width(3);
b7f07692f95074fdcf74c7350fbf5f3099ffc1b6miklosh Gtk::HBox* export_image_label = new Gtk::HBox(false, 3);
b7f07692f95074fdcf74c7350fbf5f3099ffc1b6miklosh export_image_label->pack_start(export_image);
b7f07692f95074fdcf74c7350fbf5f3099ffc1b6miklosh export_image_label->pack_start(export_label);
4b1c2be41ce8c1a88502c1b1885ad1468646fbfftheadib
b7f07692f95074fdcf74c7350fbf5f3099ffc1b6miklosh export_button.add(*export_image_label);
b7f07692f95074fdcf74c7350fbf5f3099ffc1b6miklosh export_button.set_tooltip_text (_("Export the bitmap file with these settings"));
b7f07692f95074fdcf74c7350fbf5f3099ffc1b6miklosh
4b1c2be41ce8c1a88502c1b1885ad1468646fbfftheadib button_box.pack_start(closeWhenDone, true, true, 0 );
b7f07692f95074fdcf74c7350fbf5f3099ffc1b6miklosh button_box.pack_end(export_button, false, false, 0);
b7f07692f95074fdcf74c7350fbf5f3099ffc1b6miklosh
17d87f5698f5c2958d38c6a6207c7b322a7adaf9johanengelen /* Main dialog */
b7f07692f95074fdcf74c7350fbf5f3099ffc1b6miklosh Gtk::Box *contents = _getContents();
b7f07692f95074fdcf74c7350fbf5f3099ffc1b6miklosh contents->set_spacing(0);
b7f07692f95074fdcf74c7350fbf5f3099ffc1b6miklosh contents->pack_start(singleexport_box);
b7f07692f95074fdcf74c7350fbf5f3099ffc1b6miklosh contents->pack_start(batch_box);
b7f07692f95074fdcf74c7350fbf5f3099ffc1b6miklosh contents->pack_start(hide_box);
b7f07692f95074fdcf74c7350fbf5f3099ffc1b6miklosh contents->pack_end(button_box, false, 0);
4b1c2be41ce8c1a88502c1b1885ad1468646fbfftheadib contents->pack_end(_prog, Gtk::PACK_EXPAND_WIDGET);
b7f07692f95074fdcf74c7350fbf5f3099ffc1b6miklosh
b7f07692f95074fdcf74c7350fbf5f3099ffc1b6miklosh /* Signal handlers */
4b1c2be41ce8c1a88502c1b1885ad1468646fbfftheadib filename_entry.signal_changed().connect( sigc::mem_fun(*this, &Export::onFilenameModified) );
b7f07692f95074fdcf74c7350fbf5f3099ffc1b6miklosh // pressing enter in the filename field is the same as clicking export:
b7f07692f95074fdcf74c7350fbf5f3099ffc1b6miklosh filename_entry.signal_activate().connect(sigc::mem_fun(*this, &Export::onExport) );
b7f07692f95074fdcf74c7350fbf5f3099ffc1b6miklosh browse_button.signal_clicked().connect(sigc::mem_fun(*this, &Export::onBrowse));
b7f07692f95074fdcf74c7350fbf5f3099ffc1b6miklosh batch_export.signal_clicked().connect(sigc::mem_fun(*this, &Export::onBatchClicked));
17d87f5698f5c2958d38c6a6207c7b322a7adaf9johanengelen export_button.signal_clicked().connect(sigc::mem_fun(*this, &Export::onExport));
b7f07692f95074fdcf74c7350fbf5f3099ffc1b6miklosh hide_export.signal_clicked().connect(sigc::mem_fun(*this, &Export::onHideExceptSelected));
b7f07692f95074fdcf74c7350fbf5f3099ffc1b6miklosh
b7f07692f95074fdcf74c7350fbf5f3099ffc1b6miklosh desktopChangeConn = deskTrack.connectDesktopChanged( sigc::mem_fun(*this, &Export::setTargetDesktop) );
b7f07692f95074fdcf74c7350fbf5f3099ffc1b6miklosh deskTrack.connect(GTK_WIDGET(gobj()));
b7f07692f95074fdcf74c7350fbf5f3099ffc1b6miklosh
b7f07692f95074fdcf74c7350fbf5f3099ffc1b6miklosh show_all_children();
b7f07692f95074fdcf74c7350fbf5f3099ffc1b6miklosh setExporting(false);
4b1c2be41ce8c1a88502c1b1885ad1468646fbfftheadib
b7f07692f95074fdcf74c7350fbf5f3099ffc1b6miklosh findDefaultSelection();
b7f07692f95074fdcf74c7350fbf5f3099ffc1b6miklosh onAreaToggled();
b7f07692f95074fdcf74c7350fbf5f3099ffc1b6miklosh}
b7f07692f95074fdcf74c7350fbf5f3099ffc1b6miklosh
b7f07692f95074fdcf74c7350fbf5f3099ffc1b6mikloshExport::~Export (void)
b7f07692f95074fdcf74c7350fbf5f3099ffc1b6miklosh{
b7f07692f95074fdcf74c7350fbf5f3099ffc1b6miklosh was_empty = TRUE;
b7f07692f95074fdcf74c7350fbf5f3099ffc1b6miklosh
b7f07692f95074fdcf74c7350fbf5f3099ffc1b6miklosh selectModifiedConn.disconnect();
b7f07692f95074fdcf74c7350fbf5f3099ffc1b6miklosh subselChangedConn.disconnect();
b7f07692f95074fdcf74c7350fbf5f3099ffc1b6miklosh selectChangedConn.disconnect();
b7f07692f95074fdcf74c7350fbf5f3099ffc1b6miklosh desktopChangeConn.disconnect();
b7f07692f95074fdcf74c7350fbf5f3099ffc1b6miklosh deskTrack.disconnect();
b7f07692f95074fdcf74c7350fbf5f3099ffc1b6miklosh}
17d87f5698f5c2958d38c6a6207c7b322a7adaf9johanengelen
17d87f5698f5c2958d38c6a6207c7b322a7adaf9johanengelenvoid Export::setDesktop(SPDesktop *desktop)
b7f07692f95074fdcf74c7350fbf5f3099ffc1b6miklosh{
b7f07692f95074fdcf74c7350fbf5f3099ffc1b6miklosh Panel::setDesktop(desktop);
b7f07692f95074fdcf74c7350fbf5f3099ffc1b6miklosh deskTrack.setBase(desktop);
b7f07692f95074fdcf74c7350fbf5f3099ffc1b6miklosh}
5c45c5153b0415f7573f69f4ee3e946b5872a8d1theadib
5c45c5153b0415f7573f69f4ee3e946b5872a8d1theadibvoid Export::setTargetDesktop(SPDesktop *desktop)
5c45c5153b0415f7573f69f4ee3e946b5872a8d1theadib{
5c45c5153b0415f7573f69f4ee3e946b5872a8d1theadib if (this->desktop != desktop) {
5c45c5153b0415f7573f69f4ee3e946b5872a8d1theadib if (this->desktop) {
5c45c5153b0415f7573f69f4ee3e946b5872a8d1theadib selectModifiedConn.disconnect();
5c45c5153b0415f7573f69f4ee3e946b5872a8d1theadib subselChangedConn.disconnect();
5c45c5153b0415f7573f69f4ee3e946b5872a8d1theadib selectChangedConn.disconnect();
5c45c5153b0415f7573f69f4ee3e946b5872a8d1theadib }
5c45c5153b0415f7573f69f4ee3e946b5872a8d1theadib this->desktop = desktop;
5c45c5153b0415f7573f69f4ee3e946b5872a8d1theadib if (desktop && desktop->selection) {
5c45c5153b0415f7573f69f4ee3e946b5872a8d1theadib
5c45c5153b0415f7573f69f4ee3e946b5872a8d1theadib selectChangedConn = desktop->selection->connectChanged(sigc::hide(sigc::mem_fun(*this, &Export::onSelectionChanged)));
17d87f5698f5c2958d38c6a6207c7b322a7adaf9johanengelen subselChangedConn = desktop->connectToolSubselectionChanged(sigc::hide(sigc::mem_fun(*this, &Export::onSelectionChanged)));
26b62dfb088a00b6debad350538a64c2af145f50johanengelen
26b62dfb088a00b6debad350538a64c2af145f50johanengelen //// Must check flags, so can't call widget_setup() directly.
5c45c5153b0415f7573f69f4ee3e946b5872a8d1theadib selectModifiedConn = desktop->selection->connectModified(sigc::hide<0>(sigc::mem_fun(*this, &Export::onSelectionModified)));
5c45c5153b0415f7573f69f4ee3e946b5872a8d1theadib }
5c45c5153b0415f7573f69f4ee3e946b5872a8d1theadib }
5c45c5153b0415f7573f69f4ee3e946b5872a8d1theadib}
5c45c5153b0415f7573f69f4ee3e946b5872a8d1theadib
5c45c5153b0415f7573f69f4ee3e946b5872a8d1theadib/*
5c45c5153b0415f7573f69f4ee3e946b5872a8d1theadib * set the default filename to be that of the current path + document
5c45c5153b0415f7573f69f4ee3e946b5872a8d1theadib * with .png extension
5c45c5153b0415f7573f69f4ee3e946b5872a8d1theadib *
5c45c5153b0415f7573f69f4ee3e946b5872a8d1theadib * One thing to notice here is that this filename may get
5c45c5153b0415f7573f69f4ee3e946b5872a8d1theadib * overwritten, but it won't happen here. The filename gets
5c45c5153b0415f7573f69f4ee3e946b5872a8d1theadib * written into the text field, but then the button to select
5c45c5153b0415f7573f69f4ee3e946b5872a8d1theadib * the area gets set. In that code the filename can be changed
5c45c5153b0415f7573f69f4ee3e946b5872a8d1theadib * if there are some with presidence in the document. So, while
5c45c5153b0415f7573f69f4ee3e946b5872a8d1theadib * this code sets the name first, it may not be the one users
861fa436e7a6d6ff3eaa889b2298e0b82a0b238ctheadib * really see.
861fa436e7a6d6ff3eaa889b2298e0b82a0b238ctheadib */
861fa436e7a6d6ff3eaa889b2298e0b82a0b238ctheadibvoid Export::set_default_filename () {
861fa436e7a6d6ff3eaa889b2298e0b82a0b238ctheadib
861fa436e7a6d6ff3eaa889b2298e0b82a0b238ctheadib if ( SP_ACTIVE_DOCUMENT && SP_ACTIVE_DOCUMENT->getURI() )
5c45c5153b0415f7573f69f4ee3e946b5872a8d1theadib {
5c45c5153b0415f7573f69f4ee3e946b5872a8d1theadib SPDocument * doc = SP_ACTIVE_DOCUMENT;
5c45c5153b0415f7573f69f4ee3e946b5872a8d1theadib const gchar *uri = doc->getURI();
5c45c5153b0415f7573f69f4ee3e946b5872a8d1theadib const gchar *text_extension = get_file_save_extension (Inkscape::Extension::FILE_SAVE_METHOD_SAVE_AS).c_str();
5c45c5153b0415f7573f69f4ee3e946b5872a8d1theadib Inkscape::Extension::Output * oextension = NULL;
5c45c5153b0415f7573f69f4ee3e946b5872a8d1theadib
5c45c5153b0415f7573f69f4ee3e946b5872a8d1theadib if (text_extension != NULL) {
5c45c5153b0415f7573f69f4ee3e946b5872a8d1theadib oextension = dynamic_cast<Inkscape::Extension::Output *>(Inkscape::Extension::db.get(text_extension));
5c45c5153b0415f7573f69f4ee3e946b5872a8d1theadib }
5c45c5153b0415f7573f69f4ee3e946b5872a8d1theadib
5c45c5153b0415f7573f69f4ee3e946b5872a8d1theadib if (oextension != NULL) {
5c45c5153b0415f7573f69f4ee3e946b5872a8d1theadib gchar * old_extension = oextension->get_extension();
5c45c5153b0415f7573f69f4ee3e946b5872a8d1theadib if (g_str_has_suffix(uri, old_extension)) {
5c45c5153b0415f7573f69f4ee3e946b5872a8d1theadib gchar * uri_copy;
5c45c5153b0415f7573f69f4ee3e946b5872a8d1theadib gchar * extension_point;
5c45c5153b0415f7573f69f4ee3e946b5872a8d1theadib gchar * final_name;
5c45c5153b0415f7573f69f4ee3e946b5872a8d1theadib
5c45c5153b0415f7573f69f4ee3e946b5872a8d1theadib uri_copy = g_strdup(uri);
5c45c5153b0415f7573f69f4ee3e946b5872a8d1theadib extension_point = g_strrstr(uri_copy, old_extension);
5c45c5153b0415f7573f69f4ee3e946b5872a8d1theadib extension_point[0] = '\0';
5c45c5153b0415f7573f69f4ee3e946b5872a8d1theadib
5c45c5153b0415f7573f69f4ee3e946b5872a8d1theadib final_name = g_strconcat(uri_copy, ".png", NULL);
5c45c5153b0415f7573f69f4ee3e946b5872a8d1theadib filename_entry.set_text(final_name);
5c45c5153b0415f7573f69f4ee3e946b5872a8d1theadib filename_entry.set_position(strlen(final_name));
5c45c5153b0415f7573f69f4ee3e946b5872a8d1theadib
5c45c5153b0415f7573f69f4ee3e946b5872a8d1theadib g_free(final_name);
5c45c5153b0415f7573f69f4ee3e946b5872a8d1theadib g_free(uri_copy);
5c45c5153b0415f7573f69f4ee3e946b5872a8d1theadib }
5c45c5153b0415f7573f69f4ee3e946b5872a8d1theadib } else {
5c45c5153b0415f7573f69f4ee3e946b5872a8d1theadib gchar *name = g_strconcat(uri, ".png", NULL);
5c45c5153b0415f7573f69f4ee3e946b5872a8d1theadib filename_entry.set_text(name);
5c45c5153b0415f7573f69f4ee3e946b5872a8d1theadib filename_entry.set_position(strlen(name));
17d87f5698f5c2958d38c6a6207c7b322a7adaf9johanengelen
17d87f5698f5c2958d38c6a6207c7b322a7adaf9johanengelen g_free(name);
5c45c5153b0415f7573f69f4ee3e946b5872a8d1theadib }
5c45c5153b0415f7573f69f4ee3e946b5872a8d1theadib
5c45c5153b0415f7573f69f4ee3e946b5872a8d1theadib doc_export_name = filename_entry.get_text();
5c45c5153b0415f7573f69f4ee3e946b5872a8d1theadib }
5c45c5153b0415f7573f69f4ee3e946b5872a8d1theadib
5c45c5153b0415f7573f69f4ee3e946b5872a8d1theadib}
5c45c5153b0415f7573f69f4ee3e946b5872a8d1theadib
17d87f5698f5c2958d38c6a6207c7b322a7adaf9johanengelen#if WITH_GTKMM_3_0
45d0b0d0dc24df8e321cbe8a085ab9b1f60b4a42theadibGlib::RefPtr<Gtk::Adjustment> Export::createSpinbutton( gchar const * /*key*/, float val, float min, float max,
17d87f5698f5c2958d38c6a6207c7b322a7adaf9johanengelen float step, float page,
5c45c5153b0415f7573f69f4ee3e946b5872a8d1theadib Gtk::Grid *t, int x, int y,
5c45c5153b0415f7573f69f4ee3e946b5872a8d1theadib const Glib::ustring& ll, const Glib::ustring& lr,
45d0b0d0dc24df8e321cbe8a085ab9b1f60b4a42theadib int digits, unsigned int sensitive,
5c45c5153b0415f7573f69f4ee3e946b5872a8d1theadib void (Export::*cb)() )
5c45c5153b0415f7573f69f4ee3e946b5872a8d1theadib#else
5c45c5153b0415f7573f69f4ee3e946b5872a8d1theadibGtk::Adjustment * Export::createSpinbutton( gchar const * /*key*/, float val, float min, float max,
5c45c5153b0415f7573f69f4ee3e946b5872a8d1theadib float step, float page,
5c45c5153b0415f7573f69f4ee3e946b5872a8d1theadib Gtk::Table *t, int x, int y,
5c45c5153b0415f7573f69f4ee3e946b5872a8d1theadib const Glib::ustring& ll, const Glib::ustring& lr,
5c45c5153b0415f7573f69f4ee3e946b5872a8d1theadib int digits, unsigned int sensitive,
5c45c5153b0415f7573f69f4ee3e946b5872a8d1theadib void (Export::*cb)() )
5c45c5153b0415f7573f69f4ee3e946b5872a8d1theadib#endif
5c45c5153b0415f7573f69f4ee3e946b5872a8d1theadib{
5c45c5153b0415f7573f69f4ee3e946b5872a8d1theadib#if WITH_GTKMM_3_0
5c45c5153b0415f7573f69f4ee3e946b5872a8d1theadib Glib::RefPtr<Gtk::Adjustment> adj = Gtk::Adjustment::create(val, min, max, step, page, 0);
5c45c5153b0415f7573f69f4ee3e946b5872a8d1theadib#else
5c45c5153b0415f7573f69f4ee3e946b5872a8d1theadib Gtk::Adjustment *adj = new Gtk::Adjustment ( val, min, max, step, page, 0 );
17d87f5698f5c2958d38c6a6207c7b322a7adaf9johanengelen#endif
45d0b0d0dc24df8e321cbe8a085ab9b1f60b4a42theadib
17d87f5698f5c2958d38c6a6207c7b322a7adaf9johanengelen int pos = 0;
3955580a5a68a873b098921626f5b9d841b964ecjaspervdg Gtk::Label *l = NULL;
5c45c5153b0415f7573f69f4ee3e946b5872a8d1theadib
5c45c5153b0415f7573f69f4ee3e946b5872a8d1theadib if (!ll.empty()) {
5c45c5153b0415f7573f69f4ee3e946b5872a8d1theadib l = new Gtk::Label(ll,true);
5c45c5153b0415f7573f69f4ee3e946b5872a8d1theadib l->set_alignment (1.0, 0.5);
5c45c5153b0415f7573f69f4ee3e946b5872a8d1theadib
5c45c5153b0415f7573f69f4ee3e946b5872a8d1theadib#if WITH_GTKMM_3_0
5c45c5153b0415f7573f69f4ee3e946b5872a8d1theadib l->set_hexpand();
5c45c5153b0415f7573f69f4ee3e946b5872a8d1theadib l->set_vexpand();
5c45c5153b0415f7573f69f4ee3e946b5872a8d1theadib t->attach(*l, x + pos, y, 1, 1);
5c45c5153b0415f7573f69f4ee3e946b5872a8d1theadib#else
5c45c5153b0415f7573f69f4ee3e946b5872a8d1theadib t->attach (*l, x + pos, x + pos + 1, y, y + 1, Gtk::EXPAND, Gtk::EXPAND, 0, 0 );
5c45c5153b0415f7573f69f4ee3e946b5872a8d1theadib#endif
5c45c5153b0415f7573f69f4ee3e946b5872a8d1theadib
5c45c5153b0415f7573f69f4ee3e946b5872a8d1theadib l->set_sensitive(sensitive);
5c45c5153b0415f7573f69f4ee3e946b5872a8d1theadib pos++;
5c45c5153b0415f7573f69f4ee3e946b5872a8d1theadib }
5c45c5153b0415f7573f69f4ee3e946b5872a8d1theadib
5c45c5153b0415f7573f69f4ee3e946b5872a8d1theadib#if WITH_GTKMM_3_0
5c45c5153b0415f7573f69f4ee3e946b5872a8d1theadib Gtk::SpinButton *sb = new Gtk::SpinButton(adj, 1.0, digits);
5c45c5153b0415f7573f69f4ee3e946b5872a8d1theadib sb->set_hexpand();
5c45c5153b0415f7573f69f4ee3e946b5872a8d1theadib sb->set_vexpand();
5c45c5153b0415f7573f69f4ee3e946b5872a8d1theadib t->attach(*sb, x + pos, y, 1, 1);
5c45c5153b0415f7573f69f4ee3e946b5872a8d1theadib#else
5c45c5153b0415f7573f69f4ee3e946b5872a8d1theadib Gtk::SpinButton *sb = new Gtk::SpinButton(*adj, 1.0, digits);
5c45c5153b0415f7573f69f4ee3e946b5872a8d1theadib t->attach (*sb, x + pos, x + pos + 1, y, y + 1, Gtk::EXPAND, Gtk::EXPAND, 0, 0 );
5c45c5153b0415f7573f69f4ee3e946b5872a8d1theadib#endif
5c45c5153b0415f7573f69f4ee3e946b5872a8d1theadib
5c45c5153b0415f7573f69f4ee3e946b5872a8d1theadib sb->set_width_chars(7);
5c45c5153b0415f7573f69f4ee3e946b5872a8d1theadib sb->set_sensitive (sensitive);
5c45c5153b0415f7573f69f4ee3e946b5872a8d1theadib pos++;
5c45c5153b0415f7573f69f4ee3e946b5872a8d1theadib
b7f07692f95074fdcf74c7350fbf5f3099ffc1b6miklosh if (!ll.empty()) {
b7f07692f95074fdcf74c7350fbf5f3099ffc1b6miklosh l->set_mnemonic_widget(*sb);
1babefb17e4c8157ca2a0f588625a8ac0258dc53buliabyak }
1babefb17e4c8157ca2a0f588625a8ac0258dc53buliabyak
1babefb17e4c8157ca2a0f588625a8ac0258dc53buliabyak if (!lr.empty()) {
1babefb17e4c8157ca2a0f588625a8ac0258dc53buliabyak l = new Gtk::Label(lr,true);
1babefb17e4c8157ca2a0f588625a8ac0258dc53buliabyak l->set_alignment (0.0, 0.5);
45d0b0d0dc24df8e321cbe8a085ab9b1f60b4a42theadib
861fa436e7a6d6ff3eaa889b2298e0b82a0b238ctheadib#if WITH_GTKMM_3_0
45d0b0d0dc24df8e321cbe8a085ab9b1f60b4a42theadib l->set_hexpand();
45d0b0d0dc24df8e321cbe8a085ab9b1f60b4a42theadib l->set_vexpand();
4b1c2be41ce8c1a88502c1b1885ad1468646fbfftheadib t->attach(*l, x + pos, y, 1, 1);
b7f07692f95074fdcf74c7350fbf5f3099ffc1b6miklosh#else
b7f07692f95074fdcf74c7350fbf5f3099ffc1b6miklosh t->attach (*l, x + pos, x + pos + 1, y, y + 1, Gtk::EXPAND, Gtk::EXPAND, 0, 0 );
b7f07692f95074fdcf74c7350fbf5f3099ffc1b6miklosh#endif
b7f07692f95074fdcf74c7350fbf5f3099ffc1b6miklosh
b7f07692f95074fdcf74c7350fbf5f3099ffc1b6miklosh l->set_sensitive (sensitive);
b7f07692f95074fdcf74c7350fbf5f3099ffc1b6miklosh pos++;
b7f07692f95074fdcf74c7350fbf5f3099ffc1b6miklosh l->set_mnemonic_widget (*sb);
b7f07692f95074fdcf74c7350fbf5f3099ffc1b6miklosh }
b7f07692f95074fdcf74c7350fbf5f3099ffc1b6miklosh
b7f07692f95074fdcf74c7350fbf5f3099ffc1b6miklosh if (cb) {
b7f07692f95074fdcf74c7350fbf5f3099ffc1b6miklosh adj->signal_value_changed().connect( sigc::mem_fun(*this, cb) );
b7f07692f95074fdcf74c7350fbf5f3099ffc1b6miklosh }
b7f07692f95074fdcf74c7350fbf5f3099ffc1b6miklosh
b7f07692f95074fdcf74c7350fbf5f3099ffc1b6miklosh return adj;
b7f07692f95074fdcf74c7350fbf5f3099ffc1b6miklosh} // end of createSpinbutton()
b7f07692f95074fdcf74c7350fbf5f3099ffc1b6miklosh
b7f07692f95074fdcf74c7350fbf5f3099ffc1b6miklosh
b7f07692f95074fdcf74c7350fbf5f3099ffc1b6mikloshGlib::ustring Export::create_filepath_from_id (Glib::ustring id, const Glib::ustring &file_entry_text)
b7f07692f95074fdcf74c7350fbf5f3099ffc1b6miklosh{
b7f07692f95074fdcf74c7350fbf5f3099ffc1b6miklosh if (id.empty())
b7f07692f95074fdcf74c7350fbf5f3099ffc1b6miklosh { /* This should never happen */
b7f07692f95074fdcf74c7350fbf5f3099ffc1b6miklosh id = "bitmap";
b7f07692f95074fdcf74c7350fbf5f3099ffc1b6miklosh }
b7f07692f95074fdcf74c7350fbf5f3099ffc1b6miklosh
b7f07692f95074fdcf74c7350fbf5f3099ffc1b6miklosh Glib::ustring directory;
b7f07692f95074fdcf74c7350fbf5f3099ffc1b6miklosh
b7f07692f95074fdcf74c7350fbf5f3099ffc1b6miklosh if (!file_entry_text.empty()) {
b7f07692f95074fdcf74c7350fbf5f3099ffc1b6miklosh directory = Glib::path_get_dirname(file_entry_text);
b7f07692f95074fdcf74c7350fbf5f3099ffc1b6miklosh }
b7f07692f95074fdcf74c7350fbf5f3099ffc1b6miklosh
b7f07692f95074fdcf74c7350fbf5f3099ffc1b6miklosh if (directory.empty()) {
b7f07692f95074fdcf74c7350fbf5f3099ffc1b6miklosh /* Grab document directory */
b7f07692f95074fdcf74c7350fbf5f3099ffc1b6miklosh const gchar* docURI = SP_ACTIVE_DOCUMENT->getURI();
4b1c2be41ce8c1a88502c1b1885ad1468646fbfftheadib if (docURI) {
b7f07692f95074fdcf74c7350fbf5f3099ffc1b6miklosh directory = Glib::path_get_dirname(docURI);
b7f07692f95074fdcf74c7350fbf5f3099ffc1b6miklosh }
b7f07692f95074fdcf74c7350fbf5f3099ffc1b6miklosh }
b7f07692f95074fdcf74c7350fbf5f3099ffc1b6miklosh
b7f07692f95074fdcf74c7350fbf5f3099ffc1b6miklosh if (directory.empty()) {
b7f07692f95074fdcf74c7350fbf5f3099ffc1b6miklosh directory = homedir_path(NULL);
b7f07692f95074fdcf74c7350fbf5f3099ffc1b6miklosh }
b7f07692f95074fdcf74c7350fbf5f3099ffc1b6miklosh
b7f07692f95074fdcf74c7350fbf5f3099ffc1b6miklosh Glib::ustring filename = Glib::build_filename(directory, id+".png");
b7f07692f95074fdcf74c7350fbf5f3099ffc1b6miklosh return filename;
b7f07692f95074fdcf74c7350fbf5f3099ffc1b6miklosh}
b7f07692f95074fdcf74c7350fbf5f3099ffc1b6miklosh
b7f07692f95074fdcf74c7350fbf5f3099ffc1b6mikloshvoid Export::onBatchClicked ()
b7f07692f95074fdcf74c7350fbf5f3099ffc1b6miklosh{
b7f07692f95074fdcf74c7350fbf5f3099ffc1b6miklosh if (batch_export.get_active()) {
b7f07692f95074fdcf74c7350fbf5f3099ffc1b6miklosh singleexport_box.set_sensitive(false);
b7f07692f95074fdcf74c7350fbf5f3099ffc1b6miklosh } else {
b7f07692f95074fdcf74c7350fbf5f3099ffc1b6miklosh singleexport_box.set_sensitive(true);
b7f07692f95074fdcf74c7350fbf5f3099ffc1b6miklosh }
4b1c2be41ce8c1a88502c1b1885ad1468646fbfftheadib}
b7f07692f95074fdcf74c7350fbf5f3099ffc1b6miklosh
b7f07692f95074fdcf74c7350fbf5f3099ffc1b6mikloshvoid Export::updateCheckbuttons ()
b7f07692f95074fdcf74c7350fbf5f3099ffc1b6miklosh{
b7f07692f95074fdcf74c7350fbf5f3099ffc1b6miklosh gint num = g_slist_length((GSList *) sp_desktop_selection(SP_ACTIVE_DESKTOP)->itemList());
b7f07692f95074fdcf74c7350fbf5f3099ffc1b6miklosh if (num >= 2) {
b7f07692f95074fdcf74c7350fbf5f3099ffc1b6miklosh batch_export.set_sensitive(true);
b7f07692f95074fdcf74c7350fbf5f3099ffc1b6miklosh batch_export.set_label(g_strdup_printf (ngettext("B_atch export %d selected object","B_atch export %d selected objects",num), num));
17d87f5698f5c2958d38c6a6207c7b322a7adaf9johanengelen } else {
17d87f5698f5c2958d38c6a6207c7b322a7adaf9johanengelen batch_export.set_active (false);
b7f07692f95074fdcf74c7350fbf5f3099ffc1b6miklosh batch_export.set_sensitive(false);
b7f07692f95074fdcf74c7350fbf5f3099ffc1b6miklosh }
b7f07692f95074fdcf74c7350fbf5f3099ffc1b6miklosh
b7f07692f95074fdcf74c7350fbf5f3099ffc1b6miklosh //hide_export.set_sensitive (num > 0);
b7f07692f95074fdcf74c7350fbf5f3099ffc1b6miklosh}
b7f07692f95074fdcf74c7350fbf5f3099ffc1b6miklosh
b7f07692f95074fdcf74c7350fbf5f3099ffc1b6mikloshinline void Export::findDefaultSelection()
b7f07692f95074fdcf74c7350fbf5f3099ffc1b6miklosh{
b7f07692f95074fdcf74c7350fbf5f3099ffc1b6miklosh selection_type key = SELECTION_NUMBER_OF;
b7f07692f95074fdcf74c7350fbf5f3099ffc1b6miklosh
b7f07692f95074fdcf74c7350fbf5f3099ffc1b6miklosh if ((sp_desktop_selection(SP_ACTIVE_DESKTOP))->isEmpty() == false) {
b7f07692f95074fdcf74c7350fbf5f3099ffc1b6miklosh key = SELECTION_SELECTION;
b7f07692f95074fdcf74c7350fbf5f3099ffc1b6miklosh }
b7f07692f95074fdcf74c7350fbf5f3099ffc1b6miklosh
b7f07692f95074fdcf74c7350fbf5f3099ffc1b6miklosh /* Try using the preferences */
b7f07692f95074fdcf74c7350fbf5f3099ffc1b6miklosh if (key == SELECTION_NUMBER_OF) {
b7f07692f95074fdcf74c7350fbf5f3099ffc1b6miklosh
b7f07692f95074fdcf74c7350fbf5f3099ffc1b6miklosh int i = SELECTION_NUMBER_OF;
b7f07692f95074fdcf74c7350fbf5f3099ffc1b6miklosh
b7f07692f95074fdcf74c7350fbf5f3099ffc1b6miklosh Glib::ustring what = prefs->getString("/dialogs/export/exportarea/value");
b7f07692f95074fdcf74c7350fbf5f3099ffc1b6miklosh
b7f07692f95074fdcf74c7350fbf5f3099ffc1b6miklosh if (!what.empty()) {
b7f07692f95074fdcf74c7350fbf5f3099ffc1b6miklosh for (i = 0; i < SELECTION_NUMBER_OF; i++) {
b7f07692f95074fdcf74c7350fbf5f3099ffc1b6miklosh if (what == selection_names[i]) {
b7f07692f95074fdcf74c7350fbf5f3099ffc1b6miklosh break;
b7f07692f95074fdcf74c7350fbf5f3099ffc1b6miklosh }
b7f07692f95074fdcf74c7350fbf5f3099ffc1b6miklosh }
b7f07692f95074fdcf74c7350fbf5f3099ffc1b6miklosh }
b7f07692f95074fdcf74c7350fbf5f3099ffc1b6miklosh
b7f07692f95074fdcf74c7350fbf5f3099ffc1b6miklosh key = (selection_type)i;
26b62dfb088a00b6debad350538a64c2af145f50johanengelen }
b7f07692f95074fdcf74c7350fbf5f3099ffc1b6miklosh
b7f07692f95074fdcf74c7350fbf5f3099ffc1b6miklosh if (key == SELECTION_NUMBER_OF) {
b7f07692f95074fdcf74c7350fbf5f3099ffc1b6miklosh key = SELECTION_SELECTION;
b7f07692f95074fdcf74c7350fbf5f3099ffc1b6miklosh }
b7f07692f95074fdcf74c7350fbf5f3099ffc1b6miklosh
b7f07692f95074fdcf74c7350fbf5f3099ffc1b6miklosh current_key = key;
b7f07692f95074fdcf74c7350fbf5f3099ffc1b6miklosh selectiontype_buttons[current_key]->set_active(true);
b7f07692f95074fdcf74c7350fbf5f3099ffc1b6miklosh updateCheckbuttons ();
b7f07692f95074fdcf74c7350fbf5f3099ffc1b6miklosh}
4b1c2be41ce8c1a88502c1b1885ad1468646fbfftheadib
b7f07692f95074fdcf74c7350fbf5f3099ffc1b6miklosh
b7f07692f95074fdcf74c7350fbf5f3099ffc1b6miklosh/**
b7f07692f95074fdcf74c7350fbf5f3099ffc1b6miklosh * If selection changed or a different document activated, we must
b7f07692f95074fdcf74c7350fbf5f3099ffc1b6miklosh * recalculate any chosen areas.
b7f07692f95074fdcf74c7350fbf5f3099ffc1b6miklosh */
b7f07692f95074fdcf74c7350fbf5f3099ffc1b6mikloshvoid Export::onSelectionChanged()
b7f07692f95074fdcf74c7350fbf5f3099ffc1b6miklosh{
b7f07692f95074fdcf74c7350fbf5f3099ffc1b6miklosh Inkscape::Selection *selection = sp_desktop_selection (SP_ACTIVE_DESKTOP);
b7f07692f95074fdcf74c7350fbf5f3099ffc1b6miklosh
4b1c2be41ce8c1a88502c1b1885ad1468646fbfftheadib if ((current_key == SELECTION_DRAWING || current_key == SELECTION_PAGE) &&
b7f07692f95074fdcf74c7350fbf5f3099ffc1b6miklosh (sp_desktop_selection(SP_ACTIVE_DESKTOP))->isEmpty() == false &&
b7f07692f95074fdcf74c7350fbf5f3099ffc1b6miklosh was_empty) {
4b1c2be41ce8c1a88502c1b1885ad1468646fbfftheadib current_key = SELECTION_SELECTION;
b7f07692f95074fdcf74c7350fbf5f3099ffc1b6miklosh selectiontype_buttons[current_key]->set_active(true);
b7f07692f95074fdcf74c7350fbf5f3099ffc1b6miklosh }
b7f07692f95074fdcf74c7350fbf5f3099ffc1b6miklosh was_empty = (sp_desktop_selection(SP_ACTIVE_DESKTOP))->isEmpty();
17d87f5698f5c2958d38c6a6207c7b322a7adaf9johanengelen
b7f07692f95074fdcf74c7350fbf5f3099ffc1b6miklosh if ( selection &&
b7f07692f95074fdcf74c7350fbf5f3099ffc1b6miklosh SELECTION_CUSTOM != current_key) {
b7f07692f95074fdcf74c7350fbf5f3099ffc1b6miklosh onAreaToggled();
17d87f5698f5c2958d38c6a6207c7b322a7adaf9johanengelen }
3955580a5a68a873b098921626f5b9d841b964ecjaspervdg
3955580a5a68a873b098921626f5b9d841b964ecjaspervdg updateCheckbuttons ();
3955580a5a68a873b098921626f5b9d841b964ecjaspervdg}
b7f07692f95074fdcf74c7350fbf5f3099ffc1b6miklosh
b7f07692f95074fdcf74c7350fbf5f3099ffc1b6mikloshvoid Export::onSelectionModified ( guint /*flags*/ )
b7f07692f95074fdcf74c7350fbf5f3099ffc1b6miklosh{
b7f07692f95074fdcf74c7350fbf5f3099ffc1b6miklosh Inkscape::Selection * Sel;
b7f07692f95074fdcf74c7350fbf5f3099ffc1b6miklosh switch (current_key) {
b7f07692f95074fdcf74c7350fbf5f3099ffc1b6miklosh case SELECTION_DRAWING:
b7f07692f95074fdcf74c7350fbf5f3099ffc1b6miklosh if ( SP_ACTIVE_DESKTOP ) {
b7f07692f95074fdcf74c7350fbf5f3099ffc1b6miklosh SPDocument *doc;
b7f07692f95074fdcf74c7350fbf5f3099ffc1b6miklosh doc = sp_desktop_document (SP_ACTIVE_DESKTOP);
b7f07692f95074fdcf74c7350fbf5f3099ffc1b6miklosh Geom::OptRect bbox = doc->getRoot()->desktopVisualBounds();
b7f07692f95074fdcf74c7350fbf5f3099ffc1b6miklosh if (bbox) {
b7f07692f95074fdcf74c7350fbf5f3099ffc1b6miklosh setArea ( bbox->left(),
b7f07692f95074fdcf74c7350fbf5f3099ffc1b6miklosh bbox->top(),
b7f07692f95074fdcf74c7350fbf5f3099ffc1b6miklosh bbox->right(),
b7f07692f95074fdcf74c7350fbf5f3099ffc1b6miklosh bbox->bottom());
b7f07692f95074fdcf74c7350fbf5f3099ffc1b6miklosh }
b7f07692f95074fdcf74c7350fbf5f3099ffc1b6miklosh }
b7f07692f95074fdcf74c7350fbf5f3099ffc1b6miklosh break;
b7f07692f95074fdcf74c7350fbf5f3099ffc1b6miklosh case SELECTION_SELECTION:
b7f07692f95074fdcf74c7350fbf5f3099ffc1b6miklosh Sel = sp_desktop_selection(SP_ACTIVE_DESKTOP);
b7f07692f95074fdcf74c7350fbf5f3099ffc1b6miklosh if (Sel->isEmpty() == false) {
b7f07692f95074fdcf74c7350fbf5f3099ffc1b6miklosh Geom::OptRect bbox = Sel->visualBounds();
b7f07692f95074fdcf74c7350fbf5f3099ffc1b6miklosh if (bbox)
b7f07692f95074fdcf74c7350fbf5f3099ffc1b6miklosh {
b7f07692f95074fdcf74c7350fbf5f3099ffc1b6miklosh setArea ( bbox->left(),
b7f07692f95074fdcf74c7350fbf5f3099ffc1b6miklosh bbox->top(),
b7f07692f95074fdcf74c7350fbf5f3099ffc1b6miklosh bbox->right(),
b7f07692f95074fdcf74c7350fbf5f3099ffc1b6miklosh bbox->bottom());
b7f07692f95074fdcf74c7350fbf5f3099ffc1b6miklosh }
4b1c2be41ce8c1a88502c1b1885ad1468646fbfftheadib }
b7f07692f95074fdcf74c7350fbf5f3099ffc1b6miklosh break;
b7f07692f95074fdcf74c7350fbf5f3099ffc1b6miklosh default:
b7f07692f95074fdcf74c7350fbf5f3099ffc1b6miklosh /* Do nothing for page or for custom */
b7f07692f95074fdcf74c7350fbf5f3099ffc1b6miklosh break;
b7f07692f95074fdcf74c7350fbf5f3099ffc1b6miklosh }
b7f07692f95074fdcf74c7350fbf5f3099ffc1b6miklosh
b7f07692f95074fdcf74c7350fbf5f3099ffc1b6miklosh return;
17d87f5698f5c2958d38c6a6207c7b322a7adaf9johanengelen}
3955580a5a68a873b098921626f5b9d841b964ecjaspervdg
3955580a5a68a873b098921626f5b9d841b964ecjaspervdg/// Called when one of the selection buttons was toggled.
3955580a5a68a873b098921626f5b9d841b964ecjaspervdgvoid Export::onAreaToggled ()
b7f07692f95074fdcf74c7350fbf5f3099ffc1b6miklosh{
b7f07692f95074fdcf74c7350fbf5f3099ffc1b6miklosh if (update) {
b7f07692f95074fdcf74c7350fbf5f3099ffc1b6miklosh return;
b7f07692f95074fdcf74c7350fbf5f3099ffc1b6miklosh }
b7f07692f95074fdcf74c7350fbf5f3099ffc1b6miklosh
b7f07692f95074fdcf74c7350fbf5f3099ffc1b6miklosh /* Find which button is active */
b7f07692f95074fdcf74c7350fbf5f3099ffc1b6miklosh selection_type key = current_key;
b7f07692f95074fdcf74c7350fbf5f3099ffc1b6miklosh for (int i = 0; i < SELECTION_NUMBER_OF; i++) {
b7f07692f95074fdcf74c7350fbf5f3099ffc1b6miklosh if (selectiontype_buttons[i]->get_active()) {
b7f07692f95074fdcf74c7350fbf5f3099ffc1b6miklosh key = (selection_type)i;
b7f07692f95074fdcf74c7350fbf5f3099ffc1b6miklosh }
b7f07692f95074fdcf74c7350fbf5f3099ffc1b6miklosh }
b7f07692f95074fdcf74c7350fbf5f3099ffc1b6miklosh
b7f07692f95074fdcf74c7350fbf5f3099ffc1b6miklosh if ( SP_ACTIVE_DESKTOP )
b7f07692f95074fdcf74c7350fbf5f3099ffc1b6miklosh {
b7f07692f95074fdcf74c7350fbf5f3099ffc1b6miklosh SPDocument *doc;
b7f07692f95074fdcf74c7350fbf5f3099ffc1b6miklosh Geom::OptRect bbox;
b7f07692f95074fdcf74c7350fbf5f3099ffc1b6miklosh bbox = Geom::Rect(Geom::Point(0.0, 0.0),Geom::Point(0.0, 0.0));
b7f07692f95074fdcf74c7350fbf5f3099ffc1b6miklosh doc = sp_desktop_document (SP_ACTIVE_DESKTOP);
b7f07692f95074fdcf74c7350fbf5f3099ffc1b6miklosh
b7f07692f95074fdcf74c7350fbf5f3099ffc1b6miklosh /* Notice how the switch is used to 'fall through' here to get
b7f07692f95074fdcf74c7350fbf5f3099ffc1b6miklosh various backups. If you modify this without noticing you'll
b7f07692f95074fdcf74c7350fbf5f3099ffc1b6miklosh probabaly screw something up. */
b7f07692f95074fdcf74c7350fbf5f3099ffc1b6miklosh switch (key) {
b7f07692f95074fdcf74c7350fbf5f3099ffc1b6miklosh case SELECTION_SELECTION:
b7f07692f95074fdcf74c7350fbf5f3099ffc1b6miklosh if ((sp_desktop_selection(SP_ACTIVE_DESKTOP))->isEmpty() == false)
b7f07692f95074fdcf74c7350fbf5f3099ffc1b6miklosh {
4b1c2be41ce8c1a88502c1b1885ad1468646fbfftheadib bbox = sp_desktop_selection (SP_ACTIVE_DESKTOP)->visualBounds();
b7f07692f95074fdcf74c7350fbf5f3099ffc1b6miklosh /* Only if there is a selection that we can set
b7f07692f95074fdcf74c7350fbf5f3099ffc1b6miklosh do we break, otherwise we fall through to the
b7f07692f95074fdcf74c7350fbf5f3099ffc1b6miklosh drawing */
b7f07692f95074fdcf74c7350fbf5f3099ffc1b6miklosh // std::cout << "Using selection: SELECTION" << std::endl;
b7f07692f95074fdcf74c7350fbf5f3099ffc1b6miklosh key = SELECTION_SELECTION;
b7f07692f95074fdcf74c7350fbf5f3099ffc1b6miklosh break;
b7f07692f95074fdcf74c7350fbf5f3099ffc1b6miklosh }
b7f07692f95074fdcf74c7350fbf5f3099ffc1b6miklosh case SELECTION_DRAWING:
b7f07692f95074fdcf74c7350fbf5f3099ffc1b6miklosh /** \todo
b7f07692f95074fdcf74c7350fbf5f3099ffc1b6miklosh * This returns wrong values if the document has a viewBox.
b7f07692f95074fdcf74c7350fbf5f3099ffc1b6miklosh */
b7f07692f95074fdcf74c7350fbf5f3099ffc1b6miklosh bbox = doc->getRoot()->desktopVisualBounds();
b7f07692f95074fdcf74c7350fbf5f3099ffc1b6miklosh /* If the drawing is valid, then we'll use it and break
b7f07692f95074fdcf74c7350fbf5f3099ffc1b6miklosh otherwise we drop through to the page settings */
b7f07692f95074fdcf74c7350fbf5f3099ffc1b6miklosh if (bbox) {
b7f07692f95074fdcf74c7350fbf5f3099ffc1b6miklosh // std::cout << "Using selection: DRAWING" << std::endl;
b7f07692f95074fdcf74c7350fbf5f3099ffc1b6miklosh key = SELECTION_DRAWING;
b7f07692f95074fdcf74c7350fbf5f3099ffc1b6miklosh break;
b7f07692f95074fdcf74c7350fbf5f3099ffc1b6miklosh }
b7f07692f95074fdcf74c7350fbf5f3099ffc1b6miklosh case SELECTION_PAGE:
b7f07692f95074fdcf74c7350fbf5f3099ffc1b6miklosh bbox = Geom::Rect(Geom::Point(0.0, 0.0),
b7f07692f95074fdcf74c7350fbf5f3099ffc1b6miklosh Geom::Point(doc->getWidth().value("px"), doc->getHeight().value("px")));
b7f07692f95074fdcf74c7350fbf5f3099ffc1b6miklosh
b7f07692f95074fdcf74c7350fbf5f3099ffc1b6miklosh // std::cout << "Using selection: PAGE" << std::endl;
b7f07692f95074fdcf74c7350fbf5f3099ffc1b6miklosh key = SELECTION_PAGE;
b7f07692f95074fdcf74c7350fbf5f3099ffc1b6miklosh break;
b7f07692f95074fdcf74c7350fbf5f3099ffc1b6miklosh case SELECTION_CUSTOM:
b7f07692f95074fdcf74c7350fbf5f3099ffc1b6miklosh default:
b7f07692f95074fdcf74c7350fbf5f3099ffc1b6miklosh break;
b7f07692f95074fdcf74c7350fbf5f3099ffc1b6miklosh } // switch
b7f07692f95074fdcf74c7350fbf5f3099ffc1b6miklosh
b7f07692f95074fdcf74c7350fbf5f3099ffc1b6miklosh current_key = key;
b7f07692f95074fdcf74c7350fbf5f3099ffc1b6miklosh
b7f07692f95074fdcf74c7350fbf5f3099ffc1b6miklosh // remember area setting
b7f07692f95074fdcf74c7350fbf5f3099ffc1b6miklosh prefs->setString("/dialogs/export/exportarea/value", selection_names[current_key]);
b7f07692f95074fdcf74c7350fbf5f3099ffc1b6miklosh
b7f07692f95074fdcf74c7350fbf5f3099ffc1b6miklosh if ( key != SELECTION_CUSTOM && bbox ) {
b7f07692f95074fdcf74c7350fbf5f3099ffc1b6miklosh setArea ( bbox->min()[Geom::X],
b7f07692f95074fdcf74c7350fbf5f3099ffc1b6miklosh bbox->min()[Geom::Y],
b7f07692f95074fdcf74c7350fbf5f3099ffc1b6miklosh bbox->max()[Geom::X],
b7f07692f95074fdcf74c7350fbf5f3099ffc1b6miklosh bbox->max()[Geom::Y]);
b7f07692f95074fdcf74c7350fbf5f3099ffc1b6miklosh }
b7f07692f95074fdcf74c7350fbf5f3099ffc1b6miklosh
b7f07692f95074fdcf74c7350fbf5f3099ffc1b6miklosh } // end of if ( SP_ACTIVE_DESKTOP )
b7f07692f95074fdcf74c7350fbf5f3099ffc1b6miklosh
b7f07692f95074fdcf74c7350fbf5f3099ffc1b6miklosh if (SP_ACTIVE_DESKTOP && !filename_modified) {
b7f07692f95074fdcf74c7350fbf5f3099ffc1b6miklosh
b7f07692f95074fdcf74c7350fbf5f3099ffc1b6miklosh Glib::ustring filename;
b7f07692f95074fdcf74c7350fbf5f3099ffc1b6miklosh float xdpi = 0.0, ydpi = 0.0;
b7f07692f95074fdcf74c7350fbf5f3099ffc1b6miklosh
b7f07692f95074fdcf74c7350fbf5f3099ffc1b6miklosh switch (key) {
b7f07692f95074fdcf74c7350fbf5f3099ffc1b6miklosh case SELECTION_PAGE:
b7f07692f95074fdcf74c7350fbf5f3099ffc1b6miklosh case SELECTION_DRAWING: {
b7f07692f95074fdcf74c7350fbf5f3099ffc1b6miklosh SPDocument * doc = SP_ACTIVE_DOCUMENT;
b7f07692f95074fdcf74c7350fbf5f3099ffc1b6miklosh sp_document_get_export_hints (doc, filename, &xdpi, &ydpi);
b7f07692f95074fdcf74c7350fbf5f3099ffc1b6miklosh
b7f07692f95074fdcf74c7350fbf5f3099ffc1b6miklosh if (filename.empty()) {
b7f07692f95074fdcf74c7350fbf5f3099ffc1b6miklosh if (!doc_export_name.empty()) {
b7f07692f95074fdcf74c7350fbf5f3099ffc1b6miklosh filename = doc_export_name;
b7f07692f95074fdcf74c7350fbf5f3099ffc1b6miklosh }
b7f07692f95074fdcf74c7350fbf5f3099ffc1b6miklosh }
b7f07692f95074fdcf74c7350fbf5f3099ffc1b6miklosh break;
b7f07692f95074fdcf74c7350fbf5f3099ffc1b6miklosh }
b7f07692f95074fdcf74c7350fbf5f3099ffc1b6miklosh case SELECTION_SELECTION:
b7f07692f95074fdcf74c7350fbf5f3099ffc1b6miklosh if ((sp_desktop_selection(SP_ACTIVE_DESKTOP))->isEmpty() == false) {
b7f07692f95074fdcf74c7350fbf5f3099ffc1b6miklosh
sp_selection_get_export_hints (sp_desktop_selection(SP_ACTIVE_DESKTOP), filename, &xdpi, &ydpi);
/* If we still don't have a filename -- let's build
one that's nice */
if (filename.empty()) {
const gchar * id = "object";
const GSList * reprlst = sp_desktop_selection(SP_ACTIVE_DESKTOP)->reprList();
for(; reprlst != NULL; reprlst = reprlst->next) {
Inkscape::XML::Node * repr = (Inkscape::XML::Node *)reprlst->data;
if (repr->attribute("id")) {
id = repr->attribute("id");
break;
}
}
filename = create_filepath_from_id (id, filename_entry.get_text());
}
}
break;
case SELECTION_CUSTOM:
default:
break;
}
if (!filename.empty()) {
original_name = filename;
filename_entry.set_text(filename);
filename_entry.set_position(filename.length());
}
if (xdpi != 0.0) {
setValue(xdpi_adj, xdpi);
}
/* These can't be separate, and setting x sets y, so for
now setting this is disabled. Hopefully it won't be in
the future */
if (FALSE && ydpi != 0.0) {
setValue(ydpi_adj, ydpi);
}
}
return;
} // end of sp_export_area_toggled()
/// Called when dialog is deleted
bool Export::onProgressDelete (GdkEventAny * /*event*/)
{
interrupted = true;
return TRUE;
} // end of sp_export_progress_delete()
/// Called when progress is cancelled
void Export::onProgressCancel ()
{
interrupted = true;
} // end of sp_export_progress_cancel()
/// Called for every progress iteration
unsigned int Export::onProgressCallback(float value, void *dlg)
{
Gtk::Dialog *dlg2 = reinterpret_cast<Gtk::Dialog*>(dlg);
if (dlg2->get_data("cancel")) {
return FALSE;
}
gint current = GPOINTER_TO_INT(dlg2->get_data("current"));
gint total = GPOINTER_TO_INT(dlg2->get_data("total"));
if (total > 0) {
double completed = current;
completed /= static_cast<double>(total);
value = completed + (value / static_cast<double>(total));
}
Gtk::ProgressBar *prg = reinterpret_cast<Gtk::ProgressBar *>(dlg2->get_data("progress"));
prg->set_fraction(value);
Export *self = reinterpret_cast<Export *>(dlg2->get_data("exportPanel"));
if (self) {
self->_prog.set_fraction(value);
}
int evtcount = 0;
while ((evtcount < 16) && gdk_events_pending()) {
gtk_main_iteration_do(FALSE);
evtcount += 1;
}
gtk_main_iteration_do(FALSE);
return TRUE;
} // end of sp_export_progress_callback()
void Export::setExporting(bool exporting, Glib::ustring const &text)
{
if (exporting) {
_prog.set_text(text);
_prog.set_fraction(0.0);
_prog.set_sensitive(true);
export_button.set_sensitive(false);
} else {
_prog.set_text("");
_prog.set_fraction(0.0);
_prog.set_sensitive(false);
export_button.set_sensitive(true);
}
}
Gtk::Dialog * Export::create_progress_dialog (Glib::ustring progress_text) {
Gtk::Dialog *dlg = new Gtk::Dialog(_("Export in progress"), TRUE);
Gtk::ProgressBar *prg = new Gtk::ProgressBar ();
prg->set_text(progress_text);
dlg->set_data ("progress", prg);
#if GTK_CHECK_VERSION(3,0,0)
Gtk::Box* CA = dlg->get_content_area();
#else
Gtk::Box* CA = dlg->get_vbox();
#endif
CA->pack_start(*prg, FALSE, FALSE, 4);
Gtk::Button* btn = dlg->add_button (Gtk::Stock::CANCEL,Gtk::RESPONSE_CANCEL );
btn->signal_clicked().connect( sigc::mem_fun(*this, &Export::onProgressCancel) );
dlg->signal_delete_event().connect( sigc::mem_fun(*this, &Export::onProgressDelete) );
dlg->show_all ();
return dlg;
}
// FIXME: Some lib function should be available to do this ...
Glib::ustring Export::filename_add_extension (Glib::ustring filename, Glib::ustring extension)
{
Glib::ustring::size_type dot;
dot = filename.find_last_of(".");
if ( !dot )
{
return filename = filename + "." + extension;
}
else
{
if (dot==filename.find_last_of(Glib::ustring::compose(".", extension)))
{
return filename;
}
else
{
return filename = filename + "." + extension;
}
}
}
Glib::ustring Export::absolutize_path_from_document_location (SPDocument *doc, const Glib::ustring &filename)
{
Glib::ustring path;
//Make relative paths go from the document location, if possible:
if (!Glib::path_is_absolute(filename) && doc->getURI()) {
Glib::ustring dirname = Glib::path_get_dirname(doc->getURI());
if (!dirname.empty()) {
path = Glib::build_filename(dirname, filename);
}
}
if (path.empty()) {
path = filename;
}
return path;
}
// Called when unit is changed
void Export::onUnitChanged()
{
onAreaToggled();
}
void Export::onHideExceptSelected ()
{
prefs->setBool("/dialogs/export/hideexceptselected/value", hide_export.get_active());
}
/// Called when export button is clicked
void Export::onExport ()
{
SPDesktop *desktop = SP_ACTIVE_DESKTOP;
if (!desktop) return;
SPNamedView *nv = sp_desktop_namedview(desktop);
SPDocument *doc = sp_desktop_document (desktop);
bool exportSuccessful = false;
bool hide = hide_export.get_active ();
if (batch_export.get_active ()) {
// Batch export of selected objects
gint num = g_slist_length(const_cast<GSList *>(sp_desktop_selection(desktop)->itemList()));
gint n = 0;
if (num < 1) {
desktop->messageStack()->flash(Inkscape::ERROR_MESSAGE, _("No items selected."));
return;
}
prog_dlg = create_progress_dialog(Glib::ustring::compose(_("Exporting %1 files"), num));
prog_dlg->set_data("exportPanel", this);
setExporting(true, Glib::ustring::compose(_("Exporting %1 files"), num));
gint export_count = 0;
for (GSList *i = const_cast<GSList *>(sp_desktop_selection(desktop)->itemList()); i && !interrupted; i = i->next) {
SPItem *item = reinterpret_cast<SPItem *>(i->data);
prog_dlg->set_data("current", GINT_TO_POINTER(n));
prog_dlg->set_data("total", GINT_TO_POINTER(num));
onProgressCallback(0.0, prog_dlg);
// retrieve export filename hint
const gchar *filename = item->getRepr()->attribute("inkscape:export-filename");
Glib::ustring path;
if (!filename) {
Glib::ustring tmp;
path = create_filepath_from_id(item->getId(), tmp);
} else {
path = absolutize_path_from_document_location(doc, filename);
}
// retrieve export dpi hints
const gchar *dpi_hint = item->getRepr()->attribute("inkscape:export-xdpi"); // only xdpi, ydpi is always the same now
gdouble dpi = 0.0;
if (dpi_hint) {
dpi = atof(dpi_hint);
}
if (dpi == 0.0) {
dpi = getValue(xdpi_adj);
}
Geom::OptRect area = item->desktopVisualBounds();
if (area) {
gint width = (gint) (area->width() * dpi / DPI_BASE + 0.5);
gint height = (gint) (area->height() * dpi / DPI_BASE + 0.5);
if (width > 1 && height > 1) {
// Do export
gchar * safeFile = Inkscape::IO::sanitizeString(path.c_str());
MessageCleaner msgCleanup(desktop->messageStack()->pushF(Inkscape::IMMEDIATE_MESSAGE,
_("Exporting file <b>%s</b>..."), safeFile), desktop);
MessageCleaner msgFlashCleanup(desktop->messageStack()->flashF(Inkscape::IMMEDIATE_MESSAGE,
_("Exporting file <b>%s</b>..."), safeFile), desktop);
if (!sp_export_png_file (doc, path.c_str(),
*area, width, height, dpi, dpi,
nv->pagecolor,
onProgressCallback, (void*)prog_dlg,
TRUE, // overwrite without asking
hide ? const_cast<GSList *>(sp_desktop_selection(desktop)->itemList()) : NULL
)) {
gchar * error = g_strdup_printf(_("Could not export to filename %s.\n"), safeFile);
desktop->messageStack()->flashF(Inkscape::ERROR_MESSAGE,
_("Could not export to filename <b>%s</b>."), safeFile);
sp_ui_error_dialog(error);
g_free(error);
} else {
++export_count; // one more item exported successfully
}
g_free(safeFile);
}
}
n++;
}
desktop->messageStack()->flashF(Inkscape::INFORMATION_MESSAGE,
_("Successfully exported <b>%d</b> files from <b>%d</b> selected items."), export_count, num);
setExporting(false);
delete prog_dlg;
prog_dlg = NULL;
interrupted = false;
exportSuccessful = (export_count > 0);
} else {
Glib::ustring filename = filename_entry.get_text();
if (filename.empty()) {
desktop->messageStack()->flash(Inkscape::ERROR_MESSAGE, _("You have to enter a filename."));
sp_ui_error_dialog(_("You have to enter a filename"));
return;
}
float const x0 = getValuePx(x0_adj);
float const y0 = getValuePx(y0_adj);
float const x1 = getValuePx(x1_adj);
float const y1 = getValuePx(y1_adj);
float const xdpi = getValue(xdpi_adj);
float const ydpi = getValue(ydpi_adj);
unsigned long int const width = int(getValue(bmwidth_adj) + 0.5);
unsigned long int const height = int(getValue(bmheight_adj) + 0.5);
if (!((x1 > x0) && (y1 > y0) && (width > 0) && (height > 0))) {
desktop->messageStack()->flash(Inkscape::ERROR_MESSAGE, _("The chosen area to be exported is invalid."));
sp_ui_error_dialog(_("The chosen area to be exported is invalid"));
return;
}
// make sure that .png is the extension of the file:
Glib::ustring const filename_ext = filename_add_extension(filename, "png");
filename_entry.set_text(filename_ext);
filename_entry.set_position(filename_ext.length());
Glib::ustring path = absolutize_path_from_document_location(doc, filename_ext);
Glib::ustring dirname = Glib::path_get_dirname(path);
if ( dirname.empty()
|| !Inkscape::IO::file_test(dirname.c_str(), (GFileTest)(G_FILE_TEST_EXISTS | G_FILE_TEST_IS_DIR)) )
{
gchar *safeDir = Inkscape::IO::sanitizeString(dirname.c_str());
gchar *error = g_strdup_printf(_("Directory %s does not exist or is not a directory.\n"),
safeDir);
desktop->messageStack()->flash(Inkscape::ERROR_MESSAGE, error);
sp_ui_error_dialog(error);
g_free(safeDir);
g_free(error);
return;
}
Glib::ustring fn = path_get_basename (path);
/* TRANSLATORS: %1 will be the filename, %2 the width, and %3 the height of the image */
prog_dlg = create_progress_dialog (Glib::ustring::compose(_("Exporting %1 (%2 x %3)"), fn, width, height));
prog_dlg->set_data("exportPanel", this);
setExporting(true, Glib::ustring::compose(_("Exporting %1 (%2 x %3)"), fn, width, height));
prog_dlg->set_data("current", GINT_TO_POINTER(0));
prog_dlg->set_data("total", GINT_TO_POINTER(0));
/* Do export */
ExportResult status = sp_export_png_file(sp_desktop_document(desktop), path.c_str(),
Geom::Rect(Geom::Point(x0, y0), Geom::Point(x1, y1)), width, height, xdpi, ydpi,
nv->pagecolor,
onProgressCallback, (void*)prog_dlg,
FALSE,
hide ? const_cast<GSList *>(sp_desktop_selection(desktop)->itemList()) : NULL
);
if (status == EXPORT_ERROR) {
gchar * safeFile = Inkscape::IO::sanitizeString(path.c_str());
gchar * error = g_strdup_printf(_("Could not export to filename %s.\n"), safeFile);
desktop->messageStack()->flash(Inkscape::ERROR_MESSAGE, error);
sp_ui_error_dialog(error);
g_free(safeFile);
g_free(error);
} else if (status == EXPORT_OK) {
exportSuccessful = true;
gchar *safeFile = Inkscape::IO::sanitizeString(path.c_str());
desktop->messageStack()->flashF(Inkscape::INFORMATION_MESSAGE, _("Drawing exported to <b>%s</b>."), safeFile);
g_free(safeFile);
} else {
desktop->messageStack()->flash(Inkscape::INFORMATION_MESSAGE, _("Export aborted."));
}
/* Reset the filename so that it can be changed again by changing
selections and all that */
original_name = filename_ext;
filename_modified = false;
setExporting(false);
delete prog_dlg;
prog_dlg = NULL;
interrupted = false;
/* Setup the values in the document */
switch (current_key) {
case SELECTION_PAGE:
case SELECTION_DRAWING: {
SPDocument * doc = SP_ACTIVE_DOCUMENT;
Inkscape::XML::Node * repr = doc->getReprRoot();
bool modified = false;
bool saved = DocumentUndo::getUndoSensitive(doc);
DocumentUndo::setUndoSensitive(doc, false);
gchar const *temp_string = repr->attribute("inkscape:export-filename");
if (temp_string == NULL || (filename_ext != temp_string)) {
repr->setAttribute("inkscape:export-filename", filename_ext.c_str());
modified = true;
}
temp_string = repr->attribute("inkscape:export-xdpi");
if (temp_string == NULL || xdpi != atof(temp_string)) {
sp_repr_set_svg_double(repr, "inkscape:export-xdpi", xdpi);
modified = true;
}
temp_string = repr->attribute("inkscape:export-ydpi");
if (temp_string == NULL || ydpi != atof(temp_string)) {
sp_repr_set_svg_double(repr, "inkscape:export-ydpi", ydpi);
modified = true;
}
DocumentUndo::setUndoSensitive(doc, saved);
if (modified) {
doc->setModifiedSinceSave();
}
break;
}
case SELECTION_SELECTION: {
const GSList * reprlst;
SPDocument * doc = SP_ACTIVE_DOCUMENT;
bool modified = false;
bool saved = DocumentUndo::getUndoSensitive(doc);
DocumentUndo::setUndoSensitive(doc, false);
reprlst = sp_desktop_selection(desktop)->reprList();
for(; reprlst != NULL; reprlst = reprlst->next) {
Inkscape::XML::Node * repr = static_cast<Inkscape::XML::Node *>(reprlst->data);
const gchar * temp_string;
Glib::ustring dir = Glib::path_get_dirname(filename.c_str());
const gchar* docURI=SP_ACTIVE_DOCUMENT->getURI();
Glib::ustring docdir;
if (docURI)
{
docdir = Glib::path_get_dirname(docURI);
}
if (repr->attribute("id") == NULL ||
!(filename_ext.find_last_of(repr->attribute("id")) &&
( !docURI ||
(dir == docdir)))) {
temp_string = repr->attribute("inkscape:export-filename");
if (temp_string == NULL || (filename_ext != temp_string)) {
repr->setAttribute("inkscape:export-filename", filename_ext.c_str());
modified = true;
}
}
temp_string = repr->attribute("inkscape:export-xdpi");
if (temp_string == NULL || xdpi != atof(temp_string)) {
sp_repr_set_svg_double(repr, "inkscape:export-xdpi", xdpi);
modified = true;
}
temp_string = repr->attribute("inkscape:export-ydpi");
if (temp_string == NULL || ydpi != atof(temp_string)) {
sp_repr_set_svg_double(repr, "inkscape:export-ydpi", ydpi);
modified = true;
}
}
DocumentUndo::setUndoSensitive(doc, saved);
if (modified) {
doc->setModifiedSinceSave();
}
break;
}
default:
break;
}
}
if (exportSuccessful && closeWhenDone.get_active()) {
for ( Gtk::Container *parent = get_parent(); parent; parent = parent->get_parent()) {
if ( GDL_IS_DOCK_ITEM(parent->gobj()) ) {
GdlDockItem *item = GDL_DOCK_ITEM(parent->gobj());
if (item) {
gdl_dock_item_hide_item(item);
}
break;
}
}
}
} // end of sp_export_export_clicked()
/// Called when Browse button is clicked
/// @todo refactor this code to use ui/dialogs/filedialog.cpp
void Export::onBrowse ()
{
GtkWidget *fs;
Glib::ustring filename;
fs = gtk_file_chooser_dialog_new (_("Select a filename for exporting"),
(GtkWindow*)desktop->getToplevel(),
GTK_FILE_CHOOSER_ACTION_SAVE,
_("_Cancel"), GTK_RESPONSE_CANCEL,
_("_Save"), GTK_RESPONSE_ACCEPT,
NULL );
#ifdef WITH_GNOME_VFS
if (gnome_vfs_initialized()) {
gtk_file_chooser_set_local_only(GTK_FILE_CHOOSER(fs), false);
}
#endif
sp_transientize (fs);
gtk_window_set_modal(GTK_WINDOW (fs), true);
filename = filename_entry.get_text();
if (filename.empty()) {
Glib::ustring tmp;
filename = create_filepath_from_id(tmp, tmp);
}
gtk_file_chooser_set_filename (GTK_FILE_CHOOSER (fs), filename.c_str());
#ifdef WIN32
// code in this section is borrowed from ui/dialogs/filedialogimpl-win32.cpp
OPENFILENAMEW opf;
WCHAR filter_string[20];
wcsncpy(filter_string, L"PNG#*.png##", 11);
filter_string[3] = L'\0';
filter_string[9] = L'\0';
filter_string[10] = L'\0';
WCHAR* title_string = (WCHAR*)g_utf8_to_utf16(_("Select a filename for exporting"), -1, NULL, NULL, NULL);
WCHAR* extension_string = (WCHAR*)g_utf8_to_utf16("*.png", -1, NULL, NULL, NULL);
// Copy the selected file name, converting from UTF-8 to UTF-16
std::string dirname = Glib::path_get_dirname(filename.raw());
if ( !Glib::file_test(dirname, Glib::FILE_TEST_EXISTS) ||
Glib::file_test(filename, Glib::FILE_TEST_IS_DIR) ||
dirname.empty() )
{
Glib::ustring tmp;
filename = create_filepath_from_id(tmp, tmp);
}
WCHAR _filename[_MAX_PATH + 1];
memset(_filename, 0, sizeof(_filename));
gunichar2* utf16_path_string = g_utf8_to_utf16(filename.c_str(), -1, NULL, NULL, NULL);
wcsncpy(_filename, reinterpret_cast<wchar_t*>(utf16_path_string), _MAX_PATH);
g_free(utf16_path_string);
SPDesktop *desktop = SP_ACTIVE_DESKTOP;
Glib::RefPtr<const Gdk::Window> parentWindow = desktop->getToplevel()->get_window();
g_assert(parentWindow->gobj() != NULL);
#if WITH_GTKMM_3_0
opf.hwndOwner = (HWND)gdk_win32_window_get_handle((GdkWindow*)parentWindow->gobj());
#else
opf.hwndOwner = (HWND)gdk_win32_drawable_get_handle((GdkDrawable*)parentWindow->gobj());
#endif
opf.lpstrFilter = filter_string;
opf.lpstrCustomFilter = 0;
opf.nMaxCustFilter = 0L;
opf.nFilterIndex = 1L;
opf.lpstrFile = _filename;
opf.nMaxFile = _MAX_PATH;
opf.lpstrFileTitle = NULL;
opf.nMaxFileTitle=0;
opf.lpstrInitialDir = 0;
opf.lpstrTitle = title_string;
opf.nFileOffset = 0;
opf.nFileExtension = 2;
opf.lpstrDefExt = extension_string;
opf.lpfnHook = NULL;
opf.lCustData = 0;
opf.Flags = OFN_PATHMUSTEXIST;
opf.lStructSize = sizeof(OPENFILENAMEW);
if (GetSaveFileNameW(&opf) != 0)
{
// Copy the selected file name, converting from UTF-16 to UTF-8
gchar *utf8string = g_utf16_to_utf8((const gunichar2*)opf.lpstrFile, _MAX_PATH, NULL, NULL, NULL);
filename_entry.set_text(utf8string);
filename_entry.set_position(strlen(utf8string));
g_free(utf8string);
}
g_free(extension_string);
g_free(title_string);
#else
if (gtk_dialog_run (GTK_DIALOG (fs)) == GTK_RESPONSE_ACCEPT)
{
gchar *file;
file = gtk_file_chooser_get_filename (GTK_FILE_CHOOSER (fs));
gchar * utf8file = g_filename_to_utf8( file, -1, NULL, NULL, NULL );
filename_entry.set_text (utf8file);
filename_entry.set_position(strlen(utf8file));
g_free(utf8file);
g_free(file);
}
#endif
gtk_widget_destroy (fs);
return;
} // end of sp_export_browse_clicked()
// TODO: Move this to nr-rect-fns.h.
bool Export::bbox_equal(Geom::Rect const &one, Geom::Rect const &two)
{
double const epsilon = pow(10.0, -EXPORT_COORD_PRECISION);
return (
(fabs(one.min()[Geom::X] - two.min()[Geom::X]) < epsilon) &&
(fabs(one.min()[Geom::Y] - two.min()[Geom::Y]) < epsilon) &&
(fabs(one.max()[Geom::X] - two.max()[Geom::X]) < epsilon) &&
(fabs(one.max()[Geom::Y] - two.max()[Geom::Y]) < epsilon)
);
}
/**
*This function is used to detect the current selection setting
* based on the values in the x0, y0, x1 and y0 fields.
*
* One of the most confusing parts of this function is why the array
* is built at the beginning. What needs to happen here is that we
* should always check the current selection to see if it is the valid
* one. While this is a performance improvement it is also a usability
* one during the cases where things like selections and drawings match
* size. This way buttons change less 'randomly' (atleast in the eyes
* of the user). To do this an array is built where the current selection
* type is placed first, and then the others in an order from smallest
* to largest (this can be configured by reshuffling \c test_order).
*
* All of the values in this function are rounded to two decimal places
* because that is what is shown to the user. While everything is kept
* more accurate than that, the user can't control more acurrate than
* that, so for this to work for them - it needs to check on that level
* of accuracy.
*
* @todo finish writing this up.
*/
void Export::detectSize() {
static const selection_type test_order[SELECTION_NUMBER_OF] = {SELECTION_SELECTION, SELECTION_DRAWING, SELECTION_PAGE, SELECTION_CUSTOM};
selection_type this_test[SELECTION_NUMBER_OF + 1];
selection_type key = SELECTION_NUMBER_OF;
Geom::Point x(getValuePx(x0_adj),
getValuePx(y0_adj));
Geom::Point y(getValuePx(x1_adj),
getValuePx(y1_adj));
Geom::Rect current_bbox(x, y);
this_test[0] = current_key;
for (int i = 0; i < SELECTION_NUMBER_OF; i++) {
this_test[i + 1] = test_order[i];
}
for (int i = 0;
i < SELECTION_NUMBER_OF + 1 &&
key == SELECTION_NUMBER_OF &&
SP_ACTIVE_DESKTOP != NULL;
i++) {
switch (this_test[i]) {
case SELECTION_SELECTION:
if ((sp_desktop_selection(SP_ACTIVE_DESKTOP))->isEmpty() == false) {
Geom::OptRect bbox = (sp_desktop_selection (SP_ACTIVE_DESKTOP))->bounds(SPItem::VISUAL_BBOX);
if ( bbox && bbox_equal(*bbox,current_bbox)) {
key = SELECTION_SELECTION;
}
}
break;
case SELECTION_DRAWING: {
SPDocument *doc = sp_desktop_document (SP_ACTIVE_DESKTOP);
Geom::OptRect bbox = doc->getRoot()->desktopVisualBounds();
if ( bbox && bbox_equal(*bbox,current_bbox) ) {
key = SELECTION_DRAWING;
}
break;
}
case SELECTION_PAGE: {
SPDocument *doc;
doc = sp_desktop_document (SP_ACTIVE_DESKTOP);
Geom::Point x(0.0, 0.0);
Geom::Point y(doc->getWidth().value("px"),
doc->getHeight().value("px"));
Geom::Rect bbox(x, y);
if (bbox_equal(bbox,current_bbox)) {
key = SELECTION_PAGE;
}
break;
}
default:
break;
}
}
// std::cout << std::endl;
if (key == SELECTION_NUMBER_OF) {
key = SELECTION_CUSTOM;
}
current_key = key;
selectiontype_buttons[current_key]->set_active(true);
return;
} /* sp_export_detect_size */
/// Called when area x0 value is changed
#if WITH_GTKMM_3_0
void Export::areaXChange(Glib::RefPtr<Gtk::Adjustment>& adj)
#else
void Export::areaXChange (Gtk::Adjustment *adj)
#endif
{
float x0, x1, xdpi, width;
if (update) {
return;
}
update = true;
x0 = getValuePx(x0_adj);
x1 = getValuePx(x1_adj);
xdpi = getValue(xdpi_adj);
width = floor ((x1 - x0) * xdpi / DPI_BASE + 0.5);
if (width < SP_EXPORT_MIN_SIZE) {
width = SP_EXPORT_MIN_SIZE;
if (adj == x1_adj) {
x1 = x0 + width * DPI_BASE / xdpi;
setValuePx(x1_adj, x1);
} else {
x0 = x1 - width * DPI_BASE / xdpi;
setValuePx(x0_adj, x0);
}
}
setValuePx(width_adj, x1 - x0);
setValue(bmwidth_adj, width);
detectSize();
update = false;
return;
} // end of sp_export_area_x_value_changed()
/// Called when area y0 value is changed.
#if WITH_GTKMM_3_0
void Export::areaYChange(Glib::RefPtr<Gtk::Adjustment>& adj)
#else
void Export::areaYChange (Gtk::Adjustment *adj)
#endif
{
float y0, y1, ydpi, height;
if (update) {
return;
}
update = true;
y0 = getValuePx(y0_adj);
y1 = getValuePx(y1_adj);
ydpi = getValue(ydpi_adj);
height = floor ((y1 - y0) * ydpi / DPI_BASE + 0.5);
if (height < SP_EXPORT_MIN_SIZE) {
//const gchar *key;
height = SP_EXPORT_MIN_SIZE;
//key = (const gchar *)g_object_get_data(G_OBJECT (adj), "key");
if (adj == y1_adj) {
//if (!strcmp (key, "y0")) {
y1 = y0 + height * DPI_BASE / ydpi;
setValuePx(y1_adj, y1);
} else {
y0 = y1 - height * DPI_BASE / ydpi;
setValuePx(y0_adj, y0);
}
}
setValuePx(height_adj, y1 - y0);
setValue(bmheight_adj, height);
detectSize();
update = false;
return;
} // end of sp_export_area_y_value_changed()
/// Called when x1-x0 or area width is changed
void Export::onAreaWidthChange()
{
if (update) {
return;
}
update = true;
float x0 = getValuePx(x0_adj);
float xdpi = getValue(xdpi_adj);
float width = getValuePx(width_adj);
float bmwidth = floor(width * xdpi / DPI_BASE + 0.5);
if (bmwidth < SP_EXPORT_MIN_SIZE) {
bmwidth = SP_EXPORT_MIN_SIZE;
width = bmwidth * DPI_BASE / xdpi;
setValuePx(width_adj, width);
}
setValuePx(x1_adj, x0 + width);
setValue(bmwidth_adj, bmwidth);
update = false;
return;
} // end of sp_export_area_width_value_changed()
/// Called when y1-y0 or area height is changed.
void Export::onAreaHeightChange()
{
if (update) {
return;
}
update = true;
float y0 = getValuePx(y0_adj);
//float y1 = sp_export_value_get_px(y1_adj);
float ydpi = getValue(ydpi_adj);
float height = getValuePx(height_adj);
float bmheight = floor (height * ydpi / DPI_BASE + 0.5);
if (bmheight < SP_EXPORT_MIN_SIZE) {
bmheight = SP_EXPORT_MIN_SIZE;
height = bmheight * DPI_BASE / ydpi;
setValuePx(height_adj, height);
}
setValuePx(y1_adj, y0 + height);
setValue(bmheight_adj, bmheight);
update = false;
return;
} // end of sp_export_area_height_value_changed()
/**
* A function to set the ydpi.
* @param base The export dialog.
*
* This function grabs all of the y values and then figures out the
* new bitmap size based on the changing dpi value. The dpi value is
* gotten from the xdpi setting as these can not currently be independent.
*/
void Export::setImageY()
{
float y0, y1, xdpi;
y0 = getValuePx(y0_adj);
y1 = getValuePx(y1_adj);
xdpi = getValue(xdpi_adj);
setValue(ydpi_adj, xdpi);
setValue(bmheight_adj, (y1 - y0) * xdpi / DPI_BASE);
return;
} // end of setImageY()
/**
* A function to set the xdpi.
*
* This function grabs all of the x values and then figures out the
* new bitmap size based on the changing dpi value. The dpi value is
* gotten from the xdpi setting as these can not currently be independent.
*
*/
void Export::setImageX()
{
float x0, x1, xdpi;
x0 = getValuePx(x0_adj);
x1 = getValuePx(x1_adj);
xdpi = getValue(xdpi_adj);
setValue(ydpi_adj, xdpi);
setValue(bmwidth_adj, (x1 - x0) * xdpi / DPI_BASE);
return;
} // end of setImageX()
/// Called when pixel width is changed
void Export::onBitmapWidthChange ()
{
float x0, x1, bmwidth, xdpi;
if (update) {
return;
}
update = true;
x0 = getValuePx(x0_adj);
x1 = getValuePx(x1_adj);
bmwidth = getValue(bmwidth_adj);
if (bmwidth < SP_EXPORT_MIN_SIZE) {
bmwidth = SP_EXPORT_MIN_SIZE;
setValue(bmwidth_adj, bmwidth);
}
xdpi = bmwidth * DPI_BASE / (x1 - x0);
setValue(xdpi_adj, xdpi);
setImageY ();
update = false;
return;
} // end of sp_export_bitmap_width_value_changed()
/// Called when pixel height is changed
void Export::onBitmapHeightChange ()
{
float y0, y1, bmheight, xdpi;
if (update) {
return;
}
update = true;
y0 = getValuePx(y0_adj);
y1 = getValuePx(y1_adj);
bmheight = getValue(bmheight_adj);
if (bmheight < SP_EXPORT_MIN_SIZE) {
bmheight = SP_EXPORT_MIN_SIZE;
setValue(bmheight_adj, bmheight);
}
xdpi = bmheight * DPI_BASE / (y1 - y0);
setValue(xdpi_adj, xdpi);
setImageX ();
update = false;
return;
} // end of sp_export_bitmap_width_value_changed()
/**
* A function to adjust the bitmap width when the xdpi value changes.
*
* The first thing this function checks is to see if we are doing an
* update. If we are, this function just returns because there is another
* instance of it that will handle everything for us. If there is a
* units change, we also assume that everyone is being updated appropriately
* and there is nothing for us to do.
*
* If we're the highest level function, we set the update flag, and
* continue on our way.
*
* All of the values are grabbed using the \c sp_export_value_get functions
* (call to the _pt ones for x0 and x1 but just standard for xdpi). The
* xdpi value is saved in the preferences for the next time the dialog
* is opened. (does the selection dpi need to be set here?)
*
* A check is done to to ensure that we aren't outputing an invalid width,
* this is set by SP_EXPORT_MIN_SIZE. If that is the case the dpi is
* changed to make it valid.
*
* After all of this the bitmap width is changed.
*
* We also change the ydpi. This is a temporary hack as these can not
* currently be independent. This is likely to change in the future.
*
*/
void Export::onExportXdpiChange()
{
float x0, x1, xdpi, bmwidth;
if (update) {
return;
}
update = true;
x0 = getValuePx(x0_adj);
x1 = getValuePx(x1_adj);
xdpi = getValue(xdpi_adj);
// remember xdpi setting
prefs->setDouble("/dialogs/export/defaultxdpi/value", xdpi);
bmwidth = (x1 - x0) * xdpi / DPI_BASE;
if (bmwidth < SP_EXPORT_MIN_SIZE) {
bmwidth = SP_EXPORT_MIN_SIZE;
if (x1 != x0)
xdpi = bmwidth * DPI_BASE / (x1 - x0);
else
xdpi = DPI_BASE;
setValue(xdpi_adj, xdpi);
}
setValue(bmwidth_adj, bmwidth);
setImageY ();
update = false;
return;
} // end of sp_export_xdpi_value_changed()
/**
* A function to change the area that is used for the exported.
* bitmap.
*
* This function just calls \c sp_export_value_set_px for each of the
* parameters that is passed in. This allows for setting them all in
* one convient area.
*
* Update is set to suspend all of the other test running while all the
* values are being set up. This allows for a performance increase, but
* it also means that the wrong type won't be detected with only some of
* the values set. After all the values are set everyone is told that
* there has been an update.
*
* @param x0 Horizontal upper left hand corner of the picture in points.
* @param y0 Vertical upper left hand corner of the picture in points.
* @param x1 Horizontal lower right hand corner of the picture in points.
* @param y1 Vertical lower right hand corner of the picture in points.
*/
void Export::setArea( double x0, double y0, double x1, double y1 )
{
update = true;
setValuePx(x1_adj, x1);
setValuePx(y1_adj, y1);
setValuePx(x0_adj, x0);
setValuePx(y0_adj, y0);
update = false;
areaXChange (x1_adj);
areaYChange (y1_adj);
return;
}
/**
* Sets the value of an adjustment.
*
* @param adj The adjustment widget
* @param val What value to set it to.
*/
#if WITH_GTKMM_3_0
void Export::setValue(Glib::RefPtr<Gtk::Adjustment>& adj, double val )
#else
void Export::setValue( Gtk::Adjustment *adj, double val )
#endif
{
if (adj) {
adj->set_value(val);
}
}
/**
* A function to set a value using the units points.
*
* This function first gets the adjustment for the key that is passed
* in. It then figures out what units are currently being used in the
* dialog. After doing all of that, it then converts the incoming
*value and sets the adjustment.
*
* @param adj The adjustment widget
* @param val What the value should be in points.
*/
#if WITH_GTKMM_3_0
void Export::setValuePx(Glib::RefPtr<Gtk::Adjustment>& adj, double val)
#else
void Export::setValuePx( Gtk::Adjustment *adj, double val)
#endif
{
Unit const *unit = unit_selector.getUnit();
setValue(adj, Inkscape::Util::Quantity::convert(val, "px", unit));
return;
}
/**
* Get the value of an adjustment in the export dialog.
*
* This function gets the adjustment from the data field in the export
* dialog. It then grabs the value from the adjustment.
*
* @param adj The adjustment widget
*
* @return The value in the specified adjustment.
*/
#if WITH_GTKMM_3_0
float Export::getValue(Glib::RefPtr<Gtk::Adjustment>& adj)
#else
float Export::getValue( Gtk::Adjustment *adj )
#endif
{
if (!adj) {
g_message("sp_export_value_get : adj is NULL");
return 0.0;
}
return adj->get_value();
}
/**
* Grabs a value in the export dialog and converts the unit
* to points.
*
* This function, at its most basic, is a call to \c sp_export_value_get
* to get the value of the adjustment. It then finds the units that
* are being used by looking at the "units" attribute of the export
* dialog. Using that it converts the returned value into points.
*
* @param adj The adjustment widget
*
* @return The value in the adjustment in points.
*/
#if WITH_GTKMM_3_0
float Export::getValuePx(Glib::RefPtr<Gtk::Adjustment>& adj)
#else
float Export::getValuePx( Gtk::Adjustment *adj )
#endif
{
float value = getValue( adj);
Unit const *unit = unit_selector.getUnit();
return Inkscape::Util::Quantity::convert(value, unit, "px");
} // end of sp_export_value_get_px()
/**
* This function is called when the filename is changed by
* anyone. It resets the virgin bit.
*
* This function gets called when the text area is modified. It is
* looking for the case where the text area is modified from its
* original value. In that case it sets the "filename-modified" bit
* to TRUE. If the text dialog returns back to the original text, the
* bit gets reset. This should stop simple mistakes.
*/
void Export::onFilenameModified()
{
if (original_name == filename_entry.get_text()) {
filename_modified = false;
} else {
filename_modified = true;
}
return;
} // end sp_export_filename_modified
}
}
}
/*
Local Variables:
mode:c++
c-file-style:"stroustrup"
c-file-offsets:((innamespace . 0)(inline-open . 0)(case-label . +))
indent-tabs-mode:nil
fill-column:99
End:
*/
// vim: filetype=cpp:expandtab:shiftwidth=4:tabstop=8:softtabstop=4:fileencoding=utf-8:textwidth=99 :