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