pspp-dev
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[PATCH 17/17] psppire-cell-renderer-button: Add "slash" property.


From: Ben Pfaff
Subject: [PATCH 17/17] psppire-cell-renderer-button: Add "slash" property.
Date: Sun, 22 Apr 2012 11:12:35 -0700

When "slash" is set to true, the button gets a diagonal slash drawn
across it.  This is ugly, but it matches what SPSS does for cases
that are filtered out.
---
 src/ui/gui/psppire-button-editable.c      |   65 ++++++++++++++++++++++++++++-
 src/ui/gui/psppire-button-editable.h      |    7 +++-
 src/ui/gui/psppire-cell-renderer-button.c |   47 ++++++++++++++++++++-
 src/ui/gui/psppire-cell-renderer-button.h |    6 +++
 4 files changed, 121 insertions(+), 4 deletions(-)

diff --git a/src/ui/gui/psppire-button-editable.c 
b/src/ui/gui/psppire-button-editable.c
index cefc7a5..2e63350 100644
--- a/src/ui/gui/psppire-button-editable.c
+++ b/src/ui/gui/psppire-button-editable.c
@@ -40,7 +40,8 @@ G_DEFINE_TYPE_EXTENDED (PsppireButtonEditable,
 enum
   {
     PROP_0,
-    PROP_PATH
+    PROP_PATH,
+    PROP_SLASH
   };
 
 static void
@@ -58,6 +59,10 @@ psppire_button_editable_set_property (GObject      *object,
       obj->path = g_value_dup_string (value);
       break;
 
+    case PROP_SLASH:
+      psppire_button_editable_set_slash (obj, g_value_get_boolean (value));
+      break;
+
     default:
       G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
       break;
@@ -78,6 +83,10 @@ psppire_button_editable_get_property (GObject      *object,
       g_value_set_string (value, obj->path);
       break;
 
+    case PROP_SLASH:
+      g_value_set_boolean (value, psppire_button_editable_get_slash (obj));
+      break;
+
     default:
       G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
       break;
@@ -110,6 +119,28 @@ psppire_button_editable_button_release (GtkWidget      
*widget,
   return TRUE;
 }
 
+static gboolean
+psppire_button_editable_expose_event (GtkWidget      *widget,
+                                      GdkEventExpose *event)
+{
+  GtkWidgetClass *widget_class;
+  GtkStyle *style = gtk_widget_get_style (widget);
+  GtkAllocation allocation;
+  gboolean retval;
+
+  widget_class = GTK_WIDGET_CLASS (psppire_button_editable_parent_class);
+  retval = widget_class->expose_event (widget, event);
+
+  gtk_widget_get_allocation (widget, &allocation);
+  if (PSPPIRE_BUTTON_EDITABLE (widget)->slash)
+    gdk_draw_line (gtk_widget_get_window (widget), style->black_gc,
+                   allocation.x,
+                   allocation.y + allocation.height,
+                   allocation.x + allocation.width,
+                   allocation.y);
+  return retval;
+}
+
 static void
 psppire_button_editable_class_init (PsppireButtonEditableClass *class)
 {
@@ -124,20 +155,31 @@ psppire_button_editable_class_init 
(PsppireButtonEditableClass *class)
   gobject_class->dispose = psppire_button_editable_dispose;
 
   widget_class->button_release_event = psppire_button_editable_button_release;
+  widget_class->expose_event = psppire_button_editable_expose_event;
 
-  g_object_class_install_property (G_OBJECT_CLASS (class),
+  g_object_class_install_property (gobject_class,
                                    PROP_PATH,
                                    g_param_spec_string ("path",
                                                        _("TreeView path"),
                                                        _("The path to the row 
in the GtkTreeView, as a string"),
                                                        "",
                                                        G_PARAM_READWRITE));
+
+  g_object_class_install_property (gobject_class,
+                                   PROP_SLASH,
+                                   g_param_spec_boolean ("slash",
+                                                         _("Diagonal slash"),
+                                                         _("Whether to draw a 
diagonal slash across the button."),
+                                                         FALSE,
+                                                         G_PARAM_READWRITE));
+
 }
 
 static void
 psppire_button_editable_init (PsppireButtonEditable *obj)
 {
   obj->path = g_strdup ("");
+  obj->slash = FALSE;
 }
 
 PsppireButtonEditable *
@@ -145,6 +187,25 @@ psppire_button_editable_new (void)
 {
   return PSPPIRE_BUTTON_EDITABLE (g_object_new (PSPPIRE_TYPE_BUTTON_EDITABLE, 
NULL));
 }
+
+void
+psppire_button_editable_set_slash (PsppireButtonEditable *button,
+                                   gboolean slash)
+{
+  g_return_if_fail (button != NULL);
+  if ((button->slash != 0) != (slash != 0))
+    {
+      button->slash = slash;
+      gtk_widget_queue_draw (GTK_WIDGET (button));
+    }
+}
+
+gboolean
+psppire_button_editable_get_slash (const PsppireButtonEditable *button)
+{
+  g_return_val_if_fail (button != NULL, FALSE);
+  return button->slash;
+}
 
 /* GtkCellEditable interface. */
 
diff --git a/src/ui/gui/psppire-button-editable.h 
b/src/ui/gui/psppire-button-editable.h
index 7949b87..a0eb349 100644
--- a/src/ui/gui/psppire-button-editable.h
+++ b/src/ui/gui/psppire-button-editable.h
@@ -1,5 +1,5 @@
 /* PSPPIRE - a graphical user interface for PSPP.
-   Copyright (C) 2011 Free Software Foundation, Inc.
+   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
@@ -34,6 +34,7 @@ typedef struct _PsppireButtonEditableClass 
PsppireButtonEditableClass;
 struct _PsppireButtonEditable {
   GtkButton parent;
   gchar *path;
+  gboolean slash;
 };
 
 struct _PsppireButtonEditableClass {
@@ -43,6 +44,10 @@ struct _PsppireButtonEditableClass {
 GType psppire_button_editable_get_type (void) G_GNUC_CONST;
 PsppireButtonEditable* psppire_button_editable_new (void);
 
+void psppire_button_editable_set_slash (PsppireButtonEditable *,
+                                        gboolean slash);
+gboolean psppire_button_editable_get_slash (const PsppireButtonEditable *);
+
 G_END_DECLS
 
 #endif /* PSPPIRE_BUTTON_EDITABLE_H */
diff --git a/src/ui/gui/psppire-cell-renderer-button.c 
b/src/ui/gui/psppire-cell-renderer-button.c
index 6c251ba..c67b5eb 100644
--- a/src/ui/gui/psppire-cell-renderer-button.c
+++ b/src/ui/gui/psppire-cell-renderer-button.c
@@ -57,7 +57,8 @@ enum
   {
     PROP_0,
     PROP_EDITABLE,
-    PROP_LABEL
+    PROP_LABEL,
+    PROP_SLASH
   };
 
 static void
@@ -83,6 +84,11 @@ psppire_cell_renderer_button_set_property (GObject      
*object,
       obj->label = g_value_dup_string (value);
       break;
 
+    case PROP_SLASH:
+      psppire_cell_renderer_button_set_slash (obj,
+                                              g_value_get_boolean (value));
+      break;
+
     default:
       G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
       break;
@@ -107,6 +113,11 @@ psppire_cell_renderer_button_get_property (GObject      
*object,
       g_value_set_string (value, obj->label);
       break;
 
+    case PROP_SLASH:
+      g_value_set_boolean (value,
+                           psppire_cell_renderer_button_get_slash (obj));
+      break;
+
     default:
       G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
       break;
@@ -220,6 +231,13 @@ psppire_cell_renderer_button_render (GtkCellRenderer      
*cell,
                         state_type,
                         button->label_style, button->label, button->xpad,
                         button->ypad, cell->xalign, cell->yalign);
+
+  if (button->slash)
+    gdk_draw_line (window, button->button_style->black_gc,
+                   cell_area->x,
+                   cell_area->y + cell_area->height,
+                   cell_area->x + cell_area->width,
+                   cell_area->y);
 }
 
 static void
@@ -402,6 +420,7 @@ psppire_cell_renderer_button_start_editing (GtkCellRenderer 
     *cell,
                                       "xalign", xalign,
                                       "yalign", yalign,
                                       "path", path,
+                                      "slash", cell_button->slash,
                                       NULL);
 
   g_signal_connect (G_OBJECT (cell_button->button), "focus-out-event",
@@ -490,6 +509,15 @@ psppire_cell_renderer_button_class_init 
(PsppireCellRendererButtonClass *class)
                                                         _("Text to appear in 
button."),
                                                         "",
                                                         G_PARAM_READWRITE));
+
+  g_object_class_install_property (gobject_class,
+                                   PROP_SLASH,
+                                   g_param_spec_boolean ("slash",
+                                                         _("Diagonal slash"),
+                                                         _("Whether to draw a 
diagonal slash across the button."),
+                                                         FALSE,
+                                                         G_PARAM_READWRITE));
+
 }
 
 static void
@@ -501,6 +529,8 @@ psppire_cell_renderer_button_init 
(PsppireCellRendererButton *obj)
   obj->xpad = 0;
   obj->ypad = 0;
 
+  obj->slash = FALSE;
+
   obj->button = NULL;
 
   obj->button_style = NULL;
@@ -525,3 +555,18 @@ psppire_cell_renderer_button_new (void)
 {
   return GTK_CELL_RENDERER (g_object_new (PSPPIRE_TYPE_CELL_RENDERER_BUTTON, 
NULL));
 }
+
+void
+psppire_cell_renderer_button_set_slash (PsppireCellRendererButton *button,
+                                        gboolean slash)
+{
+  g_return_if_fail (button != NULL);
+  button->slash = slash;
+}
+
+gboolean
+psppire_cell_renderer_button_get_slash (const PsppireCellRendererButton 
*button)
+{
+  g_return_val_if_fail (button != NULL, FALSE);
+  return button->slash;
+}
diff --git a/src/ui/gui/psppire-cell-renderer-button.h 
b/src/ui/gui/psppire-cell-renderer-button.h
index 821a6e9..a878f51 100644
--- a/src/ui/gui/psppire-cell-renderer-button.h
+++ b/src/ui/gui/psppire-cell-renderer-button.h
@@ -40,6 +40,8 @@ struct _PsppireCellRendererButton {
   gint xpad;
   gint ypad;
 
+  gboolean slash;
+
   GtkWidget *button;
   guint32 click_time;
   gdouble click_x;
@@ -60,6 +62,10 @@ struct _PsppireCellRendererButtonClass {
 GType psppire_cell_renderer_button_get_type (void) G_GNUC_CONST;
 GtkCellRenderer* psppire_cell_renderer_button_new (void);
 
+void psppire_cell_renderer_button_set_slash (PsppireCellRendererButton *,
+                                             gboolean slash);
+gboolean psppire_cell_renderer_button_get_slash (const 
PsppireCellRendererButton *);
+
 G_END_DECLS
 
 #endif /* PSPPIRE_CELL_RENDERER_BUTTON_H */
-- 
1.7.2.5




reply via email to

[Prev in Thread] Current Thread [Next in Thread]