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 <comphelper/property.hxx>
24 #include <comphelper/types.hxx>
25 #include <tools/color.hxx>
26 #include <toolkit/helper/emptyfontdescriptor.hxx>
27 #include <com/sun/star/awt/FontRelief.hpp>
28 #include <com/sun/star/awt/FontEmphasisMark.hpp>
30 //.........................................................................
33 //.........................................................................
35 using namespace ::comphelper
;
36 using namespace ::com::sun::star::uno
;
37 using namespace ::com::sun::star::awt
;
38 using namespace ::com::sun::star::lang
;
39 using namespace ::com::sun::star::beans
;
41 //------------------------------------------------------------------------------
44 Any
lcl_extractFontDescriptorAggregate( sal_Int32 _nHandle
, const FontDescriptor
& _rFont
)
49 case PROPERTY_ID_FONT_NAME
:
50 aValue
<<= _rFont
.Name
;
53 case PROPERTY_ID_FONT_STYLENAME
:
54 aValue
<<= _rFont
.StyleName
;
57 case PROPERTY_ID_FONT_FAMILY
:
58 aValue
<<= (sal_Int16
)_rFont
.Family
;
61 case PROPERTY_ID_FONT_CHARSET
:
62 aValue
<<= (sal_Int16
)_rFont
.CharSet
;
65 case PROPERTY_ID_FONT_CHARWIDTH
:
66 aValue
<<= _rFont
.CharacterWidth
;
69 case PROPERTY_ID_FONT_KERNING
:
70 aValue
<<= _rFont
.Kerning
;
73 case PROPERTY_ID_FONT_ORIENTATION
:
74 aValue
<<= _rFont
.Orientation
;
77 case PROPERTY_ID_FONT_PITCH
:
78 aValue
<<= _rFont
.Pitch
;
81 case PROPERTY_ID_FONT_TYPE
:
82 aValue
<<= _rFont
.Type
;
85 case PROPERTY_ID_FONT_WIDTH
:
86 aValue
<<= _rFont
.Width
;
89 case PROPERTY_ID_FONT_HEIGHT
:
90 aValue
<<= (float)( _rFont
.Height
);
93 case PROPERTY_ID_FONT_WEIGHT
:
94 aValue
<<= (float)_rFont
.Weight
;
97 case PROPERTY_ID_FONT_SLANT
:
98 aValue
= makeAny(_rFont
.Slant
);
101 case PROPERTY_ID_FONT_UNDERLINE
:
102 aValue
<<= (sal_Int16
)_rFont
.Underline
;
105 case PROPERTY_ID_FONT_STRIKEOUT
:
106 aValue
<<= (sal_Int16
)_rFont
.Strikeout
;
109 case PROPERTY_ID_FONT_WORDLINEMODE
:
110 aValue
= makeAny( (sal_Bool
)_rFont
.WordLineMode
);
114 OSL_FAIL( "lcl_extractFontDescriptorAggregate: invalid handle!" );
121 //=====================================================================
123 //=====================================================================
124 //---------------------------------------------------------------------
125 FontControlModel::FontControlModel( bool _bToolkitCompatibleDefaults
)
126 :m_nFontRelief( FontRelief::NONE
)
127 ,m_nFontEmphasis( FontEmphasisMark::NONE
)
128 ,m_bToolkitCompatibleDefaults( _bToolkitCompatibleDefaults
)
132 //---------------------------------------------------------------------
133 FontControlModel::FontControlModel( const FontControlModel
* _pOriginal
)
135 m_aFont
= _pOriginal
->m_aFont
;
136 m_nFontRelief
= _pOriginal
->m_nFontRelief
;
137 m_nFontEmphasis
= _pOriginal
->m_nFontEmphasis
;
138 m_aTextLineColor
= _pOriginal
->m_aTextLineColor
;
139 m_aTextColor
= _pOriginal
->m_aTextColor
;
140 m_bToolkitCompatibleDefaults
= _pOriginal
->m_bToolkitCompatibleDefaults
;
143 //---------------------------------------------------------------------
144 bool FontControlModel::isFontRelatedProperty( sal_Int32 _nPropertyHandle
) const
146 return isFontAggregateProperty( _nPropertyHandle
)
147 || ( _nPropertyHandle
== PROPERTY_ID_FONT
)
148 || ( _nPropertyHandle
== PROPERTY_ID_FONTEMPHASISMARK
)
149 || ( _nPropertyHandle
== PROPERTY_ID_FONTRELIEF
)
150 || ( _nPropertyHandle
== PROPERTY_ID_TEXTLINECOLOR
)
151 || ( _nPropertyHandle
== PROPERTY_ID_TEXTCOLOR
);
154 //---------------------------------------------------------------------
155 bool FontControlModel::isFontAggregateProperty( sal_Int32 _nPropertyHandle
) const
157 return ( _nPropertyHandle
== PROPERTY_ID_FONT_CHARWIDTH
)
158 || ( _nPropertyHandle
== PROPERTY_ID_FONT_ORIENTATION
)
159 || ( _nPropertyHandle
== PROPERTY_ID_FONT_WIDTH
)
160 || ( _nPropertyHandle
== PROPERTY_ID_FONT_NAME
)
161 || ( _nPropertyHandle
== PROPERTY_ID_FONT_STYLENAME
)
162 || ( _nPropertyHandle
== PROPERTY_ID_FONT_FAMILY
)
163 || ( _nPropertyHandle
== PROPERTY_ID_FONT_CHARSET
)
164 || ( _nPropertyHandle
== PROPERTY_ID_FONT_HEIGHT
)
165 || ( _nPropertyHandle
== PROPERTY_ID_FONT_WEIGHT
)
166 || ( _nPropertyHandle
== PROPERTY_ID_FONT_SLANT
)
167 || ( _nPropertyHandle
== PROPERTY_ID_FONT_UNDERLINE
)
168 || ( _nPropertyHandle
== PROPERTY_ID_FONT_STRIKEOUT
)
169 || ( _nPropertyHandle
== PROPERTY_ID_FONT_WORDLINEMODE
)
170 || ( _nPropertyHandle
== PROPERTY_ID_FONT_PITCH
)
171 || ( _nPropertyHandle
== PROPERTY_ID_FONT_KERNING
)
172 || ( _nPropertyHandle
== PROPERTY_ID_FONT_TYPE
);
175 //---------------------------------------------------------------------
176 sal_Int32
FontControlModel::getTextColor( ) const
178 sal_Int32 nColor
= COL_TRANSPARENT
;
179 m_aTextColor
>>= nColor
;
183 //---------------------------------------------------------------------
184 sal_Int32
FontControlModel::getTextLineColor( ) const
186 sal_Int32 nColor
= COL_TRANSPARENT
;
187 m_aTextLineColor
>>= nColor
;
191 //------------------------------------------------------------------------------
192 void FontControlModel::describeFontRelatedProperties( Sequence
< Property
>& /* [out] */ _rProps
) const
194 sal_Int32 nPos
= _rProps
.getLength();
195 _rProps
.realloc( nPos
+ 21 );
196 Property
* pProperties
= _rProps
.getArray();
198 DECL_PROP2 ( FONT
, FontDescriptor
, BOUND
, MAYBEDEFAULT
);
199 DECL_PROP2 ( FONTEMPHASISMARK
, sal_Int16
, BOUND
, MAYBEDEFAULT
);
200 DECL_PROP2 ( FONTRELIEF
, sal_Int16
, BOUND
, MAYBEDEFAULT
);
201 DECL_PROP3 ( TEXTCOLOR
, sal_Int32
, BOUND
, MAYBEDEFAULT
, MAYBEVOID
);
202 DECL_PROP3 ( TEXTLINECOLOR
, sal_Int32
, BOUND
, MAYBEDEFAULT
, MAYBEVOID
);
204 DECL_PROP1 ( FONT_CHARWIDTH
, float, MAYBEDEFAULT
);
205 DECL_BOOL_PROP1 ( FONT_KERNING
, MAYBEDEFAULT
);
206 DECL_PROP1 ( FONT_ORIENTATION
, float, MAYBEDEFAULT
);
207 DECL_PROP1 ( FONT_PITCH
, sal_Int16
, MAYBEDEFAULT
);
208 DECL_PROP1 ( FONT_TYPE
, sal_Int16
, MAYBEDEFAULT
);
209 DECL_PROP1 ( FONT_WIDTH
, sal_Int16
, MAYBEDEFAULT
);
210 DECL_PROP1 ( FONT_NAME
, OUString
, MAYBEDEFAULT
);
211 DECL_PROP1 ( FONT_STYLENAME
, OUString
, MAYBEDEFAULT
);
212 DECL_PROP1 ( FONT_FAMILY
, sal_Int16
, MAYBEDEFAULT
);
213 DECL_PROP1 ( FONT_CHARSET
, sal_Int16
, MAYBEDEFAULT
);
214 DECL_PROP1 ( FONT_HEIGHT
, float, MAYBEDEFAULT
);
215 DECL_PROP1 ( FONT_WEIGHT
, float, MAYBEDEFAULT
);
216 DECL_PROP1 ( FONT_SLANT
, sal_Int16
, MAYBEDEFAULT
);
217 DECL_PROP1 ( FONT_UNDERLINE
, sal_Int16
, MAYBEDEFAULT
);
218 DECL_PROP1 ( FONT_STRIKEOUT
, sal_Int16
, MAYBEDEFAULT
);
219 DECL_BOOL_PROP1 ( FONT_WORDLINEMODE
, MAYBEDEFAULT
);
222 //---------------------------------------------------------------------
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
:
244 _rValue
= makeAny( m_aFont
);
248 _rValue
= lcl_extractFontDescriptorAggregate( _nHandle
, m_aFont
);
253 //---------------------------------------------------------------------
254 sal_Bool
FontControlModel::convertFastPropertyValue( Any
& _rConvertedValue
, Any
& _rOldValue
,
255 sal_Int32 _nHandle
, const Any
& _rValue
) throw( IllegalArgumentException
)
257 sal_Bool bModified
= sal_False
;
260 case PROPERTY_ID_TEXTCOLOR
:
261 bModified
= tryPropertyValue( _rConvertedValue
, _rOldValue
, _rValue
, m_aTextColor
, ::getCppuType( static_cast< const sal_Int32
* >( NULL
) ) );
264 case PROPERTY_ID_TEXTLINECOLOR
:
265 bModified
= tryPropertyValue( _rConvertedValue
, _rOldValue
, _rValue
, m_aTextLineColor
, ::getCppuType( static_cast< sal_Int32
* >( NULL
) ) );
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
, ::getCppuType( &m_aFont
) );
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
, (sal_Int16
)m_aFont
.Family
);
295 case PROPERTY_ID_FONT_CHARSET
:
296 bModified
= tryPropertyValue( _rConvertedValue
, _rOldValue
, _rValue
, (sal_Int16
)m_aFont
.CharSet
);
299 case PROPERTY_ID_FONT_CHARWIDTH
:
300 bModified
= tryPropertyValue( _rConvertedValue
, _rOldValue
, _rValue
, float( m_aFont
.CharacterWidth
) );
303 case PROPERTY_ID_FONT_KERNING
:
304 bModified
= tryPropertyValue( _rConvertedValue
, _rOldValue
, _rValue
, (sal_Int16
)m_aFont
.Kerning
);
307 case PROPERTY_ID_FONT_ORIENTATION
:
308 bModified
= tryPropertyValue( _rConvertedValue
, _rOldValue
, _rValue
, float( m_aFont
.Orientation
) );
311 case PROPERTY_ID_FONT_PITCH
:
312 bModified
= tryPropertyValue( _rConvertedValue
, _rOldValue
, _rValue
, (sal_Int16
)m_aFont
.Pitch
);
315 case PROPERTY_ID_FONT_TYPE
:
316 bModified
= tryPropertyValue( _rConvertedValue
, _rOldValue
, _rValue
, (sal_Int16
)m_aFont
.Type
);
319 case PROPERTY_ID_FONT_WIDTH
:
320 bModified
= tryPropertyValue( _rConvertedValue
, _rOldValue
, _rValue
, (sal_Int16
)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
, (sal_Int16
)m_aFont
.Underline
);
339 case PROPERTY_ID_FONT_STRIKEOUT
:
340 bModified
= tryPropertyValue( _rConvertedValue
, _rOldValue
, _rValue
, (sal_Int16
)m_aFont
.Strikeout
);
343 case PROPERTY_ID_FONT_WORDLINEMODE
:
344 bModified
= tryPropertyValue( _rConvertedValue
, _rOldValue
, _rValue
, (sal_Bool
)m_aFont
.WordLineMode
);
348 OSL_FAIL( "FontControlModel::convertFastPropertyValue: no font aggregate!" );
353 //------------------------------------------------------------------------------
354 void FontControlModel::setFastPropertyValue_NoBroadcast( sal_Int32 _nHandle
, const Any
& _rValue
) throw ( Exception
)
358 case PROPERTY_ID_TEXTCOLOR
:
359 m_aTextColor
= _rValue
;
362 case PROPERTY_ID_TEXTLINECOLOR
:
363 m_aTextLineColor
= _rValue
;
366 case PROPERTY_ID_FONTEMPHASISMARK
:
367 _rValue
>>= m_nFontEmphasis
;
370 case PROPERTY_ID_FONTRELIEF
:
371 _rValue
>>= m_nFontRelief
;
374 case PROPERTY_ID_FONT
:
378 case PROPERTY_ID_FONT_NAME
:
379 _rValue
>>= m_aFont
.Name
;
382 case PROPERTY_ID_FONT_STYLENAME
:
383 _rValue
>>= m_aFont
.StyleName
;
386 case PROPERTY_ID_FONT_FAMILY
:
387 _rValue
>>= m_aFont
.Family
;
390 case PROPERTY_ID_FONT_CHARSET
:
391 _rValue
>>= m_aFont
.CharSet
;
394 case PROPERTY_ID_FONT_CHARWIDTH
:
395 _rValue
>>= m_aFont
.CharacterWidth
;
398 case PROPERTY_ID_FONT_KERNING
:
399 _rValue
>>= m_aFont
.Kerning
;
402 case PROPERTY_ID_FONT_ORIENTATION
:
403 _rValue
>>= m_aFont
.Orientation
;
406 case PROPERTY_ID_FONT_PITCH
:
407 _rValue
>>= m_aFont
.Pitch
;
410 case PROPERTY_ID_FONT_TYPE
:
411 _rValue
>>= m_aFont
.Type
;
414 case PROPERTY_ID_FONT_WIDTH
:
415 _rValue
>>= m_aFont
.Width
;
418 case PROPERTY_ID_FONT_HEIGHT
:
422 m_aFont
.Height
= (sal_Int16
)nHeight
;
426 case PROPERTY_ID_FONT_WEIGHT
:
427 _rValue
>>= m_aFont
.Weight
;
430 case PROPERTY_ID_FONT_SLANT
:
431 _rValue
>>= m_aFont
.Slant
;
434 case PROPERTY_ID_FONT_UNDERLINE
:
435 _rValue
>>= m_aFont
.Underline
;
438 case PROPERTY_ID_FONT_STRIKEOUT
:
439 _rValue
>>= m_aFont
.Strikeout
;
442 case PROPERTY_ID_FONT_WORDLINEMODE
:
444 sal_Bool bWordLineMode
= sal_False
;
445 _rValue
>>= bWordLineMode
;
446 m_aFont
.WordLineMode
= bWordLineMode
;
451 OSL_FAIL( "FontControlModel::setFastPropertyValue_NoBroadcast: invalid property!" );
455 //------------------------------------------------------------------------------
456 Any
FontControlModel::getPropertyDefaultByHandle( sal_Int32 _nHandle
) const
459 // some defaults which are the same, not matter if we have toolkit-compatible
461 bool bHandled
= false;
464 case PROPERTY_ID_TEXTCOLOR
:
465 case PROPERTY_ID_TEXTLINECOLOR
:
470 case PROPERTY_ID_FONTEMPHASISMARK
:
471 aReturn
<<= FontEmphasisMark::NONE
;
475 case PROPERTY_ID_FONTRELIEF
:
476 aReturn
<<= FontRelief::NONE
;
483 if ( m_bToolkitCompatibleDefaults
)
485 EmptyFontDescriptor aEmpty
;
486 if ( PROPERTY_ID_FONT
== _nHandle
)
487 return makeAny( (FontDescriptor
)aEmpty
);
488 return lcl_extractFontDescriptorAggregate( _nHandle
, aEmpty
);
493 case PROPERTY_ID_FONT
:
494 aReturn
<<= ::comphelper::getDefaultFont();
497 case PROPERTY_ID_FONT_WORDLINEMODE
:
498 aReturn
= makeBoolAny(sal_False
);
500 case PROPERTY_ID_FONT_NAME
:
501 case PROPERTY_ID_FONT_STYLENAME
:
502 aReturn
<<= OUString();
504 case PROPERTY_ID_FONT_FAMILY
:
505 case PROPERTY_ID_FONT_CHARSET
:
506 case PROPERTY_ID_FONT_SLANT
:
507 case PROPERTY_ID_FONT_UNDERLINE
:
508 case PROPERTY_ID_FONT_STRIKEOUT
:
509 aReturn
<<= (sal_Int16
)1;
512 case PROPERTY_ID_FONT_KERNING
:
513 aReturn
= makeBoolAny(sal_False
);
516 case PROPERTY_ID_FONT_PITCH
:
517 case PROPERTY_ID_FONT_TYPE
:
518 case PROPERTY_ID_FONT_WIDTH
:
519 aReturn
<<= (sal_Int16
)0;
522 case PROPERTY_ID_FONT_HEIGHT
:
523 case PROPERTY_ID_FONT_WEIGHT
:
524 case PROPERTY_ID_FONT_CHARWIDTH
:
525 case PROPERTY_ID_FONT_ORIENTATION
:
526 aReturn
<<= (float)0;
530 OSL_FAIL( "FontControlModel::getPropertyDefaultByHandle: invalid property!" );
536 //.........................................................................
538 //.........................................................................
540 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */