Tizen 2.1 base
[framework/osp/uifw.git] / src / ui / controls / FUiCtrl_TabBarItem.cpp
1 //
2 // Open Service Platform
3 // Copyright (c) 2012-2013 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  * @file                FUiCtrl_TabBarItem.cpp
19  * @brief               This is the implementation file for the _TabBarItem class.
20  */
21
22
23 #include <FBaseErrorDefine.h>
24 #include <FBaseSysLog.h>
25 #include "FUiCtrl_TabBarItem.h"
26 #include "FUi_ResourceManager.h"
27
28 using namespace Tizen::Graphics;
29
30 namespace Tizen { namespace Ui { namespace Controls
31 {
32
33 _TabBarItem::_TabBarItem(_ControlOrientation orientation)
34         : __actionId(-1)
35         , __text(L"")
36         , __status(ITEM_STATUS_MAX)
37 {
38         __bounds.x = 0;
39         GET_SHAPE_CONFIG(TABBAR::ITEM_MIN_WIDTH, orientation, __bounds.width);
40         GET_SHAPE_CONFIG(TABBAR::ITEM_HEIGHT, orientation, __bounds.height);
41         GET_SHAPE_CONFIG(TABBAR::TOP_MARGIN, orientation, __bounds.y);
42 }
43
44
45 _TabBarItem::~_TabBarItem(void)
46 {
47 }
48
49
50 void
51 _TabBarItem::SetActionId(int actionId)
52 {
53         __actionId = actionId;
54 }
55
56 int
57 _TabBarItem::GetActionId(void) const
58 {
59         return __actionId;
60 }
61
62 void
63 _TabBarItem::SetText(const Tizen::Base::String& text, _ControlOrientation orientation)
64 {
65         int fontSize = 0;
66         GET_SHAPE_CONFIG(TABBAR::FONT_SIZE, orientation, fontSize);
67         Dimension bounds(0, 0);
68
69         int minWidth = 0;
70         int maxWidth = 0;
71         int fontMargin = 0;
72         GET_SHAPE_CONFIG(TABBAR::ITEM_MIN_WIDTH, orientation, minWidth);
73         GET_SHAPE_CONFIG(TABBAR::ITEM_MAX_WIDTH, orientation, maxWidth);
74         GET_SHAPE_CONFIG(TABBAR::FONT_MARGIN, orientation, fontMargin);
75
76         Font font;
77         font.Construct(FONT_STYLE_BOLD, fontSize);
78         font.GetTextExtent(text, text.GetLength(), bounds);
79
80         bounds.width += 2 * fontMargin;
81         __bounds.width = bounds.width;
82
83         if (bounds.width < minWidth)
84         {
85                 __bounds.width = minWidth;
86         }
87
88         if (bounds.width > maxWidth)
89         {
90                 __bounds.width = maxWidth;
91         }
92
93         __text = text;
94 }
95
96 Tizen::Base::String
97 _TabBarItem::GetText(void) const
98 {
99         return __text;
100 }
101
102 void
103 _TabBarItem::SetStatus(_TabBarItemStatus status)
104 {
105         __status = status;
106 }
107
108 _TabBarItemStatus
109 _TabBarItem::GetStatus(void) const
110 {
111         return __status;
112 }
113
114 void
115 _TabBarItem::SetBounds(const Tizen::Graphics::Rectangle& bounds)
116 {
117         __bounds = bounds;
118 }
119
120 Tizen::Graphics::Rectangle
121 _TabBarItem::GetBounds(void) const
122 {
123         return __bounds;
124 }
125
126 }}} // Tizen::Ui::Controls