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
24 #include <glib/gprintf.h>
25 #include <gobject/gvaluecollector.h>
26 #include "gsheet-column-iface.h"
27 #include "gtkextra-marshal.h"
35 static guint sheet_column_signals[LAST_SIGNAL];
39 static void g_sheet_column_base_init (gpointer g_class);
43 g_sheet_column_get_type (void)
45 static GType sheet_column_type = 0;
47 if (! sheet_column_type)
49 static const GTypeInfo sheet_column_info =
52 sizeof (GSheetColumnIface), /* class_size */
53 g_sheet_column_base_init, /* base_init */
54 NULL, /* base_finalize */
56 NULL, /* class_finalize */
57 NULL, /* class_data */
64 g_type_register_static (G_TYPE_INTERFACE, "GSheetColumn",
65 &sheet_column_info, 0);
67 g_assert(sheet_column_type);
69 g_type_interface_add_prerequisite (sheet_column_type, G_TYPE_OBJECT);
72 return sheet_column_type;
76 static GtkSheetButton default_button;
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,
98 default_button.state = GTK_STATE_NORMAL;
99 default_button.label = NULL;
100 default_button.label_visible = TRUE;
101 default_button.child = NULL;
102 default_button.justification = GTK_JUSTIFY_FILL;
110 g_sheet_column_set_width (GSheetColumn *column,
111 gint col, gint size, const GtkSheet *sheet)
113 g_return_if_fail (G_IS_SHEET_COLUMN (column));
115 if ((G_SHEET_COLUMN_GET_IFACE (column)->set_width) )
116 (G_SHEET_COLUMN_GET_IFACE (column)->set_width) (column, col,
122 g_sheet_column_get_width (const GSheetColumn *column,
123 gint col, const GtkSheet *sheet)
125 g_return_val_if_fail (G_IS_SHEET_COLUMN (column), -1);
127 g_assert (G_SHEET_COLUMN_GET_IFACE (column)->get_width);
129 return (G_SHEET_COLUMN_GET_IFACE (column)->get_width) (column, col,
136 g_sheet_column_get_visibility(const GSheetColumn *column,
137 gint col, const GtkSheet *sheet)
139 g_return_val_if_fail (G_IS_SHEET_COLUMN (column), FALSE);
141 g_assert (G_SHEET_COLUMN_GET_IFACE (column)->get_visibility);
143 return (G_SHEET_COLUMN_GET_IFACE (column)->get_visibility) (column,
149 g_sheet_column_get_sensitivity(const GSheetColumn *column,
150 gint col, const GtkSheet *sheet)
152 g_return_val_if_fail (G_IS_SHEET_COLUMN (column), FALSE);
154 g_assert (G_SHEET_COLUMN_GET_IFACE (column)->get_sensitivity);
156 return (G_SHEET_COLUMN_GET_IFACE (column)->get_sensitivity) (column,
162 inline const GtkSheetButton *
163 g_sheet_column_get_button(const GSheetColumn *column,
164 gint col, const GtkSheet *sheet)
166 static GtkSheetButton button ;
167 GSheetColumnIface *iface = G_SHEET_COLUMN_GET_IFACE (column);
169 g_return_val_if_fail (G_IS_SHEET_COLUMN (column), FALSE);
171 memcpy(&button, &default_button, sizeof (button));
173 if ( iface->get_button_label)
174 button.label = iface->get_button_label(column, col, sheet);
179 inline GtkJustification
180 g_sheet_column_get_justification(const GSheetColumn *column,
181 gint col, const GtkSheet *sheet)
183 g_return_val_if_fail (G_IS_SHEET_COLUMN (column), FALSE);
185 g_assert (G_SHEET_COLUMN_GET_IFACE (column)->get_justification);
187 return (G_SHEET_COLUMN_GET_IFACE (column)->get_justification) (column, col, sheet);
194 g_sheet_column_get_left_text_column (const GSheetColumn *column,
195 gint col, const GtkSheet *sheet)
197 g_return_val_if_fail (G_IS_SHEET_COLUMN (column), -1);
199 if ( ! G_SHEET_COLUMN_GET_IFACE (column)->get_left_text_column)
202 return (G_SHEET_COLUMN_GET_IFACE (column)->get_left_text_column) (column, col, sheet);
207 g_sheet_column_get_right_text_column (const GSheetColumn *column,
208 gint col, const GtkSheet *sheet)
210 g_return_val_if_fail (G_IS_SHEET_COLUMN (column), -1);
212 if ( ! G_SHEET_COLUMN_GET_IFACE (column)->get_right_text_column)
215 return (G_SHEET_COLUMN_GET_IFACE (column)->get_right_text_column) (column, col, sheet);
220 g_sheet_column_set_left_text_column (const GSheetColumn *column,
221 gint col, gint i, const GtkSheet *sheet)
223 g_return_if_fail (G_IS_SHEET_COLUMN (column));
225 if ( G_SHEET_COLUMN_GET_IFACE (column)->set_left_text_column)
226 (G_SHEET_COLUMN_GET_IFACE (column)->set_left_text_column) (column, col, i, sheet);
232 g_sheet_column_set_right_text_column (const GSheetColumn *column,
233 gint col, gint i, const GtkSheet *sheet)
235 g_return_if_fail (G_IS_SHEET_COLUMN (column));
237 if ( G_SHEET_COLUMN_GET_IFACE (column)->set_right_text_column)
238 (G_SHEET_COLUMN_GET_IFACE (column)->set_right_text_column) (column, col, i, sheet);
242 g_sheet_column_get_column_count(const GSheetColumn *geo, const GtkSheet *sheet)
244 g_return_val_if_fail (G_IS_SHEET_COLUMN (geo), -1);
246 g_assert ( G_SHEET_COLUMN_GET_IFACE (geo)->get_column_count);
248 return (G_SHEET_COLUMN_GET_IFACE (geo)->get_column_count) (geo, sheet);
252 g_sheet_column_start_pixel(const GSheetColumn *geo, gint col, const GtkSheet *sheet)
255 gint start_pixel = 0;
257 g_return_val_if_fail (G_IS_SHEET_COLUMN (geo), -1);
258 g_return_val_if_fail (col <
259 g_sheet_column_get_column_count(geo, sheet),-1);
261 for ( i = 0 ; i < col ; ++i )
263 if ( g_sheet_column_get_visibility(geo, i, sheet))
264 start_pixel += g_sheet_column_get_width(geo, i, sheet);
274 g_sheet_column_columns_deleted(GSheetColumn *geo,
275 gint first, gint n_columns)
277 g_return_if_fail (G_IS_SHEET_COLUMN (geo));
279 g_signal_emit (geo, sheet_column_signals[COLUMNS_CHANGED], 0,