Applied latest source code
[apps/native/preloaded/Clock.git] / src / ClkDropdownAndRepeatCustomItem.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         ClkDropDownCustomItem
20  *@brief        To create Drop Down custom item
21  *
22  */
23
24 #include <FApp.h>
25 #include <FBase.h>
26 #include <FGraphics.h>
27 #include <FUiControls.h>
28
29 #include "ClkDropdownAndRepeatCustomItem.h"
30 #include "ClkTypes.h"
31
32 using namespace Tizen::App;
33 using namespace Tizen::Base;
34 using namespace Tizen::Graphics;
35 using namespace Tizen::Ui::Controls;
36
37 static const int IDA_FORMAT_MAIN_STRING = 101;
38 static const int IDA_FORMAT_SUB_STRING = 102;
39 static const int IDA_FORMAT_DROPPER = 103;
40
41 DropdownAndRepeatCustomItem::DropdownAndRepeatCustomItem(void)
42         : currentState(DROP_DOWN_AND_REPEAT_ITEM_STATE_CLOSED)
43         , __height(0)
44         , __mainText("")
45         , __repeatFlags("")
46         , __subText("")
47         , __width(0)
48 {
49
50 }
51
52 DropdownAndRepeatCustomItem::~DropdownAndRepeatCustomItem(void)
53 {
54
55 }
56
57 result
58 DropdownAndRepeatCustomItem::Construct(int width)
59 {
60         result r = E_SUCCESS;
61         __width = width;
62         __height = 128;
63         Dimension dim(__width, __height);
64         r = CustomItem::Construct(dim, LIST_ANNEX_STYLE_NORMAL);
65         return r;
66 }
67
68 void
69 DropdownAndRepeatCustomItem::SetMainText(const String& text)
70 {
71         __mainText = text;
72 }
73
74 String
75 DropdownAndRepeatCustomItem::GetMainText(void) const
76 {
77         return __mainText;
78 }
79
80 void
81 DropdownAndRepeatCustomItem::SetSubText(const String& text)
82 {
83         __subText = text;
84 }
85
86 String
87 DropdownAndRepeatCustomItem::GetSubText(void) const
88 {
89         return __subText;
90 }
91
92 void
93 DropdownAndRepeatCustomItem::SetRepeatFlags(const String& flag)
94 {
95         __repeatFlags = flag;
96 }
97
98 String
99 DropdownAndRepeatCustomItem::GetRepeatFlag(void) const
100 {
101         return __repeatFlags;
102 }
103
104 result
105 DropdownAndRepeatCustomItem::MakeElements()
106 {
107         AppLogDebug("DropDownCustomItem::Make entered");
108         result r = E_FAILURE;
109         EnrichedText* pMainEnText = null;
110         EnrichedText* pSubEnText = null;
111         TextElement* pMainTextElement = null;
112         TextElement* pSubTextElement = null;
113         Font* pMainTextFont = null;
114         Font* pSubTextFont = null;
115         AppResource* pAppResource = null;
116         Bitmap* pDropperBitmapNormal = null;
117         Bitmap* pDropperBitmapPressed = null;
118         Color textColor = Color(0, 0, 0);
119         Color pressedTextColor = Color(249, 249, 249);
120         int xText = 80;
121         int yText = 40;
122         int subTextFont = 32;
123         int repeatFlagX = 26;
124         int characterGap = 37;
125         int repeatFlagY = 75;
126         int repeatFlagWidth = 32;
127         int repeatFlagHeight = 48;
128         int repeatFlagFont = 32;
129         int mainStringX = 26;
130         int mainStringY = 25;
131         int mainStringWidth = 80;
132         int mainStringHeight = 60;
133         int dropperX = 87;
134         int dropperY = 64;
135         int dropperWidth = 64;
136         int dropperHeight = 64;
137         pMainEnText = new (std::nothrow) EnrichedText();
138
139         if (pMainEnText == null)
140         {
141                 return E_FAILURE;
142         }
143
144         pMainEnText->Construct(Dimension(__width - xText, yText));
145
146         pMainTextElement = new (std::nothrow) TextElement();
147
148         if (pMainTextElement == null)
149         {
150                 return E_FAILURE;
151         }
152
153         pMainTextElement->Construct(__mainText);
154
155         pMainTextFont = new (std::nothrow) Font();
156
157         if (pMainTextFont == null)
158         {
159                 return E_FAILURE;
160         }
161
162         pMainTextFont->Construct(FONT_STYLE_PLAIN, yText);
163
164         pMainTextElement->SetFont(*pMainTextFont);
165         pMainTextElement->SetTextColor(textColor);
166         pMainEnText->Add(*pMainTextElement);
167
168         pSubEnText = new (std::nothrow) EnrichedText();
169
170         if (pSubEnText == null)
171         {
172                 return E_FAILURE;
173         }
174
175         pSubEnText->Construct(Dimension(__width - xText, yText));
176
177         pSubTextElement = new (std::nothrow) TextElement();
178
179         if (pSubTextElement == null)
180         {
181                 return E_FAILURE;
182         }
183
184         __subText.Insert('\n',0);
185     pSubTextElement->Construct(__subText);
186
187         pSubTextFont = new (std::nothrow) Font();
188
189         if (pSubTextFont == null)
190         {
191                 return E_FAILURE;
192         }
193
194         pSubTextFont->Construct(FONT_STYLE_PLAIN, subTextFont);
195
196         pSubTextElement->SetFont(*pSubTextFont);
197         pSubTextElement->SetTextColor(Color(128, 128, 128));
198         pMainEnText->Add(*pSubTextElement);
199
200         for (int i = 0; i < 7 ; i++)
201         {
202                 AppLogDebug("inside for loop");
203                 String flag = L"";
204                 wchar_t ch;
205
206                 GetRepeatFlag().GetCharAt(i, ch);
207                 AppLogDebug("the flag is %ls",GetRepeatFlag().GetPointer());
208
209                 if (ch == '1')
210                 {
211                         textColor = Color::GetColor(COLOR_ID_BLUE);
212                         AppLogDebug("color is blue");
213                 }
214                 else
215                 {
216                         textColor = Color(124,124,124);
217                 }
218
219                 switch (i)
220                 {
221                         case 0:
222                                 flag.Append(L"S");
223                                 break;
224                         case 1:
225                                 flag.Append(L"M");
226                                 break;
227                         case 2:
228                                 flag.Append(L"T");
229                                 break;
230                         case 3:
231                                 flag.Append(L"W");
232                                 break;
233                         case 4:
234                                 flag.Append(L"T");
235                                 break;
236                         case 5:
237                                 flag.Append(L"F");
238                                 break;
239                         case 6:
240                                 flag.Append(L"S");
241                                 break;
242                 }
243
244                 AppLogDebug("the string is  %ls", flag.GetPointer());
245                 r = AddElement(Rectangle(repeatFlagX + i*characterGap, repeatFlagY, repeatFlagWidth, repeatFlagHeight), i, flag, repeatFlagFont, textColor, textColor, textColor, true);
246                 AppLogDebug("the last result  %s", GetErrorMessage(r));
247         }
248         r = AddElement(Rectangle(mainStringX, mainStringY, __width - mainStringWidth, mainStringHeight), IDA_FORMAT_MAIN_STRING, __mainText);
249
250         pAppResource = UiApp::GetInstance()->GetAppResource();
251
252         if (pAppResource != null)
253         {
254
255                 if (GetCurState() == DROP_DOWN_AND_REPEAT_ITEM_STATE_CLOSED)
256                 {
257                         pDropperBitmapNormal = pAppResource->GetBitmapN(IDB_LIST_EXPAND_CLOSED, BITMAP_PIXEL_FORMAT_ARGB8888);
258                         pDropperBitmapPressed = pAppResource->GetBitmapN(IDB_LIST_EXPAND_CLOSED_PRESS, BITMAP_PIXEL_FORMAT_ARGB8888);
259                 }
260                 else
261                 {
262                         pDropperBitmapNormal = pAppResource->GetBitmapN(IDB_LIST_EXPAND_OPENED, BITMAP_PIXEL_FORMAT_ARGB8888);
263                         pDropperBitmapPressed = pAppResource->GetBitmapN(IDB_LIST_EXPAND_OPENED_PRESS, BITMAP_PIXEL_FORMAT_ARGB8888);
264                 }
265
266                 AddElement(Rectangle(__width - dropperX, (__height - dropperY) / 2, dropperWidth, dropperHeight), IDA_FORMAT_DROPPER, *pDropperBitmapNormal, pDropperBitmapPressed, pDropperBitmapNormal);
267                 delete pDropperBitmapNormal;
268                 delete pDropperBitmapPressed;
269         }
270
271         SetElementSelectionEnabled(IDA_FORMAT_MAIN_STRING, true);
272         SetElementSelectionEnabled(IDA_FORMAT_SUB_STRING, true);
273         SetElementSelectionEnabled(IDA_FORMAT_DROPPER, true);
274
275         if (pMainTextFont != null)
276         {
277                 delete pMainTextFont;
278                 pMainTextFont = null;
279         }
280
281         if (pSubTextFont != null)
282         {
283                 delete pSubTextFont;
284                 pSubTextFont = null;
285         }
286
287         if (pSubEnText != null)
288         {
289                 pSubEnText->RemoveAllTextElements(true);
290                 delete pSubEnText;
291                 pSubEnText = null;
292         }
293
294         if (pMainEnText != null)
295         {
296                 pMainEnText->RemoveAllTextElements(true);
297                 delete pMainEnText;
298                 pMainEnText = null;
299         }
300
301         return E_SUCCESS;
302 }
303
304 DropDownAndRepeatItemState
305 DropdownAndRepeatCustomItem::GetCurState(void) const
306 {
307         return currentState;
308 }
309
310 void
311 DropdownAndRepeatCustomItem::SetCurState(const DropDownAndRepeatItemState state)
312 {
313         currentState = state;
314 }