License conversion from Flora to Apache 2.0
[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   // Signal names
51   static const char* const SIGNAL_PRESSED;
52   static const char* const SIGNAL_HIDE_FINISHED;
53   static const char* const SIGNAL_SHOW_FINISHED;
54
55   // Popup Button Pressed
56   typedef SignalV2< bool( Toolkit::Button ) > PressedSignalV2;
57
58   // Popup Hide Finished
59   typedef SignalV2< void( TextInputPopup& ) > HideFinishedSignalV2;
60
61   // Popup Show Finished
62   typedef SignalV2< void( TextInputPopup& ) > ShowFinishedSignalV2;
63
64   /**
65    * Signal emitted when the button is touched.
66    */
67   PressedSignalV2& PressedSignal();
68
69   /**
70    * Signal emitted when popup is completely hidden
71    * @note Only occurs after a Show() call with animation enabled.
72    */
73   HideFinishedSignalV2& HideFinishedSignal();
74
75   /**
76    * Signal emitted when popup is completely shown
77    * @note Only occurs after a Hide() call with animation enabled.
78    */
79   ShowFinishedSignalV2& ShowFinishedSignal();
80
81 public:
82
83   /**
84    * Default constructor
85    * Creates an empty popup base actor (no content i.e. invisible)
86    */
87   TextInputPopup();
88
89   /**
90    * @return The root actor of for this popup is returned.
91    */
92   Actor Self();
93
94   /**
95    * Clears popup options (popup no longer exists)
96    */
97   void Clear();
98
99   /**
100    * Create the label
101    * @param[in] styledCaption The text to be displayed
102    * @return the newly created label
103    */
104   Toolkit::TextView CreateOptionText( const MarkupProcessor::StyledTextArray& styledCaption );
105
106   /**
107    * Create the label
108    * @param[in] iconImage the image to be used
109    * @return the newly created Image actor to be used as the icon
110    */
111   ImageActor CreateOptionIcon( Image iconImage );
112
113   /**
114    * Creates and sets up the popup background
115    */
116   void CreatePopUpBackground();
117
118   /**
119    * Create divider if multiple options
120    */
121   void CreateDivider();
122
123   /**
124    * Create a background to be used when button pressed
125    * @param[in] requiredSize size Image actor should be
126    * @param[in] finalFlag flag to be set if option is the final one.
127    * @return Returns an Image Actor to be used a pressed background
128    */
129   ImageActor CreatePressedBackground( const Vector3 requiredSize, const bool finalFlag );
130
131   /**
132    * Adds a popup option.
133    * @note Creates popup frame if not already created.
134    * @param[in] name The unique name for this option.
135    * @param[in] caption The caption (label) for this option
136    * @param[in] iconImage Image to displayed with text.
137    * @param[in] finalOption Flag to indicate that this is the final option.
138    * (set to true on the last option you add)
139    */
140   void AddOption(const std::string& name, const std::string& caption, const Image iconImage, bool finalOption);
141
142   /**
143    * Hides the popup
144    * @param[in] animate (optional) whether to animate popup to hide state over time (i.e. tween).
145    */
146   void Hide(bool animate = true);
147
148   /**
149    * Shows the popup
150    * @param[in] animate (optional) whether to animate popup to show state over time (i.e. tween).
151    */
152   void Show(bool animate = true);
153
154   /**
155    * Sets Alternative offset property.
156    * The alternative offset property is how much to move in the horizontal and vertical
157    * axes when the popup goes out of the screen on the left/right sides or top/bottom sides.
158    * @param[in] offset Vector holding the left/right offset (x) and top/bottom offset (y)
159    */
160   void SetAlternativeOffset(Vector2 offset);
161
162   /**
163    * Returns the current state of the popup.
164    * @return The state of the popup see enum State
165    */
166   State GetState(void) const;
167
168   /**
169    * Get the root actor which the buttons are added to.
170    * @return the root actor
171    */
172   Actor GetRootActor() const;
173
174 private:
175
176   /**
177    * Adds popup to the stage (ideally on a separate top-most layer and as an overlay)
178    */
179   void AddToStage();
180
181   /**
182    * Applies constraint to keep Popup in view within the desired area.
183    */
184   void ApplyConfinementConstraint();
185
186   /**
187    * Removes popup from the stage.
188    */
189   void RemoveFromStage();
190
191   /**
192    * Called when a button is pressed in the popup
193    * @param[in] button The button pressed.
194    */
195   bool OnButtonPressed( Toolkit::Button button );
196
197   /**
198    * Invoked upon popup Hide animation completing.
199    * @note Only called for animating hide, not called for instantaneous (animate = false)
200    * @param[in] source The animation which completed.
201    */
202   void OnHideFinished(Animation& source);
203
204   /**
205    * Invoked upon popup Show animation completing.
206    * @note Only called for animating show, not called for instantaneous (animate = false)
207    * @param[in] source The animation which completed.
208    */
209   void OnShowFinished(Animation& source);
210
211 private:
212
213   State mState;                                       ///< Popup State.
214   Actor mRootActor;                                   ///< The actor which all popup content is added to (i.e. panel and buttons)
215   Property::Index mAlternativeOffsetProperty;         ///< Property [Vector3] how much to offset the popup if it goes out of the screen
216   ImageActor mBackground;                             ///< The background popup panel
217   ImageActor mTail;                                   ///< The tail for the popup
218   Vector3 mContentSize;                               ///< Size of Content (i.e. Buttons)
219   ActorContainer mButtonContainer;                    ///< List of buttons added to popup.
220   ActorContainer mDividerContainer;                   ///< List of dividers added to popup.
221   Animation mAnimation;                               ///< Popup Hide/Show animation.
222
223   PressedSignalV2 mPressedSignal;              ///< Signal emitted when a button within the popup is pressed.
224   HideFinishedSignalV2 mHideFinishedSignal;    ///< Signal emitted when popup is completely hidden
225   ShowFinishedSignalV2 mShowFinishedSignal;    ///< Signal emitted when popup is completely shown
226
227 };
228
229 } // namespace Internal
230
231 } // namespace Toolkit
232
233 } // namespace Dali
234
235 #endif // __DALI_TOOLKIT_INTERNAL_ITEM_VIEW_H__