bump product version to 4.1.6.2
[LibreOffice.git] / svx / source / stbctrls / zoomctrl.cxx
blob8ad0c2ef143520b903906d9b31b860d44d90cc23
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 <tools/shl.hxx>
21 #include <vcl/status.hxx>
22 #include <vcl/menu.hxx>
23 #include <sfx2/dispatch.hxx>
24 #include <tools/urlobj.hxx>
26 #include <svx/dialogs.hrc>
28 #include "svx/zoomctrl.hxx"
29 #include <sfx2/zoomitem.hxx>
30 #include "stbctrls.h"
31 #include <svx/dialmgr.hxx>
33 SFX_IMPL_STATUSBAR_CONTROL(SvxZoomStatusBarControl,SvxZoomItem);
35 // class ZoomPopup_Impl --------------------------------------------------
37 class ZoomPopup_Impl : public PopupMenu
39 public:
40 ZoomPopup_Impl( sal_uInt16 nZ, sal_uInt16 nValueSet );
42 sal_uInt16 GetZoom() const { return nZoom; }
43 sal_uInt16 GetCurId() const { return nCurId; }
45 private:
46 sal_uInt16 nZoom;
47 sal_uInt16 nCurId;
49 virtual void Select();
52 // -----------------------------------------------------------------------
54 ZoomPopup_Impl::ZoomPopup_Impl( sal_uInt16 nZ, sal_uInt16 nValueSet )
56 : PopupMenu( ResId( RID_SVXMNU_ZOOM, DIALOG_MGR() ) ),
58 nZoom( nZ )
60 static sal_uInt16 aTable[] =
62 SVX_ZOOM_ENABLE_50, ZOOM_50,
63 SVX_ZOOM_ENABLE_100, ZOOM_100,
64 SVX_ZOOM_ENABLE_150, ZOOM_150,
65 SVX_ZOOM_ENABLE_200, ZOOM_200,
66 SVX_ZOOM_ENABLE_OPTIMAL, ZOOM_OPTIMAL,
67 SVX_ZOOM_ENABLE_WHOLEPAGE, ZOOM_WHOLE_PAGE,
68 SVX_ZOOM_ENABLE_PAGEWIDTH, ZOOM_PAGE_WIDTH
71 for ( sal_uInt16 nPos = 0; nPos < SAL_N_ELEMENTS(aTable); nPos += 2 )
72 if ( ( aTable[nPos] != ( aTable[nPos] & nValueSet ) ) )
73 EnableItem( aTable[nPos+1], sal_False );
76 // -----------------------------------------------------------------------
78 void ZoomPopup_Impl::Select()
80 nCurId = GetCurItemId();
82 switch ( nCurId )
84 case ZOOM_200: nZoom = 200; break;
85 case ZOOM_150: nZoom = 150; break;
86 case ZOOM_100: nZoom = 100; break;
87 case ZOOM_75: nZoom = 75; break;
88 case ZOOM_50: nZoom = 50; break;
90 case ZOOM_OPTIMAL:
91 case ZOOM_PAGE_WIDTH:
92 case ZOOM_WHOLE_PAGE: nZoom = 0; break;
97 // class SvxZoomStatusBarControl ------------------------------------------
99 SvxZoomStatusBarControl::SvxZoomStatusBarControl( sal_uInt16 _nSlotId,
100 sal_uInt16 _nId,
101 StatusBar& rStb ) :
103 SfxStatusBarControl( _nSlotId, _nId, rStb ),
104 nZoom( 100 ),
105 nValueSet( SVX_ZOOM_ENABLE_ALL )
109 // -----------------------------------------------------------------------
111 void SvxZoomStatusBarControl::StateChanged( sal_uInt16, SfxItemState eState,
112 const SfxPoolItem* pState )
114 if( SFX_ITEM_AVAILABLE != eState )
116 GetStatusBar().SetItemText( GetId(), String() );
117 nValueSet = 0;
119 else if ( pState->ISA( SfxUInt16Item) )
121 const SfxUInt16Item* pItem = (const SfxUInt16Item*)pState;
122 nZoom = pItem->GetValue();
123 String aStr( OUString::number(nZoom) );
124 aStr += '%';
125 GetStatusBar().SetItemText( GetId(), aStr );
127 if ( pState->ISA(SvxZoomItem) )
129 nValueSet = ((const SvxZoomItem*)pState)->GetValueSet();
131 else
133 DBG_WARNING( "use SfxZoomItem for SID_ATTR_ZOOM" );
134 nValueSet = SVX_ZOOM_ENABLE_ALL;
139 // -----------------------------------------------------------------------
141 void SvxZoomStatusBarControl::Paint( const UserDrawEvent& )
143 String aStr( OUString::number( nZoom ));
144 aStr += '%';
145 GetStatusBar().SetItemText( GetId(), aStr );
148 // -----------------------------------------------------------------------
150 void SvxZoomStatusBarControl::Command( const CommandEvent& rCEvt )
152 if ( COMMAND_CONTEXTMENU & rCEvt.GetCommand() && 0 != nValueSet )
154 CaptureMouse();
155 ZoomPopup_Impl aPop( nZoom, nValueSet );
156 StatusBar& rStatusbar = GetStatusBar();
158 if ( aPop.Execute( &rStatusbar, rCEvt.GetMousePosPixel() ) && ( nZoom != aPop.GetZoom() || !nZoom ) )
160 nZoom = aPop.GetZoom();
161 SvxZoomItem aZoom( SVX_ZOOM_PERCENT, nZoom, GetId() );
163 switch( aPop.GetCurId() )
165 case ZOOM_OPTIMAL: aZoom.SetType( SVX_ZOOM_OPTIMAL ); break;
166 case ZOOM_PAGE_WIDTH: aZoom.SetType( SVX_ZOOM_PAGEWIDTH ); break;
167 case ZOOM_WHOLE_PAGE: aZoom.SetType( SVX_ZOOM_WHOLEPAGE ); break;
170 ::com::sun::star::uno::Any a;
171 INetURLObject aObj( m_aCommandURL );
173 ::com::sun::star::uno::Sequence< ::com::sun::star::beans::PropertyValue > aArgs( 1 );
174 aArgs[0].Name = aObj.GetURLPath();
175 aZoom.QueryValue( a );
176 aArgs[0].Value = a;
178 execute( aArgs );
180 ReleaseMouse();
182 else
183 SfxStatusBarControl::Command( rCEvt );
187 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */