New Window constructor added.
[platform/core/uifw/dali-adaptor.git] / dali / internal / window-system / common / window-impl.cpp
1 /*
2  * Copyright (c) 2019 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 <dali/internal/window-system/common/window-impl.h>
20
21 // EXTERNAL HEADERS
22 #include <dali/integration-api/core.h>
23 #include <dali/public-api/actors/actor.h>
24 #include <dali/public-api/actors/layer.h>
25 #include <dali/public-api/actors/camera-actor.h>
26 #include <dali/public-api/render-tasks/render-task.h>
27 #include <dali/public-api/render-tasks/render-task-list.h>
28 #include <dali/public-api/rendering/frame-buffer.h>
29 #include <dali/devel-api/adaptor-framework/orientation.h>
30 #include <dali/integration-api/events/touch-event-integ.h>
31
32 // INTERNAL HEADERS
33 #include <dali/integration-api/adaptor-framework/render-surface-interface.h>
34 #include <dali/internal/window-system/common/event-handler.h>
35 #include <dali/internal/window-system/common/orientation-impl.h>
36 #include <dali/internal/window-system/common/render-surface-factory.h>
37 #include <dali/internal/window-system/common/window-factory.h>
38 #include <dali/internal/window-system/common/window-base.h>
39 #include <dali/internal/window-system/common/window-system.h>
40 #include <dali/internal/window-system/common/window-render-surface.h>
41 #include <dali/internal/window-system/common/window-visibility-observer.h>
42
43 namespace Dali
44 {
45 namespace Internal
46 {
47 namespace Adaptor
48 {
49
50 namespace
51 {
52
53 #if defined(DEBUG_ENABLED)
54 Debug::Filter* gWindowLogFilter = Debug::Filter::New( Debug::NoLogging, false, "LOG_WINDOW" );
55 #endif
56
57 } // unnamed namespace
58
59 Window* Window::New(const PositionSize& positionSize, const std::string& name, const std::string& className, bool isTransparent)
60 {
61   Any surface;
62   return Window::New(surface, positionSize, name, className, isTransparent);
63 }
64
65 Window* Window::New(Any surface, const PositionSize& positionSize, const std::string& name, const std::string& className, bool isTransparent)
66 {
67   Window* window = new Window();
68   window->mIsTransparent = isTransparent;
69   window->Initialize(surface, positionSize, name, className);
70   return window;
71 }
72
73 Window::Window()
74 : mWindowSurface( nullptr ),
75   mWindowBase(),
76   mIsTransparent( false ),
77   mIsFocusAcceptable( true ),
78   mIconified( false ),
79   mOpaqueState( false ),
80   mResizeEnabled( false ),
81   mType( Dali::Window::NORMAL ),
82   mParentWindow( NULL ),
83   mPreferredAngle( Dali::Window::NO_ORIENTATION_PREFERENCE ),
84   mRotationAngle( -1 ),
85   mWindowWidth( 0 ),
86   mWindowHeight( 0 ),
87   mOrientationMode( Internal::Adaptor::Window::OrientationMode::PORTRAIT ),
88   mNativeWindowId( -1 ),
89   mFocusChangedSignal(),
90   mResizedSignal(),
91   mDeleteRequestSignal(),
92   mFocusChangeSignal(),
93   mResizeSignal(),
94   mVisibilityChangedSignal(),
95   mTransitionEffectEventSignal()
96 {
97 }
98
99 Window::~Window()
100 {
101   if ( mEventHandler )
102   {
103     mEventHandler->RemoveObserver( *this );
104   }
105 }
106
107 void Window::Initialize(Any surface, const PositionSize& positionSize, const std::string& name, const std::string& className)
108 {
109   // Create a window render surface
110   auto renderSurfaceFactory = Dali::Internal::Adaptor::GetRenderSurfaceFactory();
111   mSurface = renderSurfaceFactory->CreateWindowRenderSurface( positionSize, surface, mIsTransparent );
112   mWindowSurface = static_cast<WindowRenderSurface*>( mSurface.get() );
113
114   // Get a window base
115   mWindowBase = mWindowSurface->GetWindowBase();
116
117   // Connect signals
118   mWindowBase->IconifyChangedSignal().Connect( this, &Window::OnIconifyChanged );
119   mWindowBase->FocusChangedSignal().Connect( this, &Window::OnFocusChanged );
120   mWindowBase->DeleteRequestSignal().Connect( this, &Window::OnDeleteRequest );
121   mWindowBase->TransitionEffectEventSignal().Connect( this, &Window::OnTransitionEffectEvent );
122
123   mWindowSurface->OutputTransformedSignal().Connect( this, &Window::OnOutputTransformed );
124
125   if( !positionSize.IsEmpty() )
126   {
127     AddAuxiliaryHint( "wm.policy.win.user.geometry", "1" );
128     mResizeEnabled = true;
129   }
130
131   SetClass( name, className );
132
133   mWindowSurface->Map();
134
135   mOrientation = Orientation::New( this );
136
137   // Get OrientationMode
138   int screenWidth, screenHeight;
139   WindowSystem::GetScreenSize( screenWidth, screenHeight );
140   if( screenWidth > screenHeight )
141   {
142     mOrientationMode = Internal::Adaptor::Window::OrientationMode::LANDSCAPE;
143   }
144   else
145   {
146     mOrientationMode = Internal::Adaptor::Window::OrientationMode::PORTRAIT;
147   }
148   // For Debugging
149   mNativeWindowId = mWindowBase->GetNativeWindowId();
150 }
151
152 void Window::OnAdaptorSet(Dali::Adaptor& adaptor)
153 {
154   mEventHandler = EventHandlerPtr(new EventHandler( mWindowSurface, *mAdaptor ) );
155   mEventHandler->AddObserver( *this );
156 }
157
158 void Window::OnSurfaceSet( Dali::RenderSurfaceInterface* surface )
159 {
160   mWindowSurface = static_cast<WindowRenderSurface*>( surface );
161 }
162
163 void Window::ShowIndicator( Dali::Window::IndicatorVisibleMode visibleMode )
164 {
165 }
166
167 void Window::SetIndicatorBgOpacity( Dali::Window::IndicatorBgOpacity opacityMode )
168 {
169 }
170
171 void Window::RotateIndicator( Dali::Window::WindowOrientation orientation )
172 {
173 }
174
175 void Window::SetClass( std::string name, std::string className )
176 {
177   mName = name;
178   mClassName = className;
179   mWindowBase->SetClass( name, className );
180 }
181
182 std::string Window::GetClassName() const
183 {
184   return mClassName;
185 }
186
187 void Window::Raise()
188 {
189   mWindowBase->Raise();
190   DALI_LOG_RELEASE_INFO( "Window (%p), WinId (%d), Raise() \n", this, mNativeWindowId );
191 }
192
193 void Window::Lower()
194 {
195   mWindowBase->Lower();
196   DALI_LOG_RELEASE_INFO( "Window (%p), WinId (%d), Lower() \n", this, mNativeWindowId );
197 }
198
199 void Window::Activate()
200 {
201   mWindowBase->Activate();
202   DALI_LOG_RELEASE_INFO( "Window (%p), WinId (%d), Activate() \n", this, mNativeWindowId );
203 }
204
205 uint32_t Window::GetLayerCount() const
206 {
207   return mScene.GetLayerCount();
208 }
209
210 Dali::Layer Window::GetLayer( uint32_t depth ) const
211 {
212   return mScene.GetLayer( depth );
213 }
214
215 Dali::RenderTaskList Window::GetRenderTaskList() const
216 {
217   return mScene.GetRenderTaskList();
218 }
219
220 void Window::AddAvailableOrientation( Dali::Window::WindowOrientation orientation )
221 {
222   if( IsOrientationAvailable( orientation ) == false )
223   {
224     return;
225   }
226
227   bool found = false;
228   int convertedAngle = ConvertToAngle( orientation );
229   DALI_LOG_RELEASE_INFO( "Window (%p), WinId (%d), AddAvailableOrientation: %d\n", this, mNativeWindowId, convertedAngle );
230   for( std::size_t i = 0; i < mAvailableAngles.size(); i++ )
231   {
232     if( mAvailableAngles[i] == convertedAngle )
233     {
234       found = true;
235       break;
236     }
237   }
238
239   if( !found )
240   {
241     mAvailableAngles.push_back( convertedAngle );
242     SetAvailableAnlges( mAvailableAngles );
243   }
244 }
245
246 void Window::RemoveAvailableOrientation( Dali::Window::WindowOrientation orientation )
247 {
248   if( IsOrientationAvailable( orientation ) == false )
249   {
250     return;
251   }
252
253   int convertedAngle = ConvertToAngle( orientation );
254   DALI_LOG_RELEASE_INFO( "Window (%p), WinId (%d), RemoveAvailableOrientation: %d\n", this, mNativeWindowId, convertedAngle );
255   for( std::vector< int >::iterator iter = mAvailableAngles.begin();
256        iter != mAvailableAngles.end(); ++iter )
257   {
258     if( *iter == convertedAngle )
259     {
260       mAvailableAngles.erase( iter );
261       break;
262     }
263   }
264
265   SetAvailableAnlges( mAvailableAngles );
266 }
267
268 void Window::SetPreferredOrientation( Dali::Window::WindowOrientation orientation )
269 {
270   if( orientation < Dali::Window::NO_ORIENTATION_PREFERENCE || orientation > Dali::Window::LANDSCAPE_INVERSE )
271   {
272     DALI_LOG_INFO( gWindowLogFilter, Debug::Verbose, "Window::CheckOrientation: Invalid input orientation [%d]\n", orientation );
273     return;
274   }
275   mPreferredAngle = ConvertToAngle( orientation );
276   DALI_LOG_RELEASE_INFO( "Window (%p), WinId (%d), SetPreferredOrientation: %d\n", this, mNativeWindowId, mPreferredAngle );
277   mWindowBase->SetPreferredAngle( mPreferredAngle );
278 }
279
280 Dali::Window::WindowOrientation Window::GetPreferredOrientation()
281 {
282   DALI_LOG_RELEASE_INFO( "Window (%p), WinId (%d), GetPreferredOrientation: %d\n", this, mNativeWindowId, mPreferredAngle );
283   Dali::Window::WindowOrientation preferredOrientation = ConvertToOrientation( mPreferredAngle );
284   return preferredOrientation;
285 }
286
287 void Window::SetAvailableAnlges( const std::vector< int >& angles )
288 {
289   if( angles.size() > 4 )
290   {
291     DALI_LOG_INFO( gWindowLogFilter, Debug::Verbose, "Window::SetAvailableAnlges: Invalid vector size! [%d]\n", angles.size() );
292     return;
293   }
294
295   mWindowBase->SetAvailableAnlges( angles );
296 }
297
298 int Window::ConvertToAngle( Dali::Window::WindowOrientation orientation )
299 {
300   int convertAngle = static_cast< int >( orientation );
301   if( mOrientationMode == Internal::Adaptor::Window::OrientationMode::LANDSCAPE )
302   {
303     switch( orientation )
304     {
305       case Dali::Window::LANDSCAPE:
306       {
307         convertAngle = 0;
308         break;
309       }
310       case Dali::Window::PORTRAIT:
311       {
312         convertAngle = 90;
313         break;
314       }
315       case Dali::Window::LANDSCAPE_INVERSE:
316       {
317         convertAngle = 180;
318         break;
319       }
320       case Dali::Window::PORTRAIT_INVERSE:
321       {
322         convertAngle = 270;
323         break;
324       }
325       case Dali::Window::NO_ORIENTATION_PREFERENCE:
326       {
327         convertAngle = -1;
328         break;
329       }
330     }
331   }
332   return convertAngle;
333 }
334
335 Dali::Window::WindowOrientation Window::ConvertToOrientation( int angle ) const
336 {
337   Dali::Window::WindowOrientation orientation = static_cast< Dali::Window::WindowOrientation >( angle );
338   if( mOrientationMode == Internal::Adaptor::Window::OrientationMode::LANDSCAPE )
339   {
340     switch( angle )
341     {
342       case 0:
343       {
344         orientation = Dali::Window::LANDSCAPE;
345         break;
346       }
347       case 90:
348       {
349         orientation = Dali::Window::PORTRAIT;
350         break;
351       }
352       case 180:
353       {
354         orientation = Dali::Window::LANDSCAPE_INVERSE;
355         break;
356       }
357       case 270:
358       {
359         orientation = Dali::Window::PORTRAIT_INVERSE;
360         break;
361       }
362       case -1:
363       {
364         orientation = Dali::Window::NO_ORIENTATION_PREFERENCE;
365         break;
366       }
367     }
368   }
369   return orientation;
370 }
371
372 bool Window::IsOrientationAvailable( Dali::Window::WindowOrientation orientation ) const
373 {
374   if( orientation <= Dali::Window::NO_ORIENTATION_PREFERENCE || orientation > Dali::Window::LANDSCAPE_INVERSE )
375   {
376     DALI_LOG_INFO( gWindowLogFilter, Debug::Verbose, "Window::IsOrientationAvailable: Invalid input orientation [%d]\n", orientation );
377     return false;
378   }
379   return true;
380 }
381
382 Dali::Any Window::GetNativeHandle() const
383 {
384   return mWindowSurface->GetNativeWindow();
385 }
386
387 void Window::SetAcceptFocus( bool accept )
388 {
389   mIsFocusAcceptable = accept;
390
391   mWindowBase->SetAcceptFocus( accept );
392 }
393
394 bool Window::IsFocusAcceptable() const
395 {
396   return mIsFocusAcceptable;
397 }
398
399 void Window::Show()
400 {
401   mVisible = true;
402
403   mWindowBase->Show();
404
405   if( !mIconified )
406   {
407     WindowVisibilityObserver* observer( mAdaptor );
408     observer->OnWindowShown();
409
410     Dali::Window handle( this );
411     mVisibilityChangedSignal.Emit( handle, true );
412   }
413
414   DALI_LOG_RELEASE_INFO( "Window (%p), WinId (%d), Show(): iconified = %d, visible = %d\n", this, mNativeWindowId, mIconified, mVisible );
415 }
416
417 void Window::Hide()
418 {
419   mVisible = false;
420
421   mWindowBase->Hide();
422
423   if( !mIconified )
424   {
425     WindowVisibilityObserver* observer( mAdaptor );
426     observer->OnWindowHidden();
427
428     Dali::Window handle( this );
429     mVisibilityChangedSignal.Emit( handle, false );
430   }
431
432   DALI_LOG_RELEASE_INFO( "Window (%p), WinId (%d), Hide(): iconified = %d, visible = %d\n", this, mNativeWindowId, mIconified, mVisible );
433 }
434
435 bool Window::IsVisible() const
436 {
437   DALI_LOG_RELEASE_INFO( "Window (%p), WinId (%d), IsVisible(): iconified = %d, visible = %d\n", this, mNativeWindowId, mIconified, mVisible );
438   return mVisible && !mIconified;
439 }
440
441 unsigned int Window::GetSupportedAuxiliaryHintCount() const
442 {
443   return mWindowBase->GetSupportedAuxiliaryHintCount();
444 }
445
446 std::string Window::GetSupportedAuxiliaryHint( unsigned int index ) const
447 {
448   return mWindowBase->GetSupportedAuxiliaryHint( index );
449 }
450
451 unsigned int Window::AddAuxiliaryHint( const std::string& hint, const std::string& value )
452 {
453   return mWindowBase->AddAuxiliaryHint( hint, value );
454 }
455
456 bool Window::RemoveAuxiliaryHint( unsigned int id )
457 {
458   return mWindowBase->RemoveAuxiliaryHint( id );
459 }
460
461 bool Window::SetAuxiliaryHintValue( unsigned int id, const std::string& value )
462 {
463   return mWindowBase->SetAuxiliaryHintValue( id, value );
464 }
465
466 std::string Window::GetAuxiliaryHintValue( unsigned int id ) const
467 {
468   return mWindowBase->GetAuxiliaryHintValue( id );
469 }
470
471 unsigned int Window::GetAuxiliaryHintId( const std::string& hint ) const
472 {
473   return mWindowBase->GetAuxiliaryHintId( hint );
474 }
475
476 void Window::SetInputRegion( const Rect< int >& inputRegion )
477 {
478   mWindowBase->SetInputRegion( inputRegion );
479
480   DALI_LOG_INFO( gWindowLogFilter, Debug::Verbose, "Window::SetInputRegion: x = %d, y = %d, w = %d, h = %d\n", inputRegion.x, inputRegion.y, inputRegion.width, inputRegion.height );
481 }
482
483 void Window::SetType( Dali::Window::Type type )
484 {
485   if( type != mType )
486   {
487     mWindowBase->SetType( type );
488
489     mType = type;
490   }
491 }
492
493 Dali::Window::Type Window::GetType() const
494 {
495   return mType;
496 }
497
498 bool Window::SetNotificationLevel( Dali::Window::NotificationLevel::Type level )
499 {
500   if( mType != Dali::Window::NOTIFICATION )
501   {
502     DALI_LOG_INFO( gWindowLogFilter, Debug::Verbose, "Window::SetNotificationLevel: Not supported window type [%d]\n", mType );
503     return false;
504   }
505
506   return mWindowBase->SetNotificationLevel( level );
507 }
508
509 Dali::Window::NotificationLevel::Type Window::GetNotificationLevel() const
510 {
511   if( mType != Dali::Window::NOTIFICATION )
512   {
513     DALI_LOG_INFO( gWindowLogFilter, Debug::Verbose, "Window::GetNotificationLevel: Not supported window type [%d]\n", mType );
514     return Dali::Window::NotificationLevel::NONE;
515   }
516
517   return mWindowBase->GetNotificationLevel();
518 }
519
520 void Window::SetOpaqueState( bool opaque )
521 {
522   mOpaqueState = opaque;
523
524   mWindowBase->SetOpaqueState( opaque );
525
526   DALI_LOG_INFO( gWindowLogFilter, Debug::Verbose, "Window::SetOpaqueState: opaque = %d\n", opaque );
527 }
528
529 bool Window::IsOpaqueState() const
530 {
531   return mOpaqueState;
532 }
533
534 bool Window::SetScreenOffMode(Dali::Window::ScreenOffMode::Type screenOffMode)
535 {
536   return mWindowBase->SetScreenOffMode( screenOffMode );
537 }
538
539 Dali::Window::ScreenOffMode::Type Window::GetScreenOffMode() const
540 {
541   return mWindowBase->GetScreenOffMode();
542 }
543
544 bool Window::SetBrightness( int brightness )
545 {
546   if( brightness < 0 || brightness > 100 )
547   {
548     DALI_LOG_INFO( gWindowLogFilter, Debug::Verbose, "Window::SetBrightness: Invalid brightness value [%d]\n", brightness );
549     return false;
550   }
551
552   return mWindowBase->SetBrightness( brightness );
553 }
554
555 int Window::GetBrightness() const
556 {
557   return mWindowBase->GetBrightness();
558 }
559
560 void Window::SetSize( Dali::Window::WindowSize size )
561 {
562   if( !mResizeEnabled )
563   {
564     AddAuxiliaryHint( "wm.policy.win.user.geometry", "1" );
565     mResizeEnabled = true;
566   }
567
568   PositionSize oldRect = mSurface->GetPositionSize();
569
570   mWindowSurface->MoveResize( PositionSize( oldRect.x, oldRect.y, size.GetWidth(), size.GetHeight() ) );
571
572   PositionSize newRect = mSurface->GetPositionSize();
573
574   // When surface size is updated, inform adaptor of resizing and emit ResizeSignal
575   if( ( oldRect.width != newRect.width ) || ( oldRect.height != newRect.height ) )
576   {
577     Uint16Pair newSize( newRect.width, newRect.height );
578
579     SurfaceResized();
580
581     mAdaptor->SurfaceResizePrepare( mSurface.get(), newSize );
582
583     DALI_LOG_RELEASE_INFO( "Window (%p), WinId (%d), SetSize(): resize signal [%d x %d]\n", this, mNativeWindowId, newRect.width, newRect.height );
584
585     Dali::Window handle( this );
586     mResizedSignal.Emit( newSize );
587     mResizeSignal.Emit( handle, newSize );
588
589     mAdaptor->SurfaceResizeComplete( mSurface.get(), newSize );
590   }
591 }
592
593 Dali::Window::WindowSize Window::GetSize() const
594 {
595   PositionSize positionSize = mSurface->GetPositionSize();
596
597   return Dali::Window::WindowSize( positionSize.width, positionSize.height );
598 }
599
600 void Window::SetPosition( Dali::Window::WindowPosition position )
601 {
602   if( !mResizeEnabled )
603   {
604     AddAuxiliaryHint( "wm.policy.win.user.geometry", "1" );
605     mResizeEnabled = true;
606   }
607
608   PositionSize oldRect = mSurface->GetPositionSize();
609
610   mWindowSurface->MoveResize( PositionSize( position.GetX(), position.GetY(), oldRect.width, oldRect.height ) );
611 }
612
613 Dali::Window::WindowPosition Window::GetPosition() const
614 {
615   PositionSize positionSize = mSurface->GetPositionSize();
616
617   return Dali::Window::WindowPosition( positionSize.x, positionSize.y );
618 }
619
620 void Window::SetPositionSize( PositionSize positionSize )
621 {
622   if( !mResizeEnabled )
623   {
624     AddAuxiliaryHint( "wm.policy.win.user.geometry", "1" );
625     mResizeEnabled = true;
626   }
627
628   PositionSize oldRect = mSurface->GetPositionSize();
629
630   mWindowSurface->MoveResize( positionSize );
631
632   PositionSize newRect = mSurface->GetPositionSize();
633
634   // When surface size is updated, inform adaptor of resizing and emit ResizeSignal
635   if( ( oldRect.width != newRect.width ) || ( oldRect.height != newRect.height ) )
636   {
637     Uint16Pair newSize( newRect.width, newRect.height );
638
639     SurfaceResized();
640
641     mAdaptor->SurfaceResizePrepare( mSurface.get(), newSize );
642
643     DALI_LOG_RELEASE_INFO( "Window (%p), WinId (%d), SetPositionSize():resize signal [%d x %d]\n", this, mNativeWindowId, newRect.width, newRect.height );
644     Dali::Window handle( this );
645     mResizedSignal.Emit( newSize );
646     mResizeSignal.Emit( handle, newSize );
647     mAdaptor->SurfaceResizeComplete( mSurface.get(), newSize );
648   }
649 }
650
651 Dali::Layer Window::GetRootLayer() const
652 {
653   return mScene.GetRootLayer();
654 }
655
656 void Window::SetTransparency( bool transparent )
657 {
658   mWindowSurface->SetTransparency( transparent );
659 }
660
661 bool Window::GrabKey( Dali::KEY key, KeyGrab::KeyGrabMode grabMode )
662 {
663   return mWindowBase->GrabKey( key, grabMode );
664 }
665
666 bool Window::UngrabKey( Dali::KEY key )
667 {
668   return mWindowBase->UngrabKey( key );
669 }
670
671 bool Window::GrabKeyList( const Dali::Vector< Dali::KEY >& key, const Dali::Vector< KeyGrab::KeyGrabMode >& grabMode, Dali::Vector< bool >& result )
672 {
673   return mWindowBase->GrabKeyList( key, grabMode, result );
674 }
675
676 bool Window::UngrabKeyList( const Dali::Vector< Dali::KEY >& key, Dali::Vector< bool >& result )
677 {
678   return mWindowBase->UngrabKeyList( key, result );
679 }
680
681 void Window::OnIconifyChanged( bool iconified )
682 {
683   if( iconified )
684   {
685     mIconified = true;
686
687     if( mVisible )
688     {
689       WindowVisibilityObserver* observer( mAdaptor );
690       observer->OnWindowHidden();
691
692       Dali::Window handle( this );
693       mVisibilityChangedSignal.Emit( handle, false );
694     }
695
696     DALI_LOG_RELEASE_INFO( "Window (%p), WinId (%d), Iconified: visible = %d\n", this, mNativeWindowId, mVisible );
697   }
698   else
699   {
700     mIconified = false;
701
702     if( mVisible )
703     {
704       WindowVisibilityObserver* observer( mAdaptor );
705       observer->OnWindowShown();
706
707       Dali::Window handle( this );
708       mVisibilityChangedSignal.Emit( handle, true );
709     }
710
711     DALI_LOG_RELEASE_INFO( "Window (%p), WinId (%d), Deiconified: visible = %d\n", this, mNativeWindowId, mVisible );
712   }
713 }
714
715 void Window::OnFocusChanged( bool focusIn )
716 {
717   Dali::Window handle( this );
718   mFocusChangedSignal.Emit( focusIn );
719   mFocusChangeSignal.Emit( handle, focusIn );
720 }
721
722 void Window::OnOutputTransformed()
723 {
724   PositionSize positionSize = mSurface->GetPositionSize();
725   SurfaceResized();
726   mAdaptor->SurfaceResizePrepare( mSurface.get(), Adaptor::SurfaceSize( positionSize.width, positionSize.height ) );
727   mAdaptor->SurfaceResizeComplete( mSurface.get(), Adaptor::SurfaceSize( positionSize.width, positionSize.height ) );
728 }
729
730 void Window::OnDeleteRequest()
731 {
732   mDeleteRequestSignal.Emit();
733 }
734
735 void Window::OnTransitionEffectEvent( DevelWindow::EffectState state, DevelWindow::EffectType type )
736 {
737   Dali::Window handle( this );
738   mTransitionEffectEventSignal.Emit( handle, state, type );
739 }
740
741 void Window::OnTouchPoint( Dali::Integration::Point& point, int timeStamp )
742 {
743   FeedTouchPoint( point, timeStamp );
744 }
745
746 void Window::OnWheelEvent( Dali::Integration::WheelEvent& wheelEvent )
747 {
748   FeedWheelEvent( wheelEvent );
749 }
750
751 void Window::OnKeyEvent( Dali::Integration::KeyEvent& keyEvent )
752 {
753   FeedKeyEvent( keyEvent );
754 }
755
756 void Window::OnRotation( const RotationEvent& rotation )
757 {
758   mRotationAngle = rotation.angle;
759   mWindowWidth = rotation.width;
760   mWindowHeight = rotation.height;
761
762   // Notify that the orientation is changed
763   mOrientation->OnOrientationChange( rotation );
764
765   mWindowSurface->RequestRotation( mRotationAngle, mWindowWidth, mWindowHeight );
766
767   SurfaceResized();
768
769   mAdaptor->SurfaceResizePrepare( mSurface.get(), Adaptor::SurfaceSize( mWindowWidth, mWindowHeight ) );
770
771   DALI_LOG_RELEASE_INFO( "Window (%p), WinId (%d), OnRotation(): resize signal emit [%d x %d]\n", this, mNativeWindowId, mWindowWidth, mWindowHeight );
772   // Emit signal
773   Dali::Window handle( this );
774   mResizedSignal.Emit( Dali::Window::WindowSize( mWindowWidth, mWindowHeight ) );
775   mResizeSignal.Emit( handle, Dali::Window::WindowSize( mWindowWidth, mWindowHeight ) );
776
777   mAdaptor->SurfaceResizeComplete( mSurface.get(), Adaptor::SurfaceSize( mWindowWidth, mWindowHeight ) );
778 }
779
780 void Window::OnPause()
781 {
782   if( mEventHandler )
783   {
784     mEventHandler->Pause();
785   }
786 }
787
788 void Window::OnResume()
789 {
790   if( mEventHandler )
791   {
792     mEventHandler->Resume();
793   }
794 }
795
796 void Window::RecalculateTouchPosition( Integration::Point& point )
797 {
798   Vector2 position = point.GetScreenPosition();
799   Vector2 convertedPosition;
800
801   switch( mRotationAngle )
802   {
803     case 90:
804     {
805       convertedPosition.x = static_cast<float>( mWindowWidth ) - position.y;
806       convertedPosition.y = position.x;
807       break;
808     }
809     case 180:
810     {
811       convertedPosition.x = static_cast<float>( mWindowWidth ) - position.x;
812       convertedPosition.y = static_cast<float>( mWindowHeight ) - position.y;
813       break;
814     }
815     case 270:
816     {
817       convertedPosition.x = position.y;
818       convertedPosition.y = static_cast<float>( mWindowHeight ) - position.x;
819       break;
820     }
821     default:
822     {
823       convertedPosition = position;
824       break;
825     }
826   }
827
828   point.SetScreenPosition( convertedPosition );
829 }
830
831 Dali::Window Window::Get( Dali::Actor actor )
832 {
833   Internal::Adaptor::Window* windowImpl = nullptr;
834
835   if ( Internal::Adaptor::Adaptor::IsAvailable() )
836   {
837     Dali::Internal::Adaptor::Adaptor& adaptor = Internal::Adaptor::Adaptor::GetImplementation( Internal::Adaptor::Adaptor::Get() );
838     windowImpl = dynamic_cast<Internal::Adaptor::Window*>( adaptor.GetWindow( actor ) );
839     if( windowImpl )
840     {
841       return Dali::Window( windowImpl );
842     }
843   }
844
845   return Dali::Window();
846 }
847
848 void Window::SetParent( Dali::Window& parent )
849 {
850   if ( DALI_UNLIKELY( parent ) )
851   {
852     mParentWindow = parent;
853     Dali::Window self = Dali::Window( this );
854     // check circular parent window setting
855     if ( Dali::DevelWindow::GetParent( parent ) == self )
856     {
857       Dali::DevelWindow::Unparent( parent );
858     }
859     mWindowBase->SetParent( GetImplementation( mParentWindow ).mWindowBase );
860   }
861 }
862
863 void Window::Unparent()
864 {
865   mWindowBase->SetParent( nullptr );
866   mParentWindow.Reset();
867 }
868
869 Dali::Window Window::GetParent()
870 {
871   return mParentWindow;
872 }
873
874 Dali::Window::WindowOrientation Window::GetCurrentOrientation() const
875 {
876   DALI_LOG_RELEASE_INFO( "Window (%p), WinId (%d), GetCurrentOrientation(): %d\n", this, mNativeWindowId, mRotationAngle );
877   return ConvertToOrientation( mRotationAngle );
878 }
879
880 void Window::SetAvailableOrientations( const Dali::Vector<Dali::Window::WindowOrientation>& orientations )
881 {
882   Dali::Vector<float>::SizeType count = orientations.Count();
883   for( Dali::Vector<float>::SizeType index = 0; index < count; ++index )
884   {
885     if( IsOrientationAvailable( orientations[index] ) == false )
886     {
887       DALI_LOG_ERROR("Window::SetAvailableOrientations, invalid orientation: %d\n", orientations[index]);
888       continue;
889     }
890
891     bool found = false;
892     int convertedAngle = ConvertToAngle( orientations[index] );
893
894     for( std::size_t i = 0; i < mAvailableAngles.size(); i++ )
895     {
896       if( mAvailableAngles[i] == convertedAngle )
897       {
898         found = true;
899         break;
900       }
901     }
902
903     if( !found )
904     {
905       DALI_LOG_RELEASE_INFO( "Window (%p), WinId (%d), SetAvailableOrientations: %d\n", this, mNativeWindowId, convertedAngle );
906       mAvailableAngles.push_back( convertedAngle );
907     }
908   }
909   SetAvailableAnlges( mAvailableAngles );
910 }
911
912 } // Adaptor
913
914 } // Internal
915
916 } // Dali