LibreOffice Module svx (master) 1
zoomctrl.cxx
Go to the documentation of this file.
1/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2/*
3 * This file is part of the LibreOffice project.
4 *
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/.
8 *
9 * This file incorporates work covered by the following license notice:
10 *
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 .
18 */
19
20#include <sal/config.h>
21
23#include <i18nutil/unicode.hxx>
24#include <vcl/commandevent.hxx>
25#include <vcl/event.hxx>
26#include <vcl/svapp.hxx>
27#include <vcl/status.hxx>
28#include <vcl/weldutils.hxx>
29#include <vcl/settings.hxx>
30#include <tools/urlobj.hxx>
31#include <sal/log.hxx>
32
33#include <svx/strings.hrc>
34
35#include <svx/zoomctrl.hxx>
36#include <sfx2/zoomitem.hxx>
37#include <svx/dialmgr.hxx>
38#include "modctrl_internal.hxx"
39#include <bitmaps.hlst>
40
41#include <com/sun/star/beans/PropertyValue.hpp>
42
44
45namespace {
46
47class ZoomPopup_Impl
48{
49public:
50 ZoomPopup_Impl(weld::Window* pPopupParent, sal_uInt16 nZ, SvxZoomEnableFlags nValueSet);
51
52 sal_uInt16 GetZoom(std::string_view ident) const;
53
54 OString popup_at_rect(const tools::Rectangle& rRect)
55 {
56 return m_xMenu->popup_at_rect(m_pPopupParent, rRect);
57 }
58
59private:
60 weld::Window* m_pPopupParent;
61 std::unique_ptr<weld::Builder> m_xBuilder;
62 std::unique_ptr<weld::Menu> m_xMenu;
63 sal_uInt16 nZoom;
64};
65
66}
67
68ZoomPopup_Impl::ZoomPopup_Impl(weld::Window* pPopupParent, sal_uInt16 nZ, SvxZoomEnableFlags nValueSet)
69 : m_pPopupParent(pPopupParent)
70 , m_xBuilder(Application::CreateBuilder(m_pPopupParent, "svx/ui/zoommenu.ui"))
71 , m_xMenu(m_xBuilder->weld_menu("menu"))
72 , nZoom(nZ)
73{
74 if ( !(SvxZoomEnableFlags::N50 & nValueSet) )
75 m_xMenu->set_sensitive("50", false);
76 if ( !(SvxZoomEnableFlags::N100 & nValueSet) )
77 m_xMenu->set_sensitive("100", false);
78 if ( !(SvxZoomEnableFlags::N150 & nValueSet) )
79 m_xMenu->set_sensitive("150", false);
80 if ( !(SvxZoomEnableFlags::N200 & nValueSet) )
81 m_xMenu->set_sensitive("200", false);
82 if ( !(SvxZoomEnableFlags::OPTIMAL & nValueSet) )
83 m_xMenu->set_sensitive("optimal", false);
84 if ( !(SvxZoomEnableFlags::WHOLEPAGE & nValueSet) )
85 m_xMenu->set_sensitive("page", false);
86 if ( !(SvxZoomEnableFlags::PAGEWIDTH & nValueSet) )
87 m_xMenu->set_sensitive("width", false);
88}
89
90sal_uInt16 ZoomPopup_Impl::GetZoom(std::string_view ident) const
91{
92 sal_uInt16 nRet = nZoom;
93
94 if (ident == "200")
95 nRet = 200;
96 else if (ident == "150")
97 nRet = 150;
98 else if (ident == "100")
99 nRet = 100;
100 else if (ident == "75")
101 nRet = 75;
102 else if (ident == "50")
103 nRet = 50;
104 else if (ident == "optimal" || ident == "width" || ident == "page")
105 nRet = 0;
106
107 return nRet;
108}
109
111 sal_uInt16 _nId,
112 StatusBar& rStb ) :
113
114 SfxStatusBarControl( _nSlotId, _nId, rStb ),
115 nZoom( 100 ),
116 nValueSet( SvxZoomEnableFlags::ALL )
117{
118 GetStatusBar().SetQuickHelpText(GetId(), SvxResId(RID_SVXSTR_ZOOMTOOL_HINT));
120}
121
123 const SfxPoolItem* pState )
124{
125 if( SfxItemState::DEFAULT != eState )
126 {
127 GetStatusBar().SetItemText( GetId(), "" );
128 nValueSet = SvxZoomEnableFlags::NONE;
129 }
130 else if ( auto pItem = dynamic_cast< const SfxUInt16Item* >(pState) )
131 {
132 nZoom = pItem->GetValue();
134
135 if ( auto pZoomItem = dynamic_cast<const SvxZoomItem*>(pState) )
136 {
137 nValueSet = pZoomItem->GetValueSet();
138 }
139 else
140 {
141 SAL_INFO( "svx", "use SfxZoomItem for SID_ATTR_ZOOM" );
142 nValueSet = SvxZoomEnableFlags::ALL;
143 }
144 }
145}
146
148{
149 // workaround - don't bother updating when we don't have a real zoom value
150 if (nZoom)
151 {
152 OUString aStr(unicode::formatPercent(nZoom, Application::GetSettings().GetUILanguageTag()));
154 }
155}
156
158{
159}
160
162{
163 if ( CommandEventId::ContextMenu == rCEvt.GetCommand() && bool(nValueSet) )
164 {
165 ::tools::Rectangle aRect(rCEvt.GetMousePosPixel(), Size(1, 1));
166 weld::Window* pPopupParent = weld::GetPopupParent(GetStatusBar(), aRect);
167 ZoomPopup_Impl aPop(pPopupParent, nZoom, nValueSet);
168
169 OString sIdent = aPop.popup_at_rect(aRect);
170 if (!sIdent.isEmpty() && (nZoom != aPop.GetZoom(sIdent) || !nZoom))
171 {
172 nZoom = aPop.GetZoom(sIdent);
174 SvxZoomItem aZoom(SvxZoomType::PERCENT, nZoom, GetId());
175
176 if (sIdent == "optimal")
177 aZoom.SetType(SvxZoomType::OPTIMAL);
178 else if (sIdent == "width")
179 aZoom.SetType(SvxZoomType::PAGEWIDTH);
180 else if (sIdent == "page")
181 aZoom.SetType(SvxZoomType::WHOLEPAGE);
182
183 css::uno::Any a;
184 aZoom.QueryValue( a );
185 INetURLObject aObj( m_aCommandURL );
186
187 css::uno::Sequence< css::beans::PropertyValue > aArgs{ comphelper::makePropertyValue(
188 aObj.GetURLPath(), a) };
189 execute( aArgs );
190 }
191 }
192 else
194}
195
197
199 sal_uInt16 _nId, StatusBar& rStb)
200 : SfxStatusBarControl(_nSlotId, _nId, rStb)
201 , maImage(StockImage::Yes, RID_SVXBMP_ZOOM_PAGE)
202{
203 GetStatusBar().SetQuickHelpText(GetId(), SvxResId(RID_SVXSTR_FIT_SLIDE));
204}
205
207{
208 vcl::RenderContext* pDev = rUsrEvt.GetRenderContext();
209 tools::Rectangle aRect = rUsrEvt.GetRect();
210 Point aPt = centerImage(aRect, maImage);
211 pDev->DrawImage(aPt, maImage);
212}
213
215{
216 SvxZoomItem aZoom( SvxZoomType::WHOLEPAGE, 0, GetId() );
217
218 css::uno::Any a;
219 aZoom.QueryValue( a );
220 INetURLObject aObj( m_aCommandURL );
221
222 css::uno::Sequence< css::beans::PropertyValue > aArgs{ comphelper::makePropertyValue(
223 aObj.GetURLPath(), a) };
224 execute( aArgs );
225
226 return true;
227}
228
229/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
static const AllSettings & GetSettings()
CommandEventId GetCommand() const
const Point & GetMousePosPixel() const
OUString GetURLPath(DecodeMechanism eMechanism=DecodeMechanism::ToIUri, rtl_TextEncoding eCharset=RTL_TEXTENCODING_UTF8) const
void DrawImage(const Point &rPos, const Image &rImage, DrawImageFlags nStyle=DrawImageFlags::NONE)
StatusBar & GetStatusBar() const
virtual void Command(const CommandEvent &rCEvt)
sal_uInt16 GetId() const
void SetItemText(sal_uInt16 nItemId, const OUString &rText, int nCharsWidth=-1)
void SetQuickHelpText(sal_uInt16 nItemId, const OUString &rText)
void SetType(SvxZoomType eNewType)
virtual bool QueryValue(css::uno::Any &rVal, sal_uInt8 nMemberId=0) const override
SvxZoomPageStatusBarControl(sal_uInt16 nSlotId, sal_uInt16 nId, StatusBar &rStb)
Definition: zoomctrl.cxx:198
virtual bool MouseButtonDown(const MouseEvent &rEvt) override
Definition: zoomctrl.cxx:214
virtual void Paint(const UserDrawEvent &rEvt) override
Definition: zoomctrl.cxx:206
virtual void Command(const CommandEvent &rCEvt) override
Definition: zoomctrl.cxx:161
SvxZoomEnableFlags nValueSet
Definition: zoomctrl.hxx:31
virtual void StateChangedAtStatusBarControl(sal_uInt16 nSID, SfxItemState eState, const SfxPoolItem *pState) override
Definition: zoomctrl.cxx:122
virtual void Paint(const UserDrawEvent &rEvt) override
Definition: zoomctrl.cxx:157
SvxZoomStatusBarControl(sal_uInt16 nSlotId, sal_uInt16 nId, StatusBar &rStb)
Definition: zoomctrl.cxx:110
vcl::RenderContext * GetRenderContext() const
const tools::Rectangle & GetRect() const
static OUString formatPercent(double dNumber, const LanguageTag &rLangTag)
OUString SvxResId(TranslateId aId)
Definition: dialmgr.cxx:24
StockImage
uno_Any a
#define SAL_INFO(area, stream)
aStr
Point centerImage(const tools::Rectangle &rBoundingRect, const Image &rImg)
Given a bounding rectangle and an image, determine the top-left position of the image so that the ima...
Definition: modctrl.cxx:127
Yes
css::beans::PropertyValue makePropertyValue(const OUString &rName, T &&rValue)
weld::Window * GetPopupParent(vcl::Window &rOutWin, tools::Rectangle &rRect)
SfxItemState
SFX_IMPL_STATUSBAR_CONTROL(SvxZoomStatusBarControl, SvxZoomItem)
SvxZoomEnableFlags