summaryrefslogtreecommitdiffstats
path: root/src/widgets/sp-attribute-widget.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'src/widgets/sp-attribute-widget.cpp')
-rw-r--r--src/widgets/sp-attribute-widget.cpp837
1 files changed, 260 insertions, 577 deletions
diff --git a/src/widgets/sp-attribute-widget.cpp b/src/widgets/sp-attribute-widget.cpp
index f3bdc062d..eb90df60e 100644
--- a/src/widgets/sp-attribute-widget.cpp
+++ b/src/widgets/sp-attribute-widget.cpp
@@ -1,8 +1,10 @@
/* Authors:
* Lauris Kaplinski <lauris@ximian.com>
- * Abhishek Sharma
+ * Abhishek Sharma
+ * Kris De Gussem <Kris.DeGussem@gmail.com>
*
* Copyright (C) 2001 Ximian, Inc.
+ * Copyright (C) 2011, authors
* Released under GNU GPL, read the file 'COPYING' for more information
*/
@@ -20,277 +22,126 @@
using Inkscape::DocumentUndo;
-static void sp_attribute_widget_class_init (SPAttributeWidgetClass *klass);
-static void sp_attribute_widget_init (SPAttributeWidget *widget);
-static void sp_attribute_widget_destroy (GtkObject *object);
-
-static void sp_attribute_widget_changed (GtkEditable *editable);
-
static void sp_attribute_widget_object_modified ( SPObject *object,
guint flags,
SPAttributeWidget *spaw );
-static void sp_attribute_widget_object_release ( SPObject *object,
- SPAttributeWidget *spaw );
-
-static GtkEntryClass *parent_class;
-
-
-
-
-GType sp_attribute_widget_get_type(void)
-{
- static GType type = 0;
- if (!type) {
- GTypeInfo info = {
- sizeof(SPAttributeWidgetClass),
- 0, // base_init
- 0, // base_finalize
- (GClassInitFunc)sp_attribute_widget_class_init,
- 0, // class_finalize
- 0, // class_data
- sizeof(SPAttributeWidget),
- 0, // n_preallocs
- (GInstanceInitFunc)sp_attribute_widget_init,
- 0 // value_table
- };
- type = g_type_register_static(GTK_TYPE_ENTRY, "SPAttributeWidget", &info, static_cast<GTypeFlags>(0));
- }
- return type;
-} // end of sp_attribute_widget_get_type()
-
-
-
-static void sp_attribute_widget_class_init (SPAttributeWidgetClass *klass)
-{
- GtkObjectClass *object_class;
- GtkEditableClass *editable_class;
-
- object_class = GTK_OBJECT_CLASS (klass);
- editable_class = GTK_EDITABLE_CLASS (klass);
- parent_class = (GtkEntryClass*)g_type_class_peek_parent (klass);
- object_class->destroy = sp_attribute_widget_destroy;
-
- editable_class->changed = sp_attribute_widget_changed;
-
-} // end of sp_attribute_widget_class_init()
-
-
-
-static void sp_attribute_widget_init (SPAttributeWidget *spaw)
+SPAttributeWidget::SPAttributeWidget () :
+ blocked(0),
+ hasobj(0),
+ _attribute(),
+ modified_connection()
{
- spaw->blocked = FALSE;
- spaw->hasobj = FALSE;
-
- spaw->src.object = NULL;
-
- spaw->attribute = NULL;
-
- new (&spaw->modified_connection) sigc::connection();
- new (&spaw->release_connection) sigc::connection();
+ src.object = NULL;
}
-
-
-static void sp_attribute_widget_destroy (GtkObject *object)
+SPAttributeWidget::~SPAttributeWidget ()
{
-
- SPAttributeWidget *spaw;
-
- spaw = SP_ATTRIBUTE_WIDGET (object);
-
- if (spaw->attribute) {
- g_free (spaw->attribute);
- spaw->attribute = NULL;
- }
-
-
- if (spaw->hasobj) {
-
- if (spaw->src.object) {
- spaw->modified_connection.disconnect();
- spaw->release_connection.disconnect();
- spaw->src.object = NULL;
- }
- } else {
-
- if (spaw->src.repr) {
- spaw->src.repr = Inkscape::GC::release(spaw->src.repr);
+ if (hasobj)
+ {
+ if (src.object)
+ {
+ modified_connection.disconnect();
+ src.object = NULL;
}
- } // end of if()
-
- spaw->modified_connection.~connection();
- spaw->release_connection.~connection();
-
- ((GtkObjectClass *) parent_class)->destroy (object);
-
-}
-
-
-
-static void sp_attribute_widget_changed (GtkEditable *editable)
-{
-
- SPAttributeWidget *spaw;
-
- spaw = SP_ATTRIBUTE_WIDGET (editable);
-
- if (!spaw->blocked) {
-
- const gchar *text;
- spaw->blocked = TRUE;
- text = gtk_entry_get_text (GTK_ENTRY (spaw));
- if (!*text)
- text = NULL;
-
- if (spaw->hasobj && spaw->src.object) {
- spaw->src.object->getRepr()->setAttribute(spaw->attribute, text, false);
- DocumentUndo::done(spaw->src.object->document, SP_VERB_NONE,
- _("Set attribute"));
-
- } else if (spaw->src.repr) {
- spaw->src.repr->setAttribute(spaw->attribute, text, false);
- /* TODO: Warning! Undo will not be flushed in given case */
+ }
+ else
+ {
+ if (src.repr)
+ {
+ src.repr = Inkscape::GC::release(src.repr);
}
- spaw->blocked = FALSE;
}
-
-} // end of sp_attribute_widget_changed()
-
-
-
-GtkWidget *sp_attribute_widget_new ( SPObject *object, const gchar *attribute )
-{
- SPAttributeWidget *spaw;
-
- g_return_val_if_fail (!object || SP_IS_OBJECT (object), NULL);
- g_return_val_if_fail (!object || attribute, NULL);
-
- spaw = (SPAttributeWidget*)g_object_new (SP_TYPE_ATTRIBUTE_WIDGET, NULL);
-
- sp_attribute_widget_set_object (spaw, object, attribute);
-
- return GTK_WIDGET (spaw);
-
-} // end of sp_attribute_widget_new()
-
-
-
-GtkWidget *sp_attribute_widget_new_repr ( Inkscape::XML::Node *repr, const gchar *attribute )
-{
- SPAttributeWidget *spaw;
-
- spaw = (SPAttributeWidget*)g_object_new (SP_TYPE_ATTRIBUTE_WIDGET, NULL);
-
- sp_attribute_widget_set_repr (spaw, repr, attribute);
-
- return GTK_WIDGET (spaw);
}
-
-
-void sp_attribute_widget_set_object ( SPAttributeWidget *spaw,
- SPObject *object,
- const gchar *attribute )
+void SPAttributeWidget::set_object(SPObject *object, const gchar *attribute)
{
-
- g_return_if_fail (spaw != NULL);
- g_return_if_fail (SP_IS_ATTRIBUTE_WIDGET (spaw));
- g_return_if_fail (!object || SP_IS_OBJECT (object));
- g_return_if_fail (!object || attribute);
- g_return_if_fail (attribute != NULL);
-
- if (spaw->attribute) {
- g_free (spaw->attribute);
- spaw->attribute = NULL;
- }
-
- if (spaw->hasobj) {
-
- if (spaw->src.object) {
- spaw->modified_connection.disconnect();
- spaw->release_connection.disconnect();
- spaw->src.object = NULL;
+ if (hasobj) {
+ if (src.object) {
+ modified_connection.disconnect();
+ src.object = NULL;
}
} else {
- if (spaw->src.repr) {
- spaw->src.repr = Inkscape::GC::release(spaw->src.repr);
+ if (src.repr) {
+ src.repr = Inkscape::GC::release(src.repr);
}
}
- spaw->hasobj = TRUE;
-
+ hasobj = true;
+
if (object) {
const gchar *val;
- spaw->blocked = TRUE;
- spaw->src.object = object;
+ blocked = true;
+ src.object = object;
- spaw->modified_connection = object->connectModified(sigc::bind<2>(sigc::ptr_fun(&sp_attribute_widget_object_modified), spaw));
- spaw->release_connection = object->connectRelease(sigc::bind<1>(sigc::ptr_fun(&sp_attribute_widget_object_release), spaw));
+ modified_connection = object->connectModified(sigc::bind<2>(sigc::ptr_fun(&sp_attribute_widget_object_modified), this));
- spaw->attribute = g_strdup (attribute);
+ _attribute = attribute;
val = object->getRepr()->attribute(attribute);
- gtk_entry_set_text (GTK_ENTRY (spaw), val ? val : (const gchar *) "");
- spaw->blocked = FALSE;
+ set_text (val ? val : (const gchar *) "");
+ blocked = false;
}
+ gtk_widget_set_sensitive (GTK_WIDGET(this), (src.object != NULL));
+}
- gtk_widget_set_sensitive (GTK_WIDGET (spaw), (spaw->src.object != NULL));
-
-} // end of sp_attribute_widget_set_object()
-
-
-
-void sp_attribute_widget_set_repr ( SPAttributeWidget *spaw,
- Inkscape::XML::Node *repr,
- const gchar *attribute )
+void SPAttributeWidget::set_repr(Inkscape::XML::Node *repr, const gchar *attribute)
{
-
- g_return_if_fail (spaw != NULL);
- g_return_if_fail (SP_IS_ATTRIBUTE_WIDGET (spaw));
- g_return_if_fail (attribute != NULL);
-
- if (spaw->attribute) {
- g_free (spaw->attribute);
- spaw->attribute = NULL;
- }
-
- if (spaw->hasobj) {
-
- if (spaw->src.object) {
- spaw->modified_connection.disconnect();
- spaw->release_connection.disconnect();
- spaw->src.object = NULL;
+ if (hasobj) {
+ if (src.object) {
+ modified_connection.disconnect();
+ src.object = NULL;
}
} else {
- if (spaw->src.repr) {
- spaw->src.repr = Inkscape::GC::release(spaw->src.repr);
+ if (src.repr) {
+ src.repr = Inkscape::GC::release(src.repr);
}
}
- spaw->hasobj = FALSE;
-
+ hasobj = false;
+
if (repr) {
const gchar *val;
- spaw->blocked = TRUE;
- spaw->src.repr = Inkscape::GC::anchor(repr);
- spaw->attribute = g_strdup (attribute);
+ blocked = true;
+ src.repr = Inkscape::GC::anchor(repr);
+ attribute = g_strdup (attribute);
val = repr->attribute(attribute);
- gtk_entry_set_text (GTK_ENTRY (spaw), val ? val : (const gchar *) "");
- spaw->blocked = FALSE;
+ set_text (val ? val : (const gchar *) "");
+ blocked = false;
}
+ gtk_widget_set_sensitive (GTK_WIDGET (this), (src.repr != NULL));
+}
- gtk_widget_set_sensitive (GTK_WIDGET (spaw), (spaw->src.repr != NULL));
-
-} // end of sp_attribute_widget_set_repr()
+void SPAttributeWidget::on_changed (void)
+{
+ if (!blocked)
+ {
+ Glib::ustring text1;
+ const gchar *text;
+ blocked = true;
+ text1 = get_text ();
+ text = text1.c_str();
+ if (!*text)
+ text = NULL;
+ if (hasobj && src.object) {
+ src.object->getRepr()->setAttribute(_attribute.c_str(), text, false);
+ DocumentUndo::done(src.object->document, SP_VERB_NONE,
+ _("Set attribute"));
+ } else if (src.repr) {
+ src.repr->setAttribute(_attribute.c_str(), text, false);
+ /* TODO: Warning! Undo will not be flushed in given case */
+ }
+ blocked = false;
+ }
+}
static void sp_attribute_widget_object_modified ( SPObject */*object*/,
guint flags,
@@ -299,18 +150,19 @@ static void sp_attribute_widget_object_modified ( SPObject */*object*/,
if (flags && SP_OBJECT_MODIFIED_FLAG) {
- const gchar *val, *text;
- val = spaw->src.object->getRepr()->attribute(spaw->attribute);
- text = gtk_entry_get_text (GTK_ENTRY (spaw));
+ const gchar *val;
+ Glib::ustring text;
+ Glib::ustring attr = spaw->get_attribute();
+ val = spaw->src.object->getRepr()->attribute(attr.c_str());
+ text = spaw->get_text();
- if (val || text) {
+ if (val || !text.empty()) {
- if (!val || !text || strcmp (val, text)) {
+ if (!val || text.empty() || (text == val)) {
/* We are different */
- spaw->blocked = TRUE;
- gtk_entry_set_text ( GTK_ENTRY (spaw),
- val ? val : (const gchar *) "");
- spaw->blocked = FALSE;
+ spaw->set_blocked(true);
+ spaw->set_text(val ? val : (const gchar *) "");
+ spaw->set_blocked(false);
} // end of if()
} // end of if()
@@ -321,364 +173,201 @@ static void sp_attribute_widget_object_modified ( SPObject */*object*/,
-static void
-sp_attribute_widget_object_release ( SPObject */*object*/,
- SPAttributeWidget *spaw )
-{
- sp_attribute_widget_set_object (spaw, NULL, NULL);
-}
-
-
-
/* SPAttributeTable */
-
-static void sp_attribute_table_class_init (SPAttributeTableClass *klass);
-static void sp_attribute_table_init (SPAttributeTable *widget);
-static void sp_attribute_table_destroy (GtkObject *object);
-
static void sp_attribute_table_object_modified (SPObject *object, guint flags, SPAttributeTable *spaw);
-static void sp_attribute_table_object_release (SPObject *object, SPAttributeTable *spaw);
-static void sp_attribute_table_entry_changed (GtkEditable *editable, SPAttributeTable *spat);
-
-static GtkVBoxClass *table_parent_class;
-
-
+static void sp_attribute_table_entry_changed (Gtk::Editable *editable, SPAttributeTable *spat);
+#define XPAD 4
+#define YPAD 0
-GType sp_attribute_table_get_type(void)
+SPAttributeTable::SPAttributeTable () :
+ blocked(0),
+ hasobj(0),
+ table(0),
+ _attributes(),
+ _entries(),
+ modified_connection()
{
- static GType type = 0;
- if (!type) {
- GTypeInfo info = {
- sizeof(SPAttributeTableClass),
- 0, // base_init
- 0, // base_finalize
- (GClassInitFunc)sp_attribute_table_class_init,
- 0, // class_finalize
- 0, // class_data
- sizeof(SPAttributeTable),
- 0, // n_preallocs
- (GInstanceInitFunc)sp_attribute_table_init,
- 0 // value_table
- };
- type = g_type_register_static(GTK_TYPE_VBOX, "SPAttributeTable", &info, static_cast<GTypeFlags>(0));
- }
- return type;
-} // end of sp_attribute_table_get_type()
-
-
+ src.object = NULL;
+}
-static void sp_attribute_table_class_init (SPAttributeTableClass *klass)
+SPAttributeTable::SPAttributeTable (SPObject *object, std::vector<Glib::ustring> &labels, std::vector<Glib::ustring> &attributes, GtkWidget* parent) :
+ blocked(0),
+ hasobj(0),
+ table(0),
+ _attributes(),
+ _entries(),
+ modified_connection()
{
- GtkObjectClass *object_class = GTK_OBJECT_CLASS (klass);
-
- table_parent_class = (GtkVBoxClass*)g_type_class_peek_parent (klass);
-
- object_class->destroy = sp_attribute_table_destroy;
-
-} // end of sp_attribute_table_class_init()
-
-
+ src.object = NULL;
+ set_object(object, labels, attributes, parent);
+}
-static void sp_attribute_table_init ( SPAttributeTable *spat )
+SPAttributeTable::~SPAttributeTable ()
{
- spat->blocked = FALSE;
- spat->hasobj = FALSE;
- spat->table = NULL;
- spat->src.object = NULL;
- spat->num_attr = 0;
- spat->attributes = NULL;
- spat->entries = NULL;
-
- new (&spat->modified_connection) sigc::connection();
- new (&spat->release_connection) sigc::connection();
+ clear();
}
-static void sp_attribute_table_destroy ( GtkObject *object )
+void SPAttributeTable::clear(void)
{
- SPAttributeTable *spat;
-
- spat = SP_ATTRIBUTE_TABLE (object);
-
- if (spat->attributes) {
- gint i;
- for (i = 0; i < spat->num_attr; i++) {
- g_free (spat->attributes[i]);
+ Gtk::Widget *w;
+
+ if (table)
+ {
+ std::vector<Widget*> ch = table->get_children();
+
+ for (int i = (ch.size())-1; i >=0 ; i--)
+ {
+ w = ch[i];
+ ch.pop_back();
+ if (w != NULL)
+ {
+ try
+ {
+ delete w;
+ }
+ catch(...)
+ {
+ }
}
- g_free (spat->attributes);
- spat->attributes = NULL;
}
+ ch.clear();
+ _attributes.clear();
+ _entries.clear();
- if (spat->hasobj) {
+ delete table;
+ table = NULL;
+ }
- if (spat->src.object) {
- spat->modified_connection.disconnect();
- spat->release_connection.disconnect();
- spat->src.object = NULL;
+ if (hasobj) {
+ if (src.object) {
+ modified_connection.disconnect();
+ src.object = NULL;
}
} else {
- if (spat->src.repr) {
- spat->src.repr = Inkscape::GC::release(spat->src.repr);
+ if (src.repr) {
+ src.repr = Inkscape::GC::release(src.repr);
}
- } // end of if()
-
- spat->modified_connection.~connection();
- spat->release_connection.~connection();
-
- if (spat->entries) {
- g_free (spat->entries);
- spat->entries = NULL;
- }
-
- spat->table = NULL;
-
- if (((GtkObjectClass *) table_parent_class)->destroy) {
- (* ((GtkObjectClass *) table_parent_class)->destroy) (object);
}
+}
-} // end of sp_attribute_table_destroy()
-
-
-GtkWidget * sp_attribute_table_new ( SPObject *object,
- gint num_attr,
- const gchar **labels,
- const gchar **attributes )
-{
- SPAttributeTable *spat;
-
- g_return_val_if_fail (!object || SP_IS_OBJECT (object), NULL);
- g_return_val_if_fail (!object || (num_attr > 0), NULL);
- g_return_val_if_fail (!num_attr || (labels && attributes), NULL);
-
- spat = (SPAttributeTable*)g_object_new (SP_TYPE_ATTRIBUTE_TABLE, NULL);
-
- sp_attribute_table_set_object (spat, object, num_attr, labels, attributes);
-
- return GTK_WIDGET (spat);
-
-} // end of sp_attribute_table_new()
-
-
-
-GtkWidget *sp_attribute_table_new_repr ( Inkscape::XML::Node *repr,
- gint num_attr,
- const gchar **labels,
- const gchar **attributes )
-{
- SPAttributeTable *spat;
-
- g_return_val_if_fail (!num_attr || (labels && attributes), NULL);
-
- spat = (SPAttributeTable*)g_object_new (SP_TYPE_ATTRIBUTE_TABLE, NULL);
-
- sp_attribute_table_set_repr (spat, repr, num_attr, labels, attributes);
-
- return GTK_WIDGET (spat);
-
-} // end of sp_attribute_table_new_repr()
-
-
-
-#define XPAD 4
-#define YPAD 0
-
-void sp_attribute_table_set_object ( SPAttributeTable *spat,
- SPObject *object,
- gint num_attr,
- const gchar **labels,
- const gchar **attributes )
+void SPAttributeTable::set_object(SPObject *object,
+ std::vector<Glib::ustring> &labels,
+ std::vector<Glib::ustring> &attributes,
+ GtkWidget* parent)
{
-
- g_return_if_fail (spat != NULL);
- g_return_if_fail (SP_IS_ATTRIBUTE_TABLE (spat));
+ g_return_if_fail (parent);
g_return_if_fail (!object || SP_IS_OBJECT (object));
- g_return_if_fail (!object || (num_attr > 0));
- g_return_if_fail (!num_attr || (labels && attributes));
-
- if (spat->table) {
- gtk_widget_destroy (spat->table);
- spat->table = NULL;
- }
-
- if (spat->attributes) {
- gint i;
- for (i = 0; i < spat->num_attr; i++) {
- g_free (spat->attributes[i]);
- }
- g_free (spat->attributes);
- spat->attributes = NULL;
- }
-
- if (spat->entries) {
- g_free (spat->entries);
- spat->entries = NULL;
- }
-
- if (spat->hasobj) {
- if (spat->src.object) {
- spat->modified_connection.disconnect();
- spat->release_connection.disconnect();
- spat->src.object = NULL;
- }
- } else {
- if (spat->src.repr) {
- spat->src.repr = Inkscape::GC::release(spat->src.repr);
- }
- }
+ g_return_if_fail (!object || !labels.empty() || !attributes.empty());
+ g_return_if_fail (labels.size() == attributes.size());
- spat->hasobj = TRUE;
+ clear();
+ hasobj = true;
if (object) {
- gint i;
-
- spat->blocked = TRUE;
-
- /* Set up object */
- spat->src.object = object;
- spat->num_attr = num_attr;
-
- spat->modified_connection = object->connectModified(sigc::bind<2>(sigc::ptr_fun(&sp_attribute_table_object_modified), spat));
- spat->release_connection = object->connectRelease(sigc::bind<1>(sigc::ptr_fun(&sp_attribute_table_object_release), spat));
-
- /* Create table */
- spat->table = gtk_table_new (num_attr, 2, FALSE);
- gtk_container_add (GTK_CONTAINER (spat), spat->table);
- /* Arrays */
- spat->attributes = g_new0 (gchar *, num_attr);
- spat->entries = g_new0 (GtkWidget *, num_attr);
- /* Fill rows */
- for (i = 0; i < num_attr; i++) {
- GtkWidget *w;
+ blocked = true;
+
+ // Set up object
+ src.object = object;
+ modified_connection = object->connectModified(sigc::bind<2>(sigc::ptr_fun(&sp_attribute_table_object_modified), this));
+
+ // Create table
+ table = Gtk::manage(new Gtk::Table (attributes.size(), 2, false));
+ gtk_container_add (GTK_CONTAINER (parent),(GtkWidget*)table->gobj());
+
+ // Fill rows
+ _attributes = attributes;
+ for (gint i = 0; i < (attributes.size()); i++) {
+ Gtk::Label *ll;
+ Gtk::Entry *ee;
+ Gtk::Widget *w;
const gchar *val;
- spat->attributes[i] = g_strdup (attributes[i]);
- w = gtk_label_new (_(labels[i]));
- gtk_widget_show (w);
- gtk_misc_set_alignment (GTK_MISC (w), 1.0, 0.5);
- gtk_table_attach ( GTK_TABLE (spat->table), w, 0, 1, i, i + 1,
- GTK_FILL,
- (GtkAttachOptions)(GTK_EXPAND | GTK_FILL),
+ 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 );
- w = gtk_entry_new ();
- gtk_widget_show (w);
- val = object->getRepr()->attribute(attributes[i]);
- gtk_entry_set_text (GTK_ENTRY (w), val ? val : (const gchar *) "");
- gtk_table_attach ( GTK_TABLE (spat->table), w, 1, 2, i, i + 1,
- (GtkAttachOptions)(GTK_EXPAND | GTK_FILL),
- (GtkAttachOptions)(GTK_EXPAND | GTK_FILL),
+ ee = new Gtk::Entry();
+ w = (Gtk::Widget *) ee;
+ ee->show();
+ val = object->getRepr()->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 );
- spat->entries[i] = w;
- g_signal_connect ( G_OBJECT (w), "changed",
+ _entries.push_back(w);
+ g_signal_connect ( w->gobj(), "changed",
G_CALLBACK (sp_attribute_table_entry_changed),
- spat );
+ this );
}
/* Show table */
- gtk_widget_show (spat->table);
-
- spat->blocked = FALSE;
+ table->show ();
+ blocked = false;
}
+}
- gtk_widget_set_sensitive ( GTK_WIDGET (spat),
- (spat->src.object != NULL) );
-
-} // end of sp_attribute_table_set_object()
-
-
-
-void sp_attribute_table_set_repr ( SPAttributeTable *spat,
- Inkscape::XML::Node *repr,
- gint num_attr,
- const gchar **labels,
- const gchar **attributes )
+void SPAttributeTable::set_repr (Inkscape::XML::Node *repr,
+ std::vector<Glib::ustring> &labels,
+ std::vector<Glib::ustring> &attributes,
+ GtkWidget* parent)
{
- g_return_if_fail (spat != NULL);
- g_return_if_fail (SP_IS_ATTRIBUTE_TABLE (spat));
- g_return_if_fail (!num_attr || (labels && attributes));
+ g_return_if_fail (!labels.empty() || !attributes.empty());
+ g_return_if_fail (labels.size() == attributes.size());
- if (spat->table) {
- gtk_widget_destroy (spat->table);
- spat->table = NULL;
- }
+ clear();
- if (spat->attributes) {
- gint i;
- for (i = 0; i < spat->num_attr; i++) {
- g_free (spat->attributes[i]);
- }
- g_free (spat->attributes);
- spat->attributes = NULL;
- }
-
- if (spat->entries) {
- g_free (spat->entries);
- spat->entries = NULL;
- }
-
- if (spat->hasobj) {
- if (spat->src.object) {
- spat->modified_connection.disconnect();
- spat->release_connection.disconnect();
- spat->src.object = NULL;
- }
- } else {
- if (spat->src.repr) {
- spat->src.repr = Inkscape::GC::release(spat->src.repr);
- }
- }
-
- spat->hasobj = FALSE;
+ hasobj = false;
if (repr) {
- gint i;
-
- spat->blocked = TRUE;
-
- /* Set up repr */
- spat->src.repr = Inkscape::GC::anchor(repr);
- spat->num_attr = num_attr;
- /* Create table */
- spat->table = gtk_table_new (num_attr, 2, FALSE);
- gtk_container_add (GTK_CONTAINER (spat), spat->table);
- /* Arrays */
- spat->attributes = g_new0 (gchar *, num_attr);
- spat->entries = g_new0 (GtkWidget *, num_attr);
-
- /* Fill rows */
- for (i = 0; i < num_attr; i++) {
- GtkWidget *w;
+ blocked = true;
+
+ // Set up repr
+ src.repr = Inkscape::GC::anchor(repr);
+
+ // Create table
+ table = new Gtk::Table (attributes.size(), 2, false);
+ gtk_container_add (GTK_CONTAINER (parent),(GtkWidget*)table->gobj());
+
+ // Fill rows
+ _attributes = attributes;
+ for (gint i = 0; i < (attributes.size()); i++) {
+ Gtk::Label *ll;
+ Gtk::Entry *ee;
+ Gtk::Widget *w;
const gchar *val;
- spat->attributes[i] = g_strdup (attributes[i]);
- w = gtk_label_new (labels[i]);
- gtk_widget_show (w);
- gtk_misc_set_alignment (GTK_MISC (w), 1.0, 0.5);
- gtk_table_attach ( GTK_TABLE (spat->table), w, 0, 1, i, i + 1,
- GTK_FILL,
- (GtkAttachOptions)(GTK_EXPAND | GTK_FILL),
+ 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 );
- w = gtk_entry_new ();
- gtk_widget_show (w);
- val = repr->attribute(attributes[i]);
- gtk_entry_set_text (GTK_ENTRY (w), val ? val : (const gchar *) "");
- gtk_table_attach ( GTK_TABLE (spat->table), w, 1, 2, i, i + 1,
- (GtkAttachOptions)(GTK_EXPAND | GTK_FILL),
- (GtkAttachOptions)(GTK_EXPAND | GTK_FILL),
+ 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 );
- spat->entries[i] = w;
- g_signal_connect ( G_OBJECT (w), "changed",
+ _entries.push_back(w);
+ g_signal_connect ( w->gobj(), "changed",
G_CALLBACK (sp_attribute_table_entry_changed),
- spat );
+ this );
}
/* Show table */
- gtk_widget_show (spat->table);
-
- spat->blocked = FALSE;
+ table->show ();
+ blocked = false;
}
-
- gtk_widget_set_sensitive (GTK_WIDGET (spat), (spat->src.repr != NULL));
-
-} // end of sp_attribute_table_set_repr()
-
+}
static void sp_attribute_table_object_modified ( SPObject */*object*/,
@@ -688,17 +377,21 @@ static void sp_attribute_table_object_modified ( SPObject */*object*/,
if (flags && SP_OBJECT_MODIFIED_FLAG)
{
gint i;
- for (i = 0; i < spat->num_attr; i++) {
- const gchar *val, *text;
- val = spat->src.object->getRepr()->attribute(spat->attributes[i]);
- text = gtk_entry_get_text (GTK_ENTRY (spat->entries[i]));
- if (val || text) {
- if (!val || !text || strcmp (val, text)) {
+ std::vector<Glib::ustring> attributes = spat->get_attributes();
+ std::vector<Gtk::Widget *> entries = spat->get_entries();
+ Gtk::Entry* e;
+ Glib::ustring text;
+ for (i = 0; i < (attributes.size()); i++) {
+ const gchar *val;
+ e = (Gtk::Entry*) entries[i];
+ val = spat->src.object->getRepr()->attribute(attributes[i].c_str());
+ text = e->get_text ();
+ if (val || !text.empty()) {
+ if (text != val) {
/* We are different */
- spat->blocked = TRUE;
- gtk_entry_set_text ( GTK_ENTRY (spat->entries[i]),
- val ? val : (const gchar *) "");
- spat->blocked = FALSE;
+ spat->blocked = true;
+ e->set_text (val ? val : (const gchar *) "");
+ spat->blocked = false;
}
}
}
@@ -706,42 +399,32 @@ static void sp_attribute_table_object_modified ( SPObject */*object*/,
} // end of sp_attribute_table_object_modified()
-
-
-static void sp_attribute_table_object_release (SPObject */*object*/, SPAttributeTable *spat)
-{
- sp_attribute_table_set_object (spat, NULL, 0, NULL, NULL);
-}
-
-
-
-static void sp_attribute_table_entry_changed ( GtkEditable *editable,
+static void sp_attribute_table_entry_changed ( Gtk::Editable *editable,
SPAttributeTable *spat )
{
if (!spat->blocked)
{
gint i;
- for (i = 0; i < spat->num_attr; i++) {
-
- if (GTK_WIDGET (editable) == spat->entries[i]) {
- const gchar *text;
- spat->blocked = TRUE;
- text = gtk_entry_get_text (GTK_ENTRY (spat->entries[i]));
-
- if (!*text)
- text = NULL;
+ std::vector<Glib::ustring> attributes = spat->get_attributes();
+ std::vector<Gtk::Widget *> entries = spat->get_entries();
+ Gtk::Entry *e;
+ for (i = 0; i < (attributes.size()); i++) {
+ e = (Gtk::Entry *) 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(spat->attributes[i], text, false);
+ spat->src.object->getRepr()->setAttribute(attributes[i].c_str(), text.c_str(), false);
DocumentUndo::done(spat->src.object->document, SP_VERB_NONE,
_("Set attribute"));
} else if (spat->src.repr) {
- spat->src.repr->setAttribute(spat->attributes[i], text, false);
+ 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;
+ spat->blocked = false;
return;
}
}