sp-filter-primitive.cpp revision 7333a6d3d0e1b6b738726a859e5875d5d97b27d9
5738b9afc93525510fa01185f7609fd5cbb0ff1aJohan Engelen#define __SP_FILTER_PRIMITIVE_CPP__
5738b9afc93525510fa01185f7609fd5cbb0ff1aJohan Engelen
5738b9afc93525510fa01185f7609fd5cbb0ff1aJohan Engelen/** \file
5738b9afc93525510fa01185f7609fd5cbb0ff1aJohan Engelen * Superclass for all the filter primitives
5738b9afc93525510fa01185f7609fd5cbb0ff1aJohan Engelen *
5738b9afc93525510fa01185f7609fd5cbb0ff1aJohan Engelen */
5738b9afc93525510fa01185f7609fd5cbb0ff1aJohan Engelen/*
5738b9afc93525510fa01185f7609fd5cbb0ff1aJohan Engelen * Authors:
5738b9afc93525510fa01185f7609fd5cbb0ff1aJohan Engelen * Kees Cook <kees@outflux.net>
5738b9afc93525510fa01185f7609fd5cbb0ff1aJohan Engelen *
5738b9afc93525510fa01185f7609fd5cbb0ff1aJohan Engelen * Copyright (C) 2004 Kees Cook
5738b9afc93525510fa01185f7609fd5cbb0ff1aJohan Engelen *
5738b9afc93525510fa01185f7609fd5cbb0ff1aJohan Engelen * Released under GNU GPL, read the file 'COPYING' for more information
5738b9afc93525510fa01185f7609fd5cbb0ff1aJohan Engelen */
5738b9afc93525510fa01185f7609fd5cbb0ff1aJohan Engelen
5738b9afc93525510fa01185f7609fd5cbb0ff1aJohan Engelen#ifdef HAVE_CONFIG_H
5738b9afc93525510fa01185f7609fd5cbb0ff1aJohan Engelen# include "config.h"
5738b9afc93525510fa01185f7609fd5cbb0ff1aJohan Engelen#endif
5738b9afc93525510fa01185f7609fd5cbb0ff1aJohan Engelen
5738b9afc93525510fa01185f7609fd5cbb0ff1aJohan Engelen#include "attributes.h"
5738b9afc93525510fa01185f7609fd5cbb0ff1aJohan Engelen#include "sp-filter-primitive.h"
5738b9afc93525510fa01185f7609fd5cbb0ff1aJohan Engelen#include "xml/repr.h"
5738b9afc93525510fa01185f7609fd5cbb0ff1aJohan Engelen#include "sp-filter.h"
5738b9afc93525510fa01185f7609fd5cbb0ff1aJohan Engelen
5738b9afc93525510fa01185f7609fd5cbb0ff1aJohan Engelen/* FilterPrimitive base class */
5738b9afc93525510fa01185f7609fd5cbb0ff1aJohan Engelen
5738b9afc93525510fa01185f7609fd5cbb0ff1aJohan Engelenstatic void sp_filter_primitive_class_init(SPFilterPrimitiveClass *klass);
5738b9afc93525510fa01185f7609fd5cbb0ff1aJohan Engelenstatic void sp_filter_primitive_init(SPFilterPrimitive *filter_primitive);
5738b9afc93525510fa01185f7609fd5cbb0ff1aJohan Engelen
5738b9afc93525510fa01185f7609fd5cbb0ff1aJohan Engelenstatic void sp_filter_primitive_build(SPObject *object, SPDocument *document, Inkscape::XML::Node *repr);
5738b9afc93525510fa01185f7609fd5cbb0ff1aJohan Engelenstatic void sp_filter_primitive_release(SPObject *object);
5738b9afc93525510fa01185f7609fd5cbb0ff1aJohan Engelenstatic void sp_filter_primitive_set(SPObject *object, unsigned int key, gchar const *value);
5738b9afc93525510fa01185f7609fd5cbb0ff1aJohan Engelenstatic void sp_filter_primitive_update(SPObject *object, SPCtx *ctx, guint flags);
5738b9afc93525510fa01185f7609fd5cbb0ff1aJohan Engelenstatic Inkscape::XML::Node *sp_filter_primitive_write(SPObject *object, Inkscape::XML::Node *repr, guint flags);
5738b9afc93525510fa01185f7609fd5cbb0ff1aJohan Engelen
5738b9afc93525510fa01185f7609fd5cbb0ff1aJohan Engelenstatic SPObjectClass *filter_primitive_parent_class;
5738b9afc93525510fa01185f7609fd5cbb0ff1aJohan Engelen
5738b9afc93525510fa01185f7609fd5cbb0ff1aJohan EngelenGType
5738b9afc93525510fa01185f7609fd5cbb0ff1aJohan Engelensp_filter_primitive_get_type()
5738b9afc93525510fa01185f7609fd5cbb0ff1aJohan Engelen{
5738b9afc93525510fa01185f7609fd5cbb0ff1aJohan Engelen static GType filter_primitive_type = 0;
5738b9afc93525510fa01185f7609fd5cbb0ff1aJohan Engelen
5738b9afc93525510fa01185f7609fd5cbb0ff1aJohan Engelen if (!filter_primitive_type) {
5738b9afc93525510fa01185f7609fd5cbb0ff1aJohan Engelen GTypeInfo filter_primitive_info = {
5738b9afc93525510fa01185f7609fd5cbb0ff1aJohan Engelen sizeof(SPFilterPrimitiveClass),
5738b9afc93525510fa01185f7609fd5cbb0ff1aJohan Engelen NULL, NULL,
5738b9afc93525510fa01185f7609fd5cbb0ff1aJohan Engelen (GClassInitFunc) sp_filter_primitive_class_init,
5738b9afc93525510fa01185f7609fd5cbb0ff1aJohan Engelen NULL, NULL,
5738b9afc93525510fa01185f7609fd5cbb0ff1aJohan Engelen sizeof(SPFilterPrimitive),
5738b9afc93525510fa01185f7609fd5cbb0ff1aJohan Engelen 16,
5738b9afc93525510fa01185f7609fd5cbb0ff1aJohan Engelen (GInstanceInitFunc) sp_filter_primitive_init,
5738b9afc93525510fa01185f7609fd5cbb0ff1aJohan Engelen NULL, /* value_table */
5738b9afc93525510fa01185f7609fd5cbb0ff1aJohan Engelen };
5738b9afc93525510fa01185f7609fd5cbb0ff1aJohan Engelen filter_primitive_type = g_type_register_static(SP_TYPE_OBJECT, "SPFilterPrimitive", &filter_primitive_info, (GTypeFlags)0);
5738b9afc93525510fa01185f7609fd5cbb0ff1aJohan Engelen }
5738b9afc93525510fa01185f7609fd5cbb0ff1aJohan Engelen return filter_primitive_type;
5738b9afc93525510fa01185f7609fd5cbb0ff1aJohan Engelen}
5738b9afc93525510fa01185f7609fd5cbb0ff1aJohan Engelen
5738b9afc93525510fa01185f7609fd5cbb0ff1aJohan Engelenstatic void
5738b9afc93525510fa01185f7609fd5cbb0ff1aJohan Engelensp_filter_primitive_class_init(SPFilterPrimitiveClass *klass)
5738b9afc93525510fa01185f7609fd5cbb0ff1aJohan Engelen{
5738b9afc93525510fa01185f7609fd5cbb0ff1aJohan Engelen //GObjectClass *gobject_class = (GObjectClass *)klass;
5738b9afc93525510fa01185f7609fd5cbb0ff1aJohan Engelen SPObjectClass *sp_object_class = (SPObjectClass *)klass;
5738b9afc93525510fa01185f7609fd5cbb0ff1aJohan Engelen
5738b9afc93525510fa01185f7609fd5cbb0ff1aJohan Engelen filter_primitive_parent_class = (SPObjectClass*)g_type_class_peek_parent(klass);
5738b9afc93525510fa01185f7609fd5cbb0ff1aJohan Engelen
5738b9afc93525510fa01185f7609fd5cbb0ff1aJohan Engelen sp_object_class->build = sp_filter_primitive_build;
5738b9afc93525510fa01185f7609fd5cbb0ff1aJohan Engelen sp_object_class->release = sp_filter_primitive_release;
5738b9afc93525510fa01185f7609fd5cbb0ff1aJohan Engelen sp_object_class->write = sp_filter_primitive_write;
5738b9afc93525510fa01185f7609fd5cbb0ff1aJohan Engelen sp_object_class->set = sp_filter_primitive_set;
5738b9afc93525510fa01185f7609fd5cbb0ff1aJohan Engelen sp_object_class->update = sp_filter_primitive_update;
5738b9afc93525510fa01185f7609fd5cbb0ff1aJohan Engelen}
5738b9afc93525510fa01185f7609fd5cbb0ff1aJohan Engelen
5738b9afc93525510fa01185f7609fd5cbb0ff1aJohan Engelenstatic void
5738b9afc93525510fa01185f7609fd5cbb0ff1aJohan Engelensp_filter_primitive_init(SPFilterPrimitive *filter_primitive)
5738b9afc93525510fa01185f7609fd5cbb0ff1aJohan Engelen{
5738b9afc93525510fa01185f7609fd5cbb0ff1aJohan Engelen}
5738b9afc93525510fa01185f7609fd5cbb0ff1aJohan Engelen
5738b9afc93525510fa01185f7609fd5cbb0ff1aJohan Engelen/**
5738b9afc93525510fa01185f7609fd5cbb0ff1aJohan Engelen * Reads the Inkscape::XML::Node, and initializes SPFilterPrimitive variables. For this to get called,
5738b9afc93525510fa01185f7609fd5cbb0ff1aJohan Engelen * our name must be associated with a repr via "sp_object_type_register". Best done through
5738b9afc93525510fa01185f7609fd5cbb0ff1aJohan Engelen * sp-object-repr.cpp's repr_name_entries array.
5738b9afc93525510fa01185f7609fd5cbb0ff1aJohan Engelen */
5738b9afc93525510fa01185f7609fd5cbb0ff1aJohan Engelenstatic void
5738b9afc93525510fa01185f7609fd5cbb0ff1aJohan Engelensp_filter_primitive_build(SPObject *object, SPDocument *document, Inkscape::XML::Node *repr)
5738b9afc93525510fa01185f7609fd5cbb0ff1aJohan Engelen{
5738b9afc93525510fa01185f7609fd5cbb0ff1aJohan Engelen if (((SPObjectClass *) filter_primitive_parent_class)->build) {
5738b9afc93525510fa01185f7609fd5cbb0ff1aJohan Engelen ((SPObjectClass *) filter_primitive_parent_class)->build(object, document, repr);
5738b9afc93525510fa01185f7609fd5cbb0ff1aJohan Engelen }
5738b9afc93525510fa01185f7609fd5cbb0ff1aJohan Engelen
5738b9afc93525510fa01185f7609fd5cbb0ff1aJohan Engelen if (object->parent)
5738b9afc93525510fa01185f7609fd5cbb0ff1aJohan Engelen add_primitive((SPFilter*)object->parent, (SPFilterPrimitive*)object);
5738b9afc93525510fa01185f7609fd5cbb0ff1aJohan Engelen}
5738b9afc93525510fa01185f7609fd5cbb0ff1aJohan Engelen
5738b9afc93525510fa01185f7609fd5cbb0ff1aJohan Engelen/**
5738b9afc93525510fa01185f7609fd5cbb0ff1aJohan Engelen * Drops any allocated memory.
5738b9afc93525510fa01185f7609fd5cbb0ff1aJohan Engelen */
5738b9afc93525510fa01185f7609fd5cbb0ff1aJohan Engelenstatic void
5738b9afc93525510fa01185f7609fd5cbb0ff1aJohan Engelensp_filter_primitive_release(SPObject *object)
5738b9afc93525510fa01185f7609fd5cbb0ff1aJohan Engelen{
5738b9afc93525510fa01185f7609fd5cbb0ff1aJohan Engelen /* deal with our children and our selves here */
5738b9afc93525510fa01185f7609fd5cbb0ff1aJohan Engelen if (((SPObjectClass *) filter_primitive_parent_class)->release)
5738b9afc93525510fa01185f7609fd5cbb0ff1aJohan Engelen ((SPObjectClass *) filter_primitive_parent_class)->release(object);
5738b9afc93525510fa01185f7609fd5cbb0ff1aJohan Engelen}
5738b9afc93525510fa01185f7609fd5cbb0ff1aJohan Engelen
5738b9afc93525510fa01185f7609fd5cbb0ff1aJohan Engelen/**
5738b9afc93525510fa01185f7609fd5cbb0ff1aJohan Engelen * Sets a specific value in the SPFilterPrimitive.
5738b9afc93525510fa01185f7609fd5cbb0ff1aJohan Engelen */
5738b9afc93525510fa01185f7609fd5cbb0ff1aJohan Engelenstatic void
5738b9afc93525510fa01185f7609fd5cbb0ff1aJohan Engelensp_filter_primitive_set(SPObject *object, unsigned int key, gchar const *value)
5738b9afc93525510fa01185f7609fd5cbb0ff1aJohan Engelen{
5738b9afc93525510fa01185f7609fd5cbb0ff1aJohan Engelen SPFilterPrimitive *filter_primitive = SP_FILTER_PRIMITIVE(object);
5738b9afc93525510fa01185f7609fd5cbb0ff1aJohan Engelen (void)filter_primitive;
5738b9afc93525510fa01185f7609fd5cbb0ff1aJohan Engelen
5738b9afc93525510fa01185f7609fd5cbb0ff1aJohan Engelen /* See if any parents need this value. */
5738b9afc93525510fa01185f7609fd5cbb0ff1aJohan Engelen if (((SPObjectClass *) filter_primitive_parent_class)->set) {
5738b9afc93525510fa01185f7609fd5cbb0ff1aJohan Engelen ((SPObjectClass *) filter_primitive_parent_class)->set(object, key, value);
5738b9afc93525510fa01185f7609fd5cbb0ff1aJohan Engelen }
5738b9afc93525510fa01185f7609fd5cbb0ff1aJohan Engelen}
5738b9afc93525510fa01185f7609fd5cbb0ff1aJohan Engelen
5738b9afc93525510fa01185f7609fd5cbb0ff1aJohan Engelen/**
5738b9afc93525510fa01185f7609fd5cbb0ff1aJohan Engelen * Receives update notifications.
5738b9afc93525510fa01185f7609fd5cbb0ff1aJohan Engelen */
5738b9afc93525510fa01185f7609fd5cbb0ff1aJohan Engelenstatic void
5738b9afc93525510fa01185f7609fd5cbb0ff1aJohan Engelensp_filter_primitive_update(SPObject *object, SPCtx *ctx, guint flags)
5738b9afc93525510fa01185f7609fd5cbb0ff1aJohan Engelen{
5738b9afc93525510fa01185f7609fd5cbb0ff1aJohan Engelen //SPFilterPrimitive *filter_primitive = SP_FILTER_PRIMITIVE(object);
5738b9afc93525510fa01185f7609fd5cbb0ff1aJohan Engelen
5738b9afc93525510fa01185f7609fd5cbb0ff1aJohan Engelen if (flags & (SP_OBJECT_MODIFIED_FLAG | SP_OBJECT_STYLE_MODIFIED_FLAG |
5738b9afc93525510fa01185f7609fd5cbb0ff1aJohan Engelen SP_OBJECT_VIEWPORT_MODIFIED_FLAG)) {
5738b9afc93525510fa01185f7609fd5cbb0ff1aJohan Engelen
5738b9afc93525510fa01185f7609fd5cbb0ff1aJohan Engelen /* do something to trigger redisplay, updates? */
5738b9afc93525510fa01185f7609fd5cbb0ff1aJohan Engelen }
5738b9afc93525510fa01185f7609fd5cbb0ff1aJohan Engelen
5738b9afc93525510fa01185f7609fd5cbb0ff1aJohan Engelen if (((SPObjectClass *) filter_primitive_parent_class)->update) {
5738b9afc93525510fa01185f7609fd5cbb0ff1aJohan Engelen ((SPObjectClass *) filter_primitive_parent_class)->update(object, ctx, flags);
5738b9afc93525510fa01185f7609fd5cbb0ff1aJohan Engelen }
5738b9afc93525510fa01185f7609fd5cbb0ff1aJohan Engelen}
5738b9afc93525510fa01185f7609fd5cbb0ff1aJohan Engelen
5738b9afc93525510fa01185f7609fd5cbb0ff1aJohan Engelen/**
5738b9afc93525510fa01185f7609fd5cbb0ff1aJohan Engelen * Writes its settings to an incoming repr object, if any.
5738b9afc93525510fa01185f7609fd5cbb0ff1aJohan Engelen */
5738b9afc93525510fa01185f7609fd5cbb0ff1aJohan Engelenstatic Inkscape::XML::Node *
5738b9afc93525510fa01185f7609fd5cbb0ff1aJohan Engelensp_filter_primitive_write(SPObject *object, Inkscape::XML::Node *repr, guint flags)
5738b9afc93525510fa01185f7609fd5cbb0ff1aJohan Engelen{
5738b9afc93525510fa01185f7609fd5cbb0ff1aJohan Engelen //SPFilterPrimitive *filterPrimitive = SP_FILTER_PRIMITIVE(object);
5738b9afc93525510fa01185f7609fd5cbb0ff1aJohan Engelen
5738b9afc93525510fa01185f7609fd5cbb0ff1aJohan Engelen // Inkscape-only object, not copied during an "plain SVG" dump:
5738b9afc93525510fa01185f7609fd5cbb0ff1aJohan Engelen if (flags & SP_OBJECT_WRITE_EXT) {
5738b9afc93525510fa01185f7609fd5cbb0ff1aJohan Engelen if (repr) {
5738b9afc93525510fa01185f7609fd5cbb0ff1aJohan Engelen // is this sane?
5738b9afc93525510fa01185f7609fd5cbb0ff1aJohan Engelen //repr->mergeFrom(SP_OBJECT_REPR(object), "id");
5738b9afc93525510fa01185f7609fd5cbb0ff1aJohan Engelen } else {
5738b9afc93525510fa01185f7609fd5cbb0ff1aJohan Engelen /// \todo FIXME: Plumb an appropriate XML::Document into this
5738b9afc93525510fa01185f7609fd5cbb0ff1aJohan Engelen repr = SP_OBJECT_REPR(object)->duplicate(NULL);
5738b9afc93525510fa01185f7609fd5cbb0ff1aJohan Engelen }
5738b9afc93525510fa01185f7609fd5cbb0ff1aJohan Engelen }
5738b9afc93525510fa01185f7609fd5cbb0ff1aJohan Engelen
5738b9afc93525510fa01185f7609fd5cbb0ff1aJohan Engelen if (((SPObjectClass *) filter_primitive_parent_class)->write) {
5738b9afc93525510fa01185f7609fd5cbb0ff1aJohan Engelen ((SPObjectClass *) filter_primitive_parent_class)->write(object, repr, flags);
5738b9afc93525510fa01185f7609fd5cbb0ff1aJohan Engelen }
5738b9afc93525510fa01185f7609fd5cbb0ff1aJohan Engelen
5738b9afc93525510fa01185f7609fd5cbb0ff1aJohan Engelen return repr;
5738b9afc93525510fa01185f7609fd5cbb0ff1aJohan Engelen}
5738b9afc93525510fa01185f7609fd5cbb0ff1aJohan Engelen
5738b9afc93525510fa01185f7609fd5cbb0ff1aJohan Engelen
5738b9afc93525510fa01185f7609fd5cbb0ff1aJohan Engelen/*
5738b9afc93525510fa01185f7609fd5cbb0ff1aJohan Engelen Local Variables:
5738b9afc93525510fa01185f7609fd5cbb0ff1aJohan Engelen mode:c++
5738b9afc93525510fa01185f7609fd5cbb0ff1aJohan Engelen c-file-style:"stroustrup"
5738b9afc93525510fa01185f7609fd5cbb0ff1aJohan Engelen c-file-offsets:((innamespace . 0)(inline-open . 0)(case-label . +))
5738b9afc93525510fa01185f7609fd5cbb0ff1aJohan Engelen indent-tabs-mode:nil
5738b9afc93525510fa01185f7609fd5cbb0ff1aJohan Engelen fill-column:99
5738b9afc93525510fa01185f7609fd5cbb0ff1aJohan Engelen End:
5738b9afc93525510fa01185f7609fd5cbb0ff1aJohan Engelen*/
5738b9afc93525510fa01185f7609fd5cbb0ff1aJohan Engelen// vim: filetype=cpp:expandtab:shiftwidth=4:tabstop=8:softtabstop=4:encoding=utf-8:textwidth=99 :
5738b9afc93525510fa01185f7609fd5cbb0ff1aJohan Engelen