Version 5.4.3.2, tag libreoffice-5.4.3.2
[LibreOffice.git] / svx / source / stbctrls / zoomctrl.cxx
blobea1059862330146a653c6a8c59ddc24b86567bd0
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/builder.hxx>
22 #include <vcl/svapp.hxx>
23 #include <vcl/status.hxx>
24 #include <vcl/menu.hxx>
25 #include <vcl/settings.hxx>
26 #include <sfx2/dispatch.hxx>
27 #include <tools/urlobj.hxx>
29 #include <svx/dialogs.hrc>
31 #include <svx/zoomctrl.hxx>
32 #include <svx/zoomslideritem.hxx>
33 #include <sfx2/zoomitem.hxx>
34 #include "stbctrls.h"
35 #include <svx/dialmgr.hxx>
36 #include "modctrl_internal.hxx"
37 #include "bitmaps.hlst"
39 SFX_IMPL_STATUSBAR_CONTROL(SvxZoomStatusBarControl,SvxZoomItem);
41 class ZoomPopup_Impl
43 public:
44 ZoomPopup_Impl( sal_uInt16 nZ, SvxZoomEnableFlags nValueSet );
46 sal_uInt16 GetZoom();
47 OString GetCurItemIdent() const { return m_xMenu->GetCurItemIdent(); }
49 sal_uInt16 Execute(vcl::Window* pWindow, const Point& rPopupPos)
51 return m_xMenu->Execute(pWindow, rPopupPos);
54 private:
55 VclBuilder m_aBuilder;
56 VclPtr<PopupMenu> m_xMenu;
57 sal_uInt16 nZoom;
60 ZoomPopup_Impl::ZoomPopup_Impl( sal_uInt16 nZ, SvxZoomEnableFlags nValueSet )
61 : m_aBuilder(nullptr, VclBuilderContainer::getUIRootDir(), "svx/ui/zoommenu.ui", "")
62 , m_xMenu(m_aBuilder.get_menu("menu"))
63 , nZoom(nZ)
65 if ( !(SvxZoomEnableFlags::N50 & nValueSet) )
66 m_xMenu->EnableItem("50", false);
67 if ( !(SvxZoomEnableFlags::N100 & nValueSet) )
68 m_xMenu->EnableItem("100", false);
69 if ( !(SvxZoomEnableFlags::N150 & nValueSet) )
70 m_xMenu->EnableItem("150", false);
71 if ( !(SvxZoomEnableFlags::N200 & nValueSet) )
72 m_xMenu->EnableItem("200", false);
73 if ( !(SvxZoomEnableFlags::OPTIMAL & nValueSet) )
74 m_xMenu->EnableItem("optimal", false);
75 if ( !(SvxZoomEnableFlags::WHOLEPAGE & nValueSet) )
76 m_xMenu->EnableItem("page", false);
77 if ( !(SvxZoomEnableFlags::PAGEWIDTH & nValueSet) )
78 m_xMenu->EnableItem("width", false);
81 sal_uInt16 ZoomPopup_Impl::GetZoom()
83 OString sIdent = GetCurItemIdent();
84 if (sIdent == "200")
85 nZoom = 200;
86 else if (sIdent == "150")
87 nZoom = 150;
88 else if (sIdent == "100")
89 nZoom = 100;
90 else if (sIdent == "75")
91 nZoom = 75;
92 else if (sIdent == "50")
93 nZoom = 50;
94 else if (sIdent == "optimal" || sIdent == "width" || sIdent == "page")
95 nZoom = 0;
97 return nZoom;
100 SvxZoomStatusBarControl::SvxZoomStatusBarControl( sal_uInt16 _nSlotId,
101 sal_uInt16 _nId,
102 StatusBar& rStb ) :
104 SfxStatusBarControl( _nSlotId, _nId, rStb ),
105 nZoom( 100 ),
106 nValueSet( SvxZoomEnableFlags::ALL )
108 GetStatusBar().SetQuickHelpText(GetId(), SvxResId(RID_SVXSTR_ZOOMTOOL_HINT));
111 void SvxZoomStatusBarControl::StateChanged( sal_uInt16, SfxItemState eState,
112 const SfxPoolItem* pState )
114 if( SfxItemState::DEFAULT != eState )
116 GetStatusBar().SetItemText( GetId(), "" );
117 nValueSet = SvxZoomEnableFlags::NONE;
119 else if ( dynamic_cast< const SfxUInt16Item* >(pState) != nullptr )
121 const SfxUInt16Item* pItem = static_cast<const SfxUInt16Item*>(pState);
122 nZoom = pItem->GetValue();
124 OUString aStr(unicode::formatPercent(nZoom, Application::GetSettings().GetUILanguageTag()));
125 GetStatusBar().SetItemText( GetId(), aStr );
127 if ( dynamic_cast<const SvxZoomItem*>( pState) != nullptr )
129 nValueSet = static_cast<const SvxZoomItem*>(pState)->GetValueSet();
131 else
133 SAL_INFO( "svx", "use SfxZoomItem for SID_ATTR_ZOOM" );
134 nValueSet = SvxZoomEnableFlags::ALL;
139 void SvxZoomStatusBarControl::Paint( const UserDrawEvent& )
141 OUString aStr(unicode::formatPercent(nZoom, Application::GetSettings().GetUILanguageTag()));
142 GetStatusBar().SetItemText( GetId(), aStr );
145 void SvxZoomStatusBarControl::Command( const CommandEvent& rCEvt )
147 if ( CommandEventId::ContextMenu == rCEvt.GetCommand() && bool(nValueSet) )
149 ZoomPopup_Impl aPop(nZoom, nValueSet);
150 StatusBar& rStatusbar = GetStatusBar();
152 if (aPop.Execute(&rStatusbar, rCEvt.GetMousePosPixel()) && (nZoom != aPop.GetZoom() || !nZoom))
154 nZoom = aPop.GetZoom();
155 SvxZoomItem aZoom(SvxZoomType::PERCENT, nZoom, GetId());
157 OString sIdent = aPop.GetCurItemIdent();
158 if (sIdent == "optimal")
159 aZoom.SetType(SvxZoomType::OPTIMAL);
160 else if (sIdent == "width")
161 aZoom.SetType(SvxZoomType::PAGEWIDTH);
162 else if (sIdent == "page")
163 aZoom.SetType(SvxZoomType::WHOLEPAGE);
165 css::uno::Any a;
166 INetURLObject aObj( m_aCommandURL );
168 css::uno::Sequence< css::beans::PropertyValue > aArgs( 1 );
169 aArgs[0].Name = aObj.GetURLPath();
170 aZoom.QueryValue( a );
171 aArgs[0].Value = a;
173 execute( aArgs );
176 else
177 SfxStatusBarControl::Command( rCEvt );
180 SFX_IMPL_STATUSBAR_CONTROL(SvxZoomPageStatusBarControl,SfxVoidItem);
182 SvxZoomPageStatusBarControl::SvxZoomPageStatusBarControl(sal_uInt16 _nSlotId,
183 sal_uInt16 _nId, StatusBar& rStb)
184 : SfxStatusBarControl(_nSlotId, _nId, rStb)
185 , maImage(BitmapEx(RID_SVXBMP_ZOOM_PAGE))
187 GetStatusBar().SetQuickHelpText(GetId(), SvxResId(RID_SVXSTR_FIT_SLIDE));
190 void SvxZoomPageStatusBarControl::Paint(const UserDrawEvent& rUsrEvt)
192 vcl::RenderContext* pDev = rUsrEvt.GetRenderContext();
193 tools::Rectangle aRect = rUsrEvt.GetRect();
194 Point aPt = centerImage(aRect, maImage);
195 pDev->DrawImage(aPt, maImage);
198 bool SvxZoomPageStatusBarControl::MouseButtonDown(const MouseEvent&)
200 SvxZoomItem aZoom( SvxZoomType::WHOLEPAGE, 0, GetId() );
202 css::uno::Any a;
203 INetURLObject aObj( m_aCommandURL );
205 css::uno::Sequence< css::beans::PropertyValue > aArgs( 1 );
206 aArgs[0].Name = aObj.GetURLPath();
207 aZoom.QueryValue( a );
208 aArgs[0].Value = a;
210 execute( aArgs );
212 return true;
215 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */