Avoid deprecated function: gtk_button_released
[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   };
46
47 static void
48 psppire_button_editable_set_property (GObject      *object,
49                                       guint         prop_id,
50                                       const GValue *value,
51                                       GParamSpec   *pspec)
52 {
53   PsppireButtonEditable *obj = PSPPIRE_BUTTON_EDITABLE (object);
54
55   switch (prop_id)
56     {
57     case PROP_PATH:
58       g_free (obj->path);
59       obj->path = g_value_dup_string (value);
60       break;
61
62     case PROP_SLASH:
63       psppire_button_editable_set_slash (obj, g_value_get_boolean (value));
64       break;
65
66     default:
67       G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
68       break;
69     }
70 }
71
72 static void
73 psppire_button_editable_get_property (GObject      *object,
74                                       guint         prop_id,
75                                       GValue       *value,
76                                       GParamSpec   *pspec)
77 {
78   PsppireButtonEditable *obj = PSPPIRE_BUTTON_EDITABLE (object);
79
80   switch (prop_id)
81     {
82     case PROP_PATH:
83       g_value_set_string (value, obj->path);
84       break;
85
86     case PROP_SLASH:
87       g_value_set_boolean (value, psppire_button_editable_get_slash (obj));
88       break;
89
90     default:
91       G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
92       break;
93     }
94 }
95
96 static void
97 psppire_button_editable_dispose (GObject *gobject)
98 {
99   PsppireButtonEditable *obj = PSPPIRE_BUTTON_EDITABLE (gobject);
100
101   g_free (obj->path);
102   obj->path = NULL;
103
104   G_OBJECT_CLASS (psppire_button_editable_parent_class)->dispose (gobject);
105 }
106
107 static gboolean
108 psppire_button_editable_button_release (GtkWidget      *widget,
109                                         GdkEventButton *event)
110 {
111   if (event->button == 1)
112     {
113       g_signal_emit_by_name (widget, "button-release-event", event, NULL);
114     }
115
116   return TRUE;
117 }
118
119 static gboolean
120 psppire_button_editable_expose_event (GtkWidget      *widget,
121                                       GdkEventExpose *event)
122 {
123   GtkWidgetClass *widget_class;
124   GtkStyle *style = gtk_widget_get_style (widget);
125   GtkAllocation allocation;
126   gboolean retval;
127
128   widget_class = GTK_WIDGET_CLASS (psppire_button_editable_parent_class);
129   retval = widget_class->expose_event (widget, event);
130
131   gtk_widget_get_allocation (widget, &allocation);
132   if (PSPPIRE_BUTTON_EDITABLE (widget)->slash)
133     gdk_draw_line (gtk_widget_get_window (widget), style->black_gc,
134                    allocation.x,
135                    allocation.y + allocation.height,
136                    allocation.x + allocation.width,
137                    allocation.y);
138   return retval;
139 }
140
141 static void
142 psppire_button_editable_class_init (PsppireButtonEditableClass *class)
143 {
144   GObjectClass *gobject_class;
145   GtkWidgetClass *widget_class;
146
147   gobject_class = G_OBJECT_CLASS (class);
148   widget_class = GTK_WIDGET_CLASS (class);
149
150   gobject_class->set_property = psppire_button_editable_set_property;
151   gobject_class->get_property = psppire_button_editable_get_property;
152   gobject_class->dispose = psppire_button_editable_dispose;
153
154   widget_class->button_release_event = psppire_button_editable_button_release;
155   widget_class->expose_event = psppire_button_editable_expose_event;
156
157   g_object_class_install_property (gobject_class,
158                                    PROP_PATH,
159                                    g_param_spec_string ("path",
160                                                         _("TreeView path"),
161                                                         _("The path to the row in the GtkTreeView, as a string"),
162                                                         "",
163                                                         G_PARAM_READWRITE));
164
165   g_object_class_install_property (gobject_class,
166                                    PROP_SLASH,
167                                    g_param_spec_boolean ("slash",
168                                                          _("Diagonal slash"),
169                                                          _("Whether to draw a diagonal slash across the button."),
170                                                          FALSE,
171                                                          G_PARAM_READWRITE));
172
173 }
174
175 static void
176 psppire_button_editable_init (PsppireButtonEditable *obj)
177 {
178   obj->path = g_strdup ("");
179   obj->slash = FALSE;
180 }
181
182 PsppireButtonEditable *
183 psppire_button_editable_new (void)
184 {
185   return PSPPIRE_BUTTON_EDITABLE (g_object_new (PSPPIRE_TYPE_BUTTON_EDITABLE, NULL));
186 }
187
188 void
189 psppire_button_editable_set_slash (PsppireButtonEditable *button,
190                                    gboolean slash)
191 {
192   g_return_if_fail (button != NULL);
193   if ((button->slash != 0) != (slash != 0))
194     {
195       button->slash = slash;
196       gtk_widget_queue_draw (GTK_WIDGET (button));
197     }
198 }
199
200 gboolean
201 psppire_button_editable_get_slash (const PsppireButtonEditable *button)
202 {
203   g_return_val_if_fail (button != NULL, FALSE);
204   return button->slash;
205 }
206 \f
207 /* GtkCellEditable interface. */
208
209 static void
210 gtk_cell_editable_interface_init (GtkCellEditableIface *iface)
211 {
212   g_return_if_fail (iface != NULL);
213
214   iface->editing_done = button_editable_editing_done;
215   iface->remove_widget = button_editable_remove_widget;
216   iface->start_editing = button_editable_start_editing;
217 }
218
219 static void
220 button_editable_editing_done (GtkCellEditable *cell_editable)
221 {
222 }
223
224 static void
225 button_editable_remove_widget (GtkCellEditable *cell_editable)
226 {
227 }
228
229 static void
230 button_editable_start_editing (GtkCellEditable *cell_editable,
231                                GdkEvent        *event)
232 {
233 }