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