755ce2585288404914ec88b302bf123dcca6aa74
[pspp-builds.git] / lib / gtksheet / gsheet-uniform-row.c
1 /* gsheet-uniform-row.c
2  *
3  *  PSPPIRE --- A Graphical User Interface for PSPP
4  * Copyright (C) 2006  Free Software Foundation
5  *
6  * This library is free software; you can redistribute it and/or
7  * modify it under the terms of the GNU Lesser General Public
8  * License as published by the Free Software Foundation; either
9  * version 2.1 of the License, or (at your option) any later version.
10  *
11  * This library is distributed in the hope that it will be useful,
12  * but WITHOUT ANY WARRANTY; without even the implied warranty of
13  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
14  * Lesser General Public License for more details.
15  *
16  * You should have received a copy of the GNU Lesser General Public
17  * License along with this library; if not, write to the Free Software
18  * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
19  */
20
21 #include <config.h>
22
23 #include "gsheet-row-iface.h"
24 #include "gsheet-uniform-row.h"
25
26
27 static void  g_sheet_uniform_row_init       (GSheetUniformRow      *ug);
28 static void  g_sheet_uniform_row_class_init (GSheetUniformRowClass *class);
29 static void  g_sheet_uniform_row_finalize   (GObject           *object);
30
31 static void g_sheet_row_init (GSheetRowIface *iface);
32
33
34 static GObjectClass *parent_class = NULL;
35
36 GType
37 g_sheet_uniform_row_get_type (void)
38 {
39   static GType uniform_row_type = 0;
40
41   if (!uniform_row_type)
42     {
43       static const GTypeInfo uniform_row_info =
44       {
45         sizeof (GSheetUniformRowClass),
46         NULL,           /* base_init */
47         NULL,           /* base_finalize */
48         (GClassInitFunc) g_sheet_uniform_row_class_init,
49         NULL,           /* class_finalize */
50         NULL,           /* class_data */
51         sizeof (GSheetUniformRow),
52         0,
53         (GInstanceInitFunc) g_sheet_uniform_row_init,
54       };
55
56       static const GInterfaceInfo row_info =
57       {
58         (GInterfaceInitFunc) g_sheet_row_init,
59         NULL,
60         NULL
61       };
62
63       uniform_row_type =
64         g_type_register_static (G_TYPE_OBJECT, "g_sheet_uniform_row",
65                                 &uniform_row_info, 0);
66
67       g_type_add_interface_static (uniform_row_type,
68                                    G_TYPE_SHEET_ROW,
69                                    &row_info);
70     }
71
72   return uniform_row_type;
73 }
74
75
76 /**
77  * g_sheet_uniform_row_new:
78  * @height: The size of rows in this uniform row
79  *
80  * Return value: a new #g_sheet_uniform_row
81  **/
82 GObject *
83 g_sheet_uniform_row_new (gint height, gint n_rows)
84 {
85   GSheetUniformRow *ug;
86   GObject *retval;
87
88   retval = g_object_new (G_TYPE_SHEET_UNIFORM_ROW, NULL);
89
90   ug = G_SHEET_UNIFORM_ROW(retval);
91   ug->n_rows = n_rows;
92   ug->height = height;
93   ug->is_visible = TRUE;
94
95   return retval;
96 }
97
98 static gint
99 g_sheet_uniform_row_get_height (const GSheetRow *geom, glong u, gpointer data)
100 {
101   GSheetUniformRow *ug = G_SHEET_UNIFORM_ROW(geom);
102
103   return ug->height;
104 }
105
106 static gboolean
107 g_sheet_uniform_row_get_sensitivity (const GSheetRow *geom, glong u,
108                                      gpointer data)
109 {
110   GSheetUniformRow *ug = G_SHEET_UNIFORM_ROW(geom);
111
112   return (u < ug->n_rows);
113 }
114
115
116 static gboolean
117 g_sheet_uniform_row_get_visibility (const GSheetRow *geom, glong u,
118                                     gpointer data)
119 {
120   GSheetUniformRow *ug = G_SHEET_UNIFORM_ROW (geom);
121
122   return ug->is_visible;
123 }
124
125
126 static gchar *
127 g_sheet_uniform_row_get_button_label(const GSheetRow *geom, glong u, gpointer data)
128 {
129   gchar *label = g_strdup_printf("%ld", u);
130
131   return label;
132 }
133
134
135
136 static glong
137 g_sheet_uniform_row_get_row_count (const GSheetRow *geom, gpointer data)
138 {
139   GSheetUniformRow *ug = G_SHEET_UNIFORM_ROW(geom);
140
141   return ug->n_rows;
142 }
143
144
145 static void
146 g_sheet_uniform_row_class_init (GSheetUniformRowClass *class)
147 {
148   GObjectClass *object_class;
149
150   parent_class = g_type_class_peek_parent (class);
151   object_class = (GObjectClass*) class;
152
153   object_class->finalize = g_sheet_uniform_row_finalize;
154
155 }
156
157
158 static void
159 g_sheet_uniform_row_init (GSheetUniformRow *o)
160 {
161 }
162
163 static void
164 g_sheet_uniform_row_finalize (GObject *object)
165 {
166 }
167
168
169 static guint
170 g_sheet_uniform_row_top_ypixel (const GSheetRow *geo, glong row, gpointer data)
171 {
172   GSheetUniformRow *ug = G_SHEET_UNIFORM_ROW(geo);
173
174   return row * ug->height;
175 }
176
177 static glong
178 g_sheet_uniform_row_pixel_to_row (const GSheetRow *geo, guint pixel,
179                                  gpointer data)
180 {
181   GSheetUniformRow *ug = G_SHEET_UNIFORM_ROW(geo);
182
183   gint row = pixel / ug->height;
184
185   if (row >= g_sheet_uniform_row_get_row_count(geo, data))
186     row = g_sheet_uniform_row_get_row_count(geo, data) -1;
187
188   return row;
189 }
190
191
192
193 static void
194 g_sheet_row_init (GSheetRowIface *iface)
195 {
196   iface->get_height = g_sheet_uniform_row_get_height;
197   iface->get_sensitivity = g_sheet_uniform_row_get_sensitivity ;
198   iface->get_visibility = g_sheet_uniform_row_get_visibility;
199   iface->get_row_count = g_sheet_uniform_row_get_row_count;
200   iface->get_button_label = g_sheet_uniform_row_get_button_label;
201   iface->top_ypixel = g_sheet_uniform_row_top_ypixel;
202   iface->pixel_to_row = g_sheet_uniform_row_pixel_to_row;
203 }
204