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>
21 #include <comphelper/sequence.hxx>
22 #include <o3tl/safeint.hxx>
23 #include <sfx2/objsh.hxx>
24 #include <tools/diagnose_ex.h>
25 #include <unotools/configmgr.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 
36 namespace {
37 
38 class MSOWordCommandConvertor : public MSOCommandConvertor
39 {
40  IdToString msoToOOcmd;
41  IdToString tcidToOOcmd;
42 
43 public:
44  MSOWordCommandConvertor();
45  virtual OUString MSOCommandToOOCommand( sal_Int16 msoCmd ) override;
46  virtual OUString MSOTCIDToOOCommand( sal_Int16 key ) override;
47 };
48 
49 }
50 
51 MSOWordCommandConvertor::MSOWordCommandConvertor()
52 {
53  // mso command id to ooo command string
54  // #FIXME and *HUNDREDS* of id's to added here
55  msoToOOcmd[ 0x20b ] = ".uno:CloseDoc";
56  msoToOOcmd[ 0x50 ] = ".uno:Open";
57 
58  // mso tcid to ooo command string
59  // #FIXME and *HUNDREDS* of id's to added here
60  tcidToOOcmd[ 0x9d9 ] = ".uno:Print";
61 }
62 
63 OUString MSOWordCommandConvertor::MSOCommandToOOCommand( sal_Int16 key )
64 {
65  IdToString::iterator it = msoToOOcmd.find( key );
66  if ( it != msoToOOcmd.end() )
67  return it->second;
68  return OUString();
69 }
70 
71 OUString MSOWordCommandConvertor::MSOTCIDToOOCommand( sal_Int16 key )
72 {
73  IdToString::iterator it = tcidToOOcmd.find( key );
74  if ( it != tcidToOOcmd.end() )
75  return it->second;
76  return OUString();
77 }
78 
80 reserved2(0)
81 ,reserved3(0)
82 ,reserved4(0)
83 ,reserved5(0)
84 ,cbTBD(0)
85 ,cCust(0)
86 ,cbDTBC(0)
87 ,rtbdc(0)
88 {
89 }
90 
92 {
93 }
94 
96 {
97  if ( index < 0 || index >= static_cast<sal_Int16>( rCustomizations.size() ) )
98  return nullptr;
99  return &rCustomizations[ index ];
100 }
101 
102 SwCTB* SwCTBWrapper::GetCustomizationData( const OUString& sTBName )
103 {
104  auto it = std::find_if(rCustomizations.begin(), rCustomizations.end(),
105  [&sTBName](Customization& rCustomization) {
106  SwCTB* pCTB = rCustomization.GetCustomizationData();
107  return pCTB && pCTB->GetName() == sTBName;
108  });
109  if (it != rCustomizations.end())
110  return it->GetCustomizationData();
111  return nullptr;
112 }
113 
115 {
116  SAL_INFO("sw.ww8","SwCTBWrapper::Read() stream pos 0x" << std::hex << rS.Tell() );
117  nOffSet = rS.Tell();
118  Tcg255SubStruct::Read( rS );
121  long nExpectedPos = rS.Tell() + cbDTBC;
122  if ( cbDTBC )
123  {
124  // cbDTBC is the size in bytes of the SwTBC array
125  // but the size of a SwTBC element is dynamic ( and this relates to TBDelta's
126  int nStart = rS.Tell();
127 
128  int bytesToRead;
129  // cbDTBC specifies the size ( in bytes ) taken by an array ( of unspecified size )
130  // of SwTBC records ( SwTBC records have dynamic length, so we need to check our position
131  // after each read )
132  do
133  {
134  SwTBC aTBC;
135  if ( !aTBC.Read( rS ) )
136  return false;
137  rtbdc.push_back( aTBC );
138  bytesToRead = cbDTBC - ( rS.Tell() - nStart );
139  } while ( bytesToRead > 0 );
140  }
141  if ( static_cast< long >( rS.Tell() ) != nExpectedPos )
142  {
143  // Strange error condition, shouldn't happen ( but does in at least
144  // one test document ) In the case where it happens the SwTBC &
145  // TBCHeader records seem blank??? ( and incorrect )
146  SAL_WARN_IF( static_cast< long >(rS.Tell()) != nExpectedPos, "sw.ww8","### Error: Expected pos not equal to actual pos after reading rtbdc");
147  SAL_INFO("sw.ww8","\tPos now is 0x" << std::hex << rS.Tell() << " should be 0x" << std::hex << nExpectedPos );
148  // seek to correct position after rtbdc
149  rS.Seek( nExpectedPos );
150  }
151  if (cCust)
152  {
153  //Each customization takes a min of 8 bytes
154  size_t nMaxPossibleRecords = rS.remainingSize() / 8;
155  if (cCust > nMaxPossibleRecords)
156  {
157  return false;
158  }
159  for (sal_uInt16 index = 0; index < cCust; ++index)
160  {
161  Customization aCust( this );
162  if ( !aCust.Read( rS ) )
163  return false;
164  rCustomizations.push_back( aCust );
165  }
166  }
167  for ( const auto& rIndex : dropDownMenuIndices )
168  {
169  if (rIndex < 0 || o3tl::make_unsigned(rIndex) >= rCustomizations.size())
170  continue;
171  rCustomizations[rIndex].bIsDroppedMenuTB = true;
172  }
173  return rS.good();
174 }
175 
176 SwTBC* SwCTBWrapper::GetTBCAtOffset( sal_uInt32 nStreamOffset )
177 {
178  auto it = std::find_if(rtbdc.begin(), rtbdc.end(),
179  [&nStreamOffset](SwTBC& rItem) { return rItem.GetOffset() == nStreamOffset; });
180  if ( it != rtbdc.end() )
181  return &(*it);
182  return nullptr;
183 }
184 
186 {
187  for ( auto& rCustomization : rCustomizations )
188  {
189  try
190  {
191  css::uno::Reference<css::ui::XUIConfigurationManager> xCfgMgr;
193  {
194  uno::Reference< uno::XComponentContext > xContext = ::comphelper::getProcessComponentContext();
195  uno::Reference< ui::XModuleUIConfigurationManagerSupplier > xAppCfgSupp( ui::theModuleUIConfigurationManagerSupplier::get(xContext) );
196  xCfgMgr = xAppCfgSupp->getUIConfigurationManager("com.sun.star.text.TextDocument");
197  }
198  CustomToolBarImportHelper helper(rDocSh, xCfgMgr);
199  helper.setMSOCommandMap( new MSOWordCommandConvertor() );
200 
201  if ( !rCustomization.ImportCustomToolBar( *this, helper ) )
202  return false;
203  }
204  catch (...)
205  {
206  continue;
207  }
208  }
209  return true;
210 }
211 
213  : tbidForTBD( 0 )
214  , reserved1( 0 )
215  , ctbds( 0 )
216  , pWrapper( wrapper )
217  , bIsDroppedMenuTB( false )
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 = std::make_shared<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  SAL_INFO("sw.ww8","SwTBC::Read() stream pos 0x" << std::hex << rS.Tell() );
488  nOffSet = rS.Tell();
489  if ( !tbch.Read( rS ) )
490  return false;
491  if ( tbch.getTcID() != 0x1 && tbch.getTcID() != 0x1051 )
492  {
493  cid = std::make_shared<sal_uInt32>();
494  rS.ReadUInt32( *cid );
495  }
496  // MUST exist if tbch.tct is not equal to 0x16
497  if ( tbch.getTct() != 0x16 )
498  {
499  tbcd = std::make_shared<TBCData>( tbch );
500  if ( !tbcd->Read( rS ) )
501  return false;
502  }
503  return rS.good();
504 }
505 
506 bool
507 SwTBC::ImportToolBarControl( SwCTBWrapper& rWrapper, const css::uno::Reference< css::container::XIndexContainer >& toolbarcontainer, CustomToolBarImportHelper& helper, bool bIsMenuBar )
508 {
509  // cmtFci 0x1 Command based on a built-in command. See CidFci.
510  // cmtMacro 0x2 Macro command. See CidMacro.
511  // cmtAllocated 0x3 Allocated command. See CidAllocated.
512  // cmtNil 0x7 No command. See Cid.
513  bool bBuiltin = false;
514  sal_Int16 cmdId = 0;
515  if ( cid.get() )
516  {
517  const sal_uInt32 nCid = ( *cid & 0xFFFF );
518 
519  const sal_uInt8 cmt = static_cast<sal_uInt8>( nCid & 0x7 );
520  const sal_Int16 arg2 = static_cast<sal_Int16>( nCid >> 3 );
521 
522  switch ( cmt )
523  {
524  case 1:
525  SAL_INFO("sw.ww8","cmt is cmtFci builtin command 0x" << std::hex << arg2);
526  bBuiltin = true;
527  cmdId = arg2;
528  break;
529  case 2:
530  SAL_INFO("sw.ww8","cmt is cmtMacro macro 0x" << std::hex << arg2);
531  break;
532  case 3:
533  SAL_INFO("sw.ww8","cmt is cmtAllocated [???] 0x" << std::hex << arg2);
534  break;
535  case 7:
536  SAL_INFO("sw.ww8","cmt is cmNill no-thing 0x" << std::hex << arg2);
537  break;
538  default:
539  SAL_INFO("sw.ww8","illegal 0x" << std::hex << cmt);
540  break;
541  }
542  }
543 
544  if ( tbcd.get() )
545  {
546  std::vector< css::beans::PropertyValue > props;
547  if ( bBuiltin )
548  {
549  const OUString sCommand = helper.MSOCommandToOOCommand( cmdId );
550  if ( !sCommand.isEmpty() )
551  {
552  beans::PropertyValue aProp;
553 
554  aProp.Name = "CommandURL";
555  aProp.Value <<= sCommand;
556  props.push_back( aProp );
557  }
558  }
559  bool bBeginGroup = false;
560  tbcd->ImportToolBarControl( helper, props, bBeginGroup, bIsMenuBar );
561 
562  TBCMenuSpecific* pMenu = tbcd->getMenuSpecific();
563  if ( pMenu )
564  {
565  SAL_INFO("sw.ww8","** control has a menu, name of toolbar with menu items is " << pMenu->Name() );
566  // search for SwCTB with the appropriate name ( it contains the
567  // menu items, although we cannot import ( or create ) a menu on
568  // a custom toolbar we can import the menu items in a separate
569  // toolbar ( better than nothing )
570  SwCTB* pCustTB = rWrapper.GetCustomizationData( pMenu->Name() );
571  if ( pCustTB )
572  {
573  uno::Reference< container::XIndexContainer > xMenuDesc = document::IndexedPropertyValues::create( comphelper::getProcessComponentContext() );
574  if ( !pCustTB->ImportMenuTB( rWrapper,xMenuDesc, helper ) )
575  return false;
576  if ( !bIsMenuBar )
577  {
578  if ( !helper.createMenu( pMenu->Name(), xMenuDesc ) )
579  return false;
580  }
581  else
582  {
583  beans::PropertyValue aProp;
584  aProp.Name = "ItemDescriptorContainer";
585  aProp.Value <<= xMenuDesc;
586  props.push_back( aProp );
587  }
588  }
589  }
590 
591  if ( bBeginGroup )
592  {
593  // insert spacer
594  uno::Sequence< beans::PropertyValue > sProps( 1 );
595  sProps[ 0 ].Name = "Type";
596  sProps[ 0 ].Value <<= ui::ItemType::SEPARATOR_LINE;
597  toolbarcontainer->insertByIndex( toolbarcontainer->getCount(), uno::makeAny( sProps ) );
598  }
599 
600  toolbarcontainer->insertByIndex( toolbarcontainer->getCount(), uno::makeAny( comphelper::containerToSequence(props) ) );
601  }
602  return true;
603 }
604 
605 OUString
607 {
608  if ( tbcd.get() )
609  return tbcd->getGeneralInfo().CustomText();
610  return OUString();
611 }
612 
613 bool
615 {
616  SAL_INFO("sw.ww8","Xst::Read() stream pos 0x" << std::hex << rS.Tell() );
617  nOffSet = rS.Tell();
619  return rS.good();
620 }
621 
622 Tcg::Tcg() : nTcgVer( -1 )
623 {
624 }
625 
627 {
628  SAL_INFO("sw.ww8","Tcg::Read() stream pos 0x" << std::hex << rS.Tell() );
629  nOffSet = rS.Tell();
630  rS.ReadSChar( nTcgVer );
631  if ( nTcgVer != -1 )
632  return false;
633  tcg.reset( new Tcg255() );
634  return tcg->Read( rS );
635 }
636 
638 {
639  if (tcg)
640  return tcg->ImportCustomToolBar( rDocSh );
641  return false;
642 }
643 
645 {
646 }
647 
649 {
650 }
651 
653 {
654  std::unique_ptr<Tcg255SubStruct> xSubStruct;
655  switch ( nId )
656  {
657  case 0x1:
658  {
659  xSubStruct.reset(new PlfMcd);
660  break;
661  }
662  case 0x2:
663  {
664  xSubStruct.reset(new PlfAcd);
665  break;
666  }
667  case 0x3:
668  case 0x4:
669  {
670  xSubStruct.reset(new PlfKme);
671  break;
672  }
673  case 0x10:
674  {
675  xSubStruct.reset(new TcgSttbf);
676  break;
677  }
678  case 0x11:
679  {
680  xSubStruct.reset(new MacroNames);
681  break;
682  }
683  case 0x12:
684  {
685  xSubStruct.reset(new SwCTBWrapper);
686  break;
687  }
688  default:
689  SAL_INFO("sw.ww8","Unknown id 0x" << std::hex << nId);
690  return false;
691  }
692  xSubStruct->ch = nId;
693  if (!xSubStruct->Read(rS))
694  return false;
695  rgtcgData.push_back(std::move(xSubStruct));
696  return true;
697 }
698 
700 {
701  // Find the SwCTBWrapper
702  for ( const auto & rSubStruct : rgtcgData )
703  {
704  if ( rSubStruct->id() == 0x12 )
705  {
706  // not so great, shouldn't really have to do a horror casting
707  SwCTBWrapper* pCTBWrapper = dynamic_cast< SwCTBWrapper* > ( rSubStruct.get() );
708  if ( pCTBWrapper )
709  {
710  // tdf#127048 set this flag if we might import something
711  uno::Reference<frame::XModel> const xModel(rDocSh.GetBaseModel());
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 (o3tl::make_unsigned(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 (o3tl::make_unsigned(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 (o3tl::make_unsigned(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:133
sal_uInt16 fExtend
Definition: ww8toolbar.hxx:250
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:507
std::vector< sal_Int16 > dropDownMenuIndices
Definition: ww8toolbar.hxx:139
sal_Int32 nIndex
bool ControlDropsToolBar()
Definition: ww8toolbar.cxx:355
sal_uInt8 ibts
Definition: ww8toolbar.hxx:72
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: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:91
bool processSubStruct(sal_uInt8 nId, SvStream &)
Definition: ww8toolbar.cxx:652
virtual ~PlfAcd() override
Definition: ww8toolbar.cxx:786
std::unique_ptr< Tcg255 > tcg
Definition: ww8toolbar.hxx:330
sal_uInt16 CiTBDE
Definition: ww8toolbar.hxx:76
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:369
bool Read(SvStream &rS) override
Definition: ww8toolbar.cxx:614
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:743
SwCTB * GetCustomizationData(const OUString &name)
Definition: ww8toolbar.cxx:102
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:899
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:386
bool Read(SvStream &rS) override
Definition: ww8toolbar.cxx:485
OUString const & GetName()
Definition: ww8toolbar.hxx:65
sal_uInt32 reserved4
Definition: ww8toolbar.hxx:162
sal_uInt64 remainingSize()
Xst xst
Definition: ww8toolbar.hxx:276
css::uno::Reference< css::frame::XModel > GetBaseModel() const
bool Read(SvStream &rS) override
Definition: ww8toolbar.cxx:938
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:252
const short nVisualData
Definition: ww8toolbar.cxx:32
sal_uInt16 reserved3
Definition: ww8toolbar.hxx:161
std::map< sal_Int16, OUString > IdToString
Definition: ww8toolbar.cxx:34
virtual ~MacroNames() override
Definition: ww8toolbar.cxx:895
sal_uInt16 cData
Definition: ww8toolbar.hxx:251
sal_uInt16 kcm1
Definition: ww8toolbar.hxx:213
bool Read(SvStream &rS) override
Definition: ww8toolbar.cxx:977
SwTBC * GetTBCAtOffset(sal_uInt32 nStreamOffset)
Definition: ww8toolbar.cxx:176
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:110
bool Read(SvStream &rS) override
Definition: ww8toolbar.cxx:790
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:722
std::shared_ptr< sal_uInt32 > cid
Definition: ww8toolbar.hxx:33
std::shared_ptr< TBCData > tbcd
Definition: ww8toolbar.hxx:34
dictionary props
sal_uInt16 reserved4
Definition: ww8toolbar.hxx:129
OUString GetCustomText()
Definition: ww8toolbar.cxx:606
bool Read(SvStream &rS) override
sal_Int32 iWCTBl
Definition: ww8toolbar.hxx:49
Customization * GetCustomizaton(sal_Int16 index)
Definition: ww8toolbar.cxx:95
sal_uInt8 reserved3
Definition: ww8toolbar.hxx:128
SvStream & ReadUChar(unsigned char &rChar)
bool ImportCustomToolBar(SfxObjectShell &rDocSh)
Definition: ww8toolbar.cxx:699
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:825
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:997
sal_uInt16 getTcID() const
bool Read(SvStream &rS) override
Definition: ww8toolbar.cxx:626
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:637
#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:870
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:648
#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:821
Customization(SwCTBWrapper *rapper)
Definition: ww8toolbar.cxx:212
sal_Int8 nTcgVer
Definition: ww8toolbar.hxx:329
sal_uInt8 getTct() const
virtual ~TcgSttbfCore() override
Definition: ww8toolbar.cxx:866
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:470
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:852
#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:185
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:160
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:350
bool Read(SvStream &rS) override
Definition: ww8toolbar.cxx:114
sal_Int32 cidNext
Definition: ww8toolbar.hxx:73
Xst name
Definition: ww8toolbar.hxx:45
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:75
bool Read(SvStream &rS) override
Definition: ww8toolbar.cxx:964
bool Read(SvStream &rS) override
Definition: ww8toolbar.cxx:221
sal_uInt8 reserved2
Definition: ww8toolbar.hxx:158
bool IsMenuToolbar() const
Definition: ww8toolbar.cxx:390
SvStream & ReadSChar(signed char &rChar)