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