1 #ifndef __DALI_TOOLKIT_INTERNAL_TEXT_INPUT_POPUP_H__
2 #define __DALI_TOOLKIT_INTERNAL_TEXT_INPUT_POPUP_H__
5 * Copyright (c) 2014 Samsung Electronics Co., Ltd.
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
11 * http://www.apache.org/licenses/LICENSE-2.0
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.
22 #include <dali/dali.h>
24 #include <dali-toolkit/public-api/controls/text-view/text-view.h>
37 class TextInputPopup : public ConnectionTracker
61 struct ButtonRequirement
63 TextInputPopup::Buttons buttonId;
64 std::size_t orderOfPriority;
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;
79 static const char* const SIGNAL_PRESSED;
80 static const char* const SIGNAL_HIDE_FINISHED;
81 static const char* const SIGNAL_SHOW_FINISHED;
83 // Popup Button Pressed
84 typedef SignalV2< bool( Toolkit::Button ) > PressedSignalV2;
86 // Popup Hide Finished
87 typedef SignalV2< void( TextInputPopup& ) > HideFinishedSignalV2;
89 // Popup Show Finished
90 typedef SignalV2< void( TextInputPopup& ) > ShowFinishedSignalV2;
93 * Signal emitted when the button is touched.
95 PressedSignalV2& PressedSignal();
98 * Signal emitted when popup is completely hidden
99 * @note Only occurs after a Show() call with animation enabled.
101 HideFinishedSignalV2& HideFinishedSignal();
104 * Signal emitted when popup is completely shown
105 * @note Only occurs after a Hide() call with animation enabled.
107 ShowFinishedSignalV2& ShowFinishedSignal();
112 * Default constructor
113 * Creates an empty popup base actor (no content i.e. invisible)
118 * @return The root actor of for this popup is returned.
123 * Clears popup options (popup no longer exists)
129 * @param[in] styledCaption The text to be displayed
130 * @return the newly created label
132 Toolkit::TextView CreateOptionText( const MarkupProcessor::StyledTextArray& styledCaption );
136 * @param[in] iconImage the image to be used
137 * @return the newly created Image actor to be used as the icon
139 ImageActor CreateOptionIcon( Image iconImage );
142 * Creates and sets up the popup background
144 void CreatePopUpBackground();
147 * Create divider if multiple options
149 void CreateDivider();
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
156 ImageActor CreatePressedBackground( const Vector3 requiredSize );
159 * Creates a ordered vector of button options
161 void CreateOrderedListOfOptions();
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)
172 void AddOption(const std::string& name, const std::string& caption, const Image iconImage, bool finalOption);
176 * @param[in] animate (optional) whether to animate popup to hide state over time (i.e. tween).
178 void Hide(bool animate = true);
182 * @param[in] animate (optional) whether to animate popup to show state over time (i.e. tween).
184 void Show(bool animate = true);
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)
192 void SetAlternativeOffset(Vector2 offset);
195 * Returns the current state of the popup.
196 * @return The state of the popup see enum State
198 State GetState(void) const;
201 * Get the root actor which the buttons are added to.
202 * @return the root actor
204 Actor GetRootActor() const;
207 * Set the Cut and Paste buttons color when in normal state
208 * @param[in] color color to use
210 void SetCutPastePopUpColor( const Vector4& color );
213 * Get the set color of the Copy and Paste PopUp buttons
216 const Vector4& GetCutPastePopUpColor() const;
219 * Set the Cut and Paste button color when pressed.
220 * @param[in] color color to use
222 void SetCutPastePopUpPressedColor( const Vector4& color );
225 * Get the Cut and Paste pressed button color.
228 const Vector4& GetCutPastePopUpPressedColor() const;
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)
235 void TogglePopUpButtonOnOff( TextInputPopup::Buttons requiredButton, bool enable );
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.
242 void SetButtonPriorityPosition( TextInputPopup::Buttons button, unsigned int priority );
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.
249 unsigned int GetButtonPriorityPosition( TextInputPopup::Buttons button ) const;
252 * Adds Popup options which have been enabled.
254 void AddPopupOptions();
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.
267 TextInputPopup::ButtonRequirement CreateRequiredButton( TextInputPopup::Buttons buttonId, std::size_t orderOfPriority,
268 const std::string& name, const std::string& caption, Image iconImage, bool enabled );
271 * Adds Popup to the stage (ideally on a separate top-most layer and as an overlay)
276 * Applies constraint to keep Popup in view within the desired area.
278 void ApplyConfinementConstraint();
281 * Removes Popup from the stage.
283 void RemoveFromStage();
286 * Called when a button is pressed in the Popup
287 * @param[in] button The button pressed.
289 bool OnButtonPressed( Toolkit::Button button );
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.
296 void OnHideFinished(Animation& source);
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.
303 void OnShowFinished(Animation& source);
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.
317 std::vector<ButtonRequirement> mOrderListOfButtons; // List of buttons in the order to be displayed and a flag to indicate if needed.
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
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
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
337 } // namespace Internal
339 } // namespace Toolkit
343 #endif // __DALI_TOOLKIT_INTERNAL_ITEM_VIEW_H__