Version 3.6.0.2, tag libreoffice-3.6.0.2
[LibreOffice.git] / svx / source / stbctrls / zoomctrl.cxx
blob1284075842d0b3a77dcf5d9c8cbfc59ea1751db9
1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 /*************************************************************************
4 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
6 * Copyright 2000, 2010 Oracle and/or its affiliates.
8 * OpenOffice.org - a multi-platform office productivity suite
10 * This file is part of OpenOffice.org.
12 * OpenOffice.org is free software: you can redistribute it and/or modify
13 * it under the terms of the GNU Lesser General Public License version 3
14 * only, as published by the Free Software Foundation.
16 * OpenOffice.org is distributed in the hope that it will be useful,
17 * but WITHOUT ANY WARRANTY; without even the implied warranty of
18 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
19 * GNU Lesser General Public License version 3 for more details
20 * (a copy is included in the LICENSE file that accompanied this code).
22 * You should have received a copy of the GNU Lesser General Public License
23 * version 3 along with OpenOffice.org. If not, see
24 * <http://www.openoffice.org/license.html>
25 * for a copy of the LGPLv3 License.
27 ************************************************************************/
29 #include <tools/shl.hxx>
30 #include <vcl/status.hxx>
31 #include <vcl/menu.hxx>
32 #include <sfx2/dispatch.hxx>
33 #include <tools/urlobj.hxx>
35 #include <svx/dialogs.hrc>
37 #include "svx/zoomctrl.hxx"
38 #include <svx/zoomitem.hxx>
39 #include "stbctrls.h"
40 #include <svx/dialmgr.hxx>
42 SFX_IMPL_STATUSBAR_CONTROL(SvxZoomStatusBarControl,SvxZoomItem);
44 // class ZoomPopup_Impl --------------------------------------------------
46 class ZoomPopup_Impl : public PopupMenu
48 public:
49 ZoomPopup_Impl( sal_uInt16 nZ, sal_uInt16 nValueSet );
51 sal_uInt16 GetZoom() const { return nZoom; }
52 sal_uInt16 GetCurId() const { return nCurId; }
54 private:
55 sal_uInt16 nZoom;
56 sal_uInt16 nCurId;
58 virtual void Select();
61 // -----------------------------------------------------------------------
63 ZoomPopup_Impl::ZoomPopup_Impl( sal_uInt16 nZ, sal_uInt16 nValueSet )
65 : PopupMenu( ResId( RID_SVXMNU_ZOOM, DIALOG_MGR() ) ),
67 nZoom( nZ )
69 static sal_uInt16 aTable[] =
71 SVX_ZOOM_ENABLE_50, ZOOM_50,
72 SVX_ZOOM_ENABLE_100, ZOOM_100,
73 SVX_ZOOM_ENABLE_150, ZOOM_150,
74 SVX_ZOOM_ENABLE_200, ZOOM_200,
75 SVX_ZOOM_ENABLE_OPTIMAL, ZOOM_OPTIMAL,
76 SVX_ZOOM_ENABLE_WHOLEPAGE, ZOOM_WHOLE_PAGE,
77 SVX_ZOOM_ENABLE_PAGEWIDTH, ZOOM_PAGE_WIDTH
80 for ( sal_uInt16 nPos = 0; nPos < SAL_N_ELEMENTS(aTable); nPos += 2 )
81 if ( ( aTable[nPos] != ( aTable[nPos] & nValueSet ) ) )
82 EnableItem( aTable[nPos+1], sal_False );
85 // -----------------------------------------------------------------------
87 void ZoomPopup_Impl::Select()
89 nCurId = GetCurItemId();
91 switch ( nCurId )
93 case ZOOM_200: nZoom = 200; break;
94 case ZOOM_150: nZoom = 150; break;
95 case ZOOM_100: nZoom = 100; break;
96 case ZOOM_75: nZoom = 75; break;
97 case ZOOM_50: nZoom = 50; break;
99 case ZOOM_OPTIMAL:
100 case ZOOM_PAGE_WIDTH:
101 case ZOOM_WHOLE_PAGE: nZoom = 0; break;
106 // class SvxZoomStatusBarControl ------------------------------------------
108 SvxZoomStatusBarControl::SvxZoomStatusBarControl( sal_uInt16 _nSlotId,
109 sal_uInt16 _nId,
110 StatusBar& rStb ) :
112 SfxStatusBarControl( _nSlotId, _nId, rStb ),
113 nZoom( 100 ),
114 nValueSet( SVX_ZOOM_ENABLE_ALL )
118 // -----------------------------------------------------------------------
120 void SvxZoomStatusBarControl::StateChanged( sal_uInt16, SfxItemState eState,
121 const SfxPoolItem* pState )
123 if( SFX_ITEM_AVAILABLE != eState )
125 GetStatusBar().SetItemText( GetId(), String() );
126 nValueSet = 0;
128 else if ( pState->ISA( SfxUInt16Item) )
130 const SfxUInt16Item* pItem = (const SfxUInt16Item*)pState;
131 nZoom = pItem->GetValue();
132 String aStr( String::CreateFromInt32(nZoom) );
133 aStr += '%';
134 GetStatusBar().SetItemText( GetId(), aStr );
136 if ( pState->ISA(SvxZoomItem) )
138 nValueSet = ((const SvxZoomItem*)pState)->GetValueSet();
140 else
142 DBG_WARNING( "use SfxZoomItem for SID_ATTR_ZOOM" );
143 nValueSet = SVX_ZOOM_ENABLE_ALL;
148 // -----------------------------------------------------------------------
150 void SvxZoomStatusBarControl::Paint( const UserDrawEvent& )
152 String aStr( String::CreateFromInt32( nZoom ));
153 aStr += '%';
154 GetStatusBar().SetItemText( GetId(), aStr );
157 // -----------------------------------------------------------------------
159 void SvxZoomStatusBarControl::Command( const CommandEvent& rCEvt )
161 if ( COMMAND_CONTEXTMENU & rCEvt.GetCommand() && 0 != nValueSet )
163 CaptureMouse();
164 ZoomPopup_Impl aPop( nZoom, nValueSet );
165 StatusBar& rStatusbar = GetStatusBar();
167 if ( aPop.Execute( &rStatusbar, rCEvt.GetMousePosPixel() ) && ( nZoom != aPop.GetZoom() || !nZoom ) )
169 nZoom = aPop.GetZoom();
170 SvxZoomItem aZoom( SVX_ZOOM_PERCENT, nZoom, GetId() );
172 switch( aPop.GetCurId() )
174 case ZOOM_OPTIMAL: aZoom.SetType( SVX_ZOOM_OPTIMAL ); break;
175 case ZOOM_PAGE_WIDTH: aZoom.SetType( SVX_ZOOM_PAGEWIDTH ); break;
176 case ZOOM_WHOLE_PAGE: aZoom.SetType( SVX_ZOOM_WHOLEPAGE ); break;
179 ::com::sun::star::uno::Any a;
180 INetURLObject aObj( m_aCommandURL );
182 ::com::sun::star::uno::Sequence< ::com::sun::star::beans::PropertyValue > aArgs( 1 );
183 aArgs[0].Name = aObj.GetURLPath();
184 aZoom.QueryValue( a );
185 aArgs[0].Value = a;
187 execute( aArgs );
189 ReleaseMouse();
191 else
192 SfxStatusBarControl::Command( rCEvt );
196 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */