Adapt (part 2)
[platform/core/security/ima-evm-reference-utils.git] / src / im-uigadget.c
1 /**
2  * Copyright (c) 2014 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  * @file        im-uigadget.c
18  * @author      Janusz Kozerski (j.kozerski@samsung.com)
19  * @version     1.0
20  * @brief
21  */
22
23 #ifndef UG_MODULE_API
24 #define UG_MODULE_API __attribute__ ((visibility("default")))
25 #endif
26
27 #include "im-uigadget.h"
28 #include "im-main-menu.h"
29
30 static void _win_del(void *data, Evas_Object * obj, void *event_info)
31 {
32     printf("Enter function: %s\n", __func__);
33     (void)data;
34     (void)obj;
35     (void)event_info;
36     elm_exit();
37 }
38
39
40 static Evas_Object *_create_win(const char *name)
41 {
42     printf("Enter function: %s\n", __func__);
43     Evas_Object *eo;
44     //int w, h;
45     eo = elm_win_add(NULL, name, ELM_WIN_BASIC);
46     if (eo) {
47         elm_win_title_set(eo, name);
48         evas_object_smart_callback_add(eo, "delete,request", _win_del, NULL );
49        // elm_win_screen_size_get(eo, NULL, NULL, &w, &h);
50         {
51          //   h /= 2;
52          //   w /= 2;
53             //int t = h * 3. / 4.;
54             //w = (t < w) ? t : w;
55         }
56         // FIXME: Hardcoded size
57         evas_object_resize(eo, 1000, 1000);
58     }
59     return eo;
60 }
61
62
63 static bool on_create(void *data)
64 {
65     printf("Enter function: %s\n", __func__);
66     if (NULL == data)
67         return EINA_FALSE;
68
69     bindtextdomain(PACKAGE, LOCALEDIR);
70
71     struct ug_data *ugd = data;
72
73     ugd->win_main = _create_win(PACKAGE);
74     if (ugd->win_main == NULL) {
75         return EINA_FALSE;
76     }
77     evas_object_show(ugd->win_main);
78     elm_win_indicator_mode_set(ugd->win_main, ELM_WIN_INDICATOR_SHOW);
79
80     ugd->bg = elm_bg_add(ugd->win_main);
81     if (!ugd->bg) {
82         LOGD("ugd->bg is null");
83         free(ugd->win_main);
84         return EINA_FALSE;
85     }
86     elm_win_resize_object_add(ugd->win_main, ugd->bg);
87 //  evas_object_size_hint_weight_set(ugd->bg, EVAS_HINT_EXPAND, EVAS_HINT_EXPAND);
88     evas_object_size_hint_weight_set(ugd->bg, EVAS_HINT_FILL, EVAS_HINT_FILL);
89     evas_object_resize(ugd->bg, 1000, 1000);
90     evas_object_show(ugd->bg);
91
92
93     ugd->layout_main = elm_layout_add(ugd->win_main);
94
95     if (!ugd->layout_main) {
96         LOGD("ugd->layout_main is null");
97         free(ugd->win_main);
98         free(ugd->bg);
99         return EINA_FALSE;
100     }
101
102     ugd->theme = elm_theme_new();
103     elm_theme_set(ugd->theme, "tizen-HD-dark");
104
105     elm_object_theme_set(ugd->layout_main, ugd->theme);
106     elm_layout_theme_set(ugd->layout_main, "layout", "application", "default");
107     //evas_object_size_hint_weight_set(ugd->layout_main, EVAS_HINT_EXPAND, EVAS_HINT_EXPAND);
108     evas_object_size_hint_weight_set(ugd->layout_main, EVAS_HINT_FILL, EVAS_HINT_FILL);
109     //evas_object_size_hint_min_set(ugd->layout_main, 600, 400);
110     evas_object_resize(ugd->layout_main, 1000, 1000);
111     evas_object_show(ugd->layout_main);
112
113     elm_object_part_content_set(ugd->layout_main, "elm.swallow.bg", ugd->bg);
114
115     ugd->navi_bar = elm_naviframe_add(ugd->layout_main);
116     if (!ugd->navi_bar) {
117         LOGD("ugd->navi_bar is null");
118         free(ugd->win_main);
119         free(ugd->bg);
120         free(ugd->layout_main);
121         return EINA_FALSE;
122     }
123     elm_object_part_content_set(ugd->layout_main, "elm.swallow.content", ugd->navi_bar);
124     evas_object_show(ugd->navi_bar);
125
126     im_main_menu_cb((void*) ugd, NULL, NULL);
127
128     return EINA_TRUE;
129 }
130
131 static void on_pause(void *priv)
132 {
133     printf("Enter function: %s\n", __func__);
134     (void)priv;
135 }
136
137 static void on_resume(void *priv)
138 {
139     printf("Enter function: %s\n", __func__);
140     (void)priv;
141 }
142
143 static void on_destroy(void *priv)
144 {
145     printf("Enter function: %s\n", __func__);
146     if (NULL == priv) {
147         LOGD("NULL == priv; return");
148         return;
149     }
150
151     struct ug_data *ugd = priv;
152
153     if (ugd->theme) {
154         elm_theme_free(ugd->theme);
155         ugd->theme = NULL;
156     }
157
158     evas_object_del(ugd->layout_main);
159     ugd->layout_main = NULL;
160 }
161
162 //static void _tmp(void *priv)
163 //{
164 //    (void)priv;
165 //    printf("Enter function: %s\n", __func__);
166 //}
167 //
168 //static  void _tmp2(app_device_orientation_e  mode, void *priv)
169 //{
170 //    (void)priv;
171 //    (void)mode;
172 //    printf("Enter function: %s\n", __func__);
173 //}
174
175 int main(int argc, char *argv[])
176 {
177     printf("Enter function: %s\n", __func__);
178     struct ug_data ugd;
179     memset(&ugd, 0x0, sizeof(struct ug_data));
180
181     app_event_callback_s event_callback;
182
183     event_callback.create    = on_create;
184     event_callback.pause     = on_pause;
185     event_callback.resume    = on_resume;
186     event_callback.terminate = on_destroy;
187
188     event_callback.service               = NULL;
189     event_callback.low_memory            = NULL;
190     event_callback.low_battery           = NULL;
191     event_callback.device_orientation    = NULL;
192     event_callback.language_changed      = NULL;
193     event_callback.region_format_changed = NULL;
194 //    event_callback.service               = NULL;
195 //    event_callback.low_memory            = _tmp;
196 //    event_callback.low_battery           = _tmp;
197 //    event_callback.device_orientation    = _tmp2;
198 //    event_callback.language_changed      = _tmp;
199 //    event_callback.region_format_changed = _tmp;
200
201     int ret = app_efl_main(&argc, &argv, &event_callback, &ugd);
202     switch (ret) {
203     case APP_ERROR_NONE:
204         printf("APP_ERROR_NONE\n");
205         break;
206     case APP_ERROR_INVALID_PARAMETER:
207         printf("APP_ERROR_INVALID_PARAMETER\n");
208         break;
209     case APP_ERROR_INVALID_CONTEXT:
210         printf("APP_ERROR_INVALID_CONTEXT\n");
211         break;
212     case APP_ERROR_ALREADY_RUNNING:
213         printf("APP_ERROR_ALREADY_RUNNING\n");
214         break;
215     default:
216         printf("Unknown error\n");
217         break;
218     }
219
220     printf("return function: %s (%d)\n", __func__, ret);
221     return ret;
222 }