1 #ifndef DALI_TOOLKIT_CONTROL_DATA_IMPL_H
2 #define DALI_TOOLKIT_CONTROL_DATA_IMPL_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/public-api/object/type-registry.h>
23 #include <dali-toolkit/devel-api/controls/control-devel.h>
27 #include <dali-toolkit/internal/visuals/visual-resource-observer.h>
28 #include <dali-toolkit/public-api/controls/control-impl.h>
29 #include <dali/devel-api/common/owner-container.h>
30 #include <dali-toolkit/devel-api/visual-factory/visual-base.h>
31 #include <dali-toolkit/internal/controls/tooltip/tooltip.h>
32 #include <dali-toolkit/internal/builder/style.h>
33 #include <dali-toolkit/internal/builder/dictionary.h>
34 #include <dali-toolkit/public-api/visuals/visual-properties.h>
46 * Struct used to store Visual within the control, index is a unique key for each visual.
48 struct RegisteredVisual
50 Property::Index index;
51 Toolkit::Visual::Base visual;
55 RegisteredVisual( Property::Index aIndex, Toolkit::Visual::Base &aVisual, bool aEnabled, bool aPendingReplacement )
56 : index(aIndex), visual(aVisual), enabled(aEnabled), pending( aPendingReplacement )
61 typedef Dali::OwnerContainer< RegisteredVisual* > RegisteredVisualContainer;
65 * @brief Holds the Implementation for the internal control class
67 class Control::Impl : public ConnectionTracker, public Visual::ResourceObserver
73 * @brief Retrieves the implementation of the internal control class.
74 * @param[in] internalControl A ref to the control whose internal implementation is required
75 * @return The internal implementation
77 static Control::Impl& Get( Internal::Control& internalControl );
80 * @copydoc Get( Internal::Control& )
82 static const Control::Impl& Get( const Internal::Control& internalControl );
86 * @param[in] controlImpl The control which own this implementation
88 Impl( Control& controlImpl );
96 * @brief Called when a pinch is detected.
97 * @param[in] actor The actor the pinch occurred on
98 * @param[in] pinch The pinch gesture details
100 void PinchDetected(Actor actor, const PinchGesture& pinch);
103 * @brief Called when a pan is detected.
104 * @param[in] actor The actor the pan occurred on
105 * @param[in] pinch The pan gesture details
107 void PanDetected(Actor actor, const PanGesture& pan);
110 * @brief Called when a tap is detected.
111 * @param[in] actor The actor the tap occurred on
112 * @param[in] pinch The tap gesture details
114 void TapDetected(Actor actor, const TapGesture& tap);
117 * @brief Called when a long-press is detected.
118 * @param[in] actor The actor the long-press occurred on
119 * @param[in] pinch The long-press gesture details
121 void LongPressDetected(Actor actor, const LongPressGesture& longPress);
124 * @brief Called when a resource is ready.
125 * @param[in] object The visual whose resources are ready
126 * @note Overriding method in Visual::ResourceObserver.
128 virtual void ResourceReady( Visual::Base& object );
131 * @copydoc Dali::Toolkit::DevelControl::RegisterVisual()
133 void RegisterVisual( Property::Index index, Toolkit::Visual::Base& visual );
136 * @copydoc Dali::Toolkit::DevelControl::RegisterVisual()
138 void RegisterVisual( Property::Index index, Toolkit::Visual::Base& visual, int depthIndex );
141 * @copydoc Dali::Toolkit::DevelControl::RegisterVisual()
143 void RegisterVisual( Property::Index index, Toolkit::Visual::Base& visual, bool enabled );
146 * @copydoc Dali::Toolkit::DevelControl::RegisterVisual()
148 void RegisterVisual( Property::Index index, Toolkit::Visual::Base& visual, bool enabled, int depthIndex );
151 * @copydoc Dali::Toolkit::DevelControl::UnregisterVisual()
153 void UnregisterVisual( Property::Index index );
156 * @copydoc Dali::Toolkit::DevelControl::GetVisual()
158 Toolkit::Visual::Base GetVisual( Property::Index index ) const;
161 * @copydoc Dali::Toolkit::DevelControl::EnableVisual()
163 void EnableVisual( Property::Index index, bool enable );
166 * @copydoc Dali::Toolkit::DevelControl::IsVisualEnabled()
168 bool IsVisualEnabled( Property::Index index ) const;
171 * @brief Stops observing the given visual.
172 * @param[in] visual The visual to stop observing
174 void StopObservingVisual( Toolkit::Visual::Base& visual );
177 * @brief Starts observing the given visual.
178 * @param[in] visual The visual to start observing
180 void StartObservingVisual( Toolkit::Visual::Base& visual);
183 * @copydoc Dali::Toolkit::DevelControl::GetVisualResourceStatus()
185 Toolkit::Visual::ResourceStatus GetVisualResourceStatus( Property::Index index ) const;
188 * @copydoc Dali::Toolkit::DevelControl::CreateTransition()
190 Dali::Animation CreateTransition( const Toolkit::TransitionData& transitionData );
193 * @copydoc Dali::Toolkit::DevelControl::DoAction()
195 void DoAction( Dali::Property::Index visualIndex, Dali::Property::Index actionId, const Dali::Property::Value attributes );
198 * @brief Function used to set control properties.
199 * @param[in] object The object whose property to set
200 * @param[in] index The index of the property to set
201 * @param[in] value The value of the property to set
203 static void SetProperty( BaseObject* object, Property::Index index, const Property::Value& value );
206 * @brief Function used to retrieve the value of control properties.
207 * @param[in] object The object whose property to get
208 * @param[in] index The index of the property to get
209 * @return The value of the property
211 static Property::Value GetProperty( BaseObject* object, Property::Index index );
214 * @brief Sets the state of the control.
215 * @param[in] newState The state to set
216 * @param[in] withTransitions Whether to show a transition when changing to the new state
218 void SetState( DevelControl::State newState, bool withTransitions=true );
221 * @brief Sets the sub-state of the control.
222 * @param[in] newState The sub-state to set
223 * @param[in] withTransitions Whether to show a transition when changing to the new sub-state
225 void SetSubState( const std::string& subStateName, bool withTransitions=true );
228 * @brief Replaces visuals and properties from the old state to the new state.
229 * @param[in] oldState The old state
230 * @param[in] newState The new state
231 * @param[in] subState The current sub state
233 void ReplaceStateVisualsAndProperties( const StylePtr oldState, const StylePtr newState, const std::string& subState );
236 * @brief Removes a visual from the control's container.
237 * @param[in] visuals The container of visuals
238 * @param[in] visualName The name of the visual to remove
240 void RemoveVisual( RegisteredVisualContainer& visuals, const std::string& visualName );
243 * @brief Removes several visuals from the control's container.
244 * @param[in] visuals The container of visuals
245 * @param[in] removeVisuals The visuals to remove
247 void RemoveVisuals( RegisteredVisualContainer& visuals, DictionaryKeys& removeVisuals );
250 * @brief Copies the visual properties that are specific to the control instance into the instancedProperties container.
251 * @param[in] visuals The control's visual container
252 * @param[out] instancedProperties The instanced properties are added to this container
254 void CopyInstancedProperties( RegisteredVisualContainer& visuals, Dictionary<Property::Map>& instancedProperties );
257 * @brief On state change, ensures visuals are moved or created appropriately.
259 * Go through the list of visuals that are common to both states.
260 * If they are different types, or are both image types with different
261 * URLs, then the existing visual needs moving and the new visual needs creating
263 * @param[in] stateVisualsToChange The visuals to change
264 * @param[in] instancedProperties The instanced properties @see CopyInstancedProperties
266 void RecreateChangedVisuals( Dictionary<Property::Map>& stateVisualsToChange, Dictionary<Property::Map>& instancedProperties );
269 * @brief Whether the resource is ready
270 * @return True if the resource is read.
272 bool IsResourceReady() const;
275 * @copydoc CustomActorImpl::OnStageDisconnection()
277 void OnStageDisconnection();
280 * @brief Sets the margin.
281 * @param[in] margin Margin is a collections of extent ( start, end, top, bottom )
283 void SetMargin( Extents margin );
286 * @brief Returns the value of margin
287 * @return The value of margin
289 Extents GetMargin() const;
292 * @brief Sets the padding.
293 * @param[in] padding Padding is a collections of extent ( start, end, top, bottom ).
295 void SetPadding( Extents padding );
298 * @brief Returns the value of padding
299 * @return The value of padding
301 Extents GetPadding() const;
304 * @brief Set the input method context.
305 * @param[in] inputMethodContext The input method context.
307 void SetInputMethodContext( InputMethodContext& inputMethodContext );
310 * @brief Filter an key event.
311 * @param[in] event The key to be filtered.
312 * @return True if the key handled, otherwise false.
314 bool FilterKeyEvent( const KeyEvent& event );
319 * Used as an alternative to boolean so that it is obvious whether a visual is enabled/disabled.
325 DISABLED = 0, ///< Visual disabled.
326 ENABLED = 1 ///< Visual enabled.
331 * Used as an alternative to boolean so that it is obvious whether a visual's depth value has been set or not by the caller.
333 struct DepthIndexValue
337 NOT_SET = 0, ///< Visual depth value not set by caller.
338 SET = 1 ///< Visual depth value set by caller.
343 * @brief Adds the visual to the list of registered visuals.
344 * @param[in] index The Property index of the visual, used to reference visual
345 * @param[in,out] visual The visual to register, which can be altered in this function
346 * @param[in] enabled false if derived class wants to control when visual is set on stage
347 * @param[in] depthIndexValueSet Set to true if the depthIndex has actually been set manually
348 * @param[in] depthIndex The visual's depth-index is set to this
350 * @note Registering a visual with an index that already has a registered visual will replace it. The replacement will
351 * occur once the replacement visual is ready (loaded).
353 void RegisterVisual( Property::Index index, Toolkit::Visual::Base& visual, VisualState::Type enabled, DepthIndexValue::Type depthIndexValueSet, int depthIndex = 0 );
357 Control& mControlImpl;
358 DevelControl::State mState;
359 std::string mSubStateName;
361 int mLeftFocusableActorId; ///< Actor ID of Left focusable control.
362 int mRightFocusableActorId; ///< Actor ID of Right focusable control.
363 int mUpFocusableActorId; ///< Actor ID of Up focusable control.
364 int mDownFocusableActorId; ///< Actor ID of Down focusable control.
366 RegisteredVisualContainer mVisuals; ///< Stores visuals needed by the control, non trivial type so std::vector used.
367 std::string mStyleName;
368 Vector4 mBackgroundColor; ///< The color of the background visual
369 Vector3* mStartingPinchScale; ///< The scale when a pinch gesture starts, TODO: consider removing this
370 Extents mMargin; ///< The margin values
371 Extents mPadding; ///< The padding values
372 Toolkit::Control::KeyEventSignalType mKeyEventSignal;
373 Toolkit::Control::KeyInputFocusSignalType mKeyInputFocusGainedSignal;
374 Toolkit::Control::KeyInputFocusSignalType mKeyInputFocusLostSignal;
375 Toolkit::Control::ResourceReadySignalType mResourceReadySignal;
378 PinchGestureDetector mPinchGestureDetector;
379 PanGestureDetector mPanGestureDetector;
380 TapGestureDetector mTapGestureDetector;
381 LongPressGestureDetector mLongPressGestureDetector;
386 InputMethodContext mInputMethodContext;
388 ControlBehaviour mFlags : CONTROL_BEHAVIOUR_FLAG_COUNT; ///< Flags passed in from constructor.
389 bool mIsKeyboardNavigationSupported :1; ///< Stores whether keyboard navigation is supported by the control.
390 bool mIsKeyboardFocusGroup :1; ///< Stores whether the control is a focus group.
392 RegisteredVisualContainer mRemoveVisuals; ///< List of visuals that are being replaced by another visual once ready
394 // Properties - these need to be members of Internal::Control::Impl as they access private methods/data of Internal::Control and Internal::Control::Impl.
395 static const PropertyRegistration PROPERTY_1;
396 static const PropertyRegistration PROPERTY_2;
397 static const PropertyRegistration PROPERTY_3;
398 static const PropertyRegistration PROPERTY_4;
399 static const PropertyRegistration PROPERTY_5;
400 static const PropertyRegistration PROPERTY_6;
401 static const PropertyRegistration PROPERTY_7;
402 static const PropertyRegistration PROPERTY_8;
403 static const PropertyRegistration PROPERTY_9;
404 static const PropertyRegistration PROPERTY_10;
405 static const PropertyRegistration PROPERTY_11;
406 static const PropertyRegistration PROPERTY_12;
407 static const PropertyRegistration PROPERTY_13;
408 static const PropertyRegistration PROPERTY_14;
412 } // namespace Internal
414 } // namespace Toolkit
418 #endif // DALI_TOOLKIT_CONTROL_DATA_IMPL_H