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
55 class TextSelectionPopup : public Control
59 struct ButtonRequirement
62 : id( Toolkit::TextSelectionPopup::NONE ),
70 ButtonRequirement( Toolkit::TextSelectionPopup::Buttons buttonId,
71 std::size_t buttonPriority,
72 const std::string& buttonName,
73 const std::string& buttonCaption,
74 Dali::Image& buttonIcon,
77 priority( buttonPriority ),
79 caption( buttonCaption ),
81 enabled( buttonEnabled )
84 Toolkit::TextSelectionPopup::Buttons id;
92 struct ButtonPriorityCompare
94 bool operator()( const ButtonRequirement& lhs, const ButtonRequirement& rhs ) const {
95 return lhs.priority < rhs.priority;
100 * @brief New constructor with provided buttons to enable.
101 * @param[in] buttonsToEnable bit mask of buttons to enable
102 * @param[in] callbackInterface The text popup callback interface which receives the button click callbacks.
103 * @return A handle to the TextSelectionPopup control.
105 static Toolkit::TextSelectionPopup New( Toolkit::TextSelectionPopup::Buttons buttonsToEnable,
106 TextSelectionPopupCallbackInterface* callbackInterface );
111 * @brief Called when a property of an object of this type is set.
112 * @param[in] object The object whose property is set.
113 * @param[in] index The property index.
114 * @param[in] value The new property value.
116 static void SetProperty( BaseObject* object, Property::Index index, const Property::Value& value );
119 * @brief Called to retrieve a property of an object of this type.
121 * @param[in] object The object whose property is to be retrieved.
122 * @param[in] index The property index.
123 * @return The current value of the property.
125 static Property::Value GetProperty( BaseObject* object, Property::Index index );
128 * @copydoc Toolkit::TextSelectionPopup::RaiseAbove()
130 void RaiseAbove( Layer target );
132 private: // From Control
135 * @copydoc Control::OnInitialize()
137 virtual void OnInitialize();
140 * @copydoc Control::OnStageConnection()
142 virtual void OnStageConnection( int depth );
144 private: // Implementation
147 * @brief When the cut button is pressed.
148 * @param[in] button the button pressed
149 * @return @e true to consume the event.
151 bool OnCutButtonPressed( Toolkit::Button button );
154 * @brief When the copy button is pressed.
155 * @param[in] button the button pressed
156 * @return @e true to consume the event.
158 bool OnCopyButtonPressed( Toolkit::Button button );
161 * @brief When the paste button is pressed.
162 * @param[in] button the button pressed
163 * @return @e true to consume the event.
165 bool OnPasteButtonPressed( Toolkit::Button button );
168 * @brief When the select button is pressed.
169 * @param[in] button the button pressed
170 * @return @e true to consume the event.
172 bool OnSelectButtonPressed( Toolkit::Button button );
175 * @brief When the select all button is pressed.
176 * @param[in] button the button pressed
177 * @return @e true to consume the event.
179 bool OnSelectAllButtonPressed( Toolkit::Button button );
182 * @brief When the clipboard button is pressed.
183 * @param[in] button the button pressed
184 * @return @e true to consume the event.
186 bool OnClipboardButtonPressed( Toolkit::Button button );
189 * @brief Method to set the dimension or dimension constraint on certain aspects of the Popup.
191 * @param[in] settingToCustomise The setting for the PopupCustomisations enum that can be customised
192 * @param[in] dimension The size to customise with
194 void SetDimensionToCustomise( const PopupCustomisations& settingToCustomise, const Size& dimension );
197 * @brief Method to get the dimension or dimension constraint on certain aspects of the Popup that was previously customised
199 * @param[in] setting The setting from the PopupCustomisations enum
201 Size GetDimensionToCustomise( const PopupCustomisations& setting );
204 * @brief Sets the image for the given button of the Popup.
206 * @param[in] button The button the image should be used for from the Buttons Enum.
207 * @param[in] image The image to use.
209 void SetButtonImage( Toolkit::TextSelectionPopup::Buttons button, Dali::Image image );
212 * @brief Retrieves the image of the given button used by the popup
214 * @param[in] button The button to get the image from
215 * @return The image used for that button.
217 Dali::Image GetButtonImage( Toolkit::TextSelectionPopup::Buttons button );
219 void CreateOrderedListOfPopupOptions();
221 void AddOption( const ButtonRequirement& button, bool showDivider, bool showIcons, bool showCaption );
223 std::size_t GetNumberOfEnabledOptions();
225 void AddPopupOptionsToToolbar( bool showIcons, bool showCaptions );
230 * Construct a new TextField.
232 TextSelectionPopup( TextSelectionPopupCallbackInterface* callbackInterface );
235 * A reference counted object may only be deleted by calling Unreference()
237 virtual ~TextSelectionPopup();
241 // Undefined copy constructor and assignment operators
242 TextSelectionPopup(const TextSelectionPopup&);
243 TextSelectionPopup& operator=(const TextSelectionPopup& rhs);
248 Dali::Toolkit::TextSelectionToolbar mToolbar;
250 Dali::Toolkit::TableView mTableOfButtons; // Actor which holds all the buttons, sensitivity can be set on buttons via this actor
252 // Images to be used by the Popup buttons
254 Image mCopyIconImage;
255 Image mPasteIconImage;
256 Image mClipboardIconImage;
257 Image mSelectIconImage;
258 Image mSelectAllIconImage;
260 Size mMaxSize; // Maximum size of the Popup
261 Size mMinSize; // Minimum size of the Popup
263 Size mOptionMaxSize; // Maximum size of an Option button
264 Size mOptionMinSize; // Minimum size of an Option button
265 Size mOptionDividerSize; // Size of divider line
267 std::vector<ButtonRequirement> mOrderListOfButtons; // List of buttons in the order to be displayed and a flag to indicate if needed.
269 Toolkit::TextSelectionPopup::Buttons mEnabledButtons; // stores enabled buttons
270 Toolkit::TextSelectionPopupCallbackInterface* mCallbackInterface;
272 Vector4 mDividerColor; // Color of the divider between buttons
273 Vector4 mIconColor; // Color of the popup icon.
274 Vector4 mPressedColor; // Color of the popup option when pressed.
276 // Priority of Options/Buttons in the Cut and Paste pop-up, higher priority buttons are displayed first, left to right.
277 std::size_t mSelectOptionPriority; // Position of Select Button
278 std::size_t mSelectAllOptionPriority; // Position of Select All button
279 std::size_t mCutOptionPriority; // Position of Cut button
280 std::size_t mCopyOptionPriority; // Position of Copy button
281 std::size_t mPasteOptionPriority; // Position of Paste button
282 std::size_t mClipboardOptionPriority; // Position of Clipboard button
284 bool mShowIcons:1; // Flag to show icons
285 bool mShowCaptions:1; // Flag to show text captions
289 } // namespace Internal
291 // Helpers for public-api forwarding methods
293 inline Toolkit::Internal::TextSelectionPopup& GetImpl( Toolkit::TextSelectionPopup& textSelectionPopup )
295 DALI_ASSERT_ALWAYS( textSelectionPopup );
297 Dali::RefObject& handle = textSelectionPopup.GetImplementation();
299 return static_cast<Toolkit::Internal::TextSelectionPopup&>(handle);
302 inline const Toolkit::Internal::TextSelectionPopup& GetImpl( const Toolkit::TextSelectionPopup& textSelectionPopup )
304 DALI_ASSERT_ALWAYS( textSelectionPopup );
306 const Dali::RefObject& handle = textSelectionPopup.GetImplementation();
308 return static_cast<const Toolkit::Internal::TextSelectionPopup&>(handle);
311 } // namespace Toolkit
315 #endif // __DALI_TOOLKIT_INTERNAL_TEXT_SELECTION_POPUP_H__