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