<commit_before>/*
 * vim:ts=8:sw=3:sts=8:noexpandtab:cino=>5n-3f0^-2{2
 */
#include <Elementary.h>
#include "elm_priv.h"

typedef struct _Widget_Data Widget_Data;

struct _Widget_Data
{
   Evas_Object *scr, *bx;
   Eina_List *items;
   int icon_size;
   Eina_Bool scrollable : 1;
   Evas_Object *menu_parent;
   Eina_Bool homogeneous : 1;
   double align;
};

struct _Elm_Toolbar_Menu_Item
{
    Elm_Toolbar_Item *parent;

    const char *icon_group;
    const char *icon_path;
    const char *label;
    void (*func) (void *data, Evas_Object *obj, void *event_info);
    const void *data;
};

struct _Elm_Toolbar_Item
{
   Evas_Object *obj;
   Evas_Object *base;
   const char *label;
   Evas_Object *icon;
   void (*func) (void *data, Evas_Object *obj, void *event_info);
   const void *data;
   Eina_Bool selected : 1;
   Eina_Bool disabled : 1;
   Eina_Bool separator : 1;
    
   Eina_Bool menu;
   Eina_List *menu_items;
   Evas_Object *menu_position;
   Evas_Object *menu_hover;
   Evas_Object *menu_bx;
};

static void _item_show(Elm_Toolbar_Item *it);
static void _item_select(Elm_Toolbar_Item *it);
static void _item_disable(Elm_Toolbar_Item *it, Eina_Bool disabled);
static void _del_hook(Evas_Object *obj);
static void _theme_hook(Evas_Object *obj);
static void _sizing_eval(Evas_Object *obj);

static void _menu_move_resize(void *data, Evas *e, Evas_Object *obj, void *event_info);
static void _menu_hide(void *data, Evas_Object *obj, void *event_info);
static void _menu_item_select(void *data, Evas_Object *obj, void *event_info);

static void
_item_show(Elm_Toolbar_Item *it)
{
   Widget_Data *wd = elm_widget_data_get(it->obj);
   Evas_Coord x, y, w, h, bx, by;

   if (!wd) return;
   evas_object_geometry_get(wd->bx, &bx, &by, NULL, NULL);
   evas_object_geometry_get(it->base, &x, &y, &w, &h);
   elm_smart_scroller_child_region_show(wd->scr, x - bx, y - by, w, h);
}

static void
_item_select(Elm_Toolbar_Item *it)
{
   Elm_Toolbar_Item *it2;
   Elm_Toolbar_Menu_Item *it_menu;
   Widget_Data *wd = elm_widget_data_get(it->obj);
   Evas_Object *obj2, *bt, *hv, *bx, *ic;
   const Eina_List *l;
   Evas_Coord x,y,w,h;

   if (!wd) return;
   if ((it->selected) || (it->disabled) || (it->separator)) return;
   EINA_LIST_FOREACH(wd->items, l, it2)
     {
	if (it2->selected)
	  {
	     it2->selected = EINA_FALSE;
	     edje_object_signal_emit(it2->base, "elm,state,unselected", "elm");
	     break;
	  }
     }
   it->selected = EINA_TRUE;
   edje_object_signal_emit(it->base, "elm,state,selected", "elm");
   _item_show(it);
   obj2 = it->obj;
   if(it->menu)
   {
       it->menu_position = elm_icon_add(it->base);

       hv = elm_hover_add(it->base);
       it->menu_hover = hv;
       if(wd->menu_parent)
           elm_hover_parent_set(hv, wd->menu_parent);
       elm_hover_target_set(hv, it->menu_position);
       elm_hover_style_set(hv, "menu");

       bx = elm_box_add(it->base);
       it->menu_bx = bx;
       evas_object_size_hint_weight_set(bx, EVAS_HINT_EXPAND, EVAS_HINT_EXPAND);
       evas_object_show(bx);

       EINA_LIST_FOREACH(it->menu_items, l, it_menu)
       {
           ic = elm_icon_add(it->base);
           elm_icon_file_set(ic, it_menu->icon_path, it_menu->icon_group);

           bt = elm_button_add(it->base);
           evas_object_size_hint_weight_set(bt, EVAS_HINT_EXPAND, EVAS_HINT_EXPAND);
           evas_object_size_hint_fill_set(bt, EVAS_HINT_FILL, EVAS_HINT_FILL);
           elm_object_style_set(bt, "menu");
           elm_button_label_set(bt, it_menu->label);
           elm_button_icon_set(bt, ic);
           evas_object_smart_callback_add(bt, "clicked", _menu_item_select, it_menu);
           elm_box_pack_end(bx, bt);
           evas_object_show(bt);
       }
       elm_hover_content_set(hv, elm_hover_best_content_location_get(hv, ELM_HOVER_AXIS_VERTICAL), bx);
       evas_object_event_callback_add(bx, EVAS_CALLBACK_RESIZE, _menu_move_resize, it);
       evas_object_event_callback_add(hv, EVAS_CALLBACK_RESIZE, _menu_move_resize, it);
       evas_object_event_callback_add(hv, EVAS_CALLBACK_MOVE, _menu_move_resize, it);
       evas_object_smart_callback_add(hv, "clicked", _menu_hide, it);
       evas_object_show(hv);
        evas_object_smart_calculate(it->menu_hover);
       _menu_move_resize(it, NULL, NULL, NULL);
   }
   if (it->func) it->func((void *)(it->data), it->obj, it);
   evas_object_smart_callback_call(obj2, "clicked", it);
}

static void
_menu_item_select(void *data, Evas_Object *obj, void *event_info)<commit_msg>elm toolbar: little fix to avoid a infinite loop<commit_after>/*
 * vim:ts=8:sw=3:sts=8:noexpandtab:cino=>5n-3f0^-2{2
 */
#include <Elementary.h>
#include "elm_priv.h"

typedef struct _Widget_Data Widget_Data;

struct _Widget_Data
{
   Evas_Object *scr, *bx;
   Eina_List *items;
   int icon_size;
   Eina_Bool scrollable : 1;
   Evas_Object *menu_parent;
   Eina_Bool homogeneous : 1;
   double align;
};

struct _Elm_Toolbar_Menu_Item
{
    Elm_Toolbar_Item *parent;

    const char *icon_group;
    const char *icon_path;
    const char *label;
    void (*func) (void *data, Evas_Object *obj, void *event_info);
    const void *data;
};

struct _Elm_Toolbar_Item
{
   Evas_Object *obj;
   Evas_Object *base;
   const char *label;
   Evas_Object *icon;
   void (*func) (void *data, Evas_Object *obj, void *event_info);
   const void *data;
   Eina_Bool selected : 1;
   Eina_Bool disabled : 1;
   Eina_Bool separator : 1;
    
   Eina_Bool menu;
   Eina_List *menu_items;
   Evas_Object *menu_position;
   Evas_Object *menu_hover;
   Evas_Object *menu_bx;
};

static void _item_show(Elm_Toolbar_Item *it);
static void _item_select(Elm_Toolbar_Item *it);
static void _item_disable(Elm_Toolbar_Item *it, Eina_Bool disabled);
static void _del_hook(Evas_Object *obj);
static void _theme_hook(Evas_Object *obj);
static void _sizing_eval(Evas_Object *obj);

static void _menu_move_resize(void *data, Evas *e, Evas_Object *obj, void *event_info);
static void _menu_hide(void *data, Evas_Object *obj, void *event_info);
static void _menu_item_select(void *data, Evas_Object *obj, void *event_info);

static void
_item_show(Elm_Toolbar_Item *it)
{
   Widget_Data *wd = elm_widget_data_get(it->obj);
   Evas_Coord x, y, w, h, bx, by;

   if (!wd) return;
   evas_object_geometry_get(wd->bx, &bx, &by, NULL, NULL);
   evas_object_geometry_get(it->base, &x, &y, &w, &h);
   elm_smart_scroller_child_region_show(wd->scr, x - bx, y - by, w, h);
}

static void
_item_select(Elm_Toolbar_Item *it)
{
   Elm_Toolbar_Item *it2;
   Elm_Toolbar_Menu_Item *it_menu;
   Widget_Data *wd = elm_widget_data_get(it->obj);
   Evas_Object *obj2, *bt, *hv, *bx, *ic;
   const Eina_List *l;
   Evas_Coord x,y,w,h;

   if (!wd) return;
   if ((it->selected) || (it->disabled) || (it->separator)) return;
   EINA_LIST_FOREACH(wd->items, l, it2)
     {
	if (it2->selected)
	  {
	     it2->selected = EINA_FALSE;
	     edje_object_signal_emit(it2->base, "elm,state,unselected", "elm");
	     break;
	  }
     }
   it->selected = EINA_TRUE;
   edje_object_signal_emit(it->base, "elm,state,selected", "elm");
   _item_show(it);
   obj2 = it->obj;
   if(it->menu)
   {
       it->menu_position = elm_icon_add(it->base);

       hv = elm_hover_add(it->base);
       it->menu_hover = hv;
       if(wd->menu_parent)
           elm_hover_parent_set(hv, wd->menu_parent);
       elm_hover_target_set(hv, it->menu_position);
       elm_hover_style_set(hv, "menu");

       bx = elm_box_add(it->base);
       it->menu_bx = bx;
       evas_object_size_hint_weight_set(bx, EVAS_HINT_EXPAND, EVAS_HINT_EXPAND);
       evas_object_show(bx);

       EINA_LIST_FOREACH(it->menu_items, l, it_menu)
       {
           ic = elm_icon_add(it->base);
           elm_icon_file_set(ic, it_menu->icon_path, it_menu->icon_group);

           bt = elm_button_add(it->base);
           evas_object_size_hint_weight_set(bt, EVAS_HINT_EXPAND, EVAS_HINT_EXPAND);
           evas_object_size_hint_fill_set(bt, EVAS_HINT_FILL, EVAS_HINT_FILL);
           elm_object_style_set(bt, "menu");
           elm_button_label_set(bt, it_menu->label);
           elm_button_icon_set(bt, ic);
           evas_object_smart_callback_add(bt, "clicked", _menu_item_select, it_menu);
           elm_box_pack_end(bx, bt);
           evas_object_show(bt);
       }
       elm_hover_content_set(hv, elm_hover_best_content_location_get(hv, ELM_HOVER_AXIS_VERTICAL), bx);
       evas_object_event_callback_add(bx, EVAS_CALLBACK_RESIZE, _menu_move_resize, it);
       evas_object_event_callback_add(it->base, EVAS_CALLBACK_RESIZE, _menu_move_resize, it);
       evas_object_event_callback_add(it->base, EVAS_CALLBACK_MOVE, _menu_move_resize, it);
       evas_object_smart_callback_add(hv, "clicked", _menu_hide, it);
       evas_object_show(hv);
        evas_object_smart_calculate(it->menu_hover);
       _menu_move_resize(it, NULL, NULL, NULL);
   }
   if (it->func) it->func((void *)(it->data), it->obj, it);
   evas_object_smart_callback_call(obj2, "clicked", it);
}

static void
_menu_item_select(void *data, Evas_Object *obj, void *event_info)
{'fraction_non_alphanumeric': 0.12085490800925416, 'fraction_numerical': 0.004627079431530241, 'mean_word_length': 3.9906542056074765, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 81, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '1740181', 'n_tokens_mistral': 3659, 'n_tokens_neox': 3584, 'n_words': 653}