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