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