Changed indicator bg color.
[platform/framework/native/uifw.git] / src / ui / controls / FUiCtrl_CustomListItemFormatImpl.cpp
1 //
2 // Open Service Platform
3 // Copyright (c) 2012-2013 Samsung Electronics Co., Ltd.
4 //
5 // Licensed under the Apache License, Version 2.0 (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://www.apache.org/licenses/LICENSE-2.0/
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         FUiCtrl_CustomListItemFormatImpl.cpp
20 * @brief        This file contains implementation of _CustomListItemFormatImpl class
21 */
22
23 #include <FBaseSysLog.h>
24 #include "FUiCtrl_CustomListItemFormatImpl.h"
25 #include "FUi_ResourceManager.h"
26
27 using namespace Tizen::Graphics;
28 using namespace Tizen::Base::Collection;
29
30 namespace Tizen { namespace Ui { namespace Controls
31 {
32
33 _ElementFormatData::_ElementFormatData(void)
34         : elementId(-1)
35         , textSize(0)
36         , enable(false)
37 {
38 }
39
40 _ElementFormatData::~_ElementFormatData(void)
41 {
42 }
43
44 _CustomListItemFormatImpl::_CustomListItemFormatImpl(void)
45 {
46 }
47
48 _CustomListItemFormatImpl::~_CustomListItemFormatImpl(void)
49 {
50         elementFormatDataList.RemoveAll(true);
51 }
52
53 _CustomListItemFormatImpl*
54 _CustomListItemFormatImpl::CreateInstanceN(void)
55 {
56         _CustomListItemFormatImpl* pImpl = new (std::nothrow) _CustomListItemFormatImpl();
57         SysTryReturn(NID_UI_CTRL, pImpl, null, E_OUT_OF_MEMORY, "[E_OUT_OF_MEMORY] Memory allocation failed.");
58
59         return pImpl;
60 }
61
62 _ElementFormatData*
63 _CustomListItemFormatImpl::GetElementFormatById(int elementId)
64 {
65         for (int elementCount = 0; elementCount < elementFormatDataList.GetCount(); elementCount++)
66     {
67         _ElementFormatData* pElementFormatData = dynamic_cast<_ElementFormatData*>(elementFormatDataList.GetAt(elementCount));
68         SysTryReturn(NID_UI_CTRL, pElementFormatData, null, E_SYSTEM, "Invalid format data.");
69
70         if (pElementFormatData->elementId == elementId)
71         {
72                 return pElementFormatData;
73         }
74     }
75
76     return null;
77 }
78
79 _ElementFormatData*
80 _CustomListItemFormatImpl::CreateElementN(int elementId)
81 {
82         _ElementFormatData* pElementFormatData = new (std::nothrow) _ElementFormatData();
83         SysTryReturn(NID_UI_CTRL, pElementFormatData, null, E_OUT_OF_MEMORY, "The memory is insufficient.");
84
85         pElementFormatData->elementId = elementId;
86
87         GET_SHAPE_CONFIG(LIST::TEXT_ELEMENT_FONTSIZE_DEFAULT, _CONTROL_ORIENTATION_PORTRAIT, pElementFormatData->textSize);
88
89         GET_COLOR_CONFIG(LIST::ELEMENT_TEXT_NORMAL, pElementFormatData->normalTextColor);
90         GET_COLOR_CONFIG(LIST::ELEMENT_TEXT_NORMAL, pElementFormatData->highlightedTextColor);
91         GET_COLOR_CONFIG(LIST::ELEMENT_TEXT_NORMAL, pElementFormatData->focusedTextColor);
92
93         return pElementFormatData;
94 }
95
96 result
97 _CustomListItemFormatImpl::AddElement(int elementId, const Rectangle& rect)
98 {
99         _ElementFormatData* pElementFormatData = GetElementFormatById(elementId);
100         result r = E_SUCCESS;
101
102         if (!pElementFormatData)
103         {
104                 pElementFormatData = CreateElementN(elementId);
105                 r = GetLastResult();
106                 SysTryReturnResult(NID_UI_CTRL, pElementFormatData, r, "[%s] Propagating.", GetErrorMessage(r));
107
108                 r = elementFormatDataList.Add(*pElementFormatData);
109                 SysTryReturn(NID_UI_CTRL, r == E_SUCCESS, r, r, "[%s] Propagating.", GetErrorMessage(r));
110
111                 GET_SHAPE_CONFIG(LIST::TEXT_ELEMENT_FONTSIZE_DEFAULT, _CONTROL_ORIENTATION_PORTRAIT, pElementFormatData->textSize);
112         }
113
114         pElementFormatData->rect = rect;
115
116         return r;
117 }
118
119 result
120 _CustomListItemFormatImpl::AddElement(int elementId, const Rectangle& rect, int textSize)
121 {
122         _ElementFormatData* pElementFormatData = GetElementFormatById(elementId);
123         result r = E_SUCCESS;
124
125         if (!pElementFormatData)
126         {
127                 pElementFormatData = CreateElementN(elementId);
128                 r = GetLastResult();
129                 SysTryReturnResult(NID_UI_CTRL, pElementFormatData, r, "[%s] Propagating.", GetErrorMessage(r));
130
131                 r = elementFormatDataList.Add(*pElementFormatData);
132                 SysTryReturn(NID_UI_CTRL, r == E_SUCCESS, r, r, "[%s] Propagating.", GetErrorMessage(r));
133         }
134
135         pElementFormatData->rect = rect;
136         pElementFormatData->textSize = textSize;
137
138         return r;
139 }
140
141 result
142 _CustomListItemFormatImpl::AddElement(int elementId, const Rectangle& rect, int textSize, const Color& normalTextColor, const Color& focusedTextColor)
143 {
144         _ElementFormatData* pElementFormatData = GetElementFormatById(elementId);
145         result r = E_SUCCESS;
146
147         if (!pElementFormatData)
148         {
149                 pElementFormatData = CreateElementN(elementId);
150                 r = GetLastResult();
151                 SysTryReturnResult(NID_UI_CTRL, pElementFormatData, r, "[%s] Propagating.", GetErrorMessage(r));
152
153                 r = elementFormatDataList.Add(*pElementFormatData);
154                 SysTryReturn(NID_UI_CTRL, r == E_SUCCESS, r, r, "[%s] Propagating.", GetErrorMessage(r));
155         }
156
157         pElementFormatData->rect = rect;
158         pElementFormatData->textSize = textSize;
159
160         pElementFormatData->normalTextColor = normalTextColor;
161         pElementFormatData->focusedTextColor = focusedTextColor;
162         pElementFormatData->highlightedTextColor = normalTextColor;
163
164         return r;
165 }
166
167 result
168 _CustomListItemFormatImpl::AddElement(int elementId, const Rectangle& rect, int textSize, const Color& normalTextColor, const Color& focusedTextColor, const Color& highlightedTextColor)
169 {
170         _ElementFormatData* pElementFormatData = GetElementFormatById(elementId);
171         result r = E_SUCCESS;
172
173         if (!pElementFormatData)
174         {
175                 pElementFormatData = CreateElementN(elementId);
176                 r = GetLastResult();
177                 SysTryReturnResult(NID_UI_CTRL, pElementFormatData, r, "[%s] Propagating.", GetErrorMessage(r));
178
179                 r = elementFormatDataList.Add(*pElementFormatData);
180                 SysTryReturn(NID_UI_CTRL, r == E_SUCCESS, r, r, "[%s] Propagating.", GetErrorMessage(r));
181         }
182
183         pElementFormatData->rect = rect;
184         pElementFormatData->textSize = textSize;
185
186         pElementFormatData->normalTextColor = normalTextColor;
187         pElementFormatData->focusedTextColor = focusedTextColor;
188         pElementFormatData->highlightedTextColor = highlightedTextColor;
189
190         return r;
191 }
192
193 Rectangle
194 _CustomListItemFormatImpl::GetElement(int elementId) const
195 {
196         _ElementFormatData* pElementFormatData = null;
197         for (int count = 0; count < elementFormatDataList.GetCount(); count++)
198         {
199                 pElementFormatData = dynamic_cast<_ElementFormatData*>(const_cast<Object*>(elementFormatDataList.GetAt(count)));
200
201                 if (pElementFormatData != null && pElementFormatData->elementId == elementId)
202                 {
203                         return pElementFormatData->rect;
204                 }
205         }
206
207         return Rectangle(0, 0, -1, -1);
208 }
209
210 int
211 _CustomListItemFormatImpl::GetFirstElementId(void)
212 {
213         _ElementFormatData* pElementFormatData = null;
214
215         for (int count = 0; count < elementFormatDataList.GetCount(); count++)
216         {
217                 pElementFormatData = dynamic_cast<_ElementFormatData*>(const_cast<Object*>(elementFormatDataList.GetAt(count)));
218                 if (pElementFormatData != null)
219                 {
220                         return pElementFormatData->elementId;
221                 }
222         }
223
224         return -1;
225 }
226
227 int
228 _CustomListItemFormatImpl::GetFirstEnabledElementId(void)
229 {
230         _ElementFormatData* pElementFormatData = null;
231
232         for (int count = 0; count < elementFormatDataList.GetCount(); count++)
233         {
234                 pElementFormatData = dynamic_cast<_ElementFormatData*>(const_cast<Object*>(elementFormatDataList.GetAt(count)));
235                 if (pElementFormatData != null && pElementFormatData->enable)
236                 {
237                         return pElementFormatData->elementId;
238                 }
239         }
240
241         return -1;
242 }
243
244 int
245 _CustomListItemFormatImpl::GetNextElementId(int elementId)
246 {
247         _ElementFormatData* pElementFormatData = null;
248         int nextElementId = -1;
249         bool found = false;
250
251         for (int count = 0; count < elementFormatDataList.GetCount(); count++)
252         {
253                 pElementFormatData = dynamic_cast<_ElementFormatData*>(elementFormatDataList.GetAt(count));
254                 if (pElementFormatData != null)
255                 {
256                         if (elementId == pElementFormatData->elementId)
257                         {
258                                 found = true;
259                         }
260                         else if (found == true)
261                         {
262                                 nextElementId = pElementFormatData->elementId;
263                                 break;
264                         }
265                 }
266         }
267         return nextElementId;
268 }
269
270 int
271 _CustomListItemFormatImpl::GetNextEnabledElementId(int elementId)
272 {
273         _ElementFormatData* pElementFormatData = null;
274         int nextEnabledElementId = -1;
275         bool found = false;
276
277         for (int count = 0; count < elementFormatDataList.GetCount(); count++)
278         {
279                 pElementFormatData = dynamic_cast<_ElementFormatData*>(elementFormatDataList.GetAt(count));
280                 if (pElementFormatData != null)
281                 {
282                         if (pElementFormatData->elementId == elementId)
283                         {
284                                 found = true;
285                         }
286                         else if (pElementFormatData->enable && found == true)
287                         {
288                                 nextEnabledElementId = pElementFormatData->elementId;
289                                 break;
290                         }
291                 }
292         }
293
294         return nextEnabledElementId;
295 }
296
297 int
298 _CustomListItemFormatImpl::GetPreviousEnabledElementId(int elementId)
299 {
300         _ElementFormatData* pElementFormatData = null;
301         int prevEnabledElementId = -1;
302
303         for (int count = 0; count < elementFormatDataList.GetCount(); count++)
304         {
305                 pElementFormatData = dynamic_cast<_ElementFormatData*>(elementFormatDataList.GetAt(count));
306                 if (pElementFormatData != null)
307                 {
308                         if (pElementFormatData->elementId != elementId)
309                         {
310                                 prevEnabledElementId = pElementFormatData->elementId;
311                         }
312                         else if (pElementFormatData->enable && pElementFormatData->elementId == elementId)
313                         {
314                                 break;
315                         }
316                 }
317         }
318
319         return prevEnabledElementId;
320 }
321
322 bool
323 _CustomListItemFormatImpl::IsElementEventEnabled(int elementId)
324 {
325         _ElementFormatData* pElementFormatData = null;
326
327         for (int count = 0; count < elementFormatDataList.GetCount(); count++)
328         {
329                 pElementFormatData = dynamic_cast<_ElementFormatData*>(const_cast<Object*>(elementFormatDataList.GetAt(count)));
330                 if (pElementFormatData != null && pElementFormatData->elementId == elementId)
331                 {
332                         return pElementFormatData->enable;
333                 }
334         }
335
336         return false;
337 }
338
339 void
340 _CustomListItemFormatImpl::SetElementEventEnabled(int elementId, bool enable)
341 {
342         _ElementFormatData* pElementFormatData = null;
343
344         for (int count = 0; count < elementFormatDataList.GetCount(); count++)
345         {
346                 pElementFormatData = dynamic_cast<_ElementFormatData*>(const_cast<Object*>(elementFormatDataList.GetAt(count)));
347                 if (pElementFormatData != null && pElementFormatData->elementId == elementId)
348                 {
349                         pElementFormatData->enable = enable;
350                 }
351         }
352
353         return;
354 }
355
356 }}} //Tizen::Ui::Controls