new toolbar mode: always_select
authorMike Blumenkrantz <michael.blumenkrantz@gmail.com>
Thu, 29 Sep 2011 23:46:55 +0000 (23:46 +0000)
committerMike Blumenkrantz <michael.blumenkrantz@gmail.com>
Thu, 29 Sep 2011 23:46:55 +0000 (23:46 +0000)
when this mode is enabled, a toolbar item will always be selected. if the selected item is deleted, the next item will be selected. if there is no next item, the first item will be selected. if there is no next or first item, you can go <expletive deleted> yourself.

SVN revision: 63691

src/lib/Elementary.h.in
src/lib/elm_toolbar.c

index 984e4a17c8b5b6d1337798c38e58f55317816c49..ecf32c2259078516fba0006569205b60c5431219 100644 (file)
@@ -14052,6 +14052,38 @@ extern "C" {
     */
    EAPI Elm_Icon_Lookup_Order   elm_toolbar_icon_order_lookup_get(const Evas_Object *obj) EINA_ARG_NONNULL(1);
 
+   /**
+    * Set whether the toolbar should always have an item selected.
+    *
+    * @param obj The toolbar object.
+    * @param wrap @c EINA_TRUE to enable always-select mode or @c EINA_FALSE to
+    * disable it.
+    *
+    * This will cause the toolbar to always have an item selected, and clicking
+    * the selected item will not cause a selected event to be emitted. Enabling this mode
+    * will immediately select the first toolbar item.
+    *
+    * Always-selected is disabled by default.
+    *
+    * @see elm_toolbar_always_select_mode_get().
+    *
+    * @ingroup Toolbar
+    */
+   EAPI void                    elm_toolbar_always_select_mode_set(Evas_Object *obj, Eina_Bool always_select) EINA_ARG_NONNULL(1);
+
+   /**
+    * Get whether the toolbar should always have an item selected.
+    *
+    * @param obj The toolbar object.
+    * @return @c EINA_TRUE means an item will always be selected, @c EINA_FALSE indicates
+    * that it is possible to have no items selected. If @p obj is @c NULL, @c EINA_FALSE is returned.
+    *
+    * @see elm_toolbar_always_select_mode_set() for details.
+    *
+    * @ingroup Toolbar
+    */
+   EAPI Eina_Bool               elm_toolbar_always_select_mode_get(const Evas_Object *obj) EINA_ARG_NONNULL(1);
+
    /**
     * Set whether the toolbar items' should be selected by the user or not.
     *
index 20f63c30e44f6502099bb37f445919195d6a9416..4030a9c49336d6511606f76220d3ebc92acc98a1 100644 (file)
@@ -15,6 +15,7 @@ struct _Widget_Data
    double align;
    Eina_Bool homogeneous : 1;
    Eina_Bool no_select : 1;
+   Eina_Bool always_select : 1;
    Eina_Bool vertical : 1;
    Ecore_Job *resize_job;
 };
@@ -144,7 +145,11 @@ _item_select(Elm_Toolbar_Item *it)
 
    if (!wd->no_select)
      {
-        if (sel) _item_unselect(it);
+        if (sel)
+          {
+             if (wd->always_select) return;
+             _item_unselect(it);
+          }
         else
           {
              it2 = elm_toolbar_selected_item_get(it->base.widget);
@@ -746,6 +751,7 @@ _item_new(Evas_Object *obj, const char *icon, const char *label, Evas_Smart_Cb f
    evas_object_size_hint_min_set(it->base.view, mw, mh);
    evas_object_event_callback_add(it->base.view, EVAS_CALLBACK_RESIZE,
                                   _resize_item, obj);
+   if ((!wd->items) && wd->always_select) _item_select(it);
    return it;
 }
 
@@ -1449,12 +1455,16 @@ elm_toolbar_item_del(Elm_Toolbar_Item *item)
 {
    Widget_Data *wd;
    Evas_Object *obj2;
+   Elm_Toolbar_Item *next;
 
    ELM_WIDGET_ITEM_WIDTYPE_CHECK_OR_RETURN(item);
    wd = elm_widget_data_get(item->base.widget);
    if (!wd) return;
    obj2 = item->base.widget;
+   next = ELM_TOOLBAR_ITEM_FROM_INLIST(EINA_INLIST_GET(item)->next);
    wd->items = eina_inlist_remove(wd->items, EINA_INLIST_GET(item));
+   if (!next) next = ELM_TOOLBAR_ITEM_FROM_INLIST(wd->items);
+   if (wd->always_select && item->selected && next) _item_select(next);
    _item_del(item);
    _theme_hook(obj2);
 }
@@ -1769,6 +1779,26 @@ elm_toolbar_item_data_get(const Elm_Toolbar_Item *item)
    return elm_widget_item_data_get(item);
 }
 
+EAPI void
+elm_toolbar_always_select_mode_set(Evas_Object *obj, Eina_Bool always_select)
+{
+   ELM_CHECK_WIDTYPE(obj, widtype);
+   Widget_Data *wd = elm_widget_data_get(obj);
+   if (!wd) return;
+   if (always_select && (!wd->always_select) && wd->items)
+     _item_select(ELM_TOOLBAR_ITEM_FROM_INLIST(wd->items));
+   wd->always_select = always_select;
+}
+
+EAPI Eina_Bool
+elm_toolbar_always_select_mode_get(const Evas_Object *obj)
+{
+   ELM_CHECK_WIDTYPE(obj, widtype) EINA_FALSE;
+   Widget_Data *wd = elm_widget_data_get(obj);
+   if (!wd) return EINA_FALSE;
+   return wd->always_select;
+}
+
 EAPI void
 elm_toolbar_no_select_mode_set(Evas_Object *obj, Eina_Bool no_select)
 {