1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 /*
3  * This file is part of the LibreOffice project.
4  *
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/.
8  *
9  * This file incorporates work covered by the following license notice:
10  *
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 .
18  */
19 #ifndef INCLUDED_SW_INC_FORMAT_HXX
20 #define INCLUDED_SW_INC_FORMAT_HXX
21 
22 #include "swdllapi.h"
23 
24 #include "BorderCacheOwner.hxx"
25 #include "calbck.hxx"
26 #include "hintids.hxx"
27 #include "swatrset.hxx"
28 #include <memory>
29 
30 class IDocumentSettingAccess;
31 class IDocumentDrawModelAccess;
32 class IDocumentLayoutAccess;
33 class IDocumentTimerAccess;
34 class IDocumentFieldsAccess;
35 class IDocumentChartDataProviderAccess;
36 class SwDoc;
37 class SfxGrabBagItem;
38 class SwTextGridItem;
39 
40 namespace drawinglayer::attribute {
41     class SdrAllFillAttributesHelper;
42     typedef std::shared_ptr< SdrAllFillAttributesHelper > SdrAllFillAttributesHelperPtr;
43 }
44 
45 /// Base class for various Writer styles.
46 class SW_DLLPUBLIC SwFormat : public sw::BorderCacheOwner, public sw::BroadcastingModify
47 {
48     friend class SwFrameFormat;
49 
50     OUString m_aFormatName;
51     SwAttrSet m_aSet;
52 
53     sal_uInt16 m_nWhichId;
54     sal_uInt16 m_nPoolFormatId;        /**< Id for "automatically" created formats.
55                                        (is not hard attribution!!!) */
56     sal_uInt16 m_nPoolHelpId;       ///< HelpId for this Pool-style.
57     sal_uInt8 m_nPoolHlpFileId;     ///< FilePos to Doc to these style helps.
58     bool   m_bAutoFormat : 1;      /**< FALSE: it is a template.
59                                        default is true! */
60     bool   m_bFormatInDTOR : 1;    /**< TRUE: Format becomes deleted. In order to be able
61                                        to recognize this in FormatChg-message!! */
62     bool   m_bAutoUpdateFormat : 1;/**< TRUE: Set attributes of a whole paragraph
63                                        at format (UI-side!). */
64     bool m_bHidden : 1;
65     std::shared_ptr<SfxGrabBagItem> m_pGrabBagItem; ///< Style InteropGrabBag.
InvalidateInSwFntCache(sal_uInt16)66     virtual void InvalidateInSwFntCache(sal_uInt16) {};
67 
68 protected:
69     SwFormat( SwAttrPool& rPool, const char* pFormatNm,
70             const sal_uInt16* pWhichRanges, SwFormat *pDrvdFrame, sal_uInt16 nFormatWhich );
71     SwFormat( SwAttrPool& rPool, const OUString &rFormatNm, const sal_uInt16* pWhichRanges,
72             SwFormat *pDrvdFrame, sal_uInt16 nFormatWhich );
73     SwFormat( const SwFormat& rFormat );
74     virtual void SwClientNotify(const SwModify&, const SfxHint&) override;
75 
76 public:
77 
78     virtual ~SwFormat() override;
79     SwFormat &operator=(const SwFormat&);
80 
81     /// for Querying of Writer-functions.
Which() const82     sal_uInt16 Which() const { return m_nWhichId; };
83 
84     /// Copy attributes even among documents.
85     void CopyAttrs( const SwFormat& );
86 
87     /// Delete all attributes that are not in rFormat.
88     void DelDiffs( const SfxItemSet& rSet );
DelDiffs(const SwFormat & rFormat)89     void DelDiffs( const SwFormat& rFormat ) { DelDiffs( rFormat.GetAttrSet() ); }
90 
91     /// 0 is Default.
92     bool SetDerivedFrom(SwFormat *pDerivedFrom = nullptr);
93 
94     /// If bInParents is FALSE, search only in this format for attribute.
95     const SfxPoolItem& GetFormatAttr( sal_uInt16 nWhich,
96                                    bool bInParents = true ) const;
GetFormatAttr(TypedWhichId<T> nWhich,bool bInParents=true) const97     template<class T> const T& GetFormatAttr( TypedWhichId<T> nWhich, bool bInParents = true ) const
98     {
99         return static_cast<const T&>(GetFormatAttr(sal_uInt16(nWhich), bInParents));
100     }
101     SfxItemState GetItemState( sal_uInt16 nWhich, bool bSrchInParent = true,
102                                     const SfxPoolItem **ppItem = nullptr ) const;
103     SfxItemState GetBackgroundState(std::unique_ptr<SvxBrushItem>& rItem) const;
104     virtual bool SetFormatAttr( const SfxPoolItem& rAttr );
105     virtual bool SetFormatAttr( const SfxItemSet& rSet );
106     virtual bool ResetFormatAttr( sal_uInt16 nWhich1, sal_uInt16 nWhich2 = 0 );
107 
108     /** Takes all hints from Delta-Array,
109         @return count of deleted hints. */
110     virtual sal_uInt16 ResetAllFormatAttr();
111 
DerivedFrom() const112     SwFormat* DerivedFrom() const { return const_cast<SwFormat*>(static_cast<const SwFormat*>(GetRegisteredIn())); }
IsDefault() const113     bool IsDefault() const { return DerivedFrom() == nullptr; }
114 
GetName() const115     const OUString& GetName() const                  { return m_aFormatName; }
HasName(std::u16string_view rName) const116     bool HasName(std::u16string_view rName) const { return m_aFormatName == rName; }
117     virtual void SetName( const OUString& rNewName, bool bBroadcast=false );
118 
119     /// For querying the attribute array.
GetAttrSet() const120     const SwAttrSet& GetAttrSet() const { return m_aSet; }
121 
122     /** The document is set in SwAttrPool now, therefore you always can access it. */
GetDoc() const123     const SwDoc *GetDoc() const         { return m_aSet.GetDoc(); }
GetDoc()124           SwDoc *GetDoc()               { return m_aSet.GetDoc(); }
125 
126     /// Provides access to the document settings interface.
127     const IDocumentSettingAccess& getIDocumentSettingAccess() const;
128 
129     /// Provides access to the document draw model interface.
130     const IDocumentDrawModelAccess& getIDocumentDrawModelAccess() const;
131           IDocumentDrawModelAccess& getIDocumentDrawModelAccess();
132 
133     /// Provides access to the document layout interface.
134     const IDocumentLayoutAccess& getIDocumentLayoutAccess() const;
135           IDocumentLayoutAccess& getIDocumentLayoutAccess();
136 
137      /// Provides access to the document idle timer interface.
138      IDocumentTimerAccess& getIDocumentTimerAccess();
139 
140      /// Provides access to the document idle timer interface.
141     IDocumentFieldsAccess& getIDocumentFieldsAccess();
142 
143      /// Gives access to the chart data-provider.
144     IDocumentChartDataProviderAccess& getIDocumentChartDataProviderAccess();
145 
146     /// Get and set Pool style IDs.
GetPoolFormatId() const147     sal_uInt16 GetPoolFormatId() const { return m_nPoolFormatId; }
SetPoolFormatId(sal_uInt16 nId)148     void SetPoolFormatId( sal_uInt16 nId ) { m_nPoolFormatId = nId; }
149 
150     /// Get and set Help-IDs for document templates.
GetPoolHelpId() const151     sal_uInt16 GetPoolHelpId() const { return m_nPoolHelpId; }
SetPoolHelpId(sal_uInt16 nId)152     void SetPoolHelpId( sal_uInt16 nId ) { m_nPoolHelpId = nId; }
GetPoolHlpFileId() const153     sal_uInt8 GetPoolHlpFileId() const { return m_nPoolHlpFileId; }
SetPoolHlpFileId(sal_uInt8 nId)154     void SetPoolHlpFileId( sal_uInt8 nId ) { m_nPoolHlpFileId = nId; }
155 
156     /// Get attribute-description. Returns passed string.
GetPresentation(SfxItemPresentation ePres,MapUnit eCoreMetric,MapUnit ePresMetric,OUString & rText) const157     void GetPresentation( SfxItemPresentation ePres,
158         MapUnit eCoreMetric, MapUnit ePresMetric, OUString &rText ) const
159         { m_aSet.GetPresentation( ePres, eCoreMetric, ePresMetric, rText ); }
160 
161     /// Query / set AutoFormat-flag.
IsAuto() const162     bool IsAuto() const                 { return m_bAutoFormat; }
SetAuto(bool bNew)163     void SetAuto( bool bNew )           { m_bAutoFormat = bNew; }
164 
IsHidden() const165     bool IsHidden() const               { return m_bHidden; }
SetHidden(bool bValue)166     void SetHidden( bool bValue )       { m_bHidden = bValue; }
167 
168     void GetGrabBagItem(css::uno::Any& rVal) const;
169     void SetGrabBagItem(const css::uno::Any& rVal);
170 
171     /// Query / set bAutoUpdateFormat-flag.
IsAutoUpdateFormat() const172     bool IsAutoUpdateFormat() const                { return m_bAutoUpdateFormat; }
SetAutoUpdateFormat(bool bNew=true)173     void SetAutoUpdateFormat( bool bNew = true )   { m_bAutoUpdateFormat = bNew; }
174 
IsFormatInDTOR() const175     bool IsFormatInDTOR() const { return m_bFormatInDTOR; }
176 
177     /** GetMethods: Bool indicates whether to search only in Set (FALSE)
178      or also in Parents.
179      If nothing is found the defaulted attribute is returned. */
180 
181     /// Character-attributes - implemented in charatr.hxx
182     inline const SvxUnderlineItem    &GetUnderline( bool = true ) const;
183     inline const SvxFontHeightItem   &GetSize( bool = true ) const;
184     inline const SvxFontItem         &GetFont( bool = true ) const;
185     inline const SvxColorItem        &GetColor( bool = true ) const;
186     inline const SvxFontItem         &GetCJKFont( bool = true ) const;
187     inline const SvxFontItem         &GetCTLFont( bool = true ) const;
188 
189     /// Frame-attributes - implemented in frmatr.hxx.
190     inline const SwFormatFillOrder           &GetFillOrder( bool = true ) const;
191     inline const SwFormatFrameSize             &GetFrameSize( bool = true ) const;
192     inline const SwFormatHeader          &GetHeader( bool = true ) const;
193     inline const SwFormatFooter          &GetFooter( bool = true ) const;
194     inline const SwFormatSurround            &GetSurround( bool = true ) const;
195     inline const SwFormatHoriOrient      &GetHoriOrient( bool = true ) const;
196     inline const SwFormatAnchor          &GetAnchor( bool = true ) const;
197     inline const SwFormatCol                 &GetCol( bool = true ) const;
198     inline const SvxPaperBinItem      &GetPaperBin( bool = true ) const;
199     inline const SvxLRSpaceItem           &GetLRSpace( bool = true ) const;
200     inline const SvxULSpaceItem           &GetULSpace( bool = true ) const;
201     inline const SwFormatContent           &GetContent( bool = true ) const;
202     inline const SvxPrintItem             &GetPrint( bool = true ) const;
203     inline const SvxOpaqueItem            &GetOpaque( bool = true ) const;
204     inline const SvxProtectItem           &GetProtect( bool = true ) const;
205     inline const SwFormatVertOrient      &GetVertOrient( bool = true ) const;
206     inline const SvxBoxItem               &GetBox( bool = true ) const;
207     inline const SvxFormatKeepItem         &GetKeep( bool = true ) const;
208 
209     // Create SvxBrushItem for Background fill (partially for backwards compatibility)
210     std::unique_ptr<SvxBrushItem> makeBackgroundBrushItem( bool = true ) const;
211 
212     inline const SvxShadowItem            &GetShadow( bool = true ) const;
213     inline const SwFormatPageDesc            &GetPageDesc( bool = true ) const;
214     inline const SvxFormatBreakItem      &GetBreak( bool = true ) const;
215     inline const SvxMacroItem             &GetMacro( bool = true ) const;
216     inline const SwFormatURL             &GetURL( bool = true ) const;
217     inline const SwFormatEditInReadonly  &GetEditInReadonly( bool = true ) const;
218     inline const SwFormatLayoutSplit     &GetLayoutSplit( bool = true ) const;
219     inline const SwFormatRowSplit          &GetRowSplit( bool = true ) const;
220     inline const SwFormatChain               &GetChain( bool = true ) const;
221     inline const SwFormatFootnoteAtTextEnd     &GetFootnoteAtTextEnd( bool = true ) const;
222     inline const SwFormatEndAtTextEnd     &GetEndAtTextEnd( bool = true ) const;
223     inline const SwFormatNoBalancedColumns &GetBalancedColumns( bool = true ) const;
224     inline const SvxFrameDirectionItem    &GetFrameDir( bool = true ) const;
225     inline const SwTextGridItem         &GetTextGrid( bool = true ) const;
226     inline const SwHeaderAndFooterEatSpacingItem &GetHeaderAndFooterEatSpacing( bool = true ) const;
227     // #i18732#
228     inline const SwFormatFollowTextFlow    &GetFollowTextFlow(bool = true) const;
229     // #i28701#
230     inline const SwFormatWrapInfluenceOnObjPos& GetWrapInfluenceOnObjPos(bool = true) const;
231     inline const SdrTextVertAdjustItem& GetTextVertAdjust(bool = true) const;
232 
233     /// Paragraph-attributes - implemented in paratr.hxx.
234     inline const SvxLineSpacingItem       &GetLineSpacing( bool = true ) const;
235     inline const SwNumRuleItem            &GetNumRule( bool = true ) const;
236     inline const SvxTabStopItem           &GetTabStops( bool = true ) const;
237     inline const SwFormatDrop                &GetDrop( bool = true ) const;
238 
239     /// TableBox attributes - implemented in cellatr.hxx.
240     inline  const SwTableBoxNumFormat     &GetTableBoxNumFormat( bool = true ) const;
241     inline  const SwTableBoxFormula       &GetTableBoxFormula( bool = true ) const;
242     inline  const SwTableBoxValue         &GetTableBoxValue( bool = true ) const;
243 
244     void SetPageFormatToDefault();
245 
246     /** SwFormat::IsBackgroundTransparent
247 
248         Virtual method to determine, if background of format is transparent.
249         Default implementation returns false. Thus, subclasses have to override
250         method, if the specific subclass can have a transparent background.
251 
252         @return false, default implementation
253     */
254     virtual bool IsBackgroundTransparent() const;
255 
256     // Access to DrawingLayer FillAttributes in a preprocessed form for primitive usage
257     virtual drawinglayer::attribute::SdrAllFillAttributesHelperPtr getSdrAllFillAttributesHelper() const;
258     virtual bool supportsFullDrawingLayerFillAttributeSet() const;
259     void RemoveAllUnos();
260 };
261 
262 #endif // INCLUDED_SW_INC_FORMAT_HXX
263 
264 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
265