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/table-view/table-view.h>
24 #include <dali-toolkit/devel-api/controls/text-controls/text-selection-popup.h>
27 #include <dali/public-api/actors/image-actor.h>
28 #include <dali/public-api/actors/layer.h>
44 POPUP_CLIPBOARD_BUTTON,
45 POPUP_CUT_BUTTON_ICON,
46 POPUP_COPY_BUTTON_ICON,
47 POPUP_PASTE_BUTTON_ICON,
48 POPUP_SELECT_BUTTON_ICON,
49 POPUP_SELECT_ALL_BUTTON_ICON,
54 class TextSelectionPopup : public Control
69 struct ButtonRequirement
72 : id( ButtonsEnumEnd ),
80 ButtonRequirement( Buttons buttonId,
81 std::size_t buttonPriority,
82 const std::string& buttonName,
83 const std::string& buttonCaption,
84 Dali::Image& buttonIcon,
87 priority( buttonPriority ),
89 caption( buttonCaption ),
91 enabled( buttonEnabled )
102 struct ButtonPriorityCompare
104 bool operator()( const ButtonRequirement& lhs, const ButtonRequirement& rhs ) const {
105 return lhs.priority < rhs.priority;
109 // static inline bool ButtonPriorityCompare( ButtonRequirement a, ButtonRequirement b )
111 // return a.priority < b.priority ? true : false;
115 * @copydoc Dali::Toollkit::TextSelectionPopup::New()
117 static Toolkit::TextSelectionPopup New();
122 * @brief Called when a property of an object of this type is set.
123 * @param[in] object The object whose property is set.
124 * @param[in] index The property index.
125 * @param[in] value The new property value.
127 static void SetProperty( BaseObject* object, Property::Index index, const Property::Value& value );
130 * @brief Called to retrieve a property of an object of this type.
132 * @param[in] object The object whose property is to be retrieved.
133 * @param[in] index The property index.
134 * @return The current value of the property.
136 static Property::Value GetProperty( BaseObject* object, Property::Index index );
142 private: // From Control
145 * @copydoc Control::OnInitialize()
147 virtual void OnInitialize();
150 // * @copydoc Control::GetNaturalSize()
152 // virtual Vector3 GetNaturalSize();
155 // * @copydoc Control::GetHeightForWidth()
157 // virtual float GetHeightForWidth( float width );
160 * @copydoc Control::OnInitialize()
162 virtual void OnRelayout( const Vector2& size, RelayoutContainer& container );
165 // * Received for single & double taps
167 // virtual void OnTap( const TapGesture& tap );
170 // * @copydoc Text::ControlInterface::RequestTextRelayout()
172 // virtual void RequestTextRelayout();
175 * Set max size of Popup
176 * @param[in] maxSize Size (Vector2)
178 void SetPopupMaxSize( const Size& maxSize );
181 * Get Max size of Popup
182 * @return Vector2 the max size of the Popup
184 const Dali::Vector2& GetPopupMaxSize() const;
187 * @brief Sets the image for the given part of the Popup.
189 * @param[in] part The part of the pop from the Enum PopupParts
190 * @param[in] image The image to use.
192 void SetPopupImage( PopupParts part, Dali::Image image );
195 * @brief Retrieves the image of the given part used by the popup
197 * @param[in] part The part of the popup
198 * @return The image used for that part.
200 Dali::Image GetPopupImage( PopupParts part );
202 void CreateOrderedListOfPopupOptions();
204 void CreateBackground();
206 void AddOption( Dali::Toolkit::TableView& parent, const std::string& name, const std::string& caption, const Image iconImage, bool finalOption, bool showIcons, bool showCaption, std::size_t& indexInTable );
210 void AddPopupOptions( bool createTail, bool showIcons, bool showCaptions );
212 private: // Implementation
215 * Construct a new TextField.
217 TextSelectionPopup();
220 * A reference counted object may only be deleted by calling Unreference()
222 virtual ~TextSelectionPopup();
226 // Undefined copy constructor and assignment operators
227 TextSelectionPopup(const TextSelectionPopup&);
228 TextSelectionPopup& operator=(const TextSelectionPopup& rhs);
232 Dali::Toolkit::TableView mTableOfButtons; // Actor which holds all the buttons, sensitivity can be set on buttons via this actor
233 Layer mStencilLayer; // Layer to enable clipping when buttons exceed popup
235 // Images to be used by the Popup
236 Image mBackgroundImage;
238 Image mCopyIconImage;
239 Image mPasteIconImage;
240 Image mClipboardIconImage;
241 Image mSelectIconImage;
242 Image mSelectAllIconImage;
244 ImageActor mBackground; // The background popup panel
245 ImageActor mTail; // The tail for the popup
246 ImageActor mTailEffect; //todo remove // the tail effect
247 ImageActor mTailLine; //todo remove // The border/outline around the tail
249 Size mMaxSize; // Max size of the Popup
250 Size mVisiblePopUpSize; // Visible Size of popup excluding content that needs scrolling.
251 Size mRequiredPopUpSize; // Total size of popup including any invisible margin
253 Vector4 mNinePatchMargins; // Margins between the edge of the cropped image and the nine patch rect (left, right, top, bottom).
255 Size mContentSize; // Size of Content (i.e. Buttons)
256 //Animation mAnimation; // Popup Hide/Show animation.
258 std::vector<ButtonRequirement> mOrderListOfButtons; // List of buttons in the order to be displayed and a flag to indicate if needed.
260 Vector4 mBackgroundColor; // Color of the background of the text input popup
261 Vector4 mBackgroundPressedColor; // Color of the option background.
262 Vector4 mLineColor; // Color of the line around the text input popup
263 Vector4 mIconColor; // Color of the popup icon.
264 Vector4 mIconPressedColor; // Color of the popup icon when pressed.
265 Vector4 mTextColor; // Color of the popup text.
266 Vector4 mTextPressedColor; // Color of the popup text when pressed.
268 // Priority of Options/Buttons in the Cut and Paste pop-up, higher priority buttons are displayed first, left to right.
269 std::size_t mSelectOptionPriority; // Position of Select Button
270 std::size_t mSelectAllOptionPriority; // Position of Select All button
271 std::size_t mCutOptionPriority; // Position of Cut button
272 std::size_t mCopyOptionPriority; // Position of Copy button
273 std::size_t mPasteOptionPriority; // Position of Paste button
274 std::size_t mClipboardOptionPriority; // Position of Clipboard button
276 bool mShowIcons; // Flag to show icons
277 bool mShowCaptions; // Flag to show text captions
281 } // namespace Internal
283 // Helpers for public-api forwarding methods
285 inline Toolkit::Internal::TextSelectionPopup& GetImpl( Toolkit::TextSelectionPopup& textSelectionPopup )
287 DALI_ASSERT_ALWAYS( textSelectionPopup );
289 Dali::RefObject& handle = textSelectionPopup.GetImplementation();
291 return static_cast<Toolkit::Internal::TextSelectionPopup&>(handle);
294 inline const Toolkit::Internal::TextSelectionPopup& GetImpl( const Toolkit::TextSelectionPopup& textSelectionPopup )
296 DALI_ASSERT_ALWAYS( textSelectionPopup );
298 const Dali::RefObject& handle = textSelectionPopup.GetImplementation();
300 return static_cast<const Toolkit::Internal::TextSelectionPopup&>(handle);
303 } // namespace Toolkit
307 #endif // __DALI_TOOLKIT_INTERNAL_TEXT_SELECTION_POPUP_H__