Merge 'master' into 'gtk3'.
[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_EDITING_CANCELED
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_EDITING_CANCELED:
63       break;
64
65     default:
66       G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
67       break;
68     }
69 }
70
71 static void
72 psppire_button_editable_get_property (GObject      *object,
73                                       guint         prop_id,
74                                       GValue       *value,
75                                       GParamSpec   *pspec)
76 {
77   PsppireButtonEditable *obj = PSPPIRE_BUTTON_EDITABLE (object);
78
79   switch (prop_id)
80     {
81     case PROP_PATH:
82       g_value_set_string (value, obj->path);
83       break;
84
85     case PROP_EDITING_CANCELED:
86       g_value_set_boolean (value, FALSE);
87       break;
88
89     default:
90       G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
91       break;
92     }
93 }
94
95 static void
96 psppire_button_editable_finalize (GObject *gobject)
97 {
98   PsppireButtonEditable *obj = PSPPIRE_BUTTON_EDITABLE (gobject);
99
100   g_free (obj->path);
101
102   G_OBJECT_CLASS (psppire_button_editable_parent_class)->finalize (gobject);
103 }
104
105 static gboolean
106 psppire_button_editable_button_release (GtkWidget      *widget,
107                                         GdkEventButton *event)
108 {
109   if (event->button == 1)
110     {
111       g_signal_emit_by_name (widget, "released", event, NULL);
112     }
113
114   return TRUE;
115 }
116
117 static void
118 psppire_button_editable_class_init (PsppireButtonEditableClass *class)
119 {
120   GObjectClass *gobject_class;
121   GtkWidgetClass *widget_class;
122
123   gobject_class = G_OBJECT_CLASS (class);
124   widget_class = GTK_WIDGET_CLASS (class);
125
126   gobject_class->set_property = psppire_button_editable_set_property;
127   gobject_class->get_property = psppire_button_editable_get_property;
128   gobject_class->finalize = psppire_button_editable_finalize;
129
130   widget_class->button_release_event = psppire_button_editable_button_release;
131
132   g_object_class_install_property (gobject_class,
133                                    PROP_PATH,
134                                    g_param_spec_string ("path",
135                                                         _("TreeView path"),
136                                                         _("The path to the row in the GtkTreeView, as a string"),
137                                                         "",
138                                                         G_PARAM_READWRITE));
139
140   g_object_class_override_property (gobject_class,
141                                    PROP_EDITING_CANCELED,
142                                     "editing-canceled");
143 }
144
145 static void
146 psppire_button_editable_init (PsppireButtonEditable *obj)
147 {
148   obj->path = g_strdup ("");
149 }
150
151 PsppireButtonEditable *
152 psppire_button_editable_new (void)
153 {
154   return PSPPIRE_BUTTON_EDITABLE (g_object_new (PSPPIRE_TYPE_BUTTON_EDITABLE, NULL));
155 }
156
157 \f
158 /* GtkCellEditable interface. */
159
160 static void
161 gtk_cell_editable_interface_init (GtkCellEditableIface *iface)
162 {
163   g_return_if_fail (iface != NULL);
164
165   iface->editing_done = button_editable_editing_done;
166   iface->remove_widget = button_editable_remove_widget;
167   iface->start_editing = button_editable_start_editing;
168 }
169
170 static void
171 button_editable_editing_done (GtkCellEditable *cell_editable)
172 {
173 }
174
175 static void
176 button_editable_remove_widget (GtkCellEditable *cell_editable)
177 {
178 }
179
180 static void
181 button_editable_start_editing (GtkCellEditable *cell_editable,
182                                GdkEvent        *event)
183 {
184 }