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] buttonsToEnable bit mask of buttons to enable
101 * @param[in] callbackInterface The text popup callback interface which receives the button click callbacks.
102 * @return A handle to the TextSelectionPopup control.
104 static Toolkit::TextSelectionPopup New( Toolkit::TextSelectionPopup::Buttons buttonsToEnable,
105 TextSelectionPopupCallbackInterface* callbackInterface );
110 * @brief Called when a property of an object of this type is set.
111 * @param[in] object The object whose property is set.
112 * @param[in] index The property index.
113 * @param[in] value The new property value.
115 static void SetProperty( BaseObject* object, Property::Index index, const Property::Value& value );
118 * @brief Called to retrieve a property of an object of this type.
120 * @param[in] object The object whose property is to be retrieved.
121 * @param[in] index The property index.
122 * @return The current value of the property.
124 static Property::Value GetProperty( BaseObject* object, Property::Index index );
127 * @copydoc Toolkit::TextSelectionPopup::RaiseAbove()
129 void RaiseAbove( Layer target );
132 * @copydoc Toolkit::TextSelectionPopup::ShowPopup()
136 private: // From Control
139 * @copydoc Control::OnInitialize()
141 virtual void OnInitialize();
144 * @copydoc Control::OnStageConnection()
146 virtual void OnStageConnection( int depth );
148 private: // Implementation
151 * @brief When the cut button is pressed.
152 * @param[in] button the button pressed
153 * @return @e true to consume the event.
155 bool OnCutButtonPressed( Toolkit::Button button );
158 * @brief When the copy button is pressed.
159 * @param[in] button the button pressed
160 * @return @e true to consume the event.
162 bool OnCopyButtonPressed( Toolkit::Button button );
165 * @brief When the paste button is pressed.
166 * @param[in] button the button pressed
167 * @return @e true to consume the event.
169 bool OnPasteButtonPressed( Toolkit::Button button );
172 * @brief When the select button is pressed.
173 * @param[in] button the button pressed
174 * @return @e true to consume the event.
176 bool OnSelectButtonPressed( Toolkit::Button button );
179 * @brief When the select all button is pressed.
180 * @param[in] button the button pressed
181 * @return @e true to consume the event.
183 bool OnSelectAllButtonPressed( Toolkit::Button button );
186 * @brief When the clipboard button is pressed.
187 * @param[in] button the button pressed
188 * @return @e true to consume the event.
190 bool OnClipboardButtonPressed( Toolkit::Button button );
193 * @brief Method to set the dimension or dimension constraint on certain aspects of the Popup.
195 * @param[in] settingToCustomise The setting for the PopupCustomisations enum that can be customised
196 * @param[in] dimension The size to customise with
198 void SetDimensionToCustomise( const PopupCustomisations& settingToCustomise, const Size& dimension );
201 * @brief Method to get the dimension or dimension constraint on certain aspects of the Popup that was previously customised
203 * @param[in] setting The setting from the PopupCustomisations enum
205 Size GetDimensionToCustomise( const PopupCustomisations& setting );
208 * @brief Sets the image for the given button of the Popup.
210 * @param[in] button The button the image should be used for from the Buttons Enum.
211 * @param[in] image The image to use.
213 void SetButtonImage( Toolkit::TextSelectionPopup::Buttons button, Dali::Image image );
216 * @brief Retrieves the image of the given button used by the popup
218 * @param[in] button The button to get the image from
219 * @return The image used for that button.
221 Dali::Image GetButtonImage( Toolkit::TextSelectionPopup::Buttons button );
224 * @brief Sets the image for the pressed state of a popup option.
226 * @param[in] filename The image filename to use.
228 void SetPressedImage( const std::string& filename);
231 * @brief Gets the image used for the pressed state of a popup option.
233 * @return The image filename used.
235 std::string GetPressedImage() const;
237 void CreateOrderedListOfPopupOptions();
239 void AddOption( const ButtonRequirement& button, bool showDivider, bool showIcons, bool showCaption );
241 std::size_t GetNumberOfEnabledOptions();
243 void AddPopupOptionsToToolbar( bool showIcons, bool showCaptions );
248 * Construct a new TextField.
250 TextSelectionPopup( TextSelectionPopupCallbackInterface* callbackInterface );
253 * A reference counted object may only be deleted by calling Unreference()
255 virtual ~TextSelectionPopup();
259 // Undefined copy constructor and assignment operators
260 TextSelectionPopup(const TextSelectionPopup&);
261 TextSelectionPopup& operator=(const TextSelectionPopup& rhs);
266 Dali::Toolkit::TextSelectionToolbar mToolbar;
268 Dali::Toolkit::TableView mTableOfButtons; // Actor which holds all the buttons, sensitivity can be set on buttons via this actor
270 // Images to be used by the Popup buttons
272 Image mCopyIconImage;
273 Image mPasteIconImage;
274 Image mClipboardIconImage;
275 Image mSelectIconImage;
276 Image mSelectAllIconImage;
278 Size mOptionMaxSize; // Maximum size of an Option button
279 Size mOptionMinSize; // Minimum size of an Option button
280 Size mOptionDividerSize; // Size of divider line
282 std::vector<ButtonRequirement> mOrderListOfButtons; // List of buttons in the order to be displayed and a flag to indicate if needed.
284 Toolkit::TextSelectionPopup::Buttons mEnabledButtons; // stores enabled buttons
285 Toolkit::TextSelectionPopupCallbackInterface* mCallbackInterface;
287 std::string mPressedImage; // Image used for the popup option when pressed.
288 Vector4 mPressedColor; // Color of the popup option when pressed.
289 Vector4 mDividerColor; // Color of the divider between buttons
290 Vector4 mIconColor; // Color of the popup icon.
292 // Priority of Options/Buttons in the Cut and Paste pop-up, higher priority buttons are displayed first, left to right.
293 std::size_t mSelectOptionPriority; // Position of Select Button
294 std::size_t mSelectAllOptionPriority; // Position of Select All button
295 std::size_t mCutOptionPriority; // Position of Cut button
296 std::size_t mCopyOptionPriority; // Position of Copy button
297 std::size_t mPasteOptionPriority; // Position of Paste button
298 std::size_t mClipboardOptionPriority; // Position of Clipboard button
300 bool mShowIcons:1; // Flag to show icons
301 bool mShowCaptions:1; // Flag to show text captions
305 } // namespace Internal
307 // Helpers for public-api forwarding methods
309 inline Toolkit::Internal::TextSelectionPopup& GetImpl( Toolkit::TextSelectionPopup& textSelectionPopup )
311 DALI_ASSERT_ALWAYS( textSelectionPopup );
313 Dali::RefObject& handle = textSelectionPopup.GetImplementation();
315 return static_cast<Toolkit::Internal::TextSelectionPopup&>(handle);
318 inline const Toolkit::Internal::TextSelectionPopup& GetImpl( const Toolkit::TextSelectionPopup& textSelectionPopup )
320 DALI_ASSERT_ALWAYS( textSelectionPopup );
322 const Dali::RefObject& handle = textSelectionPopup.GetImplementation();
324 return static_cast<const Toolkit::Internal::TextSelectionPopup&>(handle);
327 } // namespace Toolkit
331 #endif // __DALI_TOOLKIT_INTERNAL_TEXT_SELECTION_POPUP_H__