Initialize Tizen 2.3
[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.1 (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 "GlDropDownCustomItem.h"
25 #include "GlTypes.h"
26
27 using namespace Tizen::App;
28 using namespace Tizen::Base;
29 using namespace Tizen::Graphics;
30 using namespace Tizen::Ui::Controls;
31
32 const int DropDownCustomItem::IDA_FORMAT_BITMAP = 101;
33 const int DropDownCustomItem::IDA_FORMAT_MAIN_STRING = 102;
34 const int DropDownCustomItem::IDA_FORMAT_SUB_STRING = 103;
35 const int DropDownCustomItem::IDA_FORMAT_DROPPER = 104;
36
37 DropDownCustomItem::DropDownCustomItem(void)
38         : __currentState(DROP_DOWN_ITEM_STATE_CLOSED)
39         , __height(0)
40         , __width(0)
41 {
42 }
43
44 DropDownCustomItem::~DropDownCustomItem(void)
45 {
46 }
47
48 result
49 DropDownCustomItem::Construct(int width, int height)
50 {
51         __width = width;
52         __height = height + 28;
53         Dimension dim(__width, __height);
54         result r = CustomItem::Construct(dim, LIST_ANNEX_STYLE_NORMAL);
55         return r;
56 }
57
58 void
59 DropDownCustomItem::SetMainText(const Tizen::Base::String& text)
60 {
61         __mainText = text;
62 }
63
64 String
65 DropDownCustomItem::GetMainText(void) const
66 {
67         return __mainText;
68 }
69
70 void
71 DropDownCustomItem::SetSubText(const Tizen::Base::String& text)
72 {
73         __subText = text;
74 }
75
76 String
77 DropDownCustomItem::GetSubText(void) const
78 {
79         return __subText;
80 }
81
82 result
83 DropDownCustomItem::Make(int fontsize, int itemHeight)
84 {
85         AppLogDebug("DropDownCustomItem::Make entered");
86
87         int xMargin = 26;
88         int yMargin = 22;
89         int subTextHeight = 42;
90         int mainTextHeight = itemHeight - yMargin - subTextHeight + 15;
91
92         Tizen::Graphics::Bitmap* pDropperBitmapNormal = null;
93         Tizen::Graphics::Bitmap* pDropperBitmapPressed = null;
94
95         AddElement(Rectangle(xMargin, yMargin, __width - 126, mainTextHeight), IDA_FORMAT_MAIN_STRING,__mainText, fontsize,
96                         CUSTOM_COLOR_TRANSPARENT, CUSTOM_COLOR_TRANSPARENT, CUSTOM_COLOR_TRANSPARENT);
97         AddElement(Rectangle(xMargin, yMargin + mainTextHeight, __width - 126, subTextHeight), IDA_FORMAT_SUB_STRING,__subText, 34, CUSTOM_COLOR_GREY , CUSTOM_COLOR_LISTVIEW_TEXT, CUSTOM_COLOR_LISTVIEW_TEXT);
98
99         AppResource* pAppResource = UiApp::GetInstance()->GetAppResource();
100         if (pAppResource)
101         {
102                 if (GetCurState() == DROP_DOWN_ITEM_STATE_CLOSED)
103                 {
104                         pDropperBitmapNormal = pAppResource->GetBitmapN(IDB_LIST_EXPAND_CLOSED, BITMAP_PIXEL_FORMAT_ARGB8888);
105                         pDropperBitmapPressed = pAppResource->GetBitmapN(IDB_LIST_EXPAND_CLOSED_PRESS, BITMAP_PIXEL_FORMAT_ARGB8888);
106                 }
107                 else
108                 {
109                         pDropperBitmapNormal = pAppResource->GetBitmapN(IDB_LIST_EXPAND_OPENED, BITMAP_PIXEL_FORMAT_ARGB8888);
110                         pDropperBitmapPressed = pAppResource->GetBitmapN(IDB_LIST_EXPAND_OPENED_PRESS, BITMAP_PIXEL_FORMAT_ARGB8888);
111                 }
112
113                 AddElement(Rectangle(__width - 85, (__height - 64) / 2, 64, 64), IDA_FORMAT_DROPPER, *pDropperBitmapNormal, pDropperBitmapPressed, pDropperBitmapNormal);
114                 delete pDropperBitmapNormal;
115         delete pDropperBitmapPressed;
116         }
117
118         return E_SUCCESS;
119 }
120
121 DropDownItemState
122 DropDownCustomItem::GetCurState(void) const
123 {
124         return __currentState;
125 }
126
127 void
128 DropDownCustomItem::SetCurState(const DropDownItemState state)
129 {
130         __currentState = state;
131 }