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