Update ooo320-m1
[ooovba.git] / chart2 / source / controller / itemsetwrapper / CharacterPropertyItemConverter.cxx
blobfa38e75f09569fe6bdcb7c392216109521be1b1e
1 /*************************************************************************
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4 *
5 * Copyright 2008 by Sun Microsystems, Inc.
7 * OpenOffice.org - a multi-platform office productivity suite
9 * $RCSfile: CharacterPropertyItemConverter.cxx,v $
10 * $Revision: 1.14.56.1 $
12 * This file is part of OpenOffice.org.
14 * OpenOffice.org is free software: you can redistribute it and/or modify
15 * it under the terms of the GNU Lesser General Public License version 3
16 * only, as published by the Free Software Foundation.
18 * OpenOffice.org is distributed in the hope that it will be useful,
19 * but WITHOUT ANY WARRANTY; without even the implied warranty of
20 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
21 * GNU Lesser General Public License version 3 for more details
22 * (a copy is included in the LICENSE file that accompanied this code).
24 * You should have received a copy of the GNU Lesser General Public License
25 * version 3 along with OpenOffice.org. If not, see
26 * <http://www.openoffice.org/license.html>
27 * for a copy of the LGPLv3 License.
29 ************************************************************************/
31 // MARKER(update_precomp.py): autogen include statement, do not remove
32 #include "precompiled_chart2.hxx"
33 #include "CharacterPropertyItemConverter.hxx"
34 #include "SchWhichPairs.hxx"
35 #include "macros.hxx"
36 #include "ItemPropertyMap.hxx"
37 #include "RelativeSizeHelper.hxx"
38 #include <svx/eeitem.hxx>
39 #include <svx/udlnitem.hxx>
40 #include <svx/fontitem.hxx>
41 #include <svx/crsditem.hxx>
42 #include <svx/postitem.hxx>
43 #include <svx/wghtitem.hxx>
44 #include <svx/fhgtitem.hxx>
45 #include <svtools/stritem.hxx>
47 #include <com/sun/star/beans/XPropertyState.hpp>
48 #include <com/sun/star/chart2/XFormattedString.hpp>
50 using namespace ::com::sun::star;
52 namespace
54 ::comphelper::ItemPropertyMapType & lcl_GetCharacterPropertyPropertyMap()
56 static ::comphelper::ItemPropertyMapType aCharacterPropertyMap(
57 ::comphelper::MakeItemPropertyMap
58 IPM_MAP_ENTRY( EE_CHAR_COLOR, "CharColor", 0 )
59 IPM_MAP_ENTRY( EE_CHAR_LANGUAGE, "CharLocale", MID_LANG_LOCALE )
60 IPM_MAP_ENTRY( EE_CHAR_LANGUAGE_CJK, "CharLocaleAsian", MID_LANG_LOCALE )
61 IPM_MAP_ENTRY( EE_CHAR_LANGUAGE_CTL, "CharLocaleComplex", MID_LANG_LOCALE )
62 // IPM_MAP_ENTRY( EE_CHAR_FONTHEIGHT, "CharHeight", 0 )
63 // IPM_MAP_ENTRY( EE_CHAR_ITALIC, "CharPosture", 0 )
64 // IPM_MAP_ENTRY( EE_CHAR_WEIGHT, "CharWeight", 0 )
66 IPM_MAP_ENTRY( EE_CHAR_STRIKEOUT, "CharStrikeout", MID_CROSS_OUT )
67 IPM_MAP_ENTRY( EE_CHAR_WLM, "CharWordMode", 0 )
68 IPM_MAP_ENTRY( EE_CHAR_SHADOW, "CharShadowed", 0 )
69 IPM_MAP_ENTRY( EE_CHAR_RELIEF, "CharRelief", 0 )
70 IPM_MAP_ENTRY( EE_CHAR_OUTLINE, "CharContoured", 0 )
71 IPM_MAP_ENTRY( EE_CHAR_EMPHASISMARK, "CharEmphasis", 0 )
73 IPM_MAP_ENTRY( EE_PARA_WRITINGDIR, "WritingMode", 0 )
75 // IPM_MAP_ENTRY( EE_CHAR_FONTHEIGHT_CJK, "CharHeightAsian", 0 )
76 // IPM_MAP_ENTRY( EE_CHAR_FONTHEIGHT_CTL, "CharHeightComplex", 0 )
77 // IPM_MAP_ENTRY( EE_CHAR_WEIGHT_CJK, "CharWeightAsian", 0 )
78 // IPM_MAP_ENTRY( EE_CHAR_WEIGHT_CTL, "CharWeightComplex", 0 )
79 // IPM_MAP_ENTRY( EE_CHAR_ITALIC_CJK, "CharPostureAsian", 0 )
80 // IPM_MAP_ENTRY( EE_CHAR_ITALIC_CTL, "CharPostureComplex", 0 )
81 IPM_MAP_ENTRY( EE_PARA_ASIANCJKSPACING, "ParaIsCharacterDistance", 0 )
84 return aCharacterPropertyMap;
86 } // anonymous namespace
88 // ========================================
90 namespace chart
92 namespace wrapper
95 CharacterPropertyItemConverter::CharacterPropertyItemConverter(
96 const uno::Reference< beans::XPropertySet > & rPropertySet,
97 SfxItemPool& rItemPool ) :
98 ItemConverter( rPropertySet, rItemPool )
101 CharacterPropertyItemConverter::CharacterPropertyItemConverter(
102 const uno::Reference< beans::XPropertySet > & rPropertySet,
103 SfxItemPool& rItemPool,
104 ::std::auto_ptr< awt::Size > pRefSize,
105 const ::rtl::OUString & rRefSizePropertyName,
106 const uno::Reference< beans::XPropertySet > & rRefSizePropSet ) :
107 ItemConverter( rPropertySet, rItemPool ),
108 m_pRefSize( pRefSize ),
109 m_aRefSizePropertyName( rRefSizePropertyName ),
110 m_xRefSizePropSet( rRefSizePropSet.is() ? rRefSizePropSet : rPropertySet )
113 CharacterPropertyItemConverter::~CharacterPropertyItemConverter()
116 const USHORT * CharacterPropertyItemConverter::GetWhichPairs() const
118 return nCharacterPropertyWhichPairs;
121 bool CharacterPropertyItemConverter::GetItemProperty( tWhichIdType nWhichId, tPropertyNameWithMemberId & rOutProperty ) const
123 ::comphelper::ItemPropertyMapType & rMap( lcl_GetCharacterPropertyPropertyMap());
124 ::comphelper::ItemPropertyMapType::const_iterator aIt( rMap.find( nWhichId ));
126 if( aIt == rMap.end())
127 return false;
129 rOutProperty =(*aIt).second;
130 return true;
133 void CharacterPropertyItemConverter::FillSpecialItem(
134 USHORT nWhichId, SfxItemSet & rOutItemSet ) const
135 throw( uno::Exception )
137 switch( nWhichId )
139 case EE_CHAR_FONTINFO:
140 case EE_CHAR_FONTINFO_CJK:
141 case EE_CHAR_FONTINFO_CTL:
143 ::rtl::OUString aPostfix;
144 if( nWhichId == EE_CHAR_FONTINFO_CJK )
145 aPostfix = C2U( "Asian" );
146 else if( nWhichId == EE_CHAR_FONTINFO_CTL )
147 aPostfix = C2U( "Complex" );
149 SvxFontItem aItem( nWhichId );
151 aItem.PutValue( GetPropertySet()->getPropertyValue( C2U( "CharFontName" ) + aPostfix),
152 MID_FONT_FAMILY_NAME );
153 aItem.PutValue( GetPropertySet()->getPropertyValue( C2U( "CharFontFamily" ) + aPostfix),
154 MID_FONT_FAMILY );
155 aItem.PutValue( GetPropertySet()->getPropertyValue( C2U( "CharFontStyleName" ) + aPostfix),
156 MID_FONT_STYLE_NAME );
157 aItem.PutValue( GetPropertySet()->getPropertyValue( C2U( "CharFontCharSet" ) + aPostfix),
158 MID_FONT_CHAR_SET );
159 aItem.PutValue( GetPropertySet()->getPropertyValue( C2U( "CharFontPitch" ) + aPostfix),
160 MID_FONT_PITCH );
162 rOutItemSet.Put( aItem );
164 break;
166 case EE_CHAR_UNDERLINE:
168 SvxUnderlineItem aItem(UNDERLINE_NONE, EE_CHAR_UNDERLINE);
169 bool bModified = false;
171 uno::Any aValue( GetPropertySet()->getPropertyValue( C2U( "CharUnderline" )));
172 if( aValue.hasValue())
174 aItem.PutValue( aValue, MID_TL_STYLE );
175 bModified = true;
178 aValue = GetPropertySet()->getPropertyValue( C2U( "CharUnderlineHasColor" ));
179 if( aValue.hasValue() &&
180 ( *reinterpret_cast< const sal_Bool * >( aValue.getValue()) != sal_False ))
182 aItem.PutValue( aValue, MID_TL_HASCOLOR );
183 bModified = true;
186 aValue = GetPropertySet()->getPropertyValue( C2U( "CharUnderlineColor" ));
187 if( aValue.hasValue())
189 aItem.PutValue( aValue, MID_TL_COLOR );
190 bModified = true;
193 if( bModified )
194 rOutItemSet.Put( aItem );
196 break;
198 case EE_CHAR_ITALIC:
199 case EE_CHAR_ITALIC_CJK:
200 case EE_CHAR_ITALIC_CTL:
202 ::rtl::OUString aPostfix;
203 if( nWhichId == EE_CHAR_ITALIC_CJK )
204 aPostfix = C2U( "Asian" );
205 else if( nWhichId == EE_CHAR_ITALIC_CTL )
206 aPostfix = C2U( "Complex" );
208 SvxPostureItem aItem( ITALIC_NONE, nWhichId );
210 uno::Any aValue( GetPropertySet()->getPropertyValue( C2U( "CharPosture" ) + aPostfix));
211 if( aValue.hasValue())
213 aItem.PutValue( aValue, MID_POSTURE );
214 rOutItemSet.Put( aItem );
217 break;
219 case EE_CHAR_WEIGHT:
220 case EE_CHAR_WEIGHT_CJK:
221 case EE_CHAR_WEIGHT_CTL:
223 ::rtl::OUString aPostfix;
224 if( nWhichId == EE_CHAR_WEIGHT_CJK )
225 aPostfix = C2U( "Asian" );
226 else if( nWhichId == EE_CHAR_WEIGHT_CTL )
227 aPostfix = C2U( "Complex" );
229 SvxWeightItem aItem( WEIGHT_NORMAL, nWhichId );
231 uno::Any aValue( GetPropertySet()->getPropertyValue( C2U( "CharWeight" ) + aPostfix));
232 if( aValue.hasValue())
234 aItem.PutValue( aValue, MID_WEIGHT );
235 rOutItemSet.Put( aItem );
238 break;
240 case EE_CHAR_FONTHEIGHT:
241 case EE_CHAR_FONTHEIGHT_CJK:
242 case EE_CHAR_FONTHEIGHT_CTL:
244 ::rtl::OUString aPostfix;
245 if( nWhichId == EE_CHAR_FONTHEIGHT_CJK )
246 aPostfix = C2U( "Asian" );
247 else if( nWhichId == EE_CHAR_FONTHEIGHT_CTL )
248 aPostfix = C2U( "Complex" );
250 SvxFontHeightItem aItem( 240, 100, nWhichId );
254 uno::Any aValue( GetPropertySet()->getPropertyValue( C2U( "CharHeight" ) + aPostfix ));
255 float fHeight;
256 if( aValue >>= fHeight )
258 if( m_pRefSize.get())
260 awt::Size aOldRefSize;
261 if( GetRefSizePropertySet()->getPropertyValue( m_aRefSizePropertyName ) >>= aOldRefSize )
263 // calculate font height in view
264 fHeight = static_cast< float >(
265 RelativeSizeHelper::calculate( fHeight, aOldRefSize, *m_pRefSize ));
266 aValue <<= fHeight;
270 aItem.PutValue( aValue, MID_FONTHEIGHT );
271 rOutItemSet.Put( aItem );
274 catch( uno::Exception & ex )
276 ASSERT_EXCEPTION( ex );
279 break;
281 case SID_CHAR_DLG_PREVIEW_STRING:
283 uno::Reference< chart2::XFormattedString > xFormattedString( GetPropertySet(), uno::UNO_QUERY );
284 if( xFormattedString.is() )
286 ::rtl::OUString aString = xFormattedString->getString();
287 rOutItemSet.Put( SfxStringItem( nWhichId, aString ) );
289 else
290 rOutItemSet.Put( SfxStringItem( nWhichId, C2U( "" ) ) );
292 break;
294 case EE_PARA_FORBIDDENRULES:
295 case EE_PARA_HANGINGPUNCTUATION:
296 rOutItemSet.DisableItem( nWhichId );
297 break;
301 bool CharacterPropertyItemConverter::ApplySpecialItem(
302 USHORT nWhichId, const SfxItemSet & rItemSet )
303 throw( uno::Exception )
305 bool bChanged = false;
306 uno::Any aValue;
308 switch( nWhichId )
310 case EE_CHAR_FONTINFO:
311 case EE_CHAR_FONTINFO_CJK:
312 case EE_CHAR_FONTINFO_CTL:
314 ::rtl::OUString aPostfix;
315 if( nWhichId == EE_CHAR_FONTINFO_CJK )
316 aPostfix = C2U( "Asian" );
317 else if( nWhichId == EE_CHAR_FONTINFO_CTL )
318 aPostfix = C2U( "Complex" );
320 const SvxFontItem & rItem =
321 static_cast< const SvxFontItem & >(
322 rItemSet.Get( nWhichId ));
324 if( rItem.QueryValue( aValue, MID_FONT_FAMILY_NAME ))
326 if( aValue != GetPropertySet()->getPropertyValue( C2U( "CharFontName" ) + aPostfix ))
328 GetPropertySet()->setPropertyValue( C2U( "CharFontName" ) + aPostfix, aValue );
329 bChanged = true;
332 if( rItem.QueryValue( aValue, MID_FONT_FAMILY ))
334 if( aValue != GetPropertySet()->getPropertyValue( C2U( "CharFontFamily" ) + aPostfix ))
336 GetPropertySet()->setPropertyValue( C2U( "CharFontFamily" ) + aPostfix, aValue );
337 bChanged = true;
340 if( rItem.QueryValue( aValue, MID_FONT_STYLE_NAME ))
342 if( aValue != GetPropertySet()->getPropertyValue( C2U( "CharFontStyleName" ) + aPostfix ))
344 GetPropertySet()->setPropertyValue( C2U( "CharFontStyleName" ) + aPostfix, aValue );
345 bChanged = true;
348 if( rItem.QueryValue( aValue, MID_FONT_CHAR_SET ))
350 if( aValue != GetPropertySet()->getPropertyValue( C2U( "CharFontCharSet" ) + aPostfix ))
352 GetPropertySet()->setPropertyValue( C2U( "CharFontCharSet" ) + aPostfix, aValue );
353 bChanged = true;
356 if( rItem.QueryValue( aValue, MID_FONT_PITCH ))
358 if( aValue != GetPropertySet()->getPropertyValue( C2U( "CharFontPitch" ) + aPostfix ))
360 GetPropertySet()->setPropertyValue( C2U( "CharFontPitch" ) + aPostfix, aValue );
361 bChanged = true;
365 break;
367 case EE_CHAR_UNDERLINE:
369 const SvxUnderlineItem & rItem =
370 static_cast< const SvxUnderlineItem & >(
371 rItemSet.Get( nWhichId ));
373 if( rItem.QueryValue( aValue, MID_TL_STYLE ))
375 if( aValue != GetPropertySet()->getPropertyValue( C2U( "CharUnderline" ) ))
377 GetPropertySet()->setPropertyValue( C2U( "CharUnderline" ), aValue );
378 bChanged = true;
382 if( rItem.QueryValue( aValue, MID_TL_COLOR ))
384 if( aValue != GetPropertySet()->getPropertyValue( C2U( "CharUnderlineColor" ) ))
386 GetPropertySet()->setPropertyValue( C2U( "CharUnderlineColor" ), aValue );
387 bChanged = true;
391 if( rItem.QueryValue( aValue, MID_TL_HASCOLOR ))
393 if( aValue != GetPropertySet()->getPropertyValue( C2U( "CharUnderlineHasColor" ) ))
395 GetPropertySet()->setPropertyValue( C2U( "CharUnderlineHasColor" ), aValue );
396 bChanged = true;
400 break;
402 case EE_CHAR_ITALIC:
403 case EE_CHAR_ITALIC_CJK:
404 case EE_CHAR_ITALIC_CTL:
406 ::rtl::OUString aPostfix;
407 if( nWhichId == EE_CHAR_ITALIC_CJK )
408 aPostfix = C2U( "Asian" );
409 else if( nWhichId == EE_CHAR_ITALIC_CTL )
410 aPostfix = C2U( "Complex" );
412 const SvxPostureItem & rItem =
413 static_cast< const SvxPostureItem & >(
414 rItemSet.Get( nWhichId ));
416 if( rItem.QueryValue( aValue, MID_POSTURE ))
418 if( aValue != GetPropertySet()->getPropertyValue( C2U( "CharPosture" ) + aPostfix))
420 GetPropertySet()->setPropertyValue( C2U( "CharPosture" ) + aPostfix, aValue );
421 bChanged = true;
425 break;
427 case EE_CHAR_WEIGHT:
428 case EE_CHAR_WEIGHT_CJK:
429 case EE_CHAR_WEIGHT_CTL:
431 ::rtl::OUString aPostfix;
432 if( nWhichId == EE_CHAR_WEIGHT_CJK )
433 aPostfix = C2U( "Asian" );
434 else if( nWhichId == EE_CHAR_WEIGHT_CTL )
435 aPostfix = C2U( "Complex" );
437 const SvxWeightItem & rItem =
438 static_cast< const SvxWeightItem & >(
439 rItemSet.Get( nWhichId ));
441 if( rItem.QueryValue( aValue, MID_WEIGHT ))
443 if( aValue != GetPropertySet()->getPropertyValue( C2U( "CharWeight" ) + aPostfix))
445 GetPropertySet()->setPropertyValue( C2U( "CharWeight" ) + aPostfix, aValue );
446 bChanged = true;
450 break;
452 case EE_CHAR_FONTHEIGHT:
453 case EE_CHAR_FONTHEIGHT_CJK:
454 case EE_CHAR_FONTHEIGHT_CTL:
456 ::rtl::OUString aPostfix;
457 if( nWhichId == EE_CHAR_FONTHEIGHT_CJK )
458 aPostfix = C2U( "Asian" );
459 else if( nWhichId == EE_CHAR_FONTHEIGHT_CTL )
460 aPostfix = C2U( "Complex" );
462 const SvxFontHeightItem & rItem =
463 static_cast< const SvxFontHeightItem & >(
464 rItemSet.Get( nWhichId ));
468 if( rItem.QueryValue( aValue, MID_FONTHEIGHT ) )
470 bool bSetValue = false;
471 if( aValue != GetPropertySet()->getPropertyValue( C2U( "CharHeight" ) + aPostfix ))
472 bSetValue = true;
473 else
475 if( m_pRefSize.get() )
477 awt::Size aNewRefSize = *m_pRefSize;
478 awt::Size aOldRefSize;
479 if( GetRefSizePropertySet()->getPropertyValue( m_aRefSizePropertyName ) >>= aOldRefSize )
481 if( aNewRefSize.Width != aOldRefSize.Width
482 || aNewRefSize.Height != aOldRefSize.Height )
483 bSetValue = true;
487 if( bSetValue )
489 // set new reference size only if there was a reference size before (auto-scaling on)
490 if( m_pRefSize.get() &&
491 GetRefSizePropertySet()->getPropertyValue( m_aRefSizePropertyName ).hasValue())
493 GetRefSizePropertySet()->setPropertyValue( m_aRefSizePropertyName,
494 uno::makeAny( *m_pRefSize ));
497 GetPropertySet()->setPropertyValue( C2U( "CharHeight" ) + aPostfix, aValue );
498 bChanged = true;
502 catch( uno::Exception & ex )
504 ASSERT_EXCEPTION( ex );
507 break;
510 return bChanged;
513 uno::Reference< beans::XPropertySet >
514 CharacterPropertyItemConverter::GetRefSizePropertySet() const
516 return m_xRefSizePropSet;
519 } // namespace wrapper
520 } // namespace chart