Fixed typo in comment
[pspp] / src / ui / gui / psppire-button-editable.c
1 /* PSPPIRE - a graphical user interface for PSPP.
2    Copyright (C) 2011, 2012, 2016 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 #define P_(STRING) STRING
25
26 /* GtkCellEditable interface. */
27 static void gtk_cell_editable_interface_init (GtkCellEditableIface *iface);
28 static void button_editable_editing_done (GtkCellEditable *cell_editable);
29 static void button_editable_remove_widget (GtkCellEditable *cell_editable);
30 static void button_editable_start_editing (GtkCellEditable *cell_editable,
31                                            GdkEvent        *event);
32
33 G_DEFINE_TYPE_EXTENDED (PsppireButtonEditable,
34                         psppire_button_editable,
35                         GTK_TYPE_BUTTON,
36                         0,
37                         G_IMPLEMENT_INTERFACE (
38                           GTK_TYPE_CELL_EDITABLE,
39                           gtk_cell_editable_interface_init));
40
41 enum
42   {
43     PROP_0,
44     PROP_PATH,
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_EDITING_CANCELED:
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_EDITING_CANCELED:
87       g_value_set_boolean (value, FALSE);
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_finalize (GObject *gobject)
98 {
99   PsppireButtonEditable *obj = PSPPIRE_BUTTON_EDITABLE (gobject);
100
101   g_free (obj->path);
102
103   G_OBJECT_CLASS (psppire_button_editable_parent_class)->finalize (gobject);
104 }
105
106 static gboolean
107 psppire_button_editable_button_release (GtkWidget      *widget,
108                                         GdkEventButton *event)
109 {
110   if (event->button == 1)
111     {
112       g_signal_emit_by_name (widget, "released", event, NULL);
113     }
114
115   return TRUE;
116 }
117
118 static void
119 psppire_button_editable_class_init (PsppireButtonEditableClass *class)
120 {
121   GObjectClass *gobject_class;
122   GtkWidgetClass *widget_class;
123
124   gobject_class = G_OBJECT_CLASS (class);
125   widget_class = GTK_WIDGET_CLASS (class);
126
127   gobject_class->set_property = psppire_button_editable_set_property;
128   gobject_class->get_property = psppire_button_editable_get_property;
129   gobject_class->finalize = psppire_button_editable_finalize;
130
131   widget_class->button_release_event = psppire_button_editable_button_release;
132
133   g_object_class_install_property (gobject_class,
134                                    PROP_PATH,
135                                    g_param_spec_string ("path",
136                                                         P_("TreeView path"),
137                                                         P_("The path to the row in the GtkTreeView, as a string"),
138                                                         "",
139                                                         G_PARAM_READWRITE));
140
141   g_object_class_override_property (gobject_class,
142                                    PROP_EDITING_CANCELED,
143                                     "editing-canceled");
144 }
145
146 static void
147 psppire_button_editable_init (PsppireButtonEditable *obj)
148 {
149   obj->path = g_strdup ("");
150 }
151
152 PsppireButtonEditable *
153 psppire_button_editable_new (void)
154 {
155   return PSPPIRE_BUTTON_EDITABLE (g_object_new (PSPPIRE_TYPE_BUTTON_EDITABLE, NULL));
156 }
157
158 \f
159 /* GtkCellEditable interface. */
160
161 static void
162 gtk_cell_editable_interface_init (GtkCellEditableIface *iface)
163 {
164   g_return_if_fail (iface != NULL);
165
166   iface->editing_done = button_editable_editing_done;
167   iface->remove_widget = button_editable_remove_widget;
168   iface->start_editing = button_editable_start_editing;
169 }
170
171 static void
172 button_editable_editing_done (GtkCellEditable *cell_editable)
173 {
174 }
175
176 static void
177 button_editable_remove_widget (GtkCellEditable *cell_editable)
178 {
179 }
180
181 static void
182 button_editable_start_editing (GtkCellEditable *cell_editable,
183                                GdkEvent        *event)
184 {
185 }