parameter.cpp revision 9deaa46a0fb28baabbf3b23fab07a0f53abf3704
/** \file
* Parameters for extensions.
*/
/*
* Authors:
* Ted Gould <ted@gould.cx>
*
* Copyright (C) 2005 Authors
*
* Released under GNU GPL, read the file 'COPYING' for more information
*/
#ifdef HAVE_CONFIG_H
# include "config.h"
#endif
#include <gtkmm/adjustment.h>
#include <gtkmm/spinbutton.h>
#include "extension.h"
#include "prefs-utils.h"
#include "parameter.h"
/** \brief The root directory in the preferences database for extension
related parameters. */
#define PREF_DIR "extensions"
namespace Inkscape {
namespace Extension {
/** \brief A boolean parameter */
private:
/** \brief Internal value. */
bool _value;
public:
ParamBool(const gchar * name, const gchar * guitext, Inkscape::Extension::Extension * ext, Inkscape::XML::Node * xml);
/** \brief Returns \c _value */
};
/** \brief Use the superclass' allocator and set the \c _value */
ParamBool::ParamBool (const gchar * name, const gchar * guitext, Inkscape::Extension::Extension * ext, Inkscape::XML::Node * xml) :
{
const char * defaultval = NULL;
if (defaultval != NULL && (!strcmp(defaultval, "TRUE") || !strcmp(defaultval, "true") || !strcmp(defaultval, "1"))) {
_value = true;
} else {
_value = false;
}
return;
}
private:
/** \brief Internal value. */
int _value;
int _min;
int _max;
public:
ParamInt (const gchar * name, const gchar * guitext, Inkscape::Extension::Extension * ext, Inkscape::XML::Node * xml);
/** \brief Returns \c _value */
};
/** \brief Use the superclass' allocator and set the \c _value */
ParamInt::ParamInt (const gchar * name, const gchar * guitext, Inkscape::Extension::Extension * ext, Inkscape::XML::Node * xml) :
{
const char * defaultval = NULL;
if (defaultval != NULL) {
}
/* We're handling this by just killing both values */
_max = 10;
_min = 0;
}
// std::cout << "New Int:: value: " << _value << " max: " << _max << " min: " << _min << std::endl;
return;
}
class ParamFloat : public Parameter {
private:
/** \brief Internal value. */
float _value;
float _min;
float _max;
public:
ParamFloat (const gchar * name, const gchar * guitext, Inkscape::Extension::Extension * ext, Inkscape::XML::Node * xml);
/** \brief Returns \c _value */
float get (const Inkscape::XML::Document * doc, const Inkscape::XML::Node * node) { return _value; }
};
/** \brief Use the superclass' allocator and set the \c _value */
ParamFloat::ParamFloat (const gchar * name, const gchar * guitext, Inkscape::Extension::Extension * ext, Inkscape::XML::Node * xml) :
{
const char * defaultval = NULL;
if (defaultval != NULL) {
}
/* We're handling this by just killing both values */
_max = 10.0;
_min = 0.0;
}
// std::cout << "New Float:: value: " << _value << " max: " << _max << " min: " << _min << std::endl;
return;
}
class ParamString : public Parameter {
private:
/** \brief Internal value. This should point to a string that has
been allocated in memory. And should be free'd. */
public:
ParamString(const gchar * name, const gchar * guitext, Inkscape::Extension::Extension * ext, Inkscape::XML::Node * xml);
~ParamString(void);
/** \brief Returns \c _value, with a \i const to protect it. */
const gchar * get (const Inkscape::XML::Document * doc, const Inkscape::XML::Node * node) { return _value; }
const gchar * set (const gchar * in, Inkscape::XML::Document * doc, const Inkscape::XML::Node * node);
};
/**
\return None
\brief This function creates a parameter that can be used later. This
is typically done in the creation of the extension and defined
in the XML file describing the extension (it's private so people
have to use the system) :)
\param in_repr The XML describing the parameter
This function first grabs all of the data out of the Repr and puts
it into local variables. Actually, these are just pointers, and the
data is not duplicated so we need to be careful with it. If there
isn't a name or a type in the XML, then no parameter is created as
the function just returns.
From this point on, we're pretty committed as we've allocated an
object and we're starting to fill it. The name is set first, and
is created with a strdup to actually allocate memory for it. Then
there is a case statement (roughly because strcmp requires 'ifs')
based on what type of parameter this is. Depending which type it
is, the value is interpreted differently, but they are relatively
straight forward. In all cases the value is set to the default
value from the XML and the type is set to the interpreted type.
*/
{
const char * name;
const char * type;
const char * guitext;
/* In this case we just don't have enough information */
return NULL;
}
}
/* Note: param could equal NULL */
return param;
}
/** \brief A function to set the \c _value
\param in The value to set to
\param doc A document that should be used to set the value.
\param node The node where the value may be placed
This function sets the internal value, but it also sets the value
in the preferences structure. To put it in the right place, \c PREF_DIR
and \c pref_name() are used.
*/
bool
{
return _value;
}
/** \brief A function to set the \c _value
\param in The value to set to
\param doc A document that should be used to set the value.
\param node The node where the value may be placed
This function sets the internal value, but it also sets the value
in the preferences structure. To put it in the right place, \c PREF_DIR
and \c pref_name() are used.
*/
int
{
return _value;
}
/** \brief A function to set the \c _value
\param in The value to set to
\param doc A document that should be used to set the value.
\param node The node where the value may be placed
This function sets the internal value, but it also sets the value
in the preferences structure. To put it in the right place, \c PREF_DIR
and \c pref_name() are used.
*/
float
{
return _value;
}
/** \brief A function to set the \c _value
\param in The value to set to
\param doc A document that should be used to set the value.
\param node The node where the value may be placed
This function sets the internal value, but it also sets the value
in the preferences structure. To put it in the right place, \c PREF_DIR
and \c pref_name() are used.
To copy the data into _value the old memory must be free'd first.
It is important to note that \c g_free handles \c NULL just fine. Then
the passed in value is duplicated using \c g_strdup().
*/
const gchar *
{
return _value;
}
/** \brief Wrapper to cast to the object and use it's function. */
bool
{
throw Extension::param_wrong_type();
}
/** \brief Wrapper to cast to the object and use it's function. */
int
{
throw Extension::param_wrong_type();
}
/** \brief Wrapper to cast to the object and use it's function. */
float
{
floatpntr = dynamic_cast<ParamFloat *>(this);
throw Extension::param_wrong_type();
}
/** \brief Wrapper to cast to the object and use it's function. */
const gchar *
{
stringpntr = dynamic_cast<ParamString *>(this);
if (stringpntr == NULL)
throw Extension::param_wrong_type();
}
/** \brief Wrapper to cast to the object and use it's function. */
bool
{
throw Extension::param_wrong_type();
}
/** \brief Wrapper to cast to the object and use it's function. */
int
{
throw Extension::param_wrong_type();
}
/** \brief Wrapper to cast to the object and use it's function. */
float
{
floatpntr = dynamic_cast<ParamFloat *>(this);
throw Extension::param_wrong_type();
}
/** \brief Wrapper to cast to the object and use it's function. */
const gchar *
{
stringpntr = dynamic_cast<ParamString *>(this);
if (stringpntr == NULL)
throw Extension::param_wrong_type();
}
/** \brief Initialize the object, to do that, copy the data. */
ParamString::ParamString (const gchar * name, const gchar * guitext, Inkscape::Extension::Extension * ext, Inkscape::XML::Node * xml) :
{
const char * defaultval = NULL;
if (defaultval != NULL)
return;
}
/** \brief Free the allocated data. */
ParamString::~ParamString(void)
{
}
/** \brief Oop, now that we need a parameter, we need it's name. */
Parameter::Parameter (const gchar * name, const gchar * guitext, Inkscape::Extension::Extension * ext) :
{
else
}
/** \brief Just free the allocated name. */
{
}
/** \brief Build the name to write the parameter from the extension's
ID and the name of this parameter. */
gchar *
{
}
/** \brief Basically, if there is no widget pass a NULL. */
Parameter::get_widget (void)
{
return NULL;
}
/** \brief If I'm not sure which it is, just don't return a value. */
{
return mystring;
}
/** \brief A class to make an adjustment that uses Extension params */
/** The parameter to adjust */
ParamFloat * _pref;
public:
/** \brief Make the adjustment using an extension and the string
describing the parameter. */
return;
};
void val_changed (void);
}; /* class ParamFloatAdjustment */
/** \brief A function to respond to the value_changed signal from the
adjustment.
This function just grabs the value from the adjustment and writes
it to the parameter. Very simple, but yet beautiful.
*/
void
ParamFloatAdjustment::val_changed (void)
{
// std::cout << "Value Changed to: " << this->get_value() << std::endl;
return;
}
/** \brief A class to make an adjustment that uses Extension params */
/** The parameter to adjust */
public:
/** \brief Make the adjustment using an extension and the string
describing the parameter. */
return;
};
void val_changed (void);
}; /* class ParamIntAdjustment */
/** \brief A function to respond to the value_changed signal from the
adjustment.
This function just grabs the value from the adjustment and writes
it to the parameter. Very simple, but yet beautiful.
*/
void
ParamIntAdjustment::val_changed (void)
{
// std::cout << "Value Changed to: " << this->get_value() << std::endl;
return;
}
/**
\brief Creates a Float Adjustment for a float parameter
Builds a hbox with a label and a float adjustment in it.
*/
ParamFloat::get_widget (void)
{
}
/**
\brief Creates a Int Adjustment for a int parameter
Builds a hbox with a label and a int adjustment in it.
*/
ParamInt::get_widget (void)
{
}
/** \brief A check button which is Param aware. It works with the
parameter to change it's value as the check button changes
value. */
private:
/** \brief Param to change */
public:
/** \brief Initialize the check button
\param param Which parameter to adjust on changing the check button
This function sets the value of the checkbox to be that of the
parameter, and then sets up a callback to \c on_toggle.
*/
return;
}
void on_toggle (void);
};
/**
\brief A function to respond to the check box changing
Adjusts the value of the preference to match that in the check box.
*/
void
ParamBoolCheckButton::on_toggle (void)
{
return;
}
/**
\brief Creates a bool check button for a bool parameter
Builds a hbox with a label and a check button in it.
*/
ParamBool::get_widget (void)
{
}
/** \brief A special category of Gtk::Entry to handle string parameteres */
private:
ParamString * _pref;
public:
/** \brief Build a string preference for the given parameter
\param pref Where to get the string from, and where to put it
when it changes.
*/
};
void changed_text (void);
};
/** \brief Respond to the text box changing
This function responds to the box changing by grabbing the value
from the text box and putting it in the parameter.
*/
void
ParamStringEntry::changed_text (void)
{
return;
}
/**
\brief Creates a text box for the string parameter
Builds a hbox with a label and a text box in it.
*/
ParamString::get_widget (void)
{
}
/** \brief Return 'true' or 'false' */
{
if (_value)
else
return mystring;
}
/** \brief Return the value as a string */
{
char startstring[32];
return mystring;
}
/** \brief Return the value as a string */
ParamFloat::string (void)
{
return mystring;
}
/** \brief Return the value as a string */
ParamString::string (void)
{
*mystring += "\"";
*mystring += "\"";
return mystring;
}
} /* namespace Extension */
} /* 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 :