tdf#121671 Floating toolbars remain their position after reopen

Calculate the relative position of the floating toolbars by calling
the ImplCallMove function, where the current position is read from
the real window.

Change-Id: I6a142055c3340dda2339980fbc5a7ebb431e228b
Reviewed-on: https://gerrit.libreoffice.org/64093
Tested-by: Jenkins
Reviewed-by: Katarina Behrens <Katarina.Behrens@cib.de>
diff --git a/framework/source/layoutmanager/toolbarlayoutmanager.cxx b/framework/source/layoutmanager/toolbarlayoutmanager.cxx
index 9396171..1bd85e5 100644
--- a/framework/source/layoutmanager/toolbarlayoutmanager.cxx
+++ b/framework/source/layoutmanager/toolbarlayoutmanager.cxx
@@ -45,6 +45,7 @@
#include <vcl/settings.hxx>
#include <vcl/svapp.hxx>
#include <sal/log.hxx>
#include <tools/gen.hxx>


using namespace ::com::sun::star;
@@ -428,10 +429,6 @@ bool ToolbarLayoutManager::requestToolbar( const OUString& rResourceURL )

    bool bCreateOrShowToolbar( aRequestedToolbar.m_bVisible && !aRequestedToolbar.m_bMasterHide );

    uno::Reference< awt::XWindow2 > xContainerWindow( m_xContainerWindow, uno::UNO_QUERY );
    if ( xContainerWindow.is() && aRequestedToolbar.m_bFloating )
        bCreateOrShowToolbar &= bool( xContainerWindow->isActive());

    if ( bCreateOrShowToolbar )
        bNotify = bMustCallCreate ? createToolbar( rResourceURL ) : showToolbar( rResourceURL );

@@ -1835,7 +1832,7 @@ void ToolbarLayoutManager::implts_getDockingAreaElementInfos( ui::DockingArea eD
    xDockAreaWindow = m_xDockAreaWindows[static_cast<int>(eDockingArea)];
    for (auto const& elem : m_aUIElements)
    {
        if ( elem.m_aDockedData.m_nDockedArea == eDockingArea && elem.m_bVisible && !elem.m_bFloating )
        if ( elem.m_aDockedData.m_nDockedArea == eDockingArea && elem.m_bVisible )
        {
            uno::Reference< ui::XUIElement > xUIElement( elem.m_xUIElement );
            if ( xUIElement.is() )
@@ -1844,8 +1841,33 @@ void ToolbarLayoutManager::implts_getDockingAreaElementInfos( ui::DockingArea eD
                uno::Reference< awt::XDockableWindow > xDockWindow( xWindow, uno::UNO_QUERY );
                if ( xDockWindow.is() )
                {
                    // docked windows
                    aWindowVector.push_back(elem);
                    if (!elem.m_bFloating)
                    {
                        // docked windows
                        aWindowVector.push_back(elem);
                    }
                    else
                    {
                        // floating windows
                        VclPtr<vcl::Window> pWindow = VCLUnoHelper::GetWindow(xWindow);
                        DockingManager* pDockMgr = vcl::Window::GetDockingManager();
                        if (pDockMgr != nullptr)
                        {
                            ImplDockingWindowWrapper* pWrapper = pDockMgr->GetDockingWindowWrapper(pWindow);
                            if (pWrapper != nullptr && pWrapper->GetFloatingWindow())
                            {
                                // update the position data of the floating window
                                if (pWrapper->GetFloatingWindow()->UpdatePositionData())
                                {
                                    awt::Rectangle aTmpRect = xWindow->getPosSize();
                                    UIElement uiElem = elem;
                                    uiElem.m_aFloatingData.m_aPos = awt::Point(aTmpRect.X, aTmpRect.Y);
                                    implts_setToolbar(uiElem);
                                    implts_writeWindowStateData(uiElem);
                                }
                            }
                        }
                    }
                }
            }
        }
diff --git a/include/vcl/floatwin.hxx b/include/vcl/floatwin.hxx
index a9ac329..75dd4c1 100644
--- a/include/vcl/floatwin.hxx
+++ b/include/vcl/floatwin.hxx
@@ -153,6 +153,7 @@ public:
    void            SetPopupModeEndHdl( const Link<FloatingWindow*,void>& rLink ) { maPopupModeEndHdl = rLink; }

    bool            GrabsFocus() const { return mbGrabFocus; }
    bool            UpdatePositionData();

    static Point    CalcFloatingPosition( vcl::Window* pWindow, const tools::Rectangle& rRect, FloatWinPopupFlags nFlags, sal_uInt16& rArrangeIndex );
};
diff --git a/vcl/source/window/floatwin.cxx b/vcl/source/window/floatwin.cxx
index e632f97..d6b4403 100644
--- a/vcl/source/window/floatwin.cxx
+++ b/vcl/source/window/floatwin.cxx
@@ -888,10 +888,22 @@ void FloatingWindow::EndPopupMode( FloatWinPopupEndFlags nFlags )
    ImplEndPopupMode(nFlags, mxPrevFocusWin);
}

void FloatingWindow::AddPopupModeWindow( vcl::Window* pWindow )
void FloatingWindow::AddPopupModeWindow(vcl::Window* pWindow)
{
    // !!! up-to-now only 1 window and not yet a list
    mpFirstPopupModeWin = pWindow;
}
bool FloatingWindow::UpdatePositionData()
{
    auto pWin = ImplGetParent();
    if (pWin)
    {
        // Simulate Move, so the relative position of the floating window will be recalculated
        pWin->ImplCallMove();
        return true;
    }

    return false;
}

/* vim:set shiftwidth=4 softtabstop=4 expandtab: */