aboutsummaryrefslogtreecommitdiffstats
path: root/src/embed.c
blob: f56fff02f0b683d0168efa35ac99fe9a5fac5e37 (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
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
#include "embed.h"

typedef struct _Embed Embed_Private;

struct _Embed
{
   Ebits_Object o;
   Evas evas;
   Evas_Object image_obj;
   Evas_Object clip_obj;
   int clip_x, clip_y;
   E_Text *text_obj;
};

static void
e_embed_text_func_show(void *_data)
{
   Embed_Private *em;
   
   em = _data;
   if (em->clip_obj) evas_show(em->evas, em->clip_obj);
   e_text_show(em->text_obj);
}

static void
e_embed_text_func_hide(void *_data)
{
   Embed_Private *em;
   
   em = _data;
   if (em->clip_obj) evas_hide(em->evas, em->clip_obj);
   e_text_hide(em->text_obj);
}

static void
e_embed_text_func_move(void *_data, double x, double y)
{
   Embed_Private *em;
   
   em = _data;
   if (em->clip_obj) evas_move(em->evas, em->clip_obj, x, y);
   e_text_move(em->text_obj, x, y);
}

static void
e_embed_text_func_resize(void *_data, double w, double h)
{
   Embed_Private *em;
   
   em = _data;
   if (em->clip_obj) evas_resize(em->evas, em->clip_obj, w, h);
   e_text_resize(em->text_obj, w, h);
}

static void
e_embed_text_func_raise(void *_data)
{
   Embed_Private *em;
   
   em = _data;
   if (em->clip_obj) evas_raise(em->evas, em->clip_obj);
   e_text_raise(em->text_obj);
}

static void
e_embed_text_func_lower(void *_data)
{
   Embed_Private *em;
   
   em = _data;
   if (em->clip_obj) evas_lower(em->evas, em->clip_obj);
   e_text_lower(em->text_obj);
}

static void
e_embed_text_func_set_layer(void *_data, int l)
{
   Embed_Private *em;
   
   em = _data;
   if (em->clip_obj) evas_set_layer(em->evas, em->clip_obj, l);
   e_text_set_layer(em->text_obj, l);
}

static void
e_embed_text_func_set_clip(void *_data, Evas_Object clip)
{
   Embed_Private *em;
   
   em = _data;
   if (em->clip_obj)
     {
	if (clip)
	  e_text_set_clip(em->clip_obj, clip);
	else
	  e_text_unset_clip(em->clip_obj);	
     }
   else
     {
	if (clip)
	  e_text_set_clip(em->text_obj, clip);
	else
	  e_text_unset_clip(em->text_obj);
     }
}

static void
e_embed_text_func_set_color_class(void *_data, char *cc, int r, int g, int b, int a)
{
   UN(_data);
   UN(cc);
   UN(r);
   UN(g);
   UN(b);
   UN(a);
}

static void
e_embed_text_func_get_min_size(void *_data, double *w, double *h)
{
   Embed_Private *em;
   
   em = _data;
   e_text_get_min_size(em->text_obj, w, h);
   if (em->clip_x) *w = 0;
   if (em->clip_y) *h = 0;
}

static void
e_embed_text_func_get_max_size(void *_data, double *w, double *h)
{
   Embed_Private *em;
   
   em = _data;
   e_text_get_max_size(em->text_obj, w, h);
   if (em->clip_x) *w = 999999999;
   if (em->clip_y) *h = 999999999;
}

/***/

Embed
e_embed_text(Ebits_Object o, char *bit_name, Evas evas, E_Text *text_obj, int clip_x, int clip_y)
{
   Embed_Private *em;
   
   em = NEW(Embed_Private, 1);
   ZERO(em, Embed_Private, 1);
   em->o = o;
   em->evas = evas;
   em->text_obj = text_obj;
   em->clip_x = clip_x;
   em->clip_y = clip_y;
   if ((clip_x) || (clip_y))
     {
	em->clip_obj = evas_add_rectangle(em->evas);
	evas_set_color(em->evas, em->clip_obj, 255, 255, 255, 255);
	e_text_set_clip(em->text_obj, em->clip_obj);
	evas_show(em->evas, em->clip_obj);
     }
   ebits_set_named_bit_replace(o, bit_name, 
			       e_embed_text_func_show,
			       e_embed_text_func_hide,
			       e_embed_text_func_move,
			       e_embed_text_func_resize,
			       e_embed_text_func_raise,
			       e_embed_text_func_lower,
			       e_embed_text_func_set_layer,
			       e_embed_text_func_set_clip,
			       e_embed_text_func_set_color_class,
			       e_embed_text_func_get_min_size,
			       e_embed_text_func_get_max_size,
			       em);   
   return em;
}

/*****************************************************************************/

static void
e_embed_image_func_show(void *_data)
{
   Embed_Private *em;
   
   em = _data;
   evas_show(em->evas, em->image_obj);
}

static void
e_embed_image_func_hide(void *_data)
{
   Embed_Private *em;
   
   em = _data;
   evas_hide(em->evas, em->image_obj);
}

static void
e_embed_image_func_move(void *_data, double x, double y)
{
   Embed_Private *em;
   
   em = _data;
   evas_move(em->evas, em->image_obj, x, y);
}

static void
e_embed_image_func_resize(void *_data, double w, double h)
{
   Embed_Private *em;
   
   em = _data;
   evas_resize(em->evas, em->image_obj, w, h);
   evas_set_image_fill(em->evas, em->image_obj, 0, 0, w, h);
}

static void
e_embed_image_func_raise(void *_data)
{
   Embed_Private *em;
   
   em = _data;
   evas_raise(em->evas, em->image_obj);
}

static void
e_embed_image_func_lower(void *_data)
{
   Embed_Private *em;
   
   em = _data;
   evas_lower(em->evas, em->image_obj);
}

static void
e_embed_image_func_set_layer(void *_data, int l)
{
   Embed_Private *em;
   
   em = _data;
   evas_set_layer(em->evas, em->image_obj, l);
}

static void
e_embed_image_func_set_clip(void *_data, Evas_Object clip)
{
   Embed_Private *em;
   
   em = _data;
   if (clip)
     evas_set_clip(em->evas, em->image_obj, clip);
   else
     evas_unset_clip(em->evas, em->image_obj);
}

static void
e_embed_image_func_set_color_class(void *_data, char *cc, int r, int g, int b, int a)
{
   Embed_Private *em;
   
   em = _data;
   if ((cc) && (!strcmp(cc, "icon")))
     evas_set_color(em->evas, em->image_obj, r, g, b, a);
}

static void
e_embed_image_func_get_min_size(void *_data, double *w, double *h)
{
   Embed_Private *em;
   int iw, ih;
   
   em = _data;
   iw = 0;
   ih = 0;
   evas_get_image_size(em->evas, em->image_obj, &iw, &ih);
   if (w) *w = iw;
   if (h) *h = ih;
}

static void
e_embed_image_func_get_max_size(void *_data, double *w, double *h)
{
   Embed_Private *em;
   int iw, ih;
   
   em = _data;
   evas_get_image_size(em->evas, em->image_obj, &iw, &ih);
   if (w) *w = iw;
   if (h) *h = ih;
}

/***/

Embed
e_embed_image_object(Ebits_Object o, char *bit_name, Evas evas, Evas_Object image_obj)
{
   Embed_Private *em;
   
   em = NEW(Embed_Private, 1);
   ZERO(em, Embed_Private, 1);
   em->o = o;
   em->evas = evas;
   em->image_obj = image_obj;
   ebits_set_named_bit_replace(o, bit_name, 
			       e_embed_image_func_show,
			       e_embed_image_func_hide,
			       e_embed_image_func_move,
			       e_embed_image_func_resize,
			       e_embed_image_func_raise,
			       e_embed_image_func_lower,
			       e_embed_image_func_set_layer,
			       e_embed_image_func_set_clip,
			       e_embed_image_func_set_color_class,
			       e_embed_image_func_get_min_size,
			       e_embed_image_func_get_max_size,
			       em);
   return em;
}

/*****/

void
e_embed_free(Embed emb)
{
   Embed_Private *em;
   
   em = emb;
   if (em->clip_obj) evas_del_object(em->evas, em->clip_obj);
   FREE(em);
}