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#include <com/sun/star/frame/ModuleManager.hpp>
43
45
46namespace {
47
48class ZoomPopup_Impl
49{
50public:
51 ZoomPopup_Impl(weld::Window* pPopupParent, sal_uInt16 nZ, SvxZoomEnableFlags nValueSet);
52
53 sal_uInt16 GetZoom(std::u16string_view ident) const;
54
55 OUString popup_at_rect(const tools::Rectangle& rRect)
56 {
57 return m_xMenu->popup_at_rect(m_pPopupParent, rRect);
58 }
59
60private:
61 weld::Window* m_pPopupParent;
62 std::unique_ptr<weld::Builder> m_xBuilder;
63 std::unique_ptr<weld::Menu> m_xMenu;
64 sal_uInt16 nZoom;
65};
66
67}
68
69ZoomPopup_Impl::ZoomPopup_Impl(weld::Window* pPopupParent, sal_uInt16 nZ, SvxZoomEnableFlags nValueSet)
70 : m_pPopupParent(pPopupParent)
71 , m_xBuilder(Application::CreateBuilder(m_pPopupParent, "svx/ui/zoommenu.ui"))
72 , m_xMenu(m_xBuilder->weld_menu("menu"))
73 , nZoom(nZ)
74{
75 if ( !(SvxZoomEnableFlags::N50 & nValueSet) )
76 m_xMenu->set_sensitive("50", false);
77 if ( !(SvxZoomEnableFlags::N100 & nValueSet) )
78 m_xMenu->set_sensitive("100", false);
79 if ( !(SvxZoomEnableFlags::N150 & nValueSet) )
80 m_xMenu->set_sensitive("150", false);
81 if ( !(SvxZoomEnableFlags::N200 & nValueSet) )
82 m_xMenu->set_sensitive("200", false);
83 if ( !(SvxZoomEnableFlags::OPTIMAL & nValueSet) )
84 m_xMenu->set_sensitive("optimal", false);
85 if ( !(SvxZoomEnableFlags::WHOLEPAGE & nValueSet) )
86 m_xMenu->set_sensitive("page", false);
87 if ( !(SvxZoomEnableFlags::PAGEWIDTH & nValueSet) )
88 m_xMenu->set_sensitive("width", false);
89}
90
91sal_uInt16 ZoomPopup_Impl::GetZoom(std::u16string_view ident) const
92{
93 sal_uInt16 nRet = nZoom;
94
95 if (ident == u"200")
96 nRet = 200;
97 else if (ident == u"150")
98 nRet = 150;
99 else if (ident == u"100")
100 nRet = 100;
101 else if (ident == u"75")
102 nRet = 75;
103 else if (ident == u"50")
104 nRet = 50;
105 else if (ident == u"optimal" || ident == u"width" || ident == u"page")
106 nRet = 0;
107
108 return nRet;
109}
110
112 sal_uInt16 _nId,
113 StatusBar& rStb ) :
114
115 SfxStatusBarControl( _nSlotId, _nId, rStb ),
116 nZoom( 100 ),
117 nValueSet( SvxZoomEnableFlags::ALL )
118{
119 GetStatusBar().SetQuickHelpText(GetId(), SvxResId(RID_SVXSTR_ZOOMTOOL_HINT));
121}
122
124 const SfxPoolItem* pState )
125{
126 if( SfxItemState::DEFAULT != eState )
127 {
128 GetStatusBar().SetItemText( GetId(), "" );
129 nValueSet = SvxZoomEnableFlags::NONE;
130 }
131 else if ( auto pItem = dynamic_cast< const SfxUInt16Item* >(pState) )
132 {
133 nZoom = pItem->GetValue();
135
136 if ( auto pZoomItem = dynamic_cast<const SvxZoomItem*>(pState) )
137 {
138 nValueSet = pZoomItem->GetValueSet();
139 }
140 else
141 {
142 SAL_INFO( "svx", "use SfxZoomItem for SID_ATTR_ZOOM" );
143 nValueSet = SvxZoomEnableFlags::ALL;
144 }
145 }
146}
147
149{
150 // workaround - don't bother updating when we don't have a real zoom value
151 if (nZoom)
152 {
153 OUString aStr(unicode::formatPercent(nZoom, Application::GetSettings().GetUILanguageTag()));
155 }
156}
157
159{
160}
161
163{
164 if ( CommandEventId::ContextMenu == rCEvt.GetCommand() && bool(nValueSet) )
165 {
166 ::tools::Rectangle aRect(rCEvt.GetMousePosPixel(), Size(1, 1));
167 weld::Window* pPopupParent = weld::GetPopupParent(GetStatusBar(), aRect);
168 ZoomPopup_Impl aPop(pPopupParent, nZoom, nValueSet);
169
170 OUString sIdent = aPop.popup_at_rect(aRect);
171 if (!sIdent.isEmpty() && (nZoom != aPop.GetZoom(sIdent) || !nZoom))
172 {
173 nZoom = aPop.GetZoom(sIdent);
175 SvxZoomItem aZoom(SvxZoomType::PERCENT, nZoom, TypedWhichId<SvxZoomItem>(GetId()));
176
177 if (sIdent == "optimal")
178 aZoom.SetType(SvxZoomType::OPTIMAL);
179 else if (sIdent == "width")
180 aZoom.SetType(SvxZoomType::PAGEWIDTH);
181 else if (sIdent == "page")
182 aZoom.SetType(SvxZoomType::WHOLEPAGE);
183
184 css::uno::Any a;
185 aZoom.QueryValue( a );
186 INetURLObject aObj( m_aCommandURL );
187
188 css::uno::Sequence< css::beans::PropertyValue > aArgs{ comphelper::makePropertyValue(
189 aObj.GetURLPath(), a) };
190 execute( aArgs );
191 }
192 }
193 else
195}
196
198
200 sal_uInt16 _nId, StatusBar& rStb)
201 : SfxStatusBarControl(_nSlotId, _nId, rStb)
202 , maImage(StockImage::Yes, RID_SVXBMP_ZOOM_PAGE)
203{
204 GetStatusBar().SetQuickHelpText(GetId(), SvxResId(RID_SVXSTR_FIT_SLIDE));
205}
206
207void SAL_CALL SvxZoomPageStatusBarControl::initialize( const css::uno::Sequence< css::uno::Any >& aArguments )
208{
209 // Call inherited initialize
210 StatusbarController::initialize(aArguments);
211
212 // Get document type
213 css::uno::Reference< css::frame::XModuleManager2 > xModuleManager = css::frame::ModuleManager::create( m_xContext );
214 OUString aModuleIdentifier = xModuleManager->identify( css::uno::Reference<XInterface>( m_xFrame, css::uno::UnoReference_Query::UNO_QUERY ) );
215
216 // Decide what to show in zoom bar
217 if ( aModuleIdentifier == "com.sun.star.drawing.DrawingDocument" )
218 {
219 GetStatusBar().SetQuickHelpText(GetId(), SvxResId(RID_SVXSTR_FIT_PAGE));
220 }
221 else if ( aModuleIdentifier == "com.sun.star.presentation.PresentationDocument" )
222 {
223 GetStatusBar().SetQuickHelpText(GetId(), SvxResId(RID_SVXSTR_FIT_SLIDE));
224 }
225}
226
228{
229 vcl::RenderContext* pDev = rUsrEvt.GetRenderContext();
230 tools::Rectangle aRect = rUsrEvt.GetRect();
231 Point aPt = centerImage(aRect, maImage);
232 pDev->DrawImage(aPt, maImage);
233}
234
236{
237 SvxZoomItem aZoom( SvxZoomType::WHOLEPAGE, 0, TypedWhichId<SvxZoomItem>(GetId()) );
238
239 css::uno::Any a;
240 aZoom.QueryValue( a );
241 INetURLObject aObj( m_aCommandURL );
242
243 css::uno::Sequence< css::beans::PropertyValue > aArgs{ comphelper::makePropertyValue(
244 aObj.GetURLPath(), a) };
245 execute( aArgs );
246
247 return true;
248}
249
250/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
Reference< XComponentContext > m_xContext
css::uno::Reference< css::lang::XComponent > m_xFrame
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:199
virtual bool MouseButtonDown(const MouseEvent &rEvt) override
Definition: zoomctrl.cxx:235
virtual void SAL_CALL initialize(const css::uno::Sequence< css::uno::Any > &aArguments) override
Definition: zoomctrl.cxx:207
virtual void Paint(const UserDrawEvent &rEvt) override
Definition: zoomctrl.cxx:227
virtual void Command(const CommandEvent &rCEvt) override
Definition: zoomctrl.cxx:162
SvxZoomEnableFlags nValueSet
Definition: zoomctrl.hxx:31
virtual void StateChangedAtStatusBarControl(sal_uInt16 nSID, SfxItemState eState, const SfxPoolItem *pState) override
Definition: zoomctrl.cxx:123
virtual void Paint(const UserDrawEvent &rEvt) override
Definition: zoomctrl.cxx:158
SvxZoomStatusBarControl(sal_uInt16 nSlotId, sal_uInt16 nId, StatusBar &rStb)
Definition: zoomctrl.cxx:111
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
Sequence< PropertyValue > aArguments
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