On Sun, Apr 22, 2012 at 11:12:34AM -0700, Ben Pfaff wrote: This allows one to put a clickable GtkButton inside a PsppSheetView row. --- src/ui/gui/automake.mk | 8 +- src/ui/gui/include/gtk/gtk.in.h | 21 ++ src/ui/gui/psppire-button-editable.c | 179 ++++++++++ src/ui/gui/psppire-button-editable.h | 48 +++ src/ui/gui/psppire-cell-renderer-button.c | 527 +++++++++++++++++++++++++++++ src/ui/gui/psppire-cell-renderer-button.h | 65 ++++ src/ui/gui/psppire.gtkrc | 7 + 7 files changed, 853 insertions(+), 2 deletions(-) create mode 100644 src/ui/gui/psppire-button-editable.c create mode 100644 src/ui/gui/psppire-button-editable.h create mode 100644 src/ui/gui/psppire-cell-renderer-button.c create mode 100644 src/ui/gui/psppire-cell-renderer-button.h create mode 100644 src/ui/gui/psppire.gtkrc diff --git a/src/ui/gui/automake.mk b/src/ui/gui/automake.mk index 924379f..6071830 100644 --- a/src/ui/gui/automake.mk +++ b/src/ui/gui/automake.mk @@ -129,8 +129,8 @@ dist_src_ui_gui_psppire_DATA = \ $(top_srcdir)/src/ui/gui/icons/16x16/scale.png \ $(top_srcdir)/src/ui/gui/icons/16x16/string.png \ $(top_srcdir)/src/ui/gui/icons/16x16/date-scale.png \ - $(top_srcdir)/src/ui/gui/icons/splash.png - + $(top_srcdir)/src/ui/gui/icons/splash.png \ + $(top_srcdir)/src/ui/gui/psppire.gtkrc src_ui_gui_psppire_SOURCES = \ src/ui/gui/pspp-sheet-selection.c \ @@ -141,6 +141,10 @@ src_ui_gui_psppire_SOURCES = \ src/ui/gui/pspp-sheet-view.h \ src/ui/gui/pspp-widget-facade.c \ src/ui/gui/pspp-widget-facade.h \ + src/ui/gui/psppire-button-editable.c \ + src/ui/gui/psppire-button-editable.h \ + src/ui/gui/psppire-cell-renderer-button.c \ + src/ui/gui/psppire-cell-renderer-button.h \ src/ui/gui/psppire-dialog.c \ src/ui/gui/psppire-keypad.c \ src/ui/gui/psppire-selector.c \ diff --git a/src/ui/gui/include/gtk/gtk.in.h b/src/ui/gui/include/gtk/gtk.in.h index 83f0b64..966111d 100644 --- a/src/ui/gui/include/gtk/gtk.in.h +++ b/src/ui/gui/include/gtk/gtk.in.h @@ -163,4 +163,25 @@ gtk_widget_set_can_focus (GtkWidget *widget, } #endif /* gtk < 2.18 */ +#if !GTK_CHECK_VERSION(2,22,0) +/** + * gtk_button_get_event_window: + * @button: a #GtkButton + * + * Returns the button's event window if it is realized, %NULL otherwise. + * This function should be rarely needed. + * + * Return value: (transfer none): @button's event window. + * + * Since: 2.22 + */ +static inline GdkWindow* +gtk_button_get_event_window (GtkButton *button) +{ + g_return_val_if_fail (GTK_IS_BUTTON (button), NULL); + + return button->event_window; +} +#endif /* gtk < 2.22 */ + #endif /* PSPP_GTK_GTK_H */ diff --git a/src/ui/gui/psppire-button-editable.c b/src/ui/gui/psppire-button-editable.c new file mode 100644 index 0000000..cefc7a5 --- /dev/null +++ b/src/ui/gui/psppire-button-editable.c @@ -0,0 +1,179 @@ +/* PSPPIRE - a graphical user interface for PSPP. + Copyright (C) 2011, 2012 Free Software Foundation, Inc. + + This program is free software: you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation, either version 3 of the License, or + (at your option) any later version. + + This program is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License + along with this program. If not, see <http://www.gnu.org/licenses/>. */ + +#include <config.h> + +#include "ui/gui/psppire-button-editable.h" + +#include <gettext.h> +#define _(msgid) gettext (msgid) +#define N_(msgid) msgid + +/* GtkCellEditable interface. */ +static void gtk_cell_editable_interface_init (GtkCellEditableIface *iface); +static void button_editable_editing_done (GtkCellEditable *cell_editable); +static void button_editable_remove_widget (GtkCellEditable *cell_editable); +static void button_editable_start_editing (GtkCellEditable *cell_editable, + GdkEvent *event); + +G_DEFINE_TYPE_EXTENDED (PsppireButtonEditable, + psppire_button_editable, + GTK_TYPE_BUTTON, + 0, + G_IMPLEMENT_INTERFACE ( + GTK_TYPE_CELL_EDITABLE, + gtk_cell_editable_interface_init)); + +enum + { + PROP_0, + PROP_PATH + }; + +static void +psppire_button_editable_set_property (GObject *object, + guint prop_id, + const GValue *value, + GParamSpec *pspec) +{ + PsppireButtonEditable *obj = PSPPIRE_BUTTON_EDITABLE (object); + + switch (prop_id) + { + case PROP_PATH: + g_free (obj->path); + obj->path = g_value_dup_string (value); + break; + + default: + G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec); + break; + } +} + +static void +psppire_button_editable_get_property (GObject *object, + guint prop_id, + GValue *value, + GParamSpec *pspec) +{ + PsppireButtonEditable *obj = PSPPIRE_BUTTON_EDITABLE (object); + + switch (prop_id) + { + case PROP_PATH: + g_value_set_string (value, obj->path); + break; + + default: + G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec); + break; + } +} + +static void +psppire_button_editable_dispose (GObject *gobject) +{ + PsppireButtonEditable *obj = PSPPIRE_BUTTON_EDITABLE (gobject); + + g_free (obj->path); + obj->path = NULL; + + G_OBJECT_CLASS (psppire_button_editable_parent_class)->dispose (gobject); +} + +static gboolean +psppire_button_editable_button_release (GtkWidget *widget, + GdkEventButton *event) +{ + GtkButton *button; + + if (event->button == 1) + { + button = GTK_BUTTON (widget); + gtk_button_released (button); + } + + return TRUE; +} + +static void +psppire_button_editable_class_init (PsppireButtonEditableClass *class) +{ + GObjectClass *gobject_class; + GtkWidgetClass *widget_class; + + gobject_class = G_OBJECT_CLASS (class); + widget_class = GTK_WIDGET_CLASS (class); + + gobject_class->set_property = psppire_button_editable_set_property; + gobject_class->get_property = psppire_button_editable_get_property; + gobject_class->dispose = psppire_button_editable_dispose; + + widget_class->button_release_event = psppire_button_editable_button_release; + + g_object_class_install_property (G_OBJECT_CLASS (class), + PROP_PATH, + g_param_spec_string ("path", + _("TreeView path"), + _("The path to the row in the GtkTreeView, as a string"), + "", + G_PARAM_READWRITE));
In other paramSpecs we've used P_() instead of _() - or nothing. If these strings are going to be translated, they should have a separate domain I think. +static void +psppire_cell_renderer_button_init (PsppireCellRendererButton *obj) +{ + obj->editable = FALSE; + obj->label = g_strdup (""); This dynamically allocated string needs to be freed in the dispose/finalize method J' -- PGP Public key ID: 1024D/2DE827B3 fingerprint = 8797 A26D 0854 2EAB 0285 A290 8A67 719C 2DE8 27B3 See http://keys.gnupg.net or any PGP keyserver for public key.
signature.asc
Description: Digital signature
_______________________________________________ pspp-dev mailing list pspp-dev@gnu.org https://lists.gnu.org/mailman/listinfo/pspp-dev