Add new public APIs for Window
[platform/core/uifw/dali-adaptor.git] / dali / internal / input / common / drag-and-drop-detector-impl.h
1 #ifndef DALI_INTERNAL_DRAG_AND_DROP_DETECTOR_H
2 #define DALI_INTERNAL_DRAG_AND_DROP_DETECTOR_H
3
4 /*
5  * Copyright (c) 2019 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 <string>
23
24 #include <dali/public-api/object/base-object.h>
25 #include <dali/public-api/math/vector2.h>
26
27 // INTERNAL INCLUDES
28 #include <dali/devel-api/adaptor-framework/drag-and-drop-detector.h>
29
30 namespace Dali
31 {
32
33 namespace Internal
34 {
35
36 namespace Adaptor
37 {
38
39 typedef IntrusivePtr< DragAndDropDetector > DragAndDropDetectorPtr;
40
41 /**
42  * This class listens to Drag & Drop events.
43  */
44 class DragAndDropDetector : public Dali::BaseObject
45 {
46 public:
47
48   typedef Dali::DragAndDropDetector::DragAndDropSignal DragAndDropSignal;
49
50   // Creation
51
52   /**
53    * Create a DragAndDropDetector.
54    * This should only be called once by the Window class.
55    * @return A newly allocated drag-and-drop-detector.
56    */
57   static Dali::DragAndDropDetector New();
58
59   // Public API
60
61   /**
62    * @copydoc Dali::DragAndDropDetector::GetContent() const
63    */
64   const std::string& GetContent() const;
65
66   /**
67    * @copydoc Dali::DragAndDropDetector::GetCurrentScreenPosition() const
68    */
69   Vector2 GetCurrentScreenPosition() const;
70
71   // Called by Drag & Drop Event Handler
72
73   /**
74    * Queries whether drag & drop behaviour is really required.
75    * @return true if drag & drop required, false otherwise.
76    */
77   bool IsEnabled() const;
78
79   /**
80    * Sets the dragged content.
81    * @param[in] content  A string that represents the content that has been dropped.
82    */
83   void SetContent( const std::string& content );
84
85   /**
86    * Clears the stored content.
87    */
88   void ClearContent();
89
90   /**
91    * Sets the position the drop occurred.
92    */
93   void SetPosition( Vector2 screenPosition );
94
95   /**
96    * Called when a draggable object enters our window.
97    */
98   void EmitEnteredSignal();
99
100   /**
101    * Called when a draggable object leaves our window.
102    */
103   void EmitExitedSignal();
104
105   /**
106    * Called when a draggable object leaves our window.
107    */
108   void EmitMovedSignal();
109
110   /**
111    * Is called when a drop actually occurs.
112    */
113   void EmitDroppedSignal();
114
115 public: // Signals
116
117   /**
118    * @copydoc Dali::DragAndDropDetector::EnteredSignal
119    */
120   DragAndDropSignal& EnteredSignal()
121   {
122     return mEnteredSignal;
123   }
124
125   /**
126    * @copydoc Dali::DragAndDropDetector::ExitedSignal
127    */
128   DragAndDropSignal& ExitedSignal()
129   {
130     return mExitedSignal;
131   }
132
133   /**
134    * @copydoc Dali::DragAndDropDetector::MovedSignal
135    */
136   DragAndDropSignal& MovedSignal()
137   {
138     return mMovedSignal;
139   }
140
141   /**
142    * @copydoc Dali::DragAndDropDetector::DroppedSignal
143    */
144   DragAndDropSignal& DroppedSignal()
145   {
146     return mDroppedSignal;
147   }
148
149 private:
150
151   // Construction & Destruction
152
153   /**
154    * Constructor.
155    */
156   DragAndDropDetector();
157
158   /**
159    * Destructor.
160    */
161   virtual ~DragAndDropDetector();
162
163   // Undefined
164   DragAndDropDetector( const DragAndDropDetector& );
165   DragAndDropDetector& operator=( DragAndDropDetector& );
166
167 private:
168
169   std::string mContent;    ///< The current Drag & drop content.
170   Vector2 mScreenPosition; ///< The screen position of the drop location.
171
172   DragAndDropSignal mEnteredSignal;
173   DragAndDropSignal mExitedSignal;
174   DragAndDropSignal mMovedSignal;
175   DragAndDropSignal mDroppedSignal;
176 };
177
178 } // namespace Adaptor
179
180 } // namespace Internal
181
182 // Helpers for public-api forwarding methods
183
184 inline Internal::Adaptor::DragAndDropDetector& GetImplementation(Dali::DragAndDropDetector& detector)
185 {
186   DALI_ASSERT_ALWAYS( detector && "DragAndDropDetector handle is empty" );
187
188   BaseObject& handle = detector.GetBaseObject();
189
190   return static_cast<Internal::Adaptor::DragAndDropDetector&>(handle);
191 }
192
193 inline const Internal::Adaptor::DragAndDropDetector& GetImplementation(const Dali::DragAndDropDetector& detector)
194 {
195   DALI_ASSERT_ALWAYS( detector && "DragAndDropDetector handle is empty" );
196
197   const BaseObject& handle = detector.GetBaseObject();
198
199   return static_cast<const Internal::Adaptor::DragAndDropDetector&>(handle);
200 }
201
202 } // namespace Dali
203
204 #endif // DALI_INTERNAL_DRAG_AND_DROP_DETECTOR_H