tizen_2.0_build
[apps/home/draglock.git] / src / draglock-util.c
1 /*
2  * Copyright 2012  Samsung Electronics Co., Ltd
3  *
4  * Licensed under the Flora License, Version 1.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.tizenopensource.org/license
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 #include <app.h>
18 #include <Ecore_X.h>
19 #include "draglock.h"
20
21 static void _draglock_util_window_deleted_cb(void *data, Evas_Object *obj,
22                 void *event) {
23         app_efl_exit();
24 }
25
26 Evas_Object *draglock_util_add_window(const char *name) {
27         Evas_Object *obj_window = NULL;
28         int width = 0, height = 0;
29
30         obj_window = elm_win_add(NULL, name, ELM_WIN_BASIC);
31         if (obj_window != NULL) {
32                 elm_win_title_set(obj_window, name);
33                 elm_win_borderless_set(obj_window, EINA_TRUE);
34                 evas_object_smart_callback_add(obj_window, "delete,request",
35                                 _draglock_util_window_deleted_cb, NULL);
36                 ecore_x_window_size_get(ecore_x_window_root_first_get(), &width,
37                                 &height);
38                 evas_object_resize(obj_window, width, height);
39                 elm_win_indicator_mode_set(obj_window, ELM_WIN_INDICATOR_SHOW);
40                 elm_win_alpha_set(obj_window, EINA_TRUE);
41         }
42
43         return obj_window;
44 }
45
46 Evas_Object *draglock_util_add_bg(Evas_Object *window) {
47         Evas_Object *obj_background = NULL;
48
49         if (window == NULL) {
50                 return NULL;
51         }
52
53         obj_background = elm_bg_add(window);
54
55         if (obj_background != NULL) {
56                 evas_object_size_hint_weight_set(obj_background, EVAS_HINT_EXPAND,
57                                 EVAS_HINT_EXPAND);
58                 elm_object_style_set(obj_background, "transparent");
59
60                 elm_win_resize_object_add(window, obj_background);
61
62                 evas_object_show(obj_background);
63         }
64
65         return obj_background;
66 }
67
68 Evas_Object *draglock_util_add_layout(Evas_Object *parent, const char *file,
69                 const char *group) {
70         Evas_Object *layout = NULL;
71         Eina_Bool ret = EINA_FALSE;
72
73         if (parent == NULL) {
74                 DRAGLOCK_ERR("parent is NULL");
75                 return NULL;
76         }
77
78         layout = elm_layout_add(parent);
79         if (layout == NULL) {
80                 DRAGLOCK_ERR("layout is NULL");
81                 return NULL;
82         }
83
84         ret = elm_layout_file_set(layout, file, group);
85         DRAGLOCK_DBG("File:%s, Group:%s", file, group);
86         if (ret != EINA_TRUE) {
87                 DRAGLOCK_DBG("File:%s, Group:%s", file, group);
88                 evas_object_del(layout);
89                 return NULL;
90         }
91         evas_object_size_hint_weight_set(layout, EVAS_HINT_EXPAND,
92                         EVAS_HINT_EXPAND);
93         evas_object_show(layout);
94
95         return layout;
96 }