summary | shortlog | log | commit | commitdiff | tree
raw | patch | inline | side by side (parent: 8c1f342)
raw | patch | inline | side by side (parent: 8c1f342)
author | pjrm <pjrm@users.sourceforge.net> | |
Thu, 11 Oct 2007 14:28:57 +0000 (14:28 +0000) | ||
committer | pjrm <pjrm@users.sourceforge.net> | |
Thu, 11 Oct 2007 14:28:57 +0000 (14:28 +0000) |
index 0550b802192f71919e7bc36a5322388a1d8d8ba0..6ad7179383abfd59df45d4311be59953a7c42b26 100644 (file)
-/**\r
- * Implementation of the file dialog interfaces defined in filedialogimpl.h\r
- *\r
- * Authors:\r
- * Bob Jamison\r
- * Joel Holdsworth\r
- * Bruno Dilly\r
- * Other dudes from The Inkscape Organization\r
- *\r
- * Copyright (C) 2004-2007 Bob Jamison\r
- * Copyright (C) 2006 Johan Engelen <johan@shouraizou.nl>\r
- * Copyright (C) 2004-2007 The Inkscape Organization\r
- * Copyright (C) 2007 Joel Holdsworth\r
- *\r
- * Released under GNU GPL, read the file 'COPYING' for more information\r
- */\r
-\r
-#ifdef HAVE_CONFIG_H\r
-# include <config.h>\r
-#endif\r
-\r
-#include "filedialogimpl-gtkmm.h"\r
-#include "dialogs/dialog-events.h"\r
-#include "interface.h"\r
-#include "io/sys.h"\r
-#include "path-prefix.h"\r
-\r
-#ifdef WITH_GNOME_VFS\r
-# include <libgnomevfs/gnome-vfs.h>\r
-#endif\r
-\r
-//Routines from file.cpp\r
-#undef INK_DUMP_FILENAME_CONV\r
-\r
-#ifdef INK_DUMP_FILENAME_CONV\r
-void dump_str( const gchar* str, const gchar* prefix );\r
-void dump_ustr( const Glib::ustring& ustr );\r
-#endif\r
-\r
-\r
-\r
-namespace Inkscape\r
-{\r
-namespace UI\r
-{\r
-namespace Dialog\r
-{\r
-\r
-\r
-\r
-\r
-\r
-//########################################################################\r
-//### U T I L I T Y\r
-//########################################################################\r
-\r
-void\r
-fileDialogExtensionToPattern(Glib::ustring &pattern,\r
- Glib::ustring &extension)\r
-{\r
- for (unsigned int i = 0; i < extension.length(); i++ )\r
- {\r
- Glib::ustring::value_type ch = extension[i];\r
- if ( Glib::Unicode::isalpha(ch) )\r
- {\r
- pattern += '[';\r
- pattern += Glib::Unicode::toupper(ch);\r
- pattern += Glib::Unicode::tolower(ch);\r
- pattern += ']';\r
- }\r
- else\r
- {\r
- pattern += ch;\r
- }\r
- }\r
-}\r
-\r
-\r
-void\r
-findEntryWidgets(Gtk::Container *parent,\r
- std::vector<Gtk::Entry *> &result)\r
-{\r
- if (!parent)\r
- return;\r
- std::vector<Gtk::Widget *> children = parent->get_children();\r
- for (unsigned int i=0; i<children.size() ; i++)\r
- {\r
- Gtk::Widget *child = children[i];\r
- GtkWidget *wid = child->gobj();\r
- if (GTK_IS_ENTRY(wid))\r
- result.push_back((Gtk::Entry *)child);\r
- else if (GTK_IS_CONTAINER(wid))\r
- findEntryWidgets((Gtk::Container *)child, result);\r
- }\r
-\r
-}\r
-\r
-void\r
-findExpanderWidgets(Gtk::Container *parent,\r
- std::vector<Gtk::Expander *> &result)\r
-{\r
- if (!parent)\r
- return;\r
- std::vector<Gtk::Widget *> children = parent->get_children();\r
- for (unsigned int i=0; i<children.size() ; i++)\r
- {\r
- Gtk::Widget *child = children[i];\r
- GtkWidget *wid = child->gobj();\r
- if (GTK_IS_EXPANDER(wid))\r
- result.push_back((Gtk::Expander *)child);\r
- else if (GTK_IS_CONTAINER(wid))\r
- findExpanderWidgets((Gtk::Container *)child, result);\r
- }\r
-\r
-}\r
-\r
-\r
-/*#########################################################################\r
-### SVG Preview Widget\r
-#########################################################################*/\r
-\r
-bool SVGPreview::setDocument(SPDocument *doc)\r
-{\r
- if (document)\r
- sp_document_unref(document);\r
-\r
- sp_document_ref(doc);\r
- document = doc;\r
-\r
- //This should remove it from the box, and free resources\r
- if (viewerGtk)\r
- gtk_widget_destroy(viewerGtk);\r
-\r
- viewerGtk = sp_svg_view_widget_new(doc);\r
- GtkWidget *vbox = (GtkWidget *)gobj();\r
- gtk_box_pack_start(GTK_BOX(vbox), viewerGtk, TRUE, TRUE, 0);\r
- gtk_widget_show(viewerGtk);\r
-\r
- return true;\r
-}\r
-\r
-\r
-bool SVGPreview::setFileName(Glib::ustring &theFileName)\r
-{\r
- Glib::ustring fileName = theFileName;\r
-\r
- fileName = Glib::filename_to_utf8(fileName);\r
-\r
- /**\r
- * I don't know why passing false to keepalive is bad. But it\r
- * prevents the display of an svg with a non-ascii filename\r
- */\r
- SPDocument *doc = sp_document_new (fileName.c_str(), true);\r
- if (!doc) {\r
- g_warning("SVGView: error loading document '%s'\n", fileName.c_str());\r
- return false;\r
- }\r
-\r
- setDocument(doc);\r
-\r
- sp_document_unref(doc);\r
-\r
- return true;\r
-}\r
-\r
-\r
-\r
-bool SVGPreview::setFromMem(char const *xmlBuffer)\r
-{\r
- if (!xmlBuffer)\r
- return false;\r
-\r
- gint len = (gint)strlen(xmlBuffer);\r
- SPDocument *doc = sp_document_new_from_mem(xmlBuffer, len, 0);\r
- if (!doc) {\r
- g_warning("SVGView: error loading buffer '%s'\n",xmlBuffer);\r
- return false;\r
- }\r
-\r
- setDocument(doc);\r
-\r
- sp_document_unref(doc);\r
-\r
- Inkscape::GC::request_early_collection();\r
-\r
- return true;\r
-}\r
-\r
-\r
-\r
-void SVGPreview::showImage(Glib::ustring &theFileName)\r
-{\r
- Glib::ustring fileName = theFileName;\r
-\r
-\r
- /*#####################################\r
- # LET'S HAVE SOME FUN WITH SVG!\r
- # Instead of just loading an image, why\r
- # don't we make a lovely little svg and\r
- # display it nicely?\r
- #####################################*/\r
-\r
- //Arbitrary size of svg doc -- rather 'portrait' shaped\r
- gint previewWidth = 400;\r
- gint previewHeight = 600;\r
-\r
- //Get some image info. Smart pointer does not need to be deleted\r
- Glib::RefPtr<Gdk::Pixbuf> img = Gdk::Pixbuf::create_from_file(fileName);\r
- gint imgWidth = img->get_width();\r
- gint imgHeight = img->get_height();\r
-\r
- //Find the minimum scale to fit the image inside the preview area\r
- double scaleFactorX = (0.9 *(double)previewWidth) / ((double)imgWidth);\r
- double scaleFactorY = (0.9 *(double)previewHeight) / ((double)imgHeight);\r
- double scaleFactor = scaleFactorX;\r
- if (scaleFactorX > scaleFactorY)\r
- scaleFactor = scaleFactorY;\r
-\r
- //Now get the resized values\r
- gint scaledImgWidth = (int) (scaleFactor * (double)imgWidth);\r
- gint scaledImgHeight = (int) (scaleFactor * (double)imgHeight);\r
-\r
- //center the image on the area\r
- gint imgX = (previewWidth - scaledImgWidth) / 2;\r
- gint imgY = (previewHeight - scaledImgHeight) / 2;\r
-\r
- //wrap a rectangle around the image\r
- gint rectX = imgX-1;\r
- gint rectY = imgY-1;\r
- gint rectWidth = scaledImgWidth +2;\r
- gint rectHeight = scaledImgHeight+2;\r
-\r
- //Our template. Modify to taste\r
- gchar const *xformat =\r
- "<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n"\r
- "<svg\n"\r
- "xmlns=\"http://www.w3.org/2000/svg\"\n"\r
- "xmlns:xlink=\"http://www.w3.org/1999/xlink\"\n"\r
- "width=\"%d\" height=\"%d\">\n" //# VALUES HERE\r
- "<rect\n"\r
- " style=\"fill:#eeeeee;stroke:none\"\n"\r
- " x=\"-100\" y=\"-100\" width=\"4000\" height=\"4000\"/>\n"\r
- "<image x=\"%d\" y=\"%d\" width=\"%d\" height=\"%d\"\n"\r
- "xlink:href=\"%s\"/>\n"\r
- "<rect\n"\r
- " style=\"fill:none;"\r
- " stroke:#000000;stroke-width:1.0;"\r
- " stroke-linejoin:miter;stroke-opacity:1.0000000;"\r
- " stroke-miterlimit:4.0000000;stroke-dasharray:none\"\n"\r
- " x=\"%d\" y=\"%d\" width=\"%d\" height=\"%d\"/>\n"\r
- "<text\n"\r
- " style=\"font-size:24.000000;font-style:normal;font-weight:normal;"\r
- " fill:#000000;fill-opacity:1.0000000;stroke:none;"\r
- " font-family:Bitstream Vera Sans\"\n"\r
- " x=\"10\" y=\"26\">%d x %d</text>\n" //# VALUES HERE\r
- "</svg>\n\n";\r
-\r
- //if (!Glib::get_charset()) //If we are not utf8\r
- fileName = Glib::filename_to_utf8(fileName);\r
-\r
- //Fill in the template\r
- /* FIXME: Do proper XML quoting for fileName. */\r
- gchar *xmlBuffer = g_strdup_printf(xformat,\r
- previewWidth, previewHeight,\r
- imgX, imgY, scaledImgWidth, scaledImgHeight,\r
- fileName.c_str(),\r
- rectX, rectY, rectWidth, rectHeight,\r
- imgWidth, imgHeight);\r
-\r
- //g_message("%s\n", xmlBuffer);\r
-\r
- //now show it!\r
- setFromMem(xmlBuffer);\r
- g_free(xmlBuffer);\r
-}\r
-\r
-\r
-\r
-void SVGPreview::showNoPreview()\r
-{\r
- //Are we already showing it?\r
- if (showingNoPreview)\r
- return;\r
-\r
- //Arbitrary size of svg doc -- rather 'portrait' shaped\r
- gint previewWidth = 300;\r
- gint previewHeight = 600;\r
-\r
- //Our template. Modify to taste\r
- gchar const *xformat =\r
- "<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n"\r
- "<svg\n"\r
- "xmlns=\"http://www.w3.org/2000/svg\"\n"\r
- "xmlns:xlink=\"http://www.w3.org/1999/xlink\"\n"\r
- "width=\"%d\" height=\"%d\">\n" //# VALUES HERE\r
- "<g transform=\"translate(-190,24.27184)\" style=\"opacity:0.12\">\n"\r
- "<path\n"\r
- "style=\"font-size:12;fill:#ffffff;fill-rule:evenodd;stroke:#000000;stroke-width:0.936193pt\"\n"\r
- "d=\"M 397.64309 320.25301 L 280.39197 282.517 L 250.74227 124.83447 L 345.08225 "\r
- "29.146783 L 393.59996 46.667064 L 483.89679 135.61619 L 397.64309 320.25301 z \"\n"\r
- "id=\"whiteSpace\" />\n"\r
- "<path\n"\r
- "style=\"font-size:12;fill-rule:evenodd;stroke-width:1pt;fill:#000000;fill-opacity:1\"\n"\r
- "d=\"M 476.95792 339.17168 C 495.78197 342.93607 499.54842 356.11361 495.78197 359.87802 "\r
- "C 492.01856 363.6434 482.6065 367.40781 475.07663 361.76014 C 467.54478 "\r
- "356.11361 467.54478 342.93607 476.95792 339.17168 z \"\n"\r
- "id=\"droplet01\" />\n"\r
- "<path\n"\r
- "style=\"font-size:12;fill-rule:evenodd;stroke-width:1pt;fill:#000000;fill-opacity:1\"\n"\r
- "d=\"M 286.46194 340.42914 C 284.6277 340.91835 269.30405 327.71337 257.16909 333.8338 "\r
- "C 245.03722 339.95336 236.89276 353.65666 248.22676 359.27982 C 259.56184 364.90298 "\r
- "267.66433 358.41867 277.60113 351.44119 C 287.53903 344.46477 "\r
- "287.18046 343.1206 286.46194 340.42914 z \"\n"\r
- "id=\"droplet02\" />\n"\r
- "<path\n"\r
- "style=\"font-size:12;fill-rule:evenodd;stroke-width:1pt;fill:#000000;fill-opacity:1\"\n"\r
- "d=\"M 510.35756 306.92856 C 520.59494 304.36879 544.24333 306.92856 540.47688 321.98634 "\r
- "C 536.71354 337.04806 504.71297 331.39827 484.00371 323.87156 C 482.12141 "\r
- "308.81083 505.53237 308.13423 510.35756 306.92856 z \"\n"\r
- "id=\"droplet03\" />\n"\r
- "<path\n"\r
- "style=\"font-size:12;fill-rule:evenodd;stroke-width:1pt;fill:#000000;fill-opacity:1\"\n"\r
- "d=\"M 359.2403 21.362537 C 347.92693 21.362537 336.6347 25.683095 327.96556 34.35223 "\r
- "L 173.87387 188.41466 C 165.37697 196.9114 161.1116 207.95813 160.94269 219.04577 "\r
- "L 160.88418 219.04577 C 160.88418 219.08524 160.94076 219.12322 160.94269 219.16279 "\r
- "C 160.94033 219.34888 160.88418 219.53256 160.88418 219.71865 L 161.14748 219.71865 "\r
- "C 164.0966 230.93917 240.29699 245.24198 248.79866 253.74346 C 261.63771 266.58263 "\r
- "199.5652 276.01151 212.4041 288.85074 C 225.24316 301.68979 289.99433 313.6933 302.8346 "\r
- "326.53254 C 315.67368 339.37161 276.5961 353.04289 289.43532 365.88196 C 302.27439 "\r
- "378.72118 345.40201 362.67257 337.5908 396.16198 C 354.92909 413.50026 391.10302 "\r
- "405.2208 415.32417 387.88252 C 428.16323 375.04345 390.6948 376.17577 403.53397 "\r
- "363.33668 C 416.37304 350.49745 448.78128 350.4282 476.08902 319.71589 C 465.09739 "\r
- "302.62116 429.10801 295.34136 441.94719 282.50217 C 454.78625 269.66311 479.74708 "\r
- "276.18423 533.60644 251.72479 C 559.89837 239.78398 557.72636 230.71459 557.62567 "\r
- "219.71865 C 557.62356 219.48727 557.62567 219.27892 557.62567 219.04577 L 557.56716 "\r
- "219.04577 C 557.3983 207.95812 553.10345 196.9114 544.60673 188.41466 L 390.54428 "\r
- "34.35223 C 381.87515 25.683095 370.55366 21.362537 359.2403 21.362537 z M 357.92378 "\r
- "41.402939 C 362.95327 41.533963 367.01541 45.368018 374.98006 50.530832 L 447.76915 "\r
- "104.50827 C 448.56596 105.02498 449.32484 105.564 450.02187 106.11735 C 450.7189 106.67062 "\r
- "451.3556 107.25745 451.95277 107.84347 C 452.54997 108.42842 453.09281 109.01553 453.59111 "\r
- "109.62808 C 454.08837 110.24052 454.53956 110.86661 454.93688 111.50048 C 455.33532 112.13538 "\r
- "455.69164 112.78029 455.9901 113.43137 C 456.28877 114.08363 456.52291 114.75639 456.7215 "\r
- "115.42078 C 456.92126 116.08419 457.08982 116.73973 457.18961 117.41019 C 457.28949 "\r
- "118.08184 457.33588 118.75535 457.33588 119.42886 L 414.21245 98.598549 L 409.9118 "\r
- "131.16055 L 386.18512 120.04324 L 349.55654 144.50131 L 335.54288 96.1703 L 317.4919 "\r
- "138.4453 L 267.08369 143.47735 L 267.63956 121.03795 C 267.63956 115.64823 296.69685 "\r
- "77.915899 314.39075 68.932902 L 346.77721 45.674327 C 351.55594 42.576634 354.90608 "\r
- "41.324327 357.92378 41.402939 z M 290.92738 261.61333 C 313.87149 267.56365 339.40299 "\r
- "275.37038 359.88393 275.50997 L 360.76161 284.72563 C 343.2235 282.91785 306.11346 "\r
- "274.45012 297.36372 269.98057 L 290.92738 261.61333 z \"\n"\r
- "id=\"mountainDroplet\" />\n"\r
- "</g> <g transform=\"translate(-20,0)\">\n"\r
- "<text xml:space=\"preserve\"\n"\r
- "style=\"font-size:32.000000;font-style:normal;font-variant:normal;font-weight:bold;"\r
- "font-stretch:normal;fill:#000000;fill-opacity:1.0000000;stroke:none;stroke-width:1.0000000pt;"\r
- "stroke-linecap:butt;stroke-linejoin:miter;stroke-opacity:1.0000000;"\r
- "font-family:Bitstream Vera Sans;text-anchor:middle;writing-mode:lr\"\n"\r
- "x=\"190\" y=\"240\">%s</text></g>\n" //# VALUE HERE\r
- "</svg>\n\n";\r
-\r
- //Fill in the template\r
- gchar *xmlBuffer = g_strdup_printf(xformat,\r
- previewWidth, previewHeight, _("No preview"));\r
-\r
- //g_message("%s\n", xmlBuffer);\r
-\r
- //now show it!\r
- setFromMem(xmlBuffer);\r
- g_free(xmlBuffer);\r
- showingNoPreview = true;\r
-\r
-}\r
-\r
-\r
-/**\r
- * Inform the user that the svg file is too large to be displayed.\r
- * This does not check for sizes of embedded images (yet)\r
- */\r
-void SVGPreview::showTooLarge(long fileLength)\r
-{\r
-\r
- //Arbitrary size of svg doc -- rather 'portrait' shaped\r
- gint previewWidth = 300;\r
- gint previewHeight = 600;\r
-\r
- //Our template. Modify to taste\r
- gchar const *xformat =\r
- "<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n"\r
- "<svg\n"\r
- "xmlns=\"http://www.w3.org/2000/svg\"\n"\r
- "xmlns:xlink=\"http://www.w3.org/1999/xlink\"\n"\r
- "width=\"%d\" height=\"%d\">\n" //# VALUES HERE\r
- "<g transform=\"translate(-170,24.27184)\" style=\"opacity:0.12\">\n"\r
- "<path\n"\r
- "style=\"font-size:12;fill:#ffffff;fill-rule:evenodd;stroke:#000000;stroke-width:0.936193pt\"\n"\r
- "d=\"M 397.64309 320.25301 L 280.39197 282.517 L 250.74227 124.83447 L 345.08225 "\r
- "29.146783 L 393.59996 46.667064 L 483.89679 135.61619 L 397.64309 320.25301 z \"\n"\r
- "id=\"whiteSpace\" />\n"\r
- "<path\n"\r
- "style=\"font-size:12;fill-rule:evenodd;stroke-width:1pt;fill:#000000;fill-opacity:1\"\n"\r
- "d=\"M 476.95792 339.17168 C 495.78197 342.93607 499.54842 356.11361 495.78197 359.87802 "\r
- "C 492.01856 363.6434 482.6065 367.40781 475.07663 361.76014 C 467.54478 "\r
- "356.11361 467.54478 342.93607 476.95792 339.17168 z \"\n"\r
- "id=\"droplet01\" />\n"\r
- "<path\n"\r
- "style=\"font-size:12;fill-rule:evenodd;stroke-width:1pt;fill:#000000;fill-opacity:1\"\n"\r
- "d=\"M 286.46194 340.42914 C 284.6277 340.91835 269.30405 327.71337 257.16909 333.8338 "\r
- "C 245.03722 339.95336 236.89276 353.65666 248.22676 359.27982 C 259.56184 364.90298 "\r
- "267.66433 358.41867 277.60113 351.44119 C 287.53903 344.46477 "\r
- "287.18046 343.1206 286.46194 340.42914 z \"\n"\r
- "id=\"droplet02\" />\n"\r
- "<path\n"\r
- "style=\"font-size:12;fill-rule:evenodd;stroke-width:1pt;fill:#000000;fill-opacity:1\"\n"\r
- "d=\"M 510.35756 306.92856 C 520.59494 304.36879 544.24333 306.92856 540.47688 321.98634 "\r
- "C 536.71354 337.04806 504.71297 331.39827 484.00371 323.87156 C 482.12141 "\r
- "308.81083 505.53237 308.13423 510.35756 306.92856 z \"\n"\r
- "id=\"droplet03\" />\n"\r
- "<path\n"\r
- "style=\"font-size:12;fill-rule:evenodd;stroke-width:1pt;fill:#000000;fill-opacity:1\"\n"\r
- "d=\"M 359.2403 21.362537 C 347.92693 21.362537 336.6347 25.683095 327.96556 34.35223 "\r
- "L 173.87387 188.41466 C 165.37697 196.9114 161.1116 207.95813 160.94269 219.04577 "\r
- "L 160.88418 219.04577 C 160.88418 219.08524 160.94076 219.12322 160.94269 219.16279 "\r
- "C 160.94033 219.34888 160.88418 219.53256 160.88418 219.71865 L 161.14748 219.71865 "\r
- "C 164.0966 230.93917 240.29699 245.24198 248.79866 253.74346 C 261.63771 266.58263 "\r
- "199.5652 276.01151 212.4041 288.85074 C 225.24316 301.68979 289.99433 313.6933 302.8346 "\r
- "326.53254 C 315.67368 339.37161 276.5961 353.04289 289.43532 365.88196 C 302.27439 "\r
- "378.72118 345.40201 362.67257 337.5908 396.16198 C 354.92909 413.50026 391.10302 "\r
- "405.2208 415.32417 387.88252 C 428.16323 375.04345 390.6948 376.17577 403.53397 "\r
- "363.33668 C 416.37304 350.49745 448.78128 350.4282 476.08902 319.71589 C 465.09739 "\r
- "302.62116 429.10801 295.34136 441.94719 282.50217 C 454.78625 269.66311 479.74708 "\r
- "276.18423 533.60644 251.72479 C 559.89837 239.78398 557.72636 230.71459 557.62567 "\r
- "219.71865 C 557.62356 219.48727 557.62567 219.27892 557.62567 219.04577 L 557.56716 "\r
- "219.04577 C 557.3983 207.95812 553.10345 196.9114 544.60673 188.41466 L 390.54428 "\r
- "34.35223 C 381.87515 25.683095 370.55366 21.362537 359.2403 21.362537 z M 357.92378 "\r
- "41.402939 C 362.95327 41.533963 367.01541 45.368018 374.98006 50.530832 L 447.76915 "\r
- "104.50827 C 448.56596 105.02498 449.32484 105.564 450.02187 106.11735 C 450.7189 106.67062 "\r
- "451.3556 107.25745 451.95277 107.84347 C 452.54997 108.42842 453.09281 109.01553 453.59111 "\r
- "109.62808 C 454.08837 110.24052 454.53956 110.86661 454.93688 111.50048 C 455.33532 112.13538 "\r
- "455.69164 112.78029 455.9901 113.43137 C 456.28877 114.08363 456.52291 114.75639 456.7215 "\r
- "115.42078 C 456.92126 116.08419 457.08982 116.73973 457.18961 117.41019 C 457.28949 "\r
- "118.08184 457.33588 118.75535 457.33588 119.42886 L 414.21245 98.598549 L 409.9118 "\r
- "131.16055 L 386.18512 120.04324 L 349.55654 144.50131 L 335.54288 96.1703 L 317.4919 "\r
- "138.4453 L 267.08369 143.47735 L 267.63956 121.03795 C 267.63956 115.64823 296.69685 "\r
- "77.915899 314.39075 68.932902 L 346.77721 45.674327 C 351.55594 42.576634 354.90608 "\r
- "41.324327 357.92378 41.402939 z M 290.92738 261.61333 C 313.87149 267.56365 339.40299 "\r
- "275.37038 359.88393 275.50997 L 360.76161 284.72563 C 343.2235 282.91785 306.11346 "\r
- "274.45012 297.36372 269.98057 L 290.92738 261.61333 z \"\n"\r
- "id=\"mountainDroplet\" />\n"\r
- "</g>\n"\r
- "<text xml:space=\"preserve\"\n"\r
- "style=\"font-size:32.000000;font-style:normal;font-variant:normal;font-weight:bold;"\r
- "font-stretch:normal;fill:#000000;fill-opacity:1.0000000;stroke:none;stroke-width:1.0000000pt;"\r
- "stroke-linecap:butt;stroke-linejoin:miter;stroke-opacity:1.0000000;"\r
- "font-family:Bitstream Vera Sans;text-anchor:middle;writing-mode:lr\"\n"\r
- "x=\"170\" y=\"215\">%5.1f MB</text>\n" //# VALUE HERE\r
- "<text xml:space=\"preserve\"\n"\r
- "style=\"font-size:24.000000;font-style:normal;font-variant:normal;font-weight:bold;"\r
- "font-stretch:normal;fill:#000000;fill-opacity:1.0000000;stroke:none;stroke-width:1.0000000pt;"\r
- "stroke-linecap:butt;stroke-linejoin:miter;stroke-opacity:1.0000000;"\r
- "font-family:Bitstream Vera Sans;text-anchor:middle;writing-mode:lr\"\n"\r
- "x=\"180\" y=\"245\">%s</text>\n" //# VALUE HERE\r
- "</svg>\n\n";\r
-\r
- //Fill in the template\r
- double floatFileLength = ((double)fileLength) / 1048576.0;\r
- //printf("%ld %f\n", fileLength, floatFileLength);\r
- gchar *xmlBuffer = g_strdup_printf(xformat,\r
- previewWidth, previewHeight, floatFileLength,\r
- _("too large for preview"));\r
-\r
- //g_message("%s\n", xmlBuffer);\r
-\r
- //now show it!\r
- setFromMem(xmlBuffer);\r
- g_free(xmlBuffer);\r
-\r
-}\r
-\r
-\r
-/**\r
- * Return true if the string ends with the given suffix\r
- */\r
-static bool\r
-hasSuffix(Glib::ustring &str, Glib::ustring &ext)\r
-{\r
- int strLen = str.length();\r
- int extLen = ext.length();\r
- if (extLen > strLen)\r
- return false;\r
- int strpos = strLen-1;\r
- for (int extpos = extLen-1 ; extpos>=0 ; extpos--, strpos--)\r
- {\r
- Glib::ustring::value_type ch = str[strpos];\r
- if (ch != ext[extpos])\r
- {\r
- if ( ((ch & 0xff80) != 0) ||\r
- static_cast<Glib::ustring::value_type>( g_ascii_tolower( static_cast<gchar>(0x07f & ch) ) ) != ext[extpos] )\r
- {\r
- return false;\r
- }\r
- }\r
- }\r
- return true;\r
-}\r
-\r
-\r
-/**\r
- * Return true if the image is loadable by Gdk, else false\r
- */\r
-static bool\r
-isValidImageFile(Glib::ustring &fileName)\r
-{\r
- std::vector<Gdk::PixbufFormat>formats = Gdk::Pixbuf::get_formats();\r
- for (unsigned int i=0; i<formats.size(); i++)\r
- {\r
- Gdk::PixbufFormat format = formats[i];\r
- std::vector<Glib::ustring>extensions = format.get_extensions();\r
- for (unsigned int j=0; j<extensions.size(); j++)\r
- {\r
- Glib::ustring ext = extensions[j];\r
- if (hasSuffix(fileName, ext))\r
- return true;\r
- }\r
- }\r
- return false;\r
-}\r
-\r
-bool SVGPreview::set(Glib::ustring &fileName, int dialogType)\r
-{\r
-\r
- if (!Glib::file_test(fileName, Glib::FILE_TEST_EXISTS))\r
- return false;\r
-\r
- //g_message("fname:%s", fileName.c_str());\r
-\r
- if (Glib::file_test(fileName, Glib::FILE_TEST_IS_DIR)) {\r
- showNoPreview();\r
- return false;\r
- }\r
-\r
- if (Glib::file_test(fileName, Glib::FILE_TEST_IS_REGULAR))\r
- {\r
- Glib::ustring fileNameUtf8 = Glib::filename_to_utf8(fileName);\r
- gchar *fName = (gchar *)fileNameUtf8.c_str();\r
- struct stat info;\r
- if (g_stat(fName, &info))\r
- {\r
- g_warning("SVGPreview::set() : %s : %s",\r
- fName, strerror(errno));\r
- return FALSE;\r
- }\r
- long fileLen = info.st_size;\r
- if (fileLen > 0x150000L)\r
- {\r
- showingNoPreview = false;\r
- showTooLarge(fileLen);\r
- return FALSE;\r
- }\r
- }\r
-\r
- Glib::ustring svg = ".svg";\r
- Glib::ustring svgz = ".svgz";\r
-\r
- if ((dialogType == SVG_TYPES || dialogType == IMPORT_TYPES) &&\r
- (hasSuffix(fileName, svg) || hasSuffix(fileName, svgz) )\r
- ) {\r
- bool retval = setFileName(fileName);\r
- showingNoPreview = false;\r
- return retval;\r
- } else if (isValidImageFile(fileName)) {\r
- showImage(fileName);\r
- showingNoPreview = false;\r
- return true;\r
- } else {\r
- showNoPreview();\r
- return false;\r
- }\r
-}\r
-\r
-\r
-SVGPreview::SVGPreview()\r
-{\r
- if (!INKSCAPE)\r
- inkscape_application_init("",false);\r
- document = NULL;\r
- viewerGtk = NULL;\r
- set_size_request(150,150);\r
- showingNoPreview = false;\r
-}\r
-\r
-SVGPreview::~SVGPreview()\r
-{\r
-\r
-}\r
-\r
-\r
-/*#########################################################################\r
-### F I L E D I A L O G B A S E C L A S S\r
-#########################################################################*/\r
-\r
-void FileDialogBaseGtk::internalSetup()\r
-{\r
- bool enablePreview =\r
- (bool)prefs_get_int_attribute( preferenceBase.c_str(),\r
- "enable_preview", 1 );\r
-\r
- previewCheckbox.set_label( Glib::ustring(_("Enable preview")) );\r
- previewCheckbox.set_active( enablePreview );\r
-\r
- previewCheckbox.signal_toggled().connect(\r
- sigc::mem_fun(*this, &FileDialogBaseGtk::_previewEnabledCB) );\r
-\r
- //Catch selection-changed events, so we can adjust the text widget\r
- signal_update_preview().connect(\r
- sigc::mem_fun(*this, &FileDialogBaseGtk::_updatePreviewCallback) );\r
-\r
- //###### Add a preview widget\r
- set_preview_widget(svgPreview);\r
- set_preview_widget_active( enablePreview );\r
- set_use_preview_label (false);\r
-\r
-}\r
-\r
-\r
-void FileDialogBaseGtk::cleanup( bool showConfirmed )\r
-{\r
- if ( showConfirmed )\r
- prefs_set_int_attribute( preferenceBase.c_str(),\r
- "enable_preview", previewCheckbox.get_active() );\r
-}\r
-\r
-\r
-void FileDialogBaseGtk::_previewEnabledCB()\r
-{\r
- bool enabled = previewCheckbox.get_active();\r
- set_preview_widget_active(enabled);\r
- if ( enabled ) {\r
- _updatePreviewCallback();\r
- }\r
-}\r
-\r
-\r
-\r
-/**\r
- * Callback for checking if the preview needs to be redrawn\r
- */\r
-void FileDialogBaseGtk::_updatePreviewCallback()\r
-{\r
- Glib::ustring fileName = get_preview_filename();\r
-\r
-#ifdef WITH_GNOME_VFS\r
- if ( fileName.empty() && gnome_vfs_initialized() ) {\r
- fileName = get_preview_uri();\r
- }\r
-#endif\r
-\r
- if (fileName.empty()) {\r
- return;\r
- }\r
-\r
- svgPreview.set(fileName, dialogType);\r
-}\r
-\r
-\r
-/*#########################################################################\r
-### F I L E O P E N\r
-#########################################################################*/\r
-\r
-/**\r
- * Constructor. Not called directly. Use the factory.\r
- */\r
-FileOpenDialogImplGtk::FileOpenDialogImplGtk(Gtk::Window& parentWindow,\r
- const Glib::ustring &dir,\r
- FileDialogType fileTypes,\r
- const Glib::ustring &title) :\r
- FileDialogBaseGtk(parentWindow, title, fileTypes, "dialogs.open")\r
-{\r
-\r
-\r
- /* One file at a time */\r
- /* And also Multiple Files */\r
- set_select_multiple(true);\r
-\r
-#ifdef WITH_GNOME_VFS\r
- if (gnome_vfs_initialized()) {\r
- set_local_only(false);\r
- }\r
-#endif\r
-\r
- /* Initalize to Autodetect */\r
- extension = NULL;\r
- /* No filename to start out with */\r
- myFilename = "";\r
-\r
- /* Set our dialog type (open, import, etc...)*/\r
- dialogType = fileTypes;\r
-\r
-\r
- /* Set the pwd and/or the filename */\r
- if (dir.size() > 0)\r
- {\r
- Glib::ustring udir(dir);\r
- Glib::ustring::size_type len = udir.length();\r
- // leaving a trailing backslash on the directory name leads to the infamous\r
- // double-directory bug on win32\r
- if (len != 0 && udir[len - 1] == '\\') udir.erase(len - 1);\r
- set_current_folder(udir.c_str());\r
- }\r
-\r
-\r
- set_extra_widget( previewCheckbox );\r
-\r
-\r
- //###### Add the file types menu\r
- createFilterMenu();\r
-\r
- add_button(Gtk::Stock::CANCEL, Gtk::RESPONSE_CANCEL);\r
- set_default(*add_button(Gtk::Stock::OPEN, Gtk::RESPONSE_OK));\r
- \r
- //###### Allow easy access to our examples folder \r
- if(Inkscape::IO::file_test(INKSCAPE_EXAMPLESDIR,\r
- (GFileTest)(G_FILE_TEST_EXISTS | G_FILE_TEST_IS_DIR)))\r
- {\r
- add_shortcut_folder(INKSCAPE_EXAMPLESDIR);\r
- }\r
-}\r
-\r
-/**\r
- * Destructor\r
- */\r
-FileOpenDialogImplGtk::~FileOpenDialogImplGtk()\r
-{\r
-\r
-}\r
-\r
-void FileOpenDialogImplGtk::createFilterMenu()\r
-{\r
- Gtk::FileFilter allInkscapeFilter;\r
- allInkscapeFilter.set_name(_("All Inkscape Files"));\r
- extensionMap[Glib::ustring(_("All Inkscape Files"))]=NULL;\r
- add_filter(allInkscapeFilter);\r
-\r
- Gtk::FileFilter allFilter;\r
- allFilter.set_name(_("All Files"));\r
- extensionMap[Glib::ustring(_("All Files"))]=NULL;\r
- allFilter.add_pattern("*");\r
- add_filter(allFilter);\r
-\r
- Gtk::FileFilter allImageFilter;\r
- allImageFilter.set_name(_("All Images"));\r
- extensionMap[Glib::ustring(_("All Images"))]=NULL;\r
- add_filter(allImageFilter);\r
-\r
- //patterns added dynamically below\r
- Inkscape::Extension::DB::InputList extension_list;\r
- Inkscape::Extension::db.get_input_list(extension_list);\r
-\r
- for (Inkscape::Extension::DB::InputList::iterator current_item = extension_list.begin();\r
- current_item != extension_list.end(); current_item++)\r
- {\r
- Inkscape::Extension::Input * imod = *current_item;\r
-\r
- // FIXME: would be nice to grey them out instead of not listing them\r
- if (imod->deactivated()) continue;\r
-\r
- Glib::ustring upattern("*");\r
- Glib::ustring extension = imod->get_extension();\r
- fileDialogExtensionToPattern(upattern, extension);\r
-\r
- Gtk::FileFilter filter;\r
- Glib::ustring uname(_(imod->get_filetypename()));\r
- filter.set_name(uname);\r
- filter.add_pattern(upattern);\r
- add_filter(filter);\r
- extensionMap[uname] = imod;\r
-\r
- //g_message("ext %s:%s '%s'\n", ioext->name, ioext->mimetype, upattern.c_str());\r
- allInkscapeFilter.add_pattern(upattern);\r
- if ( strncmp("image", imod->get_mimetype(), 5)==0 )\r
- allImageFilter.add_pattern(upattern);\r
- }\r
-\r
- return;\r
-}\r
-\r
-/**\r
- * Show this dialog modally. Return true if user hits [OK]\r
- */\r
-bool\r
-FileOpenDialogImplGtk::show()\r
-{\r
- Glib::ustring s = Glib::filename_to_utf8 (get_current_folder());\r
- if (s.length() == 0)\r
- s = getcwd (NULL, 0);\r
- set_current_folder(Glib::filename_from_utf8(s)); //hack to force initial dir listing\r
- set_modal (TRUE); //Window\r
- sp_transientize((GtkWidget *)gobj()); //Make transient\r
- gint b = run(); //Dialog\r
- svgPreview.showNoPreview();\r
- hide();\r
-\r
- if (b == Gtk::RESPONSE_OK)\r
- {\r
- //This is a hack, to avoid the warning messages that\r
- //Gtk::FileChooser::get_filter() returns\r
- //should be: Gtk::FileFilter *filter = get_filter();\r
- GtkFileChooser *gtkFileChooser = Gtk::FileChooser::gobj();\r
- GtkFileFilter *filter = gtk_file_chooser_get_filter(gtkFileChooser);\r
- if (filter)\r
- {\r
- //Get which extension was chosen, if any\r
- extension = extensionMap[gtk_file_filter_get_name(filter)];\r
- }\r
- myFilename = get_filename();\r
-#ifdef WITH_GNOME_VFS\r
- if (myFilename.empty() && gnome_vfs_initialized())\r
- myFilename = get_uri();\r
-#endif\r
- cleanup( true );\r
- return TRUE;\r
- }\r
- else\r
- {\r
- cleanup( false );\r
- return FALSE;\r
- }\r
-}\r
-\r
-\r
-\r
-\r
-/**\r
- * Get the file extension type that was selected by the user. Valid after an [OK]\r
- */\r
-Inkscape::Extension::Extension *\r
-FileOpenDialogImplGtk::getSelectionType()\r
-{\r
- return extension;\r
-}\r
-\r
-\r
-/**\r
- * Get the file name chosen by the user. Valid after an [OK]\r
- */\r
-Glib::ustring\r
-FileOpenDialogImplGtk::getFilename (void)\r
-{\r
- return g_strdup(myFilename.c_str());\r
-}\r
-\r
-\r
-/**\r
- * To Get Multiple filenames selected at-once.\r
- */\r
-std::vector<Glib::ustring>FileOpenDialogImplGtk::getFilenames()\r
-{\r
- std::vector<Glib::ustring> result = get_filenames();\r
-#ifdef WITH_GNOME_VFS\r
- if (result.empty() && gnome_vfs_initialized())\r
- result = get_uris();\r
-#endif\r
- return result;\r
-}\r
-\r
-\r
-\r
-\r
-\r
-\r
-//########################################################################\r
-//# F I L E S A V E\r
-//########################################################################\r
-\r
-/**\r
- * Constructor\r
- */\r
-FileSaveDialogImplGtk::FileSaveDialogImplGtk(Gtk::Window &parentWindow,\r
- const Glib::ustring &dir,\r
- FileDialogType fileTypes,\r
- const Glib::ustring &title,\r
- const Glib::ustring &default_key) :\r
- FileDialogBaseGtk(parentWindow, title, Gtk::FILE_CHOOSER_ACTION_SAVE, fileTypes, "dialogs.save_as")\r
-{\r
- /* One file at a time */\r
- set_select_multiple(false);\r
-\r
-#ifdef WITH_GNOME_VFS\r
- if (gnome_vfs_initialized()) {\r
- set_local_only(false);\r
- }\r
-#endif\r
-\r
- /* Initalize to Autodetect */\r
- extension = NULL;\r
- /* No filename to start out with */\r
- myFilename = "";\r
-\r
- /* Set our dialog type (save, export, etc...)*/\r
- dialogType = fileTypes;\r
-\r
- /* Set the pwd and/or the filename */\r
- if (dir.size() > 0)\r
- {\r
- Glib::ustring udir(dir);\r
- Glib::ustring::size_type len = udir.length();\r
- // leaving a trailing backslash on the directory name leads to the infamous\r
- // double-directory bug on win32\r
- if (len != 0 && udir[len - 1] == '\\') udir.erase(len - 1);\r
- myFilename = udir;\r
- }\r
-\r
- //###### Add the file types menu\r
- //createFilterMenu();\r
-\r
- //###### Do we want the .xxx extension automatically added?\r
- fileTypeCheckbox.set_label(Glib::ustring(_("Append filename extension automatically")));\r
- fileTypeCheckbox.set_active( (bool)prefs_get_int_attribute("dialogs.save_as",\r
- "append_extension", 1) );\r
-\r
- createFileTypeMenu();\r
- fileTypeComboBox.set_size_request(200,40);\r
- fileTypeComboBox.signal_changed().connect(\r
- sigc::mem_fun(*this, &FileSaveDialogImplGtk::fileTypeChangedCallback) );\r
-\r
-\r
- childBox.pack_start( checksBox );\r
- childBox.pack_end( fileTypeComboBox );\r
- checksBox.pack_start( fileTypeCheckbox );\r
- checksBox.pack_start( previewCheckbox );\r
-\r
- set_extra_widget( childBox );\r
-\r
- //Let's do some customization\r
- fileNameEntry = NULL;\r
- Gtk::Container *cont = get_toplevel();\r
- std::vector<Gtk::Entry *> entries;\r
- findEntryWidgets(cont, entries);\r
- //g_message("Found %d entry widgets\n", entries.size());\r
- if (entries.size() >=1 )\r
- {\r
- //Catch when user hits [return] on the text field\r
- fileNameEntry = entries[0];\r
- fileNameEntry->signal_activate().connect(\r
- sigc::mem_fun(*this, &FileSaveDialogImplGtk::fileNameEntryChangedCallback) );\r
- }\r
-\r
- //Let's do more customization\r
- std::vector<Gtk::Expander *> expanders;\r
- findExpanderWidgets(cont, expanders);\r
- //g_message("Found %d expander widgets\n", expanders.size());\r
- if (expanders.size() >=1 )\r
- {\r
- //Always show the file list\r
- Gtk::Expander *expander = expanders[0];\r
- expander->set_expanded(true);\r
- }\r
-\r
-\r
- //if (extension == NULL)\r
- // checkbox.set_sensitive(FALSE);\r
-\r
- add_button(Gtk::Stock::CANCEL, Gtk::RESPONSE_CANCEL);\r
- set_default(*add_button(Gtk::Stock::SAVE, Gtk::RESPONSE_OK));\r
-\r
- show_all_children();\r
-}\r
-\r
-/**\r
- * Destructor\r
- */\r
-FileSaveDialogImplGtk::~FileSaveDialogImplGtk()\r
-{\r
-}\r
-\r
-/**\r
- * Callback for fileNameEntry widget\r
- */\r
-void FileSaveDialogImplGtk::fileNameEntryChangedCallback()\r
-{\r
- if (!fileNameEntry)\r
- return;\r
-\r
- Glib::ustring fileName = fileNameEntry->get_text();\r
- if (!Glib::get_charset()) //If we are not utf8\r
- fileName = Glib::filename_to_utf8(fileName);\r
-\r
- //g_message("User hit return. Text is '%s'\n", fileName.c_str());\r
-\r
- if (!Glib::path_is_absolute(fileName)) {\r
- //try appending to the current path\r
- // not this way: fileName = get_current_folder() + "/" + fileName;\r
- std::vector<Glib::ustring> pathSegments;\r
- pathSegments.push_back( get_current_folder() );\r
- pathSegments.push_back( fileName );\r
- fileName = Glib::build_filename(pathSegments);\r
- }\r
-\r
- //g_message("path:'%s'\n", fileName.c_str());\r
-\r
- if (Glib::file_test(fileName, Glib::FILE_TEST_IS_DIR)) {\r
- set_current_folder(fileName);\r
- } else if (/*Glib::file_test(fileName, Glib::FILE_TEST_IS_REGULAR)*/1) {\r
- //dialog with either (1) select a regular file or (2) cd to dir\r
- //simulate an 'OK'\r
- set_filename(fileName);\r
- response(Gtk::RESPONSE_OK);\r
- }\r
-}\r
-\r
-\r
-\r
-/**\r
- * Callback for fileNameEntry widget\r
- */\r
-void FileSaveDialogImplGtk::fileTypeChangedCallback()\r
-{\r
- int sel = fileTypeComboBox.get_active_row_number();\r
- if (sel<0 || sel >= (int)fileTypes.size())\r
- return;\r
- FileType type = fileTypes[sel];\r
- //g_message("selected: %s\n", type.name.c_str());\r
-\r
- extension = type.extension;\r
- Gtk::FileFilter filter;\r
- filter.add_pattern(type.pattern);\r
- set_filter(filter);\r
-\r
- updateNameAndExtension();\r
-}\r
-\r
-\r
-\r
-void FileSaveDialogImplGtk::createFileTypeMenu()\r
-{\r
- Inkscape::Extension::DB::OutputList extension_list;\r
- Inkscape::Extension::db.get_output_list(extension_list);\r
- knownExtensions.clear();\r
-\r
- for (Inkscape::Extension::DB::OutputList::iterator current_item = extension_list.begin();\r
- current_item != extension_list.end(); current_item++)\r
- {\r
- Inkscape::Extension::Output * omod = *current_item;\r
-\r
- // FIXME: would be nice to grey them out instead of not listing them\r
- if (omod->deactivated()) continue;\r
-\r
- FileType type;\r
- type.name = (_(omod->get_filetypename()));\r
- type.pattern = "*";\r
- Glib::ustring extension = omod->get_extension();\r
- knownExtensions.insert( extension.casefold() );\r
- fileDialogExtensionToPattern (type.pattern, extension);\r
- type.extension= omod;\r
- fileTypeComboBox.append_text(type.name);\r
- fileTypes.push_back(type);\r
- }\r
-\r
- //#Let user choose\r
- FileType guessType;\r
- guessType.name = _("Guess from extension");\r
- guessType.pattern = "*";\r
- guessType.extension = NULL;\r
- fileTypeComboBox.append_text(guessType.name);\r
- fileTypes.push_back(guessType);\r
-\r
-\r
- fileTypeComboBox.set_active(0);\r
- fileTypeChangedCallback(); //call at least once to set the filter\r
-}\r
-\r
-\r
-\r
-\r
-\r
-/**\r
- * Show this dialog modally. Return true if user hits [OK]\r
- */\r
-bool\r
-FileSaveDialogImplGtk::show()\r
-{\r
- change_path(myFilename);\r
- set_modal (TRUE); //Window\r
- sp_transientize((GtkWidget *)gobj()); //Make transient\r
- gint b = run(); //Dialog\r
- svgPreview.showNoPreview();\r
- set_preview_widget_active(false);\r
- hide();\r
-\r
- if (b == Gtk::RESPONSE_OK)\r
- {\r
- updateNameAndExtension();\r
-\r
- // Store changes of the "Append filename automatically" checkbox back to preferences.\r
- prefs_set_int_attribute("dialogs.save_as", "append_extension", fileTypeCheckbox.get_active());\r
-\r
- // Store the last used save-as filetype to preferences.\r
- prefs_set_string_attribute("dialogs.save_as", "default",\r
- ( extension != NULL ? extension->get_id() : "" ));\r
-\r
- cleanup( true );\r
-\r
- return TRUE;\r
- }\r
- else\r
- {\r
- cleanup( false );\r
-\r
- return FALSE;\r
- }\r
-}\r
-\r
-\r
-/**\r
- * Get the file extension type that was selected by the user. Valid after an [OK]\r
- */\r
-Inkscape::Extension::Extension *\r
-FileSaveDialogImplGtk::getSelectionType()\r
-{\r
- return extension;\r
-}\r
-\r
-void FileSaveDialogImplGtk::setSelectionType( Inkscape::Extension::Extension * key )\r
-{\r
- // If no pointer to extension is passed in, look up based on filename extension.\r
- if ( !key ) {\r
- // Not quite UTF-8 here.\r
- gchar *filenameLower = g_ascii_strdown(myFilename.c_str(), -1);\r
- for ( int i = 0; !key && (i < (int)fileTypes.size()); i++ ) {\r
- Inkscape::Extension::Output *ext = dynamic_cast<Inkscape::Extension::Output*>(fileTypes[i].extension);\r
- if ( ext && ext->get_extension() ) {\r
- gchar *extensionLower = g_ascii_strdown( ext->get_extension(), -1 );\r
- if ( g_str_has_suffix(filenameLower, extensionLower) ) {\r
- key = fileTypes[i].extension;\r
- }\r
- g_free(extensionLower);\r
- }\r
- }\r
- g_free(filenameLower);\r
- }\r
-\r
- // Ensure the proper entry in the combo box is selected.\r
- if ( key ) {\r
- extension = key;\r
- gchar const * extensionID = extension->get_id();\r
- if ( extensionID ) {\r
- for ( int i = 0; i < (int)fileTypes.size(); i++ ) {\r
- Inkscape::Extension::Extension *ext = fileTypes[i].extension;\r
- if ( ext ) {\r
- gchar const * id = ext->get_id();\r
- if ( id && ( strcmp(extensionID, id) == 0) ) {\r
- int oldSel = fileTypeComboBox.get_active_row_number();\r
- if ( i != oldSel ) {\r
- fileTypeComboBox.set_active(i);\r
- }\r
- break;\r
- }\r
- }\r
- }\r
- }\r
- }\r
-}\r
-\r
-\r
-/**\r
- * Get the file name chosen by the user. Valid after an [OK]\r
- */\r
-Glib::ustring\r
-FileSaveDialogImplGtk::getFilename()\r
-{\r
- return myFilename;\r
-}\r
-\r
-\r
-void\r
-FileSaveDialogImplGtk::change_title(const Glib::ustring& title)\r
-{\r
- this->set_title(title);\r
-}\r
-\r
-/**\r
- * Change the default save path location.\r
- */\r
-void\r
-FileSaveDialogImplGtk::change_path(const Glib::ustring& path)\r
-{\r
- myFilename = path;\r
- if (Glib::file_test(myFilename, Glib::FILE_TEST_IS_DIR)) {\r
- //fprintf(stderr,"set_current_folder(%s)\n",myFilename.c_str());\r
- set_current_folder(myFilename);\r
- } else {\r
- //fprintf(stderr,"set_filename(%s)\n",myFilename.c_str());\r
- if ( Glib::file_test( myFilename, Glib::FILE_TEST_EXISTS ) ) {\r
- set_filename(myFilename);\r
- } else {\r
- std::string dirName = Glib::path_get_dirname( myFilename );\r
- if ( dirName != get_current_folder() ) {\r
- set_current_folder(dirName);\r
- }\r
- }\r
- Glib::ustring basename = Glib::path_get_basename(myFilename);\r
- //fprintf(stderr,"set_current_name(%s)\n",basename.c_str());\r
- try {\r
- set_current_name( Glib::filename_to_utf8(basename) );\r
- } catch ( Glib::ConvertError& e ) {\r
- g_warning( "Error converting save filename to UTF-8." );\r
- // try a fallback.\r
- set_current_name( basename );\r
- }\r
- }\r
-}\r
-\r
-void FileSaveDialogImplGtk::updateNameAndExtension()\r
-{\r
- // Pick up any changes the user has typed in.\r
- Glib::ustring tmp = get_filename();\r
-#ifdef WITH_GNOME_VFS\r
- if ( tmp.empty() && gnome_vfs_initialized() ) {\r
- tmp = get_uri();\r
- }\r
-#endif\r
- if ( !tmp.empty() ) {\r
- myFilename = tmp;\r
- }\r
-\r
- Inkscape::Extension::Output* newOut = extension ? dynamic_cast<Inkscape::Extension::Output*>(extension) : 0;\r
- if ( fileTypeCheckbox.get_active() && newOut ) {\r
- try {\r
- bool appendExtension = true;\r
- Glib::ustring utf8Name = Glib::filename_to_utf8( myFilename );\r
- Glib::ustring::size_type pos = utf8Name.rfind('.');\r
- if ( pos != Glib::ustring::npos ) {\r
- Glib::ustring trail = utf8Name.substr( pos );\r
- Glib::ustring foldedTrail = trail.casefold();\r
- if ( (trail == ".")\r
- | (foldedTrail != Glib::ustring( newOut->get_extension() ).casefold()\r
- && ( knownExtensions.find(foldedTrail) != knownExtensions.end() ) ) ) {\r
- utf8Name = utf8Name.erase( pos );\r
- } else {\r
- appendExtension = false;\r
- }\r
- }\r
-\r
- if (appendExtension) {\r
- utf8Name = utf8Name + newOut->get_extension();\r
- myFilename = Glib::filename_from_utf8( utf8Name );\r
- change_path(myFilename);\r
- }\r
- } catch ( Glib::ConvertError& e ) {\r
- // ignore\r
- }\r
- }\r
-}\r
-\r
-\r
-//########################################################################\r
-//# F I L E E X P O R T\r
-//########################################################################\r
-\r
-/**\r
- * Callback for fileNameEntry widget\r
- */\r
-void FileExportDialogImpl::fileNameEntryChangedCallback()\r
-{\r
- if (!fileNameEntry)\r
- return;\r
-\r
- Glib::ustring fileName = fileNameEntry->get_text();\r
- if (!Glib::get_charset()) //If we are not utf8\r
- fileName = Glib::filename_to_utf8(fileName);\r
-\r
- //g_message("User hit return. Text is '%s'\n", fileName.c_str());\r
-\r
- if (!Glib::path_is_absolute(fileName)) {\r
- //try appending to the current path\r
- // not this way: fileName = get_current_folder() + "/" + fileName;\r
- std::vector<Glib::ustring> pathSegments;\r
- pathSegments.push_back( get_current_folder() );\r
- pathSegments.push_back( fileName );\r
- fileName = Glib::build_filename(pathSegments);\r
- }\r
-\r
- //g_message("path:'%s'\n", fileName.c_str());\r
-\r
- if (Glib::file_test(fileName, Glib::FILE_TEST_IS_DIR)) {\r
- set_current_folder(fileName);\r
- } else if (/*Glib::file_test(fileName, Glib::FILE_TEST_IS_REGULAR)*/1) {\r
- //dialog with either (1) select a regular file or (2) cd to dir\r
- //simulate an 'OK'\r
- set_filename(fileName);\r
- response(Gtk::RESPONSE_OK);\r
- }\r
-}\r
-\r
-\r
-\r
-/**\r
- * Callback for fileNameEntry widget\r
- */\r
-void FileExportDialogImpl::fileTypeChangedCallback()\r
-{\r
- int sel = fileTypeComboBox.get_active_row_number();\r
- if (sel<0 || sel >= (int)fileTypes.size())\r
- return;\r
- FileType type = fileTypes[sel];\r
- //g_message("selected: %s\n", type.name.c_str());\r
- Gtk::FileFilter filter;\r
- filter.add_pattern(type.pattern);\r
- set_filter(filter);\r
-}\r
-\r
-\r
-\r
-void FileExportDialogImpl::createFileTypeMenu()\r
-{\r
- Inkscape::Extension::DB::OutputList extension_list;\r
- Inkscape::Extension::db.get_output_list(extension_list);\r
-\r
- for (Inkscape::Extension::DB::OutputList::iterator current_item = extension_list.begin();\r
- current_item != extension_list.end(); current_item++)\r
- {\r
- Inkscape::Extension::Output * omod = *current_item;\r
-\r
- // FIXME: would be nice to grey them out instead of not listing them\r
- if (omod->deactivated()) continue;\r
-\r
- FileType type;\r
- type.name = (_(omod->get_filetypename()));\r
- type.pattern = "*";\r
- Glib::ustring extension = omod->get_extension();\r
- fileDialogExtensionToPattern (type.pattern, extension);\r
- type.extension= omod;\r
- fileTypeComboBox.append_text(type.name);\r
- fileTypes.push_back(type);\r
- }\r
-\r
- //#Let user choose\r
- FileType guessType;\r
- guessType.name = _("Guess from extension");\r
- guessType.pattern = "*";\r
- guessType.extension = NULL;\r
- fileTypeComboBox.append_text(guessType.name);\r
- fileTypes.push_back(guessType);\r
-\r
-\r
- fileTypeComboBox.set_active(0);\r
- fileTypeChangedCallback(); //call at least once to set the filter\r
-}\r
-\r
-\r
-/**\r
- * Constructor\r
- */\r
-FileExportDialogImpl::FileExportDialogImpl(Gtk::Window& parentWindow,\r
- const Glib::ustring &dir,\r
- FileDialogType fileTypes,\r
- const Glib::ustring &title,\r
- const Glib::ustring &default_key) :\r
- FileDialogBaseGtk(parentWindow, title, Gtk::FILE_CHOOSER_ACTION_SAVE, fileTypes, "dialogs.export"),\r
- sourceX0Spinner("X0", _("Left edge of source")),\r
- sourceY0Spinner("Y0", _("Top edge of source")),\r
- sourceX1Spinner("X1", _("Right edge of source")),\r
- sourceY1Spinner("Y1", _("Bottom edge of source")),\r
- sourceWidthSpinner("Width", _("Source width")),\r
- sourceHeightSpinner("Height", _("Source height")),\r
- destWidthSpinner("Width", _("Destination width")),\r
- destHeightSpinner("Height", _("Destination height")),\r
- destDPISpinner("DPI", _("Resolution (dots per inch)"))\r
-{\r
- append_extension = (bool)prefs_get_int_attribute("dialogs.save_as", "append_extension", 1);\r
-\r
- /* One file at a time */\r
- set_select_multiple(false);\r
-\r
-#ifdef WITH_GNOME_VFS\r
- if (gnome_vfs_initialized()) {\r
- set_local_only(false);\r
- }\r
-#endif\r
-\r
- /* Initalize to Autodetect */\r
- extension = NULL;\r
- /* No filename to start out with */\r
- myFilename = "";\r
-\r
- /* Set our dialog type (save, export, etc...)*/\r
- dialogType = fileTypes;\r
-\r
- /* Set the pwd and/or the filename */\r
- if (dir.size()>0)\r
- {\r
- Glib::ustring udir(dir);\r
- Glib::ustring::size_type len = udir.length();\r
- // leaving a trailing backslash on the directory name leads to the infamous\r
- // double-directory bug on win32\r
- if (len != 0 && udir[len - 1] == '\\') udir.erase(len - 1);\r
- set_current_folder(udir.c_str());\r
- }\r
-\r
- //#########################################\r
- //## EXTRA WIDGET -- SOURCE SIDE\r
- //#########################################\r
-\r
- //##### Export options buttons/spinners, etc\r
- documentButton.set_label(_("Document"));\r
- scopeBox.pack_start(documentButton);\r
- scopeGroup = documentButton.get_group();\r
-\r
- pageButton.set_label(_("Page"));\r
- pageButton.set_group(scopeGroup);\r
- scopeBox.pack_start(pageButton);\r
-\r
- selectionButton.set_label(_("Selection"));\r
- selectionButton.set_group(scopeGroup);\r
- scopeBox.pack_start(selectionButton);\r
-\r
- customButton.set_label(_("Custom"));\r
- customButton.set_group(scopeGroup);\r
- scopeBox.pack_start(customButton);\r
-\r
- sourceBox.pack_start(scopeBox);\r
-\r
-\r
-\r
- //dimension buttons\r
- sourceTable.resize(3,3);\r
- sourceTable.attach(sourceX0Spinner, 0,1,0,1);\r
- sourceTable.attach(sourceY0Spinner, 1,2,0,1);\r
- sourceUnitsSpinner.setUnitType(UNIT_TYPE_LINEAR);\r
- sourceTable.attach(sourceUnitsSpinner, 2,3,0,1);\r
- sourceTable.attach(sourceX1Spinner, 0,1,1,2);\r
- sourceTable.attach(sourceY1Spinner, 1,2,1,2);\r
- sourceTable.attach(sourceWidthSpinner, 0,1,2,3);\r
- sourceTable.attach(sourceHeightSpinner, 1,2,2,3);\r
-\r
- sourceBox.pack_start(sourceTable);\r
- sourceFrame.set_label(_("Source"));\r
- sourceFrame.add(sourceBox);\r
- exportOptionsBox.pack_start(sourceFrame);\r
-\r
-\r
- //#########################################\r
- //## EXTRA WIDGET -- SOURCE SIDE\r
- //#########################################\r
-\r
-\r
- destTable.resize(3,3);\r
- destTable.attach(destWidthSpinner, 0,1,0,1);\r
- destTable.attach(destHeightSpinner, 1,2,0,1);\r
- destUnitsSpinner.setUnitType(UNIT_TYPE_LINEAR);\r
- destTable.attach(destUnitsSpinner, 2,3,0,1);\r
- destTable.attach(destDPISpinner, 0,1,1,2);\r
-\r
- destBox.pack_start(destTable);\r
-\r
-\r
- cairoButton.set_label(_("Cairo"));\r
- otherOptionBox.pack_start(cairoButton);\r
-\r
- antiAliasButton.set_label(_("Antialias"));\r
- otherOptionBox.pack_start(antiAliasButton);\r
-\r
- backgroundButton.set_label(_("Background"));\r
- otherOptionBox.pack_start(backgroundButton);\r
-\r
- destBox.pack_start(otherOptionBox);\r
-\r
-\r
-\r
-\r
-\r
- //###### File options\r
- //###### Do we want the .xxx extension automatically added?\r
- fileTypeCheckbox.set_label(Glib::ustring(_("Append filename extension automatically")));\r
- fileTypeCheckbox.set_active(append_extension);\r
- destBox.pack_start(fileTypeCheckbox);\r
-\r
- //###### File type menu\r
- createFileTypeMenu();\r
- fileTypeComboBox.set_size_request(200,40);\r
- fileTypeComboBox.signal_changed().connect(\r
- sigc::mem_fun(*this, &FileExportDialogImpl::fileTypeChangedCallback) );\r
-\r
- destBox.pack_start(fileTypeComboBox);\r
-\r
- destFrame.set_label(_("Destination"));\r
- destFrame.add(destBox);\r
- exportOptionsBox.pack_start(destFrame);\r
-\r
- //##### Put the two boxes and their parent onto the dialog\r
- exportOptionsBox.pack_start(sourceFrame);\r
- exportOptionsBox.pack_start(destFrame);\r
-\r
- set_extra_widget(exportOptionsBox);\r
-\r
-\r
-\r
-\r
- //Let's do some customization\r
- fileNameEntry = NULL;\r
- Gtk::Container *cont = get_toplevel();\r
- std::vector<Gtk::Entry *> entries;\r
- findEntryWidgets(cont, entries);\r
- //g_message("Found %d entry widgets\n", entries.size());\r
- if (entries.size() >=1 )\r
- {\r
- //Catch when user hits [return] on the text field\r
- fileNameEntry = entries[0];\r
- fileNameEntry->signal_activate().connect(\r
- sigc::mem_fun(*this, &FileExportDialogImpl::fileNameEntryChangedCallback) );\r
- }\r
-\r
- //Let's do more customization\r
- std::vector<Gtk::Expander *> expanders;\r
- findExpanderWidgets(cont, expanders);\r
- //g_message("Found %d expander widgets\n", expanders.size());\r
- if (expanders.size() >=1 )\r
- {\r
- //Always show the file list\r
- Gtk::Expander *expander = expanders[0];\r
- expander->set_expanded(true);\r
- }\r
-\r
-\r
- //if (extension == NULL)\r
- // checkbox.set_sensitive(FALSE);\r
-\r
- add_button(Gtk::Stock::CANCEL, Gtk::RESPONSE_CANCEL);\r
- set_default(*add_button(Gtk::Stock::SAVE, Gtk::RESPONSE_OK));\r
-\r
- show_all_children();\r
-}\r
-\r
-/**\r
- * Destructor\r
- */\r
-FileExportDialogImpl::~FileExportDialogImpl()\r
-{\r
-}\r
-\r
-\r
-\r
-/**\r
- * Show this dialog modally. Return true if user hits [OK]\r
- */\r
-bool\r
-FileExportDialogImpl::show()\r
-{\r
- Glib::ustring s = Glib::filename_to_utf8 (get_current_folder());\r
- if (s.length() == 0)\r
- s = getcwd (NULL, 0);\r
- set_current_folder(Glib::filename_from_utf8(s)); //hack to force initial dir listing\r
- set_modal (TRUE); //Window\r
- sp_transientize((GtkWidget *)gobj()); //Make transient\r
- gint b = run(); //Dialog\r
- svgPreview.showNoPreview();\r
- hide();\r
-\r
- if (b == Gtk::RESPONSE_OK)\r
- {\r
- int sel = fileTypeComboBox.get_active_row_number ();\r
- if (sel>=0 && sel< (int)fileTypes.size())\r
- {\r
- FileType &type = fileTypes[sel];\r
- extension = type.extension;\r
- }\r
- myFilename = get_filename();\r
-#ifdef WITH_GNOME_VFS\r
- if ( myFilename.empty() && gnome_vfs_initialized() ) {\r
- myFilename = get_uri();\r
- }\r
-#endif\r
-\r
- /*\r
-\r
- // FIXME: Why do we have more code\r
-\r
- append_extension = checkbox.get_active();\r
- prefs_set_int_attribute("dialogs.save_as", "append_extension", append_extension);\r
- prefs_set_string_attribute("dialogs.save_as", "default",\r
- ( extension != NULL ? extension->get_id() : "" ));\r
- */\r
- return TRUE;\r
- }\r
- else\r
- {\r
- return FALSE;\r
- }\r
-}\r
-\r
-\r
-/**\r
- * Get the file extension type that was selected by the user. Valid after an [OK]\r
- */\r
-Inkscape::Extension::Extension *\r
-FileExportDialogImpl::getSelectionType()\r
-{\r
- return extension;\r
-}\r
-\r
-\r
-/**\r
- * Get the file name chosen by the user. Valid after an [OK]\r
- */\r
-Glib::ustring\r
-FileExportDialogImpl::getFilename()\r
-{\r
- return myFilename;\r
-}\r
-\r
-\r
-} //namespace Dialog\r
-} //namespace UI\r
-} //namespace Inkscape\r
-\r
-/*\r
- Local Variables:\r
- mode:c++\r
- c-file-style:"stroustrup"\r
- c-file-offsets:((innamespace . 0)(inline-open . 0)(case-label . +))\r
- indent-tabs-mode:nil\r
- fill-column:99\r
- End:\r
-*/\r
-// vim: filetype=cpp:expandtab:shiftwidth=4:tabstop=8:softtabstop=4 :\r
+/**
+ * Implementation of the file dialog interfaces defined in filedialogimpl.h
+ *
+ * Authors:
+ * Bob Jamison
+ * Joel Holdsworth
+ * Bruno Dilly
+ * Other dudes from The Inkscape Organization
+ *
+ * Copyright (C) 2004-2007 Bob Jamison
+ * Copyright (C) 2006 Johan Engelen <johan@shouraizou.nl>
+ * Copyright (C) 2004-2007 The Inkscape Organization
+ * Copyright (C) 2007 Joel Holdsworth
+ *
+ * Released under GNU GPL, read the file 'COPYING' for more information
+ */
+
+#ifdef HAVE_CONFIG_H
+# include <config.h>
+#endif
+
+#include "filedialogimpl-gtkmm.h"
+#include "dialogs/dialog-events.h"
+#include "interface.h"
+#include "io/sys.h"
+#include "path-prefix.h"
+
+#ifdef WITH_GNOME_VFS
+# include <libgnomevfs/gnome-vfs.h>
+#endif
+
+//Routines from file.cpp
+#undef INK_DUMP_FILENAME_CONV
+
+#ifdef INK_DUMP_FILENAME_CONV
+void dump_str( const gchar* str, const gchar* prefix );
+void dump_ustr( const Glib::ustring& ustr );
+#endif
+
+
+
+namespace Inkscape
+{
+namespace UI
+{
+namespace Dialog
+{
+
+
+
+
+
+//########################################################################
+//### U T I L I T Y
+//########################################################################
+
+void
+fileDialogExtensionToPattern(Glib::ustring &pattern,
+ Glib::ustring &extension)
+{
+ for (unsigned int i = 0; i < extension.length(); i++ )
+ {
+ Glib::ustring::value_type ch = extension[i];
+ if ( Glib::Unicode::isalpha(ch) )
+ {
+ pattern += '[';
+ pattern += Glib::Unicode::toupper(ch);
+ pattern += Glib::Unicode::tolower(ch);
+ pattern += ']';
+ }
+ else
+ {
+ pattern += ch;
+ }
+ }
+}
+
+
+void
+findEntryWidgets(Gtk::Container *parent,
+ std::vector<Gtk::Entry *> &result)
+{
+ if (!parent)
+ return;
+ std::vector<Gtk::Widget *> children = parent->get_children();
+ for (unsigned int i=0; i<children.size() ; i++)
+ {
+ Gtk::Widget *child = children[i];
+ GtkWidget *wid = child->gobj();
+ if (GTK_IS_ENTRY(wid))
+ result.push_back((Gtk::Entry *)child);
+ else if (GTK_IS_CONTAINER(wid))
+ findEntryWidgets((Gtk::Container *)child, result);
+ }
+
+}
+
+void
+findExpanderWidgets(Gtk::Container *parent,
+ std::vector<Gtk::Expander *> &result)
+{
+ if (!parent)
+ return;
+ std::vector<Gtk::Widget *> children = parent->get_children();
+ for (unsigned int i=0; i<children.size() ; i++)
+ {
+ Gtk::Widget *child = children[i];
+ GtkWidget *wid = child->gobj();
+ if (GTK_IS_EXPANDER(wid))
+ result.push_back((Gtk::Expander *)child);
+ else if (GTK_IS_CONTAINER(wid))
+ findExpanderWidgets((Gtk::Container *)child, result);
+ }
+
+}
+
+
+/*#########################################################################
+### SVG Preview Widget
+#########################################################################*/
+
+bool SVGPreview::setDocument(SPDocument *doc)
+{
+ if (document)
+ sp_document_unref(document);
+
+ sp_document_ref(doc);
+ document = doc;
+
+ //This should remove it from the box, and free resources
+ if (viewerGtk)
+ gtk_widget_destroy(viewerGtk);
+
+ viewerGtk = sp_svg_view_widget_new(doc);
+ GtkWidget *vbox = (GtkWidget *)gobj();
+ gtk_box_pack_start(GTK_BOX(vbox), viewerGtk, TRUE, TRUE, 0);
+ gtk_widget_show(viewerGtk);
+
+ return true;
+}
+
+
+bool SVGPreview::setFileName(Glib::ustring &theFileName)
+{
+ Glib::ustring fileName = theFileName;
+
+ fileName = Glib::filename_to_utf8(fileName);
+
+ /**
+ * I don't know why passing false to keepalive is bad. But it
+ * prevents the display of an svg with a non-ascii filename
+ */
+ SPDocument *doc = sp_document_new (fileName.c_str(), true);
+ if (!doc) {
+ g_warning("SVGView: error loading document '%s'\n", fileName.c_str());
+ return false;
+ }
+
+ setDocument(doc);
+
+ sp_document_unref(doc);
+
+ return true;
+}
+
+
+
+bool SVGPreview::setFromMem(char const *xmlBuffer)
+{
+ if (!xmlBuffer)
+ return false;
+
+ gint len = (gint)strlen(xmlBuffer);
+ SPDocument *doc = sp_document_new_from_mem(xmlBuffer, len, 0);
+ if (!doc) {
+ g_warning("SVGView: error loading buffer '%s'\n",xmlBuffer);
+ return false;
+ }
+
+ setDocument(doc);
+
+ sp_document_unref(doc);
+
+ Inkscape::GC::request_early_collection();
+
+ return true;
+}
+
+
+
+void SVGPreview::showImage(Glib::ustring &theFileName)
+{
+ Glib::ustring fileName = theFileName;
+
+
+ /*#####################################
+ # LET'S HAVE SOME FUN WITH SVG!
+ # Instead of just loading an image, why
+ # don't we make a lovely little svg and
+ # display it nicely?
+ #####################################*/
+
+ //Arbitrary size of svg doc -- rather 'portrait' shaped
+ gint previewWidth = 400;
+ gint previewHeight = 600;
+
+ //Get some image info. Smart pointer does not need to be deleted
+ Glib::RefPtr<Gdk::Pixbuf> img = Gdk::Pixbuf::create_from_file(fileName);
+ gint imgWidth = img->get_width();
+ gint imgHeight = img->get_height();
+
+ //Find the minimum scale to fit the image inside the preview area
+ double scaleFactorX = (0.9 *(double)previewWidth) / ((double)imgWidth);
+ double scaleFactorY = (0.9 *(double)previewHeight) / ((double)imgHeight);
+ double scaleFactor = scaleFactorX;
+ if (scaleFactorX > scaleFactorY)
+ scaleFactor = scaleFactorY;
+
+ //Now get the resized values
+ gint scaledImgWidth = (int) (scaleFactor * (double)imgWidth);
+ gint scaledImgHeight = (int) (scaleFactor * (double)imgHeight);
+
+ //center the image on the area
+ gint imgX = (previewWidth - scaledImgWidth) / 2;
+ gint imgY = (previewHeight - scaledImgHeight) / 2;
+
+ //wrap a rectangle around the image
+ gint rectX = imgX-1;
+ gint rectY = imgY-1;
+ gint rectWidth = scaledImgWidth +2;
+ gint rectHeight = scaledImgHeight+2;
+
+ //Our template. Modify to taste
+ gchar const *xformat =
+ "<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n"
+ "<svg\n"
+ "xmlns=\"http://www.w3.org/2000/svg\"\n"
+ "xmlns:xlink=\"http://www.w3.org/1999/xlink\"\n"
+ "width=\"%d\" height=\"%d\">\n" //# VALUES HERE
+ "<rect\n"
+ " style=\"fill:#eeeeee;stroke:none\"\n"
+ " x=\"-100\" y=\"-100\" width=\"4000\" height=\"4000\"/>\n"
+ "<image x=\"%d\" y=\"%d\" width=\"%d\" height=\"%d\"\n"
+ "xlink:href=\"%s\"/>\n"
+ "<rect\n"
+ " style=\"fill:none;"
+ " stroke:#000000;stroke-width:1.0;"
+ " stroke-linejoin:miter;stroke-opacity:1.0000000;"
+ " stroke-miterlimit:4.0000000;stroke-dasharray:none\"\n"
+ " x=\"%d\" y=\"%d\" width=\"%d\" height=\"%d\"/>\n"
+ "<text\n"
+ " style=\"font-size:24.000000;font-style:normal;font-weight:normal;"
+ " fill:#000000;fill-opacity:1.0000000;stroke:none;"
+ " font-family:Bitstream Vera Sans\"\n"
+ " x=\"10\" y=\"26\">%d x %d</text>\n" //# VALUES HERE
+ "</svg>\n\n";
+
+ //if (!Glib::get_charset()) //If we are not utf8
+ fileName = Glib::filename_to_utf8(fileName);
+
+ //Fill in the template
+ /* FIXME: Do proper XML quoting for fileName. */
+ gchar *xmlBuffer = g_strdup_printf(xformat,
+ previewWidth, previewHeight,
+ imgX, imgY, scaledImgWidth, scaledImgHeight,
+ fileName.c_str(),
+ rectX, rectY, rectWidth, rectHeight,
+ imgWidth, imgHeight);
+
+ //g_message("%s\n", xmlBuffer);
+
+ //now show it!
+ setFromMem(xmlBuffer);
+ g_free(xmlBuffer);
+}
+
+
+
+void SVGPreview::showNoPreview()
+{
+ //Are we already showing it?
+ if (showingNoPreview)
+ return;
+
+ //Arbitrary size of svg doc -- rather 'portrait' shaped
+ gint previewWidth = 300;
+ gint previewHeight = 600;
+
+ //Our template. Modify to taste
+ gchar const *xformat =
+ "<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n"
+ "<svg\n"
+ "xmlns=\"http://www.w3.org/2000/svg\"\n"
+ "xmlns:xlink=\"http://www.w3.org/1999/xlink\"\n"
+ "width=\"%d\" height=\"%d\">\n" //# VALUES HERE
+ "<g transform=\"translate(-190,24.27184)\" style=\"opacity:0.12\">\n"
+ "<path\n"
+ "style=\"font-size:12;fill:#ffffff;fill-rule:evenodd;stroke:#000000;stroke-width:0.936193pt\"\n"
+ "d=\"M 397.64309 320.25301 L 280.39197 282.517 L 250.74227 124.83447 L 345.08225 "
+ "29.146783 L 393.59996 46.667064 L 483.89679 135.61619 L 397.64309 320.25301 z \"\n"
+ "id=\"whiteSpace\" />\n"
+ "<path\n"
+ "style=\"font-size:12;fill-rule:evenodd;stroke-width:1pt;fill:#000000;fill-opacity:1\"\n"
+ "d=\"M 476.95792 339.17168 C 495.78197 342.93607 499.54842 356.11361 495.78197 359.87802 "
+ "C 492.01856 363.6434 482.6065 367.40781 475.07663 361.76014 C 467.54478 "
+ "356.11361 467.54478 342.93607 476.95792 339.17168 z \"\n"
+ "id=\"droplet01\" />\n"
+ "<path\n"
+ "style=\"font-size:12;fill-rule:evenodd;stroke-width:1pt;fill:#000000;fill-opacity:1\"\n"
+ "d=\"M 286.46194 340.42914 C 284.6277 340.91835 269.30405 327.71337 257.16909 333.8338 "
+ "C 245.03722 339.95336 236.89276 353.65666 248.22676 359.27982 C 259.56184 364.90298 "
+ "267.66433 358.41867 277.60113 351.44119 C 287.53903 344.46477 "
+ "287.18046 343.1206 286.46194 340.42914 z \"\n"
+ "id=\"droplet02\" />\n"
+ "<path\n"
+ "style=\"font-size:12;fill-rule:evenodd;stroke-width:1pt;fill:#000000;fill-opacity:1\"\n"
+ "d=\"M 510.35756 306.92856 C 520.59494 304.36879 544.24333 306.92856 540.47688 321.98634 "
+ "C 536.71354 337.04806 504.71297 331.39827 484.00371 323.87156 C 482.12141 "
+ "308.81083 505.53237 308.13423 510.35756 306.92856 z \"\n"
+ "id=\"droplet03\" />\n"
+ "<path\n"
+ "style=\"font-size:12;fill-rule:evenodd;stroke-width:1pt;fill:#000000;fill-opacity:1\"\n"
+ "d=\"M 359.2403 21.362537 C 347.92693 21.362537 336.6347 25.683095 327.96556 34.35223 "
+ "L 173.87387 188.41466 C 165.37697 196.9114 161.1116 207.95813 160.94269 219.04577 "
+ "L 160.88418 219.04577 C 160.88418 219.08524 160.94076 219.12322 160.94269 219.16279 "
+ "C 160.94033 219.34888 160.88418 219.53256 160.88418 219.71865 L 161.14748 219.71865 "
+ "C 164.0966 230.93917 240.29699 245.24198 248.79866 253.74346 C 261.63771 266.58263 "
+ "199.5652 276.01151 212.4041 288.85074 C 225.24316 301.68979 289.99433 313.6933 302.8346 "
+ "326.53254 C 315.67368 339.37161 276.5961 353.04289 289.43532 365.88196 C 302.27439 "
+ "378.72118 345.40201 362.67257 337.5908 396.16198 C 354.92909 413.50026 391.10302 "
+ "405.2208 415.32417 387.88252 C 428.16323 375.04345 390.6948 376.17577 403.53397 "
+ "363.33668 C 416.37304 350.49745 448.78128 350.4282 476.08902 319.71589 C 465.09739 "
+ "302.62116 429.10801 295.34136 441.94719 282.50217 C 454.78625 269.66311 479.74708 "
+ "276.18423 533.60644 251.72479 C 559.89837 239.78398 557.72636 230.71459 557.62567 "
+ "219.71865 C 557.62356 219.48727 557.62567 219.27892 557.62567 219.04577 L 557.56716 "
+ "219.04577 C 557.3983 207.95812 553.10345 196.9114 544.60673 188.41466 L 390.54428 "
+ "34.35223 C 381.87515 25.683095 370.55366 21.362537 359.2403 21.362537 z M 357.92378 "
+ "41.402939 C 362.95327 41.533963 367.01541 45.368018 374.98006 50.530832 L 447.76915 "
+ "104.50827 C 448.56596 105.02498 449.32484 105.564 450.02187 106.11735 C 450.7189 106.67062 "
+ "451.3556 107.25745 451.95277 107.84347 C 452.54997 108.42842 453.09281 109.01553 453.59111 "
+ "109.62808 C 454.08837 110.24052 454.53956 110.86661 454.93688 111.50048 C 455.33532 112.13538 "
+ "455.69164 112.78029 455.9901 113.43137 C 456.28877 114.08363 456.52291 114.75639 456.7215 "
+ "115.42078 C 456.92126 116.08419 457.08982 116.73973 457.18961 117.41019 C 457.28949 "
+ "118.08184 457.33588 118.75535 457.33588 119.42886 L 414.21245 98.598549 L 409.9118 "
+ "131.16055 L 386.18512 120.04324 L 349.55654 144.50131 L 335.54288 96.1703 L 317.4919 "
+ "138.4453 L 267.08369 143.47735 L 267.63956 121.03795 C 267.63956 115.64823 296.69685 "
+ "77.915899 314.39075 68.932902 L 346.77721 45.674327 C 351.55594 42.576634 354.90608 "
+ "41.324327 357.92378 41.402939 z M 290.92738 261.61333 C 313.87149 267.56365 339.40299 "
+ "275.37038 359.88393 275.50997 L 360.76161 284.72563 C 343.2235 282.91785 306.11346 "
+ "274.45012 297.36372 269.98057 L 290.92738 261.61333 z \"\n"
+ "id=\"mountainDroplet\" />\n"
+ "</g> <g transform=\"translate(-20,0)\">\n"
+ "<text xml:space=\"preserve\"\n"
+ "style=\"font-size:32.000000;font-style:normal;font-variant:normal;font-weight:bold;"
+ "font-stretch:normal;fill:#000000;fill-opacity:1.0000000;stroke:none;stroke-width:1.0000000pt;"
+ "stroke-linecap:butt;stroke-linejoin:miter;stroke-opacity:1.0000000;"
+ "font-family:Bitstream Vera Sans;text-anchor:middle;writing-mode:lr\"\n"
+ "x=\"190\" y=\"240\">%s</text></g>\n" //# VALUE HERE
+ "</svg>\n\n";
+
+ //Fill in the template
+ gchar *xmlBuffer = g_strdup_printf(xformat,
+ previewWidth, previewHeight, _("No preview"));
+
+ //g_message("%s\n", xmlBuffer);
+
+ //now show it!
+ setFromMem(xmlBuffer);
+ g_free(xmlBuffer);
+ showingNoPreview = true;
+
+}
+
+
+/**
+ * Inform the user that the svg file is too large to be displayed.
+ * This does not check for sizes of embedded images (yet)
+ */
+void SVGPreview::showTooLarge(long fileLength)
+{
+
+ //Arbitrary size of svg doc -- rather 'portrait' shaped
+ gint previewWidth = 300;
+ gint previewHeight = 600;
+
+ //Our template. Modify to taste
+ gchar const *xformat =
+ "<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n"
+ "<svg\n"
+ "xmlns=\"http://www.w3.org/2000/svg\"\n"
+ "xmlns:xlink=\"http://www.w3.org/1999/xlink\"\n"
+ "width=\"%d\" height=\"%d\">\n" //# VALUES HERE
+ "<g transform=\"translate(-170,24.27184)\" style=\"opacity:0.12\">\n"
+ "<path\n"
+ "style=\"font-size:12;fill:#ffffff;fill-rule:evenodd;stroke:#000000;stroke-width:0.936193pt\"\n"
+ "d=\"M 397.64309 320.25301 L 280.39197 282.517 L 250.74227 124.83447 L 345.08225 "
+ "29.146783 L 393.59996 46.667064 L 483.89679 135.61619 L 397.64309 320.25301 z \"\n"
+ "id=\"whiteSpace\" />\n"
+ "<path\n"
+ "style=\"font-size:12;fill-rule:evenodd;stroke-width:1pt;fill:#000000;fill-opacity:1\"\n"
+ "d=\"M 476.95792 339.17168 C 495.78197 342.93607 499.54842 356.11361 495.78197 359.87802 "
+ "C 492.01856 363.6434 482.6065 367.40781 475.07663 361.76014 C 467.54478 "
+ "356.11361 467.54478 342.93607 476.95792 339.17168 z \"\n"
+ "id=\"droplet01\" />\n"
+ "<path\n"
+ "style=\"font-size:12;fill-rule:evenodd;stroke-width:1pt;fill:#000000;fill-opacity:1\"\n"
+ "d=\"M 286.46194 340.42914 C 284.6277 340.91835 269.30405 327.71337 257.16909 333.8338 "
+ "C 245.03722 339.95336 236.89276 353.65666 248.22676 359.27982 C 259.56184 364.90298 "
+ "267.66433 358.41867 277.60113 351.44119 C 287.53903 344.46477 "
+ "287.18046 343.1206 286.46194 340.42914 z \"\n"
+ "id=\"droplet02\" />\n"
+ "<path\n"
+ "style=\"font-size:12;fill-rule:evenodd;stroke-width:1pt;fill:#000000;fill-opacity:1\"\n"
+ "d=\"M 510.35756 306.92856 C 520.59494 304.36879 544.24333 306.92856 540.47688 321.98634 "
+ "C 536.71354 337.04806 504.71297 331.39827 484.00371 323.87156 C 482.12141 "
+ "308.81083 505.53237 308.13423 510.35756 306.92856 z \"\n"
+ "id=\"droplet03\" />\n"
+ "<path\n"
+ "style=\"font-size:12;fill-rule:evenodd;stroke-width:1pt;fill:#000000;fill-opacity:1\"\n"
+ "d=\"M 359.2403 21.362537 C 347.92693 21.362537 336.6347 25.683095 327.96556 34.35223 "
+ "L 173.87387 188.41466 C 165.37697 196.9114 161.1116 207.95813 160.94269 219.04577 "
+ "L 160.88418 219.04577 C 160.88418 219.08524 160.94076 219.12322 160.94269 219.16279 "
+ "C 160.94033 219.34888 160.88418 219.53256 160.88418 219.71865 L 161.14748 219.71865 "
+ "C 164.0966 230.93917 240.29699 245.24198 248.79866 253.74346 C 261.63771 266.58263 "
+ "199.5652 276.01151 212.4041 288.85074 C 225.24316 301.68979 289.99433 313.6933 302.8346 "
+ "326.53254 C 315.67368 339.37161 276.5961 353.04289 289.43532 365.88196 C 302.27439 "
+ "378.72118 345.40201 362.67257 337.5908 396.16198 C 354.92909 413.50026 391.10302 "
+ "405.2208 415.32417 387.88252 C 428.16323 375.04345 390.6948 376.17577 403.53397 "
+ "363.33668 C 416.37304 350.49745 448.78128 350.4282 476.08902 319.71589 C 465.09739 "
+ "302.62116 429.10801 295.34136 441.94719 282.50217 C 454.78625 269.66311 479.74708 "
+ "276.18423 533.60644 251.72479 C 559.89837 239.78398 557.72636 230.71459 557.62567 "
+ "219.71865 C 557.62356 219.48727 557.62567 219.27892 557.62567 219.04577 L 557.56716 "
+ "219.04577 C 557.3983 207.95812 553.10345 196.9114 544.60673 188.41466 L 390.54428 "
+ "34.35223 C 381.87515 25.683095 370.55366 21.362537 359.2403 21.362537 z M 357.92378 "
+ "41.402939 C 362.95327 41.533963 367.01541 45.368018 374.98006 50.530832 L 447.76915 "
+ "104.50827 C 448.56596 105.02498 449.32484 105.564 450.02187 106.11735 C 450.7189 106.67062 "
+ "451.3556 107.25745 451.95277 107.84347 C 452.54997 108.42842 453.09281 109.01553 453.59111 "
+ "109.62808 C 454.08837 110.24052 454.53956 110.86661 454.93688 111.50048 C 455.33532 112.13538 "
+ "455.69164 112.78029 455.9901 113.43137 C 456.28877 114.08363 456.52291 114.75639 456.7215 "
+ "115.42078 C 456.92126 116.08419 457.08982 116.73973 457.18961 117.41019 C 457.28949 "
+ "118.08184 457.33588 118.75535 457.33588 119.42886 L 414.21245 98.598549 L 409.9118 "
+ "131.16055 L 386.18512 120.04324 L 349.55654 144.50131 L 335.54288 96.1703 L 317.4919 "
+ "138.4453 L 267.08369 143.47735 L 267.63956 121.03795 C 267.63956 115.64823 296.69685 "
+ "77.915899 314.39075 68.932902 L 346.77721 45.674327 C 351.55594 42.576634 354.90608 "
+ "41.324327 357.92378 41.402939 z M 290.92738 261.61333 C 313.87149 267.56365 339.40299 "
+ "275.37038 359.88393 275.50997 L 360.76161 284.72563 C 343.2235 282.91785 306.11346 "
+ "274.45012 297.36372 269.98057 L 290.92738 261.61333 z \"\n"
+ "id=\"mountainDroplet\" />\n"
+ "</g>\n"
+ "<text xml:space=\"preserve\"\n"
+ "style=\"font-size:32.000000;font-style:normal;font-variant:normal;font-weight:bold;"
+ "font-stretch:normal;fill:#000000;fill-opacity:1.0000000;stroke:none;stroke-width:1.0000000pt;"
+ "stroke-linecap:butt;stroke-linejoin:miter;stroke-opacity:1.0000000;"
+ "font-family:Bitstream Vera Sans;text-anchor:middle;writing-mode:lr\"\n"
+ "x=\"170\" y=\"215\">%5.1f MB</text>\n" //# VALUE HERE
+ "<text xml:space=\"preserve\"\n"
+ "style=\"font-size:24.000000;font-style:normal;font-variant:normal;font-weight:bold;"
+ "font-stretch:normal;fill:#000000;fill-opacity:1.0000000;stroke:none;stroke-width:1.0000000pt;"
+ "stroke-linecap:butt;stroke-linejoin:miter;stroke-opacity:1.0000000;"
+ "font-family:Bitstream Vera Sans;text-anchor:middle;writing-mode:lr\"\n"
+ "x=\"180\" y=\"245\">%s</text>\n" //# VALUE HERE
+ "</svg>\n\n";
+
+ //Fill in the template
+ double floatFileLength = ((double)fileLength) / 1048576.0;
+ //printf("%ld %f\n", fileLength, floatFileLength);
+ gchar *xmlBuffer = g_strdup_printf(xformat,
+ previewWidth, previewHeight, floatFileLength,
+ _("too large for preview"));
+
+ //g_message("%s\n", xmlBuffer);
+
+ //now show it!
+ setFromMem(xmlBuffer);
+ g_free(xmlBuffer);
+
+}
+
+
+/**
+ * Return true if the string ends with the given suffix
+ */
+static bool
+hasSuffix(Glib::ustring &str, Glib::ustring &ext)
+{
+ int strLen = str.length();
+ int extLen = ext.length();
+ if (extLen > strLen)
+ return false;
+ int strpos = strLen-1;
+ for (int extpos = extLen-1 ; extpos>=0 ; extpos--, strpos--)
+ {
+ Glib::ustring::value_type ch = str[strpos];
+ if (ch != ext[extpos])
+ {
+ if ( ((ch & 0xff80) != 0) ||
+ static_cast<Glib::ustring::value_type>( g_ascii_tolower( static_cast<gchar>(0x07f & ch) ) ) != ext[extpos] )
+ {
+ return false;
+ }
+ }
+ }
+ return true;
+}
+
+
+/**
+ * Return true if the image is loadable by Gdk, else false
+ */
+static bool
+isValidImageFile(Glib::ustring &fileName)
+{
+ std::vector<Gdk::PixbufFormat>formats = Gdk::Pixbuf::get_formats();
+ for (unsigned int i=0; i<formats.size(); i++)
+ {
+ Gdk::PixbufFormat format = formats[i];
+ std::vector<Glib::ustring>extensions = format.get_extensions();
+ for (unsigned int j=0; j<extensions.size(); j++)
+ {
+ Glib::ustring ext = extensions[j];
+ if (hasSuffix(fileName, ext))
+ return true;
+ }
+ }
+ return false;
+}
+
+bool SVGPreview::set(Glib::ustring &fileName, int dialogType)
+{
+
+ if (!Glib::file_test(fileName, Glib::FILE_TEST_EXISTS))
+ return false;
+
+ //g_message("fname:%s", fileName.c_str());
+
+ if (Glib::file_test(fileName, Glib::FILE_TEST_IS_DIR)) {
+ showNoPreview();
+ return false;
+ }
+
+ if (Glib::file_test(fileName, Glib::FILE_TEST_IS_REGULAR))
+ {
+ Glib::ustring fileNameUtf8 = Glib::filename_to_utf8(fileName);
+ gchar *fName = (gchar *)fileNameUtf8.c_str();
+ struct stat info;
+ if (g_stat(fName, &info))
+ {
+ g_warning("SVGPreview::set() : %s : %s",
+ fName, strerror(errno));
+ return FALSE;
+ }
+ long fileLen = info.st_size;
+ if (fileLen > 0x150000L)
+ {
+ showingNoPreview = false;
+ showTooLarge(fileLen);
+ return FALSE;
+ }
+ }
+
+ Glib::ustring svg = ".svg";
+ Glib::ustring svgz = ".svgz";
+
+ if ((dialogType == SVG_TYPES || dialogType == IMPORT_TYPES) &&
+ (hasSuffix(fileName, svg) || hasSuffix(fileName, svgz) )
+ ) {
+ bool retval = setFileName(fileName);
+ showingNoPreview = false;
+ return retval;
+ } else if (isValidImageFile(fileName)) {
+ showImage(fileName);
+ showingNoPreview = false;
+ return true;
+ } else {
+ showNoPreview();
+ return false;
+ }
+}
+
+
+SVGPreview::SVGPreview()
+{
+ if (!INKSCAPE)
+ inkscape_application_init("",false);
+ document = NULL;
+ viewerGtk = NULL;
+ set_size_request(150,150);
+ showingNoPreview = false;
+}
+
+SVGPreview::~SVGPreview()
+{
+
+}
+
+
+/*#########################################################################
+### F I L E D I A L O G B A S E C L A S S
+#########################################################################*/
+
+void FileDialogBaseGtk::internalSetup()
+{
+ bool enablePreview =
+ (bool)prefs_get_int_attribute( preferenceBase.c_str(),
+ "enable_preview", 1 );
+
+ previewCheckbox.set_label( Glib::ustring(_("Enable preview")) );
+ previewCheckbox.set_active( enablePreview );
+
+ previewCheckbox.signal_toggled().connect(
+ sigc::mem_fun(*this, &FileDialogBaseGtk::_previewEnabledCB) );
+
+ //Catch selection-changed events, so we can adjust the text widget
+ signal_update_preview().connect(
+ sigc::mem_fun(*this, &FileDialogBaseGtk::_updatePreviewCallback) );
+
+ //###### Add a preview widget
+ set_preview_widget(svgPreview);
+ set_preview_widget_active( enablePreview );
+ set_use_preview_label (false);
+
+}
+
+
+void FileDialogBaseGtk::cleanup( bool showConfirmed )
+{
+ if ( showConfirmed )
+ prefs_set_int_attribute( preferenceBase.c_str(),
+ "enable_preview", previewCheckbox.get_active() );
+}
+
+
+void FileDialogBaseGtk::_previewEnabledCB()
+{
+ bool enabled = previewCheckbox.get_active();
+ set_preview_widget_active(enabled);
+ if ( enabled ) {
+ _updatePreviewCallback();
+ }
+}
+
+
+
+/**
+ * Callback for checking if the preview needs to be redrawn
+ */
+void FileDialogBaseGtk::_updatePreviewCallback()
+{
+ Glib::ustring fileName = get_preview_filename();
+
+#ifdef WITH_GNOME_VFS
+ if ( fileName.empty() && gnome_vfs_initialized() ) {
+ fileName = get_preview_uri();
+ }
+#endif
+
+ if (fileName.empty()) {
+ return;
+ }
+
+ svgPreview.set(fileName, dialogType);
+}
+
+
+/*#########################################################################
+### F I L E O P E N
+#########################################################################*/
+
+/**
+ * Constructor. Not called directly. Use the factory.
+ */
+FileOpenDialogImplGtk::FileOpenDialogImplGtk(Gtk::Window& parentWindow,
+ const Glib::ustring &dir,
+ FileDialogType fileTypes,
+ const Glib::ustring &title) :
+ FileDialogBaseGtk(parentWindow, title, fileTypes, "dialogs.open")
+{
+
+
+ /* One file at a time */
+ /* And also Multiple Files */
+ set_select_multiple(true);
+
+#ifdef WITH_GNOME_VFS
+ if (gnome_vfs_initialized()) {
+ set_local_only(false);
+ }
+#endif
+
+ /* Initalize to Autodetect */
+ extension = NULL;
+ /* No filename to start out with */
+ myFilename = "";
+
+ /* Set our dialog type (open, import, etc...)*/
+ dialogType = fileTypes;
+
+
+ /* Set the pwd and/or the filename */
+ if (dir.size() > 0)
+ {
+ Glib::ustring udir(dir);
+ Glib::ustring::size_type len = udir.length();
+ // leaving a trailing backslash on the directory name leads to the infamous
+ // double-directory bug on win32
+ if (len != 0 && udir[len - 1] == '\\') udir.erase(len - 1);
+ set_current_folder(udir.c_str());
+ }
+
+
+ set_extra_widget( previewCheckbox );
+
+
+ //###### Add the file types menu
+ createFilterMenu();
+
+ add_button(Gtk::Stock::CANCEL, Gtk::RESPONSE_CANCEL);
+ set_default(*add_button(Gtk::Stock::OPEN, Gtk::RESPONSE_OK));
+
+ //###### Allow easy access to our examples folder
+ if(Inkscape::IO::file_test(INKSCAPE_EXAMPLESDIR,
+ (GFileTest)(G_FILE_TEST_EXISTS | G_FILE_TEST_IS_DIR)))
+ {
+ add_shortcut_folder(INKSCAPE_EXAMPLESDIR);
+ }
+}
+
+/**
+ * Destructor
+ */
+FileOpenDialogImplGtk::~FileOpenDialogImplGtk()
+{
+
+}
+
+void FileOpenDialogImplGtk::createFilterMenu()
+{
+ Gtk::FileFilter allInkscapeFilter;
+ allInkscapeFilter.set_name(_("All Inkscape Files"));
+ extensionMap[Glib::ustring(_("All Inkscape Files"))]=NULL;
+ add_filter(allInkscapeFilter);
+
+ Gtk::FileFilter allFilter;
+ allFilter.set_name(_("All Files"));
+ extensionMap[Glib::ustring(_("All Files"))]=NULL;
+ allFilter.add_pattern("*");
+ add_filter(allFilter);
+
+ Gtk::FileFilter allImageFilter;
+ allImageFilter.set_name(_("All Images"));
+ extensionMap[Glib::ustring(_("All Images"))]=NULL;
+ add_filter(allImageFilter);
+
+ //patterns added dynamically below
+ Inkscape::Extension::DB::InputList extension_list;
+ Inkscape::Extension::db.get_input_list(extension_list);
+
+ for (Inkscape::Extension::DB::InputList::iterator current_item = extension_list.begin();
+ current_item != extension_list.end(); current_item++)
+ {
+ Inkscape::Extension::Input * imod = *current_item;
+
+ // FIXME: would be nice to grey them out instead of not listing them
+ if (imod->deactivated()) continue;
+
+ Glib::ustring upattern("*");
+ Glib::ustring extension = imod->get_extension();
+ fileDialogExtensionToPattern(upattern, extension);
+
+ Gtk::FileFilter filter;
+ Glib::ustring uname(_(imod->get_filetypename()));
+ filter.set_name(uname);
+ filter.add_pattern(upattern);
+ add_filter(filter);
+ extensionMap[uname] = imod;
+
+ //g_message("ext %s:%s '%s'\n", ioext->name, ioext->mimetype, upattern.c_str());
+ allInkscapeFilter.add_pattern(upattern);
+ if ( strncmp("image", imod->get_mimetype(), 5)==0 )
+ allImageFilter.add_pattern(upattern);
+ }
+
+ return;
+}
+
+/**
+ * Show this dialog modally. Return true if user hits [OK]
+ */
+bool
+FileOpenDialogImplGtk::show()
+{
+ Glib::ustring s = Glib::filename_to_utf8 (get_current_folder());
+ if (s.length() == 0)
+ s = getcwd (NULL, 0);
+ set_current_folder(Glib::filename_from_utf8(s)); //hack to force initial dir listing
+ set_modal (TRUE); //Window
+ sp_transientize((GtkWidget *)gobj()); //Make transient
+ gint b = run(); //Dialog
+ svgPreview.showNoPreview();
+ hide();
+
+ if (b == Gtk::RESPONSE_OK)
+ {
+ //This is a hack, to avoid the warning messages that
+ //Gtk::FileChooser::get_filter() returns
+ //should be: Gtk::FileFilter *filter = get_filter();
+ GtkFileChooser *gtkFileChooser = Gtk::FileChooser::gobj();
+ GtkFileFilter *filter = gtk_file_chooser_get_filter(gtkFileChooser);
+ if (filter)
+ {
+ //Get which extension was chosen, if any
+ extension = extensionMap[gtk_file_filter_get_name(filter)];
+ }
+ myFilename = get_filename();
+#ifdef WITH_GNOME_VFS
+ if (myFilename.empty() && gnome_vfs_initialized())
+ myFilename = get_uri();
+#endif
+ cleanup( true );
+ return TRUE;
+ }
+ else
+ {
+ cleanup( false );
+ return FALSE;
+ }
+}
+
+
+
+
+/**
+ * Get the file extension type that was selected by the user. Valid after an [OK]
+ */
+Inkscape::Extension::Extension *
+FileOpenDialogImplGtk::getSelectionType()
+{
+ return extension;
+}
+
+
+/**
+ * Get the file name chosen by the user. Valid after an [OK]
+ */
+Glib::ustring
+FileOpenDialogImplGtk::getFilename (void)
+{
+ return g_strdup(myFilename.c_str());
+}
+
+
+/**
+ * To Get Multiple filenames selected at-once.
+ */
+std::vector<Glib::ustring>FileOpenDialogImplGtk::getFilenames()
+{
+ std::vector<Glib::ustring> result = get_filenames();
+#ifdef WITH_GNOME_VFS
+ if (result.empty() && gnome_vfs_initialized())
+ result = get_uris();
+#endif
+ return result;
+}
+
+
+
+
+
+
+//########################################################################
+//# F I L E S A V E
+//########################################################################
+
+/**
+ * Constructor
+ */
+FileSaveDialogImplGtk::FileSaveDialogImplGtk(Gtk::Window &parentWindow,
+ const Glib::ustring &dir,
+ FileDialogType fileTypes,
+ const Glib::ustring &title,
+ const Glib::ustring &default_key) :
+ FileDialogBaseGtk(parentWindow, title, Gtk::FILE_CHOOSER_ACTION_SAVE, fileTypes, "dialogs.save_as")
+{
+ /* One file at a time */
+ set_select_multiple(false);
+
+#ifdef WITH_GNOME_VFS
+ if (gnome_vfs_initialized()) {
+ set_local_only(false);
+ }
+#endif
+
+ /* Initalize to Autodetect */
+ extension = NULL;
+ /* No filename to start out with */
+ myFilename = "";
+
+ /* Set our dialog type (save, export, etc...)*/
+ dialogType = fileTypes;
+
+ /* Set the pwd and/or the filename */
+ if (dir.size() > 0)
+ {
+ Glib::ustring udir(dir);
+ Glib::ustring::size_type len = udir.length();
+ // leaving a trailing backslash on the directory name leads to the infamous
+ // double-directory bug on win32
+ if (len != 0 && udir[len - 1] == '\\') udir.erase(len - 1);
+ myFilename = udir;
+ }
+
+ //###### Add the file types menu
+ //createFilterMenu();
+
+ //###### Do we want the .xxx extension automatically added?
+ fileTypeCheckbox.set_label(Glib::ustring(_("Append filename extension automatically")));
+ fileTypeCheckbox.set_active( (bool)prefs_get_int_attribute("dialogs.save_as",
+ "append_extension", 1) );
+
+ createFileTypeMenu();
+ fileTypeComboBox.set_size_request(200,40);
+ fileTypeComboBox.signal_changed().connect(
+ sigc::mem_fun(*this, &FileSaveDialogImplGtk::fileTypeChangedCallback) );
+
+
+ childBox.pack_start( checksBox );
+ childBox.pack_end( fileTypeComboBox );
+ checksBox.pack_start( fileTypeCheckbox );
+ checksBox.pack_start( previewCheckbox );
+
+ set_extra_widget( childBox );
+
+ //Let's do some customization
+ fileNameEntry = NULL;
+ Gtk::Container *cont = get_toplevel();
+ std::vector<Gtk::Entry *> entries;
+ findEntryWidgets(cont, entries);
+ //g_message("Found %d entry widgets\n", entries.size());
+ if (entries.size() >=1 )
+ {
+ //Catch when user hits [return] on the text field
+ fileNameEntry = entries[0];
+ fileNameEntry->signal_activate().connect(
+ sigc::mem_fun(*this, &FileSaveDialogImplGtk::fileNameEntryChangedCallback) );
+ }
+
+ //Let's do more customization
+ std::vector<Gtk::Expander *> expanders;
+ findExpanderWidgets(cont, expanders);
+ //g_message("Found %d expander widgets\n", expanders.size());
+ if (expanders.size() >=1 )
+ {
+ //Always show the file list
+ Gtk::Expander *expander = expanders[0];
+ expander->set_expanded(true);
+ }
+
+
+ //if (extension == NULL)
+ // checkbox.set_sensitive(FALSE);
+
+ add_button(Gtk::Stock::CANCEL, Gtk::RESPONSE_CANCEL);
+ set_default(*add_button(Gtk::Stock::SAVE, Gtk::RESPONSE_OK));
+
+ show_all_children();
+}
+
+/**
+ * Destructor
+ */
+FileSaveDialogImplGtk::~FileSaveDialogImplGtk()
+{
+}
+
+/**
+ * Callback for fileNameEntry widget
+ */
+void FileSaveDialogImplGtk::fileNameEntryChangedCallback()
+{
+ if (!fileNameEntry)
+ return;
+
+ Glib::ustring fileName = fileNameEntry->get_text();
+ if (!Glib::get_charset()) //If we are not utf8
+ fileName = Glib::filename_to_utf8(fileName);
+
+ //g_message("User hit return. Text is '%s'\n", fileName.c_str());
+
+ if (!Glib::path_is_absolute(fileName)) {
+ //try appending to the current path
+ // not this way: fileName = get_current_folder() + "/" + fileName;
+ std::vector<Glib::ustring> pathSegments;
+ pathSegments.push_back( get_current_folder() );
+ pathSegments.push_back( fileName );
+ fileName = Glib::build_filename(pathSegments);
+ }
+
+ //g_message("path:'%s'\n", fileName.c_str());
+
+ if (Glib::file_test(fileName, Glib::FILE_TEST_IS_DIR)) {
+ set_current_folder(fileName);
+ } else if (/*Glib::file_test(fileName, Glib::FILE_TEST_IS_REGULAR)*/1) {
+ //dialog with either (1) select a regular file or (2) cd to dir
+ //simulate an 'OK'
+ set_filename(fileName);
+ response(Gtk::RESPONSE_OK);
+ }
+}
+
+
+
+/**
+ * Callback for fileNameEntry widget
+ */
+void FileSaveDialogImplGtk::fileTypeChangedCallback()
+{
+ int sel = fileTypeComboBox.get_active_row_number();
+ if (sel<0 || sel >= (int)fileTypes.size())
+ return;
+ FileType type = fileTypes[sel];
+ //g_message("selected: %s\n", type.name.c_str());
+
+ extension = type.extension;
+ Gtk::FileFilter filter;
+ filter.add_pattern(type.pattern);
+ set_filter(filter);
+
+ updateNameAndExtension();
+}
+
+
+
+void FileSaveDialogImplGtk::createFileTypeMenu()
+{
+ Inkscape::Extension::DB::OutputList extension_list;
+ Inkscape::Extension::db.get_output_list(extension_list);
+ knownExtensions.clear();
+
+ for (Inkscape::Extension::DB::OutputList::iterator current_item = extension_list.begin();
+ current_item != extension_list.end(); current_item++)
+ {
+ Inkscape::Extension::Output * omod = *current_item;
+
+ // FIXME: would be nice to grey them out instead of not listing them
+ if (omod->deactivated()) continue;
+
+ FileType type;
+ type.name = (_(omod->get_filetypename()));
+ type.pattern = "*";
+ Glib::ustring extension = omod->get_extension();
+ knownExtensions.insert( extension.casefold() );
+ fileDialogExtensionToPattern (type.pattern, extension);
+ type.extension= omod;
+ fileTypeComboBox.append_text(type.name);
+ fileTypes.push_back(type);
+ }
+
+ //#Let user choose
+ FileType guessType;
+ guessType.name = _("Guess from extension");
+ guessType.pattern = "*";
+ guessType.extension = NULL;
+ fileTypeComboBox.append_text(guessType.name);
+ fileTypes.push_back(guessType);
+
+
+ fileTypeComboBox.set_active(0);
+ fileTypeChangedCallback(); //call at least once to set the filter
+}
+
+
+
+
+
+/**
+ * Show this dialog modally. Return true if user hits [OK]
+ */
+bool
+FileSaveDialogImplGtk::show()
+{
+ change_path(myFilename);
+ set_modal (TRUE); //Window
+ sp_transientize((GtkWidget *)gobj()); //Make transient
+ gint b = run(); //Dialog
+ svgPreview.showNoPreview();
+ set_preview_widget_active(false);
+ hide();
+
+ if (b == Gtk::RESPONSE_OK)
+ {
+ updateNameAndExtension();
+
+ // Store changes of the "Append filename automatically" checkbox back to preferences.
+ prefs_set_int_attribute("dialogs.save_as", "append_extension", fileTypeCheckbox.get_active());
+
+ // Store the last used save-as filetype to preferences.
+ prefs_set_string_attribute("dialogs.save_as", "default",
+ ( extension != NULL ? extension->get_id() : "" ));
+
+ cleanup( true );
+
+ return TRUE;
+ }
+ else
+ {
+ cleanup( false );
+
+ return FALSE;
+ }
+}
+
+
+/**
+ * Get the file extension type that was selected by the user. Valid after an [OK]
+ */
+Inkscape::Extension::Extension *
+FileSaveDialogImplGtk::getSelectionType()
+{
+ return extension;
+}
+
+void FileSaveDialogImplGtk::setSelectionType( Inkscape::Extension::Extension * key )
+{
+ // If no pointer to extension is passed in, look up based on filename extension.
+ if ( !key ) {
+ // Not quite UTF-8 here.
+ gchar *filenameLower = g_ascii_strdown(myFilename.c_str(), -1);
+ for ( int i = 0; !key && (i < (int)fileTypes.size()); i++ ) {
+ Inkscape::Extension::Output *ext = dynamic_cast<Inkscape::Extension::Output*>(fileTypes[i].extension);
+ if ( ext && ext->get_extension() ) {
+ gchar *extensionLower = g_ascii_strdown( ext->get_extension(), -1 );
+ if ( g_str_has_suffix(filenameLower, extensionLower) ) {
+ key = fileTypes[i].extension;
+ }
+ g_free(extensionLower);
+ }
+ }
+ g_free(filenameLower);
+ }
+
+ // Ensure the proper entry in the combo box is selected.
+ if ( key ) {
+ extension = key;
+ gchar const * extensionID = extension->get_id();
+ if ( extensionID ) {
+ for ( int i = 0; i < (int)fileTypes.size(); i++ ) {
+ Inkscape::Extension::Extension *ext = fileTypes[i].extension;
+ if ( ext ) {
+ gchar const * id = ext->get_id();
+ if ( id && ( strcmp(extensionID, id) == 0) ) {
+ int oldSel = fileTypeComboBox.get_active_row_number();
+ if ( i != oldSel ) {
+ fileTypeComboBox.set_active(i);
+ }
+ break;
+ }
+ }
+ }
+ }
+ }
+}
+
+
+/**
+ * Get the file name chosen by the user. Valid after an [OK]
+ */
+Glib::ustring
+FileSaveDialogImplGtk::getFilename()
+{
+ return myFilename;
+}
+
+
+void
+FileSaveDialogImplGtk::change_title(const Glib::ustring& title)
+{
+ this->set_title(title);
+}
+
+/**
+ * Change the default save path location.
+ */
+void
+FileSaveDialogImplGtk::change_path(const Glib::ustring& path)
+{
+ myFilename = path;
+ if (Glib::file_test(myFilename, Glib::FILE_TEST_IS_DIR)) {
+ //fprintf(stderr,"set_current_folder(%s)\n",myFilename.c_str());
+ set_current_folder(myFilename);
+ } else {
+ //fprintf(stderr,"set_filename(%s)\n",myFilename.c_str());
+ if ( Glib::file_test( myFilename, Glib::FILE_TEST_EXISTS ) ) {
+ set_filename(myFilename);
+ } else {
+ std::string dirName = Glib::path_get_dirname( myFilename );
+ if ( dirName != get_current_folder() ) {
+ set_current_folder(dirName);
+ }
+ }
+ Glib::ustring basename = Glib::path_get_basename(myFilename);
+ //fprintf(stderr,"set_current_name(%s)\n",basename.c_str());
+ try {
+ set_current_name( Glib::filename_to_utf8(basename) );
+ } catch ( Glib::ConvertError& e ) {
+ g_warning( "Error converting save filename to UTF-8." );
+ // try a fallback.
+ set_current_name( basename );
+ }
+ }
+}
+
+void FileSaveDialogImplGtk::updateNameAndExtension()
+{
+ // Pick up any changes the user has typed in.
+ Glib::ustring tmp = get_filename();
+#ifdef WITH_GNOME_VFS
+ if ( tmp.empty() && gnome_vfs_initialized() ) {
+ tmp = get_uri();
+ }
+#endif
+ if ( !tmp.empty() ) {
+ myFilename = tmp;
+ }
+
+ Inkscape::Extension::Output* newOut = extension ? dynamic_cast<Inkscape::Extension::Output*>(extension) : 0;
+ if ( fileTypeCheckbox.get_active() && newOut ) {
+ try {
+ bool appendExtension = true;
+ Glib::ustring utf8Name = Glib::filename_to_utf8( myFilename );
+ Glib::ustring::size_type pos = utf8Name.rfind('.');
+ if ( pos != Glib::ustring::npos ) {
+ Glib::ustring trail = utf8Name.substr( pos );
+ Glib::ustring foldedTrail = trail.casefold();
+ if ( (trail == ".")
+ | (foldedTrail != Glib::ustring( newOut->get_extension() ).casefold()
+ && ( knownExtensions.find(foldedTrail) != knownExtensions.end() ) ) ) {
+ utf8Name = utf8Name.erase( pos );
+ } else {
+ appendExtension = false;
+ }
+ }
+
+ if (appendExtension) {
+ utf8Name = utf8Name + newOut->get_extension();
+ myFilename = Glib::filename_from_utf8( utf8Name );
+ change_path(myFilename);
+ }
+ } catch ( Glib::ConvertError& e ) {
+ // ignore
+ }
+ }
+}
+
+
+//########################################################################
+//# F I L E E X P O R T
+//########################################################################
+
+/**
+ * Callback for fileNameEntry widget
+ */
+void FileExportDialogImpl::fileNameEntryChangedCallback()
+{
+ if (!fileNameEntry)
+ return;
+
+ Glib::ustring fileName = fileNameEntry->get_text();
+ if (!Glib::get_charset()) //If we are not utf8
+ fileName = Glib::filename_to_utf8(fileName);
+
+ //g_message("User hit return. Text is '%s'\n", fileName.c_str());
+
+ if (!Glib::path_is_absolute(fileName)) {
+ //try appending to the current path
+ // not this way: fileName = get_current_folder() + "/" + fileName;
+ std::vector<Glib::ustring> pathSegments;
+ pathSegments.push_back( get_current_folder() );
+ pathSegments.push_back( fileName );
+ fileName = Glib::build_filename(pathSegments);
+ }
+
+ //g_message("path:'%s'\n", fileName.c_str());
+
+ if (Glib::file_test(fileName, Glib::FILE_TEST_IS_DIR)) {
+ set_current_folder(fileName);
+ } else if (/*Glib::file_test(fileName, Glib::FILE_TEST_IS_REGULAR)*/1) {
+ //dialog with either (1) select a regular file or (2) cd to dir
+ //simulate an 'OK'
+ set_filename(fileName);
+ response(Gtk::RESPONSE_OK);
+ }
+}
+
+
+
+/**
+ * Callback for fileNameEntry widget
+ */
+void FileExportDialogImpl::fileTypeChangedCallback()
+{
+ int sel = fileTypeComboBox.get_active_row_number();
+ if (sel<0 || sel >= (int)fileTypes.size())
+ return;
+ FileType type = fileTypes[sel];
+ //g_message("selected: %s\n", type.name.c_str());
+ Gtk::FileFilter filter;
+ filter.add_pattern(type.pattern);
+ set_filter(filter);
+}
+
+
+
+void FileExportDialogImpl::createFileTypeMenu()
+{
+ Inkscape::Extension::DB::OutputList extension_list;
+ Inkscape::Extension::db.get_output_list(extension_list);
+
+ for (Inkscape::Extension::DB::OutputList::iterator current_item = extension_list.begin();
+ current_item != extension_list.end(); current_item++)
+ {
+ Inkscape::Extension::Output * omod = *current_item;
+
+ // FIXME: would be nice to grey them out instead of not listing them
+ if (omod->deactivated()) continue;
+
+ FileType type;
+ type.name = (_(omod->get_filetypename()));
+ type.pattern = "*";
+ Glib::ustring extension = omod->get_extension();
+ fileDialogExtensionToPattern (type.pattern, extension);
+ type.extension= omod;
+ fileTypeComboBox.append_text(type.name);
+ fileTypes.push_back(type);
+ }
+
+ //#Let user choose
+ FileType guessType;
+ guessType.name = _("Guess from extension");
+ guessType.pattern = "*";
+ guessType.extension = NULL;
+ fileTypeComboBox.append_text(guessType.name);
+ fileTypes.push_back(guessType);
+
+
+ fileTypeComboBox.set_active(0);
+ fileTypeChangedCallback(); //call at least once to set the filter
+}
+
+
+/**
+ * Constructor
+ */
+FileExportDialogImpl::FileExportDialogImpl(Gtk::Window& parentWindow,
+ const Glib::ustring &dir,
+ FileDialogType fileTypes,
+ const Glib::ustring &title,
+ const Glib::ustring &default_key) :
+ FileDialogBaseGtk(parentWindow, title, Gtk::FILE_CHOOSER_ACTION_SAVE, fileTypes, "dialogs.export"),
+ sourceX0Spinner("X0", _("Left edge of source")),
+ sourceY0Spinner("Y0", _("Top edge of source")),
+ sourceX1Spinner("X1", _("Right edge of source")),
+ sourceY1Spinner("Y1", _("Bottom edge of source")),
+ sourceWidthSpinner("Width", _("Source width")),
+ sourceHeightSpinner("Height", _("Source height")),
+ destWidthSpinner("Width", _("Destination width")),
+ destHeightSpinner("Height", _("Destination height")),
+ destDPISpinner("DPI", _("Resolution (dots per inch)"))
+{
+ append_extension = (bool)prefs_get_int_attribute("dialogs.save_as", "append_extension", 1);
+
+ /* One file at a time */
+ set_select_multiple(false);
+
+#ifdef WITH_GNOME_VFS
+ if (gnome_vfs_initialized()) {
+ set_local_only(false);
+ }
+#endif
+
+ /* Initalize to Autodetect */
+ extension = NULL;
+ /* No filename to start out with */
+ myFilename = "";
+
+ /* Set our dialog type (save, export, etc...)*/
+ dialogType = fileTypes;
+
+ /* Set the pwd and/or the filename */
+ if (dir.size()>0)
+ {
+ Glib::ustring udir(dir);
+ Glib::ustring::size_type len = udir.length();
+ // leaving a trailing backslash on the directory name leads to the infamous
+ // double-directory bug on win32
+ if (len != 0 && udir[len - 1] == '\\') udir.erase(len - 1);
+ set_current_folder(udir.c_str());
+ }
+
+ //#########################################
+ //## EXTRA WIDGET -- SOURCE SIDE
+ //#########################################
+
+ //##### Export options buttons/spinners, etc
+ documentButton.set_label(_("Document"));
+ scopeBox.pack_start(documentButton);
+ scopeGroup = documentButton.get_group();
+
+ pageButton.set_label(_("Page"));
+ pageButton.set_group(scopeGroup);
+ scopeBox.pack_start(pageButton);
+
+ selectionButton.set_label(_("Selection"));
+ selectionButton.set_group(scopeGroup);
+ scopeBox.pack_start(selectionButton);
+
+ customButton.set_label(_("Custom"));
+ customButton.set_group(scopeGroup);
+ scopeBox.pack_start(customButton);
+
+ sourceBox.pack_start(scopeBox);
+
+
+
+ //dimension buttons
+ sourceTable.resize(3,3);
+ sourceTable.attach(sourceX0Spinner, 0,1,0,1);
+ sourceTable.attach(sourceY0Spinner, 1,2,0,1);
+ sourceUnitsSpinner.setUnitType(UNIT_TYPE_LINEAR);
+ sourceTable.attach(sourceUnitsSpinner, 2,3,0,1);
+ sourceTable.attach(sourceX1Spinner, 0,1,1,2);
+ sourceTable.attach(sourceY1Spinner, 1,2,1,2);
+ sourceTable.attach(sourceWidthSpinner, 0,1,2,3);
+ sourceTable.attach(sourceHeightSpinner, 1,2,2,3);
+
+ sourceBox.pack_start(sourceTable);
+ sourceFrame.set_label(_("Source"));
+ sourceFrame.add(sourceBox);
+ exportOptionsBox.pack_start(sourceFrame);
+
+
+ //#########################################
+ //## EXTRA WIDGET -- SOURCE SIDE
+ //#########################################
+
+
+ destTable.resize(3,3);
+ destTable.attach(destWidthSpinner, 0,1,0,1);
+ destTable.attach(destHeightSpinner, 1,2,0,1);
+ destUnitsSpinner.setUnitType(UNIT_TYPE_LINEAR);
+ destTable.attach(destUnitsSpinner, 2,3,0,1);
+ destTable.attach(destDPISpinner, 0,1,1,2);
+
+ destBox.pack_start(destTable);
+
+
+ cairoButton.set_label(_("Cairo"));
+ otherOptionBox.pack_start(cairoButton);
+
+ antiAliasButton.set_label(_("Antialias"));
+ otherOptionBox.pack_start(antiAliasButton);
+
+ backgroundButton.set_label(_("Background"));
+ otherOptionBox.pack_start(backgroundButton);
+
+ destBox.pack_start(otherOptionBox);
+
+
+
+
+
+ //###### File options
+ //###### Do we want the .xxx extension automatically added?
+ fileTypeCheckbox.set_label(Glib::ustring(_("Append filename extension automatically")));
+ fileTypeCheckbox.set_active(append_extension);
+ destBox.pack_start(fileTypeCheckbox);
+
+ //###### File type menu
+ createFileTypeMenu();
+ fileTypeComboBox.set_size_request(200,40);
+ fileTypeComboBox.signal_changed().connect(
+ sigc::mem_fun(*this, &FileExportDialogImpl::fileTypeChangedCallback) );
+
+ destBox.pack_start(fileTypeComboBox);
+
+ destFrame.set_label(_("Destination"));
+ destFrame.add(destBox);
+ exportOptionsBox.pack_start(destFrame);
+
+ //##### Put the two boxes and their parent onto the dialog
+ exportOptionsBox.pack_start(sourceFrame);
+ exportOptionsBox.pack_start(destFrame);
+
+ set_extra_widget(exportOptionsBox);
+
+
+
+
+ //Let's do some customization
+ fileNameEntry = NULL;
+ Gtk::Container *cont = get_toplevel();
+ std::vector<Gtk::Entry *> entries;
+ findEntryWidgets(cont, entries);
+ //g_message("Found %d entry widgets\n", entries.size());
+ if (entries.size() >=1 )
+ {
+ //Catch when user hits [return] on the text field
+ fileNameEntry = entries[0];
+ fileNameEntry->signal_activate().connect(
+ sigc::mem_fun(*this, &FileExportDialogImpl::fileNameEntryChangedCallback) );
+ }
+
+ //Let's do more customization
+ std::vector<Gtk::Expander *> expanders;
+ findExpanderWidgets(cont, expanders);
+ //g_message("Found %d expander widgets\n", expanders.size());
+ if (expanders.size() >=1 )
+ {
+ //Always show the file list
+ Gtk::Expander *expander = expanders[0];
+ expander->set_expanded(true);
+ }
+
+
+ //if (extension == NULL)
+ // checkbox.set_sensitive(FALSE);
+
+ add_button(Gtk::Stock::CANCEL, Gtk::RESPONSE_CANCEL);
+ set_default(*add_button(Gtk::Stock::SAVE, Gtk::RESPONSE_OK));
+
+ show_all_children();
+}
+
+/**
+ * Destructor
+ */
+FileExportDialogImpl::~FileExportDialogImpl()
+{
+}
+
+
+
+/**
+ * Show this dialog modally. Return true if user hits [OK]
+ */
+bool
+FileExportDialogImpl::show()
+{
+ Glib::ustring s = Glib::filename_to_utf8 (get_current_folder());
+ if (s.length() == 0)
+ s = getcwd (NULL, 0);
+ set_current_folder(Glib::filename_from_utf8(s)); //hack to force initial dir listing
+ set_modal (TRUE); //Window
+ sp_transientize((GtkWidget *)gobj()); //Make transient
+ gint b = run(); //Dialog
+ svgPreview.showNoPreview();
+ hide();
+
+ if (b == Gtk::RESPONSE_OK)
+ {
+ int sel = fileTypeComboBox.get_active_row_number ();
+ if (sel>=0 && sel< (int)fileTypes.size())
+ {
+ FileType &type = fileTypes[sel];
+ extension = type.extension;
+ }
+ myFilename = get_filename();
+#ifdef WITH_GNOME_VFS
+ if ( myFilename.empty() && gnome_vfs_initialized() ) {
+ myFilename = get_uri();
+ }
+#endif
+
+ /*
+
+ // FIXME: Why do we have more code
+
+ append_extension = checkbox.get_active();
+ prefs_set_int_attribute("dialogs.save_as", "append_extension", append_extension);
+ prefs_set_string_attribute("dialogs.save_as", "default",
+ ( extension != NULL ? extension->get_id() : "" ));
+ */
+ return TRUE;
+ }
+ else
+ {
+ return FALSE;
+ }
+}
+
+
+/**
+ * Get the file extension type that was selected by the user. Valid after an [OK]
+ */
+Inkscape::Extension::Extension *
+FileExportDialogImpl::getSelectionType()
+{
+ return extension;
+}
+
+
+/**
+ * Get the file name chosen by the user. Valid after an [OK]
+ */
+Glib::ustring
+FileExportDialogImpl::getFilename()
+{
+ return myFilename;
+}
+
+
+} //namespace Dialog
+} //namespace UI
+} //namespace Inkscape
+
+/*
+ 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 :
index 16383b4dade97733090cd3393fead5bc21cd59ed..e5058d0c207f6f2def2584381753bd7ff2b26c94 100644 (file)
#ifndef __FILE_DIALOGIMPL_H__
#define __FILE_DIALOGIMPL_H__
-/**\r
- * Implementation of the file dialog interfaces defined in filedialogimpl.h\r
- *\r
- * Authors:\r
- * Bob Jamison\r
- * Joel Holdsworth\r
- * Bruno Dilly\r
- * Other dudes from The Inkscape Organization\r
- *\r
- * Copyright (C) 2004-2007 Bob Jamison\r
- * Copyright (C) 2006 Johan Engelen <johan@shouraizou.nl>\r
- * Copyright (C) 2004-2007 The Inkscape Organization\r
- * Copyright (C) 2007 Joel Holdsworth\r
- *\r
- * Released under GNU GPL, read the file 'COPYING' for more information\r
- */\r
- \r
-#include "filedialog.h"\r
- \r
-//General includes\r
-#include <unistd.h>\r
-#include <sys/stat.h>\r
-#include <errno.h>\r
-#include <set>\r
-#include <libxml/parser.h>\r
-#include <libxml/tree.h>\r
-\r
-\r
-//Gtk includes\r
-#include <glibmm/i18n.h>\r
-#include <glib/gstdio.h>\r
-\r
-//Temporary ugly hack\r
-//Remove this after the get_filter() calls in\r
-//show() on both classes are fixed\r
-#include <gtk/gtkfilechooser.h>\r
-\r
-//Another hack\r
-#include <gtk/gtkentry.h>\r
-#include <gtk/gtkexpander.h>\r
-#ifdef WITH_GNOME_VFS\r
-# include <libgnomevfs/gnome-vfs-init.h> // gnome_vfs_initialized\r
-#endif\r
-\r
-//Inkscape includes\r
-#include "prefs-utils.h"\r
-#include <extension/input.h>\r
-#include <extension/output.h>\r
-#include <extension/db.h>\r
-#include "inkscape.h"\r
-#include "svg-view-widget.h"\r
-#include "gc-core.h"\r
-\r
-//For export dialog\r
-#include "ui/widget/scalar-unit.h"\r
- \r
-namespace Inkscape\r
-{\r
-namespace UI\r
-{\r
-namespace Dialog\r
+/**
+ * Implementation of the file dialog interfaces defined in filedialogimpl.h
+ *
+ * Authors:
+ * Bob Jamison
+ * Joel Holdsworth
+ * Bruno Dilly
+ * Other dudes from The Inkscape Organization
+ *
+ * Copyright (C) 2004-2007 Bob Jamison
+ * Copyright (C) 2006 Johan Engelen <johan@shouraizou.nl>
+ * Copyright (C) 2004-2007 The Inkscape Organization
+ * Copyright (C) 2007 Joel Holdsworth
+ *
+ * Released under GNU GPL, read the file 'COPYING' for more information
+ */
+
+#include "filedialog.h"
+
+//General includes
+#include <unistd.h>
+#include <sys/stat.h>
+#include <errno.h>
+#include <set>
+#include <libxml/parser.h>
+#include <libxml/tree.h>
+
+
+//Gtk includes
+#include <glibmm/i18n.h>
+#include <glib/gstdio.h>
+
+//Temporary ugly hack
+//Remove this after the get_filter() calls in
+//show() on both classes are fixed
+#include <gtk/gtkfilechooser.h>
+
+//Another hack
+#include <gtk/gtkentry.h>
+#include <gtk/gtkexpander.h>
+#ifdef WITH_GNOME_VFS
+# include <libgnomevfs/gnome-vfs-init.h> // gnome_vfs_initialized
+#endif
+
+//Inkscape includes
+#include "prefs-utils.h"
+#include <extension/input.h>
+#include <extension/output.h>
+#include <extension/db.h>
+#include "inkscape.h"
+#include "svg-view-widget.h"
+#include "gc-core.h"
+
+//For export dialog
+#include "ui/widget/scalar-unit.h"
+
+namespace Inkscape
+{
+namespace UI
+{
+namespace Dialog
{
-/*#########################################################################\r
-### Utility\r
+/*#########################################################################
+### Utility
#########################################################################*/
-void\r
-fileDialogExtensionToPattern(Glib::ustring &pattern,\r
+void
+fileDialogExtensionToPattern(Glib::ustring &pattern,
Glib::ustring &extension);
-\r
-void\r
-findEntryWidgets(Gtk::Container *parent,\r
+
+void
+findEntryWidgets(Gtk::Container *parent,
std::vector<Gtk::Entry *> &result);
-void\r
-findExpanderWidgets(Gtk::Container *parent,\r
- std::vector<Gtk::Expander *> &result);\r
-\r
-/*#########################################################################\r
-### SVG Preview Widget\r
+void
+findExpanderWidgets(Gtk::Container *parent,
+ std::vector<Gtk::Expander *> &result);
+
+/*#########################################################################
+### SVG Preview Widget
#########################################################################*/
-class FileType\r
-{\r
- public:\r
- FileType() {}\r
- ~FileType() {}\r
- Glib::ustring name;\r
- Glib::ustring pattern;\r
- Inkscape::Extension::Extension *extension;\r
-};\r
-\r
-/**\r
- * Simple class for displaying an SVG file in the "preview widget."\r
- * Currently, this is just a wrapper of the sp_svg_view Gtk widget.\r
- * Hopefully we will eventually replace with a pure Gtkmm widget.\r
- */\r
-class SVGPreview : public Gtk::VBox\r
-{\r
-public:\r
-\r
- SVGPreview();\r
-\r
- ~SVGPreview();\r
-\r
- bool setDocument(SPDocument *doc);\r
-\r
- bool setFileName(Glib::ustring &fileName);\r
-\r
- bool setFromMem(char const *xmlBuffer);\r
-\r
- bool set(Glib::ustring &fileName, int dialogType);\r
-\r
- bool setURI(URI &uri);\r
-\r
- /**\r
- * Show image embedded in SVG\r
- */\r
- void showImage(Glib::ustring &fileName);\r
-\r
- /**\r
- * Show the "No preview" image\r
- */\r
- void showNoPreview();\r
-\r
- /**\r
- * Show the "Too large" image\r
- */\r
- void showTooLarge(long fileLength);\r
-\r
-private:\r
- /**\r
- * The svg document we are currently showing\r
- */\r
- SPDocument *document;\r
-\r
- /**\r
- * The sp_svg_view widget\r
- */\r
- GtkWidget *viewerGtk;\r
-\r
- /**\r
- * are we currently showing the "no preview" image?\r
- */\r
- bool showingNoPreview;\r
-\r
-};\r
-\r
-/*#########################################################################\r
-### F I L E D I A L O G B A S E C L A S S\r
-#########################################################################*/\r
-\r
-/**\r
- * This class is the base implementation for the others. This\r
- * reduces redundancies and bugs.\r
- */\r
-class FileDialogBaseGtk : public Gtk::FileChooserDialog\r
-{\r
-public:\r
-\r
- /**\r
- *\r
- */\r
- FileDialogBaseGtk(Gtk::Window& parentWindow, const Glib::ustring &title,\r
- FileDialogType type, gchar const* preferenceBase) :\r
- Gtk::FileChooserDialog(parentWindow, title),\r
- preferenceBase(preferenceBase ? preferenceBase : "unknown"),\r
- dialogType(type)\r
- {\r
- internalSetup();\r
- }\r
-\r
- /**\r
- *\r
- */\r
- FileDialogBaseGtk(Gtk::Window& parentWindow, const Glib::ustring &title,\r
- Gtk::FileChooserAction dialogType, FileDialogType type, gchar const* preferenceBase) :\r
- Gtk::FileChooserDialog(parentWindow, title, dialogType),\r
- preferenceBase(preferenceBase ? preferenceBase : "unknown"),\r
- dialogType(type)\r
- {\r
- internalSetup();\r
- }\r
-\r
- /**\r
- *\r
- */\r
- virtual ~FileDialogBaseGtk()\r
- {}\r
-\r
-protected:\r
- void cleanup( bool showConfirmed );\r
-\r
- Glib::ustring preferenceBase;\r
- /**\r
- * What type of 'open' are we? (open, import, place, etc)\r
- */\r
- FileDialogType dialogType;\r
-\r
- /**\r
- * Our svg preview widget\r
- */\r
- SVGPreview svgPreview;\r
-\r
- //# Child widgets\r
- Gtk::CheckButton previewCheckbox;\r
-\r
-private:\r
- void internalSetup();\r
-\r
- /**\r
- * Callback for user changing preview checkbox\r
- */\r
- void _previewEnabledCB();\r
-\r
- /**\r
- * Callback for seeing if the preview needs to be drawn\r
- */\r
- void _updatePreviewCallback();\r
-};\r
-\r
-\r
-\r
-\r
-/*#########################################################################\r
-### F I L E O P E N\r
-#########################################################################*/\r
-\r
-/**\r
- * Our implementation class for the FileOpenDialog interface..\r
- */\r
-class FileOpenDialogImplGtk : public FileOpenDialog, public FileDialogBaseGtk\r
-{\r
-public:\r
-\r
- FileOpenDialogImplGtk(Gtk::Window& parentWindow,\r
- const Glib::ustring &dir,\r
- FileDialogType fileTypes,\r
- const Glib::ustring &title);\r
-\r
- virtual ~FileOpenDialogImplGtk();\r
-\r
- bool show();\r
-\r
- Inkscape::Extension::Extension *getSelectionType();\r
-\r
- Glib::ustring getFilename();\r
-\r
- std::vector<Glib::ustring> getFilenames ();\r
-\r
-private:\r
-\r
- /**\r
- * Create a filter menu for this type of dialog\r
- */\r
- void createFilterMenu();\r
-\r
- /**\r
- * Filter name->extension lookup\r
- */\r
- std::map<Glib::ustring, Inkscape::Extension::Extension *> extensionMap;\r
-\r
- /**\r
- * The extension to use to write this file\r
- */\r
- Inkscape::Extension::Extension *extension;\r
-\r
- /**\r
- * Filename that was given\r
- */\r
- Glib::ustring myFilename;\r
-\r
-};\r
-\r
-\r
-\r
-//########################################################################\r
-//# F I L E S A V E\r
-//########################################################################\r
-\r
-/**\r
- * Our implementation of the FileSaveDialog interface.\r
- */\r
-class FileSaveDialogImplGtk : public FileSaveDialog, public FileDialogBaseGtk\r
-{\r
-\r
-public:\r
- FileSaveDialogImplGtk(Gtk::Window &parentWindow, \r
- const Glib::ustring &dir,\r
- FileDialogType fileTypes,\r
- const Glib::ustring &title,\r
- const Glib::ustring &default_key);\r
-\r
- virtual ~FileSaveDialogImplGtk();\r
-\r
- bool show();\r
-\r
- Inkscape::Extension::Extension *getSelectionType();\r
- virtual void setSelectionType( Inkscape::Extension::Extension * key );\r
-\r
- Glib::ustring getFilename();\r
-\r
- void change_title(const Glib::ustring& title);\r
- void change_path(const Glib::ustring& path);\r
- void updateNameAndExtension();\r
-\r
-private:\r
-\r
- /**\r
- * Fix to allow the user to type the file name\r
- */\r
- Gtk::Entry *fileNameEntry;\r
-\r
-\r
- /**\r
- * Allow the specification of the output file type\r
- */\r
- Gtk::ComboBoxText fileTypeComboBox;\r
-\r
-\r
- /**\r
- * Data mirror of the combo box\r
- */\r
- std::vector<FileType> fileTypes;\r
-\r
- //# Child widgets\r
- Gtk::HBox childBox;\r
- Gtk::VBox checksBox;\r
-\r
- Gtk::CheckButton fileTypeCheckbox;\r
-\r
- /**\r
- * Callback for user input into fileNameEntry\r
- */\r
- void fileTypeChangedCallback();\r
-\r
- /**\r
- * Create a filter menu for this type of dialog\r
- */\r
- void createFileTypeMenu();\r
-\r
-\r
- /**\r
- * The extension to use to write this file\r
- */\r
- Inkscape::Extension::Extension *extension;\r
-\r
- /**\r
- * Callback for user input into fileNameEntry\r
- */\r
- void fileNameEntryChangedCallback();\r
-\r
- /**\r
- * Filename that was given\r
- */\r
- Glib::ustring myFilename;\r
-\r
- /**\r
- * List of known file extensions.\r
- */\r
- std::set<Glib::ustring> knownExtensions;\r
-};\r
-\r
-\r
-\r
-\r
-//########################################################################\r
-//# F I L E E X P O R T\r
-//########################################################################\r
-\r
-/**\r
- * Our implementation of the FileExportDialog interface.\r
- */\r
-class FileExportDialogImpl : public FileExportDialog, public FileDialogBaseGtk\r
-{\r
-\r
-public:\r
- FileExportDialogImpl(Gtk::Window& parentWindow,\r
- const Glib::ustring &dir,\r
- FileDialogType fileTypes,\r
- const Glib::ustring &title,\r
- const Glib::ustring &default_key);\r
-\r
- virtual ~FileExportDialogImpl();\r
-\r
- bool show();\r
-\r
- Inkscape::Extension::Extension *getSelectionType();\r
-\r
- Glib::ustring getFilename();\r
-\r
-\r
- /**\r
- * Return the scope of the export. One of the enumerated types\r
- * in ScopeType \r
- */\r
- ScopeType getScope()\r
- { \r
- if (pageButton.get_active())\r
- return SCOPE_PAGE;\r
- else if (selectionButton.get_active())\r
- return SCOPE_SELECTION;\r
- else if (customButton.get_active())\r
- return SCOPE_CUSTOM;\r
- else\r
- return SCOPE_DOCUMENT;\r
-\r
- }\r
- \r
- /**\r
- * Return left side of the exported region\r
- */\r
- double getSourceX()\r
- { return sourceX0Spinner.getValue(); }\r
- \r
- /**\r
- * Return the top of the exported region\r
- */\r
- double getSourceY()\r
- { return sourceY1Spinner.getValue(); }\r
- \r
- /**\r
- * Return the width of the exported region\r
- */\r
- double getSourceWidth()\r
- { return sourceWidthSpinner.getValue(); }\r
- \r
- /**\r
- * Return the height of the exported region\r
- */\r
- double getSourceHeight()\r
- { return sourceHeightSpinner.getValue(); }\r
-\r
- /**\r
- * Return the units of the coordinates of exported region\r
- */\r
- Glib::ustring getSourceUnits()\r
- { return sourceUnitsSpinner.getUnitAbbr(); }\r
-\r
- /**\r
- * Return the width of the destination document\r
- */\r
- double getDestinationWidth()\r
- { return destWidthSpinner.getValue(); }\r
-\r
- /**\r
- * Return the height of the destination document\r
- */\r
- double getDestinationHeight()\r
- { return destHeightSpinner.getValue(); }\r
-\r
- /**\r
- * Return the height of the exported region\r
- */\r
- Glib::ustring getDestinationUnits()\r
- { return destUnitsSpinner.getUnitAbbr(); }\r
-\r
- /**\r
- * Return the destination DPI image resulution, if bitmap\r
- */\r
- double getDestinationDPI()\r
- { return destDPISpinner.getValue(); }\r
-\r
- /**\r
- * Return whether we should use Cairo for rendering\r
- */\r
- bool getUseCairo()\r
- { return cairoButton.get_active(); }\r
-\r
- /**\r
- * Return whether we should use antialiasing\r
- */\r
- bool getUseAntialias()\r
- { return antiAliasButton.get_active(); }\r
-\r
- /**\r
- * Return the background color for exporting\r
- */\r
- unsigned long getBackground()\r
- { return backgroundButton.get_color().get_pixel(); }\r
-\r
-private:\r
-\r
- /**\r
- * Fix to allow the user to type the file name\r
- */\r
- Gtk::Entry *fileNameEntry;\r
-\r
- //##########################################\r
- //# EXTRA WIDGET -- SOURCE SIDE\r
- //##########################################\r
-\r
- Gtk::Frame sourceFrame;\r
- Gtk::VBox sourceBox;\r
-\r
- Gtk::HBox scopeBox;\r
- Gtk::RadioButtonGroup scopeGroup;\r
- Gtk::RadioButton documentButton;\r
- Gtk::RadioButton pageButton;\r
- Gtk::RadioButton selectionButton;\r
- Gtk::RadioButton customButton;\r
-\r
- Gtk::Table sourceTable;\r
- Inkscape::UI::Widget::Scalar sourceX0Spinner;\r
- Inkscape::UI::Widget::Scalar sourceY0Spinner;\r
- Inkscape::UI::Widget::Scalar sourceX1Spinner;\r
- Inkscape::UI::Widget::Scalar sourceY1Spinner;\r
- Inkscape::UI::Widget::Scalar sourceWidthSpinner;\r
- Inkscape::UI::Widget::Scalar sourceHeightSpinner;\r
- Inkscape::UI::Widget::UnitMenu sourceUnitsSpinner;\r
-\r
-\r
- //##########################################\r
- //# EXTRA WIDGET -- DESTINATION SIDE\r
- //##########################################\r
-\r
- Gtk::Frame destFrame;\r
- Gtk::VBox destBox;\r
-\r
- Gtk::Table destTable;\r
- Inkscape::UI::Widget::Scalar destWidthSpinner;\r
- Inkscape::UI::Widget::Scalar destHeightSpinner;\r
- Inkscape::UI::Widget::Scalar destDPISpinner;\r
- Inkscape::UI::Widget::UnitMenu destUnitsSpinner;\r
-\r
- Gtk::HBox otherOptionBox;\r
- Gtk::CheckButton cairoButton;\r
- Gtk::CheckButton antiAliasButton;\r
- Gtk::ColorButton backgroundButton;\r
-\r
-\r
- /**\r
- * 'Extra' widget that holds two boxes above\r
- */\r
- Gtk::HBox exportOptionsBox;\r
-\r
-\r
- //# Child widgets\r
- Gtk::CheckButton fileTypeCheckbox;\r
-\r
- /**\r
- * Allow the specification of the output file type\r
- */\r
- Gtk::ComboBoxText fileTypeComboBox;\r
-\r
-\r
- /**\r
- * Data mirror of the combo box\r
- */\r
- std::vector<FileType> fileTypes;\r
-\r
-\r
-\r
- /**\r
- * Callback for user input into fileNameEntry\r
- */\r
- void fileTypeChangedCallback();\r
-\r
- /**\r
- * Create a filter menu for this type of dialog\r
- */\r
- void createFileTypeMenu();\r
-\r
-\r
- bool append_extension;\r
-\r
- /**\r
- * The extension to use to write this file\r
- */\r
- Inkscape::Extension::Extension *extension;\r
-\r
- /**\r
- * Callback for user input into fileNameEntry\r
- */\r
- void fileNameEntryChangedCallback();\r
-\r
- /**\r
- * Filename that was given\r
- */\r
- Glib::ustring myFilename;\r
-};\r
-\r
-\r
-\r\r
-}\r
-}\r
-}\r
-\r
+class FileType
+{
+ public:
+ FileType() {}
+ ~FileType() {}
+ Glib::ustring name;
+ Glib::ustring pattern;
+ Inkscape::Extension::Extension *extension;
+};
+
+/**
+ * Simple class for displaying an SVG file in the "preview widget."
+ * Currently, this is just a wrapper of the sp_svg_view Gtk widget.
+ * Hopefully we will eventually replace with a pure Gtkmm widget.
+ */
+class SVGPreview : public Gtk::VBox
+{
+public:
+
+ SVGPreview();
+
+ ~SVGPreview();
+
+ bool setDocument(SPDocument *doc);
+
+ bool setFileName(Glib::ustring &fileName);
+
+ bool setFromMem(char const *xmlBuffer);
+
+ bool set(Glib::ustring &fileName, int dialogType);
+
+ bool setURI(URI &uri);
+
+ /**
+ * Show image embedded in SVG
+ */
+ void showImage(Glib::ustring &fileName);
+
+ /**
+ * Show the "No preview" image
+ */
+ void showNoPreview();
+
+ /**
+ * Show the "Too large" image
+ */
+ void showTooLarge(long fileLength);
+
+private:
+ /**
+ * The svg document we are currently showing
+ */
+ SPDocument *document;
+
+ /**
+ * The sp_svg_view widget
+ */
+ GtkWidget *viewerGtk;
+
+ /**
+ * are we currently showing the "no preview" image?
+ */
+ bool showingNoPreview;
+
+};
+
+/*#########################################################################
+### F I L E D I A L O G B A S E C L A S S
+#########################################################################*/
+
+/**
+ * This class is the base implementation for the others. This
+ * reduces redundancies and bugs.
+ */
+class FileDialogBaseGtk : public Gtk::FileChooserDialog
+{
+public:
+
+ /**
+ *
+ */
+ FileDialogBaseGtk(Gtk::Window& parentWindow, const Glib::ustring &title,
+ FileDialogType type, gchar const* preferenceBase) :
+ Gtk::FileChooserDialog(parentWindow, title),
+ preferenceBase(preferenceBase ? preferenceBase : "unknown"),
+ dialogType(type)
+ {
+ internalSetup();
+ }
+
+ /**
+ *
+ */
+ FileDialogBaseGtk(Gtk::Window& parentWindow, const Glib::ustring &title,
+ Gtk::FileChooserAction dialogType, FileDialogType type, gchar const* preferenceBase) :
+ Gtk::FileChooserDialog(parentWindow, title, dialogType),
+ preferenceBase(preferenceBase ? preferenceBase : "unknown"),
+ dialogType(type)
+ {
+ internalSetup();
+ }
+
+ /**
+ *
+ */
+ virtual ~FileDialogBaseGtk()
+ {}
+
+protected:
+ void cleanup( bool showConfirmed );
+
+ Glib::ustring preferenceBase;
+ /**
+ * What type of 'open' are we? (open, import, place, etc)
+ */
+ FileDialogType dialogType;
+
+ /**
+ * Our svg preview widget
+ */
+ SVGPreview svgPreview;
+
+ //# Child widgets
+ Gtk::CheckButton previewCheckbox;
+
+private:
+ void internalSetup();
+
+ /**
+ * Callback for user changing preview checkbox
+ */
+ void _previewEnabledCB();
+
+ /**
+ * Callback for seeing if the preview needs to be drawn
+ */
+ void _updatePreviewCallback();
+};
+
+
+
+
+/*#########################################################################
+### F I L E O P E N
+#########################################################################*/
+
+/**
+ * Our implementation class for the FileOpenDialog interface..
+ */
+class FileOpenDialogImplGtk : public FileOpenDialog, public FileDialogBaseGtk
+{
+public:
+
+ FileOpenDialogImplGtk(Gtk::Window& parentWindow,
+ const Glib::ustring &dir,
+ FileDialogType fileTypes,
+ const Glib::ustring &title);
+
+ virtual ~FileOpenDialogImplGtk();
+
+ bool show();
+
+ Inkscape::Extension::Extension *getSelectionType();
+
+ Glib::ustring getFilename();
+
+ std::vector<Glib::ustring> getFilenames ();
+
+private:
+
+ /**
+ * Create a filter menu for this type of dialog
+ */
+ void createFilterMenu();
+
+ /**
+ * Filter name->extension lookup
+ */
+ std::map<Glib::ustring, Inkscape::Extension::Extension *> extensionMap;
+
+ /**
+ * The extension to use to write this file
+ */
+ Inkscape::Extension::Extension *extension;
+
+ /**
+ * Filename that was given
+ */
+ Glib::ustring myFilename;
+
+};
+
+
+
+//########################################################################
+//# F I L E S A V E
+//########################################################################
+
+/**
+ * Our implementation of the FileSaveDialog interface.
+ */
+class FileSaveDialogImplGtk : public FileSaveDialog, public FileDialogBaseGtk
+{
+
+public:
+ FileSaveDialogImplGtk(Gtk::Window &parentWindow,
+ const Glib::ustring &dir,
+ FileDialogType fileTypes,
+ const Glib::ustring &title,
+ const Glib::ustring &default_key);
+
+ virtual ~FileSaveDialogImplGtk();
+
+ bool show();
+
+ Inkscape::Extension::Extension *getSelectionType();
+ virtual void setSelectionType( Inkscape::Extension::Extension * key );
+
+ Glib::ustring getFilename();
+
+ void change_title(const Glib::ustring& title);
+ void change_path(const Glib::ustring& path);
+ void updateNameAndExtension();
+
+private:
+
+ /**
+ * Fix to allow the user to type the file name
+ */
+ Gtk::Entry *fileNameEntry;
+
+
+ /**
+ * Allow the specification of the output file type
+ */
+ Gtk::ComboBoxText fileTypeComboBox;
+
+
+ /**
+ * Data mirror of the combo box
+ */
+ std::vector<FileType> fileTypes;
+
+ //# Child widgets
+ Gtk::HBox childBox;
+ Gtk::VBox checksBox;
+
+ Gtk::CheckButton fileTypeCheckbox;
+
+ /**
+ * Callback for user input into fileNameEntry
+ */
+ void fileTypeChangedCallback();
+
+ /**
+ * Create a filter menu for this type of dialog
+ */
+ void createFileTypeMenu();
+
+
+ /**
+ * The extension to use to write this file
+ */
+ Inkscape::Extension::Extension *extension;
+
+ /**
+ * Callback for user input into fileNameEntry
+ */
+ void fileNameEntryChangedCallback();
+
+ /**
+ * Filename that was given
+ */
+ Glib::ustring myFilename;
+
+ /**
+ * List of known file extensions.
+ */
+ std::set<Glib::ustring> knownExtensions;
+};
+
+
+
+
+//########################################################################
+//# F I L E E X P O R T
+//########################################################################
+
+/**
+ * Our implementation of the FileExportDialog interface.
+ */
+class FileExportDialogImpl : public FileExportDialog, public FileDialogBaseGtk
+{
+
+public:
+ FileExportDialogImpl(Gtk::Window& parentWindow,
+ const Glib::ustring &dir,
+ FileDialogType fileTypes,
+ const Glib::ustring &title,
+ const Glib::ustring &default_key);
+
+ virtual ~FileExportDialogImpl();
+
+ bool show();
+
+ Inkscape::Extension::Extension *getSelectionType();
+
+ Glib::ustring getFilename();
+
+
+ /**
+ * Return the scope of the export. One of the enumerated types
+ * in ScopeType
+ */
+ ScopeType getScope()
+ {
+ if (pageButton.get_active())
+ return SCOPE_PAGE;
+ else if (selectionButton.get_active())
+ return SCOPE_SELECTION;
+ else if (customButton.get_active())
+ return SCOPE_CUSTOM;
+ else
+ return SCOPE_DOCUMENT;
+
+ }
+
+ /**
+ * Return left side of the exported region
+ */
+ double getSourceX()
+ { return sourceX0Spinner.getValue(); }
+
+ /**
+ * Return the top of the exported region
+ */
+ double getSourceY()
+ { return sourceY1Spinner.getValue(); }
+
+ /**
+ * Return the width of the exported region
+ */
+ double getSourceWidth()
+ { return sourceWidthSpinner.getValue(); }
+
+ /**
+ * Return the height of the exported region
+ */
+ double getSourceHeight()
+ { return sourceHeightSpinner.getValue(); }
+
+ /**
+ * Return the units of the coordinates of exported region
+ */
+ Glib::ustring getSourceUnits()
+ { return sourceUnitsSpinner.getUnitAbbr(); }
+
+ /**
+ * Return the width of the destination document
+ */
+ double getDestinationWidth()
+ { return destWidthSpinner.getValue(); }
+
+ /**
+ * Return the height of the destination document
+ */
+ double getDestinationHeight()
+ { return destHeightSpinner.getValue(); }
+
+ /**
+ * Return the height of the exported region
+ */
+ Glib::ustring getDestinationUnits()
+ { return destUnitsSpinner.getUnitAbbr(); }
+
+ /**
+ * Return the destination DPI image resulution, if bitmap
+ */
+ double getDestinationDPI()
+ { return destDPISpinner.getValue(); }
+
+ /**
+ * Return whether we should use Cairo for rendering
+ */
+ bool getUseCairo()
+ { return cairoButton.get_active(); }
+
+ /**
+ * Return whether we should use antialiasing
+ */
+ bool getUseAntialias()
+ { return antiAliasButton.get_active(); }
+
+ /**
+ * Return the background color for exporting
+ */
+ unsigned long getBackground()
+ { return backgroundButton.get_color().get_pixel(); }
+
+private:
+
+ /**
+ * Fix to allow the user to type the file name
+ */
+ Gtk::Entry *fileNameEntry;
+
+ //##########################################
+ //# EXTRA WIDGET -- SOURCE SIDE
+ //##########################################
+
+ Gtk::Frame sourceFrame;
+ Gtk::VBox sourceBox;
+
+ Gtk::HBox scopeBox;
+ Gtk::RadioButtonGroup scopeGroup;
+ Gtk::RadioButton documentButton;
+ Gtk::RadioButton pageButton;
+ Gtk::RadioButton selectionButton;
+ Gtk::RadioButton customButton;
+
+ Gtk::Table sourceTable;
+ Inkscape::UI::Widget::Scalar sourceX0Spinner;
+ Inkscape::UI::Widget::Scalar sourceY0Spinner;
+ Inkscape::UI::Widget::Scalar sourceX1Spinner;
+ Inkscape::UI::Widget::Scalar sourceY1Spinner;
+ Inkscape::UI::Widget::Scalar sourceWidthSpinner;
+ Inkscape::UI::Widget::Scalar sourceHeightSpinner;
+ Inkscape::UI::Widget::UnitMenu sourceUnitsSpinner;
+
+
+ //##########################################
+ //# EXTRA WIDGET -- DESTINATION SIDE
+ //##########################################
+
+ Gtk::Frame destFrame;
+ Gtk::VBox destBox;
+
+ Gtk::Table destTable;
+ Inkscape::UI::Widget::Scalar destWidthSpinner;
+ Inkscape::UI::Widget::Scalar destHeightSpinner;
+ Inkscape::UI::Widget::Scalar destDPISpinner;
+ Inkscape::UI::Widget::UnitMenu destUnitsSpinner;
+
+ Gtk::HBox otherOptionBox;
+ Gtk::CheckButton cairoButton;
+ Gtk::CheckButton antiAliasButton;
+ Gtk::ColorButton backgroundButton;
+
+
+ /**
+ * 'Extra' widget that holds two boxes above
+ */
+ Gtk::HBox exportOptionsBox;
+
+
+ //# Child widgets
+ Gtk::CheckButton fileTypeCheckbox;
+
+ /**
+ * Allow the specification of the output file type
+ */
+ Gtk::ComboBoxText fileTypeComboBox;
+
+
+ /**
+ * Data mirror of the combo box
+ */
+ std::vector<FileType> fileTypes;
+
+
+
+ /**
+ * Callback for user input into fileNameEntry
+ */
+ void fileTypeChangedCallback();
+
+ /**
+ * Create a filter menu for this type of dialog
+ */
+ void createFileTypeMenu();
+
+
+ bool append_extension;
+
+ /**
+ * The extension to use to write this file
+ */
+ Inkscape::Extension::Extension *extension;
+
+ /**
+ * Callback for user input into fileNameEntry
+ */
+ void fileNameEntryChangedCallback();
+
+ /**
+ * Filename that was given
+ */
+ Glib::ustring myFilename;
+};
+
+
+}
+}
+}
+
#endif /*__FILE_DIALOGIMPL_H__*/
-/*\r
- Local Variables:\r
- mode:c++\r
- c-file-style:"stroustrup"\r
- c-file-offsets:((innamespace . 0)(inline-open . 0)(case-label . +))\r
- indent-tabs-mode:nil\r
- fill-column:99\r
- End:\r
-*/\r
-// vim: filetype=cpp:expandtab:shiftwidth=4:tabstop=8:softtabstop=4 :\r
+/*
+ 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 :
index 6da07c2d876c34fd753c20817a12fb0cc0e7dff6..ec6c5c6ee7457cec187376f9488c7e00851916cc 100644 (file)
-/**\r
- * \brief LivePathEffect dialog\r
- *\r
- * Authors:\r
- * Johan Engelen <j.b.c.engelen@utwente.nl>\r
- *\r
- * Copyright (C) 2007 Author\r
- *\r
- * Released under GNU GPL. Read the file 'COPYING' for more information.\r
- */\r
-\r
-#ifdef HAVE_CONFIG_H\r
-# include <config.h>\r
-#endif\r
-\r
-#include <glibmm/i18n.h>\r
-#include "livepatheffect-editor.h"\r
-#include "verbs.h"\r
-#include "selection.h"\r
-#include "sp-shape.h"\r
-#include "sp-path.h"\r
-#include "live_effects/effect.h"\r
-#include "live_effects/lpeobject.h"\r
-#include "gtkmm/widget.h"\r
-#include <vector>\r
-#include "inkscape.h"\r
-#include "desktop-handles.h"\r
-#include "desktop.h"\r
-#include "document-private.h"\r
-#include "xml/node.h"\r
-#include "xml/document.h"\r
-\r
-namespace Inkscape {\r
-class Application;\r
-\r
-namespace UI {\r
-namespace Dialog {\r
-\r
-\r
-/*####################\r
- * Callback functions\r
- */\r
-static void lpeeditor_selection_changed (Inkscape::Selection * selection, gpointer data)\r
-{\r
- LivePathEffectEditor *lpeeditor = static_cast<LivePathEffectEditor *>(data);\r
- lpeeditor->onSelectionChanged(selection);\r
-}\r
-\r
-static void lpeeditor_selection_modified (Inkscape::Selection *selection, guint flags, gpointer data)\r
-{\r
- lpeeditor_selection_changed (selection, data);\r
-}\r
-\r
-\r
-static void lpeeditor_desktop_change(Inkscape::Application*, SPDesktop* desktop, void *data)\r
-{\r
- if (!desktop) {\r
- return;\r
- }\r
- LivePathEffectEditor* editor = reinterpret_cast<LivePathEffectEditor*>(data);\r
- editor->setDesktop(desktop);\r
-}\r
-\r
-\r
-\r
-/*#######################\r
- * LivePathEffectEditor\r
- */\r
-LivePathEffectEditor::LivePathEffectEditor(Behavior::BehaviorFactory behavior_factory) \r
- : Dialog (behavior_factory, "dialogs.livepatheffect", SP_VERB_DIALOG_LIVE_PATH_EFFECT),\r
- combo_effecttype(Inkscape::LivePathEffect::LPETypeConverter),\r
- button_apply(_("_Apply"), _("Apply chosen effect to selection")),\r
- button_remove(_("_Remove"), _("Remove effect from selection")),\r
- effectwidget(NULL),\r
- explain_label("", Gtk::ALIGN_CENTER),\r
- effectapplication_frame(_("Apply new effect")),\r
- effectcontrol_frame(_("Current effect")),\r
- current_desktop(NULL)\r
-{\r
- // Top level vbox\r
- Gtk::VBox *vbox = get_vbox();\r
- vbox->set_spacing(4);\r
-\r
- effectapplication_hbox.set_spacing(4);\r
- effectcontrol_vbox.set_spacing(4);\r
-\r
- effectapplication_hbox.pack_start(combo_effecttype, true, true);\r
- effectapplication_hbox.pack_start(button_apply, true, true);\r
- effectapplication_frame.add(effectapplication_hbox);\r
-\r
- effectcontrol_vbox.pack_start(explain_label, true, true);\r
- effectcontrol_vbox.pack_end(button_remove, true, true);\r
- effectcontrol_frame.add(effectcontrol_vbox);\r
-\r
- vbox->pack_start(effectapplication_frame, true, true);\r
- vbox->pack_start(effectcontrol_frame, true, true);\r
-\r
- // connect callback functions to buttons\r
- button_apply.signal_clicked().connect(sigc::mem_fun(*this, &LivePathEffectEditor::onApply));\r
- button_remove.signal_clicked().connect(sigc::mem_fun(*this, &LivePathEffectEditor::onRemove));\r
-\r
- // connect callback functions to changes in selected desktop.\r
- g_signal_connect( G_OBJECT(INKSCAPE), "activate_desktop",\r
- G_CALLBACK(lpeeditor_desktop_change), this);\r
-\r
- g_signal_connect( G_OBJECT(INKSCAPE), "deactivate_desktop",\r
- G_CALLBACK(lpeeditor_desktop_change), this);\r
-\r
- setDesktop(SP_ACTIVE_DESKTOP);\r
- show_all_children();\r
- button_remove.hide();\r
-}\r
-\r
-LivePathEffectEditor::~LivePathEffectEditor() \r
-{\r
- if (effectwidget) {\r
- effectcontrol_vbox.remove(*effectwidget);\r
- effectwidget = NULL;\r
- }\r
-\r
- if (current_desktop) {\r
- selection_changed_connection.disconnect();\r
- selection_modified_connection.disconnect();\r
- }\r
-}\r
-\r
-void\r
-LivePathEffectEditor::showParams(LivePathEffect::Effect* effect)\r
-{\r
- if (effectwidget) {\r
- effectcontrol_vbox.remove(*effectwidget);\r
- effectwidget = NULL;\r
- }\r
-\r
- explain_label.set_markup("<b>" + effect->getName() + "</b>");\r
- effectwidget = effect->getWidget();\r
- if (effectwidget) {\r
- effectcontrol_vbox.pack_start(*effectwidget, true, true);\r
- }\r
- button_remove.show();\r
-\r
- effectcontrol_vbox.show_all_children();\r
- // fixme: do resizing of dialog \r
-}\r
-\r
-void\r
-LivePathEffectEditor::showText(Glib::ustring const &str)\r
-{\r
- if (effectwidget) {\r
- effectcontrol_vbox.remove(*effectwidget);\r
- effectwidget = NULL;\r
- }\r
-\r
- explain_label.set_label(str);\r
- button_remove.hide();\r
-\r
- // fixme: do resizing of dialog ?\r
-}\r
-\r
-void\r
-LivePathEffectEditor::set_sensitize_all(bool sensitive)\r
-{\r
- combo_effecttype.set_sensitive(sensitive);\r
- button_apply.set_sensitive(sensitive);\r
- button_remove.set_sensitive(sensitive);\r
-}\r
-\r
-void\r
-LivePathEffectEditor::onSelectionChanged(Inkscape::Selection *sel)\r
-{\r
- if ( sel && !sel->isEmpty() ) {\r
- SPItem *item = sel->singleItem();\r
- if ( item ) {\r
- if ( SP_IS_SHAPE(item) ) {\r
- SPShape *shape = SP_SHAPE(item);\r
- LivePathEffectObject *lpeobj = sp_shape_get_livepatheffectobject(shape);\r
- set_sensitize_all(true);\r
- if (lpeobj) {\r
- if (lpeobj->lpe) {\r
- showParams(lpeobj->lpe);\r
- } else {\r
- showText(_("Unknown effect is applied"));\r
- }\r
- } else {\r
- showText(_("No effect applied"));\r
- button_remove.set_sensitive(false);\r
- }\r
- } else {\r
- showText(_("Item is not a shape or path"));\r
- set_sensitize_all(false);\r
- }\r
- } else {\r
- showText(_("Only one item can be selected"));\r
- set_sensitize_all(false);\r
- }\r
- } else {\r
- showText(_("Empty selection"));\r
- set_sensitize_all(false);\r
- }\r
-}\r
-\r
-void \r
-LivePathEffectEditor::setDesktop(SPDesktop *desktop)\r
-{\r
-\r
- if ( desktop == current_desktop ) {\r
- return;\r
- }\r
-\r
- if (current_desktop) {\r
- selection_changed_connection.disconnect();\r
- selection_modified_connection.disconnect();\r
- }\r
-\r
- current_desktop = desktop;\r
- if (desktop) {\r
- Inkscape::Selection *selection = sp_desktop_selection(desktop);\r
- selection_changed_connection = selection->connectChanged(\r
- sigc::bind (sigc::ptr_fun(&lpeeditor_selection_changed), this ) );\r
- selection_modified_connection = selection->connectModified(\r
- sigc::bind (sigc::ptr_fun(&lpeeditor_selection_modified), this ) );\r
-\r
- onSelectionChanged(selection);\r
- } else {\r
- onSelectionChanged(NULL);\r
- }\r
-}\r
-\r
-\r
-\r
-\r
-/*########################################################################\r
-# BUTTON CLICK HANDLERS (callbacks)\r
-########################################################################*/\r
-\r
-// TODO: factor out the effect applying code which can be called from anywhere. (selection-chemistry.cpp also needs it)\r
-\r
-void\r
-LivePathEffectEditor::onApply()\r
-{\r
- Inkscape::Selection *sel = _getSelection();\r
- if ( sel && !sel->isEmpty() ) {\r
- SPItem *item = sel->singleItem();\r
- if ( item && SP_IS_SHAPE(item) ) {\r
- SPDocument *doc = current_desktop->doc();\r
-\r
- const Util::EnumData<LivePathEffect::EffectType>* data = combo_effecttype.get_active_data();\r
- if (!data) return;\r
-\r
- Inkscape::XML::Document *xml_doc = sp_document_repr_doc(doc);\r
- Inkscape::XML::Node *repr = xml_doc->createElement("inkscape:path-effect");\r
- repr->setAttribute("effect", data->key.c_str() );\r
-\r
- SP_OBJECT_REPR(SP_DOCUMENT_DEFS(doc))->addChild(repr, NULL); // adds to <defs> and assigns the 'id' attribute\r
- const gchar * repr_id = repr->attribute("id");\r
- Inkscape::GC::release(repr);\r
-\r
- gchar *href = g_strdup_printf("#%s", repr_id);\r
- sp_shape_set_path_effect(SP_SHAPE(item), href);\r
- g_free(href);\r
-\r
- // make sure there is an original-d for paths!!!\r
- if ( SP_IS_PATH(item) ) {\r
- Inkscape::XML::Node *pathrepr = SP_OBJECT_REPR(item);\r
- if ( ! pathrepr->attribute("inkscape:original-d") ) {\r
- pathrepr->setAttribute("inkscape:original-d", pathrepr->attribute("d"));\r
- }\r
- }\r
-\r
- sp_document_done(doc, SP_VERB_DIALOG_LIVE_PATH_EFFECT, \r
- _("Create and apply path effect"));\r
- }\r
- }\r
-}\r
-\r
-void\r
-LivePathEffectEditor::onRemove()\r
-{\r
- Inkscape::Selection *sel = _getSelection();\r
- if ( sel && !sel->isEmpty() ) {\r
- SPItem *item = sel->singleItem();\r
- if ( item && SP_IS_SHAPE(item) ) {\r
- sp_shape_remove_path_effect(SP_SHAPE(item));\r
- sp_document_done ( sp_desktop_document (current_desktop), SP_VERB_DIALOG_LIVE_PATH_EFFECT, \r
- _("Remove path effect") );\r
- }\r
- }\r
-}\r
-\r
-\r
-\r
-} // namespace Dialog\r
-} // namespace UI\r
-} // namespace Inkscape\r
-\r
+/**
+ * \brief LivePathEffect dialog
+ *
+ * Authors:
+ * Johan Engelen <j.b.c.engelen@utwente.nl>
+ *
+ * Copyright (C) 2007 Author
+ *
+ * Released under GNU GPL. Read the file 'COPYING' for more information.
+ */
+
+#ifdef HAVE_CONFIG_H
+# include <config.h>
+#endif
+
+#include <glibmm/i18n.h>
+#include "livepatheffect-editor.h"
+#include "verbs.h"
+#include "selection.h"
+#include "sp-shape.h"
+#include "sp-path.h"
+#include "live_effects/effect.h"
+#include "live_effects/lpeobject.h"
+#include "gtkmm/widget.h"
+#include <vector>
+#include "inkscape.h"
+#include "desktop-handles.h"
+#include "desktop.h"
+#include "document-private.h"
+#include "xml/node.h"
+#include "xml/document.h"
+
+namespace Inkscape {
+class Application;
+
+namespace UI {
+namespace Dialog {
+
+
+/*####################
+ * Callback functions
+ */
+static void lpeeditor_selection_changed (Inkscape::Selection * selection, gpointer data)
+{
+ LivePathEffectEditor *lpeeditor = static_cast<LivePathEffectEditor *>(data);
+ lpeeditor->onSelectionChanged(selection);
+}
+
+static void lpeeditor_selection_modified (Inkscape::Selection *selection, guint flags, gpointer data)
+{
+ lpeeditor_selection_changed (selection, data);
+}
+
+
+static void lpeeditor_desktop_change(Inkscape::Application*, SPDesktop* desktop, void *data)
+{
+ if (!desktop) {
+ return;
+ }
+ LivePathEffectEditor* editor = reinterpret_cast<LivePathEffectEditor*>(data);
+ editor->setDesktop(desktop);
+}
+
+
+
+/*#######################
+ * LivePathEffectEditor
+ */
+LivePathEffectEditor::LivePathEffectEditor(Behavior::BehaviorFactory behavior_factory)
+ : Dialog (behavior_factory, "dialogs.livepatheffect", SP_VERB_DIALOG_LIVE_PATH_EFFECT),
+ combo_effecttype(Inkscape::LivePathEffect::LPETypeConverter),
+ button_apply(_("_Apply"), _("Apply chosen effect to selection")),
+ button_remove(_("_Remove"), _("Remove effect from selection")),
+ effectwidget(NULL),
+ explain_label("", Gtk::ALIGN_CENTER),
+ effectapplication_frame(_("Apply new effect")),
+ effectcontrol_frame(_("Current effect")),
+ current_desktop(NULL)
+{
+ // Top level vbox
+ Gtk::VBox *vbox = get_vbox();
+ vbox->set_spacing(4);
+
+ effectapplication_hbox.set_spacing(4);
+ effectcontrol_vbox.set_spacing(4);
+
+ effectapplication_hbox.pack_start(combo_effecttype, true, true);
+ effectapplication_hbox.pack_start(button_apply, true, true);
+ effectapplication_frame.add(effectapplication_hbox);
+
+ effectcontrol_vbox.pack_start(explain_label, true, true);
+ effectcontrol_vbox.pack_end(button_remove, true, true);
+ effectcontrol_frame.add(effectcontrol_vbox);
+
+ vbox->pack_start(effectapplication_frame, true, true);
+ vbox->pack_start(effectcontrol_frame, true, true);
+
+ // connect callback functions to buttons
+ button_apply.signal_clicked().connect(sigc::mem_fun(*this, &LivePathEffectEditor::onApply));
+ button_remove.signal_clicked().connect(sigc::mem_fun(*this, &LivePathEffectEditor::onRemove));
+
+ // connect callback functions to changes in selected desktop.
+ g_signal_connect( G_OBJECT(INKSCAPE), "activate_desktop",
+ G_CALLBACK(lpeeditor_desktop_change), this);
+
+ g_signal_connect( G_OBJECT(INKSCAPE), "deactivate_desktop",
+ G_CALLBACK(lpeeditor_desktop_change), this);
+
+ setDesktop(SP_ACTIVE_DESKTOP);
+ show_all_children();
+ button_remove.hide();
+}
+
+LivePathEffectEditor::~LivePathEffectEditor()
+{
+ if (effectwidget) {
+ effectcontrol_vbox.remove(*effectwidget);
+ effectwidget = NULL;
+ }
+
+ if (current_desktop) {
+ selection_changed_connection.disconnect();
+ selection_modified_connection.disconnect();
+ }
+}
+
+void
+LivePathEffectEditor::showParams(LivePathEffect::Effect* effect)
+{
+ if (effectwidget) {
+ effectcontrol_vbox.remove(*effectwidget);
+ effectwidget = NULL;
+ }
+
+ explain_label.set_markup("<b>" + effect->getName() + "</b>");
+ effectwidget = effect->getWidget();
+ if (effectwidget) {
+ effectcontrol_vbox.pack_start(*effectwidget, true, true);
+ }
+ button_remove.show();
+
+ effectcontrol_vbox.show_all_children();
+ // fixme: do resizing of dialog
+}
+
+void
+LivePathEffectEditor::showText(Glib::ustring const &str)
+{
+ if (effectwidget) {
+ effectcontrol_vbox.remove(*effectwidget);
+ effectwidget = NULL;
+ }
+
+ explain_label.set_label(str);
+ button_remove.hide();
+
+ // fixme: do resizing of dialog ?
+}
+
+void
+LivePathEffectEditor::set_sensitize_all(bool sensitive)
+{
+ combo_effecttype.set_sensitive(sensitive);
+ button_apply.set_sensitive(sensitive);
+ button_remove.set_sensitive(sensitive);
+}
+
+void
+LivePathEffectEditor::onSelectionChanged(Inkscape::Selection *sel)
+{
+ if ( sel && !sel->isEmpty() ) {
+ SPItem *item = sel->singleItem();
+ if ( item ) {
+ if ( SP_IS_SHAPE(item) ) {
+ SPShape *shape = SP_SHAPE(item);
+ LivePathEffectObject *lpeobj = sp_shape_get_livepatheffectobject(shape);
+ set_sensitize_all(true);
+ if (lpeobj) {
+ if (lpeobj->lpe) {
+ showParams(lpeobj->lpe);
+ } else {
+ showText(_("Unknown effect is applied"));
+ }
+ } else {
+ showText(_("No effect applied"));
+ button_remove.set_sensitive(false);
+ }
+ } else {
+ showText(_("Item is not a shape or path"));
+ set_sensitize_all(false);
+ }
+ } else {
+ showText(_("Only one item can be selected"));
+ set_sensitize_all(false);
+ }
+ } else {
+ showText(_("Empty selection"));
+ set_sensitize_all(false);
+ }
+}
+
+void
+LivePathEffectEditor::setDesktop(SPDesktop *desktop)
+{
+
+ if ( desktop == current_desktop ) {
+ return;
+ }
+
+ if (current_desktop) {
+ selection_changed_connection.disconnect();
+ selection_modified_connection.disconnect();
+ }
+
+ current_desktop = desktop;
+ if (desktop) {
+ Inkscape::Selection *selection = sp_desktop_selection(desktop);
+ selection_changed_connection = selection->connectChanged(
+ sigc::bind (sigc::ptr_fun(&lpeeditor_selection_changed), this ) );
+ selection_modified_connection = selection->connectModified(
+ sigc::bind (sigc::ptr_fun(&lpeeditor_selection_modified), this ) );
+
+ onSelectionChanged(selection);
+ } else {
+ onSelectionChanged(NULL);
+ }
+}
+
+
+
+
+/*########################################################################
+# BUTTON CLICK HANDLERS (callbacks)
+########################################################################*/
+
+// TODO: factor out the effect applying code which can be called from anywhere. (selection-chemistry.cpp also needs it)
+
+void
+LivePathEffectEditor::onApply()
+{
+ Inkscape::Selection *sel = _getSelection();
+ if ( sel && !sel->isEmpty() ) {
+ SPItem *item = sel->singleItem();
+ if ( item && SP_IS_SHAPE(item) ) {
+ SPDocument *doc = current_desktop->doc();
+
+ const Util::EnumData<LivePathEffect::EffectType>* data = combo_effecttype.get_active_data();
+ if (!data) return;
+
+ Inkscape::XML::Document *xml_doc = sp_document_repr_doc(doc);
+ Inkscape::XML::Node *repr = xml_doc->createElement("inkscape:path-effect");
+ repr->setAttribute("effect", data->key.c_str() );
+
+ SP_OBJECT_REPR(SP_DOCUMENT_DEFS(doc))->addChild(repr, NULL); // adds to <defs> and assigns the 'id' attribute
+ const gchar * repr_id = repr->attribute("id");
+ Inkscape::GC::release(repr);
+
+ gchar *href = g_strdup_printf("#%s", repr_id);
+ sp_shape_set_path_effect(SP_SHAPE(item), href);
+ g_free(href);
+
+ // make sure there is an original-d for paths!!!
+ if ( SP_IS_PATH(item) ) {
+ Inkscape::XML::Node *pathrepr = SP_OBJECT_REPR(item);
+ if ( ! pathrepr->attribute("inkscape:original-d") ) {
+ pathrepr->setAttribute("inkscape:original-d", pathrepr->attribute("d"));
+ }
+ }
+
+ sp_document_done(doc, SP_VERB_DIALOG_LIVE_PATH_EFFECT,
+ _("Create and apply path effect"));
+ }
+ }
+}
+
+void
+LivePathEffectEditor::onRemove()
+{
+ Inkscape::Selection *sel = _getSelection();
+ if ( sel && !sel->isEmpty() ) {
+ SPItem *item = sel->singleItem();
+ if ( item && SP_IS_SHAPE(item) ) {
+ sp_shape_remove_path_effect(SP_SHAPE(item));
+ sp_document_done ( sp_desktop_document (current_desktop), SP_VERB_DIALOG_LIVE_PATH_EFFECT,
+ _("Remove path effect") );
+ }
+ }
+}
+
+
+
+} // namespace Dialog
+} // namespace UI
+} // namespace Inkscape
+
index 30706553e2f2a178dbbe983b91151813249f5bbf..5a40cfd307403fd2b5e6548a9fa45e770d9720b8 100644 (file)
-/**\r
- * \brief LivePathEffect dialog\r
- *\r
- * Author:\r
- * Johan Engelen <j.b.c.engelen@ewi.utwente.nl>\r
- *\r
- * Copyright (C) 2007 Author\r
- *\r
- * Released under GNU GPL. Read the file 'COPYING' for more information.\r
- */\r
-\r
-#ifndef INKSCAPE_UI_DIALOG_LIVE_PATH_EFFECT_H\r
-#define INKSCAPE_UI_DIALOG_LIVE_PATH_EFFECT_H\r
-\r
-#include "dialog.h"\r
-#include "ui/widget/button.h"\r
-\r
-#include <gtkmm/label.h>\r
-#include <gtkmm/comboboxtext.h>\r
-#include <gtkmm/frame.h>\r
-#include "ui/widget/combo-enums.h"\r
-#include "live_effects/effect.h"\r
-\r
-class SPDesktop;\r
-\r
-namespace Inkscape {\r
-\r
-namespace UI {\r
-namespace Dialog {\r
-\r
-class LivePathEffectEditor : public Dialog {\r
-public:\r
- LivePathEffectEditor(Behavior::BehaviorFactory behavior_factory);\r
- virtual ~LivePathEffectEditor();\r
-\r
- static LivePathEffectEditor *create(Behavior::BehaviorFactory behavior_factory)\r
- { return new LivePathEffectEditor(behavior_factory); }\r
-\r
- void onSelectionChanged(Inkscape::Selection *sel);\r
- void setDesktop(SPDesktop *desktop);\r
-\r
-private:\r
- sigc::connection selection_changed_connection;\r
- sigc::connection selection_modified_connection;\r
-\r
- void set_sensitize_all(bool sensitive);\r
-\r
- void showParams(LivePathEffect::Effect* effect);\r
- void showText(Glib::ustring const &str);\r
-\r
- // callback methods for buttons on grids page.\r
- void onApply();\r
- void onRemove();\r
-\r
- Inkscape::UI::Widget::ComboBoxEnum<LivePathEffect::EffectType> combo_effecttype;\r
- Inkscape::UI::Widget::Button button_apply;\r
- Inkscape::UI::Widget::Button button_remove;\r
- Gtk::Widget * effectwidget;\r
- Gtk::Label explain_label;\r
- Gtk::Frame effectapplication_frame;\r
- Gtk::Frame effectcontrol_frame;\r
- Gtk::HBox effectapplication_hbox;\r
- Gtk::VBox effectcontrol_vbox;\r
-\r
- SPDesktop * current_desktop;\r
-\r
- LivePathEffectEditor(LivePathEffectEditor const &d);\r
- LivePathEffectEditor& operator=(LivePathEffectEditor const &d);\r
-};\r
-\r
-} // namespace Dialog\r
-} // namespace UI\r
-} // namespace Inkscape\r
-\r
-#endif // INKSCAPE_UI_DIALOG_LIVE_PATH_EFFECT_H\r
-\r
-/*\r
- Local Variables:\r
- mode:c++\r
- c-file-style:"stroustrup"\r
- c-file-offsets:((innamespace . 0)(inline-open . 0)(case-label . +))\r
- indent-tabs-mode:nil\r
- fill-column:99\r
- End:\r
-*/\r
-// vim: filetype=cpp:expandtab:shiftwidth=4:tabstop=8:softtabstop=4:encoding=utf-8:textwidth=99 :\r
+/**
+ * \brief LivePathEffect dialog
+ *
+ * Author:
+ * Johan Engelen <j.b.c.engelen@ewi.utwente.nl>
+ *
+ * Copyright (C) 2007 Author
+ *
+ * Released under GNU GPL. Read the file 'COPYING' for more information.
+ */
+
+#ifndef INKSCAPE_UI_DIALOG_LIVE_PATH_EFFECT_H
+#define INKSCAPE_UI_DIALOG_LIVE_PATH_EFFECT_H
+
+#include "dialog.h"
+#include "ui/widget/button.h"
+
+#include <gtkmm/label.h>
+#include <gtkmm/comboboxtext.h>
+#include <gtkmm/frame.h>
+#include "ui/widget/combo-enums.h"
+#include "live_effects/effect.h"
+
+class SPDesktop;
+
+namespace Inkscape {
+
+namespace UI {
+namespace Dialog {
+
+class LivePathEffectEditor : public Dialog {
+public:
+ LivePathEffectEditor(Behavior::BehaviorFactory behavior_factory);
+ virtual ~LivePathEffectEditor();
+
+ static LivePathEffectEditor *create(Behavior::BehaviorFactory behavior_factory)
+ { return new LivePathEffectEditor(behavior_factory); }
+
+ void onSelectionChanged(Inkscape::Selection *sel);
+ void setDesktop(SPDesktop *desktop);
+
+private:
+ sigc::connection selection_changed_connection;
+ sigc::connection selection_modified_connection;
+
+ void set_sensitize_all(bool sensitive);
+
+ void showParams(LivePathEffect::Effect* effect);
+ void showText(Glib::ustring const &str);
+
+ // callback methods for buttons on grids page.
+ void onApply();
+ void onRemove();
+
+ Inkscape::UI::Widget::ComboBoxEnum<LivePathEffect::EffectType> combo_effecttype;
+ Inkscape::UI::Widget::Button button_apply;
+ Inkscape::UI::Widget::Button button_remove;
+ Gtk::Widget * effectwidget;
+ Gtk::Label explain_label;
+ Gtk::Frame effectapplication_frame;
+ Gtk::Frame effectcontrol_frame;
+ Gtk::HBox effectapplication_hbox;
+ Gtk::VBox effectcontrol_vbox;
+
+ SPDesktop * current_desktop;
+
+ LivePathEffectEditor(LivePathEffectEditor const &d);
+ LivePathEffectEditor& operator=(LivePathEffectEditor const &d);
+};
+
+} // namespace Dialog
+} // namespace UI
+} // namespace Inkscape
+
+#endif // INKSCAPE_UI_DIALOG_LIVE_PATH_EFFECT_H
+
+/*
+ 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:encoding=utf-8:textwidth=99 :
index ae7197c29fbc9aa3bafe0897587cdc6cad87ebeb..634329ddcb45892d884ffcf3eb02f4a48340d47f 100644 (file)
--- a/src/ui/widget/point.cpp
+++ b/src/ui/widget/point.cpp
-/**\r
- * \brief Point Widget - A labelled text box, with spin buttons and optional\r
- * icon or suffix, for entering arbitrary coordinate values.\r
- *\r
- * Authors:\r
- * Johan Engelen <j.b.c.engelen@utwente.nl>\r
- * Carl Hetherington <inkscape@carlh.net>\r
- * Derek P. Moore <derekm@hackunix.org>\r
- * Bryce Harrington <bryce@bryceharrington.org>\r
- *\r
- * Copyright (C) 2007 Authors\r
- * Copyright (C) 2004 Authors\r
- *\r
- * Released under GNU GPL. Read the file 'COPYING' for more information.\r
- */\r
-\r
-#ifdef HAVE_CONFIG_H\r
-# include <config.h>\r
-#endif\r
-\r
-\r
-#include "ui/widget/point.h"\r
-#include "ui/widget/labelled.h"\r
-#include "ui/widget/scalar.h"\r
-#include <gtkmm/box.h>\r
-\r
-namespace Inkscape {\r
-namespace UI {\r
-namespace Widget {\r
-\r
-/**\r
- * Construct a Point Widget.\r
- *\r
- * \param label Label.\r
- * \param suffix Suffix, placed after the widget (defaults to "").\r
- * \param icon Icon filename, placed before the label (defaults to "").\r
- * \param mnemonic Mnemonic toggle; if true, an underscore (_) in the label\r
- * indicates the next character should be used for the\r
- * mnemonic accelerator key (defaults to false).\r
- */\r
-Point::Point(Glib::ustring const &label, Glib::ustring const &tooltip,\r
- Glib::ustring const &suffix,\r
- Glib::ustring const &icon,\r
- bool mnemonic)\r
- : Labelled(label, tooltip, new Gtk::VBox(), suffix, icon, mnemonic),\r
- xwidget("X:",""),\r
- ywidget("Y:","")\r
-{\r
- static_cast<Gtk::VBox*>(_widget)->pack_start(xwidget, true, true);\r
- static_cast<Gtk::VBox*>(_widget)->pack_start(ywidget, true, true);\r
- static_cast<Gtk::VBox*>(_widget)->show_all_children();\r
-}\r
-\r
-/**\r
- * Construct a Point Widget.\r
- *\r
- * \param label Label.\r
- * \param digits Number of decimal digits to display.\r
- * \param suffix Suffix, placed after the widget (defaults to "").\r
- * \param icon Icon filename, placed before the label (defaults to "").\r
- * \param mnemonic Mnemonic toggle; if true, an underscore (_) in the label\r
- * indicates the next character should be used for the\r
- * mnemonic accelerator key (defaults to false).\r
- */\r
-Point::Point(Glib::ustring const &label, Glib::ustring const &tooltip,\r
- unsigned digits,\r
- Glib::ustring const &suffix,\r
- Glib::ustring const &icon,\r
- bool mnemonic)\r
- : Labelled(label, tooltip, new Gtk::VBox(), suffix, icon, mnemonic),\r
- xwidget("X:","", digits),\r
- ywidget("Y:","", digits)\r
-{\r
- static_cast<Gtk::VBox*>(_widget)->pack_start(xwidget, true, true);\r
- static_cast<Gtk::VBox*>(_widget)->pack_start(ywidget, true, true);\r
- static_cast<Gtk::VBox*>(_widget)->show_all_children();\r
-}\r
-\r
-/**\r
- * Construct a Point Widget.\r
- *\r
- * \param label Label.\r
- * \param adjust Adjustment to use for the SpinButton.\r
- * \param digits Number of decimal digits to display (defaults to 0).\r
- * \param suffix Suffix, placed after the widget (defaults to "").\r
- * \param icon Icon filename, placed before the label (defaults to "").\r
- * \param mnemonic Mnemonic toggle; if true, an underscore (_) in the label\r
- * indicates the next character should be used for the\r
- * mnemonic accelerator key (defaults to true).\r
- */\r
-Point::Point(Glib::ustring const &label, Glib::ustring const &tooltip,\r
- Gtk::Adjustment &adjust,\r
- unsigned digits,\r
- Glib::ustring const &suffix,\r
- Glib::ustring const &icon,\r
- bool mnemonic)\r
- : Labelled(label, tooltip, new Gtk::VBox(), suffix, icon, mnemonic),\r
- xwidget("X:","", adjust, digits),\r
- ywidget("Y:","", adjust, digits)\r
-{\r
- static_cast<Gtk::VBox*>(_widget)->pack_start(xwidget, true, true);\r
- static_cast<Gtk::VBox*>(_widget)->pack_start(ywidget, true, true);\r
- static_cast<Gtk::VBox*>(_widget)->show_all_children();\r
-}\r
-\r
-/** Fetches the precision of the spin buton */\r
-unsigned\r
-Point::getDigits() const\r
-{\r
- return xwidget.getDigits();\r
-}\r
-\r
-/** Gets the current step ingrement used by the spin button */\r
-double\r
-Point::getStep() const\r
-{\r
- return xwidget.getStep();\r
-}\r
-\r
-/** Gets the current page increment used by the spin button */\r
-double\r
-Point::getPage() const\r
-{\r
- return xwidget.getPage();\r
-}\r
-\r
-/** Gets the minimum range value allowed for the spin button */\r
-double\r
-Point::getRangeMin() const\r
-{\r
- return xwidget.getRangeMin();\r
-}\r
-\r
-/** Gets the maximum range value allowed for the spin button */\r
-double\r
-Point::getRangeMax() const\r
-{\r
- return xwidget.getRangeMax();\r
-}\r
-\r
-/** Get the value in the spin_button . */\r
-double\r
-Point::getXValue() const\r
-{\r
- return xwidget.getValue();\r
-}\r
-double\r
-Point::getYValue() const\r
-{\r
- return ywidget.getValue();\r
-}\r
-\r
-/** Get the value spin_button represented as an integer. */\r
-int\r
-Point::getXValueAsInt() const\r
-{\r
- return xwidget.getValueAsInt();\r
-}\r
-int\r
-Point::getYValueAsInt() const\r
-{\r
- return ywidget.getValueAsInt();\r
-}\r
-\r
-\r
-/** Sets the precision to be displayed by the spin button */\r
-void\r
-Point::setDigits(unsigned digits)\r
-{\r
- xwidget.setDigits(digits);\r
- ywidget.setDigits(digits);\r
-}\r
-\r
-/** Sets the step and page increments for the spin button */\r
-void\r
-Point::setIncrements(double step, double page)\r
-{\r
- xwidget.setIncrements(step, page);\r
- ywidget.setIncrements(step, page);\r
-}\r
-\r
-/** Sets the minimum and maximum range allowed for the spin button */\r
-void\r
-Point::setRange(double min, double max)\r
-{\r
- xwidget.setRange(min, max);\r
- ywidget.setRange(min, max);\r
-}\r
-\r
-/** Sets the value of the spin button */\r
-void\r
-Point::setValue(double xvalue, double yvalue)\r
-{\r
- xwidget.setValue(xvalue);\r
- ywidget.setValue(yvalue);\r
-}\r
-\r
-/** Manually forces an update of the spin button */\r
-void\r
-Point::update() {\r
- xwidget.update();\r
- ywidget.update();\r
-}\r
-\r
-/** Check 'setProgrammatically' of both scalar widgets. False if value is changed by user by clicking the widget. */\r
-bool\r
-Point::setProgrammatically() {\r
- return (xwidget.setProgrammatically || ywidget.setProgrammatically);\r
-}\r
-\r
-void\r
-Point::clearProgrammatically() {\r
- xwidget.setProgrammatically = false;\r
- ywidget.setProgrammatically = false;\r
-}\r
-\r
-\r
-/** Signal raised when the spin button's value changes */\r
-Glib::SignalProxy0<void>\r
-Point::signal_x_value_changed()\r
-{\r
- return xwidget.signal_value_changed();\r
-}\r
-Glib::SignalProxy0<void>\r
-Point::signal_y_value_changed()\r
-{\r
- return ywidget.signal_value_changed();\r
-}\r
-\r
-\r
-} // namespace Widget\r
-} // namespace UI\r
-} // namespace Inkscape\r
-\r
-/*\r
- Local Variables:\r
- mode:c++\r
- c-file-style:"stroustrup"\r
- c-file-offsets:((innamespace . 0)(inline-open . 0)(case-label . +))\r
- indent-tabs-mode:nil\r
- fill-column:99\r
- End:\r
-*/\r
-// vim: filetype=cpp:expandtab:shiftwidth=4:tabstop=8:softtabstop=4:encoding=utf-8:textwidth=99 :\r
+/**
+ * \brief Point Widget - A labelled text box, with spin buttons and optional
+ * icon or suffix, for entering arbitrary coordinate values.
+ *
+ * Authors:
+ * Johan Engelen <j.b.c.engelen@utwente.nl>
+ * Carl Hetherington <inkscape@carlh.net>
+ * Derek P. Moore <derekm@hackunix.org>
+ * Bryce Harrington <bryce@bryceharrington.org>
+ *
+ * Copyright (C) 2007 Authors
+ * Copyright (C) 2004 Authors
+ *
+ * Released under GNU GPL. Read the file 'COPYING' for more information.
+ */
+
+#ifdef HAVE_CONFIG_H
+# include <config.h>
+#endif
+
+
+#include "ui/widget/point.h"
+#include "ui/widget/labelled.h"
+#include "ui/widget/scalar.h"
+#include <gtkmm/box.h>
+
+namespace Inkscape {
+namespace UI {
+namespace Widget {
+
+/**
+ * Construct a Point Widget.
+ *
+ * \param label Label.
+ * \param suffix Suffix, placed after the widget (defaults to "").
+ * \param icon Icon filename, placed before the label (defaults to "").
+ * \param mnemonic Mnemonic toggle; if true, an underscore (_) in the label
+ * indicates the next character should be used for the
+ * mnemonic accelerator key (defaults to false).
+ */
+Point::Point(Glib::ustring const &label, Glib::ustring const &tooltip,
+ Glib::ustring const &suffix,
+ Glib::ustring const &icon,
+ bool mnemonic)
+ : Labelled(label, tooltip, new Gtk::VBox(), suffix, icon, mnemonic),
+ xwidget("X:",""),
+ ywidget("Y:","")
+{
+ static_cast<Gtk::VBox*>(_widget)->pack_start(xwidget, true, true);
+ static_cast<Gtk::VBox*>(_widget)->pack_start(ywidget, true, true);
+ static_cast<Gtk::VBox*>(_widget)->show_all_children();
+}
+
+/**
+ * Construct a Point Widget.
+ *
+ * \param label Label.
+ * \param digits Number of decimal digits to display.
+ * \param suffix Suffix, placed after the widget (defaults to "").
+ * \param icon Icon filename, placed before the label (defaults to "").
+ * \param mnemonic Mnemonic toggle; if true, an underscore (_) in the label
+ * indicates the next character should be used for the
+ * mnemonic accelerator key (defaults to false).
+ */
+Point::Point(Glib::ustring const &label, Glib::ustring const &tooltip,
+ unsigned digits,
+ Glib::ustring const &suffix,
+ Glib::ustring const &icon,
+ bool mnemonic)
+ : Labelled(label, tooltip, new Gtk::VBox(), suffix, icon, mnemonic),
+ xwidget("X:","", digits),
+ ywidget("Y:","", digits)
+{
+ static_cast<Gtk::VBox*>(_widget)->pack_start(xwidget, true, true);
+ static_cast<Gtk::VBox*>(_widget)->pack_start(ywidget, true, true);
+ static_cast<Gtk::VBox*>(_widget)->show_all_children();
+}
+
+/**
+ * Construct a Point Widget.
+ *
+ * \param label Label.
+ * \param adjust Adjustment to use for the SpinButton.
+ * \param digits Number of decimal digits to display (defaults to 0).
+ * \param suffix Suffix, placed after the widget (defaults to "").
+ * \param icon Icon filename, placed before the label (defaults to "").
+ * \param mnemonic Mnemonic toggle; if true, an underscore (_) in the label
+ * indicates the next character should be used for the
+ * mnemonic accelerator key (defaults to true).
+ */
+Point::Point(Glib::ustring const &label, Glib::ustring const &tooltip,
+ Gtk::Adjustment &adjust,
+ unsigned digits,
+ Glib::ustring const &suffix,
+ Glib::ustring const &icon,
+ bool mnemonic)
+ : Labelled(label, tooltip, new Gtk::VBox(), suffix, icon, mnemonic),
+ xwidget("X:","", adjust, digits),
+ ywidget("Y:","", adjust, digits)
+{
+ static_cast<Gtk::VBox*>(_widget)->pack_start(xwidget, true, true);
+ static_cast<Gtk::VBox*>(_widget)->pack_start(ywidget, true, true);
+ static_cast<Gtk::VBox*>(_widget)->show_all_children();
+}
+
+/** Fetches the precision of the spin buton */
+unsigned
+Point::getDigits() const
+{
+ return xwidget.getDigits();
+}
+
+/** Gets the current step ingrement used by the spin button */
+double
+Point::getStep() const
+{
+ return xwidget.getStep();
+}
+
+/** Gets the current page increment used by the spin button */
+double
+Point::getPage() const
+{
+ return xwidget.getPage();
+}
+
+/** Gets the minimum range value allowed for the spin button */
+double
+Point::getRangeMin() const
+{
+ return xwidget.getRangeMin();
+}
+
+/** Gets the maximum range value allowed for the spin button */
+double
+Point::getRangeMax() const
+{
+ return xwidget.getRangeMax();
+}
+
+/** Get the value in the spin_button . */
+double
+Point::getXValue() const
+{
+ return xwidget.getValue();
+}
+double
+Point::getYValue() const
+{
+ return ywidget.getValue();
+}
+
+/** Get the value spin_button represented as an integer. */
+int
+Point::getXValueAsInt() const
+{
+ return xwidget.getValueAsInt();
+}
+int
+Point::getYValueAsInt() const
+{
+ return ywidget.getValueAsInt();
+}
+
+
+/** Sets the precision to be displayed by the spin button */
+void
+Point::setDigits(unsigned digits)
+{
+ xwidget.setDigits(digits);
+ ywidget.setDigits(digits);
+}
+
+/** Sets the step and page increments for the spin button */
+void
+Point::setIncrements(double step, double page)
+{
+ xwidget.setIncrements(step, page);
+ ywidget.setIncrements(step, page);
+}
+
+/** Sets the minimum and maximum range allowed for the spin button */
+void
+Point::setRange(double min, double max)
+{
+ xwidget.setRange(min, max);
+ ywidget.setRange(min, max);
+}
+
+/** Sets the value of the spin button */
+void
+Point::setValue(double xvalue, double yvalue)
+{
+ xwidget.setValue(xvalue);
+ ywidget.setValue(yvalue);
+}
+
+/** Manually forces an update of the spin button */
+void
+Point::update() {
+ xwidget.update();
+ ywidget.update();
+}
+
+/** Check 'setProgrammatically' of both scalar widgets. False if value is changed by user by clicking the widget. */
+bool
+Point::setProgrammatically() {
+ return (xwidget.setProgrammatically || ywidget.setProgrammatically);
+}
+
+void
+Point::clearProgrammatically() {
+ xwidget.setProgrammatically = false;
+ ywidget.setProgrammatically = false;
+}
+
+
+/** Signal raised when the spin button's value changes */
+Glib::SignalProxy0<void>
+Point::signal_x_value_changed()
+{
+ return xwidget.signal_value_changed();
+}
+Glib::SignalProxy0<void>
+Point::signal_y_value_changed()
+{
+ return ywidget.signal_value_changed();
+}
+
+
+} // namespace Widget
+} // namespace UI
+} // namespace Inkscape
+
+/*
+ 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:encoding=utf-8:textwidth=99 :
diff --git a/src/ui/widget/point.h b/src/ui/widget/point.h
index 7653ceaa43a593a79355202c99ebd5f907606123..b65a13e2035de9953c67f0ff8b230267960ebfb7 100644 (file)
--- a/src/ui/widget/point.h
+++ b/src/ui/widget/point.h
-/**\r
- * \brief Point Widget - A labelled text box, with spin buttons and optional\r
- * icon or suffix, for entering arbitrary coordinate values.\r
- *\r
- * Authors:\r
- * Johan Engelen <j.b.c.engelen@utwente.nl>\r
- * Carl Hetherington <inkscape@carlh.net>\r
- * Derek P. Moore <derekm@hackunix.org>\r
- * Bryce Harrington <bryce@bryceharrington.org>\r
- *\r
- * Copyright (C) 2007 Authors\r
- * Copyright (C) 2004 Authors\r
- *\r
- * Released under GNU GPL. Read the file 'COPYING' for more information.\r
- */\r
-\r
-#ifndef INKSCAPE_UI_WIDGET_POINT_H\r
-#define INKSCAPE_UI_WIDGET_POINT_H\r
-\r
-#include <gtkmm/adjustment.h>\r
-#include <gtkmm/spinbutton.h>\r
-\r
-#include "ui/widget/labelled.h"\r
-#include "ui/widget/scalar.h"\r
-\r
-namespace Inkscape {\r
-namespace UI {\r
-namespace Widget {\r
-\r
-class Point : public Labelled\r
-{\r
-public:\r
- Point( Glib::ustring const &label,\r
- Glib::ustring const &tooltip,\r
- Glib::ustring const &suffix = "",\r
- Glib::ustring const &icon = "",\r
- bool mnemonic = true);\r
- Point( Glib::ustring const &label,\r
- Glib::ustring const &tooltip,\r
- unsigned digits,\r
- Glib::ustring const &suffix = "",\r
- Glib::ustring const &icon = "",\r
- bool mnemonic = true);\r
- Point( Glib::ustring const &label,\r
- Glib::ustring const &tooltip,\r
- Gtk::Adjustment &adjust,\r
- unsigned digits = 0,\r
- Glib::ustring const &suffix = "",\r
- Glib::ustring const &icon = "",\r
- bool mnemonic = true);\r
-\r
- unsigned getDigits() const;\r
- double getStep() const;\r
- double getPage() const;\r
- double getRangeMin() const;\r
- double getRangeMax() const;\r
- bool getSnapToTicks() const;\r
- double getXValue() const;\r
- double getYValue() const;\r
- int getXValueAsInt() const;\r
- int getYValueAsInt() const;\r
-\r
- void setDigits(unsigned digits);\r
- void setIncrements(double step, double page);\r
- void setRange(double min, double max);\r
- void setValue(double xvalue, double yvalue);\r
-\r
- void update();\r
-\r
- Glib::SignalProxy0<void> signal_x_value_changed();\r
- Glib::SignalProxy0<void> signal_y_value_changed();\r
-\r
- bool setProgrammatically(); // true if the value was set by setValue, not changed by the user; \r
- // if a callback checks it, it must reset it back to false\r
- void clearProgrammatically();\r
-\r
-protected:\r
- Scalar xwidget, ywidget;\r
-\r
-};\r
-\r
-} // namespace Widget\r
-} // namespace UI\r
-} // namespace Inkscape\r
-\r
-#endif // INKSCAPE_UI_WIDGET_POINT_H\r
-\r
-/*\r
- Local Variables:\r
- mode:c++\r
- c-file-style:"stroustrup"\r
- c-file-offsets:((innamespace . 0)(inline-open . 0)(case-label . +))\r
- indent-tabs-mode:nil\r
- fill-column:99\r
- End:\r
-*/\r
-// vim: filetype=cpp:expandtab:shiftwidth=4:tabstop=8:softtabstop=4:encoding=utf-8:textwidth=99 :\r
+/**
+ * \brief Point Widget - A labelled text box, with spin buttons and optional
+ * icon or suffix, for entering arbitrary coordinate values.
+ *
+ * Authors:
+ * Johan Engelen <j.b.c.engelen@utwente.nl>
+ * Carl Hetherington <inkscape@carlh.net>
+ * Derek P. Moore <derekm@hackunix.org>
+ * Bryce Harrington <bryce@bryceharrington.org>
+ *
+ * Copyright (C) 2007 Authors
+ * Copyright (C) 2004 Authors
+ *
+ * Released under GNU GPL. Read the file 'COPYING' for more information.
+ */
+
+#ifndef INKSCAPE_UI_WIDGET_POINT_H
+#define INKSCAPE_UI_WIDGET_POINT_H
+
+#include <gtkmm/adjustment.h>
+#include <gtkmm/spinbutton.h>
+
+#include "ui/widget/labelled.h"
+#include "ui/widget/scalar.h"
+
+namespace Inkscape {
+namespace UI {
+namespace Widget {
+
+class Point : public Labelled
+{
+public:
+ Point( Glib::ustring const &label,
+ Glib::ustring const &tooltip,
+ Glib::ustring const &suffix = "",
+ Glib::ustring const &icon = "",
+ bool mnemonic = true);
+ Point( Glib::ustring const &label,
+ Glib::ustring const &tooltip,
+ unsigned digits,
+ Glib::ustring const &suffix = "",
+ Glib::ustring const &icon = "",
+ bool mnemonic = true);
+ Point( Glib::ustring const &label,
+ Glib::ustring const &tooltip,
+ Gtk::Adjustment &adjust,
+ unsigned digits = 0,
+ Glib::ustring const &suffix = "",
+ Glib::ustring const &icon = "",
+ bool mnemonic = true);
+
+ unsigned getDigits() const;
+ double getStep() const;
+ double getPage() const;
+ double getRangeMin() const;
+ double getRangeMax() const;
+ bool getSnapToTicks() const;
+ double getXValue() const;
+ double getYValue() const;
+ int getXValueAsInt() const;
+ int getYValueAsInt() const;
+
+ void setDigits(unsigned digits);
+ void setIncrements(double step, double page);
+ void setRange(double min, double max);
+ void setValue(double xvalue, double yvalue);
+
+ void update();
+
+ Glib::SignalProxy0<void> signal_x_value_changed();
+ Glib::SignalProxy0<void> signal_y_value_changed();
+
+ bool setProgrammatically(); // true if the value was set by setValue, not changed by the user;
+ // if a callback checks it, it must reset it back to false
+ void clearProgrammatically();
+
+protected:
+ Scalar xwidget, ywidget;
+
+};
+
+} // namespace Widget
+} // namespace UI
+} // namespace Inkscape
+
+#endif // INKSCAPE_UI_WIDGET_POINT_H
+
+/*
+ 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:encoding=utf-8:textwidth=99 :
index 1d99f406cf4ef5824066e0807e464de7078413de..9fb0e7be22ef8dbae448aec8a94685839d8ddd28 100644 (file)
--- a/src/ui/widget/random.cpp
+++ b/src/ui/widget/random.cpp
-/**\r
- * \brief Scalar Widget - A labelled text box, with spin buttons and optional\r
- * icon or suffix, for entering arbitrary number values. It adds an extra\r
- * number called "startseed", that is not UI edittable, but should be put in SVG.\r
- * This does NOT generate a random number, but provides merely the saving of \r
- * the startseed value.\r
- *\r
- * Authors:\r
- * Carl Hetherington <inkscape@carlh.net>\r
- * Derek P. Moore <derekm@hackunix.org>\r
- * Bryce Harrington <bryce@bryceharrington.org>\r
- *\r
- * Copyright (C) 2004 Carl Hetherington\r
- *\r
- * Released under GNU GPL. Read the file 'COPYING' for more information.\r
- */\r
-\r
-#ifdef HAVE_CONFIG_H\r
-# include <config.h>\r
-#endif\r
-\r
-\r
-#include "random.h"\r
-#include "widgets/icon.h"\r
-\r
-#include <glibmm/i18n.h>\r
-\r
-namespace Inkscape {\r
-namespace UI {\r
-namespace Widget {\r
-\r
-/**\r
- * Construct a Random scalar Widget.\r
- *\r
- * \param label Label.\r
- * \param suffix Suffix, placed after the widget (defaults to "").\r
- * \param icon Icon filename, placed before the label (defaults to "").\r
- * \param mnemonic Mnemonic toggle; if true, an underscore (_) in the label\r
- * indicates the next character should be used for the\r
- * mnemonic accelerator key (defaults to false).\r
- */\r
-Random::Random(Glib::ustring const &label, Glib::ustring const &tooltip,\r
- Glib::ustring const &suffix,\r
- Glib::ustring const &icon,\r
- bool mnemonic)\r
- : Scalar(label, tooltip, suffix, icon, mnemonic)\r
-{\r
- startseed = 0;\r
- addReseedButton();\r
-}\r
-\r
-/**\r
- * Construct a Random Scalar Widget.\r
- *\r
- * \param label Label.\r
- * \param digits Number of decimal digits to display.\r
- * \param suffix Suffix, placed after the widget (defaults to "").\r
- * \param icon Icon filename, placed before the label (defaults to "").\r
- * \param mnemonic Mnemonic toggle; if true, an underscore (_) in the label\r
- * indicates the next character should be used for the\r
- * mnemonic accelerator key (defaults to false).\r
- */\r
-Random::Random(Glib::ustring const &label, Glib::ustring const &tooltip,\r
- unsigned digits,\r
- Glib::ustring const &suffix,\r
- Glib::ustring const &icon,\r
- bool mnemonic)\r
- : Scalar(label, tooltip, digits, suffix, icon, mnemonic)\r
-{\r
- startseed = 0;\r
- addReseedButton();\r
-}\r
-\r
-/**\r
- * Construct a Random Scalar Widget.\r
- *\r
- * \param label Label.\r
- * \param adjust Adjustment to use for the SpinButton.\r
- * \param digits Number of decimal digits to display (defaults to 0).\r
- * \param suffix Suffix, placed after the widget (defaults to "").\r
- * \param icon Icon filename, placed before the label (defaults to "").\r
- * \param mnemonic Mnemonic toggle; if true, an underscore (_) in the label\r
- * indicates the next character should be used for the\r
- * mnemonic accelerator key (defaults to true).\r
- */\r
-Random::Random(Glib::ustring const &label, Glib::ustring const &tooltip,\r
- Gtk::Adjustment &adjust,\r
- unsigned digits,\r
- Glib::ustring const &suffix,\r
- Glib::ustring const &icon,\r
- bool mnemonic)\r
- : Scalar(label, tooltip, adjust, digits, suffix, icon, mnemonic)\r
-{\r
- startseed = 0;\r
- addReseedButton();\r
-}\r
-\r
-/** Gets the startseed */\r
-long\r
-Random::getStartSeed() const\r
-{\r
- return startseed;\r
-}\r
-\r
-/** Sets the startseed number */\r
-void\r
-Random::setStartSeed(long newseed)\r
-{\r
- startseed = newseed;\r
-}\r
-\r
-/** Add reseed button to the widget */\r
-void\r
-Random::addReseedButton()\r
-{\r
- Gtk::Widget* pIcon = Gtk::manage( sp_icon_get_icon( "draw_spiral", Inkscape::ICON_SIZE_BUTTON) );\r
- Gtk::Button * pButton = Gtk::manage(new Gtk::Button());\r
- pButton->set_relief(Gtk::RELIEF_NONE);\r
- pIcon->show();\r
- pButton->add(*pIcon);\r
- pButton->show();\r
- pButton->signal_clicked().connect(sigc::mem_fun(*this, &Random::onReseedButtonClick));\r
- _tooltips.set_tip(*pButton, _("Reseed the random number generator; this creates a different sequence of random numbers."));\r
-\r
- pack_start(*pButton, Gtk::PACK_SHRINK, 0);\r
-}\r
-\r
-void\r
-Random::onReseedButtonClick()\r
-{\r
- startseed = g_random_int();\r
- signal_reseeded.emit();\r
-}\r
-\r
-} // namespace Widget\r
-} // namespace UI\r
-} // namespace Inkscape\r
-\r
-/*\r
- Local Variables:\r
- mode:c++\r
- c-file-style:"stroustrup"\r
- c-file-offsets:((innamespace . 0)(inline-open . 0)(case-label . +))\r
- indent-tabs-mode:nil\r
- fill-column:99\r
- End:\r
-*/\r
-// vim: filetype=cpp:expandtab:shiftwidth=4:tabstop=8:softtabstop=4:encoding=utf-8:textwidth=99 :\r
+/**
+ * \brief Scalar Widget - A labelled text box, with spin buttons and optional
+ * icon or suffix, for entering arbitrary number values. It adds an extra
+ * number called "startseed", that is not UI edittable, but should be put in SVG.
+ * This does NOT generate a random number, but provides merely the saving of
+ * the startseed value.
+ *
+ * Authors:
+ * Carl Hetherington <inkscape@carlh.net>
+ * Derek P. Moore <derekm@hackunix.org>
+ * Bryce Harrington <bryce@bryceharrington.org>
+ *
+ * Copyright (C) 2004 Carl Hetherington
+ *
+ * Released under GNU GPL. Read the file 'COPYING' for more information.
+ */
+
+#ifdef HAVE_CONFIG_H
+# include <config.h>
+#endif
+
+
+#include "random.h"
+#include "widgets/icon.h"
+
+#include <glibmm/i18n.h>
+
+namespace Inkscape {
+namespace UI {
+namespace Widget {
+
+/**
+ * Construct a Random scalar Widget.
+ *
+ * \param label Label.
+ * \param suffix Suffix, placed after the widget (defaults to "").
+ * \param icon Icon filename, placed before the label (defaults to "").
+ * \param mnemonic Mnemonic toggle; if true, an underscore (_) in the label
+ * indicates the next character should be used for the
+ * mnemonic accelerator key (defaults to false).
+ */
+Random::Random(Glib::ustring const &label, Glib::ustring const &tooltip,
+ Glib::ustring const &suffix,
+ Glib::ustring const &icon,
+ bool mnemonic)
+ : Scalar(label, tooltip, suffix, icon, mnemonic)
+{
+ startseed = 0;
+ addReseedButton();
+}
+
+/**
+ * Construct a Random Scalar Widget.
+ *
+ * \param label Label.
+ * \param digits Number of decimal digits to display.
+ * \param suffix Suffix, placed after the widget (defaults to "").
+ * \param icon Icon filename, placed before the label (defaults to "").
+ * \param mnemonic Mnemonic toggle; if true, an underscore (_) in the label
+ * indicates the next character should be used for the
+ * mnemonic accelerator key (defaults to false).
+ */
+Random::Random(Glib::ustring const &label, Glib::ustring const &tooltip,
+ unsigned digits,
+ Glib::ustring const &suffix,
+ Glib::ustring const &icon,
+ bool mnemonic)
+ : Scalar(label, tooltip, digits, suffix, icon, mnemonic)
+{
+ startseed = 0;
+ addReseedButton();
+}
+
+/**
+ * Construct a Random Scalar Widget.
+ *
+ * \param label Label.
+ * \param adjust Adjustment to use for the SpinButton.
+ * \param digits Number of decimal digits to display (defaults to 0).
+ * \param suffix Suffix, placed after the widget (defaults to "").
+ * \param icon Icon filename, placed before the label (defaults to "").
+ * \param mnemonic Mnemonic toggle; if true, an underscore (_) in the label
+ * indicates the next character should be used for the
+ * mnemonic accelerator key (defaults to true).
+ */
+Random::Random(Glib::ustring const &label, Glib::ustring const &tooltip,
+ Gtk::Adjustment &adjust,
+ unsigned digits,
+ Glib::ustring const &suffix,
+ Glib::ustring const &icon,
+ bool mnemonic)
+ : Scalar(label, tooltip, adjust, digits, suffix, icon, mnemonic)
+{
+ startseed = 0;
+ addReseedButton();
+}
+
+/** Gets the startseed */
+long
+Random::getStartSeed() const
+{
+ return startseed;
+}
+
+/** Sets the startseed number */
+void
+Random::setStartSeed(long newseed)
+{
+ startseed = newseed;
+}
+
+/** Add reseed button to the widget */
+void
+Random::addReseedButton()
+{
+ Gtk::Widget* pIcon = Gtk::manage( sp_icon_get_icon( "draw_spiral", Inkscape::ICON_SIZE_BUTTON) );
+ Gtk::Button * pButton = Gtk::manage(new Gtk::Button());
+ pButton->set_relief(Gtk::RELIEF_NONE);
+ pIcon->show();
+ pButton->add(*pIcon);
+ pButton->show();
+ pButton->signal_clicked().connect(sigc::mem_fun(*this, &Random::onReseedButtonClick));
+ _tooltips.set_tip(*pButton, _("Reseed the random number generator; this creates a different sequence of random numbers."));
+
+ pack_start(*pButton, Gtk::PACK_SHRINK, 0);
+}
+
+void
+Random::onReseedButtonClick()
+{
+ startseed = g_random_int();
+ signal_reseeded.emit();
+}
+
+} // namespace Widget
+} // namespace UI
+} // namespace Inkscape
+
+/*
+ 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:encoding=utf-8:textwidth=99 :
diff --git a/src/ui/widget/random.h b/src/ui/widget/random.h
index 56c39ccc1a88b057a7dd988a19582ecca3565d7f..93c6c2ff43a5153d9898d929f62ad8d25f6e74e2 100644 (file)
--- a/src/ui/widget/random.h
+++ b/src/ui/widget/random.h
-/**\r
- * \brief Random Scalar Widget - A labelled text box, with spin buttons and optional\r
- * icon or suffix, for entering arbitrary number values and generating a random number from it.\r
- *\r
- * Authors:\r
- * Johan Engelen <j.b.c.engelen@ewi.utwente.nl>\r
- *\r
- * Copyright (C) 2007 Author\r
- *\r
- * Released under GNU GPL. Read the file 'COPYING' for more information.\r
- */\r
-\r
-#ifndef INKSCAPE_UI_WIDGET_RANDOM_H\r
-#define INKSCAPE_UI_WIDGET_RANDOM_H\r
-\r
-#include "scalar.h"\r
-\r
-namespace Inkscape {\r
-namespace UI {\r
-namespace Widget {\r
-\r
-class Random : public Scalar\r
-{\r
-public:\r
- Random(Glib::ustring const &label,\r
- Glib::ustring const &tooltip,\r
- Glib::ustring const &suffix = "",\r
- Glib::ustring const &icon = "",\r
- bool mnemonic = true);\r
- Random(Glib::ustring const &label,\r
- Glib::ustring const &tooltip,\r
- unsigned digits,\r
- Glib::ustring const &suffix = "",\r
- Glib::ustring const &icon = "",\r
- bool mnemonic = true);\r
- Random(Glib::ustring const &label,\r
- Glib::ustring const &tooltip,\r
- Gtk::Adjustment &adjust,\r
- unsigned digits = 0,\r
- Glib::ustring const &suffix = "",\r
- Glib::ustring const &icon = "",\r
- bool mnemonic = true);\r
-\r
- long getStartSeed() const;\r
- void setStartSeed(long newseed);\r
-\r
- sigc::signal <void> signal_reseeded;\r
-\r
-protected:\r
- long startseed;\r
-\r
-private:\r
- void addReseedButton();\r
- void onReseedButtonClick();\r
-};\r
-\r
-} // namespace Widget\r
-} // namespace UI\r
-} // namespace Inkscape\r
-\r
-#endif // INKSCAPE_UI_WIDGET_RANDOM_H\r
-\r
-/*\r
- Local Variables:\r
- mode:c++\r
- c-file-style:"stroustrup"\r
- c-file-offsets:((innamespace . 0)(inline-open . 0)(case-label . +))\r
- indent-tabs-mode:nil\r
- fill-column:99\r
- End:\r
-*/\r
-// vim: filetype=cpp:expandtab:shiftwidth=4:tabstop=8:softtabstop=4:encoding=utf-8:textwidth=99 :\r
+/**
+ * \brief Random Scalar Widget - A labelled text box, with spin buttons and optional
+ * icon or suffix, for entering arbitrary number values and generating a random number from it.
+ *
+ * Authors:
+ * Johan Engelen <j.b.c.engelen@ewi.utwente.nl>
+ *
+ * Copyright (C) 2007 Author
+ *
+ * Released under GNU GPL. Read the file 'COPYING' for more information.
+ */
+
+#ifndef INKSCAPE_UI_WIDGET_RANDOM_H
+#define INKSCAPE_UI_WIDGET_RANDOM_H
+
+#include "scalar.h"
+
+namespace Inkscape {
+namespace UI {
+namespace Widget {
+
+class Random : public Scalar
+{
+public:
+ Random(Glib::ustring const &label,
+ Glib::ustring const &tooltip,
+ Glib::ustring const &suffix = "",
+ Glib::ustring const &icon = "",
+ bool mnemonic = true);
+ Random(Glib::ustring const &label,
+ Glib::ustring const &tooltip,
+ unsigned digits,
+ Glib::ustring const &suffix = "",
+ Glib::ustring const &icon = "",
+ bool mnemonic = true);
+ Random(Glib::ustring const &label,
+ Glib::ustring const &tooltip,
+ Gtk::Adjustment &adjust,
+ unsigned digits = 0,
+ Glib::ustring const &suffix = "",
+ Glib::ustring const &icon = "",
+ bool mnemonic = true);
+
+ long getStartSeed() const;
+ void setStartSeed(long newseed);
+
+ sigc::signal <void> signal_reseeded;
+
+protected:
+ long startseed;
+
+private:
+ void addReseedButton();
+ void onReseedButtonClick();
+};
+
+} // namespace Widget
+} // namespace UI
+} // namespace Inkscape
+
+#endif // INKSCAPE_UI_WIDGET_RANDOM_H
+
+/*
+ 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:encoding=utf-8:textwidth=99 :
index 41b40497835a20e42e56e330d5624dba79eaebf2..6dfa48b7af18adf1485ca29e0796a07319b9cf93 100644 (file)
-/**\r
- * \brief Simplified management of enumerations in the UI as combobox.\r
- *\r
- * Authors:\r
- * Johan Engelen <j.b.c.engelen@ewi.utwente.nl>\r
- *\r
- * Copyright (C) 2007 Authors\r
- *\r
- * Released under GNU GPL. Read the file 'COPYING' for more information.\r
- */\r
-\r
-#ifndef INKSCAPE_UI_WIDGET_REGISTERED_ENUMS_H\r
-#define INKSCAPE_UI_WIDGET_REGISTERED_ENUMS_H\r
-\r
-#include "ui/widget/combo-enums.h"\r
-#include "ui/widget/registered-widget.h"\r
-\r
-namespace Inkscape {\r
-namespace UI {\r
-namespace Widget {\r
-\r
-template<typename E> class RegisteredEnum : public RegisteredWidget\r
-{\r
-public:\r
- RegisteredEnum() {\r
- labelled = NULL;\r
- }\r
-\r
- ~RegisteredEnum() {\r
- _changed_connection.disconnect();\r
- if (labelled)\r
- delete labelled;\r
- }\r
-\r
- void init ( const Glib::ustring& label,\r
- const Glib::ustring& tip,\r
- const Glib::ustring& key,\r
- const Util::EnumDataConverter<E>& c,\r
- Registry& wr,\r
- Inkscape::XML::Node* repr_in,\r
- SPDocument *doc_in)\r
- {\r
- init_parent(key, wr, repr_in, doc_in);\r
-\r
- labelled = new LabelledComboBoxEnum<E> (label, tip, c);\r
-\r
- _changed_connection = combobox()->signal_changed().connect (sigc::mem_fun (*this, &RegisteredEnum::on_changed));\r
- }\r
-\r
- inline void init ( const Glib::ustring& label,\r
- const Glib::ustring& key,\r
- Registry& wr)\r
- {\r
- init(label, key, wr, NULL, NULL);\r
- }\r
-\r
- void set_active_by_id (E id) {\r
- combobox()->set_active_by_id(id);\r
- };\r
-\r
- void set_active_by_key (const Glib::ustring& key) {\r
- combobox()->set_active_by_key(key);\r
- }\r
-\r
- inline const Util::EnumData<E>* get_active_data() {\r
- return combobox()->get_active_data();\r
- }\r
-\r
- ComboBoxEnum<E> * combobox() {\r
- if (labelled) {\r
- return labelled->getCombobox();\r
- } else {\r
- return NULL;\r
- }\r
- }\r
-\r
- LabelledComboBoxEnum<E> * labelled;\r
- sigc::connection _changed_connection;\r
-\r
-protected:\r
- void on_changed() {\r
- if (combobox()->setProgrammatically) {\r
- combobox()->setProgrammatically = false;\r
- return;\r
- }\r
-\r
- if (_wr->isUpdating())\r
- return;\r
- _wr->setUpdating (true);\r
-\r
- const Util::EnumData<E>* data = combobox()->get_active_data();\r
- if (data) {\r
- write_to_xml(data->key.c_str());\r
- }\r
-\r
- _wr->setUpdating (false);\r
- }\r
-};\r
-\r
-}\r
-}\r
-}\r
-\r
-#endif\r
-\r
-/*\r
- Local Variables:\r
- mode:c++\r
- c-file-style:"stroustrup"\r
- c-file-offsets:((innamespace . 0)(inline-open . 0)(case-label . +))\r
- indent-tabs-mode:nil\r
- fill-column:99\r
- End:\r
-*/\r
-// vim: filetype=cpp:expandtab:shiftwidth=4:tabstop=8:softtabstop=4:encoding=utf-8:textwidth=99 :\r
+/**
+ * \brief Simplified management of enumerations in the UI as combobox.
+ *
+ * Authors:
+ * Johan Engelen <j.b.c.engelen@ewi.utwente.nl>
+ *
+ * Copyright (C) 2007 Authors
+ *
+ * Released under GNU GPL. Read the file 'COPYING' for more information.
+ */
+
+#ifndef INKSCAPE_UI_WIDGET_REGISTERED_ENUMS_H
+#define INKSCAPE_UI_WIDGET_REGISTERED_ENUMS_H
+
+#include "ui/widget/combo-enums.h"
+#include "ui/widget/registered-widget.h"
+
+namespace Inkscape {
+namespace UI {
+namespace Widget {
+
+template<typename E> class RegisteredEnum : public RegisteredWidget
+{
+public:
+ RegisteredEnum() {
+ labelled = NULL;
+ }
+
+ ~RegisteredEnum() {
+ _changed_connection.disconnect();
+ if (labelled)
+ delete labelled;
+ }
+
+ void init ( const Glib::ustring& label,
+ const Glib::ustring& tip,
+ const Glib::ustring& key,
+ const Util::EnumDataConverter<E>& c,
+ Registry& wr,
+ Inkscape::XML::Node* repr_in,
+ SPDocument *doc_in)
+ {
+ init_parent(key, wr, repr_in, doc_in);
+
+ labelled = new LabelledComboBoxEnum<E> (label, tip, c);
+
+ _changed_connection = combobox()->signal_changed().connect (sigc::mem_fun (*this, &RegisteredEnum::on_changed));
+ }
+
+ inline void init ( const Glib::ustring& label,
+ const Glib::ustring& key,
+ Registry& wr)
+ {
+ init(label, key, wr, NULL, NULL);
+ }
+
+ void set_active_by_id (E id) {
+ combobox()->set_active_by_id(id);
+ };
+
+ void set_active_by_key (const Glib::ustring& key) {
+ combobox()->set_active_by_key(key);
+ }
+
+ inline const Util::EnumData<E>* get_active_data() {
+ return combobox()->get_active_data();
+ }
+
+ ComboBoxEnum<E> * combobox() {
+ if (labelled) {
+ return labelled->getCombobox();
+ } else {
+ return NULL;
+ }
+ }
+
+ LabelledComboBoxEnum<E> * labelled;
+ sigc::connection _changed_connection;
+
+protected:
+ void on_changed() {
+ if (combobox()->setProgrammatically) {
+ combobox()->setProgrammatically = false;
+ return;
+ }
+
+ if (_wr->isUpdating())
+ return;
+ _wr->setUpdating (true);
+
+ const Util::EnumData<E>* data = combobox()->get_active_data();
+ if (data) {
+ write_to_xml(data->key.c_str());
+ }
+
+ _wr->setUpdating (false);
+ }
+};
+
+}
+}
+}
+
+#endif
+
+/*
+ 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:encoding=utf-8:textwidth=99 :