Tizen 2.4.0 rev3 SDK Public Release
[apps/home/message.git] / composer / src / ui-composer / msg-ui-composer-body-page.c
1 /*
2  * Copyright (c) 2009-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 "msg-ui-composer-body.h"
19 #include "msg-ui-composer-body-page.h"
20 #include "msg-ui-composer-body-callback.h"
21 #include "msg-ui-composer-common.h"
22 #include "msg-ui-composer-popup.h"
23 #include "msg-ui-composer-message.h"
24 #include "msg-ui-composer-util.h"
25 #include "msg-ui-composer-recipient.h"
26 #include "msg-ui-composer-attachment.h"
27 #include "msg-ui-composer-external.h"
28 #include "msg-ui-content-utility.h"
29 #include "msg-file-util.h"
30
31 #include <glib.h>
32
33 /*==================================================================================================
34                                      STRUCTURES
35 ==================================================================================================*/
36
37 static void msg_ui_composer_mms_attach_sound_remove(MSG_COMPOSER_BODY_PAGE_S *page_data, Evas_Object *remove_item);
38 static void msg_ui_composer_mms_attach_image_remove(MSG_COMPOSER_BODY_PAGE_S *page_data, Evas_Object *remove_item);
39
40 COMPOSER_RETURN_TYPE_E msg_ui_composer_body_read_sms_body(MSG_COMPOSER_VIEW_DATA_S *cd)
41 {
42         D_ENTER;
43
44         if (!cd) {
45                 D_EMSG("composer view data is NULL ");
46                 return COMPOSER_RETURN_FAIL;
47         }
48
49         MSG_COMPOSER_BODY_S *body_data = &cd->body_data;
50         MSG_COMPOSER_BODY_PAGE_S *page_data = NULL;
51
52         Evas_Object *entry = NULL;
53
54         page_data = (MSG_COMPOSER_BODY_PAGE_S *)eina_list_nth(body_data->page_list, 0);
55         if (!page_data) {
56                 D_EMSG("page data is not exist");
57                 return COMPOSER_RETURN_FAIL;
58         }
59
60         entry = page_data->entry;
61         if (!entry) {
62                 D_EMSG("sms entry is NULL");
63                 return COMPOSER_RETURN_FAIL;
64         }
65
66         char *entry_text = g_strdup(elm_entry_entry_get(entry));
67         char *sms_text = NULL;
68         int sms_length = 0;
69
70         if (entry_text) {
71                 convert_ps_to_br(entry_text);
72                 sms_text = elm_entry_markup_to_utf8(entry_text);
73                 if (sms_text == NULL) {
74                         D_EMSG("sms_text is NULL");
75                         g_free(entry_text);
76                         return COMPOSER_RETURN_FAIL;
77                 }
78
79                 sms_length = strlen(sms_text);
80
81                 if (sms_length > 0) {
82                         msg_ui_composer_message_set_sms_body(sms_text);
83                 } else {
84                         D_WMSG("sms_length is %d", sms_length);
85                 }
86
87                 if (sms_text)
88                         g_free(sms_text);
89
90                 g_free(entry_text);
91         } else {
92                 D_WMSG("entry_text is NULL");
93                 sms_length = 0;
94         }
95
96         return COMPOSER_RETURN_SUCCESS;
97 }
98
99 COMPOSER_RETURN_TYPE_E msg_ui_composer_body_read_mms_body(MSG_COMPOSER_VIEW_DATA_S *cd)
100 {
101         D_ENTER;
102
103         if (!cd) {
104                 D_EMSG("composer data is NULL");
105                 return COMPOSER_RETURN_NULL_POINTER;
106         }
107
108         MSG_COMPOSER_BODY_S *body_data = &cd->body_data;
109         MSG_COMPOSER_BODY_PAGE_S *page_data = NULL;
110         Eina_List *page_list = body_data->page_list;
111         int page_count = body_data->page_count;
112
113         msg_ui_composer_message_set_page_count(page_count);
114
115         if (body_data->region_order == COMPOSER_REGION_ORDER_IMAGE_TOP)
116                 msg_ui_composer_message_set_is_text_top(false);
117         else
118                 msg_ui_composer_message_set_is_text_top(true);
119
120         int i = 0;
121         for (i = 0; i < page_count; i++) {
122                 page_data = (MSG_COMPOSER_BODY_PAGE_S *)eina_list_nth(page_list, i);
123                 if (page_data) {
124                         char *body_text;
125                         D_MSG("page duration = %d", page_data->page_duration);
126
127                         msg_ui_composer_message_mms_set_page_duration(i, page_data->page_duration);
128
129                         if (page_data->entry) {
130                                 D_MSG("read TEXT region data");
131                                 char *entry_text = g_strdup(elm_entry_entry_get(page_data->entry));
132                                 convert_ps_to_br(entry_text);
133
134                                 body_text = elm_entry_markup_to_utf8(entry_text);
135
136                                 if (body_text && strlen(body_text) > 0) {
137                                         msg_ui_composer_message_mms_set_text(body_text, i);
138                                 } else {
139                                         D_MSG("no text [%d]", i + 1);
140                                 }
141
142                                 if (body_text)
143                                         g_free(body_text);
144
145                                 g_free(entry_text);
146                         } else {
147                                 D_MSG("no page entry @ page [%d]", i + 1);
148                         }
149
150                         if (page_data->is_image_item) {
151                                 if (page_data->isVideo) {
152                                         D_MSG("read video region data");
153                                         msg_ui_composer_message_mms_set_media(page_data->image_file_path, COMPOSER_MEDIA_TYPE_VIDEO, i);
154                                 } else {
155                                         D_MSG("read image region data");
156                                         msg_ui_composer_message_mms_set_media(page_data->image_file_path, COMPOSER_MEDIA_TYPE_IMAGE, i);
157                                 }
158                         } else {
159                                 D_MSG("No [Image] region data");
160                         }
161
162                         if (page_data->is_sound_item) {
163                                 D_MSG("read SOUND region data");
164
165                                 msg_ui_composer_message_mms_set_media(page_data->sound_file_path, COMPOSER_MEDIA_TYPE_AUDIO, i);
166                         } else {
167                                 D_MSG("No [Sound] region data");
168                         }
169                 }
170         }
171
172         D_LEAVE;
173         return COMPOSER_RETURN_SUCCESS;
174 }
175
176 COMPOSER_RETURN_TYPE_E msg_ui_composer_update_char_count(MSG_COMPOSER_VIEW_DATA_S *cd, Evas_Object* entry)
177 {
178         if (!cd || !entry) {
179                 D_EMSG("NULL parameter passed.");
180                 return COMPOSER_RETURN_FAIL;
181         }
182
183         int char_count = 0;
184         int char_encode = COMPOSER_CHAR_ENCODE_MAX;
185         int page_size = 0;
186         char *body_text = elm_entry_markup_to_utf8(elm_entry_entry_get(entry));
187
188         if (body_text == NULL) {
189                 D_EMSG("no text on there");
190                 return COMPOSER_RETURN_FAIL;
191         }
192
193         /* update text count */
194         int text_len = strlen(body_text);
195         MSG_COMPOSER_BODY_PAGE_S *page_data = NULL;
196
197         page_data = evas_object_data_get(entry, "page_data");
198         if (page_data == NULL) {
199                 D_EMSG("page_data is NULL");
200                 free(body_text);
201                 return COMPOSER_RETURN_FAIL;
202         }
203
204         if (text_len <= 0) {
205                 COMPOSER_CHAR_ENCODE_E encode = COMPOSER_CHAR_ENCODE_GSM7;
206
207                 page_data->text_info.char_count = 0;
208
209                 switch (cd->encode_mode) {
210                 case MSG_ENCODE_GSM7BIT:
211                 case MSG_ENCODE_AUTO:
212                         encode = COMPOSER_CHAR_ENCODE_GSM7;
213                         break;
214                 case MSG_ENCODE_UCS2:
215                         encode = COMPOSER_CHAR_ENCODE_UNICODE;
216                         break;
217                 }
218                 page_data->text_info.encode = encode;
219
220                 if (cd->encode_mode == MSG_ENCODE_UCS2)
221                         page_data->text_info.page_size = (COMPOSER_SMS_UNICODE_MAX_LEN * 2);
222                 else
223                         page_data->text_info.page_size = COMPOSER_SMS_GSM7_MAX_LEN;
224         } else {
225                 int encode_mode = cd->encode_mode;
226
227                 COMPOSER_TEXT_EXCEPTION_CHAR_E is_exception_char = COMPOSER_TEXT_HAS_NO_EXCEPTION_CHAR;
228
229                 is_exception_char = msg_composer_check_exception_char_from_utf8(cd->encode_mode, (const unsigned char *)body_text);
230
231                 /* When Emot Icons Entered. it should not be converted to MMS, So disable the check     for Emot Icons*/
232 #ifdef _CONVERT_SMS_TO_MMS_IF_EMOTICON_PRESENT
233                 if (is_exception_char == COMPOSER_TEXT_HAS_EMOTICON) {
234                         /*there is emoticon, it should be changed to MMS;*/
235                         cd->has_emoticon = true;
236                         free(body_text);
237                         return COMPOSER_RETURN_SUCCESS;
238                 }
239 #endif
240                 if (cd->encode_mode == MSG_ENCODE_GSM7BIT) {
241                         if (is_exception_char == COMPOSER_TEXT_HAS_KOREAN) {
242                                 D_MSG("there is korean,Encoding mode has to be changed");
243                                 encode_mode = MSG_ENCODE_AUTO;
244                                 cd->changed_encode_mode = MSG_ENCODE_AUTO;
245                         }
246                 }
247                 char_encode = msg_ui_composer_body_entry_char_count(cd, (const char *)body_text, encode_mode, &char_count, &page_size);
248
249                 page_data->text_info.encode = char_encode;
250                 page_data->text_info.char_count = char_count;
251                 page_data->text_info.page_size = page_size;
252         }
253
254         free(body_text);
255
256         return COMPOSER_RETURN_SUCCESS;
257 }
258
259 int msg_ui_composer_body_entry_char_count(void *data, const char *text, int encode_type, int *char_count, int *page_size)
260 {
261         D_MSG_RETVM_IF(data == NULL, -1, "param is NULL");
262         D_MSG_RETVM_IF(text == NULL, -1, "param is NULL");
263         D_MSG_RETVM_IF(char_count == NULL, -1, "param is NULL");
264         D_MSG_RETVM_IF(page_size == NULL, -1, "param is NULL");
265         unsigned int text_size = 0;
266         unsigned int segment_size = 0;
267         int encoded_mode = 0;
268         int encode_mode_in = encode_type;
269         int ret = MSG_SUCCESS;
270         COMPOSER_CHAR_ENCODE_E encode = COMPOSER_CHAR_ENCODE_MAX;
271
272         ret = msg_util_calculate_text_length(text, encode_mode_in, &text_size, &segment_size, (msg_encode_type_t *)&encoded_mode);
273         D_MSG("encode_mode_in = %d, text_size = %d, segment_size = %d encoded_mode = %d", encode_mode_in, text_size, segment_size, encoded_mode);
274
275         if (ret != MSG_SUCCESS) {
276                 D_EMSG("msg_calculate_text_length is failed ret = %d", ret);
277         } else {
278                 switch (encode_mode_in) {
279                 case MSG_ENCODE_GSM7BIT:
280                         *char_count = (int)text_size;
281                         *page_size = (int)segment_size;
282
283                         if (encoded_mode == MSG_ENCODE_GSM7BIT_ABNORMAL)
284                                 encode = COMPOSER_CHAR_ENCODE_GSM7_ABNORMAL;
285                         else
286                                 encode = COMPOSER_CHAR_ENCODE_GSM7;
287
288                         break;
289
290                 case MSG_ENCODE_UCS2:
291                         *char_count = (int)text_size;
292                         *page_size = (int)segment_size;
293                         encode = COMPOSER_CHAR_ENCODE_UNICODE;
294
295                         break;
296
297                 case MSG_ENCODE_AUTO:
298                         *char_count = (int)text_size;
299                         *page_size = (int)segment_size;
300
301                         if (encoded_mode == MSG_ENCODE_GSM7BIT)
302                                 encode = COMPOSER_CHAR_ENCODE_GSM7;
303                         else
304                                 encode = COMPOSER_CHAR_ENCODE_UNICODE;
305
306                         break;
307
308                 default:
309                         D_EMSG("unsupported encode mode %d", encode_mode_in);
310                 }
311         }
312
313         return encode;
314 }
315
316 Eina_Bool msg_ui_composer_body_keypad_show_idler(void *data)
317 {
318         MSG_COMPOSER_VIEW_DATA_S *cd = (MSG_COMPOSER_VIEW_DATA_S *)data;
319         D_MSG_RETVM_IF(cd == NULL, ECORE_CALLBACK_CANCEL, "composer data is NULL");
320
321         D_MSG("show_keypad_on_launch : %d", cd->show_keypad_on_launch);
322
323         if (cd->show_keypad_on_launch) {
324                 msg_ui_composer_entry_input_panel_show(cd->last_focus_entry);
325                 cd->show_keypad_on_launch = false;
326         }
327
328         int preferred_subscription = MSG_SIM_PREFERENCE_SIM_COUNT_LESS_THAN_TWO;
329         preferred_subscription = cd->voice_preferred_sim;
330
331         bool bMax_recipient_over = false;
332
333         int recipient_cnt = msg_ui_composer_common_recipient_count_get(cd);
334         if (recipient_cnt > cd->recipient_max_count) {
335                 bMax_recipient_over = true;
336         }
337
338         if (cd->active_sims != 2) {
339                 if (msg_ui_composer_common_is_send_possible(cd) && bMax_recipient_over == false) {
340                         msg_ui_composer_send_btn_disabled_set(cd, EINA_FALSE);
341                         msg_ui_composer_body_update_send_btn_icon(cd, false);
342                 } else {
343                         msg_ui_composer_send_btn_disabled_set(cd, EINA_TRUE);
344                         msg_ui_composer_body_update_send_btn_icon(cd, true);
345                 }
346         }
347
348         cd->keypad_show_idler = NULL;
349         D_LEAVE;
350
351         return ECORE_CALLBACK_CANCEL;
352 }
353
354 void msg_ui_composer_body_info_area_update(MSG_COMPOSER_VIEW_DATA_S *cd)
355 {
356         D_MSG_RETM_IF(cd == NULL, "composer data is NULL");
357         MSG_COMPOSER_BODY_S *body_data = &cd->body_data;
358         char count_str[DEF_BUF_LEN] = {0,};
359
360         if (cd->msg_type == COMPOSER_MSG_TYPE_SMS) {
361                 MSG_COMPOSER_BODY_PAGE_S *page_data = (MSG_COMPOSER_BODY_PAGE_S *)eina_list_nth(body_data->page_list, 0);
362                 if (page_data == NULL) {
363                         D_EMSG("page_data is NULL");
364                         return;
365                 }
366
367                 int char_encode = page_data->text_info.encode;
368                 int char_count = page_data->text_info.char_count;
369                 int page_size = page_data->text_info.page_size;
370                 int cms_page = 0;
371                 int max_count = 0;
372                 int remaining_count = 0;
373
374                 if (char_encode == COMPOSER_CHAR_ENCODE_UNICODE ||
375                         char_encode == COMPOSER_CHAR_ENCODE_GSM7 ||
376                         char_encode == COMPOSER_CHAR_ENCODE_GSM7_ABNORMAL) {
377                         if (char_count > page_size) {
378                                 cms_page = char_count / page_size;
379
380                                 if (!(char_count % page_size))
381                                         --cms_page;
382
383                                 if ((cms_page+1) >= cd->cms_max_page)
384                                         max_count = page_size * cd->cms_max_page;
385                                 else
386                                         max_count = page_size * (cms_page+1);
387
388                         } else {
389                                 max_count = page_size;
390                         }
391
392                 } else {
393                         D_EMSG("Unknown character encode");
394                         return;
395                 }
396
397                 remaining_count = max_count - char_count;
398
399                 if (char_encode == COMPOSER_CHAR_ENCODE_UNICODE)
400                         remaining_count /= 2;
401
402                 if (cd->cms_max_page == 1)
403                         snprintf(count_str, sizeof(count_str), "%d", remaining_count);
404                 else
405                         snprintf(count_str, sizeof(count_str), "%d/%d", remaining_count, cms_page+1);
406
407                 edje_object_part_text_set(_EDJ(cd->input_field_layout), "text.char_count", count_str); /*Add Char count*/
408
409                 if (char_count == 0) {
410                         msg_ui_composer_entry_set_guide_text(page_data->entry, "IDS_MSGF_BODY_TEXT_MESSAGES");
411                 }
412
413                 MSG_ECORE_IDLER_DEL(cd->keypad_show_idler);
414                 cd->keypad_show_idler = ecore_idler_add(msg_ui_composer_body_keypad_show_idler, cd);
415         } else if (cd->msg_type == COMPOSER_MSG_TYPE_MMS) {
416                 int64 msg_size = 0;
417                 int sizeKB = 0;
418                 int sizeB = 0;
419
420                 if (msg_ui_composer_get_message_size(cd, &msg_size) == COMPOSER_RETURN_SUCCESS) {
421                         cd->mms_remained_size = cd->mms_max_size - (int)msg_size;
422                         D_MSG("cd->mms_remained_byte = %d", cd->mms_remained_size);
423                         if (cd->mms_remained_size < 0)
424                                 cd->mms_remained_size = 0;
425
426                         if (msg_size < MSGC_1KB) {
427                                 snprintf(count_str, sizeof(count_str), "1%s", dgettext(MESSAGE_PKGNAME, "IDS_MSGF_BODY_MSGSIZE_KB"));
428                         } else {
429                                 sizeKB = (int64)msg_size / MSGC_1KB;
430                                 sizeB = (int64)msg_size % MSGC_1KB;
431
432                                 if (sizeB) {
433                                         if (sizeKB < cd->mms_max_size)
434                                                 sizeKB++;
435                                 }
436                                 snprintf(count_str, sizeof(count_str), "%d%s", sizeKB, dgettext(MESSAGE_PKGNAME, "IDS_MSGF_BODY_MSGSIZE_KB"));
437                         }
438                         edje_object_part_text_set(_EDJ(cd->input_field_layout), "text.char_count", count_str);
439                 }
440
441                 /* update body guide text */
442                 int page_count = 0;
443                 MSG_COMPOSER_BODY_PAGE_S *page_data = NULL;
444                 page_data = eina_list_nth(body_data->page_list, 0);
445                 if (page_data) {
446                         page_count = eina_list_count(body_data->page_list);
447                         if (page_count == 1) {
448                                 /* if there is inserted content */
449                                 if (page_data->is_image_item || page_data->is_sound_item) {
450                                         msg_ui_composer_entry_set_guide_text(page_data->entry, "");
451                                 } else {
452                                         msg_ui_composer_entry_set_guide_text(page_data->entry, "IDS_MSGF_BODY_TEXT_MESSAGES");
453                                 }
454                         } else if (page_count > 1) {
455                                 msg_ui_composer_entry_set_guide_text(page_data->entry, "");
456                         } else {
457                                 D_EMSG("Invalid page count = %d", page_count);
458                         }
459                 }
460
461                 MSG_ECORE_IDLER_DEL(cd->keypad_show_idler);
462                 cd->keypad_show_idler = ecore_idler_add(msg_ui_composer_body_keypad_show_idler, cd);
463         }
464 }
465
466 static Evas_Object *__msg_ui_composer_body_create_page_divider(MSG_COMPOSER_VIEW_DATA_S *cd, Evas_Object *parent)
467 {
468         D_ENTER;
469         D_MSG_RETVM_IF(cd == NULL, NULL, "composer data is NULL");
470         D_MSG_RETVM_IF(parent == NULL, NULL, "parent is NULL");
471         Evas_Object *layout = NULL;
472         Evas_Load_Error err = EVAS_LOAD_ERROR_NONE;
473
474         layout = elm_layout_add(parent);
475         if (!layout) {
476                 D_EMSG("elm_layout_add error !!");
477                 return NULL;
478         }
479         elm_layout_file_set(layout, msg_ui_composer_edj_get(cd), "composer/body/page_divider");
480         evas_object_size_hint_weight_set(layout, EVAS_HINT_EXPAND, EVAS_HINT_EXPAND);
481         evas_object_size_hint_align_set(layout, EVAS_HINT_FILL, EVAS_HINT_FILL);
482         evas_object_show(layout);
483
484         Evas *evas = evas_object_evas_get(cd->main_window);
485         Evas_Object *img = evas_object_image_add(evas);
486         evas_object_image_file_set(img, MSGC_DOTTED_LINE_ICON, NULL);
487
488         err = evas_object_image_load_error_get(img);
489         if (err != EVAS_LOAD_ERROR_NONE)
490                 D_EMSG("image loading is failed = %d", err);
491
492         evas_object_image_fill_set(img, 0, 0, 8, 1); /* this is image resource size (8*1) */
493         elm_object_part_content_set(layout, "swl.divider_line", img);
494
495         D_LEAVE;
496         return layout;
497 }
498
499 static Evas_Object *__msg_ui_composer_body_page_create(MSG_COMPOSER_VIEW_DATA_S *cd, Evas_Object *parent, MSG_COMPOSER_BODY_PAGE_S *page_data)
500 {
501         D_ENTER;
502         D_MSG_RETVM_IF(cd == NULL, NULL, "composer data is NULL");
503         D_MSG_RETVM_IF(parent == NULL, NULL, "parent is NULL");
504         D_MSG_RETVM_IF(page_data == NULL, NULL, "page_data is NULL");
505         Evas_Object *layout = NULL;
506         Evas_Object *page_box = NULL;
507         Evas_Object *entry = NULL;
508         Elm_Entry_Filter_Limit_Size limit_filter;
509
510         layout = elm_layout_add(parent);
511         if (!layout) {
512                 D_EMSG("elm_layout_add error !!");
513                 return NULL;
514         }
515
516         elm_layout_file_set(layout, msg_ui_composer_edj_get(cd), MSGC_EDJ_GRP_BODY_PAGE);
517         evas_object_size_hint_weight_set(layout, EVAS_HINT_EXPAND, EVAS_HINT_EXPAND);
518         evas_object_size_hint_align_set(layout, EVAS_HINT_FILL, EVAS_HINT_FILL);
519         evas_object_show(layout);
520
521         page_box = elm_box_add(layout);
522         if (!page_box) {
523                 D_EMSG("elm_box_add error !!");
524                 return NULL;
525         }
526
527         evas_object_size_hint_weight_set(page_box, EVAS_HINT_EXPAND, EVAS_HINT_EXPAND);
528         evas_object_size_hint_align_set(page_box, EVAS_HINT_FILL, EVAS_HINT_FILL);
529         evas_object_show(page_box);
530
531         entry = elm_entry_add(page_box);
532         if (!entry) {
533                 D_EMSG("elm_box_add error !!");
534                 return NULL;
535         }
536
537         D_MSG("### body entry : %p", entry);
538
539         evas_object_size_hint_weight_set(entry, EVAS_HINT_EXPAND, EVAS_HINT_EXPAND);
540         evas_object_size_hint_align_set(entry, EVAS_HINT_FILL, EVAS_HINT_FILL);
541
542         elm_entry_markup_filter_append(entry, msg_composer_entry_filter_check_boundary, cd);
543         elm_entry_markup_filter_append(entry, msg_composer_entry_filter_addimage, cd);
544         /* add filter for removing markup */
545         elm_entry_markup_filter_append(entry, msg_composer_entry_filter_remove_markup, cd);
546
547         /* set entry max character count*/
548 #ifdef _MSG_FEATURE_MMS_DISABLE
549         int max_char_count = COMPOSER_SMS_GSM7_MAX_LEN;
550
551         if (cd->cms_max_page > 1)
552                 max_char_count = COMPOSER_CMS_GSM7_MAX_LEN * cd->cms_max_page;
553
554         limit_filter.max_char_count = max_char_count;
555 #else
556         limit_filter.max_char_count = COMPOSER_MMS_TEXT_MAX_CHAR;
557 #endif
558
559         elm_entry_markup_filter_append(entry, elm_entry_filter_limit_size, &limit_filter);
560
561 #ifdef _MSG_FEATURE_MMS_DISABLE
562         elm_entry_cnp_mode_set(entry, ELM_CNP_MODE_PLAINTEXT);
563 #endif
564
565         elm_entry_prediction_allow_set(entry, EINA_TRUE);
566         elm_entry_autocapital_type_set(entry, ELM_AUTOCAPITAL_TYPE_SENTENCE);
567         elm_entry_input_panel_return_key_type_set(entry, ELM_INPUT_PANEL_RETURN_KEY_TYPE_DEFAULT);
568
569         int len = 0;
570         if (cd->msg_type == COMPOSER_MSG_TYPE_SMS && cd->encode_mode == MSG_ENCODE_GSM7BIT) {
571                 len = strlen("type=gsm_alphabet&action=enable_emoticons");
572                 elm_entry_input_panel_imdata_set(entry, "type=gsm_alphabet&action=enable_emoticons", len);
573         } else {
574                 len = strlen("action=enable_emoticons");
575                 elm_entry_input_panel_imdata_set(entry, "action=enable_emoticons", len);
576         }
577
578         Ecore_IMF_Context *entry_ctx = elm_entry_imf_context_get(entry);
579         ecore_imf_context_input_panel_event_callback_add((Ecore_IMF_Context *)entry_ctx, ECORE_IMF_INPUT_PANEL_STATE_EVENT, msg_ui_composer_entry_imf_state_cb, cd);
580
581         /* We should not connect the resize callback on the keypad and try to resize the scroller in the callback.
582          * This is creating the flickering issue in bubble composer when candidate window comes and goes.
583          * ecore_imf_context_input_panel_event_callback_add((Ecore_IMF_Context *)entry_ctx, ECORE_IMF_INPUT_PANEL_GEOMETRY_EVENT, msg_ui_composer_entry_imf_resize_cb, cd); */
584
585         evas_object_show(entry);
586         evas_object_data_set(entry, "page_data", page_data);
587
588         evas_object_smart_callback_add(entry, "cursor,changed", msg_ui_composer_body_entry_cursor_changed_cb, cd);
589         evas_object_smart_callback_add(entry, "focused", msg_ui_composer_body_entry_focused_cb, cd);
590         evas_object_smart_callback_add(entry, "unfocused", msg_ui_composer_body_entry_unfocused_cb, cd);
591         evas_object_smart_callback_add(entry, "changed", msg_ui_composer_body_entry_changed_cb, cd);
592         evas_object_smart_callback_add(entry, "preedit,changed", msg_ui_composer_body_entry_changed_cb, cd);
593         evas_object_smart_callback_add(entry, "press", msg_ui_composer_body_entry_press_cb, cd);
594         evas_object_smart_callback_add(entry, "clicked", msg_ui_composer_body_entry_clicked_cb, cd);
595 #ifndef _MSG_FEATURE_MMS_DISABLE
596         evas_object_smart_callback_add(entry, "maxlength,reached", msg_ui_composer_body_entry_maxlength_reached_cb, cd);
597         evas_object_event_callback_add(entry, EVAS_CALLBACK_KEY_DOWN, msg_ui_composer_key_down_cb, cd);
598         evas_object_event_callback_add(entry, EVAS_CALLBACK_KEY_UP, msg_ui_composer_key_up_cb, cd);
599 #endif
600         eext_entry_selection_back_event_allow_set(entry, EINA_TRUE);
601
602         elm_box_pack_end(page_box, entry);
603         elm_object_part_content_set(layout, "swl.page", page_box);
604
605         page_data->upper_layout = layout;
606         page_data->entry = entry;
607         page_data->page_box = page_box;
608
609         /* keypad is manually controlled, so disabling the auto control of keypad */
610         elm_entry_input_panel_enabled_set(page_data->entry, EINA_FALSE);
611
612         /* Check appcontrol launching scenario because share text scenario. (eg. browser > share)
613          * Fix do not add signature firstly, and append signature later after setting loaded share text to entry. */
614         if (!cd->isAppControl) {
615                 /* Signature is added only to first page
616                  * Incase of bubble view, whether the composer mode is draft or not, will
617                  * be decided while loading the data so we neglect that case here */
618                 if ((cd->body_data.page_count == 0) && (cd->msg_ug_mode != MSG_UG_MODE_BUBBLE_COMPOSER)) {
619                         if (true == msg_ui_composer_common_is_signature_enabled(cd, false)) {
620                                 D_MSG("cd->signature_string = %s", cd->signature_string);
621                                 char *utf8_string = NULL;
622                                 utf8_string = elm_entry_utf8_to_markup(cd->signature_string);
623                                 if (NULL != utf8_string) {
624                                         elm_entry_entry_set(entry, utf8_string);
625                                         free(utf8_string);
626                                 }
627                         }
628                 }
629         }
630
631         if (cd->page_duration > COMPOSER_PAGE_DEFAULT_DURATION)
632                 page_data->page_duration = cd->page_duration;
633         else
634                 page_data->page_duration = COMPOSER_PAGE_DEFAULT_DURATION;
635
636         D_LEAVE;
637         return layout;
638 }
639
640 static Evas_Object *__msg_ui_composer_body_page_main_create(MSG_COMPOSER_VIEW_DATA_S *cd, Evas_Object *parent)
641 {
642         D_ENTER;
643         D_MSG_RETVM_IF(cd == NULL, NULL, "composer data is NULL");
644         D_MSG_RETVM_IF(parent == NULL, NULL, "parent is NULL");
645         MSG_COMPOSER_BODY_S *body_data = &cd->body_data;
646         MSG_COMPOSER_BODY_PAGE_S *page_data = NULL;
647         Evas_Object *layout = NULL;
648         Evas_Object *new_page = NULL;
649         Evas_Object *page_main_box = NULL;
650         Evas_Object *page_divider = NULL;
651
652         page_data = (MSG_COMPOSER_BODY_PAGE_S *)calloc(1, sizeof(MSG_COMPOSER_BODY_PAGE_S));
653         if (!page_data) {
654                 D_EMSG("page_data is NULL!! calloc error");
655                 return NULL;
656         }
657
658         layout = elm_layout_add(parent);
659         if (!layout) {
660                 D_EMSG(" elm_layout_add error !!");
661                 g_free(page_data);
662                 return NULL;
663         }
664
665         elm_layout_file_set(layout, msg_ui_composer_edj_get(cd), MSGC_EDJ_GRP_BODY_PAGE_MAIN);
666
667         edje_object_signal_emit(_EDJ(layout), "show.normal.mode", "*");
668
669         evas_object_size_hint_weight_set(layout, EVAS_HINT_EXPAND, EVAS_HINT_EXPAND);
670         evas_object_size_hint_align_set(layout, EVAS_HINT_FILL, EVAS_HINT_FILL);
671         evas_object_show(layout);
672
673         page_main_box = elm_box_add(layout);
674         if (!page_main_box) {
675                 D_EMSG("elm_box_add error !!");
676                 g_free(page_data);
677                 return NULL;
678         }
679
680         evas_object_size_hint_weight_set(page_main_box, EVAS_HINT_EXPAND, EVAS_HINT_EXPAND);
681         evas_object_size_hint_align_set(page_main_box, EVAS_HINT_FILL, EVAS_HINT_FILL);
682         evas_object_show(page_main_box);
683
684         page_data->page_main_box = page_main_box;
685         page_data->layout = layout;
686
687         new_page = __msg_ui_composer_body_page_create(cd, page_main_box, page_data);
688         if (!new_page) {
689                 D_EMSG(" new_page error !!");
690                 g_free(page_data);
691                 return NULL;
692         }
693
694         elm_box_pack_end(page_main_box, new_page);
695
696         if (body_data->page_count > 0) {
697                 page_divider = __msg_ui_composer_body_create_page_divider(cd, page_main_box);
698                 if (page_divider) {
699                         page_data->page_divider = page_divider;
700                         elm_box_pack_start(page_main_box, page_divider);
701                 }
702         }
703
704         elm_object_part_content_set(layout, "swl.page.main", page_main_box);
705
706         evas_object_data_set(_EDJ(layout), "private_data", cd);
707         edje_object_signal_callback_add(_EDJ(layout), "page_layout,clicked", "", msg_ui_composer_page_main_layout_clicked_cb, (void *)page_data);
708
709         body_data->page_list = eina_list_append(body_data->page_list, (void *)page_data);
710         body_data->page_count++;
711
712         int page_count = 0;
713         page_count = eina_list_count(body_data->page_list);
714
715         if (page_count == 1) {
716                 ;
717         } else if (page_count == 2) {
718                 if (page_divider) {
719                         char page_str[DEF_BUF_LEN_D + 1] = {0,};
720                         snprintf(page_str, sizeof(page_str), "%d/%d", page_count - 1, page_count);
721                         edje_object_part_text_set(_EDJ(page_divider), "text.page_info", page_str);
722                 }
723         } else if (page_count > 2) {
724                 msg_ui_composer_body_update_page_divider(cd);
725         }
726
727         D_LEAVE;
728         return layout;
729 }
730
731 COMPOSER_RETURN_TYPE_E msg_ui_composer_body_add_page(MSG_COMPOSER_VIEW_DATA_S *cd)
732 {
733         D_ENTER;
734         D_MSG_RETVM_IF(cd == NULL, COMPOSER_RETURN_FAIL, "composer data is NULL");
735         MSG_COMPOSER_BODY_S *body_data = &cd->body_data;
736         Evas_Object *main_box = cd->pages_box;
737         Evas_Object *new_page = NULL;
738
739         if (body_data->page_count >= COMPOSER_MMS_MAX_PAGE) {
740                 char buf[DEF_BUF_LEN] = { 0, };
741                 char *text = dgettext(MESSAGE_PKGNAME, "IDS_MSG_TPOP_UNABLE_TO_ADD_ATTACHMENT_MAXIMUM_NUMBER_OF_ATTACHMENTS_HPD_REACHED");
742                 snprintf(buf, sizeof(buf), text, COMPOSER_MMS_MAX_PAGE);
743                 msg_ui_composer_create_text_btn_popup(cd, buf, 0, MESSAGE_PKGNAME, "IDS_MSG_BUTTON_OK_ABB");
744                 return COMPOSER_RETURN_MAX_PAGE;
745         }
746
747         if (!main_box) {
748                 D_EMSG("composer body box is NULL");
749                 return COMPOSER_RETURN_FAIL;
750         }
751
752         if (body_data->page_count == 0) {
753                 cd->page_duration = COMPOSER_PAGE_DEFAULT_DURATION;
754         }
755
756         new_page = __msg_ui_composer_body_page_main_create(cd, main_box);
757         if (!new_page) {
758                 D_EMSG("page create error");
759                 return COMPOSER_RETURN_FAIL;
760         }
761
762         elm_box_pack_end(main_box, new_page);
763
764
765         D_LEAVE;
766         return COMPOSER_RETURN_SUCCESS;
767 }
768
769 COMPOSER_RETURN_TYPE_E msg_ui_composer_mms_insert_item_remove(MSG_COMPOSER_VIEW_DATA_S *cd, Evas_Object *remove_item)
770 {
771         D_ENTER;
772         D_MSG_RETVM_IF(cd == NULL, COMPOSER_RETURN_NULL_POINTER, "cd is NULL");
773         D_MSG_RETVM_IF(remove_item == NULL, COMPOSER_RETURN_NULL_POINTER, "remove_item is NULL");
774         MSG_COMPOSER_BODY_S *body_data = &cd->body_data;
775         MSG_COMPOSER_BODY_PAGE_S *page_data = NULL;
776         Eina_List *page_list = body_data->page_list;
777         int page_count = body_data->page_count;
778         int i = 0;
779
780         for (i = 0; i < page_count; i++) {
781                 page_data = (MSG_COMPOSER_BODY_PAGE_S *)eina_list_nth(page_list, i);
782                 if (page_data) {
783                         if (page_data->image_item == remove_item) {
784                                 D_MSG("remove image region media item !!");
785                                 page_data->is_image_item = false;
786                                 page_data->image_item = NULL;
787                                 page_data->isVideo = false;
788                                 page_data->is_image_focus = false;
789                                 /* remove temp file */
790                                 msg_composer_remove_file(page_data->image_file_path);
791                                 memset(page_data->image_file_path, 0x00, sizeof(page_data->image_file_path));
792                                 evas_object_del(remove_item);
793                                 break;
794                         } else if (page_data->sound_item == remove_item) {
795                                 D_MSG("remove sound media item !!");
796                                 page_data->is_sound_item = false;
797                                 page_data->sound_item = NULL;
798                                 page_data->is_sound_focus = false;
799                                 /* remove temp file */
800                                 msg_composer_remove_file(page_data->sound_file_path);
801                                 memset(page_data->sound_file_path, 0x00, sizeof(page_data->sound_file_path));
802                                 evas_object_del(remove_item);
803                                 break;
804                         }
805                 } else {
806                         D_WMSG("page_data is NULL");
807                 }
808         }
809         if (cd->is_replace == false) {
810                 msg_ui_composer_message_type_check_and_change(cd);
811         }
812
813         msg_ui_composer_body_info_area_update(cd);
814
815         D_LEAVE;
816         return COMPOSER_RETURN_SUCCESS;
817 }
818
819 static void __msgc_body_remove_page(MSG_COMPOSER_VIEW_DATA_S *cd, MSG_COMPOSER_BODY_PAGE_S *page_data, Evas_Object *remove_page)
820 {
821         D_MSG_RETM_IF(cd == NULL, "cd is NULL");
822         D_MSG_RETM_IF(page_data == NULL, "remove_page is NULL");
823         D_MSG_RETM_IF(remove_page == NULL, "remove_page is NULL");
824         MSG_COMPOSER_BODY_S *body_data = &cd->body_data;
825
826         elm_box_unpack(cd->pages_box, remove_page);
827
828         if (page_data->is_image_item)
829                 msg_ui_composer_mms_insert_item_remove(cd, page_data->image_item);
830
831         if (page_data->is_sound_item)
832                 msg_ui_composer_mms_insert_item_remove(cd, page_data->sound_item);
833
834         /* page count should be decresed before delete page layout */
835         body_data->page_list = eina_list_remove(body_data->page_list, page_data);
836         body_data->page_count--;
837
838         if (page_data->page_main_box) {
839                 if (page_data->page_divider) {
840                         evas_object_del(page_data->page_divider);
841                 }
842
843                 if (page_data->page_box) {
844                         if (page_data->image_item) {
845                                 evas_object_del(page_data->image_item);
846                         }
847
848                         if (page_data->sound_item) {
849                                 evas_object_del(page_data->sound_item);
850                         }
851
852                         if (page_data->entry) {
853                                 evas_object_del(page_data->entry);
854                         }
855
856                         evas_object_del(page_data->page_box);
857                 }
858
859                 if (page_data->upper_layout) {
860                         evas_object_del(page_data->upper_layout);
861                 }
862
863                 evas_object_del(page_data->page_main_box);
864         }
865
866         evas_object_del(page_data->layout);
867         free(page_data);
868 }
869
870 COMPOSER_RETURN_TYPE_E msg_ui_composer_mms_body_remove_page(MSG_COMPOSER_VIEW_DATA_S *cd, Evas_Object *remove_page, bool clear_body)
871 {
872         D_ENTER;
873         D_MSG_RETVM_IF(cd == NULL, COMPOSER_RETURN_NULL_POINTER, "cd is NULL");
874         D_MSG_RETVM_IF(remove_page == NULL, COMPOSER_RETURN_NULL_POINTER, "remove_page is NULL");
875         MSG_COMPOSER_BODY_S *body_data = &cd->body_data;
876         MSG_COMPOSER_BODY_PAGE_S *page_data = NULL;
877         Eina_List *page_list = body_data->page_list;
878         int page_count = body_data->page_count;
879         int i = 0;
880
881         if (page_count == 1) { /* in case of only one page exist */
882                 if (clear_body == true) {
883                         /* clear page */
884                         page_data = (MSG_COMPOSER_BODY_PAGE_S *)eina_list_nth(page_list, 0);
885
886                         if (page_data->is_image_item)
887                                 msg_ui_composer_mms_insert_item_remove(cd, page_data->image_item);
888
889                         if (page_data->is_sound_item)
890                                 msg_ui_composer_mms_insert_item_remove(cd, page_data->sound_item);
891
892                         elm_entry_entry_set(page_data->entry, "");
893
894                         D_MSG("focus change to the first page");
895                         /* focus change to the first page */
896                         cd->current_edit_entry = 0;
897
898                         Evas_Object *body_entry = msg_ui_composer_last_body_entry_get(cd);
899                         Evas_Object *last_focused_entry = msg_ui_composer_last_focused_entry_get(cd);
900                         /* last focus is body entry*/
901                         if (body_entry && (body_entry == last_focused_entry))
902                                 msg_ui_composer_last_focused_entry_set(cd, page_data->entry);
903
904                         page_data->page_duration = COMPOSER_PAGE_DEFAULT_DURATION;
905                 } else {
906                         /* remove page */
907                         page_data = (MSG_COMPOSER_BODY_PAGE_S *)eina_list_nth(page_list, 0);
908                         __msgc_body_remove_page(cd, page_data, remove_page);
909
910                         cd->current_edit_entry = 0;
911                 }
912         } else {
913                 for (i = 0; i < page_count; i++) {
914                         page_data = (MSG_COMPOSER_BODY_PAGE_S *)eina_list_nth(body_data->page_list, i);
915                         if (page_data) {
916                                 if (page_data->layout == remove_page) {
917                                         D_MSG("Remove MMS (%d)th page", i + 1);
918                                         Evas_Object *body_entry = msg_ui_composer_last_body_entry_get(cd);
919                                         Evas_Object *last_focused_entry = msg_ui_composer_last_focused_entry_get(cd);
920                                         int current_edit_entry = cd->current_edit_entry;
921                                         D_MSG("current_edit_entry = %d", cd->current_edit_entry);
922
923                                         /* When focus is with body page entry, click on recipient entry once and again click
924                                          * on body entry and then remove the page. Here since body entry is getting deleted
925                                          * and last focused entry was recipient, EFL is giving the focus temporarily to recipient entry
926                                          * Due to which the contents of recipient entry is going off. This is default behaviour of
927                                          * EFL that when a entry is deleted focus should be given to some other object.
928                                          * So prevent this temporarily giving the focus to send button. */
929                                         elm_object_focus_set(cd->send_button, EINA_TRUE);
930
931                                         /* remove page */
932                                         __msgc_body_remove_page(cd, page_data, remove_page);
933
934                                         if (i == 0) {
935                                                 /* remove next page's page_divider */
936                                                 MSG_COMPOSER_BODY_PAGE_S *next_page_data = (MSG_COMPOSER_BODY_PAGE_S *)eina_list_nth(body_data->page_list, i);
937                                                 if (next_page_data && next_page_data->page_divider) {
938                                                         D_MSG("remove next page's page_divider");
939                                                         elm_box_unpack(next_page_data->page_main_box, next_page_data->page_divider);
940                                                         evas_object_del(next_page_data->page_divider);
941                                                         next_page_data->page_divider = NULL;
942                                                 }
943                                         }
944                                         /* update page separator */
945                                         msg_ui_composer_body_update_page_divider(cd);
946
947                                         D_MSG("before update current entry");
948                                         /* deleted page is current edit page */
949                                         if (current_edit_entry == i) {
950                                                 D_MSG("update focus index");
951                                                 /* update body focus index*/
952                                                 if (i == 0) { /* if it is first page, update focus index to next page */
953                                                         cd->current_edit_entry = 0;
954                                                 } else { /* if it is not first page, update focus index to previous page */
955                                                         cd->current_edit_entry = i - 1;
956                                                 }
957
958                                                 /* change focus when last focused entry is a body entry */
959                                                 if (body_entry && (body_entry == last_focused_entry)) {
960                                                         page_data = (MSG_COMPOSER_BODY_PAGE_S *)eina_list_nth(body_data->page_list, cd->current_edit_entry);
961                                                         if (page_data) {
962                                                                 msg_ui_composer_last_focused_entry_set(cd, page_data->entry);
963                                                                 if (!cd->isclosed) {
964                                                                         msg_ui_composer_last_focus_load(cd);
965                                                                         elm_entry_cursor_end_set(msg_ui_composer_last_focused_entry_get(cd));
966                                                                 }
967                                                         } else {
968                                                                 D_EMSG("page_data is NULL");
969                                                         }
970                                                 }
971                                         } else if (cd->current_edit_entry > i) {
972                                                 D_MSG("update focus index");
973                                                 /* update body focus index*/
974                                                 cd->current_edit_entry--;
975
976                                                 if (cd->current_edit_entry <= 0)
977                                                         cd->current_edit_entry = 0;
978                                         }
979
980                                         break;
981                                 }
982                         }
983                 }
984         }
985
986         D_LEAVE;
987         return COMPOSER_RETURN_SUCCESS;
988 }
989
990 static Evas_Object *__msg_ui_composer_body_media_layout_create(MSG_COMPOSER_VIEW_DATA_S *cd, const char *file_path, Evas_Object *parent, COMPOSER_MEDIA_TYPE_E media_type, COMPOSER_MEDIA_ORIENT_E orient_mode)
991 {
992         D_ENTER;
993         D_MSG_RETVM_IF(cd == NULL, NULL, "cd is NULL");
994         D_MSG_RETVM_IF(parent == NULL, NULL, "parent is NULL");
995         Evas_Object *layout = NULL;
996         Evas_Object *thumb_icon = NULL;
997         const char *filename = NULL;
998         int image_icon_w = (int) ELM_SCALE_SIZE(MSGC_IMAGE_THUMB_LANDSCAPE_W);
999         int image_icon_h = (int) ELM_SCALE_SIZE(MSGC_IMAGE_THUMB_LANDSCAPE_H);
1000         int sound_icon_w = (int) ELM_SCALE_SIZE(MSGC_SOUND_THUMB_WIDTH);
1001         int sound_icon_h = (int) ELM_SCALE_SIZE(MSGC_SOUND_THUMB_HEIGHT);
1002
1003         layout = elm_layout_add(parent);
1004         if (!layout) {
1005                 D_EMSG("layout create error !!!!");
1006                 return NULL;
1007         }
1008
1009         if (media_type == COMPOSER_MEDIA_TYPE_AUDIO)
1010                 elm_layout_file_set(layout, msg_ui_composer_edj_get(cd), MSGC_EDJ_GRP_BODY_MEDIA_SOUND);
1011         else
1012                 elm_layout_file_set(layout, msg_ui_composer_edj_get(cd), MSGC_EDJ_GRP_BODY_MEDIA_IMAGE);
1013
1014         evas_object_size_hint_weight_set(layout, EVAS_HINT_EXPAND, EVAS_HINT_EXPAND);
1015         evas_object_size_hint_align_set(layout, EVAS_HINT_FILL, EVAS_HINT_FILL);
1016         evas_object_show(layout);
1017
1018         thumb_icon = elm_icon_add(layout);
1019
1020         if (media_type != COMPOSER_MEDIA_TYPE_AUDIO) {
1021                 D_MSG("orient_mode = %d", orient_mode);
1022                 if (orient_mode == COMPOSER_MEDIA_PORTRAIT_MODE) {
1023                         image_icon_w = (int)ELM_SCALE_SIZE(MSGC_IMAGE_THUMB_PORTRAIT_W);
1024                         image_icon_h = (int)ELM_SCALE_SIZE(MSGC_IMAGE_THUMB_PORTRAIT_H);
1025                 } else if (orient_mode == COMPOSER_MEDIA_LANDSCAPE_MODE) {
1026                         image_icon_w = (int)ELM_SCALE_SIZE(MSGC_IMAGE_THUMB_LANDSCAPE_W);
1027                         image_icon_h = (int)ELM_SCALE_SIZE(MSGC_IMAGE_THUMB_LANDSCAPE_H);
1028                 } else if (orient_mode == COMPOSER_MEDIA_EQUAL_MODE) {
1029                         image_icon_w = (int)ELM_SCALE_SIZE(MSGC_IMAGE_THUMB_EQUAL_W_H);
1030                         image_icon_h = (int)ELM_SCALE_SIZE(MSGC_IMAGE_THUMB_EQUAL_W_H);
1031                 }
1032         }
1033
1034         if (media_type == COMPOSER_MEDIA_TYPE_IMAGE) {
1035                 elm_image_file_set(thumb_icon, file_path, NULL);
1036                 evas_object_size_hint_min_set(thumb_icon, image_icon_w, image_icon_h);
1037                 elm_image_aspect_fixed_set(thumb_icon, EINA_FALSE);
1038         } else if (media_type == COMPOSER_MEDIA_TYPE_VIDEO) {
1039                 if (strcmp(file_path, MSGC_IMG_INSERT_ETC_ICON)) {
1040                         elm_image_file_set(thumb_icon, file_path, NULL);
1041                 } else {
1042                         elm_image_file_set(thumb_icon, MSG_IMAGES_EDJ, MSGC_IMG_INSERT_ETC_ICON);
1043                 }
1044                 evas_object_size_hint_min_set(thumb_icon, image_icon_w, image_icon_h);
1045                 elm_image_aspect_fixed_set(thumb_icon, EINA_FALSE);
1046         } else {
1047                 elm_image_file_set(thumb_icon, MSG_IMAGES_EDJ, MSGC_IMG_INSERT_ETC_ICON);
1048                 evas_object_size_hint_min_set(thumb_icon, sound_icon_w, sound_icon_h);
1049         }
1050         if (media_type != COMPOSER_MEDIA_TYPE_AUDIO) {
1051                 evas_object_show(thumb_icon);
1052                 elm_object_part_content_set(layout, "swl.thumbnail", thumb_icon);
1053         }
1054
1055         if (media_type == COMPOSER_MEDIA_TYPE_AUDIO) {
1056                 filename = msg_file_file_get(file_path);
1057                 if (filename)
1058                         edje_object_part_text_set(_EDJ(layout), "text.filename", filename);
1059         } else if (media_type == COMPOSER_MEDIA_TYPE_VIDEO) {
1060                 if (strcmp(file_path, MSGC_IMG_INSERT_ETC_ICON))
1061                         edje_object_signal_emit(_EDJ(layout), "elm,state,icon,show", "");
1062         }
1063
1064         D_LEAVE;
1065         return layout;
1066 }
1067
1068 static Evas_Object *__msg_ui_composer_body_create_insert_media(MSG_COMPOSER_VIEW_DATA_S *cd, const char *file_path, Evas_Object *parent, COMPOSER_MEDIA_TYPE_E media_type)
1069 {
1070         D_ENTER;
1071         D_MSG_RETVM_IF(cd == NULL, NULL, "cd is NULL");
1072         D_MSG_RETVM_IF(file_path == NULL, NULL, "file_path is NULL");
1073         D_MSG_RETVM_IF(parent == NULL, NULL, "parent is NULL");
1074         Evas_Object *layout = NULL;
1075         Evas_Object *transparent_button = NULL;
1076         char *inserted_file_path = (char *)file_path;
1077         char thumbnail_path[COMPOSER_FILEPATH_LEN_MAX + 1] = {0, };
1078         COMPOSER_MEDIA_ORIENT_E media_orient = COMPOSER_MEDIA_NONE;
1079
1080         Evas_Load_Error err = EVAS_LOAD_ERROR_NONE;
1081
1082         layout = elm_layout_add(parent);
1083         if (!layout) {
1084                 D_EMSG("layout create error !!!!");
1085                 return NULL;
1086         }
1087
1088         elm_layout_file_set(layout, msg_ui_composer_edj_get(cd), MSGC_EDJ_GRP_BODY_MEDIA_MAIN);
1089         evas_object_size_hint_weight_set(layout, EVAS_HINT_EXPAND, EVAS_HINT_EXPAND);
1090         evas_object_size_hint_align_set(layout, EVAS_HINT_FILL, EVAS_HINT_FILL);
1091         evas_object_show(layout);
1092
1093         if (media_type != COMPOSER_MEDIA_TYPE_AUDIO) {
1094                 bool is_portrait = false;
1095                 bool is_landscape = false ;
1096                 int content_w = 0;
1097                 int content_h = 0;
1098
1099                 if (media_type == COMPOSER_MEDIA_TYPE_VIDEO) {
1100                         if (msg_composer_common_get_thumbnail(cd, file_path, thumbnail_path, COMPOSER_FILEPATH_LEN_MAX) == COMPOSER_RETURN_SUCCESS) {
1101                                 inserted_file_path = thumbnail_path;
1102                         } else {
1103                                 D_EMSG("getting thumbnail from video is failed");
1104                                 inserted_file_path = MSGC_IMG_INSERT_ETC_ICON;
1105                         }
1106                 }
1107
1108                 D_SEC_MSG("inserted_file_path = (%s)", inserted_file_path);
1109
1110                 if (media_type == COMPOSER_MEDIA_TYPE_IMAGE || media_type == COMPOSER_MEDIA_TYPE_VIDEO) {
1111                         /*get image's content size*/
1112                         Evas *evas = evas_object_evas_get(cd->main_window);
1113                         Evas_Object *img = evas_object_image_add(evas);
1114                         evas_object_image_load_orientation_set(img, EINA_TRUE);
1115                         evas_object_image_file_set(img, inserted_file_path, NULL);
1116
1117                         err = evas_object_image_load_error_get(img);
1118                         if (err != EVAS_LOAD_ERROR_NONE) {
1119                                 D_EMSG("image loading is failed = %d", err);
1120                                 return NULL;
1121                         }
1122                         evas_object_image_size_get(img, &content_w, &content_h);
1123                         evas_object_del(img);
1124                         D_SEC_MSG("image_width = %d, image_height = %d", content_w, content_h);
1125                 }
1126
1127                 if (content_w && content_h) {
1128                         if (content_w < content_h) {
1129                                 is_portrait = true;
1130                         } else if (content_w > content_h) {
1131                                 is_landscape = true;
1132                         }
1133                 }
1134
1135                 if (is_portrait) {
1136                         D_MSG("change to image portrait layout");
1137                         media_orient = COMPOSER_MEDIA_PORTRAIT_MODE;
1138                         edje_object_signal_emit(_EDJ(layout), "media.image.portrait", "*");
1139                 } else if (is_landscape) {
1140                         D_MSG("change to image landscape layout");
1141                         media_orient = COMPOSER_MEDIA_LANDSCAPE_MODE;
1142                         edje_object_signal_emit(_EDJ(layout), "media.image.landscape", "*");
1143                 } else {
1144                         D_MSG("change to image equal layout");
1145                         media_orient = COMPOSER_MEDIA_EQUAL_MODE;
1146                         edje_object_signal_emit(_EDJ(layout), "media.image.equal", "*");
1147                 }
1148
1149                 Evas_Object *rect = evas_object_rectangle_add(evas_object_evas_get(layout));
1150                 evas_object_size_hint_align_set(rect, EVAS_HINT_FILL, EVAS_HINT_FILL);
1151                 evas_object_size_hint_weight_set(rect, EVAS_HINT_EXPAND, EVAS_HINT_EXPAND);
1152                 evas_object_color_set(rect, 0, 0, 0, 0);
1153                 evas_object_size_hint_min_set(rect, 0, ELM_SCALE_SIZE(MSGC_IMAGE_THUMB_LANDSCAPE_ORIGIN_H));
1154                 evas_object_show(rect);
1155
1156                 elm_object_part_content_set(layout, "swl.rect", rect);
1157         }
1158
1159         /* create transparent focus button so that insert media can have a focus and tts highlight*/
1160         transparent_button = elm_button_add(layout);
1161
1162         elm_object_style_set(transparent_button, "focus");
1163         evas_object_size_hint_weight_set(transparent_button, EVAS_HINT_EXPAND, EVAS_HINT_EXPAND);
1164         evas_object_size_hint_align_set(transparent_button, EVAS_HINT_FILL, EVAS_HINT_FILL);
1165         evas_object_show(transparent_button);
1166
1167         elm_object_part_content_set(layout, "swl.content", transparent_button);
1168
1169         /* create media layout */
1170         Evas_Object *media_layout = __msg_ui_composer_body_media_layout_create(cd, inserted_file_path, transparent_button, media_type, media_orient);
1171
1172         /* create gesture_layout */
1173         Evas_Object *gl = elm_gesture_layer_add(parent);
1174         if (gl) {
1175                 if (elm_gesture_layer_attach(gl, media_layout) == EINA_TRUE) {
1176                         elm_gesture_layer_cb_set(gl, ELM_GESTURE_N_LONG_TAPS, ELM_GESTURE_STATE_START, msg_ui_composer_body_media_longpress_s_cb, layout);
1177                         elm_gesture_layer_cb_set(gl, ELM_GESTURE_N_LONG_TAPS, ELM_GESTURE_STATE_MOVE, msg_ui_composer_body_media_longpress_m_cb, layout);
1178                 } else {
1179                         D_EMSG("gesture_layer_attach is failed");
1180                         evas_object_del(gl);
1181                         gl = NULL;
1182                 }
1183         } else {
1184                 D_EMSG("gesture layer is NULL");
1185         }
1186
1187         evas_object_smart_callback_add(transparent_button, "clicked", msg_ui_composer_body_media_btn_clicked_cb, layout);
1188         evas_object_smart_callback_add(transparent_button, "pressed", msg_ui_composer_body_media_btn_pressed_cb, layout);
1189         evas_object_smart_callback_add(transparent_button, "focused", msg_ui_composer_body_media_btn_focused_cb, layout);
1190         evas_object_smart_callback_add(transparent_button, "unfocused", msg_ui_composer_body_media_btn_unfocused_cb, layout);
1191         evas_object_smart_callback_add(transparent_button, "unpressed", msg_ui_composer_body_media_btn_unpressed_cb, layout);
1192
1193         elm_object_part_content_set(transparent_button, "elm.swallow.content", media_layout);
1194         evas_object_data_set(layout, "priv_data", cd);
1195
1196         return layout;
1197 }
1198
1199 COMPOSER_RETURN_TYPE_E msg_ui_composer_body_insert_media(MSG_COMPOSER_VIEW_DATA_S *cd, const char *file_path, COMPOSER_MEDIA_TYPE_E media_type)
1200 {
1201         D_ENTER;
1202         D_MSG_RETVM_IF(cd == NULL, COMPOSER_RETURN_FAIL, "cd is NULL");
1203         D_MSG_RETVM_IF(file_path == NULL, COMPOSER_RETURN_FAIL, "file_path is NULL");
1204         MSG_COMPOSER_BODY_S *body_data = &cd->body_data;
1205         MSG_COMPOSER_BODY_PAGE_S *page_data = NULL;
1206         Eina_List *page_list = body_data->page_list;
1207         int page_count = eina_list_count(page_list);
1208         bool is_new_page_needed = false;
1209         int length = 0;
1210         COMPOSER_RETURN_TYPE_E ret;
1211
1212         if (strlen(file_path) == 0) {
1213                 D_EMSG("empty file path");
1214                 return COMPOSER_RETURN_FAIL;
1215         }
1216
1217         if (page_count < 1) {
1218                 D_EMSG("mms page count error");
1219                 return COMPOSER_RETURN_FAIL;
1220         }
1221
1222         if (page_count <= cd->current_edit_entry) {
1223                 D_EMSG("mms page count error case page_count <= cd->current_edit_entry");
1224                 return COMPOSER_RETURN_INVALID_PAGE;
1225         }
1226
1227         /* Check whether the selected file has some valid size or not */
1228         struct stat stat_buf;
1229         if (stat(file_path, &stat_buf) != 0) {
1230                 return COMPOSER_RETURN_FAIL;
1231         }
1232
1233         if (stat_buf.st_size <= 0) {
1234                 D_MSG("file size is invalid");
1235                 return COMPOSER_RETURN_FAIL;
1236         }
1237
1238         page_data = (MSG_COMPOSER_BODY_PAGE_S *)eina_list_nth(page_list, cd->current_edit_entry);
1239         if (page_data) {
1240                 if (media_type == COMPOSER_MEDIA_TYPE_IMAGE) {
1241                         if (page_data->is_image_item)
1242                                 is_new_page_needed = true;
1243                 } else if (media_type == COMPOSER_MEDIA_TYPE_VIDEO) {
1244                         if (page_data->is_image_item || page_data->is_sound_item)
1245                                 is_new_page_needed = true;
1246                 } else if (media_type == COMPOSER_MEDIA_TYPE_AUDIO) {
1247                         if (page_data->is_sound_item || (page_data->is_image_item && page_data->isVideo))
1248                                 is_new_page_needed = true;
1249                 } else {
1250                         D_EMSG("invalid media type [%d]", media_type);
1251                         return COMPOSER_RETURN_INVALID_MEDIA_TYPE;
1252                 }
1253                 if (cd->is_replace == false) {
1254                         if (is_new_page_needed) {
1255                                 ret = msg_ui_composer_body_add_page(cd);
1256                                 if (ret != COMPOSER_RETURN_SUCCESS) {
1257                                         D_EMSG("Fail of new page created");
1258                                         return ret;
1259                                 }
1260                                 D_MSG("new page created");
1261                                 /* if new page added, current edit entry is changed to a new page's entry */
1262                                 cd->current_edit_entry = page_count;
1263                         }
1264                 } else {
1265                         if (page_data->is_image_focus) {
1266                                 msg_ui_composer_mms_insert_item_remove(cd, page_data->image_item);
1267                         } else if (page_data->is_sound_focus) {
1268                                 msg_ui_composer_mms_insert_item_remove(cd, page_data->sound_item);
1269                         }
1270                 }
1271         }
1272
1273         page_data = (MSG_COMPOSER_BODY_PAGE_S *)eina_list_nth(page_list, cd->current_edit_entry);
1274         if (page_data != NULL) {
1275                 if (media_type == COMPOSER_MEDIA_TYPE_AUDIO) {
1276                         page_data->is_sound_item = true;
1277                         length = strlen(file_path);
1278                         strncpy(page_data->sound_file_path, file_path, length);
1279                         page_data->sound_file_path[length] = '\0';
1280
1281                         int media_duration = 0;
1282                         msg_composer_common_get_media_duration(file_path, &media_duration);
1283                         D_MSG("audio file duration [%d]", media_duration);
1284
1285                         if (media_duration % 1000)
1286                                 media_duration = media_duration / 1000 + 1;
1287                         else
1288                                 media_duration = media_duration / 1000;
1289
1290                         if (media_duration > page_data->page_duration)
1291                                 page_data->page_duration = media_duration;
1292
1293                         page_data->sound_item = __msg_ui_composer_body_create_insert_media(cd, page_data->sound_file_path, page_data->layout, media_type);
1294
1295                         if (page_data->sound_item) {
1296                                 elm_box_pack_end(page_data->page_box, page_data->sound_item);
1297                         } else {
1298                                 D_EMSG("creating insert item layout error");
1299                                 return COMPOSER_RETURN_FAIL;
1300                         }
1301                 } else {
1302                         page_data->is_image_item = true;
1303                         page_data->isVideo = media_type == COMPOSER_MEDIA_TYPE_VIDEO ? true : false;
1304                         length = strlen(file_path);
1305                         strncpy(page_data->image_file_path, file_path, length);
1306                         page_data->image_file_path[length] = '\0';
1307
1308                         if (page_data->isVideo) {
1309                                 int media_duration = 0;
1310                                 msg_composer_common_get_media_duration(file_path, &media_duration);
1311                                 D_MSG("video file duration [%d]", media_duration);
1312
1313                                 if (media_duration % 1000)
1314                                         media_duration = media_duration / 1000 + 1;
1315                                 else
1316                                         media_duration = media_duration / 1000;
1317
1318                                 if (media_duration > page_data->page_duration)
1319                                         page_data->page_duration = media_duration;
1320                         }
1321
1322                         page_data->image_item = __msg_ui_composer_body_create_insert_media(cd, page_data->image_file_path, page_data->layout, media_type);
1323
1324                         if (page_data->image_item) {
1325                                 D_MSG("cd->body_data.region_order = %d", cd->body_data.region_order);
1326                                 if (cd->body_data.region_order == COMPOSER_REGION_ORDER_IMAGE_TOP)
1327                                         elm_box_pack_start(page_data->page_box, page_data->image_item);
1328                                 else
1329                                         elm_box_pack_after(page_data->page_box, page_data->image_item, page_data->entry);
1330                         } else {
1331                                 msg_composer_remove_file(page_data->image_file_path);
1332                                 memset(page_data->image_file_path, 0x00, sizeof(page_data->image_file_path));
1333                                 page_data->is_image_item = false;
1334                                 D_EMSG("creating insert item layout error");
1335                                 return COMPOSER_RETURN_FAIL;
1336                         }
1337                 }
1338         }
1339
1340         msg_ui_composer_send_btn_disabled_set(cd, EINA_FALSE);
1341         if (cd->is_replace == false) {
1342                 msg_ui_composer_message_type_check_and_change(cd);
1343         }
1344         msg_ui_composer_body_info_area_update(cd);
1345
1346         if (cd->msg_ug_mode == MSG_UG_MODE_BUBBLE_COMPOSER)
1347                 msg_ui_composer_change_body_layout_mode(cd, cd->rotate);
1348
1349         D_MSG("cd->attach_index = %d", cd->attach_index);
1350
1351         if (msg_ui_composer_recipient_check_showing_popup_condition(cd) == true) {
1352                 int media_count = eina_list_count(cd->attachlist);
1353                 /* show invalid popup when last content is added */
1354                 if (media_count == cd->attach_index) {
1355                         if (msg_ui_composer_recipient_addr_type_get(cd->recipient) == COMPOSER_RECP_ADDR_INVALID) {
1356                                 msg_common_create_noti_toast_popup("IDS_MSG_TPOP_UNABLE_TO_ADD_RECIPIENT_NUMBER_NOT_VALID");
1357                         } else {
1358                                 msg_ui_composer_common_tickernoti(cd, COMPOSER_TICKERNOTI_COUNT_MAX);
1359                         }
1360                 }
1361         } else {
1362                 /* change last focused entry to a page that is added media recently*/
1363                 const char *recipient = NULL;
1364                 bool status = true;
1365                 if (cd->msg_ug_mode != MSG_UG_MODE_BUBBLE_COMPOSER) {
1366                         if (cd->recipient) {
1367                                 RECIPIENT_S *rd = cd->recipient;
1368                                 D_MSG_RETVM_IF(rd == NULL, COMPOSER_RETURN_FAIL, "rd is NULL");
1369                                 recipient = msg_ui_composer_recipient_entry_text_get(cd->recipient);
1370                                 status = rd->was_entry_empty;
1371                         }
1372                 }
1373                 if (recipient && recipient[0] != '\0' && false == status) {
1374                         msg_ui_composer_last_focused_entry_set(cd, cd->recipient->entry);
1375                 } else {
1376                         msg_ui_composer_recipient_hide_mbe_and_update_entry(cd->recipient);
1377
1378                         if (page_data != NULL) {
1379                                 msg_ui_composer_last_focused_entry_set(cd, page_data->entry);
1380                         }
1381                 }
1382         }
1383         D_LEAVE;
1384         return COMPOSER_RETURN_SUCCESS;
1385 }
1386
1387 int msg_ui_composer_get_inserted_item_size(MSG_COMPOSER_VIEW_DATA_S *cd)
1388 {
1389         D_MSG_RETVM_IF(cd == NULL, MSG_UI_RET_ERR, "cd is NULL");
1390         int page_count = cd->body_data.page_count;
1391         Eina_List *page_list = cd->body_data.page_list;
1392         int total_size = 0;
1393         int i = 0;
1394
1395         for (i = 0; i < page_count; i++) {
1396                 MSG_COMPOSER_BODY_PAGE_S *page_data = (MSG_COMPOSER_BODY_PAGE_S *)eina_list_nth(page_list, i);
1397                 int image_file_size = 0;
1398                 int sound_file_size = 0;
1399                 int body_text_size = 0;
1400                 char *body_text = NULL;
1401                 if (page_data) {
1402                         if (page_data->is_image_item) {
1403                                 image_file_size = msg_composer_get_file_size(page_data->image_file_path);
1404                         }
1405                         if (page_data->is_sound_item) {
1406                                 sound_file_size = msg_composer_get_file_size(page_data->sound_file_path);
1407                         }
1408
1409                         if (page_data->entry) {
1410                                 body_text = elm_entry_markup_to_utf8(elm_entry_entry_get(page_data->entry));
1411                                 if (body_text) {
1412                                         body_text_size = strlen(body_text);
1413                                         free(body_text);
1414                                 }
1415                         }
1416
1417                         total_size = total_size + image_file_size + sound_file_size + body_text_size;
1418                 }
1419         }
1420         return total_size;
1421 }
1422
1423 bool should_body_keypad_be_shown(MSG_COMPOSER_VIEW_DATA_S *cd, int nPage)
1424 {
1425         bool show_keypad = false;
1426
1427         if (cd->msg_ug_mode != MSG_UG_MODE_BUBBLE_COMPOSER) {
1428                 show_keypad = true;
1429         } else {
1430                 if ((cd->bubble_data && true == cd->bubble_data->reply_mode) ||
1431                         ((cd->loaded_aul == false) && (cd->state == COMPOSER_STATE_TYPE_PAUSE))) {
1432                         if (cd->isclosed == false) {
1433                                 show_keypad = true;
1434                         }
1435                 }
1436         }
1437         return show_keypad;
1438 }
1439
1440 void msg_ui_composer_body_apply_font_size(MSG_COMPOSER_VIEW_DATA_S *cd, const char *font_sytle)
1441 {
1442         D_ENTER;
1443         D_MSG_RETM_IF(cd == NULL, "Composer Data is NULL");
1444         D_MSG_RETM_IF(font_sytle == NULL, "font_sytle is NULL");
1445         MSG_COMPOSER_BODY_S *body_data = &cd->body_data;
1446         int page_count = body_data->page_count;
1447         MSG_COMPOSER_BODY_PAGE_S *page_data = NULL;
1448         int i = 0;
1449
1450         D_MSG_RETM_IF(body_data->page_list == NULL, "page_list is NULL");
1451
1452         for (i = 0; i < page_count; i++) {
1453                 page_data = (MSG_COMPOSER_BODY_PAGE_S *)eina_list_nth(body_data->page_list, i);
1454                 if (page_data && page_data->entry) {
1455                         elm_entry_text_style_user_push(page_data->entry, font_sytle);
1456                 }
1457         }
1458
1459         D_LEAVE;
1460 }
1461
1462 void msg_ui_composer_body_focus_set(MSG_COMPOSER_VIEW_DATA_S *cd, int nPage)
1463 {
1464         D_ENTER;
1465         D_MSG_RETM_IF(cd == NULL, "cd is NULL");
1466         D_MSG_RETM_IF(nPage < 0, "nPage < 0");
1467         MSG_COMPOSER_BODY_S *body_data = &cd->body_data;
1468         D_MSG_RETM_IF(body_data->page_list == NULL, "page_list is NULL");
1469
1470         RECIPIENT_S *rd = cd->recipient;
1471
1472         MSG_COMPOSER_BODY_PAGE_S *page_data = (MSG_COMPOSER_BODY_PAGE_S *)eina_list_nth(body_data->page_list, nPage);
1473
1474         if (page_data) {
1475                 bool is_recipient_entry_activated = false;
1476                 if (rd)
1477                         is_recipient_entry_activated = rd->is_entry_activated;
1478                 elm_object_focus_set(page_data->entry, EINA_TRUE);
1479
1480                 D_MSG("Focus to Page[%d]", nPage);
1481                 if (should_body_keypad_be_shown(cd, nPage)) {
1482                         /*Even If internal mode is true check if reply mode is false or not . if false only then launch keypad , otherwise launch it in idler.
1483                         Because when we launch bubble composer from quickpanel , internal mode will be true.
1484                         */
1485                         if (cd->isMsgInternal || !cd->isAppControl) {
1486                                 if ((cd->bubble_data) && (cd->bubble_data->reply_mode == true)) {
1487                                         D_MSG("MEssage INtyernal MOde is :%d ", cd->isMsgInternal);
1488                                         cd->show_keypad_on_launch = true;
1489                                 } else {
1490                                         msg_ui_composer_entry_input_panel_show(page_data->entry);
1491                                 }
1492                         } else {
1493                                 if ((cd->msg_ug_mode != MSG_UG_MODE_BUBBLE_COMPOSER) && (is_recipient_entry_activated == true)) {
1494                                         msg_ui_composer_entry_input_panel_show(page_data->entry);
1495                                 } else {
1496                                         D_MSG("MEssage INtyernal MOde is :%d ", cd->isMsgInternal);
1497                                         cd->show_keypad_on_launch = true;
1498                                 }
1499                         }
1500                 }
1501
1502                 /* Make reply mode false here mode false here */
1503                 if (cd->msg_ug_mode == MSG_UG_MODE_BUBBLE_COMPOSER) {
1504                         if (cd->bubble_data) {
1505                                 if ((cd->bubble_data->reply_mode) || ((cd->loaded_aul == false) && (cd->state == COMPOSER_STATE_TYPE_PAUSE))) {
1506                                         cd->bubble_data->reply_mode = false;
1507                                 }
1508                         }
1509                 }
1510
1511                 if ((nPage == 0) && (true == msg_ui_composer_common_is_signature_enabled(cd, false))) {
1512                         char *body_text = elm_entry_markup_to_utf8(elm_entry_entry_get(page_data->entry));
1513                         if (body_text) {
1514                                 char *signature_start = g_strrstr(body_text, cd->signature_string);
1515
1516                                 if (signature_start) {
1517                                         if (!strcmp(signature_start, cd->signature_string)) {
1518                                                 glong full_str_cnt = g_utf8_strlen(body_text, -1);
1519                                                 glong signature_str_cnt = g_utf8_strlen(cd->signature_string, -1);
1520
1521                                                 elm_entry_cursor_pos_set(page_data->entry, (full_str_cnt - signature_str_cnt));
1522                                                 D_MSG("cursor = %d", (full_str_cnt - signature_str_cnt));
1523                                         }
1524                                 } else {
1525                                         D_EMSG("signature_start is NULL");
1526                                 }
1527
1528                                 free(body_text);
1529                         } else {
1530                                 D_EMSG("body_text is NULL");
1531                         }
1532                 } else {
1533                         elm_entry_cursor_end_set(page_data->entry);
1534                 }
1535         } else {
1536                 D_MSG("There is not exist Page[%d]", nPage);
1537         }
1538
1539         D_LEAVE;
1540 }
1541
1542 Evas_Object *msg_ui_composer_body_get_page_entry(MSG_COMPOSER_VIEW_DATA_S *cd, int nPage)
1543 {
1544         D_ENTER;
1545         D_MSG_RETVM_IF(cd == NULL, NULL, "cd is NULL");
1546         D_MSG_RETVM_IF(nPage < 0, NULL, "nPage < 0");
1547         MSG_COMPOSER_BODY_S *body_data = &cd->body_data;
1548         MSG_COMPOSER_BODY_PAGE_S *page_data = (MSG_COMPOSER_BODY_PAGE_S *)eina_list_nth(body_data->page_list, nPage);
1549
1550         if (page_data)
1551                 return page_data->entry;
1552         else
1553                 return NULL;
1554 }
1555
1556 MSG_COMPOSER_BODY_PAGE_S *msg_ui_composer_body_get_page_by_content(MSG_COMPOSER_VIEW_DATA_S *cd, Evas_Object *obj)
1557 {
1558         D_ENTER;
1559         D_MSG_RETVM_IF(cd == NULL, NULL, "cd is NULL");
1560         D_MSG_RETVM_IF(obj == NULL, NULL, "obj is NULL");
1561         MSG_COMPOSER_BODY_PAGE_S *page_data = NULL;
1562         MSG_COMPOSER_BODY_S *body_data = &cd->body_data;
1563         Eina_List *page_list = body_data->page_list;
1564
1565         if (!page_list) {
1566                 D_EMSG("page_list is NULL");
1567                 return NULL;
1568         }
1569
1570         int page_count = eina_list_count(page_list);
1571         int i = 0;
1572
1573         for (i = 0; i < page_count; i++) {
1574                 page_data = (MSG_COMPOSER_BODY_PAGE_S *)eina_list_nth(page_list, i);
1575
1576                 if (!page_data) {
1577                         D_EMSG("page data is NULL !!!");
1578                         return NULL;
1579                 }
1580
1581                 if (page_data->sound_item == obj) {
1582                         break;
1583                 } else if (page_data->image_item == obj) {
1584                         break;
1585                 } else if (page_data->entry == obj) {
1586                         break;
1587                 } else {
1588                         page_data = NULL;
1589                 }
1590         }
1591
1592         return page_data;
1593 }
1594
1595 bool msg_ui_composer_body_get_focused_page_index(MSG_COMPOSER_VIEW_DATA_S *cd, int *page_index)
1596 {
1597         D_ENTER;
1598         D_MSG_RETVM_IF(cd == NULL, false, "cd is NULL");
1599         D_MSG_RETVM_IF(page_index == NULL, false, "page_index is NULL");
1600         MSG_COMPOSER_BODY_PAGE_S *page_data = NULL;
1601         Eina_List *page_list = cd->body_data.page_list;
1602         int index = 0;
1603
1604         if (page_list == NULL) {
1605                 D_EMSG("page_list is NULL");
1606                 return false;
1607         }
1608
1609         Eina_List *l = NULL;
1610         EINA_LIST_FOREACH(page_list, l, page_data) {
1611                 if (page_data == NULL) {
1612                         D_EMSG("page_data is NULL");
1613                         return false;
1614                 }
1615
1616                 if (page_data->is_image_focus || page_data->is_sound_focus) {
1617                         *page_index = index;
1618                         return true;
1619                 }
1620
1621                 if (evas_object_focus_get(page_data->entry)) {
1622                         *page_index = index;
1623                         return true;
1624                 }
1625
1626                 ++index;
1627         }
1628
1629         D_LEAVE;
1630         return false;
1631 }
1632
1633 bool msg_ui_composer_body_get_page_index(MSG_COMPOSER_VIEW_DATA_S *cd, MSG_COMPOSER_BODY_PAGE_S *page, int *page_index)
1634 {
1635         D_ENTER;
1636         D_MSG_RETVM_IF(cd == NULL, false, "cd is NULL");
1637         D_MSG_RETVM_IF(page_index == NULL, false, "page_index is NULL");
1638         MSG_COMPOSER_BODY_PAGE_S *page_data = NULL;
1639         Eina_List *page_list = cd->body_data.page_list;
1640         int index = 0;
1641
1642         if (page_list) {
1643                 Eina_List *l = NULL;
1644                 EINA_LIST_FOREACH(page_list, l, page_data) {
1645                         if (page_data == page) {
1646                                 *page_index = index;
1647                                 return true;
1648                         }
1649
1650                         ++index;
1651                 }
1652         } else {
1653                 D_EMSG("page_list is NULL");
1654         }
1655         D_LEAVE;
1656         return false;
1657 }
1658
1659 MSG_COMPOSER_BODY_PAGE_S *msg_ui_composer_body_get_page_by_index(MSG_COMPOSER_VIEW_DATA_S *cd, int page_index)
1660 {
1661         D_MSG_RETVM_IF(cd == NULL, NULL, "cd is NULL");
1662
1663         if (page_index > cd->body_data.page_count) {
1664                 D_EMSG("invalid page_index = %d, page_count = %d", page_index, cd->body_data.page_count);
1665                 return NULL;
1666         }
1667
1668         MSG_COMPOSER_BODY_PAGE_S *page_data = eina_list_nth(cd->body_data.page_list, page_index);
1669
1670         if (page_data)
1671                 return page_data;
1672         else
1673                 return NULL;
1674 }
1675
1676 bool msg_ui_composer_body_is_page_data(MSG_COMPOSER_BODY_PAGE_S *page)
1677 {
1678         D_MSG_RETVM_IF(page == NULL, false, "page is NULL");
1679
1680         if (page->is_image_item)
1681                 return true;
1682
1683         if (page->is_sound_item)
1684                 return true;
1685
1686         if (page->entry) {
1687                 const char *str = elm_entry_entry_get(page->entry);
1688                 if (str && strlen(str)) {
1689                         return true;
1690                 }
1691         }
1692
1693         return false;
1694 }
1695
1696 void msg_ui_composer_body_page_image_layout_focus_hide(MSG_COMPOSER_BODY_PAGE_S *page_data)
1697 {
1698         D_ENTER;
1699         D_MSG_RETM_IF(page_data == NULL, "page_data is NULL");
1700         Evas_Object *btn = elm_object_part_content_get(page_data->image_item, "swl.content");
1701         Evas_Object *media_layout = elm_object_part_content_get(btn, "elm.swallow.content");
1702
1703         if (media_layout)
1704                 edje_object_signal_emit(_EDJ(media_layout), "unfocused", "*");
1705
1706         page_data->is_image_focus = false;
1707
1708         D_LEAVE;
1709 }
1710
1711 void msg_ui_composer_body_page_image_layout_focus_show(MSG_COMPOSER_BODY_PAGE_S *page_data)
1712 {
1713         D_ENTER;
1714         D_MSG_RETM_IF(page_data == NULL, "page_data is NULL");
1715         Evas_Object *btn = elm_object_part_content_get(page_data->image_item, "swl.content");
1716         Evas_Object *media_layout = elm_object_part_content_get(btn, "elm.swallow.content");
1717
1718         if (media_layout)
1719                 edje_object_signal_emit(_EDJ(media_layout), "focused", "*");
1720
1721         page_data->is_image_focus = true;
1722
1723         D_LEAVE;
1724 }
1725
1726 void msg_ui_composer_body_page_sound_layout_focus_hide(MSG_COMPOSER_BODY_PAGE_S *page_data)
1727 {
1728         D_ENTER;
1729         D_MSG_RETM_IF(page_data == NULL, "page_data is NULL");
1730         Evas_Object *btn = elm_object_part_content_get(page_data->sound_item, "swl.content");
1731         Evas_Object *media_layout = elm_object_part_content_get(btn, "elm.swallow.content");
1732
1733         if (media_layout)
1734                 edje_object_signal_emit(_EDJ(media_layout), "unfocused", "*");
1735
1736         page_data->is_sound_focus = false;
1737
1738         D_LEAVE;
1739 }
1740
1741 void msg_ui_composer_body_page_sound_layout_focus_show(MSG_COMPOSER_BODY_PAGE_S *page_data)
1742 {
1743         D_ENTER;
1744         D_MSG_RETM_IF(page_data == NULL, "page_data is NULL");
1745         Evas_Object *btn = elm_object_part_content_get(page_data->sound_item, "swl.content");
1746         Evas_Object *media_layout = elm_object_part_content_get(btn, "elm.swallow.content");
1747
1748         if (media_layout)
1749                 edje_object_signal_emit(_EDJ(media_layout), "focused", "*");
1750
1751         page_data->is_sound_focus = true;
1752
1753         D_LEAVE;
1754 }
1755
1756 void msg_ui_composer_body_media_layout_focus_hide(MSG_COMPOSER_VIEW_DATA_S *cd, COMPOSER_MEDIA_HIDE_TYPE_E type, int page_index)
1757 {
1758         D_ENTER;
1759         D_MSG_RETM_IF(cd == NULL, "cd is NULL");
1760         MSG_COMPOSER_BODY_PAGE_S *page_data = NULL;
1761         Eina_List *page_list = cd->body_data.page_list;
1762
1763         if (!page_list) {
1764                 D_EMSG("page_list is NULL");
1765                 return;
1766         }
1767
1768         int page_count = eina_list_count(page_list);
1769         int i = 0;
1770
1771         for (i = 0; i < page_count; i++) {
1772                 page_data = (MSG_COMPOSER_BODY_PAGE_S *)eina_list_nth(page_list, i);
1773                 if (!page_data) {
1774                         D_EMSG("page data is NULL !!!");
1775                         return;
1776                 }
1777
1778                 if ((type != COMPOSER_MEDIA_HIDE_EXCEPT_IMAGE) || (i != page_index)) {
1779                         if (page_data->is_image_item && page_data->is_image_focus)
1780                                 msg_ui_composer_body_page_image_layout_focus_hide(page_data);
1781                 }
1782
1783                 if ((type != COMPOSER_MEDIA_HIDE_EXCEPT_SOUND) || (i != page_index)) {
1784                         if (page_data->is_sound_item && page_data->is_sound_focus)
1785                         msg_ui_composer_body_page_sound_layout_focus_hide(page_data);
1786                 }
1787         }
1788 }
1789
1790 void msg_ui_composer_body_update_page_divider(MSG_COMPOSER_VIEW_DATA_S *cd)
1791 {
1792         D_ENTER;
1793         D_MSG_RETM_IF(cd == NULL, "cd is NULL");
1794         MSG_COMPOSER_BODY_PAGE_S *page_data = NULL;
1795         Eina_List *l = NULL;
1796         Eina_List *page_list = cd->body_data.page_list;
1797         char page_str[DEF_BUF_LEN_D + 1] = {0,};
1798         int index = 0;
1799
1800         if (!page_list) {
1801                 D_EMSG("page_list is NULL");
1802                 return;
1803         }
1804
1805         int total_page_count = eina_list_count(page_list);
1806
1807         EINA_LIST_FOREACH(page_list, l, page_data) {
1808                 if (!page_data) {
1809                         D_IMSG("page data is NULL !!!");
1810                         return;
1811                 }
1812
1813                 if (index > 0) { /*skip first page*/
1814                         if (page_data->page_divider) {
1815                                 memset(page_str, 0, sizeof(page_str));
1816                                 snprintf(page_str, sizeof(page_str), "%d/%d", index, total_page_count);
1817                                 edje_object_part_text_set(_EDJ(page_data->page_divider), "text.page_info", page_str);
1818                         }
1819                 }
1820                 ++index;
1821         }
1822 }
1823
1824 void msg_ui_composer_body_backspace_image_layout_focus_show(MSG_COMPOSER_VIEW_DATA_S *cd, MSG_COMPOSER_BODY_PAGE_S *page_data)
1825 {
1826         D_ENTER;
1827         D_MSG_RETM_IF(page_data == NULL, "page_data is NULL");
1828         D_MSG_RETM_IF(cd == NULL, "cd is NULL");
1829
1830         /* layout is not focusible widget. So, in order to disappear cursor of entry unset focus of entry.
1831         And, manually use input_panel_show to keep keypad showing becase entry unfocused cb makes hiding keypad. */
1832
1833         page_data->is_image_focus = true; /* removed from msg_ui_composer_body_page_image_layout_focus_show and put here so that in entry unfocused callback it can be tracked */
1834         elm_object_focus_set(page_data->entry, EINA_FALSE);
1835         msg_ui_composer_entry_input_panel_show(page_data->entry);
1836
1837         /* Bellow elm_object_focus_set() code should be called so that input_field_key_down_cb is called after moving focus to image layout */
1838         elm_object_focus_set(elm_layout_edje_get(page_data->image_item), EINA_TRUE);
1839
1840         msg_ui_composer_body_page_image_layout_focus_show(page_data);
1841
1842         D_LEAVE;
1843 }
1844
1845 void msg_ui_composer_body_backspace_sound_layout_focus_show(MSG_COMPOSER_VIEW_DATA_S *cd, MSG_COMPOSER_BODY_PAGE_S *page_data)
1846 {
1847         D_ENTER;
1848         D_MSG_RETM_IF(page_data == NULL, "page_data is NULL");
1849         D_MSG_RETM_IF(cd == NULL, "cd is NULL");
1850
1851         /* layout is not focusible widget. So, in order to disappear cursor of entry unset focus of entry.
1852         And, manually use input_panel_show to keep keypad showing becase entry unfocused cb makes hiding keypad. */
1853         elm_object_focus_set(page_data->entry, EINA_FALSE);
1854         msg_ui_composer_entry_input_panel_show(page_data->entry);
1855
1856         /* Bellow elm_object_focus_set() code should be called so that input_field_key_down_cb is called after moving focus to image layout */
1857         elm_object_focus_set(elm_layout_edje_get(page_data->sound_item), EINA_TRUE);
1858
1859         msg_ui_composer_body_page_sound_layout_focus_show(page_data);
1860
1861         D_LEAVE;
1862 }
1863
1864 void msg_ui_composer_body_remove_cur_page(void *data, MSG_COMPOSER_BODY_PAGE_S *page_data, int page_index)
1865 {
1866         D_ENTER;
1867         D_MSG_RETM_IF(data == NULL, "data is NULL");
1868         D_MSG_RETM_IF(page_data == NULL, "page_data is NULL");
1869         MSG_COMPOSER_VIEW_DATA_S *cd = (MSG_COMPOSER_VIEW_DATA_S *)data;
1870         Evas_Object *remove_layout = NULL;
1871
1872         remove_layout = page_data->layout;
1873
1874         if (page_data->sound_item && page_data->is_sound_focus) {
1875                 D_MSG("remove sound layout");
1876                 msg_ui_composer_mms_attach_sound_remove(page_data, page_data->sound_item);
1877         } else if (page_data->image_item && page_data->is_image_focus) {
1878                 D_MSG("remove image region layout");
1879                 msg_ui_composer_mms_attach_image_remove(page_data, page_data->image_item);
1880         }
1881
1882         if (elm_entry_is_empty(page_data->entry)) {
1883                 D_MSG("remove page if entry is empty");
1884                 msg_ui_composer_mms_body_remove_page(cd, remove_layout, true);
1885         }
1886
1887         msg_ui_composer_message_type_check_and_change(cd);
1888         msg_ui_composer_body_info_area_update(cd);
1889
1890         if (page_index >= 1) { /* if there is a previous page, check it */
1891                 int prev_page_index = page_index - 1;
1892                 MSG_COMPOSER_BODY_PAGE_S *prev_page_data = msg_ui_composer_body_get_page_by_index(cd, prev_page_index);
1893                 if (prev_page_data) {
1894                         if (prev_page_data->is_sound_item) {
1895                                 /* move cursor to sound layout */
1896                                 msg_ui_composer_body_backspace_sound_layout_focus_show(cd, prev_page_data);
1897                         } else {
1898                                 if (cd->body_data.region_order == COMPOSER_REGION_ORDER_TEXT_TOP) {
1899                                         /* set focus to image layout */
1900                                         if (prev_page_data->is_image_item) {
1901                                                 msg_ui_composer_body_backspace_image_layout_focus_show(cd, prev_page_data);
1902                                         } else {
1903                                                 msg_ui_composer_entry_input_panel_show(prev_page_data->entry);
1904                                         }
1905                                 } else {
1906                                         /* move cursor at end of text of prev page */
1907                                         /* entry focused_cb of prev_page_data is called at later. So, keypad is not shown on focused_cb */
1908                                         msg_ui_composer_entry_input_panel_show(prev_page_data->entry);
1909                                 }
1910                         }
1911                 }
1912         }
1913
1914         D_LEAVE;
1915 }
1916
1917 static void msg_ui_composer_mms_attach_sound_remove(MSG_COMPOSER_BODY_PAGE_S *page_data, Evas_Object *remove_item)
1918 {
1919         D_ENTER;
1920         D_MSG("remove sound media item !!");
1921         page_data->is_sound_item = false;
1922         page_data->sound_item = NULL;
1923         page_data->is_sound_focus = false;
1924         /* remove temp file */
1925         msg_composer_remove_file(page_data->sound_file_path);
1926         page_data->sound_file_path[0] = '\0';
1927         evas_object_del(remove_item);
1928         D_LEAVE;
1929 }
1930
1931 static void msg_ui_composer_mms_attach_image_remove(MSG_COMPOSER_BODY_PAGE_S *page_data, Evas_Object *remove_item)
1932 {
1933         D_ENTER;
1934         D_MSG("remove image region media item !!");
1935         page_data->is_image_item = false;
1936         page_data->image_item = NULL;
1937         page_data->isVideo = false;
1938         page_data->is_image_focus = false;
1939         /* remove temp file */
1940         msg_composer_remove_file(page_data->image_file_path);
1941         page_data->image_file_path[0] = '\0';
1942         evas_object_del(remove_item);
1943         D_LEAVE;
1944 }
1945
1946 void msg_ui_composer_back_space_remove_page(void *data, MSG_COMPOSER_BODY_PAGE_S *page_data)
1947 {
1948         D_ENTER;
1949         D_MSG_RETM_IF(data == NULL, "data is NULL");
1950         D_MSG_RETM_IF(page_data == NULL, "page_data is NULL");
1951         MSG_COMPOSER_VIEW_DATA_S *cd = (MSG_COMPOSER_VIEW_DATA_S *)data;
1952
1953         /* check prev page's data and current pags' data
1954                 if (prev has data & current no data), then remove current page
1955                 else if (prev no data & current has data), then remove prev page
1956                 else if (prev no data & current no data), then remove prev page <= no concept,
1957         */
1958         int page_index = 0;
1959         if (msg_ui_composer_body_get_page_index(cd, page_data, &page_index)) {
1960                 int prev_page_index = 0;
1961                 bool is_prev_page_data = false;
1962                 bool is_cur_page_data = false;
1963
1964                 D_MSG("page_index = %d", page_index)
1965                 if (page_index > 0) {
1966                         prev_page_index = page_index - 1;
1967                         MSG_COMPOSER_BODY_PAGE_S *prev_page_data = msg_ui_composer_body_get_page_by_index(cd, prev_page_index);
1968                         if (prev_page_data) {
1969                                 Evas_Object *remove_layout = NULL;
1970                                 is_prev_page_data = msg_ui_composer_body_is_page_data(prev_page_data);
1971                                 is_cur_page_data = msg_ui_composer_body_is_page_data(page_data);
1972                                 D_MSG("is_prev_page_data = %d, is_cur_page_data = %d", is_prev_page_data, is_cur_page_data);
1973
1974                                 if (is_prev_page_data && !is_cur_page_data) {
1975                                         msg_ui_composer_body_remove_cur_page(cd, page_data, page_index);
1976                                 } else if (!is_prev_page_data && is_cur_page_data) {
1977                                         /* remove prev page and keep cursor position(start) */
1978                                         D_MSG("remove prev page");
1979                                         remove_layout = prev_page_data->layout;
1980                                         msg_ui_composer_mms_body_remove_page(cd, remove_layout, true);
1981                                         msg_ui_composer_message_type_check_and_change(cd);
1982                                         msg_ui_composer_body_info_area_update(cd);
1983                                 } else if (!is_prev_page_data && !is_cur_page_data) {
1984                                         /* remove prev page and keep cursor position(start) */
1985                                         D_MSG("remove prev page");
1986                                         remove_layout = prev_page_data->layout;
1987                                         msg_ui_composer_mms_body_remove_page(cd, remove_layout, true);
1988                                         msg_ui_composer_message_type_check_and_change(cd);
1989                                         msg_ui_composer_body_info_area_update(cd);
1990                                 } else {
1991                                         D_MSG("Do nothing. Both pages have data");
1992                                 }
1993                         } else {
1994                                 D_EMSG("prev_page_data is NULL");
1995                         }
1996                 }
1997         } else {
1998                 D_IMSG("msg_ui_composer_body_get_page_index is failed");
1999         }
2000
2001         D_LEAVE;
2002 }