1 /* gsheet-uniform-row.c
3 * PSPPIRE --- A Graphical User Interface for PSPP
4 * Copyright (C) 2006 Free Software Foundation
5 * Written by John Darrington
7 * This library is free software; you can redistribute it and/or
8 * modify it under the terms of the GNU Lesser General Public
9 * License as published by the Free Software Foundation; either
10 * version 2.1 of the License, or (at your option) any later version.
12 * This library is distributed in the hope that it will be useful,
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
15 * Lesser General Public License for more details.
17 * You should have received a copy of the GNU Lesser General Public
18 * License along with this library; if not, write to the Free Software
19 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
22 #include "gsheet-row-iface.h"
23 #include "gsheet-uniform-row.h"
26 static void g_sheet_uniform_row_init (GSheetUniformRow *ug);
27 static void g_sheet_uniform_row_class_init (GSheetUniformRowClass *class);
28 static void g_sheet_uniform_row_finalize (GObject *object);
30 static void g_sheet_row_init (GSheetRowIface *iface);
33 static GObjectClass *parent_class = NULL;
36 g_sheet_uniform_row_get_type (void)
38 static GType uniform_row_type = 0;
40 if (!uniform_row_type)
42 static const GTypeInfo uniform_row_info =
44 sizeof (GSheetUniformRowClass),
46 NULL, /* base_finalize */
47 (GClassInitFunc) g_sheet_uniform_row_class_init,
48 NULL, /* class_finalize */
49 NULL, /* class_data */
50 sizeof (GSheetUniformRow),
52 (GInstanceInitFunc) g_sheet_uniform_row_init,
55 static const GInterfaceInfo row_info =
57 (GInterfaceInitFunc) g_sheet_row_init,
63 g_type_register_static (G_TYPE_OBJECT, "g_sheet_uniform_row",
64 &uniform_row_info, 0);
66 g_type_add_interface_static (uniform_row_type,
71 return uniform_row_type;
76 * g_sheet_uniform_row_new:
77 * @height: The size of rows in this uniform row
79 * Return value: a new #g_sheet_uniform_row
82 g_sheet_uniform_row_new (gint height, gint n_rows)
87 retval = g_object_new (G_TYPE_SHEET_UNIFORM_ROW, NULL);
89 ug = G_SHEET_UNIFORM_ROW(retval);
92 ug->is_visible = TRUE;
98 g_sheet_uniform_row_get_height(const GSheetRow *geom, gint u)
100 GSheetUniformRow *ug = G_SHEET_UNIFORM_ROW(geom);
106 g_sheet_uniform_row_get_sensitivity(const GSheetRow *geom, gint u)
108 GSheetUniformRow *ug = G_SHEET_UNIFORM_ROW(geom);
110 return (u < ug->n_rows);
115 g_sheet_uniform_row_get_visibility(const GSheetRow *geom, gint u)
117 GSheetUniformRow *ug = G_SHEET_UNIFORM_ROW(geom);
119 return ug->is_visible;
124 g_sheet_uniform_row_get_button_label(const GSheetRow *geom, gint u)
128 label = g_strdup_printf("%d", u);
136 g_sheet_uniform_row_get_row_count(const GSheetRow *geom)
138 GSheetUniformRow *ug = G_SHEET_UNIFORM_ROW(geom);
145 g_sheet_uniform_row_class_init (GSheetUniformRowClass *class)
147 GObjectClass *object_class;
149 parent_class = g_type_class_peek_parent (class);
150 object_class = (GObjectClass*) class;
152 object_class->finalize = g_sheet_uniform_row_finalize;
158 g_sheet_uniform_row_init (GSheetUniformRow *o)
163 g_sheet_uniform_row_finalize (GObject *object)
169 g_sheet_uniform_row_top_ypixel(GSheetRow *geo, gint row, const GtkSheet *sheet)
171 GSheetUniformRow *ug = G_SHEET_UNIFORM_ROW(geo);
173 return row * ug->height;
177 g_sheet_uniform_row_pixel_to_row(GSheetRow *geo,
178 gint pixel, const GtkSheet *sheet)
180 GSheetUniformRow *ug = G_SHEET_UNIFORM_ROW(geo);
182 gint row = pixel / ug->height;
184 if (row >= g_sheet_uniform_row_get_row_count(geo))
185 row = g_sheet_uniform_row_get_row_count(geo) -1;
193 g_sheet_row_init (GSheetRowIface *iface)
195 iface->get_height = g_sheet_uniform_row_get_height;
196 iface->get_sensitivity = g_sheet_uniform_row_get_sensitivity ;
197 iface->get_visibility = g_sheet_uniform_row_get_visibility;
198 iface->get_row_count = g_sheet_uniform_row_get_row_count;
199 iface->get_button_label = g_sheet_uniform_row_get_button_label;
200 iface->top_ypixel = g_sheet_uniform_row_top_ypixel;
201 iface->pixel_to_row = g_sheet_uniform_row_pixel_to_row;