2 // Copyright (c) 2012 Samsung Electronics Co., Ltd.
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
8 // http://floralicense.org/license/
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.
18 * @file StFontForm.cpp
19 * @brief This is the implementation file for FontForm class.
24 #include "StFontForm.h"
25 #include "StResourceManager.h"
26 #include "StSettingScenesList.h"
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;
40 static const int ID_GROUP_FONT = 0;
41 static const int ID_GROUP_FONT_ITEM_COUNT = 2;
42 static const int ID_ITEM_FONT_TYPE = 0;
43 static const int ID_ITEM_FONT_SIZE = 1;
45 static const int ID_GROUP_FONT_TEXT = 1;
46 static const int ID_GROUP_FONT_TEXT_ITEM_COUNT = 0;
48 static const int ID_GROUP_COUNT = 2;
49 static const int ID_GROUP_MAX_ITEM_COUNT = ID_GROUP_FONT_ITEM_COUNT;
52 static const int ID_GROUP_FONT = 0;
53 static const int ID_GROUP_FONT_ITEM_COUNT = 1;
54 static const int ID_ITEM_FONT_TYPE = 0;
56 static const int ID_GROUP_FONT_LIST = 1;
58 static const int ID_GROUP_FONT_SIZE = 2;
59 static const int ID_GROUP_FONT_SIZE_ITEM_COUNT = 1;
60 static const int ID_ITEM_FONT_SIZE = 0;
62 static const int ID_GROUP_FONT_TEXT = 3;
63 static const int ID_GROUP_FONT_TEXT_ITEM_COUNT = 0;
65 static const int ID_GROUP_COUNT = 4;
66 static const int ID_GROUP_MAX_ITEM_COUNT = ID_GROUP_FONT_ITEM_COUNT;
68 static const int H_HELP_TEXT_GAP = 6;
70 FontForm::FontForm(void)
71 : __isAppControlRequest(false)
72 , __categoryCheck(L"")
73 , __isFontTypeExpend(false)
77 FontForm::~FontForm(void)
82 FontForm::CreateFooter(void)
84 Footer* pFooter = GetFooter();
87 pFooter->SetStyle(FOOTER_STYLE_BUTTON_TEXT);
88 pFooter->SetBackButton();
89 pFooter->AddActionEventListener(*this);
91 SetFormBackEventListener(this);
95 FontForm::OnInitializing(void)
97 CreateHeader(ResourceManager::GetString(L"IDS_ST_BODY_FONT"));
100 __fontList = new (std::nothrow) ArrayList(SingleObjectDeleter);
101 __fontList->Construct();
102 GetFontList(*__fontList);
106 AppLogDebug("ENTER");
112 FontForm::OnTerminating(void)
117 SetFormBackEventListener(null);
122 FontForm::OnSceneActivatedN(const Tizen::Ui::Scenes::SceneId& previousSceneId, const Tizen::Ui::Scenes::SceneId& currentSceneId, Tizen::Base::Collection::IList* pArgs)
124 __pTableView->UpdateTableView();
127 __categoryCheck = static_cast<String*>(pArgs->GetAt(0))->GetPointer();
129 if ((__categoryCheck == L"category:FontType") || (__categoryCheck == L"category:FontSize"))
131 SetAppControlRequest(true);
133 if (__categoryCheck.Equals(L"category:FontType", false))
135 __pTableView->SetItemEnabled(ID_GROUP_FONT_SIZE, ID_ITEM_FONT_SIZE, false);
139 __pTableView->SetItemEnabled(ID_GROUP_FONT, ID_ITEM_FONT_TYPE, false);
142 __pTableView->UpdateTableView();
146 String currentFontType;
148 if (SettingInfo::GetValue(SETTING_INFO_KEY_FONT_TYPE, currentFontType) == E_SUCCESS)
150 for (int i = 0; i < __fontList->GetCount(); i++)
152 String itemText = static_cast<String*>(__fontList->GetAt(i))->GetPointer();
154 if (itemText.Equals(currentFontType, false))
156 __pTableView->SetItemChecked(ID_GROUP_FONT_LIST, i, true);
160 AppLogDebug("Get Font Type[%ls] :Result[%s]", currentFontType.GetPointer(), GetErrorMessage(GetLastResult()));
162 __pTableView->CollapseGroup(ID_GROUP_FONT_LIST);
166 FontForm::OnSceneDeactivated(const Tizen::Ui::Scenes::SceneId& currentSceneId, const Tizen::Ui::Scenes::SceneId& nextSceneId)
171 FontForm::OnFormBackRequested(Tizen::Ui::Controls::Form& source)
173 SceneManager* pSceneManager = SceneManager::GetInstance();
174 AppAssert(pSceneManager);
176 if (GetAppControlRequest() == true)
178 UiApp* pApp = UiApp::GetInstance();
180 AppControlFontResult();
185 pSceneManager->GoBackward(BackwardSceneTransition(SCENE_TRANSITION_ANIMATION_TYPE_RIGHT), null);
190 FontForm::GetGroupCount(void)
192 AppLogDebug("ENTER");
193 return ID_GROUP_COUNT;
197 FontForm::GetItemCount(int groupIndex)
205 case ID_GROUP_FONT_SIZE:
207 itemCount = ID_GROUP_MAX_ITEM_COUNT;
211 case ID_GROUP_FONT_LIST:
213 itemCount = __fontList->GetCount();
221 AppLogDebug("GetItemCount %d", itemCount);
227 FontForm::CreateGroupItem(int groupIndex, int itemWidth)
229 AppLogDebug("ENTER");
231 int itemHeight = H_GROUP_INDEX_NO_TITLE_DEFAULT;
232 int yItemOffset = H_GROUP_INDEX_HELP_TEXT_TOP_GAP;
233 LabelTextStyle style = LABEL_TEXT_STYLE_NORMAL;
234 Rectangle itemRectangle;
236 Label* pLabel = null;
237 int fontSize = GetFontSize();
239 TableViewGroupItem* pItem = new (std::nothrow) TableViewGroupItem();
245 yItemOffset = H_GROUP_INDEX_NO_HELP_TEXT_GAP;
246 itemHeight = H_GROUP_INDEX_NO_TITLE_DEFAULT;
250 case ID_GROUP_FONT_LIST:
256 case ID_GROUP_FONT_SIZE:
258 case ID_GROUP_FONT_TEXT:
266 yItemOffset = H_GROUP_INDEX_NO_HELP_TEXT_GAP;
267 itemHeight = H_GROUP_INDEX_NO_TITLE_DEFAULT;
272 itemRectangle.x = X_GROUP_ITEM_DEFAULT_LABEL;
273 itemRectangle.y = yItemOffset;
274 itemRectangle.width = itemWidth;
275 itemRectangle.height = itemHeight;
277 RelativeLayout relativeLayout;
278 relativeLayout.Construct();
280 pItem->Construct(relativeLayout, Dimension(itemWidth, itemHeight));
281 pItem->SetBackgroundColor(COLOR_BG_GROUP_INDEX_DEFAULT);
283 pLabel = new (std::nothrow) Label();
284 pLabel->Construct(itemRectangle, groupText);
285 pLabel->SetTextHorizontalAlignment(ALIGNMENT_LEFT);
286 pLabel->SetTextVerticalAlignment(ALIGNMENT_TOP);
287 pLabel->SetTextConfig(fontSize, style);
288 pLabel->SetTextColor(COLOR_HELP_TEXT_TYPE_01);
290 pItem->AddControl(*pLabel);
291 relativeLayout.SetMargin(*pLabel, itemRectangle.x, RELATIVE_LAYOUT_RIGHT_MARGIN, 0, 0);
292 relativeLayout.SetRelation(*pLabel, *pItem, RECT_EDGE_RELATION_LEFT_TO_LEFT);
293 relativeLayout.SetRelation(*pLabel, *pItem, RECT_EDGE_RELATION_RIGHT_TO_RIGHT);
294 pItem->SetEnabled(false);
300 FontForm::CreateItem(int groupIndex, int itemIndex, int itemWidth)
302 AppLogDebug("group[%d] index[%d]", groupIndex, itemIndex);
304 Rectangle itemRectangle;
305 Rectangle itemSecondLineTextRect;
306 TableViewAnnexStyle style = TABLE_VIEW_ANNEX_STYLE_NORMAL;
308 String secondLineText;
309 String fontReturnValue;
310 Label* pLabel = null;
311 int fontSize = GetFontSize();
312 bool isTwoLineText = true;
313 int itemHeight = H_GROUP_ITEM_DEFAULT;
319 style = TABLE_VIEW_ANNEX_STYLE_DETAILED;
320 if ((SettingInfo::GetValue(SETTING_INFO_KEY_FONT_TYPE, fontReturnValue)) == E_SUCCESS)
322 secondLineText = fontReturnValue;
324 itemText = ResourceManager::GetString(L"IDS_ST_BODY_FONT_TYPE");
328 case ID_GROUP_FONT_LIST:
330 String currentFontType;
331 isTwoLineText = false;
332 style = TABLE_VIEW_ANNEX_STYLE_RADIO;
333 itemText = static_cast<String*>(__fontList->GetAt(itemIndex))->GetPointer();
335 if (SettingInfo::GetValue(SETTING_INFO_KEY_FONT_TYPE, currentFontType) == E_SUCCESS)
337 if (itemText.Equals(currentFontType, false))
339 __pTableView->SetItemChecked(groupIndex, itemIndex, true);
342 AppLogDebug("Get Font Type[%ls] :Result[%s]", currentFontType.GetPointer(), GetErrorMessage(GetLastResult()));
346 case ID_GROUP_FONT_SIZE:
348 if ((SettingInfo::GetValue(SETTING_INFO_KEY_FONT_SIZE, fontReturnValue)) == E_SUCCESS)
350 if (fontReturnValue.Equals(L"giant", false))
352 secondLineText = ResourceManager::GetString(L"IDS_EMAIL_POP_GIANT_M_TEXTSIZE");
354 else if (fontReturnValue.Equals(L"huge", false))
356 secondLineText = ResourceManager::GetString(L"IDS_EMAIL_OPT_HUGE_M_TEXTSIZE");
358 else if (fontReturnValue.Equals(L"large", false))
360 secondLineText = ResourceManager::GetString(L"IDS_ST_BODY_TEXTSTYLE_LARGE");
362 else if (fontReturnValue.Equals(L"medium", false))
364 secondLineText = ResourceManager::GetString(L"IDS_ST_BODY_FONTTYPE_NORMAL");
368 secondLineText = ResourceManager::GetString(L"IDS_ST_BODY_SMALL_M_TEXTSIZE");
371 itemText = ResourceManager::GetString(L"IDS_ST_BODY_FONT_SIZE");
379 TableViewItem* pItem = new (std::nothrow) TableViewItem();
381 if (isTwoLineText == true )
383 ItemTypeTwoLine(itemRectangle, itemSecondLineTextRect, fontSize);
384 itemHeight = (itemRectangle.height + itemSecondLineTextRect.height);
386 RelativeLayout relativeLayout;
387 relativeLayout.Construct();
389 pItem->Construct(relativeLayout, Dimension(itemWidth, itemHeight), style);
390 pItem->SetBackgroundColor(COLOR_BG_GROUP_ITEM_DEFAULT);
392 pLabel = new (std::nothrow) Label();
393 pLabel->Construct(itemRectangle, itemText);
394 pLabel->SetTextHorizontalAlignment(ALIGNMENT_LEFT);
395 pLabel->SetTextConfig(fontSize, LABEL_TEXT_STYLE_NORMAL);
396 pLabel->SetTextColor(COLOR_MAIN_TEXT);
398 pItem->AddControl(*pLabel);
399 relativeLayout.SetMargin(*pLabel, itemRectangle.x, RELATIVE_LAYOUT_RIGHT_MARGIN, 0, 0);
400 relativeLayout.SetRelation(*pLabel, *pItem, RECT_EDGE_RELATION_LEFT_TO_LEFT);
401 relativeLayout.SetRelation(*pLabel, *pItem, RECT_EDGE_RELATION_RIGHT_TO_RIGHT);
403 pLabel = new (std::nothrow) Label();
404 pLabel->Construct(itemSecondLineTextRect, secondLineText);
405 pLabel->SetTextHorizontalAlignment(ALIGNMENT_LEFT);
406 pLabel->SetTextVerticalAlignment(ALIGNMENT_TOP);
407 pLabel->SetTextConfig(FONT_SIZE_SUB_TEXT, LABEL_TEXT_STYLE_NORMAL);
408 pLabel->SetTextColor(COLOR_SUB_TEXT);
410 pItem->AddControl(*pLabel);
411 relativeLayout.SetMargin(*pLabel, itemSecondLineTextRect.x, RELATIVE_LAYOUT_RIGHT_MARGIN, 0, 0);
412 relativeLayout.SetRelation(*pLabel, *pItem, RECT_EDGE_RELATION_LEFT_TO_LEFT);
413 relativeLayout.SetRelation(*pLabel, *pItem, RECT_EDGE_RELATION_RIGHT_TO_RIGHT);
417 RelativeLayout relativeLayout;
418 relativeLayout.Construct();
420 pItem->Construct(relativeLayout, Dimension(itemWidth, H_GROUP_ITEM_DEFAULT), style);
421 pItem->SetBackgroundColor(COLOR_BG_GROUP_ITEM_DEFAULT);
423 ItemTypeOneLine(itemRectangle);
424 pLabel = new (std::nothrow) Label();
425 pLabel->Construct(itemRectangle, itemText);
426 pLabel->SetTextHorizontalAlignment(ALIGNMENT_LEFT);
427 pLabel->SetTextConfig(fontSize, LABEL_TEXT_STYLE_NORMAL);
428 pLabel->SetTextColor(COLOR_MAIN_TEXT);
430 pItem->AddControl(*pLabel);
431 relativeLayout.SetMargin(*pLabel, RELATIVE_LAYOUT_LEFT_MARGIN, RELATIVE_LAYOUT_RIGHT_MARGIN, 0, 0);
432 relativeLayout.SetRelation(*pLabel, *pItem, RECT_EDGE_RELATION_LEFT_TO_LEFT);
433 relativeLayout.SetRelation(*pLabel, *pItem, RECT_EDGE_RELATION_RIGHT_TO_RIGHT);
436 if (GetAppControlRequest() == true)
438 if (__categoryCheck.Equals(L"category:FontType", false))
440 if (groupIndex == ID_GROUP_FONT_SIZE)
446 else if (__categoryCheck.Equals(L"category:FontSize", false))
448 if ((groupIndex == ID_GROUP_FONT) || (groupIndex == ID_GROUP_FONT_LIST))
460 FontForm::DeleteGroupItem(int groupIndex, TableViewGroupItem* pItem)
462 AppLogDebug("ENTER");
471 FontForm::DeleteItem(int groupIndex, int itemIndex, TableViewItem* pItem)
473 AppLogDebug("ENTER");
482 FontForm::OnGroupedTableViewItemStateChanged(Tizen::Ui::Controls::GroupedTableView& tableView, int groupIndex, int itemIndex, Tizen::Ui::Controls::TableViewItem* pItem, Tizen::Ui::Controls::TableViewItemStatus status)
484 AppLogDebug("group[%d] index[%d]", groupIndex, itemIndex);
486 SceneManager* pSceneManager = SceneManager::GetInstance();
487 AppAssert(pSceneManager);
488 String fontReturnValue;
494 if(__pTableView->IsGroupExpanded(ID_GROUP_FONT_LIST))
496 __pTableView->CollapseGroup(ID_GROUP_FONT_LIST);
500 __pTableView->ExpandGroup(ID_GROUP_FONT_LIST);
505 case ID_GROUP_FONT_LIST:
507 int listCount = __fontList->GetCount();
509 fontReturnValue = static_cast<String*>(__fontList->GetAt(itemIndex))->GetPointer();
511 tableView.UpdateTableView();
513 for (int count = 0; count < listCount; count++)
515 if (itemIndex == count)
517 tableView.SetItemChecked(groupIndex, count, true);
521 tableView.SetItemChecked(groupIndex, count, false);
524 if ((SettingInfo::GetValue(SETTING_INFO_KEY_FONT_TYPE, fontGetValue)) == E_SUCCESS)
526 if (fontGetValue.Equals(fontReturnValue, false))
532 if (SettingInfo::SetValue(SETTING_INFO_KEY_FONT_TYPE, fontReturnValue) != E_SUCCESS)
534 AppLogDebug("Set Font Type :Result[%s]", GetErrorMessage(GetLastResult()));
536 AppLogDebug("Set Font Type[%ls] :Result[%s]", fontReturnValue.GetPointer(), GetErrorMessage(GetLastResult()));
540 case ID_GROUP_FONT_SIZE:
542 pSceneManager->GoForward(ForwardSceneTransition(IDSCN_FONT_SIZE, SCENE_TRANSITION_ANIMATION_TYPE_LEFT));
552 FontForm::GetDefaultGroupItemHeight(void)
554 return H_GROUP_INDEX_NO_TITLE_DEFAULT;
558 FontForm::GetDefaultItemHeight(void)
560 return H_GROUP_ITEM_DEFAULT;
564 FontForm::UpdateGroupItem(int groupIndex, Tizen::Ui::Controls::TableViewGroupItem* pItem)
569 FontForm::UpdateItem(int groupIndex, int itemIndex, Tizen::Ui::Controls::TableViewItem* pItem)
574 FontForm::OnGroupedTableViewContextItemActivationStateChanged(Tizen::Ui::Controls::GroupedTableView& tableView, int groupIndex, int itemIndex, Tizen::Ui::Controls::TableViewContextItem* pContextItem, bool activated)
579 FontForm::OnGroupedTableViewGroupItemStateChanged(Tizen::Ui::Controls::GroupedTableView& tableView, int groupIndex, Tizen::Ui::Controls::TableViewGroupItem* pItem, Tizen::Ui::Controls::TableViewItemStatus status)
584 FontForm::AppControlFontResult(void)
588 AppControlProviderManager* pAppManager = AppControlProviderManager::GetInstance();
591 IList* pDefaultResultIList = null;
592 ArrayList* pDataList = null;
594 pDataList = new (std::nothrow) ArrayList();
595 pDataList->Construct();
597 pDataList->Add(*(new (std::nothrow) String(L"APPCONTROL_RESULT_SUCCEEDED")));
598 pDataList->Add(*(new (std::nothrow) String(__categoryCheck)));
600 if (__categoryCheck == L"category:FontType")
602 SettingInfo::GetValue(SETTING_INFO_KEY_FONT_TYPE, value);
604 else if (__categoryCheck == L"category:FontSize")
606 SettingInfo::GetValue(SETTING_INFO_KEY_FONT_SIZE, value);
608 pDataList->Add(*(new (std::nothrow) String(value)));
610 pDefaultResultIList = (pDataList->GetItemsN(0, pDataList->GetCount()));
612 pAppManager->SendAppControlResult(reqId, pDefaultResultIList);
614 pDataList->RemoveAll(true);
616 pDefaultResultIList->RemoveAll(true);
617 delete pDefaultResultIList;
619 HashMap* hashMap = new (std::nothrow) HashMap();
620 hashMap->Construct();
622 if (__categoryCheck == L"category:FontType")
624 SettingInfo::GetValue(SETTING_INFO_KEY_FONT_TYPE, value);
625 hashMap->Add(*(new (std::nothrow) String(L"category")), *(new (std::nothrow) String(L"FontType")));
626 hashMap->Add(*(new (std::nothrow) String(L"type")), *(new (std::nothrow) String(value)));
629 else if (__categoryCheck == L"category:FontSize")
631 SettingInfo::GetValue(SETTING_INFO_KEY_FONT_SIZE, value);
632 hashMap->Add(*(new (std::nothrow) String(L"category")), *(new (std::nothrow) String(L"FontSize")));
633 hashMap->Add(*(new (std::nothrow) String(L"size")), *(new (std::nothrow) String(value)));
636 pAppManager->SendAppControlResult(reqId, APP_CTRL_RESULT_SUCCEEDED, hashMap);
638 hashMap->RemoveAll();
644 FontForm::GetFontList(Tizen::Base::Collection::IList& list)
646 const String FONT_DIR_PATH[] =
651 list.RemoveAll(true);
652 const int FONT_DIR_PATH_COUNT = sizeof(FONT_DIR_PATH) / sizeof(FONT_DIR_PATH[0]);
654 for (int i = 0; i < FONT_DIR_PATH_COUNT; i++)
657 result r = directory.Construct(FONT_DIR_PATH[i]);
660 std::auto_ptr<DirEnumerator>dirEnumerator(directory.ReadN());
662 while (dirEnumerator->MoveNext() == E_SUCCESS)
664 DirEntry entry = dirEnumerator->GetCurrentDirEntry();
665 if (entry.IsDirectory() == false && entry.IsHidden() == false)
667 Tizen::Base::Utility::StringTokenizer formatTok(entry.GetName(), ".");
669 while (formatTok.GetTokenCount())
671 formatTok.GetNextToken(token);
674 if (token.Equals("ttf",false) || token.Equals("ttc",false))
677 fullName.Append(FONT_DIR_PATH[i]);
678 fullName.Append(L"/");
679 fullName.Append(entry.GetName());
680 bool isNewFont = true;
682 String* pFamilyName = new (std::nothrow) String(Font::GetFaceName(fullName));
684 for (int idx = 0; idx < list.GetCount(); idx++)
686 String* pName = static_cast <String*>(list.GetAt(idx));
691 if (pFamilyName->Equals(*pName, true))
699 list.Add(*pFamilyName);
715 FontForm::GetAppControlRequest(void)
717 return __isAppControlRequest;
721 FontForm::SetAppControlRequest(bool requestStatus)
723 __isAppControlRequest = requestStatus;