summaryrefslogtreecommitdiff
path: root/src/lib/elementary/elm_part_helper.h
blob: 292ab9ccdf3501c52b722bfab95b7191310bd9a6 (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
330
331
332
333
334
#ifndef _ELM_PART_HELPER_H
#define _ELM_PART_HELPER_H

#include "Elementary.h"
#include "elm_priv.h"
#include "efl_ui_layout_part_legacy.eo.h"

//#define ELM_PART_HOOK do { ERR("%s@%p:%s [%d]", efl_class_name_get(pd->obj), pd->obj, pd->part, (int) pd->temp); } while(0)
#define ELM_PART_HOOK do {} while(0)

typedef struct _Elm_Part_Data Elm_Part_Data;
struct _Elm_Part_Data
{
   Eo             *obj;
   Eina_Tmpstr    *part;
};

// Note: this generic implementation can be improved to support part object
// caching or something...

// FIXME: Some widgets return the alias name, some return the real name
// alias doesn't work for frame, _elm_layout_part_aliasing_eval() fails for scroller
#define ELM_PART_CONTENT_DEFAULT_GET(type, part) \
   static const char * _ ## type ## _default_content_part_get(const Eo *obj EINA_UNUSED, void *sd EINA_UNUSED) { return part; }

#define ELM_PART_CONTENT_DEFAULT_OPS(type) \
   EFL_OBJECT_OP_FUNC(efl_ui_widget_default_content_part_get, _ ## type ## _default_content_part_get)

#define ELM_PART_TEXT_DEFAULT_GET(type, part) \
   static const char * _ ## type ## _default_text_part_get(const Eo *obj EINA_UNUSED, void *sd EINA_UNUSED) { return part; }

#define ELM_PART_TEXT_DEFAULT_OPS(type) \
   EFL_OBJECT_OP_FUNC(efl_ui_widget_default_text_part_get, _ ## type ## _default_text_part_get)

#define ELM_PART_CONTENT_DEFAULT_IMPLEMENT(type, typedata) \
   EOLIAN static Eina_Bool \
   _ ## type ## _efl_content_content_set(Eo *obj, typedata *sd EINA_UNUSED, Evas_Object *content) \
   { \
      return efl_content_set(efl_part(obj, efl_ui_widget_default_content_part_get(obj)), content); \
   } \
   \
   EOLIAN static Evas_Object* \
   _ ## type ## _efl_content_content_get(const Eo *obj, typedata *sd EINA_UNUSED) \
   { \
      return efl_content_get(efl_part(obj, efl_ui_widget_default_content_part_get(obj))); \
   } \
   \
   EOLIAN static Evas_Object* \
   _ ## type ## _efl_content_content_unset(Eo *obj, typedata *sd EINA_UNUSED) \
   { \
      return efl_content_unset(efl_part(obj, efl_ui_widget_default_content_part_get(obj))); \
   }

static inline Eo *
_elm_part_initialize(Eo *proxy, Eo *obj, const char *part)
{
   Elm_Part_Data *pd = efl_data_scope_get(proxy, EFL_UI_WIDGET_PART_CLASS);

   EINA_SAFETY_ON_FALSE_RETURN_VAL(pd && obj && part, NULL);
   pd->part = eina_tmpstr_add(part);
   pd->obj = obj;

   return proxy;
}

static inline Eo *
ELM_PART_IMPLEMENT(const Efl_Class *part_klass, const Eo *obj, const char *part)
{
   return efl_add(part_klass, (Eo *) obj,
                  _elm_part_initialize(efl_added, (Eo *) obj, part));
}

#define ELM_PART_OVERRIDE_PARTIAL(type, TYPE, typedata, _is_part_cb) \
   EOLIAN static Efl_Object * \
   _ ## type ## _efl_part_part_get(const Eo *obj, typedata *priv EINA_UNUSED, const char *part) \
   { \
     EINA_SAFETY_ON_NULL_RETURN_VAL(part, NULL); \
     if (_is_part_cb(obj, part)) \
       return ELM_PART_IMPLEMENT(TYPE ## _PART_CLASS, obj, part); \
     return efl_part_get(efl_super(obj, TYPE ## _CLASS), part); \
   }

#define ELM_PART_OVERRIDE(type, TYPE, typedata) \
EOLIAN static Efl_Object * \
_ ## type ## _efl_part_part_get(const Eo *obj, typedata *priv EINA_UNUSED, const char *part) \
{ \
   EINA_SAFETY_ON_NULL_RETURN_VAL(part, NULL); \
   return ELM_PART_IMPLEMENT(TYPE ## _PART_CLASS, obj, part); \
}

#define ELM_PART_OVERRIDE_INTERNALS_FETCH(TYPE, typedata) \
   Elm_Part_Data *pd = efl_data_scope_get(obj, EFL_UI_WIDGET_PART_CLASS); \
   typedata *sd = efl_data_scope_get(pd->obj, TYPE ## _CLASS);

#define ELM_PART_OVERRIDE_INTERNALS_FETCH_NO_SD() \
   Elm_Part_Data *pd = efl_data_scope_get(obj, EFL_UI_WIDGET_PART_CLASS); \
   void *sd = NULL;

#define ELM_PART_OVERRIDE_CONTENT_SET_FULL(full, type, internals) \
EOLIAN static Eina_Bool \
_ ## full ## _efl_content_content_set(Eo *obj, void *_pd EINA_UNUSED, Efl_Gfx_Entity *content) \
{ \
   internals \
   return _ ## type ## _content_set(pd->obj, sd, pd->part, content); \
}

#define ELM_PART_OVERRIDE_CONTENT_GET_FULL(full, type, internals) \
EOLIAN static Efl_Gfx_Entity * \
_ ## full ## _efl_content_content_get(const Eo *obj, void *_pd EINA_UNUSED) \
{ \
   internals \
   return _ ## type ## _content_get(pd->obj, sd, pd->part); \
}

#define ELM_PART_OVERRIDE_CONTENT_UNSET_FULL(full, type, internals) \
EOLIAN static Efl_Gfx_Entity * \
_ ## full ## _efl_content_content_unset(Eo *obj, void *_pd EINA_UNUSED) \
{ \
   internals \
   return _ ## type ## _content_unset(pd->obj, sd, pd->part); \
}

#define ELM_PART_OVERRIDE_TEXT_TEXT_SET_FULL(full, type, internals) \
EOLIAN static void \
_ ## full ## _efl_text_text_set(Eo *obj, void *_pd EINA_UNUSED, const char *text) \
{ \
   internals \
   _ ## type ## _text_set(pd->obj, sd, pd->part, text); \
}

#define ELM_PART_OVERRIDE_TEXT_TEXT_GET_FULL(full, type, internals) \
EOLIAN static const char *\
_ ## full ## _efl_text_text_get(const Eo *obj, void *_pd EINA_UNUSED) \
{ \
   internals \
   return _ ## type ## _text_get(pd->obj, sd, pd->part); \
}

#define ELM_PART_OVERRIDE_TEXT_MARKUP_GET_FULL(full, type, internals) \
EOLIAN static const char *\
_ ## full ## _efl_text_markup_markup_get(const Eo *obj, void *_pd EINA_UNUSED) \
{ \
   internals \
   return _ ## type ## _text_markup_get(pd->obj, sd, pd->part); \
}

#define ELM_PART_OVERRIDE_TEXT_MARKUP_SET_FULL(full, type, internals) \
EOLIAN static void \
_ ## full ## _efl_text_markup_markup_set(Eo *obj, void *_pd EINA_UNUSED, const char *markup) \
{ \
   internals \
   _ ## type ## _text_markup_set(pd->obj, sd, pd->part, markup); \
}

#define ELM_PART_OVERRIDE_TEXT_FONT_SET_FULL(full, type, internals) \
EOLIAN static void \
_ ## full ## _efl_text_font_font_set(Eo *obj, void *_pd EINA_UNUSED, const char *font, Efl_Font_Size size) \
{ \
   internals \
   _ ## type ## _text_font_set(pd->obj, sd, pd->part, font, size); \
}

#define ELM_PART_OVERRIDE_TEXT_FONT_GET_FULL(full, type, internals) \
EOLIAN static void \
_ ## full ## _efl_text_font_font_get(const Eo *obj, void *_pd EINA_UNUSED, const char **font, Efl_Font_Size *size) \
{ \
   internals \
   _ ## type ## _text_font_get(pd->obj, sd, pd->part, font, size); \
}

#define ELM_PART_OVERRIDE_TEXT_COLOR_SET_FULL(col, full, type, internals) \
EOLIAN static void \
_ ## full ## _efl_text_style_ ##col ##_color_set(Eo *obj, void *_pd EINA_UNUSED, unsigned char r, unsigned char g, unsigned char b, unsigned char a) \
{ \
   internals \
   _ ## type ## _text_ ##col ##_color_set(pd->obj, sd, pd->part, r, g, b, a); \
}

#define ELM_PART_OVERRIDE_TEXT_COLOR_GET_FULL(col, full, type, internals) \
EOLIAN static void \
_ ## full ## _efl_text_style_ ##col ##_color_get(const Eo *obj, void *_pd EINA_UNUSED, unsigned char *r, unsigned char *g, unsigned char *b, unsigned char *a) \
{ \
   internals \
   _ ## type ## _text_ ##col ##_color_get(pd->obj, sd, pd->part, r, g, b, a); \
}

#define ELM_PART_OVERRIDE_TEXT_BACKING_SET_FULL(full, type, internals) \
EOLIAN static void \
_ ## full ## _efl_text_style_backing_type_set(Eo *obj, void *_pd EINA_UNUSED, Efl_Text_Style_Backing_Type type) \
{ \
   internals \
   _ ## type ## _text_backing_type_set(pd->obj, sd, pd->part, type); \
}

#define ELM_PART_OVERRIDE_TEXT_BACKING_GET_FULL(full, type, internals) \
EOLIAN static Efl_Text_Style_Backing_Type \
_ ## full ## _efl_text_style_backing_type_get(const Eo *obj, void *_pd EINA_UNUSED) \
{ \
   internals \
   return _ ## type ## _text_backing_type_get(pd->obj, sd, pd->part); \
}

#define ELM_PART_OVERRIDE_TEXT_SHADOW_DIRECTION_SET_FULL(full, type, internals) \
EOLIAN static void \
_ ## full ## _efl_text_style_shadow_direction_set(Eo *obj, void *_pd EINA_UNUSED, Efl_Text_Style_Shadow_Direction dir) \
{ \
   internals \
   _ ## type ## _text_shadow_direction_set(pd->obj, sd, pd->part, dir); \
}

#define ELM_PART_OVERRIDE_TEXT_SHADOW_DIRECTION_GET_FULL(full, type, internals) \
EOLIAN static Efl_Text_Style_Shadow_Direction \
_ ## full ## _efl_text_style_shadow_direction_type_get(const Eo *obj, void *_pd EINA_UNUSED) \
{ \
   internals \
   return _ ## type ## _text_shadow_direction_get(pd->obj, sd, pd->part); \
}

#define ELM_PART_OVERRIDE_TEXT_STRIKETHROUGH_SET_FULL(full, type, internals) \
EOLIAN static void \
_ ## full ## _efl_text_style_strikethrough_type_set(Eo *obj, void *_pd EINA_UNUSED, Efl_Text_Style_Strikethrough_Type type) \
{ \
   internals \
   _ ## type ## _text_strikethrough_type_set(pd->obj, sd, pd->part, type); \
}

#define ELM_PART_OVERRIDE_TEXT_UNDERLINE_SET_FULL(full, type, internals) \
EOLIAN static void \
_ ## full ## _efl_text_style_underline_type_set(Eo *obj, void *_pd EINA_UNUSED, Efl_Text_Style_Underline_Type type) \
{ \
   internals \
   _ ## type ## _text_underline_type_set(pd->obj, sd, pd->part, type); \
}

#define ELM_PART_OVERRIDE_TEXT_UNDERLINE_DASHED_WIDTH_FULL(full, type, internals) \
EOLIAN static void \
_ ## full ## _efl_text_style_underline_dashed_width_set(Eo *obj, void *_pd EINA_UNUSED, int width) \
{ \
   internals \
   _ ## type ## _text_underline_dashed_width_set(pd->obj, sd, pd->part, width); \
}

#define ELM_PART_OVERRIDE_TEXT_UNDERLINE_DASHED_GAP_FULL(full, type, internals) \
EOLIAN static void \
_ ## full ## _efl_text_style_underline_dashed_gap_set(Eo *obj, void *_pd EINA_UNUSED, int gap) \
{ \
   internals \
   _ ## type ## _text_underline_dashed_gap_set(pd->obj, sd, pd->part, gap); \
}

#define ELM_PART_OVERRIDE_CONTENT_SET(type, TYPE, typedata) \
   ELM_PART_OVERRIDE_CONTENT_SET_FULL(type ## _part, type, ELM_PART_OVERRIDE_INTERNALS_FETCH(TYPE, typedata))

#define ELM_PART_OVERRIDE_CONTENT_GET(type, TYPE, typedata) \
   ELM_PART_OVERRIDE_CONTENT_GET_FULL(type ## _part, type, ELM_PART_OVERRIDE_INTERNALS_FETCH(TYPE, typedata))

#define ELM_PART_OVERRIDE_CONTENT_UNSET(type, TYPE, typedata) \
   ELM_PART_OVERRIDE_CONTENT_UNSET_FULL(type ## _part, type, ELM_PART_OVERRIDE_INTERNALS_FETCH(TYPE, typedata))

#define ELM_PART_OVERRIDE_TEXT_SET(type, TYPE, typedata) \
   ELM_PART_OVERRIDE_TEXT_TEXT_SET_FULL(type ## _part, type, ELM_PART_OVERRIDE_INTERNALS_FETCH(TYPE, typedata))

#define ELM_PART_OVERRIDE_TEXT_GET(type, TYPE, typedata) \
   ELM_PART_OVERRIDE_TEXT_TEXT_GET_FULL(type ## _part, type, ELM_PART_OVERRIDE_INTERNALS_FETCH(TYPE, typedata))

#define ELM_PART_OVERRIDE_MARKUP_SET(type, TYPE, typedata) \
   ELM_PART_OVERRIDE_TEXT_MARKUP_SET_FULL(type ## _part, type, ELM_PART_OVERRIDE_INTERNALS_FETCH(TYPE, typedata))

#define ELM_PART_OVERRIDE_MARKUP_GET(type, TYPE, typedata) \
   ELM_PART_OVERRIDE_TEXT_MARKUP_GET_FULL(type ## _part, type, ELM_PART_OVERRIDE_INTERNALS_FETCH(TYPE, typedata))

#define ELM_PART_OVERRIDE_CONTENT_SET_NO_SD(type) \
   ELM_PART_OVERRIDE_CONTENT_SET_FULL(type ## _part, type, ELM_PART_OVERRIDE_INTERNALS_FETCH_NO_SD())

#define ELM_PART_OVERRIDE_CONTENT_GET_NO_SD(type) \
   ELM_PART_OVERRIDE_CONTENT_GET_FULL(type ## _part, type, ELM_PART_OVERRIDE_INTERNALS_FETCH_NO_SD())

#define ELM_PART_OVERRIDE_CONTENT_UNSET_NO_SD(type) \
   ELM_PART_OVERRIDE_CONTENT_UNSET_FULL(type ## _part, type, ELM_PART_OVERRIDE_INTERNALS_FETCH_NO_SD())

#define ELM_PART_OVERRIDE_TEXT_SET_NO_SD(type) \
   ELM_PART_OVERRIDE_TEXT_TEXT_SET_FULL(type ## _part, type, ELM_PART_OVERRIDE_INTERNALS_FETCH_NO_SD())

#define ELM_PART_OVERRIDE_TEXT_GET_NO_SD(type) \
   ELM_PART_OVERRIDE_TEXT_TEXT_GET_FULL(type ## _part, type, ELM_PART_OVERRIDE_INTERNALS_FETCH_NO_SD())

#define ELM_PART_OVERRIDE_MARKUP_SET_NO_SD(type) \
   ELM_PART_OVERRIDE_TEXT_MARKUP_SET_FULL(type ## _part, type, ELM_PART_OVERRIDE_INTERNALS_FETCH_NO_SD())

#define ELM_PART_OVERRIDE_MARKUP_GET_NO_SD(type) \
   ELM_PART_OVERRIDE_TEXT_MARKUP_GET_FULL(type ## _part, type, ELM_PART_OVERRIDE_INTERNALS_FETCH_NO_SD())

#define ELM_PART_OVERRIDE_FONT_SET(type, TYPE, typedata) \
   ELM_PART_OVERRIDE_TEXT_FONT_SET_FULL(type ## _part, type, ELM_PART_OVERRIDE_INTERNALS_FETCH(TYPE, typedata))

#define ELM_PART_OVERRIDE_FONT_GET(type, TYPE, typedata) \
   ELM_PART_OVERRIDE_TEXT_FONT_GET_FULL(type ## _part, type, ELM_PART_OVERRIDE_INTERNALS_FETCH(TYPE, typedata))


#define ELM_PART_TEXT_DEFAULT_IMPLEMENT(type, typedata) \
EOLIAN static void \
_ ## type ## _efl_text_text_set(Eo *obj, typedata *sd EINA_UNUSED, const char *text) \
{ \
   efl_text_set(efl_part(obj, efl_ui_widget_default_text_part_get(obj)), text); \
} \
EOLIAN static const char * \
_ ## type ## _efl_text_text_get(const Eo *obj, typedata *sd EINA_UNUSED) \
{ \
  return efl_text_get(efl_part(obj, efl_ui_widget_default_text_part_get(obj))); \
} \
EOLIAN static void \
_ ## type ## _efl_ui_translatable_translatable_text_set(Eo *obj, typedata *sd EINA_UNUSED, const char *label, const char *domain) \
{ \
   efl_ui_translatable_text_set(efl_part(obj, efl_ui_widget_default_text_part_get(obj)), label, domain); \
} \
EOLIAN static const char * \
_ ## type ## _efl_ui_translatable_translatable_text_get(const Eo *obj, typedata *sd EINA_UNUSED, const char **domain) \
{ \
  return efl_ui_translatable_text_get(efl_part(obj, efl_ui_widget_default_text_part_get(obj)), domain); \
}

#define ELM_PART_MARKUP_DEFAULT_IMPLEMENT(type, typedata) \
EOLIAN static const char * \
_ ## type ## _efl_text_markup_markup_get(const Eo *obj, typedata *sd EINA_UNUSED) \
{ \
  return efl_text_markup_get(efl_part(obj, efl_ui_widget_default_text_part_get(obj))); \
} \
EOLIAN static void \
_ ## type ## _efl_text_markup_markup_set(Eo *obj, typedata *sd EINA_UNUSED, const char *markup) \
{ \
  efl_text_markup_set(efl_part(obj, efl_ui_widget_default_text_part_get(obj)), markup); \
}

#endif