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

Generated by: LCOV version 1.10