bump product version to 7.2.5.1
[LibreOffice.git] / svx / source / stbctrls / zoomctrl.cxx
blob7fcf7bcbabe95873321957a20e77eeb7e05e2881
1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 /*
3 * This file is part of the LibreOffice project.
5 * This Source Code Form is subject to the terms of the Mozilla Public
6 * License, v. 2.0. If a copy of the MPL was not distributed with this
7 * file, You can obtain one at http://mozilla.org/MPL/2.0/.
9 * This file incorporates work covered by the following license notice:
11 * Licensed to the Apache Software Foundation (ASF) under one or more
12 * contributor license agreements. See the NOTICE file distributed
13 * with this work for additional information regarding copyright
14 * ownership. The ASF licenses this file to you under the Apache
15 * License, Version 2.0 (the "License"); you may not use this file
16 * except in compliance with the License. You may obtain a copy of
17 * the License at http://www.apache.org/licenses/LICENSE-2.0 .
20 #include <i18nutil/unicode.hxx>
21 #include <vcl/commandevent.hxx>
22 #include <vcl/event.hxx>
23 #include <vcl/svapp.hxx>
24 #include <vcl/status.hxx>
25 #include <vcl/weldutils.hxx>
26 #include <vcl/settings.hxx>
27 #include <tools/urlobj.hxx>
28 #include <sal/log.hxx>
30 #include <svx/strings.hrc>
32 #include <svx/zoomctrl.hxx>
33 #include <sfx2/zoomitem.hxx>
34 #include <svx/dialmgr.hxx>
35 #include "modctrl_internal.hxx"
36 #include <bitmaps.hlst>
38 #include <com/sun/star/beans/PropertyValue.hpp>
40 SFX_IMPL_STATUSBAR_CONTROL(SvxZoomStatusBarControl,SvxZoomItem);
42 namespace {
44 class ZoomPopup_Impl
46 public:
47 ZoomPopup_Impl(weld::Window* pPopupParent, sal_uInt16 nZ, SvxZoomEnableFlags nValueSet);
49 sal_uInt16 GetZoom(std::string_view ident);
51 OString popup_at_rect(const tools::Rectangle& rRect)
53 return m_xMenu->popup_at_rect(m_pPopupParent, rRect);
56 private:
57 weld::Window* m_pPopupParent;
58 std::unique_ptr<weld::Builder> m_xBuilder;
59 std::unique_ptr<weld::Menu> m_xMenu;
60 sal_uInt16 nZoom;
65 ZoomPopup_Impl::ZoomPopup_Impl(weld::Window* pPopupParent, sal_uInt16 nZ, SvxZoomEnableFlags nValueSet)
66 : m_pPopupParent(pPopupParent)
67 , m_xBuilder(Application::CreateBuilder(m_pPopupParent, "svx/ui/zoommenu.ui"))
68 , m_xMenu(m_xBuilder->weld_menu("menu"))
69 , nZoom(nZ)
71 if ( !(SvxZoomEnableFlags::N50 & nValueSet) )
72 m_xMenu->set_sensitive("50", false);
73 if ( !(SvxZoomEnableFlags::N100 & nValueSet) )
74 m_xMenu->set_sensitive("100", false);
75 if ( !(SvxZoomEnableFlags::N150 & nValueSet) )
76 m_xMenu->set_sensitive("150", false);
77 if ( !(SvxZoomEnableFlags::N200 & nValueSet) )
78 m_xMenu->set_sensitive("200", false);
79 if ( !(SvxZoomEnableFlags::OPTIMAL & nValueSet) )
80 m_xMenu->set_sensitive("optimal", false);
81 if ( !(SvxZoomEnableFlags::WHOLEPAGE & nValueSet) )
82 m_xMenu->set_sensitive("page", false);
83 if ( !(SvxZoomEnableFlags::PAGEWIDTH & nValueSet) )
84 m_xMenu->set_sensitive("width", false);
87 sal_uInt16 ZoomPopup_Impl::GetZoom(std::string_view ident)
89 sal_uInt16 nRet = nZoom;
91 if (ident == "200")
92 nRet = 200;
93 else if (ident == "150")
94 nRet = 150;
95 else if (ident == "100")
96 nRet = 100;
97 else if (ident == "75")
98 nRet = 75;
99 else if (ident == "50")
100 nRet = 50;
101 else if (ident == "optimal" || ident == "width" || ident == "page")
102 nRet = 0;
104 return nRet;
107 SvxZoomStatusBarControl::SvxZoomStatusBarControl( sal_uInt16 _nSlotId,
108 sal_uInt16 _nId,
109 StatusBar& rStb ) :
111 SfxStatusBarControl( _nSlotId, _nId, rStb ),
112 nZoom( 100 ),
113 nValueSet( SvxZoomEnableFlags::ALL )
115 GetStatusBar().SetQuickHelpText(GetId(), SvxResId(RID_SVXSTR_ZOOMTOOL_HINT));
116 ImplUpdateItemText();
119 void SvxZoomStatusBarControl::StateChanged( sal_uInt16, SfxItemState eState,
120 const SfxPoolItem* pState )
122 if( SfxItemState::DEFAULT != eState )
124 GetStatusBar().SetItemText( GetId(), "" );
125 nValueSet = SvxZoomEnableFlags::NONE;
127 else if ( auto pItem = dynamic_cast< const SfxUInt16Item* >(pState) )
129 nZoom = pItem->GetValue();
130 ImplUpdateItemText();
132 if ( auto pZoomItem = dynamic_cast<const SvxZoomItem*>(pState) )
134 nValueSet = pZoomItem->GetValueSet();
136 else
138 SAL_INFO( "svx", "use SfxZoomItem for SID_ATTR_ZOOM" );
139 nValueSet = SvxZoomEnableFlags::ALL;
144 void SvxZoomStatusBarControl::ImplUpdateItemText()
146 // workaround - don't bother updating when we don't have a real zoom value
147 if (nZoom)
149 OUString aStr(unicode::formatPercent(nZoom, Application::GetSettings().GetUILanguageTag()));
150 GetStatusBar().SetItemText( GetId(), aStr );
154 void SvxZoomStatusBarControl::Paint( const UserDrawEvent& )
158 void SvxZoomStatusBarControl::Command( const CommandEvent& rCEvt )
160 if ( CommandEventId::ContextMenu == rCEvt.GetCommand() && bool(nValueSet) )
162 ::tools::Rectangle aRect(rCEvt.GetMousePosPixel(), Size(1, 1));
163 weld::Window* pPopupParent = weld::GetPopupParent(GetStatusBar(), aRect);
164 ZoomPopup_Impl aPop(pPopupParent, nZoom, nValueSet);
166 OString sIdent = aPop.popup_at_rect(aRect);
167 if (!sIdent.isEmpty() && (nZoom != aPop.GetZoom(sIdent) || !nZoom))
169 nZoom = aPop.GetZoom(sIdent);
170 ImplUpdateItemText();
171 SvxZoomItem aZoom(SvxZoomType::PERCENT, nZoom, GetId());
173 if (sIdent == "optimal")
174 aZoom.SetType(SvxZoomType::OPTIMAL);
175 else if (sIdent == "width")
176 aZoom.SetType(SvxZoomType::PAGEWIDTH);
177 else if (sIdent == "page")
178 aZoom.SetType(SvxZoomType::WHOLEPAGE);
180 css::uno::Any a;
181 INetURLObject aObj( m_aCommandURL );
183 css::uno::Sequence< css::beans::PropertyValue > aArgs( 1 );
184 aArgs[0].Name = aObj.GetURLPath();
185 aZoom.QueryValue( a );
186 aArgs[0].Value = a;
188 execute( aArgs );
191 else
192 SfxStatusBarControl::Command( rCEvt );
195 SFX_IMPL_STATUSBAR_CONTROL(SvxZoomPageStatusBarControl,SfxVoidItem);
197 SvxZoomPageStatusBarControl::SvxZoomPageStatusBarControl(sal_uInt16 _nSlotId,
198 sal_uInt16 _nId, StatusBar& rStb)
199 : SfxStatusBarControl(_nSlotId, _nId, rStb)
200 , maImage(StockImage::Yes, RID_SVXBMP_ZOOM_PAGE)
202 GetStatusBar().SetQuickHelpText(GetId(), SvxResId(RID_SVXSTR_FIT_SLIDE));
205 void SvxZoomPageStatusBarControl::Paint(const UserDrawEvent& rUsrEvt)
207 vcl::RenderContext* pDev = rUsrEvt.GetRenderContext();
208 tools::Rectangle aRect = rUsrEvt.GetRect();
209 Point aPt = centerImage(aRect, maImage);
210 pDev->DrawImage(aPt, maImage);
213 bool SvxZoomPageStatusBarControl::MouseButtonDown(const MouseEvent&)
215 SvxZoomItem aZoom( SvxZoomType::WHOLEPAGE, 0, GetId() );
217 css::uno::Any a;
218 INetURLObject aObj( m_aCommandURL );
220 css::uno::Sequence< css::beans::PropertyValue > aArgs( 1 );
221 aArgs[0].Name = aObj.GetURLPath();
222 aZoom.QueryValue( a );
223 aArgs[0].Value = a;
225 execute( aArgs );
227 return true;
230 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */