LCOV - code coverage report
Current view: top level - svx/source/stbctrls - zoomctrl.cxx (source / functions) Hit Total Coverage
Test: commit c8344322a7af75b84dd3ca8f78b05543a976dfd5 Lines: 27 96 28.1 %
Date: 2015-06-13 12:38:46 Functions: 8 17 47.1 %
Legend: Lines: hit not hit

          Line data    Source code
       1             : /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
       2             : /*
       3             :  * This file is part of the LibreOffice project.
       4             :  *
       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/.
       8             :  *
       9             :  * This file incorporates work covered by the following license notice:
      10             :  *
      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 .
      18             :  */
      19             : 
      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>
      27             : 
      28             : #include <svx/dialogs.hrc>
      29             : 
      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"
      36             : 
      37         329 : SFX_IMPL_STATUSBAR_CONTROL(SvxZoomStatusBarControl,SvxZoomItem);
      38             : 
      39           0 : class ZoomPopup_Impl : public PopupMenu
      40             : {
      41             : public:
      42             :     ZoomPopup_Impl( sal_uInt16 nZ, SvxZoomEnableFlags nValueSet );
      43             : 
      44           0 :     sal_uInt16          GetZoom() const { return nZoom; }
      45           0 :     sal_uInt16          GetCurId() const { return nCurId; }
      46             : 
      47             : private:
      48             :     sal_uInt16          nZoom;
      49             :     sal_uInt16          nCurId;
      50             : 
      51             :     virtual void    Select() SAL_OVERRIDE;
      52             : };
      53             : 
      54             : 
      55             : 
      56           0 : ZoomPopup_Impl::ZoomPopup_Impl( sal_uInt16 nZ, SvxZoomEnableFlags nValueSet )
      57           0 :     : PopupMenu(ResId(RID_SVXMNU_ZOOM, DIALOG_MGR()))
      58             :     , nZoom(nZ)
      59           0 :     , nCurId(0)
      60             : {
      61           0 :     if ( !(SvxZoomEnableFlags::N50 & nValueSet) )
      62           0 :             EnableItem( ZOOM_50, false );
      63           0 :     if ( !(SvxZoomEnableFlags::N100 & nValueSet) )
      64           0 :             EnableItem( ZOOM_100, false );
      65           0 :     if ( !(SvxZoomEnableFlags::N150 & nValueSet) )
      66           0 :             EnableItem( ZOOM_150, false );
      67           0 :     if ( !(SvxZoomEnableFlags::N200 & nValueSet) )
      68           0 :             EnableItem( ZOOM_200, false );
      69           0 :     if ( !(SvxZoomEnableFlags::OPTIMAL & nValueSet) )
      70           0 :             EnableItem( ZOOM_OPTIMAL, false );
      71           0 :     if ( !(SvxZoomEnableFlags::WHOLEPAGE & nValueSet) )
      72           0 :             EnableItem( ZOOM_WHOLE_PAGE, false );
      73           0 :     if ( !(SvxZoomEnableFlags::PAGEWIDTH & nValueSet) )
      74           0 :             EnableItem( ZOOM_PAGE_WIDTH, false );
      75           0 : }
      76             : 
      77             : 
      78             : 
      79           0 : void ZoomPopup_Impl::Select()
      80             : {
      81           0 :     nCurId = GetCurItemId();
      82             : 
      83           0 :     switch ( nCurId )
      84             :     {
      85           0 :         case ZOOM_200:          nZoom = 200; break;
      86           0 :         case ZOOM_150:          nZoom = 150; break;
      87           0 :         case ZOOM_100:          nZoom = 100; break;
      88           0 :         case ZOOM_75:           nZoom =  75; break;
      89           0 :         case ZOOM_50:           nZoom =  50; break;
      90             : 
      91             :         case ZOOM_OPTIMAL:
      92             :         case ZOOM_PAGE_WIDTH:
      93           0 :         case ZOOM_WHOLE_PAGE:   nZoom = 0; break;
      94             : 
      95             :     }
      96           0 : }
      97             : 
      98         588 : SvxZoomStatusBarControl::SvxZoomStatusBarControl( sal_uInt16 _nSlotId,
      99             :                                                   sal_uInt16 _nId,
     100             :                                                   StatusBar& rStb ) :
     101             : 
     102             :     SfxStatusBarControl( _nSlotId, _nId, rStb ),
     103             :     nZoom( 100 ),
     104         588 :     nValueSet( SvxZoomEnableFlags::ALL )
     105             : {
     106         588 :     GetStatusBar().SetQuickHelpText(GetId(), SVX_RESSTR(RID_SVXSTR_ZOOMTOOL_HINT));
     107         588 : }
     108             : 
     109        1003 : void SvxZoomStatusBarControl::StateChanged( sal_uInt16, SfxItemState eState,
     110             :                                             const SfxPoolItem* pState )
     111             : {
     112        1003 :     if( SfxItemState::DEFAULT != eState )
     113             :     {
     114           0 :         GetStatusBar().SetItemText( GetId(), "" );
     115           0 :         nValueSet = SvxZoomEnableFlags::NONE;
     116             :     }
     117        1003 :     else if ( pState->ISA( SfxUInt16Item) )
     118             :     {
     119        1003 :         const SfxUInt16Item* pItem = static_cast<const SfxUInt16Item*>(pState);
     120        1003 :         nZoom = pItem->GetValue();
     121             : 
     122        1003 :         OUString aStr(unicode::formatPercent(nZoom, Application::GetSettings().GetUILanguageTag()));
     123        1003 :         GetStatusBar().SetItemText( GetId(), aStr );
     124             : 
     125        1003 :         if ( pState->ISA(SvxZoomItem) )
     126             :         {
     127        1003 :             nValueSet = static_cast<const SvxZoomItem*>(pState)->GetValueSet();
     128             :         }
     129             :         else
     130             :         {
     131             :             DBG_WARNING( "use SfxZoomItem for SID_ATTR_ZOOM" );
     132           0 :             nValueSet = SvxZoomEnableFlags::ALL;
     133        1003 :         }
     134             :     }
     135        1003 : }
     136             : 
     137           0 : void SvxZoomStatusBarControl::Paint( const UserDrawEvent& )
     138             : {
     139           0 :     OUString aStr(unicode::formatPercent(nZoom, Application::GetSettings().GetUILanguageTag()));
     140           0 :     GetStatusBar().SetItemText( GetId(), aStr );
     141           0 : }
     142             : 
     143           0 : void SvxZoomStatusBarControl::Command( const CommandEvent& rCEvt )
     144             : {
     145           0 :     if ( CommandEventId::ContextMenu == rCEvt.GetCommand() && bool(nValueSet) )
     146             :     {
     147           0 :         ZoomPopup_Impl aPop( nZoom, nValueSet );
     148           0 :         StatusBar& rStatusbar = GetStatusBar();
     149             : 
     150           0 :         if ( aPop.Execute( &rStatusbar, rCEvt.GetMousePosPixel() ) && ( nZoom != aPop.GetZoom() || !nZoom ) )
     151             :         {
     152           0 :             nZoom = aPop.GetZoom();
     153           0 :             SvxZoomItem aZoom( SvxZoomType::PERCENT, nZoom, GetId() );
     154             : 
     155           0 :             switch( aPop.GetCurId() )
     156             :             {
     157           0 :             case ZOOM_OPTIMAL:      aZoom.SetType( SvxZoomType::OPTIMAL ); break;
     158           0 :             case ZOOM_PAGE_WIDTH:   aZoom.SetType( SvxZoomType::PAGEWIDTH ); break;
     159           0 :             case ZOOM_WHOLE_PAGE:   aZoom.SetType( SvxZoomType::WHOLEPAGE ); break;
     160             :             }
     161             : 
     162           0 :             ::com::sun::star::uno::Any a;
     163           0 :             INetURLObject aObj( m_aCommandURL );
     164             : 
     165           0 :             ::com::sun::star::uno::Sequence< ::com::sun::star::beans::PropertyValue > aArgs( 1 );
     166           0 :             aArgs[0].Name  = aObj.GetURLPath();
     167           0 :             aZoom.QueryValue( a );
     168           0 :             aArgs[0].Value = a;
     169             : 
     170           0 :             execute( aArgs );
     171           0 :         }
     172             :     }
     173             :     else
     174           0 :         SfxStatusBarControl::Command( rCEvt );
     175           0 : }
     176             : 
     177          84 : SFX_IMPL_STATUSBAR_CONTROL(SvxZoomPageStatusBarControl,SfxVoidItem);
     178             : 
     179          63 : SvxZoomPageStatusBarControl::SvxZoomPageStatusBarControl(sal_uInt16 _nSlotId,
     180             :     sal_uInt16 _nId, StatusBar& rStb)
     181             :     : SfxStatusBarControl(_nSlotId, _nId, rStb)
     182          63 :     , maImage(SVX_RES(RID_SVXBMP_ZOOM_PAGE))
     183             : {
     184          63 :     GetStatusBar().SetQuickHelpText(GetId(), SVX_RESSTR(RID_SVXSTR_FIT_SLIDE));
     185          63 : }
     186             : 
     187         243 : void SvxZoomPageStatusBarControl::Paint(const UserDrawEvent& rUsrEvt)
     188             : {
     189         243 :     OutputDevice* pDev = rUsrEvt.GetDevice();
     190         243 :     Rectangle aRect = rUsrEvt.GetRect();
     191         243 :     Point aPt = centerImage(aRect, maImage);
     192         243 :     pDev->DrawImage(aPt, maImage);
     193         243 : }
     194             : 
     195           0 : bool SvxZoomPageStatusBarControl::MouseButtonDown(const MouseEvent&)
     196             : {
     197           0 :     SvxZoomItem aZoom( SvxZoomType::WHOLEPAGE, 0, GetId() );
     198             : 
     199           0 :     ::com::sun::star::uno::Any a;
     200           0 :     INetURLObject aObj( m_aCommandURL );
     201             : 
     202           0 :     ::com::sun::star::uno::Sequence< ::com::sun::star::beans::PropertyValue > aArgs( 1 );
     203           0 :     aArgs[0].Name  = aObj.GetURLPath();
     204           0 :     aZoom.QueryValue( a );
     205           0 :     aArgs[0].Value = a;
     206             : 
     207           0 :     execute( aArgs );
     208             : 
     209           0 :     return true;
     210             : }
     211             : 
     212             : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */

Generated by: LCOV version 1.11