1 #ifndef __DALI_TOOLKIT_INTERNAL_TEXT_SELECTION_POPUP_H__
2 #define __DALI_TOOLKIT_INTERNAL_TEXT_SELECTION_POPUP_H__
5 * Copyright (c) 2015 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/image-actor.h>
30 #include <dali/public-api/actors/layer.h>
44 enum PopupCustomisations
54 class TextSelectionPopup : public Control
58 struct ButtonRequirement
61 : id( Toolkit::TextSelectionPopup::NONE ),
69 ButtonRequirement( Toolkit::TextSelectionPopup::Buttons buttonId,
70 std::size_t buttonPriority,
71 const std::string& buttonName,
72 const std::string& buttonCaption,
73 Dali::Image& buttonIcon,
76 priority( buttonPriority ),
78 caption( buttonCaption ),
80 enabled( buttonEnabled )
83 Toolkit::TextSelectionPopup::Buttons id;
91 struct ButtonPriorityCompare
93 bool operator()( const ButtonRequirement& lhs, const ButtonRequirement& rhs ) const {
94 return lhs.priority < rhs.priority;
99 * @brief New constructor with provided buttons to enable.
100 * @param[in] callbackInterface The text popup callback interface which receives the button click callbacks.
101 * @return A handle to the TextSelectionPopup control.
103 static Toolkit::TextSelectionPopup New( TextSelectionPopupCallbackInterface* callbackInterface );
108 * @brief Called when a property of an object of this type is set.
109 * @param[in] object The object whose property is set.
110 * @param[in] index The property index.
111 * @param[in] value The new property value.
113 static void SetProperty( BaseObject* object, Property::Index index, const Property::Value& value );
116 * @brief Called to retrieve a property of an object of this type.
118 * @param[in] object The object whose property is to be retrieved.
119 * @param[in] index The property index.
120 * @return The current value of the property.
122 static Property::Value GetProperty( BaseObject* object, Property::Index index );
125 * @copydoc Toolkit::EnableButtons
127 void EnableButtons( Toolkit::TextSelectionPopup::Buttons buttonsToEnable );
130 * @copydoc Toolkit::TextSelectionPopup::RaiseAbove()
132 void RaiseAbove( Layer target );
135 * @copydoc Toolkit::TextSelectionPopup::ShowPopup()
140 * @copydoc Toolkiut::TextSelectionPopup::HidePopup()
144 private: // From Control
147 * @copydoc Control::OnInitialize()
149 virtual void OnInitialize();
152 * @copydoc Control::OnStageConnection()
154 virtual void OnStageConnection( int depth );
156 private: // Implementation
158 void HideAnimationFinished( Animation& animation );
161 * @brief When the cut button is pressed.
162 * @param[in] button the button pressed
163 * @return @e true to consume the event.
165 bool OnCutButtonPressed( Toolkit::Button button );
168 * @brief When the copy button is pressed.
169 * @param[in] button the button pressed
170 * @return @e true to consume the event.
172 bool OnCopyButtonPressed( Toolkit::Button button );
175 * @brief When the paste button is pressed.
176 * @param[in] button the button pressed
177 * @return @e true to consume the event.
179 bool OnPasteButtonPressed( Toolkit::Button button );
182 * @brief When the select button is pressed.
183 * @param[in] button the button pressed
184 * @return @e true to consume the event.
186 bool OnSelectButtonPressed( Toolkit::Button button );
189 * @brief When the select all button is pressed.
190 * @param[in] button the button pressed
191 * @return @e true to consume the event.
193 bool OnSelectAllButtonPressed( Toolkit::Button button );
196 * @brief When the clipboard button is pressed.
197 * @param[in] button the button pressed
198 * @return @e true to consume the event.
200 bool OnClipboardButtonPressed( Toolkit::Button button );
203 * @brief Method to set the dimension or dimension constraint on certain aspects of the Popup.
205 * @param[in] settingToCustomise The setting for the PopupCustomisations enum that can be customised
206 * @param[in] dimension The size to customise with
208 void SetDimensionToCustomise( const PopupCustomisations& settingToCustomise, const Size& dimension );
211 * @brief Method to get the dimension or dimension constraint on certain aspects of the Popup that was previously customised
213 * @param[in] setting The setting from the PopupCustomisations enum
215 Size GetDimensionToCustomise( const PopupCustomisations& setting );
218 * @brief Sets the image for the given button of the Popup.
220 * @param[in] button The button the image should be used for from the Buttons Enum.
221 * @param[in] image The image to use.
223 void SetButtonImage( Toolkit::TextSelectionPopup::Buttons button, Dali::Image image );
226 * @brief Retrieves the image of the given button used by the popup
228 * @param[in] button The button to get the image from
229 * @return The image used for that button.
231 Dali::Image GetButtonImage( Toolkit::TextSelectionPopup::Buttons button );
234 * @brief Sets the image for the pressed state of a popup option.
236 * @param[in] filename The image filename to use.
238 void SetPressedImage( const std::string& filename);
241 * @brief Gets the image used for the pressed state of a popup option.
243 * @return The image filename used.
245 std::string GetPressedImage() const;
247 void CreateOrderedListOfPopupOptions();
249 void AddOption( const ButtonRequirement& button, bool showDivider, bool showIcons, bool showCaption );
251 std::size_t GetNumberOfEnabledOptions();
253 void AddPopupOptionsToToolbar( bool showIcons, bool showCaptions );
256 * Construct a new TextField.
258 TextSelectionPopup( TextSelectionPopupCallbackInterface* callbackInterface );
261 * A reference counted object may only be deleted by calling Unreference()
263 virtual ~TextSelectionPopup();
267 // Undefined copy constructor and assignment operators
268 TextSelectionPopup(const TextSelectionPopup&);
269 TextSelectionPopup& operator=(const TextSelectionPopup& rhs);
274 Dali::Toolkit::TextSelectionToolbar mToolbar;
276 Dali::Toolkit::TableView mTableOfButtons; // Actor which holds all the buttons, sensitivity can be set on buttons via this actor
278 // Images to be used by the Popup buttons
280 Image mCopyIconImage;
281 Image mPasteIconImage;
282 Image mClipboardIconImage;
283 Image mSelectIconImage;
284 Image mSelectAllIconImage;
286 Size mPopupMaxSize; // Maximum size of the Popup
287 Size mOptionMaxSize; // Maximum size of an Option button
288 Size mOptionMinSize; // Minimum size of an Option button
289 Size mOptionDividerSize; // Size of divider line
291 std::vector<ButtonRequirement> mOrderListOfButtons; // List of buttons in the order to be displayed and a flag to indicate if needed.
293 Toolkit::TextSelectionPopup::Buttons mEnabledButtons; // stores enabled buttons
294 Toolkit::TextSelectionPopupCallbackInterface* mCallbackInterface;
296 std::string mPressedImage; // Image used for the popup option when pressed.
297 Vector4 mPressedColor; // Color of the popup option when pressed.
298 Vector4 mDividerColor; // Color of the divider between buttons
299 Vector4 mIconColor; // Color of the popup icon.
301 // Priority of Options/Buttons in the Cut and Paste pop-up, higher priority buttons are displayed first, left to right.
302 std::size_t mSelectOptionPriority; // Position of Select Button
303 std::size_t mSelectAllOptionPriority; // Position of Select All button
304 std::size_t mCutOptionPriority; // Position of Cut button
305 std::size_t mCopyOptionPriority; // Position of Copy button
306 std::size_t mPasteOptionPriority; // Position of Paste button
307 std::size_t mClipboardOptionPriority; // Position of Clipboard button
308 float mFadeInDuration; // Duration of the animation to fade in the Popup
309 float mFadeOutDuration; // Duration of the animation to fade out the Popup
311 bool mShowIcons:1; // Flag to show icons
312 bool mShowCaptions:1; // Flag to show text captions
313 bool mPopupShowing:1; // Flag to indicate Popup showing
314 bool mButtonsChanged:1; // Flag to indicate the Popup Buttons have changed
318 } // namespace Internal
320 // Helpers for public-api forwarding methods
322 inline Toolkit::Internal::TextSelectionPopup& GetImpl( Toolkit::TextSelectionPopup& textSelectionPopup )
324 DALI_ASSERT_ALWAYS( textSelectionPopup );
326 Dali::RefObject& handle = textSelectionPopup.GetImplementation();
328 return static_cast<Toolkit::Internal::TextSelectionPopup&>(handle);
331 inline const Toolkit::Internal::TextSelectionPopup& GetImpl( const Toolkit::TextSelectionPopup& textSelectionPopup )
333 DALI_ASSERT_ALWAYS( textSelectionPopup );
335 const Dali::RefObject& handle = textSelectionPopup.GetImplementation();
337 return static_cast<const Toolkit::Internal::TextSelectionPopup&>(handle);
340 } // namespace Toolkit
344 #endif // __DALI_TOOLKIT_INTERNAL_TEXT_SELECTION_POPUP_H__