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>
25 #include <dali/public-api/common/stage.h>
28 #include <dali-toolkit/public-api/controls/control-impl.h>
29 #include <dali-toolkit/public-api/controls/scroll-bar/scroll-bar.h>
30 #include <dali-toolkit/public-api/controls/text-controls/text-editor.h>
31 #include <dali-toolkit/internal/text/decorator/text-decorator.h>
32 #include <dali-toolkit/internal/text/text-control-interface.h>
33 #include <dali-toolkit/internal/text/text-editable-control-interface.h>
34 #include <dali-toolkit/internal/text/text-controller.h>
35 #include <dali-toolkit/internal/text/text-vertical-scroller.h>
36 #include <dali-toolkit/internal/text/rendering/text-renderer.h>
47 * @brief A control which renders a long text string with styles.
49 class TextEditor : public Control, public Text::ControlInterface, public Text::EditableControlInterface
54 * @copydoc Dali::Toollkit::TextEditor::New()
56 static Toolkit::TextEditor New();
61 * @brief Called when a property of an object of this type is set.
63 * @param[in] object The object whose property is set.
64 * @param[in] index The property index.
65 * @param[in] value The new property value.
67 static void SetProperty( BaseObject* object, Property::Index index, const Property::Value& value );
70 * @brief Called to retrieve a property of an object of this type.
72 * @param[in] object The object whose property is to be retrieved.
73 * @param[in] index The property index.
74 * @return The current value of the property.
76 static Property::Value GetProperty( BaseObject* object, Property::Index index );
79 * @copydoc Dali::Toollkit::TextEditor::GetInputMethodContext()
81 InputMethodContext GetInputMethodContext();
84 * Connects a callback function with the object's signals.
85 * @param[in] object The object providing the signal.
86 * @param[in] tracker Used to disconnect the signal.
87 * @param[in] signalName The signal to connect to.
88 * @param[in] functor A newly allocated FunctorDelegate.
89 * @return True if the signal was connected.
90 * @post If a signal was connected, ownership of functor was passed to CallbackBase. Otherwise the caller is responsible for deleting the unused functor.
92 static bool DoConnectSignal( BaseObject* object, ConnectionTrackerInterface* tracker, const std::string& signalName, FunctorDelegate* functor );
95 * @copydoc TextEditor::TextChangedSignal()
97 Toolkit::TextEditor::TextChangedSignalType& TextChangedSignal();
100 * @copydoc TextEditor::TextChangedSignal()
102 Toolkit::TextEditor::InputStyleChangedSignalType& InputStyleChangedSignal();
105 * @copydoc TextEditor::ScrollStateChangedSignal()
107 Toolkit::TextEditor::ScrollStateChangedSignalType& ScrollStateChangedSignal();
109 private: // From Control
112 * @copydoc Control::OnInitialize()
114 virtual void OnInitialize();
117 * @copydoc Control::OnStyleChange()
119 virtual void OnStyleChange( Toolkit::StyleManager styleManager, StyleChange::Type change );
122 * @copydoc Control::GetNaturalSize()
124 virtual Vector3 GetNaturalSize();
127 * @copydoc Control::GetHeightForWidth()
129 virtual float GetHeightForWidth( float width );
132 * @copydoc Control::OnInitialize()
134 virtual void OnRelayout( const Vector2& size, RelayoutContainer& container );
137 * @copydoc Control::OnKeyInputFocusGained()
139 virtual void OnKeyInputFocusGained();
142 * @copydoc Control::OnKeyInputFocusLost()
144 virtual void OnKeyInputFocusLost();
147 * @copydoc Control::OnTap()
149 virtual void OnTap( const TapGesture& tap );
152 * @copydoc Control::OnPan()
154 virtual void OnPan( const PanGesture& gesture );
157 * @copydoc Control::OnLongPress()
159 virtual void OnLongPress( const LongPressGesture& gesture );
162 * @copydoc Control::OnStageConnection()
164 virtual void OnStageConnection( int depth );
167 * @copydoc Dali::CustomActorImpl::OnKeyEvent(const KeyEvent&)
169 virtual bool OnKeyEvent(const KeyEvent& event);
171 // From ControlInterface
174 * @copydoc Text::ControlInterface::RequestTextRelayout()
176 virtual void RequestTextRelayout();
178 // From EditableControlInterface
181 * @copydoc Text::ControlInterface::TextChanged()
183 virtual void TextChanged();
186 * @copydoc Text::ControlInterface::MaxLengthReached()
188 virtual void MaxLengthReached();
191 * @copydoc Text::ControlInterface::InputStyleChanged()
193 virtual void InputStyleChanged( Text::InputStyle::Mask inputStyleMask );
196 * @copydoc Text::ControlInterface::AddDecoration()
198 virtual void AddDecoration( Actor& actor, bool needsClipping );
200 private: // Implementation
203 * @copydoc Dali::Toolkit::Text::Controller::(InputMethodContext& inputMethodContext, const InputMethodContext::EventData& inputMethodContextEvent)
205 InputMethodContext::CallbackData OnInputMethodContextEvent( InputMethodContext& inputMethodContext, const InputMethodContext::EventData& inputMethodContextEvent );
208 * @brief Callback when Clipboard signals an item should be pasted
209 * @param[in] clipboard handle to Clipboard Event Notifier
211 void OnClipboardTextSelected( ClipboardEventNotifier& clipboard );
214 * @brief Get a Property Map for the image used for the required Handle Image
215 * @param[out] value the returned image property
216 * @param[in] handleType the type of handle
217 * @param[in] handleImageType the type of image for the given handleType
219 void GetHandleImagePropertyValue( Property::Value& value, Text::HandleType handleType, Text::HandleImageType handleImageType );
222 * @brief Callback when keyboard is shown/hidden.
224 * @param[in] keyboardShown True if keyboard is shown.
226 void KeyboardStatusChanged( bool keyboardShown );
229 * @brief update scroll bar position
231 * If text scroll is occurred, create or update scroll bar position
233 void UpdateScrollBar();
236 * @brief Callback when TextEditor is touched
238 * @param[in] actor TextEditor touched
239 * @param[in] touch Touch information
241 bool OnTouched( Actor actor, const TouchData& touch );
244 * @brief Callbacks called on idle.
246 * If there are notifications of change of input style on the queue, Toolkit::TextEditor::InputStyleChangedSignal() are emitted.
251 * @brief set RenderActor's position with new scrollPosition
253 * Apply updated scroll position or start scroll animation if VerticalScrollAnimation is enabled
255 void ApplyScrollPosition();
258 * @brief Callback function for ScrollBar indicator animation finished signal
260 * Emit ScrollBarStateChanged Signal and toggle mScrollStarted flag to false
262 void OnScrollIndicatorAnimationFinished( Animation& animation );
265 * Construct a new TextEditor.
270 * A reference counted object may only be deleted by calling Unreference()
272 virtual ~TextEditor();
274 // Undefined copy constructor and assignment operators
275 TextEditor(const TextEditor&);
276 TextEditor& operator=(const TextEditor& rhs);
279 * @brief Render view, create and attach actor(s) to this text editor.
281 void RenderText( Text::Controller::UpdateTextType updateTextType );
283 // Connection needed to re-render text, when a text editor returns to the stage.
284 void OnStageConnect( Dali::Actor actor );
288 Toolkit::TextEditor::TextChangedSignalType mTextChangedSignal;
289 Toolkit::TextEditor::InputStyleChangedSignalType mInputStyleChangedSignal;
290 Toolkit::TextEditor::ScrollStateChangedSignalType mScrollStateChangedSignal;
292 InputMethodContext mInputMethodContext;
293 Text::ControllerPtr mController;
294 Text::RendererPtr mRenderer;
295 Text::DecoratorPtr mDecorator;
296 Text::TextVerticalScrollerPtr mTextVerticalScroller;
297 Toolkit::Control mStencil;
298 Toolkit::ScrollBar mScrollBar;
299 Dali::Animation mAnimation; ///< Scroll indicator Show/Hide Animation.
300 Dali::TimePeriod mAnimationPeriod;
301 std::vector<Actor> mClippingDecorationActors; ///< Decoration actors which need clipping.
303 Actor mRenderableActor;
305 CallbackBase* mIdleCallback;
307 float mAlignmentOffset;
308 float mScrollAnimationDuration;
310 int mRenderingBackend;
311 bool mHasBeenStaged:1;
312 bool mScrollAnimationEnabled:1;
313 bool mScrollBarEnabled:1;
314 bool mScrollStarted:1;
317 } // namespace Internal
319 // Helpers for public-api forwarding methods
321 inline Toolkit::Internal::TextEditor& GetImpl( Toolkit::TextEditor& textEditor )
323 DALI_ASSERT_ALWAYS(textEditor);
325 Dali::RefObject& handle = textEditor.GetImplementation();
327 return static_cast<Toolkit::Internal::TextEditor&>(handle);
330 inline const Toolkit::Internal::TextEditor& GetImpl( const Toolkit::TextEditor& textEditor )
332 DALI_ASSERT_ALWAYS(textEditor);
334 const Dali::RefObject& handle = textEditor.GetImplementation();
336 return static_cast<const Toolkit::Internal::TextEditor&>(handle);
339 } // namespace Toolkit
343 #endif // DALI_TOOLKIT_INTERNAL_TEXT_EDITOR_H