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 * @return A handle to the TextSelectionPopup control.
104 static Toolkit::TextSelectionPopup New( Toolkit::TextSelectionPopup::Buttons buttonsToEnable );
109 * @brief Called when a property of an object of this type is set.
110 * @param[in] object The object whose property is set.
111 * @param[in] index The property index.
112 * @param[in] value The new property value.
114 static void SetProperty( BaseObject* object, Property::Index index, const Property::Value& value );
117 * @brief Called to retrieve a property of an object of this type.
119 * @param[in] object The object whose property is to be retrieved.
120 * @param[in] index The property index.
121 * @return The current value of the property.
123 static Property::Value GetProperty( BaseObject* object, Property::Index index );
125 private: // From Control
128 * @copydoc Control::OnInitialize()
130 virtual void OnInitialize();
132 private: // Implementation
135 * @brief When a popup button is pressed
136 * @param[in] button the button pressed
139 bool OnButtonPressed( Toolkit::Button button );
142 * @brief Method to set the dimension or dimension constraint on certain aspects of the Popup.
144 * @param[in] settingToCustomise The setting for the PopupCustomisations enum that can be customised
145 * @param[in] dimension The size to customise with
147 void SetDimensionToCustomise( const PopupCustomisations& settingToCustomise, const Size& dimension );
150 * @brief Method to get the dimension or dimension constraint on certain aspects of the Popup that was previously customised
152 * @param[in] setting The setting from the PopupCustomisations enum
154 Size GetDimensionToCustomise( const PopupCustomisations& setting );
157 * @brief Sets the image for the given button of the Popup.
159 * @param[in] button The button the image should be used for from the Buttons Enum.
160 * @param[in] image The image to use.
162 void SetButtonImage( Toolkit::TextSelectionPopup::Buttons button, Dali::Image image );
165 * @brief Retrieves the image of the given button used by the popup
167 * @param[in] button The button to get the image from
168 * @return The image used for that button.
170 Dali::Image GetButtonImage( Toolkit::TextSelectionPopup::Buttons button );
172 void CreateOrderedListOfPopupOptions();
174 void AddOption( const std::string& name, const std::string& caption, const Image iconImage, bool showDivider, bool showIcons, bool showCaption );
176 std::size_t GetNumberOfEnabledOptions();
178 void AddPopupOptionsToToolbar( bool showIcons, bool showCaptions );
183 * Construct a new TextField.
185 TextSelectionPopup();
188 * A reference counted object may only be deleted by calling Unreference()
190 virtual ~TextSelectionPopup();
194 // Undefined copy constructor and assignment operators
195 TextSelectionPopup(const TextSelectionPopup&);
196 TextSelectionPopup& operator=(const TextSelectionPopup& rhs);
201 Dali::Toolkit::TextSelectionToolbar mToolbar;
203 Dali::Toolkit::TableView mTableOfButtons; // Actor which holds all the buttons, sensitivity can be set on buttons via this actor
205 // Images to be used by the Popup buttons
207 Image mCopyIconImage;
208 Image mPasteIconImage;
209 Image mClipboardIconImage;
210 Image mSelectIconImage;
211 Image mSelectAllIconImage;
213 Size mMaxSize; // Maximum size of the Popup
214 Size mMinSize; // Minimum size of the Popup
216 Size mOptionMaxSize; // Maximum size of an Option button
217 Size mOptionMinSize; // Minimum size of an Option button
218 Size mOptionDividerSize; // Size of divider line
220 std::vector<ButtonRequirement> mOrderListOfButtons; // List of buttons in the order to be displayed and a flag to indicate if needed.
222 Toolkit::TextSelectionPopup::Buttons mEnabledButtons; // stores enabled buttons
224 Vector4 mLineColor; // Color of the line around the text input popup
225 Vector4 mIconColor; // Color of the popup icon.
226 Vector4 mPressedColor; // Color of the popup option when pressed.
228 // Priority of Options/Buttons in the Cut and Paste pop-up, higher priority buttons are displayed first, left to right.
229 std::size_t mSelectOptionPriority; // Position of Select Button
230 std::size_t mSelectAllOptionPriority; // Position of Select All button
231 std::size_t mCutOptionPriority; // Position of Cut button
232 std::size_t mCopyOptionPriority; // Position of Copy button
233 std::size_t mPasteOptionPriority; // Position of Paste button
234 std::size_t mClipboardOptionPriority; // Position of Clipboard button
236 bool mShowIcons:1; // Flag to show icons
237 bool mShowCaptions:1; // Flag to show text captions
241 } // namespace Internal
243 // Helpers for public-api forwarding methods
245 inline Toolkit::Internal::TextSelectionPopup& GetImpl( Toolkit::TextSelectionPopup& textSelectionPopup )
247 DALI_ASSERT_ALWAYS( textSelectionPopup );
249 Dali::RefObject& handle = textSelectionPopup.GetImplementation();
251 return static_cast<Toolkit::Internal::TextSelectionPopup&>(handle);
254 inline const Toolkit::Internal::TextSelectionPopup& GetImpl( const Toolkit::TextSelectionPopup& textSelectionPopup )
256 DALI_ASSERT_ALWAYS( textSelectionPopup );
258 const Dali::RefObject& handle = textSelectionPopup.GetImplementation();
260 return static_cast<const Toolkit::Internal::TextSelectionPopup&>(handle);
263 } // namespace Toolkit
267 #endif // __DALI_TOOLKIT_INTERNAL_TEXT_SELECTION_POPUP_H__