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