1 #ifndef DALI_TOOLKIT_INTERNAL_TEXT_SELECTION_POPUP_H
2 #define DALI_TOOLKIT_INTERNAL_TEXT_SELECTION_POPUP_H
5 * Copyright (c) 2021 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/public-api/actors/layer.h>
23 #include <dali/public-api/object/property-map.h>
27 #include <dali-toolkit/devel-api/controls/control-devel.h>
28 #include <dali-toolkit/devel-api/controls/table-view/table-view.h>
29 #include <dali-toolkit/devel-api/controls/text-controls/text-selection-popup.h>
30 #include <dali-toolkit/devel-api/controls/text-controls/text-selection-toolbar.h>
31 #include <dali-toolkit/public-api/controls/buttons/push-button.h>
32 #include <dali-toolkit/public-api/controls/control-impl.h>
33 #include <dali-toolkit/public-api/controls/image-view/image-view.h>
41 enum PopupCustomisations
49 class TextSelectionPopup : public Control
52 struct ButtonRequirement
55 : id(Toolkit::TextSelectionPopup::NONE),
63 ButtonRequirement(Toolkit::TextSelectionPopup::Buttons buttonId,
64 std::size_t buttonPriority,
65 const std::string& buttonName,
66 const std::string& buttonCaption,
69 priority(buttonPriority),
71 caption(buttonCaption),
72 enabled(buttonEnabled)
76 Toolkit::TextSelectionPopup::Buttons id;
83 struct ButtonPriorityCompare
85 bool operator()(const ButtonRequirement& lhs, const ButtonRequirement& rhs) const
87 return lhs.priority < rhs.priority;
92 * @brief New constructor with provided buttons to enable.
93 * @param[in] callbackInterface The text popup callback interface which receives the button click callbacks.
94 * @return A handle to the TextSelectionPopup control.
96 static Toolkit::TextSelectionPopup New(TextSelectionPopupCallbackInterface* callbackInterface);
101 * @brief Called when a property of an object of this type is set.
102 * @param[in] object The object whose property is set.
103 * @param[in] index The property index.
104 * @param[in] value The new property value.
106 static void SetProperty(BaseObject* object, Property::Index index, const Property::Value& value);
109 * @brief Called to retrieve a property of an object of this type.
111 * @param[in] object The object whose property is to be retrieved.
112 * @param[in] index The property index.
113 * @return The current value of the property.
115 static Property::Value GetProperty(BaseObject* object, Property::Index index);
118 * @brief Toolkit::TextSelectionPopup::SetProperties()
120 void SetProperties(const Property::Map& properties);
123 * @brief Toolkit::TextSelectionPopup::GetProperties()
125 void GetProperties(Property::Map& properties);
128 * @copydoc Toolkit::EnableButtons
130 void EnableButtons(Toolkit::TextSelectionPopup::Buttons buttonsToEnable);
133 * @copydoc Toolkit::TextSelectionPopup::RaiseAbove()
135 void RaiseAbove(Actor target);
138 * @copydoc Toolkit::TextSelectionPopup::ShowPopup()
143 * @copydoc Toolkiut::TextSelectionPopup::HidePopup()
147 private: // From Control
149 * @copydoc Control::OnInitialize()
151 void OnInitialize() override;
154 * @copydoc Toolkit::Internal::Control::CreateAccessibleObject()
156 DevelControl::ControlAccessible* CreateAccessibleObject() override;
158 private: // Implementation
159 void HideAnimationFinished(Animation& animation);
162 * @brief When the cut button is pressed.
163 * @param[in] button the button pressed
164 * @return @e true to consume the event.
166 bool OnCutButtonPressed(Toolkit::Button button);
169 * @brief When the copy button is pressed.
170 * @param[in] button the button pressed
171 * @return @e true to consume the event.
173 bool OnCopyButtonPressed(Toolkit::Button button);
176 * @brief When the paste button is pressed.
177 * @param[in] button the button pressed
178 * @return @e true to consume the event.
180 bool OnPasteButtonPressed(Toolkit::Button button);
183 * @brief When the select button is pressed.
184 * @param[in] button the button pressed
185 * @return @e true to consume the event.
187 bool OnSelectButtonPressed(Toolkit::Button button);
190 * @brief When the select all button is pressed.
191 * @param[in] button the button pressed
192 * @return @e true to consume the event.
194 bool OnSelectAllButtonPressed(Toolkit::Button button);
197 * @brief When the clipboard button is pressed.
198 * @param[in] button the button pressed
199 * @return @e true to consume the event.
201 bool OnClipboardButtonPressed(Toolkit::Button button);
204 * @brief Method to set the dimension or dimension constraint on certain aspects of the Popup.
206 * @param[in] settingToCustomise The setting for the PopupCustomisations enum that can be customised
207 * @param[in] dimension The size to customise with
209 void SetDimensionToCustomise(const PopupCustomisations& settingToCustomise, const Size& dimension);
212 * @brief Method to get the dimension or dimension constraint on certain aspects of the Popup that was previously customised
214 * @param[in] setting The setting from the PopupCustomisations enum
216 Size GetDimensionToCustomise(const PopupCustomisations& setting) const;
219 * @brief Sets the image for the given button of the Popup.
221 * @param[in] button The button the image should be used for from the Buttons Enum.
222 * @param[in] image The image to use.
224 void SetButtonImage(Toolkit::TextSelectionPopup::Buttons button, const std::string& image);
227 * @brief Retrieves the image of the given button used by the popup
229 * @param[in] button The button to get the image from
230 * @return The image used for that button.
232 const std::string& GetButtonImage(Toolkit::TextSelectionPopup::Buttons button) const;
235 * @brief Sets the image for the pressed state of a popup option.
237 * @param[in] filename The image filename to use.
239 void SetPressedImage(const std::string& filename);
242 * @brief Gets the image used for the pressed state of a popup option.
244 * @return The image filename used.
246 std::string GetPressedImage() const;
249 * Set option divider padding
250 * @param[in] padding BEGIN END BOTTOM TOP
252 void SetOptionDividerPadding(const Padding& padding);
255 * Get option divider padding
258 Padding GetOptionDividerPadding() const;
262 * @param[in] padding BEGIN END BOTTOM TOP
264 void SetLabelPadding(const Padding& padding);
270 Padding GetLabelPadding() const;
272 void CreateOrderedListOfPopupOptions();
274 void AddOption(const ButtonRequirement& button, bool showDivider, bool showIcons, bool showCaption);
276 std::size_t GetNumberOfEnabledOptions() const;
278 void AddPopupOptionsToToolbar(bool showIcons, bool showCaptions);
281 * Creates the background-border image
283 * @param[in] propertyMap The properties describing the background-border
285 void CreateBackgroundBorder(Property::Map& propertyMap);
288 * Creates the background image
290 * @param[in] propertyMap The properties describing the background
292 void CreateBackground(Property::Map& propertyMap);
296 * Construct a new TextField.
298 TextSelectionPopup(TextSelectionPopupCallbackInterface* callbackInterface);
301 * A reference counted object may only be deleted by calling Unreference()
303 virtual ~TextSelectionPopup();
306 struct PropertyHandler;
308 class TextSelectionPopupAccessible : public DevelControl::ControlAccessible
311 using DevelControl::ControlAccessible::ControlAccessible;
314 * @copydoc DevelControl::ControlAccessible::CalculateStates()
316 Dali::Accessibility::States CalculateStates() override;
320 // Undefined copy constructor and assignment operators
321 TextSelectionPopup(const TextSelectionPopup&);
322 TextSelectionPopup& operator=(const TextSelectionPopup& rhs);
325 Dali::Toolkit::TextSelectionToolbar mToolbar;
327 Dali::Toolkit::TableView mTableOfButtons; // Actor which holds all the buttons, sensitivity can be set on buttons via this actor
329 // Images paths to be used by the Popup buttons
330 std::string mCutIconImage;
331 std::string mCopyIconImage;
332 std::string mPasteIconImage;
333 std::string mClipboardIconImage;
334 std::string mSelectIconImage;
335 std::string mSelectAllIconImage;
337 Size mPopupMaxSize; // Maximum size of the Popup
338 Size mOptionMaxSize; // Maximum size of an Option button
339 Size mOptionMinSize; // Minimum size of an Option button
340 Size mOptionDividerSize; // Size of divider line
341 Padding mOptionDividerPadding; // Padding of divider line
343 Vector2 mLabelMinimumSize; // Minimum size of label
344 Padding mLabelPadding; // Padding of label
345 Property::Map mLabelTextVisual; // Text visual map of label
346 bool mEnableScrollBar; // Enable scrollbar
348 std::vector<ButtonRequirement> mOrderListOfButtons; // List of buttons in the order to be displayed and a flag to indicate if needed.
350 Toolkit::TextSelectionPopup::Buttons mEnabledButtons; // stores enabled buttons
351 Toolkit::TextSelectionPopupCallbackInterface* mCallbackInterface;
353 std::string mPressedImage; // Image used for the popup option when pressed.
354 Vector4 mPressedColor; // Color of the popup option when pressed.
355 float mPressedCornerRadius; // Corner radius of the popup option when pressed.
356 Vector4 mDividerColor; // Color of the divider between buttons
357 Vector4 mIconColor; // Color of the popup icon.
359 // Priority of Options/Buttons in the Cut and Paste pop-up, higher priority buttons are displayed first, left to right.
360 std::size_t mSelectOptionPriority; // Position of Select Button
361 std::size_t mSelectAllOptionPriority; // Position of Select All button
362 std::size_t mCutOptionPriority; // Position of Cut button
363 std::size_t mCopyOptionPriority; // Position of Copy button
364 std::size_t mPasteOptionPriority; // Position of Paste button
365 std::size_t mClipboardOptionPriority; // Position of Clipboard button
366 float mFadeInDuration; // Duration of the animation to fade in the Popup
367 float mFadeOutDuration; // Duration of the animation to fade out the Popup
369 bool mShowIcons : 1; // Flag to show icons
370 bool mShowCaptions : 1; // Flag to show text captions
371 bool mPopupShowing : 1; // Flag to indicate Popup showing
372 bool mButtonsChanged : 1; // Flag to indicate the Popup Buttons have changed
375 } // namespace Internal
377 // Helpers for public-api forwarding methods
379 inline Toolkit::Internal::TextSelectionPopup& GetImpl(Toolkit::TextSelectionPopup& textSelectionPopup)
381 DALI_ASSERT_ALWAYS(textSelectionPopup);
383 Dali::RefObject& handle = textSelectionPopup.GetImplementation();
385 return static_cast<Toolkit::Internal::TextSelectionPopup&>(handle);
388 inline const Toolkit::Internal::TextSelectionPopup& GetImpl(const Toolkit::TextSelectionPopup& textSelectionPopup)
390 DALI_ASSERT_ALWAYS(textSelectionPopup);
392 const Dali::RefObject& handle = textSelectionPopup.GetImplementation();
394 return static_cast<const Toolkit::Internal::TextSelectionPopup&>(handle);
397 } // namespace Toolkit
401 #endif // DALI_TOOLKIT_INTERNAL_TEXT_SELECTION_POPUP_H