diff options
| author | Johan B. C. Engelen <jbc.engelen@swissonline.ch> | 2008-03-24 21:58:41 +0000 |
|---|---|---|
| committer | johanengelen <johanengelen@users.sourceforge.net> | 2008-03-24 21:58:41 +0000 |
| commit | c738eeee2a05689efaf8d4543557063534d8f9a3 (patch) | |
| tree | 2fcf79f2952d86ef8f3f2233d36d825c40231fd0 /src/uri-references.cpp | |
| parent | Visually indicate linked devices (diff) | |
| download | inkscape-c738eeee2a05689efaf8d4543557063534d8f9a3.tar.gz inkscape-c738eeee2a05689efaf8d4543557063534d8f9a3.zip | |
whitespace. tab to spaces. improve readability
(bzr r5188)
Diffstat (limited to 'src/uri-references.cpp')
| -rw-r--r-- | src/uri-references.cpp | 177 |
1 files changed, 92 insertions, 85 deletions
diff --git a/src/uri-references.cpp b/src/uri-references.cpp index 8041fbf52..d979fe292 100644 --- a/src/uri-references.cpp +++ b/src/uri-references.cpp @@ -26,120 +26,127 @@ namespace Inkscape { URIReference::URIReference(SPObject *owner) - : _owner(owner), _owner_document(NULL), _obj(NULL), _uri(NULL) + : _owner(owner), _owner_document(NULL), _obj(NULL), _uri(NULL) { - g_assert(_owner != NULL); - /* FIXME !!! attach to owner's destroy signal to clean up in case */ + g_assert(_owner != NULL); + /* FIXME !!! attach to owner's destroy signal to clean up in case */ } URIReference::URIReference(SPDocument *owner_document) - : _owner(NULL), _owner_document(owner_document), _obj(NULL), _uri(NULL) + : _owner(NULL), _owner_document(owner_document), _obj(NULL), _uri(NULL) { - g_assert(_owner_document != NULL); + g_assert(_owner_document != NULL); } -URIReference::~URIReference() { - detach(); +URIReference::~URIReference() +{ + detach(); } void URIReference::attach(const URI &uri) throw(BadURIException) { - SPDocument *document; - if (_owner) { - document = SP_OBJECT_DOCUMENT(_owner); - } else if (_owner_document) { - document = _owner_document; - } else { - g_assert_not_reached(); - } - gchar const *fragment = uri.getFragment(); - if ( !uri.isRelative() || uri.getQuery() || !fragment ) { - throw UnsupportedURIException(); - } - - /* FIXME !!! real xpointer support should be delegated to document */ - /* for now this handles the minimal xpointer form that SVG 1.0 - * requires of us - */ - gchar *id; - if (!strncmp(fragment, "xpointer(", 9)) { - /* FIXME !!! this is wasteful */ - /* FIXME: It looks as though this is including "))" in the id. I suggest moving - the strlen calculation and validity testing to before strdup, and copying just - the id without the "))". -- pjrm */ - if (!strncmp(fragment, "xpointer(id(", 12)) { - id = g_strdup(fragment+12); - size_t const len = strlen(id); - if ( len < 3 || strcmp(id+len-2, "))") ) { - g_free(id); - throw MalformedURIException(); - } - } else { - throw UnsupportedURIException(); - } - } else { - id = g_strdup(fragment); - } - - /* FIXME !!! validate id as an NCName somewhere */ - - if (_uri) { - delete _uri; - } - _uri = new URI(uri); - - _connection.disconnect(); - _setObject(document->getObjectById(id)); - _connection = document->connectIdChanged(id, sigc::mem_fun(*this, &URIReference::_setObject)); - - g_free(id); + SPDocument *document; + if (_owner) { + document = SP_OBJECT_DOCUMENT(_owner); + } else if (_owner_document) { + document = _owner_document; + } else { + g_assert_not_reached(); + } + + gchar const *fragment = uri.getFragment(); + if ( !uri.isRelative() || uri.getQuery() || !fragment ) { + throw UnsupportedURIException(); + } + + /* FIXME !!! real xpointer support should be delegated to document */ + /* for now this handles the minimal xpointer form that SVG 1.0 + * requires of us + */ + gchar *id; + if (!strncmp(fragment, "xpointer(", 9)) { + /* FIXME !!! this is wasteful */ + /* FIXME: It looks as though this is including "))" in the id. I suggest moving + the strlen calculation and validity testing to before strdup, and copying just + the id without the "))". -- pjrm */ + if (!strncmp(fragment, "xpointer(id(", 12)) { + id = g_strdup(fragment+12); + size_t const len = strlen(id); + if ( len < 3 || strcmp(id+len-2, "))") ) { + g_free(id); + throw MalformedURIException(); + } + } else { + throw UnsupportedURIException(); + } + } else { + id = g_strdup(fragment); + } + + /* FIXME !!! validate id as an NCName somewhere */ + + if (_uri) { + delete _uri; + } + _uri = new URI(uri); + + _connection.disconnect(); + _setObject(document->getObjectById(id)); + _connection = document->connectIdChanged(id, sigc::mem_fun(*this, &URIReference::_setObject)); + + g_free(id); } -void URIReference::detach() { - _connection.disconnect(); - delete _uri; - _uri = NULL; - _setObject(NULL); +void URIReference::detach() +{ + _connection.disconnect(); + delete _uri; + _uri = NULL; + _setObject(NULL); } -void URIReference::_setObject(SPObject *obj) { - if ( obj && !_acceptObject(obj) ) { - obj = NULL; - } - - if ( obj == _obj ) return; - - SPObject *old_obj=_obj; - _obj = obj; - - _release_connection.disconnect(); - if (_obj) { - sp_object_href(_obj, _owner); - _release_connection = _obj->connectRelease(sigc::mem_fun(*this, &URIReference::_release)); - } - _changed_signal.emit(old_obj, _obj); - if (old_obj) { - /* release the old object _after_ the signal emission */ - sp_object_hunref(old_obj, _owner); - } +void URIReference::_setObject(SPObject *obj) +{ + if ( obj && !_acceptObject(obj) ) { + obj = NULL; + } + + if ( obj == _obj ) return; + + SPObject *old_obj=_obj; + _obj = obj; + + _release_connection.disconnect(); + if (_obj) { + sp_object_href(_obj, _owner); + _release_connection = _obj->connectRelease(sigc::mem_fun(*this, &URIReference::_release)); + } + _changed_signal.emit(old_obj, _obj); + if (old_obj) { + /* release the old object _after_ the signal emission */ + sp_object_hunref(old_obj, _owner); + } } /* If an object is deleted, current semantics require that we release * it on its "release" signal, rather than later, when its ID is actually * unregistered from the document. */ -void URIReference::_release(SPObject *obj) { - g_assert( _obj == obj ); - _setObject(NULL); +void URIReference::_release(SPObject *obj) +{ + g_assert( _obj == obj ); + _setObject(NULL); } } /* namespace Inkscape */ + + SPObject* sp_css_uri_reference_resolve( SPDocument *document, const gchar *uri ) { SPObject* ref = 0; - if ( document && uri && ( strncmp(uri, "url(", 4) == 0 )) { + if ( document && uri && ( strncmp(uri, "url(", 4) == 0 ) ) { gchar *trimmed = extract_uri( uri ); if ( trimmed ) { ref = sp_uri_reference_resolve( document, trimmed ); |
