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 );
127 private: // From Control
130 * @copydoc Control::OnInitialize()
132 virtual void OnInitialize();
134 private: // Implementation
137 * @brief When the cut button is pressed.
138 * @param[in] button the button pressed
139 * @return @e true to consume the event.
141 bool OnCutButtonPressed( Toolkit::Button button );
144 * @brief When the copy button is pressed.
145 * @param[in] button the button pressed
146 * @return @e true to consume the event.
148 bool OnCopyButtonPressed( Toolkit::Button button );
151 * @brief When the paste button is pressed.
152 * @param[in] button the button pressed
153 * @return @e true to consume the event.
155 bool OnPasteButtonPressed( Toolkit::Button button );
158 * @brief When the select button is pressed.
159 * @param[in] button the button pressed
160 * @return @e true to consume the event.
162 bool OnSelectButtonPressed( Toolkit::Button button );
165 * @brief When the select all button is pressed.
166 * @param[in] button the button pressed
167 * @return @e true to consume the event.
169 bool OnSelectAllButtonPressed( Toolkit::Button button );
172 * @brief When the clipboard button is pressed.
173 * @param[in] button the button pressed
174 * @return @e true to consume the event.
176 bool OnClipboardButtonPressed( Toolkit::Button button );
179 * @brief Method to set the dimension or dimension constraint on certain aspects of the Popup.
181 * @param[in] settingToCustomise The setting for the PopupCustomisations enum that can be customised
182 * @param[in] dimension The size to customise with
184 void SetDimensionToCustomise( const PopupCustomisations& settingToCustomise, const Size& dimension );
187 * @brief Method to get the dimension or dimension constraint on certain aspects of the Popup that was previously customised
189 * @param[in] setting The setting from the PopupCustomisations enum
191 Size GetDimensionToCustomise( const PopupCustomisations& setting );
194 * @brief Sets the image for the given button of the Popup.
196 * @param[in] button The button the image should be used for from the Buttons Enum.
197 * @param[in] image The image to use.
199 void SetButtonImage( Toolkit::TextSelectionPopup::Buttons button, Dali::Image image );
202 * @brief Retrieves the image of the given button used by the popup
204 * @param[in] button The button to get the image from
205 * @return The image used for that button.
207 Dali::Image GetButtonImage( Toolkit::TextSelectionPopup::Buttons button );
209 void CreateOrderedListOfPopupOptions();
211 void AddOption( const ButtonRequirement& button, bool showDivider, bool showIcons, bool showCaption );
213 std::size_t GetNumberOfEnabledOptions();
215 void AddPopupOptionsToToolbar( bool showIcons, bool showCaptions );
220 * Construct a new TextField.
222 TextSelectionPopup( TextSelectionPopupCallbackInterface* callbackInterface );
225 * A reference counted object may only be deleted by calling Unreference()
227 virtual ~TextSelectionPopup();
231 // Undefined copy constructor and assignment operators
232 TextSelectionPopup(const TextSelectionPopup&);
233 TextSelectionPopup& operator=(const TextSelectionPopup& rhs);
238 Dali::Toolkit::TextSelectionToolbar mToolbar;
240 Dali::Toolkit::TableView mTableOfButtons; // Actor which holds all the buttons, sensitivity can be set on buttons via this actor
242 // Images to be used by the Popup buttons
244 Image mCopyIconImage;
245 Image mPasteIconImage;
246 Image mClipboardIconImage;
247 Image mSelectIconImage;
248 Image mSelectAllIconImage;
250 Size mMaxSize; // Maximum size of the Popup
251 Size mMinSize; // Minimum size of the Popup
253 Size mOptionMaxSize; // Maximum size of an Option button
254 Size mOptionMinSize; // Minimum size of an Option button
255 Size mOptionDividerSize; // Size of divider line
257 std::vector<ButtonRequirement> mOrderListOfButtons; // List of buttons in the order to be displayed and a flag to indicate if needed.
259 Toolkit::TextSelectionPopup::Buttons mEnabledButtons; // stores enabled buttons
260 Toolkit::TextSelectionPopupCallbackInterface* mCallbackInterface;
262 Vector4 mLineColor; // Color of the line around the text input popup
263 Vector4 mIconColor; // Color of the popup icon.
264 Vector4 mPressedColor; // Color of the popup option when pressed.
266 // Priority of Options/Buttons in the Cut and Paste pop-up, higher priority buttons are displayed first, left to right.
267 std::size_t mSelectOptionPriority; // Position of Select Button
268 std::size_t mSelectAllOptionPriority; // Position of Select All button
269 std::size_t mCutOptionPriority; // Position of Cut button
270 std::size_t mCopyOptionPriority; // Position of Copy button
271 std::size_t mPasteOptionPriority; // Position of Paste button
272 std::size_t mClipboardOptionPriority; // Position of Clipboard button
274 bool mShowIcons:1; // Flag to show icons
275 bool mShowCaptions:1; // Flag to show text captions
279 } // namespace Internal
281 // Helpers for public-api forwarding methods
283 inline Toolkit::Internal::TextSelectionPopup& GetImpl( Toolkit::TextSelectionPopup& textSelectionPopup )
285 DALI_ASSERT_ALWAYS( textSelectionPopup );
287 Dali::RefObject& handle = textSelectionPopup.GetImplementation();
289 return static_cast<Toolkit::Internal::TextSelectionPopup&>(handle);
292 inline const Toolkit::Internal::TextSelectionPopup& GetImpl( const Toolkit::TextSelectionPopup& textSelectionPopup )
294 DALI_ASSERT_ALWAYS( textSelectionPopup );
296 const Dali::RefObject& handle = textSelectionPopup.GetImplementation();
298 return static_cast<const Toolkit::Internal::TextSelectionPopup&>(handle);
301 } // namespace Toolkit
305 #endif // __DALI_TOOLKIT_INTERNAL_TEXT_SELECTION_POPUP_H__