1 #include "xltoolbar.hxx"
2 #include <rtl/ustrbuf.hxx>
4 #include <com/sun/star/ui/XUIConfigurationPersistence.hpp>
5 #include <com/sun/star/ui/XUIConfigurationPersistence.hpp>
6 #include <com/sun/star/ui/XModuleUIConfigurationManagerSupplier.hpp>
7 #include <com/sun/star/lang/XMultiServiceFactory.hpp>
8 #include <com/sun/star/lang/XSingleComponentFactory.hpp>
9 #include <com/sun/star/lang/XMultiComponentFactory.hpp>
10 #include <com/sun/star/ui/XImageManager.hpp>
11 #include <com/sun/star/ui/ItemType.hpp>
13 #include <comphelper/processfactory.hxx>
14 #include <vcl/graph.hxx>
16 using namespace com::sun::star
;
18 typedef std::map
< sal_Int16
, rtl::OUString
> IdToString
;
20 class MSOExcelCommandConvertor
: public MSOCommandConvertor
22 IdToString msoToOOcmd
;
23 IdToString tcidToOOcmd
;
25 MSOExcelCommandConvertor();
26 virtual rtl::OUString
MSOCommandToOOCommand( sal_Int16 msoCmd
);
27 virtual rtl::OUString
MSOTCIDToOOCommand( sal_Int16 key
);
30 MSOExcelCommandConvertor::MSOExcelCommandConvertor()
33 // mso command id to ooo command string
34 // #FIXME and *HUNDREDS* of id's to added here
35 msoToOOcmd[ 0x20b ] = rtl::OUString( RTL_CONSTASCII_USTRINGPARAM(".uno:CloseDoc") );
36 msoToOOcmd[ 0x50 ] = rtl::OUString( RTL_CONSTASCII_USTRINGPARAM(".uno:Open") );
38 // mso tcid to ooo command string
39 // #FIXME and *HUNDREDS* of id's to added here
40 tcidToOOcmd[ 0x9d9 ] = rtl::OUString( RTL_CONSTASCII_USTRINGPARAM(".uno:Print") );
44 rtl::OUString
MSOExcelCommandConvertor::MSOCommandToOOCommand( sal_Int16 key
)
46 rtl::OUString sResult
;
47 IdToString::iterator it
= msoToOOcmd
.find( key
);
48 if ( it
!= msoToOOcmd
.end() )
53 rtl::OUString
MSOExcelCommandConvertor::MSOTCIDToOOCommand( sal_Int16 key
)
55 rtl::OUString sResult
;
56 IdToString::iterator it
= tcidToOOcmd
.find( key
);
57 if ( it
!= tcidToOOcmd
.end() )
64 CTBS::CTBS() : bSignature(0), bVersion(0), reserved1(0), reserved2(0), reserved3(0), ctb(0), ctbViews(0), ictbView(0)
68 CTB::CTB() : nViews( 0 ), ectbid(0)
72 CTB::CTB(sal_uInt16 nNum
) : nViews( nNum
), ectbid(0)
76 bool CTB::Read( SvStream
*pS
)
78 OSL_TRACE("CTB::Read() stream pos 0x%x", pS
->Tell() );
81 for ( sal_uInt16 index
= 0; index
< nViews
; ++index
)
83 TBVisualData aVisData
;
85 rVisualData
.push_back( aVisData
);
89 for ( sal_Int16 index
= 0; index
< tb
.getcCL(); ++index
)
93 rTBC
.push_back( aTBC
);
98 void CTB::Print( FILE* fp
)
101 indent_printf( fp
, "[ 0x%x ] CTB -- dump\n", nOffSet
);
102 indent_printf( fp
, " nViews 0x%x\n", nViews
);
105 std::vector
<TBVisualData
>::iterator visData_end
= rVisualData
.end();
106 sal_Int32 counter
= 0;
107 for ( std::vector
<TBVisualData
>::iterator it
= rVisualData
.begin(); it
!= visData_end
; ++it
)
110 indent_printf( fp
, " TBVisualData [%d]\n", counter
++ );
114 indent_printf( fp
, " ectbid 0x%x\n", ectbid
);
115 std::vector
<TBC
>::iterator it_end
= rTBC
.end();
117 for ( std::vector
<TBC
>::iterator it
= rTBC
.begin(); it
!= it_end
; ++it
)
119 indent_printf( fp
, " TBC [%d]\n", counter
++);
125 bool CTB::IsMenuToolbar()
127 return tb
.IsMenuToolbar();
130 bool CTB::ImportMenuTB( CTBWrapper
& rWrapper
, const css::uno::Reference
< css::container::XIndexContainer
>& xMenuDesc
, CustomToolBarImportHelper
& helper
)
133 for ( std::vector
< TBC
>::iterator it
= rTBC
.begin(); it
!= rTBC
.end(); ++it
, ++index
)
135 if ( !it
->ImportToolBarControl( rWrapper
, xMenuDesc
, helper
, IsMenuToolbar() ) )
141 bool CTB::ImportCustomToolBar( CTBWrapper
& rWrapper
, CustomToolBarImportHelper
& helper
)
144 static rtl::OUString
sToolbarPrefix( RTL_CONSTASCII_USTRINGPARAM( "private:resource/toolbar/custom_" ) );
148 if ( !tb
.IsEnabled() )
149 return true; // didn't fail, just ignoring
151 // Create default setting
152 uno::Reference
< container::XIndexContainer
> xIndexContainer( helper
.getCfgManager()->createSettings(), uno::UNO_QUERY_THROW
);
153 uno::Reference
< container::XIndexAccess
> xIndexAccess( xIndexContainer
, uno::UNO_QUERY_THROW
);
154 uno::Reference
< beans::XPropertySet
> xProps( xIndexContainer
, uno::UNO_QUERY_THROW
);
155 WString
& name
= tb
.getName();
156 // set UI name for toolbar
157 xProps
->setPropertyValue( rtl::OUString( RTL_CONSTASCII_USTRINGPARAM("UIName") ), uno::makeAny( name
.getString() ) );
159 rtl::OUString sToolBarName
= sToolbarPrefix
.concat( name
.getString() );
160 for ( std::vector
< TBC
>::iterator it
= rTBC
.begin(); it
!= rTBC
.end(); ++it
)
162 if ( !it
->ImportToolBarControl( rWrapper
, xIndexContainer
, helper
, IsMenuToolbar() ) )
166 OSL_TRACE("Name of toolbar :-/ %s", rtl::OUStringToOString( sToolBarName
, RTL_TEXTENCODING_UTF8
).getStr() );
168 helper
.getCfgManager()->insertSettings( sToolBarName
, xIndexAccess
);
171 uno::Reference
< ui::XUIConfigurationPersistence
> xPersistence( helper
.getCfgManager()->getImageManager(), uno::UNO_QUERY_THROW
);
172 xPersistence
->store();
174 xPersistence
.set( helper
.getCfgManager(), uno::UNO_QUERY_THROW
);
175 xPersistence
->store();
180 catch( uno::Exception
& )
186 bool CTBS::Read( SvStream
*pS
)
188 OSL_TRACE("CTBS::Read() stream pos 0x%x", pS
->Tell() );
189 nOffSet
= pS
->Tell();
190 *pS
>> bSignature
>> bVersion
>> reserved1
>> reserved2
>> reserved3
>> ctb
>> ctbViews
>> ictbView
;
194 void CTBS::Print( FILE* fp
)
197 indent_printf( fp
, "[ 0x%x ] CTBS -- dump\n", nOffSet
);
199 indent_printf( fp
, " bSignature 0x%x\n", bSignature
);
200 indent_printf( fp
, " bVersion 0x%x\n", bVersion
);
202 indent_printf( fp
, " reserved1 0x%x\n", reserved1
);
203 indent_printf( fp
, " reserved2 0x%x\n", reserved2
);
204 indent_printf( fp
, " reserved3 0x%x\n", reserved3
);
206 indent_printf( fp
, " ctb 0x%x\n", ctb
);
207 indent_printf( fp
, " ctbViews 0x%x\n", ctbViews
);
208 indent_printf( fp
, " ictbView 0x%x\n", ictbView
);
216 TBC::Read(SvStream
*pS
)
218 OSL_TRACE("TBC::Read() stream pos 0x%x", pS
->Tell() );
219 nOffSet
= pS
->Tell();
220 if ( !tbch
.Read( pS
) )
222 sal_uInt16 tcid
= tbch
.getTcID();
223 sal_uInt8 tct
= tbch
.getTct();
224 if ( ( tcid
!= 0x0001 && tcid
!= 0x06CC && tcid
!= 0x03D8 && tcid
!= 0x03EC && tcid
!= 0x1051 ) && ( ( tct
> 0 && tct
< 0x0B ) || ( ( tct
> 0x0B && tct
< 0x10 ) || tct
== 0x15 ) ) )
226 tbcCmd
.reset( new TBCCmd
);
227 if ( ! tbcCmd
->Read( pS
) )
232 tbcd
.reset( new TBCData( tbch
) );
233 if ( !tbcd
->Read( pS
) )
244 indent_printf( fp
, "[ 0x%x ] TBC -- dump\n", nOffSet
);
252 bool TBC::ImportToolBarControl( CTBWrapper
& rWrapper
, const css::uno::Reference
< css::container::XIndexContainer
>& toolbarcontainer
, CustomToolBarImportHelper
& helper
, bool bIsMenuToolbar
)
254 // how to identify built-in-command ?
255 // bool bBuiltin = false;
258 std::vector
< css::beans::PropertyValue
> props
;
262 rtl::OUString sCommand = helper.MSOCommandToOOCommand( cmdId );
263 if ( sCommand.getLength() > 0 )
265 beans::PropertyValue aProp;
267 aProp.Name = rtl::OUString( RTL_CONSTASCII_USTRINGPARAM("CommandURL") );
268 aProp.Value <<= sCommand;
269 props.push_back( aProp );
274 bool bBeginGroup
= false;
275 if ( ! tbcd
->ImportToolBarControl( helper
, props
, bBeginGroup
, bIsMenuToolbar
) )
277 TBCMenuSpecific
* pMenu
= tbcd
->getMenuSpecific();
280 // search for CTB with the appropriate name ( it contains the
281 // menu items, although we cannot import ( or create ) a menu on
282 // a custom toolbar we can import the menu items in a separate
283 // toolbar ( better than nothing )
284 CTB
* pCustTB
= rWrapper
.GetCustomizationData( pMenu
->Name() );
287 uno::Reference
< container::XIndexContainer
> xMenuDesc
;
288 uno::Reference
< lang::XMultiServiceFactory
> xMSF( ::comphelper::getProcessServiceFactory(), uno::UNO_QUERY_THROW
);
289 xMenuDesc
.set( xMSF
->createInstance( rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "com.sun.star.document.IndexedPropertyValues" ) ) ), uno::UNO_QUERY_THROW
);
290 if ( !pCustTB
->ImportMenuTB( rWrapper
, xMenuDesc
, helper
) )
292 OSL_TRACE("*** Read menu, no. items is %d", xMenuDesc
->getCount() );
293 beans::PropertyValue aProp
;
295 aProp
.Name
= rtl::OUString( RTL_CONSTASCII_USTRINGPARAM("ItemDescriptorContainer") );
296 aProp
.Value
<<= xMenuDesc
;
297 props
.push_back( aProp
);
304 uno::Sequence
< beans::PropertyValue
> sProps( 1 );
305 sProps
[ 0 ].Name
= rtl::OUString( RTL_CONSTASCII_USTRINGPARAM("Type") );
306 sProps
[ 0 ].Value
= uno::makeAny( ui::ItemType::SEPARATOR_LINE
);
307 toolbarcontainer
->insertByIndex( toolbarcontainer
->getCount(), uno::makeAny( sProps
) );
309 uno::Sequence
< beans::PropertyValue
> sProps( props
.size() );
310 beans::PropertyValue
* pProp
= sProps
.getArray();
312 for ( std::vector
< css::beans::PropertyValue
>::iterator it
= props
.begin(); it
!= props
.end(); ++it
, ++pProp
)
315 toolbarcontainer
->insertByIndex( toolbarcontainer
->getCount(), uno::makeAny( sProps
) );
321 TBCCmd::Print(FILE* fp
)
324 indent_printf( fp
, " TBCCmd -- dump\n" );
325 indent_printf( fp
, " cmdID 0x%x\n", cmdID
);
326 indent_printf( fp
, " A ( fHideDrawing ) %s\n", A
? "true" : "false" );
327 indent_printf( fp
, " B ( reserved - ignored ) %s\n", A
? "true" : "false" );
328 indent_printf( fp
, " cmdType 0x%x\n", cmdType
);
329 indent_printf( fp
, " C ( reserved - ignored ) %s\n", A
? "true" : "false" );
330 indent_printf( fp
, " reserved3 0x%x\n", reserved3
);
333 bool TBCCmd::Read( SvStream
*pS
)
335 OSL_TRACE("TBCCmd::Read() stream pos 0x%x", pS
->Tell() );
336 nOffSet
= pS
->Tell();
340 OSL_TRACE("TBCmd temp = 0x%x", temp
);
341 A
= (temp
& 0x8000 ) == 0x8000;
342 B
= (temp
& 0x4000) == 0x4000;
343 cmdType
= ( temp
& 0x3E00 ) >> 9;
344 C
= ( temp
& 0x100 ) == 0x100;
345 reserved3
= ( temp
& 0xFF );
349 CTBWrapper::CTBWrapper()
353 CTBWrapper::~CTBWrapper()
358 CTBWrapper::Read( SvStream
*pS
)
360 OSL_TRACE("CTBWrapper::Read() stream pos 0x%x", pS
->Tell() );
361 nOffSet
= pS
->Tell();
362 if ( !ctbSet
.Read( pS
) )
364 for ( sal_uInt16 index
= 0; index
< ctbSet
.ctb
; ++index
)
366 CTB
aCTB( ctbSet
.ctbViews
);
367 if ( !aCTB
.Read( pS
) )
369 rCTB
.push_back( aCTB
);
375 CTBWrapper::Print( FILE* fp
)
378 indent_printf( fp
, "[ 0x%x ] CTBWrapper -- dump\n", nOffSet
);
380 std::vector
<CTB
>::iterator it_end
= rCTB
.end();
381 for ( std::vector
<CTB
>::iterator it
= rCTB
.begin(); it
!= it_end
; ++it
)
388 CTB
* CTBWrapper::GetCustomizationData( const rtl::OUString
& sTBName
)
391 for ( std::vector
< CTB
>::iterator it
= rCTB
.begin(); it
!= rCTB
.end(); ++it
)
393 if ( it
->GetName().equals( sTBName
) )
402 bool CTBWrapper::ImportCustomToolBar( SfxObjectShell
& rDocSh
)
404 std::vector
<CTB
>::iterator it_end
= rCTB
.end();
405 for ( std::vector
<CTB
>::iterator it
= rCTB
.begin(); it
!= it_end
; ++it
)
407 // for each customtoolbar
408 uno::Reference
< lang::XMultiServiceFactory
> xMSF( ::comphelper::getProcessServiceFactory(), uno::UNO_QUERY_THROW
);
409 uno::Reference
< ui::XModuleUIConfigurationManagerSupplier
> xAppCfgSupp( xMSF
->createInstance( rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "com.sun.star.ui.ModuleUIConfigurationManagerSupplier" ) ) ), uno::UNO_QUERY_THROW
);
410 CustomToolBarImportHelper
helper( rDocSh
, xAppCfgSupp
->getUIConfigurationManager( rtl::OUString( RTL_CONSTASCII_USTRINGPARAM("com.sun.star.sheet.SpreadsheetDocument" ) ) ) );
411 helper
.setMSOCommandMap( new MSOExcelCommandConvertor() );
412 // Ignore menu toolbars, excel doesn't ( afaics ) store
413 // menu customizations ( but you can have menus in a customtoolbar
414 // such menus will be dealt with when they are encountered
415 // as part of importing the appropriate MenuSpecific toolbar control )
418 if ( !(*it
).IsMenuToolbar() )
420 if ( !(*it
).ImportCustomToolBar( *this, helper
) )