diff options
| author | Liam P. White <inkscapebronyat-signgmaildotcom> | 2014-03-05 02:24:03 +0000 |
|---|---|---|
| committer | Liam P. White <inkscapebronyat-signgmaildotcom> | 2014-03-05 02:24:03 +0000 |
| commit | 3093434e177d4bb7ccc57c1339fad00d47431c17 (patch) | |
| tree | 730371a0630bbd8aa205f032c26872153a0fb40d /src | |
| parent | Added some basic swatch stuff (does not compile) (diff) | |
| download | inkscape-3093434e177d4bb7ccc57c1339fad00d47431c17.tar.gz inkscape-3093434e177d4bb7ccc57c1339fad00d47431c17.zip | |
Added a few swatch related functions (does not compile)
(bzr r13090.1.15)
Diffstat (limited to 'src')
| -rw-r--r-- | src/sp-gradient-fns.h | 47 | ||||
| -rw-r--r-- | src/sp-tag-use-reference.cpp | 147 | ||||
| -rw-r--r-- | src/sp-tag-use-reference.h | 77 | ||||
| -rw-r--r-- | src/sp-tag-use.cpp | 281 | ||||
| -rw-r--r-- | src/sp-tag-use.h | 53 | ||||
| -rw-r--r-- | src/sp-tag.cpp | 240 | ||||
| -rw-r--r-- | src/sp-tag.h | 55 | ||||
| -rw-r--r-- | src/ui/dialog/swatches.cpp | 2 | ||||
| -rw-r--r-- | src/ui/widget/addtoicon.cpp | 149 | ||||
| -rw-r--r-- | src/ui/widget/addtoicon.h | 98 |
10 files changed, 1148 insertions, 1 deletions
diff --git a/src/sp-gradient-fns.h b/src/sp-gradient-fns.h new file mode 100644 index 000000000..e57877256 --- /dev/null +++ b/src/sp-gradient-fns.h @@ -0,0 +1,47 @@ +#ifndef SEEN_SP_GRADIENT_FNS_H +#define SEEN_SP_GRADIENT_FNS_H + +/** \file + * Macros and fn declarations related to gradients. + */ + +#include <glib.h> +#include <glib-object.h> +#include <2geom/forward.h> +#include "sp-gradient-spread.h" +#include "sp-gradient-units.h" + +class SPGradient; +class SPMeshGradient; + +SPGradientSpread sp_gradient_get_spread (SPGradient *gradient); + +/* Gradient repr methods */ +void sp_gradient_repr_write_vector(SPGradient *gr); +void sp_gradient_repr_clear_vector(SPGradient *gr); + +void sp_meshgradient_repr_write(SPMeshGradient *mg); + +cairo_pattern_t *sp_gradient_create_preview_pattern(SPGradient *gradient, double width); + +/** Transforms to/from gradient position space in given environment */ +Geom::Affine sp_gradient_get_g2d_matrix(SPGradient const *gr, Geom::Affine const &ctm, + Geom::Rect const &bbox); +Geom::Affine sp_gradient_get_gs2d_matrix(SPGradient const *gr, Geom::Affine const &ctm, + Geom::Rect const &bbox); +void sp_gradient_set_gs2d_matrix(SPGradient *gr, Geom::Affine const &ctm, Geom::Rect const &bbox, + Geom::Affine const &gs2d); + + +#endif /* !SEEN_SP_GRADIENT_FNS_H */ + +/* + 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:fileencoding=utf-8:textwidth=99 : diff --git a/src/sp-tag-use-reference.cpp b/src/sp-tag-use-reference.cpp new file mode 100644 index 000000000..8e48c0285 --- /dev/null +++ b/src/sp-tag-use-reference.cpp @@ -0,0 +1,147 @@ +/* + * The reference corresponding to href of <inkscape:tagref> element. + * + * Copyright (C) Theodore Janeczko 2012 <flutterguy317@gmail.com> + * + * Released under GNU GPL, read the file 'COPYING' for more information. + */ + +#include <cstring> +#include <string> +#include <string.h> + +#include "enums.h" +#include "sp-tag-use-reference.h" + +#include "display/curve.h" +#include "livarot/Path.h" +#include "preferences.h" +#include "sp-shape.h" +#include "sp-text.h" +#include "uri.h" + + + +bool SPTagUseReference::_acceptObject(SPObject * const obj) const +{ + if (SP_IS_ITEM(obj)) { + SPObject * const owner = getOwner(); + // Refuse references to us or to an ancestor. + for ( SPObject *iter = owner ; iter ; iter = iter->parent ) { + if ( iter == obj ) { + return false; + } + } + return true; + } else { + return false; + } +} + + +static void sp_usepath_href_changed(SPObject *old_ref, SPObject *ref, SPTagUsePath *offset); +static void sp_usepath_delete_self(SPObject *deleted, SPTagUsePath *offset); + +SPTagUsePath::SPTagUsePath(SPObject* i_owner):SPTagUseReference(i_owner) +{ + owner=i_owner; + originalPath = NULL; + sourceDirty=false; + sourceHref = NULL; + sourceRepr = NULL; + sourceObject = NULL; + _changed_connection = changedSignal().connect(sigc::bind(sigc::ptr_fun(sp_usepath_href_changed), this)); // listening to myself, this should be virtual instead + + user_unlink = NULL; +} + +SPTagUsePath::~SPTagUsePath(void) +{ + delete originalPath; + originalPath = NULL; + + _changed_connection.disconnect(); // to do before unlinking + + quit_listening(); + unlink(); +} + +void +SPTagUsePath::link(char *to) +{ + if ( to == NULL ) { + quit_listening(); + unlink(); + } else { + if ( !sourceHref || ( strcmp(to, sourceHref) != 0 ) ) { + g_free(sourceHref); + sourceHref = g_strdup(to); + try { + attach(Inkscape::URI(to)); + } catch (Inkscape::BadURIException &e) { + /* TODO: Proper error handling as per + * http://www.w3.org/TR/SVG11/implnote.html#ErrorProcessing. + */ + g_warning("%s", e.what()); + detach(); + } + } + } +} + +void +SPTagUsePath::unlink(void) +{ + g_free(sourceHref); + sourceHref = NULL; + detach(); +} + +void +SPTagUsePath::start_listening(SPObject* to) +{ + if ( to == NULL ) { + return; + } + sourceObject = to; + sourceRepr = to->getRepr(); + _delete_connection = to->connectDelete(sigc::bind(sigc::ptr_fun(&sp_usepath_delete_self), this)); +} + +void +SPTagUsePath::quit_listening(void) +{ + if ( sourceObject == NULL ) { + return; + } + _delete_connection.disconnect(); + sourceRepr = NULL; + sourceObject = NULL; +} + +static void +sp_usepath_href_changed(SPObject */*old_ref*/, SPObject */*ref*/, SPTagUsePath *offset) +{ + offset->quit_listening(); + SPItem *refobj = offset->getObject(); + if ( refobj ) { + offset->start_listening(refobj); + } +} + +static void +sp_usepath_delete_self(SPObject */*deleted*/, SPTagUsePath *offset) +{ + offset->owner->deleteObject(); +} + +/* + 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 : diff --git a/src/sp-tag-use-reference.h b/src/sp-tag-use-reference.h new file mode 100644 index 000000000..039d2fd7d --- /dev/null +++ b/src/sp-tag-use-reference.h @@ -0,0 +1,77 @@ +#ifndef SEEN_SP_TAG_USE_REFERENCE_H +#define SEEN_SP_TAG_USE_REFERENCE_H + +/* + * The reference corresponding to href of <inkscape:tagref> element. + * + * Copyright (C) Theodore Janeczko 2012 <flutterguy317@gmail.com> + * + * Released under GNU GPL, read the file 'COPYING' for more information. + */ + +#include "sp-object.h" +#include "sp-item.h" +#include <uri-references.h> +#include <stddef.h> +#include <sigc++/sigc++.h> + +class Path; + +namespace Inkscape { +namespace XML { + struct Node; +} +} + + +class SPTagUseReference : public Inkscape::URIReference { +public: + SPTagUseReference(SPObject *owner) : URIReference(owner) {} + + SPItem *getObject() const { + return static_cast<SPItem *>(URIReference::getObject()); + } + +protected: + virtual bool _acceptObject(SPObject * const obj) const; + +}; + + +class SPTagUsePath : public SPTagUseReference { +public: + Path *originalPath; + bool sourceDirty; + + SPObject *owner; + gchar *sourceHref; + Inkscape::XML::Node *sourceRepr; + SPObject *sourceObject; + + sigc::connection _delete_connection; + sigc::connection _changed_connection; + + SPTagUsePath(SPObject* i_owner); + ~SPTagUsePath(void); + + void link(char* to); + void unlink(void); + void start_listening(SPObject* to); + void quit_listening(void); + void refresh_source(void); + + void (*user_unlink) (SPObject *user); +}; + +#endif /* !SEEN_SP_USE_REFERENCE_H */ + +/* + 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 : diff --git a/src/sp-tag-use.cpp b/src/sp-tag-use.cpp new file mode 100644 index 000000000..4c5171bbb --- /dev/null +++ b/src/sp-tag-use.cpp @@ -0,0 +1,281 @@ +/* + * SVG <inkscape:tagref> implementation + * + * Authors: + * Theodore Janeczko + * + * Copyright (C) Theodore Janeczko 2012 <flutterguy317@gmail.com> + * + * Released under GNU GPL, read the file 'COPYING' for more information + */ + +#ifdef HAVE_CONFIG_H +# include <config.h> +#endif + +#include <cstring> +#include <string> + +#include <glibmm/i18n.h> +#include "display/drawing-group.h" +#include "attributes.h" +#include "document.h" +#include "sp-object-repr.h" +#include "uri.h" +#include "xml/repr.h" +#include "preferences.h" +#include "style.h" +#include "sp-symbol.h" +#include "sp-tag-use.h" +#include "sp-tag-use-reference.h" + +/* fixme: */ + +static void sp_tag_use_class_init(SPTagUseClass *classname); +static void sp_tag_use_init(SPTagUse *use); +static void sp_tag_use_finalize(GObject *obj); + +static void sp_tag_use_build(SPObject *object, SPDocument *document, Inkscape::XML::Node *repr); +static void sp_tag_use_release(SPObject *object); +static void sp_tag_use_set(SPObject *object, unsigned key, gchar const *value); +static Inkscape::XML::Node *sp_tag_use_write(SPObject *object, Inkscape::XML::Document *doc, Inkscape::XML::Node *repr, guint flags); +static void sp_tag_use_update(SPObject *object, SPCtx *ctx, guint flags); + +static void sp_tag_use_href_changed(SPObject *old_ref, SPObject *ref, SPTagUse *use); + +static SPObjectClass *parent_class; + + +GType +sp_tag_use_get_type(void) +{ + static GType use_type = 0; + if (!use_type) { + GTypeInfo use_info = { + sizeof(SPTagUseClass), + NULL, /* base_init */ + NULL, /* base_finalize */ + (GClassInitFunc) sp_tag_use_class_init, + NULL, /* class_finalize */ + NULL, /* class_data */ + sizeof(SPTagUse), + 16, /* n_preallocs */ + (GInstanceInitFunc) sp_tag_use_init, + NULL, /* value_table */ + }; + use_type = g_type_register_static(SP_TYPE_OBJECT, "SPTagUse", &use_info, (GTypeFlags)0); + } + return use_type; +} + +static void +sp_tag_use_class_init(SPTagUseClass *classname) +{ + GObjectClass *gobject_class = (GObjectClass *) classname; + SPObjectClass *sp_object_class = (SPObjectClass *) classname; + + parent_class = (SPObjectClass*)g_type_class_peek_parent(classname); + + gobject_class->finalize = sp_tag_use_finalize; + + sp_object_class->build = sp_tag_use_build; + sp_object_class->release = sp_tag_use_release; + sp_object_class->set = sp_tag_use_set; + sp_object_class->write = sp_tag_use_write; + sp_object_class->update = sp_tag_use_update; +} + +static void +sp_tag_use_init(SPTagUse *use) +{ + use->href = NULL; + + new (&use->_changed_connection) sigc::connection(); + + use->ref = new SPTagUseReference(use); + + use->_changed_connection = use->ref->changedSignal().connect(sigc::bind(sigc::ptr_fun(sp_tag_use_href_changed), use)); +} + +static void +sp_tag_use_finalize(GObject *obj) +{ + SPTagUse *use = reinterpret_cast<SPTagUse *>(obj); + + if (use->child) { + use->detach(use->child); + use->child = NULL; + } + + use->ref->detach(); + delete use->ref; + use->ref = 0; + + use->_changed_connection.~connection(); + +} + +static void +sp_tag_use_build(SPObject *object, SPDocument *document, Inkscape::XML::Node *repr) +{ + if (((SPObjectClass *) parent_class)->build) { + (* ((SPObjectClass *) parent_class)->build)(object, document, repr); + } + + object->readAttr( "xlink:href" ); + + // We don't need to create child here: + // reading xlink:href will attach ref, and that will cause the changed signal to be emitted, + // which will call sp_tag_use_href_changed, and that will take care of the child +} + +static void +sp_tag_use_release(SPObject *object) +{ + SPTagUse *use = SP_TAG_USE(object); + + if (use->child) { + object->detach(use->child); + use->child = NULL; + } + + use->_changed_connection.disconnect(); + + g_free(use->href); + use->href = NULL; + + use->ref->detach(); + + if (((SPObjectClass *) parent_class)->release) { + ((SPObjectClass *) parent_class)->release(object); + } +} + +static void +sp_tag_use_set(SPObject *object, unsigned key, gchar const *value) +{ + SPTagUse *use = SP_TAG_USE(object); + + switch (key) { + case SP_ATTR_XLINK_HREF: { + if ( value && use->href && ( strcmp(value, use->href) == 0 ) ) { + /* No change, do nothing. */ + } else { + g_free(use->href); + use->href = NULL; + if (value) { + // First, set the href field, because sp_tag_use_href_changed will need it. + use->href = g_strdup(value); + + // Now do the attaching, which emits the changed signal. + try { + use->ref->attach(Inkscape::URI(value)); + } catch (Inkscape::BadURIException &e) { + g_warning("%s", e.what()); + use->ref->detach(); + } + } else { + use->ref->detach(); + } + } + break; + } + + default: + if (((SPObjectClass *) parent_class)->set) { + ((SPObjectClass *) parent_class)->set(object, key, value); + } + break; + } +} + +static Inkscape::XML::Node * +sp_tag_use_write(SPObject *object, Inkscape::XML::Document *xml_doc, Inkscape::XML::Node *repr, guint flags) +{ + SPTagUse *use = SP_TAG_USE(object); + + if ((flags & SP_OBJECT_WRITE_BUILD) && !repr) { + repr = xml_doc->createElement("inkscape:tagref"); + } + + if (((SPObjectClass *) (parent_class))->write) { + ((SPObjectClass *) (parent_class))->write(object, xml_doc, repr, flags); + } + + if (use->ref->getURI()) { + gchar *uri_string = use->ref->getURI()->toString(); + repr->setAttribute("xlink:href", uri_string); + g_free(uri_string); + } + + return repr; +} + +/** + * Returns the ultimate original of a SPTagUse (i.e. the first object in the chain of its originals + * which is not an SPTagUse). If no original is found, NULL is returned (it is the responsibility + * of the caller to make sure that this is handled correctly). + * + * Note that the returned is the clone object, i.e. the child of an SPTagUse (of the argument one for + * the trivial case) and not the "true original". + */ +SPItem * +sp_tag_use_root(SPTagUse *use) +{ + SPObject *orig = use->child; + while (orig && SP_IS_TAG_USE(orig)) { + orig = SP_TAG_USE(orig)->child; + } + if (!orig || !SP_IS_ITEM(orig)) + return NULL; + return SP_ITEM(orig); +} + +static void +sp_tag_use_href_changed(SPObject */*old_ref*/, SPObject */*ref*/, SPTagUse *use) +{ + if (use->href) { + SPItem *refobj = use->ref->getObject(); + if (refobj) { + Inkscape::XML::Node *childrepr = refobj->getRepr(); + GType type = sp_repr_type_lookup(childrepr); + g_return_if_fail(type > G_TYPE_NONE); + if (g_type_is_a(type, SP_TYPE_ITEM)) { + use->child = (SPObject*) g_object_new(type, 0); + use->attach(use->child, use->lastChild()); + sp_object_unref(use->child, use); + (use->child)->invoke_build(use->document, childrepr, TRUE); + + } + } + } +} + +static void +sp_tag_use_update(SPObject *object, SPCtx *ctx, unsigned flags) +{ + if (((SPObjectClass *) (parent_class))->update) + ((SPObjectClass *) (parent_class))->update(object, ctx, flags); +} + +SPItem *sp_tag_use_get_original(SPTagUse *use) +{ + SPItem *ref = NULL; + if (use){ + if (use->ref){ + ref = use->ref->getObject(); + } + } + return ref; +} + +/* + 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 : diff --git a/src/sp-tag-use.h b/src/sp-tag-use.h new file mode 100644 index 000000000..6e068fc21 --- /dev/null +++ b/src/sp-tag-use.h @@ -0,0 +1,53 @@ +#ifndef __SP_TAG_USE_H__ +#define __SP_TAG_USE_H__ + +/* + * SVG <inkscape:tagref> implementation + * + * Authors: + * Theodore Janeczko + * + * Copyright (C) Theodore Janeczko 2012 <flutterguy317@gmail.com> + * + * Released under GNU GPL, read the file 'COPYING' for more information + */ + +#include <stddef.h> +#include <sigc++/sigc++.h> +#include "svg/svg-length.h" +#include "sp-object.h" + + +#define SP_TYPE_TAG_USE (sp_tag_use_get_type ()) +#define SP_TAG_USE(obj) (G_TYPE_CHECK_INSTANCE_CAST ((obj), SP_TYPE_TAG_USE, SPTagUse)) +#define SP_TAG_USE_CLASS(klass) (G_TYPE_CHECK_CLASS_CAST ((klass), SP_TYPE_TAG_USE, SPTagUseClass)) +#define SP_IS_TAG_USE(obj) (G_TYPE_CHECK_INSTANCE_TYPE ((obj), SP_TYPE_TAG_USE)) +#define SP_IS_TAG_USE_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE ((klass), SP_TYPE_TAG_USE)) + +class SPTagUse; +class SPTagUseClass; +class SPTagUseReference; + +struct SPTagUse : public SPObject { + // item built from the original's repr (the visible clone) + // relative to the SPUse itself, it is treated as a child, similar to a grouped item relative to its group + SPObject *child; + + gchar *href; + + // the reference to the original object + SPTagUseReference *ref; + sigc::connection _changed_connection; +}; + +struct SPTagUseClass { + SPObjectClass parent_class; +}; + +GType sp_tag_use_get_type (void); + +SPItem *sp_tag_use_unlink (SPTagUse *use); +SPItem *sp_tag_use_get_original (SPTagUse *use); + +SPItem *sp_tag_use_root(SPTagUse *use); +#endif diff --git a/src/sp-tag.cpp b/src/sp-tag.cpp new file mode 100644 index 000000000..eef55d628 --- /dev/null +++ b/src/sp-tag.cpp @@ -0,0 +1,240 @@ +/** \file + * SVG <inkscape:tag> implementation + * + * Authors: + * Theodore Janeczko + * + * Copyright (C) Theodore Janeczko 2012 <flutterguy317@gmail.com> + * + * Released under GNU GPL, read the file 'COPYING' for more information + */ + +#ifdef HAVE_CONFIG_H +# include "config.h" +#endif + +#include "attributes.h" +#include "sp-tag.h" +#include "xml/repr.h" +#include <cstring> + +#define DEBUG_TAG +#ifdef DEBUG_TAG +# define debug(f, a...) { g_print("%s(%d) %s:", \ + __FILE__,__LINE__,__FUNCTION__); \ + g_print(f, ## a); \ + g_print("\n"); \ + } +#else +# define debug(f, a...) /**/ +#endif + +/* Tag base class */ + +static void sp_tag_class_init(SPTagClass *klass); +static void sp_tag_init(SPTag *tag); + +static void sp_tag_build(SPObject *object, SPDocument *document, Inkscape::XML::Node *repr); +static void sp_tag_release(SPObject *object); +static void sp_tag_set(SPObject *object, unsigned int key, gchar const *value); +static void sp_tag_update(SPObject *object, SPCtx *ctx, guint flags); +static Inkscape::XML::Node *sp_tag_write(SPObject *object, Inkscape::XML::Document *doc, Inkscape::XML::Node *repr, guint flags); + +static SPObjectClass *tag_parent_class; + +GType +sp_tag_get_type() +{ + static GType tag_type = 0; + + if (!tag_type) { + GTypeInfo tag_info = { + sizeof(SPTagClass), + NULL, NULL, + (GClassInitFunc) sp_tag_class_init, + NULL, NULL, + sizeof(SPTag), + 16, + (GInstanceInitFunc) sp_tag_init, + NULL, /* value_table */ + }; + tag_type = g_type_register_static(SP_TYPE_OBJECT, "SPTag", &tag_info, (GTypeFlags)0); + } + return tag_type; +} + +static void +sp_tag_class_init(SPTagClass *klass) +{ + //GObjectClass *gobject_class = (GObjectClass *)klass; + SPObjectClass *sp_object_class = (SPObjectClass *)klass; + + tag_parent_class = (SPObjectClass*)g_type_class_peek_parent(klass); + + sp_object_class->build = sp_tag_build; + sp_object_class->release = sp_tag_release; + sp_object_class->write = sp_tag_write; + sp_object_class->set = sp_tag_set; + sp_object_class->update = sp_tag_update; +} + +static void +sp_tag_init(SPTag *tag) +{ +} + +/* + * Move this SPItem into or after another SPItem in the doc + * \param target - the SPItem to move into or after + * \param intoafter - move to after the target (false), move inside (sublayer) of the target (true) + */ +void SPTag::moveTo(SPObject *target, gboolean intoafter) { + + Inkscape::XML::Node *target_ref = ( target ? target->getRepr() : NULL ); + Inkscape::XML::Node *our_ref = getRepr(); + gboolean first = FALSE; + + if (target_ref == our_ref) { + // Move to ourself ignore + return; + } + + if (!target_ref) { + // Assume move to the "first" in the top node, find the top node + target_ref = our_ref; + while (target_ref->parent() != target_ref->root()) { + target_ref = target_ref->parent(); + } + first = TRUE; + } + + if (intoafter) { + // Move this inside of the target at the end + our_ref->parent()->removeChild(our_ref); + target_ref->addChild(our_ref, NULL); + } else if (target_ref->parent() != our_ref->parent()) { + // Change in parent, need to remove and add + our_ref->parent()->removeChild(our_ref); + target_ref->parent()->addChild(our_ref, target_ref); + } else if (!first) { + // Same parent, just move + our_ref->parent()->changeOrder(our_ref, target_ref); + } +} + +/** + * Reads the Inkscape::XML::Node, and initializes SPTag variables. For this to get called, + * our name must be associated with a repr via "sp_object_type_register". Best done through + * sp-object-repr.cpp's repr_name_entries array. + */ +static void +sp_tag_build(SPObject *object, SPDocument *document, Inkscape::XML::Node *repr) +{ + object->readAttr( "inkscape:expanded" ); + + if (((SPObjectClass *) tag_parent_class)->build) { + ((SPObjectClass *) tag_parent_class)->build(object, document, repr); + } +} + +/** + * Drops any allocated memory. + */ +static void +sp_tag_release(SPObject *object) +{ + /* deal with our children and our selves here */ + + if (((SPObjectClass *) tag_parent_class)->release) + ((SPObjectClass *) tag_parent_class)->release(object); +} + +/** + * Sets a specific value in the SPTag. + */ +static void +sp_tag_set(SPObject *object, unsigned int key, gchar const *value) +{ + SPTag *tag = SP_TAG(object); + + switch (key) + { + case SP_ATTR_INKSCAPE_EXPANDED: + if ( value && !strcmp(value, "true") ) { + tag->setExpanded(true); + } + break; + default: + if (((SPObjectClass *) tag_parent_class)->set) { + ((SPObjectClass *) tag_parent_class)->set(object, key, value); + } + break; + } +} + +void SPTag::setExpanded(bool isexpanded) { + if ( _expanded != isexpanded ){ + _expanded = isexpanded; + } +} + +/** + * Receives update notifications. + */ +static void +sp_tag_update(SPObject *object, SPCtx *ctx, guint flags) +{ + //SPTag *tag = SP_TAG(object); + + if (flags & (SP_OBJECT_MODIFIED_FLAG | SP_OBJECT_STYLE_MODIFIED_FLAG | + SP_OBJECT_VIEWPORT_MODIFIED_FLAG)) { + + /* do something to trigger redisplay, updates? */ + + } + + if (((SPObjectClass *) tag_parent_class)->update) { + ((SPObjectClass *) tag_parent_class)->update(object, ctx, flags); + } +} + +/** + * Writes its settings to an incoming repr object, if any. + */ +static Inkscape::XML::Node * +sp_tag_write(SPObject *object, Inkscape::XML::Document *doc, Inkscape::XML::Node *repr, guint flags) +{ + SPTag *tag = SP_TAG(object); + + if ((flags & SP_OBJECT_WRITE_BUILD) && !repr) { + repr = doc->createElement("inkscape:tag"); + } + + // Inkscape-only object, not copied during an "plain SVG" dump: + if (flags & SP_OBJECT_WRITE_EXT) { + + if (tag->_expanded) { + repr->setAttribute("inkscape:expanded", "true"); + } else { + repr->setAttribute("inkscape:expanded", NULL); + } + } + + if (((SPObjectClass *) tag_parent_class)->write) { + ((SPObjectClass *) tag_parent_class)->write(object, doc, repr, flags); + } + + return repr; +} + + +/* + 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:fileencoding=utf-8:textwidth=99 : diff --git a/src/sp-tag.h b/src/sp-tag.h new file mode 100644 index 000000000..c5eec785a --- /dev/null +++ b/src/sp-tag.h @@ -0,0 +1,55 @@ +#ifndef SP_TAG_H_SEEN +#define SP_TAG_H_SEEN + +/** \file + * SVG <inkscape:tag> implementation + * + * Authors: + * Theodore Janeczko + * + * Copyright (C) Theodore Janeczko 2012 <flutterguy317@gmail.com> + * + * Released under GNU GPL, read the file 'COPYING' for more information + */ + +#include "sp-object.h" + +/* Skeleton base class */ + +#define SP_TYPE_TAG (sp_tag_get_type()) +#define SP_TAG(o) (G_TYPE_CHECK_INSTANCE_CAST((o), SP_TYPE_TAG, SPTag)) +#define SP_IS_TAG(o) (G_TYPE_CHECK_INSTANCE_TYPE((o), SP_TYPE_TAG)) + +class SPTag; +class SPTagClass; + +class SPTag : public SPObject { +public: + bool _expanded; + + bool expanded() const { return _expanded; } + void setExpanded(bool isexpanded); + + void moveTo(SPObject *target, gboolean intoafter); + +}; + +struct SPTagClass { + SPObjectClass parent_class; +}; + +GType sp_tag_get_type(); + + +#endif /* !SP_SKELETON_H_SEEN */ + +/* + 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:fileencoding=utf-8:textwidth=99 : diff --git a/src/ui/dialog/swatches.cpp b/src/ui/dialog/swatches.cpp index a0c79b8ac..2956c6d17 100644 --- a/src/ui/dialog/swatches.cpp +++ b/src/ui/dialog/swatches.cpp @@ -68,7 +68,7 @@ #include "sp-radial-gradient.h" #include "color-rgba.h" #include "svg/css-ostringstream.h" -//#include "event-context.h" //no longer exists +#include "ui/tools/tool-base.h" //event-context.h #include <queue> #ifdef WIN32 #include <windows.h> diff --git a/src/ui/widget/addtoicon.cpp b/src/ui/widget/addtoicon.cpp new file mode 100644 index 000000000..3d6091f70 --- /dev/null +++ b/src/ui/widget/addtoicon.cpp @@ -0,0 +1,149 @@ +/* + * Authors: + * Theodore Janeczko + * + * Copyright (C) Theodore Janeczko 2012 <flutterguy317@gmail.com> + * + * Released under GNU GPL, read the file 'COPYING' for more information + */ + + +#include "ui/widget/addtoicon.h" + +#include <gtkmm/icontheme.h> + +#include "widgets/icon.h" +#include "widgets/toolbox.h" +#include "ui/icon-names.h" +#include "layertypeicon.h" +#include "addtoicon.h" + +namespace Inkscape { +namespace UI { +namespace Widget { + +AddToIcon::AddToIcon() : + Glib::ObjectBase(typeid(AddToIcon)), + Gtk::CellRendererPixbuf(), +// _pixAddName(INKSCAPE_ICON("layer-new")), + _property_active(*this, "active", false) +// _property_pixbuf_add(*this, "pixbuf_on", Glib::RefPtr<Gdk::Pixbuf>(0)) +{ + property_mode() = Gtk::CELL_RENDERER_MODE_ACTIVATABLE; + phys = sp_icon_get_phys_size((int)Inkscape::ICON_SIZE_BUTTON); +// Glib::RefPtr<Gtk::IconTheme> icon_theme = Gtk::IconTheme::get_default(); +// +// if (!icon_theme->has_icon(_pixAddName)) { +// Inkscape::queueIconPrerender( INKSCAPE_ICON(_pixAddName.data()), Inkscape::ICON_SIZE_DECORATION ); +// } +// if (icon_theme->has_icon(_pixAddName)) { +// _property_pixbuf_add = icon_theme->load_icon(_pixAddName, phys, (Gtk::IconLookupFlags)0); +// } +// +// _property_pixbuf_add = Gtk::Widget:: + + property_stock_id() = GTK_STOCK_ADD; +} + + +#if WITH_GTKMM_3_0 +void AddToIcon::get_preferred_height_vfunc(Gtk::Widget& widget, + int& min_h, + int& nat_h) const +{ + Gtk::CellRendererPixbuf::get_preferred_height_vfunc(widget, min_h, nat_h); + + if (min_h) { + min_h += (min_h) >> 1; + } + + if (nat_h) { + nat_h += (nat_h) >> 1; + } +} + +void AddToIcon::get_preferred_width_vfunc(Gtk::Widget& widget, + int& min_w, + int& nat_w) const +{ + Gtk::CellRendererPixbuf::get_preferred_width_vfunc(widget, min_w, nat_w); + + if (min_w) { + min_w += (min_w) >> 1; + } + + if (nat_w) { + nat_w += (nat_w) >> 1; + } +} +#else +void AddToIcon::get_size_vfunc(Gtk::Widget& widget, + const Gdk::Rectangle* cell_area, + int* x_offset, + int* y_offset, + int* width, + int* height ) const +{ + Gtk::CellRendererPixbuf::get_size_vfunc( widget, cell_area, x_offset, y_offset, width, height ); + + if ( width ) { + *width = phys;//+= (*width) >> 1; + } + if ( height ) { + *height =phys;//+= (*height) >> 1; + } +} +#endif + +#if WITH_GTKMM_3_0 +void AddToIcon::render_vfunc( const Cairo::RefPtr<Cairo::Context>& cr, + Gtk::Widget& widget, + const Gdk::Rectangle& background_area, + const Gdk::Rectangle& cell_area, + Gtk::CellRendererState flags ) +#else +void AddToIcon::render_vfunc( const Glib::RefPtr<Gdk::Drawable>& window, + Gtk::Widget& widget, + const Gdk::Rectangle& background_area, + const Gdk::Rectangle& cell_area, + const Gdk::Rectangle& expose_area, + Gtk::CellRendererState flags ) +#endif +{ + property_stock_id() = property_active().get_value() ? GTK_STOCK_ADD : GTK_STOCK_DELETE; + +#if WITH_GTKMM_3_0 + Gtk::CellRendererPixbuf::render_vfunc( cr, widget, background_area, cell_area, flags ); +#else + Gtk::CellRendererPixbuf::render_vfunc( window, widget, background_area, cell_area, expose_area, flags ); +#endif +} + +bool +AddToIcon::activate_vfunc(GdkEvent* event, + Gtk::Widget& /*widget*/, + const Glib::ustring& path, + const Gdk::Rectangle& /*background_area*/, + const Gdk::Rectangle& /*cell_area*/, + Gtk::CellRendererState /*flags*/) +{ + return false; +} + + +} // namespace Widget +} // namespace UI +} // 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:fileencoding=utf-8:textwidth=99 : + + diff --git a/src/ui/widget/addtoicon.h b/src/ui/widget/addtoicon.h new file mode 100644 index 000000000..aa8b4148e --- /dev/null +++ b/src/ui/widget/addtoicon.h @@ -0,0 +1,98 @@ +#ifndef __UI_DIALOG_ADDTOICON_H__ +#define __UI_DIALOG_ADDTOICON_H__ +/* + * Authors: + * Theodore Janeczko + * + * Copyright (C) Theodore Janeczko 2012 <flutterguy317@gmail.com> + * + * Released under GNU GPL, read the file 'COPYING' for more information + */ + +#if HAVE_CONFIG_H +#include "config.h" +#endif + +#include <glibmm/property.h> +#include <gtkmm/cellrendererpixbuf.h> +#include <gtkmm/widget.h> + +namespace Inkscape { +namespace UI { +namespace Widget { + +class AddToIcon : public Gtk::CellRendererPixbuf { +public: + AddToIcon(); + virtual ~AddToIcon() {}; + + Glib::PropertyProxy<bool> property_active() { return _property_active.get_proxy(); } + Glib::PropertyProxy< Glib::RefPtr<Gdk::Pixbuf> > property_pixbuf_on(); + Glib::PropertyProxy< Glib::RefPtr<Gdk::Pixbuf> > property_pixbuf_off(); + +protected: + +#if WITH_GTKMM_3_0 + virtual void render_vfunc( const Cairo::RefPtr<Cairo::Context>& cr, + Gtk::Widget& widget, + const Gdk::Rectangle& background_area, + const Gdk::Rectangle& cell_area, + Gtk::CellRendererState flags ); + + virtual void get_preferred_width_vfunc(Gtk::Widget& widget, + int& min_w, + int& nat_w) const; + + virtual void get_preferred_height_vfunc(Gtk::Widget& widget, + int& min_h, + int& nat_h) const; +#else + virtual void render_vfunc( const Glib::RefPtr<Gdk::Drawable>& window, + Gtk::Widget& widget, + const Gdk::Rectangle& background_area, + const Gdk::Rectangle& cell_area, + const Gdk::Rectangle& expose_area, + Gtk::CellRendererState flags ); + + virtual void get_size_vfunc( Gtk::Widget &widget, + Gdk::Rectangle const *cell_area, + int *x_offset, int *y_offset, int *width, int *height ) const; +#endif + + virtual bool activate_vfunc(GdkEvent *event, + Gtk::Widget &widget, + const Glib::ustring &path, + const Gdk::Rectangle &background_area, + const Gdk::Rectangle &cell_area, + Gtk::CellRendererState flags); + + +private: + int phys; + +// Glib::ustring _pixAddName; + + Glib::Property<bool> _property_active; +// Glib::Property< Glib::RefPtr<Gdk::Pixbuf> > _property_pixbuf_add; + +}; + + + +} // namespace Widget +} // namespace UI +} // namespace Inkscape + + +#endif /* __UI_DIALOG_IMAGETOGGLER_H__ */ + +/* + 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:fileencoding=utf-8:textwidth=99 : |
