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 <formcontrolfont.hxx>
21 #include <frm_strings.hxx>
22 #include <property.hxx>
23 #include <cppuhelper/propshlp.hxx>
24 #include <comphelper/property.hxx>
25 #include <comphelper/types.hxx>
26 #include <tools/color.hxx>
27 #include <sal/log.hxx>
28 #include <toolkit/helper/emptyfontdescriptor.hxx>
29 #include <com/sun/star/awt/FontRelief.hpp>
30 #include <com/sun/star/awt/FontEmphasisMark.hpp>
37 using namespace ::comphelper
;
38 using namespace ::com::sun::star::uno
;
39 using namespace ::com::sun::star::awt
;
40 using namespace ::com::sun::star::lang
;
41 using namespace ::com::sun::star::beans
;
46 Any
lcl_extractFontDescriptorAggregate( sal_Int32 _nHandle
, const FontDescriptor
& _rFont
)
51 case PROPERTY_ID_FONT_NAME
:
52 aValue
<<= _rFont
.Name
;
55 case PROPERTY_ID_FONT_STYLENAME
:
56 aValue
<<= _rFont
.StyleName
;
59 case PROPERTY_ID_FONT_FAMILY
:
60 aValue
<<= _rFont
.Family
;
63 case PROPERTY_ID_FONT_CHARSET
:
64 aValue
<<= _rFont
.CharSet
;
67 case PROPERTY_ID_FONT_CHARWIDTH
:
68 aValue
<<= _rFont
.CharacterWidth
;
71 case PROPERTY_ID_FONT_KERNING
:
72 aValue
<<= _rFont
.Kerning
;
75 case PROPERTY_ID_FONT_ORIENTATION
:
76 aValue
<<= _rFont
.Orientation
;
79 case PROPERTY_ID_FONT_PITCH
:
80 aValue
<<= _rFont
.Pitch
;
83 case PROPERTY_ID_FONT_TYPE
:
84 aValue
<<= _rFont
.Type
;
87 case PROPERTY_ID_FONT_WIDTH
:
88 aValue
<<= _rFont
.Width
;
91 case PROPERTY_ID_FONT_HEIGHT
:
92 aValue
<<= static_cast<float>( _rFont
.Height
);
95 case PROPERTY_ID_FONT_WEIGHT
:
96 aValue
<<= _rFont
.Weight
;
99 case PROPERTY_ID_FONT_SLANT
:
100 aValue
<<= _rFont
.Slant
;
103 case PROPERTY_ID_FONT_UNDERLINE
:
104 aValue
<<= _rFont
.Underline
;
107 case PROPERTY_ID_FONT_STRIKEOUT
:
108 aValue
<<= _rFont
.Strikeout
;
111 case PROPERTY_ID_FONT_WORDLINEMODE
:
112 aValue
<<= _rFont
.WordLineMode
;
116 OSL_FAIL( "lcl_extractFontDescriptorAggregate: invalid handle!" );
123 FontControlModel::FontControlModel( bool _bToolkitCompatibleDefaults
)
124 :m_nFontRelief( css::awt::FontRelief::NONE
)
125 ,m_nFontEmphasis( css::awt::FontEmphasisMark::NONE
)
126 ,m_bToolkitCompatibleDefaults( _bToolkitCompatibleDefaults
)
131 FontControlModel::FontControlModel( const FontControlModel
* _pOriginal
)
133 m_aFont
= _pOriginal
->m_aFont
;
134 m_nFontRelief
= _pOriginal
->m_nFontRelief
;
135 m_nFontEmphasis
= _pOriginal
->m_nFontEmphasis
;
136 m_aTextLineColor
= _pOriginal
->m_aTextLineColor
;
137 m_aTextColor
= _pOriginal
->m_aTextColor
;
138 m_bToolkitCompatibleDefaults
= _pOriginal
->m_bToolkitCompatibleDefaults
;
142 bool FontControlModel::isFontRelatedProperty( sal_Int32 _nPropertyHandle
)
144 return isFontAggregateProperty( _nPropertyHandle
)
145 || ( _nPropertyHandle
== PROPERTY_ID_FONT
)
146 || ( _nPropertyHandle
== PROPERTY_ID_FONTEMPHASISMARK
)
147 || ( _nPropertyHandle
== PROPERTY_ID_FONTRELIEF
)
148 || ( _nPropertyHandle
== PROPERTY_ID_TEXTLINECOLOR
)
149 || ( _nPropertyHandle
== PROPERTY_ID_TEXTCOLOR
);
153 bool FontControlModel::isFontAggregateProperty( sal_Int32 _nPropertyHandle
)
155 return ( _nPropertyHandle
== PROPERTY_ID_FONT_CHARWIDTH
)
156 || ( _nPropertyHandle
== PROPERTY_ID_FONT_ORIENTATION
)
157 || ( _nPropertyHandle
== PROPERTY_ID_FONT_WIDTH
)
158 || ( _nPropertyHandle
== PROPERTY_ID_FONT_NAME
)
159 || ( _nPropertyHandle
== PROPERTY_ID_FONT_STYLENAME
)
160 || ( _nPropertyHandle
== PROPERTY_ID_FONT_FAMILY
)
161 || ( _nPropertyHandle
== PROPERTY_ID_FONT_CHARSET
)
162 || ( _nPropertyHandle
== PROPERTY_ID_FONT_HEIGHT
)
163 || ( _nPropertyHandle
== PROPERTY_ID_FONT_WEIGHT
)
164 || ( _nPropertyHandle
== PROPERTY_ID_FONT_SLANT
)
165 || ( _nPropertyHandle
== PROPERTY_ID_FONT_UNDERLINE
)
166 || ( _nPropertyHandle
== PROPERTY_ID_FONT_STRIKEOUT
)
167 || ( _nPropertyHandle
== PROPERTY_ID_FONT_WORDLINEMODE
)
168 || ( _nPropertyHandle
== PROPERTY_ID_FONT_PITCH
)
169 || ( _nPropertyHandle
== PROPERTY_ID_FONT_KERNING
)
170 || ( _nPropertyHandle
== PROPERTY_ID_FONT_TYPE
);
174 Color
FontControlModel::getTextColor( ) const
176 Color nColor
= COL_TRANSPARENT
;
177 m_aTextColor
>>= nColor
;
182 Color
FontControlModel::getTextLineColor( ) const
184 Color nColor
= COL_TRANSPARENT
;
185 m_aTextLineColor
>>= nColor
;
190 void FontControlModel::describeFontRelatedProperties( Sequence
< Property
>& /* [out] */ _rProps
)
192 sal_Int32 nPos
= _rProps
.getLength();
193 _rProps
.realloc( nPos
+ 21 );
194 Property
* pProperties
= _rProps
.getArray();
196 *pProperties
++ = css::beans::Property(PROPERTY_FONT
, PROPERTY_ID_FONT
, cppu::UnoType
<FontDescriptor
>::get(), css::beans::PropertyAttribute::BOUND
| css::beans::PropertyAttribute::MAYBEDEFAULT
);
197 *pProperties
++ = css::beans::Property(PROPERTY_FONTEMPHASISMARK
, PROPERTY_ID_FONTEMPHASISMARK
, cppu::UnoType
<sal_Int16
>::get(), css::beans::PropertyAttribute::BOUND
| css::beans::PropertyAttribute::MAYBEDEFAULT
);
198 *pProperties
++ = css::beans::Property(PROPERTY_FONTRELIEF
, PROPERTY_ID_FONTRELIEF
, cppu::UnoType
<sal_Int16
>::get(), css::beans::PropertyAttribute::BOUND
| css::beans::PropertyAttribute::MAYBEDEFAULT
);
199 *pProperties
++ = css::beans::Property(PROPERTY_TEXTCOLOR
, PROPERTY_ID_TEXTCOLOR
, cppu::UnoType
<sal_Int32
>::get(), css::beans::PropertyAttribute::BOUND
| css::beans::PropertyAttribute::MAYBEDEFAULT
| css::beans::PropertyAttribute::MAYBEVOID
);
200 *pProperties
++ = css::beans::Property(PROPERTY_TEXTLINECOLOR
, PROPERTY_ID_TEXTLINECOLOR
, cppu::UnoType
<sal_Int32
>::get(), css::beans::PropertyAttribute::BOUND
| css::beans::PropertyAttribute::MAYBEDEFAULT
| css::beans::PropertyAttribute::MAYBEVOID
);
202 *pProperties
++ = css::beans::Property(PROPERTY_FONT_CHARWIDTH
, PROPERTY_ID_FONT_CHARWIDTH
, cppu::UnoType
<float>::get(), css::beans::PropertyAttribute::MAYBEDEFAULT
);
203 *pProperties
++ = css::beans::Property(PROPERTY_FONT_KERNING
, PROPERTY_ID_FONT_KERNING
, cppu::UnoType
<bool>::get(),
204 css::beans::PropertyAttribute::MAYBEDEFAULT
);
205 *pProperties
++ = css::beans::Property(PROPERTY_FONT_ORIENTATION
, PROPERTY_ID_FONT_ORIENTATION
, cppu::UnoType
<float>::get(), css::beans::PropertyAttribute::MAYBEDEFAULT
);
206 *pProperties
++ = css::beans::Property(PROPERTY_FONT_PITCH
, PROPERTY_ID_FONT_PITCH
, cppu::UnoType
<sal_Int16
>::get(), css::beans::PropertyAttribute::MAYBEDEFAULT
);
207 *pProperties
++ = css::beans::Property(PROPERTY_FONT_TYPE
, PROPERTY_ID_FONT_TYPE
, cppu::UnoType
<sal_Int16
>::get(), css::beans::PropertyAttribute::MAYBEDEFAULT
);
208 *pProperties
++ = css::beans::Property(PROPERTY_FONT_WIDTH
, PROPERTY_ID_FONT_WIDTH
, cppu::UnoType
<sal_Int16
>::get(), css::beans::PropertyAttribute::MAYBEDEFAULT
);
209 *pProperties
++ = css::beans::Property(PROPERTY_FONT_NAME
, PROPERTY_ID_FONT_NAME
, cppu::UnoType
<OUString
>::get(), css::beans::PropertyAttribute::MAYBEDEFAULT
);
210 *pProperties
++ = css::beans::Property(PROPERTY_FONT_STYLENAME
, PROPERTY_ID_FONT_STYLENAME
, cppu::UnoType
<OUString
>::get(), css::beans::PropertyAttribute::MAYBEDEFAULT
);
211 *pProperties
++ = css::beans::Property(PROPERTY_FONT_FAMILY
, PROPERTY_ID_FONT_FAMILY
, cppu::UnoType
<sal_Int16
>::get(), css::beans::PropertyAttribute::MAYBEDEFAULT
);
212 *pProperties
++ = css::beans::Property(PROPERTY_FONT_CHARSET
, PROPERTY_ID_FONT_CHARSET
, cppu::UnoType
<sal_Int16
>::get(), css::beans::PropertyAttribute::MAYBEDEFAULT
);
213 *pProperties
++ = css::beans::Property(PROPERTY_FONT_HEIGHT
, PROPERTY_ID_FONT_HEIGHT
, cppu::UnoType
<float>::get(), css::beans::PropertyAttribute::MAYBEDEFAULT
);
214 *pProperties
++ = css::beans::Property(PROPERTY_FONT_WEIGHT
, PROPERTY_ID_FONT_WEIGHT
, cppu::UnoType
<float>::get(), css::beans::PropertyAttribute::MAYBEDEFAULT
);
215 *pProperties
++ = css::beans::Property(PROPERTY_FONT_SLANT
, PROPERTY_ID_FONT_SLANT
, cppu::UnoType
<sal_Int16
>::get(), css::beans::PropertyAttribute::MAYBEDEFAULT
);
216 *pProperties
++ = css::beans::Property(PROPERTY_FONT_UNDERLINE
, PROPERTY_ID_FONT_UNDERLINE
, cppu::UnoType
<sal_Int16
>::get(), css::beans::PropertyAttribute::MAYBEDEFAULT
);
217 *pProperties
++ = css::beans::Property(PROPERTY_FONT_STRIKEOUT
, PROPERTY_ID_FONT_STRIKEOUT
, cppu::UnoType
<sal_Int16
>::get(), css::beans::PropertyAttribute::MAYBEDEFAULT
);
218 *pProperties
++ = css::beans::Property(PROPERTY_FONT_WORDLINEMODE
, PROPERTY_ID_FONT_WORDLINEMODE
, cppu::UnoType
<bool>::get(),
219 css::beans::PropertyAttribute::MAYBEDEFAULT
);
223 void FontControlModel::getFastPropertyValue( Any
& _rValue
, sal_Int32 _nHandle
) const
227 case PROPERTY_ID_TEXTCOLOR
:
228 _rValue
= m_aTextColor
;
231 case PROPERTY_ID_FONTEMPHASISMARK
:
232 _rValue
<<= m_nFontEmphasis
;
235 case PROPERTY_ID_FONTRELIEF
:
236 _rValue
<<= m_nFontRelief
;
239 case PROPERTY_ID_TEXTLINECOLOR
:
240 _rValue
= m_aTextLineColor
;
243 case PROPERTY_ID_FONT
:
248 _rValue
= lcl_extractFontDescriptorAggregate( _nHandle
, m_aFont
);
254 bool FontControlModel::convertFastPropertyValue( Any
& _rConvertedValue
, Any
& _rOldValue
,
255 sal_Int32 _nHandle
, const Any
& _rValue
)
257 bool bModified
= false;
260 case PROPERTY_ID_TEXTCOLOR
:
261 bModified
= tryPropertyValue( _rConvertedValue
, _rOldValue
, _rValue
, m_aTextColor
, cppu::UnoType
<sal_Int32
>::get() );
264 case PROPERTY_ID_TEXTLINECOLOR
:
265 bModified
= tryPropertyValue( _rConvertedValue
, _rOldValue
, _rValue
, m_aTextLineColor
, cppu::UnoType
<sal_Int32
>::get() );
268 case PROPERTY_ID_FONTEMPHASISMARK
:
269 bModified
= tryPropertyValue( _rConvertedValue
, _rOldValue
, _rValue
, m_nFontEmphasis
);
272 case PROPERTY_ID_FONTRELIEF
:
273 bModified
= tryPropertyValue( _rConvertedValue
, _rOldValue
, _rValue
, m_nFontRelief
);
276 case PROPERTY_ID_FONT
:
278 Any aWorkAroundGccLimitation
= makeAny( m_aFont
);
279 bModified
= tryPropertyValue( _rConvertedValue
, _rOldValue
, _rValue
, aWorkAroundGccLimitation
, cppu::UnoType
<decltype(m_aFont
)>::get() );
283 case PROPERTY_ID_FONT_NAME
:
284 bModified
= tryPropertyValue( _rConvertedValue
, _rOldValue
, _rValue
, m_aFont
.Name
);
287 case PROPERTY_ID_FONT_STYLENAME
:
288 bModified
= tryPropertyValue( _rConvertedValue
, _rOldValue
, _rValue
, m_aFont
.StyleName
);
291 case PROPERTY_ID_FONT_FAMILY
:
292 bModified
= tryPropertyValue( _rConvertedValue
, _rOldValue
, _rValue
, m_aFont
.Family
);
295 case PROPERTY_ID_FONT_CHARSET
:
296 bModified
= tryPropertyValue( _rConvertedValue
, _rOldValue
, _rValue
, m_aFont
.CharSet
);
299 case PROPERTY_ID_FONT_CHARWIDTH
:
300 bModified
= tryPropertyValue( _rConvertedValue
, _rOldValue
, _rValue
, m_aFont
.CharacterWidth
);
303 case PROPERTY_ID_FONT_KERNING
:
304 bModified
= tryPropertyValue( _rConvertedValue
, _rOldValue
, _rValue
, m_aFont
.Kerning
);
307 case PROPERTY_ID_FONT_ORIENTATION
:
308 bModified
= tryPropertyValue( _rConvertedValue
, _rOldValue
, _rValue
, m_aFont
.Orientation
);
311 case PROPERTY_ID_FONT_PITCH
:
312 bModified
= tryPropertyValue( _rConvertedValue
, _rOldValue
, _rValue
, m_aFont
.Pitch
);
315 case PROPERTY_ID_FONT_TYPE
:
316 bModified
= tryPropertyValue( _rConvertedValue
, _rOldValue
, _rValue
, m_aFont
.Type
);
319 case PROPERTY_ID_FONT_WIDTH
:
320 bModified
= tryPropertyValue( _rConvertedValue
, _rOldValue
, _rValue
, m_aFont
.Width
);
323 case PROPERTY_ID_FONT_HEIGHT
:
324 bModified
= tryPropertyValue( _rConvertedValue
, _rOldValue
, _rValue
, float( m_aFont
.Height
) );
327 case PROPERTY_ID_FONT_WEIGHT
:
328 bModified
= tryPropertyValue( _rConvertedValue
, _rOldValue
, _rValue
, m_aFont
.Weight
);
331 case PROPERTY_ID_FONT_SLANT
:
332 bModified
= tryPropertyValueEnum( _rConvertedValue
, _rOldValue
, _rValue
, m_aFont
.Slant
);
335 case PROPERTY_ID_FONT_UNDERLINE
:
336 bModified
= tryPropertyValue( _rConvertedValue
, _rOldValue
, _rValue
, m_aFont
.Underline
);
339 case PROPERTY_ID_FONT_STRIKEOUT
:
340 bModified
= tryPropertyValue( _rConvertedValue
, _rOldValue
, _rValue
, m_aFont
.Strikeout
);
343 case PROPERTY_ID_FONT_WORDLINEMODE
:
344 bModified
= tryPropertyValue( _rConvertedValue
, _rOldValue
, _rValue
, m_aFont
.WordLineMode
);
348 OSL_FAIL( "FontControlModel::convertFastPropertyValue: no font aggregate!" );
353 /// @throws Exception
354 static void setFastPropertyValue_NoBroadcast_implimpl(
355 FontDescriptor
& rFont
,
356 sal_Int32 nHandle
, const Any
& rValue
)
360 case PROPERTY_ID_FONT_NAME
:
361 rValue
>>= rFont
.Name
;
364 case PROPERTY_ID_FONT_STYLENAME
:
365 rValue
>>= rFont
.StyleName
;
368 case PROPERTY_ID_FONT_FAMILY
:
369 rValue
>>= rFont
.Family
;
372 case PROPERTY_ID_FONT_CHARSET
:
373 rValue
>>= rFont
.CharSet
;
376 case PROPERTY_ID_FONT_CHARWIDTH
:
377 rValue
>>= rFont
.CharacterWidth
;
380 case PROPERTY_ID_FONT_KERNING
:
381 rValue
>>= rFont
.Kerning
;
384 case PROPERTY_ID_FONT_ORIENTATION
:
385 rValue
>>= rFont
.Orientation
;
388 case PROPERTY_ID_FONT_PITCH
:
389 rValue
>>= rFont
.Pitch
;
392 case PROPERTY_ID_FONT_TYPE
:
393 rValue
>>= rFont
.Type
;
396 case PROPERTY_ID_FONT_WIDTH
:
397 rValue
>>= rFont
.Width
;
400 case PROPERTY_ID_FONT_HEIGHT
:
404 rFont
.Height
= static_cast<sal_Int16
>(nHeight
);
408 case PROPERTY_ID_FONT_WEIGHT
:
409 rValue
>>= rFont
.Weight
;
412 case PROPERTY_ID_FONT_SLANT
:
413 rValue
>>= rFont
.Slant
;
416 case PROPERTY_ID_FONT_UNDERLINE
:
417 rValue
>>= rFont
.Underline
;
420 case PROPERTY_ID_FONT_STRIKEOUT
:
421 rValue
>>= rFont
.Strikeout
;
424 case PROPERTY_ID_FONT_WORDLINEMODE
:
426 bool bWordLineMode
= false;
427 rValue
>>= bWordLineMode
;
428 rFont
.WordLineMode
= bWordLineMode
;
433 assert(false); // isFontAggregateProperty
437 void FontControlModel::setFastPropertyValue_NoBroadcast_impl(
438 ::cppu::OPropertySetHelper
& rBase
,
439 void (::cppu::OPropertySetHelper::*pSet
)(sal_Int32
, Any
const&),
440 sal_Int32 nHandle
, const Any
& rValue
)
442 if (isFontAggregateProperty(nHandle
))
444 // need to fire an event for PROPERTY_ID_FONT too apparently, so:
445 FontDescriptor
font(getFont());
447 // first set new value on backup copy
448 setFastPropertyValue_NoBroadcast_implimpl(font
, nHandle
, rValue
);
450 // then set that as the actual property - will eventually call
451 // this method recursively again...
452 (rBase
.*pSet
)(PROPERTY_ID_FONT
, makeAny(font
));
454 // verify that the nHandle property has the new value
456 getFastPropertyValue(tmp
, nHandle
);
457 assert(tmp
== rValue
|| PROPERTY_ID_FONT_HEIGHT
== nHandle
/*rounded*/);
464 case PROPERTY_ID_TEXTCOLOR
:
465 m_aTextColor
= rValue
;
468 case PROPERTY_ID_TEXTLINECOLOR
:
469 m_aTextLineColor
= rValue
;
472 case PROPERTY_ID_FONTEMPHASISMARK
:
473 rValue
>>= m_nFontEmphasis
;
476 case PROPERTY_ID_FONTRELIEF
:
477 rValue
>>= m_nFontRelief
;
480 case PROPERTY_ID_FONT
:
485 SAL_WARN("forms.component", "invalid property: " << nHandle
);
491 Any
FontControlModel::getPropertyDefaultByHandle( sal_Int32 _nHandle
) const
494 // some defaults which are the same, not matter if we have toolkit-compatible
496 bool bHandled
= false;
499 case PROPERTY_ID_TEXTCOLOR
:
500 case PROPERTY_ID_TEXTLINECOLOR
:
505 case PROPERTY_ID_FONTEMPHASISMARK
:
506 aReturn
<<= css::awt::FontEmphasisMark::NONE
;
510 case PROPERTY_ID_FONTRELIEF
:
511 aReturn
<<= css::awt::FontRelief::NONE
;
518 if ( m_bToolkitCompatibleDefaults
)
520 EmptyFontDescriptor aEmpty
;
521 if ( PROPERTY_ID_FONT
== _nHandle
)
522 return makeAny( FontDescriptor(aEmpty
) );
523 return lcl_extractFontDescriptorAggregate( _nHandle
, aEmpty
);
528 case PROPERTY_ID_FONT
:
529 aReturn
<<= ::comphelper::getDefaultFont();
532 case PROPERTY_ID_FONT_WORDLINEMODE
:
536 case PROPERTY_ID_FONT_NAME
:
537 case PROPERTY_ID_FONT_STYLENAME
:
538 aReturn
<<= OUString();
541 case PROPERTY_ID_FONT_FAMILY
:
542 case PROPERTY_ID_FONT_CHARSET
:
543 case PROPERTY_ID_FONT_SLANT
:
544 case PROPERTY_ID_FONT_UNDERLINE
:
545 case PROPERTY_ID_FONT_STRIKEOUT
:
546 aReturn
<<= sal_Int16(1);
549 case PROPERTY_ID_FONT_KERNING
:
553 case PROPERTY_ID_FONT_PITCH
:
554 case PROPERTY_ID_FONT_TYPE
:
555 case PROPERTY_ID_FONT_WIDTH
:
556 aReturn
<<= sal_Int16(0);
559 case PROPERTY_ID_FONT_HEIGHT
:
560 case PROPERTY_ID_FONT_WEIGHT
:
561 case PROPERTY_ID_FONT_CHARWIDTH
:
562 case PROPERTY_ID_FONT_ORIENTATION
:
563 aReturn
<<= float(0);
567 OSL_FAIL( "FontControlModel::getPropertyDefaultByHandle: invalid property!" );
577 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */