DALi signals refactor to remove V2 naming
[platform/core/uifw/dali-toolkit.git] / base / dali-toolkit / internal / controls / text-input / text-input-popup-impl.h
1 #ifndef __DALI_TOOLKIT_INTERNAL_TEXT_INPUT_POPUP_H__
2 #define __DALI_TOOLKIT_INTERNAL_TEXT_INPUT_POPUP_H__
3
4 /*
5  * Copyright (c) 2014 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 // EXTERNAL INCLUDES
22 #include <dali/public-api/actors/image-actor.h>
23 #include <dali/public-api/actors/layer.h>
24 #include <dali/public-api/animation/animation.h>
25
26 // INTERNAL INCLUDES
27 #include <dali-toolkit/public-api/controls/text-view/text-view.h>
28 #include <dali-toolkit/public-api/controls/scrollable/scroll-view/scroll-view.h>
29
30 namespace Dali
31 {
32
33 namespace Toolkit
34 {
35
36 class Button;
37
38 namespace Internal
39 {
40
41 class TextInputPopup : public ConnectionTracker
42 {
43
44 public:
45
46   enum State
47   {
48     StateHidden,
49     StateHiding,
50     StateShowing,
51     StateShown
52   };
53
54   enum Buttons
55   {
56     ButtonsCut,
57     ButtonsCopy,
58     ButtonsPaste,
59     ButtonsSelect,
60     ButtonsSelectAll,
61     ButtonsClipboard,
62     ButtonsEnumEnd
63   };
64
65   struct ButtonRequirement
66   {
67     TextInputPopup::Buttons buttonId;
68     std::size_t orderOfPriority;
69     std::string name;
70     std::string caption;
71     Image iconImage;
72     bool enabled;
73   };
74
75   static const char* const OPTION_SELECT_WORD;
76   static const char* const OPTION_SELECT_ALL;
77   static const char* const OPTION_CUT;
78   static const char* const OPTION_COPY;
79   static const char* const OPTION_PASTE;
80   static const char* const OPTION_CLIPBOARD;
81
82   // Signal names
83   static const char* const SIGNAL_PRESSED;
84   static const char* const SIGNAL_HIDE_FINISHED;
85   static const char* const SIGNAL_SHOW_FINISHED;
86
87   // Popup Button Pressed
88   typedef Signal< bool( Toolkit::Button ) > PressedSignalType;
89
90   // Popup Hide Finished
91   typedef Signal< void( TextInputPopup& ) > HideFinishedSignalType;
92
93   // Popup Show Finished
94   typedef Signal< void( TextInputPopup& ) > ShowFinishedSignalType;
95
96   /**
97    * Signal emitted when the button is touched.
98    */
99   PressedSignalType& PressedSignal();
100
101   /**
102    * Signal emitted when popup is completely hidden
103    * @note Only occurs after a Show() call with animation enabled.
104    */
105   HideFinishedSignalType& HideFinishedSignal();
106
107   /**
108    * Signal emitted when popup is completely shown
109    * @note Only occurs after a Hide() call with animation enabled.
110    */
111   ShowFinishedSignalType& ShowFinishedSignal();
112
113 public:
114
115   /**
116    * Default constructor
117    * Creates an empty popup base actor (no content i.e. invisible)
118    */
119   TextInputPopup();
120
121   /**
122    * Clears popup options (popup no longer exists)
123    */
124   void Clear();
125
126   /**
127    * Create the label
128    * @return the newly created Image actor to be used as the icon
129    */
130   ImageActor CreateOptionIcon( Image iconImage, const Vector4& color );
131
132   /**
133    * Create the caption
134    * @param[in] styledCaption The text to be displayed
135    * @return the newly created label
136    */
137   Toolkit::TextView CreateOptionCaption( const std::string& caption, const Vector4& color );
138
139   /**
140    * Creates and sets up the background
141    */
142   void CreateBackground();
143
144   /**
145    * Create and set up the tail
146    */
147   void CreateTail();
148
149   /**
150    * Create divider if multiple options
151    * @return Return a divider image actor
152    */
153   ImageActor CreateDivider();
154
155   /**
156    * Create a background to be used when option pressed
157    * @param[in] requiredSize size Image actor should be
158    * @return Returns an Image Actor to be used a pressed background
159    */
160   ImageActor CreatePressedBackground( const Vector2& requiredSize );
161
162   /**
163    * Creates a ordered vector of button options
164    */
165   void CreateOrderedListOfOptions();
166
167   /**
168    * Get the TextSize after constrained by the Popup margins.
169    * @param[in] textSize Natural size of text
170    * @return Vector2 constrained text size.
171    *
172    */
173   Vector2 GetConstrainedTextSize( const Vector2& textSize );
174
175   /**
176    * Adds a popup option.
177    * @note Creates popup frame if not already created.
178    * @param[in] name The unique name for this option.
179    * @param[in] caption The caption (label) for this option
180    * @param[in] iconImage Image to displayed with text.
181    * @param[in] finalOption Flag to indicate that this is the final option.
182    * (set to true on the last option you add)
183    */
184   void AddOption(const std::string& name, const std::string& caption, const Image iconImage, bool finalOption);
185
186   /**
187    * Hides the popup
188    * @param[in] animate (optional) whether to animate popup to hide state over time (i.e. tween).
189    */
190   void Hide(bool animate = true);
191
192   /**
193    * Shows the popup
194    * @param[in] animate (optional) whether to animate popup to show state over time (i.e. tween).
195    * @param[in] target Actor to parent popup.
196    */
197   void Show( Actor target, bool animate = true );
198
199   /**
200    * Returns the current state of the popup.
201    * @return The state of the popup see enum State
202    */
203   State GetState(void) const;
204
205   /**
206    * Get the root actor which the buttons are added to.
207    * @return the root actor
208    */
209   Actor GetRootActor() const;
210
211   /**
212    * Set the Cut and Paste buttons color when in normal state
213    * @param[in] color color to use
214    */
215   void SetCutPastePopupColor( const Vector4& color );
216
217   /**
218    * Get the set color of the Copy and Paste Popup buttons
219    * @return color
220    */
221   const Vector4& GetCutPastePopupColor() const;
222
223   /**
224    * Set the Cut and Paste button color when pressed.
225    * @param[in] color color to use
226    */
227   void SetCutPastePopupPressedColor( const Vector4& color );
228
229   /**
230    * Get the Cut and Paste pressed button color.
231    * @return color
232    */
233   const Vector4& GetCutPastePopupPressedColor() const;
234
235   /**
236    * Set the border color of the popup
237    * @param[in] color required color
238    */
239   void SetCutPastePopupBorderColor( const Vector4& color );
240
241   /**
242    * Get the border color
243    * @return Vector4 the color of the border
244    */
245   const Vector4& GetCutPastePopupBorderColor() const;
246
247   /**
248    * Toggle if a popup button should be enabled (shown) or not
249    * @param[in]  requiredButton Button Id to enable or disable
250    * @param[in]  enable toggle to enable (true) or disable (false)
251    */
252   void TogglePopupButtonOnOff( TextInputPopup::Buttons requiredButton, bool enable );
253
254   /**
255    * Set the Button Priority Position
256    * @param[in] button Button id for priority to be set on
257    * @param[in] priority Priority level, 1 is highest so will appear first.  0 priority will not show the button.
258    */
259   void SetButtonPriorityPosition( TextInputPopup::Buttons button, unsigned int priority );
260
261   /**
262    * Set the icon color of the popup
263    * @param[in] color required color
264    */
265   void SetCutPastePopupIconColor( const Vector4& color );
266
267   /**
268    * Get the popup icon color
269    * @return Vector4 the color of the popup icon
270    */
271   const Vector4& GetCutPastePopupIconColor() const;
272
273   /**
274    * Set the pressed icon color of the popup
275    * @param[in] color required color
276    */
277   void SetCutPastePopupIconPressedColor( const Vector4& color );
278
279   /**
280    * Get the popup pressed icon color
281    * @return Vector4 the color of the popup pressed icon
282    */
283   const Vector4& GetCutPastePopupIconPressedColor();
284
285   /**
286    * Set the text color of the popup
287    * @param[in] color required color
288    */
289   void SetCutPastePopupTextColor( const Vector4& color );
290
291   /**
292    * Get the popup text color
293    * @return Vector4 the color of the popup text
294    */
295   const Vector4& GetCutPastePopupTextColor();
296
297   /**
298    * Set the pressed text color of the popup
299    * @param[in] color required color
300    */
301   void SetCutPastePopupTextPressedColor( const Vector4& color );
302
303   /**
304    * Get the popup pressed text color
305    * @return Vector4 the color of the popup pressed text
306    */
307   const Vector4& GetCutPastePopupTextPressedColor();
308
309   /**
310    * Get the Button Priority Position
311    * @param[in] button Button id to get priority of
312    * @return the button priority, 1 is highest, 0 is not shown.
313    */
314   unsigned int GetButtonPriorityPosition( TextInputPopup::Buttons button ) const;
315
316   /**
317    * Adds Popup options which have been enabled.
318    */
319   void AddPopupOptions();
320
321   /**
322    * Get Visible size of the Popup, excludes content that needs scrolling
323    * @return Vector3 size of Popup
324    */
325   const Vector3& GetVisibileSize() const;
326
327   /**
328    * Sets the positon of the PopUp tail relative to TextInput
329    * @param[in] position Position to set
330    * @param[in] yAxisFlip If tail should be flipped in y axis
331    */
332   void SetTailPosition( const Vector3& position, const bool yAxisFlip );
333
334 private:
335
336   /**
337    * Creates a Button with the required parameters.
338    * @param[in] buttonId enum representing the button
339    * @param[in] orderOfPriority Position in toolbar button should be position, 1 is first from left to right.
340    * @param[in] name Given name for Button actor
341    * @param[in] caption Text to display in button
342    * @param[in] iconImage Icon to display in button
343    * @param[in] enabled Toggle if button should be used or not, this is decided by the current state/conditions.
344    */
345   TextInputPopup::ButtonRequirement CreateRequiredButton( TextInputPopup::Buttons buttonId, std::size_t orderOfPriority,
346                                                                           const std::string& name, const std::string& caption, Image iconImage, bool enabled );
347
348   /**
349    * @brief Adds popup to the given parent
350    * @paran[in] parent target to add Popup to
351    */
352   void AddToParent( Actor parent );
353
354   /**
355    * @brief Removes Popup from Parent
356    */
357   void RemoveFromParent();
358
359   /**
360    * Applies constraint to keep Popup in view within the desired area.
361    */
362   void ApplyConfinementConstraint();
363
364   /**
365    * Applies constraint to keep the Tail attached to Popup
366    */
367   void ApplyTailConstraint();
368
369   /**
370    * Create Layer to be used with stencil to allow scrolling of buttons which do not fit in visible popup
371    * @param[in] size of the layer.
372    */
373   void CreateLayer( const Vector2& size );
374
375   /**
376    * Create a stencil to clip the scroll view content
377    * @param[in] size of the stencil.
378    */
379   void CreateStencil( const Vector2& size );
380
381   /**
382    * Popup has started to scroll
383    * @param[in] position current scroll view position
384    */
385   void OnScrollStarted( const Vector3& position );
386
387   /**
388    * Popup has stopped scrolling
389    * @param[in] position current scroll view position
390    */
391   void OnScrollCompleted( const Vector3& position );
392
393   /**
394    * Create a scroll view to hold the popup buttons and allow scrolling if too many buttons to fit within the visible boundary
395    */
396   void CreateScrollView();
397
398   /**
399    * Set the scroll view size and ruler.
400    * @param[in] visibleSize size of the visible scroll view
401    */
402   void UpdateScrollViewRulerAndSize( const Vector2& visibleSize );
403
404   /**
405    * Called when a button is pressed in the Popup
406    * @param[in] button The button pressed.
407    */
408   bool OnButtonPressed( Toolkit::Button button );
409
410   /**
411    * Invoked upon popup Hide animation completing.
412    * @note Only called for animating hide, not called for instantaneous (animate = false)
413    * @param[in] source The animation which completed.
414    */
415   void OnHideFinished(Animation& source);
416
417   /**
418    * Invoked upon popup Show animation completing.
419    * @note Only called for animating show, not called for instantaneous (animate = false)
420    * @param[in] source The animation which completed.
421    */
422   void OnShowFinished(Animation& source);
423
424 private:
425
426   State mState;                                       ///< Popup State.
427   Layer mRoot;                                        ///< The actor which all popup content is added to (i.e. panel and buttons)
428   Actor mButtons;                                     ///< Actor which holds all the buttons, sensitivity can be set on all buttons via this actor
429   ImageActor mBackground;                             ///< The background popup panel
430   ImageActor mBackgroundEffect;                       ///< The background effect
431   ImageActor mBackgroundLine;                         ///< The background line
432   ImageActor mTail;                                   ///< The tail for the popup
433   ImageActor mTailEffect;                             ///< the tail effect
434   ImageActor mTailLine;                               ///< The border/outline around the tail
435
436   Vector3 mVisiblePopUpSize;                          ///< Visible Size of Popup excluding content that needs scrolling.
437   float mPopupTailXPosition;                          ///< X position of PopUp tail.
438
439   Vector2 mContentSize;                               ///< Size of Content (i.e. Buttons)
440   ActorContainer mDividerContainer;                   ///< List of dividers added to popup.
441   Animation mAnimation;                               ///< Popup Hide/Show animation.
442
443   Layer mLayer;                                       ///< Layer to be used with Stencil
444   Actor mStencil;                                     ///< Stencil to clip scrollview
445   Toolkit::ScrollView mScrollView;                    ///< Scrollview to house the popup
446
447   std::vector<ButtonRequirement> mOrderListOfButtons;        // List of buttons in the order to be displayed and a flag to indicate if needed.
448
449   Vector4 mBackgroundColor;              // Color of the background of the text input popup
450   Vector4 mBackgroundPressedColor;       // Color of the option background.
451   Vector4 mLineColor;                    // Color of the line around the text input popup
452   Vector4 mIconColor;                    // Color of the popup icon.
453   Vector4 mIconPressedColor;             // Color of the popup icon when pressed.
454   Vector4 mTextColor;                    // Color of the popup text.
455   Vector4 mTextPressedColor;             // Color of the popup text when pressed.
456
457   // Priority of Options/Buttons in the Cut and Paste pop-up, higher priority buttons are displayed first, left to right.
458   std::size_t mSelectOptionPriority;  // Position of Select Button
459   std::size_t mSelectAllOptionPriority; // Position of Select All button
460   std::size_t mCutOptionPriority; // Position of Cut button
461   std::size_t mCopyOptionPriority; // Position of Copy button
462   std::size_t mPasteOptionPriority;  // Position of Paste button
463   std::size_t mClipboardOptionPriority;  // Position of Clipboard button
464
465   PressedSignalType mPressedSignal;              ///< Signal emitted when a button within the popup is pressed.
466   HideFinishedSignalType mHideFinishedSignal;    ///< Signal emitted when popup is completely hidden
467   ShowFinishedSignalType mShowFinishedSignal;    ///< Signal emitted when popup is completely shown
468
469 };
470
471 } // namespace Internal
472
473 } // namespace Toolkit
474
475 } // namespace Dali
476
477 #endif // __DALI_TOOLKIT_INTERNAL_ITEM_VIEW_H__