fix baseline build (old cairo) - 'cairo_rectangle_int_t' does not name a type
[LibreOffice.git] / sc / source / core / data / patattr.cxx
blobbef793eb54151028c7361f92ea7f8f3c1d9ed8a5
1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 /*
3 * This file is part of the LibreOffice project.
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/.
9 * This file incorporates work covered by the following license notice:
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 .
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>
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"
65 // STATIC DATA -----------------------------------------------------------
67 using sc::HMMToTwips;
68 using sc::TwipsToHMM;
70 ScPatternAttr::ScPatternAttr( SfxItemSet* pItemSet, const OUString& rStyleName )
71 : SfxSetItem ( ATTR_PATTERN, pItemSet ),
72 pName ( new OUString( rStyleName ) ),
73 pStyle ( NULL )
77 ScPatternAttr::ScPatternAttr( SfxItemSet* pItemSet, ScStyleSheet* pStyleSheet )
78 : SfxSetItem ( ATTR_PATTERN, pItemSet ),
79 pName ( NULL ),
80 pStyle ( pStyleSheet )
82 if ( pStyleSheet )
83 GetItemSet().SetParent( &pStyleSheet->GetItemSet() );
86 ScPatternAttr::ScPatternAttr( SfxItemPool* pItemPool )
87 : SfxSetItem ( ATTR_PATTERN, new SfxItemSet( *pItemPool, ATTR_PATTERN_START, ATTR_PATTERN_END ) ),
88 pName ( NULL ),
89 pStyle ( NULL )
93 ScPatternAttr::ScPatternAttr( const ScPatternAttr& rPatternAttr )
94 : SfxSetItem ( rPatternAttr ),
95 pStyle ( rPatternAttr.pStyle )
97 if (rPatternAttr.pName)
98 pName = new OUString(*rPatternAttr.pName);
99 else
100 pName = NULL;
103 ScPatternAttr::~ScPatternAttr()
105 delete pName;
108 SfxPoolItem* ScPatternAttr::Clone( SfxItemPool *pPool ) const
110 ScPatternAttr* pPattern = new ScPatternAttr( GetItemSet().Clone(true, pPool) );
112 pPattern->pStyle = pStyle;
113 pPattern->pName = pName ? new OUString(*pName) : NULL;
115 return pPattern;
118 inline bool StrCmp( const OUString* pStr1, const OUString* pStr2 )
120 return ( pStr1 ? ( pStr2 && ( *pStr1 == *pStr2 ) ) : ( pStr2 == nullptr ) );
123 inline bool EqualPatternSets( const SfxItemSet& rSet1, const SfxItemSet& rSet2 )
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).
129 if ( rSet1.Count() != rSet2.Count() )
130 return false;
132 SfxItemArray pItems1 = rSet1.GetItems_Impl(); // inline method of SfxItemSet
133 SfxItemArray pItems2 = rSet2.GetItems_Impl();
135 return ( 0 == memcmp( pItems1, pItems2, (ATTR_PATTERN_END - ATTR_PATTERN_START + 1) * sizeof(pItems1[0]) ) );
138 bool ScPatternAttr::operator==( const SfxPoolItem& rCmp ) const
140 // #i62090# Use quick comparison between ScPatternAttr's ItemSets
142 return ( EqualPatternSets( GetItemSet(), static_cast<const ScPatternAttr&>(rCmp).GetItemSet() ) &&
143 StrCmp( GetStyleName(), static_cast<const ScPatternAttr&>(rCmp).GetStyleName() ) );
146 SfxPoolItem* ScPatternAttr::Create( SvStream& rStream, sal_uInt16 /* nVersion */ ) const
148 OUString* pStr;
149 bool bHasStyle;
151 rStream.ReadCharAsBool( bHasStyle );
153 if ( bHasStyle )
155 short eFamDummy;
156 pStr = new OUString;
157 *pStr = rStream.ReadUniOrByteString( rStream.GetStreamCharSet() );
158 rStream.ReadInt16( eFamDummy ); // due to old data format
160 else
161 pStr = new OUString( ScGlobal::GetRscString(STR_STYLENAME_STANDARD) );
163 SfxItemSet *pNewSet = new SfxItemSet( *GetItemSet().GetPool(),
164 ATTR_PATTERN_START, ATTR_PATTERN_END );
165 pNewSet->Load( rStream );
167 ScPatternAttr* pPattern = new ScPatternAttr( pNewSet );
169 pPattern->pName = pStr;
171 return pPattern;
174 SvStream& ScPatternAttr::Store(SvStream& rStream, sal_uInt16 /* nItemVersion */) const
176 rStream.WriteBool( true );
178 if ( pStyle )
179 rStream.WriteUniOrByteString( pStyle->GetName(), rStream.GetStreamCharSet() );
180 else if ( pName ) // when style is/was deleted
181 rStream.WriteUniOrByteString( *pName, rStream.GetStreamCharSet() );
182 else
183 rStream.WriteUniOrByteString( ScGlobal::GetRscString(STR_STYLENAME_STANDARD),
184 rStream.GetStreamCharSet() );
186 rStream.WriteInt16( SFX_STYLE_FAMILY_PARA ); // due to old data format
188 GetItemSet().Store( rStream );
190 return rStream;
193 SvxCellOrientation ScPatternAttr::GetCellOrientation( const SfxItemSet& rItemSet, const SfxItemSet* pCondSet )
195 SvxCellOrientation eOrient = SVX_ORIENTATION_STANDARD;
197 if( static_cast<const SfxBoolItem&>(GetItem( ATTR_STACKED, rItemSet, pCondSet )).GetValue() )
199 eOrient = SVX_ORIENTATION_STACKED;
201 else
203 sal_Int32 nAngle = static_cast<const SfxInt32Item&>(GetItem( ATTR_ROTATE_VALUE, rItemSet, pCondSet )).GetValue();
204 if( nAngle == 9000 )
205 eOrient = SVX_ORIENTATION_BOTTOMTOP;
206 else if( nAngle == 27000 )
207 eOrient = SVX_ORIENTATION_TOPBOTTOM;
210 return eOrient;
213 SvxCellOrientation ScPatternAttr::GetCellOrientation( const SfxItemSet* pCondSet ) const
215 return GetCellOrientation( GetItemSet(), pCondSet );
218 namespace {
220 void getFontIDsByScriptType(SvtScriptType nScript,
221 sal_uInt16& nFontId, sal_uInt16& nHeightId, sal_uInt16& nWeightId, sal_uInt16& nPostureId, sal_uInt16& nLangId)
223 if ( nScript == SvtScriptType::ASIAN )
225 nFontId = ATTR_CJK_FONT;
226 nHeightId = ATTR_CJK_FONT_HEIGHT;
227 nWeightId = ATTR_CJK_FONT_WEIGHT;
228 nPostureId = ATTR_CJK_FONT_POSTURE;
229 nLangId = ATTR_CJK_FONT_LANGUAGE;
231 else if ( nScript == SvtScriptType::COMPLEX )
233 nFontId = ATTR_CTL_FONT;
234 nHeightId = ATTR_CTL_FONT_HEIGHT;
235 nWeightId = ATTR_CTL_FONT_WEIGHT;
236 nPostureId = ATTR_CTL_FONT_POSTURE;
237 nLangId = ATTR_CTL_FONT_LANGUAGE;
239 else
241 nFontId = ATTR_FONT;
242 nHeightId = ATTR_FONT_HEIGHT;
243 nWeightId = ATTR_FONT_WEIGHT;
244 nPostureId = ATTR_FONT_POSTURE;
245 nLangId = ATTR_FONT_LANGUAGE;
251 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 )
257 // Read items
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 Color aColor;
272 LanguageType eLang;
274 sal_uInt16 nFontId, nHeightId, nWeightId, nPostureId, nLangId;
275 getFontIDsByScriptType(nScript, nFontId, nHeightId, nWeightId, nPostureId, nLangId);
277 if ( pCondSet )
279 const SfxPoolItem* pItem;
281 if ( pCondSet->GetItemState( nFontId, true, &pItem ) != SfxItemState::SET )
282 pItem = &rItemSet.Get( nFontId );
283 pFontAttr = static_cast<const SvxFontItem*>(pItem);
285 if ( pCondSet->GetItemState( nHeightId, true, &pItem ) != SfxItemState::SET )
286 pItem = &rItemSet.Get( nHeightId );
287 nFontHeight = static_cast<const SvxFontHeightItem*>(pItem)->GetHeight();
289 if ( pCondSet->GetItemState( nWeightId, true, &pItem ) != SfxItemState::SET )
290 pItem = &rItemSet.Get( nWeightId );
291 eWeight = (FontWeight)static_cast<const SvxWeightItem*>(pItem)->GetValue();
293 if ( pCondSet->GetItemState( nPostureId, true, &pItem ) != SfxItemState::SET )
294 pItem = &rItemSet.Get( nPostureId );
295 eItalic = (FontItalic)static_cast<const SvxPostureItem*>(pItem)->GetValue();
297 if ( pCondSet->GetItemState( ATTR_FONT_UNDERLINE, true, &pItem ) != SfxItemState::SET )
298 pItem = &rItemSet.Get( ATTR_FONT_UNDERLINE );
299 eUnder = (FontUnderline)static_cast<const SvxUnderlineItem*>(pItem)->GetValue();
301 if ( pCondSet->GetItemState( ATTR_FONT_OVERLINE, true, &pItem ) != SfxItemState::SET )
302 pItem = &rItemSet.Get( ATTR_FONT_OVERLINE );
303 eOver = (FontUnderline)static_cast<const SvxOverlineItem*>(pItem)->GetValue();
305 if ( pCondSet->GetItemState( ATTR_FONT_WORDLINE, true, &pItem ) != SfxItemState::SET )
306 pItem = &rItemSet.Get( ATTR_FONT_WORDLINE );
307 bWordLine = static_cast<const SvxWordLineModeItem*>(pItem)->GetValue();
309 if ( pCondSet->GetItemState( ATTR_FONT_CROSSEDOUT, true, &pItem ) != SfxItemState::SET )
310 pItem = &rItemSet.Get( ATTR_FONT_CROSSEDOUT );
311 eStrike = (FontStrikeout)static_cast<const SvxCrossedOutItem*>(pItem)->GetValue();
313 if ( pCondSet->GetItemState( ATTR_FONT_CONTOUR, true, &pItem ) != SfxItemState::SET )
314 pItem = &rItemSet.Get( ATTR_FONT_CONTOUR );
315 bOutline = static_cast<const SvxContourItem*>(pItem)->GetValue();
317 if ( pCondSet->GetItemState( ATTR_FONT_SHADOWED, true, &pItem ) != SfxItemState::SET )
318 pItem = &rItemSet.Get( ATTR_FONT_SHADOWED );
319 bShadow = static_cast<const SvxShadowedItem*>(pItem)->GetValue();
321 if ( pCondSet->GetItemState( ATTR_FONT_EMPHASISMARK, true, &pItem ) != SfxItemState::SET )
322 pItem = &rItemSet.Get( ATTR_FONT_EMPHASISMARK );
323 eEmphasis = static_cast<const SvxEmphasisMarkItem*>(pItem)->GetEmphasisMark();
325 if ( pCondSet->GetItemState( ATTR_FONT_RELIEF, true, &pItem ) != SfxItemState::SET )
326 pItem = &rItemSet.Get( ATTR_FONT_RELIEF );
327 eRelief = (FontRelief)static_cast<const SvxCharReliefItem*>(pItem)->GetValue();
329 if ( pCondSet->GetItemState( ATTR_FONT_COLOR, true, &pItem ) != SfxItemState::SET )
330 pItem = &rItemSet.Get( ATTR_FONT_COLOR );
331 aColor = static_cast<const SvxColorItem*>(pItem)->GetValue();
333 if ( pCondSet->GetItemState( nLangId, true, &pItem ) != SfxItemState::SET )
334 pItem = &rItemSet.Get( nLangId );
335 eLang = static_cast<const SvxLanguageItem*>(pItem)->GetLanguage();
337 else // Everything from rItemSet
339 pFontAttr = &static_cast<const SvxFontItem&>(rItemSet.Get( nFontId ));
340 nFontHeight = static_cast<const SvxFontHeightItem&>(
341 rItemSet.Get( nHeightId )).GetHeight();
342 eWeight = (FontWeight)static_cast<const SvxWeightItem&>(
343 rItemSet.Get( nWeightId )).GetValue();
344 eItalic = (FontItalic)static_cast<const SvxPostureItem&>(
345 rItemSet.Get( nPostureId )).GetValue();
346 eUnder = (FontUnderline)static_cast<const SvxUnderlineItem&>(
347 rItemSet.Get( ATTR_FONT_UNDERLINE )).GetValue();
348 eOver = (FontUnderline)static_cast<const SvxOverlineItem&>(
349 rItemSet.Get( ATTR_FONT_OVERLINE )).GetValue();
350 bWordLine = static_cast<const SvxWordLineModeItem&>(
351 rItemSet.Get( ATTR_FONT_WORDLINE )).GetValue();
352 eStrike = (FontStrikeout)static_cast<const SvxCrossedOutItem&>(
353 rItemSet.Get( ATTR_FONT_CROSSEDOUT )).GetValue();
354 bOutline = static_cast<const SvxContourItem&>(
355 rItemSet.Get( ATTR_FONT_CONTOUR )).GetValue();
356 bShadow = static_cast<const SvxShadowedItem&>(
357 rItemSet.Get( ATTR_FONT_SHADOWED )).GetValue();
358 eEmphasis = static_cast<const SvxEmphasisMarkItem&>(
359 rItemSet.Get( ATTR_FONT_EMPHASISMARK )).GetEmphasisMark();
360 eRelief = (FontRelief)static_cast<const SvxCharReliefItem&>(
361 rItemSet.Get( ATTR_FONT_RELIEF )).GetValue();
362 aColor = static_cast<const SvxColorItem&>(
363 rItemSet.Get( ATTR_FONT_COLOR )).GetValue();
364 // for graphite language features
365 eLang = static_cast<const SvxLanguageItem&>(rItemSet.Get( nLangId )).GetLanguage();
367 OSL_ENSURE(pFontAttr,"Oops?");
369 // Evaluate
371 // FontItem:
373 if (rFont.GetName() != pFontAttr->GetFamilyName())
374 rFont.SetName( pFontAttr->GetFamilyName() );
375 if (rFont.GetStyleName() != pFontAttr->GetStyleName())
376 rFont.SetStyleName( pFontAttr->GetStyleName() );
378 rFont.SetFamily( pFontAttr->GetFamily() );
379 rFont.SetCharSet( pFontAttr->GetCharSet() );
380 rFont.SetPitch( pFontAttr->GetPitch() );
382 rFont.SetLanguage(eLang);
384 // Size
386 if ( pOutDev != NULL )
388 Size aEffSize;
389 Fraction aFraction( 1,1 );
390 if (pScale)
391 aFraction = *pScale;
392 Size aSize( 0, (long) nFontHeight );
393 MapMode aDestMode = pOutDev->GetMapMode();
394 MapMode aSrcMode( MAP_TWIP, Point(), aFraction, aFraction );
395 if (aDestMode.GetMapUnit() == MAP_PIXEL)
396 aEffSize = pOutDev->LogicToPixel( aSize, aSrcMode );
397 else
399 Fraction aFractOne(1,1);
400 aDestMode.SetScaleX( aFractOne );
401 aDestMode.SetScaleY( aFractOne );
402 aEffSize = OutputDevice::LogicToLogic( aSize, aSrcMode, aDestMode );
404 rFont.SetSize( aEffSize );
406 else /* if pOutDev != NULL */
408 rFont.SetSize( Size( 0, (long) nFontHeight ) );
411 // determine effective font color
413 if ( ( aColor.GetColor() == COL_AUTO && eAutoMode != SC_AUTOCOL_RAW ) ||
414 eAutoMode == SC_AUTOCOL_IGNOREFONT || eAutoMode == SC_AUTOCOL_IGNOREALL )
416 if ( eAutoMode == SC_AUTOCOL_BLACK )
417 aColor.SetColor( COL_BLACK );
418 else
420 // get background color from conditional or own set
421 Color aBackColor;
422 if ( pCondSet )
424 const SfxPoolItem* pItem;
425 if ( pCondSet->GetItemState( ATTR_BACKGROUND, true, &pItem ) != SfxItemState::SET )
426 pItem = &rItemSet.Get( ATTR_BACKGROUND );
427 aBackColor = static_cast<const SvxBrushItem*>(pItem)->GetColor();
429 else
430 aBackColor = static_cast<const SvxBrushItem&>(rItemSet.Get( ATTR_BACKGROUND )).GetColor();
432 // if background color attribute is transparent, use window color for brightness comparisons
433 if ( aBackColor == COL_TRANSPARENT ||
434 eAutoMode == SC_AUTOCOL_IGNOREBACK || eAutoMode == SC_AUTOCOL_IGNOREALL )
436 if ( eAutoMode == SC_AUTOCOL_PRINT )
437 aBackColor.SetColor( COL_WHITE );
438 else if ( pBackConfigColor )
440 // pBackConfigColor can be used to avoid repeated lookup of the configured color
441 aBackColor = *pBackConfigColor;
443 else
444 aBackColor.SetColor( SC_MOD()->GetColorConfig().GetColorValue(svtools::DOCCOLOR).nColor );
447 // get system text color for comparison
448 Color aSysTextColor;
449 if ( eAutoMode == SC_AUTOCOL_PRINT )
450 aSysTextColor.SetColor( COL_BLACK );
451 else if ( pTextConfigColor )
453 // pTextConfigColor can be used to avoid repeated lookup of the configured color
454 aSysTextColor = *pTextConfigColor;
456 else
457 aSysTextColor.SetColor( SC_MOD()->GetColorConfig().GetColorValue(svtools::FONTCOLOR).nColor );
459 // select the resulting color
460 if ( aBackColor.IsDark() && aSysTextColor.IsDark() )
462 // use white instead of dark on dark
463 aColor.SetColor( COL_WHITE );
465 else if ( aBackColor.IsBright() && aSysTextColor.IsBright() )
467 // use black instead of bright on bright
468 aColor.SetColor( COL_BLACK );
470 else
472 // use aSysTextColor (black for SC_AUTOCOL_PRINT, from style settings otherwise)
473 aColor = aSysTextColor;
478 // set font effects
479 rFont.SetWeight( eWeight );
480 rFont.SetItalic( eItalic );
481 rFont.SetUnderline( eUnder );
482 rFont.SetOverline( eOver );
483 rFont.SetWordLineMode( bWordLine );
484 rFont.SetStrikeout( eStrike );
485 rFont.SetOutline( bOutline );
486 rFont.SetShadow( bShadow );
487 rFont.SetEmphasisMark( eEmphasis );
488 rFont.SetRelief( eRelief );
489 rFont.SetColor( aColor );
490 rFont.SetTransparent( true );
493 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
499 GetFont( rFont, GetItemSet(), eAutoMode, pOutDev, pScale, pCondSet, nScript, pBackConfigColor, pTextConfigColor );
502 ScDxfFont ScPatternAttr::GetDxfFont(const SfxItemSet& rItemSet, SvtScriptType nScript)
504 sal_uInt16 nFontId, nHeightId, nWeightId, nPostureId, nLangId;
505 getFontIDsByScriptType(nScript, nFontId, nHeightId, nWeightId, nPostureId, nLangId);
506 const SfxPoolItem* pItem;
508 ScDxfFont aReturn;
510 if ( rItemSet.GetItemState( nFontId, true, &pItem ) == SfxItemState::SET )
512 pItem = &rItemSet.Get( nFontId );
513 aReturn.pFontAttr = static_cast<const SvxFontItem*>(pItem);
516 if ( rItemSet.GetItemState( nHeightId, true, &pItem ) == SfxItemState::SET )
518 pItem = &rItemSet.Get( nHeightId );
519 aReturn.nFontHeight = static_cast<const SvxFontHeightItem*>(pItem)->GetHeight();
522 if ( rItemSet.GetItemState( nWeightId, true, &pItem ) == SfxItemState::SET )
524 pItem = &rItemSet.Get( nWeightId );
525 aReturn.eWeight = (FontWeight)static_cast<const SvxWeightItem*>(pItem)->GetValue();
528 if ( rItemSet.GetItemState( nPostureId, true, &pItem ) == SfxItemState::SET )
530 pItem = &rItemSet.Get( nPostureId );
531 aReturn.eItalic = (FontItalic)static_cast<const SvxPostureItem*>(pItem)->GetValue();
534 if ( rItemSet.GetItemState( ATTR_FONT_UNDERLINE, true, &pItem ) == SfxItemState::SET )
536 pItem = &rItemSet.Get( ATTR_FONT_UNDERLINE );
537 aReturn.eUnder = (FontUnderline)static_cast<const SvxUnderlineItem*>(pItem)->GetValue();
540 if ( rItemSet.GetItemState( ATTR_FONT_OVERLINE, true, &pItem ) == SfxItemState::SET )
542 pItem = &rItemSet.Get( ATTR_FONT_OVERLINE );
543 aReturn.eOver = (FontUnderline)static_cast<const SvxOverlineItem*>(pItem)->GetValue();
546 if ( rItemSet.GetItemState( ATTR_FONT_WORDLINE, true, &pItem ) == SfxItemState::SET )
548 pItem = &rItemSet.Get( ATTR_FONT_WORDLINE );
549 aReturn.bWordLine = static_cast<const SvxWordLineModeItem*>(pItem)->GetValue();
552 if ( rItemSet.GetItemState( ATTR_FONT_CROSSEDOUT, true, &pItem ) == SfxItemState::SET )
554 pItem = &rItemSet.Get( ATTR_FONT_CROSSEDOUT );
555 aReturn.eStrike = (FontStrikeout)static_cast<const SvxCrossedOutItem*>(pItem)->GetValue();
558 if ( rItemSet.GetItemState( ATTR_FONT_CONTOUR, true, &pItem ) == SfxItemState::SET )
560 pItem = &rItemSet.Get( ATTR_FONT_CONTOUR );
561 aReturn.bOutline = static_cast<const SvxContourItem*>(pItem)->GetValue();
564 if ( rItemSet.GetItemState( ATTR_FONT_SHADOWED, true, &pItem ) == SfxItemState::SET )
566 pItem = &rItemSet.Get( ATTR_FONT_SHADOWED );
567 aReturn.bShadow = static_cast<const SvxShadowedItem*>(pItem)->GetValue();
570 if ( rItemSet.GetItemState( ATTR_FONT_EMPHASISMARK, true, &pItem ) == SfxItemState::SET )
572 pItem = &rItemSet.Get( ATTR_FONT_EMPHASISMARK );
573 aReturn.eEmphasis = static_cast<const SvxEmphasisMarkItem*>(pItem)->GetEmphasisMark();
576 if ( rItemSet.GetItemState( ATTR_FONT_RELIEF, true, &pItem ) == SfxItemState::SET )
578 pItem = &rItemSet.Get( ATTR_FONT_RELIEF );
579 aReturn.eRelief = (FontRelief)static_cast<const SvxCharReliefItem*>(pItem)->GetValue();
582 if ( rItemSet.GetItemState( ATTR_FONT_COLOR, true, &pItem ) == SfxItemState::SET )
584 pItem = &rItemSet.Get( ATTR_FONT_COLOR );
585 aReturn.aColor = static_cast<const SvxColorItem*>(pItem)->GetValue();
588 if ( rItemSet.GetItemState( nLangId, true, &pItem ) == SfxItemState::SET )
590 pItem = &rItemSet.Get( nLangId );
591 aReturn.eLang = static_cast<const SvxLanguageItem*>(pItem)->GetLanguage();
594 return aReturn;
597 void ScPatternAttr::FillToEditItemSet( SfxItemSet& rEditSet, const SfxItemSet& rSrcSet, const SfxItemSet* pCondSet )
599 // Read Items
601 SvxColorItem aColorItem(EE_CHAR_COLOR); // use item as-is
602 SvxFontItem aFontItem(EE_CHAR_FONTINFO); // use item as-is
603 SvxFontItem aCjkFontItem(EE_CHAR_FONTINFO_CJK);
604 SvxFontItem aCtlFontItem(EE_CHAR_FONTINFO_CTL);
605 long nTHeight, nCjkTHeight, nCtlTHeight; // Twips
606 FontWeight eWeight, eCjkWeight, eCtlWeight;
607 SvxUnderlineItem aUnderlineItem(UNDERLINE_NONE, EE_CHAR_UNDERLINE);
608 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;
621 //TODO: additional parameter to control if language is needed?
623 if ( pCondSet )
625 const SfxPoolItem* pItem;
627 if ( pCondSet->GetItemState( ATTR_FONT_COLOR, true, &pItem ) != SfxItemState::SET )
628 pItem = &rSrcSet.Get( ATTR_FONT_COLOR );
629 aColorItem = *static_cast<const SvxColorItem*>(pItem);
631 if ( pCondSet->GetItemState( ATTR_FONT, true, &pItem ) != SfxItemState::SET )
632 pItem = &rSrcSet.Get( ATTR_FONT );
633 aFontItem = *static_cast<const SvxFontItem*>(pItem);
634 if ( pCondSet->GetItemState( ATTR_CJK_FONT, true, &pItem ) != SfxItemState::SET )
635 pItem = &rSrcSet.Get( ATTR_CJK_FONT );
636 aCjkFontItem = *static_cast<const SvxFontItem*>(pItem);
637 if ( pCondSet->GetItemState( ATTR_CTL_FONT, true, &pItem ) != SfxItemState::SET )
638 pItem = &rSrcSet.Get( ATTR_CTL_FONT );
639 aCtlFontItem = *static_cast<const SvxFontItem*>(pItem);
641 if ( pCondSet->GetItemState( ATTR_FONT_HEIGHT, true, &pItem ) != SfxItemState::SET )
642 pItem = &rSrcSet.Get( ATTR_FONT_HEIGHT );
643 nTHeight = static_cast<const SvxFontHeightItem*>(pItem)->GetHeight();
644 if ( pCondSet->GetItemState( ATTR_CJK_FONT_HEIGHT, true, &pItem ) != SfxItemState::SET )
645 pItem = &rSrcSet.Get( ATTR_CJK_FONT_HEIGHT );
646 nCjkTHeight = static_cast<const SvxFontHeightItem*>(pItem)->GetHeight();
647 if ( pCondSet->GetItemState( ATTR_CTL_FONT_HEIGHT, true, &pItem ) != SfxItemState::SET )
648 pItem = &rSrcSet.Get( ATTR_CTL_FONT_HEIGHT );
649 nCtlTHeight = static_cast<const SvxFontHeightItem*>(pItem)->GetHeight();
651 if ( pCondSet->GetItemState( ATTR_FONT_WEIGHT, true, &pItem ) != SfxItemState::SET )
652 pItem = &rSrcSet.Get( ATTR_FONT_WEIGHT );
653 eWeight = (FontWeight)static_cast<const SvxWeightItem*>(pItem)->GetValue();
654 if ( pCondSet->GetItemState( ATTR_CJK_FONT_WEIGHT, true, &pItem ) != SfxItemState::SET )
655 pItem = &rSrcSet.Get( ATTR_CJK_FONT_WEIGHT );
656 eCjkWeight = (FontWeight)static_cast<const SvxWeightItem*>(pItem)->GetValue();
657 if ( pCondSet->GetItemState( ATTR_CTL_FONT_WEIGHT, true, &pItem ) != SfxItemState::SET )
658 pItem = &rSrcSet.Get( ATTR_CTL_FONT_WEIGHT );
659 eCtlWeight = (FontWeight)static_cast<const SvxWeightItem*>(pItem)->GetValue();
661 if ( pCondSet->GetItemState( ATTR_FONT_POSTURE, true, &pItem ) != SfxItemState::SET )
662 pItem = &rSrcSet.Get( ATTR_FONT_POSTURE );
663 eItalic = (FontItalic)static_cast<const SvxPostureItem*>(pItem)->GetValue();
664 if ( pCondSet->GetItemState( ATTR_CJK_FONT_POSTURE, true, &pItem ) != SfxItemState::SET )
665 pItem = &rSrcSet.Get( ATTR_CJK_FONT_POSTURE );
666 eCjkItalic = (FontItalic)static_cast<const SvxPostureItem*>(pItem)->GetValue();
667 if ( pCondSet->GetItemState( ATTR_CTL_FONT_POSTURE, true, &pItem ) != SfxItemState::SET )
668 pItem = &rSrcSet.Get( ATTR_CTL_FONT_POSTURE );
669 eCtlItalic = (FontItalic)static_cast<const SvxPostureItem*>(pItem)->GetValue();
671 if ( pCondSet->GetItemState( ATTR_FONT_UNDERLINE, true, &pItem ) != SfxItemState::SET )
672 pItem = &rSrcSet.Get( ATTR_FONT_UNDERLINE );
673 aUnderlineItem = *static_cast<const SvxUnderlineItem*>(pItem);
675 if ( pCondSet->GetItemState( ATTR_FONT_OVERLINE, true, &pItem ) != SfxItemState::SET )
676 pItem = &rSrcSet.Get( ATTR_FONT_OVERLINE );
677 aOverlineItem = *static_cast<const SvxOverlineItem*>(pItem);
679 if ( pCondSet->GetItemState( ATTR_FONT_WORDLINE, true, &pItem ) != SfxItemState::SET )
680 pItem = &rSrcSet.Get( ATTR_FONT_WORDLINE );
681 bWordLine = static_cast<const SvxWordLineModeItem*>(pItem)->GetValue();
683 if ( pCondSet->GetItemState( ATTR_FONT_CROSSEDOUT, true, &pItem ) != SfxItemState::SET )
684 pItem = &rSrcSet.Get( ATTR_FONT_CROSSEDOUT );
685 eStrike = (FontStrikeout)static_cast<const SvxCrossedOutItem*>(pItem)->GetValue();
687 if ( pCondSet->GetItemState( ATTR_FONT_CONTOUR, true, &pItem ) != SfxItemState::SET )
688 pItem = &rSrcSet.Get( ATTR_FONT_CONTOUR );
689 bOutline = static_cast<const SvxContourItem*>(pItem)->GetValue();
691 if ( pCondSet->GetItemState( ATTR_FONT_SHADOWED, true, &pItem ) != SfxItemState::SET )
692 pItem = &rSrcSet.Get( ATTR_FONT_SHADOWED );
693 bShadow = static_cast<const SvxShadowedItem*>(pItem)->GetValue();
695 if ( pCondSet->GetItemState( ATTR_FORBIDDEN_RULES, true, &pItem ) != SfxItemState::SET )
696 pItem = &rSrcSet.Get( ATTR_FORBIDDEN_RULES );
697 bForbidden = static_cast<const SvxForbiddenRuleItem*>(pItem)->GetValue();
699 if ( pCondSet->GetItemState( ATTR_FONT_EMPHASISMARK, true, &pItem ) != SfxItemState::SET )
700 pItem = &rSrcSet.Get( ATTR_FONT_EMPHASISMARK );
701 eEmphasis = static_cast<const SvxEmphasisMarkItem*>(pItem)->GetEmphasisMark();
702 if ( pCondSet->GetItemState( ATTR_FONT_RELIEF, true, &pItem ) != SfxItemState::SET )
703 pItem = &rSrcSet.Get( ATTR_FONT_RELIEF );
704 eRelief = (FontRelief)static_cast<const SvxCharReliefItem*>(pItem)->GetValue();
706 if ( pCondSet->GetItemState( ATTR_FONT_LANGUAGE, true, &pItem ) != SfxItemState::SET )
707 pItem = &rSrcSet.Get( ATTR_FONT_LANGUAGE );
708 eLang = static_cast<const SvxLanguageItem*>(pItem)->GetLanguage();
709 if ( pCondSet->GetItemState( ATTR_CJK_FONT_LANGUAGE, true, &pItem ) != SfxItemState::SET )
710 pItem = &rSrcSet.Get( ATTR_CJK_FONT_LANGUAGE );
711 eCjkLang = static_cast<const SvxLanguageItem*>(pItem)->GetLanguage();
712 if ( pCondSet->GetItemState( ATTR_CTL_FONT_LANGUAGE, true, &pItem ) != SfxItemState::SET )
713 pItem = &rSrcSet.Get( ATTR_CTL_FONT_LANGUAGE );
714 eCtlLang = static_cast<const SvxLanguageItem*>(pItem)->GetLanguage();
716 if ( pCondSet->GetItemState( ATTR_HYPHENATE, true, &pItem ) != SfxItemState::SET )
717 pItem = &rSrcSet.Get( ATTR_HYPHENATE );
718 bHyphenate = static_cast<const SfxBoolItem*>(pItem)->GetValue();
720 if ( pCondSet->GetItemState( ATTR_WRITINGDIR, true, &pItem ) != SfxItemState::SET )
721 pItem = &rSrcSet.Get( ATTR_WRITINGDIR );
722 eDirection = (SvxFrameDirection)static_cast<const SvxFrameDirectionItem*>(pItem)->GetValue();
724 else // Everything directly from Pattern
726 aColorItem = static_cast<const SvxColorItem&>( rSrcSet.Get( ATTR_FONT_COLOR ) );
727 aFontItem = static_cast<const SvxFontItem&>( rSrcSet.Get( ATTR_FONT ) );
728 aCjkFontItem = static_cast<const SvxFontItem&>( rSrcSet.Get( ATTR_CJK_FONT ) );
729 aCtlFontItem = static_cast<const SvxFontItem&>( rSrcSet.Get( ATTR_CTL_FONT ) );
730 nTHeight = static_cast<const SvxFontHeightItem&>(
731 rSrcSet.Get( ATTR_FONT_HEIGHT )).GetHeight();
732 nCjkTHeight = static_cast<const SvxFontHeightItem&>(
733 rSrcSet.Get( ATTR_CJK_FONT_HEIGHT )).GetHeight();
734 nCtlTHeight = static_cast<const SvxFontHeightItem&>(
735 rSrcSet.Get( ATTR_CTL_FONT_HEIGHT )).GetHeight();
736 eWeight = (FontWeight)static_cast<const SvxWeightItem&>(
737 rSrcSet.Get( ATTR_FONT_WEIGHT )).GetValue();
738 eCjkWeight = (FontWeight)static_cast<const SvxWeightItem&>(
739 rSrcSet.Get( ATTR_CJK_FONT_WEIGHT )).GetValue();
740 eCtlWeight = (FontWeight)static_cast<const SvxWeightItem&>(
741 rSrcSet.Get( ATTR_CTL_FONT_WEIGHT )).GetValue();
742 eItalic = (FontItalic)static_cast<const SvxPostureItem&>(
743 rSrcSet.Get( ATTR_FONT_POSTURE )).GetValue();
744 eCjkItalic = (FontItalic)static_cast<const SvxPostureItem&>(
745 rSrcSet.Get( ATTR_CJK_FONT_POSTURE )).GetValue();
746 eCtlItalic = (FontItalic)static_cast<const SvxPostureItem&>(
747 rSrcSet.Get( ATTR_CTL_FONT_POSTURE )).GetValue();
748 aUnderlineItem = static_cast<const SvxUnderlineItem&>( rSrcSet.Get( ATTR_FONT_UNDERLINE ) );
749 aOverlineItem = static_cast<const SvxOverlineItem&>( rSrcSet.Get( ATTR_FONT_OVERLINE ) );
750 bWordLine = static_cast<const SvxWordLineModeItem&>(
751 rSrcSet.Get( ATTR_FONT_WORDLINE )).GetValue();
752 eStrike = (FontStrikeout)static_cast<const SvxCrossedOutItem&>(
753 rSrcSet.Get( ATTR_FONT_CROSSEDOUT )).GetValue();
754 bOutline = static_cast<const SvxContourItem&>(
755 rSrcSet.Get( ATTR_FONT_CONTOUR )).GetValue();
756 bShadow = static_cast<const SvxShadowedItem&>(
757 rSrcSet.Get( ATTR_FONT_SHADOWED )).GetValue();
758 bForbidden = static_cast<const SvxForbiddenRuleItem&>(
759 rSrcSet.Get( ATTR_FORBIDDEN_RULES )).GetValue();
760 eEmphasis = static_cast<const SvxEmphasisMarkItem&>(
761 rSrcSet.Get( ATTR_FONT_EMPHASISMARK )).GetEmphasisMark();
762 eRelief = (FontRelief)static_cast<const SvxCharReliefItem&>(
763 rSrcSet.Get( ATTR_FONT_RELIEF )).GetValue();
764 eLang = static_cast<const SvxLanguageItem&>(
765 rSrcSet.Get( ATTR_FONT_LANGUAGE )).GetLanguage();
766 eCjkLang = static_cast<const SvxLanguageItem&>(
767 rSrcSet.Get( ATTR_CJK_FONT_LANGUAGE )).GetLanguage();
768 eCtlLang = static_cast<const SvxLanguageItem&>(
769 rSrcSet.Get( ATTR_CTL_FONT_LANGUAGE )).GetLanguage();
770 bHyphenate = static_cast<const SfxBoolItem&>(
771 rSrcSet.Get( ATTR_HYPHENATE )).GetValue();
772 eDirection = (SvxFrameDirection)static_cast<const SvxFrameDirectionItem&>(
773 rSrcSet.Get( ATTR_WRITINGDIR )).GetValue();
776 // Expect to be compatible to LogicToLogic, ie. 2540/1440 = 127/72, and round
778 long nHeight = TwipsToHMM(nTHeight);
779 long nCjkHeight = TwipsToHMM(nCjkTHeight);
780 long nCtlHeight = TwipsToHMM(nCtlTHeight);
782 // put items into EditEngine ItemSet
784 if ( aColorItem.GetValue().GetColor() == COL_AUTO )
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 rEditSet.ClearItem( EE_CHAR_COLOR );
793 else
794 rEditSet.Put( aColorItem );
795 rEditSet.Put( aFontItem );
796 rEditSet.Put( aCjkFontItem );
797 rEditSet.Put( aCtlFontItem );
798 rEditSet.Put( SvxFontHeightItem( nHeight, 100, EE_CHAR_FONTHEIGHT ) );
799 rEditSet.Put( SvxFontHeightItem( nCjkHeight, 100, EE_CHAR_FONTHEIGHT_CJK ) );
800 rEditSet.Put( SvxFontHeightItem( nCtlHeight, 100, EE_CHAR_FONTHEIGHT_CTL ) );
801 rEditSet.Put( SvxWeightItem ( eWeight, EE_CHAR_WEIGHT ) );
802 rEditSet.Put( SvxWeightItem ( eCjkWeight, EE_CHAR_WEIGHT_CJK ) );
803 rEditSet.Put( SvxWeightItem ( eCtlWeight, EE_CHAR_WEIGHT_CTL ) );
804 rEditSet.Put( aUnderlineItem );
805 rEditSet.Put( aOverlineItem );
806 rEditSet.Put( SvxWordLineModeItem( bWordLine, EE_CHAR_WLM ) );
807 rEditSet.Put( SvxCrossedOutItem( eStrike, EE_CHAR_STRIKEOUT ) );
808 rEditSet.Put( SvxPostureItem ( eItalic, EE_CHAR_ITALIC ) );
809 rEditSet.Put( SvxPostureItem ( eCjkItalic, EE_CHAR_ITALIC_CJK ) );
810 rEditSet.Put( SvxPostureItem ( eCtlItalic, EE_CHAR_ITALIC_CTL ) );
811 rEditSet.Put( SvxContourItem ( bOutline, EE_CHAR_OUTLINE ) );
812 rEditSet.Put( SvxShadowedItem ( bShadow, EE_CHAR_SHADOW ) );
813 rEditSet.Put( SfxBoolItem ( EE_PARA_FORBIDDENRULES, bForbidden ) );
814 rEditSet.Put( SvxEmphasisMarkItem( eEmphasis, EE_CHAR_EMPHASISMARK ) );
815 rEditSet.Put( SvxCharReliefItem( eRelief, EE_CHAR_RELIEF ) );
816 rEditSet.Put( SvxLanguageItem ( eLang, EE_CHAR_LANGUAGE ) );
817 rEditSet.Put( SvxLanguageItem ( eCjkLang, EE_CHAR_LANGUAGE_CJK ) );
818 rEditSet.Put( SvxLanguageItem ( eCtlLang, EE_CHAR_LANGUAGE_CTL ) );
819 rEditSet.Put( SfxBoolItem ( EE_PARA_HYPHENATE, bHyphenate ) );
820 rEditSet.Put( SvxFrameDirectionItem( eDirection, EE_PARA_WRITINGDIR ) );
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 rEditSet.Put( SvxScriptSpaceItem( false, EE_PARA_ASIANCJKSPACING ) );
830 void ScPatternAttr::FillEditItemSet( SfxItemSet* pEditSet, const SfxItemSet* pCondSet ) const
832 if( pEditSet )
833 FillToEditItemSet( *pEditSet, GetItemSet(), pCondSet );
836 void ScPatternAttr::GetFromEditItemSet( SfxItemSet& rDestSet, const SfxItemSet& rEditSet )
838 const SfxPoolItem* pItem;
840 if (rEditSet.GetItemState(EE_CHAR_COLOR,true,&pItem) == SfxItemState::SET)
841 rDestSet.Put( SvxColorItem(ATTR_FONT_COLOR) = *static_cast<const SvxColorItem*>(pItem) );
843 if (rEditSet.GetItemState(EE_CHAR_FONTINFO,true,&pItem) == SfxItemState::SET)
844 rDestSet.Put( SvxFontItem(ATTR_FONT) = *static_cast<const SvxFontItem*>(pItem) );
845 if (rEditSet.GetItemState(EE_CHAR_FONTINFO_CJK,true,&pItem) == SfxItemState::SET)
846 rDestSet.Put( SvxFontItem(ATTR_CJK_FONT) = *static_cast<const SvxFontItem*>(pItem) );
847 if (rEditSet.GetItemState(EE_CHAR_FONTINFO_CTL,true,&pItem) == SfxItemState::SET)
848 rDestSet.Put( SvxFontItem(ATTR_CTL_FONT) = *static_cast<const SvxFontItem*>(pItem) );
850 if (rEditSet.GetItemState(EE_CHAR_FONTHEIGHT,true,&pItem) == SfxItemState::SET)
851 rDestSet.Put( SvxFontHeightItem( HMMToTwips( static_cast<const SvxFontHeightItem*>(pItem)->GetHeight() ),
852 100, ATTR_FONT_HEIGHT ) );
853 if (rEditSet.GetItemState(EE_CHAR_FONTHEIGHT_CJK,true,&pItem) == SfxItemState::SET)
854 rDestSet.Put( SvxFontHeightItem( HMMToTwips( static_cast<const SvxFontHeightItem*>(pItem)->GetHeight() ),
855 100, ATTR_CJK_FONT_HEIGHT ) );
856 if (rEditSet.GetItemState(EE_CHAR_FONTHEIGHT_CTL,true,&pItem) == SfxItemState::SET)
857 rDestSet.Put( SvxFontHeightItem( HMMToTwips( static_cast<const SvxFontHeightItem*>(pItem)->GetHeight() ),
858 100, ATTR_CTL_FONT_HEIGHT ) );
860 if (rEditSet.GetItemState(EE_CHAR_WEIGHT,true,&pItem) == SfxItemState::SET)
861 rDestSet.Put( SvxWeightItem( (FontWeight)static_cast<const SvxWeightItem*>(pItem)->GetValue(),
862 ATTR_FONT_WEIGHT) );
863 if (rEditSet.GetItemState(EE_CHAR_WEIGHT_CJK,true,&pItem) == SfxItemState::SET)
864 rDestSet.Put( SvxWeightItem( (FontWeight)static_cast<const SvxWeightItem*>(pItem)->GetValue(),
865 ATTR_CJK_FONT_WEIGHT) );
866 if (rEditSet.GetItemState(EE_CHAR_WEIGHT_CTL,true,&pItem) == SfxItemState::SET)
867 rDestSet.Put( SvxWeightItem( (FontWeight)static_cast<const SvxWeightItem*>(pItem)->GetValue(),
868 ATTR_CTL_FONT_WEIGHT) );
870 // SvxTextLineItem contains enum and color
871 if (rEditSet.GetItemState(EE_CHAR_UNDERLINE,true,&pItem) == SfxItemState::SET)
872 rDestSet.Put( SvxUnderlineItem(UNDERLINE_NONE,ATTR_FONT_UNDERLINE) = *static_cast<const SvxUnderlineItem*>(pItem) );
873 if (rEditSet.GetItemState(EE_CHAR_OVERLINE,true,&pItem) == SfxItemState::SET)
874 rDestSet.Put( SvxOverlineItem(UNDERLINE_NONE,ATTR_FONT_OVERLINE) = *static_cast<const SvxOverlineItem*>(pItem) );
875 if (rEditSet.GetItemState(EE_CHAR_WLM,true,&pItem) == SfxItemState::SET)
876 rDestSet.Put( SvxWordLineModeItem( static_cast<const SvxWordLineModeItem*>(pItem)->GetValue(),
877 ATTR_FONT_WORDLINE) );
879 if (rEditSet.GetItemState(EE_CHAR_STRIKEOUT,true,&pItem) == SfxItemState::SET)
880 rDestSet.Put( SvxCrossedOutItem( (FontStrikeout)static_cast<const SvxCrossedOutItem*>(pItem)->GetValue(),
881 ATTR_FONT_CROSSEDOUT) );
883 if (rEditSet.GetItemState(EE_CHAR_ITALIC,true,&pItem) == SfxItemState::SET)
884 rDestSet.Put( SvxPostureItem( (FontItalic)static_cast<const SvxPostureItem*>(pItem)->GetValue(),
885 ATTR_FONT_POSTURE) );
886 if (rEditSet.GetItemState(EE_CHAR_ITALIC_CJK,true,&pItem) == SfxItemState::SET)
887 rDestSet.Put( SvxPostureItem( (FontItalic)static_cast<const SvxPostureItem*>(pItem)->GetValue(),
888 ATTR_CJK_FONT_POSTURE) );
889 if (rEditSet.GetItemState(EE_CHAR_ITALIC_CTL,true,&pItem) == SfxItemState::SET)
890 rDestSet.Put( SvxPostureItem( (FontItalic)static_cast<const SvxPostureItem*>(pItem)->GetValue(),
891 ATTR_CTL_FONT_POSTURE) );
893 if (rEditSet.GetItemState(EE_CHAR_OUTLINE,true,&pItem) == SfxItemState::SET)
894 rDestSet.Put( SvxContourItem( static_cast<const SvxContourItem*>(pItem)->GetValue(),
895 ATTR_FONT_CONTOUR) );
896 if (rEditSet.GetItemState(EE_CHAR_SHADOW,true,&pItem) == SfxItemState::SET)
897 rDestSet.Put( SvxShadowedItem( static_cast<const SvxShadowedItem*>(pItem)->GetValue(),
898 ATTR_FONT_SHADOWED) );
899 if (rEditSet.GetItemState(EE_CHAR_EMPHASISMARK,true,&pItem) == SfxItemState::SET)
900 rDestSet.Put( SvxEmphasisMarkItem( static_cast<const SvxEmphasisMarkItem*>(pItem)->GetEmphasisMark(),
901 ATTR_FONT_EMPHASISMARK) );
902 if (rEditSet.GetItemState(EE_CHAR_RELIEF,true,&pItem) == SfxItemState::SET)
903 rDestSet.Put( SvxCharReliefItem( (FontRelief)static_cast<const SvxCharReliefItem*>(pItem)->GetValue(),
904 ATTR_FONT_RELIEF) );
906 if (rEditSet.GetItemState(EE_CHAR_LANGUAGE,true,&pItem) == SfxItemState::SET)
907 rDestSet.Put( SvxLanguageItem(static_cast<const SvxLanguageItem*>(pItem)->GetValue(), ATTR_FONT_LANGUAGE) );
908 if (rEditSet.GetItemState(EE_CHAR_LANGUAGE_CJK,true,&pItem) == SfxItemState::SET)
909 rDestSet.Put( SvxLanguageItem(static_cast<const SvxLanguageItem*>(pItem)->GetValue(), ATTR_CJK_FONT_LANGUAGE) );
910 if (rEditSet.GetItemState(EE_CHAR_LANGUAGE_CTL,true,&pItem) == SfxItemState::SET)
911 rDestSet.Put( SvxLanguageItem(static_cast<const SvxLanguageItem*>(pItem)->GetValue(), ATTR_CTL_FONT_LANGUAGE) );
913 if (rEditSet.GetItemState(EE_PARA_JUST,true,&pItem) == SfxItemState::SET)
915 SvxCellHorJustify eVal;
916 switch ( static_cast<const SvxAdjustItem*>(pItem)->GetAdjust() )
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 eVal = SVX_HOR_JUSTIFY_STANDARD;
922 break;
923 case SVX_ADJUST_RIGHT:
924 eVal = SVX_HOR_JUSTIFY_RIGHT;
925 break;
926 case SVX_ADJUST_BLOCK:
927 eVal = SVX_HOR_JUSTIFY_BLOCK;
928 break;
929 case SVX_ADJUST_CENTER:
930 eVal = SVX_HOR_JUSTIFY_CENTER;
931 break;
932 case SVX_ADJUST_BLOCKLINE:
933 eVal = SVX_HOR_JUSTIFY_BLOCK;
934 break;
935 case SVX_ADJUST_END:
936 eVal = SVX_HOR_JUSTIFY_RIGHT;
937 break;
938 default:
939 eVal = SVX_HOR_JUSTIFY_STANDARD;
941 if ( eVal != SVX_HOR_JUSTIFY_STANDARD )
942 rDestSet.Put( SvxHorJustifyItem( eVal, ATTR_HOR_JUSTIFY) );
946 void ScPatternAttr::GetFromEditItemSet( const SfxItemSet* pEditSet )
948 if( pEditSet )
949 GetFromEditItemSet( GetItemSet(), *pEditSet );
952 void ScPatternAttr::FillEditParaItems( SfxItemSet* pEditSet ) const
954 // already there in GetFromEditItemSet, but not in FillEditItemSet
955 // Default horizontal alignmnet is always implemented as left
957 const SfxItemSet& rMySet = GetItemSet();
959 SvxCellHorJustify eHorJust = (SvxCellHorJustify)
960 static_cast<const SvxHorJustifyItem&>(rMySet.Get(ATTR_HOR_JUSTIFY)).GetValue();
962 SvxAdjust eSvxAdjust;
963 switch (eHorJust)
965 case SVX_HOR_JUSTIFY_RIGHT: eSvxAdjust = SVX_ADJUST_RIGHT; break;
966 case SVX_HOR_JUSTIFY_CENTER: eSvxAdjust = SVX_ADJUST_CENTER; break;
967 case SVX_HOR_JUSTIFY_BLOCK: eSvxAdjust = SVX_ADJUST_BLOCK; break;
968 default: eSvxAdjust = SVX_ADJUST_LEFT; break;
970 pEditSet->Put( SvxAdjustItem( eSvxAdjust, EE_PARA_JUST ) );
973 void ScPatternAttr::DeleteUnchanged( const ScPatternAttr* pOldAttrs )
975 SfxItemSet& rThisSet = GetItemSet();
976 const SfxItemSet& rOldSet = pOldAttrs->GetItemSet();
978 const SfxPoolItem* pThisItem;
979 const SfxPoolItem* pOldItem;
981 for ( sal_uInt16 nSubWhich=ATTR_PATTERN_START; nSubWhich<=ATTR_PATTERN_END; nSubWhich++ )
983 // only items that are set are interesting
984 if ( rThisSet.GetItemState( nSubWhich, false, &pThisItem ) == SfxItemState::SET )
986 SfxItemState eOldState = rOldSet.GetItemState( nSubWhich, true, &pOldItem );
987 if ( eOldState == SfxItemState::SET )
989 // item is set in OldAttrs (or its parent) -> compare pointers
990 if ( pThisItem == pOldItem )
991 rThisSet.ClearItem( nSubWhich );
993 else if ( eOldState != SfxItemState::DONTCARE )
995 // not set in OldAttrs -> compare item value to default item
996 if ( *pThisItem == rThisSet.GetPool()->GetDefaultItem( nSubWhich ) )
997 rThisSet.ClearItem( nSubWhich );
1003 bool ScPatternAttr::HasItemsSet( const sal_uInt16* pWhich ) const
1005 const SfxItemSet& rSet = GetItemSet();
1006 for (sal_uInt16 i=0; pWhich[i]; i++)
1007 if ( rSet.GetItemState( pWhich[i], false ) == SfxItemState::SET )
1008 return true;
1009 return false;
1012 void ScPatternAttr::ClearItems( const sal_uInt16* pWhich )
1014 SfxItemSet& rSet = GetItemSet();
1015 for (sal_uInt16 i=0; pWhich[i]; i++)
1016 rSet.ClearItem(pWhich[i]);
1019 static SfxStyleSheetBase* lcl_CopyStyleToPool
1021 SfxStyleSheetBase* pSrcStyle,
1022 SfxStyleSheetBasePool* pSrcPool,
1023 SfxStyleSheetBasePool* pDestPool,
1024 const SvNumberFormatterIndexTable* pFormatExchangeList
1027 if ( !pSrcStyle || !pDestPool || !pSrcPool )
1029 OSL_FAIL( "CopyStyleToPool: Invalid Arguments :-/" );
1030 return NULL;
1033 const OUString aStrSrcStyle = pSrcStyle->GetName();
1034 const SfxStyleFamily eFamily = pSrcStyle->GetFamily();
1035 SfxStyleSheetBase* pDestStyle = pDestPool->Find( aStrSrcStyle, eFamily );
1037 if ( !pDestStyle )
1039 const OUString aStrParent = pSrcStyle->GetParent();
1040 const SfxItemSet& rSrcSet = pSrcStyle->GetItemSet();
1042 pDestStyle = &pDestPool->Make( aStrSrcStyle, eFamily, SFXSTYLEBIT_USERDEF );
1043 SfxItemSet& rDestSet = pDestStyle->GetItemSet();
1044 rDestSet.Put( rSrcSet );
1046 // number format exchange list has to be handled here, too
1047 // (only called for cell styles)
1049 const SfxPoolItem* pSrcItem;
1050 if ( pFormatExchangeList &&
1051 rSrcSet.GetItemState( ATTR_VALUE_FORMAT, false, &pSrcItem ) == SfxItemState::SET )
1053 sal_uLong nOldFormat = static_cast<const SfxUInt32Item*>(pSrcItem)->GetValue();
1054 SvNumberFormatterIndexTable::const_iterator it = pFormatExchangeList->find(nOldFormat);
1055 if (it != pFormatExchangeList->end())
1057 sal_uInt32 nNewFormat = it->second;
1058 rDestSet.Put( SfxUInt32Item( ATTR_VALUE_FORMAT, nNewFormat ) );
1062 // if necessary create derivative Styles, if not available:
1064 if ( ScGlobal::GetRscString(STR_STYLENAME_STANDARD) != aStrParent &&
1065 aStrSrcStyle != aStrParent &&
1066 !pDestPool->Find( aStrParent, eFamily ) )
1068 lcl_CopyStyleToPool( pSrcPool->Find( aStrParent, eFamily ),
1069 pSrcPool, pDestPool, pFormatExchangeList );
1072 pDestStyle->SetParent( aStrParent );
1075 return pDestStyle;
1078 ScPatternAttr* ScPatternAttr::PutInPool( ScDocument* pDestDoc, ScDocument* pSrcDoc ) const
1080 const SfxItemSet* pSrcSet = &GetItemSet();
1082 ScPatternAttr* pDestPattern = new ScPatternAttr(pDestDoc->GetPool());
1083 SfxItemSet* pDestSet = &pDestPattern->GetItemSet();
1085 // Copy cell pattern style to other document:
1087 if ( pDestDoc != pSrcDoc )
1089 OSL_ENSURE( pStyle, "Missing Pattern-Style! :-/" );
1091 // if pattern in DestDoc is available, use this, otherwise copy
1092 // parent style to style or create if necessary and attach DestDoc
1094 SfxStyleSheetBase* pStyleCpy = lcl_CopyStyleToPool( pStyle,
1095 pSrcDoc->GetStyleSheetPool(),
1096 pDestDoc->GetStyleSheetPool(),
1097 pDestDoc->GetFormatExchangeList() );
1099 pDestPattern->SetStyleSheet( static_cast<ScStyleSheet*>(pStyleCpy) );
1102 for ( sal_uInt16 nAttrId = ATTR_PATTERN_START; nAttrId <= ATTR_PATTERN_END; nAttrId++ )
1104 const SfxPoolItem* pSrcItem;
1105 SfxItemState eItemState = pSrcSet->GetItemState( nAttrId, false, &pSrcItem );
1106 if (eItemState==SfxItemState::SET)
1108 SfxPoolItem* pNewItem = NULL;
1110 if ( nAttrId == ATTR_VALIDDATA )
1112 // Copy validity to the new document
1114 sal_uLong nNewIndex = 0;
1115 ScValidationDataList* pSrcList = pSrcDoc->GetValidationList();
1116 if ( pSrcList )
1118 sal_uLong nOldIndex = static_cast<const SfxUInt32Item*>(pSrcItem)->GetValue();
1119 const ScValidationData* pOldData = pSrcList->GetData( nOldIndex );
1120 if ( pOldData )
1121 nNewIndex = pDestDoc->AddValidationEntry( *pOldData );
1123 pNewItem = new SfxUInt32Item( ATTR_VALIDDATA, nNewIndex );
1125 else if ( nAttrId == ATTR_VALUE_FORMAT && pDestDoc->GetFormatExchangeList() )
1127 // Number format to Exchange List
1129 sal_uLong nOldFormat = static_cast<const SfxUInt32Item*>(pSrcItem)->GetValue();
1130 SvNumberFormatterIndexTable::const_iterator it = pDestDoc->GetFormatExchangeList()->find(nOldFormat);
1131 if (it != pDestDoc->GetFormatExchangeList()->end())
1133 sal_uInt32 nNewFormat = it->second;
1134 pNewItem = new SfxUInt32Item( ATTR_VALUE_FORMAT, nNewFormat );
1138 if ( pNewItem )
1140 pDestSet->Put(*pNewItem);
1141 delete pNewItem;
1143 else
1144 pDestSet->Put(*pSrcItem);
1148 ScPatternAttr* pPatternAttr =
1149 const_cast<ScPatternAttr*>( static_cast<const ScPatternAttr*>( &pDestDoc->GetPool()->Put(*pDestPattern) ) );
1150 delete pDestPattern;
1151 return pPatternAttr;
1154 bool ScPatternAttr::IsVisible() const
1156 const SfxItemSet& rSet = GetItemSet();
1158 const SfxPoolItem* pItem;
1159 SfxItemState eState;
1161 eState = rSet.GetItemState( ATTR_BACKGROUND, true, &pItem );
1162 if ( eState == SfxItemState::SET )
1163 if ( static_cast<const SvxBrushItem*>(pItem)->GetColor().GetColor() != COL_TRANSPARENT )
1164 return true;
1166 eState = rSet.GetItemState( ATTR_BORDER, true, &pItem );
1167 if ( eState == SfxItemState::SET )
1169 const SvxBoxItem* pBoxItem = static_cast<const SvxBoxItem*>(pItem);
1170 if ( pBoxItem->GetTop() || pBoxItem->GetBottom() ||
1171 pBoxItem->GetLeft() || pBoxItem->GetRight() )
1172 return true;
1175 eState = rSet.GetItemState( ATTR_BORDER_TLBR, true, &pItem );
1176 if ( eState == SfxItemState::SET )
1177 if( static_cast< const SvxLineItem* >( pItem )->GetLine() )
1178 return true;
1180 eState = rSet.GetItemState( ATTR_BORDER_BLTR, true, &pItem );
1181 if ( eState == SfxItemState::SET )
1182 if( static_cast< const SvxLineItem* >( pItem )->GetLine() )
1183 return true;
1185 eState = rSet.GetItemState( ATTR_SHADOW, true, &pItem );
1186 if ( eState == SfxItemState::SET )
1187 if ( static_cast<const SvxShadowItem*>(pItem)->GetLocation() != SVX_SHADOW_NONE )
1188 return true;
1190 return false;
1193 inline bool OneEqual( const SfxItemSet& rSet1, const SfxItemSet& rSet2, sal_uInt16 nId )
1195 const SfxPoolItem* pItem1 = &rSet1.Get(nId);
1196 const SfxPoolItem* pItem2 = &rSet2.Get(nId);
1197 return ( pItem1 == pItem2 || *pItem1 == *pItem2 );
1200 bool ScPatternAttr::IsVisibleEqual( const ScPatternAttr& rOther ) const
1202 const SfxItemSet& rThisSet = GetItemSet();
1203 const SfxItemSet& rOtherSet = rOther.GetItemSet();
1205 return OneEqual( rThisSet, rOtherSet, ATTR_BACKGROUND ) &&
1206 OneEqual( rThisSet, rOtherSet, ATTR_BORDER ) &&
1207 OneEqual( rThisSet, rOtherSet, ATTR_BORDER_TLBR ) &&
1208 OneEqual( rThisSet, rOtherSet, ATTR_BORDER_BLTR ) &&
1209 OneEqual( rThisSet, rOtherSet, ATTR_SHADOW );
1211 //TODO: also here only check really visible values !!!
1214 const OUString* ScPatternAttr::GetStyleName() const
1216 return pName ? pName : ( pStyle ? &pStyle->GetName() : NULL );
1219 void ScPatternAttr::SetStyleSheet( ScStyleSheet* pNewStyle, bool bClearDirectFormat )
1221 if (pNewStyle)
1223 SfxItemSet& rPatternSet = GetItemSet();
1224 const SfxItemSet& rStyleSet = pNewStyle->GetItemSet();
1226 if (bClearDirectFormat)
1228 for (sal_uInt16 i=ATTR_PATTERN_START; i<=ATTR_PATTERN_END; i++)
1230 if (rStyleSet.GetItemState(i, true) == SfxItemState::SET)
1231 rPatternSet.ClearItem(i);
1234 rPatternSet.SetParent(&pNewStyle->GetItemSet());
1235 pStyle = pNewStyle;
1236 DELETEZ( pName );
1238 else
1240 OSL_FAIL( "ScPatternAttr::SetStyleSheet( NULL ) :-|" );
1241 GetItemSet().SetParent(NULL);
1242 pStyle = NULL;
1246 void ScPatternAttr::UpdateStyleSheet(ScDocument* pDoc)
1248 if (pName)
1250 pStyle = static_cast<ScStyleSheet*>(pDoc->GetStyleSheetPool()->Find(*pName, SFX_STYLE_FAMILY_PARA));
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 if (!pStyle)
1257 SfxStyleSheetIteratorPtr pIter = pDoc->GetStyleSheetPool()->CreateIterator( SFX_STYLE_FAMILY_PARA, SFXSTYLEBIT_ALL );
1258 pStyle = dynamic_cast< ScStyleSheet* >(pIter->First());
1261 if (pStyle)
1263 GetItemSet().SetParent(&pStyle->GetItemSet());
1264 DELETEZ( pName );
1267 else
1268 pStyle = NULL;
1271 void ScPatternAttr::StyleToName()
1273 // Style was deleted, remember name:
1275 if ( pStyle )
1277 if ( pName )
1278 *pName = pStyle->GetName();
1279 else
1280 pName = new OUString( pStyle->GetName() );
1282 pStyle = NULL;
1283 GetItemSet().SetParent( NULL );
1287 bool ScPatternAttr::IsSymbolFont() const
1289 const SfxPoolItem* pItem;
1290 if( GetItemSet().GetItemState( ATTR_FONT, true, &pItem ) == SfxItemState::SET )
1291 return static_cast<const SvxFontItem*>(pItem)->GetCharSet() == RTL_TEXTENCODING_SYMBOL;
1292 else
1293 return false;
1296 sal_uLong ScPatternAttr::GetNumberFormat( SvNumberFormatter* pFormatter ) const
1298 sal_uLong nFormat =
1299 static_cast<const SfxUInt32Item*>(&GetItemSet().Get( ATTR_VALUE_FORMAT ))->GetValue();
1300 LanguageType eLang =
1301 static_cast<const SvxLanguageItem*>(&GetItemSet().Get( ATTR_LANGUAGE_FORMAT ))->GetLanguage();
1302 if ( nFormat < SV_COUNTRY_LANGUAGE_OFFSET && eLang == LANGUAGE_SYSTEM )
1303 ; // it remains as it is
1304 else if ( pFormatter )
1305 nFormat = pFormatter->GetFormatForLanguageIfBuiltIn( nFormat, eLang );
1306 return nFormat;
1309 // the same if conditional formatting is in play:
1311 sal_uLong ScPatternAttr::GetNumberFormat( SvNumberFormatter* pFormatter,
1312 const SfxItemSet* pCondSet ) const
1314 OSL_ENSURE(pFormatter,"GetNumberFormat without Formatter");
1316 const SfxPoolItem* pFormItem;
1317 if ( !pCondSet || pCondSet->GetItemState(ATTR_VALUE_FORMAT,true,&pFormItem) != SfxItemState::SET )
1318 pFormItem = &GetItemSet().Get(ATTR_VALUE_FORMAT);
1320 const SfxPoolItem* pLangItem;
1321 if ( !pCondSet || pCondSet->GetItemState(ATTR_LANGUAGE_FORMAT,true,&pLangItem) != SfxItemState::SET )
1322 pLangItem = &GetItemSet().Get(ATTR_LANGUAGE_FORMAT);
1324 return pFormatter->GetFormatForLanguageIfBuiltIn(
1325 static_cast<const SfxUInt32Item*>(pFormItem)->GetValue(),
1326 static_cast<const SvxLanguageItem*>(pLangItem)->GetLanguage() );
1329 const SfxPoolItem& ScPatternAttr::GetItem( sal_uInt16 nWhich, const SfxItemSet& rItemSet, const SfxItemSet* pCondSet )
1331 const SfxPoolItem* pCondItem;
1332 if ( pCondSet && pCondSet->GetItemState( nWhich, true, &pCondItem ) == SfxItemState::SET )
1333 return *pCondItem;
1334 return rItemSet.Get(nWhich);
1337 const SfxPoolItem& ScPatternAttr::GetItem( sal_uInt16 nSubWhich, const SfxItemSet* pCondSet ) const
1339 return GetItem( nSubWhich, GetItemSet(), pCondSet );
1342 // GetRotateVal is tested before ATTR_ORIENTATION
1344 long ScPatternAttr::GetRotateVal( const SfxItemSet* pCondSet ) const
1346 long nAttrRotate = 0;
1347 if ( GetCellOrientation() == SVX_ORIENTATION_STANDARD )
1349 bool bRepeat = ( static_cast<const SvxHorJustifyItem&>(GetItem(ATTR_HOR_JUSTIFY, pCondSet)).
1350 GetValue() == SVX_HOR_JUSTIFY_REPEAT );
1351 // ignore orientation/rotation if "repeat" is active
1352 if ( !bRepeat )
1353 nAttrRotate = static_cast<const SfxInt32Item&>(GetItem( ATTR_ROTATE_VALUE, pCondSet )).GetValue();
1355 return nAttrRotate;
1358 sal_uInt8 ScPatternAttr::GetRotateDir( const SfxItemSet* pCondSet ) const
1360 sal_uInt8 nRet = SC_ROTDIR_NONE;
1362 long nAttrRotate = GetRotateVal( pCondSet );
1363 if ( nAttrRotate )
1365 SvxRotateMode eRotMode = (SvxRotateMode)static_cast<const SvxRotateModeItem&>(
1366 GetItem(ATTR_ROTATE_MODE, pCondSet)).GetValue();
1368 if ( eRotMode == SVX_ROTATE_MODE_STANDARD || nAttrRotate == 18000 )
1369 nRet = SC_ROTDIR_STANDARD;
1370 else if ( eRotMode == SVX_ROTATE_MODE_CENTER )
1371 nRet = SC_ROTDIR_CENTER;
1372 else if ( eRotMode == SVX_ROTATE_MODE_TOP || eRotMode == SVX_ROTATE_MODE_BOTTOM )
1374 long nRot180 = nAttrRotate % 18000; // 1/100 degrees
1375 if ( nRot180 == 9000 )
1376 nRet = SC_ROTDIR_CENTER;
1377 else if ( ( eRotMode == SVX_ROTATE_MODE_TOP && nRot180 < 9000 ) ||
1378 ( eRotMode == SVX_ROTATE_MODE_BOTTOM && nRot180 > 9000 ) )
1379 nRet = SC_ROTDIR_LEFT;
1380 else
1381 nRet = SC_ROTDIR_RIGHT;
1385 return nRet;
1388 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */