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();
99 * @copydoc TextEditor::ScrollStateChangedSignal()
101 Toolkit::TextEditor::ScrollStateChangedSignalType& ScrollStateChangedSignal();
103 private: // From Control
106 * @copydoc Control::OnInitialize()
108 virtual void OnInitialize();
111 * @copydoc Control::OnStyleChange()
113 virtual void OnStyleChange( Toolkit::StyleManager styleManager, StyleChange::Type change );
116 * @copydoc Control::GetNaturalSize()
118 virtual Vector3 GetNaturalSize();
121 * @copydoc Control::GetHeightForWidth()
123 virtual float GetHeightForWidth( float width );
126 * @copydoc Control::OnInitialize()
128 virtual void OnRelayout( const Vector2& size, RelayoutContainer& container );
131 * @copydoc Control::OnKeyInputFocusGained()
133 virtual void OnKeyInputFocusGained();
136 * @copydoc Control::OnKeyInputFocusLost()
138 virtual void OnKeyInputFocusLost();
141 * @copydoc Control::OnTap()
143 virtual void OnTap( const TapGesture& tap );
146 * @copydoc Control::OnPan()
148 virtual void OnPan( const PanGesture& gesture );
151 * @copydoc Control::OnLongPress()
153 virtual void OnLongPress( const LongPressGesture& gesture );
156 * @copydoc Control::OnStageConnection()
158 virtual void OnStageConnection( int depth );
161 * @copydoc Dali::CustomActorImpl::OnKeyEvent(const KeyEvent&)
163 virtual bool OnKeyEvent(const KeyEvent& event);
165 // From ControlInterface
168 * @copydoc Text::ControlInterface::RequestTextRelayout()
170 virtual void RequestTextRelayout();
172 // From EditableControlInterface
175 * @copydoc Text::ControlInterface::TextChanged()
177 virtual void TextChanged();
180 * @copydoc Text::ControlInterface::MaxLengthReached()
182 virtual void MaxLengthReached();
185 * @copydoc Text::ControlInterface::InputStyleChanged()
187 virtual void InputStyleChanged( Text::InputStyle::Mask inputStyleMask );
190 * @copydoc Text::ControlInterface::AddDecoration()
192 virtual void AddDecoration( Actor& actor, bool needsClipping );
194 private: // Implementation
197 * @copydoc Dali::Toolkit::Text::Controller::(ImfManager& imfManager, const ImfManager::ImfEventData& imfEvent)
199 ImfManager::ImfCallbackData OnImfEvent( ImfManager& imfManager, const ImfManager::ImfEventData& imfEvent );
202 * @brief Callback when Clipboard signals an item should be pasted
203 * @param[in] clipboard handle to Clipboard Event Notifier
205 void OnClipboardTextSelected( ClipboardEventNotifier& clipboard );
208 * @brief Get a Property Map for the image used for the required Handle Image
209 * @param[out] value the returned image property
210 * @param[in] handleType the type of handle
211 * @param[in] handleImageType the type of image for the given handleType
213 void GetHandleImagePropertyValue( Property::Value& value, Text::HandleType handleType, Text::HandleImageType handleImageType );
216 * @brief Callback when keyboard is shown/hidden.
218 * @param[in] keyboardShown True if keyboard is shown.
220 void KeyboardStatusChanged( bool keyboardShown );
223 * @brief update scroll bar position
225 * If text scroll is occurred, create or update scroll bar position
227 void UpdateScrollBar();
230 * @brief Callback when TextEditor is touched
232 * @param[in] actor TextEditor touched
233 * @param[in] touch Touch information
235 bool OnTouched( Actor actor, const TouchData& touch );
238 * @brief Callbacks called on idle.
240 * If there are notifications of change of input style on the queue, Toolkit::TextEditor::InputStyleChangedSignal() are emitted.
245 * @brief set RenderActor's position with new scrollPosition
247 * Apply updated scroll position or start scroll animation if VerticalScrollAnimation is enabled
249 void ApplyScrollPosition();
252 * @brief Callback function for ScrollBar indicator animation finished signal
254 * Emit ScrollBarStateChanged Signal and toggle mScrollStarted flag to false
256 void OnScrollIndicatorAnimationFinished( Animation& animation );
259 * Construct a new TextEditor.
264 * A reference counted object may only be deleted by calling Unreference()
266 virtual ~TextEditor();
268 // Undefined copy constructor and assignment operators
269 TextEditor(const TextEditor&);
270 TextEditor& operator=(const TextEditor& rhs);
273 * @brief Render view, create and attach actor(s) to this text editor.
275 void RenderText( Text::Controller::UpdateTextType updateTextType );
277 // Connection needed to re-render text, when a text editor returns to the stage.
278 void OnStageConnect( Dali::Actor actor );
282 Toolkit::TextEditor::TextChangedSignalType mTextChangedSignal;
283 Toolkit::TextEditor::InputStyleChangedSignalType mInputStyleChangedSignal;
284 Toolkit::TextEditor::ScrollStateChangedSignalType mScrollStateChangedSignal;
286 ImfManager mImfManager;
287 Text::ControllerPtr mController;
288 Text::RendererPtr mRenderer;
289 Text::DecoratorPtr mDecorator;
290 Text::TextVerticalScrollerPtr mTextVerticalScroller;
291 Toolkit::Control mStencil;
292 Toolkit::ScrollBar mScrollBar;
293 Dali::Animation mAnimation; ///< Scroll indicator Show/Hide Animation.
294 Dali::TimePeriod mAnimationPeriod;
295 std::vector<Actor> mClippingDecorationActors; ///< Decoration actors which need clipping.
297 Actor mRenderableActor;
299 CallbackBase* mIdleCallback;
301 float mAlignmentOffset;
302 float mScrollAnimationDuration;
303 int mRenderingBackend;
304 bool mHasBeenStaged:1;
305 bool mScrollAnimationEnabled:1;
306 bool mScrollBarEnabled:1;
307 bool mScrollStarted:1;
310 } // namespace Internal
312 // Helpers for public-api forwarding methods
314 inline Toolkit::Internal::TextEditor& GetImpl( Toolkit::TextEditor& textEditor )
316 DALI_ASSERT_ALWAYS(textEditor);
318 Dali::RefObject& handle = textEditor.GetImplementation();
320 return static_cast<Toolkit::Internal::TextEditor&>(handle);
323 inline const Toolkit::Internal::TextEditor& GetImpl( const Toolkit::TextEditor& textEditor )
325 DALI_ASSERT_ALWAYS(textEditor);
327 const Dali::RefObject& handle = textEditor.GetImplementation();
329 return static_cast<const Toolkit::Internal::TextEditor&>(handle);
332 } // namespace Toolkit
336 #endif // DALI_TOOLKIT_INTERNAL_TEXT_EDITOR_H