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