Calendar - Signal callback and getters.

Most of setters explained on previous examples have associated getters. That's the subject of this example. We'll add a callback to display all calendar information every time user interacts with the calendar.

Let's check our callback function:

static void
_print_cal_info_cb(void *data EINA_UNUSED, Evas_Object *obj,
void *event_info EINA_UNUSED)
{
int year_min, year_max;
Eina_Bool sel_enabled;
const char **wds;
struct tm sel_time;
double interval;
unsigned char Eina_Bool
Type to mimic a boolean.
Definition: eina_types.h:527
#define EINA_UNUSED
Used to indicate that a function parameter is purposely unused.
Definition: eina_types.h:339
Efl_Canvas_Object Evas_Object
An Evas Object handle.
Definition: Evas_Common.h:185

To get selected day, we need to call elm_calendar_selected_time_get(), but to assure nothing wrong happened, we must check for function return. It'll return EINA_FALSE if fail. Otherwise we can use time set to our structure stime.

if (!elm_calendar_selected_time_get(obj, &sel_time))
return;

Next we'll get information from calendar and place on declared vars:

interval = elm_calendar_interval_get(obj);
elm_calendar_min_max_year_get(obj, &year_min, &year_max);
sel_enabled = (elm_calendar_select_mode_get(obj) != ELM_CALENDAR_SELECT_MODE_NONE);
wds = elm_calendar_weekdays_names_get(obj);

The only tricky part is that last line gets an array of strings (char arrays), one for each weekday.

Then we can simple print that to stdin:

printf("Day: %i, Mon: %i, Year %i, WeekDay: %i<br>\n"
"Interval: %0.2f, Year_Min: %i, Year_Max %i, Sel Enabled : %i<br>\n"
"Weekdays: %s, %s, %s, %s, %s, %s, %s<br>\n\n",
sel_time.tm_mday, sel_time.tm_mon, sel_time.tm_year + 1900, sel_time.tm_wday,
interval, year_min, year_max, sel_enabled,
wds[0], wds[1], wds[2], wds[3], wds[4], wds[5], wds[6]);
}

struct tm is declared on time.h. You can check ctime manpage to read about it.

To register this callback, that will be called every time user selects a day or goes to next or previous month, just add a callback for signal changed.

evas_object_smart_callback_add(cal, "changed", _print_cal_info_cb, NULL);
EVAS_API void evas_object_smart_callback_add(Evas_Object *eo_obj, const char *event, Evas_Smart_Cb func, const void *data)
Add (register) a callback function to the smart event specified by event on the smart object obj.
Definition: evas_object_smart.c:1040

Our example will look like this:

See the full source code calendar_example_05.c here.