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 * This file incorporates work covered by the following license notice:
10 *
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 .
18 */
19 #ifndef INCLUDED_EDITENG_LRSPITEM_HXX
20 #define INCLUDED_EDITENG_LRSPITEM_HXX
21
22 #include <svl/poolitem.hxx>
23 #include <editeng/editengdllapi.h>
24
25
26 // class SvxLRSpaceItem --------------------------------------------------
27
28 /* [Description]
29
30 Left/Right margin and first line indent
31
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:
37
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
44 */
45
46 #define LRSPACE_TXTLEFT_VERSION (sal_uInt16(0x0002))
47 #define LRSPACE_NEGATIVE_VERSION (sal_uInt16(0x0004))
48
49 class EDITENG_DLLPUBLIC SvxLRSpaceItem final : public SfxPoolItem
50 {
51 tools::Long nTxtLeft; // We spend a sal_uInt16
52 tools::Long nLeftMargin; // nLeft or the negative first-line indent
53 tools::Long nRightMargin; // The unproblematic right edge
54 /// The amount of extra space added to the left margin.
55 tools::Long m_nGutterMargin;
56 /// The amount of extra space added to the right margin, on mirrored pages.
57 tools::Long m_nRightGutterMargin;
58
59 sal_uInt16 nPropFirstLineOffset, nPropLeftMargin, nPropRightMargin;
60 short nFirstLineOffset; // First-line indent _always_ relative to nTxtLeft
61 bool bAutoFirst; // Automatic calculation of the first line indent
62 bool bExplicitZeroMarginValRight;
63 bool bExplicitZeroMarginValLeft;
64
65 void AdjustLeft(); // nLeftMargin and nTxtLeft are being adjusted.
66
67 public:
68
69 static SfxPoolItem* CreateDefault();
70
71 explicit SvxLRSpaceItem( const sal_uInt16 nId );
72 SvxLRSpaceItem( const tools::Long nLeft, const tools::Long nRight,
73 const tools::Long nTLeft /*= 0*/, const short nOfset /*= 0*/,
74 const sal_uInt16 nId );
75 SvxLRSpaceItem(SvxLRSpaceItem const &) = default; // SfxPoolItem copy function dichotomy
76
77 // "pure virtual Methods" from SfxPoolItem
78 virtual bool operator==( const SfxPoolItem& ) const override;
79
80 virtual bool QueryValue( css::uno::Any& rVal, sal_uInt8 nMemberId = 0 ) const override;
81 virtual bool PutValue( const css::uno::Any& rVal, sal_uInt8 nMemberId ) override;
82
83 virtual bool GetPresentation( SfxItemPresentation ePres,
84 MapUnit eCoreMetric,
85 MapUnit ePresMetric,
86 OUString &rText, const IntlWrapper& ) const override;
87
88 virtual SvxLRSpaceItem* Clone( SfxItemPool *pPool = nullptr ) const override;
89 virtual void ScaleMetrics( tools::Long nMult, tools::Long nDiv ) override;
90 virtual bool HasMetrics() const override;
91
92 // The "layout interface":
93 inline void SetLeft ( const tools::Long nL, const sal_uInt16 nProp = 100 );
94 inline void SetRight( const tools::Long nR, const sal_uInt16 nProp = 100 );
95
96 // Query/direct setting of the absolute values
GetLeft() const97 tools::Long GetLeft() const { return nLeftMargin; }
GetRight() const98 tools::Long GetRight() const { return nRightMargin;}
SetLeftValue(const tools::Long nL)99 void SetLeftValue( const tools::Long nL ) { nTxtLeft = nLeftMargin = nL; }
SetRightValue(const tools::Long nR)100 void SetRightValue( const tools::Long nR ) { nRightMargin = nR; }
IsAutoFirst() const101 bool IsAutoFirst() const { return bAutoFirst; }
SetAutoFirst(const bool bNew)102 void SetAutoFirst( const bool bNew ) { bAutoFirst = bNew; }
103
IsExplicitZeroMarginValRight() const104 bool IsExplicitZeroMarginValRight() const { return bExplicitZeroMarginValRight; }
IsExplicitZeroMarginValLeft() const105 bool IsExplicitZeroMarginValLeft() const { return bExplicitZeroMarginValLeft; }
SetExplicitZeroMarginValRight(const bool eR)106 void SetExplicitZeroMarginValRight( const bool eR ) { bExplicitZeroMarginValRight = eR; }
SetExplicitZeroMarginValLeft(const bool eL)107 void SetExplicitZeroMarginValLeft( const bool eL ) { bExplicitZeroMarginValLeft = eL; }
GetPropLeft() const108 sal_uInt16 GetPropLeft() const { return nPropLeftMargin; }
GetPropRight() const109 sal_uInt16 GetPropRight() const { return nPropRightMargin;}
110
111 // The UI/text interface:
112 inline void SetTextLeft( const tools::Long nL, const sal_uInt16 nProp = 100 );
GetTextLeft() const113 tools::Long GetTextLeft() const { return nTxtLeft; }
114
115 inline void SetTextFirstLineOffset( const short nF, const sal_uInt16 nProp = 100 );
GetTextFirstLineOffset() const116 short GetTextFirstLineOffset() const { return nFirstLineOffset; }
SetPropTextFirstLineOffset(const sal_uInt16 nProp)117 void SetPropTextFirstLineOffset( const sal_uInt16 nProp )
118 { nPropFirstLineOffset = nProp; }
GetPropTextFirstLineOffset() const119 sal_uInt16 GetPropTextFirstLineOffset() const
120 { return nPropFirstLineOffset; }
SetTextFirstLineOffsetValue(const short nValue)121 void SetTextFirstLineOffsetValue( const short nValue )
122 { nFirstLineOffset = nValue; }
SetGutterMargin(const tools::Long nGutterMargin)123 void SetGutterMargin(const tools::Long nGutterMargin) { m_nGutterMargin = nGutterMargin; }
GetGutterMargin() const124 tools::Long GetGutterMargin() const { return m_nGutterMargin; }
SetRightGutterMargin(const tools::Long nRightGutterMargin)125 void SetRightGutterMargin(const tools::Long nRightGutterMargin) { m_nRightGutterMargin = nRightGutterMargin; }
GetRightGutterMargin() const126 tools::Long GetRightGutterMargin() const { return m_nRightGutterMargin; }
127
128 void dumpAsXml(xmlTextWriterPtr pWriter) const override;
129 virtual boost::property_tree::ptree dumpAsJSON() const override;
130 };
131
SetLeft(const tools::Long nL,const sal_uInt16 nProp)132 inline void SvxLRSpaceItem::SetLeft( const tools::Long nL, const sal_uInt16 nProp )
133 {
134 nLeftMargin = (nL * nProp) / 100;
135 nTxtLeft = nLeftMargin;
136 nPropLeftMargin = nProp;
137 }
SetRight(const tools::Long nR,const sal_uInt16 nProp)138 inline void SvxLRSpaceItem::SetRight( const tools::Long nR, const sal_uInt16 nProp )
139 {
140 if (0 == nR)
141 {
142 SetExplicitZeroMarginValRight(true);
143 }
144 nRightMargin = (nR * nProp) / 100;
145 nPropRightMargin = nProp;
146 }
SetTextFirstLineOffset(const short nF,const sal_uInt16 nProp)147 inline void SvxLRSpaceItem::SetTextFirstLineOffset( const short nF,
148 const sal_uInt16 nProp )
149 {
150 nFirstLineOffset = short((tools::Long(nF) * nProp ) / 100);
151 nPropFirstLineOffset = nProp;
152 AdjustLeft();
153 }
154
SetTextLeft(const tools::Long nL,const sal_uInt16 nProp)155 inline void SvxLRSpaceItem::SetTextLeft( const tools::Long nL, const sal_uInt16 nProp )
156 {
157 if (0 == nL)
158 {
159 SetExplicitZeroMarginValLeft(true);
160 }
161 nTxtLeft = (nL * nProp) / 100;
162 nPropLeftMargin = nProp;
163 AdjustLeft();
164 }
165
166 #endif
167
168 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
169