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