Fix PostScript output of multiple charts.
[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)
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)
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)
116 {
117   GSheetUniformRow *ug = G_SHEET_UNIFORM_ROW(geom);
118   
119   return ug->is_visible;
120 }
121
122
123 static const gchar *
124 g_sheet_uniform_row_get_button_label(const GSheetRow *geom, gint u)
125 {
126   static gchar *label; 
127   g_free(label);
128   label = g_strdup_printf("%d", u);
129
130   return label;
131 }
132
133
134
135 static gint 
136 g_sheet_uniform_row_get_row_count(const GSheetRow *geom)
137 {
138   GSheetUniformRow *ug = G_SHEET_UNIFORM_ROW(geom);
139
140   return ug->n_rows;
141 }
142
143
144 static void
145 g_sheet_uniform_row_class_init (GSheetUniformRowClass *class)
146 {
147   GObjectClass *object_class;
148
149   parent_class = g_type_class_peek_parent (class);
150   object_class = (GObjectClass*) class;
151
152   object_class->finalize = g_sheet_uniform_row_finalize;
153
154 }
155
156
157 static void
158 g_sheet_uniform_row_init (GSheetUniformRow *o)
159 {
160 }
161
162 static void         
163 g_sheet_uniform_row_finalize (GObject           *object)
164 {
165 }
166
167
168 static guint
169 g_sheet_uniform_row_top_ypixel(GSheetRow *geo, gint row, const GtkSheet *sheet)
170 {
171   GSheetUniformRow *ug = G_SHEET_UNIFORM_ROW(geo);
172
173   return row * ug->height;
174 }
175
176 static guint
177 g_sheet_uniform_row_pixel_to_row(GSheetRow *geo, 
178                                  gint pixel, const GtkSheet *sheet)
179 {
180   GSheetUniformRow *ug = G_SHEET_UNIFORM_ROW(geo);
181
182   gint row = pixel / ug->height;
183
184   if (row >= g_sheet_uniform_row_get_row_count(geo))
185     row = g_sheet_uniform_row_get_row_count(geo) -1;
186
187   return row;
188 }
189
190
191
192 static void
193 g_sheet_row_init (GSheetRowIface *iface)
194 {
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;
202 }
203