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 :
10 : #include "ww8toolbar.hxx"
11 : #include "ww8scan.hxx"
12 : #include <rtl/ustrbuf.hxx>
13 : #include <stdarg.h>
14 : #include <com/sun/star/document/IndexedPropertyValues.hpp>
15 : #include <com/sun/star/ui/XUIConfigurationPersistence.hpp>
16 : #include <com/sun/star/ui/theModuleUIConfigurationManagerSupplier.hpp>
17 : #include <com/sun/star/lang/XMultiServiceFactory.hpp>
18 : #include <com/sun/star/lang/XSingleComponentFactory.hpp>
19 : #include <com/sun/star/lang/XMultiComponentFactory.hpp>
20 : #include <com/sun/star/ui/XImageManager.hpp>
21 : #include <com/sun/star/ui/ItemType.hpp>
22 : #include <fstream>
23 : #include <comphelper/processfactory.hxx>
24 : #include <vcl/graph.hxx>
25 : #include <map>
26 : #include "sal/log.hxx"
27 :
28 : using namespace com::sun::star;
29 :
30 : // no. of visual data elements in a SwCTB ( fixed )
31 : const short nVisualData = 5;
32 :
33 : typedef std::map< sal_Int16, OUString > IdToString;
34 :
35 0 : class MSOWordCommandConvertor : public MSOCommandConvertor
36 : {
37 : IdToString msoToOOcmd;
38 : IdToString tcidToOOcmd;
39 :
40 : public:
41 : MSOWordCommandConvertor();
42 : virtual OUString MSOCommandToOOCommand( sal_Int16 msoCmd ) SAL_OVERRIDE;
43 : virtual OUString MSOTCIDToOOCommand( sal_Int16 key ) SAL_OVERRIDE;
44 : };
45 :
46 0 : MSOWordCommandConvertor::MSOWordCommandConvertor()
47 : {
48 : // mso command id to ooo command string
49 : // #FIXME and *HUNDREDS* of id's to added here
50 0 : msoToOOcmd[ 0x20b ] = ".uno:CloseDoc";
51 0 : msoToOOcmd[ 0x50 ] = ".uno:Open";
52 :
53 : // mso tcid to ooo command string
54 : // #FIXME and *HUNDREDS* of id's to added here
55 0 : tcidToOOcmd[ 0x9d9 ] = ".uno:Print";
56 0 : }
57 :
58 0 : OUString MSOWordCommandConvertor::MSOCommandToOOCommand( sal_Int16 key )
59 : {
60 0 : OUString sResult;
61 0 : IdToString::iterator it = msoToOOcmd.find( key );
62 0 : if ( it != msoToOOcmd.end() )
63 0 : sResult = it->second;
64 0 : return sResult;
65 : }
66 :
67 0 : OUString MSOWordCommandConvertor::MSOTCIDToOOCommand( sal_Int16 key )
68 : {
69 0 : OUString sResult;
70 0 : IdToString::iterator it = tcidToOOcmd.find( key );
71 0 : if ( it != tcidToOOcmd.end() )
72 0 : sResult = it->second;
73 0 : return sResult;
74 : }
75 :
76 0 : SwCTBWrapper::SwCTBWrapper( bool bReadId ) : Tcg255SubStruct( bReadId )
77 : ,reserved2(0)
78 : ,reserved3(0)
79 : ,reserved4(0)
80 : ,reserved5(0)
81 : ,cbTBD(0)
82 : ,cCust(0)
83 : ,cbDTBC(0)
84 0 : ,rtbdc(0)
85 : {
86 0 : }
87 :
88 0 : SwCTBWrapper::~SwCTBWrapper()
89 : {
90 0 : }
91 :
92 0 : Customization* SwCTBWrapper::GetCustomizaton( sal_Int16 index )
93 : {
94 0 : if ( index < 0 || index >= static_cast<sal_Int16>( rCustomizations.size() ) )
95 0 : return NULL;
96 0 : return &rCustomizations[ index ];
97 : }
98 :
99 0 : SwCTB* SwCTBWrapper::GetCustomizationData( const OUString& sTBName )
100 : {
101 0 : SwCTB* pCTB = NULL;
102 0 : for ( std::vector< Customization >::iterator it = rCustomizations.begin(); it != rCustomizations.end(); ++it )
103 : {
104 0 : if ( it->GetCustomizationData() && it->GetCustomizationData()->GetName().equals( sTBName ) )
105 : {
106 0 : pCTB = it->GetCustomizationData();
107 0 : break;
108 : }
109 : }
110 0 : return pCTB;
111 : }
112 :
113 0 : bool SwCTBWrapper::Read( SvStream& rS )
114 : {
115 : SAL_INFO("sw.ww8","SwCTBWrapper::Read() stream pos 0x" << std::hex << rS.Tell() );
116 0 : nOffSet = rS.Tell();
117 0 : Tcg255SubStruct::Read( rS );
118 0 : rS.ReadUInt16( reserved2 ).ReadUChar( reserved3 ).ReadUInt16( reserved4 ).ReadUInt16( reserved5 );
119 0 : rS.ReadInt16( cbTBD ).ReadInt16( cCust ).ReadInt32( cbDTBC );
120 0 : long nExpectedPos = rS.Tell() + cbDTBC;
121 0 : if ( cbDTBC )
122 : {
123 : // cbDTBC is the size in bytes of the SwTBC array
124 : // but the size of a SwTBC element is dynamic ( and this relates to TBDelta's
125 0 : int nStart = rS.Tell();
126 :
127 0 : int bytesRead = 0;
128 0 : int bytesToRead = cbDTBC - bytesRead;
129 : // cbDTBC specifies the size ( in bytes ) taken by an array ( of unspecified size )
130 : // of SwTBC records ( SwTBC records have dynamic length, so we need to check our position
131 : // after each read )
132 0 : do
133 : {
134 0 : SwTBC aTBC;
135 0 : if ( !aTBC.Read( rS ) )
136 0 : return false;
137 0 : rtbdc.push_back( aTBC );
138 0 : bytesToRead = cbDTBC - ( rS.Tell() - nStart );
139 : } while ( bytesToRead > 0 );
140 : }
141 0 : if ( static_cast< long >( rS.Tell() ) != nExpectedPos )
142 : {
143 : // Strange error condition, shouldn't happen ( but does in at least
144 : // one test document ) In the case where it happens the SwTBC &
145 : // TBCHeader records seem blank??? ( and incorrect )
146 : SAL_WARN_IF( static_cast< long >(rS.Tell()) != nExpectedPos, "sw.ww8","### Error: Expected pos not equal to actual pos after reading rtbdc");
147 : SAL_INFO("sw.ww8","\tPos now is 0x" << std::hex << rS.Tell() << " should be 0x" << std::hex << nExpectedPos );
148 : // seek to correct position after rtbdc
149 0 : rS.Seek( nExpectedPos );
150 : }
151 0 : if ( cCust )
152 : {
153 0 : for ( sal_Int32 index = 0; index < cCust; ++index )
154 : {
155 0 : Customization aCust( this );
156 0 : if ( !aCust.Read( rS ) )
157 0 : return false;
158 0 : rCustomizations.push_back( aCust );
159 0 : }
160 : }
161 0 : std::vector< sal_Int16 >::iterator it_end = dropDownMenuIndices.end();
162 0 : for ( std::vector< sal_Int16 >::iterator it = dropDownMenuIndices.begin(); it != it_end; ++it )
163 : {
164 0 : rCustomizations[ *it ].bIsDroppedMenuTB = true;
165 : }
166 0 : return true;
167 : }
168 :
169 0 : SwTBC* SwCTBWrapper::GetTBCAtOffset( sal_uInt32 nStreamOffset )
170 : {
171 0 : for ( std::vector< SwTBC >::iterator it = rtbdc.begin(); it != rtbdc.end(); ++it )
172 : {
173 0 : if ( (*it).GetOffset() == nStreamOffset )
174 0 : return &(*it);
175 : }
176 0 : return NULL;
177 : }
178 :
179 0 : void SwCTBWrapper::Print( FILE* fp )
180 : {
181 0 : Indent a;
182 0 : indent_printf(fp,"[ 0x%x ] SwCTBWrapper - dump\n", nOffSet );
183 0 : bool bRes = ( ch == 0x12 && reserved2 == 0x0 && reserved3 == 0x7 && reserved4 == 0x6 && reserved5 == 0xC );
184 0 : if ( bRes )
185 0 : indent_printf(fp," sanity check ( first 8 bytes conform )\n");
186 : else
187 : {
188 0 : indent_printf(fp," reserved1(0x%x)\n",ch);
189 0 : indent_printf(fp," reserved2(0x%x)\n",reserved2);
190 0 : indent_printf(fp," reserved3(0x%x)\n",reserved3);
191 0 : indent_printf(fp," reserved4(0x%x)\n",reserved4);
192 0 : indent_printf(fp," reserved5(0x%x)\n",reserved5);
193 0 : indent_printf(fp,"Quiting dump");
194 0 : return;
195 : }
196 0 : indent_printf(fp," size of TBDelta structures 0x%x\n", cbTBD );
197 0 : indent_printf(fp," cCust: no. of cCust structures 0x%x\n",cCust);
198 0 : indent_printf(fp," cbDTBC: no. of bytes in rtbdc array 0x%x\n", static_cast< unsigned int >( cbDTBC ));
199 :
200 0 : sal_Int32 index = 0;
201 :
202 0 : for ( std::vector< SwTBC >::iterator it = rtbdc.begin(); it != rtbdc.end(); ++it, ++index )
203 : {
204 0 : indent_printf(fp," Dumping rtbdc[%d]\n", static_cast< int >( index ));
205 0 : Indent b;
206 0 : it->Print( fp );
207 0 : }
208 :
209 0 : index = 0;
210 :
211 0 : for ( std::vector< Customization >::iterator it = rCustomizations.begin(); it != rCustomizations.end(); ++it, ++index )
212 : {
213 0 : indent_printf(fp," Dumping custimization [%d]\n", static_cast< int >( index ));
214 0 : Indent c;
215 0 : it->Print(fp);
216 0 : }
217 : }
218 :
219 0 : bool SwCTBWrapper::ImportCustomToolBar( SfxObjectShell& rDocSh )
220 : {
221 0 : for ( std::vector< Customization >::iterator it = rCustomizations.begin(); it != rCustomizations.end(); ++it )
222 : {
223 : try
224 : {
225 0 : uno::Reference< uno::XComponentContext > xContext = ::comphelper::getProcessComponentContext();
226 0 : uno::Reference< ui::XModuleUIConfigurationManagerSupplier > xAppCfgSupp( ui::theModuleUIConfigurationManagerSupplier::get(xContext) );
227 0 : CustomToolBarImportHelper helper( rDocSh, xAppCfgSupp->getUIConfigurationManager( "com.sun.star.text.TextDocument" ) );
228 0 : helper.setMSOCommandMap( new MSOWordCommandConvertor() );
229 :
230 0 : if ( !(*it).ImportCustomToolBar( *this, helper ) )
231 0 : return false;
232 : }
233 0 : catch(...)
234 : {
235 0 : continue;
236 : }
237 : }
238 0 : return false;
239 : }
240 :
241 0 : Customization::Customization( SwCTBWrapper* wrapper ) : tbidForTBD( 0 )
242 : ,reserved1( 0 )
243 : , ctbds( 0 )
244 : , pWrapper( wrapper )
245 0 : , bIsDroppedMenuTB( false )
246 : {
247 0 : }
248 :
249 0 : Customization::~Customization()
250 : {
251 0 : }
252 :
253 0 : bool Customization::Read( SvStream &rS)
254 : {
255 : SAL_INFO("sw.ww8","Custimization::Read() stream pos 0x" << std::hex << rS.Tell() );
256 0 : nOffSet = rS.Tell();
257 0 : rS.ReadInt32( tbidForTBD ).ReadUInt16( reserved1 ).ReadInt16( ctbds );
258 0 : if ( tbidForTBD )
259 : {
260 0 : for ( sal_Int32 index = 0; index < ctbds; ++index )
261 : {
262 0 : TBDelta aTBDelta;
263 0 : if (!aTBDelta.Read( rS ) )
264 0 : return false;
265 0 : customizationDataTBDelta.push_back( aTBDelta );
266 : // Only set the drop down for menu's associated with standard toolbar
267 0 : if ( aTBDelta.ControlDropsToolBar() && tbidForTBD == 0x25 )
268 0 : pWrapper->InsertDropIndex( aTBDelta.CustomizationIndex() );
269 0 : }
270 : }
271 : else
272 : {
273 0 : customizationDataCTB.reset( new SwCTB() );
274 0 : if ( !customizationDataCTB->Read( rS ) )
275 0 : return false;
276 : }
277 0 : return true;
278 : }
279 :
280 0 : void Customization::Print( FILE* fp )
281 : {
282 0 : Indent a;
283 0 : indent_printf( fp,"[ 0x%x ] Customization -- dump \n", nOffSet );
284 0 : indent_printf( fp," tbidForTBD 0x%x ( should be 0 for CTBs )\n", static_cast< unsigned int >( tbidForTBD ));
285 0 : indent_printf( fp," reserved1 0x%x \n", reserved1);
286 0 : indent_printf( fp," ctbds - number of customisations %d(0x%x) \n", ctbds, ctbds );
287 0 : if ( !tbidForTBD && !ctbds )
288 0 : customizationDataCTB->Print( fp );
289 : else
290 : {
291 0 : const char* pToolBar = NULL;
292 0 : switch ( tbidForTBD )
293 : {
294 : case 0x9:
295 0 : pToolBar = "Standard";
296 0 : break;
297 : case 0x25:
298 0 : pToolBar = "Builtin-Menu";
299 0 : break;
300 : default:
301 0 : pToolBar = "Unknown toolbar";
302 0 : break;
303 : }
304 :
305 0 : indent_printf( fp," TBDelta(s) are associated with %s toolbar.\n", pToolBar);
306 0 : std::vector< TBDelta >::iterator it = customizationDataTBDelta.begin();
307 0 : for ( sal_Int32 index = 0; index < ctbds; ++it,++index )
308 0 : it->Print( fp );
309 0 : }
310 :
311 0 : }
312 :
313 0 : bool Customization::ImportMenu( SwCTBWrapper& rWrapper, CustomToolBarImportHelper& helper )
314 : {
315 0 : if ( tbidForTBD == 0x25 ) // we can handle in a limited way additions the built-in menu bar
316 : {
317 0 : for ( std::vector< TBDelta >::iterator it = customizationDataTBDelta.begin(); it != customizationDataTBDelta.end(); ++it )
318 : {
319 : // for each new menu ( control that drops a toolbar )
320 : // import a toolbar
321 0 : if ( it->ControlIsInserted() && it->ControlDropsToolBar() )
322 : {
323 0 : Customization* pCust = pWrapper->GetCustomizaton( it->CustomizationIndex() );
324 0 : if ( pCust )
325 : {
326 : // currently only support built-in menu
327 0 : OUString sMenuBar( "private:resource/menubar/" );
328 :
329 0 : sMenuBar = sMenuBar.concat( "menubar" );
330 : // Get menu name
331 0 : SwTBC* pTBC = pWrapper->GetTBCAtOffset( it->TBCStreamOffset() );
332 0 : if ( !pTBC )
333 0 : return false;
334 0 : OUString sMenuName = pTBC->GetCustomText();
335 0 : sMenuName = sMenuName.replace('&','~');
336 :
337 : // see if the document has already setting for the menubar
338 :
339 0 : uno::Reference< container::XIndexContainer > xIndexContainer;
340 0 : bool bHasSettings = false;
341 0 : if ( helper.getCfgManager()->hasSettings( sMenuBar ) )
342 : {
343 0 : xIndexContainer.set( helper.getCfgManager()->getSettings( sMenuBar, sal_True ), uno::UNO_QUERY_THROW );
344 0 : bHasSettings = true;
345 : }
346 : else
347 : {
348 0 : if ( helper.getAppCfgManager()->hasSettings( sMenuBar ) )
349 0 : xIndexContainer.set( helper.getAppCfgManager()->getSettings( sMenuBar, sal_True ), uno::UNO_QUERY_THROW );
350 : else
351 0 : xIndexContainer.set( helper.getAppCfgManager()->createSettings(), uno::UNO_QUERY_THROW );
352 : }
353 :
354 0 : uno::Reference< lang::XSingleComponentFactory > xSCF( xIndexContainer, uno::UNO_QUERY_THROW );
355 : uno::Reference< uno::XComponentContext > xContext(
356 0 : comphelper::getProcessComponentContext() );
357 : // create the popup menu
358 0 : uno::Sequence< beans::PropertyValue > aPopupMenu( 4 );
359 0 : aPopupMenu[0].Name = "CommandURL";
360 0 : aPopupMenu[0].Value = uno::makeAny( OUString( "vnd.openoffice.org:" ) + sMenuName );
361 0 : aPopupMenu[1].Name = "Label";
362 0 : aPopupMenu[1].Value <<= sMenuName;
363 0 : aPopupMenu[2].Name = "Type";
364 0 : aPopupMenu[2].Value <<= sal_Int32( 0 );
365 0 : aPopupMenu[3].Name = "ItemDescriptorContainer";
366 0 : uno::Reference< container::XIndexContainer > xMenuContainer( xSCF->createInstanceWithContext( xContext ), uno::UNO_QUERY_THROW );
367 0 : aPopupMenu[3].Value <<= xMenuContainer;
368 0 : if ( pCust->customizationDataCTB.get() && !pCust->customizationDataCTB->ImportMenuTB( rWrapper, xMenuContainer, helper ) )
369 0 : return false;
370 : SAL_INFO("sw.ww8","** there are " << xIndexContainer->getCount() << " menu items on the bar, inserting after that");
371 0 : xIndexContainer->insertByIndex( xIndexContainer->getCount(), uno::makeAny( aPopupMenu ) );
372 :
373 0 : if ( bHasSettings )
374 0 : helper.getCfgManager()->replaceSettings( sMenuBar, uno::Reference< container::XIndexAccess >( xIndexContainer, uno::UNO_QUERY_THROW ) );
375 : else
376 0 : helper.getCfgManager()->insertSettings( sMenuBar, uno::Reference< container::XIndexAccess >( xIndexContainer, uno::UNO_QUERY_THROW ) );
377 :
378 0 : uno::Reference< ui::XUIConfigurationPersistence > xPersistence( helper.getCfgManager(), uno::UNO_QUERY_THROW );
379 0 : xPersistence->store();
380 : }
381 : }
382 : }
383 0 : return true;
384 : }
385 0 : return true;
386 : }
387 :
388 0 : bool Customization::ImportCustomToolBar( SwCTBWrapper& rWrapper, CustomToolBarImportHelper& helper )
389 : {
390 0 : if ( GetTBIDForTB() == 0x25 )
391 0 : return ImportMenu( rWrapper, helper );
392 0 : if ( !customizationDataCTB.get() )
393 0 : return false;
394 0 : if ( !customizationDataCTB->IsMenuToolbar() )
395 : {
396 0 : if ( !customizationDataCTB->ImportCustomToolBar( rWrapper, helper ) )
397 0 : return false;
398 : }
399 0 : return true;
400 : }
401 :
402 0 : TBDelta::TBDelta()
403 : : doprfatendFlags(0)
404 : , ibts(0)
405 : , cidNext(0)
406 : , cid(0)
407 : , fc(0)
408 : , CiTBDE(0)
409 0 : , cbTBC(0)
410 : {
411 0 : }
412 :
413 0 : bool TBDelta::ControlIsModified()
414 : {
415 0 : return ( ( doprfatendFlags & 0x3 ) == 0x2 );
416 : }
417 :
418 0 : bool TBDelta::ControlIsInserted()
419 : {
420 0 : return ( ( doprfatendFlags & 0x3 ) == 0x1 );
421 : }
422 :
423 0 : bool TBDelta::ControlIsChanged()
424 : {
425 0 : return ( ( doprfatendFlags & 0x3 ) == 0x1 );
426 : }
427 :
428 0 : bool TBDelta::ControlDropsToolBar()
429 : {
430 0 : return !( CiTBDE & 0x8000 );
431 : }
432 :
433 0 : sal_Int32 TBDelta::TBCStreamOffset()
434 : {
435 0 : return fc;
436 : }
437 :
438 0 : sal_Int16 TBDelta::CustomizationIndex()
439 : {
440 0 : sal_Int16 nIndex = CiTBDE;
441 0 : nIndex = nIndex >> 1;
442 0 : nIndex &= 0x1ff; // only 13 bits are relevant
443 0 : return nIndex;
444 : }
445 :
446 0 : bool TBDelta::Read(SvStream &rS)
447 : {
448 : SAL_INFO("sw.ww8","TBDelta::Read() stream pos 0x" << std::hex << rS.Tell() );
449 0 : nOffSet = rS.Tell();
450 0 : rS.ReadUChar( doprfatendFlags ).ReadUChar( ibts ).ReadInt32( cidNext ).ReadInt32( cid ).ReadInt32( fc ) ;
451 0 : rS.ReadUInt16( CiTBDE ).ReadUInt16( cbTBC );
452 0 : return true;
453 : }
454 :
455 0 : void TBDelta::Print( FILE* fp )
456 : {
457 : // Like most of the debug output, it's raw and little ( no )
458 : // interpretation of the data is output ( e.g. flag values etc. )
459 0 : indent_printf( fp, "[ 0x%x ] TBDelta -- dump\n", nOffSet );
460 0 : indent_printf( fp, " doprfatendFlags 0x%x\n",doprfatendFlags );
461 :
462 0 : indent_printf( fp, " ibts 0x%x\n",ibts );
463 0 : indent_printf( fp, " cidNext 0x%x\n", static_cast< unsigned int >( cidNext ) );
464 0 : indent_printf( fp, " cid 0x%x\n", static_cast< unsigned int >( cid ) );
465 0 : indent_printf( fp, " fc 0x%x\n", static_cast< unsigned int >( fc ) );
466 0 : indent_printf( fp, " CiTBDE 0x%x\n",CiTBDE );
467 0 : indent_printf( fp, " cbTBC 0x%x\n", cbTBC );
468 0 : if ( ControlDropsToolBar() )
469 : {
470 0 : indent_printf( fp, " this delta is associated with a control that drops a menu toolbar\n", cbTBC );
471 0 : 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() );
472 : }
473 0 : }
474 :
475 0 : SwCTB::SwCTB() : cbTBData( 0 )
476 : ,iWCTBl( 0 )
477 : ,reserved( 0 )
478 : ,unused( 0 )
479 0 : ,cCtls( 0 )
480 : {
481 0 : }
482 :
483 0 : SwCTB::~SwCTB()
484 : {
485 0 : }
486 :
487 0 : bool SwCTB::IsMenuToolbar()
488 : {
489 0 : return tb.IsMenuToolbar();
490 : }
491 :
492 0 : bool SwCTB::Read( SvStream &rS)
493 : {
494 : SAL_INFO("sw.ww8","SwCTB::Read() stream pos 0x" << std::hex << rS.Tell() );
495 0 : nOffSet = rS.Tell();
496 0 : if ( !name.Read( rS ) )
497 0 : return false;
498 0 : rS.ReadInt32( cbTBData );
499 0 : if ( !tb.Read( rS ) )
500 0 : return false;
501 0 : for ( short index = 0; index < nVisualData; ++index )
502 : {
503 0 : TBVisualData aVisData;
504 0 : aVisData.Read( rS );
505 0 : rVisualData.push_back( aVisData );
506 0 : }
507 :
508 0 : rS.ReadInt32( iWCTBl ).ReadUInt16( reserved ).ReadUInt16( unused ).ReadInt32( cCtls );
509 :
510 0 : if ( cCtls )
511 : {
512 0 : for ( sal_Int32 index = 0; index < cCtls; ++index )
513 : {
514 0 : SwTBC aTBC;
515 0 : if ( !aTBC.Read( rS ) )
516 0 : return false;
517 0 : rTBC.push_back( aTBC );
518 0 : }
519 : }
520 0 : return true;
521 : }
522 :
523 : void
524 0 : SwCTB::Print( FILE* fp )
525 : {
526 0 : Indent a;
527 0 : indent_printf(fp, "[ 0x%x ] SwCTB - dump\n", nOffSet );
528 0 : indent_printf(fp, " name %s\n", OUStringToOString( name.getString(), RTL_TEXTENCODING_UTF8 ).getStr() );
529 0 : indent_printf(fp, " cbTBData size, in bytes, of this structure excluding the name, cCtls, and rTBC fields. %x\n", static_cast< unsigned int >( cbTBData ) );
530 :
531 0 : tb.Print(fp);
532 0 : for ( short counter = 0; counter < nVisualData; ++counter )
533 : {
534 0 : indent_printf( fp, " TBVisualData [%d]\n", counter);
535 0 : Indent b;
536 0 : rVisualData[ counter ].Print( fp );
537 0 : }
538 0 : 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 ) );
539 0 : if ( cCtls )
540 : {
541 0 : for ( sal_Int32 index = 0; index < cCtls; ++index )
542 : {
543 :
544 0 : indent_printf(fp, " dumping toolbar control 0x%x\n", static_cast< unsigned int >( index ) );
545 0 : rTBC[ index ].Print( fp );
546 : }
547 0 : }
548 0 : }
549 :
550 0 : bool SwCTB::ImportCustomToolBar( SwCTBWrapper& rWrapper, CustomToolBarImportHelper& helper )
551 : {
552 0 : static OUString sToolbarPrefix( "private:resource/toolbar/custom_" );
553 0 : bool bRes = false;
554 : try
555 : {
556 0 : if ( !tb.IsEnabled() )
557 0 : return true; // didn't fail, just ignoring
558 : // Create default setting
559 0 : uno::Reference< container::XIndexContainer > xIndexContainer( helper.getCfgManager()->createSettings(), uno::UNO_QUERY_THROW );
560 0 : uno::Reference< container::XIndexAccess > xIndexAccess( xIndexContainer, uno::UNO_QUERY_THROW );
561 0 : uno::Reference< beans::XPropertySet > xProps( xIndexContainer, uno::UNO_QUERY_THROW );
562 :
563 : // set UI name for toolbar
564 0 : xProps->setPropertyValue( "UIName", uno::makeAny( name.getString() ) );
565 :
566 0 : OUString sToolBarName = sToolbarPrefix.concat( name.getString() );
567 0 : for ( std::vector< SwTBC >::iterator it = rTBC.begin(); it != rTBC.end(); ++it )
568 : {
569 : // createToolBar item for control
570 0 : if ( !it->ImportToolBarControl( rWrapper, xIndexContainer, helper, IsMenuToolbar() ) )
571 0 : return false;
572 : }
573 :
574 : SAL_INFO("sw.ww8","Name of toolbar :-/ " << sToolBarName );
575 :
576 0 : helper.getCfgManager()->insertSettings( sToolBarName, xIndexAccess );
577 0 : helper.applyIcons();
578 : #if 1 // don't think this is necessary
579 0 : uno::Reference< ui::XUIConfigurationPersistence > xPersistence( helper.getCfgManager()->getImageManager(), uno::UNO_QUERY_THROW );
580 0 : xPersistence->store();
581 :
582 0 : xPersistence.set( helper.getCfgManager(), uno::UNO_QUERY_THROW );
583 0 : xPersistence->store();
584 : #endif
585 0 : bRes = true;
586 : }
587 0 : catch( const uno::Exception& e )
588 : {
589 : SAL_INFO("sw.ww8","***** For some reason we have an exception " << e.Message );
590 0 : bRes = false;
591 : }
592 0 : return bRes;
593 : }
594 :
595 0 : bool SwCTB::ImportMenuTB( SwCTBWrapper& rWrapper, const css::uno::Reference< css::container::XIndexContainer >& xIndexContainer, CustomToolBarImportHelper& rHelper )
596 : {
597 0 : for ( std::vector< SwTBC >::iterator it = rTBC.begin(); it != rTBC.end(); ++it )
598 : {
599 : // createToolBar item for control
600 0 : if ( !it->ImportToolBarControl( rWrapper, xIndexContainer, rHelper, true ) )
601 0 : return false;
602 : }
603 0 : return true;
604 : }
605 :
606 0 : SwTBC::SwTBC()
607 : {
608 0 : }
609 :
610 0 : SwTBC::~SwTBC()
611 : {
612 0 : }
613 :
614 0 : bool SwTBC::Read( SvStream &rS )
615 : {
616 : SAL_INFO("sw.ww8","SwTBC::Read() stream pos 0x" << std::hex << rS.Tell() );
617 0 : nOffSet = rS.Tell();
618 0 : if ( !tbch.Read( rS ) )
619 0 : return false;
620 0 : if ( tbch.getTcID() != 0x1 && tbch.getTcID() != 0x1051 )
621 : {
622 0 : cid.reset( new sal_uInt32 );
623 0 : rS.ReadUInt32( *cid );
624 : }
625 : // MUST exist if tbch.tct is not equal to 0x16
626 0 : if ( tbch.getTct() != 0x16 )
627 : {
628 0 : tbcd.reset( new TBCData( tbch ) );
629 0 : if ( !tbcd->Read( rS ) )
630 0 : return false;
631 : }
632 0 : return true;
633 : }
634 :
635 0 : void SwTBC::Print( FILE* fp )
636 : {
637 0 : Indent a;
638 0 : indent_printf(fp,"[ 0x%x ] SwTBC -- dump\n", nOffSet );
639 0 : indent_printf(fp," dumping header ( TBCHeader )\n");
640 0 : tbch.Print( fp );
641 0 : if ( cid.get() )
642 0 : indent_printf(fp," cid = 0x%x\n", static_cast< unsigned int >( *cid ) );
643 0 : if ( tbcd.get() )
644 : {
645 0 : indent_printf(fp," dumping toolbar data TBCData \n");
646 0 : tbcd->Print(fp);
647 0 : }
648 0 : }
649 :
650 : bool
651 0 : SwTBC::ImportToolBarControl( SwCTBWrapper& rWrapper, const css::uno::Reference< css::container::XIndexContainer >& toolbarcontainer, CustomToolBarImportHelper& helper, bool bIsMenuBar )
652 : {
653 : // cmtFci 0x1 Command based on a built-in command. See CidFci.
654 : // cmtMacro 0x2 Macro command. See CidMacro.
655 : // cmtAllocated 0x3 Allocated command. See CidAllocated.
656 : // cmtNil 0x7 No command. See Cid.
657 0 : bool bBuiltin = false;
658 0 : sal_uInt16 cmdId = 0;
659 0 : if ( cid.get() )
660 : {
661 0 : sal_uInt16 arg2 = ( *( cid.get() ) & 0xFFFF );
662 :
663 0 : sal_uInt8 cmt = ( arg2 & 0x7 );
664 0 : arg2 = ( arg2 >> 3 );
665 :
666 0 : switch ( cmt )
667 : {
668 : case 1:
669 : SAL_INFO("sw.ww8","cmt is cmtFci builtin command 0x" << std::hex << arg2);
670 0 : bBuiltin = true;
671 0 : cmdId = arg2;
672 0 : break;
673 : case 2:
674 : SAL_INFO("sw.ww8","cmt is cmtMacro macro 0x" << std::hex << arg2);
675 0 : break;
676 : case 3:
677 : SAL_INFO("sw.ww8","cmt is cmtAllocated [???] 0x" << std::hex << arg2);
678 0 : break;
679 : case 7:
680 : SAL_INFO("sw.ww8","cmt is cmNill no-phing 0x" << std::hex << arg2);
681 0 : break;
682 : default:
683 : SAL_INFO("sw.ww8","illegal 0x" << std::hex << cmt);
684 0 : break;
685 : }
686 : }
687 :
688 0 : if ( tbcd.get() )
689 : {
690 0 : std::vector< css::beans::PropertyValue > props;
691 0 : if ( bBuiltin )
692 : {
693 0 : OUString sCommand = helper.MSOCommandToOOCommand( cmdId );
694 0 : if ( !sCommand.isEmpty() )
695 : {
696 0 : beans::PropertyValue aProp;
697 :
698 0 : aProp.Name = "CommandURL";
699 0 : aProp.Value <<= sCommand;
700 0 : props.push_back( aProp );
701 0 : }
702 : }
703 0 : bool bBeginGroup = false;
704 0 : if ( ! tbcd->ImportToolBarControl( helper, props, bBeginGroup, bIsMenuBar ) )
705 0 : return false;
706 :
707 0 : TBCMenuSpecific* pMenu = tbcd->getMenuSpecific();
708 0 : if ( pMenu )
709 : {
710 : SAL_INFO("sw.ww8","** control has a menu, name of toolbar with menu items is " << pMenu->Name() );
711 : // search for SwCTB with the appropriate name ( it contains the
712 : // menu items, although we cannot import ( or create ) a menu on
713 : // a custom toolbar we can import the menu items in a separate
714 : // toolbar ( better than nothing )
715 0 : SwCTB* pCustTB = rWrapper.GetCustomizationData( pMenu->Name() );
716 0 : if ( pCustTB )
717 : {
718 0 : uno::Reference< container::XIndexContainer > xMenuDesc = document::IndexedPropertyValues::create( comphelper::getProcessComponentContext() );
719 0 : if ( !pCustTB->ImportMenuTB( rWrapper,xMenuDesc, helper ) )
720 0 : return false;
721 0 : if ( !bIsMenuBar )
722 : {
723 0 : if ( !helper.createMenu( pMenu->Name(), uno::Reference< container::XIndexAccess >( xMenuDesc, uno::UNO_QUERY ), true ) )
724 0 : return false;
725 : }
726 : else
727 : {
728 0 : beans::PropertyValue aProp;
729 0 : aProp.Name = "ItemDescriptorContainer";
730 0 : aProp.Value <<= xMenuDesc;
731 0 : props.push_back( aProp );
732 0 : }
733 : }
734 : }
735 :
736 0 : if ( bBeginGroup )
737 : {
738 : // insert spacer
739 0 : uno::Sequence< beans::PropertyValue > sProps( 1 );
740 0 : sProps[ 0 ].Name = "Type";
741 0 : sProps[ 0 ].Value = uno::makeAny( ui::ItemType::SEPARATOR_LINE );
742 0 : toolbarcontainer->insertByIndex( toolbarcontainer->getCount(), uno::makeAny( sProps ) );
743 : }
744 :
745 0 : uno::Sequence< beans::PropertyValue > sProps( props.size() );
746 0 : beans::PropertyValue* pProp = sProps.getArray();
747 :
748 0 : for ( std::vector< css::beans::PropertyValue >::iterator it = props.begin(); it != props.end(); ++it, ++pProp )
749 0 : *pProp = *it;
750 :
751 0 : toolbarcontainer->insertByIndex( toolbarcontainer->getCount(), uno::makeAny( sProps ) );
752 : }
753 0 : return true;
754 : }
755 :
756 : OUString
757 0 : SwTBC::GetCustomText()
758 : {
759 0 : OUString sCustomText;
760 0 : if ( tbcd.get() )
761 0 : sCustomText = tbcd->getGeneralInfo().CustomText();
762 0 : return sCustomText;
763 : }
764 :
765 : bool
766 1 : Xst::Read( SvStream& rS )
767 : {
768 : SAL_INFO("sw.ww8","Xst::Read() stream pos 0x" << std::hex << rS.Tell() );
769 1 : nOffSet = rS.Tell();
770 1 : sString = read_uInt16_PascalString(rS);
771 1 : return true;
772 : }
773 :
774 : void
775 0 : Xst::Print( FILE* fp )
776 : {
777 0 : Indent a;
778 0 : indent_printf( fp, "[ 0x%x ] Xst -- dump\n", nOffSet );
779 0 : indent_printf( fp, " %s", OUStringToOString( sString, RTL_TEXTENCODING_UTF8 ).getStr() );
780 0 : }
781 :
782 59 : Tcg::Tcg() : nTcgVer( -1 )
783 : {
784 59 : }
785 :
786 59 : bool Tcg::Read(SvStream &rS)
787 : {
788 : SAL_INFO("sw.ww8","Tcg::Read() stream pos 0x" << std::hex << rS.Tell() );
789 59 : nOffSet = rS.Tell();
790 59 : rS.ReadSChar( nTcgVer );
791 59 : if ( nTcgVer != -1 )
792 2 : return false;
793 57 : tcg.reset( new Tcg255() );
794 57 : return tcg->Read( rS );
795 : }
796 :
797 0 : void Tcg::Print( FILE* fp )
798 : {
799 0 : Indent a(true);
800 0 : indent_printf(fp, "[ 0x%x ] Tcg - dump %d\n", nOffSet, nTcgVer);
801 0 : indent_printf(fp," nTcgVer %d\n", nTcgVer);
802 0 : if ( tcg.get() )
803 0 : tcg->Print( fp );
804 0 : }
805 :
806 56 : bool Tcg::ImportCustomToolBar( SfxObjectShell& rDocSh )
807 : {
808 56 : if ( tcg.get() )
809 56 : return tcg->ImportCustomToolBar( rDocSh );
810 0 : return false;
811 : }
812 :
813 57 : Tcg255::Tcg255()
814 : {
815 57 : }
816 :
817 171 : Tcg255::~Tcg255()
818 : {
819 57 : std::vector< Tcg255SubStruct* >::iterator it = rgtcgData.begin();
820 62 : for ( ; it != rgtcgData.end(); ++it )
821 5 : delete *it;
822 114 : }
823 :
824 6 : bool Tcg255::processSubStruct( sal_uInt8 nId, SvStream &rS )
825 : {
826 6 : Tcg255SubStruct* pSubStruct = NULL;
827 6 : switch ( nId )
828 : {
829 : case 0x1:
830 : {
831 2 : pSubStruct = new PlfMcd( false ); // don't read the id
832 2 : break;
833 : }
834 : case 0x2:
835 : {
836 0 : pSubStruct = new PlfAcd( false );
837 0 : break;
838 : }
839 : case 0x3:
840 : case 0x4:
841 : {
842 0 : pSubStruct = new PlfKme( false );
843 0 : break;
844 : }
845 : case 0x10:
846 : {
847 2 : pSubStruct = new TcgSttbf( false );
848 2 : break;
849 : }
850 : case 0x11:
851 : {
852 1 : pSubStruct = new MacroNames( false );
853 1 : break;
854 : }
855 : case 0x12:
856 : {
857 0 : pSubStruct = new SwCTBWrapper( false );
858 0 : break;
859 : }
860 : default:
861 : SAL_INFO("sw.ww8","Unknown id 0x" << std::hex << nId);
862 1 : return false;
863 : }
864 5 : pSubStruct->ch = nId;
865 5 : if ( !pSubStruct->Read( rS ) )
866 0 : return false;
867 5 : rgtcgData.push_back( pSubStruct );
868 5 : return true;
869 : }
870 :
871 56 : bool Tcg255::ImportCustomToolBar( SfxObjectShell& rDocSh )
872 : {
873 : // Find the SwCTBWrapper
874 59 : for ( std::vector< Tcg255SubStruct* >::const_iterator it = rgtcgData.begin(); it != rgtcgData.end(); ++it )
875 : {
876 3 : if ( (*it)->id() == 0x12 )
877 : {
878 : // not so great, shouldn't really have to do a horror casting
879 0 : SwCTBWrapper* pCTBWrapper = dynamic_cast< SwCTBWrapper* > ( *it );
880 0 : if ( pCTBWrapper )
881 : {
882 0 : if ( !pCTBWrapper->ImportCustomToolBar( rDocSh ) )
883 0 : return false;
884 : }
885 : }
886 : }
887 56 : return true;
888 : }
889 :
890 57 : bool Tcg255::Read(SvStream &rS)
891 : {
892 : SAL_INFO("sw.ww8","Tcg255::Read() stream pos 0x" << std::hex << rS.Tell() );
893 57 : nOffSet = rS.Tell();
894 57 : sal_uInt8 nId = 0x40;
895 57 : rS.ReadUChar( nId );
896 119 : while ( nId != 0x40 )
897 : {
898 6 : if ( !processSubStruct( nId, rS ) )
899 1 : return false;
900 5 : nId = 0x40;
901 5 : rS.ReadUChar( nId );
902 : }
903 56 : return true;
904 : // Peek at
905 : }
906 :
907 0 : void Tcg255::Print( FILE* fp)
908 : {
909 0 : Indent a;
910 0 : indent_printf(fp, "[ 0x%x ] Tcg255 - dump\n", nOffSet );
911 0 : indent_printf(fp, " contains %d sub records\n", rgtcgData.size() );
912 0 : std::vector< Tcg255SubStruct* >::iterator it = rgtcgData.begin();
913 0 : std::vector< Tcg255SubStruct* >::iterator it_end = rgtcgData.end();
914 :
915 0 : for( sal_Int32 count = 1; it != it_end ; ++it, ++count )
916 : {
917 0 : Indent b;
918 0 : indent_printf(fp, " [%d] Tcg255SubStruct \n", static_cast< unsigned int >( count ) );
919 0 : (*it)->Print(fp);
920 0 : }
921 0 : }
922 :
923 5 : Tcg255SubStruct::Tcg255SubStruct( bool bReadId ) : mbReadId( bReadId ), ch(0)
924 : {
925 5 : }
926 :
927 5 : bool Tcg255SubStruct::Read(SvStream &rS)
928 : {
929 : SAL_INFO("sw.ww8","Tcg255SubStruct::Read() stream pos 0x" << std::hex << rS.Tell() );
930 5 : nOffSet = rS.Tell();
931 5 : if ( mbReadId )
932 0 : rS.ReadUChar( ch );
933 5 : return true;
934 : }
935 :
936 2 : PlfMcd::PlfMcd(bool bReadId)
937 : : Tcg255SubStruct(bReadId)
938 2 : , iMac(0)
939 : {
940 2 : }
941 :
942 2 : bool PlfMcd::Read(SvStream &rS)
943 : {
944 : SAL_INFO("sw.ww8","PffMcd::Read() stream pos 0x" << std::hex << rS.Tell() );
945 2 : nOffSet = rS.Tell();
946 2 : Tcg255SubStruct::Read( rS );
947 2 : rS.ReadInt32( iMac );
948 2 : if ( iMac )
949 : {
950 2 : rgmcd.resize(iMac);
951 4 : for ( sal_Int32 index = 0; index < iMac; ++index )
952 : {
953 2 : if ( !rgmcd[ index ].Read( rS ) )
954 0 : return false;
955 : }
956 : }
957 2 : return true;
958 : }
959 :
960 0 : void PlfMcd::Print( FILE* fp )
961 : {
962 0 : Indent a;
963 0 : indent_printf(fp, "[ 0x%x ] PlfMcd ( Tcg255SubStruct ) - dump\n", nOffSet );
964 0 : indent_printf(fp, " contains %d MCD records\n", static_cast<int>( iMac ) );
965 0 : for ( sal_Int32 count=0; count < iMac; ++count )
966 : {
967 0 : Indent b;
968 0 : indent_printf(fp, "[%d] MCD\n", static_cast< int >( count ) );
969 0 : rgmcd[ count ].Print( fp );
970 0 : }
971 :
972 0 : }
973 :
974 0 : PlfAcd::PlfAcd( bool bReadId ) : Tcg255SubStruct( bReadId )
975 : ,iMac(0)
976 0 : ,rgacd(NULL)
977 : {
978 0 : }
979 :
980 0 : PlfAcd::~PlfAcd()
981 : {
982 0 : delete[] rgacd;
983 0 : }
984 :
985 0 : bool PlfAcd::Read( SvStream &rS)
986 : {
987 : SAL_INFO("sw.ww8","PffAcd::Read() stream pos 0x" << std::hex << rS.Tell() );
988 0 : nOffSet = rS.Tell();
989 0 : Tcg255SubStruct::Read( rS );
990 0 : rS.ReadInt32( iMac );
991 0 : if ( iMac )
992 : {
993 0 : rgacd = new Acd[ iMac ];
994 0 : for ( sal_Int32 index = 0; index < iMac; ++index )
995 : {
996 0 : if ( !rgacd[ index ].Read( rS ) )
997 0 : return false;
998 : }
999 : }
1000 0 : return true;
1001 : }
1002 :
1003 0 : void PlfAcd::Print( FILE* fp )
1004 : {
1005 0 : Indent a;
1006 0 : indent_printf(fp, "[ 0x%x ] PlfAcd ( Tcg255SubStruct ) - dump\n", nOffSet );
1007 0 : indent_printf(fp, " contains %d ACD records\n", static_cast< int >( iMac ) );
1008 0 : for ( sal_Int32 count=0; count < iMac; ++count )
1009 : {
1010 0 : Indent b;
1011 0 : indent_printf(fp, "[%d] ACD\n", static_cast< int >( count ) );
1012 0 : rgacd[ count ].Print( fp );
1013 0 : }
1014 :
1015 0 : }
1016 :
1017 0 : PlfKme::PlfKme( bool bReadId ) : Tcg255SubStruct( bReadId )
1018 : ,iMac( 0 )
1019 0 : ,rgkme( NULL )
1020 : {
1021 0 : }
1022 :
1023 0 : PlfKme::~PlfKme()
1024 : {
1025 0 : delete[] rgkme;
1026 0 : }
1027 :
1028 0 : bool PlfKme::Read(SvStream &rS)
1029 : {
1030 : SAL_INFO("sw.ww8","PlfKme::Read() stream pos 0x" << std::hex << rS.Tell() );
1031 0 : nOffSet = rS.Tell();
1032 0 : Tcg255SubStruct::Read( rS );
1033 0 : rS.ReadInt32( iMac );
1034 0 : if ( iMac )
1035 : {
1036 0 : rgkme = new Kme[ iMac ];
1037 0 : for( sal_Int32 index=0; index<iMac; ++index )
1038 : {
1039 0 : if ( !rgkme[ index ].Read( rS ) )
1040 0 : return false;
1041 : }
1042 : }
1043 0 : return true;
1044 : }
1045 :
1046 0 : void PlfKme::Print( FILE* fp )
1047 : {
1048 0 : Indent a;
1049 0 : indent_printf(fp, "[ 0x%x ] PlfKme ( Tcg255SubStruct ) - dump\n", nOffSet );
1050 0 : indent_printf(fp, " contains %d Kme records\n", static_cast< int >( iMac ) );
1051 0 : for ( sal_Int32 count=0; count < iMac; ++count )
1052 : {
1053 0 : Indent b;
1054 0 : indent_printf(fp, "[%d] Kme\n", static_cast< int >( count ) );
1055 0 : rgkme[ count ].Print( fp );
1056 0 : }
1057 :
1058 0 : }
1059 :
1060 2 : TcgSttbf::TcgSttbf( bool bReadId ) : Tcg255SubStruct( bReadId )
1061 : {
1062 2 : }
1063 :
1064 2 : bool TcgSttbf::Read( SvStream &rS)
1065 : {
1066 : SAL_INFO("sw.ww8","TcgSttbf::Read() stream pos 0x" << std::hex << rS.Tell() );
1067 2 : nOffSet = rS.Tell();
1068 2 : Tcg255SubStruct::Read( rS );
1069 2 : return sttbf.Read( rS );
1070 : }
1071 :
1072 0 : void TcgSttbf::Print( FILE* fp )
1073 : {
1074 0 : Indent a;
1075 0 : indent_printf(fp,"[ 0x%x ] TcgSttbf - dump\n", nOffSet );
1076 0 : sttbf.Print( fp );
1077 0 : }
1078 :
1079 2 : TcgSttbfCore::TcgSttbfCore() : fExtend( 0 )
1080 : ,cData( 0 )
1081 : ,cbExtra( 0 )
1082 2 : ,dataItems( NULL )
1083 : {
1084 2 : }
1085 :
1086 4 : TcgSttbfCore::~TcgSttbfCore()
1087 : {
1088 2 : delete[] dataItems;
1089 2 : }
1090 :
1091 2 : bool TcgSttbfCore::Read( SvStream& rS )
1092 : {
1093 : SAL_INFO("sw.ww8","TcgSttbfCore::Read() stream pos 0x" << std::hex << rS.Tell() );
1094 2 : nOffSet = rS.Tell();
1095 2 : rS.ReadUInt16( fExtend ).ReadUInt16( cData ).ReadUInt16( cbExtra );
1096 2 : if ( cData )
1097 : {
1098 2 : dataItems = new SBBItem[ cData ];
1099 4 : for ( sal_Int32 index = 0; index < cData; ++index )
1100 : {
1101 2 : rS.ReadUInt16( dataItems[ index ].cchData );
1102 2 : dataItems[ index ].data = read_uInt16s_ToOUString(rS, dataItems[index].cchData);
1103 2 : rS.ReadUInt16( dataItems[ index ].extraData );
1104 : }
1105 : }
1106 2 : return true;
1107 : }
1108 :
1109 0 : void TcgSttbfCore::Print( FILE* fp )
1110 : {
1111 0 : Indent a;
1112 0 : indent_printf( fp, "[ 0x%x ] TcgSttbfCore - dump\n");
1113 0 : indent_printf( fp, " fExtend 0x%x [expected 0xFFFF ]\n", fExtend );
1114 0 : indent_printf( fp, " cbExtra 0x%x [expected 0x02 ]\n", cbExtra );
1115 0 : indent_printf( fp, " cData no. or string data items %d (0x%x)\n", cData, cData );
1116 :
1117 0 : if ( cData )
1118 : {
1119 0 : for ( sal_Int32 index = 0; index < cData; ++index )
1120 0 : 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 ), OUStringToOString( dataItems[ index ].data, RTL_TEXTENCODING_UTF8 ).getStr(), dataItems[ index ].extraData );
1121 0 : }
1122 :
1123 0 : }
1124 :
1125 1 : MacroNames::MacroNames( bool bReadId ) : Tcg255SubStruct( bReadId )
1126 : ,iMac( 0 )
1127 1 : ,rgNames( NULL )
1128 : {
1129 1 : }
1130 :
1131 3 : MacroNames::~MacroNames()
1132 : {
1133 1 : delete[] rgNames;
1134 2 : }
1135 :
1136 1 : bool MacroNames::Read( SvStream &rS)
1137 : {
1138 : SAL_INFO("sw.ww8","MacroNames::Read() stream pos 0x" << std::hex << rS.Tell() );
1139 1 : nOffSet = rS.Tell();
1140 1 : Tcg255SubStruct::Read( rS );
1141 1 : rS.ReadUInt16( iMac );
1142 1 : if ( iMac )
1143 : {
1144 1 : rgNames = new MacroName[ iMac ];
1145 2 : for ( sal_Int32 index = 0; index < iMac; ++index )
1146 : {
1147 1 : if ( !rgNames[ index ].Read( rS ) )
1148 0 : return false;
1149 : }
1150 : }
1151 1 : return true;
1152 : }
1153 :
1154 0 : void MacroNames::Print( FILE* fp )
1155 : {
1156 0 : Indent a;
1157 0 : indent_printf(fp, "[ 0x%x ] MacroNames ( Tcg255SubStruct ) - dump\n");
1158 0 : indent_printf(fp, " contains %d MacroName records\n", iMac );
1159 0 : for ( sal_Int32 count=0; count < iMac; ++count )
1160 : {
1161 0 : Indent b;
1162 0 : indent_printf(fp, "[%d] MacroName\n", static_cast<int>( count ) );
1163 0 : rgNames[ count ].Print( fp );
1164 0 : }
1165 :
1166 0 : }
1167 :
1168 1 : MacroName::MacroName():ibst(0)
1169 : {
1170 1 : }
1171 :
1172 1 : bool MacroName::Read(SvStream &rS)
1173 : {
1174 : SAL_INFO("sw.ww8","MacroName::Read() stream pos 0x" << std::hex << rS.Tell() );
1175 1 : nOffSet = rS.Tell();
1176 1 : rS.ReadUInt16( ibst );
1177 1 : return xstz.Read( rS );
1178 : }
1179 :
1180 0 : void MacroName::Print( FILE* fp )
1181 : {
1182 0 : Indent a;
1183 0 : indent_printf( fp, "[ 0x%x ] MacroName - dump");
1184 0 : indent_printf( fp," index - 0x%x has associated following record\n", ibst );
1185 0 : xstz.Print( fp );
1186 0 : }
1187 :
1188 1 : Xstz::Xstz():chTerm(0)
1189 : {
1190 1 : }
1191 :
1192 : bool
1193 1 : Xstz::Read(SvStream &rS)
1194 : {
1195 : SAL_INFO("sw.ww8","Xstz::Read() stream pos 0x" << std::hex << rS.Tell() );
1196 1 : nOffSet = rS.Tell();
1197 1 : if ( !xst.Read( rS ) )
1198 0 : return false;
1199 1 : rS.ReadUInt16( chTerm );
1200 1 : if ( chTerm != 0 ) // should be an assert
1201 0 : return false;
1202 1 : return true;
1203 : }
1204 :
1205 0 : void Xstz::Print( FILE* fp )
1206 : {
1207 0 : Indent a;
1208 0 : indent_printf(fp,"[ 0x%x ] Xstz -- dump\n", nOffSet );
1209 0 : indent_printf(fp," Xst\n");
1210 0 : xst.Print( fp );
1211 0 : indent_printf(fp," chterm 0x%x ( should be zero )\n", chTerm);
1212 0 : }
1213 :
1214 0 : Kme::Kme() : reserved1(0)
1215 : ,reserved2(0)
1216 : ,kcm1(0)
1217 : ,kcm2(0)
1218 : ,kt(0)
1219 0 : ,param(0)
1220 : {
1221 0 : }
1222 :
1223 0 : Kme::~Kme()
1224 : {
1225 0 : }
1226 :
1227 : bool
1228 0 : Kme::Read(SvStream &rS)
1229 : {
1230 : SAL_INFO("sw.ww8","Kme::Read() stream pos 0x" << std::hex << rS.Tell() );
1231 0 : nOffSet = rS.Tell();
1232 0 : rS.ReadInt16( reserved1 ).ReadInt16( reserved2 ).ReadUInt16( kcm1 ).ReadUInt16( kcm2 ).ReadUInt16( kt ).ReadUInt32( param );
1233 0 : return true;
1234 : }
1235 :
1236 0 : void Kme::Print( FILE* fp )
1237 : {
1238 0 : Indent a;
1239 :
1240 0 : indent_printf( fp, "[ 0x%x ] Kme - dump\n", nOffSet );
1241 0 : indent_printf( fp, " reserved1 0x%x [expected 0x0 ]\n", reserved1 );
1242 0 : indent_printf( fp, " reserved2 0x%x [expected 0x0 ]\n", reserved2 );
1243 0 : indent_printf( fp, " kcm1 0x%x [shortcut key]\n", kcm1 );
1244 0 : indent_printf( fp, " kcm2 0x%x [shortcut key]\n", kcm2 );
1245 0 : indent_printf( fp, " kt 0x%x \n", kt );
1246 0 : indent_printf( fp, " param 0x%x \n", static_cast< unsigned int >( param ) );
1247 0 : }
1248 :
1249 0 : Acd::Acd() : ibst( 0 )
1250 0 : , fciBasedOnABC( 0 )
1251 : {
1252 0 : }
1253 :
1254 0 : bool Acd::Read(SvStream &rS)
1255 : {
1256 : SAL_INFO("sw.ww8","Acd::Read() stream pos 0x" << std::hex << rS.Tell() );
1257 0 : nOffSet = rS.Tell();
1258 0 : rS.ReadInt16( ibst ).ReadUInt16( fciBasedOnABC );
1259 0 : return true;
1260 : }
1261 :
1262 0 : void Acd::Print( FILE* fp )
1263 : {
1264 0 : Indent a;
1265 0 : indent_printf( fp,"[ 0x%x ] ACD - dump\n", nOffSet );
1266 : // #TODO flesh out interpretation of these values
1267 0 : indent_printf( fp," ibst 0x%x\n", ibst);
1268 0 : indent_printf( fp," fciBaseObABC 0x%x\n", fciBasedOnABC);
1269 0 : }
1270 :
1271 2 : MCD::MCD() : reserved1(0x56)
1272 : ,reserved2( 0 )
1273 : ,ibst( 0 )
1274 : ,ibstName( 0 )
1275 : ,reserved3( 0xFFFF )
1276 : ,reserved4( 0 )
1277 : ,reserved5( 0 )
1278 : ,reserved6( 0 )
1279 2 : ,reserved7( 0 )
1280 : {
1281 2 : }
1282 :
1283 0 : MCD::MCD(const MCD& rO)
1284 : : TBBase(rO)
1285 : , reserved1(rO.reserved1)
1286 : , reserved2(rO.reserved2)
1287 : , ibst(rO.ibst)
1288 : , ibstName(rO.ibstName)
1289 : , reserved3(rO.reserved3)
1290 : , reserved4(rO.reserved4)
1291 : , reserved5(rO.reserved5)
1292 : , reserved6(rO.reserved6)
1293 0 : , reserved7(rO.reserved7)
1294 : {
1295 0 : }
1296 :
1297 0 : MCD& MCD::operator=(const MCD& rO)
1298 : {
1299 0 : if (this != &rO)
1300 : {
1301 0 : reserved1 = rO.reserved1;
1302 0 : reserved2 = rO.reserved2;
1303 0 : ibst = rO.ibst;
1304 0 : ibstName = rO.ibstName;
1305 0 : reserved3 = rO.reserved3;
1306 0 : reserved4 = rO.reserved4;
1307 0 : reserved5 = rO.reserved5;
1308 0 : reserved6 = rO.reserved6;
1309 0 : reserved7 = rO.reserved7;
1310 : }
1311 0 : return *this;
1312 : }
1313 :
1314 2 : bool MCD::Read(SvStream &rS)
1315 : {
1316 : SAL_INFO("sw.ww8","MCD::Read() stream pos 0x" << rS.Tell() );
1317 2 : nOffSet = rS.Tell();
1318 2 : rS.ReadSChar( reserved1 ).ReadUChar( reserved2 ).ReadUInt16( ibst ).ReadUInt16( ibstName ).ReadUInt16( reserved3 );
1319 2 : rS.ReadUInt32( reserved4 ).ReadUInt32( reserved5 ).ReadUInt32( reserved6 ).ReadUInt32( reserved7 );
1320 2 : return true;
1321 : }
1322 :
1323 0 : void MCD::Print( FILE* fp )
1324 : {
1325 0 : Indent a;
1326 0 : indent_printf( fp, "[ 0x%x ] MCD - dump\n", nOffSet );
1327 0 : indent_printf( fp, " reserved1 0x%x [expected 0x56 ]\n", reserved1 );
1328 0 : indent_printf( fp, " reserved2 0x%x [expected 0x0 ]\n", reserved2 );
1329 0 : indent_printf( fp, " ibst 0x%x specifies macro with MacroName.xstz = 0x%x\n", ibst, ibst );
1330 0 : indent_printf( fp, " ibstName 0x%x index into command string table ( TcgSttbf.sttbf )\n", ibstName );
1331 :
1332 0 : indent_printf( fp, " reserved3 0x%x [expected 0xFFFF ]\n", reserved3 );
1333 0 : indent_printf( fp, " reserved4 0x%x\n", static_cast< unsigned int >( reserved4 ) );
1334 0 : indent_printf( fp, " reserved5 0x%x [expected 0x0 ]\n", static_cast< unsigned int >( reserved5 ) );
1335 0 : indent_printf( fp, " reserved6 0x%x\n", static_cast< unsigned int >( reserved6 ) );
1336 0 : indent_printf( fp, " reserved7 0x%x\n", static_cast< unsigned int >( reserved7 ) );
1337 0 : }
1338 :
1339 : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
|