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 .
20 #include "document.hxx"
21 #include "stlsheet.hxx"
22 #include "stlpool.hxx"
24 #include "scitems.hxx"
25 #include <editeng/boxitem.hxx>
26 #include <editeng/frmdiritem.hxx>
27 #include <editeng/lrspitem.hxx>
28 #include <svx/pageitem.hxx>
29 #include <editeng/paperinf.hxx>
30 #include <editeng/pbinitem.hxx>
31 #include <editeng/sizeitem.hxx>
32 #include <editeng/ulspitem.hxx>
33 #include <sfx2/printer.hxx>
34 #include <svl/itempool.hxx>
35 #include <svl/itemset.hxx>
36 #include <svl/smplhint.hxx>
39 #include <vcl/svapp.hxx>
41 #include "globstr.hrc"
44 TYPEINIT1(ScStyleSheet
, SfxStyleSheet
);
49 ScStyleSheet::ScStyleSheet( const OUString
& rName
,
50 ScStyleSheetPool
& rPoolP
,
51 SfxStyleFamily eFamily
,
54 : SfxStyleSheet ( rName
, rPoolP
, eFamily
, nMaskP
)
59 ScStyleSheet::ScStyleSheet( const ScStyleSheet
& rStyle
)
60 : SfxStyleSheet ( rStyle
)
65 ScStyleSheet::~ScStyleSheet()
69 bool ScStyleSheet::HasFollowSupport() const
74 bool ScStyleSheet::HasParentSupport () const
76 bool bHasParentSupport
= false;
78 switch ( GetFamily() )
80 case SFX_STYLE_FAMILY_PARA
: bHasParentSupport
= true; break;
81 case SFX_STYLE_FAMILY_PAGE
: bHasParentSupport
= false; break;
84 // added to avoid warnings
88 return bHasParentSupport
;
91 bool ScStyleSheet::SetParent( const OUString
& rParentName
)
94 OUString aEffName
= rParentName
;
95 SfxStyleSheetBase
* pStyle
= pPool
->Find( aEffName
, nFamily
);
98 SfxStyleSheetIteratorPtr pIter
= pPool
->CreateIterator( nFamily
, SFXSTYLEBIT_ALL
);
99 pStyle
= pIter
->First();
101 aEffName
= pStyle
->GetName();
104 if ( pStyle
&& aEffName
!= GetName() )
106 bResult
= SfxStyleSheet::SetParent( aEffName
);
109 SfxItemSet
& rParentSet
= pStyle
->GetItemSet();
110 GetItemSet().SetParent( &rParentSet
);
112 // #i113491# Drag&Drop in the stylist's hierarchical view doesn't execute a slot,
113 // so the repaint has to come from here (after modifying the ItemSet).
114 // RepaintRange checks the document's IsVisible flag and locked repaints.
115 ScDocument
* pDoc
= static_cast<ScStyleSheetPool
&>(GetPool()).GetDocument();
117 pDoc
->RepaintRange( ScRange( 0,0,0, MAXCOL
,MAXROW
,MAXTAB
) );
124 void ScStyleSheet::ResetParent()
126 GetItemSet().SetParent(NULL
);
129 SfxItemSet
& ScStyleSheet::GetItemSet()
133 switch ( GetFamily() )
135 case SFX_STYLE_FAMILY_PAGE
:
137 // Page templates should not be derivable,
138 // therefore suitable values are set at this point.
139 // (== Standard page template)
141 SfxItemPool
& rItemPool
= GetPool().GetPool();
142 pSet
= new SfxItemSet( rItemPool
,
143 ATTR_BACKGROUND
, ATTR_BACKGROUND
,
144 ATTR_BORDER
, ATTR_SHADOW
,
145 ATTR_LRSPACE
, ATTR_PAGE_SCALETO
,
146 ATTR_WRITINGDIR
, ATTR_WRITINGDIR
,
147 ATTR_USERDEF
, ATTR_USERDEF
,
150 // If being loaded also the set is then filled in from the file,
151 // so the defaults do not need to be set.
152 // GetPrinter would then also create a new printer,
153 // because the stored Printer is not loaded yet!
155 ScDocument
* pDoc
= static_cast<ScStyleSheetPool
&>(GetPool()).GetDocument();
158 // Setting reasonable default values:
159 SvxPageItem
aPageItem( ATTR_PAGE
);
160 SvxSizeItem
aPaperSizeItem( ATTR_PAGE_SIZE
, SvxPaperInfo::GetDefaultPaperSize() );
162 SvxSetItem
aHFSetItem(
163 static_cast<const SvxSetItem
&>(
164 rItemPool
.GetDefaultItem(ATTR_PAGE_HEADERSET
) ));
166 SfxItemSet
& rHFSet
= aHFSetItem
.GetItemSet();
167 SvxSizeItem
aHFSizeItem( // 0,5 cm + distance
169 Size( 0, (long)( 500 / HMM_PER_TWIPS
) + HFDIST_CM
) );
171 SvxULSpaceItem
aHFDistItem ( HFDIST_CM
,// nUp
175 SvxLRSpaceItem
aLRSpaceItem( TWO_CM
, // nLeft
178 0, // nFirstLineOffset
180 SvxULSpaceItem
aULSpaceItem( TWO_CM
, // nUp
183 SvxBoxInfoItem
aBoxInfoItem( ATTR_BORDER_INNER
);
185 aBoxInfoItem
.SetTable( false );
186 aBoxInfoItem
.SetDist( true );
187 aBoxInfoItem
.SetValid( SvxBoxInfoItemValidFlags::DISTANCE
, true );
189 aPageItem
.SetLandscape( false );
191 rHFSet
.Put( aBoxInfoItem
);
192 rHFSet
.Put( aHFSizeItem
);
193 rHFSet
.Put( aHFDistItem
);
194 rHFSet
.Put( SvxLRSpaceItem( 0,0,0,0, ATTR_LRSPACE
) ); // Set border to Null
196 pSet
->Put( aHFSetItem
, ATTR_PAGE_HEADERSET
);
197 pSet
->Put( aHFSetItem
, ATTR_PAGE_FOOTERSET
);
198 pSet
->Put( aBoxInfoItem
); // Do not overwrite PoolDefault
199 // due to format templates
202 // Writing direction: not as pool default because the default for cells
203 // must remain FRMDIR_ENVIRONMENT, and each page style's setting is
204 // supposed to be saved in the file format.
205 // The page default depends on the system language.
206 SvxFrameDirection eDirection
= ScGlobal::IsSystemRTL() ?
207 FRMDIR_HORI_RIGHT_TOP
: FRMDIR_HORI_LEFT_TOP
;
208 pSet
->Put( SvxFrameDirectionItem( eDirection
, ATTR_WRITINGDIR
), ATTR_WRITINGDIR
);
210 rItemPool
.SetPoolDefaultItem( aPageItem
);
211 rItemPool
.SetPoolDefaultItem( aPaperSizeItem
);
212 rItemPool
.SetPoolDefaultItem( aLRSpaceItem
);
213 rItemPool
.SetPoolDefaultItem( aULSpaceItem
);
214 rItemPool
.SetPoolDefaultItem( SfxUInt16Item( ATTR_PAGE_SCALE
, 100 ) );
215 ScPageScaleToItem aScaleToItem
;
216 rItemPool
.SetPoolDefaultItem( aScaleToItem
);
217 rItemPool
.SetPoolDefaultItem( SfxUInt16Item( ATTR_PAGE_SCALETOPAGES
, 0 ) );
222 case SFX_STYLE_FAMILY_PARA
:
224 pSet
= new SfxItemSet( GetPool().GetPool(), ATTR_PATTERN_START
, ATTR_PATTERN_END
);
229 if ( nHelpId
== HID_SC_SHEET_CELL_ERG1
)
231 if ( !pSet
->Count() )
233 // Hack to work around that when this code is called from
234 // ~ScStyleSheetPool -> ~SfxStyleSheetPool, GetPool() is no longer
235 // an ScStyleSheetPool:
236 ScStyleSheetPool
* pool
= dynamic_cast<ScStyleSheetPool
*>(
238 if (pool
!= nullptr) {
239 ScDocument
* pDoc
= pool
->GetDocument();
242 sal_uLong nNumFmt
= pDoc
->GetFormatTable()->GetStandardFormat( css::util::NumberFormat::CURRENCY
,ScGlobal::eLnge
);
243 pSet
->Put( SfxUInt32Item( ATTR_VALUE_FORMAT
, nNumFmt
) );
252 bool ScStyleSheet::IsUsed() const
254 if ( GetFamily() == SFX_STYLE_FAMILY_PARA
)
256 // Always query the document to let it decide if a rescan is necessary,
257 // and store the state.
258 ScDocument
* pDoc
= static_cast<ScStyleSheetPool
*>(pPool
)->GetDocument();
259 if ( pDoc
&& pDoc
->IsStyleSheetUsed( *this, true ) )
263 return eUsage
== USED
;
269 void ScStyleSheet::Notify( SfxBroadcaster
&, const SfxHint
& rHint
)
271 const SfxSimpleHint
* pSimpleHint
= dynamic_cast<const SfxSimpleHint
*>(&rHint
);
272 if ( pSimpleHint
&& pSimpleHint
->GetId() == SFX_HINT_DYING
)
273 GetItemSet().SetParent( NULL
);
276 // Dirty tricks, to always save the default template as "standard"
277 // even though when shown to the user it is renamed:
279 const OUString
& ScStyleSheet::GetName() const
281 const OUString
& rBase
= SfxStyleSheet::GetName();
282 const OUString
* pForceStdName
= static_cast<ScStyleSheetPool
*>(pPool
)->GetForceStdName();
283 if ( pForceStdName
&& rBase
== ScGlobal::GetRscString(STR_STYLENAME_STANDARD
) )
284 return *pForceStdName
;
289 const OUString
& ScStyleSheet::GetParent() const
291 const OUString
& rBase
= SfxStyleSheet::GetParent();
292 const OUString
* pForceStdName
= static_cast<ScStyleSheetPool
*>(pPool
)->GetForceStdName();
293 if ( pForceStdName
&& rBase
== ScGlobal::GetRscString(STR_STYLENAME_STANDARD
) )
294 return *pForceStdName
;
299 const OUString
& ScStyleSheet::GetFollow() const
301 const OUString
& rBase
= SfxStyleSheet::GetFollow();
302 const OUString
* pForceStdName
= static_cast<ScStyleSheetPool
*>(pPool
)->GetForceStdName();
303 if ( pForceStdName
&& rBase
== ScGlobal::GetRscString(STR_STYLENAME_STANDARD
) )
304 return *pForceStdName
;
309 // Avoid creating a Style "Standard" if this is not the Standard-Name;
310 // otherwise two styles would have the same name when storing.
311 // (on loading the style is created directly per Make with the name; making this query
313 //TODO: If at any time during loading SetName is called, a flag has to be set/checked for loading
314 //TODO: The whole check has to be removed if for a new file version the name transformation is dropped.
316 bool ScStyleSheet::SetName(const OUString
& rNew
, bool bReindexNow
)
318 OUString aFileStdName
= OUString(STRING_STANDARD
);
319 if ( rNew
== aFileStdName
&& aFileStdName
!= ScGlobal::GetRscString(STR_STYLENAME_STANDARD
) )
322 return SfxStyleSheet::SetName(rNew
, bReindexNow
);
325 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */