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