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