Initialize efl-assist
[platform/core/uifw/efl-assist.git] / src / include / efl_assist_events.h
1 /*
2  * Copyright (c) 2013 Samsung Electronics Co., Ltd All Rights Reserved
3  *
4  *  Licensed under the Apache License, Version 2.0 (the "License");
5  *  you may not use this file except in compliance with the License.
6  *  You may obtain a copy of the License at
7  *
8  *      http://www.apache.org/licenses/LICENSE-2.0
9  *
10  *  Unless required by applicable law or agreed to in writing, software
11  *  distributed under the License is distributed on an "AS IS" BASIS,
12  *  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13  *  See the License for the specific language governing permissions and
14  *  limitations under the License.
15  *
16  */
17
18 #ifndef __EFL_ASSIST_EVENTS_H__
19 #define __EFL_ASSIST_EVENTS_H__
20
21 #include <Elementary.h>
22
23 #ifdef __cplusplus
24 extern "C" {
25 #endif
26
27 /**
28  * @brief Convenient macro function that sends back key events to the popup
29  *        to be removed.
30  *
31  * @see   ea_object_event_callback_add()
32  */
33 static inline void
34 ea_popup_back_cb(void *data, Evas_Object *obj, void *event_info)
35 {
36    evas_object_del(obj);
37 }
38
39 /**
40  * @brief Convenient macro function that sends back key events to the ctxpopup
41  *        to be dismissed.
42  *
43  * @see   ea_object_event_callback_add()
44  */
45 static inline void
46 ea_ctxpopup_back_cb(void *data, Evas_Object *obj, void *event_info)
47 {
48    elm_ctxpopup_dismiss(obj);
49 }
50
51 /**
52  * @brief Convenient macro function that sends more key events to the naviframe
53  *        top item.
54  * @see   ea_object_event_callback_add()
55  */
56 static inline void
57 ea_naviframe_more_cb(void *data, Evas_Object *obj, void *event_info)
58 {
59    Elm_Object_Item *top = elm_naviframe_top_item_get(obj);
60    if (!top) return;
61    Evas_Object *more_btn = elm_object_item_part_content_get(top, "toolbar_more_btn");
62    if (more_btn)
63      evas_object_smart_callback_call(more_btn, "clicked", NULL);
64 }
65
66 /**
67  * @brief Convenient macro function that pop the naviframe item.
68  * @see   ea_object_event_callback_add()
69  */
70 static inline void
71 ea_naviframe_back_cb(void *data, Evas_Object *obj, void *event_info)
72 {
73    elm_naviframe_item_pop(obj);
74 }
75
76 /**
77  * Identifier of callbacks to be set for Ea events.
78  *
79  * @see ea_object_event_callback_add()
80  * @see ea_object_event_callback_del()
81  */
82 typedef enum _Ea_Callback_Type
83 {
84    EA_CALLBACK_BACK,
85    EA_CALLBACK_MORE,
86    EA_CALLBACK_LAST
87 } Ea_Callback_Type;
88
89 /** <Ea event callback function signature */
90 typedef void (*Ea_Event_Cb)(void *data, Evas_Object *obj, void *event_info);
91
92 /**
93  * Delete a callback function from an object.
94  *
95  * @param[in] obj Object to remove a callback from.
96  * @param[in] type The type of event that was triggering the callback.
97  * @param[in] func The function that was to be called when the event was
98  *            triggered
99  * @return    data The data pointer that was to be passed to the callback.
100  *
101  * @brief     This function removes the most recently added callback from the
102  *            object @p obj which was triggered by the type @p type and
103  *            was calling the function @p func when triggered. If the removal is
104  *            successful it will also return the data pointer that was passed to
105  *            ea_object_event_callback_add() when the callback was added to
106  *            the object. If not successful @c NULl will be returned.
107  *
108  * @see ea_object_event_callback_add()
109  */
110
111 EAPI void *ea_object_event_callback_del(Evas_Object *obj, Ea_Callback_Type type, Ea_Event_Cb);
112
113 /**
114  * Add (register) a callback function to a given evas object.
115  *
116  * @param[in] obj evas object.
117  * @param[in] type The type of event that will trigger the callback.
118  * @param[in] func The function to be called when the key event is triggered.
119  * @param[in] data The data pointer to be passed to @p func.
120  *
121  * @brief This function adds a function callback to an object when the key event
122  *        occurs on object @p obj. The key event on the object is only triggered
123  *        when the object is the most top in objects stack and visible. This
124  *        means, like the naviframe widget, if your application needs to have
125  *        the events based on the view but not focus, you can use this callback.
126  *
127  *        A callback function must have the Ea_Event_Cb prototype definition.
128  *        The first parameter (@p data) in this definition will have the same
129  *        value passed to ea_object_event_callback_add() as the @p data
130  *        parameter, at runtime. The second parameter @p obj is the evas object
131  *        on which event occurred. Finally, the third parameter @p event_info is
132  *        a pointer to a data structure that may or may not be passed to the
133  *        callback, depending on the event type that triggered the callback.
134  *        This is so because some events don't carry extra context with them,
135  *        but others do.
136  *
137  * @see ea_object_event_callback_del()
138  */
139
140 EAPI void ea_object_event_callback_add(Evas_Object *obj, Ea_Callback_Type type, Ea_Event_Cb func, void *data);
141
142 #ifdef __cplusplus
143 }
144 #endif
145
146 #endif /* __EFL_ASSIST_EVENTS_H__ */