Code

SPDocument->Document
[inkscape.git] / src / dialogs / export.cpp
index cce57486d7813cc3e1a69c1561a190cfd2e10dc4..56d50596ce57b9835fcc34a242676eb01cbcb86d 100644 (file)
@@ -16,6 +16,9 @@
 # include "config.h"
 #endif
 
+// This has to be included prior to anything that includes setjmp.h, it croaks otherwise
+#include <png.h>
+
 #include <gtk/gtk.h>
 #include <gtkmm/box.h>
 #include <gtkmm/buttonbox.h>
 #include "io/sys.h"
 
 #include "helper/png-write.h"
-#include <png.h>
 
+#ifdef WIN32
+#include <windows.h>
+#include <COMMDLG.h>
+#include <gdk/gdkwin32.h>
+#endif
 
 #define SP_EXPORT_MIN_SIZE 1.0
 
@@ -165,7 +172,7 @@ sp_export_dialog_delete ( GtkObject */*object*/, GdkEvent */*event*/, gpointer /
 
     if (x<0) x=0;
     if (y<0) y=0;
-    
+
     Inkscape::Preferences *prefs = Inkscape::Preferences::get();
     prefs->setInt(prefs_path + "x", x);
     prefs->setInt(prefs_path + "y", y);
@@ -204,13 +211,13 @@ sp_export_spinbutton_new ( gchar const *key, float val, float min, float max,
                            int digits, unsigned int sensitive,
                            GCallback cb, GtkWidget *dlg )
 {
-    GtkObject *a = gtk_adjustment_new (val, min, max, step, page, page);
-    gtk_object_set_data (a, "key", const_cast<gchar *>(key));
-    gtk_object_set_data (GTK_OBJECT (dlg), (const gchar *)key, a);
+    GtkObject *adj = gtk_adjustment_new( val, min, max, step, page, 0 );
+    gtk_object_set_data( adj, "key", const_cast<gchar *>(key) );
+    gtk_object_set_data( GTK_OBJECT (dlg), (const gchar *)key, adj );
 
     if (us) {
         sp_unit_selector_add_adjustment ( SP_UNIT_SELECTOR (us),
-                                          GTK_ADJUSTMENT (a) );
+                                          GTK_ADJUSTMENT (adj) );
     }
 
     int pos = 0;
@@ -228,7 +235,7 @@ sp_export_spinbutton_new ( gchar const *key, float val, float min, float max,
 
     }
 
-    GtkWidget *sb = gtk_spin_button_new (GTK_ADJUSTMENT (a), 1.0, digits);
+    GtkWidget *sb = gtk_spin_button_new (GTK_ADJUSTMENT (adj), 1.0, digits);
     gtk_table_attach ( GTK_TABLE (t), sb, x + pos, x + pos + 1, y, y + 1,
                        (GtkAttachOptions)0, (GtkAttachOptions)0, 0, 0 );
     gtk_widget_set_size_request (sb, 80, -1);
@@ -250,7 +257,7 @@ sp_export_spinbutton_new ( gchar const *key, float val, float min, float max,
     }
 
     if (cb)
-        gtk_signal_connect (a, "value_changed", cb, dlg);
+        gtk_signal_connect (adj, "value_changed", cb, dlg);
 
     return;
 } // end of sp_export_spinbutton_new()
@@ -531,7 +538,7 @@ sp_export_dialog (void)
             if (SP_ACTIVE_DOCUMENT && SP_DOCUMENT_URI (SP_ACTIVE_DOCUMENT))
             {
                 gchar *name;
-                SPDocument * doc = SP_ACTIVE_DOCUMENT;
+                Document * 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");
@@ -622,7 +629,7 @@ sp_export_dialog (void)
 
         {
             Gtk::HBox* hide_box = new Gtk::HBox(FALSE, 5);
-            GtkWidget *he = gtk_check_button_new_with_label(_("Hide _all except selected"));
+            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);
@@ -772,7 +779,7 @@ sp_export_selection_modified ( Inkscape::Application */*inkscape*/,
     switch (current_key) {
         case SELECTION_DRAWING:
             if ( SP_ACTIVE_DESKTOP ) {
-                SPDocument *doc;
+                Document *doc;
                 doc = sp_desktop_document (SP_ACTIVE_DESKTOP);
                 Geom::OptRect bbox = sp_item_bbox_desktop (SP_ITEM (SP_DOCUMENT_ROOT (doc)));
                 if (bbox) {
@@ -832,7 +839,7 @@ sp_export_area_toggled (GtkToggleButton *tb, GtkObject *base)
 
     if ( SP_ACTIVE_DESKTOP )
     {
-        SPDocument *doc;
+        Document *doc;
         Geom::OptRect bbox;
         doc = sp_desktop_document (SP_ACTIVE_DESKTOP);
 
@@ -899,7 +906,7 @@ sp_export_area_toggled (GtkToggleButton *tb, GtkObject *base)
         switch (key) {
             case SELECTION_PAGE:
             case SELECTION_DRAWING: {
-                SPDocument * doc = SP_ACTIVE_DOCUMENT;
+                Document * doc = SP_ACTIVE_DOCUMENT;
                 sp_document_get_export_hints (doc, &filename, &xdpi, &ydpi);
 
                 if (filename == NULL) {
@@ -1034,7 +1041,7 @@ create_progress_dialog (GtkObject *base, gchar *progress_text) {
 static gchar *
 filename_add_extension (const gchar *filename, const gchar *extension)
 {
-  gchar *dot;
+  const gchar *dot;
 
   dot = strrchr (filename, '.');
   if ( !dot )
@@ -1206,7 +1213,7 @@ sp_export_export_clicked (GtkButton */*button*/, GtkObject *base)
     switch ((selection_type)(GPOINTER_TO_INT(gtk_object_get_data(GTK_OBJECT(base), "selection-type")))) {
         case SELECTION_PAGE:
         case SELECTION_DRAWING: {
-            SPDocument * doc = SP_ACTIVE_DOCUMENT;
+            Document * doc = SP_ACTIVE_DOCUMENT;
             Inkscape::XML::Node * repr = sp_document_repr_root(doc);
             bool modified = false;
             const gchar * temp_string;
@@ -1238,7 +1245,7 @@ sp_export_export_clicked (GtkButton */*button*/, GtkObject *base)
         }
         case SELECTION_SELECTION: {
             const GSList * reprlst;
-            SPDocument * doc = SP_ACTIVE_DOCUMENT;
+            Document * doc = SP_ACTIVE_DOCUMENT;
             bool modified = false;
 
             bool saved = sp_document_get_undo_sensitive(doc);
@@ -1288,6 +1295,7 @@ sp_export_export_clicked (GtkButton */*button*/, GtkObject *base)
 } // end of sp_export_export_clicked()
 
 /// Called when Browse button is clicked
+/// @todo refactor this code to use ui/dialogs/filedialog.cpp
 static void
 sp_export_browse_clicked (GtkButton */*button*/, gpointer /*userdata*/)
 {
@@ -1316,11 +1324,55 @@ sp_export_browse_clicked (GtkButton */*button*/, gpointer /*userdata*/)
     filename = gtk_entry_get_text (GTK_ENTRY (fe));
 
     if (*filename == '\0') {
-        filename = homedir_path(NULL);
+        filename = create_filepath_from_id(NULL, NULL);
     }
 
     gtk_file_chooser_set_filename (GTK_FILE_CHOOSER (fs), filename);
 
+#ifdef WIN32
+       // code in this section is borrowed from ui/dialogs/filedialogimpl-win32.cpp
+       OPENFILENAMEW opf;
+       WCHAR* filter_string = (WCHAR*)g_utf8_to_utf16("PNG\0*.png\0\0", 12, NULL, NULL, NULL);
+       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
+       WCHAR _filename[_MAX_PATH + 1];
+    memset(_filename, 0, sizeof(_filename));
+    gunichar2* utf16_path_string = g_utf8_to_utf16(filename, -1, NULL, NULL, NULL);
+    wcsncpy(_filename, (wchar_t*)utf16_path_string, _MAX_PATH);
+    g_free(utf16_path_string);
+
+       opf.hwndOwner = (HWND)(GDK_WINDOW_HWND(GTK_WIDGET(dlg)->window));
+       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);
+               gtk_entry_set_text (GTK_ENTRY (fe), utf8string);
+        g_object_set_data (G_OBJECT (dlg), "filename", fe);
+               g_free(utf8string);
+
+       }
+       g_free(extension_string);
+       g_free(title_string);
+       g_free(filter_string);
+#else
     if (gtk_dialog_run (GTK_DIALOG (fs)) == GTK_RESPONSE_ACCEPT)
     {
         gchar *file;
@@ -1335,6 +1387,7 @@ sp_export_browse_clicked (GtkButton */*button*/, gpointer /*userdata*/)
         g_free(utf8file);
         g_free(file);
     }
+#endif
 
     gtk_widget_destroy (fs);
 
@@ -1413,7 +1466,7 @@ sp_export_detect_size(GtkObject * base) {
                 }
                 break;
             case SELECTION_DRAWING: {
-                SPDocument *doc = sp_desktop_document (SP_ACTIVE_DESKTOP);
+                Document *doc = sp_desktop_document (SP_ACTIVE_DESKTOP);
 
                 Geom::OptRect bbox = sp_item_bbox_desktop (SP_ITEM (SP_DOCUMENT_ROOT (doc)));
 
@@ -1425,7 +1478,7 @@ sp_export_detect_size(GtkObject * base) {
             }
 
             case SELECTION_PAGE: {
-                SPDocument *doc;
+                Document *doc;
 
                 doc = sp_desktop_document (SP_ACTIVE_DESKTOP);