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