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: 0 72 0.0 %
Date: 2012-12-27 Functions: 0 9 0.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           0 : BmkMenu_Impl::BmkMenu_Impl() :
      76           0 :     m_bInitialized(sal_False)
      77             : {
      78           0 : }
      79             : 
      80           0 : BmkMenu_Impl::~BmkMenu_Impl()
      81             : {
      82           0 : }
      83             : 
      84           0 : sal_uInt16 BmkMenu_Impl::GetMID()
      85             : {
      86           0 :     m_nMID++;
      87           0 :     if( !m_nMID )
      88           0 :         m_nMID = BMKMENU_ITEMID_START;
      89           0 :     return m_nMID;
      90             : }
      91             : 
      92             : // ------------------------------------------------------------------------
      93             : 
      94           0 : BmkMenu::BmkMenu( Reference< XFrame >& xFrame, BmkMenu::BmkMenuType nType )
      95             :     :AddonMenu(xFrame)
      96           0 :     ,m_nType( nType )
      97             : {
      98           0 :     _pImp = new BmkMenu_Impl();
      99           0 :     Initialize();
     100           0 : }
     101             : 
     102           0 : BmkMenu::~BmkMenu()
     103             : {
     104           0 :     delete _pImp;
     105           0 : }
     106             : 
     107           0 : void BmkMenu::Initialize()
     108             : {
     109             :     RTL_LOGFILE_CONTEXT( aLog, "framework (cd100003) ::BmkMenu::Initialize" );
     110             : 
     111           0 :     if( _pImp->m_bInitialized )
     112           0 :         return;
     113             : 
     114           0 :     _pImp->m_bInitialized = sal_True;
     115             : 
     116           0 :     Sequence< Sequence< PropertyValue > > aDynamicMenuEntries;
     117             : 
     118           0 :     if ( m_nType == BmkMenu::BMK_NEWMENU )
     119           0 :         aDynamicMenuEntries = SvtDynamicMenuOptions().GetMenu( E_NEWMENU );
     120           0 :     else if ( m_nType == BmkMenu::BMK_WIZARDMENU )
     121           0 :         aDynamicMenuEntries = SvtDynamicMenuOptions().GetMenu( E_WIZARDMENU );
     122             : 
     123           0 :     const StyleSettings& rSettings = Application::GetSettings().GetStyleSettings();
     124           0 :     sal_Bool bShowMenuImages = rSettings.GetUseImagesInMenus();
     125             : 
     126           0 :     ::rtl::OUString aTitle;
     127           0 :     ::rtl::OUString aURL;
     128           0 :     ::rtl::OUString aTargetFrame;
     129           0 :     ::rtl::OUString aImageId;
     130             : 
     131           0 :     sal_uInt32 i, nCount = aDynamicMenuEntries.getLength();
     132           0 :     for ( i = 0; i < nCount; ++i )
     133             :     {
     134           0 :         GetMenuEntry( aDynamicMenuEntries[i], aTitle, aURL, aTargetFrame, aImageId );
     135             : 
     136           0 :         if ( aTitle.isEmpty() && aURL.isEmpty() )
     137           0 :             continue;
     138             : 
     139           0 :         if ( aURL == ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "private:separator" )))
     140           0 :             InsertSeparator();
     141             :         else
     142             :         {
     143           0 :             sal_Bool    bImageSet = sal_False;
     144           0 :             sal_uInt16      nId = CreateMenuId();
     145             : 
     146           0 :             if ( bShowMenuImages )
     147             :             {
     148           0 :                 if ( !aImageId.isEmpty() )
     149             :                 {
     150           0 :                     Image aImage = GetImageFromURL( m_xFrame, aImageId, false );
     151           0 :                     if ( !!aImage )
     152             :                     {
     153           0 :                         bImageSet = sal_True;
     154           0 :                         InsertItem( nId, aTitle, aImage );
     155           0 :                     }
     156             :                 }
     157             : 
     158           0 :                 if ( !bImageSet )
     159             :                 {
     160           0 :                     Image aImage = GetImageFromURL( m_xFrame, aURL, false );
     161           0 :                     if ( !aImage )
     162           0 :                         InsertItem( nId, aTitle );
     163             :                     else
     164           0 :                         InsertItem( nId, aTitle, aImage );
     165             :                 }
     166             :             }
     167             :             else
     168           0 :                 InsertItem( nId, aTitle );
     169             : 
     170           0 :             MenuConfiguration::Attributes* pUserAttributes = new MenuConfiguration::Attributes( aTargetFrame, aImageId );
     171           0 :             SetUserValue( nId, (sal_uIntPtr)pUserAttributes );
     172             : 
     173           0 :             SetItemCommand( nId, aURL );
     174             :         }
     175           0 :     }
     176             : }
     177             : 
     178           0 : sal_uInt16 BmkMenu::CreateMenuId()
     179             : {
     180           0 :     return BmkMenu_Impl::GetMID();
     181             : }
     182             : 
     183           0 : 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           0 :     for ( int i = 0; i < aDynamicMenuEntry.getLength(); i++ )
     193             :     {
     194           0 :         if ( aDynamicMenuEntry[i].Name == DYNAMICMENU_PROPERTYNAME_URL )
     195           0 :             aDynamicMenuEntry[i].Value >>= rURL;
     196           0 :         else if ( aDynamicMenuEntry[i].Name == DYNAMICMENU_PROPERTYNAME_TITLE )
     197           0 :             aDynamicMenuEntry[i].Value >>= rTitle;
     198           0 :         else if ( aDynamicMenuEntry[i].Name == DYNAMICMENU_PROPERTYNAME_IMAGEIDENTIFIER )
     199           0 :             aDynamicMenuEntry[i].Value >>= rImageId;
     200           0 :         else if ( aDynamicMenuEntry[i].Name == DYNAMICMENU_PROPERTYNAME_TARGETNAME )
     201           0 :             aDynamicMenuEntry[i].Value >>= rFrame;
     202             :     }
     203           0 : }
     204             : 
     205             : }
     206             : 
     207             : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */

Generated by: LCOV version 1.10