Merge "[Copy&Paste] remove "Paste" button when CBHM has no item"
[framework/uifw/elementary.git] / src / edje_externals / elm_page_control.c
1 #include <assert.h>
2
3 #include "private.h"
4
5 typedef struct _Elm_Params_Icon
6 {
7    Eina_Bool page_count_exists;
8    unsigned int page_count;
9    Eina_Bool page_id_exists;
10    unsigned int page_id;
11 } Elm_Params_Icon;
12
13 static unsigned int page_count_bk;
14
15 static void
16 external_page_control_state_set(void *data __UNUSED__, Evas_Object *obj, const void *from_params, const void *to_params, float pos __UNUSED__)
17 {
18    const Elm_Params_Icon *p;
19
20    if (to_params) p = to_params;
21    else if (from_params) p = from_params;
22    else return;
23
24    if (p->page_count_exists)
25      {
26         elm_page_control_page_count_set(obj, p->page_count);
27         page_count_bk = p->page_count;
28      }
29    if (p->page_id_exists)
30      elm_page_control_page_id_set(obj, p->page_id-1);
31 }
32
33 static Eina_Bool
34 external_page_control_param_set(void *data __UNUSED__, Evas_Object *obj, const Edje_External_Param *param)
35 {
36    if (!strcmp(param->name, "page count")
37                    && param->type == EDJE_EXTERNAL_PARAM_TYPE_INT)
38      {
39         elm_page_control_page_count_set(obj, param->i);
40         page_count_bk = param->i;
41         return EINA_TRUE;
42      }
43    else if (!strcmp(param->name, "page id")
44                    && param->type == EDJE_EXTERNAL_PARAM_TYPE_INT)
45      {
46         elm_page_control_page_id_set(obj, param->i-1);
47         return EINA_TRUE;
48      }
49
50    ERR("unknown parameter '%s' of type '%s'",
51        param->name, edje_external_param_type_str(param->type));
52
53    return EINA_FALSE;
54 }
55
56 static Eina_Bool
57 external_page_control_param_get(void *data __UNUSED__, const Evas_Object *obj, Edje_External_Param *param)
58 {
59    if (!strcmp(param->name, "page count")
60                    && param->type == EDJE_EXTERNAL_PARAM_TYPE_INT)
61      {
62         param->i = page_count_bk;
63         return EINA_TRUE;
64      }
65    else if (!strcmp(param->name, "page id")
66                    && param->type == EDJE_EXTERNAL_PARAM_TYPE_INT)
67      {
68         param->i = elm_page_control_page_id_get((Evas_Object *)obj);
69         return EINA_TRUE;
70      }
71
72    ERR("unknown parameter '%s' of type '%s'",
73                    param->name, edje_external_param_type_str(param->type));
74
75    return EINA_FALSE;
76 }
77
78 static void *
79 external_page_control_params_parse(void *data __UNUSED__, Evas_Object *obj __UNUSED__, const Eina_List *params)
80 {
81    Elm_Params_Icon *mem;
82    Edje_External_Param *param;
83    const Eina_List *l;
84
85    mem = calloc(1, sizeof(Elm_Params_Icon));
86    if (!mem)
87      return NULL;
88
89    EINA_LIST_FOREACH(params, l, param)
90      {
91         if (!strcmp(param->name, "page count"))
92           {
93              mem->page_count = param->i;
94              mem->page_count_exists = EINA_TRUE;
95           }
96         else if (!strcmp(param->name, "page id"))
97           {
98              mem->page_id = param->i;
99              mem->page_id_exists = EINA_TRUE;
100           }
101      }
102
103    return mem;
104 }
105
106 static Evas_Object *external_page_control_content_get(void *data __UNUSED__,
107                                           const Evas_Object *obj __UNUSED__,
108                                           const char *content __UNUSED__)
109 {
110    ERR("so content");
111    return NULL;
112 }
113
114 static void
115 external_page_control_params_free(void *params)
116 {
117    Elm_Params_Icon *mem = params;
118
119    free(mem);
120 }
121
122 static Edje_External_Param_Info external_page_control_params[] = {
123     EDJE_EXTERNAL_PARAM_INFO_INT("page count"),
124     EDJE_EXTERNAL_PARAM_INFO_INT("page id"),
125     EDJE_EXTERNAL_PARAM_INFO_SENTINEL
126 };
127
128 DEFINE_EXTERNAL_ICON_ADD(page_control, "page_control");
129 DEFINE_EXTERNAL_TYPE_SIMPLE(page_control, "Page_control");
130