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
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
|
/*
* setting
*
* Copyright (c) 2000 - 2011 Samsung Electronics Co., Ltd.
*
* Contact: MyoungJune Park <mj2004.park@samsung.com>
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*
*/
#include "setting-common-draw-widget.h"
#include <efl_extension.h>
/**
* Hide the input panel
*
* @param[in] entry
*/
EXPORT_PUBLIC
void setting_hide_input_panel_cb(Evas_Object *entry)
{
ret_if(entry == NULL);
Ecore_IMF_Context *imf_context =
(Ecore_IMF_Context *)elm_entry_imf_context_get(entry);
if (imf_context)
ecore_imf_context_input_panel_hide(imf_context);
elm_object_focus_set(entry, EINA_FALSE);
Evas_Object *entry_container = elm_object_parent_widget_get(entry);
if (entry_container) {
if (elm_entry_is_empty(entry))
elm_object_signal_emit(entry_container,
"elm,state,guidetext,show", "elm");
elm_object_signal_emit(entry_container,
"elm,state,eraser,hide", "elm");
}
}
EXPORT_PUBLIC
Evas_Object *setting_create_button(
Evas_Object *parent,
const char *btn_str,
const char *btn_style,
Evas_Smart_Cb btn_click_cb,
void *cb_data)
{
retv_if(!parent, NULL);
Evas_Object *button = elm_button_add(parent);
retv_if(!button, NULL);
if (btn_style)
elm_object_style_set(button, btn_style);
/* not '<-' button */
if (0 != safeStrCmp("naviframe/end_btn/default", btn_style)) {
elm_object_text_set(button, _(btn_str));
evas_object_size_hint_weight_set(
button, EVAS_HINT_EXPAND, EVAS_HINT_EXPAND);
evas_object_size_hint_align_set(button, EVAS_HINT_FILL, 0.5);
}
if (btn_click_cb) {
evas_object_smart_callback_add(
button, "clicked", btn_click_cb, cb_data);
}
evas_object_show(button);
LAUNCH_SETTING_OUT();
return button;
}
EXPORT_PUBLIC
Evas_Object *setting_create_button_with_translatable_text(
Evas_Object *parent,
const char *btn_str_key,
const char *btn_style,
Evas_Smart_Cb btn_click_cb,
void *cb_data)
{
Evas_Object *button = setting_create_button(parent, "", btn_style, btn_click_cb, cb_data);
elm_object_translatable_text_set(button, btn_str_key);
return button;
}
static double _step_size_calculate(Evas_Object *obj, double min, double max)
{
double step = 0.0;
int steps = 0;
steps = max - min;
if (steps)
step = (1.0 / steps);
return step;
}
/**
* To create slider object of a genlist item
*
*@return a slider container object
*/
EXPORT_PUBLIC Evas_Object *setting_create_5step_slider(
Evas_Object *parent,
Evas *evas,
const char *l_swallow_path,
const char *r_swallow_path,
double value,
bool indicator,
double slider_min,
double slider_max,
setting_call_back_func slider_change_cb,
setting_call_back_func slider_start_change_cb,
setting_call_back_func slider_stop_change_cb,
void *cb_data)
{
char path_str[PATH_MAX] = {'\0',};
Evas_Object *layout = elm_layout_add(parent);
char *app_res_path = app_get_resource_path();
snprintf(path_str, PATH_MAX, "%sedje/font-slider.edj", app_res_path);
free(app_res_path);
int r = elm_layout_file_set(layout, path_str,
"elm/slider/horizontal/music/soundalive");
if (!r) {
SETTING_TRACE_ERROR("elm_layout_add failed : %s",
"elm/slider/horizontal/music/soundalive");
evas_object_del(layout);
return NULL;
}
/* "elm/slider/horizontal/default" */
Evas_Object *slider = elm_slider_add(layout);
retv_if(slider == NULL, NULL);
elm_object_style_set(slider, "music/soundalive");
elm_slider_indicator_format_set(slider, "%1.0f");
elm_slider_indicator_show_set(slider, 5);
evas_object_size_hint_weight_set(slider, EVAS_HINT_EXPAND, 0.0);
evas_object_size_hint_align_set(slider, EVAS_HINT_FILL, 0.5);
double step = _step_size_calculate(slider, slider_min, slider_max);
elm_slider_step_set(slider, step);
SETTING_TRACE("slider_change_cb:%p", slider_change_cb);
if (slider_change_cb) evas_object_smart_callback_add(
slider, "changed", slider_change_cb, cb_data);
if (slider_stop_change_cb) evas_object_smart_callback_add(
slider, "slider,drag,stop", slider_stop_change_cb,
cb_data);
if (slider_start_change_cb) evas_object_smart_callback_add(
slider, "slider,drag,start", slider_start_change_cb,
cb_data);
if (l_swallow_path) {
Evas_Object *icon1 = elm_icon_add(slider);
elm_image_file_set(icon1, l_swallow_path, NULL);
evas_object_size_hint_aspect_set(
icon1, EVAS_ASPECT_CONTROL_VERTICAL, 1, 1);
elm_object_content_set(slider, icon1);
}
if (r_swallow_path) {
Evas_Object *icon2 = elm_icon_add(slider);
elm_image_file_set(icon2, r_swallow_path, NULL);
evas_object_size_hint_aspect_set(
icon2, EVAS_ASPECT_CONTROL_VERTICAL, 1, 1);
elm_object_part_content_set(slider, "end", icon2);
}
elm_slider_min_max_set(slider, slider_min, slider_max);
elm_slider_value_set(slider, value);
return slider;
}
/**
* To create slider object of a genlist item
*
*@return a slider container object
*/
EXPORT_PUBLIC Evas_Object *setting_create_slider(
Evas_Object *parent,
Setting_GenGroupItem_Data *item_data)
{
/* "elm/slider/horizontal/default" */
Evas_Object *slider = elm_slider_add(parent);
retv_if(slider == NULL, NULL);
if (item_data->isIndicatorVisible) {
elm_slider_indicator_format_set(slider, "%1.0f");
elm_slider_indicator_show_set(slider, EINA_TRUE);
} else {
/* for brightness slider */
elm_slider_indicator_show_set(slider, EINA_FALSE);
}
evas_object_size_hint_weight_set(slider, EVAS_HINT_EXPAND, 0.0);
evas_object_size_hint_align_set(slider, EVAS_HINT_FILL, 0.5);
double step = _step_size_calculate(
slider, item_data->slider_min, item_data->slider_max);
elm_slider_step_set(slider, step);
SETTING_TRACE("slider_change_cb:%p", item_data->chk_change_cb);
if (item_data->chk_change_cb)
evas_object_smart_callback_add(
slider, "changed", item_data->chk_change_cb,
item_data);
if (item_data->stop_change_cb)
evas_object_smart_callback_add(
slider, "slider,drag,stop",
item_data->stop_change_cb, item_data);
if (item_data->start_change_cb)
evas_object_smart_callback_add(
slider, "slider,drag,start",
item_data->start_change_cb, item_data);
if (item_data->l_swallow_path) {
Evas_Object *icon1 = elm_icon_add(slider);
elm_image_file_set(icon1, item_data->l_swallow_path, NULL);
evas_object_size_hint_aspect_set(
icon1, EVAS_ASPECT_CONTROL_VERTICAL, 1, 1);
elm_object_content_set(slider, icon1);
}
if (item_data->r_swallow_path) {
Evas_Object *icon2 = elm_icon_add(slider);
elm_image_file_set(icon2, item_data->r_swallow_path, NULL);
evas_object_size_hint_aspect_set(
icon2, EVAS_ASPECT_CONTROL_VERTICAL, 1, 1);
elm_object_part_content_set(slider, "end", icon2);
}
elm_slider_min_max_set(
slider, item_data->slider_min, item_data->slider_max);
elm_slider_value_set(slider, item_data->chk_status);
return slider;
}
#define DEMO_STEP 0.8
typedef struct _setting_gif_data {
Ecore_Timer *update_timer;
const char **png_list;
int cur_png_idx;
} setting_gif_data;
static void __gif_del_cb(
void *data, Evas *e, Evas_Object *obj, void *event_info)
{
SETTING_TRACE_BEGIN;
ret_if(!data);
setting_gif_data *gif_data = data;
if (gif_data->update_timer) {/*first delete the timer */
ecore_timer_del(gif_data->update_timer);
gif_data->update_timer = NULL;
}
FREE(gif_data);/*delete the date. */
evas_object_data_set(obj, "gif_data", NULL);
}
Eina_Bool __gif_updater(void *data)
{
retv_if(!data, FALSE);
Evas_Object *gif = data;
setting_gif_data *gif_data = evas_object_data_get(gif, "gif_data");
retv_if(!gif_data, FALSE);
/*SETTING_TRACE_BEGIN; */
gif_data->cur_png_idx++;
/*the last element of current array. */
if (NULL == gif_data->png_list[gif_data->cur_png_idx])
gif_data->cur_png_idx = 0;
elm_image_file_set(
gif, gif_data->png_list[gif_data->cur_png_idx], NULL);
int w = 0;
int h = 0;
elm_image_object_size_get(gif, &w, &h);
setting_resize_object(gif, w, h);
return TRUE;
}
EXPORT_PUBLIC
Evas_Object *setting_create_image(Evas_Object *parent, const char *img_path)
{
Evas_Object *image = elm_image_add(parent);
elm_image_file_set(image, img_path, NULL);
elm_image_resizable_set(image, EINA_TRUE, EINA_TRUE);
int w = 0;
int h = 0;
elm_image_object_size_get(image, &w, &h);
setting_resize_object(image, w, h);
evas_object_show(image);
return image;
}
/* @png_list is an array end with 'NULL'. like ,
const char *png_list[] = {
SETTING_ICON_PATH_CFG"motions/motion_overturn_01.png",
SETTING_ICON_PATH_CFG"motions/motion_overturn_02.png",
SETTING_ICON_PATH_CFG"motions/motion_overturn_03.png",
SETTING_ICON_PATH_CFG"motions/motion_overturn_04.png",
SETTING_ICON_PATH_CFG"motions/motion_overturn_05.png",
NULL //must end with 'NULL'
};
*/
EXPORT_PUBLIC
Evas_Object *setting_create_gif(Evas_Object *parent, const char **png_list)
{
retv_if(!png_list, NULL);
setting_gif_data *gif_data = calloc(1, sizeof(setting_gif_data));
setting_retvm_if(!gif_data, NULL, "calloc failed");
gif_data->cur_png_idx = 0;
gif_data->png_list = png_list;
SETTING_TRACE_BEGIN;
/*the first element */
Evas_Object *gif = setting_create_image(parent, *png_list);
/*bind object data */
evas_object_data_set(gif, "gif_data", gif_data);
evas_object_event_callback_add(
gif, EVAS_CALLBACK_DEL, __gif_del_cb, gif_data);
if (gif_data->update_timer) {
ecore_timer_del(gif_data->update_timer);
gif_data->update_timer = NULL;
}
gif_data->update_timer = ecore_timer_add(
DEMO_STEP, (Ecore_Task_Cb)__gif_updater, gif);
/* W011:bg, T051:text */
setting_decorate_image_RGBA(gif, 14, 41, 73, 255);
return gif;
}
/**
* Set the status of radio group object via its binded vconf value.
* @return 0: success, other: failed
*/
EXPORT_PUBLIC
int setting_update_chk_status(Evas_Object *chk, setting_int_slp_list type)
{
SETTING_TRACE_BEGIN;
/* error check */
if (chk == NULL)
return SETTING_GENERAL_ERR_NULL_DATA_PARAMETER;
SETTING_TRACE_BEGIN;
int ret = SETTING_RETURN_FAIL;
int value;
int err;
/* value set */
ret = setting_get_int_slp_key(type, &value, &err);
SETTING_TRACE("binded: %d, checked: %d, err: %d", type, value, err);
elm_radio_value_set(chk, value);
return ret;
}
/**
* Create a size specialized rectangle object
* @return a size specialized rectangle object
*/
EXPORT_PUBLIC
Evas_Object *setting_create_blank_rect_customize(
Evas_Object *layout,
int w,
int h)
{
Evas_Object *rect;
rect = evas_object_rectangle_add(evas_object_evas_get(layout));
evas_object_size_hint_min_set(
rect, ELM_SCALE_SIZE(w), ELM_SCALE_SIZE(h));
evas_object_size_hint_weight_set(rect, EVAS_HINT_EXPAND, 0);
evas_object_color_set(rect, 8, 8, 8, 8);
return rect;
}
/**
* Create a text box, which cannot be edited, just to show a specialization
* segment.
*
* @return a text box, which cannot be edited
*/
EXPORT_PUBLIC
Evas_Object *setting_create_textbox(Evas_Object *parent, const char *content)
{
Evas_Object *obj = NULL;
obj = elm_entry_add(parent);
evas_object_size_hint_weight_set(obj, EVAS_HINT_EXPAND, 0.0);
evas_object_size_hint_align_set(obj, EVAS_HINT_FILL, 0.5);
elm_entry_single_line_set(obj, 0);
elm_entry_editable_set(obj, 0);
elm_entry_context_menu_disabled_set(obj, 1);
elm_entry_entry_set(obj, content);
evas_object_show(obj);
return obj;
}
/**
* To resize a evas object, such as, icon, button..
*
* @param[in] obj
* @param[in] w
* @param[in] h
*/
EXPORT_PUBLIC
void setting_resize_object(Evas_Object *obj, Evas_Coord w, Evas_Coord h)
{
if (obj) {
evas_object_size_hint_min_set(
obj, ELM_SCALE_SIZE(w), ELM_SCALE_SIZE(h));
evas_object_size_hint_max_set(obj, w, h);
evas_object_resize(obj, w, h);
}
}
/**
* To create a bg object
*
* @param[in] parent
* @param[in] bg_style
* @return bg object
*/
EXPORT_PUBLIC
Evas_Object *setting_create_bg(
Evas_Object *parent, Evas_Object *win, const char *bg_style)
{
retv_if(!parent, NULL);
Evas_Object *bg = elm_bg_add(parent);
retv_if(!bg, NULL);
if (bg_style) elm_object_style_set(bg, bg_style);
evas_object_size_hint_weight_set(
bg, EVAS_HINT_EXPAND, EVAS_HINT_EXPAND);
evas_object_show(bg);
return bg;
}
#define DIFF_TIMES 2
/**
* To make an object which is operated by setting_dim_evas_object normal color
*
* @param[in] obj
* @param[in] b_transparency_set:
* 1:the appearance of obj is made up of transparent background color.
* 0:the appearance of obj is made up of non transparent color.
*/
EXPORT_PUBLIC
void setting_undo_dim_evas_object(Evas_Object *obj, bool b_transparency)
{
if (obj) {
int r;
int g;
int b;
int a;
evas_object_color_get(obj, &r, &g, &b, &a);
/*the appearance of obj is made up of transparent background
* color. */
if (b_transparency)
a *= DIFF_TIMES;
evas_object_color_set(
obj,
r * DIFF_TIMES,
g * DIFF_TIMES,
b * DIFF_TIMES,
a);
}
}
/**
* To make an object dim color
*
* @param[in] obj
* @param[in] b_transparency_set:
* 1:the appearance of obj is made up of transparent background color.
* 0:the appearance of obj is made up of non transparent color.
*/
EXPORT_PUBLIC
void setting_dim_evas_object(Evas_Object *obj, bool b_transparency)
{
if (obj) {
int r;
int g;
int b;
int a;
evas_object_color_get(obj, &r, &g, &b, &a);
/*the appearance of obj is made up of transparent background
* color. */
if (b_transparency)
a /= DIFF_TIMES;
evas_object_color_set(
obj,
r / DIFF_TIMES,
g / DIFF_TIMES,
b / DIFF_TIMES,
a);
}
}
/*
* set font_size, color or align(right, left, middle),if need, you
* can add </font_siz>, </color> or </align> to controll a segment words;
* or else the text will take the same effect until the end of text.
* @param[in] input_str
* @param[in] font_size
* @param[in] color
* @param[in] align :may be right, left, middle/center
*/
EXPORT_PUBLIC
char *setting_customize_text(
const char *input_str, const int font_size,
const char *color, const char *align)
{
/*SETTING_TRACE_BEGIN; */
retv_if(isEmptyStr(input_str), NULL);
char specialization[MAX_SPECIALIZATION_LEN] = { 0, };
/*<font_size=%d><align=middle><color=#9C9C9C>bbb</color></align>
* </font_size> */
if (font_size > 0) {
snprintf(specialization, sizeof(specialization),
"<font_size=%d>", font_size);
}
if (align) {
g_strlcat(specialization, "<align=", MAX_SPECIALIZATION_LEN);
g_strlcat(specialization, align, MAX_SPECIALIZATION_LEN);
g_strlcat(specialization, ">", MAX_SPECIALIZATION_LEN);
}
if (color) {
char input_str1[MAX_SPECIALIZATION_LEN] = { 0, };
safeCopyStr(input_str1, input_str, MAX_SPECIALIZATION_LEN - 1);
char *p = strstr(input_str1, "<color=");
/*already has customized color,to replace color sub_string */
if (p) {
p += strlen("<color=");
char *q = (char *)color;
while ('\0' != p[0] && '\0' != q[0]) {
*p = *q;
p++;
q++;
}
if ('>' != p[0]) { /*invalid format */
g_strlcat(specialization, "<color=",
MAX_SPECIALIZATION_LEN);
g_strlcat(specialization, color,
MAX_SPECIALIZATION_LEN);
g_strlcat(specialization, ">",
MAX_SPECIALIZATION_LEN);
g_strlcat(specialization, input_str,
MAX_SPECIALIZATION_LEN);
g_strlcat(specialization, "</color>",
MAX_SPECIALIZATION_LEN);
} else
g_strlcat(specialization, input_str1,
MAX_SPECIALIZATION_LEN);
} else {
g_strlcat(specialization, "<color=",
MAX_SPECIALIZATION_LEN);
g_strlcat(specialization, color,
MAX_SPECIALIZATION_LEN);
g_strlcat(specialization, ">",
MAX_SPECIALIZATION_LEN);
g_strlcat(specialization, input_str,
MAX_SPECIALIZATION_LEN);
g_strlcat(specialization, "</color>",
MAX_SPECIALIZATION_LEN);
}
} else {
g_strlcat(specialization, input_str,
MAX_SPECIALIZATION_LEN);
}
if (align) {
g_strlcat(specialization, "</align>",
MAX_SPECIALIZATION_LEN);
}
if (font_size > 0) {
g_strlcat(specialization, "</font_size>",
MAX_SPECIALIZATION_LEN);
}
return strdup(specialization);;
}
EXPORT_PUBLIC void setting_conformant_keypad_state(
Evas_Object *window, bool enable)
{
Evas_Object *conform = evas_object_data_get(window, "conformant");
if (conform) {
SETTING_TRACE("conformant keypad %d", enable);
if (enable) {
elm_object_signal_emit(conform,
"elm,state,virtualkeypad,enable", "");
elm_object_signal_emit(conform,
"elm,state,clipboard,enable", "");
} else {
elm_object_signal_emit(conform,
"elm,state,virtualkeypad,disable", "");
elm_object_signal_emit(conform,
"elm,state,clipboard,disable", "");
}
}
}
EXPORT_PUBLIC void
setting_decorate_image_RGBA(Evas_Object *obj, int r, int g, int b, int a)
{
if (obj)
evas_object_color_set(obj, r, g, b, a);
}
EXPORT_PUBLIC void
setting_protect_cb(void *data, Evas *e, Evas_Object *obj, void *event_info)
{
if (NULL != data) *((void **)data) = NULL;
}
EXPORT_PUBLIC void
setting_add_gl_help(Evas_Object *scroller, const char *str)
{
if (str) {
Setting_GenGroupItem_Data *item_data = setting_create_Gendial_field_def(
scroller,
&itc_multiline_text,
NULL,
NULL,
SWALLOW_Type_LAYOUT_SPECIALIZATION_X,
NULL,
NULL,
0,
str,
NULL,
NULL);
if (NULL == item_data) {
SETTING_TRACE_ERROR("item_data is NULL");
return;
}
elm_genlist_item_select_mode_set(
item_data->item,
ELM_OBJECT_SELECT_MODE_DISPLAY_ONLY);
}
}
EXPORT_PUBLIC Evas_Object *setting_add_empty_page(Evas_Object *parent, const char *text, const char *help)
{
Evas_Object *layout = NULL;
layout = elm_layout_add(parent);
elm_layout_theme_set(layout, "layout", "nocontents", "default");
evas_object_size_hint_weight_set(layout, EVAS_HINT_EXPAND,
EVAS_HINT_EXPAND);
evas_object_size_hint_align_set(layout, EVAS_HINT_FILL, EVAS_HINT_FILL);
elm_object_part_text_set(layout, "elm.text", _(text));
if (help) {
elm_object_part_text_set(layout, "elm.help.text", _(help));
elm_layout_signal_emit(layout, "align.center", "elm");
}
return layout;
}
|