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>
40 #include <vcl/svapp.hxx>
42 #include "globstr.hrc"
44 //------------------------------------------------------------------------
46 TYPEINIT1(ScStyleSheet
, SfxStyleSheet
);
51 //========================================================================
53 ScStyleSheet::ScStyleSheet( const OUString
& rName
,
54 ScStyleSheetPool
& rPoolP
,
55 SfxStyleFamily eFamily
,
58 : SfxStyleSheet ( rName
, rPoolP
, eFamily
, nMaskP
)
63 //------------------------------------------------------------------------
65 ScStyleSheet::ScStyleSheet( const ScStyleSheet
& rStyle
)
66 : SfxStyleSheet ( rStyle
)
71 //------------------------------------------------------------------------
73 ScStyleSheet::~ScStyleSheet()
77 //------------------------------------------------------------------------
79 bool ScStyleSheet::HasFollowSupport() const
84 //------------------------------------------------------------------------
86 bool ScStyleSheet::HasParentSupport () const
88 bool bHasParentSupport
= false;
90 switch ( GetFamily() )
92 case SFX_STYLE_FAMILY_PARA
: bHasParentSupport
= true; break;
93 case SFX_STYLE_FAMILY_PAGE
: bHasParentSupport
= false; break;
96 // added to avoid warnings
100 return bHasParentSupport
;
103 //------------------------------------------------------------------------
105 bool ScStyleSheet::SetParent( const OUString
& rParentName
)
107 bool bResult
= false;
108 OUString aEffName
= rParentName
;
109 SfxStyleSheetBase
* pStyle
= pPool
->Find( aEffName
, nFamily
);
112 SfxStyleSheetIteratorPtr pIter
= pPool
->CreateIterator( nFamily
, SFXSTYLEBIT_ALL
);
113 pStyle
= pIter
->First();
115 aEffName
= pStyle
->GetName();
118 if ( pStyle
&& aEffName
!= GetName() )
120 bResult
= SfxStyleSheet::SetParent( aEffName
);
123 SfxItemSet
& rParentSet
= pStyle
->GetItemSet();
124 GetItemSet().SetParent( &rParentSet
);
126 // #i113491# Drag&Drop in the stylist's hierarchical view doesn't execute a slot,
127 // so the repaint has to come from here (after modifying the ItemSet).
128 // RepaintRange checks the document's IsVisible flag and locked repaints.
129 ScDocument
* pDoc
= static_cast<ScStyleSheetPool
&>(GetPool()).GetDocument();
131 pDoc
->RepaintRange( ScRange( 0,0,0, MAXCOL
,MAXROW
,MAXTAB
) );
138 //------------------------------------------------------------------------
140 SfxItemSet
& ScStyleSheet::GetItemSet()
144 switch ( GetFamily() )
146 case SFX_STYLE_FAMILY_PAGE
:
148 // Seitenvorlagen sollen nicht ableitbar sein,
149 // deshalb werden an dieser Stelle geeignete
150 // Werte eingestellt. (==Standard-Seitenvorlage)
152 SfxItemPool
& rItemPool
= GetPool().GetPool();
153 pSet
= new SfxItemSet( rItemPool
,
154 ATTR_BACKGROUND
, ATTR_BACKGROUND
,
155 ATTR_BORDER
, ATTR_SHADOW
,
156 ATTR_LRSPACE
, ATTR_PAGE_SCALETO
,
157 ATTR_WRITINGDIR
, ATTR_WRITINGDIR
,
158 ATTR_USERDEF
, ATTR_USERDEF
,
161 // Wenn gerade geladen wird, wird auch der Set hinterher aus der Datei
162 // gefuellt, es brauchen also keine Defaults gesetzt zu werden.
163 // GetPrinter wuerde dann auch einen neuen Printer anlegen, weil der
164 // gespeicherte Printer noch nicht geladen ist!
166 ScDocument
* pDoc
= ((ScStyleSheetPool
&)GetPool()).GetDocument();
169 // Setzen von sinnvollen Default-Werten:
170 SvxPageItem
aPageItem( ATTR_PAGE
);
171 SvxSizeItem
aPaperSizeItem( ATTR_PAGE_SIZE
, SvxPaperInfo::GetDefaultPaperSize() );
173 SvxSetItem
aHFSetItem(
175 rItemPool
.GetDefaultItem(ATTR_PAGE_HEADERSET
) );
177 SfxItemSet
& rHFSet
= aHFSetItem
.GetItemSet();
178 SvxSizeItem
aHFSizeItem( // 0,5 cm + Abstand
180 Size( 0, (long)( 500 / HMM_PER_TWIPS
) + HFDIST_CM
) );
182 SvxULSpaceItem
aHFDistItem ( HFDIST_CM
,// nUp
186 SvxLRSpaceItem
aLRSpaceItem( TWO_CM
, // nLeft
189 0, // nFirstLineOffset
191 SvxULSpaceItem
aULSpaceItem( TWO_CM
, // nUp
194 SvxBoxInfoItem
aBoxInfoItem( ATTR_BORDER_INNER
);
196 aBoxInfoItem
.SetTable( false );
197 aBoxInfoItem
.SetDist( sal_True
);
198 aBoxInfoItem
.SetValid( VALID_DISTANCE
, sal_True
);
200 aPageItem
.SetLandscape( false );
202 rHFSet
.Put( aBoxInfoItem
);
203 rHFSet
.Put( aHFSizeItem
);
204 rHFSet
.Put( aHFDistItem
);
205 rHFSet
.Put( SvxLRSpaceItem( 0,0,0,0, ATTR_LRSPACE
) ); // Rand auf Null setzen
207 pSet
->Put( aHFSetItem
, ATTR_PAGE_HEADERSET
);
208 pSet
->Put( aHFSetItem
, ATTR_PAGE_FOOTERSET
);
209 pSet
->Put( aBoxInfoItem
); // PoolDefault wg. Formatvorlagen
210 // nicht ueberschreiben!
212 // Writing direction: not as pool default because the default for cells
213 // must remain FRMDIR_ENVIRONMENT, and each page style's setting is
214 // supposed to be saved in the file format.
215 // The page default depends on the system language.
216 SvxFrameDirection eDirection
= ScGlobal::IsSystemRTL() ?
217 FRMDIR_HORI_RIGHT_TOP
: FRMDIR_HORI_LEFT_TOP
;
218 pSet
->Put( SvxFrameDirectionItem( eDirection
, ATTR_WRITINGDIR
), ATTR_WRITINGDIR
);
220 rItemPool
.SetPoolDefaultItem( aPageItem
);
221 rItemPool
.SetPoolDefaultItem( aPaperSizeItem
);
222 rItemPool
.SetPoolDefaultItem( aLRSpaceItem
);
223 rItemPool
.SetPoolDefaultItem( aULSpaceItem
);
224 rItemPool
.SetPoolDefaultItem( SfxUInt16Item( ATTR_PAGE_SCALE
, 100 ) );
225 ScPageScaleToItem aScaleToItem
;
226 rItemPool
.SetPoolDefaultItem( aScaleToItem
);
227 rItemPool
.SetPoolDefaultItem( SfxUInt16Item( ATTR_PAGE_SCALETOPAGES
, 0 ) );
232 case SFX_STYLE_FAMILY_PARA
:
234 pSet
= new SfxItemSet( GetPool().GetPool(), ATTR_PATTERN_START
, ATTR_PATTERN_END
);
239 if ( nHelpId
== HID_SC_SHEET_CELL_ERG1
)
241 if ( !pSet
->Count() )
243 ScDocument
* pDoc
= ((ScStyleSheetPool
&)GetPool()).GetDocument();
246 sal_uLong nNumFmt
= pDoc
->GetFormatTable()->GetStandardFormat( NUMBERFORMAT_CURRENCY
,ScGlobal::eLnge
);
247 pSet
->Put( SfxUInt32Item( ATTR_VALUE_FORMAT
, nNumFmt
) );
255 //------------------------------------------------------------------------
257 bool ScStyleSheet::IsUsed() const
259 if ( GetFamily() == SFX_STYLE_FAMILY_PARA
)
261 // Always query the document to let it decide if a rescan is necessary,
262 // and store the state.
263 ScDocument
* pDoc
= ((ScStyleSheetPool
*)pPool
)->GetDocument();
264 if ( pDoc
&& pDoc
->IsStyleSheetUsed( *this, sal_True
) )
268 return eUsage
== USED
;
274 //------------------------------------------------------------------------
276 void ScStyleSheet::Notify( SfxBroadcaster
&, const SfxHint
& rHint
)
278 if ( rHint
.ISA(SfxSimpleHint
) )
279 if ( ((SfxSimpleHint
&)rHint
).GetId() == SFX_HINT_DYING
)
280 GetItemSet().SetParent( NULL
);
283 //------------------------------------------------------------------------
285 // schmutzige Tricks, um die Standard-Vorlage immer als "Standard" zu speichern,
286 // obwohl der fuer den Benutzer sichtbare Name uebersetzt ist:
288 const OUString
& ScStyleSheet::GetName() const
290 const OUString
& rBase
= SfxStyleSheet::GetName();
291 const OUString
* pForceStdName
= ((ScStyleSheetPool
*)pPool
)->GetForceStdName();
292 if ( pForceStdName
&& rBase
== ScGlobal::GetRscString(STR_STYLENAME_STANDARD
) )
293 return *pForceStdName
;
298 const OUString
& ScStyleSheet::GetParent() const
300 const OUString
& rBase
= SfxStyleSheet::GetParent();
301 const OUString
* pForceStdName
= ((ScStyleSheetPool
*)pPool
)->GetForceStdName();
302 if ( pForceStdName
&& rBase
== ScGlobal::GetRscString(STR_STYLENAME_STANDARD
) )
303 return *pForceStdName
;
308 const OUString
& ScStyleSheet::GetFollow() const
310 const OUString
& rBase
= SfxStyleSheet::GetFollow();
311 const OUString
* pForceStdName
= ((ScStyleSheetPool
*)pPool
)->GetForceStdName();
312 if ( pForceStdName
&& rBase
== ScGlobal::GetRscString(STR_STYLENAME_STANDARD
) )
313 return *pForceStdName
;
318 // Verhindern, dass ein Style "Standard" angelegt wird, wenn das nicht der
319 // Standard-Name ist, weil sonst beim Speichern zwei Styles denselben Namen haetten
320 // (Beim Laden wird der Style direkt per Make mit dem Namen erzeugt, so dass diese
321 // Abfrage dann nicht gilt)
322 //! Wenn irgendwann aus dem Laden SetName aufgerufen wird, muss fuer das Laden ein
323 //! Flag gesetzt und abgefragt werden.
324 //! Die ganze Abfrage muss raus, wenn fuer eine neue Datei-Version die Namens-Umsetzung wegfaellt.
326 bool ScStyleSheet::SetName( const OUString
& rNew
)
328 OUString aFileStdName
= OUString(STRING_STANDARD
);
329 if ( rNew
== aFileStdName
&& aFileStdName
!= ScGlobal::GetRscString(STR_STYLENAME_STANDARD
) )
332 return SfxStyleSheet::SetName( rNew
);
337 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */