Remove MaskedImageView
[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/public-api/controls/text-controls/text-selection-popup.h>
25
26 // EXTERNAL INCLUDES
27 #include <dali/public-api/actors/image-actor.h>
28 #include <dali/public-api/actors/layer.h>
29
30 namespace Dali
31 {
32
33 namespace Toolkit
34 {
35
36 namespace Internal
37 {
38
39 namespace
40 {
41 enum PopupParts
42 {
43   POPUP_BACKGROUND,
44   POPUP_CLIPBOARD_BUTTON,
45   POPUP_CUT_BUTTON_ICON,
46   POPUP_COPY_BUTTON_ICON,
47   POPUP_PASTE_BUTTON_ICON,
48   POPUP_SELECT_BUTTON_ICON,
49   POPUP_SELECT_ALL_BUTTON_ICON,
50 };
51
52 } // namespace
53
54 class TextSelectionPopup : public Control
55 {
56 public:
57
58   enum Buttons
59   {
60     ButtonsCut,
61     ButtonsCopy,
62     ButtonsPaste,
63     ButtonsSelect,
64     ButtonsSelectAll,
65     ButtonsClipboard,
66     ButtonsEnumEnd
67   };
68
69   struct ButtonRequirement
70   {
71     ButtonRequirement()
72     : id( ButtonsEnumEnd ),
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 //  static inline bool ButtonPriorityCompare( ButtonRequirement a, ButtonRequirement b )
110 //  {
111 //    return a.priority < b.priority ? true : false;
112 //  }
113
114   /**
115    * @copydoc Dali::Toollkit::TextSelectionPopup::New()
116    */
117   static Toolkit::TextSelectionPopup New();
118
119   // Properties
120
121   /**
122    * @brief Called when a property of an object of this type is set.
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( Dali::Toolkit::TableView& parent, const std::string& name, const std::string& caption, const Image iconImage, bool finalOption, bool showIcons, bool showCaption, std::size_t& indexInTable  );
207
208   void SetUpPopup();
209
210   void AddPopupOptions( bool createTail, bool showIcons, bool showCaptions );
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   Dali::Toolkit::TableView mTableOfButtons;                          // Actor which holds all the buttons, sensitivity can be set on 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   bool mShowCaptions; // Flag to show text captions
278
279 };
280
281 } // namespace Internal
282
283 // Helpers for public-api forwarding methods
284
285 inline Toolkit::Internal::TextSelectionPopup& GetImpl( Toolkit::TextSelectionPopup& textSelectionPopup )
286 {
287   DALI_ASSERT_ALWAYS( textSelectionPopup );
288
289   Dali::RefObject& handle = textSelectionPopup.GetImplementation();
290
291   return static_cast<Toolkit::Internal::TextSelectionPopup&>(handle);
292 }
293
294 inline const Toolkit::Internal::TextSelectionPopup& GetImpl( const Toolkit::TextSelectionPopup& textSelectionPopup )
295 {
296   DALI_ASSERT_ALWAYS( textSelectionPopup );
297
298   const Dali::RefObject& handle = textSelectionPopup.GetImplementation();
299
300   return static_cast<const Toolkit::Internal::TextSelectionPopup&>(handle);
301 }
302
303 } // namespace Toolkit
304
305 } // namespace Dali
306
307 #endif // __DALI_TOOLKIT_INTERNAL_TEXT_SELECTION_POPUP_H__