Remove ini file
[apps/osp/Gallery.git] / src / GlDropDownCustomItem.cpp
1 //
2 // Copyright (c) 2012 Samsung Electronics Co., Ltd.
3 //
4 // Licensed under the Flora License, Version 1.0 (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
7 //
8 //     http://floralicense.org/license/
9 //
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.
15 //
16
17 /**
18  *@file:    DropDownCustomItem
19  *@brief: To create Drop Down custom item
20  *
21  */
22
23 #include <FApp.h>
24 #include <FUiControls.h>
25 #include "GlDropDownCustomItem.h"
26 #include "GlTypes.h"
27
28 using namespace Tizen::App;
29 using namespace Tizen::Base;
30 using namespace Tizen::Graphics;
31 using namespace Tizen::Ui::Controls;
32
33 const int DropDownCustomItem::IDA_FORMAT_BITMAP = 101;
34 const int DropDownCustomItem::IDA_FORMAT_MAIN_STRING = 102;
35 const int DropDownCustomItem::IDA_FORMAT_SUB_STRING = 103;
36 const int DropDownCustomItem::IDA_FORMAT_DROPPER = 104;
37
38 DropDownCustomItem::DropDownCustomItem(void)
39         : __currentState(DROP_DOWN__ITEM_STATE_CLOSED)
40         , __height(0)
41         , __width(0)
42 {
43 }
44
45 DropDownCustomItem::~DropDownCustomItem(void)
46 {
47 }
48
49 result
50 DropDownCustomItem::Construct(int width)
51 {
52         result r = E_SUCCESS;
53         __width = width;
54         __height = 140;
55         Dimension dim(__width, __height);
56         r = CustomItem::Construct(dim, LIST_ANNEX_STYLE_NORMAL);
57         return r;
58 }
59
60 void
61 DropDownCustomItem::SetMainText(const Tizen::Base::String& text)
62 {
63         __mainText = text;
64 }
65
66 String
67 DropDownCustomItem::GetMainText(void)
68 {
69         return __mainText;
70 }
71
72 void
73 DropDownCustomItem::SetSubText(const Tizen::Base::String& text)
74 {
75         __subText = text;
76 }
77
78 String
79 DropDownCustomItem::GetSubText(void)
80 {
81         return __subText;
82 }
83
84 result
85 DropDownCustomItem::Make()
86 {
87         AppLogDebug("DropDownCustomItem::Make entered");
88         result r = E_FAILURE;
89         EnrichedText* pMainEnText = null;
90         EnrichedText* pSubEnText = null;
91         TextElement* pMainTextElement = null;
92         TextElement* pSubTextElement = null;
93         Font mainTextFont;
94         Font subTextFont;
95         Tizen::Graphics::Bitmap* pDropperBitmapNormal = null;
96         Tizen::Graphics::Bitmap* pDropperBitmapPressed = null;
97
98         pMainEnText = new(std::nothrow) EnrichedText();
99         r = pMainEnText->Construct(Dimension(__width - 80, 54));
100         if (IsFailed(r))
101         {
102                 delete pMainEnText;
103                 return E_FAILURE;
104         }
105
106         pMainTextElement = new(std::nothrow) TextElement();
107         pMainTextElement->Construct(__mainText);
108
109         mainTextFont.Construct(FONT_STYLE_BOLD, 44);
110
111         Color pressedTextColor = CUSTOM_COLOR_LISTVIEW_TEXT;
112         pMainTextElement->SetFont(mainTextFont);
113         pMainTextElement->SetTextColor(CUSTOM_COLOR_TRANSPARENT);
114         pMainEnText->Add(*pMainTextElement);
115
116         pSubEnText = new(std::nothrow) EnrichedText();
117         r = pSubEnText->Construct(Dimension(__width - 80, 42));
118
119         if (IsFailed(r))
120         {
121                 pMainEnText->RemoveAll(true);
122                 delete pMainEnText;
123                 delete pSubEnText;
124                 return E_FAILURE;
125         }
126
127         pSubTextElement = new(std::nothrow) TextElement();
128         pSubTextElement->Construct(__subText);
129
130         subTextFont.Construct(FONT_STYLE_PLAIN, 32);
131
132         pSubTextElement->SetFont(subTextFont);
133         pSubTextElement->SetTextColor(CUSTOM_COLOR_GREY);
134         pSubEnText->Add(*pSubTextElement);
135
136         r = AddElement(Rectangle(26, 22, __width - 126, 54), IDA_FORMAT_MAIN_STRING, *pMainEnText);
137         r = AddElement(Rectangle(26, 76, __width - 126, 42), IDA_FORMAT_SUB_STRING, *pSubEnText);
138         if (IsFailed(r))
139         {
140                 pMainEnText->RemoveAll(true);
141                 pSubEnText->RemoveAll(true);
142                 delete pMainEnText;
143                 delete pSubEnText;
144                 return E_FAILURE;
145         }
146         AppResource* pAppResource = UiApp::GetInstance()->GetAppResource();
147         if (pAppResource)
148         {
149                 if (GetCurState() == DROP_DOWN__ITEM_STATE_CLOSED)
150                 {
151                         pDropperBitmapNormal = pAppResource->GetBitmapN(IDB_LIST_EXPAND_CLOSED, BITMAP_PIXEL_FORMAT_ARGB8888);
152                         pDropperBitmapPressed = pAppResource->GetBitmapN(IDB_LIST_EXPAND_CLOSED_PRESS, BITMAP_PIXEL_FORMAT_ARGB8888);
153                 }
154                 else
155                 {
156                         pDropperBitmapNormal = pAppResource->GetBitmapN(IDB_LIST_EXPAND_OPENED, BITMAP_PIXEL_FORMAT_ARGB8888);
157                         pDropperBitmapPressed = pAppResource->GetBitmapN(IDB_LIST_EXPAND_OPENED_PRESS, BITMAP_PIXEL_FORMAT_ARGB8888);
158                 }
159
160                 AddElement(Rectangle(__width - 95, (__height - 74) / 2, 74, 74), IDA_FORMAT_DROPPER, *pDropperBitmapNormal, pDropperBitmapPressed, pDropperBitmapNormal);
161                 delete pDropperBitmapNormal;
162                 delete pDropperBitmapPressed;
163         }
164
165         SetElementSelectionEnabled(IDA_FORMAT_MAIN_STRING, true);
166         SetElementSelectionEnabled(IDA_FORMAT_SUB_STRING, true);
167         SetElementSelectionEnabled(IDA_FORMAT_DROPPER, true);
168
169         pSubEnText->RemoveAllTextElements(true);
170         pMainEnText->RemoveAllTextElements(true);
171
172         delete pMainEnText;
173         delete pSubEnText;
174
175         return E_SUCCESS;
176 }
177
178 DropDownItemState
179 DropDownCustomItem::GetCurState(void)
180 {
181         return __currentState;
182 }
183
184 void
185 DropDownCustomItem::SetCurState(DropDownItemState state)
186 {
187         __currentState = state;
188 }