LCOV - code coverage report
Current view: top level - svx/source/mnuctrls - clipboardctl.cxx (source / functions) Hit Total Coverage
Test: commit 10e77ab3ff6f4314137acd6e2702a6e5c1ce1fae Lines: 26 62 41.9 %
Date: 2014-11-03 Functions: 9 11 81.8 %
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 <sfx2/app.hxx>
      21             : #include <sfx2/tbxctrl.hxx>
      22             : #include <sfx2/bindings.hxx>
      23             : #include <sfx2/dispatch.hxx>
      24             : #include <svl/intitem.hxx>
      25             : #include <sot/exchange.hxx>
      26             : #include <svl/eitem.hxx>
      27             : #include <vcl/toolbox.hxx>
      28             : #include <svx/clipboardctl.hxx>
      29             : #include <svx/clipfmtitem.hxx>
      30             : 
      31             : #include <svtools/insdlg.hxx>
      32             : #include <svx/svxids.hrc>
      33             : 
      34             : using namespace ::com::sun::star::uno;
      35             : using namespace ::com::sun::star::beans;
      36             : 
      37             : 
      38             : 
      39        1666 : SFX_IMPL_TOOLBOX_CONTROL( SvxClipBoardControl, SfxVoidItem /*SfxUInt16Item*/ );
      40             : 
      41             : 
      42        1430 : SvxClipBoardControl::SvxClipBoardControl(
      43             :         sal_uInt16 nSlotId, sal_uInt16 nId, ToolBox& rTbx ) :
      44             : 
      45             :     SfxToolBoxControl( nSlotId, nId, rTbx ),
      46             :     pClipboardFmtItem( 0 ),
      47             :     pPopup( 0 ),
      48        1430 :     bDisabled( false )
      49             : {
      50        1430 :     addStatusListener( OUString( ".uno:ClipboardFormatItems" ));
      51        1430 :     ToolBox& rBox = GetToolBox();
      52        1430 :     rBox.SetItemBits( nId, ToolBoxItemBits::DROPDOWN | rBox.GetItemBits( nId ) );
      53        1430 :     rBox.Invalidate();
      54        1430 : }
      55             : 
      56             : 
      57        4290 : SvxClipBoardControl::~SvxClipBoardControl()
      58             : {
      59        1430 :     DelPopup();
      60        1430 :     delete pClipboardFmtItem;
      61        2860 : }
      62             : 
      63             : 
      64           0 : SfxPopupWindow* SvxClipBoardControl::CreatePopupWindow()
      65             : {
      66           0 :     const SvxClipboardFmtItem* pFmtItem = PTR_CAST( SvxClipboardFmtItem, pClipboardFmtItem );
      67           0 :     if ( pFmtItem )
      68             :     {
      69           0 :         if (pPopup)
      70           0 :             pPopup->Clear();
      71             :         else
      72           0 :             pPopup = new PopupMenu;
      73             : 
      74           0 :         sal_uInt16 nCount = pFmtItem->Count();
      75           0 :         for (sal_uInt16 i = 0;  i < nCount;  ++i)
      76             :         {
      77           0 :             sal_uIntPtr nFmtID =  pFmtItem->GetClipbrdFormatId( i );
      78           0 :             OUString aFmtStr( pFmtItem->GetClipbrdFormatName( i ) );
      79           0 :             if (aFmtStr.isEmpty())
      80           0 :               aFmtStr = SvPasteObjectHelper::GetSotFormatUIName( nFmtID );
      81           0 :             pPopup->InsertItem( (sal_uInt16)nFmtID, aFmtStr );
      82           0 :         }
      83             : 
      84           0 :         ToolBox& rBox = GetToolBox();
      85           0 :         sal_uInt16 nId = GetId();
      86           0 :         rBox.SetItemDown( nId, true );
      87             : 
      88           0 :         pPopup->Execute( &rBox, rBox.GetItemRect( nId ),
      89           0 :             (rBox.GetAlign() == WINDOWALIGN_TOP || rBox.GetAlign() == WINDOWALIGN_BOTTOM) ?
      90           0 :                 POPUPMENU_EXECUTE_DOWN : POPUPMENU_EXECUTE_RIGHT );
      91             : 
      92           0 :         rBox.SetItemDown( nId, false );
      93             : 
      94           0 :         SfxUInt32Item aItem( SID_CLIPBOARD_FORMAT_ITEMS, pPopup->GetCurItemId() );
      95             : 
      96           0 :         Any a;
      97           0 :         Sequence< PropertyValue > aArgs( 1 );
      98           0 :         aArgs[0].Name = "SelectedFormat";
      99           0 :         aItem.QueryValue( a );
     100           0 :         aArgs[0].Value = a;
     101             :         Dispatch( OUString( ".uno:ClipboardFormatItems" ),
     102           0 :                   aArgs );
     103             :     }
     104             : 
     105           0 :     GetToolBox().EndSelection();
     106           0 :     DelPopup();
     107           0 :     return 0;
     108             : }
     109             : 
     110             : 
     111           0 : SfxPopupWindowType SvxClipBoardControl::GetPopupWindowType() const
     112             : {
     113           0 :     return SFX_POPUPWINDOW_ONTIMEOUT;
     114             : }
     115             : 
     116             : 
     117        2662 : void SvxClipBoardControl::StateChanged( sal_uInt16 nSID, SfxItemState eState, const SfxPoolItem* pState )
     118             : {
     119        2662 :     if ( SID_CLIPBOARD_FORMAT_ITEMS == nSID )
     120             :     {
     121        1331 :         DELETEZ( pClipboardFmtItem );
     122        1331 :         if ( eState >= SfxItemState::DEFAULT )
     123             :         {
     124         937 :             pClipboardFmtItem = pState->Clone();
     125         937 :             GetToolBox().SetItemBits( GetId(), GetToolBox().GetItemBits( GetId() ) | ToolBoxItemBits::DROPDOWN );
     126             :         }
     127         394 :         else if ( !bDisabled )
     128           0 :             GetToolBox().SetItemBits( GetId(), GetToolBox().GetItemBits( GetId() ) & ~ToolBoxItemBits::DROPDOWN );
     129        1331 :         GetToolBox().Invalidate( GetToolBox().GetItemRect( GetId() ) );
     130             :     }
     131             :     else
     132             :     {
     133             :         // enable the item as a whole
     134        1331 :         bDisabled = (GetItemState(pState) == SfxItemState::DISABLED);
     135        1331 :         GetToolBox().EnableItem( GetId(), (GetItemState(pState) != SfxItemState::DISABLED) );
     136             :     }
     137        2662 : }
     138             : 
     139             : 
     140        1430 : void SvxClipBoardControl::DelPopup()
     141             : {
     142        1430 :     if(pPopup)
     143             :     {
     144           0 :         delete pPopup;
     145           0 :         pPopup = 0;
     146             :     }
     147        2024 : }
     148             : 
     149             : 
     150             : 
     151             : 
     152             : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */

Generated by: LCOV version 1.10