Avoid potential negative array index access to cached text.
[LibreOffice.git] / include / editeng / tstpitem.hxx
blob037e766366416f92cbe9e6fd340bc20799d74fab
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 .
19 #ifndef INCLUDED_EDITENG_TSTPITEM_HXX
20 #define INCLUDED_EDITENG_TSTPITEM_HXX
22 #include <svl/poolitem.hxx>
23 #include <editeng/svxenum.hxx>
24 #include <editeng/editengdllapi.h>
25 #include <o3tl/sorted_vector.hxx>
27 // class SvxTabStop ------------------------------------------------------
29 #define SVX_TAB_DEFCOUNT 10
30 #define SVX_TAB_DEFDIST 1134 // 2cm in twips
31 #define SVX_TAB_NOTFOUND USHRT_MAX
32 #define cDfltDecimalChar u'\0' // Get from IntlWrapper
33 #define cDfltFillChar u' '
35 class EDITENG_DLLPUBLIC SvxTabStop
37 private:
38 sal_Int32 nTabPos;
39 SvxTabAdjust eAdjustment;
40 mutable sal_Unicode
41 m_cDecimal;
42 sal_Unicode cFill;
44 void fillDecimal() const;
46 public:
47 SvxTabStop();
48 explicit SvxTabStop( const sal_Int32 nPos,
49 const SvxTabAdjust eAdjst = SvxTabAdjust::Left,
50 const sal_Unicode cDec = cDfltDecimalChar,
51 const sal_Unicode cFil = cDfltFillChar );
53 sal_Int32& GetTabPos() { return nTabPos; }
54 sal_Int32 GetTabPos() const { return nTabPos; }
56 SvxTabAdjust& GetAdjustment() { return eAdjustment; }
57 SvxTabAdjust GetAdjustment() const { return eAdjustment; }
59 sal_Unicode& GetDecimal() { fillDecimal(); return m_cDecimal; }
60 sal_Unicode GetDecimal() const { fillDecimal(); return m_cDecimal; }
62 sal_Unicode& GetFill() { return cFill; }
63 sal_Unicode GetFill() const { return cFill; }
65 bool operator==( const SvxTabStop& rTS ) const
67 return ( nTabPos == rTS.nTabPos &&
68 eAdjustment == rTS.eAdjustment &&
69 m_cDecimal == rTS.m_cDecimal &&
70 cFill == rTS.cFill );
72 bool operator!=( const SvxTabStop& rTS ) const
74 return !operator==(rTS);
76 // For the SortedArray:
77 bool operator <( const SvxTabStop& rTS ) const
78 { return nTabPos < rTS.nTabPos; }
80 void dumpAsXml(xmlTextWriterPtr pWriter) const;
83 // class SvxTabStopItem --------------------------------------------------
85 typedef o3tl::sorted_vector<SvxTabStop> SvxTabStopArr;
87 /* [Description]
89 This item describes a list of TabStops.
92 class EDITENG_DLLPUBLIC SvxTabStopItem final : public SfxPoolItem
94 SvxTabStopArr maTabStops;
95 /// Defines default tab width for tabs without dedicated tab stop in the paragraph.
96 sal_Int32 mnDefaultDistance = 0;
98 public:
99 static SfxPoolItem* CreateDefault();
101 explicit SvxTabStopItem( sal_uInt16 nWhich );
102 SvxTabStopItem( const sal_uInt16 nTabs,
103 const sal_uInt16 nDist,
104 const SvxTabAdjust eAdjst /*= SvxTabAdjust::Default*/,
105 sal_uInt16 nWhich );
107 // Returns index of the tab or TAB_NOTFOUND
108 sal_uInt16 GetPos( const SvxTabStop& rTab ) const;
110 // Returns index of the tab at nPos, or TAB_NOTFOUND
111 sal_uInt16 GetPos( const sal_Int32 nPos ) const;
112 void SetDefaultDistance(sal_Int32 nDefaultDistancenDefTabSize);
113 sal_Int32 GetDefaultDistance() const;
115 // unprivatized:
116 sal_uInt16 Count() const { return maTabStops.size(); }
117 bool Insert( const SvxTabStop& rTab );
118 void Insert( const SvxTabStopItem* pTabs );
119 void Remove( const sal_uInt16 nPos, const sal_uInt16 nLen = 1 )
120 { maTabStops.erase( maTabStops.begin() + nPos, maTabStops.begin() + nPos + nLen ); }
122 // Assignment operator, equality operator (caution: expensive!)
124 // this is already included in SfxPoolItem declaration
125 //int operator!=( const SvxTabStopItem& rTSI ) const
126 // { return !( operator==( rTSI ) ); }
128 const SvxTabStop& operator[]( const sal_uInt16 nPos ) const
129 { return maTabStops[nPos]; }
131 const SvxTabStop& At( const sal_uInt16 nPos ) const
133 return maTabStops[nPos];
136 // "pure virtual Methods" from SfxPoolItem
137 virtual bool operator==( const SfxPoolItem& ) const override;
138 virtual bool QueryValue( css::uno::Any& rVal, sal_uInt8 nMemberId = 0 ) const override;
139 virtual bool PutValue( const css::uno::Any& rVal, sal_uInt8 nMemberId ) override;
141 virtual bool GetPresentation( SfxItemPresentation ePres,
142 MapUnit eCoreMetric,
143 MapUnit ePresMetric,
144 OUString &rText, const IntlWrapper& ) const override;
146 virtual SvxTabStopItem* Clone( SfxItemPool *pPool = nullptr ) const override;
148 void dumpAsXml(xmlTextWriterPtr pWriter) const override;
151 #endif
153 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */