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