2 * Copyright (c) 2013 Samsung Electronics Co., Ltd.
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.
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.
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.
22 * @brief EailBubble implementation
25 #include <Elementary.h>
27 #include "eail_bubble.h"
28 #include "eail_utils.h"
30 static void atk_action_interface_init(AtkActionIface *iface);
31 static void atk_text_interface_init(AtkTextIface *iface);
34 * @brief Definition of EailBubble type
36 G_DEFINE_TYPE_WITH_CODE(EailBubble,
39 G_IMPLEMENT_INTERFACE(ATK_TYPE_TEXT,
40 atk_text_interface_init)
41 G_IMPLEMENT_INTERFACE(ATK_TYPE_ACTION,
42 atk_action_interface_init));
45 * Implementation of the *AtkObject* interface
49 * @brief EailBubble object initialization
51 * @param obj EailBubble instance
52 * @param data user set additional initialization data
55 eail_bubble_initialize(AtkObject *obj, gpointer data)
57 ATK_OBJECT_CLASS(eail_bubble_parent_class)->initialize(obj, data);
59 obj->role = ATK_ROLE_FILLER;
63 * @brief Class destructor
65 * @param object GObject instance
68 eail_bubble_finalize(GObject *object)
70 EailBubble *bubble = EAIL_BUBBLE(object);
72 if (bubble->click_description) free(bubble->click_description);
74 G_OBJECT_CLASS(eail_bubble_parent_class)->finalize(object);
78 * @brief EailBubble instance initialization
80 * @param bubble EailBubble instance
83 eail_bubble_init(EailBubble *bubble)
85 bubble->click_description = NULL;
89 * @brief Gets the list of widget's accessible children
91 * @param widget EailWidget instance
93 * @return Eina_List representing the list of accessible children
94 * or NULL if widget has no children
97 eail_bubble_get_widget_children(EailWidget *widget)
99 Eina_List *list = NULL;
100 Evas_Object *child, *obj;
102 obj = eail_widget_get_widget(EAIL_WIDGET(widget));
106 child = elm_object_part_content_get(obj, "default");
107 if (child && elm_object_widget_check(child))
108 list = eina_list_append(list, child);
110 child = elm_object_part_content_get(obj, "icon");
111 if (child && elm_object_widget_check(child))
112 list = eina_list_append(list, child);
119 * @brief GObject type initialization function
121 * @param klass EailBubbleClass instance
124 eail_bubble_class_init(EailBubbleClass *klass)
126 AtkObjectClass *atk_class = ATK_OBJECT_CLASS(klass);
127 EailWidgetClass *widget_class = EAIL_WIDGET_CLASS(klass);
128 GObjectClass *gobject_class = G_OBJECT_CLASS(klass);
130 atk_class->initialize = eail_bubble_initialize;
131 widget_class->get_widget_children = eail_bubble_get_widget_children;
132 gobject_class->finalize = eail_bubble_finalize;
136 * Implementation of the *AtkAction* interface
140 * @brief Gets the number of accessible actions available on the object
142 * Implementation of get_n_actions from AtkAction interface.
144 * @param action EailBubble instance
146 * @returns integer representing the number of available actions
149 eail_bubble_n_actions_get(AtkAction *action)
155 * @brief Gets the description string of the specified action
157 * Implementation of get_description from AtkAction interface.
159 * @param action EailBubble instance
160 * @param i action index
162 * @return string representing the specified action's description
165 eail_bubble_description_get(AtkAction *action,
169 const char *action_description;
171 bubble = EAIL_BUBBLE(action);
172 if (!bubble) return NULL;
177 action_description = bubble->click_description;
180 action_description = NULL;
184 return action_description;
188 * @brief Sets a description of the specified action of the object
190 * Implementation of set_description from AtkAction interface.
192 * @param action AtkAction instance
193 * @param i action index
194 * @param description action description
196 * @return TRUE on success, FALSE otherwise
199 eail_bubble_description_set(AtkAction *action,
201 const char *description)
206 bubble = EAIL_BUBBLE(action);
207 if (!bubble) return FALSE;
212 value = &bubble->click_description;
222 *value = g_strdup(description);
230 * @brief Gets the name string of the specified action
232 * Implementation of get_name from AtkAction interface.
234 * @param action AtkAction instance
235 * @param i action index
237 * @return string representing the specified action's name
240 eail_bubble_action_name_get(AtkAction *action,
243 const char* action_name;
248 action_name = "click";
259 * @brief Performs the specified action on the object
261 * Implementation of do_action from AtkAction interface.
263 * @param action AtkAction instance
264 * @param i action index
266 * @return TRUE on success, FALSE otherwise
269 eail_bubble_do_action(AtkAction *action,
274 widget = eail_widget_get_widget(EAIL_WIDGET(action));
275 if (!widget) return FALSE;
277 if ((elm_object_disabled_get(widget)) || (!evas_object_visible_get(widget)))
280 const char *action_name = atk_action_get_name(action, i);
281 if (!action_name) return FALSE;
283 evas_object_smart_callback_call(widget, "clicked", NULL);
289 * @brief AtkAction interface initializer
291 * @param iface action interface to be filled
294 atk_action_interface_init(AtkActionIface *iface)
296 g_return_if_fail(iface != NULL);
298 iface->get_n_actions = eail_bubble_n_actions_get;
299 iface->get_description = eail_bubble_description_get;
300 iface->set_description = eail_bubble_description_set;
301 iface->get_name = eail_bubble_action_name_get;
302 iface->do_action = eail_bubble_do_action;
307 * @brief Helper func to get Textblock form bubble widget
309 * @param text AtkText instance
310 * @returns Textblock part of bubble widget
312 static const Evas_Object *
313 _eail_get_textblock(AtkText *text)
315 Evas_Object *widget= NULL;
316 const Evas_Object *textblock = NULL;
317 Evas_Object *label = NULL;
318 Evas_Object *label_edje_layer = NULL;
319 Evas_Object *bubble_edje_layer = NULL;
321 widget = eail_widget_get_widget(EAIL_WIDGET(text));
322 if (!widget) return NULL;
324 bubble_edje_layer = elm_layout_edje_get(widget);
325 if (!bubble_edje_layer) return NULL;
327 label= edje_object_part_swallow_get(bubble_edje_layer, "elm.swallow.content");
328 if (!label) return NULL;
330 label_edje_layer = elm_layout_edje_get(label);
331 if (!label_edje_layer) return NULL;
333 textblock = edje_object_part_object_get(label_edje_layer, "elm.text");
334 if (!textblock) return NULL;
340 * @brief Gets text bounded by start_offset and end_offset
342 * Use g_free() to free the returned string
344 * @param text AtkText instance
345 * @param start_offset start position
346 * @param end_offset end position, -1 for the end of the string
347 * @return string containing text from start_offset up to, but not including
351 eail_bubble_get_text(AtkText *text,
355 gchar *string = NULL;
356 Evas_Object *widget = eail_widget_get_widget(EAIL_WIDGET(text));
357 Evas_Object *label = NULL;
361 label = elm_object_content_get(widget);
364 string = (gchar *)elm_object_text_get(label);
366 return eail_get_substring(string, start_offset, end_offset);
370 * @brief Gets the character at offset
372 * @param text AtkText instance
373 * @param offset character offset
374 * @return char representing the character at offset
377 eail_bubble_get_character_at_offset(AtkText *text,
380 gunichar character = '\0';
381 Evas_Object *widget = eail_widget_get_widget(EAIL_WIDGET(text));
382 Evas_Object *label = NULL;
387 label = elm_object_content_get(widget);
390 character = g_utf8_get_char(
391 g_utf8_offset_to_pointer(elm_object_text_get(label), offset));
397 * @brief Gets the text's length
399 * @param text AtkText instance
400 * @return integer representing the text length
403 eail_bubble_get_character_count(AtkText *text)
406 const gchar *string_text = NULL;
408 Evas_Object *widget = eail_widget_get_widget(EAIL_WIDGET(text));
409 Evas_Object *label = NULL;
411 if (!widget) return count;
413 label = elm_object_content_get(widget);
414 if (!label) return count;
416 string_text = elm_object_text_get(label);
417 if (!string_text) return count;
419 count = g_utf8_strlen(string_text, -1);
426 * @brief Get the bounding box containing the glyph
427 * representing the character at a particular text offset.
429 * @param text AtkText instance
430 * @param offset The offset of the text character for which
431 * bounding information is required.
432 * @param x Pointer for the x cordinate of the bounding box
433 * @param y Pointer for the y cordinate of the bounding box
434 * @param width Pointer for the width of the bounding box
435 * @param height Pointer for the height of the bounding box
436 * @param coords specify whether coordinates are relative to the
437 * screen or widget window
441 eail_bubble_get_character_extents(AtkText *text,
450 const Evas_Object *textblock = NULL;
451 Evas_Textblock_Cursor *cur = NULL;
453 Evas_Object *widget = eail_widget_get_widget(EAIL_WIDGET(text));
456 textblock = _eail_get_textblock(text);
457 if (!textblock) return;
459 cur = evas_object_textblock_cursor_new(textblock);
462 evas_textblock_cursor_pos_set(cur, offset);
464 result = evas_textblock_cursor_char_geometry_get(cur, x, y, width, height);
466 evas_textblock_cursor_free(cur);
468 if (-1 == result) return;
470 if (coords == ATK_XY_SCREEN)
473 Ecore_Evas *ee= ecore_evas_ecore_evas_get(evas_object_evas_get(widget));
475 ecore_evas_geometry_get(ee, &ee_x, &ee_y, NULL, NULL);
482 * @brief Gets the specified text after offset
484 * Use g_free() to free the returned string.
486 * @param text AtkText instance
487 * @param offset character offset
488 * @param boundary_type AtkTextBoundary instance
489 * @param [out] start_offset start offset of the returned string
490 * @param [out] end_offset offset of the first character after the returned
492 * @returns newly allocated string containing the text after offset bounded
493 * by the specified boundary_type
496 eail_bubble_get_text_after_offset(AtkText *text,
498 AtkTextBoundary boundary_type,
502 const Evas_Object *textblock;
504 textblock = _eail_get_textblock(text);
505 if (!textblock) return NULL;
507 return eail_get_text_after(textblock, offset, boundary_type, start_offset,
513 * @brief Gets the specified text at offset
515 * Use g_free() to free the returned string.
517 * @param text AtkText instance
518 * @param offset character offset
519 * @param boundary_type AtkTextBoundary instance
520 * @param [out] start_offset start offset of the returned string
521 * @param [out] end_offset offset of the first character after the returned
523 * @returns newly allocated string containing the text after offset bounded
524 * by the specified boundary_type
527 eail_bubble_get_text_at_offset(AtkText *text,
529 AtkTextBoundary boundary_type,
533 const Evas_Object *textblock;
535 textblock = _eail_get_textblock(text);
536 if (!textblock) return NULL;
538 return eail_get_text_at(textblock, offset, boundary_type, start_offset,
543 * @brief Gets the specified text before offset
545 * Use g_free() to free the returned string.
547 * @param text AtkText instance
548 * @param offset character offset
549 * @param boundary_type AtkTextBoundary instance
550 * @param [out] start_offset start offset of the returned string
551 * @param [out] end_offset offset of the first character after the returned
553 * @returns newly allocated string containing the text after offset bounded
554 * by the specified boundary_type
557 eail_bubble_get_text_before_offset(AtkText *text,
559 AtkTextBoundary boundary_type,
563 const Evas_Object *textblock;
565 textblock = _eail_get_textblock(text);
566 if (!textblock) return NULL;
568 return eail_get_text_before(textblock, offset, boundary_type, start_offset,
573 * @brief Gets the offset of the character located at coordinates x and y.
574 * x and y are interpreted as being relative to the screen or this
575 * widget's window depending on coords.
577 * @param text AtkText instance
578 * @param screen x-position of character
579 * @param screen y-position of character
580 * @param specify whether coordinates are relative to the screen or widget window
582 * @returns the offset to the character which is located at the specified x and y coordinates.
585 eail_bubble_get_offset_at_point(AtkText *text,
591 const Evas_Object *textblock = NULL;
592 Evas_Textblock_Cursor *cur = NULL;
594 Evas_Object *widget = eail_widget_get_widget(EAIL_WIDGET(text));
596 if (!widget) return -1;
598 textblock = _eail_get_textblock(text);
599 if (!textblock) return -1;
601 cur = evas_object_textblock_cursor_new(textblock);
603 if (coords == ATK_XY_SCREEN)
606 Ecore_Evas *ee= ecore_evas_ecore_evas_get(evas_object_evas_get(widget));
607 ecore_evas_geometry_get(ee, &ee_x, &ee_y, NULL, NULL);
612 evas_textblock_cursor_char_coord_set( cur, x, y);
613 result = evas_textblock_cursor_pos_get( cur );
614 evas_textblock_cursor_free(cur);
621 * @brief Initializes AtkTextIface interface
623 * @param iface AtkTextIface instance
626 atk_text_interface_init(AtkTextIface *iface)
628 iface->get_text = eail_bubble_get_text;
629 iface->get_character_at_offset = eail_bubble_get_character_at_offset;
630 iface->get_character_count = eail_bubble_get_character_count;
631 iface->get_character_extents = eail_bubble_get_character_extents;
632 iface->get_text_after_offset = eail_bubble_get_text_after_offset;
633 iface->get_text_at_offset = eail_bubble_get_text_at_offset;
634 iface->get_text_before_offset = eail_bubble_get_text_before_offset;
635 iface->get_offset_at_point = eail_bubble_get_offset_at_point;