File Manager / src / view /
  1. /*
  2. * Copyright 2014 -2015 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.  
  18. #include "view/navi-bar-title.h"
  19. #include "view/navi-path-widget.h"
  20. #include "view/list-view.h"
  21. #include "view/navigator.h"
  22. #include "utils/ui-utils.h"
  23. #include "utils/model-utils.h"
  24. #include "utils/app-types.h"
  25. #include "utils/config.h"
  26. #include "utils/logger.h"
  27. #include "main-app.h"
  28.  
  29. void _navi_bar_title_widget_delete(title_widget *widget);
  30. static Evas_Object *_navi_bar_title_create_button(title_widget *widget,
  31. Evas_Object *parent_layout,
  32. const char *icon_id,
  33. const char *part,
  34. Evas_Smart_Cb cb_clicked,
  35. Evas_Smart_Cb cb_pressed,
  36. Evas_Smart_Cb cb_unpressed);
  37.  
  38.  
  39. void _navi_bar_title_widget_delete_cb(void *data, Evas *e, Evas_Object *obj,
  40. void *event_info);
  41.  
  42. static void _navi_bar_title_home_button_on_click_cb(void *data, Evas_Object *obj, void *eventInfo);
  43. static void _navi_bar_title_home_button_on_pressed_cb(void *data, Evas_Object *obj, void *eventInfo);
  44. static void _navi_bar_title_home_button_on_unpressed_cb(void *data, Evas_Object *obj, void *eventInfo);
  45.  
  46. static void _navi_bar_title_upper_button_on_click_cb(void *data, Evas_Object *obj, void *eventInfo);
  47. static void _navi_bar_title_upper_button_on_pressed_cb(void *data, Evas_Object *obj, void *eventInfo);
  48. static void _navi_bar_title_upper_button_on_unpressed_cb(void *data, Evas_Object *obj, void *eventInfo);
  49.  
  50. title_widget *navi_bar_title_widget_add(view_data *view)
  51. {
  52. RETVM_IF(!view, NULL, "View is NULL");
  53.  
  54. title_widget *data = calloc(1, sizeof(title_widget));
  55. RETVM_IF(!data, NULL, "Fail allocate memory");
  56.  
  57. data->view = view;
  58.  
  59. Evas_Object *btn = _navi_bar_title_create_button(data,
  60. data->view->navi_layout,
  61. ui_utils_get_resource(FM_TITLE_ICON_HOME),
  62. "title_left_btn",
  63. _navi_bar_title_home_button_on_click_cb,
  64. _navi_bar_title_home_button_on_pressed_cb,
  65. _navi_bar_title_home_button_on_unpressed_cb);
  66.  
  67. if (!btn) {
  68. ERR("Fail to create home button");
  69. _navi_bar_title_widget_delete(data);
  70. return NULL;
  71. }
  72.  
  73. elm_object_item_part_content_set(data->view->navi_item, "title_left_btn", btn);
  74.  
  75. btn = _navi_bar_title_create_button(data,
  76. data->view->navi_layout,
  77. ui_utils_get_resource(FM_TITLE_ICON_UPPER),
  78. "title_right_btn",
  79. _navi_bar_title_upper_button_on_click_cb,
  80. _navi_bar_title_upper_button_on_pressed_cb,
  81. _navi_bar_title_upper_button_on_unpressed_cb);
  82.  
  83. if (!btn) {
  84. ERR("Fail to create upper button");
  85. _navi_bar_title_widget_delete(data);
  86. return NULL;
  87. }
  88.  
  89. elm_object_item_part_content_set(data->view->navi_item, "title_right_btn", btn);
  90.  
  91. evas_object_event_callback_add(btn, EVAS_CALLBACK_FREE, _navi_bar_title_widget_delete_cb, data);
  92.  
  93. return data;
  94. }
  95.  
  96. void _navi_bar_title_widget_delete(title_widget *widget)
  97. {
  98. free(widget);
  99. }
  100.  
  101. void _navi_bar_title_widget_delete_cb(void *data, Evas *e, Evas_Object *obj,
  102. void *event_info)
  103. {
  104. _navi_bar_title_widget_delete(data);
  105. }
  106.  
  107. static Evas_Object *_navi_bar_title_create_button(title_widget *widget,
  108. Evas_Object *parent_layout,
  109. const char *icon_id,
  110. const char *part,
  111. Evas_Smart_Cb cb_clicked,
  112. Evas_Smart_Cb cb_pressed,
  113. Evas_Smart_Cb cb_unpressed)
  114. {
  115. Evas_Object *btn = elm_object_part_content_get(parent_layout, part);
  116. if (!btn) {
  117. btn = elm_button_add(parent_layout);
  118. RETVM_IF(!btn, NULL, "btn is NULL");
  119.  
  120. elm_object_style_set(btn, "naviframe/title_icon");
  121.  
  122. Evas_Object *icon = elm_image_add(parent_layout);
  123. RETVM_IF(!icon, NULL, "Icon is NULL");
  124.  
  125. elm_image_file_set(icon, icon_id, NULL);
  126. elm_image_resizable_set(icon, EINA_TRUE, EINA_TRUE);
  127. elm_object_content_set(btn, icon);
  128. evas_object_smart_callback_add(btn, "clicked" , cb_clicked , widget);
  129. evas_object_smart_callback_add(btn, "pressed" , cb_pressed , icon);
  130. evas_object_smart_callback_add(btn, "unpressed", cb_unpressed, icon);
  131. evas_object_show(btn);
  132.  
  133. elm_object_part_content_set(parent_layout, part, btn);
  134. }
  135.  
  136. return btn;
  137. }
  138.  
  139. static void _navi_bar_title_home_button_on_click_cb(void *data, Evas_Object *obj, void *eventInfo)
  140. {
  141. RETM_IF(!data, "Data is NULL");
  142.  
  143. title_widget *widget = data;
  144. app_data *app = widget->view->app;
  145.  
  146. int res = navigator_goto_root_view(app->navigator);
  147. RETM_IF(res != RESULT_TYPE_OK, "Fail to navigate to root view");
  148.  
  149. }
  150.  
  151. static void _navi_bar_title_home_button_on_pressed_cb(void *data, Evas_Object *obj, void *eventInfo)
  152. {
  153. RETM_IF(!data, "Data is NULL");
  154.  
  155. Evas_Object *home_button_ic = data;
  156. elm_image_file_set(home_button_ic, ui_utils_get_resource(FM_TITLE_ICON_HOME_PRESS), NULL);
  157. }
  158.  
  159. static void _navi_bar_title_home_button_on_unpressed_cb(void *data, Evas_Object *obj, void *eventInfo)
  160. {
  161. RETM_IF(!data, "Data is NULL");
  162.  
  163. Evas_Object *home_button_ic = data;
  164. elm_image_file_set(home_button_ic, ui_utils_get_resource(FM_TITLE_ICON_HOME), NULL);
  165. }
  166.  
  167. static void _navi_bar_title_upper_button_on_click_cb(void *data, Evas_Object *obj, void *eventInfo)
  168. {
  169. RETM_IF(!data, "Data is NULL");
  170.  
  171. title_widget *widget = data;
  172. app_data *app = widget->view->app;
  173.  
  174. int res = navigator_goto_previous_view(app->navigator);
  175. RETM_IF(res != RESULT_TYPE_OK, "Fail to navigate to previous view");
  176. }
  177.  
  178. static void _navi_bar_title_upper_button_on_pressed_cb(void *data, Evas_Object *obj, void *eventInfo)
  179. {
  180. RETM_IF(!data, "Data is NULL");
  181.  
  182. Evas_Object *upper_button_ic = data;
  183. elm_image_file_set(upper_button_ic, ui_utils_get_resource(FM_TITLE_ICON_UPPER_PRESS), NULL);
  184. }
  185.  
  186. static void _navi_bar_title_upper_button_on_unpressed_cb(void *data, Evas_Object *obj, void *eventInfo)
  187. {
  188. RETM_IF(!data, "Data is NULL");
  189.  
  190. Evas_Object *upper_button_ic = data;
  191. elm_image_file_set(upper_button_ic, ui_utils_get_resource(FM_TITLE_ICON_UPPER), NULL);
  192. }