Applied latest source code
[apps/native/preloaded/Settings.git] / src / StFontForm.cpp
1 //
2 // Copyright (c) 2012 Samsung Electronics Co., Ltd.
3 //
4 // Licensed under the Flora License, Version 1.1 (the License);
5 // you may not use this file except in compliance with the License.
6 // You may obtain a copy of the License at
7 //
8 //     http://floralicense.org/license/
9 //
10 // Unless required by applicable law or agreed to in writing, software
11 // distributed under the License is distributed on an AS IS BASIS,
12 // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 // See the License for the specific language governing permissions and
14 // limitations under the License.
15 //
16
17 /**
18  * @file                StFontForm.cpp
19  * @brief               This is the implementation file for FontForm class.
20  */
21
22 #include <memory>
23 #include <FIo.h>
24 #include "StFontForm.h"
25 #include "StResourceManager.h"
26 #include "StSettingScenesList.h"
27 #include "StTypes.h"
28
29 using namespace Tizen::App;
30 using namespace Tizen::Base;
31 using namespace Tizen::Base::Collection;
32 using namespace Tizen::Io;
33 using namespace Tizen::Graphics;
34 using namespace Tizen::System;
35 using namespace Tizen::Ui;
36 using namespace Tizen::Ui::Controls;
37 using namespace Tizen::Ui::Scenes;
38
39 static const char APPCONTROL_DEFAULT = 0x00;
40 static const char APPCONTROL_REQUEST_FONT_TYPE = 0x21;
41 static const char APPCONTROL_REQUEST_FONT_SIZE = 0x22;
42 static const char APPCONTROL_TYPE = 0x01;
43 static const char APPCONTROL_SIZE = 0x02;
44
45 static const int ID_GROUP_FONT = 0;
46 static const int ID_GROUP_FONT_ITEM_COUNT = 1;
47 static const int ID_ITEM_FONT_TYPE = 0;
48
49 static const int ID_GROUP_FONT_LIST = 1;
50
51 static const int ID_GROUP_FONT_SIZE = 2;
52 static const int ID_ITEM_FONT_SIZE = 0;
53
54 static const int ID_GROUP_FONT_TEXT = 3;
55
56 static const int ID_GROUP_COUNT = 4;
57 static const int ID_GROUP_MAX_ITEM_COUNT = ID_GROUP_FONT_ITEM_COUNT;
58
59 static const int FONT_FORM_FIRST_CONTROL = 0;
60 static const int FONT_FORM_SECOND_CONTROL = 1;
61 static const int FONT_FORM_THIRD_CONTROL = 2;
62
63 static const wchar_t* LABEL_0 = L"Label0";
64 static const wchar_t* LABEL_2 = L"Label2";
65 static const wchar_t* FONT_TYPE = L"Font_type";
66 static const wchar_t* FONT_SIZE = L"Font_size";
67
68 FontForm::FontForm(void)
69         : __isAppControlRequest(APPCONTROL_DEFAULT)
70         , __categoryCheck(L"")
71         , __isFontTypeExpend(false)
72 {
73          __pLabel[0] = null;
74          __pLabel[1] = null;
75 }
76
77 FontForm::~FontForm(void)
78 {
79 }
80
81 void
82 FontForm::CreateFooter(void)
83 {
84         Footer* pFooter = GetFooter();
85         AppAssert(pFooter);
86
87         pFooter->SetStyle(FOOTER_STYLE_BUTTON_TEXT);
88         pFooter->AddActionEventListener(*this);
89
90         SetFormBackEventListener(this);
91 }
92
93 result
94 FontForm::OnInitializing(void)
95 {
96         CreateHeader(ResourceManager::GetString(L"IDS_ST_BODY_FONT"));
97
98         __fontList = new (std::nothrow) ArrayList(SingleObjectDeleter);
99         __fontList->Construct();
100         GetFontList(*__fontList);
101         CreateTableView();
102         __pTableView->UpdateTableView();
103         __pTableView->CollapseGroup(ID_GROUP_FONT_LIST);
104         SettingInfo::AddSettingEventListener(*this);
105         AppLogDebug("ENTER");
106
107         return E_SUCCESS;
108 }
109
110 result
111 FontForm::OnTerminating(void)
112 {
113         __pTableView = null;
114         delete __fontList;
115         __fontList = null;
116
117         SettingInfo::RemoveSettingEventListener(*this);
118         SetFormBackEventListener(null);
119         return E_SUCCESS;
120 }
121
122 void
123 FontForm::OnSceneActivatedN(const Tizen::Ui::Scenes::SceneId& previousSceneId, const Tizen::Ui::Scenes::SceneId& currentSceneId, Tizen::Base::Collection::IList* pArgs)
124 {
125
126         if (previousSceneId == IDSCN_FONT_SIZE)
127         {
128                 __pTableView->RefreshAllItems();
129                 __pTableView->CollapseGroup(ID_GROUP_FONT_LIST);
130         }
131
132         if (pArgs != null)
133         {
134                 __categoryCheck = static_cast<String*>(pArgs->GetAt(0))->GetPointer();
135
136                 if (__categoryCheck.CompareTo(L"http://tizen.org/appcontrol/data/font/type") == 0)
137                 {
138                         SetAppControlRequest(APPCONTROL_REQUEST_FONT_TYPE);
139                         __pTableView->SetItemEnabled(ID_GROUP_FONT_SIZE, ID_ITEM_FONT_SIZE, false);
140                 }
141                 else if (__categoryCheck.Equals(L"http://tizen.org/appcontrol/data/font/size", false))
142                 {
143                         SetAppControlRequest(APPCONTROL_REQUEST_FONT_SIZE);
144                         __pTableView->SetItemEnabled(ID_GROUP_FONT, ID_ITEM_FONT_TYPE, false);
145                 }
146
147                 delete pArgs;
148         }
149
150         __pTableView->UpdateTableView();
151
152         String currentFontType;
153
154         if (SettingInfo::GetValue(SETTING_INFO_KEY_FONT_TYPE, currentFontType) == E_SUCCESS)
155         {
156                 for (int i = 0; i < __fontList->GetCount(); i++)
157                 {
158                         String itemMainText = static_cast<String*>(__fontList->GetAt(i))->GetPointer();
159
160                         if (itemMainText.Equals(currentFontType, false))
161                         {
162                                 __pTableView->SetItemChecked(ID_GROUP_FONT_LIST, i, true);
163                                 break;
164                         }
165                 }
166                 AppLogDebug("Get Font Type[%ls] :Result[%s]", currentFontType.GetPointer(), GetErrorMessage(GetLastResult()));
167         }
168         __pTableView->RefreshItem(ID_GROUP_FONT_SIZE, ID_ITEM_FONT_SIZE, TABLE_VIEW_REFRESH_TYPE_ITEM_MODIFY);
169         __pTableView->RefreshItem(ID_GROUP_FONT_LIST, ID_ITEM_FONT_TYPE, TABLE_VIEW_REFRESH_TYPE_ITEM_MODIFY);
170         __pTableView->RefreshItem(ID_GROUP_FONT, ID_ITEM_FONT_TYPE, TABLE_VIEW_REFRESH_TYPE_ITEM_MODIFY);
171 }
172
173 void
174 FontForm::OnSceneDeactivated(const Tizen::Ui::Scenes::SceneId& currentSceneId, const Tizen::Ui::Scenes::SceneId& nextSceneId)
175 {
176 }
177
178 void
179 FontForm::OnFormBackRequested(Tizen::Ui::Controls::Form& source)
180 {
181         SceneManager* pSceneManager = SceneManager::GetInstance();
182         AppAssert(pSceneManager);
183
184         __pTableView->CollapseGroup(ID_GROUP_FONT_LIST);
185         if (GetAppControlRequest() != APPCONTROL_DEFAULT)
186         {
187                 UiApp* pApp = UiApp::GetInstance();
188                 AppAssert(pApp);
189                 AppControlFontResult();
190                 pApp->Terminate();
191         }
192         else
193         {
194                 pSceneManager->GoBackward(BackwardSceneTransition(SCENE_TRANSITION_ANIMATION_TYPE_RIGHT), null);
195         }
196 }
197
198 int
199 FontForm::GetGroupCount(void)
200 {
201         AppLogDebug("ENTER");
202         return ID_GROUP_COUNT;
203 }
204
205 int
206 FontForm::GetItemCount(int groupIndex)
207 {
208         int itemCount = 0;
209
210         switch (groupIndex)
211         {
212         case ID_GROUP_FONT:
213            // fall through
214         case ID_GROUP_FONT_SIZE:
215                 {
216                         itemCount = ID_GROUP_MAX_ITEM_COUNT;
217                 }
218                 break;
219
220         case ID_GROUP_FONT_LIST:
221                 {
222                         itemCount = __fontList->GetCount();
223                 }
224                 break;
225
226         default:
227                 break;
228         }
229
230         AppLogDebug("GetItemCount %d", itemCount);
231
232         return itemCount;
233 }
234
235 TableViewGroupItem*
236 FontForm::CreateGroupItem(int groupIndex, int itemWidth)
237 {
238         AppLogDebug("ENTER");
239
240         int itemHeight = H_GROUP_INDEX_NO_TITLE_DEFAULT;
241         int yItemOffset = H_GROUP_INDEX_HELP_TEXT_TOP_GAP;
242         LabelTextStyle style = LABEL_TEXT_STYLE_NORMAL;
243         Rectangle itemMainRectangle;
244         String groupText;
245         Label* pLabel = null;
246         int fontSize = GetFontSize();
247
248         TableViewGroupItem* pItem = new (std::nothrow) TableViewGroupItem();
249
250         switch (groupIndex)
251         {
252         case ID_GROUP_FONT:
253                 {
254                         yItemOffset = H_GROUP_INDEX_NO_HELP_TEXT_GAP;
255                         itemHeight = H_GROUP_INDEX_NO_TITLE_DEFAULT;
256                 }
257                 break;
258
259         case ID_GROUP_FONT_LIST:
260                 {
261                         itemHeight = 0;
262                 }
263                 break;
264
265         case ID_GROUP_FONT_SIZE:
266                 // fall through
267         case ID_GROUP_FONT_TEXT:
268                 {
269                         itemHeight = 0;
270                 }
271                 break;
272
273         default:
274                 {
275                         yItemOffset = H_GROUP_INDEX_NO_HELP_TEXT_GAP;
276                         itemHeight = H_GROUP_INDEX_NO_TITLE_DEFAULT;
277                 }
278                 break;
279         }
280
281         itemMainRectangle.x = X_GROUP_ITEM_DEFAULT_LABEL;
282         itemMainRectangle.y = yItemOffset;
283         itemMainRectangle.width = itemWidth;
284         itemMainRectangle.height = itemHeight;
285
286         RelativeLayout relativeLayout;
287         relativeLayout.Construct();
288
289         pItem->Construct(relativeLayout, Dimension(itemWidth, itemHeight));
290         pItem->SetBackgroundColor(COLOR_BG_GROUP_INDEX_DEFAULT);
291
292         pLabel = new (std::nothrow) Label();
293         pLabel->Construct(itemMainRectangle, groupText);
294         pLabel->SetTextHorizontalAlignment(ALIGNMENT_LEFT);
295         pLabel->SetTextVerticalAlignment(ALIGNMENT_TOP);
296         pLabel->SetTextConfig(fontSize, style);
297         pLabel->SetTextColor(COLOR_HELP_TEXT_TYPE_01);
298
299         pItem->AddControl(pLabel);
300         relativeLayout.SetMargin(*pLabel, itemMainRectangle.x, RELATIVE_LAYOUT_RIGHT_MARGIN, 0, 0);
301         relativeLayout.SetRelation(*pLabel, pItem, RECT_EDGE_RELATION_LEFT_TO_LEFT);
302         relativeLayout.SetRelation(*pLabel, pItem, RECT_EDGE_RELATION_RIGHT_TO_RIGHT);
303         pItem->SetEnabled(false);
304
305         return pItem;
306 }
307
308 TableViewItem*
309 FontForm::CreateItem(int groupIndex, int itemIndex, int itemWidth)
310 {
311         AppLogDebug("group[%d] index[%d]", groupIndex, itemIndex);
312
313         Rectangle itemMainRectangle;
314         Rectangle itemSubRectangle;
315         TableViewAnnexStyle style = TABLE_VIEW_ANNEX_STYLE_NORMAL;
316         String itemMainText;
317         String itemSubText;
318         String fontReturnValue;
319         Label* pLabel = null;
320         Label* pLabelArrow = null;
321
322         int fontSize = GetFontSize();
323         bool isItemSubText = true;
324         int itemHeight = H_GROUP_ITEM_DEFAULT;
325         Rectangle detailArrow;
326         Bitmap* pBitmap = null;
327         char appControlRequest;
328
329         if (groupIndex == ID_GROUP_FONT_LIST)
330         {
331                 String currentFontType;
332                 isItemSubText = false;
333                 style = TABLE_VIEW_ANNEX_STYLE_RADIO;
334         }
335
336         GetTableViewItemString(groupIndex, itemIndex, itemMainText, itemSubText);
337
338         TableViewItem* pItem = new (std::nothrow) TableViewItem();
339
340         if (isItemSubText == true)
341         {
342                 ItemTypeTwoLine(itemMainRectangle, itemSubRectangle, fontSize);
343                 itemHeight = (itemMainRectangle.height + itemSubRectangle.height);
344                 String name = LABEL_NAME;
345                 int index = 0;
346                 RelativeLayout relativeLayout;
347                 relativeLayout.Construct();
348
349                 pItem->Construct(relativeLayout, Dimension(itemWidth, itemHeight), style);
350                 pItem->SetBackgroundColor(COLOR_BG_GROUP_ITEM_DEFAULT);
351                 name.Append(groupIndex);
352                 pLabel = new (std::nothrow) Label();
353                 pLabel->Construct(itemMainRectangle, itemMainText);
354                 pLabel->SetTextHorizontalAlignment(ALIGNMENT_LEFT);
355                 pLabel->SetTextConfig(fontSize, LABEL_TEXT_STYLE_NORMAL);
356                 pLabel->SetTextColor(COLOR_MAIN_TEXT);
357                 pLabel->SetName(name);
358                 pLabel->AddTouchEventListener(*this);
359
360                 pItem->AddKeyEventListener(*this);
361                 pItem->AddFocusEventListener(*this);
362                 pItem->AddControl(pLabel);
363                 relativeLayout.SetMargin(*pLabel, itemMainRectangle.x, RELATIVE_LAYOUT_RIGHT_MARGIN, 0, 0);
364                 relativeLayout.SetRelation(*pLabel, pItem, RECT_EDGE_RELATION_LEFT_TO_LEFT);
365
366                 if (groupIndex == ID_GROUP_FONT)
367                 {
368                         if (__pTableView->IsGroupExpanded(ID_GROUP_FONT_LIST))
369                         {
370                                 pBitmap = ResourceManager::GetBitmapN(IDB_DETAIL_BUTTON_EXPAND_OPENED);
371                         }
372                         else
373                         {
374                                 pBitmap = ResourceManager::GetBitmapN(IDB_DETAIL_BUTTON_EXPAND_CLOSED);
375                         }
376
377                         detailArrow = itemMainRectangle;
378                         detailArrow.y = itemMainRectangle.y + ((itemHeight - W_DETAIL_ARROW_BUTTON) / DIVIDE_BY_TWO);
379                         detailArrow.height = W_DETAIL_ARROW_BUTTON;
380                         detailArrow.width = W_DETAIL_ARROW_BUTTON;
381
382                         pLabelArrow = new (std::nothrow) Label();
383                         pLabelArrow->Construct(detailArrow, L"");
384                         pLabelArrow->SetName(LABEL_DETAIL_ARROW);
385                         pLabelArrow->AddTouchEventListener(*this);
386
387                         pLabelArrow->SetBackgroundBitmap(*pBitmap);
388
389                         pItem->AddControl(pLabelArrow);
390                         relativeLayout.SetMargin(*pLabelArrow, itemMainRectangle.x, RELATIVE_LAYOUT_RIGHT_MARGIN_DETAIL_ARROW_BUTTON, 0, 0);
391                         relativeLayout.SetRelation(*pLabelArrow, pItem, RECT_EDGE_RELATION_RIGHT_TO_RIGHT);
392                         relativeLayout.SetRelation(*pLabel, pLabelArrow, RECT_EDGE_RELATION_RIGHT_TO_LEFT);
393                 }
394                 else
395                 {
396                         relativeLayout.SetRelation(*pLabel, pItem, RECT_EDGE_RELATION_RIGHT_TO_RIGHT);
397                 }
398
399                 if (groupIndex == ID_GROUP_FONT)
400                 {
401                         index = ID_GROUP_FONT;
402                         name = FONT_TYPE;
403                         pItem->SetName(ITEM_NAME_1);
404                 }
405                 else if(groupIndex == ID_GROUP_FONT_SIZE)
406                 {
407                         index = ID_GROUP_FONT_SIZE - 1;
408                         name = FONT_SIZE;
409                         pItem->SetName(ITEM_NAME_2);
410                 }
411
412                 __pLabel[index] = new (std::nothrow) Label();
413                 __pLabel[index]->Construct(itemSubRectangle, itemSubText);
414                 __pLabel[index]->SetTextHorizontalAlignment(ALIGNMENT_LEFT);
415                 __pLabel[index]->SetTextVerticalAlignment(ALIGNMENT_TOP);
416                 __pLabel[index]->SetTextConfig(FONT_SIZE_SUB_TEXT, LABEL_TEXT_STYLE_NORMAL);
417                 __pLabel[index]->SetTextColor(COLOR_SUB_TEXT);
418                 __pLabel[index]->SetName(name);
419                 __pLabel[index]->AddTouchEventListener(*this);
420
421                 pItem->AddControl(__pLabel[index]);
422                 relativeLayout.SetMargin(*__pLabel[index], itemSubRectangle.x, RELATIVE_LAYOUT_RIGHT_MARGIN, 0, 0);
423                 relativeLayout.SetRelation(*__pLabel[index], pItem, RECT_EDGE_RELATION_LEFT_TO_LEFT);
424                 relativeLayout.SetRelation(*__pLabel[index], pItem, RECT_EDGE_RELATION_RIGHT_TO_RIGHT);
425         }
426         else
427         {
428                 RelativeLayout relativeLayout;
429                 relativeLayout.Construct();
430
431                 pItem->Construct(relativeLayout, Dimension(itemWidth, H_GROUP_ITEM_DEFAULT), style);
432                 pItem->SetBackgroundColor(COLOR_BG_GROUP_ITEM_DEFAULT);
433
434                 ItemTypeOneLine(itemMainRectangle);
435                 pLabel = new (std::nothrow) Label();
436                 pLabel->Construct(itemMainRectangle, itemMainText);
437                 pLabel->SetTextHorizontalAlignment(ALIGNMENT_LEFT);
438                 pLabel->SetTextConfig(fontSize, LABEL_TEXT_STYLE_NORMAL);
439                 pLabel->SetTextColor(COLOR_MAIN_TEXT);
440
441                 pItem->AddControl(pLabel);
442                 relativeLayout.SetMargin(*pLabel, RELATIVE_LAYOUT_LEFT_MARGIN, RELATIVE_LAYOUT_RIGHT_MARGIN, 0, 0);
443                 relativeLayout.SetRelation(*pLabel, pItem, RECT_EDGE_RELATION_LEFT_TO_LEFT);
444                 relativeLayout.SetRelation(*pLabel, pItem, RECT_EDGE_RELATION_RIGHT_TO_RIGHT);
445         }
446
447         if ((appControlRequest = GetAppControlRequest()) != APPCONTROL_DEFAULT)
448         {
449                 if (appControlRequest & APPCONTROL_TYPE)
450                 {
451                         if (groupIndex == ID_GROUP_FONT_SIZE)
452                         {
453                                 delete pItem;
454                                 pItem = null;
455                         }
456                 }
457                 else if (appControlRequest & APPCONTROL_SIZE)
458                 {
459                         if ((groupIndex == ID_GROUP_FONT) || (groupIndex == ID_GROUP_FONT_LIST))
460                         {
461                                 delete pItem;
462                                 pItem = null;
463                         }
464                 }
465         }
466
467         return pItem;
468 }
469
470 bool
471 FontForm::DeleteGroupItem(int groupIndex, TableViewGroupItem* pItem)
472 {
473         AppLogDebug("ENTER");
474
475         delete pItem;
476         pItem = null;
477
478         return true;
479 }
480
481 bool
482 FontForm::DeleteItem(int groupIndex, int itemIndex, TableViewItem* pItem)
483 {
484         AppLogDebug("ENTER");
485
486         delete pItem;
487         pItem = null;
488
489         return true;
490 }
491
492 void
493 FontForm::OnGroupedTableViewItemStateChanged(Tizen::Ui::Controls::GroupedTableView& tableView, int groupIndex, int itemIndex, Tizen::Ui::Controls::TableViewItem* pItem, Tizen::Ui::Controls::TableViewItemStatus status)
494 {
495         AppLogDebug("group[%d] index[%d]", groupIndex, itemIndex);
496
497         SceneManager* pSceneManager = SceneManager::GetInstance();
498         AppAssert(pSceneManager);
499         String fontReturnValue;
500
501         switch (groupIndex)
502         {
503         case ID_GROUP_FONT:
504                 {
505                         if (__pTableView->IsGroupExpanded(ID_GROUP_FONT_LIST))
506                         {
507                                 __pTableView->CollapseGroup(ID_GROUP_FONT_LIST);
508                         }
509                         else
510                         {
511                                 __pTableView->ExpandGroup(ID_GROUP_FONT_LIST);
512                         }
513
514                         __pTableView->RefreshItem(groupIndex, itemIndex, TABLE_VIEW_REFRESH_TYPE_ITEM_MODIFY);
515                 }
516                 break;
517
518         case ID_GROUP_FONT_LIST:
519                 {
520                         int listCount = __fontList->GetCount();
521                         String fontGetValue;
522                         fontReturnValue = static_cast<String*>(__fontList->GetAt(itemIndex))->GetPointer();
523
524                         for (int count = 0; count < listCount; count++)
525                         {
526                                 if (itemIndex == count)
527                                 {
528                                         tableView.SetItemChecked(groupIndex, count, true);
529                                 }
530                                 else
531                                 {
532                                         tableView.SetItemChecked(groupIndex, count, false);
533                                 }
534                         }
535                         if ((SettingInfo::GetValue(SETTING_INFO_KEY_FONT_TYPE, fontGetValue)) == E_SUCCESS)
536                         {
537                                 if (fontGetValue.Equals(fontReturnValue, false))
538                                 {
539                                         break;
540                                 }
541                         }
542
543                         if (SettingInfo::SetValue(SETTING_INFO_KEY_FONT_TYPE, fontReturnValue) != E_SUCCESS)
544                         {
545                                 AppLogDebug("Set Font Type :Result[%s]", GetErrorMessage(GetLastResult()));
546                         }
547                         AppLogDebug("Set Font Type[%ls] :Result[%s]", fontReturnValue.GetPointer(), GetErrorMessage(GetLastResult()));
548                 }
549                 break;
550
551         case ID_GROUP_FONT_SIZE:
552                 {
553                         pSceneManager->GoForward(ForwardSceneTransition(IDSCN_FONT_SIZE, SCENE_TRANSITION_ANIMATION_TYPE_LEFT));
554                 }
555                 break;
556
557         default:
558                 break;
559         }
560 }
561
562 int
563 FontForm::GetDefaultGroupItemHeight(void)
564 {
565         return H_GROUP_INDEX_NO_TITLE_DEFAULT;
566 }
567
568 int
569 FontForm::GetDefaultItemHeight(void)
570 {
571         return H_GROUP_ITEM_DEFAULT;
572 }
573
574 void
575 FontForm::UpdateGroupItem(int groupIndex, Tizen::Ui::Controls::TableViewGroupItem* pItem)
576 {
577 }
578
579 void
580 FontForm::UpdateItem(int groupIndex, int itemIndex, Tizen::Ui::Controls::TableViewItem* pItem)
581 {
582         Rectangle itemMainRectangle;
583         Rectangle itemSubRectangle;
584         Rectangle pItemBounds = pItem->GetBounds();
585         int fontSize = GetFontSize();
586
587         switch (groupIndex)
588         {
589         case ID_GROUP_FONT:
590                 {
591                         ItemTypeTwoLine(itemMainRectangle, itemSubRectangle, fontSize);
592
593                         pItemBounds.height = itemMainRectangle.height + itemSubRectangle.height;
594                         pItem->SetBounds(pItemBounds);
595                         Label* pFirstLabel = static_cast<Label*>(pItem->GetControl(FONT_FORM_FIRST_CONTROL));
596                         Label* pSecondLabel = static_cast<Label*>(pItem->GetControl(FONT_FORM_SECOND_CONTROL));
597                         Label* pThirdLabel = static_cast<Label*>(pItem->GetControl(FONT_FORM_THIRD_CONTROL));
598                         Rectangle detailArrow = pSecondLabel->GetBounds();
599                         detailArrow.y = itemMainRectangle.y + ((pItemBounds.height - W_DETAIL_ARROW_BUTTON) / DIVIDE_BY_TWO);
600
601                         pFirstLabel->SetBounds(itemMainRectangle);
602                         pFirstLabel->SetTextConfig(fontSize, LABEL_TEXT_STYLE_NORMAL);
603                         pSecondLabel->SetBounds(detailArrow);
604                         pThirdLabel->SetBounds(itemSubRectangle);
605                         pThirdLabel->SetTextConfig(FONT_SIZE_SUB_TEXT, LABEL_TEXT_STYLE_NORMAL);
606
607                         Bitmap* pBitmap = null;
608
609                         if (__pTableView->IsGroupExpanded(ID_GROUP_FONT_LIST))
610                         {
611                                 pBitmap = ResourceManager::GetBitmapN(IDB_DETAIL_BUTTON_EXPAND_OPENED);
612                         }
613                         else
614                         {
615                                 pBitmap = ResourceManager::GetBitmapN(IDB_DETAIL_BUTTON_EXPAND_CLOSED);
616                         }
617                         pSecondLabel->SetBackgroundBitmap(*pBitmap);
618                         pSecondLabel->Invalidate(false);
619                         pFirstLabel->Invalidate(false);
620                         pItem->Invalidate(false);
621                         delete pBitmap;
622                 }
623                 break;
624
625         case ID_GROUP_FONT_SIZE:
626                 {
627                         ItemTypeTwoLine(itemMainRectangle, itemSubRectangle, fontSize);
628
629                         pItemBounds.height = itemMainRectangle.height + itemSubRectangle.height;
630                         pItem->SetBounds(pItemBounds);
631                         Label* pFirstLabel = static_cast<Label*>(pItem->GetControl(FONT_FORM_FIRST_CONTROL));
632                         Label* pSecondLabel = static_cast<Label*>(pItem->GetControl(FONT_FORM_SECOND_CONTROL));
633
634                         pFirstLabel->SetBounds(itemMainRectangle);
635                         pFirstLabel->SetTextConfig(fontSize, LABEL_TEXT_STYLE_NORMAL);
636                         pSecondLabel->SetBounds(itemSubRectangle);
637                         pSecondLabel->SetTextConfig(FONT_SIZE_SUB_TEXT, LABEL_TEXT_STYLE_NORMAL);
638
639                         String itemMainText = L"";
640                         String itemSubText = L"";
641
642                         GetTableViewItemString(groupIndex, itemIndex, itemMainText, itemSubText);
643                         pFirstLabel->SetText(itemMainText);
644                         pSecondLabel->SetText(itemSubText);
645
646                         pFirstLabel->Invalidate(false);
647                         pSecondLabel->Invalidate(false);
648                         pItem->Invalidate(false);
649                 }
650                 break;
651
652         case ID_GROUP_FONT_LIST:
653                 {
654                         ItemTypeOneLine(itemMainRectangle);
655                         Label* pFirstLabel = static_cast<Label*>(pItem->GetControl(0));
656                         pFirstLabel->SetBounds(itemMainRectangle);
657                         pFirstLabel->SetTextConfig(fontSize, LABEL_TEXT_STYLE_NORMAL);
658                         pFirstLabel->Invalidate(false);
659                 }
660                 break;
661
662         default:
663                 break;
664         }
665
666         Invalidate(true);
667 }
668
669 void
670 FontForm::OnGroupedTableViewContextItemActivationStateChanged(Tizen::Ui::Controls::GroupedTableView& tableView, int groupIndex, int itemIndex, Tizen::Ui::Controls::TableViewContextItem* pContextItem, bool activated)
671 {
672 }
673
674 void
675 FontForm::OnGroupedTableViewGroupItemStateChanged(Tizen::Ui::Controls::GroupedTableView& tableView, int groupIndex, Tizen::Ui::Controls::TableViewGroupItem* pItem, Tizen::Ui::Controls::TableViewItemStatus status)
676 {
677 }
678
679 void
680 FontForm::AppControlFontResult(void)
681 {
682         RequestId reqId = 0;
683         String value;
684         AppControlProviderManager* pAppManager = AppControlProviderManager::GetInstance();
685
686         HashMap* hashMap = new (std::nothrow) HashMap();
687         hashMap->Construct();
688
689         if (GetAppControlRequest() == APPCONTROL_REQUEST_FONT_TYPE)
690         {
691                 SettingInfo::GetValue(SETTING_INFO_KEY_FONT_TYPE, value);
692                 hashMap->Add((new (std::nothrow) String(L"http://tizen.org/appcontrol/data/font/type")), new (std::nothrow) String(value));
693         }
694         else if (GetAppControlRequest() == APPCONTROL_REQUEST_FONT_SIZE)
695         {
696                 SettingInfo::GetValue(SETTING_INFO_KEY_FONT_SIZE, value);
697                 hashMap->Add((new (std::nothrow) String(L"http://tizen.org/appcontrol/data/font/size")), new (std::nothrow) String(value));
698         }
699
700         pAppManager->SendAppControlResult(reqId, APP_CTRL_RESULT_SUCCEEDED, hashMap);
701
702         hashMap->RemoveAll();
703         delete hashMap;
704 }
705
706 result
707 FontForm::GetFontList(Tizen::Base::Collection::IList& list)
708 {
709         const String FONT_DIR_PATH[] =
710         {
711                 L"/usr/share/fonts"
712         };
713
714         list.RemoveAll(true);
715         const int FONT_DIR_PATH_COUNT = sizeof(FONT_DIR_PATH) / sizeof(FONT_DIR_PATH[0]);
716
717         for (int i = 0; i < FONT_DIR_PATH_COUNT; i++)
718         {
719                 Directory directory;
720                 result r = directory.Construct(FONT_DIR_PATH[i]);
721                 if (!IsFailed(r))
722                 {
723                         std::auto_ptr<DirEnumerator>dirEnumerator(directory.ReadN());
724
725                         while (dirEnumerator->MoveNext() == E_SUCCESS)
726                         {
727                                 DirEntry entry = dirEnumerator->GetCurrentDirEntry();
728                                 if (entry.IsDirectory() == false && entry.IsHidden() == false)
729                                 {
730                                         Tizen::Base::Utility::StringTokenizer formatTok(entry.GetName(), ".");
731                                         String token;
732                                         while (formatTok.GetTokenCount())
733                                         {
734                                                 formatTok.GetNextToken(token);
735                                         }
736
737                                         if (token.Equals("ttf", false) || token.Equals("ttc", false))
738                                         {
739                                                 String fullName;
740                                                 fullName.Append(FONT_DIR_PATH[i]);
741                                                 fullName.Append(L"/");
742                                                 fullName.Append(entry.GetName());
743                                                 bool isNewFont = true;
744
745                                                 String* pFamilyName = new (std::nothrow) String(Font::GetFaceName(fullName));
746
747                                                 for (int idx = 0; idx < list.GetCount(); idx++)
748                                                 {
749                                                         String* pName = static_cast <String*>(list.GetAt(idx));
750                                                         if (pName == null)
751                                                         {
752                                                                 continue;
753                                                         }
754                                                         if (pFamilyName->Equals(*pName, true))
755                                                         {
756                                                                 isNewFont = false;
757                                                                 break;
758                                                         }
759                                                 }
760                                                 if (isNewFont)
761                                                 {
762                                                         list.Add(pFamilyName);
763                                                 }
764                                                 else
765                                                 {
766                                                         delete pFamilyName;
767                                                         pFamilyName = null;
768                                                 }
769                                         }
770                                 }
771                         }
772                 }
773         }
774         return E_SUCCESS;
775 }
776
777 void
778 FontForm::GetTableViewItemString(int groupIndex, int itemIndex, Tizen::Base::String& itemMainText, Tizen::Base::String& itemSubText)
779 {
780         switch (groupIndex)
781         {
782         case ID_GROUP_FONT:
783                 {
784                         String fontReturnValue;
785                         if ((SettingInfo::GetValue(SETTING_INFO_KEY_FONT_TYPE, fontReturnValue)) == E_SUCCESS)
786                         {
787                                 itemSubText = fontReturnValue;
788                         }
789                         itemMainText = ResourceManager::GetString(L"IDS_ST_BODY_FONT_TYPE");
790                 }
791                 break;
792
793         case ID_GROUP_FONT_LIST:
794                 {
795                         itemMainText = static_cast<String*>(__fontList->GetAt(itemIndex))->GetPointer();
796                         itemSubText = L"";
797                 }
798                 break;
799
800         case ID_GROUP_FONT_SIZE:
801                 {
802                         String fontReturnValue;
803                         if ((SettingInfo::GetValue(SETTING_INFO_KEY_FONT_SIZE, fontReturnValue)) == E_SUCCESS)
804                         {
805                                 if (fontReturnValue.Equals(L"giant", false))
806                                 {
807                                         itemSubText = ResourceManager::GetString(L"IDS_EMAIL_POP_GIANT_M_TEXTSIZE");
808                                 }
809                                 else if (fontReturnValue.Equals(L"huge", false))
810                                 {
811                                         itemSubText = ResourceManager::GetString(L"IDS_EMAIL_OPT_HUGE_M_TEXTSIZE");
812                                 }
813                                 else if (fontReturnValue.Equals(L"large", false))
814                                 {
815                                         itemSubText = ResourceManager::GetString(L"IDS_ST_BODY_TEXTSTYLE_LARGE");
816                                 }
817                                 else if (fontReturnValue.Equals(L"medium", false))
818                                 {
819                                         itemSubText = ResourceManager::GetString(L"IDS_ST_BODY_FONTTYPE_NORMAL");
820                                 }
821                                 else
822                                 {
823                                         itemSubText = ResourceManager::GetString(L"IDS_ST_BODY_SMALL_M_TEXTSIZE");
824                                 }
825                         }
826                         itemMainText = ResourceManager::GetString(L"IDS_ST_BODY_FONT_SIZE");
827                 }
828                 break;
829
830         default:
831                 break;
832         }
833 }
834
835 void
836 FontForm::OnSettingChanged (Tizen::Base::String &key)
837 {
838         AppLogDebug("FontForm::key changed [%ls]", key.GetPointer());
839
840         int groupCount = __pTableView->GetGroupCount();
841
842         for (int i = 0; i < groupCount; i++)
843         {
844                 int itemCount = __pTableView->GetItemCountAt(i);
845
846                 for (int j = 0; j < itemCount; j++)
847                 {
848                         __pTableView->RefreshItem(i, j, TABLE_VIEW_REFRESH_TYPE_ITEM_MODIFY);
849                 }
850         }
851 }
852
853 char
854 FontForm::GetAppControlRequest(void)
855 {
856         return __isAppControlRequest;
857 }
858
859 void
860 FontForm::SetAppControlRequest(char requestStatus)
861 {
862         __isAppControlRequest = requestStatus;
863 }
864
865 void
866 FontForm::OnTouchMoved(const Tizen::Ui::Control& source, const Tizen::Graphics::Point& currentPosition, const Tizen::Ui::TouchEventInfo& touchInfo)
867 {
868         int index = 0;
869         if (source.GetName() == LABEL_0 || source.GetName() == FONT_TYPE)
870         {
871                 index = 0;
872         }
873         else if (source.GetName() == LABEL_2 || source.GetName() == FONT_SIZE)
874         {
875                 index = 1;
876         }
877         else if (source.GetName() == LABEL_DETAIL_ARROW)
878         {
879                 index = 0;
880         }
881         __pLabel[index]->SetTextColor(COLOR_SUB_TEXT);
882         __pLabel[index]->Invalidate(false);
883 }
884
885 void
886 FontForm::OnTouchPressed(const Tizen::Ui::Control& source, const Tizen::Graphics::Point& currentPosition, const Tizen::Ui::TouchEventInfo& touchInfo)
887 {
888         int index = 0;
889         if (source.GetName() == LABEL_0 || source.GetName() == FONT_TYPE)
890         {
891                 index = 0;
892         }
893         else if (source.GetName() == LABEL_2 || source.GetName() == FONT_SIZE)
894         {
895                 index = 1;
896         }
897         else if (source.GetName() == LABEL_DETAIL_ARROW)
898         {
899                 index = 0;
900         }
901         __pLabel[index]->SetTextColor(Color::GetColor(COLOR_ID_WHITE));
902         __pLabel[index]->Invalidate(false);
903 }
904
905 void
906 FontForm::OnTouchReleased(const Tizen::Ui::Control& source, const Tizen::Graphics::Point& currentPosition, const Tizen::Ui::TouchEventInfo& touchInfo)
907 {
908         int index = 0;
909         if (source.GetName() == LABEL_0 || source.GetName() == FONT_TYPE)
910         {
911                 index = 0;
912         }
913         else if (source.GetName() == LABEL_2 || source.GetName() == FONT_SIZE)
914         {
915                 index = 1;
916         }
917         else if (source.GetName() == LABEL_DETAIL_ARROW)
918         {
919                 index = 0;
920         }
921         __pLabel[index]->SetTextColor(COLOR_SUB_TEXT);
922         __pLabel[index]->Invalidate(false);
923 }
924
925 void
926 FontForm::OnTouchCanceled(const Tizen::Ui::Control& source, const Tizen::Graphics::Point& currentPosition, const Tizen::Ui::TouchEventInfo& touchInfo)
927 {
928         int index = 0;
929         if (source.GetName() == LABEL_0 || source.GetName() == FONT_TYPE)
930         {
931                 index = 0;
932         }
933         else if (source.GetName() == LABEL_2 || source.GetName() == FONT_SIZE)
934         {
935                 index = 1;
936         }
937         else if (source.GetName() == LABEL_DETAIL_ARROW)
938         {
939                 index = 0;
940         }
941         __pLabel[index]->SetTextColor(COLOR_SUB_TEXT);
942         __pLabel[index]->Invalidate(false);
943 }
944
945 void
946 FontForm::OnKeyPressed(const Tizen::Ui::Control& source, Tizen::Ui::KeyCode keyCode)
947 {
948         AppLog("Enter");
949         if(keyCode == KEY_ENTER)
950         {
951                 AppLog("Enter");
952                 int index = 0;
953                 if (source.GetName() == ITEM_NAME_1)
954                 {
955                         index = 0;
956                 }
957                 else if (source.GetName() == ITEM_NAME_2)
958                 {
959                         index = 1;
960                 }
961                 __pLabel[index]->SetTextColor(Color::GetColor(COLOR_ID_WHITE));
962                 __pLabel[index]->Invalidate(false);
963         }
964 }
965
966 void
967 FontForm::OnKeyReleased(const Tizen::Ui::Control& source, Tizen::Ui::KeyCode keyCode)
968 {
969         AppLog("Enter");
970         if(keyCode == KEY_ENTER)
971         {
972                 AppLog("Enter");
973                 int index = 0;
974                 if (source.GetName() ==ITEM_NAME_1)
975                 {
976                         index = 0;
977                 }
978                 else if (source.GetName() == ITEM_NAME_2)
979                 {
980                         index = 1;
981                 }
982                 __pLabel[index]->SetTextColor(COLOR_SUB_TEXT);
983                 __pLabel[index]->Invalidate(false);
984         }
985 }
986
987 void
988 FontForm::OnKeyLongPressed(const Tizen::Ui::Control& source, Tizen::Ui::KeyCode keyCode)
989 {
990 }
991
992 void
993 FontForm::OnFocusLost(const Tizen::Ui::Control& source)
994 {
995         AppLog("Enter");
996         int index = 0;
997
998         if (source.GetName() == ITEM_NAME_1)
999         {
1000                 index = 0;
1001         }
1002
1003         else if (source.GetName() == ITEM_NAME_2)
1004         {
1005                 index = 1;
1006         }
1007
1008         __pLabel[index]->SetTextColor(COLOR_SUB_TEXT);
1009         __pLabel[index]->Invalidate(false);
1010 }