diff options
author | Rafael Lima <rafael.palma.lima@gmail.com> | 2022-12-05 11:33:32 +0000 |
---|---|---|
committer | Jim Raykowski <raykowj@gmail.com> | 2022-12-08 08:25:16 +0000 |
commit | be6024a2d4fc11c908aeb29b58ce33f851dab6bc (patch) | |
tree | 294e8a3a5efa068871aeee13ef0572aa012b5841 /basctl/source | |
parent | 705b2924a14841883b4a8cac549f7af326d7a185 (diff) |
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>
Diffstat (limited to 'basctl/source')
-rw-r--r-- | basctl/source/basicide/baside2b.cxx | 22 | ||||
-rw-r--r-- | basctl/source/basicide/basides1.cxx | 21 | ||||
-rw-r--r-- | basctl/source/basicide/basidesh.cxx | 29 | ||||
-rw-r--r-- | basctl/source/inc/basidesh.hxx | 5 |
4 files changed, 52 insertions, 25 deletions
diff --git a/basctl/source/basicide/baside2b.cxx b/basctl/source/basicide/baside2b.cxx index e0dfe9f38ee5..b5deee9b6a9e 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 490a4dc0b0e3..fd0fb7acccff 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 a08a675f6378..eb3d6996c191 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 c8c634daae5e..7c8779d62d12 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; } |