LCOV - code coverage report
Current view: top level - svx/source/stbctrls - selctrl.cxx (source / functions) Hit Total Coverage
Test: commit 10e77ab3ff6f4314137acd6e2702a6e5c1ce1fae Lines: 30 60 50.0 %
Date: 2014-11-03 Functions: 10 13 76.9 %
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        1398 : SFX_IMPL_STATUSBAR_CONTROL(SvxSelectionModeControl, SfxUInt16Item);
      33             : 
      34             : /// Popup menu to select the selection type
      35        1413 : class SelectionTypePopup : public PopupMenu
      36             : {
      37             : public:
      38             :     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        2826 : static sal_uInt16 state_to_id( sal_uInt16 nState )
      56             : {
      57        2826 :     switch ( nState )
      58             :     {
      59             :         default: // fall through
      60        2826 :         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        1413 : SelectionTypePopup::SelectionTypePopup( sal_uInt16 nCurrent )
      68        1413 :     : PopupMenu( ResId( RID_SVXMENU_SELECTION, DIALOG_MGR() ) )
      69             : {
      70        1413 :     CheckItem( state_to_id( nCurrent ), true );
      71        1413 : }
      72             : 
      73        1234 : SvxSelectionModeControl::SvxSelectionModeControl( sal_uInt16 _nSlotId,
      74             :                                                   sal_uInt16 _nId,
      75             :                                                   StatusBar& rStb ) :
      76             :     SfxStatusBarControl( _nSlotId, _nId, rStb ),
      77             :     mnState( 0 ),
      78        1234 :     maImage( SVX_RES( RID_SVXBMP_SELECTION ) )
      79             : {
      80             : //#ifndef MACOSX
      81        1234 :     if ( GetStatusBar().GetDPIScaleFactor() > 1 )
      82             :     {
      83           0 :         BitmapEx b = maImage.GetBitmapEx();
      84           0 :         b.Scale(GetStatusBar().GetDPIScaleFactor(), GetStatusBar().GetDPIScaleFactor(), BMP_SCALE_FAST);
      85           0 :         maImage = Image(b);
      86             :     }
      87             : //#endif
      88        1234 :     GetStatusBar().SetItemText( GetId(), "" );
      89        1234 : }
      90             : 
      91             : 
      92             : 
      93        1439 : void SvxSelectionModeControl::StateChanged( sal_uInt16, SfxItemState eState,
      94             :                                             const SfxPoolItem* pState )
      95             : {
      96        1439 :     if ( SfxItemState::DEFAULT == eState )
      97             :     {
      98             :         DBG_ASSERT( pState->ISA( SfxUInt16Item ), "invalid item type" );
      99        1413 :         const SfxUInt16Item* pItem = static_cast<const SfxUInt16Item*>(pState);
     100        1413 :         mnState = pItem->GetValue();
     101             : 
     102        1413 :         SelectionTypePopup aPop( mnState );
     103        1413 :         GetStatusBar().SetQuickHelpText( GetId(), aPop.GetItemText( state_to_id( mnState ) ) );
     104             :     }
     105        1439 : }
     106             : 
     107             : 
     108             : 
     109           0 : bool SvxSelectionModeControl::MouseButtonDown( const MouseEvent& rEvt )
     110             : {
     111           0 :     CaptureMouse();
     112           0 :     SelectionTypePopup aPop( mnState );
     113           0 :     StatusBar& rStatusbar = GetStatusBar();
     114             : 
     115           0 :     if ( aPop.Execute( &rStatusbar, rEvt.GetPosPixel() ) )
     116             :     {
     117           0 :         sal_uInt16 nNewState = id_to_state( aPop.GetCurItemId() );
     118           0 :         if ( nNewState != mnState )
     119             :         {
     120           0 :             mnState = nNewState;
     121             : 
     122           0 :             ::com::sun::star::uno::Any a;
     123           0 :             SfxUInt16Item aState( GetSlotId(), mnState );
     124           0 :             INetURLObject aObj( m_aCommandURL );
     125             : 
     126           0 :             ::com::sun::star::uno::Sequence< ::com::sun::star::beans::PropertyValue > aArgs( 1 );
     127           0 :             aArgs[0].Name  = aObj.GetURLPath();
     128           0 :             aState.QueryValue( a );
     129           0 :             aArgs[0].Value = a;
     130             : 
     131           0 :             execute( aArgs );
     132             :         }
     133             :     }
     134           0 :     ReleaseMouse();
     135             : 
     136           0 :     return true;
     137             : }
     138             : 
     139             : 
     140             : 
     141        1699 : void SvxSelectionModeControl::Paint( const UserDrawEvent& rUsrEvt )
     142             : {
     143        1699 :     const Rectangle aControlRect = getControlRect();
     144        1699 :     OutputDevice* pDev = rUsrEvt.GetDevice();
     145        1699 :     Rectangle aRect = rUsrEvt.GetRect();
     146             : 
     147        1699 :     Size aImgSize( maImage.GetSizePixel() );
     148             : 
     149        3398 :     Point aPos( aRect.Left() + ( aControlRect.GetWidth() - aImgSize.Width() ) / 2,
     150        5097 :             aRect.Top() + ( aControlRect.GetHeight() - aImgSize.Height() ) / 2 );
     151             : 
     152        1699 :     pDev->DrawImage( aPos, maImage );
     153        2293 : }
     154             : 
     155             : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */

Generated by: LCOV version 1.10