Applied latest source code
[apps/native/preloaded/Settings.git] / src / StKeyboardSelectionForm.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                StKeyboardSelectionForm.cpp
19  * @brief               This is the implementation file for KeyboardSelectionForm class.
20  */
21
22 #include <FUiIme.h>
23 #include "StKeyboardSelectionForm.h"
24 #include "StResourceManager.h"
25 #include "StSettingScenesList.h"
26 #include "StTypes.h"
27
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;
34
35 static const int ID_GROUP_KEYBOARD_SOFTWARE = 0;
36
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;
41
42 static const int ID_GROUP_COUNT = 1;
43
44 static const int GROUP_KEYBOARD_SOFTWARE_DEFAULT_COUNT = 1;
45
46 static const int ITEM_WIDE_GAP = 20;
47
48 KeyboardSelectionForm::KeyboardSelectionForm(void)
49         : __pInputMethodInfoList(null)
50 {
51 }
52
53 KeyboardSelectionForm::~KeyboardSelectionForm(void)
54 {
55 }
56
57 void
58 KeyboardSelectionForm::CreateFooter(void)
59 {
60         Footer* pFooter = GetFooter();
61         AppAssert(pFooter);
62
63         pFooter->SetStyle(FOOTER_STYLE_BUTTON_TEXT);
64         pFooter->AddActionEventListener(*this);
65
66         SetFormBackEventListener(this);
67 }
68
69 result
70 KeyboardSelectionForm::OnInitializing(void)
71 {
72         CreateHeader(ResourceManager::GetString(L"IDS_IME_BODY_KEYBOARD_SELECTION"));
73         CreateTableView();
74
75         return InitInputMethodInfoList();
76 }
77
78 result
79 KeyboardSelectionForm::OnTerminating(void)
80 {
81         if (__pInputMethodInfoList)
82         {
83                 __pInputMethodInfoList->RemoveAll();
84                 delete __pInputMethodInfoList;
85                 __pInputMethodInfoList = null;
86         }
87
88         __pTableView = null;
89
90         SetFormBackEventListener(null);
91         return E_SUCCESS;
92 }
93
94 void
95 KeyboardSelectionForm::OnSceneActivatedN(const Tizen::Ui::Scenes::SceneId& previousSceneId, const Tizen::Ui::Scenes::SceneId& currentSceneId, Tizen::Base::Collection::IList* pArgs)
96 {
97         __pTableView->UpdateTableView();
98 }
99
100 void
101 KeyboardSelectionForm::OnSceneDeactivated(const Tizen::Ui::Scenes::SceneId& currentSceneId, const Tizen::Ui::Scenes::SceneId& nextSceneId)
102 {
103 }
104
105 void
106 KeyboardSelectionForm::OnFormBackRequested(Tizen::Ui::Controls::Form& source)
107 {
108         SceneManager* pSceneManager = SceneManager::GetInstance();
109         AppAssert(pSceneManager);
110
111         pSceneManager->GoBackward(BackwardSceneTransition(SCENE_TRANSITION_ANIMATION_TYPE_RIGHT), null);
112 }
113
114 int
115 KeyboardSelectionForm::GetGroupCount(void)
116 {
117         AppLogDebug("ENTER");
118         return ID_GROUP_COUNT;
119 }
120
121 int
122 KeyboardSelectionForm::GetItemCount(int groupIndex)
123 {
124         int itemCount = 0;
125
126         switch (groupIndex)
127         {
128         case ID_GROUP_KEYBOARD_SOFTWARE:
129                 {
130                         if (__pInputMethodInfoList != null)
131                         {
132                                 itemCount = __pInputMethodInfoList->GetCount();
133                         }
134                 }
135                 break;
136
137         case ID_GROUP_KEYBOARD_HARDWARE:
138                 {
139                         itemCount = ID_GROUP_KEYBOARD_HARDWARE_ITEM_COUNT;
140                 }
141                 break;
142
143         default:
144                 break;
145         }
146
147         AppLogDebug("GetItemCount %d", itemCount);
148         return itemCount;
149 }
150
151 TableViewGroupItem*
152 KeyboardSelectionForm::CreateGroupItem(int groupIndex, int itemWidth)
153 {
154         AppLogDebug("ENTER");
155
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;
160         String groupText;
161         Label* pLabel = null;
162
163         TableViewGroupItem* pItem = new (std::nothrow) TableViewGroupItem();
164
165         switch (groupIndex)
166         {
167         case ID_GROUP_KEYBOARD_SOFTWARE:
168                 {
169                         yItemOffset = H_GROUP_INDEX_NO_HELP_TEXT_GAP;
170                         itemHeight = 0;
171                         groupText = ResourceManager::GetString(L"IDS_IME_BODY_SOFTWARE_KEYBOARD");
172                 }
173                 break;
174
175         case ID_GROUP_KEYBOARD_HARDWARE:
176                 {
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");
180                 }
181                 break;
182
183         default:
184                 break;
185         }
186
187         itemMainRectangle.x = X_GROUP_ITEM_DEFAULT_LABEL;
188         itemMainRectangle.y = yItemOffset;
189         itemMainRectangle.width = itemWidth;
190         itemMainRectangle.height = itemHeight;
191
192         pItem->Construct(Dimension(itemWidth, itemHeight));
193         pItem->SetBackgroundColor(COLOR_BG_GROUP_INDEX_DEFAULT);
194
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);
201
202         pItem->AddControl(pLabel);
203         pItem->SetEnabled(false);
204
205         return pItem;
206 }
207
208 TableViewItem*
209 KeyboardSelectionForm::CreateItem(int groupIndex, int itemIndex, int itemWidth)
210 {
211         Rectangle itemMainRectangle;
212         TableViewAnnexStyle style = TABLE_VIEW_ANNEX_STYLE_DETAILED;
213         String itemMainText;
214         Label* pLabel = null;
215         int fontSize = GetFontSize();
216
217         TableViewItem* pItem = new (std::nothrow) TableViewItem();
218
219         switch (groupIndex)
220         {
221         case ID_GROUP_KEYBOARD_SOFTWARE:
222                 {
223                         if (__pInputMethodInfoList == null)
224                         {
225                                 delete pItem;
226                                 return null;
227                         }
228
229                         InputMethodInfo* pInputMethodInfo = static_cast<InputMethodInfo*>(__pInputMethodInfoList->GetAt(itemIndex));
230                         itemMainText = pInputMethodInfo->GetName();
231                 }
232                 break;
233
234         case ID_GROUP_KEYBOARD_HARDWARE:
235                 {
236                         switch (itemIndex)
237                         {
238                         case ID_ITEM_KEYBOARD_HARDWARE_SELECT_KEYBOARD:
239                                 {
240                                         itemMainText = ResourceManager::GetString(L"IDS_IME_BODY_KEYBOARD_SELECTION");
241                                 }
242                                 break;
243
244                         case ID_ITEM_KEYBOARD_HARDWARE_KEYBOARD_SETTING:
245                                 {
246                                         itemMainText = ResourceManager::GetString(L"IDS_IME_BODY_KEYBOARD_SETTINGS");
247                                 }
248                                 break;
249
250                         default:
251                                 break;
252                         }
253                 }
254                 break;
255
256         default:
257                 break;
258         }
259
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);
264
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);
270
271         pItem->AddControl(pLabel);
272
273         return pItem;
274 }
275
276 bool
277 KeyboardSelectionForm::DeleteGroupItem(int groupIndex, TableViewGroupItem* pItem)
278 {
279         AppLogDebug("ENTER");
280
281         delete pItem;
282         pItem = null;
283
284         return true;
285 }
286
287 bool
288 KeyboardSelectionForm::DeleteItem(int groupIndex, int itemIndex, TableViewItem* pItem)
289 {
290         delete pItem;
291         pItem = null;
292
293         return true;
294 }
295
296 void
297 KeyboardSelectionForm::OnGroupedTableViewItemStateChanged(Tizen::Ui::Controls::GroupedTableView& tableView, int groupIndex, int itemIndex, Tizen::Ui::Controls::TableViewItem* pItem, Tizen::Ui::Controls::TableViewItemStatus status)
298 {
299         SceneManager* pSceneManager = SceneManager::GetInstance();
300         AppAssert(pSceneManager);
301
302         if (__pInputMethodInfoList == null)
303         {
304                 return;
305         }
306
307         switch (groupIndex)
308         {
309         case ID_GROUP_KEYBOARD_SOFTWARE:
310                 {
311                         if (status == TABLE_VIEW_ITEM_STATUS_MORE)
312                         {
313                                 IList* pList = __pInputMethodInfoList->GetItemsN(itemIndex, GROUP_KEYBOARD_SOFTWARE_DEFAULT_COUNT);
314                                 if (pList == null)
315                                 {
316                                         AppLogDebug("GetItemsN is null");
317                                         break;
318                                 }
319
320                                 pSceneManager->GoForward(ForwardSceneTransition(IDSCN_KEYBOARD_INFO, SCENE_TRANSITION_ANIMATION_TYPE_LEFT), pList);
321                                 break;
322                         }
323                         InputMethodManager* pInputMethodManager = InputMethodManager::GetInstance();
324                         InputMethodInfo* pInputMethodInfo = static_cast<InputMethodInfo*>(__pInputMethodInfoList->GetAt(itemIndex));
325                         if (pInputMethodInfo == null || pInputMethodManager == null)
326                         {
327                                 AppLogDebug("pInputMethodInfo or pInputMethodManager is null");
328                                 break;
329                         }
330                         result r = pInputMethodManager->SetInputMethod(pInputMethodInfo->GetAppId());
331                         if (IsFailed(r))
332                         {
333                                 AppLogDebug("SetInputMethod(appId(%ls)) failed(%s)", pInputMethodInfo->GetAppId().GetPointer(), GetErrorMessage(r));
334                         }
335                         pSceneManager->GoBackward(BackwardSceneTransition(SCENE_TRANSITION_ANIMATION_TYPE_RIGHT), null);
336                 }
337                 break;
338
339         case ID_GROUP_KEYBOARD_HARDWARE:
340                 {
341                         if (itemIndex == ID_ITEM_KEYBOARD_HARDWARE_SELECT_KEYBOARD)
342                         {
343                                 // TODO: nothing todo yet.
344                         }
345
346                         if (itemIndex == ID_ITEM_KEYBOARD_HARDWARE_KEYBOARD_SETTING)
347                         {
348                                 // TODO: nothing todo yet.
349                         }
350                 }
351                 break;
352
353         default:
354                 break;
355         }
356 }
357
358 int
359 KeyboardSelectionForm::GetDefaultGroupItemHeight(void)
360 {
361         return H_GROUP_INDEX_NO_TITLE_DEFAULT;
362 }
363
364 int
365 KeyboardSelectionForm::GetDefaultItemHeight(void)
366 {
367         return H_GROUP_ITEM_DEFAULT;
368 }
369
370 void
371 KeyboardSelectionForm::UpdateGroupItem(int groupIndex, Tizen::Ui::Controls::TableViewGroupItem* pItem)
372 {
373 }
374
375 void
376 KeyboardSelectionForm::UpdateItem(int groupIndex, int itemIndex, Tizen::Ui::Controls::TableViewItem* pItem)
377 {
378 }
379
380 void
381 KeyboardSelectionForm::OnGroupedTableViewContextItemActivationStateChanged(Tizen::Ui::Controls::GroupedTableView& tableView, int groupIndex, int itemIndex, Tizen::Ui::Controls::TableViewContextItem* pContextItem, bool activated)
382 {
383 }
384
385 void
386 KeyboardSelectionForm::OnGroupedTableViewGroupItemStateChanged(Tizen::Ui::Controls::GroupedTableView& tableView, int groupIndex, Tizen::Ui::Controls::TableViewGroupItem* pItem, Tizen::Ui::Controls::TableViewItemStatus status)
387 {
388 }
389
390 result
391 KeyboardSelectionForm::InitInputMethodInfoList(void)
392 {
393         InputMethodManager* pInputMethodManager = InputMethodManager::GetInstance();
394         __pInputMethodInfoList = pInputMethodManager->GetInputMethodInfoListN();
395         if (__pInputMethodInfoList == null)
396         {
397                 return E_FAILURE;
398         }
399
400         return E_SUCCESS;
401 }
402
403 void
404 KeyboardSelectionForm::OnOrientationChanged(const Tizen::Ui::Control& source, Tizen::Ui::OrientationStatus orientationStatus)
405 {
406         BaseForm::OnOrientationChanged(source, orientationStatus);
407         __pTableView->UpdateTableView();
408 }