1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
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 --------------------------------------------------
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?)
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 long nTxtLeft
; // We spend a sal_uInt16
54 long nLeftMargin
; // nLeft or the negative first-line indent
55 long nRightMargin
; // The unproblematic right edge
57 sal_uInt16 nPropFirstLineOfst
, nPropLeftMargin
, nPropRightMargin
;
58 short nFirstLineOfst
; // First-line indent _always_ relative to nTxtLeft
59 bool bAutoFirst
; // Automatic calculation of the first line indent
60 bool bExplicitZeroMarginValRight
;
61 bool bExplicitZeroMarginValLeft
;
63 void AdjustLeft(); // nLeftMargin and nTxtLeft are being adjusted.
67 static SfxPoolItem
* CreateDefault();
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 override
;
78 virtual bool QueryValue( css::uno::Any
& rVal
, sal_uInt8 nMemberId
= 0 ) const override
;
79 virtual bool PutValue( const css::uno::Any
& rVal
, sal_uInt8 nMemberId
) override
;
81 virtual bool GetPresentation( SfxItemPresentation ePres
,
84 OUString
&rText
, const IntlWrapper
* = nullptr ) const override
;
86 virtual SfxPoolItem
* Clone( SfxItemPool
*pPool
= nullptr ) const override
;
87 virtual SfxPoolItem
* Create(SvStream
&, sal_uInt16
) const override
;
88 virtual SvStream
& Store(SvStream
&, sal_uInt16 nItemVersion
) const override
;
89 virtual sal_uInt16
GetVersion( sal_uInt16 nFileVersion
) const override
;
90 virtual void ScaleMetrics( long nMult
, long nDiv
) override
;
91 virtual bool HasMetrics() const 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 long GetLeft() const { return nLeftMargin
; }
99 long GetRight() const { return nRightMargin
;}
100 void SetLeftValue( const long nL
) { nTxtLeft
= nLeftMargin
= nL
; }
101 void SetRightValue( const long nR
) { nRightMargin
= nR
; }
102 bool IsAutoFirst() const { return bAutoFirst
; }
103 void SetAutoFirst( const bool bNew
) { bAutoFirst
= bNew
; }
105 bool IsExplicitZeroMarginValRight() const { return bExplicitZeroMarginValRight
; }
106 bool IsExplicitZeroMarginValLeft() const { return bExplicitZeroMarginValLeft
; }
107 void SetExplicitZeroMarginValRight( const bool eR
) { bExplicitZeroMarginValRight
= eR
; }
108 void SetExplicitZeroMarginValLeft( const bool eL
) { bExplicitZeroMarginValLeft
= eL
; }
109 sal_uInt16
GetPropLeft() const { return nPropLeftMargin
; }
110 sal_uInt16
GetPropRight() const { return nPropRightMargin
;}
112 // The UI/text interface:
113 inline void SetTextLeft( const long nL
, const sal_uInt16 nProp
= 100 );
114 long GetTextLeft() const { return nTxtLeft
; }
116 inline void SetTextFirstLineOfst( const short nF
, const sal_uInt16 nProp
= 100 );
117 short GetTextFirstLineOfst() const { return nFirstLineOfst
; }
118 void SetPropTextFirstLineOfst( const sal_uInt16 nProp
)
119 { nPropFirstLineOfst
= nProp
; }
120 sal_uInt16
GetPropTextFirstLineOfst() const
121 { return nPropFirstLineOfst
; }
122 void SetTextFirstLineOfstValue( const short nValue
)
123 { nFirstLineOfst
= nValue
; }
124 void dumpAsXml(struct _xmlTextWriter
* pWriter
) const override
;
127 inline SvxLRSpaceItem
&SvxLRSpaceItem::operator=( const SvxLRSpaceItem
&rCpy
)
129 nFirstLineOfst
= rCpy
.nFirstLineOfst
;
130 nTxtLeft
= rCpy
.nTxtLeft
;
131 nLeftMargin
= rCpy
.nLeftMargin
;
132 nRightMargin
= rCpy
.nRightMargin
;
133 nPropFirstLineOfst
= rCpy
.nPropFirstLineOfst
;
134 nPropLeftMargin
= rCpy
.nPropLeftMargin
;
135 nPropRightMargin
= rCpy
.nPropRightMargin
;
136 bAutoFirst
= rCpy
.bAutoFirst
;
137 bExplicitZeroMarginValRight
= rCpy
.bExplicitZeroMarginValRight
;
138 bExplicitZeroMarginValLeft
= rCpy
.bExplicitZeroMarginValLeft
;
142 inline void SvxLRSpaceItem::SetLeft( const long nL
, const sal_uInt16 nProp
)
144 nLeftMargin
= (nL
* nProp
) / 100;
145 nTxtLeft
= nLeftMargin
;
146 nPropLeftMargin
= nProp
;
148 inline void SvxLRSpaceItem::SetRight( const long nR
, const sal_uInt16 nProp
)
152 SetExplicitZeroMarginValRight(true);
154 nRightMargin
= (nR
* nProp
) / 100;
155 nPropRightMargin
= nProp
;
157 inline void SvxLRSpaceItem::SetTextFirstLineOfst( const short nF
,
158 const sal_uInt16 nProp
)
160 nFirstLineOfst
= short((long(nF
) * nProp
) / 100);
161 nPropFirstLineOfst
= nProp
;
165 inline void SvxLRSpaceItem::SetTextLeft( const long nL
, const sal_uInt16 nProp
)
169 SetExplicitZeroMarginValLeft(true);
171 nTxtLeft
= (nL
* nProp
) / 100;
172 nPropLeftMargin
= nProp
;
178 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */