Resolves tdf#142513 - Order of ZoomIn and ZoomOut at Print Preview
[LibreOffice.git] / sw / inc / pagedesc.hxx
blobefeb6539b400dee843a9134dd0d4e724f77395b7
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_SW_INC_PAGEDESC_HXX
20 #define INCLUDED_SW_INC_PAGEDESC_HXX
22 #include <tools/fract.hxx>
23 #include <tools/color.hxx>
24 #include "swdllapi.h"
25 #include "swtypes.hxx"
26 #include "frmfmt.hxx"
27 #include <editeng/numitem.hxx>
28 #include <editeng/borderline.hxx>
29 #include <com/sun/star/drawing/TextVerticalAdjust.hpp>
30 #include <com/sun/star/text/HorizontalAdjust.hpp>
31 #include <o3tl/typed_flags_set.hxx>
33 #include <boost/multi_index_container.hpp>
34 #include <boost/multi_index/identity.hpp>
35 #include <boost/multi_index/ordered_index.hpp>
36 #include <boost/multi_index/random_access_index.hpp>
38 using namespace ::com::sun::star;
41 class SfxPoolItem;
42 class SwTextFormatColl;
43 class SwNode;
44 class SwPageDescs;
45 typedef struct _xmlTextWriter* xmlTextWriterPtr;
47 /// Footnote information.
48 class SW_DLLPUBLIC SwPageFootnoteInfo
50 private:
51 SwTwips m_nMaxHeight; ///< maximum height of the footnote area.
52 sal_uLong m_nLineWidth; ///< width of separator line
53 SvxBorderLineStyle m_eLineStyle; ///< Style of the separator line
54 Color m_LineColor; ///< color of the separator line
55 Fraction m_Width; ///< percentage width of the separator line.
56 css::text::HorizontalAdjust m_eAdjust; ///< line adjustment.
57 SwTwips m_nTopDist; ///< distance between body and separator.
58 SwTwips m_nBottomDist; ///< distance between separator and first footnote
60 public:
61 SwTwips GetHeight() const { return m_nMaxHeight; }
62 sal_uLong GetLineWidth() const { return m_nLineWidth; }
63 const Color& GetLineColor() const { return m_LineColor;}
64 SvxBorderLineStyle GetLineStyle() const { return m_eLineStyle; }
65 const Fraction& GetWidth() const { return m_Width; }
66 css::text::HorizontalAdjust GetAdj() const { return m_eAdjust; }
67 SwTwips GetTopDist() const { return m_nTopDist; }
68 SwTwips GetBottomDist() const { return m_nBottomDist; }
70 void SetHeight(SwTwips const nNew) { m_nMaxHeight = nNew; }
71 void SetLineWidth(sal_uLong const nSet) { m_nLineWidth = nSet; }
72 void SetLineStyle(SvxBorderLineStyle const eSet) {m_eLineStyle = eSet;}
73 void SetLineColor(const Color& rCol) { m_LineColor = rCol;}
74 void SetWidth(const Fraction & rNew) { m_Width = rNew; }
75 void SetAdj(css::text::HorizontalAdjust const eNew) { m_eAdjust = eNew; }
76 void SetTopDist (SwTwips const nNew) { m_nTopDist = nNew; }
77 void SetBottomDist(SwTwips const nNew) { m_nBottomDist = nNew; }
79 SwPageFootnoteInfo();
80 SwPageFootnoteInfo( const SwPageFootnoteInfo& );
81 SwPageFootnoteInfo& operator=( const SwPageFootnoteInfo& );
83 bool operator ==( const SwPageFootnoteInfo& ) const;
87 * Use of UseOnPage (m_eUse) and of FrameFormats
89 * RIGHT - m_Master only for right hand (odd) pages, left hand (even) pages
90 * always empty.
91 * LEFT - m_Left for left-hand pages, right-hand pages always empty.
92 * m_Left is a copy of master.
93 * ALL - m_Master for right hand pages, m_Left for left hand pages.
94 * - m_Left is a copy of master.
95 * MIRROR - m_Master for right hand pages, m_Left for left hand pagers.
96 * m_Left is a copy of master, margins are mirrored.
98 * UI works exclusively on master! m_Left is adjusted on Chg at document
99 * according to m_eUse.
101 * In order to simplify the work of the filters some more values are placed
102 * into m_eUse:
104 * HEADERSHARE - Content of header is equal on left and right hand pages.
105 * FOOTERSHARE - Content of footer is equal on left and right hand pages.
107 * The values are masked out in the respective getter and setter methods.
108 * Access to complete m_eUse including the information on header and footer
109 * via ReadUseOn(), WriteUseOn() (for Filter and CopyCTor)!
111 * The Frameformats for header/footer are adjusted by the UI according to
112 * the attributes for header and footer at master (height, margin, back-
113 * ground ...)
114 * Header/footer for left hand pages are copied or mirrored (Chg at
115 * document).
116 * The respective attribute for content is cared for automatically on Chg at
117 * document (contents are created or removed according to SHARE-information).
120 enum class UseOnPage : sal_uInt16
122 NONE = 0x0000, ///< For internal use only.
123 Left = 0x0001,
124 Right = 0x0002,
125 All = 0x0003,
126 Mirror = 0x0007,
127 HeaderShare = 0x0040,
128 FooterShare = 0x0080,
129 FirstShare = 0x0100,
130 NoHeaderShare = 0xFFBF, ///< For internal use only.
131 NoFooterShare = 0xFF7F, ///< For internal use only.
132 NoFirstShare = 0xFEFF
134 namespace o3tl {
135 template<> struct typed_flags<UseOnPage> : is_typed_flags<UseOnPage, 0xffff> {};
138 class SW_DLLPUBLIC SwPageDesc
139 : public sw::BroadcastingModify
141 friend class SwDoc;
142 friend class SwPageDescs;
144 OUString m_StyleName;
145 SvxNumberType m_NumType;
146 SwFrameFormat m_Master;
147 SwFrameFormat m_Left;
148 // FIXME epicycles growing here - page margins need to be stored differently
149 SwFrameFormat m_FirstMaster;
150 SwFrameFormat m_FirstLeft;
152 struct StashedPageDesc
154 std::shared_ptr<SwFrameFormat> m_pStashedFirst;
155 std::shared_ptr<SwFrameFormat> m_pStashedLeft;
156 std::shared_ptr<SwFrameFormat> m_pStashedFirstLeft;
159 mutable StashedPageDesc m_aStashedHeader;
160 mutable StashedPageDesc m_aStashedFooter;
162 sw::WriterMultiListener m_aDepends; ///< Because of grid alignment (Registerhaltigkeit).
163 mutable const SwTextFormatColl* m_pTextFormatColl;
164 SwPageDesc *m_pFollow;
165 sal_uInt16 m_nRegHeight; ///< Sentence spacing and fontascent of style.
166 sal_uInt16 m_nRegAscent; ///< For grid alignment (Registerhaltigkeit).
167 drawing::TextVerticalAdjust m_nVerticalAdjustment; // doc/docx: vertically center / justify / bottom
168 UseOnPage m_eUse;
169 bool m_IsLandscape;
170 bool m_IsHidden;
172 /// Footnote information.
173 SwPageFootnoteInfo m_FootnoteInfo;
175 /// Backref to the assigned SwPageDescs list to handle renames.
176 SwPageDescs *m_pdList;
178 /** Called for mirroring of Chg (doc).
179 No adjustment at any other place. */
180 SAL_DLLPRIVATE void Mirror();
182 SAL_DLLPRIVATE void ResetAllAttr();
184 SAL_DLLPRIVATE SwPageDesc(const OUString&, SwFrameFormat*, SwDoc *pDc );
186 struct change_name
188 change_name(const OUString &rName) : mName(rName) {}
189 void operator()(SwPageDesc *pPageDesc) { pPageDesc->m_StyleName = mName; }
190 const OUString &mName;
193 protected:
194 virtual void SwClientNotify(const SwModify&, const SfxHint&) override;
196 public:
197 const OUString& GetName() const { return m_StyleName; }
198 bool SetName(const OUString& rNewName);
200 bool GetLandscape() const { return m_IsLandscape; }
201 void SetLandscape( bool bNew ) { m_IsLandscape = bNew; }
203 const SvxNumberType &GetNumType() const { return m_NumType; }
204 void SetNumType(const SvxNumberType& rNew) { m_NumType = rNew; }
206 const SwPageFootnoteInfo &GetFootnoteInfo() const { return m_FootnoteInfo; }
207 SwPageFootnoteInfo &GetFootnoteInfo() { return m_FootnoteInfo; }
208 void SetFootnoteInfo(const SwPageFootnoteInfo &rNew) { m_FootnoteInfo = rNew; }
210 inline bool IsHeaderShared() const;
211 inline bool IsFooterShared() const;
212 inline void ChgHeaderShare( bool bNew );
213 inline void ChgFooterShare( bool bNew );
214 bool IsFirstShared() const;
215 void ChgFirstShare( bool bNew );
217 bool IsHidden() const { return m_IsHidden; }
218 void SetHidden(bool const bValue) { m_IsHidden = bValue; }
220 /// Remember original header/footer formats even when they are hidden by "sharing".
221 void StashFrameFormat(const SwFrameFormat& rFormat, bool bHeader, bool bLeft, bool bFirst);
223 /// Used to restore hidden header/footer formats.
224 const SwFrameFormat* GetStashedFrameFormat(bool bHeader, bool bLeft, bool bFirst) const;
226 /// Checks if the pagedescriptor has a stashed format according to the parameters or not.
227 bool HasStashedFormat(bool bHeader, bool bLeft, bool bFirst);
229 /// Gives the feature of removing the stashed format by hand if it is necessary.
230 void RemoveStashedFormat(bool bHeader, bool bLeft, bool bFirst);
232 /// Same as WriteUseOn(), but the >= HeaderShare part of the bitfield is not modified.
233 inline void SetUseOn( UseOnPage eNew );
234 inline UseOnPage GetUseOn() const;
236 void WriteUseOn(UseOnPage const eNew) { m_eUse = eNew; }
237 UseOnPage ReadUseOn() const { return m_eUse; }
239 SwFrameFormat &GetMaster() { return m_Master; }
240 SwFrameFormat &GetLeft() { return m_Left; }
241 SwFrameFormat &GetFirstMaster() { return m_FirstMaster; }
242 SwFrameFormat &GetFirstLeft() { return m_FirstLeft; }
243 const SwFrameFormat &GetMaster() const { return m_Master; }
244 const SwFrameFormat &GetLeft() const { return m_Left; }
245 const SwFrameFormat &GetFirstMaster() const { return m_FirstMaster; }
246 const SwFrameFormat &GetFirstLeft() const { return m_FirstLeft; }
248 /** Reset all attrs of the format but keep the ones a pagedesc
249 cannot live without. */
250 inline void ResetAllMasterAttr();
252 /** Layout uses the following methods to obtain a format in order
253 to be able to create a page. */
254 SwFrameFormat *GetRightFormat(bool const bFirst = false);
255 inline const SwFrameFormat *GetRightFormat(bool const bFirst = false) const;
256 SwFrameFormat *GetLeftFormat(bool const bFirst = false);
257 inline const SwFrameFormat *GetLeftFormat(bool const bFirst = false) const;
259 sal_uInt16 GetRegHeight() const { return m_nRegHeight; }
260 sal_uInt16 GetRegAscent() const { return m_nRegAscent; }
261 void SetRegHeight(sal_uInt16 const nNew) { m_nRegHeight = nNew; }
262 void SetRegAscent(sal_uInt16 const nNew) { m_nRegAscent = nNew; }
264 drawing::TextVerticalAdjust GetVerticalAdjustment () const {return m_nVerticalAdjustment; }
265 void SetVerticalAdjustment (const drawing::TextVerticalAdjust nVA) {m_nVerticalAdjustment = nVA; }
267 inline void SetFollow( const SwPageDesc* pNew );
268 const SwPageDesc* GetFollow() const { return m_pFollow; }
269 SwPageDesc* GetFollow() { return m_pFollow; }
271 void SetRegisterFormatColl( const SwTextFormatColl* rFormat );
272 const SwTextFormatColl* GetRegisterFormatColl() const;
273 void RegisterChange();
275 /// Query and set PoolFormat-Id.
276 sal_uInt16 GetPoolFormatId() const { return m_Master.GetPoolFormatId(); }
277 void SetPoolFormatId(sal_uInt16 const nId) { m_Master.SetPoolFormatId(nId); }
278 sal_uInt16 GetPoolHelpId() const { return m_Master.GetPoolHelpId(); }
279 void SetPoolHelpId(sal_uInt16 const nId){ m_Master.SetPoolHelpId(nId); }
280 sal_uInt8 GetPoolHlpFileId() const { return m_Master.GetPoolHlpFileId(); }
281 void SetPoolHlpFileId(sal_uInt8 const nId) { m_Master.SetPoolHlpFileId(nId); }
283 /// Query information from Client.
284 virtual bool GetInfo( SfxPoolItem& ) const override;
286 const SwFrameFormat* GetPageFormatOfNode( const SwNode& rNd,
287 bool bCheckForThisPgDc = true ) const;
288 bool IsFollowNextPageOfNode( const SwNode& rNd ) const;
290 /// Given a SwNode return the pagedesc in use at that location.
291 static const SwPageDesc* GetPageDescOfNode(const SwNode& rNd);
293 static SwPageDesc* GetByName(SwDoc& rDoc, std::u16string_view rName);
295 SwPageDesc& operator=( const SwPageDesc& );
297 SwPageDesc( const SwPageDesc& );
298 virtual ~SwPageDesc() override;
300 void dumpAsXml(xmlTextWriterPtr pWriter) const;
303 namespace std {
304 template<>
305 struct less<SwPageDesc*> {
306 bool operator()(const SwPageDesc *pPageDesc, std::u16string_view rName) const
307 { return pPageDesc->GetName() < rName; }
308 bool operator()(std::u16string_view rName, const SwPageDesc *pPageDesc) const
309 { return rName < pPageDesc->GetName(); }
310 bool operator()(const SwPageDesc *lhs, const SwPageDesc *rhs) const
311 { return lhs->GetName() < rhs->GetName(); }
315 inline void SwPageDesc::SetFollow( const SwPageDesc* pNew )
317 m_pFollow = pNew ? const_cast<SwPageDesc*>(pNew) : this;
320 inline bool SwPageDesc::IsHeaderShared() const
322 return bool(m_eUse & UseOnPage::HeaderShare);
324 inline bool SwPageDesc::IsFooterShared() const
326 return bool(m_eUse & UseOnPage::FooterShare);
328 inline void SwPageDesc::ChgHeaderShare( bool bNew )
330 if ( bNew )
331 m_eUse |= UseOnPage::HeaderShare;
332 else
333 m_eUse &= UseOnPage::NoHeaderShare;
335 inline void SwPageDesc::ChgFooterShare( bool bNew )
337 if ( bNew )
338 m_eUse |= UseOnPage::FooterShare;
339 else
340 m_eUse &= UseOnPage::NoFooterShare;
342 inline void SwPageDesc::SetUseOn( UseOnPage eNew )
344 UseOnPage eTmp = UseOnPage::NONE;
345 if (m_eUse & UseOnPage::HeaderShare)
346 eTmp = UseOnPage::HeaderShare;
347 if (m_eUse & UseOnPage::FooterShare)
348 eTmp |= UseOnPage::FooterShare;
349 if (m_eUse & UseOnPage::FirstShare)
350 eTmp |= UseOnPage::FirstShare;
351 m_eUse = eTmp | eNew;
354 inline UseOnPage SwPageDesc::GetUseOn() const
356 UseOnPage eRet = m_eUse;
357 eRet &= UseOnPage::NoHeaderShare;
358 eRet &= UseOnPage::NoFooterShare;
359 eRet &= UseOnPage::NoFirstShare;
360 return eRet;
363 inline void SwPageDesc::ResetAllMasterAttr()
365 ResetAllAttr();
368 inline const SwFrameFormat *SwPageDesc::GetRightFormat(bool const bFirst) const
370 return const_cast<SwPageDesc*>(this)->GetRightFormat(bFirst);
372 inline const SwFrameFormat *SwPageDesc::GetLeftFormat(bool const bFirst) const
374 return const_cast<SwPageDesc*>(this)->GetLeftFormat(bFirst);
377 class SwPageDescExt
379 public:
380 SwPageDesc m_PageDesc;
381 private:
382 SwDoc * m_pDoc;
383 OUString m_sFollow;
385 void SetPageDesc(const SwPageDesc & rPageDesc);
387 public:
388 SwPageDescExt(const SwPageDesc & rPageDesc, SwDoc * pDoc);
389 SwPageDescExt(const SwPageDescExt & rSrc);
390 ~SwPageDescExt();
392 SwPageDescExt & operator = (const SwPageDescExt & rSrc);
393 SwPageDescExt & operator = (const SwPageDesc & rSrc);
395 OUString const & GetName() const;
397 operator SwPageDesc() const; // #i7983#
400 namespace sw {
401 class PageFootnoteHint final : public SfxHint {};
403 SW_DLLPUBLIC SwTwips FootnoteSeparatorHeight(SwPageFootnoteInfo const&);
406 typedef boost::multi_index_container<
407 SwPageDesc*,
408 boost::multi_index::indexed_by<
409 boost::multi_index::random_access<>,
410 boost::multi_index::ordered_unique<
411 boost::multi_index::identity<SwPageDesc*> >
414 SwPageDescsBase;
416 class SwPageDescs final
418 // function updating ByName index via modify
419 friend bool SwPageDesc::SetName( const OUString& rNewName );
421 typedef SwPageDescsBase::nth_index<0>::type ByPos;
422 typedef SwPageDescsBase::nth_index<1>::type ByName;
423 typedef ByPos::iterator iterator;
425 iterator find_( const OUString &name ) const;
427 SwPageDescsBase m_Array;
428 ByPos &m_PosIndex;
429 ByName &m_NameIndex;
431 public:
432 typedef ByPos::const_iterator const_iterator;
433 typedef SwPageDescsBase::size_type size_type;
434 typedef SwPageDescsBase::value_type value_type;
436 SwPageDescs();
438 // frees all SwPageDesc!
439 ~SwPageDescs();
441 void clear() { return m_Array.clear(); }
442 bool empty() const { return m_Array.empty(); }
443 size_t size() const { return m_Array.size(); }
445 std::pair<const_iterator,bool> push_back( const value_type& x );
446 void erase( const value_type& x );
447 void erase( size_type index );
448 void erase( const_iterator const& position );
450 const_iterator find( const OUString &name ) const
451 { return find_( name ); }
452 const value_type& operator[]( size_t index_ ) const
453 { return m_PosIndex.operator[]( index_ ); }
454 const value_type& front() const { return m_PosIndex.front(); }
455 const value_type& back() const { return m_PosIndex.back(); }
456 const_iterator begin() const { return m_PosIndex.begin(); }
457 const_iterator end() const { return m_PosIndex.end(); }
459 bool contains( const value_type& x ) const
460 { return x->m_pdList == this; }
462 void dumpAsXml(xmlTextWriterPtr pWriter) const;
465 #endif // INCLUDED_SW_INC_PAGEDESC_HXX
467 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */