Merge "Changed ImageView to use a unit square mesh and instead to size the mesh in...
[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   /**
224    * @brief Sets the image for the pressed state of a popup option.
225    *
226    * @param[in]  filename The image filename to use.
227    */
228   void SetPressedImage( const std::string& filename);
229
230   /**
231    * @brief Gets the image used for the pressed state of a popup option.
232    *
233    * @return     The image filename used.
234    */
235   std::string GetPressedImage() const;
236
237   void CreateOrderedListOfPopupOptions();
238
239   void AddOption( const ButtonRequirement& button, bool showDivider, bool showIcons, bool showCaption );
240
241   std::size_t GetNumberOfEnabledOptions();
242
243   void AddPopupOptionsToToolbar(  bool showIcons, bool showCaptions );
244
245   void CreatePopup();
246
247   /**
248    * Construct a new TextField.
249    */
250   TextSelectionPopup( TextSelectionPopupCallbackInterface* callbackInterface );
251
252   /**
253    * A reference counted object may only be deleted by calling Unreference()
254    */
255   virtual ~TextSelectionPopup();
256
257 private:
258
259   // Undefined copy constructor and assignment operators
260   TextSelectionPopup(const TextSelectionPopup&);
261   TextSelectionPopup& operator=(const TextSelectionPopup& rhs);
262
263 private: // Data
264
265
266   Dali::Toolkit::TextSelectionToolbar mToolbar;
267
268   Dali::Toolkit::TableView mTableOfButtons;           // Actor which holds all the buttons, sensitivity can be set on buttons via this actor
269
270   // Images to be used by the Popup buttons
271   Image mCutIconImage;
272   Image mCopyIconImage;
273   Image mPasteIconImage;
274   Image mClipboardIconImage;
275   Image mSelectIconImage;
276   Image mSelectAllIconImage;
277
278   Size mOptionMaxSize;                  // Maximum size of an Option button
279   Size mOptionMinSize;                  // Minimum size of an Option button
280   Size mOptionDividerSize;              // Size of divider line
281
282   std::vector<ButtonRequirement> mOrderListOfButtons; // List of buttons in the order to be displayed and a flag to indicate if needed.
283
284   Toolkit::TextSelectionPopup::Buttons mEnabledButtons; // stores enabled buttons
285   Toolkit::TextSelectionPopupCallbackInterface* mCallbackInterface;
286
287   std::string mPressedImage;            // Image used for the popup option when pressed.
288   Vector4 mPressedColor;                // Color of the popup option when pressed.
289   Vector4 mDividerColor;                // Color of the divider between buttons
290   Vector4 mIconColor;                   // Color of the popup icon.
291
292   // Priority of Options/Buttons in the Cut and Paste pop-up, higher priority buttons are displayed first, left to right.
293   std::size_t mSelectOptionPriority;    // Position of Select Button
294   std::size_t mSelectAllOptionPriority; // Position of Select All button
295   std::size_t mCutOptionPriority;       // Position of Cut button
296   std::size_t mCopyOptionPriority;      // Position of Copy button
297   std::size_t mPasteOptionPriority;     // Position of Paste button
298   std::size_t mClipboardOptionPriority; // Position of Clipboard button
299
300   bool mShowIcons:1; // Flag to show icons
301   bool mShowCaptions:1; // Flag to show text captions
302
303 };
304
305 } // namespace Internal
306
307 // Helpers for public-api forwarding methods
308
309 inline Toolkit::Internal::TextSelectionPopup& GetImpl( Toolkit::TextSelectionPopup& textSelectionPopup )
310 {
311   DALI_ASSERT_ALWAYS( textSelectionPopup );
312
313   Dali::RefObject& handle = textSelectionPopup.GetImplementation();
314
315   return static_cast<Toolkit::Internal::TextSelectionPopup&>(handle);
316 }
317
318 inline const Toolkit::Internal::TextSelectionPopup& GetImpl( const Toolkit::TextSelectionPopup& textSelectionPopup )
319 {
320   DALI_ASSERT_ALWAYS( textSelectionPopup );
321
322   const Dali::RefObject& handle = textSelectionPopup.GetImplementation();
323
324   return static_cast<const Toolkit::Internal::TextSelectionPopup&>(handle);
325 }
326
327 } // namespace Toolkit
328
329 } // namespace Dali
330
331 #endif // __DALI_TOOLKIT_INTERNAL_TEXT_SELECTION_POPUP_H__
332