update credits
[LibreOffice.git] / forms / source / component / formcontrolfont.cxx
blobcd351e5b88a226b75249eb25c67795f95e5debdd
1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 /*
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 //.........................................................................
31 namespace frm
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 //------------------------------------------------------------------------------
42 namespace
44 Any lcl_extractFontDescriptorAggregate( sal_Int32 _nHandle, const FontDescriptor& _rFont )
46 Any aValue;
47 switch ( _nHandle )
49 case PROPERTY_ID_FONT_NAME:
50 aValue <<= _rFont.Name;
51 break;
53 case PROPERTY_ID_FONT_STYLENAME:
54 aValue <<= _rFont.StyleName;
55 break;
57 case PROPERTY_ID_FONT_FAMILY:
58 aValue <<= (sal_Int16)_rFont.Family;
59 break;
61 case PROPERTY_ID_FONT_CHARSET:
62 aValue <<= (sal_Int16)_rFont.CharSet;
63 break;
65 case PROPERTY_ID_FONT_CHARWIDTH:
66 aValue <<= _rFont.CharacterWidth;
67 break;
69 case PROPERTY_ID_FONT_KERNING:
70 aValue <<= _rFont.Kerning;
71 break;
73 case PROPERTY_ID_FONT_ORIENTATION:
74 aValue <<= _rFont.Orientation;
75 break;
77 case PROPERTY_ID_FONT_PITCH:
78 aValue <<= _rFont.Pitch;
79 break;
81 case PROPERTY_ID_FONT_TYPE:
82 aValue <<= _rFont.Type;
83 break;
85 case PROPERTY_ID_FONT_WIDTH:
86 aValue <<= _rFont.Width;
87 break;
89 case PROPERTY_ID_FONT_HEIGHT:
90 aValue <<= (float)( _rFont.Height );
91 break;
93 case PROPERTY_ID_FONT_WEIGHT:
94 aValue <<= (float)_rFont.Weight;
95 break;
97 case PROPERTY_ID_FONT_SLANT:
98 aValue = makeAny(_rFont.Slant);
99 break;
101 case PROPERTY_ID_FONT_UNDERLINE:
102 aValue <<= (sal_Int16)_rFont.Underline;
103 break;
105 case PROPERTY_ID_FONT_STRIKEOUT:
106 aValue <<= (sal_Int16)_rFont.Strikeout;
107 break;
109 case PROPERTY_ID_FONT_WORDLINEMODE:
110 aValue = makeAny( (sal_Bool)_rFont.WordLineMode );
111 break;
113 default:
114 OSL_FAIL( "lcl_extractFontDescriptorAggregate: invalid handle!" );
115 break;
117 return aValue;
121 //=====================================================================
122 //= FontControlModel
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;
180 return nColor;
183 //---------------------------------------------------------------------
184 sal_Int32 FontControlModel::getTextLineColor( ) const
186 sal_Int32 nColor = COL_TRANSPARENT;
187 m_aTextLineColor >>= nColor;
188 return 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
225 switch( _nHandle )
227 case PROPERTY_ID_TEXTCOLOR:
228 _rValue = m_aTextColor;
229 break;
231 case PROPERTY_ID_FONTEMPHASISMARK:
232 _rValue <<= m_nFontEmphasis;
233 break;
235 case PROPERTY_ID_FONTRELIEF:
236 _rValue <<= m_nFontRelief;
237 break;
239 case PROPERTY_ID_TEXTLINECOLOR:
240 _rValue = m_aTextLineColor;
241 break;
243 case PROPERTY_ID_FONT:
244 _rValue = makeAny( m_aFont );
245 break;
247 default:
248 _rValue = lcl_extractFontDescriptorAggregate( _nHandle, m_aFont );
249 break;
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;
258 switch( _nHandle )
260 case PROPERTY_ID_TEXTCOLOR:
261 bModified = tryPropertyValue( _rConvertedValue, _rOldValue, _rValue, m_aTextColor, ::getCppuType( static_cast< const sal_Int32* >( NULL ) ) );
262 break;
264 case PROPERTY_ID_TEXTLINECOLOR:
265 bModified = tryPropertyValue( _rConvertedValue, _rOldValue, _rValue, m_aTextLineColor, ::getCppuType( static_cast< sal_Int32* >( NULL ) ) );
266 break;
268 case PROPERTY_ID_FONTEMPHASISMARK:
269 bModified = tryPropertyValue( _rConvertedValue, _rOldValue, _rValue, m_nFontEmphasis );
270 break;
272 case PROPERTY_ID_FONTRELIEF:
273 bModified = tryPropertyValue( _rConvertedValue, _rOldValue, _rValue, m_nFontRelief );
274 break;
276 case PROPERTY_ID_FONT:
278 Any aWorkAroundGccLimitation = makeAny( m_aFont );
279 bModified = tryPropertyValue( _rConvertedValue, _rOldValue, _rValue, aWorkAroundGccLimitation, ::getCppuType( &m_aFont ) );
281 break;
283 case PROPERTY_ID_FONT_NAME:
284 bModified = tryPropertyValue( _rConvertedValue, _rOldValue, _rValue, m_aFont.Name );
285 break;
287 case PROPERTY_ID_FONT_STYLENAME:
288 bModified = tryPropertyValue( _rConvertedValue, _rOldValue, _rValue, m_aFont.StyleName );
289 break;
291 case PROPERTY_ID_FONT_FAMILY:
292 bModified = tryPropertyValue( _rConvertedValue, _rOldValue, _rValue, (sal_Int16)m_aFont.Family );
293 break;
295 case PROPERTY_ID_FONT_CHARSET:
296 bModified = tryPropertyValue( _rConvertedValue, _rOldValue, _rValue, (sal_Int16)m_aFont.CharSet );
297 break;
299 case PROPERTY_ID_FONT_CHARWIDTH:
300 bModified = tryPropertyValue( _rConvertedValue, _rOldValue, _rValue, float( m_aFont.CharacterWidth ) );
301 break;
303 case PROPERTY_ID_FONT_KERNING:
304 bModified = tryPropertyValue( _rConvertedValue, _rOldValue, _rValue, (sal_Int16)m_aFont.Kerning );
305 break;
307 case PROPERTY_ID_FONT_ORIENTATION:
308 bModified = tryPropertyValue( _rConvertedValue, _rOldValue, _rValue, float( m_aFont.Orientation ) );
309 break;
311 case PROPERTY_ID_FONT_PITCH:
312 bModified = tryPropertyValue( _rConvertedValue, _rOldValue, _rValue, (sal_Int16)m_aFont.Pitch );
313 break;
315 case PROPERTY_ID_FONT_TYPE:
316 bModified = tryPropertyValue( _rConvertedValue, _rOldValue, _rValue, (sal_Int16)m_aFont.Type );
317 break;
319 case PROPERTY_ID_FONT_WIDTH:
320 bModified = tryPropertyValue( _rConvertedValue, _rOldValue, _rValue, (sal_Int16)m_aFont.Width );
321 break;
323 case PROPERTY_ID_FONT_HEIGHT:
324 bModified = tryPropertyValue( _rConvertedValue, _rOldValue, _rValue, float( m_aFont.Height ) );
325 break;
327 case PROPERTY_ID_FONT_WEIGHT:
328 bModified = tryPropertyValue( _rConvertedValue, _rOldValue, _rValue, m_aFont.Weight );
329 break;
331 case PROPERTY_ID_FONT_SLANT:
332 bModified = tryPropertyValueEnum( _rConvertedValue, _rOldValue, _rValue, m_aFont.Slant );
333 break;
335 case PROPERTY_ID_FONT_UNDERLINE:
336 bModified = tryPropertyValue( _rConvertedValue, _rOldValue, _rValue, (sal_Int16)m_aFont.Underline );
337 break;
339 case PROPERTY_ID_FONT_STRIKEOUT:
340 bModified = tryPropertyValue( _rConvertedValue, _rOldValue, _rValue, (sal_Int16)m_aFont.Strikeout );
341 break;
343 case PROPERTY_ID_FONT_WORDLINEMODE:
344 bModified = tryPropertyValue( _rConvertedValue, _rOldValue, _rValue, (sal_Bool)m_aFont.WordLineMode );
345 break;
347 default:
348 OSL_FAIL( "FontControlModel::convertFastPropertyValue: no font aggregate!" );
350 return bModified;
353 //------------------------------------------------------------------------------
354 void FontControlModel::setFastPropertyValue_NoBroadcast( sal_Int32 _nHandle, const Any& _rValue ) throw ( Exception )
356 switch( _nHandle )
358 case PROPERTY_ID_TEXTCOLOR:
359 m_aTextColor = _rValue;
360 break;
362 case PROPERTY_ID_TEXTLINECOLOR:
363 m_aTextLineColor = _rValue;
364 break;
366 case PROPERTY_ID_FONTEMPHASISMARK:
367 _rValue >>= m_nFontEmphasis;
368 break;
370 case PROPERTY_ID_FONTRELIEF:
371 _rValue >>= m_nFontRelief;
372 break;
374 case PROPERTY_ID_FONT:
375 _rValue >>= m_aFont;
376 break;
378 case PROPERTY_ID_FONT_NAME:
379 _rValue >>= m_aFont.Name;
380 break;
382 case PROPERTY_ID_FONT_STYLENAME:
383 _rValue >>= m_aFont.StyleName;
384 break;
386 case PROPERTY_ID_FONT_FAMILY:
387 _rValue >>= m_aFont.Family;
388 break;
390 case PROPERTY_ID_FONT_CHARSET:
391 _rValue >>= m_aFont.CharSet;
392 break;
394 case PROPERTY_ID_FONT_CHARWIDTH:
395 _rValue >>= m_aFont.CharacterWidth;
396 break;
398 case PROPERTY_ID_FONT_KERNING:
399 _rValue >>= m_aFont.Kerning;
400 break;
402 case PROPERTY_ID_FONT_ORIENTATION:
403 _rValue >>= m_aFont.Orientation;
404 break;
406 case PROPERTY_ID_FONT_PITCH:
407 _rValue >>= m_aFont.Pitch;
408 break;
410 case PROPERTY_ID_FONT_TYPE:
411 _rValue >>= m_aFont.Type;
412 break;
414 case PROPERTY_ID_FONT_WIDTH:
415 _rValue >>= m_aFont.Width;
416 break;
418 case PROPERTY_ID_FONT_HEIGHT:
420 float nHeight = 0;
421 _rValue >>= nHeight;
422 m_aFont.Height = (sal_Int16)nHeight;
424 break;
426 case PROPERTY_ID_FONT_WEIGHT:
427 _rValue >>= m_aFont.Weight;
428 break;
430 case PROPERTY_ID_FONT_SLANT:
431 _rValue >>= m_aFont.Slant;
432 break;
434 case PROPERTY_ID_FONT_UNDERLINE:
435 _rValue >>= m_aFont.Underline;
436 break;
438 case PROPERTY_ID_FONT_STRIKEOUT:
439 _rValue >>= m_aFont.Strikeout;
440 break;
442 case PROPERTY_ID_FONT_WORDLINEMODE:
444 sal_Bool bWordLineMode = sal_False;
445 _rValue >>= bWordLineMode;
446 m_aFont.WordLineMode = bWordLineMode;
448 break;
450 default:
451 OSL_FAIL( "FontControlModel::setFastPropertyValue_NoBroadcast: invalid property!" );
455 //------------------------------------------------------------------------------
456 Any FontControlModel::getPropertyDefaultByHandle( sal_Int32 _nHandle ) const
458 Any aReturn;
459 // some defaults which are the same, not matter if we have toolkit-compatible
460 // defaults or not
461 bool bHandled = false;
462 switch( _nHandle )
464 case PROPERTY_ID_TEXTCOLOR:
465 case PROPERTY_ID_TEXTLINECOLOR:
466 // void
467 bHandled = true;
468 break;
470 case PROPERTY_ID_FONTEMPHASISMARK:
471 aReturn <<= FontEmphasisMark::NONE;
472 bHandled = true;
473 break;
475 case PROPERTY_ID_FONTRELIEF:
476 aReturn <<= FontRelief::NONE;
477 bHandled = true;
478 break;
480 if ( bHandled )
481 return aReturn;
483 if ( m_bToolkitCompatibleDefaults )
485 EmptyFontDescriptor aEmpty;
486 if ( PROPERTY_ID_FONT == _nHandle )
487 return makeAny( (FontDescriptor)aEmpty );
488 return lcl_extractFontDescriptorAggregate( _nHandle, aEmpty );
491 switch( _nHandle )
493 case PROPERTY_ID_FONT:
494 aReturn <<= ::comphelper::getDefaultFont();
495 break;
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;
510 break;
512 case PROPERTY_ID_FONT_KERNING:
513 aReturn = makeBoolAny(sal_False);
514 break;
516 case PROPERTY_ID_FONT_PITCH:
517 case PROPERTY_ID_FONT_TYPE:
518 case PROPERTY_ID_FONT_WIDTH:
519 aReturn <<= (sal_Int16)0;
520 break;
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;
527 break;
529 default:
530 OSL_FAIL( "FontControlModel::getPropertyDefaultByHandle: invalid property!" );
533 return aReturn;
536 //.........................................................................
537 } // namespace frm
538 //.........................................................................
540 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */