1*cdf0e10cSrcweir /************************************************************************* 2*cdf0e10cSrcweir * 3*cdf0e10cSrcweir * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. 4*cdf0e10cSrcweir * 5*cdf0e10cSrcweir * Copyright 2000, 2010 Oracle and/or its affiliates. 6*cdf0e10cSrcweir * 7*cdf0e10cSrcweir * OpenOffice.org - a multi-platform office productivity suite 8*cdf0e10cSrcweir * 9*cdf0e10cSrcweir * This file is part of OpenOffice.org. 10*cdf0e10cSrcweir * 11*cdf0e10cSrcweir * OpenOffice.org is free software: you can redistribute it and/or modify 12*cdf0e10cSrcweir * it under the terms of the GNU Lesser General Public License version 3 13*cdf0e10cSrcweir * only, as published by the Free Software Foundation. 14*cdf0e10cSrcweir * 15*cdf0e10cSrcweir * OpenOffice.org is distributed in the hope that it will be useful, 16*cdf0e10cSrcweir * but WITHOUT ANY WARRANTY; without even the implied warranty of 17*cdf0e10cSrcweir * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 18*cdf0e10cSrcweir * GNU Lesser General Public License version 3 for more details 19*cdf0e10cSrcweir * (a copy is included in the LICENSE file that accompanied this code). 20*cdf0e10cSrcweir * 21*cdf0e10cSrcweir * You should have received a copy of the GNU Lesser General Public License 22*cdf0e10cSrcweir * version 3 along with OpenOffice.org. If not, see 23*cdf0e10cSrcweir * <http://www.openoffice.org/license.html> 24*cdf0e10cSrcweir * for a copy of the LGPLv3 License. 25*cdf0e10cSrcweir * 26*cdf0e10cSrcweir ************************************************************************/ 27*cdf0e10cSrcweir 28*cdf0e10cSrcweir // MARKER(update_precomp.py): autogen include statement, do not remove 29*cdf0e10cSrcweir #include "precompiled_svx.hxx" 30*cdf0e10cSrcweir #include <tools/shl.hxx> 31*cdf0e10cSrcweir #ifndef _STATUS_HXX //autogen 32*cdf0e10cSrcweir #include <vcl/status.hxx> 33*cdf0e10cSrcweir #endif 34*cdf0e10cSrcweir #ifndef _MENU_HXX //autogen 35*cdf0e10cSrcweir #include <vcl/menu.hxx> 36*cdf0e10cSrcweir #endif 37*cdf0e10cSrcweir #include <sfx2/dispatch.hxx> 38*cdf0e10cSrcweir #include <tools/urlobj.hxx> 39*cdf0e10cSrcweir 40*cdf0e10cSrcweir #include <svx/dialogs.hrc> 41*cdf0e10cSrcweir 42*cdf0e10cSrcweir #include "svx/zoomctrl.hxx" 43*cdf0e10cSrcweir //CHINA001 #include "zoom.hxx" 44*cdf0e10cSrcweir #include <svx/zoomitem.hxx> 45*cdf0e10cSrcweir #include "stbctrls.h" 46*cdf0e10cSrcweir #include <svx/dialmgr.hxx> 47*cdf0e10cSrcweir 48*cdf0e10cSrcweir SFX_IMPL_STATUSBAR_CONTROL(SvxZoomStatusBarControl,SvxZoomItem); 49*cdf0e10cSrcweir 50*cdf0e10cSrcweir // class ZoomPopup_Impl -------------------------------------------------- 51*cdf0e10cSrcweir 52*cdf0e10cSrcweir class ZoomPopup_Impl : public PopupMenu 53*cdf0e10cSrcweir { 54*cdf0e10cSrcweir public: 55*cdf0e10cSrcweir ZoomPopup_Impl( sal_uInt16 nZ, sal_uInt16 nValueSet ); 56*cdf0e10cSrcweir 57*cdf0e10cSrcweir sal_uInt16 GetZoom() const { return nZoom; } 58*cdf0e10cSrcweir sal_uInt16 GetCurId() const { return nCurId; } 59*cdf0e10cSrcweir 60*cdf0e10cSrcweir private: 61*cdf0e10cSrcweir sal_uInt16 nZoom; 62*cdf0e10cSrcweir sal_uInt16 nCurId; 63*cdf0e10cSrcweir 64*cdf0e10cSrcweir virtual void Select(); 65*cdf0e10cSrcweir }; 66*cdf0e10cSrcweir 67*cdf0e10cSrcweir // ----------------------------------------------------------------------- 68*cdf0e10cSrcweir 69*cdf0e10cSrcweir ZoomPopup_Impl::ZoomPopup_Impl( sal_uInt16 nZ, sal_uInt16 nValueSet ) 70*cdf0e10cSrcweir 71*cdf0e10cSrcweir : PopupMenu( ResId( RID_SVXMNU_ZOOM, DIALOG_MGR() ) ), 72*cdf0e10cSrcweir 73*cdf0e10cSrcweir nZoom( nZ ) 74*cdf0e10cSrcweir { 75*cdf0e10cSrcweir static sal_uInt16 aTable[] = 76*cdf0e10cSrcweir { 77*cdf0e10cSrcweir SVX_ZOOM_ENABLE_50, ZOOM_50, 78*cdf0e10cSrcweir SVX_ZOOM_ENABLE_100, ZOOM_100, 79*cdf0e10cSrcweir SVX_ZOOM_ENABLE_150, ZOOM_150, 80*cdf0e10cSrcweir SVX_ZOOM_ENABLE_200, ZOOM_200, 81*cdf0e10cSrcweir SVX_ZOOM_ENABLE_OPTIMAL, ZOOM_OPTIMAL, 82*cdf0e10cSrcweir SVX_ZOOM_ENABLE_WHOLEPAGE, ZOOM_WHOLE_PAGE, 83*cdf0e10cSrcweir SVX_ZOOM_ENABLE_PAGEWIDTH, ZOOM_PAGE_WIDTH 84*cdf0e10cSrcweir }; 85*cdf0e10cSrcweir 86*cdf0e10cSrcweir for ( sal_uInt16 nPos = 0; nPos < sizeof(aTable) / sizeof(sal_uInt16); nPos += 2 ) 87*cdf0e10cSrcweir if ( ( aTable[nPos] != ( aTable[nPos] & nValueSet ) ) ) 88*cdf0e10cSrcweir EnableItem( aTable[nPos+1], sal_False ); 89*cdf0e10cSrcweir } 90*cdf0e10cSrcweir 91*cdf0e10cSrcweir // ----------------------------------------------------------------------- 92*cdf0e10cSrcweir 93*cdf0e10cSrcweir void ZoomPopup_Impl::Select() 94*cdf0e10cSrcweir { 95*cdf0e10cSrcweir nCurId = GetCurItemId(); 96*cdf0e10cSrcweir 97*cdf0e10cSrcweir switch ( nCurId ) 98*cdf0e10cSrcweir { 99*cdf0e10cSrcweir case ZOOM_200: nZoom = 200; break; 100*cdf0e10cSrcweir case ZOOM_150: nZoom = 150; break; 101*cdf0e10cSrcweir case ZOOM_100: nZoom = 100; break; 102*cdf0e10cSrcweir case ZOOM_75: nZoom = 75; break; 103*cdf0e10cSrcweir case ZOOM_50: nZoom = 50; break; 104*cdf0e10cSrcweir 105*cdf0e10cSrcweir case ZOOM_OPTIMAL: 106*cdf0e10cSrcweir case ZOOM_PAGE_WIDTH: 107*cdf0e10cSrcweir case ZOOM_WHOLE_PAGE: nZoom = 0; break; 108*cdf0e10cSrcweir 109*cdf0e10cSrcweir } 110*cdf0e10cSrcweir } 111*cdf0e10cSrcweir 112*cdf0e10cSrcweir // class SvxZoomStatusBarControl ------------------------------------------ 113*cdf0e10cSrcweir 114*cdf0e10cSrcweir SvxZoomStatusBarControl::SvxZoomStatusBarControl( sal_uInt16 _nSlotId, 115*cdf0e10cSrcweir sal_uInt16 _nId, 116*cdf0e10cSrcweir StatusBar& rStb ) : 117*cdf0e10cSrcweir 118*cdf0e10cSrcweir SfxStatusBarControl( _nSlotId, _nId, rStb ), 119*cdf0e10cSrcweir nZoom( 100 ), 120*cdf0e10cSrcweir nValueSet( SVX_ZOOM_ENABLE_ALL ) 121*cdf0e10cSrcweir { 122*cdf0e10cSrcweir } 123*cdf0e10cSrcweir 124*cdf0e10cSrcweir // ----------------------------------------------------------------------- 125*cdf0e10cSrcweir 126*cdf0e10cSrcweir void SvxZoomStatusBarControl::StateChanged( sal_uInt16, SfxItemState eState, 127*cdf0e10cSrcweir const SfxPoolItem* pState ) 128*cdf0e10cSrcweir { 129*cdf0e10cSrcweir if( SFX_ITEM_AVAILABLE != eState ) 130*cdf0e10cSrcweir { 131*cdf0e10cSrcweir GetStatusBar().SetItemText( GetId(), String() ); 132*cdf0e10cSrcweir nValueSet = 0; 133*cdf0e10cSrcweir } 134*cdf0e10cSrcweir else if ( pState->ISA( SfxUInt16Item) ) 135*cdf0e10cSrcweir { 136*cdf0e10cSrcweir const SfxUInt16Item* pItem = (const SfxUInt16Item*)pState; 137*cdf0e10cSrcweir nZoom = pItem->GetValue(); 138*cdf0e10cSrcweir String aStr( String::CreateFromInt32(nZoom) ); 139*cdf0e10cSrcweir aStr += '%'; 140*cdf0e10cSrcweir GetStatusBar().SetItemText( GetId(), aStr ); 141*cdf0e10cSrcweir 142*cdf0e10cSrcweir if ( pState->ISA(SvxZoomItem) ) 143*cdf0e10cSrcweir { 144*cdf0e10cSrcweir nValueSet = ((const SvxZoomItem*)pState)->GetValueSet(); 145*cdf0e10cSrcweir /*!!! 146*cdf0e10cSrcweir SvxZoomType eType = ((const SvxZoomItem*)pState)->GetType(); 147*cdf0e10cSrcweir 148*cdf0e10cSrcweir switch ( eType ) 149*cdf0e10cSrcweir { 150*cdf0e10cSrcweir case SVX_ZOOM_OPTIMAL: 151*cdf0e10cSrcweir GetStatusBar().SetItemText( GetId(), "Opt." ); 152*cdf0e10cSrcweir break; 153*cdf0e10cSrcweir case SVX_ZOOM_WHOLEPAGE: 154*cdf0e10cSrcweir GetStatusBar().SetItemText( GetId(), "Page" ); 155*cdf0e10cSrcweir break; 156*cdf0e10cSrcweir case SVX_ZOOM_PAGEWIDTH: 157*cdf0e10cSrcweir GetStatusBar().SetItemText( GetId(), "Width" ); 158*cdf0e10cSrcweir break; 159*cdf0e10cSrcweir } 160*cdf0e10cSrcweir */ 161*cdf0e10cSrcweir } 162*cdf0e10cSrcweir else 163*cdf0e10cSrcweir { 164*cdf0e10cSrcweir DBG_WARNING( "use SfxZoomItem for SID_ATTR_ZOOM" ); 165*cdf0e10cSrcweir nValueSet = SVX_ZOOM_ENABLE_ALL; 166*cdf0e10cSrcweir } 167*cdf0e10cSrcweir } 168*cdf0e10cSrcweir } 169*cdf0e10cSrcweir 170*cdf0e10cSrcweir // ----------------------------------------------------------------------- 171*cdf0e10cSrcweir 172*cdf0e10cSrcweir void SvxZoomStatusBarControl::Paint( const UserDrawEvent& ) 173*cdf0e10cSrcweir { 174*cdf0e10cSrcweir String aStr( String::CreateFromInt32( nZoom )); 175*cdf0e10cSrcweir aStr += '%'; 176*cdf0e10cSrcweir GetStatusBar().SetItemText( GetId(), aStr ); 177*cdf0e10cSrcweir } 178*cdf0e10cSrcweir 179*cdf0e10cSrcweir // ----------------------------------------------------------------------- 180*cdf0e10cSrcweir 181*cdf0e10cSrcweir void SvxZoomStatusBarControl::Command( const CommandEvent& rCEvt ) 182*cdf0e10cSrcweir { 183*cdf0e10cSrcweir if ( COMMAND_CONTEXTMENU & rCEvt.GetCommand() && 0 != nValueSet ) 184*cdf0e10cSrcweir { 185*cdf0e10cSrcweir CaptureMouse(); 186*cdf0e10cSrcweir ZoomPopup_Impl aPop( nZoom, nValueSet ); 187*cdf0e10cSrcweir StatusBar& rStatusbar = GetStatusBar(); 188*cdf0e10cSrcweir 189*cdf0e10cSrcweir if ( aPop.Execute( &rStatusbar, rCEvt.GetMousePosPixel() ) && ( nZoom != aPop.GetZoom() || !nZoom ) ) 190*cdf0e10cSrcweir { 191*cdf0e10cSrcweir nZoom = aPop.GetZoom(); 192*cdf0e10cSrcweir SvxZoomItem aZoom( SVX_ZOOM_PERCENT, nZoom, GetId() ); 193*cdf0e10cSrcweir 194*cdf0e10cSrcweir switch( aPop.GetCurId() ) 195*cdf0e10cSrcweir { 196*cdf0e10cSrcweir case ZOOM_OPTIMAL: aZoom.SetType( SVX_ZOOM_OPTIMAL ); break; 197*cdf0e10cSrcweir case ZOOM_PAGE_WIDTH: aZoom.SetType( SVX_ZOOM_PAGEWIDTH ); break; 198*cdf0e10cSrcweir case ZOOM_WHOLE_PAGE: aZoom.SetType( SVX_ZOOM_WHOLEPAGE ); break; 199*cdf0e10cSrcweir } 200*cdf0e10cSrcweir 201*cdf0e10cSrcweir ::com::sun::star::uno::Any a; 202*cdf0e10cSrcweir INetURLObject aObj( m_aCommandURL ); 203*cdf0e10cSrcweir 204*cdf0e10cSrcweir ::com::sun::star::uno::Sequence< ::com::sun::star::beans::PropertyValue > aArgs( 1 ); 205*cdf0e10cSrcweir aArgs[0].Name = aObj.GetURLPath(); 206*cdf0e10cSrcweir aZoom.QueryValue( a ); 207*cdf0e10cSrcweir aArgs[0].Value = a; 208*cdf0e10cSrcweir 209*cdf0e10cSrcweir execute( aArgs ); 210*cdf0e10cSrcweir } 211*cdf0e10cSrcweir ReleaseMouse(); 212*cdf0e10cSrcweir } 213*cdf0e10cSrcweir else 214*cdf0e10cSrcweir SfxStatusBarControl::Command( rCEvt ); 215*cdf0e10cSrcweir } 216*cdf0e10cSrcweir 217*cdf0e10cSrcweir sal_uIntPtr SvxZoomStatusBarControl::GetDefItemWidth(const StatusBar& rStb) 218*cdf0e10cSrcweir { 219*cdf0e10cSrcweir long nWidth1 = rStb.GetTextWidth(String::CreateFromAscii("XXXXX%")); 220*cdf0e10cSrcweir return nWidth1; 221*cdf0e10cSrcweir } 222*cdf0e10cSrcweir 223*cdf0e10cSrcweir 224