8763da1006736bc123944c313706610371f8f567
[pspp-builds.git] / lib / gtksheet / psppire-axis-uniform.c
1 /* PSPPIRE - a graphical user interface for PSPP.
2    Copyright (C) 2008  Free Software Foundation
3
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.
8
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.
13
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/>. */
16
17 #include <config.h>
18 #include <string.h>
19 #include <stdlib.h>
20
21 #include <libpspp/tower.h>
22 #include <libpspp/pool.h>
23 #include "psppire-axis-uniform.h"
24 #include <gtk/gtk.h>
25
26
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);
31
32
33 /* --- variables --- */
34 static GObjectClass     *parent_class = NULL;
35
36
37 #define UNIT_SIZE 25
38
39 static gint
40 get_unit_at_pixel (const PsppireAxis *a, glong pixel)
41 {
42   gint unit_size;
43   PsppireAxisUniform *au = PSPPIRE_AXIS_UNIFORM (a);
44
45   g_object_get (au, "default-size", &unit_size, NULL);
46
47   return pixel / unit_size;
48 }
49
50
51 static gint
52 unit_count (const PsppireAxis *a)
53 {
54   PsppireAxisUniform *au = PSPPIRE_AXIS_UNIFORM (a);
55
56   return au->n_items;
57 }
58
59
60 static glong
61 pixel_start (const PsppireAxis *a, gint unit)
62 {
63   gint unit_size;
64   PsppireAxisUniform *au = PSPPIRE_AXIS_UNIFORM (a);
65
66   g_object_get (au, "default-size", &unit_size, NULL);
67
68   return unit * unit_size;
69 }
70
71
72 static gint
73 unit_size (const PsppireAxis *a, gint unit)
74 {
75   gint unit_size;
76   PsppireAxisUniform *au = PSPPIRE_AXIS_UNIFORM (a);
77
78   g_object_get (au, "default-size", &unit_size, NULL);
79
80   return unit_size;
81 }
82
83
84 static glong
85 total_size (const PsppireAxis *a)
86 {
87   gint unit_size;
88   PsppireAxisUniform *au = PSPPIRE_AXIS_UNIFORM (a);
89
90   g_object_get (au, "default-size", &unit_size, NULL);
91
92   return unit_size * au->n_items;
93 }
94
95
96
97 static void
98 psppire_uniform_iface_init (PsppireAxisIface *iface)
99 {
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;
105 }
106
107 /* --- functions --- */
108 /**
109  * psppire_axis_uniform_get_type:
110  * @returns: the type ID for accelerator groups.
111  */
112 GType
113 psppire_axis_uniform_get_type (void)
114 {
115   static GType object_type = 0;
116
117   if (!object_type)
118     {
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),
127         0,      /* n_preallocs */
128         (GInstanceInitFunc) psppire_axis_uniform_init,
129       };
130
131       static const GInterfaceInfo interface_info =
132       {
133         (GInterfaceInitFunc) psppire_uniform_iface_init,
134         NULL,
135         NULL
136       };
137
138
139       object_type = g_type_register_static (G_TYPE_PSPPIRE_AXIS,
140                                             "PsppireAxisUniform",
141                                             &object_info, 0);
142
143
144       g_type_add_interface_static (object_type,
145                                    PSPPIRE_TYPE_AXIS_IFACE,
146                                    &interface_info);
147     }
148
149   return object_type;
150 }
151
152 static void
153 psppire_axis_uniform_class_init (PsppireAxisUniformClass *class)
154 {
155   GObjectClass *object_class = G_OBJECT_CLASS (class);
156   parent_class = g_type_class_peek_parent (class);
157
158   object_class->finalize = psppire_axis_uniform_finalize;
159 }
160
161
162 static void
163 psppire_axis_uniform_init (PsppireAxisUniform *axis)
164 {
165   axis->n_items = 0;
166 }
167
168
169 static void
170 psppire_axis_uniform_finalize (GObject *object)
171 {
172   G_OBJECT_CLASS (parent_class)->finalize (object);
173 }
174
175 /**
176  * psppire_axis_uniform_new:
177  * @returns: a new #PsppireAxisUniform object
178  *
179  * Creates a new #PsppireAxisUniform.
180  */
181 PsppireAxisUniform*
182 psppire_axis_uniform_new (void)
183 {
184   return g_object_new (G_TYPE_PSPPIRE_AXIS_UNIFORM, NULL);
185 }
186
187
188
189 \f
190
191
192 void
193 psppire_axis_uniform_set_count (PsppireAxisUniform *axis, gint n)
194 {
195   axis->n_items = n;
196 }