Fixed issue 30399
[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
89         Tizen::Graphics::Bitmap* pDropperBitmapNormal = null;
90         Tizen::Graphics::Bitmap* pDropperBitmapPressed = null;
91
92         AddElement(Rectangle(26, 22, __width - 126, 54), IDA_FORMAT_MAIN_STRING,__mainText,44,CUSTOM_COLOR_TRANSPARENT,CUSTOM_COLOR_TRANSPARENT,CUSTOM_COLOR_TRANSPARENT);
93         AddElement(Rectangle(26, 76, __width - 126, 42), IDA_FORMAT_SUB_STRING,__subText,34,CUSTOM_COLOR_GREY,CUSTOM_COLOR_GREY,CUSTOM_COLOR_GREY);
94
95         AppResource* pAppResource = UiApp::GetInstance()->GetAppResource();
96         if (pAppResource)
97         {
98                 if (GetCurState() == DROP_DOWN__ITEM_STATE_CLOSED)
99                 {
100                         pDropperBitmapNormal = pAppResource->GetBitmapN(IDB_LIST_EXPAND_CLOSED, BITMAP_PIXEL_FORMAT_ARGB8888);
101                         pDropperBitmapPressed = pAppResource->GetBitmapN(IDB_LIST_EXPAND_CLOSED_PRESS, BITMAP_PIXEL_FORMAT_ARGB8888);
102                 }
103                 else
104                 {
105                         pDropperBitmapNormal = pAppResource->GetBitmapN(IDB_LIST_EXPAND_OPENED, BITMAP_PIXEL_FORMAT_ARGB8888);
106                         pDropperBitmapPressed = pAppResource->GetBitmapN(IDB_LIST_EXPAND_OPENED_PRESS, BITMAP_PIXEL_FORMAT_ARGB8888);
107                 }
108
109                 AddElement(Rectangle(__width - 95, (__height - 74) / 2, 74, 74), IDA_FORMAT_DROPPER, *pDropperBitmapNormal, pDropperBitmapPressed, pDropperBitmapNormal);
110                 delete pDropperBitmapNormal;
111                 delete pDropperBitmapPressed;
112         }
113
114         SetElementSelectionEnabled(IDA_FORMAT_MAIN_STRING, true);
115         SetElementSelectionEnabled(IDA_FORMAT_SUB_STRING, true);
116         SetElementSelectionEnabled(IDA_FORMAT_DROPPER, true);
117
118         return E_SUCCESS;
119 }
120
121 DropDownItemState
122 DropDownCustomItem::GetCurState(void)
123 {
124         return __currentState;
125 }
126
127 void
128 DropDownCustomItem::SetCurState(DropDownItemState state)
129 {
130         __currentState = state;
131 }