08397c30b02be011f00880bfe9ef55f1f9f5b22c
[pspp] / 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  * Written by John Darrington
6  * 
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.
11  *
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.
16  * 
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
20  */
21
22 #include "gsheet-row-iface.h"
23 #include "gsheet-uniform-row.h"
24
25
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);
29
30 static void g_sheet_row_init (GSheetRowIface *iface);
31
32
33 static GObjectClass *parent_class = NULL;
34
35 GType
36 g_sheet_uniform_row_get_type (void)
37 {
38   static GType uniform_row_type = 0;
39
40   if (!uniform_row_type)
41     {
42       static const GTypeInfo uniform_row_info =
43       {
44         sizeof (GSheetUniformRowClass),
45         NULL,           /* base_init */
46         NULL,           /* base_finalize */
47         (GClassInitFunc) g_sheet_uniform_row_class_init,
48         NULL,           /* class_finalize */
49         NULL,           /* class_data */
50         sizeof (GSheetUniformRow),
51         0,
52         (GInstanceInitFunc) g_sheet_uniform_row_init,
53       };
54
55       static const GInterfaceInfo row_info =
56       {
57         (GInterfaceInitFunc) g_sheet_row_init,
58         NULL,
59         NULL
60       };
61
62       uniform_row_type = 
63         g_type_register_static (G_TYPE_OBJECT, "g_sheet_uniform_row",
64                                 &uniform_row_info, 0);
65
66       g_type_add_interface_static (uniform_row_type,
67                                    G_TYPE_SHEET_ROW,
68                                    &row_info);
69     }
70
71   return uniform_row_type;
72 }
73
74
75 /**
76  * g_sheet_uniform_row_new:
77  * @height: The size of rows in this uniform row
78  *
79  * Return value: a new #g_sheet_uniform_row
80  **/
81 GObject *
82 g_sheet_uniform_row_new (gint height, gint n_rows)
83 {
84   GSheetUniformRow *ug;
85   GObject *retval;
86
87   retval = g_object_new (G_TYPE_SHEET_UNIFORM_ROW, NULL);
88
89   ug = G_SHEET_UNIFORM_ROW(retval);
90   ug->n_rows = n_rows;
91   ug->height = height;
92   ug->is_visible = TRUE;
93
94   return retval;
95 }
96
97 static gint 
98 g_sheet_uniform_row_get_height(const GSheetRow *geom, gint u, gpointer data)
99 {
100   GSheetUniformRow *ug = G_SHEET_UNIFORM_ROW(geom);
101   
102   return ug->height;
103 }
104
105 static gboolean
106 g_sheet_uniform_row_get_sensitivity(const GSheetRow *geom, gint u, gpointer data)
107 {
108   GSheetUniformRow *ug = G_SHEET_UNIFORM_ROW(geom);
109   
110   return (u < ug->n_rows);
111 }
112
113
114 static gboolean
115 g_sheet_uniform_row_get_visibility(const GSheetRow *geom, gint u, gpointer data)
116 {
117   GSheetUniformRow *ug = G_SHEET_UNIFORM_ROW(geom);
118   
119   return ug->is_visible;
120 }
121
122
123 static gchar *
124 g_sheet_uniform_row_get_button_label(const GSheetRow *geom, gint u, gpointer data)
125 {
126   gchar *label = g_strdup_printf("%d", u);
127
128   return label;
129 }
130
131
132
133 static gint 
134 g_sheet_uniform_row_get_row_count(const GSheetRow *geom, gpointer data)
135 {
136   GSheetUniformRow *ug = G_SHEET_UNIFORM_ROW(geom);
137
138   return ug->n_rows;
139 }
140
141
142 static void
143 g_sheet_uniform_row_class_init (GSheetUniformRowClass *class)
144 {
145   GObjectClass *object_class;
146
147   parent_class = g_type_class_peek_parent (class);
148   object_class = (GObjectClass*) class;
149
150   object_class->finalize = g_sheet_uniform_row_finalize;
151
152 }
153
154
155 static void
156 g_sheet_uniform_row_init (GSheetUniformRow *o)
157 {
158 }
159
160 static void         
161 g_sheet_uniform_row_finalize (GObject           *object)
162 {
163 }
164
165
166 static guint
167 g_sheet_uniform_row_top_ypixel(const GSheetRow *geo, gint row, gpointer data)
168 {
169   GSheetUniformRow *ug = G_SHEET_UNIFORM_ROW(geo);
170
171   return row * ug->height;
172 }
173
174 static gint
175 g_sheet_uniform_row_pixel_to_row(const GSheetRow *geo, guint pixel, 
176                                  gpointer data)
177 {
178   GSheetUniformRow *ug = G_SHEET_UNIFORM_ROW(geo);
179
180   gint row = pixel / ug->height;
181
182   if (row >= g_sheet_uniform_row_get_row_count(geo, data))
183     row = g_sheet_uniform_row_get_row_count(geo, data) -1;
184
185   return row;
186 }
187
188
189
190 static void
191 g_sheet_row_init (GSheetRowIface *iface)
192 {
193   iface->get_height = g_sheet_uniform_row_get_height;
194   iface->get_sensitivity = g_sheet_uniform_row_get_sensitivity ;
195   iface->get_visibility = g_sheet_uniform_row_get_visibility;
196   iface->get_row_count = g_sheet_uniform_row_get_row_count;
197   iface->get_button_label = g_sheet_uniform_row_get_button_label;
198   iface->top_ypixel = g_sheet_uniform_row_top_ypixel;
199   iface->pixel_to_row = g_sheet_uniform_row_pixel_to_row;
200 }
201