tdf#152078 Enable Ctrl+Wheel zoom in Basic code editor

Change-Id: Ic68ae67c311a83e4003da2ca7486fcbf6698bdc5
Reviewed-on: https://gerrit.libreoffice.org/c/core/+/143584
Tested-by: Jenkins
Reviewed-by: Jim Raykowski <raykowj@gmail.com>
diff --git a/basctl/Library_basctl.mk b/basctl/Library_basctl.mk
index 693ac39..bbd9a00 100644
--- a/basctl/Library_basctl.mk
+++ b/basctl/Library_basctl.mk
@@ -40,6 +40,7 @@ $(eval $(call gb_Library_set_precompiled_header,basctl,basctl/inc/pch/precompile
$(eval $(call gb_Library_use_sdk_api,basctl))

$(eval $(call gb_Library_use_libraries,basctl,\
	basegfx \
	comphelper \
	cppu \
	cppuhelper \
diff --git a/basctl/source/basicide/baside2b.cxx b/basctl/source/basicide/baside2b.cxx
index e0dfe9f..b5deee9 100644
--- a/basctl/source/basicide/baside2b.cxx
+++ b/basctl/source/basicide/baside2b.cxx
@@ -71,6 +71,7 @@
#include <o3tl/string_view.hxx>
#include "textwindowpeer.hxx"
#include "uiobject.hxx"
#include <basegfx/utils/zoomtools.hxx>

namespace basctl
{
@@ -499,8 +500,25 @@ void EditorWindow::Command( const CommandEvent& rCEvt )
         ( rCEvt.GetCommand() == CommandEventId::StartAutoScroll ) ||
         ( rCEvt.GetCommand() == CommandEventId::AutoScroll ) )
    {
        HandleScrollCommand( rCEvt, &rModulWindow.GetEditHScrollBar(), &rModulWindow.GetEditVScrollBar() );
    } else if ( rCEvt.GetCommand() == CommandEventId::ContextMenu ) {
        const CommandWheelData* pData = rCEvt.GetWheelData();

        // Check if it is a Ctrl+Wheel zoom command
        if (pData->IsMod1())
        {
            const sal_uInt16 nOldZoom = GetCurrentZoom();
            sal_uInt16 nNewZoom;
            if( pData->GetDelta() < 0 )
                nNewZoom = std::max<sal_uInt16>(basctl::Shell::GetMinZoom(),
                                                basegfx::zoomtools::zoomOut(nOldZoom));
            else
                nNewZoom = std::min<sal_uInt16>(basctl::Shell::GetMaxZoom(),
                                                basegfx::zoomtools::zoomIn(nOldZoom));
            GetShell()->SetGlobalEditorZoomLevel(nNewZoom);
        }
        else
            HandleScrollCommand(rCEvt, &rModulWindow.GetEditHScrollBar(), &rModulWindow.GetEditVScrollBar());
    }
    else if ( rCEvt.GetCommand() == CommandEventId::ContextMenu ) {
        SfxDispatcher* pDispatcher = GetDispatcher();
        if ( pDispatcher )
        {
diff --git a/basctl/source/basicide/basides1.cxx b/basctl/source/basicide/basides1.cxx
index 490a4dc..fd0fb7a 100644
--- a/basctl/source/basicide/basides1.cxx
+++ b/basctl/source/basicide/basides1.cxx
@@ -770,23 +770,8 @@ void Shell::ExecuteGlobal( SfxRequest& rReq )
            const SfxItemSet *pArgs = rReq.GetArgs();
            const SfxPoolItem* pItem;

            if ( pArgs && pArgs->GetItemState(SID_ATTR_ZOOMSLIDER, true, &pItem ) == SfxItemState::SET )
            {
                nCurrentZoomSliderValue = static_cast<const SvxZoomSliderItem*>(pItem)->GetValue();
                // Apply zoom to all open windows
                for (auto const& window : aWindowTable)
                {
                    ModulWindow* pModuleWindow = dynamic_cast<ModulWindow*>(window.second.get());
                    if (pModuleWindow)
                    {
                        EditorWindow& pEditorWindow = pModuleWindow->GetEditorWindow();
                        pEditorWindow.SetEditorZoomLevel(nCurrentZoomSliderValue);
                    }
                }

                if (SfxBindings* pBindings = GetBindingsPtr())
                    pBindings->Invalidate( SID_BASICIDE_CURRENT_ZOOM );
            }
            if (pArgs && pArgs->GetItemState(SID_ATTR_ZOOMSLIDER, true, &pItem ) == SfxItemState::SET)
                SetGlobalEditorZoomLevel(static_cast<const SvxZoomSliderItem*>(pItem)->GetValue());
        }
        break;

@@ -1046,7 +1031,7 @@ void Shell::GetState(SfxItemSet &rSet)
                if (pModuleWindow)
                {
                    OUString sZoom;
                    sZoom = OUString::number(nCurrentZoomSliderValue) + "%";
                    sZoom = OUString::number(m_nCurrentZoomSliderValue) + "%";
                    SfxStringItem aItem( SID_BASICIDE_CURRENT_ZOOM, sZoom );
                    rSet.Put( aItem );
                }
diff --git a/basctl/source/basicide/basidesh.cxx b/basctl/source/basicide/basidesh.cxx
index a08a675..eb3d699 100644
--- a/basctl/source/basicide/basidesh.cxx
+++ b/basctl/source/basicide/basidesh.cxx
@@ -263,7 +263,7 @@ Shell::~Shell()

    // Remember current zoom level
    SvtViewOptions(EViewType::Window, BASIC_IDE_EDITOR_WINDOW).SetUserItem(
        BASIC_IDE_CURRENT_ZOOM, Any(nCurrentZoomSliderValue));
        BASIC_IDE_CURRENT_ZOOM, Any(m_nCurrentZoomSliderValue));
}

void Shell::onDocumentCreated( const ScriptDocument& /*_rDocument*/ )
@@ -368,19 +368,42 @@ void Shell::onDocumentModeChanged( const ScriptDocument& _rDocument )

void Shell::InitZoomLevel()
{
    nCurrentZoomSliderValue = DEFAULT_ZOOM_LEVEL;
    m_nCurrentZoomSliderValue = DEFAULT_ZOOM_LEVEL;
    SvtViewOptions aWinOpt(EViewType::Window, BASIC_IDE_EDITOR_WINDOW);
    if (aWinOpt.Exists())
    {
        try
        {
            aWinOpt.GetUserItem(BASIC_IDE_CURRENT_ZOOM) >>= nCurrentZoomSliderValue;
            aWinOpt.GetUserItem(BASIC_IDE_CURRENT_ZOOM) >>= m_nCurrentZoomSliderValue;
        }
        catch(const css::container::NoSuchElementException&)
        { TOOLS_WARN_EXCEPTION("basctl.basicide", "Zoom level not defined"); }
    }
}

// Applies the new zoom level to all open editor windows
void Shell::SetGlobalEditorZoomLevel(sal_uInt16 nNewZoomLevel)
{
    for (auto const& window : aWindowTable)
    {
        ModulWindow* pModuleWindow = dynamic_cast<ModulWindow*>(window.second.get());
        if (pModuleWindow)
        {
            EditorWindow& pEditorWindow = pModuleWindow->GetEditorWindow();
            pEditorWindow.SetEditorZoomLevel(nNewZoomLevel);
        }
    }

    // Update the zoom slider value based on the new global zoom level
    m_nCurrentZoomSliderValue = nNewZoomLevel;

    if (SfxBindings* pBindings = GetBindingsPtr())
    {
        pBindings->Invalidate( SID_BASICIDE_CURRENT_ZOOM );
        pBindings->Invalidate( SID_ATTR_ZOOMSLIDER );
    }
}

void Shell::StoreAllWindowData( bool bPersistent )
{
    for (auto const& window : aWindowTable)
diff --git a/basctl/source/inc/basidesh.hxx b/basctl/source/inc/basidesh.hxx
index c8c634d..7c8779d 100644
--- a/basctl/source/inc/basidesh.hxx
+++ b/basctl/source/inc/basidesh.hxx
@@ -75,7 +75,7 @@ private:
    std::shared_ptr<LocalizationMgr> m_pCurLocalizationMgr;

    // Current value of the zoom slider
    sal_uInt16          nCurrentZoomSliderValue;
    sal_uInt16            m_nCurrentZoomSliderValue;
    VclPtr<ScrollAdaptor> aHScrollBar;
    VclPtr<ScrollAdaptor> aVScrollBar;
    VclPtr<TabBar>       pTabBar;           // basctl::TabBar
@@ -171,7 +171,8 @@ public:

    SfxUndoManager*     GetUndoManager() override;

    sal_uInt16          GetCurrentZoomSliderValue() { return nCurrentZoomSliderValue; }
    void                SetGlobalEditorZoomLevel(sal_uInt16 nNewZoomLevel);
    sal_uInt16          GetCurrentZoomSliderValue() { return m_nCurrentZoomSliderValue; }
    static sal_uInt16   GetMinZoom() { return MIN_ZOOM_LEVEL; }
    static sal_uInt16   GetMaxZoom() { return MAX_ZOOM_LEVEL; }