1 #ifndef E_MACROS_H
2 # define E_MACROS_H
3 
4 
5 # ifdef E_API
6 #  undef E_API
7 # endif
8 # ifdef WIN32
9 #  ifdef BUILDING_DLL
10 #   define E_API __declspec(dllexport)
11 #  else
12 #   define E_API __declspec(dllimport)
13 #  endif
14 # else
15 #  ifdef __GNUC__
16 #   if __GNUC__ >= 4
17 /* BROKEN in gcc 4 on amd64 */
18 #    if 0
19 #     pragma GCC visibility push(hidden)
20 #    endif
21 #    define E_API __attribute__ ((visibility("default")))
22 #   else
23 #    define E_API
24 #   endif
25 #  else
26 #   define E_API
27 #  endif
28 # endif
29 
30 # ifdef EINTERN
31 #  undef EINTERN
32 # endif
33 # ifdef __GNUC__
34 #  if __GNUC__ >= 4
35 #   define EINTERN __attribute__ ((visibility("hidden")))
36 #  else
37 #   define EINTERN
38 #  endif
39 # else
40 #  define EINTERN
41 # endif
42 
43 /* convenience macro to compress code and avoid typos */
44 #ifndef MAX
45 # define MAX(x, y) (((x) > (y)) ? (x) : (y))
46 #endif
47 
48 #ifndef MIN
49 # define MIN(x, y) (((x) < (y)) ? (x) : (y))
50 #endif
51 
52 # define E_FREE_FUNC(_h, _fn) do { if (_h) { _fn((void*)_h); _h = NULL; } } while (0)
53 # define E_INTERSECTS(x, y, w, h, xx, yy, ww, hh) \
54   (((x) < ((xx) + (ww))) && ((y) < ((yy) + (hh))) && (((x) + (w)) > (xx)) && (((y) + (h)) > (yy)))
55 # define E_INSIDE(x, y, xx, yy, ww, hh) \
56   (((x) < ((xx) + (ww))) && ((y) < ((yy) + (hh))) && ((x) >= (xx)) && ((y) >= (yy)))
57 # define E_CONTAINS(x, y, w, h, xx, yy, ww, hh) \
58   (((xx) >= (x)) && (((x) + (w)) >= ((xx) + (ww))) && ((yy) >= (y)) && (((y) + (h)) >= ((yy) + (hh))))
59 # define E_SPANS_COMMON(x1, w1, x2, w2) \
60   (!((((x2) + (w2)) <= (x1)) || ((x2) >= ((x1) + (w1)))))
61 # define E_REALLOC(p, s, n)   p = (s *)realloc(p, sizeof(s) * n)
62 # define E_NEW(s, n)          (s *)calloc(n, sizeof(s))
63 # define E_NEW_RAW(s, n)      (s *)malloc(n * sizeof(s))
64 # define E_FREE(p)            do { free(p); p = NULL; } while (0)
65 # define E_FREE_LIST(list, free)    \
66   do                                \
67     {                               \
68        void *_tmp_;                 \
69        EINA_LIST_FREE(list, _tmp_) \
70          {                          \
71             free(_tmp_);            \
72          }                          \
73     }                               \
74   while (0)
75 
76 # define E_LIST_REVERSE_FREE(list, data)         \
77   for (data = eina_list_last_data_get(list);          \
78        list;                                     \
79        list = eina_list_remove_list(list, eina_list_last(list)), \
80        data = eina_list_last_data_get(list))
81 
82 # define E_LIST_FOREACH(list, func)    \
83   do                                \
84     {                               \
85        void *_tmp_;                 \
86        const Eina_List *_list, *_list2;  \
87        EINA_LIST_FOREACH_SAFE(list, _list, _list2, _tmp_) \
88          {                          \
89             func(_tmp_);            \
90          }                          \
91     }                               \
92   while (0)
93 
94 # define E_LIST_HANDLER_APPEND(list, type, callback, data) \
95   do \
96     { \
97        Ecore_Event_Handler *_eh; \
98        _eh = ecore_event_handler_add(type, (void *)callback, data); \
99        assert(_eh); \
100        list = eina_list_append(list, _eh); \
101     } \
102   while (0)
103 # define E_LIST_HANDLER_APPEND_PRE(list, type, callback, data) \
104   do \
105     { \
106        Ecore_Event_Handler *_eh; \
107        _eh = ecore_event_handler_prepend(type, (void *)callback, data); \
108        assert(_eh); \
109        list = eina_list_append(list, _eh); \
110     } \
111   while (0)
112 
113 # define E_CLAMP(x, min, max) (x < min ? min : (x > max ? max : x))
114 # define E_RECTS_CLIP_TO_RECT(_x, _y, _w, _h, _cx, _cy, _cw, _ch) \
115   {                                                               \
116      if (E_INTERSECTS(_x, _y, _w, _h, _cx, _cy, _cw, _ch))        \
117        {                                                          \
118           if ((int)_x < (int)(_cx))                               \
119             {                                                     \
120                _w += _x - (_cx);                                  \
121                _x = (_cx);                                        \
122                if ((int)_w < 0) _w = 0;                           \
123             }                                                     \
124           if ((int)(_x + _w) > (int)((_cx) + (_cw)))              \
125             _w = (_cx) + (_cw) - _x;                              \
126           if ((int)_y < (int)(_cy))                               \
127             {                                                     \
128                _h += _y - (_cy);                                  \
129                _y = (_cy);                                        \
130                if ((int)_h < 0) _h = 0;                           \
131             }                                                     \
132           if ((int)(_y + _h) > (int)((_cy) + (_ch)))              \
133             _h = (_cy) + (_ch) - _y;                              \
134        }                                                          \
135      else                                                         \
136        {                                                          \
137           _w = 0; _h = 0;                                         \
138        }                                                          \
139   }
140 
141 #define E_WEIGHT evas_object_size_hint_weight_set
142 #define E_ALIGN evas_object_size_hint_align_set
143 #define E_EXPAND(X) E_WEIGHT((X), EVAS_HINT_EXPAND, EVAS_HINT_EXPAND)
144 #define E_FILL(X) E_ALIGN((X), EVAS_HINT_FILL, EVAS_HINT_FILL)
145 
146 #ifdef E_RELEASE_BUILD
147 # define E_BITFIELD :1
148 #else
149 # define E_BITFIELD
150 #endif
151 
152 #endif
153