elementary/map - map supports language,changed
[framework/uifw/elementary.git] / src / lib / elm_widget_image.h
1 #ifndef ELM_WIDGET_IMAGE_H
2 #define ELM_WIDGET_IMAGE_H
3
4 /**
5  * @addtogroup Widget
6  * @{
7  *
8  * @section elm-image-class The Elementary Image Class
9  *
10  * This class defines a common interface for @b image objects having
11  * an image as their basic graphics. This interface is so that one can
12  * tune various properties of the image, like:
13  * - smooth scaling,
14  * - orientation,
15  * - aspect ratio during resizes, etc.
16  *
17  * Image files may be set via memory buffers, image files, EET files
18  * with image data or Edje files. On the last case (which is
19  * exceptional), most of the properties cited above will @b not be
20  * changeable anymore.
21  */
22
23  /**
24   * @def ELM_IMAGE_CLASS
25   *
26   * Use this macro to cast whichever subclass of
27   * #Elm_Image_Smart_Class into it, so to access its fields.
28   *
29   * @ingroup Widget
30   */
31  #define ELM_IMAGE_CLASS(x) ((Elm_Image_Smart_Class *) x)
32
33 /**
34  * @def ELM_IMAGE_DATA
35  *
36  * Use this macro to cast whichever subdata of
37  * #Elm_Image_Smart_Data into it, so to access its fields.
38  *
39  * @ingroup Widget
40  */
41 #define ELM_IMAGE_DATA(x) ((Elm_Image_Smart_Data *) x)
42
43 /**
44  * @def ELM_IMAGE_SMART_CLASS_VERSION
45  *
46  * Current version for Elementary image @b base smart class, a value
47  * which goes to _Elm_Image_Smart_Class::version.
48  *
49  * @ingroup Widget
50  */
51 #define ELM_IMAGE_SMART_CLASS_VERSION 1
52
53 /**
54  * @def ELM_IMAGE_SMART_CLASS_INIT
55  *
56  * Initializer for a whole #Elm_Image_Smart_Class structure, with
57  * @c NULL values on its specific fields.
58  *
59  * @param smart_class_init initializer to use for the "base" field
60  * (#Evas_Smart_Class).
61  *
62  * @see EVAS_SMART_CLASS_INIT_NULL
63  * @see EVAS_SMART_CLASS_INIT_NAME_VERSION
64  * @see ELM_IMAGE_SMART_CLASS_INIT_NULL
65  * @see ELM_IMAGE_SMART_CLASS_INIT_NAME_VERSION
66  *
67  * @ingroup Widget
68  */
69 #define ELM_IMAGE_SMART_CLASS_INIT(smart_class_init)                        \
70   {smart_class_init, ELM_IMAGE_SMART_CLASS_VERSION, NULL, NULL, NULL, NULL, \
71    NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL,  \
72    NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL}
73
74 /**
75  * @def ELM_IMAGE_SMART_CLASS_INIT_NULL
76  *
77  * Initializer to zero out a whole #Elm_Image_Smart_Class structure.
78  *
79  * @see ELM_IMAGE_SMART_CLASS_INIT_NAME_VERSION
80  * @see ELM_IMAGE_SMART_CLASS_INIT
81  *
82  * @ingroup Widget
83  */
84 #define ELM_IMAGE_SMART_CLASS_INIT_NULL \
85   ELM_IMAGE_SMART_CLASS_INIT(EVAS_SMART_CLASS_INIT_NULL)
86
87 /**
88  * @def ELM_IMAGE_SMART_CLASS_INIT_NAME_VERSION
89  *
90  * Initializer to zero out a whole #Elm_Image_Smart_Class structure and
91  * set its name and version.
92  *
93  * This is similar to #ELM_IMAGE_SMART_CLASS_INIT_NULL, but it will
94  * also set the version field of #Elm_Image_Smart_Class (base field)
95  * to the latest #ELM_IMAGE_SMART_CLASS_VERSION and name it to the
96  * specific value.
97  *
98  * It will keep a reference to the name field as a <c>"const char *"</c>,
99  * i.e., the name must be available while the structure is
100  * used (hint: static or global variable!) and must not be modified.
101  *
102  * @see ELM_IMAGE_SMART_CLASS_INIT_NULL
103  * @see ELM_IMAGE_SMART_CLASS_INIT
104  *
105  * @ingroup Widget
106  */
107 #define ELM_IMAGE_SMART_CLASS_INIT_NAME_VERSION(name) \
108   ELM_IMAGE_SMART_CLASS_INIT(ELM_WIDGET_SMART_CLASS_INIT_NAME_VERSION(name))
109
110 /**
111  * Elementary image base smart class. This inherits directly from
112  * #Elm_Widget_Smart_Class and is meant to build widgets relying on an
113  * image as the building block of its visuals.
114  */
115
116 typedef struct _Elm_Image_Smart_Class
117 {
118    Elm_Widget_Smart_Class base; /**< Base Elementary widget class struct, since we're inheriting from it */
119
120    int                    version; /**< Version of this smart class definition */
121
122    void                 (*sizing_eval)(Evas_Object *obj); /* 'Virtual' function on evalutating the object's final geometry */
123    Eina_Bool            (*memfile_set)(Evas_Object *obj,
124                                        const void *img,
125                                        size_t size,
126                                        const char *format,
127                                        const char *key); /* 'Virtual' function on setting the image content on the object via a memory buffer */
128    Eina_Bool            (*file_set)(Evas_Object *obj,
129                                     const char *file,
130                                     const char *key); /* 'Virtual' function on setting the image content on the object via a file. It may be a direct image, an EET-encoded image or an Edje file. They @a key argument will be used for the last two cases mentioned (@c NULL must be used on the first). Beware that the Edje case will only be detected by an @c "edj" extension on the file name. */
131    void                 (*file_get)(const Evas_Object *obj,
132                                     const char **file,
133                                     const char **key); /* 'Virtual' function on retrieving back the image object's file path and key */
134
135    Evas_Object        *(*image_object_get)(const Evas_Object *obj); /* 'Virtual' function on retrieving the object's internal image file, which may me an Evas image or an Edje file */
136
137    void                 (*size_get)(const Evas_Object *obj,
138                                     int *w,
139                                     int *h); /* 'Virtual' function on retrieving the size of the object's internal image. */
140
141    void                 (*preload_set)(Evas_Object *obj,
142                                        Eina_Bool disable); /* 'Virtual' function on enabling/disabling pre-loading for the object's image data. */
143    void                 (*fill_inside_set)(Evas_Object *obj,
144                                            Eina_Bool fill_inside); /* 'Virtual' function on how to resize the object's internal image, when maintaining a given aspect ratio -- leave blank spaces or scale to fill all space, with pixels out of bounds. */
145    Eina_Bool            (*fill_inside_get)(const Evas_Object *obj); /* 'Virtual' function on retrieving how the object's internal image is to be resized, when maintaining a given aspect ratio. */
146
147    void                 (*scale_set)(Evas_Object *obj,
148                                      double scale); /* 'Virtual' function on setting the scale for the object's image size (@c 1.0 meaning original size). */
149    double               (*scale_get)(const Evas_Object *obj); /* 'Virtual' function on retrieving the scale for the object's image size. */
150
151    void                 (*smooth_scale_set)(Evas_Object *obj,
152                                             Eina_Bool smooth); /* 'Virtual' function on setting whether the object's image should be scaled smoothly or not. */
153    Eina_Bool            (*smooth_scale_get)(const Evas_Object *obj); /* 'Virtual' function on retrieving whether the object's image is to scaled smoothly or not. */
154    void                 (*resize_up_set)(Evas_Object *obj,
155                                         Eina_Bool resize_up); /* 'Virtual' function on setting whether the object's image can be resized to a size greater than the original one. */
156    Eina_Bool            (*resize_up_get)(const Evas_Object *obj); /* 'Virtual' function on retrieving whether the object's image can be resized to a size greater than the original one. */
157    void                 (*resize_down_set)(Evas_Object *obj,
158                                         Eina_Bool resize_down); /* 'Virtual' function on setting whether the object's image can be resized to a size smaller than the original one. */
159    Eina_Bool            (*resize_down_get)(const Evas_Object *obj); /* 'Virtual' function on retrieving whether the object's image can be resized to a size smaller than the original one. */
160    void                 (*load_size_set)(Evas_Object *obj,
161                                          int size); /* 'Virtual' function on setting the object's image loading size (in pixels, applied to both axis). */
162    int                  (*load_size_get)(const Evas_Object *obj); /* 'Virtual' function on retrieving the object's image loading size. */
163
164    void                 (*orient_set)(Evas_Object *obj,
165                                       Elm_Image_Orient orient); /* 'Virtual' function on setting the object's image orientation. */
166    Elm_Image_Orient     (*orient_get)(const Evas_Object *obj); /* 'Virtual' function on retrieving the object's image orientation. */
167
168    void                 (*aspect_fixed_set)(Evas_Object *obj,
169                                             Eina_Bool fixed); /* 'Virtual' function on setting whether the original aspect ratio of the object's image should be kept if it's resized. */
170    Eina_Bool            (*aspect_fixed_get)(const Evas_Object *obj); /* 'Virtual' function on retrieving whether the original aspect ratio of the object's image is to be kept if it's resized. */
171
172    void                 (*edit_set)(Evas_Object *obj,
173                                     Eina_Bool edit,
174                                     Evas_Object *parent); /* 'Virtual' function on setting whether the object is a valid target/source for drag and drop actions. */
175    Eina_Bool            (*edit_get)(const Evas_Object *obj); /* 'Virtual' function on retrieving whether the object is a valid target/source for drag and drop actions. */
176 } Elm_Image_Smart_Class;
177
178 /**
179  * Base widget smart data extended with image instance data.
180  */
181 typedef struct _Elm_Image_Smart_Data Elm_Image_Smart_Data;
182 struct _Elm_Image_Smart_Data
183 {
184    Elm_Widget_Smart_Data base;
185
186    Evas_Object          *hit_rect;
187    Evas_Object          *img;
188    Evas_Object          *prev_img;
189
190    Evas_Coord            img_x, img_y, img_w, img_h;
191
192    int                   load_size;
193    double                scale;
194    Elm_Image_Orient      orient;
195
196    int                   frame_count;
197    int                   cur_frame;
198    double                frame_duration;
199
200    Eina_Bool             aspect_fixed : 1;
201    Eina_Bool             fill_inside : 1;
202    Eina_Bool             resize_down : 1;
203    Eina_Bool             preloading : 1;
204    Eina_Bool             resize_up : 1;
205    Eina_Bool             no_scale : 1;
206    Eina_Bool             smooth : 1;
207    Eina_Bool             show : 1;
208    Eina_Bool             edit : 1;
209    Eina_Bool             edje : 1;
210    Eina_Bool             anim : 1;
211    Eina_Bool             play : 1;
212
213    Ecore_Timer          *anim_timer;
214 };
215
216 /**
217  * @}
218  */
219
220 EAPI extern const char ELM_IMAGE_SMART_NAME[];
221 EAPI const Elm_Image_Smart_Class *elm_image_smart_class_get(void);
222
223 #define ELM_IMAGE_DATA_GET(o, sd) \
224   Elm_Image_Smart_Data * sd = evas_object_smart_data_get(o)
225
226 #define ELM_IMAGE_DATA_GET_OR_RETURN(o, ptr)         \
227   ELM_IMAGE_DATA_GET(o, ptr);                        \
228   if (!ptr)                                          \
229     {                                                \
230        CRITICAL("No widget data for object %p (%s)", \
231                 o, evas_object_type_get(o));         \
232        return;                                       \
233     }
234
235 #define ELM_IMAGE_DATA_GET_OR_RETURN_VAL(o, ptr, val) \
236   ELM_IMAGE_DATA_GET(o, ptr);                         \
237   if (!ptr)                                           \
238     {                                                 \
239        CRITICAL("No widget data for object %p (%s)",  \
240                 o, evas_object_type_get(o));          \
241        return val;                                    \
242     }
243
244 #define ELM_IMAGE_CHECK(obj)                                                 \
245   if (!obj || !elm_widget_type_check((obj), ELM_IMAGE_SMART_NAME, __func__)) \
246     return
247
248 #endif