summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMatthias Clasen <mclasen@redhat.com>2015-02-08 21:03:34 +0100
committerMatthias Clasen <mclasen@redhat.com>2015-02-10 06:57:48 -0500
commit5471365b07f24e9deb1021c030674b0953a0c830 (patch)
tree5efa3d771d848c1dd230178c9c4376a8ea9e838c
parent8e7088342d19b2fb228cdac0f311d6c5ca6a69da (diff)
downloadgtk+-wip/combo.tar.gz
option list: Underline matcheswip/combo
When using search in an option list, show matches in the list. This commit is just a proof-of-concept, it needs more work to be utf8-safe.
-rw-r--r--gtk/gtkoptionlist.c46
1 files changed, 35 insertions, 11 deletions
diff --git a/gtk/gtkoptionlist.c b/gtk/gtkoptionlist.c
index 759440d0cc..bee1d3c717 100644
--- a/gtk/gtkoptionlist.c
+++ b/gtk/gtkoptionlist.c
@@ -382,21 +382,45 @@ static gboolean
gtk_option_list_row_matches (GtkOptionListRow *row,
const gchar *match)
{
- gchar *row_text;
- gchar *search_text;
- gchar *hit;
+ gchar *hit = NULL;
+ PangoAttrList *attrs = NULL;
+ gboolean ret = TRUE;
- if (match[0] == '\0')
- return TRUE;
+ if (match[0] != '\0')
+ {
+ gchar *row_text;
+ gchar *search_text;
+
+ row_text = g_utf8_strdown (row->text, -1);
+ search_text = g_utf8_strdown (match, -1);
+
+ hit = strstr (row_text, search_text);
+ ret = hit != NULL;
- row_text = g_utf8_strdown (row->text, -1);
- search_text = g_utf8_strdown (match, -1);
- hit = strstr (row_text, search_text);
+ if (hit != NULL)
+ {
+ gint offset;
+ gint length;
+ PangoAttribute *attr;
+
+ /* FIXME: this is not utf8 safe */
+ offset = hit - row_text;
+ length = strlen (match);
+
+ attrs = pango_attr_list_new ();
+ attr = pango_attr_underline_new (PANGO_UNDERLINE_SINGLE);
+ attr->start_index = offset;
+ attr->end_index = offset + length;
+ pango_attr_list_insert (attrs, attr);
+ }
+
+ g_free (row_text);
+ g_free (search_text);
+ }
- g_free (row_text);
- g_free (search_text);
+ gtk_label_set_attributes (GTK_LABEL (row->label), attrs);
- return hit != NULL;
+ return ret;
}
static const gchar *