Ecore_Timer *spin, *update_timer;
Elm_Calendar_Format_Cb format_func;
const char *weekdays[ELM_DAY_LAST];
- struct tm current_time, selected_time;
+ struct tm current_time, selected_time, showed_time;
Day_Color day_color[42]; // EINA_DEPRECATED
Elm_Calendar_Select_Mode select_mode;
+ Eina_Bool selected:1;
};
struct _Elm_Calendar_Mark
_select(Widget_Data *wd, int selected)
{
char emission[32];
+ wd->selected_it = selected;
snprintf(emission, sizeof(emission), "cit_%i,selected", selected);
edje_object_signal_emit(wd->calendar, emission, "elm");
}
char *buf;
/* Set selected month */
- buf = wd->format_func(&wd->selected_time);
+ buf = wd->format_func(&wd->showed_time);
if (buf)
{
edje_object_part_text_escaped_set(wd->calendar, "month_text", buf);
if (wd->today_it > 0) _not_today(wd);
- maxdays = _maxdays_get(&wd->selected_time);
- mon = wd->selected_time.tm_mon;
- yr = wd->selected_time.tm_year;
+ maxdays = _maxdays_get(&wd->showed_time);
+ mon = wd->showed_time.tm_mon;
+ yr = wd->showed_time.tm_year;
_set_month_year(wd);
/* Set days */
day = 0;
- first_day = wd->selected_time;
+ first_day = wd->showed_time;
first_day.tm_mday = 1;
mktime(&first_day);
{
if ((wd->selected_it > -1) && (wd->selected_it != i))
_unselect(wd, wd->selected_it);
-
- if (wd->select_mode != ELM_CALENDAR_SELECT_MODE_NONE)
- _select(wd, i);
-
- wd->selected_it = i;
+ if (wd->select_mode == ELM_CALENDAR_SELECT_MODE_ONDEMAND)
+ {
+ if ((mon == wd->selected_time.tm_mon)
+ && (yr == wd->selected_time.tm_year)
+ && (wd->selected))
+ {
+ _select(wd, i);
+ }
+ }
+ else if (wd->select_mode != ELM_CALENDAR_SELECT_MODE_NONE)
+ {
+ _select(wd, i);
+ }
}
if ((day) && (day <= maxdays))
EINA_LIST_FOREACH(wd->marks, l, mark)
{
struct tm *mtime = &mark->mark_time;
- int month = wd->selected_time.tm_mon;
- int year = wd->selected_time.tm_year;
+ int month = wd->showed_time.tm_mon;
+ int year = wd->showed_time.tm_year;
int mday_it = mtime->tm_mday + wd->first_day_it - 1;
switch (mark->repeat)
static inline void
_fix_selected_time(Widget_Data *wd)
{
+ if (wd->selected_time.tm_mon != wd->showed_time.tm_mon)
+ wd->selected_time.tm_mon = wd->showed_time.tm_mon;
+ if (wd->selected_time.tm_year != wd->showed_time.tm_year)
+ wd->selected_time.tm_year = wd->showed_time.tm_year;
mktime(&wd->selected_time);
}
if (!wd) return EINA_FALSE;
/* check if it's a valid time. for 32 bits, year greater than 2037 is not */
- time_check = wd->selected_time;
+ time_check = wd->showed_time;
time_check.tm_mon += delta;
if (mktime(&time_check) == -1)
return EINA_FALSE;
- wd->selected_time.tm_mon += delta;
- if (wd->selected_time.tm_mon < 0)
+ wd->showed_time.tm_mon += delta;
+ if (wd->showed_time.tm_mon < 0)
{
- if (wd->selected_time.tm_year == wd->year_min)
+ if (wd->showed_time.tm_year == wd->year_min)
{
- wd->selected_time.tm_mon++;
+ wd->showed_time.tm_mon++;
return EINA_FALSE;
}
- wd->selected_time.tm_mon = 11;
- wd->selected_time.tm_year--;
+ wd->showed_time.tm_mon = 11;
+ wd->showed_time.tm_year--;
}
- else if (wd->selected_time.tm_mon > 11)
+ else if (wd->showed_time.tm_mon > 11)
{
- if (wd->selected_time.tm_year == wd->year_max)
+ if (wd->showed_time.tm_year == wd->year_max)
{
- wd->selected_time.tm_mon--;
+ wd->showed_time.tm_mon--;
return EINA_FALSE;
}
- wd->selected_time.tm_mon = 0;
- wd->selected_time.tm_year++;
+ wd->showed_time.tm_mon = 0;
+ wd->showed_time.tm_year++;
}
- maxdays = _maxdays_get(&wd->selected_time);
- if (wd->selected_time.tm_mday > maxdays)
- wd->selected_time.tm_mday = maxdays;
+ if ((wd->select_mode != ELM_CALENDAR_SELECT_MODE_ONDEMAND)
+ && (wd->select_mode != ELM_CALENDAR_SELECT_MODE_NONE))
+ {
+ maxdays = _maxdays_get(&wd->showed_time);
+ if (wd->selected_time.tm_mday > maxdays)
+ wd->selected_time.tm_mday = maxdays;
- _fix_selected_time(wd);
- evas_object_smart_callback_call(obj, SIG_CHANGED, NULL);
+ _fix_selected_time(wd);
+ evas_object_smart_callback_call(obj, SIG_CHANGED, NULL);
+ }
return EINA_TRUE;
}
if (!wd) return 0;
day = selected_it - wd->first_day_it + 1;
- if ((day < 0) || (day > _maxdays_get(&wd->selected_time)))
+ if ((day < 0) || (day > _maxdays_get(&wd->showed_time)))
return 0;
return day;
return;
_unselect(wd, wd->selected_it);
+ if (!wd->selected)
+ wd->selected = EINA_TRUE;
- wd->selected_it = sel_it;
wd->selected_time.tm_mday = day;
- _select(wd, wd->selected_it);
_fix_selected_time(wd);
+ _select(wd, sel_it);
evas_object_smart_callback_call(obj, SIG_CHANGED, NULL);
}
t = _time_to_next_day(&wd->current_time);
ecore_timer_interval_set(wd->update_timer, t);
- if ((wd->current_time.tm_mon != wd->selected_time.tm_mon) ||
- (wd->current_time.tm_year!= wd->selected_time.tm_year))
+ if ((wd->current_time.tm_mon != wd->showed_time.tm_mon) ||
+ (wd->current_time.tm_year!= wd->showed_time.tm_year))
return ECORE_CALLBACK_RENEW;
day = wd->current_time.tm_mday + wd->first_day_it - 1;
if (!wd) return EINA_FALSE;
if (elm_widget_disabled_get(obj)) return EINA_FALSE;
- if (wd->select_mode == ELM_CALENDAR_SELECT_MODE_NONE) return EINA_FALSE;
- if ((!strcmp(ev->keyname, "Left")) ||
- ((!strcmp(ev->keyname, "KP_Left")) && (!ev->string)))
- {
- _update_sel_it(obj, wd->selected_it-1);
- }
- else if ((!strcmp(ev->keyname, "Right")) ||
- ((!strcmp(ev->keyname, "KP_Right")) && (!ev->string)))
- {
- _update_sel_it(obj, wd->selected_it+1);
- }
- else if ((!strcmp(ev->keyname, "Up")) ||
- ((!strcmp(ev->keyname, "KP_Up")) && (!ev->string)))
- {
- _update_sel_it(obj, wd->selected_it-ELM_DAY_LAST);
- }
- else if ((!strcmp(ev->keyname, "Down")) ||
- ((!strcmp(ev->keyname, "KP_Down")) && (!ev->string)))
- {
- _update_sel_it(obj, wd->selected_it+ELM_DAY_LAST);
- }
- else if ((!strcmp(ev->keyname, "Prior")) ||
- ((!strcmp(ev->keyname, "KP_Prior")) && (!ev->string)))
+ if ((!strcmp(ev->keyname, "Prior")) ||
+ ((!strcmp(ev->keyname, "KP_Prior")) && (!ev->string)))
{
if (_update_month(obj, -1)) _populate(obj);
}
{
if (_update_month(obj, 1)) _populate(obj);
}
+
+ else if ((wd->select_mode != ELM_CALENDAR_SELECT_MODE_NONE)
+ && ((wd->select_mode != ELM_CALENDAR_SELECT_MODE_ONDEMAND)
+ || (wd->selected)))
+ {
+ if ((!strcmp(ev->keyname, "Left")) ||
+ ((!strcmp(ev->keyname, "KP_Left")) && (!ev->string)))
+ {
+ if ((wd->select_mode != ELM_CALENDAR_SELECT_MODE_ONDEMAND)
+ || ((wd->showed_time.tm_year == wd->selected_time.tm_year)
+ && (wd->showed_time.tm_mon == wd->selected_time.tm_mon)))
+ _update_sel_it(obj, wd->selected_it-1);
+ }
+ else if ((!strcmp(ev->keyname, "Right")) ||
+ ((!strcmp(ev->keyname, "KP_Right")) && (!ev->string)))
+ {
+ if ((wd->select_mode != ELM_CALENDAR_SELECT_MODE_ONDEMAND)
+ || ((wd->showed_time.tm_year == wd->selected_time.tm_year)
+ && (wd->showed_time.tm_mon == wd->selected_time.tm_mon)))
+ _update_sel_it(obj, wd->selected_it+1);
+ }
+ else if ((!strcmp(ev->keyname, "Up")) ||
+ ((!strcmp(ev->keyname, "KP_Up")) && (!ev->string)))
+ {
+ if ((wd->select_mode != ELM_CALENDAR_SELECT_MODE_ONDEMAND)
+ || ((wd->showed_time.tm_year == wd->selected_time.tm_year)
+ && (wd->showed_time.tm_mon == wd->selected_time.tm_mon)))
+ _update_sel_it(obj, wd->selected_it-ELM_DAY_LAST);
+ }
+ else if ((!strcmp(ev->keyname, "Down")) ||
+ ((!strcmp(ev->keyname, "KP_Down")) && (!ev->string)))
+ {
+ if ((wd->select_mode != ELM_CALENDAR_SELECT_MODE_ONDEMAND)
+ || ((wd->showed_time.tm_year == wd->selected_time.tm_year)
+ && (wd->showed_time.tm_mon == wd->selected_time.tm_mon)))
+ _update_sel_it(obj, wd->selected_it+ELM_DAY_LAST);
+ }
+ else return EINA_FALSE;
+ }
else return EINA_FALSE;
return EINA_TRUE;
}
current_time = time(NULL);
- localtime_r(¤t_time, &wd->selected_time);
- wd->current_time = wd->selected_time;
+ localtime_r(¤t_time, &wd->showed_time);
+ wd->current_time = wd->showed_time;
+ wd->selected_time = wd->showed_time;
t = _time_to_next_day(&wd->current_time);
wd->update_timer = ecore_timer_add(t, _update_cur_date, obj);
wd->year_max = max;
else
wd->year_max = wd->year_min;
- if (wd->selected_time.tm_year > wd->year_max)
- wd->selected_time.tm_year = wd->year_max;
- if (wd->selected_time.tm_year < wd->year_min)
- wd->selected_time.tm_year = wd->year_min;
- _fix_selected_time(wd);
+ if (wd->showed_time.tm_year > wd->year_max)
+ wd->showed_time.tm_year = wd->year_max;
+ if (wd->showed_time.tm_year < wd->year_min)
+ wd->showed_time.tm_year = wd->year_min;
_populate(obj);
}
EINA_SAFETY_ON_NULL_RETURN(selected_time);
wd->selected_time = *selected_time;
+ _fix_selected_time(wd);
_populate(obj);
return;
}
&& (wd->select_mode != mode))
{
wd->select_mode = mode;
- if (wd->select_mode == ELM_CALENDAR_SELECT_MODE_ALWAYS)
+ if (wd->select_mode == ELM_CALENDAR_SELECT_MODE_ONDEMAND)
+ wd->selected = EINA_FALSE;
+ if ((wd->select_mode == ELM_CALENDAR_SELECT_MODE_ALWAYS)
+ || (wd->select_mode == ELM_CALENDAR_SELECT_MODE_DEFAULT))
_select(wd, wd->selected_it);
else
_unselect(wd, wd->selected_it);