LCOV - code coverage report
Current view: top level - svx/source/mnuctrls - clipboardctl.cxx (source / functions) Hit Total Coverage
Test: libreoffice_filtered.info Lines: 26 62 41.9 %
Date: 2012-08-25 Functions: 7 9 77.8 %
Legend: Lines: hit not hit | Branches: + taken - not taken # not executed Branches: 21 110 19.1 %

           Branch data     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 <tools/gen.hxx>
      25                 :            : #include <svl/intitem.hxx>
      26                 :            : #include <sot/exchange.hxx>
      27                 :            : #include <svl/eitem.hxx>
      28                 :            : #include <vcl/toolbox.hxx>
      29                 :            : #include <svx/clipboardctl.hxx>
      30                 :            : #include <svx/clipfmtitem.hxx>
      31                 :            : 
      32                 :            : #include <svtools/insdlg.hxx>
      33                 :            : #include <svx/svxids.hrc>
      34                 :            : 
      35                 :            : using namespace ::com::sun::star::uno;
      36                 :            : using namespace ::com::sun::star::beans;
      37                 :            : 
      38                 :            : /////////////////////////////////////////////////////////////////
      39                 :            : 
      40         [ +  - ]:       1258 : SFX_IMPL_TOOLBOX_CONTROL( SvxClipBoardControl, SfxVoidItem /*SfxUInt16Item*/ );
      41                 :            : 
      42                 :            : 
      43                 :       1109 : SvxClipBoardControl::SvxClipBoardControl(
      44                 :            :         sal_uInt16 nSlotId, sal_uInt16 nId, ToolBox& rTbx ) :
      45                 :            : 
      46                 :            :     SfxToolBoxControl( nSlotId, nId, rTbx ),
      47                 :            :     pClipboardFmtItem( 0 ),
      48                 :            :      pPopup     (0),
      49                 :       1109 :     bDisabled( sal_False )
      50                 :            : {
      51 [ +  - ][ +  - ]:       1109 :     addStatusListener( rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( ".uno:ClipboardFormatItems" )));
      52         [ +  - ]:       1109 :     ToolBox& rBox = GetToolBox();
      53 [ +  - ][ +  - ]:       1109 :     rBox.SetItemBits( nId, TIB_DROPDOWN | rBox.GetItemBits( nId ) );
      54         [ +  - ]:       1109 :     rBox.Invalidate();
      55                 :       1109 : }
      56                 :            : 
      57                 :            : 
      58                 :       1109 : SvxClipBoardControl::~SvxClipBoardControl()
      59                 :            : {
      60         [ +  - ]:       1109 :     DelPopup();
      61 [ +  + ][ +  - ]:       1109 :     delete pClipboardFmtItem;
      62         [ -  + ]:       2218 : }
      63                 :            : 
      64                 :            : 
      65                 :          0 : SfxPopupWindow* SvxClipBoardControl::CreatePopupWindow()
      66                 :            : {
      67 [ #  # ][ #  # ]:          0 :     const SvxClipboardFmtItem* pFmtItem = PTR_CAST( SvxClipboardFmtItem, pClipboardFmtItem );
      68         [ #  # ]:          0 :     if ( pFmtItem )
      69                 :            :     {
      70         [ #  # ]:          0 :         if (pPopup)
      71         [ #  # ]:          0 :             pPopup->Clear();
      72                 :            :         else
      73 [ #  # ][ #  # ]:          0 :             pPopup = new PopupMenu;
      74                 :            : 
      75         [ #  # ]:          0 :         sal_uInt16 nCount = pFmtItem->Count();
      76         [ #  # ]:          0 :         for (sal_uInt16 i = 0;  i < nCount;  ++i)
      77                 :            :         {
      78         [ #  # ]:          0 :             sal_uIntPtr nFmtID =  pFmtItem->GetClipbrdFormatId( i );
      79 [ #  # ][ #  # ]:          0 :             String aFmtStr( pFmtItem->GetClipbrdFormatName( i ) );
      80         [ #  # ]:          0 :             if (!aFmtStr.Len())
      81 [ #  # ][ #  # ]:          0 :               aFmtStr = SvPasteObjectHelper::GetSotFormatUIName( nFmtID );
                 [ #  # ]
      82         [ #  # ]:          0 :             pPopup->InsertItem( (sal_uInt16)nFmtID, aFmtStr );
      83         [ #  # ]:          0 :         }
      84                 :            : 
      85         [ #  # ]:          0 :         ToolBox& rBox = GetToolBox();
      86         [ #  # ]:          0 :         sal_uInt16 nId = GetId();
      87         [ #  # ]:          0 :         rBox.SetItemDown( nId, sal_True );
      88                 :            : 
      89                 :          0 :         pPopup->Execute( &rBox, rBox.GetItemRect( nId ),
      90                 :          0 :             (rBox.GetAlign() == WINDOWALIGN_TOP || rBox.GetAlign() == WINDOWALIGN_BOTTOM) ?
      91 [ #  # ][ #  # ]:          0 :                 POPUPMENU_EXECUTE_DOWN : POPUPMENU_EXECUTE_RIGHT );
           [ #  #  #  # ]
      92                 :            : 
      93         [ #  # ]:          0 :         rBox.SetItemDown( nId, sal_False );
      94                 :            : 
      95 [ #  # ][ #  # ]:          0 :         SfxUInt32Item aItem( SID_CLIPBOARD_FORMAT_ITEMS, pPopup->GetCurItemId() );
      96                 :            : 
      97                 :          0 :         Any a;
      98         [ #  # ]:          0 :         Sequence< PropertyValue > aArgs( 1 );
      99 [ #  # ][ #  # ]:          0 :         aArgs[0].Name = rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "SelectedFormat" ));
     100         [ #  # ]:          0 :         aItem.QueryValue( a );
     101         [ #  # ]:          0 :         aArgs[0].Value = a;
     102                 :            :         Dispatch( rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( ".uno:ClipboardFormatItems" )),
     103 [ #  # ][ #  # ]:          0 :                   aArgs );
         [ #  # ][ #  # ]
     104                 :            :     }
     105                 :            : 
     106                 :          0 :     GetToolBox().EndSelection();
     107                 :          0 :     DelPopup();
     108                 :          0 :     return 0;
     109                 :            : }
     110                 :            : 
     111                 :            : 
     112                 :          0 : SfxPopupWindowType SvxClipBoardControl::GetPopupWindowType() const
     113                 :            : {
     114                 :          0 :     return SFX_POPUPWINDOW_ONTIMEOUT;
     115                 :            : }
     116                 :            : 
     117                 :            : 
     118                 :       3634 : void SvxClipBoardControl::StateChanged( sal_uInt16 nSID, SfxItemState eState, const SfxPoolItem* pState )
     119                 :            : {
     120         [ +  + ]:       3634 :     if ( SID_CLIPBOARD_FORMAT_ITEMS == nSID )
     121                 :            :     {
     122         [ +  + ]:       1817 :         DELETEZ( pClipboardFmtItem );
     123         [ +  + ]:       1817 :         if ( eState >= SFX_ITEM_AVAILABLE )
     124                 :            :         {
     125                 :       1295 :             pClipboardFmtItem = pState->Clone();
     126                 :       1295 :             GetToolBox().SetItemBits( GetId(), GetToolBox().GetItemBits( GetId() ) | TIB_DROPDOWN );
     127                 :            :         }
     128         [ -  + ]:        522 :         else if ( !bDisabled )
     129                 :          0 :             GetToolBox().SetItemBits( GetId(), GetToolBox().GetItemBits( GetId() ) & ~TIB_DROPDOWN );
     130         [ +  - ]:       1817 :         GetToolBox().Invalidate( GetToolBox().GetItemRect( GetId() ) );
     131                 :            :     }
     132                 :            :     else
     133                 :            :     {
     134                 :            :         // enable the item as a whole
     135                 :       1817 :         bDisabled = (GetItemState(pState) == SFX_ITEM_DISABLED);
     136                 :       1817 :         GetToolBox().EnableItem( GetId(), (GetItemState(pState) != SFX_ITEM_DISABLED) );
     137                 :            :     }
     138                 :       3634 : }
     139                 :            : 
     140                 :            : 
     141                 :       1109 : void SvxClipBoardControl::DelPopup()
     142                 :            : {
     143         [ -  + ]:       1109 :     if(pPopup)
     144                 :            :     {
     145         [ #  # ]:          0 :         delete pPopup;
     146                 :          0 :         pPopup = 0;
     147                 :            :     }
     148                 :       1109 : }
     149                 :            : 
     150                 :            : 
     151                 :            : /////////////////////////////////////////////////////////////////
     152                 :            : 
     153                 :            : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */

Generated by: LCOV version 1.10