From: Andrea Zagli Date: Sat, 30 Apr 2011 14:02:37 +0000 (+0200) Subject: Development begin of GtkFormDecoder widget. X-Git-Tag: 0.3.1~16 X-Git-Url: https://saetta.ns0.it/gitweb?a=commitdiff_plain;h=6167305869ea3cc13dc9df34c01c5b7c293f91ee;p=libgtkform Development begin of GtkFormDecoder widget. --- diff --git a/Makefile.am b/Makefile.am index 936661f..24f47f7 100644 --- a/Makefile.am +++ b/Makefile.am @@ -1,13 +1,15 @@ DISTCHECK_CONFIGURE_FLAGS = --enable-gtk-doc -SUBDIRS = po src test docs data +SUBDIRS = po src ui test docs data ACLOCAL_AMFLAGS = -I m4 -EXTRA_DIST = libgtkform.pc.in +EXTRA_DIST = libgtkform.pc.in \ + libgtkformui.pc.in pkgconfigdir = $(libdir)/pkgconfig -pkgconfig_DATA = libgtkform.pc +pkgconfig_DATA = libgtkform.pc \ + libgtkformui.pc distclean-local: if test "$(srcdir)" = "."; then :; else \ diff --git a/configure.ac b/configure.ac index 10699cc..a8e5423 100644 --- a/configure.ac +++ b/configure.ac @@ -60,14 +60,17 @@ AC_FUNC_STRTOD AC_FUNC_MALLOC # Checks for library functions. -AC_CONFIG_FILES([ po/Makefile.in +AC_CONFIG_FILES([ libgtkform.pc + libgtkformui.pc Makefile src/Makefile + ui/Makefile test/Makefile docs/Makefile docs/reference/Makefile docs/reference/version.xml data/Makefile + po/Makefile.in ]) AC_OUTPUT diff --git a/libgtkformui.pc.in b/libgtkformui.pc.in new file mode 100644 index 0000000..371fefe --- /dev/null +++ b/libgtkformui.pc.in @@ -0,0 +1,11 @@ +prefix=@prefix@ +exec_prefix=@exec_prefix@ +libdir=@libdir@ +includedir=@includedir@ + +Name: @PACKAGE_NAME@ui +Description: Class to more easly manage Gtk+ forms binded to db (or not) UI. +Version: @PACKAGE_VERSION@ +Requires: gtk+-2.0, libgtkform +Libs: -L${libdir} -lgtkform +Cflags: -I${includedir} diff --git a/ui/Makefile.am b/ui/Makefile.am new file mode 100644 index 0000000..649b3d8 --- /dev/null +++ b/ui/Makefile.am @@ -0,0 +1,20 @@ +AM_CPPFLAGS = $(WARN_CFLAGS) \ + $(DISABLE_DEPRECATED_CFLAGS) \ + $(GTKFORMUI_CFLAGS) \ + $(GTKFORM_CFLAGS) \ + -DLOCALEDIR=\"$(localedir)\" \ + -DMODULESDIR=\""$(libdir)/$(PACKAGE)/modules"\" \ + -DG_LOG_DOMAIN=\"GtkFormUI\" + +LIBS = $(GTKFORMUI_LIBS) \ + $(GTKFORM_LIBS) + +lib_LTLIBRARIES = libgtkformui.la + +libgtkformui_la_SOURCES = gtkformdecoder.c + +libgtkformui_la_LDFLAGS = -no-undefined + +libgtkformui_include_HEADERS = gtkformdecoder.h + +libgtkformui_includedir = $(includedir)/libgtkformui diff --git a/ui/gtkformdecoder.c b/ui/gtkformdecoder.c new file mode 100644 index 0000000..a651d96 --- /dev/null +++ b/ui/gtkformdecoder.c @@ -0,0 +1,214 @@ +/* + * GtkFormDecoder widget for GTK+ + * + * Copyright (C) 2011 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 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., 59 Temple Place - Suite 330, + * Boston, MA 02111-1307, USA. + */ + +#include "gtkformdecoder.h" + +enum +{ + PROP_0 +}; + +static void gtk_form_decoder_class_init (GtkFormDecoderClass *klass); +static void gtk_form_decoder_init (GtkFormDecoder *date); + +static void gtk_form_decoder_size_request (GtkWidget *widget, + GtkRequisition *requisition); +static void gtk_form_decoder_size_allocate (GtkWidget *widget, + GtkAllocation *allocation); + +static void gtk_form_decoder_set_property (GObject *object, + guint property_id, + const GValue *value, + GParamSpec *pspec); +static void gtk_form_decoder_get_property (GObject *object, + guint property_id, + GValue *value, + GParamSpec *pspec); + +static GtkWidgetClass *parent_class = NULL; + + +#define GTK_FORM_DECODER_GET_PRIVATE(obj) (G_TYPE_INSTANCE_GET_PRIVATE ((obj), GTK_TYPE_FORM_DECODER, GtkFormDecoderPrivate)) + +typedef struct _GtkFormDecoderPrivate GtkFormDecoderPrivate; +struct _GtkFormDecoderPrivate + { + GtkWidget *hbox; + GtkWidget *txt_decoded; + GtkWidget *btn_browse; + GtkWidget *lbl_key; + }; + +G_DEFINE_TYPE (GtkFormDecoder, gtk_form_decoder, GTK_TYPE_BIN) + +static void +gtk_form_decoder_class_init (GtkFormDecoderClass *klass) +{ + GtkWidgetClass *widget_class; + + GObjectClass *object_class = G_OBJECT_CLASS (klass); + + g_type_class_add_private (object_class, sizeof (GtkFormDecoderPrivate)); + + widget_class = (GtkWidgetClass*) klass; + parent_class = g_type_class_peek_parent (klass); + + object_class->set_property = gtk_form_decoder_set_property; + object_class->get_property = gtk_form_decoder_get_property; + + widget_class->size_request = gtk_form_decoder_size_request; + widget_class->size_allocate = gtk_form_decoder_size_allocate; +} + +static void +gtk_form_decoder_init (GtkFormDecoder *decoder) +{ + GtkFormDecoderPrivate *priv = GTK_FORM_DECODER_GET_PRIVATE (decoder); + + priv->hbox = gtk_hbox_new (FALSE, 0); + gtk_container_add (GTK_CONTAINER (decoder), priv->hbox); + gtk_widget_show (priv->hbox); + + priv->txt_decoded = gtk_entry_new (); + gtk_box_pack_start (GTK_BOX (priv->hbox), priv->txt_decoded, TRUE, TRUE, 0); + gtk_widget_show (priv->txt_decoded); + + priv->btn_browse = gtk_button_new_with_label ("..."); + gtk_box_pack_start (GTK_BOX (priv->hbox), priv->btn_browse, FALSE, FALSE, 0); + gtk_widget_set_no_show_all (priv->btn_browse, TRUE); + gtk_widget_show (priv->btn_browse); + + priv->lbl_key = gtk_label_new (""); + gtk_box_pack_start (GTK_BOX (priv->hbox), priv->lbl_key, FALSE, FALSE, 0); + gtk_widget_set_no_show_all (priv->lbl_key, TRUE); +} + +/** + * gtk_form_decoder_new: + * + * Creates a new #GtkFormDecoder. + * + * Returns: The newly created #GtkFormDecoder widget. + */ +GtkWidget +*gtk_form_decoder_new () +{ + GtkWidget *w = GTK_WIDGET (g_object_new (gtk_form_decoder_get_type (), NULL)); + + return w; +} + +/* PRIVATE */ + +/* CALLBACKS */ +static void +gtk_form_decoder_set_property (GObject *object, guint property_id, const GValue *value, GParamSpec *pspec) +{ + GtkFormDecoder *decoder = GTK_FORM_DECODER (object); + GtkFormDecoderPrivate *priv = GTK_FORM_DECODER_GET_PRIVATE (decoder); + + switch (property_id) + { + default: + G_OBJECT_WARN_INVALID_PROPERTY_ID (object, property_id, pspec); + break; + } +} + +static void +gtk_form_decoder_get_property (GObject *object, guint property_id, GValue *value, GParamSpec *pspec) +{ + GtkFormDecoder *decoder = GTK_FORM_DECODER (object); + GtkFormDecoderPrivate *priv = GTK_FORM_DECODER_GET_PRIVATE (decoder); + + switch (property_id) + { + default: + G_OBJECT_WARN_INVALID_PROPERTY_ID (object, property_id, pspec); + break; + } +} + +static void +gtk_form_decoder_size_request (GtkWidget *widget, + GtkRequisition *requisition) +{ + GtkFormDecoder *decoder; + GtkBin *bin; + GtkRequisition child_requisition; + + guint border_width; + + g_return_if_fail (GTK_IS_DATE_ENTRY (widget)); + g_return_if_fail (requisition != NULL); + + decoder = GTK_FORM_DECODER (widget); + bin = GTK_BIN (decoder); + + requisition->width = 0; + requisition->height = 0; + + if (bin->child && GTK_WIDGET_VISIBLE (bin->child)) + { + gtk_widget_size_request (bin->child, &child_requisition); + requisition->width += child_requisition.width; + requisition->height += child_requisition.height; + } + + border_width = gtk_container_get_border_width (GTK_CONTAINER (widget)); + requisition->width += (border_width * 2); + requisition->height += (border_width * 2); +} + +static void +gtk_form_decoder_size_allocate (GtkWidget *widget, + GtkAllocation *allocation) +{ + GtkFormDecoder *decoder; + GtkBin *bin; + GtkAllocation relative_allocation; + GtkAllocation child_allocation; + + guint border_width; + + g_return_if_fail (GTK_IS_DATE_ENTRY (widget)); + g_return_if_fail (allocation != NULL); + + decoder = GTK_FORM_DECODER (widget); + bin = GTK_BIN (decoder); + + gtk_widget_set_allocation (widget, allocation); + + border_width = gtk_container_get_border_width (GTK_CONTAINER (widget)); + relative_allocation.x = border_width; + relative_allocation.y = border_width; + relative_allocation.width = MAX (1, (gint)widget->allocation.width - relative_allocation.x * 2); + relative_allocation.height = MAX (1, (gint)widget->allocation.height - relative_allocation.y * 2); + + if (bin->child && GTK_WIDGET_VISIBLE (bin->child)) + { + child_allocation.x = relative_allocation.x + allocation->x; + child_allocation.y = relative_allocation.y + allocation->y; + child_allocation.width = relative_allocation.width; + child_allocation.height = relative_allocation.height; + gtk_widget_size_allocate (bin->child, &child_allocation); + } +} diff --git a/ui/gtkformdecoder.h b/ui/gtkformdecoder.h new file mode 100644 index 0000000..c7a09c7 --- /dev/null +++ b/ui/gtkformdecoder.h @@ -0,0 +1,60 @@ +/* + * GtkFormDecoder widget for GTK+ + * + * Copyright (C) 2011 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 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., 59 Temple Place - Suite 330, + * Boston, MA 02111-1307, USA. + */ + +#ifndef __GTK_FORM_DECODER_H__ +#define __GTK_FORM_DECODER_H__ + +#include + +G_BEGIN_DECLS + + +#define GTK_TYPE_FORM_DECODER (gtk_form_decoder_get_type ()) +#define GTK_FORM_DECODER(obj) (G_TYPE_CHECK_INSTANCE_CAST ((obj), GTK_TYPE_FORM_DECODER, GtkFormDecoder)) +#define GTK_FORM_DECODER_CLASS(klass) (G_TYPE_CHECK_CLASS_CAST ((klass), GTK_TYPE_FORM_DECODER, GtkFormDecoder)) +#define GTK_IS_FORM_DECODER(obj) (G_TYPE_CHECK_INSTANCE_TYPE ((obj), GTK_TYPE_FORM_DECODER)) +#define GTK_IS_FORM_DECODER_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE ((klass), GTK_TYPE_FORM_DECODER)) +#define GTK_FORM_DECODER_GET_CLASS(obj) (G_TYPE_INSTANCE_GET_CLASS ((obj), GTK_TYPE_FORM_DECODER, GtkFormDecoder)) + + +typedef struct _GtkFormDecoder GtkFormDecoder; +typedef struct _GtkFormDecoderClass GtkFormDecoderClass; + + +struct _GtkFormDecoder +{ + GtkBin parent; +}; + +struct _GtkFormDecoderClass +{ + GtkBinClass parent_class; +}; + + +GType gtk_form_decoder_get_type (void) G_GNUC_CONST; + +GtkWidget *gtk_form_decoder_new (void); + + +G_END_DECLS + +#endif /* __GTK_FORM_DECODER_H__ */