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