update dev300-m58
[ooovba.git] / forms / source / component / formcontrolfont.cxx
blob8d188cf1b9c92408fe014e9ffeec7d9628feaeb4
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: formcontrolfont.cxx,v $
10 * $Revision: 1.10 $
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"
36 #endif
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 //.........................................................................
47 namespace frm
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 //------------------------------------------------------------------------------
58 namespace
60 Any lcl_extractFontDescriptorAggregate( sal_Int32 _nHandle, const FontDescriptor& _rFont )
62 Any aValue;
63 switch ( _nHandle )
65 case PROPERTY_ID_FONT_NAME:
66 aValue <<= _rFont.Name;
67 break;
69 case PROPERTY_ID_FONT_STYLENAME:
70 aValue <<= _rFont.StyleName;
71 break;
73 case PROPERTY_ID_FONT_FAMILY:
74 aValue <<= (sal_Int16)_rFont.Family;
75 break;
77 case PROPERTY_ID_FONT_CHARSET:
78 aValue <<= (sal_Int16)_rFont.CharSet;
79 break;
81 case PROPERTY_ID_FONT_CHARWIDTH:
82 aValue <<= _rFont.CharacterWidth;
83 break;
85 case PROPERTY_ID_FONT_KERNING:
86 aValue <<= _rFont.Kerning;
87 break;
89 case PROPERTY_ID_FONT_ORIENTATION:
90 aValue <<= _rFont.Orientation;
91 break;
93 case PROPERTY_ID_FONT_PITCH:
94 aValue <<= _rFont.Pitch;
95 break;
97 case PROPERTY_ID_FONT_TYPE:
98 aValue <<= _rFont.Type;
99 break;
101 case PROPERTY_ID_FONT_WIDTH:
102 aValue <<= _rFont.Width;
103 break;
105 case PROPERTY_ID_FONT_HEIGHT:
106 aValue <<= (float)( _rFont.Height );
107 break;
109 case PROPERTY_ID_FONT_WEIGHT:
110 aValue <<= (float)_rFont.Weight;
111 break;
113 case PROPERTY_ID_FONT_SLANT:
114 aValue = makeAny(_rFont.Slant);
115 break;
117 case PROPERTY_ID_FONT_UNDERLINE:
118 aValue <<= (sal_Int16)_rFont.Underline;
119 break;
121 case PROPERTY_ID_FONT_STRIKEOUT:
122 aValue <<= (sal_Int16)_rFont.Strikeout;
123 break;
125 case PROPERTY_ID_FONT_WORDLINEMODE:
126 aValue = makeAny( (sal_Bool)_rFont.WordLineMode );
127 break;
129 default:
130 OSL_ENSURE( sal_False, "lcl_extractFontDescriptorAggregate: invalid handle!" );
131 break;
133 return aValue;
137 //=====================================================================
138 //= FontControlModel
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;
196 return nColor;
199 //---------------------------------------------------------------------
200 sal_Int32 FontControlModel::getTextLineColor( ) const
202 sal_Int32 nColor = COL_TRANSPARENT;
203 m_aTextLineColor >>= nColor;
204 return 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
241 switch( _nHandle )
243 case PROPERTY_ID_TEXTCOLOR:
244 _rValue = m_aTextColor;
245 break;
247 case PROPERTY_ID_FONTEMPHASISMARK:
248 _rValue <<= m_nFontEmphasis;
249 break;
251 case PROPERTY_ID_FONTRELIEF:
252 _rValue <<= m_nFontRelief;
253 break;
255 case PROPERTY_ID_TEXTLINECOLOR:
256 _rValue = m_aTextLineColor;
257 break;
259 case PROPERTY_ID_FONT:
260 _rValue = makeAny( m_aFont );
261 break;
263 default:
264 _rValue = lcl_extractFontDescriptorAggregate( _nHandle, m_aFont );
265 break;
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;
274 switch( _nHandle )
276 case PROPERTY_ID_TEXTCOLOR:
277 bModified = tryPropertyValue( _rConvertedValue, _rOldValue, _rValue, m_aTextColor, ::getCppuType( static_cast< const sal_Int32* >( NULL ) ) );
278 break;
280 case PROPERTY_ID_TEXTLINECOLOR:
281 bModified = tryPropertyValue( _rConvertedValue, _rOldValue, _rValue, m_aTextLineColor, ::getCppuType( static_cast< sal_Int32* >( NULL ) ) );
282 break;
284 case PROPERTY_ID_FONTEMPHASISMARK:
285 bModified = tryPropertyValue( _rConvertedValue, _rOldValue, _rValue, m_nFontEmphasis );
286 break;
288 case PROPERTY_ID_FONTRELIEF:
289 bModified = tryPropertyValue( _rConvertedValue, _rOldValue, _rValue, m_nFontRelief );
290 break;
292 case PROPERTY_ID_FONT:
294 Any aWorkAroundGccLimitation = makeAny( m_aFont );
295 bModified = tryPropertyValue( _rConvertedValue, _rOldValue, _rValue, aWorkAroundGccLimitation, ::getCppuType( &m_aFont ) );
297 break;
299 case PROPERTY_ID_FONT_NAME:
300 bModified = tryPropertyValue( _rConvertedValue, _rOldValue, _rValue, m_aFont.Name );
301 break;
303 case PROPERTY_ID_FONT_STYLENAME:
304 bModified = tryPropertyValue( _rConvertedValue, _rOldValue, _rValue, m_aFont.StyleName );
305 break;
307 case PROPERTY_ID_FONT_FAMILY:
308 bModified = tryPropertyValue( _rConvertedValue, _rOldValue, _rValue, (sal_Int16)m_aFont.Family );
309 break;
311 case PROPERTY_ID_FONT_CHARSET:
312 bModified = tryPropertyValue( _rConvertedValue, _rOldValue, _rValue, (sal_Int16)m_aFont.CharSet );
313 break;
315 case PROPERTY_ID_FONT_CHARWIDTH:
316 bModified = tryPropertyValue( _rConvertedValue, _rOldValue, _rValue, float( m_aFont.CharacterWidth ) );
317 break;
319 case PROPERTY_ID_FONT_KERNING:
320 bModified = tryPropertyValue( _rConvertedValue, _rOldValue, _rValue, (sal_Int16)m_aFont.Kerning );
321 break;
323 case PROPERTY_ID_FONT_ORIENTATION:
324 bModified = tryPropertyValue( _rConvertedValue, _rOldValue, _rValue, float( m_aFont.Orientation ) );
325 break;
327 case PROPERTY_ID_FONT_PITCH:
328 bModified = tryPropertyValue( _rConvertedValue, _rOldValue, _rValue, (sal_Int16)m_aFont.Pitch );
329 break;
331 case PROPERTY_ID_FONT_TYPE:
332 bModified = tryPropertyValue( _rConvertedValue, _rOldValue, _rValue, (sal_Int16)m_aFont.Type );
333 break;
335 case PROPERTY_ID_FONT_WIDTH:
336 bModified = tryPropertyValue( _rConvertedValue, _rOldValue, _rValue, (sal_Int16)m_aFont.Width );
337 break;
339 case PROPERTY_ID_FONT_HEIGHT:
340 bModified = tryPropertyValue( _rConvertedValue, _rOldValue, _rValue, float( m_aFont.Height ) );
341 break;
343 case PROPERTY_ID_FONT_WEIGHT:
344 bModified = tryPropertyValue( _rConvertedValue, _rOldValue, _rValue, m_aFont.Weight );
345 break;
347 case PROPERTY_ID_FONT_SLANT:
348 bModified = tryPropertyValueEnum( _rConvertedValue, _rOldValue, _rValue, m_aFont.Slant );
349 break;
351 case PROPERTY_ID_FONT_UNDERLINE:
352 bModified = tryPropertyValue( _rConvertedValue, _rOldValue, _rValue, (sal_Int16)m_aFont.Underline );
353 break;
355 case PROPERTY_ID_FONT_STRIKEOUT:
356 bModified = tryPropertyValue( _rConvertedValue, _rOldValue, _rValue, (sal_Int16)m_aFont.Strikeout );
357 break;
359 case PROPERTY_ID_FONT_WORDLINEMODE:
360 bModified = tryPropertyValue( _rConvertedValue, _rOldValue, _rValue, (sal_Bool)m_aFont.WordLineMode );
361 break;
363 default:
364 DBG_ERROR( "FontControlModel::convertFastPropertyValue: no font aggregate!" );
366 return bModified;
369 //------------------------------------------------------------------------------
370 void FontControlModel::setFastPropertyValue_NoBroadcast( sal_Int32 _nHandle, const Any& _rValue ) throw ( Exception )
372 switch( _nHandle )
374 case PROPERTY_ID_TEXTCOLOR:
375 m_aTextColor = _rValue;
376 break;
378 case PROPERTY_ID_TEXTLINECOLOR:
379 m_aTextLineColor = _rValue;
380 break;
382 case PROPERTY_ID_FONTEMPHASISMARK:
383 _rValue >>= m_nFontEmphasis;
384 break;
386 case PROPERTY_ID_FONTRELIEF:
387 _rValue >>= m_nFontRelief;
388 break;
390 case PROPERTY_ID_FONT:
391 _rValue >>= m_aFont;
392 break;
394 case PROPERTY_ID_FONT_NAME:
395 _rValue >>= m_aFont.Name;
396 break;
398 case PROPERTY_ID_FONT_STYLENAME:
399 _rValue >>= m_aFont.StyleName;
400 break;
402 case PROPERTY_ID_FONT_FAMILY:
403 _rValue >>= m_aFont.Family;
404 break;
406 case PROPERTY_ID_FONT_CHARSET:
407 _rValue >>= m_aFont.CharSet;
408 break;
410 case PROPERTY_ID_FONT_CHARWIDTH:
411 _rValue >>= m_aFont.CharacterWidth;
412 break;
414 case PROPERTY_ID_FONT_KERNING:
415 _rValue >>= m_aFont.Kerning;
416 break;
418 case PROPERTY_ID_FONT_ORIENTATION:
419 _rValue >>= m_aFont.Orientation;
420 break;
422 case PROPERTY_ID_FONT_PITCH:
423 _rValue >>= m_aFont.Pitch;
424 break;
426 case PROPERTY_ID_FONT_TYPE:
427 _rValue >>= m_aFont.Type;
428 break;
430 case PROPERTY_ID_FONT_WIDTH:
431 _rValue >>= m_aFont.Width;
432 break;
434 case PROPERTY_ID_FONT_HEIGHT:
436 float nHeight = 0;
437 _rValue >>= nHeight;
438 m_aFont.Height = (sal_Int16)nHeight;
440 break;
442 case PROPERTY_ID_FONT_WEIGHT:
443 _rValue >>= m_aFont.Weight;
444 break;
446 case PROPERTY_ID_FONT_SLANT:
447 _rValue >>= m_aFont.Slant;
448 break;
450 case PROPERTY_ID_FONT_UNDERLINE:
451 _rValue >>= m_aFont.Underline;
452 break;
454 case PROPERTY_ID_FONT_STRIKEOUT:
455 _rValue >>= m_aFont.Strikeout;
456 break;
458 case PROPERTY_ID_FONT_WORDLINEMODE:
460 sal_Bool bWordLineMode = sal_False;
461 _rValue >>= bWordLineMode;
462 m_aFont.WordLineMode = bWordLineMode;
464 break;
466 default:
467 DBG_ERROR( "FontControlModel::setFastPropertyValue_NoBroadcast: invalid property!" );
471 //------------------------------------------------------------------------------
472 Any FontControlModel::getPropertyDefaultByHandle( sal_Int32 _nHandle ) const
474 Any aReturn;
475 // some defaults which are the same, not matter if we have toolkit-compatible
476 // defaults or not
477 bool bHandled = false;
478 switch( _nHandle )
480 case PROPERTY_ID_TEXTCOLOR:
481 case PROPERTY_ID_TEXTLINECOLOR:
482 // void
483 bHandled = true;
484 break;
486 case PROPERTY_ID_FONTEMPHASISMARK:
487 aReturn <<= FontEmphasisMark::NONE;
488 bHandled = true;
489 break;
491 case PROPERTY_ID_FONTRELIEF:
492 aReturn <<= FontRelief::NONE;
493 bHandled = true;
494 break;
496 if ( bHandled )
497 return aReturn;
499 if ( m_bToolkitCompatibleDefaults )
501 EmptyFontDescriptor aEmpty;
502 if ( PROPERTY_ID_FONT == _nHandle )
503 return makeAny( (FontDescriptor)aEmpty );
504 return lcl_extractFontDescriptorAggregate( _nHandle, aEmpty );
507 switch( _nHandle )
509 case PROPERTY_ID_FONT:
510 aReturn <<= ::comphelper::getDefaultFont();
511 break;
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;
526 break;
528 case PROPERTY_ID_FONT_KERNING:
529 aReturn = makeBoolAny(sal_False);
530 break;
532 case PROPERTY_ID_FONT_PITCH:
533 case PROPERTY_ID_FONT_TYPE:
534 case PROPERTY_ID_FONT_WIDTH:
535 aReturn <<= (sal_Int16)0;
536 break;
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;
543 break;
545 default:
546 DBG_ERROR( "FontControlModel::getPropertyDefaultByHandle: invalid property!" );
549 return aReturn;
552 //.........................................................................
553 } // namespace frm
554 //.........................................................................