1 /* PSPPIRE - a graphical user interface for PSPP.
2 Copyright (C) 2008 Free Software Foundation
4 This program is free software: you can redistribute it and/or modify
5 it under the terms of the GNU General Public License as published by
6 the Free Software Foundation, either version 3 of the License, or
7 (at your option) any later version.
9 This program is distributed in the hope that it will be useful,
10 but WITHOUT ANY WARRANTY; without even the implied warranty of
11 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 GNU General Public License for more details.
14 You should have received a copy of the GNU General Public License
15 along with this program. If not, see <http://www.gnu.org/licenses/>. */
21 #include <libpspp/tower.h>
22 #include <libpspp/pool.h>
23 #include "psppire-axis-uniform.h"
27 /* --- prototypes --- */
28 static void psppire_axis_uniform_class_init (PsppireAxisUniformClass *class);
29 static void psppire_axis_uniform_init (PsppireAxisUniform *axis);
30 static void psppire_axis_uniform_finalize (GObject *object);
33 /* --- variables --- */
34 static GObjectClass *parent_class = NULL;
40 get_unit_at_pixel (const PsppireAxis *a, glong pixel)
43 PsppireAxisUniform *au = PSPPIRE_AXIS_UNIFORM (a);
45 g_object_get (au, "default-size", &unit_size, NULL);
47 return pixel / unit_size;
52 unit_count (const PsppireAxis *a)
54 PsppireAxisUniform *au = PSPPIRE_AXIS_UNIFORM (a);
61 pixel_start (const PsppireAxis *a, gint unit)
64 PsppireAxisUniform *au = PSPPIRE_AXIS_UNIFORM (a);
66 g_object_get (au, "default-size", &unit_size, NULL);
68 return unit * unit_size;
73 unit_size (const PsppireAxis *a, gint unit)
76 PsppireAxisUniform *au = PSPPIRE_AXIS_UNIFORM (a);
78 g_object_get (au, "default-size", &unit_size, NULL);
85 total_size (const PsppireAxis *a)
88 PsppireAxisUniform *au = PSPPIRE_AXIS_UNIFORM (a);
90 g_object_get (au, "default-size", &unit_size, NULL);
92 return unit_size * au->n_items;
98 psppire_uniform_iface_init (PsppireAxisIface *iface)
100 iface->unit_size = unit_size;
101 iface->unit_count = unit_count;
102 iface->pixel_start = pixel_start;
103 iface->get_unit_at_pixel = get_unit_at_pixel;
104 iface->total_size = total_size;
107 /* --- functions --- */
109 * psppire_axis_uniform_get_type:
110 * @returns: the type ID for accelerator groups.
113 psppire_axis_uniform_get_type (void)
115 static GType object_type = 0;
119 static const GTypeInfo object_info = {
120 sizeof (PsppireAxisUniformClass),
121 (GBaseInitFunc) NULL,
122 (GBaseFinalizeFunc) NULL,
123 (GClassInitFunc) psppire_axis_uniform_class_init,
124 NULL, /* class_finalize */
125 NULL, /* class_data */
126 sizeof (PsppireAxisUniform),
128 (GInstanceInitFunc) psppire_axis_uniform_init,
131 static const GInterfaceInfo interface_info =
133 (GInterfaceInitFunc) psppire_uniform_iface_init,
139 object_type = g_type_register_static (G_TYPE_PSPPIRE_AXIS,
140 "PsppireAxisUniform",
144 g_type_add_interface_static (object_type,
145 PSPPIRE_TYPE_AXIS_IFACE,
153 psppire_axis_uniform_class_init (PsppireAxisUniformClass *class)
155 GObjectClass *object_class = G_OBJECT_CLASS (class);
156 parent_class = g_type_class_peek_parent (class);
158 object_class->finalize = psppire_axis_uniform_finalize;
163 psppire_axis_uniform_init (PsppireAxisUniform *axis)
170 psppire_axis_uniform_finalize (GObject *object)
172 G_OBJECT_CLASS (parent_class)->finalize (object);
176 * psppire_axis_uniform_new:
177 * @returns: a new #PsppireAxisUniform object
179 * Creates a new #PsppireAxisUniform.
182 psppire_axis_uniform_new (void)
184 return g_object_new (G_TYPE_PSPPIRE_AXIS_UNIFORM, NULL);
193 psppire_axis_uniform_set_count (PsppireAxisUniform *axis, gint n)