LibreOffice Module sc (master) 1
stlsheet.cxx
Go to the documentation of this file.
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
20#include <document.hxx>
21#include <stlsheet.hxx>
22#include <stlpool.hxx>
23
24#include <scitems.hxx>
25#include <editeng/boxitem.hxx>
27#include <editeng/lrspitem.hxx>
28#include <svx/pageitem.hxx>
29#include <svx/svddef.hxx>
30#include <svx/svdpool.hxx>
31#include <svx/xdef.hxx>
32#include <editeng/eeitem.hxx>
33#include <editeng/paperinf.hxx>
34#include <editeng/shaditem.hxx>
35#include <editeng/sizeitem.hxx>
36#include <editeng/ulspitem.hxx>
37#include <editeng/xmlcnitm.hxx>
38#include <svl/itempool.hxx>
39#include <svl/itemset.hxx>
40#include <svl/numformat.hxx>
41#include <svl/hint.hxx>
43#include <attrib.hxx>
44
45#include <globstr.hrc>
46#include <scresid.hxx>
47#include <sc.hrc>
48
51
52ScStyleSheet::ScStyleSheet( const OUString& rName,
53 const ScStyleSheetPool& rPoolP,
54 SfxStyleFamily eFamily,
55 SfxStyleSearchBits nMaskP )
56
57 : SfxStyleSheet ( rName, rPoolP, eFamily, nMaskP )
58 , eUsage( Usage::UNKNOWN )
59{
60}
61
63 : SfxStyleSheet ( rStyle )
64 , eUsage( Usage::UNKNOWN )
65{
66}
67
69{
70}
71
73{
74 return false;
75}
76
78{
79 bool bHasParentSupport = false;
80
81 switch ( GetFamily() )
82 {
83 case SfxStyleFamily::Para: bHasParentSupport = true; break;
84 case SfxStyleFamily::Frame: bHasParentSupport = true; break;
85 case SfxStyleFamily::Page: bHasParentSupport = false; break;
86 default:
87 {
88 // added to avoid warnings
89 }
90 }
91
92 return bHasParentSupport;
93}
94
95bool ScStyleSheet::SetParent( const OUString& rParentName )
96{
97 bool bResult = false;
98 OUString aEffName = rParentName;
99 SfxStyleSheetBase* pStyle = m_pPool->Find( aEffName, nFamily );
100 if (!pStyle)
101 {
102 std::unique_ptr<SfxStyleSheetIterator> pIter = m_pPool->CreateIterator(nFamily);
103 pStyle = pIter->First();
104 if (pStyle)
105 aEffName = pStyle->GetName();
106 }
107
108 if ( pStyle && aEffName != GetName() )
109 {
110 bResult = SfxStyleSheet::SetParent( aEffName );
111 if (bResult)
112 {
113 SfxItemSet& rParentSet = pStyle->GetItemSet();
114 GetItemSet().SetParent( &rParentSet );
115
116 // #i113491# Drag&Drop in the stylist's hierarchical view doesn't execute a slot,
117 // so the repaint has to come from here (after modifying the ItemSet).
118 // RepaintRange checks the document's IsVisible flag and locked repaints.
119 ScDocument* pDoc = static_cast<ScStyleSheetPool*>(GetPool())->GetDocument();
120 if (pDoc)
121 pDoc->RepaintRange( ScRange( 0,0,0, pDoc->MaxCol(),pDoc->MaxRow(),MAXTAB ) );
122 }
123 }
124
125 return bResult;
126}
127
129{
130 GetItemSet().SetParent(nullptr);
131}
132
134{
135 if ( !pSet )
136 {
137 switch ( GetFamily() )
138 {
139 case SfxStyleFamily::Page:
140 {
141 // Page templates should not be derivable,
142 // therefore suitable values are set at this point.
143 // (== Standard page template)
144
145 SfxItemPool& rItemPool = GetPool()->GetPool();
146 pSet = new SfxItemSetFixed<
151 ATTR_LRSPACE, ATTR_PAGE_SCALETO>(rItemPool);
152
153 // If being loaded also the set is then filled in from the file,
154 // so the defaults do not need to be set.
155 // GetPrinter would then also create a new printer,
156 // because the stored Printer is not loaded yet!
157
158 ScDocument* pDoc = static_cast<ScStyleSheetPool*>(GetPool())->GetDocument();
159 if ( pDoc )
160 {
161 // Setting reasonable default values:
162 SvxPageItem aPageItem( ATTR_PAGE );
164
165 SvxSetItem aHFSetItem(
167
168 SfxItemSet& rHFSet = aHFSetItem.GetItemSet();
169 SvxSizeItem aHFSizeItem( // 0,5 cm + distance
172
173 SvxULSpaceItem aHFDistItem ( HFDIST_CM,// nUp
174 HFDIST_CM,// nLow
175 ATTR_ULSPACE );
176
177 SvxLRSpaceItem aLRSpaceItem( TWO_CM, // nLeft
178 TWO_CM, // nRight
179 0, // nFirstLineOffset
180 ATTR_LRSPACE );
181 SvxULSpaceItem aULSpaceItem( TWO_CM, // nUp
182 TWO_CM, // nLow
183 ATTR_ULSPACE );
184 SvxBoxInfoItem aBoxInfoItem( ATTR_BORDER_INNER );
185
186 aBoxInfoItem.SetTable( false );
187 aBoxInfoItem.SetDist( true );
188 aBoxInfoItem.SetValid( SvxBoxInfoItemValidFlags::DISTANCE );
189
190 aPageItem.SetLandscape( false );
191
192 rHFSet.Put( aBoxInfoItem );
193 rHFSet.Put( aHFSizeItem );
194 rHFSet.Put( aHFDistItem );
195 rHFSet.Put( SvxLRSpaceItem(0, 0, 0, ATTR_LRSPACE) ); // Set border to Null
196
197 aHFSetItem.SetWhich(ATTR_PAGE_HEADERSET);
198 pSet->Put( aHFSetItem );
199 aHFSetItem.SetWhich(ATTR_PAGE_FOOTERSET);
200 pSet->Put( aHFSetItem );
201 pSet->Put( aBoxInfoItem ); // Do not overwrite PoolDefault
202 // due to format templates
203
204
205 // Writing direction: not as pool default because the default for cells
206 // must remain SvxFrameDirection::Environment, and each page style's setting is
207 // supposed to be saved in the file format.
208 // The page default depends on the system language.
210 SvxFrameDirection::Horizontal_RL_TB : SvxFrameDirection::Horizontal_LR_TB;
212
213 rItemPool.SetPoolDefaultItem( aPageItem );
214 rItemPool.SetPoolDefaultItem( aPaperSizeItem );
215 rItemPool.SetPoolDefaultItem( aLRSpaceItem );
216 rItemPool.SetPoolDefaultItem( aULSpaceItem );
218 ScPageScaleToItem aScaleToItem;
219 rItemPool.SetPoolDefaultItem( aScaleToItem );
221 }
222 }
223 break;
224
225 case SfxStyleFamily::Frame:
226 {
227 SfxItemPool* pItemPool = &GetPool()->GetPool();
228 if (dynamic_cast<SdrItemPool*>(pItemPool) == nullptr)
229 pItemPool = pItemPool->GetSecondaryPool();
230 assert(pItemPool);
231
232 pSet = new SfxItemSetFixed<
239 EE_PARA_START, EE_CHAR_END>(*pItemPool);
240 }
241 break;
242
243 case SfxStyleFamily::Para:
244 default:
246 break;
247 }
248 bMySet = true;
249 }
250 if ( nHelpId == HID_SC_SHEET_CELL_ERG1 )
251 {
252 if ( !pSet->Count() )
253 {
254 // Hack to work around that when this code is called from
255 // ~ScStyleSheetPool -> ~SfxStyleSheetPool, GetPool() is no longer
256 // an ScStyleSheetPool:
257 ScStyleSheetPool * pool = dynamic_cast<ScStyleSheetPool *>(
258 GetPool());
259 if (pool != nullptr) {
260 ScDocument* pDoc = pool->GetDocument();
261 if ( pDoc )
262 {
263 sal_uInt32 nNumFmt = pDoc->GetFormatTable()->GetStandardFormat( SvNumFormatType::CURRENCY,ScGlobal::eLnge );
264 pSet->Put( SfxUInt32Item( ATTR_VALUE_FORMAT, nNumFmt ) );
265 }
266 }
267 }
268 }
269
270 return *pSet;
271}
272
274{
275 switch (GetFamily())
276 {
277 case SfxStyleFamily::Para:
278 {
279 // Always query the document to let it decide if a rescan is necessary,
280 // and store the state.
281 ScDocument* pDoc = static_cast<ScStyleSheetPool*>(m_pPool)->GetDocument();
282 if ( pDoc && pDoc->IsStyleSheetUsed( *this ) )
284 else
286 return eUsage == Usage::USED;
287 }
288 case SfxStyleFamily::Page:
289 {
290 // tdf#108188 - verify that the page style is actually used
291 ScDocument* pDoc = static_cast<ScStyleSheetPool*>(m_pPool)->GetDocument();
292 if (pDoc && pDoc->IsPageStyleInUse(GetName(), nullptr))
294 else
296 return eUsage == Usage::USED;
297 }
298 case SfxStyleFamily::Frame:
299 {
300 ForAllListeners([this] (SfxListener* pListener)
301 {
302 auto pUser(dynamic_cast<svl::StyleSheetUser*>(pListener));
303 if (pUser && pUser->isUsedByModel())
304 {
306 return true; // break loop
307 }
308 else
310 return false;
311 });
312 return eUsage == Usage::USED;
313 }
314 default:
315 return true;
316 }
317}
318
320{
321 if ( rHint.GetId() == SfxHintId::Dying )
322 GetItemSet().SetParent( nullptr );
323 if (GetFamily() == SfxStyleFamily::Frame)
324 SfxStyleSheet::Notify(rBC, rHint);
325}
326
327// Avoid creating a Style "Standard" if this is not the Standard-Name;
328// otherwise two styles would have the same name when storing.
329// (on loading the style is created directly per Make with the name; making this query
330// not applicable)
331//TODO: If at any time during loading SetName is called, a flag has to be set/checked for loading
332//TODO: The whole check has to be removed if for a new file version the name transformation is dropped.
333
334bool ScStyleSheet::SetName(const OUString& rNew, bool bReindexNow)
335{
336 OUString aFileStdName = STRING_STANDARD;
337 if ( rNew == aFileStdName && aFileStdName != ScResId(STR_STYLENAME_STANDARD) )
338 return false;
339 else
340 return SfxStyleSheet::SetName(rNew, bReindexNow);
341}
342
343/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
const SCTAB MAXTAB
Definition: address.hxx:70
SC_DLLPUBLIC SCCOL MaxCol() const
Definition: document.hxx:892
SC_DLLPUBLIC SCROW MaxRow() const
Definition: document.hxx:893
bool IsPageStyleInUse(std::u16string_view rStrPageStyle, SCTAB *pInTab)
Definition: documen8.cxx:310
void RepaintRange(const ScRange &rRange)
Definition: documen8.cxx:689
bool IsStyleSheetUsed(const ScStyleSheet &rStyle) const
Definition: document.cxx:4938
SC_DLLPUBLIC SvNumberFormatter * GetFormatTable() const
Definition: documen2.cxx:467
static bool IsSystemRTL()
Definition: global.cxx:895
static SC_DLLPUBLIC LanguageType eLnge
Definition: global.hxx:560
Contains the "scale to width/height" attribute in page styles.
Definition: attrib.hxx:230
ScDocument * GetDocument() const
Definition: stlpool.hxx:35
virtual ~ScStyleSheet() override
Definition: stlsheet.cxx:68
virtual bool SetName(const OUString &rNewName, bool bReindexNow=true) override
Definition: stlsheet.cxx:334
virtual SC_DLLPUBLIC SfxItemSet & GetItemSet() override
Definition: stlsheet.cxx:133
virtual void Notify(SfxBroadcaster &rBC, const SfxHint &rHint) override
Definition: stlsheet.cxx:319
virtual bool SetParent(const OUString &rParentName) override
Definition: stlsheet.cxx:95
ScStyleSheet(const ScStyleSheet &rStyle)
Definition: stlsheet.cxx:62
virtual bool HasFollowSupport() const override
Definition: stlsheet.cxx:72
virtual bool HasParentSupport() const override
Definition: stlsheet.cxx:77
SC_DLLPUBLIC void ResetParent()
Definition: stlsheet.cxx:128
virtual bool IsUsed() const override
Definition: stlsheet.cxx:273
ScStyleSheet::Usage eUsage
Definition: stlsheet.hxx:67
void ForAllListeners(std::function< bool(SfxListener *)> f) const
SfxHintId GetId() const
SfxItemPool * GetSecondaryPool() const
const SfxPoolItem & GetDefaultItem(sal_uInt16 nWhich) const
void SetPoolDefaultItem(const SfxPoolItem &)
void SetParent(const SfxItemSet *pNew)
sal_uInt16 Count() const
const SfxPoolItem * Put(const SfxPoolItem &rItem, sal_uInt16 nWhich)
virtual std::unique_ptr< SfxStyleSheetIterator > CreateIterator(SfxStyleFamily, SfxStyleSearchBits nMask=SfxStyleSearchBits::All)
SfxItemPool & GetPool()
virtual SfxStyleSheetBase * Find(const OUString &, SfxStyleFamily eFam, SfxStyleSearchBits n=SfxStyleSearchBits::All)
virtual bool SetName(const OUString &rNewName, bool bReindexNow=true)
const OUString & GetName() const
SfxStyleFamily GetFamily() const
virtual SfxItemSet & GetItemSet()
SfxItemSet * pSet
SfxStyleSheetBasePool * GetPool()
SfxStyleSheetBasePool * m_pPool
SfxStyleFamily nFamily
virtual void Notify(SfxBroadcaster &rBC, const SfxHint &rHint) override
virtual bool SetParent(const OUString &) override
sal_uInt32 GetStandardFormat(SvNumFormatType eType, LanguageType eLnge=LANGUAGE_DONTKNOW)
void SetTable(bool bNew)
void SetDist(bool bNew)
void SetValid(SvxBoxInfoItemValidFlags nValid, bool bValid=true)
void SetLandscape(bool bL)
static Size GetDefaultPaperSize(MapUnit eUnit=MapUnit::MapTwip)
constexpr sal_uInt16 EE_PARA_START(EE_ITEMS_START+0)
constexpr sal_uInt16 EE_CHAR_END(EE_CHAR_START+32)
UNKNOWN
SvxFrameDirection
constexpr OUStringLiteral STRING_STANDARD
Definition: global.hxx:60
constexpr Point convert(const Point &rPoint, o3tl::Length eFrom, o3tl::Length eTo)
OUString ScResId(TranslateId aId)
Definition: scdll.cxx:90
constexpr TypedWhichId< SfxUInt16Item > ATTR_PAGE_SCALE(175)
constexpr TypedWhichId< SvxSizeItem > ATTR_PAGE_SIZE(161)
constexpr TypedWhichId< SvxSetItem > ATTR_PAGE_HEADERSET(184)
constexpr TypedWhichId< SvxULSpaceItem > ATTR_ULSPACE(158)
constexpr TypedWhichId< SvxBrushItem > ATTR_BACKGROUND(148)
constexpr TypedWhichId< SvxShadowItem > ATTR_SHADOW(152)
constexpr TypedWhichId< SvxBoxInfoItem > ATTR_BORDER_INNER(151)
constexpr TypedWhichId< SvxPageItem > ATTR_PAGE(159)
constexpr TypedWhichId< SvxBoxItem > ATTR_BORDER(150)
constexpr TypedWhichId< ScPageScaleToItem > ATTR_PAGE_SCALETO(188)
constexpr TypedWhichId< SfxUInt32Item > ATTR_VALUE_FORMAT(146)
constexpr TypedWhichId< SvxFrameDirectionItem > ATTR_WRITINGDIR(138)
constexpr TypedWhichId< SfxUInt16Item > ATTR_PAGE_SCALETOPAGES(176)
constexpr TypedWhichId< SvxSetItem > ATTR_PAGE_FOOTERSET(185)
constexpr TypedWhichId< SvXMLAttrContainerItem > ATTR_USERDEF(122)
constexpr TypedWhichId< SvxLRSpaceItem > ATTR_LRSPACE(157)
constexpr auto TWO_CM
Definition: stlsheet.cxx:49
constexpr auto HFDIST_CM
Definition: stlsheet.cxx:50
SfxStyleFamily
SfxStyleSearchBits
constexpr sal_uInt16 SDRATTR_MEASURE_LAST(SDRATTR_MEASUREDECIMALPLACES)
constexpr sal_uInt16 SDRATTR_3D_FIRST(SDRATTR_GRAF_LAST+1)
constexpr sal_uInt16 SDRATTR_3D_LAST(SDRATTR_3DSCENE_LAST)
constexpr sal_uInt16 SDRATTR_SHADOW_FIRST(XATTR_END+1)
constexpr TypedWhichId< SdrOnOffItem > SDRATTR_TEXT_WORDWRAP(SDRATTR_MISC_FIRST+24)
constexpr TypedWhichId< SdrMetricItem > SDRATTR_TEXT_MINFRAMEHEIGHT(SDRATTR_MISC_FIRST+1)
constexpr sal_uInt16 SDRATTR_SHADOW_LAST(SDRATTR_SHADOWALIGNMENT)
constexpr sal_uInt16 SDRATTR_EDGE_FIRST(SDRATTR_MISC_LAST+1)
constexpr sal_uInt16 XATTR_LINE_FIRST(XATTR_START)
constexpr sal_uInt16 XATTR_FILL_FIRST(XATTRSET_LINE+1)
constexpr sal_uInt16 XATTR_LINE_LAST(XATTR_LINECAP)
constexpr sal_uInt16 XATTR_FILL_LAST(XATTR_FILLUSESLIDEBACKGROUND)