]> saetta.ns0.it Git - libgtkform/commitdiff
On GtkFormDecoder added the "new" button (closes #122).
authorAndrea Zagli <a.zagli@comune.scandicci.fi.it>
Thu, 20 Oct 2011 15:06:57 +0000 (17:06 +0200)
committerAndrea Zagli <a.zagli@comune.scandicci.fi.it>
Thu, 20 Oct 2011 15:06:57 +0000 (17:06 +0200)
libgtkformui/gtkformdecoder.c
libgtkformui/gtkformdecoder.h
libgtkformui/test/decoder.c

index fd6256afc328e20969d0c11c2eb5f2795f335c98..fa8f9c7ef50ac782345a9ce7d1610c02ef0fa325 100644 (file)
@@ -37,6 +37,7 @@ enum
        PROP_GDAEX,
        PROP_SQL,
        PROP_SHOW_CLEAN,
+       PROP_SHOW_NEW,
        PROP_SHOW_OPEN,
        PROP_SHOW_BROWSE
 };
@@ -65,6 +66,9 @@ static void gtk_form_decoder_on_btn_clean_clicked (GtkEntry *entry,
                                          GdkEvent *event,
                                          gpointer user_data);
 
+static void gtk_form_decoder_on_btn_new_clicked (GtkButton *button,
+                                        gpointer user_data);
+
 static void gtk_form_decoder_on_btn_open_clicked (GtkButton *button,
                                         gpointer user_data);
 
@@ -93,6 +97,7 @@ struct _GtkFormDecoderPrivate
        {
                GtkWidget *hbox;
                GtkWidget *txt_decoded;
+               GtkWidget *btn_new;
                GtkWidget *btn_open;
                GtkWidget *btn_browse;
                GtkWidget *lbl_key;
@@ -149,6 +154,13 @@ gtk_form_decoder_class_init (GtkFormDecoderClass *klass)
                                                               FALSE,
                                                               G_PARAM_READWRITE));
 
+       g_object_class_install_property (object_class, PROP_SHOW_NEW,
+                                        g_param_spec_boolean ("show-btn-new",
+                                                              "Show new button",
+                                                              "Whether to show the new button",
+                                                              FALSE,
+                                                              G_PARAM_READWRITE));
+
        g_object_class_install_property (object_class, PROP_SHOW_OPEN,
                                         g_param_spec_boolean ("show-btn-open",
                                                               "Show open button",
@@ -178,6 +190,21 @@ gtk_form_decoder_class_init (GtkFormDecoderClass *klass)
                                                       G_TYPE_BOOLEAN,
                                                       1, G_TYPE_INT);
 
+       /**
+        * GtkFormDecoder::btn_new_clicked:
+        * @gtk_form_decoder:
+        *
+        */
+       klass->btn_new_clicked_signal_id = g_signal_new ("btn-new-clicked",
+                                                      G_TYPE_FROM_CLASS (object_class),
+                                                      G_SIGNAL_RUN_LAST,
+                                                      0,
+                                                      NULL,
+                                                      NULL,
+                                                      g_cclosure_marshal_VOID__VOID,
+                                                      G_TYPE_NONE,
+                                                      0);
+
        /**
         * GtkFormDecoder::btn_open_clicked:
         * @gtk_form_decoder:
@@ -216,7 +243,7 @@ gtk_form_decoder_init (GtkFormDecoder *decoder)
 
        GtkWidget *icon;
 
-       priv->hbox = gtk_hbox_new (FALSE, 3);
+       priv->hbox = gtk_hbox_new (FALSE, 1);
        gtk_container_add (GTK_CONTAINER (decoder), priv->hbox);
        gtk_widget_show (priv->hbox);
 
@@ -228,6 +255,17 @@ 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_new = gtk_button_new ();
+       gtk_widget_set_tooltip_text (priv->btn_new, _("New"));
+       gtk_box_pack_start (GTK_BOX (priv->hbox), priv->btn_new, FALSE, FALSE, 0);
+       gtk_widget_set_no_show_all (priv->btn_new, TRUE);
+       icon = gtk_image_new_from_stock ("gtk-new", GTK_ICON_SIZE_MENU);
+       gtk_container_add (GTK_CONTAINER (priv->btn_new), icon);
+       gtk_widget_show (icon);
+
+       g_signal_connect (G_OBJECT (priv->btn_new), "clicked",
+                         G_CALLBACK (gtk_form_decoder_on_btn_new_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);
@@ -445,6 +483,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);
 }
 
+void
+gtk_form_decoder_show_btn_new (GtkFormDecoder *decoder, gboolean visible)
+{
+       GtkFormDecoderPrivate *priv = GTK_FORM_DECODER_GET_PRIVATE (decoder);
+
+       gtk_widget_set_visible (priv->btn_new, visible);
+}
+
 void
 gtk_form_decoder_show_btn_open (GtkFormDecoder *decoder, gboolean visible)
 {
@@ -469,6 +515,14 @@ gtk_form_decoder_btn_clean_is_visible (GtkFormDecoder *decoder)
        return gtk_entry_get_icon_stock (GTK_ENTRY (priv->txt_decoded), GTK_ENTRY_ICON_SECONDARY) != NULL;
 }
 
+gboolean
+gtk_form_decoder_btn_new_is_visible (GtkFormDecoder *decoder)
+{
+       GtkFormDecoderPrivate *priv = GTK_FORM_DECODER_GET_PRIVATE (decoder);
+
+       return gtk_widget_get_visible (priv->btn_new);
+}
+
 gboolean
 gtk_form_decoder_btn_open_is_visible (GtkFormDecoder *decoder)
 {
@@ -621,6 +675,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_NEW:
+                               gtk_form_decoder_show_btn_new (decoder, g_value_get_boolean (value));
+                               break;
+
                        case PROP_SHOW_OPEN:
                                gtk_form_decoder_show_btn_open (decoder, g_value_get_boolean (value));
                                break;
@@ -655,6 +713,10 @@ gtk_form_decoder_get_property (GObject *object, guint property_id, GValue *value
                                g_value_set_boolean (value, gtk_form_decoder_btn_clean_is_visible (decoder));
                                break;
 
+                       case PROP_SHOW_NEW:
+                               g_value_set_boolean (value, gtk_form_decoder_btn_new_is_visible (decoder));
+                               break;
+
                        case PROP_SHOW_OPEN:
                                g_value_set_boolean (value, gtk_form_decoder_btn_open_is_visible (decoder));
                                break;
@@ -756,6 +818,15 @@ gtk_form_decoder_on_btn_clean_clicked (GtkEntry *entry,
                }
 }
 
+static void
+gtk_form_decoder_on_btn_new_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_new_clicked_signal_id, 0);
+}
+
 static void
 gtk_form_decoder_on_btn_open_clicked (GtkButton *button,
                                         gpointer user_data)
index c3fc9046e90edbc76ea3e092cc052efb927abf2c..73cf5e411459cdf37fb0ee8f014ab0065324b3c6 100644 (file)
@@ -49,6 +49,7 @@ struct _GtkFormDecoderClass
        GtkBinClass parent_class;
 
        guint btn_clean_clicked_signal_id;
+       guint btn_new_clicked_signal_id;
        guint btn_open_clicked_signal_id;
        guint btn_browse_clicked_signal_id;
 };
@@ -64,10 +65,12 @@ gchar *gtk_form_decoder_get_key (GtkFormDecoder *decoder);
 gchar *gtk_form_decoder_get_decoded (GtkFormDecoder *decoder);
 
 void gtk_form_decoder_show_btn_clean (GtkFormDecoder *decoder, gboolean visible);
+void gtk_form_decoder_show_btn_new (GtkFormDecoder *decoder, gboolean visible);
 void gtk_form_decoder_show_btn_open (GtkFormDecoder *decoder, gboolean visible);
 void gtk_form_decoder_show_btn_browse (GtkFormDecoder *decoder, gboolean visible);
 
 gboolean gtk_form_decoder_btn_clean_is_visible (GtkFormDecoder *decoder);
+gboolean gtk_form_decoder_btn_new_is_visible (GtkFormDecoder *decoder);
 gboolean gtk_form_decoder_btn_open_is_visible (GtkFormDecoder *decoder);
 gboolean gtk_form_decoder_btn_browse_is_visible (GtkFormDecoder *decoder);
 
index 626f16e21ca84ec3ad8a0043c063ed363472fb39..0417a59fc4231cd9b349cf30001aa58d34a6f2d5 100644 (file)
@@ -33,16 +33,25 @@ on_btn_clean_clicked (gpointer instance, gint arg1, gpointer user_data)
        return FALSE;
 }
 
-static void
+static gboolean
+on_btn_new_clicked (gpointer instance, gpointer user_data)
+{
+       g_debug ("New clicked.");
+       return FALSE;
+}
+
+static gboolean
 on_btn_open_clicked (gpointer instance, gpointer user_data)
 {
        g_debug ("Open clicked.");
+       return FALSE;
 }
 
-static void
+static gboolean
 on_btn_browse_clicked (gpointer instance, gpointer user_data)
 {
        gtk_form_decoder_set_key (GTK_FORM_DECODER (decoder), "1");
+       return FALSE;
 }
 
 gboolean
@@ -77,6 +86,7 @@ main (int argc, char **argv)
                             " FROM customers"
                             " WHERE id = ##key0::gint",
                      "show-btn-clean", TRUE,
+                     "show-btn-new", TRUE,
                      "show-btn-open", TRUE,
                      NULL);
 
@@ -87,6 +97,8 @@ main (int argc, char **argv)
 
        g_signal_connect (G_OBJECT (decoder), "btn_clean_clicked",
                          G_CALLBACK (on_btn_clean_clicked), NULL);
+       g_signal_connect (G_OBJECT (decoder), "btn_new_clicked",
+                         G_CALLBACK (on_btn_new_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",