efl

Форк
0
/
edje-text.c 
210 строк · 7.6 Кб
1
/**
2
 * Simple Edje example illustrating text functions.
3
 *
4
 * You'll need at least one Evas engine built for it (excluding the
5
 * buffer one). See stdout/stderr for output.
6
 *
7
 * @verbatim
8
 * edje_cc -md . text.edc && gcc -o edje-text edje-text.c `pkg-config --libs --cflags ecore-evas edje evas ecore eo`
9
 * @endverbatim
10
 */
11

12
#ifdef HAVE_CONFIG_H
13
# include "config.h"
14
#else
15
# define EINA_UNUSED
16
#endif
17

18
#ifndef PACKAGE_DATA_DIR
19
#define PACKAGE_DATA_DIR "."
20
#endif
21

22
#include <Ecore.h>
23
#include <Ecore_Evas.h>
24
#include <Edje.h>
25
#include <locale.h>
26
#include "Eo.h"
27

28
#define WIDTH  (500)
29
#define HEIGHT (500)
30

31
static int lang_idx = 0;
32
static const char *lang[] = {
33
  "en_IN",
34
  "ta_IN",
35
  "hi_IN"
36
};
37

38
static void
39
_on_delete(Ecore_Evas *ee EINA_UNUSED)
40
{
41
   ecore_main_loop_quit();
42
}
43

44
static void
45
_on_text_change(void *data EINA_UNUSED, Evas_Object *obj, const char *part)
46
{
47
   char *str = edje_object_part_text_unescaped_get(obj, part);
48
   printf("text: %s\n", str);
49
   free(str);
50
}
51

52
static void
53
_on_mouse_down(void *data EINA_UNUSED, Evas *e EINA_UNUSED, Evas_Object *o, void *event_info EINA_UNUSED)
54
{
55
   static char envbuf[20]; // doesn't have to be static, but a good habit
56
   char *env;
57
   lang_idx = (lang_idx + 1) % (sizeof (lang) / sizeof (lang[0]));
58
   fprintf(stderr, "Setting lang of this edje object to '%s'\n", lang[lang_idx]);
59

60
   // unfortunately dealing with env vars portably means using putenv()
61
   // which has issues that lead to complexity like below. the envbuf is
62
   // static because in general  it's a good habit when dealing with putenv()
63
   // but in this case it doesn't need to be. it's good to show good habits
64
   // at any rate. read up pn putenv() and how it takes the string pointer
65
   // directly into the env and takes "ownership" (but will never actually
66
   // free it if its an allocated string etc.).
67
   env = getenv("LANGUAGE");
68
   if (env) env = strdup(env);
69
   snprintf(envbuf, sizeof(envbuf), "LANGUAGE=%s", lang[lang_idx]);
70
   putenv(envbuf);
71

72
   edje_object_language_set(o, lang[lang_idx]);
73

74
   snprintf(envbuf, sizeof(envbuf), "LANGUAGE=%s", env ? env : "");
75
   putenv(envbuf);
76
   free(env);
77
}
78

79
static void
80
_on_mouse_down_text(void *data EINA_UNUSED, Evas *e EINA_UNUSED, Evas_Object *o EINA_UNUSED, void *event_info EINA_UNUSED)
81
{
82
   static char *env_lang_str = NULL;
83
   char *s;
84

85
   lang_idx = (lang_idx + 1) % (sizeof (lang)/ sizeof (lang[0]));
86
   fprintf(stderr, "Setting lang to '%s'\n", lang[lang_idx]);
87
   s = malloc(10 + strlen(lang[lang_idx]));
88
   if (s)
89
     {
90
        strcpy(s, "LANGUAGE=");
91
        strcpy(s + 9, lang[lang_idx]);
92
        putenv(s);
93
        if (env_lang_str) free(env_lang_str);
94
        env_lang_str = s;
95
     }
96
   edje_language_set(lang[lang_idx]);
97
}
98
int
99
main(int argc EINA_UNUSED, char *argv[] EINA_UNUSED)
100
{
101
   const char  *edje_file = PACKAGE_DATA_DIR"/text.edj";
102
   Ecore_Evas  *ee;
103
   Evas        *evas;
104
   Evas_Object *bg;
105
   Evas_Object *edje_obj;
106
   Evas_Object *edje_obj_one;
107
   Evas_Object *edje_obj_two;
108
   Evas_Object *edje_obj_three;
109

110
   if (!ecore_evas_init())
111
     return EXIT_FAILURE;
112

113
   if (!edje_init())
114
     goto shutdown_ecore_evas;
115

116
   /* this will give you a window with an Evas canvas under the first
117
    * engine available */
118
   ee = ecore_evas_new(NULL, 0, 0, WIDTH, HEIGHT, NULL);
119
   if (!ee) goto shutdown_edje;
120

121
   ecore_evas_callback_delete_request_set(ee, _on_delete);
122
   ecore_evas_title_set(ee, "Edje Text Example");
123

124
   evas = ecore_evas_get(ee);
125

126
   bg = evas_object_rectangle_add(evas);
127
   evas_object_color_set(bg, 255, 255, 255, 255); /* white bg */
128
   evas_object_move(bg, 0, 0); /* at canvas' origin */
129
   evas_object_resize(bg, WIDTH, HEIGHT); /* covers full canvas */
130
   evas_object_show(bg);
131
   ecore_evas_object_associate(ee, bg, ECORE_EVAS_OBJECT_ASSOCIATE_BASE);
132

133
   edje_obj = edje_object_add(evas);
134
   edje_object_file_set(edje_obj, edje_file, "example_group");
135
   evas_object_move(edje_obj, 0, 20);
136
   evas_object_resize(edje_obj, WIDTH - 40, HEIGHT - 40);
137
   evas_object_show(edje_obj);
138
   putenv("LANGUAGE=en_IN");
139
   edje_object_language_set(edje_obj, "en_IN");
140
   edje_object_text_change_cb_set(edje_obj, _on_text_change, NULL);
141
   edje_object_part_text_set(edje_obj, "part_two", "<b>Click here");
142
   edje_object_part_text_select_allow_set(edje_obj, "part_two", EINA_TRUE);
143
   edje_object_part_text_select_all(edje_obj, "part_two");
144
   printf("selection: %s\n", edje_object_part_text_selection_get(edje_obj, "part_two"));
145
   edje_object_part_text_select_none(edje_obj, "part_two");
146
   printf("selection: %s\n", edje_object_part_text_selection_get(edje_obj, "part_two"));
147
   evas_object_event_callback_add(edje_obj, EVAS_CALLBACK_MOUSE_DOWN, _on_mouse_down, NULL);
148

149
   edje_obj_one = edje_object_add(evas);
150
   edje_object_file_set(edje_obj_one, edje_file, "example_group1");
151
   evas_object_move(edje_obj_one, 0, 50);
152
   evas_object_resize(edje_obj_one, WIDTH - 40, HEIGHT - 40);
153
   evas_object_show(edje_obj_one);
154
   edje_object_language_set(edje_obj_one, "en_IN");
155
   edje_object_text_change_cb_set(edje_obj_one, _on_text_change, NULL);
156
   edje_object_part_text_set(edje_obj_one, "part_two", "<b>Click here");
157
   edje_object_part_text_select_allow_set(edje_obj_one, "part_two", EINA_TRUE);
158
   edje_object_part_text_select_all(edje_obj_one, "part_two");
159
   printf("selection: %s\n", edje_object_part_text_selection_get(edje_obj_one, "part_two"));
160
   edje_object_part_text_select_none(edje_obj_one, "part_two");
161
   printf("selection: %s\n", edje_object_part_text_selection_get(edje_obj_one, "part_two"));
162
   evas_object_event_callback_add(edje_obj_one, EVAS_CALLBACK_MOUSE_DOWN, _on_mouse_down, NULL);
163

164
   //Generic Language change
165
   edje_obj_two = edje_object_add(evas);
166
   edje_object_file_set(edje_obj_two, edje_file, "example_group2");
167
   evas_object_move(edje_obj_two, 0, 250);
168
   evas_object_resize(edje_obj_two, WIDTH - 40, HEIGHT - 40);
169
   evas_object_show(edje_obj_two);
170
   edje_language_set("en_IN");
171
   edje_object_text_change_cb_set(edje_obj_two, _on_text_change, NULL);
172
   edje_object_part_text_set(edje_obj_two, "part_two", "<b>Click here");
173
   edje_object_part_text_select_allow_set(edje_obj_two, "part_two", EINA_TRUE);
174
   edje_object_part_text_select_all(edje_obj_two, "part_two");
175
   printf("selection: %s\n", edje_object_part_text_selection_get(edje_obj_two, "part_two"));
176
   edje_object_part_text_select_none(edje_obj_two, "part_two");
177
   printf("selection: %s\n", edje_object_part_text_selection_get(edje_obj_two, "part_two"));
178
   evas_object_event_callback_add(edje_obj_two, EVAS_CALLBACK_MOUSE_DOWN, _on_mouse_down_text, NULL);
179

180
   edje_obj_three = edje_object_add(evas);
181
   edje_object_file_set(edje_obj_three, edje_file, "example_group3");
182
   evas_object_move(edje_obj_three, 0, 350);
183
   evas_object_resize(edje_obj_three, WIDTH - 40, HEIGHT - 40);
184
   evas_object_show(edje_obj_three);
185
   edje_object_text_change_cb_set(edje_obj_three, _on_text_change, NULL);
186
   edje_object_part_text_set(edje_obj_three, "part_two", "<b>Click here");
187
   edje_object_part_text_select_allow_set(edje_obj_three, "part_two", EINA_TRUE);
188
   edje_object_part_text_select_all(edje_obj_three, "part_two");
189
   printf("selection: %s\n", edje_object_part_text_selection_get(edje_obj_three, "part_two"));
190
   edje_object_part_text_select_none(edje_obj_three, "part_two");
191
   printf("selection: %s\n", edje_object_part_text_selection_get(edje_obj_three, "part_two"));
192
   evas_object_event_callback_add(edje_obj_three, EVAS_CALLBACK_MOUSE_DOWN, _on_mouse_down_text, NULL);
193

194
   ecore_evas_show(ee);
195

196
   ecore_main_loop_begin();
197

198
   ecore_evas_free(ee);
199
   ecore_evas_shutdown();
200
   edje_shutdown();
201

202
   return EXIT_SUCCESS;
203

204
 shutdown_edje:
205
   edje_shutdown();
206
 shutdown_ecore_evas:
207
   ecore_evas_shutdown();
208

209
   return EXIT_FAILURE;
210
}
211

Использование cookies

Мы используем файлы cookie в соответствии с Политикой конфиденциальности и Политикой использования cookies.

Нажимая кнопку «Принимаю», Вы даете АО «СберТех» согласие на обработку Ваших персональных данных в целях совершенствования нашего веб-сайта и Сервиса GitVerse, а также повышения удобства их использования.

Запретить использование cookies Вы можете самостоятельно в настройках Вашего браузера.