2014-02-21 10:20:28 +00:00
|
|
|
/*
|
|
|
|
* Copyright (C) 2012 - Juan Ferrer Toribio
|
|
|
|
*
|
|
|
|
* 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 "vn-label.h"
|
|
|
|
|
|
|
|
/**
|
|
|
|
* SECTION:vn-label
|
|
|
|
* @Short_description: a text label widget
|
|
|
|
* @Title: VnLabel
|
|
|
|
* @See_also: #VnField
|
|
|
|
*
|
|
|
|
* A label representing a generic value field.
|
2014-07-10 10:12:48 +00:00
|
|
|
*/
|
2014-02-21 10:20:28 +00:00
|
|
|
G_DEFINE_TYPE (VnLabel, vn_label, VN_TYPE_FIELD);
|
|
|
|
|
|
|
|
/**
|
|
|
|
* vn_label_new:
|
|
|
|
*
|
|
|
|
* Creates a new #VnLabel
|
|
|
|
*
|
|
|
|
* Return value:a #VnLabel
|
|
|
|
**/
|
|
|
|
VnField * vn_label_new ()
|
|
|
|
{
|
|
|
|
return g_object_new (VN_TYPE_LABEL, NULL);
|
|
|
|
}
|
|
|
|
|
|
|
|
//+++++++++++++++++++++++++++++++++++++++++++++++++++ Private
|
|
|
|
|
|
|
|
static void vn_label_set_value (VnLabel * obj, const GValue * value)
|
|
|
|
{
|
|
|
|
GValue new_value = G_VALUE_INIT;
|
|
|
|
gvn_value_to_format_string (value, obj->format, &new_value);
|
|
|
|
gtk_label_set_text (obj->label, g_value_get_string (&new_value));
|
|
|
|
g_value_unset (&new_value);
|
|
|
|
}
|
|
|
|
|
|
|
|
//+++++++++++++++++++++++++++++++++++++++++++++++++++ Properties
|
|
|
|
|
|
|
|
enum
|
|
|
|
{
|
|
|
|
PROP_FORMAT = 1
|
|
|
|
};
|
|
|
|
|
|
|
|
static void vn_label_set_property (VnLabel * obj, guint id,
|
|
|
|
const GValue * value, GParamSpec * pspec)
|
|
|
|
{
|
|
|
|
switch (id)
|
|
|
|
{
|
|
|
|
case PROP_FORMAT:
|
|
|
|
g_free (obj->format);
|
|
|
|
obj->format = g_value_dup_string (value);
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
G_OBJECT_WARN_INVALID_PROPERTY_ID (obj, id, pspec);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
static void vn_label_get_property (VnLabel * obj, guint id,
|
|
|
|
GValue * value, GParamSpec * pspec)
|
|
|
|
{
|
|
|
|
switch (id)
|
|
|
|
{
|
|
|
|
case PROP_FORMAT:
|
|
|
|
g_value_set_string (value, obj->format);
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
G_OBJECT_WARN_INVALID_PROPERTY_ID (obj, id, pspec);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
//+++++++++++++++++++++++++++++++++++++++++++++++++++ Class
|
|
|
|
|
|
|
|
static void vn_label_init (VnLabel * obj)
|
|
|
|
{
|
|
|
|
obj->format = NULL;
|
|
|
|
obj->label = GTK_LABEL (gtk_label_new (""));
|
2014-07-10 10:12:48 +00:00
|
|
|
gtk_misc_set_alignment (GTK_MISC (obj->label), 0, 0.5);
|
|
|
|
gtk_widget_show (GTK_WIDGET (obj->label));
|
2014-02-21 10:20:28 +00:00
|
|
|
gtk_container_add (GTK_CONTAINER (obj), GTK_WIDGET (obj->label));
|
|
|
|
|
|
|
|
VN_FIELD (obj)->field = GTK_WIDGET (obj->label);
|
|
|
|
}
|
|
|
|
|
|
|
|
static void vn_label_finalize (VnLabel * obj)
|
|
|
|
{
|
|
|
|
g_free (obj->format);
|
|
|
|
G_OBJECT_CLASS (vn_label_parent_class)->finalize (G_OBJECT (obj));
|
|
|
|
}
|
|
|
|
|
|
|
|
static void vn_label_class_init (VnLabelClass * klass)
|
|
|
|
{
|
|
|
|
GObjectClass * k = G_OBJECT_CLASS (klass);
|
|
|
|
k->set_property = (GObjectSetPropertyFunc) vn_label_set_property;
|
|
|
|
k->get_property = (GObjectGetPropertyFunc) vn_label_get_property;
|
|
|
|
k->finalize = (GObjectFinalizeFunc) vn_label_finalize;
|
|
|
|
VN_FIELD_CLASS (klass)->set_value = (VnFieldSetValueFunc) vn_label_set_value;
|
|
|
|
|
|
|
|
g_object_class_install_property (k, PROP_FORMAT,
|
|
|
|
g_param_spec_string ("format"
|
|
|
|
,_("Format")
|
|
|
|
,_("The format string describing the output of the entry.")
|
|
|
|
,NULL
|
|
|
|
,G_PARAM_CONSTRUCT | G_PARAM_READWRITE
|
|
|
|
));
|
|
|
|
}
|