fix baseline build (old cairo) - 'cairo_rectangle_int_t' does not name a type
[LibreOffice.git] / sc / source / core / data / stlsheet.cxx
blobbe060c284ad668d7563a511386704347dc6eac8d
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 .
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>
37 #include "attrib.hxx"
39 #include <vcl/svapp.hxx>
41 #include "globstr.hrc"
42 #include "sc.hrc"
44 TYPEINIT1(ScStyleSheet, SfxStyleSheet);
46 #define TWO_CM 1134
47 #define HFDIST_CM 142
49 ScStyleSheet::ScStyleSheet( const OUString& rName,
50 ScStyleSheetPool& rPoolP,
51 SfxStyleFamily eFamily,
52 sal_uInt16 nMaskP )
54 : SfxStyleSheet ( rName, rPoolP, eFamily, nMaskP )
55 , eUsage( UNKNOWN )
59 ScStyleSheet::ScStyleSheet( const ScStyleSheet& rStyle )
60 : SfxStyleSheet ( rStyle )
61 , eUsage( UNKNOWN )
65 ScStyleSheet::~ScStyleSheet()
69 bool ScStyleSheet::HasFollowSupport() const
71 return false;
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;
82 default:
84 // added to avoid warnings
88 return bHasParentSupport;
91 bool ScStyleSheet::SetParent( const OUString& rParentName )
93 bool bResult = false;
94 OUString aEffName = rParentName;
95 SfxStyleSheetBase* pStyle = pPool->Find( aEffName, nFamily );
96 if (!pStyle)
98 SfxStyleSheetIteratorPtr pIter = pPool->CreateIterator( nFamily, SFXSTYLEBIT_ALL );
99 pStyle = pIter->First();
100 if (pStyle)
101 aEffName = pStyle->GetName();
104 if ( pStyle && aEffName != GetName() )
106 bResult = SfxStyleSheet::SetParent( aEffName );
107 if (bResult)
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();
116 if (pDoc)
117 pDoc->RepaintRange( ScRange( 0,0,0, MAXCOL,MAXROW,MAXTAB ) );
121 return bResult;
124 void ScStyleSheet::ResetParent()
126 GetItemSet().SetParent(NULL);
129 SfxItemSet& ScStyleSheet::GetItemSet()
131 if ( !pSet )
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,
148 0 );
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();
156 if ( pDoc )
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
168 ATTR_PAGE_SIZE,
169 Size( 0, (long)( 500 / HMM_PER_TWIPS ) + HFDIST_CM ) );
171 SvxULSpaceItem aHFDistItem ( HFDIST_CM,// nUp
172 HFDIST_CM,// nLow
173 ATTR_ULSPACE );
175 SvxLRSpaceItem aLRSpaceItem( TWO_CM, // nLeft
176 TWO_CM, // nRight
177 TWO_CM, // nTLeft
178 0, // nFirstLineOffset
179 ATTR_LRSPACE );
180 SvxULSpaceItem aULSpaceItem( TWO_CM, // nUp
181 TWO_CM, // nLow
182 ATTR_ULSPACE );
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 ) );
220 break;
222 case SFX_STYLE_FAMILY_PARA:
223 default:
224 pSet = new SfxItemSet( GetPool().GetPool(), ATTR_PATTERN_START, ATTR_PATTERN_END );
225 break;
227 bMySet = true;
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 *>(
237 &GetPool());
238 if (pool != nullptr) {
239 ScDocument* pDoc = pool->GetDocument();
240 if ( pDoc )
242 sal_uLong nNumFmt = pDoc->GetFormatTable()->GetStandardFormat( css::util::NumberFormat::CURRENCY,ScGlobal::eLnge );
243 pSet->Put( SfxUInt32Item( ATTR_VALUE_FORMAT, nNumFmt ) );
249 return *pSet;
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 ) )
260 eUsage = USED;
261 else
262 eUsage = NOTUSED;
263 return eUsage == USED;
265 else
266 return true;
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;
285 else
286 return rBase;
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;
295 else
296 return rBase;
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;
305 else
306 return rBase;
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
312 // not applicable)
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) )
320 return false;
321 else
322 return SfxStyleSheet::SetName(rNew, bReindexNow);
325 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */