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