1 #include "ww8toolbar.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 // no. of visual data elements in a CTB ( fixed )
19 const short nVisualData
= 5;
21 typedef std::map
< sal_Int16
, rtl::OUString
> IdToString
;
23 class MSOWordCommandConvertor
: public MSOCommandConvertor
25 IdToString msoToOOcmd
;
26 IdToString tcidToOOcmd
;
28 MSOWordCommandConvertor();
29 virtual rtl::OUString
MSOCommandToOOCommand( sal_Int16 msoCmd
);
30 virtual rtl::OUString
MSOTCIDToOOCommand( sal_Int16 key
);
33 MSOWordCommandConvertor::MSOWordCommandConvertor()
35 // mso command id to ooo command string
36 // #FIXME and *HUNDREDS* of id's to added here
37 msoToOOcmd
[ 0x20b ] = rtl::OUString( RTL_CONSTASCII_USTRINGPARAM(".uno:CloseDoc") );
38 msoToOOcmd
[ 0x50 ] = rtl::OUString( RTL_CONSTASCII_USTRINGPARAM(".uno:Open") );
40 // mso tcid to ooo command string
41 // #FIXME and *HUNDREDS* of id's to added here
42 tcidToOOcmd
[ 0x9d9 ] = rtl::OUString( RTL_CONSTASCII_USTRINGPARAM(".uno:Print") );
45 rtl::OUString
MSOWordCommandConvertor::MSOCommandToOOCommand( sal_Int16 key
)
47 rtl::OUString sResult
;
48 IdToString::iterator it
= msoToOOcmd
.find( key
);
49 if ( it
!= msoToOOcmd
.end() )
54 rtl::OUString
MSOWordCommandConvertor::MSOTCIDToOOCommand( sal_Int16 key
)
56 rtl::OUString sResult
;
57 IdToString::iterator it
= tcidToOOcmd
.find( key
);
58 if ( it
!= tcidToOOcmd
.end() )
64 CTBWrapper::CTBWrapper( bool bReadId
) : Tcg255SubStruct( bReadId
)
76 CTBWrapper::~CTBWrapper()
80 Customization
* CTBWrapper::GetCustomizaton( sal_Int16 index
)
82 if ( index
< 0 || index
>= rCustomizations
.size() )
84 return &rCustomizations
[ index
];
87 CTB
* CTBWrapper::GetCustomizationData( const rtl::OUString
& sTBName
)
90 for ( std::vector
< Customization
>::iterator it
= rCustomizations
.begin(); it
!= rCustomizations
.end(); ++it
)
92 if ( it
->GetCustomizationData() && it
->GetCustomizationData()->GetName().equals( sTBName
) )
94 pCTB
= it
->GetCustomizationData();
101 bool CTBWrapper::Read( SvStream
* pS
)
103 OSL_TRACE("CTBWrapper::Read() stream pos 0x%x", pS
->Tell() );
104 nOffSet
= pS
->Tell();
105 Tcg255SubStruct::Read( pS
);
106 *pS
>> reserved2
>> reserved3
>> reserved4
>> reserved5
;
107 *pS
>> cbTBD
>> cCust
>> cbDTBC
;
110 // cbDTBC is the size in bytes of the TBC array
111 // but the size of a TBC element is dynamic ( and this relates to TBDelta's
112 int nStart
= pS
->Tell();
115 int bytesToRead
= cbDTBC
- bytesRead
;
116 // cbDTBC specifies the size ( in bytes ) taken by an array ( of unspecified size )
117 // of TBC records ( TBC records have dynamic length, so we need to check our position
122 if ( !aTBC
.Read( pS
) )
124 rtbdc
.push_back( aTBC
);
125 bytesToRead
= cbDTBC
- ( pS
->Tell() - nStart
);
126 } while ( bytesToRead
> 0 );
130 for ( sal_Int32 index
= 0; index
< cCust
; ++index
)
132 Customization
aCust( this );
133 if ( !aCust
.Read( pS
) )
135 rCustomizations
.push_back( aCust
);
138 std::vector
< sal_Int16
>::iterator it_end
= dropDownMenuIndices
.end();
139 for ( std::vector
< sal_Int16
>::iterator it
= dropDownMenuIndices
.begin(); it
!= it_end
; ++it
)
141 rCustomizations
[ *it
].bIsDroppedMenuTB
= true;
146 TBC
* CTBWrapper::GetTBCAtOffset( sal_uInt32 nStreamOffset
)
148 for ( std::vector
< TBC
>::iterator it
= rtbdc
.begin(); it
!= rtbdc
.end(); ++it
)
150 if ( (*it
).GetOffset() == nStreamOffset
)
156 void CTBWrapper::Print( FILE* fp
)
159 indent_printf(fp
,"[ 0x%x ] CTBWrapper - dump\n", nOffSet
);
160 bool bRes
= ( ch
== 0x12 && reserved2
== 0x0 && reserved3
== 0x7 && reserved4
== 0x6 && reserved5
== 0xC );
162 indent_printf(fp
," sanity check ( first 8 bytes conform )\n");
165 indent_printf(fp
," reserved1(0x%x)\n",ch
);
166 indent_printf(fp
," reserved2(0x%x)\n",reserved2
);
167 indent_printf(fp
," reserved3(0x%x)\n",reserved3
);
168 indent_printf(fp
," reserved4(0x%x)\n",reserved4
);
169 indent_printf(fp
," reserved5(0x%x)\n",reserved5
);
170 indent_printf(fp
,"Quiting dump");
173 indent_printf(fp
," size of TBDelta structures 0x%x\n", cbTBD
);
174 indent_printf(fp
," cCust: no. of cCust structures 0x%x\n",cCust
);
175 indent_printf(fp
," cbDTBC: no. of bytes in rtbdc array 0x%x\n", static_cast< unsigned int >( cbDTBC
));
179 for ( std::vector
< TBC
>::iterator it
= rtbdc
.begin(); it
!= rtbdc
.end(); ++it
, ++index
)
181 indent_printf(fp
," Dumping rtbdc[%d]\n", static_cast< int >( index
));
188 for ( std::vector
< Customization
>::iterator it
= rCustomizations
.begin(); it
!= rCustomizations
.end(); ++it
, ++index
)
190 indent_printf(fp
," Dumping custimization [%d]\n", static_cast< int >( index
));
196 bool CTBWrapper::ImportCustomToolBar( SfxObjectShell
& rDocSh
)
198 for ( std::vector
< Customization
>::iterator it
= rCustomizations
.begin(); it
!= rCustomizations
.end(); ++it
)
200 uno::Reference
< lang::XMultiServiceFactory
> xMSF( ::comphelper::getProcessServiceFactory(), uno::UNO_QUERY_THROW
);
201 uno::Reference
< ui::XModuleUIConfigurationManagerSupplier
> xAppCfgSupp( xMSF
->createInstance( rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "com.sun.star.ui.ModuleUIConfigurationManagerSupplier" ) ) ), uno::UNO_QUERY_THROW
);
202 CustomToolBarImportHelper
helper( rDocSh
, xAppCfgSupp
->getUIConfigurationManager( rtl::OUString( RTL_CONSTASCII_USTRINGPARAM("com.sun.star.text.TextDocument" ) ) ) );
203 helper
.setMSOCommandMap( new MSOWordCommandConvertor() );
205 if ( !(*it
).ImportCustomToolBar( *this, helper
) )
211 Customization::Customization( CTBWrapper
* wrapper
) : tbidForTBD( 0 )
214 , pWrapper( wrapper
)
215 , bIsDroppedMenuTB( false )
219 Customization::~Customization()
223 bool Customization::Read( SvStream
*pS
)
225 OSL_TRACE("Custimization::Read() stream pos 0x%x", pS
->Tell() );
226 nOffSet
= pS
->Tell();
227 *pS
>> tbidForTBD
>> reserved1
>> ctbds
;
230 for ( sal_Int32 index
= 0; index
< ctbds
; ++index
)
233 if (!aTBDelta
.Read( pS
) )
235 customizationDataTBDelta
.push_back( aTBDelta
);
236 // Only set the drop down for menu's associated with standard toolbar
237 if ( aTBDelta
.ControlDropsToolBar() && tbidForTBD
== 0x25 )
238 pWrapper
->InsertDropIndex( aTBDelta
.CustomizationIndex() );
243 customizationDataCTB
.reset( new CTB() );
244 if ( !customizationDataCTB
->Read( pS
) )
250 void Customization::Print( FILE* fp
)
253 indent_printf( fp
,"[ 0x%x ] Customization -- dump \n", nOffSet
);
254 indent_printf( fp
," tbidForTBD 0x%x ( should be 0 for CTBs )\n", static_cast< unsigned int >( tbidForTBD
));
255 indent_printf( fp
," reserved1 0x%x \n", reserved1
);
256 indent_printf( fp
," ctbds - number of customisations %d(0x%x) \n", ctbds
, ctbds
);
257 if ( !tbidForTBD
&& !ctbds
)
258 customizationDataCTB
->Print( fp
);
261 const char* pToolBar
= NULL
;
262 switch ( tbidForTBD
)
265 pToolBar
= "Standard";
268 pToolBar
= "Builtin-Menu";
271 pToolBar
= "Unknown toolbar";
275 indent_printf( fp
," TBDelta(s) are associated with %s toolbar.\n", pToolBar
);
276 std::vector
< TBDelta
>::iterator it
= customizationDataTBDelta
.begin();
277 for ( sal_Int32 index
= 0; index
< ctbds
; ++it
,++index
)
283 bool Customization::ImportMenu( CTBWrapper
& rWrapper
, CustomToolBarImportHelper
& helper
)
285 if ( tbidForTBD
== 0x25 ) // we can handle in a limited way additions the built-in menu bar
287 for ( std::vector
< TBDelta
>::iterator it
= customizationDataTBDelta
.begin(); it
!= customizationDataTBDelta
.end(); ++it
)
289 // for each new menu ( control that drops a toolbar )
291 if ( it
->ControlIsInserted() && it
->ControlDropsToolBar() )
293 Customization
* pCust
= pWrapper
->GetCustomizaton( it
->CustomizationIndex() );
296 // currently only support built-in menu
297 rtl::OUString
sMenuBar( RTL_CONSTASCII_USTRINGPARAM("private:resource/menubar/") );
299 sMenuBar
= sMenuBar
.concat( rtl::OUString( RTL_CONSTASCII_USTRINGPARAM("menubar") ) );
301 TBC
* pTBC
= pWrapper
->GetTBCAtOffset( it
->TBCStreamOffset() );
304 rtl::OUString sMenuName
= pTBC
->GetCustomText();
305 sMenuName
= sMenuName
.replace('&','~');
307 // see if the document has already setting for the menubar
309 uno::Reference
< container::XIndexContainer
> xIndexContainer
;
310 bool bHasSettings
= false;
311 if ( helper
.getCfgManager()->hasSettings( sMenuBar
) )
313 xIndexContainer
.set( helper
.getCfgManager()->getSettings( sMenuBar
, sal_True
), uno::UNO_QUERY_THROW
);
318 if ( helper
.getAppCfgManager()->hasSettings( sMenuBar
) )
319 xIndexContainer
.set( helper
.getAppCfgManager()->getSettings( sMenuBar
, sal_True
), uno::UNO_QUERY_THROW
);
321 xIndexContainer
.set( helper
.getAppCfgManager()->createSettings(), uno::UNO_QUERY_THROW
);
324 uno::Reference
< lang::XSingleComponentFactory
> xSCF( xIndexContainer
, uno::UNO_QUERY_THROW
);
325 uno::Reference
< beans::XPropertySet
> xProps( ::comphelper::getProcessServiceFactory(), uno::UNO_QUERY_THROW
);
326 uno::Reference
< uno::XComponentContext
> xContext( xProps
->getPropertyValue( rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "DefaultContext" ))), uno::UNO_QUERY_THROW
);
327 // create the popup menu
328 uno::Sequence
< beans::PropertyValue
> aPopupMenu( 4 );
329 aPopupMenu
[0].Name
= rtl::OUString( RTL_CONSTASCII_USTRINGPARAM("CommandURL") );
330 aPopupMenu
[0].Value
= uno::makeAny( rtl::OUString( RTL_CONSTASCII_USTRINGPARAM("vnd.openoffice.org:") ) + sMenuName
);
331 aPopupMenu
[1].Name
= rtl::OUString( RTL_CONSTASCII_USTRINGPARAM("Label") );
332 aPopupMenu
[1].Value
<<= sMenuName
;
333 aPopupMenu
[2].Name
= rtl::OUString( RTL_CONSTASCII_USTRINGPARAM("Type" ) );
334 aPopupMenu
[2].Value
<<= sal_Int32( 0 );
335 aPopupMenu
[3].Name
= rtl::OUString( RTL_CONSTASCII_USTRINGPARAM("ItemDescriptorContainer") );
336 uno::Reference
< container::XIndexContainer
> xMenuContainer( xSCF
->createInstanceWithContext( xContext
), uno::UNO_QUERY_THROW
);
337 aPopupMenu
[3].Value
<<= xMenuContainer
;
338 if ( pCust
->customizationDataCTB
.get() && !pCust
->customizationDataCTB
->ImportMenuTB( rWrapper
, xMenuContainer
, helper
) )
340 OSL_TRACE("** there are %d menu items on the bar, inserting after that", xIndexContainer
->getCount() );
341 xIndexContainer
->insertByIndex( xIndexContainer
->getCount(), uno::makeAny( aPopupMenu
) );
344 helper
.getCfgManager()->replaceSettings( sMenuBar
, uno::Reference
< container::XIndexAccess
>( xIndexContainer
, uno::UNO_QUERY_THROW
) );
346 helper
.getCfgManager()->insertSettings( sMenuBar
, uno::Reference
< container::XIndexAccess
>( xIndexContainer
, uno::UNO_QUERY_THROW
) );
347 uno::Reference
< ui::XUIConfigurationPersistence
> xPersistence( helper
.getCfgManager(), uno::UNO_QUERY_THROW
);
348 xPersistence
->store();
357 bool Customization::ImportCustomToolBar( CTBWrapper
& rWrapper
, CustomToolBarImportHelper
& helper
)
359 if ( GetTBIDForTB() == 0x25 )
360 return ImportMenu( rWrapper
, helper
);
361 if ( !customizationDataCTB
.get() )
363 if ( !customizationDataCTB
->IsMenuToolbar() )
365 if ( !customizationDataCTB
->ImportCustomToolBar( rWrapper
, helper
) )
371 TBDelta::TBDelta() : doprfatendFlags(0)
380 bool TBDelta::ControlIsModified()
382 return ( ( doprfatendFlags
& 0x3 ) == 0x2 );
385 bool TBDelta::ControlIsInserted()
387 return ( ( doprfatendFlags
& 0x3 ) == 0x1 );
390 bool TBDelta::ControlIsChanged()
392 return ( ( doprfatendFlags
& 0x3 ) == 0x1 );
395 bool TBDelta::ControlDropsToolBar()
397 return !( CiTBDE
& 0x8000 );
400 sal_Int32
TBDelta::TBCStreamOffset()
405 sal_Int16
TBDelta::CustomizationIndex()
407 sal_Int16 nIndex
= CiTBDE
;
408 nIndex
= nIndex
>> 1;
409 nIndex
&= 0x1ff; // only 13 bits are relevant
413 bool TBDelta::Read(SvStream
*pS
)
415 OSL_TRACE("TBDelta::Read() stream pos 0x%x", pS
->Tell() );
416 nOffSet
= pS
->Tell();
417 *pS
>> doprfatendFlags
>> ibts
>> cidNext
>> cid
>> fc
;
418 *pS
>> CiTBDE
>> cbTBC
;
422 void TBDelta::Print( FILE* fp
)
424 // Like most of the debug output, it's raw and little ( no )
425 // interpretation of the data is output ( e.g. flag values etc. )
426 indent_printf( fp
, "[ 0x%x ] TBDelta -- dump\n", nOffSet
);
427 indent_printf( fp
, " doprfatendFlags 0x%x\n",doprfatendFlags
);
429 indent_printf( fp
, " ibts 0x%x\n",ibts
);
430 indent_printf( fp
, " cidNext 0x%x\n", static_cast< unsigned int >( cidNext
) );
431 indent_printf( fp
, " cid 0x%x\n", static_cast< unsigned int >( cid
) );
432 indent_printf( fp
, " fc 0x%x\n", static_cast< unsigned int >( fc
) );
433 indent_printf( fp
, " CiTBDE 0x%x\n",CiTBDE
);
434 indent_printf( fp
, " cbTBC 0x%x\n", cbTBC
);
435 if ( ControlDropsToolBar() )
437 indent_printf( fp
, " this delta is associated with a control that drops a menu toolbar\n", cbTBC
);
438 indent_printf( fp
, " the menu toolbar drops the toolbar defined at index[%d] in the rCustomizations array of the CTBWRAPPER that contains this TBDelta\n", CustomizationIndex() );
442 CTB::CTB() : cbTBData( 0 )
454 bool CTB::IsMenuToolbar()
456 return tb
.IsMenuToolbar();
460 bool CTB::Read( SvStream
*pS
)
462 OSL_TRACE("CTB::Read() stream pos 0x%x", pS
->Tell() );
463 nOffSet
= pS
->Tell();
464 if ( !name
.Read( pS
) )
467 if ( !tb
.Read( pS
) )
469 for ( short index
= 0; index
< nVisualData
; ++index
)
471 TBVisualData aVisData
;
473 rVisualData
.push_back( aVisData
);
476 *pS
>> iWCTBl
>> reserved
>> unused
>> cCtls
;
480 for ( sal_Int32 index
= 0; index
< cCtls
; ++index
)
483 if ( !aTBC
.Read( pS
) )
485 rTBC
.push_back( aTBC
);
492 CTB::Print( FILE* fp
)
495 indent_printf(fp
, "[ 0x%x ] CTB - dump\n", nOffSet
);
496 indent_printf(fp
, " name %s\n", rtl::OUStringToOString( name
.getString(), RTL_TEXTENCODING_UTF8
).getStr() );
497 indent_printf(fp
, " cbTBData size, in bytes, of this structure excluding the name, cCtls, and rTBC fields. %x\n", static_cast< unsigned int >( cbTBData
) );
500 for ( short counter
= 0; counter
< nVisualData
; ++counter
)
502 indent_printf( fp
, " TBVisualData [%d]\n", counter
);
504 rVisualData
[ counter
].Print( fp
);
506 indent_printf(fp
, " iWCTBl 0x%x reserved 0x%x unused 0x%x cCtls( toolbar controls ) 0x%x \n", static_cast< unsigned int >( iWCTBl
), reserved
, unused
, static_cast< unsigned int >( cCtls
) );
509 for ( sal_Int32 index
= 0; index
< cCtls
; ++index
)
512 indent_printf(fp
, " dumping toolbar control 0x%x\n", static_cast< unsigned int >( index
) );
513 rTBC
[ index
].Print( fp
);
518 bool CTB::ImportCustomToolBar( CTBWrapper
& rWrapper
, CustomToolBarImportHelper
& helper
)
520 static rtl::OUString
sToolbarPrefix( RTL_CONSTASCII_USTRINGPARAM( "private:resource/toolbar/custom_" ) );
524 if ( !tb
.IsEnabled() )
525 return true; // didn't fail, just ignoring
526 // Create default setting
527 uno::Reference
< container::XIndexContainer
> xIndexContainer( helper
.getCfgManager()->createSettings(), uno::UNO_QUERY_THROW
);
528 uno::Reference
< container::XIndexAccess
> xIndexAccess( xIndexContainer
, uno::UNO_QUERY_THROW
);
529 uno::Reference
< beans::XPropertySet
> xProps( xIndexContainer
, uno::UNO_QUERY_THROW
);
531 // set UI name for toolbar
532 xProps
->setPropertyValue( rtl::OUString( RTL_CONSTASCII_USTRINGPARAM("UIName") ), uno::makeAny( name
.getString() ) );
534 rtl::OUString sToolBarName
= sToolbarPrefix
.concat( name
.getString() );
535 for ( std::vector
< TBC
>::iterator it
= rTBC
.begin(); it
!= rTBC
.end(); ++it
)
537 // createToolBar item for control
538 if ( !it
->ImportToolBarControl( rWrapper
, xIndexContainer
, helper
, IsMenuToolbar() ) )
542 OSL_TRACE("Name of toolbar :-/ %s", rtl::OUStringToOString( sToolBarName
, RTL_TEXTENCODING_UTF8
).getStr() );
544 helper
.getCfgManager()->insertSettings( sToolBarName
, xIndexAccess
);
546 #if 1 // don't think this is necessary
547 uno::Reference
< ui::XUIConfigurationPersistence
> xPersistence( helper
.getCfgManager()->getImageManager(), uno::UNO_QUERY_THROW
);
548 xPersistence
->store();
550 xPersistence
.set( helper
.getCfgManager(), uno::UNO_QUERY_THROW
);
551 xPersistence
->store();
555 catch( uno::Exception
& e
)
557 OSL_TRACE("***** For some reason we have an exception %s", rtl::OUStringToOString( e
.Message
, RTL_TEXTENCODING_UTF8
).getStr() );
563 bool CTB::ImportMenuTB( CTBWrapper
& rWrapper
, const css::uno::Reference
< css::container::XIndexContainer
>& xIndexContainer
, CustomToolBarImportHelper
& rHelper
)
565 for ( std::vector
< TBC
>::iterator it
= rTBC
.begin(); it
!= rTBC
.end(); ++it
)
567 // createToolBar item for control
568 if ( !it
->ImportToolBarControl( rWrapper
, xIndexContainer
, rHelper
, true ) )
582 bool TBC::Read( SvStream
*pS
)
584 OSL_TRACE("TBC::Read() stream pos 0x%x", pS
->Tell() );
585 nOffSet
= pS
->Tell();
586 if ( !tbch
.Read( pS
) )
588 if ( tbch
.getTcID() != 0x1 && tbch
.getTcID() != 0x1051 )
590 cid
.reset( new sal_uInt32
);
593 // MUST exist if tbch.tct is not equal to 0x16
594 if ( tbch
.getTct() != 0x16 )
596 tbcd
.reset( new TBCData( tbch
) );
597 if ( !tbcd
->Read( pS
) )
603 void TBC::Print( FILE* fp
)
606 indent_printf(fp
,"[ 0x%x ] TBC -- dump\n", nOffSet
);
607 indent_printf(fp
," dumping header ( TBCHeader )\n");
610 indent_printf(fp
," cid = 0x%x\n", static_cast< unsigned int >( *cid
) );
613 indent_printf(fp
," dumping toolbar data TBCData \n");
619 TBC::ImportToolBarControl( CTBWrapper
& rWrapper
, const css::uno::Reference
< css::container::XIndexContainer
>& toolbarcontainer
, CustomToolBarImportHelper
& helper
, bool bIsMenuBar
)
621 // cmtFci 0x1 Command based on a built-in command. See CidFci.
622 // cmtMacro 0x2 Macro command. See CidMacro.
623 // cmtAllocated 0x3 Allocated command. See CidAllocated.
624 // cmtNil 0x7 No command. See Cid.
625 bool bBuiltin
= false;
626 sal_uInt16 cmdId
= 0;
629 sal_uInt16 arg2
= ( *( cid
.get() ) & 0xFFFF );
631 sal_uInt8 cmt
= ( arg2
& 0x7 );
632 arg2
= ( arg2
>> 3 );
637 OSL_TRACE("cmt is cmtFci builtin command 0x%x", arg2
);
642 OSL_TRACE("cmt is cmtMacro macro 0x%x", arg2
);
645 OSL_TRACE("cmt is cmtAllocated [???] 0x%x", arg2
);
648 OSL_TRACE("cmt is cmNill no-phing 0x%x", arg2
);
651 OSL_TRACE("illegal 0x%x", cmt
);
658 std::vector
< css::beans::PropertyValue
> props
;
661 rtl::OUString sCommand
= helper
.MSOCommandToOOCommand( cmdId
);
662 if ( sCommand
.getLength() > 0 )
664 beans::PropertyValue aProp
;
666 aProp
.Name
= rtl::OUString( RTL_CONSTASCII_USTRINGPARAM("CommandURL") );
667 aProp
.Value
<<= sCommand
;
668 props
.push_back( aProp
);
671 bool bBeginGroup
= false;
672 if ( ! tbcd
->ImportToolBarControl( helper
, props
, bBeginGroup
, bIsMenuBar
) )
675 TBCMenuSpecific
* pMenu
= tbcd
->getMenuSpecific();
678 OSL_TRACE("** control has a menu, name of toolbar with menu items is %s", rtl::OUStringToOString( pMenu
->Name(), RTL_TEXTENCODING_UTF8
).getStr() );
679 // search for CTB with the appropriate name ( it contains the
680 // menu items, although we cannot import ( or create ) a menu on
681 // a custom toolbar we can import the menu items in a separate
682 // toolbar ( better than nothing )
683 CTB
* pCustTB
= rWrapper
.GetCustomizationData( pMenu
->Name() );
686 uno::Reference
< container::XIndexContainer
> xMenuDesc
;
687 uno::Reference
< lang::XMultiServiceFactory
> xMSF( ::comphelper::getProcessServiceFactory(), uno::UNO_QUERY_THROW
);
688 xMenuDesc
.set( xMSF
->createInstance( rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "com.sun.star.document.IndexedPropertyValues" ) ) ), uno::UNO_QUERY_THROW
);
689 if ( !pCustTB
->ImportMenuTB( rWrapper
,xMenuDesc
, helper
) )
691 beans::PropertyValue aProp
;
693 aProp
.Name
= rtl::OUString( RTL_CONSTASCII_USTRINGPARAM("ItemDescriptorContainer") );
694 aProp
.Value
<<= xMenuDesc
;
695 props
.push_back( aProp
);
702 uno::Sequence
< beans::PropertyValue
> sProps( 1 );
703 sProps
[ 0 ].Name
= rtl::OUString( RTL_CONSTASCII_USTRINGPARAM("Type") );
704 sProps
[ 0 ].Value
= uno::makeAny( ui::ItemType::SEPARATOR_LINE
);
705 toolbarcontainer
->insertByIndex( toolbarcontainer
->getCount(), uno::makeAny( sProps
) );
708 uno::Sequence
< beans::PropertyValue
> sProps( props
.size() );
709 beans::PropertyValue
* pProp
= sProps
.getArray();
711 for ( std::vector
< css::beans::PropertyValue
>::iterator it
= props
.begin(); it
!= props
.end(); ++it
, ++pProp
)
714 toolbarcontainer
->insertByIndex( toolbarcontainer
->getCount(), uno::makeAny( sProps
) );
722 rtl::OUString sCustomText
;
724 sCustomText
= tbcd
->getGeneralInfo().CustomText();
731 Xst::Read( SvStream
* pS
)
733 OSL_TRACE("Xst::Read() stream pos 0x%x", pS
->Tell() );
734 nOffSet
= pS
->Tell();
735 sal_Int16 nChars
= 0;
737 sString
= readUnicodeString( pS
, static_cast< sal_Int32
>( nChars
) );
742 Xst::Print( FILE* fp
)
745 indent_printf( fp
, "[ 0x%x ] Xst -- dump\n", nOffSet
);
746 indent_printf( fp
, " %s", rtl::OUStringToOString( sString
, RTL_TEXTENCODING_UTF8
).getStr() );
749 Tcg::Tcg() : nTcgVer( 255 )
753 bool Tcg::Read(SvStream
*pS
)
755 OSL_TRACE("Tcg::Read() stream pos 0x%x", pS
->Tell() );
756 nOffSet
= pS
->Tell();
758 if ( nTcgVer
!= (sal_Int8
)255 )
760 tcg
.reset( new Tcg255() );
761 return tcg
->Read( pS
);
764 void Tcg::Print( FILE* fp
)
767 indent_printf(fp
, "[ 0x%x ] Tcg - dump %d\n", nOffSet
, nTcgVer
);
768 indent_printf(fp
," nTcgVer %d\n", nTcgVer
);
772 bool Tcg::ImportCustomToolBar( SfxObjectShell
& rDocSh
)
774 return tcg
->ImportCustomToolBar( rDocSh
);
783 std::vector
< Tcg255SubStruct
* >::iterator it
= rgtcgData
.begin();
784 for ( ; it
!= rgtcgData
.end(); ++it
)
788 bool Tcg255::processSubStruct( sal_uInt8 nId
, SvStream
*pS
)
790 Tcg255SubStruct
* pSubStruct
= NULL
;
795 pSubStruct
= new PlfMcd( false ); // don't read the id
800 pSubStruct
= new PlfAcd( false );
806 pSubStruct
= new PlfKme( false );
811 pSubStruct
= new TcgSttbf( false );
816 pSubStruct
= new MacroNames( false );
821 pSubStruct
= new CTBWrapper( false );
825 OSL_TRACE("Unknown id 0x%x",nId
);
828 pSubStruct
->ch
= nId
;
829 if ( !pSubStruct
->Read( pS
) )
831 rgtcgData
.push_back( pSubStruct
);
835 bool Tcg255::ImportCustomToolBar( SfxObjectShell
& rDocSh
)
837 // Find the CTBWrapper
838 for ( std::vector
< Tcg255SubStruct
* >::const_iterator it
= rgtcgData
.begin(); it
!= rgtcgData
.end(); ++it
)
840 if ( (*it
)->id() == 0x12 )
842 // not so great, shouldn't really have to do a horror casting
843 CTBWrapper
* pCTBWrapper
= dynamic_cast< CTBWrapper
* > ( *it
);
846 if ( !pCTBWrapper
->ImportCustomToolBar( rDocSh
) )
855 bool Tcg255::Read(SvStream
*pS
)
857 OSL_TRACE("Tcg255::Read() stream pos 0x%x", pS
->Tell() );
858 nOffSet
= pS
->Tell();
859 sal_uInt8 nId
= 0; //
861 while ( nId
!= 0x40 )
863 if ( !processSubStruct( nId
, pS
) )
871 void Tcg255::Print( FILE* fp
)
874 indent_printf(fp
, "[ 0x%x ] Tcg255 - dump\n", nOffSet
);
875 indent_printf(fp
, " contains %d sub records\n", rgtcgData
.size() );
876 std::vector
< Tcg255SubStruct
* >::iterator it
= rgtcgData
.begin();
877 std::vector
< Tcg255SubStruct
* >::iterator it_end
= rgtcgData
.end();
879 for( sal_Int32 count
= 1; it
!= it_end
; ++it
, ++count
)
882 indent_printf(fp
, " [%d] Tcg255SubStruct \n", static_cast< unsigned int >( count
) );
888 Tcg255SubStruct::Tcg255SubStruct( bool bReadId
) : mbReadId( bReadId
), ch(0)
892 bool Tcg255SubStruct::Read(SvStream
*pS
)
894 OSL_TRACE("Tcg255SubStruct::Read() stream pos 0x%x", pS
->Tell() );
895 nOffSet
= pS
->Tell();
901 PlfMcd::PlfMcd( bool bReadId
): Tcg255SubStruct( bReadId
), rgmcd( NULL
)
910 bool PlfMcd::Read(SvStream
*pS
)
912 OSL_TRACE("PffMcd::Read() stream pos 0x%x", pS
->Tell() );
913 nOffSet
= pS
->Tell();
914 Tcg255SubStruct::Read( pS
);
918 rgmcd
= new MCD
[ iMac
];
919 for ( sal_Int32 index
= 0; index
< iMac
; ++index
)
921 if ( !rgmcd
[ index
].Read( pS
) )
928 void PlfMcd::Print( FILE* fp
)
931 indent_printf(fp
, "[ 0x%x ] PlfMcd ( Tcg255SubStruct ) - dump\n", nOffSet
);
932 indent_printf(fp
, " contains %d MCD records\n", static_cast<int>( iMac
) );
933 for ( sal_Int32 count
=0; count
< iMac
; ++count
)
936 indent_printf(fp
, "[%d] MCD\n", static_cast< int >( count
) );
937 rgmcd
[ count
].Print( fp
);
942 PlfAcd::PlfAcd( bool bReadId
) : Tcg255SubStruct( bReadId
)
955 bool PlfAcd::Read( SvStream
*pS
)
957 OSL_TRACE("PffAcd::Read() stream pos 0x%x", pS
->Tell() );
958 nOffSet
= pS
->Tell();
959 Tcg255SubStruct::Read( pS
);
963 rgacd
= new Acd
[ iMac
];
964 for ( sal_Int32 index
= 0; index
< iMac
; ++index
)
966 if ( !rgacd
[ index
].Read( pS
) )
972 void PlfAcd::Print( FILE* fp
)
975 indent_printf(fp
, "[ 0x%x ] PlfAcd ( Tcg255SubStruct ) - dump\n", nOffSet
);
976 indent_printf(fp
, " contains %d ACD records\n", static_cast< int >( iMac
) );
977 for ( sal_Int32 count
=0; count
< iMac
; ++count
)
980 indent_printf(fp
, "[%d] ACD\n", static_cast< int >( count
) );
981 rgacd
[ count
].Print( fp
);
986 PlfKme::PlfKme( bool bReadId
) : Tcg255SubStruct( bReadId
)
998 bool PlfKme::Read(SvStream
*pS
)
1000 OSL_TRACE("PlfKme::Read() stream pos 0x%x", pS
->Tell() );
1001 nOffSet
= pS
->Tell();
1002 Tcg255SubStruct::Read( pS
);
1006 rgkme
= new Kme
[ iMac
];
1007 for( sal_Int32 index
=0; index
<iMac
; ++index
)
1009 if ( !rgkme
[ index
].Read( pS
) )
1016 void PlfKme::Print( FILE* fp
)
1019 indent_printf(fp
, "[ 0x%x ] PlfKme ( Tcg255SubStruct ) - dump\n", nOffSet
);
1020 indent_printf(fp
, " contains %d Kme records\n", static_cast< int >( iMac
) );
1021 for ( sal_Int32 count
=0; count
< iMac
; ++count
)
1024 indent_printf(fp
, "[%d] Kme\n", static_cast< int >( count
) );
1025 rgkme
[ count
].Print( fp
);
1030 TcgSttbf::TcgSttbf( bool bReadId
) : Tcg255SubStruct( bReadId
)
1034 bool TcgSttbf::Read( SvStream
*pS
)
1036 OSL_TRACE("TcgSttbf::Read() stream pos 0x%x", pS
->Tell() );
1037 nOffSet
= pS
->Tell();
1038 Tcg255SubStruct::Read( pS
);
1039 return sttbf
.Read( pS
);
1042 void TcgSttbf::Print( FILE* fp
)
1045 indent_printf(fp
,"[ 0x%x ] TcgSttbf - dump\n", nOffSet
);
1049 TcgSttbfCore::TcgSttbfCore() : fExtend( 0 )
1056 TcgSttbfCore::~TcgSttbfCore()
1062 bool TcgSttbfCore::Read( SvStream
* pS
)
1064 OSL_TRACE("TcgSttbfCore::Read() stream pos 0x%x", pS
->Tell() );
1065 nOffSet
= pS
->Tell();
1066 *pS
>> fExtend
>> cData
>> cbExtra
;
1069 dataItems
= new SBBItem
[ cData
];
1070 for ( sal_Int32 index
= 0; index
< cData
; ++index
)
1072 *pS
>> dataItems
[ index
].cchData
;
1073 dataItems
[ index
].data
= readUnicodeString( pS
, dataItems
[ index
].cchData
);
1074 *pS
>> dataItems
[ index
].extraData
;
1080 void TcgSttbfCore::Print( FILE* fp
)
1083 indent_printf( fp
, "[ 0x%x ] TcgSttbfCore - dump\n");
1084 indent_printf( fp
, " fExtend 0x%x [expected 0xFFFF ]\n", fExtend
);
1085 indent_printf( fp
, " cbExtra 0x%x [expected 0x02 ]\n", cbExtra
);
1086 indent_printf( fp
, " cData no. or string data items %d (0x%x)\n", cData
, cData
);
1090 for ( sal_Int32 index
= 0; index
< cData
; ++index
)
1091 indent_printf(fp
," string dataItem[ %d(0x%x) ] has name %s and if referenced %d times.\n", static_cast< int >( index
), static_cast< unsigned int >( index
), rtl::OUStringToOString( dataItems
[ index
].data
, RTL_TEXTENCODING_UTF8
).getStr(), dataItems
[ index
].extraData
);
1095 MacroNames::MacroNames( bool bReadId
) : Tcg255SubStruct( bReadId
)
1101 MacroNames::~MacroNames()
1107 bool MacroNames::Read( SvStream
*pS
)
1109 OSL_TRACE("MacroNames::Read() stream pos 0x%x", pS
->Tell() );
1110 nOffSet
= pS
->Tell();
1111 Tcg255SubStruct::Read( pS
);
1115 rgNames
= new MacroName
[ iMac
];
1116 for ( sal_Int32 index
= 0; index
< iMac
; ++index
)
1118 if ( !rgNames
[ index
].Read( pS
) )
1125 void MacroNames::Print( FILE* fp
)
1128 indent_printf(fp
, "[ 0x%x ] MacroNames ( Tcg255SubStruct ) - dump\n");
1129 indent_printf(fp
, " contains %d MacroName records\n", iMac
);
1130 for ( sal_Int32 count
=0; count
< iMac
; ++count
)
1133 indent_printf(fp
, "[%d] MacroName\n", static_cast<int>( count
) );
1134 rgNames
[ count
].Print( fp
);
1139 MacroName::MacroName():ibst(0)
1144 bool MacroName::Read(SvStream
*pS
)
1146 OSL_TRACE("MacroName::Read() stream pos 0x%x", pS
->Tell() );
1147 nOffSet
= pS
->Tell();
1149 return xstz
.Read( pS
);
1152 void MacroName::Print( FILE* fp
)
1155 indent_printf( fp
, "[ 0x%x ] MacroName - dump");
1156 indent_printf( fp
," index - 0x%x has associated following record\n", ibst
);
1162 Xstz::Xstz():chTerm(0)
1167 Xstz::Read(SvStream
*pS
)
1169 OSL_TRACE("Xstz::Read() stream pos 0x%x", pS
->Tell() );
1170 nOffSet
= pS
->Tell();
1171 if ( !xst
.Read( pS
) )
1174 if ( chTerm
!= 0 ) // should be an assert
1179 void Xstz::Print( FILE* fp
)
1182 indent_printf(fp
,"[ 0x%x ] Xstz -- dump\n", nOffSet
);
1183 indent_printf(fp
," Xst\n");
1185 indent_printf(fp
," chterm 0x%x ( should be zero )\n", chTerm
);
1188 Kme::Kme() : reserved1(0)
1202 Kme::Read(SvStream
*pS
)
1204 OSL_TRACE("Kme::Read() stream pos 0x%x", pS
->Tell() );
1205 nOffSet
= pS
->Tell();
1206 *pS
>> reserved1
>> reserved2
>> kcm1
>> kcm2
>> kt
>> param
;
1210 void Kme::Print( FILE* fp
)
1214 indent_printf( fp
, "[ 0x%x ] Kme - dump\n", nOffSet
);
1215 indent_printf( fp
, " reserved1 0x%x [expected 0x0 ]\n", reserved1
);
1216 indent_printf( fp
, " reserved2 0x%x [expected 0x0 ]\n", reserved2
);
1217 indent_printf( fp
, " kcm1 0x%x [shortcut key]\n", kcm1
);
1218 indent_printf( fp
, " kcm2 0x%x [shortcut key]\n", kcm2
);
1219 indent_printf( fp
, " kt 0x%x \n", kt
);
1220 indent_printf( fp
, " param 0x%x \n", static_cast< unsigned int >( param
) );
1223 Acd::Acd() : ibst( 0 )
1224 , fciBasedOnABC( 0 )
1228 bool Acd::Read(SvStream
*pS
)
1230 OSL_TRACE("Acd::Read() stream pos 0x%x", pS
->Tell() );
1231 nOffSet
= pS
->Tell();
1232 *pS
>> ibst
>> fciBasedOnABC
;
1236 void Acd::Print( FILE* fp
)
1239 indent_printf( fp
,"[ 0x%x ] ACD - dump\n", nOffSet
);
1240 // #TODO flesh out interpretation of these values
1241 indent_printf( fp
," ibst 0x%x\n", ibst
);
1242 indent_printf( fp
," fciBaseObABC 0x%x\n", fciBasedOnABC
);
1245 MCD::MCD() : reserved1(0x56)
1249 ,reserved3( 0xFFFF )
1257 bool MCD::Read(SvStream
*pS
)
1259 OSL_TRACE("MCD::Read() stream pos 0x%x", pS
->Tell() );
1260 nOffSet
= pS
->Tell();
1261 *pS
>> reserved1
>> reserved2
>> ibst
>> ibstName
>> reserved3
;
1262 *pS
>> reserved4
>> reserved5
>> reserved6
>> reserved7
;
1266 void MCD::Print( FILE* fp
)
1269 indent_printf( fp
, "[ 0x%x ] MCD - dump\n", nOffSet
);
1270 indent_printf( fp
, " reserved1 0x%x [expected 0x56 ]\n", reserved1
);
1271 indent_printf( fp
, " reserved2 0x%x [expected 0x0 ]\n", reserved2
);
1272 indent_printf( fp
, " ibst 0x%x specifies macro with MacroName.xstz = 0x%x\n", ibst
, ibst
);
1273 indent_printf( fp
, " ibstName 0x%x index into command string table ( TcgSttbf.sttbf )\n", ibstName
);
1275 indent_printf( fp
, " reserved3 0x%x [expected 0xFFFF ]\n", reserved3
);
1276 indent_printf( fp
, " reserved4 0x%x\n", static_cast< unsigned int >( reserved4
) );
1277 indent_printf( fp
, " reserved5 0x%x [expected 0x0 ]\n", static_cast< unsigned int >( reserved5
) );
1278 indent_printf( fp
, " reserved6 0x%x\n", static_cast< unsigned int >( reserved6
) );
1279 indent_printf( fp
, " reserved7 0x%x\n", static_cast< unsigned int >( reserved7
) );