1 #ifndef DALI_TOOLKIT_INTERNAL_TEXT_SELECTION_POPUP_H
2 #define DALI_TOOLKIT_INTERNAL_TEXT_SELECTION_POPUP_H
5 * Copyright (c) 2019 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-toolkit/public-api/controls/control-impl.h>
23 #include <dali-toolkit/public-api/controls/buttons/push-button.h>
24 #include <dali-toolkit/public-api/controls/image-view/image-view.h>
25 #include <dali-toolkit/public-api/controls/table-view/table-view.h>
26 #include <dali-toolkit/devel-api/controls/text-controls/text-selection-popup.h>
27 #include <dali-toolkit/devel-api/controls/text-controls/text-selection-toolbar.h>
30 #include <dali/public-api/actors/layer.h>
31 #include <dali/public-api/object/property-map.h>
42 enum PopupCustomisations
50 class TextSelectionPopup : public Control
54 struct ButtonRequirement
57 : id( Toolkit::TextSelectionPopup::NONE ),
65 ButtonRequirement( Toolkit::TextSelectionPopup::Buttons buttonId,
66 std::size_t buttonPriority,
67 const std::string& buttonName,
68 const std::string& buttonCaption,
69 Dali::Image& buttonIcon,
72 priority( buttonPriority ),
74 caption( buttonCaption ),
76 enabled( buttonEnabled )
79 Toolkit::TextSelectionPopup::Buttons id;
87 struct ButtonPriorityCompare
89 bool operator()( const ButtonRequirement& lhs, const ButtonRequirement& rhs ) const {
90 return lhs.priority < rhs.priority;
95 * @brief New constructor with provided buttons to enable.
96 * @param[in] callbackInterface The text popup callback interface which receives the button click callbacks.
97 * @return A handle to the TextSelectionPopup control.
99 static Toolkit::TextSelectionPopup New( TextSelectionPopupCallbackInterface* callbackInterface );
104 * @brief Called when a property of an object of this type is set.
105 * @param[in] object The object whose property is set.
106 * @param[in] index The property index.
107 * @param[in] value The new property value.
109 static void SetProperty( BaseObject* object, Property::Index index, const Property::Value& value );
112 * @brief Called to retrieve a property of an object of this type.
114 * @param[in] object The object whose property is to be retrieved.
115 * @param[in] index The property index.
116 * @return The current value of the property.
118 static Property::Value GetProperty( BaseObject* object, Property::Index index );
121 * @copydoc Toolkit::EnableButtons
123 void EnableButtons( Toolkit::TextSelectionPopup::Buttons buttonsToEnable );
126 * @copydoc Toolkit::TextSelectionPopup::RaiseAbove()
128 void RaiseAbove( Layer target );
131 * @copydoc Toolkit::TextSelectionPopup::ShowPopup()
136 * @copydoc Toolkiut::TextSelectionPopup::HidePopup()
140 private: // From Control
143 * @copydoc Control::OnInitialize()
145 virtual void OnInitialize();
147 private: // Implementation
149 void HideAnimationFinished( Animation& animation );
152 * @brief When the cut button is pressed.
153 * @param[in] button the button pressed
154 * @return @e true to consume the event.
156 bool OnCutButtonPressed( Toolkit::Button button );
159 * @brief When the copy button is pressed.
160 * @param[in] button the button pressed
161 * @return @e true to consume the event.
163 bool OnCopyButtonPressed( Toolkit::Button button );
166 * @brief When the paste button is pressed.
167 * @param[in] button the button pressed
168 * @return @e true to consume the event.
170 bool OnPasteButtonPressed( Toolkit::Button button );
173 * @brief When the select button is pressed.
174 * @param[in] button the button pressed
175 * @return @e true to consume the event.
177 bool OnSelectButtonPressed( Toolkit::Button button );
180 * @brief When the select all button is pressed.
181 * @param[in] button the button pressed
182 * @return @e true to consume the event.
184 bool OnSelectAllButtonPressed( Toolkit::Button button );
187 * @brief When the clipboard button is pressed.
188 * @param[in] button the button pressed
189 * @return @e true to consume the event.
191 bool OnClipboardButtonPressed( Toolkit::Button button );
194 * @brief Method to set the dimension or dimension constraint on certain aspects of the Popup.
196 * @param[in] settingToCustomise The setting for the PopupCustomisations enum that can be customised
197 * @param[in] dimension The size to customise with
199 void SetDimensionToCustomise( const PopupCustomisations& settingToCustomise, const Size& dimension );
202 * @brief Method to get the dimension or dimension constraint on certain aspects of the Popup that was previously customised
204 * @param[in] setting The setting from the PopupCustomisations enum
206 Size GetDimensionToCustomise( const PopupCustomisations& setting );
209 * @brief Sets the image for the given button of the Popup.
211 * @param[in] button The button the image should be used for from the Buttons Enum.
212 * @param[in] image The image to use.
214 void SetButtonImage( Toolkit::TextSelectionPopup::Buttons button, Dali::Image image );
217 * @brief Retrieves the image of the given button used by the popup
219 * @param[in] button The button to get the image from
220 * @return The image used for that button.
222 Dali::Image GetButtonImage( Toolkit::TextSelectionPopup::Buttons button );
225 * @brief Sets the image for the pressed state of a popup option.
227 * @param[in] filename The image filename to use.
229 void SetPressedImage( const std::string& filename);
232 * @brief Gets the image used for the pressed state of a popup option.
234 * @return The image filename used.
236 std::string GetPressedImage() const;
238 void CreateOrderedListOfPopupOptions();
240 void AddOption( const ButtonRequirement& button, bool showDivider, bool showIcons, bool showCaption );
242 std::size_t GetNumberOfEnabledOptions();
244 void AddPopupOptionsToToolbar( bool showIcons, bool showCaptions );
247 * Creates the background-border image
249 * @param[in] propertyMap The properties describing the background-border
251 void CreateBackgroundBorder( Property::Map& propertyMap );
254 * Construct a new TextField.
256 TextSelectionPopup( TextSelectionPopupCallbackInterface* callbackInterface );
259 * A reference counted object may only be deleted by calling Unreference()
261 virtual ~TextSelectionPopup();
265 // Undefined copy constructor and assignment operators
266 TextSelectionPopup(const TextSelectionPopup&);
267 TextSelectionPopup& operator=(const TextSelectionPopup& rhs);
272 Dali::Toolkit::TextSelectionToolbar mToolbar;
274 Dali::Toolkit::TableView mTableOfButtons; // Actor which holds all the buttons, sensitivity can be set on buttons via this actor
276 // Images to be used by the Popup buttons
278 Image mCopyIconImage;
279 Image mPasteIconImage;
280 Image mClipboardIconImage;
281 Image mSelectIconImage;
282 Image mSelectAllIconImage;
284 Size mPopupMaxSize; // Maximum size of the Popup
285 Size mOptionMaxSize; // Maximum size of an Option button
286 Size mOptionMinSize; // Minimum size of an Option button
287 Size mOptionDividerSize; // Size of divider line
289 std::vector<ButtonRequirement> mOrderListOfButtons; // List of buttons in the order to be displayed and a flag to indicate if needed.
291 Toolkit::TextSelectionPopup::Buttons mEnabledButtons; // stores enabled buttons
292 Toolkit::TextSelectionPopupCallbackInterface* mCallbackInterface;
294 std::string mPressedImage; // Image used for the popup option when pressed.
295 Vector4 mPressedColor; // Color of the popup option when pressed.
296 Vector4 mDividerColor; // Color of the divider between buttons
297 Vector4 mIconColor; // Color of the popup icon.
299 // Priority of Options/Buttons in the Cut and Paste pop-up, higher priority buttons are displayed first, left to right.
300 std::size_t mSelectOptionPriority; // Position of Select Button
301 std::size_t mSelectAllOptionPriority; // Position of Select All button
302 std::size_t mCutOptionPriority; // Position of Cut button
303 std::size_t mCopyOptionPriority; // Position of Copy button
304 std::size_t mPasteOptionPriority; // Position of Paste button
305 std::size_t mClipboardOptionPriority; // Position of Clipboard button
306 float mFadeInDuration; // Duration of the animation to fade in the Popup
307 float mFadeOutDuration; // Duration of the animation to fade out the Popup
309 bool mShowIcons:1; // Flag to show icons
310 bool mShowCaptions:1; // Flag to show text captions
311 bool mPopupShowing:1; // Flag to indicate Popup showing
312 bool mButtonsChanged:1; // Flag to indicate the Popup Buttons have changed
316 } // namespace Internal
318 // Helpers for public-api forwarding methods
320 inline Toolkit::Internal::TextSelectionPopup& GetImpl( Toolkit::TextSelectionPopup& textSelectionPopup )
322 DALI_ASSERT_ALWAYS( textSelectionPopup );
324 Dali::RefObject& handle = textSelectionPopup.GetImplementation();
326 return static_cast<Toolkit::Internal::TextSelectionPopup&>(handle);
329 inline const Toolkit::Internal::TextSelectionPopup& GetImpl( const Toolkit::TextSelectionPopup& textSelectionPopup )
331 DALI_ASSERT_ALWAYS( textSelectionPopup );
333 const Dali::RefObject& handle = textSelectionPopup.GetImplementation();
335 return static_cast<const Toolkit::Internal::TextSelectionPopup&>(handle);
338 } // namespace Toolkit
342 #endif // DALI_TOOLKIT_INTERNAL_TEXT_SELECTION_POPUP_H