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 "property.hrc"
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 <toolkit/helper/emptyfontdescriptor.hxx>
28 #include <com/sun/star/awt/FontRelief.hpp>
29 #include <com/sun/star/awt/FontEmphasisMark.hpp>
36 using namespace ::comphelper
;
37 using namespace ::com::sun::star::uno
;
38 using namespace ::com::sun::star::awt
;
39 using namespace ::com::sun::star::lang
;
40 using namespace ::com::sun::star::beans
;
45 Any
lcl_extractFontDescriptorAggregate( sal_Int32 _nHandle
, const FontDescriptor
& _rFont
)
50 case PROPERTY_ID_FONT_NAME
:
51 aValue
<<= _rFont
.Name
;
54 case PROPERTY_ID_FONT_STYLENAME
:
55 aValue
<<= _rFont
.StyleName
;
58 case PROPERTY_ID_FONT_FAMILY
:
59 aValue
<<= (sal_Int16
)_rFont
.Family
;
62 case PROPERTY_ID_FONT_CHARSET
:
63 aValue
<<= (sal_Int16
)_rFont
.CharSet
;
66 case PROPERTY_ID_FONT_CHARWIDTH
:
67 aValue
<<= _rFont
.CharacterWidth
;
70 case PROPERTY_ID_FONT_KERNING
:
71 aValue
<<= _rFont
.Kerning
;
74 case PROPERTY_ID_FONT_ORIENTATION
:
75 aValue
<<= _rFont
.Orientation
;
78 case PROPERTY_ID_FONT_PITCH
:
79 aValue
<<= _rFont
.Pitch
;
82 case PROPERTY_ID_FONT_TYPE
:
83 aValue
<<= _rFont
.Type
;
86 case PROPERTY_ID_FONT_WIDTH
:
87 aValue
<<= _rFont
.Width
;
90 case PROPERTY_ID_FONT_HEIGHT
:
91 aValue
<<= (float)( _rFont
.Height
);
94 case PROPERTY_ID_FONT_WEIGHT
:
95 aValue
<<= (float)_rFont
.Weight
;
98 case PROPERTY_ID_FONT_SLANT
:
99 aValue
= makeAny(_rFont
.Slant
);
102 case PROPERTY_ID_FONT_UNDERLINE
:
103 aValue
<<= (sal_Int16
)_rFont
.Underline
;
106 case PROPERTY_ID_FONT_STRIKEOUT
:
107 aValue
<<= (sal_Int16
)_rFont
.Strikeout
;
110 case PROPERTY_ID_FONT_WORDLINEMODE
:
111 aValue
= makeAny( _rFont
.WordLineMode
);
115 OSL_FAIL( "lcl_extractFontDescriptorAggregate: invalid handle!" );
122 FontControlModel::FontControlModel( bool _bToolkitCompatibleDefaults
)
123 :m_nFontRelief( css::awt::FontRelief::NONE
)
124 ,m_nFontEmphasis( FontEmphasisMark::NONE
)
125 ,m_bToolkitCompatibleDefaults( _bToolkitCompatibleDefaults
)
130 FontControlModel::FontControlModel( const FontControlModel
* _pOriginal
)
132 m_aFont
= _pOriginal
->m_aFont
;
133 m_nFontRelief
= _pOriginal
->m_nFontRelief
;
134 m_nFontEmphasis
= _pOriginal
->m_nFontEmphasis
;
135 m_aTextLineColor
= _pOriginal
->m_aTextLineColor
;
136 m_aTextColor
= _pOriginal
->m_aTextColor
;
137 m_bToolkitCompatibleDefaults
= _pOriginal
->m_bToolkitCompatibleDefaults
;
141 bool FontControlModel::isFontRelatedProperty( sal_Int32 _nPropertyHandle
)
143 return isFontAggregateProperty( _nPropertyHandle
)
144 || ( _nPropertyHandle
== PROPERTY_ID_FONT
)
145 || ( _nPropertyHandle
== PROPERTY_ID_FONTEMPHASISMARK
)
146 || ( _nPropertyHandle
== PROPERTY_ID_FONTRELIEF
)
147 || ( _nPropertyHandle
== PROPERTY_ID_TEXTLINECOLOR
)
148 || ( _nPropertyHandle
== PROPERTY_ID_TEXTCOLOR
);
152 bool FontControlModel::isFontAggregateProperty( sal_Int32 _nPropertyHandle
)
154 return ( _nPropertyHandle
== PROPERTY_ID_FONT_CHARWIDTH
)
155 || ( _nPropertyHandle
== PROPERTY_ID_FONT_ORIENTATION
)
156 || ( _nPropertyHandle
== PROPERTY_ID_FONT_WIDTH
)
157 || ( _nPropertyHandle
== PROPERTY_ID_FONT_NAME
)
158 || ( _nPropertyHandle
== PROPERTY_ID_FONT_STYLENAME
)
159 || ( _nPropertyHandle
== PROPERTY_ID_FONT_FAMILY
)
160 || ( _nPropertyHandle
== PROPERTY_ID_FONT_CHARSET
)
161 || ( _nPropertyHandle
== PROPERTY_ID_FONT_HEIGHT
)
162 || ( _nPropertyHandle
== PROPERTY_ID_FONT_WEIGHT
)
163 || ( _nPropertyHandle
== PROPERTY_ID_FONT_SLANT
)
164 || ( _nPropertyHandle
== PROPERTY_ID_FONT_UNDERLINE
)
165 || ( _nPropertyHandle
== PROPERTY_ID_FONT_STRIKEOUT
)
166 || ( _nPropertyHandle
== PROPERTY_ID_FONT_WORDLINEMODE
)
167 || ( _nPropertyHandle
== PROPERTY_ID_FONT_PITCH
)
168 || ( _nPropertyHandle
== PROPERTY_ID_FONT_KERNING
)
169 || ( _nPropertyHandle
== PROPERTY_ID_FONT_TYPE
);
173 sal_Int32
FontControlModel::getTextColor( ) const
175 sal_Int32 nColor
= COL_TRANSPARENT
;
176 m_aTextColor
>>= nColor
;
181 sal_Int32
FontControlModel::getTextLineColor( ) const
183 sal_Int32 nColor
= COL_TRANSPARENT
;
184 m_aTextLineColor
>>= nColor
;
189 void FontControlModel::describeFontRelatedProperties( Sequence
< Property
>& /* [out] */ _rProps
)
191 sal_Int32 nPos
= _rProps
.getLength();
192 _rProps
.realloc( nPos
+ 21 );
193 Property
* pProperties
= _rProps
.getArray();
195 DECL_PROP2 ( FONT
, FontDescriptor
, BOUND
, MAYBEDEFAULT
);
196 DECL_PROP2 ( FONTEMPHASISMARK
, sal_Int16
, BOUND
, MAYBEDEFAULT
);
197 DECL_PROP2 ( FONTRELIEF
, sal_Int16
, BOUND
, MAYBEDEFAULT
);
198 DECL_PROP3 ( TEXTCOLOR
, sal_Int32
, BOUND
, MAYBEDEFAULT
, MAYBEVOID
);
199 DECL_PROP3 ( TEXTLINECOLOR
, sal_Int32
, BOUND
, MAYBEDEFAULT
, MAYBEVOID
);
201 DECL_PROP1 ( FONT_CHARWIDTH
, float, MAYBEDEFAULT
);
202 DECL_BOOL_PROP1 ( FONT_KERNING
, MAYBEDEFAULT
);
203 DECL_PROP1 ( FONT_ORIENTATION
, float, MAYBEDEFAULT
);
204 DECL_PROP1 ( FONT_PITCH
, sal_Int16
, MAYBEDEFAULT
);
205 DECL_PROP1 ( FONT_TYPE
, sal_Int16
, MAYBEDEFAULT
);
206 DECL_PROP1 ( FONT_WIDTH
, sal_Int16
, MAYBEDEFAULT
);
207 DECL_PROP1 ( FONT_NAME
, OUString
, MAYBEDEFAULT
);
208 DECL_PROP1 ( FONT_STYLENAME
, OUString
, MAYBEDEFAULT
);
209 DECL_PROP1 ( FONT_FAMILY
, sal_Int16
, MAYBEDEFAULT
);
210 DECL_PROP1 ( FONT_CHARSET
, sal_Int16
, MAYBEDEFAULT
);
211 DECL_PROP1 ( FONT_HEIGHT
, float, MAYBEDEFAULT
);
212 DECL_PROP1 ( FONT_WEIGHT
, float, MAYBEDEFAULT
);
213 DECL_PROP1 ( FONT_SLANT
, sal_Int16
, MAYBEDEFAULT
);
214 DECL_PROP1 ( FONT_UNDERLINE
, sal_Int16
, MAYBEDEFAULT
);
215 DECL_PROP1 ( FONT_STRIKEOUT
, sal_Int16
, MAYBEDEFAULT
);
216 DECL_BOOL_PROP1 ( FONT_WORDLINEMODE
, MAYBEDEFAULT
);
220 void FontControlModel::getFastPropertyValue( Any
& _rValue
, sal_Int32 _nHandle
) const
224 case PROPERTY_ID_TEXTCOLOR
:
225 _rValue
= m_aTextColor
;
228 case PROPERTY_ID_FONTEMPHASISMARK
:
229 _rValue
<<= m_nFontEmphasis
;
232 case PROPERTY_ID_FONTRELIEF
:
233 _rValue
<<= m_nFontRelief
;
236 case PROPERTY_ID_TEXTLINECOLOR
:
237 _rValue
= m_aTextLineColor
;
240 case PROPERTY_ID_FONT
:
241 _rValue
= makeAny( m_aFont
);
245 _rValue
= lcl_extractFontDescriptorAggregate( _nHandle
, m_aFont
);
251 bool FontControlModel::convertFastPropertyValue( Any
& _rConvertedValue
, Any
& _rOldValue
,
252 sal_Int32 _nHandle
, const Any
& _rValue
) throw( IllegalArgumentException
)
254 bool bModified
= false;
257 case PROPERTY_ID_TEXTCOLOR
:
258 bModified
= tryPropertyValue( _rConvertedValue
, _rOldValue
, _rValue
, m_aTextColor
, cppu::UnoType
<sal_Int32
>::get() );
261 case PROPERTY_ID_TEXTLINECOLOR
:
262 bModified
= tryPropertyValue( _rConvertedValue
, _rOldValue
, _rValue
, m_aTextLineColor
, cppu::UnoType
<sal_Int32
>::get() );
265 case PROPERTY_ID_FONTEMPHASISMARK
:
266 bModified
= tryPropertyValue( _rConvertedValue
, _rOldValue
, _rValue
, m_nFontEmphasis
);
269 case PROPERTY_ID_FONTRELIEF
:
270 bModified
= tryPropertyValue( _rConvertedValue
, _rOldValue
, _rValue
, m_nFontRelief
);
273 case PROPERTY_ID_FONT
:
275 Any aWorkAroundGccLimitation
= makeAny( m_aFont
);
276 bModified
= tryPropertyValue( _rConvertedValue
, _rOldValue
, _rValue
, aWorkAroundGccLimitation
, cppu::UnoType
<decltype(m_aFont
)>::get() );
280 case PROPERTY_ID_FONT_NAME
:
281 bModified
= tryPropertyValue( _rConvertedValue
, _rOldValue
, _rValue
, m_aFont
.Name
);
284 case PROPERTY_ID_FONT_STYLENAME
:
285 bModified
= tryPropertyValue( _rConvertedValue
, _rOldValue
, _rValue
, m_aFont
.StyleName
);
288 case PROPERTY_ID_FONT_FAMILY
:
289 bModified
= tryPropertyValue( _rConvertedValue
, _rOldValue
, _rValue
, (sal_Int16
)m_aFont
.Family
);
292 case PROPERTY_ID_FONT_CHARSET
:
293 bModified
= tryPropertyValue( _rConvertedValue
, _rOldValue
, _rValue
, (sal_Int16
)m_aFont
.CharSet
);
296 case PROPERTY_ID_FONT_CHARWIDTH
:
297 bModified
= tryPropertyValue( _rConvertedValue
, _rOldValue
, _rValue
, float( m_aFont
.CharacterWidth
) );
300 case PROPERTY_ID_FONT_KERNING
:
301 bModified
= tryPropertyValue( _rConvertedValue
, _rOldValue
, _rValue
, m_aFont
.Kerning
);
304 case PROPERTY_ID_FONT_ORIENTATION
:
305 bModified
= tryPropertyValue( _rConvertedValue
, _rOldValue
, _rValue
, float( m_aFont
.Orientation
) );
308 case PROPERTY_ID_FONT_PITCH
:
309 bModified
= tryPropertyValue( _rConvertedValue
, _rOldValue
, _rValue
, (sal_Int16
)m_aFont
.Pitch
);
312 case PROPERTY_ID_FONT_TYPE
:
313 bModified
= tryPropertyValue( _rConvertedValue
, _rOldValue
, _rValue
, (sal_Int16
)m_aFont
.Type
);
316 case PROPERTY_ID_FONT_WIDTH
:
317 bModified
= tryPropertyValue( _rConvertedValue
, _rOldValue
, _rValue
, (sal_Int16
)m_aFont
.Width
);
320 case PROPERTY_ID_FONT_HEIGHT
:
321 bModified
= tryPropertyValue( _rConvertedValue
, _rOldValue
, _rValue
, float( m_aFont
.Height
) );
324 case PROPERTY_ID_FONT_WEIGHT
:
325 bModified
= tryPropertyValue( _rConvertedValue
, _rOldValue
, _rValue
, m_aFont
.Weight
);
328 case PROPERTY_ID_FONT_SLANT
:
329 bModified
= tryPropertyValueEnum( _rConvertedValue
, _rOldValue
, _rValue
, m_aFont
.Slant
);
332 case PROPERTY_ID_FONT_UNDERLINE
:
333 bModified
= tryPropertyValue( _rConvertedValue
, _rOldValue
, _rValue
, (sal_Int16
)m_aFont
.Underline
);
336 case PROPERTY_ID_FONT_STRIKEOUT
:
337 bModified
= tryPropertyValue( _rConvertedValue
, _rOldValue
, _rValue
, (sal_Int16
)m_aFont
.Strikeout
);
340 case PROPERTY_ID_FONT_WORDLINEMODE
:
341 bModified
= tryPropertyValue( _rConvertedValue
, _rOldValue
, _rValue
, m_aFont
.WordLineMode
);
345 OSL_FAIL( "FontControlModel::convertFastPropertyValue: no font aggregate!" );
351 static void setFastPropertyValue_NoBroadcast_implimpl(
352 FontDescriptor
& rFont
,
353 sal_Int32 nHandle
, const Any
& rValue
) throw (Exception
)
357 case PROPERTY_ID_FONT_NAME
:
358 rValue
>>= rFont
.Name
;
361 case PROPERTY_ID_FONT_STYLENAME
:
362 rValue
>>= rFont
.StyleName
;
365 case PROPERTY_ID_FONT_FAMILY
:
366 rValue
>>= rFont
.Family
;
369 case PROPERTY_ID_FONT_CHARSET
:
370 rValue
>>= rFont
.CharSet
;
373 case PROPERTY_ID_FONT_CHARWIDTH
:
374 rValue
>>= rFont
.CharacterWidth
;
377 case PROPERTY_ID_FONT_KERNING
:
378 rValue
>>= rFont
.Kerning
;
381 case PROPERTY_ID_FONT_ORIENTATION
:
382 rValue
>>= rFont
.Orientation
;
385 case PROPERTY_ID_FONT_PITCH
:
386 rValue
>>= rFont
.Pitch
;
389 case PROPERTY_ID_FONT_TYPE
:
390 rValue
>>= rFont
.Type
;
393 case PROPERTY_ID_FONT_WIDTH
:
394 rValue
>>= rFont
.Width
;
397 case PROPERTY_ID_FONT_HEIGHT
:
401 rFont
.Height
= (sal_Int16
)nHeight
;
405 case PROPERTY_ID_FONT_WEIGHT
:
406 rValue
>>= rFont
.Weight
;
409 case PROPERTY_ID_FONT_SLANT
:
410 rValue
>>= rFont
.Slant
;
413 case PROPERTY_ID_FONT_UNDERLINE
:
414 rValue
>>= rFont
.Underline
;
417 case PROPERTY_ID_FONT_STRIKEOUT
:
418 rValue
>>= rFont
.Strikeout
;
421 case PROPERTY_ID_FONT_WORDLINEMODE
:
423 bool bWordLineMode
= false;
424 rValue
>>= bWordLineMode
;
425 rFont
.WordLineMode
= bWordLineMode
;
430 assert(false); // isFontAggregateProperty
434 void FontControlModel::setFastPropertyValue_NoBroadcast_impl(
435 ::cppu::OPropertySetHelper
& rBase
,
436 void (::cppu::OPropertySetHelper::*pSet
)(sal_Int32
, Any
const&),
437 sal_Int32 nHandle
, const Any
& rValue
) throw (Exception
)
439 if (isFontAggregateProperty(nHandle
))
441 // need to fire a event for PROPERTY_ID_FONT too apparently, so:
442 FontDescriptor
font(getFont());
444 // first set new value on backup copy
445 setFastPropertyValue_NoBroadcast_implimpl(font
, nHandle
, rValue
);
447 // then set that as the actual property - will eventually call
448 // this method recursively again...
449 (rBase
.*pSet
)(PROPERTY_ID_FONT
, makeAny(font
));
451 // verify that the nHandle property has the new value
453 getFastPropertyValue(tmp
, nHandle
);
454 assert(tmp
== rValue
|| PROPERTY_ID_FONT_HEIGHT
== nHandle
/*rounded*/);
461 case PROPERTY_ID_TEXTCOLOR
:
462 m_aTextColor
= rValue
;
465 case PROPERTY_ID_TEXTLINECOLOR
:
466 m_aTextLineColor
= rValue
;
469 case PROPERTY_ID_FONTEMPHASISMARK
:
470 rValue
>>= m_nFontEmphasis
;
473 case PROPERTY_ID_FONTRELIEF
:
474 rValue
>>= m_nFontRelief
;
477 case PROPERTY_ID_FONT
:
482 SAL_WARN("forms.component", "invalid property: " << nHandle
);
488 Any
FontControlModel::getPropertyDefaultByHandle( sal_Int32 _nHandle
) const
491 // some defaults which are the same, not matter if we have toolkit-compatible
493 bool bHandled
= false;
496 case PROPERTY_ID_TEXTCOLOR
:
497 case PROPERTY_ID_TEXTLINECOLOR
:
502 case PROPERTY_ID_FONTEMPHASISMARK
:
503 aReturn
<<= FontEmphasisMark::NONE
;
507 case PROPERTY_ID_FONTRELIEF
:
508 aReturn
<<= css::awt::FontRelief::NONE
;
515 if ( m_bToolkitCompatibleDefaults
)
517 EmptyFontDescriptor aEmpty
;
518 if ( PROPERTY_ID_FONT
== _nHandle
)
519 return makeAny( FontDescriptor(aEmpty
) );
520 return lcl_extractFontDescriptorAggregate( _nHandle
, aEmpty
);
525 case PROPERTY_ID_FONT
:
526 aReturn
<<= ::comphelper::getDefaultFont();
529 case PROPERTY_ID_FONT_WORDLINEMODE
:
530 aReturn
= makeBoolAny(false);
533 case PROPERTY_ID_FONT_NAME
:
534 case PROPERTY_ID_FONT_STYLENAME
:
535 aReturn
<<= OUString();
538 case PROPERTY_ID_FONT_FAMILY
:
539 case PROPERTY_ID_FONT_CHARSET
:
540 case PROPERTY_ID_FONT_SLANT
:
541 case PROPERTY_ID_FONT_UNDERLINE
:
542 case PROPERTY_ID_FONT_STRIKEOUT
:
543 aReturn
<<= (sal_Int16
)1;
546 case PROPERTY_ID_FONT_KERNING
:
547 aReturn
= makeBoolAny(false);
550 case PROPERTY_ID_FONT_PITCH
:
551 case PROPERTY_ID_FONT_TYPE
:
552 case PROPERTY_ID_FONT_WIDTH
:
553 aReturn
<<= (sal_Int16
)0;
556 case PROPERTY_ID_FONT_HEIGHT
:
557 case PROPERTY_ID_FONT_WEIGHT
:
558 case PROPERTY_ID_FONT_CHARWIDTH
:
559 case PROPERTY_ID_FONT_ORIENTATION
:
560 aReturn
<<= (float)0;
564 OSL_FAIL( "FontControlModel::getPropertyDefaultByHandle: invalid property!" );
574 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */