LCOV - code coverage report
Current view: top level - svx/source/stbctrls - selctrl.cxx (source / functions) Hit Total Coverage
Test: libreoffice_filtered.info Lines: 30 56 53.6 %
Date: 2012-08-25 Functions: 8 11 72.7 %
Legend: Lines: hit not hit | Branches: + taken - not taken # not executed Branches: 22 86 25.6 %

           Branch data     Line data    Source code
       1                 :            : /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
       2                 :            : /*************************************************************************
       3                 :            :  *
       4                 :            :  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
       5                 :            :  *
       6                 :            :  * Copyright 2000, 2010 Oracle and/or its affiliates.
       7                 :            :  *
       8                 :            :  * OpenOffice.org - a multi-platform office productivity suite
       9                 :            :  *
      10                 :            :  * This file is part of OpenOffice.org.
      11                 :            :  *
      12                 :            :  * OpenOffice.org is free software: you can redistribute it and/or modify
      13                 :            :  * it under the terms of the GNU Lesser General Public License version 3
      14                 :            :  * only, as published by the Free Software Foundation.
      15                 :            :  *
      16                 :            :  * OpenOffice.org is distributed in the hope that it will be useful,
      17                 :            :  * but WITHOUT ANY WARRANTY; without even the implied warranty of
      18                 :            :  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
      19                 :            :  * GNU Lesser General Public License version 3 for more details
      20                 :            :  * (a copy is included in the LICENSE file that accompanied this code).
      21                 :            :  *
      22                 :            :  * You should have received a copy of the GNU Lesser General Public License
      23                 :            :  * version 3 along with OpenOffice.org.  If not, see
      24                 :            :  * <http://www.openoffice.org/license.html>
      25                 :            :  * for a copy of the LGPLv3 License.
      26                 :            :  *
      27                 :            :  ************************************************************************/
      28                 :            : 
      29                 :            : #include <tools/shl.hxx>
      30                 :            : #include <vcl/menu.hxx>
      31                 :            : #include <vcl/status.hxx>
      32                 :            : #include <svl/intitem.hxx>
      33                 :            : #include <sfx2/dispatch.hxx>
      34                 :            : #include <tools/urlobj.hxx>
      35                 :            : 
      36                 :            : #include <svx/selctrl.hxx>
      37                 :            : #include <svx/dialmgr.hxx>
      38                 :            : #include <svx/dialogs.hrc>
      39                 :            : 
      40                 :            : #include "stbctrls.h"
      41                 :            : 
      42         [ +  - ]:       1103 : SFX_IMPL_STATUSBAR_CONTROL(SvxSelectionModeControl, SfxUInt16Item);
      43                 :            : 
      44                 :            : /// Popup menu to select the selection type
      45         [ -  + ]:       1489 : class SelectionTypePopup : public PopupMenu
      46                 :            : {
      47                 :            : public:
      48                 :            :     SelectionTypePopup( sal_uInt16 nCurrent );
      49                 :            : };
      50                 :            : 
      51                 :            : /// Item id's cannot start from 0, so we need to convert
      52                 :          0 : static sal_uInt16 id_to_state( sal_uInt16 nId )
      53                 :            : {
      54   [ #  #  #  # ]:          0 :     switch ( nId )
      55                 :            :     {
      56                 :            :         default: // fall through
      57                 :          0 :         case SELECTION_STANDARD: return 0;
      58                 :          0 :         case SELECTION_EXTENDED: return 1;
      59                 :          0 :         case SELECTION_ADDED:    return 2;
      60                 :          0 :         case SELECTION_BLOCK:    return 3;
      61                 :            :     }
      62                 :            : }
      63                 :            : 
      64                 :            : /// Item id's cannot start from 0, so we need to convert
      65                 :       2978 : static sal_uInt16 state_to_id( sal_uInt16 nState )
      66                 :            : {
      67   [ +  -  -  - ]:       2978 :     switch ( nState )
      68                 :            :     {
      69                 :            :         default: // fall through
      70                 :       2978 :         case 0: return SELECTION_STANDARD;
      71                 :          0 :         case 1: return SELECTION_EXTENDED;
      72                 :          0 :         case 2: return SELECTION_ADDED;
      73                 :       2978 :         case 3: return SELECTION_BLOCK;
      74                 :            :     }
      75                 :            : }
      76                 :            : 
      77                 :       1489 : SelectionTypePopup::SelectionTypePopup( sal_uInt16 nCurrent )
      78         [ +  - ]:       1489 :     : PopupMenu( ResId( RID_SVXMENU_SELECTION, DIALOG_MGR() ) )
      79                 :            : {
      80         [ +  - ]:       1489 :     CheckItem( state_to_id( nCurrent ), true );
      81                 :       1489 : }
      82                 :            : 
      83                 :            : // class SvxSelectionModeControl -----------------------------------------
      84                 :            : 
      85                 :        979 : SvxSelectionModeControl::SvxSelectionModeControl( sal_uInt16 _nSlotId,
      86                 :            :                                                   sal_uInt16 _nId,
      87                 :            :                                                   StatusBar& rStb ) :
      88                 :            :     SfxStatusBarControl( _nSlotId, _nId, rStb ),
      89                 :            :     mnState( 0 ),
      90 [ +  - ][ +  - ]:        979 :     maImage( SVX_RES( RID_SVXBMP_SELECTION ) )
      91                 :            : {
      92 [ +  - ][ +  - ]:        979 :     GetStatusBar().SetItemText( GetId(), String() );
                 [ +  - ]
      93                 :        979 : }
      94                 :            : 
      95                 :            : // -----------------------------------------------------------------------
      96                 :            : 
      97                 :       1516 : void SvxSelectionModeControl::StateChanged( sal_uInt16, SfxItemState eState,
      98                 :            :                                             const SfxPoolItem* pState )
      99                 :            : {
     100         [ +  + ]:       1516 :     if ( SFX_ITEM_AVAILABLE == eState )
     101                 :            :     {
     102                 :            :         DBG_ASSERT( pState->ISA( SfxUInt16Item ), "invalid item type" );
     103                 :       1489 :         SfxUInt16Item* pItem = (SfxUInt16Item*)pState;
     104                 :       1489 :         mnState = pItem->GetValue();
     105                 :            : 
     106         [ +  - ]:       1489 :         SelectionTypePopup aPop( mnState );
     107 [ +  - ][ +  - ]:       1489 :         GetStatusBar().SetQuickHelpText( GetId(), aPop.GetItemText( state_to_id( mnState ) ) );
         [ +  - ][ +  - ]
     108                 :            :     }
     109                 :       1516 : }
     110                 :            : 
     111                 :            : // -----------------------------------------------------------------------
     112                 :            : 
     113                 :          0 : sal_Bool SvxSelectionModeControl::MouseButtonDown( const MouseEvent& rEvt )
     114                 :            : {
     115         [ #  # ]:          0 :     CaptureMouse();
     116         [ #  # ]:          0 :     SelectionTypePopup aPop( mnState );
     117                 :          0 :     StatusBar& rStatusbar = GetStatusBar();
     118                 :            : 
     119 [ #  # ][ #  # ]:          0 :     if ( aPop.Execute( &rStatusbar, rEvt.GetPosPixel() ) )
     120                 :            :     {
     121         [ #  # ]:          0 :         sal_uInt16 nNewState = id_to_state( aPop.GetCurItemId() );
     122         [ #  # ]:          0 :         if ( nNewState != mnState )
     123                 :            :         {
     124                 :          0 :             mnState = nNewState;
     125                 :            : 
     126                 :          0 :             ::com::sun::star::uno::Any a;
     127         [ #  # ]:          0 :             SfxUInt16Item aState( GetSlotId(), mnState );
     128         [ #  # ]:          0 :             INetURLObject aObj( m_aCommandURL );
     129                 :            : 
     130         [ #  # ]:          0 :             ::com::sun::star::uno::Sequence< ::com::sun::star::beans::PropertyValue > aArgs( 1 );
     131 [ #  # ][ #  # ]:          0 :             aArgs[0].Name  = aObj.GetURLPath();
     132         [ #  # ]:          0 :             aState.QueryValue( a );
     133         [ #  # ]:          0 :             aArgs[0].Value = a;
     134                 :            : 
     135 [ #  # ][ #  # ]:          0 :             execute( aArgs );
         [ #  # ][ #  # ]
     136                 :            :         }
     137                 :            :     }
     138         [ #  # ]:          0 :     ReleaseMouse();
     139                 :            : 
     140         [ #  # ]:          0 :     return sal_True;
     141                 :            : }
     142                 :            : 
     143                 :            : // -----------------------------------------------------------------------
     144                 :            : 
     145                 :       1898 : void SvxSelectionModeControl::Paint( const UserDrawEvent& rUsrEvt )
     146                 :            : {
     147         [ +  - ]:       1898 :     const Rectangle aControlRect = getControlRect();
     148                 :       1898 :     OutputDevice* pDev = rUsrEvt.GetDevice();
     149                 :       1898 :     Rectangle aRect = rUsrEvt.GetRect();
     150                 :            : 
     151         [ +  - ]:       1898 :     Size aImgSize( maImage.GetSizePixel() );
     152                 :            : 
     153         [ +  - ]:       1898 :     Point aPos( aRect.Left() + ( aControlRect.GetWidth() - aImgSize.Width() ) / 2,
     154         [ +  - ]:       3796 :             aRect.Top() + ( aControlRect.GetHeight() - aImgSize.Height() ) / 2 );
     155                 :            : 
     156         [ +  - ]:       1898 :     pDev->DrawImage( aPos, maImage );
     157                 :       1898 : }
     158                 :            : 
     159                 :            : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */

Generated by: LCOV version 1.10