xref: /AOO41X/main/sc/source/core/data/stlsheet.cxx (revision 49bd4d4b0041a732963ad6f2f737c048ee2652b5)
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 
ScStyleSheet(const String & rName,ScStyleSheetPool & rPoolP,SfxStyleFamily eFamily,sal_uInt16 nMaskP)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 
ScStyleSheet(const ScStyleSheet & rStyle)75 ScStyleSheet::ScStyleSheet( const ScStyleSheet& rStyle )
76     : SfxStyleSheet ( rStyle )
77     , eUsage( UNKNOWN )
78 {
79 }
80 
81 //------------------------------------------------------------------------
82 
~ScStyleSheet()83 __EXPORT ScStyleSheet::~ScStyleSheet()
84 {
85 }
86 
87 //------------------------------------------------------------------------
88 
HasFollowSupport() const89 sal_Bool __EXPORT ScStyleSheet::HasFollowSupport() const
90 {
91     return sal_False;
92 }
93 
94 //------------------------------------------------------------------------
95 
HasParentSupport() const96 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 
SetParent(const String & rParentName)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         SfxStyleSheetIteratorPtr pIter = rPool.CreateIterator( nFamily, SFXSTYLEBIT_ALL );
123         pStyle = pIter->First();
124         if (pStyle)
125             aEffName = pStyle->GetName();
126     }
127 
128     if ( pStyle && aEffName != GetName() )
129     {
130         bResult = SfxStyleSheet::SetParent( aEffName );
131         if (bResult)
132         {
133             SfxItemSet& rParentSet = pStyle->GetItemSet();
134             GetItemSet().SetParent( &rParentSet );
135 
136             // #i113491# Drag&Drop in the stylist's hierarchical view doesn't execute a slot,
137             // so the repaint has to come from here (after modifying the ItemSet).
138             // RepaintRange checks the document's IsVisible flag and locked repaints.
139             ScDocument* pDoc = static_cast<ScStyleSheetPool&>(GetPool()).GetDocument();
140             if (pDoc)
141                 pDoc->RepaintRange( ScRange( 0,0,0, MAXCOL,MAXROW,MAXTAB ) );
142         }
143     }
144 
145     return bResult;
146 }
147 
148 //------------------------------------------------------------------------
149 
GetItemSet()150 SfxItemSet& __EXPORT ScStyleSheet::GetItemSet()
151 {
152     if ( !pSet )
153     {
154         switch ( GetFamily() )
155         {
156             case SFX_STYLE_FAMILY_PAGE:
157                 {
158                     // Seitenvorlagen sollen nicht ableitbar sein,
159                     // deshalb werden an dieser Stelle geeignete
160                     // Werte eingestellt. (==Standard-Seitenvorlage)
161 
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 );
170 
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!
175 
176                     ScDocument* pDoc = ((ScStyleSheetPool&)GetPool()).GetDocument();
177                     if ( pDoc )
178                     {
179                         // Setzen von sinnvollen Default-Werten:
180                         SvxPageItem     aPageItem( ATTR_PAGE );
181                         SvxSizeItem     aPaperSizeItem( ATTR_PAGE_SIZE, SvxPaperInfo::GetDefaultPaperSize() );
182 
183                         SvxSetItem      aHFSetItem(
184                                             (const SvxSetItem&)
185                                             rItemPool.GetDefaultItem(ATTR_PAGE_HEADERSET) );
186 
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 ) );
191 
192                         SvxULSpaceItem  aHFDistItem ( HFDIST_CM,// nUp
193                                                       HFDIST_CM,// nLow
194                                                       ATTR_ULSPACE );
195 
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 );
205 
206                         aBoxInfoItem.SetTable( sal_False );
207                         aBoxInfoItem.SetDist( sal_True );
208                         aBoxInfoItem.SetValid( VALID_DISTANCE, sal_True );
209 
210                         // aPageItem.SetLandscape( ORIENTATION_LANDSCAPE == pPrinter->GetOrientation() );
211                         aPageItem.SetLandscape( sal_False );
212 
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
217 
218                         pSet->Put( aHFSetItem, ATTR_PAGE_HEADERSET );
219                         pSet->Put( aHFSetItem, ATTR_PAGE_FOOTERSET );
220                         pSet->Put( aBoxInfoItem ); // PoolDefault wg. Formatvorlagen
221                                                    // nicht ueberschreiben!
222 
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 );
230 
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 ) );
239                     }
240                 }
241                 break;
242 
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;
249         }
250         bMySet = sal_True;
251     } // if ( !pSet )
252     if ( nHelpId == HID_SC_SHEET_CELL_ERG1 )
253     {
254         if ( !pSet->Count() )
255         {
256             ScDocument* pDoc = ((ScStyleSheetPool&)GetPool()).GetDocument();
257             if ( pDoc )
258             {
259                 sal_uLong nNumFmt = pDoc->GetFormatTable()->GetStandardFormat( NUMBERFORMAT_CURRENCY,ScGlobal::eLnge );
260                 pSet->Put( SfxUInt32Item( ATTR_VALUE_FORMAT, nNumFmt ) );
261             } // if ( pDoc && pDoc->IsLoadingDone() )
262         }
263     }
264 
265     return *pSet;
266 }
267 
268 //------------------------------------------------------------------------
269 
IsUsed() const270 sal_Bool __EXPORT ScStyleSheet::IsUsed() const
271 {
272     if ( GetFamily() == SFX_STYLE_FAMILY_PARA )
273     {
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, sal_True ) )
278             eUsage = USED;
279         else
280             eUsage = NOTUSED;
281         return eUsage == USED;
282     }
283     else
284         return sal_True;
285 }
286 
287 //------------------------------------------------------------------------
288 
Notify(SfxBroadcaster &,const SfxHint & rHint)289 void __EXPORT ScStyleSheet::Notify( SfxBroadcaster&, const SfxHint& rHint )
290 {
291     if ( rHint.ISA(SfxSimpleHint) )
292         if ( ((SfxSimpleHint&)rHint).GetId() == SFX_HINT_DYING )
293             GetItemSet().SetParent( NULL );
294 }
295 
296 //------------------------------------------------------------------------
297 
298 //  #66123# schmutzige Tricks, um die Standard-Vorlage immer als "Standard" zu speichern,
299 //  obwohl der fuer den Benutzer sichtbare Name uebersetzt ist:
300 
GetName() const301 const String& ScStyleSheet::GetName() const
302 {
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;
309 }
310 
GetParent() const311 const String& ScStyleSheet::GetParent() const
312 {
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;
319 }
320 
GetFollow() const321 const String& ScStyleSheet::GetFollow() const
322 {
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;
329 }
330 
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.
338 
SetName(const String & rNew)339 sal_Bool ScStyleSheet::SetName( const String& rNew )
340 {
341     String aFileStdName = String::CreateFromAscii(RTL_CONSTASCII_STRINGPARAM(STRING_STANDARD));
342     if ( rNew == aFileStdName && aFileStdName != ScGlobal::GetRscString(STR_STYLENAME_STANDARD) )
343         return sal_False;
344     else
345         return SfxStyleSheet::SetName( rNew );
346 }
347 
348 
349 
350