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

Generated by: LCOV version 1.10