merge the formfield patch from ooo-build
[ooovba.git] / sc / source / core / data / stlsheet.cxx
blob22db96040d349d941c602f224a3909f58871d506
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"
57 #include <vcl/svapp.hxx> // GetSettings()
59 #include "globstr.hrc"
60 #include "sc.hrc"
61 //------------------------------------------------------------------------
63 TYPEINIT1(ScStyleSheet, SfxStyleSheet);
65 #define TWO_CM 1134
66 #define HFDIST_CM 142
68 //========================================================================
70 ScStyleSheet::ScStyleSheet( const String& rName,
71 ScStyleSheetPool& rPoolP,
72 SfxStyleFamily eFamily,
73 USHORT nMaskP )
75 : SfxStyleSheet ( rName, rPoolP, eFamily, nMaskP )
76 , eUsage( UNKNOWN )
80 //------------------------------------------------------------------------
82 ScStyleSheet::ScStyleSheet( const ScStyleSheet& rStyle )
83 : SfxStyleSheet ( rStyle )
84 , eUsage( UNKNOWN )
88 //------------------------------------------------------------------------
90 __EXPORT ScStyleSheet::~ScStyleSheet()
94 //------------------------------------------------------------------------
96 BOOL __EXPORT ScStyleSheet::HasFollowSupport() const
98 return FALSE;
101 //------------------------------------------------------------------------
103 BOOL __EXPORT ScStyleSheet::HasParentSupport () const
105 BOOL bHasParentSupport = FALSE;
107 switch ( GetFamily() )
109 case SFX_STYLE_FAMILY_PARA: bHasParentSupport = TRUE; break;
110 case SFX_STYLE_FAMILY_PAGE: bHasParentSupport = FALSE; break;
111 default:
113 // added to avoid warnings
117 return bHasParentSupport;
120 //------------------------------------------------------------------------
122 BOOL __EXPORT ScStyleSheet::SetParent( const String& rParentName )
124 BOOL bResult = FALSE;
125 String aEffName = rParentName;
126 SfxStyleSheetBase* pStyle = rPool.Find( aEffName, nFamily );
127 if (!pStyle)
129 SfxStyleSheetIterator* pIter = rPool.CreateIterator( nFamily, SFXSTYLEBIT_ALL );
130 pStyle = pIter->First();
131 if (pStyle)
132 aEffName = pStyle->GetName();
135 if ( pStyle && aEffName != GetName() )
137 bResult = SfxStyleSheet::SetParent( aEffName );
138 if (bResult)
140 SfxItemSet& rParentSet = pStyle->GetItemSet();
141 GetItemSet().SetParent( &rParentSet );
145 return bResult;
148 //------------------------------------------------------------------------
150 SfxItemSet& __EXPORT ScStyleSheet::GetItemSet()
152 if ( !pSet )
154 switch ( GetFamily() )
156 case SFX_STYLE_FAMILY_PAGE:
158 // Seitenvorlagen sollen nicht ableitbar sein,
159 // deshalb werden an dieser Stelle geeignete
160 // Werte eingestellt. (==Standard-Seitenvorlage)
162 SfxItemPool& rItemPool = GetPool().GetPool();
163 pSet = new SfxItemSet( rItemPool,
164 ATTR_BACKGROUND, ATTR_BACKGROUND,
165 ATTR_BORDER, ATTR_SHADOW,
166 ATTR_LRSPACE, ATTR_PAGE_SCALETO,
167 ATTR_WRITINGDIR, ATTR_WRITINGDIR,
168 ATTR_USERDEF, ATTR_USERDEF,
169 0 );
171 // Wenn gerade geladen wird, wird auch der Set hinterher aus der Datei
172 // gefuellt, es brauchen also keine Defaults gesetzt zu werden.
173 // GetPrinter wuerde dann auch einen neuen Printer anlegen, weil der
174 // gespeicherte Printer noch nicht geladen ist!
176 ScDocument* pDoc = ((ScStyleSheetPool&)GetPool()).GetDocument();
177 if ( pDoc && pDoc->IsLoadingDone() )
179 // Setzen von sinnvollen Default-Werten:
180 SvxPageItem aPageItem( ATTR_PAGE );
181 SvxSizeItem aPaperSizeItem( ATTR_PAGE_SIZE, SvxPaperInfo::GetDefaultPaperSize() );
183 SvxSetItem aHFSetItem(
184 (const SvxSetItem&)
185 rItemPool.GetDefaultItem(ATTR_PAGE_HEADERSET) );
187 SfxItemSet& rHFSet = aHFSetItem.GetItemSet();
188 SvxSizeItem aHFSizeItem( // 0,5 cm + Abstand
189 ATTR_PAGE_SIZE,
190 Size( 0, (long)( 500 / HMM_PER_TWIPS ) + HFDIST_CM ) );
192 SvxULSpaceItem aHFDistItem ( HFDIST_CM,// nUp
193 HFDIST_CM,// nLow
194 ATTR_ULSPACE );
196 SvxLRSpaceItem aLRSpaceItem( TWO_CM, // nLeft
197 TWO_CM, // nRight
198 TWO_CM, // nTLeft
199 0, // nFirstLineOffset
200 ATTR_LRSPACE );
201 SvxULSpaceItem aULSpaceItem( TWO_CM, // nUp
202 TWO_CM, // nLow
203 ATTR_ULSPACE );
204 SvxBoxInfoItem aBoxInfoItem( ATTR_BORDER_INNER );
206 aBoxInfoItem.SetTable( FALSE );
207 aBoxInfoItem.SetDist( TRUE );
208 aBoxInfoItem.SetValid( VALID_DISTANCE, TRUE );
210 // aPageItem.SetLandscape( ORIENTATION_LANDSCAPE == pPrinter->GetOrientation() );
211 aPageItem.SetLandscape( FALSE );
213 rHFSet.Put( aBoxInfoItem );
214 rHFSet.Put( aHFSizeItem );
215 rHFSet.Put( aHFDistItem );
216 rHFSet.Put( SvxLRSpaceItem( 0,0,0,0, ATTR_LRSPACE ) ); // Rand auf Null setzen
218 pSet->Put( aHFSetItem, ATTR_PAGE_HEADERSET );
219 pSet->Put( aHFSetItem, ATTR_PAGE_FOOTERSET );
220 pSet->Put( aBoxInfoItem ); // PoolDefault wg. Formatvorlagen
221 // nicht ueberschreiben!
223 // Writing direction: not as pool default because the default for cells
224 // must remain FRMDIR_ENVIRONMENT, and each page style's setting is
225 // supposed to be saved in the file format.
226 // The page default depends on the system language.
227 SvxFrameDirection eDirection = ScGlobal::IsSystemRTL() ?
228 FRMDIR_HORI_RIGHT_TOP : FRMDIR_HORI_LEFT_TOP;
229 pSet->Put( SvxFrameDirectionItem( eDirection, ATTR_WRITINGDIR ), ATTR_WRITINGDIR );
231 rItemPool.SetPoolDefaultItem( aPageItem );
232 rItemPool.SetPoolDefaultItem( aPaperSizeItem );
233 rItemPool.SetPoolDefaultItem( aLRSpaceItem );
234 rItemPool.SetPoolDefaultItem( aULSpaceItem );
235 rItemPool.SetPoolDefaultItem( SfxUInt16Item( ATTR_PAGE_SCALE, 100 ) );
236 ScPageScaleToItem aScaleToItem;
237 rItemPool.SetPoolDefaultItem( aScaleToItem );
238 rItemPool.SetPoolDefaultItem( SfxUInt16Item( ATTR_PAGE_SCALETOPAGES, 0 ) );
241 break;
243 case SFX_STYLE_FAMILY_PARA:
244 default:
245 pSet = new SfxItemSet( GetPool().GetPool(),
246 ATTR_PATTERN_START, ATTR_PATTERN_END,
247 0 );
248 break;
250 bMySet = TRUE;
251 } // if ( !pSet )
252 if ( nHelpId == HID_SC_SHEET_CELL_ERG1 )
254 if ( !pSet->Count() )
256 ScDocument* pDoc = ((ScStyleSheetPool&)GetPool()).GetDocument();
257 if ( pDoc )
259 ULONG nNumFmt = pDoc->GetFormatTable()->GetStandardFormat( NUMBERFORMAT_CURRENCY,ScGlobal::eLnge );
260 pSet->Put( SfxUInt32Item( ATTR_VALUE_FORMAT, nNumFmt ) );
261 } // if ( pDoc && pDoc->IsLoadingDone() )
265 return *pSet;
268 //------------------------------------------------------------------------
270 BOOL __EXPORT ScStyleSheet::IsUsed() const
272 if ( GetFamily() == SFX_STYLE_FAMILY_PARA )
274 // Always query the document to let it decide if a rescan is necessary,
275 // and store the state.
276 ScDocument* pDoc = ((ScStyleSheetPool&)rPool).GetDocument();
277 if ( pDoc && pDoc->IsStyleSheetUsed( *this, TRUE ) )
278 eUsage = USED;
279 else
280 eUsage = NOTUSED;
281 return eUsage == USED;
283 else
284 return TRUE;
287 //------------------------------------------------------------------------
289 void __EXPORT ScStyleSheet::Notify( SfxBroadcaster&, const SfxHint& rHint )
291 if ( rHint.ISA(SfxSimpleHint) )
292 if ( ((SfxSimpleHint&)rHint).GetId() == SFX_HINT_DYING )
293 GetItemSet().SetParent( NULL );
296 //------------------------------------------------------------------------
298 // #66123# schmutzige Tricks, um die Standard-Vorlage immer als "Standard" zu speichern,
299 // obwohl der fuer den Benutzer sichtbare Name uebersetzt ist:
301 const String& ScStyleSheet::GetName() const
303 const String& rBase = SfxStyleSheet::GetName();
304 const String* pForceStdName = ((ScStyleSheetPool&)rPool).GetForceStdName();
305 if ( pForceStdName && rBase == ScGlobal::GetRscString(STR_STYLENAME_STANDARD) )
306 return *pForceStdName;
307 else
308 return rBase;
311 const String& ScStyleSheet::GetParent() const
313 const String& rBase = SfxStyleSheet::GetParent();
314 const String* pForceStdName = ((ScStyleSheetPool&)rPool).GetForceStdName();
315 if ( pForceStdName && rBase == ScGlobal::GetRscString(STR_STYLENAME_STANDARD) )
316 return *pForceStdName;
317 else
318 return rBase;
321 const String& ScStyleSheet::GetFollow() const
323 const String& rBase = SfxStyleSheet::GetFollow();
324 const String* pForceStdName = ((ScStyleSheetPool&)rPool).GetForceStdName();
325 if ( pForceStdName && rBase == ScGlobal::GetRscString(STR_STYLENAME_STANDARD) )
326 return *pForceStdName;
327 else
328 return rBase;
331 // Verhindern, dass ein Style "Standard" angelegt wird, wenn das nicht der
332 // Standard-Name ist, weil sonst beim Speichern zwei Styles denselben Namen haetten
333 // (Beim Laden wird der Style direkt per Make mit dem Namen erzeugt, so dass diese
334 // Abfrage dann nicht gilt)
335 //! Wenn irgendwann aus dem Laden SetName aufgerufen wird, muss fuer das Laden ein
336 //! Flag gesetzt und abgefragt werden.
337 //! Die ganze Abfrage muss raus, wenn fuer eine neue Datei-Version die Namens-Umsetzung wegfaellt.
339 BOOL ScStyleSheet::SetName( const String& rNew )
341 String aFileStdName = String::CreateFromAscii(RTL_CONSTASCII_STRINGPARAM(STRING_STANDARD));
342 if ( rNew == aFileStdName && aFileStdName != ScGlobal::GetRscString(STR_STYLENAME_STANDARD) )
343 return FALSE;
344 else
345 return SfxStyleSheet::SetName( rNew );