e7e6f4edc67ccbddc5bfe32c08c7470b87c563d3
[pspp] / lib / gtksheet / gsheet-uniform-column.c
1 /* gsheet-uniform-column.c
2  * 
3  * PSPPIRE --- A Graphical User Interface for PSPP
4  * Copyright (C) 2006  Free Software Foundation
5  * Written by John Darrington
6  * 
7  * This library is free software; you can redistribute it and/or
8  * modify it under the terms of the GNU Lesser General Public
9  * License as published by the Free Software Foundation; either
10  * version 2.1 of the License, or (at your option) any later version.
11  *
12  * This library is distributed in the hope that it will be useful,
13  * but WITHOUT ANY WARRANTY; without even the implied warranty of
14  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
15  * Lesser General Public License for more details.
16  * 
17  * You should have received a copy of the GNU Lesser General Public
18  * License along with this library; if not, write to the Free Software
19  * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
20  */
21
22 #include "gsheet-column-iface.h"
23 #include "gsheet-uniform-column.h"
24
25
26 static void  g_sheet_uniform_column_init       (GSheetUniformColumn      *ug);
27 static void  g_sheet_uniform_column_class_init (GSheetUniformColumnClass *class);
28 static void  g_sheet_uniform_column_finalize   (GObject           *object);
29
30 static void g_sheet_column_init (GSheetColumnIface *iface);
31
32
33 static GObjectClass *parent_class = NULL;
34
35 GType
36 g_sheet_uniform_column_get_type (void)
37 {
38   static GType uniform_column_type = 0;
39
40   if (!uniform_column_type)
41     {
42       static const GTypeInfo uniform_column_info =
43       {
44         sizeof (GSheetUniformColumnClass),
45         NULL,           /* base_init */
46         NULL,           /* base_finalize */
47         (GClassInitFunc) g_sheet_uniform_column_class_init,
48         NULL,           /* class_finalize */
49         NULL,           /* class_data */
50         sizeof (GSheetUniformColumn),
51         0,
52         (GInstanceInitFunc) g_sheet_uniform_column_init,
53       };
54
55       static const GInterfaceInfo column_info =
56       {
57         (GInterfaceInitFunc) g_sheet_column_init,
58         NULL,
59         NULL
60       };
61
62       uniform_column_type = 
63         g_type_register_static (G_TYPE_OBJECT, "g_sheet_uniform_column",
64                                 &uniform_column_info, 0);
65
66       g_type_add_interface_static (uniform_column_type,
67                                    G_TYPE_SHEET_COLUMN,
68                                    &column_info);
69     }
70
71   return uniform_column_type;
72 }
73
74
75 /**
76  * g_sheet_uniform_column_new:
77  * @width: The size of columns in this uniform column
78  *
79  * Return value: a new #g_sheet_uniform_column
80  **/
81 GObject *
82 g_sheet_uniform_column_new (gint width, gint n_columns)
83 {
84   GSheetUniformColumn *ug;
85   GObject *retval;
86
87   retval = g_object_new (G_TYPE_SHEET_UNIFORM_COLUMN, NULL);
88
89   ug = G_SHEET_UNIFORM_COLUMN(retval);
90   ug->n_columns = n_columns;
91   ug->width = width;
92   ug->is_visible = TRUE;
93   ug->is_sensitive = FALSE;
94
95   return retval;
96 }
97
98 static gint 
99 g_sheet_uniform_column_get_width(const GSheetColumn *geom, gint u)
100 {
101   GSheetUniformColumn *ug = G_SHEET_UNIFORM_COLUMN(geom);
102   
103   return ug->width;
104 }
105
106 static gint 
107 g_sheet_uniform_column_get_sensitivity(const GSheetColumn *geom, gint u)
108 {
109   GSheetUniformColumn *ug = G_SHEET_UNIFORM_COLUMN(geom);
110   
111   return ug->is_sensitive;
112 }
113
114
115 static gint 
116 g_sheet_uniform_column_get_visibility(const GSheetColumn *geom, gint u)
117 {
118   GSheetUniformColumn *ug = G_SHEET_UNIFORM_COLUMN(geom);
119   
120   return ug->is_visible;
121 }
122
123
124 static gchar *
125 g_sheet_uniform_column_get_button_label(const GSheetColumn *geom, gint u)
126 {
127   gchar *label = g_strdup_printf("%d", u);
128
129   return label;
130 }
131
132
133 static GtkJustification
134 g_sheet_uniform_column_get_justification(const GSheetColumn *geom, gint u)
135 {
136   return GTK_JUSTIFY_FILL;
137 }
138
139
140
141 static gint 
142 g_sheet_uniform_column_get_column_count(const GSheetColumn *geom)
143 {
144   GSheetUniformColumn *ug = G_SHEET_UNIFORM_COLUMN(geom);
145
146   return ug->n_columns;
147 }
148
149 static void
150 g_sheet_uniform_column_class_init (GSheetUniformColumnClass *class)
151 {
152   GObjectClass *object_class;
153
154   parent_class = g_type_class_peek_parent (class);
155   object_class = (GObjectClass*) class;
156
157   object_class->finalize = g_sheet_uniform_column_finalize;
158
159 }
160
161
162 static void
163 g_sheet_uniform_column_init (GSheetUniformColumn *o)
164 {
165 }
166
167 static void         
168 g_sheet_uniform_column_finalize (GObject           *object)
169 {
170 }
171
172
173 static void
174 g_sheet_column_init (GSheetColumnIface *iface)
175 {
176   iface->get_width = g_sheet_uniform_column_get_width ;
177   iface->get_sensitivity = g_sheet_uniform_column_get_sensitivity ;
178   iface->get_visibility = g_sheet_uniform_column_get_visibility ;
179   iface->get_justification = g_sheet_uniform_column_get_justification;
180   iface->get_column_count = g_sheet_uniform_column_get_column_count;
181   iface->get_button_label = g_sheet_uniform_column_get_button_label;
182 }
183