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/devel-api/controls/text-controls/text-editor-devel.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>
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 * Connects a callback function with the object's signals.
80 * @param[in] object The object providing the signal.
81 * @param[in] tracker Used to disconnect the signal.
82 * @param[in] signalName The signal to connect to.
83 * @param[in] functor A newly allocated FunctorDelegate.
84 * @return True if the signal was connected.
85 * @post If a signal was connected, ownership of functor was passed to CallbackBase. Otherwise the caller is responsible for deleting the unused functor.
87 static bool DoConnectSignal( BaseObject* object, ConnectionTrackerInterface* tracker, const std::string& signalName, FunctorDelegate* functor );
90 * @copydoc TextEditor::TextChangedSignal()
92 Toolkit::TextEditor::TextChangedSignalType& TextChangedSignal();
95 * @copydoc TextEditor::TextChangedSignal()
97 Toolkit::TextEditor::InputStyleChangedSignalType& InputStyleChangedSignal();
100 * @copydoc DevelTextEditor::ScrollStateChangedSignal()
102 Toolkit::DevelTextEditor::ScrollStateChangedSignalType& ScrollStateChangedSignal();
104 private: // From Control
107 * @copydoc Control::OnInitialize()
109 virtual void OnInitialize();
112 * @copydoc Control::OnStyleChange()
114 virtual void OnStyleChange( Toolkit::StyleManager styleManager, StyleChange::Type change );
117 * @copydoc Control::GetNaturalSize()
119 virtual Vector3 GetNaturalSize();
122 * @copydoc Control::GetHeightForWidth()
124 virtual float GetHeightForWidth( float width );
127 * @copydoc Control::OnInitialize()
129 virtual void OnRelayout( const Vector2& size, RelayoutContainer& container );
132 * @copydoc Control::OnKeyInputFocusGained()
134 virtual void OnKeyInputFocusGained();
137 * @copydoc Control::OnKeyInputFocusLost()
139 virtual void OnKeyInputFocusLost();
142 * @copydoc Control::OnTap()
144 virtual void OnTap( const TapGesture& tap );
147 * @copydoc Control::OnPan()
149 virtual void OnPan( const PanGesture& gesture );
152 * @copydoc Control::OnLongPress()
154 virtual void OnLongPress( const LongPressGesture& gesture );
157 * @copydoc Control::OnStageConnection()
159 virtual void OnStageConnection( int depth );
162 * @copydoc Dali::CustomActorImpl::OnKeyEvent(const KeyEvent&)
164 virtual bool OnKeyEvent(const KeyEvent& event);
166 // From ControlInterface
169 * @copydoc Text::ControlInterface::RequestTextRelayout()
171 virtual void RequestTextRelayout();
173 // From EditableControlInterface
176 * @copydoc Text::ControlInterface::TextChanged()
178 virtual void TextChanged();
181 * @copydoc Text::ControlInterface::MaxLengthReached()
183 virtual void MaxLengthReached();
186 * @copydoc Text::ControlInterface::InputStyleChanged()
188 virtual void InputStyleChanged( Text::InputStyle::Mask inputStyleMask );
191 * @copydoc Text::ControlInterface::AddDecoration()
193 virtual void AddDecoration( Actor& actor, bool needsClipping );
195 private: // Implementation
198 * @copydoc Dali::Toolkit::Text::Controller::(ImfManager& imfManager, const ImfManager::ImfEventData& imfEvent)
200 ImfManager::ImfCallbackData OnImfEvent( ImfManager& imfManager, const ImfManager::ImfEventData& imfEvent );
203 * @brief Callback when Clipboard signals an item should be pasted
204 * @param[in] clipboard handle to Clipboard Event Notifier
206 void OnClipboardTextSelected( ClipboardEventNotifier& clipboard );
209 * @brief Get a Property Map for the image used for the required Handle Image
210 * @param[out] value the returned image property
211 * @param[in] handleType the type of handle
212 * @param[in] handleImageType the type of image for the given handleType
214 void GetHandleImagePropertyValue( Property::Value& value, Text::HandleType handleType, Text::HandleImageType handleImageType );
217 * @brief Callback when keyboard is shown/hidden.
219 * @param[in] keyboardShown True if keyboard is shown.
221 void KeyboardStatusChanged( bool keyboardShown );
224 * @brief update scroll bar position
226 * If text scroll is occurred, create or update scroll bar position
228 void UpdateScrollBar();
231 * @brief Callback when TextEditor is touched
233 * @param[in] actor TextEditor touched
234 * @param[in] touch Touch information
236 bool OnTouched( Actor actor, const TouchData& touch );
239 * @brief Callbacks called on idle.
241 * If there are notifications of change of input style on the queue, Toolkit::TextEditor::InputStyleChangedSignal() are emitted.
246 * @brief set RenderActor's position with new scrollPosition
248 * Apply updated scroll position or start scroll animation if VerticalScrollAnimation is enabled
250 void ApplyScrollPosition();
253 * @brief Callback function for ScrollBar indicator animation finished signal
255 * Emit ScrollBarStateChanged Signal and toggle mScrollStarted flag to false
257 void OnScrollIndicatorAnimationFinished( Animation& animation );
260 * Construct a new TextEditor.
265 * A reference counted object may only be deleted by calling Unreference()
267 virtual ~TextEditor();
269 // Undefined copy constructor and assignment operators
270 TextEditor(const TextEditor&);
271 TextEditor& operator=(const TextEditor& rhs);
274 * @brief Render view, create and attach actor(s) to this text editor.
276 void RenderText( Text::Controller::UpdateTextType updateTextType );
278 // Connection needed to re-render text, when a text editor returns to the stage.
279 void OnStageConnect( Dali::Actor actor );
283 Toolkit::TextEditor::TextChangedSignalType mTextChangedSignal;
284 Toolkit::TextEditor::InputStyleChangedSignalType mInputStyleChangedSignal;
285 Toolkit::DevelTextEditor::ScrollStateChangedSignalType mScrollStateChangedSignal;
287 ImfManager mImfManager;
288 Text::ControllerPtr mController;
289 Text::RendererPtr mRenderer;
290 Text::DecoratorPtr mDecorator;
291 Text::TextVerticalScrollerPtr mTextVerticalScroller;
292 Toolkit::Control mStencil;
293 Toolkit::ScrollBar mScrollBar;
294 Dali::Animation mAnimation; ///< Scroll indicator Show/Hide Animation.
295 Dali::TimePeriod mAnimationPeriod;
296 std::vector<Actor> mClippingDecorationActors; ///< Decoration actors which need clipping.
298 Actor mRenderableActor;
300 CallbackBase* mIdleCallback;
302 float mAlignmentOffset;
303 float mScrollAnimationDuration;
304 int mRenderingBackend;
305 bool mHasBeenStaged:1;
306 bool mScrollAnimationEnabled:1;
307 bool mScrollBarEnabled:1;
308 bool mScrollStarted:1;
311 } // namespace Internal
313 // Helpers for public-api forwarding methods
315 inline Toolkit::Internal::TextEditor& GetImpl( Toolkit::TextEditor& textEditor )
317 DALI_ASSERT_ALWAYS(textEditor);
319 Dali::RefObject& handle = textEditor.GetImplementation();
321 return static_cast<Toolkit::Internal::TextEditor&>(handle);
324 inline const Toolkit::Internal::TextEditor& GetImpl( const Toolkit::TextEditor& textEditor )
326 DALI_ASSERT_ALWAYS(textEditor);
328 const Dali::RefObject& handle = textEditor.GetImplementation();
330 return static_cast<const Toolkit::Internal::TextEditor&>(handle);
333 } // namespace Toolkit
337 #endif // DALI_TOOLKIT_INTERNAL_TEXT_EDITOR_H