aboutsummaryrefslogtreecommitdiffstats
path: root/src/bin/e_widget_slider.c
blob: 58014e33c0cce1638f2f8405489d00051a2405b4 (plain) (blame)
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
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
#include "e.h"

typedef struct _E_Widget_Data E_Widget_Data;
struct _E_Widget_Data
{
   Evas_Object *o_widget, *o_slider;
   double      *dval;
   int         *ival;
};

static void _e_wid_del_hook(Evas_Object *obj);
static void _e_wid_focus_hook(Evas_Object *obj);
static void _e_wid_focus_steal(void *data, Evas *e, Evas_Object *obj, void *event_info);
static void _e_wid_cb_changed(void *data, Evas_Object *obj, void *event_info);
static void _e_wid_disable_hook(Evas_Object *obj);

/* externally accessible functions */
E_API Evas_Object *
e_widget_slider_add(Evas *evas, int horiz, int rev, const char *fmt, double min, double max, double step, int count, double *dval, int *ival, Evas_Coord size)
{
   Evas_Object *obj, *o;
   E_Widget_Data *wd;
   Evas_Coord mw, mh;

   obj = e_widget_add(evas);

   e_widget_del_hook_set(obj, _e_wid_del_hook);
   e_widget_focus_hook_set(obj, _e_wid_focus_hook);
   e_widget_disable_hook_set(obj, _e_wid_disable_hook);
   wd = calloc(1, sizeof(E_Widget_Data));
   e_widget_data_set(obj, wd);
   wd->o_widget = obj;

   o = e_slider_add(evas);
   wd->o_slider = o;
   evas_object_show(o);
   e_widget_sub_object_add(obj, o);
   e_widget_resize_object_set(obj, o);
   evas_object_event_callback_add(o, EVAS_CALLBACK_MOUSE_DOWN, _e_wid_focus_steal, obj);

   e_slider_orientation_set(o, horiz);
   e_slider_direction_set(o, rev);
   e_slider_value_range_set(o, min, max);
   e_slider_value_format_display_set(o, fmt);
   e_slider_value_step_count_set(o, count);
   e_slider_value_step_size_set(o, step);
   if (dval) e_slider_value_set(o, *dval);
   else if (ival)
     e_slider_value_set(o, *ival);

   e_slider_size_min_get(o, &mw, &mh);
   if (horiz)
     e_widget_size_min_set(obj, mw + size, mh);
   else
     e_widget_size_min_set(obj, mw, mh + size);

   wd->dval = dval;
   wd->ival = ival;
   evas_object_smart_callback_add(o, "changed", _e_wid_cb_changed, wd);

   return obj;
}

/**
 * Set the double value for the slider. This will also move the slider to
 * the correct position and update the text indicator. Will not do anything
 * if the slider was not created with a double value.
 *
 * @param slider pointer to the slider to be modified
 * @param dval the double value to set the slider to
 * @return 1 if value set, return 0 if value not set
 */
E_API int
e_widget_slider_value_double_set(Evas_Object *slider, double dval)
{
   E_Widget_Data *wd;

   wd = e_widget_data_get(slider);
   if (!wd->dval) return 0;
   *(wd->dval) = dval;
   e_slider_value_set(wd->o_slider, dval);
   return 1;
}

/**
 * Set the integer value for the slider. This will also move the slider to
 * the correct position and update the text indicator. Will not do anything
 * if the slider was not created with an integer value.
 *
 * @param slider pointer to the slider to be modified
 * @param ival the integer value to set the slider to
 * @return 1 if value set, return 0 if value not set
 */
E_API int
e_widget_slider_value_int_set(Evas_Object *slider, int ival)
{
   E_Widget_Data *wd;

   wd = e_widget_data_get(slider);
   if (!wd->ival) return 0;
   *(wd->ival) = ival;
   e_slider_value_set(wd->o_slider, ival);
   return 1;
}

/**
 * Get the double value for the slider. The value of dval is undefined
 * if the slider was not created with a double value.
 *
 * @param slider pointer to the slider to be queried
 * @param dval the pointer to the double value to be set with the value of the slider
 * @return 1 if value returned, return 0 if value not returned
 */
E_API int
e_widget_slider_value_double_get(Evas_Object *slider, double *dval)
{
   E_Widget_Data *wd;

   wd = e_widget_data_get(slider);
   if (!wd->dval) return 0;
   if (!dval) return 0;

   *dval = *(wd->dval);
   return 1;
}

/**
 * Get the integer value for the slider. The value of ival is undefined
 * if the slider was not created with an integer value.
 *
 * @param slider pointer to the slider to be queried
 * @param ival the pointer to the integer value to be set with the value of the slider
 * @return 1 if value returned, return 0 if value not returned
 */
E_API int
e_widget_slider_value_int_get(Evas_Object *slider, int *ival)
{
   E_Widget_Data *wd;

   wd = e_widget_data_get(slider);
   if (!wd->ival) return 0;
   if (!ival) return 0;

   *ival = *(wd->ival);
   return 1;
}

E_API void
e_widget_slider_value_format_display_set(Evas_Object *slider, const char *format)
{
   E_Widget_Data *wd;

   wd = e_widget_data_get(slider);
   e_slider_value_format_display_set(wd->o_slider, format);
}

E_API void
e_widget_slider_value_range_set(Evas_Object *slider, double min, double max)
{
   E_Widget_Data *wd;

   wd = e_widget_data_get(slider);
   e_slider_value_range_set(wd->o_slider, min, max);
}

E_API void
e_widget_slider_value_step_size_set(Evas_Object *slider, double step_size)
{
   E_Widget_Data *wd;

   wd = e_widget_data_get(slider);
   e_slider_value_step_size_set(wd->o_slider, step_size);
}

E_API void
e_widget_slider_special_value_add(Evas_Object *obj, double value, double error, const char *label)
{
   E_Widget_Data *wd;

   wd = e_widget_data_get(obj);
   e_slider_special_value_add(wd->o_slider, value, error, label);
}

/* Private functions */
static void
_e_wid_del_hook(Evas_Object *obj)
{
   E_Widget_Data *wd;

   wd = e_widget_data_get(obj);
   free(wd);
}

static void
_e_wid_focus_hook(Evas_Object *obj)
{
   E_Widget_Data *wd;

   wd = e_widget_data_get(obj);
   if (e_widget_focus_get(obj))
     {
        edje_object_signal_emit(e_slider_edje_object_get(wd->o_slider), "e,state,focused", "e");
        evas_object_focus_set(wd->o_slider, 1);
     }
   else
     {
        edje_object_signal_emit(e_slider_edje_object_get(wd->o_slider), "e,state,unfocused", "e");
        evas_object_focus_set(wd->o_slider, 0);
     }
}

static void
_e_wid_focus_steal(void *data, Evas *e EINA_UNUSED, Evas_Object *obj EINA_UNUSED, void *event_info EINA_UNUSED)
{
   e_widget_focus_steal(data);
}

static void
_e_wid_cb_changed(void *data, Evas_Object *obj EINA_UNUSED, void *event_info EINA_UNUSED)
{
   E_Widget_Data *wd;

   wd = data;
   if (wd->dval) *(wd->dval) = e_slider_value_get(wd->o_slider);
   else if (wd->ival)
     *(wd->ival) = e_slider_value_get(wd->o_slider);
   e_widget_change(wd->o_widget);
   evas_object_smart_callback_call(wd->o_widget, "changed", NULL);
}

static void
_e_wid_disable_hook(Evas_Object *obj)
{
   E_Widget_Data *wd;
   Eina_Bool disable;

   wd = e_widget_data_get(obj);
   disable = e_widget_disabled_get(obj);
   e_slider_disabled_set(wd->o_slider, disable);
   if (disable)
     edje_object_signal_emit(e_slider_edje_object_get(wd->o_slider),
                             "e,state,disabled", "e");
   else
     edje_object_signal_emit(e_slider_edje_object_get(wd->o_slider),
                             "e,state,enabled", "e");
}