LCOV - code coverage report
Current view: top level - framework/source/fwe/classes - bmkmenu.cxx (source / functions) Hit Total Coverage
Test: libreoffice_filtered.info Lines: 67 72 93.1 %
Date: 2012-08-25 Functions: 9 9 100.0 %
Legend: Lines: hit not hit | Branches: + taken - not taken # not executed Branches: 70 136 51.5 %

           Branch data     Line data    Source code
       1                 :            : /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
       2                 :            : /*************************************************************************
       3                 :            :  *
       4                 :            :  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
       5                 :            :  *
       6                 :            :  * Copyright 2000, 2010 Oracle and/or its affiliates.
       7                 :            :  *
       8                 :            :  * OpenOffice.org - a multi-platform office productivity suite
       9                 :            :  *
      10                 :            :  * This file is part of OpenOffice.org.
      11                 :            :  *
      12                 :            :  * OpenOffice.org is free software: you can redistribute it and/or modify
      13                 :            :  * it under the terms of the GNU Lesser General Public License version 3
      14                 :            :  * only, as published by the Free Software Foundation.
      15                 :            :  *
      16                 :            :  * OpenOffice.org is distributed in the hope that it will be useful,
      17                 :            :  * but WITHOUT ANY WARRANTY; without even the implied warranty of
      18                 :            :  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
      19                 :            :  * GNU Lesser General Public License version 3 for more details
      20                 :            :  * (a copy is included in the LICENSE file that accompanied this code).
      21                 :            :  *
      22                 :            :  * You should have received a copy of the GNU Lesser General Public License
      23                 :            :  * version 3 along with OpenOffice.org.  If not, see
      24                 :            :  * <http://www.openoffice.org/license.html>
      25                 :            :  * for a copy of the LGPLv3 License.
      26                 :            :  *
      27                 :            :  ************************************************************************/
      28                 :            : 
      29                 :            : #include <limits.h>
      30                 :            : 
      31                 :            : #include "framework/bmkmenu.hxx"
      32                 :            : #include <general.h>
      33                 :            : #include <macros/debug/assertion.hxx>
      34                 :            : #include <framework/imageproducer.hxx>
      35                 :            : #include <framework/menuconfiguration.hxx>
      36                 :            : 
      37                 :            : #include <com/sun/star/uno/Reference.h>
      38                 :            : #include <com/sun/star/util/URL.hpp>
      39                 :            : #include <com/sun/star/beans/PropertyValue.hpp>
      40                 :            : #include <comphelper/processfactory.hxx>
      41                 :            : #include <com/sun/star/util/XURLTransformer.hpp>
      42                 :            : #include <com/sun/star/lang/XMultiServiceFactory.hpp>
      43                 :            : #include <com/sun/star/util/DateTime.hpp>
      44                 :            : 
      45                 :            : #include <vcl/svapp.hxx>
      46                 :            : #include <unotools/dynamicmenuoptions.hxx>
      47                 :            : #include <svtools/menuoptions.hxx>
      48                 :            : #include <rtl/logfile.hxx>
      49                 :            : 
      50                 :            : using namespace ::comphelper;
      51                 :            : using namespace ::com::sun::star::uno;
      52                 :            : using namespace ::com::sun::star::lang;
      53                 :            : using namespace ::com::sun::star::util;
      54                 :            : using namespace ::com::sun::star::frame;
      55                 :            : using namespace ::com::sun::star::beans;
      56                 :            : 
      57                 :            : namespace framework
      58                 :            : {
      59                 :            : 
      60                 :            : void GetMenuEntry(
      61                 :            :     Sequence< PropertyValue >&  aDynamicMenuEntry,
      62                 :            :     ::rtl::OUString&            rTitle,
      63                 :            :     ::rtl::OUString&            rURL,
      64                 :            :     ::rtl::OUString&            rFrame,
      65                 :            :     ::rtl::OUString&            rImageId );
      66                 :            : 
      67                 :            : class BmkMenu_Impl
      68                 :            : {
      69                 :            :     private:
      70                 :            :         static sal_uInt16        m_nMID;
      71                 :            : 
      72                 :            :     public:
      73                 :            :         sal_Bool                 m_bInitialized;
      74                 :            : 
      75                 :            :         BmkMenu_Impl();
      76                 :            :         ~BmkMenu_Impl();
      77                 :            : 
      78                 :            :         static sal_uInt16       GetMID();
      79                 :            : };
      80                 :            : 
      81                 :            : sal_uInt16 BmkMenu_Impl::m_nMID = BMKMENU_ITEMID_START;
      82                 :            : 
      83                 :            : 
      84                 :       1104 : BmkMenu_Impl::BmkMenu_Impl() :
      85                 :       1104 :     m_bInitialized(sal_False)
      86                 :            : {
      87                 :       1104 : }
      88                 :            : 
      89                 :       1104 : BmkMenu_Impl::~BmkMenu_Impl()
      90                 :            : {
      91                 :       1104 : }
      92                 :            : 
      93                 :      13248 : sal_uInt16 BmkMenu_Impl::GetMID()
      94                 :            : {
      95                 :      13248 :     m_nMID++;
      96         [ -  + ]:      13248 :     if( !m_nMID )
      97                 :          0 :         m_nMID = BMKMENU_ITEMID_START;
      98                 :      13248 :     return m_nMID;
      99                 :            : }
     100                 :            : 
     101                 :            : // ------------------------------------------------------------------------
     102                 :            : 
     103                 :       1104 : BmkMenu::BmkMenu( Reference< XFrame >& xFrame, BmkMenu::BmkMenuType nType )
     104                 :            :     :AddonMenu(xFrame)
     105                 :       1104 :     ,m_nType( nType )
     106                 :            : {
     107         [ +  - ]:       1104 :     _pImp = new BmkMenu_Impl();
     108         [ +  - ]:       1104 :     Initialize();
     109                 :       1104 : }
     110                 :            : 
     111                 :       1104 : BmkMenu::~BmkMenu()
     112                 :            : {
     113         [ +  - ]:       1104 :     delete _pImp;
     114         [ -  + ]:       2208 : }
     115                 :            : 
     116                 :       1104 : void BmkMenu::Initialize()
     117                 :            : {
     118                 :            :     RTL_LOGFILE_CONTEXT( aLog, "framework (cd100003) ::BmkMenu::Initialize" );
     119                 :            : 
     120         [ +  - ]:       1104 :     if( _pImp->m_bInitialized )
     121                 :       1104 :         return;
     122                 :            : 
     123                 :       1104 :     _pImp->m_bInitialized = sal_True;
     124                 :            : 
     125         [ +  - ]:       1104 :     Sequence< Sequence< PropertyValue > > aDynamicMenuEntries;
     126                 :            : 
     127         [ +  - ]:       1104 :     if ( m_nType == BmkMenu::BMK_NEWMENU )
     128 [ +  - ][ +  - ]:       1104 :         aDynamicMenuEntries = SvtDynamicMenuOptions().GetMenu( E_NEWMENU );
         [ +  - ][ +  - ]
                 [ +  - ]
     129         [ #  # ]:          0 :     else if ( m_nType == BmkMenu::BMK_WIZARDMENU )
     130 [ #  # ][ #  # ]:          0 :         aDynamicMenuEntries = SvtDynamicMenuOptions().GetMenu( E_WIZARDMENU );
         [ #  # ][ #  # ]
                 [ #  # ]
     131                 :            : 
     132         [ +  - ]:       1104 :     const StyleSettings& rSettings = Application::GetSettings().GetStyleSettings();
     133         [ +  - ]:       1104 :     sal_Bool bShowMenuImages = rSettings.GetUseImagesInMenus();
     134                 :            : 
     135                 :       1104 :     ::rtl::OUString aTitle;
     136                 :       1104 :     ::rtl::OUString aURL;
     137                 :       1104 :     ::rtl::OUString aTargetFrame;
     138                 :       1104 :     ::rtl::OUString aImageId;
     139                 :            : 
     140                 :       1104 :     sal_uInt32 i, nCount = aDynamicMenuEntries.getLength();
     141         [ +  + ]:      17664 :     for ( i = 0; i < nCount; ++i )
     142                 :            :     {
     143 [ +  - ][ +  - ]:      16560 :         GetMenuEntry( aDynamicMenuEntries[i], aTitle, aURL, aTargetFrame, aImageId );
     144                 :            : 
     145 [ +  + ][ -  + ]:      16560 :         if ( aTitle.isEmpty() && aURL.isEmpty() )
                 [ -  + ]
     146                 :          0 :             continue;
     147                 :            : 
     148 [ +  - ][ +  + ]:      16560 :         if ( aURL == ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "private:separator" )))
     149         [ +  - ]:       3312 :             InsertSeparator();
     150                 :            :         else
     151                 :            :         {
     152                 :      13248 :             sal_Bool    bImageSet = sal_False;
     153         [ +  - ]:      13248 :             sal_uInt16      nId = CreateMenuId();
     154                 :            : 
     155         [ +  - ]:      13248 :             if ( bShowMenuImages )
     156                 :            :             {
     157         [ +  + ]:      13248 :                 if ( !aImageId.isEmpty() )
     158                 :            :                 {
     159         [ +  - ]:       4416 :                     Image aImage = GetImageFromURL( m_xFrame, aImageId, false );
     160         [ +  + ]:       4416 :                     if ( !!aImage )
     161                 :            :                     {
     162                 :       3312 :                         bImageSet = sal_True;
     163 [ +  - ][ +  - ]:       3312 :                         InsertItem( nId, aTitle, aImage );
                 [ +  - ]
     164         [ +  - ]:       4416 :                     }
     165                 :            :                 }
     166                 :            : 
     167         [ +  + ]:      13248 :                 if ( !bImageSet )
     168                 :            :                 {
     169         [ +  - ]:       9936 :                     Image aImage = GetImageFromURL( m_xFrame, aURL, false );
     170         [ +  + ]:       9936 :                     if ( !aImage )
     171 [ +  - ][ +  - ]:          2 :                         InsertItem( nId, aTitle );
                 [ +  - ]
     172                 :            :                     else
     173 [ +  - ][ +  - ]:       9936 :                         InsertItem( nId, aTitle, aImage );
         [ +  - ][ +  - ]
     174                 :            :                 }
     175                 :            :             }
     176                 :            :             else
     177 [ #  # ][ #  # ]:          0 :                 InsertItem( nId, aTitle );
                 [ #  # ]
     178                 :            : 
     179 [ +  - ][ +  - ]:      13248 :             MenuConfiguration::Attributes* pUserAttributes = new MenuConfiguration::Attributes( aTargetFrame, aImageId );
     180         [ +  - ]:      13248 :             SetUserValue( nId, (sal_uIntPtr)pUserAttributes );
     181                 :            : 
     182 [ +  - ][ +  - ]:      13248 :             SetItemCommand( nId, aURL );
                 [ +  - ]
     183                 :            :         }
     184         [ +  - ]:       1104 :     }
     185                 :            : }
     186                 :            : 
     187                 :      13248 : sal_uInt16 BmkMenu::CreateMenuId()
     188                 :            : {
     189                 :      13248 :     return BmkMenu_Impl::GetMID();
     190                 :            : }
     191                 :            : 
     192                 :      16560 : void GetMenuEntry
     193                 :            : (
     194                 :            :     Sequence< PropertyValue >& aDynamicMenuEntry,
     195                 :            :     ::rtl::OUString& rTitle,
     196                 :            :     ::rtl::OUString& rURL,
     197                 :            :     ::rtl::OUString& rFrame,
     198                 :            :     ::rtl::OUString& rImageId
     199                 :            : )
     200                 :            : {
     201         [ +  + ]:      82800 :     for ( int i = 0; i < aDynamicMenuEntry.getLength(); i++ )
     202                 :            :     {
     203 [ +  - ][ +  + ]:      66240 :         if ( aDynamicMenuEntry[i].Name == DYNAMICMENU_PROPERTYNAME_URL )
     204                 :      16560 :             aDynamicMenuEntry[i].Value >>= rURL;
     205 [ +  - ][ +  + ]:      49680 :         else if ( aDynamicMenuEntry[i].Name == DYNAMICMENU_PROPERTYNAME_TITLE )
     206                 :      16560 :             aDynamicMenuEntry[i].Value >>= rTitle;
     207 [ +  - ][ +  + ]:      33120 :         else if ( aDynamicMenuEntry[i].Name == DYNAMICMENU_PROPERTYNAME_IMAGEIDENTIFIER )
     208                 :      16560 :             aDynamicMenuEntry[i].Value >>= rImageId;
     209 [ +  - ][ +  - ]:      16560 :         else if ( aDynamicMenuEntry[i].Name == DYNAMICMENU_PROPERTYNAME_TARGETNAME )
     210                 :      16560 :             aDynamicMenuEntry[i].Value >>= rFrame;
     211                 :            :     }
     212                 :      16560 : }
     213                 :            : 
     214                 :            : }
     215                 :            : 
     216                 :            : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */

Generated by: LCOV version 1.10