2013-04-25 22:13:00 -07:00
|
|
|
#ifdef HAVE_CONFIG_H
|
|
|
|
# include "elementary_config.h"
|
|
|
|
#endif
|
|
|
|
|
2014-10-17 08:56:11 -07:00
|
|
|
#define ELM_INTERFACE_ATSPI_ACCESSIBLE_PROTECTED
|
|
|
|
|
2012-05-02 18:19:05 -07:00
|
|
|
#include <Elementary.h>
|
|
|
|
#include "elm_priv.h"
|
2012-08-01 14:04:47 -07:00
|
|
|
#include "elm_widget_dayselector.h"
|
2012-11-25 22:32:53 -08:00
|
|
|
#include "elm_widget_container.h"
|
2012-05-02 18:19:05 -07:00
|
|
|
|
2014-06-03 03:35:28 -07:00
|
|
|
#define MY_CLASS ELM_DAYSELECTOR_CLASS
|
2012-11-25 22:32:53 -08:00
|
|
|
|
2013-11-07 03:44:22 -08:00
|
|
|
#define MY_CLASS_NAME "Elm_Dayselector"
|
|
|
|
#define MY_CLASS_NAME_LEGACY "elm_dayselector"
|
2012-05-02 18:19:05 -07:00
|
|
|
|
|
|
|
/* signals to edc */
|
2012-05-03 15:43:51 -07:00
|
|
|
#define ITEM_TYPE_WEEKDAY_DEFAULT "elm,type,weekday,default"
|
|
|
|
#define ITEM_TYPE_WEEKDAY_STYLE1 "elm,type,weekday,style1"
|
|
|
|
#define ITEM_TYPE_WEEKEND_DEFAULT "elm,type,weekend,default"
|
|
|
|
#define ITEM_TYPE_WEEKEND_STYLE1 "elm,type,weekend,style1"
|
|
|
|
#define ITEM_POS_LEFT "elm,pos,check,left"
|
|
|
|
#define ITEM_POS_RIGHT "elm,pos,check,right"
|
|
|
|
#define ITEM_POS_MIDDLE "elm,pos,check,middle"
|
|
|
|
|
2012-05-02 18:19:05 -07:00
|
|
|
static const char SIG_CHANGED[] = "dayselector,changed";
|
2012-05-03 15:43:51 -07:00
|
|
|
static const Evas_Smart_Cb_Description _smart_callbacks[] = {
|
|
|
|
{SIG_CHANGED, ""},
|
2014-01-23 02:30:34 -08:00
|
|
|
{SIG_WIDGET_LANG_CHANGED, ""}, /**< handled by elm_widget */
|
2014-02-07 21:05:06 -08:00
|
|
|
{SIG_WIDGET_ACCESS_CHANGED, ""}, /**< handled by elm_widget */
|
2012-05-03 15:43:51 -07:00
|
|
|
{NULL, NULL}
|
2012-05-02 18:19:05 -07:00
|
|
|
};
|
|
|
|
|
2014-03-21 07:01:48 -07:00
|
|
|
EOLIAN static void
|
|
|
|
_elm_dayselector_elm_layout_sizing_eval(Eo *obj, Elm_Dayselector_Data *sd EINA_UNUSED)
|
2012-05-02 18:19:05 -07:00
|
|
|
{
|
|
|
|
Evas_Coord min_w = -1, min_h = -1;
|
2013-10-05 01:14:03 -07:00
|
|
|
ELM_WIDGET_DATA_GET_OR_RETURN(obj, wd);
|
2012-05-02 18:19:05 -07:00
|
|
|
|
|
|
|
elm_coords_finger_size_adjust(ELM_DAYSELECTOR_MAX, &min_w, 1, &min_h);
|
2012-05-03 15:43:51 -07:00
|
|
|
edje_object_size_min_restricted_calc
|
2012-11-25 22:32:53 -08:00
|
|
|
(wd->resize_obj, &min_w, &min_h, min_w, min_h);
|
2012-05-02 18:19:05 -07:00
|
|
|
evas_object_size_hint_min_set(obj, min_w, min_h);
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
2012-05-03 15:43:51 -07:00
|
|
|
_dayselector_resize(void *data,
|
2014-01-06 06:30:02 -08:00
|
|
|
Evas *e EINA_UNUSED,
|
|
|
|
Evas_Object *obj EINA_UNUSED,
|
|
|
|
void *event_info EINA_UNUSED)
|
2012-05-02 18:19:05 -07:00
|
|
|
{
|
2012-05-03 15:43:51 -07:00
|
|
|
elm_layout_sizing_eval(data);
|
2012-05-02 18:19:05 -07:00
|
|
|
}
|
|
|
|
|
2014-03-21 07:01:48 -07:00
|
|
|
EOLIAN static Eina_Bool
|
|
|
|
_elm_dayselector_elm_widget_translate(Eo *obj EINA_UNUSED, Elm_Dayselector_Data *sd)
|
2012-05-02 18:19:05 -07:00
|
|
|
{
|
|
|
|
time_t t;
|
2012-05-03 15:43:51 -07:00
|
|
|
Eina_List *l;
|
2012-05-02 18:19:05 -07:00
|
|
|
char buf[1024];
|
2012-05-03 15:43:51 -07:00
|
|
|
struct tm time_daysel;
|
2014-09-27 22:13:49 -07:00
|
|
|
Elm_Dayselector_Item_Data *it;
|
2012-05-03 15:43:51 -07:00
|
|
|
|
2013-07-11 11:34:58 -07:00
|
|
|
if (sd->weekdays_names_set)
|
2014-03-21 07:01:48 -07:00
|
|
|
return EINA_TRUE;
|
2013-07-11 11:34:58 -07:00
|
|
|
|
2012-05-02 18:19:05 -07:00
|
|
|
t = time(NULL);
|
|
|
|
localtime_r(&t, &time_daysel);
|
2012-10-01 00:36:27 -07:00
|
|
|
EINA_LIST_FOREACH(sd->items, l, it)
|
2012-05-02 18:19:05 -07:00
|
|
|
{
|
|
|
|
time_daysel.tm_wday = it->day;
|
|
|
|
strftime(buf, sizeof(buf), "%a", &time_daysel);
|
|
|
|
elm_object_text_set(VIEW(it), buf);
|
|
|
|
}
|
2012-05-03 15:43:51 -07:00
|
|
|
|
2014-04-03 07:03:20 -07:00
|
|
|
eo_do_super(obj, MY_CLASS, elm_obj_widget_translate());
|
2014-01-23 03:20:43 -08:00
|
|
|
|
2014-03-21 07:01:48 -07:00
|
|
|
return EINA_TRUE;
|
2012-05-02 18:19:05 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
2012-05-03 15:43:51 -07:00
|
|
|
_update_items(Evas_Object *obj)
|
2012-05-02 18:19:05 -07:00
|
|
|
{
|
|
|
|
Eina_List *l;
|
2012-05-03 15:43:51 -07:00
|
|
|
Eina_Bool rtl;
|
|
|
|
unsigned int last_day;
|
2014-09-27 22:13:49 -07:00
|
|
|
Elm_Dayselector_Item_Data *it;
|
2012-05-03 15:43:51 -07:00
|
|
|
|
|
|
|
ELM_DAYSELECTOR_DATA_GET(obj, sd);
|
|
|
|
|
|
|
|
last_day = sd->week_start + ELM_DAYSELECTOR_MAX - 1;
|
|
|
|
if (last_day >= ELM_DAYSELECTOR_MAX)
|
|
|
|
last_day = last_day % ELM_DAYSELECTOR_MAX;
|
|
|
|
|
|
|
|
rtl = elm_widget_mirrored_get(obj);
|
2012-10-01 00:36:27 -07:00
|
|
|
EINA_LIST_FOREACH(sd->items, l, it)
|
2012-05-03 15:43:51 -07:00
|
|
|
{
|
2013-10-05 05:35:27 -07:00
|
|
|
elm_object_signal_emit(VIEW(it), it->day_style, ""); // XXX: compat
|
|
|
|
elm_object_signal_emit(VIEW(it), it->day_style, "elm");
|
2012-05-03 15:43:51 -07:00
|
|
|
if (it->day == sd->week_start)
|
|
|
|
{
|
|
|
|
if (rtl) elm_object_signal_emit(VIEW(it), ITEM_POS_RIGHT, "elm");
|
|
|
|
else elm_object_signal_emit(VIEW(it), ITEM_POS_LEFT, "elm");
|
|
|
|
}
|
|
|
|
else if (it->day == last_day)
|
|
|
|
{
|
|
|
|
if (rtl) elm_object_signal_emit(VIEW(it), ITEM_POS_LEFT, "elm");
|
|
|
|
else elm_object_signal_emit(VIEW(it), ITEM_POS_RIGHT, "elm");
|
|
|
|
}
|
|
|
|
else
|
|
|
|
elm_object_signal_emit(VIEW(it), ITEM_POS_MIDDLE, "elm");
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
static inline unsigned int
|
2014-03-21 07:01:48 -07:00
|
|
|
_item_location_get(Elm_Dayselector_Data *sd,
|
2014-09-27 22:13:49 -07:00
|
|
|
Elm_Dayselector_Item_Data *it)
|
2012-05-03 15:43:51 -07:00
|
|
|
{
|
|
|
|
return (ELM_DAYSELECTOR_MAX - sd->week_start + it->day) %
|
|
|
|
ELM_DAYSELECTOR_MAX;
|
|
|
|
}
|
|
|
|
|
2014-03-21 07:01:48 -07:00
|
|
|
EOLIAN static Eina_Bool
|
|
|
|
_elm_dayselector_elm_widget_theme_apply(Eo *obj, Elm_Dayselector_Data *sd)
|
2012-05-03 15:43:51 -07:00
|
|
|
{
|
2012-11-25 22:32:53 -08:00
|
|
|
Eina_Bool int_ret = EINA_FALSE;
|
|
|
|
|
2012-05-03 15:43:51 -07:00
|
|
|
Eina_List *l;
|
2012-05-02 18:19:05 -07:00
|
|
|
char buf[1024];
|
2014-09-27 22:13:49 -07:00
|
|
|
Elm_Dayselector_Item_Data *it;
|
2012-05-03 15:43:51 -07:00
|
|
|
|
2014-04-03 07:03:20 -07:00
|
|
|
eo_do_super(obj, MY_CLASS, int_ret = elm_obj_widget_theme_apply());
|
2014-03-21 07:01:48 -07:00
|
|
|
if (!int_ret) return EINA_FALSE;
|
2012-05-02 18:19:05 -07:00
|
|
|
|
2012-10-01 00:36:27 -07:00
|
|
|
EINA_LIST_FOREACH(sd->items, l, it)
|
2012-05-02 18:19:05 -07:00
|
|
|
{
|
2012-05-03 15:43:51 -07:00
|
|
|
snprintf
|
|
|
|
(buf, sizeof(buf), "dayselector/%s", elm_object_style_get(obj));
|
2012-05-02 18:19:05 -07:00
|
|
|
elm_object_style_set(VIEW(it), buf);
|
2012-05-03 15:43:51 -07:00
|
|
|
|
|
|
|
snprintf
|
|
|
|
(buf, sizeof(buf), "day%d,visible", _item_location_get(sd, it));
|
|
|
|
elm_layout_signal_emit(obj, buf, "elm");
|
2012-05-02 18:19:05 -07:00
|
|
|
}
|
2012-05-03 15:43:51 -07:00
|
|
|
|
2012-05-02 18:19:05 -07:00
|
|
|
_update_items(obj);
|
2012-05-03 15:43:51 -07:00
|
|
|
elm_layout_sizing_eval(obj);
|
|
|
|
|
2014-03-21 07:01:48 -07:00
|
|
|
return EINA_TRUE;
|
2012-05-02 18:19:05 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
2012-05-03 15:43:51 -07:00
|
|
|
_item_del_cb(void *data,
|
2014-01-06 06:30:02 -08:00
|
|
|
Evas *e EINA_UNUSED,
|
2012-05-03 15:43:51 -07:00
|
|
|
Evas_Object *obj,
|
2014-01-06 06:30:02 -08:00
|
|
|
void *event_info EINA_UNUSED)
|
2012-05-02 18:19:05 -07:00
|
|
|
{
|
|
|
|
Eina_List *l;
|
|
|
|
char buf[1024];
|
2014-09-27 22:13:49 -07:00
|
|
|
Elm_Dayselector_Item_Data *it;
|
2012-05-03 15:43:51 -07:00
|
|
|
|
|
|
|
ELM_DAYSELECTOR_DATA_GET(data, sd);
|
2012-05-02 18:19:05 -07:00
|
|
|
|
2012-10-01 00:36:27 -07:00
|
|
|
EINA_LIST_FOREACH(sd->items, l, it)
|
2012-05-02 18:19:05 -07:00
|
|
|
{
|
|
|
|
if (obj == VIEW(it))
|
|
|
|
{
|
2012-05-03 15:43:51 -07:00
|
|
|
sd->items = eina_list_remove(sd->items, it);
|
2012-05-02 18:19:05 -07:00
|
|
|
eina_stringshare_del(it->day_style);
|
2012-05-03 15:43:51 -07:00
|
|
|
snprintf(buf, sizeof(buf), "day%d,default",
|
|
|
|
_item_location_get(sd, it));
|
|
|
|
elm_layout_signal_emit(obj, buf, "elm");
|
|
|
|
|
|
|
|
VIEW(it) = NULL;
|
2014-08-19 00:52:24 -07:00
|
|
|
eo_del(EO_OBJ(it));
|
2012-05-03 15:43:51 -07:00
|
|
|
|
|
|
|
elm_layout_sizing_eval(obj);
|
2012-05-02 18:19:05 -07:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
2012-05-03 15:43:51 -07:00
|
|
|
_item_signal_emit_cb(void *data,
|
2014-01-06 06:30:02 -08:00
|
|
|
Evas_Object *obj EINA_UNUSED,
|
2012-05-03 15:43:51 -07:00
|
|
|
const char *emission,
|
2014-01-06 06:30:02 -08:00
|
|
|
const char *source EINA_UNUSED)
|
2012-05-02 18:19:05 -07:00
|
|
|
{
|
2014-09-27 22:13:49 -07:00
|
|
|
Elm_Dayselector_Item_Data *it = data;
|
2012-05-02 18:19:05 -07:00
|
|
|
|
2012-05-03 15:43:51 -07:00
|
|
|
eina_stringshare_replace(&it->day_style, emission);
|
2012-05-02 18:19:05 -07:00
|
|
|
}
|
|
|
|
|
2015-04-29 04:30:15 -07:00
|
|
|
static Eina_Bool
|
2012-05-03 15:43:51 -07:00
|
|
|
_item_clicked_cb(void *data,
|
2015-04-29 04:30:15 -07:00
|
|
|
Eo *obj EINA_UNUSED, const Eo_Event_Description *desc EINA_UNUSED, void *event_info EINA_UNUSED)
|
2012-05-02 18:19:05 -07:00
|
|
|
{
|
2014-09-27 22:13:49 -07:00
|
|
|
Elm_Dayselector_Item_Data *it = data;
|
2012-05-02 18:19:05 -07:00
|
|
|
|
2015-04-29 04:30:15 -07:00
|
|
|
eo_do(WIDGET(it), eo_event_callback_call(ELM_CHECK_EVENT_CHANGED, (void *)it->day));
|
|
|
|
|
|
|
|
return EINA_TRUE;
|
2012-05-02 18:19:05 -07:00
|
|
|
}
|
|
|
|
|
2014-09-27 22:13:49 -07:00
|
|
|
static Elm_Dayselector_Item_Data *
|
2012-05-03 15:43:51 -07:00
|
|
|
_item_find(const Evas_Object *obj,
|
|
|
|
Elm_Dayselector_Day day)
|
2012-05-02 18:19:05 -07:00
|
|
|
{
|
|
|
|
Eina_List *l;
|
2014-09-27 22:13:49 -07:00
|
|
|
Elm_Dayselector_Item_Data *it;
|
2012-05-02 18:19:05 -07:00
|
|
|
|
2012-05-03 15:43:51 -07:00
|
|
|
ELM_DAYSELECTOR_DATA_GET(obj, sd);
|
|
|
|
|
2012-10-01 00:36:27 -07:00
|
|
|
EINA_LIST_FOREACH(sd->items, l, it)
|
2012-05-03 15:43:51 -07:00
|
|
|
if (day == it->day) return it;
|
|
|
|
|
2012-05-02 18:19:05 -07:00
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
2014-03-21 07:01:48 -07:00
|
|
|
EOLIAN static Eina_Bool
|
|
|
|
_elm_dayselector_elm_container_content_set(Eo *obj, Elm_Dayselector_Data *sd, const char *item, Evas_Object *content)
|
2012-05-02 18:19:05 -07:00
|
|
|
{
|
2012-11-25 22:32:53 -08:00
|
|
|
Eina_Bool int_ret = EINA_FALSE;
|
|
|
|
|
2012-05-03 15:43:51 -07:00
|
|
|
int day;
|
2012-05-02 18:19:05 -07:00
|
|
|
char buf[1024];
|
2014-09-27 22:13:49 -07:00
|
|
|
Elm_Dayselector_Item_Data *it = NULL;
|
2015-06-17 06:02:48 -07:00
|
|
|
const char *type = elm_object_widget_type_get(content);
|
2012-05-03 15:43:51 -07:00
|
|
|
|
2015-06-17 06:02:48 -07:00
|
|
|
if (type && strcmp(type, "Elm_Check"))
|
2014-03-21 07:01:48 -07:00
|
|
|
return EINA_FALSE;
|
2012-05-03 15:43:51 -07:00
|
|
|
|
2014-03-21 07:01:48 -07:00
|
|
|
if (!item) return EINA_FALSE;
|
2012-05-03 15:43:51 -07:00
|
|
|
|
|
|
|
day = atoi(item + (strlen(item) - 1));
|
2014-03-21 07:01:48 -07:00
|
|
|
if (day < 0 || day > ELM_DAYSELECTOR_MAX) return EINA_FALSE;
|
2012-05-02 18:19:05 -07:00
|
|
|
|
2012-05-03 15:43:51 -07:00
|
|
|
it = _item_find(obj, day);
|
|
|
|
if (it)
|
2012-05-02 18:19:05 -07:00
|
|
|
{
|
2012-05-03 15:43:51 -07:00
|
|
|
snprintf(buf, sizeof(buf), "day%d", _item_location_get(sd, it));
|
|
|
|
|
2014-04-03 07:03:20 -07:00
|
|
|
eo_do_super(obj, MY_CLASS, int_ret = elm_obj_container_content_set(buf, content));
|
2014-03-21 07:01:48 -07:00
|
|
|
if (!int_ret) return EINA_FALSE;
|
2012-05-03 15:43:51 -07:00
|
|
|
|
2014-03-21 07:01:48 -07:00
|
|
|
if (!content) return EINA_TRUE; /* item deletion already handled */
|
2012-05-03 15:43:51 -07:00
|
|
|
|
|
|
|
evas_object_del(VIEW(it));
|
|
|
|
VIEW(it) = content;
|
2012-05-02 18:19:05 -07:00
|
|
|
}
|
2012-05-03 15:43:51 -07:00
|
|
|
else
|
2012-05-02 18:19:05 -07:00
|
|
|
{
|
2014-09-27 22:13:49 -07:00
|
|
|
Eo *eo_it = eo_add(ELM_DAYSELECTOR_ITEM_CLASS, obj);
|
|
|
|
it = eo_data_scope_get(eo_it, ELM_DAYSELECTOR_ITEM_CLASS);
|
2012-05-03 15:43:51 -07:00
|
|
|
it->day = day;
|
|
|
|
|
|
|
|
snprintf(buf, sizeof(buf), "day%d", _item_location_get(sd, it));
|
|
|
|
|
2014-04-03 07:03:20 -07:00
|
|
|
eo_do_super(obj, MY_CLASS, int_ret = elm_obj_container_content_set(buf, content));
|
2012-11-25 22:32:53 -08:00
|
|
|
if (!int_ret)
|
2012-05-02 18:19:05 -07:00
|
|
|
{
|
2014-09-27 22:13:49 -07:00
|
|
|
eo_del(eo_it);
|
2014-03-21 07:01:48 -07:00
|
|
|
return EINA_FALSE;
|
2012-05-02 18:19:05 -07:00
|
|
|
}
|
2012-05-03 15:43:51 -07:00
|
|
|
|
|
|
|
sd->items = eina_list_append(sd->items, it);
|
|
|
|
VIEW(it) = content;
|
2012-05-02 18:19:05 -07:00
|
|
|
}
|
|
|
|
|
2012-05-03 15:43:51 -07:00
|
|
|
snprintf(buf, sizeof(buf), "day%d,visible", _item_location_get(sd, it));
|
|
|
|
elm_layout_signal_emit(obj, buf, "elm");
|
2012-05-02 18:19:05 -07:00
|
|
|
|
2015-04-29 04:30:15 -07:00
|
|
|
eo_do(VIEW(it), eo_event_callback_add
|
|
|
|
(ELM_CHECK_EVENT_CHANGED, _item_clicked_cb, it));
|
2012-05-03 15:43:51 -07:00
|
|
|
evas_object_event_callback_add
|
|
|
|
(VIEW(it), EVAS_CALLBACK_DEL, _item_del_cb, obj);
|
|
|
|
|
|
|
|
elm_object_signal_callback_add
|
2013-10-05 05:35:27 -07:00
|
|
|
(VIEW(it), ITEM_TYPE_WEEKDAY_DEFAULT, "*", _item_signal_emit_cb, it);
|
2012-05-03 15:43:51 -07:00
|
|
|
elm_object_signal_callback_add
|
2013-10-05 05:35:27 -07:00
|
|
|
(VIEW(it), ITEM_TYPE_WEEKDAY_STYLE1, "*", _item_signal_emit_cb, it);
|
2012-05-03 15:43:51 -07:00
|
|
|
elm_object_signal_callback_add
|
2013-10-05 05:35:27 -07:00
|
|
|
(VIEW(it), ITEM_TYPE_WEEKEND_DEFAULT, "*", _item_signal_emit_cb, it);
|
2012-05-03 15:43:51 -07:00
|
|
|
elm_object_signal_callback_add
|
2013-10-05 05:35:27 -07:00
|
|
|
(VIEW(it), ITEM_TYPE_WEEKEND_STYLE1, "*", _item_signal_emit_cb, it);
|
2012-05-03 15:43:51 -07:00
|
|
|
|
|
|
|
elm_layout_sizing_eval(obj);
|
|
|
|
_update_items(obj);
|
|
|
|
|
2014-03-21 07:01:48 -07:00
|
|
|
return EINA_TRUE;
|
2012-05-02 18:19:05 -07:00
|
|
|
}
|
|
|
|
|
2015-05-19 05:34:07 -07:00
|
|
|
EOLIAN static Eo *
|
2014-09-27 22:13:49 -07:00
|
|
|
_elm_dayselector_item_eo_base_constructor(Eo *eo_item, Elm_Dayselector_Item_Data *item)
|
|
|
|
{
|
2015-05-19 05:34:07 -07:00
|
|
|
eo_item = eo_do_super_ret(eo_item, ELM_DAYSELECTOR_ITEM_CLASS, eo_item, eo_constructor());
|
2014-09-27 22:13:49 -07:00
|
|
|
item->base = eo_data_scope_get(eo_item, ELM_WIDGET_ITEM_CLASS);
|
2015-05-19 05:34:07 -07:00
|
|
|
|
|
|
|
return eo_item;
|
2014-09-27 22:13:49 -07:00
|
|
|
}
|
|
|
|
|
2014-03-21 07:01:48 -07:00
|
|
|
EOLIAN static Evas_Object*
|
|
|
|
_elm_dayselector_elm_container_content_unset(Eo *obj, Elm_Dayselector_Data *sd, const char *item)
|
2012-05-02 18:19:05 -07:00
|
|
|
{
|
2012-05-03 15:43:51 -07:00
|
|
|
int day;
|
2012-05-02 18:19:05 -07:00
|
|
|
char buf[1024];
|
2012-05-03 15:43:51 -07:00
|
|
|
Evas_Object *content;
|
2014-09-27 22:13:49 -07:00
|
|
|
Elm_Dayselector_Item_Data *it = NULL;
|
2012-05-02 18:19:05 -07:00
|
|
|
|
2012-05-03 15:43:51 -07:00
|
|
|
day = atoi(item + (strlen(item) - 1));
|
2014-03-21 07:01:48 -07:00
|
|
|
if (day < 0 || day > ELM_DAYSELECTOR_MAX) return NULL;
|
2012-05-02 18:19:05 -07:00
|
|
|
|
2012-05-03 15:43:51 -07:00
|
|
|
it = _item_find(obj, day);
|
2014-03-21 07:01:48 -07:00
|
|
|
if (!it) return NULL;
|
2012-05-02 18:19:05 -07:00
|
|
|
|
2012-05-03 15:43:51 -07:00
|
|
|
content = VIEW(it);
|
2012-05-02 18:19:05 -07:00
|
|
|
|
2014-04-03 07:03:20 -07:00
|
|
|
eo_do_super(obj, MY_CLASS, content = elm_obj_container_content_unset(buf));
|
2014-03-21 07:01:48 -07:00
|
|
|
if (!content) return NULL;
|
2012-05-02 18:19:05 -07:00
|
|
|
|
2012-05-03 15:43:51 -07:00
|
|
|
sd->items = eina_list_remove(sd->items, it);
|
2015-04-29 04:30:15 -07:00
|
|
|
eo_do(content, eo_event_callback_del(
|
|
|
|
ELM_CHECK_EVENT_CHANGED, _item_clicked_cb, it));
|
2012-05-03 15:43:51 -07:00
|
|
|
evas_object_event_callback_del(content, EVAS_CALLBACK_DEL, _item_del_cb);
|
|
|
|
|
|
|
|
elm_object_signal_callback_del
|
2013-10-05 05:35:27 -07:00
|
|
|
(content, ITEM_TYPE_WEEKDAY_DEFAULT, "*", _item_signal_emit_cb);
|
2012-05-03 15:43:51 -07:00
|
|
|
elm_object_signal_callback_del
|
2013-10-05 05:35:27 -07:00
|
|
|
(content, ITEM_TYPE_WEEKDAY_STYLE1, "*", _item_signal_emit_cb);
|
2012-05-03 15:43:51 -07:00
|
|
|
elm_object_signal_callback_del
|
2013-10-05 05:35:27 -07:00
|
|
|
(content, ITEM_TYPE_WEEKEND_DEFAULT, "*", _item_signal_emit_cb);
|
2012-05-03 15:43:51 -07:00
|
|
|
elm_object_signal_callback_del
|
2013-10-05 05:35:27 -07:00
|
|
|
(content, ITEM_TYPE_WEEKEND_STYLE1, "*", _item_signal_emit_cb);
|
2012-05-03 15:43:51 -07:00
|
|
|
|
|
|
|
snprintf(buf, sizeof(buf), "day%d,default", _item_location_get(sd, it));
|
|
|
|
elm_layout_signal_emit(obj, buf, "elm");
|
|
|
|
|
|
|
|
VIEW(it) = NULL;
|
2014-08-19 00:52:24 -07:00
|
|
|
eo_del(EO_OBJ(it));
|
2012-05-03 15:43:51 -07:00
|
|
|
|
|
|
|
elm_layout_sizing_eval(obj);
|
|
|
|
|
2014-03-21 07:01:48 -07:00
|
|
|
return content;
|
2012-05-02 18:19:05 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
_items_style_set(Evas_Object *obj)
|
|
|
|
{
|
|
|
|
Eina_List *l;
|
2014-09-27 22:13:49 -07:00
|
|
|
Elm_Dayselector_Item_Data *it;
|
2012-05-02 18:19:05 -07:00
|
|
|
unsigned int weekend_last;
|
|
|
|
|
2012-05-03 15:43:51 -07:00
|
|
|
ELM_DAYSELECTOR_DATA_GET(obj, sd);
|
|
|
|
|
|
|
|
weekend_last = sd->weekend_start + sd->weekend_len - 1;
|
2012-05-02 18:19:05 -07:00
|
|
|
if (weekend_last >= ELM_DAYSELECTOR_MAX)
|
|
|
|
weekend_last = weekend_last % ELM_DAYSELECTOR_MAX;
|
|
|
|
|
2012-10-01 00:36:27 -07:00
|
|
|
EINA_LIST_FOREACH(sd->items, l, it)
|
2012-05-02 18:19:05 -07:00
|
|
|
{
|
2012-05-03 15:43:51 -07:00
|
|
|
if (weekend_last >= sd->weekend_start)
|
2012-05-02 18:19:05 -07:00
|
|
|
{
|
2012-05-03 15:43:51 -07:00
|
|
|
if ((it->day >= sd->weekend_start) && (it->day <= weekend_last))
|
2012-05-02 18:19:05 -07:00
|
|
|
eina_stringshare_replace(&it->day_style,
|
|
|
|
ITEM_TYPE_WEEKEND_DEFAULT);
|
|
|
|
else
|
|
|
|
eina_stringshare_replace(&it->day_style,
|
|
|
|
ITEM_TYPE_WEEKDAY_DEFAULT);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2012-05-03 15:43:51 -07:00
|
|
|
if ((it->day >= sd->weekend_start) || (it->day <= weekend_last))
|
2012-05-02 18:19:05 -07:00
|
|
|
eina_stringshare_replace(&it->day_style,
|
|
|
|
ITEM_TYPE_WEEKEND_DEFAULT);
|
|
|
|
else
|
|
|
|
eina_stringshare_replace(&it->day_style,
|
|
|
|
ITEM_TYPE_WEEKDAY_DEFAULT);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
2012-05-03 15:43:51 -07:00
|
|
|
_items_create(Evas_Object *obj)
|
2012-05-02 18:19:05 -07:00
|
|
|
{
|
|
|
|
time_t t;
|
|
|
|
char buf[1024];
|
2012-05-03 15:43:51 -07:00
|
|
|
unsigned int idx;
|
|
|
|
struct tm time_daysel;
|
2012-05-02 18:19:05 -07:00
|
|
|
|
|
|
|
t = time(NULL);
|
|
|
|
localtime_r(&t, &time_daysel);
|
|
|
|
|
|
|
|
for (idx = 0; idx < ELM_DAYSELECTOR_MAX; idx++)
|
|
|
|
{
|
2012-05-03 15:43:51 -07:00
|
|
|
Evas_Object *chk;
|
|
|
|
|
|
|
|
chk = elm_check_add(obj);
|
|
|
|
elm_object_style_set(chk, "dayselector/default");
|
|
|
|
|
2012-05-02 18:19:05 -07:00
|
|
|
time_daysel.tm_wday = idx;
|
|
|
|
strftime(buf, sizeof(buf), "%a", &time_daysel);
|
2012-05-03 15:43:51 -07:00
|
|
|
elm_object_text_set(chk, buf);
|
|
|
|
|
|
|
|
snprintf(buf, sizeof(buf), "day%d", idx);
|
|
|
|
elm_layout_content_set(obj, buf, chk);
|
2012-07-31 05:24:58 -07:00
|
|
|
|
|
|
|
// XXX: ACCESS
|
2013-07-30 20:53:04 -07:00
|
|
|
_elm_access_text_set(_elm_access_info_get(chk),
|
2012-07-31 05:24:58 -07:00
|
|
|
ELM_ACCESS_TYPE, E_("day selector item"));
|
2012-05-02 18:19:05 -07:00
|
|
|
}
|
2012-05-03 15:43:51 -07:00
|
|
|
|
2012-05-02 18:19:05 -07:00
|
|
|
_items_style_set(obj);
|
|
|
|
_update_items(obj);
|
|
|
|
}
|
|
|
|
|
2014-03-21 07:01:48 -07:00
|
|
|
EOLIAN static void
|
2014-06-03 03:35:28 -07:00
|
|
|
_elm_dayselector_evas_object_smart_add(Eo *obj, Elm_Dayselector_Data *priv)
|
2012-05-03 15:43:51 -07:00
|
|
|
{
|
2013-03-18 09:07:38 -07:00
|
|
|
eo_do_super(obj, MY_CLASS, evas_obj_smart_add());
|
2013-09-24 21:33:39 -07:00
|
|
|
elm_widget_sub_object_parent_add(obj);
|
2013-08-26 08:29:45 -07:00
|
|
|
|
2013-11-12 10:24:59 -08:00
|
|
|
if (!elm_layout_theme_set(obj, "dayselector", "base",
|
|
|
|
elm_widget_style_get(obj)))
|
2013-12-25 20:03:55 -08:00
|
|
|
CRI("Failed to set layout!");
|
2012-05-03 15:43:51 -07:00
|
|
|
|
|
|
|
priv->week_start = _elm_config->week_start;
|
|
|
|
priv->weekend_start = _elm_config->weekend_start;
|
|
|
|
priv->weekend_len = _elm_config->weekend_len;
|
|
|
|
_items_create(obj);
|
|
|
|
|
|
|
|
evas_object_event_callback_add
|
|
|
|
(obj, EVAS_CALLBACK_RESIZE, _dayselector_resize, obj);
|
|
|
|
|
|
|
|
elm_layout_sizing_eval(obj);
|
|
|
|
}
|
|
|
|
|
2014-03-21 07:01:48 -07:00
|
|
|
EOLIAN static void
|
2014-06-03 03:35:28 -07:00
|
|
|
_elm_dayselector_evas_object_smart_del(Eo *obj, Elm_Dayselector_Data *sd)
|
2012-05-03 15:43:51 -07:00
|
|
|
{
|
2014-09-27 22:13:49 -07:00
|
|
|
Elm_Dayselector_Item_Data *it;
|
2012-05-03 15:43:51 -07:00
|
|
|
|
2013-03-08 20:23:42 -08:00
|
|
|
EINA_LIST_FREE(sd->items, it)
|
2012-05-03 15:43:51 -07:00
|
|
|
{
|
|
|
|
sd->items = eina_list_remove(sd->items, it);
|
|
|
|
eina_stringshare_del(it->day_style);
|
2014-08-19 00:52:24 -07:00
|
|
|
eo_del(EO_OBJ(it));
|
2012-05-03 15:43:51 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
/* handles freeing sd */
|
2013-03-18 09:07:38 -07:00
|
|
|
eo_do_super(obj, MY_CLASS, evas_obj_smart_del());
|
2012-05-03 15:43:51 -07:00
|
|
|
}
|
|
|
|
|
2012-05-02 18:19:05 -07:00
|
|
|
EAPI Evas_Object *
|
|
|
|
elm_dayselector_add(Evas_Object *parent)
|
|
|
|
{
|
2012-05-03 15:43:51 -07:00
|
|
|
EINA_SAFETY_ON_NULL_RETURN_VAL(parent, NULL);
|
2012-11-25 22:32:53 -08:00
|
|
|
Evas_Object *obj = eo_add(MY_CLASS, parent);
|
|
|
|
return obj;
|
|
|
|
}
|
2012-05-03 15:43:51 -07:00
|
|
|
|
2015-05-19 05:34:07 -07:00
|
|
|
EOLIAN static Eo *
|
2014-03-21 07:01:48 -07:00
|
|
|
_elm_dayselector_eo_base_constructor(Eo *obj, Elm_Dayselector_Data *_pd EINA_UNUSED)
|
2012-11-25 22:32:53 -08:00
|
|
|
{
|
2015-05-19 05:34:07 -07:00
|
|
|
obj = eo_do_super_ret(obj, MY_CLASS, obj, eo_constructor());
|
2012-11-25 22:32:53 -08:00
|
|
|
eo_do(obj,
|
2013-11-07 03:44:22 -08:00
|
|
|
evas_obj_type_set(MY_CLASS_NAME_LEGACY),
|
2014-06-10 19:07:15 -07:00
|
|
|
evas_obj_smart_callbacks_descriptions_set(_smart_callbacks),
|
|
|
|
elm_interface_atspi_accessible_role_set(ELM_ATSPI_ROLE_PANEL));
|
2015-05-19 05:34:07 -07:00
|
|
|
|
|
|
|
return obj;
|
2012-05-02 18:19:05 -07:00
|
|
|
}
|
|
|
|
|
2014-03-21 07:01:48 -07:00
|
|
|
EOLIAN static void
|
|
|
|
_elm_dayselector_day_selected_set(Eo *obj, Elm_Dayselector_Data *_pd EINA_UNUSED, Elm_Dayselector_Day day, Eina_Bool selected)
|
2012-11-25 22:32:53 -08:00
|
|
|
{
|
2015-06-17 06:02:48 -07:00
|
|
|
Elm_Dayselector_Item_Data *it = _item_find(obj, day);
|
|
|
|
if (!it)
|
|
|
|
{
|
|
|
|
ERR("Failed to find item");
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
elm_check_state_set(VIEW(it), selected);
|
2012-05-02 18:19:05 -07:00
|
|
|
}
|
|
|
|
|
2014-03-21 07:01:48 -07:00
|
|
|
EOLIAN static Eina_Bool
|
2015-06-25 04:21:00 -07:00
|
|
|
_elm_dayselector_day_selected_get(const Eo *obj, Elm_Dayselector_Data *_pd EINA_UNUSED, Elm_Dayselector_Day day)
|
2012-05-02 18:19:05 -07:00
|
|
|
{
|
2015-06-17 06:02:48 -07:00
|
|
|
Elm_Dayselector_Item_Data *it = _item_find(obj, day);
|
|
|
|
if (!it)
|
|
|
|
{
|
|
|
|
ERR("Failed to find item");
|
|
|
|
return EINA_FALSE;
|
|
|
|
}
|
|
|
|
return elm_check_state_get(VIEW(it));
|
2012-11-25 22:32:53 -08:00
|
|
|
}
|
|
|
|
|
2014-03-21 07:01:48 -07:00
|
|
|
EOLIAN static void
|
|
|
|
_elm_dayselector_week_start_set(Eo *obj, Elm_Dayselector_Data *sd, Elm_Dayselector_Day day)
|
2012-11-25 22:32:53 -08:00
|
|
|
{
|
2013-10-05 01:14:03 -07:00
|
|
|
ELM_WIDGET_DATA_GET_OR_RETURN(obj, wd);
|
2012-05-02 18:19:05 -07:00
|
|
|
Eina_List *l;
|
|
|
|
char buf[1024];
|
2014-09-27 22:13:49 -07:00
|
|
|
Elm_Dayselector_Item_Data *it;
|
2012-05-03 15:43:51 -07:00
|
|
|
|
|
|
|
/* just shuffling items, so swalling them directly */
|
|
|
|
sd->week_start = day;
|
2012-10-01 00:36:27 -07:00
|
|
|
EINA_LIST_FOREACH(sd->items, l, it)
|
2012-05-02 18:19:05 -07:00
|
|
|
{
|
2012-05-03 15:43:51 -07:00
|
|
|
snprintf(buf, sizeof(buf), "day%d", _item_location_get(sd, it));
|
|
|
|
edje_object_part_swallow
|
2012-11-25 22:32:53 -08:00
|
|
|
(wd->resize_obj, buf, VIEW(it));
|
2012-05-02 18:19:05 -07:00
|
|
|
}
|
2012-05-03 15:43:51 -07:00
|
|
|
|
2012-05-02 18:19:05 -07:00
|
|
|
_update_items(obj);
|
|
|
|
}
|
|
|
|
|
2014-03-21 07:01:48 -07:00
|
|
|
EOLIAN static Elm_Dayselector_Day
|
|
|
|
_elm_dayselector_week_start_get(Eo *obj EINA_UNUSED, Elm_Dayselector_Data *sd)
|
2012-05-02 18:19:05 -07:00
|
|
|
{
|
2014-03-21 07:01:48 -07:00
|
|
|
return sd->week_start;
|
2012-11-25 22:32:53 -08:00
|
|
|
}
|
|
|
|
|
2014-03-21 07:01:48 -07:00
|
|
|
EOLIAN static void
|
|
|
|
_elm_dayselector_weekend_start_set(Eo *obj, Elm_Dayselector_Data *sd, Elm_Dayselector_Day day)
|
2012-11-25 22:32:53 -08:00
|
|
|
{
|
2012-05-03 15:43:51 -07:00
|
|
|
sd->weekend_start = day;
|
2012-05-02 18:19:05 -07:00
|
|
|
|
|
|
|
_items_style_set(obj);
|
|
|
|
_update_items(obj);
|
|
|
|
}
|
|
|
|
|
2014-03-21 07:01:48 -07:00
|
|
|
EOLIAN static Elm_Dayselector_Day
|
|
|
|
_elm_dayselector_weekend_start_get(Eo *obj EINA_UNUSED, Elm_Dayselector_Data *sd)
|
2012-05-02 18:19:05 -07:00
|
|
|
{
|
2014-03-21 07:01:48 -07:00
|
|
|
return sd->weekend_start;
|
2012-11-25 22:32:53 -08:00
|
|
|
}
|
|
|
|
|
2014-03-21 07:01:48 -07:00
|
|
|
EOLIAN static void
|
|
|
|
_elm_dayselector_weekend_length_set(Eo *obj, Elm_Dayselector_Data *sd, unsigned int length)
|
2012-11-25 22:32:53 -08:00
|
|
|
{
|
2012-05-03 15:43:51 -07:00
|
|
|
sd->weekend_len = length;
|
2012-05-02 18:19:05 -07:00
|
|
|
|
|
|
|
_items_style_set(obj);
|
|
|
|
_update_items(obj);
|
|
|
|
}
|
|
|
|
|
2014-03-21 07:01:48 -07:00
|
|
|
EOLIAN static unsigned int
|
|
|
|
_elm_dayselector_weekend_length_get(Eo *obj EINA_UNUSED, Elm_Dayselector_Data *sd)
|
2013-07-11 11:34:58 -07:00
|
|
|
{
|
2014-03-21 07:01:48 -07:00
|
|
|
return sd->weekend_len;
|
2013-07-11 11:34:58 -07:00
|
|
|
}
|
|
|
|
|
2014-03-21 07:01:48 -07:00
|
|
|
EOLIAN static void
|
|
|
|
_elm_dayselector_weekdays_names_set(Eo *obj, Elm_Dayselector_Data *sd, const char **weekdays)
|
2013-07-11 11:34:58 -07:00
|
|
|
{
|
|
|
|
int idx;
|
|
|
|
time_t now;
|
|
|
|
struct tm time_daysel;
|
2014-09-27 22:13:49 -07:00
|
|
|
Elm_Dayselector_Item_Data *it;
|
2013-07-11 11:34:58 -07:00
|
|
|
char buf[1024];
|
|
|
|
|
|
|
|
if (weekdays)
|
|
|
|
sd->weekdays_names_set = EINA_TRUE;
|
|
|
|
else
|
|
|
|
{
|
2013-11-12 10:24:03 -08:00
|
|
|
now = time(NULL);
|
|
|
|
localtime_r(&now, &time_daysel);
|
|
|
|
sd->weekdays_names_set = EINA_FALSE;
|
2013-07-11 11:34:58 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
for (idx = 0; idx < ELM_DAYSELECTOR_MAX; idx++)
|
|
|
|
{
|
|
|
|
it = _item_find(obj, idx);
|
2015-06-17 06:02:48 -07:00
|
|
|
if (!it) continue;
|
2013-07-11 11:34:58 -07:00
|
|
|
|
|
|
|
if (sd->weekdays_names_set)
|
|
|
|
elm_object_text_set(VIEW(it), weekdays[idx]);
|
|
|
|
else
|
2013-11-12 10:24:03 -08:00
|
|
|
{
|
|
|
|
time_daysel.tm_wday = idx;
|
|
|
|
strftime(buf, sizeof(buf), "%a", &time_daysel);
|
|
|
|
elm_object_text_set(VIEW(it), buf);
|
|
|
|
}
|
2013-07-11 11:34:58 -07:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2014-03-21 07:01:48 -07:00
|
|
|
EOLIAN static Eina_List *
|
2015-06-25 04:21:00 -07:00
|
|
|
_elm_dayselector_weekdays_names_get(const Eo *obj, Elm_Dayselector_Data *sd EINA_UNUSED)
|
2013-07-11 11:34:58 -07:00
|
|
|
{
|
|
|
|
int idx;
|
|
|
|
const char *weekday;
|
2014-09-27 22:13:49 -07:00
|
|
|
Elm_Dayselector_Item_Data *it;
|
2014-03-21 07:01:48 -07:00
|
|
|
Eina_List *weekdays = NULL;
|
2013-07-11 11:34:58 -07:00
|
|
|
|
|
|
|
for (idx = 0; idx < ELM_DAYSELECTOR_MAX; idx++)
|
|
|
|
{
|
|
|
|
it = _item_find(obj, idx);
|
2015-06-17 06:02:48 -07:00
|
|
|
if (!it) continue ;
|
|
|
|
|
2013-07-11 11:34:58 -07:00
|
|
|
weekday = elm_object_text_get(VIEW(it));
|
2014-03-21 07:01:48 -07:00
|
|
|
weekdays = eina_list_append(weekdays, eina_stringshare_add(weekday));
|
2013-07-11 11:34:58 -07:00
|
|
|
}
|
2014-03-21 07:01:48 -07:00
|
|
|
return weekdays;
|
2013-07-11 11:34:58 -07:00
|
|
|
}
|
|
|
|
|
2014-03-21 07:01:48 -07:00
|
|
|
EOLIAN static Eina_Bool
|
|
|
|
_elm_dayselector_elm_widget_focus_direction_manager_is(Eo *obj EINA_UNUSED, Elm_Dayselector_Data *_pd EINA_UNUSED)
|
2012-11-25 22:32:53 -08:00
|
|
|
{
|
2014-03-21 07:01:48 -07:00
|
|
|
return EINA_FALSE;
|
2012-11-25 22:32:53 -08:00
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
2014-03-21 07:01:48 -07:00
|
|
|
_elm_dayselector_class_constructor(Eo_Class *klass)
|
2012-11-25 22:32:53 -08:00
|
|
|
{
|
2013-11-07 03:44:22 -08:00
|
|
|
evas_smart_legacy_type_register(MY_CLASS_NAME_LEGACY, klass);
|
2012-11-25 22:32:53 -08:00
|
|
|
}
|
|
|
|
|
2014-03-21 07:01:48 -07:00
|
|
|
#include "elm_dayselector.eo.c"
|
2014-09-27 22:13:49 -07:00
|
|
|
#include "elm_dayselector_item.eo.c"
|
|
|
|
|