3 * Copyright (c) 2015 Samsung Electronics Co., Ltd.
5 * Licensed under the Apache License, Version 2.0 (the License);
6 * you may not use this file except in compliance with the License.
7 * You may obtain a copy of the License at
9 * http://www.apache.org/license/
11 * Unless required by applicable law or agreed to in writing, software
12 * distributed under the License is distributed on an AS IS BASIS,
13 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14 * See the License for the specific language governing permissions and
15 * limitations under the License.
19 #include <app_control.h>
20 #include <Elementary.h>
21 #include <efl_extension.h>
23 #include "attach_panel.h"
28 const char *const KEY_BACK = "XF86Back";
29 const char *const LAYOUT = "/usr/share/attach-panel/sample/sample.edj";
37 Evas_Object *conformant;
38 attach_panel_h attach_panel;
55 static void _rotate_cb(void *data, Evas_Object *obj, void *event)
61 angle = elm_win_rotation_get(obj);
63 _D("Angle is %d degree", angle);
68 evas_object_size_hint_min_set(obj, sample_info.root_w, sample_info.root_h);
69 evas_object_resize(obj, sample_info.root_w, sample_info.root_h);
70 evas_object_move(obj, 0, 0);
74 evas_object_size_hint_min_set(obj, sample_info.root_h, sample_info.root_w);
75 evas_object_resize(obj, sample_info.root_h, sample_info.root_w);
76 evas_object_move(obj, 0, 0);
79 _E("cannot reach here");
85 static void _result_cb(attach_panel_h attach_panel, attach_panel_content_category_e content_category, app_control_h result, app_control_result_e result_code, void *user_data)
90 int ret = APP_CONTROL_ERROR_NONE;
94 ret = app_control_get_extra_data_array(result, "http://tizen.org/appcontrol/data/selected", &select, &length);
95 if (APP_CONTROL_ERROR_NONE == ret) {
96 for (i = 0; i < length; i++) {
97 _D("file_path is %s[%d]", select[i], i);
98 elm_object_part_text_set(sample_info.layout, "result", select[i]);
108 static void _event_cb(attach_panel_h attach_panel, attach_panel_event_e event, void *event_info, void *data)
110 ret_if(!attach_panel);
113 case ATTACH_PANEL_EVENT_SHOW_START:
114 _D("attach panel : show start");
116 case ATTACH_PANEL_EVENT_SHOW_FINISH:
117 _D("attach panel : show finish");
119 case ATTACH_PANEL_EVENT_HIDE_START:
120 _D("attach panel : hide start");
122 case ATTACH_PANEL_EVENT_HIDE_FINISH:
123 _D("attach panel : hide finish");
130 static void _win_back_key_cb(void *data, Evas_Object *obj, void *event_info)
132 bool visible = false;
134 if (sample_info.attach_panel) {
135 if (attach_panel_get_visibility(sample_info.attach_panel, &visible) != ATTACH_PANEL_ERROR_NONE) {
136 _E("Fail to get visible of attach panel");
140 _D("attach panel state : show->hide");
141 attach_panel_hide(sample_info.attach_panel);
143 attach_panel_remove_content_category(sample_info.attach_panel, ATTACH_PANEL_CONTENT_CATEGORY_IMAGE);
144 attach_panel_remove_content_category(sample_info.attach_panel, ATTACH_PANEL_CONTENT_CATEGORY_CAMERA);
145 attach_panel_remove_content_category(sample_info.attach_panel, ATTACH_PANEL_CONTENT_CATEGORY_VOICE);
146 attach_panel_remove_content_category(sample_info.attach_panel, ATTACH_PANEL_CONTENT_CATEGORY_VIDEO);
147 attach_panel_remove_content_category(sample_info.attach_panel, ATTACH_PANEL_CONTENT_CATEGORY_AUDIO);
148 attach_panel_remove_content_category(sample_info.attach_panel, ATTACH_PANEL_CONTENT_CATEGORY_CALENDAR);
149 attach_panel_remove_content_category(sample_info.attach_panel, ATTACH_PANEL_CONTENT_CATEGORY_CONTACT);
150 attach_panel_remove_content_category(sample_info.attach_panel, ATTACH_PANEL_CONTENT_CATEGORY_MYFILES);
151 attach_panel_remove_content_category(sample_info.attach_panel, ATTACH_PANEL_CONTENT_CATEGORY_VIDEO_RECORDER);
153 attach_panel_unset_result_cb(sample_info.attach_panel);
154 attach_panel_unset_event_cb(sample_info.attach_panel);
156 attach_panel_destroy(sample_info.attach_panel);
157 sample_info.attach_panel = NULL;
166 static void _attach_panel_cancel_cb(void *data, Evas_Object *obj, const char *emission, const char *source)
170 if (sample_info.attach_panel) {
171 attach_panel_remove_content_category(sample_info.attach_panel, ATTACH_PANEL_CONTENT_CATEGORY_IMAGE);
172 attach_panel_remove_content_category(sample_info.attach_panel, ATTACH_PANEL_CONTENT_CATEGORY_CAMERA);
173 attach_panel_remove_content_category(sample_info.attach_panel, ATTACH_PANEL_CONTENT_CATEGORY_VOICE);
174 attach_panel_remove_content_category(sample_info.attach_panel, ATTACH_PANEL_CONTENT_CATEGORY_VIDEO);
175 attach_panel_remove_content_category(sample_info.attach_panel, ATTACH_PANEL_CONTENT_CATEGORY_AUDIO);
176 attach_panel_remove_content_category(sample_info.attach_panel, ATTACH_PANEL_CONTENT_CATEGORY_CALENDAR);
177 attach_panel_remove_content_category(sample_info.attach_panel, ATTACH_PANEL_CONTENT_CATEGORY_CONTACT);
178 attach_panel_remove_content_category(sample_info.attach_panel, ATTACH_PANEL_CONTENT_CATEGORY_MYFILES);
179 attach_panel_remove_content_category(sample_info.attach_panel, ATTACH_PANEL_CONTENT_CATEGORY_VIDEO_RECORDER);
181 attach_panel_hide(sample_info.attach_panel);
182 attach_panel_unset_result_cb(sample_info.attach_panel);
183 attach_panel_unset_event_cb(sample_info.attach_panel);
185 attach_panel_destroy(sample_info.attach_panel);
186 sample_info.attach_panel = NULL;
192 static void _attach_panel_create_cb(void *data, Evas_Object *obj, void *event_info)
194 attach_panel_h attach_panel = NULL;
195 int ret = ATTACH_PANEL_ERROR_NONE;
196 bool visible = false;
198 if (sample_info.attach_panel) {
199 _D("attach panel already existed");
200 if (attach_panel_get_visibility(sample_info.attach_panel, &visible) != ATTACH_PANEL_ERROR_NONE) {
201 _E("Fail to get visible of attach panel");
205 _D("attach panel state : hide->show");
206 attach_panel_show(sample_info.attach_panel);
211 ret = attach_panel_create(sample_info.conformant, &attach_panel);
212 ret_if(ATTACH_PANEL_ERROR_NONE != ret);
214 attach_panel_add_content_category(attach_panel, ATTACH_PANEL_CONTENT_CATEGORY_IMAGE, NULL);
215 attach_panel_add_content_category(attach_panel, ATTACH_PANEL_CONTENT_CATEGORY_CAMERA, NULL);
216 attach_panel_add_content_category(attach_panel, ATTACH_PANEL_CONTENT_CATEGORY_VOICE, NULL);
217 attach_panel_add_content_category(attach_panel, ATTACH_PANEL_CONTENT_CATEGORY_VIDEO, NULL);
218 attach_panel_add_content_category(attach_panel, ATTACH_PANEL_CONTENT_CATEGORY_AUDIO, NULL);
219 attach_panel_add_content_category(attach_panel, ATTACH_PANEL_CONTENT_CATEGORY_CALENDAR, NULL);
220 attach_panel_add_content_category(attach_panel, ATTACH_PANEL_CONTENT_CATEGORY_CONTACT, NULL);
221 attach_panel_add_content_category(attach_panel, ATTACH_PANEL_CONTENT_CATEGORY_MYFILES, NULL);
222 attach_panel_add_content_category(attach_panel, ATTACH_PANEL_CONTENT_CATEGORY_VIDEO_RECORDER, NULL);
223 attach_panel_set_result_cb(attach_panel, _result_cb, NULL);
224 attach_panel_set_event_cb(attach_panel, _event_cb, NULL);
226 attach_panel_show(attach_panel);
228 sample_info.attach_panel = attach_panel;
233 static Evas_Object *_create_entry(Evas_Object *layout)
235 Evas_Object *entry = NULL;
237 retv_if(!layout, NULL);
239 entry = elm_entry_add(layout);
240 retv_if(!entry, NULL);
242 elm_entry_scrollable_set(entry, EINA_TRUE);
243 elm_object_part_text_set(entry, "elm.guide", "search");
245 elm_object_part_content_set(layout, "entry", entry);
247 elm_entry_cnp_mode_set(entry, ELM_CNP_MODE_PLAINTEXT);
248 elm_entry_input_panel_layout_set(entry, ELM_INPUT_PANEL_LAYOUT_NORMAL);
249 elm_entry_prediction_allow_set(entry, EINA_FALSE);
250 elm_entry_autocapital_type_set(entry, ELM_AUTOCAPITAL_TYPE_NONE);
251 elm_entry_input_panel_return_key_type_set(entry, ELM_INPUT_PANEL_RETURN_KEY_TYPE_DONE);
252 elm_entry_input_panel_return_key_disabled_set(entry, EINA_FALSE);
254 evas_object_show(entry);
261 static void _destroy_entry(Evas_Object *layout)
263 Evas_Object *entry = NULL;
266 entry = elm_object_part_content_unset(layout, "entry");
270 evas_object_del(entry);
275 static Evas_Object *_create_button(Evas_Object *layout)
277 Evas_Object *button = NULL;
279 retv_if(!layout, NULL);
281 button = elm_button_add(layout);
282 retv_if(!button, NULL);
284 elm_object_text_set(button, "attach");
285 elm_object_part_content_set(layout, "button", button);
286 evas_object_size_hint_weight_set(button, EVAS_HINT_EXPAND, EVAS_HINT_EXPAND);
287 evas_object_show(button);
289 evas_object_smart_callback_add(button, "clicked", _attach_panel_create_cb, NULL);
296 static void _destroy_button(Evas_Object *layout)
298 Evas_Object *button = NULL;
300 button = elm_object_part_content_unset(layout, "button");
305 evas_object_smart_callback_del(button, "clicked", _attach_panel_create_cb);
306 evas_object_del(button);
311 static void _destroy_layout(void)
313 ret_if(!sample_info.layout);
315 _destroy_button(sample_info.layout);
316 _destroy_entry(sample_info.layout);
318 elm_object_signal_callback_del(sample_info.layout, "bg,up", "bg", _attach_panel_cancel_cb);
320 if (sample_info.conformant) {
321 elm_object_content_unset(sample_info.conformant);
323 evas_object_del(sample_info.layout);
324 sample_info.layout = NULL;
329 static Evas_Object *_create_layout(Evas_Object *parent)
331 Evas_Object *layout = NULL;
332 Eina_Bool ret = EINA_FALSE;
334 retv_if(!parent, NULL);
336 layout = elm_layout_add(parent);
337 goto_if(!layout, ERROR);
339 ret = elm_layout_file_set(layout, LAYOUT, "layout");
340 goto_if(EINA_FALSE == ret, ERROR);
342 evas_object_size_hint_weight_set(layout, EVAS_HINT_EXPAND, EVAS_HINT_EXPAND);
343 evas_object_size_hint_align_set(layout, EVAS_HINT_FILL, EVAS_HINT_FILL);
344 evas_object_show(layout);
345 elm_object_signal_callback_add(layout, "bg,up", "bg", _attach_panel_cancel_cb, NULL);
347 goto_if(!_create_entry(layout), ERROR);
348 goto_if(!_create_button(layout), ERROR);
350 elm_object_content_set(parent, layout);
362 static Evas_Object *_create_bg(Evas_Object *parent)
364 Evas_Object *bg = NULL;
365 retv_if(!parent, NULL);
367 bg = elm_bg_add(parent);
369 evas_object_size_hint_weight_set(bg, EVAS_HINT_EXPAND, EVAS_HINT_EXPAND);
370 elm_win_resize_object_add(parent, bg);
372 evas_object_show(bg);
379 static void _destroy_bg(void)
381 ret_if(!sample_info.bg);
382 evas_object_del(sample_info.bg);
383 sample_info.bg = NULL;
388 static void _destroy_conformant(void)
390 ret_if(!sample_info.conformant);
391 evas_object_del(sample_info.conformant);
392 sample_info.conformant = NULL;
397 static Evas_Object *_create_conformant(Evas_Object *parent)
399 Evas_Object *conformant = NULL;
400 retv_if(!parent, NULL);
402 conformant = elm_conformant_add(parent);
403 retv_if(!conformant, NULL);
405 elm_win_indicator_mode_set(parent, ELM_WIN_INDICATOR_SHOW);
406 elm_win_indicator_opacity_set(parent, ELM_WIN_INDICATOR_OPAQUE);
407 evas_object_size_hint_weight_set(conformant, EVAS_HINT_EXPAND, EVAS_HINT_EXPAND);
408 elm_win_resize_object_add(parent, conformant);
409 elm_win_conformant_set(parent, EINA_TRUE);
411 evas_object_show(conformant);
418 static void _create_cb(void)
420 Evas_Object *layout = NULL;
421 Evas_Object *conformant = NULL;
422 Evas_Object *bg = NULL;
424 sample_info.win = elm_win_add(NULL, "Attach Panel Sample", ELM_WIN_BASIC);
425 ret_if(!sample_info.win);
427 elm_app_base_scale_set(1.7);
429 elm_win_title_set(sample_info.win, "Attach Panel");
430 elm_win_alpha_set(sample_info.win, EINA_FALSE);
431 elm_win_borderless_set(sample_info.win, EINA_TRUE);
432 elm_win_autodel_set(sample_info.win, EINA_TRUE);
433 elm_win_raise(sample_info.win);
435 evas_object_show(sample_info.win);
437 elm_win_screen_size_get(sample_info.win, NULL, NULL, &sample_info.root_w, &sample_info.root_h);
438 _D("screen size is (%d, %d)", sample_info.root_w, sample_info.root_h);
441 if (elm_win_wm_rotation_supported_get(sample_info.win)) {
442 int rots[4] = { 0, 90, 180, 270 };
443 elm_win_wm_rotation_available_rotations_set(sample_info.win, rots, 4);
446 eext_object_event_callback_add(sample_info.win, EEXT_CALLBACK_BACK, _win_back_key_cb, NULL);
447 evas_object_smart_callback_add(sample_info.win, "wm,rotation,changed", _rotate_cb, NULL);
449 bg = _create_bg(sample_info.win);
452 conformant = _create_conformant(sample_info.win);
453 goto_if(!conformant, ERROR);
455 layout = _create_layout(conformant);
456 goto_if(!layout, ERROR);
458 sample_info.layout = layout;
459 sample_info.conformant = conformant;
465 _D("there is some error");
467 _destroy_conformant();
473 if (sample_info.win) {
474 evas_object_del(sample_info.win);
475 eext_object_event_callback_del(sample_info.win, EEXT_CALLBACK_BACK, _win_back_key_cb);
476 sample_info.win = NULL;
482 static void _terminate_cb(void)
487 _destroy_conformant();
490 if (sample_info.win) {
491 eext_object_event_callback_del(sample_info.win, EEXT_CALLBACK_BACK, _win_back_key_cb);
492 evas_object_del(sample_info.win);
493 sample_info.win = NULL;
499 int main(int argc, char **argv)
501 elm_init(argc, argv);