LibreOffice Module sw (master)  1
ww8toolbar.cxx
Go to the documentation of this file.
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/beans/XPropertySet.hpp>
15 #include <com/sun/star/document/IndexedPropertyValues.hpp>
16 #include <com/sun/star/ui/XUIConfigurationPersistence.hpp>
17 #include <com/sun/star/ui/theModuleUIConfigurationManagerSupplier.hpp>
18 #include <com/sun/star/lang/XSingleComponentFactory.hpp>
19 #include <com/sun/star/ui/ItemType.hpp>
20 #include <fstream>
22 #include <comphelper/sequence.hxx>
23 #include <tools/diagnose_ex.h>
24 #include <unotools/configmgr.hxx>
25 #include <vcl/graph.hxx>
26 #include <map>
27 #include <sal/log.hxx>
28 
29 using namespace com::sun::star;
30 
31 // no. of visual data elements in a SwCTB ( fixed )
32 const short nVisualData = 5;
33 
34 typedef std::map< sal_Int16, OUString > IdToString;
35 
37 {
40 
41 public:
43  virtual OUString MSOCommandToOOCommand( sal_Int16 msoCmd ) override;
44  virtual OUString MSOTCIDToOOCommand( sal_Int16 key ) override;
45 };
46 
48 {
49  // mso command id to ooo command string
50  // #FIXME and *HUNDREDS* of id's to added here
51  msoToOOcmd[ 0x20b ] = ".uno:CloseDoc";
52  msoToOOcmd[ 0x50 ] = ".uno:Open";
53 
54  // mso tcid to ooo command string
55  // #FIXME and *HUNDREDS* of id's to added here
56  tcidToOOcmd[ 0x9d9 ] = ".uno:Print";
57 }
58 
60 {
61  IdToString::iterator it = msoToOOcmd.find( key );
62  if ( it != msoToOOcmd.end() )
63  return it->second;
64  return OUString();
65 }
66 
68 {
69  IdToString::iterator it = tcidToOOcmd.find( key );
70  if ( it != tcidToOOcmd.end() )
71  return it->second;
72  return OUString();
73 }
74 
76 reserved2(0)
77 ,reserved3(0)
78 ,reserved4(0)
79 ,reserved5(0)
80 ,cbTBD(0)
81 ,cCust(0)
82 ,cbDTBC(0)
83 ,rtbdc(0)
84 {
85 }
86 
88 {
89 }
90 
92 {
93  if ( index < 0 || index >= static_cast<sal_Int16>( rCustomizations.size() ) )
94  return nullptr;
95  return &rCustomizations[ index ];
96 }
97 
98 SwCTB* SwCTBWrapper::GetCustomizationData( const OUString& sTBName )
99 {
100  auto it = std::find_if(rCustomizations.begin(), rCustomizations.end(),
101  [&sTBName](Customization& rCustomization) {
102  SwCTB* pCTB = rCustomization.GetCustomizationData();
103  return pCTB && pCTB->GetName() == sTBName;
104  });
105  if (it != rCustomizations.end())
106  return it->GetCustomizationData();
107  return nullptr;
108 }
109 
111 {
112  SAL_INFO("sw.ww8","SwCTBWrapper::Read() stream pos 0x" << std::hex << rS.Tell() );
113  nOffSet = rS.Tell();
114  Tcg255SubStruct::Read( rS );
117  long nExpectedPos = rS.Tell() + cbDTBC;
118  if ( cbDTBC )
119  {
120  // cbDTBC is the size in bytes of the SwTBC array
121  // but the size of a SwTBC element is dynamic ( and this relates to TBDelta's
122  int nStart = rS.Tell();
123 
124  int bytesToRead;
125  // cbDTBC specifies the size ( in bytes ) taken by an array ( of unspecified size )
126  // of SwTBC records ( SwTBC records have dynamic length, so we need to check our position
127  // after each read )
128  do
129  {
130  SwTBC aTBC;
131  if ( !aTBC.Read( rS ) )
132  return false;
133  rtbdc.push_back( aTBC );
134  bytesToRead = cbDTBC - ( rS.Tell() - nStart );
135  } while ( bytesToRead > 0 );
136  }
137  if ( static_cast< long >( rS.Tell() ) != nExpectedPos )
138  {
139  // Strange error condition, shouldn't happen ( but does in at least
140  // one test document ) In the case where it happens the SwTBC &
141  // TBCHeader records seem blank??? ( and incorrect )
142  SAL_WARN_IF( static_cast< long >(rS.Tell()) != nExpectedPos, "sw.ww8","### Error: Expected pos not equal to actual pos after reading rtbdc");
143  SAL_INFO("sw.ww8","\tPos now is 0x" << std::hex << rS.Tell() << " should be 0x" << std::hex << nExpectedPos );
144  // seek to correct position after rtbdc
145  rS.Seek( nExpectedPos );
146  }
147  if (cCust)
148  {
149  //Each customization takes a min of 8 bytes
150  size_t nMaxPossibleRecords = rS.remainingSize() / 8;
151  if (cCust > nMaxPossibleRecords)
152  {
153  return false;
154  }
155  for (sal_uInt16 index = 0; index < cCust; ++index)
156  {
157  Customization aCust( this );
158  if ( !aCust.Read( rS ) )
159  return false;
160  rCustomizations.push_back( aCust );
161  }
162  }
163  for ( const auto& rIndex : dropDownMenuIndices )
164  {
165  if (rIndex < 0 || static_cast<size_t>(rIndex) >= rCustomizations.size())
166  continue;
167  rCustomizations[rIndex].bIsDroppedMenuTB = true;
168  }
169  return rS.good();
170 }
171 
172 SwTBC* SwCTBWrapper::GetTBCAtOffset( sal_uInt32 nStreamOffset )
173 {
174  auto it = std::find_if(rtbdc.begin(), rtbdc.end(),
175  [&nStreamOffset](SwTBC& rItem) { return rItem.GetOffset() == nStreamOffset; });
176  if ( it != rtbdc.end() )
177  return &(*it);
178  return nullptr;
179 }
180 
182 {
183  for ( auto& rCustomization : rCustomizations )
184  {
185  try
186  {
187  css::uno::Reference<css::ui::XUIConfigurationManager> xCfgMgr;
189  {
190  uno::Reference< uno::XComponentContext > xContext = ::comphelper::getProcessComponentContext();
191  uno::Reference< ui::XModuleUIConfigurationManagerSupplier > xAppCfgSupp( ui::theModuleUIConfigurationManagerSupplier::get(xContext) );
192  xCfgMgr = xAppCfgSupp->getUIConfigurationManager("com.sun.star.text.TextDocument");
193  }
194  CustomToolBarImportHelper helper(rDocSh, xCfgMgr);
196 
197  if ( !rCustomization.ImportCustomToolBar( *this, helper ) )
198  return false;
199  }
200  catch (...)
201  {
202  continue;
203  }
204  }
205  return true;
206 }
207 
209  : tbidForTBD( 0 )
210  , reserved1( 0 )
211  , ctbds( 0 )
212  , pWrapper( wrapper )
213  , bIsDroppedMenuTB( false )
214 {
215 }
216 
218 {
219 }
220 
222 {
223  SAL_INFO("sw.ww8","Customization::Read() stream pos 0x" << std::hex << rS.Tell() );
224  nOffSet = rS.Tell();
226  if ( tbidForTBD )
227  {
228  //each TBDelta is at least 18 bytes in size
229  size_t nMaxAvailableRecords = rS.remainingSize() / 18;
230  if (ctbds > nMaxAvailableRecords)
231  return false;
232  for (sal_uInt16 index = 0; index < ctbds; ++index)
233  {
234  TBDelta aTBDelta;
235  if (!aTBDelta.Read( rS ) )
236  return false;
237  customizationDataTBDelta.push_back( aTBDelta );
238  // Only set the drop down for menus associated with standard toolbar
239  if ( aTBDelta.ControlDropsToolBar() && tbidForTBD == 0x25 )
241  }
242  }
243  else
244  {
245  customizationDataCTB.reset( new SwCTB() );
246  if ( !customizationDataCTB->Read( rS ) )
247  return false;
248  }
249  return rS.good();
250 }
251 
253 {
254  if ( tbidForTBD == 0x25 ) // we can handle in a limited way additions the built-in menu bar
255  {
256  for ( auto& rTBDelta : customizationDataTBDelta )
257  {
258  // for each new menu ( control that drops a toolbar )
259  // import a toolbar
260  if ( rTBDelta.ControlIsInserted() && rTBDelta.ControlDropsToolBar() )
261  {
262  Customization* pCust = pWrapper->GetCustomizaton( rTBDelta.CustomizationIndex() );
263  if ( pCust )
264  {
265  // currently only support built-in menu
266  const OUString sMenuBar( "private:resource/menubar/menubar" );
267 
268  // Get menu name
269  SwTBC* pTBC = pWrapper->GetTBCAtOffset( rTBDelta.TBCStreamOffset() );
270  if ( !pTBC )
271  return false;
272  const OUString sMenuName = pTBC->GetCustomText().replace('&','~');
273 
274  // see if the document has already setting for the menubar
275 
276  uno::Reference< container::XIndexContainer > xIndexContainer;
277  bool bHasSettings = false;
278  if ( helper.getCfgManager()->hasSettings( sMenuBar ) )
279  {
280  xIndexContainer.set( helper.getCfgManager()->getSettings( sMenuBar, true ), uno::UNO_QUERY_THROW );
281  bHasSettings = true;
282  }
283  else
284  {
285  if ( helper.getAppCfgManager()->hasSettings( sMenuBar ) )
286  xIndexContainer.set( helper.getAppCfgManager()->getSettings( sMenuBar, true ), uno::UNO_QUERY_THROW );
287  else
288  xIndexContainer.set( helper.getAppCfgManager()->createSettings(), uno::UNO_SET_THROW );
289  }
290 
291  uno::Reference< lang::XSingleComponentFactory > xSCF( xIndexContainer, uno::UNO_QUERY_THROW );
292  uno::Reference< uno::XComponentContext > xContext(
294  // create the popup menu
295  uno::Sequence< beans::PropertyValue > aPopupMenu( 4 );
296  aPopupMenu[0].Name = "CommandURL";
297  aPopupMenu[0].Value <<= "vnd.openoffice.org:" + sMenuName;
298  aPopupMenu[1].Name = "Label";
299  aPopupMenu[1].Value <<= sMenuName;
300  aPopupMenu[2].Name = "Type";
301  aPopupMenu[2].Value <<= sal_Int32( 0 );
302  aPopupMenu[3].Name = "ItemDescriptorContainer";
303  uno::Reference< container::XIndexContainer > xMenuContainer( xSCF->createInstanceWithContext( xContext ), uno::UNO_QUERY_THROW );
304  aPopupMenu[3].Value <<= xMenuContainer;
305  if ( pCust->customizationDataCTB.get() && !pCust->customizationDataCTB->ImportMenuTB( rWrapper, xMenuContainer, helper ) )
306  return false;
307  SAL_INFO("sw.ww8","** there are " << xIndexContainer->getCount() << " menu items on the bar, inserting after that");
308  xIndexContainer->insertByIndex( xIndexContainer->getCount(), uno::makeAny( aPopupMenu ) );
309 
310  if ( bHasSettings )
311  helper.getCfgManager()->replaceSettings( sMenuBar, uno::Reference< container::XIndexAccess >( xIndexContainer, uno::UNO_QUERY_THROW ) );
312  else
313  helper.getCfgManager()->insertSettings( sMenuBar, uno::Reference< container::XIndexAccess >( xIndexContainer, uno::UNO_QUERY_THROW ) );
314 
315  uno::Reference< ui::XUIConfigurationPersistence > xPersistence( helper.getCfgManager(), uno::UNO_QUERY_THROW );
316  xPersistence->store();
317  }
318  }
319  }
320  return true;
321  }
322  return true;
323 }
324 
326 {
327  if ( tbidForTBD == 0x25 )
328  return ImportMenu( rWrapper, helper );
329  if ( !customizationDataCTB.get() )
330  return false;
331  if ( !customizationDataCTB->IsMenuToolbar() )
332  {
333  if ( !customizationDataCTB->ImportCustomToolBar( rWrapper, helper ) )
334  return false;
335  }
336  return true;
337 }
338 
340  : doprfatendFlags(0)
341  , ibts(0)
342  , cidNext(0)
343  , cid(0)
344  , fc(0)
345  , CiTBDE(0)
346  , cbTBC(0)
347 {
348 }
349 
351 {
352  return ( ( doprfatendFlags & 0x3 ) == 0x1 );
353 }
354 
356 {
357  return !( CiTBDE & 0x8000 );
358 }
359 
360 
362 {
363  sal_Int16 nIndex = CiTBDE;
364  nIndex = nIndex >> 1;
365  nIndex &= 0x1ff; // only 13 bits are relevant
366  return nIndex;
367 }
368 
370 {
371  SAL_INFO("sw.ww8","TBDelta::Read() stream pos 0x" << std::hex << rS.Tell() );
372  nOffSet = rS.Tell();
375  return rS.good();
376 }
377 
378 SwCTB::SwCTB() : cbTBData( 0 )
379 ,iWCTBl( 0 )
380 ,reserved( 0 )
381 ,unused( 0 )
382 ,cCtls( 0 )
383 {
384 }
385 
387 {
388 }
389 
391 {
392  return tb.IsMenuToolbar();
393 }
394 
396 {
397  SAL_INFO("sw.ww8","SwCTB::Read() stream pos 0x" << std::hex << rS.Tell() );
398  nOffSet = rS.Tell();
399  if ( !name.Read( rS ) )
400  return false;
401  rS.ReadInt32( cbTBData );
402  if ( !tb.Read( rS ) )
403  return false;
404  for ( short index = 0; index < nVisualData; ++index )
405  {
406  TBVisualData aVisData;
407  aVisData.Read( rS );
408  rVisualData.push_back( aVisData );
409  }
410 
412 
413  if ( cCtls )
414  {
415  for ( sal_Int32 index = 0; index < cCtls; ++index )
416  {
417  SwTBC aTBC;
418  if ( !aTBC.Read( rS ) )
419  return false;
420  rTBC.push_back( aTBC );
421  }
422  }
423  return rS.good();
424 }
425 
427 {
428  bool bRes = false;
429  try
430  {
431  if ( !tb.IsEnabled() )
432  return true; // didn't fail, just ignoring
433  // Create default setting
434  uno::Reference< container::XIndexContainer > xIndexContainer( helper.getCfgManager()->createSettings(), uno::UNO_SET_THROW );
435  uno::Reference< container::XIndexAccess > xIndexAccess( xIndexContainer, uno::UNO_QUERY_THROW );
436  uno::Reference< beans::XPropertySet > xProps( xIndexContainer, uno::UNO_QUERY_THROW );
437 
438  // set UI name for toolbar
439  xProps->setPropertyValue( "UIName", uno::makeAny( name.getString() ) );
440 
441  const OUString sToolBarName = "private:resource/toolbar/custom_" + name.getString();
442  for ( auto& rItem : rTBC )
443  {
444  // createToolBar item for control
445  if ( !rItem.ImportToolBarControl( rWrapper, xIndexContainer, helper, IsMenuToolbar() ) )
446  return false;
447  }
448 
449  SAL_INFO("sw.ww8","Name of toolbar :-/ " << sToolBarName );
450 
451  helper.getCfgManager()->insertSettings( sToolBarName, xIndexAccess );
452  helper.applyIcons();
453 #if 1 // don't think this is necessary
454  uno::Reference< ui::XUIConfigurationPersistence > xPersistence( helper.getCfgManager()->getImageManager(), uno::UNO_QUERY_THROW );
455  xPersistence->store();
456 
457  xPersistence.set( helper.getCfgManager(), uno::UNO_QUERY_THROW );
458  xPersistence->store();
459 #endif
460  bRes = true;
461  }
462  catch( const uno::Exception& )
463  {
464  TOOLS_INFO_EXCEPTION("sw.ww8","***** For some reason we have an" );
465  bRes = false;
466  }
467  return bRes;
468 }
469 
470 bool SwCTB::ImportMenuTB( SwCTBWrapper& rWrapper, const css::uno::Reference< css::container::XIndexContainer >& xIndexContainer, CustomToolBarImportHelper& rHelper )
471 {
472  for ( auto& rItem : rTBC )
473  {
474  // createToolBar item for control
475  if ( !rItem.ImportToolBarControl( rWrapper, xIndexContainer, rHelper, true ) )
476  return false;
477  }
478  return true;
479 }
480 
482 {
483 }
484 
486 {
487 }
488 
490 {
491  SAL_INFO("sw.ww8","SwTBC::Read() stream pos 0x" << std::hex << rS.Tell() );
492  nOffSet = rS.Tell();
493  if ( !tbch.Read( rS ) )
494  return false;
495  if ( tbch.getTcID() != 0x1 && tbch.getTcID() != 0x1051 )
496  {
497  cid.reset( new sal_uInt32 );
498  rS.ReadUInt32( *cid );
499  }
500  // MUST exist if tbch.tct is not equal to 0x16
501  if ( tbch.getTct() != 0x16 )
502  {
503  tbcd.reset( new TBCData( tbch ) );
504  if ( !tbcd->Read( rS ) )
505  return false;
506  }
507  return rS.good();
508 }
509 
510 bool
511 SwTBC::ImportToolBarControl( SwCTBWrapper& rWrapper, const css::uno::Reference< css::container::XIndexContainer >& toolbarcontainer, CustomToolBarImportHelper& helper, bool bIsMenuBar )
512 {
513  // cmtFci 0x1 Command based on a built-in command. See CidFci.
514  // cmtMacro 0x2 Macro command. See CidMacro.
515  // cmtAllocated 0x3 Allocated command. See CidAllocated.
516  // cmtNil 0x7 No command. See Cid.
517  bool bBuiltin = false;
518  sal_Int16 cmdId = 0;
519  if ( cid.get() )
520  {
521  const sal_uInt32 nCid = ( *cid & 0xFFFF );
522 
523  const sal_uInt8 cmt = static_cast<sal_uInt8>( nCid & 0x7 );
524  const sal_Int16 arg2 = static_cast<sal_Int16>( nCid >> 3 );
525 
526  switch ( cmt )
527  {
528  case 1:
529  SAL_INFO("sw.ww8","cmt is cmtFci builtin command 0x" << std::hex << arg2);
530  bBuiltin = true;
531  cmdId = arg2;
532  break;
533  case 2:
534  SAL_INFO("sw.ww8","cmt is cmtMacro macro 0x" << std::hex << arg2);
535  break;
536  case 3:
537  SAL_INFO("sw.ww8","cmt is cmtAllocated [???] 0x" << std::hex << arg2);
538  break;
539  case 7:
540  SAL_INFO("sw.ww8","cmt is cmNill no-thing 0x" << std::hex << arg2);
541  break;
542  default:
543  SAL_INFO("sw.ww8","illegal 0x" << std::hex << cmt);
544  break;
545  }
546  }
547 
548  if ( tbcd.get() )
549  {
550  std::vector< css::beans::PropertyValue > props;
551  if ( bBuiltin )
552  {
553  const OUString sCommand = helper.MSOCommandToOOCommand( cmdId );
554  if ( !sCommand.isEmpty() )
555  {
556  beans::PropertyValue aProp;
557 
558  aProp.Name = "CommandURL";
559  aProp.Value <<= sCommand;
560  props.push_back( aProp );
561  }
562  }
563  bool bBeginGroup = false;
564  tbcd->ImportToolBarControl( helper, props, bBeginGroup, bIsMenuBar );
565 
566  TBCMenuSpecific* pMenu = tbcd->getMenuSpecific();
567  if ( pMenu )
568  {
569  SAL_INFO("sw.ww8","** control has a menu, name of toolbar with menu items is " << pMenu->Name() );
570  // search for SwCTB with the appropriate name ( it contains the
571  // menu items, although we cannot import ( or create ) a menu on
572  // a custom toolbar we can import the menu items in a separate
573  // toolbar ( better than nothing )
574  SwCTB* pCustTB = rWrapper.GetCustomizationData( pMenu->Name() );
575  if ( pCustTB )
576  {
577  uno::Reference< container::XIndexContainer > xMenuDesc = document::IndexedPropertyValues::create( comphelper::getProcessComponentContext() );
578  if ( !pCustTB->ImportMenuTB( rWrapper,xMenuDesc, helper ) )
579  return false;
580  if ( !bIsMenuBar )
581  {
582  if ( !helper.createMenu( pMenu->Name(), uno::Reference< container::XIndexAccess >( xMenuDesc, uno::UNO_QUERY ) ) )
583  return false;
584  }
585  else
586  {
587  beans::PropertyValue aProp;
588  aProp.Name = "ItemDescriptorContainer";
589  aProp.Value <<= xMenuDesc;
590  props.push_back( aProp );
591  }
592  }
593  }
594 
595  if ( bBeginGroup )
596  {
597  // insert spacer
598  uno::Sequence< beans::PropertyValue > sProps( 1 );
599  sProps[ 0 ].Name = "Type";
600  sProps[ 0 ].Value <<= ui::ItemType::SEPARATOR_LINE;
601  toolbarcontainer->insertByIndex( toolbarcontainer->getCount(), uno::makeAny( sProps ) );
602  }
603 
604  toolbarcontainer->insertByIndex( toolbarcontainer->getCount(), uno::makeAny( comphelper::containerToSequence(props) ) );
605  }
606  return true;
607 }
608 
609 OUString
611 {
612  if ( tbcd.get() )
613  return tbcd->getGeneralInfo().CustomText();
614  return OUString();
615 }
616 
617 bool
619 {
620  SAL_INFO("sw.ww8","Xst::Read() stream pos 0x" << std::hex << rS.Tell() );
621  nOffSet = rS.Tell();
623  return rS.good();
624 }
625 
626 Tcg::Tcg() : nTcgVer( -1 )
627 {
628 }
629 
631 {
632  SAL_INFO("sw.ww8","Tcg::Read() stream pos 0x" << std::hex << rS.Tell() );
633  nOffSet = rS.Tell();
634  rS.ReadSChar( nTcgVer );
635  if ( nTcgVer != -1 )
636  return false;
637  tcg.reset( new Tcg255() );
638  return tcg->Read( rS );
639 }
640 
642 {
643  if (tcg)
644  return tcg->ImportCustomToolBar( rDocSh );
645  return false;
646 }
647 
649 {
650 }
651 
653 {
654 }
655 
657 {
658  std::unique_ptr<Tcg255SubStruct> xSubStruct;
659  switch ( nId )
660  {
661  case 0x1:
662  {
663  xSubStruct.reset(new PlfMcd);
664  break;
665  }
666  case 0x2:
667  {
668  xSubStruct.reset(new PlfAcd);
669  break;
670  }
671  case 0x3:
672  case 0x4:
673  {
674  xSubStruct.reset(new PlfKme);
675  break;
676  }
677  case 0x10:
678  {
679  xSubStruct.reset(new TcgSttbf);
680  break;
681  }
682  case 0x11:
683  {
684  xSubStruct.reset(new MacroNames);
685  break;
686  }
687  case 0x12:
688  {
689  xSubStruct.reset(new SwCTBWrapper);
690  break;
691  }
692  default:
693  SAL_INFO("sw.ww8","Unknown id 0x" << std::hex << nId);
694  return false;
695  }
696  xSubStruct->ch = nId;
697  if (!xSubStruct->Read(rS))
698  return false;
699  rgtcgData.push_back(std::move(xSubStruct));
700  return true;
701 }
702 
704 {
705  // Find the SwCTBWrapper
706  for ( auto & rSubStruct : rgtcgData )
707  {
708  if ( rSubStruct->id() == 0x12 )
709  {
710  // not so great, shouldn't really have to do a horror casting
711  SwCTBWrapper* pCTBWrapper = dynamic_cast< SwCTBWrapper* > ( rSubStruct.get() );
712  if ( pCTBWrapper )
713  {
714  if ( !pCTBWrapper->ImportCustomToolBar( rDocSh ) )
715  return false;
716  }
717  }
718  }
719  return true;
720 }
721 
723 {
724  SAL_INFO("sw.ww8","Tcg255::Read() stream pos 0x" << std::hex << rS.Tell() );
725  nOffSet = rS.Tell();
726  sal_uInt8 nId = 0x40;
727  rS.ReadUChar( nId );
728  while ( nId != 0x40 )
729  {
730  if ( !processSubStruct( nId, rS ) )
731  return false;
732  nId = 0x40;
733  rS.ReadUChar( nId );
734  }
735  return rS.good();
736  // Peek at
737 }
738 
740 {
741 }
742 
744 {
745  SAL_INFO("sw.ww8","Tcg255SubStruct::Read() stream pos 0x" << std::hex << rS.Tell() );
746  nOffSet = rS.Tell();
747  return rS.good();
748 }
749 
751  : iMac(0)
752 {
753 }
754 
756 {
757  SAL_INFO("sw.ww8","PffMcd::Read() stream pos 0x" << std::hex << rS.Tell() );
758  nOffSet = rS.Tell();
759  Tcg255SubStruct::Read( rS );
760  rS.ReadInt32( iMac );
761  if (iMac < 0)
762  return false;
763  auto nMaxPossibleRecords = rS.remainingSize() / 24 /*sizeof MCD*/;
764  if (static_cast<sal_uInt32>(iMac) > nMaxPossibleRecords)
765  {
766  SAL_WARN("sw.ww8", iMac << " records claimed, but max possible is " << nMaxPossibleRecords);
767  iMac = nMaxPossibleRecords;
768  }
769  if (iMac)
770  {
771  rgmcd.resize(iMac);
772  for ( sal_Int32 index = 0; index < iMac; ++index )
773  {
774  if ( !rgmcd[ index ].Read( rS ) )
775  return false;
776  }
777  }
778  return rS.good();
779 }
780 
782  iMac(0)
783 {
784 }
785 
787 {
788 }
789 
791 {
792  SAL_INFO("sw.ww8","PffAcd::Read() stream pos 0x" << std::hex << rS.Tell() );
793  nOffSet = rS.Tell();
794  Tcg255SubStruct::Read( rS );
795  rS.ReadInt32( iMac );
796  if (iMac < 0)
797  return false;
798  auto nMaxPossibleRecords = rS.remainingSize() / (sizeof(sal_uInt16)*2);
799  if (static_cast<sal_uInt32>(iMac) > nMaxPossibleRecords)
800  {
801  SAL_WARN("sw.ww8", iMac << " records claimed, but max possible is " << nMaxPossibleRecords);
802  iMac = nMaxPossibleRecords;
803  }
804  if (iMac)
805  {
806  rgacd.reset( new Acd[ iMac ] );
807  for ( sal_Int32 index = 0; index < iMac; ++index )
808  {
809  if ( !rgacd[ index ].Read( rS ) )
810  return false;
811  }
812  }
813  return rS.good();
814 }
815 
817  iMac( 0 )
818 {
819 }
820 
822 {
823 }
824 
826 {
827  SAL_INFO("sw.ww8","PlfKme::Read() stream pos 0x" << std::hex << rS.Tell() );
828  nOffSet = rS.Tell();
829  Tcg255SubStruct::Read( rS );
830  rS.ReadInt32( iMac );
831  if (iMac > 0)
832  {
833  //each Kme is 14 bytes in size
834  size_t nMaxAvailableRecords = rS.remainingSize() / 14;
835  if (static_cast<sal_uInt32>(iMac) > nMaxAvailableRecords)
836  return false;
837 
838  rgkme.reset( new Kme[ iMac ] );
839  for( sal_Int32 index=0; index<iMac; ++index )
840  {
841  if ( !rgkme[ index ].Read( rS ) )
842  return false;
843  }
844  }
845  return rS.good();
846 }
847 
849 {
850 }
851 
853 {
854  SAL_INFO("sw.ww8","TcgSttbf::Read() stream pos 0x" << std::hex << rS.Tell() );
855  nOffSet = rS.Tell();
856  Tcg255SubStruct::Read( rS );
857  return sttbf.Read( rS );
858 }
859 
861 ,cData( 0 )
862 ,cbExtra( 0 )
863 {
864 }
865 
867 {
868 }
869 
871 {
872  SAL_INFO("sw.ww8","TcgSttbfCore::Read() stream pos 0x" << std::hex << rS.Tell() );
873  nOffSet = rS.Tell();
875  if ( cData )
876  {
877  if (cData > rS.remainingSize() / 4) //definitely an invalid record
878  return false;
879  dataItems.reset( new SBBItem[ cData ] );
880  for ( sal_Int32 index = 0; index < cData; ++index )
881  {
882  rS.ReadUInt16( dataItems[ index ].cchData );
883  dataItems[ index ].data = read_uInt16s_ToOUString(rS, dataItems[index].cchData);
884  rS.ReadUInt16( dataItems[ index ].extraData );
885  }
886  }
887  return rS.good();
888 }
889 
891  iMac( 0 )
892 {
893 }
894 
896 {
897 }
898 
900 {
901  SAL_INFO("sw.ww8","MacroNames::Read() stream pos 0x" << std::hex << rS.Tell() );
902  nOffSet = rS.Tell();
903  Tcg255SubStruct::Read( rS );
904  rS.ReadUInt16( iMac );
905  if ( iMac )
906  {
907  //even an empty MacroName will take 2 bytes
908  size_t nMaxAvailableRecords = rS.remainingSize()/sizeof(sal_uInt16);
909  if (iMac > nMaxAvailableRecords)
910  return false;
911  rgNames.reset( new MacroName[ iMac ] );
912  for ( sal_Int32 index = 0; index < iMac; ++index )
913  {
914  if ( !rgNames[ index ].Read( rS ) )
915  return false;
916  }
917  }
918  return rS.good();
919 }
920 
922 {
923 }
924 
926 {
927  SAL_INFO("sw.ww8","MacroName::Read() stream pos 0x" << std::hex << rS.Tell() );
928  nOffSet = rS.Tell();
929  rS.ReadUInt16( ibst );
930  return xstz.Read( rS );
931 }
932 
933 Xstz::Xstz():chTerm(0)
934 {
935 }
936 
937 bool
939 {
940  SAL_INFO("sw.ww8","Xstz::Read() stream pos 0x" << std::hex << rS.Tell() );
941  nOffSet = rS.Tell();
942  if ( !xst.Read( rS ) )
943  return false;
944  rS.ReadUInt16( chTerm );
945  if ( chTerm != 0 ) // should be an assert
946  return false;
947  return rS.good();
948 }
949 
950 Kme::Kme() : reserved1(0)
951 ,reserved2(0)
952 ,kcm1(0)
953 ,kcm2(0)
954 ,kt(0)
955 ,param(0)
956 {
957 }
958 
960 {
961 }
962 
963 bool
965 {
966  SAL_INFO("sw.ww8","Kme::Read() stream pos 0x" << std::hex << rS.Tell() );
967  nOffSet = rS.Tell();
969  return rS.good();
970 }
971 
972 Acd::Acd() : ibst( 0 )
973 , fciBasedOnABC( 0 )
974 {
975 }
976 
978 {
979  SAL_INFO("sw.ww8","Acd::Read() stream pos 0x" << std::hex << rS.Tell() );
980  nOffSet = rS.Tell();
982  return rS.good();
983 }
984 
985 MCD::MCD() : reserved1(0x56)
986 ,reserved2( 0 )
987 ,ibst( 0 )
988 ,ibstName( 0 )
989 ,reserved3( 0xFFFF )
990 ,reserved4( 0 )
991 ,reserved5( 0 )
992 ,reserved6( 0 )
993 ,reserved7( 0 )
994 {
995 }
996 
998 {
999  SAL_INFO("sw.ww8","MCD::Read() stream pos 0x" << rS.Tell() );
1000  nOffSet = rS.Tell();
1003  return rS.good();
1004 }
1005 
1006 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
css::uno::Reference< css::linguistic2::XProofreadingIterator > get(css::uno::Reference< css::uno::XComponentContext > const &context)
sal_uInt16 cCust
Definition: ww8toolbar.hxx:135
sal_uInt16 fExtend
Definition: ww8toolbar.hxx:252
bool Read(SvStream &rS) override
Definition: ww8toolbar.cxx:395
const OUString & getString() const
Definition: ww8toolbar.hxx:27
OUString Name()
bool Read(SvStream &rS) override
Definition: ww8toolbar.cxx:755
SvStream & ReadInt16(sal_Int16 &rInt16)
bool ImportToolBarControl(SwCTBWrapper &, const css::uno::Reference< css::container::XIndexContainer > &, CustomToolBarImportHelper &, bool)
Definition: ww8toolbar.cxx:511
std::vector< sal_Int16 > dropDownMenuIndices
Definition: ww8toolbar.hxx:141
bool ControlDropsToolBar()
Definition: ww8toolbar.cxx:355
sal_uInt8 ibts
Definition: ww8toolbar.hxx:73
bool ImportCustomToolBar(SwCTBWrapper &, CustomToolBarImportHelper &)
Definition: ww8toolbar.cxx:325
bool Read(SvStream &rS) override
virtual ~Kme() override
Definition: ww8toolbar.cxx:959
std::vector< TBVisualData > rVisualData
Definition: ww8toolbar.hxx:49
sal_uInt8 doprfatendFlags
Definition: ww8toolbar.hxx:71
OUString read_uInt16s_ToOUString(SvStream &rStrm, std::size_t nLen)
SwCTBWrapper * pWrapper
Definition: ww8toolbar.hxx:112
bool IsMenuToolbar()
Definition: ww8toolbar.cxx:390
SvStream & ReadUInt16(sal_uInt16 &rUInt16)
virtual ~SwCTBWrapper() override
Definition: ww8toolbar.cxx:87
bool processSubStruct(sal_uInt8 nId, SvStream &)
Definition: ww8toolbar.cxx:656
virtual ~PlfAcd() override
Definition: ww8toolbar.cxx:786
std::unique_ptr< Tcg255 > tcg
Definition: ww8toolbar.hxx:332
sal_uInt16 CiTBDE
Definition: ww8toolbar.hxx:77
sal_Int32 iMac
Definition: ww8toolbar.hxx:176
sal_Int32 iMac
Definition: ww8toolbar.hxx:200
sal_Int16 nId
sal_uInt64 Seek(sal_uInt64 nPos)
bool Read(SvStream &rS) override
Definition: ww8toolbar.cxx:369
bool Read(SvStream &rS) override
Definition: ww8toolbar.cxx:618
std::map< sal_Int16, OUString > IdToString
sal_uInt16 reserved5
Definition: ww8toolbar.hxx:132
virtual ~SwTBC() override
Definition: ww8toolbar.cxx:485
sal_uInt16 fciBasedOnABC
Definition: ww8toolbar.hxx:189
bool Read(SvStream &rS) override
Definition: ww8toolbar.cxx:743
SwCTB * GetCustomizationData(const OUString &name)
Definition: ww8toolbar.cxx:98
sal_uInt32 reserved5
Definition: ww8toolbar.hxx:165
std::vector< MCD > rgmcd
Definition: ww8toolbar.hxx:177
std::vector< std::unique_ptr< Tcg255SubStruct > > rgtcgData
Definition: ww8toolbar.hxx:317
sal_Int16 reserved2
Definition: ww8toolbar.hxx:214
OUString MSOCommandToOOCommand(sal_Int16 msoCmd)
virtual OUString MSOCommandToOOCommand(sal_Int16 msoCmd) override
Definition: ww8toolbar.cxx:59
bool Read(SvStream &rS) override
Definition: ww8toolbar.cxx:899
std::vector< SwTBC > rtbdc
Definition: ww8toolbar.hxx:139
static bool IsFuzzing()
sal_Int8 reserved1
Definition: ww8toolbar.hxx:159
sal_Int16 ibst
Definition: ww8toolbar.hxx:188
sal_uInt16 ibstName
Definition: ww8toolbar.hxx:162
virtual ~SwCTB() override
Definition: ww8toolbar.cxx:386
bool Read(SvStream &rS) override
Definition: ww8toolbar.cxx:489
OUString const & GetName()
Definition: ww8toolbar.hxx:66
sal_uInt32 reserved4
Definition: ww8toolbar.hxx:164
sal_uInt64 remainingSize()
Xst xst
Definition: ww8toolbar.hxx:278
bool Read(SvStream &rS) override
Definition: ww8toolbar.cxx:938
sal_uInt16 reserved1
Definition: ww8toolbar.hxx:110
sal_Int16 reserved1
Definition: ww8toolbar.hxx:213
sal_uInt16 ibst
Definition: ww8toolbar.hxx:291
void setMSOCommandMap(MSOCommandConvertor *pCnvtr)
css::uno::Reference< css::ui::XUIConfigurationManager > getCfgManager()
SvStream & ReadUInt32(sal_uInt32 &rUInt32)
bool ImportMenu(SwCTBWrapper &, CustomToolBarImportHelper &)
Definition: ww8toolbar.cxx:252
const short nVisualData
Definition: ww8toolbar.cxx:32
sal_uInt16 reserved3
Definition: ww8toolbar.hxx:163
std::map< sal_Int16, OUString > IdToString
Definition: ww8toolbar.cxx:34
virtual ~MacroNames() override
Definition: ww8toolbar.cxx:895
sal_uInt16 cData
Definition: ww8toolbar.hxx:253
sal_uInt16 kcm1
Definition: ww8toolbar.hxx:215
bool Read(SvStream &rS) override
Definition: ww8toolbar.cxx:977
SwTBC * GetTBCAtOffset(sal_uInt32 nStreamOffset)
Definition: ww8toolbar.cxx:172
sal_Int16 CustomizationIndex()
Definition: ww8toolbar.cxx:361
bool createMenu(const OUString &rName, const css::uno::Reference< css::container::XIndexAccess > &xMenuDesc)
sal_uInt16 ctbds
Definition: ww8toolbar.hxx:111
bool Read(SvStream &rS) override
Definition: ww8toolbar.cxx:790
sal_uInt32 reserved7
Definition: ww8toolbar.hxx:167
sal_uInt16 cbExtra
Definition: ww8toolbar.hxx:254
sal_Int32 cCtls
Definition: ww8toolbar.hxx:53
std::shared_ptr< SwCTB > customizationDataCTB
Definition: ww8toolbar.hxx:113
bool Read(SvStream &rS) override
Definition: ww8toolbar.cxx:722
virtual ~Customization() override
Definition: ww8toolbar.cxx:217
std::shared_ptr< sal_uInt32 > cid
Definition: ww8toolbar.hxx:33
std::shared_ptr< TBCData > tbcd
Definition: ww8toolbar.hxx:34
sal_uInt16 reserved4
Definition: ww8toolbar.hxx:131
OUString GetCustomText()
Definition: ww8toolbar.cxx:610
bool Read(SvStream &rS) override
sal_Int32 iWCTBl
Definition: ww8toolbar.hxx:50
Customization * GetCustomizaton(sal_Int16 index)
Definition: ww8toolbar.cxx:91
sal_uInt8 reserved3
Definition: ww8toolbar.hxx:130
SvStream & ReadUChar(unsigned char &rChar)
bool ImportCustomToolBar(SfxObjectShell &rDocSh)
Definition: ww8toolbar.cxx:703
tuple index
sal_uInt16 ibst
Definition: ww8toolbar.hxx:161
std::vector< Customization > rCustomizations
Definition: ww8toolbar.hxx:140
sal_Int32 cbTBData
Definition: ww8toolbar.hxx:47
bool Read(SvStream &rS) override
Definition: ww8toolbar.cxx:825
sal_Int32 tbidForTBD
Definition: ww8toolbar.hxx:109
sal_uInt32 reserved6
Definition: ww8toolbar.hxx:166
std::vector< TBDelta > customizationDataTBDelta
Definition: ww8toolbar.hxx:114
SvStream & ReadInt32(sal_Int32 &rInt32)
#define TOOLS_INFO_EXCEPTION(area, stream)
std::vector< SwTBC > rTBC
Definition: ww8toolbar.hxx:54
sal_uInt16 cbTBC
Definition: ww8toolbar.hxx:78
bool IsEnabled()
sal_uInt32 nOffSet
bool Read(SvStream &rS) override
Definition: ww8toolbar.cxx:997
sal_uInt16 getTcID() const
bool Read(SvStream &rS) override
Definition: ww8toolbar.cxx:630
std::unique_ptr< MacroName[]> rgNames
Definition: ww8toolbar.hxx:304
sal_Int32 iMac
Definition: ww8toolbar.hxx:231
bool ImportCustomToolBar(SfxObjectShell &rDocSh)
Definition: ww8toolbar.cxx:641
#define SAL_WARN_IF(condition, area, stream)
sal_uInt16 unused
Definition: ww8toolbar.hxx:52
unsigned char sal_uInt8
bool Read(SvStream &rS) override
Definition: ww8toolbar.cxx:870
std::unique_ptr< Acd[]> rgacd
Definition: ww8toolbar.hxx:201
css::uno::Sequence< DstElementType > containerToSequence(const SrcType &i_Container)
sal_Int32 cbDTBC
Definition: ww8toolbar.hxx:137
virtual ~Tcg255() override
Definition: ww8toolbar.cxx:652
#define SAL_INFO(area, stream)
sal_uInt16 chTerm
Definition: ww8toolbar.hxx:279
sal_uInt16 reserved2
Definition: ww8toolbar.hxx:129
virtual ~PlfKme() override
Definition: ww8toolbar.cxx:821
Customization(SwCTBWrapper *rapper)
Definition: ww8toolbar.cxx:208
sal_Int8 nTcgVer
Definition: ww8toolbar.hxx:331
sal_uInt8 getTct() const
virtual ~TcgSttbfCore() override
Definition: ww8toolbar.cxx:866
TcgSttbfCore sttbf
Definition: ww8toolbar.hxx:267
sal_uInt64 Tell() const
Reference< XComponentContext > getProcessComponentContext()
bool ImportMenuTB(SwCTBWrapper &, const css::uno::Reference< css::container::XIndexContainer > &, CustomToolBarImportHelper &)
Definition: ww8toolbar.cxx:470
sal_Int16 cbTBD
Definition: ww8toolbar.hxx:134
sal_uInt16 reserved
Definition: ww8toolbar.hxx:51
bool good() const
bool Read(SvStream &rS) override
bool Read(SvStream &rS) override
Definition: ww8toolbar.cxx:852
#define SAL_WARN(area, stream)
std::unique_ptr< SBBItem[]> dataItems
Definition: ww8toolbar.hxx:255
sal_uInt32 param
Definition: ww8toolbar.hxx:218
TBCHeader tbch
Definition: ww8toolbar.hxx:32
bool ImportCustomToolBar(SfxObjectShell &rDocSh)
Definition: ww8toolbar.cxx:181
std::unique_ptr< Kme[]> rgkme
Definition: ww8toolbar.hxx:232
sal_Int32 cid
Definition: ww8toolbar.hxx:75
sal_uInt16 kcm2
Definition: ww8toolbar.hxx:216
void InsertDropIndex(sal_Int32 aIndex)
Definition: ww8toolbar.hxx:148
OUString read_uInt16_PascalString(SvStream &rStrm)
Definition: ww8scan.hxx:160
sal_uInt16 kt
Definition: ww8toolbar.hxx:217
sal_uInt16 iMac
Definition: ww8toolbar.hxx:303
bool ControlIsInserted()
Definition: ww8toolbar.cxx:350
bool Read(SvStream &rS) override
Definition: ww8toolbar.cxx:110
sal_Int32 cidNext
Definition: ww8toolbar.hxx:74
Xst name
Definition: ww8toolbar.hxx:46
bool IsMenuToolbar()
bool ImportCustomToolBar(SwCTBWrapper &, CustomToolBarImportHelper &)
Definition: ww8toolbar.cxx:426
OUString sString
Definition: ww8toolbar.hxx:22
bool Read(SvStream &rS) override
Definition: ww8toolbar.cxx:925
sal_Int32 fc
Definition: ww8toolbar.hxx:76
virtual OUString MSOTCIDToOOCommand(sal_Int16 key) override
Definition: ww8toolbar.cxx:67
bool Read(SvStream &rS) override
Definition: ww8toolbar.cxx:964
bool Read(SvStream &rS) override
Definition: ww8toolbar.cxx:221
sal_uInt8 reserved2
Definition: ww8toolbar.hxx:160
const css::uno::Reference< css::ui::XUIConfigurationManager > & getAppCfgManager()
SvStream & ReadSChar(signed char &rChar)