summaryrefslogtreecommitdiff
path: root/src/modules/elementary/prefs/elm_check.c
blob: 7d1b2cbf66e0df382c4586fef1f69a06418f498f (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
#include "private.h"

static Elm_Prefs_Item_Type supported_types[] =
{
   ELM_PREFS_TYPE_BOOL,
   ELM_PREFS_TYPE_UNKNOWN
};

static Eina_Bool
_item_changed_cb(void *data, const Eo_Event *event)
{
    Elm_Prefs_Item_Changed_Cb prefs_it_changed_cb = data;

    prefs_it_changed_cb(event->object);
    return EINA_TRUE;
}

static Evas_Object *
elm_prefs_check_add(const Elm_Prefs_Item_Iface *iface EINA_UNUSED,
                    Evas_Object *prefs,
                    const Elm_Prefs_Item_Type type EINA_UNUSED,
                    const Elm_Prefs_Item_Spec spec,
                    Elm_Prefs_Item_Changed_Cb cb)
{
   Evas_Object *obj = elm_check_add(prefs);

   eo_event_callback_add
     (obj, EFL_UI_CHECK_EVENT_CHANGED, _item_changed_cb, cb);
   elm_check_state_set(obj, spec.b.def);

   return obj;
}

static Eina_Bool
elm_prefs_check_value_set(Evas_Object *obj,
                          Eina_Value *value)
{
   Eina_Bool val;

   if (eina_value_type_get(value) != EINA_VALUE_TYPE_UCHAR) return EINA_FALSE;

   eina_value_get(value, &val);
   elm_check_state_set(obj, val);

   return EINA_TRUE;
}

static Eina_Bool
elm_prefs_check_value_get(Evas_Object *obj,
                          Eina_Value *value)
{
   Eina_Bool val;

   val = elm_check_state_get(obj);

   if (!eina_value_setup(value, EINA_VALUE_TYPE_UCHAR)) return EINA_FALSE;
   if (!eina_value_set(value, val)) return EINA_FALSE;

   return EINA_TRUE;
}

static Eina_Bool
elm_prefs_check_label_set(Evas_Object *obj,
                          const char *label)
{
   return elm_layout_text_set(obj, NULL, label);
}

static Eina_Bool
elm_prefs_check_icon_set(Evas_Object *obj,
                         const char *icon)
{
   Evas_Object *ic = elm_icon_add(obj);
   Eina_Bool ret;

   if (!elm_icon_standard_set(ic, icon)) goto err;

   elm_image_resizable_set(ic, EINA_FALSE, EINA_FALSE);

   ret = elm_layout_content_set(obj, "icon", ic);
   if (!ret) goto err;

   return ret;

err:
   evas_object_del(ic);
   return EINA_FALSE;
}

PREFS_ITEM_WIDGET_ADD(check,
                      supported_types,
                      elm_prefs_check_value_set,
                      elm_prefs_check_value_get,
                      NULL,
                      elm_prefs_check_label_set,
                      elm_prefs_check_icon_set,
                      NULL,
                      NULL,
                      NULL);