122 lines
3.2 KiB
C
122 lines
3.2 KiB
C
/*
|
|
* 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.
|
|
*/
|
|
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 * self, const GValue * value)
|
|
{
|
|
GValue new_value = G_VALUE_INIT;
|
|
gvn_value_to_format_string (value, self->format, &new_value);
|
|
gtk_label_set_text (self->label, g_value_get_string (&new_value));
|
|
g_value_unset (&new_value);
|
|
}
|
|
|
|
//+++++++++++++++++++++++++++++++++++++++++++++++++++ Properties
|
|
|
|
enum
|
|
{
|
|
PROP_FORMAT = 1
|
|
};
|
|
|
|
static void vn_label_set_property (VnLabel * self, guint id,
|
|
const GValue * value, GParamSpec * pspec)
|
|
{
|
|
switch (id)
|
|
{
|
|
case PROP_FORMAT:
|
|
g_free (self->format);
|
|
self->format = g_value_dup_string (value);
|
|
break;
|
|
default:
|
|
G_OBJECT_WARN_INVALID_PROPERTY_ID (self, id, pspec);
|
|
}
|
|
}
|
|
|
|
static void vn_label_get_property (VnLabel * self, guint id,
|
|
GValue * value, GParamSpec * pspec)
|
|
{
|
|
switch (id)
|
|
{
|
|
case PROP_FORMAT:
|
|
g_value_set_string (value, self->format);
|
|
break;
|
|
default:
|
|
G_OBJECT_WARN_INVALID_PROPERTY_ID (self, id, pspec);
|
|
}
|
|
}
|
|
|
|
//+++++++++++++++++++++++++++++++++++++++++++++++++++ Class
|
|
|
|
static void vn_label_init (VnLabel * self)
|
|
{
|
|
self->format = NULL;
|
|
self->label = GTK_LABEL (gtk_label_new (""));
|
|
gtk_misc_set_alignment (GTK_MISC (self->label), 0, 0.5);
|
|
gtk_widget_show (GTK_WIDGET (self->label));
|
|
gtk_container_add (GTK_CONTAINER (self), GTK_WIDGET (self->label));
|
|
|
|
VN_FIELD_GET_CLASS (self)->set_widget (VN_FIELD (self),
|
|
GTK_WIDGET (self->label));
|
|
}
|
|
|
|
static void vn_label_finalize (VnLabel * self)
|
|
{
|
|
g_free (self->format);
|
|
G_OBJECT_CLASS (vn_label_parent_class)->finalize (G_OBJECT (self));
|
|
}
|
|
|
|
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
|
|
));
|
|
}
|