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