From ac25946a19f1ccc71bf5024a67e6067266068d0e Mon Sep 17 00:00:00 2001 From: Daniel Juyung Seo Date: Wed, 22 May 2013 02:24:02 +0900 Subject: [PATCH] elm: introduce ELM_FREE_FUNC for code quality enhancement. There are pros and cons but this 1. reduces human mistakes. 2. enhances readability. 3. enhances code quality. 4. removes future bug. 5. was adopted from enlightenment. This is not all. I will work on enhancing elementary more and more. --- legacy/elementary/src/lib/elc_player.c | 14 +- legacy/elementary/src/lib/elm_access.c | 20 +-- legacy/elementary/src/lib/elm_button.c | 27 +--- legacy/elementary/src/lib/elm_calendar.c | 20 ++- legacy/elementary/src/lib/elm_clock.c | 11 +- legacy/elementary/src/lib/elm_cnp.c | 21 +-- legacy/elementary/src/lib/elm_colorselector.c | 18 +-- legacy/elementary/src/lib/elm_config.c | 12 +- legacy/elementary/src/lib/elm_conform.c | 15 +-- legacy/elementary/src/lib/elm_entry.c | 52 ++------ legacy/elementary/src/lib/elm_flipselector.c | 18 +-- legacy/elementary/src/lib/elm_gengrid.c | 47 ++----- legacy/elementary/src/lib/elm_genlist.c | 123 +++++------------- legacy/elementary/src/lib/elm_priv.h | 3 + legacy/elementary/src/lib/elm_toolbar.c | 15 +-- 15 files changed, 120 insertions(+), 296 deletions(-) diff --git a/legacy/elementary/src/lib/elc_player.c b/legacy/elementary/src/lib/elc_player.c index 183741ec80..4abe26c249 100644 --- a/legacy/elementary/src/lib/elc_player.c +++ b/legacy/elementary/src/lib/elc_player.c @@ -175,11 +175,7 @@ _update_slider(void *data, elm_slider_min_max_set(sd->slider, 0, length); elm_slider_value_set(sd->slider, pos); sd->last_update_time = ecore_loop_time_get(); - if (sd->delay_update) - { - ecore_timer_del(sd->delay_update); - sd->delay_update = NULL; - } + ELM_FREE_FUNC(sd->delay_update, ecore_timer_del); } static Eina_Bool @@ -202,7 +198,7 @@ _update_frame(void *data, if ((ecore_loop_time_get() - sd->last_update_time) < 0.25) { - if (sd->delay_update) ecore_timer_del(sd->delay_update); + ELM_FREE_FUNC(sd->delay_update, ecore_timer_del); sd->delay_update = ecore_timer_add(0.30, _update_delay, data); return; } @@ -555,11 +551,7 @@ _elm_player_smart_del(Eo *obj, void *_pd, va_list *list EINA_UNUSED) { Elm_Player_Smart_Data *sd = _pd; - if (sd->delay_update) - { - ecore_timer_del(sd->delay_update); - sd->delay_update = NULL; - } + ELM_FREE_FUNC(sd->delay_update, ecore_timer_del); eo_do_super(obj, MY_CLASS, evas_obj_smart_del()); } diff --git a/legacy/elementary/src/lib/elm_access.c b/legacy/elementary/src/lib/elm_access.c index a6120ad8c3..ec74f66571 100644 --- a/legacy/elementary/src/lib/elm_access.c +++ b/legacy/elementary/src/lib/elm_access.c @@ -297,11 +297,8 @@ _access_obj_mouse_in_cb(void *data, Evas *e __UNUSED__, Evas_Object *obj __UNUSE ac = evas_object_data_get(data, "_elm_access"); if (!ac) return; - if (ac->delay_timer) - { - ecore_timer_del(ac->delay_timer); - ac->delay_timer = NULL; - } + ELM_FREE_FUNC(ac->delay_timer, ecore_timer_del); + if (_elm_config->access_mode != ELM_ACCESS_MODE_OFF) ac->delay_timer = ecore_timer_add(0.2, _access_obj_over_timeout_cb, data); } @@ -316,11 +313,8 @@ _access_obj_mouse_out_cb(void *data, Evas *e __UNUSED__, Evas_Object *obj __UNUS if (!ac) return; _elm_access_object_unhilight(data); - if (ac->delay_timer) - { - ecore_timer_del(ac->delay_timer); - ac->delay_timer = NULL; - } + + ELM_FREE_FUNC(ac->delay_timer, ecore_timer_del); } static void @@ -564,11 +558,7 @@ _elm_access_clear(Elm_Access_Info *ac) Elm_Access_Item *ai; if (!ac) return; - if (ac->delay_timer) - { - ecore_timer_del(ac->delay_timer); - ac->delay_timer = NULL; - } + ELM_FREE_FUNC(ac->delay_timer, ecore_timer_del); EINA_LIST_FREE(ac->items, ai) { if (!ai->func) diff --git a/legacy/elementary/src/lib/elm_button.c b/legacy/elementary/src/lib/elm_button.c index e5d2ba12a5..5405c0b11f 100644 --- a/legacy/elementary/src/lib/elm_button.c +++ b/legacy/elementary/src/lib/elm_button.c @@ -45,12 +45,7 @@ _activate(Evas_Object *obj) { ELM_BUTTON_DATA_GET_OR_RETURN(obj, sd); - if (sd->timer) - { - ecore_timer_del(sd->timer); - sd->timer = NULL; - } - + ELM_FREE_FUNC(sd->timer, ecore_timer_del); sd->repeating = EINA_FALSE; if ((_elm_config->access_mode == ELM_ACCESS_MODE_OFF) || @@ -225,7 +220,7 @@ _autorepeat_initial_send(void *data) { ELM_BUTTON_DATA_GET_OR_RETURN_VAL(data, sd, ECORE_CALLBACK_CANCEL); - if (sd->timer) ecore_timer_del(sd->timer); + ELM_FREE_FUNC(sd->timer, ecore_timer_del); sd->repeating = EINA_TRUE; _autorepeat_send(data); sd->timer = ecore_timer_add(sd->ar_interval, _autorepeat_send, data); @@ -261,11 +256,7 @@ _on_unpressed_signal(void *data, { ELM_BUTTON_DATA_GET_OR_RETURN(data, sd); - if (sd->timer) - { - ecore_timer_del(sd->timer); - sd->timer = NULL; - } + ELM_FREE_FUNC(sd->timer, ecore_timer_del); sd->repeating = EINA_FALSE; evas_object_smart_callback_call(data, SIG_UNPRESSED, NULL); } @@ -368,11 +359,7 @@ _autorepeat_set(Eo *obj EINA_UNUSED, void *_pd, va_list *list) Eina_Bool on = va_arg(*list, int); Elm_Button_Smart_Data *sd = _pd; - if (sd->timer) - { - ecore_timer_del(sd->timer); - sd->timer = NULL; - } + ELM_FREE_FUNC(sd->timer, ecore_timer_del); sd->autorepeat = on; sd->repeating = EINA_FALSE; } @@ -433,11 +420,7 @@ _autorepeat_initial_timeout_set(Eo *obj, void *_pd, va_list *list) } if (sd->ar_threshold == t) return; - if (sd->timer) - { - ecore_timer_del(sd->timer); - sd->timer = NULL; - } + ELM_FREE_FUNC(sd->timer, ecore_timer_del); sd->ar_threshold = t; } diff --git a/legacy/elementary/src/lib/elm_calendar.c b/legacy/elementary/src/lib/elm_calendar.c index b115b7e5bf..04a59cff9d 100644 --- a/legacy/elementary/src/lib/elm_calendar.c +++ b/legacy/elementary/src/lib/elm_calendar.c @@ -672,7 +672,7 @@ _button_month_inc_start(void *data, sd->interval = sd->first_interval; sd->spin_speed = 1; - if (sd->spin_month) ecore_timer_del(sd->spin_month); + ELM_FREE_FUNC(sd->spin_month, ecore_timer_del); sd->spin_month = ecore_timer_add(sd->interval, _spin_month_value, data); _spin_month_value(data); @@ -688,7 +688,7 @@ _button_month_dec_start(void *data, sd->interval = sd->first_interval; sd->spin_speed = -1; - if (sd->spin_month) ecore_timer_del(sd->spin_month); + ELM_FREE_FUNC(sd->spin_month, ecore_timer_del); sd->spin_month = ecore_timer_add(sd->interval, _spin_month_value, data); _spin_month_value(data); @@ -703,8 +703,7 @@ _button_month_stop(void *data, ELM_CALENDAR_DATA_GET(data, sd); sd->interval = sd->first_interval; - if (sd->spin_month) ecore_timer_del(sd->spin_month); - sd->spin_month = NULL; + ELM_FREE_FUNC(sd->spin_month, ecore_timer_del); } static void @@ -717,7 +716,7 @@ _button_year_inc_start(void *data, sd->interval = sd->first_interval; sd->spin_speed = 1; - if (sd->spin_year) ecore_timer_del(sd->spin_year); + ELM_FREE_FUNC(sd->spin_year, ecore_timer_del); sd->spin_year = ecore_timer_add(sd->interval, _spin_year_value, data); _spin_year_value(data); @@ -733,7 +732,7 @@ _button_year_dec_start(void *data, sd->interval = sd->first_interval; sd->spin_speed = -1; - if (sd->spin_year) ecore_timer_del(sd->spin_year); + ELM_FREE_FUNC(sd->spin_year, ecore_timer_del); sd->spin_year = ecore_timer_add(sd->interval, _spin_year_value, data); _spin_year_value(data); @@ -748,8 +747,7 @@ _button_year_stop(void *data, ELM_CALENDAR_DATA_GET(data, sd); sd->interval = sd->first_interval; - if (sd->spin_year) ecore_timer_del(sd->spin_year); - sd->spin_year = NULL; + ELM_FREE_FUNC(sd->spin_year, ecore_timer_del); } static int @@ -1030,9 +1028,9 @@ _elm_calendar_smart_del(Eo *obj, void *_pd, va_list *list EINA_UNUSED) Elm_Calendar_Mark *mark; Elm_Calendar_Smart_Data *sd = _pd; - if (sd->spin_month) ecore_timer_del(sd->spin_month); - if (sd->spin_year) ecore_timer_del(sd->spin_year); - if (sd->update_timer) ecore_timer_del(sd->update_timer); + ELM_FREE_FUNC(sd->spin_month, ecore_timer_del); + ELM_FREE_FUNC(sd->spin_year, ecore_timer_del); + ELM_FREE_FUNC(sd->update_timer, ecore_timer_del); if (sd->marks) { diff --git a/legacy/elementary/src/lib/elm_clock.c b/legacy/elementary/src/lib/elm_clock.c index 6e5bcb3864..ed2663c340 100644 --- a/legacy/elementary/src/lib/elm_clock.c +++ b/legacy/elementary/src/lib/elm_clock.c @@ -142,7 +142,7 @@ _on_clock_val_up_start(void *data, sd->interval = sd->first_interval; sd->sel_obj = obj; - if (sd->spin) ecore_timer_del(sd->spin); + ELM_FREE_FUNC(sd->spin, ecore_timer_del); sd->spin = ecore_timer_add(sd->interval, _on_clock_val_up, data); _on_clock_val_up(data); @@ -158,7 +158,7 @@ _on_clock_val_down_start(void *data, sd->interval = sd->first_interval; sd->sel_obj = obj; - if (sd->spin) ecore_timer_del(sd->spin); + ELM_FREE_FUNC(sd->spin, ecore_timer_del); sd->spin = ecore_timer_add(sd->interval, _on_clock_val_down, data); _on_clock_val_down(data); @@ -172,8 +172,7 @@ _on_clock_val_change_stop(void *data, { ELM_CLOCK_DATA_GET(data, sd); - if (sd->spin) ecore_timer_del(sd->spin); - sd->spin = NULL; + ELM_FREE_FUNC(sd->spin, ecore_timer_del); sd->sel_obj = NULL; } @@ -713,8 +712,8 @@ _elm_clock_smart_del(Eo *obj, void *_pd, va_list *list EINA_UNUSED) { Elm_Clock_Smart_Data *sd = _pd; - if (sd->ticker) ecore_timer_del(sd->ticker); - if (sd->spin) ecore_timer_del(sd->spin); + ELM_FREE_FUNC(sd->ticker, ecore_timer_del); + ELM_FREE_FUNC(sd->spin, ecore_timer_del); /* NB: digits are killed for being sub objects, automatically */ diff --git a/legacy/elementary/src/lib/elm_cnp.c b/legacy/elementary/src/lib/elm_cnp.c index 6559856daa..237368110d 100644 --- a/legacy/elementary/src/lib/elm_cnp.c +++ b/legacy/elementary/src/lib/elm_cnp.c @@ -3037,8 +3037,8 @@ _cont_obj_mouse_down(void *data, Evas *e, Evas_Object *obj __UNUSED__, void *eve evas_object_event_callback_add(st->obj, EVAS_CALLBACK_MOUSE_UP, _cont_obj_mouse_up, st); #endif - if (st->tm) - ecore_timer_del(st->tm); + + ELM_FREE_FUNC(st->tm, ecore_timer_del); st->e = e; st->x_down = ev->canvas.x; @@ -3065,11 +3065,7 @@ _cont_obj_mouse_move(void *data, Evas *e __UNUSED__, Evas_Object *obj __UNUSED__ #endif elm_drag_item_container_del_internal(obj, EINA_FALSE); - if (st->tm) - { - ecore_timer_del(st->tm); - st->tm = NULL; - } + ELM_FREE_FUNC(st->tm, ecore_timer_del); _anim_st_free(st); } @@ -3090,11 +3086,7 @@ _cont_obj_mouse_up(void *data, Evas *e __UNUSED__, Evas_Object *obj __UNUSED__, evas_object_event_callback_del_full (st->obj, EVAS_CALLBACK_MOUSE_UP, _cont_obj_mouse_up, st); - if (st->tm) - { - ecore_timer_del(st->tm); - st->tm = NULL; - } + ELM_FREE_FUNC(st->tm, ecore_timer_del); _anim_st_free(st); } @@ -3108,14 +3100,11 @@ elm_drag_item_container_del_internal(Evas_Object *obj, Eina_Bool full) if (st) { - if (st->tm) - ecore_timer_del(st->tm); /* Cancel drag-start timer */ + ELM_FREE_FUNC(st->tm, ecore_timer_del); /* Cancel drag-start timer */ if (st->ea) /* Cancel ongoing default animation */ _anim_st_free(st); - st->tm = NULL; - if (full) { st->itemgetcb = NULL; diff --git a/legacy/elementary/src/lib/elm_colorselector.c b/legacy/elementary/src/lib/elm_colorselector.c index ae1ccea428..2bb677a787 100644 --- a/legacy/elementary/src/lib/elm_colorselector.c +++ b/legacy/elementary/src/lib/elm_colorselector.c @@ -1284,7 +1284,7 @@ _on_color_pressed(void *data, elm_object_signal_emit(VIEW(item), "elm,state,selected", "elm"); sd->longpressed = EINA_FALSE; - if (sd->longpress_timer) ecore_timer_del(sd->longpress_timer); + ELM_FREE_FUNC(sd->longpress_timer, ecore_timer_del); sd->longpress_timer = ecore_timer_add (_elm_config->longpress_timeout, _on_color_long_press, data); } @@ -1304,11 +1304,7 @@ _on_color_released(void *data, ELM_COLORSELECTOR_DATA_GET(WIDGET(item), sd); if (ev->button != 1) return; - if (sd->longpress_timer) - { - ecore_timer_del(sd->longpress_timer); - sd->longpress_timer = NULL; - } + ELM_FREE_FUNC(sd->longpress_timer, ecore_timer_del); elm_object_signal_emit(VIEW(item), "elm,state,unselected", "elm"); if (!sd->longpressed) { @@ -1563,12 +1559,12 @@ _elm_colorselector_smart_del(Eo *obj, void *_pd, va_list *list EINA_UNUSED) evas_event_callback_del_full(evas_object_evas_get(obj), EVAS_CALLBACK_CANVAS_FOCUS_IN, _mouse_in_canvas, obj); evas_event_callback_del_full(evas_object_evas_get(obj), EVAS_CALLBACK_CANVAS_FOCUS_OUT, _mouse_out_canvas, obj); - if (sd->longpress_timer) ecore_timer_del(sd->longpress_timer); - if (sd->palette_name) eina_stringshare_del(sd->palette_name); + ELM_FREE_FUNC(sd->longpress_timer, ecore_timer_del); + ELM_FREE_FUNC(sd->palette_name, eina_stringshare_del); #ifdef HAVE_ELEMENTARY_X - if (sd->grab.mouse_motion) ecore_event_handler_del(sd->grab.mouse_motion); - if (sd->grab.mouse_up) ecore_event_handler_del(sd->grab.mouse_up); - if (sd->grab.key_up) ecore_event_handler_del(sd->grab.key_up); + ELM_FREE_FUNC(sd->grab.mouse_motion, ecore_event_handler_del); + ELM_FREE_FUNC(sd->grab.mouse_up, ecore_event_handler_del); + ELM_FREE_FUNC(sd->grab.key_up, ecore_event_handler_del); #endif _items_del(sd); diff --git a/legacy/elementary/src/lib/elm_config.c b/legacy/elementary/src/lib/elm_config.c index 1776dd98a9..dedb29312b 100644 --- a/legacy/elementary/src/lib/elm_config.c +++ b/legacy/elementary/src/lib/elm_config.c @@ -246,13 +246,13 @@ _prop_change(void *data __UNUSED__, { if (event->atom == _atom[ATOM_E_PROFILE]) { - if (_prop_change_delay_timer) ecore_timer_del(_prop_change_delay_timer); + ELM_FREE_FUNC(_prop_change_delay_timer, ecore_timer_del); _prop_change_delay_timer = ecore_timer_add(0.1, _prop_change_delay_cb, NULL); } else if (((_atom_config > 0) && (event->atom == _atom_config)) || (event->atom == _atom[ATOM_E_CONFIG])) { - if (_prop_change_delay_timer) ecore_timer_del(_prop_change_delay_timer); + ELM_FREE_FUNC(_prop_change_delay_timer, ecore_timer_del); _prop_change_delay_timer = ecore_timer_add(0.1, _prop_change_delay_cb, NULL); } } @@ -2319,7 +2319,7 @@ EAPI void elm_config_all_flush(void) { #ifdef HAVE_ELEMENTARY_X - if (_prop_all_update_timer) ecore_timer_del(_prop_all_update_timer); + ELM_FREE_FUNC(_prop_all_update_timer, ecore_timer_del); _prop_all_update_timer = ecore_timer_add(0.1, _prop_all_update_cb, NULL); #endif } @@ -2375,12 +2375,10 @@ _elm_config_sub_shutdown(void) #ifdef HAVE_ELEMENTARY_X if (_prop_all_update_timer) { - ecore_timer_del(_prop_all_update_timer); - _prop_all_update_timer = NULL; + ELM_FREE_FUNC(_prop_all_update_timer, ecore_timer_del); _prop_all_update_cb(NULL); } - if (_prop_change_delay_timer) ecore_timer_del(_prop_change_delay_timer); - _prop_change_delay_timer = NULL; + ELM_FREE_FUNC(_prop_change_delay_timer, ecore_timer_del); #endif #define ENGINE_COMPARE(name) (!strcmp(_elm_config->engine, name)) diff --git a/legacy/elementary/src/lib/elm_conform.c b/legacy/elementary/src/lib/elm_conform.c index 8d1e3c9dbd..4463f70726 100644 --- a/legacy/elementary/src/lib/elm_conform.c +++ b/legacy/elementary/src/lib/elm_conform.c @@ -917,16 +917,15 @@ _elm_conformant_smart_del(Eo *obj, void *_pd, va_list *list EINA_UNUSED) Elm_Conformant_Smart_Data *sd = _pd; #ifdef HAVE_ELEMENTARY_X - if (sd->prop_hdl) ecore_event_handler_del(sd->prop_hdl); + ELM_FREE_FUNC(sd->prop_hdl, ecore_event_handler_del); #endif - if (sd->show_region_job) ecore_job_del(sd->show_region_job); - if (sd->port_indi_timer) ecore_timer_del(sd->port_indi_timer); - if (sd->land_indi_timer) ecore_timer_del(sd->land_indi_timer); - if (sd->portrait_indicator) - evas_object_del(sd->portrait_indicator); - if (sd->landscape_indicator) - evas_object_del(sd->landscape_indicator); + ELM_FREE_FUNC(sd->show_region_job, ecore_job_del); + ELM_FREE_FUNC(sd->port_indi_timer, ecore_timer_del); + ELM_FREE_FUNC(sd->land_indi_timer, ecore_timer_del); + ELM_FREE_FUNC(sd->portrait_indicator, evas_object_del); + ELM_FREE_FUNC(sd->landscape_indicator, evas_object_del); + top = elm_widget_top_get(obj); evas_object_data_set(top, "\377 elm,conformant", NULL); diff --git a/legacy/elementary/src/lib/elm_entry.c b/legacy/elementary/src/lib/elm_entry.c index c98d266172..73f946ffc2 100644 --- a/legacy/elementary/src/lib/elm_entry.c +++ b/legacy/elementary/src/lib/elm_entry.c @@ -1382,7 +1382,7 @@ _mouse_down_cb(void *data, sd->downy = ev->canvas.y; if (ev->button == 1) { - if (sd->longpress_timer) ecore_timer_del(sd->longpress_timer); + ELM_FREE_FUNC(sd->longpress_timer, ecore_timer_del); sd->longpress_timer = ecore_timer_add (_elm_config->longpress_timeout, _long_press_cb, data); } @@ -1406,11 +1406,7 @@ _mouse_up_cb(void *data, if (sd->disabled) return; if (ev->button == 1) { - if (sd->longpress_timer) - { - ecore_timer_del(sd->longpress_timer); - sd->longpress_timer = NULL; - } + ELM_FREE_FUNC(sd->longpress_timer, ecore_timer_del); } else if ((ev->button == 3) && (!_elm_config->desktop_entry)) { @@ -1434,11 +1430,7 @@ _mouse_move_cb(void *data, { if (ev->event_flags & EVAS_EVENT_FLAG_ON_HOLD) { - if (sd->longpress_timer) - { - ecore_timer_del(sd->longpress_timer); - sd->longpress_timer = NULL; - } + ELM_FREE_FUNC(sd->longpress_timer, ecore_timer_del); } else if (sd->longpress_timer) { @@ -1452,8 +1444,7 @@ _mouse_move_cb(void *data, ((_elm_config->finger_size / 2) * (_elm_config->finger_size / 2))) { - ecore_timer_del(sd->longpress_timer); - sd->longpress_timer = NULL; + ELM_FREE_FUNC(sd->longpress_timer, ecore_timer_del); } } } @@ -1469,8 +1460,7 @@ _mouse_move_cb(void *data, ((_elm_config->finger_size / 2) * (_elm_config->finger_size / 2))) { - ecore_timer_del(sd->longpress_timer); - sd->longpress_timer = NULL; + ELM_FREE_FUNC(sd->longpress_timer, ecore_timer_del); } } } @@ -1495,11 +1485,7 @@ _entry_changed_handle(void *data, elm_layout_sizing_eval(data); if (sd->text) eina_stringshare_del(sd->text); sd->text = NULL; - if (sd->delay_write) - { - ecore_timer_del(sd->delay_write); - sd->delay_write = NULL; - } + ELM_FREE_FUNC(sd->delay_write, ecore_timer_del); evas_event_thaw(evas_object_evas_get(data)); evas_event_thaw_eval(evas_object_evas_get(data)); if ((sd->auto_save) && (sd->file)) @@ -2975,8 +2961,7 @@ _elm_entry_smart_del(Eo *obj, void *_pd, va_list *list EINA_UNUSED) if (sd->delay_write) { - ecore_timer_del(sd->delay_write); - sd->delay_write = NULL; + ELM_FREE_FUNC(sd->delay_write, ecore_timer_del); if (sd->auto_save) _save_do(obj); } @@ -3009,7 +2994,7 @@ _elm_entry_smart_del(Eo *obj, void *_pd, va_list *list EINA_UNUSED) sd->append_text_left = NULL; sd->append_text_idler = NULL; } - if (sd->longpress_timer) ecore_timer_del(sd->longpress_timer); + ELM_FREE_FUNC(sd->longpress_timer, ecore_timer_del); EINA_LIST_FREE(sd->items, it) { eina_stringshare_del(it->label); @@ -3025,11 +3010,9 @@ _elm_entry_smart_del(Eo *obj, void *_pd, va_list *list EINA_UNUSED) { _filter_free(tf); } - if (sd->delay_write) ecore_timer_del(sd->delay_write); - if (sd->input_panel_imdata) free(sd->input_panel_imdata); - - if (sd->anchor_hover.hover_style) - eina_stringshare_del(sd->anchor_hover.hover_style); + ELM_FREE_FUNC(sd->delay_write, ecore_timer_del); + ELM_FREE_FUNC(sd->input_panel_imdata, free); + ELM_FREE_FUNC(sd->anchor_hover.hover_style, eina_stringshare_del); evas_event_thaw(evas_object_evas_get(obj)); evas_event_thaw_eval(evas_object_evas_get(obj)); @@ -4412,12 +4395,7 @@ _file_set(Eo *obj, void *_pd, va_list *list) Elm_Entry_Smart_Data *sd = _pd; - if (sd->delay_write) - { - ecore_timer_del(sd->delay_write); - sd->delay_write = NULL; - } - + ELM_FREE_FUNC(sd->delay_write, ecore_timer_del); if (sd->auto_save) _save_do(obj); eina_stringshare_replace(&sd->file, file); sd->format = format; @@ -4457,11 +4435,7 @@ _file_save(Eo *obj, void *_pd, va_list *list EINA_UNUSED) { Elm_Entry_Smart_Data *sd = _pd; - if (sd->delay_write) - { - ecore_timer_del(sd->delay_write); - sd->delay_write = NULL; - } + ELM_FREE_FUNC(sd->delay_write, ecore_timer_del); _save_do(obj); sd->delay_write = ecore_timer_add(2.0, _delay_write, obj); } diff --git a/legacy/elementary/src/lib/elm_flipselector.c b/legacy/elementary/src/lib/elm_flipselector.c index d009ab8eb2..4a111e1838 100644 --- a/legacy/elementary/src/lib/elm_flipselector.c +++ b/legacy/elementary/src/lib/elm_flipselector.c @@ -456,8 +456,7 @@ _elm_flipselector_smart_event(Eo *obj, void *_pd, va_list *list) else if ((strcmp(ev->keyname, "Up")) && (strcmp(ev->keyname, "KP_Up"))) return; - if (sd->spin) ecore_timer_del(sd->spin); - sd->spin = NULL; + ELM_FREE_FUNC(sd->spin, ecore_timer_del); /* TODO: if direction setting via API is not coming in, replace these calls by flip_{next,prev} */ @@ -501,7 +500,7 @@ _signal_val_up_start(void *data, sd->interval = sd->first_interval; - if (sd->spin) ecore_timer_del(sd->spin); + ELM_FREE_FUNC(sd->spin, ecore_timer_del); sd->spin = ecore_timer_add(sd->interval, _signal_val_up, data); _signal_val_up(data); @@ -534,7 +533,7 @@ _signal_val_down_start(void *data, sd->interval = sd->first_interval; - if (sd->spin) ecore_timer_del(sd->spin); + ELM_FREE_FUNC(sd->spin, ecore_timer_del); sd->spin = ecore_timer_add(sd->interval, _signal_val_down, data); _signal_val_down(data); @@ -548,8 +547,7 @@ _signal_val_change_stop(void *data, { ELM_FLIPSELECTOR_DATA_GET(data, sd); - if (sd->spin) ecore_timer_del(sd->spin); - sd->spin = NULL; + ELM_FREE_FUNC(sd->spin, ecore_timer_del); } static void @@ -591,7 +589,7 @@ _elm_flipselector_smart_del(Eo *obj, void *_pd, va_list *list EINA_UNUSED) while (sd->items) elm_widget_item_del(DATA_GET(sd->items)); - if (sd->spin) ecore_timer_del(sd->spin); + ELM_FREE_FUNC(sd->spin, ecore_timer_del); eo_do_super(obj, MY_CLASS, evas_obj_smart_del()); } @@ -630,8 +628,7 @@ _flip_next(Eo *obj EINA_UNUSED, void *_pd, va_list *list EINA_UNUSED) { Elm_Flipselector_Smart_Data *sd = _pd; - if (sd->spin) ecore_timer_del(sd->spin); - sd->spin = NULL; + ELM_FREE_FUNC(sd->spin, ecore_timer_del); _flipselector_walk(sd); _flip_down(sd); @@ -650,8 +647,7 @@ _flip_prev(Eo *obj EINA_UNUSED, void *_pd, va_list *list EINA_UNUSED) { Elm_Flipselector_Smart_Data *sd = _pd; - if (sd->spin) ecore_timer_del(sd->spin); - sd->spin = NULL; + ELM_FREE_FUNC(sd->spin, ecore_timer_del); _flipselector_walk(sd); _flip_up(sd); diff --git a/legacy/elementary/src/lib/elm_gengrid.c b/legacy/elementary/src/lib/elm_gengrid.c index ed6a99de69..8eb4994609 100644 --- a/legacy/elementary/src/lib/elm_gengrid.c +++ b/legacy/elementary/src/lib/elm_gengrid.c @@ -328,22 +328,14 @@ _item_mouse_move_cb(void *data, if ((it->dragging) && (it->down)) { - if (it->long_timer) - { - ecore_timer_del(it->long_timer); - it->long_timer = NULL; - } + ELM_FREE_FUNC(it->long_timer, ecore_timer_del); evas_object_smart_callback_call(WIDGET(it), SIG_DRAG, it); return; } if ((!it->down) || (GG_IT(it)->wsd->longpressed)) { - if (it->long_timer) - { - ecore_timer_del(it->long_timer); - it->long_timer = NULL; - } + ELM_FREE_FUNC(it->long_timer, ecore_timer_del); if ((GG_IT(it)->wsd->reorder_mode) && (GG_IT(it)->wsd->reorder_it)) { @@ -408,11 +400,7 @@ _item_mouse_move_cb(void *data, } it->dragging = 1; - if (it->long_timer) - { - ecore_timer_del(it->long_timer); - it->long_timer = NULL; - } + ELM_FREE_FUNC(it->long_timer, ecore_timer_del); if (!GG_IT(it)->wsd->was_selected) _item_unselect(it); @@ -519,7 +507,7 @@ _item_mouse_down_cb(void *data, } evas_object_smart_callback_call(WIDGET(it), SIG_PRESSED, it); - if (it->long_timer) ecore_timer_del(it->long_timer); + ELM_FREE_FUNC(it->long_timer, ecore_timer_del); if (it->realized) it->long_timer = ecore_timer_add (_elm_config->longpress_timeout, _long_press_cb, it); @@ -539,18 +527,11 @@ _elm_gengrid_item_unrealize(Elm_Gen_Item *it, evas_event_freeze(evas_object_evas_get(WIDGET(it))); if (!calc) evas_object_smart_callback_call(WIDGET(it), SIG_UNREALIZED, it); - if (it->long_timer) - { - ecore_timer_del(it->long_timer); - it->long_timer = NULL; - } + ELM_FREE_FUNC(it->long_timer, ecore_timer_del); + ELM_FREE_FUNC(it->texts, elm_widget_stringlist_free); + ELM_FREE_FUNC(it->contents, elm_widget_stringlist_free); + ELM_FREE_FUNC(it->states, elm_widget_stringlist_free); - elm_widget_stringlist_free(it->texts); - it->texts = NULL; - elm_widget_stringlist_free(it->contents); - it->contents = NULL; - elm_widget_stringlist_free(it->states); - it->states = NULL; EINA_LIST_FREE(it->content_objs, content) evas_object_del(content); @@ -583,11 +564,7 @@ _item_mouse_up_cb(void *data, else sd->on_hold = EINA_FALSE; evas_object_smart_callback_call(WIDGET(it), SIG_RELEASED, it); - if (it->long_timer) - { - ecore_timer_del(it->long_timer); - it->long_timer = NULL; - } + ELM_FREE_FUNC(it->long_timer, ecore_timer_del); if (it->dragging) { it->dragging = EINA_FALSE; @@ -2063,11 +2040,7 @@ _elm_gengrid_item_del_serious(Elm_Gen_Item *it) if (it->tooltip.del_cb) it->tooltip.del_cb((void *)it->tooltip.data, WIDGET(it), it); GG_IT(it)->wsd->walking -= it->walking; - if (it->long_timer) - { - ecore_timer_del(it->long_timer); - it->long_timer = NULL; - } + ELM_FREE_FUNC(it->long_timer, ecore_timer_del); if (it->group) GG_IT(it)->wsd->group_items = eina_list_remove(GG_IT(it)->wsd->group_items, it); diff --git a/legacy/elementary/src/lib/elm_genlist.c b/legacy/elementary/src/lib/elm_genlist.c index 6e5c19b0e8..8b7e4e9a84 100644 --- a/legacy/elementary/src/lib/elm_genlist.c +++ b/legacy/elementary/src/lib/elm_genlist.c @@ -373,26 +373,19 @@ _elm_genlist_item_unrealize(Elm_Gen_Item *it, evas_event_freeze(evas_object_evas_get(WIDGET(it))); if (!calc) evas_object_smart_callback_call(WIDGET(it), SIG_UNREALIZED, it); - if (it->long_timer) - { - ecore_timer_del(it->long_timer); - it->long_timer = NULL; - } + ELM_FREE_FUNC(it->long_timer, ecore_timer_del); EINA_LIST_FOREACH(it->texts, l, part) edje_object_part_text_set(VIEW(it), part, NULL); - elm_widget_stringlist_free(it->texts); - it->texts = NULL; - elm_widget_stringlist_free(it->contents); - it->contents = NULL; - elm_widget_stringlist_free(it->states); - it->states = NULL; + ELM_FREE_FUNC(it->texts, elm_widget_stringlist_free); + ELM_FREE_FUNC(it->contents, elm_widget_stringlist_free); + ELM_FREE_FUNC(it->states, elm_widget_stringlist_free); + EINA_LIST_FREE(it->content_objs, content) evas_object_del(content); - eina_list_free(it->item_focus_chain); - it->item_focus_chain = NULL; + ELM_FREE_FUNC(it->item_focus_chain, eina_list_free); it->unrealize_cb(it); @@ -1293,16 +1286,9 @@ _item_cache_add(Elm_Gen_Item *it) itc->selected = it->selected; itc->disabled = elm_widget_item_disabled_get(it); itc->expanded = it->item->expanded; - if (it->long_timer) - { - ecore_timer_del(it->long_timer); - it->long_timer = NULL; - } - if (it->item->swipe_timer) - { - ecore_timer_del(it->item->swipe_timer); - it->item->swipe_timer = NULL; - } + ELM_FREE_FUNC(it->long_timer, ecore_timer_del); + ELM_FREE_FUNC(it->item->swipe_timer, ecore_timer_del); + // FIXME: other callbacks? edje_object_signal_callback_del_full (itc->base_view, "elm,action,expand,toggle", "elm", @@ -3034,11 +3020,7 @@ _elm_genlist_item_del_serious(Elm_Gen_Item *it) if (it->tooltip.del_cb) it->tooltip.del_cb((void *)it->tooltip.data, WIDGET(it), it); sd->walking -= it->walking; - if (it->long_timer) - { - ecore_timer_del(it->long_timer); - it->long_timer = NULL; - } + ELM_FREE_FUNC(it->long_timer, ecore_timer_del); if (it->group) sd->group_items = eina_list_remove(sd->group_items, it); @@ -3094,11 +3076,7 @@ _item_del(Elm_Gen_Item *it) if (sd->move_items) sd->move_items = eina_list_remove(sd->move_items, it); if (it->parent) it->parent->item->items = eina_list_remove(it->parent->item->items, it); - if (it->item->swipe_timer) - { - ecore_timer_del(it->item->swipe_timer); - it->item->swipe_timer = NULL; - } + ELM_FREE_FUNC(it->item->swipe_timer, ecore_timer_del); _elm_genlist_item_del_serious(it); elm_genlist_item_class_unref((Elm_Genlist_Item_Class *)it->itc); evas_event_thaw(evas_object_evas_get(obj)); @@ -3168,21 +3146,13 @@ _item_mouse_move_cb(void *data, else sd->movements++; } - if (it->long_timer) - { - ecore_timer_del(it->long_timer); - it->long_timer = NULL; - } + ELM_FREE_FUNC(it->long_timer, ecore_timer_del); evas_object_smart_callback_call(WIDGET(it), SIG_DRAG, it); return; } if ((!it->down) || (sd->longpressed)) { - if (it->long_timer) - { - ecore_timer_del(it->long_timer); - it->long_timer = NULL; - } + ELM_FREE_FUNC(it->long_timer, ecore_timer_del); if ((sd->reorder_mode) && (sd->reorder_it)) { evas_object_geometry_get(sd->pan_obj, &ox, &oy, &ow, &oh); @@ -3234,11 +3204,7 @@ _item_mouse_move_cb(void *data, if ((adx > minw) || (ady > minh)) { it->dragging = EINA_TRUE; - if (it->long_timer) - { - ecore_timer_del(it->long_timer); - it->long_timer = NULL; - } + ELM_FREE_FUNC(it->long_timer, ecore_timer_del); if (!sd->wasselected) _item_unselect(it); if (dy < 0) @@ -3376,11 +3342,7 @@ _multi_touch_gesture_eval(void *data) ELM_GENLIST_DATA_GET_FROM_ITEM(it, sd); sd->multi_touched = EINA_FALSE; - if (sd->multi_timer) - { - ecore_timer_del(sd->multi_timer); - sd->multi_timer = NULL; - } + ELM_FREE_FUNC(sd->multi_timer, ecore_timer_del); if (sd->multi_timeout) { sd->multi_timeout = EINA_FALSE; @@ -3456,21 +3418,13 @@ _item_multi_down_cb(void *data, _item_unselect(it); sd->wasselected = EINA_FALSE; sd->longpressed = EINA_FALSE; - if (it->long_timer) - { - ecore_timer_del(it->long_timer); - it->long_timer = NULL; - } + ELM_FREE_FUNC(it->long_timer, ecore_timer_del); if (it->dragging) { it->dragging = EINA_FALSE; evas_object_smart_callback_call(WIDGET(it), SIG_DRAG_STOP, it); } - if (it->item->swipe_timer) - { - ecore_timer_del(it->item->swipe_timer); - it->item->swipe_timer = NULL; - } + ELM_FREE_FUNC(it->item->swipe_timer, ecore_timer_del); if (sd->on_hold) { sd->swipe = EINA_FALSE; @@ -3539,7 +3493,7 @@ _item_mouse_down_cb(void *data, sd->prev_x = ev->canvas.x; sd->prev_y = ev->canvas.y; sd->multi_timeout = EINA_FALSE; - if (sd->multi_timer) ecore_timer_del(sd->multi_timer); + ELM_FREE_FUNC(sd->multi_timer, ecore_timer_del); sd->multi_timer = ecore_timer_add(MULTI_DOWN_TIME, _multi_cancel, sd->obj); } sd->longpressed = EINA_FALSE; @@ -3556,9 +3510,9 @@ _item_mouse_down_cb(void *data, evas_object_smart_callback_call(WIDGET(it), SIG_ACTIVATED, it); } evas_object_smart_callback_call(WIDGET(it), SIG_PRESSED, it); - if (it->item->swipe_timer) ecore_timer_del(it->item->swipe_timer); + ELM_FREE_FUNC(it->item->swipe_timer, ecore_timer_del); it->item->swipe_timer = ecore_timer_add(SWIPE_TIME, _swipe_cancel, it); - if (it->long_timer) ecore_timer_del(it->long_timer); + ELM_FREE_FUNC(it->long_timer, ecore_timer_del); if (it->realized) it->long_timer = ecore_timer_add (sd->longpress_timeout, _long_press_cb, it); @@ -4135,26 +4089,17 @@ _item_mouse_up_cb(void *data, if (ev->event_flags & EVAS_EVENT_FLAG_ON_HOLD) sd->on_hold = EINA_TRUE; else sd->on_hold = EINA_FALSE; - if (it->long_timer) - { - ecore_timer_del(it->long_timer); - it->long_timer = NULL; - } + ELM_FREE_FUNC(it->long_timer, ecore_timer_del); if (it->dragging) { it->dragging = EINA_FALSE; evas_object_smart_callback_call(WIDGET(it), SIG_DRAG_STOP, it); dragged = 1; } - if (it->item->swipe_timer) - { - ecore_timer_del(it->item->swipe_timer); - it->item->swipe_timer = NULL; - } + ELM_FREE_FUNC(it->item->swipe_timer, ecore_timer_del); if (sd->multi_timer) { - ecore_timer_del(sd->multi_timer); - sd->multi_timer = NULL; + ELM_FREE_FUNC(sd->multi_timer, ecore_timer_del); sd->multi_timeout = EINA_FALSE; } if (sd->on_hold) @@ -4787,11 +4732,7 @@ _decorate_item_set(Elm_Gen_Item *it) sd->mode_item = it; it->item->nocache_once = EINA_TRUE; - if (sd->scr_hold_timer) - { - ecore_timer_del(sd->scr_hold_timer); - sd->scr_hold_timer = NULL; - } + ELM_FREE_FUNC(sd->scr_hold_timer, ecore_timer_del); eo_do(sd->obj, elm_scrollable_interface_hold_set(EINA_TRUE)); sd->scr_hold_timer = ecore_timer_add(SCR_HOLD_TIME, _scroll_hold_timer_cb, sd->obj); @@ -4916,14 +4857,14 @@ _elm_genlist_smart_del(Eo *obj, void *_pd, va_list *list EINA_UNUSED) sd->pan_obj = NULL; _item_cache_zero(sd); - if (sd->calc_job) ecore_job_del(sd->calc_job); - if (sd->update_job) ecore_job_del(sd->update_job); - if (sd->queue_idle_enterer) ecore_idle_enterer_del(sd->queue_idle_enterer); - if (sd->must_recalc_idler) ecore_idler_del(sd->must_recalc_idler); - if (sd->multi_timer) ecore_timer_del(sd->multi_timer); - if (sd->decorate_it_type) eina_stringshare_del(sd->decorate_it_type); - if (sd->scr_hold_timer) ecore_timer_del(sd->scr_hold_timer); - if (sd->tree_effect_animator) ecore_animator_del(sd->tree_effect_animator); + ELM_FREE_FUNC(sd->calc_job, ecore_job_del); + ELM_FREE_FUNC(sd->update_job, ecore_job_del); + ELM_FREE_FUNC(sd->queue_idle_enterer, ecore_idle_enterer_del); + ELM_FREE_FUNC(sd->must_recalc_idler, ecore_idler_del); + ELM_FREE_FUNC(sd->multi_timer, ecore_timer_del); + ELM_FREE_FUNC(sd->scr_hold_timer, ecore_timer_del); + ELM_FREE_FUNC(sd->decorate_it_type, eina_stringshare_del); + ELM_FREE_FUNC(sd->tree_effect_animator, ecore_animator_del); eo_do_super(obj, MY_CLASS, evas_obj_smart_del()); } diff --git a/legacy/elementary/src/lib/elm_priv.h b/legacy/elementary/src/lib/elm_priv.h index 5d5b5fc38f..eb10177faa 100644 --- a/legacy/elementary/src/lib/elm_priv.h +++ b/legacy/elementary/src/lib/elm_priv.h @@ -144,11 +144,14 @@ extern const char *_elm_engines[]; #define ELM_ACCESS_MODE_OFF EINA_FALSE #define ELM_ACCESS_MODE_ON EINA_TRUE +/* convenience macro to compress code and avoid typos */ #undef MIN #define MIN(x, y) (((x) < (y)) ? (x) : (y)) #undef MAX #define MAX(x, y) (((x) > (y)) ? (x) : (y)) +# define ELM_FREE_FUNC(_h, _fn) do { if (_h) { _fn((void*)_h); _h = NULL; } } while (0) + struct _Elm_Config { int config_version; diff --git a/legacy/elementary/src/lib/elm_toolbar.c b/legacy/elementary/src/lib/elm_toolbar.c index 6841f9e2aa..d7e83f766d 100644 --- a/legacy/elementary/src/lib/elm_toolbar.c +++ b/legacy/elementary/src/lib/elm_toolbar.c @@ -1830,12 +1830,7 @@ static void _drag_start_cb(Evas_Object *obj, void *data __UNUSED__) { ELM_TOOLBAR_DATA_GET(obj, sd); - - if (sd->long_timer) - { - ecore_timer_del(sd->long_timer); - sd->long_timer = NULL; - } + ELM_FREE_FUNC(sd->long_timer, ecore_timer_del); } static void @@ -1849,12 +1844,10 @@ _mouse_move_cb(Elm_Toolbar_Item *it, ELM_TOOLBAR_DATA_GET(WIDGET(it), sd); evas_object_geometry_get(VIEW(it), &x, &y, &w, &h); - if ((sd->long_timer) && - ((x > ev->cur.canvas.x) || (ev->cur.canvas.x > x + w) || - (y > ev->cur.canvas.y) || (ev->cur.canvas.y > y + h))) + if ((x > ev->cur.canvas.x) || (ev->cur.canvas.x > x + w) || + (y > ev->cur.canvas.y) || (ev->cur.canvas.y > y + h)) { - ecore_timer_del(sd->long_timer); - sd->long_timer = NULL; + ELM_FREE_FUNC(sd->long_timer, ecore_timer_del); } }