1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
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_FORMAT_HXX
20 #define INCLUDED_SW_INC_FORMAT_HXX
24 #include "BorderCacheOwner.hxx"
26 #include "hintids.hxx"
27 #include "swatrset.hxx"
30 class IDocumentSettingAccess
;
31 class IDocumentDrawModelAccess
;
32 class IDocumentLayoutAccess
;
33 class IDocumentTimerAccess
;
34 class IDocumentFieldsAccess
;
35 class IDocumentChartDataProviderAccess
;
40 namespace drawinglayer::attribute
{
41 class SdrAllFillAttributesHelper
;
42 typedef std::shared_ptr
< SdrAllFillAttributesHelper
> SdrAllFillAttributesHelperPtr
;
45 /// Base class for various Writer styles.
46 class SW_DLLPUBLIC SwFormat
: public sw::BorderCacheOwner
, public sw::BroadcastingModify
48 friend class SwFrameFormat
;
50 OUString m_aFormatName
;
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.
60 bool m_bFormatInDTOR
: 1; /**< TRUE: Format becomes deleted. In order to be able
61 to recognize this in FormatChg-message!! */
62 bool m_bAutoUpdateOnDirectFormat
: 1;/**< TRUE: Set attributes of a whole paragraph
63 at format (UI-side!). */
65 std::shared_ptr
<SfxGrabBagItem
> m_pGrabBagItem
; ///< Style InteropGrabBag.
66 virtual void InvalidateInSwFntCache(sal_uInt16
) {};
69 SwFormat( SwAttrPool
& rPool
, const char* pFormatNm
,
70 const WhichRangesContainer
& pWhichRanges
, SwFormat
*pDrvdFrame
, sal_uInt16 nFormatWhich
);
71 SwFormat( SwAttrPool
& rPool
, OUString aFormatNm
, const WhichRangesContainer
& pWhichRanges
,
72 SwFormat
*pDrvdFrame
, sal_uInt16 nFormatWhich
);
73 SwFormat( const SwFormat
& rFormat
);
74 virtual void SwClientNotify(const SwModify
&, const SfxHint
&) override
;
78 virtual ~SwFormat() override
;
79 SwFormat
&operator=(const SwFormat
&);
81 /// for Querying of Writer-functions.
82 sal_uInt16
Which() const { return m_nWhichId
; };
84 /// Copy attributes even among documents.
85 void CopyAttrs( const SwFormat
& );
87 /// Delete all attributes that are not in rFormat.
88 void DelDiffs( const SfxItemSet
& rSet
);
89 void DelDiffs( const SwFormat
& rFormat
) { DelDiffs( rFormat
.GetAttrSet() ); }
92 bool SetDerivedFrom(SwFormat
*pDerivedFrom
= nullptr);
94 /// If bInParents is FALSE, search only in this format for attribute.
95 const SfxPoolItem
& GetFormatAttr( sal_uInt16 nWhich
,
96 bool bInParents
= true ) const;
97 template<class T
> const T
& GetFormatAttr( TypedWhichId
<T
> nWhich
, bool bInParents
= true ) const
99 return static_cast<const T
&>(GetFormatAttr(sal_uInt16(nWhich
), bInParents
));
102 SfxItemState
GetItemState( sal_uInt16 nWhich
, bool bSrchInParent
= true,
103 const SfxPoolItem
**ppItem
= nullptr ) const;
105 SfxItemState
GetItemState( TypedWhichId
<T
> nWhich
, bool bSrchInParent
= true,
106 const T
**ppItem
= nullptr ) const
107 { return GetItemState(sal_uInt16(nWhich
), bSrchInParent
, reinterpret_cast<const SfxPoolItem
**>(ppItem
)); }
109 /// Templatized version of GetItemState() to directly return the correct type.
111 const T
* GetItemIfSet( TypedWhichId
<T
> nWhich
,
112 bool bSrchInParent
= true ) const
114 const SfxPoolItem
* pItem
= nullptr;
115 if( SfxItemState::SET
== GetItemState(sal_uInt16(nWhich
), bSrchInParent
, &pItem
) )
116 return static_cast<const T
*>(pItem
);
119 SfxItemState
GetBackgroundState(std::unique_ptr
<SvxBrushItem
>& rItem
) const;
120 virtual bool SetFormatAttr( const SfxPoolItem
& rAttr
);
121 virtual bool SetFormatAttr( const SfxItemSet
& rSet
);
122 virtual bool ResetFormatAttr( sal_uInt16 nWhich1
, sal_uInt16 nWhich2
= 0 );
124 /** Takes all hints from Delta-Array,
125 @return count of deleted hints. */
126 virtual sal_uInt16
ResetAllFormatAttr();
128 SwFormat
* DerivedFrom() const { return const_cast<SwFormat
*>(static_cast<const SwFormat
*>(GetRegisteredIn())); }
129 bool IsDefault() const { return DerivedFrom() == nullptr; }
131 const OUString
& GetName() const { return m_aFormatName
; }
132 bool HasName(std::u16string_view rName
) const { return m_aFormatName
== rName
; }
133 virtual void SetFormatName( const OUString
& rNewName
, bool bBroadcast
=false );
135 /// For querying the attribute array.
136 const SwAttrSet
& GetAttrSet() const { return m_aSet
; }
138 /** The document is set in SwAttrPool now, therefore you always can access it. */
139 const SwDoc
*GetDoc() const { return m_aSet
.GetDoc(); }
140 SwDoc
*GetDoc() { return m_aSet
.GetDoc(); }
142 /// Provides access to the document settings interface.
143 const IDocumentSettingAccess
& getIDocumentSettingAccess() const;
145 /// Provides access to the document draw model interface.
146 const IDocumentDrawModelAccess
& getIDocumentDrawModelAccess() const;
147 IDocumentDrawModelAccess
& getIDocumentDrawModelAccess();
149 /// Provides access to the document layout interface.
150 const IDocumentLayoutAccess
& getIDocumentLayoutAccess() const;
151 IDocumentLayoutAccess
& getIDocumentLayoutAccess();
153 /// Provides access to the document idle timer interface.
154 IDocumentTimerAccess
& getIDocumentTimerAccess();
156 /// Provides access to the document idle timer interface.
157 IDocumentFieldsAccess
& getIDocumentFieldsAccess();
159 /// Gives access to the chart data-provider.
160 IDocumentChartDataProviderAccess
& getIDocumentChartDataProviderAccess();
162 /// Get and set Pool style IDs.
163 sal_uInt16
GetPoolFormatId() const { return m_nPoolFormatId
; }
164 void SetPoolFormatId( sal_uInt16 nId
) { m_nPoolFormatId
= nId
; }
166 /// Get and set Help-IDs for document templates.
167 sal_uInt16
GetPoolHelpId() const { return m_nPoolHelpId
; }
168 void SetPoolHelpId( sal_uInt16 nId
) { m_nPoolHelpId
= nId
; }
169 sal_uInt8
GetPoolHlpFileId() const { return m_nPoolHlpFileId
; }
170 void SetPoolHlpFileId( sal_uInt8 nId
) { m_nPoolHlpFileId
= nId
; }
172 /// Get attribute-description. Returns passed string.
173 void GetPresentation( SfxItemPresentation ePres
,
174 MapUnit eCoreMetric
, MapUnit ePresMetric
, OUString
&rText
) const
175 { m_aSet
.GetPresentation( ePres
, eCoreMetric
, ePresMetric
, rText
); }
177 /// Query / set AutoFormat-flag.
178 bool IsAuto() const { return m_bAutoFormat
; }
179 void SetAuto( bool bNew
) { m_bAutoFormat
= bNew
; }
181 bool IsHidden() const { return m_bHidden
; }
182 void SetHidden( bool bValue
) { m_bHidden
= bValue
; }
184 void GetGrabBagItem(css::uno::Any
& rVal
) const;
185 void SetGrabBagItem(const css::uno::Any
& rVal
);
187 /// Query / set m_bAutoUpdateOnDirectFormat-flag.
188 bool IsAutoUpdateOnDirectFormat() const { return m_bAutoUpdateOnDirectFormat
; }
189 void SetAutoUpdateOnDirectFormat( bool bNew
= true ) { m_bAutoUpdateOnDirectFormat
= bNew
; }
191 bool IsFormatInDTOR() const { return m_bFormatInDTOR
; }
193 /** GetMethods: Bool indicates whether to search only in Set (FALSE)
195 If nothing is found the defaulted attribute is returned. */
197 /// Character-attributes - implemented in charatr.hxx
198 inline const SvxUnderlineItem
&GetUnderline( bool = true ) const;
199 inline const SvxFontHeightItem
&GetSize( bool = true ) const;
200 inline const SvxFontItem
&GetFont( bool = true ) const;
201 inline const SvxColorItem
&GetColor( bool = true ) const;
202 inline const SvxFontItem
&GetCJKFont( bool = true ) const;
203 inline const SvxFontItem
&GetCTLFont( bool = true ) const;
205 /// Frame-attributes - implemented in frmatr.hxx.
206 inline const SwFormatFillOrder
&GetFillOrder( bool = true ) const;
207 inline const SwFormatFrameSize
&GetFrameSize( bool = true ) const;
208 inline const SwFormatHeader
&GetHeader( bool = true ) const;
209 inline const SwFormatFooter
&GetFooter( bool = true ) const;
210 inline const SwFormatSurround
&GetSurround( bool = true ) const;
211 inline const SwFormatHoriOrient
&GetHoriOrient( bool = true ) const;
212 inline const SwFormatAnchor
&GetAnchor( bool = true ) const;
213 inline const SwFormatCol
&GetCol( bool = true ) const;
214 inline const SvxPaperBinItem
&GetPaperBin( bool = true ) const;
215 inline const SvxLeftMarginItem
& GetLeftMargin(bool = true) const;
216 inline const SvxTextLeftMarginItem
&GetTextLeftMargin(bool = true) const;
217 inline const SvxFirstLineIndentItem
&GetFirstLineIndent(bool = true) const;
218 inline const SvxRightMarginItem
& GetRightMargin(bool = true) const;
219 inline const SvxGutterLeftMarginItem
&GetGutterLeftMargin(bool = true) const;
220 inline const SvxGutterRightMarginItem
&GetGutterRightMargin(bool = true) const;
221 inline const SvxLRSpaceItem
&GetLRSpace( bool = true ) const;
222 inline const SvxULSpaceItem
&GetULSpace( bool = true ) const;
223 inline const SwFormatContent
&GetContent( bool = true ) const;
224 inline const SvxPrintItem
&GetPrint( bool = true ) const;
225 inline const SvxOpaqueItem
&GetOpaque( bool = true ) const;
226 inline const SvxProtectItem
&GetProtect( bool = true ) const;
227 inline const SwFormatVertOrient
&GetVertOrient( bool = true ) const;
228 inline const SvxBoxItem
&GetBox( bool = true ) const;
229 inline const SvxFormatKeepItem
&GetKeep( bool = true ) const;
231 // Create SvxBrushItem for Background fill (partially for backwards compatibility)
232 std::unique_ptr
<SvxBrushItem
> makeBackgroundBrushItem( bool = true ) const;
234 inline const SvxShadowItem
&GetShadow( bool = true ) const;
235 inline const SwFormatPageDesc
&GetPageDesc( bool = true ) const;
236 inline const SvxFormatBreakItem
&GetBreak( bool = true ) const;
237 inline const SvxMacroItem
&GetMacro( bool = true ) const;
238 inline const SwFormatURL
&GetURL( bool = true ) const;
239 inline const SwFormatEditInReadonly
&GetEditInReadonly( bool = true ) const;
240 inline const SwFormatLayoutSplit
&GetLayoutSplit( bool = true ) const;
241 inline const SwFormatRowSplit
&GetRowSplit( bool = true ) const;
242 inline const SwFormatFlySplit
&GetFlySplit( bool = true ) const;
243 inline const SwFormatChain
&GetChain( bool = true ) const;
244 inline const SwFormatFootnoteAtTextEnd
&GetFootnoteAtTextEnd( bool = true ) const;
245 inline const SwFormatEndAtTextEnd
&GetEndAtTextEnd( bool = true ) const;
246 inline const SwFormatNoBalancedColumns
&GetBalancedColumns( bool = true ) const;
247 inline const SvxFrameDirectionItem
&GetFrameDir( bool = true ) const;
248 inline const SwTextGridItem
&GetTextGrid( bool = true ) const;
249 inline const SwHeaderAndFooterEatSpacingItem
&GetHeaderAndFooterEatSpacing( bool = true ) const;
251 inline const SwFormatFollowTextFlow
&GetFollowTextFlow(bool = true) const;
253 inline const SwFormatWrapInfluenceOnObjPos
& GetWrapInfluenceOnObjPos(bool = true) const;
254 inline const SdrTextVertAdjustItem
& GetTextVertAdjust(bool = true) const;
256 /// Paragraph-attributes - implemented in paratr.hxx.
257 inline const SvxLineSpacingItem
&GetLineSpacing( bool = true ) const;
258 inline const SwNumRuleItem
&GetNumRule( bool = true ) const;
259 inline const SvxTabStopItem
&GetTabStops( bool = true ) const;
260 inline const SwFormatDrop
&GetDrop( bool = true ) const;
262 /// TableBox attributes - implemented in cellatr.hxx.
263 inline const SwTableBoxNumFormat
&GetTableBoxNumFormat( bool = true ) const;
264 inline const SwTableBoxFormula
&GetTableBoxFormula( bool = true ) const;
265 inline const SwTableBoxValue
&GetTableBoxValue( bool = true ) const;
267 void SetPageFormatToDefault();
269 /** SwFormat::IsBackgroundTransparent
271 Virtual method to determine, if background of format is transparent.
272 Default implementation returns false. Thus, subclasses have to override
273 method, if the specific subclass can have a transparent background.
275 @return false, default implementation
277 virtual bool IsBackgroundTransparent() const;
279 // Access to DrawingLayer FillAttributes in a preprocessed form for primitive usage
280 virtual drawinglayer::attribute::SdrAllFillAttributesHelperPtr
getSdrAllFillAttributesHelper() const;
281 virtual bool supportsFullDrawingLayerFillAttributeSet() const;
282 void RemoveAllUnos();
285 #endif // INCLUDED_SW_INC_FORMAT_HXX
287 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */