[dali_2.3.19] Merge branch 'devel/master'
[platform/core/uifw/dali-toolkit.git] / dali-toolkit / internal / controls / text-controls / text-selection-toolbar-impl.h
1 #ifndef DALI_TOOLKIT_INTERNAL_TEXT_SELECTION_TOOLBAR_H
2 #define DALI_TOOLKIT_INTERNAL_TEXT_SELECTION_TOOLBAR_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 // INTERNAL INCLUDES
22 #include <dali-toolkit/devel-api/controls/scroll-bar/scroll-bar.h>
23 #include <dali-toolkit/devel-api/controls/table-view/table-view.h>
24 #include <dali-toolkit/devel-api/controls/text-controls/text-selection-toolbar.h>
25 #include <dali-toolkit/public-api/controls/control-impl.h>
26 #include <dali-toolkit/public-api/controls/scrollable/scroll-view/scroll-view.h>
27
28 // EXTERNAL INCLUDES
29 #include <dali/public-api/actors/layer.h>
30
31 namespace Dali
32 {
33 namespace Toolkit
34 {
35 namespace Internal
36 {
37 class TextSelectionToolbar : public Control
38 {
39 public:
40   /**
41    * @copydoc Dali::Toollkit::TextSelectionToolbar::New()
42    */
43   static Toolkit::TextSelectionToolbar New();
44
45   // Properties
46
47   /**
48    * @brief Called when a property of an object of this type is set.
49    * @param[in] object The object whose property is set.
50    * @param[in] index The property index.
51    * @param[in] value The new property value.
52    */
53   static void SetProperty(BaseObject* object, Property::Index index, const Property::Value& value);
54
55   /**
56    * @brief Called to retrieve a property of an object of this type.
57    *
58    * @param[in] object The object whose property is to be retrieved.
59    * @param[in] index The property index.
60    * @return The current value of the property.
61    */
62   static Property::Value GetProperty(BaseObject* object, Property::Index index);
63
64   /**
65    *  @copydoc Toolkit::TextSelectionToolbar::AddOption()
66    */
67   void AddOption(Actor& option);
68
69   /**
70    *  @copydoc Toolkit::TextSelectionToolbar::AddDivider()
71    */
72   void AddDivider(Actor& divider);
73
74   /**
75    * @copydoc Toolkit::TextSelectionToolbar::ResizeDividers()
76    */
77   void ResizeDividers(Size& size);
78
79   /**
80    * @copydoc Toolkit::TextSelectionToolbar::RaiseAbove()
81    */
82   void RaiseAbove(Actor target);
83
84   /**
85    * Sets the scroll bar padding.
86    *
87    * @param[in] padding The padding value.
88    */
89   void SetScrollBarPadding(const Vector2& padding);
90
91   /**
92    * @return The padding value.
93    */
94   const Vector2& GetScrollBarPadding() const;
95
96   /**
97    * @copydoc Toolkit::TextSelectionToolbar::ScrollTo()
98    */
99   void ScrollTo(const Vector2& position);
100
101 private: // From Control
102   /**
103    * @copydoc Control::OnInitialize()
104    */
105   void OnInitialize() override;
106
107   /**
108   * @copydoc Control::OnRelayout()
109   */
110   void OnRelayout(const Vector2& size, RelayoutContainer& container) override;
111
112   /**
113    * @brief Set max size of Popup
114    * @param[in] maxSize Size (Vector2)
115    */
116   void SetPopupMaxSize(const Size& maxSize);
117
118   /**
119    * @brief Get Max size of Popup
120    * @return Vector2 the max size of the Popup
121    */
122   const Dali::Vector2& GetPopupMaxSize() const;
123
124 private: // Implementation
125   /**
126    * @copydoc Toolkit::TextSelectionToolbar::ConfigureScrollview()
127    */
128   void ConfigureScrollview(const Property::Map& properties);
129
130   /**
131    * @brief Set up scrollview to scroll Toolbar horizontally
132    */
133   void SetUpScrollView();
134
135   /**
136    * @brief Set up the parts that make the Toolbar
137    */
138   void SetUp();
139
140   /**
141    * @brief Enable or disable the scroll-bar
142    *
143    * @param[in] enable True if the scroll-bar is required
144    */
145   void SetUpScrollBar(bool enable);
146
147   /**
148    * Toolbar has started to scroll
149    * @param[in] position current scroll view position
150    */
151   void OnScrollStarted(const Vector2& position);
152
153   /**
154    * Toolbar has stopped scrolling
155    * @param[in] position current scroll view position
156    */
157   void OnScrollCompleted(const Vector2& position);
158
159   /**
160    * Construct a new TextField.
161    */
162   TextSelectionToolbar();
163
164   /**
165    * A reference counted object may only be deleted by calling Unreference()
166    */
167   virtual ~TextSelectionToolbar();
168
169 private:
170   // Undefined copy constructor and assignment operators
171   TextSelectionToolbar(const TextSelectionToolbar&);
172   TextSelectionToolbar& operator=(const TextSelectionToolbar& rhs);
173
174 private:                                        // Data
175   Actor                      mToolbarActor;     ///< The actor used to house the toolbar.
176   Toolkit::TableView         mTableOfButtons;   ///< Actor which holds all the buttons, sensitivity can be set on buttons via this actor
177   Toolkit::ScrollView        mScrollView;       ///< Provides scrolling of Toolbar when content does not fit.
178   Toolkit::ScrollBar         mScrollBar;        ///< An horizontal scroll bar for the text's popup options.
179   RulerPtr                   mRulerX;           ///< Ruler to clamp horizontal scrolling. Updates on Relayout
180   Size                       mMaxSize;          ///< Max size of the Toolbar
181   Vector2                    mScrollBarPadding; ///< The padding used to position the scroll indicator.
182   unsigned int               mIndexInTable;     ///< Index in table to add option
183   Dali::Vector<unsigned int> mDividerIndexes;   ///< Vector of indexes in the Toolbar that contain dividers.
184   bool                       mFirstScrollEnd;   ///< Used for RTL mirroring. Avoids the overshoot to be shown the first time the popup is shown.
185 };
186
187 } // namespace Internal
188
189 // Helpers for public-api forwarding methods
190
191 inline Toolkit::Internal::TextSelectionToolbar& GetImpl(Toolkit::TextSelectionToolbar& textSelectionToolbar)
192 {
193   DALI_ASSERT_ALWAYS(textSelectionToolbar);
194
195   Dali::RefObject& handle = textSelectionToolbar.GetImplementation();
196
197   return static_cast<Toolkit::Internal::TextSelectionToolbar&>(handle);
198 }
199
200 inline const Toolkit::Internal::TextSelectionToolbar& GetImpl(const Toolkit::TextSelectionToolbar& textSelectionToolbar)
201 {
202   DALI_ASSERT_ALWAYS(textSelectionToolbar);
203
204   const Dali::RefObject& handle = textSelectionToolbar.GetImplementation();
205
206   return static_cast<const Toolkit::Internal::TextSelectionToolbar&>(handle);
207 }
208
209 } // namespace Toolkit
210
211 } // namespace Dali
212
213 #endif // DALI_TOOLKIT_INTERNAL_TEXT_SELECTION_TOOLBAR_H