ResizePolicy for TextField
[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/text-controls/text-selection-popup.h>
24
25 // EXTERNAL INCLUDES
26 #include <dali/public-api/actors/image-actor.h>
27 #include <dali/public-api/actors/layer.h>
28
29 namespace Dali
30 {
31
32 namespace Toolkit
33 {
34
35 namespace Internal
36 {
37
38 namespace
39 {
40 enum PopupParts
41 {
42   POPUP_BACKGROUND,
43   POPUP_CLIPBOARD_BUTTON,
44   POPUP_CUT_BUTTON_ICON,
45   POPUP_COPY_BUTTON_ICON,
46   POPUP_PASTE_BUTTON_ICON,
47   POPUP_SELECT_BUTTON_ICON,
48   POPUP_SELECT_ALL_BUTTON_ICON,
49 };
50
51 } // namespace
52
53 class TextSelectionPopup : public Control
54 {
55 public:
56
57   enum Buttons
58   {
59     ButtonsCut,
60     ButtonsCopy,
61     ButtonsPaste,
62     ButtonsSelect,
63     ButtonsSelectAll,
64     ButtonsClipboard,
65     ButtonsEnumEnd
66   };
67
68   struct ButtonRequirement
69   {
70     ButtonRequirement()
71     : id( ButtonsEnumEnd ),
72       priority( 0u ),
73       name(),
74       caption(),
75       icon(),
76       enabled( false )
77     {}
78
79     ButtonRequirement( Buttons buttonId,
80                        std::size_t buttonPriority,
81                        const std::string& buttonName,
82                        const std::string& buttonCaption,
83                        Dali::Image& buttonIcon,
84                        bool buttonEnabled )
85     : id( buttonId ),
86       priority( buttonPriority ),
87       name( buttonName ),
88       caption( buttonCaption ),
89       icon( buttonIcon ),
90       enabled( buttonEnabled )
91     {}
92
93     Buttons id;
94     std::size_t priority;
95     std::string name;
96     std::string caption;
97     Dali::Image icon;
98     bool enabled;
99   };
100
101   struct ButtonPriorityCompare
102   {
103       bool operator()( const ButtonRequirement& lhs, const ButtonRequirement& rhs ) const {
104         return lhs.priority < rhs.priority;
105       }
106   };
107
108 //  static inline bool ButtonPriorityCompare( ButtonRequirement a, ButtonRequirement b )
109 //  {
110 //    return a.priority < b.priority ? true : false;
111 //  }
112
113   /**
114    * @copydoc Dali::Toollkit::TextSelectionPopup::New()
115    */
116   static Toolkit::TextSelectionPopup New();
117
118   // Properties
119
120   /**
121    * @brief Called when a property of an object of this type is set.
122    *
123    * @param[in] object The object whose property is set.
124    * @param[in] index The property index.
125    * @param[in] value The new property value.
126    */
127   static void SetProperty( BaseObject* object, Property::Index index, const Property::Value& value );
128
129   /**
130    * @brief Called to retrieve a property of an object of this type.
131    *
132    * @param[in] object The object whose property is to be retrieved.
133    * @param[in] index The property index.
134    * @return The current value of the property.
135    */
136   static Property::Value GetProperty( BaseObject* object, Property::Index index );
137
138   void CreatePopup();
139
140   void DestroyPopup();
141
142 private: // From Control
143
144   /**
145    * @copydoc Control::OnInitialize()
146    */
147  virtual void OnInitialize();
148
149 //  /**
150 //   * @copydoc Control::GetNaturalSize()
151 //   */
152 //  virtual Vector3 GetNaturalSize();
153 //
154 //  /**
155 //   * @copydoc Control::GetHeightForWidth()
156 //   */
157 //  virtual float GetHeightForWidth( float width );
158
159   /**
160    * @copydoc Control::OnInitialize()
161    */
162   virtual void OnRelayout( const Vector2& size, RelayoutContainer& container );
163 //
164 //  /**
165 //   * Received for single & double taps
166 //   */
167 //  virtual void OnTap( const TapGesture& tap );
168 //
169 //  /**
170 //   * @copydoc Text::ControlInterface::RequestTextRelayout()
171 //   */
172 //  virtual void RequestTextRelayout();
173
174   /**
175    * Set max size of Popup
176    * @param[in] maxSize Size (Vector2)
177    */
178   void SetPopupMaxSize( const Size& maxSize );
179
180   /**
181    * Get Max size of Popup
182    * @return Vector2 the max size of the Popup
183    */
184   const Dali::Vector2& GetPopupMaxSize() const;
185
186   /**
187    * @brief Sets the image for the given part of the Popup.
188    *
189    * @param[in] part  The part of the pop from the Enum PopupParts
190    * @param[in] image The image to use.
191    */
192  void SetPopupImage( PopupParts part, Dali::Image image );
193
194   /**
195    * @brief Retrieves the image of the given part used by the popup
196    *
197    * @param[in] part The part of the popup
198    * @return The image used for that part.
199    */
200   Dali::Image GetPopupImage( PopupParts part );
201
202   void CreateOrderedListOfPopupOptions();
203
204   void CreateBackground();
205
206   void AddOption( Actor& parent, const std::string& name, const std::string& caption, const Image iconImage, bool finalOption, bool showIcons );
207
208   void SetUpPopup( Size& size );
209
210   void AddPopupOptions( bool createTail, bool showIcons );
211
212 private: // Implementation
213
214   /**
215    * Construct a new TextField.
216    */
217   TextSelectionPopup();
218
219   /**
220    * A reference counted object may only be deleted by calling Unreference()
221    */
222   virtual ~TextSelectionPopup();
223
224 private:
225
226   // Undefined copy constructor and assignment operators
227   TextSelectionPopup(const TextSelectionPopup&);
228   TextSelectionPopup& operator=(const TextSelectionPopup& rhs);
229
230 private: // Data
231
232   Actor mButtons;                                     // Actor which holds all the buttons, sensitivity can be set oActor buttons via this actor
233   Layer mStencilLayer;                                // Layer to enable clipping when buttons exceed popup
234
235   // Images to be used by the Popup
236   Image mBackgroundImage;
237   Image mCutIconImage;
238   Image mCopyIconImage;
239   Image mPasteIconImage;
240   Image mClipboardIconImage;
241   Image mSelectIconImage;
242   Image mSelectAllIconImage;
243
244   ImageActor mBackground;                             // The background popup panel
245   ImageActor mTail;                                   // The tail for the popup
246   ImageActor mTailEffect;   //todo remove                          // the tail effect
247   ImageActor mTailLine;     //todo remove                          // The border/outline around the tail
248
249   Size mMaxSize;                                      // Max size of the Popup
250   Size mVisiblePopUpSize;                             // Visible Size of popup excluding content that needs scrolling.
251   Size mRequiredPopUpSize;                            // Total size of popup including any invisible margin
252
253   Vector4 mNinePatchMargins;                          // Margins between the edge of the cropped image and the nine patch rect (left, right, top, bottom).
254
255   Size mContentSize;                                  // Size of Content (i.e. Buttons)
256   //Animation mAnimation;                               // Popup Hide/Show animation.
257
258   std::vector<ButtonRequirement> mOrderListOfButtons; // List of buttons in the order to be displayed and a flag to indicate if needed.
259
260   Vector4 mBackgroundColor;             // Color of the background of the text input popup
261   Vector4 mBackgroundPressedColor;      // Color of the option background.
262   Vector4 mLineColor;                   // Color of the line around the text input popup
263   Vector4 mIconColor;                   // Color of the popup icon.
264   Vector4 mIconPressedColor;            // Color of the popup icon when pressed.
265   Vector4 mTextColor;                   // Color of the popup text.
266   Vector4 mTextPressedColor;            // Color of the popup text when pressed.
267
268   // Priority of Options/Buttons in the Cut and Paste pop-up, higher priority buttons are displayed first, left to right.
269   std::size_t mSelectOptionPriority;    // Position of Select Button
270   std::size_t mSelectAllOptionPriority; // Position of Select All button
271   std::size_t mCutOptionPriority;       // Position of Cut button
272   std::size_t mCopyOptionPriority;      // Position of Copy button
273   std::size_t mPasteOptionPriority;     // Position of Paste button
274   std::size_t mClipboardOptionPriority; // Position of Clipboard button
275
276   bool mShowIcons; // Flag to show icons
277
278 };
279
280 } // namespace Internal
281
282 // Helpers for public-api forwarding methods
283
284 inline Toolkit::Internal::TextSelectionPopup& GetImpl( Toolkit::TextSelectionPopup& textSelectionPopup )
285 {
286   DALI_ASSERT_ALWAYS( textSelectionPopup );
287
288   Dali::RefObject& handle = textSelectionPopup.GetImplementation();
289
290   return static_cast<Toolkit::Internal::TextSelectionPopup&>(handle);
291 }
292
293 inline const Toolkit::Internal::TextSelectionPopup& GetImpl( const Toolkit::TextSelectionPopup& textSelectionPopup )
294 {
295   DALI_ASSERT_ALWAYS( textSelectionPopup );
296
297   const Dali::RefObject& handle = textSelectionPopup.GetImplementation();
298
299   return static_cast<const Toolkit::Internal::TextSelectionPopup&>(handle);
300 }
301
302 } // namespace Toolkit
303
304 } // namespace Dali
305
306 #endif // __DALI_TOOLKIT_INTERNAL_TEXT_SELECTION_POPUP_H__