Line data Source code
1 : /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 : /*
3 : * This file is part of the LibreOffice project.
4 : *
5 : * This Source Code Form is subject to the terms of the Mozilla Public
6 : * License, v. 2.0. If a copy of the MPL was not distributed with this
7 : * file, You can obtain one at http://mozilla.org/MPL/2.0/.
8 : *
9 : * This file incorporates work covered by the following license notice:
10 : *
11 : * Licensed to the Apache Software Foundation (ASF) under one or more
12 : * contributor license agreements. See the NOTICE file distributed
13 : * with this work for additional information regarding copyright
14 : * ownership. The ASF licenses this file to you under the Apache
15 : * License, Version 2.0 (the "License"); you may not use this file
16 : * except in compliance with the License. You may obtain a copy of
17 : * the License at http://www.apache.org/licenses/LICENSE-2.0 .
18 : */
19 :
20 : #include "scitems.hxx"
21 : #include <editeng/adjustitem.hxx>
22 : #include <svx/algitem.hxx>
23 : #include <editeng/boxitem.hxx>
24 : #include <editeng/lineitem.hxx>
25 : #include <editeng/brushitem.hxx>
26 : #include <editeng/charreliefitem.hxx>
27 : #include <editeng/contouritem.hxx>
28 : #include <svtools/colorcfg.hxx>
29 : #include <editeng/colritem.hxx>
30 : #include <editeng/crossedoutitem.hxx>
31 : #include <editeng/emphasismarkitem.hxx>
32 : #include <editeng/fhgtitem.hxx>
33 : #include <editeng/fontitem.hxx>
34 : #include <editeng/forbiddenruleitem.hxx>
35 : #include <editeng/frmdiritem.hxx>
36 : #include <editeng/langitem.hxx>
37 : #include <editeng/postitem.hxx>
38 : #include <svx/rotmodit.hxx>
39 : #include <editeng/scriptspaceitem.hxx>
40 : #include <editeng/scripttypeitem.hxx>
41 : #include <editeng/shaditem.hxx>
42 : #include <editeng/shdditem.hxx>
43 : #include <editeng/udlnitem.hxx>
44 : #include <editeng/wghtitem.hxx>
45 : #include <editeng/wrlmitem.hxx>
46 : #include <editeng/justifyitem.hxx>
47 : #include <svl/intitem.hxx>
48 : #include <svl/zforlist.hxx>
49 : #include <vcl/outdev.hxx>
50 : #include <vcl/svapp.hxx>
51 : #include <tools/fract.hxx>
52 :
53 : #include "patattr.hxx"
54 : #include "docpool.hxx"
55 : #include "stlsheet.hxx"
56 : #include "stlpool.hxx"
57 : #include "document.hxx"
58 : #include "global.hxx"
59 : #include "globstr.hrc"
60 : #include "conditio.hxx"
61 : #include "validat.hxx"
62 : #include "scmod.hxx"
63 : #include "fillinfo.hxx"
64 :
65 : // STATIC DATA -----------------------------------------------------------
66 :
67 : using sc::HMMToTwips;
68 : using sc::TwipsToHMM;
69 :
70 1378 : ScPatternAttr::ScPatternAttr( SfxItemSet* pItemSet, const OUString& rStyleName )
71 : : SfxSetItem ( ATTR_PATTERN, pItemSet ),
72 1378 : pName ( new OUString( rStyleName ) ),
73 2756 : pStyle ( NULL )
74 : {
75 1378 : }
76 :
77 141333 : ScPatternAttr::ScPatternAttr( SfxItemSet* pItemSet, ScStyleSheet* pStyleSheet )
78 : : SfxSetItem ( ATTR_PATTERN, pItemSet ),
79 : pName ( NULL ),
80 141333 : pStyle ( pStyleSheet )
81 : {
82 141333 : if ( pStyleSheet )
83 0 : GetItemSet().SetParent( &pStyleSheet->GetItemSet() );
84 141333 : }
85 :
86 4001 : ScPatternAttr::ScPatternAttr( SfxItemPool* pItemPool )
87 4001 : : SfxSetItem ( ATTR_PATTERN, new SfxItemSet( *pItemPool, ATTR_PATTERN_START, ATTR_PATTERN_END ) ),
88 : pName ( NULL ),
89 8002 : pStyle ( NULL )
90 : {
91 4001 : }
92 :
93 424737 : ScPatternAttr::ScPatternAttr( const ScPatternAttr& rPatternAttr )
94 : : SfxSetItem ( rPatternAttr ),
95 424737 : pStyle ( rPatternAttr.pStyle )
96 : {
97 424737 : if (rPatternAttr.pName)
98 792 : pName = new OUString(*rPatternAttr.pName);
99 : else
100 423945 : pName = NULL;
101 424737 : }
102 :
103 1701970 : ScPatternAttr::~ScPatternAttr()
104 : {
105 571227 : delete pName;
106 1130743 : }
107 :
108 124272 : SfxPoolItem* ScPatternAttr::Clone( SfxItemPool *pPool ) const
109 : {
110 124272 : ScPatternAttr* pPattern = new ScPatternAttr( GetItemSet().Clone(true, pPool) );
111 :
112 124272 : pPattern->pStyle = pStyle;
113 124272 : pPattern->pName = pName ? new OUString(*pName) : NULL;
114 :
115 124272 : return pPattern;
116 : }
117 :
118 659712 : inline bool StrCmp( const OUString* pStr1, const OUString* pStr2 )
119 : {
120 659712 : return ( pStr1 ? ( pStr2 && ( *pStr1 == *pStr2 ) ) : ( pStr2 == nullptr ) );
121 : }
122 :
123 8148325 : inline bool EqualPatternSets( const SfxItemSet& rSet1, const SfxItemSet& rSet2 )
124 : {
125 : // #i62090# The SfxItemSet in the SfxSetItem base class always has the same ranges
126 : // (single range from ATTR_PATTERN_START to ATTR_PATTERN_END), and the items are pooled,
127 : // so it's enough to compare just the pointers (Count just because it's even faster).
128 :
129 8148325 : if ( rSet1.Count() != rSet2.Count() )
130 6712390 : return false;
131 :
132 1435935 : SfxItemArray pItems1 = rSet1.GetItems_Impl(); // inline method of SfxItemSet
133 1435935 : SfxItemArray pItems2 = rSet2.GetItems_Impl();
134 :
135 1435935 : return ( 0 == memcmp( pItems1, pItems2, (ATTR_PATTERN_END - ATTR_PATTERN_START + 1) * sizeof(pItems1[0]) ) );
136 : }
137 :
138 8148325 : bool ScPatternAttr::operator==( const SfxPoolItem& rCmp ) const
139 : {
140 : // #i62090# Use quick comparison between ScPatternAttr's ItemSets
141 :
142 8808037 : return ( EqualPatternSets( GetItemSet(), static_cast<const ScPatternAttr&>(rCmp).GetItemSet() ) &&
143 8808037 : StrCmp( GetStyleName(), static_cast<const ScPatternAttr&>(rCmp).GetStyleName() ) );
144 : }
145 :
146 0 : SfxPoolItem* ScPatternAttr::Create( SvStream& rStream, sal_uInt16 /* nVersion */ ) const
147 : {
148 : OUString* pStr;
149 : bool bHasStyle;
150 :
151 0 : rStream.ReadCharAsBool( bHasStyle );
152 :
153 0 : if ( bHasStyle )
154 : {
155 : short eFamDummy;
156 0 : pStr = new OUString;
157 0 : *pStr = rStream.ReadUniOrByteString( rStream.GetStreamCharSet() );
158 0 : rStream.ReadInt16( eFamDummy ); // due to old data format
159 : }
160 : else
161 0 : pStr = new OUString( ScGlobal::GetRscString(STR_STYLENAME_STANDARD) );
162 :
163 0 : SfxItemSet *pNewSet = new SfxItemSet( *GetItemSet().GetPool(),
164 0 : ATTR_PATTERN_START, ATTR_PATTERN_END );
165 0 : pNewSet->Load( rStream );
166 :
167 0 : ScPatternAttr* pPattern = new ScPatternAttr( pNewSet );
168 :
169 0 : pPattern->pName = pStr;
170 :
171 0 : return pPattern;
172 : }
173 :
174 0 : SvStream& ScPatternAttr::Store(SvStream& rStream, sal_uInt16 /* nItemVersion */) const
175 : {
176 0 : rStream.WriteBool( true );
177 :
178 0 : if ( pStyle )
179 0 : rStream.WriteUniOrByteString( pStyle->GetName(), rStream.GetStreamCharSet() );
180 0 : else if ( pName ) // when style is/was deleted
181 0 : rStream.WriteUniOrByteString( *pName, rStream.GetStreamCharSet() );
182 : else
183 0 : rStream.WriteUniOrByteString( ScGlobal::GetRscString(STR_STYLENAME_STANDARD),
184 0 : rStream.GetStreamCharSet() );
185 :
186 0 : rStream.WriteInt16( SFX_STYLE_FAMILY_PARA ); // due to old data format
187 :
188 0 : GetItemSet().Store( rStream );
189 :
190 0 : return rStream;
191 : }
192 :
193 1287601 : SvxCellOrientation ScPatternAttr::GetCellOrientation( const SfxItemSet& rItemSet, const SfxItemSet* pCondSet )
194 : {
195 1287601 : SvxCellOrientation eOrient = SVX_ORIENTATION_STANDARD;
196 :
197 1287601 : if( static_cast<const SfxBoolItem&>(GetItem( ATTR_STACKED, rItemSet, pCondSet )).GetValue() )
198 : {
199 96205 : eOrient = SVX_ORIENTATION_STACKED;
200 : }
201 : else
202 : {
203 1191396 : sal_Int32 nAngle = static_cast<const SfxInt32Item&>(GetItem( ATTR_ROTATE_VALUE, rItemSet, pCondSet )).GetValue();
204 1191396 : if( nAngle == 9000 )
205 2 : eOrient = SVX_ORIENTATION_BOTTOMTOP;
206 1191394 : else if( nAngle == 27000 )
207 350 : eOrient = SVX_ORIENTATION_TOPBOTTOM;
208 : }
209 :
210 1287601 : return eOrient;
211 : }
212 :
213 1287601 : SvxCellOrientation ScPatternAttr::GetCellOrientation( const SfxItemSet* pCondSet ) const
214 : {
215 1287601 : return GetCellOrientation( GetItemSet(), pCondSet );
216 : }
217 :
218 : namespace {
219 :
220 10616 : void getFontIDsByScriptType(SvtScriptType nScript,
221 : sal_uInt16& nFontId, sal_uInt16& nHeightId, sal_uInt16& nWeightId, sal_uInt16& nPostureId, sal_uInt16& nLangId)
222 : {
223 10616 : if ( nScript == SvtScriptType::ASIAN )
224 : {
225 2 : nFontId = ATTR_CJK_FONT;
226 2 : nHeightId = ATTR_CJK_FONT_HEIGHT;
227 2 : nWeightId = ATTR_CJK_FONT_WEIGHT;
228 2 : nPostureId = ATTR_CJK_FONT_POSTURE;
229 2 : nLangId = ATTR_CJK_FONT_LANGUAGE;
230 : }
231 10614 : else if ( nScript == SvtScriptType::COMPLEX )
232 : {
233 0 : nFontId = ATTR_CTL_FONT;
234 0 : nHeightId = ATTR_CTL_FONT_HEIGHT;
235 0 : nWeightId = ATTR_CTL_FONT_WEIGHT;
236 0 : nPostureId = ATTR_CTL_FONT_POSTURE;
237 0 : nLangId = ATTR_CTL_FONT_LANGUAGE;
238 : }
239 : else
240 : {
241 10614 : nFontId = ATTR_FONT;
242 10614 : nHeightId = ATTR_FONT_HEIGHT;
243 10614 : nWeightId = ATTR_FONT_WEIGHT;
244 10614 : nPostureId = ATTR_FONT_POSTURE;
245 10614 : nLangId = ATTR_FONT_LANGUAGE;
246 : }
247 10616 : }
248 :
249 : }
250 :
251 10606 : void ScPatternAttr::GetFont(
252 : vcl::Font& rFont, const SfxItemSet& rItemSet, ScAutoFontColorMode eAutoMode,
253 : OutputDevice* pOutDev, const Fraction* pScale,
254 : const SfxItemSet* pCondSet, SvtScriptType nScript,
255 : const Color* pBackConfigColor, const Color* pTextConfigColor )
256 : {
257 : // Read items
258 :
259 : const SvxFontItem* pFontAttr;
260 : sal_uInt32 nFontHeight;
261 : FontWeight eWeight;
262 : FontItalic eItalic;
263 : FontUnderline eUnder;
264 : FontUnderline eOver;
265 : bool bWordLine;
266 : FontStrikeout eStrike;
267 : bool bOutline;
268 : bool bShadow;
269 : FontEmphasisMark eEmphasis;
270 : FontRelief eRelief;
271 10606 : Color aColor;
272 : LanguageType eLang;
273 :
274 : sal_uInt16 nFontId, nHeightId, nWeightId, nPostureId, nLangId;
275 10606 : getFontIDsByScriptType(nScript, nFontId, nHeightId, nWeightId, nPostureId, nLangId);
276 :
277 10606 : if ( pCondSet )
278 : {
279 : const SfxPoolItem* pItem;
280 :
281 2 : if ( pCondSet->GetItemState( nFontId, true, &pItem ) != SfxItemState::SET )
282 2 : pItem = &rItemSet.Get( nFontId );
283 2 : pFontAttr = static_cast<const SvxFontItem*>(pItem);
284 :
285 2 : if ( pCondSet->GetItemState( nHeightId, true, &pItem ) != SfxItemState::SET )
286 2 : pItem = &rItemSet.Get( nHeightId );
287 2 : nFontHeight = static_cast<const SvxFontHeightItem*>(pItem)->GetHeight();
288 :
289 2 : if ( pCondSet->GetItemState( nWeightId, true, &pItem ) != SfxItemState::SET )
290 0 : pItem = &rItemSet.Get( nWeightId );
291 2 : eWeight = (FontWeight)static_cast<const SvxWeightItem*>(pItem)->GetValue();
292 :
293 2 : if ( pCondSet->GetItemState( nPostureId, true, &pItem ) != SfxItemState::SET )
294 0 : pItem = &rItemSet.Get( nPostureId );
295 2 : eItalic = (FontItalic)static_cast<const SvxPostureItem*>(pItem)->GetValue();
296 :
297 2 : if ( pCondSet->GetItemState( ATTR_FONT_UNDERLINE, true, &pItem ) != SfxItemState::SET )
298 0 : pItem = &rItemSet.Get( ATTR_FONT_UNDERLINE );
299 2 : eUnder = (FontUnderline)static_cast<const SvxUnderlineItem*>(pItem)->GetValue();
300 :
301 2 : if ( pCondSet->GetItemState( ATTR_FONT_OVERLINE, true, &pItem ) != SfxItemState::SET )
302 2 : pItem = &rItemSet.Get( ATTR_FONT_OVERLINE );
303 2 : eOver = (FontUnderline)static_cast<const SvxOverlineItem*>(pItem)->GetValue();
304 :
305 2 : if ( pCondSet->GetItemState( ATTR_FONT_WORDLINE, true, &pItem ) != SfxItemState::SET )
306 2 : pItem = &rItemSet.Get( ATTR_FONT_WORDLINE );
307 2 : bWordLine = static_cast<const SvxWordLineModeItem*>(pItem)->GetValue();
308 :
309 2 : if ( pCondSet->GetItemState( ATTR_FONT_CROSSEDOUT, true, &pItem ) != SfxItemState::SET )
310 2 : pItem = &rItemSet.Get( ATTR_FONT_CROSSEDOUT );
311 2 : eStrike = (FontStrikeout)static_cast<const SvxCrossedOutItem*>(pItem)->GetValue();
312 :
313 2 : if ( pCondSet->GetItemState( ATTR_FONT_CONTOUR, true, &pItem ) != SfxItemState::SET )
314 2 : pItem = &rItemSet.Get( ATTR_FONT_CONTOUR );
315 2 : bOutline = static_cast<const SvxContourItem*>(pItem)->GetValue();
316 :
317 2 : if ( pCondSet->GetItemState( ATTR_FONT_SHADOWED, true, &pItem ) != SfxItemState::SET )
318 2 : pItem = &rItemSet.Get( ATTR_FONT_SHADOWED );
319 2 : bShadow = static_cast<const SvxShadowedItem*>(pItem)->GetValue();
320 :
321 2 : if ( pCondSet->GetItemState( ATTR_FONT_EMPHASISMARK, true, &pItem ) != SfxItemState::SET )
322 2 : pItem = &rItemSet.Get( ATTR_FONT_EMPHASISMARK );
323 2 : eEmphasis = static_cast<const SvxEmphasisMarkItem*>(pItem)->GetEmphasisMark();
324 :
325 2 : if ( pCondSet->GetItemState( ATTR_FONT_RELIEF, true, &pItem ) != SfxItemState::SET )
326 2 : pItem = &rItemSet.Get( ATTR_FONT_RELIEF );
327 2 : eRelief = (FontRelief)static_cast<const SvxCharReliefItem*>(pItem)->GetValue();
328 :
329 2 : if ( pCondSet->GetItemState( ATTR_FONT_COLOR, true, &pItem ) != SfxItemState::SET )
330 2 : pItem = &rItemSet.Get( ATTR_FONT_COLOR );
331 2 : aColor = static_cast<const SvxColorItem*>(pItem)->GetValue();
332 :
333 2 : if ( pCondSet->GetItemState( nLangId, true, &pItem ) != SfxItemState::SET )
334 2 : pItem = &rItemSet.Get( nLangId );
335 2 : eLang = static_cast<const SvxLanguageItem*>(pItem)->GetLanguage();
336 : }
337 : else // Everything from rItemSet
338 : {
339 10604 : pFontAttr = &static_cast<const SvxFontItem&>(rItemSet.Get( nFontId ));
340 : nFontHeight = static_cast<const SvxFontHeightItem&>(
341 10604 : rItemSet.Get( nHeightId )).GetHeight();
342 : eWeight = (FontWeight)static_cast<const SvxWeightItem&>(
343 10604 : rItemSet.Get( nWeightId )).GetValue();
344 : eItalic = (FontItalic)static_cast<const SvxPostureItem&>(
345 10604 : rItemSet.Get( nPostureId )).GetValue();
346 : eUnder = (FontUnderline)static_cast<const SvxUnderlineItem&>(
347 10604 : rItemSet.Get( ATTR_FONT_UNDERLINE )).GetValue();
348 : eOver = (FontUnderline)static_cast<const SvxOverlineItem&>(
349 10604 : rItemSet.Get( ATTR_FONT_OVERLINE )).GetValue();
350 : bWordLine = static_cast<const SvxWordLineModeItem&>(
351 10604 : rItemSet.Get( ATTR_FONT_WORDLINE )).GetValue();
352 : eStrike = (FontStrikeout)static_cast<const SvxCrossedOutItem&>(
353 10604 : rItemSet.Get( ATTR_FONT_CROSSEDOUT )).GetValue();
354 : bOutline = static_cast<const SvxContourItem&>(
355 10604 : rItemSet.Get( ATTR_FONT_CONTOUR )).GetValue();
356 : bShadow = static_cast<const SvxShadowedItem&>(
357 10604 : rItemSet.Get( ATTR_FONT_SHADOWED )).GetValue();
358 : eEmphasis = static_cast<const SvxEmphasisMarkItem&>(
359 10604 : rItemSet.Get( ATTR_FONT_EMPHASISMARK )).GetEmphasisMark();
360 : eRelief = (FontRelief)static_cast<const SvxCharReliefItem&>(
361 10604 : rItemSet.Get( ATTR_FONT_RELIEF )).GetValue();
362 : aColor = static_cast<const SvxColorItem&>(
363 10604 : rItemSet.Get( ATTR_FONT_COLOR )).GetValue();
364 : // for graphite language features
365 10604 : eLang = static_cast<const SvxLanguageItem&>(rItemSet.Get( nLangId )).GetLanguage();
366 : }
367 : OSL_ENSURE(pFontAttr,"Oops?");
368 :
369 : // Evaluate
370 :
371 : // FontItem:
372 :
373 10606 : if (rFont.GetName() != pFontAttr->GetFamilyName())
374 6457 : rFont.SetName( pFontAttr->GetFamilyName() );
375 10606 : if (rFont.GetStyleName() != pFontAttr->GetStyleName())
376 1598 : rFont.SetStyleName( pFontAttr->GetStyleName() );
377 :
378 10606 : rFont.SetFamily( pFontAttr->GetFamily() );
379 10606 : rFont.SetCharSet( pFontAttr->GetCharSet() );
380 10606 : rFont.SetPitch( pFontAttr->GetPitch() );
381 :
382 10606 : rFont.SetLanguage(eLang);
383 :
384 : // Size
385 :
386 10606 : if ( pOutDev != NULL )
387 : {
388 9771 : Size aEffSize;
389 9771 : Fraction aFraction( 1,1 );
390 9771 : if (pScale)
391 7479 : aFraction = *pScale;
392 9771 : Size aSize( 0, (long) nFontHeight );
393 19542 : MapMode aDestMode = pOutDev->GetMapMode();
394 19542 : MapMode aSrcMode( MAP_TWIP, Point(), aFraction, aFraction );
395 9771 : if (aDestMode.GetMapUnit() == MAP_PIXEL && pOutDev->GetDPIX() > 0)
396 9726 : aEffSize = pOutDev->LogicToPixel( aSize, aSrcMode );
397 : else
398 : {
399 45 : Fraction aFractOne(1,1);
400 45 : aDestMode.SetScaleX( aFractOne );
401 45 : aDestMode.SetScaleY( aFractOne );
402 45 : aEffSize = OutputDevice::LogicToLogic( aSize, aSrcMode, aDestMode );
403 : }
404 19542 : rFont.SetSize( aEffSize );
405 : }
406 : else /* if pOutDev != NULL */
407 : {
408 835 : rFont.SetSize( Size( 0, (long) nFontHeight ) );
409 : }
410 :
411 : // determine effective font color
412 :
413 29120 : if ( ( aColor.GetColor() == COL_AUTO && eAutoMode != SC_AUTOCOL_RAW ) ||
414 13613 : eAutoMode == SC_AUTOCOL_IGNOREFONT || eAutoMode == SC_AUTOCOL_IGNOREALL )
415 : {
416 7599 : if ( eAutoMode == SC_AUTOCOL_BLACK )
417 2720 : aColor.SetColor( COL_BLACK );
418 : else
419 : {
420 : // get background color from conditional or own set
421 4879 : Color aBackColor;
422 4879 : if ( pCondSet )
423 : {
424 : const SfxPoolItem* pItem;
425 2 : if ( pCondSet->GetItemState( ATTR_BACKGROUND, true, &pItem ) != SfxItemState::SET )
426 2 : pItem = &rItemSet.Get( ATTR_BACKGROUND );
427 2 : aBackColor = static_cast<const SvxBrushItem*>(pItem)->GetColor();
428 : }
429 : else
430 4877 : aBackColor = static_cast<const SvxBrushItem&>(rItemSet.Get( ATTR_BACKGROUND )).GetColor();
431 :
432 : // if background color attribute is transparent, use window color for brightness comparisons
433 15898 : if ( aBackColor == COL_TRANSPARENT ||
434 15898 : eAutoMode == SC_AUTOCOL_IGNOREBACK || eAutoMode == SC_AUTOCOL_IGNOREALL )
435 : {
436 3618 : if ( eAutoMode == SC_AUTOCOL_PRINT )
437 5 : aBackColor.SetColor( COL_WHITE );
438 3613 : else if ( pBackConfigColor )
439 : {
440 : // pBackConfigColor can be used to avoid repeated lookup of the configured color
441 3607 : aBackColor = *pBackConfigColor;
442 : }
443 : else
444 6 : aBackColor.SetColor( SC_MOD()->GetColorConfig().GetColorValue(svtools::DOCCOLOR).nColor );
445 : }
446 :
447 : // get system text color for comparison
448 4879 : Color aSysTextColor;
449 4879 : if ( eAutoMode == SC_AUTOCOL_PRINT )
450 5 : aSysTextColor.SetColor( COL_BLACK );
451 4874 : else if ( pTextConfigColor )
452 : {
453 : // pTextConfigColor can be used to avoid repeated lookup of the configured color
454 4868 : aSysTextColor = *pTextConfigColor;
455 : }
456 : else
457 6 : aSysTextColor.SetColor( SC_MOD()->GetColorConfig().GetColorValue(svtools::FONTCOLOR).nColor );
458 :
459 : // select the resulting color
460 4879 : if ( aBackColor.IsDark() && aSysTextColor.IsDark() )
461 : {
462 : // use white instead of dark on dark
463 0 : aColor.SetColor( COL_WHITE );
464 : }
465 4879 : else if ( aBackColor.IsBright() && aSysTextColor.IsBright() )
466 : {
467 : // use black instead of bright on bright
468 0 : aColor.SetColor( COL_BLACK );
469 : }
470 : else
471 : {
472 : // use aSysTextColor (black for SC_AUTOCOL_PRINT, from style settings otherwise)
473 4879 : aColor = aSysTextColor;
474 : }
475 : }
476 : }
477 :
478 : // set font effects
479 10606 : rFont.SetWeight( eWeight );
480 10606 : rFont.SetItalic( eItalic );
481 10606 : rFont.SetUnderline( eUnder );
482 10606 : rFont.SetOverline( eOver );
483 10606 : rFont.SetWordLineMode( bWordLine );
484 10606 : rFont.SetStrikeout( eStrike );
485 10606 : rFont.SetOutline( bOutline );
486 10606 : rFont.SetShadow( bShadow );
487 10606 : rFont.SetEmphasisMark( eEmphasis );
488 10606 : rFont.SetRelief( eRelief );
489 10606 : rFont.SetColor( aColor );
490 10606 : rFont.SetTransparent( true );
491 10606 : }
492 :
493 9787 : void ScPatternAttr::GetFont(
494 : vcl::Font& rFont, ScAutoFontColorMode eAutoMode,
495 : OutputDevice* pOutDev, const Fraction* pScale,
496 : const SfxItemSet* pCondSet, SvtScriptType nScript,
497 : const Color* pBackConfigColor, const Color* pTextConfigColor ) const
498 : {
499 9787 : GetFont( rFont, GetItemSet(), eAutoMode, pOutDev, pScale, pCondSet, nScript, pBackConfigColor, pTextConfigColor );
500 9787 : }
501 :
502 10 : ScDxfFont ScPatternAttr::GetDxfFont(const SfxItemSet& rItemSet, SvtScriptType nScript)
503 : {
504 : sal_uInt16 nFontId, nHeightId, nWeightId, nPostureId, nLangId;
505 10 : getFontIDsByScriptType(nScript, nFontId, nHeightId, nWeightId, nPostureId, nLangId);
506 : const SfxPoolItem* pItem;
507 :
508 10 : ScDxfFont aReturn;
509 :
510 10 : if ( rItemSet.GetItemState( nFontId, true, &pItem ) == SfxItemState::SET )
511 : {
512 0 : pItem = &rItemSet.Get( nFontId );
513 0 : aReturn.pFontAttr = static_cast<const SvxFontItem*>(pItem);
514 : }
515 :
516 10 : if ( rItemSet.GetItemState( nHeightId, true, &pItem ) == SfxItemState::SET )
517 : {
518 0 : pItem = &rItemSet.Get( nHeightId );
519 0 : aReturn.nFontHeight = static_cast<const SvxFontHeightItem*>(pItem)->GetHeight();
520 : }
521 :
522 10 : if ( rItemSet.GetItemState( nWeightId, true, &pItem ) == SfxItemState::SET )
523 : {
524 0 : pItem = &rItemSet.Get( nWeightId );
525 0 : aReturn.eWeight = (FontWeight)static_cast<const SvxWeightItem*>(pItem)->GetValue();
526 : }
527 :
528 10 : if ( rItemSet.GetItemState( nPostureId, true, &pItem ) == SfxItemState::SET )
529 : {
530 0 : pItem = &rItemSet.Get( nPostureId );
531 0 : aReturn.eItalic = (FontItalic)static_cast<const SvxPostureItem*>(pItem)->GetValue();
532 : }
533 :
534 10 : if ( rItemSet.GetItemState( ATTR_FONT_UNDERLINE, true, &pItem ) == SfxItemState::SET )
535 : {
536 0 : pItem = &rItemSet.Get( ATTR_FONT_UNDERLINE );
537 0 : aReturn.eUnder = (FontUnderline)static_cast<const SvxUnderlineItem*>(pItem)->GetValue();
538 : }
539 :
540 10 : if ( rItemSet.GetItemState( ATTR_FONT_OVERLINE, true, &pItem ) == SfxItemState::SET )
541 : {
542 0 : pItem = &rItemSet.Get( ATTR_FONT_OVERLINE );
543 0 : aReturn.eOver = (FontUnderline)static_cast<const SvxOverlineItem*>(pItem)->GetValue();
544 : }
545 :
546 10 : if ( rItemSet.GetItemState( ATTR_FONT_WORDLINE, true, &pItem ) == SfxItemState::SET )
547 : {
548 0 : pItem = &rItemSet.Get( ATTR_FONT_WORDLINE );
549 0 : aReturn.bWordLine = static_cast<const SvxWordLineModeItem*>(pItem)->GetValue();
550 : }
551 :
552 10 : if ( rItemSet.GetItemState( ATTR_FONT_CROSSEDOUT, true, &pItem ) == SfxItemState::SET )
553 : {
554 0 : pItem = &rItemSet.Get( ATTR_FONT_CROSSEDOUT );
555 0 : aReturn.eStrike = (FontStrikeout)static_cast<const SvxCrossedOutItem*>(pItem)->GetValue();
556 : }
557 :
558 10 : if ( rItemSet.GetItemState( ATTR_FONT_CONTOUR, true, &pItem ) == SfxItemState::SET )
559 : {
560 0 : pItem = &rItemSet.Get( ATTR_FONT_CONTOUR );
561 0 : aReturn.bOutline = static_cast<const SvxContourItem*>(pItem)->GetValue();
562 : }
563 :
564 10 : if ( rItemSet.GetItemState( ATTR_FONT_SHADOWED, true, &pItem ) == SfxItemState::SET )
565 : {
566 0 : pItem = &rItemSet.Get( ATTR_FONT_SHADOWED );
567 0 : aReturn.bShadow = static_cast<const SvxShadowedItem*>(pItem)->GetValue();
568 : }
569 :
570 10 : if ( rItemSet.GetItemState( ATTR_FONT_EMPHASISMARK, true, &pItem ) == SfxItemState::SET )
571 : {
572 0 : pItem = &rItemSet.Get( ATTR_FONT_EMPHASISMARK );
573 0 : aReturn.eEmphasis = static_cast<const SvxEmphasisMarkItem*>(pItem)->GetEmphasisMark();
574 : }
575 :
576 10 : if ( rItemSet.GetItemState( ATTR_FONT_RELIEF, true, &pItem ) == SfxItemState::SET )
577 : {
578 0 : pItem = &rItemSet.Get( ATTR_FONT_RELIEF );
579 0 : aReturn.eRelief = (FontRelief)static_cast<const SvxCharReliefItem*>(pItem)->GetValue();
580 : }
581 :
582 10 : if ( rItemSet.GetItemState( ATTR_FONT_COLOR, true, &pItem ) == SfxItemState::SET )
583 : {
584 0 : pItem = &rItemSet.Get( ATTR_FONT_COLOR );
585 0 : aReturn.aColor = static_cast<const SvxColorItem*>(pItem)->GetValue();
586 : }
587 :
588 10 : if ( rItemSet.GetItemState( nLangId, true, &pItem ) == SfxItemState::SET )
589 : {
590 0 : pItem = &rItemSet.Get( nLangId );
591 0 : aReturn.eLang = static_cast<const SvxLanguageItem*>(pItem)->GetLanguage();
592 : }
593 :
594 10 : return aReturn;
595 : }
596 :
597 4469 : void ScPatternAttr::FillToEditItemSet( SfxItemSet& rEditSet, const SfxItemSet& rSrcSet, const SfxItemSet* pCondSet )
598 : {
599 : // Read Items
600 :
601 4469 : SvxColorItem aColorItem(EE_CHAR_COLOR); // use item as-is
602 8938 : SvxFontItem aFontItem(EE_CHAR_FONTINFO); // use item as-is
603 8938 : SvxFontItem aCjkFontItem(EE_CHAR_FONTINFO_CJK);
604 8938 : SvxFontItem aCtlFontItem(EE_CHAR_FONTINFO_CTL);
605 : long nTHeight, nCjkTHeight, nCtlTHeight; // Twips
606 : FontWeight eWeight, eCjkWeight, eCtlWeight;
607 8938 : SvxUnderlineItem aUnderlineItem(UNDERLINE_NONE, EE_CHAR_UNDERLINE);
608 8938 : SvxOverlineItem aOverlineItem(UNDERLINE_NONE, EE_CHAR_OVERLINE);
609 : bool bWordLine;
610 : FontStrikeout eStrike;
611 : FontItalic eItalic, eCjkItalic, eCtlItalic;
612 : bool bOutline;
613 : bool bShadow;
614 : bool bForbidden;
615 : FontEmphasisMark eEmphasis;
616 : FontRelief eRelief;
617 : LanguageType eLang, eCjkLang, eCtlLang;
618 : bool bHyphenate;
619 : SvxFrameDirection eDirection;
620 :
621 : //TODO: additional parameter to control if language is needed?
622 :
623 4469 : if ( pCondSet )
624 : {
625 : const SfxPoolItem* pItem;
626 :
627 0 : if ( pCondSet->GetItemState( ATTR_FONT_COLOR, true, &pItem ) != SfxItemState::SET )
628 0 : pItem = &rSrcSet.Get( ATTR_FONT_COLOR );
629 0 : aColorItem = *static_cast<const SvxColorItem*>(pItem);
630 :
631 0 : if ( pCondSet->GetItemState( ATTR_FONT, true, &pItem ) != SfxItemState::SET )
632 0 : pItem = &rSrcSet.Get( ATTR_FONT );
633 0 : aFontItem = *static_cast<const SvxFontItem*>(pItem);
634 0 : if ( pCondSet->GetItemState( ATTR_CJK_FONT, true, &pItem ) != SfxItemState::SET )
635 0 : pItem = &rSrcSet.Get( ATTR_CJK_FONT );
636 0 : aCjkFontItem = *static_cast<const SvxFontItem*>(pItem);
637 0 : if ( pCondSet->GetItemState( ATTR_CTL_FONT, true, &pItem ) != SfxItemState::SET )
638 0 : pItem = &rSrcSet.Get( ATTR_CTL_FONT );
639 0 : aCtlFontItem = *static_cast<const SvxFontItem*>(pItem);
640 :
641 0 : if ( pCondSet->GetItemState( ATTR_FONT_HEIGHT, true, &pItem ) != SfxItemState::SET )
642 0 : pItem = &rSrcSet.Get( ATTR_FONT_HEIGHT );
643 0 : nTHeight = static_cast<const SvxFontHeightItem*>(pItem)->GetHeight();
644 0 : if ( pCondSet->GetItemState( ATTR_CJK_FONT_HEIGHT, true, &pItem ) != SfxItemState::SET )
645 0 : pItem = &rSrcSet.Get( ATTR_CJK_FONT_HEIGHT );
646 0 : nCjkTHeight = static_cast<const SvxFontHeightItem*>(pItem)->GetHeight();
647 0 : if ( pCondSet->GetItemState( ATTR_CTL_FONT_HEIGHT, true, &pItem ) != SfxItemState::SET )
648 0 : pItem = &rSrcSet.Get( ATTR_CTL_FONT_HEIGHT );
649 0 : nCtlTHeight = static_cast<const SvxFontHeightItem*>(pItem)->GetHeight();
650 :
651 0 : if ( pCondSet->GetItemState( ATTR_FONT_WEIGHT, true, &pItem ) != SfxItemState::SET )
652 0 : pItem = &rSrcSet.Get( ATTR_FONT_WEIGHT );
653 0 : eWeight = (FontWeight)static_cast<const SvxWeightItem*>(pItem)->GetValue();
654 0 : if ( pCondSet->GetItemState( ATTR_CJK_FONT_WEIGHT, true, &pItem ) != SfxItemState::SET )
655 0 : pItem = &rSrcSet.Get( ATTR_CJK_FONT_WEIGHT );
656 0 : eCjkWeight = (FontWeight)static_cast<const SvxWeightItem*>(pItem)->GetValue();
657 0 : if ( pCondSet->GetItemState( ATTR_CTL_FONT_WEIGHT, true, &pItem ) != SfxItemState::SET )
658 0 : pItem = &rSrcSet.Get( ATTR_CTL_FONT_WEIGHT );
659 0 : eCtlWeight = (FontWeight)static_cast<const SvxWeightItem*>(pItem)->GetValue();
660 :
661 0 : if ( pCondSet->GetItemState( ATTR_FONT_POSTURE, true, &pItem ) != SfxItemState::SET )
662 0 : pItem = &rSrcSet.Get( ATTR_FONT_POSTURE );
663 0 : eItalic = (FontItalic)static_cast<const SvxPostureItem*>(pItem)->GetValue();
664 0 : if ( pCondSet->GetItemState( ATTR_CJK_FONT_POSTURE, true, &pItem ) != SfxItemState::SET )
665 0 : pItem = &rSrcSet.Get( ATTR_CJK_FONT_POSTURE );
666 0 : eCjkItalic = (FontItalic)static_cast<const SvxPostureItem*>(pItem)->GetValue();
667 0 : if ( pCondSet->GetItemState( ATTR_CTL_FONT_POSTURE, true, &pItem ) != SfxItemState::SET )
668 0 : pItem = &rSrcSet.Get( ATTR_CTL_FONT_POSTURE );
669 0 : eCtlItalic = (FontItalic)static_cast<const SvxPostureItem*>(pItem)->GetValue();
670 :
671 0 : if ( pCondSet->GetItemState( ATTR_FONT_UNDERLINE, true, &pItem ) != SfxItemState::SET )
672 0 : pItem = &rSrcSet.Get( ATTR_FONT_UNDERLINE );
673 0 : aUnderlineItem = *static_cast<const SvxUnderlineItem*>(pItem);
674 :
675 0 : if ( pCondSet->GetItemState( ATTR_FONT_OVERLINE, true, &pItem ) != SfxItemState::SET )
676 0 : pItem = &rSrcSet.Get( ATTR_FONT_OVERLINE );
677 0 : aOverlineItem = *static_cast<const SvxOverlineItem*>(pItem);
678 :
679 0 : if ( pCondSet->GetItemState( ATTR_FONT_WORDLINE, true, &pItem ) != SfxItemState::SET )
680 0 : pItem = &rSrcSet.Get( ATTR_FONT_WORDLINE );
681 0 : bWordLine = static_cast<const SvxWordLineModeItem*>(pItem)->GetValue();
682 :
683 0 : if ( pCondSet->GetItemState( ATTR_FONT_CROSSEDOUT, true, &pItem ) != SfxItemState::SET )
684 0 : pItem = &rSrcSet.Get( ATTR_FONT_CROSSEDOUT );
685 0 : eStrike = (FontStrikeout)static_cast<const SvxCrossedOutItem*>(pItem)->GetValue();
686 :
687 0 : if ( pCondSet->GetItemState( ATTR_FONT_CONTOUR, true, &pItem ) != SfxItemState::SET )
688 0 : pItem = &rSrcSet.Get( ATTR_FONT_CONTOUR );
689 0 : bOutline = static_cast<const SvxContourItem*>(pItem)->GetValue();
690 :
691 0 : if ( pCondSet->GetItemState( ATTR_FONT_SHADOWED, true, &pItem ) != SfxItemState::SET )
692 0 : pItem = &rSrcSet.Get( ATTR_FONT_SHADOWED );
693 0 : bShadow = static_cast<const SvxShadowedItem*>(pItem)->GetValue();
694 :
695 0 : if ( pCondSet->GetItemState( ATTR_FORBIDDEN_RULES, true, &pItem ) != SfxItemState::SET )
696 0 : pItem = &rSrcSet.Get( ATTR_FORBIDDEN_RULES );
697 0 : bForbidden = static_cast<const SvxForbiddenRuleItem*>(pItem)->GetValue();
698 :
699 0 : if ( pCondSet->GetItemState( ATTR_FONT_EMPHASISMARK, true, &pItem ) != SfxItemState::SET )
700 0 : pItem = &rSrcSet.Get( ATTR_FONT_EMPHASISMARK );
701 0 : eEmphasis = static_cast<const SvxEmphasisMarkItem*>(pItem)->GetEmphasisMark();
702 0 : if ( pCondSet->GetItemState( ATTR_FONT_RELIEF, true, &pItem ) != SfxItemState::SET )
703 0 : pItem = &rSrcSet.Get( ATTR_FONT_RELIEF );
704 0 : eRelief = (FontRelief)static_cast<const SvxCharReliefItem*>(pItem)->GetValue();
705 :
706 0 : if ( pCondSet->GetItemState( ATTR_FONT_LANGUAGE, true, &pItem ) != SfxItemState::SET )
707 0 : pItem = &rSrcSet.Get( ATTR_FONT_LANGUAGE );
708 0 : eLang = static_cast<const SvxLanguageItem*>(pItem)->GetLanguage();
709 0 : if ( pCondSet->GetItemState( ATTR_CJK_FONT_LANGUAGE, true, &pItem ) != SfxItemState::SET )
710 0 : pItem = &rSrcSet.Get( ATTR_CJK_FONT_LANGUAGE );
711 0 : eCjkLang = static_cast<const SvxLanguageItem*>(pItem)->GetLanguage();
712 0 : if ( pCondSet->GetItemState( ATTR_CTL_FONT_LANGUAGE, true, &pItem ) != SfxItemState::SET )
713 0 : pItem = &rSrcSet.Get( ATTR_CTL_FONT_LANGUAGE );
714 0 : eCtlLang = static_cast<const SvxLanguageItem*>(pItem)->GetLanguage();
715 :
716 0 : if ( pCondSet->GetItemState( ATTR_HYPHENATE, true, &pItem ) != SfxItemState::SET )
717 0 : pItem = &rSrcSet.Get( ATTR_HYPHENATE );
718 0 : bHyphenate = static_cast<const SfxBoolItem*>(pItem)->GetValue();
719 :
720 0 : if ( pCondSet->GetItemState( ATTR_WRITINGDIR, true, &pItem ) != SfxItemState::SET )
721 0 : pItem = &rSrcSet.Get( ATTR_WRITINGDIR );
722 0 : eDirection = (SvxFrameDirection)static_cast<const SvxFrameDirectionItem*>(pItem)->GetValue();
723 : }
724 : else // Everything directly from Pattern
725 : {
726 4469 : aColorItem = static_cast<const SvxColorItem&>( rSrcSet.Get( ATTR_FONT_COLOR ) );
727 4469 : aFontItem = static_cast<const SvxFontItem&>( rSrcSet.Get( ATTR_FONT ) );
728 4469 : aCjkFontItem = static_cast<const SvxFontItem&>( rSrcSet.Get( ATTR_CJK_FONT ) );
729 4469 : aCtlFontItem = static_cast<const SvxFontItem&>( rSrcSet.Get( ATTR_CTL_FONT ) );
730 : nTHeight = static_cast<const SvxFontHeightItem&>(
731 4469 : rSrcSet.Get( ATTR_FONT_HEIGHT )).GetHeight();
732 : nCjkTHeight = static_cast<const SvxFontHeightItem&>(
733 4469 : rSrcSet.Get( ATTR_CJK_FONT_HEIGHT )).GetHeight();
734 : nCtlTHeight = static_cast<const SvxFontHeightItem&>(
735 4469 : rSrcSet.Get( ATTR_CTL_FONT_HEIGHT )).GetHeight();
736 : eWeight = (FontWeight)static_cast<const SvxWeightItem&>(
737 4469 : rSrcSet.Get( ATTR_FONT_WEIGHT )).GetValue();
738 : eCjkWeight = (FontWeight)static_cast<const SvxWeightItem&>(
739 4469 : rSrcSet.Get( ATTR_CJK_FONT_WEIGHT )).GetValue();
740 : eCtlWeight = (FontWeight)static_cast<const SvxWeightItem&>(
741 4469 : rSrcSet.Get( ATTR_CTL_FONT_WEIGHT )).GetValue();
742 : eItalic = (FontItalic)static_cast<const SvxPostureItem&>(
743 4469 : rSrcSet.Get( ATTR_FONT_POSTURE )).GetValue();
744 : eCjkItalic = (FontItalic)static_cast<const SvxPostureItem&>(
745 4469 : rSrcSet.Get( ATTR_CJK_FONT_POSTURE )).GetValue();
746 : eCtlItalic = (FontItalic)static_cast<const SvxPostureItem&>(
747 4469 : rSrcSet.Get( ATTR_CTL_FONT_POSTURE )).GetValue();
748 4469 : aUnderlineItem = static_cast<const SvxUnderlineItem&>( rSrcSet.Get( ATTR_FONT_UNDERLINE ) );
749 4469 : aOverlineItem = static_cast<const SvxOverlineItem&>( rSrcSet.Get( ATTR_FONT_OVERLINE ) );
750 : bWordLine = static_cast<const SvxWordLineModeItem&>(
751 4469 : rSrcSet.Get( ATTR_FONT_WORDLINE )).GetValue();
752 : eStrike = (FontStrikeout)static_cast<const SvxCrossedOutItem&>(
753 4469 : rSrcSet.Get( ATTR_FONT_CROSSEDOUT )).GetValue();
754 : bOutline = static_cast<const SvxContourItem&>(
755 4469 : rSrcSet.Get( ATTR_FONT_CONTOUR )).GetValue();
756 : bShadow = static_cast<const SvxShadowedItem&>(
757 4469 : rSrcSet.Get( ATTR_FONT_SHADOWED )).GetValue();
758 : bForbidden = static_cast<const SvxForbiddenRuleItem&>(
759 4469 : rSrcSet.Get( ATTR_FORBIDDEN_RULES )).GetValue();
760 : eEmphasis = static_cast<const SvxEmphasisMarkItem&>(
761 4469 : rSrcSet.Get( ATTR_FONT_EMPHASISMARK )).GetEmphasisMark();
762 : eRelief = (FontRelief)static_cast<const SvxCharReliefItem&>(
763 4469 : rSrcSet.Get( ATTR_FONT_RELIEF )).GetValue();
764 : eLang = static_cast<const SvxLanguageItem&>(
765 4469 : rSrcSet.Get( ATTR_FONT_LANGUAGE )).GetLanguage();
766 : eCjkLang = static_cast<const SvxLanguageItem&>(
767 4469 : rSrcSet.Get( ATTR_CJK_FONT_LANGUAGE )).GetLanguage();
768 : eCtlLang = static_cast<const SvxLanguageItem&>(
769 4469 : rSrcSet.Get( ATTR_CTL_FONT_LANGUAGE )).GetLanguage();
770 : bHyphenate = static_cast<const SfxBoolItem&>(
771 4469 : rSrcSet.Get( ATTR_HYPHENATE )).GetValue();
772 : eDirection = (SvxFrameDirection)static_cast<const SvxFrameDirectionItem&>(
773 4469 : rSrcSet.Get( ATTR_WRITINGDIR )).GetValue();
774 : }
775 :
776 : // Expect to be compatible to LogicToLogic, ie. 2540/1440 = 127/72, and round
777 :
778 4469 : long nHeight = TwipsToHMM(nTHeight);
779 4469 : long nCjkHeight = TwipsToHMM(nCjkTHeight);
780 4469 : long nCtlHeight = TwipsToHMM(nCtlTHeight);
781 :
782 : // put items into EditEngine ItemSet
783 :
784 4469 : if ( aColorItem.GetValue().GetColor() == COL_AUTO )
785 : {
786 : // When cell attributes are converted to EditEngine paragraph attributes,
787 : // don't create a hard item for automatic color, because that would be converted
788 : // to black when the item's Store method is used in CreateTransferable/WriteBin.
789 : // COL_AUTO is the EditEngine's pool default, so ClearItem will result in automatic
790 : // color, too, without having to store the item.
791 3277 : rEditSet.ClearItem( EE_CHAR_COLOR );
792 : }
793 : else
794 1192 : rEditSet.Put( aColorItem );
795 4469 : rEditSet.Put( aFontItem );
796 4469 : rEditSet.Put( aCjkFontItem );
797 4469 : rEditSet.Put( aCtlFontItem );
798 4469 : rEditSet.Put( SvxFontHeightItem( nHeight, 100, EE_CHAR_FONTHEIGHT ) );
799 4469 : rEditSet.Put( SvxFontHeightItem( nCjkHeight, 100, EE_CHAR_FONTHEIGHT_CJK ) );
800 4469 : rEditSet.Put( SvxFontHeightItem( nCtlHeight, 100, EE_CHAR_FONTHEIGHT_CTL ) );
801 4469 : rEditSet.Put( SvxWeightItem ( eWeight, EE_CHAR_WEIGHT ) );
802 4469 : rEditSet.Put( SvxWeightItem ( eCjkWeight, EE_CHAR_WEIGHT_CJK ) );
803 4469 : rEditSet.Put( SvxWeightItem ( eCtlWeight, EE_CHAR_WEIGHT_CTL ) );
804 4469 : rEditSet.Put( aUnderlineItem );
805 4469 : rEditSet.Put( aOverlineItem );
806 4469 : rEditSet.Put( SvxWordLineModeItem( bWordLine, EE_CHAR_WLM ) );
807 4469 : rEditSet.Put( SvxCrossedOutItem( eStrike, EE_CHAR_STRIKEOUT ) );
808 4469 : rEditSet.Put( SvxPostureItem ( eItalic, EE_CHAR_ITALIC ) );
809 4469 : rEditSet.Put( SvxPostureItem ( eCjkItalic, EE_CHAR_ITALIC_CJK ) );
810 4469 : rEditSet.Put( SvxPostureItem ( eCtlItalic, EE_CHAR_ITALIC_CTL ) );
811 4469 : rEditSet.Put( SvxContourItem ( bOutline, EE_CHAR_OUTLINE ) );
812 4469 : rEditSet.Put( SvxShadowedItem ( bShadow, EE_CHAR_SHADOW ) );
813 4469 : rEditSet.Put( SfxBoolItem ( EE_PARA_FORBIDDENRULES, bForbidden ) );
814 4469 : rEditSet.Put( SvxEmphasisMarkItem( eEmphasis, EE_CHAR_EMPHASISMARK ) );
815 4469 : rEditSet.Put( SvxCharReliefItem( eRelief, EE_CHAR_RELIEF ) );
816 4469 : rEditSet.Put( SvxLanguageItem ( eLang, EE_CHAR_LANGUAGE ) );
817 4469 : rEditSet.Put( SvxLanguageItem ( eCjkLang, EE_CHAR_LANGUAGE_CJK ) );
818 4469 : rEditSet.Put( SvxLanguageItem ( eCtlLang, EE_CHAR_LANGUAGE_CTL ) );
819 4469 : rEditSet.Put( SfxBoolItem ( EE_PARA_HYPHENATE, bHyphenate ) );
820 4469 : rEditSet.Put( SvxFrameDirectionItem( eDirection, EE_PARA_WRITINGDIR ) );
821 :
822 : // Script spacing is always off.
823 : // The cell attribute isn't used here as long as there is no UI to set it
824 : // (don't evaluate attributes that can't be changed).
825 : // If a locale-dependent default is needed, it has to go into the cell
826 : // style, like the fonts.
827 8938 : rEditSet.Put( SvxScriptSpaceItem( false, EE_PARA_ASIANCJKSPACING ) );
828 4469 : }
829 :
830 4309 : void ScPatternAttr::FillEditItemSet( SfxItemSet* pEditSet, const SfxItemSet* pCondSet ) const
831 : {
832 4309 : if( pEditSet )
833 4309 : FillToEditItemSet( *pEditSet, GetItemSet(), pCondSet );
834 4309 : }
835 :
836 285 : void ScPatternAttr::GetFromEditItemSet( SfxItemSet& rDestSet, const SfxItemSet& rEditSet )
837 : {
838 : const SfxPoolItem* pItem;
839 :
840 285 : if (rEditSet.GetItemState(EE_CHAR_COLOR,true,&pItem) == SfxItemState::SET)
841 259 : rDestSet.Put( SvxColorItem(ATTR_FONT_COLOR) = *static_cast<const SvxColorItem*>(pItem) );
842 :
843 285 : if (rEditSet.GetItemState(EE_CHAR_FONTINFO,true,&pItem) == SfxItemState::SET)
844 264 : rDestSet.Put( SvxFontItem(ATTR_FONT) = *static_cast<const SvxFontItem*>(pItem) );
845 285 : if (rEditSet.GetItemState(EE_CHAR_FONTINFO_CJK,true,&pItem) == SfxItemState::SET)
846 240 : rDestSet.Put( SvxFontItem(ATTR_CJK_FONT) = *static_cast<const SvxFontItem*>(pItem) );
847 285 : if (rEditSet.GetItemState(EE_CHAR_FONTINFO_CTL,true,&pItem) == SfxItemState::SET)
848 206 : rDestSet.Put( SvxFontItem(ATTR_CTL_FONT) = *static_cast<const SvxFontItem*>(pItem) );
849 :
850 285 : if (rEditSet.GetItemState(EE_CHAR_FONTHEIGHT,true,&pItem) == SfxItemState::SET)
851 257 : rDestSet.Put( SvxFontHeightItem( HMMToTwips( static_cast<const SvxFontHeightItem*>(pItem)->GetHeight() ),
852 257 : 100, ATTR_FONT_HEIGHT ) );
853 285 : if (rEditSet.GetItemState(EE_CHAR_FONTHEIGHT_CJK,true,&pItem) == SfxItemState::SET)
854 204 : rDestSet.Put( SvxFontHeightItem( HMMToTwips( static_cast<const SvxFontHeightItem*>(pItem)->GetHeight() ),
855 204 : 100, ATTR_CJK_FONT_HEIGHT ) );
856 285 : if (rEditSet.GetItemState(EE_CHAR_FONTHEIGHT_CTL,true,&pItem) == SfxItemState::SET)
857 224 : rDestSet.Put( SvxFontHeightItem( HMMToTwips( static_cast<const SvxFontHeightItem*>(pItem)->GetHeight() ),
858 224 : 100, ATTR_CTL_FONT_HEIGHT ) );
859 :
860 285 : if (rEditSet.GetItemState(EE_CHAR_WEIGHT,true,&pItem) == SfxItemState::SET)
861 255 : rDestSet.Put( SvxWeightItem( (FontWeight)static_cast<const SvxWeightItem*>(pItem)->GetValue(),
862 255 : ATTR_FONT_WEIGHT) );
863 285 : if (rEditSet.GetItemState(EE_CHAR_WEIGHT_CJK,true,&pItem) == SfxItemState::SET)
864 216 : rDestSet.Put( SvxWeightItem( (FontWeight)static_cast<const SvxWeightItem*>(pItem)->GetValue(),
865 216 : ATTR_CJK_FONT_WEIGHT) );
866 285 : if (rEditSet.GetItemState(EE_CHAR_WEIGHT_CTL,true,&pItem) == SfxItemState::SET)
867 217 : rDestSet.Put( SvxWeightItem( (FontWeight)static_cast<const SvxWeightItem*>(pItem)->GetValue(),
868 217 : ATTR_CTL_FONT_WEIGHT) );
869 :
870 : // SvxTextLineItem contains enum and color
871 285 : if (rEditSet.GetItemState(EE_CHAR_UNDERLINE,true,&pItem) == SfxItemState::SET)
872 256 : rDestSet.Put( SvxUnderlineItem(UNDERLINE_NONE,ATTR_FONT_UNDERLINE) = *static_cast<const SvxUnderlineItem*>(pItem) );
873 285 : if (rEditSet.GetItemState(EE_CHAR_OVERLINE,true,&pItem) == SfxItemState::SET)
874 220 : rDestSet.Put( SvxOverlineItem(UNDERLINE_NONE,ATTR_FONT_OVERLINE) = *static_cast<const SvxOverlineItem*>(pItem) );
875 285 : if (rEditSet.GetItemState(EE_CHAR_WLM,true,&pItem) == SfxItemState::SET)
876 247 : rDestSet.Put( SvxWordLineModeItem( static_cast<const SvxWordLineModeItem*>(pItem)->GetValue(),
877 247 : ATTR_FONT_WORDLINE) );
878 :
879 285 : if (rEditSet.GetItemState(EE_CHAR_STRIKEOUT,true,&pItem) == SfxItemState::SET)
880 249 : rDestSet.Put( SvxCrossedOutItem( (FontStrikeout)static_cast<const SvxCrossedOutItem*>(pItem)->GetValue(),
881 249 : ATTR_FONT_CROSSEDOUT) );
882 :
883 285 : if (rEditSet.GetItemState(EE_CHAR_ITALIC,true,&pItem) == SfxItemState::SET)
884 254 : rDestSet.Put( SvxPostureItem( (FontItalic)static_cast<const SvxPostureItem*>(pItem)->GetValue(),
885 254 : ATTR_FONT_POSTURE) );
886 285 : if (rEditSet.GetItemState(EE_CHAR_ITALIC_CJK,true,&pItem) == SfxItemState::SET)
887 191 : rDestSet.Put( SvxPostureItem( (FontItalic)static_cast<const SvxPostureItem*>(pItem)->GetValue(),
888 191 : ATTR_CJK_FONT_POSTURE) );
889 285 : if (rEditSet.GetItemState(EE_CHAR_ITALIC_CTL,true,&pItem) == SfxItemState::SET)
890 174 : rDestSet.Put( SvxPostureItem( (FontItalic)static_cast<const SvxPostureItem*>(pItem)->GetValue(),
891 174 : ATTR_CTL_FONT_POSTURE) );
892 :
893 285 : if (rEditSet.GetItemState(EE_CHAR_OUTLINE,true,&pItem) == SfxItemState::SET)
894 243 : rDestSet.Put( SvxContourItem( static_cast<const SvxContourItem*>(pItem)->GetValue(),
895 243 : ATTR_FONT_CONTOUR) );
896 285 : if (rEditSet.GetItemState(EE_CHAR_SHADOW,true,&pItem) == SfxItemState::SET)
897 244 : rDestSet.Put( SvxShadowedItem( static_cast<const SvxShadowedItem*>(pItem)->GetValue(),
898 244 : ATTR_FONT_SHADOWED) );
899 285 : if (rEditSet.GetItemState(EE_CHAR_EMPHASISMARK,true,&pItem) == SfxItemState::SET)
900 242 : rDestSet.Put( SvxEmphasisMarkItem( static_cast<const SvxEmphasisMarkItem*>(pItem)->GetEmphasisMark(),
901 242 : ATTR_FONT_EMPHASISMARK) );
902 285 : if (rEditSet.GetItemState(EE_CHAR_RELIEF,true,&pItem) == SfxItemState::SET)
903 241 : rDestSet.Put( SvxCharReliefItem( (FontRelief)static_cast<const SvxCharReliefItem*>(pItem)->GetValue(),
904 241 : ATTR_FONT_RELIEF) );
905 :
906 285 : if (rEditSet.GetItemState(EE_CHAR_LANGUAGE,true,&pItem) == SfxItemState::SET)
907 245 : rDestSet.Put( SvxLanguageItem(static_cast<const SvxLanguageItem*>(pItem)->GetValue(), ATTR_FONT_LANGUAGE) );
908 285 : if (rEditSet.GetItemState(EE_CHAR_LANGUAGE_CJK,true,&pItem) == SfxItemState::SET)
909 224 : rDestSet.Put( SvxLanguageItem(static_cast<const SvxLanguageItem*>(pItem)->GetValue(), ATTR_CJK_FONT_LANGUAGE) );
910 285 : if (rEditSet.GetItemState(EE_CHAR_LANGUAGE_CTL,true,&pItem) == SfxItemState::SET)
911 225 : rDestSet.Put( SvxLanguageItem(static_cast<const SvxLanguageItem*>(pItem)->GetValue(), ATTR_CTL_FONT_LANGUAGE) );
912 :
913 285 : if (rEditSet.GetItemState(EE_PARA_JUST,true,&pItem) == SfxItemState::SET)
914 : {
915 : SvxCellHorJustify eVal;
916 103 : switch ( static_cast<const SvxAdjustItem*>(pItem)->GetAdjust() )
917 : {
918 : case SVX_ADJUST_LEFT:
919 : // EditEngine Default is always set in the GetAttribs() ItemSet !
920 : // whether left or right, is decided in text / number
921 101 : eVal = SVX_HOR_JUSTIFY_STANDARD;
922 101 : break;
923 : case SVX_ADJUST_RIGHT:
924 0 : eVal = SVX_HOR_JUSTIFY_RIGHT;
925 0 : break;
926 : case SVX_ADJUST_BLOCK:
927 0 : eVal = SVX_HOR_JUSTIFY_BLOCK;
928 0 : break;
929 : case SVX_ADJUST_CENTER:
930 2 : eVal = SVX_HOR_JUSTIFY_CENTER;
931 2 : break;
932 : case SVX_ADJUST_BLOCKLINE:
933 0 : eVal = SVX_HOR_JUSTIFY_BLOCK;
934 0 : break;
935 : case SVX_ADJUST_END:
936 0 : eVal = SVX_HOR_JUSTIFY_RIGHT;
937 0 : break;
938 : default:
939 0 : eVal = SVX_HOR_JUSTIFY_STANDARD;
940 : }
941 103 : if ( eVal != SVX_HOR_JUSTIFY_STANDARD )
942 2 : rDestSet.Put( SvxHorJustifyItem( eVal, ATTR_HOR_JUSTIFY) );
943 : }
944 285 : }
945 :
946 182 : void ScPatternAttr::GetFromEditItemSet( const SfxItemSet* pEditSet )
947 : {
948 182 : if( pEditSet )
949 182 : GetFromEditItemSet( GetItemSet(), *pEditSet );
950 182 : }
951 :
952 61 : void ScPatternAttr::FillEditParaItems( SfxItemSet* pEditSet ) const
953 : {
954 : // already there in GetFromEditItemSet, but not in FillEditItemSet
955 : // Default horizontal alignmnet is always implemented as left
956 :
957 61 : const SfxItemSet& rMySet = GetItemSet();
958 :
959 : SvxCellHorJustify eHorJust = (SvxCellHorJustify)
960 61 : static_cast<const SvxHorJustifyItem&>(rMySet.Get(ATTR_HOR_JUSTIFY)).GetValue();
961 :
962 : SvxAdjust eSvxAdjust;
963 61 : switch (eHorJust)
964 : {
965 2 : case SVX_HOR_JUSTIFY_RIGHT: eSvxAdjust = SVX_ADJUST_RIGHT; break;
966 0 : case SVX_HOR_JUSTIFY_CENTER: eSvxAdjust = SVX_ADJUST_CENTER; break;
967 0 : case SVX_HOR_JUSTIFY_BLOCK: eSvxAdjust = SVX_ADJUST_BLOCK; break;
968 59 : default: eSvxAdjust = SVX_ADJUST_LEFT; break;
969 : }
970 61 : pEditSet->Put( SvxAdjustItem( eSvxAdjust, EE_PARA_JUST ) );
971 61 : }
972 :
973 176 : void ScPatternAttr::DeleteUnchanged( const ScPatternAttr* pOldAttrs )
974 : {
975 176 : SfxItemSet& rThisSet = GetItemSet();
976 176 : const SfxItemSet& rOldSet = pOldAttrs->GetItemSet();
977 :
978 : const SfxPoolItem* pThisItem;
979 : const SfxPoolItem* pOldItem;
980 :
981 10032 : for ( sal_uInt16 nSubWhich=ATTR_PATTERN_START; nSubWhich<=ATTR_PATTERN_END; nSubWhich++ )
982 : {
983 : // only items that are set are interesting
984 9856 : if ( rThisSet.GetItemState( nSubWhich, false, &pThisItem ) == SfxItemState::SET )
985 : {
986 2981 : SfxItemState eOldState = rOldSet.GetItemState( nSubWhich, true, &pOldItem );
987 2981 : if ( eOldState == SfxItemState::SET )
988 : {
989 : // item is set in OldAttrs (or its parent) -> compare pointers
990 2814 : if ( pThisItem == pOldItem )
991 2732 : rThisSet.ClearItem( nSubWhich );
992 : }
993 167 : else if ( eOldState != SfxItemState::DONTCARE )
994 : {
995 : // not set in OldAttrs -> compare item value to default item
996 167 : if ( *pThisItem == rThisSet.GetPool()->GetDefaultItem( nSubWhich ) )
997 136 : rThisSet.ClearItem( nSubWhich );
998 : }
999 : }
1000 : }
1001 176 : }
1002 :
1003 247 : bool ScPatternAttr::HasItemsSet( const sal_uInt16* pWhich ) const
1004 : {
1005 247 : const SfxItemSet& rSet = GetItemSet();
1006 494 : for (sal_uInt16 i=0; pWhich[i]; i++)
1007 247 : if ( rSet.GetItemState( pWhich[i], false ) == SfxItemState::SET )
1008 0 : return true;
1009 247 : return false;
1010 : }
1011 :
1012 0 : void ScPatternAttr::ClearItems( const sal_uInt16* pWhich )
1013 : {
1014 0 : SfxItemSet& rSet = GetItemSet();
1015 0 : for (sal_uInt16 i=0; pWhich[i]; i++)
1016 0 : rSet.ClearItem(pWhich[i]);
1017 0 : }
1018 :
1019 72 : static SfxStyleSheetBase* lcl_CopyStyleToPool
1020 : (
1021 : SfxStyleSheetBase* pSrcStyle,
1022 : SfxStyleSheetBasePool* pSrcPool,
1023 : SfxStyleSheetBasePool* pDestPool,
1024 : const SvNumberFormatterIndexTable* pFormatExchangeList
1025 : )
1026 : {
1027 72 : if ( !pSrcStyle || !pDestPool || !pSrcPool )
1028 : {
1029 : OSL_FAIL( "CopyStyleToPool: Invalid Arguments :-/" );
1030 0 : return NULL;
1031 : }
1032 :
1033 72 : const OUString aStrSrcStyle = pSrcStyle->GetName();
1034 72 : const SfxStyleFamily eFamily = pSrcStyle->GetFamily();
1035 72 : SfxStyleSheetBase* pDestStyle = pDestPool->Find( aStrSrcStyle, eFamily );
1036 :
1037 72 : if ( !pDestStyle )
1038 : {
1039 1 : const OUString aStrParent = pSrcStyle->GetParent();
1040 1 : const SfxItemSet& rSrcSet = pSrcStyle->GetItemSet();
1041 :
1042 1 : pDestStyle = &pDestPool->Make( aStrSrcStyle, eFamily, SFXSTYLEBIT_USERDEF );
1043 1 : SfxItemSet& rDestSet = pDestStyle->GetItemSet();
1044 1 : rDestSet.Put( rSrcSet );
1045 :
1046 : // number format exchange list has to be handled here, too
1047 : // (only called for cell styles)
1048 :
1049 : const SfxPoolItem* pSrcItem;
1050 1 : if ( pFormatExchangeList &&
1051 0 : rSrcSet.GetItemState( ATTR_VALUE_FORMAT, false, &pSrcItem ) == SfxItemState::SET )
1052 : {
1053 0 : sal_uLong nOldFormat = static_cast<const SfxUInt32Item*>(pSrcItem)->GetValue();
1054 0 : SvNumberFormatterIndexTable::const_iterator it = pFormatExchangeList->find(nOldFormat);
1055 0 : if (it != pFormatExchangeList->end())
1056 : {
1057 0 : sal_uInt32 nNewFormat = it->second;
1058 0 : rDestSet.Put( SfxUInt32Item( ATTR_VALUE_FORMAT, nNewFormat ) );
1059 : }
1060 : }
1061 :
1062 : // if necessary create derivative Styles, if not available:
1063 :
1064 2 : if ( ScGlobal::GetRscString(STR_STYLENAME_STANDARD) != aStrParent &&
1065 1 : aStrSrcStyle != aStrParent &&
1066 0 : !pDestPool->Find( aStrParent, eFamily ) )
1067 : {
1068 0 : lcl_CopyStyleToPool( pSrcPool->Find( aStrParent, eFamily ),
1069 0 : pSrcPool, pDestPool, pFormatExchangeList );
1070 : }
1071 :
1072 1 : pDestStyle->SetParent( aStrParent );
1073 : }
1074 :
1075 72 : return pDestStyle;
1076 : }
1077 :
1078 72 : ScPatternAttr* ScPatternAttr::PutInPool( ScDocument* pDestDoc, ScDocument* pSrcDoc ) const
1079 : {
1080 72 : const SfxItemSet* pSrcSet = &GetItemSet();
1081 :
1082 72 : ScPatternAttr* pDestPattern = new ScPatternAttr(pDestDoc->GetPool());
1083 72 : SfxItemSet* pDestSet = &pDestPattern->GetItemSet();
1084 :
1085 : // Copy cell pattern style to other document:
1086 :
1087 72 : if ( pDestDoc != pSrcDoc )
1088 : {
1089 : OSL_ENSURE( pStyle, "Missing Pattern-Style! :-/" );
1090 :
1091 : // if pattern in DestDoc is available, use this, otherwise copy
1092 : // parent style to style or create if necessary and attach DestDoc
1093 :
1094 : SfxStyleSheetBase* pStyleCpy = lcl_CopyStyleToPool( pStyle,
1095 72 : pSrcDoc->GetStyleSheetPool(),
1096 72 : pDestDoc->GetStyleSheetPool(),
1097 144 : pDestDoc->GetFormatExchangeList() );
1098 :
1099 72 : pDestPattern->SetStyleSheet( static_cast<ScStyleSheet*>(pStyleCpy) );
1100 : }
1101 :
1102 4104 : for ( sal_uInt16 nAttrId = ATTR_PATTERN_START; nAttrId <= ATTR_PATTERN_END; nAttrId++ )
1103 : {
1104 : const SfxPoolItem* pSrcItem;
1105 4032 : SfxItemState eItemState = pSrcSet->GetItemState( nAttrId, false, &pSrcItem );
1106 4032 : if (eItemState==SfxItemState::SET)
1107 : {
1108 2 : SfxPoolItem* pNewItem = NULL;
1109 :
1110 2 : if ( nAttrId == ATTR_VALIDDATA )
1111 : {
1112 : // Copy validity to the new document
1113 :
1114 0 : sal_uLong nNewIndex = 0;
1115 0 : ScValidationDataList* pSrcList = pSrcDoc->GetValidationList();
1116 0 : if ( pSrcList )
1117 : {
1118 0 : sal_uLong nOldIndex = static_cast<const SfxUInt32Item*>(pSrcItem)->GetValue();
1119 0 : const ScValidationData* pOldData = pSrcList->GetData( nOldIndex );
1120 0 : if ( pOldData )
1121 0 : nNewIndex = pDestDoc->AddValidationEntry( *pOldData );
1122 : }
1123 0 : pNewItem = new SfxUInt32Item( ATTR_VALIDDATA, nNewIndex );
1124 : }
1125 2 : else if ( nAttrId == ATTR_VALUE_FORMAT && pDestDoc->GetFormatExchangeList() )
1126 : {
1127 : // Number format to Exchange List
1128 :
1129 0 : sal_uLong nOldFormat = static_cast<const SfxUInt32Item*>(pSrcItem)->GetValue();
1130 0 : SvNumberFormatterIndexTable::const_iterator it = pDestDoc->GetFormatExchangeList()->find(nOldFormat);
1131 0 : if (it != pDestDoc->GetFormatExchangeList()->end())
1132 : {
1133 0 : sal_uInt32 nNewFormat = it->second;
1134 0 : pNewItem = new SfxUInt32Item( ATTR_VALUE_FORMAT, nNewFormat );
1135 : }
1136 : }
1137 :
1138 2 : if ( pNewItem )
1139 : {
1140 0 : pDestSet->Put(*pNewItem);
1141 0 : delete pNewItem;
1142 : }
1143 : else
1144 2 : pDestSet->Put(*pSrcItem);
1145 : }
1146 : }
1147 :
1148 : ScPatternAttr* pPatternAttr =
1149 72 : const_cast<ScPatternAttr*>( static_cast<const ScPatternAttr*>( &pDestDoc->GetPool()->Put(*pDestPattern) ) );
1150 72 : delete pDestPattern;
1151 72 : return pPatternAttr;
1152 : }
1153 :
1154 5080 : bool ScPatternAttr::IsVisible() const
1155 : {
1156 5080 : const SfxItemSet& rSet = GetItemSet();
1157 :
1158 : const SfxPoolItem* pItem;
1159 : SfxItemState eState;
1160 :
1161 5080 : eState = rSet.GetItemState( ATTR_BACKGROUND, true, &pItem );
1162 5080 : if ( eState == SfxItemState::SET )
1163 4237 : if ( static_cast<const SvxBrushItem*>(pItem)->GetColor().GetColor() != COL_TRANSPARENT )
1164 4190 : return true;
1165 :
1166 890 : eState = rSet.GetItemState( ATTR_BORDER, true, &pItem );
1167 890 : if ( eState == SfxItemState::SET )
1168 : {
1169 357 : const SvxBoxItem* pBoxItem = static_cast<const SvxBoxItem*>(pItem);
1170 766 : if ( pBoxItem->GetTop() || pBoxItem->GetBottom() ||
1171 409 : pBoxItem->GetLeft() || pBoxItem->GetRight() )
1172 331 : return true;
1173 : }
1174 :
1175 559 : eState = rSet.GetItemState( ATTR_BORDER_TLBR, true, &pItem );
1176 559 : if ( eState == SfxItemState::SET )
1177 26 : if( static_cast< const SvxLineItem* >( pItem )->GetLine() )
1178 0 : return true;
1179 :
1180 559 : eState = rSet.GetItemState( ATTR_BORDER_BLTR, true, &pItem );
1181 559 : if ( eState == SfxItemState::SET )
1182 26 : if( static_cast< const SvxLineItem* >( pItem )->GetLine() )
1183 0 : return true;
1184 :
1185 559 : eState = rSet.GetItemState( ATTR_SHADOW, true, &pItem );
1186 559 : if ( eState == SfxItemState::SET )
1187 0 : if ( static_cast<const SvxShadowItem*>(pItem)->GetLocation() != SVX_SHADOW_NONE )
1188 0 : return true;
1189 :
1190 559 : return false;
1191 : }
1192 :
1193 1090210 : inline bool OneEqual( const SfxItemSet& rSet1, const SfxItemSet& rSet2, sal_uInt16 nId )
1194 : {
1195 1090210 : const SfxPoolItem* pItem1 = &rSet1.Get(nId);
1196 1090210 : const SfxPoolItem* pItem2 = &rSet2.Get(nId);
1197 1090210 : return ( pItem1 == pItem2 || *pItem1 == *pItem2 );
1198 : }
1199 :
1200 221521 : bool ScPatternAttr::IsVisibleEqual( const ScPatternAttr& rOther ) const
1201 : {
1202 221521 : const SfxItemSet& rThisSet = GetItemSet();
1203 221521 : const SfxItemSet& rOtherSet = rOther.GetItemSet();
1204 :
1205 441649 : return OneEqual( rThisSet, rOtherSet, ATTR_BACKGROUND ) &&
1206 436315 : OneEqual( rThisSet, rOtherSet, ATTR_BORDER ) &&
1207 432374 : OneEqual( rThisSet, rOtherSet, ATTR_BORDER_TLBR ) &&
1208 653895 : OneEqual( rThisSet, rOtherSet, ATTR_BORDER_BLTR ) &&
1209 437708 : OneEqual( rThisSet, rOtherSet, ATTR_SHADOW );
1210 :
1211 : //TODO: also here only check really visible values !!!
1212 : }
1213 :
1214 1441112 : const OUString* ScPatternAttr::GetStyleName() const
1215 : {
1216 1441112 : return pName ? pName : ( pStyle ? &pStyle->GetName() : NULL );
1217 : }
1218 :
1219 526017 : void ScPatternAttr::SetStyleSheet( ScStyleSheet* pNewStyle, bool bClearDirectFormat )
1220 : {
1221 526017 : if (pNewStyle)
1222 : {
1223 526017 : SfxItemSet& rPatternSet = GetItemSet();
1224 526017 : const SfxItemSet& rStyleSet = pNewStyle->GetItemSet();
1225 :
1226 526017 : if (bClearDirectFormat)
1227 : {
1228 23062143 : for (sal_uInt16 i=ATTR_PATTERN_START; i<=ATTR_PATTERN_END; i++)
1229 : {
1230 22657544 : if (rStyleSet.GetItemState(i, true) == SfxItemState::SET)
1231 2808383 : rPatternSet.ClearItem(i);
1232 : }
1233 : }
1234 526017 : rPatternSet.SetParent(&pNewStyle->GetItemSet());
1235 526017 : pStyle = pNewStyle;
1236 526017 : DELETEZ( pName );
1237 : }
1238 : else
1239 : {
1240 : OSL_FAIL( "ScPatternAttr::SetStyleSheet( NULL ) :-|" );
1241 0 : GetItemSet().SetParent(NULL);
1242 0 : pStyle = NULL;
1243 : }
1244 526017 : }
1245 :
1246 609 : void ScPatternAttr::UpdateStyleSheet(ScDocument* pDoc)
1247 : {
1248 609 : if (pName)
1249 : {
1250 609 : pStyle = static_cast<ScStyleSheet*>(pDoc->GetStyleSheetPool()->Find(*pName, SFX_STYLE_FAMILY_PARA));
1251 :
1252 : // use Standard if Style is not found,
1253 : // to avoid empty display in Toolbox-Controller
1254 : // Assumes that "Standard" is always the 1st entry!
1255 609 : if (!pStyle)
1256 : {
1257 0 : SfxStyleSheetIteratorPtr pIter = pDoc->GetStyleSheetPool()->CreateIterator( SFX_STYLE_FAMILY_PARA, SFXSTYLEBIT_ALL );
1258 0 : pStyle = dynamic_cast< ScStyleSheet* >(pIter->First());
1259 : }
1260 :
1261 609 : if (pStyle)
1262 : {
1263 609 : GetItemSet().SetParent(&pStyle->GetItemSet());
1264 609 : DELETEZ( pName );
1265 : }
1266 : }
1267 : else
1268 0 : pStyle = NULL;
1269 609 : }
1270 :
1271 0 : void ScPatternAttr::StyleToName()
1272 : {
1273 : // Style was deleted, remember name:
1274 :
1275 0 : if ( pStyle )
1276 : {
1277 0 : if ( pName )
1278 0 : *pName = pStyle->GetName();
1279 : else
1280 0 : pName = new OUString( pStyle->GetName() );
1281 :
1282 0 : pStyle = NULL;
1283 0 : GetItemSet().SetParent( NULL );
1284 : }
1285 0 : }
1286 :
1287 0 : bool ScPatternAttr::IsSymbolFont() const
1288 : {
1289 : const SfxPoolItem* pItem;
1290 0 : if( GetItemSet().GetItemState( ATTR_FONT, true, &pItem ) == SfxItemState::SET )
1291 0 : return static_cast<const SvxFontItem*>(pItem)->GetCharSet() == RTL_TEXTENCODING_SYMBOL;
1292 : else
1293 0 : return false;
1294 : }
1295 :
1296 62569 : sal_uLong ScPatternAttr::GetNumberFormat( SvNumberFormatter* pFormatter ) const
1297 : {
1298 : sal_uLong nFormat =
1299 62569 : static_cast<const SfxUInt32Item*>(&GetItemSet().Get( ATTR_VALUE_FORMAT ))->GetValue();
1300 : LanguageType eLang =
1301 62569 : static_cast<const SvxLanguageItem*>(&GetItemSet().Get( ATTR_LANGUAGE_FORMAT ))->GetLanguage();
1302 62569 : if ( nFormat < SV_COUNTRY_LANGUAGE_OFFSET && eLang == LANGUAGE_SYSTEM )
1303 : ; // it remains as it is
1304 486 : else if ( pFormatter )
1305 486 : nFormat = pFormatter->GetFormatForLanguageIfBuiltIn( nFormat, eLang );
1306 62569 : return nFormat;
1307 : }
1308 :
1309 : // the same if conditional formatting is in play:
1310 :
1311 61833 : sal_uLong ScPatternAttr::GetNumberFormat( SvNumberFormatter* pFormatter,
1312 : const SfxItemSet* pCondSet ) const
1313 : {
1314 : OSL_ENSURE(pFormatter,"GetNumberFormat without Formatter");
1315 :
1316 : const SfxPoolItem* pFormItem;
1317 61833 : if ( !pCondSet || pCondSet->GetItemState(ATTR_VALUE_FORMAT,true,&pFormItem) != SfxItemState::SET )
1318 61570 : pFormItem = &GetItemSet().Get(ATTR_VALUE_FORMAT);
1319 :
1320 : const SfxPoolItem* pLangItem;
1321 61833 : if ( !pCondSet || pCondSet->GetItemState(ATTR_LANGUAGE_FORMAT,true,&pLangItem) != SfxItemState::SET )
1322 61713 : pLangItem = &GetItemSet().Get(ATTR_LANGUAGE_FORMAT);
1323 :
1324 : return pFormatter->GetFormatForLanguageIfBuiltIn(
1325 : static_cast<const SfxUInt32Item*>(pFormItem)->GetValue(),
1326 61833 : static_cast<const SvxLanguageItem*>(pLangItem)->GetLanguage() );
1327 : }
1328 :
1329 3428506 : const SfxPoolItem& ScPatternAttr::GetItem( sal_uInt16 nWhich, const SfxItemSet& rItemSet, const SfxItemSet* pCondSet )
1330 : {
1331 : const SfxPoolItem* pCondItem;
1332 3428506 : if ( pCondSet && pCondSet->GetItemState( nWhich, true, &pCondItem ) == SfxItemState::SET )
1333 60 : return *pCondItem;
1334 3428446 : return rItemSet.Get(nWhich);
1335 : }
1336 :
1337 949509 : const SfxPoolItem& ScPatternAttr::GetItem( sal_uInt16 nSubWhich, const SfxItemSet* pCondSet ) const
1338 : {
1339 949509 : return GetItem( nSubWhich, GetItemSet(), pCondSet );
1340 : }
1341 :
1342 : // GetRotateVal is tested before ATTR_ORIENTATION
1343 :
1344 422996 : long ScPatternAttr::GetRotateVal( const SfxItemSet* pCondSet ) const
1345 : {
1346 422996 : long nAttrRotate = 0;
1347 422996 : if ( GetCellOrientation() == SVX_ORIENTATION_STANDARD )
1348 : {
1349 422996 : bool bRepeat = ( static_cast<const SvxHorJustifyItem&>(GetItem(ATTR_HOR_JUSTIFY, pCondSet)).
1350 422996 : GetValue() == SVX_HOR_JUSTIFY_REPEAT );
1351 : // ignore orientation/rotation if "repeat" is active
1352 422996 : if ( !bRepeat )
1353 422996 : nAttrRotate = static_cast<const SfxInt32Item&>(GetItem( ATTR_ROTATE_VALUE, pCondSet )).GetValue();
1354 : }
1355 422996 : return nAttrRotate;
1356 : }
1357 :
1358 422996 : sal_uInt8 ScPatternAttr::GetRotateDir( const SfxItemSet* pCondSet ) const
1359 : {
1360 422996 : sal_uInt8 nRet = SC_ROTDIR_NONE;
1361 :
1362 422996 : long nAttrRotate = GetRotateVal( pCondSet );
1363 422996 : if ( nAttrRotate )
1364 : {
1365 : SvxRotateMode eRotMode = (SvxRotateMode)static_cast<const SvxRotateModeItem&>(
1366 3906 : GetItem(ATTR_ROTATE_MODE, pCondSet)).GetValue();
1367 :
1368 3906 : if ( eRotMode == SVX_ROTATE_MODE_STANDARD || nAttrRotate == 18000 )
1369 3906 : nRet = SC_ROTDIR_STANDARD;
1370 0 : else if ( eRotMode == SVX_ROTATE_MODE_CENTER )
1371 0 : nRet = SC_ROTDIR_CENTER;
1372 0 : else if ( eRotMode == SVX_ROTATE_MODE_TOP || eRotMode == SVX_ROTATE_MODE_BOTTOM )
1373 : {
1374 0 : long nRot180 = nAttrRotate % 18000; // 1/100 degrees
1375 0 : if ( nRot180 == 9000 )
1376 0 : nRet = SC_ROTDIR_CENTER;
1377 0 : else if ( ( eRotMode == SVX_ROTATE_MODE_TOP && nRot180 < 9000 ) ||
1378 0 : ( eRotMode == SVX_ROTATE_MODE_BOTTOM && nRot180 > 9000 ) )
1379 0 : nRet = SC_ROTDIR_LEFT;
1380 : else
1381 0 : nRet = SC_ROTDIR_RIGHT;
1382 : }
1383 : }
1384 :
1385 422996 : return nRet;
1386 156 : }
1387 :
1388 : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
|