1 /* PSPPIRE - a graphical user interface for PSPP.
2 Copyright (C) 2011, 2012 Free Software Foundation, Inc.
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.
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.
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/>. */
19 #include "ui/gui/psppire-button-editable.h"
22 #define _(msgid) gettext (msgid)
23 #define N_(msgid) msgid
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,
32 G_DEFINE_TYPE_EXTENDED (PsppireButtonEditable,
33 psppire_button_editable,
36 G_IMPLEMENT_INTERFACE (
37 GTK_TYPE_CELL_EDITABLE,
38 gtk_cell_editable_interface_init));
48 psppire_button_editable_set_property (GObject *object,
53 PsppireButtonEditable *obj = PSPPIRE_BUTTON_EDITABLE (object);
59 obj->path = g_value_dup_string (value);
63 psppire_button_editable_set_slash (obj, g_value_get_boolean (value));
67 G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
73 psppire_button_editable_get_property (GObject *object,
78 PsppireButtonEditable *obj = PSPPIRE_BUTTON_EDITABLE (object);
83 g_value_set_string (value, obj->path);
87 g_value_set_boolean (value, psppire_button_editable_get_slash (obj));
91 G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
97 psppire_button_editable_dispose (GObject *gobject)
99 PsppireButtonEditable *obj = PSPPIRE_BUTTON_EDITABLE (gobject);
104 G_OBJECT_CLASS (psppire_button_editable_parent_class)->dispose (gobject);
108 psppire_button_editable_button_release (GtkWidget *widget,
109 GdkEventButton *event)
111 if (event->button == 1)
113 g_signal_emit_by_name (widget, "button-release-event", event, NULL);
120 psppire_button_editable_expose_event (GtkWidget *widget,
121 GdkEventExpose *event)
123 GtkWidgetClass *widget_class;
124 GtkStyle *style = gtk_widget_get_style (widget);
125 GtkAllocation allocation;
128 widget_class = GTK_WIDGET_CLASS (psppire_button_editable_parent_class);
129 retval = widget_class->expose_event (widget, event);
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,
135 allocation.y + allocation.height,
136 allocation.x + allocation.width,
142 psppire_button_editable_class_init (PsppireButtonEditableClass *class)
144 GObjectClass *gobject_class;
145 GtkWidgetClass *widget_class;
147 gobject_class = G_OBJECT_CLASS (class);
148 widget_class = GTK_WIDGET_CLASS (class);
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;
154 widget_class->button_release_event = psppire_button_editable_button_release;
155 widget_class->expose_event = psppire_button_editable_expose_event;
157 g_object_class_install_property (gobject_class,
159 g_param_spec_string ("path",
161 _("The path to the row in the GtkTreeView, as a string"),
165 g_object_class_install_property (gobject_class,
167 g_param_spec_boolean ("slash",
169 _("Whether to draw a diagonal slash across the button."),
176 psppire_button_editable_init (PsppireButtonEditable *obj)
178 obj->path = g_strdup ("");
182 PsppireButtonEditable *
183 psppire_button_editable_new (void)
185 return PSPPIRE_BUTTON_EDITABLE (g_object_new (PSPPIRE_TYPE_BUTTON_EDITABLE, NULL));
189 psppire_button_editable_set_slash (PsppireButtonEditable *button,
192 g_return_if_fail (button != NULL);
193 if ((button->slash != 0) != (slash != 0))
195 button->slash = slash;
196 gtk_widget_queue_draw (GTK_WIDGET (button));
201 psppire_button_editable_get_slash (const PsppireButtonEditable *button)
203 g_return_val_if_fail (button != NULL, FALSE);
204 return button->slash;
207 /* GtkCellEditable interface. */
210 gtk_cell_editable_interface_init (GtkCellEditableIface *iface)
212 g_return_if_fail (iface != NULL);
214 iface->editing_done = button_editable_editing_done;
215 iface->remove_widget = button_editable_remove_widget;
216 iface->start_editing = button_editable_start_editing;
220 button_editable_editing_done (GtkCellEditable *cell_editable)
225 button_editable_remove_widget (GtkCellEditable *cell_editable)
230 button_editable_start_editing (GtkCellEditable *cell_editable,