NABI_SE Issue fix 54243 54185 54293 54549 54398 54284 54434 54315 54404 54546 54411
[apps/osp/Contacts.git] / src / CtContactEditorForm.cpp
1 //
2 // Copyright (c) 2012 Samsung Electronics Co., Ltd.
3 //
4 // Licensed under the Flora License, Version 1.1 (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://floralicense.org/license/
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  * @file        CtContactEditorForm.cpp
19  * @brief       This is the implementation file for the ContactEditorForm class.
20  */
21
22 #include <FApp.h>
23 #include <FMedia.h>
24 #include "CtContactEditorForm.h"
25 #include "CtContactPresentationModel.h"
26 #include "CtContactsApp.h"
27 #include "CtContactValueListItemProvider.h"
28 #include "CtResourceManager.h"
29 #include "CtSceneRegister.h"
30 #include "CtTypes.h"
31 #include "CtCommonUtil.h"
32
33 using namespace Tizen::App;
34 using namespace Tizen::Base;
35 using namespace Tizen::Base::Collection;
36 using namespace Tizen::Base::Utility;
37 using namespace Tizen::Graphics;
38 using namespace Tizen::Io;
39 using namespace Tizen::Media;
40 using namespace Tizen::Ui;
41 using namespace Tizen::Ui::Controls;
42 using namespace Tizen::Ui::Scenes;
43 using namespace Tizen::Social;
44 using namespace Tizen::System;
45
46 static const int IDA_ACTION_BAR_SAVE = 11;
47 static const int IDA_BUTTON_THUMBNAIL_ADD = 21;
48 static const int IDA_BUTTON_THUMBNAIL_DELETE = 22;
49 static const int IDA_BUTTON_CAMERA = 23;
50 static const int IDA_BUTTON_EXPANDABLE = 24;
51 static const int IDA_BUTTON_MORE_INFO = 25;
52 static const int IDA_BUTTON_BIRTHDAY_CLEAR = 26;
53 static const int IDA_BUTTON_DEFAULT_PHONE_NUMBER = 27;
54 static const int IDA_BUTTON_RINGTONE_CLEAR = 28;
55 static const int IDA_BUTTON_TYPE = 29;
56 static const int IDA_BUTTON_BIRTHDAY_DELETE = 30;
57 static const int IDA_CONTEXT_MENU_ITEM_JOB_TITLE = 31;
58 static const int IDA_CONTEXT_MENU_ITEM_DEPARTMENT = 32;
59 static const int IDA_CONTEXT_MENU_ITEM_INSTANT_MESSENGER = 33;
60 static const int IDA_CONTEXT_MENU_ITEM_URL = 34;
61 static const int IDA_CONTEXT_MENU_ITEM_BIRTHDAY = 35;
62 static const int IDA_CONTEXT_MENU_ITEM_NOTE = 36;
63 static const int IDA_INPUT_FIELD_DISPLAY_NAME = 41;
64 static const int IDA_POPUP_DISCARD_CHANGES_OK = 44;
65 static const int IDA_POPUP_DISCARD_CHANGES_CANCEL = 45;
66
67 static const wchar_t* IDB_EXPAND_BUTTON_NORMAL = L"00_circle_button.png";
68 static const wchar_t* IDB_EXPAND_BUTTON_PRESSED = L"00_circle_button_press.png";
69 static const wchar_t* IDB_EXPAND_CLOSED = L"00_button_expand_closed.png";
70 static const wchar_t* IDB_EXPAND_CLOSED_PRESSED = L"00_button_expand_closed_press.png";
71 static const wchar_t* IDB_EXPAND_OPENED = L"00_button_expand_opened.png";
72 static const wchar_t* IDB_EXPAND_OPENED_PRESSED = L"00_button_expand_opened_press.png";
73 static const wchar_t* IDB_BUTTON_DELETE_NORMAL = L"00_circle_button_delete.png";
74 static const wchar_t* IDB_BUTTON_DELETE_PRESSED = L"00_circle_button_delete_press.png";
75 static const wchar_t* IDB_BUTTON_MINUS = L"00_button_expand_minus_press.png";
76 static const wchar_t* IDB_BUTTON_MINUS_PRESSED = L"00_button_expand_minus_press.png";
77 static const wchar_t* IDB_BUTTON_RESET_NORMAL = L"00_button_refresh.png";
78 static const wchar_t* IDB_BUTTON_RESET_PRESSED = L"00_button_refresh_press.png";
79 static const wchar_t* IDB_BUTTON_ADD= L"C02_caller_id_icon_add.png";
80 static const wchar_t* IDB_BUTTON_ADD_PRESSED = L"C02_caller_id_icon_add_press.png";
81 static const wchar_t* IDB_BUTTON_CAMERA = L"C02_caller_id_icon_camera.png";
82 static const wchar_t* IDB_BUTTON_CAMERA_PRESSED = L"C02_caller_id_icon_camera_press.png";
83 static const wchar_t* IDB_BUTTON_DROPBOX = L"C02_button_icon_dropbox.png";
84 static const wchar_t* IDB_THUMBNAIL_BACKGROUND = L"C02_created_photo_bg.png";
85 static const wchar_t* IDB_DETAILS_RESET_NORMAL = L"00_button_refresh.png";
86 static const wchar_t* IDB_DETAILS_RESET_PRESSED = L"00_button_refresh_press.png";
87
88 static const wchar_t* INPUT_DATA_SELECTION_MODE_SINGLE = L"single";
89 static const wchar_t* INPUT_KEY_SELECTION_MODE = L"http://tizen.org/appcontrol/data/selection_mode";
90 static const wchar_t* INPUT_KEY_IMAGEVIEWER_MODE = L"http://tizen.org/appcontrol/data/image/crop_mode";
91 static const wchar_t* INPUT_KEY_ALLOW_SWITCH = L"http://tizen.org/appcontrol/data/camera/allow_switch";
92 static const wchar_t* INPUT_MIME_TYPE_CAMERA = L"image/jpg";
93 static const wchar_t* INPUT_MIME_TYPE_GALLERY = L"image/*";
94 static const wchar_t* INPUT_MIME_TYPE_AUDIO = L"audio/*";
95 static const wchar_t* INPUT_VALUE_FALSE = L"false";
96 static const wchar_t* INPUT_VALUE_IMAGEVIEWER_TYPE = L"fit_to_screen";
97 static const wchar_t* OUTPUT_KEY_SELECTED = L"http://tizen.org/appcontrol/data/selected";
98 static const wchar_t* SD_CARD_UNMOUNTED = L"Unmounted";
99
100 static const int H_ITEM = 112;
101 static const int H_DOUBLE_LINE_ITEM = 140;
102 static const int H_LABEL = 40;
103 static const int H_DESCRIPTION_CONTAINER = 136;
104 static const int H_DIVIDER = 1;
105 static const int W_DIVIDER = 1;
106 static const int H_EMPTY_SPACE = 32;
107 static const int H_BUTTON = 74;
108 static const int H_ICON_BUTTON = 74;
109 static const int W_THUMBNAIL = 360;
110 static const int W_TITLE_LABEL = 170;
111 static const int X_MORE_INFORMATION_BUTTON = 60;
112 static const int Y_MORE_INFORMATION_BUTTON = 30;
113 static const int Y_DEFAULT_NUMBER_BUTTON = 19;
114 static const int W_ITEM_GAP = 16;
115 static const int W_TYPE_BUTTON = 186;
116 static const int H_THUMBNAIL_DELETE_BUTTON_GAP = 31;
117 static const int H_THUMBNAIL_GROUP_ITEM_HEIGHT = 34;
118 static const int H_NAMEFIELD_GROUP_ITEM_HEIGHT = 40;
119 static const int H_GROUP_RINGTONE_TITLE_GAP = 22;
120 static const int H_GROUP_RINGTONE_TITLE_LABEL = 42;
121 static const int H_GROUP_RINGTONE_VALUE_LABEL = 62;
122 static const int W_DROPBOX_ICON = 29;
123 static const int H_DROPBOX_ICON = 29;
124 static const int X_REFRESH_BUTTON_MARGIN = 88;
125 static const int Y_EDIT_FIELD_GAP = 5;
126 static const int H_EDIT_FIELD_GAP = 10;
127
128 static const int X_MORE_INFO_PANEL_GAP = 5;
129 static const int H_MORE_INFO_PANEL_GAP = 10;
130
131 static const int FONT_SIZE_TITLE_TEXT = 32;
132
133 static const int GROUP_ITEM_COUNT = 11;
134 static const int NAME_FIELD_ITEM_COUNT = 1;
135
136 static const int EDIT_FIELD_EXTENDED_LENGTH = 100;
137
138 static const int MESSAGE_BOX_TIMEOUT_MS = 300000;
139
140 static const int DEFAULT_EXPAND_NAME_FIELD_COUNT = 6;
141
142 static const wchar_t* EXPAND_BUTTON = L"ExpandButton";
143
144 static const unsigned int COLOR_TABLE_VIEW_BG = Color32<248, 246, 239>::Value;
145 static const unsigned int COLOR_DIVIDER = Color32<169, 169, 169>::Value;
146 static const unsigned int COLOR_THUMBNAIL_BACKGROUND = Color32<239, 237, 229>::Value;
147 static const unsigned int COLOR_ITEM_TITLE = Color32<128, 128, 128>::Value;
148 static const unsigned int COLOR_ITEM_VALUE = Color32<0, 0, 0>::Value;
149 static const unsigned int COLOR_ITEM_PRESSED = Color32<248, 246, 239>::Value;
150 static const unsigned int COLOR_PRESSED = Color32<87, 135, 194>::Value;
151
152 static const int TABLE_VIEW_DELETE_INPUT_FIELD_ID = 0xE0000000;
153 static const int TABLE_VIEW_INPUT_FIELD_ACTION_MASK = 0xF0000000;
154 static const int TABLE_VIEW_INPUT_FIELD_INDEX_MASK = 0x0F000000;
155 static const int TABLE_VIEW_GROUP_INDEX_MASK = 0x00FF0000;
156 static const int TABLE_VIEW_ITEM_INDEX_MASK = 0x0000FFFF;
157 static const int TABLE_VIEW_GROUP_INDEX_SHIFT = 16;
158 static const int TABLE_VIEW_INPUT_FIELD_INDEX_SHIFT = 24;
159 static const int TABLE_VIEW_INPUT_FIELD_ACTION_SHIFT = 28;
160 static const int TABLE_VIEW_THUMBNAIL_FIELD_INDEX = 0;
161 static const int TABLE_VIEW_NAME_FIELD_INDEX = 1;
162 static const int TABLE_VIEW_PHONE_NUMBER_FIELD_INDEX = 2;
163 static const int TABLE_VIEW_EMAIL_FIELD_INDEX = 3;
164 static const int TABLE_VIEW_ADDRESS_FIELD_INDEX = 4;
165 static const int TABLE_VIEW_IM_ADDRESS_FIELD_INDEX = 5;
166 static const int TABLE_VIEW_URL_FIELD_INDEX = 6;
167 static const int TABLE_VIEW_BIRTHDAY_FIELD_INDEX = 7;
168 static const int TABLE_VIEW_NOTE_FIELD_INDEX = 8;
169 static const int TABLE_VIEW_GROUP_RINGTONE_FIELD_INDEX = 9;
170 static const int TABLE_VIEW_MORE_INFORMATION_FIELD_INDEX = 10;
171
172 static const wchar_t* INPUT_TYPE_PHONE = L"phone";
173 static const wchar_t* INPUT_TYPE_EMAIL = L"email";
174 static const wchar_t* INPUT_TYPE_URL = L"url";
175 static const wchar_t* VIEW_TYPE = L"viewType";
176 static const wchar_t* VIEW_TYPE_VALUE_CONTACT = L"contact";
177 static const wchar_t* VIEW_TYPE_CONTACT_ID = L"contactId";
178 static const wchar_t* GROUP_LABEL_TITLE = L"GroupLabelTitle";
179 static const wchar_t* GROUP_LABEL_VALUE = L"GroupLabelValue";
180 static const wchar_t* GROUP_STYLE_PANEL = L"GroupStylePanel";
181
182 ContactEditorForm::ContactEditorForm(void)
183 : __isExpandable(false)
184 , __isAppControl(false)
185 , __isJobTitleEnabled(false)
186 , __isDepartmentEnabled(false)
187 , __isDefaultPhoneNumberButtonEnabled(false)
188 , __isSaved(false)
189 , __isMoreInformationContextMenuShowing(false)
190 , __isTypeContextMenuShowing(false)
191 , __isKeypadOpened(false)
192 , __isScrollOccurred(false)
193 , __isContactModified(false)
194 , __scrolledDistance(0)
195 , __origScrolledDistance(0)
196 , __itemIndex(-1)
197 , __groupIndex(-1)
198 , __previousItemIndex(-1)
199 , __previousGroupIndex(-1)
200 , __pAppControl(null)
201 , __pPhoneNumberFieldItem(null)
202 , __pEmailFieldItem(null)
203 , __pAddressFieldItem(null)
204 , __pImAddressFieldItem(null)
205 , __pUrlFieldItem(null)
206 , __pDeletedItemList(null)
207 , __pFileEventManager(null)
208 , __pDiscardChangesPopup(null)
209 , __pCurrentFocusedItem(null)
210 , __pDefaultPhoneNumberContextMenu(null)
211 , __pMoreInformationContextMenu(null)
212 , __pThumbnailContextMenu(null)
213 , __pTypeContextMenu(null)
214 , __pTableView(null)
215 , __pNameFieldItem(null)
216 , __pNoteFieldItem(null)
217 , __pPresentationModel(null)
218 {
219 }
220
221 ContactEditorForm::~ContactEditorForm(void)
222 {
223 }
224
225 void
226 ContactEditorForm::Initialize(void)
227 {
228         Construct(FORM_STYLE_NORMAL | FORM_STYLE_INDICATOR | FORM_STYLE_HEADER | FORM_STYLE_FOOTER);
229 }
230
231 result
232 ContactEditorForm::OnInitializing(void)
233 {
234         SetFormBackEventListener(this);
235         SettingInfo::AddSettingEventListener(*this);
236
237         Footer* pFooter = GetFooter();
238
239         FooterItem footerItemSave;
240         footerItemSave.Construct(IDA_ACTION_BAR_SAVE);
241         footerItemSave.SetText(ResourceManager::GetString(L"IDS_COM_SK_SAVE"));
242
243         pFooter->AddItem(footerItemSave);
244         pFooter->AddActionEventListener(*this);
245
246         __pTableView = new (std::nothrow) GroupedTableView();
247         __pTableView->Construct(Rectangle(0, 0, GetClientAreaBounds().width, GetClientAreaBounds().height), false, TABLE_VIEW_SCROLL_BAR_STYLE_FADE_OUT);
248         __pTableView->SetItemProvider(this);
249         __pTableView->AddScrollEventListener(*this);
250         __pTableView->AddGroupedTableViewItemEventListener(*this);
251         AddControl(__pTableView);
252
253         __pPhoneNumberFieldItem = new (std::nothrow) ArrayList();
254         __pPhoneNumberFieldItem->Construct();
255
256         __pEmailFieldItem = new (std::nothrow) ArrayList();
257         __pEmailFieldItem->Construct();
258
259         __pAddressFieldItem = new (std::nothrow) ArrayList();
260         __pAddressFieldItem->Construct();
261
262         __pImAddressFieldItem = new (std::nothrow) ArrayList();
263         __pImAddressFieldItem->Construct();
264
265         __pUrlFieldItem = new (std::nothrow) ArrayList();
266         __pUrlFieldItem->Construct();
267
268         __pPresentationModel = new (std::nothrow) ContactPresentationModel();
269         __pPresentationModel->Construct();
270         __pPresentationModel->AddContactChangeListener(*this);
271
272         DeviceManager::AddDeviceEventListener(DEVICE_TYPE_STORAGE_CARD, *this);
273
274         __pDeletedItemList = new ArrayList();
275         __pDeletedItemList->Construct();
276
277         return E_SUCCESS;
278 }
279
280 result
281 ContactEditorForm::OnTerminating(void)
282 {
283         AppLog("ContactEditorForm::OnTerminating()");
284
285         result r = E_SUCCESS;
286
287         __pTableView->SetItemProvider(null);
288
289         if (__pPresentationModel != null)
290         {
291                 __pPresentationModel->RemoveContactChangeListener(*this);
292                 delete __pPresentationModel;
293         }
294
295         if (__pPhoneNumberFieldItem)
296         {
297                 __pPhoneNumberFieldItem->RemoveAll(true);
298                 delete __pPhoneNumberFieldItem;
299         }
300
301         if (__pEmailFieldItem)
302         {
303                 __pEmailFieldItem->RemoveAll(true);
304                 delete __pEmailFieldItem;
305         }
306
307         if (__pAddressFieldItem)
308         {
309                 __pAddressFieldItem->RemoveAll(true);
310                 delete __pAddressFieldItem;
311         }
312
313         if (__pUrlFieldItem)
314         {
315                 __pUrlFieldItem->RemoveAll(true);
316                 delete __pUrlFieldItem;
317         }
318
319         if (__pImAddressFieldItem)
320         {
321                 __pImAddressFieldItem->RemoveAll(true);
322                 delete __pImAddressFieldItem;
323         }
324
325         if (__pDeletedItemList)
326         {
327                 __pDeletedItemList->RemoveAll(true);
328                 delete __pDeletedItemList;
329         }
330
331         if (__pDiscardChangesPopup)
332         {
333                 delete __pDiscardChangesPopup;
334         }
335         delete __pAppControl;
336         delete __pNameFieldItem;
337         delete __pNoteFieldItem;
338         delete __pDefaultPhoneNumberContextMenu;
339         delete __pMoreInformationContextMenu;
340         delete __pThumbnailContextMenu;
341         delete __pTypeContextMenu;
342         delete __pFileEventManager;
343
344         DeviceManager::RemoveDeviceEventListener(DEVICE_TYPE_STORAGE_CARD, *this);
345         SettingInfo::RemoveSettingEventListener(*this);
346
347         return r;
348 }
349
350 void
351 ContactEditorForm::OnFormBackRequested(Tizen::Ui::Controls::Form& source)
352 {
353         SetFocus();
354
355         if( IsSaveContactValid() == true  && __isContactModified == true)
356         {
357                 ShowDiscardChangesPopup();
358                 return;
359         }
360         if (__isAppControl == true)
361         {
362                 ContactsApp* pContactsApp = static_cast<ContactsApp*>(ContactsApp::GetInstance());
363                 AppControlProviderManager* pAppManager = AppControlProviderManager::GetInstance();
364
365                 result r = pAppManager->SendAppControlResult(pContactsApp->GetRequestId(), APP_CTRL_RESULT_CANCELED, null);
366                 AppLogDebug("[%s] The return result from SendAppControlResult().", GetErrorMessage(r));
367
368                 UiApp::GetInstance()->Terminate();
369         }
370         else
371         {
372                 SceneManager* pSceneManager = SceneManager::GetInstance();
373
374                 result r = pSceneManager->GoBackward(BackwardSceneTransition(SCENE_TRANSITION_ANIMATION_TYPE_RIGHT));
375                 TryReturnVoid(r == E_SUCCESS, "[%s] Unable to go backward", GetErrorMessage(r));
376         }
377 }
378
379 void
380 ContactEditorForm::OnActionPerformed(const Tizen::Ui::Control& source, int actionId)
381 {
382         AppLog("ContactEditorForm::OnActionPerformed(), actionId %d", actionId);
383
384         if ((actionId & TABLE_VIEW_INPUT_FIELD_ACTION_MASK) == TABLE_VIEW_DELETE_INPUT_FIELD_ID)
385         {
386                 int groupIndex = (actionId & TABLE_VIEW_GROUP_INDEX_MASK) >> TABLE_VIEW_GROUP_INDEX_SHIFT;
387                 int itemIndex = (actionId & TABLE_VIEW_ITEM_INDEX_MASK);
388
389                 if (groupIndex > TABLE_VIEW_NAME_FIELD_INDEX)
390                 {
391                         DeleteInputField(groupIndex, itemIndex);
392                         if (groupIndex == __previousGroupIndex && itemIndex < __previousItemIndex) //if we deleted a number on top of the item to be deleted
393                         {
394                                 __previousItemIndex--; //adjust the index of the item to be deleted
395                         }
396                         __isContactModified = true;
397                 }
398
399                 return;
400         }
401         else if (&source == __pDefaultPhoneNumberContextMenu)
402         {
403                 SetAsDefaultPhoneNumber(actionId, true);
404                 __isContactModified = true;
405
406                 return;
407         }
408         else if (((actionId & TABLE_VIEW_INPUT_FIELD_ACTION_MASK) >> TABLE_VIEW_INPUT_FIELD_ACTION_SHIFT) == TABLE_VIEW_PHONE_NUMBER_FIELD_INDEX)
409         {
410                 int itemIndex = (actionId & TABLE_VIEW_ITEM_INDEX_MASK);
411                 int selectedItemIndex = (actionId & TABLE_VIEW_INPUT_FIELD_INDEX_MASK) >> TABLE_VIEW_INPUT_FIELD_INDEX_SHIFT;
412
413                 TableViewItem* pItem = static_cast<TableViewItem *>(__pPhoneNumberFieldItem->GetAt(itemIndex));
414                 if (pItem == null)
415                 {
416                         return;
417                 }
418                 pItem->SetName(Integer::ToString(selectedItemIndex));
419
420                 Button* pButtonType = static_cast<Button *>(pItem->GetControl(1));
421                 if (pButtonType == null)
422                 {
423                         return;
424                 }
425
426                 pButtonType->SetText(__pPresentationModel->GetPhoneNumberTypeString((DetailPhoneNumberType)selectedItemIndex));
427                 pButtonType->Invalidate(false);
428
429                 __isContactModified = true;
430                 return;
431         }
432         else if (((actionId & TABLE_VIEW_INPUT_FIELD_ACTION_MASK) >> TABLE_VIEW_INPUT_FIELD_ACTION_SHIFT) == TABLE_VIEW_EMAIL_FIELD_INDEX)
433         {
434                 int itemIndex = (actionId & TABLE_VIEW_ITEM_INDEX_MASK);
435                 int selectedItemIndex = (actionId & TABLE_VIEW_INPUT_FIELD_INDEX_MASK) >> TABLE_VIEW_INPUT_FIELD_INDEX_SHIFT;
436
437                 TableViewItem* pItem = static_cast<TableViewItem *>(__pEmailFieldItem->GetAt(itemIndex));
438                 if (pItem == null)
439                 {
440                         return;
441                 }
442                 pItem->SetName(Integer::ToString(selectedItemIndex));
443
444                 Button* pButtonType = static_cast<Button *>(pItem->GetControl(1));
445                 if (pButtonType == null)
446                 {
447                         return;
448                 }
449
450                 pButtonType->SetText(__pPresentationModel->GetEmailTypeString((DetailEmailType)selectedItemIndex));
451                 pButtonType->Invalidate(false);
452
453                 __isContactModified = true;
454                 return;
455         }
456         else if (((actionId & TABLE_VIEW_INPUT_FIELD_ACTION_MASK) >> TABLE_VIEW_INPUT_FIELD_ACTION_SHIFT) == TABLE_VIEW_ADDRESS_FIELD_INDEX)
457         {
458                 int itemIndex = (actionId & TABLE_VIEW_ITEM_INDEX_MASK);
459                 int selectedItemIndex = (actionId & TABLE_VIEW_INPUT_FIELD_INDEX_MASK) >> TABLE_VIEW_INPUT_FIELD_INDEX_SHIFT;
460
461                 TableViewItem* pItem = static_cast<TableViewItem *>(__pAddressFieldItem->GetAt(itemIndex));
462                 if (pItem == null)
463                 {
464                         return;
465                 }
466                 pItem->SetName(Integer::ToString(selectedItemIndex));
467
468                 Button* pButtonType = static_cast<Button *>(pItem->GetControl(1));
469                 if (pButtonType == null)
470                 {
471                         return;
472                 }
473
474                 pButtonType->SetText(__pPresentationModel->GetAddressTypeString((DetailAddressType)selectedItemIndex));
475                 pButtonType->Invalidate(false);
476
477                 __isContactModified = true;
478                 return;
479         }
480         else if (((actionId & TABLE_VIEW_INPUT_FIELD_ACTION_MASK) >> TABLE_VIEW_INPUT_FIELD_ACTION_SHIFT) == TABLE_VIEW_IM_ADDRESS_FIELD_INDEX)
481         {
482                 int itemIndex = (actionId & TABLE_VIEW_ITEM_INDEX_MASK);
483                 int selectedItemIndex = (actionId & TABLE_VIEW_INPUT_FIELD_INDEX_MASK) >> TABLE_VIEW_INPUT_FIELD_INDEX_SHIFT;
484
485                 TableViewItem* pItem = static_cast<TableViewItem *>(__pImAddressFieldItem->GetAt(itemIndex));
486                 if (pItem == null)
487                 {
488                         return;
489                 }
490                 pItem->SetName(Integer::ToString(selectedItemIndex));
491
492                 Button* pButtonType = static_cast<Button *>(pItem->GetControl(1));
493                 if (pButtonType == null)
494                 {
495                         return;
496                 }
497
498                 pButtonType->SetText(__pPresentationModel->GetImAddressTypeString((DetailImAddressType)selectedItemIndex));
499                 pButtonType->Invalidate(false);
500
501                 __isContactModified = true;
502                 return;
503         }
504         else if (((actionId & TABLE_VIEW_INPUT_FIELD_ACTION_MASK) >> TABLE_VIEW_INPUT_FIELD_ACTION_SHIFT) == TABLE_VIEW_URL_FIELD_INDEX)
505         {
506                 int itemIndex = (actionId & TABLE_VIEW_ITEM_INDEX_MASK);
507                 int selectedItemIndex = (actionId & TABLE_VIEW_INPUT_FIELD_INDEX_MASK) >> TABLE_VIEW_INPUT_FIELD_INDEX_SHIFT;
508
509                 TableViewItem* pItem = static_cast<TableViewItem *>(__pUrlFieldItem->GetAt(itemIndex));
510                 if (pItem == null)
511                 {
512                         return;
513                 }
514                 pItem->SetName(Integer::ToString(selectedItemIndex));
515
516                 Button* pButtonType = static_cast<Button *>(pItem->GetControl(1));
517                 if (pButtonType == null)
518                 {
519                         return;
520                 }
521
522                 pButtonType->SetText(__pPresentationModel->GetUrlTypeString((DetailUrlType)selectedItemIndex));
523                 pButtonType->Invalidate(false);
524
525                 __isContactModified = true;
526                 return;
527         }
528
529         switch (actionId)
530         {
531         case IDA_ACTION_BAR_SAVE:
532                 {
533                         result r = E_SUCCESS;
534
535                         DateTime changedDate;
536                         DateTime currentDate;
537                         SystemTime::GetCurrentTime(currentDate);
538
539                         __pPresentationModel->GetBirthday(changedDate);
540
541                         if (changedDate.CompareTo(currentDate) > 0)
542                         {
543                                 int modalResult;
544                                 MessageBox invalidBirthYear;
545                                 invalidBirthYear.Construct(L"", ResourceManager::GetString(L"IDS_SAPPS_POP_INVALID_DATE_OF_BIRTH"), MSGBOX_STYLE_OK, MESSAGE_BOX_TIMEOUT_MS);
546                                 invalidBirthYear.ShowAndWait(modalResult);
547                                 __pPresentationModel->SetBirthday(currentDate);
548                                 __pTableView->RefreshItem(TABLE_VIEW_BIRTHDAY_FIELD_INDEX, 0, TABLE_VIEW_REFRESH_TYPE_ITEM_MODIFY);
549                         }
550                         else
551                         {
552                                 r = SaveContactData();
553                                 if (r != E_SUCCESS)
554                                 {
555                                         return;
556                                 }
557                                 SetFocus();
558
559                                 __isSaved = true;
560                         }
561                 }
562                 break;
563         case IDA_BUTTON_THUMBNAIL_ADD:
564                 {
565                         if (__pCurrentFocusedItem != null)
566                         {
567                                 SetFocus();
568                         }
569                         LaunchAppControl(PROVIDER_ID_GALLERY, OPERATION_ID_PICK);
570                 }
571                 break;
572         case IDA_BUTTON_THUMBNAIL_DELETE:
573                 {
574                         __pPresentationModel->SetThumbnail(L"");
575                         __isContactModified = true;
576                         __pTableView->RefreshItem(TABLE_VIEW_THUMBNAIL_FIELD_INDEX, 0, TABLE_VIEW_REFRESH_TYPE_ITEM_MODIFY);
577
578                         delete __pFileEventManager;
579                         __pFileEventManager = null;
580                 }
581                 break;
582         case IDA_BUTTON_CAMERA:
583                 {
584                         if (__pCurrentFocusedItem != null)
585                         {
586                                 SetFocus();
587                         }
588                         LaunchAppControl(PROVIDER_ID_CAMERA, OPERATION_ID_CREATE_CONTENT);
589                 }
590                 break;
591         case IDA_BUTTON_EXPANDABLE:
592                 {
593                         ChangeNameFieldStatus();
594                         if (__previousItemIndex != -1 && __previousGroupIndex != -1)
595                         {
596                                 DeleteInputField(__previousGroupIndex, __previousItemIndex, true);
597                         }
598                         if (__pCurrentFocusedItem == __pNameFieldItem)
599                         {
600                                 __pCurrentFocusedItem = null;
601                         }
602
603                         __pTableView->UpdateTableView();
604                         static_cast<Button*>(__pNameFieldItem->GetControl(EXPAND_BUTTON))->SetFocus();
605
606                         Rectangle clientBounds = GetClientAreaBounds();
607                         __pTableView->SetSize(clientBounds.width, clientBounds.height);
608
609                         if (__pCurrentFocusedItem != null)
610                         {
611                                 SetFocus();
612                         }
613                 }
614                 break;
615         case IDA_BUTTON_MORE_INFO:
616                 {
617                         if (__pCurrentFocusedItem != null)
618                         {
619                                 if (__isKeypadOpened)
620                                 {
621                                         __isMoreInformationContextMenuShowing = true;
622                                         __scrolledDistance = 0;
623                                 }
624                         }
625
626                         Control* pParentPanel = source.GetParent();
627                         if (pParentPanel == null)
628                         {
629                                 return;
630                         }
631
632                         Control* pParentTableViewItem = pParentPanel->GetParent();
633                         if (pParentTableViewItem == null)
634                         {
635                                 return;
636                         }
637
638                         Point contextMenuPos;
639
640                         contextMenuPos.x = pParentTableViewItem->GetWidth() / 2;
641                         contextMenuPos.y = GetClientAreaBounds().y + pParentTableViewItem->GetY() + source.GetY() - __scrolledDistance;
642
643                         ShowMoreInformationContextMenu(contextMenuPos);
644
645                         Button* pMoreInfo = static_cast<Button*>(&(const_cast<Control&>(source)));
646                         pMoreInfo->SetFocus();
647                 }
648                 break;
649         case IDA_BUTTON_BIRTHDAY_CLEAR:
650                 {
651                         DateTime currentDate;
652                         Tizen::System::SystemTime::GetCurrentTime(currentDate);
653                         __pPresentationModel->SetBirthday(currentDate);
654
655                         __pTableView->RefreshItem(TABLE_VIEW_BIRTHDAY_FIELD_INDEX, 0, TABLE_VIEW_REFRESH_TYPE_ITEM_MODIFY);
656                         __isContactModified = true;
657                 }
658                 break;
659         case IDA_CONTEXT_MENU_ITEM_JOB_TITLE:
660                 {
661                         __isExpandable = false;
662                         __isJobTitleEnabled = true;
663
664                         ChangeNameFieldStatus();
665
666                         __pTableView->UpdateTableView();
667
668                         if (IsMoreInformationButtonVisible() == false)
669                         {
670                                 __pTableView->RefreshItem(TABLE_VIEW_MORE_INFORMATION_FIELD_INDEX, 0, TABLE_VIEW_REFRESH_TYPE_ITEM_REMOVE);
671                         }
672                         __pTableView->ScrollToItem(TABLE_VIEW_NAME_FIELD_INDEX, 0);
673                 }
674                 break;
675         case IDA_CONTEXT_MENU_ITEM_DEPARTMENT:
676                 {
677                         __isExpandable = false;
678                         __isDepartmentEnabled = true;
679
680                         ChangeNameFieldStatus();
681
682                         __pTableView->UpdateTableView();
683
684                         if (IsMoreInformationButtonVisible() == false)
685                         {
686                                 __pTableView->RefreshItem(TABLE_VIEW_MORE_INFORMATION_FIELD_INDEX, 0, TABLE_VIEW_REFRESH_TYPE_ITEM_REMOVE);
687                         }
688                         __pTableView->ScrollToItem(TABLE_VIEW_NAME_FIELD_INDEX, 0);
689                 }
690                 break;
691         case IDA_CONTEXT_MENU_ITEM_INSTANT_MESSENGER:
692                 {
693                         SaveContactData(false);
694
695                         int index = __pPresentationModel->GetMultiValuesCount(DETAIL_PROPERTY_IM_ADDRESS);
696
697                         __pTableView->RefreshItem(TABLE_VIEW_IM_ADDRESS_FIELD_INDEX, index, TABLE_VIEW_REFRESH_TYPE_ITEM_ADD);
698
699                         if (IsMoreInformationButtonVisible() == false)
700                         {
701                                 __pTableView->RefreshItem(TABLE_VIEW_MORE_INFORMATION_FIELD_INDEX, 0, TABLE_VIEW_REFRESH_TYPE_ITEM_REMOVE);
702                         }
703                         __pTableView->ScrollToItem(TABLE_VIEW_IM_ADDRESS_FIELD_INDEX, 0);
704                 }
705                 break;
706         case IDA_CONTEXT_MENU_ITEM_URL:
707                 {
708                         SaveContactData(false);
709
710                         int index = __pPresentationModel->GetMultiValuesCount(DETAIL_PROPERTY_URL);
711
712                         __pTableView->RefreshItem(TABLE_VIEW_URL_FIELD_INDEX, index, TABLE_VIEW_REFRESH_TYPE_ITEM_ADD);
713
714                         if (IsMoreInformationButtonVisible() == false)
715                         {
716                                 __pTableView->RefreshItem(TABLE_VIEW_MORE_INFORMATION_FIELD_INDEX, 0, TABLE_VIEW_REFRESH_TYPE_ITEM_REMOVE);
717                         }
718                         __pTableView->ScrollToItem(TABLE_VIEW_URL_FIELD_INDEX, 0);
719                 }
720                 break;
721         case IDA_CONTEXT_MENU_ITEM_BIRTHDAY:
722                 {
723                         DateTime currentDate;
724
725                         Tizen::System::SystemTime::GetCurrentTime(currentDate);
726                         __pPresentationModel->SetBirthday(currentDate);
727
728                         __pTableView->RefreshItem(TABLE_VIEW_BIRTHDAY_FIELD_INDEX, 0, TABLE_VIEW_REFRESH_TYPE_ITEM_ADD);
729
730                         if (IsMoreInformationButtonVisible() == false)
731                         {
732                                 __pTableView->RefreshItem(TABLE_VIEW_MORE_INFORMATION_FIELD_INDEX, 0, TABLE_VIEW_REFRESH_TYPE_ITEM_REMOVE);
733                         }
734                         __pTableView->ScrollToItem(TABLE_VIEW_BIRTHDAY_FIELD_INDEX, 0);
735                 }
736                 break;
737         case IDA_CONTEXT_MENU_ITEM_NOTE:
738                 {
739                         __pTableView->RefreshItem(TABLE_VIEW_NOTE_FIELD_INDEX, 0, TABLE_VIEW_REFRESH_TYPE_ITEM_ADD);
740
741                         if (IsMoreInformationButtonVisible() == false)
742                         {
743                                 __pTableView->RefreshItem(TABLE_VIEW_MORE_INFORMATION_FIELD_INDEX, 0, TABLE_VIEW_REFRESH_TYPE_ITEM_REMOVE);
744                         }
745                         __pTableView->ScrollToItem(TABLE_VIEW_NOTE_FIELD_INDEX, 0);
746                 }
747                 break;
748         case IDA_BUTTON_DEFAULT_PHONE_NUMBER:
749                 {
750                         Control* pParent = source.GetParent();
751                         Point contextMenuPos;
752
753                         contextMenuPos.x = pParent->GetWidth() / 2;
754                         contextMenuPos.y = GetClientAreaBounds().y + pParent->GetY() + source.GetY() + (source.GetHeight() / 2) - __scrolledDistance;
755
756                         if (__pCurrentFocusedItem != null)
757                         {
758                                 SetFocus();
759                         }
760
761                         SaveContactData(false);
762                         ShowDefaultPhoneNumberContextMenu(contextMenuPos);
763                 }
764                 break;
765         case IDA_POPUP_DISCARD_CHANGES_CANCEL:
766                 {
767                         HideDiscardChangesPopup();
768                 }
769                 break;
770         case IDA_POPUP_DISCARD_CHANGES_OK:
771                 {
772                         HideDiscardChangesPopup();
773
774                         if (__isAppControl == true)
775                         {
776                                 ContactsApp* pContactsApp = static_cast<ContactsApp*>(ContactsApp::GetInstance());
777                                 AppControlProviderManager* pAppManager = AppControlProviderManager::GetInstance();
778
779                                 result r = pAppManager->SendAppControlResult(pContactsApp->GetRequestId(), APP_CTRL_RESULT_CANCELED, null);
780                                 AppLogDebug("[%s] The return result from SendAppControlResult().", GetErrorMessage(r));
781
782                                 UiApp::GetInstance()->Terminate();
783                         }
784                         else
785                         {
786
787                                 SceneManager* pSceneManager = SceneManager::GetInstance();
788
789                                 result r = pSceneManager->GoBackward(BackwardSceneTransition(SCENE_TRANSITION_ANIMATION_TYPE_RIGHT));
790                                 TryReturnVoid(r == E_SUCCESS, "[%s] Unable to go backward", GetErrorMessage(r));
791                         }
792                 }
793                 break;
794         case IDA_BUTTON_RINGTONE_CLEAR:
795                 {
796                         __pPresentationModel->SetValue(DETAIL_PROPERTY_RINGTONE, L"", 0);
797                         __pTableView->RefreshItem(TABLE_VIEW_GROUP_RINGTONE_FIELD_INDEX, 2, TABLE_VIEW_REFRESH_TYPE_ITEM_MODIFY);
798                 }
799                 break;
800         case IDA_BUTTON_BIRTHDAY_DELETE:
801                 {
802                         __pPresentationModel->RemoveBirthday();
803                         __pTableView->RefreshItem(TABLE_VIEW_BIRTHDAY_FIELD_INDEX, 0, TABLE_VIEW_REFRESH_TYPE_ITEM_REMOVE);
804                 }
805                 break;
806         case IDA_BUTTON_TYPE:
807                 {
808                         Control* pParent = source.GetParent();
809                         Point position = pParent->GetPosition();
810                         Point itemPosition(position.x + source.GetX(), GetClientAreaBounds().y + position.y + source.GetY() + (source.GetHeight() / 2) - __scrolledDistance);
811                         String typeString = pParent->GetName();
812                         String itemIndexTag = source.GetName();
813                         int type;
814                         int itemIndex;
815
816                         Integer::Parse(itemIndexTag, itemIndex);
817                         Integer::Parse(typeString, type);
818                         ShowTypeContextMenu(type, itemPosition, itemIndex);
819                 }
820                 break;
821         default:
822                 break;
823         }
824 }
825
826 void
827 ContactEditorForm::OnSceneActivatedN(const Tizen::Ui::Scenes::SceneId& previousSceneId, const Tizen::Ui::Scenes::SceneId& currentSceneId,
828                                                                                          Tizen::Base::Collection::IList* pArgs)
829 {
830         ContactsApp* pContactsApp = static_cast<ContactsApp*>(ContactsApp::GetInstance());
831         TryReturnVoid(pContactsApp != null, "Unable to cast UiApp to ContactsApp");
832
833         pContactsApp->AddContactsAppChangeEventListener(*this);
834
835         Header* pHeader = GetHeader();
836         Footer* pFooter = GetFooter();
837
838         if (previousSceneId.Equals(IDSCN_GROUP_SELECTOR, true) || previousSceneId.Equals(IDSCN_GROUP_EDITOR, true))
839         {
840                 if (pArgs != null)
841                 {
842                         Integer* pCategoryId = null;
843                         int prevCount = 0;
844                         int curCount  = 0;
845
846                         IList* pCategoryList = __pPresentationModel->GetAssignedCategoryIdListN();
847                         prevCount = pCategoryList->GetCount();
848                         delete pCategoryList;
849
850                         __pPresentationModel->RemoveContactFromAllCategories();
851
852                         IEnumerator* pEnum = pArgs->GetEnumeratorN();
853                         while (pEnum->MoveNext() == E_SUCCESS)
854                         {
855                                 pCategoryId = static_cast<Integer*>(pEnum->GetCurrent());
856                                 if (pCategoryId != null)
857                                 {
858                                         __pPresentationModel->AddContactToCategory(pCategoryId->ToInt());
859                                         __isContactModified = true;
860                                         curCount++;
861                                 }
862                         }
863
864                         if(prevCount > 0 && curCount == 0)
865                         {
866                                 __isContactModified = true;
867                         }
868
869                         delete pEnum;
870
871                         pArgs->RemoveAll(true);
872                         delete pArgs;
873                 }
874
875                 __pTableView->RefreshItem(TABLE_VIEW_GROUP_RINGTONE_FIELD_INDEX, 0, TABLE_VIEW_REFRESH_TYPE_ITEM_MODIFY);
876
877                 return;
878         }
879
880         if (pContactsApp->GetOperationId() == OPERATION_ID_ADD)
881         {
882                 __isAppControl = true;
883                 __pPresentationModel->PrepareNewContact();
884
885                 pHeader->SetTitleText(ResourceManager::GetString(L"IDS_COM_BODY_CREATE"));
886                 pFooter->SetItemEnabled(0, false);
887         }
888         else if (pContactsApp->GetOperationId() == OPERATION_ID_EDIT)
889         {
890                 __isAppControl = true;
891
892                 if (pArgs != null)
893                 {
894                         String* pArgString = null;
895                         String type;
896                         String content;
897
898                         IEnumerator* pEnum = pArgs->GetEnumeratorN();
899                         while (pEnum->MoveNext() == E_SUCCESS)
900                         {
901                                 pArgString = static_cast<String*>(pEnum->GetCurrent());
902                                 if (pArgString != null)
903                                 {
904                                         ParseAppControlArgument(*pArgString, type, content);
905
906                                         if (type.Equals(RETURN_TYPE_ITEM_ID, false))
907                                         {
908                                                 RecordId contactId;
909                                                 Integer::Parse(content, contactId);
910                                                 result r = __pPresentationModel->SetContactId(contactId, true);
911
912                                                 if (IsFailed(r))
913                                                 {
914                                                         AppLogDebug("Invalid contactId has been input : %d", contactId);
915                                                         UiApp::GetInstance()->Terminate();
916                                                 }
917
918                                                 if (__pPresentationModel->GetValue(DETAIL_PROPERTY_JOB_TITLE).IsEmpty() == false)
919                                                 {
920                                                         __isJobTitleEnabled = true;
921                                                 }
922                                                 if (__pPresentationModel->GetValue(DETAIL_PROPERTY_DEPARTMENT).IsEmpty() == false)
923                                                 {
924                                                         __isDepartmentEnabled = true;
925                                                 }
926                                                 break;
927                                         }
928                                 }
929                         }
930                         delete pEnum;
931
932                         pHeader->SetTitleText(ResourceManager::GetString(L"IDS_COM_SK_EDIT"));
933                 }
934         }
935         else
936         {
937                 if (pArgs != null)
938                 {
939                         Integer* pContactId = null;
940
941                         pContactId = static_cast<Integer*>(pArgs->GetAt(0));
942                         if (pContactId != null)
943                         {
944                                 if (pContactId->ToInt() != INVALID_RECORD_ID)
945                                 {
946                                         pHeader->SetTitleText(ResourceManager::GetString(L"IDS_COM_SK_EDIT"));
947                                         __pPresentationModel->SetContactId(pContactId->ToInt(), true);
948                                 }
949                                 else
950                                 {
951                                         pHeader->SetTitleText(ResourceManager::GetString(L"IDS_COM_BODY_CREATE"));
952
953                                         String* pVcfPath = static_cast<String*>(pArgs->GetAt(1));
954                                         if (pVcfPath != null)
955                                         {
956                                                 __pPresentationModel->SetVcfPath(*pVcfPath, true);
957                                         }
958                                 }
959                         }
960
961                         if (__pPresentationModel->GetValue(DETAIL_PROPERTY_JOB_TITLE).IsEmpty() == false)
962                         {
963                                 __isJobTitleEnabled = true;
964                         }
965                         if (__pPresentationModel->GetValue(DETAIL_PROPERTY_DEPARTMENT).IsEmpty() == false)
966                         {
967                                 __isDepartmentEnabled = true;
968                         }
969                 }
970                 else
971                 {
972                         pHeader->SetTitleText(ResourceManager::GetString(L"IDS_COM_BODY_CREATE"));
973                         pFooter->SetItemEnabled(0, false);
974                         __pPresentationModel->PrepareNewContact();
975                 }
976         }
977
978         if (__isAppControl == true)
979         {
980                 if (pArgs != null)
981                 {
982                         String* pArgString = null;
983                         String type;
984                         String content;
985
986                         IEnumerator* pEnum = pArgs->GetEnumeratorN();
987                         while (pEnum->MoveNext() == E_SUCCESS)
988                         {
989                                 pArgString = static_cast<String*>(pEnum->GetCurrent());
990                                 if (pArgString != null)
991                                 {
992                                         result r = E_SUCCESS;
993                                         ParseAppControlArgument(*pArgString, type, content);
994
995                                         if (type.Equals(INPUT_TYPE_PHONE, false))
996                                         {
997                                                 r = __pPresentationModel->SetValue(DETAIL_PROPERTY_PHONE_NUMBER, content, __pPresentationModel->GetMultiValuesCount(DETAIL_PROPERTY_PHONE_NUMBER));
998                                         }
999                                         else if (type.Equals(INPUT_TYPE_EMAIL, false))
1000                                         {
1001                                                 r = __pPresentationModel->SetValue(DETAIL_PROPERTY_EMAIL, content, __pPresentationModel->GetMultiValuesCount(DETAIL_PROPERTY_EMAIL));
1002                                         }
1003                                         else if (type.Equals(INPUT_TYPE_URL, false))
1004                                         {
1005                                                 r = __pPresentationModel->SetValue(DETAIL_PROPERTY_URL, content, __pPresentationModel->GetMultiValuesCount(DETAIL_PROPERTY_URL));
1006                                         }
1007
1008                                         if (r == E_SUCCESS)
1009                                         {
1010                                                 pFooter->SetItemEnabled(0, true);
1011                                         }
1012                                 }
1013                         }
1014                         delete pEnum;
1015                 }
1016         }
1017
1018         if (pArgs != null)
1019         {
1020                 pArgs->RemoveAll(true);
1021                 delete pArgs;
1022         }
1023 }
1024
1025 void
1026 ContactEditorForm::OnSceneDeactivated(const Tizen::Ui::Scenes::SceneId& currentSceneId, const Tizen::Ui::Scenes::SceneId& nextSceneId)
1027 {
1028         ContactsApp* pContactsApp = static_cast<ContactsApp*>(ContactsApp::GetInstance());
1029
1030         pContactsApp->RemoveContactsAppChangeEventListener(*this);
1031         if (__previousItemIndex != -1 && __previousGroupIndex != -1)
1032         {
1033                 DeleteInputField(__previousGroupIndex, __previousItemIndex);
1034         }
1035 }
1036
1037 void
1038 ContactEditorForm::OnKeypadWillOpen(Tizen::Ui::Control& source)
1039 {
1040 }
1041
1042 void
1043 ContactEditorForm::OnKeypadOpened(Tizen::Ui::Control& source)
1044 {
1045         Rectangle clientBounds = GetClientAreaBounds();
1046
1047         __pTableView->SetSize(clientBounds.width, clientBounds.height);
1048         __isKeypadOpened = true;
1049 }
1050
1051 void
1052 ContactEditorForm::OnKeypadClosed(Tizen::Ui::Control& source)
1053 {
1054         Rectangle clientBounds = GetClientAreaBounds();
1055         AppLogDebug("Contacts::OnKeypadclosed bounds are width:(%d), height:(%d)", clientBounds.width, clientBounds.height);
1056         __pTableView->SetSize(clientBounds.width, clientBounds.height);
1057
1058         if (__isMoreInformationContextMenuShowing)
1059         {
1060                 Point anchorPosition = __pMoreInformationContextMenu->GetAnchorPosition();
1061                 __pTableView->ScrollToItem(TABLE_VIEW_MORE_INFORMATION_FIELD_INDEX, 0, TABLE_VIEW_SCROLL_ITEM_ALIGNMENT_BOTTOM);
1062                 if (__scrolledDistance != __origScrolledDistance)
1063                 {
1064                         __scrolledDistance = __origScrolledDistance;
1065                 }
1066                 anchorPosition.y -= __scrolledDistance;
1067                 __pMoreInformationContextMenu->SetAnchorPosition(anchorPosition);
1068                 __pMoreInformationContextMenu->Show();
1069
1070                 __isMoreInformationContextMenuShowing = false;
1071         }
1072         __isKeypadOpened = false;
1073 }
1074
1075 void
1076 ContactEditorForm::OnKeypadActionPerformed(Tizen::Ui::Control& source, Tizen::Ui::KeypadAction keypadAction)
1077 {
1078 }
1079
1080 void
1081 ContactEditorForm::OnKeypadBoundsChanged(Tizen::Ui::Control& source)
1082 {
1083         Rectangle clientBounds = GetClientAreaBounds();
1084         int diff = clientBounds.height - __pTableView->GetHeight();
1085
1086         if (__pTypeContextMenu != null)
1087         {
1088                 int yPos = __pTypeContextMenu->GetAnchorPosition().y;
1089                 __pTypeContextMenu->SetAnchorPosition(Point(__pTypeContextMenu->GetAnchorPosition().x, yPos + diff));
1090                 __pTypeContextMenu->Show();
1091         }
1092         __pTableView->SetSize(clientBounds.width, clientBounds.height);
1093 }
1094
1095 void
1096 ContactEditorForm::OnGroupedTableViewItemStateChanged(Tizen::Ui::Controls::GroupedTableView &tableView, int groupIndex, int itemIndex, Tizen::Ui::Controls::TableViewItem *pItem, Tizen::Ui::Controls::TableViewItemStatus status)
1097 {
1098         SceneManager* pSceneManager = SceneManager::GetInstance();
1099
1100         if (status == TABLE_VIEW_ITEM_STATUS_SELECTED && groupIndex == TABLE_VIEW_GROUP_RINGTONE_FIELD_INDEX)
1101         {
1102                 if (__pCurrentFocusedItem != null)
1103                 {
1104                         SetFocus();
1105                 }
1106
1107                 if (itemIndex == 0)
1108                 {
1109                         if (__pPresentationModel->GetCategoryCount() > 0)
1110                         {
1111                                 IList* pCategoryList = __pPresentationModel->GetAssignedCategoryIdListN();
1112
1113                                 pSceneManager->GoForward(ForwardSceneTransition(IDSCN_GROUP_SELECTOR, SCENE_TRANSITION_ANIMATION_TYPE_LEFT), pCategoryList);
1114                         }
1115                         else
1116                         {
1117                                 pSceneManager->GoForward(ForwardSceneTransition(IDSCN_GROUP_EDITOR, SCENE_TRANSITION_ANIMATION_TYPE_LEFT));
1118                         }
1119
1120                         return;
1121                 }
1122                 else if (itemIndex == 2)
1123                 {
1124                         LaunchAppControl(PROVIDER_ID_FILEMANAGER, OPERATION_ID_PICK);
1125                 }
1126         }
1127 }
1128
1129 void
1130 ContactEditorForm::OnGroupedTableViewContextItemActivationStateChanged(Tizen::Ui::Controls::GroupedTableView &tableView, int groupIndex, int itemIndex, Tizen::Ui::Controls::TableViewContextItem *pContextItem, bool activated)
1131 {
1132 }
1133
1134 void
1135 ContactEditorForm::OnGroupedTableViewGroupItemStateChanged(Tizen::Ui::Controls::GroupedTableView &tableView, int groupIndex, Tizen::Ui::Controls::TableViewGroupItem *pItem, Tizen::Ui::Controls::TableViewItemStatus status)
1136 {
1137 }
1138
1139 int
1140 ContactEditorForm::GetGroupCount(void)
1141 {
1142         return GROUP_ITEM_COUNT;
1143 }
1144
1145 int
1146 ContactEditorForm::GetItemCount(int groupIndex)
1147 {
1148         int itemCount = 0;
1149
1150         switch (groupIndex)
1151         {
1152         case TABLE_VIEW_THUMBNAIL_FIELD_INDEX:
1153                 {
1154                         itemCount = 1;
1155                 }
1156                 break;
1157         case TABLE_VIEW_NAME_FIELD_INDEX:
1158                 {
1159                         itemCount = NAME_FIELD_ITEM_COUNT;
1160                 }
1161                 break;
1162         case TABLE_VIEW_PHONE_NUMBER_FIELD_INDEX:
1163                 {
1164                         itemCount = __pPresentationModel->GetMultiValuesCount(DETAIL_PROPERTY_PHONE_NUMBER) + 1;
1165
1166                         if (__pPresentationModel->GetMultiValuesCount(DETAIL_PROPERTY_PHONE_NUMBER) > 1)
1167                         {
1168                                 __isDefaultPhoneNumberButtonEnabled = true;
1169                                 itemCount++;
1170                         }
1171                         else
1172                         {
1173                                 __isDefaultPhoneNumberButtonEnabled = false;
1174                         }
1175                 }
1176                 break;
1177         case TABLE_VIEW_EMAIL_FIELD_INDEX:
1178                 {
1179                         itemCount = __pPresentationModel->GetMultiValuesCount(DETAIL_PROPERTY_EMAIL) + 1;
1180                 }
1181                 break;
1182         case TABLE_VIEW_ADDRESS_FIELD_INDEX:
1183                 {
1184                         itemCount = __pPresentationModel->GetMultiValuesCount(DETAIL_PROPERTY_ADDRESS) + 1;
1185                 }
1186                 break;
1187         case TABLE_VIEW_IM_ADDRESS_FIELD_INDEX:
1188                 {
1189                         itemCount = __pPresentationModel->GetMultiValuesCount(DETAIL_PROPERTY_IM_ADDRESS);
1190
1191                         if ((itemCount == 0 && __pImAddressFieldItem->GetCount() > 0) || itemCount > 0)
1192                         {
1193                                 itemCount++;
1194                         }
1195                 }
1196                 break;
1197         case TABLE_VIEW_URL_FIELD_INDEX:
1198                 {
1199                         itemCount = __pPresentationModel->GetMultiValuesCount(DETAIL_PROPERTY_URL);
1200
1201                         if ((itemCount == 0 && __pUrlFieldItem->GetCount() > 0) || itemCount > 0)
1202                         {
1203                                 itemCount++;
1204                         }
1205                 }
1206                 break;
1207         case TABLE_VIEW_BIRTHDAY_FIELD_INDEX:
1208                 {
1209                         DateTime birthday;
1210                         if (__pPresentationModel->GetBirthday(birthday) != E_SUCCESS)
1211                         {
1212                                 itemCount = 0;
1213                         }
1214                         else
1215                         {
1216                                 itemCount = 1;
1217                         }
1218                 }
1219                 break;
1220         case TABLE_VIEW_NOTE_FIELD_INDEX:
1221                 {
1222                         if (__pPresentationModel->GetValue(DETAIL_PROPERTY_NOTE).IsEmpty() == false || __pNoteFieldItem != null )
1223                         {
1224                                 itemCount = 1;
1225                         }
1226                         else
1227                         {
1228                                 itemCount = 0;
1229                         }
1230                 }
1231                 break;
1232         case TABLE_VIEW_GROUP_RINGTONE_FIELD_INDEX:
1233                 {
1234                         itemCount = 3;
1235                 }
1236                 break;
1237         case TABLE_VIEW_MORE_INFORMATION_FIELD_INDEX:
1238                 {
1239                         if (IsMoreInformationButtonVisible())
1240                         {
1241                                 itemCount = 1;
1242                         }
1243                         else
1244                         {
1245                                 itemCount = 0;
1246                         }
1247                 }
1248                 break;
1249         default:
1250                 break;
1251         }
1252
1253         return itemCount;
1254 }
1255
1256 int
1257 ContactEditorForm::GetDefaultGroupItemHeight(void)
1258 {
1259         return H_EMPTY_SPACE;
1260 }
1261
1262 int
1263 ContactEditorForm::GetDefaultItemHeight(void)
1264 {
1265         ContactsApp *pContactsApp = static_cast<ContactsApp*>(ContactsApp::GetInstance());
1266         return pContactsApp->GetListItemSingleLineHeight();
1267 }
1268
1269 TableViewGroupItem*
1270 ContactEditorForm::CreateGroupItem(int groupIndex, int itemWidth)
1271 {
1272         int groupItemHeight = H_EMPTY_SPACE;
1273
1274         if (groupIndex == TABLE_VIEW_THUMBNAIL_FIELD_INDEX)
1275         {
1276                 groupItemHeight = H_THUMBNAIL_GROUP_ITEM_HEIGHT;
1277         }
1278         else if (groupIndex == TABLE_VIEW_NAME_FIELD_INDEX)
1279         {
1280                 groupItemHeight = H_NAMEFIELD_GROUP_ITEM_HEIGHT;
1281         }
1282         else if (groupIndex == TABLE_VIEW_BIRTHDAY_FIELD_INDEX)
1283         {
1284                 groupItemHeight = Y_EDIT_FIELD_GAP;
1285         }
1286         else if (groupIndex == TABLE_VIEW_NOTE_FIELD_INDEX)
1287         {
1288                 groupItemHeight = H_EDIT_FIELD_GAP;
1289         }
1290         else if ((groupIndex > TABLE_VIEW_PHONE_NUMBER_FIELD_INDEX && groupIndex < TABLE_VIEW_GROUP_RINGTONE_FIELD_INDEX) || groupIndex == TABLE_VIEW_MORE_INFORMATION_FIELD_INDEX)
1291         {
1292                 groupItemHeight = 0;
1293         }
1294
1295         TableViewGroupItem* pGroupItem = new (std::nothrow) TableViewGroupItem();
1296         pGroupItem->Construct(Dimension(itemWidth, groupItemHeight));
1297         pGroupItem->SetBackgroundColor(Color(COLOR_TABLE_VIEW_BG), TABLE_VIEW_ITEM_DRAWING_STATUS_NORMAL);
1298         pGroupItem->SetEnabled(false);
1299
1300         Panel* pPanel = new (std::nothrow) Panel();
1301         pPanel->Construct(Rectangle(0, -(H_DIVIDER), itemWidth, groupItemHeight + H_DIVIDER));
1302         pPanel->SetBackgroundColor(Color(COLOR_TABLE_VIEW_BG));
1303
1304         pGroupItem->AddControl(pPanel);
1305
1306         return pGroupItem;
1307 }
1308
1309 bool
1310 ContactEditorForm::DeleteGroupItem(int groupIndex, Tizen::Ui::Controls::TableViewGroupItem* pItem)
1311 {
1312         delete pItem;
1313         pItem = null;
1314
1315         return true;
1316 }
1317
1318 TableViewItem*
1319 ContactEditorForm::CreateItem(int groupIndex, int itemIndex, int itemWidth)
1320 {
1321         TableViewItem* pItem = null;
1322
1323         switch (groupIndex)
1324         {
1325         case TABLE_VIEW_THUMBNAIL_FIELD_INDEX:
1326                 {
1327                         pItem = GetThumbnailField(itemWidth);
1328                 }
1329                 break;
1330         case TABLE_VIEW_NAME_FIELD_INDEX:
1331                 {
1332                         pItem = GetNameFields(itemWidth);
1333                 }
1334                 break;
1335         case TABLE_VIEW_PHONE_NUMBER_FIELD_INDEX:
1336                 {
1337                         if ((itemIndex == __pTableView->GetItemCountAt(groupIndex) - 1) && __isDefaultPhoneNumberButtonEnabled == true)
1338                         {
1339                                 pItem = GetDefaultPhoneNumberItem(itemWidth);
1340                                 break;
1341                         }
1342
1343                         pItem = GetPhoneNumberFields(itemIndex, itemWidth);
1344                 }
1345                 break;
1346         case TABLE_VIEW_EMAIL_FIELD_INDEX:
1347                 {
1348                         pItem = GetEmailFields(itemIndex, itemWidth);
1349                 }
1350                 break;
1351         case TABLE_VIEW_ADDRESS_FIELD_INDEX:
1352                 {
1353                         pItem = GetAddressFields(itemIndex, itemWidth);
1354                 }
1355                 break;
1356         case TABLE_VIEW_IM_ADDRESS_FIELD_INDEX:
1357                 {
1358                         pItem = GetImAddressFields(itemIndex, itemWidth);
1359                 }
1360                 break;
1361         case TABLE_VIEW_URL_FIELD_INDEX:
1362                 {
1363                         pItem = GetUrlFields(itemIndex, itemWidth);
1364                 }
1365                 break;
1366         case TABLE_VIEW_BIRTHDAY_FIELD_INDEX:
1367                 {
1368                         pItem = GetBirthdayField(itemWidth);
1369                 }
1370                 break;
1371         case TABLE_VIEW_NOTE_FIELD_INDEX:
1372                 {
1373                         pItem = GetNoteField(itemWidth);
1374                 }
1375                 break;
1376         case TABLE_VIEW_GROUP_RINGTONE_FIELD_INDEX:
1377                 {
1378                         switch (itemIndex)
1379                         {
1380                         case 0:
1381                                 pItem = GetGroupsField(itemWidth);
1382                                 break;
1383                         case 1:
1384                                 {
1385                                         pItem = new (std::nothrow) TableViewItem();
1386                                         pItem->Construct(Dimension(itemWidth, H_DIVIDER * 2));
1387                                         pItem->SetEnabled(false);
1388                                 }
1389                                 break;
1390                         case 2:
1391                                 pItem = GetRingtoneField(itemWidth);
1392                                 break;
1393                         default:
1394                                 break;
1395                         }
1396                 }
1397                 break;
1398         case TABLE_VIEW_MORE_INFORMATION_FIELD_INDEX:
1399                 {
1400                         if (IsMoreInformationButtonVisible())
1401                         {
1402                                 pItem = GetMoreInformationField(itemWidth);
1403                         }
1404                         else
1405                         {
1406                                 pItem = null;
1407                         }
1408                 }
1409                 break;
1410         default:
1411                 break;
1412         }
1413
1414         return pItem;
1415 }
1416
1417 bool
1418 ContactEditorForm::DeleteItem(int groupIndex, int itemIndex, Tizen::Ui::Controls::TableViewItem* pItem)
1419 {
1420         if ((groupIndex > TABLE_VIEW_NAME_FIELD_INDEX && groupIndex < TABLE_VIEW_BIRTHDAY_FIELD_INDEX) || groupIndex == TABLE_VIEW_NOTE_FIELD_INDEX)
1421         {
1422                 int index = -1;
1423                 __pDeletedItemList->IndexOf(*pItem, index);
1424
1425                 if (index >= 0)
1426                 {
1427                         __pDeletedItemList->RemoveAt(index);
1428                 }
1429                 else
1430                 {
1431                         return true;
1432                 }
1433         }
1434         else if (groupIndex == TABLE_VIEW_NAME_FIELD_INDEX)
1435         {
1436                 SaveNameFields();
1437                 __pNameFieldItem = null;
1438         }
1439
1440         if (__pCurrentFocusedItem == pItem && __isKeypadOpened)
1441         {
1442                 __isKeypadOpened = false;
1443         }
1444
1445         delete pItem;
1446         pItem = null;
1447
1448         return true;
1449 }
1450
1451 void
1452 ContactEditorForm::UpdateGroupItem(int groupIndex, Tizen::Ui::Controls::TableViewGroupItem *pItem)
1453 {
1454 }
1455
1456 void
1457 ContactEditorForm::UpdateItem(int groupIndex, int itemIndex, Tizen::Ui::Controls::TableViewItem *pItem)
1458 {
1459         if (pItem == null)
1460         {
1461                 return;
1462         }
1463
1464         switch (groupIndex)
1465         {
1466         case TABLE_VIEW_THUMBNAIL_FIELD_INDEX:
1467                 {
1468                         SetThumbnailControls(*pItem, true);
1469                         pItem->Invalidate(true);
1470                 }
1471                 break;
1472         case TABLE_VIEW_NAME_FIELD_INDEX:
1473                 {
1474                         if (__pCurrentFocusedItem == pItem && __isKeypadOpened)
1475                         {
1476                                 __isKeypadOpened = false;
1477                         }
1478                         pItem->RemoveAllControls();
1479                         SetNameFields(*pItem);
1480                         Invalidate(true);
1481                 }
1482             break;
1483         case TABLE_VIEW_GROUP_RINGTONE_FIELD_INDEX:
1484                 {
1485                         String valueString;
1486                         Panel* pPanel = static_cast<Panel*>(pItem->GetControl(0));
1487
1488                         if (pPanel == null)
1489                         {
1490                                 return;
1491                         }
1492
1493                         Label* pLabel = static_cast<Label*>(pPanel->GetControl(1));
1494
1495                         if (pLabel == null)
1496                         {
1497                                 return;
1498                         }
1499
1500                         if (itemIndex == 0)
1501                         {
1502                                 valueString =  __pPresentationModel->GetValue(DETAIL_PROPERTY_GROUP);
1503                                 if (valueString.IsEmpty() == true)
1504                                 {
1505                                         valueString = ResourceManager::GetString(L"IDS_PB_BODY_NOT_ASSIGNED");
1506                                 }
1507                         }
1508                         else if (itemIndex == 2)
1509                         {
1510                                 String ringtoneName =  __pPresentationModel->GetValue(DETAIL_PROPERTY_RINGTONE);
1511                                 int index = 0;
1512
1513                                 ringtoneName.LastIndexOf(L"/", ringtoneName.GetLength() - 1, index);
1514
1515                                 if (index != 0)
1516                                 {
1517                                         ringtoneName.SubString(index + 1, valueString);
1518                                 }
1519                         }
1520
1521                         pLabel->SetText(valueString);
1522                         pLabel->Invalidate(false);
1523                 }
1524                 break;
1525         case TABLE_VIEW_BIRTHDAY_FIELD_INDEX:
1526                 {
1527                         int min;
1528                         int max;
1529                         DateTime birthdayDate;
1530                         EditDate* pBirthday = static_cast<EditDate *>(pItem->GetControl(1));
1531
1532                         if (pBirthday == null)
1533                         {
1534                                 return;
1535                         }
1536
1537                         __pPresentationModel->GetBirthday(birthdayDate);
1538
1539                         pBirthday->GetYearRange(min, max);
1540                         max = birthdayDate.GetYear();
1541                         pBirthday->SetYearRange(max - BIRTHDAY_MIN_YEAR_DIFF, max);
1542                         pBirthday->SetDate(birthdayDate);
1543                         pBirthday->Invalidate(false);
1544                 }
1545                 break;
1546         case TABLE_VIEW_NOTE_FIELD_INDEX:
1547                 {
1548                         Control* pNoteField = pItem->GetControl(1);
1549                         Control* pNoteLabel = pItem->GetControl(0);
1550                         if (pNoteField == null)
1551                         {
1552                                 return;
1553                         }
1554
1555                         pItem->SetSize(pItem->GetWidth(), pNoteLabel->GetHeight() + pNoteField->GetHeight() + H_EDIT_FIELD_GAP);
1556                 }
1557                 break;
1558         default:
1559                 break;
1560         }
1561 }
1562
1563 Tizen::Ui::Controls::TableViewItem*
1564 ContactEditorForm::GetThumbnailField(int itemWidth)
1565 {
1566         TableViewItem* pThumbnailItem = new (std::nothrow) TableViewItem();
1567         pThumbnailItem->Construct(Dimension(itemWidth, W_THUMBNAIL + H_THUMBNAIL_DELETE_BUTTON_GAP + Y_EDIT_FIELD_GAP * 2));
1568         pThumbnailItem->SetBackgroundColor(Color(0), TABLE_VIEW_ITEM_DRAWING_STATUS_PRESSED);
1569
1570         SetThumbnailControls(*pThumbnailItem);
1571
1572         return pThumbnailItem;
1573 }
1574
1575 Tizen::Ui::Controls::TableViewItem*
1576 ContactEditorForm::GetNameFields(int itemWidth)
1577 {
1578         ContactsApp *pContactsApp = static_cast<ContactsApp*>(ContactsApp::GetInstance());
1579
1580         __pNameFieldItem = new (std::nothrow) TableViewItem();
1581         __pNameFieldItem->Construct(Dimension(itemWidth, pContactsApp->GetListItemSingleLineHeight()));
1582         __pNameFieldItem->SetBackgroundColor(Color(0), TABLE_VIEW_ITEM_DRAWING_STATUS_PRESSED);
1583
1584         SetNameFields(*__pNameFieldItem);
1585
1586         return __pNameFieldItem;
1587 }
1588
1589 void
1590 ContactEditorForm::SetNameFields(Tizen::Ui::Controls::TableViewItem& item)
1591 {
1592         ContactsApp *pContactsApp = static_cast<ContactsApp*>(ContactsApp::GetInstance());
1593
1594         int itemWidth = item.GetWidth();
1595         int itemHeight = pContactsApp->GetListItemSingleLineHeight();
1596
1597         if (__isExpandable == true)
1598         {
1599                 itemHeight = DEFAULT_EXPAND_NAME_FIELD_COUNT * pContactsApp->GetListItemSingleLineHeight();
1600
1601                 if (__isJobTitleEnabled == true)
1602                 {
1603                         itemHeight += pContactsApp->GetListItemSingleLineHeight();
1604                 }
1605
1606                 if (__isDepartmentEnabled)
1607                 {
1608                         itemHeight += pContactsApp->GetListItemSingleLineHeight();
1609                 }
1610         }
1611
1612         item.SetSize(itemWidth, itemHeight);
1613
1614         Rectangle itemBounds(W_ITEM_GAP, Y_EDIT_FIELD_GAP, itemWidth - (W_ITEM_GAP * 3) - H_BUTTON, pContactsApp->GetListItemSingleLineHeight() - H_EDIT_FIELD_GAP);
1615
1616         if (__isExpandable == true)
1617         {
1618                 EditField* pFirstName = new (std::nothrow) EditField();
1619                 pFirstName->Construct(itemBounds, EDIT_FIELD_STYLE_NORMAL, INPUT_STYLE_OVERLAY, false, __pPresentationModel->GetValue(DETAIL_PROPERTY_FIRST_NAME).GetLength() + EDIT_FIELD_EXTENDED_LENGTH);
1620                 pFirstName->SetGuideText(ResourceManager::GetString(L"IDS_PB_BODY_FIRST_NAME"));
1621                 pFirstName->AddFocusEventListener(*this);
1622                 pFirstName->AddKeypadEventListener(*this);
1623                 pFirstName->SetName(ResourceManager::GetString(L"IDS_PB_BODY_FIRST_NAME"));
1624                 pFirstName->SetText(__pPresentationModel->GetValue(DETAIL_PROPERTY_FIRST_NAME));
1625                 pFirstName->AddTextEventListener(*this);
1626                 pFirstName->SetTextSize(pContactsApp->GetFontSize());
1627
1628                 item.AddControl(pFirstName);
1629                 item.SetIndividualSelectionEnabled(pFirstName, true);
1630
1631                 itemBounds.y += pContactsApp->GetListItemSingleLineHeight();
1632                 EditField* pMiddleName = new (std::nothrow) EditField();
1633                 pMiddleName->Construct(itemBounds, EDIT_FIELD_STYLE_NORMAL, INPUT_STYLE_OVERLAY, false, __pPresentationModel->GetValue(DETAIL_PROPERTY_MIDDLE_NAME).GetLength() + EDIT_FIELD_EXTENDED_LENGTH);
1634                 pMiddleName->SetGuideText(ResourceManager::GetString(L"IDS_PB_BODY_MIDDLE_NAME"));
1635                 pMiddleName->AddFocusEventListener(*this);
1636                 pMiddleName->AddKeypadEventListener(*this);
1637                 pMiddleName->AddTextEventListener(*this);
1638                 pMiddleName->SetName(ResourceManager::GetString(L"IDS_PB_BODY_MIDDLE_NAME"));
1639                 pMiddleName->SetText(__pPresentationModel->GetValue(DETAIL_PROPERTY_MIDDLE_NAME));
1640                 pMiddleName->SetTextSize(pContactsApp->GetFontSize());
1641
1642                 item.AddControl(pMiddleName);
1643                 item.SetIndividualSelectionEnabled(pMiddleName, true);
1644
1645                 itemBounds.y += pContactsApp->GetListItemSingleLineHeight();
1646                 EditField* pLastName = new (std::nothrow) EditField();
1647                 pLastName->Construct(itemBounds, EDIT_FIELD_STYLE_NORMAL, INPUT_STYLE_OVERLAY, false, __pPresentationModel->GetValue(DETAIL_PROPERTY_LAST_NAME).GetLength() + EDIT_FIELD_EXTENDED_LENGTH);
1648                 pLastName->SetGuideText(ResourceManager::GetString(L"IDS_PB_BODY_LAST_NAME"));
1649                 pLastName->AddFocusEventListener(*this);
1650                 pLastName->AddKeypadEventListener(*this);
1651                 pLastName->SetName(ResourceManager::GetString(L"IDS_PB_BODY_LAST_NAME"));
1652                 pLastName->SetText(__pPresentationModel->GetValue(DETAIL_PROPERTY_LAST_NAME));
1653                 pLastName->SetTextSize(pContactsApp->GetFontSize());
1654                 pLastName->AddTextEventListener(*this);
1655
1656                 item.AddControl(pLastName);
1657                 item.SetIndividualSelectionEnabled(pLastName, true);
1658
1659                 itemBounds.y += pContactsApp->GetListItemSingleLineHeight();
1660                 EditField* pSuffix = new (std::nothrow) EditField();
1661                 pSuffix->Construct(itemBounds, EDIT_FIELD_STYLE_NORMAL, INPUT_STYLE_OVERLAY, false, __pPresentationModel->GetValue(DETAIL_PROPERTY_NAME_SUFFIX).GetLength() + EDIT_FIELD_EXTENDED_LENGTH);
1662                 pSuffix->SetGuideText(ResourceManager::GetString(L"IDS_PB_BODY_SUFFIX"));
1663                 pSuffix->AddFocusEventListener(*this);
1664                 pSuffix->AddKeypadEventListener(*this);
1665                 pSuffix->AddTextEventListener(*this);
1666                 pSuffix->SetName(ResourceManager::GetString(L"IDS_PB_BODY_SUFFIX"));
1667                 pSuffix->SetText(__pPresentationModel->GetValue(DETAIL_PROPERTY_NAME_SUFFIX));
1668                 pSuffix->SetTextSize(pContactsApp->GetFontSize());
1669
1670                 item.AddControl(pSuffix);
1671                 item.SetIndividualSelectionEnabled(pSuffix, true);
1672
1673                 itemBounds.y += pContactsApp->GetListItemSingleLineHeight();
1674                 EditField* pNickName = new (std::nothrow) EditField();
1675                 pNickName->Construct(itemBounds, EDIT_FIELD_STYLE_NORMAL, INPUT_STYLE_OVERLAY);
1676                 pNickName->SetGuideText(ResourceManager::GetString(L"IDS_PB_BODY_NICKNAME"));
1677                 pNickName->AddFocusEventListener(*this);
1678                 pNickName->AddKeypadEventListener(*this);
1679                 pNickName->AddTextEventListener(*this);
1680                 pNickName->SetName(ResourceManager::GetString(L"IDS_PB_BODY_NICKNAME"));
1681                 pNickName->SetText(__pPresentationModel->GetValue(DETAIL_PROPERTY_NICK_NAME));
1682                 pNickName->SetTextSize(pContactsApp->GetFontSize());
1683
1684                 item.AddControl(pNickName);
1685                 item.SetIndividualSelectionEnabled(pNickName, true);
1686
1687                 itemBounds.y += pContactsApp->GetListItemSingleLineHeight();
1688                 if (__isJobTitleEnabled == true)
1689                 {
1690                         EditField* pJobTitle = new (std::nothrow) EditField();
1691                         pJobTitle->Construct(itemBounds, EDIT_FIELD_STYLE_NORMAL, INPUT_STYLE_OVERLAY);
1692                         pJobTitle->SetGuideText(ResourceManager::GetString(L"IDS_PB_BODY_JOB_TITLE"));
1693                         pJobTitle->AddFocusEventListener(*this);
1694                         pJobTitle->AddKeypadEventListener(*this);
1695                         pJobTitle->AddTextEventListener(*this);
1696                         pJobTitle->SetName(ResourceManager::GetString(L"IDS_PB_BODY_JOB_TITLE"));
1697                         pJobTitle->SetText(__pPresentationModel->GetValue(DETAIL_PROPERTY_JOB_TITLE));
1698                         pJobTitle->SetTextSize(pContactsApp->GetFontSize());
1699
1700                         item.AddControl(pJobTitle);
1701                         item.SetIndividualSelectionEnabled(pJobTitle, true);
1702
1703                         itemBounds.y += pContactsApp->GetListItemSingleLineHeight();
1704                 }
1705
1706                 if (__isDepartmentEnabled == true)
1707                 {
1708                         EditField* pDepartment = new (std::nothrow) EditField();
1709                         pDepartment->Construct(itemBounds, EDIT_FIELD_STYLE_NORMAL, INPUT_STYLE_OVERLAY);
1710                         pDepartment->SetGuideText(ResourceManager::GetString(L"IDS_PB_BODY_DEPARTMENT"));
1711                         pDepartment->AddFocusEventListener(*this);
1712                         pDepartment->AddKeypadEventListener(*this);
1713                         pDepartment->AddTextEventListener(*this);
1714                         pDepartment->SetName(ResourceManager::GetString(L"IDS_PB_BODY_DEPARTMENT"));
1715                         pDepartment->SetText(__pPresentationModel->GetValue(DETAIL_PROPERTY_DEPARTMENT));
1716                         pDepartment->SetTextSize(pContactsApp->GetFontSize());
1717
1718                         item.AddControl(pDepartment);
1719                         item.SetIndividualSelectionEnabled(pDepartment, true);
1720
1721                         itemBounds.y += pContactsApp->GetListItemSingleLineHeight();
1722                 }
1723
1724                 EditField* pCompanyName = new (std::nothrow) EditField();
1725                 pCompanyName->Construct(itemBounds, EDIT_FIELD_STYLE_NORMAL, INPUT_STYLE_OVERLAY);
1726                 pCompanyName->SetGuideText(ResourceManager::GetString(L"IDS_PB_BODY_COMPANY"));
1727                 pCompanyName->AddFocusEventListener(*this);
1728                 pCompanyName->AddKeypadEventListener(*this);
1729                 pCompanyName->SetName(ResourceManager::GetString(L"IDS_PB_BODY_COMPANY"));
1730                 pCompanyName->SetText(__pPresentationModel->GetValue(DETAIL_PROPERTY_COMPANY));
1731                 pCompanyName->SetTextSize(pContactsApp->GetFontSize());
1732
1733                 item.AddControl(pCompanyName);
1734                 item.SetIndividualSelectionEnabled(pCompanyName, true);
1735         }
1736         else
1737         {
1738                 int nameLength = 0;
1739                 String firstName(__pPresentationModel->GetValue(DETAIL_PROPERTY_FIRST_NAME));
1740                 String lastName(__pPresentationModel->GetValue(DETAIL_PROPERTY_LAST_NAME));
1741                 String middleName(__pPresentationModel->GetValue(DETAIL_PROPERTY_MIDDLE_NAME));
1742                 String suffix(__pPresentationModel->GetValue(DETAIL_PROPERTY_NAME_SUFFIX));
1743
1744                 nameLength = firstName.GetLength() + lastName.GetLength() + middleName.GetLength();
1745                 if (suffix.IsEmpty() == false)
1746                 {
1747                         nameLength = nameLength + suffix.GetLength() + 1;
1748                 }
1749
1750                 EditField* pName = new (std::nothrow) EditField();
1751                 pName->Construct(itemBounds, EDIT_FIELD_STYLE_NORMAL, INPUT_STYLE_OVERLAY, false, nameLength + EDIT_FIELD_EXTENDED_LENGTH);
1752                 pName->SetGuideText(ResourceManager::GetString(L"IDS_COM_BODY_DETAILS_NAME"));
1753                 pName->AddFocusEventListener(*this);
1754                 pName->AddKeypadEventListener(*this);
1755                 pName->SetName(Integer::ToString(IDA_INPUT_FIELD_DISPLAY_NAME));
1756                 pName->AddTextEventListener(*this);
1757                 pName->SetTextSize(pContactsApp->GetFontSize());
1758
1759                 if (firstName.IsEmpty() == false)
1760                 {
1761                         pName->SetText(firstName);
1762                 }
1763
1764                 if (middleName.IsEmpty() == false)
1765                 {
1766                         pName->AppendText(CHARACTER_SPACE + middleName);
1767                 }
1768
1769                 if (lastName.IsEmpty() == false)
1770                 {
1771                         pName->AppendText(CHARACTER_SPACE + lastName);
1772                 }
1773
1774                 if (suffix.IsEmpty() == false)
1775                 {
1776                         pName->AppendText(DELIMITER_COMMA);
1777                         pName->AppendText(CHARACTER_SPACE + suffix);
1778                 }
1779
1780                 item.AddControl(pName);
1781                 item.SetIndividualSelectionEnabled(pName, true);
1782                 __fullName = pName->GetText();
1783         }
1784
1785         Button* pButtonExpand = new (std::nothrow) Button();
1786         pButtonExpand->Construct(Rectangle(itemWidth - (H_BUTTON + W_ITEM_GAP), (pContactsApp->GetListItemSingleLineHeight() - H_BUTTON) / 2, H_BUTTON, H_BUTTON));
1787         pButtonExpand->SetActionId(IDA_BUTTON_EXPANDABLE);
1788         pButtonExpand->SetName(EXPAND_BUTTON);
1789         pButtonExpand->AddActionEventListener(*this);
1790
1791         Bitmap* pBitmap = null;
1792         Bitmap* pBitmapPressed = null;
1793
1794         if (__isExpandable == true)
1795         {
1796                 pBitmap = ResourceManager::GetBitmapN(IDB_EXPAND_OPENED);
1797                 pBitmapPressed = ResourceManager::GetBitmapN(IDB_EXPAND_OPENED_PRESSED);
1798         }
1799         else
1800         {
1801                 pBitmap = ResourceManager::GetBitmapN(IDB_EXPAND_CLOSED);
1802                 pBitmapPressed = ResourceManager::GetBitmapN(IDB_EXPAND_CLOSED_PRESSED);
1803         }
1804
1805         if (pBitmap != null)
1806         {
1807                 pButtonExpand->SetNormalBitmap(Point(0, 0), *pBitmap);
1808         }
1809
1810         if (pBitmapPressed != null)
1811         {
1812                 pButtonExpand->SetPressedBitmap(Point(0, 0), *pBitmapPressed);
1813         }
1814
1815         delete pBitmap;
1816         delete pBitmapPressed;
1817
1818         pBitmap = ResourceManager::GetBitmapN(IDB_EXPAND_BUTTON_NORMAL);
1819         pBitmapPressed = ResourceManager::GetBitmapN(IDB_EXPAND_BUTTON_PRESSED);
1820
1821         if (pBitmap != null)
1822         {
1823                 pButtonExpand->SetNormalBackgroundBitmap(*pBitmap);
1824                 delete pBitmap;
1825         }
1826         if (pBitmapPressed != null)
1827         {
1828                 pButtonExpand->SetPressedBackgroundBitmap(*pBitmapPressed);
1829                 delete pBitmapPressed;
1830         }
1831
1832         item.AddControl(pButtonExpand);
1833         item.SetIndividualSelectionEnabled(pButtonExpand, true);
1834 }
1835
1836 Tizen::Ui::Controls::TableViewItem*
1837 ContactEditorForm::GetInputFieldN(int groupIndex, int itemIndex, int itemWidth, Tizen::Ui::Controls::EditFieldStyle style, const Tizen::Base::String& titleText, const Tizen::Base::String& guideText, const Tizen::Base::String& text, bool isDeleteButton)
1838 {
1839         ContactsApp *pContactsApp = static_cast<ContactsApp*>(ContactsApp::GetInstance());
1840
1841         TableViewItem* pTableViewItem = new (std::nothrow) TableViewItem();
1842         pTableViewItem->Construct(Dimension(itemWidth, pContactsApp->GetListItemSingleLineHeight()), TABLE_VIEW_ANNEX_STYLE_NORMAL);
1843         pTableViewItem->SetBackgroundColor(Color(0), TABLE_VIEW_ITEM_DRAWING_STATUS_PRESSED);
1844
1845         EditField* pInputField = new (std::nothrow) EditField();
1846         pInputField->Construct(Rectangle(W_ITEM_GAP, Y_EDIT_FIELD_GAP, itemWidth - (W_ITEM_GAP * 4) - H_BUTTON - W_TYPE_BUTTON, pContactsApp->GetListItemSingleLineHeight() - H_EDIT_FIELD_GAP), style, INPUT_STYLE_OVERLAY);
1847         pInputField->SetGuideText(guideText);
1848         pInputField->SetText(text);
1849         pInputField->SetTextSize(pContactsApp->GetFontSize());
1850         pInputField->AddKeypadEventListener(*this);
1851         pInputField->AddFocusEventListener(*this);
1852         pInputField->AddTextEventListener(*this);
1853         pInputField->SetEnabled(true);
1854
1855         int parsedItemIndex = 0;
1856         parsedItemIndex |= (groupIndex << TABLE_VIEW_INPUT_FIELD_ACTION_SHIFT);
1857         parsedItemIndex |= (groupIndex << TABLE_VIEW_GROUP_INDEX_SHIFT);
1858         parsedItemIndex |= itemIndex;
1859
1860         pInputField->SetName(Integer::ToString(parsedItemIndex));
1861         pTableViewItem->AddControl(pInputField);
1862
1863         Button *pButtonType = new (std::nothrow) Button();
1864         pButtonType->Construct(Rectangle(pInputField->GetX() + pInputField->GetWidth() + W_ITEM_GAP, (pContactsApp->GetListItemSingleLineHeight() - H_BUTTON) / 2, W_TYPE_BUTTON, H_BUTTON));
1865         pButtonType->SetText(titleText);
1866         pButtonType->SetActionId(IDA_BUTTON_TYPE);
1867         pButtonType->AddActionEventListener(*this);
1868         pButtonType->AddTouchEventListener(*this);
1869         pButtonType->SetName(Integer::ToString(parsedItemIndex));
1870
1871         Bitmap* pDropBoxIcon = ResourceManager::GetBitmapN(IDB_BUTTON_DROPBOX);
1872
1873         if (pDropBoxIcon != null)
1874         {
1875                 pButtonType->SetNormalBitmap(Point(W_TYPE_BUTTON - W_DROPBOX_ICON, H_BUTTON - H_DROPBOX_ICON), *pDropBoxIcon);
1876                 pButtonType->SetPressedBitmap(Point(W_TYPE_BUTTON - W_DROPBOX_ICON, H_BUTTON - H_DROPBOX_ICON), *pDropBoxIcon);
1877                 pButtonType->SetDisabledBitmap(Point(W_TYPE_BUTTON - W_DROPBOX_ICON, H_BUTTON - H_DROPBOX_ICON), *pDropBoxIcon);
1878                 delete pDropBoxIcon;
1879         }
1880         pTableViewItem->AddControl(pButtonType);
1881
1882         Button *pButtonDelete = new (std::nothrow) Button();
1883         pButtonDelete->Construct(Rectangle(itemWidth - H_BUTTON - W_ITEM_GAP, (pContactsApp->GetListItemSingleLineHeight() - H_BUTTON) / 2, H_BUTTON, H_BUTTON));
1884         Bitmap* pBitmap = ResourceManager::GetBitmapN(IDB_BUTTON_MINUS);
1885         Bitmap* pBitmapPressed = ResourceManager::GetBitmapN(IDB_BUTTON_MINUS_PRESSED);
1886
1887         if (pBitmap != null)
1888         {
1889                 pButtonDelete->SetNormalBitmap(Point(0, 0), *pBitmap);
1890                 delete pBitmap;
1891         }
1892         if (pBitmapPressed != null)
1893         {
1894                 pButtonDelete->SetPressedBitmap(Point(0, 0), *pBitmapPressed);
1895                 delete pBitmapPressed;
1896         }
1897
1898         pBitmap = ResourceManager::GetBitmapN(IDB_BUTTON_DELETE_NORMAL);
1899         pBitmapPressed = ResourceManager::GetBitmapN(IDB_BUTTON_DELETE_PRESSED);
1900
1901         if (pBitmap != null)
1902         {
1903                 pButtonDelete->SetNormalBackgroundBitmap(*pBitmap);
1904                 delete pBitmap;
1905         }
1906         if (pBitmapPressed != null)
1907         {
1908                 pButtonDelete->SetPressedBackgroundBitmap(*pBitmapPressed);
1909                 delete pBitmapPressed;
1910         }
1911
1912         int actionId = 0;
1913         actionId |= TABLE_VIEW_DELETE_INPUT_FIELD_ID;
1914         actionId |= (groupIndex << TABLE_VIEW_GROUP_INDEX_SHIFT);
1915         actionId |= itemIndex;
1916
1917         pButtonDelete->SetActionId(actionId);
1918         pButtonDelete->AddActionEventListener(*this);
1919
1920         pTableViewItem->AddControl(pButtonDelete);
1921
1922         if (isDeleteButton == false)
1923         {
1924                 pButtonDelete->SetShowState(false);
1925         }
1926
1927         pTableViewItem->SetIndividualSelectionEnabled(pInputField, true);
1928         pTableViewItem->SetIndividualSelectionEnabled(pButtonType, true);
1929         pTableViewItem->SetIndividualSelectionEnabled(pButtonDelete, true);
1930
1931         return pTableViewItem;
1932 }
1933
1934 Tizen::Ui::Controls::TableViewItem*
1935 ContactEditorForm::GetPhoneNumberFields(int itemIndex, int itemWidth)
1936 {
1937         if (__pPhoneNumberFieldItem->GetCount() == 0)
1938         {
1939                 int phoneNumberCount = __pPresentationModel->GetMultiValuesCount(DETAIL_PROPERTY_PHONE_NUMBER);
1940                 String guideText = ResourceManager::GetString(L"IDS_PB_BODY_NUMBER");
1941                 String defaultPhoneNumber = __pPresentationModel->GetValue(DETAIL_PROPERTY_DEFAULT_PHONE_NUMBER);
1942
1943                 for (int i = 0; i < phoneNumberCount; i++)
1944                 {
1945                         String typeString = __pPresentationModel->GetType(DETAIL_PROPERTY_PHONE_NUMBER, i);
1946                         String phoneNumberString =  __pPresentationModel->GetValue(DETAIL_PROPERTY_PHONE_NUMBER, i);
1947
1948                         TableViewItem* pItem = GetInputFieldN(TABLE_VIEW_PHONE_NUMBER_FIELD_INDEX, i, itemWidth, EDIT_FIELD_STYLE_PHONE_NUMBER, typeString, guideText, phoneNumberString, true);
1949                         pItem->SetName(Integer::ToString(__pPresentationModel->GetPhoneNumberType(i)));
1950
1951                         __pPhoneNumberFieldItem->Add(*pItem);
1952                 }
1953
1954                 TableViewItem* pItem = GetInputFieldN(TABLE_VIEW_PHONE_NUMBER_FIELD_INDEX, phoneNumberCount, itemWidth, EDIT_FIELD_STYLE_PHONE_NUMBER, __pPresentationModel->GetPhoneNumberTypeString(DETAIL_PHONENUMBER_TYPE_MOBILE), guideText);
1955                 pItem->SetName(Integer::ToString(DETAIL_PHONENUMBER_TYPE_MOBILE));
1956
1957                 __pPhoneNumberFieldItem->Add(*pItem);
1958                 SetAsDefaultPhoneNumber(__pPresentationModel->GetDefaultNumberIndex());
1959         }
1960
1961         if (__pPhoneNumberFieldItem->GetCount() < (__pPresentationModel->GetMultiValuesCount(DETAIL_PROPERTY_PHONE_NUMBER) + 1))
1962         {
1963                 TableViewItem* pItem = GetInputFieldN(TABLE_VIEW_PHONE_NUMBER_FIELD_INDEX, __pPhoneNumberFieldItem->GetCount(), itemWidth, EDIT_FIELD_STYLE_PHONE_NUMBER, __pPresentationModel->GetPhoneNumberTypeString(DETAIL_PHONENUMBER_TYPE_MOBILE), ResourceManager::GetString(L"IDS_PB_BODY_NUMBER"));
1964                 pItem->SetName(Integer::ToString(DETAIL_PHONENUMBER_TYPE_MOBILE));
1965
1966                 __pPhoneNumberFieldItem->Add(*pItem);
1967         }
1968
1969         TableViewItem* pItem = static_cast<TableViewItem *>(__pPhoneNumberFieldItem->GetAt(itemIndex));
1970         if (pItem == null)
1971         {
1972                 return null;
1973         }
1974
1975         return pItem;
1976 }
1977
1978 Tizen::Ui::Controls::TableViewItem*
1979 ContactEditorForm::GetEmailFields(int itemIndex, int itemWidth)
1980 {
1981         if (__pEmailFieldItem->GetCount() == 0)
1982         {
1983                 int emailCount = __pPresentationModel->GetMultiValuesCount(DETAIL_PROPERTY_EMAIL);
1984                 String guideText = ResourceManager::GetString(L"IDS_COM_BODY_EMAIL");
1985
1986                 for (int i = 0; i < emailCount; i++)
1987                 {
1988                         String typeString = __pPresentationModel->GetType(DETAIL_PROPERTY_EMAIL, i);
1989                         String emailString =  __pPresentationModel->GetValue(DETAIL_PROPERTY_EMAIL, i);
1990
1991                         TableViewItem* pItem = GetInputFieldN(TABLE_VIEW_EMAIL_FIELD_INDEX, i, itemWidth, EDIT_FIELD_STYLE_EMAIL, typeString, guideText, emailString, true);
1992                         pItem->SetName(Integer::ToString(__pPresentationModel->GetEmailType(i)));
1993
1994                         __pEmailFieldItem->Add(*pItem);
1995                 }
1996
1997                 TableViewItem* pItem = GetInputFieldN(TABLE_VIEW_EMAIL_FIELD_INDEX, emailCount, itemWidth, EDIT_FIELD_STYLE_EMAIL, __pPresentationModel->GetEmailTypeString(DETAIL_EMAIL_TYPE_HOME), guideText);
1998                 pItem->SetName(Integer::ToString(DETAIL_EMAIL_TYPE_HOME));
1999
2000                 __pEmailFieldItem->Add(*pItem);
2001         }
2002
2003         if (__pEmailFieldItem->GetCount() < (__pPresentationModel->GetMultiValuesCount(DETAIL_PROPERTY_EMAIL) + 1))
2004         {
2005                 TableViewItem* pItem = GetInputFieldN(TABLE_VIEW_EMAIL_FIELD_INDEX, __pEmailFieldItem->GetCount(), itemWidth, EDIT_FIELD_STYLE_EMAIL, __pPresentationModel->GetEmailTypeString(DETAIL_EMAIL_TYPE_HOME), ResourceManager::GetString(L"IDS_COM_BODY_EMAIL"));
2006                 pItem->SetName(Integer::ToString(DETAIL_EMAIL_TYPE_HOME));
2007
2008                 __pEmailFieldItem->Add(*pItem);
2009         }
2010
2011         TableViewItem* pItem = static_cast<TableViewItem *>(__pEmailFieldItem->GetAt(itemIndex));
2012         if (pItem == null)
2013         {
2014                 return null;
2015         }
2016
2017         return pItem;
2018 }
2019
2020 Tizen::Ui::Controls::TableViewItem*
2021 ContactEditorForm::GetAddressFields(int itemIndex, int itemWidth)
2022 {
2023         if (__pAddressFieldItem->GetCount() == 0)
2024         {
2025                 int addressCount = __pPresentationModel->GetMultiValuesCount(DETAIL_PROPERTY_ADDRESS);
2026                 String guideText = ResourceManager::GetString(L"IDS_PB_BODY_ADDRESS");
2027
2028                 for (int i = 0; i < addressCount; i++)
2029                 {
2030                         String typeString = __pPresentationModel->GetType(DETAIL_PROPERTY_ADDRESS, i);
2031                         String addressString =  __pPresentationModel->GetValue(DETAIL_PROPERTY_ADDRESS, i);
2032
2033                         TableViewItem* pItem= GetInputFieldN(TABLE_VIEW_ADDRESS_FIELD_INDEX, i, itemWidth, EDIT_FIELD_STYLE_NORMAL, typeString, guideText, addressString, true);
2034                         pItem->SetName(Integer::ToString(__pPresentationModel->GetAddressType(DETAIL_PROPERTY_ADDRESS, i)));
2035
2036                         __pAddressFieldItem->Add(*pItem);
2037                 }
2038
2039                 TableViewItem* pItem = GetInputFieldN(TABLE_VIEW_ADDRESS_FIELD_INDEX, addressCount, itemWidth, EDIT_FIELD_STYLE_NORMAL, ResourceManager::GetString(L"IDS_PB_BODY_HOME"), guideText);
2040                 pItem->SetName(Integer::ToString(DETAIL_ADDRESS_TYPE_HOME));
2041
2042                 __pAddressFieldItem->Add(*pItem);
2043         }
2044
2045         if (__pAddressFieldItem->GetCount() < (__pPresentationModel->GetMultiValuesCount(DETAIL_PROPERTY_ADDRESS) + 1))
2046         {
2047                 TableViewItem* pItem = GetInputFieldN(TABLE_VIEW_ADDRESS_FIELD_INDEX, __pAddressFieldItem->GetCount(), itemWidth, EDIT_FIELD_STYLE_NORMAL, ResourceManager::GetString(L"IDS_PB_BODY_HOME"), ResourceManager::GetString(L"IDS_PB_BODY_ADDRESS"));
2048                 pItem->SetName(Integer::ToString(DETAIL_ADDRESS_TYPE_HOME));
2049
2050                 __pAddressFieldItem->Add(*pItem);
2051         }
2052
2053         TableViewItem* pItem = static_cast<TableViewItem *>(__pAddressFieldItem->GetAt(itemIndex));
2054         if (pItem == null)
2055         {
2056                 return null;
2057         }
2058
2059         return pItem;
2060 }
2061
2062 Tizen::Ui::Controls::TableViewItem*
2063 ContactEditorForm::GetImAddressFields(int itemIndex, int itemWidth)
2064 {
2065         if (__pImAddressFieldItem->GetCount() == 0)
2066         {
2067                 int imCount = __pPresentationModel->GetMultiValuesCount(DETAIL_PROPERTY_IM_ADDRESS);
2068                 String guideText = ResourceManager::GetString(L"IDS_PB_HEADER_INSTANT_MESSENGER_ABB");
2069
2070                 for (int i = 0; i < imCount; i++)
2071                 {
2072                         String typeString = __pPresentationModel->GetType(DETAIL_PROPERTY_IM_ADDRESS, i);
2073                         String imString =  __pPresentationModel->GetValue(DETAIL_PROPERTY_IM_ADDRESS, i);
2074
2075                         TableViewItem* pItem = GetInputFieldN(TABLE_VIEW_IM_ADDRESS_FIELD_INDEX, i, itemWidth, EDIT_FIELD_STYLE_NORMAL, typeString, guideText, imString, true);
2076                         pItem->SetName(Integer::ToString(__pPresentationModel->GetImAddressType(i)));
2077
2078                         __pImAddressFieldItem->Add(*pItem);
2079                 }
2080
2081                 TableViewItem* pItem = GetInputFieldN(TABLE_VIEW_IM_ADDRESS_FIELD_INDEX, imCount, itemWidth, EDIT_FIELD_STYLE_NORMAL, IM_ADDRESS_YAHOO, guideText);
2082                 pItem->SetName(Integer::ToString(DETAIL_IM_ADDRESS_TYPE_YAHOO));
2083
2084                 __pImAddressFieldItem->Add(*pItem);
2085         }
2086
2087         if (__pImAddressFieldItem->GetCount() < (__pPresentationModel->GetMultiValuesCount(DETAIL_PROPERTY_IM_ADDRESS) + 1))
2088         {
2089                 TableViewItem* pItem = GetInputFieldN(TABLE_VIEW_IM_ADDRESS_FIELD_INDEX, __pImAddressFieldItem->GetCount(), itemWidth, EDIT_FIELD_STYLE_NORMAL, IM_ADDRESS_YAHOO, ResourceManager::GetString(L"IDS_PB_HEADER_INSTANT_MESSENGER_ABB"));
2090                 pItem->SetName(Integer::ToString(DETAIL_IM_ADDRESS_TYPE_YAHOO));
2091
2092                 __pImAddressFieldItem->Add(*pItem);
2093         }
2094
2095         TableViewItem* pItem = static_cast<TableViewItem *>(__pImAddressFieldItem->GetAt(itemIndex));
2096         if (pItem == null)
2097         {
2098                 return null;
2099         }
2100
2101         return pItem;
2102 }
2103
2104 Tizen::Ui::Controls::TableViewItem*
2105 ContactEditorForm::GetUrlFields(int itemIndex, int itemWidth)
2106 {
2107         if (__pUrlFieldItem->GetCount() == 0)
2108         {
2109                 int urlCount = __pPresentationModel->GetMultiValuesCount(DETAIL_PROPERTY_URL);
2110                 String guideText = ResourceManager::GetString(L"IDS_PB_BODY_URL");
2111
2112                 for (int i = 0; i < urlCount; i++)
2113                 {
2114                         String typeString = __pPresentationModel->GetType(DETAIL_PROPERTY_URL, i);
2115                         String urlString =  __pPresentationModel->GetValue(DETAIL_PROPERTY_URL, i);
2116
2117                         TableViewItem* pItem = GetInputFieldN(TABLE_VIEW_URL_FIELD_INDEX, i, itemWidth, EDIT_FIELD_STYLE_URL, typeString, guideText, urlString, true);
2118                         pItem->SetName(Integer::ToString(__pPresentationModel->GetUrlType(i)));
2119
2120                         __pUrlFieldItem->Add(*pItem);
2121                 }
2122
2123                 TableViewItem* pItem = GetInputFieldN(TABLE_VIEW_URL_FIELD_INDEX, urlCount, itemWidth, EDIT_FIELD_STYLE_URL, __pPresentationModel->GetUrlTypeString(DETAIL_URL_TYPE_HOME), guideText);
2124                 pItem->SetName(Integer::ToString(DETAIL_URL_TYPE_HOME));
2125
2126                 __pUrlFieldItem->Add(*pItem);
2127         }
2128
2129         if (__pUrlFieldItem->GetCount() < (__pPresentationModel->GetMultiValuesCount(DETAIL_PROPERTY_URL) + 1))
2130         {
2131                 TableViewItem* pItem = GetInputFieldN(TABLE_VIEW_URL_FIELD_INDEX, __pUrlFieldItem->GetCount(), itemWidth, EDIT_FIELD_STYLE_URL, __pPresentationModel->GetUrlTypeString(DETAIL_URL_TYPE_HOME), ResourceManager::GetString(L"IDS_PB_BODY_URL"));
2132                 pItem->SetName(Integer::ToString(DETAIL_URL_TYPE_HOME));
2133
2134                 __pUrlFieldItem->Add(*pItem);
2135         }
2136
2137         TableViewItem* pItem = static_cast<TableViewItem *>(__pUrlFieldItem->GetAt(itemIndex));
2138         if (pItem == null)
2139         {
2140                 return null;
2141         }
2142
2143         return pItem;
2144 }
2145 Tizen::Ui::Controls::TableViewItem*
2146 ContactEditorForm::GetGroupsField(int itemWidth)
2147 {
2148         ContactsApp *pContactsApp = static_cast<ContactsApp*>(ContactsApp::GetInstance());
2149
2150         TableViewItem* pGroupsItem = new (std::nothrow) TableViewItem();
2151         pGroupsItem->Construct(Dimension(itemWidth, H_DOUBLE_LINE_ITEM + pContactsApp->GetFontHeightOffset()), TABLE_VIEW_ANNEX_STYLE_NORMAL);
2152         pGroupsItem->SetBackgroundColor(COLOR_THUMBNAIL_BACKGROUND);
2153         pGroupsItem->AddKeyEventListener(*this);
2154
2155         Panel* pGroupStyle = new (std::nothrow) Panel();
2156         pGroupStyle->Construct(Rectangle(0, 0, itemWidth , H_DOUBLE_LINE_ITEM + pContactsApp->GetFontHeightOffset()), GROUP_STYLE_NONE);
2157         pGroupStyle->SetName(GROUP_STYLE_PANEL);
2158         pGroupStyle->SetBackgroundColor(COLOR_THUMBNAIL_BACKGROUND);
2159         pGroupStyle->AddTouchEventListener(*this);
2160         pGroupsItem->AddControl(pGroupStyle);
2161
2162         Label* pLabelTitle = new (std::nothrow) Label();
2163         pLabelTitle->Construct(Rectangle(0, H_GROUP_RINGTONE_TITLE_GAP, itemWidth, H_GROUP_RINGTONE_TITLE_LABEL), ResourceManager::GetString(L"IDS_PB_BODY_GROUPS"));
2164         pLabelTitle->SetName(GROUP_LABEL_TITLE);
2165         pLabelTitle->AddTouchEventListener(*this);
2166         pLabelTitle->SetTextConfig(FONT_SIZE_TITLE_TEXT, LABEL_TEXT_STYLE_BOLD);
2167         pLabelTitle->SetTextColor(COLOR_ITEM_TITLE);
2168         pLabelTitle->SetTextHorizontalAlignment(ALIGNMENT_LEFT);
2169
2170         pGroupStyle->AddControl(pLabelTitle);
2171
2172         String groupsName =  __pPresentationModel->GetValue(DETAIL_PROPERTY_GROUP);
2173         if (groupsName.IsEmpty() == true)
2174         {
2175                 groupsName = ResourceManager::GetString(L"IDS_PB_BODY_NOT_ASSIGNED");
2176         }
2177
2178         Label* pLabelGroupName = new (std::nothrow) Label();
2179         pLabelGroupName->Construct(Rectangle(0, H_GROUP_RINGTONE_TITLE_GAP + H_GROUP_RINGTONE_TITLE_LABEL, itemWidth, H_GROUP_RINGTONE_VALUE_LABEL + pContactsApp->GetFontHeightOffset()), groupsName);
2180         pLabelGroupName->SetName(GROUP_LABEL_VALUE);
2181         pLabelGroupName->AddTouchEventListener(*this);
2182         pLabelGroupName->SetTextConfig(pContactsApp->GetFontSize(), LABEL_TEXT_STYLE_NORMAL);
2183         pLabelGroupName->SetTextHorizontalAlignment(ALIGNMENT_LEFT);
2184                 
2185         pGroupStyle->AddControl(pLabelGroupName);
2186
2187         return pGroupsItem;
2188 }
2189
2190 Tizen::Ui::Controls::TableViewItem*
2191 ContactEditorForm::GetBirthdayField(int itemWidth)
2192 {
2193         DateTime birthdayDate;
2194         EditDate* pBirthday = new (std::nothrow) EditDate();
2195         pBirthday->Construct(Point(W_TITLE_LABEL, 0));
2196         pBirthday->AddDateChangeEventListener(*this);
2197
2198         __pPresentationModel->GetBirthday(birthdayDate);
2199         pBirthday->SetDate(birthdayDate);
2200
2201         DateTime currentDate;
2202         Tizen::System::SystemTime::GetCurrentTime(currentDate);
2203         int min;
2204         int max;
2205         pBirthday->GetYearRange(min, max);
2206         max = currentDate.GetYear();
2207         pBirthday->SetYearRange(max - BIRTHDAY_MIN_YEAR_DIFF, max);
2208
2209         if (birthdayDate.GetYear() < (currentDate.GetYear() - BIRTHDAY_MIN_YEAR_DIFF))
2210         {
2211                 birthdayDate.SetValue(currentDate.GetYear() - BIRTHDAY_MIN_YEAR_DIFF, birthdayDate.GetMonth(), birthdayDate.GetDay());
2212                 __pPresentationModel->SetBirthday(birthdayDate);
2213         }
2214
2215         TableViewItem* pBirthdayItem = new (std::nothrow) TableViewItem();
2216         pBirthdayItem->Construct(Dimension(itemWidth, H_ITEM), TABLE_VIEW_ANNEX_STYLE_NORMAL);
2217         pBirthdayItem->SetBackgroundColor(COLOR_THUMBNAIL_BACKGROUND, TABLE_VIEW_ITEM_DRAWING_STATUS_NORMAL);
2218         pBirthdayItem->SetBackgroundColor(COLOR_THUMBNAIL_BACKGROUND, TABLE_VIEW_ITEM_DRAWING_STATUS_PRESSED);
2219
2220         Label* pLabelTitle = new (std::nothrow) Label();
2221         pLabelTitle->Construct(Rectangle(0, 0, W_TITLE_LABEL, pBirthdayItem->GetHeight()), L"");
2222         pLabelTitle->SetText(ResourceManager::GetString(L"IDS_PB_BODY_BIRTHDAY"));
2223         pLabelTitle->SetTextHorizontalAlignment(ALIGNMENT_LEFT);
2224         pLabelTitle->SetTextColor(COLOR_ITEM_TITLE);
2225         pLabelTitle->SetTextConfig(FONT_SIZE_TITLE_TEXT, LABEL_TEXT_STYLE_BOLD);
2226
2227         pBirthdayItem->AddControl(pLabelTitle);
2228         pBirthdayItem->AddControl(pBirthday);
2229
2230         Button* pClearButton = new (std::nothrow) Button();
2231         pClearButton->Construct(Rectangle(itemWidth - (H_BUTTON * 2) - H_BUTTON/2, (pBirthdayItem->GetHeight() - H_BUTTON) / 2, H_BUTTON, H_BUTTON));
2232         pClearButton->SetActionId(IDA_BUTTON_BIRTHDAY_CLEAR);
2233         pClearButton->AddActionEventListener(*this);
2234
2235         Bitmap* pBitmap = ResourceManager::GetBitmapN(IDB_BUTTON_RESET_NORMAL);
2236         if (pBitmap != null)
2237         {
2238                 pClearButton->SetNormalBitmap(Point(0, 0), *pBitmap);
2239                 delete pBitmap;
2240         }
2241         pBitmap = ResourceManager::GetBitmapN(IDB_BUTTON_RESET_PRESSED);
2242         if (pBitmap != null)
2243         {
2244                 pClearButton->SetPressedBitmap(Point(0, 0), *pBitmap);
2245                 delete pBitmap;
2246         }
2247
2248         pBirthdayItem->AddControl(pClearButton);
2249
2250         Button *pButtonDelete = new (std::nothrow) Button();
2251         pButtonDelete->Construct(Rectangle(itemWidth - H_BUTTON - W_ITEM_GAP, (H_ITEM - H_BUTTON) / 2, H_BUTTON, H_BUTTON));
2252
2253         pBitmap = ResourceManager::GetBitmapN(IDB_BUTTON_MINUS);
2254         if (pBitmap != null)
2255         {
2256                 pButtonDelete->SetNormalBitmap(Point(0, 0), *pBitmap);
2257                 delete pBitmap;
2258         }
2259
2260         pBitmap = ResourceManager::GetBitmapN(IDB_BUTTON_MINUS_PRESSED);
2261         if (pBitmap != null)
2262         {
2263                 pButtonDelete->SetPressedBitmap(Point(0, 0), *pBitmap);
2264                 delete pBitmap;
2265         }
2266
2267         pBitmap = ResourceManager::GetBitmapN(IDB_BUTTON_DELETE_NORMAL);
2268         if (pBitmap != null)
2269         {
2270                 pButtonDelete->SetNormalBackgroundBitmap(*pBitmap);
2271                 delete pBitmap;
2272         }
2273
2274         pBitmap = ResourceManager::GetBitmapN(IDB_BUTTON_DELETE_PRESSED);
2275         if (pBitmap != null)
2276         {
2277                 pButtonDelete->SetPressedBackgroundBitmap(*pBitmap);
2278                 delete pBitmap;
2279         }
2280
2281         pButtonDelete->SetActionId(IDA_BUTTON_BIRTHDAY_DELETE);
2282         pButtonDelete->AddActionEventListener(*this);
2283
2284         pBirthdayItem->AddControl(pButtonDelete);
2285
2286         pBirthdayItem->SetIndividualSelectionEnabled(pBirthday, true);
2287         pBirthdayItem->SetIndividualSelectionEnabled(pClearButton, true);
2288         pBirthdayItem->SetIndividualSelectionEnabled(pButtonDelete, true);
2289
2290         return pBirthdayItem;
2291 }
2292
2293 Tizen::Ui::Controls::TableViewItem*
2294 ContactEditorForm::GetNoteField(int itemWidth)
2295 {
2296         ContactsApp *pContactsApp = static_cast<ContactsApp*>(ContactsApp::GetInstance());
2297
2298         if (__pNoteFieldItem != null)
2299         {
2300                 return __pNoteFieldItem;
2301         }
2302
2303         __pNoteFieldItem = new (std::nothrow) TableViewItem();
2304         __pNoteFieldItem->Construct(Dimension(itemWidth, pContactsApp->GetListItemSingleLineHeight() + Y_EDIT_FIELD_GAP), TABLE_VIEW_ANNEX_STYLE_NORMAL);
2305         __pNoteFieldItem->SetBackgroundColor(COLOR_THUMBNAIL_BACKGROUND, TABLE_VIEW_ITEM_DRAWING_STATUS_NORMAL);
2306         __pNoteFieldItem->SetBackgroundColor(COLOR_THUMBNAIL_BACKGROUND, TABLE_VIEW_ITEM_DRAWING_STATUS_PRESSED);
2307
2308
2309         Label* pNoteTitle = new (std::nothrow) Label();
2310         pNoteTitle->Construct(Rectangle(0, 0, itemWidth, H_LABEL), ResourceManager::GetString(L"IDS_PB_BODY_NOTE"));
2311         pNoteTitle->SetTextHorizontalAlignment(ALIGNMENT_LEFT);
2312         pNoteTitle->SetTextColor(COLOR_ITEM_TITLE);
2313         pNoteTitle->SetTextConfig(FONT_SIZE_TITLE_TEXT, LABEL_TEXT_STYLE_BOLD);
2314         __pNoteFieldItem->AddControl(pNoteTitle);
2315
2316         ExpandableEditArea* pNoteEditArea = new (std::nothrow) ExpandableEditArea();
2317         pNoteEditArea->Construct(Rectangle(Y_EDIT_FIELD_GAP, H_LABEL, itemWidth - H_EDIT_FIELD_GAP, pContactsApp->GetListItemSingleLineHeight() - H_LABEL + Y_EDIT_FIELD_GAP), EXPANDABLE_EDIT_AREA_STYLE_NORMAL, EXPANDABLE_EDIT_AREA_TITLE_STYLE_NONE);
2318         pNoteEditArea->SetTitleText(ResourceManager::GetString(L"IDS_PB_BODY_NOTE"));
2319         pNoteEditArea->SetText(__pPresentationModel->GetValue(DETAIL_PROPERTY_NOTE));
2320         pNoteEditArea->AddExpandableEditAreaEventListener(*this);
2321         pNoteEditArea->AddKeypadEventListener(*this);
2322         pNoteEditArea->AddFocusEventListener(*this);
2323         pNoteEditArea->SetTextSize(pContactsApp->GetFontSize());
2324         pNoteEditArea->AddTextEventListener(*this);
2325
2326         __pNoteFieldItem->AddControl(pNoteEditArea);
2327         __pNoteFieldItem->SetIndividualSelectionEnabled(pNoteEditArea, true);
2328
2329         return __pNoteFieldItem;
2330 }
2331
2332 Tizen::Ui::Controls::TableViewItem*
2333 ContactEditorForm::GetRingtoneField(int itemWidth)
2334 {
2335         ContactsApp *pContactsApp = static_cast<ContactsApp*>(ContactsApp::GetInstance());
2336
2337         TableViewItem* pRingtoneItem = new (std::nothrow) TableViewItem();
2338         pRingtoneItem->Construct(Dimension(itemWidth, H_DOUBLE_LINE_ITEM + pContactsApp->GetFontHeightOffset()), TABLE_VIEW_ANNEX_STYLE_NORMAL);
2339         pRingtoneItem->SetBackgroundColor(COLOR_THUMBNAIL_BACKGROUND);
2340         pRingtoneItem->AddKeyEventListener(*this);
2341
2342         Panel* pGroupStyle = new (std::nothrow) Panel();
2343         pGroupStyle->Construct(Rectangle(0, 0, itemWidth , H_DOUBLE_LINE_ITEM + pContactsApp->GetFontHeightOffset()), GROUP_STYLE_NONE);
2344         pGroupStyle->SetName(GROUP_STYLE_PANEL);
2345         pGroupStyle->SetBackgroundColor(COLOR_THUMBNAIL_BACKGROUND);
2346         pGroupStyle->AddTouchEventListener(*this);
2347         pRingtoneItem->AddControl(pGroupStyle);
2348
2349         Label* pLabelTitle = new (std::nothrow) Label();
2350         pLabelTitle->Construct(Rectangle(0, H_GROUP_RINGTONE_TITLE_GAP, itemWidth, H_GROUP_RINGTONE_TITLE_LABEL), ResourceManager::GetString(L"IDS_PB_BODY_RINGTONE"));
2351         pLabelTitle->SetName(GROUP_LABEL_TITLE);
2352         pLabelTitle->AddTouchEventListener(*this);
2353         pLabelTitle->SetTextConfig(FONT_SIZE_TITLE_TEXT, LABEL_TEXT_STYLE_BOLD);
2354         pLabelTitle->SetTextColor(COLOR_ITEM_TITLE);
2355         pLabelTitle->SetTextHorizontalAlignment(ALIGNMENT_LEFT);
2356
2357         pGroupStyle->AddControl(pLabelTitle);
2358
2359         String ringtoneName = __pPresentationModel->GetValue(DETAIL_PROPERTY_RINGTONE);
2360         String trimmedPath;
2361         int index = 0;
2362
2363         ringtoneName.LastIndexOf(L"/", ringtoneName.GetLength() - 1, index);
2364
2365         if (index != 0)
2366         {
2367                 ringtoneName.SubString(index + 1, trimmedPath);
2368         }
2369
2370         Label* pLabelRingToneName = new (std::nothrow) Label();
2371         pLabelRingToneName->Construct(Rectangle(0, H_GROUP_RINGTONE_TITLE_GAP + H_GROUP_RINGTONE_TITLE_LABEL, itemWidth - H_GROUP_RINGTONE_TITLE_GAP - H_ICON_BUTTON, H_GROUP_RINGTONE_VALUE_LABEL + pContactsApp->GetFontHeightOffset()), trimmedPath);
2372         pLabelRingToneName->SetName(GROUP_LABEL_VALUE);
2373         pLabelRingToneName->AddTouchEventListener(*this);
2374         pLabelRingToneName->SetTextConfig(pContactsApp->GetFontSize(), LABEL_TEXT_STYLE_NORMAL);
2375         pLabelRingToneName->SetTextHorizontalAlignment(ALIGNMENT_LEFT);
2376         pGroupStyle->AddControl(pLabelRingToneName);
2377
2378         Button* pClearButton = new (std::nothrow) Button();
2379         pClearButton->Construct(Rectangle(itemWidth - X_REFRESH_BUTTON_MARGIN, (pRingtoneItem->GetHeight() - H_ICON_BUTTON) / 2, H_ICON_BUTTON, H_ICON_BUTTON));
2380         pClearButton->SetActionId(IDA_BUTTON_RINGTONE_CLEAR);
2381         pClearButton->AddActionEventListener(*this);
2382
2383         Bitmap* pReset = ResourceManager::GetBitmapN(IDB_DETAILS_RESET_NORMAL);
2384         if (pReset != null)
2385         {
2386                 pClearButton->SetNormalBitmap(Point(0, 0), *pReset);
2387                 delete pReset;
2388         }
2389         pReset = ResourceManager::GetBitmapN(IDB_DETAILS_RESET_PRESSED);
2390         if (pReset != null)
2391         {
2392                 pClearButton->SetPressedBitmap(Point(0, 0), *pReset);
2393                 delete pReset;
2394         }
2395
2396         pGroupStyle->AddControl(pClearButton);
2397         pRingtoneItem->SetIndividualSelectionEnabled(pClearButton, true);
2398
2399         return pRingtoneItem;
2400 }
2401
2402 Tizen::Ui::Controls::TableViewItem*
2403 ContactEditorForm::GetMoreInformationField(int itemWidth)
2404 {
2405         TableViewItem* pMoreInformationItem = new (std::nothrow) TableViewItem();
2406         pMoreInformationItem->Construct(Dimension(itemWidth, H_DESCRIPTION_CONTAINER));
2407         pMoreInformationItem->SetBackgroundColor(Color(COLOR_TABLE_VIEW_BG), TABLE_VIEW_ITEM_DRAWING_STATUS_NORMAL);
2408         pMoreInformationItem->SetBackgroundColor(Color(COLOR_TABLE_VIEW_BG), TABLE_VIEW_ITEM_DRAWING_STATUS_PRESSED);
2409
2410         Panel* pPanel = new (std::nothrow) Panel();
2411         pPanel->Construct(Rectangle(X_MORE_INFO_PANEL_GAP, X_MORE_INFO_PANEL_GAP, itemWidth - H_MORE_INFO_PANEL_GAP, H_DESCRIPTION_CONTAINER - H_MORE_INFO_PANEL_GAP));
2412         pPanel->SetBackgroundColor(Color(COLOR_TABLE_VIEW_BG));
2413
2414         pMoreInformationItem->AddControl(pPanel);
2415
2416         Button* pButtonMoreInformation = new (std::nothrow) Button();
2417         pButtonMoreInformation->Construct(Rectangle(X_MORE_INFORMATION_BUTTON, Y_MORE_INFORMATION_BUTTON, itemWidth - (X_MORE_INFORMATION_BUTTON * 2), H_BUTTON));
2418         pButtonMoreInformation->SetText(ResourceManager::GetString(L"IDS_KA_BODY_MORE_INFORMATION"));
2419         pButtonMoreInformation->SetActionId(IDA_BUTTON_MORE_INFO);
2420         pButtonMoreInformation->AddActionEventListener(*this);
2421
2422         pPanel->AddControl(pButtonMoreInformation);
2423
2424         return pMoreInformationItem;
2425 }
2426
2427 Tizen::Ui::Controls::TableViewItem*
2428 ContactEditorForm::GetDefaultPhoneNumberItem(int itemWidth)
2429 {
2430         ContactsApp *pContactsApp = static_cast<ContactsApp*>(ContactsApp::GetInstance());
2431
2432         TableViewItem* pDefaultPhoneNumberItem = new (std::nothrow) TableViewItem();
2433         pDefaultPhoneNumberItem->Construct(Dimension(itemWidth, pContactsApp->GetListItemSingleLineHeight()));
2434         pDefaultPhoneNumberItem->SetBackgroundColor(Color(0), TABLE_VIEW_ITEM_DRAWING_STATUS_PRESSED);
2435
2436         Button* pButtonDefaultNumber = new (std::nothrow) Button();
2437         pButtonDefaultNumber->Construct(Rectangle(X_MORE_INFORMATION_BUTTON, Y_DEFAULT_NUMBER_BUTTON, itemWidth - (X_MORE_INFORMATION_BUTTON * 2), H_BUTTON));
2438         pButtonDefaultNumber->SetText(ResourceManager::GetString(L"IDS_PB_BODY_MARK_AS_DEFAULT_NUMBER"));
2439         pButtonDefaultNumber->SetActionId(IDA_BUTTON_DEFAULT_PHONE_NUMBER);
2440         pButtonDefaultNumber->AddActionEventListener(*this);
2441
2442         pDefaultPhoneNumberItem->AddControl(pButtonDefaultNumber);
2443         pDefaultPhoneNumberItem->SetIndividualSelectionEnabled(pButtonDefaultNumber, true);
2444
2445         return pDefaultPhoneNumberItem;
2446 }
2447
2448 result
2449 ContactEditorForm::DeleteInputField(int groupIndex, int itemIndex, int isUpdating)
2450 {
2451         result r = E_SUCCESS;
2452         ArrayList* pFieldList = null;
2453
2454         switch (groupIndex)
2455         {
2456         case TABLE_VIEW_PHONE_NUMBER_FIELD_INDEX:
2457                 {
2458                         pFieldList = __pPhoneNumberFieldItem;
2459                         __pPresentationModel->SetPhoneNumber(DETAIL_PHONENUMBER_TYPE_NONE, L"", itemIndex); //phoneNumberType doesn't matter
2460                 }
2461                 break;
2462         case TABLE_VIEW_EMAIL_FIELD_INDEX:
2463                 {
2464                         pFieldList = __pEmailFieldItem;
2465                         __pPresentationModel->SetEmail(DETAIL_EMAIL_TYPE_NONE, L"", itemIndex);
2466                 }
2467                 break;
2468         case TABLE_VIEW_ADDRESS_FIELD_INDEX:
2469                 {
2470                         pFieldList = __pAddressFieldItem;
2471                         __pPresentationModel->SetAddress(DETAIL_ADDRESS_TYPE_NONE, L"", itemIndex);
2472                 }
2473                 break;
2474         case TABLE_VIEW_IM_ADDRESS_FIELD_INDEX:
2475                 {
2476                         pFieldList = __pImAddressFieldItem;
2477                         __pPresentationModel->SetImAddress(DETAIL_IM_ADDRESS_TYPE_NONE, L"", itemIndex);
2478                 }
2479                 break;
2480         case TABLE_VIEW_URL_FIELD_INDEX:
2481                 {
2482                         pFieldList = __pUrlFieldItem;
2483                         __pPresentationModel->SetUrl(DETAIL_URL_TYPE_NONE, L"", itemIndex);
2484                 }
2485                 break;
2486         default:
2487                 break;
2488         }
2489
2490         TryReturn(pFieldList != null, E_FAILURE, "[E_FAILURE] Unable to delete the item.")
2491
2492         __pDeletedItemList->Add(pFieldList->GetAt(itemIndex));
2493
2494         r = pFieldList->RemoveAt(itemIndex, false);
2495
2496         if (__previousGroupIndex == groupIndex && __previousItemIndex == itemIndex)
2497         {
2498                 __previousGroupIndex = -1;
2499                 __previousItemIndex  = -1;
2500         }
2501         if (isUpdating == false)
2502         {
2503                 __pTableView->RefreshItem(groupIndex, itemIndex, TABLE_VIEW_REFRESH_TYPE_ITEM_REMOVE);
2504         }
2505
2506         Rectangle clientBounds = GetClientAreaBounds();
2507         __pTableView->SetSize(clientBounds.width, clientBounds.height);
2508
2509         for (int i = itemIndex; i < pFieldList->GetCount(); i++)
2510         {
2511                 TableViewItem* pItem = static_cast<TableViewItem *>(pFieldList->GetAt(i));
2512                 if (pItem == null)
2513                 {
2514                         return E_FAILURE;
2515                 }
2516
2517                 int parsedIndex;
2518                 EditField* pInputField = static_cast<EditField*>(pItem->GetControl(0));
2519                 if (pInputField == null)
2520                 {
2521                         return E_FAILURE;
2522                 }
2523
2524                 result r = Integer::Decode(pInputField->GetName(), parsedIndex);
2525                 if (r == E_NUM_FORMAT)
2526                 {
2527                         return E_FAILURE;
2528                 }
2529                 pInputField->SetName(Integer::ToString(parsedIndex - 1));
2530
2531                 Button* pTypeButton = static_cast<Button*>(pItem->GetControl(1));
2532                 if (pTypeButton == null)
2533                 {
2534                         return E_FAILURE;
2535                 }
2536
2537                 r = Integer::Decode(pTypeButton->GetName(), parsedIndex);
2538                 if (r == E_NUM_FORMAT)
2539                 {
2540                         return E_FAILURE;
2541                 }
2542                 pTypeButton->SetName(Integer::ToString(parsedIndex - 1));
2543
2544                 Button* pDeleteButton = static_cast<Button *>(pItem->GetControl(2));
2545                 if (pDeleteButton == null)
2546                 {
2547                         return E_FAILURE;
2548                 }
2549                 pDeleteButton->SetActionId(pDeleteButton->GetActionId() - 1);
2550         }
2551
2552         SaveContactData(false);
2553         SetSaveButtonEnabled(IsSaveContactValid());
2554         
2555         if (groupIndex == TABLE_VIEW_PHONE_NUMBER_FIELD_INDEX)
2556         {
2557                 if (itemIndex == __pPresentationModel->GetDefaultNumberIndex())
2558                 {
2559                         SetAsDefaultPhoneNumber(0);
2560                 }
2561                 else if (itemIndex < __pPresentationModel->GetDefaultNumberIndex())
2562                 {
2563                         SetAsDefaultPhoneNumber(__pPresentationModel->GetDefaultNumberIndex() - 1);
2564                 }
2565         }
2566
2567         if (__isDefaultPhoneNumberButtonEnabled == true && __pPresentationModel->GetMultiValuesCount(DETAIL_PROPERTY_PHONE_NUMBER) < 2)
2568         {
2569                 if (isUpdating == false)
2570                 {
2571                         __pTableView->RefreshItem(TABLE_VIEW_PHONE_NUMBER_FIELD_INDEX, __pTableView->GetItemCountAt(TABLE_VIEW_PHONE_NUMBER_FIELD_INDEX) - 1, TABLE_VIEW_REFRESH_TYPE_ITEM_REMOVE);
2572                 }
2573                 __isDefaultPhoneNumberButtonEnabled = false;
2574         }
2575
2576         return r;
2577 }
2578
2579 void
2580 ContactEditorForm::SetThumbnailControls(Tizen::Ui::Controls::TableViewItem& item, bool isUpdated)
2581 {
2582         Label* pLabelThumbnail = null;
2583         Button* pButtonAdd = null;
2584         Button* pButtonDelete = null;
2585
2586         if (isUpdated == false)
2587         {
2588                 int itemWidth = GetBounds().width;
2589
2590                 pLabelThumbnail = new (std::nothrow) Label();
2591                 pLabelThumbnail->Construct(Rectangle((itemWidth - W_THUMBNAIL) / 2, H_THUMBNAIL_DELETE_BUTTON_GAP + Y_EDIT_FIELD_GAP, W_THUMBNAIL, W_THUMBNAIL), L"");
2592
2593                 item.AddControl(pLabelThumbnail);
2594
2595                 Bitmap* pBitmapItem = null;
2596                 Bitmap* pBitmapItemPressed = null;
2597
2598                 pButtonAdd = new (std::nothrow) Button();
2599                 pButtonAdd->Construct(Rectangle(pLabelThumbnail->GetX() + ((pLabelThumbnail->GetWidth() - H_BUTTON) / 2), pLabelThumbnail->GetY() + ((pLabelThumbnail->GetHeight() - H_BUTTON) / 2), H_BUTTON, H_BUTTON));
2600                 pButtonAdd->SetActionId(IDA_BUTTON_THUMBNAIL_ADD);
2601                 pButtonAdd->AddActionEventListener(*this);
2602
2603                 pBitmapItem = ResourceManager::GetBitmapN(IDB_BUTTON_ADD);
2604                 pBitmapItemPressed = ResourceManager::GetBitmapN(IDB_BUTTON_ADD_PRESSED);
2605
2606                 if (pBitmapItem != null)
2607                 {
2608                         pButtonAdd->SetNormalBackgroundBitmap(*pBitmapItem);
2609                         delete pBitmapItem;
2610                 }
2611                 if (pBitmapItemPressed != null)
2612                 {
2613                         pButtonAdd->SetPressedBackgroundBitmap(*pBitmapItemPressed);
2614                         delete pBitmapItemPressed;
2615                 }
2616                 item.AddControl(pButtonAdd);
2617                 item.SetIndividualSelectionEnabled(pButtonAdd, true);
2618
2619                 pButtonDelete = new (std::nothrow) Button();
2620                 pButtonDelete->Construct(Rectangle(pLabelThumbnail->GetX() - H_THUMBNAIL_DELETE_BUTTON_GAP, pLabelThumbnail->GetY() - H_THUMBNAIL_DELETE_BUTTON_GAP + Y_EDIT_FIELD_GAP, H_BUTTON, H_BUTTON));
2621                 pButtonDelete->SetActionId(IDA_BUTTON_THUMBNAIL_DELETE);
2622                 pButtonDelete->AddActionEventListener(*this);
2623
2624                 pBitmapItem = ResourceManager::GetBitmapN(IDB_BUTTON_MINUS);
2625                 pBitmapItemPressed = ResourceManager::GetBitmapN(IDB_BUTTON_MINUS_PRESSED);
2626
2627                 if (pBitmapItem != null)
2628                 {
2629                         pButtonDelete->SetNormalBitmap(Point(0, 0), *pBitmapItem);
2630                         delete pBitmapItem;
2631                 }
2632                 if (pBitmapItemPressed != null)
2633                 {
2634                         pButtonDelete->SetPressedBitmap(Point(0, 0), *pBitmapItemPressed);
2635                         delete pBitmapItemPressed;
2636                 }
2637
2638                 pBitmapItem = ResourceManager::GetBitmapN(IDB_BUTTON_DELETE_NORMAL);
2639                 pBitmapItemPressed = ResourceManager::GetBitmapN(IDB_BUTTON_DELETE_PRESSED);
2640
2641                 if (pBitmapItem != null)
2642                 {
2643                         pButtonDelete->SetNormalBackgroundBitmap(*pBitmapItem);
2644                         delete pBitmapItem;
2645                 }
2646                 if (pBitmapItemPressed != null)
2647                 {
2648                         pButtonDelete->SetPressedBackgroundBitmap(*pBitmapItemPressed);
2649                         delete pBitmapItemPressed;
2650                 }
2651                 item.AddControl(pButtonDelete);
2652                 item.SetIndividualSelectionEnabled(pButtonDelete, true);
2653
2654                 Button* pButtonCamera = new (std::nothrow) Button();
2655                 pButtonCamera->Construct(Rectangle(pLabelThumbnail->GetX() + pLabelThumbnail->GetWidth(), pLabelThumbnail->GetY() + pLabelThumbnail->GetHeight() - H_BUTTON, H_BUTTON, H_BUTTON));
2656                 pButtonCamera->SetActionId(IDA_BUTTON_CAMERA);
2657                 pButtonCamera->AddActionEventListener(*this);
2658
2659                 pBitmapItem = ResourceManager::GetBitmapN(IDB_BUTTON_CAMERA);
2660                 pBitmapItemPressed = ResourceManager::GetBitmapN(IDB_BUTTON_CAMERA_PRESSED);
2661                 if (pBitmapItem != null)
2662                 {
2663                         pButtonCamera->SetNormalBackgroundBitmap(*pBitmapItem);
2664                         delete pBitmapItem;
2665                 }
2666                 if (pBitmapItemPressed != null)
2667                 {
2668                         pButtonCamera->SetPressedBackgroundBitmap(*pBitmapItemPressed);
2669                         delete pBitmapItemPressed;
2670                 }
2671
2672                 item.AddControl(pButtonCamera);
2673                 item.SetIndividualSelectionEnabled(pButtonCamera, true);
2674         }
2675         else
2676         {
2677                 pLabelThumbnail = static_cast<Label*>(item.GetControl(0));
2678                 TryReturnVoid(pLabelThumbnail != null, "[E_FAILURE] Unable to get a thumbnail control.");
2679
2680                 pButtonAdd = static_cast<Button*>(item.GetControl(1));
2681                 TryReturnVoid(pButtonAdd != null, "[E_FAILURE] Unable to get a button.");
2682
2683                 pButtonDelete = static_cast<Button*>(item.GetControl(2));
2684                 TryReturnVoid(pButtonDelete != null, "[E_FAILURE] Unable to get a button.");
2685         }
2686
2687         Bitmap* pThumbnail = null;
2688         String thumbnailPath = __pPresentationModel->GetValue(DETAIL_PROPERTY_THUMBNAIL);
2689
2690         if (thumbnailPath.IsEmpty() == false)
2691         {
2692                 ImageBuffer thumbnailImageBuffer;
2693                 result r = thumbnailImageBuffer.Construct(thumbnailPath);
2694                 if (r == E_SUCCESS)
2695                 {
2696                         pThumbnail = thumbnailImageBuffer.GetBitmapN(BITMAP_PIXEL_FORMAT_ARGB8888, BUFFER_SCALING_NONE);
2697                 }
2698                 if (pThumbnail != null)
2699                 {
2700                         pThumbnail->SetScalingQuality(BITMAP_SCALING_QUALITY_HIGH);
2701                         pThumbnail->Scale(Dimension(W_THUMBNAIL, W_THUMBNAIL));
2702                         pLabelThumbnail->SetBackgroundBitmap(*pThumbnail);
2703                 }
2704                 pButtonAdd->SetShowState(false);
2705                 pButtonAdd->SetEnabled(false);
2706                 pButtonDelete->SetShowState(true);
2707         }
2708         else
2709         {
2710                 pThumbnail = ResourceManager::GetBitmapN(IDB_THUMBNAIL_BACKGROUND);
2711                 if (pThumbnail != null)
2712                 {
2713                         pLabelThumbnail->SetBackgroundBitmap(*pThumbnail);
2714                         pButtonAdd->SetShowState(true);
2715                         pButtonAdd->SetEnabled(true);
2716                         pButtonDelete->SetShowState(false);
2717                 }
2718         }
2719
2720         delete pThumbnail;
2721 }
2722
2723 void
2724 ContactEditorForm::AddHorizontalDivider(Tizen::Ui::Controls::TableViewItem* pItem, int positionY, int width)
2725 {
2726         Label* pDivider = new (std::nothrow) Label();
2727         pDivider->Construct(Rectangle(0, positionY, width, H_DIVIDER), L"");
2728         pDivider->SetBackgroundColor(Color(COLOR_DIVIDER));
2729         pDivider->SetEnabled(false);
2730
2731         pItem->AddControl(pDivider);
2732 }
2733
2734 void
2735 ContactEditorForm::AddVerticalDivider(Tizen::Ui::Controls::TableViewItem* pItem, int positionX, int positionY)
2736 {
2737         ContactsApp *pContactsApp = static_cast<ContactsApp*>(ContactsApp::GetInstance());
2738
2739         Label* pDivider = new (std::nothrow) Label();
2740         pDivider->Construct(Rectangle(positionX, positionY, W_DIVIDER, pContactsApp->GetListItemSingleLineHeight()), L"");
2741         pDivider->SetBackgroundColor(Color(COLOR_DIVIDER));
2742         pDivider->SetEnabled(false);
2743
2744         pItem->AddControl(pDivider);
2745 }
2746
2747 result
2748 ContactEditorForm::SetAsDefaultPhoneNumber(int index, bool scrollToItem)
2749 {
2750         result r = E_SUCCESS;
2751         TableViewItem* pItem = null;
2752         EditField* pEditField = null;
2753
2754         pItem = static_cast<TableViewItem *>(__pPhoneNumberFieldItem->GetAt(index));
2755         if (pItem == null)
2756         {
2757                 r = E_FAILURE;
2758                 goto CATCH;
2759         }
2760
2761         pEditField = static_cast<EditField *>(pItem->GetControl(0));
2762         if (pEditField == null)
2763         {
2764                 r = E_FAILURE;
2765                 goto CATCH;
2766         }
2767
2768         __pPresentationModel->SetValue(DETAIL_PROPERTY_DEFAULT_PHONE_NUMBER, L"", index);
2769
2770         if (pEditField->IsVisible() == false && scrollToItem == true)
2771         {
2772                 __pTableView->ScrollToItem(TABLE_VIEW_PHONE_NUMBER_FIELD_INDEX, index);
2773         }
2774         pEditField->Invalidate(true);
2775
2776 CATCH:
2777         return r;
2778 }
2779
2780 result
2781 ContactEditorForm::ChangeNameFieldStatus(void)
2782 {
2783         result r = E_SUCCESS;
2784
2785         r = SaveNameFields();
2786
2787         __isExpandable = (__isExpandable == true) ? false : true;
2788
2789         return r;
2790 }
2791
2792 result
2793 ContactEditorForm::SaveContactData(bool isSaved)
2794 {
2795         result r = E_SUCCESS;
2796
2797         if (isSaved == true)
2798         {
2799                 if (CommonUtil::isMemoryAvailable() == false)
2800                 {
2801                         CommonUtil::showMemoryFullMessageBox();
2802                         return E_FAILURE;
2803                 }
2804         }
2805
2806         r = SaveNameFields();
2807
2808         for (int i = 0; i < __pPhoneNumberFieldItem->GetCount(); i++)
2809         {
2810                 r = E_SUCCESS;
2811                 TableViewItem* pItem = static_cast<TableViewItem *>(__pPhoneNumberFieldItem->GetAt(i));
2812                 if (pItem == null)
2813                 {
2814                         r = E_FAILURE;
2815                         break;
2816                 }
2817
2818                 EditField* pEditField = static_cast<EditField *>(pItem->GetControl(0));
2819                 if (pEditField == null)
2820                 {
2821                         r = E_FAILURE;
2822                         break;
2823                 }
2824
2825                 String phoneNumberString(pEditField->GetText());
2826                 String phoneNumberTypeString(pItem->GetName());
2827                 int phoneNumberType;
2828                 phoneNumberString.Trim();
2829                 wchar_t ch;
2830
2831                 for (int i = 0; i < phoneNumberString.GetLength(); i++)
2832                 {
2833                         phoneNumberString.GetCharAt(i, ch);
2834
2835                         if(ch == '+' && i == 0)
2836                         {
2837                                 continue;
2838                         }
2839                         if((ch == ',' || ch == ';' || ch == 'p') && i == 0)
2840                         {
2841                                 r = E_FAILURE;
2842                                 break;
2843                         }
2844                         else if ((ch < '0' || ch > '9') && (ch != '*') && (ch != '#') && (ch != ',') && (ch != ';') && (ch != 'p'))
2845                         {
2846                                 r = E_FAILURE;
2847                                 break;
2848                         }
2849                         else
2850                         {
2851                                 r = E_SUCCESS;
2852                         }
2853                 }
2854
2855                 if (isSaved == true && phoneNumberString.GetLength() > 0 && r != E_SUCCESS)
2856                 {
2857                         int modalResult;
2858                         MessageBox invalidNumberMessage;
2859                         invalidNumberMessage.Construct(L"", ResourceManager::GetString(L"IDS_PB_BODY_INVALID_NUMBER"), MSGBOX_STYLE_OK, MESSAGE_BOX_TIMEOUT_MS);
2860                         invalidNumberMessage.ShowAndWait(modalResult);
2861
2862                         return E_FAILURE;
2863                 }
2864
2865                 Integer::Parse(phoneNumberTypeString, phoneNumberType);
2866
2867                 __pPresentationModel->SetPhoneNumber((DetailPhoneNumberType)phoneNumberType, phoneNumberString, i);
2868         }
2869
2870         for (int i = 0; i < __pEmailFieldItem->GetCount(); i++)
2871         {
2872                 TableViewItem* pItem = static_cast<TableViewItem *>(__pEmailFieldItem->GetAt(i));
2873                 if (pItem == null)
2874                 {
2875                         r = E_FAILURE;
2876                         break;
2877                 }
2878
2879                 EditField* pEditField = static_cast<EditField *>(pItem->GetControl(0));
2880                 if (pEditField == null)
2881                 {
2882                         r = E_FAILURE;
2883                         break;
2884                 }
2885
2886                 String emailString(pEditField->GetText());
2887                 String remainingString;
2888                 String emailTypeString(pItem->GetName());
2889                 int emailType;
2890
2891                 emailString.Trim();
2892                 Integer::Parse(emailTypeString, emailType);
2893
2894                 r = __pPresentationModel->SetEmail((DetailEmailType)emailType, emailString, i);
2895
2896                 if (isSaved == true && r == E_SUCCESS)
2897                 {
2898                         if(emailString.GetLength() > 0)
2899                         {
2900                                 bool isValidEmail = ValidateEmailAddress(emailString);
2901                                 if (isValidEmail != true)
2902                                 {
2903                                         int modalResult;
2904                                         MessageBox invalidEmailMessage;
2905                                         invalidEmailMessage.Construct(L"", ResourceManager::GetString(L"IDS_PB_POP_INVALID_EMAIL_ADDRESS"), MSGBOX_STYLE_OK, MESSAGE_BOX_TIMEOUT_MS);
2906                                         invalidEmailMessage.ShowAndWait(modalResult);
2907                                         pEditField->ShowKeypad();
2908
2909                                         return E_FAILURE;
2910                                 }
2911                         }
2912                 }
2913         }
2914
2915         for (int i = 0; i < __pAddressFieldItem->GetCount(); i++)
2916         {
2917                 TableViewItem* pItem = static_cast<TableViewItem *>(__pAddressFieldItem->GetAt(i));
2918                 if (pItem == null)
2919                 {
2920                         r = E_FAILURE;
2921                         break;
2922                 }
2923
2924                 EditField* pEditField = static_cast<EditField *>(pItem->GetControl(0));
2925                 if (pEditField == null)
2926                 {
2927                         r = E_FAILURE;
2928                         break;
2929                 }
2930
2931                 String addressString(pEditField->GetText());
2932                 String addressTypeString(pItem->GetName());
2933                 int addressType;
2934
2935                 addressString.Trim();
2936                 Integer::Parse(addressTypeString, addressType);
2937
2938                 __pPresentationModel->SetAddress((DetailAddressType)addressType, addressString, i);
2939         }
2940
2941         for (int i = 0; i < __pImAddressFieldItem->GetCount(); i++)
2942         {
2943                 TableViewItem* pItem = static_cast<TableViewItem *>(__pImAddressFieldItem->GetAt(i));
2944                 if (pItem == null)
2945                 {
2946                         r = E_FAILURE;
2947                         break;
2948                 }
2949
2950                 EditField* pEditField = static_cast<EditField *>(pItem->GetControl(0));
2951                 if (pEditField == null)
2952                 {
2953                         r = E_FAILURE;
2954                         break;
2955                 }
2956
2957                 String addressString(pEditField->GetText());
2958                 String addressTypeString(pItem->GetName());
2959                 int addressType;
2960
2961                 addressString.Trim();
2962                 Integer::Parse(addressTypeString, addressType);
2963
2964                 __pPresentationModel->SetImAddress((DetailImAddressType)addressType, addressString, i);
2965         }
2966
2967         for (int i = 0; i < __pUrlFieldItem->GetCount(); i++)
2968         {
2969                 TableViewItem* pItem = static_cast<TableViewItem *>(__pUrlFieldItem->GetAt(i));
2970                 if (pItem == null)
2971                 {
2972                         r = E_FAILURE;
2973                         break;
2974                 }
2975
2976                 EditField* pEditField = static_cast<EditField *>(pItem->GetControl(0));
2977                 if (pEditField == null)
2978                 {
2979                         r = E_FAILURE;
2980                         break;
2981                 }
2982
2983                 String urlString(pEditField->GetText());
2984                 String urlTypeString(pItem->GetName());
2985                 int urlType;
2986
2987                 urlString.Trim();
2988                 Integer::Parse(urlTypeString, urlType);
2989
2990                 __pPresentationModel->SetUrl((DetailUrlType)urlType, urlString, i);
2991         }
2992
2993         if (__pNoteFieldItem != null)
2994         {
2995                 String noteString;
2996                 ExpandableEditArea* pNoteEditArea = static_cast<ExpandableEditArea *>(__pNoteFieldItem->GetControl(1));
2997                 if (pNoteEditArea != null)
2998                 {
2999                         noteString.Append(pNoteEditArea->GetText());
3000                 }
3001
3002                 __pPresentationModel->SetValue(DETAIL_PROPERTY_NOTE, noteString);
3003         }
3004
3005         if (isSaved == true)
3006         {
3007                 r = __pPresentationModel->AddAddressBook();
3008         }
3009         return r;
3010 }
3011
3012 result
3013 ContactEditorForm::SaveNameFields(void)
3014 {
3015         result r = E_SUCCESS;
3016
3017         if (__pNameFieldItem == null)
3018         {
3019                 return E_FAILURE;
3020         }
3021
3022         if (__isExpandable == true)
3023         {
3024                 EditField* pFirstName = static_cast<EditField *>(__pNameFieldItem->GetControl(ResourceManager::GetString(L"IDS_PB_BODY_FIRST_NAME"), false));
3025                 if (pFirstName == null)
3026                 {
3027                         return E_FAILURE;
3028                 }
3029                 __pPresentationModel->SetValue(DETAIL_PROPERTY_FIRST_NAME, pFirstName->GetText());
3030
3031                 EditField* pLastName = static_cast<EditField *>(__pNameFieldItem->GetControl(ResourceManager::GetString(L"IDS_PB_BODY_LAST_NAME"), false));
3032                 if (pLastName == null)
3033                 {
3034                         return E_FAILURE;
3035                 }
3036
3037                 __pPresentationModel->SetValue(DETAIL_PROPERTY_LAST_NAME, pLastName->GetText());
3038
3039                 EditField* pMiddleName = static_cast<EditField *>(__pNameFieldItem->GetControl(ResourceManager::GetString(L"IDS_PB_BODY_MIDDLE_NAME"), false));
3040                 if (pMiddleName == null)
3041                 {
3042                         return E_FAILURE;
3043                 }
3044                 __pPresentationModel->SetValue(DETAIL_PROPERTY_MIDDLE_NAME, pMiddleName->GetText());
3045
3046                 EditField* pSuffix = static_cast<EditField *>(__pNameFieldItem->GetControl(ResourceManager::GetString(L"IDS_PB_BODY_SUFFIX"), false));
3047                 if (pSuffix == null)
3048                 {
3049                         return E_FAILURE;
3050                 }
3051                 __pPresentationModel->SetValue(DETAIL_PROPERTY_NAME_SUFFIX, pSuffix->GetText());
3052
3053                 EditField* pNickName = static_cast<EditField *>(__pNameFieldItem->GetControl(ResourceManager::GetString(L"IDS_PB_BODY_NICKNAME"), false));
3054                 if (pNickName == null)
3055                 {
3056                         return E_FAILURE;
3057                 }
3058                 __pPresentationModel->SetValue(DETAIL_PROPERTY_NICK_NAME, pNickName->GetText());
3059
3060                 EditField* pCompanyName = static_cast<EditField *>(__pNameFieldItem->GetControl(ResourceManager::GetString(L"IDS_PB_BODY_COMPANY"), false));
3061                 if (pCompanyName == null)
3062                 {
3063                         return E_FAILURE;
3064                 }
3065                 __pPresentationModel->SetValue(DETAIL_PROPERTY_COMPANY, pCompanyName->GetText());
3066
3067                 if (__isJobTitleEnabled == true)
3068                 {
3069                         EditField* pJobTitle = static_cast<EditField *>(__pNameFieldItem->GetControl(ResourceManager::GetString(L"IDS_PB_BODY_JOB_TITLE"), false));
3070                         if (pJobTitle == null)
3071                         {
3072                                 return E_FAILURE;
3073                         }
3074                         __pPresentationModel->SetValue(DETAIL_PROPERTY_JOB_TITLE, pJobTitle->GetText());
3075                 }
3076
3077                 if (__isDepartmentEnabled == true)
3078                 {
3079                         EditField* pDepartment = static_cast<EditField *>(__pNameFieldItem->GetControl(ResourceManager::GetString(L"IDS_PB_BODY_DEPARTMENT"), false));
3080                         if (pDepartment == null)
3081                         {
3082                                 return E_FAILURE;
3083                         }
3084                         __pPresentationModel->SetValue(DETAIL_PROPERTY_DEPARTMENT, pDepartment->GetText());
3085                 }
3086         }
3087         else
3088         {
3089                 EditField* pName = static_cast<EditField *>(__pNameFieldItem->GetControl(Integer::ToString(IDA_INPUT_FIELD_DISPLAY_NAME), false));
3090                 if (pName == null)
3091                 {
3092                         return E_FAILURE;
3093                 }
3094
3095                 int delimeterIndex = -1;
3096                 int delimcommaIndex = -1;
3097
3098                 String displayName(pName->GetText());
3099                 if (displayName != __fullName)
3100                 {
3101                 String firstName;
3102                 String lastName;
3103                 String middleName;
3104                 String suffix;
3105
3106                 displayName.Trim();
3107                 if (!displayName.IsEmpty())
3108                 {
3109                         displayName.IndexOf(DELIMITER_COMMA, 0, delimcommaIndex);
3110                         if (delimcommaIndex >= 0)
3111                         {
3112                                 displayName.SubString(delimcommaIndex + 1, displayName.GetLength() - (delimcommaIndex + 1), suffix);
3113                                 displayName.SetLength(delimcommaIndex);
3114                                 displayName.Trim();
3115                         }
3116
3117                         if (!displayName.IsEmpty())
3118                         {
3119                                 delimeterIndex = -1;
3120                                 displayName.IndexOf(CHARACTER_SPACE, 0, delimeterIndex);
3121                                 if (delimeterIndex < 0)
3122                                 {
3123                                         firstName.Append(displayName);
3124                                 }
3125                                 else
3126                                 {
3127                                         displayName.SubString(0, delimeterIndex++, firstName);
3128                                         displayName.SubString(delimeterIndex, displayName.GetLength() - delimeterIndex, displayName);
3129                 
3130                                         delimeterIndex = -1;
3131                                         displayName.Trim();
3132                                         
3133                                         if (!displayName.IsEmpty())
3134                                         {
3135                                                 displayName.IndexOf(CHARACTER_SPACE, 0, delimeterIndex);
3136                                                 if (delimeterIndex < 0)
3137                                                 {
3138                                                         lastName.Append(displayName);
3139                                                 }
3140                                                 else
3141                                                 {
3142                                                         displayName.SubString(0, delimeterIndex, middleName);
3143                                                         displayName.SubString(delimeterIndex + 1, displayName.GetLength() - (delimeterIndex + 1), lastName);
3144                                                 }
3145                                         }
3146                                 }
3147                         }
3148                 }
3149                 __pPresentationModel->SetValue(DETAIL_PROPERTY_FIRST_NAME, firstName);
3150                 __pPresentationModel->SetValue(DETAIL_PROPERTY_MIDDLE_NAME, middleName);
3151                 __pPresentationModel->SetValue(DETAIL_PROPERTY_LAST_NAME, lastName);
3152                 __pPresentationModel->SetValue(DETAIL_PROPERTY_NAME_SUFFIX, suffix);
3153                 }
3154         }
3155
3156         return r;
3157 }
3158
3159 bool
3160 ContactEditorForm::IsSaveContactValid(void)
3161 {
3162         if (__pPresentationModel->GetValue(DETAIL_PROPERTY_FIRST_NAME).IsEmpty() == false)
3163         {
3164                 return true;
3165         }
3166
3167         if (__pPresentationModel->GetValue(DETAIL_PROPERTY_LAST_NAME).IsEmpty() == false)
3168         {
3169                 return true;
3170         }
3171
3172         for (int i = 0; i < __pPresentationModel->GetMultiValuesCount(DETAIL_PROPERTY_PHONE_NUMBER); i++)
3173         {
3174                 if (__pPresentationModel->GetValue(DETAIL_PROPERTY_PHONE_NUMBER, i).IsEmpty() == false)
3175                 {
3176                         return true;
3177                 }
3178         }
3179
3180         for (int i = 0; i < __pPresentationModel->GetMultiValuesCount(DETAIL_PROPERTY_EMAIL); i++)
3181         {
3182                 if (__pPresentationModel->GetValue(DETAIL_PROPERTY_EMAIL, i).IsEmpty() == false)
3183                 {
3184                         return true;
3185                 }
3186         }
3187
3188         return false;
3189 }
3190
3191 void
3192 ContactEditorForm::SetSaveButtonEnabled(bool enable)
3193 {
3194         Footer* pFooter = GetFooter();
3195
3196         if (enable)
3197         {
3198                 pFooter->SetItemEnabled(0, true);
3199         }
3200         else
3201         {
3202                 pFooter->SetItemEnabled(0, false);
3203         }
3204
3205         pFooter->Invalidate(true);
3206 }
3207
3208 bool
3209 ContactEditorForm::IsMoreInformationButtonVisible(void)
3210 {
3211         if (__isJobTitleEnabled == false)
3212         {
3213                 return true;
3214         }
3215
3216         if (__isDepartmentEnabled == false)
3217         {
3218                 return true;
3219         }
3220
3221         if (__pImAddressFieldItem->GetCount() == 0)
3222         {
3223                 return true;
3224         }
3225
3226         if (__pUrlFieldItem->GetCount() == 0)
3227         {
3228                 return true;
3229         }
3230
3231         DateTime birthday;
3232         if (__pPresentationModel->GetBirthday(birthday) != E_SUCCESS)
3233         {
3234                 return true;
3235         }
3236
3237         if (__pNoteFieldItem == null)
3238         {
3239                 return true;
3240         }
3241
3242         return false;
3243 }
3244
3245 void
3246 ContactEditorForm::OnTextValueChanged(const Tizen::Ui::Control& source)
3247 {
3248         TableViewItem* pTableViewItem = static_cast<TableViewItem *>(source.GetParent());
3249
3250         __isContactModified = true;
3251
3252         if (pTableViewItem == null)
3253         {
3254                 return;
3255         }
3256
3257         SaveContactData(false);
3258         SetSaveButtonEnabled(IsSaveContactValid());
3259
3260         if (__pNameFieldItem == pTableViewItem)
3261         {
3262                 return;
3263         }
3264
3265         EditField* pEditField = const_cast<EditField *>(static_cast<const EditField *>(&source));
3266         if (pEditField == null)
3267         {
3268                 return;
3269         }
3270
3271         Control* pDeleteButton = pTableViewItem->GetControl(2);
3272         if (pDeleteButton == null)
3273         {
3274                 return;
3275         }
3276
3277         int index = 0;
3278         int groupIndex = 0;
3279         int inputFlag = 0;
3280         int itemCount = 0;
3281
3282         Integer::Decode(pEditField->GetName(), index);
3283         groupIndex = (index & TABLE_VIEW_GROUP_INDEX_MASK) >> TABLE_VIEW_GROUP_INDEX_SHIFT;
3284         inputFlag = (index & TABLE_VIEW_INPUT_FIELD_INDEX_MASK) >> TABLE_VIEW_INPUT_FIELD_INDEX_SHIFT;
3285         int itemIndex = (index & TABLE_VIEW_ITEM_INDEX_MASK);
3286         itemCount = __pTableView->GetItemCountAt(groupIndex);
3287
3288         String trimmedString = pEditField->GetText();
3289         trimmedString.Trim();
3290
3291         if (trimmedString.IsEmpty())
3292         {
3293                 pDeleteButton->SetShowState(false);
3294                 __previousItemIndex = itemIndex;  //if the entered text is empty store the index of the field for deletion
3295                 __previousGroupIndex = groupIndex;
3296         }
3297         else if (pDeleteButton->GetShowState() == false)
3298         {
3299                 __previousItemIndex = -1;
3300                 __previousGroupIndex = -1;
3301                 pDeleteButton->SetShowState(true);
3302                 if (inputFlag <= 0)
3303                 {
3304                         index |= (1 << TABLE_VIEW_INPUT_FIELD_INDEX_SHIFT);
3305                         pEditField->SetName(Integer::ToString(index));
3306
3307                         if (groupIndex == TABLE_VIEW_PHONE_NUMBER_FIELD_INDEX)
3308                         {
3309                                 if (__isDefaultPhoneNumberButtonEnabled == false && __pPresentationModel->GetMultiValuesCount(DETAIL_PROPERTY_PHONE_NUMBER) > 1)
3310                                 {
3311                                         __isDefaultPhoneNumberButtonEnabled = true;
3312                                         __pTableView->RefreshItem(groupIndex, __pTableView->GetItemCountAt(groupIndex), TABLE_VIEW_REFRESH_TYPE_ITEM_ADD);
3313                                 }
3314                                 else if (itemCount > 1)
3315                                 {
3316                                         itemCount--;
3317                                 }
3318                         }
3319
3320                         ArrayList* pFieldList = null;
3321                         switch (groupIndex)
3322                         {
3323                         case TABLE_VIEW_PHONE_NUMBER_FIELD_INDEX:
3324                                 {
3325                                         pFieldList = __pPhoneNumberFieldItem;
3326                                 }
3327                                 break;
3328                         case TABLE_VIEW_EMAIL_FIELD_INDEX:
3329                                 {
3330                                         pFieldList = __pEmailFieldItem;
3331                                 }
3332                                 break;
3333                         case TABLE_VIEW_ADDRESS_FIELD_INDEX:
3334                                 {
3335                                         pFieldList = __pAddressFieldItem;
3336                                 }
3337                                 break;
3338                         case TABLE_VIEW_IM_ADDRESS_FIELD_INDEX:
3339                                 {
3340                                         pFieldList = __pImAddressFieldItem;
3341                                 }
3342                                 break;
3343                         case TABLE_VIEW_URL_FIELD_INDEX:
3344                                 {
3345                                         pFieldList = __pUrlFieldItem;
3346                                 }
3347                                 break;
3348                         default:
3349                                 break;
3350                         }
3351
3352                         if (pFieldList != null)
3353                         {
3354                                 TableViewItem* pItem = static_cast<TableViewItem*>(pFieldList->GetAt(pFieldList->GetCount() - 1));
3355                                 if (pItem != null)
3356                                 {
3357                                         EditField* pInputField = static_cast<EditField*>(pItem->GetControl(0));
3358
3359                                         if (pInputField != null && pInputField->GetTextLength() != 0)
3360                                         {
3361                                                 __pTableView->RefreshItem(groupIndex, itemCount, TABLE_VIEW_REFRESH_TYPE_ITEM_ADD);
3362                                         }
3363                                 }
3364                         }
3365                 }
3366         }
3367         else
3368         {
3369                 __previousItemIndex = -1;
3370                 __previousGroupIndex = -1;
3371         }
3372         if(__pPresentationModel->GetMultiValuesCount(DETAIL_PROPERTY_PHONE_NUMBER) <= 1 && __isDefaultPhoneNumberButtonEnabled == true)
3373         {
3374                 __isDefaultPhoneNumberButtonEnabled = false;
3375                 __pTableView->RefreshItem(groupIndex, __pTableView->GetItemCountAt(groupIndex) - 1, TABLE_VIEW_REFRESH_TYPE_ITEM_REMOVE);
3376         }
3377         else if(__pPresentationModel->GetMultiValuesCount(DETAIL_PROPERTY_PHONE_NUMBER) > 1 && __isDefaultPhoneNumberButtonEnabled == false)
3378         {
3379                 __isDefaultPhoneNumberButtonEnabled = true;
3380                 __pTableView->RefreshItem(groupIndex, __pTableView->GetItemCountAt(groupIndex), TABLE_VIEW_REFRESH_TYPE_ITEM_ADD);
3381         }
3382 }
3383
3384 void
3385 ContactEditorForm::OnTextValueChangeCanceled(const Tizen::Ui::Control& source)
3386 {
3387 }
3388
3389 result
3390 ContactEditorForm::ParseAppControlArgument(const Tizen::Base::String& argument, Tizen::Base::String& type, Tizen::Base::String& content)
3391 {
3392         result r = E_SUCCESS;
3393
3394         if (argument.IsEmpty() || argument.Contains(DELIMITER) == false)
3395         {
3396                 return E_FAILURE;
3397         }
3398
3399         int delimiterIndex;
3400
3401         argument.IndexOf(DELIMITER, 0, delimiterIndex);
3402         argument.SubString(0, delimiterIndex++, type);
3403         TryReturn(r == E_SUCCESS, r, "[%s] Unable to get type", GetErrorMessage(r));
3404         argument.SubString(delimiterIndex, argument.GetLength() - delimiterIndex, content);
3405         TryReturn(r == E_SUCCESS, r, "[%s] Unable to get type", GetErrorMessage(r));
3406
3407         return r;
3408 }
3409
3410 void
3411 ContactEditorForm::OnFocusGained(const Tizen::Ui::Control& source)
3412 {
3413         __pCurrentFocusedItem = source.GetParent();
3414
3415         if (__previousItemIndex != -1 && __previousGroupIndex != -1)
3416         {
3417                 const EditField* pEditField = static_cast<const EditField*>(&source);
3418                 if (pEditField == null)
3419                 {
3420                         return;
3421                 }
3422
3423                 int groupIndex;
3424                 int itemIndex;
3425                 int index;
3426
3427                 Integer::Decode(pEditField->GetName(), index);
3428                 groupIndex = (index & TABLE_VIEW_GROUP_INDEX_MASK) >> TABLE_VIEW_GROUP_INDEX_SHIFT;
3429                 itemIndex = (index & TABLE_VIEW_ITEM_INDEX_MASK);
3430
3431                 if (groupIndex == __previousGroupIndex && itemIndex == __previousItemIndex)
3432                 {
3433                         //Same item is focused. Hence not deleting it
3434                 }
3435                 else
3436                 {
3437                         DeleteInputField(__previousGroupIndex, __previousItemIndex);
3438                 }
3439         }
3440 }
3441
3442 void
3443 ContactEditorForm::OnFocusLost(const Tizen::Ui::Control& source)
3444 {
3445         if (__pCurrentFocusedItem == __pNameFieldItem)
3446         {
3447                 SaveNameFields();
3448         }
3449
3450         __pCurrentFocusedItem = null;
3451 }
3452
3453 void
3454 ContactEditorForm::ShowDefaultPhoneNumberContextMenu(const Tizen::Graphics::Point& position)
3455 {
3456         if (__pDefaultPhoneNumberContextMenu != null)
3457         {
3458                 delete __pDefaultPhoneNumberContextMenu;
3459                 __pDefaultPhoneNumberContextMenu = null;
3460         }
3461
3462         __pDefaultPhoneNumberContextMenu = new (std::nothrow) ContextMenu();
3463         __pDefaultPhoneNumberContextMenu->Construct(position, CONTEXT_MENU_STYLE_LIST);
3464         __pDefaultPhoneNumberContextMenu->AddActionEventListener(*this);
3465         __pDefaultPhoneNumberContextMenu->SetFocusable(true);
3466
3467         int count = __pPresentationModel->GetMultiValuesCount(DETAIL_PROPERTY_PHONE_NUMBER);
3468         int defaultPhoneNumberIndex = __pPresentationModel->GetDefaultNumberIndex();
3469
3470         for (int i = 0; i < count; i++)
3471         {
3472                 String phoneNumber(__pPresentationModel->GetValue(DETAIL_PROPERTY_PHONE_NUMBER, i));
3473
3474                 if (i != defaultPhoneNumberIndex)
3475                 {
3476                         phoneNumber.Insert(__pPresentationModel->GetType(DETAIL_PROPERTY_PHONE_NUMBER, i) + CHARACTER_SPACE, 0);
3477                         __pDefaultPhoneNumberContextMenu->AddItem(phoneNumber, i);
3478                 }
3479         }
3480
3481         if (__pDefaultPhoneNumberContextMenu->GetItemCount() > 0)
3482         {
3483                 __pDefaultPhoneNumberContextMenu->Show();
3484         }
3485 }
3486
3487 void
3488 ContactEditorForm::ShowMoreInformationContextMenu(const Tizen::Graphics::Point& position)
3489 {
3490         if (__pMoreInformationContextMenu != null)
3491         {
3492                 delete __pMoreInformationContextMenu;
3493                 __pMoreInformationContextMenu = null;
3494         }
3495
3496         __pMoreInformationContextMenu = new (std::nothrow) ContextMenu();
3497         __pMoreInformationContextMenu->Construct(position, CONTEXT_MENU_STYLE_LIST);
3498
3499         __pMoreInformationContextMenu->SetMaxVisibleItemsCount(6);
3500         __pMoreInformationContextMenu->AddActionEventListener(*this);
3501         __pMoreInformationContextMenu->SetFocusable(true);
3502
3503         if (__isJobTitleEnabled == false)
3504         {
3505                 __pMoreInformationContextMenu->AddItem(ResourceManager::GetString(L"IDS_PB_BODY_JOB_TITLE"), IDA_CONTEXT_MENU_ITEM_JOB_TITLE);
3506         }
3507
3508         if (__isDepartmentEnabled == false)
3509         {
3510                 __pMoreInformationContextMenu->AddItem(ResourceManager::GetString(L"IDS_PB_BODY_DEPARTMENT"), IDA_CONTEXT_MENU_ITEM_DEPARTMENT);
3511         }
3512
3513         if (__pImAddressFieldItem->GetCount() == 0)
3514         {
3515                 __pMoreInformationContextMenu->AddItem(ResourceManager::GetString(L"IDS_PB_HEADER_INSTANT_MESSENGER_ABB"), IDA_CONTEXT_MENU_ITEM_INSTANT_MESSENGER);
3516         }
3517
3518         if (__pUrlFieldItem->GetCount() == 0)
3519         {
3520                 __pMoreInformationContextMenu->AddItem(ResourceManager::GetString(L"IDS_PB_BODY_URL"), IDA_CONTEXT_MENU_ITEM_URL);
3521         }
3522
3523         DateTime birthday;
3524         if (__pPresentationModel->GetBirthday(birthday) != E_SUCCESS)
3525         {
3526                 __pMoreInformationContextMenu->AddItem(ResourceManager::GetString(L"IDS_PB_BODY_BIRTHDAY"), IDA_CONTEXT_MENU_ITEM_BIRTHDAY);
3527         }
3528
3529         if (__pNoteFieldItem == null)
3530         {
3531                 __pMoreInformationContextMenu->AddItem(ResourceManager::GetString(L"IDS_PB_BODY_NOTE"), IDA_CONTEXT_MENU_ITEM_NOTE);
3532         }
3533
3534         if (__isMoreInformationContextMenuShowing == false)
3535         {
3536                 __pMoreInformationContextMenu->Show();
3537         }
3538 }
3539
3540 void
3541 ContactEditorForm::ShowTypeContextMenu(int currentType, const Tizen::Graphics::Point& position, int itemTag)
3542 {
3543         int groupIndex = (itemTag & TABLE_VIEW_GROUP_INDEX_MASK) >> TABLE_VIEW_GROUP_INDEX_SHIFT;
3544
3545         __groupIndex = groupIndex;
3546         __itemIndex = itemTag;
3547
3548         if (__isKeypadOpened)
3549         {
3550                 __isTypeContextMenuShowing = true;
3551         }
3552
3553         if (__pTypeContextMenu != null)
3554         {
3555                 delete __pTypeContextMenu;
3556                 __pTypeContextMenu = null;
3557         }
3558
3559         __pTypeContextMenu = new (std::nothrow) ContextMenu();
3560         __pTypeContextMenu->Construct(position, CONTEXT_MENU_STYLE_LIST, CONTEXT_MENU_ANCHOR_DIRECTION_LEFTWARD);
3561         __pTypeContextMenu->AddActionEventListener(*this);
3562         __pTypeContextMenu->SetFocusable(true);
3563
3564         switch (groupIndex)
3565         {
3566         case TABLE_VIEW_PHONE_NUMBER_FIELD_INDEX:
3567                 {
3568                         __pTypeContextMenu->SetMaxVisibleItemsCount(DETAIL_PHONENUMBER_TYPE_OTHER + 1);
3569                         for (int i = 0; i <= DETAIL_PHONENUMBER_TYPE_OTHER; i++)
3570                         {
3571                                 int index = i << TABLE_VIEW_INPUT_FIELD_INDEX_SHIFT;
3572                                 __pTypeContextMenu->AddItem(__pPresentationModel->GetPhoneNumberTypeString((DetailPhoneNumberType)i), itemTag | index);
3573                         }
3574                 }
3575                 break;
3576         case TABLE_VIEW_EMAIL_FIELD_INDEX:
3577                 {
3578                         __pTypeContextMenu->SetMaxVisibleItemsCount(DETAIL_EMAIL_TYPE_OTHER + 1);
3579                         for (int i = 0; i <= DETAIL_EMAIL_TYPE_OTHER; i++)
3580                         {
3581                                 int index = i << TABLE_VIEW_INPUT_FIELD_INDEX_SHIFT;
3582                                 __pTypeContextMenu->AddItem(__pPresentationModel->GetAddressTypeString((DetailAddressType)i), itemTag | index);
3583                         }
3584                 }
3585                 break;
3586         case TABLE_VIEW_ADDRESS_FIELD_INDEX:
3587                 {
3588                         __pTypeContextMenu->SetMaxVisibleItemsCount(DETAIL_ADDRESS_TYPE_OTHER + 1);
3589                         for (int i = 0; i <= DETAIL_ADDRESS_TYPE_OTHER; i++)
3590                         {
3591                                 int index = i << TABLE_VIEW_INPUT_FIELD_INDEX_SHIFT;
3592                                 __pTypeContextMenu->AddItem(__pPresentationModel->GetAddressTypeString((DetailAddressType)i), itemTag | index);
3593                         }
3594                 }
3595                 break;
3596         case TABLE_VIEW_IM_ADDRESS_FIELD_INDEX:
3597                 {
3598                         __pTypeContextMenu->SetMaxVisibleItemsCount(7); // Temporary the code due to limit max count(8) by UI framework.
3599                         for (int i = 0; i <= DETAIL_IM_ADDRESS_TYPE_OTHER; i++)
3600                         {
3601                                 int index = i << TABLE_VIEW_INPUT_FIELD_INDEX_SHIFT;
3602                                 __pTypeContextMenu->AddItem(__pPresentationModel->GetImAddressTypeString((DetailImAddressType)i), itemTag | index);
3603                         }
3604                 }
3605                 break;
3606         case TABLE_VIEW_URL_FIELD_INDEX:
3607                 {
3608                         __pTypeContextMenu->SetMaxVisibleItemsCount(DETAIL_URL_TYPE_OTHER + 1);
3609                         for (int i = 0; i <= DETAIL_URL_TYPE_OTHER; i++)
3610                         {
3611                                 int index = i << TABLE_VIEW_INPUT_FIELD_INDEX_SHIFT;
3612                                 __pTypeContextMenu->AddItem(__pPresentationModel->GetUrlTypeString((DetailUrlType)i), itemTag | index);
3613                         }
3614                 }
3615                 break;
3616         default:
3617                 {
3618                         __isTypeContextMenuShowing = false;
3619                         __groupIndex = -1;
3620                         __itemIndex = -1;
3621                         delete __pTypeContextMenu;
3622                         __pTypeContextMenu = null;
3623                 }
3624                 break;
3625         }
3626
3627         if (__pTypeContextMenu != null)
3628         {
3629                 __pTypeContextMenu->RemoveItemAt(currentType);
3630                 __pTypeContextMenu->Show();
3631         }
3632 }
3633
3634 void
3635 ContactEditorForm::OnTouchPressed(const Tizen::Ui::Control& source, const Tizen::Graphics::Point& currentPosition, const Tizen::Ui::TouchEventInfo& touchInfo)
3636 {
3637         __isScrollOccurred = false;
3638
3639         Panel* pPanel = null;
3640
3641         if (source.GetName().Equals(GROUP_STYLE_PANEL, true))
3642         {
3643                 pPanel = static_cast<Panel*>(&(const_cast<Control&>(source)));
3644         }
3645         else if (source.GetName().Equals(GROUP_LABEL_TITLE, true) || source.GetName().Equals(GROUP_LABEL_VALUE, true))
3646         {
3647                 pPanel = static_cast<Panel*>(source.GetParent());
3648         }
3649
3650         if (pPanel != null)
3651         {
3652                 pPanel->SetBackgroundColor(COLOR_PRESSED);
3653
3654                 Label* pLabelValue = static_cast<Label*>(pPanel->GetControl(GROUP_LABEL_VALUE, true));
3655                 pLabelValue->SetTextColor(Color(COLOR_ITEM_PRESSED));
3656
3657                 Label* pLabelTitle = static_cast<Label*>(pPanel->GetControl(GROUP_LABEL_TITLE, true));
3658                 pLabelTitle->SetTextColor(COLOR_ITEM_PRESSED);
3659
3660                 pPanel->Invalidate(true);
3661         }
3662 }
3663
3664 void
3665 ContactEditorForm::OnTouchReleased(const Tizen::Ui::Control& source, const Tizen::Graphics::Point& currentPosition, const Tizen::Ui::TouchEventInfo& touchInfo)
3666 {
3667         Panel* pPanel = null;
3668
3669         if (source.GetName().Equals(GROUP_STYLE_PANEL, true))
3670         {
3671                 pPanel = static_cast<Panel*>(&(const_cast<Control&>(source)));
3672         }
3673         else if (source.GetName().Equals(GROUP_LABEL_TITLE, true) || source.GetName().Equals(GROUP_LABEL_VALUE, true))
3674         {
3675                 pPanel = static_cast<Panel*>(source.GetParent());
3676         }
3677
3678         if (pPanel != null)
3679         {
3680                 pPanel->SetBackgroundColor(COLOR_THUMBNAIL_BACKGROUND);
3681
3682                 Label* pLabelValue = static_cast<Label*>(pPanel->GetControl(GROUP_LABEL_VALUE, true));
3683                 pLabelValue->SetTextColor(Color(COLOR_ITEM_VALUE));
3684
3685                 Label* pLabelTitle = static_cast<Label*>(pPanel->GetControl(GROUP_LABEL_TITLE, true));
3686                 pLabelTitle->SetTextColor(COLOR_ITEM_TITLE);
3687
3688                 pPanel->Invalidate(true);
3689         }
3690
3691         if (__isScrollOccurred || source.Contains(currentPosition) == false)
3692         {
3693                 return;
3694         }
3695 }
3696
3697 void
3698 ContactEditorForm::OnTouchMoved(const Tizen::Ui::Control& source, const Tizen::Graphics::Point& currentPosition, const Tizen::Ui::TouchEventInfo& touchInfo)
3699 {
3700         Panel* pPanel = null;
3701
3702         if (source.GetName().Equals(GROUP_STYLE_PANEL, true))
3703         {
3704                 pPanel = static_cast<Panel*>(&(const_cast<Control&>(source)));
3705         }
3706         else if (source.GetName().Equals(GROUP_LABEL_TITLE, true) || source.GetName().Equals(GROUP_LABEL_VALUE, true))
3707         {
3708                 pPanel = static_cast<Panel*>(source.GetParent());
3709         }
3710
3711         if (pPanel != null)
3712         {
3713                 pPanel->SetBackgroundColor(COLOR_THUMBNAIL_BACKGROUND);
3714
3715                 Label* pLabelValue = static_cast<Label*>(pPanel->GetControl(GROUP_LABEL_VALUE, true));
3716                 pLabelValue->SetTextColor(Color(COLOR_ITEM_VALUE));
3717
3718                 Label* pLabelTitle = static_cast<Label*>(pPanel->GetControl(GROUP_LABEL_TITLE, true));
3719                 pLabelTitle->SetTextColor(COLOR_ITEM_TITLE);
3720
3721                 pPanel->Invalidate(true);
3722         }
3723 }
3724
3725 void
3726 ContactEditorForm::OnKeyPressed(const Tizen::Ui::Control& source, Tizen::Ui::KeyCode keyCode)
3727 {
3728         if (keyCode == KEY_ENTER )
3729         {
3730                 TableViewItem* pItem = static_cast<TableViewItem*>(&(const_cast<Control&>(source)));
3731                 String valueString;
3732                 Panel* pPanel = static_cast<Panel*>(pItem->GetControl(0));
3733
3734                 if (pPanel == null)
3735                 {
3736                         return;
3737                 }
3738
3739                 Label* pLabelValue = static_cast<Label*>(pPanel->GetControl(1));
3740
3741                 if (pLabelValue == null)
3742                 {
3743                         return;
3744                 }
3745
3746                 Label* pLabelTitle = static_cast<Label*>(pPanel->GetControl(0));
3747
3748                 if (pLabelTitle == null)
3749                 {
3750                         return;
3751                 }
3752
3753                 pPanel->SetBackgroundColor(COLOR_PRESSED);
3754                 pLabelValue->SetTextColor(Color(COLOR_ITEM_PRESSED));
3755                 pLabelTitle->SetTextColor(COLOR_ITEM_PRESSED);
3756                 pPanel->Invalidate(true);
3757         }
3758 }
3759
3760 void
3761 ContactEditorForm::OnKeyReleased(const Tizen::Ui::Control& source, Tizen::Ui::KeyCode keyCode)
3762 {
3763         if (keyCode == KEY_ENTER )
3764         {
3765
3766                 TableViewItem* pItem = static_cast<TableViewItem*>(&(const_cast<Control&>(source)));
3767                 String valueString;
3768                 Panel* pPanel = static_cast<Panel*>(pItem->GetControl(0));
3769
3770                 if (pPanel == null)
3771                 {
3772                         return;
3773                 }
3774
3775                 Label* pLabelValue = static_cast<Label*>(pPanel->GetControl(1));
3776
3777                 if (pLabelValue == null)
3778                 {
3779                         return;
3780                 }
3781
3782                 Label* pLabelTitle = static_cast<Label*>(pPanel->GetControl(0));
3783
3784                 if (pLabelTitle == null)
3785                 {
3786                         return;
3787                 }
3788
3789                 pPanel->SetBackgroundColor(COLOR_THUMBNAIL_BACKGROUND);
3790                 pLabelValue->SetTextColor(Color(COLOR_ITEM_VALUE));
3791                 pLabelTitle->SetTextColor(COLOR_ITEM_TITLE);
3792                 pPanel->Invalidate(true);
3793         }
3794 }
3795
3796 void
3797 ContactEditorForm::OnKeyLongPressed(const Tizen::Ui::Control& source, Tizen::Ui::KeyCode keyCode)
3798 {
3799
3800 }
3801
3802 void
3803 ContactEditorForm::OnTouchFocusIn(const Tizen::Ui::Control& source, const Tizen::Graphics::Point& currentPosition, const Tizen::Ui::TouchEventInfo& touchInfo)
3804 {
3805 }
3806
3807 void
3808 ContactEditorForm::OnTouchFocusOut(const Tizen::Ui::Control& source, const Tizen::Graphics::Point& currentPosition, const Tizen::Ui::TouchEventInfo& touchInfo)
3809 {
3810 }
3811
3812 void
3813 ContactEditorForm::OnTouchCanceled(const Tizen::Ui::Control& source, const Tizen::Graphics::Point& currentPosition, const Tizen::Ui::TouchEventInfo& touchInfo)
3814 {
3815         Panel* pPanel = null;
3816
3817         if (source.GetName().Equals(GROUP_STYLE_PANEL, true))
3818         {
3819                 pPanel = static_cast<Panel*>(&(const_cast<Control&>(source)));
3820         }
3821         else if (source.GetName().Equals(GROUP_LABEL_TITLE, true) || source.GetName().Equals(GROUP_LABEL_VALUE, true))
3822         {
3823                 pPanel = static_cast<Panel*>(source.GetParent());
3824         }
3825
3826         if (pPanel != null)
3827         {
3828                 pPanel->SetBackgroundColor(COLOR_THUMBNAIL_BACKGROUND);
3829
3830                 Label* pLabelValue = static_cast<Label*>(pPanel->GetControl(GROUP_LABEL_VALUE, true));
3831                 pLabelValue->SetTextColor(Color(COLOR_ITEM_VALUE));
3832
3833                 Label* pLabelTitle = static_cast<Label*>(pPanel->GetControl(GROUP_LABEL_TITLE, true));
3834                 pLabelTitle->SetTextColor(COLOR_ITEM_TITLE);
3835
3836                 pPanel->Invalidate(true);
3837         }
3838
3839         if (__isScrollOccurred || source.Contains(currentPosition) == false)
3840         {
3841                 return;
3842         }
3843 }
3844
3845 void
3846 ContactEditorForm::OnScrollEndReached (Tizen::Ui::Control &source, Tizen::Ui::Controls::ScrollEndEvent type)
3847 {
3848 }
3849
3850 void
3851 ContactEditorForm::OnScrollPositionChanged (Tizen::Ui::Control &source, int scrollPos)
3852 {
3853         int scrollDif = scrollPos - __scrolledDistance;
3854         if (__isTypeContextMenuShowing)
3855         {
3856                 Point anchorPosition = __pTypeContextMenu->GetAnchorPosition();
3857
3858                 anchorPosition.y -= scrollDif;
3859                 __pTypeContextMenu->SetAnchorPosition(anchorPosition);
3860                 __pTypeContextMenu->Show();
3861
3862                 __isTypeContextMenuShowing = false;
3863                 __groupIndex = -1;
3864                 __itemIndex = -1;
3865         }
3866         if (__pDefaultPhoneNumberContextMenu != null)
3867         {
3868                 Point anchorPosition = __pDefaultPhoneNumberContextMenu->GetAnchorPosition();
3869
3870                 anchorPosition.y -= scrollDif;
3871                 __pDefaultPhoneNumberContextMenu->SetAnchorPosition(anchorPosition);
3872                 __pDefaultPhoneNumberContextMenu->Show();
3873         }
3874
3875         __scrolledDistance = scrollPos;
3876         __origScrolledDistance = scrollPos;
3877
3878         if (__isScrollOccurred == false)
3879         {
3880                 __isScrollOccurred = true;
3881         }
3882 }
3883
3884 void
3885 ContactEditorForm::OnScrollStopped (Tizen::Ui::Control &source)
3886 {
3887 }
3888
3889 void
3890 ContactEditorForm::OnExpandableEditAreaLineAdded (Tizen::Ui::Controls::ExpandableEditArea &source, int newLineCount)
3891 {
3892         __pTableView->RefreshItem(TABLE_VIEW_NOTE_FIELD_INDEX, 0, TABLE_VIEW_REFRESH_TYPE_ITEM_MODIFY);
3893 }
3894
3895 void
3896 ContactEditorForm::OnExpandableEditAreaLineRemoved (Tizen::Ui::Controls::ExpandableEditArea &source, int newLineCount)
3897 {
3898         __pTableView->RefreshItem(TABLE_VIEW_NOTE_FIELD_INDEX, 0, TABLE_VIEW_REFRESH_TYPE_ITEM_MODIFY);
3899 }
3900
3901 void
3902 ContactEditorForm::OnDateChanged(const Tizen::Ui::Control& source, int year, int month, int day)
3903 {
3904         DateTime changedDate;
3905
3906         changedDate.SetValue(year, month, day);
3907         __pPresentationModel->SetBirthday(changedDate);
3908         __isContactModified = true;
3909 }
3910
3911 void
3912 ContactEditorForm::OnDateChangeCanceled(const Tizen::Ui::Control& source)
3913 {
3914 }
3915
3916 void
3917 ContactEditorForm::OnAppControlCompleteResponseReceived(const Tizen::App::AppId& appId, const Tizen::Base::String& operationId, Tizen::App::AppCtrlResult appControlResult, const Tizen::Base::Collection::IMap* pExtraData)
3918 {
3919         AppLogDebug("ENTER");
3920
3921         if (__pAppControl != null)
3922         {
3923                 delete __pAppControl;
3924                 __pAppControl = null;
3925         }
3926
3927         TryReturnVoid(appControlResult == APP_CTRL_RESULT_SUCCEEDED, "[E_FAILURE] The result of an appcontrol is not succeeded.");
3928         TryReturnVoid(pExtraData != null, "[E_FAILURE] The extra data is null.");
3929
3930         const String *pResultString = null;
3931         const ArrayList* pResultList = dynamic_cast<const ArrayList*>(pExtraData->GetValue(String(OUTPUT_KEY_SELECTED)));
3932         if (pResultList != null)
3933         {
3934                 pResultString = static_cast<const String*>(pResultList->GetAt(0));
3935         }
3936         else
3937         {
3938                 pResultString = static_cast<const String*>(pExtraData->GetValue(String(OUTPUT_KEY_SELECTED)));
3939         }
3940         TryReturnVoid(pResultString != null, "[E_FAILURE] Unable to get file path.");
3941
3942         if (appId.Equals(String(PROVIDER_ID_CAMERA)) && operationId.Equals(String(OPERATION_ID_CREATE_CONTENT)))
3943         {
3944                 __pPresentationModel->SetThumbnail(*pResultString);
3945                 __pTableView->RefreshItem(TABLE_VIEW_THUMBNAIL_FIELD_INDEX, 0, TABLE_VIEW_REFRESH_TYPE_ITEM_MODIFY);
3946
3947                 if (__pFileEventManager == null)
3948                 {
3949                         __pFileEventManager = new (std::nothrow) FileEventManager();
3950                         __pFileEventManager->Construct(*this);
3951                 }
3952                 __pFileEventManager->AddPath(*pResultString, FILE_EVENT_TYPE_DELETE | FILE_EVENT_TYPE_DELETE_SELF | FILE_EVENT_TYPE_MODIFY | FILE_EVENT_TYPE_MOVE_SELF);
3953                 __isContactModified = true;
3954         }
3955         else if (appId.Equals(String(PROVIDER_ID_GALLERY)) && operationId.Equals(String(OPERATION_ID_PICK)))
3956         {
3957                 int width = 0;
3958                 int height = 0;
3959                 ImageFormat imageFormat;
3960                 result r = ImageBuffer::GetImageInfo(*pResultString, imageFormat, width, height);
3961
3962                 if (appControlResult == APP_CTRL_RESULT_FAILED || r != E_SUCCESS)
3963                 {
3964                         int modalResult = 0;
3965                         MessageBox unsupportedMessageBox;
3966                         unsupportedMessageBox.Construct(L"", ResourceManager::GetString(L"IDS_MP_POP_INVALID_FILE"), MSGBOX_STYLE_NONE, 3000);
3967                         unsupportedMessageBox.ShowAndWait(modalResult);
3968
3969                         return;
3970                 }
3971
3972                 r = LaunchImageViewerAppControl(*pResultString);
3973         }
3974         else if (appId.Equals(String(PROVIDER_ID_FILEMANAGER)) && operationId.Equals(String(OPERATION_ID_PICK)))
3975         {
3976                 __pPresentationModel->SetValue(DETAIL_PROPERTY_RINGTONE, *pResultString);
3977                 __pTableView->RefreshItem(TABLE_VIEW_GROUP_RINGTONE_FIELD_INDEX, 2, TABLE_VIEW_REFRESH_TYPE_ITEM_MODIFY);
3978
3979                 if (__pFileEventManager == null)
3980                 {
3981                         __pFileEventManager = new (std::nothrow) FileEventManager();
3982                         __pFileEventManager->Construct(*this);
3983                 }
3984                 __pFileEventManager->AddPath(*pResultString, FILE_EVENT_TYPE_DELETE | FILE_EVENT_TYPE_DELETE_SELF | FILE_EVENT_TYPE_MODIFY | FILE_EVENT_TYPE_MOVE_SELF);
3985
3986                 __isContactModified = true;
3987         }
3988         else if(appId.Equals(String(PROVIDER_ID_IMAGEVIEWER)) && operationId.Equals(String(OPERATION_ID_CROP)))
3989         {
3990                 int width = 0;
3991                 int height = 0;
3992                 ImageFormat imageFormat;
3993                 result r = ImageBuffer::GetImageInfo(*pResultString, imageFormat, width, height);
3994
3995                 if (appControlResult == APP_CTRL_RESULT_FAILED || r != E_SUCCESS)
3996                 {
3997                         int modalResult = 0;
3998                         MessageBox unsupportedMessageBox;
3999                         unsupportedMessageBox.Construct(L"", ResourceManager::GetString(L"IDS_MP_POP_INVALID_FILE"), MSGBOX_STYLE_NONE, 3000);
4000                         unsupportedMessageBox.ShowAndWait(modalResult);
4001
4002                         return;
4003                 }
4004
4005                 __pPresentationModel->SetThumbnail(*pResultString);
4006                 AppLogDebug("pResultString is %ls", pResultString->GetPointer());
4007                 __isContactModified = true;
4008                 __pTableView->RefreshItem(TABLE_VIEW_THUMBNAIL_FIELD_INDEX, 0, TABLE_VIEW_REFRESH_TYPE_ITEM_MODIFY);
4009
4010                 if (__pFileEventManager == null)
4011                 {
4012                         __pFileEventManager = new (std::nothrow) FileEventManager();
4013                         __pFileEventManager->Construct(*this);
4014                 }
4015                 __pFileEventManager->AddPath(*pResultString, FILE_EVENT_TYPE_DELETE | FILE_EVENT_TYPE_DELETE_SELF | FILE_EVENT_TYPE_MODIFY | FILE_EVENT_TYPE_MOVE_SELF);
4016         }
4017
4018         AppLogDebug("EXIT");
4019 }
4020
4021 result
4022 ContactEditorForm::LaunchAppControl(const Tizen::App::AppId& appId, const Tizen::Base::String& operationId)
4023 {
4024         result r = E_SUCCESS;
4025
4026         String uri;
4027         String mimeType;
4028         HashMap extraData;
4029         extraData.Construct();
4030
4031         if (appId.Equals(String(PROVIDER_ID_CAMERA)) && operationId.Equals(String(OPERATION_ID_CREATE_CONTENT)))
4032         {
4033                 mimeType.Append(INPUT_MIME_TYPE_CAMERA);
4034                 extraData.Add(new (std::nothrow) String(INPUT_KEY_ALLOW_SWITCH), new (std::nothrow) String(INPUT_VALUE_FALSE));
4035         }
4036         else if (appId.Equals(String(PROVIDER_ID_GALLERY)) && operationId.Equals(String(OPERATION_ID_PICK)))
4037         {
4038                 mimeType.Append(INPUT_MIME_TYPE_GALLERY);
4039                 extraData.Add(new (std::nothrow) String(INPUT_KEY_SELECTION_MODE), new (std::nothrow) String(INPUT_DATA_SELECTION_MODE_SINGLE));
4040         }
4041         else if (appId.Equals(String(PROVIDER_ID_FILEMANAGER)) && operationId.Equals(String(OPERATION_ID_PICK)))
4042         {
4043                 mimeType.Append(INPUT_MIME_TYPE_AUDIO);
4044                 extraData.Add(new (std::nothrow) String(INPUT_KEY_SELECTION_MODE), new (std::nothrow) String(INPUT_DATA_SELECTION_MODE_SINGLE));
4045         }
4046
4047         __pAppControl = AppManager::FindAppControlN(appId, operationId);
4048
4049         if (__pAppControl != null)
4050         {
4051                 r = __pAppControl->Start(&uri, &mimeType, &extraData, this);
4052                 TryCatch(r == E_SUCCESS, , "[%s] Unable to launch app control.", GetErrorMessage(r));
4053
4054                 SetEnabled(false);
4055                 Invalidate(true);
4056         }
4057         extraData.RemoveAll(true);
4058
4059         return r;
4060
4061 CATCH:
4062         extraData.RemoveAll(true);
4063         delete __pAppControl;
4064         __pAppControl = null;
4065
4066         return r;
4067 }
4068
4069 result
4070 ContactEditorForm::LaunchImageViewerAppControl(const Tizen::Base::String& filePath)
4071 {
4072         result r = E_SUCCESS;
4073
4074         HashMap extraData;
4075         extraData.Construct();
4076         extraData.Add(new (std::nothrow) String(INPUT_KEY_IMAGEVIEWER_MODE), new (std::nothrow) String(INPUT_VALUE_IMAGEVIEWER_TYPE));
4077
4078         __pAppControl = AppManager::FindAppControlN(PROVIDER_ID_IMAGEVIEWER, OPERATION_ID_CROP);
4079
4080         if (__pAppControl)
4081         {
4082                 r = __pAppControl->Start(&filePath, null, &extraData, this);
4083                 TryCatch(r == E_SUCCESS, , "[%s] Unable to launch app control.", GetErrorMessage(r));
4084
4085                 SetEnabled(false);
4086                 Invalidate(true);
4087         }
4088         extraData.RemoveAll(true);
4089
4090         return r;
4091
4092         CATCH:
4093         extraData.RemoveAll(true);
4094         delete __pAppControl;
4095         __pAppControl = null;
4096
4097         return r;
4098 }
4099
4100 void
4101 ContactEditorForm::OnContactsChanged(void)
4102 {
4103         SceneManager* pSceneManager = SceneManager::GetInstance();
4104         ContactsApp* pContactsApp = static_cast<ContactsApp*>(ContactsApp::GetInstance());
4105
4106         if (__isSaved == false)
4107         {
4108                 if (__pPresentationModel->IsContactRemoved())
4109                 {
4110                         if (pContactsApp->GetOperationId() == OPERATION_ID_VIEW)
4111                         {
4112                                 __pPresentationModel->RemoveContactChangeListener(*this);
4113                         }
4114                         else
4115                         {
4116                                 if (__pAppControl != null)
4117                                 {
4118                                         __pAppControl->Stop();
4119                                 }
4120                                 pSceneManager->GoBackward(BackwardSceneTransition(SCENE_TRANSITION_ANIMATION_TYPE_RIGHT));
4121                         }
4122                 }
4123
4124                 return;
4125         }
4126
4127         SetFocus();
4128
4129         if (__isAppControl)
4130         {
4131                 AppControlProviderManager* pAppManager = AppControlProviderManager::GetInstance();
4132                 HashMap* pReturnValue = new (std::nothrow) HashMap();
4133                 pReturnValue->Construct();
4134
4135                 pReturnValue->Add(new (std::nothrow) String(CONTACT_KEY_ITEM_ID), new (std::nothrow) String(Integer::ToString(__pPresentationModel->GetContactId())));
4136
4137                 result r = pAppManager->SendAppControlResult(pContactsApp->GetRequestId(), APP_CTRL_RESULT_SUCCEEDED, pReturnValue);
4138                 AppLogDebug("[%s] The return result from SendAppControlResult().", GetErrorMessage(r));
4139
4140                 UiApp::GetInstance()->Terminate();
4141         }
4142         else
4143         {
4144                 ArrayList* pArg = null;
4145
4146                 if (__pPresentationModel->GetVcfPath().IsEmpty() == false)
4147                 {
4148                         pArg = new (std::nothrow) ArrayList();
4149                         pArg->Construct();
4150
4151                         String* pViewType = new (std::nothrow) String();
4152                         String* pValueType = new (std::nothrow) String();
4153
4154                         pViewType->Append(VIEW_TYPE);
4155                         pViewType->Append(DELIMITER);
4156                         pViewType->Append(VIEW_TYPE_VALUE_CONTACT);
4157
4158                         pValueType->Append(VIEW_TYPE_CONTACT_ID);
4159                         pValueType->Append(DELIMITER);
4160                         pValueType->Append(Integer::ToString(__pPresentationModel->GetContactId()));
4161
4162                         pArg->Add(pViewType);
4163                         pArg->Add(pValueType);
4164                 }
4165                 pSceneManager->GoBackward(BackwardSceneTransition(SCENE_TRANSITION_ANIMATION_TYPE_RIGHT), pArg);
4166         }
4167
4168         __isSaved = false;
4169 }
4170
4171 void
4172 ContactEditorForm::OnCategoriesChanged(void)
4173 {
4174         __pTableView->RefreshItem(TABLE_VIEW_GROUP_RINGTONE_FIELD_INDEX, 0, TABLE_VIEW_REFRESH_TYPE_ITEM_MODIFY);
4175 }
4176
4177 void
4178 ContactEditorForm::OnForeground(void)
4179 {
4180 }
4181
4182 void
4183 ContactEditorForm::OnBackground(void)
4184 {
4185         if (__previousItemIndex != -1 && __previousGroupIndex != -1)
4186         {
4187                 DeleteInputField(__previousGroupIndex, __previousItemIndex);
4188         }
4189         if (IsEnabled() == false)
4190         {
4191                 SetEnabled(true);
4192                 Invalidate(true);
4193         }
4194 }
4195
4196 void
4197 ContactEditorForm::OnFileEventOccured(const unsigned long events, const Tizen::Base::String &path, const unsigned int eventId)
4198 {
4199         String thumbnailPath = __pPresentationModel->GetValue(DETAIL_PROPERTY_THUMBNAIL);
4200         if (thumbnailPath.Equals(path, false) == true)
4201         {
4202                 __pPresentationModel->SetThumbnail(L"");
4203                 __pTableView->RefreshItem(TABLE_VIEW_THUMBNAIL_FIELD_INDEX, 0, TABLE_VIEW_REFRESH_TYPE_ITEM_MODIFY);
4204         }
4205         else
4206         {
4207                 String ringtonePath = __pPresentationModel->GetValue(DETAIL_PROPERTY_RINGTONE);
4208                 if (ringtonePath.Equals(ResourceManager::GetString(L"IDS_PB_BODY_DEFAULT"), false) == true )
4209                 {
4210                         __pTableView->RefreshItem(TABLE_VIEW_GROUP_RINGTONE_FIELD_INDEX, 2, TABLE_VIEW_REFRESH_TYPE_ITEM_MODIFY);
4211                 }
4212         }
4213 }
4214
4215 void
4216 ContactEditorForm::OnDeviceStateChanged(Tizen::System::DeviceType deviceType, const Tizen::Base::String &state)
4217 {
4218         if (deviceType != DEVICE_TYPE_STORAGE_CARD || __pPresentationModel->GetValue(DETAIL_PROPERTY_THUMBNAIL).IsEmpty())
4219         {
4220                 return;
4221         }
4222
4223         if (state.Equals(SD_CARD_UNMOUNTED, false) && File::IsFileExist(__pPresentationModel->GetValue(DETAIL_PROPERTY_THUMBNAIL)) == false)
4224         {
4225                 __pPresentationModel->SetThumbnail(L"");
4226                 __pTableView->RefreshItem(TABLE_VIEW_THUMBNAIL_FIELD_INDEX, 0, TABLE_VIEW_REFRESH_TYPE_ITEM_MODIFY);
4227         }
4228 }
4229
4230 bool ContactEditorForm::ValidateEmailAddress(const Tizen::Base::String& emailAddress)
4231 {
4232         int count = 0;
4233         int index = 0;
4234         const wchar_t* tmpChar;
4235         const wchar_t* tmpDomain;
4236         String splChars = L"([<@,;\\:\">])";
4237
4238         for (tmpChar = emailAddress.GetPointer(), index=0; index < emailAddress.GetLength(); tmpChar++, index++)
4239         {
4240                 if (*tmpChar == '\"' && (tmpChar == emailAddress.GetPointer() || *(tmpChar-1) == '.' || *(tmpChar-1) == '\"'))
4241                 {
4242                         while (*++tmpChar)
4243                         {
4244                                 if (*tmpChar == '\"')
4245                                 {
4246                                         break;
4247                                 }
4248                                 if (*tmpChar == '\\' && (*++tmpChar == ' '))
4249                                 {
4250                                         continue;
4251                                 }
4252                                 if (*tmpChar <= ' ' || *tmpChar >= 127)
4253                                 {
4254                                         return false;
4255                                 }
4256                         }
4257                         if (!*tmpChar++)
4258                         {
4259                                 return false;
4260                         }
4261                         if (*tmpChar == '@')
4262                         {
4263                                 break;
4264                         }
4265                         if (*tmpChar != '.')
4266                         {
4267                                 return false;
4268                         }
4269                         continue;
4270                 }
4271                 if (*tmpChar == '@')
4272                 {
4273                         break;
4274                 }
4275                 if (*tmpChar <= ' ' || *tmpChar >= 127)
4276                 {
4277                         return false;
4278                 }
4279                 if (splChars.IndexOf(*tmpChar, 0, index) != E_OBJ_NOT_FOUND)
4280                 {
4281                         return false;
4282                 }
4283         }
4284         if (tmpChar == emailAddress.GetPointer() || *(tmpChar-1) == '.')
4285         {
4286                 return false;
4287         }
4288
4289         if (!*(tmpDomain = ++tmpChar))
4290         {
4291                 return false;
4292         }
4293         do
4294         {
4295                 if (*tmpChar == '.')
4296                 {
4297                         if (tmpChar == tmpDomain || *(tmpChar-1) == '.')
4298                         {
4299                                 return false;
4300                         }
4301                         count++;
4302                 }
4303                 if (*tmpChar <= ' ' || *tmpChar >= 127)
4304                 {
4305                         return false;
4306                 }
4307                 if (splChars.IndexOf(*tmpChar, 0, index) != E_OBJ_NOT_FOUND)
4308                 {
4309                         return false;
4310                 }
4311         } while (*++tmpChar);
4312
4313         if (*(tmpChar-1) == '.')
4314         {
4315                 return false;
4316         }
4317
4318         if (count >= 1)
4319         {
4320                 return true;
4321         }
4322
4323         return false;
4324 }
4325
4326 void
4327 ContactEditorForm::OnSettingChanged(Tizen::Base::String &key)
4328 {
4329         if(key == L"http://tizen.org/setting/locale.date_time")
4330         {
4331                 DateTime bday;
4332                 __pPresentationModel->GetBirthday(bday);
4333
4334                 DateTime currentDate;
4335                 Tizen::System::SystemTime::GetCurrentTime(currentDate);
4336
4337                 if(bday > currentDate)
4338                 {
4339                         __pPresentationModel->SetBirthday(currentDate);
4340                         __pTableView->RefreshItem(TABLE_VIEW_BIRTHDAY_FIELD_INDEX, 0, TABLE_VIEW_REFRESH_TYPE_ITEM_MODIFY);
4341                 }
4342         }
4343 }
4344
4345 bool
4346 ContactEditorForm::OnKeyPressed(Control& source, const KeyEventInfo& keyEventInfo)
4347 {
4348         return false;
4349 }
4350
4351 bool
4352 ContactEditorForm::OnKeyReleased(Control& source, const KeyEventInfo& keyEventInfo)
4353 {
4354         if (keyEventInfo.GetKeyCode() == KEY_BACK || keyEventInfo.GetKeyCode() == KEY_ESC)
4355         {
4356                 if (__pDiscardChangesPopup && __pDiscardChangesPopup->GetShowState() == true)
4357                 {
4358                         HideDiscardChangesPopup();
4359                         return true;
4360                 }
4361         }
4362         return false;
4363 }
4364
4365 bool
4366 ContactEditorForm::OnPreviewKeyPressed(Control& source, const KeyEventInfo& keyEventInfo)
4367 {
4368         return false;
4369 }
4370
4371 bool
4372 ContactEditorForm::OnPreviewKeyReleased(Control& source, const KeyEventInfo& keyEventInfo)
4373 {
4374         return false;
4375 }
4376
4377 void
4378 ContactEditorForm::ShowDiscardChangesPopup(void)
4379 {
4380         if (__pDiscardChangesPopup == null)
4381         {
4382                 __pDiscardChangesPopup = new (std::nothrow) Popup();
4383                 __pDiscardChangesPopup->Construct(false, Dimension(W_SAVE_POPUP, H_SAVE_POPUP));
4384                 __pDiscardChangesPopup->SetPropagatedKeyEventListener(this);
4385
4386                 Rectangle popupClientBounds = __pDiscardChangesPopup->GetClientAreaBounds();
4387
4388                 Label* pLabel = new (std::nothrow) Label();
4389                 pLabel->Construct(Rectangle(X_SAVE_LABEL, Y_SAVE_LABEL, W_SAVE_LABEL, H_SAVE_LABEL), ResourceManager::GetString(L"IDS_PB_POP_DISCARD_CHANGES_Q"));
4390                 pLabel->SetTextConfig(FONT_SIZE_SAVE_CONFIRM, LABEL_TEXT_STYLE_NORMAL);
4391                 pLabel->SetTextVerticalAlignment(ALIGNMENT_MIDDLE);
4392                 pLabel->SetTextHorizontalAlignment(ALIGNMENT_LEFT);
4393
4394                 Button* pSaveButton = new (std::nothrow) Button();
4395                 pSaveButton->Construct(Rectangle(X_SAVE_LABEL + W_SAVE_BUTTON + W_POPUP_ITEM_GAP, Y_SAVE_BUTTON, W_SAVE_BUTTON, H_SAVE_BUTTON), ResourceManager::GetString(L"IDS_COM_SK_OK"));
4396                 pSaveButton->SetTextSize(FONT_SIZE_SAVE_BUTTON);
4397                 pSaveButton->SetActionId(IDA_POPUP_DISCARD_CHANGES_OK);
4398                 pSaveButton->AddActionEventListener(*this);
4399
4400                 Button* pCancelButton = new (std::nothrow) Button();
4401                 pCancelButton->Construct(Rectangle(X_SAVE_LABEL, Y_SAVE_BUTTON, W_SAVE_BUTTON, H_SAVE_BUTTON), ResourceManager::GetString(L"IDS_PB_SK_CANCEL"));
4402                 pCancelButton->SetTextSize(FONT_SIZE_SAVE_BUTTON);
4403                 pCancelButton->SetActionId(IDA_POPUP_DISCARD_CHANGES_CANCEL);
4404                 pCancelButton->AddActionEventListener(*this);
4405
4406                 __pDiscardChangesPopup->AddControl(pLabel);
4407                 __pDiscardChangesPopup->AddControl(pSaveButton);
4408                 __pDiscardChangesPopup->AddControl(pCancelButton);
4409         }
4410
4411         __pDiscardChangesPopup->SetShowState(true);
4412         __pDiscardChangesPopup->Show();
4413 }
4414
4415 void
4416 ContactEditorForm::HideDiscardChangesPopup(void)
4417 {
4418         __pDiscardChangesPopup->SetShowState(false);
4419         Invalidate(true);
4420 }