Fixed bug reporting the significance of paired value t-test.
[pspp-builds.git] / lib / gtksheet / gsheet-row-iface.c
1 /* GSheetRow --- an abstract model of the row geometry of a
2  * GSheet widget.
3  * Copyright (C) 2006 Free Software Foundation
4  *
5  * This library is free software; you can redistribute it and/or
6  * modify it under the terms of the GNU Lesser General Public
7  * License as published by the Free Software Foundation; either
8  * version 2.1 of the License, or (at your option) any later version.
9  *
10  * This library is distributed in the hope that it will be useful,
11  * but WITHOUT ANY WARRANTY; without even the implied warranty of
12  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
13  * Lesser General Public License for more details.
14  *
15  * You should have received a copy of the GNU Lesser General Public
16  * License along with this library; if not, write to the Free Software
17  * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
18  */
19 #include <config.h>
20
21 #include <stdlib.h>
22 #include <string.h>
23 #include <glib.h>
24 #include <glib/gprintf.h>
25 #include <gobject/gvaluecollector.h>
26 #include "gsheet-row-iface.h"
27 #include "gtkextra-marshal.h"
28
29
30 enum {
31   ROWS_CHANGED,
32   LAST_SIGNAL
33 };
34
35 static guint sheet_row_signals[LAST_SIGNAL];
36
37
38
39 static void      g_sheet_row_base_init   (gpointer g_class);
40
41
42 GType
43 g_sheet_row_get_type (void)
44 {
45   static GType sheet_row_type = 0;
46
47   if (! sheet_row_type)
48     {
49       static const GTypeInfo sheet_row_info =
50
51       {
52         sizeof (GSheetRowIface), /* class_size */
53         g_sheet_row_base_init,   /* base_init */
54         NULL,           /* base_finalize */
55         NULL,
56         NULL,           /* class_finalize */
57         NULL,           /* class_data */
58         0,
59         0,              /* n_preallocs */
60         NULL
61       };
62
63       sheet_row_type =
64         g_type_register_static (G_TYPE_INTERFACE, "GSheetRow",
65                                 &sheet_row_info, 0);
66
67       g_type_interface_add_prerequisite (sheet_row_type, G_TYPE_OBJECT);
68     }
69
70   return sheet_row_type;
71 }
72
73
74 static GtkSheetButton default_button;
75
76 static void
77 g_sheet_row_base_init (gpointer g_class)
78 {
79   static gboolean initialized = FALSE;
80
81   if (! initialized)
82     {
83
84       sheet_row_signals[ROWS_CHANGED] =
85         g_signal_new ("rows_changed",
86                       G_TYPE_SHEET_ROW,
87                       G_SIGNAL_RUN_LAST,
88                       G_STRUCT_OFFSET (GSheetRowIface, rows_changed),
89                       NULL, NULL,
90                       gtkextra_VOID__INT_INT,
91                       G_TYPE_NONE, 2,
92                       G_TYPE_INT,
93                       G_TYPE_INT);
94
95
96       default_button.state = GTK_STATE_NORMAL;
97       default_button.label = NULL;
98       default_button.label_visible = TRUE;
99       default_button.child = NULL;
100       default_button.justification = GTK_JUSTIFY_FILL;
101
102       initialized = TRUE;
103     }
104 }
105
106 void
107 g_sheet_row_set_height (GSheetRow *row_geo,
108                         glong row, gint size)
109 {
110   g_return_if_fail (G_IS_SHEET_ROW (row_geo));
111
112   if ((G_SHEET_ROW_GET_IFACE (row_geo)->set_height) )
113     (G_SHEET_ROW_GET_IFACE (row_geo)->set_height) (row_geo, row,
114                                                         size);
115 }
116
117
118 gint
119 g_sheet_row_get_height     (const GSheetRow *row_geo,
120                             glong row)
121 {
122   g_return_val_if_fail (G_IS_SHEET_ROW (row_geo), -1);
123
124   g_assert (G_SHEET_ROW_GET_IFACE (row_geo)->get_height);
125
126   return (G_SHEET_ROW_GET_IFACE (row_geo)->get_height) (row_geo, row);
127 }
128
129
130
131 gboolean
132 g_sheet_row_get_visibility(const GSheetRow *row_geo,
133                            glong row)
134 {
135   g_return_val_if_fail (G_IS_SHEET_ROW (row_geo), FALSE);
136
137   g_assert (G_SHEET_ROW_GET_IFACE (row_geo)->get_visibility);
138
139   return (G_SHEET_ROW_GET_IFACE (row_geo)->get_visibility) (row_geo,
140                                                                   row);
141
142 }
143
144 gboolean
145 g_sheet_row_get_sensitivity(const GSheetRow *row_geo,
146                             glong row)
147 {
148   g_return_val_if_fail (G_IS_SHEET_ROW (row_geo), FALSE);
149
150   g_assert (G_SHEET_ROW_GET_IFACE (row_geo)->get_sensitivity);
151
152   return (G_SHEET_ROW_GET_IFACE (row_geo)->get_sensitivity) (row_geo,
153                                                              row);
154
155 }
156
157
158 GtkSheetButton *
159 g_sheet_row_get_button(const GSheetRow *row_geo,
160                        glong row)
161 {
162   GtkSheetButton *button  = gtk_sheet_button_new();
163
164   GSheetRowIface *iface = G_SHEET_ROW_GET_IFACE (row_geo);
165
166   g_return_val_if_fail (G_IS_SHEET_ROW (row_geo), FALSE);
167
168   if ( iface->get_button_label)
169     button->label = iface->get_button_label(row_geo, row);
170
171   return button;
172 }
173
174 gchar *
175 g_sheet_row_get_subtitle (const GSheetRow *row_geo, glong row)
176 {
177   g_return_val_if_fail (G_IS_SHEET_ROW (row_geo), NULL);
178
179   if ( ! G_SHEET_ROW_GET_IFACE (row_geo)->get_subtitle )
180     return NULL;
181
182   return (G_SHEET_ROW_GET_IFACE (row_geo)->get_subtitle) (row_geo, row);
183 }
184
185
186
187
188 glong
189 g_sheet_row_get_row_count (const GSheetRow *geo)
190 {
191   g_return_val_if_fail (G_IS_SHEET_ROW (geo), -1);
192
193   g_assert  ( G_SHEET_ROW_GET_IFACE (geo)->get_row_count);
194
195   return (G_SHEET_ROW_GET_IFACE (geo)->get_row_count) (geo);
196 }
197
198 /**
199  * g_sheet_row_start_pixel:
200  * @geo: the row model
201  * @row: the row number
202  * @sheet: pointer to the sheet
203  *
204  * Returns the top y pixel for ROW.
205  * Instances may override this method in order to achieve time and/or memory
206  * optmisation.
207  *
208  * Returns: the y coordinate of the top of the row.
209  */
210
211 gint
212 g_sheet_row_start_pixel(const GSheetRow *geo, glong row)
213 {
214   gint i;
215   gint start_pixel = 0;
216
217   g_return_val_if_fail (G_IS_SHEET_ROW (geo), -1);
218   g_return_val_if_fail (row >= 0, -1);
219   g_return_val_if_fail (row <
220                         g_sheet_row_get_row_count(geo),-1);
221
222   if ( G_SHEET_ROW_GET_IFACE(geo)->top_ypixel)
223     return (G_SHEET_ROW_GET_IFACE(geo)->top_ypixel)(geo, row);
224
225   for ( i = 0 ; i < row ; ++i )
226     {
227       if ( g_sheet_row_get_visibility(geo, i))
228         start_pixel += g_sheet_row_get_height(geo, i);
229     }
230
231   return start_pixel;
232 }
233
234
235 glong
236 g_sheet_row_pixel_to_row (const GSheetRow *geo, gint pixel)
237 {
238   gint i, cy;
239   g_return_val_if_fail (G_IS_SHEET_ROW (geo), -1);
240   g_return_val_if_fail (pixel >= 0, -1) ;
241
242   if ( G_SHEET_ROW_GET_IFACE(geo)->pixel_to_row)
243     return (G_SHEET_ROW_GET_IFACE(geo)->pixel_to_row)(geo, pixel);
244
245   cy = 0;
246   for (i = 0; i < g_sheet_row_get_row_count (geo); ++i )
247     {
248       if (pixel >= cy  &&
249           pixel <= (cy + g_sheet_row_get_height (geo, i)) &&
250           g_sheet_row_get_visibility (geo, i))
251         return i;
252
253       if(g_sheet_row_get_visibility (geo, i))
254         cy += g_sheet_row_get_height (geo, i);
255     }
256
257   /* no match */
258   return g_sheet_row_get_row_count (geo) - 1;
259 }
260
261
262
263 void
264 g_sheet_row_rows_deleted (GSheetRow *geo,
265                                  glong first, glong n_rows)
266 {
267   g_return_if_fail (G_IS_SHEET_ROW (geo));
268
269   g_signal_emit (geo, sheet_row_signals[ROWS_CHANGED], 0,
270                  first, n_rows);
271 }