Applied latest source code
[apps/native/preloaded/Clock.git] / src / ClkDefaultCustomItem.cpp
1 //
2 //  Tizen Native SDK
3 // Copyright (c) 2012 Samsung Electronics Co., Ltd.
4 //
5 // Licensed under the Flora License, Version 1.1 (the License);
6 // you may not use this file except in compliance with the License.
7 // You may obtain a copy of the License at
8 //
9 //     http://floralicense.org/license/
10 //
11 // Unless required by applicable law or agreed to in writing, software
12 // distributed under the License is distributed on an AS IS BASIS,
13 // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14 // See the License for the specific language governing permissions and
15 // limitations under the License.
16 //
17
18 /**
19  * @file    ClkDefaultCustomItem
20  * @brief       This header file contains the declarations of the DefaultCustomItem
21  *
22  */
23
24 #include <FUiControls.h>
25 #include "ClkDefaultCustomItem.h"
26
27 using namespace Tizen::Base;
28 using namespace Tizen::Graphics;
29 using namespace Tizen::Ui::Controls;
30
31 static const int IDA_FORMAT_STRING = 101;
32 static const int IDA_FORMAT_SUB_STRING = 102;
33 static const int IDA_FORMAT_RIGHT_SUB_STRING = 103;
34
35 DefaultCustomItem::DefaultCustomItem(void)
36 :__rightSubText(""),
37  __subText(""),
38  __text("")
39
40 {
41
42 }
43
44 DefaultCustomItem::~DefaultCustomItem(void)
45 {
46
47 }
48
49 result
50 DefaultCustomItem::Construct(int width, int fontsize)
51 {
52         result r = E_FAILURE;
53         __width = width;
54         __height = 128 + fontsize - 44;
55         const Dimension dim(width, __height);
56         r = CustomItem::Construct(dim, LIST_ANNEX_STYLE_NORMAL);
57         return r;
58
59 }
60
61 void
62 DefaultCustomItem::SetText(String& text)
63 {
64         __text = text;
65 }
66
67 String
68 DefaultCustomItem::GetText(void)
69 {
70         return __text;
71 }
72
73 void
74 DefaultCustomItem::SetSubText(String& text)
75 {
76         __subText.Clear();
77         __subText.Append(text);
78 }
79
80 String
81 DefaultCustomItem::GetSubText(void)
82 {
83         return __subText;
84 }
85
86 void
87 DefaultCustomItem::SetRightSubText(String& text)
88 {
89         __rightSubText.Clear();
90         __rightSubText.Append(text);
91 }
92
93 String
94 DefaultCustomItem::GetRightSubText(void)
95 {
96         return __rightSubText;
97 }
98
99
100 result
101 DefaultCustomItem::Make(int fontSize)
102 {
103         result r = E_SUCCESS;
104
105         EnrichedText* pMainEnText = null;
106         EnrichedText* pSubEnText = null;
107         TextElement* pMainTextElement = null;
108         TextElement* pSubTextElement = null;
109         Font* pMainTextFont = null;
110         Font* pSubTextFont = null;
111         int mainTextFont = 32;
112         int subTextFont = fontSize;
113         int textX = 80;
114         int textY = 40;
115         int xMargin = 26;
116         int yMargin = 25;
117         int width_Element = __width - 60;
118         int width_text = width_Element;
119         int width_rightSubText = 0;
120         int stringHeight = 60;
121         int subStringHeight = 62 + fontSize - 44;
122         int subStringFont = 44;
123         Color textColor = Color(128, 128, 128);
124         Color pressedTextColor = Color(255, 255, 255);
125
126         pMainEnText = new (std::nothrow) EnrichedText();
127
128         if (pMainEnText == null)
129         {
130                 return E_FAILURE;
131         }
132
133         pMainEnText->Construct(Dimension(__width - textX, textY));
134
135         pMainTextElement = new (std::nothrow) TextElement();
136         pMainTextElement->Construct(__text);
137
138         pMainTextFont = new (std::nothrow) Font();
139
140         if (pMainTextFont == null)
141         {
142                 return E_FAILURE;
143         }
144
145         pMainTextFont->Construct(FONT_STYLE_BOLD, mainTextFont);
146
147         pMainTextElement->SetFont(*pMainTextFont);
148         pMainTextElement->SetTextColor(textColor);
149         pMainEnText->Add(*pMainTextElement);
150
151
152         if (__rightSubText != L"")
153         {
154                 width_rightSubText = 200;
155                 width_text = width_Element - width_rightSubText - 16;
156         }
157
158         r = AddElement(Rectangle(xMargin, yMargin, width_text, stringHeight), IDA_FORMAT_STRING, *pMainEnText);
159         //r = AddElement(Rectangle(xMargin, yMargin, width_text, stringHeight), IDA_FORMAT_STRING, __text, textSize, textColor, pressedTextColor, pressedTextColor, true);
160         //TryCatch( !IsFailed(r),L"DefaultCustomItem::Make %s",GetErrorMessage(r));
161
162         if (__subText != L"")
163         {
164                 pSubEnText = new (std::nothrow) EnrichedText();
165
166                 if (pSubEnText == null)
167                 {
168                         return E_FAILURE;
169                 }
170
171                 pSubEnText->Construct(Dimension(__width - textX, textY));
172
173                 pSubTextElement = new (std::nothrow) TextElement();
174             pSubTextElement->Construct(__subText);
175
176                 pSubTextFont = new (std::nothrow) Font();
177
178                 if (pSubTextFont == null)
179                 {
180                         return E_FAILURE;
181                 }
182
183                 pSubTextFont->Construct(FONT_STYLE_PLAIN, subTextFont);
184
185                 pSubTextElement->SetFont(*pSubTextFont);
186                 pSubTextElement->SetTextColor(Color(0, 0, 0));
187                 pSubEnText->Add(*pSubTextElement);
188
189                 r = AddElement(Rectangle(xMargin, yMargin + stringHeight -20, width_Element, subStringHeight), IDA_FORMAT_SUB_STRING, *pSubEnText);
190         }
191
192         if (__rightSubText != L"")
193         {
194                 r = AddElement(Rectangle(xMargin + width_text + 16, yMargin, width_rightSubText, subStringHeight), IDA_FORMAT_RIGHT_SUB_STRING, __rightSubText, subStringFont, Color(128,128,128), pressedTextColor, pressedTextColor, true);
195         }
196
197 //      SetElementSelectionEnabled(IDA_FORMAT_STRING, true);
198 //      SetElementSelectionEnabled(IDA_FORMAT_SUB_STRING, true);
199
200         if (pMainTextFont != null)
201         {
202                 delete pMainTextFont;
203                 pMainTextFont = null;
204         }
205
206         if (pSubTextFont != null)
207         {
208                 delete pSubTextFont;
209                 pSubTextFont = null;
210         }
211
212         if (pSubEnText != null)
213         {
214                 pSubEnText->RemoveAllTextElements(true);
215                 delete pSubEnText;
216                 pSubEnText = null;
217         }
218
219         if (pMainEnText != null)
220         {
221                 pMainEnText->RemoveAllTextElements(true);
222                 delete pMainEnText;
223                 pMainEnText = null;
224         }
225
226         return r;
227
228 }