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

Generated by: LCOV version 1.10