From 1bb7ef1bb0de88d6a8537a2ae39218a69bc49858 Mon Sep 17 00:00:00 2001 From: Andrea Zagli Date: Thu, 26 Nov 2015 19:24:38 +0100 Subject: [PATCH] Added ZakFormGtkFormElementLabel. --- src/Makefile.am | 6 +- src/formelementlabel.c | 171 +++++++++++++++++++++++++++++++++++++++++ src/formelementlabel.h | 60 +++++++++++++++ src/libzakformgtk.h | 1 + 4 files changed, 236 insertions(+), 2 deletions(-) create mode 100644 src/formelementlabel.c create mode 100644 src/formelementlabel.h diff --git a/src/Makefile.am b/src/Makefile.am index ca9cbe1..46fc12e 100644 --- a/src/Makefile.am +++ b/src/Makefile.am @@ -10,7 +10,8 @@ libzakformgtk_la_SOURCES = \ form.c \ formelement.c \ formelementcheck.c \ - formelemententry.c + formelemententry.c \ + formelementlabel.c libzakformgtk_la_LDFLAGS = -no-undefined @@ -19,6 +20,7 @@ libzakformgtk_include_HEADERS = \ form.h \ formelement.h \ formelementcheck.h \ - formelemententry.h + formelemententry.h \ + formelementlabel.h libzakformgtk_includedir = $(includedir)/libzakformgtk diff --git a/src/formelementlabel.c b/src/formelementlabel.c new file mode 100644 index 0000000..f8ddc41 --- /dev/null +++ b/src/formelementlabel.c @@ -0,0 +1,171 @@ +/* + * Copyright (C) 2015 Andrea Zagli + * + * 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.1 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, write to the Free Software + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA + */ + +#ifdef HAVE_CONFIG_H + #include +#endif + +#include "formelementlabel.h" + +static void zak_form_gtk_form_element_label_class_init (ZakFormGtkFormElementLabelClass *class); +static void zak_form_gtk_form_element_label_init (ZakFormGtkFormElementLabel *zak_form_gtk_form_element_label); + +static void zak_form_gtk_form_element_label_set_property (GObject *object, + guint property_id, + const GValue *value, + GParamSpec *pspec); +static void zak_form_gtk_form_element_label_get_property (GObject *object, + guint property_id, + GValue *value, + GParamSpec *pspec); + +static void zak_form_gtk_form_element_label_dispose (GObject *gobject); +static void zak_form_gtk_form_element_label_finalize (GObject *gobject); + +static gchar *zak_form_gtk_form_element_label_get_value (ZakFormGtkFormElementLabel *element); +static gboolean zak_form_gtk_form_element_label_set_value (ZakFormGtkFormElementLabel *element, const gchar *value); + +#define ZAK_FORM_GTK_FORM_ELEMENT_LABEL_GET_PRIVATE(obj) (G_TYPE_INSTANCE_GET_PRIVATE ((obj), ZAK_FORM_GTK_TYPE_FORM_ELEMENT_LABEL, ZakFormGtkFormElementLabelPrivate)) + +typedef struct _ZakFormGtkFormElementLabelPrivate ZakFormGtkFormElementLabelPrivate; +struct _ZakFormGtkFormElementLabelPrivate + { + gpointer empty; + }; + +G_DEFINE_TYPE (ZakFormGtkFormElementLabel, zak_form_gtk_form_element_label, ZAK_FORM_GTK_TYPE_FORM_ELEMENT) + +static void +zak_form_gtk_form_element_label_class_init (ZakFormGtkFormElementLabelClass *klass) +{ + GObjectClass *object_class = G_OBJECT_CLASS (klass); + ZakFormElementClass *elem_class = ZAK_FORM_ELEMENT_CLASS (klass); + + object_class->set_property = zak_form_gtk_form_element_label_set_property; + object_class->get_property = zak_form_gtk_form_element_label_get_property; + object_class->dispose = zak_form_gtk_form_element_label_dispose; + object_class->finalize = zak_form_gtk_form_element_label_finalize; + + elem_class->get_value = zak_form_gtk_form_element_label_get_value; + elem_class->set_value = zak_form_gtk_form_element_label_set_value; + + g_type_class_add_private (object_class, sizeof (ZakFormGtkFormElementLabelPrivate)); +} + +static void +zak_form_gtk_form_element_label_init (ZakFormGtkFormElementLabel *zak_form_gtk_form_element_label) +{ + ZakFormGtkFormElementLabelPrivate *priv = ZAK_FORM_GTK_FORM_ELEMENT_LABEL_GET_PRIVATE (zak_form_gtk_form_element_label); + +} + +/** + * zak_form_gtk_form_element_label_new: + * + * Returns: the newly created #ZakFormGtkFormElementLabel object. + */ +ZakFormGtkFormElement +*zak_form_gtk_form_element_label_new () +{ + ZakFormGtkFormElementLabel *zak_form_gtk_form_element_label; + + zak_form_gtk_form_element_label = ZAK_FORM_GTK_FORM_ELEMENT_LABEL (g_object_new (zak_form_gtk_form_element_label_get_type (), NULL)); + + return ZAK_FORM_GTK_FORM_ELEMENT (zak_form_gtk_form_element_label); +} + +/* PRIVATE */ +static void +zak_form_gtk_form_element_label_set_property (GObject *object, + guint property_id, + const GValue *value, + GParamSpec *pspec) +{ + ZakFormGtkFormElementLabel *zak_form_gtk_form_element_label = (ZakFormGtkFormElementLabel *)object; + ZakFormGtkFormElementLabelPrivate *priv = ZAK_FORM_GTK_FORM_ELEMENT_LABEL_GET_PRIVATE (zak_form_gtk_form_element_label); + + switch (property_id) + { + default: + G_OBJECT_WARN_INVALID_PROPERTY_ID (object, property_id, pspec); + break; + } +} + +static void +zak_form_gtk_form_element_label_get_property (GObject *object, + guint property_id, + GValue *value, + GParamSpec *pspec) +{ + ZakFormGtkFormElementLabel *zak_form_gtk_form_element_label = (ZakFormGtkFormElementLabel *)object; + ZakFormGtkFormElementLabelPrivate *priv = ZAK_FORM_GTK_FORM_ELEMENT_LABEL_GET_PRIVATE (zak_form_gtk_form_element_label); + + switch (property_id) + { + default: + G_OBJECT_WARN_INVALID_PROPERTY_ID (object, property_id, pspec); + break; + } +} + +static void +zak_form_gtk_form_element_label_dispose (GObject *gobject) +{ + ZakFormGtkFormElementLabel *zak_form_gtk_form_element_label = (ZakFormGtkFormElementLabel *)gobject; + ZakFormGtkFormElementLabelPrivate *priv = ZAK_FORM_GTK_FORM_ELEMENT_LABEL_GET_PRIVATE (zak_form_gtk_form_element_label); + + + + GObjectClass *parent_class = g_type_class_peek_parent (G_OBJECT_GET_CLASS (gobject)); + parent_class->dispose (gobject); +} + +static void +zak_form_gtk_form_element_label_finalize (GObject *gobject) +{ + ZakFormGtkFormElementLabel *zak_form_gtk_form_element_label = (ZakFormGtkFormElementLabel *)gobject; + ZakFormGtkFormElementLabelPrivate *priv = ZAK_FORM_GTK_FORM_ELEMENT_LABEL_GET_PRIVATE (zak_form_gtk_form_element_label); + + + + GObjectClass *parent_class = g_type_class_peek_parent (G_OBJECT_GET_CLASS (gobject)); + parent_class->finalize (gobject); +} + +static gchar +*zak_form_gtk_form_element_label_get_value (ZakFormGtkFormElementLabel *element) +{ + GtkWidget *w; + + w = zak_form_gtk_form_element_get_widget (ZAK_FORM_GTK_FORM_ELEMENT (element)); + + return (gchar *)gtk_label_get_text (GTK_LABEL (w)); +} + +static gboolean +zak_form_gtk_form_element_label_set_value (ZakFormGtkFormElementLabel *element, const gchar *value) +{ + GtkWidget *w; + + w = zak_form_gtk_form_element_get_widget (ZAK_FORM_GTK_FORM_ELEMENT (element)); + + gtk_label_set_text (GTK_LABEL (w), value); + + return TRUE; +} diff --git a/src/formelementlabel.h b/src/formelementlabel.h new file mode 100644 index 0000000..602c51a --- /dev/null +++ b/src/formelementlabel.h @@ -0,0 +1,60 @@ +/* + * Copyright (C) 2015 Andrea Zagli + * + * 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.1 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, write to the Free Software + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA + */ + +#ifndef __ZAK_FORM_GTK_FORM_ELEMENT_LABEL_H__ +#define __ZAK_FORM_GTK_FORM_ELEMENT_LABEL_H__ + + +#include + +#include "formelement.h" + + +G_BEGIN_DECLS + + +#define ZAK_FORM_GTK_TYPE_FORM_ELEMENT_LABEL (zak_form_gtk_form_element_label_get_type ()) +#define ZAK_FORM_GTK_FORM_ELEMENT_LABEL(obj) (G_TYPE_CHECK_INSTANCE_CAST ((obj), ZAK_FORM_GTK_TYPE_FORM_ELEMENT_LABEL, ZakFormGtkFormElementLabel)) +#define ZAK_FORM_GTK_FORM_ELEMENT_LABEL_CLASS(klass) (G_TYPE_CHECK_CLASS_CAST ((klass), ZAK_FORM_GTK_TYPE_FORM_ELEMENT_LABEL, ZakFormGtkFormElementLabelClass)) +#define ZAK_FORM_GTK_IS_FORM_ELEMENT_LABEL(obj) (G_TYPE_CHECK_INSTANCE_TYPE ((obj), ZAK_FORM_GTK_TYPE_FORM_ELEMENT_LABEL)) +#define ZAK_FORM_GTK_IS_FORM_ELEMENT_LABEL_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE ((klass), ZAK_FORM_GTK_TYPE_FORM_ELEMENT_LABEL)) +#define ZAK_FORM_GTK_FORM_ELEMENT_LABEL_GET_CLASS(obj) (G_TYPE_INSTANCE_GET_CLASS ((obj), ZAK_FORM_GTK_TYPE_FORM_ELEMENT_LABEL, ZakFormGtkFormElementLabelClass)) + +typedef struct _ZakFormGtkFormElementLabel ZakFormGtkFormElementLabel; +typedef struct _ZakFormGtkFormElementLabelClass ZakFormGtkFormElementLabelClass; + +struct _ZakFormGtkFormElementLabel + { + ZakFormGtkFormElement parent_instance; + }; + +struct _ZakFormGtkFormElementLabelClass + { + ZakFormGtkFormElementClass parent_class; + }; + + +GType zak_form_gtk_form_element_label_get_type (void); + +ZakFormGtkFormElement *zak_form_gtk_form_element_label_new (void); + + +G_END_DECLS + + +#endif /* __ZAK_FORM_GTK_FORM_ELEMENT_LABEL_H__ */ diff --git a/src/libzakformgtk.h b/src/libzakformgtk.h index 8456ab0..3f3c6af 100644 --- a/src/libzakformgtk.h +++ b/src/libzakformgtk.h @@ -25,6 +25,7 @@ #include #include #include +#include #endif /* __LIBZAKFORMGTK_H__ */ -- 2.49.0