Merge "TextSelectionToolbar and Style Properties added" 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/table-view/table-view.h>
24 #include <dali-toolkit/devel-api/controls/text-controls/text-selection-popup.h>
25 #include <dali-toolkit/devel-api/controls/text-controls/text-selection-toolbar.h>
26
27 // EXTERNAL INCLUDES
28 #include <dali/public-api/actors/image-actor.h>
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 namespace
41 {
42
43 enum PopupCustomisations
44 {
45   POPUP_MAXIMUM_SIZE,
46   POPUP_MINIMUM_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   enum Buttons
59   {
60     CUT,
61     COPY,
62     PASTE,
63     SELECT,
64     SELECT_ALL,
65     CLIPBOARD,
66     ENUM_END
67   };
68
69   struct ButtonRequirement
70   {
71     ButtonRequirement()
72     : id( ENUM_END ),
73       priority( 0u ),
74       name(),
75       caption(),
76       icon(),
77       enabled( false )
78     {}
79
80     ButtonRequirement( Buttons buttonId,
81                        std::size_t buttonPriority,
82                        const std::string& buttonName,
83                        const std::string& buttonCaption,
84                        Dali::Image& buttonIcon,
85                        bool buttonEnabled )
86     : id( buttonId ),
87       priority( buttonPriority ),
88       name( buttonName ),
89       caption( buttonCaption ),
90       icon( buttonIcon ),
91       enabled( buttonEnabled )
92     {}
93
94     Buttons id;
95     std::size_t priority;
96     std::string name;
97     std::string caption;
98     Dali::Image icon;
99     bool enabled;
100   };
101
102   struct ButtonPriorityCompare
103   {
104       bool operator()( const ButtonRequirement& lhs, const ButtonRequirement& rhs ) const {
105         return lhs.priority < rhs.priority;
106       }
107   };
108
109   /**
110    * @copydoc Dali::Toollkit::TextSelectionPopup::New()
111    */
112   static Toolkit::TextSelectionPopup New();
113
114   // Properties
115
116   /**
117    * @brief Called when a property of an object of this type is set.
118    * @param[in] object The object whose property is set.
119    * @param[in] index The property index.
120    * @param[in] value The new property value.
121    */
122   static void SetProperty( BaseObject* object, Property::Index index, const Property::Value& value );
123
124   /**
125    * @brief Called to retrieve a property of an object of this type.
126    *
127    * @param[in] object The object whose property is to be retrieved.
128    * @param[in] index The property index.
129    * @return The current value of the property.
130    */
131   static Property::Value GetProperty( BaseObject* object, Property::Index index );
132
133 private: // From Control
134
135   /**
136    * @copydoc Control::OnInitialize()
137    */
138   virtual void OnInitialize();
139
140 private: // Implementation
141
142   /**
143    * @brief Method to set the dimension or dimension constraint on certain aspects of the Popup.
144    *
145    * @param[in] settingToCustomise The setting for the PopupCustomisations enum that can be customised
146    * @param[in] dimension The size to customise with
147    */
148   void SetDimensionToCustomise( const PopupCustomisations& settingToCustomise, const Size& dimension );
149
150   /**
151    * @brief Method to get the dimension or dimension constraint on certain aspects of the Popup that was previously customised
152    *
153    * @param[in] setting The setting from the PopupCustomisations enum
154    */
155   Size GetDimensionToCustomise( const PopupCustomisations& setting );
156
157   /**
158    * @brief Sets the image for the given button of the Popup.
159    *
160    * @param[in] button  The button the image should be used for from the Buttons Enum.
161    * @param[in] image The image to use.
162    */
163  void SetButtonImage( Buttons button, Dali::Image image );
164
165   /**
166    * @brief Retrieves the image of the given button used by the popup
167    *
168    * @param[in] button The button to get the image from
169    * @return The image used for that button.
170    */
171   Dali::Image GetButtonImage( Buttons button );
172
173   void CreateOrderedListOfPopupOptions();
174
175   void AddOption( const std::string& name, const std::string& caption, const Image iconImage, bool showDivider, bool showIcons, bool showCaption );
176
177   std::size_t GetNumberOfEnabledOptions();
178
179   void AddPopupOptionsToToolbar(  bool showIcons, bool showCaptions );
180
181   void CreatePopup();
182
183   /**
184    * Construct a new TextField.
185    */
186   TextSelectionPopup();
187
188   /**
189    * A reference counted object may only be deleted by calling Unreference()
190    */
191   virtual ~TextSelectionPopup();
192
193 private:
194
195   // Undefined copy constructor and assignment operators
196   TextSelectionPopup(const TextSelectionPopup&);
197   TextSelectionPopup& operator=(const TextSelectionPopup& rhs);
198
199 private: // Data
200
201
202   Dali::Toolkit::TextSelectionToolbar mToolbar;
203
204   Dali::Toolkit::TableView mTableOfButtons;           // Actor which holds all the buttons, sensitivity can be set on buttons via this actor
205
206   // Images to be used by the Popup buttons
207   Image mCutIconImage;
208   Image mCopyIconImage;
209   Image mPasteIconImage;
210   Image mClipboardIconImage;
211   Image mSelectIconImage;
212   Image mSelectAllIconImage;
213
214   Size mMaxSize;                       // Maximum size of the Popup
215   Size mMinSize;                       // Minimum size of the Popup
216
217   Size mOptionMaxSize;                 // Maximum size of an Option button
218   Size mOptionMinSize;                 // Minimum size of an Option button
219   Size mOptionDividerSize;             // Size of divider line
220
221   std::vector<ButtonRequirement> mOrderListOfButtons; // List of buttons in the order to be displayed and a flag to indicate if needed.
222
223   Vector4 mLineColor;                   // Color of the line around the text input popup
224   Vector4 mIconColor;                   // Color of the popup icon.
225   Vector4 mIconPressedColor;            // Color of the popup icon when pressed.
226
227   // Priority of Options/Buttons in the Cut and Paste pop-up, higher priority buttons are displayed first, left to right.
228   std::size_t mSelectOptionPriority;    // Position of Select Button
229   std::size_t mSelectAllOptionPriority; // Position of Select All button
230   std::size_t mCutOptionPriority;       // Position of Cut button
231   std::size_t mCopyOptionPriority;      // Position of Copy button
232   std::size_t mPasteOptionPriority;     // Position of Paste button
233   std::size_t mClipboardOptionPriority; // Position of Clipboard button
234
235   bool mShowIcons; // Flag to show icons
236   bool mShowCaptions; // Flag to show text captions
237
238 };
239
240 } // namespace Internal
241
242 // Helpers for public-api forwarding methods
243
244 inline Toolkit::Internal::TextSelectionPopup& GetImpl( Toolkit::TextSelectionPopup& textSelectionPopup )
245 {
246   DALI_ASSERT_ALWAYS( textSelectionPopup );
247
248   Dali::RefObject& handle = textSelectionPopup.GetImplementation();
249
250   return static_cast<Toolkit::Internal::TextSelectionPopup&>(handle);
251 }
252
253 inline const Toolkit::Internal::TextSelectionPopup& GetImpl( const Toolkit::TextSelectionPopup& textSelectionPopup )
254 {
255   DALI_ASSERT_ALWAYS( textSelectionPopup );
256
257   const Dali::RefObject& handle = textSelectionPopup.GetImplementation();
258
259   return static_cast<const Toolkit::Internal::TextSelectionPopup&>(handle);
260 }
261
262 } // namespace Toolkit
263
264 } // namespace Dali
265
266 #endif // __DALI_TOOLKIT_INTERNAL_TEXT_SELECTION_POPUP_H__
267