UNO objects should never hold a VclPtr they dont own on heap ...

... so admit that the VclPtr that ChartController used to have is really
owned by m_xViewWindow, and get fetch that (stack-scoped only) from
there.

Change-Id: Ib9e2cd20201ebe5019c3607a8c65cb1a9856812f
Reviewed-on: https://gerrit.libreoffice.org/35603
Tested-by: Jenkins <ci@libreoffice.org>
Reviewed-by: Björn Michaelsen <bjoern.michaelsen@canonical.com>
diff --git a/chart2/source/controller/inc/ChartController.hxx b/chart2/source/controller/inc/ChartController.hxx
index d58708d..02a3468 100644
--- a/chart2/source/controller/inc/ChartController.hxx
+++ b/chart2/source/controller/inc/ChartController.hxx
@@ -379,7 +379,6 @@ private:
    TheModelRef m_aModel;

    //view
    VclPtr<ChartWindow> m_pChartWindow;
    css::uno::Reference<css::awt::XWindow> m_xViewWindow;
    css::uno::Reference<css::uno::XInterface> m_xChartView;
    std::shared_ptr< DrawModelWrapper > m_pDrawModelWrapper;
diff --git a/chart2/source/controller/main/ChartController.cxx b/chart2/source/controller/main/ChartController.cxx
index abcdeea..d678689 100644
--- a/chart2/source/controller/main/ChartController.cxx
+++ b/chart2/source/controller/main/ChartController.cxx
@@ -106,7 +106,6 @@ ChartController::ChartController(uno::Reference<uno::XComponentContext> const & 
    m_xFrame( nullptr ),
    m_aModelMutex(),
    m_aModel( nullptr, m_aModelMutex ),
    m_pChartWindow( nullptr ),
    m_xViewWindow(),
    m_xChartView(),
    m_pDrawModelWrapper(),
@@ -442,21 +441,22 @@ void SAL_CALL ChartController::attachFrame(
        pParent = VCLUnoHelper::GetWindow( xContainerWindow ).get();
    }

    if(m_pChartWindow)
    auto pChartWindow(GetChartWindow());
    if(pChartWindow)
    {
        //@todo delete ...
        m_pChartWindow->clear();
        pChartWindow->clear();
        m_apDropTargetHelper.reset();
    }
    {
        // calls to VCL
        SolarMutexGuard aSolarGuard;
        m_pChartWindow = VclPtr<ChartWindow>::Create(this,pParent,pParent?pParent->GetStyle():0);
        m_pChartWindow->SetBackground();//no Background
        m_xViewWindow.set( m_pChartWindow->GetComponentInterface(), uno::UNO_QUERY );
        m_pChartWindow->Show();
        pChartWindow = VclPtr<ChartWindow>::Create(this,pParent,pParent?pParent->GetStyle():0);
        pChartWindow->SetBackground();//no Background
        m_xViewWindow.set( pChartWindow->GetComponentInterface(), uno::UNO_QUERY );
        pChartWindow->Show();
        m_apDropTargetHelper.reset(
            new ChartDropTargetHelper( m_pChartWindow->GetDropTarget(),
            new ChartDropTargetHelper( pChartWindow->GetDropTarget(),
                                       uno::Reference< chart2::XChartDocument >( getModel(), uno::UNO_QUERY )));

        impl_createDrawViewController();
@@ -506,14 +506,15 @@ void SAL_CALL ChartController::attachFrame(
//XModeChangeListener
void SAL_CALL ChartController::modeChanged( const util::ModeChangeEvent& rEvent )
{
    auto pChartWindow(GetChartWindow());
    //adjust controller to view status changes

    if( rEvent.NewMode == "dirty" )
    {
        //the view has become dirty, we should repaint it if we have a window
        SolarMutexGuard aGuard;
        if( m_pChartWindow )
            m_pChartWindow->ForceInvalidate();
        if( pChartWindow )
            pChartWindow->ForceInvalidate();
    }
    else if( rEvent.NewMode == "invalid" )
    {
@@ -533,7 +534,7 @@ void SAL_CALL ChartController::modeChanged( const util::ModeChangeEvent& rEvent 
        //the view was rebuild so we can start some actions on it again
        if( !m_bConnectingToView )
        {
            if(m_pChartWindow && m_aModel.is() )
            if(pChartWindow && m_aModel.is() )
            {
                m_bConnectingToView = true;

@@ -556,8 +557,8 @@ void SAL_CALL ChartController::modeChanged( const util::ModeChangeEvent& rEvent 

                    {
                        SolarMutexGuard aGuard;
                        if( m_pChartWindow )
                            m_pChartWindow->Invalidate();
                        if( pChartWindow )
                            pChartWindow->Invalidate();
                    }
                }

@@ -645,8 +646,9 @@ sal_Bool SAL_CALL ChartController::attachModel( const uno::Reference< frame::XMo
    //the frameloader is responsible to call xModel->connectController
    {
        SolarMutexGuard aGuard2;
        if( m_pChartWindow )
            m_pChartWindow->Invalidate();
        auto pChartWindow(GetChartWindow());
        if( pChartWindow )
            pChartWindow->Invalidate();
    }

    uno::Reference< document::XUndoManagerSupplier > xSuppUndo( getModel(), uno::UNO_QUERY_THROW );
@@ -744,7 +746,7 @@ void ChartController::impl_createDrawViewController()
    {
        if( m_pDrawModelWrapper )
        {
            m_pDrawViewWrapper = new DrawViewWrapper(&m_pDrawModelWrapper->getSdrModel(),m_pChartWindow);
            m_pDrawViewWrapper = new DrawViewWrapper(&m_pDrawModelWrapper->getSdrModel(),GetChartWindow());
            m_pDrawViewWrapper->attachParentReferenceDevice( getModel() );
        }
    }
@@ -826,9 +828,7 @@ void SAL_CALL ChartController::dispose()
            m_apDropTargetHelper.reset();

            //the accessible view is disposed within window destructor of m_pChartWindow
            m_pChartWindow->clear();
            m_pChartWindow = nullptr;//m_pChartWindow is deleted via UNO due to dispose of m_xViewWindow (triggered by Framework (Controller pretends to be XWindow also))
            m_xViewWindow->dispose();
            m_xViewWindow->dispose(); //ChartWindow is deleted via UNO due to dispose of m_xViewWindow (triggered by Framework (Controller pretends to be XWindow also))
            m_xChartView.clear();
        }

@@ -1111,8 +1111,9 @@ void SAL_CALL ChartController::dispatch(
    {
        ChartViewHelper::setViewToDirtyState( getModel() );
        SolarMutexGuard aGuard;
        if( m_pChartWindow )
            m_pChartWindow->Invalidate();
        auto pChartWindow(GetChartWindow());
        if( pChartWindow )
            pChartWindow->Invalidate();
    }
    else if(aCommand == "DiagramData" )
        this->executeDispatch_EditData();
@@ -1312,7 +1313,7 @@ void ChartController::executeDispatch_ChartType()

    SolarMutexGuard aSolarGuard;
    //prepare and open dialog
    ScopedVclPtrInstance< ChartTypeDialog > aDlg( m_pChartWindow, getModel() );
    ScopedVclPtrInstance< ChartTypeDialog > aDlg( GetChartWindow(), getModel() );
    if( aDlg->Execute() == RET_OK )
    {
        impl_adaptDataSeriesAutoResize();
@@ -1333,7 +1334,7 @@ void ChartController::executeDispatch_SourceData()
    if( xChartDoc.is())
    {
        SolarMutexGuard aSolarGuard;
        ScopedVclPtrInstance< ::chart::DataSourceDialog > aDlg( m_pChartWindow, xChartDoc, m_xCC );
        ScopedVclPtrInstance< ::chart::DataSourceDialog > aDlg( GetChartWindow(), xChartDoc, m_xCC );
        if( aDlg->Execute() == RET_OK )
        {
            impl_adaptDataSeriesAutoResize();
@@ -1449,7 +1450,9 @@ DrawViewWrapper* ChartController::GetDrawViewWrapper()

VclPtr<ChartWindow> ChartController::GetChartWindow()
{
    return m_pChartWindow;
    if(!m_xViewWindow.is())
        return nullptr;
    return dynamic_cast<ChartWindow*>(m_xViewWindow.get());
}

bool ChartController::isAdditionalShapeSelected()
@@ -1478,9 +1481,10 @@ uno::Reference< XAccessible > ChartController::CreateAccessible()
void ChartController::impl_invalidateAccessible()
{
    SolarMutexGuard aGuard;
    if( m_pChartWindow )
    auto pChartWindow(GetChartWindow());
    if( pChartWindow )
    {
        Reference< lang::XInitialization > xInit( m_pChartWindow->GetAccessible(false), uno::UNO_QUERY );
        Reference< lang::XInitialization > xInit( pChartWindow->GetAccessible(false), uno::UNO_QUERY );
        if(xInit.is())
        {
            uno::Sequence< uno::Any > aArguments(3);//empty arguments -> invalid accessible
@@ -1491,8 +1495,9 @@ void ChartController::impl_invalidateAccessible()
void ChartController::impl_initializeAccessible()
{
    SolarMutexGuard aGuard;
    if( m_pChartWindow )
        this->impl_initializeAccessible( Reference< lang::XInitialization >( m_pChartWindow->GetAccessible(false), uno::UNO_QUERY ) );
    auto pChartWindow(GetChartWindow());
    if( pChartWindow )
        this->impl_initializeAccessible( Reference< lang::XInitialization >( pChartWindow->GetAccessible(false), uno::UNO_QUERY ) );
}
void ChartController::impl_initializeAccessible( const uno::Reference< lang::XInitialization >& xInit )
{
@@ -1505,9 +1510,10 @@ void ChartController::impl_initializeAccessible( const uno::Reference< lang::XIn
        uno::Reference< XAccessible > xParent;
        {
            SolarMutexGuard aGuard;
            if( m_pChartWindow )
            auto pChartWindow(GetChartWindow());
            if( pChartWindow )
            {
                vcl::Window* pParentWin( m_pChartWindow->GetAccessibleParentWindow());
                vcl::Window* pParentWin( pChartWindow->GetAccessibleParentWindow());
                if( pParentWin )
                    xParent.set( pParentWin->GetAccessible());
            }
diff --git a/chart2/source/controller/main/ChartController_Insert.cxx b/chart2/source/controller/main/ChartController_Insert.cxx
index 1fb0971..7f652b5 100644
--- a/chart2/source/controller/main/ChartController_Insert.cxx
+++ b/chart2/source/controller/main/ChartController_Insert.cxx
@@ -99,7 +99,7 @@ void ChartController::executeDispatch_InsertAxes()
        AxisHelper::getAxisOrGridPossibilities( aDialogInput.aPossibilityList, xDiagram );

        SolarMutexGuard aGuard;
        ScopedVclPtrInstance<SchAxisDlg> aDlg( m_pChartWindow, aDialogInput );
        ScopedVclPtrInstance<SchAxisDlg> aDlg( GetChartWindow(), aDialogInput );
        if( aDlg->Execute() == RET_OK )
        {
            // lock controllers till end of block
@@ -137,7 +137,7 @@ void ChartController::executeDispatch_InsertGrid()
        AxisHelper::getAxisOrGridPossibilities( aDialogInput.aPossibilityList, xDiagram, false );

        SolarMutexGuard aGuard;
        ScopedVclPtrInstance<SchGridDlg> aDlg(m_pChartWindow, aDialogInput);//aItemSet, b3D, bNet, bSecondaryX, bSecondaryY );
        ScopedVclPtrInstance<SchGridDlg> aDlg(GetChartWindow(), aDialogInput);//aItemSet, b3D, bNet, bSecondaryX, bSecondaryY );
        if( aDlg->Execute() == RET_OK )
        {
            // lock controllers till end of block
@@ -169,7 +169,7 @@ void ChartController::executeDispatch_InsertTitles()
        aDialogInput.readFromModel( getModel() );

        SolarMutexGuard aGuard;
        ScopedVclPtrInstance< SchTitleDlg > aDlg( m_pChartWindow, aDialogInput );
        ScopedVclPtrInstance< SchTitleDlg > aDlg( GetChartWindow(), aDialogInput );
        if( aDlg->Execute() == RET_OK )
        {
            // lock controllers till end of block
@@ -222,7 +222,7 @@ void ChartController::executeDispatch_OpenLegendDialog()
    {
        //prepare and open dialog
        SolarMutexGuard aGuard;
        ScopedVclPtrInstance< SchLegendDlg > aDlg( m_pChartWindow, m_xCC );
        ScopedVclPtrInstance< SchLegendDlg > aDlg( GetChartWindow(), m_xCC );
        aDlg->init( getModel() );
        if( aDlg->Execute() == RET_OK )
        {
@@ -282,7 +282,7 @@ void ChartController::executeDispatch_InsertMenu_DataLabels()
        NumberFormatterWrapper aNumberFormatterWrapper( xNumberFormatsSupplier );
        SvNumberFormatter* pNumberFormatter = aNumberFormatterWrapper.getSvNumberFormatter();

        ScopedVclPtrInstance< DataLabelsDialog > aDlg( m_pChartWindow, aItemSet, pNumberFormatter);
        ScopedVclPtrInstance< DataLabelsDialog > aDlg( GetChartWindow(), aItemSet, pNumberFormatter);

        if( aDlg->Execute() == RET_OK )
        {
@@ -390,7 +390,7 @@ void ChartController::executeDispatch_InsertTrendline()
    ViewElementListProvider aViewElementListProvider( m_pDrawModelWrapper.get());
    SolarMutexGuard aGuard;
    ScopedVclPtrInstance<SchAttribTabDlg> aDialog(
        m_pChartWindow, &aItemSet, &aDialogParameter,
        GetChartWindow(), &aItemSet, &aDialogParameter,
        &aViewElementListProvider,
        uno::Reference< util::XNumberFormatsSupplier >(
                getModel(), uno::UNO_QUERY ) );
@@ -448,7 +448,7 @@ void ChartController::executeDispatch_InsertErrorBars( bool bYError )
        ViewElementListProvider aViewElementListProvider( m_pDrawModelWrapper.get());
        SolarMutexGuard aGuard;
        ScopedVclPtrInstance<SchAttribTabDlg> aDlg(
                m_pChartWindow, &aItemSet, &aDialogParameter,
                GetChartWindow(), &aItemSet, &aDialogParameter,
                &aViewElementListProvider,
                uno::Reference< util::XNumberFormatsSupplier >(
                        getModel(), uno::UNO_QUERY ) );
@@ -488,7 +488,7 @@ void ChartController::executeDispatch_InsertErrorBars( bool bYError )
            //prepare and open dialog
            SolarMutexGuard aGuard;
            ScopedVclPtrInstance<InsertErrorBarsDialog> aDlg(
                m_pChartWindow, aItemSet,
                GetChartWindow(), aItemSet,
                uno::Reference< chart2::XChartDocument >( getModel(), uno::UNO_QUERY ),
                bYError ? ErrorBarResources::ERROR_BAR_Y : ErrorBarResources::ERROR_BAR_X);

diff --git a/chart2/source/controller/main/ChartController_Position.cxx b/chart2/source/controller/main/ChartController_Position.cxx
index b470348..a11f210 100644
--- a/chart2/source/controller/main/ChartController_Position.cxx
+++ b/chart2/source/controller/main/ChartController_Position.cxx
@@ -141,7 +141,7 @@ void ChartController::executeDispatch_PositionAndSize()
        SvxAbstractDialogFactory * pFact = SvxAbstractDialogFactory::Create();
        OSL_ENSURE( pFact, "No dialog factory" );
        ScopedVclPtr<SfxAbstractTabDialog> pDlg(pFact->CreateSchTransformTabDialog(
            m_pChartWindow, &aItemSet, pSdrView, bResizePossible ));
            GetChartWindow(), &aItemSet, pSdrView, bResizePossible ));
        OSL_ENSURE( pDlg, "Couldn't create SchTransformTabDialog" );

        if( pDlg->Execute() == RET_OK )
diff --git a/chart2/source/controller/main/ChartController_Properties.cxx b/chart2/source/controller/main/ChartController_Properties.cxx
index 5be1be5..b5577ff 100644
--- a/chart2/source/controller/main/ChartController_Properties.cxx
+++ b/chart2/source/controller/main/ChartController_Properties.cxx
@@ -761,7 +761,7 @@ bool ChartController::executeDlg_ObjectProperties_withoutUndoGuard(

        SolarMutexGuard aGuard;
        ScopedVclPtrInstance<SchAttribTabDlg> aDlg(
                m_pChartWindow, &aItemSet, &aDialogParameter,
                GetChartWindow(), &aItemSet, &aDialogParameter,
                &aViewElementListProvider,
                uno::Reference< util::XNumberFormatsSupplier >(
                        getModel(), uno::UNO_QUERY ) );
@@ -823,7 +823,7 @@ void ChartController::executeDispatch_View3D()

        //open dialog
        SolarMutexGuard aSolarGuard;
        ScopedVclPtrInstance< View3DDialog > aDlg(m_pChartWindow, getModel());
        ScopedVclPtrInstance< View3DDialog > aDlg(GetChartWindow(), getModel());
        if( aDlg->Execute() == RET_OK )
            aUndoGuard.commit();
    }
diff --git a/chart2/source/controller/main/ChartController_TextEdit.cxx b/chart2/source/controller/main/ChartController_TextEdit.cxx
index 9d958fc..a250d78 100644
--- a/chart2/source/controller/main/ChartController_TextEdit.cxx
+++ b/chart2/source/controller/main/ChartController_TextEdit.cxx
@@ -73,7 +73,7 @@ void ChartController::StartTextEdit( const Point* pMousePixel )

    bool bEdit = m_pDrawViewWrapper->SdrBeginTextEdit( pTextObj
                    , m_pDrawViewWrapper->GetPageView()
                    , m_pChartWindow
                    , GetChartWindow()
                    , false //bIsNewObj
                    , pOutliner
                    , nullptr //pOutlinerView
@@ -98,7 +98,7 @@ void ChartController::StartTextEdit( const Point* pMousePixel )

        //we invalidate the outliner region because the outliner has some
        //paint problems (some characters are painted twice a little bit shifted)
        m_pChartWindow->Invalidate( m_pDrawViewWrapper->GetMarkedObjBoundRect() );
        GetChartWindow()->Invalidate( m_pDrawViewWrapper->GetMarkedObjBoundRect() );
    }
}

@@ -169,7 +169,7 @@ void ChartController::executeDispatch_InsertSpecialCharacter()
    vcl::Font aCurFont = m_pDrawViewWrapper->getOutliner()->GetRefDevice()->GetFont();
    aSet.Put( SvxFontItem( aCurFont.GetFamilyType(), aCurFont.GetFamilyName(), aCurFont.GetStyleName(), aCurFont.GetPitch(), aCurFont.GetCharSet(), SID_ATTR_CHAR_FONT ) );

    ScopedVclPtr<SfxAbstractDialog> pDlg(pFact->CreateSfxDialog( m_pChartWindow, aSet, getFrame(), RID_SVXDLG_CHARMAP ));
    ScopedVclPtr<SfxAbstractDialog> pDlg(pFact->CreateSfxDialog( GetChartWindow(), aSet, getFrame(), RID_SVXDLG_CHARMAP ));
    OSL_ENSURE( pDlg, "Couldn't create SvxCharacterMap dialog" );
    if( pDlg->Execute() == RET_OK )
    {
diff --git a/chart2/source/controller/main/ChartController_Tools.cxx b/chart2/source/controller/main/ChartController_Tools.cxx
index bc62696..6a33c1c 100644
--- a/chart2/source/controller/main/ChartController_Tools.cxx
+++ b/chart2/source/controller/main/ChartController_Tools.cxx
@@ -249,15 +249,16 @@ void ChartController::executeDispatch_ScaleText()
void ChartController::executeDispatch_Paste()
{
    SolarMutexGuard aGuard;
    if( m_pChartWindow )
    auto pChartWindow(GetChartWindow());
    if( GetChartWindow() )
    {
        Graphic aGraphic;
        // paste location: center of window
        Point aPos;
        aPos = m_pChartWindow->PixelToLogic( Rectangle( aPos, m_pChartWindow->GetSizePixel()).Center());
        aPos = pChartWindow->PixelToLogic( Rectangle( aPos, pChartWindow->GetSizePixel()).Center());

        // handle different formats
        TransferableDataHelper aDataHelper( TransferableDataHelper::CreateFromSystemClipboard( m_pChartWindow ));
        TransferableDataHelper aDataHelper( TransferableDataHelper::CreateFromSystemClipboard( pChartWindow ));
        if( aDataHelper.GetTransferable().is())
        {
            if ( aDataHelper.HasFormat( SotClipboardFormatId::DRAWING ) )
@@ -359,11 +360,12 @@ void ChartController::impl_PasteGraphic(
        uno::Reference< beans::XPropertySet > xGraphicProp( xGraphic, uno::UNO_QUERY );

        awt::Size aGraphicSize( 1000, 1000 );
        auto pChartWindow(GetChartWindow());
        // first try size in 100th mm, then pixel size
        if( ! ( xGraphicProp->getPropertyValue( "Size100thMM") >>= aGraphicSize ) &&
            ( ( xGraphicProp->getPropertyValue( "SizePixel") >>= aGraphicSize ) && m_pChartWindow ))
            ( ( xGraphicProp->getPropertyValue( "SizePixel") >>= aGraphicSize ) && pChartWindow ))
        {
            ::Size aVCLSize( m_pChartWindow->PixelToLogic( Size( aGraphicSize.Width, aGraphicSize.Height )));
            ::Size aVCLSize( pChartWindow->PixelToLogic( Size( aGraphicSize.Width, aGraphicSize.Height )));
            aGraphicSize.Width = aVCLSize.getWidth();
            aGraphicSize.Height = aVCLSize.getHeight();
        }
diff --git a/chart2/source/controller/main/ChartController_Window.cxx b/chart2/source/controller/main/ChartController_Window.cxx
index f32e0c2..feaa696 100644
--- a/chart2/source/controller/main/ChartController_Window.cxx
+++ b/chart2/source/controller/main/ChartController_Window.cxx
@@ -225,10 +225,11 @@ void SAL_CALL ChartController::setPosSize(
{
    SolarMutexGuard aGuard;
    uno::Reference<awt::XWindow> xWindow = m_xViewWindow;
    auto pChartWindow(GetChartWindow());

    if(xWindow.is() && m_pChartWindow)
    if(xWindow.is() && pChartWindow)
    {
        Size aLogicSize = m_pChartWindow->PixelToLogic( Size( Width, Height ), MapMode( MapUnit::Map100thMM )  );
        Size aLogicSize = pChartWindow->PixelToLogic( Size( Width, Height ), MapMode( MapUnit::Map100thMM )  );

        //todo: for standalone chart: detect whether we are standalone
        //change map mode to fit new size
@@ -242,8 +243,8 @@ void SAL_CALL ChartController::setPosSize(
                    Point(0,0),
                    Fraction(nScaleXNumerator, nScaleXDenominator),
                    Fraction(nScaleYNumerator, nScaleYDenominator) );
        m_pChartWindow->SetMapMode(aNewMapMode);
        m_pChartWindow->setPosSizePixel( X, Y, Width, Height, static_cast<PosSizeFlags>(Flags) );
        pChartWindow->SetMapMode(aNewMapMode);
        pChartWindow->setPosSizePixel( X, Y, Width, Height, static_cast<PosSizeFlags>(Flags) );

        //#i75867# poor quality of ole's alternative view with 3D scenes and zoomfactors besides 100%
        uno::Reference< beans::XPropertySet > xProp( m_xChartView, uno::UNO_QUERY );
@@ -261,10 +262,10 @@ void SAL_CALL ChartController::setPosSize(
        //a correct work area is at least necessary for correct values in the position and  size dialog and for dragging area
        if(m_pDrawViewWrapper)
        {
            Rectangle aRect(Point(0,0), m_pChartWindow->GetOutputSize());
            Rectangle aRect(Point(0,0), pChartWindow->GetOutputSize());
            m_pDrawViewWrapper->SetWorkArea( aRect );
        }
        m_pChartWindow->Invalidate();
        pChartWindow->Invalidate();
    }
}

@@ -455,10 +456,11 @@ void ChartController::execute_Paint(vcl::RenderContext& rRenderContext, const Re
            awt::Size aResolution(1000, 1000);
            {
                SolarMutexGuard aGuard;
                if (m_pChartWindow)
                auto pChartWindow(GetChartWindow());
                if (pChartWindow)
                {
                    aResolution.Width = m_pChartWindow->GetSizePixel().Width();
                    aResolution.Height = m_pChartWindow->GetSizePixel().Height();
                    aResolution.Width = pChartWindow->GetSizePixel().Width();
                    aResolution.Height = pChartWindow->GetSizePixel().Height();
                }
            }
            xProp->setPropertyValue( "Resolution", uno::Any( aResolution ));
@@ -497,9 +499,10 @@ void ChartController::startDoubleClickWaiting()
    m_bWaitingForDoubleClick = true;

    sal_uInt64 nDblClkTime = 500;
    if( m_pChartWindow )
    auto pChartWindow(GetChartWindow());
    if( pChartWindow )
    {
        const MouseSettings& rMSettings = m_pChartWindow->GetSettings().GetMouseSettings();
        const MouseSettings& rMSettings = pChartWindow->GetSettings().GetMouseSettings();
        nDblClkTime = rMSettings.GetDoubleClickTime();
    }
    m_aDoubleClickTimer.SetTimeout( nDblClkTime );
@@ -520,9 +523,10 @@ IMPL_LINK_NOARG(ChartController, DoubleClickWaitingHdl, Timer *, void)
    {
        this->impl_selectObjectAndNotiy();
        SolarMutexGuard aGuard;
        if( m_pChartWindow )
        auto pChartWindow(GetChartWindow());
        if( pChartWindow )
        {
            vcl::Window::PointerState aPointerState( m_pChartWindow->GetPointerState() );
            vcl::Window::PointerState aPointerState( pChartWindow->GetPointerState() );
            MouseEvent aMouseEvent(
                            aPointerState.maPos,
                            1/*nClicks*/,
@@ -548,15 +552,16 @@ void ChartController::execute_MouseButtonDown( const MouseEvent& rMEvt )
    m_aSelection.remindSelectionBeforeMouseDown();

    DrawViewWrapper* pDrawViewWrapper = m_pDrawViewWrapper;
    if(!m_pChartWindow || !pDrawViewWrapper )
    auto pChartWindow(GetChartWindow());
    if(!pChartWindow || !pDrawViewWrapper )
        return;

    Point   aMPos   = m_pChartWindow->PixelToLogic(rMEvt.GetPosPixel());
    Point   aMPos   = pChartWindow->PixelToLogic(rMEvt.GetPosPixel());

    if ( MOUSE_LEFT == rMEvt.GetButtons() )
    {
        m_pChartWindow->GrabFocus();
        m_pChartWindow->CaptureMouse();
        pChartWindow->GrabFocus();
        pChartWindow->CaptureMouse();
    }

    if( pDrawViewWrapper->IsTextEdit() )
@@ -566,7 +571,7 @@ void ChartController::execute_MouseButtonDown( const MouseEvent& rMEvt )
             // #i12587# support for shapes in chart
             ( rMEvt.IsRight() && pDrawViewWrapper->PickAnything( rMEvt, SdrMouseEventKind::BUTTONDOWN, aVEvt ) == SdrHitKind::MarkedObject ) )
        {
            pDrawViewWrapper->MouseButtonDown(rMEvt,m_pChartWindow);
            pDrawViewWrapper->MouseButtonDown(rMEvt, pChartWindow);
            return;
        }
        else
@@ -644,7 +649,7 @@ void ChartController::execute_MouseButtonDown( const MouseEvent& rMEvt )
        && !rMEvt.IsRight() )
    {
        //start drag
        sal_uInt16  nDrgLog = (sal_uInt16)m_pChartWindow->PixelToLogic(Size(DRGPIX,0)).Width();
        sal_uInt16  nDrgLog = (sal_uInt16)pChartWindow->PixelToLogic(Size(DRGPIX,0)).Width();
        SdrDragMethod* pDragMethod = nullptr;

        //change selection to 3D scene if rotate mode
@@ -685,18 +690,19 @@ void ChartController::execute_MouseMove( const MouseEvent& rMEvt )
    SolarMutexGuard aGuard;

    DrawViewWrapper* pDrawViewWrapper = m_pDrawViewWrapper;
    if(!m_pChartWindow || !pDrawViewWrapper)
    auto pChartWindow(GetChartWindow());
    if(!pChartWindow || !pDrawViewWrapper)
        return;

    if( m_pDrawViewWrapper->IsTextEdit() )
    {
        if( m_pDrawViewWrapper->MouseMove(rMEvt,m_pChartWindow) )
        if( m_pDrawViewWrapper->MouseMove(rMEvt,pChartWindow) )
            return;
    }

    if(pDrawViewWrapper->IsAction())
    {
        pDrawViewWrapper->MovAction( m_pChartWindow->PixelToLogic( rMEvt.GetPosPixel() ) );
        pDrawViewWrapper->MovAction( pChartWindow->PixelToLogic( rMEvt.GetPosPixel() ) );
    }

    impl_SetMousePointer( rMEvt );
@@ -712,14 +718,15 @@ void ChartController::execute_MouseButtonUp( const MouseEvent& rMEvt )
        SolarMutexGuard aGuard;

        DrawViewWrapper* pDrawViewWrapper = m_pDrawViewWrapper;
        if(!m_pChartWindow || !pDrawViewWrapper)
        auto pChartWindow(GetChartWindow());
        if(!pChartWindow || !pDrawViewWrapper)
            return;

        Point   aMPos   = m_pChartWindow->PixelToLogic(rMEvt.GetPosPixel());
        Point   aMPos   = pChartWindow->PixelToLogic(rMEvt.GetPosPixel());

        if(pDrawViewWrapper->IsTextEdit())
        {
            if( pDrawViewWrapper->MouseButtonUp(rMEvt,m_pChartWindow) )
            if( pDrawViewWrapper->MouseButtonUp(rMEvt,pChartWindow) )
                return;
        }

@@ -856,7 +863,7 @@ void ChartController::execute_MouseButtonUp( const MouseEvent& rMEvt )
        }

        //@todo ForcePointer(&rMEvt);
        m_pChartWindow->ReleaseMouse();
        pChartWindow->ReleaseMouse();

        if( m_aSelection.isSelectionDifferentFromBeforeMouseDown() )
            bNotifySelectionChange = true;
@@ -906,17 +913,19 @@ void ChartController::execute_DoubleClick( const Point* pMousePixel )
void ChartController::execute_Resize()
{
    SolarMutexGuard aGuard;
    if(m_pChartWindow)
        m_pChartWindow->Invalidate();
    auto pChartWindow(GetChartWindow());
    if(pChartWindow)
        pChartWindow->Invalidate();
}

void ChartController::execute_Command( const CommandEvent& rCEvt )
{
    auto pChartWindow(GetChartWindow());
    bool bIsAction = false;
    {
        SolarMutexGuard aGuard;
        DrawViewWrapper* pDrawViewWrapper = m_pDrawViewWrapper;
        if(!m_pChartWindow || !pDrawViewWrapper)
        if(!pChartWindow || !pDrawViewWrapper)
            return;
        bIsAction = m_pDrawViewWrapper->IsAction();
    }
@@ -926,8 +935,8 @@ void ChartController::execute_Command( const CommandEvent& rCEvt )
    {
        {
            SolarMutexGuard aGuard;
            if(m_pChartWindow)
                m_pChartWindow->ReleaseMouse();
            if(pChartWindow)
                pChartWindow->ReleaseMouse();
        }

        if( m_aSelection.isSelectionDifferentFromBeforeMouseDown() )
@@ -940,8 +949,8 @@ void ChartController::execute_Command( const CommandEvent& rCEvt )
        if( !rCEvt.IsMouseEvent() )
        {
            SolarMutexGuard aGuard;
            if(m_pChartWindow)
                aPos = m_pChartWindow->GetPointerState().maPos;
            if(pChartWindow)
                aPos = pChartWindow->GetPointerState().maPos;
        }

        OUString aMenuName;
@@ -1229,7 +1238,7 @@ void ChartController::execute_Command( const CommandEvent& rCEvt )
        //#i84417# enable editing with IME
        SolarMutexGuard aGuard;
        if( m_pDrawViewWrapper )
            m_pDrawViewWrapper->Command( rCEvt, m_pChartWindow );
            m_pDrawViewWrapper->Command( rCEvt, pChartWindow );
    }
}

@@ -1238,7 +1247,8 @@ bool ChartController::execute_KeyInput( const KeyEvent& rKEvt )
    bool bReturn=false;

    DrawViewWrapper* pDrawViewWrapper = m_pDrawViewWrapper;
    if(!m_pChartWindow || !pDrawViewWrapper)
    auto pChartWindow(GetChartWindow());
    if(!pChartWindow || !pDrawViewWrapper)
        return bReturn;

    // handle accelerators
@@ -1264,7 +1274,7 @@ bool ChartController::execute_KeyInput( const KeyEvent& rKEvt )
        SolarMutexGuard aGuard;
        if( pDrawViewWrapper->IsTextEdit() )
        {
            if( pDrawViewWrapper->KeyInput(rKEvt,m_pChartWindow) )
            if( pDrawViewWrapper->KeyInput(rKEvt, pChartWindow) )
            {
                bReturn = true;
                if( nCode == KEY_ESCAPE )
@@ -1360,13 +1370,13 @@ bool ChartController::execute_KeyInput( const KeyEvent& rKEvt )
                    // default 1 mm in each direction
                    double fGrowAmountX = 200.0;
                    double fGrowAmountY = 200.0;
                    if( bAlternate && m_pChartWindow )
                    if( bAlternate && pChartWindow )
                    {
                        // together with Alt-key: 1 px in each direction
                        SolarMutexGuard aGuard;
                        if( m_pChartWindow )
                        if( pChartWindow )
                        {
                            Size aPixelSize = m_pChartWindow->PixelToLogic( Size( 2, 2 ));
                            Size aPixelSize = pChartWindow->PixelToLogic( Size( 2, 2 ));
                            fGrowAmountX = static_cast< double >( aPixelSize.Width());
                            fGrowAmountY = static_cast< double >( aPixelSize.Height());
                        }
@@ -1391,13 +1401,13 @@ bool ChartController::execute_KeyInput( const KeyEvent& rKEvt )
                    // default 1 mm
                    double fShiftAmountX = 100.0;
                    double fShiftAmountY = 100.0;
                    if( bAlternate && m_pChartWindow )
                    if( bAlternate && pChartWindow )
                    {
                        // together with Alt-key: 1 px
                        SolarMutexGuard aGuard;
                        if(m_pChartWindow)
                        if(pChartWindow)
                        {
                            Size aPixelSize = m_pChartWindow->PixelToLogic( Size( 1, 1 ));
                            Size aPixelSize = pChartWindow->PixelToLogic( Size( 1, 1 ));
                            fShiftAmountX = static_cast< double >( aPixelSize.Width());
                            fShiftAmountY = static_cast< double >( aPixelSize.Height());
                        }
@@ -1498,7 +1508,7 @@ bool ChartController::execute_KeyInput( const KeyEvent& rKEvt )
        if( ! bReturn )
        {
            SolarMutexGuard aGuard;
            ScopedVclPtrInstance<InfoBox>(m_pChartWindow, SCH_RESSTR(STR_ACTION_NOTPOSSIBLE))->Execute();
            ScopedVclPtrInstance<InfoBox>(GetChartWindow(), SCH_RESSTR(STR_ACTION_NOTPOSSIBLE))->Execute();
        }
    }

@@ -1583,9 +1593,10 @@ sal_Bool SAL_CALL ChartController::select( const uno::Any& rSelection )
            this->EndTextEdit();
        }
        this->impl_selectObjectAndNotiy();
        if ( m_pChartWindow )
        auto pChartWindow(GetChartWindow());
        if ( pChartWindow )
        {
            m_pChartWindow->Invalidate();
            pChartWindow->Invalidate();
        }
        return true;
    }
@@ -1786,11 +1797,12 @@ bool ChartController::impl_DragDataPoint( const OUString & rCID, double fAdditio
void ChartController::impl_SetMousePointer( const MouseEvent & rEvent )
{
    SolarMutexGuard aGuard;
    auto pChartWindow(GetChartWindow());

    if (!m_pDrawViewWrapper || !m_pChartWindow)
    if (!m_pDrawViewWrapper || !pChartWindow)
        return;

    Point aMousePos( m_pChartWindow->PixelToLogic( rEvent.GetPosPixel()));
    Point aMousePos( pChartWindow->PixelToLogic( rEvent.GetPosPixel()));
    sal_uInt16 nModifier = rEvent.GetModifier();
    bool bLeftDown = rEvent.IsLeft();

@@ -1798,8 +1810,8 @@ void ChartController::impl_SetMousePointer( const MouseEvent & rEvent )
    {
        if( m_pDrawViewWrapper->IsTextEditHit( aMousePos ) )
        {
            m_pChartWindow->SetPointer( m_pDrawViewWrapper->GetPreferredPointer(
                aMousePos, m_pChartWindow, nModifier, bLeftDown ) );
            pChartWindow->SetPointer( m_pDrawViewWrapper->GetPreferredPointer(
                aMousePos, pChartWindow, nModifier, bLeftDown ) );
            return;
        }
    }
@@ -1815,7 +1827,7 @@ void ChartController::impl_SetMousePointer( const MouseEvent & rEvent )
    if( pHitSelectionHdl )
    {
        Pointer aPointer = m_pDrawViewWrapper->GetPreferredPointer(
            aMousePos, m_pChartWindow, nModifier, bLeftDown );
            aMousePos, pChartWindow, nModifier, bLeftDown );
        bool bForceArrowPointer = false;

        ObjectIdentifier aOID( m_aSelection.getSelectedOID() );
@@ -1848,9 +1860,9 @@ void ChartController::impl_SetMousePointer( const MouseEvent & rEvent )
        }

        if( bForceArrowPointer )
            m_pChartWindow->SetPointer( Pointer( PointerStyle::Arrow ));
            pChartWindow->SetPointer( Pointer( PointerStyle::Arrow ));
        else
            m_pChartWindow->SetPointer( aPointer );
            pChartWindow->SetPointer( aPointer );

        return;
    }
@@ -1900,7 +1912,7 @@ void ChartController::impl_SetMousePointer( const MouseEvent & rEvent )
                }
                break;
        }
        m_pChartWindow->SetPointer( Pointer( ePointerStyle ) );
        pChartWindow->SetPointer( Pointer( ePointerStyle ) );
        return;
    }

@@ -1912,7 +1924,7 @@ void ChartController::impl_SetMousePointer( const MouseEvent & rEvent )
    {
        if( aHitObjectCID.equals(m_aSelection.getSelectedCID()) )
        {
            m_pChartWindow->SetPointer( Pointer( PointerStyle::Arrow ));
            pChartWindow->SetPointer( Pointer( PointerStyle::Arrow ));
            return;
        }
    }
@@ -1920,14 +1932,14 @@ void ChartController::impl_SetMousePointer( const MouseEvent & rEvent )
    if( aHitObjectCID.isEmpty() )
    {
        //additional shape was hit
        m_pChartWindow->SetPointer( PointerStyle::Move );
        pChartWindow->SetPointer( PointerStyle::Move );
    }
    else if( ObjectIdentifier::isDragableObject( aHitObjectCID ) )
    {
        if( (m_eDragMode == SdrDragMode::Rotate)
            && SelectionHelper::isRotateableObject( aHitObjectCID
                , getModel() ) )
            m_pChartWindow->SetPointer( Pointer( PointerStyle::Rotate ) );
            pChartWindow->SetPointer( Pointer( PointerStyle::Rotate ) );
        else
        {
            ObjectType eHitObjectType = ObjectIdentifier::getObjectType( aHitObjectCID );
@@ -1936,15 +1948,15 @@ void ChartController::impl_SetMousePointer( const MouseEvent & rEvent )
                if( !ObjectIdentifier::areSiblings(aHitObjectCID,m_aSelection.getSelectedCID())
                    && !ObjectIdentifier::areIdenticalObjects(aHitObjectCID,m_aSelection.getSelectedCID()) )
                {
                    m_pChartWindow->SetPointer( Pointer( PointerStyle::Arrow ));
                    pChartWindow->SetPointer( Pointer( PointerStyle::Arrow ));
                    return;
                }
            }
            m_pChartWindow->SetPointer( PointerStyle::Move );
            pChartWindow->SetPointer( PointerStyle::Move );
        }
    }
    else
        m_pChartWindow->SetPointer( Pointer( PointerStyle::Arrow ));
        pChartWindow->SetPointer( Pointer( PointerStyle::Arrow ));
}

css::uno::Reference<css::uno::XInterface> const & ChartController::getChartView()