a7be512f6cb214b7363d312b4ccae4c04c7b22cc
[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.0 (the License);
5 // you may not use this file except in compliance with the License.
6 // You may obtain a copy of the License at
7 //
8 //     http://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
32 using namespace Tizen::App;
33 using namespace Tizen::Base;
34 using namespace Tizen::Base::Collection;
35 using namespace Tizen::Base::Utility;
36 using namespace Tizen::Graphics;
37 using namespace Tizen::Io;
38 using namespace Tizen::Media;
39 using namespace Tizen::Ui;
40 using namespace Tizen::Ui::Controls;
41 using namespace Tizen::Ui::Scenes;
42 using namespace Tizen::Social;
43 using namespace Tizen::System;
44
45 static const int IDA_ACTION_BAR_SAVE = 11;
46 static const int IDA_BUTTON_THUMBNAIL_ADD = 21;
47 static const int IDA_BUTTON_THUMBNAIL_DELETE = 22;
48 static const int IDA_BUTTON_CAMERA = 23;
49 static const int IDA_BUTTON_EXPANDABLE = 24;
50 static const int IDA_BUTTON_MORE_INFO = 25;
51 static const int IDA_BUTTON_BIRTHDAY_CLEAR = 26;
52 static const int IDA_BUTTON_DEFAULT_PHONE_NUMBER = 27;
53 static const int IDA_CONTEXT_MENU_ITEM_JOB_TITLE = 31;
54 static const int IDA_CONTEXT_MENU_ITEM_DEPARTMENT = 32;
55 static const int IDA_CONTEXT_MENU_ITEM_INSTANT_MESSENGER = 33;
56 static const int IDA_CONTEXT_MENU_ITEM_URL = 34;
57 static const int IDA_CONTEXT_MENU_ITEM_BIRTHDAY = 35;
58 static const int IDA_CONTEXT_MENU_ITEM_NOTE = 36;
59 static const int IDA_INPUT_FIELD_DISPLAY_NAME = 41;
60
61 static const wchar_t* IDB_EXPAND_BUTTON_NORMAL = L"00_circle_button.png";
62 static const wchar_t* IDB_EXPAND_BUTTON_PRESSED = L"00_circle_button_press.png";
63 static const wchar_t* IDB_EXPAND_CLOSED = L"00_button_expand_closed.png";
64 static const wchar_t* IDB_EXPAND_CLOSED_PRESSED = L"00_button_expand_closed_press.png";
65 static const wchar_t* IDB_EXPAND_OPENED = L"00_button_expand_opened.png";
66 static const wchar_t* IDB_EXPAND_OPENED_PRESSED = L"00_button_expand_opened_press.png";
67 static const wchar_t* IDB_BUTTON_DELETE_NORMAL = L"00_circle_button_delete.png";
68 static const wchar_t* IDB_BUTTON_DELETE_PRESSED = L"00_circle_button_delete_press.png";
69 static const wchar_t* IDB_BUTTON_MINUS = L"00_button_expand_minus_press.png";
70 static const wchar_t* IDB_BUTTON_MINUS_PRESSED = L"00_button_expand_minus_press.png";
71 static const wchar_t* IDB_BUTTON_RESET_NORMAL = L"00_button_refresh.png";
72 static const wchar_t* IDB_BUTTON_RESET_PRESSED = L"00_button_refresh_press.png";
73 static const wchar_t* IDB_BUTTON_ADD= L"C02_caller_id_icon_add.png";
74 static const wchar_t* IDB_BUTTON_ADD_PRESSED = L"C02_caller_id_icon_add_press.png";
75 static const wchar_t* IDB_BUTTON_CAMERA = L"C02_caller_id_icon_camera.png";
76 static const wchar_t* IDB_BUTTON_CAMERA_PRESSED = L"C02_caller_id_icon_camera_press.png";
77 static const wchar_t* IDB_BUTTON_DROPBOX = L"C02_button_icon_dropbox.png";
78 static const wchar_t* IDB_THUMBNAIL_BACKGROUND = L"C02_created_photo_bg.png";
79
80 static const wchar_t* INPUT_DATA_SELECTION_MODE_SINGLE = L"single";
81 static const wchar_t* INPUT_KEY_SELECTION_MODE = L"http://tizen.org/appcontrol/data/selection_mode";
82 static const wchar_t* INPUT_KEY_ALLOW_SWITCH = L"http://tizen.org/appcontrol/data/camera/allow_switch";
83 static const wchar_t* INPUT_MIME_TYPE_CAMERA = L"image/jpg";
84 static const wchar_t* INPUT_MIME_TYPE_GALLERY = L"image/*";
85 static const wchar_t* INPUT_MIME_TYPE_AUDIO = L"audio/*";
86 static const wchar_t* INPUT_VALUE_FALSE = L"false";
87 static const wchar_t* OUTPUT_KEY_SELECTED = L"http://tizen.org/appcontrol/data/selected";
88 static const wchar_t* CHARACTER_AT = L"@";
89 static const wchar_t* CHARACTER_DOT = L".";
90 static const wchar_t* SD_CARD_UNMOUNTED = L"Unmounted";
91
92 static const int H_ITEM = 112;
93 static const int H_DOUBLE_LINE_ITEM = 140;
94 static const int H_DESCRIPTION_CONTAINER = 136;
95 static const int H_DIVIDER = 1;
96 static const int W_DIVIDER = 1;
97 static const int H_EMPTY_SPACE = 32;
98 static const int H_EXPANDED_NAME_FIELDS = 672;
99 static const int H_BUTTON = 74;
100 static const int W_THUMBNAIL = 360;
101 static const int W_TITLE_LABEL = 170;
102 static const int X_MORE_INFORMATION_BUTTON = 60;
103 static const int Y_MORE_INFORMATION_BUTTON = 30;
104 static const int Y_DEFAULT_NUMBER_BUTTON = 19;
105 static const int W_ITEM_GAP = 16;
106 static const int W_TYPE_BUTTON = 186;
107 static const int W_THUMBNAIL_DELETE_BUTTON_GAP = 10;
108 static const int H_THUMBNAIL_DELETE_BUTTON_GAP = 10;
109 static const int H_THUMBNAIL_GROUP_ITEM_HEIGHT = 34;
110 static const int H_NAMEFIELD_GROUP_ITEM_HEIGHT = 40;
111 static const int H_GROUP_RINGTONE_TITLE_GAP = 22;
112 static const int H_GROUP_RINGTONE_TITLE_LABEL = 42;
113 static const int H_GROUP_RINGTONE_VALUE_LABEL = 54;
114 static const int W_DROPBOX_ICON = 29;
115 static const int H_DROPBOX_ICON = 29;
116
117 static const int FONT_SIZE_VALUE_TEXT = 44;
118 static const int FONT_SIZE_TITLE_TEXT = 32;
119
120 static const int GROUP_ITEM_COUNT = 11;
121 static const int NAME_FIELD_ITEM_COUNT = 1;
122
123 static const unsigned int COLOR_TABLE_VIEW_BG = Color32<248, 246, 239>::Value;
124 static const unsigned int COLOR_DIVIDER = Color32<169, 169, 169>::Value;
125 static const unsigned int COLOR_THUMBNAIL_BACKGROUND = Color32<239, 237, 229>::Value;
126 static const unsigned int COLOR_ITEM_TITLE = Color32<128, 128, 128>::Value;
127
128 static const int TABLE_VIEW_DELETE_INPUT_FIELD_ID = 0xE0000000;
129 static const int TABLE_VIEW_INPUT_FIELD_ACTION_MASK = 0xF0000000;
130 static const int TABLE_VIEW_INPUT_FIELD_INDEX_MASK = 0x0F000000;
131 static const int TABLE_VIEW_GROUP_INDEX_MASK = 0x00FF0000;
132 static const int TABLE_VIEW_ITEM_INDEX_MASK = 0x0000FFFF;
133 static const int TABLE_VIEW_GROUP_INDEX_SHIFT = 16;
134 static const int TABLE_VIEW_INPUT_FIELD_INDEX_SHIFT = 24;
135 static const int TABLE_VIEW_INPUT_FIELD_ACTION_SHIFT = 28;
136 static const int TABLE_VIEW_THUMBNAIL_FIELD_INDEX = 0;
137 static const int TABLE_VIEW_NAME_FIELD_INDEX = 1;
138 static const int TABLE_VIEW_PHONE_NUMBER_FIELD_INDEX = 2;
139 static const int TABLE_VIEW_EMAIL_FIELD_INDEX = 3;
140 static const int TABLE_VIEW_ADDRESS_FIELD_INDEX = 4;
141 static const int TABLE_VIEW_IM_ADDRESS_FIELD_INDEX = 5;
142 static const int TABLE_VIEW_URL_FIELD_INDEX = 6;
143 static const int TABLE_VIEW_BIRTHDAY_FIELD_INDEX = 7;
144 static const int TABLE_VIEW_NOTE_FIELD_INDEX = 8;
145 static const int TABLE_VIEW_GROUP_RINGTONE_FIELD_INDEX = 9;
146 static const int TABLE_VIEW_MORE_INFORMATION_FIELD_INDEX = 10;
147
148 static const wchar_t* INPUT_TYPE_PHONE = L"phone";
149 static const wchar_t* INPUT_TYPE_EMAIL = L"email";
150 static const wchar_t* INPUT_TYPE_URL = L"url";
151 static const wchar_t* VIEW_TYPE = L"viewType";
152 static const wchar_t* VIEW_TYPE_VALUE_CONTACT = L"contact";
153 static const wchar_t* VIEW_TYPE_CONTACT_ID = L"contactId";
154
155 ContactEditorForm::ContactEditorForm(void)
156 : __isExpandable(false)
157 , __isAppControl(false)
158 , __isJobTitleEnabled(false)
159 , __isDepartmentEnabled(false)
160 , __isDefaultPhoneNumberButtonEnabled(false)
161 , __isSaved(false)
162 , __isDataRemoved(false)
163 , __isMoreInformationContextMenuShowing(false)
164 , __isKeypadOpened(false)
165 , __scrolledDistance(0)
166 , __pPhoneNumberFieldItem(null)
167 , __pEmailFieldItem(null)
168 , __pAddressFieldItem(null)
169 , __pImAddressFieldItem(null)
170 , __pUrlFieldItem(null)
171 , __pFileEventManager(null)
172 , __pCurrentFocusedItem(null)
173 , __pDefaultPhoneNumberContextMenu(null)
174 , __pMoreInformationContextMenu(null)
175 , __pThumbnailContextMenu(null)
176 , __pTypeContextMenu(null)
177 , __pTableView(null)
178 , __pNameFieldItem(null)
179 , __pNoteFieldItem(null)
180 , __pPresentationModel(null)
181 {
182 }
183
184 ContactEditorForm::~ContactEditorForm(void)
185 {
186 }
187
188 void
189 ContactEditorForm::Initialize(void)
190 {
191         Construct(FORM_STYLE_NORMAL | FORM_STYLE_INDICATOR | FORM_STYLE_HEADER | FORM_STYLE_FOOTER);
192 }
193
194 result
195 ContactEditorForm::OnInitializing(void)
196 {
197         SetFormBackEventListener(this);
198
199         Footer* pFooter = GetFooter();
200         pFooter->SetBackButton();
201
202         FooterItem footerItemSave;
203         footerItemSave.Construct(IDA_ACTION_BAR_SAVE);
204         footerItemSave.SetText(ResourceManager::GetString(L"IDS_COM_SK_SAVE"));
205
206         pFooter->AddItem(footerItemSave);
207         pFooter->AddActionEventListener(*this);
208
209         __pTableView = new (std::nothrow) GroupedTableView();
210         __pTableView->Construct(Rectangle(0, 0, GetClientAreaBounds().width, GetClientAreaBounds().height), false, TABLE_VIEW_SCROLL_BAR_STYLE_FADE_OUT);
211         __pTableView->SetItemProvider(this);
212         __pTableView->AddScrollEventListener(*this);
213         __pTableView->AddGroupedTableViewItemEventListener(*this);
214         AddControl(*__pTableView);
215
216         __pPhoneNumberFieldItem = new (std::nothrow) ArrayList();
217         __pPhoneNumberFieldItem->Construct();
218
219         __pEmailFieldItem = new (std::nothrow) ArrayList();
220         __pEmailFieldItem->Construct();
221
222         __pAddressFieldItem = new (std::nothrow) ArrayList();
223         __pAddressFieldItem->Construct();
224
225         __pImAddressFieldItem = new (std::nothrow) ArrayList();
226         __pImAddressFieldItem->Construct();
227
228         __pUrlFieldItem = new (std::nothrow) ArrayList();
229         __pUrlFieldItem->Construct();
230
231         __pPresentationModel = new (std::nothrow) ContactPresentationModel();
232         __pPresentationModel->Construct();
233         __pPresentationModel->AddContactChangeListener(*this);
234
235         DeviceManager::AddDeviceEventListener(DEVICE_TYPE_STORAGE_CARD, *this);
236
237         return E_SUCCESS;
238 }
239
240 result
241 ContactEditorForm::OnTerminating(void)
242 {
243         AppLog("ContactEditorForm::OnTerminating()");
244
245         result r = E_SUCCESS;
246
247         __pTableView->SetItemProvider(null);
248
249         if (__pPresentationModel != null)
250         {
251                 __pPresentationModel->RemoveContactChangeListener(*this);
252                 delete __pPresentationModel;
253         }
254
255         if (__pPhoneNumberFieldItem)
256         {
257                 __pPhoneNumberFieldItem->RemoveAll(true);
258                 delete __pPhoneNumberFieldItem;
259         }
260
261         if (__pEmailFieldItem)
262         {
263                 __pEmailFieldItem->RemoveAll(true);
264                 delete __pEmailFieldItem;
265         }
266
267         if (__pAddressFieldItem)
268         {
269                 __pAddressFieldItem->RemoveAll(true);
270                 delete __pAddressFieldItem;
271         }
272
273         if (__pUrlFieldItem)
274         {
275                 __pUrlFieldItem->RemoveAll(true);
276                 delete __pUrlFieldItem;
277         }
278
279         if (__pImAddressFieldItem)
280         {
281                 __pImAddressFieldItem->RemoveAll(true);
282                 delete __pImAddressFieldItem;
283         }
284
285         delete __pNameFieldItem;
286         delete __pNoteFieldItem;
287         delete __pDefaultPhoneNumberContextMenu;
288         delete __pMoreInformationContextMenu;
289         delete __pThumbnailContextMenu;
290         delete __pTypeContextMenu;
291         delete __pFileEventManager;
292
293         DeviceManager::RemoveDeviceEventListener(DEVICE_TYPE_STORAGE_CARD, *this);
294
295         return r;
296 }
297
298 void
299 ContactEditorForm::OnFormBackRequested(Tizen::Ui::Controls::Form& source)
300 {
301         SceneManager* pSceneManager = SceneManager::GetInstance();
302
303         SetFocus();
304
305         if (__isAppControl == true)
306         {
307                 UiApp* pApp = UiApp::GetInstance();
308                 pApp->Terminate();
309         }
310         else
311         {
312                 pSceneManager->GoBackward(BackwardSceneTransition(SCENE_TRANSITION_ANIMATION_TYPE_RIGHT));
313         }
314 }
315
316 void
317 ContactEditorForm::OnActionPerformed(const Tizen::Ui::Control& source, int actionId)
318 {
319         AppLog("ContactEditorForm::OnActionPerformed(), actionId %d", actionId);
320
321         if ((actionId & TABLE_VIEW_INPUT_FIELD_ACTION_MASK) == TABLE_VIEW_DELETE_INPUT_FIELD_ID)
322         {
323                 int groupIndex = (actionId & TABLE_VIEW_GROUP_INDEX_MASK) >> TABLE_VIEW_GROUP_INDEX_SHIFT;
324                 int itemIndex = (actionId & TABLE_VIEW_ITEM_INDEX_MASK);
325
326                 if (groupIndex > TABLE_VIEW_NAME_FIELD_INDEX)
327                 {
328                         DeleteInputField(groupIndex, itemIndex);
329                 }
330
331                 return;
332         }
333         else if (&source == __pDefaultPhoneNumberContextMenu)
334         {
335                 SetAsDefaultPhoneNumber(actionId);
336
337                 return;
338         }
339         else if (((actionId & TABLE_VIEW_INPUT_FIELD_ACTION_MASK) >> TABLE_VIEW_INPUT_FIELD_ACTION_SHIFT) == TABLE_VIEW_PHONE_NUMBER_FIELD_INDEX)
340         {
341                 int itemIndex = (actionId & TABLE_VIEW_ITEM_INDEX_MASK);
342                 int selectedItemIndex = (actionId & TABLE_VIEW_INPUT_FIELD_INDEX_MASK) >> TABLE_VIEW_INPUT_FIELD_INDEX_SHIFT;
343
344                 TableViewItem* pItem = static_cast<TableViewItem *>(__pPhoneNumberFieldItem->GetAt(itemIndex));
345                 if (pItem == null)
346                 {
347                         return;
348                 }
349                 pItem->SetName(Integer::ToString(selectedItemIndex));
350
351                 Button* pButtonType = static_cast<Button *>(pItem->GetControl(1));
352                 if (pButtonType == null)
353                 {
354                         return;
355                 }
356
357                 pButtonType->SetText(__pPresentationModel->GetPhoneNumberTypeString((DetailPhoneNumberType)selectedItemIndex));
358                 pButtonType->Invalidate(false);
359
360                 return;
361         }
362         else if (((actionId & TABLE_VIEW_INPUT_FIELD_ACTION_MASK) >> TABLE_VIEW_INPUT_FIELD_ACTION_SHIFT) == TABLE_VIEW_EMAIL_FIELD_INDEX)
363         {
364                 int itemIndex = (actionId & TABLE_VIEW_ITEM_INDEX_MASK);
365                 int selectedItemIndex = (actionId & TABLE_VIEW_INPUT_FIELD_INDEX_MASK) >> TABLE_VIEW_INPUT_FIELD_INDEX_SHIFT;
366
367                 TableViewItem* pItem = static_cast<TableViewItem *>(__pEmailFieldItem->GetAt(itemIndex));
368                 if (pItem == null)
369                 {
370                         return;
371                 }
372                 pItem->SetName(Integer::ToString(selectedItemIndex));
373
374                 Button* pButtonType = static_cast<Button *>(pItem->GetControl(1));
375                 if (pButtonType == null)
376                 {
377                         return;
378                 }
379
380                 pButtonType->SetText(__pPresentationModel->GetEmailTypeString((DetailEmailType)selectedItemIndex));
381                 pButtonType->Invalidate(false);
382
383                 return;
384         }
385         else if (((actionId & TABLE_VIEW_INPUT_FIELD_ACTION_MASK) >> TABLE_VIEW_INPUT_FIELD_ACTION_SHIFT) == TABLE_VIEW_ADDRESS_FIELD_INDEX)
386         {
387                 int itemIndex = (actionId & TABLE_VIEW_ITEM_INDEX_MASK);
388                 int selectedItemIndex = (actionId & TABLE_VIEW_INPUT_FIELD_INDEX_MASK) >> TABLE_VIEW_INPUT_FIELD_INDEX_SHIFT;
389
390                 TableViewItem* pItem = static_cast<TableViewItem *>(__pAddressFieldItem->GetAt(itemIndex));
391                 if (pItem == null)
392                 {
393                         return;
394                 }
395                 pItem->SetName(Integer::ToString(selectedItemIndex));
396
397                 Button* pButtonType = static_cast<Button *>(pItem->GetControl(1));
398                 if (pButtonType == null)
399                 {
400                         return;
401                 }
402
403                 pButtonType->SetText(__pPresentationModel->GetAddressTypeString((DetailAddressType)selectedItemIndex));
404                 pButtonType->Invalidate(false);
405
406                 return;
407         }
408         else if (((actionId & TABLE_VIEW_INPUT_FIELD_ACTION_MASK) >> TABLE_VIEW_INPUT_FIELD_ACTION_SHIFT) == TABLE_VIEW_IM_ADDRESS_FIELD_INDEX)
409         {
410                 int itemIndex = (actionId & TABLE_VIEW_ITEM_INDEX_MASK);
411                 int selectedItemIndex = (actionId & TABLE_VIEW_INPUT_FIELD_INDEX_MASK) >> TABLE_VIEW_INPUT_FIELD_INDEX_SHIFT;
412
413                 TableViewItem* pItem = static_cast<TableViewItem *>(__pImAddressFieldItem->GetAt(itemIndex));
414                 if (pItem == null)
415                 {
416                         return;
417                 }
418                 pItem->SetName(Integer::ToString(selectedItemIndex));
419
420                 Button* pButtonType = static_cast<Button *>(pItem->GetControl(1));
421                 if (pButtonType == null)
422                 {
423                         return;
424                 }
425
426                 pButtonType->SetText(__pPresentationModel->GetImAddressTypeString((DetailImAddressType)selectedItemIndex));
427                 pButtonType->Invalidate(false);
428
429                 return;
430         }
431         else if (((actionId & TABLE_VIEW_INPUT_FIELD_ACTION_MASK) >> TABLE_VIEW_INPUT_FIELD_ACTION_SHIFT) == TABLE_VIEW_URL_FIELD_INDEX)
432         {
433                 int itemIndex = (actionId & TABLE_VIEW_ITEM_INDEX_MASK);
434                 int selectedItemIndex = (actionId & TABLE_VIEW_INPUT_FIELD_INDEX_MASK) >> TABLE_VIEW_INPUT_FIELD_INDEX_SHIFT;
435
436                 TableViewItem* pItem = static_cast<TableViewItem *>(__pUrlFieldItem->GetAt(itemIndex));
437                 if (pItem == null)
438                 {
439                         return;
440                 }
441                 pItem->SetName(Integer::ToString(selectedItemIndex));
442
443                 Button* pButtonType = static_cast<Button *>(pItem->GetControl(1));
444                 if (pButtonType == null)
445                 {
446                         return;
447                 }
448
449                 pButtonType->SetText(__pPresentationModel->GetUrlTypeString((DetailUrlType)selectedItemIndex));
450                 pButtonType->Invalidate(false);
451
452                 return;
453         }
454
455         switch (actionId)
456         {
457         case IDA_ACTION_BAR_SAVE:
458                 {
459                         result r = SaveContactData();
460
461                         if (r != E_SUCCESS)
462                         {
463                                 return;
464                         }
465
466                         __isSaved = true;
467                 }
468                 break;
469         case IDA_BUTTON_THUMBNAIL_ADD:
470                 {
471                         if (__pCurrentFocusedItem != null)
472                         {
473                                 SetFocus();
474                         }
475                         LaunchAppControl(PROVIDER_ID_GALLERY, OPERATION_ID_PICK);
476                 }
477                 break;
478         case IDA_BUTTON_THUMBNAIL_DELETE:
479                 {
480                         __pPresentationModel->SetThumbnail(L"");
481                         __pTableView->RefreshItem(TABLE_VIEW_THUMBNAIL_FIELD_INDEX, 0, TABLE_VIEW_REFRESH_TYPE_ITEM_MODIFY);
482
483                         delete __pFileEventManager;
484                         __pFileEventManager = null;
485                 }
486                 break;
487         case IDA_BUTTON_CAMERA:
488                 {
489                         if (__pCurrentFocusedItem != null)
490                         {
491                                 SetFocus();
492                         }
493                         LaunchAppControl(PROVIDER_ID_CAMERA, OPERATION_ID_CREATE_CONTENT);
494                 }
495                 break;
496         case IDA_BUTTON_EXPANDABLE:
497                 {
498                         ChangeNameFieldStatus();
499
500                         if (__pCurrentFocusedItem == __pNameFieldItem)
501                         {
502                                 __pCurrentFocusedItem = null;
503                         }
504
505                         __pTableView->RefreshItem(TABLE_VIEW_NAME_FIELD_INDEX, 0, TABLE_VIEW_REFRESH_TYPE_ITEM_MODIFY);
506
507                         Rectangle clientBounds = GetClientAreaBounds();
508                         __pTableView->SetSize(clientBounds.width, clientBounds.height);
509
510                         if (__pCurrentFocusedItem != null)
511                         {
512                                 SetFocus();
513                         }
514                 }
515                 break;
516         case IDA_BUTTON_MORE_INFO:
517                 {
518                         if (__pCurrentFocusedItem != null)
519                         {
520                                 if (__isKeypadOpened)
521                                 {
522                                         __isMoreInformationContextMenuShowing = true;
523                                         __scrolledDistance = 0;
524                                 }
525                                 SetFocus();
526                         }
527
528                         Control* pParentPanel = source.GetParent();
529                         if (pParentPanel == null)
530                         {
531                                 return;
532                         }
533
534                         Control* pParentTableViewItem = pParentPanel->GetParent();
535                         if (pParentTableViewItem == null)
536                         {
537                                 return;
538                         }
539
540                         Point contextMenuPos;
541
542                         contextMenuPos.x = pParentTableViewItem->GetWidth() / 2;
543                         contextMenuPos.y = GetClientAreaBounds().y + pParentTableViewItem->GetY() + source.GetY() - __scrolledDistance;
544
545                         ShowMoreInformationContextMenu(contextMenuPos);
546                 }
547                 break;
548         case IDA_BUTTON_BIRTHDAY_CLEAR:
549                 {
550                         DateTime currentDate;
551                         Tizen::System::SystemTime::GetCurrentTime(currentDate);
552                         __pPresentationModel->SetBirthday(currentDate);
553
554                         __pTableView->RefreshItem(TABLE_VIEW_BIRTHDAY_FIELD_INDEX, 0, TABLE_VIEW_REFRESH_TYPE_ITEM_MODIFY);
555                 }
556                 break;
557         case IDA_CONTEXT_MENU_ITEM_JOB_TITLE:
558                 {
559                         __isExpandable = false;
560                         __isJobTitleEnabled = true;
561
562                         ChangeNameFieldStatus();
563
564                         __pTableView->RefreshItem(TABLE_VIEW_NAME_FIELD_INDEX, 0, TABLE_VIEW_REFRESH_TYPE_ITEM_MODIFY);
565                         __pTableView->ScrollToItem(TABLE_VIEW_NAME_FIELD_INDEX, 0);
566                 }
567                 break;
568         case IDA_CONTEXT_MENU_ITEM_DEPARTMENT:
569                 {
570                         __isExpandable = false;
571                         __isDepartmentEnabled = true;
572
573                         ChangeNameFieldStatus();
574
575                         __pTableView->RefreshItem(TABLE_VIEW_NAME_FIELD_INDEX, 0, TABLE_VIEW_REFRESH_TYPE_ITEM_MODIFY);
576                         __pTableView->ScrollToItem(TABLE_VIEW_NAME_FIELD_INDEX, 0);
577                 }
578                 break;
579         case IDA_CONTEXT_MENU_ITEM_INSTANT_MESSENGER:
580                 {
581                         SaveContactData(false);
582
583                         int index = __pPresentationModel->GetMultiValuesCount(DETAIL_PROPERTY_IM_ADDRESS);
584
585                         __pTableView->RefreshItem(TABLE_VIEW_IM_ADDRESS_FIELD_INDEX, index, TABLE_VIEW_REFRESH_TYPE_ITEM_ADD);
586
587                         if (IsMoreInformationButtonVisible() == false)
588                         {
589                                 __pTableView->RefreshItem(TABLE_VIEW_MORE_INFORMATION_FIELD_INDEX, 0, TABLE_VIEW_REFRESH_TYPE_ITEM_REMOVE);
590                         }
591                         __pTableView->ScrollToItem(TABLE_VIEW_IM_ADDRESS_FIELD_INDEX, 0);
592                 }
593                 break;
594         case IDA_CONTEXT_MENU_ITEM_URL:
595                 {
596                         SaveContactData(false);
597
598                         int index = __pPresentationModel->GetMultiValuesCount(DETAIL_PROPERTY_URL);
599
600                         __pTableView->RefreshItem(TABLE_VIEW_URL_FIELD_INDEX, index, TABLE_VIEW_REFRESH_TYPE_ITEM_ADD);
601
602                         if (IsMoreInformationButtonVisible() == false)
603                         {
604                                 __pTableView->RefreshItem(TABLE_VIEW_MORE_INFORMATION_FIELD_INDEX, 0, TABLE_VIEW_REFRESH_TYPE_ITEM_REMOVE);
605                         }
606                         __pTableView->ScrollToItem(TABLE_VIEW_URL_FIELD_INDEX, 0);
607                 }
608                 break;
609         case IDA_CONTEXT_MENU_ITEM_BIRTHDAY:
610                 {
611                         DateTime currentDate;
612
613                         Tizen::System::SystemTime::GetCurrentTime(currentDate);
614                         __pPresentationModel->SetBirthday(currentDate);
615
616                         __pTableView->RefreshItem(TABLE_VIEW_BIRTHDAY_FIELD_INDEX, 0, TABLE_VIEW_REFRESH_TYPE_ITEM_ADD);
617
618                         if (IsMoreInformationButtonVisible() == false)
619                         {
620                                 __pTableView->RefreshItem(TABLE_VIEW_MORE_INFORMATION_FIELD_INDEX, 0, TABLE_VIEW_REFRESH_TYPE_ITEM_REMOVE);
621                         }
622                         __pTableView->ScrollToItem(TABLE_VIEW_BIRTHDAY_FIELD_INDEX, 0);
623                 }
624                 break;
625         case IDA_CONTEXT_MENU_ITEM_NOTE:
626                 {
627                         __pTableView->RefreshItem(TABLE_VIEW_NOTE_FIELD_INDEX, 0, TABLE_VIEW_REFRESH_TYPE_ITEM_ADD);
628
629                         if (IsMoreInformationButtonVisible() == false)
630                         {
631                                 __pTableView->RefreshItem(TABLE_VIEW_MORE_INFORMATION_FIELD_INDEX, 0, TABLE_VIEW_REFRESH_TYPE_ITEM_REMOVE);
632                         }
633                         __pTableView->ScrollToItem(TABLE_VIEW_NOTE_FIELD_INDEX, 0);
634                 }
635                 break;
636         case IDA_BUTTON_DEFAULT_PHONE_NUMBER:
637                 {
638                         Control* pParent = source.GetParent();
639                         Point contextMenuPos;
640
641                         contextMenuPos.x = pParent->GetWidth() / 2;
642                         contextMenuPos.y = GetClientAreaBounds().y + pParent->GetY() + source.GetY() + (source.GetHeight() / 2) - __scrolledDistance;
643
644                         if (__pCurrentFocusedItem != null)
645                         {
646                                 SetFocus();
647                         }
648
649                         SaveContactData(false);
650                         ShowDefaultPhoneNumberContextMenu(contextMenuPos);
651                 }
652                 break;
653         default:
654                 break;
655         }
656 }
657
658 void
659 ContactEditorForm::OnSceneActivatedN(const Tizen::Ui::Scenes::SceneId& previousSceneId, const Tizen::Ui::Scenes::SceneId& currentSceneId,
660                                                                                          Tizen::Base::Collection::IList* pArgs)
661 {
662         ContactsApp* pContactsApp = static_cast<ContactsApp*>(ContactsApp::GetInstance());
663         TryReturnVoid(pContactsApp != null, "Unable to cast UiApp to ContactsApp");
664
665         pContactsApp->AddContactsAppChangeEventListener(*this);
666
667         Header* pHeader = GetHeader();
668         Footer* pFooter = GetFooter();
669
670         if (previousSceneId.Equals(IDSCN_GROUP_SELECTOR, true) || previousSceneId.Equals(IDSCN_GROUP_EDITOR, true))
671         {
672                 if (pArgs != null)
673                 {
674                         Integer* pCategoryId = null;
675                         __pPresentationModel->RemoveContactFromAllCategories();
676
677                         IEnumerator* pEnum = pArgs->GetEnumeratorN();
678                         while (pEnum->MoveNext() == E_SUCCESS)
679                         {
680                                 pCategoryId = static_cast<Integer*>(pEnum->GetCurrent());
681                                 if (pCategoryId != null)
682                                 {
683                                         __pPresentationModel->AddContactToCategory(pCategoryId->ToInt());
684                                 }
685                         }
686                         delete pEnum;
687
688                         pArgs->RemoveAll(true);
689                         delete pArgs;
690                 }
691
692                 __pTableView->RefreshItem(TABLE_VIEW_GROUP_RINGTONE_FIELD_INDEX, 0, TABLE_VIEW_REFRESH_TYPE_ITEM_MODIFY);
693
694                 return;
695         }
696
697         if (pContactsApp->GetOperationId() == OPERATION_ID_ADD)
698         {
699                 __isAppControl = true;
700                 __pPresentationModel->PrepareNewContact();
701
702                 pHeader->SetTitleText(ResourceManager::GetString(L"IDS_COM_BODY_CREATE"));
703                 pFooter->SetItemEnabled(0, false);
704         }
705         else if (pContactsApp->GetOperationId() == OPERATION_ID_EDIT)
706         {
707                 __isAppControl = true;
708
709                 if (pArgs != null)
710                 {
711                         String* pArgString = null;
712                         String type;
713                         String content;
714
715                         IEnumerator* pEnum = pArgs->GetEnumeratorN();
716                         while (pEnum->MoveNext() == E_SUCCESS)
717                         {
718                                 pArgString = static_cast<String*>(pEnum->GetCurrent());
719                                 if (pArgString != null)
720                                 {
721                                         ParseAppControlArgument(*pArgString, type, content);
722
723                                         if (type.Equals(RETURN_TYPE_ITEM_ID, false))
724                                         {
725                                                 RecordId contactId;
726                                                 Integer::Parse(content, contactId);
727                                                 result r = __pPresentationModel->SetContactId(contactId, true);
728
729                                                 if (IsFailed(r))
730                                                 {
731                                                         AppLogDebug("Invalid contactId has been input : %d", contactId);
732                                                         UiApp::GetInstance()->Terminate();
733                                                 }
734
735                                                 if (__pPresentationModel->GetValue(DETAIL_PROPERTY_JOB_TITLE).IsEmpty() == false)
736                                                 {
737                                                         __isJobTitleEnabled = true;
738                                                 }
739                                                 if (__pPresentationModel->GetValue(DETAIL_PROPERTY_DEPARTMENT).IsEmpty() == false)
740                                                 {
741                                                         __isDepartmentEnabled = true;
742                                                 }
743                                                 break;
744                                         }
745                                 }
746                         }
747                         delete pEnum;
748
749                         pHeader->SetTitleText(ResourceManager::GetString(L"IDS_COM_SK_EDIT"));
750                 }
751         }
752         else
753         {
754                 if (pArgs != null)
755                 {
756                         Integer* pContactId = null;
757
758                         pContactId = static_cast<Integer*>(pArgs->GetAt(0));
759                         if (pContactId != null)
760                         {
761                                 if (pContactId->ToInt() != INVALID_RECORD_ID)
762                                 {
763                                         pHeader->SetTitleText(ResourceManager::GetString(L"IDS_COM_SK_EDIT"));
764                                         __pPresentationModel->SetContactId(pContactId->ToInt(), true);
765                                 }
766                                 else
767                                 {
768                                         pHeader->SetTitleText(ResourceManager::GetString(L"IDS_COM_BODY_CREATE"));
769
770                                         String* pVcfPath = static_cast<String*>(pArgs->GetAt(1));
771                                         if (pVcfPath != null)
772                                         {
773                                                 __pPresentationModel->SetVcfPath(*pVcfPath, true);
774                                         }
775                                 }
776                         }
777
778                         if (__pPresentationModel->GetValue(DETAIL_PROPERTY_JOB_TITLE).IsEmpty() == false)
779                         {
780                                 __isJobTitleEnabled = true;
781                         }
782                         if (__pPresentationModel->GetValue(DETAIL_PROPERTY_DEPARTMENT).IsEmpty() == false)
783                         {
784                                 __isDepartmentEnabled = true;
785                         }
786                 }
787                 else
788                 {
789                         pHeader->SetTitleText(ResourceManager::GetString(L"IDS_COM_BODY_CREATE"));
790                         pFooter->SetItemEnabled(0, false);
791                         __pPresentationModel->PrepareNewContact();
792                 }
793         }
794
795         if (__isAppControl == true)
796         {
797                 if (pArgs != null)
798                 {
799                         String* pArgString = null;
800                         String type;
801                         String content;
802
803                         IEnumerator* pEnum = pArgs->GetEnumeratorN();
804                         while (pEnum->MoveNext() == E_SUCCESS)
805                         {
806                                 pArgString = static_cast<String*>(pEnum->GetCurrent());
807                                 if (pArgString != null)
808                                 {
809                                         result r = E_SUCCESS;
810                                         ParseAppControlArgument(*pArgString, type, content);
811
812                                         if (type.Equals(INPUT_TYPE_PHONE, false))
813                                         {
814                                                 r = __pPresentationModel->SetValue(DETAIL_PROPERTY_PHONE_NUMBER, content, __pPresentationModel->GetMultiValuesCount(DETAIL_PROPERTY_PHONE_NUMBER));
815                                         }
816                                         else if (type.Equals(INPUT_TYPE_EMAIL, false))
817                                         {
818                                                 r = __pPresentationModel->SetValue(DETAIL_PROPERTY_EMAIL, content, __pPresentationModel->GetMultiValuesCount(DETAIL_PROPERTY_EMAIL));
819                                         }
820                                         else if (type.Equals(INPUT_TYPE_URL, false))
821                                         {
822                                                 r = __pPresentationModel->SetValue(DETAIL_PROPERTY_URL, content, __pPresentationModel->GetMultiValuesCount(DETAIL_PROPERTY_URL));
823                                         }
824
825                                         if (r == E_SUCCESS)
826                                         {
827                                                 pFooter->SetItemEnabled(0, true);
828                                         }
829                                 }
830                         }
831                         delete pEnum;
832                 }
833         }
834
835         if (pArgs != null)
836         {
837                 pArgs->RemoveAll(true);
838                 delete pArgs;
839         }
840 }
841
842 void
843 ContactEditorForm::OnSceneDeactivated(const Tizen::Ui::Scenes::SceneId& currentSceneId, const Tizen::Ui::Scenes::SceneId& nextSceneId)
844 {
845         ContactsApp* pContactsApp = static_cast<ContactsApp*>(ContactsApp::GetInstance());
846
847         pContactsApp->RemoveContactsAppChangeEventListener(*this);
848 }
849
850 void
851 ContactEditorForm::OnKeypadWillOpen(Tizen::Ui::Control& source)
852 {
853 }
854
855 void
856 ContactEditorForm::OnKeypadOpened(Tizen::Ui::Control& source)
857 {
858         Rectangle clientBounds = GetClientAreaBounds();
859
860         __pTableView->SetSize(clientBounds.width, clientBounds.height);
861         __isKeypadOpened = true;
862 }
863
864 void
865 ContactEditorForm::OnKeypadClosed(Tizen::Ui::Control& source)
866 {
867         if (__pCurrentFocusedItem != null)
868         {
869                 SetFocus();
870         }
871         else if (__isMoreInformationContextMenuShowing)
872         {
873                 Point anchorPosition = __pMoreInformationContextMenu->GetAnchorPosition();
874
875                 __pTableView->ScrollToItem(TABLE_VIEW_MORE_INFORMATION_FIELD_INDEX, 0, TABLE_VIEW_SCROLL_ITEM_ALIGNMENT_BOTTOM);
876                 anchorPosition.y -= __scrolledDistance;
877                 __pMoreInformationContextMenu->SetAnchorPosition(anchorPosition);
878                 __pMoreInformationContextMenu->Show();
879
880                 __isMoreInformationContextMenuShowing = false;
881         }
882         __isKeypadOpened = false;
883 }
884
885 void
886 ContactEditorForm::OnKeypadActionPerformed(Tizen::Ui::Control& source, Tizen::Ui::KeypadAction keypadAction)
887 {
888 }
889
890 void
891 ContactEditorForm::OnKeypadBoundsChanged(Tizen::Ui::Control& source)
892 {
893         Rectangle clientBounds = GetClientAreaBounds();
894
895         __pTableView->SetSize(clientBounds.width, clientBounds.height);
896 }
897
898 void
899 ContactEditorForm::OnGroupedTableViewItemStateChanged(Tizen::Ui::Controls::GroupedTableView &tableView, int groupIndex, int itemIndex, Tizen::Ui::Controls::TableViewItem *pItem, Tizen::Ui::Controls::TableViewItemStatus status)
900 {
901         SceneManager* pSceneManager = SceneManager::GetInstance();
902
903         if (status == TABLE_VIEW_ITEM_STATUS_SELECTED && groupIndex == TABLE_VIEW_GROUP_RINGTONE_FIELD_INDEX)
904         {
905                 if (__pCurrentFocusedItem != null)
906                 {
907                         SetFocus();
908                 }
909
910                 if (itemIndex == 0)
911                 {
912                         if (__pPresentationModel->GetCategoryCount() > 0)
913                         {
914                                 IList* pCategoryList = __pPresentationModel->GetAssignedCategoryIdListN();
915
916                                 pSceneManager->GoForward(ForwardSceneTransition(IDSCN_GROUP_SELECTOR, SCENE_TRANSITION_ANIMATION_TYPE_LEFT), pCategoryList);
917                         }
918                         else
919                         {
920                                 pSceneManager->GoForward(ForwardSceneTransition(IDSCN_GROUP_EDITOR, SCENE_TRANSITION_ANIMATION_TYPE_LEFT));
921                         }
922
923                         return;
924                 }
925                 else if (itemIndex == 2)
926                 {
927                         LaunchAppControl(PROVIDER_ID_FILEMANAGER, OPERATION_ID_PICK);
928                 }
929         }
930 }
931
932 void
933 ContactEditorForm::OnGroupedTableViewContextItemActivationStateChanged(Tizen::Ui::Controls::GroupedTableView &tableView, int groupIndex, int itemIndex, Tizen::Ui::Controls::TableViewContextItem *pContextItem, bool activated)
934 {
935 }
936
937 void
938 ContactEditorForm::OnGroupedTableViewGroupItemStateChanged(Tizen::Ui::Controls::GroupedTableView &tableView, int groupIndex, Tizen::Ui::Controls::TableViewGroupItem *pItem, Tizen::Ui::Controls::TableViewItemStatus status)
939 {
940 }
941
942 int
943 ContactEditorForm::GetGroupCount(void)
944 {
945         return GROUP_ITEM_COUNT;
946 }
947
948 int
949 ContactEditorForm::GetItemCount(int groupIndex)
950 {
951         int itemCount = 0;
952
953         switch (groupIndex)
954         {
955         case TABLE_VIEW_THUMBNAIL_FIELD_INDEX:
956                 {
957                         itemCount = 1;
958                 }
959                 break;
960         case TABLE_VIEW_NAME_FIELD_INDEX:
961                 {
962                         itemCount = NAME_FIELD_ITEM_COUNT;
963                 }
964                 break;
965         case TABLE_VIEW_PHONE_NUMBER_FIELD_INDEX:
966                 {
967                         itemCount = __pPresentationModel->GetMultiValuesCount(DETAIL_PROPERTY_PHONE_NUMBER) + 1;
968
969                         if (__pPresentationModel->GetMultiValuesCount(DETAIL_PROPERTY_PHONE_NUMBER) > 1)
970                         {
971                                 __isDefaultPhoneNumberButtonEnabled = true;
972                                 itemCount++;
973                         }
974                         else
975                         {
976                                 __isDefaultPhoneNumberButtonEnabled = false;
977                         }
978                 }
979                 break;
980         case TABLE_VIEW_EMAIL_FIELD_INDEX:
981                 {
982                         itemCount = __pPresentationModel->GetMultiValuesCount(DETAIL_PROPERTY_EMAIL) + 1;
983                 }
984                 break;
985         case TABLE_VIEW_ADDRESS_FIELD_INDEX:
986                 {
987                         itemCount = __pPresentationModel->GetMultiValuesCount(DETAIL_PROPERTY_ADDRESS) + 1;
988                 }
989                 break;
990         case TABLE_VIEW_IM_ADDRESS_FIELD_INDEX:
991                 {
992                         itemCount = __pPresentationModel->GetMultiValuesCount(DETAIL_PROPERTY_IM_ADDRESS);
993
994                         if ((itemCount == 0 && __pImAddressFieldItem->GetCount() > 0) || itemCount > 0)
995                         {
996                                 itemCount++;
997                         }
998                 }
999                 break;
1000         case TABLE_VIEW_URL_FIELD_INDEX:
1001                 {
1002                         itemCount = __pPresentationModel->GetMultiValuesCount(DETAIL_PROPERTY_URL);
1003
1004                         if ((itemCount == 0 && __pUrlFieldItem->GetCount() > 0) || itemCount > 0)
1005                         {
1006                                 itemCount++;
1007                         }
1008                 }
1009                 break;
1010         case TABLE_VIEW_BIRTHDAY_FIELD_INDEX:
1011                 {
1012                         DateTime birthday;
1013                         if (__pPresentationModel->GetBirthday(birthday) != E_SUCCESS)
1014                         {
1015                                 itemCount = 0;
1016                         }
1017                         else
1018                         {
1019                                 itemCount = 1;
1020                         }
1021                 }
1022                 break;
1023         case TABLE_VIEW_NOTE_FIELD_INDEX:
1024                 {
1025                         if (__pPresentationModel->GetValue(DETAIL_PROPERTY_NOTE).IsEmpty() == false || __pNoteFieldItem != null )
1026                         {
1027                                 itemCount = 1;
1028                         }
1029                         else
1030                         {
1031                                 itemCount = 0;
1032                         }
1033                 }
1034                 break;
1035         case TABLE_VIEW_GROUP_RINGTONE_FIELD_INDEX:
1036                 {
1037                         itemCount = 3;
1038                 }
1039                 break;
1040         case TABLE_VIEW_MORE_INFORMATION_FIELD_INDEX:
1041                 {
1042                         if (IsMoreInformationButtonVisible())
1043                         {
1044                                 itemCount = 1;
1045                         }
1046                         else
1047                         {
1048                                 itemCount = 0;
1049                         }
1050                 }
1051                 break;
1052         default:
1053                 break;
1054         }
1055
1056         return itemCount;
1057 }
1058
1059 int
1060 ContactEditorForm::GetDefaultGroupItemHeight(void)
1061 {
1062         return H_EMPTY_SPACE;
1063 }
1064
1065 int
1066 ContactEditorForm::GetDefaultItemHeight(void)
1067 {
1068         return H_ITEM;
1069 }
1070
1071 TableViewGroupItem*
1072 ContactEditorForm::CreateGroupItem(int groupIndex, int itemWidth)
1073 {
1074         int groupItemHeight = H_EMPTY_SPACE;
1075
1076         if (groupIndex == TABLE_VIEW_THUMBNAIL_FIELD_INDEX)
1077         {
1078                 groupItemHeight = H_THUMBNAIL_GROUP_ITEM_HEIGHT;
1079         }
1080         else if (groupIndex == TABLE_VIEW_NAME_FIELD_INDEX)
1081         {
1082                 groupItemHeight = H_NAMEFIELD_GROUP_ITEM_HEIGHT;
1083         }
1084         else if ((groupIndex > TABLE_VIEW_PHONE_NUMBER_FIELD_INDEX && groupIndex < TABLE_VIEW_GROUP_RINGTONE_FIELD_INDEX) || groupIndex == TABLE_VIEW_MORE_INFORMATION_FIELD_INDEX)
1085         {
1086                 groupItemHeight = 0;
1087         }
1088
1089         TableViewGroupItem* pGroupItem = new (std::nothrow) TableViewGroupItem();
1090         pGroupItem->Construct(Dimension(itemWidth, groupItemHeight));
1091         pGroupItem->SetBackgroundColor(Color(COLOR_TABLE_VIEW_BG), TABLE_VIEW_ITEM_DRAWING_STATUS_NORMAL);
1092         pGroupItem->SetEnabled(false);
1093
1094         Panel* pPanel = new (std::nothrow) Panel();
1095         pPanel->Construct(Rectangle(0, -(H_DIVIDER), itemWidth, groupItemHeight + H_DIVIDER));
1096         pPanel->SetBackgroundColor(Color(COLOR_TABLE_VIEW_BG));
1097
1098         pGroupItem->AddControl(*pPanel);
1099
1100         return pGroupItem;
1101 }
1102
1103 bool
1104 ContactEditorForm::DeleteGroupItem(int groupIndex, Tizen::Ui::Controls::TableViewGroupItem* pItem)
1105 {
1106         delete pItem;
1107         pItem = null;
1108
1109         return true;
1110 }
1111
1112 TableViewItem*
1113 ContactEditorForm::CreateItem(int groupIndex, int itemIndex, int itemWidth)
1114 {
1115         TableViewItem* pItem = null;
1116
1117         switch (groupIndex)
1118         {
1119         case TABLE_VIEW_THUMBNAIL_FIELD_INDEX:
1120                 {
1121                         pItem = GetThumbnailField(itemWidth);
1122                 }
1123                 break;
1124         case TABLE_VIEW_NAME_FIELD_INDEX:
1125                 {
1126                         pItem = GetNameFields(itemWidth);
1127                 }
1128                 break;
1129         case TABLE_VIEW_PHONE_NUMBER_FIELD_INDEX:
1130                 {
1131                         if ((itemIndex == __pTableView->GetItemCountAt(groupIndex) - 1) && __isDefaultPhoneNumberButtonEnabled == true)
1132                         {
1133                                 pItem = GetDefaultPhoneNumberItem(itemWidth);
1134                                 break;
1135                         }
1136
1137                         pItem = GetPhoneNumberFields(itemIndex, itemWidth);
1138                 }
1139                 break;
1140         case TABLE_VIEW_EMAIL_FIELD_INDEX:
1141                 {
1142                         pItem = GetEmailFields(itemIndex, itemWidth);
1143                 }
1144                 break;
1145         case TABLE_VIEW_ADDRESS_FIELD_INDEX:
1146                 {
1147                         pItem = GetAddressFields(itemIndex, itemWidth);
1148                 }
1149                 break;
1150         case TABLE_VIEW_IM_ADDRESS_FIELD_INDEX:
1151                 {
1152                         pItem = GetImAddressFields(itemIndex, itemWidth);
1153                 }
1154                 break;
1155         case TABLE_VIEW_URL_FIELD_INDEX:
1156                 {
1157                         pItem = GetUrlFields(itemIndex, itemWidth);
1158                 }
1159                 break;
1160         case TABLE_VIEW_BIRTHDAY_FIELD_INDEX:
1161                 {
1162                         pItem = GetBirthdayField(itemWidth);
1163                 }
1164                 break;
1165         case TABLE_VIEW_NOTE_FIELD_INDEX:
1166                 {
1167                         pItem = GetNoteField(itemWidth);
1168                 }
1169                 break;
1170         case TABLE_VIEW_GROUP_RINGTONE_FIELD_INDEX:
1171                 {
1172                         switch (itemIndex)
1173                         {
1174                         case 0:
1175                                 pItem = GetGroupsField(itemWidth);
1176                                 break;
1177                         case 1:
1178                                 {
1179                                         pItem = new (std::nothrow) TableViewItem();
1180                                         pItem->Construct(Dimension(itemWidth, H_DIVIDER * 2));
1181                                         pItem->SetEnabled(false);
1182                                 }
1183                                 break;
1184                         case 2:
1185                                 pItem = GetRingtoneField(itemWidth);
1186                                 break;
1187                         default:
1188                                 break;
1189                         }
1190                 }
1191                 break;
1192         case TABLE_VIEW_MORE_INFORMATION_FIELD_INDEX:
1193                 {
1194                         if (IsMoreInformationButtonVisible())
1195                         {
1196                                 pItem = GetMoreInformationField(itemWidth);
1197                         }
1198                         else
1199                         {
1200                                 pItem = null;
1201                         }
1202                 }
1203                 break;
1204         default:
1205                 break;
1206         }
1207
1208         return pItem;
1209 }
1210
1211 bool
1212 ContactEditorForm::DeleteItem(int groupIndex, int itemIndex, Tizen::Ui::Controls::TableViewItem* pItem)
1213 {
1214         if (groupIndex == TABLE_VIEW_PHONE_NUMBER_FIELD_INDEX)
1215         {
1216                 if ((itemIndex == __pPhoneNumberFieldItem->GetCount()) && __isDefaultPhoneNumberButtonEnabled == true)
1217                 {
1218                         delete pItem;
1219                         pItem = null;
1220
1221                         return true;
1222                 }
1223         }
1224
1225         if ((groupIndex > TABLE_VIEW_NAME_FIELD_INDEX && groupIndex < TABLE_VIEW_BIRTHDAY_FIELD_INDEX) || groupIndex == TABLE_VIEW_NOTE_FIELD_INDEX)
1226         {
1227                 if (__isDataRemoved == false)
1228                 {
1229                         return true;
1230                 }
1231         }
1232         else if (groupIndex == TABLE_VIEW_NAME_FIELD_INDEX)
1233         {
1234                 SaveNameFields();
1235                 __pNameFieldItem = null;
1236         }
1237
1238         if (__pCurrentFocusedItem == pItem && __isKeypadOpened)
1239         {
1240                 __isKeypadOpened = false;
1241         }
1242
1243         delete pItem;
1244         pItem = null;
1245
1246         return true;
1247 }
1248
1249 void
1250 ContactEditorForm::UpdateGroupItem(int groupIndex, Tizen::Ui::Controls::TableViewGroupItem *pItem)
1251 {
1252 }
1253
1254 void
1255 ContactEditorForm::UpdateItem(int groupIndex, int itemIndex, Tizen::Ui::Controls::TableViewItem *pItem)
1256 {
1257         if (pItem == null)
1258         {
1259                 return;
1260         }
1261
1262         switch (groupIndex)
1263         {
1264         case TABLE_VIEW_THUMBNAIL_FIELD_INDEX:
1265                 {
1266                         SetThumbnailControls(*pItem, true);
1267                         pItem->Invalidate(true);
1268                 }
1269                 break;
1270         case TABLE_VIEW_NAME_FIELD_INDEX:
1271                 {
1272                         if (__pCurrentFocusedItem == pItem && __isKeypadOpened)
1273                         {
1274                                 __isKeypadOpened = false;
1275                         }
1276                         pItem->RemoveAllControls();
1277                         SetNameFields(*pItem);
1278                         Invalidate(true);
1279                 }
1280             break;
1281         case TABLE_VIEW_GROUP_RINGTONE_FIELD_INDEX:
1282                 {
1283                         String valueString;
1284                         Label* pLabel = static_cast<Label *>(pItem->GetControl(1));
1285
1286                         if (pLabel == null)
1287                         {
1288                                 return;
1289                         }
1290
1291                         if (itemIndex == 0)
1292                         {
1293                                 valueString =  __pPresentationModel->GetValue(DETAIL_PROPERTY_GROUP);
1294                                 if (valueString.IsEmpty() == true)
1295                                 {
1296                                         valueString = ResourceManager::GetString(L"IDS_PB_BODY_NOT_ASSIGNED");
1297                                 }
1298                         }
1299                         else if (itemIndex == 2)
1300                         {
1301                                 String ringtoneName =  __pPresentationModel->GetValue(DETAIL_PROPERTY_RINGTONE);
1302                                 int index = 0;
1303
1304                                 ringtoneName.LastIndexOf(L"/", ringtoneName.GetLength() - 1, index);
1305
1306                                 if (index != 0)
1307                                 {
1308                                         ringtoneName.SubString(index + 1, valueString);
1309                                 }
1310                         }
1311
1312                         pLabel->SetText(valueString);
1313                         pLabel->Invalidate(false);
1314                 }
1315                 break;
1316         case TABLE_VIEW_BIRTHDAY_FIELD_INDEX:
1317                 {
1318                         DateTime birthdayDate;
1319                         EditDate* pBirthday = static_cast<EditDate *>(pItem->GetControl(1));
1320
1321                         if (pBirthday == null)
1322                         {
1323                                 return;
1324                         }
1325
1326                         __pPresentationModel->GetBirthday(birthdayDate);
1327
1328                         pBirthday->SetDate(birthdayDate);
1329                         pBirthday->Invalidate(false);
1330                 }
1331                 break;
1332         case TABLE_VIEW_NOTE_FIELD_INDEX:
1333                 {
1334                         Control* pNoteField = pItem->GetControl(0);
1335
1336                         if (pNoteField == null)
1337                         {
1338                                 return;
1339                         }
1340
1341                         pItem->SetSize(pItem->GetWidth(), pNoteField->GetHeight());
1342                 }
1343                 break;
1344         default:
1345                 break;
1346         }
1347 }
1348
1349 Tizen::Ui::Controls::TableViewItem*
1350 ContactEditorForm::GetThumbnailField(int itemWidth)
1351 {
1352         TableViewItem* pThumbnailItem = new (std::nothrow) TableViewItem();
1353         pThumbnailItem->Construct(Dimension(itemWidth, W_THUMBNAIL));
1354         pThumbnailItem->SetBackgroundColor(Color(0), TABLE_VIEW_ITEM_DRAWING_STATUS_PRESSED);
1355
1356         SetThumbnailControls(*pThumbnailItem);
1357
1358         return pThumbnailItem;
1359 }
1360
1361 Tizen::Ui::Controls::TableViewItem*
1362 ContactEditorForm::GetNameFields(int itemWidth)
1363 {
1364         __pNameFieldItem = new (std::nothrow) TableViewItem();
1365         __pNameFieldItem->Construct(Dimension(itemWidth, H_ITEM));
1366         __pNameFieldItem->SetBackgroundColor(Color(0), TABLE_VIEW_ITEM_DRAWING_STATUS_PRESSED);
1367
1368         SetNameFields(*__pNameFieldItem);
1369
1370         return __pNameFieldItem;
1371 }
1372
1373 void
1374 ContactEditorForm::SetNameFields(Tizen::Ui::Controls::TableViewItem& item)
1375 {
1376         int itemWidth = item.GetWidth();
1377         int itemHeight = H_ITEM;
1378
1379         if (__isExpandable == true)
1380         {
1381                 itemHeight = H_EXPANDED_NAME_FIELDS;
1382
1383                 if (__isJobTitleEnabled == true)
1384                 {
1385                         itemHeight += H_ITEM;
1386                 }
1387
1388                 if (__isDepartmentEnabled)
1389                 {
1390                         itemHeight += H_ITEM;
1391                 }
1392         }
1393
1394         item.SetSize(itemWidth, itemHeight);
1395
1396         Rectangle itemBounds(W_ITEM_GAP, 0, itemWidth - (W_ITEM_GAP * 3) - H_BUTTON, H_ITEM);
1397
1398         if (__isExpandable == true)
1399         {
1400                 EditField* pFirstName = new (std::nothrow) EditField();
1401                 pFirstName->Construct(itemBounds, EDIT_FIELD_STYLE_NORMAL, INPUT_STYLE_OVERLAY);
1402                 pFirstName->SetGuideText(ResourceManager::GetString(L"IDS_PB_BODY_FIRST_NAME"));
1403                 pFirstName->AddFocusEventListener(*this);
1404                 pFirstName->AddKeypadEventListener(*this);
1405                 pFirstName->SetName(ResourceManager::GetString(L"IDS_PB_BODY_FIRST_NAME"));
1406                 pFirstName->SetText(__pPresentationModel->GetValue(DETAIL_PROPERTY_FIRST_NAME));
1407                 pFirstName->AddTextEventListener(*this);
1408
1409                 item.AddControl(*pFirstName);
1410
1411                 itemBounds.y += pFirstName->GetHeight();
1412                 EditField* pMiddleName = new (std::nothrow) EditField();
1413                 pMiddleName->Construct(itemBounds, EDIT_FIELD_STYLE_NORMAL, INPUT_STYLE_OVERLAY);
1414                 pMiddleName->SetGuideText(ResourceManager::GetString(L"IDS_PB_BODY_MIDDLE_NAME"));
1415                 pMiddleName->AddFocusEventListener(*this);
1416                 pMiddleName->AddKeypadEventListener(*this);
1417                 pMiddleName->SetName(ResourceManager::GetString(L"IDS_PB_BODY_MIDDLE_NAME"));
1418                 pMiddleName->SetText(__pPresentationModel->GetValue(DETAIL_PROPERTY_MIDDLE_NAME));
1419
1420                 item.AddControl(*pMiddleName);
1421
1422                 itemBounds.y += pMiddleName->GetHeight();
1423                 EditField* pLastName = new (std::nothrow) EditField();
1424                 pLastName->Construct(itemBounds, EDIT_FIELD_STYLE_NORMAL, INPUT_STYLE_OVERLAY);
1425                 pLastName->SetGuideText(ResourceManager::GetString(L"IDS_PB_BODY_LAST_NAME"));
1426                 pLastName->AddFocusEventListener(*this);
1427                 pLastName->AddKeypadEventListener(*this);
1428                 pLastName->SetName(ResourceManager::GetString(L"IDS_PB_BODY_LAST_NAME"));
1429                 pLastName->SetText(__pPresentationModel->GetValue(DETAIL_PROPERTY_LAST_NAME));
1430                 pLastName->AddTextEventListener(*this);
1431
1432                 item.AddControl(*pLastName);
1433
1434                 itemBounds.y += pLastName->GetHeight();
1435                 EditField* pSuffix = new (std::nothrow) EditField();
1436                 pSuffix->Construct(itemBounds, EDIT_FIELD_STYLE_NORMAL, INPUT_STYLE_OVERLAY);
1437                 pSuffix->SetGuideText(ResourceManager::GetString(L"IDS_PB_BODY_SUFFIX"));
1438                 pSuffix->AddFocusEventListener(*this);
1439                 pSuffix->AddKeypadEventListener(*this);
1440                 pSuffix->SetName(ResourceManager::GetString(L"IDS_PB_BODY_SUFFIX"));
1441                 pSuffix->SetText(__pPresentationModel->GetValue(DETAIL_PROPERTY_NAME_SUFFIX));
1442
1443                 item.AddControl(*pSuffix);
1444
1445                 itemBounds.y += pSuffix->GetHeight();
1446                 EditField* pNickName = new (std::nothrow) EditField();
1447                 pNickName->Construct(itemBounds, EDIT_FIELD_STYLE_NORMAL, INPUT_STYLE_OVERLAY);
1448                 pNickName->SetGuideText(ResourceManager::GetString(L"IDS_PB_BODY_NICKNAME"));
1449                 pNickName->AddFocusEventListener(*this);
1450                 pNickName->AddKeypadEventListener(*this);
1451                 pNickName->SetName(ResourceManager::GetString(L"IDS_PB_BODY_NICKNAME"));
1452                 pNickName->SetText(__pPresentationModel->GetValue(DETAIL_PROPERTY_NICK_NAME));
1453
1454                 item.AddControl(*pNickName);
1455
1456                 itemBounds.y += pNickName->GetHeight();
1457                 if (__isJobTitleEnabled == true)
1458                 {
1459                         EditField* pJobTitle = new (std::nothrow) EditField();
1460                         pJobTitle->Construct(itemBounds, EDIT_FIELD_STYLE_NORMAL, INPUT_STYLE_OVERLAY);
1461                         pJobTitle->SetGuideText(ResourceManager::GetString(L"IDS_PB_BODY_JOB_TITLE"));
1462                         pJobTitle->AddFocusEventListener(*this);
1463                         pJobTitle->AddKeypadEventListener(*this);
1464                         pJobTitle->SetName(ResourceManager::GetString(L"IDS_PB_BODY_JOB_TITLE"));
1465                         pJobTitle->SetText(__pPresentationModel->GetValue(DETAIL_PROPERTY_JOB_TITLE));
1466
1467                         item.AddControl(*pJobTitle);
1468
1469                         itemBounds.y += pJobTitle->GetHeight();
1470                 }
1471
1472                 if (__isDepartmentEnabled == true)
1473                 {
1474                         EditField* pDepartment = new (std::nothrow) EditField();
1475                         pDepartment->Construct(itemBounds, EDIT_FIELD_STYLE_NORMAL, INPUT_STYLE_OVERLAY);
1476                         pDepartment->SetGuideText(ResourceManager::GetString(L"IDS_PB_BODY_DEPARTMENT"));
1477                         pDepartment->AddFocusEventListener(*this);
1478                         pDepartment->AddKeypadEventListener(*this);
1479                         pDepartment->SetName(ResourceManager::GetString(L"IDS_PB_BODY_DEPARTMENT"));
1480                         pDepartment->SetText(__pPresentationModel->GetValue(DETAIL_PROPERTY_DEPARTMENT));
1481
1482                         item.AddControl(*pDepartment);
1483
1484                         itemBounds.y += pDepartment->GetHeight();
1485                 }
1486
1487                 EditField* pCompanyName = new (std::nothrow) EditField();
1488                 pCompanyName->Construct(itemBounds, EDIT_FIELD_STYLE_NORMAL, INPUT_STYLE_OVERLAY);
1489                 pCompanyName->SetGuideText(ResourceManager::GetString(L"IDS_PB_BODY_COMPANY"));
1490                 pCompanyName->AddFocusEventListener(*this);
1491                 pCompanyName->AddKeypadEventListener(*this);
1492                 pCompanyName->SetName(ResourceManager::GetString(L"IDS_PB_BODY_COMPANY"));
1493                 pCompanyName->SetText(__pPresentationModel->GetValue(DETAIL_PROPERTY_COMPANY));
1494
1495                 item.AddControl(*pCompanyName);
1496         }
1497         else
1498         {
1499                 EditField* pName = new (std::nothrow) EditField();
1500                 pName->Construct(itemBounds, EDIT_FIELD_STYLE_NORMAL, INPUT_STYLE_OVERLAY);
1501                 pName->SetGuideText(ResourceManager::GetString(L"IDS_COM_BODY_DETAILS_NAME"));
1502                 pName->AddFocusEventListener(*this);
1503                 pName->AddKeypadEventListener(*this);
1504                 pName->SetName(Integer::ToString(IDA_INPUT_FIELD_DISPLAY_NAME));
1505                 pName->AddTextEventListener(*this);
1506
1507                 String firstName(__pPresentationModel->GetValue(DETAIL_PROPERTY_FIRST_NAME));
1508                 String lastName(__pPresentationModel->GetValue(DETAIL_PROPERTY_LAST_NAME));
1509
1510                 if (firstName.IsEmpty() == false)
1511                 {
1512                         pName->SetText(firstName);
1513                 }
1514
1515                 if (lastName.IsEmpty() == false)
1516                 {
1517                         pName->AppendText(CHARACTER_SPACE + lastName);
1518                 }
1519
1520                 item.AddControl(*pName);
1521         }
1522
1523         Button* pButtonExpand = new (std::nothrow) Button();
1524         pButtonExpand->Construct(Rectangle(itemWidth - (H_BUTTON + W_ITEM_GAP), (H_ITEM - H_BUTTON) / 2, H_BUTTON, H_BUTTON));
1525         pButtonExpand->SetActionId(IDA_BUTTON_EXPANDABLE);
1526         pButtonExpand->AddActionEventListener(*this);
1527
1528         Bitmap* pBitmap = null;
1529         Bitmap* pBitmapPressed = null;
1530
1531         if (__isExpandable == true)
1532         {
1533                 pBitmap = ResourceManager::GetBitmapN(IDB_EXPAND_OPENED);
1534                 pBitmapPressed = ResourceManager::GetBitmapN(IDB_EXPAND_OPENED_PRESSED);
1535         }
1536         else
1537         {
1538                 pBitmap = ResourceManager::GetBitmapN(IDB_EXPAND_CLOSED);
1539                 pBitmapPressed = ResourceManager::GetBitmapN(IDB_EXPAND_CLOSED_PRESSED);
1540         }
1541
1542         if (pBitmap != null)
1543         {
1544                 pButtonExpand->SetNormalBitmap(Point(0, 0), *pBitmap);
1545         }
1546
1547         if (pBitmapPressed != null)
1548         {
1549                 pButtonExpand->SetPressedBitmap(Point(0, 0), *pBitmapPressed);
1550         }
1551
1552         delete pBitmap;
1553         delete pBitmapPressed;
1554
1555         pBitmap = ResourceManager::GetBitmapN(IDB_EXPAND_BUTTON_NORMAL);
1556         pBitmapPressed = ResourceManager::GetBitmapN(IDB_EXPAND_BUTTON_PRESSED);
1557
1558         if (pBitmap != null)
1559         {
1560                 pButtonExpand->SetNormalBackgroundBitmap(*pBitmap);
1561                 delete pBitmap;
1562         }
1563         if (pBitmapPressed != null)
1564         {
1565                 pButtonExpand->SetPressedBackgroundBitmap(*pBitmapPressed);
1566                 delete pBitmapPressed;
1567         }
1568
1569         item.AddControl(*pButtonExpand);
1570 }
1571
1572 Tizen::Ui::Controls::TableViewItem*
1573 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)
1574 {
1575         TableViewItem* pTableViewItem = new (std::nothrow) TableViewItem();
1576         pTableViewItem->Construct(Dimension(itemWidth, H_ITEM), TABLE_VIEW_ANNEX_STYLE_NORMAL);
1577         pTableViewItem->SetBackgroundColor(Color(0), TABLE_VIEW_ITEM_DRAWING_STATUS_PRESSED);
1578
1579         EditField* pInputField = new (std::nothrow) EditField();
1580         pInputField->Construct(Rectangle(W_ITEM_GAP, 0, itemWidth - (W_ITEM_GAP * 4) - H_BUTTON - W_TYPE_BUTTON, H_ITEM), style, INPUT_STYLE_OVERLAY);
1581         pInputField->SetGuideText(guideText);
1582         pInputField->SetText(text);
1583         pInputField->AddKeypadEventListener(*this);
1584         pInputField->AddFocusEventListener(*this);
1585         pInputField->AddTextEventListener(*this);
1586
1587         int parsedItemIndex = 0;
1588         parsedItemIndex |= (groupIndex << TABLE_VIEW_INPUT_FIELD_ACTION_SHIFT);
1589         parsedItemIndex |= (groupIndex << TABLE_VIEW_GROUP_INDEX_SHIFT);
1590         parsedItemIndex |= itemIndex;
1591
1592         pInputField->SetName(Integer::ToString(parsedItemIndex));
1593         pTableViewItem->AddControl(*pInputField);
1594
1595         Button *pButtonType = new (std::nothrow) Button();
1596         pButtonType->Construct(Rectangle(pInputField->GetX() + pInputField->GetWidth() + W_ITEM_GAP, (H_ITEM - H_BUTTON) / 2, W_TYPE_BUTTON, H_BUTTON));
1597         pButtonType->SetText(titleText);
1598         pButtonType->AddTouchEventListener(*this);
1599         pButtonType->SetName(Integer::ToString(parsedItemIndex));
1600
1601         Bitmap* pDropBoxIcon = ResourceManager::GetBitmapN(IDB_BUTTON_DROPBOX);
1602
1603         if (pDropBoxIcon != null)
1604         {
1605                 pButtonType->SetNormalBitmap(Point(W_TYPE_BUTTON - W_DROPBOX_ICON, H_BUTTON - H_DROPBOX_ICON), *pDropBoxIcon);
1606                 pButtonType->SetPressedBitmap(Point(W_TYPE_BUTTON - W_DROPBOX_ICON, H_BUTTON - H_DROPBOX_ICON), *pDropBoxIcon);
1607                 pButtonType->SetDisabledBitmap(Point(W_TYPE_BUTTON - W_DROPBOX_ICON, H_BUTTON - H_DROPBOX_ICON), *pDropBoxIcon);
1608                 delete pDropBoxIcon;
1609         }
1610         pTableViewItem->AddControl(*pButtonType);
1611
1612         Button *pButtonDelete = new (std::nothrow) Button();
1613         pButtonDelete->Construct(Rectangle(itemWidth - H_BUTTON - W_ITEM_GAP, (H_ITEM - H_BUTTON) / 2, H_BUTTON, H_BUTTON));
1614         Bitmap* pBitmap = ResourceManager::GetBitmapN(IDB_BUTTON_MINUS);
1615         Bitmap* pBitmapPressed = ResourceManager::GetBitmapN(IDB_BUTTON_MINUS_PRESSED);
1616
1617         if (pBitmap != null)
1618         {
1619                 pButtonDelete->SetNormalBitmap(Point(0, 0), *pBitmap);
1620                 delete pBitmap;
1621         }
1622         if (pBitmapPressed != null)
1623         {
1624                 pButtonDelete->SetPressedBitmap(Point(0, 0), *pBitmapPressed);
1625                 delete pBitmapPressed;
1626         }
1627
1628         pBitmap = ResourceManager::GetBitmapN(IDB_BUTTON_DELETE_NORMAL);
1629         pBitmapPressed = ResourceManager::GetBitmapN(IDB_BUTTON_DELETE_PRESSED);
1630
1631         if (pBitmap != null)
1632         {
1633                 pButtonDelete->SetNormalBackgroundBitmap(*pBitmap);
1634                 delete pBitmap;
1635         }
1636         if (pBitmapPressed != null)
1637         {
1638                 pButtonDelete->SetPressedBackgroundBitmap(*pBitmapPressed);
1639                 delete pBitmapPressed;
1640         }
1641
1642         int actionId = 0;
1643         actionId |= TABLE_VIEW_DELETE_INPUT_FIELD_ID;
1644         actionId |= (groupIndex << TABLE_VIEW_GROUP_INDEX_SHIFT);
1645         actionId |= itemIndex;
1646
1647         pButtonDelete->SetActionId(actionId);
1648         pButtonDelete->AddActionEventListener(*this);
1649
1650         pTableViewItem->AddControl(*pButtonDelete);
1651
1652         if (isDeleteButton == false)
1653         {
1654                 pButtonDelete->SetShowState(false);
1655         }
1656
1657         return pTableViewItem;
1658 }
1659
1660 Tizen::Ui::Controls::TableViewItem*
1661 ContactEditorForm::GetPhoneNumberFields(int itemIndex, int itemWidth)
1662 {
1663         if (__pPhoneNumberFieldItem->GetCount() == 0)
1664         {
1665                 int phoneNumberCount = __pPresentationModel->GetMultiValuesCount(DETAIL_PROPERTY_PHONE_NUMBER);
1666                 String guideText = ResourceManager::GetString(L"IDS_PB_BODY_NUMBER");
1667                 String defaultPhoneNumber = __pPresentationModel->GetValue(DETAIL_PROPERTY_DEFAULT_PHONE_NUMBER);
1668
1669                 for (int i = 0; i < phoneNumberCount; i++)
1670                 {
1671                         String typeString = __pPresentationModel->GetType(DETAIL_PROPERTY_PHONE_NUMBER, i);
1672                         String phoneNumberString =  __pPresentationModel->GetValue(DETAIL_PROPERTY_PHONE_NUMBER, i);
1673
1674                         TableViewItem* pItem = GetInputFieldN(TABLE_VIEW_PHONE_NUMBER_FIELD_INDEX, i, itemWidth, EDIT_FIELD_STYLE_PHONE_NUMBER, typeString, guideText, phoneNumberString, true);
1675                         pItem->SetName(Integer::ToString(__pPresentationModel->GetPhoneNumberType(i)));
1676
1677                         __pPhoneNumberFieldItem->Add(*pItem);
1678                 }
1679
1680                 TableViewItem* pItem = GetInputFieldN(TABLE_VIEW_PHONE_NUMBER_FIELD_INDEX, phoneNumberCount, itemWidth, EDIT_FIELD_STYLE_PHONE_NUMBER, __pPresentationModel->GetPhoneNumberTypeString(DETAIL_PHONENUMBER_TYPE_MOBILE), guideText);
1681                 pItem->SetName(Integer::ToString(DETAIL_PHONENUMBER_TYPE_MOBILE));
1682
1683                 __pPhoneNumberFieldItem->Add(*pItem);
1684
1685                 SetAsDefaultPhoneNumber(__pPresentationModel->GetDefaultNumberIndex());
1686         }
1687
1688         if (__pPhoneNumberFieldItem->GetCount() != (__pPresentationModel->GetMultiValuesCount(DETAIL_PROPERTY_PHONE_NUMBER) + 1))
1689         {
1690                 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"));
1691                 pItem->SetName(Integer::ToString(DETAIL_PHONENUMBER_TYPE_MOBILE));
1692
1693                 __pPhoneNumberFieldItem->Add(*pItem);
1694         }
1695
1696         TableViewItem* pItem = static_cast<TableViewItem *>(__pPhoneNumberFieldItem->GetAt(itemIndex));
1697         if (pItem == null)
1698         {
1699                 return null;
1700         }
1701
1702         return pItem;
1703 }
1704
1705 Tizen::Ui::Controls::TableViewItem*
1706 ContactEditorForm::GetEmailFields(int itemIndex, int itemWidth)
1707 {
1708         if (__pEmailFieldItem->GetCount() == 0)
1709         {
1710                 int emailCount = __pPresentationModel->GetMultiValuesCount(DETAIL_PROPERTY_EMAIL);
1711                 String guideText = ResourceManager::GetString(L"IDS_COM_BODY_EMAIL");
1712
1713                 for (int i = 0; i < emailCount; i++)
1714                 {
1715                         String typeString = __pPresentationModel->GetType(DETAIL_PROPERTY_EMAIL, i);
1716                         String emailString =  __pPresentationModel->GetValue(DETAIL_PROPERTY_EMAIL, i);
1717
1718                         TableViewItem* pItem = GetInputFieldN(TABLE_VIEW_EMAIL_FIELD_INDEX, i, itemWidth, EDIT_FIELD_STYLE_EMAIL, typeString, guideText, emailString, true);
1719                         pItem->SetName(Integer::ToString(__pPresentationModel->GetEmailType(i)));
1720
1721                         __pEmailFieldItem->Add(*pItem);
1722                 }
1723
1724                 TableViewItem* pItem = GetInputFieldN(TABLE_VIEW_EMAIL_FIELD_INDEX, emailCount, itemWidth, EDIT_FIELD_STYLE_EMAIL, __pPresentationModel->GetEmailTypeString(DETAIL_EMAIL_TYPE_HOME), guideText);
1725                 pItem->SetName(Integer::ToString(DETAIL_EMAIL_TYPE_HOME));
1726
1727                 __pEmailFieldItem->Add(*pItem);
1728         }
1729
1730         if (__pEmailFieldItem->GetCount() != (__pPresentationModel->GetMultiValuesCount(DETAIL_PROPERTY_EMAIL) + 1))
1731         {
1732                 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"));
1733                 pItem->SetName(Integer::ToString(DETAIL_EMAIL_TYPE_HOME));
1734
1735                 __pEmailFieldItem->Add(*pItem);
1736         }
1737
1738         TableViewItem* pItem = static_cast<TableViewItem *>(__pEmailFieldItem->GetAt(itemIndex));
1739         if (pItem == null)
1740         {
1741                 return null;
1742         }
1743
1744         return pItem;
1745 }
1746
1747 Tizen::Ui::Controls::TableViewItem*
1748 ContactEditorForm::GetAddressFields(int itemIndex, int itemWidth)
1749 {
1750         if (__pAddressFieldItem->GetCount() == 0)
1751         {
1752                 int addressCount = __pPresentationModel->GetMultiValuesCount(DETAIL_PROPERTY_ADDRESS);
1753                 String guideText = ResourceManager::GetString(L"IDS_PB_BODY_ADDRESS");
1754
1755                 for (int i = 0; i < addressCount; i++)
1756                 {
1757                         String typeString = __pPresentationModel->GetType(DETAIL_PROPERTY_ADDRESS, i);
1758                         String addressString =  __pPresentationModel->GetValue(DETAIL_PROPERTY_ADDRESS, i);
1759
1760                         TableViewItem* pItem= GetInputFieldN(TABLE_VIEW_ADDRESS_FIELD_INDEX, i, itemWidth, EDIT_FIELD_STYLE_NORMAL, typeString, guideText, addressString, true);
1761                         pItem->SetName(Integer::ToString(__pPresentationModel->GetAddressType(DETAIL_PROPERTY_ADDRESS, i)));
1762
1763                         __pAddressFieldItem->Add(*pItem);
1764                 }
1765
1766                 TableViewItem* pItem = GetInputFieldN(TABLE_VIEW_ADDRESS_FIELD_INDEX, addressCount, itemWidth, EDIT_FIELD_STYLE_NORMAL, ResourceManager::GetString(L"IDS_PB_BODY_HOME"), guideText);
1767                 pItem->SetName(Integer::ToString(DETAIL_ADDRESS_TYPE_HOME));
1768
1769                 __pAddressFieldItem->Add(*pItem);
1770         }
1771
1772         if (__pAddressFieldItem->GetCount() != (__pPresentationModel->GetMultiValuesCount(DETAIL_PROPERTY_ADDRESS) + 1))
1773         {
1774                 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"));
1775                 pItem->SetName(Integer::ToString(DETAIL_ADDRESS_TYPE_HOME));
1776
1777                 __pAddressFieldItem->Add(*pItem);
1778         }
1779
1780         TableViewItem* pItem = static_cast<TableViewItem *>(__pAddressFieldItem->GetAt(itemIndex));
1781         if (pItem == null)
1782         {
1783                 return null;
1784         }
1785
1786         return pItem;
1787 }
1788
1789 Tizen::Ui::Controls::TableViewItem*
1790 ContactEditorForm::GetImAddressFields(int itemIndex, int itemWidth)
1791 {
1792         if (__pImAddressFieldItem->GetCount() == 0)
1793         {
1794                 int imCount = __pPresentationModel->GetMultiValuesCount(DETAIL_PROPERTY_IM_ADDRESS);
1795                 String guideText = ResourceManager::GetString(L"IDS_PB_HEADER_INSTANT_MESSENGER_ABB");
1796
1797                 for (int i = 0; i < imCount; i++)
1798                 {
1799                         String typeString = __pPresentationModel->GetType(DETAIL_PROPERTY_IM_ADDRESS, i);
1800                         String imString =  __pPresentationModel->GetValue(DETAIL_PROPERTY_IM_ADDRESS, i);
1801
1802                         TableViewItem* pItem = GetInputFieldN(TABLE_VIEW_IM_ADDRESS_FIELD_INDEX, i, itemWidth, EDIT_FIELD_STYLE_NORMAL, typeString, guideText, imString, true);
1803                         pItem->SetName(Integer::ToString(__pPresentationModel->GetImAddressType(i)));
1804
1805                         __pImAddressFieldItem->Add(*pItem);
1806                 }
1807
1808                 TableViewItem* pItem = GetInputFieldN(TABLE_VIEW_IM_ADDRESS_FIELD_INDEX, imCount, itemWidth, EDIT_FIELD_STYLE_NORMAL, IM_ADDRESS_YAHOO, guideText);
1809                 pItem->SetName(Integer::ToString(DETAIL_IM_ADDRESS_TYPE_YAHOO));
1810
1811                 __pImAddressFieldItem->Add(*pItem);
1812         }
1813
1814         if (__pImAddressFieldItem->GetCount() != (__pPresentationModel->GetMultiValuesCount(DETAIL_PROPERTY_IM_ADDRESS) + 1))
1815         {
1816                 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"));
1817                 pItem->SetName(Integer::ToString(DETAIL_IM_ADDRESS_TYPE_YAHOO));
1818
1819                 __pImAddressFieldItem->Add(*pItem);
1820         }
1821
1822         TableViewItem* pItem = static_cast<TableViewItem *>(__pImAddressFieldItem->GetAt(itemIndex));
1823         if (pItem == null)
1824         {
1825                 return null;
1826         }
1827
1828         return pItem;
1829 }
1830
1831 Tizen::Ui::Controls::TableViewItem*
1832 ContactEditorForm::GetUrlFields(int itemIndex, int itemWidth)
1833 {
1834         if (__pUrlFieldItem->GetCount() == 0)
1835         {
1836                 int urlCount = __pPresentationModel->GetMultiValuesCount(DETAIL_PROPERTY_URL);
1837                 String guideText = ResourceManager::GetString(L"IDS_PB_BODY_URL");
1838
1839                 for (int i = 0; i < urlCount; i++)
1840                 {
1841                         String typeString = __pPresentationModel->GetType(DETAIL_PROPERTY_URL, i);
1842                         String urlString =  __pPresentationModel->GetValue(DETAIL_PROPERTY_URL, i);
1843
1844                         TableViewItem* pItem = GetInputFieldN(TABLE_VIEW_URL_FIELD_INDEX, i, itemWidth, EDIT_FIELD_STYLE_URL, typeString, guideText, urlString, true);
1845                         pItem->SetName(Integer::ToString(__pPresentationModel->GetUrlType(i)));
1846
1847                         __pUrlFieldItem->Add(*pItem);
1848                 }
1849
1850                 TableViewItem* pItem = GetInputFieldN(TABLE_VIEW_URL_FIELD_INDEX, urlCount, itemWidth, EDIT_FIELD_STYLE_URL, __pPresentationModel->GetUrlTypeString(DETAIL_URL_TYPE_HOME), guideText);
1851                 pItem->SetName(Integer::ToString(DETAIL_URL_TYPE_HOME));
1852
1853                 __pUrlFieldItem->Add(*pItem);
1854         }
1855
1856         if (__pUrlFieldItem->GetCount() != (__pPresentationModel->GetMultiValuesCount(DETAIL_PROPERTY_URL) + 1))
1857         {
1858                 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"));
1859                 pItem->SetName(Integer::ToString(DETAIL_URL_TYPE_HOME));
1860
1861                 __pUrlFieldItem->Add(*pItem);
1862         }
1863
1864         TableViewItem* pItem = static_cast<TableViewItem *>(__pUrlFieldItem->GetAt(itemIndex));
1865         if (pItem == null)
1866         {
1867                 return null;
1868         }
1869
1870         return pItem;
1871 }
1872 Tizen::Ui::Controls::TableViewItem*
1873 ContactEditorForm::GetGroupsField(int itemWidth)
1874 {
1875         TableViewItem* pGroupsItem = new (std::nothrow) TableViewItem();
1876         pGroupsItem->Construct(Dimension(itemWidth, H_DOUBLE_LINE_ITEM), TABLE_VIEW_ANNEX_STYLE_NORMAL);
1877         pGroupsItem->SetBackgroundColor(COLOR_THUMBNAIL_BACKGROUND);
1878
1879         Label* pLabelTitle = new (std::nothrow) Label();
1880         pLabelTitle->Construct(Rectangle(0, H_GROUP_RINGTONE_TITLE_GAP, itemWidth, H_GROUP_RINGTONE_TITLE_LABEL), ResourceManager::GetString(L"IDS_PB_BODY_GROUPS"));
1881         pLabelTitle->SetTextConfig(FONT_SIZE_TITLE_TEXT, LABEL_TEXT_STYLE_BOLD);
1882         pLabelTitle->SetTextColor(COLOR_ITEM_TITLE);
1883         pLabelTitle->SetTextHorizontalAlignment(ALIGNMENT_LEFT);
1884
1885         pGroupsItem->AddControl(*pLabelTitle);
1886
1887         String groupsName =  __pPresentationModel->GetValue(DETAIL_PROPERTY_GROUP);
1888         if (groupsName.IsEmpty() == true)
1889         {
1890                 groupsName = ResourceManager::GetString(L"IDS_PB_BODY_NOT_ASSIGNED");
1891         }
1892
1893         Label* pLabelGroupName = new (std::nothrow) Label();
1894         pLabelGroupName->Construct(Rectangle(0, H_GROUP_RINGTONE_TITLE_GAP + H_GROUP_RINGTONE_TITLE_LABEL, itemWidth, H_GROUP_RINGTONE_VALUE_LABEL), groupsName);
1895         pLabelGroupName->SetTextConfig(FONT_SIZE_VALUE_TEXT, LABEL_TEXT_STYLE_NORMAL);
1896         pLabelGroupName->SetTextHorizontalAlignment(ALIGNMENT_LEFT);
1897
1898         pGroupsItem->AddControl(*pLabelGroupName);
1899
1900         return pGroupsItem;
1901 }
1902
1903 Tizen::Ui::Controls::TableViewItem*
1904 ContactEditorForm::GetBirthdayField(int itemWidth)
1905 {
1906         DateTime birthdayDate;
1907         EditDate* pBirthday = new (std::nothrow) EditDate();
1908         pBirthday->Construct(Point(W_TITLE_LABEL, 0));
1909         pBirthday->AddDateChangeEventListener(*this);
1910
1911         __pPresentationModel->GetBirthday(birthdayDate);
1912         pBirthday->SetDate(birthdayDate);
1913
1914         TableViewItem* pBirthdayItem = new (std::nothrow) TableViewItem();
1915         pBirthdayItem->Construct(Dimension(itemWidth, H_ITEM), TABLE_VIEW_ANNEX_STYLE_NORMAL);
1916         pBirthdayItem->SetBackgroundColor(COLOR_THUMBNAIL_BACKGROUND, TABLE_VIEW_ITEM_DRAWING_STATUS_NORMAL);
1917         pBirthdayItem->SetBackgroundColor(COLOR_THUMBNAIL_BACKGROUND, TABLE_VIEW_ITEM_DRAWING_STATUS_PRESSED);
1918
1919         Label* pLabelTitle = new (std::nothrow) Label();
1920         pLabelTitle->Construct(Rectangle(0, 0, W_TITLE_LABEL, pBirthdayItem->GetHeight()), L"");
1921         pLabelTitle->SetText(ResourceManager::GetString(L"IDS_PB_BODY_BIRTHDAY"));
1922         pLabelTitle->SetTextHorizontalAlignment(ALIGNMENT_LEFT);
1923         pLabelTitle->SetTextColor(COLOR_ITEM_TITLE);
1924         pLabelTitle->SetTextConfig(FONT_SIZE_TITLE_TEXT, LABEL_TEXT_STYLE_BOLD);
1925
1926         pBirthdayItem->AddControl(*pLabelTitle);
1927         pBirthdayItem->AddControl(*pBirthday);
1928
1929         Button* pClearButton = new (std::nothrow) Button();
1930         pClearButton->Construct(Rectangle(itemWidth - (H_BUTTON * 2), (pBirthdayItem->GetHeight() - H_BUTTON) / 2, H_BUTTON, H_BUTTON));
1931         pClearButton->SetActionId(IDA_BUTTON_BIRTHDAY_CLEAR);
1932         pClearButton->AddActionEventListener(*this);
1933
1934         Bitmap* pBitmap = ResourceManager::GetBitmapN(IDB_BUTTON_RESET_NORMAL);
1935         if (pBitmap != null)
1936         {
1937                 pClearButton->SetNormalBitmap(Point(0, 0), *pBitmap);
1938                 delete pBitmap;
1939         }
1940         pBitmap = ResourceManager::GetBitmapN(IDB_BUTTON_RESET_PRESSED);
1941         if (pBitmap != null)
1942         {
1943                 pClearButton->SetPressedBitmap(Point(0, 0), *pBitmap);
1944                 delete pBitmap;
1945         }
1946
1947         pBirthdayItem->AddControl(*pClearButton);
1948
1949         return pBirthdayItem;
1950 }
1951
1952 Tizen::Ui::Controls::TableViewItem*
1953 ContactEditorForm::GetNoteField(int itemWidth)
1954 {
1955         if (__pNoteFieldItem != null)
1956         {
1957                 return __pNoteFieldItem;
1958         }
1959
1960         __pNoteFieldItem = new (std::nothrow) TableViewItem();
1961         __pNoteFieldItem->Construct(Dimension(itemWidth, H_DOUBLE_LINE_ITEM), TABLE_VIEW_ANNEX_STYLE_NORMAL);
1962         __pNoteFieldItem->SetBackgroundColor(Color(0), TABLE_VIEW_ITEM_DRAWING_STATUS_PRESSED);
1963
1964         ExpandableEditArea* pNoteEditArea = new (std::nothrow) ExpandableEditArea();
1965         pNoteEditArea->Construct(Rectangle(0, 0, itemWidth, H_DOUBLE_LINE_ITEM), EXPANDABLE_EDIT_AREA_STYLE_NORMAL, EXPANDABLE_EDIT_AREA_TITLE_STYLE_TOP);
1966         pNoteEditArea->SetTitleText(ResourceManager::GetString(L"IDS_PB_BODY_NOTE"));
1967         pNoteEditArea->SetText(__pPresentationModel->GetValue(DETAIL_PROPERTY_NOTE));
1968         pNoteEditArea->AddExpandableEditAreaEventListener(*this);
1969         pNoteEditArea->AddKeypadEventListener(*this);
1970         pNoteEditArea->AddFocusEventListener(*this);
1971
1972         __pNoteFieldItem->AddControl(*pNoteEditArea);
1973
1974         return __pNoteFieldItem;
1975 }
1976
1977 Tizen::Ui::Controls::TableViewItem*
1978 ContactEditorForm::GetRingtoneField(int itemWidth)
1979 {
1980         TableViewItem* pRingtoneItem = new (std::nothrow) TableViewItem();
1981         pRingtoneItem->Construct(Dimension(itemWidth, H_DOUBLE_LINE_ITEM), TABLE_VIEW_ANNEX_STYLE_NORMAL);
1982         pRingtoneItem->SetBackgroundColor(COLOR_THUMBNAIL_BACKGROUND);
1983
1984         Label* pLabelTitle = new (std::nothrow) Label();
1985         pLabelTitle->Construct(Rectangle(0, H_GROUP_RINGTONE_TITLE_GAP, itemWidth, H_GROUP_RINGTONE_TITLE_LABEL), ResourceManager::GetString(L"IDS_PB_BODY_RINGTONE"));
1986         pLabelTitle->SetTextConfig(FONT_SIZE_TITLE_TEXT, LABEL_TEXT_STYLE_BOLD);
1987         pLabelTitle->SetTextColor(COLOR_ITEM_TITLE);
1988         pLabelTitle->SetTextHorizontalAlignment(ALIGNMENT_LEFT);
1989
1990         pRingtoneItem->AddControl(*pLabelTitle);
1991
1992         String ringtoneName =  __pPresentationModel->GetValue(DETAIL_PROPERTY_RINGTONE);
1993         String trimmedPath;
1994         int index = 0;
1995
1996         ringtoneName.LastIndexOf(L"/", ringtoneName.GetLength() - 1, index);
1997
1998         if (index != 0)
1999         {
2000                 ringtoneName.SubString(index + 1, trimmedPath);
2001         }
2002
2003         Label* pLabelRingToneName = new (std::nothrow) Label();
2004         pLabelRingToneName->Construct(Rectangle(0, H_GROUP_RINGTONE_TITLE_GAP + H_GROUP_RINGTONE_TITLE_LABEL, itemWidth, H_GROUP_RINGTONE_VALUE_LABEL), trimmedPath);
2005         pLabelRingToneName->SetTextConfig(FONT_SIZE_VALUE_TEXT, LABEL_TEXT_STYLE_NORMAL);
2006         pLabelRingToneName->SetTextHorizontalAlignment(ALIGNMENT_LEFT);
2007
2008         pRingtoneItem->AddControl(*pLabelRingToneName);
2009
2010         return pRingtoneItem;
2011 }
2012
2013 Tizen::Ui::Controls::TableViewItem*
2014 ContactEditorForm::GetMoreInformationField(int itemWidth)
2015 {
2016         TableViewItem* pMoreInformationItem = new (std::nothrow) TableViewItem();
2017         pMoreInformationItem->Construct(Dimension(itemWidth, H_DESCRIPTION_CONTAINER));
2018         pMoreInformationItem->SetBackgroundColor(Color(COLOR_TABLE_VIEW_BG), TABLE_VIEW_ITEM_DRAWING_STATUS_NORMAL);
2019         pMoreInformationItem->SetBackgroundColor(Color(COLOR_TABLE_VIEW_BG), TABLE_VIEW_ITEM_DRAWING_STATUS_PRESSED);
2020
2021         Panel* pPanel = new (std::nothrow) Panel();
2022         pPanel->Construct(Rectangle(0, -(H_DIVIDER), itemWidth, H_DESCRIPTION_CONTAINER + H_DIVIDER));
2023         pPanel->SetBackgroundColor(Color(COLOR_TABLE_VIEW_BG));
2024
2025         pMoreInformationItem->AddControl(*pPanel);
2026
2027         Button* pButtonMoreInformation = new (std::nothrow) Button();
2028         pButtonMoreInformation->Construct(Rectangle(X_MORE_INFORMATION_BUTTON, Y_MORE_INFORMATION_BUTTON, itemWidth - (X_MORE_INFORMATION_BUTTON * 2), H_BUTTON));
2029         pButtonMoreInformation->SetText(ResourceManager::GetString(L"IDS_KA_BODY_MORE_INFORMATION"));
2030         pButtonMoreInformation->SetActionId(IDA_BUTTON_MORE_INFO);
2031         pButtonMoreInformation->AddActionEventListener(*this);
2032
2033         pPanel->AddControl(*pButtonMoreInformation);
2034
2035         return pMoreInformationItem;
2036 }
2037
2038 Tizen::Ui::Controls::TableViewItem*
2039 ContactEditorForm::GetDefaultPhoneNumberItem(int itemWidth)
2040 {
2041         TableViewItem* pDefaultPhoneNumberItem = new (std::nothrow) TableViewItem();
2042         pDefaultPhoneNumberItem->Construct(Dimension(itemWidth, H_ITEM));
2043         pDefaultPhoneNumberItem->SetBackgroundColor(Color(0), TABLE_VIEW_ITEM_DRAWING_STATUS_PRESSED);
2044
2045         Button* pButtonDefaultNumber = new (std::nothrow) Button();
2046         pButtonDefaultNumber->Construct(Rectangle(X_MORE_INFORMATION_BUTTON, Y_DEFAULT_NUMBER_BUTTON, itemWidth - (X_MORE_INFORMATION_BUTTON * 2), H_BUTTON));
2047         pButtonDefaultNumber->SetText(ResourceManager::GetString(L"IDS_PB_BODY_MARK_AS_DEFAULT_NUMBER"));
2048         pButtonDefaultNumber->SetActionId(IDA_BUTTON_DEFAULT_PHONE_NUMBER);
2049         pButtonDefaultNumber->AddActionEventListener(*this);
2050
2051         pDefaultPhoneNumberItem->AddControl(*pButtonDefaultNumber);
2052
2053         return pDefaultPhoneNumberItem;
2054 }
2055
2056 result
2057 ContactEditorForm::DeleteInputField(int groupIndex, int itemIndex)
2058 {
2059         result r = E_SUCCESS;
2060         ArrayList* pFieldList = null;
2061
2062         switch (groupIndex)
2063         {
2064         case TABLE_VIEW_PHONE_NUMBER_FIELD_INDEX:
2065                 {
2066                         pFieldList = __pPhoneNumberFieldItem;
2067                 }
2068                 break;
2069         case TABLE_VIEW_EMAIL_FIELD_INDEX:
2070                 {
2071                         pFieldList = __pEmailFieldItem;
2072                 }
2073                 break;
2074         case TABLE_VIEW_ADDRESS_FIELD_INDEX:
2075                 {
2076                         pFieldList = __pAddressFieldItem;
2077                 }
2078                 break;
2079         case TABLE_VIEW_IM_ADDRESS_FIELD_INDEX:
2080                 {
2081                         pFieldList = __pImAddressFieldItem;
2082                 }
2083                 break;
2084         case TABLE_VIEW_URL_FIELD_INDEX:
2085                 {
2086                         pFieldList = __pUrlFieldItem;
2087                 }
2088                 break;
2089         default:
2090                 break;
2091         }
2092
2093         TryReturn(pFieldList != null, E_FAILURE, "[E_FAILURE] Unable to delete the item.")
2094
2095         r = pFieldList->RemoveAt(itemIndex, false);
2096         __isDataRemoved = true;
2097         __pTableView->RefreshItem(groupIndex, itemIndex, TABLE_VIEW_REFRESH_TYPE_ITEM_REMOVE);
2098         __isDataRemoved = false;
2099
2100         Rectangle clientBounds = GetClientAreaBounds();
2101         __pTableView->SetSize(clientBounds.width, clientBounds.height);
2102
2103         for (int i = itemIndex; i < pFieldList->GetCount(); i++)
2104         {
2105                 TableViewItem* pItem = static_cast<TableViewItem *>(pFieldList->GetAt(i));
2106                 if (pItem == null)
2107                 {
2108                         return E_FAILURE;
2109                 }
2110
2111                 int parsedIndex;
2112                 EditField* pInputField = static_cast<EditField*>(pItem->GetControl(0));
2113                 if (pInputField == null)
2114                 {
2115                         return E_FAILURE;
2116                 }
2117
2118                 result r = Integer::Decode(pInputField->GetName(), parsedIndex);
2119                 if (r == E_NUM_FORMAT)
2120                 {
2121                         return E_FAILURE;
2122                 }
2123                 pInputField->SetName(Integer::ToString(parsedIndex - 1));
2124
2125                 Button* pTypeButton = static_cast<Button*>(pItem->GetControl(1));
2126                 if (pTypeButton == null)
2127                 {
2128                         return E_FAILURE;
2129                 }
2130
2131                 r = Integer::Decode(pTypeButton->GetName(), parsedIndex);
2132                 if (r == E_NUM_FORMAT)
2133                 {
2134                         return E_FAILURE;
2135                 }
2136                 pTypeButton->SetName(Integer::ToString(parsedIndex - 1));
2137
2138                 Button* pDeleteButton = static_cast<Button *>(pItem->GetControl(2));
2139                 if (pDeleteButton == null)
2140                 {
2141                         return E_FAILURE;
2142                 }
2143                 pDeleteButton->SetActionId(pDeleteButton->GetActionId() - 1);
2144         }
2145
2146         SaveContactData(false);
2147         SetSaveButtonEnabled(IsSaveContactValid());
2148         
2149         if (groupIndex == TABLE_VIEW_PHONE_NUMBER_FIELD_INDEX)
2150         {
2151                 if (itemIndex == __pPresentationModel->GetDefaultNumberIndex())
2152                 {
2153                         if (itemIndex > 0)
2154                         {
2155                                 SetAsDefaultPhoneNumber(itemIndex - 1);
2156                         }
2157                         else
2158                         {
2159                                 SetAsDefaultPhoneNumber(itemIndex);
2160                         }
2161                 }
2162                 else if (itemIndex < __pPresentationModel->GetDefaultNumberIndex())
2163                 {
2164                         SetAsDefaultPhoneNumber(__pPresentationModel->GetDefaultNumberIndex() - 1);
2165                 }
2166         }
2167
2168         if (__isDefaultPhoneNumberButtonEnabled == true && __pPresentationModel->GetMultiValuesCount(DETAIL_PROPERTY_PHONE_NUMBER) < 2)
2169         {
2170                 __pTableView->RefreshItem(TABLE_VIEW_PHONE_NUMBER_FIELD_INDEX, __pTableView->GetItemCountAt(TABLE_VIEW_PHONE_NUMBER_FIELD_INDEX) - 1, TABLE_VIEW_REFRESH_TYPE_ITEM_REMOVE);
2171
2172                 __isDefaultPhoneNumberButtonEnabled = false;
2173         }
2174
2175         return r;
2176 }
2177
2178 void
2179 ContactEditorForm::SetThumbnailControls(Tizen::Ui::Controls::TableViewItem& item, bool isUpdated)
2180 {
2181         Label* pLabelThumbnail = null;
2182         Button* pButtonAdd = null;
2183         Button* pButtonDelete = null;
2184
2185         if (isUpdated == false)
2186         {
2187                 int itemWidth = GetBounds().width;
2188
2189                 pLabelThumbnail = new (std::nothrow) Label();
2190                 pLabelThumbnail->Construct(Rectangle((itemWidth - W_THUMBNAIL) / 2, 0, W_THUMBNAIL, W_THUMBNAIL), L"");
2191
2192                 item.AddControl(*pLabelThumbnail);
2193
2194                 Bitmap* pBitmapItem = null;
2195                 Bitmap* pBitmapItemPressed = null;
2196
2197                 pButtonAdd = new (std::nothrow) Button();
2198                 pButtonAdd->Construct(Rectangle(pLabelThumbnail->GetX() + ((pLabelThumbnail->GetWidth() - H_BUTTON) / 2), pLabelThumbnail->GetY() + ((pLabelThumbnail->GetHeight() - H_BUTTON) / 2), H_BUTTON, H_BUTTON));
2199                 pButtonAdd->SetActionId(IDA_BUTTON_THUMBNAIL_ADD);
2200                 pButtonAdd->AddActionEventListener(*this);
2201
2202                 pBitmapItem = ResourceManager::GetBitmapN(IDB_BUTTON_ADD);
2203                 pBitmapItemPressed = ResourceManager::GetBitmapN(IDB_BUTTON_ADD_PRESSED);
2204
2205                 if (pBitmapItem != null)
2206                 {
2207                         pButtonAdd->SetNormalBackgroundBitmap(*pBitmapItem);
2208                         delete pBitmapItem;
2209                 }
2210                 if (pBitmapItemPressed != null)
2211                 {
2212                         pButtonAdd->SetPressedBackgroundBitmap(*pBitmapItemPressed);
2213                         delete pBitmapItemPressed;
2214                 }
2215                 item.AddControl(*pButtonAdd);
2216
2217                 pButtonDelete = new (std::nothrow) Button();
2218                 pButtonDelete->Construct(Rectangle(pLabelThumbnail->GetX() + W_THUMBNAIL_DELETE_BUTTON_GAP, pLabelThumbnail->GetY() + H_THUMBNAIL_DELETE_BUTTON_GAP, H_BUTTON, H_BUTTON));
2219                 pButtonDelete->SetActionId(IDA_BUTTON_THUMBNAIL_DELETE);
2220                 pButtonDelete->AddActionEventListener(*this);
2221
2222                 pBitmapItem = ResourceManager::GetBitmapN(IDB_BUTTON_MINUS);
2223                 pBitmapItemPressed = ResourceManager::GetBitmapN(IDB_BUTTON_MINUS_PRESSED);
2224
2225                 if (pBitmapItem != null)
2226                 {
2227                         pButtonDelete->SetNormalBitmap(Point(0, 0), *pBitmapItem);
2228                         delete pBitmapItem;
2229                 }
2230                 if (pBitmapItemPressed != null)
2231                 {
2232                         pButtonDelete->SetPressedBitmap(Point(0, 0), *pBitmapItemPressed);
2233                         delete pBitmapItemPressed;
2234                 }
2235
2236                 pBitmapItem = ResourceManager::GetBitmapN(IDB_BUTTON_DELETE_NORMAL);
2237                 pBitmapItemPressed = ResourceManager::GetBitmapN(IDB_BUTTON_DELETE_PRESSED);
2238
2239                 if (pBitmapItem != null)
2240                 {
2241                         pButtonDelete->SetNormalBackgroundBitmap(*pBitmapItem);
2242                         delete pBitmapItem;
2243                 }
2244                 if (pBitmapItemPressed != null)
2245                 {
2246                         pButtonDelete->SetPressedBackgroundBitmap(*pBitmapItemPressed);
2247                         delete pBitmapItemPressed;
2248                 }
2249                 item.AddControl(*pButtonDelete);
2250
2251                 Button* pButtonCamera = new (std::nothrow) Button();
2252                 pButtonCamera->Construct(Rectangle(pLabelThumbnail->GetX() + pLabelThumbnail->GetWidth(), pLabelThumbnail->GetY() + pLabelThumbnail->GetHeight() - H_BUTTON, H_BUTTON, H_BUTTON));
2253                 pButtonCamera->SetActionId(IDA_BUTTON_CAMERA);
2254                 pButtonCamera->AddActionEventListener(*this);
2255
2256                 pBitmapItem = ResourceManager::GetBitmapN(IDB_BUTTON_CAMERA);
2257                 pBitmapItemPressed = ResourceManager::GetBitmapN(IDB_BUTTON_CAMERA_PRESSED);
2258                 if (pBitmapItem != null)
2259                 {
2260                         pButtonCamera->SetNormalBackgroundBitmap(*pBitmapItem);
2261                         delete pBitmapItem;
2262                 }
2263                 if (pBitmapItemPressed != null)
2264                 {
2265                         pButtonCamera->SetPressedBackgroundBitmap(*pBitmapItemPressed);
2266                         delete pBitmapItemPressed;
2267                 }
2268
2269                 item.AddControl(*pButtonCamera);
2270         }
2271         else
2272         {
2273                 pLabelThumbnail = static_cast<Label*>(item.GetControl(0));
2274                 TryReturnVoid(pLabelThumbnail != null, "[E_FAILURE] Unable to get a thumbnail control.");
2275
2276                 pButtonAdd = static_cast<Button*>(item.GetControl(1));
2277                 TryReturnVoid(pButtonAdd != null, "[E_FAILURE] Unable to get a button.");
2278
2279                 pButtonDelete = static_cast<Button*>(item.GetControl(2));
2280                 TryReturnVoid(pButtonDelete != null, "[E_FAILURE] Unable to get a button.");
2281         }
2282
2283         Bitmap* pThumbnail = null;
2284         String thumbnailPath = __pPresentationModel->GetValue(DETAIL_PROPERTY_THUMBNAIL);
2285
2286         if (thumbnailPath.IsEmpty() == false)
2287         {
2288                 ImageBuffer thumbnailImageBuffer;
2289                 result r = thumbnailImageBuffer.Construct(thumbnailPath);
2290                 if (r == E_SUCCESS)
2291                 {
2292                         pThumbnail = thumbnailImageBuffer.GetBitmapN(BITMAP_PIXEL_FORMAT_ARGB8888, BUFFER_SCALING_NONE);
2293                 }
2294                 if (pThumbnail != null)
2295                 {
2296                         pThumbnail->SetScalingQuality(BITMAP_SCALING_QUALITY_HIGH);
2297                         pThumbnail->Scale(Dimension(W_THUMBNAIL, W_THUMBNAIL));
2298                         pLabelThumbnail->SetBackgroundBitmap(*pThumbnail);
2299                         pButtonAdd->SetShowState(false);
2300                         pButtonDelete->SetShowState(true);
2301                 }
2302         }
2303         else
2304         {
2305                 pThumbnail = ResourceManager::GetBitmapN(IDB_THUMBNAIL_BACKGROUND);
2306                 if (pThumbnail != null)
2307                 {
2308                         pLabelThumbnail->SetBackgroundBitmap(*pThumbnail);
2309                         pButtonAdd->SetShowState(true);
2310                         pButtonDelete->SetShowState(false);
2311                 }
2312         }
2313
2314         delete pThumbnail;
2315 }
2316
2317 void
2318 ContactEditorForm::AddHorizontalDivider(Tizen::Ui::Controls::TableViewItem* pItem, int positionY, int width)
2319 {
2320         Label* pDivider = new (std::nothrow) Label();
2321         pDivider->Construct(Rectangle(0, positionY, width, H_DIVIDER), L"");
2322         pDivider->SetBackgroundColor(Color(COLOR_DIVIDER));
2323         pDivider->SetEnabled(false);
2324
2325         pItem->AddControl(*pDivider);
2326 }
2327
2328 void
2329 ContactEditorForm::AddVerticalDivider(Tizen::Ui::Controls::TableViewItem* pItem, int positionX, int positionY)
2330 {
2331         Label* pDivider = new (std::nothrow) Label();
2332         pDivider->Construct(Rectangle(positionX, positionY, W_DIVIDER, H_ITEM), L"");
2333         pDivider->SetBackgroundColor(Color(COLOR_DIVIDER));
2334         pDivider->SetEnabled(false);
2335
2336         pItem->AddControl(*pDivider);
2337 }
2338
2339 result
2340 ContactEditorForm::SetAsDefaultPhoneNumber(int index)
2341 {
2342         result r = E_SUCCESS;
2343         TableViewItem* pItem = null;
2344         EditField* pEditField = null;
2345         int previousDefaultIndex = __pPresentationModel->GetDefaultNumberIndex();
2346
2347         pItem = static_cast<TableViewItem *>(__pPhoneNumberFieldItem->GetAt(previousDefaultIndex));
2348         if (pItem == null)
2349         {
2350                 r = E_FAILURE;
2351                 goto CATCH;
2352         }
2353
2354         pEditField = static_cast<EditField *>(pItem->GetControl(0));
2355         if (pEditField == null)
2356         {
2357                 r = E_FAILURE;
2358                 goto CATCH;
2359         }
2360
2361         pEditField->SetTextColor(EDIT_TEXT_COLOR_NORMAL, Color(0xFF000000));
2362         pEditField->SetTextColor(EDIT_TEXT_COLOR_HIGHLIGHTED, Color(0xFF000000));
2363
2364         if (pEditField->IsVisible() == false)
2365         {
2366                 __pTableView->ScrollToItem(TABLE_VIEW_PHONE_NUMBER_FIELD_INDEX, previousDefaultIndex);
2367         }
2368         pEditField->Invalidate(true);
2369
2370         pItem = static_cast<TableViewItem *>(__pPhoneNumberFieldItem->GetAt(index));
2371         if (pItem == null)
2372         {
2373                 r = E_FAILURE;
2374                 goto CATCH;
2375         }
2376
2377         pEditField = static_cast<EditField *>(pItem->GetControl(0));
2378         if (pEditField == null)
2379         {
2380                 r = E_FAILURE;
2381                 goto CATCH;
2382         }
2383
2384         __pPresentationModel->SetValue(DETAIL_PROPERTY_DEFAULT_PHONE_NUMBER, L"", index);
2385         pEditField->SetTextColor(EDIT_TEXT_COLOR_NORMAL, Color(0xFFFF00FF));
2386         pEditField->SetTextColor(EDIT_TEXT_COLOR_HIGHLIGHTED, Color(0xFFFF00FF));
2387
2388         if (pEditField->IsVisible() == false)
2389         {
2390                 __pTableView->ScrollToItem(TABLE_VIEW_PHONE_NUMBER_FIELD_INDEX, index);
2391         }
2392         pEditField->Invalidate(true);
2393
2394 CATCH:
2395         return r;
2396 }
2397
2398 result
2399 ContactEditorForm::ChangeNameFieldStatus(void)
2400 {
2401         result r = E_SUCCESS;
2402
2403         r = SaveNameFields();
2404
2405         __isExpandable = (__isExpandable == true) ? false : true;
2406
2407         return r;
2408 }
2409
2410 result
2411 ContactEditorForm::SaveContactData(bool isSaved)
2412 {
2413         result r = E_SUCCESS;
2414
2415         r = SaveNameFields();
2416
2417         for (int i = 0; i < __pPhoneNumberFieldItem->GetCount(); i++)
2418         {
2419                 TableViewItem* pItem = static_cast<TableViewItem *>(__pPhoneNumberFieldItem->GetAt(i));
2420                 if (pItem == null)
2421                 {
2422                         r = E_FAILURE;
2423                         break;
2424                 }
2425
2426                 EditField* pEditField = static_cast<EditField *>(pItem->GetControl(0));
2427                 if (pEditField == null)
2428                 {
2429                         r = E_FAILURE;
2430                         break;
2431                 }
2432
2433                 String phoneNumberString(pEditField->GetText());
2434                 String phoneNumberTypeString(pItem->GetName());
2435                 int phoneNumberType;
2436
2437                 phoneNumberString.Trim();
2438                 Integer::Parse(phoneNumberTypeString, phoneNumberType);
2439
2440                 __pPresentationModel->SetPhoneNumber((DetailPhoneNumberType)phoneNumberType, phoneNumberString, i);
2441         }
2442
2443         for (int i = 0; i < __pEmailFieldItem->GetCount(); i++)
2444         {
2445                 TableViewItem* pItem = static_cast<TableViewItem *>(__pEmailFieldItem->GetAt(i));
2446                 if (pItem == null)
2447                 {
2448                         r = E_FAILURE;
2449                         break;
2450                 }
2451
2452                 EditField* pEditField = static_cast<EditField *>(pItem->GetControl(0));
2453                 if (pEditField == null)
2454                 {
2455                         r = E_FAILURE;
2456                         break;
2457                 }
2458
2459                 String emailString(pEditField->GetText());
2460                 String emailTypeString(pItem->GetName());
2461                 int emailType;
2462
2463                 emailString.Trim();
2464                 Integer::Parse(emailTypeString, emailType);
2465
2466                 r = __pPresentationModel->SetEmail((DetailEmailType)emailType, emailString, i);
2467
2468                 if (isSaved == true && r == E_SUCCESS)
2469                 {
2470                         int existedAtIndex;
2471                         int existedDotIndex;
2472
2473                         r = emailString.IndexOf(CHARACTER_AT, 0, existedAtIndex);
2474                         if (r == E_SUCCESS)
2475                         {
2476                                 r = emailString.IndexOf(CHARACTER_DOT, existedAtIndex + 2, existedDotIndex);
2477                         }
2478
2479                         if (r != E_SUCCESS || emailString.GetLength() == (existedDotIndex + 1))
2480                         {
2481                                 int modalResult;
2482                                 MessageBox invalidEmailMessage;
2483                                 invalidEmailMessage.Construct(L"", ResourceManager::GetString(L"IDS_PB_POP_INVALID_EMAIL_ADDRESS"), MSGBOX_STYLE_OK);
2484                                 invalidEmailMessage.ShowAndWait(modalResult);
2485
2486                                 pEditField->ShowKeypad();
2487
2488                                 return E_FAILURE;
2489                         }
2490                 }
2491         }
2492
2493         for (int i = 0; i < __pAddressFieldItem->GetCount(); i++)
2494         {
2495                 TableViewItem* pItem = static_cast<TableViewItem *>(__pAddressFieldItem->GetAt(i));
2496                 if (pItem == null)
2497                 {
2498                         r = E_FAILURE;
2499                         break;
2500                 }
2501
2502                 EditField* pEditField = static_cast<EditField *>(pItem->GetControl(0));
2503                 if (pEditField == null)
2504                 {
2505                         r = E_FAILURE;
2506                         break;
2507                 }
2508
2509                 String addressString(pEditField->GetText());
2510
2511                 addressString.Trim();
2512                 __pPresentationModel->SetValue(DETAIL_PROPERTY_ADDRESS_STREET, addressString, i);
2513         }
2514
2515         for (int i = 0; i < __pImAddressFieldItem->GetCount(); i++)
2516         {
2517                 TableViewItem* pItem = static_cast<TableViewItem *>(__pImAddressFieldItem->GetAt(i));
2518                 if (pItem == null)
2519                 {
2520                         r = E_FAILURE;
2521                         break;
2522                 }
2523
2524                 EditField* pEditField = static_cast<EditField *>(pItem->GetControl(0));
2525                 if (pEditField == null)
2526                 {
2527                         r = E_FAILURE;
2528                         break;
2529                 }
2530
2531                 String addressString(pEditField->GetText());
2532                 String addressTypeString(pItem->GetName());
2533                 int addressType;
2534
2535                 addressString.Trim();
2536                 Integer::Parse(addressTypeString, addressType);
2537
2538                 __pPresentationModel->SetImAddress((DetailImAddressType)addressType, addressString, i);
2539         }
2540
2541         for (int i = 0; i < __pUrlFieldItem->GetCount(); i++)
2542         {
2543                 TableViewItem* pItem = static_cast<TableViewItem *>(__pUrlFieldItem->GetAt(i));
2544                 if (pItem == null)
2545                 {
2546                         r = E_FAILURE;
2547                         break;
2548                 }
2549
2550                 EditField* pEditField = static_cast<EditField *>(pItem->GetControl(0));
2551                 if (pEditField == null)
2552                 {
2553                         r = E_FAILURE;
2554                         break;
2555                 }
2556
2557                 String urlString(pEditField->GetText());
2558                 String urlTypeString(pItem->GetName());
2559                 int urlType;
2560
2561                 urlString.Trim();
2562                 Integer::Parse(urlTypeString, urlType);
2563
2564                 __pPresentationModel->SetUrl((DetailUrlType)urlType, urlString, i);
2565         }
2566
2567         if (__pNoteFieldItem != null)
2568         {
2569                 String noteString;
2570                 ExpandableEditArea* pNoteEditArea = static_cast<ExpandableEditArea *>(__pNoteFieldItem->GetControl(0));
2571                 if (pNoteEditArea != null)
2572                 {
2573                         noteString.Append(pNoteEditArea->GetText());
2574                 }
2575
2576                 __pPresentationModel->SetValue(DETAIL_PROPERTY_NOTE, noteString);
2577         }
2578
2579         if (isSaved == true)
2580         {
2581                 r = __pPresentationModel->AddAddressBook();
2582         }
2583
2584         return r;
2585 }
2586
2587 result
2588 ContactEditorForm::SaveNameFields(void)
2589 {
2590         result r = E_SUCCESS;
2591
2592         if (__pNameFieldItem == null)
2593         {
2594                 return E_FAILURE;
2595         }
2596
2597         if (__isExpandable == true)
2598         {
2599                 EditField* pFirstName = static_cast<EditField *>(__pNameFieldItem->GetControl(ResourceManager::GetString(L"IDS_PB_BODY_FIRST_NAME"), false));
2600                 if (pFirstName == null)
2601                 {
2602                         return E_FAILURE;
2603                 }
2604                 __pPresentationModel->SetValue(DETAIL_PROPERTY_FIRST_NAME, pFirstName->GetText());
2605
2606                 EditField* pLastName = static_cast<EditField *>(__pNameFieldItem->GetControl(ResourceManager::GetString(L"IDS_PB_BODY_LAST_NAME"), false));
2607                 if (pLastName == null)
2608                 {
2609                         return E_FAILURE;
2610                 }
2611
2612                 __pPresentationModel->SetValue(DETAIL_PROPERTY_LAST_NAME, pLastName->GetText());
2613
2614                 EditField* pMiddleName = static_cast<EditField *>(__pNameFieldItem->GetControl(ResourceManager::GetString(L"IDS_PB_BODY_MIDDLE_NAME"), false));
2615                 if (pMiddleName == null)
2616                 {
2617                         return E_FAILURE;
2618                 }
2619                 __pPresentationModel->SetValue(DETAIL_PROPERTY_MIDDLE_NAME, pMiddleName->GetText());
2620
2621                 EditField* pSuffix = static_cast<EditField *>(__pNameFieldItem->GetControl(ResourceManager::GetString(L"IDS_PB_BODY_SUFFIX"), false));
2622                 if (pSuffix == null)
2623                 {
2624                         return E_FAILURE;
2625                 }
2626                 __pPresentationModel->SetValue(DETAIL_PROPERTY_NAME_SUFFIX, pSuffix->GetText());
2627
2628                 EditField* pNickName = static_cast<EditField *>(__pNameFieldItem->GetControl(ResourceManager::GetString(L"IDS_PB_BODY_NICKNAME"), false));
2629                 if (pNickName == null)
2630                 {
2631                         return E_FAILURE;
2632                 }
2633                 __pPresentationModel->SetValue(DETAIL_PROPERTY_NICK_NAME, pNickName->GetText());
2634
2635                 EditField* pCompanyName = static_cast<EditField *>(__pNameFieldItem->GetControl(ResourceManager::GetString(L"IDS_PB_BODY_COMPANY"), false));
2636                 if (pCompanyName == null)
2637                 {
2638                         return E_FAILURE;
2639                 }
2640                 __pPresentationModel->SetValue(DETAIL_PROPERTY_COMPANY, pCompanyName->GetText());
2641
2642                 if (__isJobTitleEnabled == true)
2643                 {
2644                         EditField* pJobTitle = static_cast<EditField *>(__pNameFieldItem->GetControl(ResourceManager::GetString(L"IDS_PB_BODY_JOB_TITLE"), false));
2645                         if (pJobTitle == null)
2646                         {
2647                                 return E_FAILURE;
2648                         }
2649                         __pPresentationModel->SetValue(DETAIL_PROPERTY_JOB_TITLE, pJobTitle->GetText());
2650                 }
2651
2652                 if (__isDepartmentEnabled == true)
2653                 {
2654                         EditField* pDepartment = static_cast<EditField *>(__pNameFieldItem->GetControl(ResourceManager::GetString(L"IDS_PB_BODY_DEPARTMENT"), false));
2655                         if (pDepartment == null)
2656                         {
2657                                 return E_FAILURE;
2658                         }
2659                         __pPresentationModel->SetValue(DETAIL_PROPERTY_DEPARTMENT, pDepartment->GetText());
2660                 }
2661         }
2662         else
2663         {
2664                 EditField* pName = static_cast<EditField *>(__pNameFieldItem->GetControl(Integer::ToString(IDA_INPUT_FIELD_DISPLAY_NAME), false));
2665                 if (pName == null)
2666                 {
2667                         return E_FAILURE;
2668                 }
2669
2670                 String displayName(pName->GetText());
2671                 String firstName;
2672                 String lastName;
2673                 int delimeterIndex;
2674
2675                 displayName.IndexOf(CHARACTER_SPACE, 0, delimeterIndex);
2676
2677                 if (delimeterIndex < 0)
2678                 {
2679                         firstName.Append(displayName);
2680                 }
2681                 else
2682                 {
2683                         displayName.SubString(0, delimeterIndex++, firstName);
2684                         displayName.SubString(delimeterIndex, displayName.GetLength() - delimeterIndex, lastName);
2685                 }
2686
2687                 __pPresentationModel->SetValue(DETAIL_PROPERTY_FIRST_NAME, firstName);
2688                 __pPresentationModel->SetValue(DETAIL_PROPERTY_LAST_NAME, lastName);
2689         }
2690
2691         return r;
2692 }
2693
2694 bool
2695 ContactEditorForm::IsSaveContactValid(void)
2696 {
2697         if (__pPresentationModel->GetValue(DETAIL_PROPERTY_FIRST_NAME).IsEmpty() == false)
2698         {
2699                 return true;
2700         }
2701
2702         if (__pPresentationModel->GetValue(DETAIL_PROPERTY_LAST_NAME).IsEmpty() == false)
2703         {
2704                 return true;
2705         }
2706
2707         for (int i = 0; i < __pPresentationModel->GetMultiValuesCount(DETAIL_PROPERTY_PHONE_NUMBER); i++)
2708         {
2709                 if (__pPresentationModel->GetValue(DETAIL_PROPERTY_PHONE_NUMBER, i).IsEmpty() == false)
2710                 {
2711                         return true;
2712                 }
2713         }
2714
2715         for (int i = 0; i < __pPresentationModel->GetMultiValuesCount(DETAIL_PROPERTY_EMAIL); i++)
2716         {
2717                 if (__pPresentationModel->GetValue(DETAIL_PROPERTY_EMAIL, i).IsEmpty() == false)
2718                 {
2719                         return true;
2720                 }
2721         }
2722
2723         return false;
2724 }
2725
2726 void
2727 ContactEditorForm::SetSaveButtonEnabled(bool enable)
2728 {
2729         Footer* pFooter = GetFooter();
2730
2731         if (enable)
2732         {
2733                 pFooter->SetItemEnabled(0, true);
2734         }
2735         else
2736         {
2737                 pFooter->SetItemEnabled(0, false);
2738         }
2739
2740         pFooter->Invalidate(true);
2741 }
2742
2743 bool
2744 ContactEditorForm::IsMoreInformationButtonVisible(void)
2745 {
2746         if (__isJobTitleEnabled == false)
2747         {
2748                 return true;
2749         }
2750
2751         if (__isDepartmentEnabled == false)
2752         {
2753                 return true;
2754         }
2755
2756         if (__pImAddressFieldItem->GetCount() == 0)
2757         {
2758                 return true;
2759         }
2760
2761         if (__pUrlFieldItem->GetCount() == 0)
2762         {
2763                 return true;
2764         }
2765
2766         DateTime birthday;
2767         if (__pPresentationModel->GetBirthday(birthday) != E_SUCCESS)
2768         {
2769                 return true;
2770         }
2771
2772         if (__pNoteFieldItem == null)
2773         {
2774                 return true;
2775         }
2776
2777         return false;
2778 }
2779
2780 void
2781 ContactEditorForm::OnTextValueChanged(const Tizen::Ui::Control& source)
2782 {
2783         TableViewItem* pTableViewItem = static_cast<TableViewItem *>(source.GetParent());
2784
2785         if (pTableViewItem == null)
2786         {
2787                 return;
2788         }
2789
2790         SaveContactData(false);
2791         SetSaveButtonEnabled(IsSaveContactValid());
2792
2793         if (__pNameFieldItem == pTableViewItem)
2794         {
2795                 return;
2796         }
2797
2798         EditField* pEditField = const_cast<EditField *>(static_cast<const EditField *>(&source));
2799         if (pEditField == null)
2800         {
2801                 return;
2802         }
2803
2804         Control* pDeleteButton = pTableViewItem->GetControl(2);
2805         if (pDeleteButton == null)
2806         {
2807                 return;
2808         }
2809
2810         String trimmedString = pEditField->GetText();
2811         trimmedString.Trim();
2812
2813         if (trimmedString.IsEmpty())
2814         {
2815                 pDeleteButton->SetShowState(false);
2816
2817                 return;
2818         }
2819
2820         if (pDeleteButton->GetShowState())
2821         {
2822                 return;
2823         }
2824
2825         pDeleteButton->SetShowState(true);
2826
2827         int index;
2828         int groupIndex;
2829         int itemCount;
2830
2831         Integer::Decode(pEditField->GetName(), index);
2832         groupIndex = (index & TABLE_VIEW_GROUP_INDEX_MASK) >> TABLE_VIEW_GROUP_INDEX_SHIFT;
2833         itemCount = __pTableView->GetItemCountAt(groupIndex);
2834         if (groupIndex == TABLE_VIEW_PHONE_NUMBER_FIELD_INDEX)
2835         {
2836                 if (__isDefaultPhoneNumberButtonEnabled == false && __pPresentationModel->GetMultiValuesCount(DETAIL_PROPERTY_PHONE_NUMBER) > 1)
2837                 {
2838                         __isDefaultPhoneNumberButtonEnabled = true;
2839                         __pTableView->RefreshItem(groupIndex, __pTableView->GetItemCountAt(groupIndex), TABLE_VIEW_REFRESH_TYPE_ITEM_ADD);
2840                 }
2841                 else if (itemCount > 1)
2842                 {
2843                         itemCount--;
2844                 }
2845         }
2846         __pTableView->RefreshItem(groupIndex, itemCount, TABLE_VIEW_REFRESH_TYPE_ITEM_ADD);
2847 }
2848
2849 void
2850 ContactEditorForm::OnTextValueChangeCanceled(const Tizen::Ui::Control& source)
2851 {
2852 }
2853
2854 result
2855 ContactEditorForm::ParseAppControlArgument(const Tizen::Base::String& argument, Tizen::Base::String& type, Tizen::Base::String& content)
2856 {
2857         result r = E_SUCCESS;
2858
2859         if (argument.IsEmpty() || argument.Contains(DELIMITER) == false)
2860         {
2861                 return E_FAILURE;
2862         }
2863
2864         int delimiterIndex;
2865
2866         argument.IndexOf(DELIMITER, 0, delimiterIndex);
2867         argument.SubString(0, delimiterIndex++, type);
2868         TryReturn(r == E_SUCCESS, r, "[%s] Unable to get type", GetErrorMessage(r));
2869         argument.SubString(delimiterIndex, argument.GetLength() - delimiterIndex, content);
2870         TryReturn(r == E_SUCCESS, r, "[%s] Unable to get type", GetErrorMessage(r));
2871
2872         return r;
2873 }
2874
2875 void
2876 ContactEditorForm::OnFocusGained(const Tizen::Ui::Control& source)
2877 {
2878         __pCurrentFocusedItem = source.GetParent();
2879
2880         if (__pCurrentFocusedItem == __pNameFieldItem)
2881         {
2882                 return;
2883         }
2884
2885         ArrayList* pFieldList = null;
2886         int groupIndex;
2887         int itemIndex;
2888
2889         const EditField* pEditField = static_cast<const EditField*>(&source);
2890         if (pEditField != null)
2891         {
2892                 int index;
2893
2894                 Integer::Decode(pEditField->GetName(), index);
2895                 groupIndex = (index & TABLE_VIEW_GROUP_INDEX_MASK) >> TABLE_VIEW_GROUP_INDEX_SHIFT;
2896                 itemIndex = (index & TABLE_VIEW_ITEM_INDEX_MASK);
2897         }
2898
2899         switch (groupIndex)
2900         {
2901         case TABLE_VIEW_PHONE_NUMBER_FIELD_INDEX:
2902                 {
2903                         pFieldList = __pPhoneNumberFieldItem;
2904                 }
2905                 break;
2906         case TABLE_VIEW_EMAIL_FIELD_INDEX:
2907                 {
2908                         pFieldList = __pEmailFieldItem;
2909                 }
2910                 break;
2911         case TABLE_VIEW_ADDRESS_FIELD_INDEX:
2912                 {
2913                         pFieldList = __pAddressFieldItem;
2914                 }
2915                 break;
2916         case TABLE_VIEW_IM_ADDRESS_FIELD_INDEX:
2917                 {
2918                         pFieldList = __pImAddressFieldItem;
2919                 }
2920                 break;
2921         case TABLE_VIEW_URL_FIELD_INDEX:
2922                 {
2923                         pFieldList = __pUrlFieldItem;
2924                 }
2925                 break;
2926         default:
2927                 break;
2928         }
2929
2930         TryReturnVoid(pFieldList != null, "[E_FAILURE] Unable to get a input field.");
2931
2932         for (int i = pFieldList->GetCount() - 2; i >= 0; i--)
2933         {
2934                 TableViewItem* pTableViewItem = static_cast<TableViewItem*>(pFieldList->GetAt(i));
2935                 if (pTableViewItem != null)
2936                 {
2937                         EditField* pInputField = static_cast<EditField*>(pTableViewItem->GetControl(0));
2938                         if (i != itemIndex && pInputField != null && pInputField->GetTextLength() == 0)
2939                         {
2940                                 DeleteInputField(groupIndex, i);
2941                         }
2942                 }
2943         }
2944 }
2945
2946 void
2947 ContactEditorForm::OnFocusLost(const Tizen::Ui::Control& source)
2948 {
2949         if (__pCurrentFocusedItem == __pNameFieldItem)
2950         {
2951                 SaveNameFields();
2952         }
2953
2954         __pCurrentFocusedItem = null;
2955 }
2956
2957 void
2958 ContactEditorForm::ShowDefaultPhoneNumberContextMenu(const Tizen::Graphics::Point& position)
2959 {
2960         if (__pDefaultPhoneNumberContextMenu != null)
2961         {
2962                 delete __pDefaultPhoneNumberContextMenu;
2963                 __pDefaultPhoneNumberContextMenu = null;
2964         }
2965
2966         __pDefaultPhoneNumberContextMenu = new (std::nothrow) ContextMenu();
2967         __pDefaultPhoneNumberContextMenu->Construct(position, CONTEXT_MENU_STYLE_LIST);
2968         __pDefaultPhoneNumberContextMenu->AddActionEventListener(*this);
2969
2970         int count = __pPresentationModel->GetMultiValuesCount(DETAIL_PROPERTY_PHONE_NUMBER);
2971         int defaultPhoneNumberIndex = __pPresentationModel->GetDefaultNumberIndex();
2972
2973         for (int i = 0; i < count; i++)
2974         {
2975                 String phoneNumber(__pPresentationModel->GetValue(DETAIL_PROPERTY_PHONE_NUMBER, i));
2976
2977                 if (i != defaultPhoneNumberIndex)
2978                 {
2979                         phoneNumber.Insert(__pPresentationModel->GetType(DETAIL_PROPERTY_PHONE_NUMBER, i) + CHARACTER_SPACE, 0);
2980                         __pDefaultPhoneNumberContextMenu->AddItem(phoneNumber, i);
2981                 }
2982         }
2983
2984         if (__pDefaultPhoneNumberContextMenu->GetItemCount() > 0)
2985         {
2986                 __pDefaultPhoneNumberContextMenu->Show();
2987         }
2988 }
2989
2990 void
2991 ContactEditorForm::ShowMoreInformationContextMenu(const Tizen::Graphics::Point& position)
2992 {
2993         if (__pMoreInformationContextMenu != null)
2994         {
2995                 delete __pMoreInformationContextMenu;
2996                 __pMoreInformationContextMenu = null;
2997         }
2998
2999         __pMoreInformationContextMenu = new (std::nothrow) ContextMenu();
3000         __pMoreInformationContextMenu->Construct(position, CONTEXT_MENU_STYLE_LIST);
3001
3002         __pMoreInformationContextMenu->SetMaxVisibleItemsCount(6);
3003         __pMoreInformationContextMenu->AddActionEventListener(*this);
3004
3005         if (__isJobTitleEnabled == false)
3006         {
3007                 __pMoreInformationContextMenu->AddItem(ResourceManager::GetString(L"IDS_PB_BODY_JOB_TITLE"), IDA_CONTEXT_MENU_ITEM_JOB_TITLE);
3008         }
3009
3010         if (__isDepartmentEnabled == false)
3011         {
3012                 __pMoreInformationContextMenu->AddItem(ResourceManager::GetString(L"IDS_PB_BODY_DEPARTMENT"), IDA_CONTEXT_MENU_ITEM_DEPARTMENT);
3013         }
3014
3015         if (__pImAddressFieldItem->GetCount() == 0)
3016         {
3017                 __pMoreInformationContextMenu->AddItem(ResourceManager::GetString(L"IDS_PB_HEADER_INSTANT_MESSENGER_ABB"), IDA_CONTEXT_MENU_ITEM_INSTANT_MESSENGER);
3018         }
3019
3020         if (__pUrlFieldItem->GetCount() == 0)
3021         {
3022                 __pMoreInformationContextMenu->AddItem(ResourceManager::GetString(L"IDS_PB_BODY_URL"), IDA_CONTEXT_MENU_ITEM_URL);
3023         }
3024
3025         DateTime birthday;
3026         if (__pPresentationModel->GetBirthday(birthday) != E_SUCCESS)
3027         {
3028                 __pMoreInformationContextMenu->AddItem(ResourceManager::GetString(L"IDS_PB_BODY_BIRTHDAY"), IDA_CONTEXT_MENU_ITEM_BIRTHDAY);
3029         }
3030
3031         if (__pNoteFieldItem == null)
3032         {
3033                 __pMoreInformationContextMenu->AddItem(ResourceManager::GetString(L"IDS_PB_BODY_NOTE"), IDA_CONTEXT_MENU_ITEM_NOTE);
3034         }
3035
3036         if (__isMoreInformationContextMenuShowing == false)
3037         {
3038                 __pMoreInformationContextMenu->Show();
3039         }
3040 }
3041
3042 void
3043 ContactEditorForm::ShowTypeContextMenu(DetailPhoneNumberType currentType, const Tizen::Graphics::Point& position, int itemTag)
3044 {
3045         if (__pTypeContextMenu != null)
3046         {
3047                 delete __pTypeContextMenu;
3048                 __pTypeContextMenu = null;
3049         }
3050
3051         __pTypeContextMenu = new (std::nothrow) ContextMenu();
3052         __pTypeContextMenu->Construct(position, CONTEXT_MENU_STYLE_LIST, CONTEXT_MENU_ANCHOR_DIRECTION_LEFTWARD);
3053
3054         __pTypeContextMenu->SetMaxVisibleItemsCount(DETAIL_PHONENUMBER_TYPE_OTHER + 1);
3055         __pTypeContextMenu->AddActionEventListener(*this);
3056
3057         for (int i = 0; i <= DETAIL_PHONENUMBER_TYPE_OTHER; i++)
3058         {
3059                 int index = i << TABLE_VIEW_INPUT_FIELD_INDEX_SHIFT;
3060                 __pTypeContextMenu->AddItem(__pPresentationModel->GetPhoneNumberTypeString((DetailPhoneNumberType)i), itemTag | index);
3061         }
3062
3063         __pTypeContextMenu->RemoveItemAt((int)currentType);
3064
3065         __pTypeContextMenu->Show();
3066 }
3067
3068 void
3069 ContactEditorForm::ShowTypeContextMenu(DetailEmailType currentType, const Tizen::Graphics::Point& position, int itemTag)
3070 {
3071         if (__pTypeContextMenu != null)
3072         {
3073                 delete __pTypeContextMenu;
3074                 __pTypeContextMenu = null;
3075         }
3076
3077         __pTypeContextMenu = new (std::nothrow) ContextMenu();
3078         __pTypeContextMenu->Construct(position, CONTEXT_MENU_STYLE_LIST, CONTEXT_MENU_ANCHOR_DIRECTION_LEFTWARD);
3079
3080         __pTypeContextMenu->SetMaxVisibleItemsCount(DETAIL_EMAIL_TYPE_OTHER + 1);
3081         __pTypeContextMenu->AddActionEventListener(*this);
3082
3083         for (int i = 0; i <= DETAIL_EMAIL_TYPE_OTHER; i++)
3084         {
3085                 int index = i << TABLE_VIEW_INPUT_FIELD_INDEX_SHIFT;
3086                 __pTypeContextMenu->AddItem(__pPresentationModel->GetAddressTypeString((DetailAddressType)i), itemTag | index);
3087         }
3088
3089         __pTypeContextMenu->RemoveItemAt((int)currentType);
3090
3091         __pTypeContextMenu->Show();
3092 }
3093
3094 void
3095 ContactEditorForm::ShowTypeContextMenu(DetailAddressType currentType, const Tizen::Graphics::Point& position, int itemTag)
3096 {
3097         if (__pTypeContextMenu != null)
3098         {
3099                 delete __pTypeContextMenu;
3100                 __pTypeContextMenu = null;
3101         }
3102
3103         __pTypeContextMenu = new (std::nothrow) ContextMenu();
3104         __pTypeContextMenu->Construct(position, CONTEXT_MENU_STYLE_LIST, CONTEXT_MENU_ANCHOR_DIRECTION_LEFTWARD);
3105
3106         __pTypeContextMenu->SetMaxVisibleItemsCount(DETAIL_ADDRESS_TYPE_OTHER + 1);
3107         __pTypeContextMenu->AddActionEventListener(*this);
3108
3109         for (int i = 0; i <= DETAIL_ADDRESS_TYPE_OTHER; i++)
3110         {
3111                 int index = i << TABLE_VIEW_INPUT_FIELD_INDEX_SHIFT;
3112                 __pTypeContextMenu->AddItem(__pPresentationModel->GetAddressTypeString((DetailAddressType)i), itemTag | index);
3113         }
3114
3115         __pTypeContextMenu->RemoveItemAt((int)currentType);
3116
3117         __pTypeContextMenu->Show();
3118 }
3119
3120 void
3121 ContactEditorForm::ShowTypeContextMenu(DetailUrlType currentType, const Tizen::Graphics::Point& position, int itemTag)
3122 {
3123         if (__pTypeContextMenu != null)
3124         {
3125                 delete __pTypeContextMenu;
3126                 __pTypeContextMenu = null;
3127         }
3128
3129         __pTypeContextMenu = new (std::nothrow) ContextMenu();
3130         __pTypeContextMenu->Construct(position, CONTEXT_MENU_STYLE_LIST, CONTEXT_MENU_ANCHOR_DIRECTION_LEFTWARD);
3131
3132         __pTypeContextMenu->SetMaxVisibleItemsCount(DETAIL_URL_TYPE_OTHER + 1);
3133         __pTypeContextMenu->AddActionEventListener(*this);
3134
3135         for (int i = 0; i <= DETAIL_URL_TYPE_OTHER; i++)
3136         {
3137                 int index = i << TABLE_VIEW_INPUT_FIELD_INDEX_SHIFT;
3138                 __pTypeContextMenu->AddItem(__pPresentationModel->GetUrlTypeString((DetailUrlType)i), itemTag | index);
3139         }
3140
3141         __pTypeContextMenu->RemoveItemAt((int)currentType);
3142
3143         __pTypeContextMenu->Show();
3144 }
3145
3146 void
3147 ContactEditorForm::ShowTypeContextMenu(DetailImAddressType currentType, const Tizen::Graphics::Point& position, int itemTag)
3148 {
3149         if (__pTypeContextMenu != null)
3150         {
3151                 delete __pTypeContextMenu;
3152                 __pTypeContextMenu = null;
3153         }
3154
3155         __pTypeContextMenu = new (std::nothrow) ContextMenu();
3156         __pTypeContextMenu->Construct(position, CONTEXT_MENU_STYLE_LIST, CONTEXT_MENU_ANCHOR_DIRECTION_LEFTWARD);
3157
3158         __pTypeContextMenu->SetMaxVisibleItemsCount(7); // Temporary the code due to limit max count(8) by UI framework.
3159         __pTypeContextMenu->AddActionEventListener(*this);
3160
3161         for (int i = 0; i <= DETAIL_IM_ADDRESS_TYPE_OTHER; i++)
3162         {
3163                 int index = i << TABLE_VIEW_INPUT_FIELD_INDEX_SHIFT;
3164                 __pTypeContextMenu->AddItem(__pPresentationModel->GetImAddressTypeString((DetailImAddressType)i), itemTag | index);
3165         }
3166
3167         __pTypeContextMenu->RemoveItemAt((int)currentType);
3168
3169         __pTypeContextMenu->Show();
3170 }
3171
3172 void
3173 ContactEditorForm::OnTouchPressed(const Tizen::Ui::Control& source, const Tizen::Graphics::Point& currentPosition, const Tizen::Ui::TouchEventInfo& touchInfo)
3174 {
3175 }
3176
3177 void
3178 ContactEditorForm::OnTouchReleased(const Tizen::Ui::Control& source, const Tizen::Graphics::Point& currentPosition, const Tizen::Ui::TouchEventInfo& touchInfo)
3179 {
3180         if (source.Contains(currentPosition) == false || touchInfo.IsFlicked() == true)
3181         {
3182                 return;
3183         }
3184
3185         SetFocus();
3186
3187         Control* pParent = source.GetParent();
3188         Point position = pParent->GetPosition();
3189         Point itemPosition(position.x + source.GetX(), GetClientAreaBounds().y + position.y + source.GetY() + (source.GetHeight() / 2) - __scrolledDistance);
3190         String typeString = pParent->GetName();
3191         String itemIndexTag = source.GetName();
3192         int type;
3193         int itemIndex;
3194
3195         Integer::Parse(itemIndexTag, itemIndex);
3196         Integer::Parse(typeString, type);
3197
3198         int groupIndex = (itemIndex & TABLE_VIEW_GROUP_INDEX_MASK) >> TABLE_VIEW_GROUP_INDEX_SHIFT;
3199
3200         switch (groupIndex)
3201         {
3202         case TABLE_VIEW_PHONE_NUMBER_FIELD_INDEX:
3203                 {
3204                         ShowTypeContextMenu((DetailPhoneNumberType)type, itemPosition, itemIndex);
3205                 }
3206                 break;
3207         case TABLE_VIEW_EMAIL_FIELD_INDEX:
3208                 {
3209                         ShowTypeContextMenu((DetailEmailType)type, itemPosition, itemIndex);
3210                 }
3211                 break;
3212         case TABLE_VIEW_ADDRESS_FIELD_INDEX:
3213                 {
3214                         ShowTypeContextMenu((DetailAddressType)type, itemPosition, itemIndex);
3215                 }
3216                 break;
3217         case TABLE_VIEW_IM_ADDRESS_FIELD_INDEX:
3218                 {
3219                         ShowTypeContextMenu((DetailImAddressType)type, itemPosition, itemIndex);
3220                 }
3221                 break;
3222         case TABLE_VIEW_URL_FIELD_INDEX:
3223                 {
3224                         ShowTypeContextMenu((DetailUrlType)type, itemPosition, itemIndex);
3225                 }
3226                 break;
3227         default:
3228                 break;
3229         }
3230 }
3231
3232 void
3233 ContactEditorForm::OnTouchMoved(const Tizen::Ui::Control& source, const Tizen::Graphics::Point& currentPosition, const Tizen::Ui::TouchEventInfo& touchInfo)
3234 {
3235 }
3236
3237 void
3238 ContactEditorForm::OnTouchFocusIn(const Tizen::Ui::Control& source, const Tizen::Graphics::Point& currentPosition, const Tizen::Ui::TouchEventInfo& touchInfo)
3239 {
3240 }
3241
3242 void
3243 ContactEditorForm::OnTouchFocusOut(const Tizen::Ui::Control& source, const Tizen::Graphics::Point& currentPosition, const Tizen::Ui::TouchEventInfo& touchInfo)
3244 {
3245 }
3246
3247 void
3248 ContactEditorForm::OnTouchCanceled(const Tizen::Ui::Control& source, const Tizen::Graphics::Point& currentPosition, const Tizen::Ui::TouchEventInfo& touchInfo)
3249 {
3250 }
3251
3252 void
3253 ContactEditorForm::OnScrollEndReached (Tizen::Ui::Control &source, Tizen::Ui::Controls::ScrollEndEvent type)
3254 {
3255 }
3256
3257 void
3258 ContactEditorForm::OnScrollPositionChanged (Tizen::Ui::Control &source, int scrollPos)
3259 {
3260         __scrolledDistance = scrollPos;
3261 }
3262
3263 void
3264 ContactEditorForm::OnScrollStopped (Tizen::Ui::Control &source)
3265 {
3266 }
3267
3268 void
3269 ContactEditorForm::OnExpandableEditAreaLineAdded (Tizen::Ui::Controls::ExpandableEditArea &source, int newLineCount)
3270 {
3271         __pTableView->RefreshItem(TABLE_VIEW_NOTE_FIELD_INDEX, 0, TABLE_VIEW_REFRESH_TYPE_ITEM_MODIFY);
3272 }
3273
3274 void
3275 ContactEditorForm::OnExpandableEditAreaLineRemoved (Tizen::Ui::Controls::ExpandableEditArea &source, int newLineCount)
3276 {
3277         __pTableView->RefreshItem(TABLE_VIEW_NOTE_FIELD_INDEX, 0, TABLE_VIEW_REFRESH_TYPE_ITEM_MODIFY);
3278 }
3279
3280 void
3281 ContactEditorForm::OnDateChanged(const Tizen::Ui::Control& source, int year, int month, int day)
3282 {
3283         DateTime changedDate;
3284         changedDate.SetValue(year, month, day);
3285
3286         __pPresentationModel->SetBirthday(changedDate);
3287 }
3288
3289 void
3290 ContactEditorForm::OnDateChangeCanceled(const Tizen::Ui::Control& source)
3291 {
3292 }
3293
3294 void
3295 ContactEditorForm::OnAppControlCompleteResponseReceived(const Tizen::App::AppId& appId, const Tizen::Base::String& operationId, Tizen::App::AppCtrlResult appControlResult, const Tizen::Base::Collection::IMap* pExtraData)
3296 {
3297         AppLogDebug("ENTER");
3298
3299         SetEnabled(true);
3300         Invalidate(true);
3301
3302         TryReturnVoid(appControlResult == APP_CTRL_RESULT_SUCCEEDED, "[E_FAILURE] The result of an appcontrol is not succeeded.");
3303         TryReturnVoid(pExtraData != null, "[E_FAILURE] The extra data is null.");
3304
3305         const String *pResultString = null;
3306         const ArrayList* pResultList = dynamic_cast<const ArrayList*>(pExtraData->GetValue(String(OUTPUT_KEY_SELECTED)));
3307         if (pResultList != null)
3308         {
3309                 pResultString = static_cast<const String*>(pResultList->GetAt(0));
3310         }
3311         else
3312         {
3313                 pResultString = static_cast<const String*>(pExtraData->GetValue(String(OUTPUT_KEY_SELECTED)));
3314         }
3315         TryReturnVoid(pResultString != null, "[E_FAILURE] Unable to get file path.");
3316
3317         if (appId.Equals(String(PROVIDER_ID_CAMERA)) && operationId.Equals(String(OPERATION_ID_CREATE_CONTENT)))
3318         {
3319                 __pPresentationModel->SetThumbnail(*pResultString);
3320                 __pTableView->RefreshItem(TABLE_VIEW_THUMBNAIL_FIELD_INDEX, 0, TABLE_VIEW_REFRESH_TYPE_ITEM_MODIFY);
3321
3322                 if (__pFileEventManager == null)
3323                 {
3324                         __pFileEventManager = new (std::nothrow) FileEventManager();
3325                         __pFileEventManager->Construct(*this);
3326                 }
3327                 __pFileEventManager->AddPath(*pResultString, FILE_EVENT_TYPE_DELETE | FILE_EVENT_TYPE_DELETE_SELF | FILE_EVENT_TYPE_MODIFY | FILE_EVENT_TYPE_MOVE_SELF);
3328         }
3329         else if (appId.Equals(String(PROVIDER_ID_GALLERY)) && operationId.Equals(String(OPERATION_ID_PICK)))
3330         {
3331                 __pPresentationModel->SetThumbnail(*pResultString);
3332                 __pTableView->RefreshItem(TABLE_VIEW_THUMBNAIL_FIELD_INDEX, 0, TABLE_VIEW_REFRESH_TYPE_ITEM_MODIFY);
3333
3334                 if (__pFileEventManager == null)
3335                 {
3336                         __pFileEventManager = new (std::nothrow) FileEventManager();
3337                         __pFileEventManager->Construct(*this);
3338                 }
3339                 __pFileEventManager->AddPath(*pResultString, FILE_EVENT_TYPE_DELETE | FILE_EVENT_TYPE_DELETE_SELF | FILE_EVENT_TYPE_MODIFY | FILE_EVENT_TYPE_MOVE_SELF);
3340         }
3341         else if (appId.Equals(String(PROVIDER_ID_FILEMANAGER)) && operationId.Equals(String(OPERATION_ID_PICK)))
3342         {
3343                 __pPresentationModel->SetValue(DETAIL_PROPERTY_RINGTONE, *pResultString);
3344                 __pTableView->RefreshItem(TABLE_VIEW_GROUP_RINGTONE_FIELD_INDEX, 2, TABLE_VIEW_REFRESH_TYPE_ITEM_MODIFY);
3345         }
3346
3347         AppLogDebug("EXIT");
3348 }
3349
3350 result
3351 ContactEditorForm::LaunchAppControl(const Tizen::App::AppId& appId, const Tizen::Base::String& operationId)
3352 {
3353         result r = E_SUCCESS;
3354
3355         String uri;
3356         String mimeType;
3357         HashMap extraData;
3358         extraData.Construct();
3359
3360         if (appId.Equals(String(PROVIDER_ID_CAMERA)) && operationId.Equals(String(OPERATION_ID_CREATE_CONTENT)))
3361         {
3362                 mimeType.Append(INPUT_MIME_TYPE_CAMERA);
3363                 extraData.Add(new (std::nothrow) String(INPUT_KEY_ALLOW_SWITCH), new (std::nothrow) String(INPUT_VALUE_FALSE));
3364         }
3365         else if (appId.Equals(String(PROVIDER_ID_GALLERY)) && operationId.Equals(String(OPERATION_ID_PICK)))
3366         {
3367                 mimeType.Append(INPUT_MIME_TYPE_GALLERY);
3368                 extraData.Add(new (std::nothrow) String(INPUT_KEY_SELECTION_MODE), new (std::nothrow) String(INPUT_DATA_SELECTION_MODE_SINGLE));
3369         }
3370         else if (appId.Equals(String(PROVIDER_ID_FILEMANAGER)) && operationId.Equals(String(OPERATION_ID_PICK)))
3371         {
3372                 mimeType.Append(INPUT_MIME_TYPE_AUDIO);
3373                 extraData.Add(new (std::nothrow) String(INPUT_KEY_SELECTION_MODE), new (std::nothrow) String(INPUT_DATA_SELECTION_MODE_SINGLE));
3374         }
3375
3376         AppControl* pAppControl = AppManager::FindAppControlN(appId, operationId);
3377
3378         if (pAppControl != null)
3379         {
3380                 r = pAppControl->Start(&uri, &mimeType, &extraData, this);
3381                 TryCatch(r == E_SUCCESS, , "[%s] Unable to launch app control.", GetErrorMessage(r));
3382
3383                 SetEnabled(false);
3384                 Invalidate(true);
3385         }
3386
3387 CATCH:
3388         extraData.RemoveAll(true);
3389         delete pAppControl;
3390
3391         return r;
3392 }
3393
3394 void
3395 ContactEditorForm::OnContactsChanged(void)
3396 {
3397         SceneManager* pSceneManager = SceneManager::GetInstance();
3398
3399         if (__isSaved == false)
3400         {
3401                 if (__pPresentationModel->IsContactRemoved())
3402                 {
3403                         pSceneManager->GoBackward(BackwardSceneTransition(SCENE_TRANSITION_ANIMATION_TYPE_RIGHT));
3404                 }
3405
3406                 return;
3407         }
3408
3409         SetFocus();
3410
3411         if (__isAppControl == true)
3412         {
3413                 UiApp* pApp = UiApp::GetInstance();
3414                 pApp->Terminate();
3415         }
3416         else
3417         {
3418                 ArrayList* pArg = null;
3419
3420                 if (__pPresentationModel->GetVcfPath().IsEmpty() == false)
3421                 {
3422                         pArg = new (std::nothrow) ArrayList();
3423                         pArg->Construct();
3424
3425                         String* pViewType = new (std::nothrow) String();
3426                         String* pValueType = new (std::nothrow) String();
3427
3428                         pViewType->Append(VIEW_TYPE);
3429                         pViewType->Append(DELIMITER);
3430                         pViewType->Append(VIEW_TYPE_VALUE_CONTACT);
3431
3432                         pValueType->Append(VIEW_TYPE_CONTACT_ID);
3433                         pValueType->Append(DELIMITER);
3434                         pValueType->Append(Integer::ToString(__pPresentationModel->GetContactId()));
3435
3436                         pArg->Add(pViewType);
3437                         pArg->Add(pValueType);
3438                 }
3439                 pSceneManager->GoBackward(BackwardSceneTransition(SCENE_TRANSITION_ANIMATION_TYPE_RIGHT), pArg);
3440         }
3441
3442         __isSaved = false;
3443 }
3444
3445 void
3446 ContactEditorForm::OnCategoriesChanged(void)
3447 {
3448 }
3449
3450 void
3451 ContactEditorForm::OnForeground(void)
3452 {
3453         if (IsEnabled() == false)
3454         {
3455                 SetEnabled(true);
3456                 Invalidate(true);
3457         }
3458 }
3459
3460 void
3461 ContactEditorForm::OnBackground(void)
3462 {
3463 }
3464
3465 void
3466 ContactEditorForm::OnFileEventOccured(const unsigned long events, const Tizen::Base::String &path, const unsigned int eventId)
3467 {
3468         __pPresentationModel->SetThumbnail(L"");
3469         __pTableView->RefreshItem(TABLE_VIEW_THUMBNAIL_FIELD_INDEX, 0, TABLE_VIEW_REFRESH_TYPE_ITEM_MODIFY);
3470 }
3471
3472 void
3473 ContactEditorForm::OnDeviceStateChanged(Tizen::System::DeviceType deviceType, const Tizen::Base::String &state)
3474 {
3475         if (deviceType != DEVICE_TYPE_STORAGE_CARD || __pPresentationModel->GetValue(DETAIL_PROPERTY_THUMBNAIL).IsEmpty())
3476         {
3477                 return;
3478         }
3479
3480         if (state.Equals(SD_CARD_UNMOUNTED, false) && File::IsFileExist(__pPresentationModel->GetValue(DETAIL_PROPERTY_THUMBNAIL)) == false)
3481         {
3482                 __pPresentationModel->SetThumbnail(L"");
3483                 __pTableView->RefreshItem(TABLE_VIEW_THUMBNAIL_FIELD_INDEX, 0, TABLE_VIEW_REFRESH_TYPE_ITEM_MODIFY);
3484         }
3485 }