LCOV - code coverage report
Current view: top level - framework/source/fwe/classes - bmkmenu.cxx (source / functions) Hit Total Coverage
Test: commit c8344322a7af75b84dd3ca8f78b05543a976dfd5 Lines: 66 72 91.7 %
Date: 2015-06-13 12:38:46 Functions: 9 9 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         606 : BmkMenu_Impl::BmkMenu_Impl() :
      74         606 :     m_bInitialized(false)
      75             : {
      76         606 : }
      77             : 
      78         606 : BmkMenu_Impl::~BmkMenu_Impl()
      79             : {
      80         606 : }
      81             : 
      82        7272 : sal_uInt16 BmkMenu_Impl::GetMID()
      83             : {
      84        7272 :     m_nMID++;
      85        7272 :     if( !m_nMID )
      86           0 :         m_nMID = BMKMENU_ITEMID_START;
      87        7272 :     return m_nMID;
      88             : }
      89             : 
      90         606 : BmkMenu::BmkMenu( Reference< XFrame >& xFrame, BmkMenu::BmkMenuType nType )
      91             :     :AddonMenu(xFrame)
      92         606 :     ,m_nType( nType )
      93             : {
      94         606 :     _pImp = new BmkMenu_Impl();
      95         606 :     Initialize();
      96         606 : }
      97             : 
      98        1818 : BmkMenu::~BmkMenu()
      99             : {
     100         606 :     delete _pImp;
     101        1212 : }
     102             : 
     103         606 : void BmkMenu::Initialize()
     104             : {
     105             :     SAL_INFO( "fwk", "framework (cd100003) ::BmkMenu::Initialize" );
     106             : 
     107         606 :     if( _pImp->m_bInitialized )
     108         606 :         return;
     109             : 
     110         606 :     _pImp->m_bInitialized = true;
     111             : 
     112         606 :     Sequence< Sequence< PropertyValue > > aDynamicMenuEntries;
     113             : 
     114         606 :     if ( m_nType == BmkMenu::BMK_NEWMENU )
     115         606 :         aDynamicMenuEntries = SvtDynamicMenuOptions().GetMenu( E_NEWMENU );
     116           0 :     else if ( m_nType == BmkMenu::BMK_WIZARDMENU )
     117           0 :         aDynamicMenuEntries = SvtDynamicMenuOptions().GetMenu( E_WIZARDMENU );
     118             : 
     119         606 :     const StyleSettings& rSettings = Application::GetSettings().GetStyleSettings();
     120         606 :     bool bShowMenuImages = rSettings.GetUseImagesInMenus();
     121             : 
     122        1212 :     OUString aTitle;
     123        1212 :     OUString aURL;
     124        1212 :     OUString aTargetFrame;
     125        1212 :     OUString aImageId;
     126             : 
     127         606 :     sal_uInt32 i, nCount = aDynamicMenuEntries.getLength();
     128        9696 :     for ( i = 0; i < nCount; ++i )
     129             :     {
     130        9090 :         GetMenuEntry( aDynamicMenuEntries[i], aTitle, aURL, aTargetFrame, aImageId );
     131             : 
     132        9090 :         if ( aTitle.isEmpty() && aURL.isEmpty() )
     133           0 :             continue;
     134             : 
     135        9090 :         if ( aURL == "private:separator" )
     136        1818 :             InsertSeparator();
     137             :         else
     138             :         {
     139        7272 :             sal_uInt16      nId = CreateMenuId();
     140             : 
     141        7272 :             if ( bShowMenuImages )
     142             :             {
     143        7272 :                 bool    bImageSet = false;
     144             : 
     145        7272 :                 if ( !aImageId.isEmpty() )
     146             :                 {
     147        2424 :                     Image aImage = GetImageFromURL( m_xFrame, aImageId, false );
     148        2424 :                     if ( !!aImage )
     149             :                     {
     150        1818 :                         bImageSet = true;
     151        1818 :                         InsertItem( nId, aTitle, aImage );
     152        2424 :                     }
     153             :                 }
     154             : 
     155        7272 :                 if ( !bImageSet )
     156             :                 {
     157        5454 :                     Image aImage = GetImageFromURL( m_xFrame, aURL, false );
     158        5454 :                     if ( !aImage )
     159           0 :                         InsertItem( nId, aTitle );
     160             :                     else
     161        5454 :                         InsertItem( nId, aTitle, aImage );
     162             :                 }
     163             :             }
     164             :             else
     165           0 :                 InsertItem( nId, aTitle );
     166             : 
     167        7272 :             sal_uIntPtr nAttributePtr = MenuAttributes::CreateAttribute(aTargetFrame, aImageId);
     168        7272 :             SetUserValue(nId, nAttributePtr, MenuAttributes::ReleaseAttribute);
     169             : 
     170        7272 :             SetItemCommand( nId, aURL );
     171             :         }
     172         606 :     }
     173             : }
     174             : 
     175        7272 : sal_uInt16 BmkMenu::CreateMenuId()
     176             : {
     177        7272 :     return BmkMenu_Impl::GetMID();
     178             : }
     179             : 
     180        9090 : void GetMenuEntry
     181             : (
     182             :     Sequence< PropertyValue >& aDynamicMenuEntry,
     183             :     OUString& rTitle,
     184             :     OUString& rURL,
     185             :     OUString& rFrame,
     186             :     OUString& rImageId
     187             : )
     188             : {
     189       45450 :     for ( int i = 0; i < aDynamicMenuEntry.getLength(); i++ )
     190             :     {
     191       36360 :         if ( aDynamicMenuEntry[i].Name == DYNAMICMENU_PROPERTYNAME_URL )
     192        9090 :             aDynamicMenuEntry[i].Value >>= rURL;
     193       27270 :         else if ( aDynamicMenuEntry[i].Name == DYNAMICMENU_PROPERTYNAME_TITLE )
     194        9090 :             aDynamicMenuEntry[i].Value >>= rTitle;
     195       18180 :         else if ( aDynamicMenuEntry[i].Name == DYNAMICMENU_PROPERTYNAME_IMAGEIDENTIFIER )
     196        9090 :             aDynamicMenuEntry[i].Value >>= rImageId;
     197        9090 :         else if ( aDynamicMenuEntry[i].Name == DYNAMICMENU_PROPERTYNAME_TARGETNAME )
     198        9090 :             aDynamicMenuEntry[i].Value >>= rFrame;
     199             :     }
     200        9090 : }
     201             : 
     202             : }
     203             : 
     204             : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */

Generated by: LCOV version 1.11