DALi Version 1.1.29
[platform/core/uifw/dali-toolkit.git] / dali-toolkit / internal / controls / tool-bar / tool-bar-impl.h
1 #ifndef __DALI_TOOLKIT_INTERNAL_TOOL_BAR_H__
2 #define __DALI_TOOLKIT_INTERNAL_TOOL_BAR_H__
3
4 /*
5  * Copyright (c) 2014 Samsung Electronics Co., Ltd.
6  *
7  * Licensed under the Apache License, Version 2.0 (the "License");
8  * you may not use this file except in compliance with the License.
9  * You may obtain a copy of the License at
10  *
11  * http://www.apache.org/licenses/LICENSE-2.0
12  *
13  * Unless required by applicable law or agreed to in writing, software
14  * distributed under the License is distributed on an "AS IS" BASIS,
15  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
16  * See the License for the specific language governing permissions and
17  * limitations under the License.
18  *
19  */
20
21 // EXTERNAL INCLUDES
22 #include <dali/devel-api/common/map-wrapper.h>
23
24 // INTERNAL INCLUDES
25 #include <dali-toolkit/public-api/controls/control-impl.h>
26 #include <dali-toolkit/public-api/controls/table-view/table-view.h>
27 #include <dali-toolkit/devel-api/controls/tool-bar/tool-bar.h>
28
29 namespace Dali
30 {
31
32 namespace Toolkit
33 {
34
35 class ToolBar;
36
37 namespace Internal
38 {
39
40 /**
41  * ToolBar is a control to create a tool bar.
42  * @see Dali::Toolkit::ToolBar for more details.
43  */
44 class ToolBar : public Control
45 {
46 public:
47
48   /**
49    * Create an initialized ToolBar.
50    * @return A handle to a newly allocated Dali resource.
51    */
52   static Toolkit::ToolBar New();
53
54   /**
55    * @copydoc Dali::Toolkit::ToolBar::AddControl()
56    */
57   void AddControl( Dali::Actor control, float relativeSize, Toolkit::Alignment::Type alignment, const Toolkit::Alignment::Padding& padding );
58
59   /**
60    * @copydoc Dali::Toolkit::ToolBar::RemoveControl()
61    */
62   void RemoveControl( Dali::Actor control );
63
64 private: // From Control
65
66   /**
67    * @copydoc Toolkit::Control::OnInitialize()
68    */
69   virtual void OnInitialize();
70
71   /**
72    * Adds a control using some default values (the control uses 10% of the tool bar space and is placed on the left group).
73    * @param child The control to be added.
74    *
75    * @see Control::OnControlChildAdd()
76    */
77   virtual void OnControlChildAdd(Actor& child);
78
79 private:
80   /**
81    */
82   class Lock
83   {
84   public:
85     /**
86      * Constructor, sets the lock boolean
87      */
88     Lock( bool& lock )
89     : mLock( lock )
90     {
91       mLock = true;
92     }
93
94     /**
95      * Destructor, releases lock boolean
96      */
97     ~Lock()
98     {
99       mLock = false;
100     }
101   private:
102     bool& mLock;
103   };
104
105   /**
106    * Constructor.
107    * It initializes ToolBar members.
108    */
109   ToolBar();
110
111   /**
112    * A reference counted object may only be deleted by calling Unreference()
113    */
114   virtual ~ToolBar();
115
116 private:
117   Toolkit::TableView mLayout;                   ///< TableView used to place controls.
118   unsigned int       mLeftOffset;               ///< Offset index where the next control is going to be added in the left group.
119   unsigned int       mCenterBase;               ///< Base index where the first control of the center group is placed.
120   unsigned int       mCenterOffset;             ///< Offset index where the next control is going to be added in the center group.
121   unsigned int       mRightBase;                ///< Base index where the first control of the right group is placed.
122   unsigned int       mRightOffset;              ///< Offset index where the next control is going to be added in the right group.
123   float              mLeftRelativeSpace;        ///< Relative space between left and center groups of controls.
124   float              mRightRelativeSpace;       ///< Relative space between center and right groups of controls.
125   float              mAccumulatedRelativeSpace; ///< Stores the total percentage space used by controls.
126   bool               mInitializing;             ///< Allows the use of Actor's API to add controls.
127
128   std::map<Actor/*control*/,Toolkit::Alignment> mControls; ///< Stores a relationship between controls and their alignments used to place them inside the table view.
129 };
130
131 } // namespace Internal
132
133
134 // Helpers for public-api forwarding methods
135
136 inline Toolkit::Internal::ToolBar& GetImpl( Toolkit::ToolBar& toolBar )
137 {
138   DALI_ASSERT_ALWAYS( toolBar );
139
140   Dali::RefObject& handle = toolBar.GetImplementation();
141
142   return static_cast<Toolkit::Internal::ToolBar&>( handle );
143 }
144
145 inline const Toolkit::Internal::ToolBar& GetImpl( const Toolkit::ToolBar& toolBar )
146 {
147   DALI_ASSERT_ALWAYS( toolBar );
148
149   const Dali::RefObject& handle = toolBar.GetImplementation();
150
151   return static_cast<const Toolkit::Internal::ToolBar&>( handle );
152 }
153
154 } // namespace Toolkit
155
156 } // namespace Dali
157
158 #endif // __DALI_TOOLKIT_INTERNAL_TOOL_BAR_H__