Logo Search packages:      
Sourcecode: inkscape version File versions  Download package

void Inkscape::XML::SimpleNode::setAttribute ( gchar const *  key,
gchar const *  value,
bool  is_interactive = false 
) [virtual, inherited]

Change an attribute of this node.

The strings passed to this method are copied, so you can free them after use.

Parameters:
key Name of the attribute to change
value The new value of the attribute
is_interactive Ignored

Implements Inkscape::XML::Node.

Definition at line 310 of file simple-node.cpp.

References Inkscape::XML::Document::logger(), Inkscape::XML::CompositeNodeObserver::notifyAttributeChanged(), Inkscape::XML::NodeObserver::notifyAttributeChanged(), Inkscape::Util::rest(), and Inkscape::Util::set_rest().

Referenced by Inkscape::XML::SimpleNode::mergeFrom().

{
    g_return_if_fail(name && *name);

    GQuark const key = g_quark_from_string(name);

    MutableList<AttributeRecord> ref;
    MutableList<AttributeRecord> existing;
    for ( existing = _attributes ; existing ; ++existing ) {
        if ( existing->key == key ) {
            break;
        }
        ref = existing;
    }

    Debug::EventTracker<> tracker;

    ptr_shared<char> old_value=( existing ? existing->value : ptr_shared<char>() );

    ptr_shared<char> new_value=ptr_shared<char>();
    if (value) {
        new_value = share_string(value);
        tracker.set<DebugSetAttribute>(*this, key, new_value);
        if (!existing) {
            if (ref) {
                set_rest(ref, MutableList<AttributeRecord>(AttributeRecord(key, new_value)));
            } else {
                _attributes = MutableList<AttributeRecord>(AttributeRecord(key, new_value));
            }
        } else {
            existing->value = new_value;
        }
    } else {
        tracker.set<DebugClearAttribute>(*this, key);
        if (existing) {
            if (ref) {
                set_rest(ref, rest(existing));
            } else {
                _attributes = rest(existing);
            }
            set_rest(existing, MutableList<AttributeRecord>());
        }
    }

    if ( new_value != old_value && (!old_value || !new_value || strcmp(old_value, new_value))) {
        _document->logger()->notifyAttributeChanged(*this, key, old_value, new_value);
        _observers.notifyAttributeChanged(*this, key, old_value, new_value);
    }
}


Generated by  Doxygen 1.6.0   Back to index