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"
26 using namespace Tizen::App;
27 using namespace Tizen::Base;
28 using namespace Tizen::Graphics;
29 using namespace Tizen::System;
30 using namespace Tizen::Ui;
31 using namespace Tizen::Ui::Controls;
33 static const int W_LARGE_SIZE_TEXT_GAP = 110;
34 static const int W_HUGE_SIZE_PORTRAIT_TEXT_GAP = 90;
35 static const int W_HUGE_SIZE_LANDSCAPE_TEXT_GAP = 220;
36 static const int LINE_COUNT_DEFAULT = 1;
38 static const int BASE_FORM_DEFAULT_MARGIN = 32;
40 BaseForm::BaseForm(void)
45 BaseForm::~BaseForm(void)
50 BaseForm::Initialize(void)
52 RelativeLayout relativeLayout;
53 relativeLayout.Construct();
54 Construct(relativeLayout, FORM_STYLE_NORMAL | FORM_STYLE_INDICATOR | FORM_STYLE_HEADER | FORM_STYLE_FOOTER);
57 SetOrientationAutoMode();
62 BaseForm::SetOrientationAutoMode(void)
64 this->SetOrientation(ORIENTATION_AUTOMATIC_FOUR_DIRECTION);
65 this->AddOrientationEventListener(*this);
69 BaseForm::CreateHeader(const Tizen::Base::String& textTitle)
71 Header* pHeader = GetHeader();
73 pHeader->SetStyle(HEADER_STYLE_TITLE);
74 pHeader->SetTitleText(textTitle);
78 BaseForm::CreateTableView(void)
80 if (__pTableView != null)
82 AppLogDebug("__pTableView is not null");
85 Rectangle bounds = GetClientAreaBounds();
86 bounds.x = X_GROUP_DEFAULT;
87 bounds.y = Y_GROUP_DEFAULT;
89 __pTableView = new (std::nothrow) GroupedTableView();
91 __pTableView->Construct(bounds, false, TABLE_VIEW_SCROLL_BAR_STYLE_FADE_OUT);
92 __pTableView->SetItemProvider(this);
94 AddControl(__pTableView);
95 __pTableView->SetGroupedLookEnabled(true);
96 __pTableView->AddGroupedTableViewItemEventListener(*this);
98 RelativeLayout* pRelativeLayout = dynamic_cast<RelativeLayout*>(this->GetLayoutN());
99 if (pRelativeLayout != null)
101 pRelativeLayout->SetHorizontalFitPolicy(*__pTableView, FIT_POLICY_PARENT);
102 pRelativeLayout->SetRelation(*__pTableView, this, RECT_EDGE_RELATION_TOP_TO_TOP);
103 pRelativeLayout->SetRelation(*__pTableView, this, RECT_EDGE_RELATION_BOTTOM_TO_BOTTOM);
104 delete pRelativeLayout;
109 BaseForm::SetFooter(void)
111 Footer* pFooter = GetFooter();
113 pFooter->SetStyle(FOOTER_STYLE_SEGMENTED_TEXT);
114 pFooter->SetBackButton();
115 pFooter->AddActionEventListener(*this);
117 SetFormBackEventListener(this);
123 BaseForm::OnActionPerformed(const Tizen::Ui::Control& source, int actionId)
125 AppLogDebug("ENTER");
129 BaseForm::OnFormBackRequested(Tizen::Ui::Controls::Form& source)
131 AppLogDebug("ENTER");
133 UiApp* pApp = UiApp::GetInstance();
139 BaseForm::ShowMessageBox(const Tizen::Base::String& title, const Tizen::Base::String& text)
141 MessageBox messageBox;
142 int result = E_SUCCESS;
144 messageBox.Construct(title, text, MSGBOX_STYLE_NONE, MESSAGEBOX_DISPLAY_TIME_2_SEC);
145 messageBox.ShowAndWait(result);
149 BaseForm::ItemTypeOneLine(Tizen::Graphics::Rectangle& main)
151 Rectangle clientRect = GetClientAreaBounds();
153 main.x = X_ITEM_TYPE_1_LABEL;
154 main.y = Y_ITEM_TYPE_1_LABEL;
155 main.width = (clientRect.width - TWO_LINE_ITEM_WIDTH_GAP);
156 main.height = H_ITEM_TYPE_1_LABEL;
160 BaseForm::ItemTypeTwoLine(Tizen::Graphics::Rectangle& main, Tizen::Graphics::Rectangle& sub, int fontSize)
162 Rectangle clientRect = GetClientAreaBounds();
164 if (fontSize >= FONT_MAIN_TEXT_SIZE_LARGE)
166 main.x = X_ITEM_TYPE_2_LABEL_MAIN;
167 main.y = Y_ITEM_TYPE_2_LABEL_MAIN;
168 main.width = (clientRect.width - TWO_LINE_ITEM_WIDTH_GAP);
169 main.height = H_ITEM_TYPE_1_LABEL;
171 sub.x = X_ITEM_TYPE_2_LABEL_SUB;
172 sub.y = H_ITEM_TYPE_1_LABEL;
173 sub.width = (clientRect.width - TWO_LINE_ITEM_WIDTH_GAP);
174 sub.height = H_ITEM_TYPE_2_LABEL_SUB;
178 main.x = X_ITEM_TYPE_2_LABEL_MAIN;
179 main.y = Y_ITEM_TYPE_2_LABEL_MAIN;
180 main.width = (clientRect.width - TWO_LINE_ITEM_WIDTH_GAP);
181 main.height = H_ITEM_TYPE_2_LABEL_MAIN;
183 sub.x = X_ITEM_TYPE_2_LABEL_SUB;
184 sub.y = Y_ITEM_TYPE_2_LABEL_SUB;
185 sub.width = (clientRect.width - TWO_LINE_ITEM_WIDTH_GAP);
186 sub.height = H_ITEM_TYPE_2_LABEL_SUB;
191 BaseForm::ItemTypeIconAndOneLine(Tizen::Graphics::Rectangle& icon, Tizen::Graphics::Rectangle& main)
193 Rectangle clientRect = GetClientAreaBounds();
195 icon.x = X_ITEM_TYPE_3_ICON;
196 icon.y = Y_ITEM_TYPE_3_ICON;
197 icon.width = W_ITEM_TYPE_3_ICON;
198 icon.height = H_ITEM_TYPE_3_ICON;
200 main.x = X_ITEM_TYPE_3_LABEL;
201 main.y = Y_ITEM_TYPE_3_LABEL;
202 main.width = (clientRect.width - ICON_AND_ONE_LINE_ITEM_WIDTH_GAP);
203 main.height = H_ITEM_TYPE_3_LABEL;
207 BaseForm::ItemTypeIconAndTwoLine(Tizen::Graphics::Rectangle& icon, Tizen::Graphics::Rectangle& main, Tizen::Graphics::Rectangle& sub, int fontSize)
209 Rectangle clientRect = GetClientAreaBounds();
211 icon.x = X_ITEM_TYPE_4_ICON;
212 icon.y = Y_ITEM_TYPE_4_ICON;
213 icon.width = W_ITEM_TYPE_4_ICON;
214 icon.height = H_ITEM_TYPE_4_ICON;
216 if (fontSize > FONT_MAIN_TEXT_SIZE_LARGE)
218 main.x = X_ITEM_TYPE_4_LABEL_MAIN;
219 main.y = Y_ITEM_TYPE_4_LABEL_MAIN;
220 main.width = (clientRect.width - X_ITEM_TYPE_4_LABEL_MAIN);
221 main.height = H_ITEM_TYPE_1_LABEL;
223 sub.x = X_ITEM_TYPE_4_LABEL_SUB;
224 sub.y = H_ITEM_TYPE_1_LABEL;
225 sub.width = (clientRect.width - X_ITEM_TYPE_4_LABEL_MAIN);
226 sub.height = H_ITEM_TYPE_4_LABEL_SUB;
230 main.x = X_ITEM_TYPE_4_LABEL_MAIN;
231 main.y = Y_ITEM_TYPE_4_LABEL_MAIN;
232 main.width = (clientRect.width - X_ITEM_TYPE_4_LABEL_MAIN);
233 main.height = H_ITEM_TYPE_4_LABEL_MAIN;
235 sub.x = X_ITEM_TYPE_4_LABEL_SUB;
236 sub.y = Y_ITEM_TYPE_4_LABEL_SUB;
237 sub.width = main.width;
238 sub.height = H_ITEM_TYPE_4_LABEL_SUB;
243 BaseForm::GetFontSize(void)
245 int fontSize = FONT_MAIN_TEXT_SIZE_NORMAL;
246 String fontSizeValue;
248 if (SettingInfo::GetValue(SETTING_INFO_KEY_FONT_SIZE, fontSizeValue) == E_SUCCESS)
250 if (fontSizeValue.Equals(L"giant", false))
252 fontSize = FONT_MAIN_TEXT_SIZE_GIANT;
254 else if (fontSizeValue.Equals(L"huge", false))
256 fontSize = FONT_MAIN_TEXT_SIZE_HUGE;
258 else if (fontSizeValue.Equals(L"large", false))
260 fontSize = FONT_MAIN_TEXT_SIZE_LARGE;
262 else if (fontSizeValue.Equals(L"medium", false))
264 fontSize = FONT_MAIN_TEXT_SIZE_NORMAL;
268 fontSize = FONT_MAIN_TEXT_SIZE_SMALL;
275 BaseForm::OnOrientationChanged(const Tizen::Ui::Control& source, Tizen::Ui::OrientationStatus orientationStatus)
281 BaseForm::GetHeightForStringArea(const Tizen::Base::String source, int width, int fontSize) const
287 int lineCount = LINE_COUNT_DEFAULT;
288 int margin = BASE_FORM_DEFAULT_MARGIN + RELATIVE_LAYOUT_RIGHT_MARGIN;
289 if (fontSize > FONT_MAIN_TEXT_SIZE_LARGE)
291 OrientationStatus orientationStatus = GetOrientationStatus();
292 if (((orientationStatus == ORIENTATION_STATUS_PORTRAIT)
293 || (orientationStatus == ORIENTATION_STATUS_PORTRAIT_REVERSE))
294 && (fontSize == FONT_MAIN_TEXT_SIZE_HUGE))
296 width -= W_HUGE_SIZE_PORTRAIT_TEXT_GAP;
298 else if (((orientationStatus == ORIENTATION_STATUS_LANDSCAPE)
299 || (orientationStatus == ORIENTATION_STATUS_LANDSCAPE_REVERSE))
300 && (fontSize == FONT_MAIN_TEXT_SIZE_HUGE))
302 width -= W_HUGE_SIZE_LANDSCAPE_TEXT_GAP;
304 width -= W_LARGE_SIZE_TEXT_GAP;
306 int boudwidth = width - margin;
307 font.Construct(FONT_STYLE_PLAIN, fontSize);
309 for (int i = 0; i < source.GetLength(); i++)
311 temp.Append(source[i]);
312 font.GetTextExtent(temp, temp.GetLength(), dim);
313 if (dim.width > boudwidth)
316 temp.Append(source[i]);
321 return dim.height * lineCount;