8f03f8c00578f572dc74668e447e037fb3039ca4
[platform/core/uifw/dali-toolkit.git] / optional / 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 #include <dali/dali.h>
22
23 // INTERNAL INCLUDES
24 #include <dali-toolkit/public-api/controls/control-impl.h>
25 #include <dali-toolkit/public-api/controls/tool-bar/tool-bar.h>
26 #include <dali-toolkit/public-api/controls/table-view/table-view.h>
27
28 namespace Dali
29 {
30
31 namespace Toolkit
32 {
33
34 class ToolBar;
35
36 namespace Internal
37 {
38
39 /**
40  * ToolBar is a control to create a tool bar.
41  * @see Dali::Toolkit::ToolBar for more details.
42  */
43 class ToolBar : public Control
44 {
45 public:
46
47   /**
48    * Create an initialized ToolBar.
49    * @return A handle to a newly allocated Dali resource.
50    */
51   static Toolkit::ToolBar New();
52
53   /**
54    * @copydoc Dali::Toolkit::View::SetBackground()
55    */
56   void SetBackground( Actor background );
57
58   /**
59    * @copydoc Dali::Toolkit::View::AddControl()
60    */
61   void AddControl( Dali::Actor control, float relativeSize, Toolkit::Alignment::Type alignment, const Toolkit::Alignment::Padding& padding );
62
63   /**
64    * @copydoc Dali::Toolkit::View::RemoveControl()
65    */
66   void RemoveControl( Dali::Actor control );
67
68 private: // From Control
69
70   /**
71    * @copydoc Toolkit::Control::OnInitialize()
72    */
73   virtual void OnInitialize();
74
75   /**
76    * Adds a control using some default values (the control uses 10% of the tool bar space and is placed on the left group).
77    * @param child The control to be added.
78    *
79    * @see Control::OnControlChildAdd()
80    */
81   virtual void OnControlChildAdd(Actor& child);
82
83   /**
84    * Called when the tool-bar is relaid out.
85    * @param[in] size The size allocated.
86    * @param[in/out] container the container to put actors not handled.
87    */
88   virtual void OnRelaidOut( Vector2 size, ActorSizeContainer& container );
89
90 private:
91   /**
92    */
93   class Lock
94   {
95   public:
96     /**
97      * Constructor, sets the lock boolean
98      */
99     Lock( bool& lock )
100     : mLock( lock )
101     {
102       mLock = true;
103     }
104
105     /**
106      * Destructor, releases lock boolean
107      */
108     ~Lock()
109     {
110       mLock = false;
111     }
112   private:
113     bool& mLock;
114   };
115
116   /**
117    * Constructor.
118    * It initializes ToolBar members.
119    */
120   ToolBar();
121
122   /**
123    * A reference counted object may only be deleted by calling Unreference()
124    */
125   virtual ~ToolBar();
126
127 private:
128   Toolkit::TableView mLayout;                   ///< TableView used to place controls.
129   unsigned int       mLeftOffset;               ///< Offset index where the next control is going to be added in the left group.
130   unsigned int       mCenterBase;               ///< Base index where the first control of the center group is placed.
131   unsigned int       mCenterOffset;             ///< Offset index where the next control is going to be added in the center group.
132   unsigned int       mRightBase;                ///< Base index where the first control of the right group is placed.
133   unsigned int       mRightOffset;              ///< Offset index where the next control is going to be added in the right group.
134   float              mLeftRelativeSpace;        ///< Relative space between left and center groups of controls.
135   float              mRightRelativeSpace;       ///< Relative space between center and right groups of controls.
136   float              mAccumulatedRelativeSpace; ///< Stores the total percentage space used by controls.
137   bool               mInitializing;             ///< Allows the use of Actor's API to add controls.
138
139   std::map<Actor/*control*/,Toolkit::Alignment> mControls; ///< Stores a relationship between controls and their alignments used to place them inside the table view.
140 };
141
142 } // namespace Internal
143
144
145 // Helpers for public-api forwarding methods
146
147 inline Toolkit::Internal::ToolBar& GetImpl( Toolkit::ToolBar& toolBar )
148 {
149   DALI_ASSERT_ALWAYS( toolBar );
150
151   Dali::RefObject& handle = toolBar.GetImplementation();
152
153   return static_cast<Toolkit::Internal::ToolBar&>( handle );
154 }
155
156 inline const Toolkit::Internal::ToolBar& GetImpl( const Toolkit::ToolBar& toolBar )
157 {
158   DALI_ASSERT_ALWAYS( toolBar );
159
160   const Dali::RefObject& handle = toolBar.GetImplementation();
161
162   return static_cast<const Toolkit::Internal::ToolBar&>( handle );
163 }
164
165 } // namespace Toolkit
166
167 } // namespace Dali
168
169 #endif // __DALI_TOOLKIT_INTERNAL_TOOL_BAR_H__