Set the minimum-extent property from the size_allocate handler of the sheet
[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
94   return retval;
95 }
96
97 static gint
98 g_sheet_uniform_row_get_height (const GSheetRow *geom, glong u)
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, glong u)
107 {
108   GSheetUniformRow *ug = G_SHEET_UNIFORM_ROW(geom);
109
110   return (u < ug->n_rows);
111 }
112
113
114 static gchar *
115 g_sheet_uniform_row_get_button_label (const GSheetRow *geom, glong u)
116 {
117   gchar *label = g_strdup_printf("%ld", u);
118
119   return label;
120 }
121
122
123
124 static glong
125 g_sheet_uniform_row_get_row_count (const GSheetRow *geom)
126 {
127   GSheetUniformRow *ug = G_SHEET_UNIFORM_ROW(geom);
128
129   return ug->n_rows;
130 }
131
132
133 static void
134 g_sheet_uniform_row_class_init (GSheetUniformRowClass *class)
135 {
136   GObjectClass *object_class;
137
138   parent_class = g_type_class_peek_parent (class);
139   object_class = (GObjectClass*) class;
140
141   object_class->finalize = g_sheet_uniform_row_finalize;
142
143 }
144
145
146 static void
147 g_sheet_uniform_row_init (GSheetUniformRow *o)
148 {
149 }
150
151 static void
152 g_sheet_uniform_row_finalize (GObject *object)
153 {
154 }
155
156
157 static guint
158 g_sheet_uniform_row_top_ypixel (const GSheetRow *geo, glong row)
159 {
160   GSheetUniformRow *ug = G_SHEET_UNIFORM_ROW(geo);
161
162   return row * ug->height;
163 }
164
165 static glong
166 g_sheet_uniform_row_pixel_to_row (const GSheetRow *geo, guint pixel)
167 {
168   GSheetUniformRow *ug = G_SHEET_UNIFORM_ROW(geo);
169
170   gint row = pixel / ug->height;
171
172   if (row >= g_sheet_uniform_row_get_row_count(geo))
173     row = g_sheet_uniform_row_get_row_count(geo) - 1;
174
175   return row;
176 }
177
178
179
180 static void
181 g_sheet_row_init (GSheetRowIface *iface)
182 {
183   iface->get_height = g_sheet_uniform_row_get_height;
184   iface->get_sensitivity = g_sheet_uniform_row_get_sensitivity ;
185   iface->get_row_count = g_sheet_uniform_row_get_row_count;
186   iface->get_button_label = g_sheet_uniform_row_get_button_label;
187   iface->top_ypixel = g_sheet_uniform_row_top_ypixel;
188   iface->pixel_to_row = g_sheet_uniform_row_pixel_to_row;
189 }
190