static gboolean gtk_form_decoder_on_decoded_focus_out_event (GtkWidget *widget,
GdkEvent *event,
gpointer user_data);
+static gboolean gtk_form_decoder_match_func (GtkEntryCompletion *completion,
+ const gchar *key,
+ GtkTreeIter *iter,
+ gpointer user_data);
static GtkWidgetClass *parent_class = NULL;
guint completion_text_column;
guint completion_key_column;
gboolean completion_only_valid_values;
+ gboolean completion_search_inside;
gulong completion_focus_out_handler_id;
};
priv->completion_key_column = 0;
priv->completion_text_column = 0;
priv->completion_only_valid_values = FALSE;
+ priv->completion_search_inside = FALSE;
priv->completion_focus_out_handler_id = 0;
}
GdaDataModel *data_model,
guint key_column,
guint text_column,
- gboolean only_valid_values)
+ gboolean only_valid_values,
+ gboolean search_inside)
{
gchar *_sql;
priv->completion_text_column = 0;
priv->completion_key_column = 0;
priv->completion_only_valid_values = FALSE;
+ priv->completion_search_inside = FALSE;
gtk_entry_set_completion (GTK_ENTRY (priv->txt_decoded), NULL);
gtk_editable_set_editable (GTK_EDITABLE (priv->txt_decoded), FALSE);
gtk_entry_completion_set_minimum_key_length (completion, 3);
gtk_entry_completion_set_text_column (completion, priv->completion_text_column);
+ priv->completion_search_inside = search_inside;
+ if (priv->completion_search_inside)
+ {
+ gtk_entry_completion_set_match_func (completion,
+ gtk_form_decoder_match_func,
+ (gpointer)decoder,
+ NULL);
+ }
+
gtk_editable_set_editable (GTK_EDITABLE (priv->txt_decoded), TRUE);
priv->completion_only_valid_values = only_valid_values;
gchar *decoded;
gchar *decoded_casefold;
+ gchar *value_casefold;
gboolean found;
priv->completion_key_column, key);
gtk_tree_model_get_value (model, &iter,
priv->completion_text_column, value);
- if (g_strcmp0 (decoded_casefold, g_utf8_casefold (gda_value_stringify (value), -1)) == 0)
+ value_casefold = g_utf8_casefold (gda_value_stringify (value), -1);
+ if (g_strcmp0 (decoded_casefold, value_casefold) == 0)
{
gtk_form_decoder_set_key (decoder, gda_value_stringify (key));
found = TRUE;
g_value_unset (key);
g_value_unset (value);
+ g_free (value_casefold);
break;
}
g_value_unset (key);
g_value_unset (value);
+ g_free (value_casefold);
} while (gtk_tree_model_iter_next (model, &iter));
if (!found)
return FALSE;
}
+
+static gboolean
+gtk_form_decoder_match_func (GtkEntryCompletion *completion,
+ const gchar *key,
+ GtkTreeIter *iter,
+ gpointer user_data)
+{
+ gchar *item;
+ gchar *item_down;
+ gchar *decoded;
+ gchar *decoded_down;
+
+ gboolean ret;
+
+ GtkTreeModel *model;
+
+ GtkFormDecoder *decoder = (GtkFormDecoder *)user_data;
+ GtkFormDecoderPrivate *priv = GTK_FORM_DECODER_GET_PRIVATE (decoder);
+
+ model = gtk_entry_completion_get_model (GTK_ENTRY_COMPLETION (completion));
+ if (model == NULL)
+ {
+ return FALSE;
+ }
+
+ ret = FALSE;
+
+ gtk_tree_model_get (model, iter,
+ priv->completion_text_column, &item,
+ -1);
+
+ if (item != NULL)
+ {
+ item_down = g_utf8_strdown (item, -1);
+
+ decoded = (gchar *)gtk_entry_get_text (GTK_ENTRY (priv->txt_decoded));
+ if (decoded == NULL)
+ {
+ gtk_form_decoder_set_key (decoder, "0");
+ g_free (item_down);
+ return FALSE;
+ }
+ decoded = g_strdup (decoded);
+ g_strstrip (decoded);
+ if (g_strcmp0 (decoded, "") == 0)
+ {
+ gtk_form_decoder_set_key (decoder, "0");
+ g_free (decoded);
+ g_free (item_down);
+ return FALSE;
+ }
+
+ decoded_down = g_utf8_strdown (decoded, -1);
+
+ if (g_strstr_len (item_down, -1, decoded_down) != NULL)
+ {
+ ret = TRUE;
+ }
+
+ g_free (decoded);
+ g_free (decoded_down);
+ g_free (item_down);
+ g_free (item);
+ }
+
+ return ret;
+}