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