From e51cbfebe3917ba1e1a722b0f76eb3d89984a083 Mon Sep 17 00:00:00 2001 From: ChunEon Park Date: Wed, 24 Nov 2010 21:31:03 +0900 Subject: [PATCH] [elm_ctxpopup.c] updated for sizing --- src/lib/elm_ctxpopup.c | 650 +++++++++++++++++++++++++------------------------ 1 file changed, 337 insertions(+), 313 deletions(-) diff --git a/src/lib/elm_ctxpopup.c b/src/lib/elm_ctxpopup.c index d46db1e..4673fc4 100644 --- a/src/lib/elm_ctxpopup.c +++ b/src/lib/elm_ctxpopup.c @@ -38,10 +38,11 @@ struct _Widget_Data { Evas_Object *area_rect; Eina_List *items; Elm_Ctxpopup_Arrow arrow_dir; + Elm_Ctxpopup_Arrow arrow_priority[4]; int btn_cnt; Elm_Transit *transit; - Elm_Ctxpopup_Arrow arrow_priority[4]; Evas_Coord max_sc_w, max_sc_h; + char *title; Eina_Bool scroller_disabled :1; Eina_Bool horizontal :1; Eina_Bool visible :1; @@ -71,6 +72,8 @@ static void _ctxpopup_hide(void *data, Evas *e, Evas_Object *obj, void *event_info); static void _ctxpopup_move(void *data, Evas *e, Evas_Object *obj, void *event_info); +static void _ctxpopup_changed_size_hints(void *data, Evas *e, Evas_Object *obj, + void *event_info); static void _ctxpopup_scroller_resize(void *data, Evas *e, Evas_Object *obj, void *event_info); static void _item_obj_create(Elm_Ctxpopup_Item *item, char *group_name); @@ -94,7 +97,6 @@ static void _adjust_pos_y(int indicator_h, Evas_Coord_Point *pos, static void _reset_scroller_size(Widget_Data *wd); static void _hide_ctxpopup(Evas_Object *obj); - static void _reset_scroller_size(Widget_Data *wd) { wd->finished = EINA_FALSE; @@ -102,9 +104,9 @@ static void _reset_scroller_size(Widget_Data *wd) wd->max_sc_w = -1; } -static void _delete_area_rect_callbacks(Widget_Data *wd) { - if (!wd->area_rect) - return; +static void _delete_area_rect_callbacks(Widget_Data *wd) +{ + if (!wd->area_rect) return; evas_object_event_callback_del(wd->area_rect, EVAS_CALLBACK_DEL, _area_rect_del); @@ -114,8 +116,8 @@ static void _delete_area_rect_callbacks(Widget_Data *wd) { _area_rect_resize); } -static void _area_rect_resize(void *data, Evas *e, Evas_Object *obj, - void *event_info) { +static void _area_rect_resize(void *data, Evas *e, Evas_Object *obj, void *event_info) +{ Widget_Data *wd = elm_widget_data_get(data); if(wd->visible) { _reset_scroller_size(wd); @@ -123,8 +125,8 @@ static void _area_rect_resize(void *data, Evas *e, Evas_Object *obj, } } -static void _area_rect_move(void *data, Evas *e, Evas_Object *obj, - void *event_info) { +static void _area_rect_move(void *data, Evas *e, Evas_Object *obj, void *event_info) +{ Widget_Data *wd = elm_widget_data_get(data); if(wd->visible) { _reset_scroller_size(wd); @@ -132,14 +134,14 @@ static void _area_rect_move(void *data, Evas *e, Evas_Object *obj, } } -static void _area_rect_del(void *data, Evas *e, Evas_Object *obj, - void *event_info) { +static void _area_rect_del(void *data, Evas *e, Evas_Object *obj, void *event_info) +{ Widget_Data *wd = elm_widget_data_get(data); wd->area_rect = NULL; } -static void _show_effect_done(void *data, Elm_Transit *transit) { - +static void _show_effect_done(void *data, Elm_Transit *transit) +{ //TODO: Consider implementing effect in edc. Widget_Data *wd = data; elm_transit_fx_clear(transit); @@ -160,8 +162,8 @@ static void _show_effect_done(void *data, Elm_Transit *transit) { edje_object_signal_emit(wd->base, "elm,state,show", "elm"); } -static void _show_effect(Widget_Data* wd) { - +static void _show_effect(Widget_Data* wd) +{ //TODO: Consider implementing effect in edc. if (wd->transit) { elm_transit_stop(wd->transit); @@ -215,10 +217,7 @@ static void _hide_effect(Evas_Object *obj) elm_transit_completion_callback_set(wd->transit, _hide_effect_done, obj); } - if(!wd->position_forced) - elm_transit_fx_insert(wd->arrow, elm_fx_color_add(wd->arrow, 255, 255, 255, 255, 0, 0, 0, 0)); - - elm_transit_fx_insert(wd->transit, elm_fx_color_add(wd->base, 255, 255, 255, 255, 0, 0, 0, 0)); +// elm_transit_fx_insert(wd->transit, elm_fx_color_add(wd->base, 255, 255, 255, 255, 0, 0, 0, 0)); switch(wd->arrow_dir) { case ELM_FX_WIPE_DIR_UP: @@ -240,28 +239,33 @@ static void _hide_effect(Evas_Object *obj) elm_transit_run(wd->transit, 0.3); } -static void _separator_obj_del(Widget_Data *wd, Elm_Ctxpopup_Item *remove_item) { +static void _separator_obj_del(Widget_Data *wd, Elm_Ctxpopup_Item *remove_item) +{ Eina_List *elist, *cur_list, *prev_list; Elm_Ctxpopup_Item *separator; - if ((!remove_item) || (!wd)) - return; + if ((!remove_item) || (!wd)) return; + elist = wd->items; cur_list = eina_list_data_find_list(elist, remove_item); - if (!cur_list) - return; + + if (!cur_list) return; + prev_list = eina_list_prev(cur_list); - if (!prev_list) - return; + + if (!prev_list) return; + separator = (Elm_Ctxpopup_Item *) eina_list_data_get(prev_list); - if (!separator) - return; + + if (!separator)return; + wd->items = eina_list_remove(wd->items, separator); evas_object_del(separator->base); free(separator); } -static void _btn_layout_create(Evas_Object *obj) { +static void _btn_layout_create(Evas_Object *obj) +{ Widget_Data *wd = elm_widget_data_get(obj); wd->btn_layout = edje_object_add(evas_object_evas_get(obj)); @@ -270,21 +274,20 @@ static void _btn_layout_create(Evas_Object *obj) { edje_object_part_swallow(wd->base, "elm.swallow.btns", wd->btn_layout); } -static void _separator_obj_add(Evas_Object *obj) { +static void _separator_obj_add(Evas_Object *obj) +{ Elm_Ctxpopup_Item *item; Widget_Data *wd = (Widget_Data *) elm_widget_data_get(obj); - if (!wd) - return; - if (eina_list_count(wd->items) == 0) - return; + if (!wd) return; + if (eina_list_count(wd->items) == 0) return; item = ELM_NEW(Elm_Ctxpopup_Item); - if (!item) - return; + if (!item) return; item->base = edje_object_add(evas_object_evas_get(wd->base)); + if (!item->base) { free(item); return; @@ -305,34 +308,29 @@ static void _separator_obj_add(Evas_Object *obj) { wd->items = eina_list_append(wd->items, item); } -static void _item_sizing_eval(Elm_Ctxpopup_Item *item) { +static void _item_sizing_eval(Elm_Ctxpopup_Item *item) +{ Evas_Coord min_w = -1, min_h = -1, max_w = -1, max_h = -1; + Evas_Coord x, y, w, h; - if (!item) - return; + if (!item) return; - if (!item->separator) - elm_coords_finger_size_adjust(1, &min_w, 1, &min_h); + if (!item->separator) elm_coords_finger_size_adjust(1, &min_w, 1, &min_h); - Evas_Coord x, y, w, h; evas_object_geometry_get(item->base, &x, &y, &w, &h); - - edje_object_size_min_restricted_calc(item->base, &min_w, &min_h, min_w, - min_h); - + edje_object_size_min_restricted_calc(item->base, &min_w, &min_h, min_w, min_h); evas_object_size_hint_min_set(item->base, min_w, min_h); evas_object_size_hint_max_set(item->base, max_w, max_h); } static void _adjust_pos_x(Evas_Coord_Point *pos, Evas_Coord_Point *base_size, - Evas_Coord_Rectangle *area_rect) { + Evas_Coord_Rectangle *area_rect) +{ pos->x -= (base_size->x / 2); - if (pos->x < area_rect->x) { - pos->x = area_rect->x; - } else if ((pos->x + base_size->x) > (area_rect->x + area_rect->w)) { + if (pos->x < area_rect->x) pos->x = area_rect->x; + else if ((pos->x + base_size->x) > (area_rect->x + area_rect->w)) pos->x = (area_rect->x + area_rect->w) - base_size->x; - } if (base_size->x > area_rect->w) base_size->x -= (base_size->x - area_rect->w); @@ -341,31 +339,27 @@ static void _adjust_pos_x(Evas_Coord_Point *pos, Evas_Coord_Point *base_size, } static void _adjust_pos_y(int indicator_h, Evas_Coord_Point *pos, - Evas_Coord_Point *base_size, Evas_Coord_Rectangle *area_rect) { + Evas_Coord_Point *base_size, Evas_Coord_Rectangle *area_rect) +{ pos->y -= (base_size->y / 2); - if (pos->y < area_rect->y) { - pos->y = area_rect->y; - } else if ((pos->y + base_size->y) > (area_rect->y + area_rect->h)) { + if (pos->y < area_rect->y) pos->y = area_rect->y; + else if ((pos->y + base_size->y) > (area_rect->y + area_rect->h)) pos->y = area_rect->y + area_rect->h - base_size->y; - } - if (base_size->y > area_rect->h) { + if (base_size->y > area_rect->h) base_size->y -= (base_size->y - area_rect->h); - } - if (pos->y < area_rect->y) { - pos->y = area_rect->y; - } + + if (pos->y < area_rect->y) pos->y = area_rect->y; } -static int _get_indicator_h(Evas_Object *parent) { - +static int _get_indicator_h(Evas_Object *parent) +{ Ecore_X_Window zone, xwin; int h = 0; - if (elm_win_indicator_state_get(parent) != 1) { + if (elm_win_indicator_state_get(parent) != 1) return 0; - } xwin = elm_win_xwindow_get(parent); zone = ecore_x_e_illume_zone_get(xwin); @@ -374,13 +368,20 @@ static int _get_indicator_h(Evas_Object *parent) { return h; } -static Elm_Ctxpopup_Arrow _calc_base_geometry(Evas_Object *obj, - Evas_Coord_Rectangle *rect) { +static void _ctxpopup_changed_size_hints(void *data, Evas *e, Evas_Object *obj, void *event_info) +{ + Widget_Data *wd = (Widget_Data *) elm_widget_data_get(obj); + if (!wd) return; + if(wd->visible)_sizing_eval(obj); +} +static Elm_Ctxpopup_Arrow _calc_base_geometry(Evas_Object *obj, Evas_Coord_Rectangle *rect) +{ Widget_Data *wd; Evas_Coord_Point pos; Evas_Coord_Point base_size; Evas_Coord_Point max_size; + Evas_Coord_Point min_size; Evas_Coord_Rectangle area_rect; Evas_Coord_Point parent_size; Evas_Coord_Point arrow_size; @@ -388,15 +389,13 @@ static Elm_Ctxpopup_Arrow _calc_base_geometry(Evas_Object *obj, Evas_Coord finger_size; Evas_Coord indicator_h; Evas_Coord_Point temp; - int idx; Evas_Coord min_calc_h; Evas_Coord min_calc_w; + int idx; wd = elm_widget_data_get(obj); - if ((!wd) || (!rect)) { - return ELM_CTXPOPUP_ARROW_DOWN; - } + if ((!wd) || (!rect)) return ELM_CTXPOPUP_ARROW_DOWN; indicator_h = _get_indicator_h(wd->parent); finger_size = elm_finger_size_get(); @@ -405,12 +404,12 @@ static Elm_Ctxpopup_Arrow _calc_base_geometry(Evas_Object *obj, &arrow_size.x, &arrow_size.y); evas_object_resize(wd->arrow, arrow_size.x, arrow_size.y); + //Initialize Area Rectangle. if (wd->area_rect) evas_object_geometry_get(wd->area_rect, &area_rect.x, &area_rect.y, &area_rect.w, &area_rect.h); else { - evas_object_geometry_get(wd->parent, NULL, NULL, &parent_size.x, - &parent_size.y); + evas_object_geometry_get(wd->parent, NULL, NULL, &parent_size.x, &parent_size.y); area_rect.x = 0; area_rect.y = 0; area_rect.w = parent_size.x; @@ -422,70 +421,80 @@ static Elm_Ctxpopup_Arrow _calc_base_geometry(Evas_Object *obj, area_rect.y = indicator_h; area_rect.h -= temp.y; } + evas_object_geometry_get(obj, &pos.x, &pos.y, NULL, NULL); edje_object_size_min_calc(wd->base, &base_size.x, &base_size.y); min_calc_w = base_size.x; min_calc_h = base_size.y; - edje_object_size_max_get(wd->base, &max_size.x, &max_size.y); - max_size.x *= elm_scale_get(); - max_size.y *= elm_scale_get(); - - if (base_size.y > max_size.y) - base_size.y = max_size.y; - - if (base_size.x > max_size.x) - base_size.x = max_size.x; + //Limit to Max Size + evas_object_size_hint_max_get(obj, &max_size.x, &max_size.y); + + if( max_size.y > 0 ) + if(base_size.y > max_size.y) base_size.y = max_size.y; + + if( max_size.x > 0 ) + if(base_size.x > max_size.x) base_size.x = max_size.x; + + //Limit to Min Size + evas_object_size_hint_min_get(obj, &min_size.x, &min_size.y); + fprintf(stderr, "2. %d %d\n", min_size.x, min_size.y); + + if( min_size.y > 0 ) { + if(base_size.y < min_size.y) base_size.y = min_size.y; + if(min_calc_h < min_size.y) min_calc_h = min_size.y; + } + + if( min_size.x > 0 ) { + if(base_size.x < min_size.x) base_size.x = min_size.x; + if(min_calc_w < min_size.x) min_calc_w = min_size.x; + } + //In case of position forced. It shows up just like popup. if (wd->position_forced) { //TODO: calculate the size of ctxpopup rect->x = pos.x; rect->y = pos.y; rect->w = base_size.x; rect->h = base_size.y; - return ELM_CTXPOPUP_ARROW_UP; } + //Check the Which direction is available. + //If find a avaialble direction, it adjusts position and size. for (idx = 0; idx < 4; ++idx) { switch (wd->arrow_priority[idx]) { - case ELM_CTXPOPUP_ARROW_DOWN: - temp.y = pos.y - base_size.y; - if ((temp.y - arrow_size.y - finger_size) < area_rect.y) - continue; - _adjust_pos_x(&pos, &base_size, &area_rect); - pos.y -= (base_size.y + finger_size); - arrow = ELM_CTXPOPUP_ARROW_DOWN; - break; - case ELM_CTXPOPUP_ARROW_RIGHT: - temp.x = (pos.x - base_size.x); - if ((temp.x - arrow_size.x - finger_size) < area_rect.x) - continue; - _adjust_pos_y(indicator_h, &pos, &base_size, &area_rect); - pos.x -= (base_size.x + finger_size); - arrow = ELM_CTXPOPUP_ARROW_RIGHT; - break; - case ELM_CTXPOPUP_ARROW_LEFT: - temp.x = (pos.x + base_size.x); - if ((temp.x + arrow_size.x + finger_size) > (area_rect.x - + area_rect.w)) - continue; - _adjust_pos_y(indicator_h, &pos, &base_size, &area_rect); - pos.x += finger_size; - arrow = ELM_CTXPOPUP_ARROW_LEFT; - break; - case ELM_CTXPOPUP_ARROW_UP: - temp.y = (pos.y + base_size.y); - if ((temp.y + arrow_size.y + finger_size) > (area_rect.y - + area_rect.h)) - continue; - _adjust_pos_x(&pos, &base_size, &area_rect); - pos.y += finger_size; - arrow = ELM_CTXPOPUP_ARROW_UP; - break; - default: - break; + case ELM_CTXPOPUP_ARROW_DOWN: + temp.y = pos.y - base_size.y; + if ((temp.y - arrow_size.y - finger_size) < area_rect.y) continue; + _adjust_pos_x(&pos, &base_size, &area_rect); + pos.y -= (base_size.y + finger_size); + arrow = ELM_CTXPOPUP_ARROW_DOWN; + break; + case ELM_CTXPOPUP_ARROW_RIGHT: + temp.x = (pos.x - base_size.x); + if ((temp.x - arrow_size.x - finger_size) < area_rect.x) continue; + _adjust_pos_y(indicator_h, &pos, &base_size, &area_rect); + pos.x -= (base_size.x + finger_size); + arrow = ELM_CTXPOPUP_ARROW_RIGHT; + break; + case ELM_CTXPOPUP_ARROW_LEFT: + temp.x = (pos.x + base_size.x); + if ((temp.x + arrow_size.x + finger_size) > (area_rect.x + area_rect.w)) continue; + _adjust_pos_y(indicator_h, &pos, &base_size, &area_rect); + pos.x += finger_size; + arrow = ELM_CTXPOPUP_ARROW_LEFT; + break; + case ELM_CTXPOPUP_ARROW_UP: + temp.y = (pos.y + base_size.y); + if ((temp.y + arrow_size.y + finger_size) > (area_rect.y + area_rect.h)) continue; + _adjust_pos_x(&pos, &base_size, &area_rect); + pos.y += finger_size; + arrow = ELM_CTXPOPUP_ARROW_UP; + break; + default: + break; } break; } @@ -515,60 +524,58 @@ static Elm_Ctxpopup_Arrow _calc_base_geometry(Evas_Object *obj, length[0] = pos.y - area_rect.y; length[1] = (area_rect.y + area_rect.h) - pos.y; - int idx; - if (length[0] > length[1]) - idx = ELM_CTXPOPUP_ARROW_DOWN; - else - idx = ELM_CTXPOPUP_ARROW_UP; + if (length[0] > length[1]) idx = ELM_CTXPOPUP_ARROW_DOWN; + else idx = ELM_CTXPOPUP_ARROW_UP; //TODO 2: determine x , y switch (idx) { - case ELM_CTXPOPUP_ARROW_DOWN: - _adjust_pos_x(&pos, &base_size, &area_rect); - pos.y -= (base_size.y + finger_size); - arrow = ELM_CTXPOPUP_ARROW_DOWN; - if (pos.y < area_rect.y + arrow_size.y) { - base_size.y -= ((area_rect.y + arrow_size.y) - pos.y); - pos.y = area_rect.y + arrow_size.y; - } - break; - case ELM_CTXPOPUP_ARROW_RIGHT: - _adjust_pos_y(indicator_h, &pos, &base_size, &area_rect); - pos.x -= (base_size.x + finger_size); - arrow = ELM_CTXPOPUP_ARROW_RIGHT; - if (pos.x < area_rect.x + arrow_size.x) { - base_size.x -= ((area_rect.x + arrow_size.x) - pos.x); - pos.x = area_rect.x + arrow_size.x; - } - break; - case ELM_CTXPOPUP_ARROW_LEFT: - _adjust_pos_y(indicator_h, &pos, &base_size, &area_rect); - pos.x += finger_size; - arrow = ELM_CTXPOPUP_ARROW_LEFT; - if (pos.x + arrow_size.x + base_size.x > area_rect.x + area_rect.w) { - base_size.x -= ((pos.x + arrow_size.x + base_size.x) + case ELM_CTXPOPUP_ARROW_DOWN: + _adjust_pos_x(&pos, &base_size, &area_rect); + pos.y -= (base_size.y + finger_size); + arrow = ELM_CTXPOPUP_ARROW_DOWN; + if (pos.y < area_rect.y + arrow_size.y) { + base_size.y -= ((area_rect.y + arrow_size.y) - pos.y); + pos.y = area_rect.y + arrow_size.y; + } + break; + case ELM_CTXPOPUP_ARROW_RIGHT: + _adjust_pos_y(indicator_h, &pos, &base_size, &area_rect); + pos.x -= (base_size.x + finger_size); + arrow = ELM_CTXPOPUP_ARROW_RIGHT; + if (pos.x < area_rect.x + arrow_size.x) { + base_size.x -= ((area_rect.x + arrow_size.x) - pos.x); + pos.x = area_rect.x + arrow_size.x; + } + break; + case ELM_CTXPOPUP_ARROW_LEFT: + _adjust_pos_y(indicator_h, &pos, &base_size, &area_rect); + pos.x += finger_size; + arrow = ELM_CTXPOPUP_ARROW_LEFT; + if (pos.x + arrow_size.x + base_size.x > area_rect.x + area_rect.w) { + base_size.x -= ((pos.x + arrow_size.x + base_size.x) - (area_rect.x + area_rect.w)); - } - break; - case ELM_CTXPOPUP_ARROW_UP: - _adjust_pos_x(&pos, &base_size, &area_rect); - pos.y += finger_size; - arrow = ELM_CTXPOPUP_ARROW_UP; - if (pos.y + arrow_size.y + base_size.y > area_rect.y + area_rect.h) { - base_size.y -= ((pos.y + arrow_size.y + base_size.y) - - (area_rect.y + area_rect.h)); - } - break; - default: - break; + } + break; + case ELM_CTXPOPUP_ARROW_UP: + _adjust_pos_x(&pos, &base_size, &area_rect); + pos.y += finger_size; + arrow = ELM_CTXPOPUP_ARROW_UP; + if (pos.y + arrow_size.y + base_size.y > area_rect.y + area_rect.h) { + base_size.y -= ((pos.y + arrow_size.y + base_size.y) - (area_rect.y + area_rect.h)); + } + break; + default: + break; } } + //Final position and size. rect->x = pos.x; rect->y = pos.y; rect->w = base_size.x; rect->h = base_size.y; + //resize scroller according to final size. if (!wd->content) { evas_object_geometry_get(wd->box, NULL, NULL, &temp.x, &temp.y); evas_object_size_hint_min_set(wd->scroller, temp.x + (base_size.x - min_calc_w), temp.y + (base_size.y - min_calc_h)); @@ -577,54 +584,54 @@ static Elm_Ctxpopup_Arrow _calc_base_geometry(Evas_Object *obj, return arrow; } -static void _update_arrow_obj(Evas_Object *obj, Elm_Ctxpopup_Arrow arrow_dir) { +static void _update_arrow_obj(Evas_Object *obj, Elm_Ctxpopup_Arrow arrow_dir) +{ Evas_Coord x, y; Evas_Coord_Rectangle arrow_size; Evas_Coord_Rectangle area_rect; Evas_Coord parent_w, parent_h; Widget_Data *wd = elm_widget_data_get(obj); - if (!wd) - return; + if (!wd) return; evas_object_geometry_get(obj, &x, &y, NULL, NULL); evas_object_geometry_get(wd->arrow, NULL, NULL, &arrow_size.w, &arrow_size.h); switch (arrow_dir) { - case ELM_CTXPOPUP_ARROW_LEFT: { - edje_object_signal_emit(wd->arrow, "elm,state,left", "elm"); - arrow_size.y = (y - (arrow_size.h * 0.5)); - arrow_size.x = (x + elm_finger_size_get()); - break; - } - case ELM_CTXPOPUP_ARROW_RIGHT: { - edje_object_signal_emit(wd->arrow, "elm,state,right", "elm"); - arrow_size.y = (y - (arrow_size.h * 0.5)); - arrow_size.x = (x - elm_finger_size_get() - arrow_size.w); - break; - } - case ELM_CTXPOPUP_ARROW_UP: { - edje_object_signal_emit(wd->arrow, "elm,state,top", "elm"); - arrow_size.x = (x - (arrow_size.w * 0.5)); - arrow_size.y = (y + elm_finger_size_get()); - break; - } - case ELM_CTXPOPUP_ARROW_DOWN: { - edje_object_signal_emit(wd->arrow, "elm,state,bottom", "elm"); - arrow_size.x = (x - (arrow_size.w * 0.5)); - arrow_size.y = (y - elm_finger_size_get() - arrow_size.h); - break; - } - default: - break; + case ELM_CTXPOPUP_ARROW_LEFT: { + edje_object_signal_emit(wd->arrow, "elm,state,left", "elm"); + arrow_size.y = (y - (arrow_size.h * 0.5)); + arrow_size.x = (x + elm_finger_size_get()); + break; + } + case ELM_CTXPOPUP_ARROW_RIGHT: { + edje_object_signal_emit(wd->arrow, "elm,state,right", "elm"); + arrow_size.y = (y - (arrow_size.h * 0.5)); + arrow_size.x = (x - elm_finger_size_get() - arrow_size.w); + break; + } + case ELM_CTXPOPUP_ARROW_UP: { + edje_object_signal_emit(wd->arrow, "elm,state,top", "elm"); + arrow_size.x = (x - (arrow_size.w * 0.5)); + arrow_size.y = (y + elm_finger_size_get()); + break; + } + case ELM_CTXPOPUP_ARROW_DOWN: { + edje_object_signal_emit(wd->arrow, "elm,state,bottom", "elm"); + arrow_size.x = (x - (arrow_size.w * 0.5)); + arrow_size.y = (y - elm_finger_size_get() - arrow_size.h); + break; + } + default: + break; } //Adjust arrow position to prevent out of area - if (wd->area_rect) { + if (wd->area_rect) evas_object_geometry_get(wd->area_rect, &area_rect.x, &area_rect.y, &area_rect.w, &area_rect.h); - } else { + else { evas_object_geometry_get(wd->parent, NULL, NULL, &parent_w, &parent_h); area_rect.x = 0; area_rect.y = 0; @@ -633,12 +640,11 @@ static void _update_arrow_obj(Evas_Object *obj, Elm_Ctxpopup_Arrow arrow_dir) { } //TODO: Temporary Code. make it more flexible - if ((arrow_size.x - (arrow_size.w / 2)) < area_rect.x) { + if ((arrow_size.x - (arrow_size.w / 2)) < area_rect.x) arrow_size.x = area_rect.x + (arrow_size.w / 2); - } else if ((arrow_size.x + arrow_size.w) > (area_rect.x + area_rect.w)) { + else if ((arrow_size.x + arrow_size.w) > (area_rect.x + area_rect.w)) arrow_size.x = (area_rect.x + area_rect.w) - arrow_size.w - (arrow_size.w / 2); - } /* //TODO: Temporary Code. make it more flexible if ((arrow_size.y - (arrow_size.h / 2)) < area_rect.y) { @@ -651,7 +657,8 @@ static void _update_arrow_obj(Evas_Object *obj, Elm_Ctxpopup_Arrow arrow_dir) { evas_object_move(wd->arrow, arrow_size.x, arrow_size.y); } -static void _sizing_eval(Evas_Object *obj) { +static void _sizing_eval(Evas_Object *obj) +{ Widget_Data *wd; Eina_List *elist; Elm_Ctxpopup_Item *item; @@ -660,10 +667,7 @@ static void _sizing_eval(Evas_Object *obj) { Evas_Coord_Point _box_size = { 0, 0 }; wd = (Widget_Data *) elm_widget_data_get(obj); - - if ((!wd) || (!wd->parent)) - return; - + if ((!wd) || (!wd->parent)) return; int idx = 0; EINA_LIST_FOREACH(wd->items, elist, item) @@ -701,7 +705,8 @@ static void _sizing_eval(Evas_Object *obj) { } static void _shift_base_by_arrow(Evas_Object *arrow, - Elm_Ctxpopup_Arrow arrow_dir, Evas_Coord_Rectangle *rect) { + Elm_Ctxpopup_Arrow arrow_dir, Evas_Coord_Rectangle *rect) +{ Evas_Coord arrow_w, arrow_h; evas_object_geometry_get(arrow, NULL, NULL, &arrow_w, &arrow_h); @@ -726,7 +731,7 @@ static void _shift_base_by_arrow(Evas_Object *arrow, static void _del_pre_hook(Evas_Object *obj) { Widget_Data *wd = (Widget_Data *) elm_widget_data_get(obj); - if (!wd) return; + if (!wd) return; evas_object_event_callback_del_full(wd->parent, EVAS_CALLBACK_RESIZE, _parent_resize, obj); @@ -741,8 +746,8 @@ static void _del_pre_hook(Evas_Object *obj) { } -static void _del_hook(Evas_Object *obj) { - +static void _del_hook(Evas_Object *obj) +{ Widget_Data *wd = (Widget_Data *) elm_widget_data_get(obj); if (!wd) return; @@ -753,16 +758,15 @@ static void _del_hook(Evas_Object *obj) { free(wd); } -static void _theme_hook(Evas_Object *obj) { +static void _theme_hook(Evas_Object *obj) +{ Eina_List *elist; Elm_Ctxpopup_Item *item; - char buf[256]; Widget_Data *wd = (Widget_Data *) elm_widget_data_get(obj); - if (!wd) - return; + if (!wd) return; //Items EINA_LIST_FOREACH(wd->items, elist, item) @@ -772,8 +776,7 @@ static void _theme_hook(Evas_Object *obj) { _elm_theme_object_set(obj, item->base, "ctxpopup", "separator", elm_widget_style_get(obj)); if (wd->horizontal) - edje_object_signal_emit(item->base, "elm,state,horizontal", - "elm"); + edje_object_signal_emit(item->base, "elm,state,horizontal", "elm"); } else { @@ -796,10 +799,10 @@ static void _theme_hook(Evas_Object *obj) { elm_widget_style_get(obj)); } if (item->label) - edje_object_part_text_set(item->base, "elm.text", item->label); + edje_object_part_text_set(item->base, "elm.text", item->label); if (item->disabled) - edje_object_signal_emit(item->base, "elm,state,disabled", "elm"); + edje_object_signal_emit(item->base, "elm,state,disabled", "elm"); } edje_object_message_signal_process(item->base); } @@ -811,10 +814,8 @@ static void _theme_hook(Evas_Object *obj) { elm_widget_style_get(obj)); } - _elm_theme_object_set(obj, wd->bg, "ctxpopup", "bg", elm_widget_style_get( - obj)); - _elm_theme_object_set(obj, wd->base, "ctxpopup", "base", - elm_widget_style_get(obj)); + _elm_theme_object_set(obj, wd->bg, "ctxpopup", "bg", elm_widget_style_get(obj)); + _elm_theme_object_set(obj, wd->base, "ctxpopup", "base", elm_widget_style_get(obj)); _elm_theme_object_set(obj, wd->arrow, "ctxpopup", "arrow", elm_widget_style_get(obj)); @@ -831,13 +832,14 @@ static void _theme_hook(Evas_Object *obj) { } static void _bg_clicked_cb(void *data, Evas_Object *obj, const char *emission, - const char *source) { + const char *source) +{ evas_object_hide(data); } static void _parent_resize(void *data, Evas *e, Evas_Object *obj, - void *event_info) { - + void *event_info) +{ Evas_Coord w, h; Widget_Data *wd = (Widget_Data *) elm_widget_data_get(data); @@ -853,7 +855,8 @@ static void _parent_resize(void *data, Evas *e, Evas_Object *obj, } static void _ctxpopup_show(void *data, Evas *e, Evas_Object *obj, - void *event_info) { + void *event_info) +{ Widget_Data *wd = (Widget_Data *) elm_widget_data_get(obj); if(wd == NULL) return; @@ -894,8 +897,8 @@ static void _hide_ctxpopup(Evas_Object *obj) evas_object_smart_callback_call(obj, "hide", NULL); } -static void _ctxpopup_hide(void *data, Evas *e, Evas_Object *obj, - void *event_info) { +static void _ctxpopup_hide(void *data, Evas *e, Evas_Object *obj, void *event_info) +{ Widget_Data *wd = (Widget_Data*) elm_widget_data_get(obj); if(wd == NULL) return; @@ -910,16 +913,16 @@ static void _ctxpopup_hide(void *data, Evas *e, Evas_Object *obj, } static void _ctxpopup_scroller_resize(void *data, Evas *e, Evas_Object * obj, - void *event_info) { - - Evas_Coord w, h; + void *event_info) +{ Widget_Data *wd; + Evas_Coord w, h; wd = elm_widget_data_get(data); if(wd == NULL) return; - if(!wd->visible) return ; - if(wd->finished) return ; + if(!wd->visible) return; + if(wd->finished) return; evas_object_geometry_get(wd->scroller, 0, 0, &w, &h); @@ -938,7 +941,8 @@ static void _ctxpopup_scroller_resize(void *data, Evas *e, Evas_Object * obj, } static void _ctxpopup_move(void *data, Evas *e, Evas_Object *obj, - void *event_info) { + void *event_info) +{ Widget_Data *wd = (Widget_Data *) elm_widget_data_get(obj); if(wd == NULL) return; @@ -950,24 +954,22 @@ static void _ctxpopup_move(void *data, Evas *e, Evas_Object *obj, } static void _ctxpopup_item_select(void *data, Evas_Object *obj, - const char *emission, const char *source) { + const char *emission, const char *source) +{ Elm_Ctxpopup_Item *item = (Elm_Ctxpopup_Item *) data; - if (!item) - return; - if (item->disabled) - return; - if (item->func) { + if (!item) return; + if (item->disabled) return; + if (item->func) item->func(item->data, item->ctxpopup, item); - } _ctxpopup_hide(item->ctxpopup, NULL, item->ctxpopup, NULL); } -static void _item_obj_create(Elm_Ctxpopup_Item *item, char *group_name) { +static void _item_obj_create(Elm_Ctxpopup_Item *item, char *group_name) +{ Widget_Data *wd = (Widget_Data *) elm_widget_data_get(item->ctxpopup); - if (!wd) - return; + if (!wd) return; item->base = edje_object_add(evas_object_evas_get(wd->base)); _elm_theme_object_set(item->ctxpopup, item->base, "ctxpopup", group_name, elm_widget_style_get(item->ctxpopup)); @@ -988,9 +990,9 @@ static void _item_obj_create(Elm_Ctxpopup_Item *item, char *group_name) { * @ingroup Ctxpopup */ EAPI Evas_Object * -elm_ctxpopup_item_icon_get(Elm_Ctxpopup_Item *item) { - if (!item) - return NULL; +elm_ctxpopup_item_icon_get(Elm_Ctxpopup_Item *item) +{ + if (!item) return NULL; return item->icon; } @@ -1003,14 +1005,13 @@ elm_ctxpopup_item_icon_get(Elm_Ctxpopup_Item *item) { * @ingroup Ctxpopup */ EAPI void elm_ctxpopup_scroller_disabled_set(Evas_Object *obj, - Eina_Bool disabled) { + Eina_Bool disabled) +{ ELM_CHECK_WIDTYPE(obj, widtype); Widget_Data *wd = (Widget_Data *) elm_widget_data_get(obj); - if (!wd) - return; - if (wd->scroller_disabled == disabled) - return; + if (!wd) return; + if (wd->scroller_disabled == disabled) return; if (disabled) elm_object_scroll_freeze_push(wd->scroller); @@ -1030,9 +1031,9 @@ EAPI void elm_ctxpopup_scroller_disabled_set(Evas_Object *obj, * */ EAPI const char * -elm_ctxpopup_item_label_get(Elm_Ctxpopup_Item *item) { - if (!item) - return NULL; +elm_ctxpopup_item_label_get(Elm_Ctxpopup_Item *item) +{ + if (!item) return NULL; return item->label; } @@ -1045,7 +1046,8 @@ elm_ctxpopup_item_label_get(Elm_Ctxpopup_Item *item) { * @ingroup Ctxpopup */ EAPI Evas_Object * -elm_ctxpopup_add(Evas_Object *parent) { +elm_ctxpopup_add(Evas_Object *parent) +{ Evas_Object *obj; Evas *e; Widget_Data *wd; @@ -1115,7 +1117,8 @@ elm_ctxpopup_add(Evas_Object *parent) { evas_object_event_callback_add(obj, EVAS_CALLBACK_SHOW, _ctxpopup_show, NULL); evas_object_event_callback_add(obj, EVAS_CALLBACK_HIDE, _ctxpopup_hide, NULL); evas_object_event_callback_add(obj, EVAS_CALLBACK_MOVE, _ctxpopup_move, NULL); - + evas_object_event_callback_add(obj, EVAS_CALLBACK_CHANGED_SIZE_HINTS, _ctxpopup_changed_size_hints, NULL); + return obj; } @@ -1126,15 +1129,15 @@ elm_ctxpopup_add(Evas_Object *parent) { * * @ingroup Ctxpopup */ -EAPI void elm_ctxpopup_clear(Evas_Object *obj) { +EAPI void elm_ctxpopup_clear(Evas_Object *obj) +{ ELM_CHECK_WIDTYPE(obj, widtype); Eina_List *elist; Elm_Ctxpopup_Item *item; Widget_Data *wd = (Widget_Data *) elm_widget_data_get(obj); - if (!wd) - return; + if (!wd) return; EINA_LIST_FOREACH(wd->items, elist, item) { @@ -1158,31 +1161,30 @@ EAPI void elm_ctxpopup_clear(Evas_Object *obj) { * * @ingroup Ctxpopup */ -EAPI void elm_ctxpopup_horizontal_set(Evas_Object *obj, Eina_Bool horizontal) { +EAPI void elm_ctxpopup_horizontal_set(Evas_Object *obj, Eina_Bool horizontal) +{ ELM_CHECK_WIDTYPE(obj, widtype); Eina_List *elist; Elm_Ctxpopup_Item *item; Widget_Data *wd = (Widget_Data *) elm_widget_data_get(obj); - if (!wd) - return; + if (!wd) return; - if (wd->horizontal == horizontal) - return; + if (wd->horizontal == horizontal) return; wd->horizontal = horizontal; if (!horizontal) { elm_box_horizontal_set(wd->box, EINA_FALSE); elm_scroller_bounce_set(wd->scroller, EINA_FALSE, EINA_TRUE); -EINA_LIST_FOREACH (wd->items, elist, item) - edje_object_signal_emit(item->base, "elm,state,vertical", "elm"); -} -else -{ - elm_box_horizontal_set(wd->box, EINA_TRUE); - elm_scroller_bounce_set(wd->scroller, EINA_TRUE, EINA_FALSE); - EINA_LIST_FOREACH(wd->items, elist, item) - edje_object_signal_emit(item->base, "elm,state,horizontal", "elm"); -} + EINA_LIST_FOREACH (wd->items, elist, item) + edje_object_signal_emit(item->base, "elm,state,vertical", "elm"); + } + else + { + elm_box_horizontal_set(wd->box, EINA_TRUE); + elm_scroller_bounce_set(wd->scroller, EINA_TRUE, EINA_FALSE); + EINA_LIST_FOREACH(wd->items, elist, item) + edje_object_signal_emit(item->base, "elm,state,horizontal", "elm"); + } } /** @@ -1193,13 +1195,11 @@ else * * @ingroup Ctxpopup */ -EAPI Eina_Bool elm_ctxpopup_horizontal_get(Evas_Object *obj) { +EAPI Eina_Bool elm_ctxpopup_horizontal_get(Evas_Object *obj) +{ ELM_CHECK_WIDTYPE(obj, widtype) EINA_FALSE; Widget_Data *wd = (Widget_Data *) elm_widget_data_get(obj); - - if (!wd) - return EINA_FALSE; - + if (!wd) return EINA_FALSE; return wd->horizontal; } @@ -1211,16 +1211,14 @@ EAPI Eina_Bool elm_ctxpopup_horizontal_get(Evas_Object *obj) { * * @ingroup Ctxpopup */ -EAPI void elm_ctxpopup_item_icon_set(Elm_Ctxpopup_Item *item, Evas_Object *icon) { +EAPI void elm_ctxpopup_item_icon_set(Elm_Ctxpopup_Item *item, Evas_Object *icon) +{ Widget_Data *wd; - if (!item) - return; + if (!item) return; wd = (Widget_Data *) elm_widget_data_get(item->ctxpopup); - if (!wd) - return; - if (item->icon == icon) - return; + if (!wd) return; + if (item->icon == icon) return; if (item->icon) { elm_widget_sub_object_del(item->base, item->icon); evas_object_del(item->icon); @@ -1244,7 +1242,8 @@ EAPI void elm_ctxpopup_item_icon_set(Elm_Ctxpopup_Item *item, Evas_Object *icon) * @ingroup Ctxpopup */ EAPI void elm_ctxpopup_item_label_set(Elm_Ctxpopup_Item *item, - const char *label) { + const char *label) +{ Widget_Data *wd; if (!item) @@ -1283,7 +1282,8 @@ EAPI void elm_ctxpopup_item_label_set(Elm_Ctxpopup_Item *item, */ EAPI Elm_Ctxpopup_Item * elm_ctxpopup_item_add(Evas_Object *obj, Evas_Object *icon, const char *label, - Evas_Smart_Cb func, void *data) { + Evas_Smart_Cb func, void *data) +{ ELM_CHECK_WIDTYPE(obj, widtype)NULL; Elm_Ctxpopup_Item *item; Widget_Data *wd = (Widget_Data *) elm_widget_data_get(obj); @@ -1324,8 +1324,8 @@ elm_ctxpopup_item_add(Evas_Object *obj, Evas_Object *icon, const char *label, * * @ingroup Ctxpopup */ -EAPI void elm_ctxpopup_item_del(Elm_Ctxpopup_Item *item) { - +EAPI void elm_ctxpopup_item_del(Elm_Ctxpopup_Item *item) +{ Widget_Data *wd; Evas_Object *obj; @@ -1361,15 +1361,15 @@ EAPI void elm_ctxpopup_item_del(Elm_Ctxpopup_Item *item) { * @ingroup Ctxpopup */ EAPI void elm_ctxpopup_item_disabled_set(Elm_Ctxpopup_Item *item, - Eina_Bool disabled) { + Eina_Bool disabled) +{ Widget_Data *wd; - if (!item) - return; - if (disabled == item->disabled) - return; - wd = (Widget_Data *) elm_widget_data_get(item->ctxpopup); + if (!item) return; + if (disabled == item->disabled) return; + wd = (Widget_Data *) elm_widget_data_get(item->ctxpopup); + if (disabled) edje_object_signal_emit(item->base, "elm,state,disabled", "elm"); else @@ -1387,7 +1387,8 @@ EAPI void elm_ctxpopup_item_disabled_set(Elm_Ctxpopup_Item *item, * @ingroup Ctxpopup */ EAPI void elm_ctxpopup_screen_dimmed_disabled_set(Evas_Object *obj, - Eina_Bool disabled) { + Eina_Bool disabled) +{ ELM_CHECK_WIDTYPE(obj, widtype); Widget_Data *wd = (Widget_Data *) elm_widget_data_get(obj); @@ -1413,19 +1414,16 @@ EAPI void elm_ctxpopup_screen_dimmed_disabled_set(Evas_Object *obj, * @ingroup Ctxpopup */ EAPI void elm_ctxpopup_button_append(Evas_Object *obj, const char *label, - Evas_Smart_Cb func, const void *data) { + Evas_Smart_Cb func, const void *data) +{ ELM_CHECK_WIDTYPE(obj, widtype); char buf[256]; Evas_Object *btn; Evas_Coord w, h; Widget_Data *wd = (Widget_Data *) elm_widget_data_get(obj); - if (!wd) - return; - - if (!wd->btn_layout) { - _btn_layout_create(obj); - } + if (!wd) return; + if (!wd->btn_layout) _btn_layout_create(obj); ++wd->btn_cnt; sprintf(buf, "buttons%d", wd->btn_cnt); @@ -1440,8 +1438,7 @@ EAPI void elm_ctxpopup_button_append(Evas_Object *obj, const char *label, edje_object_part_swallow(wd->btn_layout, buf, btn); edje_object_part_geometry_get(wd->btn_layout, buf, NULL, NULL, &w, &h); - //TODO: remove this line!! - evas_object_size_hint_max_set(wd->btn_layout, -1, 60 * elm_scale_get()); + evas_object_size_hint_max_set(wd->btn_layout, -1, h); if (wd->visible) { _reset_scroller_size(wd); @@ -1464,7 +1461,8 @@ EAPI void elm_ctxpopup_button_append(Evas_Object *obj, const char *label, */ EAPI void elm_ctxpopup_arrow_priority_set(Evas_Object *obj, Elm_Ctxpopup_Arrow first, Elm_Ctxpopup_Arrow second, - Elm_Ctxpopup_Arrow third, Elm_Ctxpopup_Arrow fourth) { + Elm_Ctxpopup_Arrow third, Elm_Ctxpopup_Arrow fourth) +{ ELM_CHECK_WIDTYPE(obj, widtype); Widget_Data *wd = (Widget_Data *) elm_widget_data_get(obj); @@ -1484,7 +1482,8 @@ EAPI void elm_ctxpopup_arrow_priority_set(Evas_Object *obj, * * @ingroup Ctxpopup */ -EAPI void elm_ctxpopup_content_set(Evas_Object *obj, Evas_Object *content) { +EAPI void elm_ctxpopup_content_set(Evas_Object *obj, Evas_Object *content) +{ ELM_CHECK_WIDTYPE(obj, widtype); Widget_Data *wd = (Widget_Data *) elm_widget_data_get(obj); Evas_Coord w, h; @@ -1516,7 +1515,8 @@ EAPI void elm_ctxpopup_content_set(Evas_Object *obj, Evas_Object *content) { * @ingroup Ctxpopup */ EAPI Evas_Object * -elm_ctxpopup_content_unset(Evas_Object *obj) { +elm_ctxpopup_content_unset(Evas_Object *obj) +{ ELM_CHECK_WIDTYPE(obj, widtype)NULL; Widget_Data *wd = (Widget_Data *) elm_widget_data_get(obj); Evas_Object *content; @@ -1524,8 +1524,7 @@ elm_ctxpopup_content_unset(Evas_Object *obj) { content = wd->content; wd->content = NULL; - if (content) - edje_object_part_unswallow(wd->base, content); + if (content) edje_object_part_unswallow(wd->base, content); elm_widget_sub_object_del(obj, content); edje_object_signal_emit(wd->base, "elm,state,content,disable", "elm"); @@ -1549,14 +1548,14 @@ elm_ctxpopup_content_unset(Evas_Object *obj) { * * @ingroup Ctxpopup */ -EAPI void elm_ctxpopup_position_forced_set(Evas_Object *obj, Eina_Bool forced) { +EAPI void elm_ctxpopup_position_forced_set(Evas_Object *obj, Eina_Bool forced) +{ ELM_CHECK_WIDTYPE(obj, widtype); Widget_Data *wd = (Widget_Data *) elm_widget_data_get(obj); wd->position_forced = forced; - if (forced) - evas_object_hide(wd->arrow); + if (forced) evas_object_hide(wd->arrow); if (wd->visible) { _reset_scroller_size(wd); @@ -1572,7 +1571,8 @@ EAPI void elm_ctxpopup_position_forced_set(Evas_Object *obj, Eina_Bool forced) { * * @ingroup Ctxpopup */ -EAPI Eina_Bool elm_ctxpopup_position_forced_get(Evas_Object *obj) { +EAPI Eina_Bool elm_ctxpopup_position_forced_get(Evas_Object *obj) +{ ELM_CHECK_WIDTYPE(obj, widtype) EINA_FALSE; Widget_Data *wd = (Widget_Data *) elm_widget_data_get(obj); @@ -1581,13 +1581,15 @@ EAPI Eina_Bool elm_ctxpopup_position_forced_get(Evas_Object *obj) { EAPI Elm_Ctxpopup_Item * elm_ctxpopup_icon_add(Evas_Object *obj, Evas_Object *icon, Evas_Smart_Cb func, - void *data) { + void *data) +{ return elm_ctxpopup_item_add(obj, icon, NULL, func, data); } EAPI Elm_Ctxpopup_Item * elm_ctxpopup_label_add(Evas_Object *obj, const char *label, Evas_Smart_Cb func, - void *data) { + void *data) +{ return elm_ctxpopup_item_add(obj, NULL, label, func, data); } @@ -1600,7 +1602,8 @@ elm_ctxpopup_label_add(Evas_Object *obj, const char *label, Evas_Smart_Cb func, * * @ingroup Ctxpopup */ -EAPI void elm_ctxpopup_area_set(Evas_Object *obj, Evas_Object *area) { +EAPI void elm_ctxpopup_area_set(Evas_Object *obj, Evas_Object *area) +{ ELM_CHECK_WIDTYPE(obj, widtype); Widget_Data *wd = (Widget_Data *) elm_widget_data_get(obj); @@ -1618,3 +1621,24 @@ EAPI void elm_ctxpopup_area_set(Evas_Object *obj, Evas_Object *area) { } +EAPI void elm_ctxpopup_title_set(Evas_Object *obj, const char *title ) +{ + ELM_CHECK_WIDTYPE(obj, widtype); + Widget_Data *wd = (Widget_Data *) elm_widget_data_get(obj); + if(!wd) return; + if(!title) return; + + if(wd->title) eina_stringshare_del(wd->title); + wd->title = eina_stringshare_add(title); + edje_object_part_text_set(wd->base, "elm.title", title); + +} + +EAPI const char* elm_ctxpopup_title_get(Evas_Object *obj) +{ + ELM_CHECK_WIDTYPE(obj, widtype); + Widget_Data *wd = (Widget_Data *) elm_widget_data_get(obj); + return wd->title; +} + + -- 2.7.4