psppire-button-editable.c: Added stub for "editing-canceled" property
[pspp] / src / ui / gui / psppire-button-editable.c
1 /* PSPPIRE - a graphical user interface for PSPP.
2    Copyright (C) 2011, 2012 Free Software Foundation, Inc.
3
4    This program is free software: you can redistribute it and/or modify
5    it under the terms of the GNU General Public License as published by
6    the Free Software Foundation, either version 3 of the License, or
7    (at your option) any later version.
8
9    This program is distributed in the hope that it will be useful,
10    but WITHOUT ANY WARRANTY; without even the implied warranty of
11    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
12    GNU General Public License for more details.
13
14    You should have received a copy of the GNU General Public License
15    along with this program.  If not, see <http://www.gnu.org/licenses/>. */
16
17 #include <config.h>
18
19 #include "ui/gui/psppire-button-editable.h"
20
21 #include <gettext.h>
22 #define _(msgid) gettext (msgid)
23 #define N_(msgid) msgid
24
25 /* GtkCellEditable interface. */
26 static void gtk_cell_editable_interface_init (GtkCellEditableIface *iface);
27 static void button_editable_editing_done (GtkCellEditable *cell_editable);
28 static void button_editable_remove_widget (GtkCellEditable *cell_editable);
29 static void button_editable_start_editing (GtkCellEditable *cell_editable,
30                                            GdkEvent        *event);
31
32 G_DEFINE_TYPE_EXTENDED (PsppireButtonEditable,
33                         psppire_button_editable,
34                         GTK_TYPE_BUTTON,
35                         0,
36                         G_IMPLEMENT_INTERFACE (
37                           GTK_TYPE_CELL_EDITABLE,
38                           gtk_cell_editable_interface_init));
39
40 enum
41   {
42     PROP_0,
43     PROP_PATH,
44     PROP_SLASH,
45     PROP_EDITING_CANCELED
46   };
47
48 static void
49 psppire_button_editable_set_property (GObject      *object,
50                                       guint         prop_id,
51                                       const GValue *value,
52                                       GParamSpec   *pspec)
53 {
54   PsppireButtonEditable *obj = PSPPIRE_BUTTON_EDITABLE (object);
55
56   switch (prop_id)
57     {
58     case PROP_PATH:
59       g_free (obj->path);
60       obj->path = g_value_dup_string (value);
61       break;
62
63     case PROP_SLASH:
64       psppire_button_editable_set_slash (obj, g_value_get_boolean (value));
65       break;
66
67     case PROP_EDITING_CANCELED:
68       break;
69
70     default:
71       G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
72       break;
73     }
74 }
75
76 static void
77 psppire_button_editable_get_property (GObject      *object,
78                                       guint         prop_id,
79                                       GValue       *value,
80                                       GParamSpec   *pspec)
81 {
82   PsppireButtonEditable *obj = PSPPIRE_BUTTON_EDITABLE (object);
83
84   switch (prop_id)
85     {
86     case PROP_PATH:
87       g_value_set_string (value, obj->path);
88       break;
89
90     case PROP_SLASH:
91       g_value_set_boolean (value, psppire_button_editable_get_slash (obj));
92       break;
93
94     case PROP_EDITING_CANCELED:
95       g_value_set_boolean (value, FALSE);
96       break;
97
98     default:
99       G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
100       break;
101     }
102 }
103
104 static void
105 psppire_button_editable_dispose (GObject *gobject)
106 {
107   PsppireButtonEditable *obj = PSPPIRE_BUTTON_EDITABLE (gobject);
108
109   g_free (obj->path);
110   obj->path = NULL;
111
112   G_OBJECT_CLASS (psppire_button_editable_parent_class)->dispose (gobject);
113 }
114
115 static gboolean
116 psppire_button_editable_button_release (GtkWidget      *widget,
117                                         GdkEventButton *event)
118 {
119   GtkButton *button;
120
121   if (event->button == 1)
122     {
123       button = GTK_BUTTON (widget);
124       gtk_button_released (button);
125     }
126
127   return TRUE;
128 }
129
130 static gboolean
131 psppire_button_editable_expose_event (GtkWidget      *widget,
132                                       GdkEventExpose *event)
133 {
134   GtkWidgetClass *widget_class;
135   GtkStyle *style = gtk_widget_get_style (widget);
136   GtkAllocation allocation;
137   gboolean retval;
138
139   widget_class = GTK_WIDGET_CLASS (psppire_button_editable_parent_class);
140   retval = widget_class->expose_event (widget, event);
141
142   gtk_widget_get_allocation (widget, &allocation);
143   if (PSPPIRE_BUTTON_EDITABLE (widget)->slash)
144     gdk_draw_line (gtk_widget_get_window (widget), style->black_gc,
145                    allocation.x,
146                    allocation.y + allocation.height,
147                    allocation.x + allocation.width,
148                    allocation.y);
149   return retval;
150 }
151
152 static void
153 psppire_button_editable_class_init (PsppireButtonEditableClass *class)
154 {
155   GObjectClass *gobject_class;
156   GtkWidgetClass *widget_class;
157
158   gobject_class = G_OBJECT_CLASS (class);
159   widget_class = GTK_WIDGET_CLASS (class);
160
161   gobject_class->set_property = psppire_button_editable_set_property;
162   gobject_class->get_property = psppire_button_editable_get_property;
163   gobject_class->dispose = psppire_button_editable_dispose;
164
165   widget_class->button_release_event = psppire_button_editable_button_release;
166   widget_class->expose_event = psppire_button_editable_expose_event;
167
168   g_object_class_install_property (gobject_class,
169                                    PROP_PATH,
170                                    g_param_spec_string ("path",
171                                                         _("TreeView path"),
172                                                         _("The path to the row in the GtkTreeView, as a string"),
173                                                         "",
174                                                         G_PARAM_READWRITE));
175
176   g_object_class_install_property (gobject_class,
177                                    PROP_SLASH,
178                                    g_param_spec_boolean ("slash",
179                                                          _("Diagonal slash"),
180                                                          _("Whether to draw a diagonal slash across the button."),
181                                                          FALSE,
182                                                          G_PARAM_READWRITE));
183
184   g_object_class_override_property (gobject_class,
185                                    PROP_EDITING_CANCELED,
186                                     "editing-canceled");
187 }
188
189 static void
190 psppire_button_editable_init (PsppireButtonEditable *obj)
191 {
192   obj->path = g_strdup ("");
193   obj->slash = FALSE;
194 }
195
196 PsppireButtonEditable *
197 psppire_button_editable_new (void)
198 {
199   return PSPPIRE_BUTTON_EDITABLE (g_object_new (PSPPIRE_TYPE_BUTTON_EDITABLE, NULL));
200 }
201
202 void
203 psppire_button_editable_set_slash (PsppireButtonEditable *button,
204                                    gboolean slash)
205 {
206   g_return_if_fail (button != NULL);
207   if ((button->slash != 0) != (slash != 0))
208     {
209       button->slash = slash;
210       gtk_widget_queue_draw (GTK_WIDGET (button));
211     }
212 }
213
214 gboolean
215 psppire_button_editable_get_slash (const PsppireButtonEditable *button)
216 {
217   g_return_val_if_fail (button != NULL, FALSE);
218   return button->slash;
219 }
220 \f
221 /* GtkCellEditable interface. */
222
223 static void
224 gtk_cell_editable_interface_init (GtkCellEditableIface *iface)
225 {
226   g_return_if_fail (iface != NULL);
227
228   iface->editing_done = button_editable_editing_done;
229   iface->remove_widget = button_editable_remove_widget;
230   iface->start_editing = button_editable_start_editing;
231 }
232
233 static void
234 button_editable_editing_done (GtkCellEditable *cell_editable)
235 {
236
237
238 }
239
240 static void
241 button_editable_remove_widget (GtkCellEditable *cell_editable)
242 {
243
244
245 }
246
247 static void
248 button_editable_start_editing (GtkCellEditable *cell_editable,
249                                GdkEvent        *event)
250 {
251 }