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.
21 * @file eail_multibuttonentry.c
22 * @brief EailMultibuttonentry implementation
25 #include <Elementary.h>
27 #include "eail_multibuttonentry.h"
28 #include "eail_factory.h"
29 #include "eail_item_parent.h"
30 #include "eail_priv.h"
31 #include "eail_utils.h"
32 #include "eail_clipboard.h"
34 static void eail_item_parent_interface_init(EailItemParentIface *iface);
35 static void atk_editable_text_interface_init(AtkEditableTextIface *iface);
36 static void atk_text_interface_init(AtkTextIface *iface);
39 * @brief EailMultibuttonentry type definition
41 G_DEFINE_TYPE_WITH_CODE(EailMultibuttonentry,
42 eail_multibuttonentry,
43 EAIL_TYPE_ACTION_WIDGET,
44 G_IMPLEMENT_INTERFACE(ATK_TYPE_TEXT,
45 atk_text_interface_init)
46 G_IMPLEMENT_INTERFACE(ATK_TYPE_EDITABLE_TEXT,
47 atk_editable_text_interface_init)
48 G_IMPLEMENT_INTERFACE(EAIL_TYPE_ITEM_PARENT,
49 eail_item_parent_interface_init));
52 * @brief Checks if content get is supported
54 * Implementation of EailItemParent->is_content_get_supported callback.
56 * @param parent EailItemParent instance
57 * @param item EailItem instance
58 * @returns always FALSE
61 eail_multibuttonentry_content_get_support(EailItemParent *parent,
68 * @brief Gets the name of a multibuttonentry's child
70 * Implementation of get_item_name callback of EailItemParent interface.
72 * @param parent EailItemParent instance representing a multibuttonentry
73 * @param item Multibuttonentry EailItem instance representing a child
75 * @returns string representing the name of the child
78 eail_multibuttonentry_item_name_get(EailItemParent *parent, EailItem *item)
80 Elm_Object_Item *it = eail_item_get_item(item);
81 /*that will work only for default theme*/
84 return elm_object_item_part_text_get(it, NULL);
88 * @brief EailItemParent interface initializer
90 * Initialization of callbacks used by EailItemParent interface.
92 * @param iface EailItemParentIface instance
95 eail_item_parent_interface_init(EailItemParentIface *iface)
97 iface->is_content_get_supported = eail_multibuttonentry_content_get_support;
98 iface->get_item_name = eail_multibuttonentry_item_name_get;
102 * @brief Helper function for getting multibuttonentry text
104 * @param text an AtkText (EailMultibutton object)
106 * @return string representation of multibutton entry text
109 _eail_multibuttonentry_get_entry_string(AtkText *text)
111 const gchar *string = NULL;
112 Evas_Object *widget = eail_widget_get_widget(EAIL_WIDGET(text));
113 Evas_Object *entry = elm_multibuttonentry_entry_get(widget);
116 string = elm_entry_entry_get(entry);
118 /* if entry string is empty then trying to return "guide" part*/
119 if (!string || 0 == g_strcmp0(string, ""))
121 /* If there are some children of widget, then it means that guide
122 * is not visible. So returning guide as text only if no children
124 if (!elm_multibuttonentry_items_get(widget))
125 string = elm_object_part_text_get(widget, "guide");
132 * @brief Gets text bounded by start_offset and end_offset
134 * Use g_free() to free the returned string.
136 * @param text AtkText instance
137 * @param start_offset start position
138 * @param end_offset end position or -1 for the end of the string
139 * @return string containing text from start_offset up to, but not including
143 eail_multibuttonentry_get_text(AtkText *text,
147 const gchar *string = NULL;
149 string = _eail_multibuttonentry_get_entry_string(text);
151 return eail_get_substring(string, start_offset, end_offset);
155 * @brief Gets the character at offset
157 * @param text AtkText instance
158 * @param offset offset to obtain the character from
159 * @return char representing the character at given offset
162 eail_multibuttonentry_get_character_at_offset(AtkText *text,
165 gunichar character = '\0';
167 character = g_utf8_get_char(
168 g_utf8_offset_to_pointer
169 (_eail_multibuttonentry_get_entry_string(text), offset));
175 * @brief Gets the length of text
177 * @param text AtkText instance
178 * @return integer representing text's length
181 eail_multibuttonentry_get_character_count(AtkText *text)
184 const gchar *string_text = NULL;
186 string_text = _eail_multibuttonentry_get_entry_string(text);
187 if (!string_text) return count;
189 count = g_utf8_strlen(string_text, -1);
195 * @brief Gets caret offset
197 * @param text an AtkText
198 * @return caret offset
201 eail_multibuttonentry_get_caret_offset(AtkText *text)
206 widget = eail_widget_get_widget(EAIL_WIDGET(text));
210 entry = elm_multibuttonentry_entry_get(widget);
214 return elm_entry_cursor_pos_get(entry);
218 * @brief Sets offset for caret
220 * Implementation of AtkTextIface->set_caret_offset callback
222 * Sets the caret (cursor) position to the specified offset.
224 * @param text an AtkText
225 * @param offset starting position
227 * @returns TRUE if success, FALSE otherwise.
230 eail_multibuttonentry_set_caret_offset (AtkText *text,
236 widget = eail_widget_get_widget(EAIL_WIDGET(text));
240 entry = elm_multibuttonentry_entry_get(widget);
244 elm_entry_cursor_pos_set(entry,offset);
250 * @brief Get the bounding box containing the glyph
251 * representing the character at a particular text offset.
253 * @param text AtkText instance
254 * @param offset The offset of the text character for which
255 * bounding information is required.
256 * @param x Pointer for the x cordinate of the bounding box
257 * @param y Pointer for the y cordinate of the bounding box
258 * @param width Pointer for the width of the bounding box
259 * @param height Pointer for the height of the bounding box
260 * @param coords specify whether coordinates are relative to the
261 * screen or widget window
265 eail_multibuttonentry_get_character_extents(AtkText *text,
274 Evas_Object *textblock = NULL;
275 Evas_Textblock_Cursor *cur = NULL;
276 Evas_Object *entry = NULL;
278 Evas_Object *widget = eail_widget_get_widget(EAIL_WIDGET(text));
282 entry = elm_multibuttonentry_entry_get(widget);
286 textblock = elm_entry_textblock_get(entry);
287 cur = evas_object_textblock_cursor_new(textblock);
288 evas_textblock_cursor_pos_set(cur, offset);
290 result = evas_textblock_cursor_char_geometry_get(cur, x, y, width, height);
292 evas_textblock_cursor_free(cur);
294 if (-1 == result) return;
296 if (coords == ATK_XY_SCREEN)
299 Ecore_Evas *ee= ecore_evas_ecore_evas_get(evas_object_evas_get(widget));
301 ecore_evas_geometry_get(ee, &ee_x, &ee_y, NULL, NULL);
308 * @brief Gets the offset of the character located at coordinates
309 * x and y. x and y are interpreted as being relative to the
310 * screen or this widget's window depending on coords.
312 * @param text AtkText instance
313 * @param x screen x-position of character
314 * @param y screen y-position of character
315 * @param coords specify whether coordinates are relative to the
316 * screen or widget window
318 * @returns the offset to the character which is located at the
319 * specified x and y coordinates.
322 eail_multibuttonentry_get_offset_at_point(AtkText *text,
327 Eina_Bool result = EINA_FALSE;
328 Evas_Object *textblock = NULL;
329 Evas_Textblock_Cursor *cur = NULL;
332 Evas_Object *entry = NULL;
333 Evas_Object *widget = eail_widget_get_widget(EAIL_WIDGET(text));
335 if (!widget) return offset;
337 entry = elm_multibuttonentry_entry_get(widget);
339 if (!entry) return offset;
341 if (coords == ATK_XY_SCREEN)
344 Ecore_Evas *ee= ecore_evas_ecore_evas_get(evas_object_evas_get(entry));
346 ecore_evas_geometry_get(ee, &ee_x, &ee_y, NULL, NULL);
351 textblock = elm_entry_textblock_get(entry);
352 if (!textblock) return offset;
354 cur = evas_object_textblock_cursor_new(textblock);
355 if (!cur) return offset;
356 result = evas_textblock_cursor_char_coord_set(cur, x, y);
358 if (result == EINA_FALSE)
360 evas_textblock_cursor_free(cur);
364 offset = evas_textblock_cursor_pos_get(cur);
365 evas_textblock_cursor_free(cur);
371 * @brief Adds a selection bounded by the specified offsets
373 * @param text AtkText instance
374 * @param start_offset start position of the selection
375 * @param end_offset offset of the first character after selection
376 * @returns TRUE on success, FALSE otherwise
379 eail_multibuttonentry_add_selection(AtkText *text,
386 widget = eail_widget_get_widget(EAIL_WIDGET(text));
390 entry = elm_multibuttonentry_entry_get(widget);
394 elm_entry_cursor_pos_set(entry, start_offset);
395 elm_entry_cursor_selection_begin(entry);
396 elm_entry_cursor_pos_set(entry, end_offset);
397 elm_entry_cursor_selection_end(entry);
399 EAIL_MULTIBUTTONENTRY(text)->selection_start = start_offset;
400 EAIL_MULTIBUTTONENTRY(text)->selection_end = end_offset;
406 * @brief Removes text selection
408 * This widget supports only one selection
409 * so selection_num should always be 0.
411 * @param text AtkText instance
412 * @param selection_num selection number
413 * @return TRUE on success, FALSE otherwise
416 eail_multibuttonentry_remove_selection(AtkText *text,
422 widget = eail_widget_get_widget(EAIL_WIDGET(text));
426 entry = elm_multibuttonentry_entry_get(widget);
430 if (selection_num != 0 || !elm_entry_selection_get(entry))
433 elm_entry_select_none(entry);
434 EAIL_MULTIBUTTONENTRY(text)->selection_start = 0;
435 EAIL_MULTIBUTTONENTRY(text)->selection_end = 0;
441 * @brief Sets text selection for multibuttonentry
443 * This widget supports only one selection
444 * so selection_num should always be 0.
446 * @param text AtkText instance
447 * @param selection_num selection number
448 * @param start_pos start position of the selected region
449 * @param end_pos end position of the selected region
451 * @returns TRUE on success, FALSE otherwise
454 eail_multibuttonentry_set_selection(AtkText *text,
459 if (0 != selection_num)
462 return eail_multibuttonentry_add_selection(text, start_pos, end_pos);
466 * @brief Gets text selection from multibuttonentry
468 * Use g_free() to free the returned string.
470 * This widget supports only one selection
471 * so selection_num should always be 0.
473 * @param text AtkText instance
474 * @param selection_num selection number
475 * @param start_offset start position of the selected region
476 * @param end_offset end position of the selected region
478 * @returns newly allocated string containing the selected text
481 eail_multibuttonentry_get_selection(AtkText *text,
486 const char* selection;
490 if (0 != selection_num)
493 widget = eail_widget_get_widget(EAIL_WIDGET(text));
497 entry = elm_multibuttonentry_entry_get(widget);
501 selection = elm_entry_selection_get(entry);
504 *start_offset = EAIL_MULTIBUTTONENTRY(text)->selection_start;
505 *end_offset = EAIL_MULTIBUTTONENTRY(text)->selection_end;
506 return g_strdup(selection);
514 * @brief Gets the number of selected text regions
516 * Only one selection is supported by this widget
517 * so the returned value is 0 or 1.
519 * @param text AtkText instance
520 * @returns integer representing the number of
521 * selected text regions
524 eail_multibuttonentry_get_n_selections(AtkText *text)
529 widget = eail_widget_get_widget(EAIL_WIDGET(text));
533 entry = elm_multibuttonentry_entry_get(widget);
537 if (elm_entry_selection_get(entry))
544 * @brief Gets the specified text after offset
546 * Use g_free() to free the returned string.
548 * @param text AtkText instance
549 * @param offset character offset
550 * @param boundary_type AtkTextBoundary instance
551 * @param [out] start_offset start offset of the returned string
552 * @param [out] end_offset offset of the first character after the returned
554 * @returns newly allocated string containing the text after offset bounded
555 * by the specified boundary_type
558 eail_multibuttonentry_get_text_after_offset(AtkText *text,
560 AtkTextBoundary boundary_type,
565 Evas_Object *textblock;
566 Evas_Object *entry = NULL;
568 widget = eail_widget_get_widget(EAIL_WIDGET(text));
569 if (!widget) return NULL;
571 entry = elm_multibuttonentry_entry_get(widget);
572 if (!entry) return NULL;
574 textblock = elm_entry_textblock_get(entry);
576 return eail_get_text_after(textblock, offset, boundary_type, start_offset,
582 * @brief Gets the specified text at offset
584 * Use g_free() to free the returned string.
586 * @param text AtkText instance
587 * @param offset character offset
588 * @param boundary_type AtkTextBoundary instance
589 * @param [out] start_offset start offset of the returned string
590 * @param [out] end_offset offset of the first character after the returned
592 * @returns newly allocated string containing the text after offset bounded
593 * by the specified boundary_type
596 eail_multibuttonentry_get_text_at_offset(AtkText *text,
598 AtkTextBoundary boundary_type,
603 Evas_Object *textblock;
604 Evas_Object *entry = NULL;
606 widget = eail_widget_get_widget(EAIL_WIDGET(text));
607 if (!widget) return NULL;
609 entry = elm_multibuttonentry_entry_get(widget);
610 if (!entry) return NULL;
612 textblock = elm_entry_textblock_get(entry);
614 return eail_get_text_at(textblock, offset, boundary_type, start_offset,
619 * @brief Gets the specified text before offset
621 * Use g_free() to free the returned string.
623 * @param text AtkText instance
624 * @param offset character offset
625 * @param boundary_type AtkTextBoundary instance
626 * @param [out] start_offset start offset of the returned string
627 * @param [out] end_offset offset of the first character after the returned
629 * @returns newly allocated string containing the text after offset bounded
630 * by the specified boundary_type
633 eail_multibuttonentry_get_text_before_offset(AtkText *text,
635 AtkTextBoundary boundary_type,
640 Evas_Object *textblock;
641 Evas_Object *entry = NULL;
643 widget = eail_widget_get_widget(EAIL_WIDGET(text));
644 if (!widget) return NULL;
646 entry = elm_multibuttonentry_entry_get(widget);
647 if (!entry) return NULL;
649 textblock = elm_entry_textblock_get(entry);
651 return eail_get_text_before(textblock, offset, boundary_type, start_offset,
656 * @brief Creates an AtkAttributeSet which consists of the default values of
657 * attributes for the text
659 * The returned AtkAttributeSet should be freed by a call to
660 * atk_attribute_set_free().
662 * @param text AtkText instance
664 * @returns AtkAttributeSet which contains the default values of attributes
667 static AtkAttributeSet *
668 eail_multibuttonentry_get_default_attributes(AtkText *text)
670 AtkAttributeSet *at_set = NULL;
672 at_set = eail_utils_text_add_attribute
673 (at_set, ATK_TEXT_ATTR_WRAP_MODE,
674 atk_text_attribute_get_value(ATK_TEXT_ATTR_WRAP_MODE, 0));
676 at_set = eail_utils_text_add_attribute
677 (at_set, ATK_TEXT_ATTR_EDITABLE,
678 atk_text_attribute_get_value
679 (ATK_TEXT_ATTR_EDITABLE, TRUE));
685 * @brief Creates an AtkAttributeSet which consists of the attributes
686 * explicitly set at the position offset in the text
688 * start_offset and end_offset are set to the start and end of the range
689 * around offset where the attributes are invariant. Note that end_offset
690 * is the offset of the first character after the range.
692 * The returned AtkAttributeSet should be freed by a call to
693 * atk_attribute_set_free()
695 * @param text AtkText instance
696 * @param offset offset at which to get the attributes
697 * @param [out] start_offset start offset of the range
698 * @param [out] end_offset end offset of the range
700 * @returns AtkAttributeSet which contains the attributes explicitly set at
703 static AtkAttributeSet *
704 eail_multibuttonentry_get_run_attributes(AtkText *text,
709 AtkAttributeSet *at_set = NULL;
710 Evas_Object *widget = eail_widget_get_widget(EAIL_WIDGET(text));
711 Evas_Object *entry = NULL;
713 if (!widget || offset >= eail_multibuttonentry_get_character_count(text))
721 entry = elm_multibuttonentry_entry_get(widget);
722 if (!entry) return NULL;
726 *end_offset = eail_multibuttonentry_get_character_count(text);
728 /* NOTE: Elm_Wrap_Type value is in 100% compatible with ATK wrap modes, so
729 * no additional conversion is needed*/
730 Elm_Wrap_Type wrap_type = elm_entry_line_wrap_get(entry);
731 at_set = eail_utils_text_add_attribute
732 (at_set, ATK_TEXT_ATTR_WRAP_MODE,
733 atk_text_attribute_get_value
734 (ATK_TEXT_ATTR_WRAP_MODE, wrap_type));
736 Eina_Bool editable = elm_entry_editable_get(entry);
737 at_set = eail_utils_text_add_attribute
738 (at_set, ATK_TEXT_ATTR_EDITABLE,
739 atk_text_attribute_get_value
740 (ATK_TEXT_ATTR_EDITABLE, editable));
746 * @brief AktText initialization function
748 * @param iface AtkTextIface instance
751 atk_text_interface_init(AtkTextIface *iface)
753 iface->get_text = eail_multibuttonentry_get_text;
754 iface->get_character_at_offset = eail_multibuttonentry_get_character_at_offset;
755 iface->get_character_count = eail_multibuttonentry_get_character_count;
756 iface->get_caret_offset = eail_multibuttonentry_get_caret_offset;
757 iface->set_caret_offset = eail_multibuttonentry_set_caret_offset;
758 iface->get_character_extents = eail_multibuttonentry_get_character_extents;
759 iface->add_selection = eail_multibuttonentry_add_selection;
760 iface->remove_selection = eail_multibuttonentry_remove_selection;
761 iface->get_selection = eail_multibuttonentry_get_selection;
762 iface->set_selection = eail_multibuttonentry_set_selection;
763 iface->get_n_selections = eail_multibuttonentry_get_n_selections;
764 iface->get_text_after_offset = eail_multibuttonentry_get_text_after_offset;
765 iface->get_text_at_offset = eail_multibuttonentry_get_text_at_offset;
766 iface->get_text_before_offset = eail_multibuttonentry_get_text_before_offset;
767 iface->get_run_attributes = eail_multibuttonentry_get_run_attributes;
768 iface->get_default_attributes = eail_multibuttonentry_get_default_attributes;
769 iface->get_offset_at_point = eail_multibuttonentry_get_offset_at_point;
773 * @brief Sets text contents of text
775 * @param text AtkEditableText instance
776 * @param string new text to be set
779 eail_multibuttonentry_set_text_contents(AtkEditableText *text,
785 widget = eail_widget_get_widget(EAIL_WIDGET(text));
788 entry = elm_multibuttonentry_entry_get(widget);
791 if (elm_multibuttonentry_editable_get(widget))
792 elm_entry_entry_set(entry, string);
796 * @brief Copies text content from entry to clipboard
798 * @param text AtkEditableText instance
799 * @param start_pos index of copied text's first character
800 * @param end_pos index of last copied text's last character
803 eail_multibuttonentry_copy_text(AtkEditableText *text,
809 const char *entry_text;
813 widget = eail_widget_get_widget(EAIL_WIDGET(text));
816 entry = elm_multibuttonentry_entry_get(widget);
817 entry_text = elm_entry_entry_get(entry);
818 tmp = eail_get_substring(entry_text, start_pos, end_pos);
819 eail_clipboard_set_text(tmp);
824 * @brief Cuts text content from entry to clipboard
826 * @param text AtkEditableText instance
827 * @param start_pos index of cut text's first character
828 * @param end_pos index of cut text's last character
831 eail_multibuttonentry_cut_text(AtkEditableText *text,
837 const char *entry_text;
842 widget = eail_widget_get_widget(EAIL_WIDGET(text));
843 if (!widget || !elm_multibuttonentry_editable_get(widget)) return;
845 entry = elm_multibuttonentry_entry_get(widget);
846 entry_text = elm_entry_entry_get(entry);
847 tmp = eail_get_substring(entry_text, start_pos, end_pos);
848 eail_clipboard_set_text(tmp);
851 s = g_string_new(entry_text);
852 s = g_string_erase(s, start_pos, end_pos - start_pos);
854 elm_entry_entry_set(entry, s->str);
855 g_string_free(s, TRUE);
859 * @brief Pastes text content from clipboard into entry
861 * @param text AtkEditableText instance
862 * @param position index of pasted text's first character
865 eail_multibuttonentry_paste_text(AtkEditableText *text,
869 Evas_Object *entry = NULL;
873 widget = eail_widget_get_widget(EAIL_WIDGET(text));
874 if (!widget || !elm_multibuttonentry_editable_get(entry))
877 entry = elm_multibuttonentry_entry_get(widget);
878 s = g_string_new(elm_entry_entry_get(entry));
879 tmp = eail_clipboard_get_text();
880 s = g_string_insert(s, position, tmp);
881 elm_entry_entry_set(entry, s->str);
882 g_string_free(s, TRUE);
886 * @brief Deletes text between start_pos and end_pos but not
889 * @param text AtkEditableText instance
890 * @param start_pos start position
891 * @param end_pos end position
894 eail_multibuttonentry_delete_text(AtkEditableText *text,
902 widget = eail_widget_get_widget(EAIL_WIDGET(text));
903 if (!widget || !elm_multibuttonentry_editable_get(widget)) return;
905 entry = elm_multibuttonentry_entry_get(widget);
906 s = g_string_new(elm_entry_entry_get(entry));
907 s = g_string_erase(s, start_pos, end_pos-start_pos);
908 elm_entry_entry_set(entry, s->str);
909 g_string_free(s, TRUE);
913 * @brief Inserts text at the given position
915 * After the call it points at the position after the newly inserted text.
917 * @param text AtkEditableText instance
918 * @param string string to insert
919 * @param length string length
920 * @param [out] position position to insert the text
924 eail_multibuttonentry_insert_text(AtkEditableText *text,
933 widget = eail_widget_get_widget(EAIL_WIDGET(text));
934 if (!widget || !elm_multibuttonentry_editable_get(widget))
937 entry = elm_multibuttonentry_entry_get(widget);
938 s = g_string_new(elm_entry_entry_get(entry));
939 s = g_string_insert_len(s, *position, string, length);
940 elm_entry_entry_set(entry, s->str);
941 g_string_free(s, TRUE);
946 * @brief Initialization for AtkEditableTextIface interface
948 * Function called upon instance creation.
950 * It initializes AtkText interface
951 * implementation i.e hooks method pointers in the interface structure
952 * to the implementing class's implementation.
954 * @param iface AtkEditableTextIface instance
957 atk_editable_text_interface_init(AtkEditableTextIface *iface)
959 iface->set_text_contents = eail_multibuttonentry_set_text_contents;
960 iface->copy_text = eail_multibuttonentry_copy_text;
961 iface->cut_text = eail_multibuttonentry_cut_text;
962 iface->paste_text = eail_multibuttonentry_paste_text;
963 iface->delete_text = eail_multibuttonentry_delete_text;
964 iface->insert_text = eail_multibuttonentry_insert_text;
968 * @brief 'expand' action callback
970 * @param action AtkAction instance
971 * @param data user data passed to callback
973 * @returns TRUE on action success, FALSE otherwise
976 eail_multibuttonentry_action_expand_cb(AtkAction *action, void *data)
980 widget = eail_widget_get_widget(EAIL_WIDGET(action));
981 if (!widget) return FALSE;
983 if ((elm_object_disabled_get(widget)) || (!evas_object_visible_get(widget)))
986 if (elm_multibuttonentry_expanded_get(widget)) return FALSE;
988 elm_multibuttonentry_expanded_set(widget, EINA_TRUE);
989 atk_object_notify_state_change(ATK_OBJECT(action), ATK_STATE_EXPANDED, TRUE);
995 * @brief 'shrink' action callback
997 * @param action AtkAction instance
998 * @param data user data passed to callback
1000 * @returns TRUE on action success, FALSE otherwise
1003 eail_multibuttonentry_action_shrink_cb(AtkAction *action, void *data)
1005 Evas_Object *widget;
1007 widget = eail_widget_get_widget(EAIL_WIDGET(action));
1008 if (!widget) return FALSE;
1010 if ((elm_object_disabled_get(widget)) || (!evas_object_visible_get(widget)))
1013 if (!elm_multibuttonentry_expanded_get(widget)) return FALSE;
1015 elm_multibuttonentry_expanded_set(widget, EINA_FALSE);
1016 atk_object_notify_state_change(ATK_OBJECT(action), ATK_STATE_EXPANDED, FALSE);
1022 * @brief Registers multibuttonentry's actions
1024 * @param action_widget EailActionWidget instance
1026 static void eail_multibuttonentry_actions_init(EailActionWidget *action_widget)
1028 eail_action_widget_action_append(action_widget, "expand", NULL,
1029 eail_multibuttonentry_action_expand_cb);
1030 eail_action_widget_action_append(action_widget, "shrink", NULL,
1031 eail_multibuttonentry_action_shrink_cb);
1035 * @brief Handler for "item,added" event, used to notify about multibuttonentry
1038 * @param data passed to callback
1039 * @param obj object that raised event
1040 * @param event_info additional event info (item is passed here)
1043 eail_multibuttonentry_item_handle_added_event(void *data,
1047 Elm_Object_Item *item = (Elm_Object_Item *) event_info;
1048 AtkObject *atk_item = NULL, *atk_parent = NULL;
1050 atk_parent = ATK_OBJECT(data);
1051 if (!atk_parent) return;
1053 atk_item = eail_factory_get_item_atk_obj
1054 (item, ATK_ROLE_LABEL, atk_parent);
1056 if (!atk_item) return;
1058 eail_emit_children_changed_obj(TRUE, atk_parent, atk_item);
1062 * @brief Handler for "item,deleted" event, used to notify about
1063 * multibuttonentry content changes
1065 * @param data passed to callback
1066 * @param obj object that raised event
1067 * @param event_info additional event info (item is passed here)
1070 eail_multibuttonentry_item_handle_removed_event(void *data,
1074 Elm_Object_Item *item = (Elm_Object_Item *) event_info;
1075 AtkObject *atk_item = NULL, *atk_parent = NULL;
1077 atk_parent = ATK_OBJECT(data);
1078 if (!atk_parent) return;
1080 atk_item = eail_factory_get_item_atk_obj
1081 (item, ATK_ROLE_LABEL, atk_parent);
1083 if (!atk_item) return;
1085 eail_emit_children_changed_obj(FALSE, atk_parent, atk_item);
1086 atk_object_notify_state_change(atk_item, ATK_STATE_DEFUNCT, TRUE);
1088 DBG("Unregistering item from cache...");
1089 eail_factory_unregister_item_from_cache(item);
1093 * @brief handler for event which is raised when entry cusror position is being changed
1095 * @param data passed to callback
1096 * @param obj object that raised event
1097 * @param event_info additional event info
1100 _eail_multibuttonentry_handle_cursor_changed_event(void *data,
1104 g_signal_emit_by_name (ATK_OBJECT(data), "text_caret_moved",
1105 elm_entry_cursor_pos_get(obj));
1109 * @brief EailMultibuttonentry type initializer
1110 * @param obj AtkObject instance
1111 * @param data initialization data
1114 eail_multibuttonentry_initialize(AtkObject *obj, gpointer data)
1116 Evas_Object *nested_widget = NULL;
1117 ATK_OBJECT_CLASS(eail_multibuttonentry_parent_class)->initialize(obj, data);
1118 obj->role = ATK_ROLE_ENTRY;
1120 eail_multibuttonentry_actions_init(EAIL_ACTION_WIDGET(obj));
1122 nested_widget = eail_widget_get_widget(EAIL_WIDGET(obj));
1125 ERR("No evas object inside EailWidget was found");
1129 evas_object_smart_callback_add(nested_widget, "item,added",
1130 eail_multibuttonentry_item_handle_added_event, obj);
1131 evas_object_smart_callback_add(nested_widget, "item,deleted",
1132 eail_multibuttonentry_item_handle_removed_event, obj);
1133 evas_object_smart_callback_add(elm_multibuttonentry_entry_get(nested_widget),
1135 _eail_multibuttonentry_handle_cursor_changed_event, obj);
1139 * @brief EailMultibuttonentry instance initializer
1141 * @param multibuttonentry EailMultibuttonentry instance
1144 eail_multibuttonentry_init(EailMultibuttonentry *multibuttonentry)
1146 multibuttonentry->selection_start = 0;
1147 multibuttonentry->selection_end = 0;
1151 * @brief Gets obj's state set
1153 * The caller must unreference it when it is no longer needed.
1155 * @param obj AtkObject instance
1156 * @return AtkStateSet containing object's state set
1158 static AtkStateSet *
1159 eail_multibuttonentry_ref_state_set(AtkObject *obj)
1161 AtkStateSet *state_set;
1162 Evas_Object *widget;
1164 g_return_val_if_fail(EAIL_MULTIBUTTONENTRY(obj), NULL);
1166 widget = eail_widget_get_widget(EAIL_WIDGET(obj));
1167 state_set = ATK_OBJECT_CLASS(eail_multibuttonentry_parent_class)->ref_state_set(obj);
1169 if (!widget) return state_set;
1171 if (elm_multibuttonentry_expanded_get(widget))
1173 atk_state_set_add_state(state_set, ATK_STATE_EXPANDED);
1175 if (elm_multibuttonentry_editable_get(widget))
1176 atk_state_set_add_state(state_set, ATK_STATE_EDITABLE);
1180 atk_state_set_add_state(state_set, ATK_STATE_DEFAULT);
1187 * @brief Gets the list of multibuttonentry's items
1189 * @param multibuttonentry EailMultibuttonentry instance
1190 * @return Eina_List containing multibuttonentry's items
1192 static const Eina_List *
1193 eail_multibuttonentry_get_items(EailMultibuttonentry *multibuttonentry)
1195 Evas_Object *widget = eail_widget_get_widget(EAIL_WIDGET(multibuttonentry));
1196 if (!widget) return NULL;
1198 return elm_multibuttonentry_items_get(widget);
1202 * @brief Gets the number of accessible children of the accessible
1204 * @param obj AtkObject instance
1205 * @return integer representing the number of accessible children of the accessible
1208 eail_multibuttonentry_get_n_children(AtkObject *obj)
1211 const Eina_List *items;
1213 items = eail_multibuttonentry_get_items(EAIL_MULTIBUTTONENTRY(obj));
1214 n_items = eina_list_count(items);
1220 * @brief Gets a reference to the specified child of obj
1222 * The caller must unreference it when it is no longer needed.
1224 * @param obj AtkObject instance
1225 * @param i child index
1226 * @return AtkObject containing reference to the specified child of obj
1229 eail_multibuttonentry_ref_child(AtkObject *obj, gint i)
1231 const Eina_List *items;
1232 AtkObject *child = NULL;
1234 items = eail_multibuttonentry_get_items(EAIL_MULTIBUTTONENTRY(obj));
1235 if (eina_list_count(items) > i)
1237 child = eail_factory_get_item_atk_obj
1238 (eina_list_nth(items, i), ATK_ROLE_LABEL, obj);
1240 g_object_ref(child);
1243 ERR("Tried to ref child with index %d out of bounds!", i);
1249 * @brief EailMultibuttonentry class initializer
1251 * @param klass EailMultibuttonentryClass instance
1254 eail_multibuttonentry_class_init(EailMultibuttonentryClass *klass)
1256 AtkObjectClass *atk_class = ATK_OBJECT_CLASS(klass);
1258 atk_class->initialize = eail_multibuttonentry_initialize;
1259 atk_class->get_n_children = eail_multibuttonentry_get_n_children;
1260 atk_class->ref_child = eail_multibuttonentry_ref_child;
1261 atk_class->ref_state_set = eail_multibuttonentry_ref_state_set;