2 * Copyright (c) 2017 Samsung Electronics Co., Ltd.
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
8 * http://www.apache.org/licenses/LICENSE-2.0
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.
19 #include "window-impl.h"
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>
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>
42 #if defined(DEBUG_ENABLED)
43 Debug::Filter* gWindowLogFilter = Debug::Filter::New(Debug::Concise, false, "LOG_WINDOW");
46 struct Window::EventHandler
51 Window* Window::New(const PositionSize& posSize, const std::string& name, const std::string& className, bool isTransparent)
53 Window* window = new Window();
54 window->mIsTransparent = isTransparent;
55 window->Initialize(posSize, name, className);
59 void Window::SetAdaptor(Dali::Adaptor& adaptor)
61 DALI_ASSERT_ALWAYS( !mStarted && "Adaptor already started" );
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();
69 Dali::RenderTaskList taskList = mOverlay->GetOverlayRenderTasks();
70 taskList.CreateTask();
72 mAdaptor = &adaptorImpl;
73 mAdaptor->AddObserver( *this );
75 // Can only create the detector when we know the Core has been instantiated.
76 mDragAndDropDetector = DragAndDropDetector::New();
77 mAdaptor->SetDragAndDropDetector( &GetImplementation( mDragAndDropDetector ) );
82 RenderSurface* Window::GetSurface()
87 void Window::ShowIndicator( Dali::Window::IndicatorVisibleMode visibleMode )
92 void Window::RotateIndicator(Dali::Window::WindowOrientation orientation)
96 void Window::SetIndicatorBgOpacity( Dali::Window::IndicatorBgOpacity opacityMode )
100 void Window::SetClass(std::string name, std::string klass)
106 mIndicatorVisible( Dali::Window::VISIBLE ),
107 mIndicatorIsShown( false ),
108 mShowRotatedIndicatorOnClose( false ),
110 mIsTransparent( false ),
111 mWMRotationAppSet( false ),
112 mIsFocusAcceptable( true ),
115 mIndicatorOrientation( Dali::Window::PORTRAIT ),
116 mNextIndicatorOrientation( Dali::Window::PORTRAIT ),
117 mIndicatorOpacityMode( Dali::Window::OPAQUE ),
120 mPreferredOrientation( Dali::Window::PORTRAIT )
122 mEventHandler = NULL;
127 delete mEventHandler;
131 mAdaptor->RemoveObserver( *this );
132 mAdaptor->SetDragAndDropDetector( NULL );
139 void Window::Initialize(const PositionSize& windowPosition, const std::string& name, const std::string& className)
141 // create an Wayland window by default
143 Wayland::RenderSurface* windowSurface = new Wayland::RenderSurface( windowPosition, surface, name, mIsTransparent );
145 mSurface = windowSurface;
147 mOrientation = Orientation::New(this);
151 void Window::DoShowIndicator( Dali::Window::WindowOrientation lastOrientation )
156 void Window::DoRotateIndicator( Dali::Window::WindowOrientation orientation )
161 void Window::SetIndicatorProperties( bool isShow, Dali::Window::WindowOrientation lastOrientation )
165 void Window::IndicatorTypeChanged(IndicatorInterface::Type type)
169 void Window::IndicatorClosed( IndicatorInterface* indicator )
174 void Window::IndicatorVisibilityChanged(bool isVisible)
179 void Window::SetIndicatorActorRotation()
192 void Window::Activate()
196 Dali::DragAndDropDetector Window::GetDragAndDropDetector() const
198 return mDragAndDropDetector;
201 Dali::Any Window::GetNativeHandle() const
203 Wayland::RenderSurface* surface = static_cast< Wayland::RenderSurface* >( mSurface );
205 return surface->GetWindow();
208 void Window::OnStart()
212 void Window::OnPause()
216 void Window::OnResume()
220 void Window::OnStop()
224 void Window::OnDestroy()
229 void Window::AddAvailableOrientation(Dali::Window::WindowOrientation orientation)
233 for( std::size_t i=0; i<mAvailableOrientations.size(); i++ )
235 if(mAvailableOrientations[i] == orientation)
244 mAvailableOrientations.push_back(orientation);
245 SetAvailableOrientations( mAvailableOrientations );
249 void Window::RemoveAvailableOrientation(Dali::Window::WindowOrientation orientation)
251 for( std::vector<Dali::Window::WindowOrientation>::iterator iter = mAvailableOrientations.begin();
252 iter != mAvailableOrientations.end(); ++iter )
254 if( *iter == orientation )
256 mAvailableOrientations.erase( iter );
260 SetAvailableOrientations( mAvailableOrientations );
263 void Window::SetAvailableOrientations(const std::vector<Dali::Window::WindowOrientation>& orientations)
265 DALI_ASSERT_ALWAYS( mAvailableOrientations.size() <= 4 && "Incorrect number of available orientations" );
268 const std::vector<Dali::Window::WindowOrientation>& Window::GetAvailableOrientations()
270 return mAvailableOrientations;
273 void Window::SetPreferredOrientation(Dali::Window::WindowOrientation orientation)
275 mPreferredOrientation = orientation;
278 Dali::Window::WindowOrientation Window::GetPreferredOrientation()
280 return mPreferredOrientation;
283 void Window::SetAcceptFocus( bool accept )
285 mIsFocusAcceptable = accept;
288 bool Window::IsFocusAcceptable()
290 return mIsFocusAcceptable;
303 bool Window::IsVisible() const
309 void Window::RotationDone( int orientation, int width, int height )