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