1 /* GSheetRow --- an abstract model of the row geometry of a
3 * Copyright (C) 2006 Free Software Foundation
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.
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.
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
24 #include <glib/gprintf.h>
25 #include <gobject/gvaluecollector.h>
26 #include "gsheet-row-iface.h"
27 #include "gtkextra-marshal.h"
35 static guint sheet_row_signals[LAST_SIGNAL];
39 static void g_sheet_row_base_init (gpointer g_class);
43 g_sheet_row_get_type (void)
45 static GType sheet_row_type = 0;
49 static const GTypeInfo sheet_row_info =
52 sizeof (GSheetRowIface), /* class_size */
53 g_sheet_row_base_init, /* base_init */
54 NULL, /* base_finalize */
56 NULL, /* class_finalize */
57 NULL, /* class_data */
64 g_type_register_static (G_TYPE_INTERFACE, "GSheetRow",
67 g_type_interface_add_prerequisite (sheet_row_type, G_TYPE_OBJECT);
70 return sheet_row_type;
74 static GtkSheetButton default_button;
77 g_sheet_row_base_init (gpointer g_class)
79 static gboolean initialized = FALSE;
84 sheet_row_signals[ROWS_CHANGED] =
85 g_signal_new ("rows_changed",
88 G_STRUCT_OFFSET (GSheetRowIface, rows_changed),
90 gtkextra_VOID__INT_INT,
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;
107 g_sheet_row_set_height (GSheetRow *row_geo,
108 glong row, gint size, gpointer data)
110 g_return_if_fail (G_IS_SHEET_ROW (row_geo));
112 if ((G_SHEET_ROW_GET_IFACE (row_geo)->set_height) )
113 (G_SHEET_ROW_GET_IFACE (row_geo)->set_height) (row_geo, row,
119 g_sheet_row_get_height (const GSheetRow *row_geo,
120 glong row, gpointer data)
122 g_return_val_if_fail (G_IS_SHEET_ROW (row_geo), -1);
124 g_assert (G_SHEET_ROW_GET_IFACE (row_geo)->get_height);
126 return (G_SHEET_ROW_GET_IFACE (row_geo)->get_height) (row_geo, row,
133 g_sheet_row_get_visibility(const GSheetRow *row_geo,
134 glong row, gpointer data)
136 g_return_val_if_fail (G_IS_SHEET_ROW (row_geo), FALSE);
138 g_assert (G_SHEET_ROW_GET_IFACE (row_geo)->get_visibility);
140 return (G_SHEET_ROW_GET_IFACE (row_geo)->get_visibility) (row_geo,
146 g_sheet_row_get_sensitivity(const GSheetRow *row_geo,
147 glong row, gpointer data)
149 g_return_val_if_fail (G_IS_SHEET_ROW (row_geo), FALSE);
151 g_assert (G_SHEET_ROW_GET_IFACE (row_geo)->get_sensitivity);
153 return (G_SHEET_ROW_GET_IFACE (row_geo)->get_sensitivity) (row_geo,
160 g_sheet_row_get_button(const GSheetRow *row_geo,
161 glong row, gpointer data)
163 GtkSheetButton *button = gtk_sheet_button_new();
165 GSheetRowIface *iface = G_SHEET_ROW_GET_IFACE (row_geo);
167 g_return_val_if_fail (G_IS_SHEET_ROW (row_geo), FALSE);
169 if ( iface->get_button_label)
170 button->label = iface->get_button_label(row_geo, row, data);
176 g_sheet_row_get_subtitle (const GSheetRow *row_geo, glong row)
178 g_return_val_if_fail (G_IS_SHEET_ROW (row_geo), NULL);
180 if ( ! G_SHEET_ROW_GET_IFACE (row_geo)->get_subtitle )
183 return (G_SHEET_ROW_GET_IFACE (row_geo)->get_subtitle) (row_geo, row);
190 g_sheet_row_get_row_count (const GSheetRow *geo, gpointer data)
192 g_return_val_if_fail (G_IS_SHEET_ROW (geo), -1);
194 g_assert ( G_SHEET_ROW_GET_IFACE (geo)->get_row_count);
196 return (G_SHEET_ROW_GET_IFACE (geo)->get_row_count) (geo, data);
200 * g_sheet_row_start_pixel:
201 * @geo: the row model
202 * @row: the row number
203 * @sheet: pointer to the sheet
205 * Returns the top y pixel for ROW.
206 * Instances may override this method in order to achieve time and/or memory
209 * Returns: the y coordinate of the top of the row.
213 g_sheet_row_start_pixel(const GSheetRow *geo, glong row, gpointer data)
216 gint start_pixel = 0;
218 g_return_val_if_fail (G_IS_SHEET_ROW (geo), -1);
219 g_return_val_if_fail (row >= 0, -1);
220 g_return_val_if_fail (row <
221 g_sheet_row_get_row_count(geo, data),-1);
223 if ( G_SHEET_ROW_GET_IFACE(geo)->top_ypixel)
224 return (G_SHEET_ROW_GET_IFACE(geo)->top_ypixel)(geo, row, data);
226 for ( i = 0 ; i < row ; ++i )
228 if ( g_sheet_row_get_visibility(geo, i, data))
229 start_pixel += g_sheet_row_get_height(geo, i, data);
237 g_sheet_row_pixel_to_row (const GSheetRow *geo, gint pixel,
241 g_return_val_if_fail (G_IS_SHEET_ROW (geo), -1);
242 g_return_val_if_fail (pixel >= 0, -1) ;
244 if ( G_SHEET_ROW_GET_IFACE(geo)->pixel_to_row)
245 return (G_SHEET_ROW_GET_IFACE(geo)->pixel_to_row)(geo, pixel, data);
248 for (i = 0; i < g_sheet_row_get_row_count(geo, data); ++i )
251 pixel <= (cy + g_sheet_row_get_height(geo, i, data)) &&
252 g_sheet_row_get_visibility(geo, i, data))
255 if(g_sheet_row_get_visibility(geo, i, data))
256 cy += g_sheet_row_get_height(geo, i, data);
260 return g_sheet_row_get_row_count(geo, data) - 1;
266 g_sheet_row_rows_deleted (GSheetRow *geo,
267 glong first, glong n_rows)
269 g_return_if_fail (G_IS_SHEET_ROW (geo));
271 g_signal_emit (geo, sheet_row_signals[ROWS_CHANGED], 0,