[dali_1.0.46] 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 private: // From Control
128
129   /**
130    * @copydoc Control::OnInitialize()
131    */
132   virtual void OnInitialize();
133
134 private: // Implementation
135
136   /**
137    * @brief When the cut button is pressed.
138    * @param[in] button the button pressed
139    * @return @e true to consume the event.
140    */
141   bool OnCutButtonPressed( Toolkit::Button button );
142
143   /**
144    * @brief When the copy button is pressed.
145    * @param[in] button the button pressed
146    * @return @e true to consume the event.
147    */
148   bool OnCopyButtonPressed( Toolkit::Button button );
149
150   /**
151    * @brief When the paste button is pressed.
152    * @param[in] button the button pressed
153    * @return @e true to consume the event.
154    */
155   bool OnPasteButtonPressed( Toolkit::Button button );
156
157   /**
158    * @brief When the select button is pressed.
159    * @param[in] button the button pressed
160    * @return @e true to consume the event.
161    */
162   bool OnSelectButtonPressed( Toolkit::Button button );
163
164   /**
165    * @brief When the select all button is pressed.
166    * @param[in] button the button pressed
167    * @return @e true to consume the event.
168    */
169   bool OnSelectAllButtonPressed( Toolkit::Button button );
170
171   /**
172    * @brief When the clipboard button is pressed.
173    * @param[in] button the button pressed
174    * @return @e true to consume the event.
175    */
176   bool OnClipboardButtonPressed( Toolkit::Button button );
177
178   /**
179    * @brief Method to set the dimension or dimension constraint on certain aspects of the Popup.
180    *
181    * @param[in] settingToCustomise The setting for the PopupCustomisations enum that can be customised
182    * @param[in] dimension The size to customise with
183    */
184   void SetDimensionToCustomise( const PopupCustomisations& settingToCustomise, const Size& dimension );
185
186   /**
187    * @brief Method to get the dimension or dimension constraint on certain aspects of the Popup that was previously customised
188    *
189    * @param[in] setting The setting from the PopupCustomisations enum
190    */
191   Size GetDimensionToCustomise( const PopupCustomisations& setting );
192
193   /**
194    * @brief Sets the image for the given button of the Popup.
195    *
196    * @param[in] button  The button the image should be used for from the Buttons Enum.
197    * @param[in] image The image to use.
198    */
199  void SetButtonImage( Toolkit::TextSelectionPopup::Buttons button, Dali::Image image );
200
201   /**
202    * @brief Retrieves the image of the given button used by the popup
203    *
204    * @param[in] button The button to get the image from
205    * @return The image used for that button.
206    */
207   Dali::Image GetButtonImage( Toolkit::TextSelectionPopup::Buttons button );
208
209   void CreateOrderedListOfPopupOptions();
210
211   void AddOption( const ButtonRequirement& button, bool showDivider, bool showIcons, bool showCaption );
212
213   std::size_t GetNumberOfEnabledOptions();
214
215   void AddPopupOptionsToToolbar(  bool showIcons, bool showCaptions );
216
217   void CreatePopup();
218
219   /**
220    * Construct a new TextField.
221    */
222   TextSelectionPopup( TextSelectionPopupCallbackInterface* callbackInterface );
223
224   /**
225    * A reference counted object may only be deleted by calling Unreference()
226    */
227   virtual ~TextSelectionPopup();
228
229 private:
230
231   // Undefined copy constructor and assignment operators
232   TextSelectionPopup(const TextSelectionPopup&);
233   TextSelectionPopup& operator=(const TextSelectionPopup& rhs);
234
235 private: // Data
236
237
238   Dali::Toolkit::TextSelectionToolbar mToolbar;
239
240   Dali::Toolkit::TableView mTableOfButtons;           // Actor which holds all the buttons, sensitivity can be set on buttons via this actor
241
242   // Images to be used by the Popup buttons
243   Image mCutIconImage;
244   Image mCopyIconImage;
245   Image mPasteIconImage;
246   Image mClipboardIconImage;
247   Image mSelectIconImage;
248   Image mSelectAllIconImage;
249
250   Size mMaxSize;                       // Maximum size of the Popup
251   Size mMinSize;                       // Minimum size of the Popup
252
253   Size mOptionMaxSize;                 // Maximum size of an Option button
254   Size mOptionMinSize;                 // Minimum size of an Option button
255   Size mOptionDividerSize;             // Size of divider line
256
257   std::vector<ButtonRequirement> mOrderListOfButtons; // List of buttons in the order to be displayed and a flag to indicate if needed.
258
259   Toolkit::TextSelectionPopup::Buttons mEnabledButtons; // stores enabled buttons
260   Toolkit::TextSelectionPopupCallbackInterface* mCallbackInterface;
261
262   Vector4 mLineColor;                   // Color of the line around the text input popup
263   Vector4 mIconColor;                   // Color of the popup icon.
264   Vector4 mPressedColor;                // Color of the popup option when pressed.
265
266   // Priority of Options/Buttons in the Cut and Paste pop-up, higher priority buttons are displayed first, left to right.
267   std::size_t mSelectOptionPriority;    // Position of Select Button
268   std::size_t mSelectAllOptionPriority; // Position of Select All button
269   std::size_t mCutOptionPriority;       // Position of Cut button
270   std::size_t mCopyOptionPriority;      // Position of Copy button
271   std::size_t mPasteOptionPriority;     // Position of Paste button
272   std::size_t mClipboardOptionPriority; // Position of Clipboard button
273
274   bool mShowIcons:1; // Flag to show icons
275   bool mShowCaptions:1; // Flag to show text captions
276
277 };
278
279 } // namespace Internal
280
281 // Helpers for public-api forwarding methods
282
283 inline Toolkit::Internal::TextSelectionPopup& GetImpl( Toolkit::TextSelectionPopup& textSelectionPopup )
284 {
285   DALI_ASSERT_ALWAYS( textSelectionPopup );
286
287   Dali::RefObject& handle = textSelectionPopup.GetImplementation();
288
289   return static_cast<Toolkit::Internal::TextSelectionPopup&>(handle);
290 }
291
292 inline const Toolkit::Internal::TextSelectionPopup& GetImpl( const Toolkit::TextSelectionPopup& textSelectionPopup )
293 {
294   DALI_ASSERT_ALWAYS( textSelectionPopup );
295
296   const Dali::RefObject& handle = textSelectionPopup.GetImplementation();
297
298   return static_cast<const Toolkit::Internal::TextSelectionPopup&>(handle);
299 }
300
301 } // namespace Toolkit
302
303 } // namespace Dali
304
305 #endif // __DALI_TOOLKIT_INTERNAL_TEXT_SELECTION_POPUP_H__
306