+void Control::Impl::OnStageDisconnection()
+{
+ Actor self = mControlImpl.Self();
+
+ // Any visuals set for replacement but not yet ready should still be registered.
+ // Reason: If a request was made to register a new visual but the control removed from stage before visual was ready
+ // then when this control appears back on stage it should use that new visual.
+
+ // Iterate through all registered visuals and set off stage
+ SetVisualsOffStage( mVisuals, self );
+
+ // Visuals pending replacement can now be taken out of the removal list and set off stage
+ // Iterate through all replacement visuals and add to a move queue then set off stage
+ for( auto removalIter = mRemoveVisuals.Begin(), end = mRemoveVisuals.End(); removalIter != end; removalIter++ )
+ {
+ Toolkit::GetImplementation((*removalIter)->visual).SetOffStage( self );
+ }
+
+ for( auto replacedIter = mVisuals.Begin(), end = mVisuals.End(); replacedIter != end; replacedIter++ )
+ {
+ (*replacedIter)->pending = false;
+ }
+
+ mRemoveVisuals.Clear();
+}
+
+void Control::Impl::SetMargin( Extents margin )
+{
+ mControlImpl.mImpl->mMargin = margin;
+
+ // Trigger a size negotiation request that may be needed when setting a margin.
+ mControlImpl.RelayoutRequest();
+}
+
+Extents Control::Impl::GetMargin() const
+{
+ return mControlImpl.mImpl->mMargin;
+}
+
+void Control::Impl::SetPadding( Extents padding )
+{
+ mControlImpl.mImpl->mPadding = padding;
+
+ // Trigger a size negotiation request that may be needed when setting a padding.
+ mControlImpl.RelayoutRequest();
+}
+
+Extents Control::Impl::GetPadding() const
+{
+ return mControlImpl.mImpl->mPadding;
+}
+
+void Control::Impl::SetInputMethodContext( InputMethodContext& inputMethodContext )
+{
+ mInputMethodContext = inputMethodContext;
+}
+
+bool Control::Impl::FilterKeyEvent( const KeyEvent& event )
+{
+ bool consumed ( false );
+
+ if ( mInputMethodContext )
+ {
+ consumed = mInputMethodContext.FilterEventKey( event );
+ }
+ return consumed;
+}
+
+Toolkit::Internal::LayoutItemPtr Control::Impl::GetLayout() const
+{
+ return mLayout;
+}
+
+void Control::Impl::SetLayout( Toolkit::Internal::LayoutItem& layout )
+{
+ DALI_LOG_INFO( gLogFilterLayout, Debug::Verbose, "Control::SetLayout control:%s existing layout:%s\n",
+ mControlImpl.Self().GetName().c_str(),
+ mLayout?"true":"false" );
+
+ if( mLayout )
+ {
+ mLayout->Unparent();
+ mLayout.Reset();
+ }
+ mLayout = &layout;
+
+ auto controlHandle = Toolkit::Control::DownCast( mControlImpl.Self() ); // Get a handle of this control implementation without copying internals.
+ mLayout->Initialize( controlHandle, controlHandle.GetTypeName() ); // LayoutGroup takes ownership of existing children
+}
+
+void Control::Impl::RemoveLayout()
+{
+ if( mLayout )
+ {
+ mLayout->Unparent();
+ mLayout.Reset();
+ }
+}
+
+void Control::Impl::SetLayoutingRequired( bool layoutingRequired )
+{
+ mControlImpl.mImpl->mIsLayoutingRequired = layoutingRequired;
+}
+
+bool Control::Impl::IsLayoutingRequired()
+{
+ return mControlImpl.mImpl->mIsLayoutingRequired;
+}
+