bump product version to 5.0.4.1
[LibreOffice.git] / svx / source / stbctrls / zoomctrl.cxx
blob024ee30f0524214a42de97655388fd03c52ba668
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/svapp.hxx>
22 #include <vcl/status.hxx>
23 #include <vcl/menu.hxx>
24 #include <vcl/settings.hxx>
25 #include <sfx2/dispatch.hxx>
26 #include <tools/urlobj.hxx>
28 #include <svx/dialogs.hrc>
30 #include <svx/zoomctrl.hxx>
31 #include <svx/zoomslideritem.hxx>
32 #include <sfx2/zoomitem.hxx>
33 #include "stbctrls.h"
34 #include <svx/dialmgr.hxx>
35 #include "modctrl_internal.hxx"
37 SFX_IMPL_STATUSBAR_CONTROL(SvxZoomStatusBarControl,SvxZoomItem);
39 class ZoomPopup_Impl : public PopupMenu
41 public:
42 ZoomPopup_Impl( sal_uInt16 nZ, SvxZoomEnableFlags nValueSet );
44 sal_uInt16 GetZoom() const { return nZoom; }
45 sal_uInt16 GetCurId() const { return nCurId; }
47 private:
48 sal_uInt16 nZoom;
49 sal_uInt16 nCurId;
51 virtual void Select() SAL_OVERRIDE;
56 ZoomPopup_Impl::ZoomPopup_Impl( sal_uInt16 nZ, SvxZoomEnableFlags nValueSet )
57 : PopupMenu(ResId(RID_SVXMNU_ZOOM, DIALOG_MGR()))
58 , nZoom(nZ)
59 , nCurId(0)
61 if ( !(SvxZoomEnableFlags::N50 & nValueSet) )
62 EnableItem( ZOOM_50, false );
63 if ( !(SvxZoomEnableFlags::N100 & nValueSet) )
64 EnableItem( ZOOM_100, false );
65 if ( !(SvxZoomEnableFlags::N150 & nValueSet) )
66 EnableItem( ZOOM_150, false );
67 if ( !(SvxZoomEnableFlags::N200 & nValueSet) )
68 EnableItem( ZOOM_200, false );
69 if ( !(SvxZoomEnableFlags::OPTIMAL & nValueSet) )
70 EnableItem( ZOOM_OPTIMAL, false );
71 if ( !(SvxZoomEnableFlags::WHOLEPAGE & nValueSet) )
72 EnableItem( ZOOM_WHOLE_PAGE, false );
73 if ( !(SvxZoomEnableFlags::PAGEWIDTH & nValueSet) )
74 EnableItem( ZOOM_PAGE_WIDTH, false );
79 void ZoomPopup_Impl::Select()
81 nCurId = GetCurItemId();
83 switch ( nCurId )
85 case ZOOM_200: nZoom = 200; break;
86 case ZOOM_150: nZoom = 150; break;
87 case ZOOM_100: nZoom = 100; break;
88 case ZOOM_75: nZoom = 75; break;
89 case ZOOM_50: nZoom = 50; break;
91 case ZOOM_OPTIMAL:
92 case ZOOM_PAGE_WIDTH:
93 case ZOOM_WHOLE_PAGE: nZoom = 0; break;
98 SvxZoomStatusBarControl::SvxZoomStatusBarControl( sal_uInt16 _nSlotId,
99 sal_uInt16 _nId,
100 StatusBar& rStb ) :
102 SfxStatusBarControl( _nSlotId, _nId, rStb ),
103 nZoom( 100 ),
104 nValueSet( SvxZoomEnableFlags::ALL )
106 GetStatusBar().SetQuickHelpText(GetId(), SVX_RESSTR(RID_SVXSTR_ZOOMTOOL_HINT));
109 void SvxZoomStatusBarControl::StateChanged( sal_uInt16, SfxItemState eState,
110 const SfxPoolItem* pState )
112 if( SfxItemState::DEFAULT != eState )
114 GetStatusBar().SetItemText( GetId(), "" );
115 nValueSet = SvxZoomEnableFlags::NONE;
117 else if ( pState->ISA( SfxUInt16Item) )
119 const SfxUInt16Item* pItem = static_cast<const SfxUInt16Item*>(pState);
120 nZoom = pItem->GetValue();
122 OUString aStr(unicode::formatPercent(nZoom, Application::GetSettings().GetUILanguageTag()));
123 GetStatusBar().SetItemText( GetId(), aStr );
125 if ( pState->ISA(SvxZoomItem) )
127 nValueSet = static_cast<const SvxZoomItem*>(pState)->GetValueSet();
129 else
131 DBG_WARNING( "use SfxZoomItem for SID_ATTR_ZOOM" );
132 nValueSet = SvxZoomEnableFlags::ALL;
137 void SvxZoomStatusBarControl::Paint( const UserDrawEvent& )
139 OUString aStr(unicode::formatPercent(nZoom, Application::GetSettings().GetUILanguageTag()));
140 GetStatusBar().SetItemText( GetId(), aStr );
143 void SvxZoomStatusBarControl::Command( const CommandEvent& rCEvt )
145 if ( CommandEventId::ContextMenu == rCEvt.GetCommand() && bool(nValueSet) )
147 ZoomPopup_Impl aPop( nZoom, nValueSet );
148 StatusBar& rStatusbar = GetStatusBar();
150 if ( aPop.Execute( &rStatusbar, rCEvt.GetMousePosPixel() ) && ( nZoom != aPop.GetZoom() || !nZoom ) )
152 nZoom = aPop.GetZoom();
153 SvxZoomItem aZoom( SvxZoomType::PERCENT, nZoom, GetId() );
155 switch( aPop.GetCurId() )
157 case ZOOM_OPTIMAL: aZoom.SetType( SvxZoomType::OPTIMAL ); break;
158 case ZOOM_PAGE_WIDTH: aZoom.SetType( SvxZoomType::PAGEWIDTH ); break;
159 case ZOOM_WHOLE_PAGE: aZoom.SetType( SvxZoomType::WHOLEPAGE ); break;
162 ::com::sun::star::uno::Any a;
163 INetURLObject aObj( m_aCommandURL );
165 ::com::sun::star::uno::Sequence< ::com::sun::star::beans::PropertyValue > aArgs( 1 );
166 aArgs[0].Name = aObj.GetURLPath();
167 aZoom.QueryValue( a );
168 aArgs[0].Value = a;
170 execute( aArgs );
173 else
174 SfxStatusBarControl::Command( rCEvt );
177 SFX_IMPL_STATUSBAR_CONTROL(SvxZoomPageStatusBarControl,SfxVoidItem);
179 SvxZoomPageStatusBarControl::SvxZoomPageStatusBarControl(sal_uInt16 _nSlotId,
180 sal_uInt16 _nId, StatusBar& rStb)
181 : SfxStatusBarControl(_nSlotId, _nId, rStb)
182 , maImage(SVX_RES(RID_SVXBMP_ZOOM_PAGE))
184 GetStatusBar().SetQuickHelpText(GetId(), SVX_RESSTR(RID_SVXSTR_FIT_SLIDE));
187 void SvxZoomPageStatusBarControl::Paint(const UserDrawEvent& rUsrEvt)
189 vcl::RenderContext* pDev = rUsrEvt.GetRenderContext();
190 Rectangle aRect = rUsrEvt.GetRect();
191 Point aPt = centerImage(aRect, maImage);
192 pDev->DrawImage(aPt, maImage);
195 bool SvxZoomPageStatusBarControl::MouseButtonDown(const MouseEvent&)
197 SvxZoomItem aZoom( SvxZoomType::WHOLEPAGE, 0, GetId() );
199 ::com::sun::star::uno::Any a;
200 INetURLObject aObj( m_aCommandURL );
202 ::com::sun::star::uno::Sequence< ::com::sun::star::beans::PropertyValue > aArgs( 1 );
203 aArgs[0].Name = aObj.GetURLPath();
204 aZoom.QueryValue( a );
205 aArgs[0].Value = a;
207 execute( aArgs );
209 return true;
212 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */