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