[gtk+/wip/strength-bar: 1/2] strength-bar: introduce GtkStrengthBar



commit 7cfd6e905c861bd50313864f96e17a9ebfac764d
Author: Cosimo Cecchi <cosimoc gnome org>
Date:   Tue May 29 17:00:33 2012 -0400

    strength-bar: introduce GtkStrengthBar
    
    Similar to CcStrengthBar from gnome-control-center, but more generic and
    with thorough CSS styling support.
    
    https://bugzilla.gnome.org/show_bug.cgi?id=677892

 docs/reference/gtk/gtk-docs.sgml        |    1 +
 docs/reference/gtk/gtk3-sections.txt    |   36 +
 docs/reference/gtk/gtk3.types.in        |    1 +
 docs/reference/gtk/objects_grouped.sgml |    1 +
 gtk/Makefile.am                         |    2 +
 gtk/gtk.h                               |    1 +
 gtk/gtk.symbols                         |   17 +
 gtk/gtkenums.h                          |   12 +
 gtk/gtkstrengthbar.c                    | 1121 +++++++++++++++++++++++++++++++
 gtk/gtkstrengthbar.h                    |  108 +++
 gtk/gtkstylecontext.h                   |   37 +
 11 files changed, 1337 insertions(+), 0 deletions(-)
---
diff --git a/docs/reference/gtk/gtk-docs.sgml b/docs/reference/gtk/gtk-docs.sgml
index a27fee9..1d4cc87 100644
--- a/docs/reference/gtk/gtk-docs.sgml
+++ b/docs/reference/gtk/gtk-docs.sgml
@@ -102,6 +102,7 @@
       <xi:include href="xml/gtklabel.xml" />
       <xi:include href="xml/gtkprogressbar.xml" />
       <xi:include href="xml/gtkstatusbar.xml" />
+      <xi:include href="xml/gtkstrengthbar.xml" />
       <xi:include href="xml/gtkinfobar.xml" />
       <xi:include href="xml/gtkstatusicon.xml" />
       <xi:include href="xml/gtkspinner.xml" />
diff --git a/docs/reference/gtk/gtk3-sections.txt b/docs/reference/gtk/gtk3-sections.txt
index aa23697..530fa60 100644
--- a/docs/reference/gtk/gtk3-sections.txt
+++ b/docs/reference/gtk/gtk3-sections.txt
@@ -3222,6 +3222,37 @@ gtk_status_icon_get_type
 </SECTION>
 
 <SECTION>
+<FILE>gtkstrengthbar</FILE>
+<TITLE>GtkStrengthBar</TITLE>
+GtkStrengthBar
+gtk_strength_bar_new
+gtk_strength_bar_set_bar_style
+gtk_strength_bar_get_bar_style
+gtk_strength_bar_set_value
+gtk_strength_bar_get_value
+gtk_strength_bar_set_min_value
+gtk_strength_bar_get_min_value
+gtk_strength_bar_set_critical_value
+gtk_strength_bar_get_critical_value
+gtk_strength_bar_set_warning_value
+gtk_strength_bar_get_warning_value
+gtk_strength_bar_set_strong_value
+gtk_strength_bar_get_strong_value
+gtk_strength_bar_set_max_value
+gtk_strength_bar_get_max_value
+<SUBSECTION Standard>
+GTK_STRENGTH_BAR
+GTK_IS_STRENGTH_BAR
+GTK_TYPE_STRENGTH_BAR
+GTK_STRENGTH_BAR_CLASS
+GTK_IS_STRENGTH_BAR_CLASS
+GTK_STRENGTH_BAR_GET_CLASS
+<SUBSECTION Private>
+GtkStrengthBarPrivate
+gtk_strength_bar_get_type
+</SECTION>
+
+<SECTION>
 <FILE>gtktable</FILE>
 <TITLE>GtkTable</TITLE>
 GtkTable
@@ -5695,6 +5726,10 @@ GTK_STYLE_CLASS_RIGHT
 GTK_STYLE_CLASS_LINKED
 GTK_STYLE_CLASS_ARROW
 GTK_STYLE_CLASS_OSD
+GTK_STYLE_CLASS_STRENGTH_BAR
+GTK_STYLE_CLASS_LEVEL_CRITICAL
+GTK_STYLE_CLASS_LEVEL_WARNING
+GTK_STYLE_CLASS_LEVEL_STRONG
 GTK_STYLE_REGION_COLUMN
 GTK_STYLE_REGION_COLUMN_HEADER
 GTK_STYLE_REGION_ROW
@@ -6221,6 +6256,7 @@ GtkSelectionMode
 GtkShadowType
 GtkStateType
 GtkStateFlags
+GtkStrengthBarStyle
 GtkToolbarStyle
 GtkWindowPosition
 GtkWindowType
diff --git a/docs/reference/gtk/gtk3.types.in b/docs/reference/gtk/gtk3.types.in
index 5b9b3bd..4f75098 100644
--- a/docs/reference/gtk/gtk3.types.in
+++ b/docs/reference/gtk/gtk3.types.in
@@ -155,6 +155,7 @@ gtk_spinner_get_type
 gtk_statusbar_get_type
 gtk_status_icon_get_type
 gtk_switch_get_type
+gtk_strength_bar_get_type
 gtk_style_get_type
 gtk_style_context_get_type
 gtk_style_provider_get_type
diff --git a/docs/reference/gtk/objects_grouped.sgml b/docs/reference/gtk/objects_grouped.sgml
index 78dc95b..56bfd95 100644
--- a/docs/reference/gtk/objects_grouped.sgml
+++ b/docs/reference/gtk/objects_grouped.sgml
@@ -90,6 +90,7 @@
     <link linkend="GtkCalendar">GtkCalendar</link>
     <link linkend="GtkProgressBar">GtkProgressBar</link>
     <link linkend="GtkStatusbar">GtkStatusbar</link>
+    <link linkend="GtkStrengthBar">GtkStrengthBar</link>
     <link linkend="GtkHRuler">GtkHRuler</link>
     <link linkend="GtkVRuler">GtkVRuler</link>
     <link linkend="GtkHScrollbar">GtkHScrollbar</link>
diff --git a/gtk/Makefile.am b/gtk/Makefile.am
index f176f59..56897af 100644
--- a/gtk/Makefile.am
+++ b/gtk/Makefile.am
@@ -324,6 +324,7 @@ gtk_public_h_sources = 		\
 	gtkstatusbar.h		\
 	gtkstatusicon.h		\
 	gtkstock.h		\
+	gtkstrengthbar.h	\
 	gtkstylecontext.h	\
 	gtkstyleproperties.h	\
 	gtkstyleprovider.h	\
@@ -763,6 +764,7 @@ gtk_base_c_sources = 		\
 	gtkprivate.c		\
 	gtkprivatetypebuiltins.c \
 	gtkprogressbar.c	\
+	gtkstrengthbar.c	\
 	gtkradioaction.c	\
 	gtkradiobutton.c	\
 	gtkradiomenuitem.c	\
diff --git a/gtk/gtk.h b/gtk/gtk.h
index 587b6de..1e06556 100644
--- a/gtk/gtk.h
+++ b/gtk/gtk.h
@@ -179,6 +179,7 @@
 #include <gtk/gtkstatusbar.h>
 #include <gtk/gtkstatusicon.h>
 #include <gtk/gtkstock.h>
+#include <gtk/gtkstrengthbar.h>
 #include <gtk/gtkstylecontext.h>
 #include <gtk/gtkstyleproperties.h>
 #include <gtk/gtkstyleprovider.h>
diff --git a/gtk/gtk.symbols b/gtk/gtk.symbols
index cfe7b02..0d7989f 100644
--- a/gtk/gtk.symbols
+++ b/gtk/gtk.symbols
@@ -2555,6 +2555,23 @@ gtk_switch_get_active
 gtk_switch_get_type
 gtk_switch_new
 gtk_switch_set_active
+gtk_strength_bar_get_type
+gtk_strength_bar_new
+gtk_strength_bar_set_bar_style
+gtk_strength_bar_get_bar_style
+gtk_strength_bar_set_value
+gtk_strength_bar_get_value
+gtk_strength_bar_set_min_value
+gtk_strength_bar_get_min_value
+gtk_strength_bar_set_critical_value
+gtk_strength_bar_get_critical_value
+gtk_strength_bar_set_warning_value
+gtk_strength_bar_get_warning_value
+gtk_strength_bar_set_strong_value
+gtk_strength_bar_get_strong_value
+gtk_strength_bar_set_max_value
+gtk_strength_bar_get_max_value
+gtk_strength_bar_style_get_type
 gtk_style_apply_default_background
 gtk_style_attach
 gtk_style_context_add_class
diff --git a/gtk/gtkenums.h b/gtk/gtkenums.h
index e409d79..d58a35d 100644
--- a/gtk/gtkenums.h
+++ b/gtk/gtkenums.h
@@ -932,6 +932,18 @@ typedef enum {
   GTK_BORDER_STYLE_RIDGE
 } GtkBorderStyle;
 
+/**
+ * GtkStrengthBarStyle:
+ * @GTK_STRENGTH_BAR_STYLE_CONTINUOUS: the bar has a continuous style
+ * @GTK_STRENGTH_BAR_STYLE_DISCRETE: the bar has a discrete style
+ *
+ * Describes how #GtkStrengthBar contents should be rendered.
+ */
+typedef enum {
+  GTK_STRENGTH_BAR_STYLE_CONTINUOUS,
+  GTK_STRENGTH_BAR_STYLE_DISCRETE
+} GtkStrengthBarStyle;
+
 G_END_DECLS
 
 
diff --git a/gtk/gtkstrengthbar.c b/gtk/gtkstrengthbar.c
new file mode 100644
index 0000000..88de41e
--- /dev/null
+++ b/gtk/gtkstrengthbar.c
@@ -0,0 +1,1121 @@
+/* GTK - The GIMP Toolkit
+ * Copyright  2012 Red Hat, Inc.
+ *
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * version 2 of the License, or (at your option) any later version.
+ *
+ * This library 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
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this library. If not, see <http://www.gnu.org/licenses/>.
+ *
+ * Author: Cosimo Cecchi <cosimoc gnome org>
+ *
+ */
+
+/**
+ * SECTION:gtkstrengthbar
+ * @Title: GtkStrengthBar
+ * @Short_description: A bar that can used as a strength indicator
+ *
+ * The #GtkStrengthBar is a bar widget that can be used
+ * as a strength indicator. Typical use cases are displaying the strength
+ * of a password, or showing the charge level of a battery.
+ *
+ * Use #gtk_strength_bar_set_value to set the current value, and
+ * #gtk_strength_bar_set_critical_value, #gtk_strength_bar_set_warning_value
+ * and #gtk_strength_bar_set_strong_value to set the value offsets at which 
+ * the bar will be considered in a critical, warning or strong state. In such
+ * cases, the bar will use the #GTK_STYLE_CLASS_LEVEL_CRITICAL, 
+ * #GTK_STYLE_CLASS_LEVEL_WARNING and #GTK_STYLE_CLASS_LEVEL_STRONG style classes
+ * when rendering the fill area.
+ * The default interval of values is between zero and one, but it's possible to
+ * modify the interval using #gtk_strength_bar_set_min_value and
+ * #gtk_strength_bar_set_max_value. The value will be always drawn in proportion to
+ * the ammissible interval, i.e. a value of 15 with a specified interval between
+ * 10 and 20 is equivalent to a value of 0.5 with an interval between 0 and 1.
+ * When #GTK_STRENGTH_BAR_STYLE_DISCRETE is used, the bar level is rendered
+ * as a finite and number of separated blocks instead of a single one. The number
+ * of blocks that will be rendered is equal to the number of units specified by
+ * the ammissible interval.
+ * For instance, to build a bar rendered with five blocks, it's sufficient to
+ * set the minimum value to 0 and the maximum value to 5 after changing the indicator
+ * style to discrete.
+ *
+ * Since: 3.6
+ */
+#include "config.h"
+
+#include "gtkintl.h"
+#include "gtkorientableprivate.h"
+#include "gtkstrengthbar.h"
+#include "gtkstylecontext.h"
+#include "gtktypebuiltins.h"
+#include "gtkwidget.h"
+
+#include <math.h>
+
+#define DEFAULT_BLOCK_SIZE 3
+
+/* these don't make sense outside of GtkStrengthBar, so we don't add
+ * global defines */
+#define STYLE_CLASS_INDICATOR_CONTINUOUS "indicator-continuous"
+#define STYLE_CLASS_INDICATOR_DISCRETE   "indicator-discrete"
+#define STYLE_CLASS_FILL_BLOCK           "fill-block"
+#define STYLE_CLASS_EMPTY_FILL_BLOCK     "empty-fill-block"
+
+G_DEFINE_TYPE_WITH_CODE (GtkStrengthBar, gtk_strength_bar, GTK_TYPE_WIDGET,
+                         G_IMPLEMENT_INTERFACE (GTK_TYPE_ORIENTABLE, NULL))
+
+enum {
+  PROP_VALUE = 1,
+  PROP_MIN_VALUE,
+  PROP_CRITICAL_VALUE,
+  PROP_WARNING_VALUE,
+  PROP_STRONG_VALUE,
+  PROP_MAX_VALUE,
+  PROP_BAR_STYLE,
+  LAST_PROPERTY,
+  PROP_ORIENTATION /* overridden */
+};
+
+static GParamSpec *properties[LAST_PROPERTY] = { NULL, };
+
+struct _GtkStrengthBarPrivate {
+  GtkOrientation orientation;
+
+  gdouble min_value;
+  gdouble max_value;
+
+  gdouble critical_value;
+  gdouble warning_value;
+  gdouble strong_value;
+
+  gdouble cur_value;
+
+  GtkStrengthBarStyle bar_style;
+};
+
+static void gtk_strength_bar_set_strong_value_internal   (GtkStrengthBar *self,
+                                                          gdouble         value);
+static void gtk_strength_bar_set_warning_value_internal  (GtkStrengthBar *self,
+                                                          gdouble         value);
+static void gtk_strength_bar_set_critical_value_internal (GtkStrengthBar *self,
+                                                          gdouble         value);
+static void gtk_strength_bar_set_value_internal          (GtkStrengthBar *self,
+                                                          gdouble         value);
+
+static gboolean
+gtk_strength_bar_value_in_interval (GtkStrengthBar *self,
+                                    gdouble         value)
+{
+  return ((value >= self->priv->min_value) &&
+          (value <= self->priv->max_value));
+}
+
+static void
+gtk_strength_bar_get_min_block_size (GtkStrengthBar *self,
+                                     gint           *block_width,
+                                     gint           *block_height)
+{
+  GtkWidget *widget = GTK_WIDGET (self);
+  GtkStyleContext *context = gtk_widget_get_style_context (widget);
+  GtkStateFlags flags = gtk_widget_get_state_flags (widget);
+  GtkBorder border, tmp, tmp2;
+  gint min_width, min_height;
+
+  gtk_style_context_save (context);
+  gtk_style_context_add_class (context, STYLE_CLASS_FILL_BLOCK);
+  gtk_style_context_get_border (context, flags, &border);
+  gtk_style_context_get_padding (context, flags, &tmp);
+  gtk_style_context_get_margin (context, flags, &tmp2);
+  gtk_style_context_restore (context);
+
+  gtk_style_context_get_style (context,
+                               "min-block-width", &min_width,
+                               "min-block-height", &min_height,
+                               NULL);
+
+  border.top += tmp.top;
+  border.right += tmp.right;
+  border.bottom += tmp.bottom;
+  border.left += tmp.left;
+
+  border.top += tmp2.top;
+  border.right += tmp2.right;
+  border.bottom += tmp2.bottom;
+  border.left += tmp2.left;
+
+  if (block_width)
+    *block_width = MAX (border.left + border.right, min_width);
+  if (block_height)
+    *block_height = MAX (border.top + border.bottom, min_height);
+}
+
+static gint
+gtk_strength_bar_get_num_blocks (GtkStrengthBar *self)
+{
+  if (self->priv->bar_style == GTK_STRENGTH_BAR_STYLE_CONTINUOUS)
+    return 1;
+  else if (self->priv->bar_style == GTK_STRENGTH_BAR_STYLE_DISCRETE)
+    return MAX (1, (gint) (round (self->priv->max_value) - round (self->priv->min_value)));
+
+  return 0;
+}
+
+static void
+gtk_strength_bar_get_borders (GtkStrengthBar *self,
+                              GtkBorder      *borders_out)
+{
+  GtkWidget *widget = GTK_WIDGET (self);
+  GtkStyleContext *context = gtk_widget_get_style_context (widget);
+  GtkStateFlags flags = gtk_widget_get_state_flags (widget);
+  GtkBorder border, tmp;
+
+  gtk_style_context_save (context);
+  gtk_style_context_add_class (context, GTK_STYLE_CLASS_TROUGH);
+  gtk_style_context_get_border (context, flags, &border);
+  gtk_style_context_get_padding (context, flags, &tmp);
+  gtk_style_context_restore (context);
+
+  border.top += tmp.top;
+  border.right += tmp.right;
+  border.bottom += tmp.bottom;
+  border.left += tmp.left;
+
+  if (borders_out)
+    *borders_out = border;
+}
+
+static void
+gtk_strength_bar_draw_fill_continuous (GtkStrengthBar        *self,
+                                       cairo_t               *cr,
+                                       cairo_rectangle_int_t *fill_area)
+{
+  GtkWidget *widget = GTK_WIDGET (self);
+  GtkStyleContext *context = gtk_widget_get_style_context (widget);
+  GtkStateFlags flags = gtk_widget_get_state_flags (widget);
+  cairo_rectangle_int_t base_area, block_area;
+  GtkBorder block_margin;
+  gdouble fill_percentage;
+
+  gtk_style_context_save (context);
+  gtk_style_context_add_class (context, STYLE_CLASS_FILL_BLOCK);
+  gtk_style_context_get_margin (context, flags, &block_margin);
+
+  /* render the empty (unfilled) part */
+  base_area = *fill_area;
+  base_area.x += block_margin.left;
+  base_area.y += block_margin.top;
+  base_area.width -= block_margin.left + block_margin.right;
+  base_area.height -= block_margin.top + block_margin.bottom;
+
+  gtk_style_context_add_class (context, STYLE_CLASS_EMPTY_FILL_BLOCK);
+
+  gtk_render_background (context, cr, base_area.x, base_area.y,
+                         base_area.width, base_area.height);
+  gtk_render_frame (context, cr, base_area.x, base_area.y,
+                    base_area.width, base_area.height);
+
+  /* now render the filled part on top of it */
+  block_area = base_area;
+
+  fill_percentage = (self->priv->cur_value - self->priv->min_value) /
+    (self->priv->max_value - self->priv->min_value);
+
+  if (self->priv->orientation == GTK_ORIENTATION_HORIZONTAL)
+    block_area.width = (gint) floor (block_area.width * fill_percentage);
+  else
+    block_area.height = (gint) floor (block_area.height * fill_percentage);
+
+  gtk_style_context_remove_class (context, STYLE_CLASS_EMPTY_FILL_BLOCK);
+
+  gtk_render_background (context, cr, block_area.x, block_area.y,
+                         block_area.width, block_area.height);
+  gtk_render_frame (context, cr, block_area.x, block_area.y,
+                    block_area.width, block_area.height);
+
+  gtk_style_context_restore (context);
+}
+
+static void
+gtk_strength_bar_draw_fill_discrete (GtkStrengthBar        *self,
+                                     cairo_t               *cr,
+                                     cairo_rectangle_int_t *fill_area)
+{
+  GtkWidget *widget = GTK_WIDGET (self);
+  GtkStyleContext *context = gtk_widget_get_style_context (widget);
+  GtkStateFlags flags = gtk_widget_get_state_flags (widget);
+  gint num_blocks, num_filled, idx;
+  gint block_width, block_height;
+  gint block_draw_width, block_draw_height;
+  GtkBorder block_margin;
+  cairo_rectangle_int_t block_area;
+
+  gtk_strength_bar_get_min_block_size (self, &block_width, &block_height);
+
+  block_area = *fill_area;
+  num_blocks = gtk_strength_bar_get_num_blocks (self);
+  num_filled = (gint) round (self->priv->cur_value) - (gint) round (self->priv->min_value);
+
+  if (self->priv->orientation == GTK_ORIENTATION_HORIZONTAL)
+    block_width = MAX (block_width, (gint) floor (block_area.width / num_blocks));
+  else
+    block_height = MAX (block_height, (gint) floor (block_area.height / num_blocks));
+
+  gtk_style_context_save (context);
+  gtk_style_context_add_class (context, STYLE_CLASS_FILL_BLOCK);
+  gtk_style_context_get_margin (context, flags, &block_margin);
+
+  block_draw_width = block_width - block_margin.left - block_margin.right;
+  block_draw_height = block_height - block_margin.top - block_margin.bottom;
+
+  if (self->priv->orientation == GTK_ORIENTATION_HORIZONTAL)
+    {
+      block_draw_height = MAX (block_draw_height, block_area.height - block_margin.top - block_margin.bottom);
+      block_area.y += block_margin.top;
+    }
+  else
+    {
+      block_draw_width = MAX (block_draw_width, block_area.width - block_margin.left - block_margin.right);
+      block_area.x += block_margin.left;
+    }
+
+  for (idx = 0; idx < num_blocks; idx++)
+    {
+      if (self->priv->orientation == GTK_ORIENTATION_HORIZONTAL)
+        block_area.x += block_margin.left;
+      else
+        block_area.y += block_margin.top;
+
+      if (idx > num_filled - 1)
+        gtk_style_context_add_class (context, STYLE_CLASS_EMPTY_FILL_BLOCK);
+
+      gtk_render_background (context, cr,
+                             block_area.x, block_area.y,
+                             block_draw_width, block_draw_height);
+      gtk_render_frame (context, cr,
+                        block_area.x, block_area.y,
+                        block_draw_width, block_draw_height);
+
+      if (self->priv->orientation == GTK_ORIENTATION_HORIZONTAL)
+        block_area.x += block_draw_width + block_margin.right;
+      else
+        block_area.y += block_draw_height + block_margin.bottom;
+    }
+
+  gtk_style_context_restore (context);
+}
+
+static void
+gtk_strength_bar_draw_fill (GtkStrengthBar *self,
+                            cairo_t        *cr)
+{
+  GtkWidget *widget = GTK_WIDGET (self);
+  GtkBorder trough_borders; 
+  cairo_rectangle_int_t fill_area;
+
+  gtk_strength_bar_get_borders (self, &trough_borders);
+
+  fill_area.x = trough_borders.left;
+  fill_area.y = trough_borders.top;
+  fill_area.width = gtk_widget_get_allocated_width (widget) -
+    trough_borders.left - trough_borders.right;
+  fill_area.height = gtk_widget_get_allocated_height (widget) -
+    trough_borders.top - trough_borders.bottom;
+
+  if (self->priv->bar_style == GTK_STRENGTH_BAR_STYLE_CONTINUOUS)
+    gtk_strength_bar_draw_fill_continuous (self, cr, &fill_area);
+  else if (self->priv->bar_style == GTK_STRENGTH_BAR_STYLE_DISCRETE)
+    gtk_strength_bar_draw_fill_discrete (self, cr, &fill_area);
+}
+
+static gboolean
+gtk_strength_bar_draw (GtkWidget *widget,
+                       cairo_t   *cr)
+{
+  GtkStrengthBar *self = GTK_STRENGTH_BAR (widget);
+  GtkStyleContext *context = gtk_widget_get_style_context (widget);
+  gint width, height;
+
+  width = gtk_widget_get_allocated_width (widget);
+  height = gtk_widget_get_allocated_height (widget);
+
+  gtk_style_context_save (context);
+  gtk_style_context_add_class (context, GTK_STYLE_CLASS_TROUGH);
+
+  gtk_render_background (context, cr, 0, 0, width, height);
+  gtk_render_frame (context, cr, 0, 0, width, height);
+
+  gtk_style_context_restore (context);
+
+  gtk_strength_bar_draw_fill (self, cr);
+
+  return FALSE;
+}
+
+static void
+gtk_strength_bar_get_preferred_width (GtkWidget *widget,
+                                      gint      *minimum,
+                                      gint      *natural)
+{
+  GtkStrengthBar *self = GTK_STRENGTH_BAR (widget);
+  GtkBorder borders;
+  gint num_blocks;
+  gint width, block_width;
+
+  num_blocks = gtk_strength_bar_get_num_blocks (self);
+  gtk_strength_bar_get_min_block_size (self, &block_width, NULL);
+
+  gtk_strength_bar_get_borders (self, &borders);
+  width = borders.left + borders.right;
+
+  if (self->priv->orientation == GTK_ORIENTATION_HORIZONTAL)
+    width += num_blocks * block_width;
+  else
+    width += block_width;
+
+  if (minimum)
+    *minimum = width;
+  if (natural)
+    *natural = width;
+}
+
+static void
+gtk_strength_bar_get_preferred_height (GtkWidget *widget,
+                                       gint      *minimum,
+                                       gint      *natural)
+{
+  GtkStrengthBar *self = GTK_STRENGTH_BAR (widget);
+  GtkBorder borders;
+  gint num_blocks;
+  gint height, block_height;
+
+  num_blocks = gtk_strength_bar_get_num_blocks (self);
+  gtk_strength_bar_get_min_block_size (self, NULL, &block_height);
+
+  gtk_strength_bar_get_borders (self, &borders);
+  height = borders.top + borders.bottom;
+
+  if (self->priv->orientation == GTK_ORIENTATION_VERTICAL)
+    height += num_blocks * block_height;
+  else
+    height += block_height;
+
+  if (minimum)
+    *minimum = height;
+  if (natural)
+    *natural = height;
+}
+
+static void
+gtk_strength_bar_update_bar_style_classes (GtkStrengthBar *self)
+{
+  GtkStyleContext *context = gtk_widget_get_style_context (GTK_WIDGET (self));
+
+  if (self->priv->bar_style == GTK_STRENGTH_BAR_STYLE_CONTINUOUS)
+    {
+      gtk_style_context_remove_class (context, STYLE_CLASS_INDICATOR_DISCRETE);
+      gtk_style_context_add_class (context, STYLE_CLASS_INDICATOR_CONTINUOUS);
+    }
+  else if (self->priv->bar_style == GTK_STRENGTH_BAR_STYLE_DISCRETE)
+    {
+      gtk_style_context_remove_class (context, STYLE_CLASS_INDICATOR_CONTINUOUS);
+      gtk_style_context_add_class (context, STYLE_CLASS_INDICATOR_DISCRETE);
+    }
+}
+
+static void
+gtk_strength_bar_update_level_style_classes (GtkStrengthBar *self)
+{
+  GtkStyleContext *context = gtk_widget_get_style_context (GTK_WIDGET (self));
+  gdouble value = gtk_strength_bar_get_value (self);
+
+  if (value < self->priv->critical_value)
+    {
+      gtk_style_context_remove_class (context, GTK_STYLE_CLASS_LEVEL_STRONG);
+      gtk_style_context_remove_class (context, GTK_STYLE_CLASS_LEVEL_WARNING);
+
+      gtk_style_context_add_class (context, GTK_STYLE_CLASS_LEVEL_CRITICAL);
+    }
+  else if (value < self->priv->warning_value)
+    {
+      gtk_style_context_remove_class (context, GTK_STYLE_CLASS_LEVEL_CRITICAL);
+      gtk_style_context_remove_class (context, GTK_STYLE_CLASS_LEVEL_STRONG);
+
+      gtk_style_context_add_class (context, GTK_STYLE_CLASS_LEVEL_WARNING);
+    }
+  else if (value > self->priv->strong_value)
+    {
+      gtk_style_context_remove_class (context, GTK_STYLE_CLASS_LEVEL_CRITICAL);
+      gtk_style_context_remove_class (context, GTK_STYLE_CLASS_LEVEL_WARNING);
+
+      gtk_style_context_add_class (context, GTK_STYLE_CLASS_LEVEL_STRONG);
+    }
+  else
+    {
+      gtk_style_context_remove_class (context, GTK_STYLE_CLASS_LEVEL_CRITICAL);
+      gtk_style_context_remove_class (context, GTK_STYLE_CLASS_LEVEL_WARNING);
+      gtk_style_context_remove_class (context, GTK_STYLE_CLASS_LEVEL_STRONG);
+    }
+}
+
+static void
+gtk_strength_bar_set_orientation (GtkStrengthBar *self,
+                                  GtkOrientation  orientation)
+{
+  if (self->priv->orientation != orientation)
+    {
+      self->priv->orientation = orientation;
+      _gtk_orientable_set_style_classes (GTK_ORIENTABLE (self));
+
+      gtk_widget_queue_resize (GTK_WIDGET (self));
+    }
+}
+
+static void
+gtk_strength_bar_get_property (GObject    *obj,
+                               guint       property_id,
+                               GValue     *value,
+                               GParamSpec *pspec)
+{
+  GtkStrengthBar *self = GTK_STRENGTH_BAR (obj);
+
+  switch (property_id)
+    {
+    case PROP_VALUE:
+      g_value_set_double (value, gtk_strength_bar_get_value (self));
+      break;
+    case PROP_MIN_VALUE:
+      g_value_set_double (value, gtk_strength_bar_get_min_value (self));
+      break;
+    case PROP_CRITICAL_VALUE:
+      g_value_set_double (value, gtk_strength_bar_get_critical_value (self));
+      break;
+    case PROP_WARNING_VALUE:
+      g_value_set_double (value, gtk_strength_bar_get_warning_value (self));
+      break;
+    case PROP_STRONG_VALUE:
+      g_value_set_double (value, gtk_strength_bar_get_strong_value (self));
+      break;
+    case PROP_MAX_VALUE:
+      g_value_set_double (value, gtk_strength_bar_get_max_value (self));
+      break;
+    case PROP_BAR_STYLE:
+      g_value_set_enum (value, gtk_strength_bar_get_bar_style (self));
+      break;
+    case PROP_ORIENTATION:
+      g_value_set_enum (value, self->priv->orientation);
+      break;
+    default:
+      G_OBJECT_WARN_INVALID_PROPERTY_ID (obj, property_id, pspec);
+      break;
+    }
+}
+
+static void
+gtk_strength_bar_set_property (GObject      *obj,
+                               guint         property_id,
+                               const GValue *value,
+                               GParamSpec   *pspec)
+{
+  GtkStrengthBar *self = GTK_STRENGTH_BAR (obj);
+
+  switch (property_id)
+    {
+    case PROP_VALUE:
+      gtk_strength_bar_set_value (self, g_value_get_double (value));
+      break;
+    case PROP_MIN_VALUE:
+      gtk_strength_bar_set_min_value (self, g_value_get_double (value));
+      break;
+    case PROP_CRITICAL_VALUE:
+      gtk_strength_bar_set_critical_value (self, g_value_get_double (value));
+      break;
+    case PROP_WARNING_VALUE:
+      gtk_strength_bar_set_warning_value (self, g_value_get_double (value));
+      break;
+    case PROP_STRONG_VALUE:
+      gtk_strength_bar_set_strong_value (self, g_value_get_double (value));
+      break;
+    case PROP_MAX_VALUE:
+      gtk_strength_bar_set_max_value (self, g_value_get_double (value));
+      break;
+    case PROP_BAR_STYLE:
+      gtk_strength_bar_set_bar_style (self, g_value_get_enum (value));
+      break;
+    case PROP_ORIENTATION:
+      gtk_strength_bar_set_orientation (self, g_value_get_enum (value));
+      break;
+    default:
+      G_OBJECT_WARN_INVALID_PROPERTY_ID (obj, property_id, pspec);
+      break;
+    }
+}
+
+static void
+gtk_strength_bar_class_init (GtkStrengthBarClass *klass)
+{
+  GObjectClass *oclass = G_OBJECT_CLASS (klass);
+  GtkWidgetClass *wclass = GTK_WIDGET_CLASS (klass);
+
+  oclass->get_property = gtk_strength_bar_get_property;
+  oclass->set_property = gtk_strength_bar_set_property;
+
+  wclass->draw = gtk_strength_bar_draw;
+  wclass->get_preferred_width = gtk_strength_bar_get_preferred_width;
+  wclass->get_preferred_height = gtk_strength_bar_get_preferred_height;
+
+  g_object_class_override_property (oclass, PROP_ORIENTATION, "orientation");
+
+  /**
+   * GtkStrengthBar:value:
+   *
+   * The #GtkStrengthBar:value property determines the currently
+   * filled value of the strength bar.
+   *
+   * Since: 3.6
+   */
+  properties[PROP_VALUE] =
+    g_param_spec_double ("value",
+                         P_("Currently filled value level"),
+                         P_("Currently filled value level of the strength bar"),
+                         0.0, G_MAXDOUBLE, 0.0,
+                         G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS);
+  /**
+   * GtkStrengthBar:min-value:
+   *
+   * The #GtkStrengthBar:min-value property determines the minimum value of
+   * the interval that can be displayed by the bar.
+   *
+   * Since: 3.6
+   */
+  properties[PROP_MIN_VALUE] =
+    g_param_spec_double ("min-value",
+                         P_("Minimum value level for the bar"),
+                         P_("Minimum value level that can be displayed by the bar"),
+                         0.0, G_MAXDOUBLE, 0.0,
+                         G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS);
+  /**
+   * GtkStrengthBar:critical-value:
+   *
+   * The #GtkStrengthBar:critical-value property determines
+   * the value below which the bar displays in a critical state.
+   * If this property is set to a value above the one specified by
+   * #GtkStrengthBar:strong-value or #GtkStrengthBar:warning-value,
+   * that will automatically be set to the same.
+   *
+   * Since: 3.6
+   */
+  properties[PROP_CRITICAL_VALUE] =
+    g_param_spec_double ("critical-value",
+                         P_("Value level for the critical state"),
+                         P_("Value level below which the bar is treated in a critical state"),
+                         0.0, G_MAXDOUBLE, 0.10,
+                         G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS);
+  /**
+   * GtkStrengthBar:warning-value:
+   *
+   * The #GtkStrengthBar:warning-value property determines
+   * the value below which the bar displays in a warning state.
+   * If this property is set to a value above the one specified by
+   * #GtkStrengthBar:strong-value, or below the one specified by
+   * #GtkStrengthBar:critical-value, that will automatically be set
+   * to the same.
+   *
+   * Since: 3.6
+   */
+  properties[PROP_WARNING_VALUE] =
+    g_param_spec_double ("warning-value",
+                         P_("Value level for the warning state"),
+                         P_("Value level below which the bar is treated in a warning state"),
+                         0.0, G_MAXDOUBLE, 0.25,
+                         G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS);
+  /**
+   * GtkStrengthBar:strong-value:
+   *
+   * The #GtkStrengthBar:strong-value property determines
+   * the value above which the bar displays in a strong state.
+   * If this property is set to a value below the one specified by
+   * #GtkStrengthBar:warning-value or #GtkStrengthBar:critical-value,
+   * that will automatically be set to the same.
+   *
+   * Since: 3.6
+   */
+  properties[PROP_STRONG_VALUE] =
+    g_param_spec_double ("strong-value",
+                         P_("Value level for the strong state"),
+                         P_("Value level above which the bar is treated as strong"),
+                         0.0, G_MAXDOUBLE, 0.75,
+                         G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS);
+  /**
+   * GtkStrengthBar:max-value:
+   *
+   * The #GtkStrengthBar:max-value property determaxes the maximum value of
+   * the interval that can be displayed by the bar.
+   *
+   * Since: 3.6
+   */
+  properties[PROP_MAX_VALUE] =
+    g_param_spec_double ("max-value",
+                         P_("Maximum value level for the bar"),
+                         P_("Maximum value level that can be displayed by the bar"),
+                         0.0, G_MAXDOUBLE, 1.0,
+                         G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS);
+  /**
+   * GtkStrengthBar:bar-style:
+   *
+   * The #GtkStrengthBar:bar-style property determines the way #GtkStrengthBar
+   * interprets the value properties to draw the level fill area.
+   * Specifically, when the value is #GTK_STRENGTH_BAR_STYLE_CONTINUOUS,
+   * #GtkStrengthBar will draw a single block representing the current value in
+   * that area; when the value is #GTK_STRENGTH_BAR_STYLE_DISCRETE,
+   * the widget will draw a succession of separate blocks filling the
+   * draw area, with the number of blocks being equal to the units separating
+   * the integral roundings of #GtkStrengthBar:min-value and #GtkStrengthBar:max-value.
+   *
+   * Since: 3.6
+   */
+  properties[PROP_BAR_STYLE] =
+    g_param_spec_enum ("bar-style",
+                       P_("The style of the value indicator"),
+                       P_("The style of the value indicator displayed by the bar"),
+                       GTK_TYPE_STRENGTH_BAR_STYLE,
+                       GTK_STRENGTH_BAR_STYLE_CONTINUOUS,
+                       G_PARAM_READWRITE);
+
+  gtk_widget_class_install_style_property 
+    (wclass, g_param_spec_int ("min-block-height",
+                               P_("Minimum height for filling blocks"),
+                               P_("Minimum height for blocks that fill the bar"),
+                               1, G_MAXINT, DEFAULT_BLOCK_SIZE,
+                               G_PARAM_READWRITE));
+  gtk_widget_class_install_style_property 
+    (wclass, g_param_spec_int ("min-block-width",
+                               P_("Minimum width for filling blocks"),
+                               P_("Minimum width for blocks that fill the bar"),
+                               1, G_MAXINT, DEFAULT_BLOCK_SIZE,
+                               G_PARAM_READWRITE));
+
+  g_type_class_add_private (klass, sizeof (GtkStrengthBarPrivate));
+  g_object_class_install_properties (oclass, LAST_PROPERTY, properties);
+}
+
+static void
+gtk_strength_bar_init (GtkStrengthBar *self)
+{
+  GtkStyleContext *context;
+
+  self->priv = G_TYPE_INSTANCE_GET_PRIVATE (self, GTK_TYPE_STRENGTH_BAR, GtkStrengthBarPrivate);
+
+  context = gtk_widget_get_style_context (GTK_WIDGET (self));
+  gtk_style_context_add_class (context, GTK_STYLE_CLASS_STRENGTH_BAR);
+
+  self->priv->cur_value = 0.0;
+  self->priv->min_value = 0.0;
+  self->priv->max_value = 1.0;
+
+  self->priv->critical_value = 0.10;
+  self->priv->warning_value = 0.25;
+  self->priv->strong_value = 0.75;
+
+  self->priv->bar_style = GTK_STRENGTH_BAR_STYLE_CONTINUOUS;
+  gtk_strength_bar_update_bar_style_classes (self);
+
+  /* set initial orientation and style classes */
+  self->priv->orientation = GTK_ORIENTATION_HORIZONTAL;
+  _gtk_orientable_set_style_classes (GTK_ORIENTABLE (self));
+
+  gtk_widget_set_has_window (GTK_WIDGET (self), FALSE);
+}
+
+/**
+ * gtk_strength_bar_new:
+ *
+ * Creates a new #GtkStrengthBar.
+ *
+ * Returns: a #GtkStrengthBar.
+ *
+ * Since: 3.6
+ */
+GtkWidget *
+gtk_strength_bar_new (void)
+{
+  return g_object_new (GTK_TYPE_STRENGTH_BAR, NULL);
+}
+
+/**
+ * gtk_strength_bar_get_min_value:
+ * @self: a #GtkStrengthBar
+ * 
+ * Returns the value of the #GtkStrengthBar:min-value property.
+ *
+ * Returns: a positive value
+ *
+ * Since: 3.6
+ */
+gdouble
+gtk_strength_bar_get_min_value (GtkStrengthBar *self)
+{
+  g_return_val_if_fail (GTK_IS_STRENGTH_BAR (self), 0.0);
+
+  return self->priv->min_value;
+}
+
+/**
+ * gtk_strength_bar_get_critical_value:
+ * @self: a #GtkStrengthBar
+ * 
+ * Returns the value of the #GtkStrengthBar:critical-value property.
+ *
+ * Returns: a value in the interval between
+ *     #GtkStrengthBar:min-value and #GtkStrengthBar:max-value
+ *
+ * Since: 3.6
+ */
+gdouble
+gtk_strength_bar_get_critical_value (GtkStrengthBar *self)
+{
+  g_return_val_if_fail (GTK_IS_STRENGTH_BAR (self), 0.0);
+
+  return self->priv->critical_value;
+}
+
+/**
+ * gtk_strength_bar_get_warning_value:
+ * @self: a #GtkStrengthBar
+ * 
+ * Returns the value of the #GtkStrengthBar:warning-value property.
+ *
+ * Returns: a value in the interval between
+ *     #GtkStrengthBar:min-value and #GtkStrengthBar:max-value
+ *
+ * Since: 3.6
+ */
+gdouble
+gtk_strength_bar_get_warning_value (GtkStrengthBar *self)
+{
+  g_return_val_if_fail (GTK_IS_STRENGTH_BAR (self), 0.0);
+
+  return self->priv->warning_value;
+}
+
+/**
+ * gtk_strength_bar_get_strong_value:
+ * @self: a #GtkStrengthBar
+ * 
+ * Returns the value of the #GtkStrengthBar:strong-value property.
+ *
+ * Returns: a value in the interval between
+ *     #GtkStrengthBar:min-value and #GtkStrengthBar:max-value
+ *
+ * Since: 3.6
+ */
+gdouble
+gtk_strength_bar_get_strong_value (GtkStrengthBar *self)
+{
+  g_return_val_if_fail (GTK_IS_STRENGTH_BAR (self), 0.0);
+
+  return self->priv->strong_value;
+}
+
+/**
+ * gtk_strength_bar_get_max_value:
+ * @self: a #GtkStrengthBar
+ * 
+ * Returns the value of the #GtkStrengthBar:max-value property.
+ *
+ * Returns: a positive value
+ *
+ * Since: 3.6
+ */
+gdouble
+gtk_strength_bar_get_max_value (GtkStrengthBar *self)
+{
+  g_return_val_if_fail (GTK_IS_STRENGTH_BAR (self), 0.0);
+
+  return self->priv->max_value;
+}
+
+/**
+ * gtk_strength_bar_get_value:
+ * @self: a #GtkStrengthBar
+ *
+ * Returns the value of the #GtkStrengthBar:value property.
+ *
+ * Returns: a value in the interval between
+ *     #GtkStrengthBar:min-value and #GtkStrengthBar:max-value
+ *
+ * Since: 3.6
+ */
+gdouble
+gtk_strength_bar_get_value (GtkStrengthBar *self)
+{
+  g_return_val_if_fail (GTK_IS_STRENGTH_BAR (self), 0.0);
+
+  return self->priv->cur_value;
+}
+
+static void
+gtk_strength_bar_set_value_internal (GtkStrengthBar *self,
+                                     gdouble         value)
+{
+  self->priv->cur_value = value;
+  g_object_notify_by_pspec (G_OBJECT (self), properties[PROP_VALUE]);
+  gtk_widget_queue_draw (GTK_WIDGET (self));
+}
+
+static void
+gtk_strength_bar_set_strong_value_internal (GtkStrengthBar *self,
+                                            gdouble         value)
+{
+  self->priv->strong_value = value;
+  g_object_notify_by_pspec (G_OBJECT (self), properties[PROP_STRONG_VALUE]);
+
+  if (self->priv->strong_value < self->priv->critical_value)
+    gtk_strength_bar_set_critical_value_internal (self, self->priv->strong_value);
+
+  if (self->priv->strong_value < self->priv->warning_value)
+    gtk_strength_bar_set_warning_value_internal (self, self->priv->strong_value);
+}
+
+static void
+gtk_strength_bar_set_warning_value_internal (GtkStrengthBar *self,
+                                             gdouble         value)
+{
+  self->priv->warning_value = value;
+  g_object_notify_by_pspec (G_OBJECT (self), properties[PROP_WARNING_VALUE]);
+
+  if (self->priv->warning_value < self->priv->critical_value)
+    gtk_strength_bar_set_critical_value_internal (self, self->priv->warning_value);
+
+  if (self->priv->warning_value > self->priv->strong_value)
+    gtk_strength_bar_set_strong_value_internal (self, self->priv->warning_value);
+}
+
+static void
+gtk_strength_bar_set_critical_value_internal (GtkStrengthBar *self,
+                                              gdouble         value)
+{
+  self->priv->critical_value = value;
+  g_object_notify_by_pspec (G_OBJECT (self), properties[PROP_CRITICAL_VALUE]);
+
+  if (self->priv->critical_value > self->priv->warning_value)
+    gtk_strength_bar_set_warning_value_internal (self, self->priv->critical_value);
+
+  if (self->priv->critical_value > self->priv->strong_value)
+    gtk_strength_bar_set_strong_value_internal (self, self->priv->critical_value);
+}
+
+/**
+ * gtk_strength_bar_set_min_value:
+ * @self: a #GtkStrengthBar
+ * @value: a positive value
+ * 
+ * Sets the value of the #GtkStrengthBar:min-value property.
+ *
+ * Since: 3.6
+ */
+void
+gtk_strength_bar_set_min_value (GtkStrengthBar *self,
+                                gdouble         value)
+{
+  g_return_if_fail (GTK_IS_STRENGTH_BAR (self));
+  g_return_if_fail (value >= 0.0);
+
+  if (value != self->priv->min_value)
+    {
+      self->priv->min_value = value;
+      g_object_notify_by_pspec (G_OBJECT (self), properties[PROP_MIN_VALUE]);
+
+      if (self->priv->min_value > self->priv->critical_value)
+        gtk_strength_bar_set_critical_value_internal (self, self->priv->min_value);
+
+      if (self->priv->min_value > self->priv->warning_value)
+        gtk_strength_bar_set_warning_value_internal (self, self->priv->min_value);
+
+      if (self->priv->min_value > self->priv->strong_value)
+        gtk_strength_bar_set_strong_value_internal (self, self->priv->min_value);
+
+      if (self->priv->min_value > self->priv->cur_value)
+        gtk_strength_bar_set_value_internal (self, self->priv->min_value);
+
+      gtk_strength_bar_update_level_style_classes (self);
+    }
+}
+
+/**
+ * gtk_strength_bar_set_critical_value:
+ * @self: a #GtkStrengthBar
+ * @value: a value in the interval between
+ *     #GtkStrengthBar:min-value and #GtkStrengthBar:max-value
+ * 
+ * Sets the value of the #GtkStrengthBar:critical-value property.
+ *
+ * Since: 3.6
+ */
+void
+gtk_strength_bar_set_critical_value (GtkStrengthBar *self,
+                                     gdouble         value)
+{
+  g_return_if_fail (GTK_IS_STRENGTH_BAR (self));
+  g_return_if_fail (gtk_strength_bar_value_in_interval (self, value));
+
+  if (value != self->priv->critical_value)
+    {
+      gtk_strength_bar_set_critical_value_internal (self, value);
+      gtk_strength_bar_update_level_style_classes (self);
+    }
+}
+
+/**
+ * gtk_strength_bar_set_warning_value:
+ * @self: a #GtkStrengthBar
+ * @value: a value in the interval between
+ *     #GtkStrengthBar:min-value and #GtkStrengthBar:max-value
+ * 
+ * Sets the value of the #GtkStrengthBar:warning-value property.
+ *
+ * Since: 3.6
+ */
+void
+gtk_strength_bar_set_warning_value (GtkStrengthBar *self,
+                                    gdouble         value)
+{
+  g_return_if_fail (GTK_IS_STRENGTH_BAR (self));
+  g_return_if_fail (gtk_strength_bar_value_in_interval (self, value));
+
+  if (value != self->priv->warning_value)
+    {
+      gtk_strength_bar_set_warning_value_internal (self, value);
+      gtk_strength_bar_update_level_style_classes (self);
+    }
+}
+
+/**
+ * gtk_strength_bar_set_strong_value:
+ * @self: a #GtkStrengthBar
+ * @value: a value in the interval between
+ *     #GtkStrengthBar:min-value and #GtkStrengthBar:max-value
+ * 
+ * Sets the value of the #GtkStrengthBar:strong-value property.
+ *
+ * Since: 3.6
+ */
+void
+gtk_strength_bar_set_strong_value (GtkStrengthBar *self,
+                                   gdouble         value)
+{
+  g_return_if_fail (GTK_IS_STRENGTH_BAR (self));
+  g_return_if_fail (gtk_strength_bar_value_in_interval (self, value));
+
+  if (value != self->priv->strong_value)
+    {
+      gtk_strength_bar_set_strong_value_internal (self, value);
+      gtk_strength_bar_update_level_style_classes (self);
+    }
+}
+
+/**
+ * gtk_strength_bar_set_max_value:
+ * @self: a #GtkStrengthBar
+ * @value: a positive value
+ * 
+ * Sets the value of the #GtkStrengthBar:max-value property.
+ *
+ * Since: 3.6
+ */
+void
+gtk_strength_bar_set_max_value (GtkStrengthBar *self,
+                                gdouble         value)
+{
+  g_return_if_fail (GTK_IS_STRENGTH_BAR (self));
+  g_return_if_fail (value >= 0.0);
+
+  if (value != self->priv->max_value)
+    {
+      self->priv->max_value = value;
+      g_object_notify_by_pspec (G_OBJECT (self), properties[PROP_MAX_VALUE]);
+
+      if (self->priv->max_value < self->priv->critical_value)
+        gtk_strength_bar_set_critical_value_internal (self, self->priv->max_value);
+
+      if (self->priv->max_value < self->priv->warning_value)
+        gtk_strength_bar_set_warning_value_internal (self, self->priv->max_value);
+
+      if (self->priv->max_value < self->priv->strong_value)
+        gtk_strength_bar_set_strong_value_internal (self, self->priv->max_value);
+
+      if (self->priv->max_value < self->priv->cur_value)
+        gtk_strength_bar_set_value_internal (self, self->priv->max_value);
+
+      gtk_strength_bar_update_level_style_classes (self);
+    }
+}
+
+/**
+ * gtk_strength_bar_set_value:
+ * @self: a #GtkStrengthBar
+ * @value: a value in the interval between
+ *     #GtkStrengthBar:min-value and #GtkStrengthBar:max-value
+ *
+ * Sets the value of the #GtkStrengthBar:value property.
+ *
+ * Since: 3.6
+ */
+void
+gtk_strength_bar_set_value (GtkStrengthBar *self,
+                            gdouble         value)
+{
+  g_return_if_fail (GTK_IS_STRENGTH_BAR (self));
+
+  if (value != self->priv->cur_value)
+    {
+      gtk_strength_bar_set_value_internal (self, value);
+      gtk_strength_bar_update_level_style_classes (self);
+    }
+}
+
+/**
+ * gtk_strength_bar_get_bar_style:
+ * @self: a #GtkStrengthBar
+ *
+ * Returns the value of the #GtkStrengthBar:bar-style property
+ *
+ * Returns: a #GtkStrengthBarStyle
+ */
+GtkStrengthBarStyle
+gtk_strength_bar_get_bar_style (GtkStrengthBar *self)
+{
+  g_return_val_if_fail (GTK_IS_STRENGTH_BAR (self), 0);
+
+  return self->priv->bar_style;
+}
+
+/**
+ * gtk_strength_bar_set_bar_style:
+ * @self: a #GtkStrengthBar
+ * @bar_style: a #GtkStrengthBarStyle
+ *
+ * Sets the value of the #GtkStrengthBar:bar-style property
+ */
+void
+gtk_strength_bar_set_bar_style (GtkStrengthBar      *self,
+                                GtkStrengthBarStyle  bar_style)
+{
+  g_return_if_fail (GTK_IS_STRENGTH_BAR (self));
+
+  if (self->priv->bar_style != bar_style)
+    {
+      self->priv->bar_style = bar_style;
+      g_object_notify_by_pspec (G_OBJECT (self), properties[PROP_BAR_STYLE]);
+
+      gtk_strength_bar_update_bar_style_classes (self);
+      gtk_widget_queue_resize (GTK_WIDGET (self));
+    }
+}
diff --git a/gtk/gtkstrengthbar.h b/gtk/gtkstrengthbar.h
new file mode 100644
index 0000000..349bbb0
--- /dev/null
+++ b/gtk/gtkstrengthbar.h
@@ -0,0 +1,108 @@
+/* GTK - The GIMP Toolkit
+ * Copyright  2012 Red Hat, Inc.
+ *
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * version 2 of the License, or (at your option) any later version.
+ *
+ * This library 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
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this library. If not, see <http://www.gnu.org/licenses/>.
+ *
+ * Author: Cosimo Cecchi <cosimoc gnome org>
+ *
+ */
+
+#if !defined (__GTK_H_INSIDE__) && !defined (GTK_COMPILATION)
+#error "Only <gtk/gtk.h> can be included directly."
+#endif
+
+#ifndef __GTK_STRENGTH_BAR_H__
+#define __GTK_STRENGTH_BAR_H__
+
+#include <gtk/gtkwidget.h>
+
+G_BEGIN_DECLS
+
+#define GTK_TYPE_STRENGTH_BAR            (gtk_strength_bar_get_type ())
+#define GTK_STRENGTH_BAR(obj)            (G_TYPE_CHECK_INSTANCE_CAST ((obj), GTK_TYPE_STRENGTH_BAR, GtkStrengthBar))
+#define GTK_STRENGTH_BAR_CLASS(klass)    (G_TYPE_CHECK_CLASS_CAST ((klass), GTK_TYPE_STRENGTH_BAR, GtkStrengthBarClass))
+#define GTK_IS_STRENGTH_BAR(obj)         (G_TYPE_CHECK_INSTANCE_TYPE ((obj), GTK_TYPE_STRENGTH_BAR))
+#define GTK_IS_STRENGTH_BAR_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE ((klass), GTK_TYPE_STRENGTH_BAR))
+#define GTK_STRENGTH_BAR_GET_CLASS(obj)  (G_TYPE_INSTANCE_GET_CLASS ((obj), GTK_TYPE_STRENGTH_BAR, GtkStrengthBarClass))
+
+typedef struct _GtkStrengthBarClass GtkStrengthBarClass;
+typedef struct _GtkStrengthBar GtkStrengthBar;
+typedef struct _GtkStrengthBarPrivate GtkStrengthBarPrivate;
+
+struct _GtkStrengthBar {
+  /*< private >*/
+  GtkWidget parent;
+
+  GtkStrengthBarPrivate *priv;
+};
+
+struct _GtkStrengthBarClass {
+  /*< private >*/
+  GtkWidgetClass parent_class;
+
+  /* padding for future class expansion */
+  gpointer padding[16];
+};
+
+GDK_AVAILABLE_IN_3_6
+GType      gtk_strength_bar_get_type             (void) G_GNUC_CONST;
+
+GDK_AVAILABLE_IN_3_6
+GtkWidget *gtk_strength_bar_new                  (void);
+
+GDK_AVAILABLE_IN_3_6
+void       gtk_strength_bar_set_bar_style      (GtkStrengthBar *self,
+                                                GtkStrengthBarStyle bar_style);
+GDK_AVAILABLE_IN_3_6
+GtkStrengthBarStyle gtk_strength_bar_get_bar_style (GtkStrengthBar *self);
+
+GDK_AVAILABLE_IN_3_6
+void       gtk_strength_bar_set_value          (GtkStrengthBar *self,
+                                                gdouble         value);
+GDK_AVAILABLE_IN_3_6
+gdouble    gtk_strength_bar_get_value          (GtkStrengthBar *self);
+
+GDK_AVAILABLE_IN_3_6
+void       gtk_strength_bar_set_min_value      (GtkStrengthBar *self,
+                                                gdouble         value);
+GDK_AVAILABLE_IN_3_6
+gdouble    gtk_strength_bar_get_min_value      (GtkStrengthBar *self);
+
+GDK_AVAILABLE_IN_3_6
+void       gtk_strength_bar_set_warning_value  (GtkStrengthBar *self,
+                                                gdouble         value);
+GDK_AVAILABLE_IN_3_6
+gdouble    gtk_strength_bar_get_warning_value  (GtkStrengthBar *self);
+
+GDK_AVAILABLE_IN_3_6
+void       gtk_strength_bar_set_critical_value (GtkStrengthBar *self,
+                                                gdouble         value);
+GDK_AVAILABLE_IN_3_6
+gdouble    gtk_strength_bar_get_critical_value (GtkStrengthBar *self);
+
+GDK_AVAILABLE_IN_3_6
+void       gtk_strength_bar_set_strong_value   (GtkStrengthBar *self,
+                                                gdouble         value);
+GDK_AVAILABLE_IN_3_6
+gdouble    gtk_strength_bar_get_strong_value   (GtkStrengthBar *self);
+
+GDK_AVAILABLE_IN_3_6
+void       gtk_strength_bar_set_max_value      (GtkStrengthBar *self,
+                                                gdouble         value);
+GDK_AVAILABLE_IN_3_6
+gdouble    gtk_strength_bar_get_max_value      (GtkStrengthBar *self);
+
+G_END_DECLS
+
+#endif /* __GTK_STRENGTH_BAR_H__ */
diff --git a/gtk/gtkstylecontext.h b/gtk/gtkstylecontext.h
index 4975862..651a482 100644
--- a/gtk/gtkstylecontext.h
+++ b/gtk/gtkstylecontext.h
@@ -691,6 +691,43 @@ struct _GtkStyleContextClass
  */
 #define GTK_STYLE_CLASS_OSD "osd"
 
+/**
+ * GTK_STYLE_CLASS_STRENGTH_BAR:
+ *
+ * A CSS class used when rendering a strength indicator, such
+ * as a battery charge level, or a password strength.
+ *
+ * This is used by #GtkStrengthBar.
+ */
+#define GTK_STYLE_CLASS_STRENGTH_BAR "strength-bar"
+
+/**
+ * GTK_STYLE_CLASS_LEVEL_CRITICAL:
+ *
+ * A CSS class used when the level is in a critical low state.
+ * 
+ * This is used by #GtkStrengthBar.
+ */
+#define GTK_STYLE_CLASS_LEVEL_CRITICAL "level-critical"
+
+/**
+ * GTK_STYLE_CLASS_LEVEL_WARNING:
+ *
+ * A CSS class used when the level is in a critical low state.
+ * 
+ * This is used by #GtkStrengthBar.
+ */
+#define GTK_STYLE_CLASS_LEVEL_WARNING "level-warning"
+
+/**
+ * GTK_STYLE_CLASS_LEVEL_STRONG:
+ *
+ * A CSS class used when the level is in a strong high state.
+ * 
+ * This is used by #GtkStrengthBar.
+ */
+#define GTK_STYLE_CLASS_LEVEL_STRONG "level-strong"
+
 /* Predefined set of widget regions */
 
 /**



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