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

Generated by: LCOV version 1.10