Code

apply patch 1498946 by zbsz (fixes #1492545 "PNG resolution value export")
[inkscape.git] / src / dialogs / export.cpp
index 54df647829f8a16c95cb8140e90f7108dad8988a..a141053dcb4e0ec5979e9fd0478d8d929e7490f8 100644 (file)
 #endif
 
 #include <gtk/gtk.h>
+#include <gtkmm/box.h>
+#include <gtkmm/buttonbox.h>
+#include <gtkmm/label.h>
+#include <gtkmm/widget.h>
+#include <gtkmm/togglebutton.h>
+#include <gtkmm/entry.h>
+#include <gtkmm/image.h>
+#include <gtkmm/stockid.h>
+#include <gtkmm/stock.h>
 
 #include <glibmm/i18n.h>
 #include "helper/unit-menu.h"
@@ -55,8 +64,6 @@
 static void sp_export_area_toggled   ( GtkToggleButton *tb, GtkObject *base );
 static void sp_export_export_clicked ( GtkButton *button, GtkObject *base );
 static void sp_export_browse_clicked ( GtkButton *button, gpointer userdata );
-static void sp_export_browse_store   ( GtkButton *button, gpointer userdata );
-
 
 static void sp_export_area_x_value_changed       ( GtkAdjustment *adj, 
                                                    GtkObject *base);
@@ -73,6 +80,9 @@ static void sp_export_area_height_value_changed  ( GtkAdjustment *adj,
 static void sp_export_bitmap_width_value_changed ( GtkAdjustment *adj, 
                                                    GtkObject *base);
                                                    
+static void sp_export_bitmap_height_value_changed ( GtkAdjustment *adj, 
+                                                   GtkObject *base);
+                                                   
 static void sp_export_xdpi_value_changed         ( GtkAdjustment *adj, 
                                                    GtkObject *base);
                                            
@@ -239,40 +249,38 @@ sp_export_spinbutton_new ( gchar *key, float val, float min, float max,
 } // end of sp_export_spinbutton_new()
 
 
-static GtkWidget *
-sp_export_dialog_area_frame (GtkWidget * dlg)
+static Gtk::VBox *
+sp_export_dialog_area_box (GtkWidget * dlg)
 {
-    GtkWidget * f, * t, * hb, * b, * us, * l, * vb, * unitbox;
+    Gtk::VBox* vb = new Gtk::VBox(false, 3);
 
-    f = gtk_frame_new (_("Export area"));
-    vb = gtk_vbox_new (FALSE, 2);
-    gtk_container_add (GTK_CONTAINER (f), vb);
+    Gtk::Label* lbl = new Gtk::Label(_("<big><b>Export area</b></big>"), Gtk::ALIGN_LEFT);
+    lbl->set_use_markup(true);
+    vb->pack_start(*lbl);
 
     /* Units box */
-    unitbox = gtk_hbox_new (FALSE, 0);
-    gtk_container_set_border_width (GTK_CONTAINER (unitbox), 4);
+    Gtk::HBox* unitbox = new Gtk::HBox(false, 0);
     /* gets added to the vbox later, but the unit selector is needed
        earlier than that */
 
-    us = sp_unit_selector_new (SP_UNIT_ABSOLUTE | SP_UNIT_DEVICE);
+    Gtk::Widget* us = Glib::wrap(sp_unit_selector_new (SP_UNIT_ABSOLUTE | SP_UNIT_DEVICE));
     SPDesktop *desktop = SP_ACTIVE_DESKTOP;
     if (desktop)
-        sp_unit_selector_set_unit (SP_UNIT_SELECTOR(us), SP_DT_NAMEDVIEW(desktop)->doc_units);
-    gtk_box_pack_end (GTK_BOX (unitbox), us, FALSE, FALSE, 0);
-    l = gtk_label_new (_("Units:"));
-    gtk_box_pack_end (GTK_BOX (unitbox), l, FALSE, FALSE, 3);
-    gtk_object_set_data (GTK_OBJECT (dlg), "units", us);
+        sp_unit_selector_set_unit (SP_UNIT_SELECTOR(us->gobj()), sp_desktop_namedview(desktop)->doc_units);
+    unitbox->pack_end(*us, false, false, 0);
+    Gtk::Label* l = new Gtk::Label(_("Units:"));
+    unitbox->pack_end(*l, false, false, 3);
+    gtk_object_set_data (GTK_OBJECT (dlg), "units", us->gobj());
 
-    hb = gtk_hbox_new (TRUE, 0);
-    gtk_container_set_border_width (GTK_CONTAINER (hb), 4);
-    gtk_box_pack_start(GTK_BOX(vb), hb, FALSE, FALSE, 3);
+    Gtk::HBox* togglebox = new Gtk::HBox(true, 0);
 
+    Gtk::ToggleButton* b;
     for (int i = 0; i < SELECTION_NUMBER_OF; i++) {
-        b = gtk_toggle_button_new_with_mnemonic (_(selection_labels[i]));
-        gtk_object_set_data (GTK_OBJECT (b), "key", GINT_TO_POINTER(i));
-        gtk_object_set_data (GTK_OBJECT (dlg), selection_names[i], b);
-        gtk_box_pack_start (GTK_BOX (hb), b, FALSE, TRUE, 0);
-        gtk_signal_connect ( GTK_OBJECT (b), "clicked", 
+        b = new Gtk::ToggleButton(_(selection_labels[i]), true);
+        b->set_data("key", GINT_TO_POINTER(i));
+        gtk_object_set_data (GTK_OBJECT (dlg), selection_names[i], b->gobj());
+        togglebox->pack_start(*b, false, true, 0);
+        gtk_signal_connect ( GTK_OBJECT (b->gobj()), "clicked", 
                              GTK_SIGNAL_FUNC (sp_export_area_toggled), dlg );
     }
 
@@ -283,55 +291,55 @@ sp_export_dialog_area_frame (GtkWidget * dlg)
     g_signal_connect ( G_OBJECT (INKSCAPE), "activate_desktop", 
                        G_CALLBACK (sp_export_selection_changed), dlg );
     
-    t = gtk_table_new (2, 6, FALSE);
-    gtk_box_pack_start(GTK_BOX(vb), t, FALSE, FALSE, 0);
-    gtk_table_set_row_spacings (GTK_TABLE (t), 4);
-    gtk_table_set_col_spacings (GTK_TABLE (t), 4);
-    gtk_container_set_border_width (GTK_CONTAINER (t), 4);
-
-    sp_export_spinbutton_new ( "x0", 0.0, -1000000.0, 1000000.0, 0.1, 1.0, us, 
-                               t, 0, 0, _("_x0:"), NULL, EXPORT_COORD_PRECISION, 1,
+    Gtk::Table* t = new Gtk::Table(2, 6, FALSE);
+    t->set_row_spacings (4);
+    t->set_col_spacings (4);
+
+    sp_export_spinbutton_new ( "x0", 0.0, -1000000.0, 1000000.0, 0.1, 1.0, us->gobj(), 
+                               GTK_WIDGET(t->gobj()), 0, 0, _("_x0:"), NULL, EXPORT_COORD_PRECISION, 1,
                                G_CALLBACK ( sp_export_area_x_value_changed), 
                                dlg );
 
-    sp_export_spinbutton_new ( "x1", 0.0, -1000000.0, 1000000.0, 0.1, 1.0, us, 
-                               t, 2, 0, _("x_1:"), NULL, EXPORT_COORD_PRECISION, 1,
+    sp_export_spinbutton_new ( "x1", 0.0, -1000000.0, 1000000.0, 0.1, 1.0, us->gobj()
+                               GTK_WIDGET(t->gobj()), 2, 0, _("x_1:"), NULL, EXPORT_COORD_PRECISION, 1,
                                G_CALLBACK (sp_export_area_x_value_changed), 
                                dlg );
 
     sp_export_spinbutton_new ( "width", 0.0, -1000000.0, 1000000.0, 0.1, 1.0, 
-                               us, t, 4, 0, _("Width:"), NULL, EXPORT_COORD_PRECISION, 1,
+                               us->gobj(), GTK_WIDGET(t->gobj()), 4, 0, _("Width:"), NULL, EXPORT_COORD_PRECISION, 1,
                                G_CALLBACK 
                                    (sp_export_area_width_value_changed), 
                                dlg );
 
-    sp_export_spinbutton_new ( "y0", 0.0, -1000000.0, 1000000.0, 0.1, 1.0, us, 
-                               t, 0, 1, _("_y0:"), NULL, EXPORT_COORD_PRECISION, 1,
+    sp_export_spinbutton_new ( "y0", 0.0, -1000000.0, 1000000.0, 0.1, 1.0, us->gobj()
+                               GTK_WIDGET(t->gobj()), 0, 1, _("_y0:"), NULL, EXPORT_COORD_PRECISION, 1,
                                G_CALLBACK (sp_export_area_y_value_changed), 
                                dlg );
 
-    sp_export_spinbutton_new ( "y1", 0.0, -1000000.0, 1000000.0, 0.1, 1.0, us, 
-                               t, 2, 1, _("y_1:"), NULL, EXPORT_COORD_PRECISION, 1,
+    sp_export_spinbutton_new ( "y1", 0.0, -1000000.0, 1000000.0, 0.1, 1.0, us->gobj()
+                               GTK_WIDGET(t->gobj()), 2, 1, _("y_1:"), NULL, EXPORT_COORD_PRECISION, 1,
                                G_CALLBACK (sp_export_area_y_value_changed), 
                                dlg );
 
     sp_export_spinbutton_new ( "height", 0.0, -1000000.0, 1000000.0, 0.1, 1.0, 
-                               us, t, 4, 1, _("Height:"), NULL, EXPORT_COORD_PRECISION, 1,
+                               us->gobj(), GTK_WIDGET(t->gobj()), 4, 1, _("Height:"), NULL, EXPORT_COORD_PRECISION, 1,
                                G_CALLBACK (sp_export_area_height_value_changed), 
                                dlg );
 
-    /* Adding in the unit box */
-    gtk_box_pack_start(GTK_BOX(vb), unitbox, FALSE, FALSE, 0);
+    vb->pack_start(*togglebox, false, false, 3);
+    vb->pack_start(*t, false, false, 0);
+    vb->pack_start(*unitbox, false, false, 0);
 
-    return f;
-} // end of sp_export_dialog_area_frame
+    return vb;
+} // end of sp_export_dialog_area_box
 
 
 void
 sp_export_dialog (void)
 {
     if (!dlg) {
-        GtkWidget *vb, *hb;
+        Gtk::VBox* vb;
+        Gtk::HBox* hb;
 
         gchar title[500];
         sp_ui_dialog_title_string (Inkscape::Verb::get(SP_VERB_FILE_EXPORT), title);
@@ -387,28 +395,35 @@ sp_export_dialog (void)
 
         GtkTooltips *tt = gtk_tooltips_new();
 
-        vb = gtk_vbox_new (FALSE, 4);
-        gtk_container_set_border_width (GTK_CONTAINER (vb), 0);
-        gtk_container_add (GTK_CONTAINER (dlg), vb);
+        vb = new Gtk::VBox(false, 3);
+        vb->set_border_width(3);
+        gtk_container_add (GTK_CONTAINER (dlg), GTK_WIDGET(vb->gobj()));
 
         /* Export area frame */
         {
-            GtkWidget *f = sp_export_dialog_area_frame(dlg);
-            gtk_box_pack_start (GTK_BOX (vb), f, FALSE, FALSE, 0);
+            Gtk::VBox *area_box = sp_export_dialog_area_box(dlg);
+            area_box->set_border_width(3);
+            vb->pack_start(*area_box, false, false, 0);
         }
 
         /* Bitmap size frame */
         {
-            GtkWidget *f = gtk_frame_new (_("Bitmap size"));
-            gtk_box_pack_start (GTK_BOX (vb), f, FALSE, FALSE, 0);
-            GtkWidget *t = gtk_table_new (2, 5, FALSE);
-            gtk_table_set_row_spacings (GTK_TABLE (t), 4);
-            gtk_table_set_col_spacings (GTK_TABLE (t), 4);
-            gtk_container_set_border_width (GTK_CONTAINER (t), 4);
-            gtk_container_add (GTK_CONTAINER (f), t);
+            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, t, 0, 0,
+                                       NULL, GTK_WIDGET(t->gobj()), 0, 0,
                                        _("_Width:"), _("pixels at"), 0, 1,
                                        G_CALLBACK 
                                        (sp_export_bitmap_width_value_changed), 
@@ -418,14 +433,17 @@ sp_export_dialog (void)
                                        prefs_get_double_attribute 
                                        ( "dialogs.export.defaultxdpi", 
                                          "value", DPI_BASE), 
-                                       1.0, 9600.0, 0.1, 1.0, NULL, t, 3, 0,
+                                       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, 10.0, 
-                                       NULL, t, 0, 1, _("Height:"), _("pixels at"), 
-                                       0, 0, NULL, 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  
@@ -434,18 +452,23 @@ sp_export_dialog (void)
             sp_export_spinbutton_new ( "ydpi", prefs_get_double_attribute 
                                        ( "dialogs.export.defaultxdpi", 
                                          "value", DPI_BASE), 
-                                       1.0, 9600.0, 0.1, 1.0, NULL, t, 3, 1,
+                                       0.01, 100000.0, 0.1, 1.0, NULL, GTK_WIDGET(t->gobj()), 3, 1,
                                        NULL, _("dpi"), 2, 0, NULL, dlg );
+
+            vb->pack_start(*size_box);
         }
 
         /* File entry */
         {
-            GtkWidget *frame = gtk_frame_new ("");
-            GtkWidget *flabel = gtk_label_new_with_mnemonic (_("_Filename"));
-            gtk_frame_set_label_widget (GTK_FRAME(frame), flabel);
-            gtk_box_pack_start (GTK_BOX (vb), frame, FALSE, FALSE, 0);
+            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);
 
-            GtkWidget *fe = gtk_entry_new ();
+            Gtk::Entry *fe = new Gtk::Entry();
 
             /*
              * set the default filename to be that of the current path + document
@@ -484,63 +507,85 @@ sp_export_dialog (void)
                         extension_point[0] = '\0';
 
                         final_name = g_strconcat(uri_copy, ".png", NULL);
-                        gtk_entry_set_text (GTK_ENTRY (fe), final_name);
+                        fe->set_text(final_name);
 
                         g_free(final_name);
                         g_free(uri_copy);
                     }
                 } else {
                     name = g_strconcat(uri, ".png", NULL);
-                    gtk_entry_set_text (GTK_ENTRY (fe), name);
+                    fe->set_text(name);
                     g_free(name);
                 }
 
-                doc_export_name = g_strdup(gtk_entry_get_text(GTK_ENTRY(fe)));
+                doc_export_name = g_strdup(fe->get_text().c_str());
             }
-            g_signal_connect ( G_OBJECT (fe), "changed",
+            g_signal_connect ( G_OBJECT (fe->gobj()), "changed",
                                G_CALLBACK (sp_export_filename_modified), dlg);
 
-            hb = gtk_hbox_new (FALSE, 5);
-            gtk_container_add (GTK_CONTAINER (frame), hb);
-            gtk_container_set_border_width (GTK_CONTAINER (hb), 4);
+            hb = new Gtk::HBox(FALSE, 5);
 
             {
-                GtkWidget *b = gtk_button_new_with_mnemonic (_("_Browse..."));
-                gtk_box_pack_end (GTK_BOX (hb), b, FALSE, FALSE, 4);
-                g_signal_connect ( G_OBJECT (b), "clicked",
+                // 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 );
             }
 
-            gtk_box_pack_start (GTK_BOX (hb), fe, TRUE, TRUE, 0);
-            gtk_object_set_data (GTK_OBJECT (dlg), "filename", fe);
+            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(gtk_entry_get_text (GTK_ENTRY (fe)));
+            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), "activate",
+            g_signal_connect ( G_OBJECT (fe->gobj()), "activate",
                                G_CALLBACK (sp_export_export_clicked), dlg );
             // focus is in the filename initially:
-            gtk_widget_grab_focus (GTK_WIDGET (fe));
+            fe->grab_focus();
 
             // mnemonic in frame label moves focus to filename:
-            gtk_label_set_mnemonic_widget (GTK_LABEL(flabel), fe);
+            flabel->set_mnemonic_widget(*fe);
+
+            vb->pack_start(*file_box);
         }
 
         /* Buttons */
-        hb = gtk_hbox_new (FALSE, 0);
-        gtk_box_pack_end (GTK_BOX (vb), hb, FALSE, FALSE, 0);
+        Gtk::HButtonBox* bb = new Gtk::HButtonBox(Gtk::BUTTONBOX_END);
+        bb->set_border_width(3);
 
         {
-            GtkWidget *b = gtk_button_new ();
-            GtkWidget *l = gtk_label_new ("");
-            gtk_label_set_markup_with_mnemonic (GTK_LABEL(l), _(" <b>_Export</b> "));
-            gtk_container_add (GTK_CONTAINER(b), l);
-            gtk_tooltips_set_tip (tt, b, _("Export the bitmap file with these settings"), NULL);
-            gtk_signal_connect ( GTK_OBJECT (b), "clicked",
+            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 );
-            gtk_box_pack_end (GTK_BOX (hb), b, FALSE, FALSE, 0);
+            bb->pack_end(*b, false, false, 0);
         }
 
-        gtk_widget_show_all (vb);
+        vb->pack_end(*bb, false, false, 0);
+        vb->show_all();
 
     } // end of if (!dlg)
 
@@ -556,7 +601,7 @@ sp_export_find_default_selection(GtkWidget * dlg)
 {
     selection_type key = SELECTION_NUMBER_OF;
 
-    if ((SP_DT_SELECTION(SP_ACTIVE_DESKTOP))->isEmpty() == false) {
+    if ((sp_desktop_selection(SP_ACTIVE_DESKTOP))->isEmpty() == false) {
         key = SELECTION_SELECTION;
     }
 
@@ -604,13 +649,13 @@ sp_export_selection_changed ( Inkscape::Application *inkscape,
     current_key = (selection_type)(GPOINTER_TO_INT(gtk_object_get_data(GTK_OBJECT(base), "selection-type")));
 
     if ((current_key == SELECTION_DRAWING || current_key == SELECTION_PAGE) &&
-            (SP_DT_SELECTION(SP_ACTIVE_DESKTOP))->isEmpty() == false &&
+            (sp_desktop_selection(SP_ACTIVE_DESKTOP))->isEmpty() == false &&
             was_empty) {
         gtk_toggle_button_set_active
             ( GTK_TOGGLE_BUTTON ( gtk_object_get_data (base, selection_names[SELECTION_SELECTION])),
               TRUE );
     }
-    was_empty = (SP_DT_SELECTION(SP_ACTIVE_DESKTOP))->isEmpty();
+    was_empty = (sp_desktop_selection(SP_ACTIVE_DESKTOP))->isEmpty();
 
     current_key = (selection_type)(GPOINTER_TO_INT(gtk_object_get_data(GTK_OBJECT(base), "selection-type")));
 
@@ -639,19 +684,22 @@ sp_export_selection_modified ( Inkscape::Application *inkscape,
         case SELECTION_DRAWING:
             if ( SP_ACTIVE_DESKTOP ) {
                 SPDocument *doc;
-                NRRect bbox;
-                doc = SP_DT_DOCUMENT (SP_ACTIVE_DESKTOP);
-                sp_item_bbox_desktop (SP_ITEM (SP_DOCUMENT_ROOT (doc)), &bbox);
+                doc = sp_desktop_document (SP_ACTIVE_DESKTOP);
+                NR::Rect bbox = sp_item_bbox_desktop (SP_ITEM (SP_DOCUMENT_ROOT (doc)));
 
-                if (!(bbox.x0 > bbox.x1 && bbox.y0 > bbox.y1)) {
-                    sp_export_set_area (base, bbox.x0, bbox.y0, bbox.x1, bbox.y1);
+                if (!(bbox.min()[NR::X] > bbox.max()[NR::X] &&
+                      bbox.min()[NR::Y] > bbox.max()[NR::Y])) {
+                    sp_export_set_area (base, bbox.min()[NR::X],
+                                              bbox.min()[NR::Y],
+                                              bbox.max()[NR::X],
+                                              bbox.max()[NR::Y]);
                 }
             }
             break;
         case SELECTION_SELECTION:
-            if ((SP_DT_SELECTION(SP_ACTIVE_DESKTOP))->isEmpty() == false) {
+            if ((sp_desktop_selection(SP_ACTIVE_DESKTOP))->isEmpty() == false) {
                 NRRect bbox;
-                (SP_DT_SELECTION (SP_ACTIVE_DESKTOP))->bounds(&bbox);
+                (sp_desktop_selection (SP_ACTIVE_DESKTOP))->bounds(&bbox);
                 sp_export_set_area (base, bbox.x0, bbox.y0, bbox.x1, bbox.y1);
             }
             break;
@@ -698,17 +746,17 @@ sp_export_area_toggled (GtkToggleButton *tb, GtkObject *base)
     if ( SP_ACTIVE_DESKTOP )
     {
         SPDocument *doc;
-        NRRect bbox;
-        doc = SP_DT_DOCUMENT (SP_ACTIVE_DESKTOP);
+        NR::Rect bbox;
+        doc = sp_desktop_document (SP_ACTIVE_DESKTOP);
 
         /* Notice how the switch is used to 'fall through' here to get
            various backups.  If you modify this without noticing you'll
            probabaly screw something up. */
         switch (key) {
             case SELECTION_SELECTION:
-                if ((SP_DT_SELECTION(SP_ACTIVE_DESKTOP))->isEmpty() == false)
+                if ((sp_desktop_selection(SP_ACTIVE_DESKTOP))->isEmpty() == false)
                 {
-                    (SP_DT_SELECTION (SP_ACTIVE_DESKTOP))->bounds(&bbox);
+                    bbox = (sp_desktop_selection (SP_ACTIVE_DESKTOP))->bounds();
                     /* Only if there is a selection that we can set
                        do we break, otherwise we fall through to the
                        drawing */
@@ -720,20 +768,21 @@ sp_export_area_toggled (GtkToggleButton *tb, GtkObject *base)
                 /** \todo 
                  * This returns wrong values if the document has a viewBox.
                  */
-                sp_item_bbox_desktop (SP_ITEM (SP_DOCUMENT_ROOT (doc)), &bbox);
+                bbox = sp_item_bbox_desktop (SP_ITEM (SP_DOCUMENT_ROOT (doc)));
                 
                 /* If the drawing is valid, then we'll use it and break
                    otherwise we drop through to the page settings */
-                if (!(bbox.x0 > bbox.x1 && bbox.y0 > bbox.y1)) { 
+                if (!(bbox.min()[NR::X] > bbox.max()[NR::X] &&
+                      bbox.min()[NR::Y] > bbox.max()[NR::Y])) { 
                     // std::cout << "Using selection: DRAWING" << std::endl;
                     key = SELECTION_DRAWING;
                     break;
                 }
             case SELECTION_PAGE:
-                bbox.x0 = 0.0;
-                bbox.y0 = 0.0;
-                bbox.x1 = sp_document_width (doc);
-                bbox.y1 = sp_document_height (doc);
+                bbox = NR::Rect(NR::Point(0.0, 0.0), 
+                                NR::Point(sp_document_width(doc), sp_document_height(doc))
+                                );
+
                 // std::cout << "Using selection: PAGE" << std::endl;
                 key = SELECTION_PAGE;
                 break;
@@ -747,7 +796,10 @@ sp_export_area_toggled (GtkToggleButton *tb, GtkObject *base)
                                      "value", selection_names[key]);
 
         if (key != SELECTION_CUSTOM) {
-            sp_export_set_area (base, bbox.x0, bbox.y0, bbox.x1, bbox.y1);
+            sp_export_set_area (base, bbox.min()[NR::X],
+                                      bbox.min()[NR::Y],
+                                      bbox.max()[NR::X],
+                                      bbox.max()[NR::Y]);
         }
     
     } // end of if ( SP_ACTIVE_DESKTOP )
@@ -788,17 +840,16 @@ sp_export_area_toggled (GtkToggleButton *tb, GtkObject *base)
                         filename = g_strdup("");
                     }
                 }
-
                 break;
             }
             case SELECTION_SELECTION:
-                if ((SP_DT_SELECTION(SP_ACTIVE_DESKTOP))->isEmpty() == false) {
+                if ((sp_desktop_selection(SP_ACTIVE_DESKTOP))->isEmpty() == false) {
                     const GSList * reprlst;
                     bool filename_search = TRUE;
                     bool xdpi_search = TRUE;
                     bool ydpi_search = TRUE;
 
-                    reprlst = SP_DT_SELECTION(SP_ACTIVE_DESKTOP)->reprList();
+                    reprlst = sp_desktop_selection(SP_ACTIVE_DESKTOP)->reprList();
                     for(; reprlst != NULL &&
                             filename_search &&
                             xdpi_search &&
@@ -836,7 +887,7 @@ sp_export_area_toggled (GtkToggleButton *tb, GtkObject *base)
                        one that's nice */
                     if (filename == NULL) {
                         const gchar * id = NULL;
-                        reprlst = SP_DT_SELECTION(SP_ACTIVE_DESKTOP)->reprList();
+                        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")) {
@@ -985,7 +1036,7 @@ sp_export_export_clicked (GtkButton *button, GtkObject *base)
     }
     g_free(dirname);
 
-    SPNamedView *nv = SP_DT_NAMEDVIEW(SP_ACTIVE_DESKTOP);
+    SPNamedView *nv = sp_desktop_namedview(SP_ACTIVE_DESKTOP);
     GtkWidget *dlg, *prg, *btn; /* progressbar-stuff */
     char *fn;
     gchar *text;
@@ -1018,8 +1069,8 @@ sp_export_export_clicked (GtkButton *button, GtkObject *base)
     gtk_widget_show_all (dlg);
     
     /* Do export */
-    if (!sp_export_png_file (SP_DT_DOCUMENT (SP_ACTIVE_DESKTOP), filename, 
-                             x0, y0, x1, y1, width, height, 
+    if (!sp_export_png_file (sp_desktop_document (SP_ACTIVE_DESKTOP), filename, 
+                             x0, y0, x1, y1, width, height, xdpi, ydpi, 
                              nv->pagecolor, 
                              sp_export_progress_callback, base)) {
         gchar * error;
@@ -1079,7 +1130,7 @@ sp_export_export_clicked (GtkButton *button, GtkObject *base)
 
             bool saved = sp_document_get_undo_sensitive(doc);
             sp_document_set_undo_sensitive(doc, FALSE);
-            reprlst = SP_DT_SELECTION(SP_ACTIVE_DESKTOP)->reprList();
+            reprlst = sp_desktop_selection(SP_ACTIVE_DESKTOP)->reprList();
 
             for(; reprlst != NULL; reprlst = reprlst->next) {
                 Inkscape::XML::Node * repr = (Inkscape::XML::Node *)reprlst->data;
@@ -1130,7 +1181,13 @@ sp_export_browse_clicked (GtkButton *button, gpointer userdata)
     GtkWidget *fs, *fe;
     const gchar *filename;
 
-    fs = gtk_file_selection_new (_("Select a filename for exporting"));
+    fs = gtk_file_chooser_dialog_new (_("Select a filename for exporting"),
+                                      NULL,
+                                      GTK_FILE_CHOOSER_ACTION_SAVE,
+                                      GTK_STOCK_CANCEL, GTK_RESPONSE_CANCEL,
+                                      GTK_STOCK_SAVE, GTK_RESPONSE_ACCEPT,
+                                      NULL );
+
     fe = (GtkWidget *)g_object_get_data (G_OBJECT (dlg), "filename");
 
     sp_transientize (fs);
@@ -1143,48 +1200,26 @@ sp_export_browse_clicked (GtkButton *button, gpointer userdata)
         filename = homedir_path(NULL);
     }
 
-    gtk_file_selection_set_filename (GTK_FILE_SELECTION (fs), filename);
+    gtk_file_chooser_set_filename (GTK_FILE_CHOOSER (fs), filename);
 
-    g_signal_connect ( GTK_OBJECT (GTK_FILE_SELECTION (fs)->ok_button),
-                       "clicked",
-                       G_CALLBACK (sp_export_browse_store),
-                       (gpointer) fs );
+    if (gtk_dialog_run (GTK_DIALOG (fs)) == GTK_RESPONSE_ACCEPT)
+    {
+        gchar *file;
 
-    g_signal_connect_swapped ( GTK_OBJECT (GTK_FILE_SELECTION (fs)->ok_button),
-                               "clicked",
-                               G_CALLBACK (gtk_widget_destroy),
-                               (gpointer) fs );
+        file = gtk_file_chooser_get_filename (GTK_FILE_CHOOSER (fs));
+        gchar * utf8file = g_filename_to_utf8( file, -1, NULL, NULL, NULL );
+        gtk_entry_set_text (GTK_ENTRY (fe), utf8file);
+        g_free(utf8file);
 
-    g_signal_connect_swapped ( GTK_OBJECT
-                                   (GTK_FILE_SELECTION (fs)->cancel_button),
-                               "clicked",
-                               G_CALLBACK (gtk_widget_destroy),
-                               (gpointer) fs );
+        g_object_set_data (G_OBJECT (dlg), "filename", fe);
+        g_free(file);
+    }
 
-    gtk_widget_show (fs);
+    gtk_widget_destroy (fs);
 
     return;
 } // end of sp_export_browse_clicked()
 
-/// Called when OK clicked in file dialog
-static void
-sp_export_browse_store (GtkButton *button, gpointer userdata)
-{
-    GtkWidget *fs = (GtkWidget *)userdata, *fe;
-    const gchar *file;
-
-    fe = (GtkWidget *)g_object_get_data (G_OBJECT (dlg), "filename");
-
-    file = gtk_file_selection_get_filename (GTK_FILE_SELECTION (fs));
-    gchar * utf8file = g_filename_to_utf8( file, -1, NULL, NULL, NULL );
-    gtk_entry_set_text (GTK_ENTRY (fe), utf8file);
-    g_free(utf8file);
-
-    g_object_set_data (G_OBJECT (dlg), "filename", fe);
-
-    return;
-} // end of sp_export_browse_store()
-
 // TODO: Move this to nr-rect-fns.h.
 static bool
 sp_export_bbox_equal(NR::Rect const &one, NR::Rect const &two)
@@ -1247,8 +1282,8 @@ sp_export_detect_size(GtkObject * base) {
         // std::cout << "Looking at: " << selection_names[this_test[i]] << std::endl;
         switch (this_test[i]) {
             case SELECTION_SELECTION:
-                if ((SP_DT_SELECTION(SP_ACTIVE_DESKTOP))->isEmpty() == false) {
-                    NR::Rect bbox = (SP_DT_SELECTION (SP_ACTIVE_DESKTOP))->bounds();
+                if ((sp_desktop_selection(SP_ACTIVE_DESKTOP))->isEmpty() == false) {
+                    NR::Rect bbox = (sp_desktop_selection (SP_ACTIVE_DESKTOP))->bounds();
 
                     //std::cout << "Selection " << bbox;
                     if (sp_export_bbox_equal(bbox,current_bbox)) {
@@ -1257,7 +1292,7 @@ sp_export_detect_size(GtkObject * base) {
                 }
                 break;
             case SELECTION_DRAWING: {
-                SPDocument *doc = SP_DT_DOCUMENT (SP_ACTIVE_DESKTOP);
+                SPDocument *doc = sp_desktop_document (SP_ACTIVE_DESKTOP);
 
                 NR::Rect bbox = sp_item_bbox_desktop (SP_ITEM (SP_DOCUMENT_ROOT (doc)));
 
@@ -1271,7 +1306,7 @@ sp_export_detect_size(GtkObject * base) {
             case SELECTION_PAGE: {
                 SPDocument *doc;
 
-                doc = SP_DT_DOCUMENT (SP_ACTIVE_DESKTOP);
+                doc = sp_desktop_document (SP_ACTIVE_DESKTOP);
 
                 NR::Point x(0.0, 0.0);
                 NR::Point y(sp_document_width(doc),
@@ -1495,6 +1530,29 @@ sp_export_set_image_y (GtkObject *base)
     return;
 } // end of sp_export_set_image_y()
 
+/**
+    \brief  A function to set the xdpi
+    \param  base  The export dialog
+
+    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.
+*/
+static void
+sp_export_set_image_x (GtkObject *base)
+{
+    float x0, x1, xdpi;
+
+    x0 = sp_export_value_get_px (base, "x0");
+    x1 = sp_export_value_get_px (base, "x1");
+    xdpi = sp_export_value_get (base, "xdpi");
+
+    sp_export_value_set (base, "ydpi", xdpi);
+    sp_export_value_set (base, "bmwidth", (x1 - x0) * xdpi / DPI_BASE);
+
+    return;
+} // end of sp_export_set_image_x()
+
 /// Called when pixel width is changed
 static void
 sp_export_bitmap_width_value_changed (GtkAdjustment *adj, GtkObject *base)
@@ -1530,6 +1588,41 @@ sp_export_bitmap_width_value_changed (GtkAdjustment *adj, GtkObject *base)
     return;
 } // end of sp_export_bitmap_width_value_changed()
 
+/// Called when pixel height is changed
+static void
+sp_export_bitmap_height_value_changed (GtkAdjustment *adj, GtkObject *base)
+{
+    float y0, y1, bmheight, xdpi;
+
+    if (gtk_object_get_data (base, "update"))
+        return;
+
+    if (sp_unit_selector_update_test ((SPUnitSelector *)gtk_object_get_data
+           (base, "units"))) {
+       return;
+    }
+
+    gtk_object_set_data (base, "update", GUINT_TO_POINTER (TRUE));
+
+    y0 = sp_export_value_get_px (base, "y0");
+    y1 = sp_export_value_get_px (base, "y1");
+    bmheight = sp_export_value_get (base, "bmheight");
+
+    if (bmheight < SP_EXPORT_MIN_SIZE) {
+        bmheight = SP_EXPORT_MIN_SIZE;
+        sp_export_value_set (base, "bmheight", bmheight);
+    }
+
+    xdpi = bmheight * DPI_BASE / (y1 - y0);
+    sp_export_value_set (base, "xdpi", xdpi);
+
+    sp_export_set_image_x (base);
+
+    gtk_object_set_data (base, "update", GUINT_TO_POINTER (FALSE));
+
+    return;
+} // end of sp_export_bitmap_width_value_changed()
+
 /**
     \brief  A function to adjust the bitmap width when the xdpi value changes
     \param  adj  The adjustment that was changed
@@ -1694,7 +1787,7 @@ sp_export_value_get ( GtkObject *base, const gchar *key )
     adj = (GtkAdjustment *)gtk_object_get_data (base, key);
 
     return adj->value;
-} // end of sp_export_value_get()
+}
 
 /**
     \brief  Grabs a value in the export dialog and converts the unit