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 * @copydoc Dali::Toollkit::TextSelectionPopup::New()
102 static Toolkit::TextSelectionPopup New();
105 * @brief New constructor with provided buttons to enable.
106 * @param[in] buttonsToEnable bit mask of buttons to enable
107 * @return A handle to the TextSelectionPopup control.
109 static Toolkit::TextSelectionPopup New( Toolkit::TextSelectionPopup::Buttons buttonsToEnable );
114 * @brief Called when a property of an object of this type is set.
115 * @param[in] object The object whose property is set.
116 * @param[in] index The property index.
117 * @param[in] value The new property value.
119 static void SetProperty( BaseObject* object, Property::Index index, const Property::Value& value );
122 * @brief Called to retrieve a property of an object of this type.
124 * @param[in] object The object whose property is to be retrieved.
125 * @param[in] index The property index.
126 * @return The current value of the property.
128 static Property::Value GetProperty( BaseObject* object, Property::Index index );
130 private: // From Control
133 * @copydoc Control::OnInitialize()
135 virtual void OnInitialize();
137 private: // Implementation
140 * @brief When a popup button is pressed
141 * @param[in] button the button pressed
144 bool OnButtonPressed( Toolkit::Button button );
147 * @brief Method to set the dimension or dimension constraint on certain aspects of the Popup.
149 * @param[in] settingToCustomise The setting for the PopupCustomisations enum that can be customised
150 * @param[in] dimension The size to customise with
152 void SetDimensionToCustomise( const PopupCustomisations& settingToCustomise, const Size& dimension );
155 * @brief Method to get the dimension or dimension constraint on certain aspects of the Popup that was previously customised
157 * @param[in] setting The setting from the PopupCustomisations enum
159 Size GetDimensionToCustomise( const PopupCustomisations& setting );
162 * @brief Sets the image for the given button of the Popup.
164 * @param[in] button The button the image should be used for from the Buttons Enum.
165 * @param[in] image The image to use.
167 void SetButtonImage( Toolkit::TextSelectionPopup::Buttons button, Dali::Image image );
170 * @brief Retrieves the image of the given button used by the popup
172 * @param[in] button The button to get the image from
173 * @return The image used for that button.
175 Dali::Image GetButtonImage( Toolkit::TextSelectionPopup::Buttons button );
177 void CreateOrderedListOfPopupOptions();
179 void AddOption( const std::string& name, const std::string& caption, const Image iconImage, bool showDivider, bool showIcons, bool showCaption );
181 std::size_t GetNumberOfEnabledOptions();
183 void AddPopupOptionsToToolbar( bool showIcons, bool showCaptions );
188 * Construct a new TextField.
190 TextSelectionPopup();
193 * A reference counted object may only be deleted by calling Unreference()
195 virtual ~TextSelectionPopup();
199 // Undefined copy constructor and assignment operators
200 TextSelectionPopup(const TextSelectionPopup&);
201 TextSelectionPopup& operator=(const TextSelectionPopup& rhs);
206 Dali::Toolkit::TextSelectionToolbar mToolbar;
208 Dali::Toolkit::TableView mTableOfButtons; // Actor which holds all the buttons, sensitivity can be set on buttons via this actor
210 // Images to be used by the Popup buttons
212 Image mCopyIconImage;
213 Image mPasteIconImage;
214 Image mClipboardIconImage;
215 Image mSelectIconImage;
216 Image mSelectAllIconImage;
218 Size mMaxSize; // Maximum size of the Popup
219 Size mMinSize; // Minimum size of the Popup
221 Size mOptionMaxSize; // Maximum size of an Option button
222 Size mOptionMinSize; // Minimum size of an Option button
223 Size mOptionDividerSize; // Size of divider line
225 std::vector<ButtonRequirement> mOrderListOfButtons; // List of buttons in the order to be displayed and a flag to indicate if needed.
227 Toolkit::TextSelectionPopup::Buttons mEnabledButtons; // stores enabled buttons
229 Vector4 mLineColor; // Color of the line around the text input popup
230 Vector4 mIconColor; // Color of the popup icon.
231 Vector4 mIconPressedColor; // Color of the popup icon when pressed.
233 // Priority of Options/Buttons in the Cut and Paste pop-up, higher priority buttons are displayed first, left to right.
234 std::size_t mSelectOptionPriority; // Position of Select Button
235 std::size_t mSelectAllOptionPriority; // Position of Select All button
236 std::size_t mCutOptionPriority; // Position of Cut button
237 std::size_t mCopyOptionPriority; // Position of Copy button
238 std::size_t mPasteOptionPriority; // Position of Paste button
239 std::size_t mClipboardOptionPriority; // Position of Clipboard button
241 bool mShowIcons:1; // Flag to show icons
242 bool mShowCaptions:1; // Flag to show text captions
246 } // namespace Internal
248 // Helpers for public-api forwarding methods
250 inline Toolkit::Internal::TextSelectionPopup& GetImpl( Toolkit::TextSelectionPopup& textSelectionPopup )
252 DALI_ASSERT_ALWAYS( textSelectionPopup );
254 Dali::RefObject& handle = textSelectionPopup.GetImplementation();
256 return static_cast<Toolkit::Internal::TextSelectionPopup&>(handle);
259 inline const Toolkit::Internal::TextSelectionPopup& GetImpl( const Toolkit::TextSelectionPopup& textSelectionPopup )
261 DALI_ASSERT_ALWAYS( textSelectionPopup );
263 const Dali::RefObject& handle = textSelectionPopup.GetImplementation();
265 return static_cast<const Toolkit::Internal::TextSelectionPopup&>(handle);
268 } // namespace Toolkit
272 #endif // __DALI_TOOLKIT_INTERNAL_TEXT_SELECTION_POPUP_H__