[Refactoring] Removed calendar/colorpalette/datefield/icon/multibuttonentry/pager...
[framework/uifw/elementary.git] / src / edje_externals / elm_calendar.c
1 #include "private.h"
2
3 typedef struct _Elm_Params_Calendar
4 {
5    Elm_Params base;
6    int year_min;
7    int year_max;
8    Eina_Bool sel_enable;
9    Eina_Bool sel_exists:1;
10    int weekday_color;
11    int saturday_color;
12    int sunday_color;
13 } Elm_Params_Calendar;
14
15 static void
16 external_calendar_state_set(void *data __UNUSED__, Evas_Object *obj, const void *from_params, const void *to_params, float pos __UNUSED__)
17 {
18    const Elm_Params_Calendar *p;
19    int min,max;
20
21    if (to_params) p = to_params;
22    else if (from_params) p = from_params;
23    else return;
24
25    if (p->year_min)
26     {
27       elm_calendar_min_max_year_get(obj, NULL, &max);
28       elm_calendar_min_max_year_set(obj, p->year_min, max);
29     }
30    if (p->year_max)
31     {
32       elm_calendar_min_max_year_get(obj, &min, NULL);
33       elm_calendar_min_max_year_set(obj, min, p->year_max);
34     }
35    if (p->sel_exists)
36       elm_calendar_day_selection_enabled_set(obj, p->sel_enable);
37    if (p->weekday_color)
38       elm_calendar_text_weekday_color_set(obj,p->weekday_color);
39    if (p->saturday_color)
40       elm_calendar_text_weekday_color_set(obj,p->saturday_color);
41    if (p->sunday_color)
42       elm_calendar_text_weekday_color_set(obj,p->sunday_color);
43 }
44
45 static Eina_Bool
46 external_calendar_param_set(void *data __UNUSED__, Evas_Object *obj, const Edje_External_Param *param)
47 {
48    int min,max;
49
50    if (!strcmp(param->name, "year_min"))
51      {
52         if (param->type == EDJE_EXTERNAL_PARAM_TYPE_INT)
53           {
54              elm_calendar_min_max_year_get(obj, NULL, &max);
55              elm_calendar_min_max_year_set(obj, param->i, max);
56              return EINA_TRUE;
57           }
58      }
59    else if (!strcmp(param->name, "year_max"))
60      {
61         if (param->type == EDJE_EXTERNAL_PARAM_TYPE_INT)
62           {
63              elm_calendar_min_max_year_get(obj, &min, NULL);
64              elm_calendar_min_max_year_set(obj, min,param->i);
65              return EINA_TRUE;
66           }
67      }
68    else if (!strcmp(param->name, "sel_enable"))
69      {
70         if (param->type == EDJE_EXTERNAL_PARAM_TYPE_BOOL)
71           {
72              elm_calendar_day_selection_enabled_set(obj,param->i );
73              return EINA_TRUE;
74           }
75      }
76    else if (!strcmp(param->name, "weekday_color"))
77      {
78         if (param->type == EDJE_EXTERNAL_PARAM_TYPE_INT)
79           {
80              elm_calendar_text_weekday_color_set(obj,param->i);
81              return EINA_TRUE;
82           }
83      }
84    else if (!strcmp(param->name, "saturday_color"))
85      {
86         if (param->type == EDJE_EXTERNAL_PARAM_TYPE_INT)
87           {
88              elm_calendar_text_saturday_color_set(obj,param->i);
89              return EINA_TRUE;
90           }
91      }
92    else if (!strcmp(param->name, "sunday_color"))
93      {
94         if (param->type == EDJE_EXTERNAL_PARAM_TYPE_INT)
95           {
96              elm_calendar_text_sunday_color_set(obj,param->i);
97              return EINA_TRUE;
98           }
99      }
100
101    ERR("unknown parameter '%s' of type '%s'",
102        param->name, edje_external_param_type_str(param->type));
103
104    return EINA_FALSE;
105 }
106
107 static Eina_Bool
108 external_calendar_param_get(void *data __UNUSED__, const Evas_Object *obj, Edje_External_Param *param)
109 {
110    int min,max;
111
112    if (!strcmp(param->name, "year_min"))
113      {
114         if (param->type == EDJE_EXTERNAL_PARAM_TYPE_INT)
115           {
116               elm_calendar_min_max_year_get(obj, &(param->i) ,&max);
117              return EINA_TRUE;
118           }
119      }
120    else if (!strcmp(param->name, "year_max"))
121      {
122         if (param->type == EDJE_EXTERNAL_PARAM_TYPE_INT)
123           {
124               elm_calendar_min_max_year_get(obj, &min,&(param->i));
125              return EINA_TRUE;
126           }
127      }
128    else if (!strcmp(param->name, "sel_enable"))
129      {
130         if (param->type == EDJE_EXTERNAL_PARAM_TYPE_BOOL)
131           {
132              param->i = elm_calendar_day_selection_enabled_get(obj);
133              return EINA_TRUE;
134           }
135      }
136    else if (!strcmp(param->name, "weekday_color"))
137      {
138         if (param->type == EDJE_EXTERNAL_PARAM_TYPE_INT)
139           {
140               //there is no API available to get the dates with normal weekday color
141              return EINA_FALSE;
142           }
143      }
144    else if (!strcmp(param->name, "saturday_color"))
145      {
146         if (param->type == EDJE_EXTERNAL_PARAM_TYPE_INT)
147           {
148              // there is no API available to get the dates with saturday color
149              return EINA_FALSE;
150           }
151      }
152    else if (!strcmp(param->name, "sunday_color"))
153      {
154         if (param->type == EDJE_EXTERNAL_PARAM_TYPE_INT)
155           {
156              // there is no API available to get the dates with sunday color
157              return EINA_FALSE;
158           }
159      }
160
161    ERR("unknown parameter '%s' of type '%s'",
162        param->name, edje_external_param_type_str(param->type));
163
164    return EINA_FALSE;
165 }
166
167 static void *
168 external_calendar_params_parse(void *data __UNUSED__, Evas_Object *obj __UNUSED__, const Eina_List *params)
169 {
170    Elm_Params_Calendar *mem;
171    Edje_External_Param *param;
172    const Eina_List *l;
173
174    mem = calloc(1, sizeof(Elm_Params_Calendar));
175    if (!mem)
176      return NULL;
177
178    EINA_LIST_FOREACH(params, l, param)
179      {
180         if (!strcmp(param->name, "year_min"))
181            mem->year_min = param->i;
182
183         else if(!strcmp(param->name, "year_max"))
184            mem->year_max = param->i;
185
186         else if (!strcmp(param->name, "sel_enable"))
187           {
188            mem->sel_enable = param->i;
189            mem->sel_exists = EINA_TRUE;
190           }
191
192         else if (!strcmp(param->name, "weekday_color"))
193            mem->weekday_color = param->i;
194
195         else if (!strcmp(param->name, "saturday_color"))
196            mem->saturday_color = param->i;
197
198         else if (!strcmp(param->name, "sunday_color"))
199            mem->sunday_color = param->i;
200      }
201
202    return mem;
203 }
204
205 static Evas_Object *external_calendar_content_get(void *data __UNUSED__,
206                 const Evas_Object *obj __UNUSED__, const char *content __UNUSED__)
207 {
208         ERR("No content.");
209         return NULL;
210 }
211
212 static void
213 external_calendar_params_free(void *params)
214 {
215    free(params);
216 }
217
218 static Edje_External_Param_Info external_calendar_params[] = {
219    DEFINE_EXTERNAL_COMMON_PARAMS,
220    EDJE_EXTERNAL_PARAM_INFO_INT("year_min"),
221    EDJE_EXTERNAL_PARAM_INFO_INT("year_max"),
222    EDJE_EXTERNAL_PARAM_INFO_BOOL("sel_enable"),
223    EDJE_EXTERNAL_PARAM_INFO_INT("weekday_color"),
224    EDJE_EXTERNAL_PARAM_INFO_INT("saturday_color"),
225    EDJE_EXTERNAL_PARAM_INFO_INT("sunday_color"),
226    EDJE_EXTERNAL_PARAM_INFO_SENTINEL
227 };
228
229 DEFINE_EXTERNAL_ICON_ADD(calendar, "calendar");
230 DEFINE_EXTERNAL_TYPE_SIMPLE(calendar, "Calendar");