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