LCOV - code coverage report
Current view: top level - svx/source/stbctrls - zoomctrl.cxx (source / functions) Hit Total Coverage
Test: commit 10e77ab3ff6f4314137acd6e2702a6e5c1ce1fae Lines: 27 86 31.4 %
Date: 2014-11-03 Functions: 10 19 52.6 %
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         746 : SFX_IMPL_STATUSBAR_CONTROL(SvxZoomStatusBarControl,SvxZoomItem);
      38             : 
      39           0 : class ZoomPopup_Impl : public PopupMenu
      40             : {
      41             : public:
      42             :     ZoomPopup_Impl( sal_uInt16 nZ, sal_uInt16 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, sal_uInt16 nValueSet )
      57           0 :     : PopupMenu(ResId(RID_SVXMNU_ZOOM, DIALOG_MGR()))
      58             :     , nZoom(nZ)
      59           0 :     , nCurId(0)
      60             : {
      61             :     static const sal_uInt16 aTable[] =
      62             :     {
      63             :         SVX_ZOOM_ENABLE_50,         ZOOM_50,
      64             :         SVX_ZOOM_ENABLE_100,        ZOOM_100,
      65             :         SVX_ZOOM_ENABLE_150,        ZOOM_150,
      66             :         SVX_ZOOM_ENABLE_200,        ZOOM_200,
      67             :         SVX_ZOOM_ENABLE_OPTIMAL,    ZOOM_OPTIMAL,
      68             :         SVX_ZOOM_ENABLE_WHOLEPAGE,  ZOOM_WHOLE_PAGE,
      69             :         SVX_ZOOM_ENABLE_PAGEWIDTH,  ZOOM_PAGE_WIDTH
      70             :     };
      71             : 
      72           0 :     for ( sal_uInt16 nPos = 0; nPos < SAL_N_ELEMENTS(aTable); nPos += 2 )
      73           0 :         if ( ( aTable[nPos] != ( aTable[nPos] & nValueSet ) ) )
      74           0 :             EnableItem( aTable[nPos+1], 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        1464 : SvxZoomStatusBarControl::SvxZoomStatusBarControl( sal_uInt16 _nSlotId,
      99             :                                                   sal_uInt16 _nId,
     100             :                                                   StatusBar& rStb ) :
     101             : 
     102             :     SfxStatusBarControl( _nSlotId, _nId, rStb ),
     103             :     nZoom( 100 ),
     104        1464 :     nValueSet( SVX_ZOOM_ENABLE_ALL )
     105             : {
     106        1464 : }
     107             : 
     108        1684 : void SvxZoomStatusBarControl::StateChanged( sal_uInt16, SfxItemState eState,
     109             :                                             const SfxPoolItem* pState )
     110             : {
     111        1684 :     if( SfxItemState::DEFAULT != eState )
     112             :     {
     113           0 :         GetStatusBar().SetItemText( GetId(), "" );
     114           0 :         nValueSet = 0;
     115             :     }
     116        1684 :     else if ( pState->ISA( SfxUInt16Item) )
     117             :     {
     118        1684 :         const SfxUInt16Item* pItem = static_cast<const SfxUInt16Item*>(pState);
     119        1684 :         nZoom = pItem->GetValue();
     120             : 
     121        1684 :         OUString aStr(unicode::formatPercent(nZoom, Application::GetSettings().GetUILanguageTag()));
     122        1684 :         GetStatusBar().SetItemText( GetId(), aStr );
     123             : 
     124        1684 :         if ( pState->ISA(SvxZoomItem) )
     125             :         {
     126        1684 :             nValueSet = static_cast<const SvxZoomItem*>(pState)->GetValueSet();
     127             :         }
     128             :         else
     129             :         {
     130             :             DBG_WARNING( "use SfxZoomItem for SID_ATTR_ZOOM" );
     131           0 :             nValueSet = SVX_ZOOM_ENABLE_ALL;
     132        1684 :         }
     133             :     }
     134        1684 : }
     135             : 
     136           0 : void SvxZoomStatusBarControl::Paint( const UserDrawEvent& )
     137             : {
     138           0 :     OUString aStr(unicode::formatPercent(nZoom, Application::GetSettings().GetUILanguageTag()));
     139           0 :     GetStatusBar().SetItemText( GetId(), aStr );
     140           0 : }
     141             : 
     142           0 : void SvxZoomStatusBarControl::Command( const CommandEvent& rCEvt )
     143             : {
     144           0 :     if ( COMMAND_CONTEXTMENU & rCEvt.GetCommand() && 0 != nValueSet )
     145             :     {
     146           0 :         CaptureMouse();
     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( SVX_ZOOM_PERCENT, nZoom, GetId() );
     154             : 
     155           0 :             switch( aPop.GetCurId() )
     156             :             {
     157           0 :             case ZOOM_OPTIMAL:      aZoom.SetType( SVX_ZOOM_OPTIMAL ); break;
     158           0 :             case ZOOM_PAGE_WIDTH:   aZoom.SetType( SVX_ZOOM_PAGEWIDTH ); break;
     159           0 :             case ZOOM_WHOLE_PAGE:   aZoom.SetType( SVX_ZOOM_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             :         }
     172           0 :         ReleaseMouse();
     173             :     }
     174             :     else
     175           0 :         SfxStatusBarControl::Command( rCEvt );
     176           0 : }
     177             : 
     178          72 : SFX_IMPL_STATUSBAR_CONTROL(SvxZoomPageStatusBarControl,SfxVoidItem);
     179             : 
     180          36 : SvxZoomPageStatusBarControl::SvxZoomPageStatusBarControl(sal_uInt16 _nSlotId,
     181             :     sal_uInt16 _nId, StatusBar& rStb)
     182             :     : SfxStatusBarControl(_nSlotId, _nId, rStb)
     183          36 :     , maImage(SVX_RES(RID_SVXBMP_ZOOM_PAGE))
     184             : {
     185          36 :     GetStatusBar().SetQuickHelpText(GetId(), SVX_RESSTR(RID_SVXSTR_FIT_SLIDE));
     186          36 : }
     187             : 
     188          16 : void SvxZoomPageStatusBarControl::Paint(const UserDrawEvent& rUsrEvt)
     189             : {
     190          16 :     OutputDevice* pDev = rUsrEvt.GetDevice();
     191          16 :     Rectangle aRect = rUsrEvt.GetRect();
     192          16 :     Point aPt = centerImage(aRect, maImage);
     193          16 :     pDev->DrawImage(aPt, maImage);
     194          16 : }
     195             : 
     196           0 : bool SvxZoomPageStatusBarControl::MouseButtonDown(const MouseEvent&)
     197             : {
     198           0 :     SvxZoomItem aZoom( SVX_ZOOM_WHOLEPAGE, 0, GetId() );
     199             : 
     200           0 :     ::com::sun::star::uno::Any a;
     201           0 :     INetURLObject aObj( m_aCommandURL );
     202             : 
     203           0 :     ::com::sun::star::uno::Sequence< ::com::sun::star::beans::PropertyValue > aArgs( 1 );
     204           0 :     aArgs[0].Name  = aObj.GetURLPath();
     205           0 :     aZoom.QueryValue( a );
     206           0 :     aArgs[0].Value = a;
     207             : 
     208           0 :     execute( aArgs );
     209             : 
     210           0 :     return true;
     211         594 : }
     212             : 
     213             : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */

Generated by: LCOV version 1.10