1b3f79822SAndrew Rist /**************************************************************
2cdf0e10cSrcweir *
3b3f79822SAndrew Rist * Licensed to the Apache Software Foundation (ASF) under one
4b3f79822SAndrew Rist * or more contributor license agreements. See the NOTICE file
5b3f79822SAndrew Rist * distributed with this work for additional information
6b3f79822SAndrew Rist * regarding copyright ownership. The ASF licenses this file
7b3f79822SAndrew Rist * to you under the Apache License, Version 2.0 (the
8b3f79822SAndrew Rist * "License"); you may not use this file except in compliance
9b3f79822SAndrew Rist * with the License. You may obtain a copy of the License at
10cdf0e10cSrcweir *
11b3f79822SAndrew Rist * http://www.apache.org/licenses/LICENSE-2.0
12cdf0e10cSrcweir *
13b3f79822SAndrew Rist * Unless required by applicable law or agreed to in writing,
14b3f79822SAndrew Rist * software distributed under the License is distributed on an
15b3f79822SAndrew Rist * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
16b3f79822SAndrew Rist * KIND, either express or implied. See the License for the
17b3f79822SAndrew Rist * specific language governing permissions and limitations
18b3f79822SAndrew Rist * under the License.
19cdf0e10cSrcweir *
20b3f79822SAndrew Rist *************************************************************/
21b3f79822SAndrew Rist
22b3f79822SAndrew Rist
23cdf0e10cSrcweir
24cdf0e10cSrcweir // MARKER(update_precomp.py): autogen include statement, do not remove
25cdf0e10cSrcweir #include "precompiled_sc.hxx"
26cdf0e10cSrcweir
27cdf0e10cSrcweir
28cdf0e10cSrcweir
29cdf0e10cSrcweir //------------------------------------------------------------------------
30cdf0e10cSrcweir #include "document.hxx"
31cdf0e10cSrcweir #include "stlsheet.hxx"
32cdf0e10cSrcweir #include "stlpool.hxx"
33cdf0e10cSrcweir
34cdf0e10cSrcweir #include "scitems.hxx"
35cdf0e10cSrcweir #include <editeng/boxitem.hxx>
36cdf0e10cSrcweir #include <editeng/frmdiritem.hxx>
37cdf0e10cSrcweir #include <editeng/lrspitem.hxx>
38cdf0e10cSrcweir #include <svx/pageitem.hxx>
39cdf0e10cSrcweir #include <editeng/paperinf.hxx>
40cdf0e10cSrcweir #include <editeng/pbinitem.hxx>
41cdf0e10cSrcweir #include <editeng/sizeitem.hxx>
42cdf0e10cSrcweir #include <editeng/ulspitem.hxx>
43cdf0e10cSrcweir #include <sfx2/printer.hxx>
44cdf0e10cSrcweir #include <svl/itempool.hxx>
45cdf0e10cSrcweir #include <svl/itemset.hxx>
46cdf0e10cSrcweir #include <svl/smplhint.hxx>
47cdf0e10cSrcweir #include "attrib.hxx"
48cdf0e10cSrcweir
49cdf0e10cSrcweir
50cdf0e10cSrcweir #include <vcl/svapp.hxx> // GetSettings()
51cdf0e10cSrcweir
52cdf0e10cSrcweir #include "globstr.hrc"
53cdf0e10cSrcweir #include "sc.hrc"
54cdf0e10cSrcweir //------------------------------------------------------------------------
55cdf0e10cSrcweir
56cdf0e10cSrcweir TYPEINIT1(ScStyleSheet, SfxStyleSheet);
57cdf0e10cSrcweir
58cdf0e10cSrcweir #define TWO_CM 1134
59cdf0e10cSrcweir #define HFDIST_CM 142
60cdf0e10cSrcweir
61cdf0e10cSrcweir //========================================================================
62cdf0e10cSrcweir
ScStyleSheet(const String & rName,ScStyleSheetPool & rPoolP,SfxStyleFamily eFamily,sal_uInt16 nMaskP)63cdf0e10cSrcweir ScStyleSheet::ScStyleSheet( const String& rName,
64cdf0e10cSrcweir ScStyleSheetPool& rPoolP,
65cdf0e10cSrcweir SfxStyleFamily eFamily,
66cdf0e10cSrcweir sal_uInt16 nMaskP )
67cdf0e10cSrcweir
68cdf0e10cSrcweir : SfxStyleSheet ( rName, rPoolP, eFamily, nMaskP )
69cdf0e10cSrcweir , eUsage( UNKNOWN )
70cdf0e10cSrcweir {
71cdf0e10cSrcweir }
72cdf0e10cSrcweir
73cdf0e10cSrcweir //------------------------------------------------------------------------
74cdf0e10cSrcweir
ScStyleSheet(const ScStyleSheet & rStyle)75cdf0e10cSrcweir ScStyleSheet::ScStyleSheet( const ScStyleSheet& rStyle )
76cdf0e10cSrcweir : SfxStyleSheet ( rStyle )
77cdf0e10cSrcweir , eUsage( UNKNOWN )
78cdf0e10cSrcweir {
79cdf0e10cSrcweir }
80cdf0e10cSrcweir
81cdf0e10cSrcweir //------------------------------------------------------------------------
82cdf0e10cSrcweir
~ScStyleSheet()83cdf0e10cSrcweir __EXPORT ScStyleSheet::~ScStyleSheet()
84cdf0e10cSrcweir {
85cdf0e10cSrcweir }
86cdf0e10cSrcweir
87cdf0e10cSrcweir //------------------------------------------------------------------------
88cdf0e10cSrcweir
HasFollowSupport() const89cdf0e10cSrcweir sal_Bool __EXPORT ScStyleSheet::HasFollowSupport() const
90cdf0e10cSrcweir {
91cdf0e10cSrcweir return sal_False;
92cdf0e10cSrcweir }
93cdf0e10cSrcweir
94cdf0e10cSrcweir //------------------------------------------------------------------------
95cdf0e10cSrcweir
HasParentSupport() const96cdf0e10cSrcweir sal_Bool __EXPORT ScStyleSheet::HasParentSupport () const
97cdf0e10cSrcweir {
98cdf0e10cSrcweir sal_Bool bHasParentSupport = sal_False;
99cdf0e10cSrcweir
100cdf0e10cSrcweir switch ( GetFamily() )
101cdf0e10cSrcweir {
102cdf0e10cSrcweir case SFX_STYLE_FAMILY_PARA: bHasParentSupport = sal_True; break;
103cdf0e10cSrcweir case SFX_STYLE_FAMILY_PAGE: bHasParentSupport = sal_False; break;
104cdf0e10cSrcweir default:
105cdf0e10cSrcweir {
106cdf0e10cSrcweir // added to avoid warnings
107cdf0e10cSrcweir }
108cdf0e10cSrcweir }
109cdf0e10cSrcweir
110cdf0e10cSrcweir return bHasParentSupport;
111cdf0e10cSrcweir }
112cdf0e10cSrcweir
113cdf0e10cSrcweir //------------------------------------------------------------------------
114cdf0e10cSrcweir
SetParent(const String & rParentName)115cdf0e10cSrcweir sal_Bool __EXPORT ScStyleSheet::SetParent( const String& rParentName )
116cdf0e10cSrcweir {
117cdf0e10cSrcweir sal_Bool bResult = sal_False;
118cdf0e10cSrcweir String aEffName = rParentName;
119cdf0e10cSrcweir SfxStyleSheetBase* pStyle = rPool.Find( aEffName, nFamily );
120cdf0e10cSrcweir if (!pStyle)
121cdf0e10cSrcweir {
122*49bd4d4bSArmin Le Grand SfxStyleSheetIteratorPtr pIter = rPool.CreateIterator( nFamily, SFXSTYLEBIT_ALL );
123*49bd4d4bSArmin Le Grand pStyle = pIter->First();
124cdf0e10cSrcweir if (pStyle)
125cdf0e10cSrcweir aEffName = pStyle->GetName();
126cdf0e10cSrcweir }
127cdf0e10cSrcweir
128cdf0e10cSrcweir if ( pStyle && aEffName != GetName() )
129cdf0e10cSrcweir {
130cdf0e10cSrcweir bResult = SfxStyleSheet::SetParent( aEffName );
131cdf0e10cSrcweir if (bResult)
132cdf0e10cSrcweir {
133cdf0e10cSrcweir SfxItemSet& rParentSet = pStyle->GetItemSet();
134cdf0e10cSrcweir GetItemSet().SetParent( &rParentSet );
135cdf0e10cSrcweir
136cdf0e10cSrcweir // #i113491# Drag&Drop in the stylist's hierarchical view doesn't execute a slot,
137cdf0e10cSrcweir // so the repaint has to come from here (after modifying the ItemSet).
138cdf0e10cSrcweir // RepaintRange checks the document's IsVisible flag and locked repaints.
139cdf0e10cSrcweir ScDocument* pDoc = static_cast<ScStyleSheetPool&>(GetPool()).GetDocument();
140cdf0e10cSrcweir if (pDoc)
141cdf0e10cSrcweir pDoc->RepaintRange( ScRange( 0,0,0, MAXCOL,MAXROW,MAXTAB ) );
142cdf0e10cSrcweir }
143cdf0e10cSrcweir }
144cdf0e10cSrcweir
145cdf0e10cSrcweir return bResult;
146cdf0e10cSrcweir }
147cdf0e10cSrcweir
148cdf0e10cSrcweir //------------------------------------------------------------------------
149cdf0e10cSrcweir
GetItemSet()150cdf0e10cSrcweir SfxItemSet& __EXPORT ScStyleSheet::GetItemSet()
151cdf0e10cSrcweir {
152cdf0e10cSrcweir if ( !pSet )
153cdf0e10cSrcweir {
154cdf0e10cSrcweir switch ( GetFamily() )
155cdf0e10cSrcweir {
156cdf0e10cSrcweir case SFX_STYLE_FAMILY_PAGE:
157cdf0e10cSrcweir {
158cdf0e10cSrcweir // Seitenvorlagen sollen nicht ableitbar sein,
159cdf0e10cSrcweir // deshalb werden an dieser Stelle geeignete
160cdf0e10cSrcweir // Werte eingestellt. (==Standard-Seitenvorlage)
161cdf0e10cSrcweir
162cdf0e10cSrcweir SfxItemPool& rItemPool = GetPool().GetPool();
163cdf0e10cSrcweir pSet = new SfxItemSet( rItemPool,
164cdf0e10cSrcweir ATTR_BACKGROUND, ATTR_BACKGROUND,
165cdf0e10cSrcweir ATTR_BORDER, ATTR_SHADOW,
166cdf0e10cSrcweir ATTR_LRSPACE, ATTR_PAGE_SCALETO,
167cdf0e10cSrcweir ATTR_WRITINGDIR, ATTR_WRITINGDIR,
168cdf0e10cSrcweir ATTR_USERDEF, ATTR_USERDEF,
169cdf0e10cSrcweir 0 );
170cdf0e10cSrcweir
171cdf0e10cSrcweir // Wenn gerade geladen wird, wird auch der Set hinterher aus der Datei
172cdf0e10cSrcweir // gefuellt, es brauchen also keine Defaults gesetzt zu werden.
173cdf0e10cSrcweir // GetPrinter wuerde dann auch einen neuen Printer anlegen, weil der
174cdf0e10cSrcweir // gespeicherte Printer noch nicht geladen ist!
175cdf0e10cSrcweir
176cdf0e10cSrcweir ScDocument* pDoc = ((ScStyleSheetPool&)GetPool()).GetDocument();
177cdf0e10cSrcweir if ( pDoc )
178cdf0e10cSrcweir {
179cdf0e10cSrcweir // Setzen von sinnvollen Default-Werten:
180cdf0e10cSrcweir SvxPageItem aPageItem( ATTR_PAGE );
181cdf0e10cSrcweir SvxSizeItem aPaperSizeItem( ATTR_PAGE_SIZE, SvxPaperInfo::GetDefaultPaperSize() );
182cdf0e10cSrcweir
183cdf0e10cSrcweir SvxSetItem aHFSetItem(
184cdf0e10cSrcweir (const SvxSetItem&)
185cdf0e10cSrcweir rItemPool.GetDefaultItem(ATTR_PAGE_HEADERSET) );
186cdf0e10cSrcweir
187cdf0e10cSrcweir SfxItemSet& rHFSet = aHFSetItem.GetItemSet();
188cdf0e10cSrcweir SvxSizeItem aHFSizeItem( // 0,5 cm + Abstand
189cdf0e10cSrcweir ATTR_PAGE_SIZE,
190cdf0e10cSrcweir Size( 0, (long)( 500 / HMM_PER_TWIPS ) + HFDIST_CM ) );
191cdf0e10cSrcweir
192cdf0e10cSrcweir SvxULSpaceItem aHFDistItem ( HFDIST_CM,// nUp
193cdf0e10cSrcweir HFDIST_CM,// nLow
194cdf0e10cSrcweir ATTR_ULSPACE );
195cdf0e10cSrcweir
196cdf0e10cSrcweir SvxLRSpaceItem aLRSpaceItem( TWO_CM, // nLeft
197cdf0e10cSrcweir TWO_CM, // nRight
198cdf0e10cSrcweir TWO_CM, // nTLeft
199cdf0e10cSrcweir 0, // nFirstLineOffset
200cdf0e10cSrcweir ATTR_LRSPACE );
201cdf0e10cSrcweir SvxULSpaceItem aULSpaceItem( TWO_CM, // nUp
202cdf0e10cSrcweir TWO_CM, // nLow
203cdf0e10cSrcweir ATTR_ULSPACE );
204cdf0e10cSrcweir SvxBoxInfoItem aBoxInfoItem( ATTR_BORDER_INNER );
205cdf0e10cSrcweir
206cdf0e10cSrcweir aBoxInfoItem.SetTable( sal_False );
207cdf0e10cSrcweir aBoxInfoItem.SetDist( sal_True );
208cdf0e10cSrcweir aBoxInfoItem.SetValid( VALID_DISTANCE, sal_True );
209cdf0e10cSrcweir
210cdf0e10cSrcweir // aPageItem.SetLandscape( ORIENTATION_LANDSCAPE == pPrinter->GetOrientation() );
211cdf0e10cSrcweir aPageItem.SetLandscape( sal_False );
212cdf0e10cSrcweir
213cdf0e10cSrcweir rHFSet.Put( aBoxInfoItem );
214cdf0e10cSrcweir rHFSet.Put( aHFSizeItem );
215cdf0e10cSrcweir rHFSet.Put( aHFDistItem );
216cdf0e10cSrcweir rHFSet.Put( SvxLRSpaceItem( 0,0,0,0, ATTR_LRSPACE ) ); // Rand auf Null setzen
217cdf0e10cSrcweir
218cdf0e10cSrcweir pSet->Put( aHFSetItem, ATTR_PAGE_HEADERSET );
219cdf0e10cSrcweir pSet->Put( aHFSetItem, ATTR_PAGE_FOOTERSET );
220cdf0e10cSrcweir pSet->Put( aBoxInfoItem ); // PoolDefault wg. Formatvorlagen
221cdf0e10cSrcweir // nicht ueberschreiben!
222cdf0e10cSrcweir
223cdf0e10cSrcweir // Writing direction: not as pool default because the default for cells
224cdf0e10cSrcweir // must remain FRMDIR_ENVIRONMENT, and each page style's setting is
225cdf0e10cSrcweir // supposed to be saved in the file format.
226cdf0e10cSrcweir // The page default depends on the system language.
227cdf0e10cSrcweir SvxFrameDirection eDirection = ScGlobal::IsSystemRTL() ?
228cdf0e10cSrcweir FRMDIR_HORI_RIGHT_TOP : FRMDIR_HORI_LEFT_TOP;
229cdf0e10cSrcweir pSet->Put( SvxFrameDirectionItem( eDirection, ATTR_WRITINGDIR ), ATTR_WRITINGDIR );
230cdf0e10cSrcweir
231cdf0e10cSrcweir rItemPool.SetPoolDefaultItem( aPageItem );
232cdf0e10cSrcweir rItemPool.SetPoolDefaultItem( aPaperSizeItem );
233cdf0e10cSrcweir rItemPool.SetPoolDefaultItem( aLRSpaceItem );
234cdf0e10cSrcweir rItemPool.SetPoolDefaultItem( aULSpaceItem );
235cdf0e10cSrcweir rItemPool.SetPoolDefaultItem( SfxUInt16Item( ATTR_PAGE_SCALE, 100 ) );
236cdf0e10cSrcweir ScPageScaleToItem aScaleToItem;
237cdf0e10cSrcweir rItemPool.SetPoolDefaultItem( aScaleToItem );
238cdf0e10cSrcweir rItemPool.SetPoolDefaultItem( SfxUInt16Item( ATTR_PAGE_SCALETOPAGES, 0 ) );
239cdf0e10cSrcweir }
240cdf0e10cSrcweir }
241cdf0e10cSrcweir break;
242cdf0e10cSrcweir
243cdf0e10cSrcweir case SFX_STYLE_FAMILY_PARA:
244cdf0e10cSrcweir default:
245cdf0e10cSrcweir pSet = new SfxItemSet( GetPool().GetPool(),
246cdf0e10cSrcweir ATTR_PATTERN_START, ATTR_PATTERN_END,
247cdf0e10cSrcweir 0 );
248cdf0e10cSrcweir break;
249cdf0e10cSrcweir }
250cdf0e10cSrcweir bMySet = sal_True;
251cdf0e10cSrcweir } // if ( !pSet )
252cdf0e10cSrcweir if ( nHelpId == HID_SC_SHEET_CELL_ERG1 )
253cdf0e10cSrcweir {
254cdf0e10cSrcweir if ( !pSet->Count() )
255cdf0e10cSrcweir {
256cdf0e10cSrcweir ScDocument* pDoc = ((ScStyleSheetPool&)GetPool()).GetDocument();
257cdf0e10cSrcweir if ( pDoc )
258cdf0e10cSrcweir {
259cdf0e10cSrcweir sal_uLong nNumFmt = pDoc->GetFormatTable()->GetStandardFormat( NUMBERFORMAT_CURRENCY,ScGlobal::eLnge );
260cdf0e10cSrcweir pSet->Put( SfxUInt32Item( ATTR_VALUE_FORMAT, nNumFmt ) );
261cdf0e10cSrcweir } // if ( pDoc && pDoc->IsLoadingDone() )
262cdf0e10cSrcweir }
263cdf0e10cSrcweir }
264cdf0e10cSrcweir
265cdf0e10cSrcweir return *pSet;
266cdf0e10cSrcweir }
267cdf0e10cSrcweir
268cdf0e10cSrcweir //------------------------------------------------------------------------
269cdf0e10cSrcweir
IsUsed() const270cdf0e10cSrcweir sal_Bool __EXPORT ScStyleSheet::IsUsed() const
271cdf0e10cSrcweir {
272cdf0e10cSrcweir if ( GetFamily() == SFX_STYLE_FAMILY_PARA )
273cdf0e10cSrcweir {
274cdf0e10cSrcweir // Always query the document to let it decide if a rescan is necessary,
275cdf0e10cSrcweir // and store the state.
276cdf0e10cSrcweir ScDocument* pDoc = ((ScStyleSheetPool&)rPool).GetDocument();
277cdf0e10cSrcweir if ( pDoc && pDoc->IsStyleSheetUsed( *this, sal_True ) )
278cdf0e10cSrcweir eUsage = USED;
279cdf0e10cSrcweir else
280cdf0e10cSrcweir eUsage = NOTUSED;
281cdf0e10cSrcweir return eUsage == USED;
282cdf0e10cSrcweir }
283cdf0e10cSrcweir else
284cdf0e10cSrcweir return sal_True;
285cdf0e10cSrcweir }
286cdf0e10cSrcweir
287cdf0e10cSrcweir //------------------------------------------------------------------------
288cdf0e10cSrcweir
Notify(SfxBroadcaster &,const SfxHint & rHint)289cdf0e10cSrcweir void __EXPORT ScStyleSheet::Notify( SfxBroadcaster&, const SfxHint& rHint )
290cdf0e10cSrcweir {
291cdf0e10cSrcweir if ( rHint.ISA(SfxSimpleHint) )
292cdf0e10cSrcweir if ( ((SfxSimpleHint&)rHint).GetId() == SFX_HINT_DYING )
293cdf0e10cSrcweir GetItemSet().SetParent( NULL );
294cdf0e10cSrcweir }
295cdf0e10cSrcweir
296cdf0e10cSrcweir //------------------------------------------------------------------------
297cdf0e10cSrcweir
298cdf0e10cSrcweir // #66123# schmutzige Tricks, um die Standard-Vorlage immer als "Standard" zu speichern,
299cdf0e10cSrcweir // obwohl der fuer den Benutzer sichtbare Name uebersetzt ist:
300cdf0e10cSrcweir
GetName() const301cdf0e10cSrcweir const String& ScStyleSheet::GetName() const
302cdf0e10cSrcweir {
303cdf0e10cSrcweir const String& rBase = SfxStyleSheet::GetName();
304cdf0e10cSrcweir const String* pForceStdName = ((ScStyleSheetPool&)rPool).GetForceStdName();
305cdf0e10cSrcweir if ( pForceStdName && rBase == ScGlobal::GetRscString(STR_STYLENAME_STANDARD) )
306cdf0e10cSrcweir return *pForceStdName;
307cdf0e10cSrcweir else
308cdf0e10cSrcweir return rBase;
309cdf0e10cSrcweir }
310cdf0e10cSrcweir
GetParent() const311cdf0e10cSrcweir const String& ScStyleSheet::GetParent() const
312cdf0e10cSrcweir {
313cdf0e10cSrcweir const String& rBase = SfxStyleSheet::GetParent();
314cdf0e10cSrcweir const String* pForceStdName = ((ScStyleSheetPool&)rPool).GetForceStdName();
315cdf0e10cSrcweir if ( pForceStdName && rBase == ScGlobal::GetRscString(STR_STYLENAME_STANDARD) )
316cdf0e10cSrcweir return *pForceStdName;
317cdf0e10cSrcweir else
318cdf0e10cSrcweir return rBase;
319cdf0e10cSrcweir }
320cdf0e10cSrcweir
GetFollow() const321cdf0e10cSrcweir const String& ScStyleSheet::GetFollow() const
322cdf0e10cSrcweir {
323cdf0e10cSrcweir const String& rBase = SfxStyleSheet::GetFollow();
324cdf0e10cSrcweir const String* pForceStdName = ((ScStyleSheetPool&)rPool).GetForceStdName();
325cdf0e10cSrcweir if ( pForceStdName && rBase == ScGlobal::GetRscString(STR_STYLENAME_STANDARD) )
326cdf0e10cSrcweir return *pForceStdName;
327cdf0e10cSrcweir else
328cdf0e10cSrcweir return rBase;
329cdf0e10cSrcweir }
330cdf0e10cSrcweir
331cdf0e10cSrcweir // Verhindern, dass ein Style "Standard" angelegt wird, wenn das nicht der
332cdf0e10cSrcweir // Standard-Name ist, weil sonst beim Speichern zwei Styles denselben Namen haetten
333cdf0e10cSrcweir // (Beim Laden wird der Style direkt per Make mit dem Namen erzeugt, so dass diese
334cdf0e10cSrcweir // Abfrage dann nicht gilt)
335cdf0e10cSrcweir //! Wenn irgendwann aus dem Laden SetName aufgerufen wird, muss fuer das Laden ein
336cdf0e10cSrcweir //! Flag gesetzt und abgefragt werden.
337cdf0e10cSrcweir //! Die ganze Abfrage muss raus, wenn fuer eine neue Datei-Version die Namens-Umsetzung wegfaellt.
338cdf0e10cSrcweir
SetName(const String & rNew)339cdf0e10cSrcweir sal_Bool ScStyleSheet::SetName( const String& rNew )
340cdf0e10cSrcweir {
341cdf0e10cSrcweir String aFileStdName = String::CreateFromAscii(RTL_CONSTASCII_STRINGPARAM(STRING_STANDARD));
342cdf0e10cSrcweir if ( rNew == aFileStdName && aFileStdName != ScGlobal::GetRscString(STR_STYLENAME_STANDARD) )
343cdf0e10cSrcweir return sal_False;
344cdf0e10cSrcweir else
345cdf0e10cSrcweir return SfxStyleSheet::SetName( rNew );
346cdf0e10cSrcweir }
347cdf0e10cSrcweir
348cdf0e10cSrcweir
349cdf0e10cSrcweir
350