1 #ifndef __DALI_TOOLKIT_INTERNAL_TEXT_SELECTION_POPUP_H__
2 #define __DALI_TOOLKIT_INTERNAL_TEXT_SELECTION_POPUP_H__
5 * Copyright (c) 2017 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/table-view/table-view.h>
25 #include <dali-toolkit/devel-api/controls/text-controls/text-selection-popup.h>
26 #include <dali-toolkit/devel-api/controls/text-controls/text-selection-toolbar.h>
29 #include <dali/public-api/actors/layer.h>
40 enum PopupCustomisations
48 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,
67 Dali::Image& buttonIcon,
70 priority( buttonPriority ),
72 caption( buttonCaption ),
74 enabled( buttonEnabled )
77 Toolkit::TextSelectionPopup::Buttons id;
85 struct ButtonPriorityCompare
87 bool operator()( const ButtonRequirement& lhs, const ButtonRequirement& rhs ) const {
88 return lhs.priority < rhs.priority;
93 * @brief New constructor with provided buttons to enable.
94 * @param[in] callbackInterface The text popup callback interface which receives the button click callbacks.
95 * @return A handle to the TextSelectionPopup control.
97 static Toolkit::TextSelectionPopup New( TextSelectionPopupCallbackInterface* callbackInterface );
102 * @brief Called when a property of an object of this type is set.
103 * @param[in] object The object whose property is set.
104 * @param[in] index The property index.
105 * @param[in] value The new property value.
107 static void SetProperty( BaseObject* object, Property::Index index, const Property::Value& value );
110 * @brief Called to retrieve a property of an object of this type.
112 * @param[in] object The object whose property is to be retrieved.
113 * @param[in] index The property index.
114 * @return The current value of the property.
116 static Property::Value GetProperty( BaseObject* object, Property::Index index );
119 * @copydoc Toolkit::EnableButtons
121 void EnableButtons( Toolkit::TextSelectionPopup::Buttons buttonsToEnable );
124 * @copydoc Toolkit::TextSelectionPopup::RaiseAbove()
126 void RaiseAbove( Layer target );
129 * @copydoc Toolkit::TextSelectionPopup::ShowPopup()
134 * @copydoc Toolkiut::TextSelectionPopup::HidePopup()
138 private: // From Control
141 * @copydoc Control::OnInitialize()
143 virtual void OnInitialize();
145 private: // Implementation
147 void HideAnimationFinished( Animation& animation );
150 * @brief When the cut button is pressed.
151 * @param[in] button the button pressed
152 * @return @e true to consume the event.
154 bool OnCutButtonPressed( Toolkit::Button button );
157 * @brief When the copy button is pressed.
158 * @param[in] button the button pressed
159 * @return @e true to consume the event.
161 bool OnCopyButtonPressed( Toolkit::Button button );
164 * @brief When the paste button is pressed.
165 * @param[in] button the button pressed
166 * @return @e true to consume the event.
168 bool OnPasteButtonPressed( Toolkit::Button button );
171 * @brief When the select button is pressed.
172 * @param[in] button the button pressed
173 * @return @e true to consume the event.
175 bool OnSelectButtonPressed( Toolkit::Button button );
178 * @brief When the select all button is pressed.
179 * @param[in] button the button pressed
180 * @return @e true to consume the event.
182 bool OnSelectAllButtonPressed( Toolkit::Button button );
185 * @brief When the clipboard button is pressed.
186 * @param[in] button the button pressed
187 * @return @e true to consume the event.
189 bool OnClipboardButtonPressed( Toolkit::Button button );
192 * @brief Method to set the dimension or dimension constraint on certain aspects of the Popup.
194 * @param[in] settingToCustomise The setting for the PopupCustomisations enum that can be customised
195 * @param[in] dimension The size to customise with
197 void SetDimensionToCustomise( const PopupCustomisations& settingToCustomise, const Size& dimension );
200 * @brief Method to get the dimension or dimension constraint on certain aspects of the Popup that was previously customised
202 * @param[in] setting The setting from the PopupCustomisations enum
204 Size GetDimensionToCustomise( const PopupCustomisations& setting );
207 * @brief Sets the image for the given button of the Popup.
209 * @param[in] button The button the image should be used for from the Buttons Enum.
210 * @param[in] image The image to use.
212 void SetButtonImage( Toolkit::TextSelectionPopup::Buttons button, Dali::Image image );
215 * @brief Retrieves the image of the given button used by the popup
217 * @param[in] button The button to get the image from
218 * @return The image used for that button.
220 Dali::Image GetButtonImage( Toolkit::TextSelectionPopup::Buttons button );
223 * @brief Sets the image for the pressed state of a popup option.
225 * @param[in] filename The image filename to use.
227 void SetPressedImage( const std::string& filename);
230 * @brief Gets the image used for the pressed state of a popup option.
232 * @return The image filename used.
234 std::string GetPressedImage() const;
236 void CreateOrderedListOfPopupOptions();
238 void AddOption( const ButtonRequirement& button, bool showDivider, bool showIcons, bool showCaption );
240 std::size_t GetNumberOfEnabledOptions();
242 void AddPopupOptionsToToolbar( bool showIcons, bool showCaptions );
245 * Construct a new TextField.
247 TextSelectionPopup( TextSelectionPopupCallbackInterface* callbackInterface );
250 * A reference counted object may only be deleted by calling Unreference()
252 virtual ~TextSelectionPopup();
256 // Undefined copy constructor and assignment operators
257 TextSelectionPopup(const TextSelectionPopup&);
258 TextSelectionPopup& operator=(const TextSelectionPopup& rhs);
263 Dali::Toolkit::TextSelectionToolbar mToolbar;
265 Dali::Toolkit::TableView mTableOfButtons; // Actor which holds all the buttons, sensitivity can be set on buttons via this actor
267 // Images to be used by the Popup buttons
269 Image mCopyIconImage;
270 Image mPasteIconImage;
271 Image mClipboardIconImage;
272 Image mSelectIconImage;
273 Image mSelectAllIconImage;
275 Size mPopupMaxSize; // Maximum size of the Popup
276 Size mOptionMaxSize; // Maximum size of an Option button
277 Size mOptionMinSize; // Minimum size of an Option button
278 Size mOptionDividerSize; // Size of divider line
280 std::vector<ButtonRequirement> mOrderListOfButtons; // List of buttons in the order to be displayed and a flag to indicate if needed.
282 Toolkit::TextSelectionPopup::Buttons mEnabledButtons; // stores enabled buttons
283 Toolkit::TextSelectionPopupCallbackInterface* mCallbackInterface;
285 std::string mPressedImage; // Image used for the popup option when pressed.
286 Vector4 mPressedColor; // Color of the popup option when pressed.
287 Vector4 mDividerColor; // Color of the divider between buttons
288 Vector4 mIconColor; // Color of the popup icon.
290 // Priority of Options/Buttons in the Cut and Paste pop-up, higher priority buttons are displayed first, left to right.
291 std::size_t mSelectOptionPriority; // Position of Select Button
292 std::size_t mSelectAllOptionPriority; // Position of Select All button
293 std::size_t mCutOptionPriority; // Position of Cut button
294 std::size_t mCopyOptionPriority; // Position of Copy button
295 std::size_t mPasteOptionPriority; // Position of Paste button
296 std::size_t mClipboardOptionPriority; // Position of Clipboard button
297 float mFadeInDuration; // Duration of the animation to fade in the Popup
298 float mFadeOutDuration; // Duration of the animation to fade out the Popup
300 bool mShowIcons:1; // Flag to show icons
301 bool mShowCaptions:1; // Flag to show text captions
302 bool mPopupShowing:1; // Flag to indicate Popup showing
303 bool mButtonsChanged:1; // Flag to indicate the Popup Buttons have changed
307 } // namespace Internal
309 // Helpers for public-api forwarding methods
311 inline Toolkit::Internal::TextSelectionPopup& GetImpl( Toolkit::TextSelectionPopup& textSelectionPopup )
313 DALI_ASSERT_ALWAYS( textSelectionPopup );
315 Dali::RefObject& handle = textSelectionPopup.GetImplementation();
317 return static_cast<Toolkit::Internal::TextSelectionPopup&>(handle);
320 inline const Toolkit::Internal::TextSelectionPopup& GetImpl( const Toolkit::TextSelectionPopup& textSelectionPopup )
322 DALI_ASSERT_ALWAYS( textSelectionPopup );
324 const Dali::RefObject& handle = textSelectionPopup.GetImplementation();
326 return static_cast<const Toolkit::Internal::TextSelectionPopup&>(handle);
329 } // namespace Toolkit
333 #endif // __DALI_TOOLKIT_INTERNAL_TEXT_SELECTION_POPUP_H__