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