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