...and also attach the patch  :)

----- "Dave Andreoli" <[EMAIL PROTECTED]> ha scritto:

> Attached a patch that fix (or almost redone) the autosearch feature of
> comboboxs, the patch also fix etk_test that was broken on the
> searchable combobox.
> 
> Changes done:
> 1. moved the search code from etk_test to inside etk_combobox_entry,
> so that everyone can use it.
> 
> 2. add 2 new field to the Etk_Combobox_Entry struct:
>    int autosearch_enable;
>    int autosearch_column;
> 
> 3. add 2 new API functions to etk_combobox_entry:
>    void etk_combobox_entry_autosearch_enable_set(Etk_Combobox_Entry
> *combobox_entry, int enable);
>    void etk_combobox_entry_autosearch_column_set(Etk_Combobox_Entry
> *combobox_entry, int col_num);
>    The first will enable/disable autosearch and the second tell witch
> is the combo-column to use for searching.
> 
> 4. Changed the way the focus is handled between the 2 windows (the
> combo-entry-win and the combo-popup-win) so that you don't need an
> etk_window as the base window.
> 
> 4. The searching code is different from the actual code, the new one
> don't split up words but simply search the typed string in the
> entries.
> 
> 5. Fixed a small bug in the current code that couse the "up" key to
> not work well
> 
> 
> Hope you like it :)
> Dave
> 
> -------------------------------------------------------------------------
> Sponsored by: SourceForge.net Community Choice Awards: VOTE NOW!
> Studies have shown that voting for your favorite open source project,
> along with a healthy diet, reduces your potential for chronic
> lameness
> and boredom. Vote Now at http://www.sourceforge.net/community/cca08
> _______________________________________________
> enlightenment-devel mailing list
> enlightenment-devel@lists.sourceforge.net
> https://lists.sourceforge.net/lists/listinfo/enlightenment-devel
Index: src/bin/etk_combobox_test.c
===================================================================
RCS file: /cvs/e/e17/libs/etk/src/bin/etk_combobox_test.c,v
retrieving revision 1.22
diff -u -u -r1.22 etk_combobox_test.c
--- src/bin/etk_combobox_test.c	2 Oct 2007 15:29:56 -0000	1.22
+++ src/bin/etk_combobox_test.c	13 Jul 2008 12:59:51 -0000
@@ -13,6 +13,7 @@
 static Etk_Bool _active_item_changed_cb(Etk_Object *object, void *data);
 static void _etk_combobox_entry_populate(Etk_Combobox_Entry *combobox_entry, char *dir);
 static Etk_Bool _etk_combobox_entry_active_item_changed_cb(Etk_Object *object, void *data);
+static Etk_Bool _etk_combobox_entry_autosearch_active_item_changed_cb(Etk_Object *object, void *data);
 static Etk_Bool _etk_combobox_entry_text_changed_cb(Etk_Object *object, void *data);
 static char **str_split(char **str, char *delim);
 
@@ -101,11 +102,12 @@
    etk_box_append(ETK_BOX(vbox), frame, ETK_BOX_START, ETK_BOX_NONE, 0);
 
    combobox = etk_combobox_entry_new_default();
+   etk_combobox_entry_autosearch_enable_set(ETK_COMBOBOX_ENTRY(combobox), ETK_TRUE);
 
    for (i = 0; _keywords[i]; i++)
      etk_combobox_entry_item_append(ETK_COMBOBOX_ENTRY(combobox), _keywords[i], NULL);
 
-   etk_signal_connect_by_code(ETK_ENTRY_TEXT_CHANGED_SIGNAL, ETK_OBJECT(etk_combobox_entry_entry_get(ETK_COMBOBOX_ENTRY(combobox))), ETK_CALLBACK(_etk_combobox_entry_text_changed_cb), combobox);
+   etk_signal_connect_by_code(ETK_COMBOBOX_ENTRY_ACTIVE_ITEM_CHANGED_SIGNAL, ETK_OBJECT(combobox), ETK_CALLBACK(_etk_combobox_entry_autosearch_active_item_changed_cb), NULL);
    etk_container_add(ETK_CONTAINER(frame), combobox);
 
    /*******************
@@ -277,68 +279,19 @@
    return ETK_TRUE;
 }
 
-static Etk_Bool _etk_combobox_entry_text_changed_cb(Etk_Object *object, void *data)
+static Etk_Bool _etk_combobox_entry_autosearch_active_item_changed_cb(Etk_Object *object, void *data)
 {
-   Etk_Combobox_Entry *combobox;
-   Etk_Entry *entry;
-   char *search_str = NULL;
-   const char *entry_text = NULL;
-   char **words = NULL;
-   int i;
+   Etk_Combobox_Entry *combobox_entry;
+   Etk_Combobox_Entry_Item *active_item = NULL;
+   const char *field;
 
-   if (!(combobox = ETK_COMBOBOX_ENTRY(data)) || !(entry = ETK_ENTRY(object)))
+   if (!(combobox_entry = ETK_COMBOBOX_ENTRY(object)) || !(active_item = etk_combobox_entry_active_item_get(combobox_entry)))
       return ETK_TRUE;
 
-   if (!etk_combobox_entry_is_popped_up(combobox))
-     {
-	etk_combobox_entry_pop_up(combobox);
-	etk_popup_window_focused_window_set(ETK_POPUP_WINDOW(win));
-     }
+   field = etk_combobox_entry_item_field_get(active_item, 0);
+   etk_entry_text_set(ETK_ENTRY(combobox_entry->entry), field);
 
-   entry_text = etk_entry_text_get(entry);
-   if (!entry_text)
-     return ETK_TRUE;
-
-   search_str = strdup(entry_text);
-   words = str_split(&search_str, " ");
-
-   etk_combobox_entry_clear(combobox);
-   etk_combobox_entry_pop_down(combobox);
-   for (i = 0; _keywords[i]; i++)
-     {
-	int j;
-
-	for (j = 0; words[j]; j++)
-	  {
-	     if (!strcasestr(_keywords[i], words[j]))
-	       goto brk;
-	  }
-	etk_combobox_entry_item_append(combobox, _keywords[i], NULL);
-brk:
-	continue;
-     }
-   etk_combobox_entry_pop_up(combobox);
-   etk_popup_window_focused_window_set(ETK_POPUP_WINDOW(win));
-   if (words)
-      free(words);
    return ETK_TRUE;
 }
 
-static char **str_split(char **str, char *delim)
-{
-   char **tok;
-   int  i = 0;
-   char *t;
-
-   tok = calloc(2048, sizeof(char*));
-   tok[i] = strtok(*str, delim);
-   i++;
-   while((t = strtok(NULL, delim)))
-     {
-	tok[i] = t;
-	i++;
-     }
-   tok[i] = NULL;
 
-   return tok;
-}
Index: src/lib/etk_combobox_entry.c
===================================================================
RCS file: /cvs/e/e17/libs/etk/src/lib/etk_combobox_entry.c,v
retrieving revision 1.13
diff -u -u -r1.13 etk_combobox_entry.c
--- src/lib/etk_combobox_entry.c	10 Apr 2008 16:50:13 -0000	1.13
+++ src/lib/etk_combobox_entry.c	13 Jul 2008 12:59:51 -0000
@@ -57,12 +57,14 @@
 static Etk_Bool _etk_combobox_entry_key_down_cb(Etk_Object *object, Etk_Event_Key_Down *event, void *data);
 static Etk_Bool _etk_combobox_entry_hbox_mouse_up_cb(Etk_Object *object, Etk_Event_Mouse_Up *event, void *data);
 static Etk_Bool _etk_combobox_entry_button_toggled_cb(Etk_Object *object, void *data);
+static Etk_Bool _etk_combobox_entry_button_pressed_cb(Etk_Object *object, void *data);
 static Etk_Bool _etk_combobox_entry_entry_key_down_cb(Etk_Object *object, Etk_Event_Key_Down *event, void *data);
 static Etk_Bool _etk_combobox_entry_window_popped_down_cb(Etk_Object *object, void *data);
 static Etk_Bool _etk_combobox_entry_window_key_down_cb(Etk_Object *object, Etk_Event_Key_Down *event, void *data);
 static Etk_Bool _etk_combobox_entry_item_entered_cb(Etk_Object *object, void *data);
 static Etk_Bool _etk_combobox_entry_item_left_cb(Etk_Object *object, void *data);
 static Etk_Bool _etk_combobox_entry_item_mouse_up_cb(Etk_Object *object, Etk_Event_Mouse_Up *event, void *data);
+static Etk_Bool _etk_combobox_entry_entry_text_changed_cb(Etk_Object *object, void *data);
 
 static void _etk_combobox_entry_selected_item_set(Etk_Combobox_Entry *combobox_entry, Etk_Combobox_Entry_Item *item);
 static void _etk_combobox_entry_item_cells_render(Etk_Combobox_Entry *combobox_entry, Etk_Widget **cells, Etk_Geometry geometry, Etk_Bool ignore_other);
@@ -939,6 +941,39 @@
    etk_toggle_button_active_set(ETK_TOGGLE_BUTTON(combobox_entry->button), ETK_FALSE);
 }
 
+/**
+ * @brief Enable or disable autosearch on the combobox entry.
+ * When a combo_Entry is set as searchable typing in the entry will show the popup
+ * window with a filtered set of option.
+ * @param combobox_entry a combobox_entry
+ * @param enable ETK_TRUE = enable, ETK_FALSE = disable
+ */
+void etk_combobox_entry_autosearch_enable_set(Etk_Combobox_Entry *combobox_entry, int enable)
+{
+   if (!combobox_entry)
+      return;
+   
+   if (enable)
+      etk_signal_connect_by_code(ETK_ENTRY_TEXT_CHANGED_SIGNAL, ETK_OBJECT(combobox_entry->entry), ETK_CALLBACK(_etk_combobox_entry_entry_text_changed_cb), combobox_entry);
+   else
+      etk_signal_disconnect_by_code(ETK_ENTRY_TEXT_CHANGED_SIGNAL, ETK_OBJECT(combobox_entry->entry), ETK_CALLBACK(_etk_combobox_entry_entry_text_changed_cb), combobox_entry);      
+   
+   combobox_entry->autosearch_enable = enable ? ETK_TRUE : ETK_FALSE;
+}
+
+/**
+ * @brief Set the colum number to use for the search, must be a string column.
+ * @param combobox_entry a combobox_entry
+ * @param col_num the string column to use for searching
+ */
+void etk_combobox_entry_autosearch_column_set(Etk_Combobox_Entry *combobox_entry, int col_num)
+{
+   if (!combobox_entry)
+      return;
+   
+   combobox_entry->autosearch_column = col_num;
+}
+
 /**************************
  *
  * Etk specific functions
@@ -988,11 +1023,14 @@
    combobox_entry->active_item = NULL;
    combobox_entry->items_height = DEFAULT_ITEM_HEIGHT;
    combobox_entry->built = ETK_FALSE;
+   combobox_entry->autosearch_column = 0;
+   combobox_entry->autosearch_enable = 0;
 
    ETK_WIDGET(combobox_entry)->size_request = _etk_combobox_entry_size_request;
    ETK_WIDGET(combobox_entry)->size_allocate = _etk_combobox_entry_size_allocate;
 
    etk_signal_connect_by_code(ETK_TOGGLE_BUTTON_TOGGLED_SIGNAL, ETK_OBJECT(combobox_entry->button), ETK_CALLBACK(_etk_combobox_entry_button_toggled_cb), combobox_entry);
+   etk_signal_connect_by_code(ETK_BUTTON_PRESSED_SIGNAL, ETK_OBJECT(combobox_entry->button), ETK_CALLBACK(_etk_combobox_entry_button_pressed_cb), combobox_entry);
    etk_signal_connect_by_code(ETK_WIDGET_MOUSE_UP_SIGNAL, ETK_OBJECT(combobox_entry->hbox), ETK_CALLBACK(_etk_combobox_entry_hbox_mouse_up_cb), combobox_entry);
    etk_signal_connect_by_code(ETK_POPUP_WINDOW_POPPED_DOWN_SIGNAL, ETK_OBJECT(combobox_entry->window), ETK_CALLBACK(_etk_combobox_entry_window_popped_down_cb), combobox_entry);
    etk_signal_connect_by_code(ETK_WIDGET_KEY_DOWN_SIGNAL, ETK_OBJECT(combobox_entry->window), ETK_CALLBACK(_etk_combobox_entry_window_key_down_cb), combobox_entry);
@@ -1330,6 +1368,24 @@
    return ETK_TRUE;
 }
 
+/* Called when the combobox_entry button is pressed */
+static Etk_Bool _etk_combobox_entry_button_pressed_cb(Etk_Object *object, void *data)
+{
+   Etk_Combobox_Entry *combobox_entry;
+   Etk_Combobox_Entry_Item *item;
+
+   if (!(combobox_entry = ETK_COMBOBOX_ENTRY(data)))
+      return ETK_TRUE;
+
+   if (!combobox_entry->autosearch_enable)
+      return ETK_TRUE;
+   
+   for (item = combobox_entry->first_item; item; item = item->next)
+      etk_widget_show(ETK_WIDGET(item));
+
+   return ETK_TRUE;
+}
+
 /* Called when a key is pressed on the combobox_entry's entry widget */
 static Etk_Bool _etk_combobox_entry_entry_key_down_cb(Etk_Object *object, Etk_Event_Key_Down *event, void *data)
 {
@@ -1350,6 +1406,10 @@
          _etk_combobox_entry_selected_item_set(combobox_entry, combobox_entry->first_item);
       else
          _etk_combobox_entry_selected_item_set(combobox_entry, combobox_entry->selected_item->next);
+
+      while (combobox_entry->selected_item &&
+             !etk_widget_is_visible(ETK_WIDGET(combobox_entry->selected_item)))
+         _etk_combobox_entry_selected_item_set(combobox_entry, combobox_entry->selected_item->next);
    }
    else if (strcmp(event->keyname, "Up") == 0)
    {
@@ -1363,6 +1423,10 @@
          _etk_combobox_entry_selected_item_set(combobox_entry, combobox_entry->last_item);
       else
          _etk_combobox_entry_selected_item_set(combobox_entry, combobox_entry->selected_item->prev);
+
+      while (combobox_entry->selected_item &&
+             !etk_widget_is_visible(ETK_WIDGET(combobox_entry->selected_item)))
+         _etk_combobox_entry_selected_item_set(combobox_entry, combobox_entry->selected_item->prev);
    }
    else if (strcmp(event->keyname, "Return") == 0 || strcmp(event->keyname, "KP_Enter") == 0)
    {
@@ -1408,16 +1472,24 @@
          _etk_combobox_entry_selected_item_set(combobox_entry, combobox_entry->first_item);
       else
          _etk_combobox_entry_selected_item_set(combobox_entry, combobox_entry->selected_item->next);
+
+      while (combobox_entry->selected_item &&
+             !etk_widget_is_visible(ETK_WIDGET(combobox_entry->selected_item)))
+         _etk_combobox_entry_selected_item_set(combobox_entry, combobox_entry->selected_item->next);
    }
    else if (strcmp(event->keyname, "Up") == 0)
    {
       if (!combobox_entry->first_item)
          return ETK_TRUE;
 
-      if (!combobox_entry->selected_item || !combobox_entry->selected_item->next)
+      if (!combobox_entry->selected_item || !combobox_entry->selected_item->prev)
          _etk_combobox_entry_selected_item_set(combobox_entry, combobox_entry->last_item);
       else
          _etk_combobox_entry_selected_item_set(combobox_entry, combobox_entry->selected_item->prev);
+
+      while (combobox_entry->selected_item &&
+             !etk_widget_is_visible(ETK_WIDGET(combobox_entry->selected_item)))
+         _etk_combobox_entry_selected_item_set(combobox_entry, combobox_entry->selected_item->prev);
    }
    else if (strcmp(event->keyname, "Return") == 0 || strcmp(event->keyname, "space") == 0
          || strcmp(event->keyname, "KP_Enter") == 0)
@@ -1431,7 +1503,9 @@
    }
    else if (strcmp(event->keyname, "Escape") == 0)
       etk_popup_window_popdown(combobox_entry->window);
-
+   else
+      etk_signal_emit(ETK_WIDGET_KEY_DOWN_SIGNAL, ETK_OBJECT(combobox_entry->entry), event, data);
+   
    return ETK_TRUE;
 }
 
@@ -1474,6 +1548,44 @@
    if (event->button == 1)
       etk_popup_window_popdown(item->combobox_entry->window);
 
+   return ETK_TRUE;
+}
+
+/* Called when the text in the entry change (used for autosearch) */
+static Etk_Bool _etk_combobox_entry_entry_text_changed_cb(Etk_Object *object, void *data)
+{
+   Etk_Entry *entry;
+   Etk_Combobox_Entry *combobox_entry;
+   Etk_Combobox_Entry_Item *item;
+   const char *entry_text = NULL;
+
+   if (!(entry = ETK_ENTRY(object)))
+      return ETK_TRUE;
+
+   if (!(combobox_entry = ETK_COMBOBOX_ENTRY(data)))
+      return ETK_TRUE;
+
+   if (!etk_combobox_entry_is_popped_up(combobox_entry))
+      etk_combobox_entry_pop_up(combobox_entry);
+
+   entry_text = etk_entry_text_get(entry);
+   if (!entry_text)
+     return ETK_TRUE;
+
+   etk_combobox_entry_pop_down(combobox_entry);
+   
+   for (item = combobox_entry->first_item; item; item = item->next)
+   {
+      const char* item_field;
+
+      item_field = etk_combobox_entry_item_field_get(item, combobox_entry->autosearch_column);
+      if (strcasestr(item_field, entry_text))
+         etk_widget_show(ETK_WIDGET(item));
+      else
+         etk_widget_hide(ETK_WIDGET(item));
+   }
+
+   etk_combobox_entry_pop_up(combobox_entry);
    return ETK_TRUE;
 }
 
Index: src/lib/etk_combobox_entry.h
===================================================================
RCS file: /cvs/e/e17/libs/etk/src/lib/etk_combobox_entry.h,v
retrieving revision 1.8
diff -u -u -r1.8 etk_combobox_entry.h
--- src/lib/etk_combobox_entry.h	8 Oct 2007 13:32:42 -0000	1.8
+++ src/lib/etk_combobox_entry.h	13 Jul 2008 12:59:51 -0000
@@ -123,6 +123,9 @@
 
    int items_height;
    Etk_Bool built:1;
+   
+   int autosearch_enable;
+   int autosearch_column;
 };
 
 
@@ -174,6 +177,9 @@
 void etk_combobox_entry_pop_up(Etk_Combobox_Entry *combobox_entry);
 void etk_combobox_entry_pop_down(Etk_Combobox_Entry *combobox_entry);
 void etk_combobox_entry_popup_feed(Etk_Combobox_Entry *combobox_entry, Etk_Window *window);
+
+void etk_combobox_entry_autosearch_enable_set(Etk_Combobox_Entry *combobox_entry, int enable);
+void etk_combobox_entry_autosearch_column_set(Etk_Combobox_Entry *combobox_entry, int col_num);
 
 /** @} */
 
-------------------------------------------------------------------------
Sponsored by: SourceForge.net Community Choice Awards: VOTE NOW!
Studies have shown that voting for your favorite open source project,
along with a healthy diet, reduces your potential for chronic lameness
and boredom. Vote Now at http://www.sourceforge.net/community/cca08
_______________________________________________
enlightenment-devel mailing list
enlightenment-devel@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/enlightenment-devel

Reply via email to