Branch libreoffice-5-0-4
[LibreOffice.git] / include / editeng / lrspitem.hxx
blob4e1b0796bbd647d6a932f5a8b3da29f36f007f72
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_LRSPITEM_HXX
20 #define INCLUDED_EDITENG_LRSPITEM_HXX
22 #include <svl/poolitem.hxx>
23 #include <editeng/editengdllapi.h>
26 // class SvxLRSpaceItem --------------------------------------------------
28 /* [Description]
30 Left/Right margin and first line indent
32 SvxLRSpaceItem offers two interfaces for views from the left margin and
33 first line indent. The get methods return the member, with the layout also
34 as expected: the left edge shifts to the negative first line indent to the
35 left. The SetTxt/Gettxt methods assume that the left side represents the
36 0 coordinate for the first line indent:
38 UI UI LAYOUT UI/TEXT UI/TEXT (Where?)
39 SetTextLeft SetTxtFirst GetLeft GetTextLeft GetTxtFirst (What?)
40 500 -500 0 500 -500 (How much?)
41 500 0 500 500 0
42 500 +500 500 500 +500
43 700 -500 200 700 -500
46 #define LRSPACE_16_VERSION ((sal_uInt16)0x0001)
47 #define LRSPACE_TXTLEFT_VERSION ((sal_uInt16)0x0002)
48 #define LRSPACE_AUTOFIRST_VERSION ((sal_uInt16)0x0003)
49 #define LRSPACE_NEGATIVE_VERSION ((sal_uInt16)0x0004)
51 class EDITENG_DLLPUBLIC SvxLRSpaceItem : public SfxPoolItem
53 short nFirstLineOfst; // First-line indent _always_ relative to nTxtLeft
54 long nTxtLeft; // We spend a sal_uInt16
55 long nLeftMargin; // nLeft or the negative first-line indent
56 long nRightMargin; // The unproblematic right edge
58 sal_uInt16 nPropFirstLineOfst, nPropLeftMargin, nPropRightMargin;
59 bool bAutoFirst : 1; // Automatic calculation of the first line indent
60 bool bExplicitZeroMarginValRight;
61 bool bExplicitZeroMarginValLeft;
63 void AdjustLeft(); // nLeftMargin and nTxtLeft are being adjusted.
65 public:
67 TYPEINFO_OVERRIDE();
69 explicit SvxLRSpaceItem( const sal_uInt16 nId );
70 SvxLRSpaceItem( const long nLeft, const long nRight,
71 const long nTLeft /*= 0*/, const short nOfset /*= 0*/,
72 const sal_uInt16 nId );
73 inline SvxLRSpaceItem& operator=( const SvxLRSpaceItem &rCpy );
75 // "pure virtual Methods" from SfxPoolItem
76 virtual bool operator==( const SfxPoolItem& ) const SAL_OVERRIDE;
78 virtual bool QueryValue( com::sun::star::uno::Any& rVal, sal_uInt8 nMemberId = 0 ) const SAL_OVERRIDE;
79 virtual bool PutValue( const com::sun::star::uno::Any& rVal, sal_uInt8 nMemberId = 0 ) SAL_OVERRIDE;
81 virtual bool GetPresentation( SfxItemPresentation ePres,
82 SfxMapUnit eCoreMetric,
83 SfxMapUnit ePresMetric,
84 OUString &rText, const IntlWrapper * = 0 ) const SAL_OVERRIDE;
86 virtual SfxPoolItem* Clone( SfxItemPool *pPool = 0 ) const SAL_OVERRIDE;
87 virtual SfxPoolItem* Create(SvStream &, sal_uInt16) const SAL_OVERRIDE;
88 virtual SvStream& Store(SvStream &, sal_uInt16 nItemVersion ) const SAL_OVERRIDE;
89 virtual sal_uInt16 GetVersion( sal_uInt16 nFileVersion ) const SAL_OVERRIDE;
90 virtual bool ScaleMetrics( long nMult, long nDiv ) SAL_OVERRIDE;
91 virtual bool HasMetrics() const SAL_OVERRIDE;
93 // Die "Layout-Schnittstelle":
94 inline void SetLeft ( const long nL, const sal_uInt16 nProp = 100 );
95 inline void SetRight( const long nR, const sal_uInt16 nProp = 100 );
97 // Query/direct setting of the absolute values
98 inline long GetLeft() const { return nLeftMargin; }
99 inline long GetRight() const { return nRightMargin;}
100 inline void SetLeftValue( const long nL ) { nTxtLeft = nLeftMargin = nL; }
101 inline void SetRightValue( const long nR ) { nRightMargin = nR; }
102 inline bool IsAutoFirst() const { return bAutoFirst; }
103 inline void SetAutoFirst( const bool bNew ) { bAutoFirst = bNew; }
105 inline bool IsExplicitZeroMarginValRight() const { return bExplicitZeroMarginValRight; }
106 inline bool IsExplicitZeroMarginValLeft() const { return bExplicitZeroMarginValLeft; }
107 inline void SetExplicitZeroMarginValRight( const bool eR ) { bExplicitZeroMarginValRight = eR; }
108 inline void SetExplicitZeroMarginValLeft( const bool eL ) { bExplicitZeroMarginValLeft = eL; }
109 // Query/Setting the percentage values
110 inline void SetPropLeft( const sal_uInt16 nProp = 100 )
111 { nPropLeftMargin = nProp; }
112 inline void SetPropRight( const sal_uInt16 nProp = 100 )
113 { nPropRightMargin = nProp;}
114 inline sal_uInt16 GetPropLeft() const { return nPropLeftMargin; }
115 inline sal_uInt16 GetPropRight() const { return nPropRightMargin;}
117 // The UI/text interface:
118 inline void SetTextLeft( const long nL, const sal_uInt16 nProp = 100 );
119 inline long GetTextLeft() const { return nTxtLeft; }
121 inline void SetTextFirstLineOfst( const short nF, const sal_uInt16 nProp = 100 );
122 inline short GetTextFirstLineOfst() const { return nFirstLineOfst; }
123 inline void SetPropTextFirstLineOfst( const sal_uInt16 nProp = 100 )
124 { nPropFirstLineOfst = nProp; }
125 inline sal_uInt16 GetPropTextFirstLineOfst() const
126 { return nPropFirstLineOfst; }
127 inline void SetTextFirstLineOfstValue( const short nValue )
128 { nFirstLineOfst = nValue; }
129 void dumpAsXml(struct _xmlTextWriter* pWriter) const SAL_OVERRIDE;
132 inline SvxLRSpaceItem &SvxLRSpaceItem::operator=( const SvxLRSpaceItem &rCpy )
134 nFirstLineOfst = rCpy.nFirstLineOfst;
135 nTxtLeft = rCpy.nTxtLeft;
136 nLeftMargin = rCpy.nLeftMargin;
137 nRightMargin = rCpy.nRightMargin;
138 nPropFirstLineOfst = rCpy.nPropFirstLineOfst;
139 nPropLeftMargin = rCpy.nPropLeftMargin;
140 nPropRightMargin = rCpy.nPropRightMargin;
141 bAutoFirst = rCpy.bAutoFirst;
142 bExplicitZeroMarginValRight = rCpy.bExplicitZeroMarginValRight;
143 bExplicitZeroMarginValLeft = rCpy.bExplicitZeroMarginValLeft;
144 return *this;
147 inline void SvxLRSpaceItem::SetLeft( const long nL, const sal_uInt16 nProp )
149 nLeftMargin = (nL * nProp) / 100;
150 nTxtLeft = nLeftMargin;
151 nPropLeftMargin = nProp;
153 inline void SvxLRSpaceItem::SetRight( const long nR, const sal_uInt16 nProp )
155 if (0 == nR)
157 SetExplicitZeroMarginValRight(true);
159 nRightMargin = (nR * nProp) / 100;
160 nPropRightMargin = nProp;
162 inline void SvxLRSpaceItem::SetTextFirstLineOfst( const short nF,
163 const sal_uInt16 nProp )
165 nFirstLineOfst = short((long(nF) * nProp ) / 100);
166 nPropFirstLineOfst = nProp;
167 AdjustLeft();
170 inline void SvxLRSpaceItem::SetTextLeft( const long nL, const sal_uInt16 nProp )
172 if (0 == nL)
174 SetExplicitZeroMarginValLeft(true);
176 nTxtLeft = (nL * nProp) / 100;
177 nPropLeftMargin = nProp;
178 AdjustLeft();
181 #endif
183 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */