Merge "custom eail widget implementation" into tizen
[platform/core/uifw/eail.git] / eail / eail_utils.h
1 /*
2  * Copyright (c) 2013 Samsung Electronics Co., Ltd.
3  *
4  * This library is free software; you can redistribute it and/or
5  * modify it under the terms of the GNU Lesser General Public
6  * License as published by the Free Software Foundation; either
7  * version 2 of the License, or (at your option) any later version.
8  *
9  * This library is distributed in the hope that it will be useful,
10  * but WITHOUT ANY WARRANTY; without even the implied warranty of
11  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
12  * Lesser General Public License for more details.
13  *
14  * You should have received a copy of the GNU Lesser General Public License
15  * along with this library; see the file COPYING.LIB.  If not, write to
16  * the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
17  * Boston, MA 02110-1301, USA.
18  */
19
20 /**
21  * @file eail_utils.h
22  *
23  * @brief Header for Eail Utility functions
24  */
25
26 #ifndef EAIL_UTILS_H
27 #define EAIL_UTILS_H
28
29 #include <glib.h>
30
31 #ifdef __cplusplus
32 extern "C" {
33 #endif
34
35 #define EAIL_STR_SCROLL_UP "scroll_up" /**< @brief String for 'scroll up'*/
36 #define EAIL_STR_SCROLL_DOWN "scroll_down" /**< @brief String for 'scroll down'*/
37 #define EAIL_STR_SCROLL_LEFT "scroll_left" /**< @brief String for 'scroll left'*/
38 #define EAIL_STR_SCROLL_RIGHT "scroll_right" /**< @brief String for 'scroll right'*/
39
40 #define float_epsilon 0.00001
41 #define float_equal(a,b) (fabs((a) - (b)) < float_epsilon)
42
43 /**
44  * @enum EAIL_SCROLL_TYPE Type of scroll direction
45  */
46 enum EAIL_SCROLL_TYPE
47 {
48    EAIL_SCROLL_TYPE_UP,/**< scroll 'up' direction */
49    EAIL_SCROLL_TYPE_DOWN,/**< scroll 'down' direction */
50    EAIL_SCROLL_TYPE_LEFT,/**< scroll 'left' direction */
51    EAIL_SCROLL_TYPE_RIGHT/**< scroll 'right' direction */
52 };
53
54 /**
55  * @brief Helper function gets substring from string
56  */
57 gchar *eail_get_substring(const gchar* string, gint start_offset, gint end_offset);
58
59 /**
60  * @brief Generic function for generating ref_state for Evas_Objects stored in
61  * ATK objects
62  *
63  */
64 AtkStateSet *eail_evas_obj_ref_state_set(Evas_Object *widget,
65                                          AtkStateSet *state_set);
66
67 /**
68  * @brief Generic function for grabbing focus on Evas_Object stored in ATK object
69  */
70 gboolean eail_evas_obj_grab_focus(Evas_Object *widget);
71
72 /**
73  * @brief Emulates mouse 'press' event at given coordinates
74  */
75 void eail_mouse_press_on_coords(Evas_Object *widget, int x, int y);
76
77 /**
78  * @brief Emulates mouse 'release' event at given coordinates
79  */
80 void eail_mouse_release_on_coords(Evas_Object *widget, int x, int y);
81
82 /**
83  * @brief Emulates mouse 'click' event at given coordinates
84  */
85 void eail_mouse_click_on_coords(Evas_Object *widget, int x, int y);
86
87 /**
88  * @brief Gets coordinates of center of given widget
89  */
90 void eail_get_coords_widget_center(Evas_Object *widget, int *x, int *y);
91
92 /**
93  * @brief Gets edje parts list for item
94  *
95  */
96 Eina_List *eail_get_edje_parts_for_item(Elm_Object_Item *item);
97
98 /**
99  * @brief Gets edje object for item
100  *
101  */
102 Evas_Object *eail_get_edje_obj_from_item(Elm_Object_Item *item);
103
104 /**
105  * @brief Gets text content from item (each text is put into field in Eina_List
106  * as const gchar*)
107  */
108 Eina_List *eail_item_get_content_strings(Elm_Object_Item *item);
109
110 /**
111  * @brief Scrolls screen to given direction
112  */
113 gboolean eail_handle_scroll(Evas_Object *widget,
114                             enum EAIL_SCROLL_TYPE type);
115
116 /**
117  * @brief Scrolls screen up
118  */
119 gboolean eail_action_scroll_up(Evas_Object *widget,
120                                void *data);
121
122 /**
123  * @brief Scrolls screen down
124  */
125 gboolean eail_action_scroll_down(Evas_Object *widget,
126                                  void *data);
127
128 /**
129  * @brief Scrolls screen left
130  */
131 gboolean eail_action_scroll_left(Evas_Object *widget,
132                                  void *data);
133
134 /**
135  * @brief Scrolls screen right
136  */
137 gboolean eail_action_scroll_right(Evas_Object *widget,
138                                   void *data);
139
140 /**
141  * @brief Emits signal for ATK Object
142  */
143 void eail_emit_atk_signal(AtkObject * atk_obj,
144                           const gchar *signal_name,
145                           GType object_type);
146
147 /**
148  * @brief Handler for selected event in for list-based content
149  */
150 void eail_list_item_handle_selected_event(void *data,
151                                           Evas_Object *obj,
152                                           void *event_info);
153
154 /**
155  * @brief Handler for unselected event for list-based content
156  */
157 void eail_list_item_handle_unselected_event(void *data,
158                                             Evas_Object *obj,
159                                             void *event_info);
160
161
162 /**
163  * @brief Gets raw evas object list for eail item
164  */
165 Eina_List *eail_get_raw_evas_obj_list_from_item(Elm_Object_Item *item);
166
167 /**
168  * @brief Helper function for emitting 'children changed' signal when needed
169  */
170 void eail_emit_children_changed(gboolean added,
171                                 AtkObject *atk_obj,
172                                 gint child_number);
173
174 /**
175  * @brief Helper function for emit children changed signal when needed (func
176  * version that takes object instead of index-number)
177  */
178 void eail_emit_children_changed_obj(gboolean added,
179                                     AtkObject *atk_obj,
180                                     AtkObject *changed_obj);
181
182 /**
183  * @brief Helper function to notify windows about focus changes of its children
184  */
185 void eail_notify_child_focus_changes(void);
186
187 /**
188  * @brief Helper function to get a slice of the text from textblock after offset
189  *
190  * Use g_free() to free the returned string.
191  *
192  * @param textblock Evas textblock
193  * @param offset character offset
194  * @param boundary_type AtkTextBoundary instance
195  * @param [out] start_offset start position of the returned text
196  * @param [out] end_offset end position of the returned text
197  * @returns newly allocated string containg a slice of text from textblock
198  */
199 gchar *
200 eail_get_text_after(const Evas_Object *textblock,
201                     gint offset,
202                     AtkTextBoundary boundary_type,
203                     gint *start_offset,
204                     gint *end_offset);
205 /**
206  * @brief Helper function to get a slice of the text from textblock at offset
207  *
208  * Use g_free() to free the returned string.
209  *
210  * @param textblock Evas textblock
211  * @param offset character offset
212  * @param boundary_type AtkTextBoundary instance
213  * @param [out] start_offset start position of the returned text
214  * @param [out] end_offset end position of the return text
215  * @returns newly allocated string containing a slice of text from textblock
216  */
217 gchar *
218 eail_get_text_at(const Evas_Object *textblock,
219                  gint offset,
220                  AtkTextBoundary boundary_type,
221                  gint *start_offset,
222                  gint *end_offset);
223 /**
224  * @brief Helper function to get a slice of the text from textblock before offset
225  *
226  * Use g_free() to free the returned string.
227  *
228  * @param textblock Evas textblock
229  * @param entry entry widget instance
230  * @param offset character offset
231  * @param boundary_type AtkTextBoundary instance
232  * @param [out] start_offset start position of the returned text
233  * @param [out] end_offset end position of the returned text
234  * @returns newly allocated string containing a slice of text from textblock
235  */
236 gchar *
237 eail_get_text_before(const Evas_Object *textblock,
238                      gint offset,
239                      AtkTextBoundary boundary_type,
240                      gint *start_offset,
241                      gint *end_offset);
242 /*
243  * @brief Helper function to add attribute to attribute set
244  *
245  * @param attrib_set AtkAttributeSet to add the attribute to
246  * @param attr AtkTextAttrribute to be added
247  * @param value attribute value
248  *
249  * Creates an AtkAttribute from attr and value, and adds it
250  * to attrib_set.
251  *
252  * @returns AtkAttributeSet containing set with added attribute
253  **/
254 AtkAttributeSet*
255 eail_utils_text_add_attribute(AtkAttributeSet *attrib_set,
256                               AtkTextAttribute attr,
257                               const gchar     *value);
258 #ifdef __cplusplus
259 }
260 #endif
261
262 #endif