check rotation lock and set rotation info when ug launch
[framework/appfw/ui-gadget-1.git] / include / SLP_UI_Gadget_PG.h
1 /*
2  *  UI Gadget
3  *
4  * Copyright (c) 2000 - 2012 Samsung Electronics Co., Ltd. All rights reserved.
5  *
6  * Contact: Jayoun Lee <airjany@samsung.com>, Jinwoo Nam <jwoo.nam@samsung.com>
7  *
8  * Licensed under the Apache License, Version 2.0 (the "License");
9  * you may not use this file except in compliance with the License.
10  * You may obtain a copy of the License at
11  *
12  * http://www.apache.org/licenses/LICENSE-2.0
13  *
14  * Unless required by applicable law or agreed to in writing, software
15  * distributed under the License is distributed on an "AS IS" BASIS,
16  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
17  * See the License for the specific language governing permissions and
18  * limitations under the License.
19  *
20  */
21
22 /**
23  *
24  * @ingroup SLP_PG
25  * @defgroup SLP_PG_UI_GADGET UI gadget library
26  * @{
27
28 <h1 class="pg">Introduction</h1>
29 <h2 class="pg">Purpose of this document</h2>
30 The purpose of this document is to describe how to develop/use UI gadget. This document gives programming guidelines to UI gadget devlopers and users.
31 <h2 class="pg">Scope</h2>
32 The scope of this document is limited to UI gadget component interface and API usage.
33
34 <h1 class="pg">UI gadget architecture</h1>
35 <h2 class="pg">UI gadget</h2>
36 An UI gadget is a visual component providing views (or features) of other applications, e.g., contact, image viewer. Because UI gadgets are supposed to deliver most commonly used features that the platform can natively support, developers can avoid unnecessary massive code writing using UI gadgets. Hence an UI gadget eventually includes logics to handle simple request. UI gadget is able to be managed by UI gadget library.
37 \image html SLP_UI_Gadget_PG_image00.png "Picture 1. UI gadget architecture diagram"
38
39 <h2 class="pg">UI gadget features</h2>
40 UI Gadget Library has the following features:
41 - It provides component interfaces for UI Gadget
42 - It manages UI gadget instances in an application according to their lifecycle
43
44 <h2 class="pg">Lifecycle</h2>
45 Essentially, an UI gadget has following five states (See Picture 2)
46 - The initial state is \b Ready
47 - If an UI gadget has been created, it is \b Created
48 - If an UI gadget has been started, it is \b Running
49 - If the application that is using an UI gadget is put into background, it is \b Stopped
50 - If an UI gadget has been destroyed, it is \b Destroyed
51
52 An UI gadget has five callback methods that you can implement to perform operations when the UI gadget moves between states
53 - When an UI gadget is created, \b create() is invoked
54 - When an UI gadget is started, \b start() is invoked
55 - When the application that is using an UI gadget is put into background, \b pause() is invoked
56 - When the application that is using an UI gadget is brought to the foreground, \b resume() is invoked.
57 - When an UI gadget is destroyed, \b destroy() is invoked
58
59 In addition, an UI gadget has callback methods for system events and message:
60 - When an system event is generated, event() is invoked
61 - When an UI gadget receives message from the caller, message() is invoked
62
63 \image html SLP_UI_Gadget_PG_image01.png "Picture 2. UI gadget state diagram"
64
65 <h2 class="pg">Management</h2>
66 UI gadgets in an application are managed as a TREE structure (See Picture 3.) The features for the tree are:
67 - Root of the tree is the UI gadget manager
68 - UI gadget caller is parent of callees
69 - Parents arrange the layout of their children
70
71 Every application which is using UI gadgets has one UI gadget manager as a root of the tree. And the UI gadget manager propagates system events and task management events by post-order traversal. Available system events are <i>low memory, low battery, language changed, region changed and window rotate event</i>. And task management events are <i>pause and resume</i>.
72
73 \image html SLP_UI_Gadget_PG_image02.png "Picture 3. UI gadget management policy"
74
75 <h1 class="pg">Getting started</h1>
76 <h2 class="pg">Overview</h2>
77 For using UI gadget, you need to know the working procedure between caller and UI gadget module.<br><br>
78 As an UI gadget module developer, the operations of UI gadget module are very important. These operations are called by UI gadget library when the caller requests something to UI gadget module and UI gadget module performs a proper job mainly related with lifecycle. “Section How to make UI gadget” describes detail of each operation.<br><br>
79 As an UI gadget caller, you need to know the APIs for using UI gadget module and callback functions for dealing with UI gadget module. The caller can create UI gadget module using ug_create() API and have right to arrange layout of UI gadget module and destroy UI gadget module. These are performed by caller when caller requests something to UI gadget library and related callback functions are called by UI gadget library. “Section How to use UI gadget” describes detail of each APIs and callback functions.
80 <h2 class="pg">How to make UI gadget</h2>
81 In this section, we are going to write your first UI gadget called "helloUG-efl". Before we get started, make sure you have read the overview, especially, lifecycle section. We will mainly deal with the operations of lifecycle.
82
83 \note <b>Sample codes</b> are included in the UI gadget source package. The samples for UI gadget developers are located in "samples/helloUG-efl/", and the samples for UI gadget users are in "samples/ugcaller/."
84
85 <br>
86 <h3 class="pg">UI gadget template</h3>
87 To create an UI gadget, start by generating boilerplate code using UI gadget template as follow:
88 @verbatim
89 # ug-gen.sh helloUG-efl helloUG-efl EFL
90 @endverbatim
91
92 \note <b>How to install UI gadget template:</b>
93 @verbatim
94 # unrpm ui-gadget-template-xxx.rpm
95 # or
96 # rpm -Uvh ui-gadget-templat-xxx.rpm
97 @endverbatim
98
99 \note <b>How to use UI gadget template:</b>
100 @verbatim
101 # ug-gen.sh [destination] [name] [UI library]
102 @endverbatim
103 - destination: destination directory
104 - name: UI gadget name
105 - UI library: UI library to use. Only EFL is available for now
106
107 After you generate code, you get following files:
108 - <i>helloUG-efl.c</i>  (Source)
109 - <i>helloUG-efl.h</i>  (Private header)
110 - <i>CMakeList.txt</i>  (Build script)
111 - <i>po/*</i>           (I18N files)
112
113 <i>helloUG-efl.c</i> contains base code, and the most important parts are <i>UG_MODULE_INIT</i> and <i>UG_MODULE_EXIT</i> which are symbols to export for dynamic linking. <i>UG_MODULE_INIT</i> is invoked when the UI gadget is loading, and it sets operations, private data, and the option. <i>UG_MODULE_EXIT</i> is invoked when the UI gadget is unloading, and it clears private data.<br><br>
114 Even if you don't understand generated code right now, don't worry about it. What you have to do is just implementation of operations according to their role (see next section.)
115 @code
116 // in helloUG-efl.c
117 UG_MODULE_API int UG_MODULE_INIT(struct ug_module_ops *ops)
118 {
119         struct ug_data *ugd;            // User defined private data
120
121         if (!ops)
122                 return -1;
123
124         ugd = calloc(1, sizeof(struct ug_data));
125         if (!ugd)
126                 return -1;
127
128         // create operation
129         ops->create = on_create;
130         // start operation
131         ops->start = on_start;
132         // pause operation
133         ops->pause = on_pause;
134         // resume operation
135         ops->resume = on_resume;
136         // destroy operation
137         ops->destroy = on_destroy;
138         // message operation
139         ops-> message = on_message;
140         // event operation
141         ops->event = on_event;
142         // private data
143         ops->priv = ugd;
144         // option
145         ops->opt = UG_OPT_INDICATOR_ENABLE;
146
147         return 0;
148 }
149
150 UG_MODULE_API void UG_MODULE_EXIT(struct ug_module_ops *ops)
151 {
152         struct ug_data *ugd;
153
154         if (!ops)
155                 return;
156
157         ugd = ops->priv;
158         if (ugd)
159                 free(ugd);              // clear private data
160 }
161
162 @endcode
163
164 \note <b>struct ug_module_ops</b> is a data structure describing operations, private data, and the option of UI gadget:
165 @code
166 struct ug_module_ops {
167         void *(*create)(ui_gadget_h ug, enum ug_mode mode, service_h service, void *priv);
168         void (*start)(ui_gadget_h ug, service_h service, void *priv);
169         void (*pause)(ui_gadget_h ug, service_h service, void *priv);
170         void (*resume)(ui_gadget_h ug, service_h service, void *priv);
171         void (*destroy)(ui_gadget_h ug, service_h service, void *priv);
172         void (*message)(ui_gadget_h ug, service_h *msg, service_h service, void *priv);
173         void (*event)(ui_gadget_h ug, enum ug_event event, service_h service, void *priv);
174         void *reserved[5];
175         void *priv;
176         enum ug_option opt;
177 };
178 @endcode
179
180 \note <b>enum ug_option</b> is UI gadget options, available options are:
181 @code
182 // Enable indicator
183 UG_OPT_INDICATOR_ENABLE
184 // Enable indicator with portrait window
185 UG_OPT_INDICATOR_PORTRAIT_ONLY
186 // Enable indicator with landscape window
187 UG_OPT_INDICATOR_LANDSCAPE_ONLY
188 // Disable indicator
189 UG_OPT_INDICATOR_DISABLE
190 @endcode
191
192 \note <b>struct ug_data</b> is a user defined private data structure describing base layout, own UI gadget handler, and whatever you need:
193 @code
194 struct ug_data {
195         Evas_Object *base;
196         ui_gadget_h ug;
197
198         // PUT WHATEVER YOU NEED
199 }
200 @endcode
201
202 <br>
203 <h3 class="pg">Operations</h3>
204 There are five state operations, a message operation, and an event operation: <i>create, start, pause, resume, destroy, message, and event.</i>
205 <br><br>
206 When "helloUG-efl" is created, the create operation is invoked (See Picture 2-1).<br><br>
207
208 \image html SLP_UI_Gadget_PG_image2-1.png "Picture 2-1. Create operation of UI gadget module"
209
210 The implementation of create operation is <b>on_create()</b>. Basically, in the operation, we have to make a base layout and return it. Hence, we made base layout using <i>"window layout winset."</i> In case of fullview, we let indicator area be shown, otherwise, we don't (see <i>create_fullview()</i> and <i>create_frameview()</i>.) In addition, in the base layout, we put a box including a label and two buttons (see <i>create_content()</i>.) The label is labeled "Hello UI Gadget." And the first button, labeled "Send result", is for sending result to the "helloUG-efl" caller. The other button, labeled "Back", is for sending destroy request to the caller. For more information about two buttons, please see <i>Send results and request to destroy section</i>.
211
212 \note <b>Arguments:</b> All operations receive servive type data which is named <i>service</i> (see \ref service_PG "Tizen Managed APi Reference Guide > Application Framework -> Application") And the argument <i>service</i> is automatically released by UI gadget manager after the UI gadget is destroyed.
213
214 @code
215 // in helloUG-efl.c
216 static void *on_create(ui_gadget_h ug, enum ug_mode mode, service_h service, void *priv)
217 {
218         Evas_Object *parent;
219         Evas_Object *content;
220         struct ug_data *ugd;
221
222         if (!ug || !priv)
223                 return NULL;
224
225         ugd = priv;
226         ugd->ug = ug;
227
228         parent = ug_get_parent_layout(ug);
229         if (!parent)
230                 return NULL;
231
232         if (mode == UG_MODE_FULLVIEW)
233                 ugd->base = create_fullview(parent, ugd);
234         else
235                 ugd->base = create_frameview(parent, ugd);
236
237         if (ugd->base) {
238                 content = create_content(parent, ugd);
239                 elm_layout_content_set(ugd->base, "elm.swallow.content", content);
240         }
241         return ugd->base;
242 }
243
244 static Evas_Object *create_fullview(Evas_Object *parent, struct ug_data *ugd)
245 {
246         Evas_Object *base;
247
248         base = elm_layout_add(parent);
249         if (!base)
250                 return NULL;
251         elm_layout_theme_set(base, "layout", "application", "default");
252         // In case of fullview, show indicator area
253         edje_object_signal_emit(_EDJ(base), "elm,state,show,indicator", "elm");
254         edje_object_signal_emit(_EDJ(base), "elm,state,show,content", "elm");
255
256         return base;
257 }
258
259 static Evas_Object *create_frameview(Evas_Object *parent, struct ug_data *ugd)
260 {
261         Evas_Object *base;
262
263         base = elm_layout_add(parent);
264         if (!base)
265                 return NULL;
266
267         elm_layout_theme_set(base, "layout", "application", "default");
268         // In case of frameview, do not show indicator area
269         edje_object_signal_emit(_EDJ(base), "elm,state,show,content", "elm");
270
271         return base;
272 }
273
274 static Evas_Object *create_content(Evas_Object *parent, struct ug_data *ugd)
275 {
276         Evas_Object *bx, *eo;
277
278         // add box
279         bx = elm_box_add(parent);
280
281         // add label and pack it in the box
282         eo = elm_label_add(parent);
283         elm_object_text_set(eo, _("Hello UI Gadget"));
284         evas_object_size_hint_align_set(eo, 0.5, EVAS_HINT_FILL);
285         evas_object_size_hint_weight_set(eo, EVAS_HINT_EXPAND, EVAS_HINT_EXPAND);
286         evas_object_show(eo);
287         elm_box_pack_end(bx, eo);
288
289         // add buttons and pack it in the box
290         eo = elm_button_add(parent);
291         elm_object_text_set(eo, _("Send result"));
292         evas_object_size_hint_align_set(eo, EVAS_HINT_FILL, EVAS_HINT_FILL);
293         evas_object_smart_callback_add(eo, "clicked", result_cb, ugd);
294         elm_object_style_set(eo, "bottom_btn");
295
296         evas_object_show(eo);
297         elm_box_pack_end(bx, eo);
298
299         eo = elm_button_add(parent);
300         elm_object_text_set(eo, _("Back"));
301         evas_object_size_hint_align_set(eo, EVAS_HINT_FILL, EVAS_HINT_FILL);
302         evas_object_smart_callback_add(eo, "clicked", back_cb, ugd);
303         elm_object_style_set(eo, "bottom_btn");
304
305         evas_object_show(eo);
306         elm_box_pack_end(bx, eo);
307         return bx;
308 }
309
310 @endcode
311
312 When "helloUG-efl" starts, the start operation is invoked (See Picture 2-2).<br><br>
313
314 \image html SLP_UI_Gadget_PG_image2-2.png "Picture 2-2. Start operation of UI gadget module"
315
316 The implementation of start operation is <b>on_start()</b>. Usually every job would be completed before this operation, so just describe additional job you need to do in this operation.
317
318 @code
319 // in helloUG-efl.c
320 static void on_start(ui_gadget_h ug, service_h service, void *priv)
321 {
322
323 }
324 @endcode
325
326 When "helloUG-efl" is destroyed, the destroy operation is invoked(See Picture 2-3). Ui gadget cannot destroy itself, so it moust be destroyed by caller using ug_destroy().<br><br>
327
328 \image html SLP_UI_Gadget_PG_image2-3.png "Picture 2-3. Destroy operation of UI gadget module"
329
330 The implementation of destroy operation is <b>on_destroy()</b>. We usually release the resources that have been used. In the following method, we delete base layout:
331
332 @code
333 // in helloUG-efl.c
334 static void on_destroy(ui_gadget_h ug, service_h service, void *priv)
335 {
336         struct ug_data *ugd;
337
338         if (!ug || !priv)
339                 return;
340
341         ugd = priv;
342
343         evas_object_del(ugd->base);
344         ugd->base = NULL;
345 }
346 @endcode
347
348 When the application using "helloUG-efl" is put into background, the pause operation is invoked (See Picture 2-4). But UI gadget could get state only from caller, so pause operation (e.g., on_pause) is called by caller using ug_pause().<br><br>
349
350 \image html SLP_UI_Gadget_PG_image2-4.png "Picture 2-4. Pause operation of UI gadget module"
351
352 When the application is brought to the foreground, the resume operation is invoked (See Picture 2-5). Resume operation (e.g.,on_resume) is called by caller using ug_resume().<br><br>
353
354 \image html SLP_UI_Gadget_PG_image2-5.png "Picture 2-5. Resume operation of UI gadget module"
355
356 Besides, when an UI gadget receives message from its caller suing ug_send_message(), the message operation(e.g., on_message) is invoked (See Picture 2-6).<br><br>
357
358 \image html SLP_UI_Gadget_PG_image2-6.png "Picture 2-6. Send message to UI gadget module"
359
360 And when a system event is generated and UI gadget receives event from caller using ug_send_event(), the event operation(e.g., on_event) is invoked (See Picture 2-7).<br><br>
361
362 \image html SLP_UI_Gadget_PG_image2-7.png "Picture 2-7. Send system event to UI gadget module"
363
364 The implementation of pause, resume, message, and event operations are on_pause(), on_resume(), on_message(), and on_event(). In on_pause() and on_resume(), you can describe actions performed when a state is changed to pause or resume. For example, music player UI gadget can stop playing music or restart playing music in these operations. In on_message(), you can get service type data from caller and deal with it. In on_event(), you can describe a proper job related to the passed system event.
365
366 @code
367 // in helloUG-efl.c
368 static void on_pause(ui_gadget_h ug, service_h service, void *priv)
369 {
370        // Do what you need to do when paused.
371 }
372 static void on_resume(ui_gadget_h ug, service_h service, void *priv)
373 {
374        // Do what you need to do when paused.
375 }
376
377 static void on_message(ui_gadget_h ug, service msg, service_h service, void *priv)
378 {
379        // Do what you need to do when paused.
380 }
381
382 static void on_event(ui_gadget_h ug, enum ug_event event, service_h service, void *priv)
383 {
384         switch (event) {
385         case UG_EVENT_LOW_MEMORY:
386                 break;
387         case UG_EVENT_LOW_BATTERY:
388                 break;
389         case UG_EVENT_LANG_CHANGE:
390                 break;
391         case UG_EVENT_ROTATE_PORTRAIT:
392                 break;
393         case UG_EVENT_ROTATE_PORTRAIT_UPSIDEDOWN:
394                 break;
395         case UG_EVENT_ROTATE_LANDSCAPE:
396                 break;
397         case UG_EVENT_ROTATE_LANDSCAPE_UPSIDEDOWN:
398                 break;
399         case UG_EVENT_REGION_CHANGE:
400                 break;
401         default:
402                 break;
403         }
404 }
405 @endcode
406
407 \warning Message data of message operation is service type data, named <i>msg.</i> <b>Because the message data is released after message operation is finished,</b> if you want to keep using it, please use <b>service_clone()()</b> which duplicates given service data (see \ref service_PG "Tizen Managed API Reference Guide")
408
409 <br>
410 <h3 class="pg">Send results and destroy request</h3>
411 Usually, an UI gadget needs to send results or destroy request to the UI gadget caller.<br><br>
412 To send result, use <b>ug_send_result()</b>, then UG library calls result callback function registered by caller (See Picture 2-8)(See <i>API reference guide</i>).<br><br>
413
414 \image html SLP_UI_Gadget_PG_image2-8.png "Picture 2-8. Send result"
415
416 And to send the destroy request, use <b>ug_destroy_me().</b>(), then UG library calls destroy callback function registered by caller (See Picture 2-9) (See <i>API reference quide</i>).<br><br>
417
418 \image html SLP_UI_Gadget_PG_image2-9.png "Picture 2-9. UI gadget destroy request"
419
420 We use service library for composing result data. The service provides us a few APIs to make a list of dictionary data that consists of key and value. (ex. {"name"  "John Doe"}) To get more information of service, please see \ref service_PG "Tizen Managed API Reference Guide".
421
422 \warning After send your result data, you have to release it using <b>service_destroy()</b> API.
423
424 In our "helloUG-efl", we made two buttons for sending results and destroy request as below:
425 @code
426 // in helloUG-efl.c
427
428 //Include to use service APIs
429 #include <app.h>
430
431 static void result_cb(void *data, Evas_Object *obj, void *event_info)
432 {
433         service_h result;
434         struct ug_data *ugd;
435         int ret;
436
437         if (!data)
438                 return;
439
440         ugd = data;
441
442         ret = service_create(&result);
443
444         service_add_extra_data(result, "name", "hello-UG");
445         service_add_extra_data(result, "description", "sample UI gadget");
446
447         ug_send_result(ugd->ug, result);
448
449         // release service
450         service_destroy(result);
451 }
452
453 static void back_cb(void *data, Evas_Object *obj, void *event_info)
454 {
455         struct ug_data *ugd;
456         int i;
457
458         if (!data)
459                 return;
460
461         ugd = data;
462
463         //Send destroy request
464         ug_destroy_me(ugd->ug);
465 }
466 @endcode
467
468 \note <b>To use service</b>
469 - Install capi-appfw-application-dev package (add in your RPM spec file)
470 - Modify CMakeFile.txt to use capi package as follow:
471 @code
472         …
473                 pkg_check_modules(pkgs REQUIRED elementary ui-gadget-1 capi-appfw-application)
474         …
475 @endcode
476
477 <br>
478 <h3 class="pg">Internationalization</h3>
479 Basically, we use <b><i>dgettext</i></b> for translating a text string into the user's native language because each UI gadget uses different textdomain.
480 @code
481 // in helloUG-efl.h
482 #define PKGNAME                 "ug-helloUG-efl"
483 #define _(s)                    dgettext(PKGNAME, s)
484 #define dgettext_noop(s)        (s)
485 #define N_(s)                   dgettext_noop(s)
486 @endcode
487
488 The PKGNAME is textdomain of "helloUG-efl", and _() is a dgettext wrapper, and N_() is dummy macro. In addition, _() and N_() are additional keywords for marking translatable string for xgettext. Especially, N_() is a dummy keyword for special case as follow:
489 @code
490 static const char *message[] = {
491         N_("translatable string"),
492 };
493 @endcode
494
495 For more information, please see <a href="http://www.gnu.org/software/gettext/manual/gettext.html">GNU gettext utilities</a>.
496
497 \note <b>xgettext</b> extracts gettext strings from given input files. The canonical keyword for marking translatable strings is 'gettext'. For convenience, many packages use '_' as a keyword instead of 'gettext', and write '_("translatable string")' instead of 'gettext("translatable string")'.
498
499 <br>
500 <h3 class="pg">Rotation and indicator</h3>
501 When the UI gadget is created as fullview, we have to consider whether the indicator is shown or not. For instance, "Image viewer" shows the indicator on the portrait mode but not on the landscape mode. Hence, we provided option field named <i>opt</i> of <i>struct ug_module_ops</i> in UG_MODULE_INIT.
502 Available options are as following:
503 - UG_OPT_INDICATOR_ENABLE (default)
504 - UG_OPT_INDICATOR_POTRAIT_ONLY
505 - UG_OPT_LANDSCAPE_ONLY
506 - UG_OPT_INDICATOR_DISABLE
507
508 And we used UG_OPT_INDICATOR_POTRAIT_ONLY in "helloUG-efl"
509
510 <br>
511 <h3 class="pg">Build and test</h3>
512 Before you build, you have to make sure whether translatable strings exist or not. IF translatable strings EXIST, please follow these steps before you build:
513 @verbatim
514 # cd po
515 # ./update-po.sh
516 # cd ..
517 @endverbatim
518 IF NOT, please remove the following line in your CMakeList.txt
519 @verbatim
520 ADD_SUBDIRECTORY(po)
521 @endverbatim
522
523 To build "helloUG-efl", follow these steps:
524 @verbatim
525 # mkdir build
526 # cd build
527 # cmake -DCMAKE_INSTALL_PREFIX=/usr ..
528 # make
529 # make install
530 or
531 make home project for your UI gadget in obs.
532 you can find RPM spec file in packaging directory by template.
533 @endverbatim
534
535 \note <b>Naming rule:</b> The output library name is <b>"libug-helloUG-efl.so"</b>, and we use <b>"helloUG-efl"</b> as UI gadget name except prefix <b>"libug-"</b> and postfix ".so" In other word, when you make an UI gadget, the name of library MUST be <b>"libug-XXXXXX.so"</b>
536 \note <b>Installation directory:</b> UI gadgets MUST be installed in "/usr/lib/ug/" which is preload Ug and "/opt/lib/ug/" is downloaded UG
537
538 Finally, we made our first UI gadget, "helloUG-efl." Let's test it using <i>ug-launcher</i> which is simple UI gadget launcher.
539 Fullview test
540 @verbatim
541 # ug-launcher -n helloUG-efl
542 @endverbatim
543 Frameview test
544 @verbatim
545 # ELM_THEME=beat ug-launcher -n helloUG-efl -f
546 @endverbatim
547
548 \note <b>How to use UG launcher</b>
549 @verbatim
550 # ug-launcher [-F] [-f] -n <UG_NAME> [-d <Argument>]
551 @endverbatim
552 - -d: argument, key, value pair.
553 - -F: Fullview mode (default)
554 - -f: frameview mode
555 \note <b> Example: </b>
556 @verbatim
557 # ug-launcher -F -n helloUG-efl -d "name,John doe" -d "age,30"
558 @endverbatim
559
560 <br>
561 <h2 class="pg">How to use UI gadget</h2>
562 Now, we are going to use "helloUG-efl" of previous section.
563
564 <br>
565 <h3 class="pg">Initialize</h3>
566
567 If you are UI gadget developer who is trying to use UI gadgets, please skip this section. This section is for application developers who use UI gadgets.
568 You have to initialize UI gadget manager before you use UI gadgets. To initialize, use <b>ug_init()</b> with arguments: <i>disp, xid, win and opt</i>. <i>disp</i> is default display, and <i>xid</i> is X window id of win. <i>win</i> is window evas object for UI gadgets, and it is usually main window. <i>opt</i> is rotation and indicator option for your application (see <i>Rotation and indicator section</i>.)
569
570 The <i>disp</i> and <i>xid</i> are used for indicator management. If you don't know how to get display and X window ID, just use following macro: <b>UG_INIT_EFL(win, opt);</b>
571
572 \note <b>Prototype of ug_init() (See API Reference guide):</b>
573 @code
574 int ug_init (Display *disp, Window xid, void *win, enum ug_option opt);
575 @endcode
576 \note <b>Macros for convenience (see 3 API reference quide):</b>
577 @code
578 UG_INIT_EFL(win, opt);
579 @endcode
580
581 <br>
582 <h3 class="pg">Create UI gadget instance</h3>
583
584 To create UI gadget instance, you have to invoke <b>ug_create()</b> which has five arguments: <i>parent, name, mode, service, and cbs.</i>
585
586 First, the <i>parent</i> is provided for specifying parent UI gadget, and it helps UI gadget manager to manage UI gadget tree (see <i>Management section.</i>) For instance, if the UI gadget 'A' uses other UI gadgets,  the parent has to be the 'A.' Otherwise, if an application uses UI gadgets, the <i>parent</i> has to be NULL.
587
588 Second, the <i>name</i> is the UI gadget's name (ex. "helloUG-efl")
589
590 Third, the <i>mode</i> could be UG_MODE_FULLVIEW to show the UI gadget as fullview, or UG_MODE_FRAMEVIEW to show it as frameview.
591
592 Fourth, the <i>service</i> is arguments for the UI gadget which is service type (see \ref service_PG "Tizen Managed API Reference Guide")
593
594 \warning After create UI gadget, you have to release the argument using <b>service_destroy()</b> API.
595
596 Fifth, the <i>cbs</i> is data describing layout callback, result callback, destroy callback, and private data. In detail, layout callback is used for layout arrangement, and it invoked after the UI gadget is created, and result callback is invoked to receive result from the UI gadget. And destroy callback is invoked to deal with destroy request from the UI gadget.
597
598 \warning Result data of the result callback is service type data, named <i>result</i>. <b>Because the result data is released after result callback is finished</b>, if you want to keep using it, please use <b>service_clone()</b> which duplicates given service data (see \ref service_PG "Tizen Managed API Reference Guide")
599
600 Using ug_create(), you can create UI gadget. After UI Gadget create operation is completed, layout callback function is called with base layout for layout arrangement (See Picture 2-11).<br><br>
601
602 \image html SLP_UI_Gadget_PG_image2-11.png "Picture 2-11. Create UI gadget"
603
604 The registered callback functions like result_cb or destroy_cb by caller is called when the UI gadget request sending result or destroy operation. <br><br>
605 When UI gadget requests to UI gadget library for sending result to caller using ug_send_result(), UI gadget library calls result callback function which is registered by caller(See Picture 2-12).<br><br>
606
607 \image html SLP_UI_Gadget_PG_image2-12.png "Picture 2-12. Send result"
608
609 And using ug_destroy_me(), UI gadget sends the destroy request to caller (See Picture 2-13). UI gadget cannot destroy itself, so it should request to caller.<br><br>
610
611 \image html SLP_UI_Gadget_PG_image2-13.png "Picture 2-13. Destroy request"
612
613 \note <b>Prototype of ug_create() (See API reference guide):</b>
614 @code
615 ui_gadget_h ug_create (ui_gadget_h parent,
616                         const char *name,
617                         enum ug_mode mode,
618                         service_h service,
619                         struct ug_cbs *cbs);
620
621 \note <b>struct ug_cbs</b> is describing some callbacks and private data:
622 @code
623 struct ug_cbs {
624         void (*layout_cb)(ui_gadget_h ug, enum ug_mode mode, void *priv);
625         void (*result_cb)(ui_gadget_h ug, service result, void *priv);
626         void (*destroy_cb)(ui_gadget_h ug, void *priv);
627         void *priv;
628 };
629 @endcode
630
631 Here are some examples:
632
633 @code
634 // FULLVIEW example
635 struct my_data {
636         ui_gadget_h ug;
637 };
638
639 static void layout_cb(ui_gadget_h ug, enum ug_mode mode, void *priv)
640 {
641         Evas_Object *base, *win;
642
643         if (!ug || !priv)
644                 return;
645
646         base = ug_get_layout(ug);
647         if (!base)
648                 return;
649
650         switch (mode) {
651         case UG_MODE_FULLVIEW:
652                 win = ug_get_window();
653                 if (!win)
654                         return;
655                 evas_object_size_hint_weight_set(base, EVAS_HINT_EXPAND, EVAS_HINT_EXPAND);
656                 elm_win_resize_object_add(win, base);
657                 ug_disable_effect(ug);
658                 evas_object_show(base);
659                 break;
660         default:
661                 break;
662         }
663 }
664
665 static void result_cb(ui_gadget_h ug, service result, void *priv)
666 {
667         struct my_data *mydata;
668         const char *val;
669
670         if (!ug || !priv)
671                 return;
672
673         mydata = priv;
674         if (result) {
675                 service_get_extra_data(result, "name", val);
676                 if (val)
677                         fprintf(stderr, "The name of UI gadget that sends result is %s\n", val);
678         }
679         ug_destroy(ug);
680         mydata->ug = NULL;
681
682 }
683
684 static void destroy_cb(ui_gadget_h ug, void *priv)
685 {
686         struct my_data *mydata;
687
688         if (!ug || !priv)
689                 return;
690
691         mydata = priv;
692
693         ug_destroy(ug);
694         mydata->ug = NULL;
695 }
696
697 ui_gadget_h create_ug(struct my_data *data)
698 {
699         ui_gadget_h ug;
700         struct ug_cbs cbs = {0, };
701
702         cbs.layout_cb = layout_cb;
703         cbs.result_cb = result_cb;
704         cbs.destroy_cb = destroy_cb;
705         cbs.priv = (void *)data;
706
707         ug = ug_create(NULL, "helloUG-efl", UG_MODE_FULLVIEW, NULL, &cbs);
708
709         return ug;
710 }
711 @endcode
712
713 @code
714 // FRAMEVIEW example
715 struct my_data {
716         ui_gadget_h ug;
717         Evas_Object *main_layout;
718 };
719
720 static void layout_cb(ui_gadget_h ug, enum ug_mode mode, void *priv)
721 {
722         Evas_Object *base, *win;
723         struct my_data *mydata;
724
725         if (!ug || !priv)
726                 return;
727
728         mydata = priv;
729
730         base = ug_get_layout(ug);
731         if (!base)
732                 return;
733
734         switch (mode) {
735                 case UG_MODE_FRAMEVIEW:
736                         elm_layout_content_set(mydata->main_layout, "content", base);
737                         break;
738                 default:
739                         break;
740         }
741 }
742
743 static void result_cb(ui_gadget_h ug, service result, void *priv)
744 {
745         struct my_data *mydata;
746         const char *val;
747
748         if (!ug || !priv)
749                 return;
750
751         mydata = priv;
752
753         if (result) {
754                 service_get_extra_data(result, "name", val);
755                 if (val)
756                         fprintf(stderr, "The name of UI gadget that sends result is %s\n", val);
757         }
758
759         ug_destroy(ug);
760         mydata->ug = NULL;
761
762 }
763
764 static void destroy_cb(ui_gadget_h ug, void *priv)
765 {
766         struct my_data *mydata;
767
768         if (!ug || !priv)
769                 return;
770
771         mydata = priv;
772
773         ug_destroy(ug);
774         mydata->ug = NULL;
775 }
776
777 ui_gadget_h create_ug(struct my_data *data)
778 {
779         ui_gadget_h ug;
780         struct ug_cbs cbs = {0, };
781
782         cbs.layout_cb = layout_cb;
783         cbs.result_cb = result_cb;
784         cbs.destroy_cb = destroy_cb;
785         cbs.priv = (void *)data;
786
787         ug = ug_create(NULL, "helloUG-efl", UG_MODE_FRAMEVIEW, NULL, &cbs);
788
789         return ug;
790 }
791 @endcode
792
793 <br>
794 <h2 class="pg">Send message</h2>
795
796 We provide API for sending message: <b>ug_send_message()</b>. When you send a message, you have to use service type data (see \ref service_PG "Tizen Managed API Reference Guide"). (See Picture 2-14)
797
798 \note <b>Prototype of ug_send_message() (See API reference guide):</b>
799 @code
800 int ug_send_message (ui_gadget_h ug, service msg);
801 @endcode
802
803 \image html SLP_UI_Gadget_PG_image2-14.png "Picture 2-14. Send message"
804
805 \warning After send your message, you have to release it using <b>service_destroy()</b> API.
806 @code
807 //example
808         service_h msg;
809
810         ret = service_create(&msg);
811
812         service_add_extra_data(msg, "name", "hello-UG");
813         service_add_extra_data(msg, "description", "sample UI gadget");
814
815         //Send message
816         ug_send_message(ug, msg);
817
818         //release service
819         service_destroy(msg);
820 @endcode
821
822 <br>
823 <h2 class="pg">Event propagation</h2>
824
825 If you are UI gadget developer who is trying to use UI gadgets, please skip this section. This section is for application developers who use UI gadgets.
826
827 We provide some APIs for event propagation: <b>ug_pause(), ug_resume(), and ug_send_event()</b>. <b>ug_pause()</b> and <b>ug_resume()</b> are used for task-managing. If the application is put into background, invoke <b>ug_pause()</b>, otherwise, if the application is brought to the foreground, invoke <b>ug_resume()</b>. <b>ug_send_event()</b> is used for system event: <i>low memory, low battery, language change, region change, rotate portrait, rotate portrait upside-down, rotate landscape, and rotate landscape upside-down.</i>
828
829 \note <b>Prototype of ug_pause(), ug_resume(), and ug_send_event() (See API reference guide):</b>
830 @code
831 int ug_pause (void);
832 int ug_resume (void);
833 int ug_send_event (enum ug_event event);
834 @endcode
835
836 \image html SLP_UI_Gadget_PG_image2-15.png "Picture 2-15. Pause event propagation"
837 \image html SLP_UI_Gadget_PG_image2-16.png "Picture 2-16. Resume event propagation"
838 \image html SLP_UI_Gadget_PG_image2-17.png "Picture 2-17. System event propagation"
839
840 <br>
841 <h2 class="pg">Destroy all UI gadgets</h2>
842
843 If you are UI gadget developer who is trying to use UI gadgets, please skip this section. This section is for application developers who use UI gadgets.
844
845 When you terminate your application, destroy all UI gadgets using <b>ug_destroy_all()</b>.
846
847 \note <b>Prototype of ug_destroy_all(See API reference guide): </b>
848 @code
849 int ug_destroy_all (void);
850 @endcode
851
852 <br>
853 <h2 class="pg">Disable UI gadget effect</h2>
854
855 We provide API for disabling transition effect: <i>ug_disable_effect</i>. If you want to disable showing/hiding transition effect when create and destroy a UI Gadget, <i>ug_disable_effect</i> should be called before show UI Gadget layout.
856
857 \note <b>Prototype of ug_disable_effect(See API reference guide): </b>
858 @code
859 int ug_disable_effect (void);
860 @endcode
861
862 Here are some examples:
863
864 @code
865 To disable transition effect :
866
867         static void layout_cb(struct ui_gadget *ug, enum ug_mode mode, void *priv)
868         {
869                 Evas_Object *base, *win;
870                 if (!ug || !priv)
871                         return;
872                 base = ug_get_layout(ug);
873                 if (!base)
874                         return;
875
876                 win = ug_get_window();
877                 switch (mode) {
878                 case UG_MODE_FULLVIEW:
879                         evas_object_size_hint_weight_set(base, EVAS_HINT_EXPAND, EVAS_HINT_EXPAND);
880                         elm_win_resize_object_add(win, base);
881                         // disable effect
882                         ug_disable_effect(ug);
883                         evas_object_show(base);
884                         break;
885                 default:
886                         break;
887         }
888 @endcode
889
890  * @}
891  */