diff options
| author | Kris De Gussem <kris.degussem@gmail.com> | 2012-01-19 19:41:25 +0000 |
|---|---|---|
| committer | Kris <Kris.De.Gussem@hotmail.com> | 2012-01-19 19:41:25 +0000 |
| commit | cd1751daf56ae0de1f835b226226888ab96f4ffd (patch) | |
| tree | 33aca34abdff78f210524909e10ff4396d8d8189 /src/widgets/sp-attribute-widget.cpp | |
| parent | unsorted powerstroke points is quite advanced. mostly annoying. (diff) | |
| download | inkscape-cd1751daf56ae0de1f835b226226888ab96f4ffd.tar.gz inkscape-cd1751daf56ae0de1f835b226226888ab96f4ffd.zip | |
Update and documentation of sp-attribute-widget
(bzr r10909)
Diffstat (limited to 'src/widgets/sp-attribute-widget.cpp')
| -rw-r--r-- | src/widgets/sp-attribute-widget.cpp | 281 |
1 files changed, 77 insertions, 204 deletions
diff --git a/src/widgets/sp-attribute-widget.cpp b/src/widgets/sp-attribute-widget.cpp index 41ff675ac..07bc19fab 100644 --- a/src/widgets/sp-attribute-widget.cpp +++ b/src/widgets/sp-attribute-widget.cpp @@ -8,7 +8,7 @@ * Kris De Gussem <Kris.DeGussem@gmail.com> * * Copyright (C) 2001 Ximian, Inc. - * Copyright (C) 2011, authors + * Copyright (C) 2012, authors * Released under GNU GPL, read the file 'COPYING' for more information */ @@ -24,67 +24,69 @@ using Inkscape::DocumentUndo; -static void sp_attribute_table_entry_changed (Gtk::Editable *editable, SPAttributeTable *spat); +/** + * Callback for user input in one of the entries. + * + * sp_attribute_table_entry_changed set the object property + * to the new value and updates history. It is a callback from + * the entries created by SPAttributeTable. + * + * @param editable pointer to the entry box. + * @param spat pointer to the SPAttributeTable instance. + */ +static void sp_attribute_table_entry_changed (Gtk::Entry *editable, SPAttributeTable *spat); +/** + * Callback for a modification of the selected object (size, color, properties, etc.). + * + * sp_attribute_table_object_modified rereads the object properties + * and shows the values in the entry boxes. It is a callback from a + * connection of the SPObject. + * + * @param object the SPObject to which this instance is referring to. + * @param flags gives the applied modifications + * @param spat pointer to the SPAttributeTable instance. + */ static void sp_attribute_table_object_modified (SPObject *object, guint flags, SPAttributeTable *spaw); +/** + * Callback for the delection of the selected object. + * + * sp_attribute_table_object_release invalidates all data of + * SPAttributeTable and disables the widget. + */ static void sp_attribute_table_object_release (SPObject */*object*/, SPAttributeTable *spat); #define XPAD 4 #define YPAD 0 -/** - * \brief Constructor defaulting to no content. - */ SPAttributeTable::SPAttributeTable () : - blocked(0), - hasobj(0), - table(0), + _object(NULL), + blocked(false), + table(NULL), _attributes(), _entries(), modified_connection(), release_connection() { - src.object = NULL; } - /** - * \brief Constructor referring to a specific object. - * - * This constructor initializes all data fields and creates the necessary widgets. - * set_object is called for this purpose. - * - * @param object the SPObject to which this instance is referring to. It should be the object that is currently selected and whose properties are being shown by this SPAttributeTable instance. - * @param labels list of labels to be shown for the different attributes. - * @param attributes list of attributes whose value can be edited. - * @param parent the parent object owning the SPAttributeTable instance. - * - * @see set_object - */ SPAttributeTable::SPAttributeTable (SPObject *object, std::vector<Glib::ustring> &labels, std::vector<Glib::ustring> &attributes, GtkWidget* parent) : - blocked(0), - hasobj(0), - table(0), + _object(NULL), + blocked(false), + table(NULL), _attributes(), _entries(), modified_connection(), release_connection() { - src.object = NULL; - src.repr = NULL; set_object(object, labels, attributes, parent); } -/** - * \brief Destructor. - */ SPAttributeTable::~SPAttributeTable () { clear(); } -/** - * \brief Clears data of SPAttributeTable instance, destroys all child widgets and closes connections. - */ void SPAttributeTable::clear(void) { Gtk::Widget *w; @@ -116,31 +118,14 @@ void SPAttributeTable::clear(void) table = NULL; } - if (hasobj) { - if (src.object) { - modified_connection.disconnect(); - release_connection.disconnect(); - src.object = NULL; - } - } else { - if (src.repr) { - src.repr = Inkscape::GC::release(src.repr); - } + if (_object) + { + modified_connection.disconnect(); + release_connection.disconnect(); + _object = NULL; } } -/** - * \brief Sets class properties and creates child widgets - * - * set_object initializes all data fields, creates links to the - * SPOject item and creates the necessary widgets. For n properties - * n labels and n entries are created and shown in tabular format. - * - * @param object the SPObject to which this instance is referring to. It should be the object that is currently selected and whose properties are being shown by this SPAttribuTable instance. - * @param labels list of labels to be shown for the different attributes. - * @param attributes list of attributes whose value can be edited. - * @param parent the parent object owning the SPAttributeTable instance. - */ void SPAttributeTable::set_object(SPObject *object, std::vector<Glib::ustring> &labels, std::vector<Glib::ustring> &attributes, @@ -151,8 +136,7 @@ void SPAttributeTable::set_object(SPObject *object, g_return_if_fail (labels.size() == attributes.size()); clear(); - hasobj = true; - src.object = object; + _object = object; if (object) { blocked = true; @@ -170,30 +154,24 @@ void SPAttributeTable::set_object(SPObject *object, // Fill rows _attributes = attributes; - Gtk::Label *ll; - Gtk::Entry *ee; - Gtk::Widget *w; - const gchar *val; for (guint i = 0; i < (attributes.size()); i++) { - ll = new Gtk::Label (_(labels[i].c_str())); - w = (Gtk::Widget *) ll; + Gtk::Label *ll = new Gtk::Label (_(labels[i].c_str())); ll->show(); ll->set_alignment (1.0, 0.5); - table->attach (*w, 0, 1, i, i + 1, + table->attach (*ll, 0, 1, i, i + 1, Gtk::FILL, (Gtk::EXPAND | Gtk::FILL), XPAD, YPAD ); - ee = new Gtk::Entry(); - w = (Gtk::Widget *) ee; + Gtk::Entry *ee = new Gtk::Entry(); ee->show(); - val = object->getRepr()->attribute(attributes[i].c_str()); + const gchar *val = object->getRepr()->attribute(attributes[i].c_str()); ee->set_text (val ? val : (const gchar *) ""); - table->attach (*w, 1, 2, i, i + 1, + table->attach (*ee, 1, 2, i, i + 1, (Gtk::EXPAND | Gtk::FILL), (Gtk::EXPAND | Gtk::FILL), XPAD, YPAD ); _entries.push_back(ee); - g_signal_connect ( w->gobj(), "changed", + g_signal_connect ( ee->gobj(), "changed", G_CALLBACK (sp_attribute_table_entry_changed), this ); } @@ -203,137 +181,56 @@ void SPAttributeTable::set_object(SPObject *object, } } -/** - * \brief Update values in entry boxes on change of object. - * - * change_object updates the values of the entry boxes in case the user - * of Inkscape selects an other object. - * change_object is a subset of set_object and should only be called by - * the parent class (holding the SPAttributeTable instance). This function - * should only be called when the number of properties/entries nor - * the labels do not change. - * - * @param object the SPObject to which this instance is referring to. It should be the object that is currently selected and whose properties are being shown by this SPAttribuTable instance. - */ void SPAttributeTable::change_object(SPObject *object) { g_return_if_fail (!object || SP_IS_OBJECT (object)); - if (hasobj) { - if (src.object) { - modified_connection.disconnect(); - release_connection.disconnect(); - src.object = NULL; - } - } else { - if (src.repr) { - src.repr = Inkscape::GC::release(src.repr); - } + if (_object) + { + modified_connection.disconnect(); + release_connection.disconnect(); + _object = NULL; } - hasobj = true; - src.object = object; - - if (object) { + _object = object; + if (_object) { blocked = true; // Set up object - modified_connection = object->connectModified(sigc::bind<2>(sigc::ptr_fun(&sp_attribute_table_object_modified), this)); - release_connection = object->connectRelease (sigc::bind<1>(sigc::ptr_fun(&sp_attribute_table_object_release), this)); + modified_connection = _object->connectModified(sigc::bind<2>(sigc::ptr_fun(&sp_attribute_table_object_modified), this)); + release_connection = _object->connectRelease (sigc::bind<1>(sigc::ptr_fun(&sp_attribute_table_object_release), this)); for (guint i = 0; i < (_attributes.size()); i++) { - const gchar *val = object->getRepr()->attribute(_attributes[i].c_str()); + const gchar *val = _object->getRepr()->attribute(_attributes[i].c_str()); _entries[i]->set_text(val ? val : ""); } + + blocked = false; } } -/*void SPAttributeTable::set_repr (Inkscape::XML::Node *repr, - std::vector<Glib::ustring> &labels, - std::vector<Glib::ustring> &attributes, - GtkWidget* parent) +void SPAttributeTable::reread_properties(void) { - g_return_if_fail (!labels.empty() || !attributes.empty()); - g_return_if_fail (labels.size() == attributes.size()); - - clear(); - - hasobj = false; - - if (repr) { - blocked = true; - - // Set up repr - src.repr = Inkscape::GC::anchor(repr); - - // Create table - table = new Gtk::Table (attributes.size(), 2, false); - if (!(parent == NULL)) - { - gtk_container_add (GTK_CONTAINER (parent),(GtkWidget*)table->gobj()); - } - - // Fill rows - _attributes = attributes; - Gtk::Label *ll; - Gtk::Entry *ee; - Gtk::Widget *w; - const gchar *val; - for (guint i = 0; i < (attributes.size()); i++) { - ll = new Gtk::Label (_(labels[i].c_str())); - w = (Gtk::Widget *) ll; - ll->show (); - ll->set_alignment (1.0, 0.5); - table->attach (*w, 0, 1, i, i + 1, - Gtk::FILL, - (Gtk::EXPAND | Gtk::FILL), - XPAD, YPAD ); - ee = new Gtk::Entry(); - w = (Gtk::Widget *) ee; - ee->show(); - val = repr->attribute(attributes[i].c_str()); - ee->set_text (val ? val : (const gchar *) ""); - table->attach (*w, 1, 2, i, i + 1, - (Gtk::EXPAND | Gtk::FILL), - (Gtk::EXPAND | Gtk::FILL), - XPAD, YPAD ); - _entries.push_back(w); - g_signal_connect ( w->gobj(), "changed", - G_CALLBACK (sp_attribute_table_entry_changed), - this ); - } - // Show table - table->show (); - blocked = false; + blocked = true; + for (guint i = 0; i < (_attributes.size()); i++) + { + const gchar *val = _object->getRepr()->attribute(_attributes[i].c_str()); + _entries[i]->set_text(val ? val : ""); } + blocked = false; } -*/ -/** - * \brief Callback for a modification of the selected object (size, color, properties, etc.). - * - * sp_attribute_table_object_modified rereads the object properties - * and shows the values in the entry boxes. It is a callback from a - * connection of the SPObject. - * - * @param object the SPObject to which this instance is referring to. - * @param flags gives the applied modifications - * @param spat pointer to the SPAttributeTable instance. - */ static void sp_attribute_table_object_modified ( SPObject */*object*/, guint flags, SPAttributeTable *spat ) { if (flags && SP_OBJECT_MODIFIED_FLAG) { - guint i; std::vector<Glib::ustring> attributes = spat->get_attributes(); std::vector<Gtk::Entry *> entries = spat->get_entries(); - Gtk::Entry* e; - Glib::ustring text; - for (i = 0; i < (attributes.size()); i++) { - const gchar *val; - e = entries[i]; - val = spat->src.object->getRepr()->attribute(attributes[i].c_str()); + Glib::ustring text=""; + for (guint i = 0; i < (attributes.size()); i++) { + Gtk::Entry* e = entries[i]; + const gchar *val = spat->_object->getRepr()->attribute(attributes[i].c_str()); text = e->get_text (); if (val || !text.empty()) { if (text != val) { @@ -348,40 +245,22 @@ static void sp_attribute_table_object_modified ( SPObject */*object*/, } // end of sp_attribute_table_object_modified() -/** - * \brief Callback for user input in one of the entries. - * - * sp_attribute_table_entry_changed set the object property - * to the new value and updates history. It is a callback from - * the entries created by SPAttributeTable. - * - * @param editable pointer to the entry box. - * @param spat pointer to the SPAttributeTable instance. - */ -static void sp_attribute_table_entry_changed ( Gtk::Editable *editable, +static void sp_attribute_table_entry_changed ( Gtk::Entry *editable, SPAttributeTable *spat ) { if (!spat->blocked) { - guint i; std::vector<Glib::ustring> attributes = spat->get_attributes(); std::vector<Gtk::Entry *> entries = spat->get_entries(); - Gtk::Entry *e; - for (i = 0; i < (attributes.size()); i++) { - e = entries[i]; - if ((GtkWidget*) (editable) == (GtkWidget*) e->gobj()) { + for (guint i = 0; i < (attributes.size()); i++) { + Gtk::Entry *e = entries[i]; + if ((GtkWidget*)editable == (GtkWidget*)e->gobj()) { spat->blocked = true; Glib::ustring text = e->get_text (); - - if (spat->hasobj && spat->src.object) { - spat->src.object->getRepr()->setAttribute(attributes[i].c_str(), text.c_str(), false); - DocumentUndo::done(spat->src.object->document, SP_VERB_NONE, + if (spat->_object) { + spat->_object->getRepr()->setAttribute(attributes[i].c_str(), text.c_str(), false); + DocumentUndo::done(spat->_object->document, SP_VERB_NONE, _("Set attribute")); - - } else if (spat->src.repr) { - - spat->src.repr->setAttribute(attributes[i].c_str(), text.c_str(), false); - /* TODO: Warning! Undo will not be flushed in given case */ } spat->blocked = false; return; @@ -392,12 +271,6 @@ static void sp_attribute_table_entry_changed ( Gtk::Editable *editable, } // end of sp_attribute_table_entry_changed() -/** - * \brief Callback for the delection of the selected object. - * - * sp_attribute_table_object_release invalidates all data of - * SPAttributeTable and disables the widget. - */ static void sp_attribute_table_object_release (SPObject */*object*/, SPAttributeTable *spat) { std::vector<Glib::ustring> labels; |
