Commit d5a2961a authored by Juan Pablo Ugarte's avatar Juan Pablo Ugarte

GladeEPropBool: Removed GladeBoolToggle and replaced with plain old good GtkSwitch.

parent 563e3a34
......@@ -100,8 +100,7 @@ libgladeui_2_la_SOURCES = \
glade-displayable-values.c \
glade-signal-model.c \
glade-cell-renderer-icon.c \
glade-preview.c \
glade-bool-toggle.c
glade-preview.c
libgladeui_2_la_CPPFLAGS = \
$(common_defines) \
......@@ -165,8 +164,7 @@ noinst_HEADERS = \
glade-design-private.h \
glade-preview-tokens.h \
glade-preview.h \
glade-path.h \
glade-bool-toggle.h
glade-path.h
if PLATFORM_WIN32
libgladeui_2_la_LDFLAGS += -no-undefined
......
/*
* glade-bool-toggle.h
*
* Copyright (C) 2013 Juan Pablo Ugarte <juanpablougarte@gmail.com>
*
* Authors:
* Juan Pablo Ugarte <juanpablougarte@gmail.com>
*
* 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 2 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, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
*/
#ifdef HAVE_CONFIG_H
#include <config.h>
#endif
#include "glade-bool-toggle.h"
#include <glib/gi18n-lib.h>
enum
{
PROP_0,
PROP_TRUE_STRING,
PROP_FALSE_STRING
};
struct _GladeBoolTogglePrivate
{
gchar *true_string;
gchar *false_string;
};
#define GLADE_BOOL_TOGGLE_GET_PRIVATE(object) (G_TYPE_INSTANCE_GET_PRIVATE ((object), \
GLADE_TYPE_BOOL_TOGGLE, \
GladeBoolTogglePrivate))
#define GLADE_BOOL_TOGGLE_PRIVATE(object) (((GladeBoolToggle*)object)->priv)
G_DEFINE_TYPE (GladeBoolToggle, glade_bool_toggle, GTK_TYPE_TOGGLE_BUTTON);
/* translators: This is the string used in boolean property editor toggle button when is active */
#define TRUE_STRING _("<span color='green'>✓</span>True")
/* translators: This is the string used in boolean property editor toggle button when is not active */
#define FALSE_STRING _("<span color='red'>✗</span>False")
static void
glade_bool_toggle_init (GladeBoolToggle *toggle)
{
GladeBoolTogglePrivate *priv = GLADE_BOOL_TOGGLE_GET_PRIVATE (toggle);
GtkWidget *label = gtk_label_new ("");
toggle->priv = priv;
priv->true_string = g_strdup (TRUE_STRING);
priv->false_string = g_strdup (FALSE_STRING);
gtk_label_set_markup (GTK_LABEL (label), priv->false_string);
gtk_container_add (GTK_CONTAINER (toggle), label);
gtk_widget_show (label);
}
static void
glade_bool_toggle_finalize (GObject *object)
{
G_OBJECT_CLASS (glade_bool_toggle_parent_class)->finalize (object);
}
static gint
layout_get_value (PangoLayout *layout, const gchar *string)
{
PangoRectangle rect;
pango_layout_set_markup (layout, string, -1);
pango_layout_get_extents (layout, NULL, &rect);
pango_extents_to_pixels (&rect, NULL);
return rect.width;
}
static void
glade_bool_toggle_get_preferred_width (GtkWidget *widget,
gint *minimum,
gint *natural)
{
GladeBoolTogglePrivate *priv = GLADE_BOOL_TOGGLE_PRIVATE (widget);
PangoLayout *layout = gtk_widget_create_pango_layout (widget, "");
GtkWidget *label = gtk_bin_get_child (GTK_BIN (widget));
gint value, width, true_width, false_width;
GTK_WIDGET_CLASS (glade_bool_toggle_parent_class)->get_preferred_width (widget, &width, NULL);
true_width = layout_get_value (layout, priv->true_string);
false_width = layout_get_value (layout, priv->false_string);
if (g_strcmp0 (gtk_label_get_label (GTK_LABEL (label)), priv->true_string))
value = width - false_width;
else
value = width - true_width;
value += MAX (true_width, false_width);
g_object_unref (layout);
if (minimum)
*minimum = value;
if (natural)
*natural = value;
}
static void
glade_bool_toggle_toggled (GtkToggleButton *toggle_button)
{
GladeBoolTogglePrivate *priv = GLADE_BOOL_TOGGLE_PRIVATE (toggle_button);
GtkWidget *label = gtk_bin_get_child (GTK_BIN (toggle_button));
if (GTK_IS_LABEL (label))
{
if (gtk_toggle_button_get_active (toggle_button))
gtk_label_set_markup (GTK_LABEL (label), priv->true_string);
else
gtk_label_set_markup (GTK_LABEL (label), priv->false_string);
}
}
static void
glade_bool_toggle_set_property (GObject *object,
guint prop_id,
const GValue *value,
GParamSpec *pspec)
{
GladeBoolTogglePrivate *priv = GLADE_BOOL_TOGGLE_PRIVATE (object);
switch (prop_id)
{
case PROP_TRUE_STRING:
g_free (priv->true_string);
priv->true_string = g_value_dup_string (value);
glade_bool_toggle_toggled (GTK_TOGGLE_BUTTON (object));
break;
case PROP_FALSE_STRING:
g_free (priv->false_string);
priv->false_string = g_value_dup_string (value);
glade_bool_toggle_toggled (GTK_TOGGLE_BUTTON (object));
break;
default:
G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
break;
}
}
static void
glade_bool_toggle_get_property (GObject *object,
guint prop_id,
GValue *value,
GParamSpec *pspec)
{
GladeBoolTogglePrivate *priv = GLADE_BOOL_TOGGLE_PRIVATE (object);
switch (prop_id)
{
case PROP_TRUE_STRING:
g_value_set_string (value, priv->true_string);
break;
case PROP_FALSE_STRING:
g_value_set_string (value, priv->false_string);
break;
default:
G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
break;
}
}
static void
glade_bool_toggle_class_init (GladeBoolToggleClass *klass)
{
GObjectClass *object_class = G_OBJECT_CLASS (klass);
GtkWidgetClass *widget_class = GTK_WIDGET_CLASS (klass);
GtkToggleButtonClass *toggle_class = GTK_TOGGLE_BUTTON_CLASS (klass);
object_class->get_property = glade_bool_toggle_get_property;
object_class->set_property = glade_bool_toggle_set_property;
object_class->finalize = glade_bool_toggle_finalize;
widget_class->get_preferred_width = glade_bool_toggle_get_preferred_width;
toggle_class->toggled = glade_bool_toggle_toggled;
g_object_class_install_property (object_class, PROP_TRUE_STRING,
g_param_spec_string ("true-string", "True string",
"String to use when toggled",
TRUE_STRING,
G_PARAM_READWRITE));
g_object_class_install_property (object_class, PROP_FALSE_STRING,
g_param_spec_string ("false-string", "False string",
"String to use when not toggled",
FALSE_STRING,
G_PARAM_READWRITE));
g_type_class_add_private (object_class, sizeof (GladeBoolTogglePrivate));
}
GtkWidget *
_glade_bool_toggle_new (void)
{
return g_object_new (GLADE_TYPE_BOOL_TOGGLE, NULL);
}
/*
* glade-bool-toggle.h
*
* Copyright (C) 2013 Juan Pablo Ugarte <juanpablougarte@gmail.com>
*
* Authors:
* Juan Pablo Ugarte <juanpablougarte@gmail.com>
*
* 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 2 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, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
*/
#ifndef _GLADE_BOOL_TOGGLE_H_
#define _GLADE_BOOL_TOGGLE_H_
#include <gtk/gtk.h>
G_BEGIN_DECLS
#define GLADE_TYPE_BOOL_TOGGLE (glade_bool_toggle_get_type ())
#define GLADE_BOOL_TOGGLE(obj) (G_TYPE_CHECK_INSTANCE_CAST ((obj), GLADE_TYPE_BOOL_TOGGLE, GladeBoolToggle))
#define GLADE_BOOL_TOGGLE_CLASS(klass) (G_TYPE_CHECK_CLASS_CAST ((klass), GLADE_TYPE_BOOL_TOGGLE, GladeBoolToggleClass))
#define GLADE_IS_BOOL_TOGGLE(obj) (G_TYPE_CHECK_INSTANCE_TYPE ((obj), GLADE_TYPE_BOOL_TOGGLE))
#define GLADE_IS_BOOL_TOGGLE_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE ((klass), GLADE_TYPE_BOOL_TOGGLE))
#define GLADE_BOOL_TOGGLE_GET_CLASS(obj) (G_TYPE_INSTANCE_GET_CLASS ((obj), GLADE_TYPE_BOOL_TOGGLE, GladeBoolToggleClass))
typedef struct _GladeBoolToggle GladeBoolToggle;
typedef struct _GladeBoolTogglePrivate GladeBoolTogglePrivate;
typedef struct _GladeBoolToggleClass GladeBoolToggleClass;
struct _GladeBoolToggleClass
{
GtkToggleButtonClass parent_class;
};
struct _GladeBoolToggle
{
GtkToggleButton parent_instance;
GladeBoolTogglePrivate *priv;
};
GType glade_bool_toggle_get_type (void) G_GNUC_CONST;
GtkWidget *_glade_bool_toggle_new (void);
G_END_DECLS
#endif /* _GLADE_BOOL_TOGGLE_H_ */
......@@ -49,7 +49,6 @@
#include "glade-marshallers.h"
#include "glade-displayable-values.h"
#include "glade-named-icon-chooser-dialog.h"
#include "glade-bool-toggle.h"
enum
{
......@@ -2303,7 +2302,7 @@ glade_eprop_bool_load (GladeEditorProperty *eprop, GladeProperty *property)
{
GladeEPropBool *eprop_bool = GLADE_EPROP_BOOL (eprop);
gboolean state = g_value_get_boolean (glade_property_inline_value (property));
gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON (eprop_bool->button), state);
gtk_switch_set_active (GTK_SWITCH (eprop_bool->button), state);
}
}
......@@ -2318,7 +2317,7 @@ glade_eprop_bool_active_notify (GObject *gobject,
return;
g_value_init (&val, G_TYPE_BOOLEAN);
g_value_set_boolean (&val, gtk_toggle_button_get_active (GTK_TOGGLE_BUTTON (gobject)));
g_value_set_boolean (&val, gtk_switch_get_active (GTK_SWITCH (gobject)));
glade_editor_property_commit_no_callback (eprop, &val);
......@@ -2330,7 +2329,7 @@ glade_eprop_bool_create_input (GladeEditorProperty *eprop)
{
GladeEPropBool *eprop_bool = GLADE_EPROP_BOOL (eprop);
eprop_bool->button = _glade_bool_toggle_new ();
eprop_bool->button = gtk_switch_new ();
gtk_widget_set_halign (eprop_bool->button, GTK_ALIGN_START);
gtk_widget_set_valign (eprop_bool->button, GTK_ALIGN_CENTER);
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment