4adfe65f370099a9133a9f6d2d7aa2b37723a534
[platform/core/uifw/dali-toolkit.git] / dali-toolkit / internal / controls / control / control-data-impl.h
1 #ifndef DALI_TOOLKIT_CONTROL_DATA_IMPL_H
2 #define DALI_TOOLKIT_CONTROL_DATA_IMPL_H
3
4 /*
5  * Copyright (c) 2016 Samsung Electronics Co., Ltd.
6  *
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
10  *
11  * http://www.apache.org/licenses/LICENSE-2.0
12  *
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.
18  *
19  */
20
21 // EXTERNAL INCLUDES
22 #include <dali/public-api/object/type-registry.h>
23 #include <dali-toolkit/devel-api/controls/control-devel.h>
24 #include <string>
25
26 // INTERNAL INCLUDES
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
35 namespace Dali
36 {
37
38 namespace Toolkit
39 {
40
41 namespace Internal
42 {
43
44 /**
45   * Struct used to store Visual within the control, index is a unique key for each visual.
46   */
47  struct RegisteredVisual
48  {
49    Property::Index index;
50    Toolkit::Visual::Base visual;
51    bool enabled;
52
53    RegisteredVisual( Property::Index aIndex, Toolkit::Visual::Base &aVisual, bool aEnabled)
54    : index(aIndex), visual(aVisual), enabled(aEnabled)
55    {
56    }
57  };
58
59 typedef Dali::OwnerContainer< RegisteredVisual* > RegisteredVisualContainer;
60
61
62 /**
63  * Holds the Implementation for the internal control class
64  */
65 class Control::Impl : public ConnectionTracker, public Visual::ResourceObserver
66 {
67
68 public:
69
70   static Control::Impl& Get( Internal::Control& internalControl );
71
72   static const Control::Impl& Get( const Internal::Control& internalControl );
73
74
75   Impl( Control& controlImpl );
76
77   ~Impl();
78
79   void PinchDetected(Actor actor, const PinchGesture& pinch);
80
81   void PanDetected(Actor actor, const PanGesture& pan);
82
83   void TapDetected(Actor actor, const TapGesture& tap);
84
85   void LongPressDetected(Actor actor, const LongPressGesture& longPress);
86
87   void ResourceReady( Visual::Base& object);
88
89   void StopObservingVisual( Toolkit::Visual::Base& visual );
90
91   void StartObservingVisual( Toolkit::Visual::Base& visual);
92
93   static void SetProperty( BaseObject* object, Property::Index index, const Property::Value& value );
94
95   static Property::Value GetProperty( BaseObject* object, Property::Index index );
96
97   void SetState( DevelControl::State newState, bool withTransitions=true );
98
99   void SetSubState( const std::string& subStateName, bool withTransitions=true );
100
101   void ReplaceStateVisualsAndProperties( const StylePtr oldState, const StylePtr newState, const std::string& subState );
102
103   void RemoveVisual( RegisteredVisualContainer& visuals, const std::string& visualName );
104
105   void RemoveVisuals( RegisteredVisualContainer& visuals, DictionaryKeys& removeVisuals );
106
107   void  CopyInstancedProperties( RegisteredVisualContainer& visuals, Dictionary<Property::Map>& instancedProperties );
108
109   void RecreateChangedVisuals( Dictionary<Property::Map>& stateVisualsToChange, Dictionary<Property::Map>& instancedProperties );
110
111   Toolkit::Visual::Base GetVisualByName( RegisteredVisualContainer& visuals, const std::string& visualName );
112
113   bool IsResourceReady() const;
114
115   Control& mControlImpl;
116   DevelControl::State mState;
117   std::string mSubStateName;
118
119   int mLeftFocusableActorId;       ///< Actor ID of Left focusable control.
120   int mRightFocusableActorId;      ///< Actor ID of Right focusable control.
121   int mUpFocusableActorId;         ///< Actor ID of Up focusable control.
122   int mDownFocusableActorId;       ///< Actor ID of Down focusable control.
123
124
125   RegisteredVisualContainer mVisuals;     ///< Stores visuals needed by the control, non trivial type so std::vector used.
126   std::string mStyleName;
127   Vector4 mBackgroundColor;               ///< The color of the background visual
128   Vector3* mStartingPinchScale;           ///< The scale when a pinch gesture starts, TODO: consider removing this
129   Toolkit::Control::KeyEventSignalType mKeyEventSignal;
130   Toolkit::Control::KeyInputFocusSignalType mKeyInputFocusGainedSignal;
131   Toolkit::Control::KeyInputFocusSignalType mKeyInputFocusLostSignal;
132
133   Toolkit::DevelControl::ResourceReadySignalType mResourceReadySignal;
134
135   // Gesture Detection
136   PinchGestureDetector mPinchGestureDetector;
137   PanGestureDetector mPanGestureDetector;
138   TapGestureDetector mTapGestureDetector;
139   LongPressGestureDetector mLongPressGestureDetector;
140
141   // Tooltip
142   TooltipPtr mTooltip;
143
144   ControlBehaviour mFlags : CONTROL_BEHAVIOUR_FLAG_COUNT;    ///< Flags passed in from constructor.
145   bool mIsKeyboardNavigationSupported :1;  ///< Stores whether keyboard navigation is supported by the control.
146   bool mIsKeyboardFocusGroup :1;           ///< Stores whether the control is a focus group.
147
148   // Properties - these need to be members of Internal::Control::Impl as they access private methods/data of Internal::Control and Internal::Control::Impl.
149   static const PropertyRegistration PROPERTY_1;
150   static const PropertyRegistration PROPERTY_2;
151   static const PropertyRegistration PROPERTY_3;
152   static const PropertyRegistration PROPERTY_4;
153   static const PropertyRegistration PROPERTY_5;
154   static const PropertyRegistration PROPERTY_6;
155   static const PropertyRegistration PROPERTY_7;
156   static const PropertyRegistration PROPERTY_8;
157   static const PropertyRegistration PROPERTY_9;
158   static const PropertyRegistration PROPERTY_10;
159   static const PropertyRegistration PROPERTY_11;
160   static const PropertyRegistration PROPERTY_12;
161
162 };
163
164
165 } // namespace Internal
166
167 } // namespace Toolkit
168
169 } // namespace Dali
170
171 #endif // DALI_TOOLKIT_CONTROL_DATA_IMPL_H