LCOV - code coverage report
Current view: top level - svx/source/stbctrls - selctrl.cxx (source / functions) Hit Total Coverage
Test: commit c8344322a7af75b84dd3ca8f78b05543a976dfd5 Lines: 30 58 51.7 %
Date: 2015-06-13 12:38:46 Functions: 8 11 72.7 %
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 <vcl/menu.hxx>
      21             : #include <vcl/status.hxx>
      22             : #include <svl/intitem.hxx>
      23             : #include <sfx2/dispatch.hxx>
      24             : #include <tools/urlobj.hxx>
      25             : 
      26             : #include <svx/selctrl.hxx>
      27             : #include <svx/dialmgr.hxx>
      28             : #include <svx/dialogs.hrc>
      29             : 
      30             : #include "stbctrls.h"
      31             : 
      32         619 : SFX_IMPL_STATUSBAR_CONTROL(SvxSelectionModeControl, SfxUInt16Item);
      33             : 
      34             : /// Popup menu to select the selection type
      35         795 : class SelectionTypePopup : public PopupMenu
      36             : {
      37             : public:
      38             :     explicit SelectionTypePopup( sal_uInt16 nCurrent );
      39             : };
      40             : 
      41             : /// Item id's cannot start from 0, so we need to convert
      42           0 : static sal_uInt16 id_to_state( sal_uInt16 nId )
      43             : {
      44           0 :     switch ( nId )
      45             :     {
      46             :         default: // fall through
      47           0 :         case SELECTION_STANDARD: return 0;
      48           0 :         case SELECTION_EXTENDED: return 1;
      49           0 :         case SELECTION_ADDED:    return 2;
      50           0 :         case SELECTION_BLOCK:    return 3;
      51             :     }
      52             : }
      53             : 
      54             : /// Item id's cannot start from 0, so we need to convert
      55        1590 : static sal_uInt16 state_to_id( sal_uInt16 nState )
      56             : {
      57        1590 :     switch ( nState )
      58             :     {
      59             :         default: // fall through
      60        1590 :         case 0: return SELECTION_STANDARD;
      61           0 :         case 1: return SELECTION_EXTENDED;
      62           0 :         case 2: return SELECTION_ADDED;
      63           0 :         case 3: return SELECTION_BLOCK;
      64             :     }
      65             : }
      66             : 
      67         795 : SelectionTypePopup::SelectionTypePopup( sal_uInt16 nCurrent )
      68         795 :     : PopupMenu( ResId( RID_SVXMENU_SELECTION, DIALOG_MGR() ) )
      69             : {
      70         795 :     CheckItem( state_to_id( nCurrent ), true );
      71         795 : }
      72             : 
      73         508 : SvxSelectionModeControl::SvxSelectionModeControl( sal_uInt16 _nSlotId,
      74             :                                                   sal_uInt16 _nId,
      75             :                                                   StatusBar& rStb ) :
      76             :     SfxStatusBarControl( _nSlotId, _nId, rStb ),
      77             :     mnState( 0 ),
      78         508 :     maImage( SVX_RES( RID_SVXBMP_SELECTION ) )
      79             : {
      80             : //#ifndef MACOSX
      81         508 :     if ( GetStatusBar().GetDPIScaleFactor() > 1 )
      82             :     {
      83           0 :         BitmapEx b = maImage.GetBitmapEx();
      84           0 :         b.Scale(GetStatusBar().GetDPIScaleFactor(), GetStatusBar().GetDPIScaleFactor(), BmpScaleFlag::Fast);
      85           0 :         maImage = Image(b);
      86             :     }
      87             : //#endif
      88         508 :     GetStatusBar().SetItemText( GetId(), "" );
      89         508 : }
      90             : 
      91             : 
      92             : 
      93         808 : void SvxSelectionModeControl::StateChanged( sal_uInt16, SfxItemState eState,
      94             :                                             const SfxPoolItem* pState )
      95             : {
      96         808 :     if ( SfxItemState::DEFAULT == eState )
      97             :     {
      98             :         DBG_ASSERT( pState->ISA( SfxUInt16Item ), "invalid item type" );
      99         795 :         const SfxUInt16Item* pItem = static_cast<const SfxUInt16Item*>(pState);
     100         795 :         mnState = pItem->GetValue();
     101             : 
     102         795 :         SelectionTypePopup aPop( mnState );
     103         795 :         GetStatusBar().SetQuickHelpText( GetId(), aPop.GetItemText( state_to_id( mnState ) ) );
     104             :     }
     105         808 : }
     106             : 
     107             : 
     108             : 
     109           0 : bool SvxSelectionModeControl::MouseButtonDown( const MouseEvent& rEvt )
     110             : {
     111           0 :     SelectionTypePopup aPop( mnState );
     112           0 :     StatusBar& rStatusbar = GetStatusBar();
     113             : 
     114           0 :     if ( aPop.Execute( &rStatusbar, rEvt.GetPosPixel() ) )
     115             :     {
     116           0 :         sal_uInt16 nNewState = id_to_state( aPop.GetCurItemId() );
     117           0 :         if ( nNewState != mnState )
     118             :         {
     119           0 :             mnState = nNewState;
     120             : 
     121           0 :             ::com::sun::star::uno::Any a;
     122           0 :             SfxUInt16Item aState( GetSlotId(), mnState );
     123           0 :             INetURLObject aObj( m_aCommandURL );
     124             : 
     125           0 :             ::com::sun::star::uno::Sequence< ::com::sun::star::beans::PropertyValue > aArgs( 1 );
     126           0 :             aArgs[0].Name  = aObj.GetURLPath();
     127           0 :             aState.QueryValue( a );
     128           0 :             aArgs[0].Value = a;
     129             : 
     130           0 :             execute( aArgs );
     131             :         }
     132             :     }
     133             : 
     134           0 :     return true;
     135             : }
     136             : 
     137             : 
     138             : 
     139        3820 : void SvxSelectionModeControl::Paint( const UserDrawEvent& rUsrEvt )
     140             : {
     141        3820 :     const Rectangle aControlRect = getControlRect();
     142        3820 :     OutputDevice* pDev = rUsrEvt.GetDevice();
     143        3820 :     Rectangle aRect = rUsrEvt.GetRect();
     144             : 
     145        3820 :     Size aImgSize( maImage.GetSizePixel() );
     146             : 
     147        7640 :     Point aPos( aRect.Left() + ( aControlRect.GetWidth() - aImgSize.Width() ) / 2,
     148       11460 :             aRect.Top() + ( aControlRect.GetHeight() - aImgSize.Height() ) / 2 );
     149             : 
     150        3820 :     pDev->DrawImage( aPos, maImage );
     151        3820 : }
     152             : 
     153             : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */

Generated by: LCOV version 1.11