/*
 * 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/>.
 */

#ifndef VN_FIELD_H
#define VN_FIELD_H

#include <db/db.h>
#include <gtk/gtk.h>

#define VN_TYPE_FIELD				(vn_field_get_type ())
#define VN_FIELD(self)				(G_TYPE_CHECK_INSTANCE_CAST (self, VN_TYPE_FIELD, VnField))
#define VN_IS_FIELD(self)			(G_TYPE_CHECK_INSTANCE_TYPE (self, VN_TYPE_FIELD))
#define VN_FIELD_CLASS(klass)		(G_TYPE_CHECK_CLASS_CAST (klass, VN_TYPE_FIELD, VnFieldClass))
#define VN_FIELD_GET_CLASS(self)	(G_TYPE_INSTANCE_GET_CLASS (self, VN_TYPE_FIELD, VnFieldClass))

typedef struct _VnField VnField;
typedef struct _VnFieldClass VnFieldClass;

typedef void (*VnFieldSetValueFunc)		(VnField * self, const GValue * value);
typedef void (*VnFieldValueChangedFunc)	(VnField * self, const GValue * value);
typedef void (*VnFieldSetWidgetFunc)	(VnField * self, GtkWidget * widget);

typedef void (*VnFieldStyleFunc)		(VnField * self, GtkWidget * widget,
										const GValue * value);

struct _VnField
{
	GtkEventBox parent;
	GtkWidget * widget;
	GValue * value;
	GvnParam * master;
	gboolean change_master;
	GvnParamSpec * spec;
	GvnParamSpec * user_spec;
	gboolean lock_changed_done;
	DbIterator * iterator;
	gchar * column_name;
	VnFieldStyleFunc style_func;
};

struct _VnFieldClass
{
	GtkEventBoxClass parent;
	GCallback changed;
	VnFieldSetValueFunc	set_value;
	VnFieldValueChangedFunc value_changed;
	VnFieldSetWidgetFunc set_widget;
};

GType			vn_field_get_type		();
GType			vn_field_get_gtype		(VnField * self);
void			vn_field_set_gtype		(VnField * self, GType type);
gboolean		vn_field_get_null		(VnField * self);
void			vn_field_set_null		(VnField * self, gboolean null);
gboolean		vn_field_get_editable	(VnField * self);
void			vn_field_set_editable	(VnField * self, gboolean editable);
const GValue *	vn_field_get_default	(VnField * self);
void			vn_field_set_default	(VnField * self, const GValue * def);
void			vn_field_set_to_default	(VnField * self);
GtkWidget *		vn_field_get_widget		(VnField * self);

#endif