aboutsummaryrefslogtreecommitdiffstats
path: root/libgnomecanvas/gnome-canvas-bpath.c
blob: a63500304bd2cea797c60c2eed45e17a07045999 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
/* Bpath item type for GnomeCanvas widget
 *
 * GnomeCanvas is basically a port of the Tk toolkit's most excellent canvas widget.  Tk is
 * copyrighted by the Regents of the University of California, Sun Microsystems, and other parties.
 *
 * Copyright (C) 1998,1999 The Free Software Foundation
 *
 * Authors: Federico Mena <federico@nuclecu.unam.mx>
 *          Raph Levien <raph@acm.org>
 *          Lauris Kaplinski <lauris@ximian.com>
 *          Miguel de Icaza <miguel@kernel.org>
 *          Cody Russell <bratsche@gnome.org>
 *          Rusty Conover <rconover@bangtail.net>
 */

/* These includes are set up for standalone compile. If/when this codebase
   is integrated into libgnomeui, the includes will need to change. */

#include <math.h>
#include <string.h>

#include <gtk/gtk.h>
#include "gnome-canvas.h"
#include "gnome-canvas-util.h"

#include "gnome-canvas-bpath.h"
#include "gnome-canvas-shape.h"
#include "gnome-canvas-shape-private.h"
#include "gnome-canvas-path-def.h"

enum {
    PROP_0,
    PROP_BPATH
};

static void gnome_canvas_bpath_class_init   (GnomeCanvasBpathClass *class);
static void gnome_canvas_bpath_init         (GnomeCanvasBpath      *bpath);
static void gnome_canvas_bpath_destroy      (GtkObject               *object);
static void gnome_canvas_bpath_set_property (GObject               *object,
                         guint                  param_id,
                         const GValue          *value,
                                             GParamSpec            *pspec);
static void gnome_canvas_bpath_get_property (GObject               *object,
                         guint                  param_id,
                         GValue                *value,
                                             GParamSpec            *pspec);

static void   gnome_canvas_bpath_update      (GnomeCanvasItem *item, gdouble *affine, ArtSVP *clip_path, gint flags);

static GnomeCanvasShapeClass *parent_class;

GType
gnome_canvas_bpath_get_type (void)
{
    static GType bpath_type;

    if (!bpath_type) {
        const GTypeInfo object_info = {
            sizeof (GnomeCanvasBpathClass),
            (GBaseInitFunc) NULL,
            (GBaseFinalizeFunc) NULL,
            (GClassInitFunc) gnome_canvas_bpath_class_init,
            (GClassFinalizeFunc) NULL,
            NULL,           /* class_data */
            sizeof (GnomeCanvasBpath),
            0,          /* n_preallocs */
            (GInstanceInitFunc) gnome_canvas_bpath_init,
            NULL            /* value_table */
        };

        bpath_type = g_type_register_static (GNOME_TYPE_CANVAS_SHAPE, "GnomeCanvasBpath",
                             &object_info, 0);
    }

    return bpath_type;
}

static void
gnome_canvas_bpath_class_init (GnomeCanvasBpathClass *class)
{
    GObjectClass         *gobject_class;
    GtkObjectClass       *object_class;
    GnomeCanvasItemClass *item_class;

    gobject_class = (GObjectClass *) class;
    object_class = (GtkObjectClass *) class;
    item_class = (GnomeCanvasItemClass *) class;

    parent_class = g_type_class_peek_parent (class);

    /* when this gets checked into libgnomeui, change the
           GTK_TYPE_POINTER to GTK_TYPE_GNOME_CANVAS_BPATH, and add an
           entry to gnome-boxed.defs */

    gobject_class->set_property = gnome_canvas_bpath_set_property;
    gobject_class->get_property = gnome_canvas_bpath_get_property;

    object_class->destroy = gnome_canvas_bpath_destroy;

    g_object_class_install_property (gobject_class,
                                         PROP_BPATH,
                                         g_param_spec_boxed ("bpath", NULL, NULL,
                                                             GNOME_TYPE_CANVAS_PATH_DEF,
                                                             (G_PARAM_READABLE | G_PARAM_WRITABLE)));

    item_class->update = gnome_canvas_bpath_update;
}

static void
gnome_canvas_bpath_init (GnomeCanvasBpath *bpath)
{

}

static void
gnome_canvas_bpath_destroy (GtkObject *object)
{
    if (GTK_OBJECT_CLASS (parent_class)->destroy)
        (* GTK_OBJECT_CLASS (parent_class)->destroy) (object);
}

static void
gnome_canvas_bpath_set_property (GObject      *object,
                                 guint         param_id,
                                 const GValue *value,
                                 GParamSpec   *pspec)
{
    GnomeCanvasItem         *item;
    GnomeCanvasPathDef      *gpp;

    item = GNOME_CANVAS_ITEM (object);

    switch (param_id) {
    case PROP_BPATH:
        gpp = (GnomeCanvasPathDef*) g_value_get_boxed (value);

        gnome_canvas_shape_set_path_def (GNOME_CANVAS_SHAPE (object), gpp);

        gnome_canvas_item_request_update (item);
        break;

    default:
        break;
    }
}

static void
gnome_canvas_bpath_get_property (GObject     *object,
                                 guint        param_id,
                                 GValue      *value,
                                 GParamSpec  *pspec)
{
    GnomeCanvasShape        *shape;

    shape = GNOME_CANVAS_SHAPE(object);

    switch (param_id) {
    case PROP_BPATH:
        g_value_set_boxed (value, shape->priv->path);
        break;
    default:
        G_OBJECT_WARN_INVALID_PROPERTY_ID (object, param_id, pspec);
        break;
    }
}

static void
gnome_canvas_bpath_update (GnomeCanvasItem *item, gdouble *affine, ArtSVP *clip_path, gint flags)
{
    if (GNOME_CANVAS_ITEM_CLASS(parent_class)->update) {
        (* GNOME_CANVAS_ITEM_CLASS(parent_class)->update)(item, affine, clip_path, flags);
    }
}