81186dfd81edea7f2a3512b7e497e1588110c291
[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
26 namespace Dali
27 {
28
29 namespace Toolkit
30 {
31
32 class Button;
33
34 namespace Internal
35 {
36
37 class TextInputPopup : public ConnectionTracker
38 {
39
40 public:
41
42   enum State
43   {
44     StateHidden,
45     StateHiding,
46     StateShowing,
47     StateShown
48   };
49
50   enum Buttons
51   {
52     ButtonsCut,
53     ButtonsCopy,
54     ButtonsPaste,
55     ButtonsSelect,
56     ButtonsSelectAll,
57     ButtonsClipboard,
58     ButtonsEnumEnd
59   };
60
61   struct ButtonRequirement
62   {
63     TextInputPopup::Buttons buttonId;
64     std::size_t orderOfPriority;
65     std::string name;
66     std::string caption;
67     Image iconImage;
68     bool enabled;
69   };
70
71   static const char* const OPTION_SELECT_WORD;
72   static const char* const OPTION_SELECT_ALL;
73   static const char* const OPTION_CUT;
74   static const char* const OPTION_COPY;
75   static const char* const OPTION_PASTE;
76   static const char* const OPTION_CLIPBOARD;
77
78   // Signal names
79   static const char* const SIGNAL_PRESSED;
80   static const char* const SIGNAL_HIDE_FINISHED;
81   static const char* const SIGNAL_SHOW_FINISHED;
82
83   // Popup Button Pressed
84   typedef SignalV2< bool( Toolkit::Button ) > PressedSignalV2;
85
86   // Popup Hide Finished
87   typedef SignalV2< void( TextInputPopup& ) > HideFinishedSignalV2;
88
89   // Popup Show Finished
90   typedef SignalV2< void( TextInputPopup& ) > ShowFinishedSignalV2;
91
92   /**
93    * Signal emitted when the button is touched.
94    */
95   PressedSignalV2& PressedSignal();
96
97   /**
98    * Signal emitted when popup is completely hidden
99    * @note Only occurs after a Show() call with animation enabled.
100    */
101   HideFinishedSignalV2& HideFinishedSignal();
102
103   /**
104    * Signal emitted when popup is completely shown
105    * @note Only occurs after a Hide() call with animation enabled.
106    */
107   ShowFinishedSignalV2& ShowFinishedSignal();
108
109 public:
110
111   /**
112    * Default constructor
113    * Creates an empty popup base actor (no content i.e. invisible)
114    */
115   TextInputPopup();
116
117   /**
118    * @return The root actor of for this popup is returned.
119    */
120   Actor Self();
121
122   /**
123    * Clears popup options (popup no longer exists)
124    */
125   void Clear();
126
127   /**
128    * Create the label
129    * @param[in] styledCaption The text to be displayed
130    * @return the newly created label
131    */
132   Toolkit::TextView CreateOptionText( const MarkupProcessor::StyledTextArray& styledCaption );
133
134   /**
135    * Create the label
136    * @param[in] iconImage the image to be used
137    * @return the newly created Image actor to be used as the icon
138    */
139   ImageActor CreateOptionIcon( Image iconImage );
140
141   /**
142    * Creates and sets up the popup background
143    */
144   void CreatePopUpBackground();
145
146   /**
147    * Create divider if multiple options
148    */
149   void CreateDivider();
150
151   /**
152    * Create a background to be used when button pressed
153    * @param[in] requiredSize size Image actor should be
154    * @return Returns an Image Actor to be used a pressed background
155    */
156   ImageActor CreatePressedBackground( const Vector3 requiredSize );
157
158   /**
159    * Creates a ordered vector of button options
160    */
161   void CreateOrderedListOfOptions();
162
163   /**
164    * Adds a popup option.
165    * @note Creates popup frame if not already created.
166    * @param[in] name The unique name for this option.
167    * @param[in] caption The caption (label) for this option
168    * @param[in] iconImage Image to displayed with text.
169    * @param[in] finalOption Flag to indicate that this is the final option.
170    * (set to true on the last option you add)
171    */
172   void AddOption(const std::string& name, const std::string& caption, const Image iconImage, bool finalOption);
173
174   /**
175    * Hides the popup
176    * @param[in] animate (optional) whether to animate popup to hide state over time (i.e. tween).
177    */
178   void Hide(bool animate = true);
179
180   /**
181    * Shows the popup
182    * @param[in] animate (optional) whether to animate popup to show state over time (i.e. tween).
183    */
184   void Show(bool animate = true);
185
186   /**
187    * Sets Alternative offset property.
188    * The alternative offset property is how much to move in the horizontal and vertical
189    * axes when the popup goes out of the screen on the left/right sides or top/bottom sides.
190    * @param[in] offset Vector holding the left/right offset (x) and top/bottom offset (y)
191    */
192   void SetAlternativeOffset(Vector2 offset);
193
194   /**
195    * Returns the current state of the popup.
196    * @return The state of the popup see enum State
197    */
198   State GetState(void) const;
199
200   /**
201    * Get the root actor which the buttons are added to.
202    * @return the root actor
203    */
204   Actor GetRootActor() const;
205
206   /**
207    * Set the Cut and Paste buttons color when in normal state
208    * @param[in] color color to use
209    */
210   void SetCutPastePopUpColor( const Vector4& color );
211
212   /**
213    * Get the set color of the Copy and Paste PopUp buttons
214    * @return color
215    */
216   const Vector4& GetCutPastePopUpColor() const;
217
218   /**
219    * Set the Cut and Paste button color when pressed.
220    * @param[in] color color to use
221    */
222   void SetCutPastePopUpPressedColor( const Vector4& color );
223
224   /**
225    * Get the Cut and Paste pressed button color.
226    * @return color
227    */
228   const Vector4& GetCutPastePopUpPressedColor() const;
229
230   /**
231    * Toggle if a popup button should be enabled (shown) or not
232    * @param[in]  requiredButton Button Id to enable or disable
233    * @param[in]  enable toggle to enable (true) or disable (false)
234    */
235   void TogglePopUpButtonOnOff( TextInputPopup::Buttons requiredButton, bool enable );
236
237   /**
238    * Set the Button Priority Position
239    * @param[in] button Button id for priority to be set on
240    * @param[in] priority Priority level, 1 is highest so will appear first.  0 priority will not show the button.
241    */
242   void SetButtonPriorityPosition( TextInputPopup::Buttons button, unsigned int priority );
243
244   /**
245    * Get the Button Priority Position
246    * @param[in] button Button id to get priority of
247    * @return the button priority, 1 is highest, 0 is not shown.
248    */
249   unsigned int GetButtonPriorityPosition( TextInputPopup::Buttons button ) const;
250
251   /**
252    * Adds Popup options which have been enabled.
253    */
254   void AddPopupOptions();
255
256 private:
257
258   /**
259    * Creates a Button with the required parameters.
260    * @param[in] buttonId enum representing the button
261    * @param[in] orderOfPriority Position in toolbar button should be position, 1 is first from left to right.
262    * @param[in] name Given name for Button actor
263    * @param[in] caption Text to display in button
264    * @param[in] iconImage Icon to display in button
265    * @param[in] enabled Toggle if button should be used or not, this is decided by the current state/conditions.
266    */
267   TextInputPopup::ButtonRequirement CreateRequiredButton( TextInputPopup::Buttons buttonId, std::size_t orderOfPriority,
268                                                                           const std::string& name, const std::string& caption, Image iconImage, bool enabled );
269
270   /**
271    * Adds Popup to the stage (ideally on a separate top-most layer and as an overlay)
272    */
273   void AddToStage();
274
275   /**
276    * Applies constraint to keep Popup in view within the desired area.
277    */
278   void ApplyConfinementConstraint();
279
280   /**
281    * Removes Popup from the stage.
282    */
283   void RemoveFromStage();
284
285   /**
286    * Called when a button is pressed in the Popup
287    * @param[in] button The button pressed.
288    */
289   bool OnButtonPressed( Toolkit::Button button );
290
291   /**
292    * Invoked upon popup Hide animation completing.
293    * @note Only called for animating hide, not called for instantaneous (animate = false)
294    * @param[in] source The animation which completed.
295    */
296   void OnHideFinished(Animation& source);
297
298   /**
299    * Invoked upon popup Show animation completing.
300    * @note Only called for animating show, not called for instantaneous (animate = false)
301    * @param[in] source The animation which completed.
302    */
303   void OnShowFinished(Animation& source);
304
305 private:
306
307   State mState;                                       ///< Popup State.
308   Actor mRootActor;                                   ///< The actor which all popup content is added to (i.e. panel and buttons)
309   Property::Index mAlternativeOffsetProperty;         ///< Property [Vector3] how much to offset the popup if it goes out of the screen
310   ImageActor mBackground;                             ///< The background popup panel
311   ImageActor mTail;                                   ///< The tail for the popup
312   Vector3 mContentSize;                               ///< Size of Content (i.e. Buttons)
313   ActorContainer mButtonContainer;                    ///< List of buttons added to popup.
314   ActorContainer mDividerContainer;                   ///< List of dividers added to popup.
315   Animation mAnimation;                               ///< Popup Hide/Show animation.
316
317   std::vector<ButtonRequirement> mOrderListOfButtons;        // List of buttons in the order to be displayed and a flag to indicate if needed.
318
319   Vector4           mCutPasteButtonsColor;  // Color of the cut and paste popup
320   Vector4           mCutPasteButtonsPressedColor;  // Color of the cut and paste buttons when pressed.
321   Vector4           mBorderColor; // Color of the border around the Cut and Paste Popup
322
323   // Priority of Options/Buttons in the Cut and Paste pop-up, higher priority buttons are displayed first, left to right.
324   std::size_t mSelectOptionPriority;  // Position of Select Button
325   std::size_t mSelectAllOptionPriority; // Position of Select All button
326   std::size_t mCutOptionPriority; // Position of Cut button
327   std::size_t mCopyOptionPriority; // Position of Copy button
328   std::size_t mPasteOptionPriority;  // Position of Paste button
329   std::size_t mClipboardOptionPriority;  // Position of Clipboard button
330
331   PressedSignalV2 mPressedSignal;              ///< Signal emitted when a button within the popup is pressed.
332   HideFinishedSignalV2 mHideFinishedSignal;    ///< Signal emitted when popup is completely hidden
333   ShowFinishedSignalV2 mShowFinishedSignal;    ///< Signal emitted when popup is completely shown
334
335 };
336
337 } // namespace Internal
338
339 } // namespace Toolkit
340
341 } // namespace Dali
342
343 #endif // __DALI_TOOLKIT_INTERNAL_ITEM_VIEW_H__