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