]> saetta.ns0.it Git - libgtkform/commitdiff
Added open button to GtkFormDecoder.
authorAndrea Zagli <azagli@libero.it>
Sat, 18 Jun 2011 15:37:36 +0000 (17:37 +0200)
committerAndrea Zagli <azagli@libero.it>
Sat, 18 Jun 2011 15:37:36 +0000 (17:37 +0200)
ui/gtkformdecoder.c
ui/gtkformdecoder.h
ui/test/decoder.c

index 96f3e475a0304759509a7d3283520ede42b7c9f6..bf0ba1dd63d8c3a49a28e75ac1a7b1f53c68e6c1 100644 (file)
@@ -27,7 +27,7 @@
 
 #include <sql-parser/gda-sql-parser.h>
 
-#include <libgdaex.h>
+#include <libgdaex/libgdaex.h>
 
 #include "gtkformdecoder.h"
 
@@ -36,7 +36,8 @@ enum
        PROP_0,
        PROP_GDAEX,
        PROP_SQL,
-       PROP_SHOW_CLEAN
+       PROP_SHOW_CLEAN,
+       PROP_SHOW_OPEN
 };
 
 static void gtk_form_decoder_class_init (GtkFormDecoderClass *klass);
@@ -58,14 +59,17 @@ static void gtk_form_decoder_get_property (GObject *object,
                                            GValue *value,
                                            GParamSpec *pspec);
 
-static void gtk_form_decoder_on_btn_browse_clicked (GtkButton *button,
-                                        gpointer user_data);
-
 static void gtk_form_decoder_on_btn_clean_clicked (GtkEntry *entry,
                                          GtkEntryIconPosition icon_pos,
                                          GdkEvent *event,
                                          gpointer user_data);
 
+static void gtk_form_decoder_on_btn_open_clicked (GtkButton *button,
+                                        gpointer user_data);
+
+static void gtk_form_decoder_on_btn_browse_clicked (GtkButton *button,
+                                        gpointer user_data);
+
 static GtkWidgetClass *parent_class = NULL;
 
 
@@ -76,6 +80,7 @@ struct _GtkFormDecoderPrivate
        {
                GtkWidget *hbox;
                GtkWidget *txt_decoded;
+               GtkWidget *btn_open;
                GtkWidget *btn_browse;
                GtkWidget *lbl_key;
 
@@ -124,27 +129,34 @@ gtk_form_decoder_class_init (GtkFormDecoderClass *klass)
                                                               FALSE,
                                                               G_PARAM_READWRITE));
 
+       g_object_class_install_property (object_class, PROP_SHOW_OPEN,
+                                        g_param_spec_boolean ("show-btn-open",
+                                                              "Show open button",
+                                                              "Whether to show the open button",
+                                                              FALSE,
+                                                              G_PARAM_READWRITE));
+
        /**
-        * GtkFormDecoder::btn_browse_clicked:
+        * GtkFormDecoder::btn_clean_clicked:
         * @gtk_form_decoder:
         *
         */
-       klass->btn_browse_clicked_signal_id = g_signal_new ("btn-browse-clicked",
+       klass->btn_clean_clicked_signal_id = g_signal_new ("btn-clean-clicked",
                                                       G_TYPE_FROM_CLASS (object_class),
                                                       G_SIGNAL_RUN_LAST,
                                                       0,
                                                       NULL,
                                                       NULL,
-                                                      g_cclosure_marshal_VOID__VOID,
-                                                      G_TYPE_NONE,
-                                                      0);
+                                                      g_cclosure_marshal_BOOLEAN__FLAGS,
+                                                      G_TYPE_BOOLEAN,
+                                                      1, G_TYPE_INT);
 
        /**
-        * GtkFormDecoder::btn_clean_clicked:
+        * GtkFormDecoder::btn_open_clicked:
         * @gtk_form_decoder:
         *
         */
-       klass->btn_clean_clicked_signal_id = g_signal_new ("btn-clean-clicked",
+       klass->btn_open_clicked_signal_id = g_signal_new ("btn-open-clicked",
                                                       G_TYPE_FROM_CLASS (object_class),
                                                       G_SIGNAL_RUN_LAST,
                                                       0,
@@ -153,6 +165,21 @@ gtk_form_decoder_class_init (GtkFormDecoderClass *klass)
                                                       g_cclosure_marshal_BOOLEAN__FLAGS,
                                                       G_TYPE_BOOLEAN,
                                                       1, G_TYPE_INT);
+
+       /**
+        * GtkFormDecoder::btn_browse_clicked:
+        * @gtk_form_decoder:
+        *
+        */
+       klass->btn_browse_clicked_signal_id = g_signal_new ("btn-browse-clicked",
+                                                      G_TYPE_FROM_CLASS (object_class),
+                                                      G_SIGNAL_RUN_LAST,
+                                                      0,
+                                                      NULL,
+                                                      NULL,
+                                                      g_cclosure_marshal_VOID__VOID,
+                                                      G_TYPE_NONE,
+                                                      0);
 }
 
 static void
@@ -160,7 +187,9 @@ gtk_form_decoder_init (GtkFormDecoder *decoder)
 {
        GtkFormDecoderPrivate *priv = GTK_FORM_DECODER_GET_PRIVATE (decoder);
 
-       priv->hbox = gtk_hbox_new (FALSE, 5);
+       GtkWidget *icon;
+
+       priv->hbox = gtk_hbox_new (FALSE, 3);
        gtk_container_add (GTK_CONTAINER (decoder), priv->hbox);
        gtk_widget_show (priv->hbox);
 
@@ -172,7 +201,20 @@ gtk_form_decoder_init (GtkFormDecoder *decoder)
        g_signal_connect (G_OBJECT (priv->txt_decoded), "icon-press",
                          G_CALLBACK (gtk_form_decoder_on_btn_clean_clicked), (gpointer)decoder);
 
+       priv->btn_open = gtk_button_new ();
+       gtk_widget_set_tooltip_text (priv->btn_open, "Open");
+       gtk_box_pack_start (GTK_BOX (priv->hbox), priv->btn_open, FALSE, FALSE, 0);
+       gtk_widget_set_no_show_all (priv->btn_open, TRUE);
+       icon = gtk_image_new_from_stock ("gtk-open", GTK_ICON_SIZE_MENU);
+       gtk_container_add (GTK_CONTAINER (priv->btn_open), icon);
+       gtk_widget_show (icon);
+       gtk_widget_show (priv->btn_open);
+
+       g_signal_connect (G_OBJECT (priv->btn_open), "clicked",
+                         G_CALLBACK (gtk_form_decoder_on_btn_open_clicked), (gpointer)decoder);
+
        priv->btn_browse = gtk_button_new_with_label ("...");
+       gtk_widget_set_tooltip_text (priv->btn_browse, "Find");
        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);
@@ -334,6 +376,14 @@ gtk_form_decoder_show_btn_clean (GtkFormDecoder *decoder, gboolean visible)
        gtk_entry_set_icon_sensitive (GTK_ENTRY (priv->txt_decoded), GTK_ENTRY_ICON_SECONDARY, visible);
 }
 
+static void
+gtk_form_decoder_show_btn_open (GtkFormDecoder *decoder, gboolean visible)
+{
+       GtkFormDecoderPrivate *priv = GTK_FORM_DECODER_GET_PRIVATE (decoder);
+
+       gtk_widget_set_visible (priv->btn_open, visible);
+}
+
 /* CALLBACKS */
 static void
 gtk_form_decoder_set_property (GObject *object, guint property_id, const GValue *value, GParamSpec *pspec)
@@ -367,6 +417,10 @@ gtk_form_decoder_set_property (GObject *object, guint property_id, const GValue
                                gtk_form_decoder_show_btn_clean (decoder, g_value_get_boolean (value));
                                break;
 
+                       case PROP_SHOW_OPEN:
+                               gtk_form_decoder_show_btn_open (decoder, g_value_get_boolean (value));
+                               break;
+
                        default:
                                G_OBJECT_WARN_INVALID_PROPERTY_ID (object, property_id, pspec);
                                break;
@@ -393,6 +447,10 @@ gtk_form_decoder_get_property (GObject *object, guint property_id, GValue *value
                                g_value_set_boolean (value, gtk_entry_get_icon_stock (GTK_ENTRY (priv->txt_decoded), GTK_ENTRY_ICON_SECONDARY) != NULL);
                                break;
 
+                       case PROP_SHOW_OPEN:
+                               g_value_set_boolean (value, gtk_widget_get_visible (priv->btn_open));
+                               break;
+
                        default:
                                G_OBJECT_WARN_INVALID_PROPERTY_ID (object, property_id, pspec);
                                break;
@@ -465,15 +523,6 @@ gtk_form_decoder_size_allocate (GtkWidget *widget,
                }
 }
 
-static void
-gtk_form_decoder_on_btn_browse_clicked (GtkButton *button,
-                                        gpointer user_data)
-{
-       GtkFormDecoderClass *klass = GTK_FORM_DECODER_GET_CLASS ((GtkFormDecoder *)user_data);
-
-       g_signal_emit (G_OBJECT (user_data), klass->btn_browse_clicked_signal_id, 0);
-}
-
 static void
 gtk_form_decoder_on_btn_clean_clicked (GtkEntry *entry,
                                        GtkEntryIconPosition icon_pos,
@@ -494,3 +543,21 @@ gtk_form_decoder_on_btn_clean_clicked (GtkEntry *entry,
                        gtk_form_decoder_set_key (decoder, "0");
                }
 }
+
+static void
+gtk_form_decoder_on_btn_open_clicked (GtkButton *button,
+                                        gpointer user_data)
+{
+       GtkFormDecoderClass *klass = GTK_FORM_DECODER_GET_CLASS ((GtkFormDecoder *)user_data);
+
+       g_signal_emit (G_OBJECT (user_data), klass->btn_open_clicked_signal_id, 0);
+}
+
+static void
+gtk_form_decoder_on_btn_browse_clicked (GtkButton *button,
+                                        gpointer user_data)
+{
+       GtkFormDecoderClass *klass = GTK_FORM_DECODER_GET_CLASS ((GtkFormDecoder *)user_data);
+
+       g_signal_emit (G_OBJECT (user_data), klass->btn_browse_clicked_signal_id, 0);
+}
index 8e1640ce41b97476d461e1be06bcb50c5a045e9d..92fb3ef55555178904fdf3b79562f8c6fe69b1f3 100644 (file)
@@ -48,8 +48,9 @@ struct _GtkFormDecoderClass
 {
        GtkBinClass parent_class;
 
-       guint btn_browse_clicked_signal_id;
        guint btn_clean_clicked_signal_id;
+       guint btn_open_clicked_signal_id;
+       guint btn_browse_clicked_signal_id;
 };
 
 
index bd6512d89f553c751b1dd9dc89a666ac518b276a..f93f62966770df19872c75ca3ff00e6acae602f0 100644 (file)
@@ -18,7 +18,7 @@
 
 #include <gtk/gtk.h>
 
-#include <libgdaex.h>
+#include <libgdaex/libgdaex.h>
 
 #include "gtkformdecoder.h"
 
@@ -27,16 +27,22 @@ GtkWidget *decoder;
 
 GdaEx *gdaex;
 
+static gboolean
+on_btn_clean_clicked (gpointer instance, gint arg1, gpointer user_data)
+{
+       return FALSE;
+}
+
 static void
-on_btn_browse_clicked (gpointer instance, gpointer user_data)
+on_btn_open_clicked (gpointer instance, gpointer user_data)
 {
-       gtk_form_decoder_set_key (GTK_FORM_DECODER (decoder), "1");
+       g_debug ("Open clicked.");
 }
 
-static gboolean
-on_btn_clean_clicked (gpointer instance, gint arg1, gpointer user_data)
+static void
+on_btn_browse_clicked (gpointer instance, gpointer user_data)
 {
-       return FALSE;
+       gtk_form_decoder_set_key (GTK_FORM_DECODER (decoder), "1");
 }
 
 gboolean
@@ -71,12 +77,15 @@ main (int argc, char **argv)
                             " FROM customers"
                             " WHERE id = ##key0::gint",
                      "show-btn-clean", TRUE,
+                     "show-btn-open", TRUE,
                      NULL);
 
-       g_signal_connect (G_OBJECT (decoder), "btn_browse_clicked",
-                         G_CALLBACK (on_btn_browse_clicked), NULL);
        g_signal_connect (G_OBJECT (decoder), "btn_clean_clicked",
                          G_CALLBACK (on_btn_clean_clicked), NULL);
+       g_signal_connect (G_OBJECT (decoder), "btn_open_clicked",
+                         G_CALLBACK (on_btn_open_clicked), NULL);
+       g_signal_connect (G_OBJECT (decoder), "btn_browse_clicked",
+                         G_CALLBACK (on_btn_browse_clicked), NULL);
 
        gtk_widget_show_all (w);