Fixed N_SE-38563, N_SE-38552
[apps/osp/Settings.git] / src / StKeyboardForm.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                StKeyboardForm.cpp
19  * @brief               This is the implementation file for KeyboardForm class.
20  */
21
22 #include "StKeyboardForm.h"
23 #include "StResourceManager.h"
24 #include "StSettingScenesList.h"
25 #include "StTypes.h"
26
27 using namespace Tizen::Base;
28 using namespace Tizen::Graphics;
29 using namespace Tizen::Ui;
30 using namespace Tizen::Ui::Controls;
31 using namespace Tizen::Ui::Scenes;
32
33 static const int ID_GROUP_KEYBOARD_SOFTWARE = 0;
34 static const int ID_GROUP_KEYBOARD_SOFTWARE_ITEM_COUNT = 1;
35 static const int ID_ITEM_KEYBOARD_SOFTWARE_SELECT_KEYBOARD = 0;
36 static const int ID_ITEM_KEYBOARD_SOFTWARE_KEYBOARD_SETTING = 1;
37
38 static const int ID_GROUP_KEYBOARD_HARDWARE = 1;
39 static const int ID_GROUP_KEYBOARD_HARDWARE_ITEM_COUNT = 2;
40 static const int ID_ITEM_KEYBOARD_HARDWARE_SELECT_KEYBOARD = 0;
41 static const int ID_ITEM_KEYBOARD_HARDWARE_KEYBOARD_SETTING = 1;
42
43 static const int ID_GROUP_COUNT = 1;
44
45 KeyboardForm::KeyboardForm(void)
46 {
47 }
48
49 KeyboardForm::~KeyboardForm(void)
50 {
51 }
52
53 void
54 KeyboardForm::CreateFooter(void)
55 {
56         Footer* pFooter = GetFooter();
57         AppAssert(pFooter);
58
59         pFooter->SetStyle(FOOTER_STYLE_BUTTON_TEXT);
60         pFooter->SetBackButton();
61         pFooter->AddActionEventListener(*this);
62
63         SetFormBackEventListener(this);
64 }
65
66 result
67 KeyboardForm::OnInitializing(void)
68 {
69         CreateHeader(ResourceManager::GetString(L"IDS_ST_BODY_KEYBOARD"));
70         CreateFooter();
71         CreateTableView();
72
73         AppLogDebug("ENTER");
74
75         return E_SUCCESS;
76 }
77
78 result
79 KeyboardForm::OnTerminating(void)
80 {
81         __pTableView = null;
82
83         SetFormBackEventListener(null);
84         return E_SUCCESS;
85 }
86
87 void
88 KeyboardForm::OnSceneActivatedN(const Tizen::Ui::Scenes::SceneId& previousSceneId, const Tizen::Ui::Scenes::SceneId& currentSceneId, Tizen::Base::Collection::IList* pArgs)
89 {
90         __pTableView->UpdateTableView();
91 }
92
93 void
94 KeyboardForm::OnSceneDeactivated(const Tizen::Ui::Scenes::SceneId& currentSceneId, const Tizen::Ui::Scenes::SceneId& nextSceneId)
95 {
96 }
97
98 void
99 KeyboardForm::OnFormBackRequested(Tizen::Ui::Controls::Form& source)
100 {
101         SceneManager* pSceneManager = SceneManager::GetInstance();
102         AppAssert(pSceneManager);
103
104         pSceneManager->GoBackward(BackwardSceneTransition(SCENE_TRANSITION_ANIMATION_TYPE_RIGHT), null);
105 }
106
107 int
108 KeyboardForm::GetGroupCount(void)
109 {
110         AppLogDebug("ENTER");
111         return ID_GROUP_COUNT;
112 }
113
114 int
115 KeyboardForm::GetItemCount(int groupIndex)
116 {
117         int itemCount = 0;
118
119         switch (groupIndex)
120         {
121         case ID_GROUP_KEYBOARD_SOFTWARE:
122                 {
123                         itemCount = ID_GROUP_KEYBOARD_SOFTWARE_ITEM_COUNT;
124                 }
125                 break;
126
127         case ID_GROUP_KEYBOARD_HARDWARE:
128                 {
129                         itemCount = ID_GROUP_KEYBOARD_HARDWARE_ITEM_COUNT;
130                 }
131                 break;
132
133         default:
134                 break;
135         }
136
137         AppLogDebug("GetItemCount %d", itemCount);
138         return itemCount;
139 }
140
141 TableViewGroupItem*
142 KeyboardForm::CreateGroupItem(int groupIndex, int itemWidth)
143 {
144         AppLogDebug("ENTER");
145
146         int itemHeight = H_GROUP_INDEX_NO_TITLE_DEFAULT;
147         int yItemOffset = H_GROUP_INDEX_HELP_TEXT_TOP_GAP;
148         LabelTextStyle style = LABEL_TEXT_STYLE_BOLD;
149         Rectangle itemMainRectangle;
150         String groupText;
151         Label* pLabel = null;
152
153         TableViewGroupItem* pItem = new (std::nothrow) TableViewGroupItem();
154
155         switch (groupIndex)
156         {
157         case ID_GROUP_KEYBOARD_SOFTWARE:
158                 {
159                         yItemOffset = H_GROUP_INDEX_NO_HELP_TEXT_GAP;
160                         itemHeight = H_GROUP_INDEX_DEFAULT;
161                         groupText = ResourceManager::GetString(L"IDS_IME_BODY_SOFTWARE_KEYBOARD");
162                 }
163                 break;
164
165         case ID_GROUP_KEYBOARD_HARDWARE:
166                 {
167                         yItemOffset = H_GROUP_INDEX_NO_HELP_TEXT_GAP;
168                         itemHeight = H_GROUP_INDEX_DEFAULT;
169                         groupText = ResourceManager::GetString(L"IDS_IME_BODY_HARDWARE_KEYBOARD");
170                 }
171                 break;
172
173         default:
174                 break;
175         }
176
177         itemMainRectangle.x = X_GROUP_ITEM_DEFAULT_LABEL;
178         itemMainRectangle.y = yItemOffset;
179         itemMainRectangle.width = itemWidth;
180         itemMainRectangle.height = itemHeight;
181
182         RelativeLayout relativeLayout;
183         relativeLayout.Construct();
184
185         pItem->Construct(relativeLayout, Dimension(itemWidth, itemHeight));
186         pItem->SetBackgroundColor(COLOR_BG_GROUP_INDEX_DEFAULT);
187
188         pLabel = new (std::nothrow) Label();
189         pLabel->Construct(itemMainRectangle, groupText);
190         pLabel->SetTextHorizontalAlignment(ALIGNMENT_LEFT);
191         pLabel->SetTextVerticalAlignment(ALIGNMENT_TOP);
192         pLabel->SetTextConfig(FONT_SIZE_GROUP_TITLE_TEXT, style);
193         pLabel->SetTextColor(COLOR_GROUP_TITLE_TEXT);
194
195         pItem->AddControl(pLabel);
196         relativeLayout.SetMargin(*pLabel, itemMainRectangle.x, RELATIVE_LAYOUT_RIGHT_MARGIN, 0, 0);
197         relativeLayout.SetRelation(*pLabel, pItem, RECT_EDGE_RELATION_LEFT_TO_LEFT);
198         relativeLayout.SetRelation(*pLabel, pItem, RECT_EDGE_RELATION_RIGHT_TO_RIGHT);
199         pItem->SetEnabled(false);
200
201         return pItem;
202 }
203
204 TableViewItem*
205 KeyboardForm::CreateItem(int groupIndex, int itemIndex, int itemWidth)
206 {
207         AppLogDebug("group[%d] index[%d]", groupIndex, itemIndex);
208
209         Rectangle itemMainRectangle;
210         TableViewAnnexStyle style = TABLE_VIEW_ANNEX_STYLE_NORMAL;
211         String itemMainText;
212         Label* pLabel = null;
213         int fontSize = GetFontSize();
214
215         TableViewItem* pItem = new (std::nothrow) TableViewItem();
216
217         if (groupIndex < ID_GROUP_KEYBOARD_SOFTWARE)
218         {
219                 style = TABLE_VIEW_ANNEX_STYLE_ONOFF_SLIDING;
220         }
221
222         switch (groupIndex)
223         {
224         case ID_GROUP_KEYBOARD_SOFTWARE:
225                 {
226                         switch (itemIndex)
227                         {
228                         case ID_ITEM_KEYBOARD_SOFTWARE_SELECT_KEYBOARD:
229                                 {
230                                         itemMainText = ResourceManager::GetString(L"IDS_IME_BODY_KEYBOARD_SELECTION");
231                                 }
232                                 break;
233
234                         case ID_ITEM_KEYBOARD_SOFTWARE_KEYBOARD_SETTING:
235                                 {
236                                         itemMainText = ResourceManager::GetString(L"IDS_IME_BODY_WRITING_LANGUAGES");
237                                 }
238                                 break;
239
240                         default:
241                                 break;
242                         }
243                 }
244                 break;
245
246         case ID_GROUP_KEYBOARD_HARDWARE:
247                 {
248                         switch (itemIndex)
249                         {
250                         case ID_ITEM_KEYBOARD_HARDWARE_SELECT_KEYBOARD:
251                                 {
252                                         itemMainText = ResourceManager::GetString(L"IDS_IME_BODY_KEYBOARD_SELECTION");
253                                 }
254                                 break;
255
256                         case ID_ITEM_KEYBOARD_HARDWARE_KEYBOARD_SETTING:
257                                 {
258                                         itemMainText = ResourceManager::GetString(L"IDS_IME_BODY_KEYBOARD_SETTINGS");
259                                 }
260                                 break;
261
262                         default:
263                                 break;
264                         }
265                 }
266                 break;
267
268         default:
269                 break;
270         }
271
272         ItemTypeOneLine(itemMainRectangle);
273
274         RelativeLayout relativeLayout;
275         relativeLayout.Construct();
276
277         pItem->Construct(relativeLayout, Dimension(itemWidth, H_GROUP_ITEM_DEFAULT), style);
278         pItem->SetBackgroundColor(COLOR_BG_GROUP_ITEM_DEFAULT);
279
280         pLabel = new (std::nothrow) Label();
281         pLabel->Construct(itemMainRectangle, itemMainText);
282         pLabel->SetTextHorizontalAlignment(ALIGNMENT_LEFT);
283         pLabel->SetTextConfig(fontSize, LABEL_TEXT_STYLE_BOLD);
284         pLabel->SetTextColor(COLOR_MAIN_TEXT);
285
286         pItem->AddControl(pLabel);
287         if (style == TABLE_VIEW_ANNEX_STYLE_ONOFF_SLIDING)
288         {
289                 relativeLayout.SetMargin(*pLabel, 0, RELATIVE_LAYOUT_RIGHT_MARGIN_ONOFF_SLIDING, 0, 0);
290         }
291         else
292         {
293                 relativeLayout.SetMargin(*pLabel, 0, RELATIVE_LAYOUT_RIGHT_MARGIN, 0, 0);
294         }
295         relativeLayout.SetRelation(*pLabel, pItem, RECT_EDGE_RELATION_LEFT_TO_LEFT);
296         relativeLayout.SetRelation(*pLabel, pItem, RECT_EDGE_RELATION_RIGHT_TO_RIGHT);
297
298         return pItem;
299 }
300
301 bool
302 KeyboardForm::DeleteGroupItem(int groupIndex, TableViewGroupItem* pItem)
303 {
304         AppLogDebug("ENTER");
305
306         delete pItem;
307         pItem = null;
308
309         return true;
310 }
311
312 bool
313 KeyboardForm::DeleteItem(int groupIndex, int itemIndex, TableViewItem* pItem)
314 {
315         AppLogDebug("ENTER");
316
317         delete pItem;
318         pItem = null;
319
320         return true;
321 }
322
323 void
324 KeyboardForm::OnGroupedTableViewItemStateChanged(Tizen::Ui::Controls::GroupedTableView& tableView, int groupIndex, int itemIndex, Tizen::Ui::Controls::TableViewItem* pItem, Tizen::Ui::Controls::TableViewItemStatus status)
325 {
326         SceneManager* pSceneManager = SceneManager::GetInstance();
327         AppAssert(pSceneManager);
328
329         AppLogDebug("group[%d] index[%d]", groupIndex, itemIndex);
330
331         switch (groupIndex)
332         {
333         case ID_GROUP_KEYBOARD_SOFTWARE:
334                 {
335                         if (itemIndex == ID_ITEM_KEYBOARD_SOFTWARE_SELECT_KEYBOARD)
336                         {
337                                 // TODO: select software keyboard.
338                                 pSceneManager->GoForward(ForwardSceneTransition(IDSCN_KEYBOARD_SELECTION, SCENE_TRANSITION_ANIMATION_TYPE_LEFT), null);
339                         }
340
341                         if (itemIndex == ID_ITEM_KEYBOARD_SOFTWARE_KEYBOARD_SETTING)
342                         {
343                                 // TODO: more setting for software keyboard.
344                         }
345                 }
346                 break;
347
348         case ID_GROUP_KEYBOARD_HARDWARE:
349                 {
350                         if (itemIndex == ID_ITEM_KEYBOARD_HARDWARE_SELECT_KEYBOARD)
351                         {
352                                 // TODO: nothing todo yet.
353                         }
354
355                         if (itemIndex == ID_ITEM_KEYBOARD_HARDWARE_KEYBOARD_SETTING)
356                         {
357                                 // TODO: nothing todo yet.
358                         }
359                 }
360                 break;
361
362         default:
363                 break;
364         }
365 }
366
367 int
368 KeyboardForm::GetDefaultGroupItemHeight(void)
369 {
370         return H_GROUP_INDEX_NO_TITLE_DEFAULT;
371 }
372
373 int
374 KeyboardForm::GetDefaultItemHeight(void)
375 {
376         return H_GROUP_ITEM_DEFAULT;
377 }
378
379 void
380 KeyboardForm::UpdateGroupItem(int groupIndex, Tizen::Ui::Controls::TableViewGroupItem* pItem)
381 {
382 }
383
384 void
385 KeyboardForm::UpdateItem(int groupIndex, int itemIndex, Tizen::Ui::Controls::TableViewItem* pItem)
386 {
387 }
388
389 void
390 KeyboardForm::OnGroupedTableViewContextItemActivationStateChanged(Tizen::Ui::Controls::GroupedTableView& tableView, int groupIndex, int itemIndex, Tizen::Ui::Controls::TableViewContextItem* pContextItem, bool activated)
391 {
392 }
393
394 void
395 KeyboardForm::OnGroupedTableViewGroupItemStateChanged(Tizen::Ui::Controls::GroupedTableView& tableView, int groupIndex, Tizen::Ui::Controls::TableViewGroupItem* pItem, Tizen::Ui::Controls::TableViewItemStatus status)
396 {
397 }