Avoid potential negative array index access to cached text.
[LibreOffice.git] / writerfilter / source / dmapper / NumberingManager.hxx
blobfc3c2f05b72f27b15478eac9a18f20a7ccbc4c35
1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 /*
3 * This file is part of the LibreOffice project.
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/.
9 * This file incorporates work covered by the following license notice:
11 * Licensed to the Apache Software Foundation (ASF) under one or more
12 * contributor license agreements. See the NOTICE file distributed
13 * with this work for additional information regarding copyright
14 * ownership. The ASF licenses this file to you under the Apache
15 * License, Version 2.0 (the "License"); you may not use this file
16 * except in compliance with the License. You may obtain a copy of
17 * the License at http://www.apache.org/licenses/LICENSE-2.0 .
20 #pragma once
22 #include "PropertyMap.hxx"
24 #include "DomainMapper.hxx"
25 #include "LoggedResources.hxx"
26 #include "StyleSheetTable.hxx"
28 #include <editeng/numitem.hxx>
30 #include <com/sun/star/container/XIndexReplace.hpp>
31 #include <com/sun/star/awt/XBitmap.hpp>
33 namespace writerfilter::dmapper {
35 class DomainMapper;
36 class StyleSheetEntry;
39 /** Class representing the numbering level properties.
41 class ListLevel : public PropertyMap
43 sal_Int32 m_nIStartAt; //LN_CT_Lvl_start
44 sal_Int32 m_nStartOverride;
45 sal_Int32 m_nNFC; //LN_CT_Lvl_numFmt
46 /// LN_CT_NumFmt_format, in case m_nNFC is custom.
47 OUString m_aCustomNumberFormat;
48 sal_Int16 m_nXChFollow; //LN_IXCHFOLLOW
49 std::optional<OUString> m_sBulletChar;
50 css::awt::Size m_aGraphicSize;
51 css::uno::Reference<css::awt::XBitmap> m_xGraphicBitmap;
52 std::optional<sal_Int32> m_nTabstop;
53 tools::SvRef< StyleSheetEntry > m_pParaStyle;
54 bool m_bHasValues = false;
55 bool m_bIsLegal = false;
57 public:
59 typedef tools::SvRef< ListLevel > Pointer;
61 ListLevel() :
62 m_nIStartAt(-1)
63 ,m_nStartOverride(-1)
64 ,m_nNFC(-1)
65 ,m_nXChFollow(SvxNumberFormat::LISTTAB)
68 // Setters for the import
69 void SetValue( Id nId, sal_Int32 nValue );
70 void SetCustomNumberFormat(const OUString& rValue);
71 void SetBulletChar( const OUString& sValue ) { m_sBulletChar = sValue; };
72 void SetGraphicSize( const css::awt::Size& aValue ) { m_aGraphicSize = aValue; };
74 void SetGraphicBitmap(css::uno::Reference<css::awt::XBitmap> const& xGraphicBitmap)
75 { m_xGraphicBitmap = xGraphicBitmap; }
76 void SetParaStyle( const tools::SvRef< StyleSheetEntry >& pStyle );
78 // Getters
79 sal_Int16 GetNumberingType(sal_Int16 nDefault) const;
80 bool HasBulletChar() const { return m_sBulletChar.has_value(); };
81 OUString GetBulletChar( ) const { return m_sBulletChar.has_value()? *m_sBulletChar : OUString(); };
82 const tools::SvRef< StyleSheetEntry >& GetParaStyle( ) const { return m_pParaStyle; };
83 sal_Int32 GetStartOverride() const { return m_nStartOverride; };
84 /// Determines if SetValue() was called at least once.
85 bool HasValues() const;
87 // UNO mapping functions
88 css::uno::Sequence<css::beans::PropertyValue> GetProperties(bool bDefaults);
90 css::uno::Sequence<css::beans::PropertyValue> GetCharStyleProperties();
91 private:
93 css::uno::Sequence<css::beans::PropertyValue> GetLevelProperties(bool bDefaults);
95 void AddParaProperties(css::uno::Sequence<css::beans::PropertyValue>* pProps);
98 /// Represents a numbering picture bullet: an id and a graphic.
99 class NumPicBullet final : public virtual SvRefBase
101 public:
102 typedef tools::SvRef<NumPicBullet> Pointer;
103 NumPicBullet();
104 ~NumPicBullet() override;
106 void SetId(sal_Int32 nId);
107 sal_Int32 GetId() const { return m_nId;}
108 void SetShape(css::uno::Reference<css::drawing::XShape> const& xShape);
109 const css::uno::Reference<css::drawing::XShape>& GetShape() const { return m_xShape; }
110 private:
111 sal_Int32 m_nId;
112 css::uno::Reference<css::drawing::XShape> m_xShape;
115 class AbstractListDef : public virtual SvRefBase
117 private:
118 // The ID member reflects either the abstractNumId or the numId
119 // depending on the use of the class
120 sal_Int32 m_nId;
122 // Properties of each level. This can also reflect the overridden
123 // levels of a numbering.
124 ::std::vector< ListLevel::Pointer > m_aLevels;
126 // Only used during the numbering import
127 ListLevel::Pointer m_pCurrentLevel;
129 // The style name linked to.
130 OUString m_sNumStyleLink;
132 // This abstract numbering is a base definition for this style
133 OUString m_sStyleLink;
135 /// list id to use for all derived numbering definitions
136 std::optional<OUString> m_oListId;
138 public:
139 typedef tools::SvRef< AbstractListDef > Pointer;
141 AbstractListDef( );
142 virtual ~AbstractListDef( ) override;
144 // Setters using during the import
145 void SetId( sal_Int32 nId ) { m_nId = nId; };
146 static void SetValue( sal_uInt32 nSprmId );
148 // Accessors
149 sal_Int32 GetId( ) const { return m_nId; };
151 sal_Int16 Size( ) { return sal_Int16( m_aLevels.size( ) ); };
152 ListLevel::Pointer GetLevel( sal_uInt16 nLvl );
153 void AddLevel( sal_uInt16 nLvl );
155 const ListLevel::Pointer& GetCurrentLevel( ) const { return m_pCurrentLevel; };
157 css::uno::Sequence< css::uno::Sequence<css::beans::PropertyValue> > GetPropertyValues(bool bDefaults);
159 void SetNumStyleLink(const OUString& sValue) { m_sNumStyleLink = sValue; };
160 const OUString& GetNumStyleLink() const { return m_sNumStyleLink; };
162 void SetStyleLink(const OUString& sValue) { m_sStyleLink = sValue; };
163 const OUString& GetStyleLink() const { return m_sStyleLink; };
165 const OUString& MapListId(OUString const& rId);
168 class ListDef : public AbstractListDef
170 private:
171 // Pointer to the abstract numbering
172 AbstractListDef::Pointer m_pAbstractDef;
174 // Cache for the UNO numbering rules
175 css::uno::Reference< css::container::XIndexReplace > m_xNumRules;
177 /// mapped list style name
178 OUString m_StyleName;
180 public:
181 typedef tools::SvRef< ListDef > Pointer;
183 ListDef( );
184 virtual ~ListDef( ) override;
186 // Accessors
187 void SetAbstractDefinition( AbstractListDef::Pointer pAbstract ) { m_pAbstractDef = pAbstract; };
188 const AbstractListDef::Pointer& GetAbstractDefinition( ) const { return m_pAbstractDef; };
190 // Mapping functions
191 const OUString & GetStyleName() const { return m_StyleName; };
192 const OUString & GetStyleName(sal_Int32 nId, css::uno::Reference<css::container::XNameContainer> const& xStyles);
194 css::uno::Sequence< css::uno::Sequence<css::beans::PropertyValue> > GetMergedPropertyValues();
196 sal_uInt16 GetChapterNumberingWeight() const;
197 void CreateNumberingRules(DomainMapper& rDMapper, css::uno::Reference<css::lang::XMultiServiceFactory> const& xFactory, sal_Int16 nOutline);
199 const css::uno::Reference<css::container::XIndexReplace>& GetNumberingRules() const { return m_xNumRules; }
203 /** This class provides access to the defined numbering styles.
205 class ListsManager :
206 public LoggedProperties,
207 public LoggedTable
209 private:
211 DomainMapper& m_rDMapper;
212 css::uno::Reference<css::lang::XMultiServiceFactory> m_xFactory;
214 // The numbering entries
215 std::vector< NumPicBullet::Pointer > m_aNumPicBullets;
216 std::vector< AbstractListDef::Pointer > m_aAbstractLists;
217 std::vector< ListDef::Pointer > m_aLists;
220 // These members are used for import only
221 AbstractListDef::Pointer m_pCurrentDefinition;
222 NumPicBullet::Pointer m_pCurrentNumPicBullet;
224 AbstractListDef::Pointer GetAbstractList( sal_Int32 nId );
226 // Properties
227 virtual void lcl_attribute( Id nName, Value & rVal ) override;
228 virtual void lcl_sprm(Sprm & sprm) override;
230 // Table
231 virtual void lcl_entry(writerfilter::Reference<Properties>::Pointer_t ref) override;
233 public:
235 ListsManager(DomainMapper& rDMapper, css::uno::Reference<css::lang::XMultiServiceFactory> xFactory);
236 virtual ~ListsManager() override;
238 typedef tools::SvRef< ListsManager > Pointer;
240 ListDef::Pointer GetList( sal_Int32 nId );
242 // Mapping methods
243 void CreateNumberingRules( );
245 // Dispose the NumPicBullets
246 void DisposeNumPicBullets( );
251 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */