LCOV - code coverage report
Current view: top level - svx/source/stbctrls - zoomctrl.cxx (source / functions) Hit Total Coverage
Test: commit e02a6cb2c3e2b23b203b422e4e0680877f232636 Lines: 0 64 0.0 %
Date: 2014-04-14 Functions: 0 12 0.0 %
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 <tools/shl.hxx>
      22             : #include <vcl/svapp.hxx>
      23             : #include <vcl/status.hxx>
      24             : #include <vcl/menu.hxx>
      25             : #include <vcl/settings.hxx>
      26             : #include <sfx2/dispatch.hxx>
      27             : #include <tools/urlobj.hxx>
      28             : 
      29             : #include <svx/dialogs.hrc>
      30             : 
      31             : #include "svx/zoomctrl.hxx"
      32             : #include <sfx2/zoomitem.hxx>
      33             : #include "stbctrls.h"
      34             : #include <svx/dialmgr.hxx>
      35             : 
      36           0 : SFX_IMPL_STATUSBAR_CONTROL(SvxZoomStatusBarControl,SvxZoomItem);
      37             : 
      38             : // class ZoomPopup_Impl --------------------------------------------------
      39             : 
      40           0 : class ZoomPopup_Impl : public PopupMenu
      41             : {
      42             : public:
      43             :     ZoomPopup_Impl( sal_uInt16 nZ, sal_uInt16 nValueSet );
      44             : 
      45           0 :     sal_uInt16          GetZoom() const { return nZoom; }
      46           0 :     sal_uInt16          GetCurId() const { return nCurId; }
      47             : 
      48             : private:
      49             :     sal_uInt16          nZoom;
      50             :     sal_uInt16          nCurId;
      51             : 
      52             :     virtual void    Select() SAL_OVERRIDE;
      53             : };
      54             : 
      55             : 
      56             : 
      57           0 : ZoomPopup_Impl::ZoomPopup_Impl( sal_uInt16 nZ, sal_uInt16 nValueSet )
      58           0 :     : PopupMenu(ResId(RID_SVXMNU_ZOOM, DIALOG_MGR()))
      59             :     , nZoom(nZ)
      60           0 :     , nCurId(0)
      61             : {
      62             :     static const sal_uInt16 aTable[] =
      63             :     {
      64             :         SVX_ZOOM_ENABLE_50,         ZOOM_50,
      65             :         SVX_ZOOM_ENABLE_100,        ZOOM_100,
      66             :         SVX_ZOOM_ENABLE_150,        ZOOM_150,
      67             :         SVX_ZOOM_ENABLE_200,        ZOOM_200,
      68             :         SVX_ZOOM_ENABLE_OPTIMAL,    ZOOM_OPTIMAL,
      69             :         SVX_ZOOM_ENABLE_WHOLEPAGE,  ZOOM_WHOLE_PAGE,
      70             :         SVX_ZOOM_ENABLE_PAGEWIDTH,  ZOOM_PAGE_WIDTH
      71             :     };
      72             : 
      73           0 :     for ( sal_uInt16 nPos = 0; nPos < SAL_N_ELEMENTS(aTable); nPos += 2 )
      74           0 :         if ( ( aTable[nPos] != ( aTable[nPos] & nValueSet ) ) )
      75           0 :             EnableItem( aTable[nPos+1], false );
      76           0 : }
      77             : 
      78             : 
      79             : 
      80           0 : void ZoomPopup_Impl::Select()
      81             : {
      82           0 :     nCurId = GetCurItemId();
      83             : 
      84           0 :     switch ( nCurId )
      85             :     {
      86           0 :         case ZOOM_200:          nZoom = 200; break;
      87           0 :         case ZOOM_150:          nZoom = 150; break;
      88           0 :         case ZOOM_100:          nZoom = 100; break;
      89           0 :         case ZOOM_75:           nZoom =  75; break;
      90           0 :         case ZOOM_50:           nZoom =  50; break;
      91             : 
      92             :         case ZOOM_OPTIMAL:
      93             :         case ZOOM_PAGE_WIDTH:
      94           0 :         case ZOOM_WHOLE_PAGE:   nZoom = 0; break;
      95             : 
      96             :     }
      97           0 : }
      98             : 
      99             : // class SvxZoomStatusBarControl ------------------------------------------
     100             : 
     101           0 : SvxZoomStatusBarControl::SvxZoomStatusBarControl( sal_uInt16 _nSlotId,
     102             :                                                   sal_uInt16 _nId,
     103             :                                                   StatusBar& rStb ) :
     104             : 
     105             :     SfxStatusBarControl( _nSlotId, _nId, rStb ),
     106             :     nZoom( 100 ),
     107           0 :     nValueSet( SVX_ZOOM_ENABLE_ALL )
     108             : {
     109           0 : }
     110             : 
     111             : 
     112             : 
     113           0 : void SvxZoomStatusBarControl::StateChanged( sal_uInt16, SfxItemState eState,
     114             :                                             const SfxPoolItem* pState )
     115             : {
     116           0 :     if( SFX_ITEM_AVAILABLE != eState )
     117             :     {
     118           0 :         GetStatusBar().SetItemText( GetId(), "" );
     119           0 :         nValueSet = 0;
     120             :     }
     121           0 :     else if ( pState->ISA( SfxUInt16Item) )
     122             :     {
     123           0 :         const SfxUInt16Item* pItem = (const SfxUInt16Item*)pState;
     124           0 :         nZoom = pItem->GetValue();
     125             : 
     126           0 :         OUString aStr(unicode::formatPercent(nZoom, Application::GetSettings().GetUILanguageTag()));
     127           0 :         GetStatusBar().SetItemText( GetId(), aStr );
     128             : 
     129           0 :         if ( pState->ISA(SvxZoomItem) )
     130             :         {
     131           0 :             nValueSet = ((const SvxZoomItem*)pState)->GetValueSet();
     132             :         }
     133             :         else
     134             :         {
     135             :             DBG_WARNING( "use SfxZoomItem for SID_ATTR_ZOOM" );
     136           0 :             nValueSet = SVX_ZOOM_ENABLE_ALL;
     137           0 :         }
     138             :     }
     139           0 : }
     140             : 
     141             : 
     142             : 
     143           0 : void SvxZoomStatusBarControl::Paint( const UserDrawEvent& )
     144             : {
     145           0 :     OUString aStr(unicode::formatPercent(nZoom, Application::GetSettings().GetUILanguageTag()));
     146           0 :     GetStatusBar().SetItemText( GetId(), aStr );
     147           0 : }
     148             : 
     149             : 
     150             : 
     151           0 : void SvxZoomStatusBarControl::Command( const CommandEvent& rCEvt )
     152             : {
     153           0 :     if ( COMMAND_CONTEXTMENU & rCEvt.GetCommand() && 0 != nValueSet )
     154             :     {
     155           0 :         CaptureMouse();
     156           0 :         ZoomPopup_Impl aPop( nZoom, nValueSet );
     157           0 :         StatusBar& rStatusbar = GetStatusBar();
     158             : 
     159           0 :         if ( aPop.Execute( &rStatusbar, rCEvt.GetMousePosPixel() ) && ( nZoom != aPop.GetZoom() || !nZoom ) )
     160             :         {
     161           0 :             nZoom = aPop.GetZoom();
     162           0 :             SvxZoomItem aZoom( SVX_ZOOM_PERCENT, nZoom, GetId() );
     163             : 
     164           0 :             switch( aPop.GetCurId() )
     165             :             {
     166           0 :             case ZOOM_OPTIMAL:      aZoom.SetType( SVX_ZOOM_OPTIMAL ); break;
     167           0 :             case ZOOM_PAGE_WIDTH:   aZoom.SetType( SVX_ZOOM_PAGEWIDTH ); break;
     168           0 :             case ZOOM_WHOLE_PAGE:   aZoom.SetType( SVX_ZOOM_WHOLEPAGE ); break;
     169             :             }
     170             : 
     171           0 :             ::com::sun::star::uno::Any a;
     172           0 :             INetURLObject aObj( m_aCommandURL );
     173             : 
     174           0 :             ::com::sun::star::uno::Sequence< ::com::sun::star::beans::PropertyValue > aArgs( 1 );
     175           0 :             aArgs[0].Name  = aObj.GetURLPath();
     176           0 :             aZoom.QueryValue( a );
     177           0 :             aArgs[0].Value = a;
     178             : 
     179           0 :             execute( aArgs );
     180             :         }
     181           0 :         ReleaseMouse();
     182             :     }
     183             :     else
     184           0 :         SfxStatusBarControl::Command( rCEvt );
     185           0 : }
     186             : 
     187             : 
     188             : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */

Generated by: LCOV version 1.10