Use COMReference to handle COM pointers in CreateShortcut
[LibreOffice.git] / sw / inc / pagedesc.hxx
blobf2da66539b96fea4a22dbbb2fd3cd62911093c14
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 SwNodes;
45 class SwPageDescs;
46 typedef struct _xmlTextWriter* xmlTextWriterPtr;
48 /// Footnote information.
49 class SW_DLLPUBLIC SwPageFootnoteInfo
51 private:
52 SwTwips m_nMaxHeight; ///< maximum height of the footnote area.
53 sal_uLong m_nLineWidth; ///< width of separator line
54 SvxBorderLineStyle m_eLineStyle; ///< Style of the separator line
55 Color m_LineColor; ///< color of the separator line
56 Fraction m_Width; ///< percentage width of the separator line.
57 css::text::HorizontalAdjust m_eAdjust; ///< line adjustment.
58 SwTwips m_nTopDist; ///< distance between body and separator.
59 SwTwips m_nBottomDist; ///< distance between separator and first footnote
61 public:
62 SwTwips GetHeight() const { return m_nMaxHeight; }
63 sal_uLong GetLineWidth() const { return m_nLineWidth; }
64 const Color& GetLineColor() const { return m_LineColor;}
65 SvxBorderLineStyle GetLineStyle() const { return m_eLineStyle; }
66 const Fraction& GetWidth() const { return m_Width; }
67 css::text::HorizontalAdjust GetAdj() const { return m_eAdjust; }
68 SwTwips GetTopDist() const { return m_nTopDist; }
69 SwTwips GetBottomDist() const { return m_nBottomDist; }
71 void SetHeight(SwTwips const nNew) { m_nMaxHeight = nNew; }
72 void SetLineWidth(sal_uLong const nSet) { m_nLineWidth = nSet; }
73 void SetLineStyle(SvxBorderLineStyle const eSet) {m_eLineStyle = eSet;}
74 void SetLineColor(const Color& rCol) { m_LineColor = rCol;}
75 void SetWidth(const Fraction & rNew) { m_Width = rNew; }
76 void SetAdj(css::text::HorizontalAdjust const eNew) { m_eAdjust = eNew; }
77 void SetTopDist (SwTwips const nNew) { m_nTopDist = nNew; }
78 void SetBottomDist(SwTwips const nNew) { m_nBottomDist = nNew; }
80 SwPageFootnoteInfo();
81 SwPageFootnoteInfo( const SwPageFootnoteInfo& );
82 SwPageFootnoteInfo& operator=( const SwPageFootnoteInfo& );
84 bool operator ==( const SwPageFootnoteInfo& ) const;
88 * Use of UseOnPage (m_eUse) and of FrameFormats
90 * RIGHT - m_Master only for right hand (odd) pages, left hand (even) pages
91 * always empty.
92 * LEFT - m_Left for left-hand pages, right-hand pages always empty.
93 * m_Left is a copy of master.
94 * ALL - m_Master for right hand pages, m_Left for left hand pages.
95 * - m_Left is a copy of master.
96 * MIRROR - m_Master for right hand pages, m_Left for left hand pagers.
97 * m_Left is a copy of master, margins are mirrored.
99 * UI works exclusively on master! m_Left is adjusted on Chg at document
100 * according to m_eUse.
102 * In order to simplify the work of the filters some more values are placed
103 * into m_eUse:
105 * HEADERSHARE - Content of header is equal on left and right hand pages.
106 * FOOTERSHARE - Content of footer is equal on left and right hand pages.
108 * The values are masked out in the respective getter and setter methods.
109 * Access to complete m_eUse including the information on header and footer
110 * via ReadUseOn(), WriteUseOn() (for Filter and CopyCTor)!
112 * The Frameformats for header/footer are adjusted by the UI according to
113 * the attributes for header and footer at master (height, margin, back-
114 * ground ...)
115 * Header/footer for left hand pages are copied or mirrored (Chg at
116 * document).
117 * The respective attribute for content is cared for automatically on Chg at
118 * document (contents are created or removed according to SHARE-information).
121 enum class UseOnPage : sal_uInt16
123 NONE = 0x0000, ///< For internal use only.
124 Left = 0x0001,
125 Right = 0x0002,
126 All = 0x0003,
127 Mirror = 0x0007,
128 HeaderShare = 0x0040,
129 FooterShare = 0x0080,
130 FirstShare = 0x0100,
131 NoHeaderShare = 0xFFBF, ///< For internal use only.
132 NoFooterShare = 0xFF7F, ///< For internal use only.
133 NoFirstShare = 0xFEFF
135 namespace o3tl {
136 template<> struct typed_flags<UseOnPage> : is_typed_flags<UseOnPage, 0xffff> {};
139 class SW_DLLPUBLIC SwPageDesc final
140 : public sw::BroadcastingModify
142 friend class SwDoc;
143 friend class SwPageDescs;
145 OUString m_StyleName;
146 SvxNumberType m_NumType;
147 SwFrameFormat m_Master;
148 SwFrameFormat m_Left;
149 // FIXME epicycles growing here - page margins need to be stored differently
150 SwFrameFormat m_FirstMaster;
151 SwFrameFormat m_FirstLeft;
153 struct StashedPageDesc
155 std::optional<SwFrameFormat> m_oStashedFirst;
156 std::optional<SwFrameFormat> m_oStashedLeft;
157 std::optional<SwFrameFormat> m_oStashedFirstLeft;
160 mutable StashedPageDesc m_aStashedHeader;
161 mutable StashedPageDesc m_aStashedFooter;
163 sw::WriterMultiListener m_aDepends; ///< Because of grid alignment (Registerhaltigkeit).
164 mutable const SwTextFormatColl* m_pTextFormatColl;
165 SwPageDesc *m_pFollow;
166 sal_uInt16 m_nRegHeight; ///< Sentence spacing and fontascent of style.
167 sal_uInt16 m_nRegAscent; ///< For grid alignment (Registerhaltigkeit).
168 drawing::TextVerticalAdjust m_nVerticalAdjustment; // doc/docx: vertically center / justify / bottom
169 UseOnPage m_eUse;
170 bool m_IsLandscape;
171 bool m_IsHidden;
173 /// Footnote information.
174 SwPageFootnoteInfo m_FootnoteInfo;
176 /// Backref to the assigned SwPageDescs list to handle renames.
177 SwPageDescs *m_pdList;
179 /** Called for mirroring of Chg (doc).
180 No adjustment at any other place. */
181 SAL_DLLPRIVATE void Mirror();
183 SAL_DLLPRIVATE void ResetAllAttr();
185 SAL_DLLPRIVATE SwPageDesc(const OUString&, SwFrameFormat*, SwDoc *pDc );
187 struct change_name
189 change_name(const OUString &rName) : mName(rName) {}
190 void operator()(SwPageDesc *pPageDesc) { pPageDesc->m_StyleName = mName; }
191 const OUString &mName;
194 virtual void SwClientNotify(const SwModify&, const SfxHint&) override;
196 public:
197 bool IsUsed() const;
198 const OUString& GetName() const { return m_StyleName; }
199 bool SetName(const OUString& rNewName);
201 bool GetLandscape() const { return m_IsLandscape; }
202 void SetLandscape( bool bNew ) { m_IsLandscape = bNew; }
204 const SvxNumberType &GetNumType() const { return m_NumType; }
205 void SetNumType(const SvxNumberType& rNew) { m_NumType = rNew; }
207 const SwPageFootnoteInfo &GetFootnoteInfo() const { return m_FootnoteInfo; }
208 SwPageFootnoteInfo &GetFootnoteInfo() { return m_FootnoteInfo; }
209 void SetFootnoteInfo(const SwPageFootnoteInfo &rNew) { m_FootnoteInfo = rNew; }
211 inline bool IsHeaderShared() const;
212 inline bool IsFooterShared() const;
213 inline void ChgHeaderShare( bool bNew );
214 inline void ChgFooterShare( bool bNew );
215 bool IsFirstShared() const;
216 void ChgFirstShare( bool bNew );
218 bool IsHidden() const { return m_IsHidden; }
219 void SetHidden(bool const bValue) { m_IsHidden = bValue; }
221 /// Remember original header/footer formats even when they are hidden by "sharing".
222 void StashFrameFormat(const SwFrameFormat& rFormat, bool bHeader, bool bLeft, bool bFirst);
224 /// Used to restore hidden header/footer formats.
225 const SwFrameFormat* GetStashedFrameFormat(bool bHeader, bool bLeft, bool bFirst) const;
227 /// Checks if the pagedescriptor has a stashed format according to the parameters or not.
228 bool HasStashedFormat(bool bHeader, bool bLeft, bool bFirst) const;
230 /// Gives the feature of removing the stashed format by hand if it is necessary.
231 void RemoveStashedFormat(bool bHeader, bool bLeft, bool bFirst);
233 /// Same as WriteUseOn(), but the >= HeaderShare part of the bitfield is not modified.
234 inline void SetUseOn( UseOnPage eNew );
235 inline UseOnPage GetUseOn() const;
237 void WriteUseOn(UseOnPage const eNew) { m_eUse = eNew; }
238 UseOnPage ReadUseOn() const { return m_eUse; }
240 SwFrameFormat &GetMaster() { return m_Master; }
241 SwFrameFormat &GetLeft() { return m_Left; }
242 SwFrameFormat &GetFirstMaster() { return m_FirstMaster; }
243 SwFrameFormat &GetFirstLeft() { return m_FirstLeft; }
244 const SwFrameFormat &GetMaster() const { return m_Master; }
245 const SwFrameFormat &GetLeft() const { return m_Left; }
246 const SwFrameFormat &GetFirstMaster() const { return m_FirstMaster; }
247 const SwFrameFormat &GetFirstLeft() const { return m_FirstLeft; }
249 /** Reset all attrs of the format but keep the ones a pagedesc
250 cannot live without. */
251 inline void ResetAllMasterAttr();
253 /** Layout uses the following methods to obtain a format in order
254 to be able to create a page. */
255 SwFrameFormat *GetRightFormat(bool const bFirst = false);
256 inline const SwFrameFormat *GetRightFormat(bool const bFirst = false) const;
257 SwFrameFormat *GetLeftFormat(bool const bFirst = false);
258 inline const SwFrameFormat *GetLeftFormat(bool const bFirst = false) const;
260 sal_uInt16 GetRegHeight() const { return m_nRegHeight; }
261 sal_uInt16 GetRegAscent() const { return m_nRegAscent; }
262 void SetRegHeight(sal_uInt16 const nNew) { m_nRegHeight = nNew; }
263 void SetRegAscent(sal_uInt16 const nNew) { m_nRegAscent = nNew; }
265 drawing::TextVerticalAdjust GetVerticalAdjustment () const {return m_nVerticalAdjustment; }
266 void SetVerticalAdjustment (const drawing::TextVerticalAdjust nVA) {m_nVerticalAdjustment = nVA; }
268 inline void SetFollow( const SwPageDesc* pNew );
269 const SwPageDesc* GetFollow() const { return m_pFollow; }
270 SwPageDesc* GetFollow() { return m_pFollow; }
272 void SetRegisterFormatColl( const SwTextFormatColl* rFormat );
273 const SwTextFormatColl* GetRegisterFormatColl() const;
274 void RegisterChange();
276 /// Query and set PoolFormat-Id.
277 sal_uInt16 GetPoolFormatId() const { return m_Master.GetPoolFormatId(); }
278 void SetPoolFormatId(sal_uInt16 const nId) { m_Master.SetPoolFormatId(nId); }
279 sal_uInt16 GetPoolHelpId() const { return m_Master.GetPoolHelpId(); }
280 void SetPoolHelpId(sal_uInt32 const nId){ m_Master.SetPoolHelpId(nId); }
281 sal_uInt8 GetPoolHlpFileId() const { return m_Master.GetPoolHlpFileId(); }
282 void SetPoolHlpFileId(sal_uInt8 const nId) { m_Master.SetPoolHlpFileId(nId); }
284 /// Query information from Client.
285 virtual bool GetInfo( SwFindNearestNode& ) const override;
287 const SwFrameFormat* GetPageFormatOfNode( const SwNode& rNd,
288 bool bCheckForThisPgDc = true ) const;
289 bool IsFollowNextPageOfNode( const SwNode& rNd ) const;
291 /// Given a SwNode return the pagedesc in use at that location.
292 static const SwPageDesc* GetPageDescOfNode(const SwNode& rNd);
294 static SwPageDesc* GetByName(SwDoc& rDoc, std::u16string_view rName);
296 SwPageDesc& operator=( const SwPageDesc& );
298 SwPageDesc( const SwPageDesc& );
299 virtual ~SwPageDesc() override;
301 void dumpAsXml(xmlTextWriterPtr pWriter) const;
304 namespace std {
305 template<>
306 struct less<SwPageDesc*> {
307 bool operator()(const SwPageDesc *pPageDesc, std::u16string_view rName) const
308 { return pPageDesc->GetName() < rName; }
309 bool operator()(std::u16string_view rName, const SwPageDesc *pPageDesc) const
310 { return rName < pPageDesc->GetName(); }
311 bool operator()(const SwPageDesc *lhs, const SwPageDesc *rhs) const
312 { return lhs->GetName() < rhs->GetName(); }
316 inline void SwPageDesc::SetFollow( const SwPageDesc* pNew )
318 m_pFollow = pNew ? const_cast<SwPageDesc*>(pNew) : this;
321 inline bool SwPageDesc::IsHeaderShared() const
323 return bool(m_eUse & UseOnPage::HeaderShare);
325 inline bool SwPageDesc::IsFooterShared() const
327 return bool(m_eUse & UseOnPage::FooterShare);
329 inline void SwPageDesc::ChgHeaderShare( bool bNew )
331 if ( bNew )
332 m_eUse |= UseOnPage::HeaderShare;
333 else
334 m_eUse &= UseOnPage::NoHeaderShare;
336 inline void SwPageDesc::ChgFooterShare( bool bNew )
338 if ( bNew )
339 m_eUse |= UseOnPage::FooterShare;
340 else
341 m_eUse &= UseOnPage::NoFooterShare;
343 inline void SwPageDesc::SetUseOn( UseOnPage eNew )
345 UseOnPage eTmp = UseOnPage::NONE;
346 if (m_eUse & UseOnPage::HeaderShare)
347 eTmp = UseOnPage::HeaderShare;
348 if (m_eUse & UseOnPage::FooterShare)
349 eTmp |= UseOnPage::FooterShare;
350 if (m_eUse & UseOnPage::FirstShare)
351 eTmp |= UseOnPage::FirstShare;
352 m_eUse = eTmp | eNew;
355 inline UseOnPage SwPageDesc::GetUseOn() const
357 UseOnPage eRet = m_eUse;
358 eRet &= UseOnPage::NoHeaderShare;
359 eRet &= UseOnPage::NoFooterShare;
360 eRet &= UseOnPage::NoFirstShare;
361 return eRet;
364 inline void SwPageDesc::ResetAllMasterAttr()
366 ResetAllAttr();
369 inline const SwFrameFormat *SwPageDesc::GetRightFormat(bool const bFirst) const
371 return const_cast<SwPageDesc*>(this)->GetRightFormat(bFirst);
373 inline const SwFrameFormat *SwPageDesc::GetLeftFormat(bool const bFirst) const
375 return const_cast<SwPageDesc*>(this)->GetLeftFormat(bFirst);
378 class SwPageDescExt
380 public:
381 SwPageDesc m_PageDesc;
382 private:
383 SwDoc * m_pDoc;
384 OUString m_sFollow;
386 void SetPageDesc(const SwPageDesc & rPageDesc);
388 public:
389 SwPageDescExt(const SwPageDesc & rPageDesc, SwDoc * pDoc);
390 SwPageDescExt(const SwPageDescExt & rSrc);
391 ~SwPageDescExt();
393 SwPageDescExt & operator = (const SwPageDescExt & rSrc);
394 SwPageDescExt & operator = (const SwPageDesc & rSrc);
396 OUString const & GetName() const;
398 explicit operator SwPageDesc() const; // #i7983#
401 namespace sw {
402 class PageFootnoteHint final : public SfxHint
404 public:
405 PageFootnoteHint() : SfxHint(SfxHintId::SwPageFootnote) {}
408 SW_DLLPUBLIC SwTwips FootnoteSeparatorHeight(SwDoc& rDoc, SwPageFootnoteInfo const&);
411 typedef boost::multi_index_container<
412 SwPageDesc*,
413 boost::multi_index::indexed_by<
414 boost::multi_index::random_access<>,
415 boost::multi_index::ordered_unique<
416 boost::multi_index::identity<SwPageDesc*> >
419 SwPageDescsBase;
421 class SwPageDescs final
423 // function updating ByName index via modify
424 friend bool SwPageDesc::SetName( const OUString& rNewName );
426 typedef SwPageDescsBase::nth_index<0>::type ByPos;
427 typedef SwPageDescsBase::nth_index<1>::type ByName;
428 typedef ByPos::iterator iterator;
430 iterator find_( const OUString &name ) const;
432 SwPageDescsBase m_Array;
433 ByPos &m_PosIndex;
434 ByName &m_NameIndex;
436 public:
437 typedef ByPos::const_iterator const_iterator;
438 typedef SwPageDescsBase::size_type size_type;
439 typedef SwPageDescsBase::value_type value_type;
441 SwPageDescs();
443 // frees all SwPageDesc!
444 ~SwPageDescs();
446 void clear() { return m_Array.clear(); }
447 bool empty() const { return m_Array.empty(); }
448 size_t size() const { return m_Array.size(); }
450 std::pair<const_iterator,bool> push_back( const value_type& x );
451 void erase( const value_type& x );
452 void erase( size_type index );
453 void erase( const_iterator const& position );
455 const_iterator find( const OUString &name ) const
456 { return find_( name ); }
457 const value_type& operator[]( size_t index_ ) const
458 { return m_PosIndex.operator[]( index_ ); }
459 const value_type& front() const { return m_PosIndex.front(); }
460 const value_type& back() const { return m_PosIndex.back(); }
461 const_iterator begin() const { return m_PosIndex.begin(); }
462 const_iterator end() const { return m_PosIndex.end(); }
464 bool contains( const value_type& x ) const
465 { return x->m_pdList == this; }
467 void dumpAsXml(xmlTextWriterPtr pWriter) const;
470 #endif // INCLUDED_SW_INC_PAGEDESC_HXX
472 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */