[access] support elm_access_action(); with ELM_ACCESS_ACTION_UNHIGHLIGHT
[framework/uifw/elementary.git] / src / edje_externals / elm_bg.c
1 #include <assert.h>
2 #include "private.h"
3
4 typedef struct _Elm_Params_Bg
5 {
6    Elm_Params base;
7    const char *file;
8    const char *option;
9 } Elm_Params_Bg;
10
11 #define OPTION_GET(CHOICES, STR)                                \
12    unsigned int i;                                              \
13    for (i = 0; i < (sizeof(CHOICES) / sizeof(CHOICES[0])); ++i) \
14      if (!strcmp(STR, CHOICES[i]))                              \
15        return i;
16
17 static const char *_bg_options[] = {"center", "scale", "stretch", "tile", NULL};
18
19 static Elm_Bg_Option
20 _bg_option_get(const char *option)
21 {
22    assert(sizeof(_bg_options) / sizeof(_bg_options[0])
23           == ELM_BG_OPTION_TILE + 2);
24    OPTION_GET(_bg_options, option);
25    return -1;
26 }
27
28 static void
29 external_bg_state_set(void *data __UNUSED__, Evas_Object *obj,
30                       const void *from_params, const void *to_params,
31                       float pos __UNUSED__)
32 {
33    const Elm_Params_Bg *p;
34    Elm_Bg_Option option;
35
36    if (to_params) p = to_params;
37    else if (from_params) p = from_params;
38    else return;
39
40    if (p->option)
41      {
42         option = _bg_option_get(p->option);
43         elm_bg_option_set(obj, option);
44      }
45    if (p->file)
46      {
47         elm_bg_file_set(obj, p->file, NULL);
48      }
49 }
50
51 static Eina_Bool
52 external_bg_param_set(void *data __UNUSED__, Evas_Object *obj,
53                       const Edje_External_Param *param)
54 {
55    if ((!strcmp(param->name, "file"))
56        && (param->type == EDJE_EXTERNAL_PARAM_TYPE_STRING))
57      {
58         return elm_bg_file_set(obj, param->s, NULL);
59      }
60    else if ((!strcmp(param->name, "select_mode"))
61             && (param->type == EDJE_EXTERNAL_PARAM_TYPE_STRING))
62      {
63         Elm_Bg_Option option;
64         option = _bg_option_get(param->s);
65         elm_bg_option_set(obj, option);
66         return EINA_TRUE;
67      }
68
69    ERR("unknown parameter '%s' of type '%s'",
70        param->name, edje_external_param_type_str(param->type));
71
72    return EINA_FALSE;
73 }
74
75 static Eina_Bool
76 external_bg_param_get(void *data __UNUSED__,
77                       const Evas_Object *obj __UNUSED__,
78                       Edje_External_Param *param)
79 {
80    if ((!strcmp(param->name, "file"))
81        && (param->type == EDJE_EXTERNAL_PARAM_TYPE_STRING))
82      {
83         elm_bg_file_get(obj, &(param->s), NULL);
84         return EINA_TRUE;
85      }
86    else if ((!strcmp(param->name, "option"))
87             && (param->type == EDJE_EXTERNAL_PARAM_TYPE_STRING))
88      {
89         Elm_Bg_Option option;
90         option = elm_bg_option_get(obj);
91         param->s = _bg_options[option];
92         return EINA_TRUE;
93      }
94
95    ERR("unknown parameter '%s' of type '%s'",
96        param->name, edje_external_param_type_str(param->type));
97
98    return EINA_FALSE;
99 }
100
101 static void *
102 external_bg_params_parse(void *data __UNUSED__, Evas_Object *obj __UNUSED__,
103                          const Eina_List *params)
104 {
105    Elm_Params_Bg *mem;
106    Edje_External_Param *param;
107    const Eina_List *l;
108
109    mem = calloc(1, sizeof(Elm_Params_Bg));
110    if (!mem)
111      return NULL;
112
113    EINA_LIST_FOREACH(params, l, param)
114      {
115         if (!strcmp(param->name, "file"))
116           mem->file = eina_stringshare_add(param->s);
117         else if (!strcmp(param->name, "option"))
118           mem->option = eina_stringshare_add(param->s);
119      }
120
121    return mem;
122 }
123
124 static Evas_Object *
125 external_bg_content_get(void *data __UNUSED__,
126                         const Evas_Object *obj __UNUSED__,
127                         const char *content __UNUSED__)
128 {
129    ERR("no content");
130    return NULL;
131 }
132
133 static void
134 external_bg_params_free(void *params)
135 {
136    Elm_Params_Bg *mem = params;
137
138    if (mem->file)
139      eina_stringshare_del(mem->file);
140
141    if (mem->option)
142      eina_stringshare_del(mem->option);
143
144    free(mem);
145 }
146
147 static Edje_External_Param_Info external_bg_params[] = {
148    DEFINE_EXTERNAL_COMMON_PARAMS,
149    EDJE_EXTERNAL_PARAM_INFO_STRING("file"),
150    EDJE_EXTERNAL_PARAM_INFO_STRING("option"),
151    EDJE_EXTERNAL_PARAM_INFO_SENTINEL
152 };
153
154 DEFINE_EXTERNAL_ICON_ADD(bg, "bg");
155 DEFINE_EXTERNAL_TYPE_SIMPLE(bg, "Bg");