1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
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 <CharacterPropertyItemConverter.hxx>
21 #include "SchWhichPairs.hxx"
22 #include <ItemPropertyMap.hxx>
23 #include <RelativeSizeHelper.hxx>
24 #include <editeng/memberids.h>
25 #include <editeng/eeitem.hxx>
26 #include <editeng/udlnitem.hxx>
27 #include <editeng/fontitem.hxx>
28 #include <editeng/postitem.hxx>
29 #include <editeng/wghtitem.hxx>
30 #include <editeng/fhgtitem.hxx>
31 #include <o3tl/any.hxx>
32 #include <svl/stritem.hxx>
34 #include <com/sun/star/beans/XPropertySet.hpp>
35 #include <com/sun/star/chart2/XFormattedString.hpp>
36 #include <tools/diagnose_ex.h>
38 using namespace ::com::sun::star
;
40 namespace chart
{ namespace wrapper
{
44 ItemPropertyMapType
& lcl_GetCharacterPropertyPropertyMap()
46 static ItemPropertyMapType aCharacterPropertyMap
{
47 {EE_CHAR_COLOR
, {"CharColor", 0}},
48 {EE_CHAR_LANGUAGE
, {"CharLocale", MID_LANG_LOCALE
}},
49 {EE_CHAR_LANGUAGE_CJK
, {"CharLocaleAsian", MID_LANG_LOCALE
}},
50 {EE_CHAR_LANGUAGE_CTL
, {"CharLocaleComplex", MID_LANG_LOCALE
}},
52 {EE_CHAR_STRIKEOUT
, {"CharStrikeout", MID_CROSS_OUT
}},
53 {EE_CHAR_WLM
, {"CharWordMode", 0}},
54 {EE_CHAR_SHADOW
, {"CharShadowed", 0}},
55 {EE_CHAR_RELIEF
, {"CharRelief", 0}},
56 {EE_CHAR_OUTLINE
, {"CharContoured", 0}},
57 {EE_CHAR_EMPHASISMARK
, {"CharEmphasis", 0}},
59 {EE_PARA_WRITINGDIR
, {"WritingMode", 0}},
61 {EE_PARA_ASIANCJKSPACING
, {"ParaIsCharacterDistance", 0}}};
63 return aCharacterPropertyMap
;
65 } // anonymous namespace
67 CharacterPropertyItemConverter::CharacterPropertyItemConverter(
68 const uno::Reference
< beans::XPropertySet
> & rPropertySet
,
69 SfxItemPool
& rItemPool
) :
70 ItemConverter( rPropertySet
, rItemPool
)
73 CharacterPropertyItemConverter::CharacterPropertyItemConverter(
74 const uno::Reference
< beans::XPropertySet
> & rPropertySet
,
75 SfxItemPool
& rItemPool
,
76 const awt::Size
* pRefSize
,
77 const OUString
& rRefSizePropertyName
,
78 const uno::Reference
< beans::XPropertySet
> & rRefSizePropSet
) :
79 ItemConverter( rPropertySet
, rItemPool
),
80 m_aRefSizePropertyName( rRefSizePropertyName
),
81 m_xRefSizePropSet( rRefSizePropSet
.is() ? rRefSizePropSet
: rPropertySet
)
84 m_pRefSize
.reset(*pRefSize
);
87 CharacterPropertyItemConverter::~CharacterPropertyItemConverter()
90 const sal_uInt16
* CharacterPropertyItemConverter::GetWhichPairs() const
92 return nCharacterPropertyWhichPairs
;
95 bool CharacterPropertyItemConverter::GetItemProperty( tWhichIdType nWhichId
, tPropertyNameWithMemberId
& rOutProperty
) const
97 ItemPropertyMapType
& rMap( lcl_GetCharacterPropertyPropertyMap());
98 ItemPropertyMapType::const_iterator
aIt( rMap
.find( nWhichId
));
100 if( aIt
== rMap
.end())
103 rOutProperty
=(*aIt
).second
;
107 void CharacterPropertyItemConverter::FillSpecialItem(
108 sal_uInt16 nWhichId
, SfxItemSet
& rOutItemSet
) const
112 case EE_CHAR_FONTINFO
:
113 case EE_CHAR_FONTINFO_CJK
:
114 case EE_CHAR_FONTINFO_CTL
:
117 if( nWhichId
== EE_CHAR_FONTINFO_CJK
)
119 else if( nWhichId
== EE_CHAR_FONTINFO_CTL
)
120 aPostfix
= "Complex";
122 SvxFontItem
aItem( nWhichId
);
124 aItem
.PutValue( GetPropertySet()->getPropertyValue( "CharFontName" + aPostfix
),
125 MID_FONT_FAMILY_NAME
);
126 aItem
.PutValue( GetPropertySet()->getPropertyValue( "CharFontFamily" + aPostfix
),
128 aItem
.PutValue( GetPropertySet()->getPropertyValue( "CharFontStyleName" + aPostfix
),
129 MID_FONT_STYLE_NAME
);
130 aItem
.PutValue( GetPropertySet()->getPropertyValue( "CharFontCharSet" + aPostfix
),
132 aItem
.PutValue( GetPropertySet()->getPropertyValue( "CharFontPitch" + aPostfix
),
135 rOutItemSet
.Put( aItem
);
139 case EE_CHAR_UNDERLINE
:
141 SvxUnderlineItem
aItem(LINESTYLE_NONE
, EE_CHAR_UNDERLINE
);
142 bool bModified
= false;
144 uno::Any
aValue( GetPropertySet()->getPropertyValue( "CharUnderline" ));
145 if( aValue
.hasValue())
147 aItem
.PutValue( aValue
, MID_TL_STYLE
);
151 aValue
= GetPropertySet()->getPropertyValue( "CharUnderlineHasColor" );
152 if( aValue
.hasValue() && *o3tl::doAccess
<bool>(aValue
) )
154 aItem
.PutValue( aValue
, MID_TL_HASCOLOR
);
158 aValue
= GetPropertySet()->getPropertyValue( "CharUnderlineColor" );
159 if( aValue
.hasValue())
161 aItem
.PutValue( aValue
, MID_TL_COLOR
);
166 rOutItemSet
.Put( aItem
);
170 case EE_CHAR_OVERLINE
:
172 SvxOverlineItem
aItem( LINESTYLE_NONE
, EE_CHAR_OVERLINE
);
173 bool bModified
= false;
175 uno::Any
aValue( GetPropertySet()->getPropertyValue( "CharOverline" ) );
176 if ( aValue
.hasValue() )
178 aItem
.PutValue( aValue
, MID_TL_STYLE
);
182 aValue
= GetPropertySet()->getPropertyValue( "CharOverlineHasColor" );
183 if ( aValue
.hasValue() && *o3tl::doAccess
<bool>(aValue
) )
185 aItem
.PutValue( aValue
, MID_TL_HASCOLOR
);
189 aValue
= GetPropertySet()->getPropertyValue( "CharOverlineColor" );
190 if ( aValue
.hasValue() )
192 aItem
.PutValue( aValue
, MID_TL_COLOR
);
198 rOutItemSet
.Put( aItem
);
204 case EE_CHAR_ITALIC_CJK
:
205 case EE_CHAR_ITALIC_CTL
:
208 if( nWhichId
== EE_CHAR_ITALIC_CJK
)
210 else if( nWhichId
== EE_CHAR_ITALIC_CTL
)
211 aPostfix
= "Complex";
213 SvxPostureItem
aItem( ITALIC_NONE
, nWhichId
);
215 uno::Any
aValue( GetPropertySet()->getPropertyValue( "CharPosture" + aPostfix
));
216 if( aValue
.hasValue())
218 aItem
.PutValue( aValue
, MID_POSTURE
);
219 rOutItemSet
.Put( aItem
);
225 case EE_CHAR_WEIGHT_CJK
:
226 case EE_CHAR_WEIGHT_CTL
:
229 if( nWhichId
== EE_CHAR_WEIGHT_CJK
)
231 else if( nWhichId
== EE_CHAR_WEIGHT_CTL
)
232 aPostfix
= "Complex";
234 SvxWeightItem
aItem( WEIGHT_NORMAL
, nWhichId
);
236 uno::Any
aValue( GetPropertySet()->getPropertyValue( "CharWeight" + aPostfix
));
237 if( aValue
.hasValue())
239 aItem
.PutValue( aValue
, MID_WEIGHT
);
240 rOutItemSet
.Put( aItem
);
245 case EE_CHAR_FONTHEIGHT
:
246 case EE_CHAR_FONTHEIGHT_CJK
:
247 case EE_CHAR_FONTHEIGHT_CTL
:
250 if( nWhichId
== EE_CHAR_FONTHEIGHT_CJK
)
252 else if( nWhichId
== EE_CHAR_FONTHEIGHT_CTL
)
253 aPostfix
= "Complex";
255 SvxFontHeightItem
aItem( 240, 100, nWhichId
);
259 uno::Any
aValue( GetPropertySet()->getPropertyValue( "CharHeight" + aPostfix
));
261 if( aValue
>>= fHeight
)
265 awt::Size aOldRefSize
;
266 if( GetRefSizePropertySet()->getPropertyValue( m_aRefSizePropertyName
) >>= aOldRefSize
)
268 // calculate font height in view
269 fHeight
= static_cast< float >(
270 RelativeSizeHelper::calculate( fHeight
, aOldRefSize
, *m_pRefSize
));
275 aItem
.PutValue( aValue
, MID_FONTHEIGHT
);
276 rOutItemSet
.Put( aItem
);
279 catch( const uno::Exception
& )
281 DBG_UNHANDLED_EXCEPTION("chart2");
286 case SID_CHAR_DLG_PREVIEW_STRING
:
288 uno::Reference
< chart2::XFormattedString
> xFormattedString( GetPropertySet(), uno::UNO_QUERY
);
289 if( xFormattedString
.is() )
291 OUString aString
= xFormattedString
->getString();
292 rOutItemSet
.Put( SfxStringItem( nWhichId
, aString
) );
295 rOutItemSet
.Put( SfxStringItem( nWhichId
, OUString() ) );
299 case EE_PARA_FORBIDDENRULES
:
300 case EE_PARA_HANGINGPUNCTUATION
:
301 rOutItemSet
.DisableItem( nWhichId
);
306 bool CharacterPropertyItemConverter::ApplySpecialItem(
307 sal_uInt16 nWhichId
, const SfxItemSet
& rItemSet
)
309 bool bChanged
= false;
314 case EE_CHAR_FONTINFO
:
315 case EE_CHAR_FONTINFO_CJK
:
316 case EE_CHAR_FONTINFO_CTL
:
319 if( nWhichId
== EE_CHAR_FONTINFO_CJK
)
321 else if( nWhichId
== EE_CHAR_FONTINFO_CTL
)
322 aPostfix
= "Complex";
324 const SvxFontItem
& rItem
=
325 static_cast< const SvxFontItem
& >(
326 rItemSet
.Get( nWhichId
));
328 if( rItem
.QueryValue( aValue
, MID_FONT_FAMILY_NAME
))
330 if( aValue
!= GetPropertySet()->getPropertyValue( "CharFontName" + aPostfix
))
332 GetPropertySet()->setPropertyValue( "CharFontName" + aPostfix
, aValue
);
336 if( rItem
.QueryValue( aValue
, MID_FONT_FAMILY
))
338 if( aValue
!= GetPropertySet()->getPropertyValue( "CharFontFamily" + aPostfix
))
340 GetPropertySet()->setPropertyValue( "CharFontFamily" + aPostfix
, aValue
);
344 if( rItem
.QueryValue( aValue
, MID_FONT_STYLE_NAME
))
346 if( aValue
!= GetPropertySet()->getPropertyValue( "CharFontStyleName" + aPostfix
))
348 GetPropertySet()->setPropertyValue( "CharFontStyleName" + aPostfix
, aValue
);
352 if( rItem
.QueryValue( aValue
, MID_FONT_CHAR_SET
))
354 if( aValue
!= GetPropertySet()->getPropertyValue( "CharFontCharSet" + aPostfix
))
356 GetPropertySet()->setPropertyValue( "CharFontCharSet" + aPostfix
, aValue
);
360 if( rItem
.QueryValue( aValue
, MID_FONT_PITCH
))
362 if( aValue
!= GetPropertySet()->getPropertyValue( "CharFontPitch" + aPostfix
))
364 GetPropertySet()->setPropertyValue( "CharFontPitch" + aPostfix
, aValue
);
371 case EE_CHAR_UNDERLINE
:
373 const SvxUnderlineItem
& rItem
=
374 static_cast< const SvxUnderlineItem
& >(
375 rItemSet
.Get( nWhichId
));
377 if( rItem
.QueryValue( aValue
, MID_TL_STYLE
))
379 if( aValue
!= GetPropertySet()->getPropertyValue( "CharUnderline" ))
381 GetPropertySet()->setPropertyValue( "CharUnderline" , aValue
);
386 if( rItem
.QueryValue( aValue
, MID_TL_COLOR
))
388 if( aValue
!= GetPropertySet()->getPropertyValue( "CharUnderlineColor" ))
390 GetPropertySet()->setPropertyValue( "CharUnderlineColor" , aValue
);
395 if( rItem
.QueryValue( aValue
, MID_TL_HASCOLOR
))
397 if( aValue
!= GetPropertySet()->getPropertyValue( "CharUnderlineHasColor" ))
399 GetPropertySet()->setPropertyValue( "CharUnderlineHasColor" , aValue
);
406 case EE_CHAR_OVERLINE
:
408 const SvxOverlineItem
& rItem
= static_cast< const SvxOverlineItem
& >( rItemSet
.Get( nWhichId
) );
410 if ( rItem
.QueryValue( aValue
, MID_TL_STYLE
) )
412 if ( aValue
!= GetPropertySet()->getPropertyValue( "CharOverline" ) )
414 GetPropertySet()->setPropertyValue( "CharOverline" , aValue
);
419 if ( rItem
.QueryValue( aValue
, MID_TL_COLOR
) )
421 if ( aValue
!= GetPropertySet()->getPropertyValue( "CharOverlineColor" ) )
423 GetPropertySet()->setPropertyValue( "CharOverlineColor" , aValue
);
428 if ( rItem
.QueryValue( aValue
, MID_TL_HASCOLOR
) )
430 if ( aValue
!= GetPropertySet()->getPropertyValue( "CharOverlineHasColor" ) )
432 GetPropertySet()->setPropertyValue( "CharOverlineHasColor" , aValue
);
440 case EE_CHAR_ITALIC_CJK
:
441 case EE_CHAR_ITALIC_CTL
:
444 if( nWhichId
== EE_CHAR_ITALIC_CJK
)
446 else if( nWhichId
== EE_CHAR_ITALIC_CTL
)
447 aPostfix
= "Complex";
449 const SvxPostureItem
& rItem
=
450 static_cast< const SvxPostureItem
& >(
451 rItemSet
.Get( nWhichId
));
453 if( rItem
.QueryValue( aValue
, MID_POSTURE
))
455 if( aValue
!= GetPropertySet()->getPropertyValue( "CharPosture" + aPostfix
))
457 GetPropertySet()->setPropertyValue( "CharPosture" + aPostfix
, aValue
);
465 case EE_CHAR_WEIGHT_CJK
:
466 case EE_CHAR_WEIGHT_CTL
:
469 if( nWhichId
== EE_CHAR_WEIGHT_CJK
)
471 else if( nWhichId
== EE_CHAR_WEIGHT_CTL
)
472 aPostfix
= "Complex";
474 const SvxWeightItem
& rItem
=
475 static_cast< const SvxWeightItem
& >(
476 rItemSet
.Get( nWhichId
));
478 if( rItem
.QueryValue( aValue
, MID_WEIGHT
))
480 if( aValue
!= GetPropertySet()->getPropertyValue( "CharWeight" + aPostfix
))
482 GetPropertySet()->setPropertyValue( "CharWeight" + aPostfix
, aValue
);
489 case EE_CHAR_FONTHEIGHT
:
490 case EE_CHAR_FONTHEIGHT_CJK
:
491 case EE_CHAR_FONTHEIGHT_CTL
:
494 if( nWhichId
== EE_CHAR_FONTHEIGHT_CJK
)
496 else if( nWhichId
== EE_CHAR_FONTHEIGHT_CTL
)
497 aPostfix
= "Complex";
499 const SvxFontHeightItem
& rItem
=
500 static_cast< const SvxFontHeightItem
& >(
501 rItemSet
.Get( nWhichId
));
505 if( rItem
.QueryValue( aValue
, MID_FONTHEIGHT
) )
507 bool bSetValue
= false;
508 if( aValue
!= GetPropertySet()->getPropertyValue( "CharHeight" + aPostfix
))
514 awt::Size aNewRefSize
= *m_pRefSize
;
515 awt::Size aOldRefSize
;
516 if( GetRefSizePropertySet()->getPropertyValue( m_aRefSizePropertyName
) >>= aOldRefSize
)
518 if( aNewRefSize
.Width
!= aOldRefSize
.Width
519 || aNewRefSize
.Height
!= aOldRefSize
.Height
)
526 // set new reference size only if there was a reference size before (auto-scaling on)
527 if (m_pRefSize
&& GetRefSizePropertySet()->getPropertyValue( m_aRefSizePropertyName
).hasValue())
529 GetRefSizePropertySet()->setPropertyValue(
530 m_aRefSizePropertyName
, uno::Any(*m_pRefSize
));
533 GetPropertySet()->setPropertyValue( "CharHeight" + aPostfix
, aValue
);
538 catch( const uno::Exception
& )
540 DBG_UNHANDLED_EXCEPTION("chart2");
549 const uno::Reference
<beans::XPropertySet
>& CharacterPropertyItemConverter::GetRefSizePropertySet() const
551 return m_xRefSizePropSet
;
556 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */