Elementary migration revision 69448
[framework/uifw/elementary.git] / src / lib / elm_calendar.h
1 /**
2  * @defgroup Calendar Calendar
3  *
4  * This is a Calendar widget. Calender widget helps applications to flexibly
5  * display a calender with day of the week, day, year and month. Applications will be
6  * able to choose a specific date that will be reported in the smart_callbacks for
7  * the calendar widget. The APIs of calendar widget let the applications perform 
8  * other functions like,
9  * placing marks on specific dates
10  * Setting the bounds for the calendar (minimum and maximum years)
11  * Setting the day names of the week. ( for ex. Thu. or Thursday)
12  * Setting the year and month format.
13  *
14  * Signals that you can add callbacks for are:
15  * - @c "changed" - emitted when the date in the calendar is changed.
16  *
17  * Supported elm_object common APIs.
18  * @li elm_object_signal_emit
19  * @li elm_object_signal_callback_add
20  * @li elm_object_signal_callback_del
21  *
22  */
23
24 /**
25  * @addtogroup Calendar
26  * @{
27  */
28
29 typedef enum
30 {
31    ELM_CALENDAR_UNIQUE, /**< Default value. Marks will be displayed only on event day. */
32    ELM_CALENDAR_DAILY, /**< Marks will be displayed every day after event day (inclusive). */
33    ELM_CALENDAR_WEEKLY, /**< Marks will be displayed every week after event day (inclusive) - i.e. each seven days. */
34    ELM_CALENDAR_MONTHLY, /**< Marks will be displayed every month day that coincides to event day. E.g.: if an event is set to 30th Jan, no marks will be displayed on Feb, but will be displayed on 30th Mar*/
35    ELM_CALENDAR_ANNUALLY /**< Marks will be displayed every year that coincides to event day (and month). E.g. an event added to 30th Jan 2012 will be repeated on 30th Jan 2013. */
36 } _Elm_Calendar_Mark_Repeat_Type;
37
38 /**
39  * @enum _Elm_Calendar_Mark_Repeat_Type
40  * @typedef Elm_Calendar_Mark_Repeat_Type
41  *
42  * Event periodicity, used to define if a mark should be repeated
43  * @b beyond event's day. It's set when a mark is added.
44  *
45  * So, for a mark added to 13th May with periodicity set to WEEKLY,
46  * there will be marks every week after this date. Marks will be displayed
47  * at 13th, 20th, 27th, 3rd June ...
48  *
49  * Values don't work as bitmask, only one can be chosen.
50  *
51  * @see elm_calendar_mark_add()
52  *
53  * @ingroup Calendar
54  */
55 typedef _Elm_Calendar_Mark_Repeat_Type Elm_Calendar_Mark_Repeat_Type;
56
57 typedef struct _Elm_Calendar_Mark Elm_Calendar_Mark;    /**< Item handle for a calendar mark. Created with elm_calendar_mark_add() and deleted with elm_calendar_mark_del(). */
58
59 /**
60  * @typedef Elm_Calendar_Format_Cb
61  *
62  * This callback type is used to format the string that will be used
63  * to display month and year.
64  *
65  * @param stime Struct representing time.
66  * @return String representing time that will be set to calendar's text.
67  *
68  * @see elm_calendar_format_function_set()
69  */
70 typedef char * (*Elm_Calendar_Format_Cb)(struct tm *stime);
71
72 /**
73  * Add a new calendar widget to the given parent Elementary
74  * (container) object.
75  *
76  * @param parent The parent object.
77  * @return a new calendar widget handle or @c NULL, on errors.
78  *
79  * This function inserts a new calendar widget on the canvas.
80  *
81  * @ref calendar_example_01
82  *
83  * @ingroup Calendar
84  */
85 EAPI Evas_Object         *elm_calendar_add(Evas_Object *parent);
86
87 /**
88  * Get weekdays names displayed by the calendar.
89  *
90  * @param obj The calendar object.
91  * @return Array of seven strings to be used as weekday names.
92  *
93  * By default, weekdays abbreviations get from system are displayed:
94  * E.g. for an en_US locale: "Sun, Mon, Tue, Wed, Thu, Fri, Sat"
95  * The first string is related to Sunday, the second to Monday...
96  *
97  * @see elm_calendar_weekdays_name_set()
98  *
99  * @ref calendar_example_05
100  *
101  * @ingroup Calendar
102  */
103 EAPI const char         **elm_calendar_weekdays_names_get(const Evas_Object *obj);
104
105 /**
106  * Set weekdays names to be displayed by the calendar.
107  *
108  * @param obj The calendar object.
109  * @param weekdays Array of seven strings to be used as weekday names.
110  * @warning It must have 7 elements, or it will access invalid memory.
111  * @warning The strings must be NULL terminated ('@\0').
112  *
113  * By default, weekdays abbreviations get from system are displayed:
114  * E.g. for an en_US locale: "Sun, Mon, Tue, Wed, Thu, Fri, Sat"
115  *
116  * The first string should be related to Sunday, the second to Monday...
117  *
118  * The usage should be like this:
119  * @code
120  *   const char *weekdays[] =
121  *   {
122  *      "Sunday", "Monday", "Tuesday", "Wednesday",
123  *      "Thursday", "Friday", "Saturday"
124  *   };
125  *   elm_calendar_weekdays_names_set(calendar, weekdays);
126  * @endcode
127  *
128  * @see elm_calendar_weekdays_name_get()
129  *
130  * @ref calendar_example_02
131  *
132  * @ingroup Calendar
133  */
134 EAPI void                 elm_calendar_weekdays_names_set(Evas_Object *obj, const char *weekdays[]);
135
136 /**
137  * Set the minimum and maximum values for the year
138  *
139  * @param obj The calendar object
140  * @param min The minimum year, greater than 1901;
141  * @param max The maximum year;
142  *
143  * Maximum must be greater than minimum, except if you don't want to set
144  * maximum year.
145  * Default values are 1902 and -1.
146  *
147  * If the maximum year is a negative value, it will be limited depending
148  * on the platform architecture (year 2037 for 32 bits);
149  *
150  * @see elm_calendar_min_max_year_get()
151  *
152  * @ref calendar_example_03
153  *
154  * @ingroup Calendar
155  */
156 EAPI void                 elm_calendar_min_max_year_set(Evas_Object *obj, int min, int max);
157
158 /**
159  * Get the minimum and maximum values for the year
160  *
161  * @param obj The calendar object.
162  * @param min The minimum year.
163  * @param max The maximum year.
164  *
165  * Default values are 1902 and -1.
166  *
167  * @see elm_calendar_min_max_year_get() for more details.
168  *
169  * @ref calendar_example_05
170  *
171  * @ingroup Calendar
172  */
173 EAPI void                 elm_calendar_min_max_year_get(const Evas_Object *obj, int *min, int *max);
174
175 /**
176  * Enable or disable day selection
177  *
178  * @param obj The calendar object.
179  * @param disabled @c EINA_TRUE to disable selection or @c EINA_FALSE to
180  * enable it.
181  *
182  * Enabled by default. If disabled, the user still can select months,
183  * but not days. Selected days are highlighted on calendar.
184  * It should be used if you won't need such selection for the widget usage.
185  *
186  * When a day is selected, or month is changed, smart callbacks for
187  * signal "changed" will be called.
188  *
189  * @see elm_calendar_day_selection_disabled_get()
190  *
191  * @ref calendar_example_04
192  *
193  * @ingroup Calendar
194  */
195 EAPI void                 elm_calendar_day_selection_disabled_set(Evas_Object *obj, Eina_Bool disabled);
196
197 /**
198  * Get a value whether day selection is disabled or not.
199  *
200  * @param obj The calendar object.
201  * @return EINA_TRUE means day selection is disabled. EINA_FALSE indicates
202  * it's enabled. If @p obj is NULL, EINA_FALSE is returned.
203  *
204  * @see elm_calendar_day_selection_disabled_set() for details.
205  *
206  * @ref calendar_example_05
207  *
208  * @ingroup Calendar
209  */
210 EAPI Eina_Bool            elm_calendar_day_selection_disabled_get(const Evas_Object *obj);
211
212 /**
213  * Set selected date to be highlighted on calendar.
214  *
215  * @param obj The calendar object.
216  * @param selected_time A @b tm struct to represent the selected date.
217  *
218  * Set the selected date, changing the displayed month if needed.
219  * Selected date changes when the user goes to next/previous month or
220  * select a day pressing over it on calendar.
221  *
222  * @see elm_calendar_selected_time_get()
223  *
224  * @ref calendar_example_04
225  *
226  * @ingroup Calendar
227  */
228 EAPI void                 elm_calendar_selected_time_set(Evas_Object *obj, struct tm *selected_time);
229
230 /**
231  * Get selected date.
232  *
233  * @param obj The calendar object
234  * @param selected_time A @b tm struct to point to selected date
235  * @return EINA_FALSE means an error occurred and returned time shouldn't
236  * be considered.
237  *
238  * Get date selected by the user or set by function
239  * elm_calendar_selected_time_set().
240  * Selected date changes when the user goes to next/previous month or
241  * select a day pressing over it on calendar.
242  *
243  * @see elm_calendar_selected_time_get()
244  *
245  * @ref calendar_example_05
246  *
247  * @ingroup Calendar
248  */
249 EAPI Eina_Bool            elm_calendar_selected_time_get(const Evas_Object *obj, struct tm *selected_time);
250
251 /**
252  * Set a function to format the string that will be used to display
253  * month and year;
254  *
255  * @param obj The calendar object
256  * @param format_func Function to set the month-year string given
257  * the selected date
258  *
259  * By default it uses strftime with "%B %Y" format string.
260  * It should allocate the memory that will be used by the string,
261  * that will be freed by the widget after usage.
262  * A pointer to the string and a pointer to the time struct will be provided.
263  *
264  * Example:
265  * @code
266  * static char *
267  * _format_month_year(struct tm *selected_time)
268  * {
269  *    char buf[32];
270  *    if (!strftime(buf, sizeof(buf), "%B %Y", selected_time)) return NULL;
271  *    return strdup(buf);
272  * }
273  *
274  * elm_calendar_format_function_set(calendar, _format_month_year);
275  * @endcode
276  *
277  * @ref calendar_example_02
278  *
279  * @ingroup Calendar
280  */
281 EAPI void                 elm_calendar_format_function_set(Evas_Object *obj, Elm_Calendar_Format_Cb format_func);
282
283 /**
284  * Add a new mark to the calendar
285  *
286  * @param obj The calendar object
287  * @param mark_type A string used to define the type of mark. It will be
288  * emitted to the theme, that should display a related modification on these
289  * days representation.
290  * @param mark_time A time struct to represent the date of inclusion of the
291  * mark. For marks that repeats it will just be displayed after the inclusion
292  * date in the calendar.
293  * @param repeat Repeat the event following this periodicity. Can be a unique
294  * mark (that don't repeat), daily, weekly, monthly or annually.
295  * @return The created mark or @p NULL upon failure.
296  *
297  * Add a mark that will be drawn in the calendar respecting the insertion
298  * time and periodicity. It will emit the type as signal to the widget theme.
299  * Default theme supports "holiday" and "checked", but it can be extended.
300  *
301  * It won't immediately update the calendar, drawing the marks.
302  * For this, call elm_calendar_marks_draw(). However, when user selects
303  * next or previous month calendar forces marks drawn.
304  *
305  * Marks created with this method can be deleted with
306  * elm_calendar_mark_del().
307  *
308  * Example
309  * @code
310  * struct tm selected_time;
311  * time_t current_time;
312  *
313  * current_time = time(NULL) + 5 * 84600;
314  * localtime_r(&current_time, &selected_time);
315  * elm_calendar_mark_add(cal, "holiday", selected_time,
316  *     ELM_CALENDAR_ANNUALLY);
317  *
318  * current_time = time(NULL) + 1 * 84600;
319  * localtime_r(&current_time, &selected_time);
320  * elm_calendar_mark_add(cal, "checked", selected_time, ELM_CALENDAR_UNIQUE);
321  *
322  * elm_calendar_marks_draw(cal);
323  * @endcode
324  *
325  * @see elm_calendar_marks_draw()
326  * @see elm_calendar_mark_del()
327  *
328  * @ref calendar_example_06
329  *
330  * @ingroup Calendar
331  */
332 EAPI Elm_Calendar_Mark   *elm_calendar_mark_add(Evas_Object *obj, const char *mark_type, struct tm *mark_time, Elm_Calendar_Mark_Repeat_Type repeat);
333
334 /**
335  * Delete mark from the calendar.
336  *
337  * @param mark The mark to be deleted.
338  *
339  * If deleting all calendar marks is required, elm_calendar_marks_clear()
340  * should be used instead of getting marks list and deleting each one.
341  *
342  * @see elm_calendar_mark_add()
343  *
344  * @ref calendar_example_06
345  *
346  * @ingroup Calendar
347  */
348 EAPI void                 elm_calendar_mark_del(Elm_Calendar_Mark *mark);
349
350 /**
351  * Remove all calendar's marks
352  *
353  * @param obj The calendar object.
354  *
355  * @see elm_calendar_mark_add()
356  * @see elm_calendar_mark_del()
357  *
358  * @ingroup Calendar
359  */
360 EAPI void                 elm_calendar_marks_clear(Evas_Object *obj);
361
362 /**
363  * Get a list of all the calendar marks.
364  *
365  * @param obj The calendar object.
366  * @return An @c Eina_List of calendar marks objects, or @c NULL on failure.
367  *
368  * @see elm_calendar_mark_add()
369  * @see elm_calendar_mark_del()
370  * @see elm_calendar_marks_clear()
371  *
372  * @ingroup Calendar
373  */
374 EAPI const Eina_List     *elm_calendar_marks_get(const Evas_Object *obj);
375
376 /**
377  * Draw calendar marks.
378  *
379  * @param obj The calendar object.
380  *
381  * Should be used after adding, removing or clearing marks.
382  * It will go through the entire marks list updating the calendar.
383  * If lots of marks will be added, add all the marks and then call
384  * this function.
385  *
386  * When the month is changed, i.e. user selects next or previous month,
387  * marks will be drawn.
388  *
389  * @see elm_calendar_mark_add()
390  * @see elm_calendar_mark_del()
391  * @see elm_calendar_marks_clear()
392  *
393  * @ref calendar_example_06
394  *
395  * @ingroup Calendar
396  */
397 EAPI void                 elm_calendar_marks_draw(Evas_Object *obj);
398
399 /**
400  * Set the interval on time updates for an user mouse button hold
401  * on calendar widgets' month selection.
402  *
403  * @param obj The calendar object
404  * @param interval The (first) interval value in seconds
405  *
406  * This interval value is @b decreased while the user holds the
407  * mouse pointer either selecting next or previous month.
408  *
409  * This helps the user to get to a given month distant from the
410  * current one easier/faster, as it will start to change quicker and
411  * quicker on mouse button holds.
412  *
413  * The calculation for the next change interval value, starting from
414  * the one set with this call, is the previous interval divided by
415  * 1.05, so it decreases a little bit.
416  *
417  * The default starting interval value for automatic changes is
418  * @b 0.85 seconds.
419  *
420  * @see elm_calendar_interval_get()
421  *
422  * @ingroup Calendar
423  */
424 EAPI void                 elm_calendar_interval_set(Evas_Object *obj, double interval);
425
426 /**
427  * Get the interval on time updates for an user mouse button hold
428  * on calendar widgets' month selection.
429  *
430  * @param obj The calendar object
431  * @return The (first) interval value, in seconds, set on it
432  *
433  * @see elm_calendar_interval_set() for more details
434  *
435  * @ingroup Calendar
436  */
437 EAPI double               elm_calendar_interval_get(const Evas_Object *obj);
438
439 /**
440  * @}
441  */