TextSelectionPopup follows Handles and button change with state and other improvements
[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    * @return A handle to the TextSelectionPopup control.
103    */
104   static Toolkit::TextSelectionPopup New( Toolkit::TextSelectionPopup::Buttons buttonsToEnable );
105
106   // Properties
107
108   /**
109    * @brief Called when a property of an object of this type is set.
110    * @param[in] object The object whose property is set.
111    * @param[in] index The property index.
112    * @param[in] value The new property value.
113    */
114   static void SetProperty( BaseObject* object, Property::Index index, const Property::Value& value );
115
116   /**
117    * @brief Called to retrieve a property of an object of this type.
118    *
119    * @param[in] object The object whose property is to be retrieved.
120    * @param[in] index The property index.
121    * @return The current value of the property.
122    */
123   static Property::Value GetProperty( BaseObject* object, Property::Index index );
124
125 private: // From Control
126
127   /**
128    * @copydoc Control::OnInitialize()
129    */
130   virtual void OnInitialize();
131
132 private: // Implementation
133
134   /**
135    * @brief When a popup button is pressed
136    * @param[in] button the button pressed
137    * @return bool
138    */
139   bool OnButtonPressed( Toolkit::Button button );
140
141   /**
142    * @brief Method to set the dimension or dimension constraint on certain aspects of the Popup.
143    *
144    * @param[in] settingToCustomise The setting for the PopupCustomisations enum that can be customised
145    * @param[in] dimension The size to customise with
146    */
147   void SetDimensionToCustomise( const PopupCustomisations& settingToCustomise, const Size& dimension );
148
149   /**
150    * @brief Method to get the dimension or dimension constraint on certain aspects of the Popup that was previously customised
151    *
152    * @param[in] setting The setting from the PopupCustomisations enum
153    */
154   Size GetDimensionToCustomise( const PopupCustomisations& setting );
155
156   /**
157    * @brief Sets the image for the given button of the Popup.
158    *
159    * @param[in] button  The button the image should be used for from the Buttons Enum.
160    * @param[in] image The image to use.
161    */
162  void SetButtonImage( Toolkit::TextSelectionPopup::Buttons button, Dali::Image image );
163
164   /**
165    * @brief Retrieves the image of the given button used by the popup
166    *
167    * @param[in] button The button to get the image from
168    * @return The image used for that button.
169    */
170   Dali::Image GetButtonImage( Toolkit::TextSelectionPopup::Buttons button );
171
172   void CreateOrderedListOfPopupOptions();
173
174   void AddOption( const std::string& name, const std::string& caption, const Image iconImage, bool showDivider, bool showIcons, bool showCaption );
175
176   std::size_t GetNumberOfEnabledOptions();
177
178   void AddPopupOptionsToToolbar(  bool showIcons, bool showCaptions );
179
180   void CreatePopup();
181
182   /**
183    * Construct a new TextField.
184    */
185   TextSelectionPopup();
186
187   /**
188    * A reference counted object may only be deleted by calling Unreference()
189    */
190   virtual ~TextSelectionPopup();
191
192 private:
193
194   // Undefined copy constructor and assignment operators
195   TextSelectionPopup(const TextSelectionPopup&);
196   TextSelectionPopup& operator=(const TextSelectionPopup& rhs);
197
198 private: // Data
199
200
201   Dali::Toolkit::TextSelectionToolbar mToolbar;
202
203   Dali::Toolkit::TableView mTableOfButtons;           // Actor which holds all the buttons, sensitivity can be set on buttons via this actor
204
205   // Images to be used by the Popup buttons
206   Image mCutIconImage;
207   Image mCopyIconImage;
208   Image mPasteIconImage;
209   Image mClipboardIconImage;
210   Image mSelectIconImage;
211   Image mSelectAllIconImage;
212
213   Size mMaxSize;                       // Maximum size of the Popup
214   Size mMinSize;                       // Minimum size of the Popup
215
216   Size mOptionMaxSize;                 // Maximum size of an Option button
217   Size mOptionMinSize;                 // Minimum size of an Option button
218   Size mOptionDividerSize;             // Size of divider line
219
220   std::vector<ButtonRequirement> mOrderListOfButtons; // List of buttons in the order to be displayed and a flag to indicate if needed.
221
222   Toolkit::TextSelectionPopup::Buttons mEnabledButtons; // stores enabled buttons
223
224   Vector4 mLineColor;                   // Color of the line around the text input popup
225   Vector4 mIconColor;                   // Color of the popup icon.
226   Vector4 mPressedColor;                // Color of the popup option when pressed.
227
228   // Priority of Options/Buttons in the Cut and Paste pop-up, higher priority buttons are displayed first, left to right.
229   std::size_t mSelectOptionPriority;    // Position of Select Button
230   std::size_t mSelectAllOptionPriority; // Position of Select All button
231   std::size_t mCutOptionPriority;       // Position of Cut button
232   std::size_t mCopyOptionPriority;      // Position of Copy button
233   std::size_t mPasteOptionPriority;     // Position of Paste button
234   std::size_t mClipboardOptionPriority; // Position of Clipboard button
235
236   bool mShowIcons:1; // Flag to show icons
237   bool mShowCaptions:1; // Flag to show text captions
238
239 };
240
241 } // namespace Internal
242
243 // Helpers for public-api forwarding methods
244
245 inline Toolkit::Internal::TextSelectionPopup& GetImpl( Toolkit::TextSelectionPopup& textSelectionPopup )
246 {
247   DALI_ASSERT_ALWAYS( textSelectionPopup );
248
249   Dali::RefObject& handle = textSelectionPopup.GetImplementation();
250
251   return static_cast<Toolkit::Internal::TextSelectionPopup&>(handle);
252 }
253
254 inline const Toolkit::Internal::TextSelectionPopup& GetImpl( const Toolkit::TextSelectionPopup& textSelectionPopup )
255 {
256   DALI_ASSERT_ALWAYS( textSelectionPopup );
257
258   const Dali::RefObject& handle = textSelectionPopup.GetImplementation();
259
260   return static_cast<const Toolkit::Internal::TextSelectionPopup&>(handle);
261 }
262
263 } // namespace Toolkit
264
265 } // namespace Dali
266
267 #endif // __DALI_TOOLKIT_INTERNAL_TEXT_SELECTION_POPUP_H__
268