1 #ifndef DALI_TOOLKIT_INTERNAL_TEXT_EDITOR_H
2 #define DALI_TOOLKIT_INTERNAL_TEXT_EDITOR_H
5 * Copyright (c) 2017 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/devel-api/adaptor-framework/clipboard-event-notifier.h>
23 #include <dali/public-api/animation/animation.h>
26 #include <dali-toolkit/public-api/controls/control-impl.h>
27 #include <dali-toolkit/public-api/controls/scroll-bar/scroll-bar.h>
28 #include <dali-toolkit/public-api/controls/text-controls/text-editor.h>
29 #include <dali-toolkit/internal/text/decorator/text-decorator.h>
30 #include <dali-toolkit/internal/text/text-control-interface.h>
31 #include <dali-toolkit/internal/text/text-editable-control-interface.h>
32 #include <dali-toolkit/internal/text/text-controller.h>
33 #include <dali-toolkit/internal/text/text-vertical-scroller.h>
34 #include <dali-toolkit/internal/text/rendering/text-renderer.h>
46 * @brief A control which renders a long text string with styles.
48 class TextEditor : public Control, public Text::ControlInterface, public Text::EditableControlInterface
53 * @copydoc Dali::Toollkit::TextEditor::New()
55 static Toolkit::TextEditor New();
60 * @brief Called when a property of an object of this type is set.
62 * @param[in] object The object whose property is set.
63 * @param[in] index The property index.
64 * @param[in] value The new property value.
66 static void SetProperty( BaseObject* object, Property::Index index, const Property::Value& value );
69 * @brief Called to retrieve a property of an object of this type.
71 * @param[in] object The object whose property is to be retrieved.
72 * @param[in] index The property index.
73 * @return The current value of the property.
75 static Property::Value GetProperty( BaseObject* object, Property::Index index );
78 * Connects a callback function with the object's signals.
79 * @param[in] object The object providing the signal.
80 * @param[in] tracker Used to disconnect the signal.
81 * @param[in] signalName The signal to connect to.
82 * @param[in] functor A newly allocated FunctorDelegate.
83 * @return True if the signal was connected.
84 * @post If a signal was connected, ownership of functor was passed to CallbackBase. Otherwise the caller is responsible for deleting the unused functor.
86 static bool DoConnectSignal( BaseObject* object, ConnectionTrackerInterface* tracker, const std::string& signalName, FunctorDelegate* functor );
89 * @copydoc TextEditor::TextChangedSignal()
91 Toolkit::TextEditor::TextChangedSignalType& TextChangedSignal();
94 * @copydoc TextEditor::TextChangedSignal()
96 Toolkit::TextEditor::InputStyleChangedSignalType& InputStyleChangedSignal();
98 private: // From Control
101 * @copydoc Control::OnInitialize()
103 virtual void OnInitialize();
106 * @copydoc Control::OnStyleChange()
108 virtual void OnStyleChange( Toolkit::StyleManager styleManager, StyleChange::Type change );
111 * @copydoc Control::GetNaturalSize()
113 virtual Vector3 GetNaturalSize();
116 * @copydoc Control::GetHeightForWidth()
118 virtual float GetHeightForWidth( float width );
121 * @copydoc Control::OnInitialize()
123 virtual void OnRelayout( const Vector2& size, RelayoutContainer& container );
126 * @copydoc Control::OnKeyInputFocusGained()
128 virtual void OnKeyInputFocusGained();
131 * @copydoc Control::OnKeyInputFocusLost()
133 virtual void OnKeyInputFocusLost();
136 * @copydoc Control::OnTap()
138 virtual void OnTap( const TapGesture& tap );
141 * @copydoc Control::OnPan()
143 virtual void OnPan( const PanGesture& gesture );
146 * @copydoc Control::OnLongPress()
148 virtual void OnLongPress( const LongPressGesture& gesture );
151 * @copydoc Control::OnStageConnection()
153 virtual void OnStageConnection( int depth );
156 * @copydoc Dali::CustomActorImpl::OnKeyEvent(const KeyEvent&)
158 virtual bool OnKeyEvent(const KeyEvent& event);
160 // From ControlInterface
163 * @copydoc Text::ControlInterface::RequestTextRelayout()
165 virtual void RequestTextRelayout();
167 // From EditableControlInterface
170 * @copydoc Text::ControlInterface::TextChanged()
172 virtual void TextChanged();
175 * @copydoc Text::ControlInterface::MaxLengthReached()
177 virtual void MaxLengthReached();
180 * @copydoc Text::ControlInterface::InputStyleChanged()
182 virtual void InputStyleChanged( Text::InputStyle::Mask inputStyleMask );
185 * @copydoc Text::ControlInterface::AddDecoration()
187 virtual void AddDecoration( Actor& actor, bool needsClipping );
189 private: // Implementation
192 * @copydoc Dali::Toolkit::Text::Controller::(ImfManager& imfManager, const ImfManager::ImfEventData& imfEvent)
194 ImfManager::ImfCallbackData OnImfEvent( ImfManager& imfManager, const ImfManager::ImfEventData& imfEvent );
197 * @brief Callback when Clipboard signals an item should be pasted
198 * @param[in] clipboard handle to Clipboard Event Notifier
200 void OnClipboardTextSelected( ClipboardEventNotifier& clipboard );
203 * @brief Get a Property Map for the image used for the required Handle Image
204 * @param[out] value the returned image property
205 * @param[in] handleType the type of handle
206 * @param[in] handleImageType the type of image for the given handleType
208 void GetHandleImagePropertyValue( Property::Value& value, Text::HandleType handleType, Text::HandleImageType handleImageType );
211 * @brief Callback when keyboard is shown/hidden.
213 * @param[in] keyboardShown True if keyboard is shown.
215 void KeyboardStatusChanged( bool keyboardShown );
218 * @brief update scroll bar position
220 * If text scroll is occurred, create or update scroll bar position
222 void UpdateScrollBar();
225 * @brief Callback when TextEditor is touched
227 * @param[in] actor TextEditor touched
228 * @param[in] touch Touch information
230 bool OnTouched( Actor actor, const TouchData& touch );
233 * @brief Callbacks called on idle.
235 * If there are notifications of change of input style on the queue, Toolkit::TextEditor::InputStyleChangedSignal() are emitted.
240 * @brief set RenderActor's position with new scrollPosition
242 * Apply updated scroll position or start scroll animation if VerticalScrollAnimation is enabled
244 void ApplyScrollPosition();
247 * Construct a new TextEditor.
252 * A reference counted object may only be deleted by calling Unreference()
254 virtual ~TextEditor();
256 // Undefined copy constructor and assignment operators
257 TextEditor(const TextEditor&);
258 TextEditor& operator=(const TextEditor& rhs);
261 * @brief Render view, create and attach actor(s) to this text editor.
263 void RenderText( Text::Controller::UpdateTextType updateTextType );
265 // Connection needed to re-render text, when a text editor returns to the stage.
266 void OnStageConnect( Dali::Actor actor );
270 Toolkit::TextEditor::TextChangedSignalType mTextChangedSignal;
271 Toolkit::TextEditor::InputStyleChangedSignalType mInputStyleChangedSignal;
273 ImfManager mImfManager;
274 Text::ControllerPtr mController;
275 Text::RendererPtr mRenderer;
276 Text::DecoratorPtr mDecorator;
277 Text::TextVerticalScrollerPtr mTextVerticalScroller;
278 Toolkit::Control mStencil;
279 Toolkit::ScrollBar mScrollBar;
280 Dali::Animation mAnimation; ///< Scroll indicator Show/Hide Animation.
281 Dali::TimePeriod mAnimationPeriod;
282 std::vector<Actor> mClippingDecorationActors; ///< Decoration actors which need clipping.
284 Actor mRenderableActor;
285 CallbackBase* mIdleCallback;
287 float mAlignmentOffset;
288 float mScrollAnimationDuration;
289 int mRenderingBackend;
290 bool mHasBeenStaged:1;
291 bool mScrollAnimationEnabled:1;
292 bool mScrollBarEnabled:1;
295 } // namespace Internal
297 // Helpers for public-api forwarding methods
299 inline Toolkit::Internal::TextEditor& GetImpl( Toolkit::TextEditor& textEditor )
301 DALI_ASSERT_ALWAYS(textEditor);
303 Dali::RefObject& handle = textEditor.GetImplementation();
305 return static_cast<Toolkit::Internal::TextEditor&>(handle);
308 inline const Toolkit::Internal::TextEditor& GetImpl( const Toolkit::TextEditor& textEditor )
310 DALI_ASSERT_ALWAYS(textEditor);
312 const Dali::RefObject& handle = textEditor.GetImplementation();
314 return static_cast<const Toolkit::Internal::TextEditor&>(handle);
317 } // namespace Toolkit
321 #endif // DALI_TOOLKIT_INTERNAL_TEXT_EDITOR_H