Changed indicator bg color.
[platform/framework/native/uifw.git] / src / ui / controls / FUiCtrlCustomListItem.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         FUiCtrlCustomListItem.cpp
20 * @brief        This file contains implementation of CustomListItem class
21 */
22
23 #include <FGrpBitmap.h>
24 #include <FGrpRectangle.h>
25 #include <FUiCtrlCustomListItem.h>
26 #include <FUiCtrlCustomListItemFormat.h>
27 #include <FBaseSysLog.h>
28 #include "FUiCtrl_CustomListItemImpl.h"
29
30 using namespace Tizen::Base;
31 using namespace Tizen::Graphics;
32
33 namespace Tizen { namespace Ui { namespace Controls
34 {
35
36 CustomListItem::CustomListItem(void)
37         : __pCustomListItemFormat(null)
38         , __pCustomListItemImpl(null)
39 {
40 }
41
42 CustomListItem::~CustomListItem(void)
43 {
44         delete __pCustomListItemImpl;
45         __pCustomListItemImpl = null;
46 }
47
48 result
49 CustomListItem::Construct(int itemHeight)
50 {
51         result r = E_SUCCESS;
52
53         SysAssertf((__pCustomListItemImpl == null),
54                 "Already constructed. Calling Construct() twice or more on a same instance is not allowed for thisclass.");
55
56         __pCustomListItemImpl = _CustomListItemImpl::CreateInstanceN(itemHeight);
57         r = GetLastResult();
58         SysTryReturn(NID_UI_CTRL, __pCustomListItemImpl, r, r, "[%s] Propagating.", GetErrorMessage(r));
59
60         return r;
61 }
62
63 void
64 CustomListItem::SetItemFormat(const CustomListItemFormat& itemFormat)
65 {
66         SysAssertf((__pCustomListItemImpl != null), "Not yet constructed. Construct() should be called before use.");
67         __pCustomListItemFormat = const_cast< CustomListItemFormat* >(&itemFormat);
68 }
69
70 const CustomListItemFormat*
71 CustomListItem::GetItemFormat(void) const
72 {
73         return __pCustomListItemFormat;
74 }
75
76 void
77 CustomListItem::SetFocusedItemBackgroundBitmap(const Bitmap& bitmap)
78 {
79         SysAssertf((__pCustomListItemImpl != null), "Not yet constructed. Construct() should be called before use.");
80         __pCustomListItemImpl->SetFocusedItemBackgroundBitmap(bitmap);
81 }
82
83 void
84 CustomListItem::SetNormalItemBackgroundBitmap(const Bitmap& bitmap)
85 {
86         SysAssertf((__pCustomListItemImpl != null), "Not yet constructed. Construct() should be called before use.");
87         __pCustomListItemImpl->SetNormalItemBackgroundBitmap(bitmap);
88 }
89
90 void
91 CustomListItem::SetHighlightedItemBackgroundBitmap(const Bitmap& bitmap)
92 {
93         SysAssertf((__pCustomListItemImpl != null), "Not yet constructed. Construct() should be called before use.");
94         __pCustomListItemImpl->SetHighlightedItemBackgroundBitmap(bitmap);
95 }
96
97 result
98 CustomListItem::SetElement(int elementId, const String& text)
99 {
100         SysAssertf((__pCustomListItemImpl != null), "Not yet constructed. Construct() should be called before use.");
101         result r = __pCustomListItemImpl->SetElement(elementId, text);
102         SysTryReturn(NID_UI_CTRL, (r == E_SUCCESS), r, r, "[%s] Failed to Set an Element.", GetErrorMessage(r));
103
104         return E_SUCCESS;
105 }
106
107 result
108 CustomListItem::SetElement(int elementId, const Bitmap& normalBitmap, const Bitmap* pFocusedBitmap)
109 {
110         SysAssertf((__pCustomListItemImpl != null), "Not yet constructed. Construct() should be called before use.");
111
112         result r = __pCustomListItemImpl->SetElement(elementId, normalBitmap, pFocusedBitmap);
113         SysTryReturn(NID_UI_CTRL, (r == E_SUCCESS), r, r, "[%s] Failed to Set an Element.", GetErrorMessage(r));
114
115         return E_SUCCESS;
116 }
117
118 result
119 CustomListItem::SetElement(int elementId, const Bitmap& normalBitmap, const Bitmap* pFocusedBitmap, const Bitmap* pHighlightedBitmap)
120 {
121         SysAssertf((__pCustomListItemImpl != null), "Not yet constructed. Construct() should be called before use.");
122
123         result r = __pCustomListItemImpl->SetElement(elementId, normalBitmap, pFocusedBitmap, pHighlightedBitmap);
124         SysTryReturn(NID_UI_CTRL, (r == E_SUCCESS), r, r, "[%s] Failed to Set an Element.", GetErrorMessage(r));
125
126         return E_SUCCESS;
127 }
128
129 result
130 CustomListItem::SetElement(int elementId, const ICustomListElement& element)
131 {
132         SysAssertf((__pCustomListItemImpl != null), "Not yet constructed. Construct() should be called before use.");
133
134         result r = __pCustomListItemImpl->SetElement(elementId, element);
135         SysTryReturn(NID_UI_CTRL, (r == E_SUCCESS), r, r, "[%s] Failed to Set an Element.", GetErrorMessage(r));
136
137         return E_SUCCESS;
138 }
139
140 result
141 CustomListItem::SetCheckBox(int elementId)
142 {
143         SysAssertf((__pCustomListItemImpl != null), "Not yet constructed. Construct() should be called before use.");
144
145         SysTryReturnResult(NID_UI_CTRL, __pCustomListItemFormat, E_SYSTEM, "The CustomListItemFormat is not constructed.");
146
147         if (__pCustomListItemFormat->GetElement(elementId) == Rectangle(0, 0, -1, -1))
148         {
149                 return E_SYSTEM;
150         }
151
152         __pCustomListItemImpl->SetCheckBox(elementId);
153
154         return E_SUCCESS;
155 }
156
157 int
158 CustomListItem::GetValue(void) const
159 {
160         SysAssertf((__pCustomListItemImpl != null), "Not yet constructed. Construct() should be called before use.");
161         return -1;
162 }
163
164 }}} //Tizen::Ui::Controls