Code

r11769@tres: ted | 2006-05-06 09:09:59 -0700
[inkscape.git] / src / extension / extension.cpp
index 6eb3a1728abd1dce629d25a9e6bf2433c5db24e8..97d71c5ee2ffba31a6e21d71d38cf5d1df5263a5 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);
         }
 
@@ -405,17 +406,18 @@ param_shared (const gchar * name, GSList * list)
               in value.  It isn't duplicated into the value string.
     \param    name    The name of the parameter to get
     \param    doc    The document to look in for document specific parameters
+    \param    node   The node to look in for a specific parameter
 
     Look up in the parameters list, then execute the function on that
     found parameter.
 */
 const gchar *
-Extension::get_param_string (const gchar * name, const Inkscape::XML::Document * doc)
+Extension::get_param_string (const gchar * name, const SPDocument * doc, const Inkscape::XML::Node * node)
 {
     Parameter * param;
 
     param = param_shared(name, parameters);
-    return param->get_string(doc);
+    return param->get_string(doc, node);
 }
 
 /**
@@ -424,17 +426,18 @@ Extension::get_param_string (const gchar * name, const Inkscape::XML::Document *
               in value.
     \param    name    The name of the parameter to get
     \param    doc    The document to look in for document specific parameters
+    \param    node   The node to look in for a specific parameter
 
     Look up in the parameters list, then execute the function on that
     found parameter.
 */
 bool
-Extension::get_param_bool (const gchar * name, const Inkscape::XML::Document * doc)
+Extension::get_param_bool (const gchar * name, const SPDocument * doc, const Inkscape::XML::Node * node)
 {
     Parameter * param;
 
     param = param_shared(name, parameters);
-    return param->get_bool(doc);
+    return param->get_bool(doc, node);
 }
 
 /**
@@ -443,17 +446,18 @@ Extension::get_param_bool (const gchar * name, const Inkscape::XML::Document * d
               in value.
     \param    name    The name of the parameter to get
     \param    doc    The document to look in for document specific parameters
+    \param    node   The node to look in for a specific parameter
 
     Look up in the parameters list, then execute the function on that
     found parameter.
 */
 int
-Extension::get_param_int (const gchar * name, const Inkscape::XML::Document * doc)
+Extension::get_param_int (const gchar * name, const SPDocument * doc, const Inkscape::XML::Node * node)
 {
     Parameter * param;
 
     param = param_shared(name, parameters);
-    return param->get_int(doc);
+    return param->get_int(doc, node);
 }
 
 /**
@@ -462,16 +466,17 @@ Extension::get_param_int (const gchar * name, const Inkscape::XML::Document * do
               in value.
     \param    name    The name of the parameter to get
     \param    doc    The document to look in for document specific parameters
+    \param    node   The node to look in for a specific parameter
 
     Look up in the parameters list, then execute the function on that
     found parameter.
 */
 float
-Extension::get_param_float (const gchar * name, const Inkscape::XML::Document * doc)
+Extension::get_param_float (const gchar * name, const SPDocument * doc, const Inkscape::XML::Node * node)
 {
     Parameter * param;
     param = param_shared(name, parameters);
-    return param->get_float(doc);
+    return param->get_float(doc, node);
 }
 
 /**
@@ -481,16 +486,17 @@ Extension::get_param_float (const gchar * name, const Inkscape::XML::Document *
     \param    name    The name of the parameter to set
     \param    value   The value to set the parameter to
     \param    doc    The document to look in for document specific parameters
+    \param    node   The node to look in for a specific parameter
 
     Look up in the parameters list, then execute the function on that
     found parameter.
 */
 bool
-Extension::set_param_bool (const gchar * name, bool value, Inkscape::XML::Document * doc)
+Extension::set_param_bool (const gchar * name, bool value, SPDocument * doc, Inkscape::XML::Node * node)
 {
     Parameter * param;
     param = param_shared(name, parameters);
-    return param->set_bool(value, doc);
+    return param->set_bool(value, doc, node);
 }
 
 /**
@@ -500,16 +506,17 @@ Extension::set_param_bool (const gchar * name, bool value, Inkscape::XML::Docume
     \param    name    The name of the parameter to set
     \param    value   The value to set the parameter to
     \param    doc    The document to look in for document specific parameters
+    \param    node   The node to look in for a specific parameter
 
     Look up in the parameters list, then execute the function on that
     found parameter.
 */
 int
-Extension::set_param_int (const gchar * name, int value, Inkscape::XML::Document * doc)
+Extension::set_param_int (const gchar * name, int value, SPDocument * doc, Inkscape::XML::Node * node)
 {
     Parameter * param;
     param = param_shared(name, parameters);
-    return param->set_int(value, doc);
+    return param->set_int(value, doc, node);
 }
 
 /**
@@ -519,16 +526,17 @@ Extension::set_param_int (const gchar * name, int value, Inkscape::XML::Document
     \param    name    The name of the parameter to set
     \param    value   The value to set the parameter to
     \param    doc    The document to look in for document specific parameters
+    \param    node   The node to look in for a specific parameter
 
     Look up in the parameters list, then execute the function on that
     found parameter.
 */
 float
-Extension::set_param_float (const gchar * name, float value, Inkscape::XML::Document * doc)
+Extension::set_param_float (const gchar * name, float value, SPDocument * doc, Inkscape::XML::Node * node)
 {
     Parameter * param;
     param = param_shared(name, parameters);
-    return param->set_float(value, doc);
+    return param->set_float(value, doc, node);
 }
 
 /**
@@ -538,16 +546,17 @@ Extension::set_param_float (const gchar * name, float value, Inkscape::XML::Docu
     \param    name    The name of the parameter to set
     \param    value   The value to set the parameter to
     \param    doc    The document to look in for document specific parameters
+    \param    node   The node to look in for a specific parameter
 
     Look up in the parameters list, then execute the function on that
     found parameter.
 */
 const gchar *
-Extension::set_param_string (const gchar * name, const gchar * value, Inkscape::XML::Document * doc)
+Extension::set_param_string (const gchar * name, const gchar * value, SPDocument * doc, Inkscape::XML::Node * node)
 {
     Parameter * param;
     param = param_shared(name, parameters);
-    return param->set_string(value, doc);
+    return param->set_string(value, doc, node);
 }
 
 /** \brief A function to open the error log file. */
@@ -572,6 +581,31 @@ 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));
+            // printf("Setting tooltip: %s\n", tooltip);
+        }
+        return;
+    };
+};
+
 /** \brief  A function to automatically generate a GUI using the parameters
     \return Generated widget
 
@@ -582,22 +616,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 = new Gtk::VBox();
-    vbox = 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;
 };
 
 /**