2 // Copyright (c) 2012 Samsung Electronics Co., Ltd.
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
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 StKeyboardSelectionForm.cpp
19 * @brief This is the implementation file for KeyboardSelectionForm class.
23 #include "StKeyboardSelectionForm.h"
24 #include "StResourceManager.h"
25 #include "StSettingScenesList.h"
28 using namespace Tizen::Base;
29 using namespace Tizen::Base::Collection;
30 using namespace Tizen::Graphics;
31 using namespace Tizen::Ui::Controls;
32 using namespace Tizen::Ui::Ime;
33 using namespace Tizen::Ui::Scenes;
35 static const int ID_GROUP_KEYBOARD_SOFTWARE = 0;
37 static const int ID_GROUP_KEYBOARD_HARDWARE = 1;
38 static const int ID_GROUP_KEYBOARD_HARDWARE_ITEM_COUNT = 2;
39 static const int ID_ITEM_KEYBOARD_HARDWARE_SELECT_KEYBOARD = 0;
40 static const int ID_ITEM_KEYBOARD_HARDWARE_KEYBOARD_SETTING = 1;
42 static const int ID_GROUP_COUNT = 1;
44 static const int GROUP_KEYBOARD_SOFTWARE_DEFAULT_COUNT = 1;
46 static const int ITEM_WIDE_GAP = 20;
48 KeyboardSelectionForm::KeyboardSelectionForm(void)
49 : __pInputMethodInfoList(null)
53 KeyboardSelectionForm::~KeyboardSelectionForm(void)
58 KeyboardSelectionForm::CreateFooter(void)
60 Footer* pFooter = GetFooter();
63 pFooter->SetStyle(FOOTER_STYLE_BUTTON_TEXT);
64 pFooter->AddActionEventListener(*this);
66 SetFormBackEventListener(this);
70 KeyboardSelectionForm::OnInitializing(void)
72 CreateHeader(ResourceManager::GetString(L"IDS_IME_BODY_KEYBOARD_SELECTION"));
75 return InitInputMethodInfoList();
79 KeyboardSelectionForm::OnTerminating(void)
81 if (__pInputMethodInfoList)
83 __pInputMethodInfoList->RemoveAll();
84 delete __pInputMethodInfoList;
85 __pInputMethodInfoList = null;
90 SetFormBackEventListener(null);
95 KeyboardSelectionForm::OnSceneActivatedN(const Tizen::Ui::Scenes::SceneId& previousSceneId, const Tizen::Ui::Scenes::SceneId& currentSceneId, Tizen::Base::Collection::IList* pArgs)
97 __pTableView->UpdateTableView();
101 KeyboardSelectionForm::OnSceneDeactivated(const Tizen::Ui::Scenes::SceneId& currentSceneId, const Tizen::Ui::Scenes::SceneId& nextSceneId)
106 KeyboardSelectionForm::OnFormBackRequested(Tizen::Ui::Controls::Form& source)
108 SceneManager* pSceneManager = SceneManager::GetInstance();
109 AppAssert(pSceneManager);
111 pSceneManager->GoBackward(BackwardSceneTransition(SCENE_TRANSITION_ANIMATION_TYPE_RIGHT), null);
115 KeyboardSelectionForm::GetGroupCount(void)
117 AppLogDebug("ENTER");
118 return ID_GROUP_COUNT;
122 KeyboardSelectionForm::GetItemCount(int groupIndex)
128 case ID_GROUP_KEYBOARD_SOFTWARE:
130 if (__pInputMethodInfoList != null)
132 itemCount = __pInputMethodInfoList->GetCount();
137 case ID_GROUP_KEYBOARD_HARDWARE:
139 itemCount = ID_GROUP_KEYBOARD_HARDWARE_ITEM_COUNT;
147 AppLogDebug("GetItemCount %d", itemCount);
152 KeyboardSelectionForm::CreateGroupItem(int groupIndex, int itemWidth)
154 AppLogDebug("ENTER");
156 int itemHeight = H_GROUP_INDEX_NO_TITLE_DEFAULT;
157 int yItemOffset = H_GROUP_INDEX_HELP_TEXT_TOP_GAP;
158 LabelTextStyle style = LABEL_TEXT_STYLE_BOLD;
159 Rectangle itemMainRectangle;
161 Label* pLabel = null;
163 TableViewGroupItem* pItem = new (std::nothrow) TableViewGroupItem();
167 case ID_GROUP_KEYBOARD_SOFTWARE:
169 yItemOffset = H_GROUP_INDEX_NO_HELP_TEXT_GAP;
171 groupText = ResourceManager::GetString(L"IDS_IME_BODY_SOFTWARE_KEYBOARD");
175 case ID_GROUP_KEYBOARD_HARDWARE:
177 yItemOffset = H_GROUP_INDEX_NO_HELP_TEXT_GAP;
178 itemHeight = H_GROUP_INDEX_DEFAULT;
179 groupText = ResourceManager::GetString(L"IDS_IME_BODY_HARDWARE_KEYBOARD");
187 itemMainRectangle.x = X_GROUP_ITEM_DEFAULT_LABEL;
188 itemMainRectangle.y = yItemOffset;
189 itemMainRectangle.width = itemWidth;
190 itemMainRectangle.height = itemHeight;
192 pItem->Construct(Dimension(itemWidth, itemHeight));
193 pItem->SetBackgroundColor(COLOR_BG_GROUP_INDEX_DEFAULT);
195 pLabel = new (std::nothrow) Label();
196 pLabel->Construct(itemMainRectangle, groupText);
197 pLabel->SetTextHorizontalAlignment(ALIGNMENT_LEFT);
198 pLabel->SetTextVerticalAlignment(ALIGNMENT_TOP);
199 pLabel->SetTextConfig(FONT_SIZE_GROUP_TITLE_TEXT, style);
200 pLabel->SetTextColor(COLOR_GROUP_TITLE_TEXT);
202 pItem->AddControl(pLabel);
203 pItem->SetEnabled(false);
209 KeyboardSelectionForm::CreateItem(int groupIndex, int itemIndex, int itemWidth)
211 Rectangle itemMainRectangle;
212 TableViewAnnexStyle style = TABLE_VIEW_ANNEX_STYLE_DETAILED;
214 Label* pLabel = null;
215 int fontSize = GetFontSize();
217 TableViewItem* pItem = new (std::nothrow) TableViewItem();
221 case ID_GROUP_KEYBOARD_SOFTWARE:
223 if (__pInputMethodInfoList == null)
229 InputMethodInfo* pInputMethodInfo = static_cast<InputMethodInfo*>(__pInputMethodInfoList->GetAt(itemIndex));
230 itemMainText = pInputMethodInfo->GetName();
234 case ID_GROUP_KEYBOARD_HARDWARE:
238 case ID_ITEM_KEYBOARD_HARDWARE_SELECT_KEYBOARD:
240 itemMainText = ResourceManager::GetString(L"IDS_IME_BODY_KEYBOARD_SELECTION");
244 case ID_ITEM_KEYBOARD_HARDWARE_KEYBOARD_SETTING:
246 itemMainText = ResourceManager::GetString(L"IDS_IME_BODY_KEYBOARD_SETTINGS");
260 ItemTypeOneLine(itemMainRectangle);
261 itemMainRectangle.width -= ITEM_WIDE_GAP;
262 pItem->Construct(Dimension(itemWidth, H_GROUP_ITEM_DEFAULT), style);
263 pItem->SetBackgroundColor(COLOR_BG_GROUP_ITEM_DEFAULT);
265 pLabel = new (std::nothrow) Label();
266 pLabel->Construct(itemMainRectangle, itemMainText);
267 pLabel->SetTextHorizontalAlignment(ALIGNMENT_LEFT);
268 pLabel->SetTextConfig(fontSize, LABEL_TEXT_STYLE_NORMAL);
269 pLabel->SetTextColor(COLOR_MAIN_TEXT);
271 pItem->AddControl(pLabel);
277 KeyboardSelectionForm::DeleteGroupItem(int groupIndex, TableViewGroupItem* pItem)
279 AppLogDebug("ENTER");
288 KeyboardSelectionForm::DeleteItem(int groupIndex, int itemIndex, TableViewItem* pItem)
297 KeyboardSelectionForm::OnGroupedTableViewItemStateChanged(Tizen::Ui::Controls::GroupedTableView& tableView, int groupIndex, int itemIndex, Tizen::Ui::Controls::TableViewItem* pItem, Tizen::Ui::Controls::TableViewItemStatus status)
299 SceneManager* pSceneManager = SceneManager::GetInstance();
300 AppAssert(pSceneManager);
302 if (__pInputMethodInfoList == null)
309 case ID_GROUP_KEYBOARD_SOFTWARE:
311 if (status == TABLE_VIEW_ITEM_STATUS_MORE)
313 IList* pList = __pInputMethodInfoList->GetItemsN(itemIndex, GROUP_KEYBOARD_SOFTWARE_DEFAULT_COUNT);
316 AppLogDebug("GetItemsN is null");
320 pSceneManager->GoForward(ForwardSceneTransition(IDSCN_KEYBOARD_INFO, SCENE_TRANSITION_ANIMATION_TYPE_LEFT), pList);
323 InputMethodManager* pInputMethodManager = InputMethodManager::GetInstance();
324 InputMethodInfo* pInputMethodInfo = static_cast<InputMethodInfo*>(__pInputMethodInfoList->GetAt(itemIndex));
325 if (pInputMethodInfo == null || pInputMethodManager == null)
327 AppLogDebug("pInputMethodInfo or pInputMethodManager is null");
330 result r = pInputMethodManager->SetInputMethod(pInputMethodInfo->GetAppId());
333 AppLogDebug("SetInputMethod(appId(%ls)) failed(%s)", pInputMethodInfo->GetAppId().GetPointer(), GetErrorMessage(r));
335 pSceneManager->GoBackward(BackwardSceneTransition(SCENE_TRANSITION_ANIMATION_TYPE_RIGHT), null);
339 case ID_GROUP_KEYBOARD_HARDWARE:
341 if (itemIndex == ID_ITEM_KEYBOARD_HARDWARE_SELECT_KEYBOARD)
343 // TODO: nothing todo yet.
346 if (itemIndex == ID_ITEM_KEYBOARD_HARDWARE_KEYBOARD_SETTING)
348 // TODO: nothing todo yet.
359 KeyboardSelectionForm::GetDefaultGroupItemHeight(void)
361 return H_GROUP_INDEX_NO_TITLE_DEFAULT;
365 KeyboardSelectionForm::GetDefaultItemHeight(void)
367 return H_GROUP_ITEM_DEFAULT;
371 KeyboardSelectionForm::UpdateGroupItem(int groupIndex, Tizen::Ui::Controls::TableViewGroupItem* pItem)
376 KeyboardSelectionForm::UpdateItem(int groupIndex, int itemIndex, Tizen::Ui::Controls::TableViewItem* pItem)
381 KeyboardSelectionForm::OnGroupedTableViewContextItemActivationStateChanged(Tizen::Ui::Controls::GroupedTableView& tableView, int groupIndex, int itemIndex, Tizen::Ui::Controls::TableViewContextItem* pContextItem, bool activated)
386 KeyboardSelectionForm::OnGroupedTableViewGroupItemStateChanged(Tizen::Ui::Controls::GroupedTableView& tableView, int groupIndex, Tizen::Ui::Controls::TableViewGroupItem* pItem, Tizen::Ui::Controls::TableViewItemStatus status)
391 KeyboardSelectionForm::InitInputMethodInfoList(void)
393 InputMethodManager* pInputMethodManager = InputMethodManager::GetInstance();
394 __pInputMethodInfoList = pInputMethodManager->GetInputMethodInfoListN();
395 if (__pInputMethodInfoList == null)
404 KeyboardSelectionForm::OnOrientationChanged(const Tizen::Ui::Control& source, Tizen::Ui::OrientationStatus orientationStatus)
406 BaseForm::OnOrientationChanged(source, orientationStatus);
407 __pTableView->UpdateTableView();