1 /* GSheetColumn --- an abstract model of the column geometry of a
4 * Copyright (C) 2006 Free Software Foundation
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.
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.
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
26 #include <glib/gprintf.h>
27 #include <gobject/gvaluecollector.h>
28 #include "gsheet-column-iface.h"
29 #include "gtkextra-marshal.h"
30 #include "gtkextra-sheet.h"
37 static guint sheet_column_signals[LAST_SIGNAL];
41 static void g_sheet_column_base_init (gpointer g_class);
45 g_sheet_column_get_type (void)
47 static GType sheet_column_type = 0;
49 if (! sheet_column_type)
51 static const GTypeInfo sheet_column_info =
54 sizeof (GSheetColumnIface), /* class_size */
55 g_sheet_column_base_init, /* base_init */
56 NULL, /* base_finalize */
58 NULL, /* class_finalize */
59 NULL, /* class_data */
66 g_type_register_static (G_TYPE_INTERFACE, "GSheetColumn",
67 &sheet_column_info, 0);
69 g_assert(sheet_column_type);
71 g_type_interface_add_prerequisite (sheet_column_type, G_TYPE_OBJECT);
74 return sheet_column_type;
79 g_sheet_column_base_init (gpointer g_class)
81 static gboolean initialized = FALSE;
86 sheet_column_signals[COLUMNS_CHANGED] =
87 g_signal_new ("columns_changed",
90 G_STRUCT_OFFSET (GSheetColumnIface, columns_changed),
92 gtkextra_VOID__INT_INT,
104 g_sheet_column_set_width (GSheetColumn *column, glong col, gint size)
106 g_return_if_fail (G_IS_SHEET_COLUMN (column));
108 if ((G_SHEET_COLUMN_GET_IFACE (column)->set_width) )
109 (G_SHEET_COLUMN_GET_IFACE (column)->set_width) (column, col, size);
114 g_sheet_column_get_width (const GSheetColumn *column, glong col)
116 g_return_val_if_fail (G_IS_SHEET_COLUMN (column), -1);
118 g_assert (G_SHEET_COLUMN_GET_IFACE (column)->get_width);
120 return (G_SHEET_COLUMN_GET_IFACE (column)->get_width) (column, col);
126 g_sheet_column_get_visibility(const GSheetColumn *column,
129 g_return_val_if_fail (G_IS_SHEET_COLUMN (column), FALSE);
131 g_assert (G_SHEET_COLUMN_GET_IFACE (column)->get_visibility);
133 return (G_SHEET_COLUMN_GET_IFACE (column)->get_visibility) (column,
139 g_sheet_column_get_sensitivity(const GSheetColumn *column,
142 g_return_val_if_fail (G_IS_SHEET_COLUMN (column), FALSE);
144 g_assert (G_SHEET_COLUMN_GET_IFACE (column)->get_sensitivity);
146 return (G_SHEET_COLUMN_GET_IFACE (column)->get_sensitivity) (column,
152 inline GtkSheetButton *
153 g_sheet_column_get_button(const GSheetColumn *column,
156 GtkSheetButton *button = gtk_sheet_button_new();
158 GSheetColumnIface *iface = G_SHEET_COLUMN_GET_IFACE (column);
160 g_return_val_if_fail (G_IS_SHEET_COLUMN (column), FALSE);
162 if ( iface->get_button_label)
163 button->label = iface->get_button_label(column, col);
168 inline GtkJustification
169 g_sheet_column_get_justification(const GSheetColumn *column,
172 g_return_val_if_fail (G_IS_SHEET_COLUMN (column), FALSE);
174 g_assert (G_SHEET_COLUMN_GET_IFACE (column)->get_justification);
176 return (G_SHEET_COLUMN_GET_IFACE (column)->get_justification) (column, col);
180 g_sheet_column_get_subtitle (const GSheetColumn *column, glong col)
182 g_return_val_if_fail (G_IS_SHEET_COLUMN (column), NULL);
184 if ( ! G_SHEET_COLUMN_GET_IFACE (column)->get_subtitle)
187 return (G_SHEET_COLUMN_GET_IFACE (column)->get_subtitle) (column, col);
193 g_sheet_column_get_left_text_column (const GSheetColumn *column,
196 g_return_val_if_fail (G_IS_SHEET_COLUMN (column), -1);
198 if ( ! G_SHEET_COLUMN_GET_IFACE (column)->get_left_text_column)
201 return (G_SHEET_COLUMN_GET_IFACE (column)->get_left_text_column) (column, col);
206 g_sheet_column_get_right_text_column (const GSheetColumn *column,
209 g_return_val_if_fail (G_IS_SHEET_COLUMN (column), -1);
211 if ( ! G_SHEET_COLUMN_GET_IFACE (column)->get_right_text_column)
214 return (G_SHEET_COLUMN_GET_IFACE (column)->get_right_text_column) (column, col);
219 g_sheet_column_set_left_text_column (const GSheetColumn *column,
222 g_return_if_fail (G_IS_SHEET_COLUMN (column));
224 if ( G_SHEET_COLUMN_GET_IFACE (column)->set_left_text_column)
225 (G_SHEET_COLUMN_GET_IFACE (column)->set_left_text_column) (column, col, i);
231 g_sheet_column_set_right_text_column (const GSheetColumn *column,
234 g_return_if_fail (G_IS_SHEET_COLUMN (column));
236 if ( G_SHEET_COLUMN_GET_IFACE (column)->set_right_text_column)
237 (G_SHEET_COLUMN_GET_IFACE (column)->set_right_text_column) (column, col, i);
241 g_sheet_column_get_column_count(const GSheetColumn *geo)
243 g_return_val_if_fail (G_IS_SHEET_COLUMN (geo), -1);
245 g_assert ( G_SHEET_COLUMN_GET_IFACE (geo)->get_column_count);
247 return (G_SHEET_COLUMN_GET_IFACE (geo)->get_column_count) (geo);
251 g_sheet_column_start_pixel(const GSheetColumn *geo, glong col)
254 gint start_pixel = 0;
256 g_return_val_if_fail (G_IS_SHEET_COLUMN (geo), -1);
257 g_return_val_if_fail (col <
258 g_sheet_column_get_column_count(geo),-1);
260 for ( i = 0 ; i < col ; ++i )
262 if ( g_sheet_column_get_visibility(geo, i))
263 start_pixel += g_sheet_column_get_width(geo, i);
273 g_sheet_column_columns_changed(GSheetColumn *geo,
274 glong first, glong n_columns)
276 g_return_if_fail (G_IS_SHEET_COLUMN (geo));
278 g_signal_emit (geo, sheet_column_signals[COLUMNS_CHANGED], 0,