LCOV - code coverage report
Current view: top level - framework/source/fwe/classes - bmkmenu.cxx (source / functions) Hit Total Coverage
Test: commit 10e77ab3ff6f4314137acd6e2702a6e5c1ce1fae Lines: 68 73 93.2 %
Date: 2014-11-03 Functions: 11 11 100.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 <limits.h>
      21             : 
      22             : #include <framework/bmkmenu.hxx>
      23             : #include <general.h>
      24             : #include <framework/imageproducer.hxx>
      25             : #include <framework/menuconfiguration.hxx>
      26             : 
      27             : #include <com/sun/star/uno/Reference.h>
      28             : #include <com/sun/star/util/URL.hpp>
      29             : #include <com/sun/star/beans/PropertyValue.hpp>
      30             : #include <comphelper/processfactory.hxx>
      31             : #include <com/sun/star/util/XURLTransformer.hpp>
      32             : #include <com/sun/star/lang/XMultiServiceFactory.hpp>
      33             : #include <com/sun/star/util/DateTime.hpp>
      34             : 
      35             : #include <vcl/svapp.hxx>
      36             : #include <vcl/settings.hxx>
      37             : #include <unotools/dynamicmenuoptions.hxx>
      38             : #include <svtools/menuoptions.hxx>
      39             : 
      40             : using namespace ::comphelper;
      41             : using namespace ::com::sun::star::uno;
      42             : using namespace ::com::sun::star::lang;
      43             : using namespace ::com::sun::star::util;
      44             : using namespace ::com::sun::star::frame;
      45             : using namespace ::com::sun::star::beans;
      46             : 
      47             : namespace framework
      48             : {
      49             : 
      50             : void GetMenuEntry(
      51             :     Sequence< PropertyValue >&  aDynamicMenuEntry,
      52             :     OUString&            rTitle,
      53             :     OUString&            rURL,
      54             :     OUString&            rFrame,
      55             :     OUString&            rImageId );
      56             : 
      57             : class BmkMenu_Impl
      58             : {
      59             :     private:
      60             :         static sal_uInt16        m_nMID;
      61             : 
      62             :     public:
      63             :         bool                 m_bInitialized;
      64             : 
      65             :         BmkMenu_Impl();
      66             :         ~BmkMenu_Impl();
      67             : 
      68             :         static sal_uInt16       GetMID();
      69             : };
      70             : 
      71             : sal_uInt16 BmkMenu_Impl::m_nMID = BMKMENU_ITEMID_START;
      72             : 
      73        1494 : BmkMenu_Impl::BmkMenu_Impl() :
      74        1494 :     m_bInitialized(false)
      75             : {
      76        1494 : }
      77             : 
      78        1494 : BmkMenu_Impl::~BmkMenu_Impl()
      79             : {
      80        1494 : }
      81             : 
      82       17928 : sal_uInt16 BmkMenu_Impl::GetMID()
      83             : {
      84       17928 :     m_nMID++;
      85       17928 :     if( !m_nMID )
      86           0 :         m_nMID = BMKMENU_ITEMID_START;
      87       17928 :     return m_nMID;
      88             : }
      89             : 
      90        1494 : BmkMenu::BmkMenu( Reference< XFrame >& xFrame, BmkMenu::BmkMenuType nType )
      91             :     :AddonMenu(xFrame)
      92        1494 :     ,m_nType( nType )
      93             : {
      94        1494 :     _pImp = new BmkMenu_Impl();
      95        1494 :     Initialize();
      96        1494 : }
      97             : 
      98        4482 : BmkMenu::~BmkMenu()
      99             : {
     100        1494 :     delete _pImp;
     101        2988 : }
     102             : 
     103        1494 : void BmkMenu::Initialize()
     104             : {
     105             :     SAL_INFO( "fwk", "framework (cd100003) ::BmkMenu::Initialize" );
     106             : 
     107        1494 :     if( _pImp->m_bInitialized )
     108        1494 :         return;
     109             : 
     110        1494 :     _pImp->m_bInitialized = true;
     111             : 
     112        1494 :     Sequence< Sequence< PropertyValue > > aDynamicMenuEntries;
     113             : 
     114        1494 :     if ( m_nType == BmkMenu::BMK_NEWMENU )
     115        1494 :         aDynamicMenuEntries = SvtDynamicMenuOptions().GetMenu( E_NEWMENU );
     116           0 :     else if ( m_nType == BmkMenu::BMK_WIZARDMENU )
     117           0 :         aDynamicMenuEntries = SvtDynamicMenuOptions().GetMenu( E_WIZARDMENU );
     118             : 
     119        1494 :     const StyleSettings& rSettings = Application::GetSettings().GetStyleSettings();
     120        1494 :     bool bShowMenuImages = rSettings.GetUseImagesInMenus();
     121             : 
     122        2988 :     OUString aTitle;
     123        2988 :     OUString aURL;
     124        2988 :     OUString aTargetFrame;
     125        2988 :     OUString aImageId;
     126             : 
     127        1494 :     sal_uInt32 i, nCount = aDynamicMenuEntries.getLength();
     128       23904 :     for ( i = 0; i < nCount; ++i )
     129             :     {
     130       22410 :         GetMenuEntry( aDynamicMenuEntries[i], aTitle, aURL, aTargetFrame, aImageId );
     131             : 
     132       22410 :         if ( aTitle.isEmpty() && aURL.isEmpty() )
     133           0 :             continue;
     134             : 
     135       22410 :         if ( aURL == "private:separator" )
     136        4482 :             InsertSeparator();
     137             :         else
     138             :         {
     139       17928 :             bool    bImageSet = false;
     140       17928 :             sal_uInt16      nId = CreateMenuId();
     141             : 
     142       17928 :             if ( bShowMenuImages )
     143             :             {
     144       17928 :                 if ( !aImageId.isEmpty() )
     145             :                 {
     146        5976 :                     Image aImage = GetImageFromURL( m_xFrame, aImageId, false );
     147        5976 :                     if ( !!aImage )
     148             :                     {
     149        4482 :                         bImageSet = true;
     150        4482 :                         InsertItem( nId, aTitle, aImage );
     151        5976 :                     }
     152             :                 }
     153             : 
     154       17928 :                 if ( !bImageSet )
     155             :                 {
     156       13446 :                     Image aImage = GetImageFromURL( m_xFrame, aURL, false );
     157       13446 :                     if ( !aImage )
     158          36 :                         InsertItem( nId, aTitle );
     159             :                     else
     160       13410 :                         InsertItem( nId, aTitle, aImage );
     161             :                 }
     162             :             }
     163             :             else
     164           0 :                 InsertItem( nId, aTitle );
     165             : 
     166       17928 :             MenuConfiguration::Attributes* pUserAttributes = new MenuConfiguration::Attributes( aTargetFrame, aImageId );
     167       17928 :             SetUserValue( nId, reinterpret_cast<sal_uIntPtr>(pUserAttributes) );
     168             : 
     169       17928 :             SetItemCommand( nId, aURL );
     170             :         }
     171        1494 :     }
     172             : }
     173             : 
     174       17928 : sal_uInt16 BmkMenu::CreateMenuId()
     175             : {
     176       17928 :     return BmkMenu_Impl::GetMID();
     177             : }
     178             : 
     179       22410 : void GetMenuEntry
     180             : (
     181             :     Sequence< PropertyValue >& aDynamicMenuEntry,
     182             :     OUString& rTitle,
     183             :     OUString& rURL,
     184             :     OUString& rFrame,
     185             :     OUString& rImageId
     186             : )
     187             : {
     188      112050 :     for ( int i = 0; i < aDynamicMenuEntry.getLength(); i++ )
     189             :     {
     190       89640 :         if ( aDynamicMenuEntry[i].Name == DYNAMICMENU_PROPERTYNAME_URL )
     191       22410 :             aDynamicMenuEntry[i].Value >>= rURL;
     192       67230 :         else if ( aDynamicMenuEntry[i].Name == DYNAMICMENU_PROPERTYNAME_TITLE )
     193       22410 :             aDynamicMenuEntry[i].Value >>= rTitle;
     194       44820 :         else if ( aDynamicMenuEntry[i].Name == DYNAMICMENU_PROPERTYNAME_IMAGEIDENTIFIER )
     195       22410 :             aDynamicMenuEntry[i].Value >>= rImageId;
     196       22410 :         else if ( aDynamicMenuEntry[i].Name == DYNAMICMENU_PROPERTYNAME_TARGETNAME )
     197       22410 :             aDynamicMenuEntry[i].Value >>= rFrame;
     198             :     }
     199       22410 : }
     200             : 
     201         969 : }
     202             : 
     203             : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */

Generated by: LCOV version 1.10