fixed plugin image size problem
[framework/uifw/elementary.git] / src / edje_externals / elm_calendar.c
1 #include <assert.h>
2
3 #include "private.h"
4
5 typedef struct _Elm_Params_Calendar
6 {
7    Elm_Params base;
8    int year_min;
9    int year_max;
10    const char *select_mode;
11
12 } Elm_Params_Calendar;
13
14 #define SELECT_MODE_GET(CHOICES, STR)                                \
15    unsigned int i;                                              \
16    for (i = 0; i < (sizeof(CHOICES) / sizeof(CHOICES[0])); ++i) \
17      if (!strcmp(STR, CHOICES[i]))                              \
18        return i;
19
20
21 static const char *_calendar_select_modes[] = {"default", "always", "none",
22                                                "ondemand", NULL};
23
24 static Elm_Calendar_Select_Mode
25 _calendar_select_mode_get(const char *select_mode)
26 {
27    assert(sizeof(_calendar_select_modes) /
28           sizeof(_calendar_select_modes[0])
29           == ELM_CALENDAR_SELECT_MODE_ONDEMAND + 2);
30    SELECT_MODE_GET(_calendar_select_modes, select_mode);
31    return -1;
32 }
33
34 static void
35 external_calendar_state_set(void *data __UNUSED__, Evas_Object *obj,
36                             const void *from_params, const void *to_params,
37                             float pos __UNUSED__)
38 {
39    const Elm_Params_Calendar *p;
40    Elm_Calendar_Select_Mode select_mode;
41    int min,max;
42
43    if (to_params) p = to_params;
44    else if (from_params) p = from_params;
45    else return;
46
47    if (p->year_min)
48      {
49         elm_calendar_min_max_year_get(obj, NULL, &max);
50         elm_calendar_min_max_year_set(obj, p->year_min, max);
51      }
52    if (p->year_max)
53      {
54         elm_calendar_min_max_year_get(obj, &min, NULL);
55         elm_calendar_min_max_year_set(obj, min, p->year_max);
56      }
57    if (p->select_mode)
58      {
59         select_mode = _calendar_select_mode_get(p->select_mode);
60         elm_calendar_select_mode_set(obj, select_mode);
61      }
62 }
63
64 static Eina_Bool
65 external_calendar_param_set(void *data __UNUSED__, Evas_Object *obj,
66                             const Edje_External_Param *param)
67 {
68    int min,max;
69
70    if (!strcmp(param->name, "year_min"))
71      {
72         if (param->type == EDJE_EXTERNAL_PARAM_TYPE_INT)
73           {
74              elm_calendar_min_max_year_get(obj, NULL, &max);
75              elm_calendar_min_max_year_set(obj, param->i, max);
76              return EINA_TRUE;
77           }
78      }
79    else if (!strcmp(param->name, "year_max"))
80      {
81         if (param->type == EDJE_EXTERNAL_PARAM_TYPE_INT)
82           {
83              elm_calendar_min_max_year_get(obj, &min, NULL);
84              elm_calendar_min_max_year_set(obj, min,param->i);
85              return EINA_TRUE;
86           }
87      }
88    else if (!strcmp(param->name, "select_mode"))
89      {
90         if (param->type == EDJE_EXTERNAL_PARAM_TYPE_STRING)
91           {
92              Elm_Calendar_Select_Mode select_mode;
93              select_mode = _calendar_select_mode_get(param->s);
94              elm_calendar_select_mode_set(obj, select_mode);
95              return EINA_TRUE;
96           }
97      }
98
99    ERR("unknown parameter '%s' of type '%s'",
100        param->name, edje_external_param_type_str(param->type));
101
102    return EINA_FALSE;
103 }
104
105 static Eina_Bool
106 external_calendar_param_get(void *data __UNUSED__, const Evas_Object *obj,
107                             Edje_External_Param *param)
108 {
109    int min, max;
110
111    if (!strcmp(param->name, "year_min"))
112      {
113         if (param->type == EDJE_EXTERNAL_PARAM_TYPE_INT)
114           {
115              elm_calendar_min_max_year_get(obj, &(param->i) ,&max);
116              return EINA_TRUE;
117           }
118      }
119    else if (!strcmp(param->name, "year_max"))
120      {
121         if (param->type == EDJE_EXTERNAL_PARAM_TYPE_INT)
122           {
123              elm_calendar_min_max_year_get(obj, &min,&(param->i));
124              return EINA_TRUE;
125           }
126      }
127    else if (!strcmp(param->name, "select_mode"))
128      {
129         if (param->type == EDJE_EXTERNAL_PARAM_TYPE_STRING)
130           {
131              Elm_Calendar_Select_Mode mode;
132              mode = elm_calendar_select_mode_get(obj);
133              param->s = _calendar_select_modes[mode];
134              return EINA_TRUE;
135           }
136      }
137
138
139    ERR("unknown parameter '%s' of type '%s'",
140        param->name, edje_external_param_type_str(param->type));
141
142    return EINA_FALSE;
143 }
144
145 static void *
146 external_calendar_params_parse(void *data __UNUSED__,
147                                Evas_Object *obj __UNUSED__,
148                                const Eina_List *params)
149 {
150    Elm_Params_Calendar *mem;
151    Edje_External_Param *param;
152    const Eina_List *l;
153
154    mem = calloc(1, sizeof(Elm_Params_Calendar));
155    if (!mem)
156      return NULL;
157
158    EINA_LIST_FOREACH(params, l, param)
159      {
160         if (!strcmp(param->name, "year_min"))
161           mem->year_min = param->i;
162
163         else if (!strcmp(param->name, "year_max"))
164           mem->year_max = param->i;
165
166         else if (!strcmp(param->name, "select_mode"))
167           mem->select_mode = eina_stringshare_add(param->s);
168      }
169
170    return mem;
171 }
172
173 static Evas_Object *
174 external_calendar_content_get(void *data __UNUSED__,
175                               const Evas_Object *obj __UNUSED__,
176                               const char *content __UNUSED__)
177 {
178    ERR("No content.");
179    return NULL;
180 }
181
182 static void
183 external_calendar_params_free(void *params)
184 {
185    Elm_Params_Calendar *mem = params;
186    if (mem->select_mode)
187      eina_stringshare_del(mem->select_mode);
188    free(params);
189 }
190
191 static Edje_External_Param_Info external_calendar_params[] = {
192    DEFINE_EXTERNAL_COMMON_PARAMS,
193    EDJE_EXTERNAL_PARAM_INFO_INT("year_min"),
194    EDJE_EXTERNAL_PARAM_INFO_INT("year_max"),
195    EDJE_EXTERNAL_PARAM_INFO_STRING("select_mode"),
196    EDJE_EXTERNAL_PARAM_INFO_SENTINEL
197 };
198
199 DEFINE_EXTERNAL_ICON_ADD(calendar, "calendar");
200 DEFINE_EXTERNAL_TYPE_SIMPLE(calendar, "Calendar");