update dev300-m57
[ooovba.git] / sc / source / core / data / stlsheet.cxx
blob0469e8d38c6685f788bd4a1cc0bee05706c9b08c
1 /*************************************************************************
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4 *
5 * Copyright 2008 by Sun Microsystems, Inc.
7 * OpenOffice.org - a multi-platform office productivity suite
9 * $RCSfile: stlsheet.cxx,v $
10 * $Revision: 1.12 $
12 * This file is part of OpenOffice.org.
14 * OpenOffice.org is free software: you can redistribute it and/or modify
15 * it under the terms of the GNU Lesser General Public License version 3
16 * only, as published by the Free Software Foundation.
18 * OpenOffice.org is distributed in the hope that it will be useful,
19 * but WITHOUT ANY WARRANTY; without even the implied warranty of
20 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
21 * GNU Lesser General Public License version 3 for more details
22 * (a copy is included in the LICENSE file that accompanied this code).
24 * You should have received a copy of the GNU Lesser General Public License
25 * version 3 along with OpenOffice.org. If not, see
26 * <http://www.openoffice.org/license.html>
27 * for a copy of the LGPLv3 License.
29 ************************************************************************/
31 // MARKER(update_precomp.py): autogen include statement, do not remove
32 #include "precompiled_sc.hxx"
36 //------------------------------------------------------------------------
37 #include "document.hxx"
38 #include "stlsheet.hxx"
39 #include "stlpool.hxx"
41 #include "scitems.hxx"
42 #include <svx/boxitem.hxx>
43 #include <svx/frmdiritem.hxx>
44 #include <svx/lrspitem.hxx>
45 #include <svx/pageitem.hxx>
46 #include <svx/paperinf.hxx>
47 #include <svx/pbinitem.hxx>
48 #include <svx/sizeitem.hxx>
49 #include <svx/ulspitem.hxx>
50 #include <sfx2/printer.hxx>
51 #include <svtools/itempool.hxx>
52 #include <svtools/itemset.hxx>
53 #include <svtools/smplhint.hxx>
54 #include "attrib.hxx"
56 #include <vcl/svapp.hxx> // GetSettings()
58 #include "globstr.hrc"
60 //------------------------------------------------------------------------
62 TYPEINIT1(ScStyleSheet, SfxStyleSheet);
64 #define TWO_CM 1134
65 #define HFDIST_CM 142
67 //========================================================================
69 ScStyleSheet::ScStyleSheet( const String& rName,
70 ScStyleSheetPool& rPoolP,
71 SfxStyleFamily eFamily,
72 USHORT nMaskP )
74 : SfxStyleSheet ( rName, rPoolP, eFamily, nMaskP )
75 , eUsage( UNKNOWN )
79 //------------------------------------------------------------------------
81 ScStyleSheet::ScStyleSheet( const ScStyleSheet& rStyle )
82 : SfxStyleSheet ( rStyle )
83 , eUsage( UNKNOWN )
87 //------------------------------------------------------------------------
89 __EXPORT ScStyleSheet::~ScStyleSheet()
93 //------------------------------------------------------------------------
95 BOOL __EXPORT ScStyleSheet::HasFollowSupport() const
97 return FALSE;
100 //------------------------------------------------------------------------
102 BOOL __EXPORT ScStyleSheet::HasParentSupport () const
104 BOOL bHasParentSupport = FALSE;
106 switch ( GetFamily() )
108 case SFX_STYLE_FAMILY_PARA: bHasParentSupport = TRUE; break;
109 case SFX_STYLE_FAMILY_PAGE: bHasParentSupport = FALSE; break;
110 default:
112 // added to avoid warnings
116 return bHasParentSupport;
119 //------------------------------------------------------------------------
121 BOOL __EXPORT ScStyleSheet::SetParent( const String& rParentName )
123 BOOL bResult = FALSE;
124 String aEffName = rParentName;
125 SfxStyleSheetBase* pStyle = rPool.Find( aEffName, nFamily );
126 if (!pStyle)
128 SfxStyleSheetIterator* pIter = rPool.CreateIterator( nFamily, SFXSTYLEBIT_ALL );
129 pStyle = pIter->First();
130 if (pStyle)
131 aEffName = pStyle->GetName();
134 if ( pStyle && aEffName != GetName() )
136 bResult = SfxStyleSheet::SetParent( aEffName );
137 if (bResult)
139 SfxItemSet& rParentSet = pStyle->GetItemSet();
140 GetItemSet().SetParent( &rParentSet );
144 return bResult;
147 //------------------------------------------------------------------------
149 SfxItemSet& __EXPORT ScStyleSheet::GetItemSet()
151 if ( !pSet )
153 switch ( GetFamily() )
155 case SFX_STYLE_FAMILY_PAGE:
157 // Seitenvorlagen sollen nicht ableitbar sein,
158 // deshalb werden an dieser Stelle geeignete
159 // Werte eingestellt. (==Standard-Seitenvorlage)
161 SfxItemPool& rItemPool = GetPool().GetPool();
162 pSet = new SfxItemSet( rItemPool,
163 ATTR_BACKGROUND, ATTR_BACKGROUND,
164 ATTR_BORDER, ATTR_SHADOW,
165 ATTR_LRSPACE, ATTR_PAGE_SCALETO,
166 ATTR_WRITINGDIR, ATTR_WRITINGDIR,
167 ATTR_USERDEF, ATTR_USERDEF,
168 0 );
170 // Wenn gerade geladen wird, wird auch der Set hinterher aus der Datei
171 // gefuellt, es brauchen also keine Defaults gesetzt zu werden.
172 // GetPrinter wuerde dann auch einen neuen Printer anlegen, weil der
173 // gespeicherte Printer noch nicht geladen ist!
175 ScDocument* pDoc = ((ScStyleSheetPool&)GetPool()).GetDocument();
176 if ( pDoc && pDoc->IsLoadingDone() )
178 // Setzen von sinnvollen Default-Werten:
179 SvxPageItem aPageItem( ATTR_PAGE );
180 SvxSizeItem aPaperSizeItem( ATTR_PAGE_SIZE, SvxPaperInfo::GetDefaultPaperSize() );
182 SvxSetItem aHFSetItem(
183 (const SvxSetItem&)
184 rItemPool.GetDefaultItem(ATTR_PAGE_HEADERSET) );
186 SfxItemSet& rHFSet = aHFSetItem.GetItemSet();
187 SvxSizeItem aHFSizeItem( // 0,5 cm + Abstand
188 ATTR_PAGE_SIZE,
189 Size( 0, (long)( 500 / HMM_PER_TWIPS ) + HFDIST_CM ) );
191 SvxULSpaceItem aHFDistItem ( HFDIST_CM,// nUp
192 HFDIST_CM,// nLow
193 ATTR_ULSPACE );
195 SvxLRSpaceItem aLRSpaceItem( TWO_CM, // nLeft
196 TWO_CM, // nRight
197 TWO_CM, // nTLeft
198 0, // nFirstLineOffset
199 ATTR_LRSPACE );
200 SvxULSpaceItem aULSpaceItem( TWO_CM, // nUp
201 TWO_CM, // nLow
202 ATTR_ULSPACE );
203 SvxBoxInfoItem aBoxInfoItem( ATTR_BORDER_INNER );
205 aBoxInfoItem.SetTable( FALSE );
206 aBoxInfoItem.SetDist( TRUE );
207 aBoxInfoItem.SetValid( VALID_DISTANCE, TRUE );
209 // aPageItem.SetLandscape( ORIENTATION_LANDSCAPE == pPrinter->GetOrientation() );
210 aPageItem.SetLandscape( FALSE );
212 rHFSet.Put( aBoxInfoItem );
213 rHFSet.Put( aHFSizeItem );
214 rHFSet.Put( aHFDistItem );
215 rHFSet.Put( SvxLRSpaceItem( 0,0,0,0, ATTR_LRSPACE ) ); // Rand auf Null setzen
217 pSet->Put( aHFSetItem, ATTR_PAGE_HEADERSET );
218 pSet->Put( aHFSetItem, ATTR_PAGE_FOOTERSET );
219 pSet->Put( aBoxInfoItem ); // PoolDefault wg. Formatvorlagen
220 // nicht ueberschreiben!
222 // Writing direction: not as pool default because the default for cells
223 // must remain FRMDIR_ENVIRONMENT, and each page style's setting is
224 // supposed to be saved in the file format.
225 // The page default depends on the system language.
226 SvxFrameDirection eDirection = ScGlobal::IsSystemRTL() ?
227 FRMDIR_HORI_RIGHT_TOP : FRMDIR_HORI_LEFT_TOP;
228 pSet->Put( SvxFrameDirectionItem( eDirection, ATTR_WRITINGDIR ), ATTR_WRITINGDIR );
230 rItemPool.SetPoolDefaultItem( aPageItem );
231 rItemPool.SetPoolDefaultItem( aPaperSizeItem );
232 rItemPool.SetPoolDefaultItem( aLRSpaceItem );
233 rItemPool.SetPoolDefaultItem( aULSpaceItem );
234 rItemPool.SetPoolDefaultItem( SfxUInt16Item( ATTR_PAGE_SCALE, 100 ) );
235 ScPageScaleToItem aScaleToItem;
236 rItemPool.SetPoolDefaultItem( aScaleToItem );
237 rItemPool.SetPoolDefaultItem( SfxUInt16Item( ATTR_PAGE_SCALETOPAGES, 0 ) );
240 break;
242 case SFX_STYLE_FAMILY_PARA:
243 default:
244 pSet = new SfxItemSet( GetPool().GetPool(),
245 ATTR_PATTERN_START, ATTR_PATTERN_END,
246 0 );
247 break;
249 bMySet = TRUE;
252 return *pSet;
255 //------------------------------------------------------------------------
257 BOOL __EXPORT 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&)rPool).GetDocument();
264 if ( pDoc && pDoc->IsStyleSheetUsed( *this, TRUE ) )
265 eUsage = USED;
266 else
267 eUsage = NOTUSED;
268 return eUsage == USED;
270 else
271 return TRUE;
274 //------------------------------------------------------------------------
276 void __EXPORT 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 // #66123# schmutzige Tricks, um die Standard-Vorlage immer als "Standard" zu speichern,
286 // obwohl der fuer den Benutzer sichtbare Name uebersetzt ist:
288 const String& ScStyleSheet::GetName() const
290 const String& rBase = SfxStyleSheet::GetName();
291 const String* pForceStdName = ((ScStyleSheetPool&)rPool).GetForceStdName();
292 if ( pForceStdName && rBase == ScGlobal::GetRscString(STR_STYLENAME_STANDARD) )
293 return *pForceStdName;
294 else
295 return rBase;
298 const String& ScStyleSheet::GetParent() const
300 const String& rBase = SfxStyleSheet::GetParent();
301 const String* pForceStdName = ((ScStyleSheetPool&)rPool).GetForceStdName();
302 if ( pForceStdName && rBase == ScGlobal::GetRscString(STR_STYLENAME_STANDARD) )
303 return *pForceStdName;
304 else
305 return rBase;
308 const String& ScStyleSheet::GetFollow() const
310 const String& rBase = SfxStyleSheet::GetFollow();
311 const String* pForceStdName = ((ScStyleSheetPool&)rPool).GetForceStdName();
312 if ( pForceStdName && rBase == ScGlobal::GetRscString(STR_STYLENAME_STANDARD) )
313 return *pForceStdName;
314 else
315 return rBase;
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 String& rNew )
328 String aFileStdName = String::CreateFromAscii(RTL_CONSTASCII_STRINGPARAM(STRING_STANDARD));
329 if ( rNew == aFileStdName && aFileStdName != ScGlobal::GetRscString(STR_STYLENAME_STANDARD) )
330 return FALSE;
331 else
332 return SfxStyleSheet::SetName( rNew );