]> saetta.ns0.it Git - solipa/territorio/commitdiff
Started developing of TerritorioWidget.
authorAndrea Zagli <azagli@libero.it>
Sun, 19 Jun 2011 09:52:09 +0000 (11:52 +0200)
committerAndrea Zagli <azagli@libero.it>
Sun, 19 Jun 2011 09:52:09 +0000 (11:52 +0200)
.gitignore
Makefile.am
autogen.sh [changed mode: 0644->0755]
configure.ac
data/territorio/gui/territorio.gui
libreria/Makefile.am
src/Makefile.am
src/widget.c [new file with mode: 0644]
src/widget.h [new file with mode: 0644]
tests/Makefile.am [new file with mode: 0644]
tests/widget.c [new file with mode: 0644]

index 26f98da5f0c0e1588fd2c66b7f5d226177a5c35b..3a9f412b620fdd7c20f136a4939be6c7a5d95a56 100644 (file)
@@ -26,3 +26,4 @@ missing
 stamp-h1
 .anjuta*
 *exe
+tests/widget
index 3f8a7d144b650efe3fd33f68a6c3bbefcb42ce91..f03852c66752c7fb613f52bb14287665aa7aafed 100644 (file)
@@ -1,4 +1,4 @@
-SUBDIRS = src libreria data docs
+SUBDIRS = src libreria data docs tests
 
 distclean-local:
        if test "$(srcdir)" = "."; then :; else \
old mode 100644 (file)
new mode 100755 (executable)
index 8afdd77e6201206e613794341d52ce1ca8564728..b3ddb8e8b326d8c8824435190fee0ea33b924496 100644 (file)
@@ -28,7 +28,8 @@ PKG_CHECK_MODULES(TERRITORIO, [gio-2.0 >= 2.20
                           gtk+-2.0 >= 2.16
                           libgda-ui-4.0 >= 4.2.0
                           libgdaex >= 0.3.0
-                          libgtkform >= 0.1.3
+                          libgtkform >= 0.3.1
+                          libgtkformui >= 0.3.1
                           libaute >= 0.0.2
                           libautoz >= 0.0.1
                           libsolipa >= 0.3.1])
@@ -54,5 +55,6 @@ AC_CONFIG_FILES([
        docs/Makefile
        docs/territorio/Makefile
        docs/territorio/examples/Makefile
+       tests/Makefile
 ])
 AC_OUTPUT
index d4fa37ad5e63b050029c093face4f65c154206b4..7254390a25a7b779ea8a970bce35353a909fa63c 100644 (file)
@@ -1,6 +1,7 @@
 <?xml version="1.0"?>
 <interface>
   <requires lib="gtk+" version="2.16"/>
+  <!-- interface-requires gtkformui 0.0 -->
   <!-- interface-naming-policy project-wide -->
   <object class="GtkWindow" id="w_main">
     <property name="title" translatable="yes">Territorio</property>
       </object>
     </child>
   </object>
+  <object class="GtkWindow" id="w_widget">
+    <child>
+      <object class="GtkTable" id="table11">
+        <property name="visible">True</property>
+        <property name="n_rows">5</property>
+        <property name="n_columns">2</property>
+        <property name="column_spacing">5</property>
+        <property name="row_spacing">5</property>
+        <child>
+          <object class="GtkLabel" id="label53">
+            <property name="visible">True</property>
+            <property name="no_show_all">True</property>
+            <property name="xalign">0</property>
+            <property name="label" translatable="yes">Stato</property>
+          </object>
+          <packing>
+            <property name="x_options">GTK_FILL</property>
+            <property name="y_options">GTK_FILL</property>
+          </packing>
+        </child>
+        <child>
+          <object class="GtkLabel" id="label54">
+            <property name="visible">True</property>
+            <property name="no_show_all">True</property>
+            <property name="xalign">0</property>
+            <property name="label" translatable="yes">Regione</property>
+          </object>
+          <packing>
+            <property name="top_attach">1</property>
+            <property name="bottom_attach">2</property>
+            <property name="x_options">GTK_FILL</property>
+            <property name="y_options">GTK_FILL</property>
+          </packing>
+        </child>
+        <child>
+          <object class="GtkLabel" id="label55">
+            <property name="visible">True</property>
+            <property name="no_show_all">True</property>
+            <property name="xalign">0</property>
+            <property name="label" translatable="yes">Provincia</property>
+          </object>
+          <packing>
+            <property name="top_attach">2</property>
+            <property name="bottom_attach">3</property>
+            <property name="x_options">GTK_FILL</property>
+            <property name="y_options">GTK_FILL</property>
+          </packing>
+        </child>
+        <child>
+          <object class="GtkLabel" id="label57">
+            <property name="visible">True</property>
+            <property name="no_show_all">True</property>
+            <property name="xalign">0</property>
+            <property name="label" translatable="yes">Comune</property>
+          </object>
+          <packing>
+            <property name="top_attach">3</property>
+            <property name="bottom_attach">4</property>
+            <property name="x_options">GTK_FILL</property>
+            <property name="y_options">GTK_FILL</property>
+          </packing>
+        </child>
+        <child>
+          <object class="GtkLabel" id="label58">
+            <property name="visible">True</property>
+            <property name="no_show_all">True</property>
+            <property name="xalign">0</property>
+            <property name="label" translatable="yes">Via</property>
+          </object>
+          <packing>
+            <property name="top_attach">4</property>
+            <property name="bottom_attach">5</property>
+            <property name="x_options">GTK_FILL</property>
+            <property name="y_options">GTK_FILL</property>
+          </packing>
+        </child>
+        <child>
+          <object class="GtkFormDecoder" id="gtkformdecoder1">
+            <property name="visible">True</property>
+            <property name="no_show_all">True</property>
+            <property name="show_btn_clean">True</property>
+            <property name="show_btn_open">True</property>
+          </object>
+          <packing>
+            <property name="left_attach">1</property>
+            <property name="right_attach">2</property>
+            <property name="y_options">GTK_FILL</property>
+          </packing>
+        </child>
+        <child>
+          <object class="GtkFormDecoder" id="gtkformdecoder2">
+            <property name="visible">True</property>
+            <property name="no_show_all">True</property>
+            <property name="show_btn_clean">True</property>
+            <property name="show_btn_open">True</property>
+          </object>
+          <packing>
+            <property name="left_attach">1</property>
+            <property name="right_attach">2</property>
+            <property name="top_attach">1</property>
+            <property name="bottom_attach">2</property>
+            <property name="y_options">GTK_FILL</property>
+          </packing>
+        </child>
+        <child>
+          <object class="GtkFormDecoder" id="gtkformdecoder3">
+            <property name="visible">True</property>
+            <property name="no_show_all">True</property>
+            <property name="show_btn_clean">True</property>
+            <property name="show_btn_open">True</property>
+          </object>
+          <packing>
+            <property name="left_attach">1</property>
+            <property name="right_attach">2</property>
+            <property name="top_attach">2</property>
+            <property name="bottom_attach">3</property>
+            <property name="y_options">GTK_FILL</property>
+          </packing>
+        </child>
+        <child>
+          <object class="GtkFormDecoder" id="gtkformdecoder4">
+            <property name="visible">True</property>
+            <property name="no_show_all">True</property>
+            <property name="show_btn_clean">True</property>
+            <property name="show_btn_open">True</property>
+          </object>
+          <packing>
+            <property name="left_attach">1</property>
+            <property name="right_attach">2</property>
+            <property name="top_attach">3</property>
+            <property name="bottom_attach">4</property>
+            <property name="y_options">GTK_FILL</property>
+          </packing>
+        </child>
+        <child>
+          <object class="GtkFormDecoder" id="gtkformdecoder5">
+            <property name="visible">True</property>
+            <property name="no_show_all">True</property>
+            <property name="show_btn_clean">True</property>
+            <property name="show_btn_open">True</property>
+          </object>
+          <packing>
+            <property name="left_attach">1</property>
+            <property name="right_attach">2</property>
+            <property name="top_attach">4</property>
+            <property name="bottom_attach">5</property>
+            <property name="y_options">GTK_FILL</property>
+          </packing>
+        </child>
+      </object>
+    </child>
+  </object>
 </interface>
index f2d2a9386278f8c5424ae05c45596f61e38bb2d9..6101241f83d897edb875c69e3b6edcfcd701f147 100644 (file)
@@ -27,7 +27,8 @@ libterritorio_la_SOURCES = \
                 ../src/tipiaggregazioneterritoriale.c \
                 ../src/tipoaggregazioneterritoriale.c \
                 ../src/via.c \
-                ../src/vie.c
+                ../src/vie.c \
+                ../src/widget.c
 
 libterritorio_la_LDFLAGS = -no-undefined
 
@@ -49,6 +50,7 @@ libterritorio_include_HEADERS = \
                 ../src/tipiaggregazioneterritoriale.h \
                 ../src/tipoaggregazioneterritoriale.h \
                 ../src/via.h \
-                ../src/vie.h
+                ../src/vie.h \
+                ../src/widget.h
 
-libterritorio_includedir = $(includedir)/libterritorio
\ No newline at end of file
+libterritorio_includedir = $(includedir)/libterritorio
index f01272cd6006e78ef063333cb8970b128ff1de0f..ff3b09437136cf52d335ed6e01b6314908e0027a 100644 (file)
@@ -54,4 +54,6 @@ territorio_SOURCES = \
                 via.c \
                 via.h \
                 vie.c \
-                vie.h
\ No newline at end of file
+                vie.h \
+                widget.c \
+                widget.h
diff --git a/src/widget.c b/src/widget.c
new file mode 100644 (file)
index 0000000..5708b63
--- /dev/null
@@ -0,0 +1,563 @@
+/* 
+ * Copyright (C) 2011 Andrea Zagli <azagli@libero.it>
+ *
+ * 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
+ *
+ */
+
+#include <libgtkform/form.h>
+#include <libgtkformui/gtkformdecoder.h>
+
+#include "widget.h"
+#include "stati.h"
+#include "stato.h"
+#include "regioni.h"
+#include "regione.h"
+#include "province.h"
+#include "provincia.h"
+#include "comuni.h"
+#include "comune.h"
+#include "vie.h"
+#include "via.h"
+
+static void territorio_widget_class_init (TerritorioWidgetClass *klass);
+static void territorio_widget_init (TerritorioWidget *territorio_widget);
+
+static void territorio_widget_size_request (GtkWidget *widget,
+                                    GtkRequisition *requisition);
+static void territorio_widget_size_allocate (GtkWidget *widget,
+                                     GtkAllocation *allocation);
+
+static void territorio_widget_set_property (GObject *object,
+                                     guint property_id,
+                                     const GValue *value,
+                                     GParamSpec *pspec);
+static void territorio_widget_get_property (GObject *object,
+                                     guint property_id,
+                                     GValue *value,
+                                     GParamSpec *pspec);
+
+static void territorio_widget_set_transient (TerritorioWidget *twidget);
+
+static void territorio_widget_on_stato_selezionato (gpointer instance, guint id, gpointer user_data);
+static void territorio_widget_on_regione_selezionato (gpointer instance, guint id, gpointer user_data);
+static void territorio_widget_on_privincia_selezionato (gpointer instance, guint id, gpointer user_data);
+static void territorio_widget_on_comune_selezionato (gpointer instance, guint id, gpointer user_data);
+static void territorio_widget_on_via_selezionato (gpointer instance, guint id, gpointer user_data);
+
+static void territorio_widget_on_btn_stato_clean_clicked (GtkButton *button,
+                      gpointer user_data);
+static void territorio_widget_on_btn_stato_open_clicked (GtkButton *button,
+                      gpointer user_data);
+static void territorio_widget_on_btn_stato_clicked (GtkButton *button,
+                      gpointer user_data);
+
+static void territorio_widget_on_btn_regione_clean_clicked (GtkButton *button,
+                      gpointer user_data);
+static void territorio_widget_on_btn_regione_open_clicked (GtkButton *button,
+                      gpointer user_data);
+static void territorio_widget_on_btn_regione_clicked (GtkButton *button,
+                      gpointer user_data);
+
+static void territorio_widget_on_btn_provincia_clean_clicked (GtkButton *button,
+                      gpointer user_data);
+static void territorio_widget_on_btn_provincia_open_clicked (GtkButton *button,
+                      gpointer user_data);
+static void territorio_widget_on_btn_provincia_clicked (GtkButton *button,
+                      gpointer user_data);
+
+static void territorio_widget_on_btn_comune_clean_clicked (GtkButton *button,
+                      gpointer user_data);
+static void territorio_widget_on_btn_comune_open_clicked (GtkButton *button,
+                      gpointer user_data);
+static void territorio_widget_on_btn_comune_clicked (GtkButton *button,
+                      gpointer user_data);
+
+static void territorio_widget_on_btn_via_clean_clicked (GtkButton *button,
+                      gpointer user_data);
+static void territorio_widget_on_btn_via_open_clicked (GtkButton *button,
+                      gpointer user_data);
+static void territorio_widget_on_btn_via_clicked (GtkButton *button,
+                      gpointer user_data);
+
+#define TERRITORIO_WIDGET_GET_PRIVATE(obj) (G_TYPE_INSTANCE_GET_PRIVATE ((obj), TYPE_TERRITORIO_WIDGET, TerritorioWidgetPrivate))
+
+typedef struct _TerritorioWidgetPrivate TerritorioWidgetPrivate;
+struct _TerritorioWidgetPrivate
+       {
+               TerritorioCommons *commons;
+
+               GtkWidget *dec_stato;
+               GtkWidget *dec_regione;
+               GtkWidget *dec_provincia;
+               GtkWidget *dec_comune;
+               GtkWidget *dec_via;
+
+               GtkWidget *transient;
+       };
+
+G_DEFINE_TYPE (TerritorioWidget, territorio_widget, GTK_TYPE_BIN)
+
+static void
+territorio_widget_class_init (TerritorioWidgetClass *klass)
+{
+       GtkWidgetClass *widget_class;
+
+       GObjectClass *object_class = G_OBJECT_CLASS (klass);
+
+       widget_class = (GtkWidgetClass*) klass;
+
+       g_type_class_add_private (object_class, sizeof (TerritorioWidgetPrivate));
+
+       object_class->set_property = territorio_widget_set_property;
+       object_class->get_property = territorio_widget_get_property;
+
+       widget_class->size_request = territorio_widget_size_request;
+       widget_class->size_allocate = territorio_widget_size_allocate;
+}
+
+static void
+territorio_widget_init (TerritorioWidget *territorio_widget)
+{
+       TerritorioWidgetPrivate *priv = TERRITORIO_WIDGET_GET_PRIVATE (territorio_widget);
+
+       priv->transient = NULL;
+}
+
+/**
+ * territorio_widget_new:
+ * @commons:
+ *
+ * Returns: the newly created #TerritorioWidget object.
+ */
+GtkWidget
+*territorio_widget_new (TerritorioCommons *commons)
+{
+       GError *error;
+
+       GtkWidget *w = GTK_WIDGET (g_object_new (territorio_widget_get_type (), NULL));
+
+       TerritorioWidget *a = TERRITORIO_WIDGET (w);
+
+       TerritorioWidgetPrivate *priv = TERRITORIO_WIDGET_GET_PRIVATE (a);
+
+       priv->commons = commons;
+
+       error = NULL;
+       gtk_builder_add_objects_from_file (priv->commons->gtkbuilder, priv->commons->guifile,
+                                          g_strsplit (g_strconcat ("table11", NULL), "|", -1),
+                                          &error);
+       if (error != NULL)
+               {
+                       g_warning ("Errore: %s.", error->message);
+                       return NULL;
+               }
+
+       gtk_container_add (GTK_CONTAINER (a), GTK_WIDGET (gtk_builder_get_object (priv->commons->gtkbuilder, "table11")));
+
+       priv->dec_stato = GTK_WIDGET (gtk_builder_get_object (priv->commons->gtkbuilder, "gtkformdecoder1"));
+       priv->dec_regione = GTK_WIDGET (gtk_builder_get_object (priv->commons->gtkbuilder, "gtkformdecoder2"));
+       priv->dec_provincia = GTK_WIDGET (gtk_builder_get_object (priv->commons->gtkbuilder, "gtkformdecoder3"));
+       priv->dec_comune = GTK_WIDGET (gtk_builder_get_object (priv->commons->gtkbuilder, "gtkformdecoder4"));
+       priv->dec_via = GTK_WIDGET (gtk_builder_get_object (priv->commons->gtkbuilder, "gtkformdecoder5"));
+
+       g_object_set (G_OBJECT (priv->dec_stato),
+                     "gdaex", priv->commons->gdaex,
+                     "sql", "SELECT nome FROM stati WHERE id = ##key0::gint",
+                     NULL);
+       g_object_set (G_OBJECT (priv->dec_regione),
+                     "gdaex", priv->commons->gdaex,
+                     "sql", "SELECT nome FROM regioni WHERE id = ##key0::gint",
+                     NULL);
+       g_object_set (G_OBJECT (priv->dec_provincia),
+                     "gdaex", priv->commons->gdaex,
+                     "sql", "SELECT nome FROM province WHERE id = ##key0::gint",
+                     NULL);
+       g_object_set (G_OBJECT (priv->dec_comune),
+                     "gdaex", priv->commons->gdaex,
+                     "sql", "SELECT nome FROM comuni WHERE id = ##key0::gint",
+                     NULL);
+       g_object_set (G_OBJECT (priv->dec_via),
+                     "gdaex", priv->commons->gdaex,
+                     "sql", "SELECT nome FROM vie WHERE id = ##key0::gint",
+                     NULL);
+
+       g_signal_connect (priv->dec_stato,
+                         "btn-clean-clicked", G_CALLBACK (territorio_widget_on_btn_stato_clean_clicked), (gpointer)a);
+       g_signal_connect (priv->dec_stato,
+                         "btn-open-clicked", G_CALLBACK (territorio_widget_on_btn_stato_open_clicked), (gpointer)a);
+       g_signal_connect (priv->dec_stato,
+                         "btn-browse-clicked", G_CALLBACK (territorio_widget_on_btn_stato_clicked), (gpointer)a);
+
+       g_signal_connect (priv->dec_regione,
+                         "btn-clean-clicked", G_CALLBACK (territorio_widget_on_btn_regione_clean_clicked), (gpointer)a);
+       g_signal_connect (priv->dec_regione,
+                         "btn-open-clicked", G_CALLBACK (territorio_widget_on_btn_regione_open_clicked), (gpointer)a);
+       g_signal_connect (priv->dec_regione,
+                         "btn-browse-clicked", G_CALLBACK (territorio_widget_on_btn_regione_clicked), (gpointer)a);
+
+       g_signal_connect (priv->dec_provincia,
+                         "btn-clean-clicked", G_CALLBACK (territorio_widget_on_btn_provincia_clean_clicked), (gpointer)a);
+       g_signal_connect (priv->dec_provincia,
+                         "btn-open-clicked", G_CALLBACK (territorio_widget_on_btn_provincia_open_clicked), (gpointer)a);
+       g_signal_connect (priv->dec_provincia,
+                         "btn-browse-clicked", G_CALLBACK (territorio_widget_on_btn_provincia_clicked), (gpointer)a);
+
+       g_signal_connect (priv->dec_comune,
+                         "btn-clean-clicked", G_CALLBACK (territorio_widget_on_btn_comune_clean_clicked), (gpointer)a);
+       g_signal_connect (priv->dec_comune,
+                         "btn-open-clicked", G_CALLBACK (territorio_widget_on_btn_comune_open_clicked), (gpointer)a);
+       g_signal_connect (priv->dec_comune,
+                         "btn-browse-clicked", G_CALLBACK (territorio_widget_on_btn_comune_clicked), (gpointer)a);
+
+       g_signal_connect (priv->dec_via,
+                         "btn-clean-clicked", G_CALLBACK (territorio_widget_on_btn_via_clean_clicked), (gpointer)a);
+       g_signal_connect (priv->dec_via,
+                         "btn-open-clicked", G_CALLBACK (territorio_widget_on_btn_via_open_clicked), (gpointer)a);
+       g_signal_connect (priv->dec_via,
+                         "btn-browse-clicked", G_CALLBACK (territorio_widget_on_btn_via_clicked), (gpointer)a);
+
+       return w;
+}
+
+/**
+ * territorio_widget_get_widget:
+ * @territorio_widget:
+ *
+ */
+GtkWidget
+*territorio_widget_get_widget (TerritorioWidget *territorio_widget)
+{
+       TerritorioWidgetPrivate *priv = TERRITORIO_WIDGET_GET_PRIVATE (territorio_widget);
+
+       return priv->transient;
+}
+
+/* PRIVATE */
+static void
+territorio_widget_set_property (GObject *object, guint property_id, const GValue *value, GParamSpec *pspec)
+{
+       TerritorioWidget *territorio_widget = TERRITORIO_WIDGET (object);
+       TerritorioWidgetPrivate *priv = TERRITORIO_WIDGET_GET_PRIVATE (territorio_widget);
+
+       switch (property_id)
+               {
+                       default:
+                               G_OBJECT_WARN_INVALID_PROPERTY_ID (object, property_id, pspec);
+                               break;
+               }
+}
+
+static void
+territorio_widget_get_property (GObject *object, guint property_id, GValue *value, GParamSpec *pspec)
+{
+       TerritorioWidget *territorio_widget = TERRITORIO_WIDGET (object);
+       TerritorioWidgetPrivate *priv = TERRITORIO_WIDGET_GET_PRIVATE (territorio_widget);
+
+       switch (property_id)
+               {
+                       default:
+                               G_OBJECT_WARN_INVALID_PROPERTY_ID (object, property_id, pspec);
+                               break;
+               }
+}
+
+static void
+territorio_widget_size_request (GtkWidget *widget,
+                        GtkRequisition *requisition)
+{
+       TerritorioWidget *twidget;
+       GtkBin *bin;
+       GtkRequisition child_requisition;
+
+       guint border_width;
+
+       g_return_if_fail (IS_TERRITORIO_WIDGET (widget));
+       g_return_if_fail (requisition != NULL);
+
+       twidget = TERRITORIO_WIDGET (widget);
+       bin = GTK_BIN (twidget);
+
+       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
+territorio_widget_size_allocate (GtkWidget *widget,
+                         GtkAllocation *allocation)
+{
+       TerritorioWidget *twidget;
+       GtkBin *bin;
+       GtkAllocation relative_allocation;
+       GtkAllocation child_allocation;
+
+       guint border_width;
+
+       g_return_if_fail (IS_TERRITORIO_WIDGET (widget));
+       g_return_if_fail (allocation != NULL);
+
+       twidget = TERRITORIO_WIDGET (widget);
+       bin = GTK_BIN (twidget);
+
+       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);
+               }
+}
+
+static void
+territorio_widget_set_transient (TerritorioWidget *twidget)
+{
+       TerritorioWidgetPrivate *priv = TERRITORIO_WIDGET_GET_PRIVATE (twidget);
+
+       GtkWidget *top = gtk_widget_get_toplevel (GTK_WIDGET (twidget));
+       if (gtk_widget_is_toplevel (top))
+               {
+                       priv->transient = top;
+               }
+       else
+               {
+                       priv->transient = NULL;
+               }
+}
+
+/* CALLBACK */
+static void
+territorio_widget_on_stato_selezionato (gpointer instance, guint id, gpointer user_data)
+{
+       TerritorioWidget *f = (TerritorioWidget *)user_data;
+       TerritorioWidgetPrivate *priv = TERRITORIO_WIDGET_GET_PRIVATE (f);
+
+       gtk_form_decoder_set_key (GTK_FORM_DECODER (priv->dec_stato), g_strdup_printf ("%d", id));
+}
+
+static void
+territorio_widget_on_regione_selezionato (gpointer instance, guint id, gpointer user_data)
+{
+       TerritorioWidget *f = (TerritorioWidget *)user_data;
+       TerritorioWidgetPrivate *priv = TERRITORIO_WIDGET_GET_PRIVATE (f);
+
+       gtk_form_decoder_set_key (GTK_FORM_DECODER (priv->dec_regione), g_strdup_printf ("%d", id));
+}
+
+static void
+territorio_widget_on_provincia_selezionato (gpointer instance, guint id, gpointer user_data)
+{
+       TerritorioWidget *f = (TerritorioWidget *)user_data;
+       TerritorioWidgetPrivate *priv = TERRITORIO_WIDGET_GET_PRIVATE (f);
+
+       gtk_form_decoder_set_key (GTK_FORM_DECODER (priv->dec_provincia), g_strdup_printf ("%d", id));
+}
+
+static void
+territorio_widget_on_comune_selezionato (gpointer instance, guint id, gpointer user_data)
+{
+       TerritorioWidget *f = (TerritorioWidget *)user_data;
+       TerritorioWidgetPrivate *priv = TERRITORIO_WIDGET_GET_PRIVATE (f);
+
+       gtk_form_decoder_set_key (GTK_FORM_DECODER (priv->dec_comune), g_strdup_printf ("%d", id));
+}
+
+static void
+territorio_widget_on_via_selezionato (gpointer instance, guint id, gpointer user_data)
+{
+       TerritorioWidget *f = (TerritorioWidget *)user_data;
+       TerritorioWidgetPrivate *priv = TERRITORIO_WIDGET_GET_PRIVATE (f);
+
+       gtk_form_decoder_set_key (GTK_FORM_DECODER (priv->dec_via), g_strdup_printf ("%d", id));
+}
+
+static void
+territorio_widget_on_btn_stato_clean_clicked (GtkButton *button,
+                      gpointer user_data)
+{
+}
+
+static void
+territorio_widget_on_btn_stato_open_clicked (GtkButton *button,
+                      gpointer user_data)
+{
+}
+
+static void
+territorio_widget_on_btn_stato_clicked (GtkButton *button,
+                      gpointer user_data)
+{
+       GtkWidget *w;
+
+       TerritorioWidget *rf = (TerritorioWidget *)user_data;
+       TerritorioWidgetPrivate *priv = TERRITORIO_WIDGET_GET_PRIVATE (rf);
+
+       TerritorioStati *c = territorio_stati_new (priv->commons, TRUE);
+
+       g_signal_connect (G_OBJECT (c), "selezionato",
+                         G_CALLBACK (territorio_widget_on_stato_selezionato), user_data);
+
+       if (priv->transient == NULL) territorio_widget_set_transient (rf);
+       w = territorio_stati_get_widget (c);
+       gtk_window_set_transient_for (GTK_WINDOW (w), GTK_WINDOW (priv->transient));
+       gtk_widget_show (w);
+}
+
+static void
+territorio_widget_on_btn_regione_clean_clicked (GtkButton *button,
+                      gpointer user_data)
+{
+}
+
+static void
+territorio_widget_on_btn_regione_open_clicked (GtkButton *button,
+                      gpointer user_data)
+{
+}
+
+static void
+territorio_widget_on_btn_regione_clicked (GtkButton *button,
+                      gpointer user_data)
+{
+       GtkWidget *w;
+
+       TerritorioWidget *rf = (TerritorioWidget *)user_data;
+       TerritorioWidgetPrivate *priv = TERRITORIO_WIDGET_GET_PRIVATE (rf);
+
+       TerritorioRegioni *c = territorio_regioni_new (priv->commons, TRUE);
+
+       g_signal_connect (G_OBJECT (c), "selezionato",
+                         G_CALLBACK (territorio_widget_on_regione_selezionato), user_data);
+
+       if (priv->transient == NULL) territorio_widget_set_transient (rf);
+       w = territorio_regioni_get_widget (c);
+       gtk_window_set_transient_for (GTK_WINDOW (w), GTK_WINDOW (priv->transient));
+       gtk_widget_show (w);
+}
+
+static void
+territorio_widget_on_btn_provincia_clean_clicked (GtkButton *button,
+                      gpointer user_data)
+{
+}
+
+static void
+territorio_widget_on_btn_provincia_open_clicked (GtkButton *button,
+                      gpointer user_data)
+{
+}
+
+static void
+territorio_widget_on_btn_provincia_clicked (GtkButton *button,
+                      gpointer user_data)
+{
+       GtkWidget *w;
+
+       TerritorioWidget *rf = (TerritorioWidget *)user_data;
+       TerritorioWidgetPrivate *priv = TERRITORIO_WIDGET_GET_PRIVATE (rf);
+
+       TerritorioProvince *c = territorio_province_new (priv->commons, TRUE);
+
+       g_signal_connect (G_OBJECT (c), "selezionato",
+                         G_CALLBACK (territorio_widget_on_provincia_selezionato), user_data);
+
+       if (priv->transient == NULL) territorio_widget_set_transient (rf);
+       w = territorio_province_get_widget (c);
+       gtk_window_set_transient_for (GTK_WINDOW (w), GTK_WINDOW (priv->transient));
+       gtk_widget_show (w);
+}
+
+static void
+territorio_widget_on_btn_comune_clean_clicked (GtkButton *button,
+                      gpointer user_data)
+{
+}
+
+static void
+territorio_widget_on_btn_comune_open_clicked (GtkButton *button,
+                      gpointer user_data)
+{
+}
+
+static void
+territorio_widget_on_btn_comune_clicked (GtkButton *button,
+                      gpointer user_data)
+{
+       GtkWidget *w;
+
+       TerritorioWidget *rf = (TerritorioWidget *)user_data;
+       TerritorioWidgetPrivate *priv = TERRITORIO_WIDGET_GET_PRIVATE (rf);
+
+       TerritorioComuni *c = territorio_comuni_new (priv->commons, TRUE);
+
+       g_signal_connect (G_OBJECT (c), "selezionato",
+                         G_CALLBACK (territorio_widget_on_comune_selezionato), user_data);
+
+       if (priv->transient == NULL) territorio_widget_set_transient (rf);
+       w = territorio_comuni_get_widget (c);
+       gtk_window_set_transient_for (GTK_WINDOW (w), GTK_WINDOW (priv->transient));
+       gtk_widget_show (w);
+}
+
+static void
+territorio_widget_on_btn_via_clean_clicked (GtkButton *button,
+                      gpointer user_data)
+{
+}
+
+static void
+territorio_widget_on_btn_via_open_clicked (GtkButton *button,
+                      gpointer user_data)
+{
+}
+
+static void
+territorio_widget_on_btn_via_clicked (GtkButton *button,
+                      gpointer user_data)
+{
+       GtkWidget *w;
+
+       TerritorioWidget *rf = (TerritorioWidget *)user_data;
+       TerritorioWidgetPrivate *priv = TERRITORIO_WIDGET_GET_PRIVATE (rf);
+
+       TerritorioVie *c = territorio_vie_new (priv->commons, TRUE);
+
+       g_signal_connect (G_OBJECT (c), "selezionato",
+                         G_CALLBACK (territorio_widget_on_via_selezionato), user_data);
+
+       if (priv->transient == NULL) territorio_widget_set_transient (rf);
+       w = territorio_vie_get_widget (c);
+       gtk_window_set_transient_for (GTK_WINDOW (w), GTK_WINDOW (priv->transient));
+       gtk_widget_show (w);
+}
diff --git a/src/widget.h b/src/widget.h
new file mode 100644 (file)
index 0000000..ddfc1f6
--- /dev/null
@@ -0,0 +1,61 @@
+/* 
+ * Copyright (C) 2011 Andrea Zagli <azagli@libero.it>
+ *
+ * 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 __TERRITORIO_WIDGET_H__
+#define __TERRITORIO_WIDGET_H__
+
+#include <glib.h>
+#include <glib-object.h>
+
+#include <gtk/gtk.h>
+
+#include "commons.h"
+
+G_BEGIN_DECLS
+
+
+#define TYPE_TERRITORIO_WIDGET                 (territorio_widget_get_type ())
+#define TERRITORIO_WIDGET(obj)                 (G_TYPE_CHECK_INSTANCE_CAST ((obj), TYPE_TERRITORIO_WIDGET, TerritorioWidget))
+#define TERRITORIO_WIDGET_CLASS(klass)         (G_TYPE_CHECK_CLASS_CAST ((klass), TYPE_TERRITORIO_WIDGET, TerritorioWidgetClass))
+#define IS_TERRITORIO_WIDGET(obj)              (G_TYPE_CHECK_INSTANCE_TYPE ((obj), TYPE_TERRITORIO_WIDGET))
+#define IS_TERRITORIO_WIDGET_CLASS(klass)      (G_TYPE_CHECK_CLASS_TYPE ((klass), TYPE_TERRITORIO_WIDGET))
+#define TERRITORIO_WIDGET_GET_CLASS(obj)       (G_TYPE_INSTANCE_GET_CLASS ((obj), TYPE_TERRITORIO_WIDGET, TerritorioWidgetClass))
+
+
+typedef struct _TerritorioWidget TerritorioWidget;
+typedef struct _TerritorioWidgetClass TerritorioWidgetClass;
+
+struct _TerritorioWidget
+       {
+               GtkBin parent;
+       };
+
+struct _TerritorioWidgetClass
+       {
+               GtkBinClass parent_class;
+       };
+
+GType territorio_widget_get_type (void) G_GNUC_CONST;
+
+GtkWidget *territorio_widget_new (TerritorioCommons *commons);
+
+
+G_END_DECLS
+
+#endif /* __TERRITORIO_WIDGET_H__ */
diff --git a/tests/Makefile.am b/tests/Makefile.am
new file mode 100644 (file)
index 0000000..1cf865d
--- /dev/null
@@ -0,0 +1,17 @@
+guidir = $(datadir)/$(PACKAGE)/gui
+formdir = $(datadir)/$(PACKAGE)/form
+
+LIBS = $(TERRITORIO_LIBS) \
+       -export-dynamic
+
+AM_CPPFLAGS = $(TERRITORIO_CFLAGS) \
+              -I$(top_srcdir)/src \
+              -DGUIDIRTEST="\"@abs_builddir@\"" \
+              -DGUIDIR=\""$(guidir)"\" \
+              -DFORMDIR=\""$(formdir)"\"
+
+noinst_PROGRAMS = widget
+
+LDADD = $(top_builddir)/libreria/libterritorio.la
+
+EXTRA_DIST = 
diff --git a/tests/widget.c b/tests/widget.c
new file mode 100644 (file)
index 0000000..36f9732
--- /dev/null
@@ -0,0 +1,135 @@
+/*
+ * Copyright (C) 2011 Andrea Zagli <azagli@libero.it>
+ *
+ *  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 2 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, write to the Free Software
+ *  Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
+ */
+
+#include <gtk/gtk.h>
+
+#include "commons.h"
+#include "widget.h"
+
+static GtkWidget *w;
+static GtkWidget *territorio;
+
+static GKeyFile *config;
+
+static TerritorioCommons *commons;
+
+static gboolean
+on_btn_clean_clicked (gpointer instance, gpointer user_data)
+{
+       return FALSE;
+}
+
+gboolean
+on_w_delete_event (GtkWidget *widget,
+                   GdkEvent *event,
+                   gpointer user_data)
+{
+       return FALSE;
+}
+
+int
+main (int argc, char **argv)
+{
+       GError *error;
+
+       gchar *cnc_string;
+
+       gtk_init (&argc, &argv);
+
+       /* leggo la configurazione dal file */
+       if (argc == 1)
+               {
+                       g_error ("Occorre passare a riga di comando il file di configurazione.");
+               }
+
+       error = NULL;
+       config = g_key_file_new ();
+       if (!g_key_file_load_from_file (config, argv[1], G_KEY_FILE_NONE, &error))
+               {
+                       g_error ("Impossibile caricare il file di configurazione specificato: %s.", argv[1]);
+               }
+
+       commons = g_new0 (TerritorioCommons, 1);
+
+#ifdef G_OS_WIN32
+
+       gchar *moddir;
+       gchar *p;
+
+       moddir = g_win32_get_package_installation_directory_of_module (NULL);
+
+       p = strrchr (moddir, G_DIR_SEPARATOR);
+       if (p != NULL
+           && (g_ascii_strcasecmp (p + 1, "src") == 0
+               || g_ascii_strcasecmp (p + 1, ".libs") == 0))
+               {
+                       commons->guidir = g_strdup (GUIDIR);
+                       commons->formdir = g_strdup (FORMDIR);
+               }
+       else
+               {
+                       commons->guidir = g_build_filename (moddir, "share", PACKAGE, "gui", NULL);
+                       commons->formdir = g_build_filename (moddir, "share", PACKAGE, "form", NULL);
+               }
+
+#else
+
+       commons->guidir = g_strdup (GUIDIR);
+       commons->formdir = g_strdup (FORMDIR);
+
+#endif
+
+       commons->guifile = g_build_filename (commons->guidir, "territorio.gui", NULL);
+
+       /* leggo la stringa di connessione al db */
+       error = NULL;
+       cnc_string = g_key_file_get_value (config, "DB", "cnc_string", &error);
+       if (cnc_string == NULL)
+               {
+                       g_error ("Impossibile leggere la stringa di connessione dal file di configurazione: %s.",
+                                error != NULL && error->message != NULL ? error->message : "nessun dettaglio");
+               }
+
+       commons->gdaex = gdaex_new_from_string (cnc_string);
+       if (commons->gdaex == NULL)
+               {
+                       g_error ("Errore nella connessione al database: %s", cnc_string);
+               }
+
+       /* inizializzo solipa */
+       commons->solipa = solipa_new ();
+
+       commons->gtkbuilder = gtk_builder_new ();
+
+       /* gui per il test */
+       w = gtk_window_new (GTK_WINDOW_TOPLEVEL);
+       g_signal_connect (w, "delete-event", G_CALLBACK (on_w_delete_event), NULL);
+       g_signal_connect (w, "destroy", gtk_main_quit, NULL);
+
+       territorio = territorio_widget_new (commons);
+       gtk_container_add (GTK_CONTAINER (w), territorio);
+
+       /*g_signal_connect (G_OBJECT (decoder), "btn_clean_clicked",
+                         G_CALLBACK (on_btn_clean_clicked), NULL);*/
+
+       gtk_widget_show_all (w);
+
+       gtk_main ();
+
+       return 0;
+}