1 #ifndef __DALI_TOOLKIT_INTERNAL_TEXT_FIELD_H__
2 #define __DALI_TOOLKIT_INTERNAL_TEXT_FIELD_H__
5 * Copyright (c) 2015 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-toolkit/public-api/controls/control-impl.h>
23 #include <dali-toolkit/public-api/controls/text-controls/text-field.h>
24 #include <dali-toolkit/internal/text/clipping/text-clipper.h>
25 #include <dali-toolkit/internal/text/decorator/text-decorator.h>
26 #include <dali-toolkit/internal/text/text-control-interface.h>
27 #include <dali-toolkit/internal/text/text-controller.h>
28 #include <dali-toolkit/internal/text/rendering/text-renderer.h>
31 #include <dali/devel-api/adaptor-framework/clipboard-event-notifier.h>
43 * @brief A control which renders a short text string.
45 class TextField : public Control, public Text::ControlInterface
50 * @copydoc Dali::Toollkit::TextField::New()
52 static Toolkit::TextField New();
57 * @brief Called when a property of an object of this type is set.
59 * @param[in] object The object whose property is set.
60 * @param[in] index The property index.
61 * @param[in] value The new property value.
63 static void SetProperty( BaseObject* object, Property::Index index, const Property::Value& value );
66 * @brief Called to retrieve a property of an object of this type.
68 * @param[in] object The object whose property is to be retrieved.
69 * @param[in] index The property index.
70 * @return The current value of the property.
72 static Property::Value GetProperty( BaseObject* object, Property::Index index );
75 * Connects a callback function with the object's signals.
76 * @param[in] object The object providing the signal.
77 * @param[in] tracker Used to disconnect the signal.
78 * @param[in] signalName The signal to connect to.
79 * @param[in] functor A newly allocated FunctorDelegate.
80 * @return True if the signal was connected.
81 * @post If a signal was connected, ownership of functor was passed to CallbackBase. Otherwise the caller is responsible for deleting the unused functor.
83 static bool DoConnectSignal( BaseObject* object, ConnectionTrackerInterface* tracker, const std::string& signalName, FunctorDelegate* functor );
86 * @copydoc TextField::TextChangedSignal()
88 Toolkit::TextField::TextChangedSignalType& TextChangedSignal();
91 * @copydoc TextField::MaxLengthReachedSignal()
93 Toolkit::TextField::MaxLengthReachedSignalType& MaxLengthReachedSignal();
95 private: // From Control
98 * @copydoc Control::OnInitialize()
100 virtual void OnInitialize();
103 * @copydoc Control::OnStyleChange()
105 virtual void OnStyleChange( Toolkit::StyleManager styleManager, StyleChange::Type change );
108 * @copydoc Control::GetNaturalSize()
110 virtual Vector3 GetNaturalSize();
113 * @copydoc Control::GetHeightForWidth()
115 virtual float GetHeightForWidth( float width );
118 * @copydoc Control::OnInitialize()
120 virtual void OnRelayout( const Vector2& size, RelayoutContainer& container );
123 * @copydoc Control::OnKeyInputFocusGained()
125 virtual void OnKeyInputFocusGained();
128 * @copydoc Control::OnKeyInputFocusLost()
130 virtual void OnKeyInputFocusLost();
133 * @copydoc Control::OnTap()
135 virtual void OnTap( const TapGesture& tap );
138 * @copydoc Control::OnPan()
140 virtual void OnPan( const PanGesture& gesture );
143 * @copydoc Control::OnLongPress()
145 virtual void OnLongPress( const LongPressGesture& gesture );
148 * @copydoc Control::OnStageConnection()
150 virtual void OnStageConnection( int depth );
153 * @copydoc Dali::CustomActorImpl::OnKeyEvent(const KeyEvent&)
155 virtual bool OnKeyEvent(const KeyEvent& event);
158 * @copydoc Text::ControlInterface::AddDecoration()
160 virtual void AddDecoration( Actor& actor, bool needsClipping );
163 * @copydoc Text::ControlInterface::RequestTextRelayout()
165 virtual void RequestTextRelayout();
168 * @copydoc Text::ControlInterface::TextChanged()
170 virtual void TextChanged();
173 * @copydoc Text::ControlInterface::MaxLengthReached()
175 virtual void MaxLengthReached();
178 * @copydoc Dali::Toolkit::Text::Controller::(ImfManager& imfManager, const ImfManager::ImfEventData& imfEvent)
180 ImfManager::ImfCallbackData OnImfEvent( ImfManager& imfManager, const ImfManager::ImfEventData& imfEvent );
183 * @brief Callback when Clipboard signals an item should be pasted
184 * @param[in] clipboard handle to Clipboard Event Notifier
186 void OnClipboardTextSelected( ClipboardEventNotifier& clipboard );
188 private: // Implementation
191 * @brief Get a Property Map for the image used for the required Handle Image
192 * @param[out] value the returned image property
193 * @param[in] handleType the type of handle
194 * @param[in] handleImageType the type of image for the given handleType
196 void GetHandleImagePropertyValue( Property::Value& value, Text::HandleType handleType, Text::HandleImageType handleImageType );
199 * @brief Enable or disable clipping.
201 * @param[in] clipping True if clipping should be enabled.
202 * @param[in] size The area to clip within.
204 void EnableClipping( bool clipping, const Vector2& size );
207 * @brief Callback when keyboard is shown/hidden.
209 * @param[in] keyboardShown True if keyboard is shown.
211 void KeyboardStatusChanged( bool keyboardShown );
214 * @brief Callback when Textfield is touched
216 * @param[in] actor TextField touched
217 * @param[in] event TouchEvent information
219 bool OnTouched( Actor actor, const TouchEvent& event );
222 * Construct a new TextField.
227 * A reference counted object may only be deleted by calling Unreference()
229 virtual ~TextField();
231 // Undefined copy constructor and assignment operators
232 TextField(const TextField&);
233 TextField& operator=(const TextField& rhs);
236 * @brief Render view, create and attach actor(s) to this Text Field.
240 // Connection needed to re-render text, when a Text Field returns to the stage.
241 void OnStageConnect( Dali::Actor actor );
246 Toolkit::TextField::TextChangedSignalType mTextChangedSignal;
247 Toolkit::TextField::MaxLengthReachedSignalType mMaxLengthReachedSignal;
249 Text::ControllerPtr mController;
250 Text::RendererPtr mRenderer;
251 Text::DecoratorPtr mDecorator;
252 Text::ClipperPtr mClipper; ///< For EXCEED_POLICY_CLIP
253 std::vector<Actor> mClippingDecorationActors; ///< Decoration actors which need clipping.
255 Actor mRenderableActor;
257 int mRenderingBackend;
259 bool mHasBeenStaged:1;
262 } // namespace Internal
264 // Helpers for public-api forwarding methods
266 inline Toolkit::Internal::TextField& GetImpl( Toolkit::TextField& textField )
268 DALI_ASSERT_ALWAYS(textField);
270 Dali::RefObject& handle = textField.GetImplementation();
272 return static_cast<Toolkit::Internal::TextField&>(handle);
275 inline const Toolkit::Internal::TextField& GetImpl( const Toolkit::TextField& textField )
277 DALI_ASSERT_ALWAYS(textField);
279 const Dali::RefObject& handle = textField.GetImplementation();
281 return static_cast<const Toolkit::Internal::TextField&>(handle);
284 } // namespace Toolkit
288 #endif // __DALI_TOOLKIT_INTERNAL_TEXT_FIELD_H__