Removed my authorship lines.
[pspp-builds.git] / lib / gtksheet / gsheet-hetero-column.c
1 /* gsheet-hetero-column.c
2  * PSPPIRE --- A Graphical User Interface for PSPP
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 "gsheet-column-iface.h"
20 #include "gsheet-hetero-column.h"
21 #include <string.h>
22
23
24 static void  g_sheet_hetero_column_init       (GSheetHeteroColumn      *hg);
25 static void  g_sheet_hetero_column_class_init (GSheetHeteroColumnClass *class);
26 static void  g_sheet_hetero_column_finalize   (GObject           *object);
27
28 static void g_sheet_column_init (GSheetColumnIface *iface);
29
30
31 static GObjectClass *parent_class = NULL;
32
33 GType
34 g_sheet_hetero_column_get_type (void)
35 {
36   static GType hetero_column_type = 0;
37
38   if (!hetero_column_type)
39     {
40       static const GTypeInfo hetero_column_info =
41       {
42         sizeof (GSheetHeteroColumnClass),
43         NULL,           /* base_init */
44         NULL,           /* base_finalize */
45         (GClassInitFunc) g_sheet_hetero_column_class_init,
46         NULL,           /* class_finalize */
47         NULL,           /* class_data */
48         sizeof (GSheetHeteroColumn),
49         0,
50         (GInstanceInitFunc) g_sheet_hetero_column_init,
51       };
52
53       static const GInterfaceInfo column_info =
54       {
55         (GInterfaceInitFunc) g_sheet_column_init,
56         NULL,
57         NULL
58       };
59
60       hetero_column_type = 
61         g_type_register_static (G_TYPE_OBJECT, "g_sheet_hetero_column",
62                                 &hetero_column_info, 0);
63
64       g_type_add_interface_static (hetero_column_type,
65                                    G_TYPE_SHEET_COLUMN,
66                                    &column_info);
67     }
68
69   return hetero_column_type;
70 }
71
72
73 static GtkSheetButton default_button;
74    
75
76
77 /**
78  * g_sheet_hetero_column_new:
79  * @width: The size of columns in this hetero column
80  *
81  * Return value: a new #g_sheet_hetero_column
82  **/
83 GObject *
84 g_sheet_hetero_column_new (gint default_width, gint n_columns)
85 {
86   gint i;
87   GSheetHeteroColumn *hg;
88   GObject *retval;
89
90   retval = g_object_new (G_TYPE_SHEET_HETERO_COLUMN, NULL);
91
92   hg = G_SHEET_HETERO_COLUMN(retval);
93   hg->n_columns = n_columns;
94   hg->default_width = default_width;
95   hg->col = g_new0(struct GSheetHeteroColumnUnit, n_columns);
96
97   for (i = 0 ; i < hg->n_columns; ++i ) 
98     {
99       hg->col[i].button = default_button;
100     }
101
102   return retval;
103 }
104
105 static gint 
106 g_sheet_hetero_column_get_width(const GSheetColumn *geom, gint i)
107 {
108   GSheetHeteroColumn *hg = G_SHEET_HETERO_COLUMN(geom);
109
110   g_return_val_if_fail(i < hg->n_columns, -1);
111   
112   return hg->col[i].width;
113 }
114
115 static gint 
116 g_sheet_hetero_column_get_sensitivity(const GSheetColumn *geom, gint u)
117 {
118   return TRUE;
119 }
120
121
122 static gint 
123 g_sheet_hetero_column_get_visibility(const GSheetColumn *geom, gint u)
124 {
125   return TRUE;
126 }
127
128
129
130 static gchar *
131 g_sheet_hetero_column_get_button_label(const GSheetColumn *geom, gint u)
132 {
133   GSheetHeteroColumn *hg = G_SHEET_HETERO_COLUMN(geom);
134
135   return g_locale_to_utf8(hg->col[u].button.label, -1, 0, 0, 0);
136 }
137
138
139 static GtkJustification
140 g_sheet_hetero_column_get_justification(const GSheetColumn *geom, gint u)
141 {
142   return GTK_JUSTIFY_FILL;
143 }
144
145
146
147 static gint 
148 g_sheet_hetero_column_get_column_count(const GSheetColumn *geom)
149 {
150   GSheetHeteroColumn *hg = G_SHEET_HETERO_COLUMN(geom);
151
152   return hg->n_columns;
153 }
154
155 static void
156 g_sheet_hetero_column_class_init (GSheetHeteroColumnClass *class)
157 {
158   GObjectClass *object_class;
159
160   parent_class = g_type_class_peek_parent (class);
161   object_class = (GObjectClass*) class;
162
163   object_class->finalize = g_sheet_hetero_column_finalize;
164
165   default_button.label=NULL;
166   default_button.child=NULL;
167   default_button.state=GTK_STATE_NORMAL;
168   default_button.justification=GTK_JUSTIFY_CENTER;
169   default_button.label_visible = TRUE;
170 }
171
172
173 static void
174 g_sheet_hetero_column_init (GSheetHeteroColumn *o)
175 {
176 }
177
178 static void         
179 g_sheet_hetero_column_finalize (GObject           *object)
180 {
181   GSheetHeteroColumn *hg = G_SHEET_HETERO_COLUMN(object);
182
183   g_free(hg->col);
184 }
185
186 static void 
187 hetero_column_set_width(GSheetColumn *geo, gint i, gint size)
188 {
189   GSheetHeteroColumn *hg = G_SHEET_HETERO_COLUMN(geo);
190
191   g_return_if_fail(i < hg->n_columns);
192
193   hg->col[i].width = size;
194 }
195
196
197
198 static void
199 g_sheet_column_init (GSheetColumnIface *iface)
200 {
201   iface->get_width = g_sheet_hetero_column_get_width ;
202   iface->set_width = hetero_column_set_width ;
203   iface->get_sensitivity = g_sheet_hetero_column_get_sensitivity ;
204   iface->get_visibility = g_sheet_hetero_column_get_visibility ;
205   iface->get_justification = g_sheet_hetero_column_get_justification;
206   iface->get_column_count = g_sheet_hetero_column_get_column_count;
207
208   iface->get_button_label = g_sheet_hetero_column_get_button_label;
209 }
210
211
212 void 
213 g_sheet_hetero_column_set_button_label(GSheetHeteroColumn *geo,
214                                               gint i, const gchar *label)
215 {
216   g_return_if_fail(i < geo->n_columns);
217
218   g_free(geo->col[i].button.label);
219   geo->col[i].button.label = g_malloc(strlen(label) + 1);
220   
221   g_stpcpy(geo->col[i].button.label, label);
222 }
223
224
225
226
227 inline void 
228 g_sheet_hetero_column_set_width(GSheetHeteroColumn *geo, gint i, gint size)
229 {
230   GSheetColumn *iface = G_SHEET_COLUMN(geo);
231
232   hetero_column_set_width(iface, i, size);
233 }
234
235
236