Code

Added forgotten #ifdef HAVE_CAIRO_PDF/#endif pair
[inkscape.git] / src / extension / extension.cpp
index e41990a1c9153e8c746f25dcfeec3261ebcd5a8a..631ab43fe2e61703d5195f4867601c7040e89811 100644 (file)
@@ -26,6 +26,7 @@
 #include <gtkmm/label.h>
 #include <gtkmm/frame.h>
 #include <gtkmm/table.h>
+#include <gtkmm/tooltips.h>
 
 #include "inkscape.h"
 #include "extension/implementation/implementation.h"
@@ -90,15 +91,15 @@ Extension::Extension (Inkscape::XML::Node * in_repr, Implementation::Implementat
             if (!strcmp(chname, "help")) {
                 _help = g_strdup (sp_repr_children(child_repr)->content());
             } /* name */
-            if (!strcmp(chname, "param")) {
+            if (!strcmp(chname, "param") || !strcmp(chname, "_param")) {
                 Parameter * param;
                 param = Parameter::make(child_repr, this);
                 if (param != NULL)
                     parameters = g_slist_append(parameters, param);
-            } /* param */
+            } /* param || _param */
             if (!strcmp(chname, "dependency")) {
                 _deps.push_back(new Dependency(child_repr));
-            } /* param */
+            } /* dependency */
             child_repr = sp_repr_next(child_repr);
         }
 
@@ -130,7 +131,15 @@ Extension::~Extension (void)
     delete timer;
     timer = NULL;
     /** \todo Need to do parameters here */
-
+    
+    // delete parameters: 
+    for (GSList * list = parameters; list != NULL; list = g_slist_next(list)) {
+        Parameter * param = reinterpret_cast<Parameter *>(list->data);
+        delete param;
+    }
+    g_slist_free(parameters);
+    
+    
     for (unsigned int i = 0 ; i < _deps.size(); i++) {
         delete _deps[i];
     }
@@ -411,7 +420,7 @@ param_shared (const gchar * name, GSList * list)
     found parameter.
 */
 const gchar *
-Extension::get_param_string (const gchar * name, const Inkscape::XML::Document * doc, const Inkscape::XML::Node * node)
+Extension::get_param_string (const gchar * name, const SPDocument * doc, const Inkscape::XML::Node * node)
 {
     Parameter * param;
 
@@ -431,7 +440,7 @@ Extension::get_param_string (const gchar * name, const Inkscape::XML::Document *
     found parameter.
 */
 bool
-Extension::get_param_bool (const gchar * name, const Inkscape::XML::Document * doc, const Inkscape::XML::Node * node)
+Extension::get_param_bool (const gchar * name, const SPDocument * doc, const Inkscape::XML::Node * node)
 {
     Parameter * param;
 
@@ -451,7 +460,7 @@ Extension::get_param_bool (const gchar * name, const Inkscape::XML::Document * d
     found parameter.
 */
 int
-Extension::get_param_int (const gchar * name, const Inkscape::XML::Document * doc, const Inkscape::XML::Node * node)
+Extension::get_param_int (const gchar * name, const SPDocument * doc, const Inkscape::XML::Node * node)
 {
     Parameter * param;
 
@@ -471,7 +480,7 @@ Extension::get_param_int (const gchar * name, const Inkscape::XML::Document * do
     found parameter.
 */
 float
-Extension::get_param_float (const gchar * name, const Inkscape::XML::Document * doc, const Inkscape::XML::Node * node)
+Extension::get_param_float (const gchar * name, const SPDocument * doc, const Inkscape::XML::Node * node)
 {
     Parameter * param;
     param = param_shared(name, parameters);
@@ -491,7 +500,7 @@ Extension::get_param_float (const gchar * name, const Inkscape::XML::Document *
     found parameter.
 */
 bool
-Extension::set_param_bool (const gchar * name, bool value, Inkscape::XML::Document * doc, Inkscape::XML::Node * node)
+Extension::set_param_bool (const gchar * name, bool value, SPDocument * doc, Inkscape::XML::Node * node)
 {
     Parameter * param;
     param = param_shared(name, parameters);
@@ -511,7 +520,7 @@ Extension::set_param_bool (const gchar * name, bool value, Inkscape::XML::Docume
     found parameter.
 */
 int
-Extension::set_param_int (const gchar * name, int value, Inkscape::XML::Document * doc, Inkscape::XML::Node * node)
+Extension::set_param_int (const gchar * name, int value, SPDocument * doc, Inkscape::XML::Node * node)
 {
     Parameter * param;
     param = param_shared(name, parameters);
@@ -531,7 +540,7 @@ Extension::set_param_int (const gchar * name, int value, Inkscape::XML::Document
     found parameter.
 */
 float
-Extension::set_param_float (const gchar * name, float value, Inkscape::XML::Document * doc, Inkscape::XML::Node * node)
+Extension::set_param_float (const gchar * name, float value, SPDocument * doc, Inkscape::XML::Node * node)
 {
     Parameter * param;
     param = param_shared(name, parameters);
@@ -551,7 +560,7 @@ Extension::set_param_float (const gchar * name, float value, Inkscape::XML::Docu
     found parameter.
 */
 const gchar *
-Extension::set_param_string (const gchar * name, const gchar * value, Inkscape::XML::Document * doc, Inkscape::XML::Node * node)
+Extension::set_param_string (const gchar * name, const gchar * value, SPDocument * doc, Inkscape::XML::Node * node)
 {
     Parameter * param;
     param = param_shared(name, parameters);
@@ -580,6 +589,30 @@ Extension::error_file_close (void)
     error_file.close();
 };
 
+/** \brief  A widget to represent the inside of an AutoGUI widget */
+class AutoGUI : public Gtk::VBox {
+    Gtk::Tooltips _tooltips;
+public:
+    /** \brief  Create an AutoGUI object */
+    AutoGUI (void) : Gtk::VBox() {};
+    /** \brief  Adds a widget with a tool tip into the autogui
+        \param  widg  Widget to add
+        \param  tooltip   Tooltip for the widget
+        
+        If there is no widget, nothing happens.  Otherwise it is just
+        added into the VBox.  If there is a tooltip (non-NULL) then it
+        is placed on the widget.
+    */
+    void addWidget (Gtk::Widget * widg, gchar const * tooltip) {
+        if (widg == NULL) return;
+        this->pack_start(*widg, true, true, 2);
+        if (tooltip != NULL) {
+            _tooltips.set_tip(*widg, Glib::ustring(tooltip));
+        }
+        return;
+    };
+};
+
 /** \brief  A function to automatically generate a GUI using the parameters
     \return Generated widget
 
@@ -590,21 +623,21 @@ Extension::error_file_close (void)
     If there are no parameters, this function just returns NULL.
 */
 Gtk::Widget *
-Extension::autogui (void)
+Extension::autogui (SPDocument * doc, Inkscape::XML::Node * node)
 {
     if (g_slist_length(parameters) == 0) return NULL;
 
-    Gtk::VBox * vbox = Gtk::manage(new Gtk::VBox());
+    AutoGUI * agui = Gtk::manage(new AutoGUI());
 
     for (GSList * list = parameters; list != NULL; list = g_slist_next(list)) {
         Parameter * param = reinterpret_cast<Parameter *>(list->data);
-        Gtk::Widget * widg = param->get_widget();
-        if (widg != NULL)
-            vbox->pack_start(*widg, true, true);
+        Gtk::Widget * widg = param->get_widget(doc, node);
+        gchar const * tip = param->get_tooltip();
+        agui->addWidget(widg, tip);
     }
 
-    vbox->show();
-    return vbox;
+    agui->show();
+    return agui;
 };
 
 /**