Logo Search packages:      
Sourcecode: inkscape version File versions  Download package

void sp_export_dialog ( void   ) 

export to bitmap dialog

Creates a dialog window for exporting an image to a bitmap if one doesn't already exist and shows it to the user. If the dialog has already been created, it simply shows the window.

Todo:
Needs fixing: there's no way to set ydpi currently, so we use the defaultxdpi value here, too...

Definition at line 391 of file export.cpp.

References Inkscape::XML::Node::attribute(), Inkscape::Verb::get(), sp_export_bitmap_height_value_changed(), sp_export_bitmap_width_value_changed(), sp_export_browse_clicked(), sp_export_dialog_delete(), sp_export_export_clicked(), sp_export_filename_modified(), sp_export_spinbutton_new(), sp_export_xdpi_value_changed(), win_data::stop, and win_data::win.

{
    if (!dlg) {

        gchar title[500];
        sp_ui_dialog_title_string (Inkscape::Verb::get(SP_VERB_FILE_EXPORT), title);

        dlg = sp_window_new (title, TRUE);

        if (x == -1000 || y == -1000) {
            x = prefs_get_int_attribute (prefs_path, "x", 0);
            y = prefs_get_int_attribute (prefs_path, "y", 0);
        }

        if (w ==0 || h == 0) {
            w = prefs_get_int_attribute (prefs_path, "w", 0);
            h = prefs_get_int_attribute (prefs_path, "h", 0);
        }

//        if (x<0) x=0;
//        if (y<0) y=0;

        if (w && h) gtk_window_resize ((GtkWindow *) dlg, w, h);
        if (x >= 0 && y >= 0 && (x < (gdk_screen_width()-MIN_ONSCREEN_DISTANCE)) && (y < (gdk_screen_height()-MIN_ONSCREEN_DISTANCE)))
            gtk_window_move ((GtkWindow *) dlg, x, y);
        else
            gtk_window_set_position(GTK_WINDOW(dlg), GTK_WIN_POS_CENTER);
        sp_transientize (dlg);
        wd.win = dlg;
        wd.stop = 0;

        g_signal_connect   ( G_OBJECT (INKSCAPE), "activate_desktop",
                             G_CALLBACK (sp_transientize_callback), &wd);

        gtk_signal_connect ( GTK_OBJECT (dlg), "event",
                             GTK_SIGNAL_FUNC (sp_dialog_event_handler), dlg);

        gtk_signal_connect ( GTK_OBJECT (dlg), "destroy",
                             G_CALLBACK (sp_export_dialog_destroy), dlg);

        gtk_signal_connect ( GTK_OBJECT (dlg), "delete_event",
                             G_CALLBACK (sp_export_dialog_delete), dlg);

        g_signal_connect   ( G_OBJECT (INKSCAPE), "shut_down",
                             G_CALLBACK (sp_export_dialog_delete), dlg);

        g_signal_connect   ( G_OBJECT (INKSCAPE), "dialogs_hide",
                             G_CALLBACK (sp_dialog_hide), dlg);

        g_signal_connect   ( G_OBJECT (INKSCAPE), "dialogs_unhide",
                             G_CALLBACK (sp_dialog_unhide), dlg);

        GtkTooltips *tt = gtk_tooltips_new();

        Gtk::VBox *vb = new Gtk::VBox(false, 3);
        vb->set_border_width(3);
        gtk_container_add (GTK_CONTAINER (dlg), GTK_WIDGET(vb->gobj()));

        Gtk::VBox *vb_singleexport = new Gtk::VBox(false, 0);
        vb_singleexport->set_border_width(0);
        vb->pack_start(*vb_singleexport);
        gtk_object_set_data(GTK_OBJECT(dlg), "vb_singleexport", vb_singleexport);

        /* Export area frame */
        {
            Gtk::VBox *area_box = sp_export_dialog_area_box(dlg);
            area_box->set_border_width(3);
            vb_singleexport->pack_start(*area_box, false, false, 0);
        }

        /* Bitmap size frame */
        {
            Gtk::VBox *size_box = new Gtk::VBox(false, 3);
            size_box->set_border_width(3);

            Gtk::Label* lbl = new Gtk::Label(_("<big><b>Bitmap size</b></big>"), Gtk::ALIGN_LEFT);
            lbl->set_use_markup(true);
            size_box->pack_start(*lbl, false, false, 0);
            const int rows = 2;
            const int cols = 5;
            const bool homogeneous = false;
            Gtk::Table *t = new Gtk::Table(rows, cols, homogeneous);
            t->set_row_spacings (4);
            t->set_col_spacings (4);
            size_box->pack_start(*t);

            sp_export_spinbutton_new ( "bmwidth", 16.0, 1.0, 1000000.0, 1.0, 10.0,
                                       NULL, GTK_WIDGET(t->gobj()), 0, 0,
                                       _("_Width:"), _("pixels at"), 0, 1,
                                       G_CALLBACK
                                       (sp_export_bitmap_width_value_changed),
                                       dlg );

            sp_export_spinbutton_new ( "xdpi",
                                       prefs_get_double_attribute
                                       ( "dialogs.export.defaultxdpi",
                                         "value", DPI_BASE),
                                       0.01, 100000.0, 0.1, 1.0, NULL, GTK_WIDGET(t->gobj()), 3, 0,
                                       NULL, _("dp_i"), 2, 1,
                                       G_CALLBACK (sp_export_xdpi_value_changed),
                                       dlg );

            sp_export_spinbutton_new ( "bmheight", 16.0, 1.0, 1000000.0, 1.0, 10.0,
                                       NULL, GTK_WIDGET(t->gobj()), 0, 1,
                                       _("Height:"), _("pixels at"), 0, 1,
                                       G_CALLBACK
                                       (sp_export_bitmap_height_value_changed),
                                       dlg );

            /** \todo
             * Needs fixing: there's no way to set ydpi currently, so we use
             *       the defaultxdpi value here, too...
             */
            sp_export_spinbutton_new ( "ydpi", prefs_get_double_attribute
                                       ( "dialogs.export.defaultxdpi",
                                         "value", DPI_BASE),
                                       0.01, 100000.0, 0.1, 1.0, NULL, GTK_WIDGET(t->gobj()), 3, 1,
                                       NULL, _("dpi"), 2, 0, NULL, dlg );

            vb_singleexport->pack_start(*size_box);
        }

        /* File entry */
        {
            Gtk::VBox* file_box = new Gtk::VBox(false, 3);
            file_box->set_border_width(3);

            // true = has mnemonic
            Gtk::Label *flabel = new Gtk::Label(_("<big><b>_Filename</b></big>"), Gtk::ALIGN_LEFT, Gtk::ALIGN_CENTER, true);
            flabel->set_use_markup(true);
            file_box->pack_start(*flabel, false, false, 0);

            Gtk::Entry *fe = new Gtk::Entry();

            /*
             * set the default filename to be that of the current path + document
             * with .png extension
             *
             * One thing to notice here is that this filename may get
             * overwritten, but it won't happen here.  The filename gets
             * written into the text field, but then the button to select
             * the area gets set.  In that code the filename can be changed
             * if there are some with presidence in the document.  So, while
             * this code sets the name first, it may not be the one users
             * really see.
             */
            if (SP_ACTIVE_DOCUMENT && SP_DOCUMENT_URI (SP_ACTIVE_DOCUMENT))
            {
                gchar *name;
                SPDocument * doc = SP_ACTIVE_DOCUMENT;
                const gchar *uri = SP_DOCUMENT_URI (doc);
                Inkscape::XML::Node * repr = sp_document_repr_root(doc);
                const gchar * text_extension = repr->attribute("inkscape:output_extension");
                Inkscape::Extension::Output * oextension = NULL;

                if (text_extension != NULL) {
                    oextension = dynamic_cast<Inkscape::Extension::Output *>(Inkscape::Extension::db.get(text_extension));
                }

                if (oextension != NULL) {
                    gchar * old_extension = oextension->get_extension();
                    if (g_str_has_suffix(uri, old_extension)) {
                        gchar * uri_copy;
                        gchar * extension_point;
                        gchar * final_name;

                        uri_copy = g_strdup(uri);
                        extension_point = g_strrstr(uri_copy, old_extension);
                        extension_point[0] = '\0';

                        final_name = g_strconcat(uri_copy, ".png", NULL);
                        fe->set_text(final_name);

                        g_free(final_name);
                        g_free(uri_copy);
                    }
                } else {
                    name = g_strconcat(uri, ".png", NULL);
                    fe->set_text(name);
                    g_free(name);
                }

                doc_export_name = g_strdup(fe->get_text().c_str());
            }
            g_signal_connect ( G_OBJECT (fe->gobj()), "changed",
                               G_CALLBACK (sp_export_filename_modified), dlg);

            Gtk::HBox *hb = new Gtk::HBox(FALSE, 5);

            {
                // true = has mnemonic
                Gtk::Button *b = new Gtk::Button();

                Gtk::HBox* pixlabel = new Gtk::HBox(false, 3);
                Gtk::Image *im = new Gtk::Image(Gtk::StockID(Gtk::Stock::INDEX),
                        Gtk::ICON_SIZE_BUTTON);
                pixlabel->pack_start(*im);

                Gtk::Label *l = new Gtk::Label();
                l->set_markup_with_mnemonic(_("_Browse..."));
                pixlabel->pack_start(*l);

                b->add(*pixlabel);

                hb->pack_end (*b, false, false, 4);
                g_signal_connect ( G_OBJECT (b->gobj()), "clicked",
                                   G_CALLBACK (sp_export_browse_clicked), NULL );
            }

            hb->pack_start (*fe, true, true, 0);
            file_box->add(*hb);
            gtk_object_set_data (GTK_OBJECT (dlg), "filename", fe->gobj());
            gtk_object_set_data (GTK_OBJECT (dlg), "filename-modified", (gpointer)FALSE);
            original_name = g_strdup(fe->get_text().c_str());
            // pressing enter in the filename field is the same as clicking export:
            g_signal_connect ( G_OBJECT (fe->gobj()), "activate",
                               G_CALLBACK (sp_export_export_clicked), dlg );
            // focus is in the filename initially:
            fe->grab_focus();

            // mnemonic in frame label moves focus to filename:
            flabel->set_mnemonic_widget(*fe);

            vb_singleexport->pack_start(*file_box);
        }

        {
            Gtk::HBox* batch_box = new Gtk::HBox(FALSE, 5);
            GtkWidget *be = gtk_check_button_new_with_label(_("Batch export all selected objects"));
            gtk_widget_set_sensitive(GTK_WIDGET(be), TRUE);
            gtk_object_set_data(GTK_OBJECT(dlg), "batch_checkbox", be);
            batch_box->pack_start(*Glib::wrap(be), false, false);
            gtk_tooltips_set_tip(tt, be, _("Export each selected object into its own PNG file, using export hints if any (caution, overwrites without asking!)"), NULL);
            batch_box->show_all();
            g_signal_connect(G_OBJECT(be), "toggled", GTK_SIGNAL_FUNC(batch_export_clicked), dlg);
            vb->pack_start(*batch_box);
        }

        {
            Gtk::HBox* hide_box = new Gtk::HBox(FALSE, 5);
            GtkWidget *he = gtk_check_button_new_with_label(_("Hide all except selected"));
            gtk_widget_set_sensitive(GTK_WIDGET(he), TRUE);
            gtk_object_set_data(GTK_OBJECT(dlg), "hide_checkbox", he);
            hide_box->pack_start(*Glib::wrap(he), false, false);
            gtk_tooltips_set_tip(tt, he, _("In the exported image, hide all objects except those that are selected"), NULL);
            hide_box->show_all();
            vb->pack_start(*hide_box);
        }

        /* Buttons */
        Gtk::HButtonBox* bb = new Gtk::HButtonBox(Gtk::BUTTONBOX_END);
        bb->set_border_width(3);

        {
            Gtk::Button *b = new Gtk::Button();
            Gtk::HBox* image_label = new Gtk::HBox(false, 3);
            Gtk::Image *im = new Gtk::Image(Gtk::StockID(Gtk::Stock::APPLY),
                    Gtk::ICON_SIZE_BUTTON);
            image_label->pack_start(*im);

            Gtk::Label *l = new Gtk::Label();
            l->set_markup_with_mnemonic(_("_Export"));
            image_label->pack_start(*l);

            b->add(*image_label);
            gtk_tooltips_set_tip (tt, GTK_WIDGET(b->gobj()), _("Export the bitmap file with these settings"), NULL);
            gtk_signal_connect ( GTK_OBJECT (b->gobj()), "clicked",
                                 GTK_SIGNAL_FUNC (sp_export_export_clicked), dlg );
            bb->pack_end(*b, false, false, 0);
        }

        vb->pack_end(*bb, false, false, 0);
        vb->show_all();

    } // end of if (!dlg)

    sp_export_find_default_selection(dlg);

    gtk_window_present ((GtkWindow *) dlg);

    return;
} // end of sp_export_dialog()


Generated by  Doxygen 1.6.0   Back to index