Merge "When matchSystemLanguageDirection is set, it should follow the direction setti...
[platform/core/uifw/dali-toolkit.git] / dali-toolkit / internal / controls / text-controls / text-selection-popup-impl.h
1 #ifndef DALI_TOOLKIT_INTERNAL_TEXT_SELECTION_POPUP_H
2 #define DALI_TOOLKIT_INTERNAL_TEXT_SELECTION_POPUP_H
3
4 /*
5  * Copyright (c) 2020 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 <string>
23 #include <dali/public-api/actors/layer.h>
24 #include <dali/public-api/object/property-map.h>
25
26 // INTERNAL INCLUDES
27 #include <dali-toolkit/public-api/controls/control-impl.h>
28 #include <dali-toolkit/public-api/controls/buttons/push-button.h>
29 #include <dali-toolkit/public-api/controls/image-view/image-view.h>
30 #include <dali-toolkit/devel-api/controls/table-view/table-view.h>
31 #include <dali-toolkit/devel-api/controls/text-controls/text-selection-popup.h>
32 #include <dali-toolkit/devel-api/controls/text-controls/text-selection-toolbar.h>
33
34 namespace Dali
35 {
36
37 namespace Toolkit
38 {
39
40 namespace Internal
41 {
42
43 enum PopupCustomisations
44 {
45   POPUP_MAXIMUM_SIZE,
46   OPTION_MAXIMUM_SIZE,
47   OPTION_MINIMUM_SIZE,
48   OPTION_DIVIDER_SIZE
49 };
50
51 class TextSelectionPopup : public Control
52 {
53 public:
54
55   struct ButtonRequirement
56   {
57     ButtonRequirement()
58     : id( Toolkit::TextSelectionPopup::NONE ),
59       priority( 0u ),
60       name(),
61       caption(),
62       enabled( false )
63     {}
64
65     ButtonRequirement( Toolkit::TextSelectionPopup::Buttons buttonId,
66                        std::size_t buttonPriority,
67                        const std::string& buttonName,
68                        const std::string& buttonCaption,
69                        bool buttonEnabled )
70     : id( buttonId ),
71       priority( buttonPriority ),
72       name( buttonName ),
73       caption( buttonCaption ),
74       enabled( buttonEnabled )
75     {}
76
77     Toolkit::TextSelectionPopup::Buttons id;
78     std::size_t priority;
79     std::string name;
80     std::string caption;
81     bool enabled;
82   };
83
84   struct ButtonPriorityCompare
85   {
86       bool operator()( const ButtonRequirement& lhs, const ButtonRequirement& rhs ) const {
87         return lhs.priority < rhs.priority;
88       }
89   };
90
91   /**
92    * @brief New constructor with provided buttons to enable.
93    * @param[in] callbackInterface The text popup callback interface which receives the button click callbacks.
94    * @return A handle to the TextSelectionPopup control.
95    */
96   static Toolkit::TextSelectionPopup New( TextSelectionPopupCallbackInterface* callbackInterface );
97
98   // Properties
99
100   /**
101    * @brief Called when a property of an object of this type is set.
102    * @param[in] object The object whose property is set.
103    * @param[in] index The property index.
104    * @param[in] value The new property value.
105    */
106   static void SetProperty( BaseObject* object, Property::Index index, const Property::Value& value );
107
108   /**
109    * @brief Called to retrieve a property of an object of this type.
110    *
111    * @param[in] object The object whose property is to be retrieved.
112    * @param[in] index The property index.
113    * @return The current value of the property.
114    */
115   static Property::Value GetProperty( BaseObject* object, Property::Index index );
116
117   /**
118    * @copydoc Toolkit::EnableButtons
119    */
120   void EnableButtons( Toolkit::TextSelectionPopup::Buttons buttonsToEnable );
121
122   /**
123    * @copydoc Toolkit::TextSelectionPopup::RaiseAbove()
124    */
125   void RaiseAbove( Layer target );
126
127   /**
128    * @copydoc Toolkit::TextSelectionPopup::ShowPopup()
129    */
130   void ShowPopup();
131
132   /**
133    * @copydoc Toolkiut::TextSelectionPopup::HidePopup()
134    */
135   void HidePopup();
136
137 private: // From Control
138
139   /**
140    * @copydoc Control::OnInitialize()
141    */
142   virtual void OnInitialize();
143
144 private: // Implementation
145
146   void HideAnimationFinished( Animation& animation );
147
148   /**
149    * @brief When the cut button is pressed.
150    * @param[in] button the button pressed
151    * @return @e true to consume the event.
152    */
153   bool OnCutButtonPressed( Toolkit::Button button );
154
155   /**
156    * @brief When the copy button is pressed.
157    * @param[in] button the button pressed
158    * @return @e true to consume the event.
159    */
160   bool OnCopyButtonPressed( Toolkit::Button button );
161
162   /**
163    * @brief When the paste button is pressed.
164    * @param[in] button the button pressed
165    * @return @e true to consume the event.
166    */
167   bool OnPasteButtonPressed( Toolkit::Button button );
168
169   /**
170    * @brief When the select button is pressed.
171    * @param[in] button the button pressed
172    * @return @e true to consume the event.
173    */
174   bool OnSelectButtonPressed( Toolkit::Button button );
175
176   /**
177    * @brief When the select all button is pressed.
178    * @param[in] button the button pressed
179    * @return @e true to consume the event.
180    */
181   bool OnSelectAllButtonPressed( Toolkit::Button button );
182
183   /**
184    * @brief When the clipboard button is pressed.
185    * @param[in] button the button pressed
186    * @return @e true to consume the event.
187    */
188   bool OnClipboardButtonPressed( Toolkit::Button button );
189
190   /**
191    * @brief Method to set the dimension or dimension constraint on certain aspects of the Popup.
192    *
193    * @param[in] settingToCustomise The setting for the PopupCustomisations enum that can be customised
194    * @param[in] dimension The size to customise with
195    */
196   void SetDimensionToCustomise( const PopupCustomisations& settingToCustomise, const Size& dimension );
197
198   /**
199    * @brief Method to get the dimension or dimension constraint on certain aspects of the Popup that was previously customised
200    *
201    * @param[in] setting The setting from the PopupCustomisations enum
202    */
203   Size GetDimensionToCustomise( const PopupCustomisations& setting ) const;
204
205   /**
206    * @brief Sets the image for the given button of the Popup.
207    *
208    * @param[in] button  The button the image should be used for from the Buttons Enum.
209    * @param[in] image The image to use.
210    */
211  void SetButtonImage( Toolkit::TextSelectionPopup::Buttons button, const std::string& image );
212
213   /**
214    * @brief Retrieves the image of the given button used by the popup
215    *
216    * @param[in] button The button to get the image from
217    * @return The image used for that button.
218    */
219   const std::string& GetButtonImage( Toolkit::TextSelectionPopup::Buttons button ) const;
220
221   /**
222    * @brief Sets the image for the pressed state of a popup option.
223    *
224    * @param[in]  filename The image filename to use.
225    */
226   void SetPressedImage( const std::string& filename);
227
228   /**
229    * @brief Gets the image used for the pressed state of a popup option.
230    *
231    * @return     The image filename used.
232    */
233   std::string GetPressedImage() const;
234
235   void CreateOrderedListOfPopupOptions();
236
237   void AddOption( const ButtonRequirement& button, bool showDivider, bool showIcons, bool showCaption );
238
239   std::size_t GetNumberOfEnabledOptions() const;
240
241   void AddPopupOptionsToToolbar(  bool showIcons, bool showCaptions );
242
243   /**
244    * Creates the background-border image
245    *
246    * @param[in] propertyMap The properties describing the background-border
247    */
248   void CreateBackgroundBorder( Property::Map& propertyMap );
249
250   /**
251    * Construct a new TextField.
252    */
253   TextSelectionPopup( TextSelectionPopupCallbackInterface* callbackInterface );
254
255   /**
256    * A reference counted object may only be deleted by calling Unreference()
257    */
258   virtual ~TextSelectionPopup();
259
260 private:
261
262   // Undefined copy constructor and assignment operators
263   TextSelectionPopup(const TextSelectionPopup&);
264   TextSelectionPopup& operator=(const TextSelectionPopup& rhs);
265
266 private: // Data
267
268
269   Dali::Toolkit::TextSelectionToolbar mToolbar;
270
271   Dali::Toolkit::TableView mTableOfButtons;           // Actor which holds all the buttons, sensitivity can be set on buttons via this actor
272
273   // Images paths to be used by the Popup buttons
274   std::string mCutIconImage;
275   std::string mCopyIconImage;
276   std::string mPasteIconImage;
277   std::string mClipboardIconImage;
278   std::string mSelectIconImage;
279   std::string mSelectAllIconImage;
280
281   Size mPopupMaxSize;                   // Maximum size of the Popup
282   Size mOptionMaxSize;                  // Maximum size of an Option button
283   Size mOptionMinSize;                  // Minimum size of an Option button
284   Size mOptionDividerSize;              // Size of divider line
285
286   std::vector<ButtonRequirement> mOrderListOfButtons; // List of buttons in the order to be displayed and a flag to indicate if needed.
287
288   Toolkit::TextSelectionPopup::Buttons mEnabledButtons; // stores enabled buttons
289   Toolkit::TextSelectionPopupCallbackInterface* mCallbackInterface;
290
291   std::string mPressedImage;            // Image used for the popup option when pressed.
292   Vector4 mPressedColor;                // Color of the popup option when pressed.
293   Vector4 mDividerColor;                // Color of the divider between buttons
294   Vector4 mIconColor;                   // Color of the popup icon.
295
296   // Priority of Options/Buttons in the Cut and Paste pop-up, higher priority buttons are displayed first, left to right.
297   std::size_t mSelectOptionPriority;    // Position of Select Button
298   std::size_t mSelectAllOptionPriority; // Position of Select All button
299   std::size_t mCutOptionPriority;       // Position of Cut button
300   std::size_t mCopyOptionPriority;      // Position of Copy button
301   std::size_t mPasteOptionPriority;     // Position of Paste button
302   std::size_t mClipboardOptionPriority; // Position of Clipboard button
303   float mFadeInDuration;                // Duration of the animation to fade in the Popup
304   float mFadeOutDuration;               // Duration of the animation to fade out the Popup
305
306   bool mShowIcons:1; // Flag to show icons
307   bool mShowCaptions:1; // Flag to show text captions
308   bool mPopupShowing:1; // Flag to indicate Popup showing
309   bool mButtonsChanged:1; // Flag to indicate the Popup Buttons have changed
310
311 };
312
313 } // namespace Internal
314
315 // Helpers for public-api forwarding methods
316
317 inline Toolkit::Internal::TextSelectionPopup& GetImpl( Toolkit::TextSelectionPopup& textSelectionPopup )
318 {
319   DALI_ASSERT_ALWAYS( textSelectionPopup );
320
321   Dali::RefObject& handle = textSelectionPopup.GetImplementation();
322
323   return static_cast<Toolkit::Internal::TextSelectionPopup&>(handle);
324 }
325
326 inline const Toolkit::Internal::TextSelectionPopup& GetImpl( const Toolkit::TextSelectionPopup& textSelectionPopup )
327 {
328   DALI_ASSERT_ALWAYS( textSelectionPopup );
329
330   const Dali::RefObject& handle = textSelectionPopup.GetImplementation();
331
332   return static_cast<const Toolkit::Internal::TextSelectionPopup&>(handle);
333 }
334
335 } // namespace Toolkit
336
337 } // namespace Dali
338
339 #endif // DALI_TOOLKIT_INTERNAL_TEXT_SELECTION_POPUP_H
340