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