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/devel-api/adaptor-framework/input-method-context.h>
24 #include <dali/public-api/animation/animation.h>
27 #include <dali-toolkit/public-api/controls/control-impl.h>
28 #include <dali-toolkit/public-api/controls/scroll-bar/scroll-bar.h>
29 #include <dali-toolkit/public-api/controls/text-controls/text-editor.h>
30 #include <dali-toolkit/internal/text/decorator/text-decorator.h>
31 #include <dali-toolkit/internal/text/text-control-interface.h>
32 #include <dali-toolkit/internal/text/text-editable-control-interface.h>
33 #include <dali-toolkit/internal/text/text-controller.h>
34 #include <dali-toolkit/internal/text/text-vertical-scroller.h>
35 #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 * @copydoc Dali::Toollkit::TextEditor::GetInputMethodContext()
80 InputMethodContext GetInputMethodContext();
83 * Connects a callback function with the object's signals.
84 * @param[in] object The object providing the signal.
85 * @param[in] tracker Used to disconnect the signal.
86 * @param[in] signalName The signal to connect to.
87 * @param[in] functor A newly allocated FunctorDelegate.
88 * @return True if the signal was connected.
89 * @post If a signal was connected, ownership of functor was passed to CallbackBase. Otherwise the caller is responsible for deleting the unused functor.
91 static bool DoConnectSignal( BaseObject* object, ConnectionTrackerInterface* tracker, const std::string& signalName, FunctorDelegate* functor );
94 * @copydoc TextEditor::TextChangedSignal()
96 Toolkit::TextEditor::TextChangedSignalType& TextChangedSignal();
99 * @copydoc TextEditor::TextChangedSignal()
101 Toolkit::TextEditor::InputStyleChangedSignalType& InputStyleChangedSignal();
104 * @copydoc TextEditor::ScrollStateChangedSignal()
106 Toolkit::TextEditor::ScrollStateChangedSignalType& ScrollStateChangedSignal();
108 private: // From Control
111 * @copydoc Control::OnInitialize()
113 virtual void OnInitialize();
116 * @copydoc Control::OnStyleChange()
118 virtual void OnStyleChange( Toolkit::StyleManager styleManager, StyleChange::Type change );
121 * @copydoc Control::GetNaturalSize()
123 virtual Vector3 GetNaturalSize();
126 * @copydoc Control::GetHeightForWidth()
128 virtual float GetHeightForWidth( float width );
131 * @copydoc Control::OnInitialize()
133 virtual void OnRelayout( const Vector2& size, RelayoutContainer& container );
136 * @copydoc Control::OnKeyInputFocusGained()
138 virtual void OnKeyInputFocusGained();
141 * @copydoc Control::OnKeyInputFocusLost()
143 virtual void OnKeyInputFocusLost();
146 * @copydoc Control::OnTap()
148 virtual void OnTap( const TapGesture& tap );
151 * @copydoc Control::OnPan()
153 virtual void OnPan( const PanGesture& gesture );
156 * @copydoc Control::OnLongPress()
158 virtual void OnLongPress( const LongPressGesture& gesture );
161 * @copydoc Control::OnStageConnection()
163 virtual void OnStageConnection( int depth );
166 * @copydoc Dali::CustomActorImpl::OnKeyEvent(const KeyEvent&)
168 virtual bool OnKeyEvent(const KeyEvent& event);
170 // From ControlInterface
173 * @copydoc Text::ControlInterface::RequestTextRelayout()
175 virtual void RequestTextRelayout();
177 // From EditableControlInterface
180 * @copydoc Text::ControlInterface::TextChanged()
182 virtual void TextChanged();
185 * @copydoc Text::ControlInterface::MaxLengthReached()
187 virtual void MaxLengthReached();
190 * @copydoc Text::ControlInterface::InputStyleChanged()
192 virtual void InputStyleChanged( Text::InputStyle::Mask inputStyleMask );
195 * @copydoc Text::ControlInterface::AddDecoration()
197 virtual void AddDecoration( Actor& actor, bool needsClipping );
199 private: // Implementation
202 * @copydoc Dali::Toolkit::Text::Controller::(InputMethodContext& inputMethodContext, const InputMethodContext::EventData& inputMethodContextEvent)
204 InputMethodContext::CallbackData OnInputMethodContextEvent( InputMethodContext& inputMethodContext, const InputMethodContext::EventData& inputMethodContextEvent );
207 * @brief Callback when Clipboard signals an item should be pasted
208 * @param[in] clipboard handle to Clipboard Event Notifier
210 void OnClipboardTextSelected( ClipboardEventNotifier& clipboard );
213 * @brief Get a Property Map for the image used for the required Handle Image
214 * @param[out] value the returned image property
215 * @param[in] handleType the type of handle
216 * @param[in] handleImageType the type of image for the given handleType
218 void GetHandleImagePropertyValue( Property::Value& value, Text::HandleType handleType, Text::HandleImageType handleImageType );
221 * @brief Callback when keyboard is shown/hidden.
223 * @param[in] keyboardShown True if keyboard is shown.
225 void KeyboardStatusChanged( bool keyboardShown );
228 * @brief update scroll bar position
230 * If text scroll is occurred, create or update scroll bar position
232 void UpdateScrollBar();
235 * @brief Callback when TextEditor is touched
237 * @param[in] actor TextEditor touched
238 * @param[in] touch Touch information
240 bool OnTouched( Actor actor, const TouchData& touch );
243 * @brief Callbacks called on idle.
245 * If there are notifications of change of input style on the queue, Toolkit::TextEditor::InputStyleChangedSignal() are emitted.
250 * @brief set RenderActor's position with new scrollPosition
252 * Apply updated scroll position or start scroll animation if VerticalScrollAnimation is enabled
254 void ApplyScrollPosition();
257 * @brief Callback function for ScrollBar indicator animation finished signal
259 * Emit ScrollBarStateChanged Signal and toggle mScrollStarted flag to false
261 void OnScrollIndicatorAnimationFinished( Animation& animation );
264 * Construct a new TextEditor.
269 * A reference counted object may only be deleted by calling Unreference()
271 virtual ~TextEditor();
273 // Undefined copy constructor and assignment operators
274 TextEditor(const TextEditor&);
275 TextEditor& operator=(const TextEditor& rhs);
278 * @brief Render view, create and attach actor(s) to this text editor.
280 void RenderText( Text::Controller::UpdateTextType updateTextType );
282 // Connection needed to re-render text, when a text editor returns to the stage.
283 void OnStageConnect( Dali::Actor actor );
287 Toolkit::TextEditor::TextChangedSignalType mTextChangedSignal;
288 Toolkit::TextEditor::InputStyleChangedSignalType mInputStyleChangedSignal;
289 Toolkit::TextEditor::ScrollStateChangedSignalType mScrollStateChangedSignal;
291 InputMethodContext mInputMethodContext;
292 Text::ControllerPtr mController;
293 Text::RendererPtr mRenderer;
294 Text::DecoratorPtr mDecorator;
295 Text::TextVerticalScrollerPtr mTextVerticalScroller;
296 Toolkit::Control mStencil;
297 Toolkit::ScrollBar mScrollBar;
298 Dali::Animation mAnimation; ///< Scroll indicator Show/Hide Animation.
299 Dali::TimePeriod mAnimationPeriod;
300 std::vector<Actor> mClippingDecorationActors; ///< Decoration actors which need clipping.
302 Actor mRenderableActor;
304 CallbackBase* mIdleCallback;
306 float mAlignmentOffset;
307 float mScrollAnimationDuration;
309 int mRenderingBackend;
310 bool mHasBeenStaged:1;
311 bool mScrollAnimationEnabled:1;
312 bool mScrollBarEnabled:1;
313 bool mScrollStarted:1;
316 } // namespace Internal
318 // Helpers for public-api forwarding methods
320 inline Toolkit::Internal::TextEditor& GetImpl( Toolkit::TextEditor& textEditor )
322 DALI_ASSERT_ALWAYS(textEditor);
324 Dali::RefObject& handle = textEditor.GetImplementation();
326 return static_cast<Toolkit::Internal::TextEditor&>(handle);
329 inline const Toolkit::Internal::TextEditor& GetImpl( const Toolkit::TextEditor& textEditor )
331 DALI_ASSERT_ALWAYS(textEditor);
333 const Dali::RefObject& handle = textEditor.GetImplementation();
335 return static_cast<const Toolkit::Internal::TextEditor&>(handle);
338 } // namespace Toolkit
342 #endif // DALI_TOOLKIT_INTERNAL_TEXT_EDITOR_H