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