3 * Copyright 2012 Samsung Electronics Co., Ltd
5 * Licensed under the Flora License, Version 1.1 (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://floralicense.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.
21 #include <appcore-efl.h>
22 #include <Elementary.h>
24 #include <memo_text_editor.h>
25 #include <memo_doodle_editor.h>
26 #include <extended-elm.h>
29 typedef struct __edit_view_t {
31 Evas_Object *navigator;
32 Elm_Object_Item *navi_it;
33 Evas_Object *body_main; /* content */
36 Eina_Bool drawing; /* drawing or text mode */
38 /* add more variables here */
42 extern Eina_Bool launch_by_new;
43 extern Eina_Bool is_previous_edit_view;
44 extern Eina_Bool normal_memo_launch;
45 static void _text_editor_callback(void *data, const char *msg, void *event);
46 static void _doodle_editor_callback(void *data, const char *msg, void *event);
48 static void _on_left_btn_clicked(void *data, Evas_Object *obj, void *event_info)
51 edit_view_t *ev = (edit_view_t *)data;
53 memo_doodle_editor_save(ev->h_ed);
55 memo_text_editor_save(ev->h_ed);
60 static void _on_right_btn_clicked(void *data, Evas_Object *obj, void *event_info)
63 edit_view_t *ev = (edit_view_t *)data;
65 memo_doodle_editor_cancel(ev->h_ed);
67 memo_text_editor_cancel(ev->h_ed);
72 static void _text_editor_callback(void *data, const char *msg, void *event)
75 edit_view_t *ev = (edit_view_t *)data;
76 if (strcmp(msg, "layout") == 0) {
77 elm_object_part_content_set(ev->body_main, "elm.swallow.content", (Evas_Object *)event);
78 } else if (strcmp(msg, "title") == 0) {
79 elm_object_item_text_set(ev->navi_it, (const char *)event);
80 } else if (strcmp(msg, "savable") == 0) {
81 elm_object_disabled_set(ev->l_btn, (int)event==0? EINA_TRUE:EINA_FALSE);
82 } else if (strcmp(msg, "save") == 0) {
83 ev->ad->index = ev->ad->index_detail;
84 memo_navigator_pop(ev->navigator);
85 if(normal_memo_launch && launch_by_new ) {
86 elm_win_lower(ev->ad->win_main);
87 launch_by_new = EINA_FALSE ;
89 if(is_previous_edit_view) {
90 is_previous_edit_view = EINA_FALSE ;
92 } else if (strcmp(msg, "cancel") == 0) {
93 ev->ad->index = ev->ad->index_detail;
94 memo_navigator_pop(ev->navigator);
95 if(normal_memo_launch && launch_by_new ) {
97 elm_win_lower(ev->ad->win_main);
98 launch_by_new = EINA_FALSE ;
100 if(is_previous_edit_view) {
101 is_previous_edit_view = EINA_FALSE ;
104 } else if (strcmp(msg, "drawing") == 0) {
105 elm_object_part_content_unset(ev->body_main, "elm.swallow.content");
106 memo_destroy_text_editor(ev->h_ed);
107 ev->h_ed = memo_load_doodle_editor(ev->ad->win_main, ev->body_main, NULL, _doodle_editor_callback, ev);
108 ev->drawing = EINA_TRUE;
113 static void _doodle_editor_callback(void *data, const char *msg, void *event)
116 edit_view_t *ev = (edit_view_t *)data;
117 if (strcmp(msg, "layout") == 0) {
118 elm_object_part_content_set(ev->body_main, "elm.swallow.content", (Evas_Object *)event);
119 } else if (strcmp(msg, "title") == 0) {
120 elm_object_item_text_set(ev->navi_it, (const char *)event);
121 } else if (strcmp(msg, "savable") == 0) {
122 elm_object_disabled_set(ev->l_btn, (int)event==0? EINA_TRUE:EINA_FALSE);
123 } else if (strcmp(msg, "save") == 0) {
124 ev->ad->index = ev->ad->index_detail;
125 memo_navigator_pop(ev->navigator);
126 if(normal_memo_launch && launch_by_new ) {
127 elm_win_lower(ev->ad->win_main);
128 launch_by_new = EINA_FALSE ;
130 if(is_previous_edit_view) {
131 is_previous_edit_view = EINA_FALSE ;
133 } else if (strcmp(msg, "cancel") == 0) {
134 ev->ad->index = ev->ad->index_detail;
135 memo_navigator_pop(ev->navigator);
136 if(normal_memo_launch && launch_by_new ) {
137 elm_win_lower(ev->ad->win_main);
138 launch_by_new = EINA_FALSE ;
140 if(is_previous_edit_view) {
141 is_previous_edit_view = EINA_FALSE ;
143 } else if (strcmp(msg, "text") == 0) {
144 elm_object_part_content_unset(ev->body_main, "elm.swallow.content");
145 memo_destroy_doodle_editor(ev->h_ed);
146 ev->h_ed = memo_load_text_editor(ev->ad->win_main, ev->body_main, NULL, _text_editor_callback, ev);
147 ev->drawing = EINA_FALSE;
152 static void _edit_on_delete(void *data, Evas *e, Evas_Object *obj, void *event_info)
155 edit_view_t *ev = (edit_view_t *)data;
156 elm_object_part_content_unset(ev->body_main, "elm.swallow.content");
158 memo_destroy_doodle_editor(ev->h_ed);
160 memo_destroy_text_editor(ev->h_ed);
162 evas_object_del(ev->l_btn);
163 evas_object_del(ev->r_btn);
168 static void _on_update(void *data, Evas_Object *obj, void *event_info)
171 edit_view_t *ev = (edit_view_t *)data;
173 memo_doodle_editor_time_format_update(ev->h_ed);
175 memo_text_editor_time_format_update(ev->h_ed);
180 void *memo_load_edit_view(appdata *ad)
184 if (ad->index == -1) {
186 if (memo_get_count(&c) == 0) {
187 RETVIF(c == MEMO_MAX_RECORD, NULL);
191 edit_view_t *ev = SMALLOC(edit_view_t);
192 RETVIF(ev == NULL, NULL);
193 is_previous_edit_view = EINA_TRUE;
196 ev->navigator = ad->navigator;
198 ev->body_main = elm_layout_create(ev->navigator, EDJ_FILE, "empty_layout");
199 elm_naviframe_prev_btn_auto_pushed_set(ev->navigator, EINA_FALSE);
200 Elm_Object_Item *navi_it = memo_naviframe_item_push(ev->navigator, "", NULL, NULL, ev->body_main, NULL);
201 ev->navi_it = navi_it;
202 evas_object_event_callback_add(ev->body_main, EVAS_CALLBACK_DEL, _edit_on_delete, ev);
203 evas_object_data_set(ev->body_main, "time_format_update_cb", _on_update);
204 evas_object_data_set(ev->body_main, "time_format_update_data", ev);
205 /* delete "<-" button */
206 Evas_Object *btn = elm_object_item_part_content_get(navi_it, MEMO_NAVIFRAME_ITEM_PREV_BTN);
208 evas_object_del(btn);
210 ev->r_btn = elm_button_create(ev->navigator, MEMO_I18N_CANCEL,
211 _on_right_btn_clicked, ev);
212 elm_object_style_set(ev->r_btn, "naviframe/back_btn/default");
213 elm_object_item_part_content_set(navi_it, "title_right_btn", ev->r_btn);
214 ev->l_btn = elm_button_create(ev->navigator, MEMO_I18N_SAVE,
215 _on_left_btn_clicked, ev);
216 elm_object_style_set(ev->l_btn, "naviframe/title_icon");
218 Evas_Object *icon = elm_icon_add(ev->l_btn);
219 elm_image_file_set(icon, "usr/apps/org.tizen.memo/res/images/01_header_icon_add.png", NULL);
220 evas_object_size_hint_aspect_set(icon, EVAS_ASPECT_CONTROL_VERTICAL, 1 , 1);
221 elm_image_resizable_set(icon, EINA_TRUE, EINA_TRUE);
222 elm_object_content_set(ev->l_btn, icon);
224 elm_object_item_part_content_set(navi_it, "title_left_btn", ev->l_btn);
227 elm_object_item_signal_emit(navi_it, "elm,state,sip,shown", "");
230 service_h service = NULL;
231 service_create(&service);
232 if (ad->init_str != NULL) {
233 service_add_extra_data(service, "init_str", ad->init_str);
236 if (ad->index == -1) {
237 ev->h_ed = memo_load_text_editor(ev->ad->win_main, ev->body_main, service, _text_editor_callback, ev);
238 ev->drawing = EINA_FALSE;
240 memo_data_t *md = memo_get_data(ad->index);
241 snprintf(ev->ad->buf, MEMO_BUFFER_SIZE, "%d", ad->index);
242 service_add_extra_data(service, "index", ev->ad->buf);
243 if (md->has_doodle == 1) {
244 ev->h_ed = memo_load_doodle_editor(ev->ad->win_main, ev->body_main, service, _doodle_editor_callback, ev);
245 ev->drawing = EINA_TRUE;
247 ev->h_ed = memo_load_text_editor(ev->ad->win_main, ev->body_main, service, _text_editor_callback, ev);
248 ev->drawing = EINA_FALSE;
252 service_destroy(service);