LCOV - code coverage report
Current view: top level - sc/source/filter/excel - xltoolbar.cxx (source / functions) Hit Total Coverage
Test: commit e02a6cb2c3e2b23b203b422e4e0680877f232636 Lines: 0 227 0.0 %
Date: 2014-04-14 Functions: 0 27 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             : #include "xltoolbar.hxx"
      10             : #include <rtl/ustrbuf.hxx>
      11             : #include <stdarg.h>
      12             : #include <com/sun/star/document/IndexedPropertyValues.hpp>
      13             : #include <com/sun/star/ui/XUIConfigurationPersistence.hpp>
      14             : #include <com/sun/star/ui/theModuleUIConfigurationManagerSupplier.hpp>
      15             : #include <com/sun/star/lang/XMultiServiceFactory.hpp>
      16             : #include <com/sun/star/lang/XSingleComponentFactory.hpp>
      17             : #include <com/sun/star/lang/XMultiComponentFactory.hpp>
      18             : #include <com/sun/star/ui/XImageManager.hpp>
      19             : #include <com/sun/star/ui/ItemType.hpp>
      20             : #include <fstream>
      21             : #include <comphelper/processfactory.hxx>
      22             : #include <vcl/graph.hxx>
      23             : #include <map>
      24             : using namespace com::sun::star;
      25             : 
      26             : typedef std::map< sal_Int16, OUString > IdToString;
      27             : 
      28           0 : class MSOExcelCommandConvertor : public MSOCommandConvertor
      29             : {
      30             :    IdToString msoToOOcmd;
      31             :    IdToString tcidToOOcmd;
      32             : public:
      33             :     MSOExcelCommandConvertor();
      34             :     virtual OUString MSOCommandToOOCommand( sal_Int16 msoCmd ) SAL_OVERRIDE;
      35             :     virtual OUString MSOTCIDToOOCommand( sal_Int16 key ) SAL_OVERRIDE;
      36             : };
      37             : 
      38           0 : MSOExcelCommandConvertor::MSOExcelCommandConvertor()
      39             : {
      40             : /*
      41             :     // mso command id to ooo command string
      42             :     // #FIXME and *HUNDREDS* of id's to added here
      43             :     msoToOOcmd[ 0x20b ] = ".uno:CloseDoc";
      44             :     msoToOOcmd[ 0x50 ] = ".uno:Open";
      45             : 
      46             :    // mso tcid to ooo command string
      47             :     // #FIXME and *HUNDREDS* of id's to added here
      48             :    tcidToOOcmd[ 0x9d9 ] = ".uno:Print";
      49             : */
      50           0 : }
      51             : 
      52           0 : OUString MSOExcelCommandConvertor::MSOCommandToOOCommand( sal_Int16 key )
      53             : {
      54           0 :     OUString sResult;
      55           0 :     IdToString::iterator it = msoToOOcmd.find( key );
      56           0 :     if ( it != msoToOOcmd.end() )
      57           0 :         sResult = it->second;
      58           0 :     return sResult;
      59             : }
      60             : 
      61           0 : OUString MSOExcelCommandConvertor::MSOTCIDToOOCommand( sal_Int16 key )
      62             : {
      63           0 :     OUString sResult;
      64           0 :     IdToString::iterator it = tcidToOOcmd.find( key );
      65           0 :     if ( it != tcidToOOcmd.end() )
      66           0 :         sResult = it->second;
      67           0 :     return sResult;
      68             : }
      69             : 
      70           0 : CTBS::CTBS() : bSignature(0), bVersion(0), reserved1(0), reserved2(0), reserved3(0), ctb(0), ctbViews(0), ictbView(0)
      71             : {
      72           0 : }
      73             : 
      74           0 : ScCTB::ScCTB(sal_uInt16 nNum ) : nViews( nNum ), ectbid(0)
      75             : {
      76           0 : }
      77             : 
      78           0 : bool ScCTB::Read( SvStream &rS )
      79             : {
      80             :     OSL_TRACE("ScCTB::Read() stream pos 0x%x", rS.Tell() );
      81           0 :     nOffSet = rS.Tell();
      82           0 :     tb.Read( rS );
      83           0 :     for ( sal_uInt16 index = 0; index < nViews; ++index )
      84             :     {
      85           0 :         TBVisualData aVisData;
      86           0 :         aVisData.Read( rS );
      87           0 :         rVisualData.push_back( aVisData );
      88           0 :     }
      89           0 :     rS.ReadUInt32( ectbid );
      90             : 
      91           0 :     for ( sal_Int16 index = 0; index < tb.getcCL(); ++index )
      92             :     {
      93           0 :         ScTBC aTBC;
      94           0 :         aTBC.Read( rS );
      95           0 :         rTBC.push_back( aTBC );
      96           0 :     }
      97           0 :     return true;
      98             : }
      99             : 
     100           0 : void ScCTB::Print( FILE* fp )
     101             : {
     102           0 :     Indent a;
     103           0 :     indent_printf( fp, "[ 0x%x ] ScCTB -- dump\n", nOffSet );
     104           0 :     indent_printf( fp, "  nViews 0x%x\n", nViews);
     105           0 :     tb.Print( fp );
     106             : 
     107           0 :     std::vector<TBVisualData>::iterator visData_end = rVisualData.end();
     108           0 :     sal_Int32 counter = 0;
     109           0 :     for ( std::vector<TBVisualData>::iterator it = rVisualData.begin(); it != visData_end; ++it )
     110             :     {
     111             : 
     112           0 :         indent_printf( fp, "  TBVisualData [%d]\n", counter++ );
     113           0 :         Indent b;
     114           0 :         it->Print( fp );
     115           0 :     }
     116           0 :     indent_printf( fp, "  ectbid 0x%x\n", ectbid);
     117           0 :     std::vector<ScTBC>::iterator it_end = rTBC.end();
     118           0 :     counter = 0;
     119           0 :     for ( std::vector<ScTBC>::iterator it = rTBC.begin(); it != it_end; ++it )
     120             :     {
     121           0 :         indent_printf( fp, "  ScTBC [%d]\n", counter++);
     122           0 :         Indent c;
     123           0 :         it->Print( fp );
     124           0 :     }
     125           0 : }
     126             : 
     127           0 : bool ScCTB::IsMenuToolbar()
     128             : {
     129           0 :     return tb.IsMenuToolbar();
     130             : }
     131             : 
     132           0 : bool ScCTB::ImportMenuTB( ScCTBWrapper& rWrapper, const css::uno::Reference< css::container::XIndexContainer >& xMenuDesc, CustomToolBarImportHelper& helper )
     133             : {
     134           0 :     sal_Int32 index = 0;
     135           0 :     for ( std::vector< ScTBC >::iterator it =  rTBC.begin(); it != rTBC.end(); ++it, ++index )
     136             :     {
     137           0 :         if ( !it->ImportToolBarControl( rWrapper, xMenuDesc, helper, IsMenuToolbar() ) )
     138           0 :             return false;
     139             :     }
     140           0 :     return true;
     141             : }
     142             : 
     143           0 : bool ScCTB::ImportCustomToolBar( ScCTBWrapper& rWrapper, CustomToolBarImportHelper& helper )
     144             : {
     145             : 
     146           0 :     static OUString sToolbarPrefix( "private:resource/toolbar/custom_" );
     147           0 :     bool bRes = false;
     148             :     try
     149             :     {
     150           0 :         if ( !tb.IsEnabled() )
     151           0 :             return true;  // didn't fail, just ignoring
     152             : 
     153             :         // Create default setting
     154           0 :         uno::Reference< container::XIndexContainer > xIndexContainer( helper.getCfgManager()->createSettings(), uno::UNO_QUERY_THROW );
     155           0 :         uno::Reference< container::XIndexAccess > xIndexAccess( xIndexContainer, uno::UNO_QUERY_THROW );
     156           0 :         uno::Reference< beans::XPropertySet > xProps( xIndexContainer, uno::UNO_QUERY_THROW );
     157           0 :         WString& name = tb.getName();
     158             :         // set UI name for toolbar
     159           0 :         xProps->setPropertyValue("UIName", uno::makeAny( name.getString() ) );
     160             : 
     161           0 :         OUString sToolBarName = sToolbarPrefix.concat( name.getString() );
     162           0 :         for ( std::vector< ScTBC >::iterator it =  rTBC.begin(); it != rTBC.end(); ++it )
     163             :         {
     164           0 :             if ( !it->ImportToolBarControl( rWrapper, xIndexContainer, helper, IsMenuToolbar() ) )
     165           0 :                 return false;
     166             :         }
     167             : 
     168             :         OSL_TRACE("Name of toolbar :-/ %s", OUStringToOString( sToolBarName, RTL_TEXTENCODING_UTF8 ).getStr() );
     169             : 
     170           0 :         helper.getCfgManager()->insertSettings( sToolBarName, xIndexAccess );
     171           0 :         helper.applyIcons();
     172             : 
     173           0 :         uno::Reference< ui::XUIConfigurationPersistence > xPersistence( helper.getCfgManager()->getImageManager(), uno::UNO_QUERY_THROW );
     174           0 :         xPersistence->store();
     175             : 
     176           0 :         xPersistence.set( helper.getCfgManager(), uno::UNO_QUERY_THROW );
     177           0 :         xPersistence->store();
     178             : 
     179           0 :         bRes = true;
     180             :     }
     181           0 :     catch( uno::Exception& )
     182             :     {
     183           0 :        bRes = false;
     184             :     }
     185           0 :     return bRes;
     186             : }
     187           0 : bool CTBS::Read( SvStream &rS )
     188             : {
     189             :     OSL_TRACE("CTBS::Read() stream pos 0x%x", rS.Tell() );
     190           0 :     nOffSet = rS.Tell();
     191           0 :     rS.ReadUChar( bSignature ).ReadUChar( bVersion ).ReadUInt16( reserved1 ).ReadUInt16( reserved2 ).ReadUInt16( reserved3 ).ReadUInt16( ctb ).ReadUInt16( ctbViews ).ReadUInt16( ictbView );
     192           0 :     return true;
     193             : }
     194             : 
     195           0 : void CTBS::Print( FILE* fp )
     196             : {
     197           0 :     Indent a;
     198           0 :     indent_printf( fp, "[ 0x%x ] CTBS -- dump\n", nOffSet );
     199             : 
     200           0 :     indent_printf( fp, "  bSignature 0x%x\n", bSignature);
     201           0 :     indent_printf( fp, "  bVersion 0x%x\n", bVersion);
     202             : 
     203           0 :     indent_printf( fp, "  reserved1 0x%x\n", reserved1 );
     204           0 :     indent_printf( fp, "  reserved2 0x%x\n", reserved2 );
     205           0 :     indent_printf( fp, "  reserved3 0x%x\n", reserved3 );
     206             : 
     207           0 :     indent_printf( fp, "  ctb 0x%x\n", ctb );
     208           0 :     indent_printf( fp, "  ctbViews 0x%x\n", ctbViews );
     209           0 :     indent_printf( fp, "  ictbView 0x%x\n", ictbView );
     210           0 : }
     211             : 
     212           0 : ScTBC::ScTBC()
     213             : {
     214           0 : }
     215             : 
     216             : bool
     217           0 : ScTBC::Read(SvStream &rS)
     218             : {
     219             :     OSL_TRACE("ScTBC::Read() stream pos 0x%x", rS.Tell() );
     220           0 :     nOffSet = rS.Tell();
     221           0 :     if ( !tbch.Read( rS ) )
     222           0 :         return false;
     223           0 :     sal_uInt16 tcid = tbch.getTcID();
     224           0 :     sal_uInt8 tct = tbch.getTct();
     225           0 :     if (  ( tcid != 0x0001 && tcid != 0x06CC && tcid != 0x03D8 && tcid != 0x03EC && tcid != 0x1051 ) && ( ( tct > 0 && tct < 0x0B ) || ( ( tct > 0x0B && tct < 0x10 ) || tct == 0x15 ) ) )
     226             :     {
     227           0 :         tbcCmd.reset( new TBCCmd );
     228           0 :         if ( !  tbcCmd->Read( rS ) )
     229           0 :             return false;
     230             :     }
     231           0 :     if ( tct != 0x16 )
     232             :     {
     233           0 :         tbcd.reset( new TBCData( tbch ) );
     234           0 :         if ( !tbcd->Read( rS ) )
     235           0 :             return false;
     236             :     }
     237           0 :     return true;
     238             : }
     239             : 
     240             : 
     241             : void
     242           0 : ScTBC::Print(FILE* fp)
     243             : {
     244           0 :     Indent a;
     245           0 :     indent_printf( fp, "[ 0x%x ] ScTBC -- dump\n", nOffSet );
     246           0 :     tbch.Print( fp );
     247           0 :     if ( tbcCmd.get() )
     248           0 :         tbcCmd->Print( fp );
     249           0 :     if ( tbcd.get() )
     250           0 :         tbcd->Print( fp );
     251           0 : }
     252             : 
     253           0 : bool ScTBC::ImportToolBarControl( ScCTBWrapper& rWrapper, const css::uno::Reference< css::container::XIndexContainer >& toolbarcontainer, CustomToolBarImportHelper& helper, bool bIsMenuToolbar )
     254             : {
     255             :     // how to identify built-in-command ?
     256             : //    bool bBuiltin = false;
     257           0 :     if ( tbcd.get() )
     258             :     {
     259           0 :         std::vector< css::beans::PropertyValue > props;
     260           0 :         bool bBeginGroup = false;
     261           0 :         if ( ! tbcd->ImportToolBarControl( helper, props, bBeginGroup, bIsMenuToolbar ) )
     262           0 :             return false;
     263           0 :         TBCMenuSpecific* pMenu = tbcd->getMenuSpecific();
     264           0 :         if ( pMenu )
     265             :         {
     266             :             // search for ScCTB with the appropriate name ( it contains the
     267             :             // menu items, although we cannot import ( or create ) a menu on
     268             :             // a custom toolbar we can import the menu items in a separate
     269             :             // toolbar ( better than nothing )
     270           0 :             ScCTB* pCustTB = rWrapper.GetCustomizationData( pMenu->Name() );
     271           0 :             if ( pCustTB )
     272             :             {
     273           0 :                  uno::Reference< container::XIndexContainer > xMenuDesc = document::IndexedPropertyValues::create( comphelper::getProcessComponentContext() );
     274           0 :                  if ( !pCustTB->ImportMenuTB( rWrapper, xMenuDesc, helper ) )
     275           0 :                      return false;
     276           0 :                  if ( !bIsMenuToolbar )
     277             :                  {
     278           0 :                      if ( !helper.createMenu( pMenu->Name(), uno::Reference< container::XIndexAccess >( xMenuDesc, uno::UNO_QUERY ), true ) )
     279           0 :                          return false;
     280             :                  }
     281             :                  else
     282             :                  {
     283           0 :                      beans::PropertyValue aProp;
     284           0 :                      aProp.Name = "ItemDescriptorContainer";
     285           0 :                      aProp.Value <<= xMenuDesc;
     286           0 :                      props.push_back( aProp );
     287           0 :                  }
     288             :             }
     289             :         }
     290             : 
     291           0 :         if ( bBeginGroup )
     292             :         {
     293             :             // insert spacer
     294           0 :             uno::Sequence< beans::PropertyValue > sProps( 1 );
     295           0 :             sProps[ 0 ].Name = "Type";
     296           0 :             sProps[ 0 ].Value = uno::makeAny( ui::ItemType::SEPARATOR_LINE );
     297           0 :             toolbarcontainer->insertByIndex( toolbarcontainer->getCount(), uno::makeAny( sProps ) );
     298             :         }
     299           0 :         uno::Sequence< beans::PropertyValue > sProps( props.size() );
     300           0 :         beans::PropertyValue* pProp = sProps.getArray();
     301             : 
     302           0 :         for ( std::vector< css::beans::PropertyValue >::iterator it = props.begin(); it != props.end(); ++it, ++pProp )
     303           0 :             *pProp = *it;
     304             : 
     305           0 :         toolbarcontainer->insertByIndex( toolbarcontainer->getCount(), uno::makeAny( sProps ) );
     306             :     }
     307           0 :     return true;
     308             : }
     309             : 
     310             : void
     311           0 : TBCCmd::Print(FILE* fp)
     312             : {
     313           0 :     Indent a;
     314           0 :     indent_printf( fp, " TBCCmd -- dump\n" );
     315           0 :     indent_printf( fp, "   cmdID 0x%x\n", cmdID );
     316           0 :     indent_printf( fp, "   A ( fHideDrawing ) %s\n", A ? "true" : "false" );
     317           0 :     indent_printf( fp, "   B ( reserved - ignored ) %s\n", A ? "true" : "false" );
     318           0 :     indent_printf( fp, "   cmdType 0x%x\n", cmdType );
     319           0 :     indent_printf( fp, "   C ( reserved - ignored ) %s\n", A ? "true" : "false" );
     320           0 :     indent_printf( fp, "   reserved3 0x%x\n", reserved3 );
     321           0 : }
     322             : 
     323           0 : bool TBCCmd::Read( SvStream &rS )
     324             : {
     325             :     OSL_TRACE("TBCCmd::Read() stream pos 0x%x", rS.Tell() );
     326           0 :     nOffSet = rS.Tell();
     327           0 :     rS.ReadUInt16( cmdID );
     328             :     sal_uInt16 temp;
     329           0 :     rS.ReadUInt16( temp );
     330             :     OSL_TRACE("TBCmd temp = 0x%x", temp );
     331           0 :     A = (temp & 0x8000 ) == 0x8000;
     332           0 :     B = (temp & 0x4000) == 0x4000;
     333           0 :     cmdType = ( temp & 0x3E00 ) >> 9;
     334           0 :     C = ( temp & 0x100 ) == 0x100;
     335           0 :     reserved3 = ( temp & 0xFF );
     336           0 :     return true;
     337             : }
     338             : 
     339           0 : ScCTBWrapper::ScCTBWrapper()
     340             : {
     341           0 : }
     342             : 
     343           0 : ScCTBWrapper::~ScCTBWrapper()
     344             : {
     345           0 : }
     346             : 
     347             : bool
     348           0 : ScCTBWrapper::Read( SvStream &rS)
     349             : {
     350             :     OSL_TRACE("ScCTBWrapper::Read() stream pos 0x%x", rS.Tell() );
     351           0 :     nOffSet = rS.Tell();
     352           0 :     if ( !ctbSet.Read( rS ) )
     353           0 :         return false;
     354           0 :     for ( sal_uInt16 index = 0; index < ctbSet.ctb; ++index )
     355             :     {
     356           0 :         ScCTB aCTB( ctbSet.ctbViews );
     357           0 :         if ( !aCTB.Read( rS ) )
     358           0 :             return false;
     359           0 :         rCTB.push_back( aCTB );
     360           0 :     }
     361           0 :     return true;
     362             : }
     363             : 
     364             : void
     365           0 : ScCTBWrapper::Print( FILE* fp )
     366             : {
     367           0 :     Indent a;
     368           0 :     indent_printf( fp, "[ 0x%x ] ScCTBWrapper -- dump\n", nOffSet );
     369           0 :     ctbSet.Print( fp );
     370           0 :     std::vector<ScCTB>::iterator it_end = rCTB.end();
     371           0 :     for ( std::vector<ScCTB>::iterator it = rCTB.begin(); it != it_end; ++it )
     372             :     {
     373           0 :         Indent b;
     374           0 :         it->Print( fp );
     375           0 :     }
     376           0 : }
     377             : 
     378           0 : ScCTB* ScCTBWrapper::GetCustomizationData( const OUString& sTBName )
     379             : {
     380           0 :     ScCTB* pCTB = NULL;
     381           0 :     for ( std::vector< ScCTB >::iterator it = rCTB.begin(); it != rCTB.end(); ++it )
     382             :     {
     383           0 :         if ( it->GetName().equals( sTBName ) )
     384             :         {
     385           0 :             pCTB = &(*it);
     386           0 :             break;
     387             :         }
     388             :     }
     389           0 :     return pCTB;
     390             : }
     391             : 
     392           0 : bool ScCTBWrapper::ImportCustomToolBar( SfxObjectShell& rDocSh )
     393             : {
     394           0 :     if(rCTB.empty())
     395           0 :         return true;
     396             : 
     397           0 :     uno::Reference< uno::XComponentContext > xContext( ::comphelper::getProcessComponentContext() );
     398           0 :     uno::Reference< ui::XModuleUIConfigurationManagerSupplier > xAppCfgSupp( ui::theModuleUIConfigurationManagerSupplier::get(xContext) );
     399             : 
     400           0 :     std::vector<ScCTB>::iterator it_end = rCTB.end();
     401           0 :     for ( std::vector<ScCTB>::iterator it = rCTB.begin(); it != it_end; ++it )
     402             :     {
     403             :         // for each customtoolbar
     404           0 :         CustomToolBarImportHelper helper( rDocSh, xAppCfgSupp->getUIConfigurationManager( OUString("com.sun.star.sheet.SpreadsheetDocument" ) ) );
     405           0 :         helper.setMSOCommandMap( new  MSOExcelCommandConvertor() );
     406             :         // Ignore menu toolbars, excel doesn't ( afaics ) store
     407             :         // menu customizations ( but you can have menus in a customtoolbar
     408             :         // such menus will be dealt with when they are encountered
     409             :         // as part of importing the appropriate MenuSpecific toolbar control )
     410             : 
     411             : 
     412           0 :         if ( !(*it).IsMenuToolbar() )
     413             :         {
     414           0 :             if ( !(*it).ImportCustomToolBar( *this, helper ) )
     415           0 :                 return false;
     416             :         }
     417           0 :     }
     418           0 :     return true;
     419             : }
     420             : 
     421             : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */

Generated by: LCOV version 1.10