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