18e17b71fa6172000b58aa4ed21cb4215eed4667
[platform/core/uifw/dali-adaptor.git] / adaptors / wayland / window-impl-wl.cpp
1 /*
2  * Copyright (c) 2017 Samsung Electronics Co., Ltd.
3  *
4  * Licensed under the Apache License, Version 2.0 (the "License");
5  * you may not use this file except in compliance with the License.
6  * You may obtain a copy of the License at
7  *
8  * http://www.apache.org/licenses/LICENSE-2.0
9  *
10  * Unless required by applicable law or agreed to in writing, software
11  * distributed under the License is distributed on an "AS IS" BASIS,
12  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13  * See the License for the specific language governing permissions and
14  * limitations under the License.
15  *
16  */
17
18 // CLASS HEADER
19 #include "window-impl.h"
20
21 // EXTERNAL HEADERS
22 #include <dali/integration-api/core.h>
23 #include <dali/integration-api/system-overlay.h>
24 #include <dali/public-api/render-tasks/render-task.h>
25 #include <dali/public-api/render-tasks/render-task-list.h>
26 #include <orientation.h>
27
28 // INTERNAL HEADERS
29 #include "render-surface/render-surface-wl.h"
30 #include <drag-and-drop-detector-impl.h>
31 #include <window-visibility-observer.h>
32 #include <orientation-impl.h>
33
34
35
36 namespace Dali
37 {
38 namespace Internal
39 {
40 namespace Adaptor
41 {
42 #if defined(DEBUG_ENABLED)
43 Debug::Filter* gWindowLogFilter = Debug::Filter::New(Debug::Concise, false, "LOG_WINDOW");
44 #endif
45
46 struct Window::EventHandler
47 {
48   // place holder
49 };
50
51 Window* Window::New(const PositionSize& posSize, const std::string& name, const std::string& className, bool isTransparent)
52 {
53   Window* window = new Window();
54   window->mIsTransparent = isTransparent;
55   window->Initialize(posSize, name, className);
56   return window;
57 }
58
59 void Window::SetAdaptor(Dali::Adaptor& adaptor)
60 {
61   DALI_ASSERT_ALWAYS( !mStarted && "Adaptor already started" );
62   mStarted = true;
63
64   // Only create one overlay per window
65   Internal::Adaptor::Adaptor& adaptorImpl = Internal::Adaptor::Adaptor::GetImplementation(adaptor);
66   Integration::Core& core = adaptorImpl.GetCore();
67   mOverlay = &core.GetSystemOverlay();
68
69   Dali::RenderTaskList taskList = mOverlay->GetOverlayRenderTasks();
70   taskList.CreateTask();
71
72   mAdaptor = &adaptorImpl;
73   mAdaptor->AddObserver( *this );
74
75   // Can only create the detector when we know the Core has been instantiated.
76   mDragAndDropDetector = DragAndDropDetector::New();
77   mAdaptor->SetDragAndDropDetector( &GetImplementation( mDragAndDropDetector ) );
78
79
80 }
81
82 RenderSurface* Window::GetSurface()
83 {
84   return mSurface;
85 }
86
87 void Window::ShowIndicator( Dali::Window::IndicatorVisibleMode visibleMode )
88 {
89
90 }
91
92 void Window::RotateIndicator(Dali::Window::WindowOrientation orientation)
93 {
94 }
95
96 void Window::SetIndicatorBgOpacity( Dali::Window::IndicatorBgOpacity opacityMode )
97 {
98 }
99
100 void Window::SetClass(std::string name, std::string klass)
101 {
102 }
103
104 Window::Window()
105 : mSurface( NULL ),
106   mIndicatorVisible( Dali::Window::VISIBLE ),
107   mIndicatorIsShown( false ),
108   mShowRotatedIndicatorOnClose( false ),
109   mStarted( false ),
110   mIsTransparent( false ),
111   mWMRotationAppSet( false ),
112   mIsFocusAcceptable( true ),
113   mVisible( true ),
114   mIndicator( NULL ),
115   mIndicatorOrientation( Dali::Window::PORTRAIT ),
116   mNextIndicatorOrientation( Dali::Window::PORTRAIT ),
117   mIndicatorOpacityMode( Dali::Window::OPAQUE ),
118   mOverlay( NULL ),
119   mAdaptor( NULL ),
120   mPreferredOrientation( Dali::Window::PORTRAIT ),
121   mSupportedAuxiliaryHints(),
122   mAuxiliaryHints()
123 {
124   mEventHandler = NULL;
125 }
126
127 Window::~Window()
128 {
129   delete mEventHandler;
130
131   if ( mAdaptor )
132   {
133     mAdaptor->RemoveObserver( *this );
134     mAdaptor->SetDragAndDropDetector( NULL );
135     mAdaptor = NULL;
136   }
137
138   delete mSurface;
139 }
140
141 void Window::Initialize(const PositionSize& windowPosition, const std::string& name, const std::string& className)
142 {
143   // create an Wayland window by default
144   Any surface;
145   Wayland::RenderSurface* windowSurface = new Wayland::RenderSurface( windowPosition, surface, name, mIsTransparent );
146
147   mSurface = windowSurface;
148
149   mOrientation = Orientation::New(this);
150
151 }
152
153 void Window::DoShowIndicator( Dali::Window::WindowOrientation lastOrientation )
154 {
155
156 }
157
158 void Window::DoRotateIndicator( Dali::Window::WindowOrientation orientation )
159 {
160
161 }
162
163 void Window::SetIndicatorProperties( bool isShow, Dali::Window::WindowOrientation lastOrientation )
164 {
165 }
166
167 void Window::IndicatorTypeChanged(IndicatorInterface::Type type)
168 {
169 }
170
171 void Window::IndicatorClosed( IndicatorInterface* indicator )
172 {
173
174 }
175
176 void Window::IndicatorVisibilityChanged(bool isVisible)
177 {
178
179 }
180
181 void Window::SetIndicatorActorRotation()
182 {
183
184 }
185
186 void Window::Raise()
187 {
188 }
189
190 void Window::Lower()
191 {
192 }
193
194 void Window::Activate()
195 {
196 }
197
198 Dali::DragAndDropDetector Window::GetDragAndDropDetector() const
199 {
200   return mDragAndDropDetector;
201 }
202
203 Dali::Any Window::GetNativeHandle() const
204 {
205   Wayland::RenderSurface* surface = static_cast<  Wayland::RenderSurface* >( mSurface );
206
207   return surface->GetWindow();
208 }
209
210 void Window::OnStart()
211 {
212 }
213
214 void Window::OnPause()
215 {
216 }
217
218 void Window::OnResume()
219 {
220 }
221
222 void Window::OnStop()
223 {
224 }
225
226 void Window::OnDestroy()
227 {
228   mAdaptor = NULL;
229 }
230
231 void Window::AddAvailableOrientation(Dali::Window::WindowOrientation orientation)
232 {
233   bool found = false;
234
235   for( std::size_t i=0; i<mAvailableOrientations.size(); i++ )
236   {
237     if(mAvailableOrientations[i] == orientation)
238     {
239       found = true;
240       break;
241     }
242   }
243
244   if( ! found )
245   {
246     mAvailableOrientations.push_back(orientation);
247     SetAvailableOrientations( mAvailableOrientations );
248   }
249 }
250
251 void Window::RemoveAvailableOrientation(Dali::Window::WindowOrientation orientation)
252 {
253   for( std::vector<Dali::Window::WindowOrientation>::iterator iter = mAvailableOrientations.begin();
254        iter != mAvailableOrientations.end(); ++iter )
255   {
256     if( *iter == orientation )
257     {
258       mAvailableOrientations.erase( iter );
259       break;
260     }
261   }
262   SetAvailableOrientations( mAvailableOrientations );
263 }
264
265 void Window::SetAvailableOrientations(const std::vector<Dali::Window::WindowOrientation>& orientations)
266 {
267   DALI_ASSERT_ALWAYS( mAvailableOrientations.size() <= 4 && "Incorrect number of available orientations" );
268 }
269
270 const std::vector<Dali::Window::WindowOrientation>& Window::GetAvailableOrientations()
271 {
272   return mAvailableOrientations;
273 }
274
275 void Window::SetPreferredOrientation(Dali::Window::WindowOrientation orientation)
276 {
277   mPreferredOrientation = orientation;
278 }
279
280 Dali::Window::WindowOrientation Window::GetPreferredOrientation()
281 {
282   return mPreferredOrientation;
283 }
284
285 void Window::SetAcceptFocus( bool accept )
286 {
287   mIsFocusAcceptable = accept;
288 }
289
290 bool Window::IsFocusAcceptable()
291 {
292   return mIsFocusAcceptable;
293 }
294
295 void Window::Show()
296 {
297   mVisible = true;
298 }
299
300 void Window::Hide()
301 {
302   mVisible = false;
303 }
304
305 bool Window::IsVisible() const
306 {
307   return mVisible;
308 }
309
310
311 void Window::RotationDone( int orientation, int width, int height )
312 {
313 }
314
315 unsigned int Window::GetSupportedAuxiliaryHintCount()
316 {
317   return 0;
318 }
319
320 std::string Window::GetSupportedAuxiliaryHint( unsigned int index )
321 {
322   return std::string();
323 }
324
325 unsigned int Window::AddAuxiliaryHint( const std::string& hint, const std::string& value )
326 {
327   return -1;
328 }
329
330 bool Window::RemoveAuxiliaryHint( unsigned int id )
331 {
332   return false;
333 }
334
335 bool Window::SetAuxiliaryHintValue( unsigned int id, const std::string& value )
336 {
337   return false;
338 }
339
340 std::string Window::GetAuxiliaryHintValue( unsigned int id ) const
341 {
342   return std::string();
343 }
344
345 unsigned int Window::GetAuxiliaryHintId( const std::string& hint ) const
346 {
347   return -1;
348 }
349
350 void Window::SetInputRegion( const Rect< int >& inputRegion )
351 {
352 }
353
354 } // Adaptor
355 } // Internal
356 } // Dali