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