Fixed N_SE-38563, N_SE-38552
[apps/osp/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 W_FONT_ITEM_RIGHT_GAP = 100;
46 static const int ID_GROUP_FONT = 0;
47 static const int ID_GROUP_FONT_ITEM_COUNT = 1;
48 static const int ID_ITEM_FONT_TYPE = 0;
49
50 static const int ID_GROUP_FONT_LIST = 1;
51
52 static const int ID_GROUP_FONT_SIZE = 2;
53 static const int ID_GROUP_FONT_SIZE_ITEM_COUNT = 1;
54 static const int ID_ITEM_FONT_SIZE = 0;
55
56 static const int ID_GROUP_FONT_TEXT = 3;
57 static const int ID_GROUP_FONT_TEXT_ITEM_COUNT = 0;
58
59 static const int ID_GROUP_COUNT = 4;
60 static const int ID_GROUP_MAX_ITEM_COUNT = ID_GROUP_FONT_ITEM_COUNT;
61
62 static const int H_HELP_TEXT_GAP = 6;
63 static const int FONT_FORM_FIRST_CONTROL = 0;
64 static const int FONT_FORM_SECOND_CONTROL = 1;
65 static const int FONT_FORM_THIRD_CONTROL = 2;
66 static const int SECOND_CONTROL_ITEM = 1;
67
68 FontForm::FontForm(void)
69         : __isAppControlRequest(APPCONTROL_DEFAULT)
70         , __categoryCheck(L"")
71         , __isFontTypeExpend(false)
72 {
73 }
74
75 FontForm::~FontForm(void)
76 {
77 }
78
79 void
80 FontForm::CreateFooter(void)
81 {
82         Footer* pFooter = GetFooter();
83         AppAssert(pFooter);
84
85         pFooter->SetStyle(FOOTER_STYLE_BUTTON_TEXT);
86         pFooter->SetBackButton();
87         pFooter->AddActionEventListener(*this);
88
89         SetFormBackEventListener(this);
90 }
91
92 result
93 FontForm::OnInitializing(void)
94 {
95         CreateHeader(ResourceManager::GetString(L"IDS_ST_BODY_FONT"));
96         CreateFooter();
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         if (pArgs != null)
126         {
127                 __categoryCheck = static_cast<String*>(pArgs->GetAt(0))->GetPointer();
128
129                 if (__categoryCheck.CompareTo(L"http://tizen.org/appcontrol/data/font/type") == 0)
130                 {
131                         SetAppControlRequest(APPCONTROL_REQUEST_FONT_TYPE);
132                         __pTableView->SetItemEnabled(ID_GROUP_FONT_SIZE, ID_ITEM_FONT_SIZE, false);
133                 }
134                 else if (__categoryCheck.Equals(L"http://tizen.org/appcontrol/data/font/size", false))
135                 {
136                         SetAppControlRequest(APPCONTROL_REQUEST_FONT_SIZE);
137                         __pTableView->SetItemEnabled(ID_GROUP_FONT, ID_ITEM_FONT_TYPE, false);
138                 }
139
140                 delete pArgs;
141         }
142         __pTableView->UpdateTableView();
143
144         String currentFontType;
145
146         if (SettingInfo::GetValue(SETTING_INFO_KEY_FONT_TYPE, currentFontType) == E_SUCCESS)
147         {
148                 for (int i = 0; i < __fontList->GetCount(); i++)
149                 {
150                         String itemMainText = static_cast<String*>(__fontList->GetAt(i))->GetPointer();
151
152                         if (itemMainText.Equals(currentFontType, false))
153                         {
154                                 __pTableView->SetItemChecked(ID_GROUP_FONT_LIST, i, true);
155                                 break;
156                         }
157                 }
158                 AppLogDebug("Get Font Type[%ls] :Result[%s]", currentFontType.GetPointer(), GetErrorMessage(GetLastResult()));
159         }
160         __pTableView->RefreshItem(ID_GROUP_FONT_SIZE, ID_ITEM_FONT_SIZE, TABLE_VIEW_REFRESH_TYPE_ITEM_MODIFY);
161         __pTableView->RefreshItem(ID_GROUP_FONT_LIST, ID_ITEM_FONT_TYPE, TABLE_VIEW_REFRESH_TYPE_ITEM_MODIFY);
162         __pTableView->RefreshItem(ID_GROUP_FONT, ID_ITEM_FONT_TYPE, TABLE_VIEW_REFRESH_TYPE_ITEM_MODIFY);
163 }
164
165 void
166 FontForm::OnSceneDeactivated(const Tizen::Ui::Scenes::SceneId& currentSceneId, const Tizen::Ui::Scenes::SceneId& nextSceneId)
167 {
168 }
169
170 void
171 FontForm::OnFormBackRequested(Tizen::Ui::Controls::Form& source)
172 {
173         SceneManager* pSceneManager = SceneManager::GetInstance();
174         AppAssert(pSceneManager);
175
176         __pTableView->CollapseGroup(ID_GROUP_FONT_LIST);
177         if (GetAppControlRequest() != APPCONTROL_DEFAULT)
178         {
179                 UiApp* pApp = UiApp::GetInstance();
180                 AppAssert(pApp);
181                 AppControlFontResult();
182                 pApp->Terminate();
183         }
184         else
185         {
186                 pSceneManager->GoBackward(BackwardSceneTransition(SCENE_TRANSITION_ANIMATION_TYPE_RIGHT), null);
187         }
188 }
189
190 int
191 FontForm::GetGroupCount(void)
192 {
193         AppLogDebug("ENTER");
194         return ID_GROUP_COUNT;
195 }
196
197 int
198 FontForm::GetItemCount(int groupIndex)
199 {
200         int itemCount = 0;
201
202         switch (groupIndex)
203         {
204         case ID_GROUP_FONT:
205            // fall through
206         case ID_GROUP_FONT_SIZE:
207                 {
208                         itemCount = ID_GROUP_MAX_ITEM_COUNT;
209                 }
210                 break;
211
212         case ID_GROUP_FONT_LIST:
213                 {
214                         itemCount = __fontList->GetCount();
215                 }
216                 break;
217
218         default:
219                 break;
220         }
221
222         AppLogDebug("GetItemCount %d", itemCount);
223
224         return itemCount;
225 }
226
227 TableViewGroupItem*
228 FontForm::CreateGroupItem(int groupIndex, int itemWidth)
229 {
230         AppLogDebug("ENTER");
231
232         int itemHeight = H_GROUP_INDEX_NO_TITLE_DEFAULT;
233         int yItemOffset = H_GROUP_INDEX_HELP_TEXT_TOP_GAP;
234         LabelTextStyle style = LABEL_TEXT_STYLE_NORMAL;
235         Rectangle itemMainRectangle;
236         String groupText;
237         Label* pLabel = null;
238         int fontSize = GetFontSize();
239
240         TableViewGroupItem* pItem = new (std::nothrow) TableViewGroupItem();
241
242         switch (groupIndex)
243         {
244         case ID_GROUP_FONT:
245                 {
246                         yItemOffset = H_GROUP_INDEX_NO_HELP_TEXT_GAP;
247                         itemHeight = H_GROUP_INDEX_NO_TITLE_DEFAULT;
248                 }
249                 break;
250
251         case ID_GROUP_FONT_LIST:
252                 {
253                         itemHeight = 0;
254                 }
255                 break;
256
257         case ID_GROUP_FONT_SIZE:
258                 // fall through
259         case ID_GROUP_FONT_TEXT:
260                 {
261                         itemHeight = 0;
262                 }
263                 break;
264
265         default:
266                 {
267                         yItemOffset = H_GROUP_INDEX_NO_HELP_TEXT_GAP;
268                         itemHeight = H_GROUP_INDEX_NO_TITLE_DEFAULT;
269                 }
270                 break;
271         }
272
273         itemMainRectangle.x = X_GROUP_ITEM_DEFAULT_LABEL;
274         itemMainRectangle.y = yItemOffset;
275         itemMainRectangle.width = itemWidth;
276         itemMainRectangle.height = itemHeight;
277
278         RelativeLayout relativeLayout;
279         relativeLayout.Construct();
280
281         pItem->Construct(relativeLayout, Dimension(itemWidth, itemHeight));
282         pItem->SetBackgroundColor(COLOR_BG_GROUP_INDEX_DEFAULT);
283
284         pLabel = new (std::nothrow) Label();
285         pLabel->Construct(itemMainRectangle, groupText);
286         pLabel->SetTextHorizontalAlignment(ALIGNMENT_LEFT);
287         pLabel->SetTextVerticalAlignment(ALIGNMENT_TOP);
288         pLabel->SetTextConfig(fontSize, style);
289         pLabel->SetTextColor(COLOR_HELP_TEXT_TYPE_01);
290
291         pItem->AddControl(pLabel);
292         relativeLayout.SetMargin(*pLabel, itemMainRectangle.x, RELATIVE_LAYOUT_RIGHT_MARGIN, 0, 0);
293         relativeLayout.SetRelation(*pLabel, pItem, RECT_EDGE_RELATION_LEFT_TO_LEFT);
294         relativeLayout.SetRelation(*pLabel, pItem, RECT_EDGE_RELATION_RIGHT_TO_RIGHT);
295         pItem->SetEnabled(false);
296
297         return pItem;
298 }
299
300 TableViewItem*
301 FontForm::CreateItem(int groupIndex, int itemIndex, int itemWidth)
302 {
303         AppLogDebug("group[%d] index[%d]", groupIndex, itemIndex);
304
305         Rectangle itemMainRectangle;
306         Rectangle itemSubRectangle;
307         TableViewAnnexStyle style = TABLE_VIEW_ANNEX_STYLE_NORMAL;
308         String itemMainText;
309         String itemSubText;
310         String fontReturnValue;
311         Label* pLabel = null;
312         Label* pLabelArrow = null;
313
314         int fontSize = GetFontSize();
315         bool isItemSubText = true;
316         int itemHeight = H_GROUP_ITEM_DEFAULT;
317         Rectangle detailArrow;
318         Bitmap* pBitmap = null;
319         char appControlRequest;
320
321         if (groupIndex == ID_GROUP_FONT_LIST)
322         {
323                 String currentFontType;
324                 isItemSubText = false;
325                 style = TABLE_VIEW_ANNEX_STYLE_RADIO;
326         }
327
328         GetTableViewItemString(groupIndex, itemIndex, itemMainText, itemSubText);
329
330         TableViewItem* pItem = new (std::nothrow) TableViewItem();
331
332         if (isItemSubText == true)
333         {
334                 ItemTypeTwoLine(itemMainRectangle, itemSubRectangle, fontSize);
335                 itemHeight = (itemMainRectangle.height + itemSubRectangle.height);
336
337                 RelativeLayout relativeLayout;
338                 relativeLayout.Construct();
339
340                 pItem->Construct(relativeLayout, Dimension(itemWidth, itemHeight), style);
341                 pItem->SetBackgroundColor(COLOR_BG_GROUP_ITEM_DEFAULT);
342
343                 pLabel = new (std::nothrow) Label();
344                 pLabel->Construct(itemMainRectangle, itemMainText);
345                 pLabel->SetTextHorizontalAlignment(ALIGNMENT_LEFT);
346                 pLabel->SetTextConfig(fontSize, LABEL_TEXT_STYLE_NORMAL);
347                 pLabel->SetTextColor(COLOR_MAIN_TEXT);
348
349                 pItem->AddControl(pLabel);
350                 relativeLayout.SetMargin(*pLabel, itemMainRectangle.x, RELATIVE_LAYOUT_RIGHT_MARGIN, 0, 0);
351                 relativeLayout.SetRelation(*pLabel, pItem, RECT_EDGE_RELATION_LEFT_TO_LEFT);
352
353                 if (groupIndex == ID_GROUP_FONT)
354                 {
355                         if (__pTableView->IsGroupExpanded(ID_GROUP_FONT_LIST))
356                         {
357                                 pBitmap = ResourceManager::GetBitmapN(IDB_DETAIL_BUTTON_EXPAND_OPENED);
358                         }
359                         else
360                         {
361                                 pBitmap = ResourceManager::GetBitmapN(IDB_DETAIL_BUTTON_EXPAND_CLOSED);
362                         }
363
364                         detailArrow = itemMainRectangle;
365                         detailArrow.y = itemMainRectangle.y + ((itemHeight - W_DETAIL_ARROW_BUTTON) / DIVIDE_BY_TWO);
366                         detailArrow.height = W_DETAIL_ARROW_BUTTON;
367                         detailArrow.width = W_DETAIL_ARROW_BUTTON;
368
369                         pLabelArrow = new (std::nothrow) Label();
370                         pLabelArrow->Construct(detailArrow, L"");
371
372                         pLabelArrow->SetBackgroundBitmap(*pBitmap);
373
374                         pItem->AddControl(pLabelArrow);
375                         relativeLayout.SetMargin(*pLabelArrow, itemMainRectangle.x, RELATIVE_LAYOUT_RIGHT_MARGIN_DETAIL_ARROW_BUTTON, 0, 0);
376                         relativeLayout.SetRelation(*pLabelArrow, pItem, RECT_EDGE_RELATION_RIGHT_TO_RIGHT);
377                         relativeLayout.SetRelation(*pLabel, pLabelArrow, RECT_EDGE_RELATION_RIGHT_TO_LEFT);
378                 }
379                 else
380                 {
381                         relativeLayout.SetRelation(*pLabel, pItem, RECT_EDGE_RELATION_RIGHT_TO_RIGHT);
382                 }
383
384                 pLabel = new (std::nothrow) Label();
385                 pLabel->Construct(itemSubRectangle, itemSubText);
386                 pLabel->SetTextHorizontalAlignment(ALIGNMENT_LEFT);
387                 pLabel->SetTextVerticalAlignment(ALIGNMENT_TOP);
388                 pLabel->SetTextConfig(FONT_SIZE_SUB_TEXT, LABEL_TEXT_STYLE_NORMAL);
389                 pLabel->SetTextColor(COLOR_SUB_TEXT);
390
391                 pItem->AddControl(pLabel);
392                 relativeLayout.SetMargin(*pLabel, itemSubRectangle.x, RELATIVE_LAYOUT_RIGHT_MARGIN, 0, 0);
393                 relativeLayout.SetRelation(*pLabel, pItem, RECT_EDGE_RELATION_LEFT_TO_LEFT);
394                 relativeLayout.SetRelation(*pLabel, pItem, RECT_EDGE_RELATION_RIGHT_TO_RIGHT);
395         }
396         else
397         {
398                 RelativeLayout relativeLayout;
399                 relativeLayout.Construct();
400
401                 pItem->Construct(relativeLayout, Dimension(itemWidth, H_GROUP_ITEM_DEFAULT), style);
402                 pItem->SetBackgroundColor(COLOR_BG_GROUP_ITEM_DEFAULT);
403
404                 ItemTypeOneLine(itemMainRectangle);
405                 pLabel = new (std::nothrow) Label();
406                 pLabel->Construct(itemMainRectangle, itemMainText);
407                 pLabel->SetTextHorizontalAlignment(ALIGNMENT_LEFT);
408                 pLabel->SetTextConfig(fontSize, LABEL_TEXT_STYLE_NORMAL);
409                 pLabel->SetTextColor(COLOR_MAIN_TEXT);
410
411                 pItem->AddControl(pLabel);
412                 relativeLayout.SetMargin(*pLabel, RELATIVE_LAYOUT_LEFT_MARGIN, RELATIVE_LAYOUT_RIGHT_MARGIN, 0, 0);
413                 relativeLayout.SetRelation(*pLabel, pItem, RECT_EDGE_RELATION_LEFT_TO_LEFT);
414                 relativeLayout.SetRelation(*pLabel, pItem, RECT_EDGE_RELATION_RIGHT_TO_RIGHT);
415         }
416
417         if ((appControlRequest = GetAppControlRequest()) != APPCONTROL_DEFAULT)
418         {
419                 if (appControlRequest & APPCONTROL_TYPE)
420                 {
421                         if (groupIndex == ID_GROUP_FONT_SIZE)
422                         {
423                                 delete pItem;
424                                 pItem = null;
425                         }
426                 }
427                 else if (appControlRequest & APPCONTROL_SIZE)
428                 {
429                         if ((groupIndex == ID_GROUP_FONT) || (groupIndex == ID_GROUP_FONT_LIST))
430                         {
431                                 delete pItem;
432                                 pItem = null;
433                         }
434                 }
435         }
436
437         return pItem;
438 }
439
440 bool
441 FontForm::DeleteGroupItem(int groupIndex, TableViewGroupItem* pItem)
442 {
443         AppLogDebug("ENTER");
444
445         delete pItem;
446         pItem = null;
447
448         return true;
449 }
450
451 bool
452 FontForm::DeleteItem(int groupIndex, int itemIndex, TableViewItem* pItem)
453 {
454         AppLogDebug("ENTER");
455
456         delete pItem;
457         pItem = null;
458
459         return true;
460 }
461
462 void
463 FontForm::OnGroupedTableViewItemStateChanged(Tizen::Ui::Controls::GroupedTableView& tableView, int groupIndex, int itemIndex, Tizen::Ui::Controls::TableViewItem* pItem, Tizen::Ui::Controls::TableViewItemStatus status)
464 {
465         AppLogDebug("group[%d] index[%d]", groupIndex, itemIndex);
466
467         SceneManager* pSceneManager = SceneManager::GetInstance();
468         AppAssert(pSceneManager);
469         String fontReturnValue;
470
471         switch (groupIndex)
472         {
473         case ID_GROUP_FONT:
474                 {
475                         if (__pTableView->IsGroupExpanded(ID_GROUP_FONT_LIST))
476                         {
477                                 __pTableView->CollapseGroup(ID_GROUP_FONT_LIST);
478                         }
479                         else
480                         {
481                                 __pTableView->ExpandGroup(ID_GROUP_FONT_LIST);
482                         }
483
484                         __pTableView->RefreshItem(groupIndex, itemIndex, TABLE_VIEW_REFRESH_TYPE_ITEM_MODIFY);
485                 }
486                 break;
487
488         case ID_GROUP_FONT_LIST:
489                 {
490                         int listCount = __fontList->GetCount();
491                         String fontGetValue;
492                         fontReturnValue = static_cast<String*>(__fontList->GetAt(itemIndex))->GetPointer();
493
494                         for (int count = 0; count < listCount; count++)
495                         {
496                                 if (itemIndex == count)
497                                 {
498                                         tableView.SetItemChecked(groupIndex, count, true);
499                                 }
500                                 else
501                                 {
502                                         tableView.SetItemChecked(groupIndex, count, false);
503                                 }
504                         }
505                         if ((SettingInfo::GetValue(SETTING_INFO_KEY_FONT_TYPE, fontGetValue)) == E_SUCCESS)
506                         {
507                                 if (fontGetValue.Equals(fontReturnValue, false))
508                                 {
509                                         break;
510                                 }
511                         }
512
513                         if (SettingInfo::SetValue(SETTING_INFO_KEY_FONT_TYPE, fontReturnValue) != E_SUCCESS)
514                         {
515                                 AppLogDebug("Set Font Type :Result[%s]", GetErrorMessage(GetLastResult()));
516                         }
517                         AppLogDebug("Set Font Type[%ls] :Result[%s]", fontReturnValue.GetPointer(), GetErrorMessage(GetLastResult()));
518                 }
519                 break;
520
521         case ID_GROUP_FONT_SIZE:
522                 {
523                         pSceneManager->GoForward(ForwardSceneTransition(IDSCN_FONT_SIZE, SCENE_TRANSITION_ANIMATION_TYPE_LEFT));
524                 }
525                 break;
526
527         default:
528                 break;
529         }
530 }
531
532 int
533 FontForm::GetDefaultGroupItemHeight(void)
534 {
535         return H_GROUP_INDEX_NO_TITLE_DEFAULT;
536 }
537
538 int
539 FontForm::GetDefaultItemHeight(void)
540 {
541         return H_GROUP_ITEM_DEFAULT;
542 }
543
544 void
545 FontForm::UpdateGroupItem(int groupIndex, Tizen::Ui::Controls::TableViewGroupItem* pItem)
546 {
547 }
548
549 void
550 FontForm::UpdateItem(int groupIndex, int itemIndex, Tizen::Ui::Controls::TableViewItem* pItem)
551 {
552         Rectangle itemMainRectangle;
553         Rectangle itemSubRectangle;
554         Rectangle pItemBounds = pItem->GetBounds();
555         int fontSize = GetFontSize();
556
557         switch (groupIndex)
558         {
559         case ID_GROUP_FONT:
560                 {
561                         ItemTypeTwoLine(itemMainRectangle, itemSubRectangle, fontSize);
562
563                         pItemBounds.height = itemMainRectangle.height + itemSubRectangle.height;
564                         pItem->SetBounds(pItemBounds);
565                         Label* pFirstLabel = static_cast<Label*>(pItem->GetControl(FONT_FORM_FIRST_CONTROL));
566                         Label* pSecondLabel = static_cast<Label*>(pItem->GetControl(FONT_FORM_SECOND_CONTROL));
567                         Label* pThirdLabel = static_cast<Label*>(pItem->GetControl(FONT_FORM_THIRD_CONTROL));
568                         Rectangle detailArrow = pSecondLabel->GetBounds();
569                         detailArrow.y = itemMainRectangle.y + ((pItemBounds.height - W_DETAIL_ARROW_BUTTON) / DIVIDE_BY_TWO);
570
571                         pFirstLabel->SetBounds(itemMainRectangle);
572                         pFirstLabel->SetTextConfig(fontSize, LABEL_TEXT_STYLE_NORMAL);
573                         pSecondLabel->SetBounds(detailArrow);
574                         pThirdLabel->SetBounds(itemSubRectangle);
575                         pThirdLabel->SetTextConfig(FONT_SIZE_SUB_TEXT, LABEL_TEXT_STYLE_NORMAL);
576
577                         Bitmap* pBitmap = null;
578
579                         if (__pTableView->IsGroupExpanded(ID_GROUP_FONT_LIST))
580                         {
581                                 pBitmap = ResourceManager::GetBitmapN(IDB_DETAIL_BUTTON_EXPAND_OPENED);
582                         }
583                         else
584                         {
585                                 pBitmap = ResourceManager::GetBitmapN(IDB_DETAIL_BUTTON_EXPAND_CLOSED);
586                         }
587                         pSecondLabel->SetBackgroundBitmap(*pBitmap);
588                         pSecondLabel->Invalidate(false);
589                         pFirstLabel->Invalidate(false);
590                         pItem->Invalidate(false);
591                         delete pBitmap;
592                 }
593                 break;
594
595         case ID_GROUP_FONT_SIZE:
596                 {
597                         ItemTypeTwoLine(itemMainRectangle, itemSubRectangle, fontSize);
598
599                         pItemBounds.height = itemMainRectangle.height + itemSubRectangle.height;
600                         pItem->SetBounds(pItemBounds);
601                         Label* pFirstLabel = static_cast<Label*>(pItem->GetControl(FONT_FORM_FIRST_CONTROL));
602                         Label* pSecondLabel = static_cast<Label*>(pItem->GetControl(FONT_FORM_SECOND_CONTROL));
603
604                         pFirstLabel->SetBounds(itemMainRectangle);
605                         pFirstLabel->SetTextConfig(fontSize, LABEL_TEXT_STYLE_NORMAL);
606                         pSecondLabel->SetBounds(itemSubRectangle);
607                         pSecondLabel->SetTextConfig(FONT_SIZE_SUB_TEXT, LABEL_TEXT_STYLE_NORMAL);
608
609                         String itemMainText = L"";
610                         String itemSubText = L"";
611
612                         GetTableViewItemString(groupIndex, itemIndex, itemMainText, itemSubText);
613                         pFirstLabel->SetText(itemMainText);
614                         pSecondLabel->SetText(itemSubText);
615
616                         pFirstLabel->Invalidate(false);
617                         pSecondLabel->Invalidate(false);
618                         pItem->Invalidate(false);
619                 }
620                 break;
621
622         case ID_GROUP_FONT_LIST:
623                 {
624                         ItemTypeOneLine(itemMainRectangle);
625                         Label* pFirstLabel = static_cast<Label*>(pItem->GetControl(0));
626                         pFirstLabel->SetBounds(itemMainRectangle);
627                         pFirstLabel->SetTextConfig(fontSize, LABEL_TEXT_STYLE_NORMAL);
628                         pFirstLabel->Invalidate(false);
629                 }
630                 break;
631
632         default:
633                 break;
634         }
635
636         Invalidate(true);
637 }
638
639 void
640 FontForm::OnGroupedTableViewContextItemActivationStateChanged(Tizen::Ui::Controls::GroupedTableView& tableView, int groupIndex, int itemIndex, Tizen::Ui::Controls::TableViewContextItem* pContextItem, bool activated)
641 {
642 }
643
644 void
645 FontForm::OnGroupedTableViewGroupItemStateChanged(Tizen::Ui::Controls::GroupedTableView& tableView, int groupIndex, Tizen::Ui::Controls::TableViewGroupItem* pItem, Tizen::Ui::Controls::TableViewItemStatus status)
646 {
647 }
648
649 void
650 FontForm::AppControlFontResult(void)
651 {
652         RequestId reqId = 0;
653         String value;
654         AppControlProviderManager* pAppManager = AppControlProviderManager::GetInstance();
655
656         HashMap* hashMap = new (std::nothrow) HashMap();
657         hashMap->Construct();
658
659         if (GetAppControlRequest() == APPCONTROL_REQUEST_FONT_TYPE)
660         {
661                 SettingInfo::GetValue(SETTING_INFO_KEY_FONT_TYPE, value);
662                 hashMap->Add(*(new (std::nothrow) String(L"http://tizen.org/appcontrol/data/font/type")), *(new (std::nothrow) String(value)));
663         }
664         else if (GetAppControlRequest() == APPCONTROL_REQUEST_FONT_SIZE)
665         {
666                 SettingInfo::GetValue(SETTING_INFO_KEY_FONT_SIZE, value);
667                 hashMap->Add(*(new (std::nothrow) String(L"http://tizen.org/appcontrol/data/font/size")), *(new (std::nothrow) String(value)));
668         }
669
670         pAppManager->SendAppControlResult(reqId, APP_CTRL_RESULT_SUCCEEDED, hashMap);
671
672         hashMap->RemoveAll();
673         delete hashMap;
674 }
675
676 result
677 FontForm::GetFontList(Tizen::Base::Collection::IList& list)
678 {
679         const String FONT_DIR_PATH[] =
680         {
681                 L"/usr/share/fonts"
682         };
683
684         list.RemoveAll(true);
685         const int FONT_DIR_PATH_COUNT = sizeof(FONT_DIR_PATH) / sizeof(FONT_DIR_PATH[0]);
686
687         for (int i = 0; i < FONT_DIR_PATH_COUNT; i++)
688         {
689                 Directory directory;
690                 result r = directory.Construct(FONT_DIR_PATH[i]);
691                 if (!IsFailed(r))
692                 {
693                         std::auto_ptr<DirEnumerator>dirEnumerator(directory.ReadN());
694
695                         while (dirEnumerator->MoveNext() == E_SUCCESS)
696                         {
697                                 DirEntry entry = dirEnumerator->GetCurrentDirEntry();
698                                 if (entry.IsDirectory() == false && entry.IsHidden() == false)
699                                 {
700                                         Tizen::Base::Utility::StringTokenizer formatTok(entry.GetName(), ".");
701                                         String token;
702                                         while (formatTok.GetTokenCount())
703                                         {
704                                                 formatTok.GetNextToken(token);
705                                         }
706
707                                         if (token.Equals("ttf", false) || token.Equals("ttc", false))
708                                         {
709                                                 String fullName;
710                                                 fullName.Append(FONT_DIR_PATH[i]);
711                                                 fullName.Append(L"/");
712                                                 fullName.Append(entry.GetName());
713                                                 bool isNewFont = true;
714
715                                                 String* pFamilyName = new (std::nothrow) String(Font::GetFaceName(fullName));
716
717                                                 for (int idx = 0; idx < list.GetCount(); idx++)
718                                                 {
719                                                         String* pName = static_cast <String*>(list.GetAt(idx));
720                                                         if (pName == null)
721                                                         {
722                                                                 continue;
723                                                         }
724                                                         if (pFamilyName->Equals(*pName, true))
725                                                         {
726                                                                 isNewFont = false;
727                                                                 break;
728                                                         }
729                                                 }
730                                                 if (isNewFont)
731                                                 {
732                                                         list.Add(*pFamilyName);
733                                                 }
734                                                 else
735                                                 {
736                                                         delete pFamilyName;
737                                                         pFamilyName = null;
738                                                 }
739                                         }
740                                 }
741                         }
742                 }
743         }
744         return E_SUCCESS;
745 }
746
747 void
748 FontForm::GetTableViewItemString(int groupIndex, int itemIndex, Tizen::Base::String& itemMainText, Tizen::Base::String& itemSubText)
749 {
750         switch (groupIndex)
751         {
752         case ID_GROUP_FONT:
753                 {
754                         String fontReturnValue;
755                         if ((SettingInfo::GetValue(SETTING_INFO_KEY_FONT_TYPE, fontReturnValue)) == E_SUCCESS)
756                         {
757                                 itemSubText = fontReturnValue;
758                         }
759                         itemMainText = ResourceManager::GetString(L"IDS_ST_BODY_FONT_TYPE");
760                 }
761                 break;
762
763         case ID_GROUP_FONT_LIST:
764                 {
765                         itemMainText = static_cast<String*>(__fontList->GetAt(itemIndex))->GetPointer();
766                         itemSubText = L"";
767                 }
768                 break;
769
770         case ID_GROUP_FONT_SIZE:
771                 {
772                         String fontReturnValue;
773                         if ((SettingInfo::GetValue(SETTING_INFO_KEY_FONT_SIZE, fontReturnValue)) == E_SUCCESS)
774                         {
775                                 if (fontReturnValue.Equals(L"giant", false))
776                                 {
777                                         itemSubText = ResourceManager::GetString(L"IDS_EMAIL_POP_GIANT_M_TEXTSIZE");
778                                 }
779                                 else if (fontReturnValue.Equals(L"huge", false))
780                                 {
781                                         itemSubText = ResourceManager::GetString(L"IDS_EMAIL_OPT_HUGE_M_TEXTSIZE");
782                                 }
783                                 else if (fontReturnValue.Equals(L"large", false))
784                                 {
785                                         itemSubText = ResourceManager::GetString(L"IDS_ST_BODY_TEXTSTYLE_LARGE");
786                                 }
787                                 else if (fontReturnValue.Equals(L"medium", false))
788                                 {
789                                         itemSubText = ResourceManager::GetString(L"IDS_ST_BODY_FONTTYPE_NORMAL");
790                                 }
791                                 else
792                                 {
793                                         itemSubText = ResourceManager::GetString(L"IDS_ST_BODY_SMALL_M_TEXTSIZE");
794                                 }
795                         }
796                         itemMainText = ResourceManager::GetString(L"IDS_ST_BODY_FONT_SIZE");
797                 }
798                 break;
799
800         default:
801                 break;
802         }
803 }
804
805 void
806 FontForm::OnSettingChanged (Tizen::Base::String &key)
807 {
808         AppLogDebug("FontForm::key changed [%ls]", key.GetPointer());
809
810         int groupCount = __pTableView->GetGroupCount();
811
812         for (int i = 0; i < groupCount; i++)
813         {
814                 int itemCount = __pTableView->GetItemCountAt(i);
815
816                 for (int j = 0; j < itemCount; j++)
817                 {
818                         __pTableView->RefreshItem(i, j, TABLE_VIEW_REFRESH_TYPE_ITEM_MODIFY);
819                 }
820         }
821 }
822
823 char
824 FontForm::GetAppControlRequest(void)
825 {
826         return __isAppControlRequest;
827 }
828
829 void
830 FontForm::SetAppControlRequest(char requestStatus)
831 {
832         __isAppControlRequest = requestStatus;
833 }