2 // Copyright (c) 2012 Samsung Electronics Co., Ltd.
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
8 // http://floralicense.org/license/
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.
18 * @file StBaseForm.cpp
19 * @brief This is the implementation file for BaseForm class.
23 #include "StBaseForm.h"
24 #include "StSettingsApp.h"
27 using namespace Tizen::App;
28 using namespace Tizen::Base;
29 using namespace Tizen::Base::Utility;
30 using namespace Tizen::Graphics;
31 using namespace Tizen::System;
32 using namespace Tizen::Ui;
33 using namespace Tizen::Ui::Controls;
35 static const int LINE_COUNT_DEFAULT = 1;
37 static const int BASE_FORM_DEFAULT_MARGIN = 32;
39 BaseForm::BaseForm(void)
44 BaseForm::~BaseForm(void)
49 BaseForm::Initialize(void)
52 RelativeLayout relativeLayout;
53 relativeLayout.Construct();
55 Construct(relativeLayout, FORM_STYLE_NORMAL | FORM_STYLE_INDICATOR | FORM_STYLE_LANDSCAPE_INDICATOR_AUTO_HIDE | FORM_STYLE_HEADER);
58 SetOrientationAutoMode();
63 BaseForm::SetOrientationAutoMode(void)
65 this->SetOrientation(ORIENTATION_AUTOMATIC_FOUR_DIRECTION);
66 this->AddOrientationEventListener(*this);
70 BaseForm::CreateHeader(const Tizen::Base::String& textTitle)
72 Header* pHeader = GetHeader();
74 pHeader->SetStyle(HEADER_STYLE_TITLE);
75 pHeader->SetTitleText(textTitle);
79 BaseForm::CreateTableView(void)
81 if (__pTableView != null)
83 AppLogDebug("__pTableView is not null");
86 Rectangle bounds = GetClientAreaBounds();
87 bounds.x = X_GROUP_DEFAULT;
88 bounds.y = Y_GROUP_DEFAULT;
90 __pTableView = new (std::nothrow) GroupedTableView();
92 __pTableView->Construct(bounds, false, TABLE_VIEW_SCROLL_BAR_STYLE_FADE_OUT);
93 __pTableView->SetItemProvider(this);
95 AddControl(__pTableView);
96 __pTableView->SetGroupedLookEnabled(true);
97 __pTableView->AddGroupedTableViewItemEventListener(*this);
99 RelativeLayout* pRelativeLayout = dynamic_cast<RelativeLayout*>(this->GetLayoutN());
100 if (pRelativeLayout != null)
102 pRelativeLayout->SetHorizontalFitPolicy(*__pTableView, FIT_POLICY_PARENT);
103 pRelativeLayout->SetRelation(*__pTableView, this, RECT_EDGE_RELATION_TOP_TO_TOP);
104 pRelativeLayout->SetRelation(*__pTableView, this, RECT_EDGE_RELATION_BOTTOM_TO_BOTTOM);
105 delete pRelativeLayout;
110 BaseForm::SetFooter(void)
112 Footer* pFooter = GetFooter();
115 pFooter->SetStyle(FOOTER_STYLE_SEGMENTED_TEXT);
116 pFooter->AddActionEventListener(*this);
118 SetFormBackEventListener(this);
124 BaseForm::OnActionPerformed(const Tizen::Ui::Control& source, int actionId)
126 AppLogDebug("ENTER");
130 BaseForm::OnFormBackRequested(Tizen::Ui::Controls::Form& source)
132 AppLogDebug("ENTER");
134 UiApp* pApp = UiApp::GetInstance();
140 BaseForm::ShowMessageBox(const Tizen::Base::String& title, const Tizen::Base::String& text)
142 MessageBox messageBox;
143 int result = E_SUCCESS;
145 messageBox.Construct(title, text, MSGBOX_STYLE_NONE, MESSAGEBOX_DISPLAY_TIME_2_SEC);
146 messageBox.ShowAndWait(result);
150 BaseForm::ItemTypeOneLine(Tizen::Graphics::Rectangle& main)
152 Rectangle clientRect = GetClientAreaBounds();
154 main.x = X_ITEM_TYPE_1_LABEL;
155 main.y = Y_ITEM_TYPE_1_LABEL;
156 main.width = (clientRect.width - TWO_LINE_ITEM_WIDTH_GAP);
157 main.height = H_ITEM_TYPE_1_LABEL;
161 BaseForm::ItemTypeTwoLine(Tizen::Graphics::Rectangle& main, Tizen::Graphics::Rectangle& sub, int fontSize)
163 Rectangle clientRect = GetClientAreaBounds();
165 if (fontSize >= FONT_MAIN_TEXT_SIZE_LARGE)
167 main.x = X_ITEM_TYPE_2_LABEL_MAIN;
168 main.y = Y_ITEM_TYPE_2_LABEL_MAIN;
169 main.width = (clientRect.width - TWO_LINE_ITEM_WIDTH_GAP);
170 main.height = H_ITEM_TYPE_1_LABEL;
172 sub.x = X_ITEM_TYPE_2_LABEL_SUB;
173 sub.y = H_ITEM_TYPE_1_LABEL;
174 sub.width = (clientRect.width - TWO_LINE_ITEM_WIDTH_GAP);
175 sub.height = H_ITEM_TYPE_2_LABEL_SUB;
179 main.x = X_ITEM_TYPE_2_LABEL_MAIN;
180 main.y = Y_ITEM_TYPE_2_LABEL_MAIN;
181 main.width = (clientRect.width - TWO_LINE_ITEM_WIDTH_GAP);
182 main.height = H_ITEM_TYPE_2_LABEL_MAIN;
184 sub.x = X_ITEM_TYPE_2_LABEL_SUB;
185 sub.y = Y_ITEM_TYPE_2_LABEL_SUB;
186 sub.width = (clientRect.width - TWO_LINE_ITEM_WIDTH_GAP);
187 sub.height = H_ITEM_TYPE_2_LABEL_SUB;
192 BaseForm::ItemTypeIconAndOneLine(Tizen::Graphics::Rectangle& icon, Tizen::Graphics::Rectangle& main)
194 Rectangle clientRect = GetClientAreaBounds();
196 icon.x = X_ITEM_TYPE_3_ICON;
197 icon.y = Y_ITEM_TYPE_3_ICON;
198 icon.width = W_ITEM_TYPE_3_ICON;
199 icon.height = H_ITEM_TYPE_3_ICON;
201 main.x = X_ITEM_TYPE_3_LABEL;
202 main.y = Y_ITEM_TYPE_3_LABEL;
203 main.width = (clientRect.width - ICON_AND_ONE_LINE_ITEM_WIDTH_GAP);
204 main.height = H_ITEM_TYPE_3_LABEL;
208 BaseForm::ItemTypeIconAndTwoLine(Tizen::Graphics::Rectangle& icon, Tizen::Graphics::Rectangle& main, Tizen::Graphics::Rectangle& sub, int fontSize)
210 Rectangle clientRect = GetClientAreaBounds();
212 icon.x = X_ITEM_TYPE_4_ICON;
213 icon.y = Y_ITEM_TYPE_4_ICON;
214 icon.width = W_ITEM_TYPE_4_ICON;
215 icon.height = H_ITEM_TYPE_4_ICON;
217 if (fontSize > FONT_MAIN_TEXT_SIZE_LARGE)
219 main.x = X_ITEM_TYPE_4_LABEL_MAIN;
220 main.y = Y_ITEM_TYPE_4_LABEL_MAIN;
221 main.width = (clientRect.width - X_ITEM_TYPE_4_LABEL_MAIN);
222 main.height = H_ITEM_TYPE_1_LABEL;
224 sub.x = X_ITEM_TYPE_4_LABEL_SUB;
225 sub.y = H_ITEM_TYPE_1_LABEL;
226 sub.width = (clientRect.width - X_ITEM_TYPE_4_LABEL_MAIN);
227 sub.height = H_ITEM_TYPE_4_LABEL_SUB;
231 main.x = X_ITEM_TYPE_4_LABEL_MAIN;
232 main.y = Y_ITEM_TYPE_4_LABEL_MAIN;
233 main.width = (clientRect.width - X_ITEM_TYPE_4_LABEL_MAIN);
234 main.height = H_ITEM_TYPE_4_LABEL_MAIN;
236 sub.x = X_ITEM_TYPE_4_LABEL_SUB;
237 sub.y = Y_ITEM_TYPE_4_LABEL_SUB;
238 sub.width = main.width;
239 sub.height = H_ITEM_TYPE_4_LABEL_SUB;
244 BaseForm::GetFontSize(void)
246 int fontSize = FONT_MAIN_TEXT_SIZE_NORMAL;
247 String fontSizeValue;
249 if (SettingInfo::GetValue(SETTING_INFO_KEY_FONT_SIZE, fontSizeValue) == E_SUCCESS)
251 if (fontSizeValue.Equals(L"giant", false))
253 fontSize = FONT_MAIN_TEXT_SIZE_GIANT;
255 else if (fontSizeValue.Equals(L"huge", false))
257 fontSize = FONT_MAIN_TEXT_SIZE_HUGE;
259 else if (fontSizeValue.Equals(L"large", false))
261 fontSize = FONT_MAIN_TEXT_SIZE_LARGE;
263 else if (fontSizeValue.Equals(L"medium", false))
265 fontSize = FONT_MAIN_TEXT_SIZE_NORMAL;
269 fontSize = FONT_MAIN_TEXT_SIZE_SMALL;
276 BaseForm::OnOrientationChanged(const Tizen::Ui::Control& source, Tizen::Ui::OrientationStatus orientationStatus)
282 BaseForm::GetHeightForStringArea(const Tizen::Base::String source, int width, int fontSize) const
288 int lineCount = LINE_COUNT_DEFAULT;
289 int boundwidth = width - BASE_FORM_DEFAULT_MARGIN;
290 AppLog("Text Label width %d", boundwidth);
291 font.Construct(FONT_STYLE_PLAIN, fontSize);
292 StringTokenizer strTokenizer(source, L" ");
293 strTokenizer.GetNextToken(temp);
294 font.GetTextExtent(temp, temp.GetLength(), dim);
296 if (dim.width >= boundwidth)
302 if (strTokenizer.HasMoreTokens())
304 while (strTokenizer.HasMoreTokens())
308 strTokenizer.GetNextToken(nextToken);
309 temp.Append(nextToken);
310 font.GetTextExtent(temp, temp.GetLength(), dim);
311 AppLog("Text Entered %ls %d", temp.GetPointer(), dim.width);
312 if (dim.width >= boundwidth)
315 temp.Append(nextToken);
317 font.GetTextExtent(temp, temp.GetLength(), dim);
318 if (dim.width >= boundwidth)
329 if (dim.width > boundwidth)
331 for (int i = 0; i < source.GetLength(); i++)
333 temp.Append(source[i]);
334 font.GetTextExtent(temp, temp.GetLength(), dim);
335 if (dim.width > boundwidth)
338 temp.Append(source[i]);
345 return dim.height * lineCount;