]> saetta.ns0.it Git - libgtkform/commitdiff
Added property GtkFormDecoder::show-btn-clean.
authorAndrea Zagli <azagli@libero.it>
Sun, 1 May 2011 07:17:42 +0000 (09:17 +0200)
committerAndrea Zagli <azagli@libero.it>
Sun, 1 May 2011 07:17:42 +0000 (09:17 +0200)
ui/gtkformdecoder.c
ui/gtkformdecoder.h
ui/test/decoder.c

index e3c24211a113c2303be249a79359c4c80d7a9a9e..b279bda8ba5d33119616917c01bbf2d6ead32165 100644 (file)
@@ -35,7 +35,8 @@ enum
 {
        PROP_0,
        PROP_GDAEX,
-       PROP_SQL
+       PROP_SQL,
+       PROP_SHOW_CLEAN
 };
 
 static void gtk_form_decoder_class_init (GtkFormDecoderClass *klass);
@@ -60,6 +61,11 @@ static void gtk_form_decoder_get_property (GObject *object,
 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 GtkWidgetClass *parent_class = NULL;
 
 
@@ -111,6 +117,13 @@ gtk_form_decoder_class_init (GtkFormDecoderClass *klass)
                                                              NULL,
                                                              G_PARAM_READWRITE | G_PARAM_CONSTRUCT));
 
+       g_object_class_install_property (object_class, PROP_SHOW_CLEAN,
+                                        g_param_spec_boolean ("show-btn-clean",
+                                                              "Show clean icon",
+                                                              "Whether to show the clean icon",
+                                                              FALSE,
+                                                              G_PARAM_READWRITE));
+
        /**
         * GtkFormDecoder::btn_browse_clicked:
         * @gtk_form_decoder:
@@ -141,6 +154,9 @@ gtk_form_decoder_init (GtkFormDecoder *decoder)
        gtk_editable_set_editable (GTK_EDITABLE (priv->txt_decoded), FALSE);
        gtk_widget_show (priv->txt_decoded);
 
+       g_signal_connect (G_OBJECT (priv->txt_decoded), "icon-press",
+                         G_CALLBACK (gtk_form_decoder_on_btn_clean_clicked), (gpointer)decoder);
+
        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);
@@ -293,6 +309,16 @@ gtk_form_decoder_decode (GtkFormDecoder *decoder)
                }
 }
 
+static void
+gtk_form_decoder_show_btn_clean (GtkFormDecoder *decoder, gboolean visible)
+{
+       GtkFormDecoderPrivate *priv = GTK_FORM_DECODER_GET_PRIVATE (decoder);
+
+       gtk_entry_set_icon_from_stock (GTK_ENTRY (priv->txt_decoded), GTK_ENTRY_ICON_SECONDARY, "gtk-clear");
+       gtk_entry_set_icon_activatable (GTK_ENTRY (priv->txt_decoded), GTK_ENTRY_ICON_SECONDARY, TRUE);
+       gtk_entry_set_icon_sensitive (GTK_ENTRY (priv->txt_decoded), GTK_ENTRY_ICON_SECONDARY, TRUE);
+}
+
 /* CALLBACKS */
 static void
 gtk_form_decoder_set_property (GObject *object, guint property_id, const GValue *value, GParamSpec *pspec)
@@ -322,6 +348,10 @@ gtk_form_decoder_set_property (GObject *object, guint property_id, const GValue
                                        }
                                break;
 
+                       case PROP_SHOW_CLEAN:
+                               gtk_form_decoder_show_btn_clean (decoder, g_value_get_boolean (value));
+                               break;
+
                        default:
                                G_OBJECT_WARN_INVALID_PROPERTY_ID (object, property_id, pspec);
                                break;
@@ -344,6 +374,10 @@ gtk_form_decoder_get_property (GObject *object, guint property_id, GValue *value
                                g_value_set_string (value, priv->sql);
                                break;
 
+                       case PROP_SHOW_CLEAN:
+                               g_value_set_boolean (value, gtk_entry_get_icon_stock (GTK_ENTRY (priv->txt_decoded), GTK_ENTRY_ICON_SECONDARY) != NULL);
+                               break;
+
                        default:
                                G_OBJECT_WARN_INVALID_PROPERTY_ID (object, property_id, pspec);
                                break;
@@ -424,3 +458,16 @@ gtk_form_decoder_on_btn_browse_clicked (GtkButton *button,
 
        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,
+                                       GdkEvent *event,
+                                       gpointer user_data)
+{
+       GtkFormDecoder *decoder = (GtkFormDecoder *)user_data;
+       GtkFormDecoderPrivate *priv = GTK_FORM_DECODER_GET_PRIVATE (decoder);
+       GtkFormDecoderClass *klass = GTK_FORM_DECODER_GET_CLASS (decoder);
+
+       gtk_form_decoder_set_key (decoder, "0");
+}
index 0f419ffdfadd073894a6fe130a6a53a8573c154d..8e1640ce41b97476d461e1be06bcb50c5a045e9d 100644 (file)
@@ -49,6 +49,7 @@ struct _GtkFormDecoderClass
        GtkBinClass parent_class;
 
        guint btn_browse_clicked_signal_id;
+       guint btn_clean_clicked_signal_id;
 };
 
 
index fe69842808fe3e9fafc4dd73e776dce9925386e8..917cf3a96513f19b88235e99ffdd0c708b755345 100644 (file)
@@ -64,6 +64,7 @@ main (int argc, char **argv)
                      "sql", "SELECT name"
                             " FROM customers"
                             " WHERE id = ##key0::gint",
+                     "show-btn-clean", TRUE,
                      NULL);
 
        g_signal_connect (G_OBJECT (decoder), "btn_browse_clicked",