xref: /trunk/main/sw/inc/pagedesc.hxx (revision 1ecadb572e7010ff3b3382ad9bf179dbc6efadbb)
1 /*************************************************************************
2  *
3  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4  *
5  * Copyright 2000, 2010 Oracle and/or its affiliates.
6  *
7  * OpenOffice.org - a multi-platform office productivity suite
8  *
9  * This file is part of OpenOffice.org.
10  *
11  * OpenOffice.org is free software: you can redistribute it and/or modify
12  * it under the terms of the GNU Lesser General Public License version 3
13  * only, as published by the Free Software Foundation.
14  *
15  * OpenOffice.org is distributed in the hope that it will be useful,
16  * but WITHOUT ANY WARRANTY; without even the implied warranty of
17  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
18  * GNU Lesser General Public License version 3 for more details
19  * (a copy is included in the LICENSE file that accompanied this code).
20  *
21  * You should have received a copy of the GNU Lesser General Public License
22  * version 3 along with OpenOffice.org.  If not, see
23  * <http://www.openoffice.org/license.html>
24  * for a copy of the LGPLv3 License.
25  *
26  ************************************************************************/
27 #ifndef _PAGEDESC_HXX
28 #define _PAGEDESC_HXX
29 
30 #include <tools/fract.hxx>
31 #include <tools/color.hxx>
32 #include <tools/string.hxx>
33 #include "swdllapi.h"
34 #include <swtypes.hxx>  //fuer SwTwips
35 #include <frmfmt.hxx>
36 //#ifndef _NUMRULE_HXX
37 //#include <numrule.hxx>
38 //#endif
39 #include <editeng/numitem.hxx>
40 
41 class SfxPoolItem;
42 class SwTxtFmtColl;
43 class SwNode;
44 
45 //Separator line adjustment
46 enum SwFtnAdj
47 {
48     FTNADJ_LEFT,
49     FTNADJ_CENTER,
50     FTNADJ_RIGHT
51 };
52 
53 //footnote information
54 class SW_DLLPUBLIC SwPageFtnInfo
55 {
56     SwTwips     nMaxHeight;     //maximum height of the footnote area.
57     sal_uLong       nLineWidth;     //width of separator line
58     Color       aLineColor;     //color of the separator line
59     Fraction    aWidth;         //percentage width of the separator line.
60     SwFtnAdj    eAdj;           //line adjustment.
61     SwTwips     nTopDist;       //distance between body and separator.
62     SwTwips     nBottomDist;    //distance between separator and first footnote
63 
64 public:
65     SwTwips     GetHeight() const       { return nMaxHeight; }
66     sal_uLong           GetLineWidth() const { return nLineWidth; }
67     const Color&    GetLineColor() const { return aLineColor;}
68     const Fraction& GetWidth() const    { return aWidth; }
69     SwFtnAdj    GetAdj()    const       { return eAdj; }
70     SwTwips     GetTopDist()const       { return nTopDist; }
71     SwTwips     GetBottomDist() const   { return nBottomDist; }
72 
73     void SetHeight( SwTwips  nNew )     { nMaxHeight = nNew; }
74     void SetLineWidth(sal_uLong nSet  )     { nLineWidth = nSet; }
75     void SetLineColor(const Color& rCol )  { aLineColor = rCol;}
76     void SetWidth( const Fraction &rNew){ aWidth = rNew; }
77     void SetAdj   ( SwFtnAdj eNew )     { eAdj = eNew; }
78     void SetTopDist   ( SwTwips nNew )  { nTopDist = nNew; }
79     void SetBottomDist( SwTwips nNew )  { nBottomDist = nNew; }
80 
81     SwPageFtnInfo();
82     SwPageFtnInfo( const SwPageFtnInfo& );
83     SwPageFtnInfo& operator=( const SwPageFtnInfo& );
84 
85     sal_Bool operator ==( const SwPageFtnInfo& ) const;
86 };
87 
88 /*
89  * Verwendung des UseOnPage (eUse) und der FrmFmt'e
90  *
91  *  RIGHT   - aMaster nur fuer rechte Seiten, linke  Seiten immer leer.
92  *  LEFT    - aLeft fuer linke  Seiten, rechte Seiten immer leer.
93  *            aLeft ist eine Kopie des Master.
94  *  ALL     - aMaster fuer rechte Seiten, aLeft fuer Linke Seiten.
95  *            aLeft ist eine Kopie des Master.
96  *  MIRROR  - aMaster fuer rechte Seiten, aLeft fuer linke Seiten.
97  *            aLeft ist eine Kopie des Master, Raender sind gespiegelt.
98  *
99  * UI dreht auschliesslich am Master! aLeft wird beim Chg am Dokument
100  * enstprechend dem eUse eingestellt.
101  *
102  * Damit es die Filter etwas einfacher haben werden weitere Werte im
103  * eUse untergebracht:
104  *
105  * HEADERSHARE - Headerinhalt auf beiden Seiten gleich
106  * FOOTERSHARE - Footerinhalt auf beiden Seiten gleich
107  *
108  * Die Werte werden bei den entsprechenden Get-/Set-Methden ausmaskiert.
109  * Zugriff auf das volle eUse inclusive der Header-Footer information
110  * per ReadUseOn(), WriteUseOn() (fuer Filter und CopyCTor)!
111  *
112  * Die FrmFormate fuer Header/Footer werden anhand der Attribute fuer
113  * Header/Footer vom UI am Master eingestellt (Hoehe, Raender, Hintergrund...);
114  * Header/Footer fuer die Linke Seite werden entsprechen kopiert bzw.
115  * gespielt (Chg am Dokument).
116  * Das jew. Attribut fuer den Inhalt wird automatisch beim Chg am
117  * Dokument versorgt (entsprechen den SHARE-informationen werden Inhalte
118  * erzeugt bzw. entfernt).
119  *
120  */
121 
122 typedef sal_uInt16 UseOnPage;
123 namespace nsUseOnPage
124 {
125     const UseOnPage PD_NONE           = 0x0000; //for internal use only.
126     const UseOnPage PD_LEFT           = 0x0001;
127     const UseOnPage PD_RIGHT          = 0x0002;
128     const UseOnPage PD_ALL            = 0x0003;
129     const UseOnPage PD_MIRROR         = 0x0007;
130     const UseOnPage PD_HEADERSHARE    = 0x0040;
131     const UseOnPage PD_FOOTERSHARE    = 0x0080;
132     const UseOnPage PD_NOHEADERSHARE  = 0x00BF; //for internal use only
133     const UseOnPage PD_NOFOOTERSHARE  = 0x007F; //for internal use only
134 }
135 
136 class SW_DLLPUBLIC SwPageDesc : public SwModify
137 {
138     friend class SwDoc;
139     friend class SwUndoPageDescExt;
140 
141     String      aDescName;
142     SvxNumberType   aNumType;
143     SwFrmFmt    aMaster;
144     SwFrmFmt    aLeft;
145     SwDepend    aDepend;    // wg. Registerhaltigkeit
146     SwPageDesc *pFollow;
147     sal_uInt16      nRegHeight; // Zeilenabstand und Fontascent der Vorlage
148     sal_uInt16      nRegAscent; // fuer die Registerhaltigkeit
149     UseOnPage   eUse;
150     sal_Bool        bLandscape;
151 
152     //Fussnoteninformationen
153     SwPageFtnInfo aFtnInfo;
154 
155     //Wird zum Spiegeln vom Chg (Doc) gerufen.
156     //Kein Abgleich an anderer Stelle.
157     SW_DLLPRIVATE void Mirror();
158 
159     SW_DLLPRIVATE void ResetAllAttr( sal_Bool bLeft );
160 
161     SW_DLLPRIVATE SwPageDesc(const String&, SwFrmFmt*, SwDoc *pDc );
162 
163 protected:
164    virtual void Modify( const SfxPoolItem* pOld, const SfxPoolItem *pNewValue );
165 
166 public:
167     const String &GetName() const { return aDescName; }
168           void    SetName( const String& rNewName ) { aDescName = rNewName; }
169 
170     sal_Bool GetLandscape() const { return bLandscape; }
171     void SetLandscape( sal_Bool bNew ) { bLandscape = bNew; }
172 
173     const SvxNumberType &GetNumType() const { return aNumType; }
174           void          SetNumType( const SvxNumberType& rNew ) { aNumType = rNew; }
175 
176     const SwPageFtnInfo &GetFtnInfo() const { return aFtnInfo; }
177           SwPageFtnInfo &GetFtnInfo()       { return aFtnInfo; }
178     void  SetFtnInfo( const SwPageFtnInfo &rNew ) { aFtnInfo = rNew; }
179 
180     inline sal_Bool IsHeaderShared() const;
181     inline sal_Bool IsFooterShared() const;
182     inline void ChgHeaderShare( sal_Bool bNew );
183     inline void ChgFooterShare( sal_Bool bNew );
184 
185     inline void      SetUseOn( UseOnPage eNew );
186     inline UseOnPage GetUseOn() const;
187 
188     void      WriteUseOn( UseOnPage eNew ) { eUse = eNew; }
189     UseOnPage ReadUseOn () const { return eUse; }
190 
191           SwFrmFmt &GetMaster() { return aMaster; }
192           SwFrmFmt &GetLeft()   { return aLeft; }
193     const SwFrmFmt &GetMaster() const { return aMaster; }
194     const SwFrmFmt &GetLeft()   const { return aLeft; }
195 
196     // Reset all attrs of the format but keep the ones a pagedesc
197     // cannot live without.
198     inline void ResetAllMasterAttr();
199     inline void ResetAllLeftAttr();
200 
201     //Mit den folgenden Methoden besorgt sich das Layout ein Format
202     //um eine Seite erzeugen zu koennen
203     inline SwFrmFmt *GetRightFmt();
204     inline const SwFrmFmt *GetRightFmt() const;
205     inline SwFrmFmt *GetLeftFmt();
206     inline const SwFrmFmt *GetLeftFmt() const;
207 
208     sal_uInt16 GetRegHeight() const { return nRegHeight; }
209     sal_uInt16 GetRegAscent() const { return nRegAscent; }
210     void SetRegHeight( sal_uInt16 nNew ){ nRegHeight = nNew; }
211     void SetRegAscent( sal_uInt16 nNew ){ nRegAscent = nNew; }
212 
213     inline void SetFollow( const SwPageDesc* pNew );
214     const SwPageDesc* GetFollow() const { return pFollow; }
215           SwPageDesc* GetFollow() { return pFollow; }
216 
217     void SetRegisterFmtColl( const SwTxtFmtColl* rFmt );
218     const SwTxtFmtColl* GetRegisterFmtColl() const;
219     void RegisterChange();
220 
221     // erfragen und setzen der PoolFormat-Id
222     sal_uInt16 GetPoolFmtId() const         { return aMaster.GetPoolFmtId(); }
223     void SetPoolFmtId( sal_uInt16 nId )     { aMaster.SetPoolFmtId( nId ); }
224     sal_uInt16 GetPoolHelpId() const        { return aMaster.GetPoolHelpId(); }
225     void SetPoolHelpId( sal_uInt16 nId )    { aMaster.SetPoolHelpId( nId ); }
226     sal_uInt8 GetPoolHlpFileId() const      { return aMaster.GetPoolHlpFileId(); }
227     void SetPoolHlpFileId( sal_uInt8 nId )  { aMaster.SetPoolHlpFileId( nId ); }
228 
229         // erfrage vom Client Informationen
230     virtual sal_Bool GetInfo( SfxPoolItem& ) const;
231 
232     const SwFrmFmt* GetPageFmtOfNode( const SwNode& rNd,
233                                     sal_Bool bCheckForThisPgDc = sal_True ) const;
234     sal_Bool IsFollowNextPageOfNode( const SwNode& rNd ) const;
235 
236     //Given a SwNode return the pagedesc in use at that location.
237     static const SwPageDesc* GetPageDescOfNode(const SwNode& rNd);
238 
239     SwPageDesc& operator=( const SwPageDesc& );
240 
241     SwPageDesc( const SwPageDesc& );
242     ~SwPageDesc();
243 };
244 
245 inline void SwPageDesc::SetFollow( const SwPageDesc* pNew )
246 {
247     pFollow = pNew ? (SwPageDesc*)pNew : this;
248 }
249 
250 inline sal_Bool SwPageDesc::IsHeaderShared() const
251 {
252     return eUse & nsUseOnPage::PD_HEADERSHARE ? sal_True : sal_False;
253 }
254 inline sal_Bool SwPageDesc::IsFooterShared() const
255 {
256     return eUse & nsUseOnPage::PD_FOOTERSHARE ? sal_True : sal_False;
257 }
258 inline void SwPageDesc::ChgHeaderShare( sal_Bool bNew )
259 {
260     if ( bNew )
261         eUse = (UseOnPage) (eUse | nsUseOnPage::PD_HEADERSHARE);
262         // (sal_uInt16&)eUse |= (sal_uInt16)nsUseOnPage::PD_HEADERSHARE;
263     else
264         eUse = (UseOnPage) (eUse & nsUseOnPage::PD_NOHEADERSHARE);
265         // (sal_uInt16&)eUse &= (sal_uInt16)nsUseOnPage::PD_NOHEADERSHARE;
266 }
267 inline void SwPageDesc::ChgFooterShare( sal_Bool bNew )
268 {
269     if ( bNew )
270         eUse = (UseOnPage) (eUse | nsUseOnPage::PD_FOOTERSHARE);
271         // (sal_uInt16&)eUse |= (sal_uInt16)nsUseOnPage::PD_FOOTERSHARE;
272     else
273         eUse = (UseOnPage) (eUse & nsUseOnPage::PD_NOFOOTERSHARE);
274         // (sal_uInt16&)eUse &= (sal_uInt16)nsUseOnPage::PD_NOFOOTERSHARE;
275 }
276 inline void SwPageDesc::SetUseOn( UseOnPage eNew )
277 {
278     UseOnPage eTmp = nsUseOnPage::PD_NONE;
279     if ( eUse & nsUseOnPage::PD_HEADERSHARE )
280         eTmp = nsUseOnPage::PD_HEADERSHARE;
281         // (sal_uInt16&)eTmp |= (sal_uInt16)nsUseOnPage::PD_HEADERSHARE;
282     if ( eUse & nsUseOnPage::PD_FOOTERSHARE )
283         eTmp = (UseOnPage) (eTmp | nsUseOnPage::PD_FOOTERSHARE);
284         // (sal_uInt16&)eTmp |= (sal_uInt16)nsUseOnPage::PD_FOOTERSHARE;
285     eUse = (UseOnPage) (eTmp | eNew);
286     // (sal_uInt16&)eUse = eTmp | eNew;
287 }
288 inline UseOnPage SwPageDesc::GetUseOn() const
289 {
290     UseOnPage eRet = eUse;
291     eRet = (UseOnPage) (eRet & nsUseOnPage::PD_NOHEADERSHARE);
292     // (sal_uInt16&)eRet &= (sal_uInt16)nsUseOnPage::PD_NOHEADERSHARE;
293     eRet = (UseOnPage) (eRet & nsUseOnPage::PD_NOFOOTERSHARE);
294     // (sal_uInt16&)eRet &= (sal_uInt16)nsUseOnPage::PD_NOFOOTERSHARE;
295     return eRet;
296 }
297 
298 inline void SwPageDesc::ResetAllMasterAttr()
299 {
300     ResetAllAttr( sal_False );
301 }
302 
303 inline void SwPageDesc::ResetAllLeftAttr()
304 {
305     ResetAllAttr( sal_True );
306 }
307 
308 inline SwFrmFmt *SwPageDesc::GetRightFmt()
309 {
310     return nsUseOnPage::PD_RIGHT & eUse ? &aMaster : 0;
311 }
312 inline const SwFrmFmt *SwPageDesc::GetRightFmt() const
313 {
314     return nsUseOnPage::PD_RIGHT & eUse ? &aMaster : 0;
315 }
316 inline SwFrmFmt *SwPageDesc::GetLeftFmt()
317 {
318     return nsUseOnPage::PD_LEFT & eUse ? &aLeft : 0;
319 }
320 inline const SwFrmFmt *SwPageDesc::GetLeftFmt() const
321 {
322     return nsUseOnPage::PD_LEFT & eUse ? &aLeft : 0;
323 }
324 
325 class SwPageDescExt
326 {
327     SwPageDesc aPageDesc;
328     SwDoc * pDoc;
329     String sFollow;
330 
331     void SetPageDesc(const SwPageDesc & aPageDesc);
332 
333 public:
334     SwPageDescExt(const SwPageDesc & rPageDesc, SwDoc * pDoc);
335     SwPageDescExt(const SwPageDescExt & rSrc);
336     ~SwPageDescExt();
337 
338     SwPageDescExt & operator = (const SwPageDescExt & rSrc);
339     SwPageDescExt & operator = (const SwPageDesc & rSrc);
340 
341     const String & GetName() const;
342 
343     operator SwPageDesc() const; // #i7983#
344 };
345 
346 
347 SwPageDesc* GetPageDescByName_Impl(SwDoc& rDoc, const String& rName);
348 
349 #endif  //_PAGEDESC_HXX
350