xref: /trunk/main/editeng/inc/editeng/lrspitem.hxx (revision cea84f56765a2ac06f0f5a2718f45f6430edc781)
1 /**************************************************************
2  *
3  * Licensed to the Apache Software Foundation (ASF) under one
4  * or more contributor license agreements.  See the NOTICE file
5  * distributed with this work for additional information
6  * regarding copyright ownership.  The ASF licenses this file
7  * to you under the Apache License, Version 2.0 (the
8  * "License"); you may not use this file except in compliance
9  * with the License.  You may obtain a copy of the License at
10  *
11  *   http://www.apache.org/licenses/LICENSE-2.0
12  *
13  * Unless required by applicable law or agreed to in writing,
14  * software distributed under the License is distributed on an
15  * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
16  * KIND, either express or implied.  See the License for the
17  * specific language governing permissions and limitations
18  * under the License.
19  *
20  *************************************************************/
21 
22 
23 #ifndef _SVX_LRSPITEM_HXX
24 #define _SVX_LRSPITEM_HXX
25 
26 // include ---------------------------------------------------------------
27 
28 #include <svl/poolitem.hxx>
29 #include <editeng/editengdllapi.h>
30 
31 namespace rtl
32 {
33     class OUString;
34 }
35 
36 // class SvxLRSpaceItem --------------------------------------------------
37 
38 /*
39 [Beschreibung]
40 Linker/Rechter Rand sowie Erstzeileneinzug
41 
42 SvxLRSpaceItem bietet zwei Schnittstellen zur Befragung des linken
43 Randes und des Erstzeileneinzuges an. Die Get-Methoden liefern
44 die Member zurueck, wie sie das Layout bisher auch erwartete:
45 Der linke Rand verschiebt sich beim negativem Erstzeileneinzug
46 nach links. Die SetTxt/GetTxt-Methoden setzen voraus, dass der
47 linke Rand der 0-Punkt des Erstzeileneinzugs darstellt:
48 
49      UI         UI       LAYOUT   UI/TEXT      UI/TEXT    (Wo?)
50 SetTxtLeft SetTxtFirst GetLeft  GetTxtLeft  GetTxtFirst  (Was?)
51     500       -500        0        500         -500      (Wieviel?)
52     500         0        500       500           0
53     500       +500       500       500         +500
54     700       -500       200       700         -500
55 */
56 
57 #define LRSPACE_16_VERSION      ((sal_uInt16)0x0001)
58 #define LRSPACE_TXTLEFT_VERSION ((sal_uInt16)0x0002)
59 #define LRSPACE_AUTOFIRST_VERSION ((sal_uInt16)0x0003)
60 #define LRSPACE_NEGATIVE_VERSION ((sal_uInt16)0x0004)
61 
62 class EDITENG_DLLPUBLIC SvxLRSpaceItem : public SfxPoolItem
63 {
64     short   nFirstLineOfst;     // Erstzeileneinzug _immer_ relativ zu nTxtLeft
65     long    nTxtLeft;           // wir spendieren einen sal_uInt16
66     long    nLeftMargin;        // nLeft oder der neg. Erstzeileneinzug
67     long    nRightMargin;       // der unproblematische rechte Rand
68 
69     sal_uInt16  nPropFirstLineOfst, nPropLeftMargin, nPropRightMargin;
70     sal_Bool    bAutoFirst  : 1;    // Automatische Berechnung der Erstzeileneinzugs
71 
72     void   AdjustLeft();        // nLeftMargin und nTxtLeft werden angepasst.
73 
74 public:
75     TYPEINFO();
76 
77     SvxLRSpaceItem( const sal_uInt16 nId  );
78     SvxLRSpaceItem( const long nLeft, const long nRight,
79                     const long nTLeft /*= 0*/, const short nOfset /*= 0*/,
80                     const sal_uInt16 nId  );
81     inline SvxLRSpaceItem& operator=( const SvxLRSpaceItem &rCpy );
82     SvxLRSpaceItem(const SvxLRSpaceItem&) = default;
83 
84     // "pure virtual Methoden" vom SfxPoolItem
85     virtual int              operator==( const SfxPoolItem& ) const;
86 
87     virtual sal_Bool             QueryValue( com::sun::star::uno::Any& rVal, sal_uInt8 nMemberId = 0 ) const;
88     virtual sal_Bool             PutValue( const com::sun::star::uno::Any& rVal, sal_uInt8 nMemberId = 0 );
89 
90     virtual SfxItemPresentation GetPresentation( SfxItemPresentation ePres,
91                                     SfxMapUnit eCoreMetric,
92                                     SfxMapUnit ePresMetric,
93                                     String &rText, const IntlWrapper * = 0 ) const;
94 
95     virtual SfxPoolItem*     Clone( SfxItemPool *pPool = 0 ) const;
96     virtual SfxPoolItem*     Create(SvStream &, sal_uInt16) const;
97     virtual SvStream&        Store(SvStream &, sal_uInt16 nItemVersion ) const;
98     virtual sal_uInt16           GetVersion( sal_uInt16 nFileVersion ) const;
99     virtual int              ScaleMetrics( long nMult, long nDiv );
100     virtual int              HasMetrics() const;
101 
102     // Die "Layout-Schnittstelle":
103     inline void   SetLeft ( const long nL, const sal_uInt16 nProp = 100 );
104     inline void   SetRight( const long nR, const sal_uInt16 nProp = 100 );
105 
106     // abfragen / direktes setzen der absoluten Werte
GetLeft() const107     inline long GetLeft()  const { return nLeftMargin; }
GetRight() const108     inline long GetRight() const { return nRightMargin;}
SetLeftValue(const long nL)109     inline void SetLeftValue( const long nL ) { nTxtLeft = nLeftMargin = nL; }
SetRightValue(const long nR)110     inline void SetRightValue( const long nR ) { nRightMargin = nR; }
IsAutoFirst() const111     inline sal_Bool IsAutoFirst()  const { return bAutoFirst; }
SetAutoFirst(const sal_Bool bNew)112     inline void SetAutoFirst( const sal_Bool bNew ) { bAutoFirst = bNew; }
113 
114     // abfragen / setzen der Prozent-Werte
SetPropLeft(const sal_uInt16 nProp=100)115     inline void SetPropLeft( const sal_uInt16 nProp = 100 )
116                     { nPropLeftMargin = nProp; }
SetPropRight(const sal_uInt16 nProp=100)117     inline void SetPropRight( const sal_uInt16 nProp = 100 )
118                     { nPropRightMargin = nProp;}
GetPropLeft() const119     inline sal_uInt16 GetPropLeft()  const { return nPropLeftMargin; }
GetPropRight() const120     inline sal_uInt16 GetPropRight() const { return nPropRightMargin;}
121 
122     // Die "UI/Text-Schnittstelle":
123     inline void SetTxtLeft( const long nL, const sal_uInt16 nProp = 100 );
GetTxtLeft() const124     inline long GetTxtLeft() const { return nTxtLeft; }
125 
126     inline void   SetTxtFirstLineOfst( const short nF, const sal_uInt16 nProp = 100 );
GetTxtFirstLineOfst() const127     inline short  GetTxtFirstLineOfst() const { return nFirstLineOfst; }
SetPropTxtFirstLineOfst(const sal_uInt16 nProp=100)128     inline void SetPropTxtFirstLineOfst( const sal_uInt16 nProp = 100 )
129                     { nPropFirstLineOfst = nProp; }
GetPropTxtFirstLineOfst() const130     inline sal_uInt16 GetPropTxtFirstLineOfst() const
131                     { return nPropFirstLineOfst; }
SetTxtFirstLineOfstValue(const short nValue)132     inline void SetTxtFirstLineOfstValue( const short nValue )
133                     { nFirstLineOfst = nValue; }
134 };
135 
operator =(const SvxLRSpaceItem & rCpy)136 inline SvxLRSpaceItem &SvxLRSpaceItem::operator=( const SvxLRSpaceItem &rCpy )
137 {
138     nFirstLineOfst = rCpy.nFirstLineOfst;
139     nTxtLeft = rCpy.nTxtLeft;
140     nLeftMargin = rCpy.nLeftMargin;
141     nRightMargin = rCpy.nRightMargin;
142     nPropFirstLineOfst = rCpy.nPropFirstLineOfst;
143     nPropLeftMargin = rCpy.nPropLeftMargin;
144     nPropRightMargin = rCpy.nPropRightMargin;
145     bAutoFirst = rCpy.bAutoFirst;
146     return *this;
147 }
148 
SetLeft(const long nL,const sal_uInt16 nProp)149 inline void SvxLRSpaceItem::SetLeft( const long nL, const sal_uInt16 nProp )
150 {
151     nLeftMargin = (nL * nProp) / 100;
152     nTxtLeft = nLeftMargin;
153     nPropLeftMargin = nProp;
154 }
SetRight(const long nR,const sal_uInt16 nProp)155 inline void SvxLRSpaceItem::SetRight( const long nR, const sal_uInt16 nProp )
156 {
157     nRightMargin = (nR * nProp) / 100;
158     nPropRightMargin = nProp;
159 }
SetTxtFirstLineOfst(const short nF,const sal_uInt16 nProp)160 inline void SvxLRSpaceItem::SetTxtFirstLineOfst( const short nF,
161                                                  const sal_uInt16 nProp )
162 {
163     nFirstLineOfst = short((long(nF) * nProp ) / 100);
164     nPropFirstLineOfst = nProp;
165     AdjustLeft();
166 }
167 
SetTxtLeft(const long nL,const sal_uInt16 nProp)168 inline void SvxLRSpaceItem::SetTxtLeft( const long nL, const sal_uInt16 nProp )
169 {
170     nTxtLeft = (nL * nProp) / 100;
171     nPropLeftMargin = nProp;
172     AdjustLeft();
173 }
174 
175 #endif
176