ddd6d148f7acbaccc22b972466056fab94d72c90
[pkgs/u/ui-gadget.git] / include / ui-gadget.h
1 /*
2  * Copyright (c) 2000 - 2012 Samsung Electronics Co., Ltd All Rights Reserved
3  *
4  * This file is part of the UI Gadget
5  * Written by Jayoun Lee <airjany@samsung.com>, Jinwoo Nam <jwoo.nam@samsung.com>
6  *
7  * PROPRIETARY/CONFIDENTIAL
8  *
9  * This software is the confidential and proprietary information of
10  * SAMSUNG ELECTRONICS (Confidential Information).
11  * You shall not disclose such Confidential Information and shall
12  * use it only in accordance with the terms of the license agreement
13  * you entered into with SAMSUNG ELECTRONICS.  SAMSUNG make no
14  * representations or warranties about the suitability
15  * of the software, either express or implied, including but not
16  * limited to the implied warranties of merchantability, fitness for a particular purpose, or non-
17  * infringement. SAMSUNG shall not be liable for any damages suffered by licensee as
18  * a result of using, modifying or distributing this software or its derivatives.
19  *
20  */
21
22 #ifndef __UI_GADGET_H__
23 #define __UI_GADGET_H__
24
25 /**
26  * @file        ui-gadget.h
27  * @author      Wonguk Jeong <wonguk.jeong@samsung.com>
28  * @version     0.1
29  * @brief       This file contains the public API of the UI gadget library
30  */
31
32 /**
33  * @addtogroup APPLICATION_FRAMEWORK
34  * @{
35  *
36  * @defgroup    UI_Gadget UI gadget library
37  * @author      Wonguk Jeong <wonguk.jeong@samsung.com>
38  * @version     0.1
39  * @brief       A library to develop/use a UI gadget
40  */
41
42 /**
43  * @addtogroup UI_Gadget
44  * @{
45  *
46  * @defgroup    UI_Gadget_For_User User API Reference Guide
47  * @brief       A module to use a UI gadget. Caller uses this module and APIs.
48  *
49  * @section Header To Use Them:
50  * @code
51  * #include <ui-gadget.h>
52  * @endcode
53  */
54
55 /**
56  * @addtogroup UI_Gadget_For_User
57  * @{
58  */
59
60 #include <bundle.h>
61 #include <X11/Xlib.h>
62
63 #ifdef __cplusplus
64 extern "C" {
65 #endif
66
67 /**
68  * struct ui_gadget is an opaque type representing a UI gadget
69  * @see ug_create(), ug_destroy()
70  * @see ug_get_layout(), ug_get_parent_layout(), ug_get_mode()
71  */
72 struct ui_gadget;
73
74 /**
75  * UI gadget mode
76  * @see ug_create()
77  * @see ug_get_mode()
78  */
79 enum ug_mode {
80         UG_MODE_FULLVIEW, /**< Fullview mode */
81         UG_MODE_FRAMEVIEW, /**< Frameview mode */
82         UG_MODE_INVALID, /**< Invalid mode */
83         UG_MODE_MAX
84 };
85
86 /**
87  * UI gadget event
88  * @see ug_send_event()
89  */
90 enum ug_event {
91         UG_EVENT_NONE = 0x00,           /**< No event */
92         UG_EVENT_LOW_MEMORY,            /**< Low memory event */
93         UG_EVENT_LOW_BATTERY,           /**< Low battery event */
94         UG_EVENT_LANG_CHANGE,           /**< Language change event */
95         UG_EVENT_ROTATE_PORTRAIT,       /**< Rotate event: Portrait */
96         UG_EVENT_ROTATE_PORTRAIT_UPSIDEDOWN,    /**< Rotate event: Portrait upsidedown */
97         UG_EVENT_ROTATE_LANDSCAPE,      /**< Rotate event: Landscape */
98         UG_EVENT_ROTATE_LANDSCAPE_UPSIDEDOWN,
99                         /**< Rotate event: Landscape upsidedown */
100         UG_EVENT_REGION_CHANGE,         /**< Region change event */
101         UG_EVENT_MAX
102 };
103
104 /**
105  * UI gadget key event
106  * @see ug_send_key_event()
107  */
108 enum ug_key_event {
109         UG_KEY_EVENT_NONE = 0x00,       /**< No event */
110         UG_KEY_EVENT_END,               /**< End key event */
111         UG_KEY_EVENT_MAX
112 };
113
114 #define UG_OPT_INDICATOR_MASK (0x03)
115 #define UG_OPT_INDICATOR(opt) (opt & UG_OPT_INDICATOR_MASK)
116
117 /**
118  * UI gadget option
119  * - Indicator option: [1, 0] bits
120  *
121  * @see ug_init()
122  */
123 enum ug_option {
124         UG_OPT_INDICATOR_ENABLE = 0x00,
125                         /**< Indicator option:
126                         Enable with both portrait and landscape window */
127         UG_OPT_INDICATOR_PORTRAIT_ONLY = 0x01,
128                         /**< Indicator option: Enable with portrait window */
129         UG_OPT_INDICATOR_LANDSCAPE_ONLY = 0x02,
130                         /**< Indicator option: Enable with landscape window */
131         UG_OPT_INDICATOR_DISABLE = 0x03,
132                         /**< Indicator option:
133                         Disable with both portrait and landscape view window */
134         UG_OPT_MAX
135 };
136
137 /**
138  * UI gadget callback type
139  * @see ug_create()
140  */
141 struct ug_cbs {
142         /** layout callback */
143         void (*layout_cb) (struct ui_gadget *ug, enum ug_mode mode,
144                                 void *priv);
145         /** result callback */
146         void (*result_cb) (struct ui_gadget *ug, bundle *result, void *priv);
147         /** destroy callback */
148         void (*destroy_cb) (struct ui_gadget *ug, void *priv);
149         /** private data */
150         void *priv;
151 };
152
153 /**
154  * Easy-to-use macro of ug_init() for EFL
155  * @see ug_init()
156  */
157 #define UG_INIT_EFL(win, opt) \
158         ug_init((Display *)ecore_x_display_get(), elm_win_xwindow_get(win), \
159                 win, opt)
160
161 /**
162  * Easy-to-use macro of ug_init() for GTK
163  * @see ug_init()
164  */
165 #define UG_INIT_GTK(win, opt) \
166         win ?  ug_init(gdk_display_get_default(), win, \
167         GDK_WINDOW_XWINDOW(GTK_WIDGET(win)->window), win, opt) : -1
168
169 /**
170  * \par Description:
171  * This function initializes default window, display, xwindow id, and indicator state.
172  *
173  * \par Purpose:
174  * First of all, to use UI gadgets in an application, default window to draw the UI gadgets has to be registered. Besides, to change indicator state for the full-view UI gadget, display and xwindow id have to be registered, and to restore application's indicator state, default indicator option has to be registered. This function is used for registering them.
175  *
176  * \par Typical use case:
177  * Application developers who want to use UI gadget MUST register display, xwindow id, default window, and option with the function at first.
178  *
179  * \par Method of function operation:
180  * Register display, xwindow id, default window, and option.
181  *
182  * \par Context of function:
183  * None
184  *
185  * \note If you are unfamiliar with display and xwindow id, please use following macros: UG_INIT_EFL, UG_INIT_GTK. The macros kindly generate proper functions to get display and xwindow id.
186  *
187  * @param[in] disp Default display
188  * @param[in] xid Default xwindow id of default window
189  * @param[in] win Default window object, it is void pointer for supporting both GTK (GtkWidget *) and EFL (Evas_Object *)
190  * @param[in] opt Default indicator state to restore application's indicator state
191  * @return 0 on success, -1 on error
192  *
193  * \pre None
194  * \post None
195  * \see UG_INIT_EFL(), UG_INIT_GTK()
196  * \remarks None
197  *
198  * \par Sample code:
199  * \code
200  * #include <ui-gadget.h>
201  * ...
202  * Evas_Object *win;
203  * ...
204  * // create window
205  * ...
206  * ug_init((Display *)ecore_x_display_get(), elm_win_xwindow_get(win), win, UG_OPT_INDICATOR_ENABLE);
207  * // for convenience you can use following macro: ELM_INIT_EFL(win, UG_OPT_INDICATOR_ENABLE);
208  * ...
209  * \endcode
210  */
211 int ug_init(Display *disp, Window xid, void *win, enum ug_option opt);
212
213 /**
214  * \par Description:
215  * This function creates a UI gadget
216  *
217  * \par Purpose:
218  * This function is used for creating a UI gadget instance. In addition, following callbacks could be registered with the function: layout callback, result callback, and destroy callback. (see struct ug_cbs)
219  *
220  * \par Typical use case:
221  * Anyone who want to create UI gadget could use the function.
222  *
223  * \par Method of function operation:
224  * First, the UI gadget with given name is dynamically loaded(dlopen). Next, state operations of loaded UI gadget are invoked according to its lifecycle. There are three callbacks which could be registered with the function: layout callback, result callback, and destroy callback. If the state is changed to "Create", the layout callback is invoked for layout arrangement. If ug_send_result() is invoked in the loaded UI gadget , the result callback is invoked. And, if ug_destroy_me() is invoked in the loaded UI gadget , the destroy callback is invoked.
225  *
226  * \par Context of function:
227  * This function supposed to be called after successful initialization with ug_init()
228  *
229  * @param[in] parent parent's UI gadget. If the UI gadget uses the function, the parent has to be the UI gadget. Otherwise, if an application uses the function, the parent has to be NULL
230  * @param[in] name name of UI gadget
231  * @param[in] mode mode of UI gadget (UG_MODE_FULLVIEW | UG_MODE_FRAMEVIEW)
232  * @param[in] data argument for the UI gadget  (see \ref bundle_PG "bundle programming guide")
233  * @param[in] cbs callback functions (layout callback, result callback, destroy callback, see struct ug_cbs) and private data.
234  * @return The pointer of UI gadget, NULL on error
235  *
236  * \pre ug_init()
237  * \post None
238  * \see struct ug_cbs, enum ug_mode
239  * \remarks If you passed "data" bundle, you MUST release it using bundle_free() after ug_create()
240  *
241  * \par Sample code:
242  * \code
243  * #include <ui-gadget.h>
244  * ...
245  * bundle *b;
246  * struct ui_gadget *ug;
247  * struct ug_cbs cbs = {0, };
248  *
249  * // set callbacks: layout callback, result callback, destroy callback
250  * cbs.layout_cb = _layout_cb;
251  * cbs.result_cb = _result_cb;
252  * cbs.destroy_cb = _destroy_cb;
253  * cbs.priv = user_data;
254  *
255  * // create arguments
256  * b = bundle_create();
257  * bundle_add(b, "Content", "Hello");
258  *
259  * // create "helloUG-efl" UI gadget instance
260  * ug = ug_create(NULL, "helloUG-efl", UG_MODE_FULLVIEW, b, &cbs);
261  *
262  * // release arguments
263  * bundle_free(b);
264  * ...
265  * \endcode
266  */
267 struct ui_gadget *ug_create(struct ui_gadget *parent, const char *name,
268                                         enum ug_mode mode, bundle *data,
269                                         struct ug_cbs *cbs);
270
271 /**
272  * \par Description:
273  * This function pauses all UI gadgets
274  *
275  * \par Purpose:
276  * This function is used for pausing UI gadgets with "Running" state. Eventually, state of the UI gadgets would be "Stopped."
277  *
278  * \par Typical use case:
279  * Application developers who want to pause loaded UI gadgets could use the function.
280  *
281  * \par Method of function operation:
282  * "Pause" state operations of UI gadgets with "Running" state in the UI gadget tree are invoked by post-order traversal.
283  *
284  * \par Context of function:
285  * This function supposed to be called after successful initialization with ug_init()
286  *
287  * @return 0 on success, -1 on error
288  *
289  * \pre ug_init()
290  * \post None
291  * \see ug_resume()
292  * \remarks None
293  *
294  * \par Sample code:
295  * \code
296  * #include <ui-gadget.h>
297  * ...
298  * // pause all UI gadget instances
299  * ug_pause();
300  * ...
301  * \endcode
302  */
303 int ug_pause(void);
304
305 /**
306  * \par Description:
307  * This function resumes all UI gadgets
308  *
309  * \par Purpose:
310  * This function is used for resuming UI gadgets with "Stopped" state. Eventually, state of all UI gadgets would be "Running."
311  *
312  * \par Typical use case:
313  * Application developers who want to resume loaded UI gadgets could use the function.
314  *
315  * \par Method of function operation:
316  * "Resume" state operations of UI gadgets with "Stopped" state in the UI gadget tree are invoked by post-order traversal.
317  *
318  * \par Context of function:
319  * This function supposed to be called after successful initialization with ug_init()
320  *
321  * @return 0 on success, -1 on error
322  *
323  * \pre ug_init()
324  * \post None
325  * \see ug_pause()
326  * \remarks None
327  *
328  * \par Sample code:
329  * \code
330  * #include <ui-gadget.h>
331  * ...
332  * // resume all UI gadget instances
333  * ug_resume();
334  * ...
335  * \endcode
336  */
337 int ug_resume(void);
338
339 /**
340  * \par Description:
341  * This function destroys the given UI gadget instance
342  *
343  * \par Purpose:
344  * This function is used for destroying given UI gadget instance and its children. Eventually, state of the instance would be "Destroyed."
345  *
346  * \par Typical use case:
347  * Anyone who want to destroy specific UI gadget could use the function.
348  *
349  * \par Method of function operation:
350  * "Destroy" state operations of the given UI gadget instance and its children are invoked.
351  *
352  * \par Context of function:
353  * This function supposed to be called after successful initialization with ug_init() and creation UI gadget with ug_create()
354  *
355  * @param[in] ug The UI gadget
356  * @return 0 on success, -1 on error
357  *
358  * \pre ug_init(), ug_create()
359  * \post None
360  * \see ug_destroy_all()
361  * \remarks None
362  *
363  * \par Sample code:
364  * \code
365  * #include <ui-gadget.h>
366  * ...
367  * // destroy UI gadget instance
368  * ug_destroy(ug);
369  * ...
370  * \endcode
371  */
372 int ug_destroy(struct ui_gadget *ug);
373
374 /**
375  * \par Description:
376  * This function destroys all UI gadgets of an application
377  *
378  * \par Purpose:
379  * This function is used for destroying all UI gadgets. Eventually, state of all UI gadgets would be "Destroyed."
380  *
381  * \par Typical use case:
382  * Application developers who want to destroy loaded UI gadgets could use the function.
383  *
384  * \par Method of function operation:
385  * "Destroy" state operations of all UI gadgets in the UI gadget tree are invoked by post-order traversal.
386  *
387  * \par Context of function:
388  * This function supposed to be called after successful initialization with ug_init()
389  *
390  * @return 0 on success, -1 on error
391  *
392  * \pre ug_init()
393  * \post None
394  * \see ug_destroy()
395  * \remarks None
396  *
397  * \par Sample code:
398  * \code
399  * #include <ui-gadget.h>
400  * ...
401  * // destroy all UI gadget instances
402  * ug_destroy_all();
403  * ...
404  * \endcode
405  */
406 int ug_destroy_all(void);
407
408 /**
409  * \par Description:
410  * This function gets base layout of the given UI gadget instance
411  *
412  * \par Purpose:
413  * This function is used for getting base layout pointer of given UI gadget instance.
414  *
415  * \par Typical use case:
416  * Anyone who want to get base layout of UI gadget could use the function.
417  *
418  * \par Method of function operation:
419  * This function returns base layout pointer which is created in "Create" operation of the given UI gadget instance.
420  *
421  * \par Context of function:
422  * This function supposed to be called after successful initialization with ug_init() and creation UI gadget with ug_create()
423  *
424  * @param[in] ug The UI gadget
425  * @return The pointer of base layout, NULL on error. The result value is void pointer for supporting both GTK (GtkWidget *) and EFL (Evas_Object *)
426  *
427  * \pre ug_init(), ug_create()
428  * \post None
429  * \see ug_get_parent_layout()
430  * \remarks None
431  *
432  * \par Sample code:
433  * \code
434  * #include <ui-gadget.h>
435  * ...
436  * Evas_Object *ly;
437  * // get a base layout
438  * ly = (Evas_Object *)ug_get_layout(ug);
439  * ...
440  * \endcode
441  */
442 void *ug_get_layout(struct ui_gadget *ug);
443
444 /**
445  * \par Description:
446  * This function gets base layout of parent of the given UI gadget instance
447  *
448  * \par Purpose:
449  * This function is used for getting base layout pointer of parent of the given UI gadget instance.
450  *
451  * \par Typical use case:
452  * Anyone who want to get base layout of UI gadget's parent could use the function.
453  *
454  * \par Method of function operation:
455  * This function returns base layout pointer which is created in "Create" operation of parent of the given UI gadget instance.
456  *
457  * \par Context of function:
458  * This function supposed to be called after successful initialization with ug_init() and creation UI gadget with ug_create()
459  *
460  * @param[in] ug The UI gadget
461  * @return The pointer of base layout, NULL on error. The result value is void pointer for supporting both GTK (GtkWidget *) and EFL (Evas_Object *)
462  *
463  * \pre ug_init(), ug_create()
464  * \post None
465  * \see ug_get_layout()
466  * \remarks None
467  *
468  * \par Sample code:
469  * \code
470  * #include <ui-gadget.h>
471  * ...
472  * Evas_Object *ly;
473  * // get a base layout of parent of the given UI gadget instance
474  * ly = (Evas_Object *)ug_get_parent_layout(ug);
475  * ...
476  * \endcode
477  */
478 void *ug_get_parent_layout(struct ui_gadget *ug);
479
480 /**
481  * \par Description:
482  * This function gets default window
483  *
484  * \par Purpose:
485  * This function is used for getting default window which is registered with ug_init()
486  *
487  * \par Typical use case:
488  * Anyone who want to get default window could use the function.
489  *
490  * \par Method of function operation:
491  * This function returns default window pointer which is registered with ug_init()
492  *
493  * \par Context of function:
494  * This function supposed to be called after successful initialization with ug_init()
495  *
496  * @return The pointer of default window, NULL on error. The result value is void pointer for supporting both GTK (GtkWidget *) and EFL (Evas_Object *)
497  *
498  * \pre ug_init()
499  * \post None
500  * \see None
501  * \remarks None
502  *
503  * \par Sample code:
504  * \code
505  * #include <ui-gadget.h>
506  * ...
507  * Evas_Object *win;
508  * // get default window
509  * win = (Evas_Object *)ug_get_window(ug);
510  * ...
511  * \endcode
512  */
513 void *ug_get_window(void);
514
515 /**
516  * \par Description:
517  * This function gets mode of the given UI gadget instance
518  *
519  * \par Purpose:
520  * This function is used for getting mode of the given UI gadget instance. Mode could be UG_MODE_FULLVIEW or UG_MODE_FRAMEVIEW.
521  *
522  * \par Typical use case:
523  * Anyone who want to get mode of UI gadget could use the function.
524  *
525  * \par Method of function operation:
526  * This function returns mode which is registered with ug_create()
527  *
528  * \par Context of function:
529  * This function supposed to be called after successful initialization with ug_init() and creation UI gadget with ug_create()
530  *
531  * @param[in] ug The UI gadget
532  * @return UI gadget mode of the given UI gadget instance (UG_MODE_FULLVIEW | UG_MODE_FRAMEVIEW)
533  *
534  * \pre ug_init(), ug_create()
535  * \post None
536  * \see enum ug_mode
537  * \remarks None
538  *
539  * \par Sample code:
540  * \code
541  * #include <ui-gadget.h>
542  * ...
543  * enum ug_mode mode;
544  * // get mode (UG_MODE_FULLVIEW | UG_MODE_FRAMEVIEW)
545  * mode = ug_get_mode(ug);
546  * ...
547  * \endcode
548  */
549 enum ug_mode ug_get_mode(struct ui_gadget *ug);
550
551 /**
552  * \par Description:
553  * This function propagates the given system event to all UI gadgets
554  *
555  * \par Purpose:
556  * This function is used for propagating the given system event. Available system events are low memory, low battery, language changed, and window rotate event.
557  *
558  * \par Typical use case:
559  * Application developers who want to propagate system event to all UI gadgets could use the function.
560  *
561  * \par Method of function operation:
562  * Event operations of all UI gadgets in the UI gadget tree are invoked by post-order traversal.
563  *
564  * \par Context of function:
565  * This function supposed to be called after successful initialization with ug_init()
566  *
567  * @param[in] event UI gadget event. (see enum ug_event)
568  * @return 0 on success, -1 on error
569  *
570  * \pre ug_init()
571  * \post None
572  * \see enum ug_event
573  * \remarks None
574  *
575  * \par Sample code:
576  * \code
577  * #include <ui-gadget.h>
578  * ...
579  * // propagate low battery event to all UI gadget instances
580  * ug_send_event(UG_EVENT_LOW_BATTERY);
581  * ...
582  * \endcode
583  */
584 int ug_send_event(enum ug_event event);
585
586 /**
587  * \par Description:
588  * This function send key event to full view top UI gadget
589  *
590  * \par Purpose:
591  * This function is used for sending key event to full view top UI gadget. Available key events are end event.
592  *
593  * \par Typical use case:
594  * Application developers who want to send key event to full view top UI gadget could use the function.
595  *
596  * \par Method of function operation:
597  * Key event operation of full view top UI gadget in the UI gadget tree are invoked.
598  *
599  * \par Context of function:
600  * This function supposed to be called after successful initialization with ug_init()
601  *
602  * @param[in] event UI gadget key event. (see enum ug_key_event)
603  * @return 0 on success, -1 on error
604  *
605  * \pre ug_init()
606  * \post None
607  * \see enum ug_key_event
608  * \remarks None
609  *
610  * \par Sample code:
611  * \code
612  * #include <ui-gadget.h>
613  * ...
614  * // send key event callback to full view top UI gadget instances
615  * ug_send_key_event(UG_KEY_EVENT_END);
616  * ...
617  * \endcode
618  */
619 int ug_send_key_event(enum ug_key_event event);
620
621 /**
622  * \par Description:
623  * This function sends message to the given UI gadget instance
624  *
625  * \par Purpose:
626  * This function is used for sending message to created UI gadget. The message have to be composed with bundle library.
627  *
628  * \par Typical use case:
629  * Anyone who want to send message to created UI gadget.
630  *
631  * \par Method of function operation:
632  * Message operation of given UI gadget instance is invoked.
633  *
634  * \par Context of function:
635  * This function supposed to be called after successful initialization with ug_init() and creation UI gadget with ug_create()
636  *
637  * @param[in] ug The UI gadget
638  * @param[in] msg message to send, which is bundle type (see \ref bundle_PG "bundle programming guide")
639  * @return 0 on success, -1 on error
640  *
641  * \pre ug_init(), ug_create()
642  * \post None
643  * \see None
644  * \remarks After send your message, you have to release it using bundle_free()
645  *
646  * \par Sample code:
647  * \code
648  * #include <ui-gadget.h>
649  * ...
650  * // make a message with bundle
651  * bundle *b;
652  * b = bundle_create();
653  * bundle_add(b, "Content", "Hello");
654  *
655  * // send the message
656  * ug_send_message(ug, b);
657  *
658  * // release the message
659  * bundle_free(b);
660  * ...
661  * \endcode
662  */
663 int ug_send_message(struct ui_gadget *ug, bundle *msg);
664
665 /**
666  * \par Description:
667  * This function disable transition effect of the given UI gadget instance
668  *
669  * \par Purpose:
670  * This function is used for disabling transition effect of created UI gadget.
671  *
672  * \par Typical use case:
673  * Anyone who want to disable transition effect of created UI gadget.
674  *
675  * \par Method of function operation:
676  * No transition effect of given UI gadget is invoked
677  *
678  * \par Context of function:
679  * This function supposed to be called after successful initialization with ug_init() and creation UI gadget with ug_create()
680  *
681  * @param[in] ug The UI gadget
682  * @return 0 on success, -1 on error
683  *
684  * \pre ug_init(), ug_create()
685  * \post None
686  * \see None
687  * \remarks Before show layout of given UI gadget, ug_disable_effect() should be called.
688  *
689  * \par Sample code:
690  * \code
691  * #include <ui-gadget.h>
692  * ...
693  * static void layout_cb(struct ui_gadget *ug, enum ug_mode mode, void *priv)
694  * {
695  * ...
696  * base = ug_get_layout(ug);
697  * switch (mode) {
698  * case UG_MODE_FULLVIEW:
699  * // disable effect
700  * ug_disable_effect(ug);
701  * evas_object_show(base);
702  * ...
703  * \endcode
704  */
705 int ug_disable_effect(struct ui_gadget *ug);
706
707 #ifdef __cplusplus
708 }
709 #endif
710 /**
711  * @} @} @}
712  */
713 #endif                          /* __UI_GADGET_H__ */