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