From a8e1fecac86b22ceb5088727cb84646765c59d94 Mon Sep 17 00:00:00 2001 From: Andrea Zagli Date: Sun, 1 May 2011 09:17:42 +0200 Subject: [PATCH] Added property GtkFormDecoder::show-btn-clean. --- ui/gtkformdecoder.c | 49 ++++++++++++++++++++++++++++++++++++++++++++- ui/gtkformdecoder.h | 1 + ui/test/decoder.c | 1 + 3 files changed, 50 insertions(+), 1 deletion(-) diff --git a/ui/gtkformdecoder.c b/ui/gtkformdecoder.c index e3c2421..b279bda 100644 --- a/ui/gtkformdecoder.c +++ b/ui/gtkformdecoder.c @@ -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"); +} diff --git a/ui/gtkformdecoder.h b/ui/gtkformdecoder.h index 0f419ff..8e1640c 100644 --- a/ui/gtkformdecoder.h +++ b/ui/gtkformdecoder.h @@ -49,6 +49,7 @@ struct _GtkFormDecoderClass GtkBinClass parent_class; guint btn_browse_clicked_signal_id; + guint btn_clean_clicked_signal_id; }; diff --git a/ui/test/decoder.c b/ui/test/decoder.c index fe69842..917cf3a 100644 --- a/ui/test/decoder.c +++ b/ui/test/decoder.c @@ -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", -- 2.49.0