[gtk+/wip/baedert/drawing: 37/73] GtkAccelLabel: Add use-underline property



commit f6be7c841926d222200ccfe8db8c94196d8d8175
Author: Timm Bäder <mail baedert org>
Date:   Fri Jun 16 15:22:04 2017 +0200

    GtkAccelLabel: Add use-underline property

 gtk/gtkaccellabel.c |   44 +++++++++++++++++++++++++++++++++++++++++++-
 gtk/gtkaccellabel.h |    8 ++++++++
 2 files changed, 51 insertions(+), 1 deletions(-)
---
diff --git a/gtk/gtkaccellabel.c b/gtk/gtkaccellabel.c
index 6aed168..bb5cac8 100644
--- a/gtk/gtkaccellabel.c
+++ b/gtk/gtkaccellabel.c
@@ -115,6 +115,7 @@ enum {
   PROP_ACCEL_CLOSURE,
   PROP_ACCEL_WIDGET,
   PROP_LABEL,
+  PROP_USE_UNDERLINE,
   LAST_PROP
 };
 
@@ -240,6 +241,13 @@ gtk_accel_label_class_init (GtkAccelLabelClass *class)
                          "",
                          GTK_PARAM_READWRITE);
 
+  props[PROP_USE_UNDERLINE] =
+    g_param_spec_boolean ("use-underline",
+                          P_("Use underline"),
+                          P_("If set, an underline in the text indicates the next character should be used 
for the mnemonic accelerator key"),
+                          FALSE,
+                          GTK_PARAM_READWRITE|G_PARAM_EXPLICIT_NOTIFY);
+
   g_object_class_install_properties (gobject_class, LAST_PROP, props);
 
   gtk_widget_class_set_css_name (widget_class, "accellabel");
@@ -266,6 +274,9 @@ gtk_accel_label_set_property (GObject      *object,
     case PROP_LABEL:
       gtk_accel_label_set_label (accel_label, g_value_get_string (value));
       break;
+    case PROP_USE_UNDERLINE:
+      gtk_accel_label_set_use_underline (accel_label, g_value_get_boolean (value));
+      break;
     default:
       G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
       break;
@@ -293,6 +304,9 @@ gtk_accel_label_get_property (GObject    *object,
     case PROP_LABEL:
       g_value_set_string (value, gtk_accel_label_get_label (accel_label));
       break;
+    case PROP_USE_UNDERLINE:
+      g_value_set_boolean (value, gtk_accel_label_get_use_underline (accel_label));
+      break;
     default:
       G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
       break;
@@ -317,7 +331,6 @@ gtk_accel_label_init (GtkAccelLabel *accel_label)
   priv->text_label = gtk_label_new ("");
   gtk_widget_set_hexpand (priv->text_label, TRUE);
   gtk_label_set_xalign (GTK_LABEL (priv->text_label), 0.0f);
-  gtk_label_set_use_underline (GTK_LABEL (priv->text_label), TRUE);
   priv->accel_label = g_object_new (GTK_TYPE_LABEL,
                                     "css-name", "accelerator",
                                     NULL);
@@ -992,3 +1005,32 @@ gtk_accel_label_get_label (GtkAccelLabel   *accel_label)
 
   return gtk_label_get_label (GTK_LABEL (priv->text_label));
 }
+
+
+void
+gtk_accel_label_set_use_underline (GtkAccelLabel *accel_label,
+                                   gboolean       setting)
+{
+  GtkAccelLabelPrivate *priv = gtk_accel_label_get_instance_private (accel_label);
+
+  g_return_if_fail (GTK_IS_ACCEL_LABEL (accel_label));
+
+  setting = !!setting;
+
+  if (setting != gtk_label_get_use_underline (GTK_LABEL (priv->text_label)))
+    {
+      gtk_label_set_use_underline (GTK_LABEL (priv->text_label), setting);
+
+      g_object_notify_by_pspec (G_OBJECT (accel_label), props[PROP_USE_UNDERLINE]);
+    }
+}
+
+gboolean
+gtk_accel_label_get_use_underline (GtkAccelLabel *accel_label)
+{
+  GtkAccelLabelPrivate *priv = gtk_accel_label_get_instance_private (accel_label);
+
+  g_return_val_if_fail (GTK_IS_ACCEL_LABEL (accel_label), FALSE);
+
+  return gtk_label_get_use_underline (GTK_LABEL (priv->text_label));
+}
diff --git a/gtk/gtkaccellabel.h b/gtk/gtkaccellabel.h
index 678b081..d10004c 100644
--- a/gtk/gtkaccellabel.h
+++ b/gtk/gtkaccellabel.h
@@ -111,6 +111,14 @@ void      gtk_accel_label_set_label          (GtkAccelLabel   *accel_label,
 GDK_AVAILABLE_IN_3_92
 const char * gtk_accel_label_get_label       (GtkAccelLabel   *accel_label);
 
+GDK_AVAILABLE_IN_3_92
+void      gtk_accel_label_set_use_underline  (GtkAccelLabel   *accel_label,
+                                              gboolean         setting);
+
+GDK_AVAILABLE_IN_3_92
+gboolean  gtk_accel_label_get_use_underline  (GtkAccelLabel   *accel_label);
+
+
 /* private */
 gchar *    _gtk_accel_label_class_get_accelerator_label (GtkAccelLabelClass *klass,
                                                         guint               accelerator_key,


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