1 /*************************************************************************
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
5 * Copyright 2008 by Sun Microsystems, Inc.
7 * OpenOffice.org - a multi-platform office productivity suite
9 * $RCSfile: formcontrolfont.cxx,v $
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_forms.hxx"
33 #include "formcontrolfont.hxx"
34 #ifndef _FRM_PROPERTY_HRC_
35 #include "property.hrc"
37 #include "property.hxx"
38 #include <tools/debug.hxx>
39 #include <comphelper/property.hxx>
40 #include <comphelper/types.hxx>
41 #include <tools/color.hxx>
42 #include <toolkit/helper/emptyfontdescriptor.hxx>
43 #include <com/sun/star/awt/FontRelief.hpp>
44 #include <com/sun/star/awt/FontEmphasisMark.hpp>
46 //.........................................................................
49 //.........................................................................
51 using namespace ::comphelper
;
52 using namespace ::com::sun::star::uno
;
53 using namespace ::com::sun::star::awt
;
54 using namespace ::com::sun::star::lang
;
55 using namespace ::com::sun::star::beans
;
57 //------------------------------------------------------------------------------
60 Any
lcl_extractFontDescriptorAggregate( sal_Int32 _nHandle
, const FontDescriptor
& _rFont
)
65 case PROPERTY_ID_FONT_NAME
:
66 aValue
<<= _rFont
.Name
;
69 case PROPERTY_ID_FONT_STYLENAME
:
70 aValue
<<= _rFont
.StyleName
;
73 case PROPERTY_ID_FONT_FAMILY
:
74 aValue
<<= (sal_Int16
)_rFont
.Family
;
77 case PROPERTY_ID_FONT_CHARSET
:
78 aValue
<<= (sal_Int16
)_rFont
.CharSet
;
81 case PROPERTY_ID_FONT_CHARWIDTH
:
82 aValue
<<= _rFont
.CharacterWidth
;
85 case PROPERTY_ID_FONT_KERNING
:
86 aValue
<<= _rFont
.Kerning
;
89 case PROPERTY_ID_FONT_ORIENTATION
:
90 aValue
<<= _rFont
.Orientation
;
93 case PROPERTY_ID_FONT_PITCH
:
94 aValue
<<= _rFont
.Pitch
;
97 case PROPERTY_ID_FONT_TYPE
:
98 aValue
<<= _rFont
.Type
;
101 case PROPERTY_ID_FONT_WIDTH
:
102 aValue
<<= _rFont
.Width
;
105 case PROPERTY_ID_FONT_HEIGHT
:
106 aValue
<<= (float)( _rFont
.Height
);
109 case PROPERTY_ID_FONT_WEIGHT
:
110 aValue
<<= (float)_rFont
.Weight
;
113 case PROPERTY_ID_FONT_SLANT
:
114 aValue
= makeAny(_rFont
.Slant
);
117 case PROPERTY_ID_FONT_UNDERLINE
:
118 aValue
<<= (sal_Int16
)_rFont
.Underline
;
121 case PROPERTY_ID_FONT_STRIKEOUT
:
122 aValue
<<= (sal_Int16
)_rFont
.Strikeout
;
125 case PROPERTY_ID_FONT_WORDLINEMODE
:
126 aValue
= makeAny( (sal_Bool
)_rFont
.WordLineMode
);
130 OSL_ENSURE( sal_False
, "lcl_extractFontDescriptorAggregate: invalid handle!" );
137 //=====================================================================
139 //=====================================================================
140 //---------------------------------------------------------------------
141 FontControlModel::FontControlModel( bool _bToolkitCompatibleDefaults
)
142 :m_nFontRelief( FontRelief::NONE
)
143 ,m_nFontEmphasis( FontEmphasisMark::NONE
)
144 ,m_bToolkitCompatibleDefaults( _bToolkitCompatibleDefaults
)
148 //---------------------------------------------------------------------
149 FontControlModel::FontControlModel( const FontControlModel
* _pOriginal
)
151 m_aFont
= _pOriginal
->m_aFont
;
152 m_nFontRelief
= _pOriginal
->m_nFontRelief
;
153 m_nFontEmphasis
= _pOriginal
->m_nFontEmphasis
;
154 m_aTextLineColor
= _pOriginal
->m_aTextLineColor
;
155 m_aTextColor
= _pOriginal
->m_aTextColor
;
156 m_bToolkitCompatibleDefaults
= _pOriginal
->m_bToolkitCompatibleDefaults
;
159 //---------------------------------------------------------------------
160 bool FontControlModel::isFontRelatedProperty( sal_Int32 _nPropertyHandle
) const
162 return isFontAggregateProperty( _nPropertyHandle
)
163 || ( _nPropertyHandle
== PROPERTY_ID_FONT
)
164 || ( _nPropertyHandle
== PROPERTY_ID_FONTEMPHASISMARK
)
165 || ( _nPropertyHandle
== PROPERTY_ID_FONTRELIEF
)
166 || ( _nPropertyHandle
== PROPERTY_ID_TEXTLINECOLOR
)
167 || ( _nPropertyHandle
== PROPERTY_ID_TEXTCOLOR
);
170 //---------------------------------------------------------------------
171 bool FontControlModel::isFontAggregateProperty( sal_Int32 _nPropertyHandle
) const
173 return ( _nPropertyHandle
== PROPERTY_ID_FONT_CHARWIDTH
)
174 || ( _nPropertyHandle
== PROPERTY_ID_FONT_ORIENTATION
)
175 || ( _nPropertyHandle
== PROPERTY_ID_FONT_WIDTH
)
176 || ( _nPropertyHandle
== PROPERTY_ID_FONT_NAME
)
177 || ( _nPropertyHandle
== PROPERTY_ID_FONT_STYLENAME
)
178 || ( _nPropertyHandle
== PROPERTY_ID_FONT_FAMILY
)
179 || ( _nPropertyHandle
== PROPERTY_ID_FONT_CHARSET
)
180 || ( _nPropertyHandle
== PROPERTY_ID_FONT_HEIGHT
)
181 || ( _nPropertyHandle
== PROPERTY_ID_FONT_WEIGHT
)
182 || ( _nPropertyHandle
== PROPERTY_ID_FONT_SLANT
)
183 || ( _nPropertyHandle
== PROPERTY_ID_FONT_UNDERLINE
)
184 || ( _nPropertyHandle
== PROPERTY_ID_FONT_STRIKEOUT
)
185 || ( _nPropertyHandle
== PROPERTY_ID_FONT_WORDLINEMODE
)
186 || ( _nPropertyHandle
== PROPERTY_ID_FONT_PITCH
)
187 || ( _nPropertyHandle
== PROPERTY_ID_FONT_KERNING
)
188 || ( _nPropertyHandle
== PROPERTY_ID_FONT_TYPE
);
191 //---------------------------------------------------------------------
192 sal_Int32
FontControlModel::getTextColor( ) const
194 sal_Int32 nColor
= COL_TRANSPARENT
;
195 m_aTextColor
>>= nColor
;
199 //---------------------------------------------------------------------
200 sal_Int32
FontControlModel::getTextLineColor( ) const
202 sal_Int32 nColor
= COL_TRANSPARENT
;
203 m_aTextLineColor
>>= nColor
;
207 //------------------------------------------------------------------------------
208 void FontControlModel::describeFontRelatedProperties( Sequence
< Property
>& /* [out] */ _rProps
) const
210 sal_Int32 nPos
= _rProps
.getLength();
211 _rProps
.realloc( nPos
+ 21 );
212 Property
* pProperties
= _rProps
.getArray();
214 DECL_PROP2 ( FONT
, FontDescriptor
, BOUND
, MAYBEDEFAULT
);
215 DECL_PROP2 ( FONTEMPHASISMARK
, sal_Int16
, BOUND
, MAYBEDEFAULT
);
216 DECL_PROP2 ( FONTRELIEF
, sal_Int16
, BOUND
, MAYBEDEFAULT
);
217 DECL_PROP3 ( TEXTCOLOR
, sal_Int32
, BOUND
, MAYBEDEFAULT
, MAYBEVOID
);
218 DECL_PROP3 ( TEXTLINECOLOR
, sal_Int32
, BOUND
, MAYBEDEFAULT
, MAYBEVOID
);
220 DECL_PROP1 ( FONT_CHARWIDTH
, float, MAYBEDEFAULT
);
221 DECL_BOOL_PROP1 ( FONT_KERNING
, MAYBEDEFAULT
);
222 DECL_PROP1 ( FONT_ORIENTATION
, float, MAYBEDEFAULT
);
223 DECL_PROP1 ( FONT_PITCH
, sal_Int16
, MAYBEDEFAULT
);
224 DECL_PROP1 ( FONT_TYPE
, sal_Int16
, MAYBEDEFAULT
);
225 DECL_PROP1 ( FONT_WIDTH
, sal_Int16
, MAYBEDEFAULT
);
226 DECL_PROP1 ( FONT_NAME
, ::rtl::OUString
, MAYBEDEFAULT
);
227 DECL_PROP1 ( FONT_STYLENAME
, ::rtl::OUString
, MAYBEDEFAULT
);
228 DECL_PROP1 ( FONT_FAMILY
, sal_Int16
, MAYBEDEFAULT
);
229 DECL_PROP1 ( FONT_CHARSET
, sal_Int16
, MAYBEDEFAULT
);
230 DECL_PROP1 ( FONT_HEIGHT
, float, MAYBEDEFAULT
);
231 DECL_PROP1 ( FONT_WEIGHT
, float, MAYBEDEFAULT
);
232 DECL_PROP1 ( FONT_SLANT
, sal_Int16
, MAYBEDEFAULT
);
233 DECL_PROP1 ( FONT_UNDERLINE
, sal_Int16
, MAYBEDEFAULT
);
234 DECL_PROP1 ( FONT_STRIKEOUT
, sal_Int16
, MAYBEDEFAULT
);
235 DECL_BOOL_PROP1 ( FONT_WORDLINEMODE
, MAYBEDEFAULT
);
238 //---------------------------------------------------------------------
239 void FontControlModel::getFastPropertyValue( Any
& _rValue
, sal_Int32 _nHandle
) const
243 case PROPERTY_ID_TEXTCOLOR
:
244 _rValue
= m_aTextColor
;
247 case PROPERTY_ID_FONTEMPHASISMARK
:
248 _rValue
<<= m_nFontEmphasis
;
251 case PROPERTY_ID_FONTRELIEF
:
252 _rValue
<<= m_nFontRelief
;
255 case PROPERTY_ID_TEXTLINECOLOR
:
256 _rValue
= m_aTextLineColor
;
259 case PROPERTY_ID_FONT
:
260 _rValue
= makeAny( m_aFont
);
264 _rValue
= lcl_extractFontDescriptorAggregate( _nHandle
, m_aFont
);
269 //---------------------------------------------------------------------
270 sal_Bool
FontControlModel::convertFastPropertyValue( Any
& _rConvertedValue
, Any
& _rOldValue
,
271 sal_Int32 _nHandle
, const Any
& _rValue
) throw( IllegalArgumentException
)
273 sal_Bool bModified
= sal_False
;
276 case PROPERTY_ID_TEXTCOLOR
:
277 bModified
= tryPropertyValue( _rConvertedValue
, _rOldValue
, _rValue
, m_aTextColor
, ::getCppuType( static_cast< const sal_Int32
* >( NULL
) ) );
280 case PROPERTY_ID_TEXTLINECOLOR
:
281 bModified
= tryPropertyValue( _rConvertedValue
, _rOldValue
, _rValue
, m_aTextLineColor
, ::getCppuType( static_cast< sal_Int32
* >( NULL
) ) );
284 case PROPERTY_ID_FONTEMPHASISMARK
:
285 bModified
= tryPropertyValue( _rConvertedValue
, _rOldValue
, _rValue
, m_nFontEmphasis
);
288 case PROPERTY_ID_FONTRELIEF
:
289 bModified
= tryPropertyValue( _rConvertedValue
, _rOldValue
, _rValue
, m_nFontRelief
);
292 case PROPERTY_ID_FONT
:
294 Any aWorkAroundGccLimitation
= makeAny( m_aFont
);
295 bModified
= tryPropertyValue( _rConvertedValue
, _rOldValue
, _rValue
, aWorkAroundGccLimitation
, ::getCppuType( &m_aFont
) );
299 case PROPERTY_ID_FONT_NAME
:
300 bModified
= tryPropertyValue( _rConvertedValue
, _rOldValue
, _rValue
, m_aFont
.Name
);
303 case PROPERTY_ID_FONT_STYLENAME
:
304 bModified
= tryPropertyValue( _rConvertedValue
, _rOldValue
, _rValue
, m_aFont
.StyleName
);
307 case PROPERTY_ID_FONT_FAMILY
:
308 bModified
= tryPropertyValue( _rConvertedValue
, _rOldValue
, _rValue
, (sal_Int16
)m_aFont
.Family
);
311 case PROPERTY_ID_FONT_CHARSET
:
312 bModified
= tryPropertyValue( _rConvertedValue
, _rOldValue
, _rValue
, (sal_Int16
)m_aFont
.CharSet
);
315 case PROPERTY_ID_FONT_CHARWIDTH
:
316 bModified
= tryPropertyValue( _rConvertedValue
, _rOldValue
, _rValue
, float( m_aFont
.CharacterWidth
) );
319 case PROPERTY_ID_FONT_KERNING
:
320 bModified
= tryPropertyValue( _rConvertedValue
, _rOldValue
, _rValue
, (sal_Int16
)m_aFont
.Kerning
);
323 case PROPERTY_ID_FONT_ORIENTATION
:
324 bModified
= tryPropertyValue( _rConvertedValue
, _rOldValue
, _rValue
, float( m_aFont
.Orientation
) );
327 case PROPERTY_ID_FONT_PITCH
:
328 bModified
= tryPropertyValue( _rConvertedValue
, _rOldValue
, _rValue
, (sal_Int16
)m_aFont
.Pitch
);
331 case PROPERTY_ID_FONT_TYPE
:
332 bModified
= tryPropertyValue( _rConvertedValue
, _rOldValue
, _rValue
, (sal_Int16
)m_aFont
.Type
);
335 case PROPERTY_ID_FONT_WIDTH
:
336 bModified
= tryPropertyValue( _rConvertedValue
, _rOldValue
, _rValue
, (sal_Int16
)m_aFont
.Width
);
339 case PROPERTY_ID_FONT_HEIGHT
:
340 bModified
= tryPropertyValue( _rConvertedValue
, _rOldValue
, _rValue
, float( m_aFont
.Height
) );
343 case PROPERTY_ID_FONT_WEIGHT
:
344 bModified
= tryPropertyValue( _rConvertedValue
, _rOldValue
, _rValue
, m_aFont
.Weight
);
347 case PROPERTY_ID_FONT_SLANT
:
348 bModified
= tryPropertyValueEnum( _rConvertedValue
, _rOldValue
, _rValue
, m_aFont
.Slant
);
351 case PROPERTY_ID_FONT_UNDERLINE
:
352 bModified
= tryPropertyValue( _rConvertedValue
, _rOldValue
, _rValue
, (sal_Int16
)m_aFont
.Underline
);
355 case PROPERTY_ID_FONT_STRIKEOUT
:
356 bModified
= tryPropertyValue( _rConvertedValue
, _rOldValue
, _rValue
, (sal_Int16
)m_aFont
.Strikeout
);
359 case PROPERTY_ID_FONT_WORDLINEMODE
:
360 bModified
= tryPropertyValue( _rConvertedValue
, _rOldValue
, _rValue
, (sal_Bool
)m_aFont
.WordLineMode
);
364 DBG_ERROR( "FontControlModel::convertFastPropertyValue: no font aggregate!" );
369 //------------------------------------------------------------------------------
370 void FontControlModel::setFastPropertyValue_NoBroadcast( sal_Int32 _nHandle
, const Any
& _rValue
) throw ( Exception
)
374 case PROPERTY_ID_TEXTCOLOR
:
375 m_aTextColor
= _rValue
;
378 case PROPERTY_ID_TEXTLINECOLOR
:
379 m_aTextLineColor
= _rValue
;
382 case PROPERTY_ID_FONTEMPHASISMARK
:
383 _rValue
>>= m_nFontEmphasis
;
386 case PROPERTY_ID_FONTRELIEF
:
387 _rValue
>>= m_nFontRelief
;
390 case PROPERTY_ID_FONT
:
394 case PROPERTY_ID_FONT_NAME
:
395 _rValue
>>= m_aFont
.Name
;
398 case PROPERTY_ID_FONT_STYLENAME
:
399 _rValue
>>= m_aFont
.StyleName
;
402 case PROPERTY_ID_FONT_FAMILY
:
403 _rValue
>>= m_aFont
.Family
;
406 case PROPERTY_ID_FONT_CHARSET
:
407 _rValue
>>= m_aFont
.CharSet
;
410 case PROPERTY_ID_FONT_CHARWIDTH
:
411 _rValue
>>= m_aFont
.CharacterWidth
;
414 case PROPERTY_ID_FONT_KERNING
:
415 _rValue
>>= m_aFont
.Kerning
;
418 case PROPERTY_ID_FONT_ORIENTATION
:
419 _rValue
>>= m_aFont
.Orientation
;
422 case PROPERTY_ID_FONT_PITCH
:
423 _rValue
>>= m_aFont
.Pitch
;
426 case PROPERTY_ID_FONT_TYPE
:
427 _rValue
>>= m_aFont
.Type
;
430 case PROPERTY_ID_FONT_WIDTH
:
431 _rValue
>>= m_aFont
.Width
;
434 case PROPERTY_ID_FONT_HEIGHT
:
438 m_aFont
.Height
= (sal_Int16
)nHeight
;
442 case PROPERTY_ID_FONT_WEIGHT
:
443 _rValue
>>= m_aFont
.Weight
;
446 case PROPERTY_ID_FONT_SLANT
:
447 _rValue
>>= m_aFont
.Slant
;
450 case PROPERTY_ID_FONT_UNDERLINE
:
451 _rValue
>>= m_aFont
.Underline
;
454 case PROPERTY_ID_FONT_STRIKEOUT
:
455 _rValue
>>= m_aFont
.Strikeout
;
458 case PROPERTY_ID_FONT_WORDLINEMODE
:
460 sal_Bool bWordLineMode
= sal_False
;
461 _rValue
>>= bWordLineMode
;
462 m_aFont
.WordLineMode
= bWordLineMode
;
467 DBG_ERROR( "FontControlModel::setFastPropertyValue_NoBroadcast: invalid property!" );
471 //------------------------------------------------------------------------------
472 Any
FontControlModel::getPropertyDefaultByHandle( sal_Int32 _nHandle
) const
475 // some defaults which are the same, not matter if we have toolkit-compatible
477 bool bHandled
= false;
480 case PROPERTY_ID_TEXTCOLOR
:
481 case PROPERTY_ID_TEXTLINECOLOR
:
486 case PROPERTY_ID_FONTEMPHASISMARK
:
487 aReturn
<<= FontEmphasisMark::NONE
;
491 case PROPERTY_ID_FONTRELIEF
:
492 aReturn
<<= FontRelief::NONE
;
499 if ( m_bToolkitCompatibleDefaults
)
501 EmptyFontDescriptor aEmpty
;
502 if ( PROPERTY_ID_FONT
== _nHandle
)
503 return makeAny( (FontDescriptor
)aEmpty
);
504 return lcl_extractFontDescriptorAggregate( _nHandle
, aEmpty
);
509 case PROPERTY_ID_FONT
:
510 aReturn
<<= ::comphelper::getDefaultFont();
513 case PROPERTY_ID_FONT_WORDLINEMODE
:
514 aReturn
= makeBoolAny(sal_False
);
516 case PROPERTY_ID_FONT_NAME
:
517 case PROPERTY_ID_FONT_STYLENAME
:
518 aReturn
<<= ::rtl::OUString();
520 case PROPERTY_ID_FONT_FAMILY
:
521 case PROPERTY_ID_FONT_CHARSET
:
522 case PROPERTY_ID_FONT_SLANT
:
523 case PROPERTY_ID_FONT_UNDERLINE
:
524 case PROPERTY_ID_FONT_STRIKEOUT
:
525 aReturn
<<= (sal_Int16
)1;
528 case PROPERTY_ID_FONT_KERNING
:
529 aReturn
= makeBoolAny(sal_False
);
532 case PROPERTY_ID_FONT_PITCH
:
533 case PROPERTY_ID_FONT_TYPE
:
534 case PROPERTY_ID_FONT_WIDTH
:
535 aReturn
<<= (sal_Int16
)0;
538 case PROPERTY_ID_FONT_HEIGHT
:
539 case PROPERTY_ID_FONT_WEIGHT
:
540 case PROPERTY_ID_FONT_CHARWIDTH
:
541 case PROPERTY_ID_FONT_ORIENTATION
:
542 aReturn
<<= (float)0;
546 DBG_ERROR( "FontControlModel::getPropertyDefaultByHandle: invalid property!" );
552 //.........................................................................
554 //.........................................................................